Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement START statements (not terms yet). Add S04-closure-traits/st…
…art.t to spectest.data.
  • Loading branch information
jnthn committed Mar 25, 2009
1 parent 9a84c35 commit f11ad52
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
41 changes: 34 additions & 7 deletions src/parser/actions.pm
Expand Up @@ -403,6 +403,26 @@ method begin_statement($/) {
make PAST::Block.new();
}

method start_statement($/) {
# Create block.
my $past := $( $<block> );
$past.blocktype('immediate');
declare_implicit_routine_vars($past);

# Mark block as needing to load state.
our @?BLOCK;
block_has_state(@?BLOCK[0]);

# We now need to emit code to run the block only once, and store the
# result. We'll just piggy-back off state vars.
make PAST::Var.new(
:scope('state'),
:name($past.unique('start_block_')),
:viviself($past),
:isdecl(1)
);
}

method end_statement($/) {
my $past := $( $<block> );
$past.blocktype('declaration');
Expand Down Expand Up @@ -1888,13 +1908,7 @@ method scope_declarator($/) {
else { $past.name('infix:,'); $past.pasttype('call'); }
if $scope eq 'state' {
$past<scopedecl> := $scope;
unless $block<needs_state_loaded> {
$block[0].push(PAST::Op.new(
:pasttype('call'),
:name('!state_var_init')
));
$block<needs_state_loaded> := 1;
}
block_has_state($block);
}
}
make $past;
Expand Down Expand Up @@ -3124,6 +3138,19 @@ sub prevent_null_return($block) {
}
}


# This takes a block and ensures we emit code to load any associated state
# (START blocks, state variables) at block entry.
sub block_has_state($block) {
unless $block<needs_state_loaded> {
$block[0].push(PAST::Op.new(
:pasttype('call'),
:name('!state_var_init')
));
$block<needs_state_loaded> := 1;
}
}

# Local Variables:
# mode: cperl
# cperl-indent-level: 4
Expand Down
7 changes: 7 additions & 0 deletions src/parser/grammar.pg
Expand Up @@ -262,6 +262,7 @@ rule statement_control {
| <for_statement> {*} #= for_statement
| <use_statement> {*} #= use_statement
| <begin_statement> {*} #= begin_statement
| <start_statement> {*} #= start_statement
| <end_statement> {*} #= end_statement
| <catch_statement> {*} #= catch_statement
| <control_statement> {*} #= control_statement
Expand Down Expand Up @@ -345,6 +346,12 @@ rule begin_statement {
{*}
}

rule start_statement {
$<sym>=[START]
<block>
{*}
}

rule end_statement {
$<sym>=[END]
<block>
Expand Down
1 change: 1 addition & 0 deletions t/spectest.data
Expand Up @@ -121,6 +121,7 @@ S03-operators/value_equivalence.t
S04-blocks-and-statements/pointy-rw.t
S04-blocks-and-statements/pointy.t
S04-closure-traits/end.t
S04-closure-traits/start.t
S04-declarations/implicit-parameter.t
S04-declarations/multiple.t
S04-declarations/my.t
Expand Down

0 comments on commit f11ad52

Please sign in to comment.