Skip to content
Permalink
Browse files

πŸŽ†β‡οΈπŸ”₯ Happy Diwali! πŸ”₯β‡οΈπŸŽ†

Set 6.d as default lang of the compiler

- We allow v6.d.PREVIEW to be an alias for v6.d, to let users
    cater to older versions of the compiler that don't know how
    to do v6.d yet
- Require the version pragma to be the first statement in the comp-unit
    (comments/Pod before it are OK). We need this because we need to
    load CORE.d for 6.d language which is now default.
- Re-write lang loading logic to be more modification-friendly. Future
    lang changes should largely require just adding new vers in the
    config and perhaps changing which versions fast-pathing cares about
  • Loading branch information...
zoffixznet committed Oct 27, 2018
1 parent 3365094 commit 46ef0ea08cae96db25c7b5a9543ba696034408c8
Showing with 69 additions and 27 deletions.
  1. +7 βˆ’1 src/Perl6/Compiler.nqp
  2. +22 βˆ’25 src/Perl6/Grammar.nqp
  3. +37 βˆ’0 src/Perl6/World.nqp
  4. +3 βˆ’1 tools/build/gen-version.pl
@@ -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 { }
@@ -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> {
@@ -1345,6 +1345,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
<.finishpad>
<.bom>?
<lang-version>
<statementlist=.FOREIGN_LANG($*MAIN, 'statementlist', 1)>
<.install_doc_phaser>
@@ -1366,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;
@@ -1759,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>
@@ -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) {
@@ -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';

0 comments on commit 46ef0ea

Please sign in to comment.
You can’t perform that action at this time.