Class Binding


public class Binding extends Expression
Bind expressions to variable names, and then execute an expression with those variables available. This is how you assign local variables, other than the ones that are parameters to a function. For example, this expression assigns a value to a variable named foo with a value of 42, and then adds 5 to that value. new Binding(new BindingPair("foo", new IntConstant(42)), Visibility.Separate, new InlineCall(Inlines.IntAdd, GetValue("foo", SimpleTypes.INT), IntConstant(5)))

A binding may contain an optional name that can be used with the BindingRecurse expression to loop back to the beginning of the binding, updating the bound variables. This is one way to simulate the functionality of recursive call.

The variables defined by a binding are local variables within the current Java method, but are only visibile within the binding. It is possible to update the value of a local variable using either the BindingRecurse expression, or the SetValue expression.

  • Field Details

    • bindings

      public final Binding.BindingPair[] bindings
      The pairs of variables and expressions in this binding
    • expr

      public final Expression expr
      The expression to be executed in the context of these bindings
    • visibility

      public final Binding.Visibility visibility
      Controls whether binding pairs in this binding can see themselves or the bindings that came before them
    • name

      public final String name
      An optional name that can be used to loop back to the beginning of the binding
  • Constructor Details

    • Binding

      public Binding(Binding.BindingPair[] bindings, Binding.Visibility visibility, Expression expr)
      Create a new binding
      Parameters:
      bindings - The pairs of variable names and the expressions they are bound to
      visibility - Specify how binding pairs are able to see one another
      expr - An expression to execute in the context of this binding
    • Binding

      public Binding(Binding.BindingPair[] bindings, Binding.Visibility visibility, Expression expr, String filename, int lineNumber)
      Create a new binding
      Parameters:
      bindings - The pairs of variable names and the expressions they are bound to
      visibility - Specify how binding pairs are able to see one another
      expr - An expression to execute in the context of this binding
      filename - The source filename this expression is associated with
      lineNumber - The source line number this expression is associated with
    • Binding

      public Binding(String name, Binding.BindingPair[] bindings, Binding.Visibility visibility, Expression expr)
      Create a new binding
      Parameters:
      name - A name for this binding that can be used to create a recursive loop
      bindings - The pairs of variable names and the expressions they are bound to
      visibility - Specify how binding pairs are able to see one another
      expr - An expression to execute in the context of this binding
    • Binding

      public Binding(String name, Binding.BindingPair[] bindings, Binding.Visibility visibility, Expression expr, String filename, int lineNumber)
      Create a new binding
      Parameters:
      name - A name for this binding that can be used to create a recursive loop
      bindings - The pairs of variable names and the expressions they are bound to
      visibility - Specify how binding pairs are able to see one another
      expr - An expression to execute in the context of this binding
      filename - The source filename this expression is associated with
      lineNumber - The source line number this expression is associated with
  • Method Details

    • getType

      public Type getType()
      Description copied from class: Expression
      Get the type returned by this expression
      Specified by:
      getType in class Expression
      Returns:
      The type of this expression
    • reset

      public void reset()
      Description copied from class: Expression
      Resets any labels in expressions so that the method can be regenerated
      Overrides:
      reset in class Expression
    • findCaptured

      public void findCaptured(Environment env)
      Description copied from class: Expression
      Search for local variables that would be captured by a lambda. Each expression has its own implementation of this, because each subexpression must be searched.
      Specified by:
      findCaptured in class Expression
      Parameters:
      env - The environment chain to search
    • convertToFullTailCalls

      public Expression convertToFullTailCalls(boolean inTailPosition)
      Description copied from class: Expression
      Converts this expression to one that is compatible with full tail call optimization
      Specified by:
      convertToFullTailCalls in class Expression
      Parameters:
      inTailPosition - True if this expression is called from the tail position
      Returns:
      A version of this expression whose types are compatible with full tail call optimization
    • generate

      public void generate(ClassGenerator generator, Environment env, boolean inTailPosition)
      Description copied from class: Expression
      Generate the bytecode for this expression
      Specified by:
      generate in class Expression
      Parameters:
      generator - The generator for generating instructions and additional declarations
      env - The environment containing the local variables currently visible to this expression
      inTailPosition - True if this expression is being generated from the tail position of the method