Skip to content

Commit

Permalink
pass the label obj around instead of its addr
Browse files Browse the repository at this point in the history
  • Loading branch information
FROGGS committed May 16, 2014
1 parent b616d6c commit 1655e4e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
20 changes: 15 additions & 5 deletions src/vm/jvm/QAST/Compiler.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -4423,11 +4423,21 @@ class QAST::CompilerJAST {

unless $handler_cares {
$il.append($DUP);
$il.append(JAST::PushIVal.new( :value($label ?? nqp::where($label.value) !! 0) ));
$il.append(JAST::PushIVal.new( :value($outer) ));
$il.append(JAST::Instruction.new( :op('aload'), 'tc' ));
$il.append(JAST::Instruction.new( :op('invokestatic'), $TYPE_OPS, '_is_same_label',
'Void', $TYPE_EX_UNWIND, 'Long', 'Long', $TYPE_TC ));
if $label {
my $labjast := self.as_jast($label, :want($RT_OBJ));
$il.append($labjast.jast);
$*STACK.obtain($il, $labjast);
$il.append(JAST::PushIVal.new( :value($outer) ));
$il.append(JAST::Instruction.new( :op('aload'), 'tc' ));
$il.append(JAST::Instruction.new( :op('invokestatic'), $TYPE_OPS, '_is_same_label',
'Void', $TYPE_EX_UNWIND, $TYPE_SMO, 'Long', $TYPE_TC ));
}
else {
$il.append(JAST::PushIVal.new( :value($outer) ));
$il.append(JAST::Instruction.new( :op('aload'), 'tc' ));
$il.append(JAST::Instruction.new( :op('invokestatic'), $TYPE_OPS, '_rethrow_label',
'Void', $TYPE_EX_UNWIND, 'Long', $TYPE_TC ));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,16 @@ private static void invokeHandler(ThreadContext tc, long[] handlerInfo,
tc.unwinder.unwindTarget = handlerInfo[0];
tc.unwinder.unwindCompUnit = handlerFrame.codeRef.staticInfo.compUnit;
tc.unwinder.category = category;
tc.unwinder.payload = null;
throw tc.unwinder;
case EX_UNWIND_OBJECT:
tc.unwinder.unwindTarget = handlerInfo[0];
tc.unwinder.unwindCompUnit = handlerFrame.codeRef.staticInfo.compUnit;
tc.unwinder.category = category;
if (exObj != null)
tc.unwinder.payload = (SixModelObject)exObj.payload;
else
tc.unwinder.payload = null;
throw tc.unwinder;
case EX_BLOCK:
try {
Expand Down Expand Up @@ -175,6 +178,7 @@ private static void invokeHandler(ThreadContext tc, long[] handlerInfo,
finally {
tc.handlers.remove(tc.handlers.size() - 1);
}
tc.unwinder.category = category;
tc.unwinder.unwindTarget = handlerInfo[0];
tc.unwinder.unwindCompUnit = handlerFrame.codeRef.staticInfo.compUnit;
tc.unwinder.result = Ops.result_o(tc.curFrame);
Expand Down
23 changes: 19 additions & 4 deletions src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java
Original file line number Diff line number Diff line change
Expand Up @@ -4528,18 +4528,33 @@ public static void _throw_c(SixModelObject obj, ThreadContext tc) {
throw ExceptionHandling.dieInternal(tc, "throw needs an object with VMException representation");
}
}
public static void _is_same_label(UnwindException uwex, long where, long outerHandler, ThreadContext tc) {
public static void _is_same_label(UnwindException uwex, SixModelObject where, long outerHandler, ThreadContext tc) {
if ((uwex.category & ExceptionHandling.EX_CAT_LABELED) == 0)
return;

if (uwex instanceof UnwindException) {
SixModelObject payload = uwex.payload;
if (payload.hashCode() == where)
if (uwex.payload.hashCode() == where.hashCode())
return;
VMExceptionInstance vmex = (VMExceptionInstance)newexception(tc);
/* We're moving to the outside so we do not rethrow to us. */
vmex.category = uwex.category;
vmex.payload = uwex.payload;
tc.curFrame.curHandler = outerHandler;
ExceptionHandling.handlerDynamic(tc, vmex.category, false, vmex);
}
else {
throw ExceptionHandling.dieInternal(tc, "_is_same_label needs an object with UnwindException representation");
}
}
public static void _rethrow_label(UnwindException uwex, long outerHandler, ThreadContext tc) {
if ((uwex.category & ExceptionHandling.EX_CAT_LABELED) == 0)
return;

if (uwex instanceof UnwindException) {
/* We're moving to the outside so we do not rethrow to us. */
VMExceptionInstance vmex = (VMExceptionInstance)newexception(tc);
vmex.category = uwex.category;
vmex.payload = payload;
vmex.payload = uwex.payload;
tc.curFrame.curHandler = outerHandler;
ExceptionHandling.handlerDynamic(tc, vmex.category, false, vmex);
}
Expand Down

0 comments on commit 1655e4e

Please sign in to comment.