Commit Graph

319 Commits

Author SHA1 Message Date
Paul Sokolovsky e7db8171d8 unix: Implement garbage collection support. 2014-02-11 16:20:02 +02:00
Paul Sokolovsky 287d9620fc Enable link map file generation. 2014-02-11 14:42:20 +02:00
Paul Sokolovsky a075741c90 Rename str_join -> strjoin to make it not clash with objstr's one. 2014-02-11 14:39:10 +02:00
Damien George d46ca25757 Fix some int casting that failed on 64 bit architecture. 2014-02-10 21:46:47 +00:00
Paul Sokolovsky 2e24ee8d80 socket: Tighten up int-to-str conversion. 2014-02-10 18:39:10 +02:00
Paul Sokolovsky 8c25201d9d socket: Make sure that symbol definitions are const. 2014-02-10 18:39:06 +02:00
Paul Sokolovsky f766264582 unix: Implement time.sleep(). 2014-02-09 12:52:04 +02:00
Paul Sokolovsky 557c9d5264 unix microsocket: Add dummy makefile() method.
Unlike CPython socket, microsocket object already implements stream protocol
(read/write methods), so makefile() just returns object itself. TODO: this
doesn't take care of arguments CPython's makefile() may accept.
2014-02-08 22:00:20 +02:00
Paul Sokolovsky 21c51f0bde ffi: Fix mp_obj_str_get_data() return type. 2014-02-08 22:00:15 +02:00
Paul Sokolovsky 1e19b24ea0 io.File, socket types: Add fileno() method.
Implementation is duplicated, but tolerate this for now, because there's
no clear idea how to de-dup it.
2014-02-08 21:20:32 +02:00
Paul Sokolovsky 9945f33886 Rename "rawsocket" module to "microsocket".
It's no longer intended to provide just "raw" socket interface, may include
some convenience methods for compatibility with CPython socket - but anyway
just minimal set required to deal with socket client and servers, not wider
network functionality.
2014-02-08 21:20:32 +02:00
Damien George 698ec21e46 Make mp_obj_str_get_data return char* instead of byte*.
Can't decide which is better for string type, char or byte pointer.
Changing to char removes a few casts.  Really need to do proper unicode.
2014-02-08 18:17:23 +00:00
Damien George 354d15a964 Implement fixed buffer vstrs; use them for import path. 2014-02-06 21:11:19 +00:00
Damien George e09ffa1400 Search paths properly on import and execute __init__.py if it exists. 2014-02-05 23:57:48 +00:00
Paul Sokolovsky 9110896063 Remove older import helpers, no longer used. 2014-02-05 02:03:23 +02:00
Paul Sokolovsky 630d85120f unix: Be sure to add current/base dir of a script to sys.path.
This mirrors CPython behavior and makes possible to run scripts which
import other modules not from script's directory.
2014-02-05 01:53:44 +02:00
Paul Sokolovsky 625d08a93e unix: Initialize sys.path from MICROPYPATH environment variable.
If it's not available, "~/.micropython/lib:/usr/lib/micropython" is used
as a fallback.
2014-02-05 01:40:41 +02:00
Paul Sokolovsky 0c59db1973 Use qstr id to create sys module. 2014-02-04 19:36:00 +02:00
Paul Sokolovsky 6964422cf4 unix time.clock(): Actually return float value. 2014-02-02 08:58:16 +02:00
Paul Sokolovsky a9459bc723 unix: Add basic time module (with time() and clock() functions).
Both return int so far (single-precision float doesn't have enough
bits to represent int32 precisely).
2014-02-02 01:34:11 +02:00
Damien George a908202d60 unix: libffi include path now found using pkg-config.
Hopefully this works for other people as well :)
2014-02-01 18:48:19 +00:00
Paul Sokolovsky ed1239fce6 Add mpconfigport.mk file to configure which modules to include into build.
Proof of concept, controls "ffi" module as one which requires external
dependencies.
2014-02-01 20:09:45 +02:00
Damien George 62ad189a65 py: Add compile option to enable/disable source line numbers. 2014-01-29 21:51:51 +00:00
Damien George 4d5b28cd08 Add qstr_info() function and bindings for unix port. 2014-01-29 18:56:46 +00:00
Damien George 8bf91f2a87 unix: Fix compile warnings for ffi module on 64-bit machine. 2014-01-28 23:08:11 +00:00
Paul Sokolovsky 60a9fac8d4 unix: Initial implementation of FFI module.
Foreign Function Interface module allows to load native dynamic libraries,
call functions and access variables in them. This makes possible to write
interface modules in pure Python.

This module provides thin wrapper around libffi. ctypes compatibility might
be possible to implement on top of this module (though ctypes allow to call
functions without prototypes, which is not supported by libffi (i.e.
implementation would be inefficient))).
2014-01-29 00:24:00 +02:00
Damien George 56bb636014 Change -Og to -O0 in unix-cpy/Makefile; cast to small int in socket.c. 2014-01-26 17:52:23 +00:00
Damien George 554a75b689 Merge pull request #226 from pfalcon/make-debug
unix Makefile: -Og doesn't work (at least) with gcc 4.6 below.
2014-01-26 09:53:31 -08:00
Paul Sokolovsky a88c30c64a unix socket: Add setsockopt() method. 2014-01-26 02:03:07 +02:00
Paul Sokolovsky 5d362d3209 unix socket: Add few more socket constants. 2014-01-26 02:03:07 +02:00
Paul Sokolovsky db0b282d45 unix socket: Store module constants in data structure.
-147 bytes on x86.
2014-01-26 02:03:07 +02:00
Paul Sokolovsky e2febe90e3 unix Makefile: -Og doesn't work (at least) with gcc 4.6 below.
Also, don't try to force debug info format, use native.
2014-01-25 19:49:38 +02:00
Damien George b829b5caec Implement mp_parse_node_free; print properly repr(string). 2014-01-25 13:51:19 +00:00
Paul Sokolovsky aee2ba70de Add parse_node_free_struct() and use it to free parse tree after compilation.
TODO: Check lexer/parse/compile error path for leaks too.
2014-01-25 02:11:59 +02:00
Dave Hylands c89c681a9f Rework makefiles. Add proper dependency checking. 2014-01-24 08:46:48 -08:00
Paul Sokolovsky 2b2cb7b7f4 unix main: Free input line.
Also, readline uses system malloc, so for symmetry, use the same for
non-readline case.
2014-01-24 16:29:49 +02:00
Damien George 5fa93b6755 Second stage of qstr revamp: uPy str object can be qstr or not. 2014-01-22 14:35:10 +00:00
Damien George 12eaccacda Merge branch 'master' of github.com:micropython/micropython
Conflicts:
	py/objstr.c
	py/py.mk
	py/stream.c
	unix/main.c
	unix/socket.c
2014-01-21 21:54:15 +00:00
Damien George 55baff4c9b Revamp qstrs: they now include length and hash.
Can now have null bytes in strings.  Can define ROM qstrs per port using
qstrdefsport.h
2014-01-21 21:40:13 +00:00
Paul Sokolovsky 51ee44a718 unix file: Refactor and add sys.stdout/stdin/stderr. 2014-01-20 23:50:55 +02:00
Paul Sokolovsky f0cfb8cb45 Don't preimport socket module. 2014-01-20 20:37:01 +02:00
Paul Sokolovsky fc35aa6828 unix socket: Add send() and recv() methods.
CPython _socket actually have only those and doesn't provide stream
interface (higher-level CPython "socket" what adds this).

+516 bytes x86.
2014-01-20 20:37:01 +02:00
Paul Sokolovsky decd597273 unix io.FileIO: Add iteration support.
A file cannot be iterated concurrently, so we make io.FileIO its own
iterator.
2014-01-20 18:42:08 +02:00
Damien George 7d08935458 Rename unix binary to 'micropython'. 2014-01-20 00:02:39 +00:00
Paul Sokolovsky fe2690da0a unix: Implement sys.argv. 2014-01-20 01:00:28 +02:00
Damien George a11ceca807 Change int to uint for n_args in function with variable arguments. 2014-01-19 16:02:09 +00:00
Damien George 136b149e41 py: Add full traceback to exception printing. 2014-01-19 12:38:49 +00:00
Damien George 49f6a99c65 Merge branch 'master' of github.com:micropython/micropython 2014-01-19 11:50:14 +00:00
Damien George cbd2f7482c py: Add module/function/class name to exceptions.
Exceptions know source file, line and block name.

Also tidy up some debug printing functions and provide a global
flag to enable/disable them.
2014-01-19 11:48:48 +00:00
Paul Sokolovsky 50a2d6ff59 Fix incorrect prototype of mp_builtin_open() after args refactor. 2014-01-19 07:50:45 +02:00
Damien George a8a6db2a1d Fix warnings about int/pointer casting. 2014-01-18 23:50:12 +00:00
Damien George 8fce5b42a2 Merge pull request #194 from pfalcon/socket
Add lean ("raw") socket module.
2014-01-18 15:34:30 -08:00
Damien George 08335004cf Add source file name and line number to error messages.
Byte code has a map from byte-code offset to source-code line number,
used to give better error messages.
2014-01-18 23:24:36 +00:00
Paul Sokolovsky fc92608237 Add lean ("raw") socket module. 2014-01-19 00:16:39 +02:00
Damien George 20006dbba9 Make VM stack grow upwards, and so no reversed args arrays.
Change state layout in VM so the stack starts at state[0] and grows
upwards.  Locals are at the top end of the state and number downwards.
This cleans up a lot of the interface connecting the VM to C: now all
functions that take an array of Micro Python objects are in order (ie no
longer in reverse).

Also clean up C API with keyword arguments (call_n and call_n_kw
replaced with single call method that takes keyword arguments).  And now
make_new takes keyword arguments.

emitnative.c has not yet been changed to comply with the new order of
stack layout.
2014-01-18 14:10:48 +00:00
Paul Sokolovsky 966879cf59 Add long int implementation using C long long type, enable for unix port. 2014-01-17 20:05:02 +02:00
Damien George 5573f9f150 Merge branch 'str2int' of github.com:xyb/micropython into xyb-str2int
Conflicts:
	py/objint.c
	unix-cpy/Makefile
	unix/Makefile
2014-01-15 22:58:39 +00:00
Damien George 4899ff9470 Merge branch 'str-repr' of github.com:pfalcon/micropython into pfalcon-str-repr
Conflicts:
	tests/basics/tests/exception1.py
2014-01-15 22:39:03 +00:00
Damien George 11507f4074 Merge branch 'master' of github.com:dpgeorge/micropython 2014-01-15 22:14:18 +00:00
Paul Sokolovsky 9953ca432b Add unbuffered readline() implementation for Raw I/O files. 2014-01-15 23:43:25 +02:00
Damien George 9528cd66d7 Convert parse errors to exceptions.
Parser no longer prints an error, but instead returns an exception ID
and message.
2014-01-15 21:23:31 +00:00
Paul Sokolovsky 76d982ef34 type->print(): Distinguish str() and repr() variety by passing extra param. 2014-01-15 02:15:38 +02:00
Damien George c6920d31e2 Merge pull request #170 from chipaca/master
made DEBUG control CFLAGS in Makefiles other than stm as well.
2014-01-14 15:54:31 -08:00
xyb c178ea471e Implemented int(str) in UNIX 2014-01-14 21:39:05 +08:00
Paul Sokolovsky 5225450b9f Add generic impl of stream .readall() method. Use one for unix io.FileIO. 2014-01-13 23:31:06 +02:00
John R. Lenton 9549919349 made DEBUG control CFLAGS in Makefiles oter than stm as well. 2014-01-13 13:25:10 +00:00
Damien George 004cdcebfe py: Implement base class lookup, issubclass, isinstance. 2014-01-09 21:43:51 +00:00
Damien George 062478e66d Improved type/class/instance code; mp_obj_type_t now has load_attr, store_attr.
Creating of classes (types) and instances is much more like CPython now.
You can use "type('name', (), {...})" to create classes.
2014-01-09 20:57:50 +00:00
Dave Hylands 4646801181 Make build output quieter.
Use make V=1e make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.

This should fix issue #117
2014-01-08 10:30:06 -08:00
Damien George 6c73ca1e75 py: add variable argument exception constructor function.
Addresses issue #104.
2014-01-08 18:11:23 +00:00
Paul Sokolovsky e0e79ae6d6 unix: Add basic implementation of io.FileIO object.
Note: only read/write/close methods are defined so far, and class
is not exposed (use open() factory function, as usual).
2014-01-08 17:39:06 +02:00
Damien George 97209d38e1 Merge branch 'cplusplus' of https://github.com/ian-v/micropython into ian-v-cplusplus
Conflicts:
	py/objcomplex.c
2014-01-07 15:58:30 +00:00
Damien George d3ebe4829d Factor and simplify Makefile's and mpconfig, part 2. 2014-01-07 15:20:33 +00:00
Damien George 136f67523b Factor and simplify Makefile's and mpconfig. 2014-01-07 14:54:15 +00:00
ian-v 5fd8fd2c16 Revert MP_BOOL, etc. and use <stdbool.h> instead 2014-01-06 13:51:53 -08:00
ian-v 7a16fadbf8 Co-exist with C++ (issue #85) 2014-01-06 09:52:29 -08:00
Paul Sokolovsky 860ffb0a43 Convert many object types structs to use C99 tagged initializer syntax. 2014-01-05 22:34:09 +02:00
Damien George 71c5181a8d Convert Python types to proper Python type hierarchy.
Now much more inline with how CPython does types.
2014-01-04 20:21:15 +00:00
Paul Sokolovsky d674bd5989 Convert USE_READLINE config option to be consistent with others. 2014-01-04 19:38:19 +02:00
Damien George eb7bfcb286 Split qstr into pools, and put initial pool in ROM.
Qstr's are now split into a linked-list of qstr pools.  This has 2
benefits: the first pool can be in ROM (huge benefit, since we no longer
use RAM for the core qstrs), and subsequent pools use m_new for the next
pool instead of m_renew (thus avoiding a huge single table for all the
qstrs).

Still would be better to use a hash table, but this scheme takes us part
of the way (eventually convert the pools to hash tables).

Also fixed bug with import.

Also improved the way the module code is referenced (not magic number 1
anymore).
2014-01-04 15:57:35 +00:00
Damien George e67ed5d285 Improve configurability for native x64/thumb emitter.
With MICROPY_EMIT_X64 and MICROPY_EMIT_THUMB disabled, the respective
emitters and assemblers will not be included in the code.  This can
significantly reduce binary size for unix version.
2014-01-04 13:55:24 +00:00
Paul Sokolovsky 1c6de11f77 Add basic implementation of slice object.
So far, only start and stop integer indexes are supported. Step is
not supported, as well as objects of arbitrary types.
2014-01-04 02:35:48 +02:00
Paul Sokolovsky c90c0f68a2 Move INT_FMT, etc. declaration into global mpconfig.h .
This in particular makes it available for stm port.
2014-01-04 01:57:00 +02:00
Paul Sokolovsky b372bfca21 Rename default config file to mpconfig.h, and port's to mpconfigport.h.
mpconfig.h will automatically pull mpconfigport.h.
2014-01-03 19:03:11 +02:00
Damien George 1fb031744f Change mp_compile so that it returns a function object for the module. 2014-01-03 14:22:03 +00:00
Damien George 66028ab6dc Basic implementation of import.
import works for simple cases.  Still work to do on finding the right
script, and setting globals/locals correctly when running an imported
function.
2014-01-03 14:03:48 +00:00
Damien George 2870862601 Add module object, to be used eventually for import. 2014-01-02 21:30:26 +00:00
Damien George 210a02e105 unix: revert Makefile to not use -ltermcap.
termcap is not needed on Linux.  Need to work out how to automatically
configure the Makefile...
2014-01-02 15:50:33 +00:00
Edd Barrett 0d02eb178a Fix undefined termcap symbols on OpenBSD.
E.g.:
/usr/lib/libreadline.so.4.0: undefined reference to `tgetnum'
/usr/lib/libreadline.so.4.0: undefined reference to `tgoto'
/usr/lib/libreadline.so.4.0: undefined reference to `tgetflag'
/usr/lib/libreadline.so.4.0: undefined reference to `tputs'
/usr/lib/libreadline.so.4.0: undefined reference to `tgetent'
/usr/lib/libreadline.so.4.0: undefined reference to `tgetstr'

Tested on linux too, works.
2014-01-01 23:26:36 +00:00
Edd Barrett 8146aea8ef malloc.h is obsolete. 2014-01-01 23:14:36 +00:00
Paul Sokolovsky fa027672da Make GNU Readline usage optional (USE_READLINE define). Still enabled.
Readline is GPL, so linking with it casts the binary GPL.
2014-01-01 18:28:01 +02:00
Paul Sokolovsky 903b24f041 Add readline history support. 2014-01-01 14:54:39 +02:00
Paul Sokolovsky e1151e463d Use rm -rf to remove build dir, so it doesn't error out if dir doesn't exist. 2013-12-30 21:02:10 +02:00
Damien George 8cc96a35e5 Put unicode functions in unicode.c, and tidy their names. 2013-12-30 18:23:50 +00:00
Damien George 212c296c0b Make unix-cpy cross platform; remove dependency of asmx64 on mpconfig. 2013-12-30 12:52:32 +00:00
Paul Sokolovsky e85c38992d Make "unix" target be crossplatform and support x86, x64, ARM hosts. 2013-12-30 03:38:32 +02:00
Damien 732407f1bf Change memory allocation API to require size for free and realloc. 2013-12-29 19:33:23 +00:00
Paul Sokolovsky 729fd12fbf Don't error out if build/ directory already exists. 2013-12-29 20:12:33 +02:00
Damien de690d128b Add unix-cpy, used to test Micro Python byte code against CPython. 2013-12-29 18:01:01 +00:00
Damien b86e3f9293 py: implement some basic exception matching. 2013-12-29 17:17:43 +00:00
Damien d99b05282d Change object representation from 1 big union to individual structs.
A big change.  Micro Python objects are allocated as individual structs
with the first element being a pointer to the type information (which
is itself an object).  This scheme follows CPython.  Much more flexible,
not necessarily slower, uses same heap memory, and can allocate objects
statically.

Also change name prefix, from py_ to mp_ (mp for Micro Python).
2013-12-21 18:17:45 +00:00
Damien e2880aa2fd Fix a few compiler warnings. 2013-12-20 14:22:59 +00:00
Damien 0f08267fa4 unix: include obj.h, and build additional py files. 2013-12-17 18:33:53 +00:00
Damien 1895cf91af Link showbc.o in unix version. 2013-11-17 13:20:13 +00:00
Damien 087d218d95 Unix: add machine-specific sqrt support. 2013-11-09 20:14:30 +00:00
Damien 014e19fc4d Fix compiler warnings in unix/main.c. 2013-11-03 14:26:21 +00:00
Damien a53f694dc3 Test code for user objects. 2013-11-02 23:58:38 +00:00
Damien 7410e440ab Add basic complex number support. 2013-11-02 19:47:57 +00:00
Damien 8b3a7c2237 Fix func decls with no arguments: () -> (void). 2013-10-23 20:20:17 +01:00
Damien 92c06561a3 Improve REPL compount statement detection. 2013-10-22 22:32:27 +01:00
Damien d276f6357e Get unix version compling. 2013-10-22 16:05:47 +01:00
Damien fa2162bc77 Integrate new lexer stream with stm framework. 2013-10-20 17:42:00 +01:00
Damien a5185f4bc8 Abstract out back-end stream functionality from lexer. 2013-10-20 14:41:27 +01:00
Damien 5ac1b2efbd Implement REPL. 2013-10-18 19:58:12 +01:00
Damien d2755ec538 Add iterators and comprehension to emitnative. 2013-10-16 23:58:48 +01:00
Damien c9f91976e1 Crude try-except working. 2013-10-15 23:46:01 +01:00
Damien ce89a21ea4 Implement basic exception framework, and simple for loop. 2013-10-15 22:25:17 +01:00
Damien 3ef4abb446 Change ifdef/if defined to simple if's. 2013-10-12 16:53:13 +01:00
Damien c025ebb2dc Separate out mpy core and unix version. 2013-10-12 14:30:21 +01:00