Skip to content

Commit 7194ff4

Browse files
authored
Merge pull request #351 from MasterDuke17/make_errors_in_QASTOperationsMAST_more_awesome
Make errors in QASTOperationsMAST more awesome
2 parents a29b818 + 513d4eb commit 7194ff4

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

src/vm/moar/QAST/QASTOperationsMAST.nqp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class QAST::MASTOperations {
178178
# if we've already seen a type-var
179179
if ($arg_kind != $type_var_kind) {
180180
# the arg types must match
181-
nqp::die("variable-type op requires same-typed args");
181+
nqp::die("variable-type op '$op' requires same-typed args");
182182
}
183183
}
184184
else {
@@ -328,7 +328,7 @@ class QAST::MASTOperations {
328328
else {
329329
nqp::die("MoarVM op '$moarop' is unknown as a core or extension op");
330330
}
331-
nqp::die("moarop $moarop return arg index out of range")
331+
nqp::die("moarop $moarop return arg index $ret out of range -1.." ~ $num_operands - 1)
332332
if $ret < -1 || $ret >= $num_operands;
333333
nqp::die("moarop $moarop is not void")
334334
if $num_operands && (nqp::atpos_i(@operands_values, $operands_offset) +& $MVM_operand_rw_mask) ==
@@ -584,7 +584,7 @@ QAST::MASTOperations.add_core_op('list_b', -> $qastcomp, $op {
584584
# Push things to the list.
585585
my $item_reg := $regalloc.fresh_register($MVM_reg_obj);
586586
for $op.list {
587-
nqp::die("list_b must have a list of blocks")
587+
nqp::die("The 'list_b' op needs a list of blocks, got " ~ $_.HOW.name($_))
588588
unless nqp::istype($_, QAST::Block);
589589
my $cuid := $_.cuid();
590590
my $frame := $qastcomp.mast_frames{$cuid};
@@ -689,7 +689,7 @@ for <if unless with without> -> $op_name {
689689
QAST::MASTOperations.add_core_op($op_name, -> $qastcomp, $op {
690690
# Check operand count.
691691
my $operands := +$op.list;
692-
nqp::die("Operation '$op_name' needs either 2 or 3 operands")
692+
nqp::die("The '$op_name' op needs 2 or 3 operands, got $operands")
693693
if $operands < 2 || $operands > 3;
694694

695695
# Create labels.
@@ -749,7 +749,7 @@ for <if unless with without> -> $op_name {
749749
}
750750

751751
if (@comp_ops[0].result_kind == $MVM_reg_void) {
752-
nqp::die("operation '$op_name' condition cannot be void");
752+
nqp::die("The '$op_name' op condition cannot be void, cannot use the results of '" ~ $op[0].op ~ "'");
753753
}
754754

755755
my $res_kind;
@@ -850,7 +850,7 @@ for <if unless with without> -> $op_name {
850850

851851
QAST::MASTOperations.add_core_op('defor', -> $qastcomp, $op {
852852
if +$op.list != 2 {
853-
nqp::die("Operation 'defor' needs 2 operands");
853+
nqp::die("The 'defor' op needs 2 operands, got " ~ +$op.list);
854854
}
855855

856856
# Compile the expression.
@@ -960,7 +960,7 @@ QAST::MASTOperations.add_core_op('xor', -> $qastcomp, $op {
960960

961961
QAST::MASTOperations.add_core_op('ifnull', -> $qastcomp, $op {
962962
if +$op.list != 2 {
963-
nqp::die("The 'ifnull' op expects two children");
963+
nqp::die("The 'ifnull' op needs 2 operands, got " ~ +$op.list);
964964
}
965965

966966
# Compile the expression.
@@ -1051,7 +1051,7 @@ for ('', 'repeat_') -> $repness {
10511051

10521052
# Check operand count.
10531053
my $operands := +@comp_ops;
1054-
nqp::die("Operation '$repness$op_name' needs 2 or 3 operands")
1054+
nqp::die("The '$repness$op_name' op needs 2 or 3 operands, got $operands")
10551055
if $operands != 2 && $operands != 3;
10561056

10571057
# Test the condition and jump to the loop end if it's
@@ -1172,10 +1172,10 @@ QAST::MASTOperations.add_core_op('for', -> $qastcomp, $op {
11721172
}
11731173

11741174
if +@operands != 2 {
1175-
nqp::die("Operation 'for' needs 2 operands");
1175+
nqp::die("The 'for' op needs 2 operands, got " ~ +@operands);
11761176
}
11771177
unless nqp::istype(@operands[1], QAST::Block) {
1178-
nqp::die("Operation 'for' expects a block as its second operand");
1178+
nqp::die("The 'for' op expects a block as its second operand, got " ~ @operands[1].HOW.name(@operands[1]));
11791179
}
11801180

11811181

@@ -1330,10 +1330,10 @@ sub handle_arg($arg, $qastcomp, @ins, @arg_regs, @arg_flags, @arg_kinds) {
13301330
$arg_mast := $qastcomp.coerce($arg_mast, $MVM_reg_int64);
13311331
}
13321332

1333-
nqp::die("arg expression cannot be void")
1333+
nqp::die("Arg expression cannot be void, cannot use the return of " ~ $arg.op)
13341334
if $arg_mast.result_kind == $MVM_reg_void;
13351335

1336-
nqp::die("arg code did not result in a MAST::Local")
1336+
nqp::die("Arg code did not result in a MAST::Local")
13371337
unless $arg_mast.result_reg && $arg_mast.result_reg ~~ MAST::Local;
13381338

13391339
nqp::push(@arg_kinds, $arg_mast.result_kind);
@@ -1391,7 +1391,7 @@ my $call_gen := sub ($qastcomp, $op) {
13911391
}
13921392
@args := arrange_args(@args);
13931393

1394-
nqp::die("callee code did not result in a MAST::Local")
1394+
nqp::die("Callee code did not result in a MAST::Local")
13951395
unless $callee.result_reg && $callee.result_reg ~~ MAST::Local;
13961396

13971397
# main instruction list
@@ -1466,10 +1466,10 @@ QAST::MASTOperations.add_core_op('callmethod', -> $qastcomp, $op {
14661466
}
14671467
@args := arrange_args(@args);
14681468

1469-
nqp::die("invocant expression must be an object")
1469+
nqp::die("Invocant expression must be an object, got " ~ $invocant.result_kind)
14701470
unless $invocant.result_kind == $MVM_reg_obj;
14711471

1472-
nqp::die("invocant code did not result in a MAST::Local")
1472+
nqp::die("Invocant code did not result in a MAST::Local")
14731473
unless $invocant.result_reg && $invocant.result_reg ~~ MAST::Local;
14741474

14751475
# main instruction list
@@ -1583,10 +1583,10 @@ QAST::MASTOperations.add_core_op('bind', -> $qastcomp, $op {
15831583
# Sanity checks.
15841584
my @children := $op.list;
15851585
if +@children != 2 {
1586-
nqp::die("A 'bind' op must have exactly two children");
1586+
nqp::die("The 'bind' op needs two children, got " ~ +@children);
15871587
}
15881588
unless nqp::istype(@children[0], QAST::Var) {
1589-
nqp::die("First child of a 'bind' op must be a QAST::Var");
1589+
nqp::die("First child of a 'bind' op must be a QAST::Var, got " ~ @children[0].HOW.name(@children[0]));
15901590
}
15911591

15921592
# Set the QAST of the think we're to bind, then delegate to
@@ -1727,7 +1727,7 @@ QAST::MASTOperations.add_core_op('handle', :!inlinable, sub ($qastcomp, $op) {
17271727
QAST::MASTOperations.add_core_op('handlepayload', :!inlinable, sub ($qastcomp, $op) {
17281728
my @children := $op.list;
17291729
if @children != 3 {
1730-
nqp::die("The 'handlepayload' op requires three children");
1730+
nqp::die("The 'handlepayload' op needs 3 children, got " ~ +@children);
17311731
}
17321732
my str $type := @children[1];
17331733
unless nqp::existskey(%handler_names, $type) {
@@ -2274,7 +2274,7 @@ QAST::MASTOperations.add_core_moarop_mapping('indexingoptimized', 'indexingoptim
22742274
QAST::MASTOperations.add_core_op('tclc', -> $qastcomp, $op {
22752275
my @operands := $op.list;
22762276
unless +@operands == 1 {
2277-
nqp::die('tclc op requires one argument');
2277+
nqp::die("The 'tclc' op needs 1 argument, got " ~ +@operands);
22782278
}
22792279
$qastcomp.as_mast(
22802280
QAST::Op.new( :op('concat'),
@@ -2674,7 +2674,7 @@ sub add_native_assign_op($op_name, $kind) {
26742674
QAST::MASTOperations.add_core_op($op_name, -> $qastcomp, $op {
26752675
my @operands := $op.list;
26762676
unless +@operands == 2 {
2677-
nqp::die($op ~ ' op requires two arguments');
2677+
nqp::die("The '$op' op needs 2 arguments, got " ~ +@operands);
26782678
}
26792679
my $target := @operands[0];
26802680
if try_get_bind_scope($target) -> $bind_scope {
@@ -2740,7 +2740,7 @@ QAST::MASTOperations.add_core_op('locallifetime', -> $qastcomp, $op {
27402740
# XXX explicit takeclosure will go away under new model; for now, no-op it.
27412741
QAST::MASTOperations.add_core_op('takeclosure', -> $qastcomp, $op {
27422742
unless +@($op) == 1 {
2743-
nqp::die('takeclosure op requires one argument');
2743+
nqp::die("The 'takeclosure' op needs 1 argument, got " ~ +@($op));
27442744
}
27452745
$qastcomp.as_mast($op[0])
27462746
});
@@ -2754,7 +2754,7 @@ QAST::MASTOperations.add_core_moarop_mapping('setdispatcherfor', 'setdispatcherf
27542754
QAST::MASTOperations.add_core_op('takedispatcher', -> $qastcomp, $op {
27552755
my $regalloc := $*REGALLOC;
27562756
unless nqp::istype($op[0], QAST::SVal) {
2757-
nqp::die("takedispatcher must have a single QAST::SVal child");
2757+
nqp::die("The 'takedispatcher' op must have a single QAST::SVal child, got " ~ $op[0].HOW.name($op[0]));
27582758
}
27592759
my @ops;
27602760
my $disp_reg := $regalloc.fresh_register($MVM_reg_obj);
@@ -2915,12 +2915,12 @@ sub resolve_condition_op($kind, $negated) {
29152915
$kind == $MVM_reg_num64 ?? 'unless_n' !!
29162916
$kind == $MVM_reg_str ?? 'unless_s0' !!
29172917
$kind == $MVM_reg_obj ?? 'unless_o' !!
2918-
nqp::die("unhandled kind $kind")
2918+
nqp::die("Unhandled kind $kind")
29192919
!! $kind == $MVM_reg_int64 ?? 'if_i' !!
29202920
$kind == $MVM_reg_num64 ?? 'if_n' !!
29212921
$kind == $MVM_reg_str ?? 'if_s0' !!
29222922
$kind == $MVM_reg_obj ?? 'if_o' !!
2923-
nqp::die("unhandled kind $kind")
2923+
nqp::die("Unhandled kind $kind")
29242924
}
29252925

29262926
sub push_op(@dest, str $op, *@args) {

0 commit comments

Comments
 (0)