<div dir="ltr">(Btw, kudos to whoever took Zelazny's Amber novels as an inspiration<br>for a project name.  Learning about this triggered a massive trip down<br>memory lane for me.)<br><br>Note: This post is also a kind of addendum to the printing discussion<br>on the other thread.<br><br>I have StackMapGenerator throwing "VerifyError: Frame offset out of<br>bytecode range", and this may be caused by an interaction with the<br>recently added ifThenElse().<br><br>Input is this unit test:<br><br>  (is (= '[["LOCAL 0: int i"]<br>           (ILOAD_0)<br>           (ICONST_1)<br>           (IADD)<br>           (ISTORE_1)<br>           ["LOCAL 1: int __temp"]<br>           (ILOAD_0)<br>           (ICONST_2)<br>           (IADD)<br>           (ISTORE_2)<br>           ["LOCAL 2: int __temp"]<br>           (ILOAD_0)<br>           (ICONST_3)<br>           (IADD)<br>           (ISTORE_3)<br>           ["LOCAL 3: int __temp"]<br>           <br>           (ILOAD_1)<br>           (ILOAD_2)<br>           (IF_ICMPGE L:1)<br>           (ILOAD_2)<br>           (ILOAD_3)<br>           (IF_ICMPGE L:0)<br>           (ICONST_1)<br>           (IRETURN)<br>           [L:0]<br>           (ICONST_0)<br>           (IRETURN)<br>           [L:1]<br>           (ICONST_0)<br>           (IRETURN)]<br>         (asm-expr [^int i] (< (+ i 1) (+ i 2) (+ i 3)))))<br><br>Extending CodeBuilder.java's "with" method with println like such<br><br>    public CodeBuilder with(CodeElement element) {<br>        System.out.println("with "+element);<br>        if (element.toString().contains("OP=GOTO")) {<br>            new Throwable().printStackTrace();<br>        }<br>        ((AbstractElement) element).writeTo(this);<br>        return this;<br>    }<br><br>I get the output below (after some manual indentation).  With the<br>exception of the additional GOTO inserted by ifThenElse() before the<br>final ICONST_0, this seems to match the intended output.<br><br>:accept ClassBuilder start<br>:accept CodeBuilder start<br>with LocalVariable[Slot=0, name=i, descriptor='I']<br>with Label[context=CodeBuilder[id=1458540918], contextInfo=-1]<br>with Load[OP=ILOAD_0, slot=0]<br>with UnboundIntrinsicConstantInstruction[op=ICONST_1]<br>with UnboundOperatorInstruction[op=IADD]<br>with Store[OP=ISTORE_1, slot=1]<br>with Label[context=CodeBuilder[id=1458540918], contextInfo=-1]<br>with LocalVariable[Slot=1, name=__temp, descriptor='I']<br>with Load[OP=ILOAD_0, slot=0]<br>with UnboundIntrinsicConstantInstruction[op=ICONST_2]<br>with UnboundOperatorInstruction[op=IADD]<br>with Store[OP=ISTORE_2, slot=2]<br>with Label[context=CodeBuilder[id=1458540918], contextInfo=-1]<br>with LocalVariable[Slot=2, name=__temp, descriptor='I']<br>with Load[OP=ILOAD_0, slot=0]<br>with UnboundIntrinsicConstantInstruction[op=ICONST_3]<br>with UnboundOperatorInstruction[op=IADD]<br>with Store[OP=ISTORE_3, slot=3]<br>with Label[context=CodeBuilder[id=1458540918], contextInfo=-1]<br>with LocalVariable[Slot=3, name=__temp, descriptor='I']<br><br>with Load[OP=ILOAD_1, slot=1]<br>with Load[OP=ILOAD_2, slot=2]<br>with Branch[OP=IF_ICMPGE]<br>with Label[context=CodeBuilder[id=1458540918], contextInfo=-1]<br>    :accept CodeBuilder start<br>    with Load[OP=ILOAD_2, slot=2]<br>    with Load[OP=ILOAD_3, slot=3]<br>    with Branch[OP=IF_ICMPGE]<br>    with Label[context=CodeBuilder[id=1458540918], contextInfo=-1]<br>        :accept CodeBuilder start<br>        with UnboundIntrinsicConstantInstruction[op=ICONST_1]<br>        with Return[OP=IRETURN]<br>        :accept CodeBuilder end<br>    with Label[context=CodeBuilder[id=1458540918], contextInfo=-1]<br>    with Label[context=CodeBuilder[id=1458540918], contextInfo=-1]<br>        :accept CodeBuilder start<br>        with UnboundIntrinsicConstantInstruction[op=ICONST_0]<br>        with Return[OP=IRETURN]<br>        :accept CodeBuilder end<br>    with Label[context=CodeBuilder[id=1458540918], contextInfo=-1]<br>    with Label[context=CodeBuilder[id=1458540918], contextInfo=-1]<br>    :accept CodeBuilder end<br>with Branch[OP=GOTO]<br>java.lang.Throwable<br>      at java.base/jdk.classfile.impl.DirectCodeBuilder.with(DirectCodeBuilder.java:143)<br>    at java.base/jdk.classfile.impl.DirectCodeBuilder.with(DirectCodeBuilder.java:75)<br>     at java.base/jdk.classfile.impl.BlockCodeBuilderImpl.with(BlockCodeBuilderImpl.java:90)<br>       at java.base/jdk.classfile.impl.BlockCodeBuilderImpl.with(BlockCodeBuilderImpl.java:39)<br>       at java.base/jdk.classfile.CodeBuilder.branchInstruction(CodeBuilder.java:383)<br>        at java.base/jdk.classfile.CodeBuilder.ifThenElse(CodeBuilder.java:288)<br>       at tcljc.emitter.bytecode.__ns100.expr-insns$split-join-insn~4(bytecode.cljt:638)<br>        [...]<br>with Label[context=CodeBuilder[id=1458540918], contextInfo=-1]<br>with Label[context=CodeBuilder[id=1458540918], contextInfo=-1]<br>    :accept CodeBuilder start<br>    with UnboundIntrinsicConstantInstruction[op=ICONST_0]<br>    with Return[OP=IRETURN]<br>    :accept CodeBuilder end<br>with Label[context=CodeBuilder[id=1458540918], contextInfo=-1]<br>with Label[context=CodeBuilder[id=1458540918], contextInfo=-1]<br>:accept CodeBuilder end<br>[...]<br>:accept ClassBuilder end<br><br>Generating stack maps for class: __ns100 method: fnbody~1 with signature: MethodTypeDesc[(int)boolean]<br> ERROR  at tcljc.switch-test/int-cmp-test:45<br>[...]<br>java.lang.VerifyError: Frame offset out of bytecode range at fnbody~1<br>    at java.base/jdk.classfile.impl.StackMapGenerator.generatorError(StackMapGenerator.java:865)<br>  at java.base/jdk.classfile.impl.StackMapGenerator$2.set(StackMapGenerator.java:878)<br>   at java.base/jdk.classfile.impl.StackMapGenerator.detectFrameOffsets(StackMapGenerator.java:893)<br>      at java.base/jdk.classfile.impl.StackMapGenerator.generate(StackMapGenerator.java:308)<br>        at java.base/jdk.classfile.impl.StackMapGenerator.<init>(StackMapGenerator.java:248)<br>    at java.base/jdk.classfile.impl.DirectCodeBuilder$4.writeBody(DirectCodeBuilder.java:298)<br>     at java.base/jdk.classfile.impl.UnboundAttribute$AdHocAttribute.writeTo(UnboundAttribute.java:931)<br>    at java.base/jdk.classfile.impl.AttributeHolder.writeTo(AttributeHolder.java:60)<br>      at java.base/jdk.classfile.impl.DirectMethodBuilder.writeTo(DirectMethodBuilder.java:137)<br>     at java.base/jdk.classfile.impl.BufWriterImpl.writeList(BufWriterImpl.java:197)<br>       at java.base/jdk.classfile.impl.DirectClassBuilder.build(DirectClassBuilder.java:177)<br> at java.base/jdk.classfile.Classfile.build(Classfile.java:216)<br>        at java.base/jdk.classfile.Classfile.build(Classfile.java:198)<br>        at java.base/jdk.classfile.Classfile.build(Classfile.java:184)<br>        at tcljc.emitter.__ns100.build-segment~1(emitter.cljt:190)<br>        [...]<br><br>-- mva<br></div>