Class MethodDef

java.lang.Object
org.jfuncmachine.compiler.model.SourceElement
org.jfuncmachine.compiler.model.MethodDef
Direct Known Subclasses:
ConstructorDef, StaticInitializerDef

public class MethodDef extends SourceElement
Defines a method, which has zero or more parameters, a return type and a single expression
  • Field Details

    • name

      public final String name
      The name of the method
    • access

      public final int access
      The access flags of the method (e.g. Access.PUBLIC + Access.STATIC)
    • parameters

      public final Field[] parameters
      The name and type of each parameter
    • body

      public Expression body
      The expression that this method executes
    • returnType

      public final Type returnType
      The return type of the method
    • startLabel

      public final Label startLabel
      A label pointing to the start of the method
    • isTailCallable

      public final boolean isTailCallable
      If true, this method can be called using the tail call elimination mechanism implemented by JFuncMachine
    • numCapturedParameters

      public int numCapturedParameters
      Used by Lambda to indicate how many method parameters were captured from the lambda environment. This allows the Recur method to know how many parameters to expect and how to call the lambda function properly.
    • isLambda

      public final boolean isLambda
      True if this method def is for a lambda
  • Constructor Details

    • MethodDef

      public MethodDef(String name, int access, Field[] parameters, Type returnType, Expression body)
      Create a method definition
      Parameters:
      name - The name of the method
      access - The access flags of the method
      parameters - The name and type of each parameter
      returnType - The return type of the method
      body - The expression that this method executes
    • MethodDef

      public MethodDef(String name, int access, Field[] parameters, Type returnType, Expression body, String filename, int lineNumber)
      Create a method definition
      Parameters:
      name - The name of the method
      access - The access flags of the method
      parameters - The name and type of each parameter
      returnType - The return type of the method
      body - The expression that this method executes
      filename - The name of the source file this method is defined in
      lineNumber - The line number in the source file where this method definition starts
    • MethodDef

      public MethodDef(String name, int access, Field[] parameters, Type returnType, Expression body, boolean isLambda, String filename, int lineNumber)
      Create a method definition
      Parameters:
      name - The name of the method
      access - The access flags of the method
      parameters - The name and type of each parameter
      returnType - The return type of the method
      body - The expression that this method executes
      isLambda - True if this method def is for a lambda function
      filename - The name of the source file this method is defined in
      lineNumber - The line number in the source file where this method definition starts
    • MethodDef

      public MethodDef(String name, int access, Field[] parameters, Type returnType, boolean isTailCallable, Expression body)
      Create a method definition
      Parameters:
      name - The name of the method
      access - The access flags of the method
      parameters - The name and type of each parameter
      returnType - The return type of the method
      isTailCallable - If true, this method can be called using JFuncMachine's tail call optimization
      body - The expression that this method executes
    • MethodDef

      public MethodDef(String name, int access, Field[] parameters, Type returnType, boolean isTailCallable, Expression body, String filename, int lineNumber)
      Create a method definition
      Parameters:
      name - The name of the method
      access - The access flags of the method
      parameters - The name and type of each parameter
      returnType - The return type of the method
      isTailCallable - If true, this method can be called using JFuncMachine's tail call optimization
      body - The expression that this method executes
      filename - The name of the source file this method is defined in
      lineNumber - The line number in the source file where this method definition starts
  • Method Details

    • getTailCallVersion

      public MethodDef getTailCallVersion()
      Returns a version of this method that can be called from the JFuncMachines tail call optimization
      Returns:
      A tail-callable version of this method
    • getReturnType

      public Type getReturnType()
      Gets the return type of this method
      Returns:
      The return type of this method
    • reset

      public void reset()
      Resets this method back to its original state so it can be regenerated (clears data that was created during code generation)