Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
cleanup
  • Loading branch information
diakopter committed Nov 8, 2011
1 parent c14bd69 commit 3997d21
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
23 changes: 23 additions & 0 deletions lua/compiler/LST.pm
Expand Up @@ -262,6 +262,29 @@ class LST::TryCatch is LST::Node {
}
}

class LST::TryCatchFinally is LST::Node {
has $!exception_type;
has $!exception_var;

method exception_type($set?) {
if $set { $!exception_type := $set }
$!exception_type
}

method exception_var($set?) {
if $set { $!exception_var := $set }
$!exception_var
}

method new(*@children, :$exception_type!, :$exception_var!) {
my $obj := self.CREATE;
$obj.exception_type($exception_type);
$obj.exception_var($exception_var);
$obj.set_children(@children);
$obj;
}
}

class LST::Throw is LST::Node {
method new() {
my $obj := self.CREATE;
Expand Down
22 changes: 22 additions & 0 deletions lua/compiler/LST2Lua.pm
Expand Up @@ -159,6 +159,28 @@ our multi sub cs_for(LST::TryCatch $tc) {
return $code;
}

our multi sub cs_for(LST::TryCatchFinally $tc) {
unless +@($tc) == 3 { pir::die('LST::TryCatchFinally nodes must have 3 children') }
my $try_result := get_unique_id('try_result');
my $code := " try_catch_finally(\n" ~
" function ()\n" ~
cs_for((@($tc))[0]);
$code := $code ~
" $try_result = $*LAST_TEMP;\n" ~
" end,\n" ~
" \"" ~ $tc.exception_type ~ "\",\n" ~
" function (catchClass, exceptions, exc)\n" ~
cs_for((@($tc))[1]) ~
" $try_result = $*LAST_TEMP;\n" ~
" end,\n" ~
" function ()\n" ~
cs_for((@($tc))[2]) ~
" end\n" ~
" );\n";
$*LAST_TEMP := $try_result;
return $code;
}

our multi sub cs_for(LST::MethodCall $mc) {
# Code generate all the arguments.
my @arg_names;
Expand Down
6 changes: 0 additions & 6 deletions lua/runtime/Try.lua
@@ -1,11 +1,5 @@
-- originally from http://failboat.me/2010/lua-exception-handling/

local _mtg = {}
local _orig = getmetatable(_G)
function _mtg.__index(self, k)
return rawget(self,k.."___macro")
end

E = {}
setmetatable(E, {__index = function(self,k) return k end})
E.resolve = function(exception)
Expand Down

0 comments on commit 3997d21

Please sign in to comment.