Skip to content

Commit

Permalink
fix a bug with ʌ SKIP involving truthiness
Browse files Browse the repository at this point in the history
  • Loading branch information
bigyihsuan committed Jun 16, 2020
1 parent b2d7313 commit fb6108a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,14 @@ def evaluate(lex, lab, debugmode, unvoiced, voiced, executionStack, currentStack
if lex[ep].lexeme == "ʟ": # Unconditional jump
ep = lab[lex[ep+1].lexeme]
elif lex[ep].lexeme == "ʌ": # Conditional skip
ele = currentStack.pop()
truthy = ele != 0 or ele != "" or ele != []
truthy = False
con = currentStack.pop()
if type(con) in [int, float]:
truthy = con != 0
elif type(con) in [str]:
truthy = con != ""
elif type(con) in [list]:
truthy = con != []

This comment has been minimized.

Copy link
@jfrech

jfrech Jun 16, 2020

Is this not equivalent to truthy = con != type(con)(), or even simpler truthy = bool(con)?

ep += 1 if truthy else 0
# loop index getters and setters
elif lex[ep].lexeme == "e":
Expand Down

1 comment on commit fb6108a

@jfrech
Copy link

@jfrech jfrech commented on fb6108a Jun 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In essence, I think this branch is equivalent to

elif lex[p].lexeme == "ʌ":
    ep += bool(currentStack.pop())

Please sign in to comment.