Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement the constant declator, with and without sigils (they aren't…
… actually constant yet though)
  • Loading branch information
sorear committed Jul 20, 2010
1 parent d48aa80 commit 007fab2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
18 changes: 18 additions & 0 deletions Niecza/Actions.pm
Expand Up @@ -753,6 +753,24 @@ sub variable_declarator { my ($cl, $M) = @_;
}
}

sub type_declarator {}
sub type_declarator__S_constant { my ($cl, $M) = @_;
my $scope = $::SCOPE // 'my';
if (!$M->{identifier} && !$M->{variable}) {
$M->sorry("Anonymous constants NYI"); #wtf?
return;
}
my $slot = ($M->{identifier} // $M->{variable})->Str;

# This is a cheat. Constants should be, well, constant, and we should be
# using the phaser rewrite mechanism to get the initializer here. XXX
# terms need to use a context hash.
push @{ $::CURLEX->{'!decls'} //= [] },
Decl::SimpleVar->new(slot => $slot);

$M->{_ast} = Op::Lexical->new(name => $slot);
}

sub package_declarator {}
sub package_declarator__S_class { my ($cl, $M) = @_;
$M->{_ast} = $M->{package_def}{_ast};
Expand Down
9 changes: 8 additions & 1 deletion test.pl
Expand Up @@ -10,7 +10,7 @@ ($num)
say ("1.." ~ $num);
}

plan 89;
plan 91;

ok 1, "one is true";
ok 2, "two is also true";
Expand Down Expand Up @@ -279,3 +279,10 @@ ($num)
ok "Hi" ~~ Str, "types match identity";
ok (?0) ~~ (?1), "bools are a constant";
}

{
constant foo = 42;
constant $bar = 51;
ok foo == 42, "constants without sigils work";
ok $bar == 51, "constants with sigils work";
}

0 comments on commit 007fab2

Please sign in to comment.