Class Binding
java.lang.Object
org.jfuncmachine.compiler.model.SourceElement
org.jfuncmachine.compiler.model.expr.Expression
org.jfuncmachine.compiler.model.expr.Binding
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAn association of a variable name with an expression valuestatic enumThe Visibility parameter controls whether or not binding variables are visible to other binding pair expressions within the same binding. -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal Binding.BindingPair[]The pairs of variables and expressions in this bindingfinal ExpressionThe expression to be executed in the context of these bindingsfinal StringAn optional name that can be used to loop back to the beginning of the bindingfinal Binding.VisibilityControls whether binding pairs in this binding can see themselves or the bindings that came before themFields inherited from class org.jfuncmachine.compiler.model.SourceElement
filename, lineNumber -
Constructor Summary
ConstructorsConstructorDescriptionBinding(String name, Binding.BindingPair[] bindings, Binding.Visibility visibility, Expression expr) Create a new bindingBinding(String name, Binding.BindingPair[] bindings, Binding.Visibility visibility, Expression expr, String filename, int lineNumber) Create a new bindingBinding(Binding.BindingPair[] bindings, Binding.Visibility visibility, Expression expr) Create a new bindingBinding(Binding.BindingPair[] bindings, Binding.Visibility visibility, Expression expr, String filename, int lineNumber) Create a new binding -
Method Summary
Modifier and TypeMethodDescriptionconvertToFullTailCalls(boolean inTailPosition) Converts this expression to one that is compatible with full tail call optimizationvoidfindCaptured(Environment env) Search for local variables that would be captured by a lambda.voidgenerate(ClassGenerator generator, Environment env, boolean inTailPosition) Generate the bytecode for this expressiongetType()Get the type returned by this expressionvoidreset()Resets any labels in expressions so that the method can be regeneratedMethods inherited from class org.jfuncmachine.compiler.model.SourceElement
generateException
-
Field Details
-
bindings
The pairs of variables and expressions in this binding -
expr
The expression to be executed in the context of these bindings -
visibility
Controls whether binding pairs in this binding can see themselves or the bindings that came before them -
name
An optional name that can be used to loop back to the beginning of the binding
-
-
Constructor Details
-
Binding
Create a new binding- Parameters:
bindings- The pairs of variable names and the expressions they are bound tovisibility- Specify how binding pairs are able to see one anotherexpr- 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 tovisibility- Specify how binding pairs are able to see one anotherexpr- An expression to execute in the context of this bindingfilename- The source filename this expression is associated withlineNumber- 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 loopbindings- The pairs of variable names and the expressions they are bound tovisibility- Specify how binding pairs are able to see one anotherexpr- 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 loopbindings- The pairs of variable names and the expressions they are bound tovisibility- Specify how binding pairs are able to see one anotherexpr- An expression to execute in the context of this bindingfilename- The source filename this expression is associated withlineNumber- The source line number this expression is associated with
-
-
Method Details
-
getType
Description copied from class:ExpressionGet the type returned by this expression- Specified by:
getTypein classExpression- Returns:
- The type of this expression
-
reset
public void reset()Description copied from class:ExpressionResets any labels in expressions so that the method can be regenerated- Overrides:
resetin classExpression
-
findCaptured
Description copied from class:ExpressionSearch 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:
findCapturedin classExpression- Parameters:
env- The environment chain to search
-
convertToFullTailCalls
Description copied from class:ExpressionConverts this expression to one that is compatible with full tail call optimization- Specified by:
convertToFullTailCallsin classExpression- 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
Description copied from class:ExpressionGenerate the bytecode for this expression- Specified by:
generatein classExpression- Parameters:
generator- The generator for generating instructions and additional declarationsenv- The environment containing the local variables currently visible to this expressioninTailPosition- True if this expression is being generated from the tail position of the method
-