Package org.allspice.bytecode

Examples of org.allspice.bytecode.ClassDef


import org.allspice.bytecode.instructions.Load;
import org.allspice.bytecode.instructions.Return;

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


import org.allspice.bytecode.instructions.ReturnVar;
import org.allspice.bytecode.instructions.Store;

public class TestJSR extends MyTestCase {
  public ClassDef defadd() {
    ClassDef cd = makeClass() ;
    Var x = new Var(1,TypeName.INT) ;
    Var y = new Var(2,TypeName.INT) ;
    Var z = new Var(3,TypeName.INT) ;
    Var vret = new Var(4,new TypeName("returnAddress")) ;
    MethodDef md = new MethodDef(TypeName.INT,"meth",x,y) ;
    Mark sub = new Mark() ;
    md = md.addInstructions(
        new JumpSub(sub),
        new Load(z),
        new Return(TypeCode.INT),
        new Nop(sub),
        new Store(vret),
        new Load(x),
        new Load(y),
        new Add(TypeCode.INT),
        new Store(z),
        new ReturnVar(vret.index)
        ) ;
    cd = cd.addMethod(md)
    return cd ;
  }
View Full Code Here

    cd = cd.addMethod(md)
    return cd ;
  }
  public void test1() throws Exception {
   
    ClassDef cd = defadd() ;
    Object obj = makeObject(cd) ;
    Method m = obj.getClass().getMethod("meth",int.class,int.class) ;
    Object o = m.invoke(obj,1,7) ;
    assertEquals(o,8) ;
  }
View Full Code Here

import org.allspice.bytecode.instructions.Return;
import org.allspice.bytecode.instructions.Store;

public class TestStaticField extends MyTestCase {
  public ClassDef defadd(String type) {
    ClassDef cd = makeClassDef() ;
    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.VOID,"setFoo",x) ;
      md = md.setStatic(true) ;
      md = md.addInstructions(
          new Load(x),
          new Store(new StaticFieldRef(cd.name,new TypeName(type),"foo")),
          new Return(TypeCode.VOID)
          ) ;
      cd = cd.addMethod(md) ;
    }
    {
      MethodDef md = new MethodDef(new TypeName(type),"getFoo") ;
      md = md.setStatic(true) ;
      md = md.addInstructions(
          new Load(new StaticFieldRef(cd.name,new TypeName(type),"foo")),
          new Return(TypeCode.getType(type))
          ) ;
      cd = cd.addMethod(md) ;
    }
    return cd ;
  }
View Full Code Here

    }
    return cd ;
  }
  public void test1() throws Exception {
   
    ClassDef cd = defadd("int") ;
    Class<?> obj = makeClass(cd) ;
    Method m = obj.getMethod("setFoo",int.class) ;
    m.invoke(null,42) ;
    Field f = obj.getField("foo") ;
    assertEquals(f.get(null),42) ;
View Full Code Here

    m = obj.getMethod("getFoo") ;
    assertEquals(m.invoke(null),42) ;
  }
  public void test2() throws Exception {
   
    ClassDef cd = defadd("long") ;
    Class<?> obj = makeClass(cd) ;
    Method m = obj.getMethod("setFoo",long.class) ;
    m.invoke(null,42L) ;
    Field f = obj.getField("foo") ;
    assertEquals(f.get(null),42L) ;
View Full Code Here

    m = obj.getMethod("getFoo") ;
    assertEquals(m.invoke(null),42L) ;
  }
  public void test3() throws Exception {
   
    ClassDef cd = defadd("float") ;
    Class<?> obj = makeClass(cd) ;
    Method m = obj.getMethod("setFoo",float.class) ;
    m.invoke(null,42F) ;
    Field f = obj.getField("foo") ;
    assertEquals(f.get(null),42F) ;
View Full Code Here

    m = obj.getMethod("getFoo") ;
    assertEquals(m.invoke(null),42F) ;
  }
  public void test4() throws Exception {
   
    ClassDef cd = defadd("double") ;
    Class<?> obj = makeClass(cd) ;
    Method m = obj.getMethod("setFoo",double.class) ;
    m.invoke(null,42D) ;
    Field f = obj.getField("foo") ;
    assertEquals(f.get(null),42D) ;
View Full Code Here

    m = obj.getMethod("getFoo") ;
    assertEquals(m.invoke(null),42D) ;
  }
  public void test5() throws Exception {
   
    ClassDef cd = defadd("byte") ;
    Class<?> obj = makeClass(cd) ;
    Method m = obj.getMethod("setFoo",byte.class) ;
    m.invoke(null,(byte)42) ;
    Field f = obj.getField("foo") ;
    assertEquals(f.get(null),(byte)42) ;
View Full Code Here

    m = obj.getMethod("getFoo") ;
    assertEquals(m.invoke(null),(byte)42) ;
  }
  public void test6() throws Exception {
   
    ClassDef cd = defadd("short") ;
    Class<?> obj = makeClass(cd) ;
    Method m = obj.getMethod("setFoo",short.class) ;
    m.invoke(null,(short)42) ;
    Field f = obj.getField("foo") ;
    assertEquals(f.get(null),(short)42) ;
View Full Code Here

TOP

Related Classes of org.allspice.bytecode.ClassDef

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.