summaryrefslogtreecommitdiffstatshomepage
path: root/py/compile.c
Commit message (Collapse)AuthorAge
* py: Remove mp_load_const_bytes and instead load precreated bytes object.Damien George2015-06-25
| | | | | | | | | | | | | | | | Previous to this patch each time a bytes object was referenced a new instance (with the same data) was created. With this patch a single bytes object is created in the compiler and is loaded directly at execute time as a true constant (similar to loading bignum and float objects). This saves on allocating RAM and means that bytes objects can now be used when the memory manager is locked (eg in interrupts). The MP_BC_LOAD_CONST_BYTES bytecode was removed as part of this. Generated bytecode is slightly larger due to storing a pointer to the bytes object instead of the qstr identifier. Code size is reduced by about 60 bytes on Thumb2 architectures.
* py: Make viper codegen raise proper exception (ViperTypeError) on error.Damien George2015-04-20
| | | | | | | | | | | This fixes a long standing problem that viper code generation gave terrible error messages, and actually no errors on pyboard where assertions are disabled. Now all compile-time errors are raised as proper Python exceptions, and are of type ViperTypeError. Addresses issue #940.
* py: Remove old debugging printf's in compile.c.Damien George2015-04-11
|
* py: Provide typedefs for function types instead of writing them inline.Damien George2015-04-09
|
* py: Adjust some spaces in code style/format, purely for consistency.Damien George2015-04-09
|
* py, compiler: When just bytecode, make explicit calls instead of table.Damien George2015-03-26
| | | | | | | | | | | | | | | | | | When just the bytecode emitter is needed there is no need to have a dynamic method table for the emitter back-end, and we can instead directly call the mp_emit_bc_XXX functions. This gives a significant reduction in code size and a very slight performance boost for the compiler. This patch saves 1160 bytes code on Thumb2 and 972 bytes on x86, when native emitters are disabled. Overall savings in code over the last 3 commits are: bare-arm: 1664 bytes. minimal: 2136 bytes. stmhal: 584 bytes (it has native emitter enabled). cc3200: 1736 bytes.
* py, compiler: Remove emit_pass1 code, using emit_bc to do its job.Damien George2015-03-26
| | | | | | | | | | | | | | | First pass for the compiler is computing the scope (eg if an identifier is local or not) and originally had an entire table of methods dedicated to this, most of which did nothing. With changes from previous commit, this set of methods can be removed and the methods from the bytecode emitter used instead, with very little modification -- this is what is done in this commit. This factoring has little to no impact on the speed of the compiler (tested by compiling 3763 Python scripts and timing it). This factoring reduces code size by about 270-300 bytes on Thumb2 archs, and 400 bytes on x86.
* py, compiler: Refactor load/store/delete_id logic to reduce code size.Damien George2015-03-26
| | | | Saves around 230 bytes on Thumb2 and 750 bytes on x86.
* py: Fix bug in compiler which allowed through illegal augmented assign.Damien George2015-03-25
| | | | It allowed such things as (a, b) += c.
* py: Simplify some logic in compiler; add comments about CPython compat.Damien George2015-03-25
|
* py, extmod: Remove include of unnecessary system headers.Damien George2015-03-14
|
* py: Add MICROPY_COMP_{DOUBLE,TRIPLE}_TUPLE_ASSIGN config options.Damien George2015-03-14
| | | | | | These allow to fine-tune the compiler to select whether it optimises tuple assignments of the form a, b = c, d and a, b, c = d, e, f. Sensible defaults are provided.
* py: In compiler, put macro guard around potentially unused asm vars.Damien George2015-03-14
|
* py: Simplify some inline-assembler error messages, but retain meaning.Damien George2015-03-03
| | | | | Just to reduce code size. Messages are still to the point and unambiguous.
* py: Give error for duplicate label in inline assembler.Damien George2015-03-03
|
* py: Set compiler scope before folding constants so error messages work.Damien George2015-03-01
| | | | Addresses issue #1140.
* py: Combine complie functions for or_test/and_test to reduce code size.Damien George2015-02-28
| | | | Saves around 60 bytes code on Thumb2 archs.
* py: Combine emit functions for jump true/false to reduce code size.Damien George2015-02-28
| | | | Saves 116 bytes for stmhal and 56 bytes for cc3200 port.
* py: Combine logic for compiling and/or tests, to reduce code size.Damien George2015-02-28
| | | | Reduces code size by 72 bytes on Thumb2 archs.
* py: Transform assert logic in compiler to save code space.Damien George2015-02-27
| | | | Saves about 250 code bytes for Thumb2 archs.
* py: More robust checking in inline assembler compiler.Damien George2015-02-16
|
* py: Expose compile.c:list_get as mp_parse_node_extract_list.Damien George2015-02-13
|
* py: Make inline assembler raise proper SyntaxError exception on error.Damien George2015-02-13
| | | | Also gives line number of location of error. Very useful!
* py: Parse big-int/float/imag constants directly in parser.Damien George2015-02-08
| | | | | | | | | 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.
* py: Protect mp_parse and mp_compile with nlr push/pop block.Damien George2015-02-07
| | | | | | | | | | 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.
* py: Change vstr so that it doesn't null terminate buffer by default.Damien George2015-01-28
| | | | | | | | | This cleans up vstr so that it's a pure "variable buffer", and the user can decide whether they need to add a terminating null byte. In most places where vstr is used, the vstr did not need to be null terminated and so this patch saves code size, a tiny bit of RAM, and makes vstr usage more efficient. When null termination is needed it must be done explicitly using vstr_null_terminate.
* py: Remove mp_obj_str_builder and use vstr instead.Damien George2015-01-21
| | | | | | | | | | | | With this patch str/bytes construction is streamlined. Always use a vstr to build a str/bytes object. If the size is known beforehand then use vstr_init_len to allocate only required memory. Otherwise use vstr_init and the vstr will grow as needed. Then use mp_obj_new_str_from_vstr to create a str/bytes object using the vstr memory. Saves code ROM: 68 bytes on stmhal, 108 bytes on bare-arm, and 336 bytes on unix x64.
* py, unix: Allow to compile with -Wunused-parameter.Damien George2015-01-20
| | | | See issue #699.
* py, unix, stmhal: Allow to compile with -Wshadow.Damien George2015-01-20
| | | | See issue #699.
* py, unix: Allow to compile with -Wsign-compare.Damien George2015-01-16
| | | | See issue #699.
* py: Remove unnecessary id_flags argument from emitter's load_fast.Damien George2015-01-16
| | | | Saves 24 bytes in bare-arm.
* py: Add "default" to switches to allow better code flow analysis.Damien George2015-01-14
| | | | | This helps compiler produce smaller code. Saves 124 bytes on stmhal and bare-arm.
* py: Only allocate strings/bytes once for load_const_obj.Damien George2015-01-14
|
* py: Reluctantly add an extra pass to bytecode compiler.Damien George2015-01-14
| | | | | | | | | | | | | | | 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.
* py: Make compiler not crash when default except is not last.Damien George2015-01-13
|
* py: Never intern data of large string/bytes object; add relevant tests.Damien George2015-01-13
| | | | | | | | | | 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.
* py: Add config option MICROPY_COMP_MODULE_CONST for module consts.Damien George2015-01-10
| | | | | | 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.
* py: Move to guarded includes, everywhere in py/ core.Damien George2015-01-01
| | | | Addresses issue #1022.
* py: Allow to properly disable builtin slice operation.Damien George2014-12-27
| | | | | | | 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.
* py: Allow to properly disable builtin "set" object.Damien George2014-12-27
| | | | | | | | 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.
* py: Remove last uses of printf from compile; use proper SyntaxError.Damien George2014-12-21
|
* py: Move global/nonlocal decl code to compiler for proper SyntaxError.Damien George2014-12-21
| | | | | | 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.
* py: Remove unnecessary RULE_none and PN_none from parser.Damien George2014-12-20
|
* py: Fix optimised for-loop compiler so it follows proper semantics.Damien George2014-12-12
| | | | | | | | | 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!).
* py: Fix a semantic issue with range optimisation.Damien George2014-12-11
| | | | | | | Now you can assign to the range variable within the for loop and it will still work. Partially addresses issue #565.
* py: Make functions static where appropriate.Damien George2014-12-10
|
* py: Fix bug with right-shifting small ints by large amounts.Paul Sokolovsky2014-11-02
| | | | Undefined behavior in C, needs explicit check.
* py: Add more compiler optimisations for constant if/while conditions.Damien George2014-10-17
|
* py: Simplify compilation of elif blocks.Damien George2014-10-17
|
* py: Fix compiling of nested while/for and exception handler.Damien George2014-10-17
| | | | Addresses issue #912.