Class CollectionImplementor
java.lang.Object
ai.timefold.jpyinterpreter.implementors.CollectionImplementor
Implementations of opcodes related to collections (list, tuple, set, dict).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidbuildCollection(Class<?> collectionType, org.objectweb.asm.MethodVisitor methodVisitor, int itemCount) Constructs a collection from the topitemCounton the stack.static voidbuildConstKeysMap(Class<? extends Map> mapType, org.objectweb.asm.MethodVisitor methodVisitor, int itemCount) Constructs a map from the topitemCount + 1on the stack.static voidbuildMap(Class<? extends Map> mapType, org.objectweb.asm.MethodVisitor methodVisitor, int itemCount) Constructs a map from the top2 * itemCounton the stack.static voidbuildSlice(FunctionMetadata functionMetadata, StackMetadata stackMetadata, int argCount) static voidcollectionAdd(FunctionMetadata functionMetadata, StackMetadata stackMetadata, PythonBytecodeInstruction instruction) Calls collection.add(TOS[i], TOS).static voidcollectionAddAll(FunctionMetadata functionMetadata, StackMetadata stackMetadata, PythonBytecodeInstruction instruction) Calls collection.addAll(TOS[i], TOS).static voidcontainsOperator(org.objectweb.asm.MethodVisitor methodVisitor, StackMetadata stackMetadata, PythonBytecodeInstruction instruction) Implements TOS1 in TOS.static voidconvertListToTuple(org.objectweb.asm.MethodVisitor methodVisitor) Convert TOS from a List to a tuple.static voiditerateIterator(org.objectweb.asm.MethodVisitor methodVisitor, int jumpTarget, StackMetadata stackMetadata, FunctionMetadata functionMetadata) TOS is an iterator; perform TOS' = next(TOS).static voidmapPut(FunctionMetadata functionMetadata, StackMetadata stackMetadata, PythonBytecodeInstruction instruction) Calls map.put(TOS1[i], TOS1, TOS).static voidmapPutAll(FunctionMetadata functionMetadata, StackMetadata stackMetadata, PythonBytecodeInstruction instruction) Calls map.putAll(TOS[i], TOS).static voidmapPutAllOnlyIfAllNewElseThrow(FunctionMetadata functionMetadata, StackMetadata stackMetadata, PythonBytecodeInstruction instruction) Calls map.putAll(TOS1[i], TOS) if TOS does not share any common keys with TOS[i].static voidsetItem(FunctionMetadata functionMetadata, StackMetadata stackMetadata) Implements TOS1[TOS] = TOS2.static voidunpackSequence(org.objectweb.asm.MethodVisitor methodVisitor, int toUnpack, LocalVariableHelper localVariableHelper) TOS is an iterable; pushtoUnpackelements from it to the stack (with first item of the iterable as the new TOS).static voidunpackSequenceWithTail(org.objectweb.asm.MethodVisitor methodVisitor, int toUnpack, LocalVariableHelper localVariableHelper) TOS is an iterable; pushtoUnpackelements from it to the stack (with first item of the iterable as the new TOS).
-
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 aStopIterationexception), Jump relatively by the instruction argument and pop TOS. Otherwise, leave TOS below TOS' and go to the next instruction. Note:StopIterationdoes 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; pushtoUnpackelements from it to the stack (with first item of the iterable as the new TOS). Raise an exception if it does not have exactlytoUnpackelements. -
unpackSequenceWithTail
public static void unpackSequenceWithTail(org.objectweb.asm.MethodVisitor methodVisitor, int toUnpack, LocalVariableHelper localVariableHelper) TOS is an iterable; pushtoUnpackelements 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 thantoUnpackelements. -
buildCollection
public static void buildCollection(Class<?> collectionType, org.objectweb.asm.MethodVisitor methodVisitor, int itemCount) Constructs a collection from the topitemCounton the stack.collectionTypeMUST 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 createitemCount- 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 codeTOS' = PythonLikeTuple.fromList(TOS); -
buildMap
public static void buildMap(Class<? extends Map> mapType, org.objectweb.asm.MethodVisitor methodVisitor, int itemCount) Constructs a map from the top2 * itemCounton the stack.mapTypeMUST 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 createitemCount- 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 topitemCount + 1on the stack. TOS is a tuple containing keys; TOS1-TOS(itemCount) are the valuesmapTypeMUST 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 createitemCount- 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
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)
-