mpconfig.h 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296
  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 00000000 00000000 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. // Cost 156 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 use the POSIX reader for importing files
  340. #ifndef MICROPY_READER_POSIX
  341. #define MICROPY_READER_POSIX (0)
  342. #endif
  343. // Whether to use the VFS reader for importing files
  344. #ifndef MICROPY_READER_VFS
  345. #define MICROPY_READER_VFS (0)
  346. #endif
  347. // Hook for the VM at the start of the opcode loop (can contain variable
  348. // definitions usable by the other hook functions)
  349. #ifndef MICROPY_VM_HOOK_INIT
  350. #define MICROPY_VM_HOOK_INIT
  351. #endif
  352. // Hook for the VM during the opcode loop (but only after jump opcodes)
  353. #ifndef MICROPY_VM_HOOK_LOOP
  354. #define MICROPY_VM_HOOK_LOOP
  355. #endif
  356. // Hook for the VM just before return opcode is finished being interpreted
  357. #ifndef MICROPY_VM_HOOK_RETURN
  358. #define MICROPY_VM_HOOK_RETURN
  359. #endif
  360. // Whether to include the garbage collector
  361. #ifndef MICROPY_ENABLE_GC
  362. #define MICROPY_ENABLE_GC (0)
  363. #endif
  364. // Whether to enable finalisers in the garbage collector (ie call __del__)
  365. #ifndef MICROPY_ENABLE_FINALISER
  366. #define MICROPY_ENABLE_FINALISER (0)
  367. #endif
  368. // Whether to check C stack usage. C stack used for calling Python functions,
  369. // etc. Not checking means segfault on overflow.
  370. #ifndef MICROPY_STACK_CHECK
  371. #define MICROPY_STACK_CHECK (0)
  372. #endif
  373. // Whether to have an emergency exception buffer
  374. #ifndef MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
  375. #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (0)
  376. #endif
  377. #if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
  378. # ifndef MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE
  379. # define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (0) // 0 - implies dynamic allocation
  380. # endif
  381. #endif
  382. // Whether to provide the mp_kbd_exception object, and micropython.kbd_intr function
  383. #ifndef MICROPY_KBD_EXCEPTION
  384. #define MICROPY_KBD_EXCEPTION (0)
  385. #endif
  386. // Prefer to raise KeyboardInterrupt asynchronously (from signal or interrupt
  387. // handler) - if supported by a particular port.
  388. #ifndef MICROPY_ASYNC_KBD_INTR
  389. #define MICROPY_ASYNC_KBD_INTR (0)
  390. #endif
  391. // Whether to include REPL helper function
  392. #ifndef MICROPY_HELPER_REPL
  393. #define MICROPY_HELPER_REPL (0)
  394. #endif
  395. // Whether to include emacs-style readline behavior in REPL
  396. #ifndef MICROPY_REPL_EMACS_KEYS
  397. #define MICROPY_REPL_EMACS_KEYS (0)
  398. #endif
  399. // Whether to implement auto-indent in REPL
  400. #ifndef MICROPY_REPL_AUTO_INDENT
  401. #define MICROPY_REPL_AUTO_INDENT (0)
  402. #endif
  403. // Whether port requires event-driven REPL functions
  404. #ifndef MICROPY_REPL_EVENT_DRIVEN
  405. #define MICROPY_REPL_EVENT_DRIVEN (0)
  406. #endif
  407. // Whether to include lexer helper function for unix
  408. #ifndef MICROPY_HELPER_LEXER_UNIX
  409. #define MICROPY_HELPER_LEXER_UNIX (0)
  410. #endif
  411. // Long int implementation
  412. #define MICROPY_LONGINT_IMPL_NONE (0)
  413. #define MICROPY_LONGINT_IMPL_LONGLONG (1)
  414. #define MICROPY_LONGINT_IMPL_MPZ (2)
  415. #ifndef MICROPY_LONGINT_IMPL
  416. #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_NONE)
  417. #endif
  418. #if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG
  419. typedef long long mp_longint_impl_t;
  420. #endif
  421. // Whether to include information in the byte code to determine source
  422. // line number (increases RAM usage, but doesn't slow byte code execution)
  423. #ifndef MICROPY_ENABLE_SOURCE_LINE
  424. #define MICROPY_ENABLE_SOURCE_LINE (0)
  425. #endif
  426. // Whether to include doc strings (increases RAM usage)
  427. #ifndef MICROPY_ENABLE_DOC_STRING
  428. #define MICROPY_ENABLE_DOC_STRING (0)
  429. #endif
  430. // Exception messages are short static strings
  431. #define MICROPY_ERROR_REPORTING_TERSE (1)
  432. // Exception messages provide basic error details
  433. #define MICROPY_ERROR_REPORTING_NORMAL (2)
  434. // Exception messages provide full info, e.g. object names
  435. #define MICROPY_ERROR_REPORTING_DETAILED (3)
  436. #ifndef MICROPY_ERROR_REPORTING
  437. #define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_NORMAL)
  438. #endif
  439. // Whether issue warnings during compiling/execution
  440. #ifndef MICROPY_WARNINGS
  441. #define MICROPY_WARNINGS (0)
  442. #endif
  443. // This macro is used when printing runtime warnings and errors
  444. #ifndef MICROPY_ERROR_PRINTER
  445. #define MICROPY_ERROR_PRINTER (&mp_plat_print)
  446. #endif
  447. // Float and complex implementation
  448. #define MICROPY_FLOAT_IMPL_NONE (0)
  449. #define MICROPY_FLOAT_IMPL_FLOAT (1)
  450. #define MICROPY_FLOAT_IMPL_DOUBLE (2)
  451. #ifndef MICROPY_FLOAT_IMPL
  452. #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_NONE)
  453. #endif
  454. #if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
  455. #define MICROPY_PY_BUILTINS_FLOAT (1)
  456. #define MICROPY_FLOAT_CONST(x) x##F
  457. #define MICROPY_FLOAT_C_FUN(fun) fun##f
  458. typedef float mp_float_t;
  459. #elif MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE
  460. #define MICROPY_PY_BUILTINS_FLOAT (1)
  461. #define MICROPY_FLOAT_CONST(x) x
  462. #define MICROPY_FLOAT_C_FUN(fun) fun
  463. typedef double mp_float_t;
  464. #else
  465. #define MICROPY_PY_BUILTINS_FLOAT (0)
  466. #endif
  467. #ifndef MICROPY_PY_BUILTINS_COMPLEX
  468. #define MICROPY_PY_BUILTINS_COMPLEX (MICROPY_PY_BUILTINS_FLOAT)
  469. #endif
  470. // Whether to provide a high-quality hash for float and complex numbers.
  471. // Otherwise the default is a very simple but correct hashing function.
  472. #ifndef MICROPY_FLOAT_HIGH_QUALITY_HASH
  473. #define MICROPY_FLOAT_HIGH_QUALITY_HASH (0)
  474. #endif
  475. // Enable features which improve CPython compatibility
  476. // but may lead to more code size/memory usage.
  477. // TODO: Originally intended as generic category to not
  478. // add bunch of once-off options. May need refactoring later
  479. #ifndef MICROPY_CPYTHON_COMPAT
  480. #define MICROPY_CPYTHON_COMPAT (1)
  481. #endif
  482. // Perform full checks as done by CPython. Disabling this
  483. // may produce incorrect results, if incorrect data is fed,
  484. // but should not lead to MicroPython crashes or similar
  485. // grave issues (in other words, only user app should be,
  486. // affected, not system).
  487. #ifndef MICROPY_FULL_CHECKS
  488. #define MICROPY_FULL_CHECKS (1)
  489. #endif
  490. // Whether POSIX-semantics non-blocking streams are supported
  491. #ifndef MICROPY_STREAMS_NON_BLOCK
  492. #define MICROPY_STREAMS_NON_BLOCK (0)
  493. #endif
  494. // Whether to provide stream functions with POSIX-like signatures
  495. // (useful for porting existing libraries to MicroPython).
  496. #ifndef MICROPY_STREAMS_POSIX_API
  497. #define MICROPY_STREAMS_POSIX_API (0)
  498. #endif
  499. // Whether to call __init__ when importing builtin modules for the first time
  500. #ifndef MICROPY_MODULE_BUILTIN_INIT
  501. #define MICROPY_MODULE_BUILTIN_INIT (0)
  502. #endif
  503. // Whether module weak links are supported
  504. #ifndef MICROPY_MODULE_WEAK_LINKS
  505. #define MICROPY_MODULE_WEAK_LINKS (0)
  506. #endif
  507. // Whether frozen modules are supported in the form of strings
  508. #ifndef MICROPY_MODULE_FROZEN_STR
  509. #define MICROPY_MODULE_FROZEN_STR (0)
  510. #endif
  511. // Whether frozen modules are supported in the form of .mpy files
  512. #ifndef MICROPY_MODULE_FROZEN_MPY
  513. #define MICROPY_MODULE_FROZEN_MPY (0)
  514. #endif
  515. // Convenience macro for whether frozen modules are supported
  516. #ifndef MICROPY_MODULE_FROZEN
  517. #define MICROPY_MODULE_FROZEN (MICROPY_MODULE_FROZEN_STR || MICROPY_MODULE_FROZEN_MPY)
  518. #endif
  519. // Whether you can override builtins in the builtins module
  520. #ifndef MICROPY_CAN_OVERRIDE_BUILTINS
  521. #define MICROPY_CAN_OVERRIDE_BUILTINS (0)
  522. #endif
  523. // Whether to check that the "self" argument of a builtin method has the
  524. // correct type. Such an explicit check is only needed if a builtin
  525. // method escapes to Python land without a first argument, eg
  526. // list.append([], 1). Without this check such calls will have undefined
  527. // behaviour (usually segfault) if the first argument is the wrong type.
  528. #ifndef MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG
  529. #define MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG (1)
  530. #endif
  531. // Whether to use internally defined errno's (otherwise system provided ones)
  532. #ifndef MICROPY_USE_INTERNAL_ERRNO
  533. #define MICROPY_USE_INTERNAL_ERRNO (0)
  534. #endif
  535. // Whether to use internally defined *printf() functions (otherwise external ones)
  536. #ifndef MICROPY_USE_INTERNAL_PRINTF
  537. #define MICROPY_USE_INTERNAL_PRINTF (1)
  538. #endif
  539. // Support for internal scheduler
  540. #ifndef MICROPY_ENABLE_SCHEDULER
  541. #define MICROPY_ENABLE_SCHEDULER (0)
  542. #endif
  543. // Maximum number of entries in the scheduler
  544. #ifndef MICROPY_SCHEDULER_DEPTH
  545. #define MICROPY_SCHEDULER_DEPTH (4)
  546. #endif
  547. // Support for generic VFS sub-system
  548. #ifndef MICROPY_VFS
  549. #define MICROPY_VFS (0)
  550. #endif
  551. /*****************************************************************************/
  552. /* Fine control over Python builtins, classes, modules, etc */
  553. // Whether to implement attributes on functions
  554. #ifndef MICROPY_PY_FUNCTION_ATTRS
  555. #define MICROPY_PY_FUNCTION_ATTRS (0)
  556. #endif
  557. // Whether to support descriptors (__get__ and __set__)
  558. // This costs some code size and makes all load attrs and store attrs slow
  559. #ifndef MICROPY_PY_DESCRIPTORS
  560. #define MICROPY_PY_DESCRIPTORS (0)
  561. #endif
  562. // Whether to support class __delattr__ and __setattr__ methods
  563. // This costs some code size and makes all del attrs and store attrs slow
  564. #ifndef MICROPY_PY_DELATTR_SETATTR
  565. #define MICROPY_PY_DELATTR_SETATTR (0)
  566. #endif
  567. // Support for async/await/async for/async with
  568. #ifndef MICROPY_PY_ASYNC_AWAIT
  569. #define MICROPY_PY_ASYNC_AWAIT (1)
  570. #endif
  571. // Issue a warning when comparing str and bytes objects
  572. #ifndef MICROPY_PY_STR_BYTES_CMP_WARN
  573. #define MICROPY_PY_STR_BYTES_CMP_WARN (0)
  574. #endif
  575. // Whether str object is proper unicode
  576. #ifndef MICROPY_PY_BUILTINS_STR_UNICODE
  577. #define MICROPY_PY_BUILTINS_STR_UNICODE (0)
  578. #endif
  579. // Whether to check for valid UTF-8 when converting bytes to str
  580. #ifndef MICROPY_PY_BUILTINS_STR_UNICODE_CHECK
  581. #define MICROPY_PY_BUILTINS_STR_UNICODE_CHECK (MICROPY_PY_BUILTINS_STR_UNICODE)
  582. #endif
  583. // Whether str.center() method provided
  584. #ifndef MICROPY_PY_BUILTINS_STR_CENTER
  585. #define MICROPY_PY_BUILTINS_STR_CENTER (0)
  586. #endif
  587. // Whether str.partition()/str.rpartition() method provided
  588. #ifndef MICROPY_PY_BUILTINS_STR_PARTITION
  589. #define MICROPY_PY_BUILTINS_STR_PARTITION (0)
  590. #endif
  591. // Whether str.splitlines() method provided
  592. #ifndef MICROPY_PY_BUILTINS_STR_SPLITLINES
  593. #define MICROPY_PY_BUILTINS_STR_SPLITLINES (0)
  594. #endif
  595. // Whether to support bytearray object
  596. #ifndef MICROPY_PY_BUILTINS_BYTEARRAY
  597. #define MICROPY_PY_BUILTINS_BYTEARRAY (1)
  598. #endif
  599. // Whether to support memoryview object
  600. #ifndef MICROPY_PY_BUILTINS_MEMORYVIEW
  601. #define MICROPY_PY_BUILTINS_MEMORYVIEW (0)
  602. #endif
  603. // Whether to support set object
  604. #ifndef MICROPY_PY_BUILTINS_SET
  605. #define MICROPY_PY_BUILTINS_SET (1)
  606. #endif
  607. // Whether to support slice subscript operators and slice object
  608. #ifndef MICROPY_PY_BUILTINS_SLICE
  609. #define MICROPY_PY_BUILTINS_SLICE (1)
  610. #endif
  611. // Whether to support slice attribute read access,
  612. // i.e. slice.start, slice.stop, slice.step
  613. #ifndef MICROPY_PY_BUILTINS_SLICE_ATTRS
  614. #define MICROPY_PY_BUILTINS_SLICE_ATTRS (0)
  615. #endif
  616. // Whether to support frozenset object
  617. #ifndef MICROPY_PY_BUILTINS_FROZENSET
  618. #define MICROPY_PY_BUILTINS_FROZENSET (0)
  619. #endif
  620. // Whether to support property object
  621. #ifndef MICROPY_PY_BUILTINS_PROPERTY
  622. #define MICROPY_PY_BUILTINS_PROPERTY (1)
  623. #endif
  624. // Whether to implement the start/stop/step attributes (readback) on
  625. // the "range" builtin type. Rarely used, and costs ~60 bytes (x86).
  626. #ifndef MICROPY_PY_BUILTINS_RANGE_ATTRS
  627. #define MICROPY_PY_BUILTINS_RANGE_ATTRS (1)
  628. #endif
  629. // Whether to support timeout exceptions (like socket.timeout)
  630. #ifndef MICROPY_PY_BUILTINS_TIMEOUTERROR
  631. #define MICROPY_PY_BUILTINS_TIMEOUTERROR (0)
  632. #endif
  633. // Whether to support complete set of special methods for user
  634. // classes, or only the most used ones. "Inplace" methods are
  635. // controlled by MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS below.
  636. // "Reverse" methods are controlled by
  637. // MICROPY_PY_REVERSE_SPECIAL_METHODS below.
  638. #ifndef MICROPY_PY_ALL_SPECIAL_METHODS
  639. #define MICROPY_PY_ALL_SPECIAL_METHODS (0)
  640. #endif
  641. // Whether to support all inplace arithmetic operarion methods
  642. // (__imul__, etc.)
  643. #ifndef MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS
  644. #define MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS (0)
  645. #endif
  646. // Whether to support reverse arithmetic operarion methods
  647. // (__radd__, etc.). Additionally gated by
  648. // MICROPY_PY_ALL_SPECIAL_METHODS.
  649. #ifndef MICROPY_PY_REVERSE_SPECIAL_METHODS
  650. #define MICROPY_PY_REVERSE_SPECIAL_METHODS (0)
  651. #endif
  652. // Whether to support compile function
  653. #ifndef MICROPY_PY_BUILTINS_COMPILE
  654. #define MICROPY_PY_BUILTINS_COMPILE (0)
  655. #endif
  656. // Whether to support enumerate function(type)
  657. #ifndef MICROPY_PY_BUILTINS_ENUMERATE
  658. #define MICROPY_PY_BUILTINS_ENUMERATE (1)
  659. #endif
  660. // Whether to support eval and exec functions
  661. // By default they are supported if the compiler is enabled
  662. #ifndef MICROPY_PY_BUILTINS_EVAL_EXEC
  663. #define MICROPY_PY_BUILTINS_EVAL_EXEC (MICROPY_ENABLE_COMPILER)
  664. #endif
  665. // Whether to support the Python 2 execfile function
  666. #ifndef MICROPY_PY_BUILTINS_EXECFILE
  667. #define MICROPY_PY_BUILTINS_EXECFILE (0)
  668. #endif
  669. // Whether to support filter function(type)
  670. #ifndef MICROPY_PY_BUILTINS_FILTER
  671. #define MICROPY_PY_BUILTINS_FILTER (1)
  672. #endif
  673. // Whether to support reversed function(type)
  674. #ifndef MICROPY_PY_BUILTINS_REVERSED
  675. #define MICROPY_PY_BUILTINS_REVERSED (1)
  676. #endif
  677. // Whether to define "NotImplemented" special constant
  678. #ifndef MICROPY_PY_BUILTINS_NOTIMPLEMENTED
  679. #define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (0)
  680. #endif
  681. // Whether to provide the built-in input() function. The implementation of this
  682. // uses mp-readline, so can only be enabled if the port uses this readline.
  683. #ifndef MICROPY_PY_BUILTINS_INPUT
  684. #define MICROPY_PY_BUILTINS_INPUT (0)
  685. #endif
  686. // Whether to support min/max functions
  687. #ifndef MICROPY_PY_BUILTINS_MIN_MAX
  688. #define MICROPY_PY_BUILTINS_MIN_MAX (1)
  689. #endif
  690. // Support for calls to pow() with 3 integer arguments
  691. #ifndef MICROPY_PY_BUILTINS_POW3
  692. #define MICROPY_PY_BUILTINS_POW3 (0)
  693. #endif
  694. // Whether to provide the help function
  695. #ifndef MICROPY_PY_BUILTINS_HELP
  696. #define MICROPY_PY_BUILTINS_HELP (0)
  697. #endif
  698. // Use this to configure the help text shown for help(). It should be a
  699. // variable with the type "const char*". A sensible default is provided.
  700. #ifndef MICROPY_PY_BUILTINS_HELP_TEXT
  701. #define MICROPY_PY_BUILTINS_HELP_TEXT mp_help_default_text
  702. #endif
  703. // Add the ability to list the available modules when executing help('modules')
  704. #ifndef MICROPY_PY_BUILTINS_HELP_MODULES
  705. #define MICROPY_PY_BUILTINS_HELP_MODULES (0)
  706. #endif
  707. // Whether to set __file__ for imported modules
  708. #ifndef MICROPY_PY___FILE__
  709. #define MICROPY_PY___FILE__ (1)
  710. #endif
  711. // Whether to provide mem-info related functions in micropython module
  712. #ifndef MICROPY_PY_MICROPYTHON_MEM_INFO
  713. #define MICROPY_PY_MICROPYTHON_MEM_INFO (0)
  714. #endif
  715. // Whether to provide "array" module. Note that large chunk of the
  716. // underlying code is shared with "bytearray" builtin type, so to
  717. // get real savings, it should be disabled too.
  718. #ifndef MICROPY_PY_ARRAY
  719. #define MICROPY_PY_ARRAY (1)
  720. #endif
  721. // Whether to support slice assignments for array (and bytearray).
  722. // This is rarely used, but adds ~0.5K of code.
  723. #ifndef MICROPY_PY_ARRAY_SLICE_ASSIGN
  724. #define MICROPY_PY_ARRAY_SLICE_ASSIGN (0)
  725. #endif
  726. // Whether to support attrtuple type (MicroPython extension)
  727. // It provides space-efficient tuples with attribute access
  728. #ifndef MICROPY_PY_ATTRTUPLE
  729. #define MICROPY_PY_ATTRTUPLE (1)
  730. #endif
  731. // Whether to provide "collections" module
  732. #ifndef MICROPY_PY_COLLECTIONS
  733. #define MICROPY_PY_COLLECTIONS (1)
  734. #endif
  735. // Whether to provide "collections.OrderedDict" type
  736. #ifndef MICROPY_PY_COLLECTIONS_ORDEREDDICT
  737. #define MICROPY_PY_COLLECTIONS_ORDEREDDICT (0)
  738. #endif
  739. // Whether to provide "math" module
  740. #ifndef MICROPY_PY_MATH
  741. #define MICROPY_PY_MATH (1)
  742. #endif
  743. // Whether to provide special math functions: math.{erf,erfc,gamma,lgamma}
  744. #ifndef MICROPY_PY_MATH_SPECIAL_FUNCTIONS
  745. #define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (0)
  746. #endif
  747. // Whether to provide "cmath" module
  748. #ifndef MICROPY_PY_CMATH
  749. #define MICROPY_PY_CMATH (0)
  750. #endif
  751. // Whether to provide "gc" module
  752. #ifndef MICROPY_PY_GC
  753. #define MICROPY_PY_GC (1)
  754. #endif
  755. // Whether to return number of collected objects from gc.collect()
  756. #ifndef MICROPY_PY_GC_COLLECT_RETVAL
  757. #define MICROPY_PY_GC_COLLECT_RETVAL (0)
  758. #endif
  759. // Whether to provide "io" module
  760. #ifndef MICROPY_PY_IO
  761. #define MICROPY_PY_IO (1)
  762. #endif
  763. // Whether to provide "uio.resource_stream()" function with
  764. // the semantics of CPython's pkg_resources.resource_stream()
  765. // (allows to access resources in frozen packages).
  766. #ifndef MICROPY_PY_IO_RESOURCE_STREAM
  767. #define MICROPY_PY_IO_RESOURCE_STREAM (0)
  768. #endif
  769. // Whether to provide "io.FileIO" class
  770. #ifndef MICROPY_PY_IO_FILEIO
  771. #define MICROPY_PY_IO_FILEIO (0)
  772. #endif
  773. // Whether to provide "io.BytesIO" class
  774. #ifndef MICROPY_PY_IO_BYTESIO
  775. #define MICROPY_PY_IO_BYTESIO (1)
  776. #endif
  777. // Whether to provide "io.BufferedWriter" class
  778. #ifndef MICROPY_PY_IO_BUFFEREDWRITER
  779. #define MICROPY_PY_IO_BUFFEREDWRITER (0)
  780. #endif
  781. // Whether to provide "struct" module
  782. #ifndef MICROPY_PY_STRUCT
  783. #define MICROPY_PY_STRUCT (1)
  784. #endif
  785. // Whether to provide "sys" module
  786. #ifndef MICROPY_PY_SYS
  787. #define MICROPY_PY_SYS (1)
  788. #endif
  789. // Whether to provide "sys.maxsize" constant
  790. #ifndef MICROPY_PY_SYS_MAXSIZE
  791. #define MICROPY_PY_SYS_MAXSIZE (0)
  792. #endif
  793. // Whether to provide "sys.modules" dictionary
  794. #ifndef MICROPY_PY_SYS_MODULES
  795. #define MICROPY_PY_SYS_MODULES (1)
  796. #endif
  797. // Whether to provide "sys.exc_info" function
  798. // Avoid enabling this, this function is Python2 heritage
  799. #ifndef MICROPY_PY_SYS_EXC_INFO
  800. #define MICROPY_PY_SYS_EXC_INFO (0)
  801. #endif
  802. // Whether to provide "sys.exit" function
  803. #ifndef MICROPY_PY_SYS_EXIT
  804. #define MICROPY_PY_SYS_EXIT (1)
  805. #endif
  806. // Whether to provide "sys.getsizeof" function
  807. #ifndef MICROPY_PY_SYS_GETSIZEOF
  808. #define MICROPY_PY_SYS_GETSIZEOF (0)
  809. #endif
  810. // Whether to provide sys.{stdin,stdout,stderr} objects
  811. #ifndef MICROPY_PY_SYS_STDFILES
  812. #define MICROPY_PY_SYS_STDFILES (0)
  813. #endif
  814. // Whether to provide sys.{stdin,stdout,stderr}.buffer object
  815. // This is implemented per-port
  816. #ifndef MICROPY_PY_SYS_STDIO_BUFFER
  817. #define MICROPY_PY_SYS_STDIO_BUFFER (0)
  818. #endif
  819. // Whether to provide "uerrno" module
  820. #ifndef MICROPY_PY_UERRNO
  821. #define MICROPY_PY_UERRNO (0)
  822. #endif
  823. // Whether to provide the uerrno.errorcode dict
  824. #ifndef MICROPY_PY_UERRNO_ERRORCODE
  825. #define MICROPY_PY_UERRNO_ERRORCODE (1)
  826. #endif
  827. // Whether to provide "uselect" module (baremetal implementation)
  828. #ifndef MICROPY_PY_USELECT
  829. #define MICROPY_PY_USELECT (0)
  830. #endif
  831. // Whether to provide "utime" module functions implementation
  832. // in terms of mp_hal_* functions.
  833. #ifndef MICROPY_PY_UTIME_MP_HAL
  834. #define MICROPY_PY_UTIME_MP_HAL (0)
  835. #endif
  836. // Period of values returned by utime.ticks_ms(), ticks_us(), ticks_cpu()
  837. // functions. Should be power of two. All functions above use the same
  838. // period, so if underlying hardware/API has different periods, the
  839. // minimum of them should be used. The value below is the maximum value
  840. // this parameter can take (corresponding to 30 bit tick values on 32-bit
  841. // system).
  842. #ifndef MICROPY_PY_UTIME_TICKS_PERIOD
  843. #define MICROPY_PY_UTIME_TICKS_PERIOD (MP_SMALL_INT_POSITIVE_MASK + 1)
  844. #endif
  845. // Whether to provide "_thread" module
  846. #ifndef MICROPY_PY_THREAD
  847. #define MICROPY_PY_THREAD (0)
  848. #endif
  849. // Whether to make the VM/runtime thread-safe using a global lock
  850. // If not enabled then thread safety must be provided at the Python level
  851. #ifndef MICROPY_PY_THREAD_GIL
  852. #define MICROPY_PY_THREAD_GIL (MICROPY_PY_THREAD)
  853. #endif
  854. // Number of VM jump-loops to do before releasing the GIL.
  855. // Set this to 0 to disable the divisor.
  856. #ifndef MICROPY_PY_THREAD_GIL_VM_DIVISOR
  857. #define MICROPY_PY_THREAD_GIL_VM_DIVISOR (32)
  858. #endif
  859. // Extended modules
  860. #ifndef MICROPY_PY_UCTYPES
  861. #define MICROPY_PY_UCTYPES (0)
  862. #endif
  863. #ifndef MICROPY_PY_UZLIB
  864. #define MICROPY_PY_UZLIB (0)
  865. #endif
  866. #ifndef MICROPY_PY_UJSON
  867. #define MICROPY_PY_UJSON (0)
  868. #endif
  869. #ifndef MICROPY_PY_URE
  870. #define MICROPY_PY_URE (0)
  871. #endif
  872. #ifndef MICROPY_PY_UHEAPQ
  873. #define MICROPY_PY_UHEAPQ (0)
  874. #endif
  875. // Optimized heap queue for relative timestamps
  876. #ifndef MICROPY_PY_UTIMEQ
  877. #define MICROPY_PY_UTIMEQ (0)
  878. #endif
  879. #ifndef MICROPY_PY_UHASHLIB
  880. #define MICROPY_PY_UHASHLIB (0)
  881. #endif
  882. #ifndef MICROPY_PY_UBINASCII
  883. #define MICROPY_PY_UBINASCII (0)
  884. #endif
  885. // Depends on MICROPY_PY_UZLIB
  886. #ifndef MICROPY_PY_UBINASCII_CRC32
  887. #define MICROPY_PY_UBINASCII_CRC32 (0)
  888. #endif
  889. #ifndef MICROPY_PY_URANDOM
  890. #define MICROPY_PY_URANDOM (0)
  891. #endif
  892. // Whether to include: randrange, randint, choice, random, uniform
  893. #ifndef MICROPY_PY_URANDOM_EXTRA_FUNCS
  894. #define MICROPY_PY_URANDOM_EXTRA_FUNCS (0)
  895. #endif
  896. #ifndef MICROPY_PY_MACHINE
  897. #define MICROPY_PY_MACHINE (0)
  898. #endif
  899. // Whether to include: time_pulse_us
  900. #ifndef MICROPY_PY_MACHINE_PULSE
  901. #define MICROPY_PY_MACHINE_PULSE (0)
  902. #endif
  903. #ifndef MICROPY_PY_MACHINE_I2C
  904. #define MICROPY_PY_MACHINE_I2C (0)
  905. #endif
  906. #ifndef MICROPY_PY_MACHINE_SPI
  907. #define MICROPY_PY_MACHINE_SPI (0)
  908. #endif
  909. #ifndef MICROPY_PY_USSL
  910. #define MICROPY_PY_USSL (0)
  911. // Whether to add finaliser code to ussl objects
  912. #define MICROPY_PY_USSL_FINALISER (0)
  913. #endif
  914. #ifndef MICROPY_PY_WEBSOCKET
  915. #define MICROPY_PY_WEBSOCKET (0)
  916. #endif
  917. #ifndef MICROPY_PY_FRAMEBUF
  918. #define MICROPY_PY_FRAMEBUF (0)
  919. #endif
  920. #ifndef MICROPY_PY_BTREE
  921. #define MICROPY_PY_BTREE (0)
  922. #endif
  923. /*****************************************************************************/
  924. /* Hooks for a port to add builtins */
  925. // Additional builtin function definitions - see builtintables.c:builtin_object_table for format.
  926. #ifndef MICROPY_PORT_BUILTINS
  927. #define MICROPY_PORT_BUILTINS
  928. #endif
  929. // Additional builtin module definitions - see builtintables.c:builtin_module_table for format.
  930. #ifndef MICROPY_PORT_BUILTIN_MODULES
  931. #define MICROPY_PORT_BUILTIN_MODULES
  932. #endif
  933. // Any module weak links - see builtintables.c:mp_builtin_module_weak_links_table.
  934. #ifndef MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS
  935. #define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS
  936. #endif
  937. // Additional constant definitions for the compiler - see compile.c:mp_constants_table.
  938. #ifndef MICROPY_PORT_CONSTANTS
  939. #define MICROPY_PORT_CONSTANTS
  940. #endif
  941. // Any root pointers for GC scanning - see mpstate.c
  942. #ifndef MICROPY_PORT_ROOT_POINTERS
  943. #define MICROPY_PORT_ROOT_POINTERS
  944. #endif
  945. /*****************************************************************************/
  946. /* Miscellaneous settings */
  947. // All uPy objects in ROM must be aligned on at least a 4 byte boundary
  948. // so that the small-int/qstr/pointer distinction can be made. For machines
  949. // that don't do this (eg 16-bit CPU), define the following macro to something
  950. // like __attribute__((aligned(4))).
  951. #ifndef MICROPY_OBJ_BASE_ALIGNMENT
  952. #define MICROPY_OBJ_BASE_ALIGNMENT
  953. #endif
  954. // On embedded platforms, these will typically enable/disable irqs.
  955. #ifndef MICROPY_BEGIN_ATOMIC_SECTION
  956. #define MICROPY_BEGIN_ATOMIC_SECTION() (0)
  957. #endif
  958. #ifndef MICROPY_END_ATOMIC_SECTION
  959. #define MICROPY_END_ATOMIC_SECTION(state) (void)(state)
  960. #endif
  961. // Allow to override static modifier for global objects, e.g. to use with
  962. // object code analysis tools which don't support static symbols.
  963. #ifndef STATIC
  964. #define STATIC static
  965. #endif
  966. // Number of bytes in a word
  967. #ifndef BYTES_PER_WORD
  968. #define BYTES_PER_WORD (sizeof(mp_uint_t))
  969. #endif
  970. #define BITS_PER_BYTE (8)
  971. #define BITS_PER_WORD (BITS_PER_BYTE * BYTES_PER_WORD)
  972. // mp_int_t value with most significant bit set
  973. #define WORD_MSBIT_HIGH (((mp_uint_t)1) << (BYTES_PER_WORD * 8 - 1))
  974. // Make sure both MP_ENDIANNESS_LITTLE and MP_ENDIANNESS_BIG are
  975. // defined and that they are the opposite of each other.
  976. #if defined(MP_ENDIANNESS_LITTLE)
  977. #define MP_ENDIANNESS_BIG (!MP_ENDIANNESS_LITTLE)
  978. #elif defined(MP_ENDIANNESS_BIG)
  979. #define MP_ENDIANNESS_LITTLE (!MP_ENDIANNESS_BIG)
  980. #else
  981. // Endiannes not defined by port so try to autodetect it.
  982. #if defined(__BYTE_ORDER__)
  983. #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
  984. #define MP_ENDIANNESS_LITTLE (1)
  985. #else
  986. #define MP_ENDIANNESS_LITTLE (0)
  987. #endif
  988. #elif defined(__LITTLE_ENDIAN__) || defined(__LITTLE_ENDIAN) || defined (_LITTLE_ENDIAN)
  989. #define MP_ENDIANNESS_LITTLE (1)
  990. #elif defined(__BIG_ENDIAN__) || defined(__BIG_ENDIAN) || defined (_BIG_ENDIAN)
  991. #define MP_ENDIANNESS_LITTLE (0)
  992. #else
  993. #include <endian.h>
  994. #if defined(__BYTE_ORDER)
  995. #if __BYTE_ORDER == __LITTLE_ENDIAN
  996. #define MP_ENDIANNESS_LITTLE (1)
  997. #else
  998. #define MP_ENDIANNESS_LITTLE (0)
  999. #endif
  1000. #else
  1001. #error endianness not defined and cannot detect it
  1002. #endif
  1003. #endif
  1004. #define MP_ENDIANNESS_BIG (!MP_ENDIANNESS_LITTLE)
  1005. #endif
  1006. // Make a pointer to RAM callable (eg set lower bit for Thumb code)
  1007. // (This scheme won't work if we want to mix Thumb and normal ARM code.)
  1008. #ifndef MICROPY_MAKE_POINTER_CALLABLE
  1009. #define MICROPY_MAKE_POINTER_CALLABLE(p) (p)
  1010. #endif
  1011. // If these MP_PLAT_*_EXEC macros are overridden then the memory allocated by them
  1012. // must be somehow reachable for marking by the GC, since the native code
  1013. // generators store pointers to GC managed memory in the code.
  1014. #ifndef MP_PLAT_ALLOC_EXEC
  1015. #define MP_PLAT_ALLOC_EXEC(min_size, ptr, size) do { *ptr = m_new(byte, min_size); *size = min_size; } while (0)
  1016. #endif
  1017. #ifndef MP_PLAT_FREE_EXEC
  1018. #define MP_PLAT_FREE_EXEC(ptr, size) m_del(byte, ptr, size)
  1019. #endif
  1020. // This macro is used to do all output (except when MICROPY_PY_IO is defined)
  1021. #ifndef MP_PLAT_PRINT_STRN
  1022. #define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
  1023. #endif
  1024. #ifndef MP_SSIZE_MAX
  1025. #define MP_SSIZE_MAX SSIZE_MAX
  1026. #endif
  1027. // printf format spec to use for mp_int_t and friends
  1028. #ifndef INT_FMT
  1029. #if defined(__LP64__)
  1030. // Archs where mp_int_t == long, long != int
  1031. #define UINT_FMT "%lu"
  1032. #define INT_FMT "%ld"
  1033. #elif defined(_WIN64)
  1034. #define UINT_FMT "%llu"
  1035. #define INT_FMT "%lld"
  1036. #else
  1037. // Archs where mp_int_t == int
  1038. #define UINT_FMT "%u"
  1039. #define INT_FMT "%d"
  1040. #endif
  1041. #endif //INT_FMT
  1042. // Modifier for function which doesn't return
  1043. #ifndef NORETURN
  1044. #define NORETURN __attribute__((noreturn))
  1045. #endif
  1046. // Modifier for weak functions
  1047. #ifndef MP_WEAK
  1048. #define MP_WEAK __attribute__((weak))
  1049. #endif
  1050. // Modifier for functions which should be never inlined
  1051. #ifndef MP_NOINLINE
  1052. #define MP_NOINLINE __attribute__((noinline))
  1053. #endif
  1054. // Modifier for functions which should be always inlined
  1055. #ifndef MP_ALWAYSINLINE
  1056. #define MP_ALWAYSINLINE __attribute__((always_inline))
  1057. #endif
  1058. // Condition is likely to be true, to help branch prediction
  1059. #ifndef MP_LIKELY
  1060. #define MP_LIKELY(x) __builtin_expect((x), 1)
  1061. #endif
  1062. // Condition is likely to be false, to help branch prediction
  1063. #ifndef MP_UNLIKELY
  1064. #define MP_UNLIKELY(x) __builtin_expect((x), 0)
  1065. #endif
  1066. #endif // MICROPY_INCLUDED_PY_MPCONFIG_H