Permalink
Browse files

[Yapsi] implemented non-immediate blocks

Needed to mark the immediate blocks in an action methods. Immediate blocks
are currently all blocks that are directly under an <expression> that's
directly under a <statement>.
  • Loading branch information...
masak committed Nov 14, 2010
1 parent 74884bf commit dd03f5893c29ac35b784ff7c6a76a301ba1f746d
Showing with 18 additions and 2 deletions.
  1. +17 −2 lib/Yapsi.pm
  2. +1 −0 t/runtime.t
View
@@ -143,6 +143,13 @@ class Yapsi::Perl6::Actions {
die qq[Variable "$p.key()" used but not declared];
}
}
+
+ method statement($/) {
+ if $<expression> && $<expression><block> -> $e {
+ my $block = $e.ast;
+ $block<immediate> = "yes";
+ }
+ }
}
class Yapsi::Compiler {
@@ -176,8 +183,13 @@ class Yapsi::Compiler {
my $register = self.unique-register;
my $block-name = $/.ast<name>;
push @blocksic,
- "$register = closure-from-block '$block-name'",
- "call $register";
+ "$register = closure-from-block '$block-name'";
+ if $/.ast<immediate> {
+ push @blocksic, "call $register";
+ }
+ else {
+ $/.ast<register> = $register;
+ }
}
elsif $key eq 'statement_control_if' {
traverse-bottom-up(
@@ -312,6 +324,9 @@ class Yapsi::Compiler {
make $/{$e}.ast;
}
}
+ if $<block> {
+ make $<block>.ast<register>;
+ }
}
elsif $key eq 'literal' {
my $register = self.unique-register;
View
@@ -47,6 +47,7 @@ my @tests =
"5\n", 'our lookup',
'my $a = 0; my $b = 0; until $a { if $b { $a = 1 }; say ++$b }',
"1\n2\n", 'nested jumps in SIC',
+ 'my $a = { say 42 }', "", 'non-immediate block',
;
for @tests -> $program, $expected, $message {

0 comments on commit dd03f58

Please sign in to comment.