Package anvil.codec

Examples of anvil.codec.Source


  public void compile(ByteCompiler context, int operation)
  {
    getChild(0).compile(context, GET_BOOLEAN);
    Code code = context.getCode();
    Source isfalse = code.if_eq();
    getChild(1).compile(context, operation);
    Source out = code.go_to();
    code.popop();
    isfalse.bind();
    getChild(2).compile(context, operation);
    out.bind();
  }
View Full Code Here


    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) {
View Full Code Here

    ConstantPool pool = code.getPool();
    context.pushCode(code);
    code.addLocal();
    code.aload(1);
    code.instance_of(context.TYPE_ANY);
    Source isfalse = code.if_eq();
    code.invokestatic(pool.addMethodRef(context.TYPE_CONTEXT, "getInstance", "()Lanvil/script/Context;"));
    code.astore(code.addLocal());
    code.self();
    context.compileArgumentList(function, CAST_P1_NODE, 2);
    code.invokevirtual(function.getTypeRef(pool));
    code.invokevirtual(pool.addMethodRef(context.TYPE_ANY, "toBoolean", "()Z"));
    code.ireturn();
    isfalse.bind();
    code.iconst(false);
    code.ireturn();
    context.popCode();
  }
View Full Code Here

  public void compile(ByteCompiler context, int operation)
  {
    super.compile(context, GET_BOOLEAN);
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    Source notequal = code.if_icmpne();
    if (operation == GET_BOOLEAN) {
      code.iconst(false);
    } else {
      code.getstatic(pool.addFieldRef(context.TYPE_ANY, "FALSE", "Lanvil/core/Any;"));
    }
    Source toend = code.go_to();
    notequal.bind();
    if (operation == GET_BOOLEAN) {
      code.iconst(true);
    } else {
      code.getstatic(pool.addFieldRef(context.TYPE_ANY, "TRUE", "Lanvil/core/Any;"));
    }
    toend.bind();
  }
View Full Code Here

        _init[i].compile(context, Expression.GET);
        code.pop();
      }
    }

    Source skip = null;
    if (_action != null) {
      skip = code.go_to();
    }

    Target start = code.getTarget();
    _startscope = code.getSource();
    _endscope = code.getSource();
   
    if (_action != null) {
      context.location(getLocation());
      int n = _action.length;
      for(int i = 0; i<n; i++) {
        _action[i].compile(context, Expression.GET);
        code.pop();
      }
      skip.bind();
    }

    if (_condition != null) {
      switch(_condition.conditionOf()) {
      case Expression.IS_FALSE:
View Full Code Here

  {
    Code code = context.getCode();
    int n = childs();
    int testmethod = code.getPool().addMethodRef(
      context.TYPE_ANY_OP, "test", "(Lanvil/core/Any;Lanvil/core/Any;)I");
    Source isfalse = code.getSource();
    for(int i=0; i<n; i++) {
      if (i==0) {
        getChild(i++).compile(context, GET);
      }
      getChild(i).compile(context, GET);
      code.dup_x1();
      code.invokestatic(testmethod);
      switch(_op[i-1]) {
      case LESS:
        code.if_ge(isfalse);
        break;       
      case LESS_OR_EQUAL:
        code.if_gt(isfalse);
        break;       
      case GREATER_OR_EQUAL:
        code.if_lt(isfalse);
        break;       
      case GREATER:
        code.if_le(isfalse);
        break;       
      default:
        code.go_to(isfalse);
      }
    }
    code.pop();
    code.iconst(true);
    Source toend = code.go_to();
    isfalse.bind();
    code.pop();
    code.iconst(false);
    toend.bind();
    if (operation != GET_BOOLEAN) {
      context.boolean2any();
    }
  }
View Full Code Here

        Code code = context.getCode();
        ConstantPool pool = code.getPool();
        left.compile(context, GET);
        code.dup();
        code.invokevirtual(pool.addMethodRef(context.TYPE_ANY, "isUndefined", "()Z"));
        Source isfalse = code.if_eq();
        code.pop();
        right.compile(context, GET);
        isfalse.bind();
      }
    });
  }
View Full Code Here

      Code code = context.getCode();
      ConstantPool pool = code.getPool();
      code.getstatic(pool.addFieldRef(context.TYPE_MODULE, "_module", "Lanvil/script/compiler/CompiledModule;"));
      code.invokevirtual(pool.addMethodRef(
        "anvil/script/compiler/CompiledModule", "getAssert", "()Z"));
      Source source = code.if_eq();
      _condition.compile(context, Expression.GET_BOOLEAN);
      code.if_ne(source);
      context.location(getLocation());
      code.aload_first();
      code.astring(_image);
      code.invokevirtual(pool.addMethodRef("anvil/script/Context", "AssertFailed",
        "(Ljava/lang/String;)Lanvil/script/ScriptException;"));
      code.athrow();
      source.bind();
    }
  }  
View Full Code Here

TOP

Related Classes of anvil.codec.Source

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.