Skip to content
This repository was archived by the owner on Feb 3, 2021. It is now read-only.

Commit 3887fc5

Browse files
committed
Switch grammars over to 6model. This includes changes to get protoregexes working again. Sadly, due to some other bug, much is still broken.
1 parent 659a99f commit 3887fc5

File tree

3 files changed

+57
-63
lines changed

3 files changed

+57
-63
lines changed

src/NQP/Actions.pm

Lines changed: 53 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,9 @@ sub push_block_handler($/, $block) {
262262
}
263263

264264
method statement_prefix:sym<INIT>($/) {
265-
@BLOCK[0].loadinit.push($<blorst>.ast);
266-
make PAST::Stmts.new(:node($/));
265+
my $init_block := PAST::Block.new(:blocktype('immediate'));
266+
$init_block.loadinit.push($<blorst>.ast);
267+
make $init_block;
267268
}
268269

269270
method statement_prefix:sym<try>($/) {
@@ -375,7 +376,7 @@ method variable($/) {
375376
method package_declarator:sym<module>($/) { make $<package_def>.ast; }
376377
method package_declarator:sym<knowhow>($/) { make package($/); }
377378
method package_declarator:sym<class>($/) { make package($/) }
378-
method package_declarator:sym<grammar>($/) { make old_package($/) }
379+
method package_declarator:sym<grammar>($/) { make package($/) }
379380
method package_declarator:sym<role>($/) { make package($/); }
380381

381382
sub package($/) {
@@ -401,7 +402,6 @@ sub package($/) {
401402
PAST::Var.new( :name('$?CLASS') ),
402403
PAST::Var.new( :name('type_obj'), :scope('register') )
403404
)
404-
# XXX name
405405
));
406406
if $<package_def><repr> {
407407
my $repr_name := $<package_def><repr>[0].ast;
@@ -425,6 +425,18 @@ sub package($/) {
425425
PAST::Var.new( :name(~$name), :namespace(@ns), :scope('package') )
426426
));
427427
}
428+
elsif ~$<sym> eq 'grammar' {
429+
$*PACKAGE-SETUP.push(PAST::Op.new(
430+
:pasttype('callmethod'), :name('add_parent'),
431+
PAST::Op.new(
432+
# XXX nqpop get_how
433+
:pirop('get_how PP'),
434+
PAST::Var.new( :name('type_obj'), :scope('register') )
435+
),
436+
PAST::Var.new( :name('type_obj'), :scope('register') ),
437+
PAST::Var.new( :name('Cursor2'), :namespace('Regex'), :scope('package') )
438+
));
439+
}
428440

429441
# Postfix it with a call to compose.
430442
$*PACKAGE-SETUP.push(PAST::Op.new(
@@ -452,31 +464,6 @@ sub package($/) {
452464
return $past;
453465
}
454466

455-
# XXX Left here so we can keep old-style classes and grammars working while
456-
# playing with KnowHOW etc.
457-
sub old_package($/) {
458-
my $past := $<package_def>.ast;
459-
my $classinit :=
460-
PAST::Op.new(
461-
PAST::Op.new(
462-
:inline( ' %r = get_root_global ["parrot"], "P6metaclass"')
463-
),
464-
~$<package_def><name>,
465-
:name('new_class'),
466-
:pasttype('callmethod')
467-
);
468-
my $parent := ~$<package_def><parent>[0]
469-
|| ($<sym> eq 'grammar' ?? 'Regex::Cursor' !! '');
470-
if $parent {
471-
$classinit.push( PAST::Val.new( :value($parent), :named('parent') ) );
472-
}
473-
if $past<attributes> {
474-
$classinit.push( $past<attributes> );
475-
}
476-
@BLOCK[0].loadinit.push($classinit);
477-
make $past;
478-
}
479-
480467
method package_def($/) {
481468
my $past := $<block> ?? $<block>.ast !! $<comp_unit>.ast;
482469
$past.namespace( $<name><identifier> );
@@ -680,11 +667,6 @@ method routine_def($/) {
680667

681668

682669
method method_def($/) {
683-
# XXX Remove this when grammar switches over to using 6model.
684-
unless $*PACKAGE-SETUP {
685-
return OLD_method_def($/);
686-
}
687-
688670
# If it's just got * as a body, make a multi-dispatch enterer.
689671
# Otherwise, build method block PAST.
690672
my $past;
@@ -727,7 +709,7 @@ method method_def($/) {
727709
# the multi-dispatcher to use.
728710
if $*MULTINESS eq 'multi' { attach_multi_signature($past); }
729711

730-
# Insert it into the namespace.
712+
# Insert it into the method table.
731713
$*PACKAGE-SETUP.push(PAST::Op.new(
732714
:pasttype('callmethod'), :name($*MULTINESS eq 'multi' ?? 'add_multi_method' !! 'add_method'),
733715
PAST::Op.new(
@@ -753,28 +735,6 @@ method method_def($/) {
753735
make $past;
754736
}
755737

756-
# XXX Toss this when grammar moves over to 6model.
757-
sub OLD_method_def($/) {
758-
my $past := $<blockoid>.ast;
759-
$past.blocktype('method');
760-
if $*SCOPE eq 'our' {
761-
$past.pirflags(':nsentry');
762-
}
763-
$past.control('return_pir');
764-
$past[0].unshift( PAST::Op.new( :inline(' .lex "self", self') ) );
765-
$past.symbol('self', :scope('lexical') );
766-
if $<deflongname> {
767-
my $name := ~$<deflongname>[0].ast;
768-
$past.name($name);
769-
}
770-
if $*MULTINESS eq 'multi' { $past.multi().unshift('_'); }
771-
$past<block_past> := $past;
772-
if $<trait> {
773-
for $<trait> { $_.ast()($/); }
774-
}
775-
make $past;
776-
}
777-
778738
sub only_star_block() {
779739
my $past := @BLOCK.shift;
780740
$past.closure(1);
@@ -911,27 +871,39 @@ method regex_declarator($/, $key?) {
911871
PAST::Stmts.new(
912872
PAST::Block.new( :name($name),
913873
PAST::Op.new(
914-
PAST::Var.new( :name('self'), :scope('register') ),
874+
PAST::Var.new( :name('self'), :scope('parameter') ),
915875
$name,
916876
:name('!protoregex'),
917877
:pasttype('callmethod')
918878
),
919-
:blocktype('method'),
879+
:blocktype('declaration'),
920880
:lexical(0),
921881
:node($/)
922882
),
923883
PAST::Block.new( :name('!PREFIX__' ~ $name),
924884
PAST::Op.new(
925-
PAST::Var.new( :name('self'), :scope('register') ),
885+
PAST::Var.new( :name('self'), :scope('parameter') ),
926886
$name,
927887
:name('!PREFIX__!protoregex'),
928888
:pasttype('callmethod')
929889
),
930-
:blocktype('method'),
890+
:blocktype('declaration'),
931891
:lexical(0),
932892
:node($/)
933893
)
934894
);
895+
for @($past) {
896+
$*PACKAGE-SETUP.push(PAST::Op.new(
897+
:pasttype('callmethod'), :name('add_method'),
898+
PAST::Op.new(
899+
:pirop('get_how PP'),
900+
PAST::Var.new( :name('type_obj'), :scope('register') )
901+
),
902+
PAST::Var.new( :name('type_obj'), :scope('register') ),
903+
PAST::Val.new( :value($_.name()) ),
904+
PAST::Val.new( :value($_) )
905+
));
906+
}
935907
}
936908
elsif $key eq 'open' {
937909
my %h;
@@ -956,6 +928,26 @@ method regex_declarator($/, $key?) {
956928
PAST::Var.new( :name('Method'), :namespace(['Regex']), :scope<package> ),
957929
$regex
958930
);
931+
$*PACKAGE-SETUP.push(PAST::Op.new(
932+
:pasttype('callmethod'), :name('add_method'),
933+
PAST::Op.new(
934+
:pirop('get_how PP'),
935+
PAST::Var.new( :name('type_obj'), :scope('register') )
936+
),
937+
PAST::Var.new( :name('type_obj'), :scope('register') ),
938+
PAST::Val.new( :value($name) ),
939+
PAST::Val.new( :value($regex) )
940+
));
941+
$*PACKAGE-SETUP.push(PAST::Op.new(
942+
:pasttype('callmethod'), :name('add_method'),
943+
PAST::Op.new(
944+
:pirop('get_how PP'),
945+
PAST::Var.new( :name('type_obj'), :scope('register') )
946+
),
947+
PAST::Var.new( :name('type_obj'), :scope('register') ),
948+
PAST::Val.new( :value('!PREFIX__' ~ $name) ),
949+
PAST::Var.new( :name('!PREFIX__' ~ $name), :scope('package') )
950+
));
959951
# In sink context, we don't need the Regex::Regex object.
960952
$past<sink> := $regex;
961953
@MODIFIERS.shift;

src/NQP/Grammar.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ method TOP() {
1212
my %*HOW;
1313
%*HOW<knowhow> := 'KnowHOW';
1414
%*HOW<class> := 'NQPClassHOW';
15-
%*HOW<grammar> := 'NQPGrammarHOW';
15+
%*HOW<grammar> := 'NQPClassHOW';
1616
%*HOW<role> := 'NQPRoleHOW';
1717

1818
# What attribute class to use with what HOW, plus a default.
@@ -288,6 +288,7 @@ token package_declarator:sym<class> {
288288
<sym> <package_def>
289289
}
290290
token package_declarator:sym<grammar> {
291+
:my $*PACKAGE-SETUP := PAST::Stmts.new();
291292
:my $*PKGDECL := 'grammar';
292293
<sym> <package_def>
293294
}

src/PAST/Compiler-Regex.pir

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ Return the POST representation of the regex AST rooted by C<node>.
110110
token_done:
111111
$S0 = regexname
112112
$S0 = concat '!PREFIX__', $S0
113+
$S1 = escape $S0
113114
$P99 = get_hll_global ['PAST'], 'Block'
114-
tpast = $P99.'new'(tpast, 'name'=>$S0, 'lexical'=>0, 'blocktype'=>'method')
115+
tpast = $P99.'new'(tpast, 'name'=>$S0, 'nsentry'=>$S1, 'lexical'=>0, 'blocktype'=>'method')
115116
tpost = self.'as_post'(tpast, 'rtype'=>'v')
116117
ops.'push'(tpost)
117118
peek_done:

0 commit comments

Comments
 (0)