DynamicCallNode.java :  » Web-Framework » anvil » anvil » script » expression » Java Open Source

Java Open Source » Web Framework » anvil 
anvil » anvil » script » expression » DynamicCallNode.java
/*
 * $Id: DynamicCallNode.java,v 1.16 2002/09/16 08:05:04 jkl Exp $
 *
 * Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
 *
 * Use is subject to license terms, as defined in
 * Anvil Sofware License, Version 1.1. See LICENSE 
 * file, or http://njet.org/license-1.1.txt
 */
package anvil.script.expression;

import anvil.core.Any;
import anvil.core.runtime.AnyFunction;
import anvil.codec.Code;
import anvil.script.compiler.ByteCompiler;
import anvil.script.Context;
import anvil.script.Function;
import java.io.IOException;

/**
 * class DynamicCallNode
 *
 * @author: Jani Lehtimki
 */
public class DynamicCallNode extends MultiParent
{
 
 
  public DynamicCallNode(Node self, Parent parameters) 
  {
    super(1 + parameters.childs());
    int n = parameters.childs();
    setChild(0, self);
    for(int i=0; i<n; i++) {
      setChild(i + 1, parameters.getChild(i));
    }
  }


  public int typeOf() 
  {
    return Node.EXPR_CALL;
  }


  public boolean isConstant() 
  {
    return false;
  }


  private static final String[] SIGNATURES = {
    "(Lanvil/script/Context;)Lanvil/core/Any;",
    "(Lanvil/script/Context;Lanvil/core/Any;)Lanvil/core/Any;",
    "(Lanvil/script/Context;Lanvil/core/Any;Lanvil/core/Any;)Lanvil/core/Any;",
    "(Lanvil/script/Context;Lanvil/core/Any;Lanvil/core/Any;Lanvil/core/Any;)Lanvil/core/Any;",
    "(Lanvil/script/Context;Lanvil/core/Any;Lanvil/core/Any;Lanvil/core/Any;Lanvil/core/Any;)Lanvil/core/Any;"
  };
  

  public void compile(ByteCompiler context, int operation)
  {
    getChild(0).compile(context, GET);
    Code code = context.getCode();
    code.aload_first();
    int n = childs() - 1;
    if (!hasSplices() && n <= 4) {
      for(int i=0; i<n; i++) {
        getChild(1 + i).compile(context, GET);
      }
      code.invokevirtual(code.getPool().addMethodRef(context.TYPE_ANY, "execute", SIGNATURES[n]));
    } else {
      context.compileArgumentList(getChilds(1));
      code.invokevirtual(code.getPool().addMethodRef(context.TYPE_ANY,
        "execute", "(Lanvil/script/Context;[Lanvil/core/Any;)Lanvil/core/Any;"));
    }
    if (operation == GET_BOOLEAN) {
      context.any2boolean();
    }
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.