Class CallMethod
java.lang.Object
org.jfuncmachine.compiler.model.SourceElement
org.jfuncmachine.compiler.model.expr.Expression
org.jfuncmachine.compiler.model.expr.CallMethod
An expression to invoke a method.
This method differs from the methods in the javainterop package in that it can apply certain optimizations.
For example, if this method call is a recursive call to the method currently being defined, and the
localTailCallsToLoops option is true, this expression updates the local variables representing the
method parameters and jumps back to the beginning of the method.
Likewise, if full tail recursion is enabled, this method should be used for any methods generated by
JFuncMachine so it can implement the looping necessary to handle full tail calls.
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal Expression[]The method argument valuesfinal StringThe name of the class containing the methodfinal StringThe name of the method to callfinal Type[]The types of the method argumentsfinal TypeThe return type of the methodfinal ExpressionThe object to call the method onFields inherited from class org.jfuncmachine.compiler.model.SourceElement
filename, lineNumber -
Constructor Summary
ConstructorsConstructorDescriptionCallMethod(String className, String name, Type[] parameterTypes, Type returnType, Expression target, Expression[] arguments) Create a new method call expressionCallMethod(String className, String name, Type[] parameterTypes, Type returnType, Expression target, Expression[] arguments, String filename, int lineNumber) Create a new method call expressionCallMethod(String name, Type[] parameterTypes, Type returnType, Expression target, Expression[] arguments) Create a new method call expressionCallMethod(String name, Type[] parameterTypes, Type returnType, Expression target, Expression[] arguments, String filename, int lineNumber) Create a new method call expressionCallMethod(Type[] parameterTypes, Type returnType, Expression target, Expression[] arguments) Create a new method call expression that calls the current method recursivelyCallMethod(Type[] parameterTypes, Type returnType, Expression target, Expression[] arguments, String filename, int lineNumber) Create a new method call expression that calls the current method recursively -
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
-
className
The name of the class containing the method -
name
The name of the method to call -
target
The object to call the method on -
arguments
The method argument values -
parameterTypes
The types of the method arguments -
returnType
The return type of the method
-
-
Constructor Details
-
CallMethod
public CallMethod(String className, String name, Type[] parameterTypes, Type returnType, Expression target, Expression[] arguments) Create a new method call expression- Parameters:
className- The name of the class containing the methodname- The name of the methodparameterTypes- The types of the method parametersreturnType- The return type of the methodtarget- The object to invoke the method onarguments- The method argument values
-
CallMethod
public CallMethod(String className, String name, Type[] parameterTypes, Type returnType, Expression target, Expression[] arguments, String filename, int lineNumber) Create a new method call expression- Parameters:
className- The name of the class containing the methodname- The name of the methodparameterTypes- The types of the method parametersreturnType- The return type of the methodtarget- The object to invoke the method onarguments- The method argument valuesfilename- The source filename this expression is associated withlineNumber- The source line number this expression is associated with
-
CallMethod
public CallMethod(String name, Type[] parameterTypes, Type returnType, Expression target, Expression[] arguments) Create a new method call expression- Parameters:
name- The name of the methodparameterTypes- The types of the method parametersreturnType- The return type of the methodtarget- The object to invoke the method onarguments- The method argument values
-
CallMethod
public CallMethod(Type[] parameterTypes, Type returnType, Expression target, Expression[] arguments) Create a new method call expression that calls the current method recursively- Parameters:
parameterTypes- The types of the method parametersreturnType- The return type of the methodtarget- The object to invoke the method onarguments- The method argument values
-
CallMethod
public CallMethod(String name, Type[] parameterTypes, Type returnType, Expression target, Expression[] arguments, String filename, int lineNumber) Create a new method call expression- Parameters:
name- The name of the methodparameterTypes- The types of the method parametersreturnType- The return type of the methodtarget- The object to invoke the method onarguments- The method argument valuesfilename- The source filename this expression is associated withlineNumber- The source line number this expression is associated with
-
CallMethod
public CallMethod(Type[] parameterTypes, Type returnType, Expression target, Expression[] arguments, String filename, int lineNumber) Create a new method call expression that calls the current method recursively- Parameters:
parameterTypes- The types of the method parametersreturnType- The return type of the methodtarget- The object to invoke the method onarguments- The method argument valuesfilename- 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
-