Skip to content

Commit

Permalink
Implement CORE::<lang-rev> pseudo-packages
Browse files Browse the repository at this point in the history
Extend `CORE` with second-level packages representing individual cores
for specific language revisions. I.e, `CORE::C` is for `CORE.setting`
or, correspondingly, for 6.c language. `CORE::D`, `CORE::E`, and so on.
New letters become available as soon as a `CORE` context with
`CORE-SETTING-REV` symbol becomes available.

Each subpackage has `PRECISE_SCOPE`. Thus, `CORE::D::Any` will fail
because `Any` is not defined in `CORE.d.setting`.

Raku/problem-solving#80
  • Loading branch information
vrurg committed Aug 7, 2019
1 parent ad51a3a commit 197fcc2
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/core.d/core_prologue.pm6
@@ -1,6 +1,6 @@
use nqp;

# This constant is only to support tests.
# This constant must specify current CORE revision
my constant CORE-SETTING-REV = 'd';

# vim: ft=perl6 expandtab sw=4
42 changes: 39 additions & 3 deletions src/core.e/PseudoStash.pm6
Expand Up @@ -43,7 +43,7 @@ my class PseudoStash is Map {
nqp::bindattr($stash, Map, '$!storage', nqp::ctxlexpad($ctx)),
nqp::bindattr($stash, PseudoStash, '$!ctx', $ctx),
nqp::bindattr_i($stash, PseudoStash, '$!mode', STATIC_CHAIN),
$stash.pseudo-package('CORE')
$stash.pseudo-package('CORE'),
)
)
},
Expand Down Expand Up @@ -187,10 +187,46 @@ my class PseudoStash is Map {
}
);


method !find-rev-core($key) {
my $rev = nqp::lc($key);
my $ctx := $!ctx;
my $found := nqp::null();
my $stash;
nqp::while(
$ctx && !$found,
nqp::stmts(
(my $lexpad := nqp::ctxlexpad($ctx)),
nqp::if(
nqp::existskey($lexpad, 'CORE-SETTING-REV')
&& nqp::iseq_s($rev, nqp::atkey($lexpad, 'CORE-SETTING-REV')),
($found := $ctx),
($ctx := nqp::ctxouterskipthunks($ctx))
),
)
);
nqp::if(
nqp::isnull($found),
Failure.new(X::NoCoreRevision.new(lang-rev => $rev)),
nqp::stmts(
($stash := nqp::create(PseudoStash)),
nqp::bindattr($stash, Map, '$!storage', nqp::ctxlexpad($found)),
nqp::bindattr($stash, PseudoStash, '$!ctx', $found),
nqp::bindattr_i($stash, PseudoStash, '$!mode', PRECISE_SCOPE),
$stash.pseudo-package($key)
)
)
}

multi method AT-KEY(PseudoStash:D: Str() $key) is raw {
my Mu $val := nqp::null();
my $name := $!package.^name;
my Mu $val := nqp::if(
(nqp::iseq_s($name, 'CORE') && nqp::iseq_i(nqp::chars($key), 1)),
self!find-rev-core($key),
nqp::null()
);
nqp::if(
nqp::existskey($pseudoers,$key),
nqp::isnull($val) && nqp::existskey($pseudoers,$key),
($val := nqp::atkey($pseudoers,$key)(self)),
nqp::stmts(
nqp::if( # PRECISE_SCOPE is exclusive
Expand Down
2 changes: 1 addition & 1 deletion src/core.e/core_prologue.pm6
@@ -1,6 +1,6 @@
use nqp;

# This constant is only to support tests.
# This constant must specify current CORE revision
my constant CORE-SETTING-REV = 'e';

# vim: ft=perl6 expandtab sw=4
5 changes: 5 additions & 0 deletions src/core/Exception.pm6
Expand Up @@ -2603,6 +2603,11 @@ my class X::NoSuchSymbol is Exception {
method message { "No such symbol '$.symbol'" }
}

my class X::NoCoreRevision is Exception {
has $.lang-rev;
method message { "No CORE for language version 6.$!lang-rev" }
}

my class X::Item is Exception {
has $.aggregate;
has $.index;
Expand Down
2 changes: 1 addition & 1 deletion src/core/core_prologue.pm6
Expand Up @@ -68,7 +68,7 @@ PROCESS::<$SCHEDULER> = JavaScriptScheduler.new();
BEGIN {nqp::p6setassociativetype(Associative);}
#?endif

# This constant is only to support tests.
# This constant must specify current CORE revision
my constant CORE-SETTING-REV = 'c';

# vim: ft=perl6 expandtab sw=4

0 comments on commit 197fcc2

Please sign in to comment.