Commit Graph

2304 Commits (609a9c6b715b80b3b84ef875408e7e3b642c8c9b)

Author SHA1 Message Date
Damien George 1b0aab621b py: Change struct and macro for builtin fun so they can be type checked. 2016-01-03 11:53:44 +00:00
Damien George 3d2daa2d03 py: Change exception traceback data to use size_t instead of mp_uint_t.
The traceback array stores qstrs and line numbers.  qstrs are typed as
size_t, and line numbers should safely fit in size_t as well.
2016-01-02 22:04:12 +00:00
Paul Sokolovsky 00ee84e1e1 py: Clean up instantiation of dupterm object.
To comply with already established scheme for extmod's.
2016-01-01 14:22:57 +02:00
Paul Sokolovsky 9bbfd5efd4 py/mpconfig: Make configuration of dupterm object reusable. 2016-01-01 13:16:18 +02:00
Paul Sokolovsky ddea7cb702 extmod/moduos_dupterm: Make uos.dupterm() implementation reusable.
That's just function which sets/gets dup terminal object, and can be
easily reused across ports.
2016-01-01 13:04:32 +02:00
Paul Sokolovsky 0992588811 py/frozenmod: Make frozen module content be 0-terminated.
To allow simple zero-terminated lexers.
2016-01-01 07:51:07 +02:00
Damien George 6dde019d93 py/map: In map lookup, check for fixed map independent of ordered map.
It's possible to have a fixed map that is properly hashed (ie not
simply ordered).
2015-12-31 00:24:33 +00:00
Dave Hylands 0dce9a21ce stmhal: Add struct qstr to block of qstrs needed for MICROPY_PY_STRUCT.
Otherwise build fails if uctypes is disabled.
2015-12-28 00:28:56 +00:00
Paul Sokolovsky 3ea03a1188 py/gc: Improve mark/sweep debug output.
Previously, mark operation weren't logged at all, while it's quite useful
to see cascade of marks in case of over-marking (and in other cases too).
Previously, sweep was logged for each block of object in memory, but that
doesn't make much sense and just lead to longer output, harder to parse
by a human. Instead, log sweep only once per object. This is similar to
other memory manager operations, e.g. an object is allocated, then freed.
Or object is allocated, then marked, otherwise swept (one log entry per
operation, with the same memory address in each case).
2015-12-27 20:40:36 +02:00
Damien George bbe8d51bd9 py/map: Add fast-path for hashing of map index when it is a qstr.
Map indicies are most commonly a qstr, and adding a fast-path for hashing
of a qstr increases overall performance of the runtime.

On pyboard there is a 4% improvement in the pystone benchmark for a cost
of 20 bytes of code size.  It's about a 2% improvement on unix.
2015-12-26 21:15:47 +00:00
Damien George 78913211a9 py: Be more restrictive binding self when looking up instance attrs.
When looking up and extracting an attribute of an instance, some
attributes must bind self as the first argument to make a working method
call.  Previously to this patch, any attribute that was callable had self
bound as the first argument.  But Python specs require the check to be
more restrictive, and only functions, closures and generators should have
self bound as the first argument

Addresses issue #1675.
2015-12-26 12:41:31 +00:00
Paul Sokolovsky b4c65c253f extmod/fsusermount: Move module qstrs to global pool from stmhal port. 2015-12-25 19:22:16 +02:00
Damien George 8047340d75 py: Handle case of return within the finally block of try-finally.
Addresses issue #1636.
2015-12-24 12:47:39 +00:00
Paul Sokolovsky 1c9210bc2b unix/unix_mphal: Raise KeyboardInterrupt straight from signal handler.
POSIX doesn't guarantee something like that to work, but it works on any
system with careful signal implementation. Roughly, the requirement is
that signal handler is executed in the context of the process, its main
thread, etc. This is true for Linux. Also tested to work without issues
on MacOSX.
2015-12-23 00:07:00 +02:00
Paul Sokolovsky d50f649cf8 py/objstr: Applying % (format) operator to bytes should return bytes, not str. 2015-12-20 16:52:11 +02:00
Paul Sokolovsky ef63ab5724 py/objstr: Make sure that b"%s" % b"foo" uses undecorated bytes value.
I.e. the expected result for above is b"foo", whereas previously we got
b"b'foo'".
2015-12-20 16:51:59 +02:00
stijn 0a4eb4dbf2 py/mpprint: Fix printing of 64bit integers for 64bit windows builds
This makes all tests pass again for 64bit windows builds which would
previously fail for anything printing ranges (builtin_range/unpack1)
because they were printed as range( ld, ld ).

This is done by reusing the mp_vprintf implementation for MICROPY_OBJ_REPR_D
for 64bit windows builds (both msvc and mingw-w64) since the format specifier
used for 64bit integers is also %lld, or %llu for the unsigned version.

Note these specifiers used to be fetched from inttypes.h, which is the
C99 way of working with printf/scanf in a portable way, but mingw-w64
wants to be backwards compatible with older MS C runtimes and uses
the non-portable %I64i instead of %lld in inttypes.h, so remove the use
of said header again in mpconfig.h and define the specifiers manually.
2015-12-19 01:15:58 +00:00
Damien George fe03e7bcb7 py/obj: Fix float constants for MICROPY_OBJ_REPR_C. 2015-12-18 21:44:01 +00:00
Damien George acaccb37ec py/gc: When printing info, use %u instead of UINT_FMT for size_t args.
Ideally we'd use %zu for size_t args, but that's unlikely to be supported
by all runtimes, and we would then need to implement it in mp_printf.
So simplest and most portable option is to use %u and cast the argument
to uint(=unsigned int).

Note: reason for the change is that UINT_FMT can be %llu (size suitable
for mp_uint_t) which is wider than size_t and prints incorrect results.
2015-12-18 12:52:45 +00:00
Damien George dd5353a405 py: Add MICROPY_ENABLE_COMPILER and MICROPY_PY_BUILTINS_EVAL_EXEC opts.
MICROPY_ENABLE_COMPILER can be used to enable/disable the entire compiler,
which is useful when only loading of pre-compiled bytecode is supported.
It is enabled by default.

MICROPY_PY_BUILTINS_EVAL_EXEC controls support of eval and exec builtin
functions.  By default they are only included if MICROPY_ENABLE_COMPILER
is enabled.

Disabling both options saves about 40k of code size on 32-bit x86.
2015-12-18 12:35:44 +00:00
Damien George ab8012bd80 py/emitglue: Add include of unistd.h for read function. 2015-12-18 12:33:08 +00:00
Damien George a83124361e py/compile: Simplify compilation of comprehension iterators.
Saves 88 bytes on Thumb2, and 200 bytes on x86-64 archs.
2015-12-18 01:37:55 +00:00
Paul Sokolovsky 2eb844e0b4 ports: Rename "machine" module to "umachine".
To let unix port implement "machine" functionality on Python level, and
keep consistent naming in other ports (baremetal ports will use magic
module "symlinking" to still load it on "import machine").

Fixes #1701.
2015-12-18 02:39:52 +02:00
Damien George 2fe7e6bef0 py/parse: Include stddef.h for definition of size_t. 2015-12-17 22:17:26 +00:00
Damien George 02fa8dff85 py/modgc: Remove obsolete extern declaration. 2015-12-17 13:20:40 +00:00
Damien George 831137b807 py/compile: Use size_t or uintptr_t instead of mp_uint_t. 2015-12-17 13:13:18 +00:00
Damien George 16a6a47a7b py/parse: Replace mp_int_t/mp_uint_t with size_t etc, where appropriate. 2015-12-17 13:06:05 +00:00
Damien George 6e2fb56d40 py/qstr: Change type of qstr from mp_uint_t to size_t.
For builds where mp_uint_t is larger than size_t, it doesn't make
sense to use such a wide type for qstrs.  There can only be as many
qstrs as there is address space on the machine, so size_t is the correct
type to use.

Saves about 3000 bytes of code size when building unix/ port with
MICROPY_OBJ_REPR_D.
2015-12-17 12:45:22 +00:00
Damien George 257848587f py/qstr: Use size_t instead of mp_uint_t when counting allocated bytes. 2015-12-17 12:41:40 +00:00
Damien George 1d899e1783 py/bc: Use size_t instead of mp_uint_t to count size of state and args. 2015-12-17 12:33:42 +00:00
Damien George 7a30e87d2b py: Fix MICROPY_STACKLESS mode to compile with MICROPY_OBJ_REPR_D. 2015-12-17 12:32:41 +00:00
Damien George ab1e36dcf9 py/mpprint: Implement %llu and %lld format specifiers for mp_printf.
Only enabled for MICROPY_OBJ_REPR_D.
2015-12-17 11:41:10 +00:00
Damien George d977d268e8 py/gc: Use size_t instead of mp_uint_t to count things related to heap.
size_t is the correct type to use to count things related to the size of
the address space.  Using size_t (instead of mp_uint_t) is important for
the efficiency of ports that configure mp_uint_t to larger than the
machine word size.
2015-12-16 20:09:11 -05:00
Damien George f7782f8082 py/gc: For finaliser, interpret a pointer into the heap as concrete obj. 2015-12-16 19:45:42 -05:00
Damien George 969e4bbe6a py/gc: Scan GC blocks as an array of pointers, not an array of objects.
The GC should search for pointers within the heap.  This patch makes a
difference when an object is larger than a pointer (eg 64-bit NaN
boxing).
2015-12-16 19:41:37 -05:00
Damien George 3911d5af32 py/modsys: Fix module globals table to use MP_ROM_QSTR. 2015-12-16 19:40:14 -05:00
Paul Sokolovsky 1a1cceaf6f py/objpolyiter: Implement instance-polymorphic iterator type.
This allows to have single itertaor type for various internal iterator
types (save rodata space by not having repeating almost-empty type
structures). It works by looking "iternext" method stored in particular
object instance (should be first object field after "base").
2015-12-14 23:48:12 +02:00
Dave Hylands f925165942 unix: Move modmachine into unix directory
This leaves behind the common functionality in extmod/machine_mem.c
which can be used by all ports.
2015-12-13 01:21:36 +02:00
Michael Buesch 17298af61e py/modmath: Add domain error checking to sqrt, log, log2, log10.
These functions will raise 'ValueError: math domain error' on invalid
input.
2015-12-12 15:12:54 +00:00
Damien George 29e9db0c58 py: Fix compiler to handle lambdas used as default arguments.
Addresses issue #1709.
2015-12-12 13:42:51 +00:00
Damien George bdbe8c9ae2 py: Make UNARY_OP_NOT a first-class op, to agree with Py not semantics.
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-12-10 22:19:48 +00:00
Henrik Sölver e242b1785f py/emitinlinethumb: Add support for MRS instruction.
Only IPSR and BASEPRI special registers supported at the moment, but easy
to extend in the future.
2015-12-10 17:32:54 +00:00
Paul Sokolovsky 645045a799 py/mkrules.mk: Don't pass COPT to linker.
Oftentimes, libc, libm, etc. don't come compiled with CPU compressed code
option (Thumb, MIPS16, etc.), but we may still want to use such compressed
code for MicroPython itself.
2015-12-10 00:49:25 +02:00
Damien George e84325bd1d py: Add mp_get_stream_raise to factor out check for stream methods. 2015-12-09 18:47:43 +00:00
Damien George 3ff259a262 py: Fix calling of parent classmethod from instance of subclass.
Addresses issue #1697.
2015-12-09 17:30:01 +00:00
Damien George 33ac0fd09f py: Don't try to optimise for+range when args are not simple expressions.
Addresses issue #1693.
2015-12-08 21:05:14 +00:00
Paul Sokolovsky 946f870e3c py/misc.h: Include stdint.h only once (unconditionally at the top). 2015-12-08 02:23:58 +02:00
Paul Sokolovsky 9f001b09a8 py/misc.h: Include stdint.h, as large share of code now depends on it. 2015-12-07 20:08:07 +02:00
pohmelie c6ee273410 py: Add min/max "default" keyword argument 2015-12-07 18:56:25 +02:00
pohmelie 354e688d8e py: Add MICROPY_PY_BUILTINS_MIN_MAX, disable for minimal ports. 2015-12-07 18:56:25 +02:00
Paul Sokolovsky 2b7236d249 py: Make it easy to build without MICROPY_PY_BUILTINS_COMPLEX.
Automagically skip related modules.
2015-12-07 00:19:24 +02:00
Paul Sokolovsky f2d532c404 py/modsys: Use MP_ROM_PTR() initializer for sys.modules.
Based on similar usage for sys.argv/sys.path.
2015-12-05 00:27:04 +02:00
Paul Sokolovsky 1a1d11fa32 py/modsys: Implement sys.modules.
This for example will allow people to reload modules which didn't load
successfully (e.g. due to syntax error).
2015-12-05 00:13:29 +02:00
Damien George 7a99639cff py: Fix function calls that have positional and a star-arg-with-iterator.
Addresses issue #1678.
2015-12-03 17:59:49 +00:00
Paul Sokolovsky b4eccfd02d py/mpconfig: Actually allow to override MICROPY_BYTES_PER_GC_BLOCK. 2015-12-03 01:58:25 +02:00
Paul Sokolovsky 75feece208 py/gc: Make GC block size be configurable. 2015-12-03 01:40:52 +02:00
fabien.lementec e042f485ed py/mpprint: Printing of doubles is now supported (by uPy own routine). 2015-12-02 14:21:36 +02:00
Damien George b8cfb0d7b2 py: Add support for 64-bit NaN-boxing object model, on 32-bit machine.
To use, put the following in mpconfigport.h:

    #define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_D)
    #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE)
    typedef int64_t mp_int_t;
    typedef uint64_t mp_uint_t;
    #define UINT_FMT "%llu"
    #define INT_FMT "%lld"

Currently does not work with native emitter enabled.
2015-11-29 14:25:36 +00:00
Damien George 999cedb90f py: Wrap all obj-ptr conversions in MP_OBJ_TO_PTR/MP_OBJ_FROM_PTR.
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-11-29 14:25:35 +00:00
Damien George cbf7674025 py: Add MP_ROM_* macros and mp_rom_* types and use them. 2015-11-29 14:25:04 +00:00
Damien George 94fe6e523d py/gc: Move away from using mp_uint_t, instead use uintptr_t and size_t.
The GC works with concrete pointers and so the types should reflect this.
2015-11-29 14:25:04 +00:00
Damien George 254cfa6c31 py: Use uintptr_t instead of mp_uint_t in MP_TAGPTR_* macros. 2015-11-29 14:25:04 +00:00
Damien George 9f6976b74e py: Make mp_setup_code_state take concrete pointer for func arg. 2015-11-29 14:25:04 +00:00
Damien George 5d66b427e2 py/emit: Change type of arg of load_const_obj from void* to mp_obj_t. 2015-11-29 14:25:04 +00:00
Damien George c3f64d9799 py: Change qstr_* functions to use size_t as the type for str len arg. 2015-11-29 14:25:04 +00:00
Damien George 4e7107a572 py: Change mp_print_strn_t func type to use size_t for the str length. 2015-11-29 14:25:04 +00:00
Damien George 0786716c5a py/asmx86: Fix function definition to use int32_t instead of int. 2015-11-27 14:06:53 +00:00
Damien George 88a9103b3c py/binary: Make use of MP_ALIGN. 2015-11-27 12:05:11 +00:00
Paul Sokolovsky f32020ef3d py/mpconfig.h: Allow to build without alloca() for ANSI C compliance.
Define MICROPY_NO_ALLOCA=1 and memory will be allocated from heap instead
and freed by garbage collection.
2015-11-25 23:24:51 +02:00
Paul Sokolovsky f0fbab7ca7 extmod/fsusermount: Make configurable with MICROPY_FSUSERMOUNT. 2015-11-25 13:19:36 +02:00
Paul Sokolovsky 3a1bbcc2ef extmod: Move fsusermount.c from stmhal for cross-port reuse. 2015-11-25 13:19:36 +02:00
stijn 3baf6b5319 windows/py: Support 64bit mingw-w64 builds
- add mp_int_t/mp_uint_t typedefs in mpconfigport.h
- fix integer suffixes/formatting in mpconfig.h and mpz.h
- use MICROPY_NLR_SETJMP=1 in Makefile since the current nlrx64.S
  implementation causes segfaults in gc_free()
- update README
2015-11-24 17:34:14 +02:00
stijn bf1570cb25 nlr: Use single preprocessor symbol to check if building on Windows 2015-11-24 17:34:14 +02:00
Damien George 9a56912ad1 py/compile: Do proper checking of * and ** in function definition.
This patch checks that there is only one *, and that ** is last in the
arg list.
2015-11-23 16:50:42 +00:00
Damien George 0e3f29cc99 py: Check that second argument to hasattr is actually a string.
Fixes issue #1623.
2015-11-23 15:57:00 +00:00
Damien George 44e6e348d6 py/emitglue: Implement persistent saving and loading of const objects. 2015-11-23 11:54:12 +00:00
Damien George 39a8deb95f py/emitglue: Add feature-flag header to .mpy to detect bytecode compat.
Loading .mpy files will now check to make sure that the target VM can
support the bytecode.
2015-11-23 10:58:16 +00:00
Paul Sokolovsky b3be4710aa py/mpz: Normalize (remove leading zeros) xor operation result. 2015-11-22 22:03:18 +02:00
Paul Sokolovsky 3d6240ba1b py/formatfloat: Handle calculation of integer digit for %f format properly.
%f prints true integer digit, so its calculation should happen before any
exponential scaling.
2015-11-22 20:05:08 +02:00
Paul Sokolovsky 3c4c069802 py/formatfloat: Workaround (fix?) incorrect rounding for %f format. 2015-11-22 18:09:28 +02:00
Paul Sokolovsky 9aaccd4735 py/formatfloat: Convert to fully portable implementation.
This takes previous IEEE-754 single precision float implementation, and
converts it to fully portable parametrizable implementation using C99
functions like signbit(), isnan(), isinf(). As long as those functions
are available (they can be defined in adhoc manner of course), and
compiler can perform standard arithmetic and comparison operations on a
float type, this implementation will work with any underlying float type
(including types whose mantissa is larger than available intergral integer
type).
2015-11-22 17:54:05 +02:00
Paul Sokolovsky 295ea12411 py/emitglue: Host definition of mp_verbose_flag.
This may not seem like the ideal place, but is actually the only place
in py/ where it gets referenced, so is just right.
2015-11-21 16:54:15 +02:00
Paul Sokolovsky 72bd172b30 py/modsys: Consistently use indented #if's. 2015-11-21 16:03:37 +02:00
Damien George 83229d3ffe py: Use MP_OBJ_NULL instead of NULL when appropriate. 2015-11-20 14:09:20 +00:00
Damien George b5b1f2c527 py/emitglue: Add mp_raw_code_load_mem to load raw-code from memory. 2015-11-20 12:44:20 +00:00
Damien George f148727b78 py/emitglue: Only compile raw-code fatfs loader when on thumb2 platform.
Here we are assuming that a thumb2 port will have fatfs, which is only
roughly true.  We need a better way of enabling specific raw-code file
readers.
2015-11-20 12:42:26 +00:00
Damien George d4dba88236 py/compile: Add mp_compile_to_raw_code() to return raw code object.
This can then be passed to mp_raw_code_save_file to save a .mpy file.
2015-11-20 12:30:37 +00:00
Igor Gatis f5c554dfe3 py: Added Cygwin support to py/nlrx86.S. 2015-11-19 20:23:43 +02:00
Damien George 593faf14c4 py/map: Store key/value in earliest possible slot in hash table.
This change makes the code behave how it was supposed to work when first
written.  The avail_slot variable is set to the first free slot when
looking for a key (which would come from deleting an entry).  So it's
more efficient (for subsequent lookups) to insert a new key into such a
slot, rather than the very last slot that was searched.
2015-11-19 01:27:28 +00:00
Damien George 994ff738c8 py/mpstate: Make mp_pending_exception volatile.
It can change asynchronously.
2015-11-17 14:27:21 +00:00
Damien George a24eafacc9 py/modmath: Make log2, log10 and hyperbolic funcs be SPECIAL_FUNCTIONS.
Will be included only when MICROPY_PY_MATH_SPECIAL_FUNCTIONS is enabled.

Also covers cmath module (but only log10 is there at the moment).
2015-11-17 14:10:13 +00:00
Damien George 2c83894257 py: Implement default and star args for lambdas. 2015-11-17 14:00:14 +00:00
Damien George cbd9ae5256 py/compile: Don't unnecessarily save state when compiling param list.
Parameter lists can't be nested so there is no need to save the global
state when compiling them.
2015-11-17 12:37:02 +00:00
Paul Sokolovsky 863d4cd862 py/modmath: Don't create symbol entry for expm1() if not needed. 2015-11-14 00:55:54 +02:00
Paul Sokolovsky 0d6116d86b py/modmath: Make expm1() be in MICROPY_PY_MATH_SPECIAL_FUNCTIONS. 2015-11-14 00:46:52 +02:00
Paul Sokolovsky 6d1eabfeaa unix/mpconfigport: Move log2() definition to modmath.c.
It's safer to define it where it's used, defining it for all source files
may lead to hard to diagnose conflicts in corner cases.
2015-11-13 15:24:48 +02:00
Damien George 432e8275a9 py: Allow to import compiled bytecode files. 2015-11-13 12:49:18 +00:00
Damien George d8c834c95d py: Add MICROPY_PERSISTENT_CODE_LOAD/SAVE to load/save bytecode.
MICROPY_PERSISTENT_CODE must be enabled, and then enabling
MICROPY_PERSISTENT_CODE_LOAD/SAVE (either or both) will allow loading
and/or saving of code (at the moment just bytecode) from/to a .mpy file.
2015-11-13 12:49:18 +00:00
Damien George c8e9c0d89a py: Add MICROPY_PERSISTENT_CODE so code can persist beyond the runtime.
Main changes when MICROPY_PERSISTENT_CODE is enabled are:

- qstrs are encoded as 2-byte fixed width in the bytecode
- all pointers are removed from bytecode and put in const_table (this
  includes const objects and raw code pointers)

Ultimately this option will enable persistence for not just bytecode but
also native code.
2015-11-13 12:49:18 +00:00
Damien George 713ea1800d py: Add constant table to bytecode.
Contains just argument names at the moment but makes it easy to add
arbitrary constants.
2015-11-13 12:49:18 +00:00