Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Give initialization of state variables START semantics.
  • Loading branch information
jnthn committed Oct 25, 2011
1 parent 1fd3f82 commit 481a027
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Perl6/Actions.pm
Expand Up @@ -1303,6 +1303,11 @@ class Perl6::Actions is HLL::Actions {
PAST::Op.new( :pirop('getinterp P') ), 'lexpad'));
}
}

# Flag state declarators.
if $*SCOPE eq 'state' {
$past<state_declarator> := 1;
}
}
elsif $*SCOPE eq 'our' {
if $*TYPENAME {
Expand Down Expand Up @@ -3129,6 +3134,11 @@ class Perl6::Actions is HLL::Actions {
$past := PAST::Op.new(:pirop('perl6_container_store__0PP'),
$lhs_ast, $rhs_ast);
}
if $lhs_ast<state_declarator> {
$past := PAST::Op.new( :pasttype('if'),
PAST::Op.new( :pirop('perl6_state_needs_init I') ),
$past);
}
return $past;
}

Expand Down
4 changes: 4 additions & 0 deletions src/binder/bind.h
Expand Up @@ -67,6 +67,10 @@ typedef struct {
*/
#define PObj_P6BINDER_ALREADY_CHECKED_FLAG PObj_private0_FLAG

/* Flags that the block has state variables and that this is the first time
* that we are visiting the block and so they need initializing. */
#define PObj_P6LEXPAD_STATE_INIT_FLAG PObj_private1_FLAG

/* Gets the ID of a 6model object PMC. */
INTVAL Rakudo_smo_id(void);

Expand Down
16 changes: 16 additions & 0 deletions src/ops/perl6.ops
Expand Up @@ -1138,6 +1138,22 @@ inline op perl6_current_args_rpa(out PMC) :base_core {
}


/*

=item perl6_state_needs_init(out INT)

Returns a non-zero value if state variables need their initialization
and START blocks should run.

=cut

*/
inline op perl6_state_needs_init(out INT) :base_core {
PMC *cur_ctx = CURRENT_CONTEXT(interp);
$1 = PObj_flag_TEST(P6LEXPAD_STATE_INIT, cur_ctx)
}


/*

=item perl6_is_list(out INT, in PMC)
Expand Down
2 changes: 2 additions & 0 deletions src/pmc/perl6lexpad.pmc
@@ -1,6 +1,7 @@
#include "pmc_perl6lexinfo.h"
#include "../binder/sixmodelobject.h"
#include "../binder/container.h"
#include "../binder/bind.h"
#include "pmc_sub.h"

/* How StatixLexPad looks on the inside. */
Expand Down Expand Up @@ -244,6 +245,7 @@ Return the LexInfo PMC, if any or a Null PMC.
if (PMC_IS_NULL(state_stash)) {
state_stash = pmc_new(interp, enum_class_Hash);
VTABLE_set_attr_keyed(interp, p6sub, Block, CONST_STRING(interp, "$!state_vars"), state_stash);
PObj_flag_SET(P6LEXPAD_STATE_INIT, (PMC *)ctx);
}
else {
cur_state = VTABLE_get_pmc_keyed_str(interp, state_stash, state);
Expand Down

0 comments on commit 481a027

Please sign in to comment.