Skip to content

Commit

Permalink
RakuAST: reorganize variable stub logic a bit
Browse files Browse the repository at this point in the history
MasterDuke++ for the nudge
  • Loading branch information
lizmat committed Sep 13, 2023
1 parent 636c878 commit 42c2f5a
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/Raku/Actions.nqp
Expand Up @@ -1896,43 +1896,43 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions {
my $/ := $*VARIABLE-MATCH;

my str $scope := $*SCOPE;
my $type := $*OFTYPE ?? $*OFTYPE.ast !! Nodify('Type');
my $type := $*OFTYPE ?? $*OFTYPE.ast !! Nodify('Type');
my str $sigil := $<sigil>;

my $decl;
if $<desigilname> {
my $desigilname := $<desigilname>;
my $ast := $desigilname<longname>
?? $desigilname<longname>.ast
!! Nodify('Name').from-identifier(~$desigilname);
my str $sigil := $<sigil>;
$ast.IMPL-CHECK($*R, $*CU.context, 1);

my str $twigil := $<twigil> || '';
my str $name := $sigil ~ $twigil ~ $ast.canonicalize;
my $shape := $<semilist> ?? $<semilist>[0].ast !! Nodify('SemiList');
$ast.IMPL-CHECK($*R, $*CU.context, 1);
my $dynprag := $*LANG.pragma('dynamic-scope');
my $forced-dynamic := $dynprag
?? $dynprag($sigil ~ $twigil ~ $ast.canonicalize)
!! 0;
my $forced-dynamic := $dynprag ?? $dynprag($name) !! 0;
$decl := Nodify('VarDeclaration', 'Simple').new:
:$scope, :$type, :desigilname($ast), :$sigil, :$twigil,
:$scope, :$type, :$sigil, :$twigil, :desigilname($ast),
:$shape, :$forced-dynamic;
if $scope eq 'my' || $scope eq 'state' || $scope eq 'our' {
my str $name := $<sigil> ~ ($<twigil> || '') ~ $ast;
$/.typed-worry('X::Redeclaration', :symbol($name))
if $*R.declare-lexical($decl);
}

$/.typed-worry('X::Redeclaration', :symbol($name))
if ($scope eq 'my' || $scope eq 'state' || $scope eq 'our')
&& $*R.declare-lexical($decl);

self.set-declarand($/, $decl);
}
else {
$scope ne 'my' && $scope ne 'state'
?? $/.panic(
"Cannot declare an anonymous {$scope}-scoped variable"
"Cannot declare an anonymous '$scope' scoped variable"
)
!! $<twigil>
?? $/.panic(
"Cannot declare an anonymous variable with a twigil"
)
!! ($decl := Nodify('VarDeclaration', 'Anonymous').new(
:$scope, :$type, :sigil(~$<sigil>)
:$scope, :$type, :$sigil
));
}

Expand Down

0 comments on commit 42c2f5a

Please sign in to comment.