Skip to content

Commit a57eda0

Browse files
committed
Collapse NQPQ back into NQP.
1 parent fea45a0 commit a57eda0

File tree

9 files changed

+108
-3036
lines changed

9 files changed

+108
-3036
lines changed

src/NQP/Actions.pm

Lines changed: 65 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,15 @@ class NQP::Actions is HLL::Actions {
199199
# this in the setting as Regex depends on the setting).
200200
unless %*COMPILING<%?OPTIONS><setting> eq 'NULL' {
201201
import_HOW_exports($SETTING);
202-
$*W.load_module('NQPRegex', $*GLOBALish);
202+
if %*COMPILING<%?OPTIONS><old-regex-lib> {
203+
$*W.load_module('NQPRegex', $*GLOBALish);
204+
}
205+
unless %*COMPILING<%?OPTIONS><no-regex-lib> {
206+
$*W.load_module('QRegex', $*GLOBALish);
207+
unless %*COMPILING<%?OPTIONS><old-regex-lib> {
208+
$*W.load_module('NQPP6QRegex', $*GLOBALish);
209+
}
210+
}
203211
}
204212
}
205213
self.SET_BLOCK_OUTER_CTX($*W.cur_lexpad());
@@ -312,7 +320,7 @@ class NQP::Actions is HLL::Actions {
312320

313321
sub push_block_handler($/, $block) {
314322
my $BLOCK := $*W.cur_lexpad();
315-
unless $BLOCK.handlers() {
323+
unless $BLOCK.handlers() {
316324
$BLOCK.handlers([]);
317325
}
318326
unless $block.arity {
@@ -347,8 +355,8 @@ class NQP::Actions is HLL::Actions {
347355
)
348356
);
349357
}
350-
351-
method statement_prefix:sym<BEGIN>($/) {
358+
359+
method statement_prefix:sym<BEGIN>($/) {
352360
make $*W.run_begin_block($<blorst>.ast);
353361
}
354362

@@ -576,7 +584,7 @@ class NQP::Actions is HLL::Actions {
576584
}
577585
}
578586
elsif pir::can($how, 'set_default_parent') {
579-
my $default := $*PKGDECL eq 'grammar' ?? ['Regex', 'Cursor'] !! ['NQPMu'];
587+
my $default := $*PKGDECL eq 'grammar' ?? ['NQPCursor'] !! ['NQPMu'];
580588
$*W.pkg_add_parent_or_role($*PACKAGE, "set_default_parent",
581589
$*W.find_sym($default));
582590
}
@@ -738,7 +746,7 @@ class NQP::Actions is HLL::Actions {
738746
}
739747

740748
# Set up dispatch routine in this scope.
741-
my $BLOCK := $*W.cur_lexpad();
749+
my $BLOCK := $*W.cur_lexpad();
742750
$cholder := PAST::Op.new( :pasttype('list') );
743751
my $dispatch_setup := PAST::Op.new(
744752
:pirop('create_dispatch_and_add_candidates PPP'),
@@ -763,7 +771,7 @@ class NQP::Actions is HLL::Actions {
763771
if $*SCOPE eq 'our' { pir::die('our-scoped protos not yet implemented') }
764772
my $cholder := PAST::Op.new( :pasttype('list') );
765773
my $BLOCK := $*W.cur_lexpad();
766-
$BLOCK[0].push(PAST::Var.new( :name($name), :isdecl(1), :directaccess(1),
774+
$BLOCK[0].push(PAST::Var.new( :name($name), :isdecl(1), :directaccess(1),
767775
:viviself($past), :scope('lexical') ) );
768776
$BLOCK[0].push(PAST::Op.new(
769777
:pirop('set_dispatchees 0PP'),
@@ -777,7 +785,7 @@ class NQP::Actions is HLL::Actions {
777785
}
778786
else {
779787
my $BLOCK := $*W.cur_lexpad();
780-
$BLOCK[0].push(PAST::Var.new( :name($name), :isdecl(1), :directaccess(1),
788+
$BLOCK[0].push(PAST::Var.new( :name($name), :isdecl(1), :directaccess(1),
781789
:viviself($past), :scope('lexical') ) );
782790
$BLOCK.symbol($name, :scope('lexical') );
783791
if $*SCOPE eq 'our' {
@@ -847,7 +855,7 @@ class NQP::Actions is HLL::Actions {
847855
# Set name.
848856
my $name := ~$<private> ~ ~$<deflongname>[0].ast;
849857
$past.name($name);
850-
858+
851859
# Insert it into the method table.
852860
my $meta_meth := $*MULTINESS eq 'multi' ?? 'add_multi_method' !! 'add_method';
853861
my $is_dispatcher := $*MULTINESS eq 'proto';
@@ -883,7 +891,7 @@ class NQP::Actions is HLL::Actions {
883891
));
884892
$past
885893
}
886-
894+
887895
sub attach_multi_signature($code_obj, $routine) {
888896
my $types := nqp::list();
889897
my $definednesses := nqp::list();
@@ -914,7 +922,7 @@ class NQP::Actions is HLL::Actions {
914922
}
915923

916924
method signature($/) {
917-
my $BLOCK := $*W.cur_lexpad();
925+
my $BLOCK := $*W.cur_lexpad();
918926
my $BLOCKINIT := $BLOCK[0];
919927
if $<invocant> {
920928
my $inv := $<invocant>[0].ast;
@@ -1040,7 +1048,6 @@ class NQP::Actions is HLL::Actions {
10401048
}
10411049

10421050
method regex_declarator($/, $key?) {
1043-
my @MODIFIERS := @Regex::P6Regex::Actions::MODIFIERS;
10441051
my $name := ~$<deflongname>.ast;
10451052
my $past;
10461053
if $<proto> {
@@ -1057,62 +1064,35 @@ class NQP::Actions is HLL::Actions {
10571064
:lexical(0),
10581065
:node($/)
10591066
),
1060-
PAST::Block.new( :name('!PREFIX__' ~ $name),
1061-
PAST::Op.new(
1062-
PAST::Var.new( :name('self'), :scope('parameter') ),
1063-
$name,
1064-
:name('!PREFIX__!protoregex'),
1065-
:pasttype('callmethod')
1066-
),
1067-
:blocktype('declaration'),
1068-
:lexical(0),
1069-
:node($/)
1070-
)
10711067
);
10721068
for @($past) {
10731069
$*W.pkg_add_method($*PACKAGE, 'add_method', $_.name(), $*W.create_code($_, $_.name(), 0));
10741070
}
10751071
}
1076-
elsif $key eq 'open' {
1077-
my %h;
1078-
if $<sym> eq 'token' { %h<r> := 1; }
1079-
if $<sym> eq 'rule' { %h<r> := 1; %h<s> := 1; }
1080-
@MODIFIERS.unshift(%h);
1081-
$Regex::P6Regex::Actions::REGEXNAME := $name;
1082-
$*W.cur_lexpad().symbol('', :scope('lexical'));
1083-
$*W.cur_lexpad().symbol('$/', :scope('lexical'));
1084-
return 0;
1085-
}
10861072
else {
1087-
my $regex :=
1088-
Regex::P6Regex::Actions::buildsub($<p6regex>.ast, $*W.pop_lexpad());
1073+
my $block := $*W.pop_lexpad();
1074+
$block[0].unshift(PAST::Var.new(:name<self>, :scope<parameter>));
1075+
$block[0].push(
1076+
PAST::Var.new(:name<self>, :scope<register>, :isdecl(1),
1077+
:viviself(PAST::Var.new( :name<self>, :scope('lexical_6model') ))));
1078+
$block[0].push(PAST::Var.new(:name<>, :scope<lexical>, :isdecl(1)));
1079+
$block[0].push(PAST::Var.new(:name<$/>, :scope<lexical>, :isdecl(1)));
1080+
$block.symbol('', :scope<lexical>);
1081+
$block.symbol('$/', :scope<lexical>);
1082+
my $regex := QRegex::P6Regex::Actions::buildsub($<p6regex>.ast, $block);
10891083
$regex.name($name);
1090-
my $prefix_meth;
10911084

10921085
if $*PKGDECL && pir::can($*PACKAGE.HOW, 'add_method') {
10931086
# Add the actual method.
10941087
$*W.pkg_add_method($*PACKAGE, 'add_method', $name, $*W.create_code($regex, $name, 0));
1095-
1096-
# Produce the prefixes method and add it.
1097-
my @prefixes := $<p6regex>.ast.prefix_list();
1098-
$prefix_meth := PAST::Block.new(
1099-
:name('!PREFIX__' ~ $name), :blocktype('method'),
1100-
PAST::Op.new( :pasttype('list'), |@prefixes )
1101-
);
1102-
$*W.pkg_add_method($*PACKAGE, 'add_method', $prefix_meth.name,
1103-
$*W.create_code($prefix_meth, $prefix_meth.name, 0));
11041088
}
11051089

11061090
# In sink context, we don't need the Regex::Regex object.
11071091
$past := PAST::Op.new(
11081092
:pasttype<callmethod>, :name<new>,
1109-
lexical_package_lookup(['Regex', 'Method'], $/),
1110-
$regex
1111-
);
1112-
$past<sink> := $prefix_meth ??
1113-
PAST::Stmts.new( $regex, $prefix_meth ) !!
1114-
$regex;
1115-
@MODIFIERS.shift;
1093+
lexical_package_lookup(['NQPRegexMethod'], $/),
1094+
$regex);
1095+
$past<sink> := $regex;
11161096
}
11171097
make $past;
11181098
}
@@ -1313,7 +1293,9 @@ class NQP::Actions is HLL::Actions {
13131293
method number($/) {
13141294
my $value := $<dec_number> ?? $<dec_number>.ast !! $<integer>.ast;
13151295
if ~$<sign> eq '-' { $value := -$value; }
1316-
make PAST::Val.new( :value($value) );
1296+
make $<dec_number> ??
1297+
PAST::Val.new( :value($value) ) !!
1298+
PAST::Want.new( PAST::Val.new( :value($value) ), 'Ii', $value );
13171299
}
13181300

13191301
method quote:sym<apos>($/) { make $<quote_EXPR>.ast; }
@@ -1327,21 +1309,23 @@ class NQP::Actions is HLL::Actions {
13271309
:node($/) );
13281310
}
13291311

1330-
method quote:sym</ />($/, $key?) {
1331-
if $key eq 'open' {
1332-
$Regex::P6Regex::Actions::REGEXNAME := pir::null__P();
1333-
$*W.cur_lexpad().symbol('', :scope('lexical'));
1334-
$*W.cur_lexpad().symbol('$/', :scope('lexical'));
1335-
return 0;
1336-
}
1337-
my $regex :=
1338-
Regex::P6Regex::Actions::buildsub($<p6regex>.ast, $*W.pop_lexpad());
1339-
my $past :=
1340-
PAST::Op.new(
1341-
:pasttype<callmethod>, :name<new>,
1342-
lexical_package_lookup(['Regex', 'Regex'], $/),
1343-
$regex
1344-
);
1312+
method quote:sym</ />($/) {
1313+
my $block := $*W.pop_lexpad();
1314+
$block[0].push(PAST::Var.new(:name<self>, :scope<parameter>));
1315+
$block[0].push(
1316+
PAST::Var.new(:name<self>, :scope<register>, :isdecl(1),
1317+
:viviself(PAST::Var.new( :name<self>, :scope('lexical_6model') ))));
1318+
$block[0].push(PAST::Var.new(:name<>, :scope<lexical>, :isdecl(1)));
1319+
$block[0].push(PAST::Var.new(:name<$/>, :scope<lexical>, :isdecl(1)));
1320+
$block.symbol('', :scope<lexical>);
1321+
$block.symbol('$/', :scope<lexical>);
1322+
1323+
my $regex := QRegex::P6Regex::Actions::buildsub($<p6regex>.ast, $block);
1324+
my $past := PAST::Op.new(
1325+
:pasttype<callmethod>, :name<new>,
1326+
lexical_package_lookup(['NQPRegex'], $/),
1327+
$regex);
1328+
13451329
# In sink context, we don't need the Regex::Regex object.
13461330
$past<sink> := $regex;
13471331
make $past;
@@ -1447,38 +1431,38 @@ class NQP::Actions is HLL::Actions {
14471431
}
14481432
}
14491433

1450-
class NQP::RegexActions is Regex::P6Regex::Actions {
1434+
class NQP::RegexActions is QRegex::P6Regex::Actions {
14511435

14521436
method metachar:sym<:my>($/) {
14531437
my $past := $<statement>.ast;
1454-
make PAST::Regex.new( $past, :pasttype('pastnode'),
1455-
:subtype('declarative'), :node($/) );
1438+
make QAST::Regex.new( $past,
1439+
:rxtype('pastnode'), :subtype('declarative'), :node($/) );
14561440
}
14571441

14581442
method metachar:sym<{ }>($/) {
1459-
make PAST::Regex.new( $<codeblock>.ast,
1460-
:pasttype<pastnode>, :node($/) );
1443+
make QAST::Regex.new( $<codeblock>.ast,
1444+
:rxtype<pastnode>, :node($/) );
14611445
}
14621446

14631447
method metachar:sym<nqpvar>($/) {
1464-
make PAST::Regex.new( '!INTERPOLATE', $<var>.ast,
1465-
:pasttype<subrule>, :subtype<method>, :node($/));
1448+
make QAST::Regex.new( PAST::Node.new('!INTERPOLATE', $<var>.ast),
1449+
:rxtype<subrule>, :subtype<method>, :node($/));
14661450
}
14671451

14681452
method assertion:sym<{ }>($/) {
1469-
make PAST::Regex.new( '!INTERPOLATE_REGEX', $<codeblock>.ast,
1470-
:pasttype<subrule>, :subtype<method>, :node($/));
1453+
make QAST::Regex.new( PAST::Node.new('!INTERPOLATE_REGEX', $<codeblock>.ast),
1454+
:rxtype<subrule>, :subtype<method>, :node($/));
14711455
}
14721456

14731457
method assertion:sym<?{ }>($/) {
1474-
make PAST::Regex.new( $<codeblock>.ast,
1458+
make QAST::Regex.new( $<codeblock>.ast,
14751459
:subtype<zerowidth>, :negate( $<zw> eq '!' ),
1476-
:pasttype<pastnode>, :node($/) );
1460+
:rxtype<pastnode>, :node($/) );
14771461
}
14781462

14791463
method assertion:sym<var>($/) {
1480-
make PAST::Regex.new( '!INTERPOLATE_REGEX', $<var>.ast,
1481-
:pasttype<subrule>, :subtype<method>, :node($/));
1464+
make QAST::Regex.new( PAST::Node.new('!INTERPOLATE_REGEX', $<var>.ast),
1465+
:rxtype<subrule>, :subtype<method>, :node($/));
14821466
}
14831467

14841468
method codeblock($/) {

src/NQP/Compiler.pm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ sub MAIN(@ARGS) {
1616
@clo.push('setting-path=s');
1717
@clo.push('module-path=s');
1818
@clo.push('vmlibs=s');
19+
@clo.push('no-regex-lib');
20+
@clo.push('old-regex-lib');
21+
22+
# Hack while we still use the old PAST classes to make sure they are
23+
# loaded.
24+
try {
25+
pir::get_hll_global__Ps('ModuleLoader').load_module('PASTRegex', GLOBALish);
26+
}
1927

2028
# Enter the compiler.
2129
$nqpcomp.command_line(@ARGS, :encoding('utf8'), :transcode('ascii iso-8859-1'));

0 commit comments

Comments
 (0)