Class LazyEvalSlot

All Implemented Interfaces:

public class LazyEvalSlot
extends Object
implements Slot

Untamed: Exists to allow delaying the work of really importing during ScopeSetup, while also allowing the imported things to be in the scope they are defining.

For example, rx__quasiParser is in the safe scope, but is obtained lazily from . For this import to work, it needs to provide the safe scope to the evaluation of this module. Laziness allows the safe scope to effectively include things that can't be defined until the safe scope exists.

Must be made thread-safe for the same reasons as org.erights.e.elib.serial.Loader.

Mark S. Miller

Field Summary
private  Object myLock
private  Object myOptScope
          only meaningful when myOptSource != null
private  Twine myOptSource
          to be evaluated in myOptScope
private  Object myOptValue
          only meaningful when myOptSource == null
Constructor Summary
(package private) LazyEvalSlot(Object scope, Twine source)
Method Summary
 void __printOn(TextWriter out)
 Object getValue()
          Enabled: Returns the result of evaluating my source text in my scope.
 void setValue(Object newValue)
          Enabled: Complains that the variable is immutable
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


private final Object myLock


private Object myOptScope
only meaningful when myOptSource != null


private Twine myOptSource
to be evaluated in myOptScope


private Object myOptValue
only meaningful when myOptSource == null

Constructor Detail


LazyEvalSlot(Object scope,
             Twine source)
scope - The scope in which to evaluate the source text. It's declared as an Object rather than Scope so that it can be a promise for a Scope. This promise must become fulfilled before the first getValue() happens.
source - The source text to be evaluated in the promised scope at the time of the first getValue().
Method Detail


public Object getValue()
Enabled: Returns the result of evaluating my source text in my scope.

This evaluation only happens the first time, after which the value is cached and returned for later requests. If the value isn't DeepPassByCopy, this has security implications, so be careful how you use this class!

Specified by:
getValue in interface Slot


public void setValue(Object newValue)
Enabled: Complains that the variable is immutable

Specified by:
setValue in interface Slot


public void __printOn(TextWriter out)
               throws IOException