blob: 2934f8ec89ee30b67a062e65380de4da5cc6b949 [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 George321d1892021-04-19 00:11:51 +100031#define MICROPY_VERSION_MINOR 15
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
Damien Georgead4656b2021-02-04 16:39:09 +1100129#define MICROPY_BYTES_PER_GC_BLOCK (4 * MP_BYTES_PER_OBJ_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
matejcik1a2ffda2021-03-22 11:20:22 +0100232// Initial size of sys.modules dict
233#ifndef MICROPY_LOADED_MODULES_DICT_SIZE
234#define MICROPY_LOADED_MODULES_DICT_SIZE (3)
235#endif
236
Damien Georged8914522015-02-27 09:54:12 +0000237// Whether realloc/free should be passed allocated memory region size
238// You must enable this if MICROPY_MEM_STATS is enabled
239#ifndef MICROPY_MALLOC_USES_ALLOCATED_SIZE
240#define MICROPY_MALLOC_USES_ALLOCATED_SIZE (0)
241#endif
242
Damien George95836f82015-01-11 22:27:30 +0000243// Number of bytes used to store qstr length
244// Dictates hard limit on maximum Python identifier length, but 1 byte
245// (limit of 255 bytes in an identifier) should be enough for everyone
246#ifndef MICROPY_QSTR_BYTES_IN_LEN
247#define MICROPY_QSTR_BYTES_IN_LEN (1)
248#endif
249
Damien Georgec3bd9412015-07-20 11:03:13 +0000250// Number of bytes used to store qstr hash
251#ifndef MICROPY_QSTR_BYTES_IN_HASH
252#define MICROPY_QSTR_BYTES_IN_HASH (2)
253#endif
254
Paul Sokolovsky7f1c9812015-03-28 01:14:45 +0200255// Avoid using C stack when making Python function calls. C stack still
256// may be used if there's no free heap.
Paul Sokolovsky20397572015-03-28 01:14:44 +0200257#ifndef MICROPY_STACKLESS
258#define MICROPY_STACKLESS (0)
259#endif
260
Paul Sokolovsky7f1c9812015-03-28 01:14:45 +0200261// Never use C stack when making Python function calls. This may break
262// testsuite as will subtly change which exception is thrown in case
263// of too deep recursion and other similar cases.
264#ifndef MICROPY_STACKLESS_STRICT
265#define MICROPY_STACKLESS_STRICT (0)
266#endif
267
Paul Sokolovskyf32020e2015-11-25 23:22:31 +0200268// Don't use alloca calls. As alloca() is not part of ANSI C, this
269// workaround option is provided for compilers lacking this de-facto
270// standard function. The way it works is allocating from heap, and
271// relying on garbage collection to free it eventually. This is of
272// course much less optimal than real alloca().
273#if defined(MICROPY_NO_ALLOCA) && MICROPY_NO_ALLOCA
274#undef alloca
275#define alloca(x) m_malloc(x)
276#endif
277
Damien George66e18f02014-05-05 13:19:03 +0100278/*****************************************************************************/
Damien Georgec408ed92017-06-26 12:29:20 +1000279/* MicroPython emitters */
Damien George136f6752014-01-07 14:54:15 +0000280
Damien Georged8c834c2015-11-02 21:55:42 +0000281// Whether to support loading of persistent code
282#ifndef MICROPY_PERSISTENT_CODE_LOAD
283#define MICROPY_PERSISTENT_CODE_LOAD (0)
284#endif
285
286// Whether to support saving of persistent code
287#ifndef MICROPY_PERSISTENT_CODE_SAVE
288#define MICROPY_PERSISTENT_CODE_SAVE (0)
289#endif
290
David CARLIERcb309282021-01-16 20:48:19 +0000291// Whether to support saving persistent code to a file via mp_raw_code_save_file
292#ifndef MICROPY_PERSISTENT_CODE_SAVE_FILE
293#define MICROPY_PERSISTENT_CODE_SAVE_FILE (0)
294#endif
295
Damien Georgec8e9c0d2015-11-02 17:27:18 +0000296// Whether generated code can persist independently of the VM/runtime instance
Damien Georged8c834c2015-11-02 21:55:42 +0000297// This is enabled automatically when needed by other features
Damien Georgec8e9c0d2015-11-02 17:27:18 +0000298#ifndef MICROPY_PERSISTENT_CODE
Damien George0a2e9652016-01-31 22:24:16 +0000299#define MICROPY_PERSISTENT_CODE (MICROPY_PERSISTENT_CODE_LOAD || MICROPY_PERSISTENT_CODE_SAVE || MICROPY_MODULE_FROZEN_MPY)
Damien Georgec8e9c0d2015-11-02 17:27:18 +0000300#endif
301
Damien George136f6752014-01-07 14:54:15 +0000302// Whether to emit x64 native code
303#ifndef MICROPY_EMIT_X64
304#define MICROPY_EMIT_X64 (0)
305#endif
306
Damien Georgec90f59e2014-09-06 23:06:36 +0100307// Whether to emit x86 native code
308#ifndef MICROPY_EMIT_X86
309#define MICROPY_EMIT_X86 (0)
310#endif
311
Damien George136f6752014-01-07 14:54:15 +0000312// Whether to emit thumb native code
313#ifndef MICROPY_EMIT_THUMB
314#define MICROPY_EMIT_THUMB (0)
315#endif
316
graham sanderson40d20102020-12-12 13:04:10 -0600317// Whether to emit ARMv7-M instruction support in thumb native code
318#ifndef MICROPY_EMIT_THUMB_ARMV7M
319#define MICROPY_EMIT_THUMB_ARMV7M (1)
320#endif
321
Damien George136f6752014-01-07 14:54:15 +0000322// Whether to enable the thumb inline assembler
323#ifndef MICROPY_EMIT_INLINE_THUMB
324#define MICROPY_EMIT_INLINE_THUMB (0)
325#endif
326
Damien Georgee8135412015-10-16 22:08:57 +0100327// Whether to enable ARMv7-M instruction support in the Thumb2 inline assembler
328#ifndef MICROPY_EMIT_INLINE_THUMB_ARMV7M
329#define MICROPY_EMIT_INLINE_THUMB_ARMV7M (1)
330#endif
331
=50089722015-04-14 13:14:57 +0100332// Whether to enable float support in the Thumb2 inline assembler
333#ifndef MICROPY_EMIT_INLINE_THUMB_FLOAT
334#define MICROPY_EMIT_INLINE_THUMB_FLOAT (1)
335#endif
336
Fabian Vogtfe3d16e2014-08-16 22:55:53 +0200337// Whether to emit ARM native code
338#ifndef MICROPY_EMIT_ARM
339#define MICROPY_EMIT_ARM (0)
340#endif
341
Damien George8e5aced2016-12-09 16:39:39 +1100342// Whether to emit Xtensa native code
343#ifndef MICROPY_EMIT_XTENSA
344#define MICROPY_EMIT_XTENSA (0)
345#endif
346
Damien Georgef76b1bf2016-12-09 17:03:33 +1100347// Whether to enable the Xtensa inline assembler
348#ifndef MICROPY_EMIT_INLINE_XTENSA
349#define MICROPY_EMIT_INLINE_XTENSA (0)
350#endif
351
Damien George9adedce2019-09-13 13:15:12 +1000352// Whether to emit Xtensa-Windowed native code
353#ifndef MICROPY_EMIT_XTENSAWIN
354#define MICROPY_EMIT_XTENSAWIN (0)
355#endif
356
Damien George2ac4af62014-08-15 16:45:41 +0100357// Convenience definition for whether any native emitter is enabled
Damien George9adedce2019-09-13 13:15:12 +1000358#define MICROPY_EMIT_NATIVE (MICROPY_EMIT_X64 || MICROPY_EMIT_X86 || MICROPY_EMIT_THUMB || MICROPY_EMIT_ARM || MICROPY_EMIT_XTENSA || MICROPY_EMIT_XTENSAWIN)
359
360// Select prelude-as-bytes-object for certain emitters
361#define MICROPY_EMIT_NATIVE_PRELUDE_AS_BYTES_OBJ (MICROPY_EMIT_XTENSAWIN)
Damien George2ac4af62014-08-15 16:45:41 +0100362
Damien Georgead297a12016-12-09 13:17:49 +1100363// Convenience definition for whether any inline assembler emitter is enabled
Damien Georgef76b1bf2016-12-09 17:03:33 +1100364#define MICROPY_EMIT_INLINE_ASM (MICROPY_EMIT_INLINE_THUMB || MICROPY_EMIT_INLINE_XTENSA)
Damien Georgead297a12016-12-09 13:17:49 +1100365
Jun Wub152bbd2019-05-06 00:31:11 -0700366// Convenience definition for whether any native or inline assembler emitter is enabled
367#define MICROPY_EMIT_MACHINE_CODE (MICROPY_EMIT_NATIVE || MICROPY_EMIT_INLINE_ASM)
368
Damien George9883d8e2020-07-27 23:52:38 +1000369// Whether native relocatable code loaded from .mpy files is explicitly tracked
370// so that the GC cannot reclaim it. Needed on architectures that allocate
371// executable memory on the MicroPython heap and don't explicitly track this
372// data some other way.
373#ifndef MICROPY_PERSISTENT_CODE_TRACK_RELOC_CODE
374#if !MICROPY_EMIT_MACHINE_CODE || defined(MP_PLAT_ALLOC_EXEC) || defined(MP_PLAT_COMMIT_EXEC)
375#define MICROPY_PERSISTENT_CODE_TRACK_RELOC_CODE (0)
376#else
377#define MICROPY_PERSISTENT_CODE_TRACK_RELOC_CODE (1)
378#endif
379#endif
380
Damien George136f6752014-01-07 14:54:15 +0000381/*****************************************************************************/
Damien George58ebde42014-05-21 20:32:59 +0100382/* Compiler configuration */
383
Damien Georgedd5353a2015-12-18 12:35:44 +0000384// Whether to include the compiler
385#ifndef MICROPY_ENABLE_COMPILER
386#define MICROPY_ENABLE_COMPILER (1)
387#endif
388
Damien Georgeea235202016-02-11 22:30:53 +0000389// Whether the compiler is dynamically configurable (ie at runtime)
Damien Georgea4f1d822019-05-29 21:17:29 +1000390// This will disable the ability to execute native/viper code
Damien Georgeea235202016-02-11 22:30:53 +0000391#ifndef MICROPY_DYNAMIC_COMPILER
392#define MICROPY_DYNAMIC_COMPILER (0)
393#endif
394
395// Configure dynamic compiler macros
396#if MICROPY_DYNAMIC_COMPILER
397#define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE_DYNAMIC (mp_dynamic_compiler.opt_cache_map_lookup_in_bytecode)
398#define MICROPY_PY_BUILTINS_STR_UNICODE_DYNAMIC (mp_dynamic_compiler.py_builtins_str_unicode)
399#else
400#define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE_DYNAMIC MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE
401#define MICROPY_PY_BUILTINS_STR_UNICODE_DYNAMIC MICROPY_PY_BUILTINS_STR_UNICODE
402#endif
403
Damien George64f2b212015-10-08 14:58:15 +0100404// Whether to enable constant folding; eg 1+2 rewritten as 3
405#ifndef MICROPY_COMP_CONST_FOLDING
406#define MICROPY_COMP_CONST_FOLDING (1)
407#endif
408
Damien George07796932019-02-27 00:10:04 +1100409// Whether to enable optimisations for constant literals, eg OrderedDict
410#ifndef MICROPY_COMP_CONST_LITERAL
411#define MICROPY_COMP_CONST_LITERAL (1)
412#endif
413
Damien Georgeddd1e182015-01-10 14:07:24 +0000414// Whether to enable lookup of constants in modules; eg module.CONST
415#ifndef MICROPY_COMP_MODULE_CONST
416#define MICROPY_COMP_MODULE_CONST (0)
417#endif
418
Damien George58ebde42014-05-21 20:32:59 +0100419// Whether to enable constant optimisation; id = const(value)
420#ifndef MICROPY_COMP_CONST
421#define MICROPY_COMP_CONST (1)
422#endif
423
Damien George42e0c592015-03-14 13:11:35 +0000424// Whether to enable optimisation of: a, b = c, d
425// Costs 124 bytes (Thumb2)
426#ifndef MICROPY_COMP_DOUBLE_TUPLE_ASSIGN
427#define MICROPY_COMP_DOUBLE_TUPLE_ASSIGN (1)
428#endif
429
430// Whether to enable optimisation of: a, b, c = d, e, f
Damien George253f2bd2018-02-04 13:35:21 +1100431// Requires MICROPY_COMP_DOUBLE_TUPLE_ASSIGN and costs 68 bytes (Thumb2)
Damien George42e0c592015-03-14 13:11:35 +0000432#ifndef MICROPY_COMP_TRIPLE_TUPLE_ASSIGN
433#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (0)
434#endif
435
Damien Georgeae54fbf2017-04-22 14:58:01 +1000436// Whether to enable optimisation of: return a if b else c
437// Costs about 80 bytes (Thumb2) and saves 2 bytes of bytecode for each use
438#ifndef MICROPY_COMP_RETURN_IF_EXPR
439#define MICROPY_COMP_RETURN_IF_EXPR (0)
440#endif
441
Damien George58ebde42014-05-21 20:32:59 +0100442/*****************************************************************************/
Damien George136f6752014-01-07 14:54:15 +0000443/* Internal debugging stuff */
444
445// Whether to collect memory allocation stats
446#ifndef MICROPY_MEM_STATS
447#define MICROPY_MEM_STATS (0)
448#endif
449
Damien Georgeda2d2b62018-08-02 14:04:44 +1000450// The mp_print_t printer used for debugging output
451#ifndef MICROPY_DEBUG_PRINTER
452#define MICROPY_DEBUG_PRINTER (&mp_plat_print)
453#endif
454
Damien Georgecbd2f742014-01-19 11:48:48 +0000455// Whether to build functions that print debugging info:
Damien George3417bc22014-05-10 10:36:38 +0100456// mp_bytecode_print
Damien Georgecbd2f742014-01-19 11:48:48 +0000457// mp_parse_node_print
458#ifndef MICROPY_DEBUG_PRINTERS
459#define MICROPY_DEBUG_PRINTERS (0)
Damien Georged3ebe482014-01-07 15:20:33 +0000460#endif
461
Stefan Naumannace9fb52017-07-24 18:55:14 +0200462// Whether to enable all debugging outputs (it will be extremely verbose)
463#ifndef MICROPY_DEBUG_VERBOSE
464#define MICROPY_DEBUG_VERBOSE (0)
465#endif
466
Damien George02cc2882019-03-08 15:48:20 +1100467// Whether to enable debugging versions of MP_OBJ_NULL/STOP_ITERATION/SENTINEL
468#ifndef MICROPY_DEBUG_MP_OBJ_SENTINELS
469#define MICROPY_DEBUG_MP_OBJ_SENTINELS (0)
470#endif
471
Damien George843dcd42020-09-30 23:34:42 +1000472// Whether to print parse rule names (rather than integers) in mp_parse_node_print
473#ifndef MICROPY_DEBUG_PARSE_RULE_NAME
474#define MICROPY_DEBUG_PARSE_RULE_NAME (0)
475#endif
476
Damien George6d199342019-01-04 17:09:41 +1100477// Whether to enable a simple VM stack overflow check
478#ifndef MICROPY_DEBUG_VM_STACK_OVERFLOW
479#define MICROPY_DEBUG_VM_STACK_OVERFLOW (0)
480#endif
481
Damien George136f6752014-01-07 14:54:15 +0000482/*****************************************************************************/
Damien Georgeee3fd462014-05-24 23:03:12 +0100483/* Optimisations */
484
485// Whether to use computed gotos in the VM, or a switch
486// Computed gotos are roughly 10% faster, and increase VM code size by a little
Damien George44f0a4d2017-09-18 23:53:33 +1000487// Note: enabling this will use the gcc-specific extensions of ranged designated
488// initialisers and addresses of labels, which are not part of the C99 standard.
Damien Georgeee3fd462014-05-24 23:03:12 +0100489#ifndef MICROPY_OPT_COMPUTED_GOTO
490#define MICROPY_OPT_COMPUTED_GOTO (0)
491#endif
492
Damien George7ee91cf2015-01-06 12:51:39 +0000493// Whether to cache result of map lookups in LOAD_NAME, LOAD_GLOBAL, LOAD_ATTR,
494// STORE_ATTR bytecodes. Uses 1 byte extra RAM for each of these opcodes and
495// uses a bit of extra code ROM, but greatly improves lookup speed.
496#ifndef MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE
497#define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE (0)
498#endif
499
Doug Currie2e2e15c2016-01-30 22:35:58 -0500500// Whether to use fast versions of bitwise operations (and, or, xor) when the
501// arguments are both positive. Increases Thumb2 code size by about 250 bytes.
502#ifndef MICROPY_OPT_MPZ_BITWISE
503#define MICROPY_OPT_MPZ_BITWISE (0)
504#endif
505
Christopher Swenson8c656752018-08-27 10:32:21 +1000506
507// Whether math.factorial is large, fast and recursive (1) or small and slow (0).
508#ifndef MICROPY_OPT_MATH_FACTORIAL
509#define MICROPY_OPT_MATH_FACTORIAL (0)
510#endif
511
Damien Georgeee3fd462014-05-24 23:03:12 +0100512/*****************************************************************************/
513/* Python internal features */
Damien George136f6752014-01-07 14:54:15 +0000514
Damien George20993682018-02-20 18:00:44 +1100515// Whether to enable import of external modules
516// When disabled, only importing of built-in modules is supported
517// When enabled, a port must implement mp_import_stat (among other things)
518#ifndef MICROPY_ENABLE_EXTERNAL_IMPORT
519#define MICROPY_ENABLE_EXTERNAL_IMPORT (1)
520#endif
521
Damien George6b239c22016-11-16 16:04:57 +1100522// Whether to use the POSIX reader for importing files
523#ifndef MICROPY_READER_POSIX
524#define MICROPY_READER_POSIX (0)
525#endif
526
Damien Georgedcb9ea72017-01-27 15:10:09 +1100527// Whether to use the VFS reader for importing files
528#ifndef MICROPY_READER_VFS
529#define MICROPY_READER_VFS (0)
530#endif
531
Sean Burtone33bc592018-12-13 12:10:35 +0000532// Whether any readers have been defined
533#ifndef MICROPY_HAS_FILE_READER
534#define MICROPY_HAS_FILE_READER (MICROPY_READER_POSIX || MICROPY_READER_VFS)
535#endif
536
Damien George40d84302016-02-15 22:46:21 +0000537// Hook for the VM at the start of the opcode loop (can contain variable
538// definitions usable by the other hook functions)
539#ifndef MICROPY_VM_HOOK_INIT
540#define MICROPY_VM_HOOK_INIT
541#endif
542
543// Hook for the VM during the opcode loop (but only after jump opcodes)
544#ifndef MICROPY_VM_HOOK_LOOP
545#define MICROPY_VM_HOOK_LOOP
546#endif
547
548// Hook for the VM just before return opcode is finished being interpreted
549#ifndef MICROPY_VM_HOOK_RETURN
550#define MICROPY_VM_HOOK_RETURN
551#endif
552
Damien Georged3ebe482014-01-07 15:20:33 +0000553// Whether to include the garbage collector
554#ifndef MICROPY_ENABLE_GC
555#define MICROPY_ENABLE_GC (0)
556#endif
557
Damien George12bab722014-04-05 20:35:48 +0100558// Whether to enable finalisers in the garbage collector (ie call __del__)
Damien George7860c2a2014-11-05 21:16:41 +0000559#ifndef MICROPY_ENABLE_FINALISER
560#define MICROPY_ENABLE_FINALISER (0)
Damien George12bab722014-04-05 20:35:48 +0100561#endif
562
Damien George02d830c2017-11-26 23:28:40 +1100563// Whether to enable a separate allocator for the Python stack.
564// If enabled then the code must call mp_pystack_init before mp_init.
565#ifndef MICROPY_ENABLE_PYSTACK
566#define MICROPY_ENABLE_PYSTACK (0)
567#endif
568
569// Number of bytes that memory returned by mp_pystack_alloc will be aligned by.
570#ifndef MICROPY_PYSTACK_ALIGN
571#define MICROPY_PYSTACK_ALIGN (8)
572#endif
573
Paul Sokolovsky23668692014-06-25 03:03:34 +0300574// Whether to check C stack usage. C stack used for calling Python functions,
575// etc. Not checking means segfault on overflow.
576#ifndef MICROPY_STACK_CHECK
Damien George4a5895c2015-01-09 00:10:55 +0000577#define MICROPY_STACK_CHECK (0)
Paul Sokolovsky23668692014-06-25 03:03:34 +0300578#endif
579
Dave Hylands5b7fd202014-07-01 23:46:53 -0700580// Whether to have an emergency exception buffer
581#ifndef MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
582#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (0)
583#endif
584#if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
Damien George69661f32020-02-27 15:36:53 +1100585#ifndef MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE
586#define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (0) // 0 - implies dynamic allocation
587#endif
Dave Hylands5b7fd202014-07-01 23:46:53 -0700588#endif
589
Damien Georgebbb4b982017-04-10 17:19:36 +1000590// Whether to provide the mp_kbd_exception object, and micropython.kbd_intr function
Damien George7f1da0a2016-12-15 13:00:19 +1100591#ifndef MICROPY_KBD_EXCEPTION
592#define MICROPY_KBD_EXCEPTION (0)
593#endif
594
Paul Sokolovsky1c9210b2015-12-23 00:06:37 +0200595// Prefer to raise KeyboardInterrupt asynchronously (from signal or interrupt
596// handler) - if supported by a particular port.
597#ifndef MICROPY_ASYNC_KBD_INTR
598#define MICROPY_ASYNC_KBD_INTR (0)
599#endif
600
Damien George136f6752014-01-07 14:54:15 +0000601// Whether to include REPL helper function
Damien George58ebde42014-05-21 20:32:59 +0100602#ifndef MICROPY_HELPER_REPL
603#define MICROPY_HELPER_REPL (0)
Damien George136f6752014-01-07 14:54:15 +0000604#endif
605
Yonatan Goldschmidt61d2b402019-12-25 09:27:38 +0200606// Allow enabling debug prints after each REPL line
607#ifndef MICROPY_REPL_INFO
608#define MICROPY_REPL_INFO (0)
609#endif
610
Tom Soulanille7d588b02015-07-09 16:32:36 -0700611// Whether to include emacs-style readline behavior in REPL
612#ifndef MICROPY_REPL_EMACS_KEYS
Damien Georged8a7f8b2015-07-26 15:49:13 +0100613#define MICROPY_REPL_EMACS_KEYS (0)
Tom Soulanille7d588b02015-07-09 16:32:36 -0700614#endif
615
Yonatan Goldschmidt853aaa02019-12-14 23:42:03 +0200616// Whether to include emacs-style word movement/kill readline behavior in REPL.
617// This adds Alt+F, Alt+B, Alt+D and Alt+Backspace for forward-word, backward-word, forward-kill-word
618// and backward-kill-word, respectively.
619#ifndef MICROPY_REPL_EMACS_WORDS_MOVE
620#define MICROPY_REPL_EMACS_WORDS_MOVE (0)
621#endif
622
623// Whether to include extra convenience keys for word movement/kill in readline REPL.
624// This adds Ctrl+Right, Ctrl+Left and Ctrl+W for forward-word, backward-word and backward-kill-word
625// respectively. Ctrl+Delete is not implemented because it's a very different escape sequence.
626// Depends on MICROPY_REPL_EMACS_WORDS_MOVE.
627#ifndef MICROPY_REPL_EMACS_EXTRA_WORDS_MOVE
628#define MICROPY_REPL_EMACS_EXTRA_WORDS_MOVE (0)
629#endif
630
Damien George0af73012015-08-20 10:34:16 +0100631// Whether to implement auto-indent in REPL
632#ifndef MICROPY_REPL_AUTO_INDENT
633#define MICROPY_REPL_AUTO_INDENT (0)
634#endif
635
Paul Sokolovsky87bc8e22015-01-15 10:46:27 +0200636// Whether port requires event-driven REPL functions
637#ifndef MICROPY_REPL_EVENT_DRIVEN
638#define MICROPY_REPL_EVENT_DRIVEN (0)
639#endif
640
Damien Georged3ebe482014-01-07 15:20:33 +0000641// Whether to include lexer helper function for unix
Damien George58ebde42014-05-21 20:32:59 +0100642#ifndef MICROPY_HELPER_LEXER_UNIX
643#define MICROPY_HELPER_LEXER_UNIX (0)
Damien Georged3ebe482014-01-07 15:20:33 +0000644#endif
645
Paul Sokolovsky48b35722014-01-12 17:30:48 +0200646// Long int implementation
647#define MICROPY_LONGINT_IMPL_NONE (0)
648#define MICROPY_LONGINT_IMPL_LONGLONG (1)
Damien George438c88d2014-02-22 19:25:23 +0000649#define MICROPY_LONGINT_IMPL_MPZ (2)
Paul Sokolovsky48b35722014-01-12 17:30:48 +0200650
651#ifndef MICROPY_LONGINT_IMPL
652#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_NONE)
653#endif
654
655#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG
656typedef long long mp_longint_impl_t;
657#endif
658
Damien George62ad1892014-01-29 21:51:51 +0000659// Whether to include information in the byte code to determine source
660// line number (increases RAM usage, but doesn't slow byte code execution)
661#ifndef MICROPY_ENABLE_SOURCE_LINE
662#define MICROPY_ENABLE_SOURCE_LINE (0)
663#endif
664
Damien George1463c1f2014-04-25 23:52:57 +0100665// Whether to include doc strings (increases RAM usage)
666#ifndef MICROPY_ENABLE_DOC_STRING
667#define MICROPY_ENABLE_DOC_STRING (0)
668#endif
669
Damien Georged4b706c2021-04-22 12:13:58 +1000670// Exception messages are removed (requires disabling MICROPY_ROM_TEXT_COMPRESSION)
671#define MICROPY_ERROR_REPORTING_NONE (0)
Damien George1e9a92f2014-11-06 17:36:16 +0000672// Exception messages are short static strings
Paul Sokolovsky1f85d622014-05-01 01:35:38 +0300673#define MICROPY_ERROR_REPORTING_TERSE (1)
674// Exception messages provide basic error details
675#define MICROPY_ERROR_REPORTING_NORMAL (2)
676// Exception messages provide full info, e.g. object names
677#define MICROPY_ERROR_REPORTING_DETAILED (3)
678
679#ifndef MICROPY_ERROR_REPORTING
680#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_NORMAL)
681#endif
682
Paul Sokolovsky8a8c1fc2015-01-01 09:29:28 +0200683// Whether issue warnings during compiling/execution
684#ifndef MICROPY_WARNINGS
685#define MICROPY_WARNINGS (0)
686#endif
687
Paul Sokolovsky2f5d1132018-12-21 14:20:55 +0300688// Whether to support warning categories
689#ifndef MICROPY_WARNINGS_CATEGORY
690#define MICROPY_WARNINGS_CATEGORY (0)
691#endif
692
David Lechner62849b72017-09-24 20:15:48 -0500693// This macro is used when printing runtime warnings and errors
694#ifndef MICROPY_ERROR_PRINTER
695#define MICROPY_ERROR_PRINTER (&mp_plat_print)
696#endif
697
Damien George0c36da02014-03-08 15:24:39 +0000698// Float and complex implementation
699#define MICROPY_FLOAT_IMPL_NONE (0)
700#define MICROPY_FLOAT_IMPL_FLOAT (1)
701#define MICROPY_FLOAT_IMPL_DOUBLE (2)
702
703#ifndef MICROPY_FLOAT_IMPL
704#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_NONE)
705#endif
706
707#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
Damien Georgefb510b32014-06-01 13:32:54 +0100708#define MICROPY_PY_BUILTINS_FLOAT (1)
Damien George561844f2016-11-03 12:33:01 +1100709#define MICROPY_FLOAT_CONST(x) x##F
Damien George0c36da02014-03-08 15:24:39 +0000710#define MICROPY_FLOAT_C_FUN(fun) fun##f
711typedef float mp_float_t;
712#elif MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE
Damien Georgefb510b32014-06-01 13:32:54 +0100713#define MICROPY_PY_BUILTINS_FLOAT (1)
Damien George561844f2016-11-03 12:33:01 +1100714#define MICROPY_FLOAT_CONST(x) x
Damien George0c36da02014-03-08 15:24:39 +0000715#define MICROPY_FLOAT_C_FUN(fun) fun
716typedef double mp_float_t;
717#else
Damien Georgefb510b32014-06-01 13:32:54 +0100718#define MICROPY_PY_BUILTINS_FLOAT (0)
Damien George136f6752014-01-07 14:54:15 +0000719#endif
720
Paul Sokolovsky3b6f7b92014-06-20 01:48:35 +0300721#ifndef MICROPY_PY_BUILTINS_COMPLEX
722#define MICROPY_PY_BUILTINS_COMPLEX (MICROPY_PY_BUILTINS_FLOAT)
723#endif
724
Damien Georgea73501b2017-04-06 17:27:33 +1000725// Whether to provide a high-quality hash for float and complex numbers.
726// Otherwise the default is a very simple but correct hashing function.
727#ifndef MICROPY_FLOAT_HIGH_QUALITY_HASH
728#define MICROPY_FLOAT_HIGH_QUALITY_HASH (0)
729#endif
730
Paul Sokolovskydcac8802014-01-16 19:19:50 +0200731// Enable features which improve CPython compatibility
732// but may lead to more code size/memory usage.
733// TODO: Originally intended as generic category to not
734// add bunch of once-off options. May need refactoring later
735#ifndef MICROPY_CPYTHON_COMPAT
736#define MICROPY_CPYTHON_COMPAT (1)
737#endif
738
Paul Sokolovsky9a973972017-04-02 21:20:07 +0300739// Perform full checks as done by CPython. Disabling this
740// may produce incorrect results, if incorrect data is fed,
741// but should not lead to MicroPython crashes or similar
742// grave issues (in other words, only user app should be,
743// affected, not system).
744#ifndef MICROPY_FULL_CHECKS
745#define MICROPY_FULL_CHECKS (1)
746#endif
747
Paul Sokolovsky0ef015b2014-05-07 02:23:46 +0300748// Whether POSIX-semantics non-blocking streams are supported
749#ifndef MICROPY_STREAMS_NON_BLOCK
750#define MICROPY_STREAMS_NON_BLOCK (0)
751#endif
752
Paul Sokolovsky61e77a42016-07-30 20:05:56 +0300753// Whether to provide stream functions with POSIX-like signatures
754// (useful for porting existing libraries to MicroPython).
755#ifndef MICROPY_STREAMS_POSIX_API
756#define MICROPY_STREAMS_POSIX_API (0)
757#endif
758
Damien George3c9c3682015-09-15 14:56:13 +0100759// Whether to call __init__ when importing builtin modules for the first time
760#ifndef MICROPY_MODULE_BUILTIN_INIT
761#define MICROPY_MODULE_BUILTIN_INIT (0)
762#endif
763
Paul m. p. P454cca62018-10-22 18:34:29 +0200764// Whether to support module-level __getattr__ (see PEP 562)
765#ifndef MICROPY_MODULE_GETATTR
Damien Georgef8fc7862020-03-01 00:06:15 +1100766#define MICROPY_MODULE_GETATTR (1)
Paul m. p. P454cca62018-10-22 18:34:29 +0200767#endif
768
Damien Georgec14a8162014-10-12 11:46:04 +0100769// Whether module weak links are supported
770#ifndef MICROPY_MODULE_WEAK_LINKS
771#define MICROPY_MODULE_WEAK_LINKS (0)
772#endif
773
Damien George0a2e9652016-01-31 22:24:16 +0000774// Whether frozen modules are supported in the form of strings
775#ifndef MICROPY_MODULE_FROZEN_STR
776#define MICROPY_MODULE_FROZEN_STR (0)
777#endif
778
779// Whether frozen modules are supported in the form of .mpy files
780#ifndef MICROPY_MODULE_FROZEN_MPY
781#define MICROPY_MODULE_FROZEN_MPY (0)
782#endif
783
784// Convenience macro for whether frozen modules are supported
Paul Sokolovsky640e0b22015-01-20 11:52:12 +0200785#ifndef MICROPY_MODULE_FROZEN
Damien George0a2e9652016-01-31 22:24:16 +0000786#define MICROPY_MODULE_FROZEN (MICROPY_MODULE_FROZEN_STR || MICROPY_MODULE_FROZEN_MPY)
Paul Sokolovsky640e0b22015-01-20 11:52:12 +0200787#endif
788
Damien George78d702c2014-12-09 16:19:48 +0000789// Whether you can override builtins in the builtins module
790#ifndef MICROPY_CAN_OVERRIDE_BUILTINS
791#define MICROPY_CAN_OVERRIDE_BUILTINS (0)
792#endif
793
Damien George06593fb2015-06-19 12:49:10 +0000794// Whether to check that the "self" argument of a builtin method has the
795// correct type. Such an explicit check is only needed if a builtin
796// method escapes to Python land without a first argument, eg
797// list.append([], 1). Without this check such calls will have undefined
798// behaviour (usually segfault) if the first argument is the wrong type.
799#ifndef MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG
800#define MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG (1)
801#endif
802
Damien George3f56fd62016-05-10 10:54:06 +0100803// Whether to use internally defined errno's (otherwise system provided ones)
804#ifndef MICROPY_USE_INTERNAL_ERRNO
805#define MICROPY_USE_INTERNAL_ERRNO (0)
806#endif
807
Delio Brignolie2ac8bb2016-08-21 11:33:37 +0200808// Whether to use internally defined *printf() functions (otherwise external ones)
809#ifndef MICROPY_USE_INTERNAL_PRINTF
810#define MICROPY_USE_INTERNAL_PRINTF (1)
811#endif
812
Damien George6e74d242017-02-16 18:05:06 +1100813// Support for internal scheduler
814#ifndef MICROPY_ENABLE_SCHEDULER
815#define MICROPY_ENABLE_SCHEDULER (0)
816#endif
817
818// Maximum number of entries in the scheduler
819#ifndef MICROPY_SCHEDULER_DEPTH
820#define MICROPY_SCHEDULER_DEPTH (4)
821#endif
822
Damien Georgedcb9ea72017-01-27 15:10:09 +1100823// Support for generic VFS sub-system
824#ifndef MICROPY_VFS
825#define MICROPY_VFS (0)
826#endif
827
Damien George8d82b0e2018-06-06 13:11:33 +1000828// Support for VFS POSIX component, to mount a POSIX filesystem within VFS
829#ifndef MICROPY_VFS
830#define MICROPY_VFS_POSIX (0)
831#endif
832
Damien Georgea8b9e712018-06-06 14:31:29 +1000833// Support for VFS FAT component, to mount a FAT filesystem within VFS
834#ifndef MICROPY_VFS
835#define MICROPY_VFS_FAT (0)
836#endif
837
Damien Georgeee3fd462014-05-24 23:03:12 +0100838/*****************************************************************************/
839/* Fine control over Python builtins, classes, modules, etc */
840
Damien Georgeda154fd2017-04-01 23:52:24 +1100841// Whether to support multiple inheritance of Python classes. Multiple
842// inheritance makes some C functions inherently recursive, and adds a bit of
843// code overhead.
844#ifndef MICROPY_MULTIPLE_INHERITANCE
845#define MICROPY_MULTIPLE_INHERITANCE (1)
846#endif
847
stijn3cc17c62015-02-14 18:44:31 +0100848// Whether to implement attributes on functions
849#ifndef MICROPY_PY_FUNCTION_ATTRS
850#define MICROPY_PY_FUNCTION_ATTRS (0)
851#endif
852
Damien George36c10522018-05-25 17:09:54 +1000853// Whether to support the descriptors __get__, __set__, __delete__
854// This costs some code size and makes load/store/delete of instance
855// attributes slower for the classes that use this feature
stijn28fa84b2015-02-14 18:43:54 +0100856#ifndef MICROPY_PY_DESCRIPTORS
857#define MICROPY_PY_DESCRIPTORS (0)
858#endif
859
dmazzella18e65692017-01-03 11:00:12 +0100860// Whether to support class __delattr__ and __setattr__ methods
Damien George36c10522018-05-25 17:09:54 +1000861// This costs some code size and makes store/delete of instance
862// attributes slower for the classes that use this feature
dmazzella18e65692017-01-03 11:00:12 +0100863#ifndef MICROPY_PY_DELATTR_SETATTR
864#define MICROPY_PY_DELATTR_SETATTR (0)
865#endif
866
pohmelie81ebba72016-01-27 23:23:11 +0300867// Support for async/await/async for/async with
868#ifndef MICROPY_PY_ASYNC_AWAIT
869#define MICROPY_PY_ASYNC_AWAIT (1)
870#endif
871
Damien George17839502020-06-16 21:42:44 +1000872// Support for assignment expressions with := (see PEP 572, Python 3.8+)
873#ifndef MICROPY_PY_ASSIGN_EXPR
874#define MICROPY_PY_ASSIGN_EXPR (1)
875#endif
876
Paul Sokolovsky63644012017-10-21 12:13:44 +0300877// Non-standard .pend_throw() method for generators, allowing for
878// Future-like behavior with respect to exception handling: an
879// exception set with .pend_throw() will activate on the next call
880// to generator's .send() or .__next__(). (This is useful to implement
881// async schedulers.)
882#ifndef MICROPY_PY_GENERATOR_PEND_THROW
883#define MICROPY_PY_GENERATOR_PEND_THROW (1)
884#endif
885
Paul Sokolovskya1b442b2016-07-22 00:46:24 +0300886// Issue a warning when comparing str and bytes objects
Paul Sokolovsky707cae72016-07-22 00:34:34 +0300887#ifndef MICROPY_PY_STR_BYTES_CMP_WARN
888#define MICROPY_PY_STR_BYTES_CMP_WARN (0)
889#endif
890
Paul Sokolovsky12bc13e2014-06-13 01:05:19 +0300891// Whether str object is proper unicode
892#ifndef MICROPY_PY_BUILTINS_STR_UNICODE
893#define MICROPY_PY_BUILTINS_STR_UNICODE (0)
Damien George8546ce12014-06-28 10:29:22 +0100894#endif
Damien Georgeb3a50f02014-06-28 10:27:15 +0100895
tll68c28172017-06-24 08:38:32 +0800896// Whether to check for valid UTF-8 when converting bytes to str
897#ifndef MICROPY_PY_BUILTINS_STR_UNICODE_CHECK
898#define MICROPY_PY_BUILTINS_STR_UNICODE_CHECK (MICROPY_PY_BUILTINS_STR_UNICODE)
899#endif
900
Paul Sokolovsky1b5abfc2016-05-22 00:13:44 +0300901// Whether str.center() method provided
902#ifndef MICROPY_PY_BUILTINS_STR_CENTER
903#define MICROPY_PY_BUILTINS_STR_CENTER (0)
904#endif
905
Paul Sokolovsky5a91fce2018-08-05 23:56:19 +0300906// Whether str.count() method provided
907#ifndef MICROPY_PY_BUILTINS_STR_COUNT
908#define MICROPY_PY_BUILTINS_STR_COUNT (1)
909#endif
910
Paul Sokolovsky2da5d412018-08-15 15:17:41 +0300911// Whether str % (...) formatting operator provided
912#ifndef MICROPY_PY_BUILTINS_STR_OP_MODULO
913#define MICROPY_PY_BUILTINS_STR_OP_MODULO (1)
914#endif
915
Paul Sokolovsky56eb25f2016-08-07 06:46:55 +0300916// Whether str.partition()/str.rpartition() method provided
917#ifndef MICROPY_PY_BUILTINS_STR_PARTITION
918#define MICROPY_PY_BUILTINS_STR_PARTITION (0)
919#endif
920
Paul Sokolovskyac2f7a72015-04-04 00:09:23 +0300921// Whether str.splitlines() method provided
922#ifndef MICROPY_PY_BUILTINS_STR_SPLITLINES
923#define MICROPY_PY_BUILTINS_STR_SPLITLINES (0)
924#endif
925
Paul Sokolovskycb78f862014-06-27 20:39:09 +0300926// Whether to support bytearray object
927#ifndef MICROPY_PY_BUILTINS_BYTEARRAY
928#define MICROPY_PY_BUILTINS_BYTEARRAY (1)
Paul Sokolovsky12bc13e2014-06-13 01:05:19 +0300929#endif
930
Paul Sokolovskyfbb83352018-08-06 01:25:41 +0300931// Whether to support dict.fromkeys() class method
932#ifndef MICROPY_PY_BUILTINS_DICT_FROMKEYS
933#define MICROPY_PY_BUILTINS_DICT_FROMKEYS (1)
934#endif
935
Damien Georgedd4f4532014-10-23 13:34:35 +0100936// Whether to support memoryview object
937#ifndef MICROPY_PY_BUILTINS_MEMORYVIEW
938#define MICROPY_PY_BUILTINS_MEMORYVIEW (0)
939#endif
940
stijn90fae912019-05-08 16:16:17 +0200941// Whether to support memoryview.itemsize attribute
942#ifndef MICROPY_PY_BUILTINS_MEMORYVIEW_ITEMSIZE
943#define MICROPY_PY_BUILTINS_MEMORYVIEW_ITEMSIZE (0)
944#endif
945
Damien George3ebd4d02014-06-01 13:46:47 +0100946// Whether to support set object
947#ifndef MICROPY_PY_BUILTINS_SET
948#define MICROPY_PY_BUILTINS_SET (1)
949#endif
950
Damien Georgefb510b32014-06-01 13:32:54 +0100951// Whether to support slice subscript operators and slice object
952#ifndef MICROPY_PY_BUILTINS_SLICE
953#define MICROPY_PY_BUILTINS_SLICE (1)
Damien Georgeee3fd462014-05-24 23:03:12 +0100954#endif
955
Tom Soulanilleaeb62f92015-09-11 14:31:32 -0700956// Whether to support slice attribute read access,
957// i.e. slice.start, slice.stop, slice.step
958#ifndef MICROPY_PY_BUILTINS_SLICE_ATTRS
959#define MICROPY_PY_BUILTINS_SLICE_ATTRS (0)
960#endif
961
Nicko van Someren4c939552019-11-16 17:07:11 -0700962// Whether to support the .indices(len) method on slice objects
963#ifndef MICROPY_PY_BUILTINS_SLICE_INDICES
964#define MICROPY_PY_BUILTINS_SLICE_INDICES (0)
965#endif
966
Damien Georgeee3fd462014-05-24 23:03:12 +0100967// Whether to support frozenset object
Damien Georgefb510b32014-06-01 13:32:54 +0100968#ifndef MICROPY_PY_BUILTINS_FROZENSET
969#define MICROPY_PY_BUILTINS_FROZENSET (0)
Damien Georgeee3fd462014-05-24 23:03:12 +0100970#endif
971
Damien Georgefb510b32014-06-01 13:32:54 +0100972// Whether to support property object
973#ifndef MICROPY_PY_BUILTINS_PROPERTY
974#define MICROPY_PY_BUILTINS_PROPERTY (1)
Damien Georgeee3fd462014-05-24 23:03:12 +0100975#endif
976
Peter D. Grayb2a237d2015-03-06 14:48:14 -0500977// Whether to implement the start/stop/step attributes (readback) on
978// the "range" builtin type. Rarely used, and costs ~60 bytes (x86).
979#ifndef MICROPY_PY_BUILTINS_RANGE_ATTRS
980#define MICROPY_PY_BUILTINS_RANGE_ATTRS (1)
981#endif
982
Damien Georged77da832018-02-14 23:17:06 +1100983// Whether to support binary ops [only (in)equality is defined] between range
984// objects. With this option disabled all range objects that are not exactly
985// the same object will compare as not-equal. With it enabled the semantics
986// match CPython and ranges are equal if they yield the same sequence of items.
987#ifndef MICROPY_PY_BUILTINS_RANGE_BINOP
988#define MICROPY_PY_BUILTINS_RANGE_BINOP (0)
989#endif
990
stijn42863832019-01-03 15:19:42 +0100991// Support for callling next() with second argument
992#ifndef MICROPY_PY_BUILTINS_NEXT2
993#define MICROPY_PY_BUILTINS_NEXT2 (0)
994#endif
995
Jan Klusacekb318ebf2018-01-09 22:47:35 +0100996// Whether to support rounding of integers (incl bignum); eg round(123,-1)=120
997#ifndef MICROPY_PY_BUILTINS_ROUND_INT
998#define MICROPY_PY_BUILTINS_ROUND_INT (0)
999#endif
1000
Paul Sokolovsky0e80f342017-10-27 22:29:15 +03001001// Whether to support complete set of special methods for user
1002// classes, or only the most used ones. "Inplace" methods are
1003// controlled by MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS below.
1004// "Reverse" methods are controlled by
1005// MICROPY_PY_REVERSE_SPECIAL_METHODS below.
Paul Sokolovsky98c4bc32015-01-30 01:42:49 +02001006#ifndef MICROPY_PY_ALL_SPECIAL_METHODS
1007#define MICROPY_PY_ALL_SPECIAL_METHODS (0)
1008#endif
1009
Paul Sokolovsky0e80f342017-10-27 22:29:15 +03001010// Whether to support all inplace arithmetic operarion methods
1011// (__imul__, etc.)
1012#ifndef MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS
1013#define MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS (0)
1014#endif
1015
1016// Whether to support reverse arithmetic operarion methods
1017// (__radd__, etc.). Additionally gated by
1018// MICROPY_PY_ALL_SPECIAL_METHODS.
Paul Sokolovskyeb84a832017-09-10 17:05:20 +03001019#ifndef MICROPY_PY_REVERSE_SPECIAL_METHODS
1020#define MICROPY_PY_REVERSE_SPECIAL_METHODS (0)
1021#endif
1022
Damien Georgec9fc6202014-10-25 21:59:14 +01001023// Whether to support compile function
1024#ifndef MICROPY_PY_BUILTINS_COMPILE
1025#define MICROPY_PY_BUILTINS_COMPILE (0)
1026#endif
1027
Paul Sokolovskye2d44e32015-04-06 23:50:37 +03001028// Whether to support enumerate function(type)
1029#ifndef MICROPY_PY_BUILTINS_ENUMERATE
1030#define MICROPY_PY_BUILTINS_ENUMERATE (1)
1031#endif
1032
Damien Georgedd5353a2015-12-18 12:35:44 +00001033// Whether to support eval and exec functions
1034// By default they are supported if the compiler is enabled
1035#ifndef MICROPY_PY_BUILTINS_EVAL_EXEC
1036#define MICROPY_PY_BUILTINS_EVAL_EXEC (MICROPY_ENABLE_COMPILER)
1037#endif
1038
Damien George2a3e2b92014-12-19 13:36:17 +00001039// Whether to support the Python 2 execfile function
1040#ifndef MICROPY_PY_BUILTINS_EXECFILE
1041#define MICROPY_PY_BUILTINS_EXECFILE (0)
1042#endif
1043
Paul Sokolovsky22ff3972015-08-20 01:01:56 +03001044// Whether to support filter function(type)
1045#ifndef MICROPY_PY_BUILTINS_FILTER
1046#define MICROPY_PY_BUILTINS_FILTER (1)
1047#endif
1048
Paul Sokolovsky282ca092015-04-07 00:16:51 +03001049// Whether to support reversed function(type)
1050#ifndef MICROPY_PY_BUILTINS_REVERSED
1051#define MICROPY_PY_BUILTINS_REVERSED (1)
1052#endif
1053
Paul Sokolovsky5ab5ac52015-05-04 19:45:53 +03001054// Whether to define "NotImplemented" special constant
1055#ifndef MICROPY_PY_BUILTINS_NOTIMPLEMENTED
1056#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (0)
1057#endif
1058
Damien Georgebc763022017-06-01 15:32:23 +10001059// Whether to provide the built-in input() function. The implementation of this
1060// uses mp-readline, so can only be enabled if the port uses this readline.
1061#ifndef MICROPY_PY_BUILTINS_INPUT
1062#define MICROPY_PY_BUILTINS_INPUT (0)
1063#endif
1064
pohmelie354e6882015-12-07 15:35:48 +03001065// Whether to support min/max functions
1066#ifndef MICROPY_PY_BUILTINS_MIN_MAX
1067#define MICROPY_PY_BUILTINS_MIN_MAX (1)
1068#endif
1069
Damien Georgea19b5a02017-02-03 12:35:48 +11001070// Support for calls to pow() with 3 integer arguments
1071#ifndef MICROPY_PY_BUILTINS_POW3
1072#define MICROPY_PY_BUILTINS_POW3 (0)
1073#endif
1074
Damien George9f04dfb2017-01-21 23:17:51 +11001075// Whether to provide the help function
1076#ifndef MICROPY_PY_BUILTINS_HELP
1077#define MICROPY_PY_BUILTINS_HELP (0)
1078#endif
1079
1080// Use this to configure the help text shown for help(). It should be a
1081// variable with the type "const char*". A sensible default is provided.
1082#ifndef MICROPY_PY_BUILTINS_HELP_TEXT
1083#define MICROPY_PY_BUILTINS_HELP_TEXT mp_help_default_text
1084#endif
1085
Damien Georgef5172af2017-01-22 12:12:54 +11001086// Add the ability to list the available modules when executing help('modules')
1087#ifndef MICROPY_PY_BUILTINS_HELP_MODULES
1088#define MICROPY_PY_BUILTINS_HELP_MODULES (0)
1089#endif
1090
Paul Sokolovskyd0f5e612014-07-25 11:00:15 +03001091// Whether to set __file__ for imported modules
1092#ifndef MICROPY_PY___FILE__
1093#define MICROPY_PY___FILE__ (1)
1094#endif
1095
Damien George89deec02015-01-09 20:12:54 +00001096// Whether to provide mem-info related functions in micropython module
1097#ifndef MICROPY_PY_MICROPYTHON_MEM_INFO
1098#define MICROPY_PY_MICROPYTHON_MEM_INFO (0)
1099#endif
1100
Damien George7e2a4882018-02-20 18:30:22 +11001101// Whether to provide "micropython.stack_use" function
1102#ifndef MICROPY_PY_MICROPYTHON_STACK_USE
1103#define MICROPY_PY_MICROPYTHON_STACK_USE (MICROPY_PY_MICROPYTHON_MEM_INFO)
1104#endif
1105
Andrew Leech86bfabe2019-06-28 16:35:51 +10001106// Whether to provide the "micropython.heap_locked" function
1107#ifndef MICROPY_PY_MICROPYTHON_HEAP_LOCKED
1108#define MICROPY_PY_MICROPYTHON_HEAP_LOCKED (0)
1109#endif
1110
Paul Sokolovskycb78f862014-06-27 20:39:09 +03001111// Whether to provide "array" module. Note that large chunk of the
1112// underlying code is shared with "bytearray" builtin type, so to
1113// get real savings, it should be disabled too.
1114#ifndef MICROPY_PY_ARRAY
1115#define MICROPY_PY_ARRAY (1)
1116#endif
1117
Paul Sokolovskycefcbb22015-02-27 22:16:05 +02001118// Whether to support slice assignments for array (and bytearray).
1119// This is rarely used, but adds ~0.5K of code.
1120#ifndef MICROPY_PY_ARRAY_SLICE_ASSIGN
1121#define MICROPY_PY_ARRAY_SLICE_ASSIGN (0)
1122#endif
1123
Damien George5aa311d2015-04-21 14:14:24 +00001124// Whether to support attrtuple type (MicroPython extension)
1125// It provides space-efficient tuples with attribute access
1126#ifndef MICROPY_PY_ATTRTUPLE
1127#define MICROPY_PY_ATTRTUPLE (1)
1128#endif
1129
Damien Georgeee3fd462014-05-24 23:03:12 +01001130// Whether to provide "collections" module
1131#ifndef MICROPY_PY_COLLECTIONS
1132#define MICROPY_PY_COLLECTIONS (1)
1133#endif
1134
Paul Sokolovsky970eedc2018-02-06 00:06:42 +02001135// Whether to provide "ucollections.deque" type
1136#ifndef MICROPY_PY_COLLECTIONS_DEQUE
1137#define MICROPY_PY_COLLECTIONS_DEQUE (0)
1138#endif
1139
Paul Sokolovsky0ef01d02015-03-18 01:25:04 +02001140// Whether to provide "collections.OrderedDict" type
1141#ifndef MICROPY_PY_COLLECTIONS_ORDEREDDICT
1142#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (0)
1143#endif
1144
stijn79ed58f2017-11-06 12:21:53 +01001145// Whether to provide the _asdict function for namedtuple
1146#ifndef MICROPY_PY_COLLECTIONS_NAMEDTUPLE__ASDICT
1147#define MICROPY_PY_COLLECTIONS_NAMEDTUPLE__ASDICT (0)
1148#endif
1149
Damien Georgeee3fd462014-05-24 23:03:12 +01001150// Whether to provide "math" module
1151#ifndef MICROPY_PY_MATH
1152#define MICROPY_PY_MATH (1)
1153#endif
1154
Damien George5cbeace2015-02-22 14:48:18 +00001155// Whether to provide special math functions: math.{erf,erfc,gamma,lgamma}
1156#ifndef MICROPY_PY_MATH_SPECIAL_FUNCTIONS
1157#define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (0)
1158#endif
1159
Christopher Swenson8c656752018-08-27 10:32:21 +10001160// Whether to provide math.factorial function
1161#ifndef MICROPY_PY_MATH_FACTORIAL
1162#define MICROPY_PY_MATH_FACTORIAL (0)
1163#endif
1164
stijnaf5c9982019-07-02 10:28:44 +02001165// Whether to provide math.isclose function
1166#ifndef MICROPY_PY_MATH_ISCLOSE
1167#define MICROPY_PY_MATH_ISCLOSE (0)
1168#endif
1169
stijn81db22f2020-05-17 12:29:25 +02001170// Whether to provide fix for atan2 Inf handling.
1171#ifndef MICROPY_PY_MATH_ATAN2_FIX_INFNAN
1172#define MICROPY_PY_MATH_ATAN2_FIX_INFNAN (0)
1173#endif
1174
1175// Whether to provide fix for fmod Inf handling.
1176#ifndef MICROPY_PY_MATH_FMOD_FIX_INFNAN
1177#define MICROPY_PY_MATH_FMOD_FIX_INFNAN (0)
1178#endif
1179
1180// Whether to provide fix for modf negative zero handling.
1181#ifndef MICROPY_PY_MATH_MODF_FIX_NEGZERO
1182#define MICROPY_PY_MATH_MODF_FIX_NEGZERO (0)
1183#endif
1184
stijn2e54d9d2020-09-08 15:22:34 +02001185// Whether to provide fix for pow(1, NaN) and pow(NaN, 0), which both should be 1 not NaN.
1186#ifndef MICROPY_PY_MATH_POW_FIX_NAN
1187#define MICROPY_PY_MATH_POW_FIX_NAN (0)
1188#endif
1189
Damien Georgeee3fd462014-05-24 23:03:12 +01001190// Whether to provide "cmath" module
1191#ifndef MICROPY_PY_CMATH
1192#define MICROPY_PY_CMATH (0)
1193#endif
1194
1195// Whether to provide "gc" module
1196#ifndef MICROPY_PY_GC
1197#define MICROPY_PY_GC (1)
1198#endif
1199
Paul Sokolovsky755a55f2014-06-05 22:48:02 +03001200// Whether to return number of collected objects from gc.collect()
1201#ifndef MICROPY_PY_GC_COLLECT_RETVAL
1202#define MICROPY_PY_GC_COLLECT_RETVAL (0)
1203#endif
1204
Damien Georgeee3fd462014-05-24 23:03:12 +01001205// Whether to provide "io" module
1206#ifndef MICROPY_PY_IO
1207#define MICROPY_PY_IO (1)
1208#endif
1209
Damien Georgeaf0932a2018-06-04 15:54:26 +10001210// Whether to provide "io.IOBase" class to support user streams
1211#ifndef MICROPY_PY_IO_IOBASE
1212#define MICROPY_PY_IO_IOBASE (0)
1213#endif
1214
Paul Sokolovskyd7da2db2017-05-03 01:47:08 +03001215// Whether to provide "uio.resource_stream()" function with
1216// the semantics of CPython's pkg_resources.resource_stream()
Paul Sokolovskye7fc7652017-12-10 02:15:43 +02001217// (allows to access binary resources in frozen source packages).
1218// Note that the same functionality can be achieved in "pure
1219// Python" by prepocessing binary resources into Python source
1220// and bytecode-freezing it (with a simple helper module available
1221// e.g. in micropython-lib).
Paul Sokolovskyd7da2db2017-05-03 01:47:08 +03001222#ifndef MICROPY_PY_IO_RESOURCE_STREAM
1223#define MICROPY_PY_IO_RESOURCE_STREAM (0)
1224#endif
1225
Damien Georgeee3fd462014-05-24 23:03:12 +01001226// Whether to provide "io.FileIO" class
1227#ifndef MICROPY_PY_IO_FILEIO
1228#define MICROPY_PY_IO_FILEIO (0)
1229#endif
1230
1231// Whether to provide "io.BytesIO" class
1232#ifndef MICROPY_PY_IO_BYTESIO
1233#define MICROPY_PY_IO_BYTESIO (1)
1234#endif
1235
Paul Sokolovsky5d93dfb2016-03-25 01:10:49 +02001236// Whether to provide "io.BufferedWriter" class
1237#ifndef MICROPY_PY_IO_BUFFEREDWRITER
1238#define MICROPY_PY_IO_BUFFEREDWRITER (0)
1239#endif
1240
Damien Georgeee3fd462014-05-24 23:03:12 +01001241// Whether to provide "struct" module
1242#ifndef MICROPY_PY_STRUCT
1243#define MICROPY_PY_STRUCT (1)
1244#endif
1245
1246// Whether to provide "sys" module
1247#ifndef MICROPY_PY_SYS
1248#define MICROPY_PY_SYS (1)
1249#endif
1250
Paul Sokolovsky4e0eeeb2014-07-03 16:50:11 +03001251// Whether to provide "sys.maxsize" constant
1252#ifndef MICROPY_PY_SYS_MAXSIZE
1253#define MICROPY_PY_SYS_MAXSIZE (0)
1254#endif
1255
Paul Sokolovsky1a1d11f2015-12-05 00:09:10 +02001256// Whether to provide "sys.modules" dictionary
1257#ifndef MICROPY_PY_SYS_MODULES
1258#define MICROPY_PY_SYS_MODULES (1)
1259#endif
1260
Paul Sokolovsky8b85d142015-04-25 03:17:41 +03001261// Whether to provide "sys.exc_info" function
1262// Avoid enabling this, this function is Python2 heritage
1263#ifndef MICROPY_PY_SYS_EXC_INFO
1264#define MICROPY_PY_SYS_EXC_INFO (0)
1265#endif
1266
Damien Georgeee3fd462014-05-24 23:03:12 +01001267// Whether to provide "sys.exit" function
1268#ifndef MICROPY_PY_SYS_EXIT
Paul Sokolovsky403c9302016-12-14 21:10:22 +03001269#define MICROPY_PY_SYS_EXIT (1)
Damien Georgeee3fd462014-05-24 23:03:12 +01001270#endif
1271
Milan Rossacb364702019-08-05 15:06:41 +02001272// Whether to provide "sys.atexit" function (MicroPython extension)
1273#ifndef MICROPY_PY_SYS_ATEXIT
1274#define MICROPY_PY_SYS_ATEXIT (0)
1275#endif
1276
Milan Rossa310b3d12019-08-14 16:09:36 +02001277// Whether to provide "sys.settrace" function
1278#ifndef MICROPY_PY_SYS_SETTRACE
1279#define MICROPY_PY_SYS_SETTRACE (0)
1280#endif
1281
Paul Sokolovskybfc20922017-08-11 09:42:39 +03001282// Whether to provide "sys.getsizeof" function
1283#ifndef MICROPY_PY_SYS_GETSIZEOF
1284#define MICROPY_PY_SYS_GETSIZEOF (0)
1285#endif
1286
Damien Georgeee3fd462014-05-24 23:03:12 +01001287// Whether to provide sys.{stdin,stdout,stderr} objects
1288#ifndef MICROPY_PY_SYS_STDFILES
1289#define MICROPY_PY_SYS_STDFILES (0)
Damien George3bb8bd82014-04-14 21:20:30 +01001290#endif
1291
Damien George3c4b5d42015-05-13 23:49:21 +01001292// Whether to provide sys.{stdin,stdout,stderr}.buffer object
1293// This is implemented per-port
1294#ifndef MICROPY_PY_SYS_STDIO_BUFFER
1295#define MICROPY_PY_SYS_STDIO_BUFFER (0)
1296#endif
Paul Sokolovsky82158472014-06-28 03:03:47 +03001297
Damien George596a3fe2016-05-10 10:54:25 +01001298// Whether to provide "uerrno" module
1299#ifndef MICROPY_PY_UERRNO
1300#define MICROPY_PY_UERRNO (0)
1301#endif
1302
Damien Georgef5634062017-02-22 12:53:42 +11001303// Whether to provide the uerrno.errorcode dict
1304#ifndef MICROPY_PY_UERRNO_ERRORCODE
1305#define MICROPY_PY_UERRNO_ERRORCODE (1)
1306#endif
1307
Paul Sokolovsky8f5bc3f2016-11-20 23:49:45 +03001308// Whether to provide "uselect" module (baremetal implementation)
1309#ifndef MICROPY_PY_USELECT
1310#define MICROPY_PY_USELECT (0)
1311#endif
1312
Paul Sokolovskya9728442016-10-14 20:13:02 +03001313// Whether to provide "utime" module functions implementation
1314// in terms of mp_hal_* functions.
1315#ifndef MICROPY_PY_UTIME_MP_HAL
1316#define MICROPY_PY_UTIME_MP_HAL (0)
1317#endif
1318
Paul Sokolovsky76146b32016-10-30 03:02:07 +03001319// Period of values returned by utime.ticks_ms(), ticks_us(), ticks_cpu()
1320// functions. Should be power of two. All functions above use the same
1321// period, so if underlying hardware/API has different periods, the
1322// minimum of them should be used. The value below is the maximum value
1323// this parameter can take (corresponding to 30 bit tick values on 32-bit
1324// system).
1325#ifndef MICROPY_PY_UTIME_TICKS_PERIOD
1326#define MICROPY_PY_UTIME_TICKS_PERIOD (MP_SMALL_INT_POSITIVE_MASK + 1)
1327#endif
1328
Damien George27cc0772016-04-22 22:52:33 +00001329// Whether to provide "_thread" module
1330#ifndef MICROPY_PY_THREAD
1331#define MICROPY_PY_THREAD (0)
1332#endif
1333
Damien George4cec63a2016-05-26 10:42:53 +00001334// Whether to make the VM/runtime thread-safe using a global lock
1335// If not enabled then thread safety must be provided at the Python level
1336#ifndef MICROPY_PY_THREAD_GIL
1337#define MICROPY_PY_THREAD_GIL (MICROPY_PY_THREAD)
1338#endif
1339
Damien Georgef6c22a02017-02-06 10:50:43 +11001340// Number of VM jump-loops to do before releasing the GIL.
1341// Set this to 0 to disable the divisor.
1342#ifndef MICROPY_PY_THREAD_GIL_VM_DIVISOR
1343#define MICROPY_PY_THREAD_GIL_VM_DIVISOR (32)
1344#endif
1345
Paul Sokolovsky82158472014-06-28 03:03:47 +03001346// Extended modules
Paul Sokolovsky510296f2014-08-08 22:51:40 +03001347
Damien Georgebc009fd2020-03-12 16:46:20 +11001348#ifndef MICROPY_PY_UASYNCIO
1349#define MICROPY_PY_UASYNCIO (0)
1350#endif
1351
Paul Sokolovsky82158472014-06-28 03:03:47 +03001352#ifndef MICROPY_PY_UCTYPES
1353#define MICROPY_PY_UCTYPES (0)
1354#endif
1355
Paul Sokolovsky38151f32018-10-06 23:34:58 +03001356// Whether to provide SHORT, INT, LONG, etc. types in addition to
1357// exact-bitness types like INT16, INT32, etc.
1358#ifndef MICROPY_PY_UCTYPES_NATIVE_C_TYPES
1359#define MICROPY_PY_UCTYPES_NATIVE_C_TYPES (1)
1360#endif
1361
Paul Sokolovsky34162872014-10-12 08:16:34 -07001362#ifndef MICROPY_PY_UZLIB
1363#define MICROPY_PY_UZLIB (0)
1364#endif
1365
Damien George612045f2014-09-17 22:56:34 +01001366#ifndef MICROPY_PY_UJSON
1367#define MICROPY_PY_UJSON (0)
1368#endif
1369
Paul Sokolovskyc71e0452014-09-12 18:48:07 +03001370#ifndef MICROPY_PY_URE
1371#define MICROPY_PY_URE (0)
1372#endif
1373
Damien George7d851a22019-08-17 23:50:19 +10001374#ifndef MICROPY_PY_URE_DEBUG
1375#define MICROPY_PY_URE_DEBUG (0)
1376#endif
1377
Damien George1f864602018-05-24 13:07:42 +10001378#ifndef MICROPY_PY_URE_MATCH_GROUPS
1379#define MICROPY_PY_URE_MATCH_GROUPS (0)
1380#endif
1381
Damien George1e9b8712018-05-24 13:08:15 +10001382#ifndef MICROPY_PY_URE_MATCH_SPAN_START_END
1383#define MICROPY_PY_URE_MATCH_SPAN_START_END (0)
1384#endif
1385
Damien Georgee30a5fc2018-05-24 13:08:51 +10001386#ifndef MICROPY_PY_URE_SUB
1387#define MICROPY_PY_URE_SUB (0)
1388#endif
1389
Damien Georgef5d69792014-10-22 17:37:18 +00001390#ifndef MICROPY_PY_UHEAPQ
1391#define MICROPY_PY_UHEAPQ (0)
1392#endif
1393
Paul Sokolovskyd02f6a92016-12-22 00:29:32 +03001394// Optimized heap queue for relative timestamps
1395#ifndef MICROPY_PY_UTIMEQ
1396#define MICROPY_PY_UTIMEQ (0)
1397#endif
1398
Paul Sokolovskyf4b19c82014-11-22 01:19:13 +02001399#ifndef MICROPY_PY_UHASHLIB
1400#define MICROPY_PY_UHASHLIB (0)
1401#endif
1402
Paul Sokolovsky5fe37302018-08-19 11:58:22 +03001403#ifndef MICROPY_PY_UHASHLIB_MD5
1404#define MICROPY_PY_UHASHLIB_MD5 (0)
1405#endif
1406
Yonatan Goldschmidt66303542018-06-09 02:48:29 +03001407#ifndef MICROPY_PY_UHASHLIB_SHA1
1408#define MICROPY_PY_UHASHLIB_SHA1 (0)
1409#endif
1410
1411#ifndef MICROPY_PY_UHASHLIB_SHA256
1412#define MICROPY_PY_UHASHLIB_SHA256 (1)
1413#endif
1414
Paul Sokolovsky567bc2d2018-01-07 15:13:56 +02001415#ifndef MICROPY_PY_UCRYPTOLIB
1416#define MICROPY_PY_UCRYPTOLIB (0)
1417#endif
1418
Yonatan Goldschmidtef984362019-04-23 12:39:05 +03001419// Depends on MICROPY_PY_UCRYPTOLIB
1420#ifndef MICROPY_PY_UCRYPTOLIB_CTR
1421#define MICROPY_PY_UCRYPTOLIB_CTR (0)
1422#endif
1423
Yonatan Goldschmidt473fe452018-06-15 17:07:47 +03001424#ifndef MICROPY_PY_UCRYPTOLIB_CONSTS
1425#define MICROPY_PY_UCRYPTOLIB_CONSTS (0)
1426#endif
1427
Paul Sokolovskybfdc2052014-11-29 06:19:30 +02001428#ifndef MICROPY_PY_UBINASCII
1429#define MICROPY_PY_UBINASCII (0)
1430#endif
1431
Paul Sokolovskyc4283672016-08-24 18:28:43 +03001432// Depends on MICROPY_PY_UZLIB
1433#ifndef MICROPY_PY_UBINASCII_CRC32
1434#define MICROPY_PY_UBINASCII_CRC32 (0)
1435#endif
1436
Paul Sokolovskya58a91e2016-01-17 12:10:28 +02001437#ifndef MICROPY_PY_URANDOM
1438#define MICROPY_PY_URANDOM (0)
1439#endif
1440
Damien Georgea53af6c2016-01-22 16:19:32 +00001441// Whether to include: randrange, randint, choice, random, uniform
1442#ifndef MICROPY_PY_URANDOM_EXTRA_FUNCS
1443#define MICROPY_PY_URANDOM_EXTRA_FUNCS (0)
1444#endif
1445
Paul Sokolovsky01162182015-05-03 20:25:40 +03001446#ifndef MICROPY_PY_MACHINE
1447#define MICROPY_PY_MACHINE (0)
1448#endif
1449
Damien George33168082016-05-31 14:25:19 +01001450// Whether to include: time_pulse_us
1451#ifndef MICROPY_PY_MACHINE_PULSE
1452#define MICROPY_PY_MACHINE_PULSE (0)
1453#endif
1454
Damien Georged0837122016-04-12 13:42:35 +01001455#ifndef MICROPY_PY_MACHINE_I2C
1456#define MICROPY_PY_MACHINE_I2C (0)
1457#endif
1458
Damien George0823c1b2016-09-01 15:07:20 +10001459#ifndef MICROPY_PY_MACHINE_SPI
1460#define MICROPY_PY_MACHINE_SPI (0)
1461#endif
1462
Paul Sokolovskyaaa88672015-10-06 18:10:00 +03001463#ifndef MICROPY_PY_USSL
1464#define MICROPY_PY_USSL (0)
Eric Poulsen74ec52d2017-10-26 21:17:35 -07001465// Whether to add finaliser code to ussl objects
1466#define MICROPY_PY_USSL_FINALISER (0)
Paul Sokolovskyaaa88672015-10-06 18:10:00 +03001467#endif
1468
Yonatan Goldschmidtbc4f8b42019-02-10 22:35:18 +02001469#ifndef MICROPY_PY_UWEBSOCKET
1470#define MICROPY_PY_UWEBSOCKET (0)
Paul Sokolovsky24342dd2016-03-24 19:14:12 +02001471#endif
1472
Damien George53ad6812016-04-08 11:08:37 +01001473#ifndef MICROPY_PY_FRAMEBUF
1474#define MICROPY_PY_FRAMEBUF (0)
1475#endif
1476
Paul Sokolovsky737bd9c2016-07-02 14:57:42 +03001477#ifndef MICROPY_PY_BTREE
1478#define MICROPY_PY_BTREE (0)
1479#endif
1480
Damien George58ebde42014-05-21 20:32:59 +01001481/*****************************************************************************/
1482/* Hooks for a port to add builtins */
1483
Yonatan Goldschmidt343401c2019-02-03 21:24:16 +02001484// Additional builtin function definitions - see modbuiltins.c:mp_module_builtins_globals_table for format.
Damien George58ebde42014-05-21 20:32:59 +01001485#ifndef MICROPY_PORT_BUILTINS
1486#define MICROPY_PORT_BUILTINS
Paul Sokolovsky910843e2014-02-14 12:02:34 +02001487#endif
Damien Georgecaac5422014-03-25 14:18:18 +00001488
Yonatan Goldschmidt343401c2019-02-03 21:24:16 +02001489// Additional builtin module definitions - see objmodule.c:mp_builtin_module_table for format.
Damien George58ebde42014-05-21 20:32:59 +01001490#ifndef MICROPY_PORT_BUILTIN_MODULES
1491#define MICROPY_PORT_BUILTIN_MODULES
Damien Georgecaac5422014-03-25 14:18:18 +00001492#endif
1493
Damien George57e99eb2014-04-10 22:42:11 +01001494// Additional constant definitions for the compiler - see compile.c:mp_constants_table.
Damien George58ebde42014-05-21 20:32:59 +01001495#ifndef MICROPY_PORT_CONSTANTS
1496#define MICROPY_PORT_CONSTANTS
Damien George57e99eb2014-04-10 22:42:11 +01001497#endif
1498
Damien Georgeb4b10fd2015-01-01 23:30:53 +00001499// Any root pointers for GC scanning - see mpstate.c
1500#ifndef MICROPY_PORT_ROOT_POINTERS
1501#define MICROPY_PORT_ROOT_POINTERS
1502#endif
1503
Damien George136f6752014-01-07 14:54:15 +00001504/*****************************************************************************/
Damien George8fb5c8f2020-02-07 12:07:50 +11001505/* Hooks for a port to wrap functions with attributes */
1506
Damien George7cbf8262021-04-28 10:52:19 +10001507#ifndef MICROPY_WRAP_MP_SCHED_EXCEPTION
1508#define MICROPY_WRAP_MP_SCHED_EXCEPTION(f) f
1509#endif
1510
Damien George8fb5c8f2020-02-07 12:07:50 +11001511#ifndef MICROPY_WRAP_MP_KEYBOARD_INTERRUPT
1512#define MICROPY_WRAP_MP_KEYBOARD_INTERRUPT(f) f
1513#endif
1514
Damien George544c3082020-04-23 16:18:14 +10001515#ifndef MICROPY_WRAP_MP_SCHED_SCHEDULE
1516#define MICROPY_WRAP_MP_SCHED_SCHEDULE(f) f
1517#endif
1518
Damien George8fb5c8f2020-02-07 12:07:50 +11001519/*****************************************************************************/
Damien George136f6752014-01-07 14:54:15 +00001520/* Miscellaneous settings */
1521
Damien George28631532015-02-08 13:42:00 +00001522// All uPy objects in ROM must be aligned on at least a 4 byte boundary
1523// so that the small-int/qstr/pointer distinction can be made. For machines
1524// that don't do this (eg 16-bit CPU), define the following macro to something
1525// like __attribute__((aligned(4))).
1526#ifndef MICROPY_OBJ_BASE_ALIGNMENT
1527#define MICROPY_OBJ_BASE_ALIGNMENT
1528#endif
1529
Dave Hylands5b7fd202014-07-01 23:46:53 -07001530// On embedded platforms, these will typically enable/disable irqs.
1531#ifndef MICROPY_BEGIN_ATOMIC_SECTION
Damien George4859edb2014-10-15 17:33:24 +00001532#define MICROPY_BEGIN_ATOMIC_SECTION() (0)
Dave Hylands5b7fd202014-07-01 23:46:53 -07001533#endif
1534#ifndef MICROPY_END_ATOMIC_SECTION
Damien George4859edb2014-10-15 17:33:24 +00001535#define MICROPY_END_ATOMIC_SECTION(state) (void)(state)
Dave Hylands5b7fd202014-07-01 23:46:53 -07001536#endif
1537
Paul Sokolovskyd5df6cd2014-02-12 18:15:40 +02001538// Allow to override static modifier for global objects, e.g. to use with
1539// object code analysis tools which don't support static symbols.
1540#ifndef STATIC
1541#define STATIC static
1542#endif
1543
Damien Georgead4656b2021-02-04 16:39:09 +11001544// Number of bytes in an object word: mp_obj_t, mp_uint_t, mp_uint_t
1545#ifndef MP_BYTES_PER_OBJ_WORD
1546#define MP_BYTES_PER_OBJ_WORD (sizeof(mp_uint_t))
Damien George4c307bf2017-04-01 11:39:38 +11001547#endif
1548
Damien George7e956fa2021-02-04 15:32:59 +11001549// Number of bits in a byte
1550#ifndef MP_BITS_PER_BYTE
1551#define MP_BITS_PER_BYTE (8)
Yonatan Goldschmidt1c849d62019-12-01 01:10:12 +02001552#endif
Damien George40f3c022014-07-03 13:25:24 +01001553// mp_int_t value with most significant bit set
Damien Georgec8911902021-02-04 16:39:46 +11001554#define MP_OBJ_WORD_MSBIT_HIGH (((mp_uint_t)1) << (MP_BYTES_PER_OBJ_WORD * MP_BITS_PER_BYTE - 1))
Paul Sokolovskyfc5aac82014-01-12 16:10:19 +02001555
Damien Georgea9bcd512014-10-06 13:44:59 +00001556// Make sure both MP_ENDIANNESS_LITTLE and MP_ENDIANNESS_BIG are
1557// defined and that they are the opposite of each other.
1558#if defined(MP_ENDIANNESS_LITTLE)
1559#define MP_ENDIANNESS_BIG (!MP_ENDIANNESS_LITTLE)
1560#elif defined(MP_ENDIANNESS_BIG)
1561#define MP_ENDIANNESS_LITTLE (!MP_ENDIANNESS_BIG)
1562#else
Damien George69661f32020-02-27 15:36:53 +11001563// Endianness not defined by port so try to autodetect it.
Damien Georgea9bcd512014-10-06 13:44:59 +00001564 #if defined(__BYTE_ORDER__)
1565 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
1566 #define MP_ENDIANNESS_LITTLE (1)
Damien George96303762018-05-07 13:36:52 +10001567 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
Damien Georgea9bcd512014-10-06 13:44:59 +00001568 #define MP_ENDIANNESS_LITTLE (0)
1569 #endif
Damien Georgea9bcd512014-10-06 13:44:59 +00001570 #else
Damien George4e4772b2015-05-30 23:12:30 +01001571 #include <endian.h>
1572 #if defined(__BYTE_ORDER)
1573 #if __BYTE_ORDER == __LITTLE_ENDIAN
1574 #define MP_ENDIANNESS_LITTLE (1)
Damien George96303762018-05-07 13:36:52 +10001575 #elif __BYTE_ORDER == __BIG_ENDIAN
Damien George4e4772b2015-05-30 23:12:30 +01001576 #define MP_ENDIANNESS_LITTLE (0)
1577 #endif
Damien George4e4772b2015-05-30 23:12:30 +01001578 #endif
Damien Georgea9bcd512014-10-06 13:44:59 +00001579 #endif
Damien George96303762018-05-07 13:36:52 +10001580 #ifndef MP_ENDIANNESS_LITTLE
1581 #error endianness not defined and cannot detect it
1582 #endif
Damien Georgea9bcd512014-10-06 13:44:59 +00001583 #define MP_ENDIANNESS_BIG (!MP_ENDIANNESS_LITTLE)
Andrew Schellercc837372014-04-14 02:39:56 +01001584#endif
Paul Sokolovsky2da81fa2014-04-11 03:44:00 +03001585
Damien George3c658a42014-08-24 16:28:17 +01001586// Make a pointer to RAM callable (eg set lower bit for Thumb code)
1587// (This scheme won't work if we want to mix Thumb and normal ARM code.)
1588#ifndef MICROPY_MAKE_POINTER_CALLABLE
1589#define MICROPY_MAKE_POINTER_CALLABLE(p) (p)
1590#endif
1591
Damien George7f9d1d62015-04-09 23:56:15 +01001592// If these MP_PLAT_*_EXEC macros are overridden then the memory allocated by them
Damien George2127e9a2015-01-14 00:11:09 +00001593// must be somehow reachable for marking by the GC, since the native code
1594// generators store pointers to GC managed memory in the code.
Fabian Vogtb7235b82014-09-03 16:59:33 +02001595#ifndef MP_PLAT_ALLOC_EXEC
Damien George4dea9222015-04-09 15:29:54 +00001596#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 +02001597#endif
1598
1599#ifndef MP_PLAT_FREE_EXEC
1600#define MP_PLAT_FREE_EXEC(ptr, size) m_del(byte, ptr, size)
1601#endif
1602
Damien George7f9d1d62015-04-09 23:56:15 +01001603// This macro is used to do all output (except when MICROPY_PY_IO is defined)
1604#ifndef MP_PLAT_PRINT_STRN
Damien George4300c7d2015-10-15 00:05:55 +01001605#define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
Damien George7f9d1d62015-04-09 23:56:15 +01001606#endif
1607
Paul Sokolovsky722e5622014-09-06 19:17:23 +03001608#ifndef MP_SSIZE_MAX
1609#define MP_SSIZE_MAX SSIZE_MAX
1610#endif
1611
Damien George40f3c022014-07-03 13:25:24 +01001612// printf format spec to use for mp_int_t and friends
Damien George136f6752014-01-07 14:54:15 +00001613#ifndef INT_FMT
stijn3baf6b52015-11-20 15:59:06 +01001614#if defined(__LP64__)
Damien George40f3c022014-07-03 13:25:24 +01001615// Archs where mp_int_t == long, long != int
Paul Sokolovskyc90c0f62014-01-04 01:57:00 +02001616#define UINT_FMT "%lu"
1617#define INT_FMT "%ld"
stijn3baf6b52015-11-20 15:59:06 +01001618#elif defined(_WIN64)
stijn0a4eb4d2015-12-18 10:20:33 +01001619#define UINT_FMT "%llu"
1620#define INT_FMT "%lld"
Paul Sokolovskyc90c0f62014-01-04 01:57:00 +02001621#else
Damien George40f3c022014-07-03 13:25:24 +01001622// Archs where mp_int_t == int
Paul Sokolovskyc90c0f62014-01-04 01:57:00 +02001623#define UINT_FMT "%u"
1624#define INT_FMT "%d"
1625#endif
stijn84fa3312020-04-16 09:13:57 +02001626#endif // INT_FMT
Paul Sokolovskye9085912014-04-30 05:35:18 +03001627
1628// Modifier for function which doesn't return
stijn01d6be42014-05-05 12:18:27 +02001629#ifndef NORETURN
Paul Sokolovskye9085912014-04-30 05:35:18 +03001630#define NORETURN __attribute__((noreturn))
stijn01d6be42014-05-05 12:18:27 +02001631#endif
mux5c8db482014-06-21 17:24:55 +02001632
1633// Modifier for weak functions
1634#ifndef MP_WEAK
1635#define MP_WEAK __attribute__((weak))
1636#endif
Paul Sokolovsky361909e2014-12-29 00:51:06 +02001637
Paul Sokolovsky0f5bf1a2016-06-15 23:52:00 +03001638// Modifier for functions which should be never inlined
1639#ifndef MP_NOINLINE
1640#define MP_NOINLINE __attribute__((noinline))
1641#endif
1642
Paul Sokolovsky1bc29112016-08-07 22:36:05 +03001643// Modifier for functions which should be always inlined
1644#ifndef MP_ALWAYSINLINE
1645#define MP_ALWAYSINLINE __attribute__((always_inline))
1646#endif
1647
Paul Sokolovsky361909e2014-12-29 00:51:06 +02001648// Condition is likely to be true, to help branch prediction
1649#ifndef MP_LIKELY
1650#define MP_LIKELY(x) __builtin_expect((x), 1)
1651#endif
1652
1653// Condition is likely to be false, to help branch prediction
1654#ifndef MP_UNLIKELY
1655#define MP_UNLIKELY(x) __builtin_expect((x), 0)
1656#endif
Damien George9ddbe292014-12-29 01:02:19 +00001657
Damien George0c80cb32019-08-19 15:50:02 +10001658// To annotate that code is unreachable
1659#ifndef MP_UNREACHABLE
1660#if defined(__GNUC__)
1661#define MP_UNREACHABLE __builtin_unreachable();
1662#else
1663#define MP_UNREACHABLE for (;;);
1664#endif
1665#endif
1666
Emil Renner Berthingccd92332019-11-28 12:47:21 +01001667// Explicitly annotate switch case fall throughs
1668#if defined(__GNUC__) && __GNUC__ >= 7
1669#define MP_FALLTHROUGH __attribute__((fallthrough));
1670#else
1671#define MP_FALLTHROUGH
1672#endif
1673
Paul Sokolovsky1b146e92017-11-08 19:45:18 +02001674#ifndef MP_HTOBE16
1675#if MP_ENDIANNESS_LITTLE
Damien Georgefeb25772020-03-20 21:47:07 +11001676#define MP_HTOBE16(x) ((uint16_t)((((x) & 0xff) << 8) | (((x) >> 8) & 0xff)))
Damien George69661f32020-02-27 15:36:53 +11001677#define MP_BE16TOH(x) MP_HTOBE16(x)
Paul Sokolovsky1b146e92017-11-08 19:45:18 +02001678#else
Damien George69661f32020-02-27 15:36:53 +11001679#define MP_HTOBE16(x) (x)
1680#define MP_BE16TOH(x) (x)
Paul Sokolovsky1b146e92017-11-08 19:45:18 +02001681#endif
1682#endif
1683
1684#ifndef MP_HTOBE32
1685#if MP_ENDIANNESS_LITTLE
Damien Georgefeb25772020-03-20 21:47:07 +11001686#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 +11001687#define MP_BE32TOH(x) MP_HTOBE32(x)
Paul Sokolovsky1b146e92017-11-08 19:45:18 +02001688#else
Damien George69661f32020-02-27 15:36:53 +11001689#define MP_HTOBE32(x) (x)
1690#define MP_BE32TOH(x) (x)
Paul Sokolovsky1b146e92017-11-08 19:45:18 +02001691#endif
1692#endif
1693
Paul Sokolovsky2f5d1132018-12-21 14:20:55 +03001694// Warning categories are by default implemented as strings, though
1695// hook is left for a port to define them as something else.
1696#if MICROPY_WARNINGS_CATEGORY
Damien George69661f32020-02-27 15:36:53 +11001697#ifndef MP_WARN_CAT
1698#define MP_WARN_CAT(x) #x
1699#endif
Paul Sokolovsky2f5d1132018-12-21 14:20:55 +03001700#else
Damien George69661f32020-02-27 15:36:53 +11001701#undef MP_WARN_CAT
1702#define MP_WARN_CAT(x) (NULL)
Paul Sokolovsky2f5d1132018-12-21 14:20:55 +03001703#endif
1704
Milan Rossa310b3d12019-08-14 16:09:36 +02001705// Feature dependency check.
1706#if MICROPY_PY_SYS_SETTRACE
1707#if !MICROPY_PERSISTENT_CODE_SAVE
1708#error "MICROPY_PY_SYS_SETTRACE requires MICROPY_PERSISTENT_CODE_SAVE to be enabled"
1709#endif
1710#if MICROPY_COMP_CONST
1711#error "MICROPY_PY_SYS_SETTRACE requires MICROPY_COMP_CONST to be disabled"
1712#endif
1713#endif
1714
Alexander Steffen299bc622017-06-29 23:14:58 +02001715#endif // MICROPY_INCLUDED_PY_MPCONFIG_H