@@ -262,8 +262,9 @@ sub push_block_handler($/, $block) {
262
262
}
263
263
264
264
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 ;
267
268
}
268
269
269
270
method statement_prefix :sym <try >($/ ) {
@@ -375,7 +376,7 @@ method variable($/) {
375
376
method package_declarator :sym <module >($/ ) { make $ < package_def > . ast; }
376
377
method package_declarator :sym <knowhow >($/ ) { make package($/ ); }
377
378
method package_declarator :sym <class >($/ ) { make package($/ ) }
378
- method package_declarator :sym <grammar >($/ ) { make old_package ($/ ) }
379
+ method package_declarator :sym <grammar >($/ ) { make package ($/ ) }
379
380
method package_declarator :sym <role >($/ ) { make package($/ ); }
380
381
381
382
sub package ($/ ) {
@@ -401,7 +402,6 @@ sub package($/) {
401
402
PAST::Var. new ( : name(' $?CLASS' ) ),
402
403
PAST::Var. new ( : name(' type_obj' ), : scope(' register' ) )
403
404
)
404
- # XXX name
405
405
));
406
406
if $ < package_def >< repr > {
407
407
my $ repr_name := $ < package_def >< repr > [0 ]. ast;
@@ -425,6 +425,18 @@ sub package($/) {
425
425
PAST::Var. new ( : name(~ $ name ), : namespace(@ ns ), : scope(' package' ) )
426
426
));
427
427
}
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
+ }
428
440
429
441
# Postfix it with a call to compose.
430
442
$ * PACKAGE-SETUP . push (PAST::Op. new (
@@ -452,31 +464,6 @@ sub package($/) {
452
464
return $ past ;
453
465
}
454
466
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
-
480
467
method package_def ($/ ) {
481
468
my $ past := $ < block > ?? $ < block > . ast !! $ < comp_unit > . ast;
482
469
$ past . namespace( $ < name >< identifier > );
@@ -680,11 +667,6 @@ method routine_def($/) {
680
667
681
668
682
669
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
-
688
670
# If it's just got * as a body, make a multi-dispatch enterer.
689
671
# Otherwise, build method block PAST.
690
672
my $ past ;
@@ -727,7 +709,7 @@ method method_def($/) {
727
709
# the multi-dispatcher to use.
728
710
if $ * MULTINESS eq ' multi' { attach_multi_signature($ past ); }
729
711
730
- # Insert it into the namespace .
712
+ # Insert it into the method table .
731
713
$ * PACKAGE-SETUP . push (PAST::Op. new (
732
714
: pasttype(' callmethod' ), : name($ * MULTINESS eq ' multi' ?? ' add_multi_method' !! ' add_method' ),
733
715
PAST::Op. new (
@@ -753,28 +735,6 @@ method method_def($/) {
753
735
make $ past ;
754
736
}
755
737
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
-
778
738
sub only_star_block () {
779
739
my $ past := @ BLOCK . shift ;
780
740
$ past . closure(1 );
@@ -911,27 +871,39 @@ method regex_declarator($/, $key?) {
911
871
PAST::Stmts. new (
912
872
PAST::Block. new ( : name($ name ),
913
873
PAST::Op. new (
914
- PAST::Var. new ( : name(' self' ), : scope(' register ' ) ),
874
+ PAST::Var. new ( : name(' self' ), : scope(' parameter ' ) ),
915
875
$ name ,
916
876
: name(' !protoregex' ),
917
877
: pasttype(' callmethod' )
918
878
),
919
- : blocktype(' method ' ),
879
+ : blocktype(' declaration ' ),
920
880
: lexical(0 ),
921
881
: node($/ )
922
882
),
923
883
PAST::Block. new ( : name(' !PREFIX__' ~ $ name ),
924
884
PAST::Op. new (
925
- PAST::Var. new ( : name(' self' ), : scope(' register ' ) ),
885
+ PAST::Var. new ( : name(' self' ), : scope(' parameter ' ) ),
926
886
$ name ,
927
887
: name(' !PREFIX__!protoregex' ),
928
888
: pasttype(' callmethod' )
929
889
),
930
- : blocktype(' method ' ),
890
+ : blocktype(' declaration ' ),
931
891
: lexical(0 ),
932
892
: node($/ )
933
893
)
934
894
);
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
+ }
935
907
}
936
908
elsif $ key eq ' open' {
937
909
my % h ;
@@ -956,6 +928,26 @@ method regex_declarator($/, $key?) {
956
928
PAST::Var. new ( : name(' Method' ), : namespace([' Regex' ]), : scope<package > ),
957
929
$ regex
958
930
);
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
+ ));
959
951
# In sink context, we don't need the Regex::Regex object.
960
952
$ past <sink > := $ regex ;
961
953
@ MODIFIERS . shift ;
0 commit comments