Skip to content

Commit

Permalink
Use better error message for unregeistered nqp ops
Browse files Browse the repository at this point in the history
Or at least, a consistent one. And in Parrot's case, stop adding to error
messages recursively.
  • Loading branch information
Mouq committed Oct 27, 2013
1 parent aeb9458 commit 27dcb8c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 16 deletions.
27 changes: 21 additions & 6 deletions src/vm/jvm/QAST/Compiler.nqp
Expand Up @@ -2807,6 +2807,19 @@ class QAST::CompilerJAST {

method new_temp_allocator() { StmtTempAlloc.new }

method source_for_node($node) {
my $source := $node.node
?? ~ nqp::escape($node.node.Str)
!! '';
if nqp::chars($source) > 103 {
$source := nqp::substr($source, 0, 100) ~ '...';
}
if nqp::chars($source) {
$source := qq[ (source text: "$source")];
}
$source;
}

method jast($source, :$classname!, *%adverbs) {
# Wrap $source in a QAST::CompUnit if it's not already a viable root node.
unless nqp::istype($source, QAST::CompUnit) {
Expand Down Expand Up @@ -3688,13 +3701,15 @@ class QAST::CompilerJAST {
my $result;
my $err;
try $hll := $*HLL;
#try {
try {
$result := QAST::OperationsJAST.compile_op(self, $hll, $node);
# CATCH { $err := $! }
#}
#if $err {
# nqp::die("Error while compiling op " ~ $node.op ~ ": $err");
#}
CATCH { $err := $! }
}
if $err {
nqp::die($err) if nqp::index($err, "Error while compiling op ") == 0;
my $source := self.source_for_node($node);
nqp::die("Error while compiling op " ~ $node.op ~ "$source: $err");
}
$result
}

Expand Down
26 changes: 25 additions & 1 deletion src/vm/moar/QAST/QASTCompilerMAST.nqp
Expand Up @@ -240,6 +240,19 @@ class QAST::MASTCompiler {
method cloned_inners() { %!cloned_inners }
}

method source_for_node($node) {
my $source := $node.node
?? ~ nqp::escape($node.node.Str)
!! '';
if nqp::chars($source) > 103 {
$source := nqp::substr($source, 0, 100) ~ '...';
}
if nqp::chars($source) {
$source := qq[ (source text: "$source")];
}
$source;
}

our $serno := 0;
method unique($prefix = '') { $prefix ~ $serno++ }

Expand Down Expand Up @@ -892,7 +905,18 @@ class QAST::MASTCompiler {
}

multi method as_mast(QAST::Op $node, :$want) {
QAST::MASTOperations.compile_op(self, $*HLL, $node)
my $result;
my $err;
try {
$result := QAST::MASTOperations.compile_op(self, $*HLL, $node);
CATCH { $err := $! }
}
if $err {
nqp::die($err) if nqp::index($err, "Error while compiling op ") == 0;
my $source := self.source_for_node($node);
nqp::die("Error while compiling op " ~ $node.op ~ "$source: $err");
}
$result
}

multi method as_mast(QAST::VM $node, :$want) {
Expand Down
11 changes: 2 additions & 9 deletions src/vm/parrot/QAST/Compiler.nqp
Expand Up @@ -453,15 +453,7 @@ class QAST::Compiler is HLL::Compiler {
my $*HAVE_IMM_ARG := 0;
my $*QAST_BLOCK_NO_CLOSE := 0;
my $*WANT;
my $err;
try {
$stmts := self.compile_all_the_stmts($node.list);
CATCH { $err := $! }
}
if $err {
my $source := self.source_for_node($node);
nqp::die("Error while compiling block " ~ $node.name ~ "$source: $err");
}
$stmts := self.compile_all_the_stmts($node.list);
}

# Generate parameter handling code.
Expand Down Expand Up @@ -732,6 +724,7 @@ class QAST::Compiler is HLL::Compiler {
CATCH { $err := $! }
}
if $err {
nqp::die($err) if nqp::index($err, "Error while compiling op ") == 0;
my $source := self.source_for_node($node);
nqp::die("Error while compiling op " ~ $node.op ~ "$source: $err");
}
Expand Down

0 comments on commit 27dcb8c

Please sign in to comment.