|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object sleep.runtime.ScriptEnvironment
public class ScriptEnvironment
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.
ScriptLoader
,
ScriptInstance
,
Serialized FormNested Class Summary | |
---|---|
protected static class |
ScriptEnvironment.Context
|
protected static class |
ScriptEnvironment.ExceptionContext
|
Field Summary | |
---|---|
protected java.util.Stack |
context
|
protected java.util.Stack |
contextStack
|
protected ScriptEnvironment.ExceptionContext |
currentHandler
|
protected java.lang.String |
debugString
|
protected java.util.Hashtable |
environment
the environment hashtable that contains all of the functions, predicates, operators, and "environment keywords" this script has access to. |
protected java.util.Stack |
environmentStack
the runtime data stack for this environment |
protected java.lang.Object |
errorMessage
stored error message... |
protected java.util.Stack |
exhandlers
|
protected int |
findex
|
static int |
FLOW_CONTROL_BREAK
request a break out of the current loop |
static int |
FLOW_CONTROL_CALLCC
adding a callcc keyword |
static int |
FLOW_CONTROL_CONTINUE
adding a continue keyword as people keep demanding it |
static int |
FLOW_CONTROL_DEBUG
a special case for debugs and such |
static int |
FLOW_CONTROL_NONE
currently no flow control change has been requested |
static int |
FLOW_CONTROL_PASS
a special case, pass control flow to the return value (it better be a function!) |
static int |
FLOW_CONTROL_RETURN
request a return from the current function |
static int |
FLOW_CONTROL_THROW
adding a throw keyword -- sleep is now useable :) |
static int |
FLOW_CONTROL_YIELD
adding a yield keyword |
protected java.util.ArrayList |
frames
|
protected java.util.HashMap |
metadata
|
protected java.util.Stack |
metaStack
|
protected boolean |
moreHandlers
|
protected int |
request
|
protected Scalar |
rv
|
protected ScriptInstance |
self
the script instance that this is the environment for |
protected java.util.Stack |
sources
how many stacks does this damned class include? |
Constructor Summary | |
---|---|
ScriptEnvironment()
Not recommended that you instantiate a script environment in this way |
|
ScriptEnvironment(java.util.Hashtable env,
ScriptInstance myscript)
Instantiate a new script environment with the specified environment (can be shared), and the specified ScriptInstance |
Method Summary | |
---|---|
void |
addToContext(Block b,
Step s)
|
Scalar |
checkError()
once an error is checked using this function, it is cleared, the orignal error message is returned as well |
void |
cleanFrame(int mark)
markFrame and cleanFrame are used to keep the sleep stack in good order after certain error conditions |
void |
clearReturn()
Clears the return value from the last executed function. |
void |
CreateFrame()
|
void |
CreateFrame(java.util.Stack frame)
|
Scalar |
evaluateExpression(java.lang.String code)
evaluates an expression |
Scalar |
evaluateOldContext()
|
Scalar |
evaluateParsedLiteral(java.lang.String code)
evaluates the passed in code as if it was a sleep parsed literal |
boolean |
evaluatePredicate(java.lang.String code)
evaluates a predicate condition |
Scalar |
evaluateStatement(java.lang.String code)
evaluate a full blown statement... |
void |
flagError(java.lang.Object message)
A utility for bridge writers to flag an error. |
void |
flagReturn(Scalar value,
int type_of_flow)
flags a return value for this script environment |
void |
FrameResult(Scalar value)
kills the current frame and if there is a parent frame pushes the specified value on to it |
Block |
getBlock(java.lang.String name)
|
java.lang.Object |
getContextMetadata(java.lang.Object key)
Returns the data associated with the particular key for this context. |
java.lang.Object |
getContextMetadata(java.lang.Object key,
java.lang.Object default_value)
Returns the data associated with the particular key for this context. |
java.util.Stack |
getCurrentFrame()
|
java.lang.String |
getCurrentSource()
obtain the filename of the current source of execution |
java.lang.String |
getDebugString()
|
java.util.Hashtable |
getEnvironment()
Returns the environment for this script. |
java.util.Stack |
getEnvironmentStack()
returns the environment stack used for temporary calculations and such. |
Block |
getExceptionHandler()
preps and returns the current exception handler... |
Scalar |
getExceptionMessage()
if there is no handler, we'll just get the message which will clear the thrown message as well |
FilterEnvironment |
getFilterEnvironment(java.lang.String env)
|
int |
getFlowControlRequest()
|
Function |
getFunction(java.lang.String func)
|
Environment |
getFunctionEnvironment(java.lang.String env)
|
Operator |
getOperator(java.lang.String oper)
|
Predicate |
getPredicate(java.lang.String name)
|
PredicateEnvironment |
getPredicateEnvironment(java.lang.String env)
|
Scalar |
getReturnValue()
|
Scalar |
getScalar(java.lang.String key)
returns a scalar from this scripts environment |
ScriptInstance |
getScriptInstance()
returns a reference to the script associated with this environment |
ScriptVariables |
getScriptVariables()
returns the variable manager for this script |
boolean |
hasFrame()
|
void |
installExceptionHandler(Block owner,
Block handler,
java.lang.String varname)
|
void |
installExceptionHandler(ScriptEnvironment.ExceptionContext exc)
|
boolean |
isCallCC()
|
boolean |
isDebugInterrupt()
|
boolean |
isExceptionHandlerInstalled()
|
boolean |
isPassControl()
|
boolean |
isResponsible(Block block)
|
boolean |
isReturn()
|
boolean |
isThrownValue()
|
boolean |
isYield()
|
void |
KillFrame()
|
void |
loadContext(java.util.Stack _context,
java.util.HashMap _metadata)
|
int |
markFrame()
markFrame and cleanFrame are used to keep the sleep stack in good order after certain error conditions |
ScriptEnvironment.ExceptionContext |
popExceptionContext()
|
void |
popSource()
remove the latest source information from the source stack |
void |
pushSource(java.lang.String s)
push source information onto the source stack |
void |
putScalar(java.lang.String key,
Scalar value)
puts a scalar into this scripts environment (global scope) |
void |
resetEnvironment()
Resets the script environment to include clearing the return of all flags (including thrown exceptions) |
java.util.Stack |
saveContext()
|
void |
setContextMetadata(java.lang.Object key,
java.lang.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. |
void |
setEnvironment(java.util.Hashtable h)
Sets the environment Hashtable this script is to use. |
void |
showDebugMessage(java.lang.String message)
fires this debug message via a runtime warning complete with line number of current step |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected ScriptInstance self
protected java.util.Stack environmentStack
protected java.util.Hashtable environment
protected java.lang.Object errorMessage
protected java.util.Stack context
protected java.util.Stack contextStack
protected java.util.HashMap metadata
protected java.util.Stack metaStack
protected ScriptEnvironment.ExceptionContext currentHandler
protected java.util.Stack exhandlers
protected boolean moreHandlers
public static final int FLOW_CONTROL_NONE
public static final int FLOW_CONTROL_RETURN
public static final int FLOW_CONTROL_BREAK
public static final int FLOW_CONTROL_CONTINUE
public static final int FLOW_CONTROL_YIELD
public static final int FLOW_CONTROL_THROW
public static final int FLOW_CONTROL_DEBUG
public static final int FLOW_CONTROL_CALLCC
public static final int FLOW_CONTROL_PASS
protected java.lang.String debugString
protected Scalar rv
protected int request
protected java.util.Stack sources
protected java.util.ArrayList frames
protected int findex
Constructor Detail |
---|
public ScriptEnvironment()
public ScriptEnvironment(java.util.Hashtable env, ScriptInstance myscript)
Method Detail |
---|
public ScriptInstance getScriptInstance()
public void flagError(java.lang.Object message)
public Scalar checkError()
public ScriptVariables getScriptVariables()
public Scalar getScalar(java.lang.String key)
public void putScalar(java.lang.String key, Scalar value)
public Block getBlock(java.lang.String name)
public Function getFunction(java.lang.String func)
public Environment getFunctionEnvironment(java.lang.String env)
public PredicateEnvironment getPredicateEnvironment(java.lang.String env)
public FilterEnvironment getFilterEnvironment(java.lang.String env)
public Predicate getPredicate(java.lang.String name)
public Operator getOperator(java.lang.String oper)
public java.util.Hashtable getEnvironment()
public void setEnvironment(java.util.Hashtable h)
public java.util.Stack getEnvironmentStack()
public java.lang.String toString()
toString
in class java.lang.Object
public void loadContext(java.util.Stack _context, java.util.HashMap _metadata)
public void setContextMetadata(java.lang.Object key, java.lang.Object value)
public java.lang.Object getContextMetadata(java.lang.Object key)
public java.lang.Object getContextMetadata(java.lang.Object key, java.lang.Object default_value)
public void addToContext(Block b, Step s)
public Scalar evaluateOldContext()
public java.util.Stack saveContext()
public boolean isExceptionHandlerInstalled()
public boolean isResponsible(Block block)
public void installExceptionHandler(ScriptEnvironment.ExceptionContext exc)
public void installExceptionHandler(Block owner, Block handler, java.lang.String varname)
public Scalar getExceptionMessage()
public Block getExceptionHandler()
public ScriptEnvironment.ExceptionContext popExceptionContext()
public boolean isThrownValue()
public boolean isDebugInterrupt()
public boolean isYield()
public boolean isCallCC()
public boolean isPassControl()
public Scalar getReturnValue()
public boolean isReturn()
public int getFlowControlRequest()
public java.lang.String getDebugString()
public void showDebugMessage(java.lang.String message)
public void flagReturn(Scalar value, int type_of_flow)
public void resetEnvironment()
public void clearReturn()
public void pushSource(java.lang.String s)
public java.lang.String getCurrentSource()
public void popSource()
public int markFrame()
public void cleanFrame(int mark)
public java.util.Stack getCurrentFrame()
public void FrameResult(Scalar value)
public boolean hasFrame()
public void KillFrame()
public void CreateFrame(java.util.Stack frame)
public void CreateFrame()
public Scalar evaluateStatement(java.lang.String code) throws YourCodeSucksException
YourCodeSucksException
public boolean evaluatePredicate(java.lang.String code) throws YourCodeSucksException
YourCodeSucksException
public Scalar evaluateExpression(java.lang.String code) throws YourCodeSucksException
YourCodeSucksException
public Scalar evaluateParsedLiteral(java.lang.String code) throws YourCodeSucksException
YourCodeSucksException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |