Examples of Code


Examples of anvil.codec.Code

  }
 

  public void compile(ByteCompiler context)
  {
    Code code = context.getCode();
    Target start = code.getTarget();
    _startscope = code.getSource();
    _endscope = code.getSource();
    _statement.compile(context);
    Target condition = code.getTarget();
    if (!_statement.isBlocked()) {
      switch(_condition.conditionOf()) {
      case Expression.IS_FALSE:
        break;

      case Expression.IS_TRUE:
        code.go_to(start);
        break;

      case Expression.IS_DYNAMIC:
        _condition.compile(context, Expression.GET_BOOLEAN);
        code.if_ne(start);
        break;
      }
    }
    _endscope.bind();
    _startscope.bind(condition);
View Full Code Here

Examples of anvil.codec.Code

  }
 

  public void compile(ByteCompiler context, int operation)
  {
    Code code = context.getCode();
    ConstantPool pool = code.getPool();

    boolean inclass = (_thunk.getType() != Type.FUNCTION);

    int clazz = pool.addClass("anvil/script/Thunk");
    code.anew(clazz);
    code.dup();

    String name = (inclass ? "m_" : "f_")+_thunk.getName();
    String signature = inclass ?
      "(Lanvil/script/StackFrame;Lanvil/script/Function;Lanvil/core/Any;)V" :
      "(Lanvil/script/StackFrame;Lanvil/script/Function;)V";

    if (_context != null) {
      code.aload(_context.getFrameIndex());
    } else {
      code.aconst_null();
    }
    code.getstatic(pool.addFieldRef(_thunk.getParent().getTypeRef(pool), name, "Lanvil/script/Function;"));
    if (inclass) {
      code.self();
    }
    code.invokespecial(pool.addMethodRef(clazz, "<init>", signature));

    if (operation == GET_BOOLEAN) {
      context.any2boolean();
    }
  }
View Full Code Here

Examples of anvil.codec.Code

  }


  public void compile(ByteCompiler context, int operation)
  {
    Code code = context.getCode();
    _left.compile(context, GET_BOOLEAN);
    code.dup();
    Source source = code.if_eq();
    code.pop();
    _right.compile(context, GET_BOOLEAN);
    source.bind();
    if (operation != GET_BOOLEAN) {
      context.boolean2any();
    }   
View Full Code Here

Examples of anvil.codec.Code

  }
 

  public void compile(ByteCompiler context)
  {
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    FunctionStatement function = getFunctionStatement();
    if (function.isGenerator()) {
      code.aload(function.getFrameIndex());
      code.invokevirtual(pool.addMethodRef("anvil/script/Generator", "setClosedState", "()V"));
    }
    int rv = 0;   
    if (_expression != null) {
      if (_expression.needLineNumbers()) {
        context.location(_expression.getLocation());
      }
      rv = code.addLocal();
      _expression.compile(context, Expression.GET);
      code.astore(rv);
    }
    boolean blocked = false;
    Statement stmt = this;
    while(!blocked && stmt!=null) {
      blocked = stmt.callFinalizer();
      if (stmt.typeOf() == ST_FUNCTION) {
        break;
      }
      stmt = stmt.getParentStatement();
    }
    if (!blocked) {
      if (_expression != null) {
        code.aload(rv);
        code.areturn();
      } else {
        code.self();
        code.areturn();
      }
    }
  }  
View Full Code Here

Examples of anvil.codec.Code


  public void compile(ByteCompiler context, int operation)
  {
    _child.compile(context, GET);
    Code code = context.getCode();
    code.invokevirtual(code.getPool().addMethodRef(context.TYPE_ANY,
      "minus", "()Lanvil/core/Any;"));
    if (operation == GET_BOOLEAN) {
      context.any2boolean();
    }
  }
View Full Code Here

Examples of anvil.codec.Code

    }
  }
 
  public void compile(ByteCompiler context)
  {
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    boolean needloop =
      (_start != null) ||
      (_end != null) ||
      (_release != null) ||
      (_statement != null);

    if (needloop) {
      if (_init != null) {
        _init.compile(context, Node.GET);
      } else {
        code.getstatic(pool.addFieldRef(context.TYPE_ANY, "UNDEFINED",
          "Lanvil/core/Any;"));
      }
      code.dup();

      int contextframe = pool.addMethodRef(context.TYPE_CONTEXT, "frame",
        "()Lanvil/script/StackFrame;");
      code.aload_first();
      code.invokevirtual(contextframe);
      code.swap();
      code.invokevirtual(pool.addMethodRef("anvil/script/StackFrame",
        "push", "(Lanvil/core/Any;)V"));

      _framelocal = code.addLocal();
      code.astore(_framelocal);

      ExceptionHandler handler = code.startExceptionHandler(true);
      _handler = handler;
      Target tostart = code.getTarget();
      if (_start != null) {
        _start.compile(context, Node.GET_BOOLEAN);
        Source istrue = code.if_ne();
        handler.callFinally();
        handler.jumpOut();
        istrue.bind();
      }
      if (_statement != null) {
        _statement.compile(context);
      }
      if (_end != null) {
        _end.compile(context, Node.GET_BOOLEAN);
        code.if_ne(tostart);
      }
      handler.endTry();
      if (_statement == null || !_statement.isBlocked()) {
        handler.callFinally();
        handler.jumpOut();
      }
      handler.endProtectedRegion();

      handler.startCatch(0);
      int thrown = code.addLocal();
      code.astore(thrown);
      handler.callFinally();
      code.aload(thrown);
      code.athrow();
      handler.endCatches();
       _handler = null;

      // finally
      handler.startFinally();
      int returnto = code.addLocal();
      code.astore(returnto);
      code.aload_first();
      code.invokevirtual(contextframe);
      code.invokevirtual(pool.addMethodRef("anvil/script/StackFrame",
        "pop", "()Lanvil/core/Any;"));
      code.pop();
      if (_release != null) {
        _release.compile(context, Node.GET);
        code.pop();
      }
      code.ret(returnto);
      handler.endFinally();
      handler.end();
     
      code.endLocal(_framelocal);
     
    } else {
      if (_init != null) {
        _init.compile(context, Node.GET);
        code.pop();
      }
    }
  }
View Full Code Here

Examples of anvil.codec.Code

  }


  public void compile(ByteCompiler context, Node child)
  {
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    _child.compile(context, GET);
    child.compile(context, GET);
    code.dup_x1();
    code.invokevirtual(pool.addMethodRef(context.TYPE_ANY, "setRef",
      "(Lanvil/core/Any;)V"));
  }
View Full Code Here

Examples of anvil.codec.Code

  }


  public void compile(ByteCompiler context, int operation)
  {
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    switch(operation) {
    case GET:
    case CHECK:
      _child.compile(context, GET_REF);
      break;
     
    case GET_BOOLEAN:
      _child.compile(context, GET_BOOLEAN);
      break;
 
    case DELETE:
      code.iconst(false);
      break;
    }
  }
View Full Code Here

Examples of anvil.codec.Code

  }
 

  public ByteCompiler symbol(int index)
  {
    Code code = getCode();
    String name = Register.getNameOf(index);
    code.getstatic(getPool().addFieldRef(TYPE_MODULE, "r_"+name, "I"));
    _symbols.put(new Integer(index), name);
    return this;
  }
View Full Code Here

Examples of anvil.codec.Code

  }


  public ByteCompiler constant(Any value, boolean canchange)
  {
    Code code = getCode();
    int slot = addConstant(value);
    code.getstatic(code.getPool().addFieldRef(TYPE_MODULE, "_const", "[Lanvil/core/Any;"));
    code.iconst(slot);
    code.aaload();
    if (canchange && value.isMutable()) {
      code.invokevirtual(getPool().addMethodRef("anvil/core/Any", "copy", "()Lanvil/core/Any;"));
    }
    return this;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.