Skip to content

Commit

Permalink
RakuAST: fix accessing 6.e PseudoStash at compile time
Browse files Browse the repository at this point in the history
6.e PseudoStash needs a $!package if one tries to make lookups in CORE::
  • Loading branch information
niner committed Mar 23, 2024
1 parent 8467b84 commit 196fbee
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
7 changes: 2 additions & 5 deletions src/Raku/ast/name.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,9 @@ class RakuAST::Name
if $*IMPL-COMPILE-DYNAMICALLY && $!parts[0].name eq 'CORE' {
nqp::shift($!parts); #FIXME don't modify please
my $PseudoStash := $PseudoStash-lookup.resolution.compile-time-value;
my $stash := nqp::create($PseudoStash);
my $package := Perl6::Metamodel::ModuleHOW.new_type(:name('CORE'));
my $found-ctx := $context.setting;
nqp::bindattr($stash, Map, '$!storage', nqp::ctxlexpad($found-ctx)),
nqp::bindattr($stash, $PseudoStash, '$!ctx', $found-ctx),
nqp::bindattr_i($stash, $PseudoStash, '$!mode', STATIC_CHAIN),
nqp::setwho(Perl6::Metamodel::ModuleHOW.new_type(:name('CORE')), $stash);
my $stash := $PseudoStash.new($found-ctx, :$package);
$context.ensure-sc($stash);
$result := QAST::WVal.new(:value($stash));
}
Expand Down
11 changes: 10 additions & 1 deletion src/core.c/PseudoStash.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,23 @@ my class PseudoStash is Map {
my int constant PRECISE_SCOPE = 4;
my int constant REQUIRE_DYNAMIC = 8;

method new() {
multi method new() {
my $obj := nqp::create(self);
my $ctx := nqp::ctxcaller(nqp::ctx());
nqp::bindattr($obj, PseudoStash, '$!ctx', $ctx);
nqp::bindattr($obj, Map, '$!storage', nqp::ctxlexpad($ctx));
$obj
}

multi method new(Mu $ctx is raw, :$mode = STATIC_CHAIN) {
my $obj := nqp::create(self);
my Mu $dctx := nqp::decont($ctx);
nqp::bindattr($obj, PseudoStash, '$!ctx', $dctx);
nqp::bindattr($obj, Map, '$!storage', nqp::ctxlexpad($ctx));
nqp::bindattr_i($obj, PseudoStash, '$!mode', nqp::decont($mode));
$obj
}

sub ok-to-include(Mu \value) {
nqp::not_i(nqp::istype(value,Code) && value.is-implementation-detail)
}
Expand Down
13 changes: 12 additions & 1 deletion src/core.e/PseudoStash.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ my class PseudoStash is CORE::v6c::PseudoStash {
# A convenience shortcut
my constant PseudoStash6c = CORE::v6c::PseudoStash;

method new(Mu :$ctx is raw, :$mode = STATIC_CHAIN) {
multi method new(Mu :$ctx is raw, :$mode = STATIC_CHAIN) {
my $stash := nqp::create(self);
my Mu $dctx := nqp::decont($ctx);
$dctx := nqp::ctxcaller(nqp::ctx()) unless nqp::defined($dctx);
Expand All @@ -29,6 +29,17 @@ my class PseudoStash is CORE::v6c::PseudoStash {
nqp::p6bindattrinvres($stash, Map, '$!storage', nqp::hash())
}

multi method new(Mu $ctx is raw, Mu :$package!, :$mode = STATIC_CHAIN) {
my $stash := nqp::create(self);
my Mu $dctx := nqp::decont($ctx);
$dctx := nqp::ctxcaller(nqp::ctx()) unless nqp::defined($dctx);
nqp::bindattr($stash, PseudoStash6c, '$!ctx', nqp::decont($dctx));

This comment has been minimized.

Copy link
@MasterDuke17

MasterDuke17 Mar 27, 2024

Contributor

Is this nqp::decont needed?

nqp::bindattr_i($stash, PseudoStash6c, '$!mode', nqp::decont($mode));
nqp::bindattr($stash, PseudoStash, '$!package', nqp::decont($package));
# See the other method candidate
nqp::p6bindattrinvres($stash, Map, '$!storage', nqp::hash())
}

my Int $id = 0;
method NEW-PACKAGE(:$name = "<anon|{cas($id, {$_ + 1})}>", *%initargs ) is raw is implementation-detail
{
Expand Down

0 comments on commit 196fbee

Please sign in to comment.