mpconfig.h 47 KB

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