Package org.allspice.bytecode

Examples of org.allspice.bytecode.MethodDef


public class TestException extends MyTestCase {
  public ClassDef defadd() {
    ClassDef cd = makeClass() ;
    Var x = new Var(1,new TypeName("java.lang.Exception")) ;
    Var ex = new Var(2,new TypeName("java.lang.Exception")) ;
    MethodDef md = new MethodDef(TypeName.INT,"meth",x) ;
    Mark start_pc = new Mark() ;
    Mark end_pc = new Mark() ;
    Mark the_end = new Mark() ;
    Mark handler = new Mark() ;
    md = md.addInstructions(
        new Nop(start_pc),
        new Load(x),
        new Throw(),
        new Nop(end_pc),
        new Goto(the_end),
View Full Code Here


  public ClassDef defadd01(String type,int i1) {
    ClassDef cd = makeClassDef() ;
    {
      Var x = new Var(0,new TypeName(type)) ;
      Var y = new Var(i1,new TypeName(type)) ;
      MethodDef md = new MethodDef(new TypeName(type),"getFoo",x) ;
      md = md.setStatic(true) ;
      md = md.addInstructions(
          new Load(x),
          new Store(y),
          new Load(y),
          new Return(TypeCode.getType(type))
          ) ;
View Full Code Here

public class TestConvert extends MyTestCase {
  public ClassDef defadd(String ret,String type) {
    ClassDef cd = makeClassDef() ;
    Var x = new Var(1,new TypeName(type)) ;
    MethodDef md = new MethodDef(new TypeName(ret),"meth",x) ;
    md = md.addInstructions(
        new Load(x),
        new Convert(TypeCode.getType(type),new TypeName(ret)),
        new Return(TypeCode.getType(ret))
        ) ;
    cd = cd.addMethod(md) ;
View Full Code Here

    FieldDef fd = new FieldDef(Scope.PUBLIC,new TypeName(type),"foo") ;
    fd = fd.setStatic(true) ;
    cd = cd.addField(fd) ;
    {
      Var x = new Var(0,new TypeName(type+"[]")) ;
      MethodDef md = new MethodDef(TypeName.INT,"getFoo",x) ;
      md = md.setStatic(true) ;
      md = md.addInstructions(
          new Load(x),
          new ArrLen(),
          new Return(TypeCode.INT)
          ) ;
      cd = cd.addMethod(md) ;
View Full Code Here

  public ClassDef defadd() {
    ClassDef cd = makeClassDef() ;
    {
      MethodRef mref = new MethodRef(
          new TypeName("java.lang.RuntimeException"),TypeName.VOID,"<init>") ;
      MethodDef md = new MethodDef(TypeName.VOID,"getFoo") ;
      md = md.setStatic(true) ;
      md = md.addInstructions(
          new New(new TypeName("java.lang.RuntimeException")),
          new org.allspice.bytecode.instructions.Dup(TypeCode.VOID,TypeCode.OBJECT),
          new InvokeSpecial(mref),
          new Throw()
          ) ;
View Full Code Here

public class TestXor extends MyTestCase {
  public ClassDef defadd(String ret,String type,int i1,int i2) {
    ClassDef cd = makeClassDef() ;
    Var x = new Var(i1,new TypeName(type)) ;
    Var y = new Var(i2,new TypeName(type)) ;
    MethodDef md = new MethodDef(new TypeName(ret),"meth",x,y) ;
    md = md.addInstructions(
        new Load(x),
        new Load(y),
        new Xor(TypeCode.getType(type)),
        new Return(TypeCode.getType(ret))
        ) ;
View Full Code Here

    ClassDef cd = new ClassDef(ClassDefType.DEFAULT,null,new TypeName("TestClass"),TypeName.OBJECT) ;
    {
      // 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)
      ) ;
View Full Code Here

TOP

Related Classes of org.allspice.bytecode.MethodDef

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.