Package anvil.codec

Examples of anvil.codec.ClassRoom


  }


  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[] nodes1,
    MethodStatement callback,
    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

  }
 
 
  protected void compileEqualsMethod(ByteCompiler context, CompilableFunction function)
  {
    ClassRoom clazz = context.getClassRoom();
    Method method = clazz.createMethod("equals", "(Ljava/lang/Object;)Z", Code.ACC_PUBLIC);
    Code code = method.getCode();
    ConstantPool pool = code.getPool();
    context.pushCode(code);
    code.addLocal();
    code.aload(1);
View Full Code Here

  }


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



  public void compile(ByteCompiler context)
  {
    ClassRoom clazz = context.getClassRoom().createClass(getDescriptor(), "n_"+_name);
    clazz.setAccessFlags(context.ACC_PUBLIC);
    ConstantPool pool = clazz.getPool();
    context.pushClass(clazz);
    Field typefield1 = clazz.createField("_class", "Lanvil/script/compiler/CompiledNamespace;", Code.ACC_PUBLIC|Code.ACC_STATIC);
    Field typefield2 = clazz.createField("_type", "Lanvil/core/Any;", Code.ACC_PUBLIC|Code.ACC_STATIC);
    clazz.setSuperClassname(context.TYPE_OBJECT);
    clazz.setAccessFlags(Code.ACC_SUPER|Code.ACC_PUBLIC);

    compileMembers(context, _types.size(), _types.elements());

    Code code = clazz.getStatic().getCode();
    context.pushCode(code);
    //code.println("INTERFACE-START:"+getDescriptor());
    code.getstatic(pool.addFieldRef(_parent.getDescriptor(), "_members", "[Ljava/lang/Object;"));
    code.pop();
    //code.println("INTERFACE-END:"+getDescriptor());
View Full Code Here

  }


  public void compile(ByteCompiler context)
  {
    ClassRoom clazz = context.getClassRoom();
    clazz.createField("m_"+_name, "Lanvil/script/Function;", ACC_PUBLIC|ACC_STATIC);
    clazz.createField("M_"+_name, "Lanvil/core/Any;", ACC_PUBLIC|ACC_STATIC);
    clazz.createMethod("m_"+_name, getSignature(), ACC_PUBLIC|ACC_ABSTRACT);
  }
View Full Code Here

  }


  public void compile(ByteCompiler context)
  {
    ClassRoom clazz = context.getClassRoom();
    clazz.createField("m_"+_name, "Lanvil/script/Function;", ACC_PUBLIC|ACC_STATIC);
    clazz.createField("M_"+_name, "Lanvil/core/Any;", ACC_PUBLIC|ACC_STATIC);
    clazz.createMethod("m_"+_name, getSignature(), ACC_PUBLIC|ACC_ABSTRACT);
  }
View Full Code Here

  }


  public void compile(ByteCompiler context)
  {
    ClassRoom room = context.getClassRoom();
    room.createField("c_"+_name, "Lanvil/core/Any;", context.ACC_PUBLIC|context.ACC_STATIC);
 
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();
    context.pushCode(code);
    code.iconst(_envelope.getVersion());
    code.ireturn();

    clazz.createField("_module", "Lanvil/script/compiler/CompiledModule;", ACC_PUBLIC|ACC_STATIC);
    clazz.createField("_type", "Lanvil/core/Any;", ACC_PUBLIC|ACC_STATIC);

    context.popCode();
  }
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);
    }
View Full Code Here

TOP

Related Classes of anvil.codec.ClassRoom

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.