Commit Graph

179 Commits

Author SHA1 Message Date
Paul Sokolovsky a01f6c9ae7 unix/main: Remove stray mp_printf() from previous commit. 2015-11-13 17:33:42 +02:00
Paul Sokolovsky 3a6b3d230c main.c: Switch stderr printing from ANSI C to native POSIX. 2015-11-13 15:29:42 +02:00
Paul Sokolovsky f882d53fcd unix/main: Use builtin unichar_isdigit() in preference if libc's.
Less dependencies.
2015-11-13 01:57:08 +02:00
Damien George 731f359292 all: Add py/mphal.h and use it in all ports.
py/mphal.h contains declarations for generic mp_hal_XXX functions, such
as stdio and delay/ticks, which ports should provide definitions for.  A
port will also provide mphalport.h with further HAL declarations.
2015-10-31 19:14:30 +03:00
Paul Sokolovsky 8e6e9eaea5 unix: Use "Ctrl" as a name of the key, not "CTRL". 2015-10-20 12:30:36 +03:00
Damien George 3aa7dd23c9 unix: Add exit and paste-mode hints to shell startup banner.
Thanks to @nyov for the initial patch.
2015-10-12 00:19:00 +01:00
Damien George 0334058fa4 Rename "Micro Python" to "MicroPython" in REPL, help, readme's and misc. 2015-10-12 00:06:25 +01:00
Damien George 46a1102852 repl: Add paste mode to friendly REPL, entered via CTRL-E.
Use CTRL-E to enter paste mode.  Prompt starts with "===" and accepts
all characters verbatim, echoing them back.  Only control characters are
CTRL-C which cancels the input and returns to normal REPL, and CTRL-D
which ends the input and executes it.  The input is executed as though
it were a file.  The input is not added to the prompt history.
2015-10-11 23:30:22 +01:00
Damien George 58e0f4ac50 py: Allocate parse nodes in chunks to reduce fragmentation and RAM use.
With this patch parse nodes are allocated sequentially in chunks.  This
reduces fragmentation of the heap and prevents waste at the end of
individually allocated parse nodes.

Saves roughly 20% of RAM during parse stage.
2015-10-02 00:11:11 +01:00
Alex March c0035d1694 unix: Use MICROPY_HAL_H macro for header inclusion.
Follow the same format as other ports using the macro to include
the HAL header.
2015-09-19 14:03:57 +01:00
Damien George 3ca84026db unix: Enable REPL auto-indent. 2015-09-12 22:09:18 +01:00
Paul Sokolovsky aa65e1edb3 unix: Bump default heap size to 1MB (2MB on 64-bit systems). 2015-08-22 23:54:25 +03:00
Damien George 031278f661 unix: Allow to cat a script into stdin from the command line.
See issue #1306.
2015-06-04 23:42:45 +01:00
Paul Sokolovsky 51726b4d43 unix: Allow to override default sys.path value.
Using MICROPY_PY_SYS_PATH_DEFAULT macro define. A usecase is building a
distribution package, which should not have user home path by default in
sys.path. In such case, MICROPY_PY_SYS_PATH_DEFAULT can be defined on
make command-line (using CFLAGS_EXTRA).
2015-05-30 01:07:58 +03:00
Damien George 9ae3fc6523 unix: Add option to use uPy readline, and enable by default.
This gets uPy readline working with unix port, with tab completion and
history.  GNU readline is still supported, configure using
MICROPY_USE_READLINE variable.
2015-05-27 15:59:43 +01:00
Damien George 4a10214be2 unix: Factor out stdio and ctrl-C code to unix_mphal.c file. 2015-05-27 15:52:35 +01:00
Paul Sokolovsky 717a958256 unix: Print unhandled exception to stderr, like CPython does. 2015-05-10 00:55:35 +03:00
Damien George d792d9e49e unix: Make extra-coverage function callable from Python scripts.
This allows the output of the extra-coverage tests to be checked using
the normal run-tests script.
2015-05-08 09:18:38 +01:00
Damien George d3b32caea4 unix: Add special function to improve coverage.
The function and corresponding command-line option are only enabled for
the coverage build.  They are used to exercise uPy features that can't
be properly tested by Python scripts.
2015-05-08 00:19:56 +01:00
Damien George 95f53461c2 py: Replace py-version.sh with makeversionhdr.py, written in Python.
Also rename py-version.h to mpversion.h for consistency with mpconfig.h.
2015-04-28 23:52:36 +01:00
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
Paul Sokolovsky 6bf423df2c unix: Bump stack limit and adjust for 64-bitness.
Without that, "import http.client" failed due to max recursion.
2015-03-21 02:16:45 +02:00
Paul Sokolovsky 1129de5ac0 unix: Support readline history saving to file, improves interactive usage. 2015-03-13 21:46:19 +00:00
Damien George 0bfc7638ba py: Protect mp_parse and mp_compile with nlr push/pop block.
To enable parsing constants more efficiently, mp_parse should be allowed
to raise an exception, and mp_compile can already raise a MemoryError.
So these functions need to be protected by an nlr push/pop block.

This patch adds that feature in all places.  This allows to simplify how
mp_parse and mp_compile are called: they now raise an exception if they
have an error and so explicit checking is not needed anymore.
2015-02-07 18:33:58 +00:00
Damien George 50912e7f5d py, unix, stmhal: Allow to compile with -Wshadow.
See issue #699.
2015-01-20 11:55:10 +00:00
Damien George 3926c72dd2 unix: Add target to build "minimal" uPy interpreter. 2015-01-16 18:03:01 +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 cd34207409 py: Can compile with -Wmissing-declarations and -Wmissing-prototypes. 2015-01-12 22:30:49 +00:00
Damien George b4b10fd350 py: Put all global state together in state structures.
This patch consolidates all global variables in py/ core into one place,
in a global structure.  Root pointers are all located together to make
GC tracing easier and more efficient.
2015-01-07 20:33:00 +00:00
Damien George 6d7e47087f unix: Prefix includes with py/; remove need for -I../py. 2015-01-01 20:40:19 +00:00
Damien George 9ddbe291c4 py: Add include guards to mpconfig,misc,qstr,obj,runtime,parsehelper. 2014-12-29 01:02:19 +00:00
Paul Sokolovsky 8427c5b76c unix/windows: Make sure that process exit code is portable 8-bit value.
This fixes FORCED_EXIT internal flag leaking into Windows exit code.
2014-12-19 00:01:49 +02:00
Damien George 969a6b37bf py: Make functions static where appropriate. 2014-12-10 22:08:14 +00:00
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.
2014-12-08 20:25:49 +00:00
Damien George a4c52c5a3d py: Optimise lexer by exposing lexer type.
mp_lexer_t type is exposed, mp_token_t type is removed, and simple lexer
functions (like checking current token kind) are now inlined.

This saves 784 bytes ROM on 32-bit unix, 348 bytes on stmhal, and 460
bytes on bare-arm.  It also saves a tiny bit of RAM since mp_lexer_t
is a bit smaller.  Also will run a bit more efficiently.
2014-12-05 19:35:18 +00:00
Paul Sokolovsky 6e8ff9cd68 modmicropython: Move mem_info() and qstr_info() functions from unix port.
TODO: Merge useful functionality from modpyb too.
2014-12-01 20:42:24 +02:00
Paul Sokolovsky 98d8d59c33 unix: Allow -X heapsize number take 'w' specifier for word size adjustment.
The specifier should go after the number, before size suffix like 'k' or 'm'.
E.g.: "-X heapsize=100wk" will use 100K heap on 32-bit system and 200K - on
64-bit.
2014-11-05 22:47:30 +00:00
Paul Sokolovsky 429e3f077e unix: Make -v dump memory info at exit.
Also, move bytecode dumps to -v -v, because they're too verbose for just -v.
2014-10-26 22:36:56 +00:00
Paul Sokolovsky e503512f83 unix: Implement -m option (execute module from stdlib).
Support for packages as argument not implemented, but otherwise error and
exit handling should be correct. This for example will allow to do:

pip-micropython install micropython-test.pystone
micropython -m test.pystone
2014-10-26 15:54:19 +00:00
Damien George c76af32575 unix/windows: Disable sigaction on windows port. 2014-10-26 00:42:41 +01:00
Damien George 124df6f8d0 py: Add mp_pending_exception global variable, for VM soft interrupt.
This allows to implement KeyboardInterrupt on unix, and a much safer
ctrl-C in stmhal port.  First ctrl-C is a soft one, with hope that VM
will notice it; second ctrl-C is a hard one that kills anything (for
both unix and stmhal).

One needs to check for a pending exception in the VM only for jump
opcodes.  Others can't produce an infinite loop (infinite recursion is
caught by stack check).
2014-10-25 23:37:57 +01:00
Paul Sokolovsky fcff4663dd unix: Allow -X heapsize= option take numbers with K & M suffixes.
For kilobytes and megabytes respectively.
2014-10-25 17:00:55 +01:00
Damien George 0b13f3e026 py: Improve memory usage debugging; better GC AT dumping.
In unix port, mem_info(1) now prints pretty GC alloc table.
2014-10-24 23:12:25 +01:00
Damien George c92672d7f8 unix: Make -c option parse input script as a file, as per CPython.
Addresses issue #915.
2014-10-17 23:51:39 +01:00
Paul Sokolovsky 23b3b04072 unix: Rename "microsocket" module to "usocket".
Per new conventions, we'd like to consistently use "u*" naming conventions
for modules which don't offer complete CPython compatibility, while offer
subset or similar API.
2014-10-09 20:43:10 +03:00
Damien George 854c8c0153 unix: Detect and print compile error. 2014-10-05 22:25:36 +01:00
Damien George 39dc145478 py: Change [u]int to mp_[u]int_t in qstr.[ch], and some other places.
This should pretty much resolve issue #50.
2014-10-03 19:52:22 +01:00
Damien George 762d57519d unix: Do a proper clean-up on sys.exit/SystemExit.
Addresses issue #859.
2014-10-01 23:18:39 +01:00
Damien George b0261341d3 py: For malloc and vstr functions, use size_t exclusively for int type.
It seems most sensible to use size_t for measuring "number of bytes" in
malloc and vstr functions (since that's what size_t is for).  We don't
use mp_uint_t because malloc and vstr are not Micro Python specific.
2014-09-25 15:49:26 +01:00
Damien George b92cbe6129 py: Move definition of mp_sys_exit to core.
sys.exit always raises SystemExit so doesn't need a special
implementation for each port.  If C exit() is really needed, use the
standard os._exit function.

Also initialise mp_sys_path and mp_sys_argv in teensy port.
2014-09-15 15:53:09 +01:00