Class Environment
java.lang.Object
org.jfuncmachine.compiler.classgen.Environment
A map of the local variables available within a method.
Environments can be chained, so that within a method, if there is a block defined that adds local variables
within a particular scope, an environment can be chained to the existing one defining just those variables
added by the block. When the block is no longer in scope, the chained environment is discarded so its variables
are no longer visible.
This class also assists in identifying variables captured by a lambda.
-
Constructor Summary
ConstructorsConstructorDescriptionEnvironment(Environment parent) Create a new environment as the child of an existing environmentEnvironment(MethodDef currentMethodDef) Create a new environment for the current method definition -
Method Summary
Modifier and TypeMethodDescriptionAllocate a new environment variableAllocate an anonymous variable.voidcheckCaptured(String name) Check to see if the named variable is capturedvoidcheckCaptured(String name, Environment headOfCapture) Check to see if a variable has been captured.voidfree(int loc) Free a previously-allocated variable by locationvoidFree a previously allocated variablegetBinding(String key) Retrieves the binding that a particular variable is associated withReturn a set of the variables captured during the analysisReturn the current method being processedRetrieves a variable by namevoidputBinding(String key, Binding binding) Stores the binding associated with a particular variable namevoidStart a capture analysis to find variables captured by a closure
-
Constructor Details
-
Environment
Create a new environment for the current method definition- Parameters:
currentMethodDef- The current method definition
-
Environment
Create a new environment as the child of an existing environment- Parameters:
parent- The parent environment
-
-
Method Details
-
allocate
Allocate a new environment variable- Parameters:
name- The name of the variabletype- The type of the variable- Returns:
- An object containing the name, type and index of the variable
-
allocate
Allocate an anonymous variable.- Parameters:
type- The type of the anonymous variable- Returns:
- An object containing the name, type and index of the variable
-
free
public void free(int loc) Free a previously-allocated variable by location- Parameters:
loc- The location of the variable to release
-
free
Free a previously allocated variable- Parameters:
envVar- The variable to free
-
getVar
Retrieves a variable by name- Parameters:
name- The name of the variable to retrieve- Returns:
- An object containing the name, type, and index of the variable
-
putBinding
Stores the binding associated with a particular variable name- Parameters:
key- The variable name associated with the bindingbinding- The binding the key is associated with
-
getBinding
Retrieves the binding that a particular variable is associated with- Parameters:
key- The variable name to look up- Returns:
- The binding associated with the variable identified by key
-
getCurrentMethod
Return the current method being processed- Returns:
- The current method being processed
-
startCaptureAnalysis
public void startCaptureAnalysis()Start a capture analysis to find variables captured by a closure -
getCaptured
Return a set of the variables captured during the analysis- Returns:
- A set containing the values identified as captured
-
checkCaptured
Check to see if the named variable is captured- Parameters:
name- The name to check
-
checkCaptured
Check to see if a variable has been captured. This version of checkCaptured is above the head of capture, so any variables checked are definitely captured, so they are added to the capture list in the headOfCapture environment- Parameters:
name- The variable name to checkheadOfCapture- The environment that contains the list of captured variables
-