Skip to content

Commit

Permalink
unwarper: Improve logic for an unconditional warp within an expression
Browse files Browse the repository at this point in the history
It actually could be negative as well as positive, so we can guess
an operator correctly.
  • Loading branch information
Andrian Nord authored and Andrian Nord committed Jan 21, 2014
1 parent 7a54f60 commit 1c00ace
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions ljd/ast/unwarper.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,16 +539,22 @@ def _unwarp_expression(body, end, true, false):
last = _invert(last.warp.condition)
else:
last = last.warp.condition

parts.append(last)
else:
assert isinstance(last.warp, nodes.UnconditionalWarp)

last = _get_last_assignment_source(last)
src = _get_last_assignment_source(last)

if src is None:
src = nodes.Primitive()

if last is None:
last = nodes.Primitive()
last.type = nodes.Primitive.T_FALSE
if last.warp.target == true:
src.type = nodes.Primitive.T_TRUE
else:
src.type = nodes.Primitive.T_FALSE

parts.append(last)
parts.append(src)

return parts

Expand Down Expand Up @@ -577,10 +583,12 @@ def _get_operator(block, true, end):
is_true = src.value != 0
elif isinstance(src, nodes.BinaryOperator):
is_true = True
elif isinstance(src, nodes.Primitive):
is_true = src.type == nodes.Primitive.T_TRUE
else:
assert isinstance(src, nodes.Primitive)
assert src is None

is_true = src.type == nodes.Primitive.T_TRUE
is_true = block.warp.target == true

if is_true:
return binop.T_LOGICAL_OR
Expand Down

0 comments on commit 1c00ace

Please sign in to comment.