01: /*
02: * $Id: DelegateNode.java,v 1.4 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.runtime.AnyNamespace;
14: import anvil.ErrorListener;
15: import anvil.ErrorListener;
16: import anvil.codec.Code;
17: import anvil.codec.ConstantPool;
18: import anvil.script.compiler.ByteCompiler;
19: import anvil.script.statements.FunctionStatement;
20: import anvil.script.statements.ClassStatement;
21: import anvil.script.ClassType;
22: import anvil.script.Context;
23: import anvil.script.MethodType;
24: import anvil.script.Type;
25: import anvil.script.Import;
26: import java.io.IOException;
27:
28: /**
29: * class DelegateNode
30: *
31: * @author: Jani Lehtimäki
32: */
33: public class DelegateNode extends UnaryParent {
34:
35: protected MethodType _method;
36:
37: public DelegateNode(Node self, MethodType method) {
38: super (self);
39: _method = method;
40: }
41:
42: public int typeOf() {
43: return Node.EXPR_TYPE;
44: }
45:
46: public boolean isConstant() {
47: return false;
48: }
49:
50: public Node optimize() {
51: return this ;
52: }
53:
54: public void compile(ByteCompiler context, int operation) {
55: Code code = context.getCode();
56: ConstantPool pool = code.getPool();
57: int anyfunctionclazz = pool
58: .addClass("anvil/core/runtime/AnyFunction");
59: code.anew(anyfunctionclazz);
60: code.dup();
61: _child.compile(context, operation);
62: code.getstatic(pool.addFieldRef(_method.getParent().getTypeRef(
63: pool), "m_" + _method.getName(),
64: "Lanvil/script/Function;"));
65: code
66: .invokespecial(pool.addMethodRef(anyfunctionclazz,
67: "<init>",
68: "(Lanvil/core/Any;Lanvil/script/Function;)V"));
69: if (operation == GET_BOOLEAN) {
70: context.any2boolean();
71: }
72: }
73:
74: }
|