Class LambdaBoxContext

All Implemented Interfaces:
Serializable, IBoxContext, IBoxAttachable

public class LambdaBoxContext extends FunctionBoxContext
This context represents the execution of a Lambda. Lambdas are a simpler form of a Function which, unlike UDFs, do not track things like return type, output, etc. Lambdas retain NO reference to the context in which they were created, and do not search scopes outside their local and arguments scope.
See Also:
  • Constructor Details

    • LambdaBoxContext

      public LambdaBoxContext(IBoxContext parent, Lambda function)
      Creates a new execution context with a bounded function instance and parent context
      Parameters:
      parent - The parent context
      function - The Lambda being invoked with this context
    • LambdaBoxContext

      public LambdaBoxContext(IBoxContext parent, Lambda function, ArgumentsScope argumentsScope)
      Creates a new execution context with a bounded function instance and parent context and arguments scope
      Parameters:
      parent - The parent context
      function - The Lambda being invoked with this context
      argumentsScope - The arguments scope for this context
    • LambdaBoxContext

      public LambdaBoxContext(IBoxContext parent, Lambda function, Key functionCalledName, Object[] positionalArguments)
      Creates a new execution context with a bounded function instance and parent context and arguments scope
      Parameters:
      parent - The parent context
      function - The Closure being invoked with this context
      functionCalledName - The name of the function being invoked
      positionalArguments - The arguments scope for this context
    • LambdaBoxContext

      public LambdaBoxContext(IBoxContext parent, Lambda function, Key functionCalledName, Map<Key,Object> namedArguments)
      Creates a new execution context with a bounded function instance and parent context and arguments scope
      Parameters:
      parent - The parent context
      function - The Closure being invoked with this context
      functionCalledName - The name of the function being invoked
      namedArguments - The arguments scope for this context
    • LambdaBoxContext

      public LambdaBoxContext(IBoxContext parent, Lambda function, Key functionCalledName, ArgumentsScope argumentsScope)
      Creates a new execution context with a bounded function instance and parent context and arguments scope
      Parameters:
      parent - The parent context
      function - The Closure being invoked with this context
      functionCalledName - The name of the function being invoked
      argumentsScope - The arguments scope for this context
  • Method Details

    • getVisibleScopes

      public IStruct getVisibleScopes(IStruct scopes, boolean nearby, boolean shallow)
      Description copied from class: BaseBoxContext
      This is mostly for the debugger. It returns all visible scopes from this context.
      Specified by:
      getVisibleScopes in interface IBoxContext
      Overrides:
      getVisibleScopes in class FunctionBoxContext
      Returns:
      A struct containing all contextual and lexically visible scopes
    • isKeyVisibleScope

      public boolean isKeyVisibleScope(Key key, boolean nearby, boolean shallow)
      Check if a key is visible in the current context as a scope name. This allows us to "reserve" known scope names to ensure arguments.foo will always look in the proper arguments scope and never in local.arguments.foo for example
      Specified by:
      isKeyVisibleScope in interface IBoxContext
      Overrides:
      isKeyVisibleScope in class FunctionBoxContext
      Parameters:
      key - The key to check for visibility
      nearby - true, check only scopes that are nearby to the current execution context
      shallow - true, do not delegate to parent or default scope if not found
      Returns:
      True if the key is visible in the current context, else false
    • scopeFindNearby

      public IBoxContext.ScopeSearchResult scopeFindNearby(Key key, IScope defaultScope, boolean shallow, boolean forAssign)
      Search for a variable in "nearby" scopes
      Specified by:
      scopeFindNearby in interface IBoxContext
      Overrides:
      scopeFindNearby in class FunctionBoxContext
      Parameters:
      key - The key to search for
      defaultScope - The default scope to use if the key is not found
      shallow - Whether to search only the "nearby" scopes or all scopes
      forAssign - true, this is for an assignment operation
      Returns:
      The search result
    • getScope

      public IScope getScope(Key name) throws ScopeNotFoundException
      Look for a scope by name
      Specified by:
      getScope in interface IBoxContext
      Overrides:
      getScope in class FunctionBoxContext
      Parameters:
      name - The name of the scope to look for
      Returns:
      The scope reference to use
      Throws:
      ScopeNotFoundException - If the scope was not found in any context
    • getScopeNearby

      public IScope getScopeNearby(Key name, boolean shallow) throws ScopeNotFoundException
      Look for a "nearby" scope by name
      Specified by:
      getScopeNearby in interface IBoxContext
      Overrides:
      getScopeNearby in class FunctionBoxContext
      Parameters:
      name - The name of the scope to look for
      shallow - true, do not delegate to parent or default scope if not found
      Returns:
      The scope reference to use
      Throws:
      ScopeNotFoundException - If the scope was not found in any context
    • scopeFind

      public IBoxContext.ScopeSearchResult scopeFind(Key key, IScope defaultScope, boolean forAssign)
      Description copied from class: FunctionBoxContext
      Search for a variable in scopes
      Specified by:
      scopeFind in interface IBoxContext
      Overrides:
      scopeFind in class FunctionBoxContext
      Parameters:
      key - The key to search for
      defaultScope - The default scope to use if the key is not found
      forAssign - true, this is for an assignment operation
      Returns:
      The search result
    • getFunction

      public Lambda getFunction()
      Returns the function being invoked with this context, cast as a Lambda
      Overrides:
      getFunction in class FunctionBoxContext
    • getDefaultAssignmentScope

      public IScope getDefaultAssignmentScope()
      Get the default variable assignment scope for this context
      Specified by:
      getDefaultAssignmentScope in interface IBoxContext
      Overrides:
      getDefaultAssignmentScope in class FunctionBoxContext
      Returns:
      The scope reference to use