Skip to content

Commit

Permalink
Provide compile-time access to CORE::X namespaces
Browse files Browse the repository at this point in the history
Make it possible to access classes of same name but defined in different
COREs: `CORE::C::PseudoStash` vs `CORE::E::PseudoStash`. Calling `.^ver`
on both would result in `6.c` for the former and `6.e` for the latter.

An example of use:

```
multi foo(CORE::C::PseudoStash:D $p) { ... }
multi foo(CORE::E::PseudoStash:D $p) { ... }
```

Raku/problem-solving#80
  • Loading branch information
vrurg committed Aug 8, 2019
1 parent 48d1172 commit dbfb2e2
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/Perl6/World.nqp
Expand Up @@ -4798,9 +4798,24 @@ class Perl6::World is HLL::World {
}

method find_symbol_in_setting(@name) {
my str $fullname := nqp::join("::", @name);
my $setting_name := Perl6::ModuleLoader.transform_setting_name($!setting_name);
my $no-outers := 0; # If 'true' then don't look in the outer contexts
my $setting_name := $!setting_name;

if nqp::iseq_s(@name[0], 'CORE') { # Looking in CORE:: namespace
nqp::shift(@name := nqp::clone(@name));
my $rev := nqp::lc(@name[0]);
# If a supported language revision requested
if nqp::chars($rev) == 1 && nqp::existskey(nqp::getcomp('perl6').language_revisions,$rev) {
$no-outers := 1; # you don't see other COREs!
nqp::shift(@name);
$setting_name := 'CORE' ~ (nqp::iseq_s($rev, 'c') ?? '' !! ".$rev");
}
}

$setting_name := Perl6::ModuleLoader.transform_setting_name($setting_name);
my $ctx := Perl6::ModuleLoader.load_setting($setting_name);

my str $fullname := nqp::join("::", @name);
my $components := +@name;

while $ctx {
Expand All @@ -4823,7 +4838,7 @@ class Perl6::World is HLL::World {
}
}
}
$ctx := nqp::ctxouter($ctx);
$ctx := $no-outers ?? nqp::null() !! nqp::ctxouter($ctx);
}
nqp::die("Cannot find symbol $fullname in $setting_name");
}
Expand All @@ -4839,6 +4854,11 @@ class Perl6::World is HLL::World {
return self.find_symbol_in_setting(@name);
}

# Support for compile-time CORE:: namespace
if +@name > 1 && nqp::iseq_s(@name[0], 'CORE') {
return self.find_symbol_in_setting(@name);
}

# GLOBAL is current view of global.
if +@name == 1 && @name[0] eq 'GLOBAL' {
return $*GLOBALish;
Expand Down

0 comments on commit dbfb2e2

Please sign in to comment.