01: /*
02: * $Id: DynamicInvokeNode.java,v 1.8 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.ErrorListener;
14: import anvil.codec.Code;
15: import anvil.script.compiler.ByteCompiler;
16: import anvil.script.Context;
17: import java.io.IOException;
18:
19: /**
20: * class DynamicInvokeNode
21: *
22: * @author: Jani Lehtimäki
23: */
24: public class DynamicInvokeNode extends MultiParent {
25:
26: public DynamicInvokeNode(Node self, Node method, Parent parameters) {
27: super (2 + parameters.childs());
28: setChild(0, self);
29: setChild(1, method);
30: int n = parameters.childs();
31: for (int i = 0; i < n; i++) {
32: setChild(2 + i, parameters.getChild(i));
33: }
34: }
35:
36: public int typeOf() {
37: return Node.EXPR_INVOKE;
38: }
39:
40: public boolean isConstant() {
41: return false;
42: }
43:
44: private static final String[] SIGNATURES = {
45: "(Lanvil/script/Context;Ljava/lang/String;)Lanvil/core/Any;",
46: "(Lanvil/script/Context;Ljava/lang/String;Lanvil/core/Any;)Lanvil/core/Any;",
47: "(Lanvil/script/Context;Ljava/lang/String;Lanvil/core/Any;Lanvil/core/Any;)Lanvil/core/Any;",
48: "(Lanvil/script/Context;Ljava/lang/String;Lanvil/core/Any;Lanvil/core/Any;Lanvil/core/Any;)Lanvil/core/Any;",
49: "(Lanvil/script/Context;Ljava/lang/String;Lanvil/core/Any;Lanvil/core/Any;Lanvil/core/Any;Lanvil/core/Any;)Lanvil/core/Any;" };
50:
51: public void compile(ByteCompiler context, int operation) {
52: Code code = context.getCode();
53: getChild(0).compile(context, GET);
54: code.aload_first();
55:
56: getChild(1).compile(context, GET);
57: code.invokevirtual(code.getPool()
58: .addMethodRef(context.TYPE_OBJECT, "toString",
59: "()Ljava/lang/String;"));
60:
61: int n = childs() - 2;
62: if (!hasSplices() && n <= 4) {
63: for (int i = 0; i < n; i++) {
64: getChild(2 + i).compile(context, GET);
65: }
66: code.invokevirtual(code.getPool().addMethodRef(
67: context.TYPE_ANY, "invoke", SIGNATURES[n]));
68:
69: } else {
70: context.compileArgumentList(getChilds(2));
71: code
72: .invokevirtual(code
73: .getPool()
74: .addMethodRef(context.TYPE_ANY, "invoke",
75: "(Lanvil/script/Context;Ljava/lang/String;[Lanvil/core/Any;)Lanvil/core/Any;"));
76: }
77:
78: if (operation == GET_BOOLEAN) {
79: context.any2boolean();
80: }
81: }
82:
83: }
|