01: /*
02: * $Id: SelectNode.java,v 1.5 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.codec.Code;
14: import anvil.codec.Source;
15: import anvil.script.compiler.ByteCompiler;
16: import anvil.script.Context;
17: import java.io.IOException;
18:
19: /**
20: * class SelectNode
21: *
22: * @author: Jani Lehtimäki
23: */
24: public class SelectNode extends BinaryParent {
25:
26: public SelectNode(Node left, Node right) {
27: super (left, right);
28: }
29:
30: public int typeOf() {
31: return Node.EXPR_SELECT;
32: }
33:
34: public Any eval() {
35: Any left = _left.eval();
36: if (left.toBoolean()) {
37: return left;
38: } else {
39: return _right.eval();
40: }
41: }
42:
43: public void compile(ByteCompiler context, int operation) {
44: _left.compile(context, CHECK);
45: Code code = context.getCode();
46: code.dup();
47: code.invokevirtual(code.getPool().addMethodRef(
48: context.TYPE_ANY, "toBoolean", "()Z"));
49: Source iftrue = code.if_ne();
50: code.pop();
51: _right.compile(context, GET);
52: iftrue.bind();
53: if (operation == GET_BOOLEAN) {
54: context.any2boolean();
55: }
56: }
57:
58: }
|