Package anvil.script.expression

Source Code of anvil.script.expression.CallNode

/*
* $Id: CallNode.java,v 1.19 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.ErrorListener;
import anvil.script.CompilableFunction;
import anvil.codec.Code;
import anvil.codec.ConstantPool;
import anvil.script.compiler.ByteCompiler;
import anvil.script.Context;
import anvil.script.Type;
import anvil.script.Grammar;
import anvil.script.NativeJava;
import java.io.IOException;

/**
* class CallNode
*
* @author: Jani Lehtim�ki
*/
public class CallNode extends MultiParent
{
  protected CompilableFunction _function = null;


  public CallNode(CompilableFunction function, Parent parameters)
  {
    super(parameters);
    _function = function;
  }


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


  public boolean isConstant()
  {
    return false;
  }

 
  public Node optimize()
  {
    optimizeChilds();
    return this;
  }



  public void compileRef(ByteCompiler context)
  {
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    code.getstatic(pool.addFieldRef(context.TYPE_MODULE,
      "f_"+_function.getName(), "Lanvil/script/Function;"));
  }
 
 
  public CompilableFunction getFunction()
  {
    return _function;
  }


  public void compile(ByteCompiler context, int operation)
  {
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    if (_function instanceof NativeJava) {
      if (hasSplices()) {
        code.getstatic(pool.addFieldRef(_function.getParent().getTypeRef(pool),
          "__module__", "Lanvil/script/compiler/NativeNamespace;"));
        code.aload_first();
        code.astring(_function.getName())
        context.compileArgumentList(getChilds(0));
        code.invokevirtual(pool.addMethodRef(
          "anvil/script/compiler/NativeNamespace", "execute",
          "(Lanvil/script/Context;Ljava/lang/String;[Lanvil/core/Any;)Lanvil/core/Any;"));
         
      } else {
        context.compileCall(_function, getChilds(0));
       
      }
     
    } else {
      if (hasSplices()) {
        code.getstatic(pool.addFieldRef(context.TYPE_MODULE,
          "f_"+_function.getName(), "Lanvil/script/Function;"));
        code.aload_first();
        context.compileArgumentList(getChilds(0));
        code.invokeinterface(pool.addInterfaceMethodRef(
          context.TYPE_FUNCTION, "execute",
          "(Lanvil/script/Context;[Lanvil/core/Any;)Lanvil/core/Any;"));
         
      } else {
        context.compileCall(_function, getChilds(0));
       
      }
    }
   
    if (operation == GET_BOOLEAN) {
      context.any2boolean();
   
  }

}
TOP

Related Classes of anvil.script.expression.CallNode

TOP
Copyright © 2018 www.massapi.com. 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.