Commit Graph

22 Commits

Author SHA1 Message Date
Damien George 7f9d1d6ab9 py: Overhaul and simplify printf/pfenv mechanism.
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-04-16 14:30:16 +00:00
Damien George 2801e6fad8 py: Some trivial cosmetic changes, for code style consistency. 2015-04-04 15:53:11 +01:00
Damien George fa1edff006 py: Remove unnecessary and unused sgn argument from pfenv_print_mp_int. 2015-03-14 22:32:40 +00:00
Damien George 4d77e1a034 py: Use m_{new,renew,del} consistently.
This is so all memory requests go through the same interface.
2015-02-27 09:34:51 +00:00
Damien George ff8dd3f486 py, unix: Allow to compile with -Wunused-parameter.
See issue #699.
2015-01-20 12:47:20 +00:00
Damien George 963a5a3e82 py, unix: Allow to compile with -Wsign-compare.
See issue #699.
2015-01-16 17:47:07 +00:00
Damien George 51dfcb4bb7 py: Move to guarded includes, everywhere in py/ core.
Addresses issue #1022.
2015-01-01 20:32:09 +00:00
Damien George 42f3de924b py: Convert [u]int to mp_[u]int_t where appropriate.
Addressing issue #50.
2014-10-03 17:44:14 +00:00
Damien George 40f3c02682 Rename machine_(u)int_t to mp_(u)int_t.
See discussion in issue #50.
2014-07-03 13:25:24 +01:00
Paul Sokolovsky 59c675a64c py: Include mpconfig.h before all other includes.
It defines types used by all other headers.

Fixes #691.
2014-06-21 22:43:22 +03:00
Dave Hylands b69f9fa31f Fix str.modulo when precision is specified. 2014-06-05 23:09:02 -07:00
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.
2014-06-01 13:32:54 +01:00
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/.
2014-05-03 23:27:38 +01:00
Damien George d0f9f6cd3f py: Fix pfenv_print_strn to return correct number of chars printed.
With this fix, all tests in tests/basics pass on pyboard.
2014-04-17 18:58:09 +01:00
Damien George 348435d279 py: Reinstate old pfenv_print_int function for stmhal's printf. 2014-04-08 22:10:37 +01:00
Damien George a12a0f78b0 py: Rename pfenv_print_int to pfenv_print_mp_int, and add back former.
stmhal relies on pfenv_* to implement its printf.  Thus, it needs a
pfenv_print_int which prints a proper 32-bit integer.  With latest
change to pfenv, this function became one that took mp_obj_t, and
extracted the integer value from that object.

To fix temporarily, pfenv_print_int has been renamed to
pfenv_print_mp_int (to indicate it takes a mp_obj_t for the int), and
pfenv_print_int has been added (which takes a normal C int).  Currently,
pfenv_print_int proxies to pfenv_print_mp_int, but this means it looses
the MSB.  Need to find a way to fix this, but the only way I can think
of will duplicate lots of code.
2014-04-08 01:29:53 +01:00
Dave Hylands c4029e5079 Add string formatting support for longlong and mpz. 2014-04-07 11:38:45 -07:00
Dave Hylands 64ef5d7f4e Change pfenv_print_int to take machine_uint_t rather than unsinged in
With this change, the following works:

>>> print('%#x' % 0x1234567890abcdef)
0x1234567890abcdef
2014-04-05 09:42:20 -07:00
Damien George e3e0500296 py: Make pfenv.c conform to code conventions. 2014-04-01 21:15:03 +01:00
Dave Hylands 1c6b4b2e24 Reduce stack usage of pfenv_print_strn 2014-04-01 11:59:31 -07:00
Dave Hylands 80359aa96e Fix INT_BUF_SIZE to work with 32-bit and 64-bit 2014-04-01 11:03:44 -07:00
Dave Hylands baf6f14deb Enhance str.format support
This adds support for almost everything (the comma isn't currently
supported).

The "unspecified" type with floats also doesn't behave exactly like
python.

Tested under unix with float and double
Spot tested on stmhal
2014-04-01 01:17:33 -07:00