blob: 99bf47536d4e48dfca402829fe95d59d5d2535fc [file] [log] [blame]
Damien George04b91472014-05-03 23:27:38 +01001/*
2 * This file is part of the Micro Python project, http://micropython.org/
3 *
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 */
Damien George9ddbe292014-12-29 01:02:19 +000026#ifndef __MICROPY_INCLUDED_PY_MPCONFIG_H__
27#define __MICROPY_INCLUDED_PY_MPCONFIG_H__
Damien George04b91472014-05-03 23:27:38 +010028
Paul Sokolovskyb372bfc2014-01-03 17:15:53 +020029// This file contains default configuration settings for MicroPython.
Paul Sokolovskyb1422de2014-10-29 04:08:49 +020030// You can override any of the options below using mpconfigport.h file
31// located in a directory of your port.
Paul Sokolovskyb372bfc2014-01-03 17:15:53 +020032
Paul Sokolovskyb1422de2014-10-29 04:08:49 +020033// mpconfigport.h is a file containing configuration settings for a
34// particular port. mpconfigport.h is actually a default name for
35// such config, and it can be overriden using MP_CONFIGFILE preprocessor
36// define (you can do that by passing CFLAGS_EXTRA='-DMP_CONFIGFILE="<file.h>"'
37// argument to make when using standard MicroPython makefiles).
38// This is useful to have more than one config per port, for example,
39// release vs debug configs, etc. Note that if you switch from one config
40// to another, you must rebuild from scratch using "-B" switch to make.
41
42#ifdef MP_CONFIGFILE
43#include MP_CONFIGFILE
44#else
Damien George8340c482014-06-12 19:50:17 +010045#include <mpconfigport.h>
Paul Sokolovskyb1422de2014-10-29 04:08:49 +020046#endif
Paul Sokolovskyb372bfc2014-01-03 17:15:53 +020047
Damien George136f6752014-01-07 14:54:15 +000048// Any options not explicitly set in mpconfigport.h will get default
49// values below.
50
51/*****************************************************************************/
Damien George567184e2015-03-29 14:05:46 +010052/* Object representation */
53
54// A Micro Python object is a machine word having the following form:
55// - xxxx...xxx1 : a small int, bits 1 and above are the value
56// - xxxx...xx10 : a qstr, bits 2 and above are the value
57// - xxxx...xx00 : a pointer to an mp_obj_base_t (unless a fake object)
58#define MICROPY_OBJ_REPR_A (0)
59
60// A Micro Python object is a machine word having the following form:
61// - xxxx...xx01 : a small int, bits 2 and above are the value
62// - xxxx...xx11 : a qstr, bits 2 and above are the value
63// - xxxx...xxx0 : a pointer to an mp_obj_base_t (unless a fake object)
64#define MICROPY_OBJ_REPR_B (1)
65
66#ifndef MICROPY_OBJ_REPR
67#define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_A)
68#endif
69
70/*****************************************************************************/
Damien George66e18f02014-05-05 13:19:03 +010071/* Memory allocation policy */
72
Damien Georgefd40a9c2015-01-01 22:04:46 +000073// Number of words allocated (in BSS) to the GC stack (minimum is 1)
74#ifndef MICROPY_ALLOC_GC_STACK_SIZE
75#define MICROPY_ALLOC_GC_STACK_SIZE (64)
76#endif
77
Damien Georgeade9a052015-06-13 21:53:22 +010078// Number of bytes to allocate initially when creating new chunks to store
79// interned string data. Smaller numbers lead to more chunks being needed
80// and more wastage at the end of the chunk. Larger numbers lead to wasted
81// space at the end when no more strings need interning.
82#ifndef MICROPY_ALLOC_QSTR_CHUNK_INIT
83#define MICROPY_ALLOC_QSTR_CHUNK_INIT (128)
84#endif
85
Damien Georgee1199ec2014-05-10 17:48:01 +010086// Initial amount for lexer indentation level
Damien George58ebde42014-05-21 20:32:59 +010087#ifndef MICROPY_ALLOC_LEXER_INDENT_INIT
88#define MICROPY_ALLOC_LEXER_INDENT_INIT (10)
Damien Georgee1199ec2014-05-10 17:48:01 +010089#endif
90
91// Increment for lexer indentation level
Damien George58ebde42014-05-21 20:32:59 +010092#ifndef MICROPY_ALLOC_LEXEL_INDENT_INC
93#define MICROPY_ALLOC_LEXEL_INDENT_INC (8)
Damien Georgee1199ec2014-05-10 17:48:01 +010094#endif
95
Damien George66e18f02014-05-05 13:19:03 +010096// Initial amount for parse rule stack
Damien George58ebde42014-05-21 20:32:59 +010097#ifndef MICROPY_ALLOC_PARSE_RULE_INIT
98#define MICROPY_ALLOC_PARSE_RULE_INIT (64)
Damien George66e18f02014-05-05 13:19:03 +010099#endif
100
101// Increment for parse rule stack
Damien George58ebde42014-05-21 20:32:59 +0100102#ifndef MICROPY_ALLOC_PARSE_RULE_INC
103#define MICROPY_ALLOC_PARSE_RULE_INC (16)
Damien George66e18f02014-05-05 13:19:03 +0100104#endif
105
106// Initial amount for parse result stack
Damien George58ebde42014-05-21 20:32:59 +0100107#ifndef MICROPY_ALLOC_PARSE_RESULT_INIT
108#define MICROPY_ALLOC_PARSE_RESULT_INIT (32)
Damien George66e18f02014-05-05 13:19:03 +0100109#endif
110
111// Increment for parse result stack
Damien George58ebde42014-05-21 20:32:59 +0100112#ifndef MICROPY_ALLOC_PARSE_RESULT_INC
113#define MICROPY_ALLOC_PARSE_RESULT_INC (16)
Damien George66e18f02014-05-05 13:19:03 +0100114#endif
115
Damien George5042bce2014-05-25 22:06:06 +0100116// Strings this length or less will be interned by the parser
117#ifndef MICROPY_ALLOC_PARSE_INTERN_STRING_LEN
118#define MICROPY_ALLOC_PARSE_INTERN_STRING_LEN (10)
119#endif
120
Damien George58e0f4a2015-09-23 10:50:43 +0100121// Number of bytes to allocate initially when creating new chunks to store
122// parse nodes. Small leads to fragmentation, large leads to excess use.
123#ifndef MICROPY_ALLOC_PARSE_CHUNK_INIT
124#define MICROPY_ALLOC_PARSE_CHUNK_INIT (128)
125#endif
126
Damien George66e18f02014-05-05 13:19:03 +0100127// Initial amount for ids in a scope
Damien George58ebde42014-05-21 20:32:59 +0100128#ifndef MICROPY_ALLOC_SCOPE_ID_INIT
129#define MICROPY_ALLOC_SCOPE_ID_INIT (4)
Damien George66e18f02014-05-05 13:19:03 +0100130#endif
131
132// Increment for ids in a scope
Damien George58ebde42014-05-21 20:32:59 +0100133#ifndef MICROPY_ALLOC_SCOPE_ID_INC
134#define MICROPY_ALLOC_SCOPE_ID_INC (6)
135#endif
136
137// Maximum length of a path in the filesystem
138// So we can allocate a buffer on the stack for path manipulation in import
139#ifndef MICROPY_ALLOC_PATH_MAX
140#define MICROPY_ALLOC_PATH_MAX (512)
Damien George66e18f02014-05-05 13:19:03 +0100141#endif
142
Paul Sokolovsky346aacf2014-11-05 00:27:15 +0200143// Initial size of module dict
144#ifndef MICROPY_MODULE_DICT_SIZE
145#define MICROPY_MODULE_DICT_SIZE (1)
146#endif
147
Damien Georged8914522015-02-27 09:54:12 +0000148// Whether realloc/free should be passed allocated memory region size
149// You must enable this if MICROPY_MEM_STATS is enabled
150#ifndef MICROPY_MALLOC_USES_ALLOCATED_SIZE
151#define MICROPY_MALLOC_USES_ALLOCATED_SIZE (0)
152#endif
153
Damien George95836f82015-01-11 22:27:30 +0000154// Number of bytes used to store qstr length
155// Dictates hard limit on maximum Python identifier length, but 1 byte
156// (limit of 255 bytes in an identifier) should be enough for everyone
157#ifndef MICROPY_QSTR_BYTES_IN_LEN
158#define MICROPY_QSTR_BYTES_IN_LEN (1)
159#endif
160
Damien Georgec3bd9412015-07-20 11:03:13 +0000161// Number of bytes used to store qstr hash
162#ifndef MICROPY_QSTR_BYTES_IN_HASH
163#define MICROPY_QSTR_BYTES_IN_HASH (2)
164#endif
165
Paul Sokolovsky7f1c9812015-03-28 01:14:45 +0200166// Avoid using C stack when making Python function calls. C stack still
167// may be used if there's no free heap.
Paul Sokolovsky20397572015-03-28 01:14:44 +0200168#ifndef MICROPY_STACKLESS
169#define MICROPY_STACKLESS (0)
170#endif
171
Paul Sokolovsky7f1c9812015-03-28 01:14:45 +0200172// Never use C stack when making Python function calls. This may break
173// testsuite as will subtly change which exception is thrown in case
174// of too deep recursion and other similar cases.
175#ifndef MICROPY_STACKLESS_STRICT
176#define MICROPY_STACKLESS_STRICT (0)
177#endif
178
Damien George66e18f02014-05-05 13:19:03 +0100179/*****************************************************************************/
Damien George136f6752014-01-07 14:54:15 +0000180/* Micro Python emitters */
181
Damien George136f6752014-01-07 14:54:15 +0000182// Whether to emit x64 native code
183#ifndef MICROPY_EMIT_X64
184#define MICROPY_EMIT_X64 (0)
185#endif
186
Damien Georgec90f59e2014-09-06 23:06:36 +0100187// Whether to emit x86 native code
188#ifndef MICROPY_EMIT_X86
189#define MICROPY_EMIT_X86 (0)
190#endif
191
Damien George136f6752014-01-07 14:54:15 +0000192// Whether to emit thumb native code
193#ifndef MICROPY_EMIT_THUMB
194#define MICROPY_EMIT_THUMB (0)
195#endif
196
197// Whether to enable the thumb inline assembler
198#ifndef MICROPY_EMIT_INLINE_THUMB
199#define MICROPY_EMIT_INLINE_THUMB (0)
200#endif
201
=50089722015-04-14 13:14:57 +0100202// Whether to enable float support in the Thumb2 inline assembler
203#ifndef MICROPY_EMIT_INLINE_THUMB_FLOAT
204#define MICROPY_EMIT_INLINE_THUMB_FLOAT (1)
205#endif
206
Fabian Vogtfe3d16e2014-08-16 22:55:53 +0200207// Whether to emit ARM native code
208#ifndef MICROPY_EMIT_ARM
209#define MICROPY_EMIT_ARM (0)
210#endif
211
Damien George2ac4af62014-08-15 16:45:41 +0100212// Convenience definition for whether any native emitter is enabled
Damien Georgec90f59e2014-09-06 23:06:36 +0100213#define MICROPY_EMIT_NATIVE (MICROPY_EMIT_X64 || MICROPY_EMIT_X86 || MICROPY_EMIT_THUMB || MICROPY_EMIT_ARM)
Damien George2ac4af62014-08-15 16:45:41 +0100214
Damien George136f6752014-01-07 14:54:15 +0000215/*****************************************************************************/
Damien George58ebde42014-05-21 20:32:59 +0100216/* Compiler configuration */
217
Damien Georgeddd1e182015-01-10 14:07:24 +0000218// Whether to enable lookup of constants in modules; eg module.CONST
219#ifndef MICROPY_COMP_MODULE_CONST
220#define MICROPY_COMP_MODULE_CONST (0)
221#endif
222
Damien George58ebde42014-05-21 20:32:59 +0100223// Whether to enable constant optimisation; id = const(value)
224#ifndef MICROPY_COMP_CONST
225#define MICROPY_COMP_CONST (1)
226#endif
227
Damien George42e0c592015-03-14 13:11:35 +0000228// Whether to enable optimisation of: a, b = c, d
229// Costs 124 bytes (Thumb2)
230#ifndef MICROPY_COMP_DOUBLE_TUPLE_ASSIGN
231#define MICROPY_COMP_DOUBLE_TUPLE_ASSIGN (1)
232#endif
233
234// Whether to enable optimisation of: a, b, c = d, e, f
235// Cost 156 bytes (Thumb2)
236#ifndef MICROPY_COMP_TRIPLE_TUPLE_ASSIGN
237#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (0)
238#endif
239
Damien George58ebde42014-05-21 20:32:59 +0100240/*****************************************************************************/
Damien George136f6752014-01-07 14:54:15 +0000241/* Internal debugging stuff */
242
243// Whether to collect memory allocation stats
244#ifndef MICROPY_MEM_STATS
245#define MICROPY_MEM_STATS (0)
246#endif
247
Damien Georgecbd2f742014-01-19 11:48:48 +0000248// Whether to build functions that print debugging info:
nhtshot5d323de2015-02-23 15:05:32 -0600249// mp_lexer_show_token
Damien George3417bc22014-05-10 10:36:38 +0100250// mp_bytecode_print
Damien Georgecbd2f742014-01-19 11:48:48 +0000251// mp_parse_node_print
252#ifndef MICROPY_DEBUG_PRINTERS
253#define MICROPY_DEBUG_PRINTERS (0)
Damien Georged3ebe482014-01-07 15:20:33 +0000254#endif
255
Damien George136f6752014-01-07 14:54:15 +0000256/*****************************************************************************/
Damien Georgeee3fd462014-05-24 23:03:12 +0100257/* Optimisations */
258
259// Whether to use computed gotos in the VM, or a switch
260// Computed gotos are roughly 10% faster, and increase VM code size by a little
261#ifndef MICROPY_OPT_COMPUTED_GOTO
262#define MICROPY_OPT_COMPUTED_GOTO (0)
263#endif
264
Damien George7ee91cf2015-01-06 12:51:39 +0000265// Whether to cache result of map lookups in LOAD_NAME, LOAD_GLOBAL, LOAD_ATTR,
266// STORE_ATTR bytecodes. Uses 1 byte extra RAM for each of these opcodes and
267// uses a bit of extra code ROM, but greatly improves lookup speed.
268#ifndef MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE
269#define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE (0)
270#endif
271
Damien Georgeee3fd462014-05-24 23:03:12 +0100272/*****************************************************************************/
273/* Python internal features */
Damien George136f6752014-01-07 14:54:15 +0000274
Damien Georged3ebe482014-01-07 15:20:33 +0000275// Whether to include the garbage collector
276#ifndef MICROPY_ENABLE_GC
277#define MICROPY_ENABLE_GC (0)
278#endif
279
Damien George12bab722014-04-05 20:35:48 +0100280// Whether to enable finalisers in the garbage collector (ie call __del__)
Damien George7860c2a2014-11-05 21:16:41 +0000281#ifndef MICROPY_ENABLE_FINALISER
282#define MICROPY_ENABLE_FINALISER (0)
Damien George12bab722014-04-05 20:35:48 +0100283#endif
284
Paul Sokolovsky23668692014-06-25 03:03:34 +0300285// Whether to check C stack usage. C stack used for calling Python functions,
286// etc. Not checking means segfault on overflow.
287#ifndef MICROPY_STACK_CHECK
Damien George4a5895c2015-01-09 00:10:55 +0000288#define MICROPY_STACK_CHECK (0)
Paul Sokolovsky23668692014-06-25 03:03:34 +0300289#endif
290
Dave Hylands5b7fd202014-07-01 23:46:53 -0700291// Whether to have an emergency exception buffer
292#ifndef MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
293#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (0)
294#endif
295#if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
296# ifndef MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE
297# define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (0) // 0 - implies dynamic allocation
298# endif
299#endif
300
Damien George136f6752014-01-07 14:54:15 +0000301// Whether to include REPL helper function
Damien George58ebde42014-05-21 20:32:59 +0100302#ifndef MICROPY_HELPER_REPL
303#define MICROPY_HELPER_REPL (0)
Damien George136f6752014-01-07 14:54:15 +0000304#endif
305
Tom Soulanille7d588b02015-07-09 16:32:36 -0700306// Whether to include emacs-style readline behavior in REPL
307#ifndef MICROPY_REPL_EMACS_KEYS
Damien Georged8a7f8b2015-07-26 15:49:13 +0100308#define MICROPY_REPL_EMACS_KEYS (0)
Tom Soulanille7d588b02015-07-09 16:32:36 -0700309#endif
310
Damien George0af73012015-08-20 10:34:16 +0100311// Whether to implement auto-indent in REPL
312#ifndef MICROPY_REPL_AUTO_INDENT
313#define MICROPY_REPL_AUTO_INDENT (0)
314#endif
315
Paul Sokolovsky87bc8e22015-01-15 10:46:27 +0200316// Whether port requires event-driven REPL functions
317#ifndef MICROPY_REPL_EVENT_DRIVEN
318#define MICROPY_REPL_EVENT_DRIVEN (0)
319#endif
320
Damien Georged3ebe482014-01-07 15:20:33 +0000321// Whether to include lexer helper function for unix
Damien George58ebde42014-05-21 20:32:59 +0100322#ifndef MICROPY_HELPER_LEXER_UNIX
323#define MICROPY_HELPER_LEXER_UNIX (0)
Damien Georged3ebe482014-01-07 15:20:33 +0000324#endif
325
Paul Sokolovsky48b35722014-01-12 17:30:48 +0200326// Long int implementation
327#define MICROPY_LONGINT_IMPL_NONE (0)
328#define MICROPY_LONGINT_IMPL_LONGLONG (1)
Damien George438c88d2014-02-22 19:25:23 +0000329#define MICROPY_LONGINT_IMPL_MPZ (2)
Paul Sokolovsky48b35722014-01-12 17:30:48 +0200330
331#ifndef MICROPY_LONGINT_IMPL
332#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_NONE)
333#endif
334
335#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG
336typedef long long mp_longint_impl_t;
337#endif
338
Damien George62ad1892014-01-29 21:51:51 +0000339// Whether to include information in the byte code to determine source
340// line number (increases RAM usage, but doesn't slow byte code execution)
341#ifndef MICROPY_ENABLE_SOURCE_LINE
342#define MICROPY_ENABLE_SOURCE_LINE (0)
343#endif
344
Damien George1463c1f2014-04-25 23:52:57 +0100345// Whether to include doc strings (increases RAM usage)
346#ifndef MICROPY_ENABLE_DOC_STRING
347#define MICROPY_ENABLE_DOC_STRING (0)
348#endif
349
Damien George1e9a92f2014-11-06 17:36:16 +0000350// Exception messages are short static strings
Paul Sokolovsky1f85d622014-05-01 01:35:38 +0300351#define MICROPY_ERROR_REPORTING_TERSE (1)
352// Exception messages provide basic error details
353#define MICROPY_ERROR_REPORTING_NORMAL (2)
354// Exception messages provide full info, e.g. object names
355#define MICROPY_ERROR_REPORTING_DETAILED (3)
356
357#ifndef MICROPY_ERROR_REPORTING
358#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_NORMAL)
359#endif
360
Paul Sokolovsky8a8c1fc2015-01-01 09:29:28 +0200361// Whether issue warnings during compiling/execution
362#ifndef MICROPY_WARNINGS
363#define MICROPY_WARNINGS (0)
364#endif
365
Damien George0c36da02014-03-08 15:24:39 +0000366// Float and complex implementation
367#define MICROPY_FLOAT_IMPL_NONE (0)
368#define MICROPY_FLOAT_IMPL_FLOAT (1)
369#define MICROPY_FLOAT_IMPL_DOUBLE (2)
370
371#ifndef MICROPY_FLOAT_IMPL
372#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_NONE)
373#endif
374
375#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
Damien Georgefb510b32014-06-01 13:32:54 +0100376#define MICROPY_PY_BUILTINS_FLOAT (1)
Damien George0c36da02014-03-08 15:24:39 +0000377#define MICROPY_FLOAT_C_FUN(fun) fun##f
378typedef float mp_float_t;
379#elif MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE
Damien Georgefb510b32014-06-01 13:32:54 +0100380#define MICROPY_PY_BUILTINS_FLOAT (1)
Damien George0c36da02014-03-08 15:24:39 +0000381#define MICROPY_FLOAT_C_FUN(fun) fun
382typedef double mp_float_t;
383#else
Damien Georgefb510b32014-06-01 13:32:54 +0100384#define MICROPY_PY_BUILTINS_FLOAT (0)
Damien George136f6752014-01-07 14:54:15 +0000385#endif
386
Paul Sokolovsky3b6f7b92014-06-20 01:48:35 +0300387#ifndef MICROPY_PY_BUILTINS_COMPLEX
388#define MICROPY_PY_BUILTINS_COMPLEX (MICROPY_PY_BUILTINS_FLOAT)
389#endif
390
Paul Sokolovskydcac8802014-01-16 19:19:50 +0200391// Enable features which improve CPython compatibility
392// but may lead to more code size/memory usage.
393// TODO: Originally intended as generic category to not
394// add bunch of once-off options. May need refactoring later
395#ifndef MICROPY_CPYTHON_COMPAT
396#define MICROPY_CPYTHON_COMPAT (1)
397#endif
398
Paul Sokolovsky0ef015b2014-05-07 02:23:46 +0300399// Whether POSIX-semantics non-blocking streams are supported
400#ifndef MICROPY_STREAMS_NON_BLOCK
401#define MICROPY_STREAMS_NON_BLOCK (0)
402#endif
403
Damien Georgec14a8162014-10-12 11:46:04 +0100404// Whether module weak links are supported
405#ifndef MICROPY_MODULE_WEAK_LINKS
406#define MICROPY_MODULE_WEAK_LINKS (0)
407#endif
408
Paul Sokolovsky640e0b22015-01-20 11:52:12 +0200409// Whether frozen modules are supported
410#ifndef MICROPY_MODULE_FROZEN
411#define MICROPY_MODULE_FROZEN (0)
412#endif
413
Damien George78d702c2014-12-09 16:19:48 +0000414// Whether you can override builtins in the builtins module
415#ifndef MICROPY_CAN_OVERRIDE_BUILTINS
416#define MICROPY_CAN_OVERRIDE_BUILTINS (0)
417#endif
418
Damien George06593fb2015-06-19 12:49:10 +0000419// Whether to check that the "self" argument of a builtin method has the
420// correct type. Such an explicit check is only needed if a builtin
421// method escapes to Python land without a first argument, eg
422// list.append([], 1). Without this check such calls will have undefined
423// behaviour (usually segfault) if the first argument is the wrong type.
424#ifndef MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG
425#define MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG (1)
426#endif
427
Damien Georgeee3fd462014-05-24 23:03:12 +0100428/*****************************************************************************/
429/* Fine control over Python builtins, classes, modules, etc */
430
stijn3cc17c62015-02-14 18:44:31 +0100431// Whether to implement attributes on functions
432#ifndef MICROPY_PY_FUNCTION_ATTRS
433#define MICROPY_PY_FUNCTION_ATTRS (0)
434#endif
435
stijn28fa84b2015-02-14 18:43:54 +0100436// Whether to support descriptors (__get__ and __set__)
437// This costs some code size and makes all load attrs and store attrs slow
438#ifndef MICROPY_PY_DESCRIPTORS
439#define MICROPY_PY_DESCRIPTORS (0)
440#endif
441
Paul Sokolovsky12bc13e2014-06-13 01:05:19 +0300442// Whether str object is proper unicode
443#ifndef MICROPY_PY_BUILTINS_STR_UNICODE
444#define MICROPY_PY_BUILTINS_STR_UNICODE (0)
Damien George8546ce12014-06-28 10:29:22 +0100445#endif
Damien Georgeb3a50f02014-06-28 10:27:15 +0100446
Paul Sokolovskyac2f7a72015-04-04 00:09:23 +0300447// Whether str.splitlines() method provided
448#ifndef MICROPY_PY_BUILTINS_STR_SPLITLINES
449#define MICROPY_PY_BUILTINS_STR_SPLITLINES (0)
450#endif
451
Paul Sokolovskycb78f862014-06-27 20:39:09 +0300452// Whether to support bytearray object
453#ifndef MICROPY_PY_BUILTINS_BYTEARRAY
454#define MICROPY_PY_BUILTINS_BYTEARRAY (1)
Paul Sokolovsky12bc13e2014-06-13 01:05:19 +0300455#endif
456
Damien Georgedd4f4532014-10-23 13:34:35 +0100457// Whether to support memoryview object
458#ifndef MICROPY_PY_BUILTINS_MEMORYVIEW
459#define MICROPY_PY_BUILTINS_MEMORYVIEW (0)
460#endif
461
Damien George3ebd4d02014-06-01 13:46:47 +0100462// Whether to support set object
463#ifndef MICROPY_PY_BUILTINS_SET
464#define MICROPY_PY_BUILTINS_SET (1)
465#endif
466
Damien Georgefb510b32014-06-01 13:32:54 +0100467// Whether to support slice subscript operators and slice object
468#ifndef MICROPY_PY_BUILTINS_SLICE
469#define MICROPY_PY_BUILTINS_SLICE (1)
Damien Georgeee3fd462014-05-24 23:03:12 +0100470#endif
471
Tom Soulanilleaeb62f92015-09-11 14:31:32 -0700472// Whether to support slice attribute read access,
473// i.e. slice.start, slice.stop, slice.step
474#ifndef MICROPY_PY_BUILTINS_SLICE_ATTRS
475#define MICROPY_PY_BUILTINS_SLICE_ATTRS (0)
476#endif
477
Damien Georgeee3fd462014-05-24 23:03:12 +0100478// Whether to support frozenset object
Damien Georgefb510b32014-06-01 13:32:54 +0100479#ifndef MICROPY_PY_BUILTINS_FROZENSET
480#define MICROPY_PY_BUILTINS_FROZENSET (0)
Damien Georgeee3fd462014-05-24 23:03:12 +0100481#endif
482
Damien Georgefb510b32014-06-01 13:32:54 +0100483// Whether to support property object
484#ifndef MICROPY_PY_BUILTINS_PROPERTY
485#define MICROPY_PY_BUILTINS_PROPERTY (1)
Damien Georgeee3fd462014-05-24 23:03:12 +0100486#endif
487
Peter D. Grayb2a237d2015-03-06 14:48:14 -0500488// Whether to implement the start/stop/step attributes (readback) on
489// the "range" builtin type. Rarely used, and costs ~60 bytes (x86).
490#ifndef MICROPY_PY_BUILTINS_RANGE_ATTRS
491#define MICROPY_PY_BUILTINS_RANGE_ATTRS (1)
492#endif
493
Daniel Campora077812b2015-06-29 22:45:39 +0200494// Whether to support timeout exceptions (like socket.timeout)
495#ifndef MICROPY_PY_BUILTINS_TIMEOUTERROR
496#define MICROPY_PY_BUILTINS_TIMEOUTERROR (0)
497#endif
498
Paul Sokolovsky98c4bc32015-01-30 01:42:49 +0200499// Whether to support complete set of special methods
500// for user classes, otherwise only the most used
501#ifndef MICROPY_PY_ALL_SPECIAL_METHODS
502#define MICROPY_PY_ALL_SPECIAL_METHODS (0)
503#endif
504
Damien Georgec9fc6202014-10-25 21:59:14 +0100505// Whether to support compile function
506#ifndef MICROPY_PY_BUILTINS_COMPILE
507#define MICROPY_PY_BUILTINS_COMPILE (0)
508#endif
509
Paul Sokolovskye2d44e32015-04-06 23:50:37 +0300510// Whether to support enumerate function(type)
511#ifndef MICROPY_PY_BUILTINS_ENUMERATE
512#define MICROPY_PY_BUILTINS_ENUMERATE (1)
513#endif
514
Damien George2a3e2b92014-12-19 13:36:17 +0000515// Whether to support the Python 2 execfile function
516#ifndef MICROPY_PY_BUILTINS_EXECFILE
517#define MICROPY_PY_BUILTINS_EXECFILE (0)
518#endif
519
Paul Sokolovsky22ff3972015-08-20 01:01:56 +0300520// Whether to support filter function(type)
521#ifndef MICROPY_PY_BUILTINS_FILTER
522#define MICROPY_PY_BUILTINS_FILTER (1)
523#endif
524
Paul Sokolovsky282ca092015-04-07 00:16:51 +0300525// Whether to support reversed function(type)
526#ifndef MICROPY_PY_BUILTINS_REVERSED
527#define MICROPY_PY_BUILTINS_REVERSED (1)
528#endif
529
Paul Sokolovsky5ab5ac52015-05-04 19:45:53 +0300530// Whether to define "NotImplemented" special constant
531#ifndef MICROPY_PY_BUILTINS_NOTIMPLEMENTED
532#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (0)
533#endif
534
Paul Sokolovskyd0f5e612014-07-25 11:00:15 +0300535// Whether to set __file__ for imported modules
536#ifndef MICROPY_PY___FILE__
537#define MICROPY_PY___FILE__ (1)
538#endif
539
Damien George89deec02015-01-09 20:12:54 +0000540// Whether to provide mem-info related functions in micropython module
541#ifndef MICROPY_PY_MICROPYTHON_MEM_INFO
542#define MICROPY_PY_MICROPYTHON_MEM_INFO (0)
543#endif
544
Paul Sokolovskycb78f862014-06-27 20:39:09 +0300545// Whether to provide "array" module. Note that large chunk of the
546// underlying code is shared with "bytearray" builtin type, so to
547// get real savings, it should be disabled too.
548#ifndef MICROPY_PY_ARRAY
549#define MICROPY_PY_ARRAY (1)
550#endif
551
Paul Sokolovskycefcbb22015-02-27 22:16:05 +0200552// Whether to support slice assignments for array (and bytearray).
553// This is rarely used, but adds ~0.5K of code.
554#ifndef MICROPY_PY_ARRAY_SLICE_ASSIGN
555#define MICROPY_PY_ARRAY_SLICE_ASSIGN (0)
556#endif
557
Damien George5aa311d2015-04-21 14:14:24 +0000558// Whether to support attrtuple type (MicroPython extension)
559// It provides space-efficient tuples with attribute access
560#ifndef MICROPY_PY_ATTRTUPLE
561#define MICROPY_PY_ATTRTUPLE (1)
562#endif
563
Damien Georgeee3fd462014-05-24 23:03:12 +0100564// Whether to provide "collections" module
565#ifndef MICROPY_PY_COLLECTIONS
566#define MICROPY_PY_COLLECTIONS (1)
567#endif
568
Paul Sokolovsky0ef01d02015-03-18 01:25:04 +0200569// Whether to provide "collections.OrderedDict" type
570#ifndef MICROPY_PY_COLLECTIONS_ORDEREDDICT
571#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (0)
572#endif
573
Damien Georgeee3fd462014-05-24 23:03:12 +0100574// Whether to provide "math" module
575#ifndef MICROPY_PY_MATH
576#define MICROPY_PY_MATH (1)
577#endif
578
Damien George5cbeace2015-02-22 14:48:18 +0000579// Whether to provide special math functions: math.{erf,erfc,gamma,lgamma}
580#ifndef MICROPY_PY_MATH_SPECIAL_FUNCTIONS
581#define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (0)
582#endif
583
Damien Georgeee3fd462014-05-24 23:03:12 +0100584// Whether to provide "cmath" module
585#ifndef MICROPY_PY_CMATH
586#define MICROPY_PY_CMATH (0)
587#endif
588
589// Whether to provide "gc" module
590#ifndef MICROPY_PY_GC
591#define MICROPY_PY_GC (1)
592#endif
593
Paul Sokolovsky755a55f2014-06-05 22:48:02 +0300594// Whether to return number of collected objects from gc.collect()
595#ifndef MICROPY_PY_GC_COLLECT_RETVAL
596#define MICROPY_PY_GC_COLLECT_RETVAL (0)
597#endif
598
Damien Georgeee3fd462014-05-24 23:03:12 +0100599// Whether to provide "io" module
600#ifndef MICROPY_PY_IO
601#define MICROPY_PY_IO (1)
602#endif
603
604// Whether to provide "io.FileIO" class
605#ifndef MICROPY_PY_IO_FILEIO
606#define MICROPY_PY_IO_FILEIO (0)
607#endif
608
609// Whether to provide "io.BytesIO" class
610#ifndef MICROPY_PY_IO_BYTESIO
611#define MICROPY_PY_IO_BYTESIO (1)
612#endif
613
614// Whether to provide "struct" module
615#ifndef MICROPY_PY_STRUCT
616#define MICROPY_PY_STRUCT (1)
617#endif
618
619// Whether to provide "sys" module
620#ifndef MICROPY_PY_SYS
621#define MICROPY_PY_SYS (1)
622#endif
623
Paul Sokolovsky4e0eeeb2014-07-03 16:50:11 +0300624// Whether to provide "sys.maxsize" constant
625#ifndef MICROPY_PY_SYS_MAXSIZE
626#define MICROPY_PY_SYS_MAXSIZE (0)
627#endif
628
Paul Sokolovsky8b85d142015-04-25 03:17:41 +0300629// Whether to provide "sys.exc_info" function
630// Avoid enabling this, this function is Python2 heritage
631#ifndef MICROPY_PY_SYS_EXC_INFO
632#define MICROPY_PY_SYS_EXC_INFO (0)
633#endif
634
Damien Georgeee3fd462014-05-24 23:03:12 +0100635// Whether to provide "sys.exit" function
636#ifndef MICROPY_PY_SYS_EXIT
637#define MICROPY_PY_SYS_EXIT (0)
638#endif
639
640// Whether to provide sys.{stdin,stdout,stderr} objects
641#ifndef MICROPY_PY_SYS_STDFILES
642#define MICROPY_PY_SYS_STDFILES (0)
Damien George3bb8bd82014-04-14 21:20:30 +0100643#endif
644
Damien George3c4b5d42015-05-13 23:49:21 +0100645// Whether to provide sys.{stdin,stdout,stderr}.buffer object
646// This is implemented per-port
647#ifndef MICROPY_PY_SYS_STDIO_BUFFER
648#define MICROPY_PY_SYS_STDIO_BUFFER (0)
649#endif
Paul Sokolovsky82158472014-06-28 03:03:47 +0300650
651// Extended modules
Paul Sokolovsky510296f2014-08-08 22:51:40 +0300652
Paul Sokolovsky82158472014-06-28 03:03:47 +0300653#ifndef MICROPY_PY_UCTYPES
654#define MICROPY_PY_UCTYPES (0)
655#endif
656
Paul Sokolovsky34162872014-10-12 08:16:34 -0700657#ifndef MICROPY_PY_UZLIB
658#define MICROPY_PY_UZLIB (0)
659#endif
660
Damien George612045f2014-09-17 22:56:34 +0100661#ifndef MICROPY_PY_UJSON
662#define MICROPY_PY_UJSON (0)
663#endif
664
Paul Sokolovskyc71e0452014-09-12 18:48:07 +0300665#ifndef MICROPY_PY_URE
666#define MICROPY_PY_URE (0)
667#endif
668
Damien Georgef5d69792014-10-22 17:37:18 +0000669#ifndef MICROPY_PY_UHEAPQ
670#define MICROPY_PY_UHEAPQ (0)
671#endif
672
Paul Sokolovskyf4b19c82014-11-22 01:19:13 +0200673#ifndef MICROPY_PY_UHASHLIB
674#define MICROPY_PY_UHASHLIB (0)
675#endif
676
Paul Sokolovskybfdc2052014-11-29 06:19:30 +0200677#ifndef MICROPY_PY_UBINASCII
678#define MICROPY_PY_UBINASCII (0)
679#endif
680
Paul Sokolovsky01162182015-05-03 20:25:40 +0300681#ifndef MICROPY_PY_MACHINE
682#define MICROPY_PY_MACHINE (0)
683#endif
684
Damien George58ebde42014-05-21 20:32:59 +0100685/*****************************************************************************/
686/* Hooks for a port to add builtins */
687
Damien Georgecaac5422014-03-25 14:18:18 +0000688// Additional builtin function definitions - see builtintables.c:builtin_object_table for format.
Damien George58ebde42014-05-21 20:32:59 +0100689#ifndef MICROPY_PORT_BUILTINS
690#define MICROPY_PORT_BUILTINS
Paul Sokolovsky910843e2014-02-14 12:02:34 +0200691#endif
Damien Georgecaac5422014-03-25 14:18:18 +0000692
693// Additional builtin module definitions - see builtintables.c:builtin_module_table for format.
Damien George58ebde42014-05-21 20:32:59 +0100694#ifndef MICROPY_PORT_BUILTIN_MODULES
695#define MICROPY_PORT_BUILTIN_MODULES
Damien Georgecaac5422014-03-25 14:18:18 +0000696#endif
697
Damien Georgec14a8162014-10-12 11:46:04 +0100698// Any module weak links - see builtintables.c:mp_builtin_module_weak_links_table.
699#ifndef MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS
700#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS
701#endif
702
Damien George57e99eb2014-04-10 22:42:11 +0100703// Additional constant definitions for the compiler - see compile.c:mp_constants_table.
Damien George58ebde42014-05-21 20:32:59 +0100704#ifndef MICROPY_PORT_CONSTANTS
705#define MICROPY_PORT_CONSTANTS
Damien George57e99eb2014-04-10 22:42:11 +0100706#endif
707
Damien Georgeb4b10fd2015-01-01 23:30:53 +0000708// Any root pointers for GC scanning - see mpstate.c
709#ifndef MICROPY_PORT_ROOT_POINTERS
710#define MICROPY_PORT_ROOT_POINTERS
711#endif
712
Damien George136f6752014-01-07 14:54:15 +0000713/*****************************************************************************/
714/* Miscellaneous settings */
715
Damien George28631532015-02-08 13:42:00 +0000716// All uPy objects in ROM must be aligned on at least a 4 byte boundary
717// so that the small-int/qstr/pointer distinction can be made. For machines
718// that don't do this (eg 16-bit CPU), define the following macro to something
719// like __attribute__((aligned(4))).
720#ifndef MICROPY_OBJ_BASE_ALIGNMENT
721#define MICROPY_OBJ_BASE_ALIGNMENT
722#endif
723
Dave Hylands5b7fd202014-07-01 23:46:53 -0700724// On embedded platforms, these will typically enable/disable irqs.
725#ifndef MICROPY_BEGIN_ATOMIC_SECTION
Damien George4859edb2014-10-15 17:33:24 +0000726#define MICROPY_BEGIN_ATOMIC_SECTION() (0)
Dave Hylands5b7fd202014-07-01 23:46:53 -0700727#endif
728#ifndef MICROPY_END_ATOMIC_SECTION
Damien George4859edb2014-10-15 17:33:24 +0000729#define MICROPY_END_ATOMIC_SECTION(state) (void)(state)
Dave Hylands5b7fd202014-07-01 23:46:53 -0700730#endif
731
Paul Sokolovskyd5df6cd2014-02-12 18:15:40 +0200732// Allow to override static modifier for global objects, e.g. to use with
733// object code analysis tools which don't support static symbols.
734#ifndef STATIC
735#define STATIC static
736#endif
737
Paul Sokolovskyfc5aac82014-01-12 16:10:19 +0200738#define BITS_PER_BYTE (8)
739#define BITS_PER_WORD (BITS_PER_BYTE * BYTES_PER_WORD)
Damien George40f3c022014-07-03 13:25:24 +0100740// mp_int_t value with most significant bit set
741#define WORD_MSBIT_HIGH (((mp_uint_t)1) << (BYTES_PER_WORD * 8 - 1))
Paul Sokolovskyfc5aac82014-01-12 16:10:19 +0200742
Damien Georgea9bcd512014-10-06 13:44:59 +0000743// Make sure both MP_ENDIANNESS_LITTLE and MP_ENDIANNESS_BIG are
744// defined and that they are the opposite of each other.
745#if defined(MP_ENDIANNESS_LITTLE)
746#define MP_ENDIANNESS_BIG (!MP_ENDIANNESS_LITTLE)
747#elif defined(MP_ENDIANNESS_BIG)
748#define MP_ENDIANNESS_LITTLE (!MP_ENDIANNESS_BIG)
749#else
750 // Endiannes not defined by port so try to autodetect it.
751 #if defined(__BYTE_ORDER__)
752 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
753 #define MP_ENDIANNESS_LITTLE (1)
754 #else
755 #define MP_ENDIANNESS_LITTLE (0)
756 #endif
Damien Georgef32498f2014-10-06 16:09:31 +0000757 #elif defined(__LITTLE_ENDIAN__) || defined(__LITTLE_ENDIAN) || defined (_LITTLE_ENDIAN)
758 #define MP_ENDIANNESS_LITTLE (1)
Damien Georgea9bcd512014-10-06 13:44:59 +0000759 #elif defined(__BIG_ENDIAN__) || defined(__BIG_ENDIAN) || defined (_BIG_ENDIAN)
760 #define MP_ENDIANNESS_LITTLE (0)
761 #else
Damien George4e4772b2015-05-30 23:12:30 +0100762 #include <endian.h>
763 #if defined(__BYTE_ORDER)
764 #if __BYTE_ORDER == __LITTLE_ENDIAN
765 #define MP_ENDIANNESS_LITTLE (1)
766 #else
767 #define MP_ENDIANNESS_LITTLE (0)
768 #endif
769 #else
770 #error endianness not defined and cannot detect it
771 #endif
Damien Georgea9bcd512014-10-06 13:44:59 +0000772 #endif
773 #define MP_ENDIANNESS_BIG (!MP_ENDIANNESS_LITTLE)
Andrew Schellercc837372014-04-14 02:39:56 +0100774#endif
Paul Sokolovsky2da81fa2014-04-11 03:44:00 +0300775
Damien George3c658a42014-08-24 16:28:17 +0100776// Make a pointer to RAM callable (eg set lower bit for Thumb code)
777// (This scheme won't work if we want to mix Thumb and normal ARM code.)
778#ifndef MICROPY_MAKE_POINTER_CALLABLE
779#define MICROPY_MAKE_POINTER_CALLABLE(p) (p)
780#endif
781
Damien George7f9d1d62015-04-09 23:56:15 +0100782// If these MP_PLAT_*_EXEC macros are overridden then the memory allocated by them
Damien George2127e9a2015-01-14 00:11:09 +0000783// must be somehow reachable for marking by the GC, since the native code
784// generators store pointers to GC managed memory in the code.
Fabian Vogtb7235b82014-09-03 16:59:33 +0200785#ifndef MP_PLAT_ALLOC_EXEC
Damien George4dea9222015-04-09 15:29:54 +0000786#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 +0200787#endif
788
789#ifndef MP_PLAT_FREE_EXEC
790#define MP_PLAT_FREE_EXEC(ptr, size) m_del(byte, ptr, size)
791#endif
792
Damien George7f9d1d62015-04-09 23:56:15 +0100793// This macro is used to do all output (except when MICROPY_PY_IO is defined)
794#ifndef MP_PLAT_PRINT_STRN
795#define MP_PLAT_PRINT_STRN(str, len) printf("%.*s", (int)len, str)
796#endif
797
Paul Sokolovsky722e5622014-09-06 19:17:23 +0300798#ifndef MP_SSIZE_MAX
799#define MP_SSIZE_MAX SSIZE_MAX
800#endif
801
Damien George40f3c022014-07-03 13:25:24 +0100802// printf format spec to use for mp_int_t and friends
Damien George136f6752014-01-07 14:54:15 +0000803#ifndef INT_FMT
Paul Sokolovskyc90c0f62014-01-04 01:57:00 +0200804#ifdef __LP64__
Damien George40f3c022014-07-03 13:25:24 +0100805// Archs where mp_int_t == long, long != int
Paul Sokolovskyc90c0f62014-01-04 01:57:00 +0200806#define UINT_FMT "%lu"
807#define INT_FMT "%ld"
808#else
Damien George40f3c022014-07-03 13:25:24 +0100809// Archs where mp_int_t == int
Paul Sokolovskyc90c0f62014-01-04 01:57:00 +0200810#define UINT_FMT "%u"
811#define INT_FMT "%d"
812#endif
813#endif //INT_FMT
Paul Sokolovskye9085912014-04-30 05:35:18 +0300814
815// Modifier for function which doesn't return
stijn01d6be42014-05-05 12:18:27 +0200816#ifndef NORETURN
Paul Sokolovskye9085912014-04-30 05:35:18 +0300817#define NORETURN __attribute__((noreturn))
stijn01d6be42014-05-05 12:18:27 +0200818#endif
mux5c8db482014-06-21 17:24:55 +0200819
820// Modifier for weak functions
821#ifndef MP_WEAK
822#define MP_WEAK __attribute__((weak))
823#endif
Paul Sokolovsky361909e2014-12-29 00:51:06 +0200824
825// Condition is likely to be true, to help branch prediction
826#ifndef MP_LIKELY
827#define MP_LIKELY(x) __builtin_expect((x), 1)
828#endif
829
830// Condition is likely to be false, to help branch prediction
831#ifndef MP_UNLIKELY
832#define MP_UNLIKELY(x) __builtin_expect((x), 0)
833#endif
Damien George9ddbe292014-12-29 01:02:19 +0000834
835#endif // __MICROPY_INCLUDED_PY_MPCONFIG_H__