Class CollectionImplementor

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

public class CollectionImplementor extends Object
Implementations of opcodes related to collections (list, tuple, set, dict).
  • Constructor Details

    • CollectionImplementor

      public CollectionImplementor()
  • Method Details

    • iterateIterator

      public static void iterateIterator(org.objectweb.asm.MethodVisitor methodVisitor, int jumpTarget, StackMetadata stackMetadata, FunctionMetadata functionMetadata)
      TOS is an iterator; perform TOS' = next(TOS). If TOS is exhausted (which is indicated when it raises a StopIteration exception), Jump relatively by the instruction argument and pop TOS. Otherwise, leave TOS below TOS' and go to the next instruction. Note: StopIteration does not fill its stack trace, which make it much more efficient than normal exceptions.
    • unpackSequence

      public static void unpackSequence(org.objectweb.asm.MethodVisitor methodVisitor, int toUnpack, LocalVariableHelper localVariableHelper)
      TOS is an iterable; push toUnpack elements from it to the stack (with first item of the iterable as the new TOS). Raise an exception if it does not have exactly toUnpack elements.
    • unpackSequenceWithTail

      public static void unpackSequenceWithTail(org.objectweb.asm.MethodVisitor methodVisitor, int toUnpack, LocalVariableHelper localVariableHelper)
      TOS is an iterable; push toUnpack elements from it to the stack (with first item of the iterable as the new TOS). Below the elements in the stack is a list containing the remaining elements in the iterable (empty if there are none). Raise an exception if it has less than toUnpack elements.
    • buildCollection

      public static void buildCollection(Class<?> collectionType, org.objectweb.asm.MethodVisitor methodVisitor, int itemCount)
      Constructs a collection from the top itemCount on the stack. collectionType MUST implement PythonLikeObject and define a reverseAdd(PythonLikeObject) method. Basically generate the following code:
           CollectionType collection = new CollectionType(itemCount);
           collection.reverseAdd(TOS);
           collection.reverseAdd(TOS1);
           ...
           collection.reverseAdd(TOS(itemCount - 1));
       
      Parameters:
      collectionType - The type of collection to create
      itemCount - The number of items to put into collection from the stack
    • convertListToTuple

      public static void convertListToTuple(org.objectweb.asm.MethodVisitor methodVisitor)
      Convert TOS from a List to a tuple. Basically generates this code
           TOS' = PythonLikeTuple.fromList(TOS);
       
    • buildMap

      public static void buildMap(Class<? extends Map> mapType, org.objectweb.asm.MethodVisitor methodVisitor, int itemCount)
      Constructs a map from the top 2 * itemCount on the stack. mapType MUST implement PythonLikeObject. Basically generate the following code:
           MapType collection = new MapType(itemCount);
           collection.put(TOS1, TOS);
           collection.put(TOS3, TOS2);
           ...
           collection.put(TTOS(2*itemCount - 1), TOS(2*itemCount - 2));
       
      Parameters:
      mapType - The type of map to create
      itemCount - The number of key value pairs to put into map from the stack
    • buildConstKeysMap

      public static void buildConstKeysMap(Class<? extends Map> mapType, org.objectweb.asm.MethodVisitor methodVisitor, int itemCount)
      Constructs a map from the top itemCount + 1 on the stack. TOS is a tuple containing keys; TOS1-TOS(itemCount) are the values mapType MUST implement PythonLikeObject. Basically generate the following code:
           MapType collection = new MapType();
           collection.put(TOS[0], TOS1);
           collection.put(TOS[1], TOS2);
           ...
           collection.put(TOS[itemCount-1], TOS(itemCount));
       
      Parameters:
      mapType - The type of map to create
      itemCount - The number of key value pairs to put into map from the stack
    • containsOperator

      public static void containsOperator(org.objectweb.asm.MethodVisitor methodVisitor, StackMetadata stackMetadata, PythonBytecodeInstruction instruction)
      Implements TOS1 in TOS. TOS must be a collection/object that implement the "__contains__" dunder method.
    • setItem

      public static void setItem(FunctionMetadata functionMetadata, StackMetadata stackMetadata)
      Implements TOS1[TOS] = TOS2. TOS1 must be a collection/object that implement the "__setitem__" dunder method.
    • collectionAdd

      public static void collectionAdd(FunctionMetadata functionMetadata, StackMetadata stackMetadata, PythonBytecodeInstruction instruction)
      Calls collection.add(TOS[i], TOS). TOS[i] remains on stack; TOS is popped. Used to implement list/set comprehensions.
    • collectionAddAll

      public static void collectionAddAll(FunctionMetadata functionMetadata, StackMetadata stackMetadata, PythonBytecodeInstruction instruction)
      Calls collection.addAll(TOS[i], TOS). TOS[i] remains on stack; TOS is popped. Used to build lists/maps.
    • mapPut

      public static void mapPut(FunctionMetadata functionMetadata, StackMetadata stackMetadata, PythonBytecodeInstruction instruction)
      Calls map.put(TOS1[i], TOS1, TOS). TOS1[i] remains on stack; TOS and TOS1 are popped. Used to implement map comprehensions.
    • mapPutAll

      public static void mapPutAll(FunctionMetadata functionMetadata, StackMetadata stackMetadata, PythonBytecodeInstruction instruction)
      Calls map.putAll(TOS[i], TOS). TOS[i] remains on stack; TOS is popped. Used to build maps
    • mapPutAllOnlyIfAllNewElseThrow

      public static void mapPutAllOnlyIfAllNewElseThrow(FunctionMetadata functionMetadata, StackMetadata stackMetadata, PythonBytecodeInstruction instruction)
      Calls map.putAll(TOS1[i], TOS) if TOS does not share any common keys with TOS[i]. If TOS shares common keys with TOS[i], an exception is thrown. TOS1[i] remains on stack; TOS is popped. Used to build maps
    • buildSlice

      public static void buildSlice(FunctionMetadata functionMetadata, StackMetadata stackMetadata, int argCount)