01: /*
02: * $Id: InvokeNode.java,v 1.12 2002/09/16 08:05:04 jkl Exp $
03: *
04: * Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
05: *
06: * Use is subject to license terms, as defined in
07: * Anvil Sofware License, Version 1.1. See LICENSE
08: * file, or http://njet.org/license-1.1.txt
09: */
10: package anvil.script.expression;
11:
12: import anvil.core.Any;
13: import anvil.core.Register;
14: import anvil.ErrorListener;
15: import anvil.codec.Code;
16: import anvil.script.compiler.ByteCompiler;
17: import anvil.script.Context;
18: import java.io.IOException;
19:
20: /**
21: * class InvokeNode
22: *
23: * @author: Jani Lehtimäki
24: */
25: public class InvokeNode extends MultiParent {
26:
27: private String _name;
28: private int _index;
29:
30: public InvokeNode(Node self, String name, Parent parameters) {
31: super (1 + parameters.childs());
32: setChild(0, self);
33: int n = parameters.childs();
34: for (int i = 0; i < n; i++) {
35: setChild(i + 1, parameters.getChild(i));
36: }
37: _name = name;
38: _index = Register.register(_name);
39: }
40:
41: public int typeOf() {
42: return Node.EXPR_INVOKE;
43: }
44:
45: public boolean isConstant() {
46: return false;
47: }
48:
49: private static final String[] SIGNATURES = {
50: "(Lanvil/script/Context;I)Lanvil/core/Any;",
51: "(Lanvil/script/Context;ILanvil/core/Any;)Lanvil/core/Any;",
52: "(Lanvil/script/Context;ILanvil/core/Any;Lanvil/core/Any;)Lanvil/core/Any;",
53: "(Lanvil/script/Context;ILanvil/core/Any;Lanvil/core/Any;Lanvil/core/Any;)Lanvil/core/Any;",
54: "(Lanvil/script/Context;ILanvil/core/Any;Lanvil/core/Any;Lanvil/core/Any;Lanvil/core/Any;)Lanvil/core/Any;" };
55:
56: public void compile(ByteCompiler context, int operation) {
57: getChild(0).compile(context, GET);
58: Code code = context.getCode();
59: code.aload_first();
60: context.symbol(_index);
61:
62: int n = childs() - 1;
63: if (!hasSplices() && n <= 4) {
64: for (int i = 0; i < n; i++) {
65: getChild(1 + i).compile(context, GET);
66: }
67: code.invokevirtual(code.getPool().addMethodRef(
68: context.TYPE_ANY, "invoke", SIGNATURES[n]));
69:
70: } else {
71: context.compileArgumentList(getChilds(1));
72: code
73: .invokevirtual(code
74: .getPool()
75: .addMethodRef(context.TYPE_ANY, "invoke",
76: "(Lanvil/script/Context;I[Lanvil/core/Any;)Lanvil/core/Any;"));
77: }
78:
79: if (operation == GET_BOOLEAN) {
80: context.any2boolean();
81: }
82: }
83:
84: }
|