Commit Graph

2062 Commits

Author SHA1 Message Date
Paul Sokolovsky
640e0b221e py: Implement very simple frozen modules support.
Only modules (not packages) supported now. Source modules can be converted
to frozen module structures using tools/make-frozen.py script.
2015-01-20 11:52:12 +02: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
0abb5609b0 py: Remove unnecessary id_flags argument from emitter's load_fast.
Saves 24 bytes in bare-arm.
2015-01-16 12:24:49 +00:00
Paul Sokolovsky
87bc8e2b3d pyexec: Add event-driven variant pyexec_friendly_repl().
pyexec_friendly_repl_process_char() and friends, useful for ports which
integrate into existing cooperative multitasking system.

Unlike readline() refactor before, this was implemented in less formal,
trial&error process, minor functionality regressions are still known
(like soft&hard reset support). So, original loop-based pyexec_friendly_repl()
is left intact, specific implementation selectable by config setting.
2015-01-16 01:30:42 +02:00
Damien George
d2d64f00fb py: Add "default" to switches to allow better code flow analysis.
This helps compiler produce smaller code.  Saves 124 bytes on stmhal and
bare-arm.
2015-01-14 21:32:42 +00:00
Damien George
65ef6b768c py: Only allocate strings/bytes once for load_const_obj. 2015-01-14 21:17:27 +00:00
Damien George
d9dc6fff21 py: Allocate memory for assembled code at start of PASS_EMIT.
Previously was allocating at end of PASS_COMPUTE, and this pass was
being run twice, so memory was being allocated twice.
2015-01-14 00:38:33 +00:00
Damien George
1e1779eacf py: Reluctantly add an extra pass to bytecode compiler.
Bytecode also needs a pass to compute the stack size.  This is because
the state size of the bytecode function is encoded as a variable uint,
so we must know the value of this uint before we encode it (otherwise
the size of the generated code changes from one pass to the next).

Having an entire pass for this seems wasteful (in time).  Alternative is
to allocate fixed space for the state size (would need 3-4 bytes to be
general, when 1 byte is usually sufficient) which uses a bit of extra
RAM per bytecode function, and makes the code less elegant in places
where this uint is encoded/decoded.

So, for now, opt for an extra pass.
2015-01-14 00:20:28 +00:00
Damien George
2127e9a844 py, unix: Trace root pointers with native emitter under unix port.
Native code has GC-heap pointers in it so it must be scanned.  But on
unix port memory for native functions is mmap'd, and so it must have
explicit code to scan it for root pointers.
2015-01-14 00:11:09 +00:00
Damien George
c935d69f74 py: Make compiler not crash when default except is not last. 2015-01-13 23:33:16 +00:00
Damien George
d6ed6702f7 py/showbc.c: Handle new LOAD_CONST_OBJ opcode, and opcodes with cache. 2015-01-13 23:08:47 +00:00
Damien George
4c81ba8015 py: Never intern data of large string/bytes object; add relevant tests.
Previously to this patch all constant string/bytes objects were
interned by the compiler, and this lead to crashes when the qstr was too
long (noticeable now that qstr length storage defaults to 1 byte).

With this patch, long string/bytes objects are never interned, and are
referenced directly as constant objects within generated code using
load_const_obj.
2015-01-13 16:21:23 +00:00
Damien George
dab1385177 py: Add load_const_obj to emitter, add LOAD_CONST_OBJ to bytecode.
This allows to directly load a Python object to the Python stack.  See
issue #722 for background.
2015-01-13 15:55:54 +00:00
Damien George
bbf5cd01e3 py: Allow to compile with -Wstrict-prototypes. 2015-01-12 22:45:35 +00:00
Damien George
30d8a82220 py: Allow to compile with -Wredundant-decls. 2015-01-12 22:41:55 +00:00
Damien George
abc1959e2c py, unix, lib: Allow to compile with -Wold-style-definition. 2015-01-12 22:34:38 +00:00
Damien George
cd34207409 py: Can compile with -Wmissing-declarations and -Wmissing-prototypes. 2015-01-12 22:30:49 +00:00
Damien George
3dd1c0a88a py: Make a function static and comment out those not used. 2015-01-12 22:22:46 +00:00
Damien George
0178aa9a11 py, unix: Allow to compile with -Wdouble-promotion.
Ref issue #699.
2015-01-12 21:56:35 +00:00
Damien George
99ab64ffd4 py/makeqstrdata.py: Make it work again with both Python2 and Python3. 2015-01-11 22:40:38 +00:00
Damien George
95836f8439 py: Add MICROPY_QSTR_BYTES_IN_LEN config option, defaulting to 1.
This new config option sets how many fixed-number-of-bytes to use to
store the length of each qstr.  Previously this was hard coded to 2,
but, as per issue #1056, this is considered overkill since no-one
needs identifiers longer than 255 bytes.

With this patch the number of bytes for the length is configurable, and
defaults to 1 byte.  The configuration option filters through to the
makeqstrdata.py script.

Code size savings going from 2 to 1 byte:
- unix x64 down by 592 bytes
- stmhal down by 1148 bytes
- bare-arm down by 284 bytes

Also has RAM savings, and will be slightly more efficient in execution.
2015-01-11 22:27:30 +00:00
Damien George
6942f80a8f py: Add qstr cfg capability; generate QSTR_NULL and QSTR_ from script. 2015-01-11 22:06:53 +00:00
Damien George
e233a55a29 py: Remove unnecessary BINARY_OP_EQUAL code that just checks pointers.
Previous patch c38dc3ccc7 allowed any
object to be compared with any other, using pointer comparison for a
fallback.  As such, existing code which checked for this case is no
longer needed.
2015-01-11 21:07:15 +00:00
Damien George
c38dc3ccc7 py: Implement fallback for equality check for all types.
Return "not equal" for objects that don't implement equality check.
This is as per Python specs.
2015-01-11 15:13:18 +00:00
Damien George
ec21405821 py: Add (commented out) code to gc_dump_alloc_table for qstr info. 2015-01-11 14:37:06 +00:00
Damien George
56e1f99ca1 py/makeqstrdata.py: Add more allowed qstr characters; escape quot. 2015-01-11 14:16:24 +00:00
Damien George
01418e9690 py: Fix hard-coded hash for empty qstr (was 0x0000 now 0x1505). 2015-01-11 14:15:45 +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
58056b0f43 py: Fix handling of "0" mpz in some functions. 2015-01-09 20:58:58 +00:00
Damien George
5d48f234d2 py: Make mem_info print correct remaining stack bytes. 2015-01-09 20:37:49 +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
c33ecb83ba tests: Add test for when instance member overrides class member. 2015-01-08 17:48:44 +00:00
Damien George
5b7aa294e0 py: Fix nlr mp_state_ctx symbol error for Mac. 2015-01-08 16:24:44 +00:00
stijn
afd6c8e1d2 Remove obsolete bss-related code/build features
GC for unix/windows builds doesn't make use of the bss section anymore,
so we do not need the (sometimes complicated) build features and code related to it
2015-01-08 15:29:44 +01: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
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
ad2307c92c py: Temporary fix for conversion of float to int when fits in small int.
Addresses issue #1044 (see also #1040).  Could do with a better fix.
2015-01-07 12:10:47 +00:00
Paul Sokolovsky
d8bfd77ad5 showbc: Show conditional jump destination as unsigned value.
This is consistent with how BC_JUMP was handled before. We never show jumps
destinations relative to jump instrucion itself, only relative to beginning
of function. Another useful way to show them as absolute (real memory
address), and this change makes result expected and consistent with how
BC_JUMP is shown.
2015-01-07 00:29:15 +02:00
Paul Sokolovsky
343ca1e63a objarray: Make sure that longint works as bytearray size. 2015-01-04 17:19:16 +02:00
Paul Sokolovsky
ed3b20aae8 modbuiltins.c: Fix NULL vs MP_OBJ_NULL usage. 2015-01-04 13:26:43 +02:00
Paul Sokolovsky
ff8e35b42e objstr: Common subexpression elimination for vstr_str(field_name). 2015-01-04 13:23:44 +02:00
Paul Sokolovsky
c114496641 objstr: Implement kwargs support for str.format(). 2015-01-04 00:26:31 +02:00
Damien George
6fd4b36bc5 py: Raise exception if trying to convert inf/nan to int. 2015-01-02 23:04:09 +00:00
David Steinberg
6e0b6d02db py: Fix float to int conversion for large exponents. 2015-01-02 22:31:41 +00:00
stijn
fbfd3554fa msvc: Fix unresolved mp_arg_error_terse_mismatch since 7f23384
The compiler treats `if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE)` as
a normal statement and generates assembly for it in degug mode as if MICROPY_ERROR_REPORTING
is an actual symbol instead of a preprocessor definition.
As such linking fails because mp_arg_error_terse_mismatch is not defined when
MICROPY_ERROR_REPORTING_TERSE is detailed or normal.
2015-01-02 16:53:54 +01:00
Damien George
fd40a9c38e py: Make GC's STACK_SIZE definition a proper MICROPY_ config variable. 2015-01-01 22:04:46 +00:00
Damien George
872a82970d py: Fix windows external name error for nlr_top. 2015-01-01 22:03:44 +00:00
Damien George
8a2347723e py: Move global variable nlr_top to one place, in a .c file.
This reduces dependency on assembler, and allows to consolidate global
variables in the future.
2015-01-01 21:47:58 +00:00
Damien George
51dfcb4bb7 py: Move to guarded includes, everywhere in py/ core.
Addresses issue #1022.
2015-01-01 20:32:09 +00:00
Paul Sokolovsky
db1ac360c3 emitnative: Disable warning in delete_fast for now (breaks test). 2015-01-01 22:09:18 +02:00
Paul Sokolovsky
8a8c1fc82f py: Add basic framework for issuing compile/runtime warnings. 2015-01-01 22:09:18 +02:00
Damien George
ebde3c694f py: Add guarded includes for asm-based headers. 2015-01-01 18:07:43 +00:00
Damien George
84e0cf0d21 py: Change namedtuple error messages to reduce code size.
We are not word-for-word compatible with CPython exceptions, so we are
free to make them short but informative in order to reduce code size.
Also, try to make messages the same as existing ones where possible.
2015-01-01 15:43:25 +00:00
Damien George
7f23384d49 py: Make terse_arg_mismatch a global function and use it elsewhere.
Reduces code size when MICROPY_ERROR_REPORTING_TERSE is selected.
2015-01-01 15:33:50 +00:00
Paul Sokolovsky
276159e5dd objnamedtuple: Make sure to initialize type structure completely. 2015-01-01 15:31:51 +02:00
stijn
021dc44009 py: Allow keyword arguments for namedtuple 2015-01-01 14:53:23 +02:00
stijn
12340147b0 py: Use sequence of strings for named tuple initialization
- remove single string initialization style
- take list of strings instead
- store list in the type for fast lookup
2015-01-01 14:53:23 +02:00
Damien George
e0ac194f4f py: Fix rshift and not of zero/one edge cases in mpz.
Addresses issue #1027.
2014-12-31 19:35:01 +00:00
Paul Sokolovsky
2c75665445 objstr: Fix %d-formatting of floats. 2014-12-31 02:21:19 +02:00
Paul Sokolovsky
5f68094e10 py: mp_obj_new_int_from_float() supported only for MICROPY_PY_BUILTINS_FLOAT. 2014-12-30 00:34:54 +02:00
Paul Sokolovsky
f79cd6a233 py: Implement mp_obj_new_int_from_float() for MICROPY_LONGINT_IMPL_NONE. 2014-12-30 00:33:32 +02:00
Paul Sokolovsky
12033df511 py: Partially fix float to int conversion.
This fixes conversion when float type has more mantissa bits than small int,
and float value has small exponent. This is for example the case of 32-bit
platform using doubles, and converting value of time.time(). Conversion of
floats with larg exponnet is still not handled correctly.
2014-12-30 00:22:50 +02:00
Damien George
9ddbe291c4 py: Add include guards to mpconfig,misc,qstr,obj,runtime,parsehelper. 2014-12-29 01:02:19 +00:00
Damien George
f89d659e3b py: In VM, for selective ip saving, store 1 byte past last opcode.
This is for efficiency, so we don't need to subtract 1 from the ip
before storing it to code_state->ip.  It saves a lot of ROM bytes on
unix and stmhal.
2014-12-29 00:29:59 +00:00
Paul Sokolovsky
23f1b5ff66 py: Add note about -fno-crossjumping when compiling vm.c. 2014-12-29 00:07:47 +00:00
Paul Sokolovsky
361909e3ca py: Add MP_LIKELY(), MP_UNLIKELY() macros to help branch prediction. 2014-12-29 00:51:24 +02:00
Paul Sokolovsky
1ee1785bed showbc: Print operation mnemonic in BINARY_OP. 2014-12-28 21:43:44 +02:00
Paul Sokolovsky
df103462dc showbc: Make code object start pointer semi-public.
This allows to pring either absolute addresses or relative offsets in jumps
and code references.
2014-12-28 21:37:17 +02:00
Paul Sokolovsky
749575097f vm: Record exception ip only for instructions where exceptions may happen.
Mirroring ip to a volatile memory variable for each opcode is an expensive
operation. For quite a lot of often executed opcodes like stack manipulation
or jumps, exceptions cannot actually happen. So, record ip only for opcode
where that's possible.
2014-12-28 07:37:04 +02:00
Damien George
83204f3406 py: Allow to properly disable builtin slice operation.
This patch makes the MICROPY_PY_BUILTINS_SLICE compile-time option
fully disable the builtin slice operation (when set to 0).  This
includes removing the slice sytanx from the grammar.  Now, enabling
slice costs 4228 bytes on unix x64, and 1816 bytes on stmhal.
2014-12-27 17:33:30 +00:00
Damien George
e37dcaafb4 py: Allow to properly disable builtin "set" object.
This patch makes MICROPY_PY_BUILTINS_SET compile-time option fully
disable the builtin set object (when set to 0).  This includes removing
set constructor/comprehension from the grammar, the compiler and the
emitters.  Now, enabling set costs 8168 bytes on unix x64, and 3576
bytes on stmhal.
2014-12-27 17:33:30 +00:00
Paul Sokolovsky
8ab6f90674 py: Move to guarded includes for compile.h and related headers. 2014-12-27 16:12:17 +02:00
Paul Sokolovsky
343266ea51 showbc: Refactor to allow inline instruction printing. 2014-12-27 05:01:21 +02:00
Damien George
c55a4d82cf py: Make bytes objs work with more str methods; add tests. 2014-12-24 20:28:30 +00:00
Damien George
74eb44c392 py: Reduce size of VM exception stack element by 1 machine word.
This optimisation reduces the VM exception stack element (mp_exc_stack_t)
by 1 word, by using bit 1 of a pointer to store whether the opcode was a
FINALLY or WITH opcode.  This optimisation was pending, waiting for
maturity of the exception handling code, which has now proven itself.

Saves 1 machine word RAM for each exception (4->3 words per exception).
Increases stmhal code by 4 bytes, and decreases unix x64 code by 32
bytes.
2014-12-22 12:49:57 +00:00
Damien George
81836c28b3 py: Use str_to_int function in more places to reduce code size. 2014-12-21 21:07:03 +00:00
Damien George
01039b5bd8 py: Remove last uses of printf from compile; use proper SyntaxError. 2014-12-21 17:44:27 +00:00
Damien George
584ba6762f py: Move global/nonlocal decl code to compiler for proper SyntaxError.
This patch gives proper SyntaxError exceptions for bad global/nonlocal
declarations.  It also reduces code size: 304 bytes on unix x64, 132
bytes on stmhal.
2014-12-21 17:26:45 +00:00
Damien George
b063b9b36d py: Fix iteration over map in 2 places. 2014-12-21 16:24:09 +00:00
Damien George
6efa66f125 py: Remove unnecessary RULE_none and PN_none from parser. 2014-12-20 18:41:59 +00:00
Damien George
b47ea4eadd py: Add blank and ident flags to grammar rules to simplify parser.
This saves around 100 bytes code space on stmhal, more on unix.
2014-12-20 18:37:50 +00:00
Damien George
2870d85a11 py: Save a few code bytes in parser; make vars local where possible. 2014-12-20 18:06:08 +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
Paul Sokolovsky
c0bc3bd736 asmarm: Fix bug with encoding small negative ints using MVN instruction. 2014-12-14 03:24:17 +02:00
Damien George
e181c0dc07 py: Fix optimised for-loop compiler so it follows proper semantics.
You can now assign to the range end variable and the for-loop still
works correctly.  This fully addresses issue #565.

Also fixed a bug with the stack not being fully popped when breaking out
of an optimised for-loop (and it's actually impossible to write a test
for this case!).
2014-12-12 17:19:56 +00:00
Damien George
7764f163fa py: Fix label printing in showbc; print sp in vm trace. 2014-12-12 17:18:56 +00:00
Damien George
c33ce606cf py: Fix a semantic issue with range optimisation.
Now you can assign to the range variable within the for loop and it will
still work.

Partially addresses issue #565.
2014-12-11 17:35:23 +00:00
Damien George
5318cc028a py: Tidy up a few function declarations. 2014-12-10 22:37:07 +00:00
Damien George
7eb2317fa2 py: Remove static from definition of pfenv_printf.
It's used by stmhal, but not unix.
2014-12-10 22:11:01 +00:00
Damien George
969a6b37bf py: Make functions static where appropriate. 2014-12-10 22:08:14 +00:00
Damien George
b4fe6e28eb py: Fix function type: () -> (void). 2014-12-10 18:05:42 +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
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
be6d8be91e py: Rename mp_obj_int_get to mp_obj_int_get_truncated; fix struct.pack.
mp_obj_int_get_truncated is used as a "fast path" int accessor that
doesn't check for overflow and returns the int truncated to the machine
word size, ie mp_int_t.

Use mp_obj_int_get_truncated to fix struct.pack when packing maximum word
sized values.

Addresses issues #779 and #998.
2014-12-05 23:13:52 +00:00
Damien George
451a087075 py: Fix printing of size_t entity; fix qemu-arm for changes to lexer. 2014-12-05 22:50:16 +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
Damien George
32ef3a3517 py: Allow bytes/bytearray/array to be init'd by buffer protocol objects.
Behaviour of array initialisation is subtly different for bytes,
bytearray and array.array when argument has buffer protocol.  This patch
gets us CPython conformant (except we allow initialisation of
array.array by buffer with length not a multiple of typecode).
2014-12-04 15:46:14 +00:00
Damien George
cd97a43f8d py, vm: Make unum a local variable for each opcode that uses it.
This makes no change to the generated code, but it's now easier to
understand since unum is not a "global" variable anymore.
2014-12-02 19:25:10 +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
Damien George
c7ca01ad96 py: Generalise and reduce code size of array +, += and .extend().
By using the buffer protocol for these array operations, we now allow
addition of memoryview objects, and objects with "incompatible"
typecodes (in this case it just adds bytes naively).  This is an
extension to CPython which seems sensible.  It also reduces the code
size.
2014-11-30 14:01:33 +00:00
Damien George
b2e731177e py: Implement +, += and .extend for bytearray and array objs.
Addresses issue #994.
2014-11-30 00:00:55 +00:00
Damien George
3b603f29ec Use MP_DEFINE_CONST_DICT macro to define module dicts.
This is just a clean-up of the code.  Generated code is exactly the
same.
2014-11-29 14:39:27 +00:00
Paul Sokolovsky
bfdc205934 modubinascii: Add, with hexlify() implementation. 2014-11-29 13:52:47 +00:00
Damien George
2399aa03b8 py: Add NLR support for xtensa CPU. 2014-11-27 20:29:33 +00:00
Paul Sokolovsky
df732bb01b pfenv_printf: Properly implement %p format specifier.
Previously, it truncated pointer value to 32 bits on 64-bit systems.
2014-11-27 17:38:03 +00:00
Paul Sokolovsky
1eca32836d builtin: Reimplement __repl_print__() in terms of print().
Before, __repl_print__() used libc printf(), while print() used uPy streams
and own printf() implementation. This led to subtle, but confusing
differences in output when just doing "foo" vs "print(foo)" on interactive
prompt.
2014-11-27 17:38:03 +00:00
Paul Sokolovsky
e5dbe1e283 map: Add empty fixed map.
Useful when need to call kw-receiving functions  without any keywords
from C, etc.
2014-11-27 17:37:07 +00:00
Damien George
6f5eb84c19 py: #if guard str_make_new when not needed. 2014-11-27 16:55:47 +00:00
Paul Sokolovsky
f4b19c873f moduhashlib: Initial module skeleton. 2014-11-22 14:47:46 +02:00
Damien George
c9f8f653ad py: Add support for float/double arrays in array module.
Addresses issue #981.
2014-11-21 18:16:25 +00:00
Damien George
5694cc5490 py: Make stream seek correctly check for ioctl fn; add seek for textio. 2014-11-16 23:56:37 +00:00
Paul Sokolovsky
838eb1fa2d stream: Implement seek operation support via ioctl, wrapped in generic method.
Also, implement for unix port.
2014-11-17 00:16:14 +02:00
Paul Sokolovsky
f4a6a577ab stream: Convert .ioctl() to take fixed number of args.
This is more efficient, as allows to use register calling convention.
If needed, a structure pointer can be passed as argument to pass more
data.
2014-11-17 00:16:14 +02:00
stijn
e00eeaf4cd py: Use __hash__ method if a type defines it 2014-11-15 18:24:22 +00:00
Sven Wegener
b98c162c52 py: Fix order-only dependencies in mkrules.mk and py.mk.
Currently compilation sporadically fails, because the automatic
dependency gets created *during* the compilation of objects.

OBJ is a auperset of PY_O and the dependencies apply to all objects.

Signed-off-by: Sven Wegener <sven.wegener@stealer.net>
2014-11-06 18:48:38 +00:00
Damien George
1e9a92f84f py: Use shorter, static error msgs when ERROR_REPORTING_TERSE enabled.
Going from MICROPY_ERROR_REPORTING_NORMAL to
MICROPY_ERROR_REPORTING_TERSE now saves 2020 bytes ROM for ARM Thumb2,
and 2200 bytes ROM for 32-bit x86.

This is about a 2.5% code size reduction for bare-arm.
2014-11-06 17:36:16 +00:00
Damien George
b6b34cd3f6 py: Remove obsolute function declaration. 2014-11-06 17:31:18 +00:00
Sven Wegener
bfb18a714b py: Add order-only dependency for py-version.h
Else the directory might not exist.

Signed-off-by: Sven Wegener <sven.wegener@stealer.net>
2014-11-05 22:52:51 +00:00
Sven Wegener
238ab5013b py: Deactivate more code without MICROPY_PY_SYS
When compiler optimization has been turned on, gcc knows that this code
block is not going to be executed. But with -O0 it complains about
path_items being used uninitialized.

Signed-off-by: Sven Wegener <sven.wegener@stealer.net>
2014-11-05 22:52:51 +00:00
Damien George
7860c2a68a py: Fix some macros defines; cleanup some includes. 2014-11-05 21:16:41 +00:00
Damien George
be8e99c7d4 py: Allow bytes object as argument to some str methods.
This turns failing assertions to type exceptions for things like
b"123".find(...).  We still don't support operations like this on bytes
objects (unlike CPython), but at least it no longer crashes.
2014-11-05 16:45:54 +00:00
Damien George
a65c03c6c0 py: Allow +, in, and compare ops between bytes and bytearray/array.
Eg b"123" + bytearray(2) now works.  This patch actually decreases code
size while adding functionality: 32-bit unix down by 128 bytes, stmhal
down by 84 bytes.
2014-11-05 16:30:34 +00:00
Paul Sokolovsky
346aacf27f unix: fast: Set initial module dict size big to have high pystone score.
For this, introduce MICROPY_MODULE_DICT_SIZE config setting.
2014-11-05 00:30:21 +02:00
Damien George
ff319dffad py: Explicitly set uninitialised struct member to false.
Uninitialised struct members get a default value of 0/false, so this is
not strictly needed.  But it actually decreases code size because when
all members are initialised the compiler doesn't need to insert a call
to memset to clear everything.  In other words, setting 1 extra member
to 0 uses less code than calling memset.

ROM savings in bytes: 32-bit unix: 100; bare-arm: 44; stmhal: 52.
2014-11-03 16:18:51 +00:00
Damien George
0344fa1ddf py: Fix builtin callable so it checks user-defined instances correctly.
Addresses issue #953.
2014-11-03 16:09:39 +00:00
Paul Sokolovsky
039887a0ac py: Fix bug with right-shifting small ints by large amounts.
Undefined behavior in C, needs explicit check.
2014-11-02 02:41:30 +02:00
Damien George
109c1de015 py: Make gc.enable/disable just control auto-GC; alloc is still allowed.
gc.enable/disable are now the same as CPython: they just control whether
automatic garbage collection is enabled or not.  If disabled, you can
still allocate heap memory, and initiate a manual collection.
2014-10-31 21:30:46 +00:00
Damien George
1559a97810 py: Add builtin round function.
Addresses issue #934.
2014-10-31 11:28:50 +00:00
stijn
0e557facb9 mpz: Fix 64bit msvc build
msvc does not treat 1L a 64bit integer hence all occurences of shifting it left or right
result in undefined behaviour since the maximum allowed shift count for 32bit ints is 31.
Forcing the correct type explicitely, stored in MPZ_LONG_1, solves this.
2014-10-30 23:00:24 +00:00
Paul Sokolovsky
e62a0fe367 objstr: Allow to convert any buffer proto object to str.
Original motivation is to support converting bytearrays, but easier to just
support buffer protocol at all.
2014-10-31 00:03:53 +02:00
Paul Sokolovsky
31619cc589 py: mp_obj_str_get_str(): Work with bytes too.
It should be fair to say that almost in all cases where some API call
expects string, it should be also possible to pass byte string. For example,
it should be open/delete/rename file with name as bytestring. Note that
similar change was done quite a long ago to mp_obj_str_get_data().
2014-10-31 00:00:39 +02:00
Paul Sokolovsky
b1422de12f py: Allow to override port config file and thus have >1 configs per port.
Use it like:

make CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_my.h>"'
2014-10-29 23:37:45 +00:00
stijn
49c47da804 Fix errors after enabling -Wpointer-arith 2014-10-29 15:42:38 +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
de3c806965 py: Fix memoryview referencing so it retains ptr to original buffer.
This way, if original parent object is GC'd, the memoryview still points
to the underlying buffer data so that buffer is not GC'd.
2014-10-26 13:20:50 +00:00
Damien George
b0b0012fd8 py: Fix VM dispatch following a pending exception check. 2014-10-26 00:33:23 +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
Damien George
c9fc620723 py: Implement compile builtin, enabled only on unix port.
This should be pretty compliant with CPython, except perhaps for some
corner cases to do with globals/locals context.

Addresses issue #879.
2014-10-25 22:07:25 +01:00
Paul Sokolovsky
e5a3759ff5 py: Factor out mp_obj_is_package() function. 2014-10-25 22:31:33 +03:00
Paul Sokolovsky
8becca7c82 py: mp_builtin___import__(): Add const to arg type. 2014-10-25 22:31:26 +03:00
Damien George
8456cc017b py: Compress load-int, load-fast, store-fast, unop, binop bytecodes.
There is a lot potential in compress bytecodes and make more use of the
coding space.  This patch introduces "multi" bytecodes which have their
argument included in the bytecode (by addition).

UNARY_OP and BINARY_OP now no longer take a 1 byte argument for the
opcode.  Rather, the opcode is included in the first byte itself.

LOAD_FAST_[0,1,2] and STORE_FAST_[0,1,2] are removed in favour of their
multi versions, which can take an argument between 0 and 15 inclusive.
The majority of LOAD_FAST/STORE_FAST codes fit in this range and so this
saves a byte for each of these.

LOAD_CONST_SMALL_INT_MULTI is used to load small ints between -16 and 47
inclusive.  Such ints are quite common and now only need 1 byte to
store, and now have much faster decoding.

In all this patch saves about 2% RAM for typically bytecode (1.8% on
64-bit test, 2.5% on pyboard test).  It also reduces the binary size
(because bytecodes are simplified) and doesn't harm performance.
2014-10-25 20:23:13 +01:00
Damien George
1084b0f9c2 py: Store bytecode arg names in bytecode (were in own array).
This saves a lot of RAM for 2 reasons:

1. For functions that don't have default values, var args or var kw
args (which is a large number of functions in the general case), the
mp_obj_fun_bc_t type now fits in 1 GC block (previously needed 2 because
of the extra pointer to point to the arg_names array).  So this saves 16
bytes per function (32 bytes on 64-bit machines).

2. Combining separate memory regions generally saves RAM because the
unused bytes at the end of the GC block are saved for 1 of the blocks
(since that block doesn't exist on its own anymore).  So generally this
saves 8 bytes per function.

Tested by importing lots of modules:

- 64-bit Linux gave about an 8% RAM saving for 86k of used RAM.
- pyboard gave about a 6% RAM saving for 31k of used RAM.
2014-10-25 20:23:13 +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
564963a170 py: Fix debug-printing of bytecode line numbers.
Also move the raw bytecode printing code from emitglue to mp_bytecode_print.
2014-10-24 14:42:50 +00:00
Damien George
d00d8ac95c py: Use mp_uint_t where appropriate in stream functions. 2014-10-24 11:26:12 +00:00
Paul Sokolovsky
e2f8d98525 stream: Add optional 2nd "length" arg to .readinto() - extension to CPython.
While extension to file.readinto() definition of CPython, the additional arg
is similar to what in CPython available in socket.recv_into().
2014-10-23 21:43:59 +03:00
Damien George
e7bb0443cd py: Properly free string parse-node; add assertion to gc_free. 2014-10-23 14:13:05 +01:00
Damien George
dd4f4530ab py: Add builtin memoryview object (mostly using array code). 2014-10-23 13:34:35 +01:00
Damien George
3aa09f5784 py: Use MP_OBJ_NULL instead of NULL in a few places. 2014-10-23 12:06:53 +01:00
Damien George
37378f8a9d py: Clean up edge cases of malloc/realloc/free. 2014-10-23 12:02:00 +01:00
Damien George
f5d69794a8 extmod: Add uheapq module. 2014-10-22 23:20:15 +01:00
Damien George
e72be1b999 py: Fix smallint modulo with negative arguments.
Addresses issue #927.
2014-10-22 23:05:50 +01:00
Damien George
e7a478204a py: Remove unused and unneeded SystemError exception.
It's purpose is for internal errors that are not catastrophic (ie not as
bad as RuntimeError).  Since we don't use it, we don't need it.
2014-10-22 19:42:55 +01:00
Damien George
20f59e182e py: Make mp_const_empty_bytes globally available. 2014-10-21 21:02:56 +01:00
stijn
2fe4cf7761 Implement kwargs for builtin open() and _io.FileIO
This makes open() and _io.FileIO() more CPython compliant.
The mode kwarg is fully iplemented.
The encoding kwarg is allowed but not implemented; mainly to allow
the tests to specify encoding for CPython, see #874
2014-10-21 22:10:01 +03:00
Damien George
21ca2d76a2 py: Partially fix viper multi-comparison; add test for it. 2014-10-19 19:00:51 +01:00
Paul Sokolovsky
1a55b6a787 unix, stmhal: Implement file.readinto() method.
Also, usocket.readinto(). Known issue is that .readinto() should be available
only for binary files, but micropython uses single method table for both
binary and text files.
2014-10-18 22:44:07 +03:00
Damien George
b7a4b0f86f py: Improve stream_read so it doesn't need to alloc 2 bits of heap. 2014-10-17 23:34:06 +01:00
Damien George
391db8669b py: Add more compiler optimisations for constant if/while conditions. 2014-10-17 17:57:33 +00:00
Damien George
235f9b33c8 py: Simplify compilation of elif blocks. 2014-10-17 17:30:16 +00:00
Damien George
c30595eb1b py: Add more debug printing code in gc_dump_alloc_table. 2014-10-17 14:12:57 +00:00
Damien George
090c9236e8 py: Fix compiling of nested while/for and exception handler.
Addresses issue #912.
2014-10-17 14:08:49 +00:00
Damien George
37ada236b3 py: Take gc_pool_start out of bss section, to reclaim 1st block of heap. 2014-10-16 21:50:39 +01:00
Paul Sokolovsky
923a8a8320 stream: Handle non-blocking errors in readline() properly.
Just like they handled in other read*(). Note that behavior of readline()
in case there's no data when it's called is underspecified in Python lib
spec, implemented to behave as read() - return None.
2014-10-16 12:22:52 +03:00
Paul Sokolovsky
0c7b26c0f8 stream: Return errno value as first arg of OSError exception.
This is CPython-compatible convention established yet in acb13886fc.
2014-10-16 02:58:52 +03:00
Paul Sokolovsky
067ae1269d objclosure: Fix printing of generator closures.
The code previously assumed that only functions can be closed over.
2014-10-16 00:14:01 +03:00
Damien George
9b0b373e5e py: Fix GC realloc issue, where memory chunks were never shrunk.
Previously, a realloc to a smaller memory chunk size would not free the
unused blocks in the tail of the chunk.
2014-10-15 18:24:47 +00:00
Damien George
4859edb95b py: Fix dummy definition of BEGIN/END_ATOMIC_SECTION. 2014-10-15 17:33:24 +00:00
Paul Sokolovsky
911c00bbc5 modzlibd: Remove, superceded by moduzlib. 2014-10-13 14:13:22 +03:00
Damien George
29f5682621 Merge pull request #904 from pfalcon/moduzlib
Module "uzlib" - based on similarly named library
2014-10-12 23:25:24 +01:00
Paul Sokolovsky
34162872b1 moduzlib: Integrate into the system. 2014-10-13 00:07:44 +03:00
Damien George
c14a81662c py: Add module weak link support.
With this patch a port can enable module weak link support and provide
a dict of qstr->module mapping.  This mapping is looked up only if an
import fails to find the requested module in the filesystem.

This allows to have the builtin module named, eg, usocket, and provide
a weak link of "socket" to the same module, but this weak link can be
overridden if a file by the name "socket.py" is found in the import
path.
2014-10-12 20:18:40 +01:00
Damien George
3c34d4140d py: Fix x86 viper code generation, mem8 <-> mem16 for load. 2014-10-12 16:10:25 +00:00
Damien George
91cfd414c0 py: Implement native load for viper.
Viper can now do: ptr8(buf)[0], which loads a byte from a buffer using
machine instructions.
2014-10-12 16:59:29 +01:00
Damien George
1ef2348df0 py: Implement and,or,xor native ops for viper. 2014-10-12 14:21:06 +01:00
Paul Sokolovsky
1606607bd4 modure: Make sure that re1.5 compiled in only of modure itself is enabled.
This is achieved by including re1.5 *.c files straight from modure.c .
2014-10-12 03:40:20 +03:00
Paul Sokolovsky
c71e045165 modure: Initial module, using re1.5 (which is based on re1 codebase).
https://github.com/pfalcon/re1.5
2014-10-11 14:36:32 +03:00
Damien George
9bf5f2857d py: Add further checks for failed malloc in lexer init functions. 2014-10-09 16:53:37 +01:00
Damien George
a8202762f0 Merge branch 'lexer-crash' of https://github.com/dhylands/micropython into dhylands-lexer-crash 2014-10-09 16:48:55 +01:00
Damien George
4091445612 py: Add #if guard around gc-specific code. 2014-10-09 16:44:43 +01:00
Dave Hylands
e20cbbec73 Make lexer fail gracefully when memory can't be allocated. 2014-10-08 23:17:35 -07:00
Dave Hylands
3556e45711 Allow real memory errors (from locked gc) to be reported with traceback. 2014-10-07 08:07:49 -07:00
Damien George
f32498fe04 py: Extra autodetect for little endianness using __LITTLE_ENDIAN__. 2014-10-06 16:09:31 +00:00
Damien George
9336ee320a py: Make mp_binary_set_val work on big endian machine. 2014-10-06 15:05:35 +00:00
Damien George
fcdb239815 py: Make int.to_bytes work on big endian machine.
Partly addresses issue #856.
2014-10-06 13:45:34 +00:00
Damien George
a9bcd51dc7 py: Try to autodetect machine endianness when not defined by port. 2014-10-06 13:44:59 +00:00
Damien George
c4d0868df1 py: Implement proper context save/restore for eval/exec; factor code.
This has benefits all round: code factoring for parse/compile/execute,
proper context save/restore for exec, allow to sepcify globals/locals
for eval, and reduced ROM usage by >100 bytes on stmhal and unix.

Also, the call to mp_parse_compile_execute is tail call optimised for
the import code, so it doesn't increase stack memory usage.
2014-10-05 20:13:34 +01:00
Damien George
a91ac2011f py: Make compiler return a proper exception on SyntaxError. 2014-10-05 19:01:34 +01:00
Fabian Vogt
e5268963c6 Implement missing ARM emitter functions for viper 2014-10-04 00:57:21 +02:00
Damien George
00be7a849a py: Fix unix-cpy to compile with uint->mp_uint_t changes. 2014-10-03 20:05:44 +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
3eaa0c3833 py: Use UINT_FMT instead of %d. 2014-10-03 17:54:25 +00:00
Damien George
42f3de924b py: Convert [u]int to mp_[u]int_t where appropriate.
Addressing issue #50.
2014-10-03 17:44:14 +00:00
Damien George
8b03d944e2 py: Remove IOError since it's deprecated; use OSError instead.
In CPython IOError (and EnvironmentError) is deprecated and aliased to
OSError.  All modules that used to raise IOError now raise OSError (or a
derived exception).

In Micro Python we never used IOError (except 1 place, incorrectly) and
so don't need to keep it.

See http://legacy.python.org/dev/peps/pep-3151/ for background.
2014-09-30 13:59:30 +00:00
Damien George
1c6a1dc740 py: Allow x86-64 to mov r16 to rm16 with extended src reg.
Fixes bug with x86-64 viper ptr16.
2014-09-29 22:44:18 +01:00
Damien George
dfef4249eb py: Fix viper store on x86; add tests for viper ptr16. 2014-09-29 21:41:41 +00:00
Damien George
e9dac3b4d0 py: Add casting to viper; add native mem stores to viper.
Viper can now do the following:

def store(p:ptr8, c:int):
    p[0] = c

This does a store of c to the memory pointed to by p using a machine
instructions inline in the code.
2014-09-29 22:10:41 +01:00
Damien George
3112cde900 py: Implement more binary ops for viper emitter.
This included a bit of restructuring of the assembler backends.  Note
that the ARM backend is missing a few functions and won't compile.
2014-09-29 19:42:06 +01:00
Damien George
6f81348fa2 py: Allow viper to use ints as direct conditionals in jumps.
Allows things like: if 1: ...
2014-09-29 19:42:06 +01:00
Damien George
a7329615eb py: Fix types, uint -> mp_uint_t. 2014-09-29 19:42:06 +01:00
Damien George
0b610de017 py: Make macro names in assemblers consistent, and tidy up a bit. 2014-09-29 19:42:06 +01:00
Damien George
d66e48662b py: Add store r8 and store r16 ops to asm_x86 and asm_x64. 2014-09-29 19:42:06 +01:00
Damien George
851f15f34c py: In asmthumb, clean up unit/int types and ite ops. 2014-09-29 19:42:06 +01:00
bvernoux
f6f248b464 Fix error: unknown type name 'size_t' 2014-09-28 09:54:35 +02:00
Damien George
133b083b89 py: Clean up nlr*.S to make it easier to read; fix clang .bss error.
It seems that newer versions of clang don't like the .bss directive, so
we don't use it for OSX.

Addressing issues #865 and #875.
2014-09-26 13:07:26 +00:00
Damien George
cde0ca21bf py: Simplify JSON str printing (while still conforming to JSON spec).
The JSON specs are relatively flexible and allow us to use one function
to print strings, be they ascii, bytes or utf-8 encoded.
2014-09-25 17:35:56 +01:00
Damien George
4bcd04bcad py: Tidy up exception matching; allow matching of tuple of exceptions.
Addresses issue #864.
2014-09-25 15:49:26 +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
52b5d76a6b py: Free non-interned strings in the parser when not needed.
mp_parse_node_free now frees the memory associated with non-interned
strings.  And the parser calls mp_parse_node_free when discarding a
non-used node (such as a doc string).

Also, the compiler now frees the parse tree explicitly just before it
exits (as opposed to relying on the caller to do this).

Addresses issue #708 as best we can.
2014-09-23 15:31:56 +00:00
Damien George
d6230f62c7 py: Make native emitter handle multi-compare and not/is not/not in ops. 2014-09-23 14:15:45 +00:00
Damien George
eaaebf3291 stmhal: Initialise stack pointer correctly.
Stack is full descending and must be 8-byte aligned.  It must start off
pointing to just above the last byte of RAM.

Previously, stack started pointed to last byte of RAM (eg 0x2001ffff)
and so was not 8-byte aligned.  This caused a bug in combination with
alloca.

This patch also updates some debug printing code.

Addresses issue #872 (among many other undiscovered issues).
2014-09-23 10:59:05 +01:00
Damien George
89e4657c69 extmod: Add loads to ujson module. 2014-09-21 23:43:03 +01:00
Damien George
3d61528fe7 py: Add 'builtins' module. 2014-09-17 23:17: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
8a9b999f1c py: Make dict use a bit less RAM when iterating; properly del values.
Heap RAM was being allocated to print dicts and do some other types of
iterating.  Now these iterations use 1 word of state on the stack.

Deleting elements from a dict was not allowing the value to be reclaimed
by the GC.  This is now fixed.
2014-09-17 15:53:03 +01:00
Damien George
d4a799f152 py: Make asm_arm_less_op take destination register as first arg.
This gets ARM native emitter working againg and addresses issue #858.
2014-09-15 16:39:24 +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
Damien George
83695596ed py: Fix build error when float disabled; add test for divmod. 2014-09-13 19:58:18 +01:00
Damien George
8594ce2280 py: Implement divmod, % and proper // for floating point.
Tested and working on unix and pyboard.
2014-09-13 18:43:09 +01:00
Damien George
bb29546868 py: Load strings as objects when compiling viper.
Eventually, viper wants to be able to use raw pointers to strings and
arrays for efficient access.  But for now, let's just load strings as a
Python object so they can be used as normal.  This will anyway be
compatible with eventual intended viper behaviour.

Addresses issue #857.
2014-09-12 23:15:06 +01:00
Damien George
20beff9ae3 py and libm: Add asinf,acosf; print higher precision for float.
Also use less stack space when printing single precision float.

Addition of asinf and acosf addresses issue #851.
2014-09-11 22:24:45 +01:00
Damien George
953074315e py: Enable struct/binary-helper to parse q and Q sized ints.
Addresses issue #848.
2014-09-10 22:10:33 +01:00
Damien George
6eae861685 py: Put define of x86 argument registers in asmx86.h. 2014-09-08 22:16:35 +00:00
Damien George
7ff996c237 py: Convert [u]int to mp_[u]int_t in emit.h and associated .c files.
Towards resolving issue #50.
2014-09-08 23:05:16 +01:00
Damien George
377b80b624 py: Print imported module's location (__file__) if available. 2014-09-08 10:45:23 +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
c7687ad7e6 py: Rename mp_builtin_id to mp_obj_id and make it public. 2014-09-07 20:41:09 +01:00
Damien George
6c9c7bc75a stmhal: Implement generic select.select and select.poll. 2014-09-07 20:40:32 +01:00
Damien George
c8c44a4c2e py: Add ioctl method to stream protocol; add initial modselect. 2014-09-07 20:40:10 +01:00
Damien George
8105736982 py: Clean up x86-64 native assembler; allow use of extended regs.
Native x86-64 now has 3 locals in registers.
2014-09-07 01:06:19 +01:00
Damien George
25d904105c py: Adjust regs for x86 so that 1 more local can live in a reg. 2014-09-06 23:24:32 +00:00
Damien George
03281b3850 py: Allow x86 native functions to take arguments.
Fix some bugs with x86 stack and saving registers correctly.
2014-09-06 22:38:50 +00:00
Damien George
c90f59ec3a py: Add support for emitting native x86 machine code. 2014-09-06 23:06:36 +01:00
Damien George
33b50a0217 Merge branch 'master' of github.com:micropython/micropython 2014-09-06 18:39:39 +01:00
Damien George
e6ce10a3e7 py: Native emitter now supports delete name & global, and end finally. 2014-09-06 18:38:20 +01:00
Paul Sokolovsky
78fde4819c modstruct: Implement 'O', 'P', 's' types for packed structs.
This is required to deal with, well, packed C structs containing pointers.
2014-09-06 20:22:06 +03:00
Paul Sokolovsky
722e562736 py: Correctly set sys.maxsize value for 64-bit.
Type representing signed size doesn't have to be int, so use special value
which defaults to SSIZE_MAX, but as it's not defined by C standard (but rather
by POSIX), allow ports to set it.
2014-09-06 20:22:06 +03:00
Damien George
8002d5d2b9 py: Fix definition of sys.maxsize with mpz changes. 2014-09-06 17:37:29 +01:00
Damien George
9a21d2e070 py: Make mpz able to use 16 bits per digit; and 32 on 64-bit arch.
Previously, mpz was restricted to using at most 15 bits in each digit,
where a digit was a uint16_t.

With this patch, mpz can use all 16 bits in the uint16_t (improvement
to mpn_div was required).  This gives small inprovements in speed and
RAM usage.  It also yields savings in ROM code size because all of the
digit masking operations become no-ops.

Also, mpz can now use a uint32_t as the digit type, and hence use 32
bits per digit.  This will give decent improvements in mpz speed on
64-bit machines.

Test for big integer division added.
2014-09-06 17:15:34 +01:00
Damien George
afb1cf75dd py: Convert (u)int to mp_(u)int_t in mpz, and remove unused function. 2014-09-05 20:37:06 +01:00
Damien George
e191d42188 py: Use % str formatting instead of {} in makeqstrdata.py.
Script is equivalent, but now also runs under ancient Python 2.6.
Goes part way to addressing issue #847.
2014-09-05 13:16:19 +01:00
Damien George
b534e1b9f1 py: Use variable length encoded uints in more places in bytecode.
Code-info size, block name, source name, n_state and n_exc_stack now use
variable length encoded uints.  This saves 7-9 bytes per bytecode
function for most functions.
2014-09-04 14:44:01 +01:00
Damien George
dda46460ff Code style/whitespace cleanup; remove obsolete headers.
And move the MAP_ANON redefinition from py/asmx64.c to unix/alloc.c.
2014-09-03 22:47:23 +01:00
Fabian Vogt
b7235b8412 Add cache flush in py/asmarm.c and add new MP_PLAT_ALLOC_EXEC and MP_PLAT_FREE_EXEC macros
Fixes issue #840
2014-09-03 23:07:42 +02:00
Damien George
ca6d75f16d py: Small simplifications in tuple and list accessors. 2014-08-30 15:17:47 +01:00
Damien George
4abff7500f py: Change uint to mp_uint_t in runtime.h, stackctrl.h, binary.h.
Part of code cleanup, working towards resolving issue #50.
2014-08-30 14:59:21 +01:00
Damien George
4d91723587 py: Remove use of int type in obj.h.
Part of code cleanup, working towards resolving issue #50.
2014-08-30 14:28:06 +01:00
Damien George
d182b98a37 py: Change all uint to mp_uint_t in obj.h.
Part of code cleanup, working towards resolving issue #50.
2014-08-30 14:19:41 +01:00
Damien George
9c4cbe2ac0 py: Make tuple and list use mp_int_t/mp_uint_t.
Part of code cleanup, to resolve issue #50.
2014-08-30 14:04:14 +01:00
Damien George
93965e726f py: Make map, dict, set use mp_int_t/mp_uint_t exclusively.
Part of code cleanup, towards resolving issue #50.
2014-08-30 13:23:35 +01:00
Damien George
1c70cbf151 py: Save about 200 bytes of ROM by using smaller type for static table. 2014-08-30 00:38:16 +01:00
Damien George
ecc88e949c Change some parts of the core API to use mp_uint_t instead of uint/int.
Addressing issue #50, still some way to go yet.
2014-08-30 00:35:11 +01:00
Damien George
17ae2395c2 py: Use memmove instead of memcpy when appropriate.
Found this bug by running unix/ tests with DEBUG=1 enabled when
compiling.
2014-08-29 21:07:54 +01:00
Damien George
02d95d7ce9 py: Fix 2 bugs in native emitter: jump_or_pop and stack settling.
Addresses issue #838.
2014-08-29 20:05:32 +01:00
Damien George
eb4e18f057 py: Add compiler optimisation for conditions in parenthesis.
Optimises:
    if () -> if False
    if (x,...) -> if True
    if (a and b) -> if a and b
2014-08-29 20:04:01 +01:00
Damien George
110ba35980 py: Move native glue code from runtime.c to new file nativeglue.c.
This way, the native glue code is only compiled if native code is
enabled (which makes complete sense; thanks to Paul Sokolovsky for
the idea).

Should fix issue #834.
2014-08-28 23:37:02 +01:00
Damien George
1ac6faa732 Merge pull request #833 from Vogtinator/arm-native
Basic native ARM emitter
2014-08-28 23:24:43 +01:00
Damien George
516b09efc3 py, gc: Further reduce heap fragmentation with new, faster gc alloc.
The heap allocation is now exactly as it was before the "faster gc
alloc" patch, but it's still nearly as fast.  It is fixed by being
careful to always update the "last free block" pointer whenever the heap
changes (eg free or realloc).

Tested on all tests by enabling EXTENSIVE_HEAP_PROFILING in py/gc.c:
old and new allocator have exactly the same behaviour, just the new one
is much faster.
2014-08-28 23:06:38 +01:00
Damien George
b796e3d848 py: Reduce fragmentation of GC heap.
Recent speed up of GC allocation made the GC have a fragmented heap.
This patch restores "original fragmentation behaviour" whilst still
retaining relatively fast allocation.  This patch works because there is
always going to be a single block allocated now and then, which advances
the gc_last_free_atb_index pointer often enough so that the whole heap
doesn't need scanning.

Should address issue #836.
2014-08-28 10:18:40 +01:00
Fabian Vogt
16ee30c6fa Clarify copyright on asmarm files 2014-08-28 01:18:56 +02:00
Fabian Vogt
fe3d16e8c2 Basic native ARM emitter 2014-08-27 18:18:50 +02:00
Damien George
a75b02ea9b py: Improve efficiency of MP_OBJ_IS_STR_OR_BYTES.
Saves ROM (16 on stmhal, 240 on 64-bit unix) and should be quicker since
there is 1 less branch.
2014-08-27 09:20:30 +01:00
Damien George
ad4c014d46 Merge branch 'int-bytes' of https://github.com/dhylands/micropython into dhylands-int-bytes 2014-08-27 09:13:15 +01:00
Dave Hylands
b7f7c655ed Make int(b'123') work properly. 2014-08-26 19:15:04 -07:00
Damien George
b427d6ae86 py: Fix line number printing for file with 1 line.
With a file with 1 line (and an error on that line), used to show the
line as number 0.  Now shows it correctly as line number 1.

But, when line numbers are disabled, it now prints line number 1 for any
line that has an error (instead of 0 as previously).  This might end up
being confusing, but requires extra RAM and/or hack logic to make it
print something special in the case of no line numbers.
2014-08-26 23:35:57 +01:00
Damien George
779794a680 py: Add dispatch for user defined ==, >, <=, >=.
Addresses issue #827.
2014-08-26 09:31:26 +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
7310fd469a py: Consolidate min/max functions into one, and add key= argument.
Addresses issue #811.
2014-08-24 19:14:09 +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
26a0d4f4f1 py: Change hash and len members of str from 16 bit to full word.
This allows to make strings longer than 64k.  It doesn't use any more
RAM with current GC because a str object still fits in a GC block.
2014-08-22 18:34:28 +01:00
Damien George
69b7dae362 py: Small cleanup in stream.c. 2014-08-22 18:30:02 +01:00
Damien George
d5e7f6e37e py: Speed up GC allocation.
This simple patch gives a very significant speed up for memory allocation
with the GC.

Eg, on PYBv1.0:
tests/basics/dict_del.py: 3.55 seconds -> 1.19 seconds
tests/misc/rge_sm.py:     15.3 seconds -> 2.48 seconds
2014-08-22 18:17:02 +01:00
Damien George
7fe2191c9b py: Code clean-up in native emitter; improve thumb native calls. 2014-08-16 22:31:57 +01:00
Damien George
86de21b810 py: Viper can call functions with native types, and raise exceptions. 2014-08-16 22:06:11 +01:00
Damien George
8f81b5cb4b py: Put SystemExit in builtin namespace.
Also fix unix port so that SystemExit with no arg exits with value 0.
2014-08-16 14:32:06 +01:00
Damien George
e6c0dff967 py: Viper can now store to global. 2014-08-15 23:47:59 +01:00
Damien George
a5190a7dac py: Fix typing of viper locals; allow default types in annotation. 2014-08-15 22:39:08 +01:00
Damien George
2ac4af6946 py: Allow viper to have type annotations.
Viper functions can now be annotated with the type of their arguments
and return value.  Eg:

@micropython.viper
def f(x:int) -> int:
    return x + 1
2014-08-15 16:45:41 +01:00
Damien George
6be0b0a8ec py: Clean up and simplify functions in scope; add STATIC in compiler.
Some small code clean-ups that result in about 80 bytes ROM saving for
stmhal.
2014-08-15 14:30:52 +01:00
Damien George
9b7a8ee8f1 py: Fix mult by negative number of tuple, list, str, bytes.
Multiplication of a tuple, list, str or bytes now yields an empty
sequence (instead of crashing).  Addresses issue #799

Also added ability to mult bytes on LHS by integer.
2014-08-13 13:22:24 +01:00
Paul Sokolovsky
510296f25a modzlibd: Decompress part of "zlib" module, based on miniz tinfl.c . 2014-08-13 00:26:19 +03:00
Damien George
75ec22bf11 py: #if guard qstrs that are optional.
Also disable gc module on bare-arm port.
2014-08-12 20:16:03 +01:00
Damien George
f20375eedd py: Add .real and .imag attributes to complex numbers. 2014-08-12 19:57:52 +01:00
Damien George
bb91f1195a py: Improve range: add len, subscr, proper print.
Can now index ranges with integers and slices, and reverse ranges
(although reversing is not very efficient).

Not sure how useful this stuff is, but gets us closer to having all of
Python's builtins.
2014-08-12 19:41:18 +01:00
Damien George
4c03b3a899 py: Implement builtin reversed() function.
reversed function now implemented, and works for tuple, list, str, bytes
and user objects with __len__ and __getitem__.

Renamed mp_builtin_len to mp_obj_len to make it publically available (eg
for reversed).
2014-08-12 18:33:40 +01:00
Damien George
69c5fe1df6 py: Make a function static; replace NULL with MP_OBJ_NULL. 2014-08-12 18:13:44 +01:00
Damien George
2eb1f604ee py, objstr: Optimise bytes subscr when unicode is enabled.
Saves code bytes and makes it faster, so why not?
2014-08-11 23:24:29 +01:00
Damien George
7703d71938 py, modcmath: Fix doc comment, and add some more of them. 2014-08-11 22:19:44 +00:00
Paul Sokolovsky
9749b2fb0d objstr: Make sure that bytes are indexed as bytes, not as unicode.
Fixes #795.
2014-08-11 22:38:00 +03:00
Paul Sokolovsky
0c5498540b objstr: split(): check arg type consistency (str vs bytes).
Similar to other methods and following CPython3 strictness.
2014-08-10 23:21:16 +03:00
Paul Sokolovsky
ecca53bd34 py: binary.c: Properly implement alignment for native unpacked structs. 2014-08-10 23:21:08 +03:00
Damien George
4ef26c14b1 doc: Fix up a few docs in sys module. 2014-08-10 17:53:43 +01:00
Damien George
30dd23aa7f doc: Document gc, sys, math, cmath. 2014-08-10 17:50:28 +01:00
Paul Sokolovsky
5f930337bc objarray: Implement equality testing between arrays and other buffers. 2014-08-10 16:22:57 +03:00
Paul Sokolovsky
7133d91773 py: mp_buffer_info_t::buf may be valid, but NULL for empty objects.
This happens for example for zero-size arrays. As .get_buffer() method now
has explicit return value, it's enough to distinguish success vs failure
of getting buffer.
2014-08-10 16:22:48 +03:00
Damien George
a1d3ee376c py: Fix bug where GC finaliser table was not completely zeroed out.
This was a nasty bug to track down.  It only had consequences when the
heap size was just the right size to expose the rounding error in the
calculation of the finaliser table size.  And, a script had to allocate
a small (1 or 2 cell) object at the very end of the heap.  And, this
object must not have a finaliser.  And, the initial state of the heap
must have been all bits set to 1.  All these conspire on the pyboard,
but only if your run the script fresh (so unused memory is all 1's),
and if your script allocates a lot of small objects (eg 2-char strings
that are not interned).
2014-08-08 12:33:49 +01:00
Damien George
5d9b816449 py: Fix bug in mpn_shl (multi-prec int shift left).
Before this patch, eg, 1 << 75 (or any large multiple of 15) was setting
the MSB in the digits, which is outside the valid range of DIG_MASK.
2014-08-07 14:27:48 +00:00
Damien George
8dbbbbc793 Put call to qstr_init and mp_init_emergency_exc_buf in mp_init.
qstr_init is always called exactly before mp_init, so makes sense to
just have mp_init call it.  Similarly with
mp_init_emergency_exception_buf.  Doing this makes the ports simpler and
less error prone (ie they can no longer forget to call these).
2014-08-04 10:05:16 +01:00
Damien George
4747becc64 py: Improve encoding scheme for line-number to bytecode map.
Reduces by about a factor of 10 on average the amount of RAM needed to
store the line-number to bytecode map in the bytecode prelude.

Using CPython3.4's stdlib for statistics: previously, an average of
13 bytes were used per (bytecode offset, line-number offset) pair, and
now with this improvement, that's down to 1.3 bytes on average.

Large RAM usage before was due to some very large steps in line numbers,
both from the start of the first line in a function way down in the
file, and also functions that have big comments and/or big strings in
them (both cases were significant).

Although the savings are large on average for the CPython stdlib, it
won't have such a big effect for small scripts used in embedded
programming.

Addresses issue #648.
2014-07-31 16:12:01 +00:00
Damien George
8cc2018d47 Merge branch 'master' of https://github.com/micropython/micropython 2014-07-31 13:47:06 +00:00
Damien George
c9aa58e638 py: Improve handling of long-int overflow.
This removes mpz_as_int, since that was a terrible function (it
implemented saturating conversion).

Use mpz_as_int_checked and mpz_as_uint_checked.  These now work
correctly (they previously had wrong overflow checking, eg
print(chr(10000000000000)) on 32-bit machine would incorrectly convert
this large number to a small int).
2014-07-31 13:41:43 +00:00
Damien George
bb4c6f35c6 py: Make MP_OBJ_NEW_SMALL_INT cast arg to mp_int_t itself.
Addresses issue #724.
2014-07-31 10:49:14 +01:00
Damien George
5f27a7e811 py: Add mp_obj_str_builder_end_with_len.
This allows to create str's with a smaller length than initially asked
for.
2014-07-31 10:29:56 +01:00
Damien George
94fbe9711a py: Change lexer stream API to return bytes not chars.
Lexer is now 8-bit clean inside strings.
2014-07-30 11:46:05 +01:00
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
Paul Sokolovsky
645582fe14 py: Make id() return small int for the most common address space mapping.
Many OSes/CPUs have affinity to put "user" data into lower half of address
space. Take advantage of that and remap such addresses into full small int
range (including negative part).

If address is from upper half, long int will be used. Previously, small
int was returned for lower quarter of address space, and upper quarter. For
2 middle quarters, long int was used, which is clearly worse schedule than
the above.
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
ffe911d228 py: Make long ints hashable.
Addresses issue #765.
2014-07-24 14:21:37 +01:00
Paul Sokolovsky
4ecb700fe3 streams: Treat non-error output size as unsigned. 2014-07-23 00:25:46 +03:00
Paul Sokolovsky
e1b1abc1e8 stream: Revert to checking for the correct error value. 2014-07-23 00:23:44 +03:00
Dave Hylands
1d8816c36b Deal with reading a buffer less than what was allocated.
With this fix, file_long_read now passes.
2014-07-21 19:10:10 -07:00
Paul Sokolovsky
cb66f41ebc py: Make print() accept "file" argument, and actually print to stream.
And not system printf(), like it was before. For this, move pfenv_printf()
from stmhal port to py/.
2014-07-19 21:27:22 +03: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
5467186b0e py: Remove unnecessary argument in bytearray print. 2014-07-17 21:56:32 +01:00
Paul Sokolovsky
e3737b858a formatfloat.c: Typo fix in comment. 2014-07-17 20:45:58 +03:00
Damien George
a4022c92f0 py, inline asm: Change "and" op name to "and_" to avoid keyword clash.
Addresses issue #753.
2014-07-17 12:37:56 +01:00
Paul Sokolovsky
ac736f15c9 stream: Factor out mp_stream_write() method to write a memstring to stream. 2014-07-13 23:14:32 +03:00
Paul Sokolovsky
564e46452d py: Add generic helper to align a pointer. 2014-07-12 15:57:28 +03:00
Paul Sokolovsky
58c9586c34 emitbc: Fix structure field alignment issue.
dummy_data field is accessed as uint value (e.g.
in emit_write_bytecode_byte_ptr), but is not aligned as such, which causes
bus errors or incorrect behavior on any arch requiring strictly aligned
data (ARM pre-v7, MIPS, etc, etc).
2014-07-12 15:57:28 +03:00
Paul Sokolovsky
2097c8b1e1 moductypes: Add symbolic constants to specify bitfield position/length. 2014-07-11 00:06:36 +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
5fa5ca40e6 binary: Factor out mp_binary_set_int(). 2014-07-05 23:54:03 +03:00
Damien George
0182385ab0 py: Automatically ake __new__ a staticmethod.
Addresses issue #622.
2014-07-05 05:55:00 +01: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
381618269a parser: Convert (u)int to mp_(u)int_t. 2014-07-03 14:13:33 +01:00
Damien George
54eb4e723e lexer: Convert type (u)int to mp_(u)int_t. 2014-07-03 13:47:47 +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
f0b29729aa py, objexcept: Only check for locked gc if gc is enabled. 2014-07-01 14:28:09 +01:00
Damien George
f065344d3b Merge branch 'preserve-except' of github.com:dhylands/micropython into dhylands-preserve-except 2014-07-01 14:26:37 +01:00
Dave Hylands
2fe841d2fa Try not to cause a MemoryError when raising an exception during nterrupt handling.
Step 1 fixes #732
2014-06-30 22:49:21 -07:00
Paul Sokolovsky
caa7334141 stackctrl: Add "mp_" prefix. 2014-07-01 02:14:08 +03:00
Damien George
4039a26679 Merge pull request #710 from iabdalkader/assert
Fix assert_func warning/error
2014-06-30 09:09:24 +01:00
Damien George
b601d9574a py: Improvements to native emitter.
Native emitter can now compile try/except blocks using nlr_push/nlr_pop.
It probably only works for 1 level of exception handling.  It doesn't
work on Thumb (only x64).

Native emitter can also handle some additional op codes.

With this patch, 198 tests now pass using "-X emit=native" option to
micropython.
2014-06-30 05:17:25 +01: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
Paul Sokolovsky
9e215fa4c2 py: Make unichar_charlen() accept/return machine_uint_t. 2014-06-28 23:15:29 +03:00
Damien George
8546ce1e28 py: Add missing #endif. 2014-06-28 10:29:22 +01:00
Damien George
e04a44e2f6 py: Small comments, name changes, use of machine_int_t. 2014-06-28 10:27:23 +01:00
Damien George
b3a50f0f3e Merge branch 'master' into unicode
Conflicts:
	py/mpconfig.h
2014-06-28 10:27:15 +01:00
Paul Sokolovsky
8993fb6cf0 py: Add protection against printing too nested or recursive data structures.
With a test which cannot be automatically validated so far.
2014-06-28 02:25:04 +03:00
Paul Sokolovsky
cb78f862cb py: Allow to disable array module and bytearray type.
array.array and bytearray share big deal of code, so to get real savings,
both need to be disabled.
2014-06-27 21:02:04 +03: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
f5f6c3b792 streams: Reading by char count from unicode text streams is not implemented. 2014-06-27 00:04:20 +03:00
Paul Sokolovsky
ce81312d8a misc: Add count_lead_ones() function, useful for UTF-8 handling. 2014-06-27 00:04:20 +03:00
Paul Sokolovsky
ea2c936c7e objstrunicode: Refactor str_index_to_ptr() following objstr. 2014-06-27 00:04:20 +03:00