Package org.allspice.bytecode.instructions

Examples of org.allspice.bytecode.instructions.Return


      // 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)
      ) ;
      // Watch it!  ClassDef is immutable
      cd = cd.addMethod(md) ;
    }
    return cd ;
View Full Code Here


      }
      for(Statement st: body) {
        context.compile(st,il) ;
      }
      StdJavaExpressions.loadZero(TypeCode.getType(retType),il) ;
      il.add(new Return(TypeCode.getType(retType))) ;
      mdef = mdef.addInstructions(il.instructions.toArray(new Inst[0])) ;
      errors.addAll(il.errors) ;
    }
    return mdef;
  }
View Full Code Here

    MethodDef md = new MethodDef(new TypeName(ret),"meth",x,y) ;
    md = md.addInstructions(
        new Load(x),
        new Load(y),
        new ShiftLeft(TypeCode.getType(type)),
        new Return(TypeCode.getType(ret))
        ) ;
    return cd.addMethod(md)
  }
View Full Code Here

      MethodDef md = new MethodDef(new TypeName(type+"[]"),"getFoo") ;
      md = md.setStatic(true) ;
      md = md.addInstructions(
          new Const(10),
          new New(new TypeName(type),1),
          new Return(TypeCode.ARRAY)
          ) ;
      cd = cd.addMethod(md) ;
    }
    return cd ;
  }
View Full Code Here

    md = md.addInstructions(
        new Load(x),
        new Load(y),
        new IfLessThan(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

    MethodDef md = new MethodDef(new TypeName(ret),"meth",x,y) ;
    md = md.addInstructions(
        new Load(x),
        new Load(y),
        new ShiftRight(TypeCode.getType(type)),
        new Return(TypeCode.getType(ret))
        ) ;
    return cd.addMethod(md)
  }
View Full Code Here

    Mark one = new Mark() ;
    md = md.addInstructions(
        new Load(x),
        new IfNotEquals0(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

    Var x = new Var(1,new TypeName(type)) ;
    MethodDef md = new MethodDef(new TypeName(type),"meth",x) ;
    md = md.addInstructions(
        new Increment(x,inc),
        new Load(x),
        new Return(TypeCode.getType(type))
        ) ;
    return cd.addMethod(md)
  }
View Full Code Here

  }

  public static void createReturn(EvaluationContext context,Expr e, InstList l) throws CompilerException {
    if (context.returnInst == null) {
      createConvert(context, e, context.fullyQualified(context.methodDef.returnType), l) ;
      l.add(new Return(TypeCode.getType(context.methodDef.returnType))) ;
    }
    else {
      final VarDecl varDecl = new VarDecl(context.methodDef.returnType,"$$ret$$",e);
      final VarStack vars = context.decls.addLocalVar(context.getFileUnitInfo(),new FIFO<VarDecl>(varDecl));
      EvaluationContext newContext = context.setVars(vars) ;
      LValue v = newContext.getVar("$$ret$$") ;
      makeInit(newContext,varDecl.init,v.getType(),l) ;
      l.add(new Store(v)) ;
      l.add(context.returnInst) ;
      l.add(new Load(v)) ;
      l.add(new Return(TypeCode.getType(context.methodDef.returnType))) ;
    }
  }
View Full Code Here

      md = md.setStatic(true) ;
      md = md.addInstructions(
          new Load(x),
          new Load(y),
          new Pop(TypeCode.INT),
          new Return(TypeCode.INT)
          ) ;
      cd = cd.addMethod(md) ;
    }
    return cd ;
  }
View Full Code Here

TOP

Related Classes of org.allspice.bytecode.instructions.Return

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.