import cafebabe.ByteCodes._ import cafebabe.AbstractByteCodes._ object babe { def output { val classFile = new cafebabe.ClassFile("Hello", None) classFile.addDefaultConstructor val middleMethod = classFile.addMethod("I", "middle", "I", "I").codeHandler val fresh: Int = middleMethod.getFreshVar middleMethod << ILoad(1) << ILoad(2) << ILoad(1) << ISUB << Ldc(2) << IDIV << IADD << IStore(fresh) << ILoad(fresh) << IRETURN middleMethod.freeze val mainMethod = classFile.addMainMethod.codeHandler mainMethod << GetStatic("java/lang/System","out","Ljava/io/PrintStream;") << DefaultNew("Hello") << Ldc(5) << Ldc(12) << InvokeVirtual("Hello", "middle", "(II)I") << InvokeVirtual("java/io/PrintStream","println","(I)V") << RETURN mainMethod.freeze classFile.writeToFile("Hello.class") } def main(arguments: Array[String]) { output } }