Package anvil.codec

Examples of anvil.codec.ConstantPool


 

  public void compile(ByteCompiler context, int operation)
  {
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    if (_local.isEscaped()) {
      switch(operation) {
      case GET:
      case CHECK:
        code.aload(_local.getFrameIndex());
        code.iconst(_local.getSlot());
        code.invokevirtual(code.getPool().addMethodRef("anvil/script/StackFrame", "getLocal", "(I)Lanvil/core/Any;"));
        break;

      case GET_REF:
        int refclass = pool.addClass("anvil/core/AnyLocalRef");
        code.anew(refclass);
        code.dup();
        code.aload(_local.getFrameIndex());
        code.iconst(_local.getSlot());
        code.invokespecial(pool.addMethodRef(refclass, "<init>", "(Lanvil/script/StackFrame;I)V"));
        break;

      case GET_BOOLEAN:
        code.aload(_local.getFrameIndex());
        code.iconst(_local.getSlot());
View Full Code Here


  };
 
  public void compile(ByteCompiler context, int operation)
  {
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    boolean inClass = (_function.getType() != Type.FUNCTION);
   
    code.aload_first();
    if (inClass) {
      code.self();
    }
   
    int parent = _function.getParent().getTypeRef(pool);
    String name = (inClass ? "m_" : "f_")+_function.getName();
    int field = pool.addFieldRef(parent, name, "Lanvil/script/Function;");
    code.getstatic(field);
   
    int depth = Grammar.countEscapeDepth(_context, _function);
    code.aload(_context.getFrameIndex());
    if (depth >= 0) {
      code.iconst(depth+1);
      code.invokevirtual(pool.addMethodRef("anvil/script/StackFrame", "getEscape",
        "(I)Lanvil/script/StackFrame;"));
    }
   
    int n = childs();
    if (!hasSplices() && n<=4) {
      for(int i=0; i<n; i++) {
        getChild(i).compile(context, GET);
      }
      code.invokevirtual(pool.addMethodRef(context.TYPE_CONTEXT, "exec",
          inClass ? SIGNATURES_SELF[n] : SIGNATURES_NO_SELF[n]));
         
    } else {
      context.compileArgumentList(getChilds(0));
      code.invokevirtual(pool.addMethodRef(context.TYPE_CONTEXT, "exec",
        inClass ? "(Lanvil/core/Any;Lanvil/script/Function;Lanvil/script/StackFrame;[Lanvil/core/Any;)Lanvil/core/Any;" :
                  "(Lanvil/script/Function;Lanvil/script/StackFrame;[Lanvil/core/Any;)Lanvil/core/Any;"));
       
    }   
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,
      "pipe", "(Lanvil/core/Any;Lanvil/core/Any;)Lanvil/core/Any;"));
    if (operation == GET_BOOLEAN) {
      context.any2boolean();
    }
  }
View Full Code Here

  public void compile(ByteCompiler context)
  {
    ClassRoom clazz = context.getClassRoom().createClass(getDescriptor(), "i_"+_name);
    clazz.setAccessFlags(context.ACC_PUBLIC);
    ConstantPool pool = clazz.getPool();
    context.pushClass(clazz);
    Field typefield1 = clazz.createField("_class", "Lanvil/script/compiler/CompiledInterfaceType;", 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());

    Field bases = clazz.createField("_bases", "[Ljava/lang/String;", Code.ACC_PUBLIC|Code.ACC_STATIC);
    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();

    int n = _bases.length;
    code.iconst(n);
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:
      {
        child.compile(context, new Node() {
          public void compile(ByteCompiler context, int operation)
          {
            Code code = context.getCode();
            child.compile(context, GET);
            code.invokevirtual(code.getPool().addMethodRef(context.TYPE_ANY, "increase", "()Lanvil/core/Any;"));
          }     
        });
      }
      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, "preinc",
          "(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, "preinc",
          "(Lanvil/core/Any;Lanvil/core/Any;Lanvil/script/Context;)Lanvil/core/Any;"));
      }
      break;

    default:
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:
      {
        child.compile(context, new Node() {
          public void compile(ByteCompiler context, int operation)
          {
            Code code = context.getCode();
            child.compile(context, GET);
            code.invokevirtual(code.getPool().addMethodRef(context.TYPE_ANY, "decrease", "()Lanvil/core/Any;"));
          }     
        });
      }
      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, "predec",
          "(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, "predec",
          "(Lanvil/core/Any;Lanvil/core/Any;Lanvil/script/Context;)Lanvil/core/Any;"));
      }
      break;

    default:
View Full Code Here

    Code code = context.getCode();
    _var.compile(context, new Node() {
      public void compile(ByteCompiler context, int operation)
      {
        Code code_ = context.getCode();
        ConstantPool pool = code_.getPool();
        int clazz = getClassReference(pool);
        code_.anew(clazz);
        code_.dup();
        code_.invokespecial(pool.addMethodRef(clazz, "<init>", "()V"));
      }     
    });
    code.pop();
    _stmt.compile(context);
    _var.compile(context, GET);
View Full Code Here


  protected static void compileMembers(ByteCompiler context, int size, Enumeration types)
  {
    ClassRoom clazz = context.getClassRoom();
    ConstantPool pool = clazz.getPool();
    Field members = clazz.createField("_members", "[Ljava/lang/Object;", Code.ACC_PUBLIC|Code.ACC_STATIC);
    Code code = clazz.getStatic().getCode();
    context.pushCode(code);
    int intclazz = pool.addClass("java/lang/Integer");
    int intclazzctor = pool.addMethodRef(intclazz, "<init>", "(I)V");
    code.iconst(size * 4);
    code.anewarray("java/lang/Object");
    for(int i=0; types.hasMoreElements();) {
      Type type = (Type)types.nextElement();
      switch(type.getType()) {
View Full Code Here

    String name = (in_class ? "m_" : "f_")+_function.getName();
    String signature = in_class ?
      "(Lanvil/core/Any;Lanvil/script/Function;Lanvil/script/StackFrame;)V" :
      "(Lanvil/script/Function;Lanvil/script/StackFrame;)V";
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    int anyfunction = pool.addClass("anvil/core/runtime/AnyFunction");
    code.anew(anyfunction);
    code.dup();
    int parent = _function.getParent().getTypeRef(pool);
    int field = pool.addFieldRef(parent, name, "Lanvil/script/Function;");
    if (in_class) {
      code.self();
    }
    code.getstatic(field);
    code.aload(_context.getFrameIndex());
    int depth = Grammar.countEscapeDepth(_context, _function);
    if (depth >= 0) {
      code.iconst(depth+1);
      code.invokevirtual(pool.addMethodRef("anvil/script/StackFrame", "getEscape",
        "(I)Lanvil/script/StackFrame;"));
    }
    code.invokespecial(pool.addMethodRef(anyfunction, "<init>", signature));
    if (operation == GET_BOOLEAN) {
      context.any2boolean();
    }
  }
View Full Code Here

 
  public void compile(ByteCompiler context, int operation)
  {
    boolean get_type = (operation == GET_TYPE);
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    if (_type instanceof NativeJava) {
      switch(_type.getType()) {
      case Type.FUNCTION:
        {
          code.getstatic(pool.addFieldRef(_type.getParent().getTypeRef(pool),
            "__module__", "Lanvil/script/compiler/NativeNamespace;"));
          code.aload_first();
          code.astring(_type.getName())
          int method;
          if (get_type) {
            method = pool.addMethodRef("anvil/script/compiler/NativeNamespace",
              "getDeclaration", "(Lanvil/script/Context;Ljava/lang/String;)Lanvil/script/Type;");
          } else {
            method = pool.addMethodRef("anvil/script/compiler/NativeNamespace", "getFunction",
              "(Lanvil/script/Context;Ljava/lang/String;)Lanvil/core/Any;");
          }
          code.invokevirtual(method);
        }
        break;

      case Type.CLASS:
        {
          code.getstatic(pool.addFieldRef(_type.getTypeRef(pool),
            "__class__", "Lanvil/script/compiler/NativeClass;"));
          if (!get_type) {
            code.invokevirtual(pool.addMethodRef("anvil/script/compiler/NativeClass",
              "getWrapper", "()Lanvil/core/Any;"));
          }
        }
        break;
       
      case Type.NAMESPACE:
        {
          code.getstatic(pool.addFieldRef(_type.getTypeRef(pool),
            "__module__", "Lanvil/script/compiler/NativeNamespace;"));
          if (!get_type) {
            code.invokevirtual(pool.addMethodRef("anvil/script/compiler/NativeNamespace",
              "getWrapper", "()Lanvil/core/Any;"));         
          }
        }
        break;
       
      case Type.METHOD:
        {
          code.getstatic(pool.addFieldRef(_type.getParent().getTypeRef(pool),
            "__class__", "Lanvil/script/compiler/NativeClass;"));
          int method;
          code.aload_first();
          code.astring(_type.getName())
          if (get_type) {
            method = pool.addMethodRef("anvil/script/compiler/NativeClass",
              "getDeclaration", "(Lanvil/script/Context;Ljava/lang/String;)Lanvil/script/Type;");
          } else {
            method = pool.addMethodRef("anvil/script/compiler/NativeClass", "getMethod",
              "(Lanvil/script/Context;Ljava/lang/String;)Lanvil/core/Any;");
          }
          code.invokevirtual(method);
        }
        break;
      }
     
    } else {
      switch(_type.getType()) {
      case Type.FUNCTION:
        {
          int field = pool.addFieldRef(_type.getParent().getTypeRef(pool),
            (get_type ? "f_" : "F_") + _type.getName(),
             get_type ? "Lanvil/script/Function;" : "Lanvil/core/Any;");
          code.getstatic(field);
        }
        break;
     
      case Type.MEMBER_VARIABLE:
        {
          Type parent = _type.getParent();
          int field = pool.addFieldRef(parent.getTypeRef(pool), "_class",
            "Lanvil/script/compiler/CompiledClassType;");
          code.getstatic(field);
          code.aload_first();
          code.astring(_type.getName());
          code.invokevirtual(pool.addMethodRef(
            "anvil/script/compiler/CompiledClassType",
            get_type ?
              "getMember" :
              "getMemberType",
            get_type ?
              "(Lanvil/script/Context;Ljava/lang/String;)Lanvil/script/Type;" :
              "(Lanvil/script/Context;Ljava/lang/String;)Lanvil/core/Any;"));
        }
        break;
       
      case Type.INTERFACE_METHOD:
      case Type.METHOD:
      case Type.CONSTRUCTOR:
        {
          int field = pool.addFieldRef(_type.getParent().getTypeRef(pool),
            (get_type ? "m_" : "M_") + _type.getName(),
             get_type ? "Lanvil/script/Function;" : "Lanvil/core/Any;");
          code.getstatic(field);
        }
        break;

      case Type.CLASS:
        {
          if (get_type) {
            int field = pool.addFieldRef(_type.getTypeRef(pool), "_class",
              "Lanvil/script/compiler/CompiledClassType;");
            code.getstatic(field);
          } else {
            int field = pool.addFieldRef(_type.getTypeRef(pool),
              "_type", "Lanvil/core/Any;");
            code.getstatic(field);           
          }
        }
        break;

      case Type.INTERFACE:
        {
          int field = pool.addFieldRef(_type.getTypeRef(pool),
            get_type ? "_class" : "_type",
            get_type ? "Lanvil/script/compiler/CompiledInterfaceType;" : "Lanvil/core/Any;");
          code.getstatic(field);
        }
        break;

      case Type.NAMESPACE:
        {
          int field = pool.addFieldRef(_type.getTypeRef(pool),
            get_type ? "_class" : "_type",
            get_type ? "Lanvil/script/compiler/CompiledNamespace;" : "Lanvil/core/Any;");
          code.getstatic(field);
        }
        break;
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.