mpconfig.h 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035
  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. This is used by sys.implementation.version
  29. // as well as a fallback to generate MICROPY_GIT_TAG if the git repo or tags
  30. // are unavailable.
  31. #define MICROPY_VERSION_MAJOR 1
  32. #define MICROPY_VERSION_MINOR 22
  33. #define MICROPY_VERSION_MICRO 2
  34. #define MICROPY_VERSION_PRERELEASE 0
  35. // Combined version as a 32-bit number for convenience to allow version
  36. // comparison. Doesn't include prerelease state.
  37. // e.g. #if MICROPY_VERSION < MICROPY_MAKE_VERSION(1, 22, 0)
  38. #define MICROPY_MAKE_VERSION(major, minor, patch) (major << 16 | minor << 8 | patch)
  39. #define MICROPY_VERSION MICROPY_MAKE_VERSION(MICROPY_VERSION_MAJOR, MICROPY_VERSION_MINOR, MICROPY_VERSION_MICRO)
  40. // String version. This is only used directly for platform.platform and
  41. // os.uname().release. All other version info available in the firmware (e.g.
  42. // the REPL banner) comes from MICROPY_GIT_TAG.
  43. #define MICROPY_VERSION_STRING_BASE \
  44. MP_STRINGIFY(MICROPY_VERSION_MAJOR) "." \
  45. MP_STRINGIFY(MICROPY_VERSION_MINOR) "." \
  46. MP_STRINGIFY(MICROPY_VERSION_MICRO)
  47. #if MICROPY_VERSION_PRERELEASE
  48. #define MICROPY_VERSION_STRING MICROPY_VERSION_STRING_BASE "-preview"
  49. #else
  50. #define MICROPY_VERSION_STRING MICROPY_VERSION_STRING_BASE
  51. #endif
  52. // If this is enabled, then in-progress/breaking changes slated for the 2.x
  53. // release will be enabled.
  54. #ifndef MICROPY_PREVIEW_VERSION_2
  55. #define MICROPY_PREVIEW_VERSION_2 (0)
  56. #endif
  57. // This file contains default configuration settings for MicroPython.
  58. // You can override any of the options below using mpconfigport.h file
  59. // located in a directory of your port.
  60. // mpconfigport.h is a file containing configuration settings for a
  61. // particular port. mpconfigport.h is actually a default name for
  62. // such config, and it can be overridden using MP_CONFIGFILE preprocessor
  63. // define (you can do that by passing CFLAGS_EXTRA='-DMP_CONFIGFILE="<file.h>"'
  64. // argument to make when using standard MicroPython makefiles).
  65. // This is useful to have more than one config per port, for example,
  66. // release vs debug configs, etc. Note that if you switch from one config
  67. // to another, you must rebuild from scratch using "-B" switch to make.
  68. // Disable all optional features (i.e. minimal port).
  69. #define MICROPY_CONFIG_ROM_LEVEL_MINIMUM (0)
  70. // Only enable core features (constrained flash, e.g. STM32L072)
  71. #define MICROPY_CONFIG_ROM_LEVEL_CORE_FEATURES (10)
  72. // Enable most common features (small on-device flash, e.g. STM32F411)
  73. #define MICROPY_CONFIG_ROM_LEVEL_BASIC_FEATURES (20)
  74. // Enable convenience features (medium on-device flash, e.g. STM32F405)
  75. #define MICROPY_CONFIG_ROM_LEVEL_EXTRA_FEATURES (30)
  76. // Enable all common features (large/external flash, rp2, unix)
  77. #define MICROPY_CONFIG_ROM_LEVEL_FULL_FEATURES (40)
  78. // Enable everything (e.g. coverage)
  79. #define MICROPY_CONFIG_ROM_LEVEL_EVERYTHING (50)
  80. #ifdef MP_CONFIGFILE
  81. #include MP_CONFIGFILE
  82. #else
  83. #include <mpconfigport.h>
  84. #endif
  85. // Ports/boards should set this, but default to level=core.
  86. #ifndef MICROPY_CONFIG_ROM_LEVEL
  87. #define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_CORE_FEATURES)
  88. #endif
  89. // Helper macros for "have at least this level".
  90. #define MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES (MICROPY_CONFIG_ROM_LEVEL >= MICROPY_CONFIG_ROM_LEVEL_CORE_FEATURES)
  91. #define MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_BASIC_FEATURES (MICROPY_CONFIG_ROM_LEVEL >= MICROPY_CONFIG_ROM_LEVEL_BASIC_FEATURES)
  92. #define MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES (MICROPY_CONFIG_ROM_LEVEL >= MICROPY_CONFIG_ROM_LEVEL_EXTRA_FEATURES)
  93. #define MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_FULL_FEATURES (MICROPY_CONFIG_ROM_LEVEL >= MICROPY_CONFIG_ROM_LEVEL_FULL_FEATURES)
  94. #define MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING (MICROPY_CONFIG_ROM_LEVEL >= MICROPY_CONFIG_ROM_LEVEL_EVERYTHING)
  95. // Any options not explicitly set in mpconfigport.h will get default
  96. // values below.
  97. /*****************************************************************************/
  98. /* Object representation */
  99. // A MicroPython object is a machine word having the following form:
  100. // - xxxx...xxx1 : a small int, bits 1 and above are the value
  101. // - xxxx...x010 : a qstr, bits 3 and above are the value
  102. // - xxxx...x110 : an immediate object, bits 3 and above are the value
  103. // - xxxx...xx00 : a pointer to an mp_obj_base_t (unless a fake object)
  104. #define MICROPY_OBJ_REPR_A (0)
  105. // A MicroPython object is a machine word having the following form:
  106. // - xxxx...xx01 : a small int, bits 2 and above are the value
  107. // - xxxx...x011 : a qstr, bits 3 and above are the value
  108. // - xxxx...x111 : an immediate object, bits 3 and above are the value
  109. // - xxxx...xxx0 : a pointer to an mp_obj_base_t (unless a fake object)
  110. #define MICROPY_OBJ_REPR_B (1)
  111. // A MicroPython object is a machine word having the following form (called R):
  112. // - iiiiiiii iiiiiiii iiiiiiii iiiiiii1 small int with 31-bit signed value
  113. // - 01111111 1qqqqqqq qqqqqqqq qqqq0110 str with 19-bit qstr value
  114. // - 01111111 10000000 00000000 ssss1110 immediate object with 4-bit value
  115. // - s1111111 10000000 00000000 00000010 +/- inf
  116. // - s1111111 1xxxxxxx xxxxxxxx xxxxx010 nan, x != 0
  117. // - seeeeeee efffffff ffffffff ffffff10 30-bit fp, e != 0xff
  118. // - pppppppp pppppppp pppppppp pppppp00 ptr (4 byte alignment)
  119. // Str, immediate and float stored as O = R + 0x80800000, retrieved as R = O - 0x80800000.
  120. // This makes strs/immediates easier to encode/decode as they have zeros in the top 9 bits.
  121. // This scheme only works with 32-bit word size and float enabled.
  122. #define MICROPY_OBJ_REPR_C (2)
  123. // A MicroPython object is a 64-bit word having the following form (called R):
  124. // - seeeeeee eeeeffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff 64-bit fp, e != 0x7ff
  125. // - s1111111 11110000 00000000 00000000 00000000 00000000 00000000 00000000 +/- inf
  126. // - 01111111 11111000 00000000 00000000 00000000 00000000 00000000 00000000 normalised nan
  127. // - 01111111 11111101 iiiiiiii iiiiiiii iiiiiiii iiiiiiii iiiiiiii iiiiiii1 small int
  128. // - 01111111 11111110 00000000 00000000 qqqqqqqq qqqqqqqq qqqqqqqq qqqqqqq1 str
  129. // - 01111111 11111111 ss000000 00000000 00000000 00000000 00000000 00000000 immediate object
  130. // - 01111111 11111100 00000000 00000000 pppppppp pppppppp pppppppp pppppp00 ptr (4 byte alignment)
  131. // Stored as O = R + 0x8004000000000000, retrieved as R = O - 0x8004000000000000.
  132. // This makes pointers have all zeros in the top 32 bits.
  133. // Small-ints and strs have 1 as LSB to make sure they don't look like pointers
  134. // to the garbage collector.
  135. #define MICROPY_OBJ_REPR_D (3)
  136. #ifndef MICROPY_OBJ_REPR
  137. #define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_A)
  138. #endif
  139. // Whether to encode None/False/True as immediate objects instead of pointers to
  140. // real objects. Reduces code size by a decent amount without hurting
  141. // performance, for all representations except D on some architectures.
  142. #ifndef MICROPY_OBJ_IMMEDIATE_OBJS
  143. #define MICROPY_OBJ_IMMEDIATE_OBJS (MICROPY_OBJ_REPR != MICROPY_OBJ_REPR_D)
  144. #endif
  145. /*****************************************************************************/
  146. /* Memory allocation policy */
  147. // Number of bytes in memory allocation/GC block. Any size allocated will be
  148. // rounded up to be multiples of this.
  149. #ifndef MICROPY_BYTES_PER_GC_BLOCK
  150. #define MICROPY_BYTES_PER_GC_BLOCK (4 * MP_BYTES_PER_OBJ_WORD)
  151. #endif
  152. // Number of words allocated (in BSS) to the GC stack (minimum is 1)
  153. #ifndef MICROPY_ALLOC_GC_STACK_SIZE
  154. #define MICROPY_ALLOC_GC_STACK_SIZE (64)
  155. #endif
  156. // The C-type to use for entries in the GC stack. By default it allows the
  157. // heap to be as large as the address space, but the bit-width of this type can
  158. // be reduced to save memory when the heap is small enough. The type must be
  159. // big enough to index all blocks in the heap, which is set by
  160. // heap-size-in-bytes / MICROPY_BYTES_PER_GC_BLOCK.
  161. #ifndef MICROPY_GC_STACK_ENTRY_TYPE
  162. #define MICROPY_GC_STACK_ENTRY_TYPE size_t
  163. #endif
  164. // Be conservative and always clear to zero newly (re)allocated memory in the GC.
  165. // This helps eliminate stray pointers that hold on to memory that's no longer
  166. // used. It decreases performance due to unnecessary memory clearing.
  167. // A memory manager which always clears memory can set this to 0.
  168. // TODO Do analysis to understand why some memory is not properly cleared and
  169. // find a more efficient way to clear it.
  170. #ifndef MICROPY_GC_CONSERVATIVE_CLEAR
  171. #define MICROPY_GC_CONSERVATIVE_CLEAR (MICROPY_ENABLE_GC)
  172. #endif
  173. // Support automatic GC when reaching allocation threshold,
  174. // configurable by gc.threshold().
  175. #ifndef MICROPY_GC_ALLOC_THRESHOLD
  176. #define MICROPY_GC_ALLOC_THRESHOLD (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  177. #endif
  178. // Number of bytes to allocate initially when creating new chunks to store
  179. // interned string data. Smaller numbers lead to more chunks being needed
  180. // and more wastage at the end of the chunk. Larger numbers lead to wasted
  181. // space at the end when no more strings need interning.
  182. #ifndef MICROPY_ALLOC_QSTR_CHUNK_INIT
  183. #define MICROPY_ALLOC_QSTR_CHUNK_INIT (128)
  184. #endif
  185. // Initial amount for lexer indentation level
  186. #ifndef MICROPY_ALLOC_LEXER_INDENT_INIT
  187. #define MICROPY_ALLOC_LEXER_INDENT_INIT (10)
  188. #endif
  189. // Increment for lexer indentation level
  190. #ifndef MICROPY_ALLOC_LEXEL_INDENT_INC
  191. #define MICROPY_ALLOC_LEXEL_INDENT_INC (8)
  192. #endif
  193. // Initial amount for parse rule stack
  194. #ifndef MICROPY_ALLOC_PARSE_RULE_INIT
  195. #define MICROPY_ALLOC_PARSE_RULE_INIT (64)
  196. #endif
  197. // Increment for parse rule stack
  198. #ifndef MICROPY_ALLOC_PARSE_RULE_INC
  199. #define MICROPY_ALLOC_PARSE_RULE_INC (16)
  200. #endif
  201. // Initial amount for parse result stack
  202. #ifndef MICROPY_ALLOC_PARSE_RESULT_INIT
  203. #define MICROPY_ALLOC_PARSE_RESULT_INIT (32)
  204. #endif
  205. // Increment for parse result stack
  206. #ifndef MICROPY_ALLOC_PARSE_RESULT_INC
  207. #define MICROPY_ALLOC_PARSE_RESULT_INC (16)
  208. #endif
  209. // Strings this length or less will be interned by the parser
  210. #ifndef MICROPY_ALLOC_PARSE_INTERN_STRING_LEN
  211. #define MICROPY_ALLOC_PARSE_INTERN_STRING_LEN (10)
  212. #endif
  213. // Number of bytes to allocate initially when creating new chunks to store
  214. // parse nodes. Small leads to fragmentation, large leads to excess use.
  215. #ifndef MICROPY_ALLOC_PARSE_CHUNK_INIT
  216. #define MICROPY_ALLOC_PARSE_CHUNK_INIT (128)
  217. #endif
  218. // Initial amount for ids in a scope
  219. #ifndef MICROPY_ALLOC_SCOPE_ID_INIT
  220. #define MICROPY_ALLOC_SCOPE_ID_INIT (4)
  221. #endif
  222. // Increment for ids in a scope
  223. #ifndef MICROPY_ALLOC_SCOPE_ID_INC
  224. #define MICROPY_ALLOC_SCOPE_ID_INC (6)
  225. #endif
  226. // Maximum length of a path in the filesystem
  227. // So we can allocate a buffer on the stack for path manipulation in import
  228. #ifndef MICROPY_ALLOC_PATH_MAX
  229. #define MICROPY_ALLOC_PATH_MAX (512)
  230. #endif
  231. // Initial size of module dict
  232. #ifndef MICROPY_MODULE_DICT_SIZE
  233. #define MICROPY_MODULE_DICT_SIZE (1)
  234. #endif
  235. // Initial size of sys.modules dict
  236. #ifndef MICROPY_LOADED_MODULES_DICT_SIZE
  237. #define MICROPY_LOADED_MODULES_DICT_SIZE (3)
  238. #endif
  239. // Whether realloc/free should be passed allocated memory region size
  240. // You must enable this if MICROPY_MEM_STATS is enabled
  241. #ifndef MICROPY_MALLOC_USES_ALLOCATED_SIZE
  242. #define MICROPY_MALLOC_USES_ALLOCATED_SIZE (0)
  243. #endif
  244. // Number of bytes used to store qstr length
  245. // Dictates hard limit on maximum Python identifier length, but 1 byte
  246. // (limit of 255 bytes in an identifier) should be enough for everyone
  247. #ifndef MICROPY_QSTR_BYTES_IN_LEN
  248. #define MICROPY_QSTR_BYTES_IN_LEN (1)
  249. #endif
  250. // Number of bytes used to store qstr hash
  251. #ifndef MICROPY_QSTR_BYTES_IN_HASH
  252. #if MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES
  253. #define MICROPY_QSTR_BYTES_IN_HASH (2)
  254. #else
  255. #define MICROPY_QSTR_BYTES_IN_HASH (1)
  256. #endif
  257. #endif
  258. // Avoid using C stack when making Python function calls. C stack still
  259. // may be used if there's no free heap.
  260. #ifndef MICROPY_STACKLESS
  261. #define MICROPY_STACKLESS (0)
  262. #endif
  263. // Never use C stack when making Python function calls. This may break
  264. // testsuite as will subtly change which exception is thrown in case
  265. // of too deep recursion and other similar cases.
  266. #ifndef MICROPY_STACKLESS_STRICT
  267. #define MICROPY_STACKLESS_STRICT (0)
  268. #endif
  269. // Don't use alloca calls. As alloca() is not part of ANSI C, this
  270. // workaround option is provided for compilers lacking this de-facto
  271. // standard function. The way it works is allocating from heap, and
  272. // relying on garbage collection to free it eventually. This is of
  273. // course much less optimal than real alloca().
  274. #if defined(MICROPY_NO_ALLOCA) && MICROPY_NO_ALLOCA
  275. #undef alloca
  276. #define alloca(x) m_malloc(x)
  277. #endif
  278. /*****************************************************************************/
  279. /* MicroPython emitters */
  280. // Whether to support loading of persistent code
  281. #ifndef MICROPY_PERSISTENT_CODE_LOAD
  282. #define MICROPY_PERSISTENT_CODE_LOAD (0)
  283. #endif
  284. // Whether to support saving of persistent code, i.e. for mpy-cross to
  285. // generate .mpy files. Enabling this enables additional metadata on raw code
  286. // objects which is also required for sys.settrace.
  287. #ifndef MICROPY_PERSISTENT_CODE_SAVE
  288. #define MICROPY_PERSISTENT_CODE_SAVE (MICROPY_PY_SYS_SETTRACE)
  289. #endif
  290. // Whether to support saving persistent code to a file via mp_raw_code_save_file
  291. #ifndef MICROPY_PERSISTENT_CODE_SAVE_FILE
  292. #define MICROPY_PERSISTENT_CODE_SAVE_FILE (0)
  293. #endif
  294. // Whether generated code can persist independently of the VM/runtime instance
  295. // This is enabled automatically when needed by other features
  296. #ifndef MICROPY_PERSISTENT_CODE
  297. #define MICROPY_PERSISTENT_CODE (MICROPY_PERSISTENT_CODE_LOAD || MICROPY_PERSISTENT_CODE_SAVE || MICROPY_MODULE_FROZEN_MPY)
  298. #endif
  299. // Whether bytecode uses a qstr_table to map internal qstr indices in the bytecode
  300. // to global qstr values in the runtime (behaviour when feature is enabled), or
  301. // just stores global qstr values directly in the bytecode. This must be enabled
  302. // if MICROPY_PERSISTENT_CODE is enabled.
  303. #ifndef MICROPY_EMIT_BYTECODE_USES_QSTR_TABLE
  304. #define MICROPY_EMIT_BYTECODE_USES_QSTR_TABLE (MICROPY_PERSISTENT_CODE)
  305. #endif
  306. // Whether to emit x64 native code
  307. #ifndef MICROPY_EMIT_X64
  308. #define MICROPY_EMIT_X64 (0)
  309. #endif
  310. // Whether to emit x86 native code
  311. #ifndef MICROPY_EMIT_X86
  312. #define MICROPY_EMIT_X86 (0)
  313. #endif
  314. // Whether to emit thumb native code
  315. #ifndef MICROPY_EMIT_THUMB
  316. #define MICROPY_EMIT_THUMB (0)
  317. #endif
  318. // Whether to emit ARMv7-M instruction support in thumb native code
  319. #ifndef MICROPY_EMIT_THUMB_ARMV7M
  320. #define MICROPY_EMIT_THUMB_ARMV7M (1)
  321. #endif
  322. // Whether to enable the thumb inline assembler
  323. #ifndef MICROPY_EMIT_INLINE_THUMB
  324. #define MICROPY_EMIT_INLINE_THUMB (0)
  325. #endif
  326. // Whether to enable float support in the Thumb2 inline assembler
  327. #ifndef MICROPY_EMIT_INLINE_THUMB_FLOAT
  328. #define MICROPY_EMIT_INLINE_THUMB_FLOAT (1)
  329. #endif
  330. // Whether to emit ARM native code
  331. #ifndef MICROPY_EMIT_ARM
  332. #define MICROPY_EMIT_ARM (0)
  333. #endif
  334. // Whether to emit Xtensa native code
  335. #ifndef MICROPY_EMIT_XTENSA
  336. #define MICROPY_EMIT_XTENSA (0)
  337. #endif
  338. // Whether to enable the Xtensa inline assembler
  339. #ifndef MICROPY_EMIT_INLINE_XTENSA
  340. #define MICROPY_EMIT_INLINE_XTENSA (0)
  341. #endif
  342. // Whether to emit Xtensa-Windowed native code
  343. #ifndef MICROPY_EMIT_XTENSAWIN
  344. #define MICROPY_EMIT_XTENSAWIN (0)
  345. #endif
  346. // Convenience definition for whether any native emitter is enabled
  347. #define MICROPY_EMIT_NATIVE (MICROPY_EMIT_X64 || MICROPY_EMIT_X86 || MICROPY_EMIT_THUMB || MICROPY_EMIT_ARM || MICROPY_EMIT_XTENSA || MICROPY_EMIT_XTENSAWIN)
  348. // Some architectures cannot read byte-wise from executable memory. In this case
  349. // the prelude for a native function (which usually sits after the machine code)
  350. // must be separated and placed somewhere where it can be read byte-wise.
  351. #define MICROPY_EMIT_NATIVE_PRELUDE_SEPARATE_FROM_MACHINE_CODE (MICROPY_EMIT_XTENSAWIN)
  352. // Convenience definition for whether any inline assembler emitter is enabled
  353. #define MICROPY_EMIT_INLINE_ASM (MICROPY_EMIT_INLINE_THUMB || MICROPY_EMIT_INLINE_XTENSA)
  354. // Convenience definition for whether any native or inline assembler emitter is enabled
  355. #define MICROPY_EMIT_MACHINE_CODE (MICROPY_EMIT_NATIVE || MICROPY_EMIT_INLINE_ASM)
  356. // Whether native relocatable code loaded from .mpy files is explicitly tracked
  357. // so that the GC cannot reclaim it. Needed on architectures that allocate
  358. // executable memory on the MicroPython heap and don't explicitly track this
  359. // data some other way.
  360. #ifndef MICROPY_PERSISTENT_CODE_TRACK_RELOC_CODE
  361. #if !MICROPY_EMIT_MACHINE_CODE || defined(MP_PLAT_ALLOC_EXEC) || defined(MP_PLAT_COMMIT_EXEC)
  362. #define MICROPY_PERSISTENT_CODE_TRACK_RELOC_CODE (0)
  363. #else
  364. #define MICROPY_PERSISTENT_CODE_TRACK_RELOC_CODE (1)
  365. #endif
  366. #endif
  367. /*****************************************************************************/
  368. /* Compiler configuration */
  369. // Whether to include the compiler
  370. #ifndef MICROPY_ENABLE_COMPILER
  371. #define MICROPY_ENABLE_COMPILER (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  372. #endif
  373. // Whether the compiler is dynamically configurable (ie at runtime)
  374. // This will disable the ability to execute native/viper code
  375. #ifndef MICROPY_DYNAMIC_COMPILER
  376. #define MICROPY_DYNAMIC_COMPILER (0)
  377. #endif
  378. // Whether to enable constant folding; eg 1+2 rewritten as 3
  379. #ifndef MICROPY_COMP_CONST_FOLDING
  380. #define MICROPY_COMP_CONST_FOLDING (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  381. #endif
  382. // Whether to compile constant tuples immediately to their respective objects; eg (1, True)
  383. // Otherwise the tuple will be built at runtime
  384. #ifndef MICROPY_COMP_CONST_TUPLE
  385. #define MICROPY_COMP_CONST_TUPLE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  386. #endif
  387. // Whether to enable optimisations for constant literals, eg OrderedDict
  388. #ifndef MICROPY_COMP_CONST_LITERAL
  389. #define MICROPY_COMP_CONST_LITERAL (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  390. #endif
  391. // Whether to enable lookup of constants in modules; eg module.CONST
  392. #ifndef MICROPY_COMP_MODULE_CONST
  393. #define MICROPY_COMP_MODULE_CONST (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  394. #endif
  395. // Whether to enable constant optimisation; id = const(value)
  396. #ifndef MICROPY_COMP_CONST
  397. #define MICROPY_COMP_CONST (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  398. #endif
  399. // Whether to enable optimisation of: a, b = c, d
  400. // Costs 124 bytes (Thumb2)
  401. #ifndef MICROPY_COMP_DOUBLE_TUPLE_ASSIGN
  402. #define MICROPY_COMP_DOUBLE_TUPLE_ASSIGN (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  403. #endif
  404. // Whether to enable optimisation of: a, b, c = d, e, f
  405. // Requires MICROPY_COMP_DOUBLE_TUPLE_ASSIGN and costs 68 bytes (Thumb2)
  406. #ifndef MICROPY_COMP_TRIPLE_TUPLE_ASSIGN
  407. #define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  408. #endif
  409. // Whether to enable optimisation of: return a if b else c
  410. // Costs about 80 bytes (Thumb2) and saves 2 bytes of bytecode for each use
  411. #ifndef MICROPY_COMP_RETURN_IF_EXPR
  412. #define MICROPY_COMP_RETURN_IF_EXPR (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  413. #endif
  414. /*****************************************************************************/
  415. /* Internal debugging stuff */
  416. // Whether to collect memory allocation stats
  417. #ifndef MICROPY_MEM_STATS
  418. #define MICROPY_MEM_STATS (0)
  419. #endif
  420. // The mp_print_t printer used for debugging output
  421. #ifndef MICROPY_DEBUG_PRINTER
  422. #define MICROPY_DEBUG_PRINTER (&mp_plat_print)
  423. #endif
  424. // Whether to build functions that print debugging info:
  425. // mp_bytecode_print
  426. // mp_parse_node_print
  427. #ifndef MICROPY_DEBUG_PRINTERS
  428. #define MICROPY_DEBUG_PRINTERS (0)
  429. #endif
  430. // Whether to enable all debugging outputs (it will be extremely verbose)
  431. #ifndef MICROPY_DEBUG_VERBOSE
  432. #define MICROPY_DEBUG_VERBOSE (0)
  433. #endif
  434. // Whether to enable debugging versions of MP_OBJ_NULL/STOP_ITERATION/SENTINEL
  435. #ifndef MICROPY_DEBUG_MP_OBJ_SENTINELS
  436. #define MICROPY_DEBUG_MP_OBJ_SENTINELS (0)
  437. #endif
  438. // Whether to print parse rule names (rather than integers) in mp_parse_node_print
  439. #ifndef MICROPY_DEBUG_PARSE_RULE_NAME
  440. #define MICROPY_DEBUG_PARSE_RULE_NAME (0)
  441. #endif
  442. // Whether to enable a simple VM stack overflow check
  443. #ifndef MICROPY_DEBUG_VM_STACK_OVERFLOW
  444. #define MICROPY_DEBUG_VM_STACK_OVERFLOW (0)
  445. #endif
  446. // Whether to enable extra instrumentation for valgrind
  447. #ifndef MICROPY_DEBUG_VALGRIND
  448. #define MICROPY_DEBUG_VALGRIND (0)
  449. #endif
  450. /*****************************************************************************/
  451. /* Optimisations */
  452. // Whether to use computed gotos in the VM, or a switch
  453. // Computed gotos are roughly 10% faster, and increase VM code size by a little,
  454. // e.g. ~1kiB on Cortex M4.
  455. // Note: enabling this will use the gcc-specific extensions of ranged designated
  456. // initialisers and addresses of labels, which are not part of the C99 standard.
  457. #ifndef MICROPY_OPT_COMPUTED_GOTO
  458. #define MICROPY_OPT_COMPUTED_GOTO (0)
  459. #endif
  460. // Optimise the fast path for loading attributes from instance types. Increases
  461. // Thumb2 code size by about 48 bytes.
  462. #ifndef MICROPY_OPT_LOAD_ATTR_FAST_PATH
  463. #define MICROPY_OPT_LOAD_ATTR_FAST_PATH (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  464. #endif
  465. // Use extra RAM to cache map lookups by remembering the likely location of
  466. // the index. Avoids the hash computation on unordered maps, and avoids the
  467. // linear search on ordered (especially in-ROM) maps. Can provide a +10-15%
  468. // performance improvement on benchmarks involving lots of attribute access
  469. // or dictionary lookup.
  470. #ifndef MICROPY_OPT_MAP_LOOKUP_CACHE
  471. #define MICROPY_OPT_MAP_LOOKUP_CACHE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  472. #endif
  473. // How much RAM (in bytes) to use for the map lookup cache.
  474. #ifndef MICROPY_OPT_MAP_LOOKUP_CACHE_SIZE
  475. #define MICROPY_OPT_MAP_LOOKUP_CACHE_SIZE (128)
  476. #endif
  477. // Whether to use fast versions of bitwise operations (and, or, xor) when the
  478. // arguments are both positive. Increases Thumb2 code size by about 250 bytes.
  479. #ifndef MICROPY_OPT_MPZ_BITWISE
  480. #define MICROPY_OPT_MPZ_BITWISE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  481. #endif
  482. // Whether math.factorial is large, fast and recursive (1) or small and slow (0).
  483. #ifndef MICROPY_OPT_MATH_FACTORIAL
  484. #define MICROPY_OPT_MATH_FACTORIAL (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  485. #endif
  486. /*****************************************************************************/
  487. /* Python internal features */
  488. // Whether to enable import of external modules
  489. // When disabled, only importing of built-in modules is supported
  490. // When enabled, a port must implement mp_import_stat (among other things)
  491. #ifndef MICROPY_ENABLE_EXTERNAL_IMPORT
  492. #define MICROPY_ENABLE_EXTERNAL_IMPORT (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  493. #endif
  494. // Whether to use the POSIX reader for importing files
  495. #ifndef MICROPY_READER_POSIX
  496. #define MICROPY_READER_POSIX (0)
  497. #endif
  498. // Whether to use the VFS reader for importing files
  499. #ifndef MICROPY_READER_VFS
  500. #define MICROPY_READER_VFS (0)
  501. #endif
  502. // Whether any readers have been defined
  503. #ifndef MICROPY_HAS_FILE_READER
  504. #define MICROPY_HAS_FILE_READER (MICROPY_READER_POSIX || MICROPY_READER_VFS)
  505. #endif
  506. // Hook for the VM at the start of the opcode loop (can contain variable
  507. // definitions usable by the other hook functions)
  508. #ifndef MICROPY_VM_HOOK_INIT
  509. #define MICROPY_VM_HOOK_INIT
  510. #endif
  511. // Hook for the VM during the opcode loop (but only after jump opcodes)
  512. #ifndef MICROPY_VM_HOOK_LOOP
  513. #define MICROPY_VM_HOOK_LOOP
  514. #endif
  515. // Hook for the VM just before return opcode is finished being interpreted
  516. #ifndef MICROPY_VM_HOOK_RETURN
  517. #define MICROPY_VM_HOOK_RETURN
  518. #endif
  519. // Hook for mp_sched_schedule when a function gets scheduled on sched_queue
  520. // (this macro executes within an atomic section)
  521. #ifndef MICROPY_SCHED_HOOK_SCHEDULED
  522. #define MICROPY_SCHED_HOOK_SCHEDULED
  523. #endif
  524. // Whether to include the garbage collector
  525. #ifndef MICROPY_ENABLE_GC
  526. #define MICROPY_ENABLE_GC (0)
  527. #endif
  528. // Whether the garbage-collected heap can be split over multiple memory areas.
  529. #ifndef MICROPY_GC_SPLIT_HEAP
  530. #define MICROPY_GC_SPLIT_HEAP (0)
  531. #endif
  532. // Whether regions should be added/removed from the split heap as needed.
  533. #ifndef MICROPY_GC_SPLIT_HEAP_AUTO
  534. #define MICROPY_GC_SPLIT_HEAP_AUTO (0)
  535. #endif
  536. // Hook to run code during time consuming garbage collector operations
  537. // *i* is the loop index variable (e.g. can be used to run every x loops)
  538. #ifndef MICROPY_GC_HOOK_LOOP
  539. #define MICROPY_GC_HOOK_LOOP(i)
  540. #endif
  541. // Whether to provide m_tracked_calloc, m_tracked_free functions
  542. #ifndef MICROPY_TRACKED_ALLOC
  543. #define MICROPY_TRACKED_ALLOC (0)
  544. #endif
  545. // Whether to enable finalisers in the garbage collector (ie call __del__)
  546. #ifndef MICROPY_ENABLE_FINALISER
  547. #define MICROPY_ENABLE_FINALISER (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  548. #endif
  549. // Whether to enable a separate allocator for the Python stack.
  550. // If enabled then the code must call mp_pystack_init before mp_init.
  551. #ifndef MICROPY_ENABLE_PYSTACK
  552. #define MICROPY_ENABLE_PYSTACK (0)
  553. #endif
  554. // Number of bytes that memory returned by mp_pystack_alloc will be aligned by.
  555. #ifndef MICROPY_PYSTACK_ALIGN
  556. #define MICROPY_PYSTACK_ALIGN (8)
  557. #endif
  558. // Whether to check C stack usage. C stack used for calling Python functions,
  559. // etc. Not checking means segfault on overflow.
  560. #ifndef MICROPY_STACK_CHECK
  561. #define MICROPY_STACK_CHECK (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  562. #endif
  563. // Whether to have an emergency exception buffer
  564. #ifndef MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
  565. #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (0)
  566. #endif
  567. #if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
  568. #ifndef MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE
  569. #define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (0) // 0 - implies dynamic allocation
  570. #endif
  571. #endif
  572. // Whether to provide the mp_kbd_exception object, and micropython.kbd_intr function
  573. #ifndef MICROPY_KBD_EXCEPTION
  574. #define MICROPY_KBD_EXCEPTION (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  575. #endif
  576. // Prefer to raise KeyboardInterrupt asynchronously (from signal or interrupt
  577. // handler) - if supported by a particular port.
  578. #ifndef MICROPY_ASYNC_KBD_INTR
  579. #define MICROPY_ASYNC_KBD_INTR (0)
  580. #endif
  581. // Whether to include REPL helper function
  582. #ifndef MICROPY_HELPER_REPL
  583. #define MICROPY_HELPER_REPL (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  584. #endif
  585. // Allow enabling debug prints after each REPL line
  586. #ifndef MICROPY_REPL_INFO
  587. #define MICROPY_REPL_INFO (0)
  588. #endif
  589. // Whether to include emacs-style readline behavior in REPL
  590. #ifndef MICROPY_REPL_EMACS_KEYS
  591. #define MICROPY_REPL_EMACS_KEYS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  592. #endif
  593. // Whether to include emacs-style word movement/kill readline behavior in REPL.
  594. // This adds Alt+F, Alt+B, Alt+D and Alt+Backspace for forward-word, backward-word, forward-kill-word
  595. // and backward-kill-word, respectively.
  596. #ifndef MICROPY_REPL_EMACS_WORDS_MOVE
  597. #define MICROPY_REPL_EMACS_WORDS_MOVE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING)
  598. #endif
  599. // Whether to include extra convenience keys for word movement/kill in readline REPL.
  600. // This adds Ctrl+Right, Ctrl+Left and Ctrl+W for forward-word, backward-word and backward-kill-word
  601. // respectively. Ctrl+Delete is not implemented because it's a very different escape sequence.
  602. // Depends on MICROPY_REPL_EMACS_WORDS_MOVE.
  603. #ifndef MICROPY_REPL_EMACS_EXTRA_WORDS_MOVE
  604. #define MICROPY_REPL_EMACS_EXTRA_WORDS_MOVE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING)
  605. #endif
  606. // Whether to implement auto-indent in REPL
  607. #ifndef MICROPY_REPL_AUTO_INDENT
  608. #define MICROPY_REPL_AUTO_INDENT (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  609. #endif
  610. // Whether port requires event-driven REPL functions
  611. #ifndef MICROPY_REPL_EVENT_DRIVEN
  612. #define MICROPY_REPL_EVENT_DRIVEN (0)
  613. #endif
  614. // The number of items to keep in the readline history.
  615. #ifndef MICROPY_READLINE_HISTORY_SIZE
  616. #define MICROPY_READLINE_HISTORY_SIZE (8)
  617. #endif
  618. // Whether to include lexer helper function for unix
  619. #ifndef MICROPY_HELPER_LEXER_UNIX
  620. #define MICROPY_HELPER_LEXER_UNIX (0)
  621. #endif
  622. // Long int implementation
  623. #define MICROPY_LONGINT_IMPL_NONE (0)
  624. #define MICROPY_LONGINT_IMPL_LONGLONG (1)
  625. #define MICROPY_LONGINT_IMPL_MPZ (2)
  626. #ifndef MICROPY_LONGINT_IMPL
  627. #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_NONE)
  628. #endif
  629. #if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG
  630. typedef long long mp_longint_impl_t;
  631. #endif
  632. // Whether to include information in the byte code to determine source
  633. // line number (increases RAM usage, but doesn't slow byte code execution)
  634. #ifndef MICROPY_ENABLE_SOURCE_LINE
  635. #define MICROPY_ENABLE_SOURCE_LINE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  636. #endif
  637. // Whether to include doc strings (increases RAM usage)
  638. #ifndef MICROPY_ENABLE_DOC_STRING
  639. #define MICROPY_ENABLE_DOC_STRING (0)
  640. #endif
  641. // Exception messages are removed (requires disabling MICROPY_ROM_TEXT_COMPRESSION)
  642. #define MICROPY_ERROR_REPORTING_NONE (0)
  643. // Exception messages are short static strings
  644. #define MICROPY_ERROR_REPORTING_TERSE (1)
  645. // Exception messages provide basic error details
  646. #define MICROPY_ERROR_REPORTING_NORMAL (2)
  647. // Exception messages provide full info, e.g. object names
  648. #define MICROPY_ERROR_REPORTING_DETAILED (3)
  649. #ifndef MICROPY_ERROR_REPORTING
  650. #if MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_FULL_FEATURES
  651. #define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_DETAILED)
  652. #elif MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES
  653. #define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_NORMAL)
  654. #else
  655. #define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_TERSE)
  656. #endif
  657. #endif
  658. // Whether issue warnings during compiling/execution
  659. #ifndef MICROPY_WARNINGS
  660. #define MICROPY_WARNINGS (0)
  661. #endif
  662. // Whether to support warning categories
  663. #ifndef MICROPY_WARNINGS_CATEGORY
  664. #define MICROPY_WARNINGS_CATEGORY (0)
  665. #endif
  666. // This macro is used when printing runtime warnings and errors
  667. #ifndef MICROPY_ERROR_PRINTER
  668. #define MICROPY_ERROR_PRINTER (&mp_plat_print)
  669. #endif
  670. // Float and complex implementation
  671. #define MICROPY_FLOAT_IMPL_NONE (0)
  672. #define MICROPY_FLOAT_IMPL_FLOAT (1)
  673. #define MICROPY_FLOAT_IMPL_DOUBLE (2)
  674. #ifndef MICROPY_FLOAT_IMPL
  675. #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_NONE)
  676. #endif
  677. #if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
  678. #define MICROPY_PY_BUILTINS_FLOAT (1)
  679. #define MICROPY_FLOAT_CONST(x) x##F
  680. #define MICROPY_FLOAT_C_FUN(fun) fun##f
  681. typedef float mp_float_t;
  682. #elif MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE
  683. #define MICROPY_PY_BUILTINS_FLOAT (1)
  684. #define MICROPY_FLOAT_CONST(x) x
  685. #define MICROPY_FLOAT_C_FUN(fun) fun
  686. typedef double mp_float_t;
  687. #else
  688. #define MICROPY_PY_BUILTINS_FLOAT (0)
  689. #endif
  690. #ifndef MICROPY_PY_BUILTINS_COMPLEX
  691. #define MICROPY_PY_BUILTINS_COMPLEX (MICROPY_PY_BUILTINS_FLOAT)
  692. #endif
  693. // Whether to provide a high-quality hash for float and complex numbers.
  694. // Otherwise the default is a very simple but correct hashing function.
  695. #ifndef MICROPY_FLOAT_HIGH_QUALITY_HASH
  696. #define MICROPY_FLOAT_HIGH_QUALITY_HASH (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING)
  697. #endif
  698. // Enable features which improve CPython compatibility
  699. // but may lead to more code size/memory usage.
  700. // TODO: Originally intended as generic category to not
  701. // add bunch of once-off options. May need refactoring later
  702. #ifndef MICROPY_CPYTHON_COMPAT
  703. #define MICROPY_CPYTHON_COMPAT (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  704. #endif
  705. // Perform full checks as done by CPython. Disabling this
  706. // may produce incorrect results, if incorrect data is fed,
  707. // but should not lead to MicroPython crashes or similar
  708. // grave issues (in other words, only user app should be,
  709. // affected, not system).
  710. #ifndef MICROPY_FULL_CHECKS
  711. #define MICROPY_FULL_CHECKS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  712. #endif
  713. // Whether POSIX-semantics non-blocking streams are supported
  714. #ifndef MICROPY_STREAMS_NON_BLOCK
  715. #define MICROPY_STREAMS_NON_BLOCK (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  716. #endif
  717. // Whether to provide stream functions with POSIX-like signatures
  718. // (useful for porting existing libraries to MicroPython).
  719. #ifndef MICROPY_STREAMS_POSIX_API
  720. #define MICROPY_STREAMS_POSIX_API (0)
  721. #endif
  722. // Whether modules can use MP_REGISTER_MODULE_DELEGATION() to delegate failed
  723. // attribute lookups to a custom handler function.
  724. #ifndef MICROPY_MODULE_ATTR_DELEGATION
  725. #define MICROPY_MODULE_ATTR_DELEGATION (MICROPY_PY_SYS_ATTR_DELEGATION || MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  726. #endif
  727. // Whether to call __init__ when importing builtin modules for the first time.
  728. // Modules using this need to handle the possibility that __init__ might be
  729. // called multiple times.
  730. #ifndef MICROPY_MODULE_BUILTIN_INIT
  731. #define MICROPY_MODULE_BUILTIN_INIT (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  732. #endif
  733. // Whether to allow built-in modules to have sub-packages (by making the
  734. // sub-package a member of their locals dict). Sub-packages should not be
  735. // registered with MP_REGISTER_MODULE, instead they should be added as
  736. // members of the parent's globals dict. To match CPython behavior,
  737. // their __name__ should be "foo.bar"(i.e. QSTR_foo_dot_bar) which will
  738. // require an entry in qstrdefs, although it does also work to just call
  739. // it "bar". Also, because subpackages can be accessed without being
  740. // imported (e.g. as foo.bar after `import foo`), they should not
  741. // have __init__ methods. Instead, the top-level package's __init__ should
  742. // initialise all sub-packages.
  743. #ifndef MICROPY_MODULE_BUILTIN_SUBPACKAGES
  744. #define MICROPY_MODULE_BUILTIN_SUBPACKAGES (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING)
  745. #endif
  746. // Whether to support module-level __getattr__ (see PEP 562)
  747. #ifndef MICROPY_MODULE_GETATTR
  748. #define MICROPY_MODULE_GETATTR (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  749. #endif
  750. // Whether to enable importing foo.py with __name__ set to '__main__'
  751. // Used by the unix port for the -m flag.
  752. #ifndef MICROPY_MODULE_OVERRIDE_MAIN_IMPORT
  753. #define MICROPY_MODULE_OVERRIDE_MAIN_IMPORT (0)
  754. #endif
  755. // Whether frozen modules are supported in the form of strings
  756. #ifndef MICROPY_MODULE_FROZEN_STR
  757. #define MICROPY_MODULE_FROZEN_STR (0)
  758. #endif
  759. // Whether frozen modules are supported in the form of .mpy files
  760. #ifndef MICROPY_MODULE_FROZEN_MPY
  761. #define MICROPY_MODULE_FROZEN_MPY (0)
  762. #endif
  763. // Convenience macro for whether frozen modules are supported
  764. #ifndef MICROPY_MODULE_FROZEN
  765. #define MICROPY_MODULE_FROZEN (MICROPY_MODULE_FROZEN_STR || MICROPY_MODULE_FROZEN_MPY)
  766. #endif
  767. // Whether you can override builtins in the builtins module
  768. #ifndef MICROPY_CAN_OVERRIDE_BUILTINS
  769. #define MICROPY_CAN_OVERRIDE_BUILTINS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  770. #endif
  771. // Whether to check that the "self" argument of a builtin method has the
  772. // correct type. Such an explicit check is only needed if a builtin
  773. // method escapes to Python land without a first argument, eg
  774. // list.append([], 1). Without this check such calls will have undefined
  775. // behaviour (usually segfault) if the first argument is the wrong type.
  776. #ifndef MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG
  777. #define MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  778. #endif
  779. // Whether to use internally defined errno's (otherwise system provided ones)
  780. #ifndef MICROPY_USE_INTERNAL_ERRNO
  781. #define MICROPY_USE_INTERNAL_ERRNO (0)
  782. #endif
  783. // Whether to use internally defined *printf() functions (otherwise external ones)
  784. #ifndef MICROPY_USE_INTERNAL_PRINTF
  785. #define MICROPY_USE_INTERNAL_PRINTF (1)
  786. #endif
  787. // The mp_print_t printer used for printf output when MICROPY_USE_INTERNAL_PRINTF is enabled
  788. #ifndef MICROPY_INTERNAL_PRINTF_PRINTER
  789. #define MICROPY_INTERNAL_PRINTF_PRINTER (&mp_plat_print)
  790. #endif
  791. // Whether to support mp_sched_vm_abort to asynchronously abort to the top level.
  792. #ifndef MICROPY_ENABLE_VM_ABORT
  793. #define MICROPY_ENABLE_VM_ABORT (0)
  794. #endif
  795. // Support for internal scheduler
  796. #ifndef MICROPY_ENABLE_SCHEDULER
  797. #define MICROPY_ENABLE_SCHEDULER (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  798. #endif
  799. // Whether the scheduler supports scheduling static nodes with C callbacks
  800. #ifndef MICROPY_SCHEDULER_STATIC_NODES
  801. #define MICROPY_SCHEDULER_STATIC_NODES (0)
  802. #endif
  803. // Maximum number of entries in the scheduler
  804. #ifndef MICROPY_SCHEDULER_DEPTH
  805. #define MICROPY_SCHEDULER_DEPTH (4)
  806. #endif
  807. // Support for generic VFS sub-system
  808. #ifndef MICROPY_VFS
  809. #define MICROPY_VFS (0)
  810. #endif
  811. // Support for VFS POSIX component, to mount a POSIX filesystem within VFS
  812. #ifndef MICROPY_VFS_POSIX
  813. #define MICROPY_VFS_POSIX (0)
  814. #endif
  815. // Support for VFS FAT component, to mount a FAT filesystem within VFS
  816. #ifndef MICROPY_VFS_FAT
  817. #define MICROPY_VFS_FAT (0)
  818. #endif
  819. // Support for VFS LittleFS v1 component, to mount a LFSv1 filesystem within VFS
  820. #ifndef MICROPY_VFS_LFS1
  821. #define MICROPY_VFS_LFS1 (0)
  822. #endif
  823. // Support for VFS LittleFS v2 component, to mount a LFSv2 filesystem within VFS
  824. #ifndef MICROPY_VFS_LFS2
  825. #define MICROPY_VFS_LFS2 (0)
  826. #endif
  827. /*****************************************************************************/
  828. /* Fine control over Python builtins, classes, modules, etc */
  829. // Whether to support multiple inheritance of Python classes. Multiple
  830. // inheritance makes some C functions inherently recursive, and adds a bit of
  831. // code overhead.
  832. #ifndef MICROPY_MULTIPLE_INHERITANCE
  833. #define MICROPY_MULTIPLE_INHERITANCE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  834. #endif
  835. // Whether to implement attributes on functions
  836. #ifndef MICROPY_PY_FUNCTION_ATTRS
  837. #define MICROPY_PY_FUNCTION_ATTRS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  838. #endif
  839. // Whether to support the descriptors __get__, __set__, __delete__
  840. // This costs some code size and makes load/store/delete of instance
  841. // attributes slower for the classes that use this feature
  842. #ifndef MICROPY_PY_DESCRIPTORS
  843. #define MICROPY_PY_DESCRIPTORS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  844. #endif
  845. // Whether to support class __delattr__ and __setattr__ methods
  846. // This costs some code size and makes store/delete of instance
  847. // attributes slower for the classes that use this feature
  848. #ifndef MICROPY_PY_DELATTR_SETATTR
  849. #define MICROPY_PY_DELATTR_SETATTR (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  850. #endif
  851. // Support for async/await/async for/async with
  852. #ifndef MICROPY_PY_ASYNC_AWAIT
  853. #define MICROPY_PY_ASYNC_AWAIT (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  854. #endif
  855. // Support for literal string interpolation, f-strings (see PEP 498, Python 3.6+)
  856. #ifndef MICROPY_PY_FSTRINGS
  857. #define MICROPY_PY_FSTRINGS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  858. #endif
  859. // Support for assignment expressions with := (see PEP 572, Python 3.8+)
  860. #ifndef MICROPY_PY_ASSIGN_EXPR
  861. #define MICROPY_PY_ASSIGN_EXPR (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  862. #endif
  863. // Non-standard .pend_throw() method for generators, allowing for
  864. // Future-like behavior with respect to exception handling: an
  865. // exception set with .pend_throw() will activate on the next call
  866. // to generator's .send() or .__next__(). (This is useful to implement
  867. // async schedulers.)
  868. #ifndef MICROPY_PY_GENERATOR_PEND_THROW
  869. #define MICROPY_PY_GENERATOR_PEND_THROW (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  870. #endif
  871. // Issue a warning when comparing str and bytes objects
  872. #ifndef MICROPY_PY_STR_BYTES_CMP_WARN
  873. #define MICROPY_PY_STR_BYTES_CMP_WARN (0)
  874. #endif
  875. // Add bytes.hex and bytes.fromhex
  876. #ifndef MICROPY_PY_BUILTINS_BYTES_HEX
  877. #define MICROPY_PY_BUILTINS_BYTES_HEX (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  878. #endif
  879. // Whether str object is proper unicode
  880. #ifndef MICROPY_PY_BUILTINS_STR_UNICODE
  881. #define MICROPY_PY_BUILTINS_STR_UNICODE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  882. #endif
  883. // Whether to check for valid UTF-8 when converting bytes to str
  884. #ifndef MICROPY_PY_BUILTINS_STR_UNICODE_CHECK
  885. #define MICROPY_PY_BUILTINS_STR_UNICODE_CHECK (MICROPY_PY_BUILTINS_STR_UNICODE)
  886. #endif
  887. // Whether str.center() method provided
  888. #ifndef MICROPY_PY_BUILTINS_STR_CENTER
  889. #define MICROPY_PY_BUILTINS_STR_CENTER (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  890. #endif
  891. // Whether str.count() method provided
  892. #ifndef MICROPY_PY_BUILTINS_STR_COUNT
  893. #define MICROPY_PY_BUILTINS_STR_COUNT (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  894. #endif
  895. // Whether str % (...) formatting operator provided
  896. #ifndef MICROPY_PY_BUILTINS_STR_OP_MODULO
  897. #define MICROPY_PY_BUILTINS_STR_OP_MODULO (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  898. #endif
  899. // Whether str.partition()/str.rpartition() method provided
  900. #ifndef MICROPY_PY_BUILTINS_STR_PARTITION
  901. #define MICROPY_PY_BUILTINS_STR_PARTITION (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  902. #endif
  903. // Whether str.splitlines() method provided
  904. #ifndef MICROPY_PY_BUILTINS_STR_SPLITLINES
  905. #define MICROPY_PY_BUILTINS_STR_SPLITLINES (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  906. #endif
  907. // Whether to support bytearray object
  908. #ifndef MICROPY_PY_BUILTINS_BYTEARRAY
  909. #define MICROPY_PY_BUILTINS_BYTEARRAY (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  910. #endif
  911. // Whether to support dict.fromkeys() class method
  912. #ifndef MICROPY_PY_BUILTINS_DICT_FROMKEYS
  913. #define MICROPY_PY_BUILTINS_DICT_FROMKEYS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  914. #endif
  915. // Whether to support memoryview object
  916. #ifndef MICROPY_PY_BUILTINS_MEMORYVIEW
  917. #define MICROPY_PY_BUILTINS_MEMORYVIEW (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  918. #endif
  919. // Whether to support memoryview.itemsize attribute
  920. #ifndef MICROPY_PY_BUILTINS_MEMORYVIEW_ITEMSIZE
  921. #define MICROPY_PY_BUILTINS_MEMORYVIEW_ITEMSIZE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING)
  922. #endif
  923. // Whether to support set object
  924. #ifndef MICROPY_PY_BUILTINS_SET
  925. #define MICROPY_PY_BUILTINS_SET (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  926. #endif
  927. // Whether to support slice subscript operators and slice object
  928. #ifndef MICROPY_PY_BUILTINS_SLICE
  929. #define MICROPY_PY_BUILTINS_SLICE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  930. #endif
  931. // Whether to support slice attribute read access,
  932. // i.e. slice.start, slice.stop, slice.step
  933. #ifndef MICROPY_PY_BUILTINS_SLICE_ATTRS
  934. #define MICROPY_PY_BUILTINS_SLICE_ATTRS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  935. #endif
  936. // Whether to support the .indices(len) method on slice objects
  937. #ifndef MICROPY_PY_BUILTINS_SLICE_INDICES
  938. #define MICROPY_PY_BUILTINS_SLICE_INDICES (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  939. #endif
  940. // Whether to support frozenset object
  941. #ifndef MICROPY_PY_BUILTINS_FROZENSET
  942. #define MICROPY_PY_BUILTINS_FROZENSET (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  943. #endif
  944. // Whether to support property object
  945. #ifndef MICROPY_PY_BUILTINS_PROPERTY
  946. #define MICROPY_PY_BUILTINS_PROPERTY (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  947. #endif
  948. // Whether to implement the start/stop/step attributes (readback) on
  949. // the "range" builtin type. Rarely used, and costs ~60 bytes (x86).
  950. #ifndef MICROPY_PY_BUILTINS_RANGE_ATTRS
  951. #define MICROPY_PY_BUILTINS_RANGE_ATTRS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  952. #endif
  953. // Whether to support binary ops [only (in)equality is defined] between range
  954. // objects. With this option disabled all range objects that are not exactly
  955. // the same object will compare as not-equal. With it enabled the semantics
  956. // match CPython and ranges are equal if they yield the same sequence of items.
  957. #ifndef MICROPY_PY_BUILTINS_RANGE_BINOP
  958. #define MICROPY_PY_BUILTINS_RANGE_BINOP (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING)
  959. #endif
  960. // Support for calling next() with second argument
  961. #ifndef MICROPY_PY_BUILTINS_NEXT2
  962. #define MICROPY_PY_BUILTINS_NEXT2 (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING)
  963. #endif
  964. // Whether to support rounding of integers (incl bignum); eg round(123,-1)=120
  965. #ifndef MICROPY_PY_BUILTINS_ROUND_INT
  966. #define MICROPY_PY_BUILTINS_ROUND_INT (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  967. #endif
  968. // Whether to support complete set of special methods for user
  969. // classes, or only the most used ones. "Inplace" methods are
  970. // controlled by MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS below.
  971. // "Reverse" methods are controlled by
  972. // MICROPY_PY_REVERSE_SPECIAL_METHODS below.
  973. #ifndef MICROPY_PY_ALL_SPECIAL_METHODS
  974. #define MICROPY_PY_ALL_SPECIAL_METHODS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  975. #endif
  976. // Whether to support all inplace arithmetic operation methods
  977. // (__imul__, etc.)
  978. #ifndef MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS
  979. #define MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING)
  980. #endif
  981. // Whether to support reverse arithmetic operation methods
  982. // (__radd__, etc.). Additionally gated by
  983. // MICROPY_PY_ALL_SPECIAL_METHODS.
  984. #ifndef MICROPY_PY_REVERSE_SPECIAL_METHODS
  985. #define MICROPY_PY_REVERSE_SPECIAL_METHODS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  986. #endif
  987. // Whether to support compile function
  988. #ifndef MICROPY_PY_BUILTINS_COMPILE
  989. #define MICROPY_PY_BUILTINS_COMPILE (MICROPY_ENABLE_COMPILER && MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  990. #endif
  991. // Whether to support enumerate function(type)
  992. #ifndef MICROPY_PY_BUILTINS_ENUMERATE
  993. #define MICROPY_PY_BUILTINS_ENUMERATE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  994. #endif
  995. // Whether to support eval and exec functions
  996. // By default they are supported if the compiler is enabled
  997. #ifndef MICROPY_PY_BUILTINS_EVAL_EXEC
  998. #define MICROPY_PY_BUILTINS_EVAL_EXEC (MICROPY_ENABLE_COMPILER)
  999. #endif
  1000. // Whether to support the Python 2 execfile function
  1001. #ifndef MICROPY_PY_BUILTINS_EXECFILE
  1002. #define MICROPY_PY_BUILTINS_EXECFILE (MICROPY_ENABLE_COMPILER && MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1003. #endif
  1004. // Whether to support filter function(type)
  1005. #ifndef MICROPY_PY_BUILTINS_FILTER
  1006. #define MICROPY_PY_BUILTINS_FILTER (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  1007. #endif
  1008. // Whether to support reversed function(type)
  1009. #ifndef MICROPY_PY_BUILTINS_REVERSED
  1010. #define MICROPY_PY_BUILTINS_REVERSED (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  1011. #endif
  1012. // Whether to define "NotImplemented" special constant
  1013. #ifndef MICROPY_PY_BUILTINS_NOTIMPLEMENTED
  1014. #define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1015. #endif
  1016. // Whether to provide the built-in input() function. The implementation of this
  1017. // uses shared/readline, so can only be enabled if the port uses this readline.
  1018. #ifndef MICROPY_PY_BUILTINS_INPUT
  1019. #define MICROPY_PY_BUILTINS_INPUT (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1020. #endif
  1021. // Whether to support min/max functions
  1022. #ifndef MICROPY_PY_BUILTINS_MIN_MAX
  1023. #define MICROPY_PY_BUILTINS_MIN_MAX (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  1024. #endif
  1025. // Support for calls to pow() with 3 integer arguments
  1026. #ifndef MICROPY_PY_BUILTINS_POW3
  1027. #define MICROPY_PY_BUILTINS_POW3 (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1028. #endif
  1029. // Whether to provide the help function
  1030. #ifndef MICROPY_PY_BUILTINS_HELP
  1031. #define MICROPY_PY_BUILTINS_HELP (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1032. #endif
  1033. // Use this to configure the help text shown for help(). It should be a
  1034. // variable with the type "const char*". A sensible default is provided.
  1035. #ifndef MICROPY_PY_BUILTINS_HELP_TEXT
  1036. #define MICROPY_PY_BUILTINS_HELP_TEXT mp_help_default_text
  1037. #endif
  1038. // Add the ability to list the available modules when executing help('modules')
  1039. #ifndef MICROPY_PY_BUILTINS_HELP_MODULES
  1040. #define MICROPY_PY_BUILTINS_HELP_MODULES (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1041. #endif
  1042. // Whether to set __file__ for imported modules
  1043. #ifndef MICROPY_PY___FILE__
  1044. #define MICROPY_PY___FILE__ (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  1045. #endif
  1046. // Whether to provide mem-info related functions in micropython module
  1047. #ifndef MICROPY_PY_MICROPYTHON_MEM_INFO
  1048. #define MICROPY_PY_MICROPYTHON_MEM_INFO (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1049. #endif
  1050. // Whether to provide "micropython.stack_use" function
  1051. #ifndef MICROPY_PY_MICROPYTHON_STACK_USE
  1052. #define MICROPY_PY_MICROPYTHON_STACK_USE (MICROPY_PY_MICROPYTHON_MEM_INFO)
  1053. #endif
  1054. // Whether to provide the "micropython.heap_locked" function
  1055. #ifndef MICROPY_PY_MICROPYTHON_HEAP_LOCKED
  1056. #define MICROPY_PY_MICROPYTHON_HEAP_LOCKED (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING)
  1057. #endif
  1058. // Whether to provide "array" module. Note that large chunk of the
  1059. // underlying code is shared with "bytearray" builtin type, so to
  1060. // get real savings, it should be disabled too.
  1061. #ifndef MICROPY_PY_ARRAY
  1062. #define MICROPY_PY_ARRAY (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  1063. #endif
  1064. // Whether to support slice assignments for array (and bytearray).
  1065. // This is rarely used, but adds ~0.5K of code.
  1066. #ifndef MICROPY_PY_ARRAY_SLICE_ASSIGN
  1067. #define MICROPY_PY_ARRAY_SLICE_ASSIGN (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1068. #endif
  1069. // Whether to support attrtuple type (MicroPython extension)
  1070. // It provides space-efficient tuples with attribute access
  1071. #ifndef MICROPY_PY_ATTRTUPLE
  1072. #define MICROPY_PY_ATTRTUPLE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  1073. #endif
  1074. // Whether to provide "collections" module
  1075. #ifndef MICROPY_PY_COLLECTIONS
  1076. #define MICROPY_PY_COLLECTIONS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  1077. #endif
  1078. // Whether to provide "collections.deque" type
  1079. #ifndef MICROPY_PY_COLLECTIONS_DEQUE
  1080. #define MICROPY_PY_COLLECTIONS_DEQUE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1081. #endif
  1082. // Whether to provide "collections.OrderedDict" type
  1083. #ifndef MICROPY_PY_COLLECTIONS_ORDEREDDICT
  1084. #define MICROPY_PY_COLLECTIONS_ORDEREDDICT (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1085. #endif
  1086. // Whether to provide the _asdict function for namedtuple
  1087. #ifndef MICROPY_PY_COLLECTIONS_NAMEDTUPLE__ASDICT
  1088. #define MICROPY_PY_COLLECTIONS_NAMEDTUPLE__ASDICT (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING)
  1089. #endif
  1090. // Whether to provide "math" module
  1091. #ifndef MICROPY_PY_MATH
  1092. #define MICROPY_PY_MATH (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  1093. #endif
  1094. // Whether to provide all math module constants (Python 3.5+), or just pi and e.
  1095. #ifndef MICROPY_PY_MATH_CONSTANTS
  1096. #define MICROPY_PY_MATH_CONSTANTS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1097. #endif
  1098. // Whether to provide special math functions: math.{erf,erfc,gamma,lgamma}
  1099. #ifndef MICROPY_PY_MATH_SPECIAL_FUNCTIONS
  1100. #define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1101. #endif
  1102. // Whether to provide math.factorial function
  1103. #ifndef MICROPY_PY_MATH_FACTORIAL
  1104. #define MICROPY_PY_MATH_FACTORIAL (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1105. #endif
  1106. // Whether to provide math.isclose function
  1107. #ifndef MICROPY_PY_MATH_ISCLOSE
  1108. #define MICROPY_PY_MATH_ISCLOSE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1109. #endif
  1110. // Whether to provide fix for atan2 Inf handling.
  1111. #ifndef MICROPY_PY_MATH_ATAN2_FIX_INFNAN
  1112. #define MICROPY_PY_MATH_ATAN2_FIX_INFNAN (0)
  1113. #endif
  1114. // Whether to provide fix for fmod Inf handling.
  1115. #ifndef MICROPY_PY_MATH_FMOD_FIX_INFNAN
  1116. #define MICROPY_PY_MATH_FMOD_FIX_INFNAN (0)
  1117. #endif
  1118. // Whether to provide fix for modf negative zero handling.
  1119. #ifndef MICROPY_PY_MATH_MODF_FIX_NEGZERO
  1120. #define MICROPY_PY_MATH_MODF_FIX_NEGZERO (0)
  1121. #endif
  1122. // Whether to provide fix for pow(1, NaN) and pow(NaN, 0), which both should be 1 not NaN.
  1123. #ifndef MICROPY_PY_MATH_POW_FIX_NAN
  1124. #define MICROPY_PY_MATH_POW_FIX_NAN (0)
  1125. #endif
  1126. // Whether to provide "cmath" module
  1127. #ifndef MICROPY_PY_CMATH
  1128. #define MICROPY_PY_CMATH (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1129. #endif
  1130. // Whether to provide "micropython" module
  1131. #ifndef MICROPY_PY_MICROPYTHON
  1132. #define MICROPY_PY_MICROPYTHON (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  1133. #endif
  1134. // Whether to provide "gc" module
  1135. #ifndef MICROPY_PY_GC
  1136. #define MICROPY_PY_GC (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  1137. #endif
  1138. // Whether to return number of collected objects from gc.collect()
  1139. #ifndef MICROPY_PY_GC_COLLECT_RETVAL
  1140. #define MICROPY_PY_GC_COLLECT_RETVAL (0)
  1141. #endif
  1142. // Whether to provide "io" module
  1143. #ifndef MICROPY_PY_IO
  1144. #define MICROPY_PY_IO (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  1145. #endif
  1146. // Whether to provide "io.IOBase" class to support user streams
  1147. #ifndef MICROPY_PY_IO_IOBASE
  1148. #define MICROPY_PY_IO_IOBASE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1149. #endif
  1150. // Whether to provide "io.BytesIO" class
  1151. #ifndef MICROPY_PY_IO_BYTESIO
  1152. #define MICROPY_PY_IO_BYTESIO (1)
  1153. #endif
  1154. // Whether to provide "io.BufferedWriter" class
  1155. #ifndef MICROPY_PY_IO_BUFFEREDWRITER
  1156. #define MICROPY_PY_IO_BUFFEREDWRITER (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING)
  1157. #endif
  1158. // Whether to provide "struct" module
  1159. #ifndef MICROPY_PY_STRUCT
  1160. #define MICROPY_PY_STRUCT (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  1161. #endif
  1162. // Whether to provide "sys" module
  1163. #ifndef MICROPY_PY_SYS
  1164. #define MICROPY_PY_SYS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
  1165. #endif
  1166. // Whether to initialise "sys.path" and "sys.argv" to their defaults in mp_init()
  1167. #ifndef MICROPY_PY_SYS_PATH_ARGV_DEFAULTS
  1168. #define MICROPY_PY_SYS_PATH_ARGV_DEFAULTS (MICROPY_PY_SYS)
  1169. #endif
  1170. // Whether to provide "sys.maxsize" constant
  1171. #ifndef MICROPY_PY_SYS_MAXSIZE
  1172. #define MICROPY_PY_SYS_MAXSIZE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1173. #endif
  1174. // Whether to provide "sys.modules" dictionary
  1175. #ifndef MICROPY_PY_SYS_MODULES
  1176. #define MICROPY_PY_SYS_MODULES (1)
  1177. #endif
  1178. // Whether to provide "sys.exc_info" function
  1179. // Avoid enabling this, this function is Python2 heritage
  1180. #ifndef MICROPY_PY_SYS_EXC_INFO
  1181. #define MICROPY_PY_SYS_EXC_INFO (0)
  1182. #endif
  1183. // Whether to provide "sys.executable", which is the absolute path to the
  1184. // micropython binary
  1185. // Intended for use on the "OS" ports (e.g. Unix)
  1186. #ifndef MICROPY_PY_SYS_EXECUTABLE
  1187. #define MICROPY_PY_SYS_EXECUTABLE (0)
  1188. #endif
  1189. // Whether to provide "sys.intern"
  1190. #ifndef MICROPY_PY_SYS_INTERN
  1191. #define MICROPY_PY_SYS_INTERN (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING)
  1192. #endif
  1193. // Whether to provide "sys.exit" function
  1194. #ifndef MICROPY_PY_SYS_EXIT
  1195. #define MICROPY_PY_SYS_EXIT (1)
  1196. #endif
  1197. // Whether to provide "sys.atexit" function (MicroPython extension)
  1198. #ifndef MICROPY_PY_SYS_ATEXIT
  1199. #define MICROPY_PY_SYS_ATEXIT (0)
  1200. #endif
  1201. // Whether to provide the "sys.path" attribute (which forces module delegation
  1202. // and mutable sys attributes to be enabled).
  1203. // If MICROPY_PY_SYS_PATH_ARGV_DEFAULTS is enabled, this is initialised in
  1204. // mp_init to an empty list. Otherwise the port must initialise it using
  1205. // `mp_sys_path = mp_obj_new_list(...)`.
  1206. #ifndef MICROPY_PY_SYS_PATH
  1207. #define MICROPY_PY_SYS_PATH (1)
  1208. #endif
  1209. // Whether to provide the "sys.argv" attribute.
  1210. // If MICROPY_PY_SYS_PATH_ARGV_DEFAULTS is enabled, this is initialised in
  1211. // mp_init to an empty list. Otherwise the port must initialise it using
  1212. // `mp_obj_list_init(MP_OBJ_TO_PTR(mp_sys_argv), ...);`
  1213. #ifndef MICROPY_PY_SYS_ARGV
  1214. #define MICROPY_PY_SYS_ARGV (1)
  1215. #endif
  1216. // Whether to provide sys.{ps1,ps2} mutable attributes, to control REPL prompts
  1217. #ifndef MICROPY_PY_SYS_PS1_PS2
  1218. #define MICROPY_PY_SYS_PS1_PS2 (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1219. #endif
  1220. // Whether to provide "sys.settrace" function
  1221. #ifndef MICROPY_PY_SYS_SETTRACE
  1222. #define MICROPY_PY_SYS_SETTRACE (0)
  1223. #endif
  1224. // Whether to provide "sys.getsizeof" function
  1225. #ifndef MICROPY_PY_SYS_GETSIZEOF
  1226. #define MICROPY_PY_SYS_GETSIZEOF (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING)
  1227. #endif
  1228. // Whether to provide sys.{stdin,stdout,stderr} objects
  1229. #ifndef MICROPY_PY_SYS_STDFILES
  1230. #define MICROPY_PY_SYS_STDFILES (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1231. #endif
  1232. // Whether to provide sys.{stdin,stdout,stderr}.buffer object
  1233. // This is implemented per-port
  1234. #ifndef MICROPY_PY_SYS_STDIO_BUFFER
  1235. #define MICROPY_PY_SYS_STDIO_BUFFER (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1236. #endif
  1237. // Whether to provide sys.tracebacklimit mutable attribute
  1238. #ifndef MICROPY_PY_SYS_TRACEBACKLIMIT
  1239. #define MICROPY_PY_SYS_TRACEBACKLIMIT (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING)
  1240. #endif
  1241. // Whether the sys module supports attribute delegation
  1242. // This is enabled automatically when needed by other features
  1243. #ifndef MICROPY_PY_SYS_ATTR_DELEGATION
  1244. #define MICROPY_PY_SYS_ATTR_DELEGATION (MICROPY_PY_SYS_PATH || MICROPY_PY_SYS_PS1_PS2 || MICROPY_PY_SYS_TRACEBACKLIMIT)
  1245. #endif
  1246. // Whether to provide "errno" module
  1247. #ifndef MICROPY_PY_ERRNO
  1248. #define MICROPY_PY_ERRNO (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1249. #endif
  1250. // Whether to provide the errno.errorcode dict
  1251. #ifndef MICROPY_PY_ERRNO_ERRORCODE
  1252. #define MICROPY_PY_ERRNO_ERRORCODE (1)
  1253. #endif
  1254. // Whether to provide "select" module
  1255. #ifndef MICROPY_PY_SELECT
  1256. #define MICROPY_PY_SELECT (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1257. #endif
  1258. // Whether to enable POSIX optimisations in the "select" module (requires system poll)
  1259. #ifndef MICROPY_PY_SELECT_POSIX_OPTIMISATIONS
  1260. #define MICROPY_PY_SELECT_POSIX_OPTIMISATIONS (0)
  1261. #endif
  1262. // Whether to enable the select() function in the "select" module (baremetal
  1263. // implementation). This is present for compatibility but can be disabled to
  1264. // save space.
  1265. #ifndef MICROPY_PY_SELECT_SELECT
  1266. #define MICROPY_PY_SELECT_SELECT (1)
  1267. #endif
  1268. // Whether to provide the "time" module
  1269. #ifndef MICROPY_PY_TIME
  1270. #define MICROPY_PY_TIME (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_BASIC_FEATURES)
  1271. #endif
  1272. // Whether to provide time.gmtime/localtime/mktime functions
  1273. #ifndef MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME
  1274. #define MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME (0)
  1275. #endif
  1276. // Whether to provide time.time/time_ns functions
  1277. #ifndef MICROPY_PY_TIME_TIME_TIME_NS
  1278. #define MICROPY_PY_TIME_TIME_TIME_NS (0)
  1279. #endif
  1280. // Period of values returned by time.ticks_ms(), ticks_us(), ticks_cpu()
  1281. // functions. Should be power of two. All functions above use the same
  1282. // period, so if underlying hardware/API has different periods, the
  1283. // minimum of them should be used. The value below is the maximum value
  1284. // this parameter can take (corresponding to 30 bit tick values on 32-bit
  1285. // system).
  1286. #ifndef MICROPY_PY_TIME_TICKS_PERIOD
  1287. #define MICROPY_PY_TIME_TICKS_PERIOD (MP_SMALL_INT_POSITIVE_MASK + 1)
  1288. #endif
  1289. // Whether to provide "_thread" module
  1290. #ifndef MICROPY_PY_THREAD
  1291. #define MICROPY_PY_THREAD (0)
  1292. #endif
  1293. // Whether to make the VM/runtime thread-safe using a global lock
  1294. // If not enabled then thread safety must be provided at the Python level
  1295. #ifndef MICROPY_PY_THREAD_GIL
  1296. #define MICROPY_PY_THREAD_GIL (MICROPY_PY_THREAD)
  1297. #endif
  1298. // Number of VM jump-loops to do before releasing the GIL.
  1299. // Set this to 0 to disable the divisor.
  1300. #ifndef MICROPY_PY_THREAD_GIL_VM_DIVISOR
  1301. #define MICROPY_PY_THREAD_GIL_VM_DIVISOR (32)
  1302. #endif
  1303. // Extended modules
  1304. #ifndef MICROPY_PY_ASYNCIO
  1305. #define MICROPY_PY_ASYNCIO (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1306. #endif
  1307. #ifndef MICROPY_PY_UCTYPES
  1308. #define MICROPY_PY_UCTYPES (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1309. #endif
  1310. // Whether to provide SHORT, INT, LONG, etc. types in addition to
  1311. // exact-bitness types like INT16, INT32, etc.
  1312. #ifndef MICROPY_PY_UCTYPES_NATIVE_C_TYPES
  1313. #define MICROPY_PY_UCTYPES_NATIVE_C_TYPES (1)
  1314. #endif
  1315. // Whether to provide "deflate" module (decompression-only by default)
  1316. #ifndef MICROPY_PY_DEFLATE
  1317. #define MICROPY_PY_DEFLATE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1318. #endif
  1319. // Whether to provide compression support in "deflate" module
  1320. #ifndef MICROPY_PY_DEFLATE_COMPRESS
  1321. #define MICROPY_PY_DEFLATE_COMPRESS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_FULL_FEATURES)
  1322. #endif
  1323. #ifndef MICROPY_PY_JSON
  1324. #define MICROPY_PY_JSON (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1325. #endif
  1326. // Whether to support the "separators" argument to dump, dumps
  1327. #ifndef MICROPY_PY_JSON_SEPARATORS
  1328. #define MICROPY_PY_JSON_SEPARATORS (1)
  1329. #endif
  1330. #ifndef MICROPY_PY_OS
  1331. #define MICROPY_PY_OS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1332. #endif
  1333. #ifndef MICROPY_PY_OS_STATVFS
  1334. #define MICROPY_PY_OS_STATVFS (MICROPY_PY_OS)
  1335. #endif
  1336. #ifndef MICROPY_PY_RE
  1337. #define MICROPY_PY_RE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1338. #endif
  1339. #ifndef MICROPY_PY_RE_DEBUG
  1340. #define MICROPY_PY_RE_DEBUG (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING)
  1341. #endif
  1342. #ifndef MICROPY_PY_RE_MATCH_GROUPS
  1343. #define MICROPY_PY_RE_MATCH_GROUPS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING)
  1344. #endif
  1345. #ifndef MICROPY_PY_RE_MATCH_SPAN_START_END
  1346. #define MICROPY_PY_RE_MATCH_SPAN_START_END (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING)
  1347. #endif
  1348. #ifndef MICROPY_PY_RE_SUB
  1349. #define MICROPY_PY_RE_SUB (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1350. #endif
  1351. #ifndef MICROPY_PY_HEAPQ
  1352. #define MICROPY_PY_HEAPQ (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1353. #endif
  1354. #ifndef MICROPY_PY_HASHLIB
  1355. #define MICROPY_PY_HASHLIB (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1356. #endif
  1357. #ifndef MICROPY_PY_HASHLIB_MD5
  1358. #define MICROPY_PY_HASHLIB_MD5 (0)
  1359. #endif
  1360. #ifndef MICROPY_PY_HASHLIB_SHA1
  1361. #define MICROPY_PY_HASHLIB_SHA1 (0)
  1362. #endif
  1363. #ifndef MICROPY_PY_HASHLIB_SHA256
  1364. #define MICROPY_PY_HASHLIB_SHA256 (1)
  1365. #endif
  1366. #ifndef MICROPY_PY_CRYPTOLIB
  1367. #define MICROPY_PY_CRYPTOLIB (0)
  1368. #endif
  1369. // Depends on MICROPY_PY_CRYPTOLIB
  1370. #ifndef MICROPY_PY_CRYPTOLIB_CTR
  1371. #define MICROPY_PY_CRYPTOLIB_CTR (0)
  1372. #endif
  1373. #ifndef MICROPY_PY_CRYPTOLIB_CONSTS
  1374. #define MICROPY_PY_CRYPTOLIB_CONSTS (0)
  1375. #endif
  1376. #ifndef MICROPY_PY_BINASCII
  1377. #define MICROPY_PY_BINASCII (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1378. #endif
  1379. // Depends on MICROPY_PY_DEFLATE
  1380. #ifndef MICROPY_PY_BINASCII_CRC32
  1381. #define MICROPY_PY_BINASCII_CRC32 (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1382. #endif
  1383. #ifndef MICROPY_PY_RANDOM
  1384. #define MICROPY_PY_RANDOM (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1385. #endif
  1386. // Whether to include: randrange, randint, choice, random, uniform
  1387. #ifndef MICROPY_PY_RANDOM_EXTRA_FUNCS
  1388. #define MICROPY_PY_RANDOM_EXTRA_FUNCS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1389. #endif
  1390. #ifndef MICROPY_PY_MACHINE
  1391. #define MICROPY_PY_MACHINE (0)
  1392. #endif
  1393. // Whether to include: bitstream
  1394. #ifndef MICROPY_PY_MACHINE_BITSTREAM
  1395. #define MICROPY_PY_MACHINE_BITSTREAM (0)
  1396. #endif
  1397. // Whether to include: time_pulse_us
  1398. #ifndef MICROPY_PY_MACHINE_PULSE
  1399. #define MICROPY_PY_MACHINE_PULSE (0)
  1400. #endif
  1401. #ifndef MICROPY_PY_MACHINE_I2C
  1402. #define MICROPY_PY_MACHINE_I2C (0)
  1403. #endif
  1404. // Whether the low-level I2C transfer function supports a separate write as the first transfer
  1405. #ifndef MICROPY_PY_MACHINE_I2C_TRANSFER_WRITE1
  1406. #define MICROPY_PY_MACHINE_I2C_TRANSFER_WRITE1 (0)
  1407. #endif
  1408. // Whether to provide the "machine.SoftI2C" class
  1409. #ifndef MICROPY_PY_MACHINE_SOFTI2C
  1410. #define MICROPY_PY_MACHINE_SOFTI2C (0)
  1411. #endif
  1412. #ifndef MICROPY_PY_MACHINE_SPI
  1413. #define MICROPY_PY_MACHINE_SPI (0)
  1414. #endif
  1415. // Whether to provide the "machine.SoftSPI" class
  1416. #ifndef MICROPY_PY_MACHINE_SOFTSPI
  1417. #define MICROPY_PY_MACHINE_SOFTSPI (0)
  1418. #endif
  1419. // Whether to provide the "machine.Timer" class
  1420. #ifndef MICROPY_PY_MACHINE_TIMER
  1421. #define MICROPY_PY_MACHINE_TIMER (0)
  1422. #endif
  1423. // The default backlog value for socket.listen(backlog)
  1424. #ifndef MICROPY_PY_SOCKET_LISTEN_BACKLOG_DEFAULT
  1425. #define MICROPY_PY_SOCKET_LISTEN_BACKLOG_DEFAULT (2)
  1426. #endif
  1427. #ifndef MICROPY_PY_SSL
  1428. #define MICROPY_PY_SSL (0)
  1429. #endif
  1430. // Whether to add finaliser code to ssl objects
  1431. #ifndef MICROPY_PY_SSL_FINALISER
  1432. #define MICROPY_PY_SSL_FINALISER (MICROPY_ENABLE_FINALISER)
  1433. #endif
  1434. #ifndef MICROPY_PY_WEBSOCKET
  1435. #define MICROPY_PY_WEBSOCKET (0)
  1436. #endif
  1437. #ifndef MICROPY_PY_FRAMEBUF
  1438. #define MICROPY_PY_FRAMEBUF (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1439. #endif
  1440. #ifndef MICROPY_PY_BTREE
  1441. #define MICROPY_PY_BTREE (0)
  1442. #endif
  1443. // Whether to provide the low-level "_onewire" module
  1444. #ifndef MICROPY_PY_ONEWIRE
  1445. #define MICROPY_PY_ONEWIRE (0)
  1446. #endif
  1447. // Whether to provide the "platform" module
  1448. #ifndef MICROPY_PY_PLATFORM
  1449. #define MICROPY_PY_PLATFORM (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
  1450. #endif
  1451. /*****************************************************************************/
  1452. /* Hooks for a port to add builtins */
  1453. // Additional builtin function definitions - see modbuiltins.c:mp_module_builtins_globals_table for format.
  1454. #ifndef MICROPY_PORT_BUILTINS
  1455. #define MICROPY_PORT_BUILTINS
  1456. #endif
  1457. // Additional builtin function definitions for extension by command-line, boards or variants.
  1458. // See modbuiltins.c:mp_module_builtins_globals_table for format.
  1459. #ifndef MICROPY_PORT_EXTRA_BUILTINS
  1460. #define MICROPY_PORT_EXTRA_BUILTINS
  1461. #endif
  1462. // Additional constant definitions for the compiler - see compile.c:mp_constants_table.
  1463. #ifndef MICROPY_PORT_CONSTANTS
  1464. #define MICROPY_PORT_CONSTANTS
  1465. #endif
  1466. /*****************************************************************************/
  1467. /* Hooks for a port to wrap functions with attributes */
  1468. #ifndef MICROPY_WRAP_MP_BINARY_OP
  1469. #define MICROPY_WRAP_MP_BINARY_OP(f) f
  1470. #endif
  1471. #ifndef MICROPY_WRAP_MP_EXECUTE_BYTECODE
  1472. #define MICROPY_WRAP_MP_EXECUTE_BYTECODE(f) f
  1473. #endif
  1474. #ifndef MICROPY_WRAP_MP_LOAD_GLOBAL
  1475. #define MICROPY_WRAP_MP_LOAD_GLOBAL(f) f
  1476. #endif
  1477. #ifndef MICROPY_WRAP_MP_LOAD_NAME
  1478. #define MICROPY_WRAP_MP_LOAD_NAME(f) f
  1479. #endif
  1480. #ifndef MICROPY_WRAP_MP_MAP_LOOKUP
  1481. #define MICROPY_WRAP_MP_MAP_LOOKUP(f) f
  1482. #endif
  1483. #ifndef MICROPY_WRAP_MP_OBJ_GET_TYPE
  1484. #define MICROPY_WRAP_MP_OBJ_GET_TYPE(f) f
  1485. #endif
  1486. #ifndef MICROPY_WRAP_MP_SCHED_EXCEPTION
  1487. #define MICROPY_WRAP_MP_SCHED_EXCEPTION(f) f
  1488. #endif
  1489. #ifndef MICROPY_WRAP_MP_SCHED_KEYBOARD_INTERRUPT
  1490. #define MICROPY_WRAP_MP_SCHED_KEYBOARD_INTERRUPT(f) f
  1491. #endif
  1492. #ifndef MICROPY_WRAP_MP_SCHED_SCHEDULE
  1493. #define MICROPY_WRAP_MP_SCHED_SCHEDULE(f) f
  1494. #endif
  1495. #ifndef MICROPY_WRAP_MP_SCHED_VM_ABORT
  1496. #define MICROPY_WRAP_MP_SCHED_VM_ABORT(f) f
  1497. #endif
  1498. /*****************************************************************************/
  1499. /* Miscellaneous settings */
  1500. // All uPy objects in ROM must be aligned on at least a 4 byte boundary
  1501. // so that the small-int/qstr/pointer distinction can be made. For machines
  1502. // that don't do this (eg 16-bit CPU), define the following macro to something
  1503. // like __attribute__((aligned(4))).
  1504. #ifndef MICROPY_OBJ_BASE_ALIGNMENT
  1505. #define MICROPY_OBJ_BASE_ALIGNMENT
  1506. #endif
  1507. // String used for the banner, and sys.version additional information
  1508. #ifndef MICROPY_BANNER_NAME_AND_VERSION
  1509. #if MICROPY_PREVIEW_VERSION_2
  1510. #define MICROPY_BANNER_NAME_AND_VERSION "MicroPython (with v2.0 preview) " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE
  1511. #else
  1512. #define MICROPY_BANNER_NAME_AND_VERSION "MicroPython " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE
  1513. #endif
  1514. #endif
  1515. // String used for the second part of the banner, and sys.implementation._machine
  1516. #ifndef MICROPY_BANNER_MACHINE
  1517. #ifdef MICROPY_HW_BOARD_NAME
  1518. #define MICROPY_BANNER_MACHINE MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME
  1519. #else
  1520. #define MICROPY_BANNER_MACHINE MICROPY_PY_SYS_PLATFORM " [" MICROPY_PLATFORM_COMPILER "] version"
  1521. #endif
  1522. #endif
  1523. // Allow to override static modifier for global objects, e.g. to use with
  1524. // object code analysis tools which don't support static symbols.
  1525. #ifndef STATIC
  1526. #define STATIC static
  1527. #endif
  1528. // Number of bytes in an object word: mp_obj_t, mp_uint_t, mp_uint_t
  1529. #ifndef MP_BYTES_PER_OBJ_WORD
  1530. #define MP_BYTES_PER_OBJ_WORD (sizeof(mp_uint_t))
  1531. #endif
  1532. // Number of bits in a byte
  1533. #ifndef MP_BITS_PER_BYTE
  1534. #define MP_BITS_PER_BYTE (8)
  1535. #endif
  1536. // mp_int_t value with most significant bit set
  1537. #define MP_OBJ_WORD_MSBIT_HIGH (((mp_uint_t)1) << (MP_BYTES_PER_OBJ_WORD * MP_BITS_PER_BYTE - 1))
  1538. // Make sure both MP_ENDIANNESS_LITTLE and MP_ENDIANNESS_BIG are
  1539. // defined and that they are the opposite of each other.
  1540. #if defined(MP_ENDIANNESS_LITTLE)
  1541. #define MP_ENDIANNESS_BIG (!MP_ENDIANNESS_LITTLE)
  1542. #elif defined(MP_ENDIANNESS_BIG)
  1543. #define MP_ENDIANNESS_LITTLE (!MP_ENDIANNESS_BIG)
  1544. #else
  1545. // Endianness not defined by port so try to autodetect it.
  1546. #if defined(__BYTE_ORDER__)
  1547. #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
  1548. #define MP_ENDIANNESS_LITTLE (1)
  1549. #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
  1550. #define MP_ENDIANNESS_LITTLE (0)
  1551. #endif
  1552. #else
  1553. #include <endian.h>
  1554. #if defined(__BYTE_ORDER)
  1555. #if __BYTE_ORDER == __LITTLE_ENDIAN
  1556. #define MP_ENDIANNESS_LITTLE (1)
  1557. #elif __BYTE_ORDER == __BIG_ENDIAN
  1558. #define MP_ENDIANNESS_LITTLE (0)
  1559. #endif
  1560. #endif
  1561. #endif
  1562. #ifndef MP_ENDIANNESS_LITTLE
  1563. #error endianness not defined and cannot detect it
  1564. #endif
  1565. #define MP_ENDIANNESS_BIG (!MP_ENDIANNESS_LITTLE)
  1566. #endif
  1567. // Make a pointer to RAM callable (eg set lower bit for Thumb code)
  1568. // (This scheme won't work if we want to mix Thumb and normal ARM code.)
  1569. #ifndef MICROPY_MAKE_POINTER_CALLABLE
  1570. #define MICROPY_MAKE_POINTER_CALLABLE(p) (p)
  1571. #endif
  1572. // If these MP_PLAT_*_EXEC macros are overridden then the memory allocated by them
  1573. // must be somehow reachable for marking by the GC, since the native code
  1574. // generators store pointers to GC managed memory in the code.
  1575. #ifndef MP_PLAT_ALLOC_EXEC
  1576. #define MP_PLAT_ALLOC_EXEC(min_size, ptr, size) do { *ptr = m_new(byte, min_size); *size = min_size; } while (0)
  1577. #endif
  1578. #ifndef MP_PLAT_FREE_EXEC
  1579. #define MP_PLAT_FREE_EXEC(ptr, size) m_del(byte, ptr, size)
  1580. #endif
  1581. // Allocating new heap area at runtime requires port to be able to allocate from system heap
  1582. #if MICROPY_GC_SPLIT_HEAP_AUTO
  1583. #ifndef MP_PLAT_ALLOC_HEAP
  1584. #define MP_PLAT_ALLOC_HEAP(size) malloc(size)
  1585. #endif
  1586. #ifndef MP_PLAT_FREE_HEAP
  1587. #define MP_PLAT_FREE_HEAP(ptr) free(ptr)
  1588. #endif
  1589. #endif
  1590. // This macro is used to do all output (except when MICROPY_PY_IO is defined)
  1591. #ifndef MP_PLAT_PRINT_STRN
  1592. #define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
  1593. #endif
  1594. #ifndef MP_SSIZE_MAX
  1595. #define MP_SSIZE_MAX SSIZE_MAX
  1596. #endif
  1597. // printf format spec to use for mp_int_t and friends
  1598. #ifndef INT_FMT
  1599. #if defined(__LP64__)
  1600. // Archs where mp_int_t == long, long != int
  1601. #define UINT_FMT "%lu"
  1602. #define INT_FMT "%ld"
  1603. #elif defined(_WIN64)
  1604. #define UINT_FMT "%llu"
  1605. #define INT_FMT "%lld"
  1606. #else
  1607. // Archs where mp_int_t == int
  1608. #define UINT_FMT "%u"
  1609. #define INT_FMT "%d"
  1610. #endif
  1611. #endif // INT_FMT
  1612. // Modifier for function which doesn't return
  1613. #ifndef NORETURN
  1614. #define NORETURN __attribute__((noreturn))
  1615. #endif
  1616. // Modifier for weak functions
  1617. #ifndef MP_WEAK
  1618. #define MP_WEAK __attribute__((weak))
  1619. #endif
  1620. // Modifier for functions which should be never inlined
  1621. #ifndef MP_NOINLINE
  1622. #define MP_NOINLINE __attribute__((noinline))
  1623. #endif
  1624. // Modifier for functions which should be always inlined
  1625. #ifndef MP_ALWAYSINLINE
  1626. #define MP_ALWAYSINLINE __attribute__((always_inline))
  1627. #endif
  1628. // Condition is likely to be true, to help branch prediction
  1629. #ifndef MP_LIKELY
  1630. #define MP_LIKELY(x) __builtin_expect((x), 1)
  1631. #endif
  1632. // Condition is likely to be false, to help branch prediction
  1633. #ifndef MP_UNLIKELY
  1634. #define MP_UNLIKELY(x) __builtin_expect((x), 0)
  1635. #endif
  1636. // To annotate that code is unreachable
  1637. #ifndef MP_UNREACHABLE
  1638. #if defined(__GNUC__)
  1639. #define MP_UNREACHABLE __builtin_unreachable();
  1640. #else
  1641. #define MP_UNREACHABLE for (;;);
  1642. #endif
  1643. #endif
  1644. // Explicitly annotate switch case fall throughs
  1645. #if defined(__GNUC__) && __GNUC__ >= 7
  1646. #define MP_FALLTHROUGH __attribute__((fallthrough));
  1647. #else
  1648. #define MP_FALLTHROUGH
  1649. #endif
  1650. #ifndef MP_HTOBE16
  1651. #if MP_ENDIANNESS_LITTLE
  1652. #define MP_HTOBE16(x) ((uint16_t)((((x) & 0xff) << 8) | (((x) >> 8) & 0xff)))
  1653. #define MP_BE16TOH(x) MP_HTOBE16(x)
  1654. #else
  1655. #define MP_HTOBE16(x) (x)
  1656. #define MP_BE16TOH(x) (x)
  1657. #endif
  1658. #endif
  1659. #ifndef MP_HTOBE32
  1660. #if MP_ENDIANNESS_LITTLE
  1661. #define MP_HTOBE32(x) ((uint32_t)((((x) & 0xff) << 24) | (((x) & 0xff00) << 8) | (((x) >> 8) & 0xff00) | (((x) >> 24) & 0xff)))
  1662. #define MP_BE32TOH(x) MP_HTOBE32(x)
  1663. #else
  1664. #define MP_HTOBE32(x) (x)
  1665. #define MP_BE32TOH(x) (x)
  1666. #endif
  1667. #endif
  1668. // Warning categories are by default implemented as strings, though
  1669. // hook is left for a port to define them as something else.
  1670. #if MICROPY_WARNINGS_CATEGORY
  1671. #ifndef MP_WARN_CAT
  1672. #define MP_WARN_CAT(x) #x
  1673. #endif
  1674. #else
  1675. #undef MP_WARN_CAT
  1676. #define MP_WARN_CAT(x) (NULL)
  1677. #endif
  1678. #endif // MICROPY_INCLUDED_PY_MPCONFIG_H