Skip to content

Commit

Permalink
Implement START term; small refactoring so we can use same code as fo…
Browse files Browse the repository at this point in the history
…r START statement.
  • Loading branch information
jnthn committed Apr 2, 2009
1 parent 3ad32e1 commit 46987f7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
44 changes: 27 additions & 17 deletions src/parser/actions.pm
Expand Up @@ -432,23 +432,7 @@ method begin_statement($/) {
}

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)
);
make make_start_block($/);
}

method end_statement($/) {
Expand Down Expand Up @@ -2503,6 +2487,11 @@ method term($/, $key) {
}


method term_START($/) {
make make_start_block($/);
}


method args($/, $key) {
my $past := build_call( $key eq 'func args'
?? $($<semilist>)
Expand Down Expand Up @@ -3181,6 +3170,27 @@ sub prevent_null_return($block) {
}


# This makes a START block (factored out since used as a term and a statement).
sub make_start_block($/) {
# 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.
return PAST::Var.new(
:scope('state'),
:name($past.unique('start_block_')),
:viviself($past),
:isdecl(1)
);
}

# 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) {
Expand Down
6 changes: 6 additions & 0 deletions src/parser/grammar.pg
Expand Up @@ -638,6 +638,7 @@ token noun {
token term {
[
| 'VAR(' <variable> ')' {*} #= VAR
| <term_START> {*} #= term_START
| <name=named_0ary>
[
| <.unsp>? '.'? '(' <semilist> ')' {*} #= func args
Expand All @@ -655,6 +656,11 @@ token term {
}


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


token args {
| \s <arglist> {*} #= listop args
| <.unsp>? '.'? '(' <semilist> ')' {*} #= func args
Expand Down

0 comments on commit 46987f7

Please sign in to comment.