Skip to content

Commit

Permalink
Do core setting name mapping via compiler config
Browse files Browse the repository at this point in the history
The main source of language revision data is tools/templates/RAKU_SPECS
file which is parsed and processed by tools/lib/NQP/Config/Rakudo.pm.
Therefore it is more reliable to automate the generation of NULL -> CORE
mapping using build-time macros than to manually manage a hash somewhere
in obscure ModuleLoader location.

- Added `@prevspec@`, `@ucprevspec@`, `@lcprevspec@` config variables
  under @for_specs()@` context
- Added key `prev-setting-name` for mapping NULL -> CORE setting
- Added key `prev-revision` mapping for custom setting handling;
  custom setting support is to be fixed/implemented yet
  • Loading branch information
vrurg committed Jul 17, 2020
1 parent ddebab5 commit 6e087e1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
15 changes: 3 additions & 12 deletions src/Perl6/ModuleLoader.nqp
Expand Up @@ -213,18 +213,10 @@ class Perl6::ModuleLoader does Perl6::ModuleLoaderVMConfig {
}
}

my %previous_setting_name := nqp::hash(
'NULL.c', 'NULL.c', # identity
'CORE.c', 'CORE.c',
'NULL.d', 'CORE.c',
'CORE.d', 'CORE.d',
'NULL.e', 'CORE.d',
'CORE.e', 'CORE.e'
);

# Transforms NULL.<release> into CORE.<previous-release>
# Transforms NULL.<release> into CORE.<previous-release>, CORE.<release> into CORE.<previous-release>
method previous_setting_name ($setting_name, :$base = 'CORE') {
%previous_setting_name{$setting_name} // nqp::die("Don't know setting $setting_name")
nqp::getcomp('Raku').config()<prev-setting-name>{$setting_name}
// nqp::die("Don't know setting $setting_name")
}

method transform_setting_name ($setting_name) {
Expand All @@ -236,7 +228,6 @@ class Perl6::ModuleLoader does Perl6::ModuleLoaderVMConfig {

if $setting_name ne 'NULL.c' {
DEBUG("Requested for settings $setting_name") if $DEBUG;
# XXX TODO: see https://github.com/rakudo/rakudo/issues/2432
$setting_name := self.transform_setting_name($setting_name);

# First, pre-load previous setting.
Expand Down
5 changes: 1 addition & 4 deletions src/Perl6/World.nqp
Expand Up @@ -572,8 +572,6 @@ class Perl6::World is HLL::World {
}
}

# NOTE: Revision .c has special meaning because it doesn't have own dedicated CORE setting and serves as the base
# for all other revisions.
method load-lang-ver($ver-match, $comp) {
if $*INSIDE-EVAL && $!have_outer {
# XXX Calling typed_panic is the desirable behavior. But it breaks some code. Just ignore version change for
Expand Down Expand Up @@ -697,7 +695,7 @@ class Perl6::World is HLL::World {
nqp::getcomp('Raku').set_language_version( nqp::isgt_s($!setting_revision, $default_revision)
?? $!setting_revision
!! $default_revision );
}
}
$*UNIT.annotate('IN_DECL', 'mainline');
}

Expand Down Expand Up @@ -955,7 +953,6 @@ class Perl6::World is HLL::World {
}
# Do nothing for the NULL.c setting.
if $setting_name ne 'NULL.c' {
# XXX TODO: see https://github.com/rakudo/rakudo/issues/2432
$setting_name := Perl6::ModuleLoader.transform_setting_name($setting_name);
# Load it immediately, so the compile time info is available.
# Once it's loaded, set it as the outer context of the code
Expand Down
6 changes: 6 additions & 0 deletions tools/lib/NQP/Config/Rakudo.pm
Expand Up @@ -726,8 +726,10 @@ sub _specs_iterate {

$self->not_in_context( specs => 'spec' );

my $prev_spec_char;
for my $spec ( $cfg->raku_specs ) {
my $spec_char = $spec->[0];
$prev_spec_char //= $spec_char; # Map c -> c
my $spec_subdir = "6.$spec_char";
my %config = (
ctx_subdir => $spec_subdir,
Expand All @@ -736,6 +738,9 @@ sub _specs_iterate {
spec_with_mod => $spec_char,
ucspec => uc $spec_char,
lcspec => lc $spec_char,
prevspec => $prev_spec_char,
ucprevspec => uc $prev_spec_char,
lcprevspec => lc $prev_spec_char,
);
my $spec_ctx = {
spec => $spec,
Expand All @@ -758,6 +763,7 @@ sub _specs_iterate {
$cb->(@_);
}
}
$prev_spec_char = $spec_char;
}
}

Expand Down
15 changes: 15 additions & 0 deletions tools/templates/main-version.in
@@ -1,9 +1,11 @@
sub hll-config($config) {
### Language
$config<implementation> := 'Rakudo';
$config<version> := '@version@';
$config<release-number> := '@release@';
$config<codename> := '@codename@';
$config<language-version> := '6.@lang_spec@';

# Though language-revisions key provides more information
# can-language-versions is used for speeding up and ordering
# Perl6::Compiler.can_langauge_versions method
Expand Down Expand Up @@ -33,9 +35,22 @@ sub hll-config($config) {
}
)@
);

# This mapping is for handling custom settings
$config<prev-revision> := nqp::hash(@for_specs(
'@lcspec@', '@lcprevspec@',)@
);
# This mapping is for quick-transforming of core setting name
$config<prev-setting-name> := nqp::hash(@for_specs(
'NULL.@lcspec@', '@if(lcspec==c NULL)@@if(lcspec!=c CORE)@.@lcprevspec@',
'CORE.@lcspec@', 'CORE.@lcspec@',)@
);

### Location
$config<prefix> := '@prefix@';
$config<static-nqp-home> := '@static_nqp_home@';
$config<static-rakudo-home> := '@static_rakudo_home@';

$config<source-digest> := '@source_digest()@';
}

0 comments on commit 6e087e1

Please sign in to comment.