Output 1 instead of -1 on constant true conditions.

The rationale for using -1 was that it had all bits set, but that's a pretty weak argument, really. Lack of optimization of the sign could be worse, so we change it to 1, which is the value of the constant TRUE.

Also change the wording of a comment, for clarity.
This commit is contained in:
Sei Lisa 2017-01-04 00:41:08 +01:00
parent b8a27bbcd2
commit b04df456cb

View file

@ -107,7 +107,7 @@ class foldconst(object):
if nt in ('CONST', 'IDENT', 'FLD'):
if node['nt'] == 'CONST':
node['t'] = 'integer'
node['value'] = -1 if lslfuncs.cond(node['value']) else 0
node['value'] = 1 if lslfuncs.cond(node['value']) else 0
return # Nothing to do if it's already simplified.
child = node['ch'] if 'ch' in node else None
@ -1173,7 +1173,8 @@ class foldconst(object):
# And if there is more than one, these expressions will need a
# new block, which means new scope, which is dangerous.
# They are expressions, no declarations or labels allowed, thus
# no new identifiers, but it still feels uneasy.
# no new identifiers may be created in the new scope, but it
# still feels dodgy.
if child[1]['value']:
# Endless loop. Traverse the loop and the iterator.
self.FoldTree(child, 3)