Package anvil.codec

Examples of anvil.codec.ConstantPool


  public void compile(ByteCompiler context)
  {
    FunctionStatement function = getFunctionStatement();
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    if (_expression.needLineNumbers()) {
      context.location(_expression.getLocation());
    }
    code.aload(function.getFrameIndex());
    code.iconst(_state);
    code.invokevirtual(pool.addMethodRef("anvil/script/Generator", "setState", "(I)V"));
    _expression.compile(context, Expression.GET);
    code.areturn();
    function.bindYieldState(_state);
    /*Code code = context.getCode();
    int rv = 0;   
View Full Code Here


 

  public void compile(ByteCompiler context, int operation)
  {
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    _left.compile(context, GET);
    _right.compile(context, GET);
    code.invokevirtual(pool.addMethodRef(context.TYPE_OBJECT, "toString", "()Ljava/lang/String;"));
    code.invokevirtual(pool.addMethodRef(context.TYPE_ANY, "has", "(Ljava/lang/String;)Z"));
    if (operation != GET_BOOLEAN) {
      context.boolean2any();
    }
  }
View Full Code Here

 

  public void compile(ByteCompiler context, int operation)
  {
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
   
    code.aload_first();
    _left.compile(context, GET);
    _right.compile(context, GET);
    code.invokevirtual(pool.addMethodRef(context.TYPE_CONTEXT, "foreach",
      "(Lanvil/core/Any;Lanvil/core/Any;)Lanvil/core/Any;"));

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

  {
    left.compile(context, new Node() {
      public void compile(ByteCompiler context, int operation)
      {
        Code code = context.getCode();
        ConstantPool pool = code.getPool();
        left.compile(context, GET);
        code.dup();
        code.invokevirtual(pool.addMethodRef(context.TYPE_ANY, "isUndefined", "()Z"));
        Source isfalse = code.if_eq();
        code.pop();
        right.compile(context, GET);
        isfalse.bind();
      }
View Full Code Here

  public void compile(ByteCompiler context)
  {
    boolean enabled = getModuleStatement().getAddress().getZone().getAssert();
    if (enabled) {
      Code code = context.getCode();
      ConstantPool pool = code.getPool();
      code.getstatic(pool.addFieldRef(context.TYPE_MODULE, "_module", "Lanvil/script/compiler/CompiledModule;"));
      code.invokevirtual(pool.addMethodRef(
        "anvil/script/compiler/CompiledModule", "getAssert", "()Z"));
      Source source = code.if_eq();
      _condition.compile(context, Expression.GET_BOOLEAN);
      code.if_ne(source);
      context.location(getLocation());
      code.aload_first();
      code.astring(_image);
      code.invokevirtual(pool.addMethodRef("anvil/script/Context", "AssertFailed",
        "(Ljava/lang/String;)Lanvil/script/ScriptException;"));
      code.athrow();
      source.bind();
    }
  }  
View Full Code Here

 
  public void compile(ByteCompiler context, int operation)
  {
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    int clazz = pool.addClass("anvil/core/AnyTuple");
    int n = childs();
    if (n > 0) {
      code.anew(clazz);
      code.dup();
      code.iconst(n);
      code.anewarray(context.TYPE_ANY);
      for(int i=0; i<n; i++) {
        code.dup();
        code.iconst(i);
        getChild(i).compile(context, GET);
        code.aastore();
      }
      code.invokespecial(pool.addMethodRef(clazz, "<init>",
        "([Lanvil/core/Any;)V"));
    } else {
      code.getstatic(pool.addFieldRef(context.TYPE_ANY, "EMPTY_TUPLE",
        "Lanvil/core/AnyTuple;"));
    }
    if (operation == context.GET_BOOLEAN) {
      context.any2boolean();
    }   
View Full Code Here

  };

  public void compile(ByteCompiler context, int operation)
  {
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    context.accessInstance(_context, _target);
    code.aload_first();
    context.symbol(_method.getName());
    int n = childs();
    if (!hasSplices() && n <= 4) {
      for(int i=0; i<n; i++) {
        getChild(i).compile(context, GET);
      }
      code.invokevirtual(pool.addMethodRef("anvil/core/AnyClass", "_invoke", SIGNATURES[n]));
    } else {
      context.compileArgumentList(getChilds(0));
      code.invokevirtual(pool.addMethodRef("anvil/core/AnyClass", "_invoke",
        "(Lanvil/script/Context;I[Lanvil/core/Any;)Lanvil/core/Any;"));
    }
    if (operation == GET_BOOLEAN) {
      context.any2boolean();
    }
View Full Code Here


  public void compile(ByteCompiler context, int operation)
  {
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    final Node child = _child;
    switch(child.typeOf()) {
    case Node.EXPR_VARIABLE:
      {
        final int tmp = code.addLocal();
        child.compile(context, GET);
        code.astore(tmp);
        child.compile(context, new Node() {
          public void compile(ByteCompiler context, int operation)
          {
            Code code = context.getCode();
            code.aload(tmp);
            code.invokevirtual(code.getPool().addMethodRef(context.TYPE_ANY, "increase", "()Lanvil/core/Any;"));
          }     
        });
        code.pop();
        code.aload(tmp);
        code.endLocal(tmp);
      }
      break;
     
    case Node.EXPR_ATTRIBUTE:
      {
        AttributeNode attr = (AttributeNode)child;
        attr.getChild().compile(context, GET);
        code.astring(attr.getAttribute());
        code.aload_first();
        code.invokestatic(pool.addMethodRef(context.TYPE_CONTEXT, "postinc",
          "(Lanvil/core/Any;Ljava/lang/String;Lanvil/script/Context;)Lanvil/core/Any;"));
      }
      break;
   
    case Node.EXPR_REFERENCE:
      {
        ReferenceNode ref = (ReferenceNode)child;
        ref.getLeft().compile(context, GET);
        ref.getRight().compile(context, GET);
        code.aload_first();
        code.invokestatic(pool.addMethodRef(context.TYPE_CONTEXT, "postinc",
          "(Lanvil/core/Any;Lanvil/core/Any;Lanvil/script/Context;)Lanvil/core/Any;"));
      }
      break;

    default:
View Full Code Here


  public void compileConstructor(ByteCompiler context)
  {
    ClassRoom clazz = context.getClassRoom();
    ConstantPool pool = clazz.getPool();
    Method constructor = clazz.createConstructor("()V", ACC_PUBLIC);
    _constructor = constructor;
    Code code = constructor.getCode();

    StringBuffer clsid = new StringBuffer();
    clsid.append("$Id: ");
    clsid.append(_address.getPathinfo());
    clsid.append(" 1.0 ");
    LocalizationPreferences prefs = _address.getZone().getLocalizationPreferences();
    Calendar cal = Calendar.getInstance(prefs.getTimezoneInstance(), prefs.getLocaleInstance());
    anvil.util.Conversions.toString(clsid, cal);
    Field clsidfield = clazz.createField("_id", "Ljava/lang/String;", ACC_PUBLIC|ACC_STATIC|ACC_FINAL);
    clsidfield.setConstantValue(pool.addString(clsid.toString()));

    context.pushCode(code);
    code.self();
    code.invokespecial(pool.addMethodRef("anvil/script/compiler/CompiledModule",
      "<init>", "()V"));
    context.popCode();
   
    Method versionmethod = clazz.createMethod("getVersion", "()I", ACC_PUBLIC);
    code = versionmethod.getCode();
View Full Code Here

  public void compileStaticInit(ByteCompiler context)
  {
    ClassRoom clazz = context.getClassRoom();
    Code code = clazz.getStatic().getCode();
    ConstantPool pool = code.getPool();
    context.pushCode(code);
    if (_staticinit != null) {
      _staticinit.compile(context);
    }
    Enumeration e = _types.elements();
    while(e.hasMoreElements()) {
      Type type = (Type)e.nextElement();
      int typeid = type.getType();
      if (typeid == CLASS || typeid == INTERFACE) {
        code.getstatic(pool.addFieldRef(type.getTypeRef(pool),
          "_members", "[Ljava/lang/Object;"));
        code.pop();
      }
    }
    context.popCode();
View Full Code Here

TOP

Related Classes of anvil.codec.ConstantPool

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.