Class VariableImplementor
java.lang.Object
ai.timefold.jpyinterpreter.implementors.VariableImplementor
Implementations of local variable manipulation opcodes.
See https://tenthousandmeters.com/blog/python-behind-the-scenes-5-how-variables-are-implemented-in-cpython/
for a detailed explanation of the differences between LOAD_FAST, LOAD_GLOBAL, LOAD_DEREF, etc.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcreateCell(org.objectweb.asm.MethodVisitor methodVisitor, LocalVariableHelper localVariableHelper, int cellIndex) Loads the cell indicated by theinstructionargument onto the stack.static voiddeleteCellVariable(FunctionMetadata functionMetadata, StackMetadata stackMetadata, int cellIndex) Deletes the cell variable or parameter indicated by theinstructionargument (which is anPythonCell, so changes in the parent function affect the variable in dependent functions).static voiddeleteGlobalVariable(org.objectweb.asm.MethodVisitor methodVisitor, String className, PythonCompiledFunction pythonCompiledFunction, PythonBytecodeInstruction instruction) Deletes the global variable or parameter indicated by theinstructionargument.static voiddeleteLocalVariable(org.objectweb.asm.MethodVisitor methodVisitor, PythonBytecodeInstruction instruction, LocalVariableHelper localVariableHelper) Deletes the local variable or parameter indicated by theinstructionargument.static intgetCellIndex(FunctionMetadata functionMetadata, int instructionArg) static voidloadCell(FunctionMetadata functionMetadata, StackMetadata stackMetadata, int cellIndex) Loads the cell indicated by theinstructionargument onto the stack.static voidloadCellVariable(FunctionMetadata functionMetadata, StackMetadata stackMetadata, int cellIndex) Loads the cell variable/free variable indicated by theinstructionargument onto the stack.static voidloadGlobalVariable(FunctionMetadata functionMetadata, StackMetadata stackMetadata, int globalIndex, PythonLikeType globalType) Loads the global variable or parameter indicated by theinstructionargument onto the stack.static voidloadLocalVariable(org.objectweb.asm.MethodVisitor methodVisitor, PythonBytecodeInstruction instruction, LocalVariableHelper localVariableHelper) Loads the local variable or parameter indicated by theinstructionargument onto the stack.static voidsetupFreeVariableCell(org.objectweb.asm.MethodVisitor methodVisitor, String internalClassName, LocalVariableHelper localVariableHelper, int cellIndex) Moves thecellIndexfree variable (stored in thePythonBytecodeToJavaBytecodeTranslator.CELLS_INSTANCE_FIELD_NAMEfield to its corresponding local variable.static voidstoreInCellVariable(FunctionMetadata functionMetadata, StackMetadata stackMetadata, int cellIndex) Stores TOS into the cell variable or parameter indicated by theinstructionargument (which is anPythonCell, so changes in the parent function affect the variable in dependent functions).static voidstoreInGlobalVariable(org.objectweb.asm.MethodVisitor methodVisitor, String className, PythonCompiledFunction pythonCompiledFunction, PythonBytecodeInstruction instruction) Stores TOS into the global variable or parameter indicated by theinstructionargument.static voidstoreInLocalVariable(org.objectweb.asm.MethodVisitor methodVisitor, PythonBytecodeInstruction instruction, LocalVariableHelper localVariableHelper) Stores TOS into the local variable or parameter indicated by theinstructionargument.
-
Constructor Details
-
VariableImplementor
public VariableImplementor()
-
-
Method Details
-
loadLocalVariable
public static void loadLocalVariable(org.objectweb.asm.MethodVisitor methodVisitor, PythonBytecodeInstruction instruction, LocalVariableHelper localVariableHelper) Loads the local variable or parameter indicated by theinstructionargument onto the stack. -
storeInLocalVariable
public static void storeInLocalVariable(org.objectweb.asm.MethodVisitor methodVisitor, PythonBytecodeInstruction instruction, LocalVariableHelper localVariableHelper) Stores TOS into the local variable or parameter indicated by theinstructionargument. -
deleteGlobalVariable
public static void deleteGlobalVariable(org.objectweb.asm.MethodVisitor methodVisitor, String className, PythonCompiledFunction pythonCompiledFunction, PythonBytecodeInstruction instruction) Deletes the global variable or parameter indicated by theinstructionargument. -
loadGlobalVariable
public static void loadGlobalVariable(FunctionMetadata functionMetadata, StackMetadata stackMetadata, int globalIndex, PythonLikeType globalType) Loads the global variable or parameter indicated by theinstructionargument onto the stack. -
storeInGlobalVariable
public static void storeInGlobalVariable(org.objectweb.asm.MethodVisitor methodVisitor, String className, PythonCompiledFunction pythonCompiledFunction, PythonBytecodeInstruction instruction) Stores TOS into the global variable or parameter indicated by theinstructionargument. -
deleteLocalVariable
public static void deleteLocalVariable(org.objectweb.asm.MethodVisitor methodVisitor, PythonBytecodeInstruction instruction, LocalVariableHelper localVariableHelper) Deletes the local variable or parameter indicated by theinstructionargument. -
getCellIndex
-
createCell
public static void createCell(org.objectweb.asm.MethodVisitor methodVisitor, LocalVariableHelper localVariableHelper, int cellIndex) Loads the cell indicated by theinstructionargument onto the stack. This is used byVariableOpDescriptor.LOAD_CLOSUREwhen creating a closure for a dependent function. -
setupFreeVariableCell
public static void setupFreeVariableCell(org.objectweb.asm.MethodVisitor methodVisitor, String internalClassName, LocalVariableHelper localVariableHelper, int cellIndex) Moves thecellIndexfree variable (stored in thePythonBytecodeToJavaBytecodeTranslator.CELLS_INSTANCE_FIELD_NAMEfield to its corresponding local variable. -
loadCell
public static void loadCell(FunctionMetadata functionMetadata, StackMetadata stackMetadata, int cellIndex) Loads the cell indicated by theinstructionargument onto the stack. This is used byVariableOpDescriptor.LOAD_CLOSUREwhen creating a closure for a dependent function. -
loadCellVariable
public static void loadCellVariable(FunctionMetadata functionMetadata, StackMetadata stackMetadata, int cellIndex) Loads the cell variable/free variable indicated by theinstructionargument onto the stack. (which is anPythonCell, so it can see changes from the parent function). -
storeInCellVariable
public static void storeInCellVariable(FunctionMetadata functionMetadata, StackMetadata stackMetadata, int cellIndex) Stores TOS into the cell variable or parameter indicated by theinstructionargument (which is anPythonCell, so changes in the parent function affect the variable in dependent functions). -
deleteCellVariable
public static void deleteCellVariable(FunctionMetadata functionMetadata, StackMetadata stackMetadata, int cellIndex) Deletes the cell variable or parameter indicated by theinstructionargument (which is anPythonCell, so changes in the parent function affect the variable in dependent functions).
-