mpconfigport.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. // options to control how MicroPython is built
  27. // Linking with GNU readline (MICROPY_USE_READLINE == 2) causes binary to be licensed under GPL
  28. #ifndef MICROPY_USE_READLINE
  29. #define MICROPY_USE_READLINE (1)
  30. #endif
  31. #define MICROPY_ALLOC_PATH_MAX (260) //see minwindef.h for msvc or limits.h for mingw
  32. #define MICROPY_PERSISTENT_CODE_LOAD (1)
  33. #define MICROPY_EMIT_X64 (0)
  34. #define MICROPY_EMIT_THUMB (0)
  35. #define MICROPY_EMIT_INLINE_THUMB (0)
  36. #define MICROPY_COMP_MODULE_CONST (1)
  37. #define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (1)
  38. #define MICROPY_COMP_RETURN_IF_EXPR (1)
  39. #define MICROPY_ENABLE_GC (1)
  40. #define MICROPY_ENABLE_FINALISER (1)
  41. #define MICROPY_ENABLE_PYSTACK (1)
  42. #define MICROPY_STACK_CHECK (1)
  43. #define MICROPY_MALLOC_USES_ALLOCATED_SIZE (1)
  44. #define MICROPY_MEM_STATS (1)
  45. #define MICROPY_DEBUG_PRINTERS (1)
  46. #define MICROPY_DEBUG_PRINTER_DEST mp_stderr_print
  47. #define MICROPY_READER_POSIX (1)
  48. #define MICROPY_USE_READLINE_HISTORY (1)
  49. #define MICROPY_HELPER_REPL (1)
  50. #define MICROPY_REPL_EMACS_KEYS (1)
  51. #define MICROPY_REPL_AUTO_INDENT (1)
  52. #define MICROPY_HELPER_LEXER_UNIX (1)
  53. #define MICROPY_ENABLE_SOURCE_LINE (1)
  54. #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE)
  55. #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
  56. #define MICROPY_STREAMS_NON_BLOCK (1)
  57. #define MICROPY_STREAMS_POSIX_API (1)
  58. #define MICROPY_OPT_COMPUTED_GOTO (0)
  59. #define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE (1)
  60. #define MICROPY_CAN_OVERRIDE_BUILTINS (1)
  61. #define MICROPY_PY_FUNCTION_ATTRS (1)
  62. #define MICROPY_PY_DESCRIPTORS (1)
  63. #define MICROPY_PY_BUILTINS_STR_UNICODE (1)
  64. #define MICROPY_PY_BUILTINS_STR_CENTER (1)
  65. #define MICROPY_PY_BUILTINS_STR_PARTITION (1)
  66. #define MICROPY_PY_BUILTINS_STR_SPLITLINES (1)
  67. #define MICROPY_PY_BUILTINS_MEMORYVIEW (1)
  68. #define MICROPY_PY_BUILTINS_FROZENSET (1)
  69. #define MICROPY_PY_BUILTINS_COMPILE (1)
  70. #define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (1)
  71. #define MICROPY_PY_BUILTINS_INPUT (1)
  72. #define MICROPY_PY_BUILTINS_POW3 (1)
  73. #define MICROPY_PY_MICROPYTHON_MEM_INFO (1)
  74. #define MICROPY_PY_ALL_SPECIAL_METHODS (1)
  75. #define MICROPY_PY_REVERSE_SPECIAL_METHODS (1)
  76. #define MICROPY_PY_ARRAY_SLICE_ASSIGN (1)
  77. #define MICROPY_PY_BUILTINS_SLICE_ATTRS (1)
  78. #define MICROPY_PY_SYS_EXIT (1)
  79. #define MICROPY_PY_SYS_PLATFORM "win32"
  80. #define MICROPY_PY_SYS_MAXSIZE (1)
  81. #define MICROPY_PY_SYS_STDFILES (1)
  82. #define MICROPY_PY_SYS_EXC_INFO (1)
  83. #define MICROPY_PY_COLLECTIONS_DEQUE (1)
  84. #define MICROPY_PY_COLLECTIONS_ORDEREDDICT (1)
  85. #define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (1)
  86. #define MICROPY_PY_CMATH (1)
  87. #define MICROPY_PY_IO_FILEIO (1)
  88. #define MICROPY_PY_GC_COLLECT_RETVAL (1)
  89. #define MICROPY_MODULE_FROZEN_STR (0)
  90. #define MICROPY_STACKLESS (0)
  91. #define MICROPY_STACKLESS_STRICT (0)
  92. #define MICROPY_PY_UTIME (1)
  93. #define MICROPY_PY_UTIME_MP_HAL (1)
  94. #define MICROPY_PY_UERRNO (1)
  95. #define MICROPY_PY_UCTYPES (1)
  96. #define MICROPY_PY_UZLIB (1)
  97. #define MICROPY_PY_UJSON (1)
  98. #define MICROPY_PY_URE (1)
  99. #define MICROPY_PY_UHEAPQ (1)
  100. #define MICROPY_PY_UTIMEQ (1)
  101. #define MICROPY_PY_UHASHLIB (1)
  102. #define MICROPY_PY_UBINASCII (1)
  103. #define MICROPY_PY_UBINASCII_CRC32 (1)
  104. #define MICROPY_PY_URANDOM (1)
  105. #define MICROPY_PY_MACHINE (1)
  106. #define MICROPY_PY_MACHINE_PULSE (1)
  107. #define MICROPY_MACHINE_MEM_GET_READ_ADDR mod_machine_mem_get_addr
  108. #define MICROPY_MACHINE_MEM_GET_WRITE_ADDR mod_machine_mem_get_addr
  109. #define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_DETAILED)
  110. #define MICROPY_ERROR_PRINTER (&mp_stderr_print)
  111. #define MICROPY_WARNINGS (1)
  112. #define MICROPY_PY_STR_BYTES_CMP_WARN (1)
  113. extern const struct _mp_print_t mp_stderr_print;
  114. #ifdef _MSC_VER
  115. #define MICROPY_GCREGS_SETJMP (1)
  116. #define MICROPY_USE_INTERNAL_PRINTF (0)
  117. #endif
  118. #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1)
  119. #define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (256)
  120. #define MICROPY_KBD_EXCEPTION (1)
  121. #define MICROPY_PORT_INIT_FUNC init()
  122. #define MICROPY_PORT_DEINIT_FUNC deinit()
  123. // type definitions for the specific machine
  124. #if defined( __MINGW32__ ) && defined( __LP64__ )
  125. typedef long mp_int_t; // must be pointer size
  126. typedef unsigned long mp_uint_t; // must be pointer size
  127. #elif defined ( __MINGW32__ ) && defined( _WIN64 )
  128. #include <stdint.h>
  129. typedef __int64 mp_int_t;
  130. typedef unsigned __int64 mp_uint_t;
  131. #define MP_SSIZE_MAX __INT64_MAX__
  132. #elif defined ( _MSC_VER ) && defined( _WIN64 )
  133. typedef __int64 mp_int_t;
  134. typedef unsigned __int64 mp_uint_t;
  135. #else
  136. // These are definitions for machines where sizeof(int) == sizeof(void*),
  137. // regardless for actual size.
  138. typedef int mp_int_t; // must be pointer size
  139. typedef unsigned int mp_uint_t; // must be pointer size
  140. #endif
  141. // Just assume Windows is little-endian - mingw32 gcc doesn't
  142. // define standard endianness macros.
  143. #define MP_ENDIANNESS_LITTLE (1)
  144. // Cannot include <sys/types.h>, as it may lead to symbol name clashes
  145. #if _FILE_OFFSET_BITS == 64 && !defined(__LP64__)
  146. typedef long long mp_off_t;
  147. #else
  148. typedef long mp_off_t;
  149. #endif
  150. #if MICROPY_PY_OS_DUPTERM
  151. #define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
  152. void mp_hal_dupterm_tx_strn(const char *str, size_t len);
  153. #else
  154. #include <unistd.h>
  155. #define MP_PLAT_PRINT_STRN(str, len) do { int ret = write(1, str, len); (void)ret; } while (0)
  156. #define mp_hal_dupterm_tx_strn(s, l)
  157. #endif
  158. #define MICROPY_PORT_BUILTINS \
  159. { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },
  160. extern const struct _mp_obj_module_t mp_module_os;
  161. extern const struct _mp_obj_module_t mp_module_time;
  162. #define MICROPY_PORT_BUILTIN_MODULES \
  163. { MP_ROM_QSTR(MP_QSTR_utime), MP_ROM_PTR(&mp_module_time) }, \
  164. { MP_ROM_QSTR(MP_QSTR_umachine), MP_ROM_PTR(&mp_module_machine) }, \
  165. { MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&mp_module_os) }, \
  166. #if MICROPY_USE_READLINE == 1
  167. #define MICROPY_PORT_ROOT_POINTERS \
  168. char *readline_hist[50];
  169. #endif
  170. #define MP_STATE_PORT MP_STATE_VM
  171. #define MICROPY_MPHALPORT_H "windows_mphal.h"
  172. // We need to provide a declaration/definition of alloca()
  173. #include <malloc.h>
  174. #include "realpath.h"
  175. #include "init.h"
  176. #include "sleep.h"
  177. #ifdef __GNUC__
  178. #define MP_NOINLINE __attribute__((noinline))
  179. #endif
  180. // MSVC specifics
  181. #ifdef _MSC_VER
  182. // Sanity check
  183. #if ( _MSC_VER < 1800 )
  184. #error Can only build with Visual Studio 2013 toolset
  185. #endif
  186. // CL specific overrides from mpconfig
  187. #define NORETURN __declspec(noreturn)
  188. #define MP_NOINLINE __declspec(noinline)
  189. #define MP_LIKELY(x) (x)
  190. #define MP_UNLIKELY(x) (x)
  191. #define MICROPY_PORT_CONSTANTS { "dummy", 0 } //can't have zero-sized array
  192. #ifdef _WIN64
  193. #define MP_SSIZE_MAX _I64_MAX
  194. #else
  195. #define MP_SSIZE_MAX _I32_MAX
  196. #endif
  197. // CL specific definitions
  198. #define restrict
  199. #define inline __inline
  200. #define alignof(t) __alignof(t)
  201. #define PATH_MAX MICROPY_ALLOC_PATH_MAX
  202. #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  203. #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  204. #ifdef _WIN64
  205. #define SSIZE_MAX _I64_MAX
  206. typedef __int64 ssize_t;
  207. #else
  208. #define SSIZE_MAX _I32_MAX
  209. typedef int ssize_t;
  210. #endif
  211. typedef mp_off_t off_t;
  212. // Put static/global variables in sections with a known name
  213. // This used to be required for GC, not the case anymore but keep it as it makes the map file easier to inspect
  214. // For this to work this header must be included by all sources, which is the case normally
  215. #define MICROPY_PORT_DATASECTION "upydata"
  216. #define MICROPY_PORT_BSSSECTION "upybss"
  217. #pragma data_seg(MICROPY_PORT_DATASECTION)
  218. #pragma bss_seg(MICROPY_PORT_BSSSECTION)
  219. // System headers (needed e.g. for nlr.h)
  220. #include <stddef.h> //for NULL
  221. #include <assert.h> //for assert
  222. #endif