This class contains methods for accessing the data stack, return value of a function, and the environment hashtable
for a script. In sleep each ScriptInstance has a ScriptEnvironment object associated with it. Most of the functions in
this class are used internally by sleep.
For the developers purposes, this class is your gateway into the runtime environment of a script.
If you use the evaluate methods to evaluate a snippet of code, they will be evaluated as if they were part of the
script file that this ScriptEnvironment represents.
The Hashtable environment contains references for all of the loaded bridges this script has access to. Every
function, predicate, and operator is specified in the environment hashtable. To force scripts to share this information
use setEnvironment(Hashtable) and pass the same instance of Hashtable that other scripts are using.
This class is instantiated by sleep.runtime.ScriptInstance.
FLOW_CONTROL_BREAK
public static final int FLOW_CONTROL_BREAK
request a break out of the current loop
FLOW_CONTROL_CONTINUE
public static final int FLOW_CONTROL_CONTINUE
adding a continue keyword as people keep demanding it
FLOW_CONTROL_NONE
public static final int FLOW_CONTROL_NONE
currently no flow contrl change has been requested
FLOW_CONTROL_RETURN
public static final int FLOW_CONTROL_RETURN
request a return from the current function
FLOW_CONTROL_YIELD
public static final int FLOW_CONTROL_YIELD
adding a yield keyword
context
protected Stack context
contextStack
protected Stack contextStack
debugString
protected String debugString
environment
protected Hashtable environment
the environment hashtable that contains all of the functions, predicates, operators, and "environment keywords" this
script has access to.
environmentStack
protected Stack environmentStack
the runtime data stack for this environment
errorMessage
protected String errorMessage
stored error message...
findex
protected int findex
frames
protected ArrayList frames
isDebugInterrupt
protected boolean isDebugInterrupt
metaStack
protected Stack metaStack
metadata
protected HashMap metadata
request
protected int request
self
protected ScriptInstance self
the script instance that this is the environment for
sources
protected Stack sources
how many stacks does this damned class include?
CreateFrame
public void CreateFrame()
FrameResult
public void FrameResult(Scalar value)
kills the current frame and if there is a parent frame pushes the specified value on to it
KillFrame
public void KillFrame()
addToContext
public void addToContext(Block b,
Step s)
checkError
public String checkError()
once an error is checked using this function, it is cleared, the orignal error message is returned as well
clearReturn
public void clearReturn()
evaluateOldContext
public Scalar evaluateOldContext()
evaluateParsedLiteral
public Scalar evaluateParsedLiteral(String code)
throws YourCodeSucksException
evaluates the passed in code as if it was a sleep parsed literal
evaluatePredicate
public boolean evaluatePredicate(String code)
throws YourCodeSucksException
evaluates a predicate condition
evaluateStatement
public Scalar evaluateStatement(String code)
throws YourCodeSucksException
evaluate a full blown statement... probably best to just load a script at this point
flagError
public void flagError(String message)
A utility for bridge writers to flag an error. flags an error that script writers can then check for with checkError().
Currently used by the IO bridge openf, exec, and connect functions. Major errors should bubble up as exceptions. Small
stuff like being unable to open a certain file should be flagged this way.
flagReturn
public void flagReturn(Scalar value,
int type_of_flow)
getContextMetadata
public Object getContextMetadata(Object key)
Returns the data associated with the particular key for this context.
getContextMetadata
public Object getContextMetadata(Object key,
Object default_value)
Returns the data associated with the particular key for this context. If the key value is null then the specified default_value is returned
getCurrentFrame
public Stack getCurrentFrame()
getCurrentSource
public String getCurrentSource()
obtain the filename of the current source of execution
getDebugString
public String getDebugString()
getEnvironment
public Hashtable getEnvironment()
Returns the environment for this script.
The environment has the following formats for keys:
&[keyname] - a sleep function
-[keyname] - assumed to be a unary predicate
[keyname] - assumed to be an environment binding, predicate, or operator
getEnvironmentStack
public Stack getEnvironmentStack()
returns the environment stack used for temporary calculations and such.
getFlowControlRequest
public int getFlowControlRequest()
getFunction
public Function getFunction(String func)
getFunctionEnvironment
public Environment getFunctionEnvironment(String env)
getOperator
public Operator getOperator(String oper)
getPredicate
public Predicate getPredicate(String name)
getReturnValue
public Scalar getReturnValue()
getScalar
public Scalar getScalar(String key)
returns a scalar from this scripts environment
getScriptInstance
public ScriptInstance getScriptInstance()
returns a reference to the script associated with this environment
getScriptVariables
public ScriptVariables getScriptVariables()
returns the variable manager for this script
hasFrame
public boolean hasFrame()
isDebugInterrupt
public boolean isDebugInterrupt()
isReturn
public boolean isReturn()
loadContext
public void loadContext(Stack _context,
HashMap _metadata)
popSource
public void popSource()
remove the latest source information from the source stack
pushSource
public void pushSource(String s)
push source information onto the source stack
putScalar
public void putScalar(String key,
Scalar value)
puts a scalar into this scripts environment
saveContext
public Stack saveContext()
setContextMetadata
public void setContextMetadata(Object key,
Object value)
Use this function to save some meta data for this particular closure context, passing null for value will
remove the key from the metadata for this context
setEnvironment
public void setEnvironment(Hashtable h)
Sets the environment Hashtable this script is to use. Sharing an instance of this Hashtable allows scripts to share
common environment data like functions, subroutines, etc. Also useful for bridge writers as their information can be
stored in this hashtable as well
showDebugMessage
public void showDebugMessage(String message)
fires this debug message via a runtime warning complete with line number of current step
toString
public String toString()