01: /*
02: * $Id: InitAssignmentNode.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.Location;
13: import anvil.core.Any;
14: import anvil.core.Any.Op;
15: import anvil.codec.Code;
16: import anvil.codec.Source;
17: import anvil.codec.ConstantPool;
18: import anvil.script.compiler.ByteCompiler;
19: import anvil.script.Context;
20: import java.io.IOException;
21:
22: /**
23: * class InitAssignmentNode
24: *
25: * @author: Jani Lehtimäki
26: */
27: public class InitAssignmentNode extends AbstractAssignmentNode {
28:
29: public InitAssignmentNode(Location location, int childs) {
30: super (location, childs);
31: }
32:
33: public int typeOf() {
34: return Node.EXPR_ASSIGN_INIT;
35: }
36:
37: public String getOperator() {
38: return "?=";
39: }
40:
41: protected String getAssignmentMethod() {
42: return "init";
43: }
44:
45: protected void compileOperation(ByteCompiler context,
46: final Node left, final Node right) {
47: left.compile(context, new Node() {
48: public void compile(ByteCompiler context, int operation) {
49: Code code = context.getCode();
50: ConstantPool pool = code.getPool();
51: left.compile(context, GET);
52: code.dup();
53: code.invokevirtual(pool.addMethodRef(context.TYPE_ANY,
54: "isUndefined", "()Z"));
55: Source isfalse = code.if_eq();
56: code.pop();
57: right.compile(context, GET);
58: isfalse.bind();
59: }
60: });
61: }
62:
63: }
|