Package org.allspice.bytecode

Examples of org.allspice.bytecode.Mark


    add(ContinueStatement.class,new ContinueConverter()) ;
  }

  public static void createAnd(EvaluationContext context,
      final Expr lhs, final Expr rhs, InstList l) throws CompilerException {
    Mark isZero = new Mark() ;
    Mark end = new Mark() ;
    context.compile(null,lhs, l) ;
    l.add(new IfEquals0(context.getTypeCode(lhs),isZero)) ;
    context.compile(null,rhs, l) ;
    l.add(new IfEquals0(context.getTypeCode(rhs),isZero)) ;
    l.add(new Const(Boolean.TRUE)) ;
View Full Code Here


    l.add(new Nop(end)) ;
  }
 
  public static void createOr(EvaluationContext context,
      final Expr lhs, final Expr rhs, InstList l) throws CompilerException {
    Mark isOne = new Mark() ;
    Mark end = new Mark() ;
    context.compile(null,lhs, l) ;
    l.add(new IfNotEquals0(context.getTypeCode(lhs),isOne)) ;
    context.compile(null,rhs, l) ;
    l.add(new IfNotEquals0(context.getTypeCode(rhs),isOne)) ;
    l.add(new Const(Boolean.FALSE)) ;
View Full Code Here

  public static void createBinopComparison(EvaluationContext context,
      final Expr lhs, final Expr rhs, TypeName t, Mark isTrue, Inst i, InstList l  ) throws CompilerException {
    createConvert(context,lhs,t,l) ;
    createConvert(context,rhs,t,l) ;
    Mark end = new Mark() ;
    l.add(i) ;
    l.add(new Const(Boolean.FALSE)) ;
    l.add(new Goto(end)) ;
    l.add(new Nop(isTrue)) ;
    l.add(new Const(Boolean.TRUE)) ;
View Full Code Here

  }
 
  public static void createSwitchStatement(
      EvaluationContext context, Expr cond, Collection<Statement> statements, InstList l) throws CompilerException {
    List<CaseLabel> labels = new ArrayList<CaseLabel>() ;
    Mark theEnd = new Mark() ;
    EvaluationContext newContext = context.setBreak(theEnd) ;
    createConvert(newContext, cond, TypeName.INT,l) ;
    boolean deffound = false ;
    IdentityHashMap<CaseStatement, Mark> marks = new IdentityHashMap<CaseStatement, Mark>() ;
    for(Statement s: statements) {
      if (s instanceof CaseStatement) {
        Mark mark = new Mark() ;
        CaseStatement cs = (CaseStatement)s ;
        final Expr e = cs.e;
        if (e == null) {
          labels.add(new CaseLabel(null,mark)) ;
          deffound = true ;
        }
        else {
          ConstObj constobj = newContext.getConst(e) ;
          if (constobj == null) {
            throw new NonConstCase() ;
          }
          Integer label = getIntValue(constobj) ;
          labels.add(new CaseLabel(label,mark)) ;         
        }
        marks.put(cs,mark) ;
      }
    }
    if (!deffound) {
      labels.add(new CaseLabel(null,theEnd)) ;
    }
    l.add(new LookupSwitch(labels)) ;
    for(Statement s: statements) {
      if (s instanceof CaseStatement) {
        CaseStatement cs = (CaseStatement)s ;
        Mark mark = marks.get(cs) ;
        l.add(new Nop(mark)) ;
      }
      else {
        newContext.compile(s,l) ;
      }
View Full Code Here

    l.add(new Nop(theEnd)) ;
  }

  public static void createFinally(EvaluationContext context,
      Collection<Statement> statements, Collection<CatchBlock> catchBlocks, Collection<Statement> finallyStatements,InstList l) throws CompilerException {
    Mark finallyMark = new Mark() ;
    final VarStack vars = context.decls.addLocalVar(context.getFileUnitInfo(),
        new FIFO<VarDecl>(
        new VarDecl("java.lang.Throwable","$$ex$$"),
        new VarDecl("returnAddress","$$ra$$")));
    EvaluationContext newContext = context.addFinallyDest(finallyMark).setVars(vars) ;
    Var ex = (Var)newContext.getVar("$$ex$$") ;
    Var vret = (Var)newContext.getVar("$$ra$$") ;
    Mark the_end = new Mark() ;
    Mark start_pc = new Mark() ;
    Mark end_pc = new Mark() ;
    Mark handler = new Mark() ;
    l.add(new Nop(start_pc)) ;
    createTryCatch(newContext, statements, catchBlocks,l) ;
    l.add(new Nop(end_pc)) ;
    l.add(new JumpSub(finallyMark)) ;
    l.add(new Goto(the_end)) ;
View Full Code Here

    l.add(new Throw()) ;
  }

  public static void createTryCatch(EvaluationContext context,
      Collection<Statement> statements, Collection<CatchBlock> catchBlocks, InstList l) throws CompilerException {
    Mark start_pc = new Mark() ;
    Mark end_pc = new Mark() ;
    l.add(new Nop(start_pc)) ;
    for(Statement s: statements) {
      context.compile(s,l) ;
    }
    l.add(new Nop(end_pc)) ;
    Mark the_end = new Mark() ;
    l.add(new Goto(the_end)) ;
    for(CatchBlock cb: catchBlocks) {
      final VarStack vars = context.decls.addLocalVar(context.getFileUnitInfo(),new FIFO<VarDecl>(cb.ex));
      EvaluationContext newContext = context.setVars(vars) ;
      Var v = (Var)newContext.getVar(cb.ex.name);
      final String extype = cb.ex.type;
      Mark handler = new Mark() ;
      l.add(new ExceptionHandler(start_pc,end_pc,handler,context.fullyQualified(extype))) ;
      l.add(new Nop(handler)) ;
      l.add(new Store(v)) ;
      for(Statement s1: cb.statements) {
        newContext.compile(s1,l) ;
View Full Code Here

    }
  }

  public static void createSynchronizedStatement(
      EvaluationContext context, Expr monitor, Collection<Statement> statements, InstList l) throws CompilerException {
    Mark finallyMark = new Mark() ;
    final VarDecl varDecl = new VarDecl("Object","$$mon$$",monitor);
    final VarStack vars = context.decls.addLocalVar(context.getFileUnitInfo(),
        new FIFO<VarDecl>(
        varDecl,
        new VarDecl("Throwable","$$ex$$"),
        new VarDecl("returnAddress","$$ra$$"))
        );
    EvaluationContext newContext = context.addFinallyDest(finallyMark).setVars(vars) ;
    LValue v = newContext.getVar("$$mon$$") ;
    Var ex = (Var)newContext.getVar("$$ex$$") ;
    Var vret = (Var)newContext.getVar("$$ra$$") ;
    makeInit(newContext,varDecl.init,v.getType(),l) ;
    l.add(new Dup(TypeCode.VOID,TypeCode.OBJECT)) ;
    l.add(new Store(v)) ;
    l.add(new MonitorEnter()) ;
    Mark the_end = new Mark() ;
    Mark start_pc = new Mark() ;
    Mark end_pc = new Mark() ;
    Mark handler = new Mark() ;
    l.add(new Nop(start_pc)) ;
    for(Statement s: statements) {
      newContext.compile(s,l) ;
    }
    l.add(new Nop(end_pc)) ;
View Full Code Here

    StubResolver td1 = context.getType(thenst) ;
    StubResolver td2 = context.getType(elsest) ;
    TypeCode t1 = condTable.get(new TypePair(td1.getTypeCode(),td2.getTypeCode())) ;
    TypeName type = (t1 != null) ? TypeName.valueOf(t1) : null ;
    context.compile(null,cond, l) ;
    Mark endmark = new Mark() ;
    Mark elsemark = new Mark() ;
    l.add(new IfEquals0(context.getTypeCode(cond),elsemark)) ;
    createConvert(context, thenst, type,l) ;
    l.add(new Goto(endmark)) ;
    l.add(new Nop(elsemark)) ;
    createConvert(context, elsest, type,l) ;
View Full Code Here

    createConvert(context, elsest, type,l) ;
    l.add(new Nop(endmark)) ;
  }

  public static void createDoWhile(EvaluationContext context,Expr cond,Collection<Statement> thenst, InstList l) throws CompilerException {
    Mark beginmark = new Mark() ;
    Mark endmark = new Mark() ;
    EvaluationContext newContext = context.setBreak(endmark).setContinue(beginmark) ;
    l.add(new Nop(beginmark)) ;
    for(Statement s: thenst) {
      newContext.compile(s,l) ;
    }
View Full Code Here

    l.add(new IfNotEquals0(context.getTypeCode(cond),beginmark)) ;
    l.add(new Nop(endmark)) ;
  }

  public static void createWhile(EvaluationContext context,Expr cond,Collection<Statement> thenst, InstList l) throws CompilerException {
    Mark beginmark = new Mark() ;
    Mark endmark = new Mark() ;
    EvaluationContext newContext = context.setBreak(endmark).setContinue(beginmark) ;
    l.add(new Nop(beginmark)) ;
    context.compile(null,cond, l) ;
    l.add(new IfEquals0(context.getTypeCode(cond),endmark)) ;
    for(Statement s: thenst) {
View Full Code Here

TOP

Related Classes of org.allspice.bytecode.Mark

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.