mpconfig.h 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377
  1. /*
  2. * This file is part of the MicroPython 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. */
  26. #ifndef MICROPY_INCLUDED_PY_MPCONFIG_H
  27. #define MICROPY_INCLUDED_PY_MPCONFIG_H
  28. // This file contains default configuration settings for MicroPython.
  29. // You can override any of the options below using mpconfigport.h file
  30. // located in a directory of your port.
  31. // mpconfigport.h is a file containing configuration settings for a
  32. // particular port. mpconfigport.h is actually a default name for
  33. // such config, and it can be overridden using MP_CONFIGFILE preprocessor
  34. // define (you can do that by passing CFLAGS_EXTRA='-DMP_CONFIGFILE="<file.h>"'
  35. // argument to make when using standard MicroPython makefiles).
  36. // This is useful to have more than one config per port, for example,
  37. // release vs debug configs, etc. Note that if you switch from one config
  38. // to another, you must rebuild from scratch using "-B" switch to make.
  39. #ifdef MP_CONFIGFILE
  40. #include MP_CONFIGFILE
  41. #else
  42. #include <mpconfigport.h>
  43. #endif
  44. // Any options not explicitly set in mpconfigport.h will get default
  45. // values below.
  46. /*****************************************************************************/
  47. /* Object representation */
  48. // A MicroPython object is a machine word having the following form:
  49. // - xxxx...xxx1 : a small int, bits 1 and above are the value
  50. // - xxxx...xx10 : a qstr, bits 2 and above are the value
  51. // - xxxx...xx00 : a pointer to an mp_obj_base_t (unless a fake object)
  52. #define MICROPY_OBJ_REPR_A (0)
  53. // A MicroPython object is a machine word having the following form:
  54. // - xxxx...xx01 : a small int, bits 2 and above are the value
  55. // - xxxx...xx11 : a qstr, bits 2 and above are the value
  56. // - xxxx...xxx0 : a pointer to an mp_obj_base_t (unless a fake object)
  57. #define MICROPY_OBJ_REPR_B (1)
  58. // A MicroPython object is a machine word having the following form (called R):
  59. // - iiiiiiii iiiiiiii iiiiiiii iiiiiii1 small int with 31-bit signed value
  60. // - 01111111 1qqqqqqq qqqqqqqq qqqqq110 str with 20-bit qstr value
  61. // - s1111111 10000000 00000000 00000010 +/- inf
  62. // - s1111111 1xxxxxxx xxxxxxxx xxxxx010 nan, x != 0
  63. // - seeeeeee efffffff ffffffff ffffff10 30-bit fp, e != 0xff
  64. // - pppppppp pppppppp pppppppp pppppp00 ptr (4 byte alignment)
  65. // Str and float stored as O = R + 0x80800000, retrieved as R = O - 0x80800000.
  66. // This makes strs easier to encode/decode as they have zeros in the top 9 bits.
  67. // This scheme only works with 32-bit word size and float enabled.
  68. #define MICROPY_OBJ_REPR_C (2)
  69. // A MicroPython object is a 64-bit word having the following form (called R):
  70. // - seeeeeee eeeeffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff 64-bit fp, e != 0x7ff
  71. // - s1111111 11110000 00000000 00000000 00000000 00000000 00000000 00000000 +/- inf
  72. // - 01111111 11111000 00000000 00000000 00000000 00000000 00000000 00000000 normalised nan
  73. // - 01111111 11111101 iiiiiiii iiiiiiii iiiiiiii iiiiiiii iiiiiiii iiiiiii1 small int
  74. // - 01111111 11111110 00000000 00000000 qqqqqqqq qqqqqqqq qqqqqqqq qqqqqqq1 str
  75. // - 01111111 11111100 00000000 00000000 pppppppp pppppppp pppppppp pppppp00 ptr (4 byte alignment)
  76. // Stored as O = R + 0x8004000000000000, retrieved as R = O - 0x8004000000000000.
  77. // This makes pointers have all zeros in the top 32 bits.
  78. // Small-ints and strs have 1 as LSB to make sure they don't look like pointers
  79. // to the garbage collector.
  80. #define MICROPY_OBJ_REPR_D (3)
  81. #ifndef MICROPY_OBJ_REPR
  82. #define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_A)
  83. #endif
  84. /*****************************************************************************/
  85. /* Memory allocation policy */
  86. // Number of bytes in memory allocation/GC block. Any size allocated will be
  87. // rounded up to be multiples of this.
  88. #ifndef MICROPY_BYTES_PER_GC_BLOCK
  89. #define MICROPY_BYTES_PER_GC_BLOCK (4 * BYTES_PER_WORD)
  90. #endif
  91. // Number of words allocated (in BSS) to the GC stack (minimum is 1)
  92. #ifndef MICROPY_ALLOC_GC_STACK_SIZE
  93. #define MICROPY_ALLOC_GC_STACK_SIZE (64)
  94. #endif
  95. // Be conservative and always clear to zero newly (re)allocated memory in the GC.
  96. // This helps eliminate stray pointers that hold on to memory that's no longer
  97. // used. It decreases performance due to unnecessary memory clearing.
  98. // A memory manager which always clears memory can set this to 0.
  99. // TODO Do analysis to understand why some memory is not properly cleared and
  100. // find a more efficient way to clear it.
  101. #ifndef MICROPY_GC_CONSERVATIVE_CLEAR
  102. #define MICROPY_GC_CONSERVATIVE_CLEAR (MICROPY_ENABLE_GC)
  103. #endif
  104. // Support automatic GC when reaching allocation threshold,
  105. // configurable by gc.threshold().
  106. #ifndef MICROPY_GC_ALLOC_THRESHOLD
  107. #define MICROPY_GC_ALLOC_THRESHOLD (1)
  108. #endif
  109. // Number of bytes to allocate initially when creating new chunks to store
  110. // interned string data. Smaller numbers lead to more chunks being needed
  111. // and more wastage at the end of the chunk. Larger numbers lead to wasted
  112. // space at the end when no more strings need interning.
  113. #ifndef MICROPY_ALLOC_QSTR_CHUNK_INIT
  114. #define MICROPY_ALLOC_QSTR_CHUNK_INIT (128)
  115. #endif
  116. // Initial amount for lexer indentation level
  117. #ifndef MICROPY_ALLOC_LEXER_INDENT_INIT
  118. #define MICROPY_ALLOC_LEXER_INDENT_INIT (10)
  119. #endif
  120. // Increment for lexer indentation level
  121. #ifndef MICROPY_ALLOC_LEXEL_INDENT_INC
  122. #define MICROPY_ALLOC_LEXEL_INDENT_INC (8)
  123. #endif
  124. // Initial amount for parse rule stack
  125. #ifndef MICROPY_ALLOC_PARSE_RULE_INIT
  126. #define MICROPY_ALLOC_PARSE_RULE_INIT (64)
  127. #endif
  128. // Increment for parse rule stack
  129. #ifndef MICROPY_ALLOC_PARSE_RULE_INC
  130. #define MICROPY_ALLOC_PARSE_RULE_INC (16)
  131. #endif
  132. // Initial amount for parse result stack
  133. #ifndef MICROPY_ALLOC_PARSE_RESULT_INIT
  134. #define MICROPY_ALLOC_PARSE_RESULT_INIT (32)
  135. #endif
  136. // Increment for parse result stack
  137. #ifndef MICROPY_ALLOC_PARSE_RESULT_INC
  138. #define MICROPY_ALLOC_PARSE_RESULT_INC (16)
  139. #endif
  140. // Strings this length or less will be interned by the parser
  141. #ifndef MICROPY_ALLOC_PARSE_INTERN_STRING_LEN
  142. #define MICROPY_ALLOC_PARSE_INTERN_STRING_LEN (10)
  143. #endif
  144. // Number of bytes to allocate initially when creating new chunks to store
  145. // parse nodes. Small leads to fragmentation, large leads to excess use.
  146. #ifndef MICROPY_ALLOC_PARSE_CHUNK_INIT
  147. #define MICROPY_ALLOC_PARSE_CHUNK_INIT (128)
  148. #endif
  149. // Initial amount for ids in a scope
  150. #ifndef MICROPY_ALLOC_SCOPE_ID_INIT
  151. #define MICROPY_ALLOC_SCOPE_ID_INIT (4)
  152. #endif
  153. // Increment for ids in a scope
  154. #ifndef MICROPY_ALLOC_SCOPE_ID_INC
  155. #define MICROPY_ALLOC_SCOPE_ID_INC (6)
  156. #endif
  157. // Maximum length of a path in the filesystem
  158. // So we can allocate a buffer on the stack for path manipulation in import
  159. #ifndef MICROPY_ALLOC_PATH_MAX
  160. #define MICROPY_ALLOC_PATH_MAX (512)
  161. #endif
  162. // Initial size of module dict
  163. #ifndef MICROPY_MODULE_DICT_SIZE
  164. #define MICROPY_MODULE_DICT_SIZE (1)
  165. #endif
  166. // Whether realloc/free should be passed allocated memory region size
  167. // You must enable this if MICROPY_MEM_STATS is enabled
  168. #ifndef MICROPY_MALLOC_USES_ALLOCATED_SIZE
  169. #define MICROPY_MALLOC_USES_ALLOCATED_SIZE (0)
  170. #endif
  171. // Number of bytes used to store qstr length
  172. // Dictates hard limit on maximum Python identifier length, but 1 byte
  173. // (limit of 255 bytes in an identifier) should be enough for everyone
  174. #ifndef MICROPY_QSTR_BYTES_IN_LEN
  175. #define MICROPY_QSTR_BYTES_IN_LEN (1)
  176. #endif
  177. // Number of bytes used to store qstr hash
  178. #ifndef MICROPY_QSTR_BYTES_IN_HASH
  179. #define MICROPY_QSTR_BYTES_IN_HASH (2)
  180. #endif
  181. // Avoid using C stack when making Python function calls. C stack still
  182. // may be used if there's no free heap.
  183. #ifndef MICROPY_STACKLESS
  184. #define MICROPY_STACKLESS (0)
  185. #endif
  186. // Never use C stack when making Python function calls. This may break
  187. // testsuite as will subtly change which exception is thrown in case
  188. // of too deep recursion and other similar cases.
  189. #ifndef MICROPY_STACKLESS_STRICT
  190. #define MICROPY_STACKLESS_STRICT (0)
  191. #endif
  192. // Don't use alloca calls. As alloca() is not part of ANSI C, this
  193. // workaround option is provided for compilers lacking this de-facto
  194. // standard function. The way it works is allocating from heap, and
  195. // relying on garbage collection to free it eventually. This is of
  196. // course much less optimal than real alloca().
  197. #if defined(MICROPY_NO_ALLOCA) && MICROPY_NO_ALLOCA
  198. #undef alloca
  199. #define alloca(x) m_malloc(x)
  200. #endif
  201. /*****************************************************************************/
  202. /* MicroPython emitters */
  203. // Whether to support loading of persistent code
  204. #ifndef MICROPY_PERSISTENT_CODE_LOAD
  205. #define MICROPY_PERSISTENT_CODE_LOAD (0)
  206. #endif
  207. // Whether to support saving of persistent code
  208. #ifndef MICROPY_PERSISTENT_CODE_SAVE
  209. #define MICROPY_PERSISTENT_CODE_SAVE (0)
  210. #endif
  211. // Whether generated code can persist independently of the VM/runtime instance
  212. // This is enabled automatically when needed by other features
  213. #ifndef MICROPY_PERSISTENT_CODE
  214. #define MICROPY_PERSISTENT_CODE (MICROPY_PERSISTENT_CODE_LOAD || MICROPY_PERSISTENT_CODE_SAVE || MICROPY_MODULE_FROZEN_MPY)
  215. #endif
  216. // Whether to emit x64 native code
  217. #ifndef MICROPY_EMIT_X64
  218. #define MICROPY_EMIT_X64 (0)
  219. #endif
  220. // Whether to emit x86 native code
  221. #ifndef MICROPY_EMIT_X86
  222. #define MICROPY_EMIT_X86 (0)
  223. #endif
  224. // Whether to emit thumb native code
  225. #ifndef MICROPY_EMIT_THUMB
  226. #define MICROPY_EMIT_THUMB (0)
  227. #endif
  228. // Whether to enable the thumb inline assembler
  229. #ifndef MICROPY_EMIT_INLINE_THUMB
  230. #define MICROPY_EMIT_INLINE_THUMB (0)
  231. #endif
  232. // Whether to enable ARMv7-M instruction support in the Thumb2 inline assembler
  233. #ifndef MICROPY_EMIT_INLINE_THUMB_ARMV7M
  234. #define MICROPY_EMIT_INLINE_THUMB_ARMV7M (1)
  235. #endif
  236. // Whether to enable float support in the Thumb2 inline assembler
  237. #ifndef MICROPY_EMIT_INLINE_THUMB_FLOAT
  238. #define MICROPY_EMIT_INLINE_THUMB_FLOAT (1)
  239. #endif
  240. // Whether to emit ARM native code
  241. #ifndef MICROPY_EMIT_ARM
  242. #define MICROPY_EMIT_ARM (0)
  243. #endif
  244. // Whether to emit Xtensa native code
  245. #ifndef MICROPY_EMIT_XTENSA
  246. #define MICROPY_EMIT_XTENSA (0)
  247. #endif
  248. // Whether to enable the Xtensa inline assembler
  249. #ifndef MICROPY_EMIT_INLINE_XTENSA
  250. #define MICROPY_EMIT_INLINE_XTENSA (0)
  251. #endif
  252. // Convenience definition for whether any native emitter is enabled
  253. #define MICROPY_EMIT_NATIVE (MICROPY_EMIT_X64 || MICROPY_EMIT_X86 || MICROPY_EMIT_THUMB || MICROPY_EMIT_ARM || MICROPY_EMIT_XTENSA)
  254. // Convenience definition for whether any inline assembler emitter is enabled
  255. #define MICROPY_EMIT_INLINE_ASM (MICROPY_EMIT_INLINE_THUMB || MICROPY_EMIT_INLINE_XTENSA)
  256. /*****************************************************************************/
  257. /* Compiler configuration */
  258. // Whether to include the compiler
  259. #ifndef MICROPY_ENABLE_COMPILER
  260. #define MICROPY_ENABLE_COMPILER (1)
  261. #endif
  262. // Whether the compiler is dynamically configurable (ie at runtime)
  263. #ifndef MICROPY_DYNAMIC_COMPILER
  264. #define MICROPY_DYNAMIC_COMPILER (0)
  265. #endif
  266. // Configure dynamic compiler macros
  267. #if MICROPY_DYNAMIC_COMPILER
  268. #define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE_DYNAMIC (mp_dynamic_compiler.opt_cache_map_lookup_in_bytecode)
  269. #define MICROPY_PY_BUILTINS_STR_UNICODE_DYNAMIC (mp_dynamic_compiler.py_builtins_str_unicode)
  270. #else
  271. #define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE_DYNAMIC MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE
  272. #define MICROPY_PY_BUILTINS_STR_UNICODE_DYNAMIC MICROPY_PY_BUILTINS_STR_UNICODE
  273. #endif
  274. // Whether to enable constant folding; eg 1+2 rewritten as 3
  275. #ifndef MICROPY_COMP_CONST_FOLDING
  276. #define MICROPY_COMP_CONST_FOLDING (1)
  277. #endif
  278. // Whether to enable lookup of constants in modules; eg module.CONST
  279. #ifndef MICROPY_COMP_MODULE_CONST
  280. #define MICROPY_COMP_MODULE_CONST (0)
  281. #endif
  282. // Whether to enable constant optimisation; id = const(value)
  283. #ifndef MICROPY_COMP_CONST
  284. #define MICROPY_COMP_CONST (1)
  285. #endif
  286. // Whether to enable optimisation of: a, b = c, d
  287. // Costs 124 bytes (Thumb2)
  288. #ifndef MICROPY_COMP_DOUBLE_TUPLE_ASSIGN
  289. #define MICROPY_COMP_DOUBLE_TUPLE_ASSIGN (1)
  290. #endif
  291. // Whether to enable optimisation of: a, b, c = d, e, f
  292. // Requires MICROPY_COMP_DOUBLE_TUPLE_ASSIGN and costs 68 bytes (Thumb2)
  293. #ifndef MICROPY_COMP_TRIPLE_TUPLE_ASSIGN
  294. #define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (0)
  295. #endif
  296. // Whether to enable optimisation of: return a if b else c
  297. // Costs about 80 bytes (Thumb2) and saves 2 bytes of bytecode for each use
  298. #ifndef MICROPY_COMP_RETURN_IF_EXPR
  299. #define MICROPY_COMP_RETURN_IF_EXPR (0)
  300. #endif
  301. /*****************************************************************************/
  302. /* Internal debugging stuff */
  303. // Whether to collect memory allocation stats
  304. #ifndef MICROPY_MEM_STATS
  305. #define MICROPY_MEM_STATS (0)
  306. #endif
  307. // Whether to build functions that print debugging info:
  308. // mp_bytecode_print
  309. // mp_parse_node_print
  310. #ifndef MICROPY_DEBUG_PRINTERS
  311. #define MICROPY_DEBUG_PRINTERS (0)
  312. #endif
  313. // Whether to enable all debugging outputs (it will be extremely verbose)
  314. #ifndef MICROPY_DEBUG_VERBOSE
  315. #define MICROPY_DEBUG_VERBOSE (0)
  316. #endif
  317. /*****************************************************************************/
  318. /* Optimisations */
  319. // Whether to use computed gotos in the VM, or a switch
  320. // Computed gotos are roughly 10% faster, and increase VM code size by a little
  321. // Note: enabling this will use the gcc-specific extensions of ranged designated
  322. // initialisers and addresses of labels, which are not part of the C99 standard.
  323. #ifndef MICROPY_OPT_COMPUTED_GOTO
  324. #define MICROPY_OPT_COMPUTED_GOTO (0)
  325. #endif
  326. // Whether to cache result of map lookups in LOAD_NAME, LOAD_GLOBAL, LOAD_ATTR,
  327. // STORE_ATTR bytecodes. Uses 1 byte extra RAM for each of these opcodes and
  328. // uses a bit of extra code ROM, but greatly improves lookup speed.
  329. #ifndef MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE
  330. #define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE (0)
  331. #endif
  332. // Whether to use fast versions of bitwise operations (and, or, xor) when the
  333. // arguments are both positive. Increases Thumb2 code size by about 250 bytes.
  334. #ifndef MICROPY_OPT_MPZ_BITWISE
  335. #define MICROPY_OPT_MPZ_BITWISE (0)
  336. #endif
  337. /*****************************************************************************/
  338. /* Python internal features */
  339. // Whether to enable import of external modules
  340. // When disabled, only importing of built-in modules is supported
  341. // When enabled, a port must implement mp_import_stat (among other things)
  342. #ifndef MICROPY_ENABLE_EXTERNAL_IMPORT
  343. #define MICROPY_ENABLE_EXTERNAL_IMPORT (1)
  344. #endif
  345. // Whether to use the POSIX reader for importing files
  346. #ifndef MICROPY_READER_POSIX
  347. #define MICROPY_READER_POSIX (0)
  348. #endif
  349. // Whether to use the VFS reader for importing files
  350. #ifndef MICROPY_READER_VFS
  351. #define MICROPY_READER_VFS (0)
  352. #endif
  353. // Hook for the VM at the start of the opcode loop (can contain variable
  354. // definitions usable by the other hook functions)
  355. #ifndef MICROPY_VM_HOOK_INIT
  356. #define MICROPY_VM_HOOK_INIT
  357. #endif
  358. // Hook for the VM during the opcode loop (but only after jump opcodes)
  359. #ifndef MICROPY_VM_HOOK_LOOP
  360. #define MICROPY_VM_HOOK_LOOP
  361. #endif
  362. // Hook for the VM just before return opcode is finished being interpreted
  363. #ifndef MICROPY_VM_HOOK_RETURN
  364. #define MICROPY_VM_HOOK_RETURN
  365. #endif
  366. // Whether to include the garbage collector
  367. #ifndef MICROPY_ENABLE_GC
  368. #define MICROPY_ENABLE_GC (0)
  369. #endif
  370. // Whether to enable finalisers in the garbage collector (ie call __del__)
  371. #ifndef MICROPY_ENABLE_FINALISER
  372. #define MICROPY_ENABLE_FINALISER (0)
  373. #endif
  374. // Whether to enable a separate allocator for the Python stack.
  375. // If enabled then the code must call mp_pystack_init before mp_init.
  376. #ifndef MICROPY_ENABLE_PYSTACK
  377. #define MICROPY_ENABLE_PYSTACK (0)
  378. #endif
  379. // Number of bytes that memory returned by mp_pystack_alloc will be aligned by.
  380. #ifndef MICROPY_PYSTACK_ALIGN
  381. #define MICROPY_PYSTACK_ALIGN (8)
  382. #endif
  383. // Whether to check C stack usage. C stack used for calling Python functions,
  384. // etc. Not checking means segfault on overflow.
  385. #ifndef MICROPY_STACK_CHECK
  386. #define MICROPY_STACK_CHECK (0)
  387. #endif
  388. // Whether to have an emergency exception buffer
  389. #ifndef MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
  390. #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (0)
  391. #endif
  392. #if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
  393. # ifndef MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE
  394. # define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (0) // 0 - implies dynamic allocation
  395. # endif
  396. #endif
  397. // Whether to provide the mp_kbd_exception object, and micropython.kbd_intr function
  398. #ifndef MICROPY_KBD_EXCEPTION
  399. #define MICROPY_KBD_EXCEPTION (0)
  400. #endif
  401. // Prefer to raise KeyboardInterrupt asynchronously (from signal or interrupt
  402. // handler) - if supported by a particular port.
  403. #ifndef MICROPY_ASYNC_KBD_INTR
  404. #define MICROPY_ASYNC_KBD_INTR (0)
  405. #endif
  406. // Whether to include REPL helper function
  407. #ifndef MICROPY_HELPER_REPL
  408. #define MICROPY_HELPER_REPL (0)
  409. #endif
  410. // Whether to include emacs-style readline behavior in REPL
  411. #ifndef MICROPY_REPL_EMACS_KEYS
  412. #define MICROPY_REPL_EMACS_KEYS (0)
  413. #endif
  414. // Whether to implement auto-indent in REPL
  415. #ifndef MICROPY_REPL_AUTO_INDENT
  416. #define MICROPY_REPL_AUTO_INDENT (0)
  417. #endif
  418. // Whether port requires event-driven REPL functions
  419. #ifndef MICROPY_REPL_EVENT_DRIVEN
  420. #define MICROPY_REPL_EVENT_DRIVEN (0)
  421. #endif
  422. // Whether to include lexer helper function for unix
  423. #ifndef MICROPY_HELPER_LEXER_UNIX
  424. #define MICROPY_HELPER_LEXER_UNIX (0)
  425. #endif
  426. // Long int implementation
  427. #define MICROPY_LONGINT_IMPL_NONE (0)
  428. #define MICROPY_LONGINT_IMPL_LONGLONG (1)
  429. #define MICROPY_LONGINT_IMPL_MPZ (2)
  430. #ifndef MICROPY_LONGINT_IMPL
  431. #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_NONE)
  432. #endif
  433. #if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG
  434. typedef long long mp_longint_impl_t;
  435. #endif
  436. // Whether to include information in the byte code to determine source
  437. // line number (increases RAM usage, but doesn't slow byte code execution)
  438. #ifndef MICROPY_ENABLE_SOURCE_LINE
  439. #define MICROPY_ENABLE_SOURCE_LINE (0)
  440. #endif
  441. // Whether to include doc strings (increases RAM usage)
  442. #ifndef MICROPY_ENABLE_DOC_STRING
  443. #define MICROPY_ENABLE_DOC_STRING (0)
  444. #endif
  445. // Exception messages are short static strings
  446. #define MICROPY_ERROR_REPORTING_TERSE (1)
  447. // Exception messages provide basic error details
  448. #define MICROPY_ERROR_REPORTING_NORMAL (2)
  449. // Exception messages provide full info, e.g. object names
  450. #define MICROPY_ERROR_REPORTING_DETAILED (3)
  451. #ifndef MICROPY_ERROR_REPORTING
  452. #define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_NORMAL)
  453. #endif
  454. // Whether issue warnings during compiling/execution
  455. #ifndef MICROPY_WARNINGS
  456. #define MICROPY_WARNINGS (0)
  457. #endif
  458. // This macro is used when printing runtime warnings and errors
  459. #ifndef MICROPY_ERROR_PRINTER
  460. #define MICROPY_ERROR_PRINTER (&mp_plat_print)
  461. #endif
  462. // Float and complex implementation
  463. #define MICROPY_FLOAT_IMPL_NONE (0)
  464. #define MICROPY_FLOAT_IMPL_FLOAT (1)
  465. #define MICROPY_FLOAT_IMPL_DOUBLE (2)
  466. #ifndef MICROPY_FLOAT_IMPL
  467. #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_NONE)
  468. #endif
  469. #if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
  470. #define MICROPY_PY_BUILTINS_FLOAT (1)
  471. #define MICROPY_FLOAT_CONST(x) x##F
  472. #define MICROPY_FLOAT_C_FUN(fun) fun##f
  473. typedef float mp_float_t;
  474. #elif MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE
  475. #define MICROPY_PY_BUILTINS_FLOAT (1)
  476. #define MICROPY_FLOAT_CONST(x) x
  477. #define MICROPY_FLOAT_C_FUN(fun) fun
  478. typedef double mp_float_t;
  479. #else
  480. #define MICROPY_PY_BUILTINS_FLOAT (0)
  481. #endif
  482. #ifndef MICROPY_PY_BUILTINS_COMPLEX
  483. #define MICROPY_PY_BUILTINS_COMPLEX (MICROPY_PY_BUILTINS_FLOAT)
  484. #endif
  485. // Whether to provide a high-quality hash for float and complex numbers.
  486. // Otherwise the default is a very simple but correct hashing function.
  487. #ifndef MICROPY_FLOAT_HIGH_QUALITY_HASH
  488. #define MICROPY_FLOAT_HIGH_QUALITY_HASH (0)
  489. #endif
  490. // Enable features which improve CPython compatibility
  491. // but may lead to more code size/memory usage.
  492. // TODO: Originally intended as generic category to not
  493. // add bunch of once-off options. May need refactoring later
  494. #ifndef MICROPY_CPYTHON_COMPAT
  495. #define MICROPY_CPYTHON_COMPAT (1)
  496. #endif
  497. // Perform full checks as done by CPython. Disabling this
  498. // may produce incorrect results, if incorrect data is fed,
  499. // but should not lead to MicroPython crashes or similar
  500. // grave issues (in other words, only user app should be,
  501. // affected, not system).
  502. #ifndef MICROPY_FULL_CHECKS
  503. #define MICROPY_FULL_CHECKS (1)
  504. #endif
  505. // Whether POSIX-semantics non-blocking streams are supported
  506. #ifndef MICROPY_STREAMS_NON_BLOCK
  507. #define MICROPY_STREAMS_NON_BLOCK (0)
  508. #endif
  509. // Whether to provide stream functions with POSIX-like signatures
  510. // (useful for porting existing libraries to MicroPython).
  511. #ifndef MICROPY_STREAMS_POSIX_API
  512. #define MICROPY_STREAMS_POSIX_API (0)
  513. #endif
  514. // Whether to call __init__ when importing builtin modules for the first time
  515. #ifndef MICROPY_MODULE_BUILTIN_INIT
  516. #define MICROPY_MODULE_BUILTIN_INIT (0)
  517. #endif
  518. // Whether module weak links are supported
  519. #ifndef MICROPY_MODULE_WEAK_LINKS
  520. #define MICROPY_MODULE_WEAK_LINKS (0)
  521. #endif
  522. // Whether frozen modules are supported in the form of strings
  523. #ifndef MICROPY_MODULE_FROZEN_STR
  524. #define MICROPY_MODULE_FROZEN_STR (0)
  525. #endif
  526. // Whether frozen modules are supported in the form of .mpy files
  527. #ifndef MICROPY_MODULE_FROZEN_MPY
  528. #define MICROPY_MODULE_FROZEN_MPY (0)
  529. #endif
  530. // Convenience macro for whether frozen modules are supported
  531. #ifndef MICROPY_MODULE_FROZEN
  532. #define MICROPY_MODULE_FROZEN (MICROPY_MODULE_FROZEN_STR || MICROPY_MODULE_FROZEN_MPY)
  533. #endif
  534. // Whether you can override builtins in the builtins module
  535. #ifndef MICROPY_CAN_OVERRIDE_BUILTINS
  536. #define MICROPY_CAN_OVERRIDE_BUILTINS (0)
  537. #endif
  538. // Whether to check that the "self" argument of a builtin method has the
  539. // correct type. Such an explicit check is only needed if a builtin
  540. // method escapes to Python land without a first argument, eg
  541. // list.append([], 1). Without this check such calls will have undefined
  542. // behaviour (usually segfault) if the first argument is the wrong type.
  543. #ifndef MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG
  544. #define MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG (1)
  545. #endif
  546. // Whether to use internally defined errno's (otherwise system provided ones)
  547. #ifndef MICROPY_USE_INTERNAL_ERRNO
  548. #define MICROPY_USE_INTERNAL_ERRNO (0)
  549. #endif
  550. // Whether to use internally defined *printf() functions (otherwise external ones)
  551. #ifndef MICROPY_USE_INTERNAL_PRINTF
  552. #define MICROPY_USE_INTERNAL_PRINTF (1)
  553. #endif
  554. // Support for internal scheduler
  555. #ifndef MICROPY_ENABLE_SCHEDULER
  556. #define MICROPY_ENABLE_SCHEDULER (0)
  557. #endif
  558. // Maximum number of entries in the scheduler
  559. #ifndef MICROPY_SCHEDULER_DEPTH
  560. #define MICROPY_SCHEDULER_DEPTH (4)
  561. #endif
  562. // Support for generic VFS sub-system
  563. #ifndef MICROPY_VFS
  564. #define MICROPY_VFS (0)
  565. #endif
  566. /*****************************************************************************/
  567. /* Fine control over Python builtins, classes, modules, etc */
  568. // Whether to support multiple inheritance of Python classes. Multiple
  569. // inheritance makes some C functions inherently recursive, and adds a bit of
  570. // code overhead.
  571. #ifndef MICROPY_MULTIPLE_INHERITANCE
  572. #define MICROPY_MULTIPLE_INHERITANCE (1)
  573. #endif
  574. // Whether to implement attributes on functions
  575. #ifndef MICROPY_PY_FUNCTION_ATTRS
  576. #define MICROPY_PY_FUNCTION_ATTRS (0)
  577. #endif
  578. // Whether to support descriptors (__get__ and __set__)
  579. // This costs some code size and makes all load attrs and store attrs slow
  580. #ifndef MICROPY_PY_DESCRIPTORS
  581. #define MICROPY_PY_DESCRIPTORS (0)
  582. #endif
  583. // Whether to support class __delattr__ and __setattr__ methods
  584. // This costs some code size and makes all del attrs and store attrs slow
  585. #ifndef MICROPY_PY_DELATTR_SETATTR
  586. #define MICROPY_PY_DELATTR_SETATTR (0)
  587. #endif
  588. // Support for async/await/async for/async with
  589. #ifndef MICROPY_PY_ASYNC_AWAIT
  590. #define MICROPY_PY_ASYNC_AWAIT (1)
  591. #endif
  592. // Non-standard .pend_throw() method for generators, allowing for
  593. // Future-like behavior with respect to exception handling: an
  594. // exception set with .pend_throw() will activate on the next call
  595. // to generator's .send() or .__next__(). (This is useful to implement
  596. // async schedulers.)
  597. #ifndef MICROPY_PY_GENERATOR_PEND_THROW
  598. #define MICROPY_PY_GENERATOR_PEND_THROW (1)
  599. #endif
  600. // Issue a warning when comparing str and bytes objects
  601. #ifndef MICROPY_PY_STR_BYTES_CMP_WARN
  602. #define MICROPY_PY_STR_BYTES_CMP_WARN (0)
  603. #endif
  604. // Whether str object is proper unicode
  605. #ifndef MICROPY_PY_BUILTINS_STR_UNICODE
  606. #define MICROPY_PY_BUILTINS_STR_UNICODE (0)
  607. #endif
  608. // Whether to check for valid UTF-8 when converting bytes to str
  609. #ifndef MICROPY_PY_BUILTINS_STR_UNICODE_CHECK
  610. #define MICROPY_PY_BUILTINS_STR_UNICODE_CHECK (MICROPY_PY_BUILTINS_STR_UNICODE)
  611. #endif
  612. // Whether str.center() method provided
  613. #ifndef MICROPY_PY_BUILTINS_STR_CENTER
  614. #define MICROPY_PY_BUILTINS_STR_CENTER (0)
  615. #endif
  616. // Whether str.partition()/str.rpartition() method provided
  617. #ifndef MICROPY_PY_BUILTINS_STR_PARTITION
  618. #define MICROPY_PY_BUILTINS_STR_PARTITION (0)
  619. #endif
  620. // Whether str.splitlines() method provided
  621. #ifndef MICROPY_PY_BUILTINS_STR_SPLITLINES
  622. #define MICROPY_PY_BUILTINS_STR_SPLITLINES (0)
  623. #endif
  624. // Whether to support bytearray object
  625. #ifndef MICROPY_PY_BUILTINS_BYTEARRAY
  626. #define MICROPY_PY_BUILTINS_BYTEARRAY (1)
  627. #endif
  628. // Whether to support memoryview object
  629. #ifndef MICROPY_PY_BUILTINS_MEMORYVIEW
  630. #define MICROPY_PY_BUILTINS_MEMORYVIEW (0)
  631. #endif
  632. // Whether to support set object
  633. #ifndef MICROPY_PY_BUILTINS_SET
  634. #define MICROPY_PY_BUILTINS_SET (1)
  635. #endif
  636. // Whether to support slice subscript operators and slice object
  637. #ifndef MICROPY_PY_BUILTINS_SLICE
  638. #define MICROPY_PY_BUILTINS_SLICE (1)
  639. #endif
  640. // Whether to support slice attribute read access,
  641. // i.e. slice.start, slice.stop, slice.step
  642. #ifndef MICROPY_PY_BUILTINS_SLICE_ATTRS
  643. #define MICROPY_PY_BUILTINS_SLICE_ATTRS (0)
  644. #endif
  645. // Whether to support frozenset object
  646. #ifndef MICROPY_PY_BUILTINS_FROZENSET
  647. #define MICROPY_PY_BUILTINS_FROZENSET (0)
  648. #endif
  649. // Whether to support property object
  650. #ifndef MICROPY_PY_BUILTINS_PROPERTY
  651. #define MICROPY_PY_BUILTINS_PROPERTY (1)
  652. #endif
  653. // Whether to implement the start/stop/step attributes (readback) on
  654. // the "range" builtin type. Rarely used, and costs ~60 bytes (x86).
  655. #ifndef MICROPY_PY_BUILTINS_RANGE_ATTRS
  656. #define MICROPY_PY_BUILTINS_RANGE_ATTRS (1)
  657. #endif
  658. // Whether to support binary ops [only (in)equality is defined] between range
  659. // objects. With this option disabled all range objects that are not exactly
  660. // the same object will compare as not-equal. With it enabled the semantics
  661. // match CPython and ranges are equal if they yield the same sequence of items.
  662. #ifndef MICROPY_PY_BUILTINS_RANGE_BINOP
  663. #define MICROPY_PY_BUILTINS_RANGE_BINOP (0)
  664. #endif
  665. // Whether to support timeout exceptions (like socket.timeout)
  666. #ifndef MICROPY_PY_BUILTINS_TIMEOUTERROR
  667. #define MICROPY_PY_BUILTINS_TIMEOUTERROR (0)
  668. #endif
  669. // Whether to support complete set of special methods for user
  670. // classes, or only the most used ones. "Inplace" methods are
  671. // controlled by MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS below.
  672. // "Reverse" methods are controlled by
  673. // MICROPY_PY_REVERSE_SPECIAL_METHODS below.
  674. #ifndef MICROPY_PY_ALL_SPECIAL_METHODS
  675. #define MICROPY_PY_ALL_SPECIAL_METHODS (0)
  676. #endif
  677. // Whether to support all inplace arithmetic operarion methods
  678. // (__imul__, etc.)
  679. #ifndef MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS
  680. #define MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS (0)
  681. #endif
  682. // Whether to support reverse arithmetic operarion methods
  683. // (__radd__, etc.). Additionally gated by
  684. // MICROPY_PY_ALL_SPECIAL_METHODS.
  685. #ifndef MICROPY_PY_REVERSE_SPECIAL_METHODS
  686. #define MICROPY_PY_REVERSE_SPECIAL_METHODS (0)
  687. #endif
  688. // Whether to support compile function
  689. #ifndef MICROPY_PY_BUILTINS_COMPILE
  690. #define MICROPY_PY_BUILTINS_COMPILE (0)
  691. #endif
  692. // Whether to support enumerate function(type)
  693. #ifndef MICROPY_PY_BUILTINS_ENUMERATE
  694. #define MICROPY_PY_BUILTINS_ENUMERATE (1)
  695. #endif
  696. // Whether to support eval and exec functions
  697. // By default they are supported if the compiler is enabled
  698. #ifndef MICROPY_PY_BUILTINS_EVAL_EXEC
  699. #define MICROPY_PY_BUILTINS_EVAL_EXEC (MICROPY_ENABLE_COMPILER)
  700. #endif
  701. // Whether to support the Python 2 execfile function
  702. #ifndef MICROPY_PY_BUILTINS_EXECFILE
  703. #define MICROPY_PY_BUILTINS_EXECFILE (0)
  704. #endif
  705. // Whether to support filter function(type)
  706. #ifndef MICROPY_PY_BUILTINS_FILTER
  707. #define MICROPY_PY_BUILTINS_FILTER (1)
  708. #endif
  709. // Whether to support reversed function(type)
  710. #ifndef MICROPY_PY_BUILTINS_REVERSED
  711. #define MICROPY_PY_BUILTINS_REVERSED (1)
  712. #endif
  713. // Whether to define "NotImplemented" special constant
  714. #ifndef MICROPY_PY_BUILTINS_NOTIMPLEMENTED
  715. #define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (0)
  716. #endif
  717. // Whether to provide the built-in input() function. The implementation of this
  718. // uses mp-readline, so can only be enabled if the port uses this readline.
  719. #ifndef MICROPY_PY_BUILTINS_INPUT
  720. #define MICROPY_PY_BUILTINS_INPUT (0)
  721. #endif
  722. // Whether to support min/max functions
  723. #ifndef MICROPY_PY_BUILTINS_MIN_MAX
  724. #define MICROPY_PY_BUILTINS_MIN_MAX (1)
  725. #endif
  726. // Support for calls to pow() with 3 integer arguments
  727. #ifndef MICROPY_PY_BUILTINS_POW3
  728. #define MICROPY_PY_BUILTINS_POW3 (0)
  729. #endif
  730. // Whether to provide the help function
  731. #ifndef MICROPY_PY_BUILTINS_HELP
  732. #define MICROPY_PY_BUILTINS_HELP (0)
  733. #endif
  734. // Use this to configure the help text shown for help(). It should be a
  735. // variable with the type "const char*". A sensible default is provided.
  736. #ifndef MICROPY_PY_BUILTINS_HELP_TEXT
  737. #define MICROPY_PY_BUILTINS_HELP_TEXT mp_help_default_text
  738. #endif
  739. // Add the ability to list the available modules when executing help('modules')
  740. #ifndef MICROPY_PY_BUILTINS_HELP_MODULES
  741. #define MICROPY_PY_BUILTINS_HELP_MODULES (0)
  742. #endif
  743. // Whether to set __file__ for imported modules
  744. #ifndef MICROPY_PY___FILE__
  745. #define MICROPY_PY___FILE__ (1)
  746. #endif
  747. // Whether to provide mem-info related functions in micropython module
  748. #ifndef MICROPY_PY_MICROPYTHON_MEM_INFO
  749. #define MICROPY_PY_MICROPYTHON_MEM_INFO (0)
  750. #endif
  751. // Whether to provide "micropython.stack_use" function
  752. #ifndef MICROPY_PY_MICROPYTHON_STACK_USE
  753. #define MICROPY_PY_MICROPYTHON_STACK_USE (MICROPY_PY_MICROPYTHON_MEM_INFO)
  754. #endif
  755. // Whether to provide "array" module. Note that large chunk of the
  756. // underlying code is shared with "bytearray" builtin type, so to
  757. // get real savings, it should be disabled too.
  758. #ifndef MICROPY_PY_ARRAY
  759. #define MICROPY_PY_ARRAY (1)
  760. #endif
  761. // Whether to support slice assignments for array (and bytearray).
  762. // This is rarely used, but adds ~0.5K of code.
  763. #ifndef MICROPY_PY_ARRAY_SLICE_ASSIGN
  764. #define MICROPY_PY_ARRAY_SLICE_ASSIGN (0)
  765. #endif
  766. // Whether to support attrtuple type (MicroPython extension)
  767. // It provides space-efficient tuples with attribute access
  768. #ifndef MICROPY_PY_ATTRTUPLE
  769. #define MICROPY_PY_ATTRTUPLE (1)
  770. #endif
  771. // Whether to provide "collections" module
  772. #ifndef MICROPY_PY_COLLECTIONS
  773. #define MICROPY_PY_COLLECTIONS (1)
  774. #endif
  775. // Whether to provide "ucollections.deque" type
  776. #ifndef MICROPY_PY_COLLECTIONS_DEQUE
  777. #define MICROPY_PY_COLLECTIONS_DEQUE (0)
  778. #endif
  779. // Whether to provide "collections.OrderedDict" type
  780. #ifndef MICROPY_PY_COLLECTIONS_ORDEREDDICT
  781. #define MICROPY_PY_COLLECTIONS_ORDEREDDICT (0)
  782. #endif
  783. // Whether to provide the _asdict function for namedtuple
  784. #ifndef MICROPY_PY_COLLECTIONS_NAMEDTUPLE__ASDICT
  785. #define MICROPY_PY_COLLECTIONS_NAMEDTUPLE__ASDICT (0)
  786. #endif
  787. // Whether to provide "math" module
  788. #ifndef MICROPY_PY_MATH
  789. #define MICROPY_PY_MATH (1)
  790. #endif
  791. // Whether to provide special math functions: math.{erf,erfc,gamma,lgamma}
  792. #ifndef MICROPY_PY_MATH_SPECIAL_FUNCTIONS
  793. #define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (0)
  794. #endif
  795. // Whether to provide "cmath" module
  796. #ifndef MICROPY_PY_CMATH
  797. #define MICROPY_PY_CMATH (0)
  798. #endif
  799. // Whether to provide "gc" module
  800. #ifndef MICROPY_PY_GC
  801. #define MICROPY_PY_GC (1)
  802. #endif
  803. // Whether to return number of collected objects from gc.collect()
  804. #ifndef MICROPY_PY_GC_COLLECT_RETVAL
  805. #define MICROPY_PY_GC_COLLECT_RETVAL (0)
  806. #endif
  807. // Whether to provide "io" module
  808. #ifndef MICROPY_PY_IO
  809. #define MICROPY_PY_IO (1)
  810. #endif
  811. // Whether to provide "uio.resource_stream()" function with
  812. // the semantics of CPython's pkg_resources.resource_stream()
  813. // (allows to access binary resources in frozen source packages).
  814. // Note that the same functionality can be achieved in "pure
  815. // Python" by prepocessing binary resources into Python source
  816. // and bytecode-freezing it (with a simple helper module available
  817. // e.g. in micropython-lib).
  818. #ifndef MICROPY_PY_IO_RESOURCE_STREAM
  819. #define MICROPY_PY_IO_RESOURCE_STREAM (0)
  820. #endif
  821. // Whether to provide "io.FileIO" class
  822. #ifndef MICROPY_PY_IO_FILEIO
  823. #define MICROPY_PY_IO_FILEIO (0)
  824. #endif
  825. // Whether to provide "io.BytesIO" class
  826. #ifndef MICROPY_PY_IO_BYTESIO
  827. #define MICROPY_PY_IO_BYTESIO (1)
  828. #endif
  829. // Whether to provide "io.BufferedWriter" class
  830. #ifndef MICROPY_PY_IO_BUFFEREDWRITER
  831. #define MICROPY_PY_IO_BUFFEREDWRITER (0)
  832. #endif
  833. // Whether to provide "struct" module
  834. #ifndef MICROPY_PY_STRUCT
  835. #define MICROPY_PY_STRUCT (1)
  836. #endif
  837. // Whether to provide "sys" module
  838. #ifndef MICROPY_PY_SYS
  839. #define MICROPY_PY_SYS (1)
  840. #endif
  841. // Whether to provide "sys.maxsize" constant
  842. #ifndef MICROPY_PY_SYS_MAXSIZE
  843. #define MICROPY_PY_SYS_MAXSIZE (0)
  844. #endif
  845. // Whether to provide "sys.modules" dictionary
  846. #ifndef MICROPY_PY_SYS_MODULES
  847. #define MICROPY_PY_SYS_MODULES (1)
  848. #endif
  849. // Whether to provide "sys.exc_info" function
  850. // Avoid enabling this, this function is Python2 heritage
  851. #ifndef MICROPY_PY_SYS_EXC_INFO
  852. #define MICROPY_PY_SYS_EXC_INFO (0)
  853. #endif
  854. // Whether to provide "sys.exit" function
  855. #ifndef MICROPY_PY_SYS_EXIT
  856. #define MICROPY_PY_SYS_EXIT (1)
  857. #endif
  858. // Whether to provide "sys.getsizeof" function
  859. #ifndef MICROPY_PY_SYS_GETSIZEOF
  860. #define MICROPY_PY_SYS_GETSIZEOF (0)
  861. #endif
  862. // Whether to provide sys.{stdin,stdout,stderr} objects
  863. #ifndef MICROPY_PY_SYS_STDFILES
  864. #define MICROPY_PY_SYS_STDFILES (0)
  865. #endif
  866. // Whether to provide sys.{stdin,stdout,stderr}.buffer object
  867. // This is implemented per-port
  868. #ifndef MICROPY_PY_SYS_STDIO_BUFFER
  869. #define MICROPY_PY_SYS_STDIO_BUFFER (0)
  870. #endif
  871. // Whether to provide "uerrno" module
  872. #ifndef MICROPY_PY_UERRNO
  873. #define MICROPY_PY_UERRNO (0)
  874. #endif
  875. // Whether to provide the uerrno.errorcode dict
  876. #ifndef MICROPY_PY_UERRNO_ERRORCODE
  877. #define MICROPY_PY_UERRNO_ERRORCODE (1)
  878. #endif
  879. // Whether to provide "uselect" module (baremetal implementation)
  880. #ifndef MICROPY_PY_USELECT
  881. #define MICROPY_PY_USELECT (0)
  882. #endif
  883. // Whether to provide "utime" module functions implementation
  884. // in terms of mp_hal_* functions.
  885. #ifndef MICROPY_PY_UTIME_MP_HAL
  886. #define MICROPY_PY_UTIME_MP_HAL (0)
  887. #endif
  888. // Period of values returned by utime.ticks_ms(), ticks_us(), ticks_cpu()
  889. // functions. Should be power of two. All functions above use the same
  890. // period, so if underlying hardware/API has different periods, the
  891. // minimum of them should be used. The value below is the maximum value
  892. // this parameter can take (corresponding to 30 bit tick values on 32-bit
  893. // system).
  894. #ifndef MICROPY_PY_UTIME_TICKS_PERIOD
  895. #define MICROPY_PY_UTIME_TICKS_PERIOD (MP_SMALL_INT_POSITIVE_MASK + 1)
  896. #endif
  897. // Whether to provide "_thread" module
  898. #ifndef MICROPY_PY_THREAD
  899. #define MICROPY_PY_THREAD (0)
  900. #endif
  901. // Whether to make the VM/runtime thread-safe using a global lock
  902. // If not enabled then thread safety must be provided at the Python level
  903. #ifndef MICROPY_PY_THREAD_GIL
  904. #define MICROPY_PY_THREAD_GIL (MICROPY_PY_THREAD)
  905. #endif
  906. // Number of VM jump-loops to do before releasing the GIL.
  907. // Set this to 0 to disable the divisor.
  908. #ifndef MICROPY_PY_THREAD_GIL_VM_DIVISOR
  909. #define MICROPY_PY_THREAD_GIL_VM_DIVISOR (32)
  910. #endif
  911. // Extended modules
  912. #ifndef MICROPY_PY_UCTYPES
  913. #define MICROPY_PY_UCTYPES (0)
  914. #endif
  915. #ifndef MICROPY_PY_UZLIB
  916. #define MICROPY_PY_UZLIB (0)
  917. #endif
  918. #ifndef MICROPY_PY_UJSON
  919. #define MICROPY_PY_UJSON (0)
  920. #endif
  921. #ifndef MICROPY_PY_URE
  922. #define MICROPY_PY_URE (0)
  923. #endif
  924. #ifndef MICROPY_PY_UHEAPQ
  925. #define MICROPY_PY_UHEAPQ (0)
  926. #endif
  927. // Optimized heap queue for relative timestamps
  928. #ifndef MICROPY_PY_UTIMEQ
  929. #define MICROPY_PY_UTIMEQ (0)
  930. #endif
  931. #ifndef MICROPY_PY_UHASHLIB
  932. #define MICROPY_PY_UHASHLIB (0)
  933. #endif
  934. #ifndef MICROPY_PY_UBINASCII
  935. #define MICROPY_PY_UBINASCII (0)
  936. #endif
  937. // Depends on MICROPY_PY_UZLIB
  938. #ifndef MICROPY_PY_UBINASCII_CRC32
  939. #define MICROPY_PY_UBINASCII_CRC32 (0)
  940. #endif
  941. #ifndef MICROPY_PY_URANDOM
  942. #define MICROPY_PY_URANDOM (0)
  943. #endif
  944. // Whether to include: randrange, randint, choice, random, uniform
  945. #ifndef MICROPY_PY_URANDOM_EXTRA_FUNCS
  946. #define MICROPY_PY_URANDOM_EXTRA_FUNCS (0)
  947. #endif
  948. #ifndef MICROPY_PY_MACHINE
  949. #define MICROPY_PY_MACHINE (0)
  950. #endif
  951. // Whether to include: time_pulse_us
  952. #ifndef MICROPY_PY_MACHINE_PULSE
  953. #define MICROPY_PY_MACHINE_PULSE (0)
  954. #endif
  955. #ifndef MICROPY_PY_MACHINE_I2C
  956. #define MICROPY_PY_MACHINE_I2C (0)
  957. #endif
  958. #ifndef MICROPY_PY_MACHINE_SPI
  959. #define MICROPY_PY_MACHINE_SPI (0)
  960. #endif
  961. #ifndef MICROPY_PY_USSL
  962. #define MICROPY_PY_USSL (0)
  963. // Whether to add finaliser code to ussl objects
  964. #define MICROPY_PY_USSL_FINALISER (0)
  965. #endif
  966. #ifndef MICROPY_PY_WEBSOCKET
  967. #define MICROPY_PY_WEBSOCKET (0)
  968. #endif
  969. #ifndef MICROPY_PY_FRAMEBUF
  970. #define MICROPY_PY_FRAMEBUF (0)
  971. #endif
  972. #ifndef MICROPY_PY_BTREE
  973. #define MICROPY_PY_BTREE (0)
  974. #endif
  975. /*****************************************************************************/
  976. /* Hooks for a port to add builtins */
  977. // Additional builtin function definitions - see builtintables.c:builtin_object_table for format.
  978. #ifndef MICROPY_PORT_BUILTINS
  979. #define MICROPY_PORT_BUILTINS
  980. #endif
  981. // Additional builtin module definitions - see builtintables.c:builtin_module_table for format.
  982. #ifndef MICROPY_PORT_BUILTIN_MODULES
  983. #define MICROPY_PORT_BUILTIN_MODULES
  984. #endif
  985. // Any module weak links - see builtintables.c:mp_builtin_module_weak_links_table.
  986. #ifndef MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS
  987. #define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS
  988. #endif
  989. // Additional constant definitions for the compiler - see compile.c:mp_constants_table.
  990. #ifndef MICROPY_PORT_CONSTANTS
  991. #define MICROPY_PORT_CONSTANTS
  992. #endif
  993. // Any root pointers for GC scanning - see mpstate.c
  994. #ifndef MICROPY_PORT_ROOT_POINTERS
  995. #define MICROPY_PORT_ROOT_POINTERS
  996. #endif
  997. /*****************************************************************************/
  998. /* Miscellaneous settings */
  999. // All uPy objects in ROM must be aligned on at least a 4 byte boundary
  1000. // so that the small-int/qstr/pointer distinction can be made. For machines
  1001. // that don't do this (eg 16-bit CPU), define the following macro to something
  1002. // like __attribute__((aligned(4))).
  1003. #ifndef MICROPY_OBJ_BASE_ALIGNMENT
  1004. #define MICROPY_OBJ_BASE_ALIGNMENT
  1005. #endif
  1006. // On embedded platforms, these will typically enable/disable irqs.
  1007. #ifndef MICROPY_BEGIN_ATOMIC_SECTION
  1008. #define MICROPY_BEGIN_ATOMIC_SECTION() (0)
  1009. #endif
  1010. #ifndef MICROPY_END_ATOMIC_SECTION
  1011. #define MICROPY_END_ATOMIC_SECTION(state) (void)(state)
  1012. #endif
  1013. // Allow to override static modifier for global objects, e.g. to use with
  1014. // object code analysis tools which don't support static symbols.
  1015. #ifndef STATIC
  1016. #define STATIC static
  1017. #endif
  1018. // Number of bytes in a word
  1019. #ifndef BYTES_PER_WORD
  1020. #define BYTES_PER_WORD (sizeof(mp_uint_t))
  1021. #endif
  1022. #define BITS_PER_BYTE (8)
  1023. #define BITS_PER_WORD (BITS_PER_BYTE * BYTES_PER_WORD)
  1024. // mp_int_t value with most significant bit set
  1025. #define WORD_MSBIT_HIGH (((mp_uint_t)1) << (BYTES_PER_WORD * 8 - 1))
  1026. // Make sure both MP_ENDIANNESS_LITTLE and MP_ENDIANNESS_BIG are
  1027. // defined and that they are the opposite of each other.
  1028. #if defined(MP_ENDIANNESS_LITTLE)
  1029. #define MP_ENDIANNESS_BIG (!MP_ENDIANNESS_LITTLE)
  1030. #elif defined(MP_ENDIANNESS_BIG)
  1031. #define MP_ENDIANNESS_LITTLE (!MP_ENDIANNESS_BIG)
  1032. #else
  1033. // Endiannes not defined by port so try to autodetect it.
  1034. #if defined(__BYTE_ORDER__)
  1035. #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
  1036. #define MP_ENDIANNESS_LITTLE (1)
  1037. #else
  1038. #define MP_ENDIANNESS_LITTLE (0)
  1039. #endif
  1040. #elif defined(__LITTLE_ENDIAN__) || defined(__LITTLE_ENDIAN) || defined (_LITTLE_ENDIAN)
  1041. #define MP_ENDIANNESS_LITTLE (1)
  1042. #elif defined(__BIG_ENDIAN__) || defined(__BIG_ENDIAN) || defined (_BIG_ENDIAN)
  1043. #define MP_ENDIANNESS_LITTLE (0)
  1044. #else
  1045. #include <endian.h>
  1046. #if defined(__BYTE_ORDER)
  1047. #if __BYTE_ORDER == __LITTLE_ENDIAN
  1048. #define MP_ENDIANNESS_LITTLE (1)
  1049. #else
  1050. #define MP_ENDIANNESS_LITTLE (0)
  1051. #endif
  1052. #else
  1053. #error endianness not defined and cannot detect it
  1054. #endif
  1055. #endif
  1056. #define MP_ENDIANNESS_BIG (!MP_ENDIANNESS_LITTLE)
  1057. #endif
  1058. // Make a pointer to RAM callable (eg set lower bit for Thumb code)
  1059. // (This scheme won't work if we want to mix Thumb and normal ARM code.)
  1060. #ifndef MICROPY_MAKE_POINTER_CALLABLE
  1061. #define MICROPY_MAKE_POINTER_CALLABLE(p) (p)
  1062. #endif
  1063. // If these MP_PLAT_*_EXEC macros are overridden then the memory allocated by them
  1064. // must be somehow reachable for marking by the GC, since the native code
  1065. // generators store pointers to GC managed memory in the code.
  1066. #ifndef MP_PLAT_ALLOC_EXEC
  1067. #define MP_PLAT_ALLOC_EXEC(min_size, ptr, size) do { *ptr = m_new(byte, min_size); *size = min_size; } while (0)
  1068. #endif
  1069. #ifndef MP_PLAT_FREE_EXEC
  1070. #define MP_PLAT_FREE_EXEC(ptr, size) m_del(byte, ptr, size)
  1071. #endif
  1072. // This macro is used to do all output (except when MICROPY_PY_IO is defined)
  1073. #ifndef MP_PLAT_PRINT_STRN
  1074. #define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
  1075. #endif
  1076. #ifndef MP_SSIZE_MAX
  1077. #define MP_SSIZE_MAX SSIZE_MAX
  1078. #endif
  1079. // printf format spec to use for mp_int_t and friends
  1080. #ifndef INT_FMT
  1081. #if defined(__LP64__)
  1082. // Archs where mp_int_t == long, long != int
  1083. #define UINT_FMT "%lu"
  1084. #define INT_FMT "%ld"
  1085. #elif defined(_WIN64)
  1086. #define UINT_FMT "%llu"
  1087. #define INT_FMT "%lld"
  1088. #else
  1089. // Archs where mp_int_t == int
  1090. #define UINT_FMT "%u"
  1091. #define INT_FMT "%d"
  1092. #endif
  1093. #endif //INT_FMT
  1094. // Modifier for function which doesn't return
  1095. #ifndef NORETURN
  1096. #define NORETURN __attribute__((noreturn))
  1097. #endif
  1098. // Modifier for weak functions
  1099. #ifndef MP_WEAK
  1100. #define MP_WEAK __attribute__((weak))
  1101. #endif
  1102. // Modifier for functions which should be never inlined
  1103. #ifndef MP_NOINLINE
  1104. #define MP_NOINLINE __attribute__((noinline))
  1105. #endif
  1106. // Modifier for functions which should be always inlined
  1107. #ifndef MP_ALWAYSINLINE
  1108. #define MP_ALWAYSINLINE __attribute__((always_inline))
  1109. #endif
  1110. // Condition is likely to be true, to help branch prediction
  1111. #ifndef MP_LIKELY
  1112. #define MP_LIKELY(x) __builtin_expect((x), 1)
  1113. #endif
  1114. // Condition is likely to be false, to help branch prediction
  1115. #ifndef MP_UNLIKELY
  1116. #define MP_UNLIKELY(x) __builtin_expect((x), 0)
  1117. #endif
  1118. #ifndef MP_HTOBE16
  1119. #if MP_ENDIANNESS_LITTLE
  1120. # define MP_HTOBE16(x) ((uint16_t)( (((x) & 0xff) << 8) | (((x) >> 8) & 0xff) ))
  1121. # define MP_BE16TOH(x) MP_HTOBE16(x)
  1122. #else
  1123. # define MP_HTOBE16(x) (x)
  1124. # define MP_BE16TOH(x) (x)
  1125. #endif
  1126. #endif
  1127. #ifndef MP_HTOBE32
  1128. #if MP_ENDIANNESS_LITTLE
  1129. # define MP_HTOBE32(x) ((uint32_t)( (((x) & 0xff) << 24) | (((x) & 0xff00) << 8) | (((x) >> 8) & 0xff00) | (((x) >> 24) & 0xff) ))
  1130. # define MP_BE32TOH(x) MP_HTOBE32(x)
  1131. #else
  1132. # define MP_HTOBE32(x) (x)
  1133. # define MP_BE32TOH(x) (x)
  1134. #endif
  1135. #endif
  1136. #endif // MICROPY_INCLUDED_PY_MPCONFIG_H