mpconfig.h 49 KB

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