Permalink
Browse files

Merge branch 'master' of git://github.com/eriksoe/erjang

  • Loading branch information...
2 parents 6788e29 + 48cfb62 commit d44999ad20e4883cbab9bd97847d158715323574 @krestenkrab krestenkrab committed Nov 10, 2010
@@ -48,25 +48,19 @@
static Logger log = Logger.getLogger("erjang");
public static EAtom am_badsig = EAtom.intern("badsig");
- public static EObject raise(EObject kind, EObject value,
- EObject trace) throws ErlangException {
-
+ public static EObject raise(EObject trace, EObject value) throws ErlangException {
// System.err.println("raise "+trace);
-
- EAtom clazz = kind.testAtom();
- ESeq traz = trace.testSeq();
-
- if (traz == null) {
- System.err.println("bad argument to raise1: ("+kind+", "+value+", "+trace+")");
- return am_badarg;
+ if (trace instanceof ErlangException.ExceptionAsObject) {
+ ErlangException etrace = ((ErlangException.ExceptionAsObject) trace).getException();
+ EAtom clazz = etrace.getExClass();
+ ESeq traz = etrace.getLazyTrace();
+ throw new ErlangRaise(clazz, value, traz);
+ } else if (trace==am_exit || trace==am_error || trace==am_throw) {
+ System.err.println("Pre-R10-1 exception style is not supported.");
}
- if (clazz==am_exit || clazz==am_error || clazz==am_throw)
- throw new ErlangRaise(clazz, value, traz);
-
- new Throwable("bad argument to raise2: ("+kind+", "+value+", "+trace+")").printStackTrace(System.err);
+ new Throwable("bad argument to raise2: ("+value+", "+trace+")").printStackTrace(System.err);
return am_badarg;
-
}
public static final EAtom am_badarg = EAtom.intern("badarg");
@@ -148,6 +148,15 @@ public ESeq getTrace() {
return decodeTrace(getStackTrace());
}
+ public ESeq getLazyTrace() {
+ return new ELazySeq() {
+ @Override
+ protected ESeq initialValue() {
+ return getTrace();
+ }
+ };
+ }
+
public static ESeq decodeTrace(StackTraceElement[] st) {
ESeq trace = ERT.NIL;
@@ -339,14 +348,18 @@ public ETuple3 getTryValue() {
ETuple3 result = new ETuple3();
result.elem1 = getExClass();
result.elem2 = reason;
- result.elem3 = new ELazySeq() {
- @Override
- protected ESeq initialValue() {
- return getTrace();
- }
- };
+ result.elem3 = wrapAsObject();
return result;
}
+ public ExceptionAsObject wrapAsObject() {
+ return new ExceptionAsObject();
+ }
+ /** Exception wrapper to be used in 'try_case' and 'raise' instructions. */
+ public class ExceptionAsObject extends EPseudoTerm {
+ public ErlangException getException() {
+ return ErlangException.this;
+ }
+ }
}
@@ -1231,14 +1231,12 @@ public void visitBitStringTest(BeamOpcode test, int failLabel, Arg in, int intg)
public void visitInsn(BeamOpcode opcode, int failLabel, Arg[] in,
Arg ex) {
if (opcode == BeamOpcode.raise) {
-
- mv.visitFieldInsn(GETSTATIC, ERT_NAME, "am_error", EATOM_DESC);
- push(in[1], EATOM_TYPE);
push(in[0], EOBJECT_TYPE);
+ push(in[1], EOBJECT_TYPE);
- // raise will actually throw
+ // raise will actually throw (if successful)
mv.visitMethodInsn(INVOKESTATIC, ERT_NAME, "raise", "("
- + EOBJECT_DESC + EOBJECT_DESC + EOBJECT_DESC + ")"
+ + EOBJECT_DESC + EOBJECT_DESC + ")"
+ EOBJECT_DESC);
mv.visitInsn(ARETURN);
@@ -1720,9 +1720,9 @@ public void analyze0() {
Insn.Y insn = (Insn.Y) insn_;
getType(current, insn.y);
current = current.popExceptionHandler();
- current = current.setx(0, EATOM_TYPE); // reason
- current = current.setx(1, EOBJECT_TYPE); // value
- current = current.setx(2, EOBJECT_TYPE); // trace
+ current = current.setx(0, EATOM_TYPE); // exc.class
+ current = current.setx(1, EOBJECT_TYPE); // value/reason
+ current = current.setx(2, EOBJECT_TYPE); // exc.object
continue next_insn;
}
@@ -397,11 +397,11 @@ try_end y:
RESTORE_EXH(GET(y));
try_case y:
- RESTORE_EXH(GET(y)); {/* Exception deconstruction done by TryExceptionHandler. */}
+ RESTORE_EXH(GET(y)); {/* Exception deconstruction done by TryExceptionHandler. */}
%class SS(src1:S src2:S)
raise value trace:
- reg[0] = ERT.raise(reg[0], GET(value), GET(trace));
+ reg[0] = ERT.raise(GET(value), GET(trace));
##########========== FLOATING-POINT ==========##########
# TODO: Room for improvement in this section - by not boxing the fregs.

0 comments on commit d44999a

Please sign in to comment.