Closed GoogleCodeExporter closed 8 years ago
Attached is a patch to tinypy r143 which fixes the issues with the logical
operators
and/or/not. Changes:
* renamed the arithmetic AND/OR/NOT opcodes and the tp_and/tp_or/tp_xor functions to
BITAND/BITOR/BITNOT and tp_bitwise_and/or/xor, to make it clear that they are
not
logical operators.
* added a new IFN opcode, which is the inverse of the existing IF opcode.
* added a new NOT opcode, which uses tp_bool() to determine the truthiness of the
operand and inverts it.
* changed the bytecode generated for logical and/or to evaluate the left-hand
expression, check it for truthiness (using IF for and, IFN for or) and skip
evaluating the right-hand expression if needed [short-circuited]. The return
value
of 'expr_a AND expr_b' is either expr_a or expr_b (not a logical 0 or 1), just
like
in bigpy.
* changed the bytecode generated for logical not to use the new NOT opcode.
* exposed the internal tp_bool() function as the builtin 'bool'.
The behaviour of logical and/or/not is now consistent with both what is
expected and
with bigpy.
Original comment by kiwid...@gmail.com
on 9 Apr 2009 at 10:27
Attachments:
I have verified this Issue and have merged kiwidrew's patch. plus, in
tinypy/tests.py, following line:
system(TINYPY+fname+' > tmp.txt')
is not right, since when running tests.py, the working directory is
$(TOPDIR)/tinypy/, while TINYPY is defined as './tinypy'. It should be changed
to
right path of executable tinypy. Thus, I changed this statement as:
system("../build/tinypy "+fname+' > tmp.txt')
Maybe there's better way around this problem.
Some test cases is added in tests.py.
Original comment by ybc2084@gmail.com
on 12 May 2009 at 4:28
Original issue reported on code.google.com by
kiwid...@gmail.com
on 8 Apr 2009 at 12:15