Skip to content

Commit

Permalink
added write outer local test
Browse files Browse the repository at this point in the history
  • Loading branch information
uuk0 committed Jul 5, 2023
1 parent 046da6c commit a074fa3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion bytecodemanipulation/opcodes/Instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 0 additions & 2 deletions bytecodemanipulation/standard_library.pyasm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions tests/test_Assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<test>()
{
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)
Expand Down
9 changes: 1 addition & 8 deletions tests/test_StandardLibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

0 comments on commit a074fa3

Please sign in to comment.