mpconfig.h 45 KB

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