sleep.runtime
Class ScriptInstance
public
class
ScriptInstance
extends Object
implements Serializable, Runnable
Every piece of information related to a loaded script. This includes the scripts runtime environment, code in compiled
form, variable information, and listeners for runtime issues.
Field Summary |
protected int | debug track all of the flagged debug options for this script (set to DEBUG_SHOW_ERRORS by default) |
static int | DEBUG_NONE debug should be absolutely quiet, never fire any runtime warnings |
static int | DEBUG_REQUIRE_STRICT fire runtime warning whenever an undeclared variable is fired |
static int | DEBUG_SHOW_ERRORS fire runtime warnings for all critical flow interrupting errors |
static int | DEBUG_SHOW_WARNINGS fire runtime warnings for anything flagged for retrieval with checkError() |
static int | DEBUG_THROW_WARNINGS throw exceptions for anything flagged for retrieval with checkError() |
static int | DEBUG_TRACE_CALLS fire a runtime warning describing each function call |
static int | DEBUG_TRACE_LOGIC fire a runtime warning describing each predicate decision made |
static int | DEBUG_TRACE_PROFILE_ONLY forces function call tracing to occur (for the sake of profiling a script) but supresses
all runtime warnings as a result of the tracing |
protected static int | DEBUG_TRACE_SUPPRESS users shouldn't need to flag this, it is just a general method of saying we're suppressing
trace messages... |
protected ScriptEnvironment | environment The script environment which contains all of the runtime info for a script |
protected boolean | loaded true by default, indicates wether or not the script is loaded. |
protected String | name the name of this script |
protected IOObject | parent |
protected Block | script The compiled sleep code for this script, the ScriptLoader will set this value upon loading a script. |
protected ScriptVariables | variables The script variables which contains all of the variable information for a script |
protected LinkedList | watchers A list of listeners watching for a runtime error |
Constructor Summary |
| ScriptInstance(Hashtable environmentToShare) Constructs a script instance, if the parameter is null a default implementation will be used.
|
| ScriptInstance(Variable varContainerToUse, Hashtable environmentToShare) Constructs a script instance, if either of the parameters are null a default implementation will be used.
|
| ScriptInstance() Constructs a new script instance |
Method Summary |
void | addWarningWatcher(RuntimeWarningWatcher w) Register a runtime warning watcher listener. |
Scalar | callFunction(String funcName, Stack parameters) Calls a subroutine/built-in function using this script. |
void | clearStackTrace() Removes the top element of the stack trace |
void | collect(String function, int lineNo, long ticks) this function is used internally by the sleep interpreter to collect profiler statistics
when DEBUG_TRACE_CALLS or DEBUG_TRACE_PROFILE_ONLY is enabled |
void | fireWarning(String message, int line) Fire a runtime script warning |
void | fireWarning(String message, int line, boolean isTrace) Fire a runtime script warning |
ScriptInstance | fork() Creates a forked script instance. |
int | getDebugFlags() retrieve the debug flags for this script |
String | getName() Returns the name of this script (typically a full pathname) as a String |
List | getProfilerStatistics() Returns a sorted (in order of total ticks used) list of function call statistics for this
script environment. |
Block | getRunnableBlock() Returns the compiled form of this script |
ScriptEnvironment | getScriptEnvironment() Returns this scripts runtime environment |
ScriptVariables | getScriptVariables() Returns the variable container used by this script |
List | getStackTrace() Returns the last stack trace. |
void | installBlock(Block _script) Install a block as the compiled script code |
boolean | isLoaded() Returns wether or not this script is loaded. |
boolean | isProfileOnly() a quick way to check if we are profiling and not tracing the script steps |
void | printProfileStatistics(OutputStream out) Dumps the profiler statistics to the specified stream |
void | recordStackFrame(String description, String source, int lineNumber) Records a stack frame into this environments stack trace tracker thingie. |
void | recordStackFrame(String description, int lineNumber) Records a stack frame into this environments stack trace tracker thingie. |
void | removeWarningWatcher(RuntimeWarningWatcher w) Removes a runtime warning watcher listener |
void | run() Executes this script, same as runScript() just here for Runnable compatability |
Scalar | runScript() Executes this script, should be done first thing once a script is loaded |
void | setDebugFlags(int options) set the debug flags for this script |
void | setName(String sn) Sets the name of this script |
void | setParent(IOObject p) Sets up the parent of this script (in case it is being run via &fork()). |
void | setScriptVariables(ScriptVariables v) Sets the variable container to be used by this script |
void | setUnloaded() Flag this script as unloaded |
protected int debug
track all of the flagged debug options for this script (set to DEBUG_SHOW_ERRORS by default)
public static final int DEBUG_NONE
debug should be absolutely quiet, never fire any runtime warnings
public static final int DEBUG_REQUIRE_STRICT
fire runtime warning whenever an undeclared variable is fired
public static final int DEBUG_SHOW_ERRORS
fire runtime warnings for all critical flow interrupting errors
public static final int DEBUG_SHOW_WARNINGS
fire runtime warnings for anything flagged for retrieval with checkError()
public static final int DEBUG_THROW_WARNINGS
throw exceptions for anything flagged for retrieval with checkError()
public static final int DEBUG_TRACE_CALLS
fire a runtime warning describing each function call
public static final int DEBUG_TRACE_LOGIC
fire a runtime warning describing each predicate decision made
public static final int DEBUG_TRACE_PROFILE_ONLY
forces function call tracing to occur (for the sake of profiling a script) but supresses
all runtime warnings as a result of the tracing
protected static final int DEBUG_TRACE_SUPPRESS
users shouldn't need to flag this, it is just a general method of saying we're suppressing
trace messages...
The script environment which contains all of the runtime info for a script
protected boolean loaded
true by default, indicates wether or not the script is loaded. Once unloaded this variable must be flagged to false so
the bridges know data related to this script is stale
protected String name
the name of this script
The compiled sleep code for this script, the ScriptLoader will set this value upon loading a script.
The script variables which contains all of the variable information for a script
protected LinkedList watchers
A list of listeners watching for a runtime error
public ScriptInstance(Hashtable environmentToShare)
Constructs a script instance, if the parameter is null a default implementation will be used.
By specifying the same shared Hashtable container for all scripts, such scripts can be made to
environment information
public ScriptInstance(
Variable varContainerToUse, Hashtable environmentToShare)
Constructs a script instance, if either of the parameters are null a default implementation will be used.
By specifying the same shared Variable and Hashtable containers for all scripts, scripts can be made to
share variables and environment information
public ScriptInstance()
Constructs a new script instance
Register a runtime warning watcher listener. If an error occurs while the script is running these listeners will
be notified
public
Scalar callFunction(String funcName, Stack parameters)
Calls a subroutine/built-in function using this script.
public void clearStackTrace()
Removes the top element of the stack trace
public void collect(String function, int lineNo, long ticks)
this function is used internally by the sleep interpreter to collect profiler statistics
when DEBUG_TRACE_CALLS or DEBUG_TRACE_PROFILE_ONLY is enabled
public void fireWarning(String message, int line)
Fire a runtime script warning
public void fireWarning(String message, int line, boolean isTrace)
Fire a runtime script warning
Creates a forked script instance. This does not work like fork in an operating system. Variables are not copied, period.
The idea is to create a fork that shares the same environment as this script instance.
public int getDebugFlags()
retrieve the debug flags for this script
public String getName()
Returns the name of this script (typically a full pathname) as a String
public List getProfilerStatistics()
Returns a sorted (in order of total ticks used) list of function call statistics for this
script environment. The list contains ScriptInstance.ProfileStatistic objects.
Note!!! For Sleep to provide profiler statistics, DEBUG_TRACE_CALLS or DEBUG_TRACE_PROFILE_ONLY must be enabled!
public
Block getRunnableBlock()
Returns the compiled form of this script
Returns this scripts runtime environment
Returns the variable container used by this script
public List getStackTrace()
Returns the last stack trace. Each element of the list is a ScriptInstance.SleepStackElement object.
First element is the top of the trace, last element is the origin of the trace. This function also
clears the stack trace.
public void installBlock(
Block _script)
Install a block as the compiled script code
public boolean isLoaded()
Returns wether or not this script is loaded. If it is unloaded it should be removed from data structures and
its modifications to the environment should be ignored
public boolean isProfileOnly()
a quick way to check if we are profiling and not tracing the script steps
public void printProfileStatistics(OutputStream out)
Dumps the profiler statistics to the specified stream
public void recordStackFrame(String description, String source, int lineNumber)
Records a stack frame into this environments stack trace tracker thingie.
public void recordStackFrame(String description, int lineNumber)
Records a stack frame into this environments stack trace tracker thingie.
Removes a runtime warning watcher listener
public void run()
Executes this script, same as runScript() just here for Runnable compatability
Executes this script, should be done first thing once a script is loaded
public void setDebugFlags(int options)
set the debug flags for this script
public void setName(String sn)
Sets the name of this script
Sets up the parent of this script (in case it is being run via &fork()). When this script returns a value, the return value will be passed to the parent IOObject to allow retrieval with the &wait function.
Sets the variable container to be used by this script
public void setUnloaded()
Flag this script as unloaded