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 TypeMethodDescriptionvoidassignVariable(Expr.Assign expr, @Nullable Object value) Assigns a variable's value utilizing the variable resolutions in theScopeTablefor the runtime.Creates a nested environment with the previous environment as its parent.voiddefineConstant(String name, @Nullable Object value) Defines a constant with desired value in the current environment.voiddefineVariable(String name, @Nullable Object value) Defines a variable with desired value in the current environment.voidimportModule(ScriptModule scriptModule) Imports functionality provided by aScriptModuleinto the globals of this runtime.@Nullable ObjectlookUpVariable(Expr.Variable expr) Looks up a variable's value utilizing the variable resolutions in theScopeTablefor the runtime.voidrestoreEnvironment(EnvironmentHandle handle) Restores an environment utilizing itsEnvironmentHandle.scopes()Gets theScopeTablefor the runtime so it can be updated with local variable resolutions.
-
Constructor Details
-
ScriptRuntime
public ScriptRuntime()
-
-
Method Details
-
importModule
Imports functionality provided by aScriptModuleinto 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
EnvironmentHandleto the previous environment
-
restoreEnvironment
Restores an environment utilizing itsEnvironmentHandle. This can be utilized, for example, when existing a block of code.- Parameters:
handle- theEnvironmentHandleto restore the environment to
-
scopes
Gets theScopeTablefor the runtime so it can be updated with local variable resolutions.- Returns:
- the
ScopeTablefor 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 theScopeTablefor the runtime.If there is not a scope resolution for the expression then it will be retrieved as a global.
- Parameters:
expr- theExpr.Variableto get the value for- Returns:
- the variable's value
-
assignVariable
Assigns a variable's value utilizing the variable resolutions in theScopeTablefor the runtime.If there is not a scope resolution for the expression then it will be assigned as a global.
- Parameters:
expr- theExpr.Assignexpressionvalue- the value to assign to the variable
-