Package anvil.codec

Examples of anvil.codec.ConstantPool



  public void compile(ByteCompiler context, int operation)
  {
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    int clazz = pool.addClass("java/lang/StringBuffer");
    int appendmethod = pool.addMethodRef(clazz, "append",
      "(Ljava/lang/Object;)Ljava/lang/StringBuffer;");
    code.anew(clazz);
    code.dup();
    code.invokespecial(pool.addMethodRef(clazz, "<init>", "()V"));
    int n = childs();
    for(int i=0; i<n; i++) {
      getChild(i).compile(context, GET);
      code.invokevirtual(appendmethod);
    }
View Full Code Here


 

  public void compile(ByteCompiler context)
  {
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    int clazz = pool.addClass("anvil/script/ExitException");
    if (_expression != null) {
      if (_expression.needLineNumbers()) {
        context.location(_expression.getLocation());
      }
      code.anew(clazz);
      code.dup();
      _expression.compile(context, Expression.GET);
      code.invokespecial(pool.addMethodRef(clazz, "<init>", "(Lanvil/core/Any;)V"));
    } else {
      code.anew(clazz);
      code.dup();
      code.invokespecial(pool.addMethodRef(clazz, "<init>", "()V"));
    }
    code.athrow();
 
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/runtime/AnyType");
    code.anew(clazz);
    code.dup();
    _child.compile(context, CHECK);
    code.invokevirtual(pool.addMethodRef(context.TYPE_ANY, "type",
      "()Lanvil/script/Type;"));
    code.invokespecial(pool.addMethodRef(clazz, "<init>",
      "(Lanvil/script/Type;)V"));
    if (operation == GET_BOOLEAN) {
      context.any2boolean();
    }     
  }
View Full Code Here

  public void compile(ByteCompiler context, int operation)
  {
    _child.compile(context, GET);
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    switch(_type) {
    case IS_DEFINED:
      code.invokevirtual(pool.addMethodRef(context.TYPE_ANY,
        "isDefined", "()Z"));
      break;

    case IS_UNDEFINED:
      code.invokevirtual(pool.addMethodRef(context.TYPE_ANY,
        "isUndefined", "()Z"));
      break;

    case Any.IS_NULL:
      code.invokevirtual(pool.addMethodRef(context.TYPE_ANY,
        "isNull", "()Z"));
      break;

    case Any.IS_BOOLEAN:
      code.invokevirtual(pool.addMethodRef(context.TYPE_ANY,
        "isBoolean", "()Z"));
      break;

    case Any.IS_INT:
      code.invokevirtual(pool.addMethodRef(context.TYPE_ANY,
        "isInt", "()Z"));
      break;

    case Any.IS_DOUBLE:
      code.invokevirtual(pool.addMethodRef(context.TYPE_ANY,
        "isDouble", "()Z"));
      break;

    case Any.IS_STRING:
      code.invokevirtual(pool.addMethodRef(context.TYPE_ANY,
        "isString", "()Z"));
      break;

    case Any.IS_BINARY:
      code.invokevirtual(pool.addMethodRef(context.TYPE_ANY,
        "isBinary", "()Z"));
      break;

    case Any.IS_PATTERN:
      code.invokevirtual(pool.addMethodRef(context.TYPE_ANY,
        "isPattern", "()Z"));
      break;

    case Any.IS_RANGE:
      code.invokevirtual(pool.addMethodRef(context.TYPE_ANY,
        "isRange", "()Z"));
      break;

    case Any.IS_MAP:
      code.invokevirtual(pool.addMethodRef(context.TYPE_ANY,
        "isMap", "()Z"));
      break;
     
    case Any.IS_TUPLE:
      code.invokevirtual(pool.addMethodRef(context.TYPE_ANY,
        "isTuple", "()Z"));
      break;
    case Any.IS_LIST:
      code.invokevirtual(pool.addMethodRef(context.TYPE_ANY,
        "isList", "()Z"));
      break;
    case Any.IS_ARRAY:
      code.invokevirtual(pool.addMethodRef(context.TYPE_ANY,
        "isArray", "()Z"));
      break;
     case Any.IS_CLASS:
      code.invokevirtual(pool.addMethodRef(context.TYPE_ANY,
        "isClass", "()Z"));
      break;

    case Any.IS_REF:
      code.invokevirtual(pool.addMethodRef(context.TYPE_ANY,
        "isRef", "()Z"));
      break;
    }
    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();
    _left.compile(context, GET);
    _right.compile(context, GET_TYPE);
    code.invokevirtual(pool.addMethodRef(context.TYPE_ANY,
      "isInstanceOf", "(Lanvil/script/Type;)Z"));
    if (operation != GET_BOOLEAN) {
      context.boolean2any();
    }
  }
View Full Code Here

  {
    _types.put(_constructor.getName(), _constructor);
   
    ClassRoom clazz = context.getClassRoom().createClass(_descriptor, "z_"+_name);
    clazz.setAccessFlags(Code.ACC_PUBLIC);
    ConstantPool pool = clazz.getPool();
    context.pushClass(clazz);
    Field typefield1 = clazz.createField("_class", "Lanvil/script/compiler/CompiledClassType;", Code.ACC_PUBLIC|Code.ACC_STATIC);
    Field typefield2 = clazz.createField("_type", "Lanvil/core/Any;", Code.ACC_PUBLIC|Code.ACC_STATIC);
    ClassType base = getBaseClass();
    if (base != Any.__class__) {
      clazz.setSuperClassname(base.getDescriptor());
    } else {
      clazz.setSuperClassname("anvil/core/AnyClass");
    }
    clazz.setAccessFlags(Code.ACC_SUPER|Code.ACC_PUBLIC);

    Field bases = clazz.createField("_bases", "[Ljava/lang/String;", Code.ACC_PUBLIC|Code.ACC_STATIC);
    Code code = clazz.getStatic().getCode();
    context.pushCode(code);
   
    code.getstatic(pool.addFieldRef(_parent.getDescriptor(), "_members", "[Ljava/lang/Object;"));
    code.pop();

    compileConstructors(context, typefield1);

    compileMembers(context, _types.size(), _types.elements());
   
    int n = _interfaces.length;
    code.iconst(n);
    code.anewarray("java/lang/String");
    for(int i=0; i<n; i++) {
      InterfaceType interfacetype = _interfaces[i].getInterfaceType();
      code.dup();
      code.iconst(i);
      code.astring(interfacetype.getDescriptor().replace('/', '.'));
      code.aastore();
    }
    code.putstatic(bases);

    Enumeration e = _types.elements();
    while(e.hasMoreElements()) {
      Type type = (Type)e.nextElement();
      if (type.getType() == CLASS) {
        code.getstatic(pool.addFieldRef(type.getTypeRef(pool),
          "_members", "[Ljava/lang/Object;"));
        code.pop();
      }
    }

    code.vreturn();

    context.popCode();

    super.compile(context);

    compileMemberCallback(context);


    MethodStatement method = getMethod("clone");
    if (method != null) {
      compileCallback(context, method, clazz.createMethod(
        "clone", "()Ljava/lang/Object;", Code.ACC_PUBLIC), true, 0, EMPTY, 0, 2);
    } else {
      compileCopyMethod(context, method, false, typefield1);
    }

    method = getMethod("copy");
    if (method != null) {
      compileCallback(context, method, clazz.createMethod(
        "copy", "()Lanvil/core/Any;", Code.ACC_PUBLIC), true, 0, EMPTY, 0, 2);
    } else {
      compileCopyMethod(context, method, true, typefield1);
    }

    method = getMethod("toBoolean");
    if (method != null) {
      compileCallback(context, method,
        clazz.createMethod("toBoolean", "()Z", Code.ACC_PUBLIC), true, 0, EMPTY,
          pool.addMethodRef(context.TYPE_ANY, "toBoolean", "()Z"), 1);
    }
   
    method = getMethod("toString");
    if (method != null) {
      compileCallback(context, method,
        clazz.createMethod("toString", "()Ljava/lang/String;", Code.ACC_PUBLIC), true, 0, EMPTY,
          pool.addMethodRef(context.TYPE_ANY, "toString", "()Ljava/lang/String;"), 2);
    }

    method = getMethod("sizeOf");
    if (method != null) {
      compileCallback(context, method,
        clazz.createMethod("sizeOf", "()I", Code.ACC_PUBLIC), true, 0, EMPTY,
          pool.addMethodRef(context.TYPE_ANY, "toInt", "()I"), 1);
    }

    method = getMethod("hashCode");
    if (method != null) {
      compileCallback(context, method,
        clazz.createMethod("hashCode", "()I", Code.ACC_PUBLIC), true, 0, EMPTY,
          pool.addMethodRef(context.TYPE_ANY, "toInt", "()I"), 1);
    }

    method = getMethod("equals");
    if (method != null) {
      compileEqualsMethod(context, method);
    }

    method = getMethod("compareTo");
    if (method != null) {
      compileCallback(context, method,
        clazz.createMethod("compare", "(Lanvil/core/Any;)I", Code.ACC_PUBLIC), true, 1, CAST_P1_NODE,
          pool.addMethodRef(context.TYPE_ANY, "toInt", "()I"), 1);
    }


    method = getMethod("_get");
    if (method != null) {
      compileCallback(context, method,
        clazz.createMethod("getReference", "(Lanvil/script/Context;Lanvil/core/Any;)Lanvil/core/Any;", Code.ACC_PUBLIC),
          false, 2, P2_NODE, 0, 2);
    }

    method = getMethod("_check");
    if (method != null) {
      compileCallback(context, method,
        clazz.createMethod("checkReference", "(Lanvil/script/Context;Lanvil/core/Any;)Lanvil/core/Any;", Code.ACC_PUBLIC),
          false, 2, P2_NODE, 0, 2);
    }

    method = getMethod("_delete");
    if (method != null) {
      compileCallback(context, method,
        clazz.createMethod("deleteReference", "(Lanvil/script/Context;Lanvil/core/Any;)Z", Code.ACC_PUBLIC),
          false, 2, P2_NODE, pool.addMethodRef(context.TYPE_ANY, "toBoolean", "()Z"), 1);
    }

    method = getMethod("_append");
    if (method != null) {
      compileCallback(context, method,
        clazz.createMethod("setReference", "(Lanvil/script/Context;Lanvil/core/Any;)Lanvil/core/Any;", Code.ACC_PUBLIC),
          false, 2, P2_NODE, 0, 2);
    }

    method = getMethod("_set");
    if (method != null) {
      compileCallback(context, method, clazz.createMethod("setReference",
        "(Lanvil/script/Context;Lanvil/core/Any;Lanvil/core/Any;)Lanvil/core/Any;", Code.ACC_PUBLIC),
        false, 3, P_Q_NODE, 0, 2);
    }

    method = getMethod("_fetch");
    MethodStatement[] methods = getMethodsStartingWith("_fetch_");
    if (method != null || methods != null) {
      Method target = clazz.createMethod("getAttribute", "(Lanvil/script/Context;Ljava/lang/String;)Lanvil/core/Any;", Code.ACC_PUBLIC);
      compileAttributeCallback(context, target, 7, false, methods, EMPTY, method, P_S2A_NODE, false);
    }

    method = getMethod("_defined");
    methods = getMethodsStartingWith("_defined_");
    if (method != null || methods != null) {
      Method target = clazz.createMethod("checkAttribute", "(Lanvil/script/Context;Ljava/lang/String;)Lanvil/core/Any;", Code.ACC_PUBLIC);
      compileAttributeCallback(context, target, 9, false, methods, EMPTY, method, P_S2A_NODE, false);
    }

    method = getMethod("_dispose");
    methods = getMethodsStartingWith("_dispose_");
    if (method != null || methods != null) {
      Method target = clazz.createMethod("deleteAttribute", "(Lanvil/script/Context;Ljava/lang/String;)Z", Code.ACC_PUBLIC);
      compileAttributeCallback(context, target, 9, false, methods, EMPTY, method, P_S2A_NODE, true);
    }

    method = getMethod("_store");
    methods = getMethodsStartingWith("_store_");
    if (method != null || methods != null) {
      Method target = clazz.createMethod("setAttribute", "(Lanvil/script/Context;Ljava/lang/String;Lanvil/core/Any;)Lanvil/core/Any;", Code.ACC_PUBLIC);
      compileAttributeCallback(context, target, 7, true, methods, P3_NODE, method, P_S2A_Q_NODE, false);
    }

    method = getMethod("_enumeration");
    if (method != null) {
      compileCallback(context, method, clazz.createMethod("enumeration",
        "()Lanvil/java/util/BindingEnumeration;", Code.ACC_PUBLIC),
        true, 0, EMPTY, -pool.addMethodRef(context.TYPE_COMPILED_SCRIPT,
        "enumerate", "(Lanvil/core/Any;)Lanvil/java/util/BindingEnumeration;"), 2);
    }

    method = getMethod("_in");
    if (method != null) {
      compileCallback(context, method,
        clazz.createMethod("contains", "(Lanvil/core/Any;)Z", Code.ACC_PUBLIC),
          true, 1, P1_NODE, pool.addMethodRef(context.TYPE_ANY, "toBoolean", "()Z"), 1);
    }

    method = getMethod("_has");
    if (method != null) {
      compileCallback(context, method,
        clazz.createMethod("has", "(Ljava/lang/String;)Z", Code.ACC_PUBLIC),
          true, 1, P1_S2A_NODE, pool.addMethodRef(context.TYPE_ANY, "toBoolean", "()Z"), 1);
    }

    method = getMethod("_invoke");
    if (method != null) {
      compileInvokeMethod(context, clazz, method);
View Full Code Here


  protected void compileAux(ByteCompiler context)
  {
    ClassRoom clazz = context.getClassRoom();
    ConstantPool pool = clazz.getPool();

    Method method = clazz.createMethod("getAllMembers", "()Lanvil/java/util/BindingEnumeration;", Code.ACC_PUBLIC);
    Code code = method.getCode();
    int cge = pool.addClass("anvil/script/ClassGraphEnumeration");
    code.anew(cge);
    code.dup();
    code.getstatic(pool.addFieldRef(clazz.getIndex(), "_class", "Lanvil/script/compiler/CompiledClassType;"));
    code.self();
    code.invokespecial(pool.addMethodRef(cge, "<init>", "(Lanvil/script/ClassType;Lanvil/core/AnyClass;)V"));
    code.areturn();

    method = clazz.createMethod("classOf", "()Lanvil/script/ClassType;", Code.ACC_PUBLIC);
    code = method.getCode();
    code.getstatic(pool.addFieldRef(clazz.getIndex(), "_class", "Lanvil/script/compiler/CompiledClassType;"));
    code.areturn();
  }
View Full Code Here

    Node[] nodes2,
    boolean castToBoolean)
  {
    ClassRoom clazz = context.getClassRoom();
    Code code = method.getCode();
    ConstantPool pool = code.getPool();
    int sig_equals = pool.addMethodRef("java/lang/String", "equals", "(Ljava/lang/Object;)Z");
    int sig_toBoolean = pool.addMethodRef("anvil/core/Any", "toBoolean", "()Z");
    context.pushCode(code);
   
    int l_context = code.addLocal();
    int l_attr = code.addLocal();
    int l_value = 0;
    if (hasValue) {
      l_value = code.addLocal();
    }
   
    if (methods != null) {
      int n = methods.length;
      if (n>3) {
        code.aload(l_attr);
        code.invokevirtual(pool.addMethodRef("java/lang/String", "hashCode", "()I"));
        Source notfound = code.getSource();
        Switch select = code.select();
        for(int i=0; i<n; i++) {
          select.addCase(methods[i].getName().substring(prefixLength).hashCode());
        }
        select.end();
        Iterator iter = select.getCases();
        while(iter.hasNext()) {
          Switch.Case kase = (Switch.Case)iter.next();
          kase.bind();
          for(int i=0; i<n; i++) {
            MethodStatement target = methods[i];
            String name = target.getName().substring(prefixLength);
            if (name.hashCode() == kase.getKey()) {
              code.aload(l_attr);
              code.astring(name);
              code.invokevirtual(sig_equals);
              Source isfalse = code.if_eq();
              code.self();
              context.compileArgumentList(target, nodes1, l_context);
              code.invokevirtual(target.getTypeRef(pool));
              if (castToBoolean) {
                code.invokevirtual(sig_toBoolean);
                code.ireturn();
              } else {
                code.areturn();
              }
              isfalse.bind();
            }
          }
          code.go_to(notfound);
        }
        select.bindDefault();
        notfound.bind();

      } else {
        for(int i=0; i<n; i++) {
          MethodStatement target = methods[i];
          code.aload(l_attr);
          code.astring(target.getName().substring(prefixLength));
          code.invokevirtual(sig_equals);
          Source isfalse = code.if_eq();
          code.self();
          context.compileArgumentList(target, nodes1, l_context);
          code.invokevirtual(target.getTypeRef(pool));
          if (castToBoolean) {
            code.invokevirtual(sig_toBoolean);
            code.ireturn();
          } else {
            code.areturn();
          }
          isfalse.bind();
        }
      }
    }
   
    if (callback != null) {
      code.self();
      context.compileArgumentList(callback, nodes2, l_context);
      code.invokevirtual(callback.getTypeRef(pool));
      if (castToBoolean) {
        code.invokevirtual(sig_toBoolean);
        code.ireturn();
      } else {
        code.areturn();
      }
   
    } else {
      code.self();
      code.aload(l_context);
      code.aload(l_attr);
      if (hasValue) {
        code.aload(l_value);
      }
      code.invokespecial(pool.addMethodRef(clazz.getSuperClassIndex(),
        method.getName(), method.getDescriptor()));
      if (castToBoolean) {
        code.ireturn();
      } else {
        code.areturn();
View Full Code Here

 
  public void compile(ByteCompiler context, int operation)
  {
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    int anyfunctionclazz = pool.addClass("anvil/core/runtime/AnyFunction");
    code.anew(anyfunctionclazz);
    code.dup();
    _child.compile(context, operation);
    code.getstatic(pool.addFieldRef(_method.getParent().getTypeRef(pool),
      "m_"+_method.getName()"Lanvil/script/Function;"));
    code.invokespecial(pool.addMethodRef(anyfunctionclazz, "<init>", "(Lanvil/core/Any;Lanvil/script/Function;)V"));
    if (operation == GET_BOOLEAN) {
      context.any2boolean();
    }
  }
View Full Code Here

    /* execute(Context, Any[]) */
    {
      Method method = clazz.createMethod("execute",
        "(Lanvil/script/Context;[Lanvil/core/Any;)Lanvil/core/Any;", Code.ACC_PUBLIC);
      Code code = method.getCode();
      ConstantPool pool = code.getPool();
      int l_context = code.addLocal();
      int l_parameters = code.addLocal();
      context.pushCode(code);
      code.getstatic(pool.addFieldRef(clazz.getIndex(), "m_"+function.getName(), "Lanvil/script/Function;"));
      code.aload(l_context);
      code.self();
      code.aload(l_parameters);
      code.invokeinterface(pool.addInterfaceMethodRef("anvil/script/Function",
        "execute", "(Lanvil/script/Context;Lanvil/core/Any;[Lanvil/core/Any;)Lanvil/core/Any;"));
      code.areturn();
      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.