Damien George
8788b131ec
py: Check for NDEBUG using #ifdef rather than #if.
Defining NDEBUG (to any value, even 0) disables debugging. Otherwise,
if it's not defined, debugging is enabled.
10 years ago
Damien George
963a5a3e82
py, unix: Allow to compile with -Wsign-compare.
See issue #699 .
10 years ago
Damien George
cd34207409
py: Can compile with -Wmissing-declarations and -Wmissing-prototypes.
10 years ago
Damien George
c38dc3ccc7
py: Implement fallback for equality check for all types.
Return "not equal" for objects that don't implement equality check.
This is as per Python specs.
10 years ago
Damien George
51dfcb4bb7
py: Move to guarded includes, everywhere in py/ core.
Addresses issue #1022 .
10 years ago
Paul Sokolovsky
46c3ab2004
modsys: Add sys.print_exception(exc, file=sys.stdout) function.
The function is modeled after traceback.print_exception(), but unbloated,
and put into existing module to save overhead on adding another module.
Compliant traceback.print_exception() is intended to be implemented in
micropython-lib in terms of sys.print_exception().
This change required refactoring mp_obj_print_exception() to take pfenv_t
interface arguments.
Addresses #751 .
10 years ago
Damien George
be6d8be91e
py: Rename mp_obj_int_get to mp_obj_int_get_truncated; fix struct.pack.
mp_obj_int_get_truncated is used as a "fast path" int accessor that
doesn't check for overflow and returns the int truncated to the machine
word size, ie mp_int_t.
Use mp_obj_int_get_truncated to fix struct.pack when packing maximum word
sized values.
Addresses issues #779 and #998 .
10 years ago
stijn
e00eeaf4cd
py: Use __hash__ method if a type defines it
10 years ago
Damien George
1e9a92f84f
py: Use shorter, static error msgs when ERROR_REPORTING_TERSE enabled.
Going from MICROPY_ERROR_REPORTING_NORMAL to
MICROPY_ERROR_REPORTING_TERSE now saves 2020 bytes ROM for ARM Thumb2,
and 2200 bytes ROM for 32-bit x86.
This is about a 2.5% code size reduction for bare-arm.
10 years ago
Damien George
0344fa1ddf
py: Fix builtin callable so it checks user-defined instances correctly.
Addresses issue #953 .
10 years ago
Damien George
c7687ad7e6
py: Rename mp_builtin_id to mp_obj_id and make it public.
10 years ago
Damien George
ca6d75f16d
py: Small simplifications in tuple and list accessors.
10 years ago
Damien George
4d91723587
py: Remove use of int type in obj.h.
Part of code cleanup, working towards resolving issue #50 .
10 years ago
Damien George
9c4cbe2ac0
py: Make tuple and list use mp_int_t/mp_uint_t.
Part of code cleanup, to resolve issue #50 .
10 years ago
Damien George
3c658a4e75
py: Fix bug where GC collected native/viper/asm function data.
Because (for Thumb) a function pointer has the LSB set, pointers to
dynamic functions in RAM (eg native, viper or asm functions) were not
being traced by the GC. This patch is a comprehensive fix for this.
Addresses issue #820 .
10 years ago
Damien George
4c03b3a899
py: Implement builtin reversed() function.
reversed function now implemented, and works for tuple, list, str, bytes
and user objects with __len__ and __getitem__.
Renamed mp_builtin_len to mp_obj_len to make it publically available (eg
for reversed).
10 years ago
Paul Sokolovsky
7133d91773
py: mp_buffer_info_t::buf may be valid, but NULL for empty objects.
This happens for example for zero-size arrays. As .get_buffer() method now
has explicit return value, it's enough to distinguish success vs failure
of getting buffer.
10 years ago
Damien George
bb4c6f35c6
py: Make MP_OBJ_NEW_SMALL_INT cast arg to mp_int_t itself.
Addresses issue #724 .
10 years ago
Damien George
ffe911d228
py: Make long ints hashable.
Addresses issue #765 .
10 years ago
Damien George
40f3c02682
Rename machine_(u)int_t to mp_(u)int_t.
See discussion in issue #50 .
11 years ago
Paul Sokolovsky
caa7334141
stackctrl: Add "mp_" prefix.
11 years ago
Paul Sokolovsky
8993fb6cf0
py: Add protection against printing too nested or recursive data structures.
With a test which cannot be automatically validated so far.
11 years ago
Paul Sokolovsky
e7f2b4c875
objstrunicode: Revamp len() handling for unicode, and optimize bool().
11 years ago
Paul Sokolovsky
3b6f7b95eb
py: Separate MICROPY_PY_BUILTINS_COMPLEX from MICROPY_PY_BUILTINS_FLOAT.
One thing is wanting to do 1 / 2 and get something else but 0, and quite
another - doing rocket science ;-).
11 years ago
Damien George
fb510b3bf9
Rename bultins config variables to MICROPY_PY_BUILTINS_*.
This renames:
MICROPY_PY_FROZENSET -> MICROPY_PY_BUILTINS_FROZENSET
MICROPY_PY_PROPERTY -> MICROPY_PY_BUILTINS_PROPERTY
MICROPY_PY_SLICE -> MICROPY_PY_BUILTINS_SLICE
MICROPY_ENABLE_FLOAT -> MICROPY_PY_BUILTINS_FLOAT
See issue #35 for discussion.
11 years ago
Damien George
6ac5dced24
py: Rename MP_OBJ_NOT_SUPPORTED to MP_OBJ_NULL.
See issue #608 for justification.
11 years ago
Paul Sokolovsky
ab7bf28489
py: More const usage.
11 years ago
Paul Sokolovsky
7e7940c39d
py: Fix __len__ special method result handling.
Having both MP_OBJ_NOT_SUPPORTED and MP_OBJ_NULL is arguably confusing.
11 years ago
Paul Sokolovsky
7aca1cae34
py: Start making good use of mp_const_obj_t.
11 years ago
Paul Sokolovsky
0bc15941c2
py: Make mp_obj_print() handle null object w/o segfault if debug build.
Happens regularly when used for debugging.
11 years ago
Damien George
04b9147e15
Add license header to (almost) all files.
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/.
11 years ago
Paul Sokolovsky
f54bcbf099
py, unix: Make "mpconfig.h" be first included, as other headers depend on it.
Specifically, nlr.h does.
11 years ago
Damien George
b11b85adaa
py: Allow to pass buffer protocol flags to get_buffer helper funcs.
11 years ago
Damien George
57a4b4f178
py: Add typecode to buffer protocol.
When querying an object that supports the buffer protocol, that object
must now return a typecode (as per binary.[ch]). This does not have to
be honoured by the caller, but can be useful for determining element
size.
11 years ago
Damien George
ea8d06c39d
py: Add MP_OBJ_STOP_ITERATION and make good use of it.
Also make consistent use of MP_OBJ_NOT_SUPPORTED and MP_OBJ_NULL.
This helps a lot in debugging and understanding of function API.
11 years ago
Damien George
729f7b42d6
py: Merge BINARY_OP_SUBSCR and store_subscr (w/ delete) into subscr.
mp_obj_t->subscr now does load/store/delete.
11 years ago
Damien George
ee01411036
py: Add len(bytes).
11 years ago
Damien George
0e4ba25834
py: Fix SyntaxError exception: don't have a block name, so pass NULL.
11 years ago
Damien George
8a1cab952f
py: Fix mp_get_buffer, and use it in more places.
Must use mp_obj_get_type to get the type of an object. Can't assume
mp_obj_t is castable to mp_obj_base_t.
11 years ago
Paul Sokolovsky
f130ca1f60
py: Make bytes type hashable.
11 years ago
Damien George
a5c82a8187
py: Convert some macros to inline functions (in obj.h).
Also convert mp_obj_is_integer to an inline function.
Overall this decreased code size (at least on 32-bit x86 machine).
11 years ago
Damien George
e22d76e73b
py: Fix up object equality test.
It regressed a bit after implementing float/complex equality. Now it
should be improved, and support more equality tests.
11 years ago
Damien George
a9ddd6d9df
py: Simplify and improve mp_get_index.
It has (again) a fast path for ints, and a simplified "slow" path for
everything else.
Also simplify the way str indexing is done (now matches tuple and list).
11 years ago
Damien George
b8a053aeb1
py: Implement float and complex == and !=.
Addresses issue #462 .
11 years ago
Damien George
686afc5c0a
py: Check that sequence has 2 elements for dict iterable constructor.
11 years ago
Damien George
b5fbd0ba87
py: Add mp_obj_is_integer; make mp_get_index check for long int.
mp_obj_is_integer should be used to check if an object is of integral
type. It returns true for bool, small int and long int.
11 years ago
Paul Sokolovsky
3aa8ee7c9e
py: Add mp_get_buffer(), mp_get_buffer_raise() convenience functions to API.
11 years ago
Damien George
ea13f407a3
py: Change nlr_jump to nlr_raise, to aid in debugging.
This does not affect code size or performance when debugging turned off.
To address issue #420 .
11 years ago
Paul Sokolovsky
e99841be69
mp_obj_get_int(): Add warning against adding implicit float->int conversion.
11 years ago
Paul Sokolovsky
91cbe6033a
py: Allow types to be hashable.
Quite natural to have d[int] = handle_int .
11 years ago