Skip to content

Commit 66dfddd

Browse files
committed
Make errors in QASTCompilerMAST more awesome
Make the wording a bit more consistent and include relevant information where possible. Similar to 513d4eb.
1 parent a70dabf commit 66dfddd

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

src/vm/moar/QAST/QASTCompilerMAST.nqp

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ my class MASTCompilerInstance {
8585
elsif $kind == $MVM_reg_uint32 { @arr := @!uint32s; $type := uint32 }
8686
elsif $kind == $MVM_reg_uint16 { @arr := @!uint16s; $type := uint16 }
8787
elsif $kind == $MVM_reg_uint8 { @arr := @!uint8s; $type := uint8 }
88-
else { nqp::die("unhandled reg kind $kind") }
88+
else { nqp::die("Unhandled reg kind $kind") }
8989

9090
my $reg;
9191
if nqp::elems(@arr) && !$new {
@@ -119,7 +119,7 @@ my class MASTCompilerInstance {
119119
return nqp::push(@!uint32s, $reg) if $kind == $MVM_reg_uint32;
120120
return nqp::push(@!uint16s, $reg) if $kind == $MVM_reg_uint16;
121121
return nqp::push(@!uint8s, $reg) if $kind == $MVM_reg_uint8;
122-
nqp::die("unhandled reg kind $kind");
122+
nqp::die("Unhandled reg kind $kind");
123123
}
124124
}
125125

@@ -263,7 +263,7 @@ my class MASTCompilerInstance {
263263

264264
method return_kind(*@value) {
265265
if @value {
266-
nqp::die("inconsistent immediate block return type")
266+
nqp::die("Inconsistent immediate block return type")
267267
if ($!qast.blocktype eq 'immediate' || $!qast.blocktype eq 'immediate_static') &&
268268
nqp::defined($!return_kind) && @value[0] != $!return_kind;
269269
$!return_kind := @value[0];
@@ -305,7 +305,7 @@ my class MASTCompilerInstance {
305305
$out++;
306306
$block := $block.outer;
307307
}
308-
nqp::die("could not resolve lexical $name");
308+
nqp::die("Could not resolve lexical $name");
309309
}
310310

311311
method capture_inner($block) {
@@ -737,9 +737,14 @@ my class MASTCompilerInstance {
737737
proto method compile_node($node, :$want) { * }
738738

739739
multi method compile_node(QAST::CompUnit $cu, :$want) {
740-
# Should have a single child which is the outer block.
741-
if +@($cu) != 1 || !nqp::istype($cu[0], QAST::Block) {
742-
nqp::die("QAST::CompUnit should have one child that is a QAST::Block");
740+
# Should have a single child
741+
if +@($cu) != 1 {
742+
nqp::die("QAST::CompUnit should have 1 child, got " ~ +@($cu));
743+
}
744+
745+
# Which is the outer block.
746+
if !nqp::istype($cu[0], QAST::Block) {
747+
nqp::die("QAST::CompUnit should have 1 child that is a QAST::Block, got " ~ $cu[0].HOW.name($cu[0]));
743748
}
744749

745750
# Set HLL and serialization context.
@@ -1090,7 +1095,7 @@ my class MASTCompilerInstance {
10901095
# build up instructions to bind the params
10911096
for $block.params -> $var {
10921097
my $scope := $var.scope;
1093-
nqp::die("Param scope must be 'local' or 'lexical'")
1098+
nqp::die("Param scope must be 'local' or 'lexical', got '$scope'")
10941099
if $scope ne 'lexical' && $scope ne 'local';
10951100

10961101
my $param_kind := self.type_to_register_kind($var.returns);
@@ -1118,7 +1123,7 @@ my class MASTCompilerInstance {
11181123
my $name := $var.named;
11191124
if nqp::islist($name) {
11201125
unless nqp::elems($name) == 2 {
1121-
nqp::die("Can only support a single fallback name for a named parameter");
1126+
nqp::die("Can only support 1 fallback name for a named parameter, '" ~ $name[0] ~ "' has " ~ nqp::elems($name) - 1);
11221127
}
11231128
$val := MAST::SVal.new( :value($name[0]) );
11241129
$val2 := MAST::SVal.new( :value($name[1]) );
@@ -1315,7 +1320,7 @@ my class MASTCompilerInstance {
13151320

13161321
multi method compile_node(QAST::Stmts $node, :$want) {
13171322
my $resultchild := $node.resultchild;
1318-
nqp::die("resultchild out of range")
1323+
nqp::die("resultchild out of range, max allowed is " ~ +@($node) - 1 ~ ", got $resultchild")
13191324
if (nqp::defined($resultchild) && $resultchild >= +@($node));
13201325
self.compile_all_the_stmts(@($node), $resultchild)
13211326
}
@@ -1335,7 +1340,7 @@ my class MASTCompilerInstance {
13351340
my %*STMTTEMPS := %stmt_temps;
13361341
my $*INSTMT := 1;
13371342
my $resultchild := $node.resultchild;
1338-
nqp::die("resultchild out of range")
1343+
nqp::die("resultchild out of range, max allowed is " ~ +@($node) - 1 ~ ", got $resultchild")
13391344
if (nqp::defined($resultchild) && $resultchild >= +@($node));
13401345
self.compile_all_the_stmts(@($node), $resultchild);
13411346
}
@@ -1429,7 +1434,7 @@ my class MASTCompilerInstance {
14291434
}
14301435

14311436
sub check_kinds($a, $b) {
1432-
nqp::die("register types $a and $b don't match") unless $a == $b;
1437+
nqp::die("Register types $a and $b don't match") unless $a == $b;
14331438
}
14341439

14351440
my @lex_n_opnames := [
@@ -1545,7 +1550,7 @@ my class MASTCompilerInstance {
15451550
}
15461551
elsif $decl eq 'static' {
15471552
if $scope ne 'lexical' {
1548-
nqp::die("Can only use 'static' decl with scope 'lexical'");
1553+
nqp::die("Can only use 'static' decl with scope 'lexical', got scope '$scope'");
15491554
}
15501555
$*BLOCK.add_lexical($node, :is_static);
15511556
}
@@ -1557,12 +1562,12 @@ my class MASTCompilerInstance {
15571562
$*BLOCK.add_lexical($node, :is_cont);
15581563
}
15591564
else {
1560-
nqp::die("Can only use 'contvar' decl with scope 'lexical' or 'local'");
1565+
nqp::die("Can only use 'contvar' decl with scope 'lexical' or 'local', got scope '$scope'");
15611566
}
15621567
}
15631568
elsif $decl eq 'statevar' {
15641569
if $scope ne 'lexical' {
1565-
nqp::die("Can only use 'statevar' decl with scope 'lexical'");
1570+
nqp::die("Can only use 'statevar' decl with scope 'lexical', got scope '$scope'");
15661571
}
15671572
$*BLOCK.add_lexical($node, :is_state);
15681573
}
@@ -1789,7 +1794,7 @@ my class MASTCompilerInstance {
17891794
# Ensure we have object and class handle.
17901795
my @args := $node.list();
17911796
if +@args != 2 {
1792-
nqp::die("An attribute lookup needs an object and a class handle");
1797+
nqp::die("An attribute lookup needs 2 args (an object and a class handle), got " ~ +@args);
17931798
}
17941799

17951800
# Compile object and handle.
@@ -1842,7 +1847,7 @@ my class MASTCompilerInstance {
18421847
# Ensure we have object and class handle, and aren't binding.
18431848
my @args := $node.list();
18441849
if +@args != 2 {
1845-
nqp::die("An attribute reference needs an object and a class handle");
1850+
nqp::die("An attribute reference needs 2 args (an object and a class handle), got" ~ +@args);
18461851
}
18471852
if $*BINDVAL {
18481853
nqp::die("Cannot bind to QAST::Var '{$name}' with scope attributeref");
@@ -1930,10 +1935,10 @@ my class MASTCompilerInstance {
19301935
if $op.op eq 'const' && nqp::existskey(%const_map, $op.name) {
19311936
return MAST::IVal.new( :value(%const_map{$op.name}) );
19321937
}
1933-
nqp::die("expected QAST constant; got op " ~ $op.op);
1938+
nqp::die("Expected QAST constant, got op '" ~ $op.op ~ "'");
19341939
}
19351940
multi method as_mast_constant(QAST::Node $qast) {
1936-
nqp::die("expected QAST constant; didn't get one");
1941+
nqp::die("Expected QAST constant, got QAST::Node");
19371942
}
19381943

19391944
multi method compile_node(QAST::Want $node, :$want) {
@@ -2059,7 +2064,7 @@ my class MASTCompilerInstance {
20592064
elsif $size == 32 { $MVM_reg_uint32 }
20602065
elsif $size == 16 { $MVM_reg_uint16 }
20612066
elsif $size == 8 { $MVM_reg_uint8 }
2062-
else { nqp::die("Unknown int size $size") }
2067+
else { nqp::die("Unknown uint size $size") }
20632068
}
20642069
else {
20652070
if $size == 64 { $MVM_reg_int64 }

0 commit comments

Comments
 (0)