micropython/py
Nicko van Someren 3aab54bf43 py: Support non-boolean results for equality and inequality tests.
This commit implements a more complete replication of CPython's behaviour
for equality and inequality testing of objects.  This addresses the issues
discussed in #5382 and a few other inconsistencies.  Improvements over the
old code include:

- Support for returning non-boolean results from comparisons (as used by
  numpy and others).
- Support for non-reflexive equality tests.
- Preferential use of __ne__ methods and MP_BINARY_OP_NOT_EQUAL binary
  operators for inequality tests, when available.
- Fallback to op2 == op1 or op2 != op1 when op1 does not implement the
  (in)equality operators.

The scheme here makes use of a new flag, MP_TYPE_FLAG_NEEDS_FULL_EQ_TEST,
in the flags word of mp_obj_type_t to indicate if various shortcuts can or
cannot be used when performing equality and inequality tests.  Currently
four built-in classes have the flag set: float and complex are
non-reflexive (since nan != nan) while bytearray and frozenszet instances
can equal other builtin class instances (bytes and set respectively).  The
flag is also set for any new class defined by the user.

This commit also includes a more comprehensive set of tests for the
behaviour of (in)equality operators implemented in special methods.
2020-01-30 14:53:07 +11:00
..
argcheck.c
asmarm.c py/asmarm: Use __builtin___clear_cache instead of __clear_cache. 2019-07-12 16:48:37 +10:00
asmarm.h py: Add support to save native, viper and asm code to .mpy files. 2019-03-08 15:53:05 +11:00
asmbase.c py: Define EMIT_MACHINE_CODE as EMIT_NATIVE || EMIT_INLINE_ASM. 2019-06-28 13:54:45 +10:00
asmbase.h py/persistentcode: Add ability to relocate loaded native code. 2019-12-12 20:15:28 +11:00
asmthumb.c py/asmthumb: Support asm_thumb code running on normal ARM processors. 2019-05-01 15:24:21 +10:00
asmthumb.h py: Add support to save native, viper and asm code to .mpy files. 2019-03-08 15:53:05 +11:00
asmx64.c py: Add support to save native, viper and asm code to .mpy files. 2019-03-08 15:53:05 +11:00
asmx64.h py: Add support to save native, viper and asm code to .mpy files. 2019-03-08 15:53:05 +11:00
asmx86.c py/asmx86: Remove unused 5th argument facility. 2019-12-27 12:30:51 +11:00
asmx86.h py/asmx86: Remove unused 5th argument facility. 2019-12-27 12:30:51 +11:00
asmxtensa.c py: Add new Xtensa-Windowed arch for native emitter. 2019-10-05 13:44:53 +10:00
asmxtensa.h py/asmxtensa: Add support for Xtensa with windowed registers. 2019-10-05 13:44:08 +10:00
bc.c py/bc: Don't include mp_decode_uint funcs when not needed. 2019-10-01 12:26:22 +10:00
bc.h py/persistentcode: Add ability to relocate loaded native code. 2019-12-12 20:15:28 +11:00
bc0.h py: Split RAISE_VARARGS opcode into 3 separate ones. 2019-09-26 15:39:50 +10:00
binary.c py/binary: Change mp_uint_t to size_t for index, size, align args. 2019-09-02 13:14:27 +10:00
binary.h py/binary: Change mp_uint_t to size_t for index, size, align args. 2019-09-02 13:14:27 +10:00
builtin.h extmod/modbluetooth: Rename module to "ubluetooth". 2019-10-22 21:58:05 +11:00
builtinevex.c py: Downcase all MP_OBJ_IS_xxx macros to make a more consistent C API. 2019-02-12 14:54:51 +11:00
builtinhelp.c py: Make mp_obj_get_type() return a const ptr to mp_obj_type_t. 2020-01-09 11:25:26 +11:00
builtinimport.c py/builtinimport: Raise exception on empty module name. 2019-11-26 00:28:32 +11:00
compile.c py/compile: Coalesce error message for break/continue outside loop. 2019-11-21 12:13:11 +11:00
compile.h py: Add global default_emit_opt variable to make emit kind persistent. 2019-08-28 12:47:58 +10:00
dynruntime.h py/dynruntime: Implement uint new/get, mp_obj_len and mp_obj_subscr. 2019-12-13 13:29:11 +11:00
dynruntime.mk py/dynruntime: Add support for float API to make/get floats. 2019-12-12 20:15:28 +11:00
emit.h py: Add new Xtensa-Windowed arch for native emitter. 2019-10-05 13:44:53 +10:00
emitbc.c py: Remove commented-out debug printf's from emitbc and objlist. 2019-12-20 23:34:46 +11:00
emitcommon.c
emitglue.c py: Integrate sys.settrace feature into the VM and runtime. 2019-08-30 16:44:12 +10:00
emitglue.h py: Integrate sys.settrace feature into the VM and runtime. 2019-08-30 16:44:12 +10:00
emitinlinethumb.c py/compile: Support multiple inline asm emitters. 2019-03-14 12:22:25 +11:00
emitinlinextensa.c py/compile: Support multiple inline asm emitters. 2019-03-14 12:22:25 +11:00
emitnarm.c
emitnative.c py/emitnative: Stop after finding an unwind target. 2020-01-27 13:22:03 +11:00
emitnthumb.c
emitnx64.c
emitnx86.c py/nativeglue: Add new header file with native function table typedef. 2019-12-12 20:15:28 +11:00
emitnxtensa.c
emitnxtensawin.c py: Add new Xtensa-Windowed arch for native emitter. 2019-10-05 13:44:53 +10:00
formatfloat.c
formatfloat.h
frozenmod.c
frozenmod.h various: Update early copyright years to match actual edit history. 2019-05-17 18:06:11 +10:00
gc.c py/gc: Don't include or init gc_mutex when GIL is enabled. 2020-01-23 13:28:42 +11:00
gc.h py/gc: Adjust gc_alloc() signature to be able to accept multiple flags. 2018-12-20 17:52:16 +11:00
grammar.h py: Add support for matmul operator @ as per PEP 465. 2019-09-26 15:12:39 +10:00
lexer.c py: Add support for matmul operator @ as per PEP 465. 2019-09-26 15:12:39 +10:00
lexer.h py: Remove 3 obsolete commented-out lines from header files. 2019-11-26 21:36:41 +11:00
makemoduledefs.py py/makedefs: Use io.open with utf-8 encoding when processing source. 2019-04-12 11:34:52 +10:00
makeqstrdata.py py: Rename MP_QSTR_NULL to MP_QSTRnull to avoid intern collisions. 2019-09-26 16:04:56 +10:00
makeqstrdefs.py py/makeqstrdefs.py: Remove unused blacklist. 2019-10-04 17:18:56 +10:00
makeversionhdr.py py/mpconfig: Move MICROPY_VERSION macros to static ones in mpconfig.h. 2018-12-22 01:40:38 +11:00
malloc.c
map.c py: Downcase MP_xxx_SLOT_IS_FILLED inline functions. 2019-02-12 14:54:51 +11:00
misc.h py/unicode: Add unichar_isalnum(). 2020-01-12 13:03:57 +11:00
mkenv.mk py/mkenv.mk: Move usage of 32-bit flags to py.mk. 2020-01-12 10:34:10 +11:00
mkrules.mk py/mkrules.mk: Add warning/error for invalid frozen config. 2019-10-21 23:21:04 +11:00
modarray.c py/modarray: Rename "array" module to "uarray". 2019-10-22 16:35:46 +11:00
modbuiltins.c py: Clean up commented-out code and comments about exception hierarchy. 2019-12-28 01:01:36 +11:00
modcmath.c
modcollections.c
modgc.c
modio.c py/modio: Call mp_import_name to do resource stream import. 2019-07-31 22:37:44 +10:00
modmath.c py/modmath: Implement math.isclose() for non-complex numbers. 2019-08-17 23:23:17 +10:00
modmicropython.c py/scheduler: Rename sched_stack to sched_queue. 2019-07-17 16:09:32 +10:00
modstruct.c py/binary: Change mp_uint_t to size_t for index, size, align args. 2019-09-02 13:14:27 +10:00
modsys.c py/modsys: Report .mpy version in sys.implementation. 2019-11-04 16:00:41 +11:00
modthread.c py: Downcase MP_xxx_SLOT_IS_FILLED inline functions. 2019-02-12 14:54:51 +11:00
moduerrno.c py: Rename MP_QSTR_NULL to MP_QSTRnull to avoid intern collisions. 2019-09-26 16:04:56 +10:00
mpconfig.h py/mpconfig.h: Define BITS_PER_BYTE only if not already defined. 2020-01-12 20:57:01 +02:00
mperrno.h
mphal.h lib/utils/sys_stdio_mphal: Add support to poll sys.stdin and sys.stdout. 2019-07-01 17:10:12 +10:00
mpprint.c py/mpprint: Support printing %ld and %lu formats on 64-bit archs. 2019-04-23 12:40:15 +10:00
mpprint.h
mpstate.c
mpstate.h py/qstr: Don't include or init qstr_mutex when GIL is enabled. 2020-01-23 13:29:11 +11:00
mpthread.h py/mpthread.h: Use strong type for mp_thread_set_state() argument. 2020-01-29 17:10:32 +11:00
mpz.c
mpz.h
nativeglue.c py/nativeglue: Fix typo about where the native fun table enum is. 2020-01-27 13:22:19 +11:00
nativeglue.h py: Make mp_obj_get_type() return a const ptr to mp_obj_type_t. 2020-01-09 11:25:26 +11:00
nlr.c
nlr.h powerpc: Add initial port to bare metal PowerPC arch. 2019-10-22 22:45:33 +11:00
nlrpowerpc.c powerpc: Add initial port to bare metal PowerPC arch. 2019-10-22 22:45:33 +11:00
nlrsetjmp.c
nlrthumb.c py: Introduce MP_UNREACHABLE macro to annotate unreachable code. 2019-08-19 16:14:33 +10:00
nlrx64.c py/nlr: Use MP_UNREACHABLE at the end of arch-specific nlr_jump funcs. 2019-08-19 16:14:57 +10:00
nlrx86.c py/nlrx86: Silence possible warnings about unused nlr argument. 2019-12-23 00:07:03 +11:00
nlrxtensa.c py/nlr: Use MP_UNREACHABLE at the end of arch-specific nlr_jump funcs. 2019-08-19 16:14:57 +10:00
obj.c py: Support non-boolean results for equality and inequality tests. 2020-01-30 14:53:07 +11:00
obj.h py: Support non-boolean results for equality and inequality tests. 2020-01-30 14:53:07 +11:00
objarray.c py: Support non-boolean results for equality and inequality tests. 2020-01-30 14:53:07 +11:00
objarray.h py/objarray: Introduce "memview_offset" alias for "free" field of object 2018-12-20 17:40:48 +11:00
objattrtuple.c
objbool.c py/obj: Add MICROPY_OBJ_IMMEDIATE_OBJS option to reduce code size. 2020-01-13 01:01:45 +11:00
objboundmeth.c
objcell.c
objclosure.c
objcomplex.c py: Support non-boolean results for equality and inequality tests. 2020-01-30 14:53:07 +11:00
objdeque.c
objdict.c py/objdict: Support ujson.dump() of OrderedDict objects. 2019-11-13 13:51:18 +11:00
objenumerate.c py/objenumerate: Check for valid args in enumerate constructor. 2019-12-09 14:28:24 +11:00
objexcept.c py/objexcept: Optimise mp_obj_new_exception[_arg1/_args] functions. 2020-01-23 13:37:25 +11:00
objexcept.h
objfilter.c py: Downcase all MP_OBJ_IS_xxx macros to make a more consistent C API. 2019-02-12 14:54:51 +11:00
objfloat.c py: Support non-boolean results for equality and inequality tests. 2020-01-30 14:53:07 +11:00
objfun.c py: Make mp_obj_get_type() return a const ptr to mp_obj_type_t. 2020-01-09 11:25:26 +11:00
objfun.h py: Integrate sys.settrace feature into the VM and runtime. 2019-08-30 16:44:12 +10:00
objgenerator.c py/objgenerator: Use mp_obj_new_exception_arg1 to make StopIteration. 2020-01-23 13:37:25 +11:00
objgenerator.h
objgetitemiter.c
objint.c all: Convert nlr_raise(mp_obj_new_exception_msg(x)) to mp_raise_msg(x). 2019-11-05 11:35:45 +11:00
objint.h
objint_longlong.c py: Downcase all MP_OBJ_IS_xxx macros to make a more consistent C API. 2019-02-12 14:54:51 +11:00
objint_mpz.c py/objint: Add mp_obj_int_get_uint_checked() helper. 2020-01-14 23:35:22 +11:00
objlist.c py: Introduce MP_ROM_NONE macro for ROM to refer to None object. 2019-12-27 22:51:17 +11:00
objlist.h
objmap.c py: Downcase all MP_OBJ_IS_xxx macros to make a more consistent C API. 2019-02-12 14:54:51 +11:00
objmodule.c extmod/modbluetooth: Rename module to "ubluetooth". 2019-10-22 21:58:05 +11:00
objmodule.h py: Automatically provide weak links from "foo" to "ufoo" module name. 2019-10-22 15:30:52 +11:00
objnamedtuple.c py: Downcase all MP_OBJ_IS_xxx macros to make a more consistent C API. 2019-02-12 14:54:51 +11:00
objnamedtuple.h
objnone.c py/obj: Add MICROPY_OBJ_IMMEDIATE_OBJS option to reduce code size. 2020-01-13 01:01:45 +11:00
objobject.c py/objobject: Fix __setattr__/__delattr__ to build in nanbox mode. 2019-12-27 22:54:53 +11:00
objpolyiter.c
objproperty.c py: Introduce MP_ROM_NONE macro for ROM to refer to None object. 2019-12-27 22:51:17 +11:00
objrange.c py: Downcase all MP_OBJ_IS_xxx macros to make a more consistent C API. 2019-02-12 14:54:51 +11:00
objreversed.c py: Downcase all MP_OBJ_IS_xxx macros to make a more consistent C API. 2019-02-12 14:54:51 +11:00
objset.c py: Support non-boolean results for equality and inequality tests. 2020-01-30 14:53:07 +11:00
objsingleton.c py/objsingleton: Use mp_generic_unary_op for singleton objects. 2019-12-27 12:53:36 +11:00
objslice.c py/objslice: Inline fetching of slice paramters in str_subscr(). 2019-12-29 00:06:02 +11:00
objstr.c py/obj.h: Add and use mp_obj_is_bool() helper. 2020-01-24 10:53:45 +11:00
objstr.h py/objstr: Don't use inline GET_STR_DATA_LEN for object-repr D. 2019-12-27 23:15:52 +11:00
objstringio.c py/objstringio: Slightly optimize stringio_copy_on_write for code size. 2019-11-26 14:26:24 +11:00
objstringio.h
objstrunicode.c py: Make mp_obj_get_type() return a const ptr to mp_obj_type_t. 2020-01-09 11:25:26 +11:00
objtuple.c py: Make mp_obj_get_type() return a const ptr to mp_obj_type_t. 2020-01-09 11:25:26 +11:00
objtuple.h
objtype.c py: Support non-boolean results for equality and inequality tests. 2020-01-30 14:53:07 +11:00
objtype.h py/runtime: Don't allocate iter buf for user-defined types. 2019-12-27 12:34:22 +11:00
objzip.c py: Downcase all MP_OBJ_IS_xxx macros to make a more consistent C API. 2019-02-12 14:54:51 +11:00
opmethods.c py: Make mp_obj_get_type() return a const ptr to mp_obj_type_t. 2020-01-09 11:25:26 +11:00
pairheap.c py/pairheap: Add generic implementation of pairing heap data structure. 2020-01-22 17:31:18 +11:00
pairheap.h py/pairheap: Add generic implementation of pairing heap data structure. 2020-01-22 17:31:18 +11:00
parse.c py: Rename MP_QSTR_NULL to MP_QSTRnull to avoid intern collisions. 2019-09-26 16:04:56 +10:00
parse.h
parsenum.c py: Rename MP_QSTR_NULL to MP_QSTRnull to avoid intern collisions. 2019-09-26 16:04:56 +10:00
parsenum.h
parsenumbase.c
parsenumbase.h
persistentcode.c py: Release GIL during syscalls in reader and writer code. 2020-01-26 23:26:31 +11:00
persistentcode.h py/persistentcode: Make ARM Thumb archs support multiple sub-archs. 2019-12-12 20:15:28 +11:00
profile.c py/profile: Fix debug opcode decoding of MP_BC_RAISE_xxx opcodes. 2019-12-20 14:57:44 +11:00
profile.h py/profile: Add debugging for sys.settrace feature. 2019-08-30 16:48:47 +10:00
py.mk py/pairheap: Add generic implementation of pairing heap data structure. 2020-01-22 17:31:18 +11:00
pystack.c
pystack.h
qstr.c py/qstr: Don't include or init qstr_mutex when GIL is enabled. 2020-01-23 13:29:11 +11:00
qstr.h py: Rename MP_QSTR_NULL to MP_QSTRnull to avoid intern collisions. 2019-09-26 16:04:56 +10:00
qstrdefs.h
reader.c py: Release GIL during syscalls in reader and writer code. 2020-01-26 23:26:31 +11:00
reader.h
repl.c py: Rename MP_QSTR_NULL to MP_QSTRnull to avoid intern collisions. 2019-09-26 16:04:56 +10:00
repl.h
ringbuf.c py/ringbuf: Add peek16 method. 2019-11-21 12:04:53 +11:00
ringbuf.h py/ringbuf: Add peek16 method. 2019-11-21 12:04:53 +11:00
runtime.c py: Support non-boolean results for equality and inequality tests. 2020-01-30 14:53:07 +11:00
runtime.h py: Remove 3 obsolete commented-out lines from header files. 2019-11-26 21:36:41 +11:00
runtime0.h py/nativeglue: Add new header file with native function table typedef. 2019-12-12 20:15:28 +11:00
runtime_utils.c
scheduler.c py/scheduler: Rename sched_stack to sched_queue. 2019-07-17 16:09:32 +10:00
scope.c
scope.h
sequence.c py: Make mp_obj_get_type() return a const ptr to mp_obj_type_t. 2020-01-09 11:25:26 +11:00
showbc.c py: Rework and compress second part of bytecode prelude. 2019-10-01 12:26:22 +10:00
smallint.c
smallint.h
stackctrl.c
stackctrl.h
stream.c py: Make mp_obj_get_type() return a const ptr to mp_obj_type_t. 2020-01-09 11:25:26 +11:00
stream.h py/stream.h: Add MP_STREAM_POLL_NVAL constant. 2019-10-31 12:54:37 +11:00
unicode.c py/unicode: Add unichar_isalnum(). 2020-01-12 13:03:57 +11:00
unicode.h
vm.c py/vm: Fix comment to refer to MP_BC_RAISE_OBJ instead of RAISE_VARARGS. 2019-12-20 14:57:06 +11:00
vmentrytable.h py: Split RAISE_VARARGS opcode into 3 separate ones. 2019-09-26 15:39:50 +10:00
vstr.c various: Add and update my copyright line based on git history. 2019-05-17 18:04:15 +10:00
warning.c py: Update my copyright info on some files. 2019-02-06 00:19:00 +11:00