01: /*
02: * $Id: MappingNode.java,v 1.8 2002/09/16 08:05:05 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.AnyMap;
14: import anvil.codec.Code;
15: import anvil.codec.ConstantPool;
16: import anvil.script.compiler.ByteCompiler;
17: import anvil.script.Context;
18: import java.io.IOException;
19:
20: /**
21: * class MappingNode
22: *
23: * @author: Jani Lehtimäki
24: */
25: public class MappingNode extends BinaryParent {
26:
27: public MappingNode(Node left, Node right) {
28: super (left, right);
29: }
30:
31: public int typeOf() {
32: return Node.EXPR_MAPPING;
33: }
34:
35: public Node optimize() {
36: optimizeChilds();
37: return this ;
38: }
39:
40: public Any getKey() {
41: return _left.eval();
42: }
43:
44: public Any getValue() {
45: return _right.eval();
46: }
47:
48: public Any eval() {
49: return new AnyMap(_left.eval(), _right.eval());
50: }
51:
52: public void compile(ByteCompiler context, int operation) {
53: Code code = context.getCode();
54: ConstantPool pool = code.getPool();
55: int clazz = pool.addClass("anvil/core/AnyMap");
56: code.anew(clazz);
57: code.dup();
58: super .compile(context, GET);
59: code.invokespecial(pool.addMethodRef(clazz, "<init>",
60: "(Lanvil/core/Any;Lanvil/core/Any;)V"));
61: if (operation == GET_BOOLEAN) {
62: context.any2boolean();
63: }
64: }
65:
66: }
|