Package anvil.codec

Examples of anvil.codec.Code


 
  public void compile(ByteCompiler context)
  {
    boolean blocked = false;
    Code code = context.getCode();
    Statement stmt = this;

    if (_target != 0) {
      SwitchStatement target = getSwitch(_label);
      while(!blocked && stmt!=target) {
        blocked = stmt.callFinalizer();
        stmt = stmt.getParentStatement();
      }
      if (!blocked) {
        _case.go_to(code);
      }

    } else {
      Labeled target = getLabeled(_label, true);
      while(!blocked && stmt!=target) {
        blocked = stmt.callFinalizer();
        stmt = stmt.getParentStatement();
      }
      if (!blocked) {
        code.go_to(target.getStartOfScope());
      }
    }
  }
View Full Code Here


  }


  public void accessInstance(ClassType context, ClassType target)
  {
    Code code = getCode();
    if (context == null || context == target) {
      code.self();
      return;
    }
    ConstantPool pool = code.getPool();
    ClassType[] parents = context.getEnclosingClasses();
    int n = parents.length;
    for(int i=0; i<n; i++) {
      ClassType parent = parents[i];
      if (parent == target) {
        code.self();
        code.getfield(pool.addFieldRef(context.getTypeRef(pool), "this$"+i,
          'L'+parent.getDescriptor()+';'));
        return;
      }
    }
    code.self();
  }
View Full Code Here

  }

 
  public void compile(ByteCompiler context, int operation)
  {
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    if (_class instanceof NativeJava) {
      if (hasSplices()) {
        code.getstatic(pool.addFieldRef(_class.getTypeRef(pool),
          "__class__", "Lanvil/script/compiler/NativeClass;"));
        code.aload_first();
        context.compileArgumentList(getChilds(0));
        code.invokevirtual(pool.addMethodRef(
          "anvil/script/compiler/NativeClass", "newInstance",
          "(Lanvil/script/Context;[Lanvil/core/Any;)Lanvil/core/Any;"));
         
       } else {
         context.compileCall(_constructor, getChilds(0));
        
       }
      
    } else {
      int classindex = _class.getTypeRef(pool);
      boolean has_splices = hasSplices();
      if (has_splices) {
        code.getstatic(pool.addFieldRef(classindex, "m_"+_constructor.getName(), "Lanvil/script/Function;"));
        code.aload_first();
      }
      code.anew(classindex);
      code.dup();
      ClassType[] clazz_parents = _class.getEnclosingClasses();
      int n = clazz_parents.length;
      for(int i=0; i<n; i++) {
        context.accessInstance(_context, clazz_parents[i]);
      }
      code.invokespecial(_class.getConstructorReference(pool));
      if (has_splices) {
        context.compileArgumentList(getChilds(0));
        code.invokeinterface(pool.addInterfaceMethodRef("anvil/script/Function", "execute",
          "(Lanvil/script/Context;Lanvil/core/Any;[Lanvil/core/Any;)Lanvil/core/Any;"));
      } else {
        context.compileArgumentList(_constructor, getChilds(0));
        code.invokevirtual(_constructor.getTypeRef(pool));
      }
    }
    if (operation == GET_BOOLEAN) {
      context.any2boolean();
    }
View Full Code Here

  }


  public void compile(ByteCompiler context, int operation)
  {
    Code code = context.getCode();
    if (operation == GET_BOOLEAN) {
      code.iconst(_const.toBoolean());
    } else {
      context.constant(_const, true);
    }
  }
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/AnyList");
    int n = childs();
    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"));
    if (operation == context.GET_BOOLEAN) {
      context.any2boolean();
    }   
  }
View Full Code Here


  public void compile(ByteCompiler context)
  {
    if (_expression != null) {
      Code code = context.getCode();
      if (_expression.needLineNumbers()) {
        context.location(getLocation());
      }
      FunctionStatement function = getFunctionStatement();
      if (_autoreturn && function != null) {
        VariableNode var = function.getReturnVariable();
        if (var != null) {
          var.compile(context, _expression);
        } else {
          _expression.compile(context, Expression.GET);
        }
      } else {
        _expression.compile(context, Expression.GET);
      }
      code.pop();
     
    }
   
  }
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, "decrease", "()Lanvil/core/Any;"));
          }     
        });
        code.pop();
        code.aload(tmp);
        code.endLocal(tmp);
View Full Code Here

  public void compile(ByteCompiler context)
  {
    if (_escaped) {
      FunctionStatement function = (FunctionStatement)_parent;
      Code code = context.getCode();
      code.aload(function.getFrameIndex());
      code.iconst(getSlot());
      code.aload(_index);
      code.invokevirtual(code.getPool().addMethodRef(context.TYPE_STACKFRAME,
        "setLocal", "(ILanvil/core/Any;)Lanvil/core/Any;"));
      code.pop();
    }
  }
View Full Code Here

  }


  public void compileInit(ByteCompiler context)
  {
    Code code = context.getCode();
    _index = code.addLocal();
  }
View Full Code Here

 

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

TOP

Related Classes of anvil.codec.Code

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.