Skip to content

Commit

Permalink
fix: logical not (#28)
Browse files Browse the repository at this point in the history
Logical not instruction returned 0 if the value was non-zero and the same value otherwise, meaning it always returned 0. We make it return 1 in the second case, so it works as one would expect.
  • Loading branch information
Nirei authored Jan 4, 2025
1 parent b44b879 commit 3b6e05a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def instruction_negate(self, args, bindings):
def instruction_not(self, args, bindings):
((_, target),) = args
old = bindings.resolve(target)
bindings.assign(target, 0 if old else old)
bindings.assign(target, 0 if old else 1)

def instruction_if(self, args, bindings):
for index in range(0, len(args) - 1, 2):
Expand Down
10 changes: 10 additions & 0 deletions tests/not.imp
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,14 @@ main begin
if x do
exit 1
end

push 0
pop x
not x

if x do
exit 0
end

exit 1
end

0 comments on commit 3b6e05a

Please sign in to comment.