Wykres commitów

70 Commity (ed56b0baba47e4d0697fdc2d81310a9a2c34c5df)

Autor SHA1 Wiadomość Data
Paul Sokolovsky 3d3ef36e97 modstruct: Rename module to "ustruct", to allow full Python-level impl. 2015-05-04 16:53:52 +03: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
Damien George 7e758b1cf8 stmhal, qemu-arm: Enable sys.maxsize attribute. 2015-04-04 22:04:53 +01:00
Damien George 40fc01f406 stmhal: Enable new str.splitlines() method. 2015-04-04 16:02:23 +01:00
stijn 3cc17c69ff py: Allow retrieving a function's __name__.
Disabled by default.  Enabled on unix and stmhal ports.
2015-03-20 23:13:32 +00:00
Paul Sokolovsky 0ef01d0a75 py: Implement core of OrderedDict type.
Given that there's already support for "fixed table" maps, which are
essentially ordered maps, the implementation of OrderedDict just extends
"fixed table" maps by adding an "is ordered" flag and add/remove
operations, and reuses 95% of objdict code, just making methods tolerant
to both dict and OrderedDict.

Some things are missing so far, like CPython-compatible repr and comparison.

OrderedDict is Disabled by default; enabled on unix and stmhal ports.
2015-03-20 17:26:10 +00:00
Damien George 42e0c59308 py: Add MICROPY_COMP_{DOUBLE,TRIPLE}_TUPLE_ASSIGN config options.
These allow to fine-tune the compiler to select whether it optimises
tuple assignments of the form a, b = c, d and a, b, c = d, e, f.
Sensible defaults are provided.
2015-03-14 13:11:35 +00:00
Damien George 565da3f569 stmhal: Enable MICROPY_PY_ARRAY_SLICE_ASSIGN. 2015-03-02 13:45:35 +00:00
Damien George 5cbeacebdb py: Make math special functions configurable and disabled by default.
The implementation of these functions is very large (order 4k) and they
are rarely used, so we don't enable them by default.

They are however enabled in stmhal and unix, since we have the room.
2015-02-22 14:48:18 +00:00
Henrik Sölver f80f1a7077 stmhal: Add support for CAN rx callbacks. 2015-02-15 03:10:53 +00:00
Damien George d39c7aa517 stmhal: Add Python-configurable USB HID mode.
Different HID modes can be configured in Python.  You can either use
predefined mouse or keyboard, or write your own report descriptor.
2015-02-13 14:02:51 +00:00
Damien George ad33e2465c stmhal: Disable MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE.
It uses RAM and on pyboard we are generally tight on RAM, so disable
this optimisation for general builds.  If users need the speed then
they can build their own version.  Maybe in the future we can have
different versions of pyboard firmware built with different tradeoffs.
2015-01-24 23:45:37 +00:00
Damien George 8b77e3dd2f stmhal: Put mod_network_nic_list in global root-pointer state.
It needs to be scanned by GC.  Thanks to Daniel Campora.
2015-01-22 00:16:41 +00:00
Damien George ddd1e18801 py: Add config option MICROPY_COMP_MODULE_CONST for module consts.
Compiler optimises lookup of module.CONST when enabled (an existing
feature).  Disabled by default; enabled for unix, windows, stmhal.
Costs about 100 bytes ROM on stmhal.
2015-01-10 14:07:24 +00:00
Damien George 89deec0bab py: Add MICROPY_PY_MICROPYTHON_MEM_INFO to enable mem-info funcs.
This allows to enable mem-info functions in micropython module, even if
MICROPY_MEM_STATS is not enabled.  In this case, you get mem_info and
qstr_info but not mem_{total,current,peak}.
2015-01-09 20:12:54 +00:00
Damien George 4a5895c4eb py: Disable stack checking by default; enable on most ports. 2015-01-09 00:10:55 +00:00
Damien George 3b51b3e90f stmhal: Collect all root pointers together in 1 place.
A GC in stmhal port now only scans true root pointers, not entire BSS.
This reduces base GC time from 1700ms to 900ms.
2015-01-07 23:38:50 +00:00
Damien George 7ee91cf861 py: Add option to cache map lookup results in bytecode.
This is a simple optimisation inspired by JITing technology: we cache in
the bytecode (using 1 byte) the offset of the last successful lookup in
a map. This allows us next time round to check in that location in the
hash table (mp_map_t) for the desired entry, and if it's there use that
entry straight away.  Otherwise fallback to a normal map lookup.

Works for LOAD_NAME, LOAD_GLOBAL, LOAD_ATTR and STORE_ATTR opcodes.

On a few tests it gives >90% cache hit and greatly improves speed of
code.

Disabled by default.  Enabled for unix and stmhal ports.
2015-01-07 21:07:23 +00:00
Damien George f3a1d673de stmhal: Enable ubinascii module, weak link to binascii. 2014-12-24 16:24:42 +00:00
Damien George 2a3e2b9033 py: Add execfile function (from Python 2); enable in stmhal port.
Adds just 60 bytes to stmhal binary.  Addresses issue #362.
2014-12-19 13:36:17 +00:00
Damien George 78d702c300 py: Allow builtins to be overridden.
This patch adds a configuration option (MICROPY_CAN_OVERRIDE_BUILTINS)
which, when enabled, allows to override all names within the builtins
module.  A builtins override dict is created the first time the user
assigns to a name in the builtins model, and then that dict is searched
first on subsequent lookups.  Note that this implementation doesn't
allow deleting of names.

This patch also does some refactoring of builtins code, creating the
modbuiltins.c file.

Addresses issue #959.
2014-12-09 16:19:48 +00:00
Damien George 92f1ed8f40 stmhal: Enable uhashlib module; add heapq, hashlib weak links.
hashlib test passes on pyboard.
2014-11-27 17:54:37 +00:00
Paul Sokolovsky fa2edabc5c stmhal: Switch to file.seek() implementation using stream ioctl. 2014-11-17 00:16:14 +02:00
Damien George 9a41b32b3f stmhal: Add ioctl to USB_VCP object, so it works with select.
This patch also enables non-blocking streams on stmhal port.

One can now make a USB-UART pass-through function:

def pass_through(usb, uart):
    while True:
        select.select([usb, uart], [], [])
        if usb.any():
            uart.write(usb.read(256))
        if uart.any():
            usb.write(uart.read(256))

pass_through(pyb.USB_VCP(), pyb.UART(1, 9600))
2014-10-31 00:12:02 +00:00
Damien George dd4f4530ab py: Add builtin memoryview object (mostly using array code). 2014-10-23 13:34:35 +01:00
Damien George f5d69794a8 extmod: Add uheapq module. 2014-10-22 23:20:15 +01:00
Damien George 4b71c056ef moduzlib: Fix fn prototype and some code style; use it in stmhal port. 2014-10-12 23:35:38 +01:00
Damien George 0107e90328 stmhal: Enable module weak links.
os, time, select modules are now prefixed with u, but are still
available (via weak links) as their original names.

ure and ujson now available as re and json via weak links.
2014-10-12 20:23:47 +01:00
Damien George dd5ee9ff9c stmhal: Enable ure module (tests pass on pyboard). 2014-10-11 18:55:12 +01:00
Damien George 3a1c4c5bc6 stmhal: Add network and usocket module.
As per issue #876, the network module is used to configure NICs
(hardware modules) and configure routing.  The usocket module is
supposed to implement the normal Python socket module and selects the
underlying NIC using routing logic.

Right now the routing logic is brain dead: first-initialised,
first-used.  And the routing table is just a list of registered NICs.

cc3k and wiznet5k work, but not at the same time due to C name clashes
(to be fixed).

Note that the usocket module has alias socket, so that one can import
socket and it works as normal.  But you can also override socket with
your own module, using usocket at the backend.
2014-09-30 22:36:47 +01:00
Damien George b766e79510 stmhal: Initial implementation of cc3k module and driver.
Pulled in and modified work done by mux/iabdalkader on cc3k driver, from
iabdalkader-cc3k-update branch.  That branch was terribly messy and had
too many conflicts to merge neatly.
2014-09-26 00:57:26 +01:00
Damien George 612045f53f py: Add native json printing using existing print framework.
Also add start of ujson module with dumps implemented.  Enabled in unix
and stmhal ports.  Test passes on both.
2014-09-17 22:56:34 +01:00
Damien George 013d53c0b4 Remove skeletal modselect from extmod and just put it in stmhal. 2014-09-07 20:42:01 +01:00
Damien George 6c9c7bc75a stmhal: Implement generic select.select and select.poll. 2014-09-07 20:40:32 +01:00
Damien George bcf041f1a3 stmhal: Add wiznet5k module, to control WIZnet ethernet adaptor.
Allows to create socket objects that support TCP and UDP in server and
client mode.  Interface is very close to standard Python socket class,
except bind and accept do not work the same (due to hardware not
supporting them in the usual way).

Not compiled by default.  To compile this module, use:
make MICROPY_PY_WIZNET5K=1
2014-09-01 22:52:38 +01:00
Damien George e5cbb70328 stmhal: Make enable_irq and disable_irq inline functions.
These functions are generally 1 machine instruction, and are used in
critical code, so makes sense to have them inline.

Also leave these functions uninverted (ie 0 means enable, 1 means
disable) and provide macro constants if you really need to distinguish
the states.  This makes for smaller code as well (combined with
inlining).

Applied to teensy port as well.
2014-08-25 13:24:33 +01:00
Dave Hylands 9480138f0c Add save/restore_irq
Factored irq functions into a separate file.
2014-08-25 12:22:11 +01:00
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.
2014-08-24 16:28:17 +01:00
Damien George 1ddd844815 extmod: Finish rename of zlib to zlibd; enable zlibd on stmhal. 2014-08-12 23:23:53 +01:00
Damien George 105e32f1a5 stmhal: Enable moductypes by default.
Also fixes compiler error in moductypes when compiled without debugging.

Addresses issue #778.
2014-08-12 20:02:26 +01:00
Dave Hylands 5b7fd20fea Add support for storing args during an exception raised by an irq.
The user code should call micropython.alloc_emergency_exception_buf(size)
where size is the size of the buffer used to print the argument
passed to the exception.

With the test code from #732, and a call to
micropython.alloc_emergenncy_exception_buf(100) the following error is
now printed:
```python
>>> import heartbeat_irq
Uncaught exception in Timer(4) interrupt handler
Traceback (most recent call last):
  File "0://heartbeat_irq.py", line 14, in heartbeat_cb
NameError: name 'led' is not defined
```
2014-07-25 14:00:06 -07:00
Damien George 1694bc733d py: Add stream reading of n unicode chars; unicode support by default.
With unicode enabled, this patch allows reading a fixed number of
characters from text-mode streams; eg file.read(5) will read 5 unicode
chars, which can made of more than 5 bytes.

For an ASCII stream (ie no chars > 127) it only needs to do 1 read.  If
there are lots of non-ASCII chars in a stream, then it needs multiple
reads of the underlying object.

Adds a new test for this case.  Enables unicode support by default on
unix and stmhal ports.
2014-07-19 18:34:04 +01: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
Damien George 7a37f647a5 Merge branch 'teensy-new' of github.com:dhylands/micropython into dhylands-teensy-new
Conflicts:
	stmhal/pin_named_pins.c
	stmhal/readline.c

Renamed HAL_H to MICROPY_HAL_H.  Made stmhal/mphal.h which intends to
define the generic Micro Python HAL, which in stmhal sits above the ST
HAL.
2014-07-02 13:42:37 +01:00
Damien George 635b60e299 unix, stmhal: Add option for STR_UNICODE to mpconfigport.h.
Unicode is disabled by default for now, since FileIO.read(n) is
currently not implemented for text-mode files, and this is an
often function.
2014-06-28 10:29:52 +01:00
Dave Hylands 4f1b7fec9f Updated teensy to build.
Refactored some stmhal files which are shared with teensy.
2014-06-15 22:48:05 -07:00
Damien George b7572ad11b stmhal, file: Implement a,x,+ open modes, seek and tell.
Also now returns correct POSIX errno when an IO operation fails.

Addresses issues #516 and #676.
2014-06-11 15:41:14 +01:00
Damien George 4480cb3711 Provide definition of alloca() in mpconfigport.h. 2014-06-08 13:25:33 +01: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 ee3fd46f13 Rename configuration variables controling Python features.
Now of the form MICROPY_PY_*.  See issue #35.
2014-05-24 23:03:12 +01:00