Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline increment on non-existing dict keys? #148

Open
phorward opened this issue Dec 28, 2024 · 0 comments
Open

Inline increment on non-existing dict keys? #148

phorward opened this issue Dec 28, 2024 · 0 comments
Labels
bug Something isn't working
Milestone

Comments

@phorward
Copy link
Member

phorward commented Dec 28, 2024

This bug raised within the aoc2024.tok repository, day 1.

Simplest test-case:

d = ()
d[0] = 1
d[0]++
# d[1] = 0  # FIX
d[1]++  # d[1] does not exist!
print(d)  # prints only "(0 => 2)", expected (0 => 2 1 => 1)

The problem is, that Op::LoadItem pushes void, and void is being modified, and afterwards cleared

__main__      ip = 2 state = Ok(Push([578deca8df88] 1 (10)))
__main__      --- Code ---
__main__       000 LoadGlobal(0)
__main__       001 Offset(Offset { offset: 2, row: 1, col: 3 })
__main__       002 Push1
__main__      >003 LoadItem
__main__       004 Offset(Offset { offset: 0, row: 1, col: 1 })
__main__       005 Dup
__main__       006 Swap(2)
__main__       007 UnaryOp("iinc")
__main__       008 Drop
__main__      --- Reader ---
__main__       offset=Offset { offset: 0, row: 1, col: 1 }
__main__       eof=false
__main__      --- Globals ---
__main__       000 Object(Dict { dict: {} })
__main__      --- Stack ---
__main__       000 [578decb12768] () (10)
__main__       001 [578deca8df88] 1 (10)
__main__      --- Frames ---
__main__       000 capture: 0, reader: 0, fuse: None

__main__      ip = 3 state = Ok(Push([578dec8ac9f8] void (10)))
__main__      --- Code ---
__main__       000 LoadGlobal(0)
__main__       001 Offset(Offset { offset: 2, row: 1, col: 3 })
__main__       002 Push1
__main__       003 LoadItem
__main__       004 Offset(Offset { offset: 0, row: 1, col: 1 })
__main__      >005 Dup
__main__       006 Swap(2)
__main__       007 UnaryOp("iinc")
__main__       008 Drop
__main__      --- Reader ---
__main__       offset=Offset { offset: 0, row: 1, col: 1 }
__main__       eof=false
__main__      --- Globals ---
__main__       000 Object(Dict { dict: {} })
__main__      --- Stack ---
__main__       000 [578dec8ac9f8] void (10)
__main__      --- Frames ---
__main__       000 capture: 0, reader: 0, fuse: None
.
.
.
__main__      ip = 7 state = Ok(Push([578dec8ac9f8] 1 (10)))
__main__      --- Code ---
__main__       000 LoadGlobal(0)
__main__       001 Offset(Offset { offset: 2, row: 1, col: 3 })
__main__       002 Push1
__main__       003 LoadItem
__main__       004 Offset(Offset { offset: 0, row: 1, col: 1 })
__main__       005 Dup
__main__       006 Swap(2)
__main__       007 UnaryOp("iinc")
__main__      >008 Drop
__main__      --- Reader ---
__main__       offset=Offset { offset: 0, row: 1, col: 1 }
__main__       eof=false
__main__      --- Globals ---
__main__       000 Object(Dict { dict: {} })
__main__      --- Stack ---
__main__       000 [578deca8df88] void (10)
__main__       001 [578dec8ac9f8] 1 (10)
__main__      --- Frames ---
__main__       000 capture: 0, reader: 0, fuse: None

Generally, the iinc works as expected, but it works with a void value being copied, incremented and dropped. A possible solution would be something like a Op::LoadItemWithDefault that is being used in the iinc code generation.

@phorward phorward added the bug Something isn't working label Dec 28, 2024
@phorward phorward added this to the v0.7 milestone Dec 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant