/*
* $Id: MappingNode.java,v 1.8 2002/09/16 08:05:05 jkl Exp $
*
* Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
*
* Use is subject to license terms, as defined in
* Anvil Sofware License, Version 1.1. See LICENSE
* file, or http://njet.org/license-1.1.txt
*/
package anvil.script.expression;
import anvil.core.Any;
import anvil.core.AnyMap;
import anvil.codec.Code;
import anvil.codec.ConstantPool;
import anvil.script.compiler.ByteCompiler;
import anvil.script.Context;
import java.io.IOException;
/**
* class MappingNode
*
* @author: Jani Lehtim�ki
*/
public class MappingNode extends BinaryParent
{
public MappingNode(Node left, Node right)
{
super(left, right);
}
public int typeOf()
{
return Node.EXPR_MAPPING;
}
public Node optimize()
{
optimizeChilds();
return this;
}
public Any getKey()
{
return _left.eval();
}
public Any getValue()
{
return _right.eval();
}
public Any eval()
{
return new AnyMap(_left.eval(), _right.eval());
}
public void compile(ByteCompiler context, int operation)
{
Code code = context.getCode();
ConstantPool pool = code.getPool();
int clazz = pool.addClass("anvil/core/AnyMap");
code.anew(clazz);
code.dup();
super.compile(context, GET);
code.invokespecial(pool.addMethodRef(clazz, "<init>",
"(Lanvil/core/Any;Lanvil/core/Any;)V"));
if (operation == GET_BOOLEAN) {
context.any2boolean();
}
}
}