summaryrefslogtreecommitdiff
path: root/py/parse.c
AgeCommit message (Collapse)Author
2016-06-06py/parse: Treat constants that start with underscore as private.Damien George
Assignments of the form "_id = const(value)" are treated as private (following a similar CPython convention) and code is no longer emitted for the assignment to a global variable. See issue #2111.
2016-05-20py: Declare constant data as properly constant.Damien George
Otherwise some compilers (eg without optimisation) will put this read-only data in RAM instead of ROM.
2016-05-10py/parse: Add uerrno to list of modules to look for constants in.Damien George
2016-04-14py: Simplify "and" action within parser by making ident-rules explicit.Damien George
Most grammar rules can optimise to the identity if they only have a single argument, saving a lot of RAM building the parse tree. Previous to this patch, whether a given grammar rule could be optimised was defined (mostly implicitly) by a complicated set of logic rules. With this patch the definition is always specified explicitly by using "and_ident" in the rule definition in the grammar. This simplifies the logic of the parser, making it a bit smaller and faster. RAM usage in unaffected.
2016-04-13py: Fix constant folding and inline-asm to work with new async grammar.Damien George
2016-03-19py/parse: When looking up consts, check they exist before checking type.Damien George
2016-02-23py/parse: Use m_renew_maybe to ensure that memory is shrunk in-place.Damien George
The chunks of memory that the parser allocates contain parse nodes and are pointed to from many places, so these chunks cannot be relocated by the memory manager. This patch makes it so that when a chunk is shrunk to fit, it is not relocated.
2016-01-12py: unary_op enum type fix, and a cast to remove clang warningAntonin ENFRUN
2016-01-08py/parse: Include unistd.h for ssize_t definition.Damien George
In some cases ssize_t is not defined by already included headers.
2016-01-07py/parse: Improve constant folding to operate on small and big ints.Damien George
Constant folding in the parser can now operate on big ints, whatever their representation. This is now possible because the parser can create parse nodes holding arbitrary objects. For the case of small ints the folding is still efficient in RAM because the folded small int is stored inplace in the parse node. Adds 48 bytes to code size on Thumb2 architecture. Helps reduce heap usage because more constants can be computed at compile time, leading to a smaller parse tree, and most importantly means that the constants don't have to be computed at runtime (perhaps more than once). Parser will now be a little slower when folding due to calls to runtime to do the arithmetic.
2016-01-07py/parse: Optimise away parse node that's just parenthesis around expr.Damien George
Before this patch, (x+y)*z would be parsed to a tree that contained a redundant identity parse node corresponding to the parenthesis. With this patch such nodes are optimised away, which reduces memory requirements for expressions with parenthesis, and simplifies the compiler because it doesn't need to handle this identity case. A parenthesis parse node is still needed for tuples.
2015-12-18py: Add MICROPY_ENABLE_COMPILER and MICROPY_PY_BUILTINS_EVAL_EXEC opts.Damien George
MICROPY_ENABLE_COMPILER can be used to enable/disable the entire compiler, which is useful when only loading of pre-compiled bytecode is supported. It is enabled by default. MICROPY_PY_BUILTINS_EVAL_EXEC controls support of eval and exec builtin functions. By default they are only included if MICROPY_ENABLE_COMPILER is enabled. Disabling both options saves about 40k of code size on 32-bit x86.
2015-12-17py/parse: Replace mp_int_t/mp_uint_t with size_t etc, where appropriate.Damien George
2015-11-29py: Add support for 64-bit NaN-boxing object model, on 32-bit machine.Damien George
To use, put the following in mpconfigport.h: #define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_D) #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE) typedef int64_t mp_int_t; typedef uint64_t mp_uint_t; #define UINT_FMT "%llu" #define INT_FMT "%lld" Currently does not work with native emitter enabled.
2015-11-29py: Wrap all obj-ptr conversions in MP_OBJ_TO_PTR/MP_OBJ_FROM_PTR.Damien George
This allows the mp_obj_t type to be configured to something other than a pointer-sized primitive type. This patch also includes additional changes to allow the code to compile when sizeof(mp_uint_t) != sizeof(void*), such as using size_t instead of mp_uint_t, and various casts.
2015-11-29py: Add MP_ROM_* macros and mp_rom_* types and use them.Damien George
2015-11-17py: Implement default and star args for lambdas.Damien George
2015-10-12py/parse: Make parser error handling cleaner, less spaghetti-like.Damien George
2015-10-12py: Move constant folding from compiler to parser.Damien George
It makes much more sense to do constant folding in the parser while the parse tree is being built. This eliminates the need to create parse nodes that will just be folded away. The code is slightly simpler and a bit smaller as well. Constant folding now has a configuration option, MICROPY_COMP_CONST_FOLDING, which is enabled by default.
2015-10-08py/parse: Factor logic when creating parse node from and-rule.Damien George
2015-10-02py: Allocate parse nodes in chunks to reduce fragmentation and RAM use.Damien George
With this patch parse nodes are allocated sequentially in chunks. This reduces fragmentation of the heap and prevents waste at the end of individually allocated parse nodes. Saves roughly 20% of RAM during parse stage.
2015-08-17unix-cpy: Remove unix-cpy. It's no longer needed.Damien George
unix-cpy was originally written to get semantic equivalent with CPython without writing functional tests. When writing the initial implementation of uPy it was a long way between lexer and functional tests, so the half-way test was to make sure that the bytecode was correct. The idea was that if the uPy bytecode matched CPython 1-1 then uPy would be proper Python if the bytecodes acted correctly. And having matching bytecode meant that it was less likely to miss some deep subtlety in the Python semantics that would require an architectural change later on. But that is all history and it no longer makes sense to retain the ability to output CPython bytecode, because: 1. It outputs CPython 3.3 compatible bytecode. CPython's bytecode changes from version to version, and seems to have changed quite a bit in 3.5. There's no point in changing the bytecode output to match CPython anymore. 2. uPy and CPy do different optimisations to the bytecode which makes it harder to match. 3. The bytecode tests are not run. They were never part of Travis and are not run locally anymore. 4. The EMIT_CPYTHON option needs a lot of extra source code which adds heaps of noise, especially in compile.c. 5. Now that there is an extensive test suite (which tests functionality) there is no need to match the bytecode. Some very subtle behaviour is tested with the test suite and passing these tests is a much better way to stay Python-language compliant, rather than trying to match CPy bytecode.
2015-07-24py/parse: Fix handling of empty input so it raises an exception.Damien George
2015-07-24py/parse: De-duplicate and simplify code for parser "or" rule.Damien George
2015-07-14py: Improve allocation policy of qstr data.Damien George
Previous to this patch all interned strings lived in their own malloc'd chunk. On average this wastes N/2 bytes per interned string, where N is the number-of-bytes for a quanta of the memory allocator (16 bytes on 32 bit archs). With this patch interned strings are concatenated into the same malloc'd chunk when possible. Such chunks are enlarged inplace when possible, and shrunk to fit when a new chunk is needed. RAM savings with this patch are highly varied, but should always show an improvement (unless only 3 or 4 strings are interned). New version typically uses about 70% of previous memory for the qstr data, and can lead to savings of around 10% of total memory footprint of a running script. Costs about 120 bytes code size on Thumb2 archs (depends on how many calls to gc_realloc are made).
2015-04-21py: Clean up some bits and pieces in parser, grammar.Damien George
2015-02-23py: Update parse.c&mpconfig.h to reflect rename of mp_lexer_show_token.nhtshot
This function is only used when DEBUG_PRINTERS and USE_RULE_NAME are enabled.
2015-02-13py: Expose compile.c:list_get as mp_parse_node_extract_list.Damien George
2015-02-08py: Initialise variables in mp_parse correctly, to satisfy gcc warning.Damien George
2015-02-08py: Parse big-int/float/imag constants directly in parser.Damien George
Previous to this patch, a big-int, float or imag constant was interned (made into a qstr) and then parsed at runtime to create an object each time it was needed. This is wasteful in RAM and not efficient. Now, these constants are parsed straight away in the parser and turned into objects. This allows constants with large numbers of digits (so addresses issue #1103) and takes us a step closer to #722.
2015-02-07py: Protect mp_parse and mp_compile with nlr push/pop block.Damien George
To enable parsing constants more efficiently, mp_parse should be allowed to raise an exception, and mp_compile can already raise a MemoryError. So these functions need to be protected by an nlr push/pop block. This patch adds that feature in all places. This allows to simplify how mp_parse and mp_compile are called: they now raise an exception if they have an error and so explicit checking is not needed anymore.
2015-01-24py: Be more machine-portable with size of bit fields.Damien George
2015-01-20py, unix, stmhal: Allow to compile with -Wshadow.Damien George
See issue #699.
2015-01-16py, unix: Allow to compile with -Wsign-compare.Damien George
See issue #699.
2015-01-14py: Add "default" to switches to allow better code flow analysis.Damien George
This helps compiler produce smaller code. Saves 124 bytes on stmhal and bare-arm.
2015-01-13py: Never intern data of large string/bytes object; add relevant tests.Damien George
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-01py: Move to guarded includes, everywhere in py/ core.Damien George
Addresses issue #1022.
2014-12-20py: Remove unnecessary RULE_none and PN_none from parser.Damien George
2014-12-20py: Add blank and ident flags to grammar rules to simplify parser.Damien George
This saves around 100 bytes code space on stmhal, more on unix.
2014-12-20py: Save a few code bytes in parser; make vars local where possible.Damien George
2014-12-05py: Optimise lexer by exposing lexer type.Damien George
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-10-23py: Properly free string parse-node; add assertion to gc_free.Damien George
2014-09-23py: Free non-interned strings in the parser when not needed.Damien George
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-08-15py: Allow viper to have type annotations.Damien George
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-07-03parser: Convert (u)int to mp_(u)int_t.Damien George
2014-07-03Rename machine_(u)int_t to mp_(u)int_t.Damien George
See discussion in issue #50.
2014-06-21py: Include mpconfig.h before all other includes.Paul Sokolovsky
It defines types used by all other headers. Fixes #691.
2014-05-28py: Fix check of small-int overflow when parsing ints.Damien George
Also unifies use of SMALL_INT_FITS macro across parser and runtime.
2014-05-25Change const byte* to const char* where sensible.Damien George
This removes need for some casts (at least, more than it adds need for new casts!).
2014-05-25py: Don't automatically intern strings in parser.Damien George
This completes non-automatic interning of strings in the parser, so that doc strings don't take up RAM. It complicates the parser and compiler, and bloats stmhal by about 300 bytes. It's complicated because now there are 2 kinds of parse-nodes that can be strings: interned leaves and non-interned structs.