01: /*
02: * $Id: ExactCompareNode.java,v 1.3 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.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 ExactCompareNode
21: *
22: * @author: Jani Lehtimäki
23: */
24: public class ExactCompareNode extends BinaryParent {
25:
26: public ExactCompareNode(Node left, Node right) {
27: super (left, right);
28: }
29:
30: public int typeOf() {
31: return Node.EXPR_COMPARE;
32: }
33:
34: public Any eval() {
35: return Any.create(_left.eval().compareTo(_right.eval()));
36: }
37:
38: public void compile(ByteCompiler context, int operation) {
39: super .compile(context, GET);
40: Code code = context.getCode();
41: code.invokevirtual(code.getPool().addMethodRef(
42: context.TYPE_ANY, "compareTo", "(Lanvil/core/Any;)I"));
43: if (operation == GET_BOOLEAN) {
44: Source isfalse = code.if_eq();
45: code.iconst(true);
46: Source toend = code.go_to();
47: isfalse.bind();
48: code.iconst(false);
49: toend.bind();
50: } else {
51: code.invokestatic(code.getPool().addMethodRef(
52: context.TYPE_ANY, "create", "(I)Lanvil/core/Any;"));
53: }
54: }
55:
56: }
|