aboutsummaryrefslogtreecommitdiff
path: root/py/objbool.c
AgeCommit message (Collapse)Author
2020-02-28all: Reformat C and Python source code with tools/codeformat.py.Damien George
This is run with uncrustify 0.70.1, and black 19.10b0.
2020-02-11py: Expand type equality flags to 3 separate ones, fix bool/namedtuple.Damien George
Both bool and namedtuple will check against other types for equality; int, float and complex for bool, and tuple for namedtuple. So to make them work after the recent commit 3aab54bf434e7f025a91ea05052f1bac439fad8c they would need MP_TYPE_FLAG_NEEDS_FULL_EQ_TEST set. But that makes all bool and namedtuple equality checks less efficient because mp_obj_equal_not_equal() could no longer short-cut x==x, and would need to try __ne__. To improve this, this commit splits the MP_TYPE_FLAG_NEEDS_FULL_EQ_TEST flags into 3 separate flags to give types more fine-grained control over how their equality behaves. These new flags are then used to fix bool and namedtuple equality. Fixes issue #5615 and #5620.
2020-01-13py/obj: Add MICROPY_OBJ_IMMEDIATE_OBJS option to reduce code size.Damien George
This option (enabled by default for object representation A, B, C) makes None/False/True objects immediate objects, ie they are no longer a concrete object in ROM but are rather just values, eg None=0x6 for representation A. Doing this saves a considerable amount of code size, due to these objects being widely used: bare-arm: -392 -0.591% minimal x86: -252 -0.170% [incl +52(data)] unix x64: -624 -0.125% [incl -128(data)] unix nanbox: +0 +0.000% stm32: -1940 -0.510% PYBV10 cc3200: -1216 -0.659% esp8266: -404 -0.062% GENERIC esp32: -732 -0.064% GENERIC[incl +48(data)] nrf: -988 -0.675% pca10040 samd: -564 -0.556% ADAFRUIT_ITSYBITSY_M4_EXPRESS Thanks go to @Jongy aka Yonatan Goldschmidt for the idea.
2017-10-04all: Remove inclusion of internal py header files.Damien George
Header files that are considered internal to the py core and should not normally be included directly are: py/nlr.h - internal nlr configuration and declarations py/bc0.h - contains bytecode macro definitions py/runtime0.h - contains basic runtime enums Instead, the top-level header files to include are one of: py/obj.h - includes runtime0.h and defines everything to use the mp_obj_t type py/runtime.h - includes mpstate.h and hence nlr.h, obj.h, runtime0.h, and defines everything to use the general runtime support functions Additional, specific headers (eg py/objlist.h) can be included if needed.
2017-08-29all: Convert mp_uint_t to mp_unary_op_t/mp_binary_op_t where appropriateDamien George
The unary-op/binary-op enums are already defined, and there are no arithmetic tricks used with these types, so it makes sense to use the correct enum type for arguments that take these values. It also reduces code size quite a bit for nan-boxing builds.
2017-07-31all: Use the name MicroPython consistently in commentsAlexander Steffen
There were several different spellings of MicroPython present in comments, when there should be only one.
2016-09-30py/objbool: Make a slight simplification of bool constructor.Damien George
Reduces code size for some archs.
2016-09-30py/objbool: Defer bool's unary op implementation to small int.Damien George
Similar to how binary op already works. Common unary operations already have fast paths for bool so there's no need to have explicit handling of ops in bool_unary_op, especially since they have the same behaviour as integers.
2016-01-11py: Change first arg of type.make_new from mp_obj_t to mp_obj_type_t*.Damien George
The first argument to the type.make_new method is naturally a uPy type, and all uses of this argument cast it directly to a pointer to a type structure. So it makes sense to just have it a pointer to a type from the very beginning (and a const pointer at that). This patch makes such a change, and removes all unnecessary casting to/from mp_obj_t.
2016-01-11py: Change type of .make_new and .call args: mp_uint_t becomes size_t.Damien George
This patch changes the type signature of .make_new and .call object method slots to use size_t for n_args and n_kw (was mp_uint_t. Makes code more efficient when mp_uint_t is larger than a machine word. Doesn't affect ports when size_t and mp_uint_t have the same size.
2015-12-10py: Make UNARY_OP_NOT a first-class op, to agree with Py not semantics.Damien George
Fixes #1684 and makes "not" match Python semantics. The code is also simplified (the separate MP_BC_NOT opcode is removed) and the patch saves 68 bytes for bare-arm/ and 52 bytes for minimal/. Previously "not x" was implemented as !mp_unary_op(x, MP_UNARY_OP_BOOL), so any given object only needs to implement MP_UNARY_OP_BOOL (and the VM had a special opcode to do the ! bit). With this patch "not x" is implemented as mp_unary_op(x, MP_UNARY_OP_NOT), but this operation is caught at the start of mp_unary_op and dispatched as !mp_obj_is_true(x). mp_obj_is_true has special logic to test for truthness, and is the correct way to handle the not operation.
2015-11-29py: Wrap all obj-ptr conversions in MP_OBJ_TO_PTR/MP_OBJ_FROM_PTR.Damien George
This allows the mp_obj_t type to be configured to something other than a pointer-sized primitive type. This patch also includes additional changes to allow the code to compile when sizeof(mp_uint_t) != sizeof(void*), such as using size_t instead of mp_uint_t, and various casts.
2015-09-04py/objbool: Simplify dispatch of bool binary op.Damien George
This optimises (in speed and code size) for the common case where the binary op for the bool object is supported. Unsupported binary ops still behave the same.
2015-05-12py: Convert hash API to use MP_UNARY_OP_HASH instead of ad-hoc function.Damien George
Hashing is now done using mp_unary_op function with MP_UNARY_OP_HASH as the operator argument. Hashing for int, str and bytes still go via fast-path in mp_unary_op since they are the most common objects which need to be hashed. This lead to quite a bit of code cleanup, and should be more efficient if anything. It saves 176 bytes code space on Thumb2, and 360 bytes on x86. The only loss is that the error message "unhashable type" is now the more generic "unsupported type for __hash__".
2015-04-16py: Overhaul and simplify printf/pfenv mechanism.Damien George
Previous to this patch the printing mechanism was a bit of a tangled mess. This patch attempts to consolidate printing into one interface. All (non-debug) printing now uses the mp_print* family of functions, mainly mp_printf. All these functions take an mp_print_t structure as their first argument, and this structure defines the printing backend through the "print_strn" function of said structure. Printing from the uPy core can reach the platform-defined print code via two paths: either through mp_sys_stdout_obj (defined pert port) in conjunction with mp_stream_write; or through the mp_plat_print structure which uses the MP_PLAT_PRINT_STRN macro to define how string are printed on the platform. The former is only used when MICROPY_PY_IO is defined. With this new scheme printing is generally more efficient (less layers to go through, less arguments to pass), and, given an mp_print_t* structure, one can call mp_print_str for efficiency instead of mp_printf("%s", ...). Code size is also reduced by around 200 bytes on Thumb2 archs.
2015-01-20py, unix: Allow to compile with -Wunused-parameter.Damien George
See issue #699.
2015-01-01py: Move to guarded includes, everywhere in py/ core.Damien George
Addresses issue #1022.
2014-09-23py: Make native emitter handle multi-compare and not/is not/not in ops.Damien George
2014-09-17py: Add native json printing using existing print framework.Damien George
Also add start of ujson module with dumps implemented. Enabled in unix and stmhal ports. Test passes on both.
2014-08-30Change some parts of the core API to use mp_uint_t instead of uint/int.Damien George
Addressing issue #50, still some way to go yet.
2014-07-31py: Make MP_OBJ_NEW_SMALL_INT cast arg to mp_int_t itself.Damien George
Addresses issue #724.
2014-07-03Rename machine_(u)int_t to mp_(u)int_t.Damien George
See discussion in issue #50.
2014-05-21py: Rename MP_OBJ_NOT_SUPPORTED to MP_OBJ_NULL.Damien George
See issue #608 for justification.
2014-05-11py: Use mp_arg_check_num in more places.Damien George
Updated functions now do proper checking that n_kw==0, and are simpler because they don't have to explicitly raise an exception. Down side is that the error messages no longer include the function name, but that's acceptable. Saves order 300 text bytes on x64 and ARM.
2014-05-03Add license header to (almost) all files.Damien George
Blanket wide to all .c and .h files. Some files originating from ST are difficult to deal with (license wise) so it was left out of those. Also merged modpyb.h, modos.h, modstm.h and modtime.h in stmhal/.
2014-05-02py, unix: Make "mpconfig.h" be first included, as other headers depend on it.Paul Sokolovsky
Specifically, nlr.h does.
2014-04-17py: Add MP_OBJ_STOP_ITERATION and make good use of it.Damien George
Also make consistent use of MP_OBJ_NOT_SUPPORTED and MP_OBJ_NULL. This helps a lot in debugging and understanding of function API.
2014-04-05py: Change nlr_jump to nlr_raise, to aid in debugging.Damien George
This does not affect code size or performance when debugging turned off. To address issue #420.
2014-04-04py: Make False and True act like 0 and 1 for integer arithmetic.Damien George
2014-03-30Rename rt_* to mp_*.Damien George
Mostly just a global search and replace. Except rt_is_true which becomes mp_obj_is_true. Still would like to tidy up some of the names, but this will do for now.
2014-03-29py: Change mp_const_* objects to macros.Damien George
Addresses issue #388.
2014-03-17py: Clean up includes.xbe
Remove unnecessary includes. Add includes that improve portability.
2014-02-15Implement proper exception type hierarchy.Damien George
Each built-in exception is now a type, with base type BaseException. C exceptions are created by passing a pointer to the exception type to make an instance of. When raising an exception from the VM, an instance is created automatically if an exception type is raised (as opposed to an exception instance). Exception matching (RT_BINARY_OP_EXCEPTION_MATCH) is now proper. Handling of parse error changed to match new exceptions. mp_const_type renamed to mp_type_type for consistency.
2014-02-15Change mp_obj_type_t.name from const char * to qstr.Damien George
Ultimately all static strings should be qstr. This entry in the type structure is only used for printing error messages (to tell the type of the bad argument), and printing objects that don't supply a .print method.
2014-02-12Replace global "static" -> "STATIC", to allow "analysis builds". Part 1.Paul Sokolovsky
Some tools do not support local/static symbols (one example is GNU ld map file). Exposing all functions will allow to do detailed size comparisons, etc. Also, added bunch of statics where they were missing, and replaced few identity functions with global mp_identity().
2014-01-30Implement __bool__ and __len__ via unary_op virtual method for all types.Paul Sokolovsky
__bool__() and __len__() are just the same as __neg__() or __invert__(), and require efficient dispatching implementation (not requiring search/lookup). type->unary_op() is just the right choice for this short of adding standalone virtual method(s) to already big mp_obj_type_t structure.
2014-01-23py: Implement bool unary op; tidy up unary op dispatch.Damien George
2014-01-21Revamp qstrs: they now include length and hash.Damien George
Can now have null bytes in strings. Can define ROM qstrs per port using qstrdefsport.h
2014-01-18Make VM stack grow upwards, and so no reversed args arrays.Damien George
Change state layout in VM so the stack starts at state[0] and grows upwards. Locals are at the top end of the state and number downwards. This cleans up a lot of the interface connecting the VM to C: now all functions that take an array of Micro Python objects are in order (ie no longer in reverse). Also clean up C API with keyword arguments (call_n and call_n_kw replaced with single call method that takes keyword arguments). And now make_new takes keyword arguments. emitnative.c has not yet been changed to comply with the new order of stack layout.
2014-01-15type->print(): Distinguish str() and repr() variety by passing extra param.Paul Sokolovsky
2014-01-08py: add variable argument exception constructor function.Damien George
Addresses issue #104.
2014-01-07Merge branch 'cplusplus' of https://github.com/ian-v/micropython into ↵Damien George
ian-v-cplusplus Conflicts: py/objcomplex.c
2014-01-06Revert MP_BOOL, etc. and use <stdbool.h> insteadian-v
2014-01-06Co-exist with C++ (issue #85)ian-v
2014-01-05Convert many object types structs to use C99 tagged initializer syntax.Paul Sokolovsky
2014-01-04Convert Python types to proper Python type hierarchy.Damien George
Now much more inline with how CPython does types.
2013-12-21Change object representation from 1 big union to individual structs.Damien
A big change. Micro Python objects are allocated as individual structs with the first element being a pointer to the type information (which is itself an object). This scheme follows CPython. Much more flexible, not necessarily slower, uses same heap memory, and can allocate objects statically. Also change name prefix, from py_ to mp_ (mp for Micro Python).