Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

make throw() a method in Perl6::World

Also run a test for typed exceptions
  • Loading branch information...
commit b57f60e83702053ba86b1c46c642ea140554768a 1 parent 22d23a8
@moritz moritz authored
Showing with 36 additions and 33 deletions.
  1. +3 −33 src/Perl6/Actions.pm
  2. +32 −0 src/Perl6/World.pm
  3. +1 −0  t/spectest.data
View
36 src/Perl6/Actions.pm
@@ -58,36 +58,6 @@ class Perl6::Actions is HLL::Actions {
nqp::box_s($s, $*W.find_symbol(['Str']));
}
- our sub throw($/, $ex_type, *%opts) {
- # TODO: provide context
- my $type_found := 1;
- my $ex := try {
- CATCH { $type_found := 0 };
- $*W.find_symbol($ex_type);
- };
- if $type_found {
- my $file := pir::find_caller_lex__ps('$?FILES');
- %opts<line> := nqp::box_i(
- HLL::Compiler.lineof($/.orig, $/.from),
- $*W.find_symbol(['Int'])
- );
- %opts<filename> := p6box_s(
- pir::isnull($file) ?? '<unknown file>' !! $file,
- );
- $ex.new(|%opts).throw;
- } else {
- my @err := ['Error while compiling, type ', nqp::join('::', $ex_type), "\n"];
- for %opts -> $key {
- @err.push: ' ';
- @err.push: $key;
- @err.push: ': ';
- @err.push: %opts{$key};
- @err.push: "\n";
- }
- $/.CURSOR.panic(nqp::join('', @err));
- }
- }
-
method ints_to_string($ints) {
if pir::does($ints, 'array') {
my $result := '';
@@ -608,7 +578,7 @@ class Perl6::Actions is HLL::Actions {
my @params;
my $block := $<blockoid>.ast;
if $block<placeholder_sig> && $<signature> {
- throw($/, ['X', 'Signature', 'Placeholder']);
+ $*W.throw($/, ['X', 'Signature', 'Placeholder']);
}
elsif $block<placeholder_sig> {
@params := $block<placeholder_sig>;
@@ -1137,7 +1107,7 @@ class Perl6::Actions is HLL::Actions {
$past := box_native_if_needed($past, $attr.type);
}
else {
- throw($/, ['X', 'Attribute', 'Undeclared'],
+ $*W.throw($/, ['X', 'Attribute', 'Undeclared'],
name => p6box_s($name),
package-type => p6box_s($*PKGDECL),
package-name => p6box_s($*PACKAGE.HOW.name($*PACKAGE)),
@@ -1489,7 +1459,7 @@ class Perl6::Actions is HLL::Actions {
# Obtain parameters, create signature object and generate code to
# call binder.
if $block<placeholder_sig> && $<multisig> {
- self.throw($/, ['X', 'Signature', 'Placeholder']);
+ $*W.throw($/, ['X', 'Signature', 'Placeholder']);
}
my @params :=
$<multisig> ?? $<multisig>[0].ast !!
View
32 src/Perl6/World.pm
@@ -1836,4 +1836,36 @@ class Perl6::World is HLL::World {
$fix
);
}
+
+ # throws a typed exception
+ method throw($/, $ex_type, *%opts) {
+ # TODO: provide context
+ my $type_found := 1;
+ my $ex := try {
+ CATCH { $type_found := 0 };
+ self.find_symbol($ex_type);
+ };
+ if $type_found {
+ my $file := pir::find_caller_lex__ps('$?FILES');
+ %opts<line> := nqp::box_i(
+ HLL::Compiler.lineof($/.orig, $/.from),
+ $*W.find_symbol(['Int'])
+ );
+ %opts<filename> := nqp::box_s(
+ pir::isnull($file) ?? '<unknown file>' !! $file,
+ self.find_symbol(['Str'])
+ );
+ $ex.new(|%opts).throw;
+ } else {
+ my @err := ['Error while compiling, type ', nqp::join('::', $ex_type), "\n"];
+ for %opts -> $key {
+ @err.push: ' ';
+ @err.push: $key;
+ @err.push: ': ';
+ @err.push: %opts{$key};
+ @err.push: "\n";
+ }
+ $/.CURSOR.panic(nqp::join('', @err));
+ }
+ }
}
View
1  t/spectest.data
@@ -498,6 +498,7 @@ S32-array/splice.t
S32-array/unshift.t
S32-basics/warn.t
S32-container/zip.t
+S32-exceptions/misc.t
S32-hash/exists.t
# S32-hash/delete.t # err: Too many positional parameters passed
S32-hash/invert.t
Please sign in to comment.
Something went wrong with that request. Please try again.