{
// constructor called <init>
// must call superclass's <init>
// Returns nothing
MethodDef md = new MethodDef(TypeName.VOID,"<init>").addInstructions(
new Load(new Var(0,new TypeName("TestClass"))),
new InvokeSpecial(new MethodRef(cd.superClass,TypeName.VOID,"<init>")),
new Return(TypeCode.VOID)
) ;
// Watch it! ClassDef is immutable
cd = cd.addMethod(md) ;
}
{
// Two variables, x & y
// Index 0 is "this"
Var x = new Var(1,TypeName.INT) ; // index 1
Var y = new Var(2,TypeName.INT) ; // index 2
MethodDef md = new MethodDef(TypeName.INT,"add",x,y).addInstructions(
new Load(x),
new Load(y),
new Add(TypeCode.INT),
new Return(TypeCode.INT)