01: /*
02: * $Id: ClassOfNode.java,v 1.6 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.ConstantPool;
15: import anvil.script.compiler.ByteCompiler;
16: import anvil.script.Context;
17: import java.io.IOException;
18:
19: /**
20: * class ClassOfNode
21: *
22: * @author: Jani Lehtimäki
23: */
24: public class ClassOfNode extends UnaryParent {
25:
26: public ClassOfNode(Node child) {
27: super (child);
28: }
29:
30: public int typeOf() {
31: return Node.EXPR_CLASSOF;
32: }
33:
34: public Any eval() {
35: return new anvil.core.runtime.AnyType(_child.eval().type());
36: }
37:
38: public void compile(ByteCompiler context, int operation) {
39: Code code = context.getCode();
40: ConstantPool pool = code.getPool();
41: int clazz = pool.addClass("anvil/core/runtime/AnyType");
42: code.anew(clazz);
43: code.dup();
44: _child.compile(context, CHECK);
45: code.invokevirtual(pool.addMethodRef(context.TYPE_ANY, "type",
46: "()Lanvil/script/Type;"));
47: code.invokespecial(pool.addMethodRef(clazz, "<init>",
48: "(Lanvil/script/Type;)V"));
49: if (operation == GET_BOOLEAN) {
50: context.any2boolean();
51: }
52: }
53:
54: }
|