package TestCase {
  use Std;
  use TestCase::EnumA;
  use TestCase::EnumB;
  use TestCase::EnumC;
  use TestCase::EnumD;
  use TestCase::Simple;
  use TestCase::Minimal;
  use TestCase::Destructor;
  use TestCase::Interface;
  use TestCase::ImplementInterface1;
  use TestCase::ImplementInterface2;
  use TestCase::Comparator;

=pod

ABCDE

=cut ppppp

=head1 NAME

SPVM::Test - SPVM test module

=cut

  
  our $PACKAGE_VAR_INT : int;
  our $PACKAGE_VAR_TEST_CASE : TestCase;
  
  has next_test : TestCase;
  has minimal : TestCase::Minimal;
  has x_byte : byte;
  has x_short : short;
  has x_int : int;
  has x_long : long;
  has x_float : float;
  has x_double : double;
  has private_field : int;
  
  sub BYTE_MAX : byte () { return (byte)127; }
  sub BYTE_MIN : byte () { return (byte)-128; }
  sub SHORT_MAX : short () { return (short)32767; }
  sub SHORT_MIN : short () { return (short)-32768; }
  sub INT_MAX : int () { return 2147483647; }
  sub INT_MIN : int () { return -2147483648; }
  sub LONG_MAX : long () { return 9223372036854775807L; }
  sub LONG_MIN : long () { return -9223372036854775808L; }
  sub FLOAT_PRECICE : float () { return 32767f; }
  sub DOUBLE_PRECICE : double () { return 2147483647.0; }
  
  sub main : int ($mvar : int) {
    # Multi array init
    {
      my $nums1 = [
        [1, 2, 3],
        [5, 6, 7]
      ];
    }

    {
      # get_bytes
      my $get_bytes_ok = 0;
      {
        my $string1 = "abc";
        
        my $bytes = $string1->get_bytes;
        my $len = @$bytes;
        if ($bytes->[0] == 'a' && $bytes->[1] == 'b' && $bytes->[2] == 'c' &&  $len == 3) {
          $get_bytes_ok = 1;
        }
      }
      
      # at
      my $at_ok = 0;
      {
        my $string1 = "abcde";
        
        my $byte = $string1->at(2);
        if ($byte == 'c') {
          $at_ok = 1;
        }
      }
      

      # at
      my $length_ok = 0;
      {
        my $string1 = "abcde";
        
        my $length = $string1->length;
        if ($length == 5) {
          $length_ok = 1;
        }
      }

      # new_bytes
      my $new_bytes_ok = 0;
      {
        my $bytes = new byte[] {'a', 'b', 'c', 'd', 'e'};
        my $string = String->new_bytes($bytes);
        my $string_expect = "abcde";
        if ($string eq $string_expect) {
          $new_bytes_ok = 1;
        }
      }
    }

    {
      my $nums1 = [1, 2, 3];
      my $nums2 = [1.0, 2, 3];
      
      print((String)$nums2->[2]);
    }
    
    # Pre increment and assign
    {
      my $num1 = 0;
      my $num2 = ++$num1;
      print((String)$num2);
    }

    # Pre decrement and assign
    {
      my $num1 = 0;
      my $num2 = --$num1;
      print((String)$num2);
    }

    # Post increment and assign
    {
      my $num1 = 0;
      my $num2 = $num1++;
      print((String)$num2);
    }

    # Post decrement and assign
    {
      my $num1 = 0;
      my $num2 = $num1--;
      print((String)$num2);
    }
    
    # UNDEF
    {
      $PACKAGE_VAR_TEST_CASE = undef;
      $@ = undef;
      {
        my $test_case = new TestCase;
        $test_case->{minimal} = undef;
      }
      {
        my $nums = new TestCase[3];
        $nums->[0] = undef;
      }
      {
        my $minimal = new TestCase::Minimal;
        $minimal = undef;
      }
      {
        receive_undef(undef);
      }
    }
    
    # Concat
    {
      my $str1 = "a";
      my $str2 = "b";
      $str2 .= $str1;
    }
    
    # Create object in loop
    for (my $i = 0; $i < 3; $i++) {
      my $minimal = new TestCase::Minimal;
    }

    # Assign same variable
    {
      my $var1 = new TestCase::Minimal;
      $var1 = $var1;
    }
    
    print((String)2.23e-9 . "\n");
    
    # sort
    {
      my $comparator = new package {
        sub compare : int ($self : self, $object1 : Object, $object2 : Object) {
          my $minimal1 = (TestCase::Minimal)$object1;
          my $minimal2 = (TestCase::Minimal)$object2;
          
          my $x1 = $minimal1->{x};
          my $x2 = $minimal2->{x};
          
          if ($x1 > $x2) {
            return 1;
          }
          elsif ($x1 < $x2) {
            return -1;
          }
          else {
            return 0;
          }
        }
      };
      
      my $minimals = new TestCase::Minimal[3];
      $minimals->[0] = new TestCase::Minimal;
      $minimals->[0]{x} = 3;
      $minimals->[1] = new TestCase::Minimal;
      $minimals->[1]{x} = 1;
      $minimals->[2] = new TestCase::Minimal;
      $minimals->[2]{x} = 2;
      
      sort_obj($minimals, $comparator);
      print((String)$minimals->[0]{x} . " " . (String)$minimals->[1]{x} . " " . (String)$minimals->[2]{x} . "\n");
    }
    
    # Anon package
    {
      my $point = new package {
        has x : int;
        has y : int;
        sub clear : void ($self : self) {
          $self->{x} = 0;
          $self->{y} = 0;
        }
      };
      
      $point->{x} = 3;
      print((String)$point->{x} . "\n");
      $point->clear;
      print((String)$point->{x} . "\n");
    }
    
    if (!(1 == 2)) {
      
    }
    
    # isa
    {
      my $minimal = new TestCase::Minimal;
      if ($minimal isa TestCase::Minimal) {
        print("isa OK\n");
      }
      if ($minimal isa TestCase::Simple) {
        print("isa NOT OK\n");
      }
    }
    
    # String comparison operator
    {
      my $string1 = "abc";
      my $string2 = "abc";
      
      if ($string1 eq $string2) {
        print("String is same\n");
      }
    }
    {
      my $string1 = "abc";
      my $string2 = "ab";
      
      if ($string1 ne $string2) {
        print("String is different\n");
      }
    }
    
    my $byte_string = (String)(byte)23;
    my $short_string = (String)(short)23;
    my $int_string = (String)23;
    my $long_string = (String)23L;
    my $float_string = (String)0.25f;
    my $double_string = (String)0.25;
    
    print($byte_string . "\n");
    print($short_string . "\n");
    print($int_string . "\n");
    print($long_string . "\n");
    print($float_string . "\n");
    print($double_string . "\n");
    
    {
      my $object : Object = new TestCase::Minimal;
      my $implement_interface1 : TestCase::Interface = new TestCase::ImplementInterface1;
      my $implement_interface2 : TestCase::Interface = new TestCase::ImplementInterface2;
      
      print((String)$implement_interface1->foo(0, 0) . "\n");
      print((String)$implement_interface2->foo(0, 0) . "\n");
      
      my $minimal = (TestCase::Minimal)$object;
      
      $minimal->{x} = 4;
    }
    
    my $num : byte = 127;
    
    eval {
      exception_croak_return_object();
    };

=pod
    {
      my $NUM = 0;
    }
=cut
    
    {
      my $num = sum0(1, 2);
      print((String)$num . "\n");
    }
    
    {
      $TestCase::PACKAGE_VAR_TEST_CASE = undef;
    }

    {
      my $num = 0xFFFFFFF0;
      my $num2 = ~$num;
    }
    {
      my $values = new int[] {1, 2, 3};
      
      print((String)$values->[0] . "\n");
    }

    {
      my $values : int[];
      $values = new int[] {1, 2, 3};
    }

    {
      my $var = $PACKAGE_VAR_INT;
      
      $PACKAGE_VAR_INT = 1;
      
      if ($PACKAGE_VAR_INT == 0) {
        $PACKAGE_VAR_INT = 1;
        if ($PACKAGE_VAR_INT == 1) {
          return 1;
        }
      }
      my $str = "" . (String)$PACKAGE_VAR_INT;
    }
    
    {
      my $var = $TestCase::PACKAGE_VAR_INT;
      
      $TestCase::PACKAGE_VAR_INT = 1;
      
      if ($TestCase::PACKAGE_VAR_INT == 0) {
        $TestCase::PACKAGE_VAR_INT = 1;
        if ($TestCase::PACKAGE_VAR_INT == 1) {
          return 1;
        }
      }
      my $str = "" . (String)$TestCase::PACKAGE_VAR_INT;
    }
    
    
=pod
    {
      my $simple1 = new TestCase::Simple;
      $simple1->{private_field};
    }
=cut

    {
      my $test_case = new TestCase;
      $test_case->{private_field};
    }
    
    {
      my $time = time();
      
      print((String)$time . "\n");
    }

    warn("warn");
    warn((String)1);
    warn((String)1L);
    warn((String)0.5f);
    warn((String)0.5);

    warn("warn");
    warn((String)1);
    warn((String)1L);
    warn((String)0.5f);
    warn((String)0.5);
    
    # .
    {
      my $foo = "abc" . "def";
    }
    
    {
      my $num = 1;
      
      $num += 4;
      
      print((String)$num . "\n");
    }
    
    {
      TestCase->error_eval_call();
    }
    
    {
      # error_call_stack();
    }
    
    {
      my $ret = error_eval();
      
      print((String)$ret . "\n");
    }
    
    error_eval();
    
    my $dest = TestCase::Destructor->new();
    
    # enum
    {
      TestCase->BYTE_MAX();
      TestCase->BYTE_MIN();
      TestCase->SHORT_MAX();
      TestCase->SHORT_MIN();
      TestCase->INT_MAX();
      TestCase->INT_MIN();
      TestCase->LONG_MAX();
      TestCase->LONG_MIN();
    }
    # Field set and get
    {
      my $test = new TestCase;
      
      $test->{x_byte} = TestCase->BYTE_MAX();
      $test->{x_short} = TestCase->SHORT_MAX();
      $test->{x_int} = TestCase->INT_MAX();
      $test->{x_long} = TestCase->LONG_MAX();
      $test->{x_float} = TestCase->FLOAT_PRECICE();
      $test->{x_double} = TestCase->DOUBLE_PRECICE();
    }
    
    # Weaken
    {
      my $num = TestCase->weaken_reference_count1_object();
    }
    
    # Weaken
    {
      my $test = new TestCase;
      
      $test->{next_test} = $test;
      
      weaken $test->{next_test};
    }
    
    TestCase->call_void();
    
    print("a" . "\n");
    
    # Default return value object
    if (TestCase->default_return_value_object_sub() == undef) {
      if (TestCase->default_return_value_object_sub_empty() == undef) {
        1;
      }
    }

    # Get object from freelist
    {
       TestCase->check_freelist();
       
       my $result = new int[65];
       $result->[64] = 0;
    }
    
    my $ppp = new int[] {
      1,
      2,
      3
    };
    
    # Logical or
    {
      if (1 || 0) {
        print("Logical or" . "\n");
      }
    }

    # Logical and
    {
      if (1 && 1) {
        print("Logical and" . "\n");
      }
    }
    
    # Constant e
    {
      my $num = 0.25E+3;
      print((String)$num . "\n");
    }

    # Constant e
    {
      my $num = 0.25E-3f;
      print((String)$num . "\n");
    }
    # Convert to string to byte[]
    {
      my $string = "abc";
      # my $byte = $string->[0];
    }
    
    # MIN long constant;
    {
      my $num = -9223372036854775808L;
      print((String)$num . "\n");
    }
    {
      my $var = 3;
      while (my $var = 964) {
        print((String)$var . "\n");
        last;
      }
    }
    
    {
      my $error = "First";
      $@ = "Error";
      if (my $error = $@) {
        print((String)$error . "\n");
      }
    }
    
    # Check for third part bug
    {
      for (my $i = 0; $i < 260; $i++) {
      }
    }
    
    # Exception variable
    {
      $@ = "Exception";
      print((String)$@ . "\n");
    }
    
    # $array->[0]{x}
    {
      my $objs = new TestCase::Minimal[3];
      $objs->[0] = TestCase::Minimal->new();
      $objs->[0]{x} = 111;
      print((String)$objs->[0]{x} . "\n");
    }
    
    # $obj->{x}[0]
    {
      my $obj = TestCase::Simple->new();
      $obj->{values1} = new int[5];
      $obj->{values1}[0] = 221;
      print((String)$obj->{values1}[0] . "\n");
    }
    
    # Call new subroutine without variable
    {
      TestCase::Minimal->new();
      sum0(1, 3);
    }
    
    # Create temporary varialbe
    {
      TestCase::Minimal->new();
      TestCase::Minimal->new();
      TestCase::Minimal->new()->{x};
    }
    
    my $obj1 = TestCase::Minimal->new();
    
    # last
    {
      while (1) {
        my $obj1 = TestCase::Minimal->new();
        my $obj2 = TestCase::Minimal->new();
        {
          my $obj3 = TestCase::Minimal->new();
          last;
          next;
        }
      }
    }
    # String escape character
    {
      my $string = "abc\"\'\\\n\t\b\r\fdef";
     
      print((String)$string . "\n");
    }
    
    # Escape sequence
    {
      my $ch1 = '\"';
      my $ch2 = '\'';
      my $ch3 = '\\';
      my $ch4 = '\n';
      my $ch5 = '\t';
      my $ch6 = '\b';
      my $ch7 = '\r';
      my $ch8 = '\f';
    }
    
    # char null string
    {
      my $ch : byte = (byte)0x04;
    }
    
    # char
    {
      my $ch : byte = 'a';
    }
    
    # Malloc mutil array
    {
      my $nums : int[][] = new int[][3];
      $nums->[0] = new int[1];
      $nums->[0][0] = 178;
      print((String)$nums->[0][0] . "\n");
    }
    
    # Declare mutil array
    {
      my $nums : int[][];
    }
    
    # Core functions
    {
      print((String)(byte)1 . "\n");
      print((String)(short)1 . "\n");
      print((String)1 . "\n");
      print((String)1L . "\n");
      print((String)1f . "\n");
      print((String)1.0 . "\n");
      print("end\n");
    }

    {
      my $nums = new int[258];
      my $len = @$nums;
      for (my $i = 0; $i < $len; $i++) {
        $nums->[$i] = $i;
      }

      for (my $i = 0; $i < @$nums; $i++) {
        $nums->[$i] = $i;
      }
    }
    
    # length with {} Too many elements over 4G
    {
      my $nums = new int[150000000];
      my $len = @{$nums};
      $nums->[149999999] = 764;
      print((String)$nums->[149999999] . "\n");
    }
    
    {
      my $nums = new int[2000000];
      my $len = len $nums;
      my $i = 0;
      for ($i = 0; $i < $len; $i = $i + 1) {
        $nums->[$i] = $i;
      }
      print((String)$i . "\n");
      print((String)$nums->[$i - 1] . "\n");
    }
    
    # Object to get long field is undef
    #{
    #  my $obj : TestCase::Minimal;
    #  $obj{x} = 1L;
    #}

    # Object to get long field is undef
    #{
    #  my $obj : TestCase::Minimal;
    #  $obj{x};
    #}

    # Index is out of range
    #{
    #  my $nums = new int[3];
    #  $nums->[3] = 1;
    #}
    
    # Index is out of range
    #{
    #  my $nums = new int[3];
    #  $nums->[-1] = 3;
    #}

    # Array is undef
    #{
    #  my $nums : int[];
    #  $nums->[0] = 1;
    #}

    # Index is out of range
    #{
    #  my $nums = new int[3];
    #  $nums->[3];
    #}
    
    # Index is out of range
    #{
    #  my $nums = new int[3];
    #  $nums->[-1];
    #}
    
    # Array is undef
    #{
    #  my $nums : int[];
    #  $nums->[0];
    #}
    
    {
      TestCase::Minimal->new();
    }
    
    {
      my $obj1 = TestCase::Minimal->new();
      
      my $obj2 : TestCase::Minimal;
      
      my $obj3 : TestCase::Minimal = undef;
    }
    
    # Increment byte
    {
      my $num = (byte)1;
      $num++;
      print((String)$num . "\n");
    }
    
    # Increment short 
    {
      my $num = (short)1;
      $num++;
      print((String)$num . "\n");
    }
    
    # increment int
    {
      my $var = 4;
      $var++;
      $var--;
      --$var;
      ++$var;
    }
    
    # Increment long
    {
      my $var = (long)4;
      $var++;
      $var--;
      --$var;
      ++$var;
    }
    
    eval {
      sum0(1, 2);
      
      3;
      
      sum0(3, 4);
      
      croak "Catch error";
      
      1;
    };
    
    {
      sum0(5, 6);
      2;
      print("Error" . "\n");
    }
    
    {
      my $string = "ace";
     
      print((String)$string . "\n");
    }

    {
      my $string = "ace";
     
      print((String)$string . "\n");
    }
    
    {
      my $num = (byte)3;
      print((String)$num . "\n");
      
      my $num2 = (long)1 + (long)$num;
      
      print((String)$num2 . "\n");
    }
    
    # get and set field
    {
      my $m = TestCase::Minimal->new();
      
      $m->{x} = 99;
      $m->{y} = 100;
      
      print((String)$m->{x} . "\n");
      print((String)$m->{y} . "\n");
    }

    # Free when assignment
    {
      my $m = TestCase::Minimal->new();
      $m = TestCase::Minimal->new();
    }

    # left is object, right is undef
    {
      my $obj : TestCase::Minimal = undef;
    }
    
    if (1) {
      2;
      if (3) {
        4;
      }
      elsif (8) {
        9;
      }
      else {
        5;
      }
    }
    else {
      6;
    }
    7;
    
    print((String)sum0(1, 1) . "\n");
    print((String)sum2(1, 2) . "\n");

    # Constant float
    print((String)0.3f . "\n");
    print((String)1f . "\n");
    print((String)2f . "\n");
    print((String)1.2f . "\n");
    
    # Constant double
    print((String)0d . "\n");
    print((String)1d . "\n");
    print((String)1.2 . "\n");

    # Constant int
    print((String)-2147483648 . "\n");
    print((String)-32769 . "\n");
    print((String)-32768 . "\n");
    print((String)-129 . "\n");
    print((String)-128 . "\n");
    print((String)-2 . "\n");
    print((String)-1 . "\n");
    print((String)0 . "\n");
    print((String)1 . "\n");
    print((String)2 . "\n");
    print((String)3 . "\n");
    print((String)4 . "\n");
    print((String)5 . "\n");
    print((String)6 . "\n");
    print((String)127 . "\n");
    print((String)128 . "\n");
    print((String)255 . "\n");
    print((String)256 . "\n");
    print((String)32767 . "\n");
    print((String)32768 . "\n");
    print((String)65535 . "\n");
    print((String)65536 . "\n");
    print((String)2147483647 . "\n");
    
    # Constant long
    print((String)-1L . "\n");
    print((String)0L . "\n");
    print((String)1L . "\n");
    print((String)2L . "\n");
    print((String)9223372036854775807L . "\n");
    print((String)-9223372036854775807L . "\n");
    print((String)-2147483648L . "\n");
    print((String)-32769L . "\n");
    print((String)-32768L . "\n");
    print((String)-129L . "\n");
    print((String)-128L . "\n");
    print((String)-2L . "\n");
    print((String)-1L . "\n");
    print((String)0L . "\n");
    print((String)1L . "\n");
    print((String)2L . "\n");
    print((String)3L . "\n");
    print((String)4L . "\n");
    print((String)5L . "\n");
    print((String)6L . "\n");
    print((String)127L . "\n");
    print((String)128L . "\n");
    print((String)255L . "\n");
    print((String)256L . "\n");
    print((String)32767L . "\n");
    print((String)32768L . "\n");
    print((String)65535L . "\n");
    print((String)65536L . "\n");
    print((String)2147483647L . "\n");
    print((String)0xFFL . "\n");
    
    "abc";
    
    # Table switch int
    {
      my $num = 3;
      
      switch($num) {
        case TestCase::EnumD->THREE():
          print((String)1 . "\n");
          last;
        case TestCase::EnumD->FORE():
          print((String)2 . "\n");
          last;
        case 5:
          print((String)3 . "\n");
          last;
        default:
          print((String)5 . "\n");
      }
    }

    # Lookup switch int
    {
      my $num = 3;
      switch ($num) {
        case 1:
          print((String)1 . "\n");
          last;
        case 3:
          print((String)2 . "\n");
          last;
        case 10000:
          print((String)2 . "\n");
          last;
        default:
          print((String)5 . "\n");
      }
    }
    
    # {
    #   my $num = 5;
    #   switch($num) {
    #     default:
    #       print((String)5 . "\n");
    #   }
    # }
    
    # my $num;
    # my $num1 = undef;
    
    if (1) {
      3;
      if (2) {
        4;
      }
      5;
    }
    6;

    my $simple3 : TestCase::Simple = TestCase::Simple->new();
    
    print((String)$simple3->{x} . "\n");
    $simple3->{x};
    
    $simple3->{y} = 2;
    $simple3->{x};
    $simple3->{y};

    my $simple2 : TestCase::Simple = TestCase::Simple->new();
    
    if (1) { }
    
    if (1 == 1) {
    
    }

    if (1 != 1) {
    
    }

    if (1 <= 1) {
    
    }

    if (1 < 1) {
    
    }

    if (1 >= 1) {
    
    }

    if (1 > 1) {
    
    }

    if (!1) { }
    
    if (1L) { }
    if (1.5) { }
    if ($simple2) { }
    
    if (undef) {
    
    }
    
    if ($simple2 == undef) {
      
    }

    if (undef == $simple2) {
      
    }
    
    if (undef == undef) {
    
    }
    if (undef != undef) {
    
    }
    
    if (5L || 6L) {
    
    }

    if (5L && 6L) {
    
    }
    if (!1L) {
    
    }
    
    if (1L > 2L) {
      3L;
      4L;
    };
    5L;

    if (1.2 > 2.0) {};
    if (1.2 >= 2.0) {};
    if (1.2 < 2.0) {};
    if (1.2 <= 2.0) {};

    if (1.2 == 1.0) { }
    if (1.2 != 2.0) { };

    if (1 > 2) {};
    if (1 >= 2) {};
    if (1 < 2) {};
    if (1 <= 2) {};

    if (1 == 1) { }
    if (1 != 2) { };

    {
      my $nums = new int[3];
      $nums->[0] = 13;
      $nums->[1] = 14;
      print((String)$nums->[0] . "\n");
      print((String)$nums->[1] . "\n");
    }
    
    {
      my $nums : long[] = new long[3];
      $nums->[0] = 11L;
      $nums->[1] = 12L;
      print((String)$nums->[0] . "\n");
      print((String)$nums->[1] . "\n");
      print((String)@$nums . "\n");
      my $nums_length : int = @$nums;
    }
    
    my $simple : TestCase::Simple = TestCase::Simple->new();
    
    
    my $v1 : int;
    my $v2 : int;
    my $v3 : int;
    
    $v3 = $v2 = $v1 = 543;
    print((String)$v3 . "\n");
    
    100;
    1000;
    1 << 2;
    1 >> 2;
    1 >>> 2;
    
    TestCase::EnumA->ONE();
    TestCase::EnumA->TWO();
    
    TestCase::EnumA->ONE();
    TestCase::EnumA->ONE();
    
    # Basic operation byte
    {
    
    }
    
    # Basic operation short
    {
    
    }
    
    # Basic operation int
    {
      1 ^ 4;
      1 & 2;
      1 | 2;
      -3 + +2;
      3 - (1 + 2);
      5 + 19;
      1 + 2;
      1 - 2;
      1 * 2;
      1 / 3;
      4 % 6;
    }
    
    # Basic operation long
    {
      1L ^ 4L;
      1L & 2L;
      1L | 2L;
      -3L + +2L;
      3L - (1L + 2L);
      5L + 19L;
      1L + 2L;
      1L - 2L;
      1L * 2L;
      1L / 3L;
      4L % 6L;
    }
    
    1.2 / 3.0;
    1.2f / 3.0f;
    1.2 * 4.0;
    1.2f * 4.0f;
    1.2 + 3.0;
    1.2f + 3.0f;
    1.2 - 3.0;
    1.2f - 3.0f;
    
    # Compare long
    {
      if (1L > 2L) {};
      if (1L >= 2L) {};
      if (1L < 2L) {};
      if (1L <= 2L) {};
      if (1L == 1L) { }
      if (1L != 2L) { };
    }
    
    my $bar : double = (double)1;
    undef;
    
    sum0(1, 2);
    sum0(1, 2);
    
    test1();
    
    while (1) {
      1;
      last;
    }
    
    # for (my $i : int = 0; $i < 5; $i = $i + 1) {
    #   1;
    #   last;
    #   next;
    # }

    {
      my $num0 = (byte)0;
      my $num1 = (byte)1;
      my $num2 = (byte)2;
      my $num3 = (byte)((int)$num0 + (int)$num1 + (int)$num2);
      print((String)$num3 . "\n");
    }

    {
      my $num0 = (short)0;
      my $num1 = (short)1;
      my $num2 = (short)2;
      my $num3 = (short)((int)$num0 + (int)$num1 + (int)$num2);
      print((String)$num3 . "\n");
    }

    # my $error : String = "Error";
    # croak $error;
    
    return $mvar + 3;
  }

  # Call void function
  sub call_void_sub : void ($nums : int[]) {
    $nums->[0] = 5;
  }
  sub call_void : int () {
    my $nums = new int[] {1};
    
    call_void_sub($nums);
    
    if ($nums->[0] == 5) {
      return 1;
    }
    return 0;
  }
  
  sub test1 : int () {
    my $num0 = 1;
    my $num1 = 2;
    my $num2 = 3;
    my $num3 = 4;
    my $num4 = 5;
    
    return 0;
  }
  
  sub sum4 : long ($num1 : long, $num2 : long) {
    return $num1 + $num2;
  }
  
  sub sum3 : int ($simple : TestCase::Simple, $foo : long, $bar : float) {
    
    if (3) {
    
    }
    
    if (3) {
      1;
    }
    elsif (4) {
      4;
    }
    else {
      
    }

    if (3) {
      1;
    }
    elsif (4) {
      4;
    }
    elsif (5) {
    
    }
    else {
      
    }
    
    if (1) {
      
    }
    else {
      
    }
    
    array_new();
    
    return 2;
  }
  
  sub sum1 : long ($num1 : long, $num2 : long) {
    return $num1 + $num2;
  }
  sub sum0 : int ($num1 : int, $num2 : int) {
    return $num1 + $num2;
  }
  
  sub sum2 : int ($num1 : int, $num2 : int) {
    # croak "Error";
    
    my $num3 = sum0($num1, $num2);
    
    return $num3 + 3;
  }

  sub increfcount : int ($test : TestCase::Minimal, $num : int) {
    
    my $aaa = TestCase::Minimal->new();
  }

  sub decinctest : int ($num1 : TestCase::Minimal, $num2 : int, $num3 : TestCase::Minimal) {
    {
      my $num4 = TestCase::Minimal->new();
      my $num5 = TestCase::Minimal->new();
    }
    return 2;
  }

  sub return_object : TestCase::Minimal () {
    my $obj0 = TestCase::Minimal->new();
    {
      my $obj1 = TestCase::Minimal->new();
      
      my $obj2 : TestCase::Minimal;
      
      my $obj3 : TestCase::Minimal = undef;

      return $obj2;
    }
  }

  sub eval_block : void () {
    my $obj0 = TestCase::Minimal->new();
    
    eval {
      my $obj1 = TestCase::Minimal->new();
      
      my $obj2 : TestCase::Minimal;
      
      my $obj3 : TestCase::Minimal = undef;
      
      my $obj_error1 = "Error1";
      
      croak $obj_error1;
    };
    
    {
      my $obj4 = TestCase::Minimal->new();
      
      my $obj5 : TestCase::Minimal;
      
      my $obj6 : TestCase::Minimal = undef;
      
      my $obj_error2 = "Error2";
      
      croak $obj_error2;
    }
  }
  sub array_new : int () {
    
    my $nums = new int[3];
    
    return @$nums;
  }
  sub check_freelist : int[] () {
    my $result = new int[63];
    my $true_result = new int[1];
    return $true_result;
  }
  sub default_return_value_object_sub : TestCase () {
    1;
  }
  sub default_return_value_object_sub_empty : TestCase () {
    
  }
  sub weaken_reference_count1_object : int (){
    my $minimal = TestCase::Minimal->new();
    my $test = new TestCase;
    
    $test->{minimal} = $minimal;
    $minimal = undef;
    weaken $test->{minimal};
    
    if ($test->{minimal} == undef) {
      return 1;
    }
    
    return 0;
  }
  
  sub error : int () {
    croak "ERROR";
  }
  
  sub error_call_stack : int () {
    error();
  }

  sub error_eval : int () {
    eval {
      croak "ERROR";
    };
    
    if ($@) {
      return 1;
    }
    else {
      return 0;
    }
  }

  sub error_eval_call : int () {
    eval {
      error();
    };
    
    if ($@) {
      return 1;
    }
    else {
      return 0;
    }
  }
  sub exception_croak_return_object : TestCase::Minimal () {
    croak "Error";
  }
  sub new : TestCase () {
    return new TestCase;
  }

  sub call_sub_args_convertion_stab1 : double ($var6 : double) {
    return ($var6);
  }
  
  sub call_sub_args_convertion : int () {
    my $return_value1 = call_sub_args_convertion_stab1(16);
    return 0;
  }

  sub sort_obj : void ($values : Object[], $comparator : TestCase::Comparator) {

    my $change_cnt = @$values - 1;
    while( $change_cnt > 0){
      for (my $i = 0; $i < $change_cnt; $i++) {
        my $ret = $comparator->compare($values->[$i], $values->[$i + 1]);
        
        if ($comparator->compare($values->[$i], $values->[$i + 1]) == 1) {
          my $tmp_value = $values->[$i];
          $values->[$i] = $values->[$i + 1];
          $values->[$i + 1] = $tmp_value;
        }
      }
      $change_cnt--;
    }
  }
  sub receive_undef : void ($test_case : TestCase) {
    
  }

}

=head1 NAME

SPVM::Test - SPVM test module