Commit Graph

373 Commits

Author SHA1 Message Date
Damien George 07133415d2 Merge pull request #738 from dhylands/except-args
Add support for storing args during an exception raised by an irq.
2014-07-29 23:15:35 +01:00
Paul Sokolovsky d0f5e61ab5 py: Implement __file__ attribute for modules. 2014-07-28 21:21:59 +03:00
Damien George adf0f2ae1a py: Change stream protocol API: fns return uint; is_text for text. 2014-07-27 22:38:58 +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 04c9fec7d1 Merge pull request #757 from stinos/windows-fsync
Add fsync for windows, i.e. _commit. See dce8876
2014-07-19 18:40:49 +01: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
stijn 73ab8cc21d Add fsync for windows, i.e. _commit. See dce8876 2014-07-16 09:37:09 +02:00
Paul Sokolovsky dce8876dbe unix: file: No fsync() on Windows. 2014-07-13 23:34:35 +03:00
Paul Sokolovsky 122c9db3db unix: file: Implement .flush() method.
This method apparently should be part of stream interface.
2014-07-13 23:14:24 +03:00
Paul Sokolovsky b82f34edde unix: Allow to disable MICROPY_EMIT_X64 from commandline.
emitnative in particular requires nlr_* to be real functions, so doesn't
compile with MICROPY_NLR_SETJMP=1.
2014-07-13 13:49:51 +03:00
Paul Sokolovsky 8215847b4d moductypes: Foreign data interface module, roughly based on ctype ideas.
But much smaller and memory-efficient. Uses Python builtin data structures
(dict, tuple, int) to describe structure layout.
2014-07-09 19:28:24 +03:00
Paul Sokolovsky 4e0eeebdc2 py: Implement sys.maxsize, standard way to check platform "bitness".
Implementing it as a static constant is a bit peculiar and require cooperation
from long int implementation.
2014-07-03 18:09:36 +03: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 caa7334141 stackctrl: Add "mp_" prefix. 2014-07-01 02:14:08 +03:00
Paul Sokolovsky e95b6b5e07 modffi: Add special 'C' code for passing a callback function pointer. 2014-07-01 02:05:34 +03:00
Paul Sokolovsky bb35f425f9 Merge pull request #730 from stinos/windows-mpconfig
windows: Sync mpconfigport.h with the unix' version
2014-06-29 20:50:16 +03:00
Paul Sokolovsky a23475979b modffi: Support short types. 2014-06-29 15:48:21 +03:00
stijn ec6fa8732b windows: Sync mpconfigport.h with the unix' version
- rearrange/add definitions that were not there so it's easier to compare both
- use MICROPY_PY_SYS_PLATFORM in main.c since it's available anyway
- define EWOULDBLOCK, it is missing from ingw32
2014-06-29 09:40:20 +02:00
stijn 5478ed18ea unix: Fix mpconfig.h not being included before misc.h
This fixes count_lead_ones in misc.h not compiling due to unknown types
2014-06-28 20:49:39 +02: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
Paul Sokolovsky 8a96ebea75 py: Move stack_ctrl_init() to mp_init().
As stack checking is enabled by default, ports which don't call
stack_ctrl_init() are broken now (report RuntimeError on startup). Save
them trouble and just init stack control framework in interpreter init.
2014-06-27 21:02:04 +03:00
Paul Sokolovsky 3c8ce38d20 Merge pull request #717 from stinos/dead-code
unix: Remove unused CTRL-D definition
2014-06-27 01:23:18 +03:00
Paul Sokolovsky 23668698cb py: Add portable framework to query/check C stack usage.
Such mechanism is important to get stable Python functioning, because Python
function calling is handled with C stack. The idea is to sprinkle
STACK_CHECK() calls in places where there can be C recursion.

TODO: Add more STACK_CHECK()'s.
2014-06-27 00:03:55 +03:00
stijn 39b6e27944 unix: Remove unused CTRL-D definition 2014-06-25 13:33:10 +02:00
Paul Sokolovsky 939c2e7f44 Merge pull request #690 from stinos/msvc-gc
msvc: Enable GC
2014-06-24 21:34:51 +03:00
Paul Sokolovsky 3c9b24bebe modsocket: Fix uClibc detection. 2014-06-24 21:20:38 +03:00
Paul Sokolovsky 141df2d350 unix: Dump default heap size in usage message. 2014-06-24 16:58:00 +03:00
Paul Sokolovsky cd590cbfaa unix: Don't error out on #warning directive. 2014-06-22 19:20:55 +03:00
Paul Sokolovsky ff5932a8d8 modsocket: Workaround uClibc issue with numeric port for getaddrinfo().
It sucks to workaround this on uPy side, but upgrading not upgradable
embedded systems sucks even more.
2014-06-22 19:20:55 +03:00
Paul Sokolovsky 949a49c9da modsocket: Add call to freeaddrinfo(). 2014-06-22 19:11:34 +03:00
Paul Sokolovsky 69d0a1c540 unix: uClibc doesn't like NULL as a buffer arg to realpath().
So, allocate one explicitly.
2014-06-22 19:08:32 +03:00
stijn de5ce6d461 gc: Use simple cast instead of union to silence compiler 2014-06-22 11:32:32 +02:00
stijn 8abcf666cb windows: Enable GC and implement bss start and end symbols
The pointers to the bss section are acquired in init.c()
by inspecting the PE header. Works for msvc and mingw.
2014-06-22 11:31:16 +02:00
Paul Sokolovsky a96cc824bd py: Support arm and thumb ARM ISAs, in addition to thumb2.
These changes were tested with QEMU, and by few people of real hardware.
2014-06-22 01:40:45 +03:00
Paul Sokolovsky 17a49431d4 unix: Allow to override MICROPY_GCREGS_SETJMP from cmdline. 2014-06-20 20:22:31 +03:00
Paul Sokolovsky 7cd46a12ae unix: Add CFLAGS_EXTRA & LDFLAGS_EXTRA for command line usage.
The idea is that it should be possible to pass any additional params for
experimentation without need to patch sources (and without need to deviate
from or repeat baseline options).
2014-06-20 20:21:21 +03:00
Paul Sokolovsky 7e56e55252 unix: Refactor order file munging fo MacOSX. 2014-06-20 20:21:11 +03:00
Paul Sokolovsky eecf3e90c6 unix: Group CFLAGS related stuff together. 2014-06-20 20:21:11 +03:00
Paul Sokolovsky 2099b6897f unix: Allow to override compiler warning options without touching the rest.
Some people want to enable even more warnings. Let them do it without putting
burden on everyone. Some people vice versa think that current settings should
be relaxed. In this regard, -Werror is the most problematic, it disallows to
use #warning directive, and disallows to pass configuration settings on make
command lines. Again, until decided how to deal with these globally, allow to
work around these problems locally.
2014-06-20 20:18:08 +03:00
Emmanuel Blot f6932d6506 Prefix ARRAY_SIZE with micropython prefix MP_ 2014-06-19 18:54:34 +02:00
Damien George 4480cb3711 Provide definition of alloca() in mpconfigport.h. 2014-06-08 13:25:33 +01:00
Damien George df896eceef Merge branch 'alloca' of github.com:marcusva/micropython into marcusva-alloca 2014-06-08 13:18:14 +01:00
Paul Sokolovsky b9b9354e6c modsys: Add optional support for sys.platform.
Ports which wants to have it, should define MICROPY_PY_SYS_PLATFORM to a
string value they need.
2014-06-07 23:40:04 +03:00
Damien George a9b5248e18 Merge pull request #672 from marcusva/makefile
toolchain fixes to enable cross compatibility
2014-06-07 13:03:29 +01:00
Marcus von Appen 585a3394df - Cast the struct stat sb.st_ino field to machine_int_t explicitly to avoid a
cast error in MP_OBJ_NEW_SMALL_INT(). This is necessary for FreeBSD, where
  st_ino is of different size
- If MP_CLOCKS_PER_SEC is defined on the target host, simply define CLOCK_DIV
  as a fraction, regardless of the value of MP_CLOCKS_PER_SEC.
  FreeBSD uses a non-POSIX compliant value of 128 for CLOCKS_PER_SEC
2014-06-07 09:50:18 +02:00
Marcus von Appen 0c90eb1658 - FreeBSD provides alloca() via stdlib.h, in contrast to Linux and Windows
- Move the includes for alloca() intp mpconfigport.h
2014-06-07 09:36:04 +02:00
Marcus von Appen 8ffc02495f - Let the build environment decide about the toolchain to be used, in case
there are special tweaks and paths to be considered. Just provide some
  defaults, in case the values are undefined.
- py-version.sh does not need any bash specific features.
- Use libdl only on Linux for now. FreeBSD provides dl*() calls from libc.
2014-06-07 09:16:42 +02:00
Damien George c61be8e1e1 Merge pull request #662 from stinos/windows-pathsep
unix: Fix path seperator used depending on OS
2014-06-07 00:05:59 +01:00
Paul Sokolovsky 755a55f507 modgc: Implement return value for gc.collect(), enable on Unix. 2014-06-05 22:48:02 +03:00
stijn df3ab07994 unix: Fix path seperator used depending on OS
';' is the standard seperator used for paths in environment variables on Windows
2014-06-05 12:34:41 +02:00
Paul Sokolovsky 76c8a4c91b unix: Add setjmp-based GC register helper implementation.
As I suspected for a long time, for x86, register helper doesn't really make
any difference - there's simply not enough register to keep anything in
them for any prolonged time. Anything gets pushed on stack anyway. So, on
x86, uPy passed all tests even with empty reg helper. So, this setjmp
implementation goes as "untested".
2014-06-05 04:32:17 +03:00
Paul Sokolovsky d3439d0c60 py: Instead of having "debug on" var, have "optimization level" var.
This allows to have multiple "optimization" levels (CPython has two
(-OO removes docstrings), we can have more).
2014-06-03 12:32:59 +03:00
Paul Sokolovsky dd0dee3afc unix: Properly print script filename in case of error. 2014-06-03 01:26:43 +03: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
Paul Sokolovsky 3dfa76cb85 unix: 64-bit cleanness. 2014-05-31 03:19:15 +03:00
Paul Sokolovsky 914bcf16d8 unix: Add poorman's stack usage info to mem_info() dump. 2014-05-31 02:34:39 +03:00
Paul Sokolovsky 347b3a3d1f modsocket: Add some comments on intended usage/API design of module. 2014-05-31 01:48:26 +03:00
Paul Sokolovsky 50b08c920a modsocket: Remove stale ifdef. 2014-05-31 01:41:41 +03:00
Paul Sokolovsky 1d567592b1 unix/gccollect.c: Make Clang workaround apply only to it. Unbreaks gcc builds. 2014-05-28 15:37:22 +03:00
Paul Sokolovsky 168a9ce863 Revert "Fix DEBUG=1 builds"
This reverts commit 6e76f7bc90.

This patch tries to workaround a previous clang workaround. Instead of going
into workaround of workaround spiral, the original workaround should be tamed.
2014-05-28 15:28:30 +03:00
Dave Hylands 6e76f7bc90 Fix DEBUG=1 builds
Without this fix, I get the following error:

CC gccollect.c
gccollect.c: In function ‘gc_helper_get_regs’:
gccollect.c:63:1: error: bp cannot be used in asm here
2014-05-26 16:29:24 -07:00
Paul Sokolovsky 0405b2210d modos: stat(): Accept bytes argument. 2014-05-26 02:02:47 +03:00
Damien George 2617eebf2f Change const byte* to const char* where sensible.
This removes need for some casts (at least, more than it adds need
for new casts!).
2014-05-25 22:27:57 +01:00
Damien George 7a4ddd2428 Add SystemExit exception and use it in unix/ and stmhal/ ports.
Addresses issue #598.
2014-05-24 23:32:19 +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
Paul Sokolovsky d0ceb04b90 modsocket: 64-bit cleanness. 2014-05-24 23:00:09 +03:00
Paul Sokolovsky 561789d718 unix modsocket: Make .makefile() method more compliant.
.makefile() should allow to specify which stream time to create - byte
or text.
2014-05-24 21:24:37 +03:00
Damien George efaef6eea3 unix: Fix casting issue, int to small int object. 2014-05-21 20:53:56 +01:00
Damien George 58ebde4664 Tidy up some configuration options.
MP_ALLOC_* -> MICROPY_ALLOC_*
MICROPY_PATH_MAX -> MICROPY_ALLOC_PATH_MAX
MICROPY_ENABLE_REPL_HELPERS -> MICROPY_HELPER_REPL
MICROPY_ENABLE_LEXER_UNIX -> MICROPY_HELPER_LEXER_UNIX
MICROPY_EXTRA_* -> MICROPY_PORT_*

See issue #35.
2014-05-21 20:32:59 +01:00
Damien George 63436ce22e unix, Mac support: Generate order.def via Makefile. 2014-05-21 19:56:54 +01:00
Damien George 0fd01683c6 Merge pull request #607 from Anton-2/osx-clang
Allow compilation of unix port under clang on OS X
2014-05-21 19:51:05 +01:00
Paul Sokolovsky 9e29666bf9 py: Implement proper separation between io.FileIO and io.TextIOWrapper.
io.FileIO is binary I/O, ans actually optional. Default file type is
io.TextIOWrapper, which provides str results. CPython3 explicitly describes
io.TextIOWrapper as buffered I/O, but we don't have buffering support yet
anyway.
2014-05-19 21:56:07 +03:00
Paul Sokolovsky 767e45c290 modos: Clean 64-bit issues. 2014-05-15 18:38:54 +03:00
Paul Sokolovsky 0c124c3123 unix: Add "_os" module with stat().
stat() is bad function to use using FFI, because its ABI is largely private.
To start with, Glibc .so doesn't even have "stat" symbol. Then, layout of
struct stat is too implementation-dependent. So, introduce _os to deal
with stat() and other similar cases.
2014-05-14 22:08:45 +03:00
Damien George f6e430f77f Merge pull request #600 from stinos/unix-exitcode
unix: Use standard return codes for main
2014-05-13 22:39:35 +01:00
Paul Sokolovsky da9f0924ef py, unix: Add copyright for modules I worked closely on. 2014-05-13 18:41:25 +03:00
Damien George cc97446ca5 unix: Implement -O option to turn off __debug__ flag. 2014-05-12 23:14:52 +01:00
Damien George 96f137b24a py: Rename BYTE_CODE to BYTECODE (this was missed in previous rename). 2014-05-12 22:35:37 +01:00
stijn f42dbb98d1 unix: Fix linker errors when time/ffi modules are disabled
When disabling these via mpconfigport.mk or on the commandline,
the correspoding build options are not set and the sources are not
built so the modules should not be added to the
MICROPY_EXTRA_BUILTIN_MODULES list since they are undefined.
2014-05-13 00:03:24 +03:00
Antonin ENFRUN da1fffaa09 Fix some unused variables, and silence a clang warning about initialization override in vmentrytable.h 2014-05-12 09:06:18 +02:00
Antonin ENFRUN ceac71f1f5 unix: Add asm statements needed to read registers with clang. Code generated by gcc 4.9.0 is unchanged (same statements, different order).
Both are inefficient, saving unmodified registers on the stack.
2014-05-12 09:06:18 +02:00
Antonin ENFRUN 6caae0bcb1 unix: Create __bss_start and _end symbols for Mach-O targets.
It's a hack, but can't find a cleaner way to do it.
2014-05-12 00:13:10 +02:00
stijn 9e040b7cd8 unix: Use standard return codes for main
As in the CPython manual: "Unix programs generally use 2 for
command line syntax errors and 1 for all other kind of errors"
2014-05-11 19:23:30 +02:00
Damien George 89755ae67f py: Rename MICROPY_SYS_EXIT to MICROPY_MOD_SYS_EXIT.
For consistency with MICROPY_MOD_SYS_STDFILES, etc.
2014-05-11 17:35:43 +01:00
Damien George bd651d1a67 Merge pull request #597 from stinos/mingw-compilation
mingw: Fix compilation issues
2014-05-11 15:06:26 +01:00
Paul Sokolovsky deaeaac469 modsys: Enable sys.exit() per port after all. 2014-05-10 17:26:47 +03:00
Paul Sokolovsky d99e9083cb modsys, unix: Add sys.exit(), should be implemented by a port. 2014-05-10 16:56:21 +03:00
Paul Sokolovsky d80e2476c7 py: Disable frozenset by default, enable on unix.
Takes 416 text bytes on x86.
2014-05-10 16:56:20 +03:00
stijn f45a83d7fc mingw: Fix compilation issues
- use lowercase windows.h
- fix for mingw32 using preprocessor-unfriendly definition of CLOCKS_PER_SEC
2014-05-10 10:42:40 +02:00
stijn 5ed284a15e windows: Add modtime implementation 2014-05-09 13:58:15 +02:00
Damien George 7c6c843965 unix: Add missing stdio.h header for readline. 2014-05-07 15:33:15 +01:00
Dave Hylands 117c46d9eb Add input command for unix 2014-05-07 07:19:51 -07:00
Paul Sokolovsky 0ef015b253 stream: Make non-blcoking stream support configurable.
Enable only on unix. To avoid unpleasant surprises with error codes.
2014-05-07 02:25:45 +03:00
Paul Sokolovsky 6c62e7257f unix modsocket: Add comments re: recv() vs read(), etc. semantics. 2014-05-07 02:17:14 +03:00
Paul Sokolovsky f9e54e0ea5 modgc: Add new module for GC-related functionality. 2014-05-06 02:28:49 +03:00
Paul Sokolovsky 6b344d7816 py, unix: Add -v option, print bytecode dump if used.
This will work if MICROPY_DEBUG_PRINTERS is defined, which is only for
unix/windows ports. This makes it convenient to user uPy normally, but
easily get bytecode dump on the spot if needed, without constant recompiles
back and forth.

TODO: Add more useful debug output, adjust verbosity level on which
specifically bytecode dump happens.
2014-05-05 00:57:00 +03:00
Damien George c327c0de5d unix: Remove test class and code. 2014-05-04 12:24:26 +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 d5f5b2f766 py, stream: Implement readlines for a stream. 2014-05-03 22:01:32 +01:00
Damien George 6ec835dfef Don't print git hash as well as git tag in banner. 2014-05-03 19:08:02 +01:00