Package anvil.codec

Examples of anvil.codec.Method


  public ByteCompiler location(Location location)
  {
    if (_debug && location != null) {
      Code code = getCode();
      Method method = code.getMethod();
      if (method.getClassRoom().getStatic() != method) {
        code.aload_first();
        code.iconst(location.getLine());
        code.invokevirtual(getPool().addMethodRef("anvil/script/StackFrameStack",
          "setLine", "(I)V"));
      }
View Full Code Here


    _f_const = clazz.createField("_const", "[Lanvil/core/Any;", ACC_PUBLIC|ACC_STATIC|ACC_FINAL);
    _f_text = clazz.createField("_text", "[[B", ACC_PUBLIC|ACC_STATIC|ACC_FINAL);
    _f_switch = clazz.createField("_switch", "[Lanvil/java/util/Hashlist;", ACC_PUBLIC|ACC_STATIC|ACC_FINAL);

    Method _m_const = clazz.createMethod("_const", "()V", ACC_PUBLIC|ACC_STATIC);
    Method _m_text = clazz.createMethod("_text", "()V", ACC_PUBLIC|ACC_STATIC);
    Method _m_switch = clazz.createMethod("_switch", "()V", ACC_PUBLIC|ACC_STATIC);
    Method _m_symbols = clazz.createMethod("_symbols", "()V", ACC_PUBLIC|ACC_STATIC);
    //Method _m_imports = clazz.createMethod("_imports", "()V", ACC_PUBLIC|ACC_STATIC);
   
    code = clazz.getStatic().getCode();
    //code.println("MODULE-START:"+classsig);
    code.invokestatic(_m_const.getIndex());
    code.invokestatic(_m_text.getIndex());
    code.invokestatic(_m_switch.getIndex());
    code.invokestatic(_m_symbols.getIndex());
    ((anvil.script.statements.ModuleStatement)getModule()).compile(this);
    //code.println("MODULE-END:"+classsig);
    code.vreturn();
   
    /* constants */
    code = _m_const.getCode();
    if (_constants.size() > 0) {
      code.iconst(_constants.size());
      code.anewarray(TYPE_ANY);
      Enumeration e = _constants.keys();
      for(int i=0; e.hasMoreElements(); i++) {
        code.dup();
        code.iconst(i);
        ((Any)e.nextElement()).toCode(code);
        code.aastore();
      }
      code.putstatic(_f_const);
    }
    code.vreturn();
   
    /* texts */
    code = _m_text.getCode();
    int getBytes = pool.addMethodRef("anvil/util/Conversions", "getBytes", "(Ljava/lang/String;)[B");
    if (_texts.size() > 0) {
      int size = _texts.size();
      code.iconst(size);
      code.anewarray("[[B", 1);
      Enumeration e = _texts.keys();
      for(int i=0; e.hasMoreElements(); i++) {
        code.dup();
        code.iconst(i);
        code.astring((String)e.nextElement());
        code.invokestatic(getBytes);
        code.aastore();
      }
      code.putstatic(_f_text);
    }
    code.vreturn();
   
    /* switchtables */
    code = _m_switch.getCode();
    int n = _switches.size();
    if (_switches.size() > 0 ) {
      int hashlistclazz = pool.addClass("anvil/java/util/Hashlist");
      int hashlistctor = pool.addMethodRef(hashlistclazz, "<init>", "()V");
      int hashlistadd = pool.addMethodRef(hashlistclazz, "add",
        "(Ljava/lang/Object;Ljava/lang/Object;)Lanvil/java/util/Hashlist;");
      int intclazz = pool.addClass("java/lang/Integer");
      int intclazzctor = pool.addMethodRef(intclazz, "<init>", "(I)V");
      code.iconst(n);
      code.anewarray(hashlistclazz);
      for(int i=0; i<n; i++) {
        code.dup();
        code.iconst(i);
        code.anew(hashlistclazz);
        code.dup();
        code.invokespecial(hashlistctor);
        int c = 0;
        Enumeration keys = (Enumeration)_switches.elementAt(i);
        while(keys.hasMoreElements()) {
          Any key = (Any)keys.nextElement();
          if (key != SwitchStatement.DEFAULT_MARKER) {
            key.toCode(code);
            code.anew(intclazz);
            code.dup();
            code.iconst(c++);
            code.invokespecial(intclazzctor);
            code.invokevirtual(hashlistadd);
          }
        }
        code.aastore();
      }
      code.putstatic(_f_switch);
    }
    code.vreturn();

    /* methodindices */
    code = _m_symbols.getCode();
    if (_symbols.size() > 0) {
      int register = pool.addMethodRef(pool.addClass("anvil/core/Register"),
        "register", "(Ljava/lang/String;)I");
      BindingEnumeration e = _symbols.keysAndElements();
      while(e.hasMoreElements()) {
View Full Code Here

    Hashlist constants = new Hashlist();

    //generic
    {
      Method method = clazz.createMethod("execute",
       "(Lanvil/script/Context;Lanvil/core/Any;[Lanvil/core/Any;)Lanvil/core/Any;",
       ACC_PUBLIC|ACC_FINAL);
      Code code = method.getCode();
      int l_context = code.addLocal();
      int l_self = code.addLocal();
      int l_parameters = code.addLocal();
      compileDispatch(function, isstatic, clazz, code, pool, l_context, l_self, l_parameters, constants);
    }

    for(int params=0; params<=4; params++) {
   
      Method method = clazz.createMethod("execute", EXECUTE_SIGNATURES[params], ACC_PUBLIC|ACC_FINAL);
      Code code = method.getCode();
      int l_context = code.addLocal();
      int l_self = code.addLocal();
      int l_base = code.addLocal();
      code.addLocals(params);
      compileDispatch(function, isstatic, clazz, code, pool, l_context, l_self, l_base, params, constants);
View Full Code Here

    clazz.setClassname(classname, null);
    clazz.setSuperClassname("java/lang/Object");
    clazz.addInterface("anvil/script/GeneratorDispatcher");
    clazz.setAccessFlags(ACC_PUBLIC|ACC_FINAL);

    Method method = clazz.createMethod("<init>", "()V", ACC_PUBLIC);
    Code code = method.getCode();
    code.self();
    code.invokespecial(pool.addMethodRef(clazz.getSuperClassIndex(), "<init>", "()V"));
    code.vreturn();

    method = clazz.createMethod("execute",
      "(Lanvil/script/Context;Lanvil/core/AnyClass;Lanvil/script/Generator;)Lanvil/core/Any;",
      ACC_PUBLIC|ACC_FINAL);
    code = method.getCode();
    code.addLocals(4);
   
    boolean ismethod = (function.getType() == Type.METHOD);
    Scope parent = function.getParent();
    int parent_ref = parent.getTypeRef(pool);
View Full Code Here

  public void compile(ByteCompiler context)
  {
    ClassRoom clazz = context.getClassRoom();
    Field typefield = clazz.createField("f_"+_name, "Lanvil/script/Function;", ACC_PUBLIC|ACC_STATIC);
    clazz.createField("F_"+_name, "Lanvil/core/Any;", ACC_PUBLIC|ACC_STATIC);
    Method method = clazz.createMethod("f_"+_name, getSignature(), ACC_PUBLIC|ACC_FINAL|ACC_STATIC|(_synchronized?ACC_SYNCHRONIZED:0));
    compileBody(context, method, typefield);
  }
View Full Code Here

  public void compile(ByteCompiler context)
  {
    ClassRoom clazz = context.getClassRoom();
    Field typefield = clazz.createField("m_"+_name, "Lanvil/script/Function;", ACC_PUBLIC|ACC_STATIC);
    clazz.createField("M_"+_name, "Lanvil/core/Any;", ACC_PUBLIC|ACC_STATIC);
    Method method = clazz.createMethod("m_"+_name, getSignature(), ACC_PUBLIC|(_synchronized?ACC_SYNCHRONIZED:0));
    compileBody(context, method, typefield);
  }
View Full Code Here

    }

    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) {
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

  protected void compileExecuteMethod(ByteCompiler context, ClassRoom clazz, CompilableFunction function)
  {
    /* 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();
    }

    for(int i=0; i<5; i++) {
      Method method = clazz.createMethod("execute", EXECUTE_SIGNATURES[i], Code.ACC_PUBLIC);
      Node[] params = new Node[i];
      for(int j=0; j<i; j++) {
        params[j] = new ParameterNode(2 + j);
      }
      compileCallback(context, function, method, false, 1+i, params, 0, 2);
View Full Code Here

 
  protected void compileInvokeMethod(ByteCompiler context, ClassRoom clazz, CompilableFunction function)
  {
    /* invoke(Context, int, Any[]) */
    {
      Method method = clazz.createMethod("invoke",
        "(Lanvil/script/Context;I[Lanvil/core/Any;)Lanvil/core/Any;", Code.ACC_PUBLIC);
      Code code = method.getCode();
      ConstantPool pool = code.getPool();
      context.pushCode(code);
      int l_context = code.addLocal();
      int l_index = code.addLocal();
      int l_parameters = code.addLocal();
      int l_length = code.addLocal();
      int l_newparameters = code.addLocal();
      code.aload(l_parameters);
      code.arraylength();
      code.istore(l_length);
      code.iload(l_length);
      code.iconst(1);
      code.iadd();
      code.anewarray(context.TYPE_ANY);
      code.astore(l_newparameters);
      code.aload(l_parameters);
      code.iconst(0);
      code.aload(l_newparameters);
      code.iconst(1);
      code.iload(l_length);
      code.invokestatic(pool.addMethodRef("java/lang/System", "arraycopy", "(Ljava/lang/Object;ILjava/lang/Object;II)V"));
      code.aload(l_newparameters);
      code.iconst(0);
      code.iload(l_index);
      code.invokestatic(pool.addMethodRef("anvil/core/Register", "getAnyNameOf", "(I)Lanvil/core/Any;"));
      code.aastore();
      code.getstatic(pool.addFieldRef(clazz.getIndex(), "m_"+function.getName(), "Lanvil/script/Function;"));
      code.aload(l_context);
      code.self();
      code.aload(l_newparameters);
      code.invokeinterface(pool.addInterfaceMethodRef("anvil/script/Function",
        "execute", "(Lanvil/script/Context;Lanvil/core/Any;[Lanvil/core/Any;)Lanvil/core/Any;"));
      code.areturn();
      context.popCode();
    }
   
    for(int i=0; i<4; i++) {
      Method method = clazz.createMethod("invoke", INVOKE_SIGNATURES[i], Code.ACC_PUBLIC);
      Node[] params = new Node[1 + i];
      params[0] = P2_TO_SYMBOL;
      for(int j=0; j<i; j++) {
        params[j+1] = new ParameterNode(3 + j);
      }
      compileCallback(context, function, method, false, 3+i, params, 0, 2);
    }

    /* invoke(Context, int, Any, Any, Any, Any) */
    {
      Method method = clazz.createMethod("invoke", INVOKE_SIGNATURES[4], Code.ACC_PUBLIC);
      Code code = method.getCode();
      ConstantPool pool = code.getPool();
      context.pushCode(code);
      int l_context = code.addLocal();
      int l_index = code.addLocal();
      int l_base = code.addLocal();
View Full Code Here

TOP

Related Classes of anvil.codec.Method

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.