2 # Copyright (C) 2005-2007, The Perl Foundation.
7 use lib qw( . lib ../lib ../../lib );
10 use Parrot::Test tests => 6;
12 ##############################
13 # Parrot Calling Conventions: Tail call optimization.
15 $ENV{TEST_PROG_ARGS} = '-Oc';
17 pir_output_is( <<'CODE', <<'OUT', "tail call optimization, final position" );
23 .const .Sub f = "_floor"
24 .const .Sub c = "_funcall"
25 set_args "0,0,0", f, $P1, $P2
26 get_results "0,0", $P3, $P4
28 print "_floor returned "
35 .const .Sub s = "_fib_step"
36 set_args "0,0,0", s, $P1, $P2
37 get_results "0,0,0", $P3, $P4, $P5
39 print "_fib_step returned "
53 get_params "0,0x20", function, argv
54 print "[doing _funcall]\n"
55 $I33 = defined function
58 printerr "_funcall: Bad function.\n"
65 ## Return quotient and remainder as two integers.
69 get_params "0,0", arg1, arg2
77 set_returns "0,0", $P1, $P2
81 ## Return the sum and the two arguments as three integers.
85 get_params "0,0", arg1, arg2
88 set_returns "0,0,0", $P1, arg1, arg2
93 _floor returned 2 values, 6 and 2.
95 _fib_step returned 3 values, 23, 20, and 3.
98 pir_output_is( <<'CODE', <<'OUT', "tail call optimization, intermediate position" );
105 .const .Sub f = "_floor"
106 .const .Sub s = "_fib_step"
107 ($P3, $P4) = _funcall(f, $P1, $P2)
108 print "_floor returned "
115 ($P3, $P4, $P5) = _funcall(s, $P1, $P2)
116 print "_fib_step returned "
129 .param pmc argv :slurpy
131 print "[doing _funcall]\n"
132 $I33 = defined function
133 unless $I33 goto bad_func
135 .return function(argv :flat)
137 printerr "_funcall: Bad function.\n"
141 ## Return quotient and remainder as two integers.
156 ## Return the sum and the two arguments as three integers.
163 .return ($P1, arg1, arg2)
167 _floor returned 2 values, 6 and 2.
169 _fib_step returned 3 values, 23, 20, and 3.
172 pir_output_is( <<'CODE', <<'OUT', "tail call optimization, implicit final return" );
180 .const .Sub f = "_floor"
181 .const .Sub s = "_fib_step"
182 ($P3, $P4) = _funcall(f, $P1, $P2)
183 print "_floor returned "
190 ($P3, $P4, $P5) = _funcall(s, $P1, $P2)
191 print "_fib_step returned "
204 .param pmc argv :slurpy
206 print "[doing _funcall]\n"
207 $I33 = defined function
210 printerr "_funcall: Bad function.\n"
213 .return function(argv :flat)
216 ## Return quotient and remainder as two integers.
231 ## Return the sum and the two arguments as three integers.
246 _floor returned 2 values, 6 and 2.
248 _fib_step returned 3 values, 23, 20, and 3.
251 pir_output_is( <<'CODE', <<'OUT', ":flatten in .return" );
259 .const .Sub s = "_fib_step"
260 ($P3, $P4, $P5) = _funcall(s, $P1, $P2)
261 print "_fib_step returned "
274 .param pmc argv :slurpy
276 $I33 = defined function
277 unless $I33 goto bad_func
279 ($P35 :slurpy) = function(argv :flat)
286 printerr "_funcall: Bad function.\n"
290 ## Return the sum and the two arguments as three integers.
297 .return ($P1, arg1, arg2)
301 _fib_step returned 3 values, 23, 20, and 3.
304 pir_output_is( <<'CODE', <<'OUT', "new tail call syntax" );
322 pir_output_is( <<'CODE', <<'OUT', "new tail method call syntax" );
329 n = 2000 # beyond recursion limit of 1000
330 setattribute o, [ "Foo" ], "n", n
332 n = getattribute o, [ "Foo" ], "n"
340 n = getattribute self, [ "Foo" ], "n"
353 # cperl-indent-level: 4
356 # vim: expandtab shiftwidth=4: