Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement state $x will start { 42 }
  • Loading branch information
sorear committed Jul 12, 2011
1 parent 22671b9 commit 787b33d
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/niecza
Expand Up @@ -392,6 +392,11 @@ method INFIX($/) {
}
make self.whatever_postcheck($/, $st, $/.ast);
}

method trait_mod:will ($/) {
make { ~$<identifier> => $<pblock>.ast };
}

method variable($/) {
my $sigil = $<sigil> ?? ~$<sigil> !! substr(~$/, 0, 1);
my $twigil = $<twigil> ?? $<twigil>[0]<sym> !! '';
Expand Down Expand Up @@ -465,8 +470,14 @@ method variable_declarator($/) {
if $*MULTINESS {
$/.CURSOR.sorry("Multi variables NYI");
}

my $scope = $*SCOPE // 'my';

my $start;
for @$<trait> -> $t {
if $t.ast<rw> {
} elsif $t.ast<start> && $*SCOPE eq 'state' {
$start = $t.ast<start>;
} else {
$/.CURSOR.sorry("Trait $t.ast.keys.[0] not available on variables");
}
Expand All @@ -475,8 +486,6 @@ method variable_declarator($/) {
$/.CURSOR.sorry("Postconstraints, and shapes on variable declarators NYI");
}

my $scope = $*SCOPE // 'my';

if $scope eq 'augment' || $scope eq 'supersede' {
$/.CURSOR.sorry("Illogical scope $scope for simple variable");
}
Expand Down Expand Up @@ -539,6 +548,16 @@ method variable_declarator($/) {
});
make ::Op::Lexical.new(|node($/), name => $slot, :$list, :$hash);
}

if $start {
my $cv = self.gensym;
$*CURLEX<!sub>.add_state_name(Str, $cv);
make mklet($/.ast, -> $ll {
Op::StatementList.new(|node($/), children => [
Op::Start.new(condvar => $cv, body => mkcall($/, '&infix:<=>',
$ll, self.inliney_call($/, $start))),
$ll ]) });
}
}


Expand Down

0 comments on commit 787b33d

Please sign in to comment.