diff --git a/Jocaml.java b/Jocaml.java index ef219c4..ffacb56 100644 --- a/Jocaml.java +++ b/Jocaml.java @@ -170,6 +170,14 @@ public class Jocaml { this.code = code; this.numArgs = numArgs; } + + static { + for (int i = 0; i < CamlInst.values().length; i++) { + if (CamlInst.values()[i].code != i) { + throw new RuntimeException("what"); + } + } + } } private static class CodeOffset { @@ -413,15 +421,13 @@ public class Jocaml { while (this.data.position() < this.data.capacity()) { int op = this.data.getInt(); String rep = null; - for (CamlInst inst : CamlInst.values()) { - if (inst.code == op) { - rep = inst.name(); - for (int i = 0; i < inst.numArgs; i++) { - rep += " " + this.data.getInt(); - } + try { + CamlInst inst = CamlInst.values()[op]; + rep = inst.name(); + for (int i = 0; i < inst.numArgs; i++) { + rep += " " + this.data.getInt(); } - } - if (rep == null) { + } catch (ArrayIndexOutOfBoundsException e) { rep = ""; } System.out.println(rep);