Skip to content

Commit

Permalink
Attempt to support nested pointy blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
leto committed Jul 30, 2010
1 parent f06bf9b commit 849e6a8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
27 changes: 19 additions & 8 deletions plperl6.pir
@@ -1,20 +1,31 @@
.sub run
.param string code
.param pmc args :slurpy

args = convert_to_perl6_parcel(args)
$S0 = "eval q<<< sub (@_) {"
$S1 = "} >>>"
code = $S0 . code
code .= $S1
.local string wrap_start, wrap_end
wrap_start = "eval q<<< sub (@_) {"
wrap_end = "} >>>"
code = wrap_start . code
code .= wrap_end
load_bytecode 'dumper.pbc'
print "About to run: "
say code
$P0 = compreg "perl6"
$P1 = $P0.'compile'(code)

.local pmc compiler, function, output
compiler = compreg "perl6"
function = compiler.'compile'(code)
say "args="
_dumper(args)
$P2 = $P1()
$P3 = $P2(args)
output = function()
$P3 = output(args)
$I0 = isa $P3, "Block"
unless $I0 goto done
# the output of running the function returned a Block,
# such as a pointy block -> $a, $b { }, so let's go ahead
# and execute that
$P3 = $P3(args)
done:
print "code returned: "
_dumper($P3)
say "=============="
Expand Down
7 changes: 7 additions & 0 deletions t/sql/plperl6.sql
Expand Up @@ -42,6 +42,12 @@ my $limit = @_[0];
[+] (1, 1, *+* ... $limit)
$$;

CREATE OR REPLACE FUNCTION test_named_pointy(integer, integer, integer) RETURNS int LANGUAGE plperl6 AS $$
-> $a, $b, $c {
return [*], $a, $b, $c;
};
$$;

CREATE OR REPLACE FUNCTION test_float_plperl6(integer) RETURNS float AS $$ 5.0 $$ LANGUAGE plperl6;

CREATE OR REPLACE FUNCTION test_string_plperl6() RETURNS varchar AS $$ "rakudo" $$ LANGUAGE plperl6;
Expand All @@ -59,6 +65,7 @@ select is(test_arguments_plperl6(5),5,'We can return an argument unchanged');
select is(test_defined_plperl6(100),1,'@_[0] is defined when an argument is passed in');
select is(test_2arguments_plperl6(4,9),2,'PL/Perl sees multiple arguments');

select is(test_named_pointy(10,20,30), 6000, 'Pointy blocks with named parameters work');

-- Finish the tests and clean up.
SELECT * FROM finish();
Expand Down

0 comments on commit 849e6a8

Please sign in to comment.