java.lang.Object
technology.sola.script.runtime.ScriptRuntime
ScriptRuntime contains environment state information as well as a
ScopeTable
to keep track of nested scope
variable resolutions.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
assignVariable
(Expr.Assign expr, @Nullable Object value) Assigns a variable's value utilizing the variable resolutions in theScopeTable
for the runtime.Creates a nested environment with the previous environment as its parent.void
defineConstant
(String name, @Nullable Object value) Defines a constant with desired value in the current environment.void
defineVariable
(String name, @Nullable Object value) Defines a variable with desired value in the current environment.void
importModule
(ScriptModule scriptModule) Imports functionality provided by aScriptModule
into the globals of this runtime.@Nullable Object
lookUpVariable
(Expr.Variable expr) Looks up a variable's value utilizing the variable resolutions in theScopeTable
for the runtime.void
restoreEnvironment
(EnvironmentHandle handle) Restores an environment utilizing itsEnvironmentHandle
.scopes()
Gets theScopeTable
for the runtime so it can be updated with local variable resolutions.
-
Constructor Details
-
ScriptRuntime
public ScriptRuntime()
-
-
Method Details
-
importModule
Imports functionality provided by aScriptModule
into the globals of this runtime.- Parameters:
scriptModule
- the module to import
-
createNestedEnvironment
Creates a nested environment with the previous environment as its parent. This can be utilized, for example, when entering a new block of code.- Returns:
- an
EnvironmentHandle
to the previous environment
-
restoreEnvironment
Restores an environment utilizing itsEnvironmentHandle
. This can be utilized, for example, when existing a block of code.- Parameters:
handle
- theEnvironmentHandle
to restore the environment to
-
scopes
Gets theScopeTable
for the runtime so it can be updated with local variable resolutions.- Returns:
- the
ScopeTable
for the runtime
-
defineVariable
Defines a variable with desired value in the current environment.- Parameters:
name
- the name of the variablevalue
- the value for the variable
-
defineConstant
Defines a constant with desired value in the current environment.- Parameters:
name
- the name of the constantvalue
- the value for the constant
-
lookUpVariable
Looks up a variable's value utilizing the variable resolutions in theScopeTable
for the runtime.If there is not a scope resolution for the expression then it will be retrieved as a global.
- Parameters:
expr
- theExpr.Variable
to get the value for- Returns:
- the variable's value
-
assignVariable
Assigns a variable's value utilizing the variable resolutions in theScopeTable
for the runtime.If there is not a scope resolution for the expression then it will be assigned as a global.
- Parameters:
expr
- theExpr.Assign
expressionvalue
- the value to assign to the variable
-