001: /*
002: * $Id: CallNode.java,v 1.19 2002/09/16 08:05:04 jkl Exp $
003: *
004: * Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
005: *
006: * Use is subject to license terms, as defined in
007: * Anvil Sofware License, Version 1.1. See LICENSE
008: * file, or http://njet.org/license-1.1.txt
009: */
010: package anvil.script.expression;
011:
012: import anvil.core.Any;
013: import anvil.ErrorListener;
014: import anvil.script.CompilableFunction;
015: import anvil.codec.Code;
016: import anvil.codec.ConstantPool;
017: import anvil.script.compiler.ByteCompiler;
018: import anvil.script.Context;
019: import anvil.script.Type;
020: import anvil.script.Grammar;
021: import anvil.script.NativeJava;
022: import java.io.IOException;
023:
024: /**
025: * class CallNode
026: *
027: * @author: Jani Lehtimäki
028: */
029: public class CallNode extends MultiParent {
030:
031: protected CompilableFunction _function = null;
032:
033: public CallNode(CompilableFunction function, Parent parameters) {
034: super (parameters);
035: _function = function;
036: }
037:
038: public int typeOf() {
039: return Node.EXPR_CALL;
040: }
041:
042: public boolean isConstant() {
043: return false;
044: }
045:
046: public Node optimize() {
047: optimizeChilds();
048: return this ;
049: }
050:
051: public void compileRef(ByteCompiler context) {
052: Code code = context.getCode();
053: ConstantPool pool = code.getPool();
054: code.getstatic(pool.addFieldRef(context.TYPE_MODULE, "f_"
055: + _function.getName(), "Lanvil/script/Function;"));
056: }
057:
058: public CompilableFunction getFunction() {
059: return _function;
060: }
061:
062: public void compile(ByteCompiler context, int operation) {
063: Code code = context.getCode();
064: ConstantPool pool = code.getPool();
065: if (_function instanceof NativeJava) {
066: if (hasSplices()) {
067: code.getstatic(pool.addFieldRef(_function.getParent()
068: .getTypeRef(pool), "__module__",
069: "Lanvil/script/compiler/NativeNamespace;"));
070: code.aload_first();
071: code.astring(_function.getName());
072: context.compileArgumentList(getChilds(0));
073: code
074: .invokevirtual(pool
075: .addMethodRef(
076: "anvil/script/compiler/NativeNamespace",
077: "execute",
078: "(Lanvil/script/Context;Ljava/lang/String;[Lanvil/core/Any;)Lanvil/core/Any;"));
079:
080: } else {
081: context.compileCall(_function, getChilds(0));
082:
083: }
084:
085: } else {
086: if (hasSplices()) {
087: code.getstatic(pool.addFieldRef(context.TYPE_MODULE,
088: "f_" + _function.getName(),
089: "Lanvil/script/Function;"));
090: code.aload_first();
091: context.compileArgumentList(getChilds(0));
092: code
093: .invokeinterface(pool
094: .addInterfaceMethodRef(
095: context.TYPE_FUNCTION,
096: "execute",
097: "(Lanvil/script/Context;[Lanvil/core/Any;)Lanvil/core/Any;"));
098:
099: } else {
100: context.compileCall(_function, getChilds(0));
101:
102: }
103: }
104:
105: if (operation == GET_BOOLEAN) {
106: context.any2boolean();
107: }
108: }
109:
110: }
|