Skip to content
Browse files

Make sure bs_utf{8,16}_size can fail correctly

  • Loading branch information...
1 parent 6199cc8 commit 3e44235a0940039e74a66761ba67f9e9bfd20baf @krestenkrab krestenkrab committed Oct 7, 2013
View
5 src/main/java/erjang/beam/BlockVisitor2.java
@@ -192,10 +192,11 @@ void visitTest(BeamOpcode test, int failLabel, Arg arg, Arg arity,
/**
* @param opcode
- * @param decodeArg
* @param arg2
+ * @param failLabel TODO
+ * @param decodeArg
*/
- void visitBS(BeamOpcode opcode, Arg arg1, Arg arg2);
+ void visitBS(BeamOpcode opcode, Arg arg1, Arg arg2, int failLabel);
/**
* @param in
View
6 src/main/java/erjang/beam/CompilerVisitor.java
@@ -1095,7 +1095,7 @@ public void visitBSAdd(Arg in1, Arg in2, int scale, Arg out) {
* erjang.beam.Arg)
*/
@Override
- public void visitBS(BeamOpcode opcode, Arg arg, Arg imm) {
+ public void visitBS(BeamOpcode opcode, Arg arg, Arg imm, int failLabel) {
switch (opcode) {
case bs_save2:
case bs_restore2:
@@ -1130,7 +1130,9 @@ public void visitBS(BeamOpcode opcode, Arg arg, Arg imm) {
EBINSTRINGBUILDER_TYPE.getInternalName(),
"bs_utf8_size", "(" + EOBJECT_DESC + ")"
+ ESMALL_TYPE.getDescriptor());
+ if (failLabel != 0) mv.visitInsn(DUP);
pop(imm, ESMALL_TYPE);
+ if (failLabel != 0) mv.visitJumpInsn(IFNULL, getLabel(failLabel));
return;
case bs_utf16_size:
@@ -1139,7 +1141,9 @@ public void visitBS(BeamOpcode opcode, Arg arg, Arg imm) {
EBINSTRINGBUILDER_TYPE.getInternalName(),
"bs_utf16_size", "(" + EOBJECT_DESC + ")"
+ ESMALL_TYPE.getDescriptor());
+ if (failLabel != 0) mv.visitInsn(DUP);
pop(imm, ESMALL_TYPE);
+ if (failLabel != 0) mv.visitJumpInsn(IFNULL, getLabel(failLabel));
return;
}
View
8 src/main/java/erjang/beam/analysis/BeamTypeAnalysis.java
@@ -992,7 +992,7 @@ private void accept_2(BlockVisitor2 vis, BeamExceptionHandler exh) {
case bs_context_to_binary: {
Insn.D insn = (Insn.D) insn_;
- vis.visitBS(opcode, dest_arg(insn_idx, insn.dest), null);
+ vis.visitBS(opcode, dest_arg(insn_idx, insn.dest), null, 0);
// do nothing for now
break;
}
@@ -1004,7 +1004,7 @@ private void accept_2(BlockVisitor2 vis, BeamExceptionHandler exh) {
//TODO: streamline - change API
insn.i2 == -1
? new Arg(EAtom.intern("start"))
- : new Arg(new ESmall(insn.i2))
+ : new Arg(new ESmall(insn.i2)), 0
);
break;
}
@@ -1068,8 +1068,8 @@ private void accept_2(BlockVisitor2 vis, BeamExceptionHandler exh) {
Insn.LSD insn = (Insn.LSD) insn_;
Arg value = src_arg(insn_idx, insn.src);
Arg out = dest_arg(insn_idx, insn.dest);
- //TODO: is the label always 0? (Op may fail)
- vis.visitBS(opcode, value, out);
+ int label = decode_labelref(insn.label, type_map.exh);
+ vis.visitBS(opcode, value, out, label);
break;
}

0 comments on commit 3e44235

Please sign in to comment.
Something went wrong with that request. Please try again.