Skip to content

Commit

Permalink
RakuAST: get more canonicalization of names correct
Browse files Browse the repository at this point in the history
Now correctly canoniclizes $today:foo["a","b"]:bar:baz["πŸ˜‚"] to
$today:foo<a b>:bar:baz<πŸ˜‚>
  • Loading branch information
niner committed Apr 30, 2023
1 parent 904d312 commit eef4a7c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Raku/Actions.nqp
Expand Up @@ -1423,6 +1423,7 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions {
}

method compile_variable_access($/, $sigil, $twigil, $desigilname) {
$desigilname.IMPL-CHECK($*R, $*CU.context, 1);
my str $name := $sigil ~ $twigil ~ $desigilname.canonicalize;
if $twigil eq '' && $desigilname.is-empty {
# Generate an anonymous state variable.
Expand Down Expand Up @@ -1721,6 +1722,7 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions {
my str $sigil := $<sigil>;
my str $twigil := $<twigil> || '';
my $shape := $<semilist> ?? $<semilist>[0].ast !! self.r('SemiList');
$desigilname.IMPL-CHECK($*R, $*CU.context, 1);
$decl := self.r('VarDeclaration', 'Simple').new:
:$scope, :$type, :$desigilname, :$sigil, :$twigil, :$shape;
if $scope eq 'my' || $scope eq 'state' || $scope eq 'our' {
Expand Down
10 changes: 10 additions & 0 deletions src/Raku/ast/circumfix.rakumod
Expand Up @@ -81,6 +81,16 @@ class RakuAST::Circumfix::ArrayComposer
method visit-children(Code $visitor) {
$visitor($!semilist);
}

method IMPL-CAN-INTERPRET() {
my @statements := self.IMPL-UNWRAP-LIST(self.semilist.statements);
nqp::elems(@statements) == 1 && @statements[0].IMPL-CAN-INTERPRET
}

method IMPL-INTERPRET(RakuAST::IMPL::InterpContext $ctx) {
my @statements := self.IMPL-UNWRAP-LIST(self.semilist.statements);
@statements[0].IMPL-INTERPRET($ctx);
}
}

# Hash composer circumfix. In Raku syntax, blocks and hash composers are
Expand Down
2 changes: 2 additions & 0 deletions src/Raku/ast/pair.rakumod
Expand Up @@ -87,6 +87,8 @@ class RakuAST::ColonPair

method canonicalize() {
my $value := self.simple-compile-time-quote-value;
$value := self.value.IMPL-INTERPRET(RakuAST::IMPL::InterpContext.new)
if !$value && self.value.IMPL-CAN-INTERPRET;
$!key ~ ($value ?? self.IMPL-QUOTE-VALUE($value) !! self.value.DEPARSE)
}

Expand Down
2 changes: 1 addition & 1 deletion src/Raku/ast/variable-declaration.rakumod
Expand Up @@ -432,7 +432,7 @@ class RakuAST::VarDeclaration::Simple
RakuAST::Doc::Declarator :$WHY
) {
my $obj := nqp::create(self);
if nqp::chars($desigilname.canonicalize) == 0 {
if $desigilname.is-empty {
nqp::die('Cannot use RakuAST::VarDeclaration::Simple to declare an anonymous variable; use RakuAST::VarDeclaration::Anonymous');
}

Expand Down

0 comments on commit eef4a7c

Please sign in to comment.