Skip to content

Commit d4ed168

Browse files
committed
Update QAST::Operations for using PIRT, which gets many more of the QAST tests passing again.
1 parent 6bc5c6c commit d4ed168

File tree

1 file changed

+54
-61
lines changed

1 file changed

+54
-61
lines changed

src/QAST/Operations.nqp

Lines changed: 54 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class QAST::Operations {
108108
elsif $ret_type eq 'N' { $ret_meth := "fresh_n"; }
109109

110110
-> $qastcomp, $op_name, @op_args {
111-
my $ops := $qastcomp.post_new('Ops');
111+
my $ops := PIRT::Ops.new();
112112

113113
# If we need a result register, create it and make it the
114114
# first argument.
@@ -174,7 +174,7 @@ class QAST::Operations {
174174
QAST::Operations.add_core_op('list', -> $qastcomp, $op {
175175
# Create register for the resulting list and make an empty one.
176176
my $list_reg := $*REGALLOC.fresh_p();
177-
my $ops := $qastcomp.post_new('Ops', :result($list_reg));
177+
my $ops := PIRT::Ops.new(:result($list_reg));
178178
$ops.push_pirop('new', $list_reg, "'ResizablePMCArray'");
179179

180180
# Push all the things.
@@ -190,7 +190,7 @@ QAST::Operations.add_core_op('list', -> $qastcomp, $op {
190190
QAST::Operations.add_core_op('qlist', -> $qastcomp, $op {
191191
# Create register for the resulting list and make an empty one.
192192
my $list_reg := $*REGALLOC.fresh_p();
193-
my $ops := $qastcomp.post_new('Ops', :result($list_reg));
193+
my $ops := PIRT::Ops.new(:result($list_reg));
194194
$ops.push_pirop('new', $list_reg, "'QRPA'");
195195

196196
# Push all the things.
@@ -206,7 +206,7 @@ QAST::Operations.add_core_op('qlist', -> $qastcomp, $op {
206206
QAST::Operations.add_core_op('list_i', -> $qastcomp, $op {
207207
# Create register for the resulting list and make an empty one.
208208
my $list_reg := $*REGALLOC.fresh_p();
209-
my $ops := $qastcomp.post_new('Ops', :result($list_reg));
209+
my $ops := PIRT::Ops.new(:result($list_reg));
210210
$ops.push_pirop('new', $list_reg, "'ResizableIntegerArray'");
211211

212212
# Push all the things.
@@ -222,7 +222,7 @@ QAST::Operations.add_core_op('list_i', -> $qastcomp, $op {
222222
QAST::Operations.add_core_op('list_s', -> $qastcomp, $op {
223223
# Create register for the resulting list and make an empty one.
224224
my $list_reg := $*REGALLOC.fresh_p();
225-
my $ops := $qastcomp.post_new('Ops', :result($list_reg));
225+
my $ops := PIRT::Ops.new(:result($list_reg));
226226
$ops.push_pirop('new', $list_reg, "'ResizableStringArray'");
227227

228228
# Push all the things.
@@ -238,7 +238,7 @@ QAST::Operations.add_core_op('list_s', -> $qastcomp, $op {
238238
QAST::Operations.add_core_op('list_b', -> $qastcomp, $op {
239239
# Create register for the resulting list and make an empty one.
240240
my $list_reg := $*REGALLOC.fresh_p();
241-
my $ops := $qastcomp.post_new('Ops', :result($list_reg));
241+
my $ops := PIRT::Ops.new(:result($list_reg));
242242
$ops.push_pirop('new', $list_reg, "'ResizablePMCArray'");
243243

244244
# Push all the things.
@@ -255,7 +255,7 @@ QAST::Operations.add_core_op('list_b', -> $qastcomp, $op {
255255
QAST::Operations.add_core_op('hash', -> $qastcomp, $op {
256256
# Create register for the resulting hash and make an empty one.
257257
my $hash_reg := $*REGALLOC.fresh_p();
258-
my $ops := $qastcomp.post_new('Ops', :result($hash_reg));
258+
my $ops := PIRT::Ops.new(:result($hash_reg));
259259
$ops.push_pirop('new', $hash_reg, "'Hash'");
260260

261261
# Set all the values by key on the hash.
@@ -286,9 +286,8 @@ QAST::Operations.add_core_op('chain', -> $qastcomp, $op {
286286
$cpast := $cpast[0];
287287
}
288288

289-
my $ops := $qastcomp.post_new('Ops', :result($*REGALLOC.fresh_p()));
290-
my $endlabel := $qastcomp.post_new('Label',
291-
:name($qastcomp.unique('chain_end_')));
289+
my $ops := PIRT::Ops.new(:result($*REGALLOC.fresh_p()));
290+
my $endlabel := PIRT::Label.new(:name($qastcomp.unique('chain_end_')));
292291

293292
$cpast := nqp::pop(@clist);
294293
my $apast := $cpast[0];
@@ -328,8 +327,8 @@ for <if unless> -> $op_name {
328327

329328
# Create labels.
330329
my $if_id := $qastcomp.unique($op_name);
331-
my $else_lbl := $qastcomp.post_new('Label', :name($if_id ~ '_else'));
332-
my $end_lbl := $qastcomp.post_new('Label', :name($if_id ~ '_end'));
330+
my $else_lbl := PIRT::Label.new(:name($if_id ~ '_else'));
331+
my $end_lbl := PIRT::Label.new(:name($if_id ~ '_end'));
333332

334333
# Compile each of the children; we'll need to look at the result
335334
# types and pick an overall result type if in non-void context.
@@ -357,7 +356,7 @@ for <if unless> -> $op_name {
357356
my $res_reg := $*REGALLOC."fresh_$res_type"();
358357

359358
# Evaluate the condition first; store result if needed.
360-
my $ops := $qastcomp.post_new('Ops');
359+
my $ops := PIRT::Ops.new();
361360
my $cond_result;
362361
if $operands == 2 {
363362
my $coerced := $qastcomp.coerce(@comp_ops[0], $res_type);
@@ -410,10 +409,9 @@ QAST::Operations.add_core_op('ifnull', -> $qastcomp, $op {
410409
my $exprpost := $qastcomp.as_post($op[0]);
411410
my $vivipost := $qastcomp.coerce($qastcomp.as_post($op[1]),
412411
$qastcomp.infer_type($exprpost));
413-
my $vivlabel := $qastcomp.post_new('Label',
414-
:name($qastcomp.unique('vivi_')));
412+
my $vivlabel := PIRT::Label.new(:name($qastcomp.unique('vivi_')));
415413

416-
my $ops := $qastcomp.post_new('Ops');
414+
my $ops := PIRT::Ops.new();
417415
$ops.push($exprpost);
418416
$ops.push_pirop('unless_null', $exprpost, $vivlabel);
419417
$ops.push($vivipost);
@@ -434,11 +432,11 @@ for ('', 'repeat_') -> $repness {
434432

435433
# Create labels.
436434
my $while_id := $qastcomp.unique($op_name);
437-
my $test_lbl := $qastcomp.post_new('Label', :name($while_id ~ '_test'));
438-
my $next_lbl := $qastcomp.post_new('Label', :name($while_id ~ '_next'));
439-
my $redo_lbl := $qastcomp.post_new('Label', :name($while_id ~ '_redo'));
440-
my $hand_lbl := $qastcomp.post_new('Label', :name($while_id ~ '_handlers'));
441-
my $done_lbl := $qastcomp.post_new('Label', :name($while_id ~ '_done'));
435+
my $test_lbl := PIRT::Label.new(:name($while_id ~ '_test'));
436+
my $next_lbl := PIRT::Label.new(:name($while_id ~ '_next'));
437+
my $redo_lbl := PIRT::Label.new(:name($while_id ~ '_redo'));
438+
my $hand_lbl := PIRT::Label.new(:name($while_id ~ '_handlers'));
439+
my $done_lbl := PIRT::Label.new(:name($while_id ~ '_done'));
442440

443441
# Compile each of the children; we'll need to look at the result
444442
# types and pick an overall result type if in non-void context.
@@ -458,7 +456,7 @@ for ('', 'repeat_') -> $repness {
458456
my $res_reg := $*REGALLOC."fresh_$res_type"();
459457

460458
# Emit the prelude.
461-
my $ops := $qastcomp.post_new('Ops');
459+
my $ops := PIRT::Ops.new();
462460
$ops.result($res_reg);
463461
my $exc_reg := $*REGALLOC.fresh_p();
464462
$ops.push_pirop('new', $exc_reg, "'ExceptionHandler'",
@@ -534,7 +532,7 @@ QAST::Operations.add_core_op('for', -> $qastcomp, $op {
534532
my $res := $*REGALLOC.fresh_p();
535533
my $curval := $*REGALLOC.fresh_p();
536534
my $iter := $*REGALLOC.fresh_p();
537-
my $ops := $qastcomp.post_new('Ops');
535+
my $ops := PIRT::Ops.new();
538536
my $listpost := $qastcomp.coerce($qastcomp.as_post($op[0]), "P");
539537
my $blockpost := $qastcomp.coerce($qastcomp.as_post($op[1]), "P");
540538
$ops.push($listpost);
@@ -543,8 +541,8 @@ QAST::Operations.add_core_op('for', -> $qastcomp, $op {
543541
$ops.push_pirop('iter', $iter, $listpost);
544542

545543
# Loop while we still have values.
546-
my $lbl_loop := $qastcomp.post_new('Label', :name('for_start'));
547-
my $lbl_end := $qastcomp.post_new('Label', :name('for_end'));
544+
my $lbl_loop := PIRT::Label.new(:name('for_start'));
545+
my $lbl_end := PIRT::Label.new(:name('for_end'));
548546
$ops.push($lbl_loop);
549547
$ops.push_pirop('unless', $iter, $lbl_end);
550548

@@ -574,8 +572,8 @@ QAST::Operations.add_core_op('defor', -> $qastcomp, $op {
574572
if +$op.list != 2 {
575573
nqp::die("Operation 'defor' needs 2 operands");
576574
}
577-
my $ops := $qastcomp.post_new('Ops');
578-
my $lbl := $qastcomp.post_new('Label', :name('defor'));
575+
my $ops := PIRT::Ops.new();
576+
my $lbl := PIRT::Label.new(:name('defor'));
579577
my $dreg := $*REGALLOC.fresh_i();
580578
my $rreg := $*REGALLOC.fresh_p();
581579
my $test := $qastcomp.coerce($qastcomp.as_post($op[0]), 'P');
@@ -592,11 +590,11 @@ QAST::Operations.add_core_op('defor', -> $qastcomp, $op {
592590
});
593591

594592
QAST::Operations.add_core_op('xor', -> $qastcomp, $op {
595-
my $ops := $qastcomp.post_new('Ops');
593+
my $ops := PIRT::Ops.new();
596594
$ops.result($*REGALLOC.fresh_p());
597595

598-
my $falselabel := $qastcomp.post_new('Label', :name('xor_false'));
599-
my $endlabel := $qastcomp.post_new('Label', :name('xor_end'));
596+
my $falselabel := PIRT::Label.new(:name('xor_false'));
597+
my $endlabel := PIRT::Label.new(:name('xor_end'));
600598

601599
my @childlist;
602600
my $fpast;
@@ -629,7 +627,7 @@ QAST::Operations.add_core_op('xor', -> $qastcomp, $op {
629627
$ops.push_pirop('and', $i, $t, $u);
630628
$ops.push_pirop('if', $i, $falselabel);
631629
if @childlist {
632-
my $truelabel := $qastcomp.post_new('Label', :name('xor_true'));
630+
my $truelabel := PIRT::Label.new(:name('xor_true'));
633631
$ops.push_pirop('if', $t, $truelabel);
634632
$ops.push_pirop('set', $ops, $bpost);
635633
$ops.push_pirop('set', $t, $u);
@@ -706,7 +704,7 @@ QAST::Operations.add_core_op('call', -> $qastcomp, $op {
706704
my $callee;
707705
my @args := nqp::clone($op.list);
708706
if $op.name {
709-
$callee := $qastcomp.post_new('Ops', :result($qastcomp.escape($op.name)));
707+
$callee := PIRT::Ops.new(:result($qastcomp.escape($op.name)));
710708
}
711709
elsif +@args {
712710
$callee := $qastcomp.as_post(@args.shift());
@@ -716,7 +714,7 @@ QAST::Operations.add_core_op('call', -> $qastcomp, $op {
716714
}
717715

718716
# Process arguments.
719-
my $ops := $qastcomp.post_new('Ops');
717+
my $ops := PIRT::Ops.new();
720718
$ops.node($op.node) if $op.node;
721719
my @pos_arg_results;
722720
my @named_arg_results;
@@ -746,7 +744,7 @@ QAST::Operations.add_core_op('callmethod', -> $qastcomp, $op {
746744
# Where is the name coming from?
747745
my $name;
748746
if $op.name {
749-
$name := $qastcomp.post_new('Ops', :result($qastcomp.escape($op.name)));
747+
$name := PIRT::Ops.new(:result($qastcomp.escape($op.name)));
750748
}
751749
elsif +@args >= 2 {
752750
my $invocant := @args.shift();
@@ -758,7 +756,7 @@ QAST::Operations.add_core_op('callmethod', -> $qastcomp, $op {
758756
}
759757

760758
# Process arguments.
761-
my $ops := $qastcomp.post_new('Ops');
759+
my $ops := PIRT::Ops.new();
762760
$ops.node($op.node) if $op.node;
763761
my @pos_arg_results;
764762
my @named_arg_results;
@@ -787,11 +785,11 @@ QAST::Operations.add_core_op('callmethod', -> $qastcomp, $op {
787785
});
788786

789787
QAST::Operations.add_core_op('lexotic', -> $qastcomp, $op {
790-
my $label1 := $qastcomp.post_new('Label', :name('lexotic_'));
791-
my $label2 := $qastcomp.post_new('Label', :name('lexotic_'));
788+
my $label1 := PIRT::Label.new(:name('lexotic_'));
789+
my $label2 := PIRT::Label.new(:name('lexotic_'));
792790
my $lexname := $qastcomp.escape($op.name);
793791

794-
my $ops := $qastcomp.post_new('Ops');
792+
my $ops := PIRT::Ops.new();
795793
my $handler := $*BLOCK.fresh_lex_p();
796794
$ops.push_pirop('root_new', $handler, "['parrot';'Continuation']");
797795
$ops.push_pirop('set_label', $handler, $label1);
@@ -812,15 +810,15 @@ QAST::Operations.add_core_op('lexotic', -> $qastcomp, $op {
812810
# Context introspection
813811
QAST::Operations.add_core_op('curlexpad', -> $qastcomp, $op {
814812
my $reg := $*REGALLOC.fresh_p();
815-
my $ops := $qastcomp.post_new('Ops');
813+
my $ops := PIRT::Ops.new();
816814
$ops.push_pirop('getinterp', $reg);
817815
$ops.push_pirop('set', $reg, $reg ~ "['lexpad']");
818816
$ops.result($reg);
819817
$ops
820818
});
821819
QAST::Operations.add_core_op('curcode', -> $qastcomp, $op {
822820
my $reg := $*REGALLOC.fresh_p();
823-
my $ops := $qastcomp.post_new('Ops');
821+
my $ops := PIRT::Ops.new();
824822
$ops.push_pirop('getinterp', $reg);
825823
$ops.push_pirop('set', $reg, $reg ~ "['sub']");
826824
$ops.result($reg);
@@ -885,22 +883,19 @@ QAST::Operations.add_core_op('handle', -> $qastcomp, $op {
885883
my $control_label;
886884
my $other_label;
887885
my $num_pops := 0;
888-
my $skip_handler_label := $qastcomp.post_new('Label',
889-
:name($qastcomp.unique('skip_handler_')));
890-
my $ops := $qastcomp.post_new('Ops');
886+
my $skip_handler_label := PIRT::Label.new(:name($qastcomp.unique('skip_handler_')));
887+
my $ops := PIRT::Ops.new();
891888
my $reg := $*REGALLOC.fresh_p();
892889
if $catch {
893-
$catch_label := $qastcomp.post_new('Label',
894-
:name($qastcomp.unique('catch_handler_')));
890+
$catch_label := PIRT::Label.new(:name($qastcomp.unique('catch_handler_')));
895891
$ops.push_pirop('new', $reg, "'ExceptionHandler'");
896892
$ops.push_pirop('set_label', $reg, $catch_label);
897893
$ops.push_pirop('callmethod', "'handle_types_except'", $reg, ".CONTROL_ALL");
898894
$ops.push_pirop('push_eh', $reg);
899895
$num_pops := $num_pops + 1;
900896
}
901897
if $control {
902-
$control_label := $qastcomp.post_new('Label',
903-
:name($qastcomp.unique('catch_handler_')));
898+
$control_label := PIRT::Label.new(:name($qastcomp.unique('catch_handler_')));
904899
$ops.push_pirop('new', $reg, "'ExceptionHandler'", "[.CONTROL_ALL]");
905900
$ops.push_pirop('set_label', $reg, $control_label);
906901
$ops.push_pirop('push_eh', $reg);
@@ -909,8 +904,7 @@ QAST::Operations.add_core_op('handle', -> $qastcomp, $op {
909904
if @other {
910905
my @hnames;
911906
for @other { nqp::push(@hnames, %handler_names{$_}); }
912-
$other_label := $qastcomp.post_new('Label',
913-
:name($qastcomp.unique('catch_handler_')));
907+
$other_label := PIRT::Label.new(:name($qastcomp.unique('catch_handler_')));
914908
$ops.push_pirop('new', $reg, "'ExceptionHandler'",
915909
"[" ~ nqp::join(", ", @hnames) ~ "]");
916910
$ops.push_pirop('set_label', $reg, $other_label);
@@ -954,8 +948,7 @@ QAST::Operations.add_core_op('handle', -> $qastcomp, $op {
954948
my %type_labels;
955949
$ops.push_pirop('set', $type_reg, $reg ~ '["type"]');
956950
for @other {
957-
my $lbl := $qastcomp.post_new('Label',
958-
:name($qastcomp.unique('handle_type_')));
951+
my $lbl := PIRT::Label.new(:name($qastcomp.unique('handle_type_')));
959952
$ops.push_pirop('eq', $type_reg, %handler_names{$_}, $lbl);
960953
%type_labels{$_} := $lbl;
961954
}
@@ -984,7 +977,7 @@ QAST::Operations.add_core_op('exception', -> $qastcomp, $op {
984977
unless $exc_reg {
985978
nqp::die("Can only use 'exception' op in the context of an exception handler");
986979
}
987-
my $ops := $qastcomp.post_new('Ops');
980+
my $ops := PIRT::Ops.new();
988981
$ops.result($exc_reg);
989982
$ops
990983
});
@@ -994,7 +987,7 @@ QAST::Operations.add_core_op('getpayload', -> $qastcomp, $op {
994987
}
995988
my $exc := $qastcomp.coerce($qastcomp.as_post($op[0]), 'P');
996989
my $reg := $*REGALLOC.fresh_p();
997-
my $ops := $qastcomp.post_new('Ops');
990+
my $ops := PIRT::Ops.new();
998991
$ops.push($exc);
999992
$ops.push_pirop('getattribute', $reg, $exc.result, '"payload"');
1000993
$ops.result($reg);
@@ -1006,7 +999,7 @@ QAST::Operations.add_core_op('setpayload', -> $qastcomp, $op {
1006999
}
10071000
my $exc := $qastcomp.coerce($qastcomp.as_post($op[0]), 'P');
10081001
my $payload := $qastcomp.coerce($qastcomp.as_post($op[1]), 'P');
1009-
my $ops := $qastcomp.post_new('Ops');
1002+
my $ops := PIRT::Ops.new();
10101003
$ops.push_pirop('setattribute', $exc, '"payload"', $payload);
10111004
$ops.result($payload.result);
10121005
$ops
@@ -1018,7 +1011,7 @@ QAST::Operations.add_core_op('getmessage', -> $qastcomp, $op {
10181011
my $exc := $qastcomp.coerce($qastcomp.as_post($op[0]), 'P');
10191012
my $pmc := $*REGALLOC.fresh_p();
10201013
my $reg := $*REGALLOC.fresh_s();
1021-
my $ops := $qastcomp.post_new('Ops');
1014+
my $ops := PIRT::Ops.new();
10221015
$ops.push($exc);
10231016
$ops.push_pirop('getattribute', $pmc, $exc.result, '"message"');
10241017
$ops.push_pirop('set', $reg, $pmc);
@@ -1032,7 +1025,7 @@ QAST::Operations.add_core_op('setmessage', -> $qastcomp, $op {
10321025
my $exc := $qastcomp.coerce($qastcomp.as_post($op[0]), 'P');
10331026
my $message := $qastcomp.coerce($qastcomp.as_post($op[1]), 'S');
10341027
my $pmc := $*REGALLOC.fresh_p();
1035-
my $ops := $qastcomp.post_new('Ops');
1028+
my $ops := PIRT::Ops.new();
10361029
$ops.push($exc);
10371030
$ops.push($message);
10381031
$ops.push_pirop('box', $pmc, $message);
@@ -1045,7 +1038,7 @@ QAST::Operations.add_core_op('newexception', -> $qastcomp, $op {
10451038
nqp::die("The 'newexception' op expects no children");
10461039
}
10471040
my $reg := $*REGALLOC.fresh_p();
1048-
my $ops := $qastcomp.post_new('Ops');
1041+
my $ops := PIRT::Ops.new();
10491042
$ops.push_pirop('new', $reg, '["Exception"]');
10501043
$ops.result($reg);
10511044
$ops
@@ -1059,7 +1052,7 @@ QAST::Operations.add_core_pirop_mapping('rethrow', 'rethrow', '0P');
10591052
for <i n s> {
10601053
QAST::Operations.add_hll_box('nqp', $_, -> $qastcomp, $post {
10611054
my $reg := $*REGALLOC.fresh_p();
1062-
my $ops := $qastcomp.post_new('Ops');
1055+
my $ops := PIRT::Ops.new();
10631056
$ops.push($post);
10641057
$ops.push_pirop('box', $reg, $post);
10651058
$ops.result($reg);
@@ -1068,23 +1061,23 @@ for <i n s> {
10681061
}
10691062
QAST::Operations.add_hll_unbox('nqp', 'i', -> $qastcomp, $post {
10701063
my $reg := $*REGALLOC.fresh_i();
1071-
my $ops := $qastcomp.post_new('Ops');
1064+
my $ops := PIRT::Ops.new();
10721065
$ops.push($post);
10731066
$ops.push_pirop('set', $reg, $post);
10741067
$ops.result($reg);
10751068
$ops
10761069
});
10771070
QAST::Operations.add_hll_unbox('nqp', 'n', -> $qastcomp, $post {
10781071
my $reg := $*REGALLOC.fresh_n();
1079-
my $ops := $qastcomp.post_new('Ops');
1072+
my $ops := PIRT::Ops.new();
10801073
$ops.push($post);
10811074
$ops.push_pirop('set', $reg, $post);
10821075
$ops.result($reg);
10831076
$ops
10841077
});
10851078
QAST::Operations.add_hll_unbox('nqp', 's', -> $qastcomp, $post {
10861079
my $reg := $*REGALLOC.fresh_s();
1087-
my $ops := $qastcomp.post_new('Ops');
1080+
my $ops := PIRT::Ops.new();
10881081
$ops.push($post);
10891082
$ops.push_pirop('set', $reg, $post);
10901083
$ops.result($reg);

0 commit comments

Comments
 (0)