Class Lambda
java.lang.Object
org.jfuncmachine.compiler.model.SourceElement
org.jfuncmachine.compiler.model.expr.Expression
org.jfuncmachine.compiler.model.expr.Lambda
A lambda (anonymous function) expression
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal ExpressionThe body of the lambdafinal StringThe name of the method in the lambda's interfacefinal TypeThe type of the interface representing the lambdafinal Field[]The lambda parametersType[]The types of the lambda parametersfinal TypeThe return type of the lambdafinal booleanIf true, the interface describing this lambda should use objects instead of native types.Fields inherited from class org.jfuncmachine.compiler.model.SourceElement
filename, lineNumber -
Constructor Summary
ConstructorsConstructorDescriptionLambda(Field[] parameters, Type returnType, boolean useObjectInterface, Expression body) Create a lambda expressionLambda(Field[] parameters, Type returnType, boolean useObjectInterface, Expression body, String filename, int lineNumber) Create a lambda expressionLambda(Field[] parameters, Type returnType, Expression body) Create a lambda expressionLambda(Field[] parameters, Type returnType, Expression body, String filename, int lineNumber) Create a lambda expressionLambda(Type interfaceType, String interfaceMethodName, Field[] parameters, Type returnType, boolean useObjectInterface, Expression body) Create a lambda expressionLambda(Type interfaceType, String interfaceMethodName, Field[] parameters, Type returnType, boolean useObjectInterface, Expression body, String filename, int lineNumber) Create a lambda expressionLambda(Type interfaceType, String interfaceMethodName, Field[] parameters, Type returnType, Expression body) Create a lambda expressionLambda(Type interfaceType, String interfaceMethodName, Field[] parameters, Type returnType, Expression body, String filename, int lineNumber) Create a lambda expression -
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
-
parameters
The lambda parameters -
body
The body of the lambda -
returnType
The return type of the lambda -
interfaceType
The type of the interface representing the lambda -
interfaceMethodName
The name of the method in the lambda's interface -
parameterTypes
The types of the lambda parameters -
useObjectInterface
public final boolean useObjectInterfaceIf true, the interface describing this lambda should use objects instead of native types. This allows it to be compatible with the java.util.function package
-
-
Constructor Details
-
Lambda
Create a lambda expression- Parameters:
parameters- The lambda parameters and their typesreturnType- The lambda return typebody- The body of the lambda
-
Lambda
public Lambda(Field[] parameters, Type returnType, Expression body, String filename, int lineNumber) Create a lambda expression- Parameters:
parameters- The lambda parameters and their typesreturnType- The lambda return typebody- The body of the lambdafilename- The source filename this expression is associated withlineNumber- The source line number this expression is associated with
-
Lambda
public Lambda(Type interfaceType, String interfaceMethodName, Field[] parameters, Type returnType, Expression body) Create a lambda expression- Parameters:
interfaceType- The type of the lambda interfaceinterfaceMethodName- The name of the interface method to generateparameters- The lambda parameters and their typesreturnType- The lambda return typebody- The body of the lambda
-
Lambda
public Lambda(Type interfaceType, String interfaceMethodName, Field[] parameters, Type returnType, Expression body, String filename, int lineNumber) Create a lambda expression- Parameters:
interfaceType- The type of the lambda interfaceinterfaceMethodName- The name of the interface method to generateparameters- The lambda parameters and their typesreturnType- The lambda return typebody- The body of the lambdafilename- The source filename this expression is associated withlineNumber- The source line number this expression is associated with
-
Lambda
Create a lambda expression- Parameters:
parameters- The lambda parameters and their typesreturnType- The lambda return typeuseObjectInterface- If true, the lambda interface should not use native typesbody- The body of the lambda
-
Lambda
public Lambda(Field[] parameters, Type returnType, boolean useObjectInterface, Expression body, String filename, int lineNumber) Create a lambda expression- Parameters:
parameters- The lambda parameters and their typesreturnType- The lambda return typeuseObjectInterface- If true, the lambda interface should not use native typesbody- The body of the lambdafilename- The source filename this expression is associated withlineNumber- The source line number this expression is associated with
-
Lambda
public Lambda(Type interfaceType, String interfaceMethodName, Field[] parameters, Type returnType, boolean useObjectInterface, Expression body) Create a lambda expression- Parameters:
interfaceType- The type of the lambda interfaceinterfaceMethodName- The name of the interface method to generateparameters- The lambda parameters and their typesreturnType- The lambda return typeuseObjectInterface- If true, the lambda interface should not use native typesbody- The body of the lambda
-
Lambda
public Lambda(Type interfaceType, String interfaceMethodName, Field[] parameters, Type returnType, boolean useObjectInterface, Expression body, String filename, int lineNumber) Create a lambda expression- Parameters:
interfaceType- The type of the lambda interfaceinterfaceMethodName- The name of the interface method to generateparameters- The lambda parameters and their typesreturnType- The lambda return typeuseObjectInterface- If true, the lambda interface should not use native typesbody- The body of the lambdafilename- 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
-