2014-05-03 18:27:38 -04:00
|
|
|
/*
|
2017-06-25 22:29:20 -04:00
|
|
|
* This file is part of the MicroPython project, http://micropython.org/
|
2014-05-03 18:27:38 -04:00
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2013, 2014 Damien P. George
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
all: Unify header guard usage.
The code conventions suggest using header guards, but do not define how
those should look like and instead point to existing files. However, not
all existing files follow the same scheme, sometimes omitting header guards
altogether, sometimes using non-standard names, making it easy to
accidentally pick a "wrong" example.
This commit ensures that all header files of the MicroPython project (that
were not simply copied from somewhere else) follow the same pattern, that
was already present in the majority of files, especially in the py folder.
The rules are as follows.
Naming convention:
* start with the words MICROPY_INCLUDED
* contain the full path to the file
* replace special characters with _
In addition, there are no empty lines before #ifndef, between #ifndef and
one empty line before #endif. #endif is followed by a comment containing
the name of the guard macro.
py/grammar.h cannot use header guards by design, since it has to be
included multiple times in a single C file. Several other files also do not
need header guards as they are only used internally and guaranteed to be
included only once:
* MICROPY_MPHALPORT_H
* mpconfigboard.h
* mpconfigport.h
* mpthreadport.h
* pin_defs_*.h
* qstrdefs*.h
2017-06-29 17:14:58 -04:00
|
|
|
#ifndef MICROPY_INCLUDED_PY_MPCONFIG_H
|
|
|
|
#define MICROPY_INCLUDED_PY_MPCONFIG_H
|
2014-05-03 18:27:38 -04:00
|
|
|
|
2018-12-14 23:13:33 -05:00
|
|
|
// Current version of MicroPython
|
2019-01-25 08:44:35 -05:00
|
|
|
#define MICROPY_VERSION_MAJOR 1
|
2019-05-29 02:38:10 -04:00
|
|
|
#define MICROPY_VERSION_MINOR 11
|
2019-01-25 08:56:48 -05:00
|
|
|
#define MICROPY_VERSION_MICRO 0
|
2018-12-14 23:13:33 -05:00
|
|
|
|
|
|
|
// Combined version as a 32-bit number for convenience
|
|
|
|
#define MICROPY_VERSION ( \
|
|
|
|
MICROPY_VERSION_MAJOR << 16 \
|
|
|
|
| MICROPY_VERSION_MINOR << 8 \
|
|
|
|
| MICROPY_VERSION_MICRO)
|
|
|
|
|
|
|
|
// String version
|
|
|
|
#define MICROPY_VERSION_STRING \
|
|
|
|
MP_STRINGIFY(MICROPY_VERSION_MAJOR) "." \
|
|
|
|
MP_STRINGIFY(MICROPY_VERSION_MINOR) "." \
|
|
|
|
MP_STRINGIFY(MICROPY_VERSION_MICRO)
|
|
|
|
|
2014-01-03 10:15:53 -05:00
|
|
|
// This file contains default configuration settings for MicroPython.
|
2014-10-28 22:08:49 -04:00
|
|
|
// You can override any of the options below using mpconfigport.h file
|
|
|
|
// located in a directory of your port.
|
2014-01-03 10:15:53 -05:00
|
|
|
|
2014-10-28 22:08:49 -04:00
|
|
|
// mpconfigport.h is a file containing configuration settings for a
|
|
|
|
// particular port. mpconfigport.h is actually a default name for
|
2017-05-29 03:08:14 -04:00
|
|
|
// such config, and it can be overridden using MP_CONFIGFILE preprocessor
|
2014-10-28 22:08:49 -04:00
|
|
|
// define (you can do that by passing CFLAGS_EXTRA='-DMP_CONFIGFILE="<file.h>"'
|
|
|
|
// argument to make when using standard MicroPython makefiles).
|
|
|
|
// This is useful to have more than one config per port, for example,
|
|
|
|
// release vs debug configs, etc. Note that if you switch from one config
|
|
|
|
// to another, you must rebuild from scratch using "-B" switch to make.
|
|
|
|
|
|
|
|
#ifdef MP_CONFIGFILE
|
|
|
|
#include MP_CONFIGFILE
|
|
|
|
#else
|
2014-06-12 14:50:17 -04:00
|
|
|
#include <mpconfigport.h>
|
2014-10-28 22:08:49 -04:00
|
|
|
#endif
|
2014-01-03 10:15:53 -05:00
|
|
|
|
2014-01-07 09:54:15 -05:00
|
|
|
// Any options not explicitly set in mpconfigport.h will get default
|
|
|
|
// values below.
|
|
|
|
|
2015-03-29 09:05:46 -04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Object representation */
|
|
|
|
|
2017-06-25 22:29:20 -04:00
|
|
|
// A MicroPython object is a machine word having the following form:
|
2015-03-29 09:05:46 -04:00
|
|
|
// - xxxx...xxx1 : a small int, bits 1 and above are the value
|
|
|
|
// - xxxx...xx10 : a qstr, bits 2 and above are the value
|
|
|
|
// - xxxx...xx00 : a pointer to an mp_obj_base_t (unless a fake object)
|
|
|
|
#define MICROPY_OBJ_REPR_A (0)
|
|
|
|
|
2017-06-25 22:29:20 -04:00
|
|
|
// A MicroPython object is a machine word having the following form:
|
2015-03-29 09:05:46 -04:00
|
|
|
// - xxxx...xx01 : a small int, bits 2 and above are the value
|
|
|
|
// - xxxx...xx11 : a qstr, bits 2 and above are the value
|
|
|
|
// - xxxx...xxx0 : a pointer to an mp_obj_base_t (unless a fake object)
|
|
|
|
#define MICROPY_OBJ_REPR_B (1)
|
|
|
|
|
2015-11-06 18:25:10 -05:00
|
|
|
// A MicroPython object is a machine word having the following form (called R):
|
2015-10-17 18:20:57 -04:00
|
|
|
// - iiiiiiii iiiiiiii iiiiiiii iiiiiii1 small int with 31-bit signed value
|
2015-11-06 18:25:10 -05:00
|
|
|
// - 01111111 1qqqqqqq qqqqqqqq qqqqq110 str with 20-bit qstr value
|
2015-10-17 18:20:57 -04:00
|
|
|
// - s1111111 10000000 00000000 00000010 +/- inf
|
|
|
|
// - s1111111 1xxxxxxx xxxxxxxx xxxxx010 nan, x != 0
|
|
|
|
// - seeeeeee efffffff ffffffff ffffff10 30-bit fp, e != 0xff
|
|
|
|
// - pppppppp pppppppp pppppppp pppppp00 ptr (4 byte alignment)
|
2015-11-06 18:25:10 -05:00
|
|
|
// Str and float stored as O = R + 0x80800000, retrieved as R = O - 0x80800000.
|
|
|
|
// This makes strs easier to encode/decode as they have zeros in the top 9 bits.
|
2015-10-17 18:20:57 -04:00
|
|
|
// This scheme only works with 32-bit word size and float enabled.
|
|
|
|
#define MICROPY_OBJ_REPR_C (2)
|
|
|
|
|
2015-11-27 12:09:11 -05:00
|
|
|
// A MicroPython object is a 64-bit word having the following form (called R):
|
|
|
|
// - seeeeeee eeeeffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff 64-bit fp, e != 0x7ff
|
|
|
|
// - s1111111 11110000 00000000 00000000 00000000 00000000 00000000 00000000 +/- inf
|
|
|
|
// - 01111111 11111000 00000000 00000000 00000000 00000000 00000000 00000000 normalised nan
|
2017-12-11 06:39:12 -05:00
|
|
|
// - 01111111 11111101 iiiiiiii iiiiiiii iiiiiiii iiiiiiii iiiiiiii iiiiiii1 small int
|
2015-11-27 12:09:11 -05:00
|
|
|
// - 01111111 11111110 00000000 00000000 qqqqqqqq qqqqqqqq qqqqqqqq qqqqqqq1 str
|
|
|
|
// - 01111111 11111100 00000000 00000000 pppppppp pppppppp pppppppp pppppp00 ptr (4 byte alignment)
|
|
|
|
// Stored as O = R + 0x8004000000000000, retrieved as R = O - 0x8004000000000000.
|
|
|
|
// This makes pointers have all zeros in the top 32 bits.
|
|
|
|
// Small-ints and strs have 1 as LSB to make sure they don't look like pointers
|
|
|
|
// to the garbage collector.
|
|
|
|
#define MICROPY_OBJ_REPR_D (3)
|
|
|
|
|
2015-03-29 09:05:46 -04:00
|
|
|
#ifndef MICROPY_OBJ_REPR
|
|
|
|
#define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_A)
|
|
|
|
#endif
|
|
|
|
|
py: Turn down amount of RAM parser and compiler use.
There are 2 locations in parser, and 1 in compiler, where memory
allocation is not precise. In the parser it's the rule stack and result
stack, in the compiler it's the array for the identifiers in the current
scope. All other mallocs are exact (ie they don't allocate more than is
needed).
This patch adds tuning options (MP_ALLOC_*) to mpconfig.h for these 3
inexact allocations.
The inexact allocations in the parser should actually be close to
logarithmic: you need an exponentially larger script (absent pathological
cases) to use up more room on the rule and result stacks. As such, the
default allocation policy for these is now to start with a modest sized
stack, but grow only in small increments.
For the identifier arrays in the compiler, these now start out quite
small (4 entries, since most functions don't have that many ids), and
grow incrementally by 6 (since if you have more ids than 4, you probably
have quite a few more, but it wouldn't be exponentially more).
Partially addresses issue #560.
2014-05-05 08:19:03 -04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Memory allocation policy */
|
|
|
|
|
2015-12-02 18:40:52 -05:00
|
|
|
// Number of bytes in memory allocation/GC block. Any size allocated will be
|
|
|
|
// rounded up to be multiples of this.
|
2015-12-02 18:57:50 -05:00
|
|
|
#ifndef MICROPY_BYTES_PER_GC_BLOCK
|
2015-12-02 18:40:52 -05:00
|
|
|
#define MICROPY_BYTES_PER_GC_BLOCK (4 * BYTES_PER_WORD)
|
2015-12-02 18:57:50 -05:00
|
|
|
#endif
|
2015-12-02 18:40:52 -05:00
|
|
|
|
2015-01-01 17:04:46 -05:00
|
|
|
// Number of words allocated (in BSS) to the GC stack (minimum is 1)
|
|
|
|
#ifndef MICROPY_ALLOC_GC_STACK_SIZE
|
|
|
|
#define MICROPY_ALLOC_GC_STACK_SIZE (64)
|
|
|
|
#endif
|
|
|
|
|
2018-02-23 12:59:31 -05:00
|
|
|
// The C-type to use for entries in the GC stack. By default it allows the
|
|
|
|
// heap to be as large as the address space, but the bit-width of this type can
|
|
|
|
// be reduced to save memory when the heap is small enough. The type must be
|
|
|
|
// big enough to index all blocks in the heap, which is set by
|
|
|
|
// heap-size-in-bytes / MICROPY_BYTES_PER_GC_BLOCK.
|
|
|
|
#ifndef MICROPY_GC_STACK_ENTRY_TYPE
|
|
|
|
#define MICROPY_GC_STACK_ENTRY_TYPE size_t
|
|
|
|
#endif
|
|
|
|
|
2016-08-26 01:35:26 -04:00
|
|
|
// Be conservative and always clear to zero newly (re)allocated memory in the GC.
|
|
|
|
// This helps eliminate stray pointers that hold on to memory that's no longer
|
|
|
|
// used. It decreases performance due to unnecessary memory clearing.
|
2016-10-31 10:52:11 -04:00
|
|
|
// A memory manager which always clears memory can set this to 0.
|
2016-08-26 01:35:26 -04:00
|
|
|
// TODO Do analysis to understand why some memory is not properly cleared and
|
|
|
|
// find a more efficient way to clear it.
|
|
|
|
#ifndef MICROPY_GC_CONSERVATIVE_CLEAR
|
2016-10-31 10:52:11 -04:00
|
|
|
#define MICROPY_GC_CONSERVATIVE_CLEAR (MICROPY_ENABLE_GC)
|
2016-08-26 01:35:26 -04:00
|
|
|
#endif
|
|
|
|
|
py/gc: Implement GC running by allocation threshold.
Currently, MicroPython runs GC when it could not allocate a block of memory,
which happens when heap is exhausted. However, that policy can't work well
with "inifinity" heaps, e.g. backed by a virtual memory - there will be a
lot of swap thrashing long before VM will be exhausted. Instead, in such
cases "allocation threshold" policy is used: a GC is run after some number of
allocations have been made. Details vary, for example, number or total amount
of allocations can be used, threshold may be self-adjusting based on GC
outcome, etc.
This change implements a simple variant of such policy for MicroPython. Amount
of allocated memory so far is used for threshold, to make it useful to typical
finite-size, and small, heaps as used with MicroPython ports. And such GC policy
is indeed useful for such types of heaps too, as it allows to better control
fragmentation. For example, if a threshold is set to half size of heap, then
for an application which usually makes big number of small allocations, that
will (try to) keep half of heap memory in a nice defragmented state for an
occasional large allocation.
For an application which doesn't exhibit such behavior, there won't be any
visible effects, except for GC running more frequently, which however may
affect performance. To address this, the GC threshold is configurable, and
by default is off so far. It's configured with gc.threshold(amount_in_bytes)
call (can be queries without an argument).
2016-07-20 17:37:30 -04:00
|
|
|
// Support automatic GC when reaching allocation threshold,
|
|
|
|
// configurable by gc.threshold().
|
|
|
|
#ifndef MICROPY_GC_ALLOC_THRESHOLD
|
|
|
|
#define MICROPY_GC_ALLOC_THRESHOLD (1)
|
|
|
|
#endif
|
|
|
|
|
2015-06-13 16:53:22 -04:00
|
|
|
// Number of bytes to allocate initially when creating new chunks to store
|
|
|
|
// interned string data. Smaller numbers lead to more chunks being needed
|
|
|
|
// and more wastage at the end of the chunk. Larger numbers lead to wasted
|
|
|
|
// space at the end when no more strings need interning.
|
|
|
|
#ifndef MICROPY_ALLOC_QSTR_CHUNK_INIT
|
|
|
|
#define MICROPY_ALLOC_QSTR_CHUNK_INIT (128)
|
|
|
|
#endif
|
|
|
|
|
2014-05-10 12:48:01 -04:00
|
|
|
// Initial amount for lexer indentation level
|
2014-05-21 15:32:59 -04:00
|
|
|
#ifndef MICROPY_ALLOC_LEXER_INDENT_INIT
|
|
|
|
#define MICROPY_ALLOC_LEXER_INDENT_INIT (10)
|
2014-05-10 12:48:01 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Increment for lexer indentation level
|
2014-05-21 15:32:59 -04:00
|
|
|
#ifndef MICROPY_ALLOC_LEXEL_INDENT_INC
|
|
|
|
#define MICROPY_ALLOC_LEXEL_INDENT_INC (8)
|
2014-05-10 12:48:01 -04:00
|
|
|
#endif
|
|
|
|
|
py: Turn down amount of RAM parser and compiler use.
There are 2 locations in parser, and 1 in compiler, where memory
allocation is not precise. In the parser it's the rule stack and result
stack, in the compiler it's the array for the identifiers in the current
scope. All other mallocs are exact (ie they don't allocate more than is
needed).
This patch adds tuning options (MP_ALLOC_*) to mpconfig.h for these 3
inexact allocations.
The inexact allocations in the parser should actually be close to
logarithmic: you need an exponentially larger script (absent pathological
cases) to use up more room on the rule and result stacks. As such, the
default allocation policy for these is now to start with a modest sized
stack, but grow only in small increments.
For the identifier arrays in the compiler, these now start out quite
small (4 entries, since most functions don't have that many ids), and
grow incrementally by 6 (since if you have more ids than 4, you probably
have quite a few more, but it wouldn't be exponentially more).
Partially addresses issue #560.
2014-05-05 08:19:03 -04:00
|
|
|
// Initial amount for parse rule stack
|
2014-05-21 15:32:59 -04:00
|
|
|
#ifndef MICROPY_ALLOC_PARSE_RULE_INIT
|
|
|
|
#define MICROPY_ALLOC_PARSE_RULE_INIT (64)
|
py: Turn down amount of RAM parser and compiler use.
There are 2 locations in parser, and 1 in compiler, where memory
allocation is not precise. In the parser it's the rule stack and result
stack, in the compiler it's the array for the identifiers in the current
scope. All other mallocs are exact (ie they don't allocate more than is
needed).
This patch adds tuning options (MP_ALLOC_*) to mpconfig.h for these 3
inexact allocations.
The inexact allocations in the parser should actually be close to
logarithmic: you need an exponentially larger script (absent pathological
cases) to use up more room on the rule and result stacks. As such, the
default allocation policy for these is now to start with a modest sized
stack, but grow only in small increments.
For the identifier arrays in the compiler, these now start out quite
small (4 entries, since most functions don't have that many ids), and
grow incrementally by 6 (since if you have more ids than 4, you probably
have quite a few more, but it wouldn't be exponentially more).
Partially addresses issue #560.
2014-05-05 08:19:03 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Increment for parse rule stack
|
2014-05-21 15:32:59 -04:00
|
|
|
#ifndef MICROPY_ALLOC_PARSE_RULE_INC
|
|
|
|
#define MICROPY_ALLOC_PARSE_RULE_INC (16)
|
py: Turn down amount of RAM parser and compiler use.
There are 2 locations in parser, and 1 in compiler, where memory
allocation is not precise. In the parser it's the rule stack and result
stack, in the compiler it's the array for the identifiers in the current
scope. All other mallocs are exact (ie they don't allocate more than is
needed).
This patch adds tuning options (MP_ALLOC_*) to mpconfig.h for these 3
inexact allocations.
The inexact allocations in the parser should actually be close to
logarithmic: you need an exponentially larger script (absent pathological
cases) to use up more room on the rule and result stacks. As such, the
default allocation policy for these is now to start with a modest sized
stack, but grow only in small increments.
For the identifier arrays in the compiler, these now start out quite
small (4 entries, since most functions don't have that many ids), and
grow incrementally by 6 (since if you have more ids than 4, you probably
have quite a few more, but it wouldn't be exponentially more).
Partially addresses issue #560.
2014-05-05 08:19:03 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Initial amount for parse result stack
|
2014-05-21 15:32:59 -04:00
|
|
|
#ifndef MICROPY_ALLOC_PARSE_RESULT_INIT
|
|
|
|
#define MICROPY_ALLOC_PARSE_RESULT_INIT (32)
|
py: Turn down amount of RAM parser and compiler use.
There are 2 locations in parser, and 1 in compiler, where memory
allocation is not precise. In the parser it's the rule stack and result
stack, in the compiler it's the array for the identifiers in the current
scope. All other mallocs are exact (ie they don't allocate more than is
needed).
This patch adds tuning options (MP_ALLOC_*) to mpconfig.h for these 3
inexact allocations.
The inexact allocations in the parser should actually be close to
logarithmic: you need an exponentially larger script (absent pathological
cases) to use up more room on the rule and result stacks. As such, the
default allocation policy for these is now to start with a modest sized
stack, but grow only in small increments.
For the identifier arrays in the compiler, these now start out quite
small (4 entries, since most functions don't have that many ids), and
grow incrementally by 6 (since if you have more ids than 4, you probably
have quite a few more, but it wouldn't be exponentially more).
Partially addresses issue #560.
2014-05-05 08:19:03 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Increment for parse result stack
|
2014-05-21 15:32:59 -04:00
|
|
|
#ifndef MICROPY_ALLOC_PARSE_RESULT_INC
|
|
|
|
#define MICROPY_ALLOC_PARSE_RESULT_INC (16)
|
py: Turn down amount of RAM parser and compiler use.
There are 2 locations in parser, and 1 in compiler, where memory
allocation is not precise. In the parser it's the rule stack and result
stack, in the compiler it's the array for the identifiers in the current
scope. All other mallocs are exact (ie they don't allocate more than is
needed).
This patch adds tuning options (MP_ALLOC_*) to mpconfig.h for these 3
inexact allocations.
The inexact allocations in the parser should actually be close to
logarithmic: you need an exponentially larger script (absent pathological
cases) to use up more room on the rule and result stacks. As such, the
default allocation policy for these is now to start with a modest sized
stack, but grow only in small increments.
For the identifier arrays in the compiler, these now start out quite
small (4 entries, since most functions don't have that many ids), and
grow incrementally by 6 (since if you have more ids than 4, you probably
have quite a few more, but it wouldn't be exponentially more).
Partially addresses issue #560.
2014-05-05 08:19:03 -04:00
|
|
|
#endif
|
|
|
|
|
2014-05-25 17:06:06 -04:00
|
|
|
// Strings this length or less will be interned by the parser
|
|
|
|
#ifndef MICROPY_ALLOC_PARSE_INTERN_STRING_LEN
|
|
|
|
#define MICROPY_ALLOC_PARSE_INTERN_STRING_LEN (10)
|
|
|
|
#endif
|
|
|
|
|
2015-09-23 05:50:43 -04:00
|
|
|
// Number of bytes to allocate initially when creating new chunks to store
|
|
|
|
// parse nodes. Small leads to fragmentation, large leads to excess use.
|
|
|
|
#ifndef MICROPY_ALLOC_PARSE_CHUNK_INIT
|
|
|
|
#define MICROPY_ALLOC_PARSE_CHUNK_INIT (128)
|
|
|
|
#endif
|
|
|
|
|
py: Turn down amount of RAM parser and compiler use.
There are 2 locations in parser, and 1 in compiler, where memory
allocation is not precise. In the parser it's the rule stack and result
stack, in the compiler it's the array for the identifiers in the current
scope. All other mallocs are exact (ie they don't allocate more than is
needed).
This patch adds tuning options (MP_ALLOC_*) to mpconfig.h for these 3
inexact allocations.
The inexact allocations in the parser should actually be close to
logarithmic: you need an exponentially larger script (absent pathological
cases) to use up more room on the rule and result stacks. As such, the
default allocation policy for these is now to start with a modest sized
stack, but grow only in small increments.
For the identifier arrays in the compiler, these now start out quite
small (4 entries, since most functions don't have that many ids), and
grow incrementally by 6 (since if you have more ids than 4, you probably
have quite a few more, but it wouldn't be exponentially more).
Partially addresses issue #560.
2014-05-05 08:19:03 -04:00
|
|
|
// Initial amount for ids in a scope
|
2014-05-21 15:32:59 -04:00
|
|
|
#ifndef MICROPY_ALLOC_SCOPE_ID_INIT
|
|
|
|
#define MICROPY_ALLOC_SCOPE_ID_INIT (4)
|
py: Turn down amount of RAM parser and compiler use.
There are 2 locations in parser, and 1 in compiler, where memory
allocation is not precise. In the parser it's the rule stack and result
stack, in the compiler it's the array for the identifiers in the current
scope. All other mallocs are exact (ie they don't allocate more than is
needed).
This patch adds tuning options (MP_ALLOC_*) to mpconfig.h for these 3
inexact allocations.
The inexact allocations in the parser should actually be close to
logarithmic: you need an exponentially larger script (absent pathological
cases) to use up more room on the rule and result stacks. As such, the
default allocation policy for these is now to start with a modest sized
stack, but grow only in small increments.
For the identifier arrays in the compiler, these now start out quite
small (4 entries, since most functions don't have that many ids), and
grow incrementally by 6 (since if you have more ids than 4, you probably
have quite a few more, but it wouldn't be exponentially more).
Partially addresses issue #560.
2014-05-05 08:19:03 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Increment for ids in a scope
|
2014-05-21 15:32:59 -04:00
|
|
|
#ifndef MICROPY_ALLOC_SCOPE_ID_INC
|
|
|
|
#define MICROPY_ALLOC_SCOPE_ID_INC (6)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Maximum length of a path in the filesystem
|
|
|
|
// So we can allocate a buffer on the stack for path manipulation in import
|
|
|
|
#ifndef MICROPY_ALLOC_PATH_MAX
|
|
|
|
#define MICROPY_ALLOC_PATH_MAX (512)
|
py: Turn down amount of RAM parser and compiler use.
There are 2 locations in parser, and 1 in compiler, where memory
allocation is not precise. In the parser it's the rule stack and result
stack, in the compiler it's the array for the identifiers in the current
scope. All other mallocs are exact (ie they don't allocate more than is
needed).
This patch adds tuning options (MP_ALLOC_*) to mpconfig.h for these 3
inexact allocations.
The inexact allocations in the parser should actually be close to
logarithmic: you need an exponentially larger script (absent pathological
cases) to use up more room on the rule and result stacks. As such, the
default allocation policy for these is now to start with a modest sized
stack, but grow only in small increments.
For the identifier arrays in the compiler, these now start out quite
small (4 entries, since most functions don't have that many ids), and
grow incrementally by 6 (since if you have more ids than 4, you probably
have quite a few more, but it wouldn't be exponentially more).
Partially addresses issue #560.
2014-05-05 08:19:03 -04:00
|
|
|
#endif
|
|
|
|
|
2014-11-04 17:27:15 -05:00
|
|
|
// Initial size of module dict
|
|
|
|
#ifndef MICROPY_MODULE_DICT_SIZE
|
|
|
|
#define MICROPY_MODULE_DICT_SIZE (1)
|
|
|
|
#endif
|
|
|
|
|
2015-02-27 04:54:12 -05:00
|
|
|
// Whether realloc/free should be passed allocated memory region size
|
|
|
|
// You must enable this if MICROPY_MEM_STATS is enabled
|
|
|
|
#ifndef MICROPY_MALLOC_USES_ALLOCATED_SIZE
|
|
|
|
#define MICROPY_MALLOC_USES_ALLOCATED_SIZE (0)
|
|
|
|
#endif
|
|
|
|
|
2015-01-11 17:27:30 -05:00
|
|
|
// Number of bytes used to store qstr length
|
|
|
|
// Dictates hard limit on maximum Python identifier length, but 1 byte
|
|
|
|
// (limit of 255 bytes in an identifier) should be enough for everyone
|
|
|
|
#ifndef MICROPY_QSTR_BYTES_IN_LEN
|
|
|
|
#define MICROPY_QSTR_BYTES_IN_LEN (1)
|
|
|
|
#endif
|
|
|
|
|
2015-07-20 07:03:13 -04:00
|
|
|
// Number of bytes used to store qstr hash
|
|
|
|
#ifndef MICROPY_QSTR_BYTES_IN_HASH
|
|
|
|
#define MICROPY_QSTR_BYTES_IN_HASH (2)
|
|
|
|
#endif
|
|
|
|
|
2015-03-27 19:14:45 -04:00
|
|
|
// Avoid using C stack when making Python function calls. C stack still
|
|
|
|
// may be used if there's no free heap.
|
2015-03-27 19:14:44 -04:00
|
|
|
#ifndef MICROPY_STACKLESS
|
|
|
|
#define MICROPY_STACKLESS (0)
|
|
|
|
#endif
|
|
|
|
|
2015-03-27 19:14:45 -04:00
|
|
|
// Never use C stack when making Python function calls. This may break
|
|
|
|
// testsuite as will subtly change which exception is thrown in case
|
|
|
|
// of too deep recursion and other similar cases.
|
|
|
|
#ifndef MICROPY_STACKLESS_STRICT
|
|
|
|
#define MICROPY_STACKLESS_STRICT (0)
|
|
|
|
#endif
|
|
|
|
|
2015-11-25 16:22:31 -05:00
|
|
|
// Don't use alloca calls. As alloca() is not part of ANSI C, this
|
|
|
|
// workaround option is provided for compilers lacking this de-facto
|
|
|
|
// standard function. The way it works is allocating from heap, and
|
|
|
|
// relying on garbage collection to free it eventually. This is of
|
|
|
|
// course much less optimal than real alloca().
|
|
|
|
#if defined(MICROPY_NO_ALLOCA) && MICROPY_NO_ALLOCA
|
|
|
|
#undef alloca
|
|
|
|
#define alloca(x) m_malloc(x)
|
|
|
|
#endif
|
|
|
|
|
2014-01-07 09:54:15 -05:00
|
|
|
/*****************************************************************************/
|
2017-06-25 22:29:20 -04:00
|
|
|
/* MicroPython emitters */
|
2014-01-07 09:54:15 -05:00
|
|
|
|
2015-11-02 16:55:42 -05:00
|
|
|
// Whether to support loading of persistent code
|
|
|
|
#ifndef MICROPY_PERSISTENT_CODE_LOAD
|
|
|
|
#define MICROPY_PERSISTENT_CODE_LOAD (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Whether to support saving of persistent code
|
|
|
|
#ifndef MICROPY_PERSISTENT_CODE_SAVE
|
|
|
|
#define MICROPY_PERSISTENT_CODE_SAVE (0)
|
|
|
|
#endif
|
|
|
|
|
2015-11-02 12:27:18 -05:00
|
|
|
// Whether generated code can persist independently of the VM/runtime instance
|
2015-11-02 16:55:42 -05:00
|
|
|
// This is enabled automatically when needed by other features
|
2015-11-02 12:27:18 -05:00
|
|
|
#ifndef MICROPY_PERSISTENT_CODE
|
2016-01-31 17:24:16 -05:00
|
|
|
#define MICROPY_PERSISTENT_CODE (MICROPY_PERSISTENT_CODE_LOAD || MICROPY_PERSISTENT_CODE_SAVE || MICROPY_MODULE_FROZEN_MPY)
|
2015-11-02 12:27:18 -05:00
|
|
|
#endif
|
|
|
|
|
2014-01-07 09:54:15 -05:00
|
|
|
// Whether to emit x64 native code
|
|
|
|
#ifndef MICROPY_EMIT_X64
|
|
|
|
#define MICROPY_EMIT_X64 (0)
|
2014-01-03 18:57:00 -05:00
|
|
|
#endif
|
|
|
|
|
2014-09-06 18:06:36 -04:00
|
|
|
// Whether to emit x86 native code
|
|
|
|
#ifndef MICROPY_EMIT_X86
|
|
|
|
#define MICROPY_EMIT_X86 (0)
|
|
|
|
#endif
|
|
|
|
|
2014-01-07 09:54:15 -05:00
|
|
|
// Whether to emit thumb native code
|
|
|
|
#ifndef MICROPY_EMIT_THUMB
|
|
|
|
#define MICROPY_EMIT_THUMB (0)
|
|
|
|
#endif
|
2014-01-03 18:57:00 -05:00
|
|
|
|
2014-01-07 09:54:15 -05:00
|
|
|
// Whether to enable the thumb inline assembler
|
|
|
|
#ifndef MICROPY_EMIT_INLINE_THUMB
|
|
|
|
#define MICROPY_EMIT_INLINE_THUMB (0)
|
|
|
|
#endif
|
|
|
|
|
2015-10-16 17:08:57 -04:00
|
|
|
// Whether to enable ARMv7-M instruction support in the Thumb2 inline assembler
|
|
|
|
#ifndef MICROPY_EMIT_INLINE_THUMB_ARMV7M
|
|
|
|
#define MICROPY_EMIT_INLINE_THUMB_ARMV7M (1)
|
|
|
|
#endif
|
|
|
|
|
2015-04-14 08:14:57 -04:00
|
|
|
// Whether to enable float support in the Thumb2 inline assembler
|
|
|
|
#ifndef MICROPY_EMIT_INLINE_THUMB_FLOAT
|
|
|
|
#define MICROPY_EMIT_INLINE_THUMB_FLOAT (1)
|
|
|
|
#endif
|
|
|
|
|
2014-08-16 16:55:53 -04:00
|
|
|
// Whether to emit ARM native code
|
|
|
|
#ifndef MICROPY_EMIT_ARM
|
|
|
|
#define MICROPY_EMIT_ARM (0)
|
|
|
|
#endif
|
|
|
|
|
2016-12-09 00:39:39 -05:00
|
|
|
// Whether to emit Xtensa native code
|
|
|
|
#ifndef MICROPY_EMIT_XTENSA
|
|
|
|
#define MICROPY_EMIT_XTENSA (0)
|
|
|
|
#endif
|
|
|
|
|
py: Add inline Xtensa assembler.
This patch adds the MICROPY_EMIT_INLINE_XTENSA option, which, when
enabled, allows the @micropython.asm_xtensa decorator to be used.
The following opcodes are currently supported (ax is a register, a0-a15):
ret_n()
callx0(ax)
j(label)
jx(ax)
beqz(ax, label)
bnez(ax, label)
mov(ax, ay)
movi(ax, imm) # imm can be full 32-bit, uses l32r if needed
and_(ax, ay, az)
or_(ax, ay, az)
xor(ax, ay, az)
add(ax, ay, az)
sub(ax, ay, az)
mull(ax, ay, az)
l8ui(ax, ay, imm)
l16ui(ax, ay, imm)
l32i(ax, ay, imm)
s8i(ax, ay, imm)
s16i(ax, ay, imm)
s32i(ax, ay, imm)
l16si(ax, ay, imm)
addi(ax, ay, imm)
ball(ax, ay, label)
bany(ax, ay, label)
bbc(ax, ay, label)
bbs(ax, ay, label)
beq(ax, ay, label)
bge(ax, ay, label)
bgeu(ax, ay, label)
blt(ax, ay, label)
bnall(ax, ay, label)
bne(ax, ay, label)
bnone(ax, ay, label)
Upon entry to the assembly function the registers a0, a12, a13, a14 are
pushed to the stack and the stack pointer (a1) decreased by 16. Upon
exit, these registers and the stack pointer are restored, and ret.n is
executed to return to the caller (caller address is in a0).
Note that the ABI for the Xtensa emitters is non-windowing.
2016-12-09 01:03:33 -05:00
|
|
|
// Whether to enable the Xtensa inline assembler
|
|
|
|
#ifndef MICROPY_EMIT_INLINE_XTENSA
|
|
|
|
#define MICROPY_EMIT_INLINE_XTENSA (0)
|
|
|
|
#endif
|
|
|
|
|
2014-08-15 11:45:41 -04:00
|
|
|
// Convenience definition for whether any native emitter is enabled
|
2016-12-09 00:39:39 -05:00
|
|
|
#define MICROPY_EMIT_NATIVE (MICROPY_EMIT_X64 || MICROPY_EMIT_X86 || MICROPY_EMIT_THUMB || MICROPY_EMIT_ARM || MICROPY_EMIT_XTENSA)
|
2014-08-15 11:45:41 -04:00
|
|
|
|
2016-12-08 21:17:49 -05:00
|
|
|
// Convenience definition for whether any inline assembler emitter is enabled
|
py: Add inline Xtensa assembler.
This patch adds the MICROPY_EMIT_INLINE_XTENSA option, which, when
enabled, allows the @micropython.asm_xtensa decorator to be used.
The following opcodes are currently supported (ax is a register, a0-a15):
ret_n()
callx0(ax)
j(label)
jx(ax)
beqz(ax, label)
bnez(ax, label)
mov(ax, ay)
movi(ax, imm) # imm can be full 32-bit, uses l32r if needed
and_(ax, ay, az)
or_(ax, ay, az)
xor(ax, ay, az)
add(ax, ay, az)
sub(ax, ay, az)
mull(ax, ay, az)
l8ui(ax, ay, imm)
l16ui(ax, ay, imm)
l32i(ax, ay, imm)
s8i(ax, ay, imm)
s16i(ax, ay, imm)
s32i(ax, ay, imm)
l16si(ax, ay, imm)
addi(ax, ay, imm)
ball(ax, ay, label)
bany(ax, ay, label)
bbc(ax, ay, label)
bbs(ax, ay, label)
beq(ax, ay, label)
bge(ax, ay, label)
bgeu(ax, ay, label)
blt(ax, ay, label)
bnall(ax, ay, label)
bne(ax, ay, label)
bnone(ax, ay, label)
Upon entry to the assembly function the registers a0, a12, a13, a14 are
pushed to the stack and the stack pointer (a1) decreased by 16. Upon
exit, these registers and the stack pointer are restored, and ret.n is
executed to return to the caller (caller address is in a0).
Note that the ABI for the Xtensa emitters is non-windowing.
2016-12-09 01:03:33 -05:00
|
|
|
#define MICROPY_EMIT_INLINE_ASM (MICROPY_EMIT_INLINE_THUMB || MICROPY_EMIT_INLINE_XTENSA)
|
2016-12-08 21:17:49 -05:00
|
|
|
|
2019-05-06 03:31:11 -04:00
|
|
|
// Convenience definition for whether any native or inline assembler emitter is enabled
|
|
|
|
#define MICROPY_EMIT_MACHINE_CODE (MICROPY_EMIT_NATIVE || MICROPY_EMIT_INLINE_ASM)
|
|
|
|
|
2014-05-21 15:32:59 -04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Compiler configuration */
|
|
|
|
|
2015-12-18 07:35:44 -05:00
|
|
|
// Whether to include the compiler
|
|
|
|
#ifndef MICROPY_ENABLE_COMPILER
|
|
|
|
#define MICROPY_ENABLE_COMPILER (1)
|
|
|
|
#endif
|
|
|
|
|
2016-02-11 17:30:53 -05:00
|
|
|
// Whether the compiler is dynamically configurable (ie at runtime)
|
2019-05-29 07:17:29 -04:00
|
|
|
// This will disable the ability to execute native/viper code
|
2016-02-11 17:30:53 -05:00
|
|
|
#ifndef MICROPY_DYNAMIC_COMPILER
|
|
|
|
#define MICROPY_DYNAMIC_COMPILER (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Configure dynamic compiler macros
|
|
|
|
#if MICROPY_DYNAMIC_COMPILER
|
|
|
|
#define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE_DYNAMIC (mp_dynamic_compiler.opt_cache_map_lookup_in_bytecode)
|
|
|
|
#define MICROPY_PY_BUILTINS_STR_UNICODE_DYNAMIC (mp_dynamic_compiler.py_builtins_str_unicode)
|
|
|
|
#else
|
|
|
|
#define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE_DYNAMIC MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE
|
|
|
|
#define MICROPY_PY_BUILTINS_STR_UNICODE_DYNAMIC MICROPY_PY_BUILTINS_STR_UNICODE
|
|
|
|
#endif
|
|
|
|
|
2015-10-08 09:58:15 -04:00
|
|
|
// Whether to enable constant folding; eg 1+2 rewritten as 3
|
|
|
|
#ifndef MICROPY_COMP_CONST_FOLDING
|
|
|
|
#define MICROPY_COMP_CONST_FOLDING (1)
|
|
|
|
#endif
|
|
|
|
|
2019-02-26 08:10:04 -05:00
|
|
|
// Whether to enable optimisations for constant literals, eg OrderedDict
|
|
|
|
#ifndef MICROPY_COMP_CONST_LITERAL
|
|
|
|
#define MICROPY_COMP_CONST_LITERAL (1)
|
|
|
|
#endif
|
|
|
|
|
2015-01-10 09:07:24 -05:00
|
|
|
// Whether to enable lookup of constants in modules; eg module.CONST
|
|
|
|
#ifndef MICROPY_COMP_MODULE_CONST
|
|
|
|
#define MICROPY_COMP_MODULE_CONST (0)
|
|
|
|
#endif
|
|
|
|
|
2014-05-21 15:32:59 -04:00
|
|
|
// Whether to enable constant optimisation; id = const(value)
|
|
|
|
#ifndef MICROPY_COMP_CONST
|
|
|
|
#define MICROPY_COMP_CONST (1)
|
|
|
|
#endif
|
|
|
|
|
2015-03-14 09:11:35 -04:00
|
|
|
// Whether to enable optimisation of: a, b = c, d
|
|
|
|
// Costs 124 bytes (Thumb2)
|
|
|
|
#ifndef MICROPY_COMP_DOUBLE_TUPLE_ASSIGN
|
|
|
|
#define MICROPY_COMP_DOUBLE_TUPLE_ASSIGN (1)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Whether to enable optimisation of: a, b, c = d, e, f
|
2018-02-03 21:35:21 -05:00
|
|
|
// Requires MICROPY_COMP_DOUBLE_TUPLE_ASSIGN and costs 68 bytes (Thumb2)
|
2015-03-14 09:11:35 -04:00
|
|
|
#ifndef MICROPY_COMP_TRIPLE_TUPLE_ASSIGN
|
|
|
|
#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (0)
|
|
|
|
#endif
|
|
|
|
|
2017-04-22 00:58:01 -04:00
|
|
|
// Whether to enable optimisation of: return a if b else c
|
|
|
|
// Costs about 80 bytes (Thumb2) and saves 2 bytes of bytecode for each use
|
|
|
|
#ifndef MICROPY_COMP_RETURN_IF_EXPR
|
|
|
|
#define MICROPY_COMP_RETURN_IF_EXPR (0)
|
|
|
|
#endif
|
|
|
|
|
2014-01-07 09:54:15 -05:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Internal debugging stuff */
|
2014-01-03 10:15:53 -05:00
|
|
|
|
|
|
|
// Whether to collect memory allocation stats
|
|
|
|
#ifndef MICROPY_MEM_STATS
|
2014-01-07 09:54:15 -05:00
|
|
|
#define MICROPY_MEM_STATS (0)
|
|
|
|
#endif
|
|
|
|
|
2018-08-02 00:04:44 -04:00
|
|
|
// The mp_print_t printer used for debugging output
|
|
|
|
#ifndef MICROPY_DEBUG_PRINTER
|
|
|
|
#define MICROPY_DEBUG_PRINTER (&mp_plat_print)
|
|
|
|
#endif
|
|
|
|
|
2014-01-19 06:48:48 -05:00
|
|
|
// Whether to build functions that print debugging info:
|
2014-05-10 05:36:38 -04:00
|
|
|
// mp_bytecode_print
|
2014-01-19 06:48:48 -05:00
|
|
|
// mp_parse_node_print
|
|
|
|
#ifndef MICROPY_DEBUG_PRINTERS
|
|
|
|
#define MICROPY_DEBUG_PRINTERS (0)
|
2014-01-07 10:20:33 -05:00
|
|
|
#endif
|
|
|
|
|
2017-07-24 12:55:14 -04:00
|
|
|
// Whether to enable all debugging outputs (it will be extremely verbose)
|
|
|
|
#ifndef MICROPY_DEBUG_VERBOSE
|
|
|
|
#define MICROPY_DEBUG_VERBOSE (0)
|
|
|
|
#endif
|
|
|
|
|
2019-03-07 23:48:20 -05:00
|
|
|
// Whether to enable debugging versions of MP_OBJ_NULL/STOP_ITERATION/SENTINEL
|
|
|
|
#ifndef MICROPY_DEBUG_MP_OBJ_SENTINELS
|
|
|
|
#define MICROPY_DEBUG_MP_OBJ_SENTINELS (0)
|
|
|
|
#endif
|
|
|
|
|
2019-01-04 01:09:41 -05:00
|
|
|
// Whether to enable a simple VM stack overflow check
|
|
|
|
#ifndef MICROPY_DEBUG_VM_STACK_OVERFLOW
|
|
|
|
#define MICROPY_DEBUG_VM_STACK_OVERFLOW (0)
|
|
|
|
#endif
|
|
|
|
|
2014-01-07 09:54:15 -05:00
|
|
|
/*****************************************************************************/
|
2014-05-24 18:03:12 -04:00
|
|
|
/* Optimisations */
|
|
|
|
|
|
|
|
// Whether to use computed gotos in the VM, or a switch
|
|
|
|
// Computed gotos are roughly 10% faster, and increase VM code size by a little
|
2017-09-18 09:53:33 -04:00
|
|
|
// Note: enabling this will use the gcc-specific extensions of ranged designated
|
|
|
|
// initialisers and addresses of labels, which are not part of the C99 standard.
|
2014-05-24 18:03:12 -04:00
|
|
|
#ifndef MICROPY_OPT_COMPUTED_GOTO
|
|
|
|
#define MICROPY_OPT_COMPUTED_GOTO (0)
|
|
|
|
#endif
|
|
|
|
|
2015-01-06 07:51:39 -05:00
|
|
|
// Whether to cache result of map lookups in LOAD_NAME, LOAD_GLOBAL, LOAD_ATTR,
|
|
|
|
// STORE_ATTR bytecodes. Uses 1 byte extra RAM for each of these opcodes and
|
|
|
|
// uses a bit of extra code ROM, but greatly improves lookup speed.
|
|
|
|
#ifndef MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE
|
|
|
|
#define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE (0)
|
|
|
|
#endif
|
|
|
|
|
2016-01-30 22:35:58 -05:00
|
|
|
// Whether to use fast versions of bitwise operations (and, or, xor) when the
|
|
|
|
// arguments are both positive. Increases Thumb2 code size by about 250 bytes.
|
|
|
|
#ifndef MICROPY_OPT_MPZ_BITWISE
|
|
|
|
#define MICROPY_OPT_MPZ_BITWISE (0)
|
|
|
|
#endif
|
|
|
|
|
2018-08-26 20:32:21 -04:00
|
|
|
|
|
|
|
// Whether math.factorial is large, fast and recursive (1) or small and slow (0).
|
|
|
|
#ifndef MICROPY_OPT_MATH_FACTORIAL
|
|
|
|
#define MICROPY_OPT_MATH_FACTORIAL (0)
|
|
|
|
#endif
|
|
|
|
|
2014-05-24 18:03:12 -04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Python internal features */
|
2014-01-07 09:54:15 -05:00
|
|
|
|
2018-02-20 02:00:44 -05:00
|
|
|
// Whether to enable import of external modules
|
|
|
|
// When disabled, only importing of built-in modules is supported
|
|
|
|
// When enabled, a port must implement mp_import_stat (among other things)
|
|
|
|
#ifndef MICROPY_ENABLE_EXTERNAL_IMPORT
|
|
|
|
#define MICROPY_ENABLE_EXTERNAL_IMPORT (1)
|
|
|
|
#endif
|
|
|
|
|
2016-11-16 00:04:57 -05:00
|
|
|
// Whether to use the POSIX reader for importing files
|
|
|
|
#ifndef MICROPY_READER_POSIX
|
|
|
|
#define MICROPY_READER_POSIX (0)
|
|
|
|
#endif
|
|
|
|
|
2017-01-26 23:10:09 -05:00
|
|
|
// Whether to use the VFS reader for importing files
|
|
|
|
#ifndef MICROPY_READER_VFS
|
|
|
|
#define MICROPY_READER_VFS (0)
|
|
|
|
#endif
|
|
|
|
|
2018-12-13 07:10:35 -05:00
|
|
|
// Whether any readers have been defined
|
|
|
|
#ifndef MICROPY_HAS_FILE_READER
|
|
|
|
#define MICROPY_HAS_FILE_READER (MICROPY_READER_POSIX || MICROPY_READER_VFS)
|
|
|
|
#endif
|
|
|
|
|
2016-02-15 17:46:21 -05:00
|
|
|
// Hook for the VM at the start of the opcode loop (can contain variable
|
|
|
|
// definitions usable by the other hook functions)
|
|
|
|
#ifndef MICROPY_VM_HOOK_INIT
|
|
|
|
#define MICROPY_VM_HOOK_INIT
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Hook for the VM during the opcode loop (but only after jump opcodes)
|
|
|
|
#ifndef MICROPY_VM_HOOK_LOOP
|
|
|
|
#define MICROPY_VM_HOOK_LOOP
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Hook for the VM just before return opcode is finished being interpreted
|
|
|
|
#ifndef MICROPY_VM_HOOK_RETURN
|
|
|
|
#define MICROPY_VM_HOOK_RETURN
|
|
|
|
#endif
|
|
|
|
|
2014-01-07 10:20:33 -05:00
|
|
|
// Whether to include the garbage collector
|
|
|
|
#ifndef MICROPY_ENABLE_GC
|
|
|
|
#define MICROPY_ENABLE_GC (0)
|
|
|
|
#endif
|
|
|
|
|
2014-04-05 15:35:48 -04:00
|
|
|
// Whether to enable finalisers in the garbage collector (ie call __del__)
|
2014-11-05 16:16:41 -05:00
|
|
|
#ifndef MICROPY_ENABLE_FINALISER
|
|
|
|
#define MICROPY_ENABLE_FINALISER (0)
|
2014-04-05 15:35:48 -04:00
|
|
|
#endif
|
|
|
|
|
py: Introduce a Python stack for scoped allocation.
This patch introduces the MICROPY_ENABLE_PYSTACK option (disabled by
default) which enables a "Python stack" that allows to allocate and free
memory in a scoped, or Last-In-First-Out (LIFO) way, similar to alloca().
A new memory allocation API is introduced along with this Py-stack. It
includes both "local" and "nonlocal" LIFO allocation. Local allocation is
intended to be equivalent to using alloca(), whereby the same function must
free the memory. Nonlocal allocation is where another function may free
the memory, so long as it's still LIFO.
Follow-up patches will convert all uses of alloca() and VLA to the new
scoped allocation API. The old behaviour (using alloca()) will still be
available, but when MICROPY_ENABLE_PYSTACK is enabled then alloca() is no
longer required or used.
The benefits of enabling this option are (or will be once subsequent
patches are made to convert alloca()/VLA):
- Toolchains without alloca() can use this feature to obtain correct and
efficient scoped memory allocation (compared to using the heap instead
of alloca(), which is slower).
- Even if alloca() is available, enabling the Py-stack gives slightly more
efficient use of stack space when calling nested Python functions, due to
the way that compilers implement alloca().
- Enabling the Py-stack with the stackless mode allows for even more
efficient stack usage, as well as retaining high performance (because the
heap is no longer used to build and destroy stackless code states).
- With Py-stack and stackless enabled, Python-calling-Python is no longer
recursive in the C mp_execute_bytecode function.
The micropython.pystack_use() function is included to measure usage of the
Python stack.
2017-11-26 07:28:40 -05:00
|
|
|
// Whether to enable a separate allocator for the Python stack.
|
|
|
|
// If enabled then the code must call mp_pystack_init before mp_init.
|
|
|
|
#ifndef MICROPY_ENABLE_PYSTACK
|
|
|
|
#define MICROPY_ENABLE_PYSTACK (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Number of bytes that memory returned by mp_pystack_alloc will be aligned by.
|
|
|
|
#ifndef MICROPY_PYSTACK_ALIGN
|
|
|
|
#define MICROPY_PYSTACK_ALIGN (8)
|
|
|
|
#endif
|
|
|
|
|
2014-06-24 20:03:34 -04:00
|
|
|
// Whether to check C stack usage. C stack used for calling Python functions,
|
|
|
|
// etc. Not checking means segfault on overflow.
|
|
|
|
#ifndef MICROPY_STACK_CHECK
|
2015-01-08 19:10:55 -05:00
|
|
|
#define MICROPY_STACK_CHECK (0)
|
2014-06-24 20:03:34 -04:00
|
|
|
#endif
|
|
|
|
|
2014-07-02 02:46:53 -04:00
|
|
|
// Whether to have an emergency exception buffer
|
|
|
|
#ifndef MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
|
|
|
|
#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (0)
|
|
|
|
#endif
|
|
|
|
#if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
|
|
|
|
# ifndef MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE
|
|
|
|
# define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (0) // 0 - implies dynamic allocation
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2017-04-10 03:19:36 -04:00
|
|
|
// Whether to provide the mp_kbd_exception object, and micropython.kbd_intr function
|
2016-12-14 21:00:19 -05:00
|
|
|
#ifndef MICROPY_KBD_EXCEPTION
|
|
|
|
#define MICROPY_KBD_EXCEPTION (0)
|
|
|
|
#endif
|
|
|
|
|
2015-12-22 17:06:37 -05:00
|
|
|
// Prefer to raise KeyboardInterrupt asynchronously (from signal or interrupt
|
|
|
|
// handler) - if supported by a particular port.
|
|
|
|
#ifndef MICROPY_ASYNC_KBD_INTR
|
|
|
|
#define MICROPY_ASYNC_KBD_INTR (0)
|
|
|
|
#endif
|
|
|
|
|
2014-01-07 09:54:15 -05:00
|
|
|
// Whether to include REPL helper function
|
2014-05-21 15:32:59 -04:00
|
|
|
#ifndef MICROPY_HELPER_REPL
|
|
|
|
#define MICROPY_HELPER_REPL (0)
|
2014-01-07 09:54:15 -05:00
|
|
|
#endif
|
|
|
|
|
2015-07-09 19:32:36 -04:00
|
|
|
// Whether to include emacs-style readline behavior in REPL
|
|
|
|
#ifndef MICROPY_REPL_EMACS_KEYS
|
2015-07-26 10:49:13 -04:00
|
|
|
#define MICROPY_REPL_EMACS_KEYS (0)
|
2015-07-09 19:32:36 -04:00
|
|
|
#endif
|
|
|
|
|
2015-08-20 05:34:16 -04:00
|
|
|
// Whether to implement auto-indent in REPL
|
|
|
|
#ifndef MICROPY_REPL_AUTO_INDENT
|
|
|
|
#define MICROPY_REPL_AUTO_INDENT (0)
|
|
|
|
#endif
|
|
|
|
|
2015-01-15 03:46:27 -05:00
|
|
|
// Whether port requires event-driven REPL functions
|
|
|
|
#ifndef MICROPY_REPL_EVENT_DRIVEN
|
|
|
|
#define MICROPY_REPL_EVENT_DRIVEN (0)
|
|
|
|
#endif
|
|
|
|
|
2014-01-07 10:20:33 -05:00
|
|
|
// Whether to include lexer helper function for unix
|
2014-05-21 15:32:59 -04:00
|
|
|
#ifndef MICROPY_HELPER_LEXER_UNIX
|
|
|
|
#define MICROPY_HELPER_LEXER_UNIX (0)
|
2014-01-07 10:20:33 -05:00
|
|
|
#endif
|
|
|
|
|
2014-01-12 10:30:48 -05:00
|
|
|
// Long int implementation
|
|
|
|
#define MICROPY_LONGINT_IMPL_NONE (0)
|
|
|
|
#define MICROPY_LONGINT_IMPL_LONGLONG (1)
|
2014-02-22 14:25:23 -05:00
|
|
|
#define MICROPY_LONGINT_IMPL_MPZ (2)
|
2014-01-12 10:30:48 -05:00
|
|
|
|
|
|
|
#ifndef MICROPY_LONGINT_IMPL
|
|
|
|
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_NONE)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG
|
|
|
|
typedef long long mp_longint_impl_t;
|
|
|
|
#endif
|
|
|
|
|
2014-01-29 16:51:51 -05:00
|
|
|
// Whether to include information in the byte code to determine source
|
|
|
|
// line number (increases RAM usage, but doesn't slow byte code execution)
|
|
|
|
#ifndef MICROPY_ENABLE_SOURCE_LINE
|
|
|
|
#define MICROPY_ENABLE_SOURCE_LINE (0)
|
|
|
|
#endif
|
|
|
|
|
2014-04-25 18:52:57 -04:00
|
|
|
// Whether to include doc strings (increases RAM usage)
|
|
|
|
#ifndef MICROPY_ENABLE_DOC_STRING
|
|
|
|
#define MICROPY_ENABLE_DOC_STRING (0)
|
|
|
|
#endif
|
|
|
|
|
2014-11-06 12:36:16 -05:00
|
|
|
// Exception messages are short static strings
|
2014-04-30 18:35:38 -04:00
|
|
|
#define MICROPY_ERROR_REPORTING_TERSE (1)
|
|
|
|
// Exception messages provide basic error details
|
|
|
|
#define MICROPY_ERROR_REPORTING_NORMAL (2)
|
|
|
|
// Exception messages provide full info, e.g. object names
|
|
|
|
#define MICROPY_ERROR_REPORTING_DETAILED (3)
|
|
|
|
|
|
|
|
#ifndef MICROPY_ERROR_REPORTING
|
|
|
|
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_NORMAL)
|
|
|
|
#endif
|
|
|
|
|
2015-01-01 02:29:28 -05:00
|
|
|
// Whether issue warnings during compiling/execution
|
|
|
|
#ifndef MICROPY_WARNINGS
|
|
|
|
#define MICROPY_WARNINGS (0)
|
|
|
|
#endif
|
|
|
|
|
2018-12-21 06:20:55 -05:00
|
|
|
// Whether to support warning categories
|
|
|
|
#ifndef MICROPY_WARNINGS_CATEGORY
|
|
|
|
#define MICROPY_WARNINGS_CATEGORY (0)
|
|
|
|
#endif
|
|
|
|
|
2017-09-24 21:15:48 -04:00
|
|
|
// This macro is used when printing runtime warnings and errors
|
|
|
|
#ifndef MICROPY_ERROR_PRINTER
|
|
|
|
#define MICROPY_ERROR_PRINTER (&mp_plat_print)
|
|
|
|
#endif
|
|
|
|
|
2014-03-08 10:24:39 -05:00
|
|
|
// Float and complex implementation
|
|
|
|
#define MICROPY_FLOAT_IMPL_NONE (0)
|
|
|
|
#define MICROPY_FLOAT_IMPL_FLOAT (1)
|
|
|
|
#define MICROPY_FLOAT_IMPL_DOUBLE (2)
|
|
|
|
|
|
|
|
#ifndef MICROPY_FLOAT_IMPL
|
|
|
|
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_NONE)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
|
2014-06-01 08:32:54 -04:00
|
|
|
#define MICROPY_PY_BUILTINS_FLOAT (1)
|
2016-11-02 21:33:01 -04:00
|
|
|
#define MICROPY_FLOAT_CONST(x) x##F
|
2014-03-08 10:24:39 -05:00
|
|
|
#define MICROPY_FLOAT_C_FUN(fun) fun##f
|
|
|
|
typedef float mp_float_t;
|
|
|
|
#elif MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE
|
2014-06-01 08:32:54 -04:00
|
|
|
#define MICROPY_PY_BUILTINS_FLOAT (1)
|
2016-11-02 21:33:01 -04:00
|
|
|
#define MICROPY_FLOAT_CONST(x) x
|
2014-03-08 10:24:39 -05:00
|
|
|
#define MICROPY_FLOAT_C_FUN(fun) fun
|
|
|
|
typedef double mp_float_t;
|
|
|
|
#else
|
2014-06-01 08:32:54 -04:00
|
|
|
#define MICROPY_PY_BUILTINS_FLOAT (0)
|
2014-01-03 10:15:53 -05:00
|
|
|
#endif
|
2014-01-02 20:01:12 -05:00
|
|
|
|
2014-06-19 18:48:35 -04:00
|
|
|
#ifndef MICROPY_PY_BUILTINS_COMPLEX
|
|
|
|
#define MICROPY_PY_BUILTINS_COMPLEX (MICROPY_PY_BUILTINS_FLOAT)
|
|
|
|
#endif
|
|
|
|
|
2017-04-06 03:27:33 -04:00
|
|
|
// Whether to provide a high-quality hash for float and complex numbers.
|
|
|
|
// Otherwise the default is a very simple but correct hashing function.
|
|
|
|
#ifndef MICROPY_FLOAT_HIGH_QUALITY_HASH
|
|
|
|
#define MICROPY_FLOAT_HIGH_QUALITY_HASH (0)
|
|
|
|
#endif
|
|
|
|
|
2014-05-24 18:03:12 -04:00
|
|
|
// Enable features which improve CPython compatibility
|
|
|
|
// but may lead to more code size/memory usage.
|
|
|
|
// TODO: Originally intended as generic category to not
|
|
|
|
// add bunch of once-off options. May need refactoring later
|
|
|
|
#ifndef MICROPY_CPYTHON_COMPAT
|
|
|
|
#define MICROPY_CPYTHON_COMPAT (1)
|
2014-04-26 05:31:15 -04:00
|
|
|
#endif
|
|
|
|
|
2017-04-02 14:20:07 -04:00
|
|
|
// Perform full checks as done by CPython. Disabling this
|
|
|
|
// may produce incorrect results, if incorrect data is fed,
|
|
|
|
// but should not lead to MicroPython crashes or similar
|
|
|
|
// grave issues (in other words, only user app should be,
|
|
|
|
// affected, not system).
|
|
|
|
#ifndef MICROPY_FULL_CHECKS
|
|
|
|
#define MICROPY_FULL_CHECKS (1)
|
|
|
|
#endif
|
|
|
|
|
2014-05-24 18:03:12 -04:00
|
|
|
// Whether POSIX-semantics non-blocking streams are supported
|
|
|
|
#ifndef MICROPY_STREAMS_NON_BLOCK
|
|
|
|
#define MICROPY_STREAMS_NON_BLOCK (0)
|
2014-04-17 12:11:03 -04:00
|
|
|
#endif
|
|
|
|
|
2016-07-30 13:05:56 -04:00
|
|
|
// Whether to provide stream functions with POSIX-like signatures
|
|
|
|
// (useful for porting existing libraries to MicroPython).
|
|
|
|
#ifndef MICROPY_STREAMS_POSIX_API
|
|
|
|
#define MICROPY_STREAMS_POSIX_API (0)
|
|
|
|
#endif
|
|
|
|
|
2015-09-15 09:56:13 -04:00
|
|
|
// Whether to call __init__ when importing builtin modules for the first time
|
|
|
|
#ifndef MICROPY_MODULE_BUILTIN_INIT
|
|
|
|
#define MICROPY_MODULE_BUILTIN_INIT (0)
|
|
|
|
#endif
|
|
|
|
|
2018-10-22 12:34:29 -04:00
|
|
|
// Whether to support module-level __getattr__ (see PEP 562)
|
|
|
|
#ifndef MICROPY_MODULE_GETATTR
|
|
|
|
#define MICROPY_MODULE_GETATTR (0)
|
|
|
|
#endif
|
|
|
|
|
2014-10-12 06:46:04 -04:00
|
|
|
// Whether module weak links are supported
|
|
|
|
#ifndef MICROPY_MODULE_WEAK_LINKS
|
|
|
|
#define MICROPY_MODULE_WEAK_LINKS (0)
|
|
|
|
#endif
|
|
|
|
|
2016-01-31 17:24:16 -05:00
|
|
|
// Whether frozen modules are supported in the form of strings
|
|
|
|
#ifndef MICROPY_MODULE_FROZEN_STR
|
|
|
|
#define MICROPY_MODULE_FROZEN_STR (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Whether frozen modules are supported in the form of .mpy files
|
|
|
|
#ifndef MICROPY_MODULE_FROZEN_MPY
|
|
|
|
#define MICROPY_MODULE_FROZEN_MPY (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Convenience macro for whether frozen modules are supported
|
2015-01-20 04:52:12 -05:00
|
|
|
#ifndef MICROPY_MODULE_FROZEN
|
2016-01-31 17:24:16 -05:00
|
|
|
#define MICROPY_MODULE_FROZEN (MICROPY_MODULE_FROZEN_STR || MICROPY_MODULE_FROZEN_MPY)
|
2015-01-20 04:52:12 -05:00
|
|
|
#endif
|
|
|
|
|
2014-12-09 11:19:48 -05:00
|
|
|
// Whether you can override builtins in the builtins module
|
|
|
|
#ifndef MICROPY_CAN_OVERRIDE_BUILTINS
|
|
|
|
#define MICROPY_CAN_OVERRIDE_BUILTINS (0)
|
|
|
|
#endif
|
|
|
|
|
2015-06-19 08:49:10 -04:00
|
|
|
// Whether to check that the "self" argument of a builtin method has the
|
|
|
|
// correct type. Such an explicit check is only needed if a builtin
|
|
|
|
// method escapes to Python land without a first argument, eg
|
|
|
|
// list.append([], 1). Without this check such calls will have undefined
|
|
|
|
// behaviour (usually segfault) if the first argument is the wrong type.
|
|
|
|
#ifndef MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG
|
|
|
|
#define MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG (1)
|
|
|
|
#endif
|
|
|
|
|
2016-05-10 05:54:06 -04:00
|
|
|
// Whether to use internally defined errno's (otherwise system provided ones)
|
|
|
|
#ifndef MICROPY_USE_INTERNAL_ERRNO
|
|
|
|
#define MICROPY_USE_INTERNAL_ERRNO (0)
|
|
|
|
#endif
|
|
|
|
|
2016-08-21 05:33:37 -04:00
|
|
|
// Whether to use internally defined *printf() functions (otherwise external ones)
|
|
|
|
#ifndef MICROPY_USE_INTERNAL_PRINTF
|
|
|
|
#define MICROPY_USE_INTERNAL_PRINTF (1)
|
|
|
|
#endif
|
|
|
|
|
2017-02-16 02:05:06 -05:00
|
|
|
// Support for internal scheduler
|
|
|
|
#ifndef MICROPY_ENABLE_SCHEDULER
|
|
|
|
#define MICROPY_ENABLE_SCHEDULER (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Maximum number of entries in the scheduler
|
|
|
|
#ifndef MICROPY_SCHEDULER_DEPTH
|
|
|
|
#define MICROPY_SCHEDULER_DEPTH (4)
|
|
|
|
#endif
|
|
|
|
|
2017-01-26 23:10:09 -05:00
|
|
|
// Support for generic VFS sub-system
|
|
|
|
#ifndef MICROPY_VFS
|
|
|
|
#define MICROPY_VFS (0)
|
|
|
|
#endif
|
|
|
|
|
2018-06-05 23:11:33 -04:00
|
|
|
// Support for VFS POSIX component, to mount a POSIX filesystem within VFS
|
|
|
|
#ifndef MICROPY_VFS
|
|
|
|
#define MICROPY_VFS_POSIX (0)
|
|
|
|
#endif
|
|
|
|
|
2018-06-06 00:31:29 -04:00
|
|
|
// Support for VFS FAT component, to mount a FAT filesystem within VFS
|
|
|
|
#ifndef MICROPY_VFS
|
|
|
|
#define MICROPY_VFS_FAT (0)
|
|
|
|
#endif
|
|
|
|
|
2014-05-24 18:03:12 -04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Fine control over Python builtins, classes, modules, etc */
|
2014-04-17 12:11:03 -04:00
|
|
|
|
2017-04-01 08:52:24 -04:00
|
|
|
// Whether to support multiple inheritance of Python classes. Multiple
|
|
|
|
// inheritance makes some C functions inherently recursive, and adds a bit of
|
|
|
|
// code overhead.
|
|
|
|
#ifndef MICROPY_MULTIPLE_INHERITANCE
|
|
|
|
#define MICROPY_MULTIPLE_INHERITANCE (1)
|
|
|
|
#endif
|
|
|
|
|
2015-02-14 12:44:31 -05:00
|
|
|
// Whether to implement attributes on functions
|
|
|
|
#ifndef MICROPY_PY_FUNCTION_ATTRS
|
|
|
|
#define MICROPY_PY_FUNCTION_ATTRS (0)
|
|
|
|
#endif
|
|
|
|
|
py/objtype: Optimise instance get/set/del by skipping special accessors.
This patch is a code optimisation, trading text bytes for speed. On
pyboard it's an increase of 0.06% in code size for a gain (in pystone
performance) of roughly 6.5%.
The patch optimises load/store/delete of attributes in user defined classes
by not looking up special accessors (@property, __get__, __delete__,
__set__, __setattr__ and __getattr_) if they are guaranteed not to exist in
the class.
Currently, if you do my_obj.foo() then the runtime has to do a few checks
to see if foo is a property or has __get__, and if so delegate the call.
And for stores things like my_obj.foo = 1 has to first check if foo is a
property or has __set__ defined on it.
Doing all those checks each and every time the attribute is accessed has a
performance penalty. This patch eliminates all those checks for cases when
it's guaranteed that the checks will always fail, ie no attributes are
properties nor have any special accessor methods defined on them.
To make this guarantee it checks all attributes of a user-defined class
when it is first created. If any of the attributes of the user class are
properties or have special accessors, or any of the base classes of the
user class have them, then it sets a flag in the class to indicate that
special accessors must be checked for. Then in the load/store/delete code
it checks this flag to see if it can take the shortcut and optimise the
lookup.
It's an optimisation that's pretty widely applicable because it improves
lookup performance for all methods of user defined classes, and stores of
attributes, at least for those that don't have special accessors. And, it
allows to enable descriptors with minimal additional runtime overhead if
they are not used for a particular user class.
There is one restriction on dynamic class creation that has been introduced
by this patch: a user-defined class cannot go from zero special accessors
to one special accessor (or more) after that class has been subclassed. If
the script attempts this an AttributeError is raised (see addition to
tests/misc/non_compliant.py for an example of this case).
The cost in code space bytes for the optimisation in this patch is:
unix x64: +528
unix nanbox: +508
stm32: +192
cc3200: +200
esp8266: +332
esp32: +244
Performance tests that were done:
- on unix x86-64, pystone improved by about 5%
- on pyboard, pystone improved by about 6.5%, from 1683 up to 1794
- on pyboard, bm_chaos (from CPython benchmark suite) improved by about 5%
- on esp32, pystone improved by about 30% (but there are caching effects)
- on esp32, bm_chaos improved by about 11%
2018-05-25 03:09:54 -04:00
|
|
|
// Whether to support the descriptors __get__, __set__, __delete__
|
|
|
|
// This costs some code size and makes load/store/delete of instance
|
|
|
|
// attributes slower for the classes that use this feature
|
2015-02-14 12:43:54 -05:00
|
|
|
#ifndef MICROPY_PY_DESCRIPTORS
|
|
|
|
#define MICROPY_PY_DESCRIPTORS (0)
|
|
|
|
#endif
|
|
|
|
|
2017-01-03 05:00:12 -05:00
|
|
|
// Whether to support class __delattr__ and __setattr__ methods
|
py/objtype: Optimise instance get/set/del by skipping special accessors.
This patch is a code optimisation, trading text bytes for speed. On
pyboard it's an increase of 0.06% in code size for a gain (in pystone
performance) of roughly 6.5%.
The patch optimises load/store/delete of attributes in user defined classes
by not looking up special accessors (@property, __get__, __delete__,
__set__, __setattr__ and __getattr_) if they are guaranteed not to exist in
the class.
Currently, if you do my_obj.foo() then the runtime has to do a few checks
to see if foo is a property or has __get__, and if so delegate the call.
And for stores things like my_obj.foo = 1 has to first check if foo is a
property or has __set__ defined on it.
Doing all those checks each and every time the attribute is accessed has a
performance penalty. This patch eliminates all those checks for cases when
it's guaranteed that the checks will always fail, ie no attributes are
properties nor have any special accessor methods defined on them.
To make this guarantee it checks all attributes of a user-defined class
when it is first created. If any of the attributes of the user class are
properties or have special accessors, or any of the base classes of the
user class have them, then it sets a flag in the class to indicate that
special accessors must be checked for. Then in the load/store/delete code
it checks this flag to see if it can take the shortcut and optimise the
lookup.
It's an optimisation that's pretty widely applicable because it improves
lookup performance for all methods of user defined classes, and stores of
attributes, at least for those that don't have special accessors. And, it
allows to enable descriptors with minimal additional runtime overhead if
they are not used for a particular user class.
There is one restriction on dynamic class creation that has been introduced
by this patch: a user-defined class cannot go from zero special accessors
to one special accessor (or more) after that class has been subclassed. If
the script attempts this an AttributeError is raised (see addition to
tests/misc/non_compliant.py for an example of this case).
The cost in code space bytes for the optimisation in this patch is:
unix x64: +528
unix nanbox: +508
stm32: +192
cc3200: +200
esp8266: +332
esp32: +244
Performance tests that were done:
- on unix x86-64, pystone improved by about 5%
- on pyboard, pystone improved by about 6.5%, from 1683 up to 1794
- on pyboard, bm_chaos (from CPython benchmark suite) improved by about 5%
- on esp32, pystone improved by about 30% (but there are caching effects)
- on esp32, bm_chaos improved by about 11%
2018-05-25 03:09:54 -04:00
|
|
|
// This costs some code size and makes store/delete of instance
|
|
|
|
// attributes slower for the classes that use this feature
|
2017-01-03 05:00:12 -05:00
|
|
|
#ifndef MICROPY_PY_DELATTR_SETATTR
|
|
|
|
#define MICROPY_PY_DELATTR_SETATTR (0)
|
|
|
|
#endif
|
|
|
|
|
2016-01-27 15:23:11 -05:00
|
|
|
// Support for async/await/async for/async with
|
|
|
|
#ifndef MICROPY_PY_ASYNC_AWAIT
|
|
|
|
#define MICROPY_PY_ASYNC_AWAIT (1)
|
|
|
|
#endif
|
|
|
|
|
2017-10-21 05:13:44 -04:00
|
|
|
// Non-standard .pend_throw() method for generators, allowing for
|
|
|
|
// Future-like behavior with respect to exception handling: an
|
|
|
|
// exception set with .pend_throw() will activate on the next call
|
|
|
|
// to generator's .send() or .__next__(). (This is useful to implement
|
|
|
|
// async schedulers.)
|
|
|
|
#ifndef MICROPY_PY_GENERATOR_PEND_THROW
|
|
|
|
#define MICROPY_PY_GENERATOR_PEND_THROW (1)
|
|
|
|
#endif
|
|
|
|
|
2016-07-21 17:46:24 -04:00
|
|
|
// Issue a warning when comparing str and bytes objects
|
2016-07-21 17:34:34 -04:00
|
|
|
#ifndef MICROPY_PY_STR_BYTES_CMP_WARN
|
|
|
|
#define MICROPY_PY_STR_BYTES_CMP_WARN (0)
|
|
|
|
#endif
|
|
|
|
|
2014-06-12 18:05:19 -04:00
|
|
|
// Whether str object is proper unicode
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_STR_UNICODE
|
|
|
|
#define MICROPY_PY_BUILTINS_STR_UNICODE (0)
|
2014-06-28 05:29:22 -04:00
|
|
|
#endif
|
2014-06-28 05:27:15 -04:00
|
|
|
|
2017-06-23 20:38:32 -04:00
|
|
|
// Whether to check for valid UTF-8 when converting bytes to str
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_STR_UNICODE_CHECK
|
|
|
|
#define MICROPY_PY_BUILTINS_STR_UNICODE_CHECK (MICROPY_PY_BUILTINS_STR_UNICODE)
|
|
|
|
#endif
|
|
|
|
|
2016-05-21 17:13:44 -04:00
|
|
|
// Whether str.center() method provided
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_STR_CENTER
|
|
|
|
#define MICROPY_PY_BUILTINS_STR_CENTER (0)
|
|
|
|
#endif
|
|
|
|
|
2018-08-05 16:56:19 -04:00
|
|
|
// Whether str.count() method provided
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_STR_COUNT
|
|
|
|
#define MICROPY_PY_BUILTINS_STR_COUNT (1)
|
|
|
|
#endif
|
|
|
|
|
2018-08-15 08:17:41 -04:00
|
|
|
// Whether str % (...) formatting operator provided
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_STR_OP_MODULO
|
|
|
|
#define MICROPY_PY_BUILTINS_STR_OP_MODULO (1)
|
|
|
|
#endif
|
|
|
|
|
2016-08-06 23:46:55 -04:00
|
|
|
// Whether str.partition()/str.rpartition() method provided
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_STR_PARTITION
|
|
|
|
#define MICROPY_PY_BUILTINS_STR_PARTITION (0)
|
|
|
|
#endif
|
|
|
|
|
2015-04-03 17:09:23 -04:00
|
|
|
// Whether str.splitlines() method provided
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_STR_SPLITLINES
|
|
|
|
#define MICROPY_PY_BUILTINS_STR_SPLITLINES (0)
|
|
|
|
#endif
|
|
|
|
|
2014-06-27 13:39:09 -04:00
|
|
|
// Whether to support bytearray object
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_BYTEARRAY
|
|
|
|
#define MICROPY_PY_BUILTINS_BYTEARRAY (1)
|
2014-06-12 18:05:19 -04:00
|
|
|
#endif
|
|
|
|
|
2018-08-05 18:25:41 -04:00
|
|
|
// Whether to support dict.fromkeys() class method
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_DICT_FROMKEYS
|
|
|
|
#define MICROPY_PY_BUILTINS_DICT_FROMKEYS (1)
|
|
|
|
#endif
|
|
|
|
|
2014-10-23 08:34:35 -04:00
|
|
|
// Whether to support memoryview object
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_MEMORYVIEW
|
|
|
|
#define MICROPY_PY_BUILTINS_MEMORYVIEW (0)
|
|
|
|
#endif
|
|
|
|
|
2019-05-08 10:16:17 -04:00
|
|
|
// Whether to support memoryview.itemsize attribute
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_MEMORYVIEW_ITEMSIZE
|
|
|
|
#define MICROPY_PY_BUILTINS_MEMORYVIEW_ITEMSIZE (0)
|
|
|
|
#endif
|
|
|
|
|
2014-06-01 08:46:47 -04:00
|
|
|
// Whether to support set object
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_SET
|
|
|
|
#define MICROPY_PY_BUILTINS_SET (1)
|
|
|
|
#endif
|
|
|
|
|
2014-06-01 08:32:54 -04:00
|
|
|
// Whether to support slice subscript operators and slice object
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_SLICE
|
|
|
|
#define MICROPY_PY_BUILTINS_SLICE (1)
|
2014-05-05 19:16:43 -04:00
|
|
|
#endif
|
|
|
|
|
2015-09-11 17:31:32 -04:00
|
|
|
// Whether to support slice attribute read access,
|
|
|
|
// i.e. slice.start, slice.stop, slice.step
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_SLICE_ATTRS
|
|
|
|
#define MICROPY_PY_BUILTINS_SLICE_ATTRS (0)
|
|
|
|
#endif
|
|
|
|
|
2014-05-24 18:03:12 -04:00
|
|
|
// Whether to support frozenset object
|
2014-06-01 08:32:54 -04:00
|
|
|
#ifndef MICROPY_PY_BUILTINS_FROZENSET
|
|
|
|
#define MICROPY_PY_BUILTINS_FROZENSET (0)
|
2014-04-03 07:57:53 -04:00
|
|
|
#endif
|
|
|
|
|
2014-06-01 08:32:54 -04:00
|
|
|
// Whether to support property object
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_PROPERTY
|
|
|
|
#define MICROPY_PY_BUILTINS_PROPERTY (1)
|
2014-05-19 13:59:13 -04:00
|
|
|
#endif
|
|
|
|
|
2015-03-06 14:48:14 -05:00
|
|
|
// Whether to implement the start/stop/step attributes (readback) on
|
|
|
|
// the "range" builtin type. Rarely used, and costs ~60 bytes (x86).
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_RANGE_ATTRS
|
|
|
|
#define MICROPY_PY_BUILTINS_RANGE_ATTRS (1)
|
|
|
|
#endif
|
|
|
|
|
2018-02-14 07:17:06 -05:00
|
|
|
// Whether to support binary ops [only (in)equality is defined] between range
|
|
|
|
// objects. With this option disabled all range objects that are not exactly
|
|
|
|
// the same object will compare as not-equal. With it enabled the semantics
|
|
|
|
// match CPython and ranges are equal if they yield the same sequence of items.
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_RANGE_BINOP
|
|
|
|
#define MICROPY_PY_BUILTINS_RANGE_BINOP (0)
|
2018-01-09 16:47:35 -05:00
|
|
|
#endif
|
|
|
|
|
2019-01-03 09:19:42 -05:00
|
|
|
// Support for callling next() with second argument
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_NEXT2
|
|
|
|
#define MICROPY_PY_BUILTINS_NEXT2 (0)
|
|
|
|
#endif
|
|
|
|
|
2018-01-09 16:47:35 -05:00
|
|
|
// Whether to support rounding of integers (incl bignum); eg round(123,-1)=120
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_ROUND_INT
|
|
|
|
#define MICROPY_PY_BUILTINS_ROUND_INT (0)
|
2018-02-14 07:17:06 -05:00
|
|
|
#endif
|
|
|
|
|
2015-06-29 16:45:39 -04:00
|
|
|
// Whether to support timeout exceptions (like socket.timeout)
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_TIMEOUTERROR
|
|
|
|
#define MICROPY_PY_BUILTINS_TIMEOUTERROR (0)
|
|
|
|
#endif
|
|
|
|
|
2017-10-27 15:29:15 -04:00
|
|
|
// Whether to support complete set of special methods for user
|
|
|
|
// classes, or only the most used ones. "Inplace" methods are
|
|
|
|
// controlled by MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS below.
|
|
|
|
// "Reverse" methods are controlled by
|
|
|
|
// MICROPY_PY_REVERSE_SPECIAL_METHODS below.
|
2015-01-29 18:42:49 -05:00
|
|
|
#ifndef MICROPY_PY_ALL_SPECIAL_METHODS
|
|
|
|
#define MICROPY_PY_ALL_SPECIAL_METHODS (0)
|
|
|
|
#endif
|
|
|
|
|
2017-10-27 15:29:15 -04:00
|
|
|
// Whether to support all inplace arithmetic operarion methods
|
|
|
|
// (__imul__, etc.)
|
|
|
|
#ifndef MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS
|
|
|
|
#define MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Whether to support reverse arithmetic operarion methods
|
|
|
|
// (__radd__, etc.). Additionally gated by
|
|
|
|
// MICROPY_PY_ALL_SPECIAL_METHODS.
|
2017-09-10 10:05:20 -04:00
|
|
|
#ifndef MICROPY_PY_REVERSE_SPECIAL_METHODS
|
|
|
|
#define MICROPY_PY_REVERSE_SPECIAL_METHODS (0)
|
|
|
|
#endif
|
|
|
|
|
2014-10-25 16:59:14 -04:00
|
|
|
// Whether to support compile function
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_COMPILE
|
|
|
|
#define MICROPY_PY_BUILTINS_COMPILE (0)
|
|
|
|
#endif
|
|
|
|
|
2015-04-06 16:50:37 -04:00
|
|
|
// Whether to support enumerate function(type)
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_ENUMERATE
|
|
|
|
#define MICROPY_PY_BUILTINS_ENUMERATE (1)
|
|
|
|
#endif
|
|
|
|
|
2015-12-18 07:35:44 -05:00
|
|
|
// Whether to support eval and exec functions
|
|
|
|
// By default they are supported if the compiler is enabled
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_EVAL_EXEC
|
|
|
|
#define MICROPY_PY_BUILTINS_EVAL_EXEC (MICROPY_ENABLE_COMPILER)
|
|
|
|
#endif
|
|
|
|
|
2014-12-19 08:36:17 -05:00
|
|
|
// Whether to support the Python 2 execfile function
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_EXECFILE
|
|
|
|
#define MICROPY_PY_BUILTINS_EXECFILE (0)
|
|
|
|
#endif
|
|
|
|
|
2015-08-19 18:01:56 -04:00
|
|
|
// Whether to support filter function(type)
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_FILTER
|
|
|
|
#define MICROPY_PY_BUILTINS_FILTER (1)
|
|
|
|
#endif
|
|
|
|
|
2015-04-06 17:16:51 -04:00
|
|
|
// Whether to support reversed function(type)
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_REVERSED
|
|
|
|
#define MICROPY_PY_BUILTINS_REVERSED (1)
|
|
|
|
#endif
|
|
|
|
|
2015-05-04 12:45:53 -04:00
|
|
|
// Whether to define "NotImplemented" special constant
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_NOTIMPLEMENTED
|
|
|
|
#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (0)
|
|
|
|
#endif
|
|
|
|
|
2017-06-01 01:32:23 -04:00
|
|
|
// Whether to provide the built-in input() function. The implementation of this
|
|
|
|
// uses mp-readline, so can only be enabled if the port uses this readline.
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_INPUT
|
|
|
|
#define MICROPY_PY_BUILTINS_INPUT (0)
|
|
|
|
#endif
|
|
|
|
|
2015-12-07 07:35:48 -05:00
|
|
|
// Whether to support min/max functions
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_MIN_MAX
|
|
|
|
#define MICROPY_PY_BUILTINS_MIN_MAX (1)
|
|
|
|
#endif
|
|
|
|
|
2017-02-02 20:35:48 -05:00
|
|
|
// Support for calls to pow() with 3 integer arguments
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_POW3
|
|
|
|
#define MICROPY_PY_BUILTINS_POW3 (0)
|
|
|
|
#endif
|
|
|
|
|
2017-01-21 07:17:51 -05:00
|
|
|
// Whether to provide the help function
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_HELP
|
|
|
|
#define MICROPY_PY_BUILTINS_HELP (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Use this to configure the help text shown for help(). It should be a
|
|
|
|
// variable with the type "const char*". A sensible default is provided.
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_HELP_TEXT
|
|
|
|
#define MICROPY_PY_BUILTINS_HELP_TEXT mp_help_default_text
|
|
|
|
#endif
|
|
|
|
|
2017-01-21 20:12:54 -05:00
|
|
|
// Add the ability to list the available modules when executing help('modules')
|
|
|
|
#ifndef MICROPY_PY_BUILTINS_HELP_MODULES
|
|
|
|
#define MICROPY_PY_BUILTINS_HELP_MODULES (0)
|
|
|
|
#endif
|
|
|
|
|
2014-07-25 04:00:15 -04:00
|
|
|
// Whether to set __file__ for imported modules
|
|
|
|
#ifndef MICROPY_PY___FILE__
|
|
|
|
#define MICROPY_PY___FILE__ (1)
|
|
|
|
#endif
|
|
|
|
|
2015-01-09 15:12:54 -05:00
|
|
|
// Whether to provide mem-info related functions in micropython module
|
|
|
|
#ifndef MICROPY_PY_MICROPYTHON_MEM_INFO
|
|
|
|
#define MICROPY_PY_MICROPYTHON_MEM_INFO (0)
|
|
|
|
#endif
|
|
|
|
|
2018-02-20 02:30:22 -05:00
|
|
|
// Whether to provide "micropython.stack_use" function
|
|
|
|
#ifndef MICROPY_PY_MICROPYTHON_STACK_USE
|
|
|
|
#define MICROPY_PY_MICROPYTHON_STACK_USE (MICROPY_PY_MICROPYTHON_MEM_INFO)
|
|
|
|
#endif
|
|
|
|
|
2014-06-27 13:39:09 -04:00
|
|
|
// Whether to provide "array" module. Note that large chunk of the
|
|
|
|
// underlying code is shared with "bytearray" builtin type, so to
|
|
|
|
// get real savings, it should be disabled too.
|
|
|
|
#ifndef MICROPY_PY_ARRAY
|
|
|
|
#define MICROPY_PY_ARRAY (1)
|
|
|
|
#endif
|
|
|
|
|
2015-02-27 15:16:05 -05:00
|
|
|
// Whether to support slice assignments for array (and bytearray).
|
|
|
|
// This is rarely used, but adds ~0.5K of code.
|
|
|
|
#ifndef MICROPY_PY_ARRAY_SLICE_ASSIGN
|
|
|
|
#define MICROPY_PY_ARRAY_SLICE_ASSIGN (0)
|
|
|
|
#endif
|
|
|
|
|
2015-04-21 10:14:24 -04:00
|
|
|
// Whether to support attrtuple type (MicroPython extension)
|
|
|
|
// It provides space-efficient tuples with attribute access
|
|
|
|
#ifndef MICROPY_PY_ATTRTUPLE
|
|
|
|
#define MICROPY_PY_ATTRTUPLE (1)
|
|
|
|
#endif
|
|
|
|
|
2014-05-24 18:03:12 -04:00
|
|
|
// Whether to provide "collections" module
|
|
|
|
#ifndef MICROPY_PY_COLLECTIONS
|
|
|
|
#define MICROPY_PY_COLLECTIONS (1)
|
2014-05-15 00:28:19 -04:00
|
|
|
#endif
|
|
|
|
|
2018-02-05 17:06:42 -05:00
|
|
|
// Whether to provide "ucollections.deque" type
|
|
|
|
#ifndef MICROPY_PY_COLLECTIONS_DEQUE
|
|
|
|
#define MICROPY_PY_COLLECTIONS_DEQUE (0)
|
|
|
|
#endif
|
|
|
|
|
2015-03-17 19:25:04 -04:00
|
|
|
// Whether to provide "collections.OrderedDict" type
|
|
|
|
#ifndef MICROPY_PY_COLLECTIONS_ORDEREDDICT
|
|
|
|
#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (0)
|
|
|
|
#endif
|
|
|
|
|
2017-11-06 06:21:53 -05:00
|
|
|
// Whether to provide the _asdict function for namedtuple
|
|
|
|
#ifndef MICROPY_PY_COLLECTIONS_NAMEDTUPLE__ASDICT
|
|
|
|
#define MICROPY_PY_COLLECTIONS_NAMEDTUPLE__ASDICT (0)
|
|
|
|
#endif
|
|
|
|
|
2014-05-24 18:03:12 -04:00
|
|
|
// Whether to provide "math" module
|
|
|
|
#ifndef MICROPY_PY_MATH
|
|
|
|
#define MICROPY_PY_MATH (1)
|
2014-04-09 20:45:38 -04:00
|
|
|
#endif
|
|
|
|
|
2015-02-22 09:48:18 -05:00
|
|
|
// Whether to provide special math functions: math.{erf,erfc,gamma,lgamma}
|
|
|
|
#ifndef MICROPY_PY_MATH_SPECIAL_FUNCTIONS
|
|
|
|
#define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (0)
|
|
|
|
#endif
|
|
|
|
|
2018-08-26 20:32:21 -04:00
|
|
|
// Whether to provide math.factorial function
|
|
|
|
#ifndef MICROPY_PY_MATH_FACTORIAL
|
|
|
|
#define MICROPY_PY_MATH_FACTORIAL (0)
|
|
|
|
#endif
|
|
|
|
|
2014-05-24 18:03:12 -04:00
|
|
|
// Whether to provide "cmath" module
|
|
|
|
#ifndef MICROPY_PY_CMATH
|
|
|
|
#define MICROPY_PY_CMATH (0)
|
2014-04-12 23:43:18 -04:00
|
|
|
#endif
|
|
|
|
|
2014-05-24 18:03:12 -04:00
|
|
|
// Whether to provide "gc" module
|
|
|
|
#ifndef MICROPY_PY_GC
|
|
|
|
#define MICROPY_PY_GC (1)
|
2014-04-13 00:00:37 -04:00
|
|
|
#endif
|
|
|
|
|
2014-06-05 15:48:02 -04:00
|
|
|
// Whether to return number of collected objects from gc.collect()
|
|
|
|
#ifndef MICROPY_PY_GC_COLLECT_RETVAL
|
|
|
|
#define MICROPY_PY_GC_COLLECT_RETVAL (0)
|
|
|
|
#endif
|
|
|
|
|
2014-05-24 18:03:12 -04:00
|
|
|
// Whether to provide "io" module
|
|
|
|
#ifndef MICROPY_PY_IO
|
|
|
|
#define MICROPY_PY_IO (1)
|
2014-05-10 10:26:47 -04:00
|
|
|
#endif
|
|
|
|
|
2018-06-04 01:54:26 -04:00
|
|
|
// Whether to provide "io.IOBase" class to support user streams
|
|
|
|
#ifndef MICROPY_PY_IO_IOBASE
|
|
|
|
#define MICROPY_PY_IO_IOBASE (0)
|
|
|
|
#endif
|
|
|
|
|
2017-05-02 18:47:08 -04:00
|
|
|
// Whether to provide "uio.resource_stream()" function with
|
|
|
|
// the semantics of CPython's pkg_resources.resource_stream()
|
unix/mpconfigport: Disable uio.resource_stream().
This function was implemented as an experiment, and was enabled only in
unix port. To remind, it allows to access arbitrary files frozen as
source modules (vs bytecode).
However, further experimentation showed that the same functionality can
be implemented with frozen bytecode. The process requires more steps, but
with suitable toolset it doesn't matter patch. This process is:
1. Convert binary files into "Python resource module" with
tools/mpy_bin2res.py.
2. Freeze as the bytecode.
3. Use micropython-lib's pkg_resources.resource_stream() to access it.
In other words, the extra step is using tools/mpy_bin2res.py (because
there would be wrapper for uio.resource_stream() anyway).
Going frozen bytecode route allows more flexibility, and same/additional
efficiency:
1. Frozen source support can be disabled altogether for additional code
savings.
2. Resources could be also accessed as a buffer, not just as a stream.
There're few caveats too:
1. It wasn't actually profiled the overhead of storing a resource in
"Python resource module" vs storing it directly, but it's assumed that
overhead is small.
2. The "efficiency" claim above applies to the case when resource
file is frozen as the bytecode. If it's not, it actually will take a
lot of RAM on loading. But in this case, the resource file should not
be used (i.e. generated) in the first place, and micropython-lib's
pkg_resources.resource_stream() implementation has the appropriate
fallback to read the raw files instead. This still poses some distribution
issues, e.g. to deployable to baremetal ports (which almost certainly
would require freezeing as the bytecode), a distribution package should
include the resource module. But for non-freezing deployment, presense
of resource module will lead to memory inefficiency.
All the discussion above reminds why uio.resource_stream() was implemented
in the first place - to address some of the issues above. However, since
then, frozen bytecode approach seems to prevail, so, while there're still
some issues to address with it, this change is being made.
This change saves 488 bytes for the unix x86_64 port.
2017-12-09 19:15:43 -05:00
|
|
|
// (allows to access binary resources in frozen source packages).
|
|
|
|
// Note that the same functionality can be achieved in "pure
|
|
|
|
// Python" by prepocessing binary resources into Python source
|
|
|
|
// and bytecode-freezing it (with a simple helper module available
|
|
|
|
// e.g. in micropython-lib).
|
2017-05-02 18:47:08 -04:00
|
|
|
#ifndef MICROPY_PY_IO_RESOURCE_STREAM
|
|
|
|
#define MICROPY_PY_IO_RESOURCE_STREAM (0)
|
|
|
|
#endif
|
|
|
|
|
2014-05-24 18:03:12 -04:00
|
|
|
// Whether to provide "io.FileIO" class
|
|
|
|
#ifndef MICROPY_PY_IO_FILEIO
|
|
|
|
#define MICROPY_PY_IO_FILEIO (0)
|
2014-01-02 20:01:12 -05:00
|
|
|
#endif
|
2014-01-07 09:54:15 -05:00
|
|
|
|
2014-05-24 18:03:12 -04:00
|
|
|
// Whether to provide "io.BytesIO" class
|
|
|
|
#ifndef MICROPY_PY_IO_BYTESIO
|
|
|
|
#define MICROPY_PY_IO_BYTESIO (1)
|
2014-05-10 09:02:17 -04:00
|
|
|
#endif
|
|
|
|
|
2016-03-24 19:10:49 -04:00
|
|
|
// Whether to provide "io.BufferedWriter" class
|
|
|
|
#ifndef MICROPY_PY_IO_BUFFEREDWRITER
|
|
|
|
#define MICROPY_PY_IO_BUFFEREDWRITER (0)
|
|
|
|
#endif
|
|
|
|
|
2014-05-24 18:03:12 -04:00
|
|
|
// Whether to provide "struct" module
|
|
|
|
#ifndef MICROPY_PY_STRUCT
|
|
|
|
#define MICROPY_PY_STRUCT (1)
|
2014-04-13 13:59:45 -04:00
|
|
|
#endif
|
|
|
|
|
2014-05-24 18:03:12 -04:00
|
|
|
// Whether to provide "sys" module
|
|
|
|
#ifndef MICROPY_PY_SYS
|
|
|
|
#define MICROPY_PY_SYS (1)
|
2014-01-16 12:19:50 -05:00
|
|
|
#endif
|
|
|
|
|
2014-07-03 09:50:11 -04:00
|
|
|
// Whether to provide "sys.maxsize" constant
|
|
|
|
#ifndef MICROPY_PY_SYS_MAXSIZE
|
|
|
|
#define MICROPY_PY_SYS_MAXSIZE (0)
|
|
|
|
#endif
|
|
|
|
|
2015-12-04 17:09:10 -05:00
|
|
|
// Whether to provide "sys.modules" dictionary
|
|
|
|
#ifndef MICROPY_PY_SYS_MODULES
|
|
|
|
#define MICROPY_PY_SYS_MODULES (1)
|
|
|
|
#endif
|
|
|
|
|
2015-04-24 20:17:41 -04:00
|
|
|
// Whether to provide "sys.exc_info" function
|
|
|
|
// Avoid enabling this, this function is Python2 heritage
|
|
|
|
#ifndef MICROPY_PY_SYS_EXC_INFO
|
|
|
|
#define MICROPY_PY_SYS_EXC_INFO (0)
|
|
|
|
#endif
|
|
|
|
|
2014-05-24 18:03:12 -04:00
|
|
|
// Whether to provide "sys.exit" function
|
|
|
|
#ifndef MICROPY_PY_SYS_EXIT
|
2016-12-14 13:10:22 -05:00
|
|
|
#define MICROPY_PY_SYS_EXIT (1)
|
2014-05-06 19:23:46 -04:00
|
|
|
#endif
|
|
|
|
|
2019-08-05 09:06:41 -04:00
|
|
|
// Whether to provide "sys.atexit" function (MicroPython extension)
|
|
|
|
#ifndef MICROPY_PY_SYS_ATEXIT
|
|
|
|
#define MICROPY_PY_SYS_ATEXIT (0)
|
|
|
|
#endif
|
|
|
|
|
2017-08-11 02:42:39 -04:00
|
|
|
// Whether to provide "sys.getsizeof" function
|
|
|
|
#ifndef MICROPY_PY_SYS_GETSIZEOF
|
|
|
|
#define MICROPY_PY_SYS_GETSIZEOF (0)
|
|
|
|
#endif
|
|
|
|
|
2014-05-24 18:03:12 -04:00
|
|
|
// Whether to provide sys.{stdin,stdout,stderr} objects
|
|
|
|
#ifndef MICROPY_PY_SYS_STDFILES
|
|
|
|
#define MICROPY_PY_SYS_STDFILES (0)
|
2014-04-14 16:20:30 -04:00
|
|
|
#endif
|
|
|
|
|
2015-05-13 18:49:21 -04:00
|
|
|
// Whether to provide sys.{stdin,stdout,stderr}.buffer object
|
|
|
|
// This is implemented per-port
|
|
|
|
#ifndef MICROPY_PY_SYS_STDIO_BUFFER
|
|
|
|
#define MICROPY_PY_SYS_STDIO_BUFFER (0)
|
2016-05-10 05:54:25 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Whether to provide "uerrno" module
|
|
|
|
#ifndef MICROPY_PY_UERRNO
|
|
|
|
#define MICROPY_PY_UERRNO (0)
|
2015-05-13 18:49:21 -04:00
|
|
|
#endif
|
2014-06-27 20:03:47 -04:00
|
|
|
|
2017-02-21 20:53:42 -05:00
|
|
|
// Whether to provide the uerrno.errorcode dict
|
|
|
|
#ifndef MICROPY_PY_UERRNO_ERRORCODE
|
|
|
|
#define MICROPY_PY_UERRNO_ERRORCODE (1)
|
|
|
|
#endif
|
|
|
|
|
2016-11-20 15:49:45 -05:00
|
|
|
// Whether to provide "uselect" module (baremetal implementation)
|
|
|
|
#ifndef MICROPY_PY_USELECT
|
|
|
|
#define MICROPY_PY_USELECT (0)
|
|
|
|
#endif
|
|
|
|
|
2016-10-14 13:13:02 -04:00
|
|
|
// Whether to provide "utime" module functions implementation
|
|
|
|
// in terms of mp_hal_* functions.
|
|
|
|
#ifndef MICROPY_PY_UTIME_MP_HAL
|
|
|
|
#define MICROPY_PY_UTIME_MP_HAL (0)
|
|
|
|
#endif
|
|
|
|
|
2016-10-29 20:02:07 -04:00
|
|
|
// Period of values returned by utime.ticks_ms(), ticks_us(), ticks_cpu()
|
|
|
|
// functions. Should be power of two. All functions above use the same
|
|
|
|
// period, so if underlying hardware/API has different periods, the
|
|
|
|
// minimum of them should be used. The value below is the maximum value
|
|
|
|
// this parameter can take (corresponding to 30 bit tick values on 32-bit
|
|
|
|
// system).
|
|
|
|
#ifndef MICROPY_PY_UTIME_TICKS_PERIOD
|
|
|
|
#define MICROPY_PY_UTIME_TICKS_PERIOD (MP_SMALL_INT_POSITIVE_MASK + 1)
|
|
|
|
#endif
|
|
|
|
|
2016-04-22 18:52:33 -04:00
|
|
|
// Whether to provide "_thread" module
|
|
|
|
#ifndef MICROPY_PY_THREAD
|
|
|
|
#define MICROPY_PY_THREAD (0)
|
|
|
|
#endif
|
|
|
|
|
2016-05-26 06:42:53 -04:00
|
|
|
// Whether to make the VM/runtime thread-safe using a global lock
|
|
|
|
// If not enabled then thread safety must be provided at the Python level
|
|
|
|
#ifndef MICROPY_PY_THREAD_GIL
|
|
|
|
#define MICROPY_PY_THREAD_GIL (MICROPY_PY_THREAD)
|
|
|
|
#endif
|
|
|
|
|
2017-02-05 18:50:43 -05:00
|
|
|
// Number of VM jump-loops to do before releasing the GIL.
|
|
|
|
// Set this to 0 to disable the divisor.
|
|
|
|
#ifndef MICROPY_PY_THREAD_GIL_VM_DIVISOR
|
|
|
|
#define MICROPY_PY_THREAD_GIL_VM_DIVISOR (32)
|
|
|
|
#endif
|
|
|
|
|
2014-06-27 20:03:47 -04:00
|
|
|
// Extended modules
|
2014-08-08 15:51:40 -04:00
|
|
|
|
2014-06-27 20:03:47 -04:00
|
|
|
#ifndef MICROPY_PY_UCTYPES
|
|
|
|
#define MICROPY_PY_UCTYPES (0)
|
|
|
|
#endif
|
|
|
|
|
2018-10-06 16:34:58 -04:00
|
|
|
// Whether to provide SHORT, INT, LONG, etc. types in addition to
|
|
|
|
// exact-bitness types like INT16, INT32, etc.
|
|
|
|
#ifndef MICROPY_PY_UCTYPES_NATIVE_C_TYPES
|
|
|
|
#define MICROPY_PY_UCTYPES_NATIVE_C_TYPES (1)
|
|
|
|
#endif
|
|
|
|
|
2014-10-12 11:16:34 -04:00
|
|
|
#ifndef MICROPY_PY_UZLIB
|
|
|
|
#define MICROPY_PY_UZLIB (0)
|
|
|
|
#endif
|
|
|
|
|
2014-09-17 17:56:34 -04:00
|
|
|
#ifndef MICROPY_PY_UJSON
|
|
|
|
#define MICROPY_PY_UJSON (0)
|
|
|
|
#endif
|
|
|
|
|
2014-09-12 11:48:07 -04:00
|
|
|
#ifndef MICROPY_PY_URE
|
|
|
|
#define MICROPY_PY_URE (0)
|
|
|
|
#endif
|
|
|
|
|
2018-05-23 23:07:42 -04:00
|
|
|
#ifndef MICROPY_PY_URE_MATCH_GROUPS
|
|
|
|
#define MICROPY_PY_URE_MATCH_GROUPS (0)
|
|
|
|
#endif
|
|
|
|
|
2018-05-23 23:08:15 -04:00
|
|
|
#ifndef MICROPY_PY_URE_MATCH_SPAN_START_END
|
|
|
|
#define MICROPY_PY_URE_MATCH_SPAN_START_END (0)
|
|
|
|
#endif
|
|
|
|
|
2018-05-23 23:08:51 -04:00
|
|
|
#ifndef MICROPY_PY_URE_SUB
|
|
|
|
#define MICROPY_PY_URE_SUB (0)
|
|
|
|
#endif
|
|
|
|
|
2014-10-22 13:37:18 -04:00
|
|
|
#ifndef MICROPY_PY_UHEAPQ
|
|
|
|
#define MICROPY_PY_UHEAPQ (0)
|
|
|
|
#endif
|
|
|
|
|
2016-12-21 16:29:32 -05:00
|
|
|
// Optimized heap queue for relative timestamps
|
|
|
|
#ifndef MICROPY_PY_UTIMEQ
|
|
|
|
#define MICROPY_PY_UTIMEQ (0)
|
|
|
|
#endif
|
|
|
|
|
2014-11-21 18:19:13 -05:00
|
|
|
#ifndef MICROPY_PY_UHASHLIB
|
|
|
|
#define MICROPY_PY_UHASHLIB (0)
|
|
|
|
#endif
|
|
|
|
|
2018-08-19 04:58:22 -04:00
|
|
|
#ifndef MICROPY_PY_UHASHLIB_MD5
|
|
|
|
#define MICROPY_PY_UHASHLIB_MD5 (0)
|
|
|
|
#endif
|
|
|
|
|
2018-06-08 19:48:29 -04:00
|
|
|
#ifndef MICROPY_PY_UHASHLIB_SHA1
|
|
|
|
#define MICROPY_PY_UHASHLIB_SHA1 (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MICROPY_PY_UHASHLIB_SHA256
|
|
|
|
#define MICROPY_PY_UHASHLIB_SHA256 (1)
|
|
|
|
#endif
|
|
|
|
|
2018-01-07 08:13:56 -05:00
|
|
|
#ifndef MICROPY_PY_UCRYPTOLIB
|
|
|
|
#define MICROPY_PY_UCRYPTOLIB (0)
|
|
|
|
#endif
|
|
|
|
|
2019-04-23 05:39:05 -04:00
|
|
|
// Depends on MICROPY_PY_UCRYPTOLIB
|
|
|
|
#ifndef MICROPY_PY_UCRYPTOLIB_CTR
|
|
|
|
#define MICROPY_PY_UCRYPTOLIB_CTR (0)
|
|
|
|
#endif
|
|
|
|
|
2018-06-15 10:07:47 -04:00
|
|
|
#ifndef MICROPY_PY_UCRYPTOLIB_CONSTS
|
|
|
|
#define MICROPY_PY_UCRYPTOLIB_CONSTS (0)
|
|
|
|
#endif
|
|
|
|
|
2014-11-28 23:19:30 -05:00
|
|
|
#ifndef MICROPY_PY_UBINASCII
|
|
|
|
#define MICROPY_PY_UBINASCII (0)
|
|
|
|
#endif
|
|
|
|
|
2016-08-24 11:28:43 -04:00
|
|
|
// Depends on MICROPY_PY_UZLIB
|
|
|
|
#ifndef MICROPY_PY_UBINASCII_CRC32
|
|
|
|
#define MICROPY_PY_UBINASCII_CRC32 (0)
|
|
|
|
#endif
|
|
|
|
|
2016-01-17 05:10:28 -05:00
|
|
|
#ifndef MICROPY_PY_URANDOM
|
|
|
|
#define MICROPY_PY_URANDOM (0)
|
|
|
|
#endif
|
|
|
|
|
2016-01-22 11:19:32 -05:00
|
|
|
// Whether to include: randrange, randint, choice, random, uniform
|
|
|
|
#ifndef MICROPY_PY_URANDOM_EXTRA_FUNCS
|
|
|
|
#define MICROPY_PY_URANDOM_EXTRA_FUNCS (0)
|
|
|
|
#endif
|
|
|
|
|
2015-05-03 13:25:40 -04:00
|
|
|
#ifndef MICROPY_PY_MACHINE
|
|
|
|
#define MICROPY_PY_MACHINE (0)
|
|
|
|
#endif
|
|
|
|
|
2016-05-31 09:25:19 -04:00
|
|
|
// Whether to include: time_pulse_us
|
|
|
|
#ifndef MICROPY_PY_MACHINE_PULSE
|
|
|
|
#define MICROPY_PY_MACHINE_PULSE (0)
|
|
|
|
#endif
|
|
|
|
|
2016-04-12 08:42:35 -04:00
|
|
|
#ifndef MICROPY_PY_MACHINE_I2C
|
|
|
|
#define MICROPY_PY_MACHINE_I2C (0)
|
|
|
|
#endif
|
|
|
|
|
2016-09-01 01:07:20 -04:00
|
|
|
#ifndef MICROPY_PY_MACHINE_SPI
|
|
|
|
#define MICROPY_PY_MACHINE_SPI (0)
|
|
|
|
#endif
|
|
|
|
|
2015-10-06 11:10:00 -04:00
|
|
|
#ifndef MICROPY_PY_USSL
|
|
|
|
#define MICROPY_PY_USSL (0)
|
2017-10-27 00:17:35 -04:00
|
|
|
// Whether to add finaliser code to ussl objects
|
|
|
|
#define MICROPY_PY_USSL_FINALISER (0)
|
2015-10-06 11:10:00 -04:00
|
|
|
#endif
|
|
|
|
|
2019-02-10 15:35:18 -05:00
|
|
|
#ifndef MICROPY_PY_UWEBSOCKET
|
|
|
|
#define MICROPY_PY_UWEBSOCKET (0)
|
2016-03-24 13:14:12 -04:00
|
|
|
#endif
|
|
|
|
|
2016-04-08 06:08:37 -04:00
|
|
|
#ifndef MICROPY_PY_FRAMEBUF
|
|
|
|
#define MICROPY_PY_FRAMEBUF (0)
|
|
|
|
#endif
|
|
|
|
|
2016-07-02 07:57:42 -04:00
|
|
|
#ifndef MICROPY_PY_BTREE
|
|
|
|
#define MICROPY_PY_BTREE (0)
|
|
|
|
#endif
|
|
|
|
|
2014-05-21 15:32:59 -04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Hooks for a port to add builtins */
|
|
|
|
|
2019-02-03 14:24:16 -05:00
|
|
|
// Additional builtin function definitions - see modbuiltins.c:mp_module_builtins_globals_table for format.
|
2014-05-21 15:32:59 -04:00
|
|
|
#ifndef MICROPY_PORT_BUILTINS
|
|
|
|
#define MICROPY_PORT_BUILTINS
|
2014-02-14 05:02:34 -05:00
|
|
|
#endif
|
2014-03-25 10:18:18 -04:00
|
|
|
|
2019-02-03 14:24:16 -05:00
|
|
|
// Additional builtin module definitions - see objmodule.c:mp_builtin_module_table for format.
|
2014-05-21 15:32:59 -04:00
|
|
|
#ifndef MICROPY_PORT_BUILTIN_MODULES
|
|
|
|
#define MICROPY_PORT_BUILTIN_MODULES
|
2014-03-25 10:18:18 -04:00
|
|
|
#endif
|
|
|
|
|
2019-02-03 14:24:16 -05:00
|
|
|
// Any module weak links - see objmodule.c:mp_builtin_module_weak_links_table.
|
2014-10-12 06:46:04 -04:00
|
|
|
#ifndef MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS
|
|
|
|
#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS
|
|
|
|
#endif
|
|
|
|
|
2014-04-10 17:42:11 -04:00
|
|
|
// Additional constant definitions for the compiler - see compile.c:mp_constants_table.
|
2014-05-21 15:32:59 -04:00
|
|
|
#ifndef MICROPY_PORT_CONSTANTS
|
|
|
|
#define MICROPY_PORT_CONSTANTS
|
2014-04-10 17:42:11 -04:00
|
|
|
#endif
|
|
|
|
|
2015-01-01 18:30:53 -05:00
|
|
|
// Any root pointers for GC scanning - see mpstate.c
|
|
|
|
#ifndef MICROPY_PORT_ROOT_POINTERS
|
|
|
|
#define MICROPY_PORT_ROOT_POINTERS
|
|
|
|
#endif
|
|
|
|
|
2014-01-07 09:54:15 -05:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Miscellaneous settings */
|
|
|
|
|
2015-02-08 08:42:00 -05:00
|
|
|
// All uPy objects in ROM must be aligned on at least a 4 byte boundary
|
|
|
|
// so that the small-int/qstr/pointer distinction can be made. For machines
|
|
|
|
// that don't do this (eg 16-bit CPU), define the following macro to something
|
|
|
|
// like __attribute__((aligned(4))).
|
|
|
|
#ifndef MICROPY_OBJ_BASE_ALIGNMENT
|
|
|
|
#define MICROPY_OBJ_BASE_ALIGNMENT
|
|
|
|
#endif
|
|
|
|
|
2014-07-02 02:46:53 -04:00
|
|
|
// On embedded platforms, these will typically enable/disable irqs.
|
|
|
|
#ifndef MICROPY_BEGIN_ATOMIC_SECTION
|
2014-10-15 13:33:24 -04:00
|
|
|
#define MICROPY_BEGIN_ATOMIC_SECTION() (0)
|
2014-07-02 02:46:53 -04:00
|
|
|
#endif
|
|
|
|
#ifndef MICROPY_END_ATOMIC_SECTION
|
2014-10-15 13:33:24 -04:00
|
|
|
#define MICROPY_END_ATOMIC_SECTION(state) (void)(state)
|
2014-07-02 02:46:53 -04:00
|
|
|
#endif
|
|
|
|
|
2014-02-12 11:15:40 -05:00
|
|
|
// Allow to override static modifier for global objects, e.g. to use with
|
|
|
|
// object code analysis tools which don't support static symbols.
|
|
|
|
#ifndef STATIC
|
|
|
|
#define STATIC static
|
|
|
|
#endif
|
|
|
|
|
2017-03-31 20:39:38 -04:00
|
|
|
// Number of bytes in a word
|
|
|
|
#ifndef BYTES_PER_WORD
|
|
|
|
#define BYTES_PER_WORD (sizeof(mp_uint_t))
|
|
|
|
#endif
|
|
|
|
|
2014-01-12 09:10:19 -05:00
|
|
|
#define BITS_PER_BYTE (8)
|
|
|
|
#define BITS_PER_WORD (BITS_PER_BYTE * BYTES_PER_WORD)
|
2014-07-03 08:25:24 -04:00
|
|
|
// mp_int_t value with most significant bit set
|
|
|
|
#define WORD_MSBIT_HIGH (((mp_uint_t)1) << (BYTES_PER_WORD * 8 - 1))
|
2014-01-12 09:10:19 -05:00
|
|
|
|
2014-10-06 09:44:59 -04:00
|
|
|
// Make sure both MP_ENDIANNESS_LITTLE and MP_ENDIANNESS_BIG are
|
|
|
|
// defined and that they are the opposite of each other.
|
|
|
|
#if defined(MP_ENDIANNESS_LITTLE)
|
|
|
|
#define MP_ENDIANNESS_BIG (!MP_ENDIANNESS_LITTLE)
|
|
|
|
#elif defined(MP_ENDIANNESS_BIG)
|
|
|
|
#define MP_ENDIANNESS_LITTLE (!MP_ENDIANNESS_BIG)
|
|
|
|
#else
|
2018-05-06 23:36:52 -04:00
|
|
|
// Endianness not defined by port so try to autodetect it.
|
2014-10-06 09:44:59 -04:00
|
|
|
#if defined(__BYTE_ORDER__)
|
|
|
|
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
|
|
|
#define MP_ENDIANNESS_LITTLE (1)
|
2018-05-06 23:36:52 -04:00
|
|
|
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
2014-10-06 09:44:59 -04:00
|
|
|
#define MP_ENDIANNESS_LITTLE (0)
|
|
|
|
#endif
|
|
|
|
#else
|
2015-05-30 18:12:30 -04:00
|
|
|
#include <endian.h>
|
|
|
|
#if defined(__BYTE_ORDER)
|
|
|
|
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
|
|
|
#define MP_ENDIANNESS_LITTLE (1)
|
2018-05-06 23:36:52 -04:00
|
|
|
#elif __BYTE_ORDER == __BIG_ENDIAN
|
2015-05-30 18:12:30 -04:00
|
|
|
#define MP_ENDIANNESS_LITTLE (0)
|
|
|
|
#endif
|
|
|
|
#endif
|
2014-10-06 09:44:59 -04:00
|
|
|
#endif
|
2018-05-06 23:36:52 -04:00
|
|
|
#ifndef MP_ENDIANNESS_LITTLE
|
|
|
|
#error endianness not defined and cannot detect it
|
|
|
|
#endif
|
2014-10-06 09:44:59 -04:00
|
|
|
#define MP_ENDIANNESS_BIG (!MP_ENDIANNESS_LITTLE)
|
2014-04-13 21:39:56 -04:00
|
|
|
#endif
|
2014-04-10 20:44:00 -04:00
|
|
|
|
2014-08-24 11:28:17 -04:00
|
|
|
// Make a pointer to RAM callable (eg set lower bit for Thumb code)
|
|
|
|
// (This scheme won't work if we want to mix Thumb and normal ARM code.)
|
|
|
|
#ifndef MICROPY_MAKE_POINTER_CALLABLE
|
|
|
|
#define MICROPY_MAKE_POINTER_CALLABLE(p) (p)
|
|
|
|
#endif
|
|
|
|
|
2015-04-09 18:56:15 -04:00
|
|
|
// If these MP_PLAT_*_EXEC macros are overridden then the memory allocated by them
|
2015-01-13 19:11:09 -05:00
|
|
|
// must be somehow reachable for marking by the GC, since the native code
|
|
|
|
// generators store pointers to GC managed memory in the code.
|
2014-09-03 10:59:33 -04:00
|
|
|
#ifndef MP_PLAT_ALLOC_EXEC
|
2015-04-09 11:29:54 -04:00
|
|
|
#define MP_PLAT_ALLOC_EXEC(min_size, ptr, size) do { *ptr = m_new(byte, min_size); *size = min_size; } while (0)
|
2014-09-03 10:59:33 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MP_PLAT_FREE_EXEC
|
|
|
|
#define MP_PLAT_FREE_EXEC(ptr, size) m_del(byte, ptr, size)
|
|
|
|
#endif
|
|
|
|
|
2015-04-09 18:56:15 -04:00
|
|
|
// This macro is used to do all output (except when MICROPY_PY_IO is defined)
|
|
|
|
#ifndef MP_PLAT_PRINT_STRN
|
2015-10-14 19:05:55 -04:00
|
|
|
#define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
|
2015-04-09 18:56:15 -04:00
|
|
|
#endif
|
|
|
|
|
2014-09-06 12:17:23 -04:00
|
|
|
#ifndef MP_SSIZE_MAX
|
|
|
|
#define MP_SSIZE_MAX SSIZE_MAX
|
|
|
|
#endif
|
|
|
|
|
2014-07-03 08:25:24 -04:00
|
|
|
// printf format spec to use for mp_int_t and friends
|
2014-01-07 09:54:15 -05:00
|
|
|
#ifndef INT_FMT
|
2015-11-20 09:59:06 -05:00
|
|
|
#if defined(__LP64__)
|
2014-07-03 08:25:24 -04:00
|
|
|
// Archs where mp_int_t == long, long != int
|
2014-01-07 09:54:15 -05:00
|
|
|
#define UINT_FMT "%lu"
|
|
|
|
#define INT_FMT "%ld"
|
2015-11-20 09:59:06 -05:00
|
|
|
#elif defined(_WIN64)
|
2015-12-18 04:20:33 -05:00
|
|
|
#define UINT_FMT "%llu"
|
|
|
|
#define INT_FMT "%lld"
|
2014-01-07 09:54:15 -05:00
|
|
|
#else
|
2014-07-03 08:25:24 -04:00
|
|
|
// Archs where mp_int_t == int
|
2014-01-07 09:54:15 -05:00
|
|
|
#define UINT_FMT "%u"
|
|
|
|
#define INT_FMT "%d"
|
|
|
|
#endif
|
|
|
|
#endif //INT_FMT
|
2014-04-29 22:35:18 -04:00
|
|
|
|
|
|
|
// Modifier for function which doesn't return
|
2014-05-05 06:18:27 -04:00
|
|
|
#ifndef NORETURN
|
2014-04-29 22:35:18 -04:00
|
|
|
#define NORETURN __attribute__((noreturn))
|
2014-05-05 06:18:27 -04:00
|
|
|
#endif
|
2014-06-21 11:24:55 -04:00
|
|
|
|
|
|
|
// Modifier for weak functions
|
|
|
|
#ifndef MP_WEAK
|
|
|
|
#define MP_WEAK __attribute__((weak))
|
|
|
|
#endif
|
2014-12-28 17:51:06 -05:00
|
|
|
|
2016-06-15 16:52:00 -04:00
|
|
|
// Modifier for functions which should be never inlined
|
|
|
|
#ifndef MP_NOINLINE
|
|
|
|
#define MP_NOINLINE __attribute__((noinline))
|
|
|
|
#endif
|
|
|
|
|
2016-08-07 15:36:05 -04:00
|
|
|
// Modifier for functions which should be always inlined
|
|
|
|
#ifndef MP_ALWAYSINLINE
|
|
|
|
#define MP_ALWAYSINLINE __attribute__((always_inline))
|
|
|
|
#endif
|
|
|
|
|
2014-12-28 17:51:06 -05:00
|
|
|
// Condition is likely to be true, to help branch prediction
|
|
|
|
#ifndef MP_LIKELY
|
|
|
|
#define MP_LIKELY(x) __builtin_expect((x), 1)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Condition is likely to be false, to help branch prediction
|
|
|
|
#ifndef MP_UNLIKELY
|
|
|
|
#define MP_UNLIKELY(x) __builtin_expect((x), 0)
|
|
|
|
#endif
|
2014-12-28 20:02:19 -05:00
|
|
|
|
2017-11-08 12:45:18 -05:00
|
|
|
#ifndef MP_HTOBE16
|
|
|
|
#if MP_ENDIANNESS_LITTLE
|
|
|
|
# define MP_HTOBE16(x) ((uint16_t)( (((x) & 0xff) << 8) | (((x) >> 8) & 0xff) ))
|
|
|
|
# define MP_BE16TOH(x) MP_HTOBE16(x)
|
|
|
|
#else
|
|
|
|
# define MP_HTOBE16(x) (x)
|
|
|
|
# define MP_BE16TOH(x) (x)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MP_HTOBE32
|
|
|
|
#if MP_ENDIANNESS_LITTLE
|
|
|
|
# define MP_HTOBE32(x) ((uint32_t)( (((x) & 0xff) << 24) | (((x) & 0xff00) << 8) | (((x) >> 8) & 0xff00) | (((x) >> 24) & 0xff) ))
|
|
|
|
# define MP_BE32TOH(x) MP_HTOBE32(x)
|
|
|
|
#else
|
|
|
|
# define MP_HTOBE32(x) (x)
|
|
|
|
# define MP_BE32TOH(x) (x)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2018-12-21 06:20:55 -05:00
|
|
|
// Warning categories are by default implemented as strings, though
|
|
|
|
// hook is left for a port to define them as something else.
|
|
|
|
#if MICROPY_WARNINGS_CATEGORY
|
|
|
|
# ifndef MP_WARN_CAT
|
|
|
|
# define MP_WARN_CAT(x) #x
|
|
|
|
# endif
|
|
|
|
#else
|
|
|
|
# undef MP_WARN_CAT
|
|
|
|
# define MP_WARN_CAT(x) (NULL)
|
|
|
|
#endif
|
|
|
|
|
all: Unify header guard usage.
The code conventions suggest using header guards, but do not define how
those should look like and instead point to existing files. However, not
all existing files follow the same scheme, sometimes omitting header guards
altogether, sometimes using non-standard names, making it easy to
accidentally pick a "wrong" example.
This commit ensures that all header files of the MicroPython project (that
were not simply copied from somewhere else) follow the same pattern, that
was already present in the majority of files, especially in the py folder.
The rules are as follows.
Naming convention:
* start with the words MICROPY_INCLUDED
* contain the full path to the file
* replace special characters with _
In addition, there are no empty lines before #ifndef, between #ifndef and
one empty line before #endif. #endif is followed by a comment containing
the name of the guard macro.
py/grammar.h cannot use header guards by design, since it has to be
included multiple times in a single C file. Several other files also do not
need header guards as they are only used internally and guaranteed to be
included only once:
* MICROPY_MPHALPORT_H
* mpconfigboard.h
* mpconfigport.h
* mpthreadport.h
* pin_defs_*.h
* qstrdefs*.h
2017-06-29 17:14:58 -04:00
|
|
|
#endif // MICROPY_INCLUDED_PY_MPCONFIG_H
|