summaryrefslogtreecommitdiffstatshomepage
path: root/py/compile.c
Commit message (Collapse)AuthorAge
* py: Add support for 64-bit NaN-boxing object model, on 32-bit machine.Damien George2015-11-29
| | | | | | | | | | | | | 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.
* py: Change qstr_* functions to use size_t as the type for str len arg.Damien George2015-11-29
|
* py/compile: Do proper checking of * and ** in function definition.Damien George2015-11-23
| | | | | This patch checks that there is only one *, and that ** is last in the arg list.
* py/compile: Add mp_compile_to_raw_code() to return raw code object.Damien George2015-11-20
| | | | This can then be passed to mp_raw_code_save_file to save a .mpy file.
* py: Implement default and star args for lambdas.Damien George2015-11-17
|
* py/compile: Don't unnecessarily save state when compiling param list.Damien George2015-11-17
| | | | | Parameter lists can't be nested so there is no need to save the global state when compiling them.
* py: Put all bytecode state (arg count, etc) in bytecode.Damien George2015-11-13
|
* py/compile: Remove unnecessary label in compilation of for statement.Damien George2015-10-14
|
* py: Move constant folding from compiler to parser.Damien George2015-10-12
| | | | | | | | | | 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.
* py: Don't generate unnecessary parse nodes for assignment or kwargs.Damien George2015-10-08
| | | | | This patch eliminates the need for a nested parse node for assignments and keyword arguments. It saves a little bit of RAM when parsing.
* py/compile: Fix edge case when constant-folding negation of integer.Damien George2015-10-08
| | | | Also adds tests specifically for testing constant folding.
* py: Allow to enable inline assembler without native emitter.Damien George2015-10-03
|
* py: Allocate parse nodes in chunks to reduce fragmentation and RAM use.Damien George2015-10-02
| | | | | | | | 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.
* py: Catch all cases of integer (big and small) division by zero.Damien George2015-10-01
|
* py/compile: Put compiler state on the C stack.Damien George2015-09-24
| | | | | It's relatively small (between 44 and 56 bytes) and helps to reduce heap pressure and fragmentation during compilation.
* py: Slightly simplify compile and emit of star/double-star arguments.Damien George2015-09-23
| | | | | Saves a few bytes of code space and eliminates need for rot_two bytecode (hence saving RAM and execution time, by a tiny bit).
* py: Fix call args when a stararg is followed by keyword args.Delio Brignoli2015-09-23
|
* py/compile: Refine SyntaxError for repeated use of global/nonlocal.Damien George2015-09-07
|
* py/compile: Only compile function annotations if really needed.Damien George2015-09-04
| | | | | | Function annotations are only needed when the native emitter is enabled and when the current scope is emitted in viper mode. All other times the annotations can be skipped completely.
* py: Remove unused compile scope flags, and irrelevant flag compute code.Damien George2015-08-17
|
* unix-cpy: Remove unix-cpy. It's no longer needed.Damien George2015-08-17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* py/compile: Give more precise line number for compile errors.Damien George2015-07-29
| | | | | | | | | | | | | | Previous to this patch there were some cases where line numbers for errors were 0 (unknown). Now the compiler attempts to give a better line number where possible, in some cases giving the line number of the closest statement, and other cases the line number of the inner-most scope of the error (eg the line number of the start of the function). This helps to give good (and sometimes exact) line numbers for ViperTypeError exceptions. This patch also makes sure that the first compile error (eg SyntaxError) that is encountered is reported (previously it was the last one that was reported).
* py: For viper compile errors, add traceback with function and filename.Damien George2015-07-27
| | | | | | | | | ViperTypeError now includes filename and function name where the error occurred. The line number is the line number of the start of the function definition, which is the best that can be done without a lot more work. Partially addresses issue #1381.
* 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.