Class VariableImplementor

java.lang.Object
ai.timefold.jpyinterpreter.implementors.VariableImplementor

public class VariableImplementor extends Object
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 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 the instruction argument 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 the instruction argument.
    • deleteGlobalVariable

      public static void deleteGlobalVariable(org.objectweb.asm.MethodVisitor methodVisitor, String className, PythonCompiledFunction pythonCompiledFunction, PythonBytecodeInstruction instruction)
      Deletes the global variable or parameter indicated by the instruction argument.
    • loadGlobalVariable

      public static void loadGlobalVariable(FunctionMetadata functionMetadata, StackMetadata stackMetadata, int globalIndex, PythonLikeType globalType)
      Loads the global variable or parameter indicated by the instruction argument 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 the instruction argument.
    • deleteLocalVariable

      public static void deleteLocalVariable(org.objectweb.asm.MethodVisitor methodVisitor, PythonBytecodeInstruction instruction, LocalVariableHelper localVariableHelper)
      Deletes the local variable or parameter indicated by the instruction argument.
    • getCellIndex

      public static int getCellIndex(FunctionMetadata functionMetadata, int instructionArg)
    • createCell

      public static void createCell(org.objectweb.asm.MethodVisitor methodVisitor, LocalVariableHelper localVariableHelper, int cellIndex)
      Loads the cell indicated by the instruction argument onto the stack. This is used by VariableOpDescriptor.LOAD_CLOSURE when creating a closure for a dependent function.
    • setupFreeVariableCell

      public static void setupFreeVariableCell(org.objectweb.asm.MethodVisitor methodVisitor, String internalClassName, LocalVariableHelper localVariableHelper, int cellIndex)
      Moves the cellIndex free variable (stored in the PythonBytecodeToJavaBytecodeTranslator.CELLS_INSTANCE_FIELD_NAME field to its corresponding local variable.
    • loadCell

      public static void loadCell(FunctionMetadata functionMetadata, StackMetadata stackMetadata, int cellIndex)
      Loads the cell indicated by the instruction argument onto the stack. This is used by VariableOpDescriptor.LOAD_CLOSURE when 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 the instruction argument onto the stack. (which is an PythonCell, 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 the instruction argument (which is an PythonCell, 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 the instruction argument (which is an PythonCell, so changes in the parent function affect the variable in dependent functions).