Package org.allspice.bytecode

Examples of org.allspice.bytecode.ClassDef


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

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


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

public class TestArrIncrement extends MyTestCase {
  public ClassDef defadd(Number inc) {
    ClassDef cd = makeClassDef() ;
    Var x = new Var(1,new TypeName("int[]")) ;
    MethodDef md = new MethodDef(TypeName.VOID,"meth",x) ;
    md = md.addInstructions(
        new Load(x),
        new Const(0),
        new Increment(new ArrLValue(TypeName.INT),inc),
        new Return(TypeCode.VOID)
        ) ;
    return cd.addMethod(md)
  }
View Full Code Here

      assertEquals(o,s1) ;
    }   
  }
  public void test6() throws Exception {
   
    ClassDef cd = defadd("int","byte",1,2) ;
    Object obj = makeObject(cd) ;
    Method m = obj.getClass().getMethod("meth",byte.class,byte.class) ;
    Object o = m.invoke(obj,(byte)7,(byte)2) ;
    assertEquals(o,(byte)7 / (byte)2) ;
  }
View Full Code Here

    Object o = m.invoke(obj,(byte)7,(byte)2) ;
    assertEquals(o,(byte)7 / (byte)2) ;
  }
  public void test7() throws Exception {
   
    ClassDef cd = defadd("int","char",1,2) ;
    Object obj = makeObject(cd) ;
    Method m = obj.getClass().getMethod("meth",char.class,char.class) ;
    Object o = m.invoke(obj,(char)7,(char)2) ;
    assertEquals(o,(char)7 / (char)2) ;
  }
View Full Code Here

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

public class TestNew extends MyTestCase {
  public ClassDef defadd() {
    ClassDef cd = makeClassDef() ;
    {
      MethodRef mref = new MethodRef(
          new TypeName("TestClass"),TypeName.VOID,"<init>") ;
      MethodDef md = new MethodDef(new TypeName("TestClass"),"getFoo") ;
      md = md.setStatic(true) ;
      md = md.addInstructions(
          new New(new TypeName("TestClass")),
          new org.allspice.bytecode.instructions.Dup(TypeCode.VOID,TypeCode.OBJECT),
          new InvokeSpecial(mref),
          new Return(TypeCode.OBJECT)
          ) ;
      cd = cd.addMethod(md) ;
    }
    return cd ;
  }
View Full Code Here

    }
    return cd ;
  }
  public void test1() throws Exception {
   
    ClassDef cd = defadd() ;
    Class<?> obj = makeClass(cd) ;
    Method m = obj.getMethod("getFoo") ;
    Object o = m.invoke(null) ;
    assertEquals(o.getClass(),obj) ;
  }
View Full Code Here

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

public class TestIFGT0 extends MyTestCase {
  public ClassDef defadd(String type,int i1) {
    ClassDef cd = makeClassDef() ;
    Var x = new Var(i1,new TypeName(type)) ;
    MethodDef md = new MethodDef(TypeName.BOOLEAN,"meth",x) ;
    Mark one = new Mark() ;
    md = md.addInstructions(
        new Load(x),
        new IfGreaterThan0(TypeCode.getType(type),one),
        new Const(false),
        new Return(TypeCode.BOOLEAN),
        new Nop(one),
        new Const(true),
        new Return(TypeCode.BOOLEAN)
        ) ;
    return cd.addMethod(md)
  }
View Full Code Here

        ) ;
    return cd.addMethod(md)
  }
  public void test1() throws Exception {
   
    ClassDef cd = defadd("double",1) ;
    Object obj = makeObject(cd) ;
    Method m = obj.getClass().getMethod("meth",double.class) ;
    assertEquals(m.invoke(obj,-2.0),false) ;
    assertEquals(m.invoke(obj,0.0),false) ;
    assertEquals(m.invoke(obj,2.0),true) ;
View Full Code Here

    assertEquals(m.invoke(obj,0.0),false) ;
    assertEquals(m.invoke(obj,2.0),true) ;
  }
  public void test2() throws Exception {
   
    ClassDef cd = defadd("long",1) ;
    Object obj = makeObject(cd) ;
    Method m = obj.getClass().getMethod("meth",long.class) ;
    assertEquals(m.invoke(obj,-2L),false) ;
    assertEquals(m.invoke(obj,0L),false) ;
    assertEquals(m.invoke(obj,2L),true) ;
View Full Code Here

    assertEquals(m.invoke(obj,0L),false) ;
    assertEquals(m.invoke(obj,2L),true) ;
  }
  public void test3() throws Exception {
   
    ClassDef cd = defadd("float",1) ;
    Object obj = makeObject(cd) ;
    Method m = obj.getClass().getMethod("meth",float.class) ;
    assertEquals(m.invoke(obj,-2F),false) ;
    assertEquals(m.invoke(obj,0F),false) ;
    assertEquals(m.invoke(obj,2F),true) ;
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.