blob: 854188b66b585863b95fc41a7f203b5fdb45d686 [file] [log] [blame]
Damien George04b91472014-05-03 23:27:38 +01001/*
Damien Georgec408ed92017-06-26 12:29:20 +10002 * This file is part of the MicroPython project, http://micropython.org/
Damien George04b91472014-05-03 23:27:38 +01003 *
4 * The MIT License (MIT)
5 *
6 * Copyright (c) 2013, 2014 Damien P. George
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 */
Alexander Steffen299bc622017-06-29 23:14:58 +020026#ifndef MICROPY_INCLUDED_PY_MPCONFIG_H
27#define MICROPY_INCLUDED_PY_MPCONFIG_H
Damien George04b91472014-05-03 23:27:38 +010028
Damien George7cd59c52018-12-15 15:13:33 +110029// Current version of MicroPython
Damien Georgeaba83e62019-01-26 00:44:35 +110030#define MICROPY_VERSION_MAJOR 1
Damien Georgeb0932fc2020-09-02 12:01:26 +100031#define MICROPY_VERSION_MINOR 13
Damien George3e25d612019-01-26 00:56:48 +110032#define MICROPY_VERSION_MICRO 0
Damien George7cd59c52018-12-15 15:13:33 +110033
34// Combined version as a 32-bit number for convenience
35#define MICROPY_VERSION ( \
36 MICROPY_VERSION_MAJOR << 16 \
Damien George69661f32020-02-27 15:36:53 +110037 | MICROPY_VERSION_MINOR << 8 \
38 | MICROPY_VERSION_MICRO)
Damien George7cd59c52018-12-15 15:13:33 +110039
40// String version
41#define MICROPY_VERSION_STRING \
42 MP_STRINGIFY(MICROPY_VERSION_MAJOR) "." \
43 MP_STRINGIFY(MICROPY_VERSION_MINOR) "." \
44 MP_STRINGIFY(MICROPY_VERSION_MICRO)
45
Paul Sokolovskyb372bfc2014-01-03 17:15:53 +020046// This file contains default configuration settings for MicroPython.
Paul Sokolovskyb1422de2014-10-29 04:08:49 +020047// You can override any of the options below using mpconfigport.h file
48// located in a directory of your port.
Paul Sokolovskyb372bfc2014-01-03 17:15:53 +020049
Paul Sokolovskyb1422de2014-10-29 04:08:49 +020050// mpconfigport.h is a file containing configuration settings for a
51// particular port. mpconfigport.h is actually a default name for
Ville Skyttäca16c382017-05-29 10:08:14 +030052// such config, and it can be overridden using MP_CONFIGFILE preprocessor
Paul Sokolovskyb1422de2014-10-29 04:08:49 +020053// define (you can do that by passing CFLAGS_EXTRA='-DMP_CONFIGFILE="<file.h>"'
54// argument to make when using standard MicroPython makefiles).
55// This is useful to have more than one config per port, for example,
56// release vs debug configs, etc. Note that if you switch from one config
57// to another, you must rebuild from scratch using "-B" switch to make.
58
59#ifdef MP_CONFIGFILE
60#include MP_CONFIGFILE
61#else
Damien George8340c482014-06-12 19:50:17 +010062#include <mpconfigport.h>
Paul Sokolovskyb1422de2014-10-29 04:08:49 +020063#endif
Paul Sokolovskyb372bfc2014-01-03 17:15:53 +020064
Damien George136f6752014-01-07 14:54:15 +000065// Any options not explicitly set in mpconfigport.h will get default
66// values below.
67
68/*****************************************************************************/
Damien George567184e2015-03-29 14:05:46 +010069/* Object representation */
70
Damien Georgec408ed92017-06-26 12:29:20 +100071// A MicroPython object is a machine word having the following form:
Damien George567184e2015-03-29 14:05:46 +010072// - xxxx...xxx1 : a small int, bits 1 and above are the value
Damien George6f0c83f2020-01-08 23:58:40 +110073// - xxxx...x010 : a qstr, bits 3 and above are the value
74// - xxxx...x110 : an immediate object, bits 3 and above are the value
Damien George567184e2015-03-29 14:05:46 +010075// - xxxx...xx00 : a pointer to an mp_obj_base_t (unless a fake object)
76#define MICROPY_OBJ_REPR_A (0)
77
Damien Georgec408ed92017-06-26 12:29:20 +100078// A MicroPython object is a machine word having the following form:
Damien George567184e2015-03-29 14:05:46 +010079// - xxxx...xx01 : a small int, bits 2 and above are the value
Damien George6f0c83f2020-01-08 23:58:40 +110080// - xxxx...x011 : a qstr, bits 3 and above are the value
81// - xxxx...x111 : an immediate object, bits 3 and above are the value
Damien George567184e2015-03-29 14:05:46 +010082// - xxxx...xxx0 : a pointer to an mp_obj_base_t (unless a fake object)
83#define MICROPY_OBJ_REPR_B (1)
84
Damien George8b8d1892015-11-06 23:25:10 +000085// A MicroPython object is a machine word having the following form (called R):
Damien George183edef2015-10-17 23:20:57 +010086// - iiiiiiii iiiiiiii iiiiiiii iiiiiii1 small int with 31-bit signed value
Damien George6f0c83f2020-01-08 23:58:40 +110087// - 01111111 1qqqqqqq qqqqqqqq qqqq0110 str with 19-bit qstr value
88// - 01111111 10000000 00000000 ssss1110 immediate object with 4-bit value
Damien George183edef2015-10-17 23:20:57 +010089// - s1111111 10000000 00000000 00000010 +/- inf
90// - s1111111 1xxxxxxx xxxxxxxx xxxxx010 nan, x != 0
91// - seeeeeee efffffff ffffffff ffffff10 30-bit fp, e != 0xff
92// - pppppppp pppppppp pppppppp pppppp00 ptr (4 byte alignment)
Damien George6f0c83f2020-01-08 23:58:40 +110093// Str, immediate and float stored as O = R + 0x80800000, retrieved as R = O - 0x80800000.
94// This makes strs/immediates easier to encode/decode as they have zeros in the top 9 bits.
Damien George183edef2015-10-17 23:20:57 +010095// This scheme only works with 32-bit word size and float enabled.
96#define MICROPY_OBJ_REPR_C (2)
97
Damien Georgeb8cfb0d2015-11-27 17:09:11 +000098// A MicroPython object is a 64-bit word having the following form (called R):
99// - seeeeeee eeeeffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff 64-bit fp, e != 0x7ff
100// - s1111111 11110000 00000000 00000000 00000000 00000000 00000000 00000000 +/- inf
101// - 01111111 11111000 00000000 00000000 00000000 00000000 00000000 00000000 normalised nan
Damien George2759bec2017-12-11 22:39:12 +1100102// - 01111111 11111101 iiiiiiii iiiiiiii iiiiiiii iiiiiiii iiiiiiii iiiiiii1 small int
Damien Georgeb8cfb0d2015-11-27 17:09:11 +0000103// - 01111111 11111110 00000000 00000000 qqqqqqqq qqqqqqqq qqqqqqqq qqqqqqq1 str
Damien George6f0c83f2020-01-08 23:58:40 +1100104// - 01111111 11111111 ss000000 00000000 00000000 00000000 00000000 00000000 immediate object
Damien Georgeb8cfb0d2015-11-27 17:09:11 +0000105// - 01111111 11111100 00000000 00000000 pppppppp pppppppp pppppppp pppppp00 ptr (4 byte alignment)
106// Stored as O = R + 0x8004000000000000, retrieved as R = O - 0x8004000000000000.
107// This makes pointers have all zeros in the top 32 bits.
108// Small-ints and strs have 1 as LSB to make sure they don't look like pointers
109// to the garbage collector.
110#define MICROPY_OBJ_REPR_D (3)
111
Damien George567184e2015-03-29 14:05:46 +0100112#ifndef MICROPY_OBJ_REPR
113#define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_A)
114#endif
115
Damien Georged96cfd12020-01-09 00:00:27 +1100116// Whether to encode None/False/True as immediate objects instead of pointers to
117// real objects. Reduces code size by a decent amount without hurting
118// performance, for all representations except D on some architectures.
119#ifndef MICROPY_OBJ_IMMEDIATE_OBJS
120#define MICROPY_OBJ_IMMEDIATE_OBJS (MICROPY_OBJ_REPR != MICROPY_OBJ_REPR_D)
121#endif
122
Damien George567184e2015-03-29 14:05:46 +0100123/*****************************************************************************/
Damien George66e18f02014-05-05 13:19:03 +0100124/* Memory allocation policy */
125
Paul Sokolovsky75feece2015-12-03 01:40:52 +0200126// Number of bytes in memory allocation/GC block. Any size allocated will be
127// rounded up to be multiples of this.
Paul Sokolovskyb4eccfd2015-12-03 01:57:50 +0200128#ifndef MICROPY_BYTES_PER_GC_BLOCK
Paul Sokolovsky75feece2015-12-03 01:40:52 +0200129#define MICROPY_BYTES_PER_GC_BLOCK (4 * BYTES_PER_WORD)
Paul Sokolovskyb4eccfd2015-12-03 01:57:50 +0200130#endif
Paul Sokolovsky75feece2015-12-03 01:40:52 +0200131
Damien Georgefd40a9c2015-01-01 22:04:46 +0000132// Number of words allocated (in BSS) to the GC stack (minimum is 1)
133#ifndef MICROPY_ALLOC_GC_STACK_SIZE
134#define MICROPY_ALLOC_GC_STACK_SIZE (64)
135#endif
136
Ayke van Laethem31cf5282018-02-23 18:59:31 +0100137// The C-type to use for entries in the GC stack. By default it allows the
138// heap to be as large as the address space, but the bit-width of this type can
139// be reduced to save memory when the heap is small enough. The type must be
140// big enough to index all blocks in the heap, which is set by
141// heap-size-in-bytes / MICROPY_BYTES_PER_GC_BLOCK.
142#ifndef MICROPY_GC_STACK_ENTRY_TYPE
143#define MICROPY_GC_STACK_ENTRY_TYPE size_t
144#endif
145
Damien George5ffe1d82016-08-26 15:35:26 +1000146// Be conservative and always clear to zero newly (re)allocated memory in the GC.
147// This helps eliminate stray pointers that hold on to memory that's no longer
148// used. It decreases performance due to unnecessary memory clearing.
Colin Hogben828df542016-10-31 14:52:11 +0000149// A memory manager which always clears memory can set this to 0.
Damien George5ffe1d82016-08-26 15:35:26 +1000150// TODO Do analysis to understand why some memory is not properly cleared and
151// find a more efficient way to clear it.
152#ifndef MICROPY_GC_CONSERVATIVE_CLEAR
Colin Hogben828df542016-10-31 14:52:11 +0000153#define MICROPY_GC_CONSERVATIVE_CLEAR (MICROPY_ENABLE_GC)
Damien George5ffe1d82016-08-26 15:35:26 +1000154#endif
155
Paul Sokolovsky93e353e2016-07-21 00:37:30 +0300156// Support automatic GC when reaching allocation threshold,
157// configurable by gc.threshold().
158#ifndef MICROPY_GC_ALLOC_THRESHOLD
159#define MICROPY_GC_ALLOC_THRESHOLD (1)
160#endif
161
Damien Georgeade9a052015-06-13 21:53:22 +0100162// Number of bytes to allocate initially when creating new chunks to store
163// interned string data. Smaller numbers lead to more chunks being needed
164// and more wastage at the end of the chunk. Larger numbers lead to wasted
165// space at the end when no more strings need interning.
166#ifndef MICROPY_ALLOC_QSTR_CHUNK_INIT
167#define MICROPY_ALLOC_QSTR_CHUNK_INIT (128)
168#endif
169
Damien Georgee1199ec2014-05-10 17:48:01 +0100170// Initial amount for lexer indentation level
Damien George58ebde42014-05-21 20:32:59 +0100171#ifndef MICROPY_ALLOC_LEXER_INDENT_INIT
172#define MICROPY_ALLOC_LEXER_INDENT_INIT (10)
Damien Georgee1199ec2014-05-10 17:48:01 +0100173#endif
174
175// Increment for lexer indentation level
Damien George58ebde42014-05-21 20:32:59 +0100176#ifndef MICROPY_ALLOC_LEXEL_INDENT_INC
177#define MICROPY_ALLOC_LEXEL_INDENT_INC (8)
Damien Georgee1199ec2014-05-10 17:48:01 +0100178#endif
179
Damien George66e18f02014-05-05 13:19:03 +0100180// Initial amount for parse rule stack
Damien George58ebde42014-05-21 20:32:59 +0100181#ifndef MICROPY_ALLOC_PARSE_RULE_INIT
182#define MICROPY_ALLOC_PARSE_RULE_INIT (64)
Damien George66e18f02014-05-05 13:19:03 +0100183#endif
184
185// Increment for parse rule stack
Damien George58ebde42014-05-21 20:32:59 +0100186#ifndef MICROPY_ALLOC_PARSE_RULE_INC
187#define MICROPY_ALLOC_PARSE_RULE_INC (16)
Damien George66e18f02014-05-05 13:19:03 +0100188#endif
189
190// Initial amount for parse result stack
Damien George58ebde42014-05-21 20:32:59 +0100191#ifndef MICROPY_ALLOC_PARSE_RESULT_INIT
192#define MICROPY_ALLOC_PARSE_RESULT_INIT (32)
Damien George66e18f02014-05-05 13:19:03 +0100193#endif
194
195// Increment for parse result stack
Damien George58ebde42014-05-21 20:32:59 +0100196#ifndef MICROPY_ALLOC_PARSE_RESULT_INC
197#define MICROPY_ALLOC_PARSE_RESULT_INC (16)
Damien George66e18f02014-05-05 13:19:03 +0100198#endif
199
Damien George5042bce2014-05-25 22:06:06 +0100200// Strings this length or less will be interned by the parser
201#ifndef MICROPY_ALLOC_PARSE_INTERN_STRING_LEN
202#define MICROPY_ALLOC_PARSE_INTERN_STRING_LEN (10)
203#endif
204
Damien George58e0f4a2015-09-23 10:50:43 +0100205// Number of bytes to allocate initially when creating new chunks to store
206// parse nodes. Small leads to fragmentation, large leads to excess use.
207#ifndef MICROPY_ALLOC_PARSE_CHUNK_INIT
208#define MICROPY_ALLOC_PARSE_CHUNK_INIT (128)
209#endif
210
Damien George66e18f02014-05-05 13:19:03 +0100211// Initial amount for ids in a scope
Damien George58ebde42014-05-21 20:32:59 +0100212#ifndef MICROPY_ALLOC_SCOPE_ID_INIT
213#define MICROPY_ALLOC_SCOPE_ID_INIT (4)
Damien George66e18f02014-05-05 13:19:03 +0100214#endif
215
216// Increment for ids in a scope
Damien George58ebde42014-05-21 20:32:59 +0100217#ifndef MICROPY_ALLOC_SCOPE_ID_INC
218#define MICROPY_ALLOC_SCOPE_ID_INC (6)
219#endif
220
221// Maximum length of a path in the filesystem
222// So we can allocate a buffer on the stack for path manipulation in import
223#ifndef MICROPY_ALLOC_PATH_MAX
224#define MICROPY_ALLOC_PATH_MAX (512)
Damien George66e18f02014-05-05 13:19:03 +0100225#endif
226
Paul Sokolovsky346aacf2014-11-05 00:27:15 +0200227// Initial size of module dict
228#ifndef MICROPY_MODULE_DICT_SIZE
229#define MICROPY_MODULE_DICT_SIZE (1)
230#endif
231
Damien Georged8914522015-02-27 09:54:12 +0000232// Whether realloc/free should be passed allocated memory region size
233// You must enable this if MICROPY_MEM_STATS is enabled
234#ifndef MICROPY_MALLOC_USES_ALLOCATED_SIZE
235#define MICROPY_MALLOC_USES_ALLOCATED_SIZE (0)
236#endif
237
Damien George95836f82015-01-11 22:27:30 +0000238// Number of bytes used to store qstr length
239// Dictates hard limit on maximum Python identifier length, but 1 byte
240// (limit of 255 bytes in an identifier) should be enough for everyone
241#ifndef MICROPY_QSTR_BYTES_IN_LEN
242#define MICROPY_QSTR_BYTES_IN_LEN (1)
243#endif
244
Damien Georgec3bd9412015-07-20 11:03:13 +0000245// Number of bytes used to store qstr hash
246#ifndef MICROPY_QSTR_BYTES_IN_HASH
247#define MICROPY_QSTR_BYTES_IN_HASH (2)
248#endif
249
Paul Sokolovsky7f1c9812015-03-28 01:14:45 +0200250// Avoid using C stack when making Python function calls. C stack still
251// may be used if there's no free heap.
Paul Sokolovsky20397572015-03-28 01:14:44 +0200252#ifndef MICROPY_STACKLESS
253#define MICROPY_STACKLESS (0)
254#endif
255
Paul Sokolovsky7f1c9812015-03-28 01:14:45 +0200256// Never use C stack when making Python function calls. This may break
257// testsuite as will subtly change which exception is thrown in case
258// of too deep recursion and other similar cases.
259#ifndef MICROPY_STACKLESS_STRICT
260#define MICROPY_STACKLESS_STRICT (0)
261#endif
262
Paul Sokolovskyf32020e2015-11-25 23:22:31 +0200263// Don't use alloca calls. As alloca() is not part of ANSI C, this
264// workaround option is provided for compilers lacking this de-facto
265// standard function. The way it works is allocating from heap, and
266// relying on garbage collection to free it eventually. This is of
267// course much less optimal than real alloca().
268#if defined(MICROPY_NO_ALLOCA) && MICROPY_NO_ALLOCA
269#undef alloca
270#define alloca(x) m_malloc(x)
271#endif
272
Damien George66e18f02014-05-05 13:19:03 +0100273/*****************************************************************************/
Damien Georgec408ed92017-06-26 12:29:20 +1000274/* MicroPython emitters */
Damien George136f6752014-01-07 14:54:15 +0000275
Damien Georged8c834c2015-11-02 21:55:42 +0000276// Whether to support loading of persistent code
277#ifndef MICROPY_PERSISTENT_CODE_LOAD
278#define MICROPY_PERSISTENT_CODE_LOAD (0)
279#endif
280
281// Whether to support saving of persistent code
282#ifndef MICROPY_PERSISTENT_CODE_SAVE
283#define MICROPY_PERSISTENT_CODE_SAVE (0)
284#endif
285
Damien Georgec8e9c0d2015-11-02 17:27:18 +0000286// Whether generated code can persist independently of the VM/runtime instance
Damien Georged8c834c2015-11-02 21:55:42 +0000287// This is enabled automatically when needed by other features
Damien Georgec8e9c0d2015-11-02 17:27:18 +0000288#ifndef MICROPY_PERSISTENT_CODE
Damien George0a2e9652016-01-31 22:24:16 +0000289#define MICROPY_PERSISTENT_CODE (MICROPY_PERSISTENT_CODE_LOAD || MICROPY_PERSISTENT_CODE_SAVE || MICROPY_MODULE_FROZEN_MPY)
Damien Georgec8e9c0d2015-11-02 17:27:18 +0000290#endif
291
Damien George136f6752014-01-07 14:54:15 +0000292// Whether to emit x64 native code
293#ifndef MICROPY_EMIT_X64
294#define MICROPY_EMIT_X64 (0)
295#endif
296
Damien Georgec90f59e2014-09-06 23:06:36 +0100297// Whether to emit x86 native code
298#ifndef MICROPY_EMIT_X86
299#define MICROPY_EMIT_X86 (0)
300#endif
301
Damien George136f6752014-01-07 14:54:15 +0000302// Whether to emit thumb native code
303#ifndef MICROPY_EMIT_THUMB
304#define MICROPY_EMIT_THUMB (0)
305#endif
306
307// Whether to enable the thumb inline assembler
308#ifndef MICROPY_EMIT_INLINE_THUMB
309#define MICROPY_EMIT_INLINE_THUMB (0)
310#endif
311
Damien Georgee8135412015-10-16 22:08:57 +0100312// Whether to enable ARMv7-M instruction support in the Thumb2 inline assembler
313#ifndef MICROPY_EMIT_INLINE_THUMB_ARMV7M
314#define MICROPY_EMIT_INLINE_THUMB_ARMV7M (1)
315#endif
316
=50089722015-04-14 13:14:57 +0100317// Whether to enable float support in the Thumb2 inline assembler
318#ifndef MICROPY_EMIT_INLINE_THUMB_FLOAT
319#define MICROPY_EMIT_INLINE_THUMB_FLOAT (1)
320#endif
321
Fabian Vogtfe3d16e2014-08-16 22:55:53 +0200322// Whether to emit ARM native code
323#ifndef MICROPY_EMIT_ARM
324#define MICROPY_EMIT_ARM (0)
325#endif
326
Damien George8e5aced2016-12-09 16:39:39 +1100327// Whether to emit Xtensa native code
328#ifndef MICROPY_EMIT_XTENSA
329#define MICROPY_EMIT_XTENSA (0)
330#endif
331
Damien Georgef76b1bf2016-12-09 17:03:33 +1100332// Whether to enable the Xtensa inline assembler
333#ifndef MICROPY_EMIT_INLINE_XTENSA
334#define MICROPY_EMIT_INLINE_XTENSA (0)
335#endif
336
Damien George9adedce2019-09-13 13:15:12 +1000337// Whether to emit Xtensa-Windowed native code
338#ifndef MICROPY_EMIT_XTENSAWIN
339#define MICROPY_EMIT_XTENSAWIN (0)
340#endif
341
Damien George2ac4af62014-08-15 16:45:41 +0100342// Convenience definition for whether any native emitter is enabled
Damien George9adedce2019-09-13 13:15:12 +1000343#define MICROPY_EMIT_NATIVE (MICROPY_EMIT_X64 || MICROPY_EMIT_X86 || MICROPY_EMIT_THUMB || MICROPY_EMIT_ARM || MICROPY_EMIT_XTENSA || MICROPY_EMIT_XTENSAWIN)
344
345// Select prelude-as-bytes-object for certain emitters
346#define MICROPY_EMIT_NATIVE_PRELUDE_AS_BYTES_OBJ (MICROPY_EMIT_XTENSAWIN)
Damien George2ac4af62014-08-15 16:45:41 +0100347
Damien Georgead297a12016-12-09 13:17:49 +1100348// Convenience definition for whether any inline assembler emitter is enabled
Damien Georgef76b1bf2016-12-09 17:03:33 +1100349#define MICROPY_EMIT_INLINE_ASM (MICROPY_EMIT_INLINE_THUMB || MICROPY_EMIT_INLINE_XTENSA)
Damien Georgead297a12016-12-09 13:17:49 +1100350
Jun Wub152bbd2019-05-06 00:31:11 -0700351// Convenience definition for whether any native or inline assembler emitter is enabled
352#define MICROPY_EMIT_MACHINE_CODE (MICROPY_EMIT_NATIVE || MICROPY_EMIT_INLINE_ASM)
353
Damien George9883d8e2020-07-27 23:52:38 +1000354// Whether native relocatable code loaded from .mpy files is explicitly tracked
355// so that the GC cannot reclaim it. Needed on architectures that allocate
356// executable memory on the MicroPython heap and don't explicitly track this
357// data some other way.
358#ifndef MICROPY_PERSISTENT_CODE_TRACK_RELOC_CODE
359#if !MICROPY_EMIT_MACHINE_CODE || defined(MP_PLAT_ALLOC_EXEC) || defined(MP_PLAT_COMMIT_EXEC)
360#define MICROPY_PERSISTENT_CODE_TRACK_RELOC_CODE (0)
361#else
362#define MICROPY_PERSISTENT_CODE_TRACK_RELOC_CODE (1)
363#endif
364#endif
365
Damien George136f6752014-01-07 14:54:15 +0000366/*****************************************************************************/
Damien George58ebde42014-05-21 20:32:59 +0100367/* Compiler configuration */
368
Damien Georgedd5353a2015-12-18 12:35:44 +0000369// Whether to include the compiler
370#ifndef MICROPY_ENABLE_COMPILER
371#define MICROPY_ENABLE_COMPILER (1)
372#endif
373
Damien Georgeea235202016-02-11 22:30:53 +0000374// Whether the compiler is dynamically configurable (ie at runtime)
Damien Georgea4f1d822019-05-29 21:17:29 +1000375// This will disable the ability to execute native/viper code
Damien Georgeea235202016-02-11 22:30:53 +0000376#ifndef MICROPY_DYNAMIC_COMPILER
377#define MICROPY_DYNAMIC_COMPILER (0)
378#endif
379
380// Configure dynamic compiler macros
381#if MICROPY_DYNAMIC_COMPILER
382#define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE_DYNAMIC (mp_dynamic_compiler.opt_cache_map_lookup_in_bytecode)
383#define MICROPY_PY_BUILTINS_STR_UNICODE_DYNAMIC (mp_dynamic_compiler.py_builtins_str_unicode)
384#else
385#define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE_DYNAMIC MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE
386#define MICROPY_PY_BUILTINS_STR_UNICODE_DYNAMIC MICROPY_PY_BUILTINS_STR_UNICODE
387#endif
388
Damien George64f2b212015-10-08 14:58:15 +0100389// Whether to enable constant folding; eg 1+2 rewritten as 3
390#ifndef MICROPY_COMP_CONST_FOLDING
391#define MICROPY_COMP_CONST_FOLDING (1)
392#endif
393
Damien George07796932019-02-27 00:10:04 +1100394// Whether to enable optimisations for constant literals, eg OrderedDict
395#ifndef MICROPY_COMP_CONST_LITERAL
396#define MICROPY_COMP_CONST_LITERAL (1)
397#endif
398
Damien Georgeddd1e182015-01-10 14:07:24 +0000399// Whether to enable lookup of constants in modules; eg module.CONST
400#ifndef MICROPY_COMP_MODULE_CONST
401#define MICROPY_COMP_MODULE_CONST (0)
402#endif
403
Damien George58ebde42014-05-21 20:32:59 +0100404// Whether to enable constant optimisation; id = const(value)
405#ifndef MICROPY_COMP_CONST
406#define MICROPY_COMP_CONST (1)
407#endif
408
Damien George42e0c592015-03-14 13:11:35 +0000409// Whether to enable optimisation of: a, b = c, d
410// Costs 124 bytes (Thumb2)
411#ifndef MICROPY_COMP_DOUBLE_TUPLE_ASSIGN
412#define MICROPY_COMP_DOUBLE_TUPLE_ASSIGN (1)
413#endif
414
415// Whether to enable optimisation of: a, b, c = d, e, f
Damien George253f2bd2018-02-04 13:35:21 +1100416// Requires MICROPY_COMP_DOUBLE_TUPLE_ASSIGN and costs 68 bytes (Thumb2)
Damien George42e0c592015-03-14 13:11:35 +0000417#ifndef MICROPY_COMP_TRIPLE_TUPLE_ASSIGN
418#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (0)
419#endif
420
Damien Georgeae54fbf2017-04-22 14:58:01 +1000421// Whether to enable optimisation of: return a if b else c
422// Costs about 80 bytes (Thumb2) and saves 2 bytes of bytecode for each use
423#ifndef MICROPY_COMP_RETURN_IF_EXPR
424#define MICROPY_COMP_RETURN_IF_EXPR (0)
425#endif
426
Damien George58ebde42014-05-21 20:32:59 +0100427/*****************************************************************************/
Damien George136f6752014-01-07 14:54:15 +0000428/* Internal debugging stuff */
429
430// Whether to collect memory allocation stats
431#ifndef MICROPY_MEM_STATS
432#define MICROPY_MEM_STATS (0)
433#endif
434
Damien Georgeda2d2b62018-08-02 14:04:44 +1000435// The mp_print_t printer used for debugging output
436#ifndef MICROPY_DEBUG_PRINTER
437#define MICROPY_DEBUG_PRINTER (&mp_plat_print)
438#endif
439
Damien Georgecbd2f742014-01-19 11:48:48 +0000440// Whether to build functions that print debugging info:
Damien George3417bc22014-05-10 10:36:38 +0100441// mp_bytecode_print
Damien Georgecbd2f742014-01-19 11:48:48 +0000442// mp_parse_node_print
443#ifndef MICROPY_DEBUG_PRINTERS
444#define MICROPY_DEBUG_PRINTERS (0)
Damien Georged3ebe482014-01-07 15:20:33 +0000445#endif
446
Stefan Naumannace9fb52017-07-24 18:55:14 +0200447// Whether to enable all debugging outputs (it will be extremely verbose)
448#ifndef MICROPY_DEBUG_VERBOSE
449#define MICROPY_DEBUG_VERBOSE (0)
450#endif
451
Damien George02cc2882019-03-08 15:48:20 +1100452// Whether to enable debugging versions of MP_OBJ_NULL/STOP_ITERATION/SENTINEL
453#ifndef MICROPY_DEBUG_MP_OBJ_SENTINELS
454#define MICROPY_DEBUG_MP_OBJ_SENTINELS (0)
455#endif
456
Damien George843dcd42020-09-30 23:34:42 +1000457// Whether to print parse rule names (rather than integers) in mp_parse_node_print
458#ifndef MICROPY_DEBUG_PARSE_RULE_NAME
459#define MICROPY_DEBUG_PARSE_RULE_NAME (0)
460#endif
461
Damien George6d199342019-01-04 17:09:41 +1100462// Whether to enable a simple VM stack overflow check
463#ifndef MICROPY_DEBUG_VM_STACK_OVERFLOW
464#define MICROPY_DEBUG_VM_STACK_OVERFLOW (0)
465#endif
466
Damien George136f6752014-01-07 14:54:15 +0000467/*****************************************************************************/
Damien Georgeee3fd462014-05-24 23:03:12 +0100468/* Optimisations */
469
470// Whether to use computed gotos in the VM, or a switch
471// Computed gotos are roughly 10% faster, and increase VM code size by a little
Damien George44f0a4d2017-09-18 23:53:33 +1000472// Note: enabling this will use the gcc-specific extensions of ranged designated
473// initialisers and addresses of labels, which are not part of the C99 standard.
Damien Georgeee3fd462014-05-24 23:03:12 +0100474#ifndef MICROPY_OPT_COMPUTED_GOTO
475#define MICROPY_OPT_COMPUTED_GOTO (0)
476#endif
477
Damien George7ee91cf2015-01-06 12:51:39 +0000478// Whether to cache result of map lookups in LOAD_NAME, LOAD_GLOBAL, LOAD_ATTR,
479// STORE_ATTR bytecodes. Uses 1 byte extra RAM for each of these opcodes and
480// uses a bit of extra code ROM, but greatly improves lookup speed.
481#ifndef MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE
482#define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE (0)
483#endif
484
Doug Currie2e2e15c2016-01-30 22:35:58 -0500485// Whether to use fast versions of bitwise operations (and, or, xor) when the
486// arguments are both positive. Increases Thumb2 code size by about 250 bytes.
487#ifndef MICROPY_OPT_MPZ_BITWISE
488#define MICROPY_OPT_MPZ_BITWISE (0)
489#endif
490
Christopher Swenson8c656752018-08-27 10:32:21 +1000491
492// Whether math.factorial is large, fast and recursive (1) or small and slow (0).
493#ifndef MICROPY_OPT_MATH_FACTORIAL
494#define MICROPY_OPT_MATH_FACTORIAL (0)
495#endif
496
Damien Georgeee3fd462014-05-24 23:03:12 +0100497/*****************************************************************************/
498/* Python internal features */
Damien George136f6752014-01-07 14:54:15 +0000499
Damien George20993682018-02-20 18:00:44 +1100500// Whether to enable import of external modules
501// When disabled, only importing of built-in modules is supported
502// When enabled, a port must implement mp_import_stat (among other things)
503#ifndef MICROPY_ENABLE_EXTERNAL_IMPORT
504#define MICROPY_ENABLE_EXTERNAL_IMPORT (1)
505#endif
506
Damien George6b239c22016-11-16 16:04:57 +1100507// Whether to use the POSIX reader for importing files
508#ifndef MICROPY_READER_POSIX
509#define MICROPY_READER_POSIX (0)
510#endif
511
Damien Georgedcb9ea72017-01-27 15:10:09 +1100512// Whether to use the VFS reader for importing files
513#ifndef MICROPY_READER_VFS
514#define MICROPY_READER_VFS (0)
515#endif
516
Sean Burtone33bc592018-12-13 12:10:35 +0000517// Whether any readers have been defined
518#ifndef MICROPY_HAS_FILE_READER
519#define MICROPY_HAS_FILE_READER (MICROPY_READER_POSIX || MICROPY_READER_VFS)
520#endif
521
Damien George40d84302016-02-15 22:46:21 +0000522// Hook for the VM at the start of the opcode loop (can contain variable
523// definitions usable by the other hook functions)
524#ifndef MICROPY_VM_HOOK_INIT
525#define MICROPY_VM_HOOK_INIT
526#endif
527
528// Hook for the VM during the opcode loop (but only after jump opcodes)
529#ifndef MICROPY_VM_HOOK_LOOP
530#define MICROPY_VM_HOOK_LOOP
531#endif
532
533// Hook for the VM just before return opcode is finished being interpreted
534#ifndef MICROPY_VM_HOOK_RETURN
535#define MICROPY_VM_HOOK_RETURN
536#endif
537
Damien Georged3ebe482014-01-07 15:20:33 +0000538// Whether to include the garbage collector
539#ifndef MICROPY_ENABLE_GC
540#define MICROPY_ENABLE_GC (0)
541#endif
542
Damien George12bab722014-04-05 20:35:48 +0100543// Whether to enable finalisers in the garbage collector (ie call __del__)
Damien George7860c2a2014-11-05 21:16:41 +0000544#ifndef MICROPY_ENABLE_FINALISER
545#define MICROPY_ENABLE_FINALISER (0)
Damien George12bab722014-04-05 20:35:48 +0100546#endif
547
Damien George02d830c2017-11-26 23:28:40 +1100548// Whether to enable a separate allocator for the Python stack.
549// If enabled then the code must call mp_pystack_init before mp_init.
550#ifndef MICROPY_ENABLE_PYSTACK
551#define MICROPY_ENABLE_PYSTACK (0)
552#endif
553
554// Number of bytes that memory returned by mp_pystack_alloc will be aligned by.
555#ifndef MICROPY_PYSTACK_ALIGN
556#define MICROPY_PYSTACK_ALIGN (8)
557#endif
558
Paul Sokolovsky23668692014-06-25 03:03:34 +0300559// Whether to check C stack usage. C stack used for calling Python functions,
560// etc. Not checking means segfault on overflow.
561#ifndef MICROPY_STACK_CHECK
Damien George4a5895c2015-01-09 00:10:55 +0000562#define MICROPY_STACK_CHECK (0)
Paul Sokolovsky23668692014-06-25 03:03:34 +0300563#endif
564
Dave Hylands5b7fd202014-07-01 23:46:53 -0700565// Whether to have an emergency exception buffer
566#ifndef MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
567#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (0)
568#endif
569#if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
Damien George69661f32020-02-27 15:36:53 +1100570#ifndef MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE
571#define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (0) // 0 - implies dynamic allocation
572#endif
Dave Hylands5b7fd202014-07-01 23:46:53 -0700573#endif
574
Damien Georgebbb4b982017-04-10 17:19:36 +1000575// Whether to provide the mp_kbd_exception object, and micropython.kbd_intr function
Damien George7f1da0a2016-12-15 13:00:19 +1100576#ifndef MICROPY_KBD_EXCEPTION
577#define MICROPY_KBD_EXCEPTION (0)
578#endif
579
Paul Sokolovsky1c9210b2015-12-23 00:06:37 +0200580// Prefer to raise KeyboardInterrupt asynchronously (from signal or interrupt
581// handler) - if supported by a particular port.
582#ifndef MICROPY_ASYNC_KBD_INTR
583#define MICROPY_ASYNC_KBD_INTR (0)
584#endif
585
Damien George136f6752014-01-07 14:54:15 +0000586// Whether to include REPL helper function
Damien George58ebde42014-05-21 20:32:59 +0100587#ifndef MICROPY_HELPER_REPL
588#define MICROPY_HELPER_REPL (0)
Damien George136f6752014-01-07 14:54:15 +0000589#endif
590
Yonatan Goldschmidt61d2b402019-12-25 09:27:38 +0200591// Allow enabling debug prints after each REPL line
592#ifndef MICROPY_REPL_INFO
593#define MICROPY_REPL_INFO (0)
594#endif
595
Tom Soulanille7d588b02015-07-09 16:32:36 -0700596// Whether to include emacs-style readline behavior in REPL
597#ifndef MICROPY_REPL_EMACS_KEYS
Damien Georged8a7f8b2015-07-26 15:49:13 +0100598#define MICROPY_REPL_EMACS_KEYS (0)
Tom Soulanille7d588b02015-07-09 16:32:36 -0700599#endif
600
Yonatan Goldschmidt853aaa02019-12-14 23:42:03 +0200601// Whether to include emacs-style word movement/kill readline behavior in REPL.
602// This adds Alt+F, Alt+B, Alt+D and Alt+Backspace for forward-word, backward-word, forward-kill-word
603// and backward-kill-word, respectively.
604#ifndef MICROPY_REPL_EMACS_WORDS_MOVE
605#define MICROPY_REPL_EMACS_WORDS_MOVE (0)
606#endif
607
608// Whether to include extra convenience keys for word movement/kill in readline REPL.
609// This adds Ctrl+Right, Ctrl+Left and Ctrl+W for forward-word, backward-word and backward-kill-word
610// respectively. Ctrl+Delete is not implemented because it's a very different escape sequence.
611// Depends on MICROPY_REPL_EMACS_WORDS_MOVE.
612#ifndef MICROPY_REPL_EMACS_EXTRA_WORDS_MOVE
613#define MICROPY_REPL_EMACS_EXTRA_WORDS_MOVE (0)
614#endif
615
Damien George0af73012015-08-20 10:34:16 +0100616// Whether to implement auto-indent in REPL
617#ifndef MICROPY_REPL_AUTO_INDENT
618#define MICROPY_REPL_AUTO_INDENT (0)
619#endif
620
Paul Sokolovsky87bc8e22015-01-15 10:46:27 +0200621// Whether port requires event-driven REPL functions
622#ifndef MICROPY_REPL_EVENT_DRIVEN
623#define MICROPY_REPL_EVENT_DRIVEN (0)
624#endif
625
Damien Georged3ebe482014-01-07 15:20:33 +0000626// Whether to include lexer helper function for unix
Damien George58ebde42014-05-21 20:32:59 +0100627#ifndef MICROPY_HELPER_LEXER_UNIX
628#define MICROPY_HELPER_LEXER_UNIX (0)
Damien Georged3ebe482014-01-07 15:20:33 +0000629#endif
630
Paul Sokolovsky48b35722014-01-12 17:30:48 +0200631// Long int implementation
632#define MICROPY_LONGINT_IMPL_NONE (0)
633#define MICROPY_LONGINT_IMPL_LONGLONG (1)
Damien George438c88d2014-02-22 19:25:23 +0000634#define MICROPY_LONGINT_IMPL_MPZ (2)
Paul Sokolovsky48b35722014-01-12 17:30:48 +0200635
636#ifndef MICROPY_LONGINT_IMPL
637#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_NONE)
638#endif
639
640#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG
641typedef long long mp_longint_impl_t;
642#endif
643
Damien George62ad1892014-01-29 21:51:51 +0000644// Whether to include information in the byte code to determine source
645// line number (increases RAM usage, but doesn't slow byte code execution)
646#ifndef MICROPY_ENABLE_SOURCE_LINE
647#define MICROPY_ENABLE_SOURCE_LINE (0)
648#endif
649
Damien George1463c1f2014-04-25 23:52:57 +0100650// Whether to include doc strings (increases RAM usage)
651#ifndef MICROPY_ENABLE_DOC_STRING
652#define MICROPY_ENABLE_DOC_STRING (0)
653#endif
654
Damien George1e9a92f2014-11-06 17:36:16 +0000655// Exception messages are short static strings
Paul Sokolovsky1f85d622014-05-01 01:35:38 +0300656#define MICROPY_ERROR_REPORTING_TERSE (1)
657// Exception messages provide basic error details
658#define MICROPY_ERROR_REPORTING_NORMAL (2)
659// Exception messages provide full info, e.g. object names
660#define MICROPY_ERROR_REPORTING_DETAILED (3)
661
662#ifndef MICROPY_ERROR_REPORTING
663#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_NORMAL)
664#endif
665
Paul Sokolovsky8a8c1fc2015-01-01 09:29:28 +0200666// Whether issue warnings during compiling/execution
667#ifndef MICROPY_WARNINGS
668#define MICROPY_WARNINGS (0)
669#endif
670
Paul Sokolovsky2f5d1132018-12-21 14:20:55 +0300671// Whether to support warning categories
672#ifndef MICROPY_WARNINGS_CATEGORY
673#define MICROPY_WARNINGS_CATEGORY (0)
674#endif
675
David Lechner62849b72017-09-24 20:15:48 -0500676// This macro is used when printing runtime warnings and errors
677#ifndef MICROPY_ERROR_PRINTER
678#define MICROPY_ERROR_PRINTER (&mp_plat_print)
679#endif
680
Damien George0c36da02014-03-08 15:24:39 +0000681// Float and complex implementation
682#define MICROPY_FLOAT_IMPL_NONE (0)
683#define MICROPY_FLOAT_IMPL_FLOAT (1)
684#define MICROPY_FLOAT_IMPL_DOUBLE (2)
685
686#ifndef MICROPY_FLOAT_IMPL
687#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_NONE)
688#endif
689
690#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
Damien Georgefb510b32014-06-01 13:32:54 +0100691#define MICROPY_PY_BUILTINS_FLOAT (1)
Damien George561844f2016-11-03 12:33:01 +1100692#define MICROPY_FLOAT_CONST(x) x##F
Damien George0c36da02014-03-08 15:24:39 +0000693#define MICROPY_FLOAT_C_FUN(fun) fun##f
694typedef float mp_float_t;
695#elif MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE
Damien Georgefb510b32014-06-01 13:32:54 +0100696#define MICROPY_PY_BUILTINS_FLOAT (1)
Damien George561844f2016-11-03 12:33:01 +1100697#define MICROPY_FLOAT_CONST(x) x
Damien George0c36da02014-03-08 15:24:39 +0000698#define MICROPY_FLOAT_C_FUN(fun) fun
699typedef double mp_float_t;
700#else
Damien Georgefb510b32014-06-01 13:32:54 +0100701#define MICROPY_PY_BUILTINS_FLOAT (0)
Damien George136f6752014-01-07 14:54:15 +0000702#endif
703
Paul Sokolovsky3b6f7b92014-06-20 01:48:35 +0300704#ifndef MICROPY_PY_BUILTINS_COMPLEX
705#define MICROPY_PY_BUILTINS_COMPLEX (MICROPY_PY_BUILTINS_FLOAT)
706#endif
707
Damien Georgea73501b2017-04-06 17:27:33 +1000708// Whether to provide a high-quality hash for float and complex numbers.
709// Otherwise the default is a very simple but correct hashing function.
710#ifndef MICROPY_FLOAT_HIGH_QUALITY_HASH
711#define MICROPY_FLOAT_HIGH_QUALITY_HASH (0)
712#endif
713
Paul Sokolovskydcac8802014-01-16 19:19:50 +0200714// Enable features which improve CPython compatibility
715// but may lead to more code size/memory usage.
716// TODO: Originally intended as generic category to not
717// add bunch of once-off options. May need refactoring later
718#ifndef MICROPY_CPYTHON_COMPAT
719#define MICROPY_CPYTHON_COMPAT (1)
720#endif
721
Paul Sokolovsky9a973972017-04-02 21:20:07 +0300722// Perform full checks as done by CPython. Disabling this
723// may produce incorrect results, if incorrect data is fed,
724// but should not lead to MicroPython crashes or similar
725// grave issues (in other words, only user app should be,
726// affected, not system).
727#ifndef MICROPY_FULL_CHECKS
728#define MICROPY_FULL_CHECKS (1)
729#endif
730
Paul Sokolovsky0ef015b2014-05-07 02:23:46 +0300731// Whether POSIX-semantics non-blocking streams are supported
732#ifndef MICROPY_STREAMS_NON_BLOCK
733#define MICROPY_STREAMS_NON_BLOCK (0)
734#endif
735
Paul Sokolovsky61e77a42016-07-30 20:05:56 +0300736// Whether to provide stream functions with POSIX-like signatures
737// (useful for porting existing libraries to MicroPython).
738#ifndef MICROPY_STREAMS_POSIX_API
739#define MICROPY_STREAMS_POSIX_API (0)
740#endif
741
Damien George3c9c3682015-09-15 14:56:13 +0100742// Whether to call __init__ when importing builtin modules for the first time
743#ifndef MICROPY_MODULE_BUILTIN_INIT
744#define MICROPY_MODULE_BUILTIN_INIT (0)
745#endif
746
Paul m. p. P454cca62018-10-22 18:34:29 +0200747// Whether to support module-level __getattr__ (see PEP 562)
748#ifndef MICROPY_MODULE_GETATTR
Damien Georgef8fc7862020-03-01 00:06:15 +1100749#define MICROPY_MODULE_GETATTR (1)
Paul m. p. P454cca62018-10-22 18:34:29 +0200750#endif
751
Damien Georgec14a8162014-10-12 11:46:04 +0100752// Whether module weak links are supported
753#ifndef MICROPY_MODULE_WEAK_LINKS
754#define MICROPY_MODULE_WEAK_LINKS (0)
755#endif
756
Damien George0a2e9652016-01-31 22:24:16 +0000757// Whether frozen modules are supported in the form of strings
758#ifndef MICROPY_MODULE_FROZEN_STR
759#define MICROPY_MODULE_FROZEN_STR (0)
760#endif
761
762// Whether frozen modules are supported in the form of .mpy files
763#ifndef MICROPY_MODULE_FROZEN_MPY
764#define MICROPY_MODULE_FROZEN_MPY (0)
765#endif
766
767// Convenience macro for whether frozen modules are supported
Paul Sokolovsky640e0b22015-01-20 11:52:12 +0200768#ifndef MICROPY_MODULE_FROZEN
Damien George0a2e9652016-01-31 22:24:16 +0000769#define MICROPY_MODULE_FROZEN (MICROPY_MODULE_FROZEN_STR || MICROPY_MODULE_FROZEN_MPY)
Paul Sokolovsky640e0b22015-01-20 11:52:12 +0200770#endif
771
Damien George78d702c2014-12-09 16:19:48 +0000772// Whether you can override builtins in the builtins module
773#ifndef MICROPY_CAN_OVERRIDE_BUILTINS
774#define MICROPY_CAN_OVERRIDE_BUILTINS (0)
775#endif
776
Damien George06593fb2015-06-19 12:49:10 +0000777// Whether to check that the "self" argument of a builtin method has the
778// correct type. Such an explicit check is only needed if a builtin
779// method escapes to Python land without a first argument, eg
780// list.append([], 1). Without this check such calls will have undefined
781// behaviour (usually segfault) if the first argument is the wrong type.
782#ifndef MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG
783#define MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG (1)
784#endif
785
Damien George3f56fd62016-05-10 10:54:06 +0100786// Whether to use internally defined errno's (otherwise system provided ones)
787#ifndef MICROPY_USE_INTERNAL_ERRNO
788#define MICROPY_USE_INTERNAL_ERRNO (0)
789#endif
790
Delio Brignolie2ac8bb2016-08-21 11:33:37 +0200791// Whether to use internally defined *printf() functions (otherwise external ones)
792#ifndef MICROPY_USE_INTERNAL_PRINTF
793#define MICROPY_USE_INTERNAL_PRINTF (1)
794#endif
795
Damien George6e74d242017-02-16 18:05:06 +1100796// Support for internal scheduler
797#ifndef MICROPY_ENABLE_SCHEDULER
798#define MICROPY_ENABLE_SCHEDULER (0)
799#endif
800
801// Maximum number of entries in the scheduler
802#ifndef MICROPY_SCHEDULER_DEPTH
803#define MICROPY_SCHEDULER_DEPTH (4)
804#endif
805
Damien Georgedcb9ea72017-01-27 15:10:09 +1100806// Support for generic VFS sub-system
807#ifndef MICROPY_VFS
808#define MICROPY_VFS (0)
809#endif
810
Damien George8d82b0e2018-06-06 13:11:33 +1000811// Support for VFS POSIX component, to mount a POSIX filesystem within VFS
812#ifndef MICROPY_VFS
813#define MICROPY_VFS_POSIX (0)
814#endif
815
Damien Georgea8b9e712018-06-06 14:31:29 +1000816// Support for VFS FAT component, to mount a FAT filesystem within VFS
817#ifndef MICROPY_VFS
818#define MICROPY_VFS_FAT (0)
819#endif
820
Damien Georgeee3fd462014-05-24 23:03:12 +0100821/*****************************************************************************/
822/* Fine control over Python builtins, classes, modules, etc */
823
Damien Georgeda154fd2017-04-01 23:52:24 +1100824// Whether to support multiple inheritance of Python classes. Multiple
825// inheritance makes some C functions inherently recursive, and adds a bit of
826// code overhead.
827#ifndef MICROPY_MULTIPLE_INHERITANCE
828#define MICROPY_MULTIPLE_INHERITANCE (1)
829#endif
830
stijn3cc17c62015-02-14 18:44:31 +0100831// Whether to implement attributes on functions
832#ifndef MICROPY_PY_FUNCTION_ATTRS
833#define MICROPY_PY_FUNCTION_ATTRS (0)
834#endif
835
Damien George36c10522018-05-25 17:09:54 +1000836// Whether to support the descriptors __get__, __set__, __delete__
837// This costs some code size and makes load/store/delete of instance
838// attributes slower for the classes that use this feature
stijn28fa84b2015-02-14 18:43:54 +0100839#ifndef MICROPY_PY_DESCRIPTORS
840#define MICROPY_PY_DESCRIPTORS (0)
841#endif
842
dmazzella18e65692017-01-03 11:00:12 +0100843// Whether to support class __delattr__ and __setattr__ methods
Damien George36c10522018-05-25 17:09:54 +1000844// This costs some code size and makes store/delete of instance
845// attributes slower for the classes that use this feature
dmazzella18e65692017-01-03 11:00:12 +0100846#ifndef MICROPY_PY_DELATTR_SETATTR
847#define MICROPY_PY_DELATTR_SETATTR (0)
848#endif
849
pohmelie81ebba72016-01-27 23:23:11 +0300850// Support for async/await/async for/async with
851#ifndef MICROPY_PY_ASYNC_AWAIT
852#define MICROPY_PY_ASYNC_AWAIT (1)
853#endif
854
Damien George17839502020-06-16 21:42:44 +1000855// Support for assignment expressions with := (see PEP 572, Python 3.8+)
856#ifndef MICROPY_PY_ASSIGN_EXPR
857#define MICROPY_PY_ASSIGN_EXPR (1)
858#endif
859
Paul Sokolovsky63644012017-10-21 12:13:44 +0300860// Non-standard .pend_throw() method for generators, allowing for
861// Future-like behavior with respect to exception handling: an
862// exception set with .pend_throw() will activate on the next call
863// to generator's .send() or .__next__(). (This is useful to implement
864// async schedulers.)
865#ifndef MICROPY_PY_GENERATOR_PEND_THROW
866#define MICROPY_PY_GENERATOR_PEND_THROW (1)
867#endif
868
Paul Sokolovskya1b442b2016-07-22 00:46:24 +0300869// Issue a warning when comparing str and bytes objects
Paul Sokolovsky707cae72016-07-22 00:34:34 +0300870#ifndef MICROPY_PY_STR_BYTES_CMP_WARN
871#define MICROPY_PY_STR_BYTES_CMP_WARN (0)
872#endif
873
Paul Sokolovsky12bc13e2014-06-13 01:05:19 +0300874// Whether str object is proper unicode
875#ifndef MICROPY_PY_BUILTINS_STR_UNICODE
876#define MICROPY_PY_BUILTINS_STR_UNICODE (0)
Damien George8546ce12014-06-28 10:29:22 +0100877#endif
Damien Georgeb3a50f02014-06-28 10:27:15 +0100878
tll68c28172017-06-24 08:38:32 +0800879// Whether to check for valid UTF-8 when converting bytes to str
880#ifndef MICROPY_PY_BUILTINS_STR_UNICODE_CHECK
881#define MICROPY_PY_BUILTINS_STR_UNICODE_CHECK (MICROPY_PY_BUILTINS_STR_UNICODE)
882#endif
883
Paul Sokolovsky1b5abfc2016-05-22 00:13:44 +0300884// Whether str.center() method provided
885#ifndef MICROPY_PY_BUILTINS_STR_CENTER
886#define MICROPY_PY_BUILTINS_STR_CENTER (0)
887#endif
888
Paul Sokolovsky5a91fce2018-08-05 23:56:19 +0300889// Whether str.count() method provided
890#ifndef MICROPY_PY_BUILTINS_STR_COUNT
891#define MICROPY_PY_BUILTINS_STR_COUNT (1)
892#endif
893
Paul Sokolovsky2da5d412018-08-15 15:17:41 +0300894// Whether str % (...) formatting operator provided
895#ifndef MICROPY_PY_BUILTINS_STR_OP_MODULO
896#define MICROPY_PY_BUILTINS_STR_OP_MODULO (1)
897#endif
898
Paul Sokolovsky56eb25f2016-08-07 06:46:55 +0300899// Whether str.partition()/str.rpartition() method provided
900#ifndef MICROPY_PY_BUILTINS_STR_PARTITION
901#define MICROPY_PY_BUILTINS_STR_PARTITION (0)
902#endif
903
Paul Sokolovskyac2f7a72015-04-04 00:09:23 +0300904// Whether str.splitlines() method provided
905#ifndef MICROPY_PY_BUILTINS_STR_SPLITLINES
906#define MICROPY_PY_BUILTINS_STR_SPLITLINES (0)
907#endif
908
Paul Sokolovskycb78f862014-06-27 20:39:09 +0300909// Whether to support bytearray object
910#ifndef MICROPY_PY_BUILTINS_BYTEARRAY
911#define MICROPY_PY_BUILTINS_BYTEARRAY (1)
Paul Sokolovsky12bc13e2014-06-13 01:05:19 +0300912#endif
913
Paul Sokolovskyfbb83352018-08-06 01:25:41 +0300914// Whether to support dict.fromkeys() class method
915#ifndef MICROPY_PY_BUILTINS_DICT_FROMKEYS
916#define MICROPY_PY_BUILTINS_DICT_FROMKEYS (1)
917#endif
918
Damien Georgedd4f4532014-10-23 13:34:35 +0100919// Whether to support memoryview object
920#ifndef MICROPY_PY_BUILTINS_MEMORYVIEW
921#define MICROPY_PY_BUILTINS_MEMORYVIEW (0)
922#endif
923
stijn90fae912019-05-08 16:16:17 +0200924// Whether to support memoryview.itemsize attribute
925#ifndef MICROPY_PY_BUILTINS_MEMORYVIEW_ITEMSIZE
926#define MICROPY_PY_BUILTINS_MEMORYVIEW_ITEMSIZE (0)
927#endif
928
Damien George3ebd4d02014-06-01 13:46:47 +0100929// Whether to support set object
930#ifndef MICROPY_PY_BUILTINS_SET
931#define MICROPY_PY_BUILTINS_SET (1)
932#endif
933
Damien Georgefb510b32014-06-01 13:32:54 +0100934// Whether to support slice subscript operators and slice object
935#ifndef MICROPY_PY_BUILTINS_SLICE
936#define MICROPY_PY_BUILTINS_SLICE (1)
Damien Georgeee3fd462014-05-24 23:03:12 +0100937#endif
938
Tom Soulanilleaeb62f92015-09-11 14:31:32 -0700939// Whether to support slice attribute read access,
940// i.e. slice.start, slice.stop, slice.step
941#ifndef MICROPY_PY_BUILTINS_SLICE_ATTRS
942#define MICROPY_PY_BUILTINS_SLICE_ATTRS (0)
943#endif
944
Nicko van Someren4c939552019-11-16 17:07:11 -0700945// Whether to support the .indices(len) method on slice objects
946#ifndef MICROPY_PY_BUILTINS_SLICE_INDICES
947#define MICROPY_PY_BUILTINS_SLICE_INDICES (0)
948#endif
949
Damien Georgeee3fd462014-05-24 23:03:12 +0100950// Whether to support frozenset object
Damien Georgefb510b32014-06-01 13:32:54 +0100951#ifndef MICROPY_PY_BUILTINS_FROZENSET
952#define MICROPY_PY_BUILTINS_FROZENSET (0)
Damien Georgeee3fd462014-05-24 23:03:12 +0100953#endif
954
Damien Georgefb510b32014-06-01 13:32:54 +0100955// Whether to support property object
956#ifndef MICROPY_PY_BUILTINS_PROPERTY
957#define MICROPY_PY_BUILTINS_PROPERTY (1)
Damien Georgeee3fd462014-05-24 23:03:12 +0100958#endif
959
Peter D. Grayb2a237d2015-03-06 14:48:14 -0500960// Whether to implement the start/stop/step attributes (readback) on
961// the "range" builtin type. Rarely used, and costs ~60 bytes (x86).
962#ifndef MICROPY_PY_BUILTINS_RANGE_ATTRS
963#define MICROPY_PY_BUILTINS_RANGE_ATTRS (1)
964#endif
965
Damien Georged77da832018-02-14 23:17:06 +1100966// Whether to support binary ops [only (in)equality is defined] between range
967// objects. With this option disabled all range objects that are not exactly
968// the same object will compare as not-equal. With it enabled the semantics
969// match CPython and ranges are equal if they yield the same sequence of items.
970#ifndef MICROPY_PY_BUILTINS_RANGE_BINOP
971#define MICROPY_PY_BUILTINS_RANGE_BINOP (0)
972#endif
973
stijn42863832019-01-03 15:19:42 +0100974// Support for callling next() with second argument
975#ifndef MICROPY_PY_BUILTINS_NEXT2
976#define MICROPY_PY_BUILTINS_NEXT2 (0)
977#endif
978
Jan Klusacekb318ebf2018-01-09 22:47:35 +0100979// Whether to support rounding of integers (incl bignum); eg round(123,-1)=120
980#ifndef MICROPY_PY_BUILTINS_ROUND_INT
981#define MICROPY_PY_BUILTINS_ROUND_INT (0)
982#endif
983
Paul Sokolovsky0e80f342017-10-27 22:29:15 +0300984// Whether to support complete set of special methods for user
985// classes, or only the most used ones. "Inplace" methods are
986// controlled by MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS below.
987// "Reverse" methods are controlled by
988// MICROPY_PY_REVERSE_SPECIAL_METHODS below.
Paul Sokolovsky98c4bc32015-01-30 01:42:49 +0200989#ifndef MICROPY_PY_ALL_SPECIAL_METHODS
990#define MICROPY_PY_ALL_SPECIAL_METHODS (0)
991#endif
992
Paul Sokolovsky0e80f342017-10-27 22:29:15 +0300993// Whether to support all inplace arithmetic operarion methods
994// (__imul__, etc.)
995#ifndef MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS
996#define MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS (0)
997#endif
998
999// Whether to support reverse arithmetic operarion methods
1000// (__radd__, etc.). Additionally gated by
1001// MICROPY_PY_ALL_SPECIAL_METHODS.
Paul Sokolovskyeb84a832017-09-10 17:05:20 +03001002#ifndef MICROPY_PY_REVERSE_SPECIAL_METHODS
1003#define MICROPY_PY_REVERSE_SPECIAL_METHODS (0)
1004#endif
1005
Damien Georgec9fc6202014-10-25 21:59:14 +01001006// Whether to support compile function
1007#ifndef MICROPY_PY_BUILTINS_COMPILE
1008#define MICROPY_PY_BUILTINS_COMPILE (0)
1009#endif
1010
Paul Sokolovskye2d44e32015-04-06 23:50:37 +03001011// Whether to support enumerate function(type)
1012#ifndef MICROPY_PY_BUILTINS_ENUMERATE
1013#define MICROPY_PY_BUILTINS_ENUMERATE (1)
1014#endif
1015
Damien Georgedd5353a2015-12-18 12:35:44 +00001016// Whether to support eval and exec functions
1017// By default they are supported if the compiler is enabled
1018#ifndef MICROPY_PY_BUILTINS_EVAL_EXEC
1019#define MICROPY_PY_BUILTINS_EVAL_EXEC (MICROPY_ENABLE_COMPILER)
1020#endif
1021
Damien George2a3e2b92014-12-19 13:36:17 +00001022// Whether to support the Python 2 execfile function
1023#ifndef MICROPY_PY_BUILTINS_EXECFILE
1024#define MICROPY_PY_BUILTINS_EXECFILE (0)
1025#endif
1026
Paul Sokolovsky22ff3972015-08-20 01:01:56 +03001027// Whether to support filter function(type)
1028#ifndef MICROPY_PY_BUILTINS_FILTER
1029#define MICROPY_PY_BUILTINS_FILTER (1)
1030#endif
1031
Paul Sokolovsky282ca092015-04-07 00:16:51 +03001032// Whether to support reversed function(type)
1033#ifndef MICROPY_PY_BUILTINS_REVERSED
1034#define MICROPY_PY_BUILTINS_REVERSED (1)
1035#endif
1036
Paul Sokolovsky5ab5ac52015-05-04 19:45:53 +03001037// Whether to define "NotImplemented" special constant
1038#ifndef MICROPY_PY_BUILTINS_NOTIMPLEMENTED
1039#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (0)
1040#endif
1041
Damien Georgebc763022017-06-01 15:32:23 +10001042// Whether to provide the built-in input() function. The implementation of this
1043// uses mp-readline, so can only be enabled if the port uses this readline.
1044#ifndef MICROPY_PY_BUILTINS_INPUT
1045#define MICROPY_PY_BUILTINS_INPUT (0)
1046#endif
1047
pohmelie354e6882015-12-07 15:35:48 +03001048// Whether to support min/max functions
1049#ifndef MICROPY_PY_BUILTINS_MIN_MAX
1050#define MICROPY_PY_BUILTINS_MIN_MAX (1)
1051#endif
1052
Damien Georgea19b5a02017-02-03 12:35:48 +11001053// Support for calls to pow() with 3 integer arguments
1054#ifndef MICROPY_PY_BUILTINS_POW3
1055#define MICROPY_PY_BUILTINS_POW3 (0)
1056#endif
1057
Damien George9f04dfb2017-01-21 23:17:51 +11001058// Whether to provide the help function
1059#ifndef MICROPY_PY_BUILTINS_HELP
1060#define MICROPY_PY_BUILTINS_HELP (0)
1061#endif
1062
1063// Use this to configure the help text shown for help(). It should be a
1064// variable with the type "const char*". A sensible default is provided.
1065#ifndef MICROPY_PY_BUILTINS_HELP_TEXT
1066#define MICROPY_PY_BUILTINS_HELP_TEXT mp_help_default_text
1067#endif
1068
Damien Georgef5172af2017-01-22 12:12:54 +11001069// Add the ability to list the available modules when executing help('modules')
1070#ifndef MICROPY_PY_BUILTINS_HELP_MODULES
1071#define MICROPY_PY_BUILTINS_HELP_MODULES (0)
1072#endif
1073
Paul Sokolovskyd0f5e612014-07-25 11:00:15 +03001074// Whether to set __file__ for imported modules
1075#ifndef MICROPY_PY___FILE__
1076#define MICROPY_PY___FILE__ (1)
1077#endif
1078
Damien George89deec02015-01-09 20:12:54 +00001079// Whether to provide mem-info related functions in micropython module
1080#ifndef MICROPY_PY_MICROPYTHON_MEM_INFO
1081#define MICROPY_PY_MICROPYTHON_MEM_INFO (0)
1082#endif
1083
Damien George7e2a4882018-02-20 18:30:22 +11001084// Whether to provide "micropython.stack_use" function
1085#ifndef MICROPY_PY_MICROPYTHON_STACK_USE
1086#define MICROPY_PY_MICROPYTHON_STACK_USE (MICROPY_PY_MICROPYTHON_MEM_INFO)
1087#endif
1088
Andrew Leech86bfabe2019-06-28 16:35:51 +10001089// Whether to provide the "micropython.heap_locked" function
1090#ifndef MICROPY_PY_MICROPYTHON_HEAP_LOCKED
1091#define MICROPY_PY_MICROPYTHON_HEAP_LOCKED (0)
1092#endif
1093
Paul Sokolovskycb78f862014-06-27 20:39:09 +03001094// Whether to provide "array" module. Note that large chunk of the
1095// underlying code is shared with "bytearray" builtin type, so to
1096// get real savings, it should be disabled too.
1097#ifndef MICROPY_PY_ARRAY
1098#define MICROPY_PY_ARRAY (1)
1099#endif
1100
Paul Sokolovskycefcbb22015-02-27 22:16:05 +02001101// Whether to support slice assignments for array (and bytearray).
1102// This is rarely used, but adds ~0.5K of code.
1103#ifndef MICROPY_PY_ARRAY_SLICE_ASSIGN
1104#define MICROPY_PY_ARRAY_SLICE_ASSIGN (0)
1105#endif
1106
Damien George5aa311d2015-04-21 14:14:24 +00001107// Whether to support attrtuple type (MicroPython extension)
1108// It provides space-efficient tuples with attribute access
1109#ifndef MICROPY_PY_ATTRTUPLE
1110#define MICROPY_PY_ATTRTUPLE (1)
1111#endif
1112
Damien Georgeee3fd462014-05-24 23:03:12 +01001113// Whether to provide "collections" module
1114#ifndef MICROPY_PY_COLLECTIONS
1115#define MICROPY_PY_COLLECTIONS (1)
1116#endif
1117
Paul Sokolovsky970eedc2018-02-06 00:06:42 +02001118// Whether to provide "ucollections.deque" type
1119#ifndef MICROPY_PY_COLLECTIONS_DEQUE
1120#define MICROPY_PY_COLLECTIONS_DEQUE (0)
1121#endif
1122
Paul Sokolovsky0ef01d02015-03-18 01:25:04 +02001123// Whether to provide "collections.OrderedDict" type
1124#ifndef MICROPY_PY_COLLECTIONS_ORDEREDDICT
1125#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (0)
1126#endif
1127
stijn79ed58f2017-11-06 12:21:53 +01001128// Whether to provide the _asdict function for namedtuple
1129#ifndef MICROPY_PY_COLLECTIONS_NAMEDTUPLE__ASDICT
1130#define MICROPY_PY_COLLECTIONS_NAMEDTUPLE__ASDICT (0)
1131#endif
1132
Damien Georgeee3fd462014-05-24 23:03:12 +01001133// Whether to provide "math" module
1134#ifndef MICROPY_PY_MATH
1135#define MICROPY_PY_MATH (1)
1136#endif
1137
Damien George5cbeace2015-02-22 14:48:18 +00001138// Whether to provide special math functions: math.{erf,erfc,gamma,lgamma}
1139#ifndef MICROPY_PY_MATH_SPECIAL_FUNCTIONS
1140#define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (0)
1141#endif
1142
Christopher Swenson8c656752018-08-27 10:32:21 +10001143// Whether to provide math.factorial function
1144#ifndef MICROPY_PY_MATH_FACTORIAL
1145#define MICROPY_PY_MATH_FACTORIAL (0)
1146#endif
1147
stijnaf5c9982019-07-02 10:28:44 +02001148// Whether to provide math.isclose function
1149#ifndef MICROPY_PY_MATH_ISCLOSE
1150#define MICROPY_PY_MATH_ISCLOSE (0)
1151#endif
1152
stijn81db22f2020-05-17 12:29:25 +02001153// Whether to provide fix for atan2 Inf handling.
1154#ifndef MICROPY_PY_MATH_ATAN2_FIX_INFNAN
1155#define MICROPY_PY_MATH_ATAN2_FIX_INFNAN (0)
1156#endif
1157
1158// Whether to provide fix for fmod Inf handling.
1159#ifndef MICROPY_PY_MATH_FMOD_FIX_INFNAN
1160#define MICROPY_PY_MATH_FMOD_FIX_INFNAN (0)
1161#endif
1162
1163// Whether to provide fix for modf negative zero handling.
1164#ifndef MICROPY_PY_MATH_MODF_FIX_NEGZERO
1165#define MICROPY_PY_MATH_MODF_FIX_NEGZERO (0)
1166#endif
1167
stijn2e54d9d2020-09-08 15:22:34 +02001168// Whether to provide fix for pow(1, NaN) and pow(NaN, 0), which both should be 1 not NaN.
1169#ifndef MICROPY_PY_MATH_POW_FIX_NAN
1170#define MICROPY_PY_MATH_POW_FIX_NAN (0)
1171#endif
1172
Damien Georgeee3fd462014-05-24 23:03:12 +01001173// Whether to provide "cmath" module
1174#ifndef MICROPY_PY_CMATH
1175#define MICROPY_PY_CMATH (0)
1176#endif
1177
1178// Whether to provide "gc" module
1179#ifndef MICROPY_PY_GC
1180#define MICROPY_PY_GC (1)
1181#endif
1182
Paul Sokolovsky755a55f2014-06-05 22:48:02 +03001183// Whether to return number of collected objects from gc.collect()
1184#ifndef MICROPY_PY_GC_COLLECT_RETVAL
1185#define MICROPY_PY_GC_COLLECT_RETVAL (0)
1186#endif
1187
Damien Georgeee3fd462014-05-24 23:03:12 +01001188// Whether to provide "io" module
1189#ifndef MICROPY_PY_IO
1190#define MICROPY_PY_IO (1)
1191#endif
1192
Damien Georgeaf0932a2018-06-04 15:54:26 +10001193// Whether to provide "io.IOBase" class to support user streams
1194#ifndef MICROPY_PY_IO_IOBASE
1195#define MICROPY_PY_IO_IOBASE (0)
1196#endif
1197
Paul Sokolovskyd7da2db2017-05-03 01:47:08 +03001198// Whether to provide "uio.resource_stream()" function with
1199// the semantics of CPython's pkg_resources.resource_stream()
Paul Sokolovskye7fc7652017-12-10 02:15:43 +02001200// (allows to access binary resources in frozen source packages).
1201// Note that the same functionality can be achieved in "pure
1202// Python" by prepocessing binary resources into Python source
1203// and bytecode-freezing it (with a simple helper module available
1204// e.g. in micropython-lib).
Paul Sokolovskyd7da2db2017-05-03 01:47:08 +03001205#ifndef MICROPY_PY_IO_RESOURCE_STREAM
1206#define MICROPY_PY_IO_RESOURCE_STREAM (0)
1207#endif
1208
Damien Georgeee3fd462014-05-24 23:03:12 +01001209// Whether to provide "io.FileIO" class
1210#ifndef MICROPY_PY_IO_FILEIO
1211#define MICROPY_PY_IO_FILEIO (0)
1212#endif
1213
1214// Whether to provide "io.BytesIO" class
1215#ifndef MICROPY_PY_IO_BYTESIO
1216#define MICROPY_PY_IO_BYTESIO (1)
1217#endif
1218
Paul Sokolovsky5d93dfb2016-03-25 01:10:49 +02001219// Whether to provide "io.BufferedWriter" class
1220#ifndef MICROPY_PY_IO_BUFFEREDWRITER
1221#define MICROPY_PY_IO_BUFFEREDWRITER (0)
1222#endif
1223
Damien Georgeee3fd462014-05-24 23:03:12 +01001224// Whether to provide "struct" module
1225#ifndef MICROPY_PY_STRUCT
1226#define MICROPY_PY_STRUCT (1)
1227#endif
1228
1229// Whether to provide "sys" module
1230#ifndef MICROPY_PY_SYS
1231#define MICROPY_PY_SYS (1)
1232#endif
1233
Paul Sokolovsky4e0eeeb2014-07-03 16:50:11 +03001234// Whether to provide "sys.maxsize" constant
1235#ifndef MICROPY_PY_SYS_MAXSIZE
1236#define MICROPY_PY_SYS_MAXSIZE (0)
1237#endif
1238
Paul Sokolovsky1a1d11f2015-12-05 00:09:10 +02001239// Whether to provide "sys.modules" dictionary
1240#ifndef MICROPY_PY_SYS_MODULES
1241#define MICROPY_PY_SYS_MODULES (1)
1242#endif
1243
Paul Sokolovsky8b85d142015-04-25 03:17:41 +03001244// Whether to provide "sys.exc_info" function
1245// Avoid enabling this, this function is Python2 heritage
1246#ifndef MICROPY_PY_SYS_EXC_INFO
1247#define MICROPY_PY_SYS_EXC_INFO (0)
1248#endif
1249
Damien Georgeee3fd462014-05-24 23:03:12 +01001250// Whether to provide "sys.exit" function
1251#ifndef MICROPY_PY_SYS_EXIT
Paul Sokolovsky403c9302016-12-14 21:10:22 +03001252#define MICROPY_PY_SYS_EXIT (1)
Damien Georgeee3fd462014-05-24 23:03:12 +01001253#endif
1254
Milan Rossacb364702019-08-05 15:06:41 +02001255// Whether to provide "sys.atexit" function (MicroPython extension)
1256#ifndef MICROPY_PY_SYS_ATEXIT
1257#define MICROPY_PY_SYS_ATEXIT (0)
1258#endif
1259
Milan Rossa310b3d12019-08-14 16:09:36 +02001260// Whether to provide "sys.settrace" function
1261#ifndef MICROPY_PY_SYS_SETTRACE
1262#define MICROPY_PY_SYS_SETTRACE (0)
1263#endif
1264
Paul Sokolovskybfc20922017-08-11 09:42:39 +03001265// Whether to provide "sys.getsizeof" function
1266#ifndef MICROPY_PY_SYS_GETSIZEOF
1267#define MICROPY_PY_SYS_GETSIZEOF (0)
1268#endif
1269
Damien Georgeee3fd462014-05-24 23:03:12 +01001270// Whether to provide sys.{stdin,stdout,stderr} objects
1271#ifndef MICROPY_PY_SYS_STDFILES
1272#define MICROPY_PY_SYS_STDFILES (0)
Damien George3bb8bd82014-04-14 21:20:30 +01001273#endif
1274
Damien George3c4b5d42015-05-13 23:49:21 +01001275// Whether to provide sys.{stdin,stdout,stderr}.buffer object
1276// This is implemented per-port
1277#ifndef MICROPY_PY_SYS_STDIO_BUFFER
1278#define MICROPY_PY_SYS_STDIO_BUFFER (0)
1279#endif
Paul Sokolovsky82158472014-06-28 03:03:47 +03001280
Damien George596a3fe2016-05-10 10:54:25 +01001281// Whether to provide "uerrno" module
1282#ifndef MICROPY_PY_UERRNO
1283#define MICROPY_PY_UERRNO (0)
1284#endif
1285
Damien Georgef5634062017-02-22 12:53:42 +11001286// Whether to provide the uerrno.errorcode dict
1287#ifndef MICROPY_PY_UERRNO_ERRORCODE
1288#define MICROPY_PY_UERRNO_ERRORCODE (1)
1289#endif
1290
Paul Sokolovsky8f5bc3f2016-11-20 23:49:45 +03001291// Whether to provide "uselect" module (baremetal implementation)
1292#ifndef MICROPY_PY_USELECT
1293#define MICROPY_PY_USELECT (0)
1294#endif
1295
Paul Sokolovskya9728442016-10-14 20:13:02 +03001296// Whether to provide "utime" module functions implementation
1297// in terms of mp_hal_* functions.
1298#ifndef MICROPY_PY_UTIME_MP_HAL
1299#define MICROPY_PY_UTIME_MP_HAL (0)
1300#endif
1301
Paul Sokolovsky76146b32016-10-30 03:02:07 +03001302// Period of values returned by utime.ticks_ms(), ticks_us(), ticks_cpu()
1303// functions. Should be power of two. All functions above use the same
1304// period, so if underlying hardware/API has different periods, the
1305// minimum of them should be used. The value below is the maximum value
1306// this parameter can take (corresponding to 30 bit tick values on 32-bit
1307// system).
1308#ifndef MICROPY_PY_UTIME_TICKS_PERIOD
1309#define MICROPY_PY_UTIME_TICKS_PERIOD (MP_SMALL_INT_POSITIVE_MASK + 1)
1310#endif
1311
Damien George27cc0772016-04-22 22:52:33 +00001312// Whether to provide "_thread" module
1313#ifndef MICROPY_PY_THREAD
1314#define MICROPY_PY_THREAD (0)
1315#endif
1316
Damien George4cec63a2016-05-26 10:42:53 +00001317// Whether to make the VM/runtime thread-safe using a global lock
1318// If not enabled then thread safety must be provided at the Python level
1319#ifndef MICROPY_PY_THREAD_GIL
1320#define MICROPY_PY_THREAD_GIL (MICROPY_PY_THREAD)
1321#endif
1322
Damien Georgef6c22a02017-02-06 10:50:43 +11001323// Number of VM jump-loops to do before releasing the GIL.
1324// Set this to 0 to disable the divisor.
1325#ifndef MICROPY_PY_THREAD_GIL_VM_DIVISOR
1326#define MICROPY_PY_THREAD_GIL_VM_DIVISOR (32)
1327#endif
1328
Paul Sokolovsky82158472014-06-28 03:03:47 +03001329// Extended modules
Paul Sokolovsky510296f2014-08-08 22:51:40 +03001330
Damien Georgebc009fd2020-03-12 16:46:20 +11001331#ifndef MICROPY_PY_UASYNCIO
1332#define MICROPY_PY_UASYNCIO (0)
1333#endif
1334
Paul Sokolovsky82158472014-06-28 03:03:47 +03001335#ifndef MICROPY_PY_UCTYPES
1336#define MICROPY_PY_UCTYPES (0)
1337#endif
1338
Paul Sokolovsky38151f32018-10-06 23:34:58 +03001339// Whether to provide SHORT, INT, LONG, etc. types in addition to
1340// exact-bitness types like INT16, INT32, etc.
1341#ifndef MICROPY_PY_UCTYPES_NATIVE_C_TYPES
1342#define MICROPY_PY_UCTYPES_NATIVE_C_TYPES (1)
1343#endif
1344
Paul Sokolovsky34162872014-10-12 08:16:34 -07001345#ifndef MICROPY_PY_UZLIB
1346#define MICROPY_PY_UZLIB (0)
1347#endif
1348
Damien George612045f2014-09-17 22:56:34 +01001349#ifndef MICROPY_PY_UJSON
1350#define MICROPY_PY_UJSON (0)
1351#endif
1352
Paul Sokolovskyc71e0452014-09-12 18:48:07 +03001353#ifndef MICROPY_PY_URE
1354#define MICROPY_PY_URE (0)
1355#endif
1356
Damien George7d851a22019-08-17 23:50:19 +10001357#ifndef MICROPY_PY_URE_DEBUG
1358#define MICROPY_PY_URE_DEBUG (0)
1359#endif
1360
Damien George1f864602018-05-24 13:07:42 +10001361#ifndef MICROPY_PY_URE_MATCH_GROUPS
1362#define MICROPY_PY_URE_MATCH_GROUPS (0)
1363#endif
1364
Damien George1e9b8712018-05-24 13:08:15 +10001365#ifndef MICROPY_PY_URE_MATCH_SPAN_START_END
1366#define MICROPY_PY_URE_MATCH_SPAN_START_END (0)
1367#endif
1368
Damien Georgee30a5fc2018-05-24 13:08:51 +10001369#ifndef MICROPY_PY_URE_SUB
1370#define MICROPY_PY_URE_SUB (0)
1371#endif
1372
Damien Georgef5d69792014-10-22 17:37:18 +00001373#ifndef MICROPY_PY_UHEAPQ
1374#define MICROPY_PY_UHEAPQ (0)
1375#endif
1376
Paul Sokolovskyd02f6a92016-12-22 00:29:32 +03001377// Optimized heap queue for relative timestamps
1378#ifndef MICROPY_PY_UTIMEQ
1379#define MICROPY_PY_UTIMEQ (0)
1380#endif
1381
Paul Sokolovskyf4b19c82014-11-22 01:19:13 +02001382#ifndef MICROPY_PY_UHASHLIB
1383#define MICROPY_PY_UHASHLIB (0)
1384#endif
1385
Paul Sokolovsky5fe37302018-08-19 11:58:22 +03001386#ifndef MICROPY_PY_UHASHLIB_MD5
1387#define MICROPY_PY_UHASHLIB_MD5 (0)
1388#endif
1389
Yonatan Goldschmidt66303542018-06-09 02:48:29 +03001390#ifndef MICROPY_PY_UHASHLIB_SHA1
1391#define MICROPY_PY_UHASHLIB_SHA1 (0)
1392#endif
1393
1394#ifndef MICROPY_PY_UHASHLIB_SHA256
1395#define MICROPY_PY_UHASHLIB_SHA256 (1)
1396#endif
1397
Paul Sokolovsky567bc2d2018-01-07 15:13:56 +02001398#ifndef MICROPY_PY_UCRYPTOLIB
1399#define MICROPY_PY_UCRYPTOLIB (0)
1400#endif
1401
Yonatan Goldschmidtef984362019-04-23 12:39:05 +03001402// Depends on MICROPY_PY_UCRYPTOLIB
1403#ifndef MICROPY_PY_UCRYPTOLIB_CTR
1404#define MICROPY_PY_UCRYPTOLIB_CTR (0)
1405#endif
1406
Yonatan Goldschmidt473fe452018-06-15 17:07:47 +03001407#ifndef MICROPY_PY_UCRYPTOLIB_CONSTS
1408#define MICROPY_PY_UCRYPTOLIB_CONSTS (0)
1409#endif
1410
Paul Sokolovskybfdc2052014-11-29 06:19:30 +02001411#ifndef MICROPY_PY_UBINASCII
1412#define MICROPY_PY_UBINASCII (0)
1413#endif
1414
Paul Sokolovskyc4283672016-08-24 18:28:43 +03001415// Depends on MICROPY_PY_UZLIB
1416#ifndef MICROPY_PY_UBINASCII_CRC32
1417#define MICROPY_PY_UBINASCII_CRC32 (0)
1418#endif
1419
Paul Sokolovskya58a91e2016-01-17 12:10:28 +02001420#ifndef MICROPY_PY_URANDOM
1421#define MICROPY_PY_URANDOM (0)
1422#endif
1423
Damien Georgea53af6c2016-01-22 16:19:32 +00001424// Whether to include: randrange, randint, choice, random, uniform
1425#ifndef MICROPY_PY_URANDOM_EXTRA_FUNCS
1426#define MICROPY_PY_URANDOM_EXTRA_FUNCS (0)
1427#endif
1428
Paul Sokolovsky01162182015-05-03 20:25:40 +03001429#ifndef MICROPY_PY_MACHINE
1430#define MICROPY_PY_MACHINE (0)
1431#endif
1432
Damien George33168082016-05-31 14:25:19 +01001433// Whether to include: time_pulse_us
1434#ifndef MICROPY_PY_MACHINE_PULSE
1435#define MICROPY_PY_MACHINE_PULSE (0)
1436#endif
1437
Damien Georged0837122016-04-12 13:42:35 +01001438#ifndef MICROPY_PY_MACHINE_I2C
1439#define MICROPY_PY_MACHINE_I2C (0)
1440#endif
1441
Damien George0823c1b2016-09-01 15:07:20 +10001442#ifndef MICROPY_PY_MACHINE_SPI
1443#define MICROPY_PY_MACHINE_SPI (0)
1444#endif
1445
Paul Sokolovskyaaa88672015-10-06 18:10:00 +03001446#ifndef MICROPY_PY_USSL
1447#define MICROPY_PY_USSL (0)
Eric Poulsen74ec52d2017-10-26 21:17:35 -07001448// Whether to add finaliser code to ussl objects
1449#define MICROPY_PY_USSL_FINALISER (0)
Paul Sokolovskyaaa88672015-10-06 18:10:00 +03001450#endif
1451
Yonatan Goldschmidtbc4f8b42019-02-10 22:35:18 +02001452#ifndef MICROPY_PY_UWEBSOCKET
1453#define MICROPY_PY_UWEBSOCKET (0)
Paul Sokolovsky24342dd2016-03-24 19:14:12 +02001454#endif
1455
Damien George53ad6812016-04-08 11:08:37 +01001456#ifndef MICROPY_PY_FRAMEBUF
1457#define MICROPY_PY_FRAMEBUF (0)
1458#endif
1459
Paul Sokolovsky737bd9c2016-07-02 14:57:42 +03001460#ifndef MICROPY_PY_BTREE
1461#define MICROPY_PY_BTREE (0)
1462#endif
1463
Damien George58ebde42014-05-21 20:32:59 +01001464/*****************************************************************************/
1465/* Hooks for a port to add builtins */
1466
Yonatan Goldschmidt343401c2019-02-03 21:24:16 +02001467// Additional builtin function definitions - see modbuiltins.c:mp_module_builtins_globals_table for format.
Damien George58ebde42014-05-21 20:32:59 +01001468#ifndef MICROPY_PORT_BUILTINS
1469#define MICROPY_PORT_BUILTINS
Paul Sokolovsky910843e2014-02-14 12:02:34 +02001470#endif
Damien Georgecaac5422014-03-25 14:18:18 +00001471
Yonatan Goldschmidt343401c2019-02-03 21:24:16 +02001472// Additional builtin module definitions - see objmodule.c:mp_builtin_module_table for format.
Damien George58ebde42014-05-21 20:32:59 +01001473#ifndef MICROPY_PORT_BUILTIN_MODULES
1474#define MICROPY_PORT_BUILTIN_MODULES
Damien Georgecaac5422014-03-25 14:18:18 +00001475#endif
1476
Damien George57e99eb2014-04-10 22:42:11 +01001477// Additional constant definitions for the compiler - see compile.c:mp_constants_table.
Damien George58ebde42014-05-21 20:32:59 +01001478#ifndef MICROPY_PORT_CONSTANTS
1479#define MICROPY_PORT_CONSTANTS
Damien George57e99eb2014-04-10 22:42:11 +01001480#endif
1481
Damien Georgeb4b10fd2015-01-01 23:30:53 +00001482// Any root pointers for GC scanning - see mpstate.c
1483#ifndef MICROPY_PORT_ROOT_POINTERS
1484#define MICROPY_PORT_ROOT_POINTERS
1485#endif
1486
Damien George136f6752014-01-07 14:54:15 +00001487/*****************************************************************************/
Damien George8fb5c8f2020-02-07 12:07:50 +11001488/* Hooks for a port to wrap functions with attributes */
1489
1490#ifndef MICROPY_WRAP_MP_KEYBOARD_INTERRUPT
1491#define MICROPY_WRAP_MP_KEYBOARD_INTERRUPT(f) f
1492#endif
1493
Damien George544c3082020-04-23 16:18:14 +10001494#ifndef MICROPY_WRAP_MP_SCHED_SCHEDULE
1495#define MICROPY_WRAP_MP_SCHED_SCHEDULE(f) f
1496#endif
1497
Damien George8fb5c8f2020-02-07 12:07:50 +11001498/*****************************************************************************/
Damien George136f6752014-01-07 14:54:15 +00001499/* Miscellaneous settings */
1500
Damien George28631532015-02-08 13:42:00 +00001501// All uPy objects in ROM must be aligned on at least a 4 byte boundary
1502// so that the small-int/qstr/pointer distinction can be made. For machines
1503// that don't do this (eg 16-bit CPU), define the following macro to something
1504// like __attribute__((aligned(4))).
1505#ifndef MICROPY_OBJ_BASE_ALIGNMENT
1506#define MICROPY_OBJ_BASE_ALIGNMENT
1507#endif
1508
Dave Hylands5b7fd202014-07-01 23:46:53 -07001509// On embedded platforms, these will typically enable/disable irqs.
1510#ifndef MICROPY_BEGIN_ATOMIC_SECTION
Damien George4859edb2014-10-15 17:33:24 +00001511#define MICROPY_BEGIN_ATOMIC_SECTION() (0)
Dave Hylands5b7fd202014-07-01 23:46:53 -07001512#endif
1513#ifndef MICROPY_END_ATOMIC_SECTION
Damien George4859edb2014-10-15 17:33:24 +00001514#define MICROPY_END_ATOMIC_SECTION(state) (void)(state)
Dave Hylands5b7fd202014-07-01 23:46:53 -07001515#endif
1516
Paul Sokolovskyd5df6cd2014-02-12 18:15:40 +02001517// Allow to override static modifier for global objects, e.g. to use with
1518// object code analysis tools which don't support static symbols.
1519#ifndef STATIC
1520#define STATIC static
1521#endif
1522
Damien George4c307bf2017-04-01 11:39:38 +11001523// Number of bytes in a word
1524#ifndef BYTES_PER_WORD
1525#define BYTES_PER_WORD (sizeof(mp_uint_t))
1526#endif
1527
Yonatan Goldschmidt1c849d62019-12-01 01:10:12 +02001528#ifndef BITS_PER_BYTE
Paul Sokolovskyfc5aac82014-01-12 16:10:19 +02001529#define BITS_PER_BYTE (8)
Yonatan Goldschmidt1c849d62019-12-01 01:10:12 +02001530#endif
Paul Sokolovskyfc5aac82014-01-12 16:10:19 +02001531#define BITS_PER_WORD (BITS_PER_BYTE * BYTES_PER_WORD)
Damien George40f3c022014-07-03 13:25:24 +01001532// mp_int_t value with most significant bit set
1533#define WORD_MSBIT_HIGH (((mp_uint_t)1) << (BYTES_PER_WORD * 8 - 1))
Paul Sokolovskyfc5aac82014-01-12 16:10:19 +02001534
Damien Georgea9bcd512014-10-06 13:44:59 +00001535// Make sure both MP_ENDIANNESS_LITTLE and MP_ENDIANNESS_BIG are
1536// defined and that they are the opposite of each other.
1537#if defined(MP_ENDIANNESS_LITTLE)
1538#define MP_ENDIANNESS_BIG (!MP_ENDIANNESS_LITTLE)
1539#elif defined(MP_ENDIANNESS_BIG)
1540#define MP_ENDIANNESS_LITTLE (!MP_ENDIANNESS_BIG)
1541#else
Damien George69661f32020-02-27 15:36:53 +11001542// Endianness not defined by port so try to autodetect it.
Damien Georgea9bcd512014-10-06 13:44:59 +00001543 #if defined(__BYTE_ORDER__)
1544 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
1545 #define MP_ENDIANNESS_LITTLE (1)
Damien George96303762018-05-07 13:36:52 +10001546 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
Damien Georgea9bcd512014-10-06 13:44:59 +00001547 #define MP_ENDIANNESS_LITTLE (0)
1548 #endif
Damien Georgea9bcd512014-10-06 13:44:59 +00001549 #else
Damien George4e4772b2015-05-30 23:12:30 +01001550 #include <endian.h>
1551 #if defined(__BYTE_ORDER)
1552 #if __BYTE_ORDER == __LITTLE_ENDIAN
1553 #define MP_ENDIANNESS_LITTLE (1)
Damien George96303762018-05-07 13:36:52 +10001554 #elif __BYTE_ORDER == __BIG_ENDIAN
Damien George4e4772b2015-05-30 23:12:30 +01001555 #define MP_ENDIANNESS_LITTLE (0)
1556 #endif
Damien George4e4772b2015-05-30 23:12:30 +01001557 #endif
Damien Georgea9bcd512014-10-06 13:44:59 +00001558 #endif
Damien George96303762018-05-07 13:36:52 +10001559 #ifndef MP_ENDIANNESS_LITTLE
1560 #error endianness not defined and cannot detect it
1561 #endif
Damien Georgea9bcd512014-10-06 13:44:59 +00001562 #define MP_ENDIANNESS_BIG (!MP_ENDIANNESS_LITTLE)
Andrew Schellercc837372014-04-14 02:39:56 +01001563#endif
Paul Sokolovsky2da81fa2014-04-11 03:44:00 +03001564
Damien George3c658a42014-08-24 16:28:17 +01001565// Make a pointer to RAM callable (eg set lower bit for Thumb code)
1566// (This scheme won't work if we want to mix Thumb and normal ARM code.)
1567#ifndef MICROPY_MAKE_POINTER_CALLABLE
1568#define MICROPY_MAKE_POINTER_CALLABLE(p) (p)
1569#endif
1570
Damien George7f9d1d62015-04-09 23:56:15 +01001571// If these MP_PLAT_*_EXEC macros are overridden then the memory allocated by them
Damien George2127e9a2015-01-14 00:11:09 +00001572// must be somehow reachable for marking by the GC, since the native code
1573// generators store pointers to GC managed memory in the code.
Fabian Vogtb7235b82014-09-03 16:59:33 +02001574#ifndef MP_PLAT_ALLOC_EXEC
Damien George4dea9222015-04-09 15:29:54 +00001575#define MP_PLAT_ALLOC_EXEC(min_size, ptr, size) do { *ptr = m_new(byte, min_size); *size = min_size; } while (0)
Fabian Vogtb7235b82014-09-03 16:59:33 +02001576#endif
1577
1578#ifndef MP_PLAT_FREE_EXEC
1579#define MP_PLAT_FREE_EXEC(ptr, size) m_del(byte, ptr, size)
1580#endif
1581
Damien George7f9d1d62015-04-09 23:56:15 +01001582// This macro is used to do all output (except when MICROPY_PY_IO is defined)
1583#ifndef MP_PLAT_PRINT_STRN
Damien George4300c7d2015-10-15 00:05:55 +01001584#define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
Damien George7f9d1d62015-04-09 23:56:15 +01001585#endif
1586
Paul Sokolovsky722e5622014-09-06 19:17:23 +03001587#ifndef MP_SSIZE_MAX
1588#define MP_SSIZE_MAX SSIZE_MAX
1589#endif
1590
Damien George40f3c022014-07-03 13:25:24 +01001591// printf format spec to use for mp_int_t and friends
Damien George136f6752014-01-07 14:54:15 +00001592#ifndef INT_FMT
stijn3baf6b52015-11-20 15:59:06 +01001593#if defined(__LP64__)
Damien George40f3c022014-07-03 13:25:24 +01001594// Archs where mp_int_t == long, long != int
Paul Sokolovskyc90c0f62014-01-04 01:57:00 +02001595#define UINT_FMT "%lu"
1596#define INT_FMT "%ld"
stijn3baf6b52015-11-20 15:59:06 +01001597#elif defined(_WIN64)
stijn0a4eb4d2015-12-18 10:20:33 +01001598#define UINT_FMT "%llu"
1599#define INT_FMT "%lld"
Paul Sokolovskyc90c0f62014-01-04 01:57:00 +02001600#else
Damien George40f3c022014-07-03 13:25:24 +01001601// Archs where mp_int_t == int
Paul Sokolovskyc90c0f62014-01-04 01:57:00 +02001602#define UINT_FMT "%u"
1603#define INT_FMT "%d"
1604#endif
stijn84fa3312020-04-16 09:13:57 +02001605#endif // INT_FMT
Paul Sokolovskye9085912014-04-30 05:35:18 +03001606
1607// Modifier for function which doesn't return
stijn01d6be42014-05-05 12:18:27 +02001608#ifndef NORETURN
Paul Sokolovskye9085912014-04-30 05:35:18 +03001609#define NORETURN __attribute__((noreturn))
stijn01d6be42014-05-05 12:18:27 +02001610#endif
mux5c8db482014-06-21 17:24:55 +02001611
1612// Modifier for weak functions
1613#ifndef MP_WEAK
1614#define MP_WEAK __attribute__((weak))
1615#endif
Paul Sokolovsky361909e2014-12-29 00:51:06 +02001616
Paul Sokolovsky0f5bf1a2016-06-15 23:52:00 +03001617// Modifier for functions which should be never inlined
1618#ifndef MP_NOINLINE
1619#define MP_NOINLINE __attribute__((noinline))
1620#endif
1621
Paul Sokolovsky1bc29112016-08-07 22:36:05 +03001622// Modifier for functions which should be always inlined
1623#ifndef MP_ALWAYSINLINE
1624#define MP_ALWAYSINLINE __attribute__((always_inline))
1625#endif
1626
Paul Sokolovsky361909e2014-12-29 00:51:06 +02001627// Condition is likely to be true, to help branch prediction
1628#ifndef MP_LIKELY
1629#define MP_LIKELY(x) __builtin_expect((x), 1)
1630#endif
1631
1632// Condition is likely to be false, to help branch prediction
1633#ifndef MP_UNLIKELY
1634#define MP_UNLIKELY(x) __builtin_expect((x), 0)
1635#endif
Damien George9ddbe292014-12-29 01:02:19 +00001636
Damien George0c80cb32019-08-19 15:50:02 +10001637// To annotate that code is unreachable
1638#ifndef MP_UNREACHABLE
1639#if defined(__GNUC__)
1640#define MP_UNREACHABLE __builtin_unreachable();
1641#else
1642#define MP_UNREACHABLE for (;;);
1643#endif
1644#endif
1645
Emil Renner Berthingccd92332019-11-28 12:47:21 +01001646// Explicitly annotate switch case fall throughs
1647#if defined(__GNUC__) && __GNUC__ >= 7
1648#define MP_FALLTHROUGH __attribute__((fallthrough));
1649#else
1650#define MP_FALLTHROUGH
1651#endif
1652
Paul Sokolovsky1b146e92017-11-08 19:45:18 +02001653#ifndef MP_HTOBE16
1654#if MP_ENDIANNESS_LITTLE
Damien Georgefeb25772020-03-20 21:47:07 +11001655#define MP_HTOBE16(x) ((uint16_t)((((x) & 0xff) << 8) | (((x) >> 8) & 0xff)))
Damien George69661f32020-02-27 15:36:53 +11001656#define MP_BE16TOH(x) MP_HTOBE16(x)
Paul Sokolovsky1b146e92017-11-08 19:45:18 +02001657#else
Damien George69661f32020-02-27 15:36:53 +11001658#define MP_HTOBE16(x) (x)
1659#define MP_BE16TOH(x) (x)
Paul Sokolovsky1b146e92017-11-08 19:45:18 +02001660#endif
1661#endif
1662
1663#ifndef MP_HTOBE32
1664#if MP_ENDIANNESS_LITTLE
Damien Georgefeb25772020-03-20 21:47:07 +11001665#define MP_HTOBE32(x) ((uint32_t)((((x) & 0xff) << 24) | (((x) & 0xff00) << 8) | (((x) >> 8) & 0xff00) | (((x) >> 24) & 0xff)))
Damien George69661f32020-02-27 15:36:53 +11001666#define MP_BE32TOH(x) MP_HTOBE32(x)
Paul Sokolovsky1b146e92017-11-08 19:45:18 +02001667#else
Damien George69661f32020-02-27 15:36:53 +11001668#define MP_HTOBE32(x) (x)
1669#define MP_BE32TOH(x) (x)
Paul Sokolovsky1b146e92017-11-08 19:45:18 +02001670#endif
1671#endif
1672
Paul Sokolovsky2f5d1132018-12-21 14:20:55 +03001673// Warning categories are by default implemented as strings, though
1674// hook is left for a port to define them as something else.
1675#if MICROPY_WARNINGS_CATEGORY
Damien George69661f32020-02-27 15:36:53 +11001676#ifndef MP_WARN_CAT
1677#define MP_WARN_CAT(x) #x
1678#endif
Paul Sokolovsky2f5d1132018-12-21 14:20:55 +03001679#else
Damien George69661f32020-02-27 15:36:53 +11001680#undef MP_WARN_CAT
1681#define MP_WARN_CAT(x) (NULL)
Paul Sokolovsky2f5d1132018-12-21 14:20:55 +03001682#endif
1683
Milan Rossa310b3d12019-08-14 16:09:36 +02001684// Feature dependency check.
1685#if MICROPY_PY_SYS_SETTRACE
1686#if !MICROPY_PERSISTENT_CODE_SAVE
1687#error "MICROPY_PY_SYS_SETTRACE requires MICROPY_PERSISTENT_CODE_SAVE to be enabled"
1688#endif
1689#if MICROPY_COMP_CONST
1690#error "MICROPY_PY_SYS_SETTRACE requires MICROPY_COMP_CONST to be disabled"
1691#endif
1692#endif
1693
Alexander Steffen299bc622017-06-29 23:14:58 +02001694#endif // MICROPY_INCLUDED_PY_MPCONFIG_H