/*
* $Id: Thunk.java,v 1.3 2002/09/16 08:05:03 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;
import java.io.IOException;
import anvil.core.Any;
import anvil.core.AnyRef;
import anvil.core.Serializer;
public class Thunk extends AnyRef
{
protected StackFrame _escape;
protected Function _function;
protected Any _self = null;
protected Any _result = null;
public Thunk(StackFrame escape, Function function)
{
_escape = escape;
_function = function;
}
public Thunk(StackFrame escape, Function function, Any self)
{
_escape = escape;
_function = function;
_self = self;
}
public void setRef(Any value)
{
}
public Any getRef()
{
Any result = _result;
if (result == null) {
synchronized(this) {
if ((result = _result) != null) {
return result;
}
Context context = Context.getInstance();
context.setEscape(_escape);
return (_result = _function.execute(context, _self, Any.ARRAY0));
}
}
return result;
}
public void serialize(Serializer serializer) throws IOException
{
throw new IOException("Cannot serialize thunks");
}
}