Skip to content

Commit

Permalink
Merge pull request #2438 from rakudo/the-d
Browse files Browse the repository at this point in the history
πŸŽ†β‡οΈπŸ”₯ Happy Diwali! πŸ”₯β‡οΈπŸŽ†
  • Loading branch information
zoffixznet committed Oct 27, 2018
2 parents e60542a + 20412b0 commit d28545d
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 34 deletions.
8 changes: 7 additions & 1 deletion src/Perl6/Compiler.nqp
Expand Up @@ -4,6 +4,7 @@ use Perl6::Optimizer;

class Perl6::Compiler is HLL::Compiler {
has $!language_version;
has $!can_language_versions;

method compilation-id() {
my class IDHolder { }
Expand All @@ -24,9 +25,14 @@ class Perl6::Compiler is HLL::Compiler {
$!language_version
}
else {
$!language_version := self.config<language_version>
$!language_version := self.config<language-version>
}
}
method can_language_versions() {
$!can_language_versions
?? $!can_language_versions
!! ($!can_language_versions := self.config<can-language-versions>)
}

method command_eval(*@args, *%options) {
if nqp::existskey(%options, 'doc') && !%options<doc> {
Expand Down
49 changes: 24 additions & 25 deletions src/Perl6/Grammar.nqp
Expand Up @@ -1304,6 +1304,8 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
:my $*NEXT_STATEMENT_ID := 1; # to give each statement an ID
:my $*IN_STMT_MOD := 0; # are we inside a statement modifier?
:my $*COMPILING_CORE_SETTING := 0; # are we compiling CORE.setting?
# TODO XXX: see https://github.com/rakudo/rakudo/issues/2432
:my $*SET_DEFAULT_LANG_VER := 1;
:my %*SIG_INFO; # information about recent signature
# Various interesting scopes we'd like to keep to hand.
Expand Down Expand Up @@ -1343,6 +1345,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
<.finishpad>
<.bom>?
<lang-version>
<statementlist=.FOREIGN_LANG($*MAIN, 'statementlist', 1)>
<.install_doc_phaser>
Expand All @@ -1364,6 +1367,25 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
$new;
}
rule lang-version {
:my $comp := nqp::getcomp('perl6');
[
<.ws>? 'use' <version> {} # <-- update $/ so we can grab $<version>
# we parse out the numeral, since we could have "6d"
:my $version := nqp::radix(10,$<version><vnum>[0],0,0)[0];
[
|| <?{ $version == 6 }> { $*W.load-lang-ver: $<version>, $comp }
|| { $/.typed_panic: 'X::Language::Unsupported',
version => ~$<version> }
]
|| {
# This is the path we take when the user did not
# provide any `use v6.blah` lang version statement
$*W.load-lang-ver: 'v6', $comp if $*SET_DEFAULT_LANG_VER;
}
]
}
rule statementlist($*statement_level = 0) {
:my $*LANG;
:my $*LEAF;
Expand Down Expand Up @@ -1757,31 +1779,8 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
$<doc>=[ 'DOC' \h+ ]**0..1
<sym> <.ws>
[
| <version> {} # <-- update $/ so we can grab $<version>
# we parse out the numeral, since we could have "6c"
:my $version := nqp::radix(10,$<version><vnum>[0],0,0)[0];
[
|| <?{ $version == 6 }> {
my $version_parts := $<version><vnum>;
my $vwant := $<version>.ast.compile_time_value;
my $comp := nqp::getcomp('perl6');
my $vhave := $*W.find_symbol(['Version']).new($comp.language_version());
my $vcould := $*W.find_symbol(['Version']).new('6.d.PREVIEW');
my $sm := $*W.find_symbol(['&infix:<~~>']);
if $sm($vcould, $vwant) && $vwant.parts.AT-POS($vwant.parts.elems - 1) eq 'PREVIEW' {
$comp.set_language_version('6.d');
$*W.load_setting($/, 'CORE.d');
}
elsif !$sm($vhave,$vwant) {
$/.typed_panic: 'X::Language::Unsupported', version => ~$<version>;
}
$*MAIN := 'MAIN';
$*STRICT := 1 if $*begin_compunit;
}
|| {
$/.typed_panic: 'X::Language::Unsupported', version => ~$<version>;
}
]
| <version>
{ $/.typed_panic: 'X::Language::TooLate', version => ~$<version> }
| <module_name>
[
|| <.spacey> <arglist> <.cheat_heredoc>? <?{ $<arglist><EXPR> }> <.explain_mystery> <.cry_sorrows>
Expand Down
2 changes: 2 additions & 0 deletions src/Perl6/ModuleLoader.nqp
Expand Up @@ -210,6 +210,8 @@ class Perl6::ModuleLoader does Perl6::ModuleLoaderVMConfig {
my $setting;

if $setting_name ne 'NULL' {
# XXX TODO: see https://github.com/rakudo/rakudo/issues/2432
$setting_name := 'CORE' if $setting_name eq 'NULL.d';
# Unless we already did so, locate and load the setting.
unless nqp::defined(%settings_loaded{$setting_name}) {
DEBUG("Loading settings $setting_name") if $DEBUG;
Expand Down
41 changes: 41 additions & 0 deletions src/Perl6/World.nqp
Expand Up @@ -521,6 +521,43 @@ class Perl6::World is HLL::World {
$want
) == -1
}
method load-lang-ver($ver-match, $comp) {
$*MAIN := 'MAIN';
$*STRICT := 1 if $*begin_compunit;

my str $version := ~$ver-match;
# fast-past the common cases
if $version eq 'v6.c' {
$comp.set_language_version: '6.c';
# CORE.c is currently our lowest core, which we don't "load"
return;
}

if $version eq 'v6' ?? nqp::substr($comp.language_version, 2, 1)
!! $version eq 'v6.d' ?? 'd'
!! $version eq 'v6.d.PREVIEW' ?? 'd'
!! '' -> $lang {
$comp.set_language_version: '6.' ~ $lang;
self.load_setting: $ver-match, 'CORE.' ~ $lang;
return;
}

my $Version := self.find_symbol: ['Version'];
my $vWant := $ver-match.ast.compile_time_value;
for $comp.can_language_versions -> $can-ver {
next unless $vWant.ACCEPTS: my $vCan := $Version.new: $can-ver;

my $lang := $vCan.parts.AT-POS: 1;
$comp.set_language_version: '6.' ~ $lang;

# CORE.c is currently our lowest core, which we don't "load"
self.load_setting: $ver-match, 'CORE.' ~ $lang
unless $lang eq 'c';
return;
}

$/.typed_panic: 'X::Language::Unsupported', :$version;
}

method RAKUDO_MODULE_DEBUG() {
if nqp::isconcrete($!RAKUDO_MODULE_DEBUG) {
Expand Down Expand Up @@ -555,6 +592,8 @@ class Perl6::World is HLL::World {
else {
$setting_name := %*COMPILING<%?OPTIONS><setting> // 'CORE';
$*COMPILING_CORE_SETTING := 1 if $setting_name eq 'NULL';
$*SET_DEFAULT_LANG_VER := 0
if nqp::eqat($setting_name, 'NULL', 0);
self.load_setting($/,$setting_name);
$*UNIT.annotate('IN_DECL', 'mainline');
}
Expand Down Expand Up @@ -791,6 +830,8 @@ class Perl6::World is HLL::World {
method load_setting($/, $setting_name) {
# Do nothing for the NULL setting.
if $setting_name ne 'NULL' {
# XXX TODO: see https://github.com/rakudo/rakudo/issues/2432
$setting_name := 'CORE' if $setting_name eq 'NULL.d';
# Load it immediately, so the compile time info is available.
# Once it's loaded, set it as the outer context of the code
# being compiled.
Expand Down
5 changes: 5 additions & 0 deletions src/core/Exception.pm6
Expand Up @@ -2965,6 +2965,11 @@ my class X::Language::Unsupported is Exception {
"No compiler available for Perl $.version"
}
}
my class X::Language::TooLate is Exception {
method message() {
"Too late to switch language version. Must be used as the very first statement."
}
}

my class X::Proc::Unsuccessful is Exception {
has $.proc;
Expand Down
5 changes: 3 additions & 2 deletions src/core/core_epilogue.pm6
Expand Up @@ -24,9 +24,10 @@ BEGIN {
}

{
my $perl := BEGIN Perl.new;
# XXX TODO: https://github.com/rakudo/rakudo/issues/2433
# my $perl := BEGIN Perl.new;
Rakudo::Internals.REGISTER-DYNAMIC: '$*PERL', {
PROCESS::<$PERL> := $perl;
PROCESS::<$PERL> := Perl.new;
}
}

Expand Down
35 changes: 35 additions & 0 deletions t/packages/Test/Helpers.pm6
@@ -1,6 +1,19 @@
unit module Test::Helpers;
use Test;

sub group-of (
Pair (
Int:D :key($plan),
Pair :value((
Str:D :key($desc),
:value(&tests))))
) is export {
subtest $desc => {
plan $plan;
tests
}
}

sub is-run (
Str() $code, $desc = "$code runs",
Stringy :$in, :@compiler-args, :@args, :$out = '', :$err = '', :$exitcode = 0
Expand Down Expand Up @@ -149,6 +162,28 @@ sub make-temp-dir (Int $chmod? --> IO::Path:D) is export {

=begin pod
=head2 group-of
group-of (Pair (Int:D :key($plan), Pair :value((Str:D :key($desc), :value(&tests)))))
A more concise way to write subtests. Code:
group-of 42 => 'some feature' => {
ok 1;
ok 2;
...
ok 42;
}
Is equivalent to:
subtest 'some feature' => {
plan 42;
ok 1;
ok 2;
...
ok 42;
}
=head2 is-run
sub is-run (
Expand Down
2 changes: 1 addition & 1 deletion tools/build/Makefile-JVM.in
Expand Up @@ -153,7 +153,7 @@ $(SETTING_JAR): $(PERL6_JAR) $(PERL6_B_JAR) $(J_CORE_SOURCES)
$(SETTING_D_JAR): $(PERL6_JAR) $(PERL6_B_JAR) $(SETTING_JAR) $(J_CORE_SOURCES)
$(J_NQP) $(J_GEN_CAT) $(J_CORE_D_SOURCES) > $(J_BUILD_DIR)/CORE.d.setting
@echo "The following step can take a long time, please be patient."
NQP_LIB=blib $(J_RUN_PERL6) --ll-exception --optimize=3 --target=jar --stagestats --output=$(SETTING_D_JAR) --nqp-lib=blib $(J_BUILD_DIR)/CORE.d.setting
NQP_LIB=blib $(J_RUN_PERL6) --setting=NULL.d --ll-exception --optimize=3 --target=jar --stagestats --output=$(SETTING_D_JAR) --nqp-lib=blib $(J_BUILD_DIR)/CORE.d.setting

$(J_RUNNER): tools/build/create-jvm-runner.pl
$(PERL5) tools/build/create-jvm-runner.pl dev . . $(NQP_PREFIX) --nqp-lib=blib $(NQP_JARS)
Expand Down
2 changes: 1 addition & 1 deletion tools/build/Makefile-Moar.in
Expand Up @@ -177,7 +177,7 @@ $(SETTING_MOAR): $(PERL6_MOAR) $(PERL6_B_MOAR) $(M_CORE_SOURCES)
$(SETTING_D_MOAR): $(PERL6_MOAR) $(PERL6_B_MOAR) $(SETTING_MOAR) $(M_CORE_D_SOURCES)
$(M_NQP) $(M_GEN_CAT) -f tools/build/moar_core_d_sources > $(M_BUILD_DIR)/CORE.d.setting
@echo "The following step can take a long time, please be patient."
$(M_RUN_PERL6) --ll-exception --optimize=3 --target=mbc --stagestats --output=$(SETTING_D_MOAR) $(M_BUILD_DIR)/CORE.d.setting
$(M_RUN_PERL6) --setting=NULL.d --ll-exception --optimize=3 --target=mbc --stagestats --output=$(SETTING_D_MOAR) $(M_BUILD_DIR)/CORE.d.setting

$(R_SETTING_MOAR): $(PERL6_MOAR) $(SETTING_MOAR) $(R_SETTING_SRC) $(SETTING_MOAR)
$(M_RUN_PERL6) --target=mbc --ll-exception --output=$(R_SETTING_MOAR) $(R_SETTING_SRC)
Expand Down
6 changes: 3 additions & 3 deletions tools/build/gen-js-makefile.nqp
Expand Up @@ -64,7 +64,7 @@ sub combine(:$sources, :$file) {
rule($target, $sources,
make_parents($target),
"\$(JS_NQP) tools/build/gen-cat.nqp js $sources > $target"
);
);
}

my $ModuleLoader-nqp := combine(:sources("src/vm/js/ModuleLoaderVMConfig.nqp src/Perl6/ModuleLoader.nqp"), :file<ModuleLoader.nqp>);
Expand Down Expand Up @@ -103,7 +103,7 @@ rule('$(JS_RUNNER)', '', '$(PERL5) tools/build/create-js-runner.pl');
my $Metamodel-combined := $build_dir ~ "/Metamodel.nqp";
rule($Metamodel-combined, '$(COMMON_BOOTSTRAP_SOURCES)',
"\$(JS_NQP) tools/build/gen-cat.nqp js -f tools/build/common_bootstrap_sources > $Metamodel-combined"
);
);
@produced.push($Metamodel-combined);

my $Bootstrap-combined := combine(:sources('$(BOOTSTRAP_SOURCES)'), :file<Perl6-BOOTSTRAP.nqp>);
Expand Down Expand Up @@ -133,7 +133,7 @@ rule($CORE, "$CORE-combined rakudo.js $Perl6-Bootstrap",

my $CORE-d := "$blib/CORE.d.setting.js";
rule($CORE-d, "$CORE-d-combined rakudo.js $Perl6-Bootstrap $CORE",
"node --max-old-space-size=8192 rakudo.js \$(JS_FLAGS) --source-map --target=js --output=$CORE-d $CORE-d-combined"
"node --max-old-space-size=8192 rakudo.js \$(JS_FLAGS) --source-map --target=js --setting=NULL.d --output=$CORE-d $CORE-d-combined"
);

say("js-all: check_nqp_version $ModuleLoader-nqp $Perl6-Grammar $Perl6-Actions $Perl6-Compiler $Perl6-Pod $Perl6-main $Perl6-Bootstrap $CORE $CORE-d \$(JS_RUNNER) $load-compiler\n");
Expand Down
4 changes: 3 additions & 1 deletion tools/build/gen-version.pl
Expand Up @@ -41,7 +41,9 @@ =head1 TITLE
\$config<release-number> := '$release';
\$config<codename> := '$codename';
\$config<build-date> := '$builddate';
\$config<language_version> := '6.c';
\$config<language-version> := '6.d';
\$config<can-language-versions>
:= nqp::list('6.c', '6.d', '6.d.PREVIEW');
\$config<prefix> := '$prefix';
\$config<libdir> := '$libdir';
\$config<source-digest> := '$source_digest';
Expand Down

0 comments on commit d28545d

Please sign in to comment.