Skip to content

Commit

Permalink
Make sure bs_utf{8,16}_size can fail correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
krestenkrab committed Oct 7, 2013
1 parent 6199cc8 commit 3e44235
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/main/java/erjang/beam/BlockVisitor2.java
Expand Up @@ -192,10 +192,11 @@ void visitTest(BeamOpcode test, int failLabel, Arg arg, Arg arity,


/** /**
* @param opcode * @param opcode
* @param decodeArg
* @param arg2 * @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 * @param in
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/erjang/beam/CompilerVisitor.java
Expand Up @@ -1095,7 +1095,7 @@ public void visitBSAdd(Arg in1, Arg in2, int scale, Arg out) {
* erjang.beam.Arg) * erjang.beam.Arg)
*/ */
@Override @Override
public void visitBS(BeamOpcode opcode, Arg arg, Arg imm) { public void visitBS(BeamOpcode opcode, Arg arg, Arg imm, int failLabel) {
switch (opcode) { switch (opcode) {
case bs_save2: case bs_save2:
case bs_restore2: case bs_restore2:
Expand Down Expand Up @@ -1130,7 +1130,9 @@ public void visitBS(BeamOpcode opcode, Arg arg, Arg imm) {
EBINSTRINGBUILDER_TYPE.getInternalName(), EBINSTRINGBUILDER_TYPE.getInternalName(),
"bs_utf8_size", "(" + EOBJECT_DESC + ")" "bs_utf8_size", "(" + EOBJECT_DESC + ")"
+ ESMALL_TYPE.getDescriptor()); + ESMALL_TYPE.getDescriptor());
if (failLabel != 0) mv.visitInsn(DUP);
pop(imm, ESMALL_TYPE); pop(imm, ESMALL_TYPE);
if (failLabel != 0) mv.visitJumpInsn(IFNULL, getLabel(failLabel));
return; return;


case bs_utf16_size: case bs_utf16_size:
Expand All @@ -1139,7 +1141,9 @@ public void visitBS(BeamOpcode opcode, Arg arg, Arg imm) {
EBINSTRINGBUILDER_TYPE.getInternalName(), EBINSTRINGBUILDER_TYPE.getInternalName(),
"bs_utf16_size", "(" + EOBJECT_DESC + ")" "bs_utf16_size", "(" + EOBJECT_DESC + ")"
+ ESMALL_TYPE.getDescriptor()); + ESMALL_TYPE.getDescriptor());
if (failLabel != 0) mv.visitInsn(DUP);
pop(imm, ESMALL_TYPE); pop(imm, ESMALL_TYPE);
if (failLabel != 0) mv.visitJumpInsn(IFNULL, getLabel(failLabel));
return; return;


} }
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/erjang/beam/analysis/BeamTypeAnalysis.java
Expand Up @@ -992,7 +992,7 @@ private void accept_2(BlockVisitor2 vis, BeamExceptionHandler exh) {


case bs_context_to_binary: { case bs_context_to_binary: {
Insn.D insn = (Insn.D) insn_; 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 // do nothing for now
break; break;
} }
Expand All @@ -1004,7 +1004,7 @@ private void accept_2(BlockVisitor2 vis, BeamExceptionHandler exh) {
//TODO: streamline - change API //TODO: streamline - change API
insn.i2 == -1 insn.i2 == -1
? new Arg(EAtom.intern("start")) ? new Arg(EAtom.intern("start"))
: new Arg(new ESmall(insn.i2)) : new Arg(new ESmall(insn.i2)), 0
); );
break; break;
} }
Expand Down Expand Up @@ -1068,8 +1068,8 @@ private void accept_2(BlockVisitor2 vis, BeamExceptionHandler exh) {
Insn.LSD insn = (Insn.LSD) insn_; Insn.LSD insn = (Insn.LSD) insn_;
Arg value = src_arg(insn_idx, insn.src); Arg value = src_arg(insn_idx, insn.src);
Arg out = dest_arg(insn_idx, insn.dest); Arg out = dest_arg(insn_idx, insn.dest);
//TODO: is the label always 0? (Op may fail) int label = decode_labelref(insn.label, type_map.exh);
vis.visitBS(opcode, value, out); vis.visitBS(opcode, value, out, label);
break; break;
} }


Expand Down

0 comments on commit 3e44235

Please sign in to comment.