sleep.runtime

Class ScriptInstance

Implemented Interfaces:
Runnable, Serializable

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.

Nested Class Summary

static class
ScriptInstance.ProfilerStatistic
A container for a profile statistic about a sleep function

Field Summary

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_TRACE_CALLS
fire a runtime warning describing each function call
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 int
debug
track all of the flagged debug options for this script (set to DEBUG_SHOW_ERRORS by default)
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()
Constructs a new script instance
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.

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 scripts
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
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
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

Field Details

DEBUG_NONE

public static final int DEBUG_NONE
debug should be absolutely quiet, never fire any runtime warnings
Field Value:
0

DEBUG_REQUIRE_STRICT

public static final int DEBUG_REQUIRE_STRICT
fire runtime warning whenever an undeclared variable is fired
Field Value:
4

DEBUG_SHOW_ERRORS

public static final int DEBUG_SHOW_ERRORS
fire runtime warnings for all critical flow interrupting errors
Field Value:
1

DEBUG_SHOW_WARNINGS

public static final int DEBUG_SHOW_WARNINGS
fire runtime warnings for anything flagged for retrieval with checkError()
Field Value:
2

DEBUG_TRACE_CALLS

public static final int DEBUG_TRACE_CALLS
fire a runtime warning describing each function call
Field Value:
8

DEBUG_TRACE_PROFILE_ONLY

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
Field Value:
24

debug

protected int debug
track all of the flagged debug options for this script (set to DEBUG_SHOW_ERRORS by default)

environment

protected ScriptEnvironment environment
The script environment which contains all of the runtime info for a script

loaded

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

name

protected String name
the name of this script

parent

protected IOObject parent

script

protected Block script
The compiled sleep code for this script, the ScriptLoader will set this value upon loading a script.

variables

protected ScriptVariables variables
The script variables which contains all of the variable information for a script

watchers

protected LinkedList watchers
A list of listeners watching for a runtime error

Constructor Details

ScriptInstance

public ScriptInstance()
Constructs a new script instance

ScriptInstance

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

ScriptInstance

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

Method Details

addWarningWatcher

public void addWarningWatcher(RuntimeWarningWatcher w)
Register a runtime warning watcher listener. If an error occurs while the script is running these listeners will be notified

callFunction

public Scalar callFunction(String funcName,
                           Stack parameters)
Calls a subroutine/built-in function using this scripts

collect

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

fireWarning

public void fireWarning(String message,
                        int line)
Fire a runtime script warning

fireWarning

public void fireWarning(String message,
                        int line,
                        boolean isTrace)
Fire a runtime script warning

fork

public ScriptInstance fork()
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.

getDebugFlags

public int getDebugFlags()
retrieve the debug flags for this script

getName

public String getName()
Returns the name of this script (typically a full pathname) as a String

getProfilerStatistics

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!

getRunnableBlock

public Block getRunnableBlock()
Returns the compiled form of this script

getScriptEnvironment

public ScriptEnvironment getScriptEnvironment()
Returns this scripts runtime environment

getScriptVariables

public ScriptVariables getScriptVariables()
Returns the variable container used by this script

installBlock

public void installBlock(Block _script)
Install a block as the compiled script code

isLoaded

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

isProfileOnly

public boolean isProfileOnly()
a quick way to check if we are profiling and not tracing the script steps

printProfileStatistics

public void printProfileStatistics(OutputStream out)
Dumps the profiler statistics to the specified stream

removeWarningWatcher

public void removeWarningWatcher(RuntimeWarningWatcher w)
Removes a runtime warning watcher listener

run

public void run()
Executes this script, same as runScript() just here for Runnable compatability

runScript

public Scalar runScript()
Executes this script, should be done first thing once a script is loaded

setDebugFlags

public void setDebugFlags(int options)
set the debug flags for this script

setName

public void setName(String sn)
Sets the name of this script

setParent

public void setParent(IOObject p)
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.

setScriptVariables

public void setScriptVariables(ScriptVariables v)
Sets the variable container to be used by this script

setUnloaded

public void setUnloaded()
Flag this script as unloaded