Class ScriptRuntime

java.lang.Object
technology.sola.script.runtime.ScriptRuntime

@NullMarked public class ScriptRuntime extends Object
ScriptRuntime contains environment state information as well as a ScopeTable to keep track of nested scope variable resolutions.
  • Constructor Details

    • ScriptRuntime

      public ScriptRuntime()
  • Method Details

    • importModule

      public void importModule(ScriptModule scriptModule)
      Imports functionality provided by a ScriptModule into the globals of this runtime.
      Parameters:
      scriptModule - the module to import
    • createNestedEnvironment

      public EnvironmentHandle 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

      public void restoreEnvironment(EnvironmentHandle handle)
      Restores an environment utilizing its EnvironmentHandle. This can be utilized, for example, when existing a block of code.
      Parameters:
      handle - the EnvironmentHandle to restore the environment to
    • scopes

      public ScopeTable scopes()
      Gets the ScopeTable for the runtime so it can be updated with local variable resolutions.
      Returns:
      the ScopeTable for the runtime
    • defineVariable

      public void defineVariable(String name, @Nullable Object value)
      Defines a variable with desired value in the current environment.
      Parameters:
      name - the name of the variable
      value - the value for the variable
    • defineConstant

      public void defineConstant(String name, @Nullable Object value)
      Defines a constant with desired value in the current environment.
      Parameters:
      name - the name of the constant
      value - the value for the constant
    • lookUpVariable

      public @Nullable Object lookUpVariable(Expr.Variable expr)
      Looks up a variable's value utilizing the variable resolutions in the ScopeTable for the runtime.

      If there is not a scope resolution for the expression then it will be retrieved as a global.

      Parameters:
      expr - the Expr.Variable to get the value for
      Returns:
      the variable's value
    • assignVariable

      public void assignVariable(Expr.Assign expr, @Nullable Object value)
      Assigns a variable's value utilizing the variable resolutions in the ScopeTable for the runtime.

      If there is not a scope resolution for the expression then it will be assigned as a global.

      Parameters:
      expr - the Expr.Assign expression
      value - the value to assign to the variable