/*
* $Id: ThunkNode.java,v 1.5 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.ErrorListener;
import anvil.Location;
import anvil.core.Any;
import anvil.codec.Code;
import anvil.codec.ConstantPool;
import anvil.script.compiler.ByteCompiler;
import anvil.script.statements.FunctionStatement;
import anvil.script.Context;
import anvil.script.Function;
import anvil.script.Type;
import java.io.IOException;
/**
* class ThunkNode
*
* @author: Jani Lehtim�ki
*/
public class ThunkNode extends Node
{
protected FunctionStatement _context;
protected Function _thunk;
public ThunkNode(FunctionStatement context, Function thunk)
{
super();
_context = context;
_thunk = thunk;
}
public int typeOf()
{
return Node.EXPR_THUNK;
}
public boolean isConstant()
{
return false;
}
public void compile(ByteCompiler context, int operation)
{
Code code = context.getCode();
ConstantPool pool = code.getPool();
boolean inclass = (_thunk.getType() != Type.FUNCTION);
int clazz = pool.addClass("anvil/script/Thunk");
code.anew(clazz);
code.dup();
String name = (inclass ? "m_" : "f_")+_thunk.getName();
String signature = inclass ?
"(Lanvil/script/StackFrame;Lanvil/script/Function;Lanvil/core/Any;)V" :
"(Lanvil/script/StackFrame;Lanvil/script/Function;)V";
if (_context != null) {
code.aload(_context.getFrameIndex());
} else {
code.aconst_null();
}
code.getstatic(pool.addFieldRef(_thunk.getParent().getTypeRef(pool), name, "Lanvil/script/Function;"));
if (inclass) {
code.self();
}
code.invokespecial(pool.addMethodRef(clazz, "<init>", signature));
if (operation == GET_BOOLEAN) {
context.any2boolean();
}
}
}