diff --git a/bytecodemanipulation/data/v3_10/instructions/FunctionDefinitionAssembly.py b/bytecodemanipulation/data/v3_10/instructions/FunctionDefinitionAssembly.py index 9f7a0c5..19a7c57 100644 --- a/bytecodemanipulation/data/v3_10/instructions/FunctionDefinitionAssembly.py +++ b/bytecodemanipulation/data/v3_10/instructions/FunctionDefinitionAssembly.py @@ -96,8 +96,6 @@ def rewrite_outer_access(instruction: Instruction): instruction.insert_after([ Instruction(Opcodes.LOAD_FAST, local_variable_buffer), Instruction(Opcodes.LOAD_CONST, instruction.arg_value), - Instruction(Opcodes.ROT_THREE), - Instruction(Opcodes.ROT_THREE), Instruction(Opcodes.STORE_SUBSCR), ]) instruction.change_opcode(Opcodes.NOP) diff --git a/bytecodemanipulation/opcodes/Instruction.py b/bytecodemanipulation/opcodes/Instruction.py index 8c58f68..4aba699 100644 --- a/bytecodemanipulation/opcodes/Instruction.py +++ b/bytecodemanipulation/opcodes/Instruction.py @@ -687,7 +687,7 @@ def get_stack_affect(self) -> typing.Tuple[int, int, int | None]: ): return 1, 1, None - if self.opcode in (Opcodes.STORE_ATTR,): + if self.opcode in (Opcodes.STORE_ATTR, Opcodes.STORE_SUBSCR): return 2, 0, None if self.opcode in ( diff --git a/bytecodemanipulation/standard_library.pyasm b/bytecodemanipulation/standard_library.pyasm index d45703c..070a9ce 100644 --- a/bytecodemanipulation/standard_library.pyasm +++ b/bytecodemanipulation/standard_library.pyasm @@ -57,8 +57,6 @@ NAMESPACE std { MACRO ASSEMBLY list(iterable, code CODE_BLOCK[1]) -> ANY { - CALL ~print(&iterable) -> \ - DEF inner<&iterable>(iter_obj) { LOAD ~list() -> $result diff --git a/tests/test_Assembly.py b/tests/test_Assembly.py index df3069f..a1c932d 100644 --- a/tests/test_Assembly.py +++ b/tests/test_Assembly.py @@ -2028,6 +2028,28 @@ def target(): } RETURN $func() +""") + + self.assertEqual(target(), 10) + + def test_write(self): + @apply_operations + def target(): + assembly(""" +LOAD 0 -> $test + +DEF func() +{ + LOAD 10 -> §test + RETURN §test +} + +CALL ~print(10) -> \\ + +LOAD $func() -> $result +# ASSERT OP ($test == 10) # wont work as we currently cannot write back outside +ASSERT OP ($test == 0) "old implementation limitation lifted?" +RETURN $result """) dis.dis(target) diff --git a/tests/test_StandardLibrary.py b/tests/test_StandardLibrary.py index 3ebb262..3f92164 100644 --- a/tests/test_StandardLibrary.py +++ b/tests/test_StandardLibrary.py @@ -180,21 +180,14 @@ def target(): ) return output - dis.dis(target) - self.assertEqual(target(), [1, 2, 3]) def test_comprehension_list(self): + @apply_operations def target(): l = [1, 2, 3, 4] assembly(""" std:comprehension:list($l, [$value] { OP $value + 1 -> % }) -> % RETURN %""") - mutable = MutableFunction(target) - apply_inline_assemblies(mutable) - mutable.reassign_to_function() - - dis.dis(target) - self.assertEqual(target(), [2, 3, 4, 5])