eelang 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. eelang-0.1.0/MANIFEST.in +1 -0
  2. eelang-0.1.0/PKG-INFO +67 -0
  3. eelang-0.1.0/README.md +57 -0
  4. eelang-0.1.0/csrc/Include/internal/mimalloc/mimalloc/atomic.h +392 -0
  5. eelang-0.1.0/csrc/Include/internal/mimalloc/mimalloc/internal.h +969 -0
  6. eelang-0.1.0/csrc/Include/internal/mimalloc/mimalloc/prim.h +329 -0
  7. eelang-0.1.0/csrc/Include/internal/mimalloc/mimalloc/track.h +147 -0
  8. eelang-0.1.0/csrc/Include/internal/mimalloc/mimalloc/types.h +748 -0
  9. eelang-0.1.0/csrc/Include/internal/mimalloc/mimalloc.h +565 -0
  10. eelang-0.1.0/csrc/Include/internal/pycore_abstract.h +74 -0
  11. eelang-0.1.0/csrc/Include/internal/pycore_asdl.h +112 -0
  12. eelang-0.1.0/csrc/Include/internal/pycore_ast.h +948 -0
  13. eelang-0.1.0/csrc/Include/internal/pycore_ast_state.h +273 -0
  14. eelang-0.1.0/csrc/Include/internal/pycore_atexit.h +31 -0
  15. eelang-0.1.0/csrc/Include/internal/pycore_audit.h +35 -0
  16. eelang-0.1.0/csrc/Include/internal/pycore_backoff.h +183 -0
  17. eelang-0.1.0/csrc/Include/internal/pycore_bitutils.h +186 -0
  18. eelang-0.1.0/csrc/Include/internal/pycore_blocks_output_buffer.h +264 -0
  19. eelang-0.1.0/csrc/Include/internal/pycore_brc.h +73 -0
  20. eelang-0.1.0/csrc/Include/internal/pycore_bytes_methods.h +85 -0
  21. eelang-0.1.0/csrc/Include/internal/pycore_bytesobject.h +112 -0
  22. eelang-0.1.0/csrc/Include/internal/pycore_c_array.h +39 -0
  23. eelang-0.1.0/csrc/Include/internal/pycore_call.h +182 -0
  24. eelang-0.1.0/csrc/Include/internal/pycore_capsule.h +17 -0
  25. eelang-0.1.0/csrc/Include/internal/pycore_cell.h +75 -0
  26. eelang-0.1.0/csrc/Include/internal/pycore_ceval.h +494 -0
  27. eelang-0.1.0/csrc/Include/internal/pycore_ceval_state.h +48 -0
  28. eelang-0.1.0/csrc/Include/internal/pycore_code.h +706 -0
  29. eelang-0.1.0/csrc/Include/internal/pycore_codecs.h +76 -0
  30. eelang-0.1.0/csrc/Include/internal/pycore_compile.h +235 -0
  31. eelang-0.1.0/csrc/Include/internal/pycore_complexobject.h +34 -0
  32. eelang-0.1.0/csrc/Include/internal/pycore_condvar.h +93 -0
  33. eelang-0.1.0/csrc/Include/internal/pycore_context.h +62 -0
  34. eelang-0.1.0/csrc/Include/internal/pycore_critical_section.h +297 -0
  35. eelang-0.1.0/csrc/Include/internal/pycore_crossinterp.h +412 -0
  36. eelang-0.1.0/csrc/Include/internal/pycore_crossinterp_data_registry.h +41 -0
  37. eelang-0.1.0/csrc/Include/internal/pycore_debug_offsets.h +423 -0
  38. eelang-0.1.0/csrc/Include/internal/pycore_descrobject.h +30 -0
  39. eelang-0.1.0/csrc/Include/internal/pycore_dict.h +453 -0
  40. eelang-0.1.0/csrc/Include/internal/pycore_dict_state.h +30 -0
  41. eelang-0.1.0/csrc/Include/internal/pycore_dtoa.h +40 -0
  42. eelang-0.1.0/csrc/Include/internal/pycore_emscripten_signal.h +30 -0
  43. eelang-0.1.0/csrc/Include/internal/pycore_emscripten_trampoline.h +67 -0
  44. eelang-0.1.0/csrc/Include/internal/pycore_exceptions.h +40 -0
  45. eelang-0.1.0/csrc/Include/internal/pycore_faulthandler.h +103 -0
  46. eelang-0.1.0/csrc/Include/internal/pycore_fileutils.h +320 -0
  47. eelang-0.1.0/csrc/Include/internal/pycore_fileutils_windows.h +98 -0
  48. eelang-0.1.0/csrc/Include/internal/pycore_floatobject.h +57 -0
  49. eelang-0.1.0/csrc/Include/internal/pycore_flowgraph.h +47 -0
  50. eelang-0.1.0/csrc/Include/internal/pycore_format.h +27 -0
  51. eelang-0.1.0/csrc/Include/internal/pycore_frame.h +61 -0
  52. eelang-0.1.0/csrc/Include/internal/pycore_freelist.h +112 -0
  53. eelang-0.1.0/csrc/Include/internal/pycore_freelist_state.h +74 -0
  54. eelang-0.1.0/csrc/Include/internal/pycore_function.h +64 -0
  55. eelang-0.1.0/csrc/Include/internal/pycore_gc.h +350 -0
  56. eelang-0.1.0/csrc/Include/internal/pycore_genobject.h +48 -0
  57. eelang-0.1.0/csrc/Include/internal/pycore_getopt.h +22 -0
  58. eelang-0.1.0/csrc/Include/internal/pycore_gil.h +66 -0
  59. eelang-0.1.0/csrc/Include/internal/pycore_global_objects.h +34 -0
  60. eelang-0.1.0/csrc/Include/internal/pycore_global_objects_fini_generated.h +2451 -0
  61. eelang-0.1.0/csrc/Include/internal/pycore_global_strings.h +945 -0
  62. eelang-0.1.0/csrc/Include/internal/pycore_hamt.h +113 -0
  63. eelang-0.1.0/csrc/Include/internal/pycore_hashtable.h +150 -0
  64. eelang-0.1.0/csrc/Include/internal/pycore_import.h +176 -0
  65. eelang-0.1.0/csrc/Include/internal/pycore_importdl.h +171 -0
  66. eelang-0.1.0/csrc/Include/internal/pycore_index_pool.h +36 -0
  67. eelang-0.1.0/csrc/Include/internal/pycore_initconfig.h +197 -0
  68. eelang-0.1.0/csrc/Include/internal/pycore_instruction_sequence.h +84 -0
  69. eelang-0.1.0/csrc/Include/internal/pycore_instruments.h +136 -0
  70. eelang-0.1.0/csrc/Include/internal/pycore_interp.h +109 -0
  71. eelang-0.1.0/csrc/Include/internal/pycore_interp_structs.h +1077 -0
  72. eelang-0.1.0/csrc/Include/internal/pycore_interpframe.h +431 -0
  73. eelang-0.1.0/csrc/Include/internal/pycore_interpframe_structs.h +94 -0
  74. eelang-0.1.0/csrc/Include/internal/pycore_interpolation.h +26 -0
  75. eelang-0.1.0/csrc/Include/internal/pycore_intrinsics.h +51 -0
  76. eelang-0.1.0/csrc/Include/internal/pycore_jit.h +41 -0
  77. eelang-0.1.0/csrc/Include/internal/pycore_jit_publish.h +31 -0
  78. eelang-0.1.0/csrc/Include/internal/pycore_jit_unwind.h +81 -0
  79. eelang-0.1.0/csrc/Include/internal/pycore_lazyimportobject.h +37 -0
  80. eelang-0.1.0/csrc/Include/internal/pycore_list.h +83 -0
  81. eelang-0.1.0/csrc/Include/internal/pycore_llist.h +106 -0
  82. eelang-0.1.0/csrc/Include/internal/pycore_lock.h +247 -0
  83. eelang-0.1.0/csrc/Include/internal/pycore_long.h +352 -0
  84. eelang-0.1.0/csrc/Include/internal/pycore_magic_number.h +323 -0
  85. eelang-0.1.0/csrc/Include/internal/pycore_memoryobject.h +20 -0
  86. eelang-0.1.0/csrc/Include/internal/pycore_mimalloc.h +69 -0
  87. eelang-0.1.0/csrc/Include/internal/pycore_mmap.h +47 -0
  88. eelang-0.1.0/csrc/Include/internal/pycore_modsupport.h +98 -0
  89. eelang-0.1.0/csrc/Include/internal/pycore_moduleobject.h +86 -0
  90. eelang-0.1.0/csrc/Include/internal/pycore_namespace.h +21 -0
  91. eelang-0.1.0/csrc/Include/internal/pycore_object.h +1046 -0
  92. eelang-0.1.0/csrc/Include/internal/pycore_object_alloc.h +71 -0
  93. eelang-0.1.0/csrc/Include/internal/pycore_object_deferred.h +32 -0
  94. eelang-0.1.0/csrc/Include/internal/pycore_object_stack.h +95 -0
  95. eelang-0.1.0/csrc/Include/internal/pycore_object_state.h +49 -0
  96. eelang-0.1.0/csrc/Include/internal/pycore_obmalloc.h +728 -0
  97. eelang-0.1.0/csrc/Include/internal/pycore_obmalloc_init.h +66 -0
  98. eelang-0.1.0/csrc/Include/internal/pycore_opcode_metadata.h +2172 -0
  99. eelang-0.1.0/csrc/Include/internal/pycore_opcode_utils.h +102 -0
  100. eelang-0.1.0/csrc/Include/internal/pycore_optimizer.h +558 -0
  101. eelang-0.1.0/csrc/Include/internal/pycore_optimizer_types.h +169 -0
  102. eelang-0.1.0/csrc/Include/internal/pycore_parking_lot.h +97 -0
  103. eelang-0.1.0/csrc/Include/internal/pycore_parser.h +63 -0
  104. eelang-0.1.0/csrc/Include/internal/pycore_pathconfig.h +26 -0
  105. eelang-0.1.0/csrc/Include/internal/pycore_pyarena.h +68 -0
  106. eelang-0.1.0/csrc/Include/internal/pycore_pyatomic_ft_wrappers.h +213 -0
  107. eelang-0.1.0/csrc/Include/internal/pycore_pybuffer.h +21 -0
  108. eelang-0.1.0/csrc/Include/internal/pycore_pyerrors.h +219 -0
  109. eelang-0.1.0/csrc/Include/internal/pycore_pyhash.h +93 -0
  110. eelang-0.1.0/csrc/Include/internal/pycore_pylifecycle.h +133 -0
  111. eelang-0.1.0/csrc/Include/internal/pycore_pymath.h +204 -0
  112. eelang-0.1.0/csrc/Include/internal/pycore_pymem.h +135 -0
  113. eelang-0.1.0/csrc/Include/internal/pycore_pymem_init.h +109 -0
  114. eelang-0.1.0/csrc/Include/internal/pycore_pystate.h +381 -0
  115. eelang-0.1.0/csrc/Include/internal/pycore_pystats.h +21 -0
  116. eelang-0.1.0/csrc/Include/internal/pycore_pythonrun.h +75 -0
  117. eelang-0.1.0/csrc/Include/internal/pycore_pythread.h +172 -0
  118. eelang-0.1.0/csrc/Include/internal/pycore_qsbr.h +173 -0
  119. eelang-0.1.0/csrc/Include/internal/pycore_range.h +21 -0
  120. eelang-0.1.0/csrc/Include/internal/pycore_runtime.h +86 -0
  121. eelang-0.1.0/csrc/Include/internal/pycore_runtime_init.h +226 -0
  122. eelang-0.1.0/csrc/Include/internal/pycore_runtime_init_generated.h +2448 -0
  123. eelang-0.1.0/csrc/Include/internal/pycore_runtime_structs.h +312 -0
  124. eelang-0.1.0/csrc/Include/internal/pycore_semaphore.h +65 -0
  125. eelang-0.1.0/csrc/Include/internal/pycore_setobject.h +41 -0
  126. eelang-0.1.0/csrc/Include/internal/pycore_signal.h +108 -0
  127. eelang-0.1.0/csrc/Include/internal/pycore_sliceobject.h +20 -0
  128. eelang-0.1.0/csrc/Include/internal/pycore_slots.h +138 -0
  129. eelang-0.1.0/csrc/Include/internal/pycore_slots_generated.h +958 -0
  130. eelang-0.1.0/csrc/Include/internal/pycore_stackref.h +865 -0
  131. eelang-0.1.0/csrc/Include/internal/pycore_stats.h +122 -0
  132. eelang-0.1.0/csrc/Include/internal/pycore_strhex.h +35 -0
  133. eelang-0.1.0/csrc/Include/internal/pycore_structs.h +88 -0
  134. eelang-0.1.0/csrc/Include/internal/pycore_structseq.h +40 -0
  135. eelang-0.1.0/csrc/Include/internal/pycore_symtable.h +209 -0
  136. eelang-0.1.0/csrc/Include/internal/pycore_sysmodule.h +27 -0
  137. eelang-0.1.0/csrc/Include/internal/pycore_template.h +26 -0
  138. eelang-0.1.0/csrc/Include/internal/pycore_time.h +325 -0
  139. eelang-0.1.0/csrc/Include/internal/pycore_token.h +110 -0
  140. eelang-0.1.0/csrc/Include/internal/pycore_traceback.h +63 -0
  141. eelang-0.1.0/csrc/Include/internal/pycore_tracemalloc.h +172 -0
  142. eelang-0.1.0/csrc/Include/internal/pycore_tstate.h +119 -0
  143. eelang-0.1.0/csrc/Include/internal/pycore_tuple.h +81 -0
  144. eelang-0.1.0/csrc/Include/internal/pycore_typedefs.h +18 -0
  145. eelang-0.1.0/csrc/Include/internal/pycore_typeobject.h +177 -0
  146. eelang-0.1.0/csrc/Include/internal/pycore_typevarobject.h +28 -0
  147. eelang-0.1.0/csrc/Include/internal/pycore_ucnhash.h +36 -0
  148. eelang-0.1.0/csrc/Include/internal/pycore_unicodectype.h +25 -0
  149. eelang-0.1.0/csrc/Include/internal/pycore_unicodeobject.h +383 -0
  150. eelang-0.1.0/csrc/Include/internal/pycore_unicodeobject_generated.h +3496 -0
  151. eelang-0.1.0/csrc/Include/internal/pycore_unionobject.h +26 -0
  152. eelang-0.1.0/csrc/Include/internal/pycore_uniqueid.h +57 -0
  153. eelang-0.1.0/csrc/Include/internal/pycore_uop.h +73 -0
  154. eelang-0.1.0/csrc/Include/internal/pycore_uop_ids.h +1452 -0
  155. eelang-0.1.0/csrc/Include/internal/pycore_uop_metadata.h +7051 -0
  156. eelang-0.1.0/csrc/Include/internal/pycore_warnings.h +21 -0
  157. eelang-0.1.0/csrc/Include/internal/pycore_weakref.h +133 -0
  158. eelang-0.1.0/csrc/Parser/Python.asdl +154 -0
  159. eelang-0.1.0/csrc/Parser/action_helpers.c +2881 -0
  160. eelang-0.1.0/csrc/Parser/asdl.py +399 -0
  161. eelang-0.1.0/csrc/Parser/asdl_c.py +2414 -0
  162. eelang-0.1.0/csrc/Parser/lexer/buffer.c +80 -0
  163. eelang-0.1.0/csrc/Parser/lexer/buffer.h +10 -0
  164. eelang-0.1.0/csrc/Parser/lexer/lexer.c +1596 -0
  165. eelang-0.1.0/csrc/Parser/lexer/lexer.h +8 -0
  166. eelang-0.1.0/csrc/Parser/lexer/state.c +137 -0
  167. eelang-0.1.0/csrc/Parser/lexer/state.h +154 -0
  168. eelang-0.1.0/csrc/Parser/myreadline.c +437 -0
  169. eelang-0.1.0/csrc/Parser/parser.c +41645 -0
  170. eelang-0.1.0/csrc/Parser/peg_api.c +42 -0
  171. eelang-0.1.0/csrc/Parser/pegen.c +1095 -0
  172. eelang-0.1.0/csrc/Parser/pegen.h +461 -0
  173. eelang-0.1.0/csrc/Parser/pegen_errors.c +416 -0
  174. eelang-0.1.0/csrc/Parser/string_parser.c +339 -0
  175. eelang-0.1.0/csrc/Parser/string_parser.h +11 -0
  176. eelang-0.1.0/csrc/Parser/token.c +250 -0
  177. eelang-0.1.0/csrc/Parser/tokenizer/file_tokenizer.c +487 -0
  178. eelang-0.1.0/csrc/Parser/tokenizer/helpers.c +650 -0
  179. eelang-0.1.0/csrc/Parser/tokenizer/helpers.h +38 -0
  180. eelang-0.1.0/csrc/Parser/tokenizer/readline_tokenizer.c +131 -0
  181. eelang-0.1.0/csrc/Parser/tokenizer/string_tokenizer.c +148 -0
  182. eelang-0.1.0/csrc/Parser/tokenizer/tokenizer.h +14 -0
  183. eelang-0.1.0/csrc/Parser/tokenizer/utf8_tokenizer.c +55 -0
  184. eelang-0.1.0/csrc/Python/Python-ast.c +18527 -0
  185. eelang-0.1.0/csrc/Python/asdl.c +6 -0
  186. eelang-0.1.0/csrc/_parser.c +76 -0
  187. eelang-0.1.0/eelang/__init__.py +22 -0
  188. eelang-0.1.0/eelang/__main__.py +25 -0
  189. eelang-0.1.0/eelang.egg-info/PKG-INFO +67 -0
  190. eelang-0.1.0/eelang.egg-info/SOURCES.txt +193 -0
  191. eelang-0.1.0/eelang.egg-info/dependency_links.txt +1 -0
  192. eelang-0.1.0/eelang.egg-info/top_level.txt +1 -0
  193. eelang-0.1.0/pyproject.toml +19 -0
  194. eelang-0.1.0/setup.cfg +4 -0
  195. eelang-0.1.0/setup.py +22 -0
@@ -0,0 +1 @@
1
+ recursive-include csrc *
eelang-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,67 @@
1
+ Metadata-Version: 2.4
2
+ Name: eelang
3
+ Version: 0.1.0
4
+ Summary: eelang — надмножество Python 3.15: паттерн-матчинг в присваиваниях, match def, пайплайны
5
+ License-Expression: MIT
6
+ Classifier: Programming Language :: Python :: 3.15
7
+ Classifier: Operating System :: POSIX :: Linux
8
+ Requires-Python: <3.16,>=3.15
9
+ Description-Content-Type: text/markdown
10
+
11
+ # eelang
12
+
13
+ Надмножество **Python 3.15** (linux x86_64): паттерн-матчинг в присваиваниях и
14
+ `assert`, `match def`, пайплайны. Распространяется обычным пакетом, код пишется в
15
+ `.eel`-файлах.
16
+
17
+ ## Установка
18
+
19
+ ```sh
20
+ pip install eelang
21
+ ```
22
+
23
+ Требуется CPython 3.15 (linux x86_64).
24
+
25
+ ## Запуск
26
+
27
+ ```sh
28
+ python -m eelang script.eel
29
+ ```
30
+
31
+ ## Фичи
32
+
33
+ - **assert-паттерны** — `assert P = e` связывает и проверяет форму; провал → `MatchError`.
34
+
35
+ ```python
36
+ assert Point(x, y) = get_point()
37
+ ```
38
+
39
+ - **match def** — паттерн-матчинг аргументов функции:
40
+
41
+ ```python
42
+ match def area(p) -> float:
43
+ case Point(x, y) = p:
44
+ x * y
45
+ else:
46
+ 0
47
+ ```
48
+
49
+ - **Пайплайны** — `..f(...)` (значение — последним аргументом), `..match:`, `..assert:`:
50
+
51
+ ```python
52
+ val =
53
+ [1, 2, 3]
54
+ ..map(lambda x: x * x)
55
+ ```
56
+
57
+ `MatchError` импортируется явно:
58
+
59
+ ```python
60
+ from eelang import MatchError
61
+ ```
62
+
63
+ ## Как устроен
64
+
65
+ Парсер — C-расширение (`eelang._parser`), собранное из PEG-парсера CPython 3.15 с
66
+ eelang-грамматикой. Синтаксис десахарится в стандартные узлы AST; `MatchError` —
67
+ обычный Python-класс (`ValueError`) в пакете.
eelang-0.1.0/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # eelang
2
+
3
+ Надмножество **Python 3.15** (linux x86_64): паттерн-матчинг в присваиваниях и
4
+ `assert`, `match def`, пайплайны. Распространяется обычным пакетом, код пишется в
5
+ `.eel`-файлах.
6
+
7
+ ## Установка
8
+
9
+ ```sh
10
+ pip install eelang
11
+ ```
12
+
13
+ Требуется CPython 3.15 (linux x86_64).
14
+
15
+ ## Запуск
16
+
17
+ ```sh
18
+ python -m eelang script.eel
19
+ ```
20
+
21
+ ## Фичи
22
+
23
+ - **assert-паттерны** — `assert P = e` связывает и проверяет форму; провал → `MatchError`.
24
+
25
+ ```python
26
+ assert Point(x, y) = get_point()
27
+ ```
28
+
29
+ - **match def** — паттерн-матчинг аргументов функции:
30
+
31
+ ```python
32
+ match def area(p) -> float:
33
+ case Point(x, y) = p:
34
+ x * y
35
+ else:
36
+ 0
37
+ ```
38
+
39
+ - **Пайплайны** — `..f(...)` (значение — последним аргументом), `..match:`, `..assert:`:
40
+
41
+ ```python
42
+ val =
43
+ [1, 2, 3]
44
+ ..map(lambda x: x * x)
45
+ ```
46
+
47
+ `MatchError` импортируется явно:
48
+
49
+ ```python
50
+ from eelang import MatchError
51
+ ```
52
+
53
+ ## Как устроен
54
+
55
+ Парсер — C-расширение (`eelang._parser`), собранное из PEG-парсера CPython 3.15 с
56
+ eelang-грамматикой. Синтаксис десахарится в стандартные узлы AST; `MatchError` —
57
+ обычный Python-класс (`ValueError`) в пакете.
@@ -0,0 +1,392 @@
1
+ /* ----------------------------------------------------------------------------
2
+ Copyright (c) 2018-2023 Microsoft Research, Daan Leijen
3
+ This is free software; you can redistribute it and/or modify it under the
4
+ terms of the MIT license. A copy of the license can be found in the file
5
+ "LICENSE" at the root of this distribution.
6
+ -----------------------------------------------------------------------------*/
7
+ #pragma once
8
+ #ifndef MIMALLOC_ATOMIC_H
9
+ #define MIMALLOC_ATOMIC_H
10
+
11
+ // --------------------------------------------------------------------------------------------
12
+ // Atomics
13
+ // We need to be portable between C, C++, and MSVC.
14
+ // We base the primitives on the C/C++ atomics and create a minimal wrapper for MSVC in C compilation mode.
15
+ // This is why we try to use only `uintptr_t` and `<type>*` as atomic types.
16
+ // To gain better insight in the range of used atomics, we use explicitly named memory order operations
17
+ // instead of passing the memory order as a parameter.
18
+ // -----------------------------------------------------------------------------------------------
19
+
20
+ #if defined(__cplusplus)
21
+ // Use C++ atomics
22
+ #include <atomic>
23
+ #define _Atomic(tp) std::atomic<tp>
24
+ #define mi_atomic(name) std::atomic_##name
25
+ #define mi_memory_order(name) std::memory_order_##name
26
+ #if (__cplusplus >= 202002L) // c++20, see issue #571
27
+ #define MI_ATOMIC_VAR_INIT(x) x
28
+ #elif !defined(ATOMIC_VAR_INIT)
29
+ #define MI_ATOMIC_VAR_INIT(x) x
30
+ #else
31
+ #define MI_ATOMIC_VAR_INIT(x) ATOMIC_VAR_INIT(x)
32
+ #endif
33
+ #elif defined(_MSC_VER)
34
+ // Use MSVC C wrapper for C11 atomics
35
+ #define _Atomic(tp) tp
36
+ #define MI_ATOMIC_VAR_INIT(x) x
37
+ #define mi_atomic(name) mi_atomic_##name
38
+ #define mi_memory_order(name) mi_memory_order_##name
39
+ #else
40
+ // Use C11 atomics
41
+ #include <stdatomic.h>
42
+ #define mi_atomic(name) atomic_##name
43
+ #define mi_memory_order(name) memory_order_##name
44
+ #if (__STDC_VERSION__ >= 201710L) // c17, see issue #735
45
+ #define MI_ATOMIC_VAR_INIT(x) x
46
+ #elif !defined(ATOMIC_VAR_INIT)
47
+ #define MI_ATOMIC_VAR_INIT(x) x
48
+ #else
49
+ #define MI_ATOMIC_VAR_INIT(x) ATOMIC_VAR_INIT(x)
50
+ #endif
51
+ #endif
52
+
53
+ // Various defines for all used memory orders in mimalloc
54
+ #define mi_atomic_cas_weak(p,expected,desired,mem_success,mem_fail) \
55
+ mi_atomic(compare_exchange_weak_explicit)(p,expected,desired,mem_success,mem_fail)
56
+
57
+ #define mi_atomic_cas_strong(p,expected,desired,mem_success,mem_fail) \
58
+ mi_atomic(compare_exchange_strong_explicit)(p,expected,desired,mem_success,mem_fail)
59
+
60
+ #define mi_atomic_load_acquire(p) mi_atomic(load_explicit)(p,mi_memory_order(acquire))
61
+ #define mi_atomic_load_relaxed(p) mi_atomic(load_explicit)(p,mi_memory_order(relaxed))
62
+ #define mi_atomic_store_release(p,x) mi_atomic(store_explicit)(p,x,mi_memory_order(release))
63
+ #define mi_atomic_store_relaxed(p,x) mi_atomic(store_explicit)(p,x,mi_memory_order(relaxed))
64
+ #define mi_atomic_exchange_release(p,x) mi_atomic(exchange_explicit)(p,x,mi_memory_order(release))
65
+ #define mi_atomic_exchange_acq_rel(p,x) mi_atomic(exchange_explicit)(p,x,mi_memory_order(acq_rel))
66
+ #define mi_atomic_cas_weak_release(p,exp,des) mi_atomic_cas_weak(p,exp,des,mi_memory_order(release),mi_memory_order(relaxed))
67
+ #define mi_atomic_cas_weak_acq_rel(p,exp,des) mi_atomic_cas_weak(p,exp,des,mi_memory_order(acq_rel),mi_memory_order(acquire))
68
+ #define mi_atomic_cas_strong_release(p,exp,des) mi_atomic_cas_strong(p,exp,des,mi_memory_order(release),mi_memory_order(relaxed))
69
+ #define mi_atomic_cas_strong_acq_rel(p,exp,des) mi_atomic_cas_strong(p,exp,des,mi_memory_order(acq_rel),mi_memory_order(acquire))
70
+
71
+ #define mi_atomic_add_relaxed(p,x) mi_atomic(fetch_add_explicit)(p,x,mi_memory_order(relaxed))
72
+ #define mi_atomic_sub_relaxed(p,x) mi_atomic(fetch_sub_explicit)(p,x,mi_memory_order(relaxed))
73
+ #define mi_atomic_add_acq_rel(p,x) mi_atomic(fetch_add_explicit)(p,x,mi_memory_order(acq_rel))
74
+ #define mi_atomic_sub_acq_rel(p,x) mi_atomic(fetch_sub_explicit)(p,x,mi_memory_order(acq_rel))
75
+ #define mi_atomic_and_acq_rel(p,x) mi_atomic(fetch_and_explicit)(p,x,mi_memory_order(acq_rel))
76
+ #define mi_atomic_or_acq_rel(p,x) mi_atomic(fetch_or_explicit)(p,x,mi_memory_order(acq_rel))
77
+
78
+ #define mi_atomic_increment_relaxed(p) mi_atomic_add_relaxed(p,(uintptr_t)1)
79
+ #define mi_atomic_decrement_relaxed(p) mi_atomic_sub_relaxed(p,(uintptr_t)1)
80
+ #define mi_atomic_increment_acq_rel(p) mi_atomic_add_acq_rel(p,(uintptr_t)1)
81
+ #define mi_atomic_decrement_acq_rel(p) mi_atomic_sub_acq_rel(p,(uintptr_t)1)
82
+
83
+ static inline void mi_atomic_yield(void);
84
+ static inline intptr_t mi_atomic_addi(_Atomic(intptr_t)*p, intptr_t add);
85
+ static inline intptr_t mi_atomic_subi(_Atomic(intptr_t)*p, intptr_t sub);
86
+
87
+
88
+ #if defined(__cplusplus) || !defined(_MSC_VER)
89
+
90
+ // In C++/C11 atomics we have polymorphic atomics so can use the typed `ptr` variants (where `tp` is the type of atomic value)
91
+ // We use these macros so we can provide a typed wrapper in MSVC in C compilation mode as well
92
+ #define mi_atomic_load_ptr_acquire(tp,p) mi_atomic_load_acquire(p)
93
+ #define mi_atomic_load_ptr_relaxed(tp,p) mi_atomic_load_relaxed(p)
94
+
95
+ // In C++ we need to add casts to help resolve templates if NULL is passed
96
+ #if defined(__cplusplus)
97
+ #define mi_atomic_store_ptr_release(tp,p,x) mi_atomic_store_release(p,(tp*)x)
98
+ #define mi_atomic_store_ptr_relaxed(tp,p,x) mi_atomic_store_relaxed(p,(tp*)x)
99
+ #define mi_atomic_cas_ptr_weak_release(tp,p,exp,des) mi_atomic_cas_weak_release(p,exp,(tp*)des)
100
+ #define mi_atomic_cas_ptr_weak_acq_rel(tp,p,exp,des) mi_atomic_cas_weak_acq_rel(p,exp,(tp*)des)
101
+ #define mi_atomic_cas_ptr_strong_release(tp,p,exp,des) mi_atomic_cas_strong_release(p,exp,(tp*)des)
102
+ #define mi_atomic_exchange_ptr_release(tp,p,x) mi_atomic_exchange_release(p,(tp*)x)
103
+ #define mi_atomic_exchange_ptr_acq_rel(tp,p,x) mi_atomic_exchange_acq_rel(p,(tp*)x)
104
+ #else
105
+ #define mi_atomic_store_ptr_release(tp,p,x) mi_atomic_store_release(p,x)
106
+ #define mi_atomic_store_ptr_relaxed(tp,p,x) mi_atomic_store_relaxed(p,x)
107
+ #define mi_atomic_cas_ptr_weak_release(tp,p,exp,des) mi_atomic_cas_weak_release(p,exp,des)
108
+ #define mi_atomic_cas_ptr_weak_acq_rel(tp,p,exp,des) mi_atomic_cas_weak_acq_rel(p,exp,des)
109
+ #define mi_atomic_cas_ptr_strong_release(tp,p,exp,des) mi_atomic_cas_strong_release(p,exp,des)
110
+ #define mi_atomic_exchange_ptr_release(tp,p,x) mi_atomic_exchange_release(p,x)
111
+ #define mi_atomic_exchange_ptr_acq_rel(tp,p,x) mi_atomic_exchange_acq_rel(p,x)
112
+ #endif
113
+
114
+ // These are used by the statistics
115
+ static inline int64_t mi_atomic_addi64_relaxed(volatile int64_t* p, int64_t add) {
116
+ return mi_atomic(fetch_add_explicit)((_Atomic(int64_t)*)p, add, mi_memory_order(relaxed));
117
+ }
118
+ static inline void mi_atomic_maxi64_relaxed(volatile int64_t* p, int64_t x) {
119
+ int64_t current = mi_atomic_load_relaxed((_Atomic(int64_t)*)p);
120
+ while (current < x && !mi_atomic_cas_weak_release((_Atomic(int64_t)*)p, &current, x)) { /* nothing */ };
121
+ }
122
+
123
+ // Used by timers
124
+ #define mi_atomic_loadi64_acquire(p) mi_atomic(load_explicit)(p,mi_memory_order(acquire))
125
+ #define mi_atomic_loadi64_relaxed(p) mi_atomic(load_explicit)(p,mi_memory_order(relaxed))
126
+ #define mi_atomic_storei64_release(p,x) mi_atomic(store_explicit)(p,x,mi_memory_order(release))
127
+ #define mi_atomic_storei64_relaxed(p,x) mi_atomic(store_explicit)(p,x,mi_memory_order(relaxed))
128
+
129
+ #define mi_atomic_casi64_strong_acq_rel(p,e,d) mi_atomic_cas_strong_acq_rel(p,e,d)
130
+ #define mi_atomic_addi64_acq_rel(p,i) mi_atomic_add_acq_rel(p,i)
131
+
132
+
133
+ #elif defined(_MSC_VER)
134
+
135
+ // MSVC C compilation wrapper that uses Interlocked operations to model C11 atomics.
136
+ #define WIN32_LEAN_AND_MEAN
137
+ #include <windows.h>
138
+ #include <intrin.h>
139
+ #ifdef _WIN64
140
+ typedef LONG64 msc_intptr_t;
141
+ #define MI_64(f) f##64
142
+ #else
143
+ typedef LONG msc_intptr_t;
144
+ #define MI_64(f) f
145
+ #endif
146
+
147
+ typedef enum mi_memory_order_e {
148
+ mi_memory_order_relaxed,
149
+ mi_memory_order_consume,
150
+ mi_memory_order_acquire,
151
+ mi_memory_order_release,
152
+ mi_memory_order_acq_rel,
153
+ mi_memory_order_seq_cst
154
+ } mi_memory_order;
155
+
156
+ static inline uintptr_t mi_atomic_fetch_add_explicit(_Atomic(uintptr_t)*p, uintptr_t add, mi_memory_order mo) {
157
+ (void)(mo);
158
+ return (uintptr_t)MI_64(_InterlockedExchangeAdd)((volatile msc_intptr_t*)p, (msc_intptr_t)add);
159
+ }
160
+ static inline uintptr_t mi_atomic_fetch_sub_explicit(_Atomic(uintptr_t)*p, uintptr_t sub, mi_memory_order mo) {
161
+ (void)(mo);
162
+ return (uintptr_t)MI_64(_InterlockedExchangeAdd)((volatile msc_intptr_t*)p, -((msc_intptr_t)sub));
163
+ }
164
+ static inline uintptr_t mi_atomic_fetch_and_explicit(_Atomic(uintptr_t)*p, uintptr_t x, mi_memory_order mo) {
165
+ (void)(mo);
166
+ return (uintptr_t)MI_64(_InterlockedAnd)((volatile msc_intptr_t*)p, (msc_intptr_t)x);
167
+ }
168
+ static inline uintptr_t mi_atomic_fetch_or_explicit(_Atomic(uintptr_t)*p, uintptr_t x, mi_memory_order mo) {
169
+ (void)(mo);
170
+ return (uintptr_t)MI_64(_InterlockedOr)((volatile msc_intptr_t*)p, (msc_intptr_t)x);
171
+ }
172
+ static inline bool mi_atomic_compare_exchange_strong_explicit(_Atomic(uintptr_t)*p, uintptr_t* expected, uintptr_t desired, mi_memory_order mo1, mi_memory_order mo2) {
173
+ (void)(mo1); (void)(mo2);
174
+ uintptr_t read = (uintptr_t)MI_64(_InterlockedCompareExchange)((volatile msc_intptr_t*)p, (msc_intptr_t)desired, (msc_intptr_t)(*expected));
175
+ if (read == *expected) {
176
+ return true;
177
+ }
178
+ else {
179
+ *expected = read;
180
+ return false;
181
+ }
182
+ }
183
+ static inline bool mi_atomic_compare_exchange_weak_explicit(_Atomic(uintptr_t)*p, uintptr_t* expected, uintptr_t desired, mi_memory_order mo1, mi_memory_order mo2) {
184
+ return mi_atomic_compare_exchange_strong_explicit(p, expected, desired, mo1, mo2);
185
+ }
186
+ static inline uintptr_t mi_atomic_exchange_explicit(_Atomic(uintptr_t)*p, uintptr_t exchange, mi_memory_order mo) {
187
+ (void)(mo);
188
+ return (uintptr_t)MI_64(_InterlockedExchange)((volatile msc_intptr_t*)p, (msc_intptr_t)exchange);
189
+ }
190
+ static inline void mi_atomic_thread_fence(mi_memory_order mo) {
191
+ (void)(mo);
192
+ _Atomic(uintptr_t) x = 0;
193
+ mi_atomic_exchange_explicit(&x, 1, mo);
194
+ }
195
+ static inline uintptr_t mi_atomic_load_explicit(_Atomic(uintptr_t) const* p, mi_memory_order mo) {
196
+ (void)(mo);
197
+ #if defined(_M_IX86) || defined(_M_X64)
198
+ return *p;
199
+ #else
200
+ uintptr_t x = *p;
201
+ if (mo > mi_memory_order_relaxed) {
202
+ while (!mi_atomic_compare_exchange_weak_explicit((_Atomic(uintptr_t)*)p, &x, x, mo, mi_memory_order_relaxed)) { /* nothing */ };
203
+ }
204
+ return x;
205
+ #endif
206
+ }
207
+ static inline void mi_atomic_store_explicit(_Atomic(uintptr_t)*p, uintptr_t x, mi_memory_order mo) {
208
+ (void)(mo);
209
+ #if defined(_M_IX86) || defined(_M_X64)
210
+ *p = x;
211
+ #else
212
+ mi_atomic_exchange_explicit(p, x, mo);
213
+ #endif
214
+ }
215
+ static inline int64_t mi_atomic_loadi64_explicit(_Atomic(int64_t)*p, mi_memory_order mo) {
216
+ (void)(mo);
217
+ #if defined(_M_X64)
218
+ return *p;
219
+ #else
220
+ int64_t old = *p;
221
+ int64_t x = old;
222
+ while ((old = InterlockedCompareExchange64(p, x, old)) != x) {
223
+ x = old;
224
+ }
225
+ return x;
226
+ #endif
227
+ }
228
+ static inline void mi_atomic_storei64_explicit(_Atomic(int64_t)*p, int64_t x, mi_memory_order mo) {
229
+ (void)(mo);
230
+ #if defined(x_M_IX86) || defined(_M_X64)
231
+ *p = x;
232
+ #else
233
+ InterlockedExchange64(p, x);
234
+ #endif
235
+ }
236
+
237
+ // These are used by the statistics
238
+ static inline int64_t mi_atomic_addi64_relaxed(volatile _Atomic(int64_t)*p, int64_t add) {
239
+ #ifdef _WIN64
240
+ return (int64_t)mi_atomic_addi((int64_t*)p, add);
241
+ #else
242
+ int64_t current;
243
+ int64_t sum;
244
+ do {
245
+ current = *p;
246
+ sum = current + add;
247
+ } while (_InterlockedCompareExchange64(p, sum, current) != current);
248
+ return current;
249
+ #endif
250
+ }
251
+ static inline void mi_atomic_maxi64_relaxed(volatile _Atomic(int64_t)*p, int64_t x) {
252
+ int64_t current;
253
+ do {
254
+ current = *p;
255
+ } while (current < x && _InterlockedCompareExchange64(p, x, current) != current);
256
+ }
257
+
258
+ static inline void mi_atomic_addi64_acq_rel(volatile _Atomic(int64_t*)p, int64_t i) {
259
+ mi_atomic_addi64_relaxed(p, i);
260
+ }
261
+
262
+ static inline bool mi_atomic_casi64_strong_acq_rel(volatile _Atomic(int64_t*)p, int64_t* exp, int64_t des) {
263
+ int64_t read = _InterlockedCompareExchange64(p, des, *exp);
264
+ if (read == *exp) {
265
+ return true;
266
+ }
267
+ else {
268
+ *exp = read;
269
+ return false;
270
+ }
271
+ }
272
+
273
+ // The pointer macros cast to `uintptr_t`.
274
+ #define mi_atomic_load_ptr_acquire(tp,p) (tp*)mi_atomic_load_acquire((_Atomic(uintptr_t)*)(p))
275
+ #define mi_atomic_load_ptr_relaxed(tp,p) (tp*)mi_atomic_load_relaxed((_Atomic(uintptr_t)*)(p))
276
+ #define mi_atomic_store_ptr_release(tp,p,x) mi_atomic_store_release((_Atomic(uintptr_t)*)(p),(uintptr_t)(x))
277
+ #define mi_atomic_store_ptr_relaxed(tp,p,x) mi_atomic_store_relaxed((_Atomic(uintptr_t)*)(p),(uintptr_t)(x))
278
+ #define mi_atomic_cas_ptr_weak_release(tp,p,exp,des) mi_atomic_cas_weak_release((_Atomic(uintptr_t)*)(p),(uintptr_t*)exp,(uintptr_t)des)
279
+ #define mi_atomic_cas_ptr_weak_acq_rel(tp,p,exp,des) mi_atomic_cas_weak_acq_rel((_Atomic(uintptr_t)*)(p),(uintptr_t*)exp,(uintptr_t)des)
280
+ #define mi_atomic_cas_ptr_strong_release(tp,p,exp,des) mi_atomic_cas_strong_release((_Atomic(uintptr_t)*)(p),(uintptr_t*)exp,(uintptr_t)des)
281
+ #define mi_atomic_exchange_ptr_release(tp,p,x) (tp*)mi_atomic_exchange_release((_Atomic(uintptr_t)*)(p),(uintptr_t)x)
282
+ #define mi_atomic_exchange_ptr_acq_rel(tp,p,x) (tp*)mi_atomic_exchange_acq_rel((_Atomic(uintptr_t)*)(p),(uintptr_t)x)
283
+
284
+ #define mi_atomic_loadi64_acquire(p) mi_atomic(loadi64_explicit)(p,mi_memory_order(acquire))
285
+ #define mi_atomic_loadi64_relaxed(p) mi_atomic(loadi64_explicit)(p,mi_memory_order(relaxed))
286
+ #define mi_atomic_storei64_release(p,x) mi_atomic(storei64_explicit)(p,x,mi_memory_order(release))
287
+ #define mi_atomic_storei64_relaxed(p,x) mi_atomic(storei64_explicit)(p,x,mi_memory_order(relaxed))
288
+
289
+
290
+ #endif
291
+
292
+
293
+ // Atomically add a signed value; returns the previous value.
294
+ static inline intptr_t mi_atomic_addi(_Atomic(intptr_t)*p, intptr_t add) {
295
+ return (intptr_t)mi_atomic_add_acq_rel((_Atomic(uintptr_t)*)p, (uintptr_t)add);
296
+ }
297
+
298
+ // Atomically subtract a signed value; returns the previous value.
299
+ static inline intptr_t mi_atomic_subi(_Atomic(intptr_t)*p, intptr_t sub) {
300
+ return (intptr_t)mi_atomic_addi(p, -sub);
301
+ }
302
+
303
+ typedef _Atomic(uintptr_t) mi_atomic_once_t;
304
+
305
+ // Returns true only on the first invocation
306
+ static inline bool mi_atomic_once( mi_atomic_once_t* once ) {
307
+ if (mi_atomic_load_relaxed(once) != 0) return false; // quick test
308
+ uintptr_t expected = 0;
309
+ return mi_atomic_cas_strong_acq_rel(once, &expected, (uintptr_t)1); // try to set to 1
310
+ }
311
+
312
+ typedef _Atomic(uintptr_t) mi_atomic_guard_t;
313
+
314
+ // Allows only one thread to execute at a time
315
+ #define mi_atomic_guard(guard) \
316
+ uintptr_t _mi_guard_expected = 0; \
317
+ for(bool _mi_guard_once = true; \
318
+ _mi_guard_once && mi_atomic_cas_strong_acq_rel(guard,&_mi_guard_expected,(uintptr_t)1); \
319
+ (mi_atomic_store_release(guard,(uintptr_t)0), _mi_guard_once = false) )
320
+
321
+
322
+
323
+ // Yield
324
+ #if defined(__cplusplus)
325
+ #include <thread>
326
+ static inline void mi_atomic_yield(void) {
327
+ std::this_thread::yield();
328
+ }
329
+ #elif defined(_WIN32)
330
+ #define WIN32_LEAN_AND_MEAN
331
+ #include <windows.h>
332
+ static inline void mi_atomic_yield(void) {
333
+ YieldProcessor();
334
+ }
335
+ #elif defined(__SSE2__)
336
+ #include <emmintrin.h>
337
+ static inline void mi_atomic_yield(void) {
338
+ _mm_pause();
339
+ }
340
+ #elif (defined(__GNUC__) || defined(__clang__)) && \
341
+ (defined(__x86_64__) || defined(__i386__) || \
342
+ defined(__aarch64__) || defined(__arm__) || \
343
+ defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) || defined(__POWERPC__))
344
+ #if defined(__x86_64__) || defined(__i386__)
345
+ static inline void mi_atomic_yield(void) {
346
+ __asm__ volatile ("pause" ::: "memory");
347
+ }
348
+ #elif defined(__aarch64__)
349
+ static inline void mi_atomic_yield(void) {
350
+ __asm__ volatile("wfe");
351
+ }
352
+ #elif defined(__arm__)
353
+ #if __ARM_ARCH >= 7
354
+ static inline void mi_atomic_yield(void) {
355
+ __asm__ volatile("yield" ::: "memory");
356
+ }
357
+ #else
358
+ static inline void mi_atomic_yield(void) {
359
+ __asm__ volatile ("nop" ::: "memory");
360
+ }
361
+ #endif
362
+ #elif defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) || defined(__POWERPC__)
363
+ #ifdef __APPLE__
364
+ static inline void mi_atomic_yield(void) {
365
+ __asm__ volatile ("or r27,r27,r27" ::: "memory");
366
+ }
367
+ #else
368
+ static inline void mi_atomic_yield(void) {
369
+ __asm__ __volatile__ ("or 27,27,27" ::: "memory");
370
+ }
371
+ #endif
372
+ #endif
373
+ #elif defined(__sun)
374
+ // Fallback for other archs
375
+ #include <synch.h>
376
+ static inline void mi_atomic_yield(void) {
377
+ smt_pause();
378
+ }
379
+ #elif defined(__wasi__)
380
+ #include <sched.h>
381
+ static inline void mi_atomic_yield(void) {
382
+ sched_yield();
383
+ }
384
+ #else
385
+ #include <unistd.h>
386
+ static inline void mi_atomic_yield(void) {
387
+ sleep(0);
388
+ }
389
+ #endif
390
+
391
+
392
+ #endif // __MIMALLOC_ATOMIC_H