Skip to content

Commit

Permalink
Correct scope definitions and EVAL support
Browse files Browse the repository at this point in the history
- MY is back to PRECISE_SCOPE
- CALLER is PRECISE_SCOPE with only dynamics included
- LEXICAL now includes dynamic symbols implementing the notion of
  'everything visible within this scope'

SETTING pseudo now correctly handles EVAL'ed scopes.
  • Loading branch information
vrurg committed Jul 12, 2019
1 parent 43bf910 commit fb6a7d3
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/core/PseudoStash.pm6
Expand Up @@ -27,7 +27,7 @@ my class PseudoStash is Map {
my $pseudoers := nqp::hash(
'MY', sub ($cur) {
my $stash := nqp::clone($cur);
nqp::bindattr_i($stash, PseudoStash, '$!mode', STATIC_CHAIN +| DYNAMIC_CHAIN);
nqp::bindattr_i($stash, PseudoStash, '$!mode', PRECISE_SCOPE);
$stash.pseudo-package('MY');
},
'CORE', sub ($cur) {
Expand Down Expand Up @@ -57,7 +57,7 @@ my class PseudoStash is Map {
(my $stash := nqp::create(PseudoStash)),
nqp::bindattr($stash, Map, '$!storage', nqp::ctxlexpad($ctx)),
nqp::bindattr($stash, PseudoStash, '$!ctx', $ctx),
nqp::bindattr_i($stash, PseudoStash, '$!mode', STATIC_CHAIN +| REQUIRE_DYNAMIC),
nqp::bindattr_i($stash, PseudoStash, '$!mode', PRECISE_SCOPE +| REQUIRE_DYNAMIC),
$stash.pseudo-package('CALLER')
)
)
Expand All @@ -79,7 +79,7 @@ my class PseudoStash is Map {
},
'LEXICAL', sub ($cur) {
my $stash := nqp::clone($cur);
nqp::bindattr_i($stash, PseudoStash, '$!mode', STATIC_CHAIN);
nqp::bindattr_i($stash, PseudoStash, '$!mode', STATIC_CHAIN +| DYNAMIC_CHAIN);
$stash.pseudo-package('LEXICAL')
},
'OUTERS', sub ($cur) {
Expand Down Expand Up @@ -138,11 +138,22 @@ my class PseudoStash is Map {
# Same as UNIT, but go a little further out (two steps, for
# internals reasons).
my Mu $ctx := nqp::getattr(nqp::decont($cur), PseudoStash, '$!ctx');
until nqp::isnull($ctx) || nqp::existskey(nqp::ctxlexpad($ctx), '!UNIT_MARKER') {
until nqp::isnull($ctx)
|| (nqp::existskey(nqp::ctxlexpad($ctx), '!UNIT_MARKER')
&& !nqp::existskey(nqp::ctxlexpad($ctx), '!EVAL_MARKER')) {
$ctx := nqp::ctxouterskipthunks($ctx);
}
# EVAL adds two extra contexts to EVAL'ed code.
my $outers = ($ctx && nqp::existskey(nqp::ctxlexpad($ctx), '!EVAL_MARKER')) ?? 4 !! 2;
nqp::until(
(nqp::isnull($ctx) || !$outers),
nqp::stmts(
($ctx := nqp::ctxouter($ctx)),
($outers--)
)
);
nqp::if(
nqp::isnull($ctx) || nqp::isnull($ctx := nqp::ctxouter(nqp::ctxouter($ctx))),
nqp::isnull($ctx),
Nil,
nqp::stmts(
(my $stash := nqp::create(PseudoStash)),
Expand Down

0 comments on commit fb6a7d3

Please sign in to comment.