tpy-lang 0.3.0.dev0__py3-none-any.whl

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 (333) hide show
  1. tpy_lang-0.3.0.dev0.dist-info/METADATA +151 -0
  2. tpy_lang-0.3.0.dev0.dist-info/RECORD +333 -0
  3. tpy_lang-0.3.0.dev0.dist-info/WHEEL +4 -0
  4. tpy_lang-0.3.0.dev0.dist-info/entry_points.txt +3 -0
  5. tpyc/__init__.py +104 -0
  6. tpyc/__main__.py +6 -0
  7. tpyc/_buildinfo.py +1 -0
  8. tpyc/_data/docs/LANGUAGE_FEATURES.md +6278 -0
  9. tpyc/_data/docs/STDLIB_ROADMAP.md +1258 -0
  10. tpyc/_data/docs/TPY_FOR_AGENTS.md +556 -0
  11. tpyc/_data/lib/tpy/_bindings/__init__.py +6 -0
  12. tpyc/_data/lib/tpy/_bindings/pcre2.py +173 -0
  13. tpyc/_data/lib/tpy/_bindings/posix_socket.py +161 -0
  14. tpyc/_data/lib/tpy/_functools_macros.py +80 -0
  15. tpyc/_data/lib/tpy/_macro_helpers.py +161 -0
  16. tpyc/_data/lib/tpy/argparse.py +2062 -0
  17. tpyc/_data/lib/tpy/asyncio/__init__.py +744 -0
  18. tpyc/_data/lib/tpy/asyncio/_executor.py +515 -0
  19. tpyc/_data/lib/tpy/base64.py +410 -0
  20. tpyc/_data/lib/tpy/bisect.py +39 -0
  21. tpyc/_data/lib/tpy/builtins.py +38 -0
  22. tpyc/_data/lib/tpy/dataclasses.py +354 -0
  23. tpyc/_data/lib/tpy/enum.py +23 -0
  24. tpyc/_data/lib/tpy/functools.py +33 -0
  25. tpyc/_data/lib/tpy/hashlib.py +206 -0
  26. tpyc/_data/lib/tpy/heapq.py +118 -0
  27. tpyc/_data/lib/tpy/io.py +395 -0
  28. tpyc/_data/lib/tpy/json.py +221 -0
  29. tpyc/_data/lib/tpy/math.py +406 -0
  30. tpyc/_data/lib/tpy/random.py +597 -0
  31. tpyc/_data/lib/tpy/re.py +467 -0
  32. tpyc/_data/lib/tpy/socket.py +379 -0
  33. tpyc/_data/lib/tpy/struct.py +178 -0
  34. tpyc/_data/lib/tpy/sys.py +40 -0
  35. tpyc/_data/lib/tpy/time.py +39 -0
  36. tpyc/_data/lib/tpy/tpy/__init__.py +78 -0
  37. tpyc/_data/lib/tpy/tpy/_bootstrap/__init__.py +10 -0
  38. tpyc/_data/lib/tpy/tpy/_bootstrap/_decorators.py +37 -0
  39. tpyc/_data/lib/tpy/tpy/_bootstrap/_extern.py +64 -0
  40. tpyc/_data/lib/tpy/tpy/_builtins/__init__.py +11 -0
  41. tpyc/_data/lib/tpy/tpy/_builtins/_bytes.py +378 -0
  42. tpyc/_data/lib/tpy/tpy/_builtins/_dict.py +151 -0
  43. tpyc/_data/lib/tpy/tpy/_builtins/_exceptions.py +125 -0
  44. tpyc/_data/lib/tpy/tpy/_builtins/_funcs.py +681 -0
  45. tpyc/_data/lib/tpy/tpy/_builtins/_io.py +97 -0
  46. tpyc/_data/lib/tpy/tpy/_builtins/_list.py +127 -0
  47. tpyc/_data/lib/tpy/tpy/_builtins/_range.py +52 -0
  48. tpyc/_data/lib/tpy/tpy/_builtins/_set.py +139 -0
  49. tpyc/_data/lib/tpy/tpy/_builtins/_super.py +11 -0
  50. tpyc/_data/lib/tpy/tpy/_builtins/_types.py +661 -0
  51. tpyc/_data/lib/tpy/tpy/_core/__init__.py +23 -0
  52. tpyc/_data/lib/tpy/tpy/_core/_bytes_view.py +129 -0
  53. tpyc/_data/lib/tpy/tpy/_core/_containers.py +137 -0
  54. tpyc/_data/lib/tpy/tpy/_core/_functions.py +40 -0
  55. tpyc/_data/lib/tpy/tpy/_core/_types.py +2061 -0
  56. tpyc/_data/lib/tpy/tpy/_typing/__init__.py +77 -0
  57. tpyc/_data/lib/tpy/tpy/_version.py +29 -0
  58. tpyc/_data/lib/tpy/tpy/bits.py +28 -0
  59. tpyc/_data/lib/tpy/tpy/coro/__init__.py +127 -0
  60. tpyc/_data/lib/tpy/tpy/extern.py +8 -0
  61. tpyc/_data/lib/tpy/tpy/mem.py +49 -0
  62. tpyc/_data/lib/tpy/tpy/unsafe.py +195 -0
  63. tpyc/_data/lib/tpy/tpy/version.py +21 -0
  64. tpyc/_data/lib/tpy/typing.py +13 -0
  65. tpyc/_data/runtime/cpp/include/tpy/any.hpp +461 -0
  66. tpyc/_data/runtime/cpp/include/tpy/as_ostream.hpp +117 -0
  67. tpyc/_data/runtime/cpp/include/tpy/async.hpp +76 -0
  68. tpyc/_data/runtime/cpp/include/tpy/bigint.hpp +1343 -0
  69. tpyc/_data/runtime/cpp/include/tpy/builtins.hpp +400 -0
  70. tpyc/_data/runtime/cpp/include/tpy/bytes_ops.hpp +469 -0
  71. tpyc/_data/runtime/cpp/include/tpy/container_ops.hpp +487 -0
  72. tpyc/_data/runtime/cpp/include/tpy/copy_iter.hpp +82 -0
  73. tpyc/_data/runtime/cpp/include/tpy/core.hpp +558 -0
  74. tpyc/_data/runtime/cpp/include/tpy/dict_ops.hpp +289 -0
  75. tpyc/_data/runtime/cpp/include/tpy/dunder.hpp +750 -0
  76. tpyc/_data/runtime/cpp/include/tpy/dynamic.hpp +44 -0
  77. tpyc/_data/runtime/cpp/include/tpy/enum.hpp +40 -0
  78. tpyc/_data/runtime/cpp/include/tpy/file.hpp +245 -0
  79. tpyc/_data/runtime/cpp/include/tpy/fixed_int.hpp +317 -0
  80. tpyc/_data/runtime/cpp/include/tpy/format.hpp +954 -0
  81. tpyc/_data/runtime/cpp/include/tpy/frame_slot.hpp +120 -0
  82. tpyc/_data/runtime/cpp/include/tpy/generator.hpp +47 -0
  83. tpyc/_data/runtime/cpp/include/tpy/iterable_ops.hpp +122 -0
  84. tpyc/_data/runtime/cpp/include/tpy/itertools.hpp +749 -0
  85. tpyc/_data/runtime/cpp/include/tpy/next_iter.hpp +82 -0
  86. tpyc/_data/runtime/cpp/include/tpy/ordered_map.hpp +518 -0
  87. tpyc/_data/runtime/cpp/include/tpy/ordered_set.hpp +337 -0
  88. tpyc/_data/runtime/cpp/include/tpy/own_iter.hpp +54 -0
  89. tpyc/_data/runtime/cpp/include/tpy/pascal_graph_sdl.hpp +192 -0
  90. tpyc/_data/runtime/cpp/include/tpy/printing.hpp +302 -0
  91. tpyc/_data/runtime/cpp/include/tpy/protocols.hpp +61 -0
  92. tpyc/_data/runtime/cpp/include/tpy/range.hpp +115 -0
  93. tpyc/_data/runtime/cpp/include/tpy/ranges.hpp +212 -0
  94. tpyc/_data/runtime/cpp/include/tpy/set_ops.hpp +265 -0
  95. tpyc/_data/runtime/cpp/include/tpy/slice.hpp +47 -0
  96. tpyc/_data/runtime/cpp/include/tpy/span_iter.hpp +42 -0
  97. tpyc/_data/runtime/cpp/include/tpy/stdlib/math.hpp +41 -0
  98. tpyc/_data/runtime/cpp/include/tpy/stdlib/pcre2_h.hpp +96 -0
  99. tpyc/_data/runtime/cpp/include/tpy/stdlib/random.hpp +25 -0
  100. tpyc/_data/runtime/cpp/include/tpy/stdlib/socket_h.hpp +145 -0
  101. tpyc/_data/runtime/cpp/include/tpy/stdlib/time.hpp +62 -0
  102. tpyc/_data/runtime/cpp/include/tpy/system.hpp +121 -0
  103. tpyc/_data/runtime/cpp/include/tpy/throwable.hpp +55 -0
  104. tpyc/_data/runtime/cpp/include/tpy/tpy.hpp +156 -0
  105. tpyc/_data/runtime/cpp/include/tpy/type_name.hpp +77 -0
  106. tpyc/_data/runtime/cpp/include/tpy/type_traits.hpp +240 -0
  107. tpyc/_data/runtime/cpp/include/tpy/uninit_array_storage.hpp +250 -0
  108. tpyc/_data/runtime/cpp/include/tpy/uninit_heap_storage.hpp +277 -0
  109. tpyc/_data/runtime/cpp/include/tpy/varargs.hpp +174 -0
  110. tpyc/_data/runtime/cpp/include/tpy/variant_ref.hpp +118 -0
  111. tpyc/_data/runtime/cpp/src/stdlib/socket_impl.cpp +104 -0
  112. tpyc/_data/runtime/cpp/third_party/README.md +58 -0
  113. tpyc/_data/runtime/cpp/third_party/pcre2/AUTHORS +36 -0
  114. tpyc/_data/runtime/cpp/third_party/pcre2/CMakeLists.txt +1233 -0
  115. tpyc/_data/runtime/cpp/third_party/pcre2/COPYING +5 -0
  116. tpyc/_data/runtime/cpp/third_party/pcre2/ChangeLog +3097 -0
  117. tpyc/_data/runtime/cpp/third_party/pcre2/HACKING +853 -0
  118. tpyc/_data/runtime/cpp/third_party/pcre2/INSTALL +368 -0
  119. tpyc/_data/runtime/cpp/third_party/pcre2/LICENCE +94 -0
  120. tpyc/_data/runtime/cpp/third_party/pcre2/NEWS +492 -0
  121. tpyc/_data/runtime/cpp/third_party/pcre2/NON-AUTOTOOLS-BUILD +430 -0
  122. tpyc/_data/runtime/cpp/third_party/pcre2/README +956 -0
  123. tpyc/_data/runtime/cpp/third_party/pcre2/cmake/COPYING-CMAKE-SCRIPTS +22 -0
  124. tpyc/_data/runtime/cpp/third_party/pcre2/cmake/FindEditline.cmake +16 -0
  125. tpyc/_data/runtime/cpp/third_party/pcre2/cmake/FindPackageHandleStandardArgs.cmake +58 -0
  126. tpyc/_data/runtime/cpp/third_party/pcre2/cmake/FindReadline.cmake +29 -0
  127. tpyc/_data/runtime/cpp/third_party/pcre2/cmake/pcre2-config-version.cmake.in +15 -0
  128. tpyc/_data/runtime/cpp/third_party/pcre2/cmake/pcre2-config.cmake.in +148 -0
  129. tpyc/_data/runtime/cpp/third_party/pcre2/config-cmake.h.in +56 -0
  130. tpyc/_data/runtime/cpp/third_party/pcre2/libpcre2-16.pc.in +13 -0
  131. tpyc/_data/runtime/cpp/third_party/pcre2/libpcre2-32.pc.in +13 -0
  132. tpyc/_data/runtime/cpp/third_party/pcre2/libpcre2-8.pc.in +13 -0
  133. tpyc/_data/runtime/cpp/third_party/pcre2/libpcre2-posix.pc.in +13 -0
  134. tpyc/_data/runtime/cpp/third_party/pcre2/pcre2-config.in +121 -0
  135. tpyc/_data/runtime/cpp/third_party/pcre2/src/config.h +483 -0
  136. tpyc/_data/runtime/cpp/third_party/pcre2/src/config.h.generic +483 -0
  137. tpyc/_data/runtime/cpp/third_party/pcre2/src/config.h.in +460 -0
  138. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2.h +1010 -0
  139. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2.h.generic +1010 -0
  140. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2.h.in +1010 -0
  141. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_auto_possess.c +1371 -0
  142. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_chartables.c +196 -0
  143. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_chartables.c.dist +196 -0
  144. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_chkdint.c +96 -0
  145. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_compile.c +11001 -0
  146. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_config.c +252 -0
  147. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_context.c +510 -0
  148. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_convert.c +1189 -0
  149. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_dfa_match.c +4119 -0
  150. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_dftables.c +297 -0
  151. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_error.c +345 -0
  152. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_extuni.c +162 -0
  153. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_find_bracket.c +219 -0
  154. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_fuzzsupport.c +792 -0
  155. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_internal.h +2084 -0
  156. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_intmodedep.h +940 -0
  157. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_jit_compile.c +14972 -0
  158. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_jit_match.c +200 -0
  159. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_jit_misc.c +234 -0
  160. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_jit_neon_inc.h +354 -0
  161. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_jit_simd_inc.h +2355 -0
  162. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_jit_test.c +2528 -0
  163. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_maketables.c +165 -0
  164. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_match.c +7777 -0
  165. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_match_data.c +185 -0
  166. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_newline.c +243 -0
  167. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_ord2utf.c +120 -0
  168. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_pattern_info.c +432 -0
  169. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_printint.c +886 -0
  170. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_script_run.c +344 -0
  171. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_serialize.c +286 -0
  172. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_string_utils.c +237 -0
  173. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_study.c +1915 -0
  174. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_substitute.c +1009 -0
  175. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_substring.c +550 -0
  176. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_tables.c +234 -0
  177. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_ucd.c +5460 -0
  178. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_ucp.h +396 -0
  179. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_ucptables.c +1533 -0
  180. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_valid_utf.c +398 -0
  181. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_xclass.c +308 -0
  182. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2demo.c +497 -0
  183. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2grep.c +4606 -0
  184. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2posix.c +425 -0
  185. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2posix.h +187 -0
  186. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2posix_test.c +209 -0
  187. tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2test.c +9708 -0
  188. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/allocator_src/sljitExecAllocatorApple.c +137 -0
  189. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/allocator_src/sljitExecAllocatorCore.c +327 -0
  190. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/allocator_src/sljitExecAllocatorFreeBSD.c +89 -0
  191. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/allocator_src/sljitExecAllocatorPosix.c +62 -0
  192. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/allocator_src/sljitExecAllocatorWindows.c +40 -0
  193. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/allocator_src/sljitProtExecAllocatorNetBSD.c +72 -0
  194. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/allocator_src/sljitProtExecAllocatorPosix.c +172 -0
  195. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/allocator_src/sljitWXExecAllocatorPosix.c +141 -0
  196. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/allocator_src/sljitWXExecAllocatorWindows.c +102 -0
  197. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitConfig.h +142 -0
  198. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitConfigCPU.h +188 -0
  199. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitConfigInternal.h +907 -0
  200. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitLir.c +3561 -0
  201. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitLir.h +2466 -0
  202. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativeARM_32.c +4636 -0
  203. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativeARM_64.c +3491 -0
  204. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativeARM_T2_32.c +4302 -0
  205. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativeLOONGARCH_64.c +3765 -0
  206. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativeMIPS_32.c +472 -0
  207. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativeMIPS_64.c +387 -0
  208. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativeMIPS_common.c +4259 -0
  209. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativePPC_32.c +485 -0
  210. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativePPC_64.c +719 -0
  211. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativePPC_common.c +3161 -0
  212. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativeRISCV_32.c +142 -0
  213. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativeRISCV_64.c +222 -0
  214. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativeRISCV_common.c +3121 -0
  215. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativeS390X.c +4526 -0
  216. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativeX86_32.c +1685 -0
  217. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativeX86_64.c +1398 -0
  218. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativeX86_common.c +5001 -0
  219. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitSerialize.c +516 -0
  220. tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitUtils.c +344 -0
  221. tpyc/_data/runtime/cpp/third_party/pcre2.sources.txt +54 -0
  222. tpyc/_data/runtime/cpp/third_party/pcre2.vendor.json +7 -0
  223. tpyc/build/__init__.py +7 -0
  224. tpyc/build/pcre2.py +122 -0
  225. tpyc/build/third_party.py +413 -0
  226. tpyc/cli.py +822 -0
  227. tpyc/codegen_cpp/__init__.py +18 -0
  228. tpyc/codegen_cpp/builtins.py +484 -0
  229. tpyc/codegen_cpp/context.py +2064 -0
  230. tpyc/codegen_cpp/expressions.py +5940 -0
  231. tpyc/codegen_cpp/functions.py +1913 -0
  232. tpyc/codegen_cpp/gen_async.py +3258 -0
  233. tpyc/codegen_cpp/gen_generators.py +657 -0
  234. tpyc/codegen_cpp/generator.py +2258 -0
  235. tpyc/codegen_cpp/match.py +1997 -0
  236. tpyc/codegen_cpp/param_const.py +172 -0
  237. tpyc/codegen_cpp/protocols.py +907 -0
  238. tpyc/codegen_cpp/records.py +1654 -0
  239. tpyc/codegen_cpp/resumable_cfg.py +1651 -0
  240. tpyc/codegen_cpp/statements.py +4963 -0
  241. tpyc/codegen_cpp/string_dispatch.py +76 -0
  242. tpyc/codegen_cpp/test_context.py +46 -0
  243. tpyc/codegen_cpp/test_param_const.py +113 -0
  244. tpyc/codegen_cpp/test_resumable_cfg.py +182 -0
  245. tpyc/codegen_cpp/type_resolution.py +53 -0
  246. tpyc/codegen_cpp/types.py +436 -0
  247. tpyc/codegen_cpp/variant_access.py +135 -0
  248. tpyc/coercions.py +749 -0
  249. tpyc/compilation_context.py +57 -0
  250. tpyc/compiler.py +3945 -0
  251. tpyc/cycle_detection.py +358 -0
  252. tpyc/diagnostics.py +135 -0
  253. tpyc/dump_types.py +353 -0
  254. tpyc/frontend_diagnostics.py +47 -0
  255. tpyc/frontend_ir/__init__.py +140 -0
  256. tpyc/frontend_ir/lower.py +1098 -0
  257. tpyc/frontend_ir/nodes.py +718 -0
  258. tpyc/frontend_ir/resolver_adapter.py +151 -0
  259. tpyc/frontend_plugin.py +209 -0
  260. tpyc/install_docs.py +81 -0
  261. tpyc/liveness.py +756 -0
  262. tpyc/macro_api.py +1724 -0
  263. tpyc/macro_loader.py +497 -0
  264. tpyc/module_names.py +64 -0
  265. tpyc/modules/__init__.py +31 -0
  266. tpyc/modules/defs.py +89 -0
  267. tpyc/modules/registry.py +36 -0
  268. tpyc/modules/resolver.py +192 -0
  269. tpyc/modules/type_resolution.py +629 -0
  270. tpyc/namespace.py +172 -0
  271. tpyc/parse/__init__.py +84 -0
  272. tpyc/parse/imports.py +490 -0
  273. tpyc/parse/nodes.py +1732 -0
  274. tpyc/parse/parser.py +4043 -0
  275. tpyc/parse/resolve_refs.py +466 -0
  276. tpyc/parse/type_resolver.py +1060 -0
  277. tpyc/prescan.py +254 -0
  278. tpyc/qnames.py +149 -0
  279. tpyc/repl.py +529 -0
  280. tpyc/repl_backends.py +848 -0
  281. tpyc/sema/__init__.py +21 -0
  282. tpyc/sema/analyzer.py +3625 -0
  283. tpyc/sema/bound_check.py +72 -0
  284. tpyc/sema/builder_trace.py +684 -0
  285. tpyc/sema/calls.py +5406 -0
  286. tpyc/sema/compatibility.py +2107 -0
  287. tpyc/sema/context.py +1243 -0
  288. tpyc/sema/expressions.py +3737 -0
  289. tpyc/sema/flow_facts.py +199 -0
  290. tpyc/sema/init_tracker.py +150 -0
  291. tpyc/sema/list_literals.py +69 -0
  292. tpyc/sema/literal_utils.py +27 -0
  293. tpyc/sema/local_deduction.py +1088 -0
  294. tpyc/sema/macros.py +179 -0
  295. tpyc/sema/match.py +1177 -0
  296. tpyc/sema/method_expansion.py +347 -0
  297. tpyc/sema/methods.py +2197 -0
  298. tpyc/sema/mutation_propagation.py +268 -0
  299. tpyc/sema/narrowing.py +857 -0
  300. tpyc/sema/numeric_lattice.py +160 -0
  301. tpyc/sema/operators.py +402 -0
  302. tpyc/sema/overloads.py +841 -0
  303. tpyc/sema/protocols.py +1209 -0
  304. tpyc/sema/reach_analysis.py +202 -0
  305. tpyc/sema/registration.py +3156 -0
  306. tpyc/sema/scope_tracker.py +193 -0
  307. tpyc/sema/statements.py +4426 -0
  308. tpyc/sema/type_ops.py +1879 -0
  309. tpyc/sema/value_range.py +181 -0
  310. tpyc/symbol_binding.py +259 -0
  311. tpyc/test_c3_mro.py +208 -0
  312. tpyc/test_cli_argv.py +52 -0
  313. tpyc/test_compiler.py +559 -0
  314. tpyc/test_contains_type_param.py +101 -0
  315. tpyc/test_cycle_detection.py +221 -0
  316. tpyc/test_dump_types.py +225 -0
  317. tpyc/test_install_docs.py +65 -0
  318. tpyc/test_local_cpp_form.py +135 -0
  319. tpyc/test_macro_loader.py +76 -0
  320. tpyc/test_method_expansion.py +254 -0
  321. tpyc/test_nominal_identity.py +182 -0
  322. tpyc/test_overloads.py +410 -0
  323. tpyc/test_parse.py +303 -0
  324. tpyc/test_parse_type_ref.py +506 -0
  325. tpyc/test_parse_version_info.py +58 -0
  326. tpyc/test_reach_analysis.py +72 -0
  327. tpyc/test_ref_type.py +216 -0
  328. tpyc/test_send_sync_substitution.py +276 -0
  329. tpyc/test_tuple_mutation_propagation.py +206 -0
  330. tpyc/test_type_def_registry.py +1729 -0
  331. tpyc/test_union_types.py +195 -0
  332. tpyc/type_def_registry.py +975 -0
  333. tpyc/typesys.py +5104 -0
@@ -0,0 +1,853 @@
1
+ Technical notes about PCRE2
2
+ ---------------------------
3
+
4
+ These are very rough technical notes that record potentially useful information
5
+ about PCRE2 internals. PCRE2 is a library based on the original PCRE library,
6
+ but with a revised (and incompatible) API. To avoid confusion, the original
7
+ library is referred to as PCRE1 below. For information about testing PCRE2, see
8
+ the pcre2test documentation and the comment at the head of the RunTest file.
9
+
10
+ PCRE1 releases were up to 8.3x when PCRE2 was developed, and later bug fix
11
+ releases carried on the 8.xx series, up to the final 8.45 release. PCRE2
12
+ releases started at 10.00 to avoid confusion with PCRE1.
13
+
14
+
15
+ Historical note 1
16
+ -----------------
17
+
18
+ Many years ago I implemented some regular expression functions to an algorithm
19
+ suggested by Martin Richards. The rather simple patterns were not Unix-like in
20
+ form, and were quite restricted in what they could do by comparison with Perl.
21
+ The interesting part about the algorithm was that the amount of space required
22
+ to hold the compiled form of an expression was known in advance. The code to
23
+ apply an expression did not operate by backtracking, as the original Henry
24
+ Spencer code and current PCRE2 and Perl code does, but instead checked all
25
+ possibilities simultaneously by keeping a list of current states and checking
26
+ all of them as it advanced through the subject string. In the terminology of
27
+ Jeffrey Friedl's book, it was a "DFA algorithm", though it was not a
28
+ traditional Finite State Machine (FSM). When the pattern was all used up, all
29
+ remaining states were possible matches, and the one matching the longest subset
30
+ of the subject string was chosen. This did not necessarily maximize the
31
+ individual wild portions of the pattern, as is expected in Unix and Perl-style
32
+ regular expressions.
33
+
34
+
35
+ Historical note 2
36
+ -----------------
37
+
38
+ By contrast, the code originally written by Henry Spencer (which was
39
+ subsequently heavily modified for Perl) compiles the expression twice: once in
40
+ a dummy mode in order to find out how much store will be needed, and then for
41
+ real. (The Perl version may or may not still do this; I'm talking about the
42
+ original library.) The execution function operates by backtracking and
43
+ maximizing (or, optionally, minimizing, in Perl) the amount of the subject that
44
+ matches individual wild portions of the pattern. This is an "NFA algorithm" in
45
+ Friedl's terminology.
46
+
47
+
48
+ OK, here's the real stuff
49
+ -------------------------
50
+
51
+ For the set of functions that formed the original PCRE1 library in 1997 (which
52
+ are unrelated to those mentioned above), I tried at first to invent an
53
+ algorithm that used an amount of store bounded by a multiple of the number of
54
+ characters in the pattern, to save on compiling time. However, because of the
55
+ greater complexity in Perl regular expressions, I couldn't do this, even though
56
+ the then current Perl 5.004 patterns were much simpler than those supported
57
+ nowadays. In any case, a first pass through the pattern is helpful for other
58
+ reasons.
59
+
60
+
61
+ Support for 16-bit and 32-bit data strings
62
+ -------------------------------------------
63
+
64
+ The PCRE2 library can be compiled in any combination of 8-bit, 16-bit or 32-bit
65
+ modes, creating up to three different libraries. In the description that
66
+ follows, the word "short" is used for a 16-bit data quantity, and the phrase
67
+ "code unit" is used for a quantity that is a byte in 8-bit mode, a short in
68
+ 16-bit mode and a 32-bit word in 32-bit mode. The names of PCRE2 functions are
69
+ given in generic form, without the _8, _16, or _32 suffix.
70
+
71
+
72
+ Computing the memory requirement: how it was
73
+ --------------------------------------------
74
+
75
+ Up to and including release 6.7, PCRE1 worked by running a very degenerate
76
+ first pass to calculate a maximum memory requirement, and then a second pass to
77
+ do the real compile - which might use a bit less than the predicted amount of
78
+ memory. The idea was that this would turn out faster than the Henry Spencer
79
+ code because the first pass is degenerate and the second pass can just store
80
+ stuff straight into memory, which it knows is big enough.
81
+
82
+
83
+ Computing the memory requirement: how it is
84
+ -------------------------------------------
85
+
86
+ By the time I was working on a potential 6.8 release, the degenerate first pass
87
+ had become very complicated and hard to maintain. Indeed one of the early
88
+ things I did for 6.8 was to fix Yet Another Bug in the memory computation. Then
89
+ I had a flash of inspiration as to how I could run the real compile function in
90
+ a "fake" mode that enables it to compute how much memory it would need, while
91
+ in most cases only ever using a small amount of working memory, and without too
92
+ many tests of the mode that might slow it down. So I refactored the compiling
93
+ functions to work this way. This got rid of about 600 lines of source and made
94
+ further maintenance and development easier. As this was such a major change, I
95
+ never released 6.8, instead upping the number to 7.0 (other quite major changes
96
+ were also present in the 7.0 release).
97
+
98
+ A side effect of this work was that the previous limit of 200 on the nesting
99
+ depth of parentheses was removed. However, there was a downside: compiling ran
100
+ more slowly than before (30% or more, depending on the pattern) because it now
101
+ did a full analysis of the pattern. My hope was that this would not be a big
102
+ issue, and in the event, nobody has commented on it.
103
+
104
+ At release 8.34, a limit on the nesting depth of parentheses was re-introduced
105
+ (default 250, settable at build time) so as to put a limit on the amount of
106
+ system stack used by the compile function, which uses recursive function calls
107
+ for nested parenthesized groups. This is a safety feature for environments with
108
+ small stacks where the patterns are provided by users.
109
+
110
+
111
+ Yet another pattern scan
112
+ ------------------------
113
+
114
+ History repeated itself for PCRE2 release 10.20. A number of bugs relating to
115
+ named subpatterns had been discovered by fuzzers. Most of these were related to
116
+ the handling of forward references when it was not known if the named group was
117
+ unique. (References to non-unique names use a different opcode and more
118
+ memory.) The use of duplicate group numbers (the (?| facility) also caused
119
+ issues.
120
+
121
+ To get around these problems I adopted a new approach by adding a third pass
122
+ over the pattern (really a "pre-pass"), which did nothing other than identify
123
+ all the named subpatterns and their corresponding group numbers. This means
124
+ that the actual compile (both the memory-computing dummy run and the real
125
+ compile) has full knowledge of group names and numbers throughout. Several
126
+ dozen lines of messy code were eliminated, though the new pre-pass was not
127
+ short. In particular, parsing and skipping over [] classes is complicated.
128
+
129
+ While working on 10.22 I realized that I could simplify yet again by moving
130
+ more of the parsing into the pre-pass, thus avoiding doing it in two places, so
131
+ after 10.22 was released, the code underwent yet another big refactoring. This
132
+ is how it is from 10.23 onwards:
133
+
134
+ The function called parse_regex() scans the pattern characters, parsing them
135
+ into literal data and meta characters. It converts escapes such as \x{123}
136
+ into literals, handles \Q...\E, and skips over comments and non-significant
137
+ white space. The result of the scanning is put into a vector of 32-bit unsigned
138
+ integers. Values less than 0x80000000 are literal data. Higher values represent
139
+ meta-characters. The top 16-bits of such values identify the meta-character,
140
+ and these are given names such as META_CAPTURE. The lower 16-bits are available
141
+ for data, for example, the capturing group number. The only situation in which
142
+ literal data values greater than 0x7fffffff can appear is when the 32-bit
143
+ library is running in non-UTF mode. This is handled by having a special
144
+ meta-character that is followed by the 32-bit data value.
145
+
146
+ The size of the parsed pattern vector, when auto-callouts are not enabled, is
147
+ bounded by the length of the pattern (with one exception). The code is written
148
+ so that each item in the pattern uses no more vector elements than the number
149
+ of code units in the item itself. The exception is the aforementioned large
150
+ 32-bit number handling. For this reason, 32-bit non-UTF patterns are scanned in
151
+ advance to check for such values. When auto-callouts are enabled, the generous
152
+ assumption is made that there will be a callout for each pattern code unit
153
+ (which of course is only actually true if all code units are literals) plus one
154
+ at the end. A default parsed pattern vector is defined on the system stack, to
155
+ minimize memory handling, but if this is not big enough, heap memory is used.
156
+
157
+ As before, the actual compiling function is run twice, the first time to
158
+ determine the amount of memory needed for the final compiled pattern. It
159
+ now processes the parsed pattern vector, not the pattern itself, although some
160
+ of the parsed items refer to strings in the pattern - for example, group
161
+ names. As escapes and comments have already been processed, the code is a bit
162
+ simpler than before.
163
+
164
+ Most errors can be diagnosed during the parsing scan. For those that cannot
165
+ (for example, "lookbehind assertion is not fixed length"), the parsed code
166
+ contains offsets into the pattern so that the actual compiling code can
167
+ report where errors are.
168
+
169
+
170
+ The elements of the parsed pattern vector
171
+ -----------------------------------------
172
+
173
+ The word "offset" below means a code unit offset into the pattern. When
174
+ PCRE2_SIZE (which is usually size_t) is no bigger than uint32_t, an offset is
175
+ stored in a single parsed pattern element. Otherwise (typically on 64-bit
176
+ systems) it occupies two elements. The following meta items occupy just one
177
+ element, with no data:
178
+
179
+ META_ACCEPT (*ACCEPT)
180
+ META_ASTERISK *
181
+ META_ASTERISK_PLUS *+
182
+ META_ASTERISK_QUERY *?
183
+ META_ATOMIC (?> start of atomic group
184
+ META_CIRCUMFLEX ^ metacharacter
185
+ META_CLASS [ start of non-empty class
186
+ META_CLASS_EMPTY [] empty class - only with PCRE2_ALLOW_EMPTY_CLASS
187
+ META_CLASS_EMPTY_NOT [^] negative empty class - ditto
188
+ META_CLASS_END ] end of non-empty class
189
+ META_CLASS_NOT [^ start non-empty negative class
190
+ META_COMMIT (*COMMIT) - no argument (see below for with argument)
191
+ META_COND_ASSERT (?(?assertion)
192
+ META_DOLLAR $ metacharacter
193
+ META_DOT . metacharacter
194
+ META_END End of pattern (this value is 0x80000000)
195
+ META_FAIL (*FAIL)
196
+ META_KET ) closing parenthesis
197
+ META_LOOKAHEAD (?= start of lookahead
198
+ META_LOOKAHEAD_NA (*napla: start of non-atomic lookahead
199
+ META_LOOKAHEADNOT (?! start of negative lookahead
200
+ META_NOCAPTURE (?: no capture parens
201
+ META_PLUS +
202
+ META_PLUS_PLUS ++
203
+ META_PLUS_QUERY +?
204
+ META_PRUNE (*PRUNE) - no argument (see below for with argument)
205
+ META_QUERY ?
206
+ META_QUERY_PLUS ?+
207
+ META_QUERY_QUERY ??
208
+ META_RANGE_ESCAPED hyphen in class range with at least one escape
209
+ META_RANGE_LITERAL hyphen in class range defined literally
210
+ META_SKIP (*SKIP) - no argument (see below for with argument)
211
+ META_THEN (*THEN) - no argument (see below for with argument)
212
+
213
+ The two RANGE values occur only in character classes. They are positioned
214
+ between two literals that define the start and end of the range. In an EBCDIC
215
+ environment it is necessary to know whether either of the range values was
216
+ specified as an escape. In an ASCII/Unicode environment the distinction is not
217
+ relevant.
218
+
219
+ The following have data in the lower 16 bits, and may be followed by other data
220
+ elements:
221
+
222
+ META_ALT | alternation
223
+ META_BACKREF back reference
224
+ META_CAPTURE start of capturing group
225
+ META_ESCAPE non-literal escape sequence
226
+ META_RECURSE recursion call
227
+
228
+ If the data for META_ALT is non-zero, it is inside a lookbehind, and the data
229
+ is the maximum length of its branch (see META_LOOKBEHIND below for more
230
+ detail).
231
+
232
+ META_BACKREF, META_CAPTURE, and META_RECURSE have the capture group number as
233
+ their data in the lower 16 bits of the element. META_RECURSE is followed by an
234
+ offset, for use in error messages.
235
+
236
+ META_BACKREF is followed by an offset if the back reference group number is 10
237
+ or more. The offsets of the first occurrences of references to groups whose
238
+ numbers are less than 10 are put in cb->small_ref_offset[] (only the first
239
+ occurrence is useful). On 64-bit systems this avoids using more than two parsed
240
+ pattern elements for items such as \3. The offset is used when an error occurs
241
+ because the reference is to a non-existent group.
242
+
243
+ META_ESCAPE has an ESC_xxx value as its data. For ESC_P and ESC_p, the next
244
+ element contains the 16-bit type and data property values, packed together.
245
+ ESC_g and ESC_k are used only for named references - numerical ones are turned
246
+ into META_RECURSE or META_BACKREF as appropriate. ESC_g and ESC_k are followed
247
+ by a length and an offset into the pattern to specify the name.
248
+
249
+ The following have one data item that follows in the next vector element:
250
+
251
+ META_BIGVALUE Next is a literal >= META_END
252
+ META_POSIX POSIX class item (data identifies the class)
253
+ META_POSIX_NEG negative POSIX class item (ditto)
254
+
255
+ The following are followed by a length element, then a number of character code
256
+ values (which should match with the length):
257
+
258
+ META_MARK (*MARK:xxxx)
259
+ META_COMMIT_ARG )*COMMIT:xxxx)
260
+ META_PRUNE_ARG (*PRUNE:xxx)
261
+ META_SKIP_ARG (*SKIP:xxxx)
262
+ META_THEN_ARG (*THEN:xxxx)
263
+
264
+ The following are followed by a length element, then an offset in the pattern
265
+ that identifies the name:
266
+
267
+ META_COND_NAME (?(<name>) or (?('name') or (?(name)
268
+ META_COND_RNAME (?(R&name)
269
+ META_COND_RNUMBER (?(Rdigits)
270
+ META_RECURSE_BYNAME (?&name)
271
+ META_BACKREF_BYNAME \k'name'
272
+
273
+ META_COND_RNUMBER is used for names that start with R and continue with digits,
274
+ because this is an ambiguous case. It could be a back reference to a group with
275
+ that name, or it could be a recursion test on a numbered group.
276
+
277
+ This one is followed by an offset, for use in error messages, then a number:
278
+
279
+ META_COND_NUMBER (?([+-]digits)
280
+
281
+ The following is followed just by an offset, for use in error messages:
282
+
283
+ META_COND_DEFINE (?(DEFINE)
284
+
285
+ The following are at first also followed just by an offset for use in error
286
+ messages. After the lengths of the branches of a lookbehind group have been
287
+ checked the error offset is no longer needed. The lower 16 bits of the main
288
+ word are now set to the maximum length of the first branch of the lookbehind
289
+ group, and the second word is set to the mimimum matching length for a
290
+ variable-length lookbehind group, or to LOOKBEHIND_MAX for a group whose
291
+ branches are all of fixed length. These values are used when generating
292
+ OP_REVERSE or OP_VREVERSE for the first branch. The miminum value is also used
293
+ for any subsequent branches because there is only room for one value (the
294
+ branch maximum length) in a META_ALT item.
295
+
296
+ META_LOOKBEHIND (?<= start of lookbehind
297
+ META_LOOKBEHIND_NA (*naplb: start of non-atomic lookbehind
298
+ META_LOOKBEHINDNOT (?<! start of negative lookbehind
299
+
300
+ The following are followed by two elements, the minimum and maximum. The
301
+ maximum value is limited to 65535 (MAX_REPEAT_COUNT). A maximum value of
302
+ "unlimited" is represented by REPEAT_UNLIMITED, which is bigger than it:
303
+
304
+ META_MINMAX {n,m} repeat
305
+ META_MINMAX_PLUS {n,m}+ repeat
306
+ META_MINMAX_QUERY {n,m}? repeat
307
+
308
+ This one is followed by two elements, giving the new option settings for the
309
+ main and extra options, respectively.
310
+
311
+ META_OPTIONS (?i) and friends
312
+
313
+ This one is followed by three elements. The first is 0 for '>' and 1 for '>=';
314
+ the next two are the major and minor numbers:
315
+
316
+ META_COND_VERSION (?(VERSION<op>x.y)
317
+
318
+ Callouts are converted into one of two items:
319
+
320
+ META_CALLOUT_NUMBER (?C with numerical argument
321
+ META_CALLOUT_STRING (?C with string argument
322
+
323
+ In both cases, the next two elements contain the offset and length of the next
324
+ item in the pattern. Then there is either one callout number, or a length and
325
+ an offset for the string argument. The length includes both delimiters.
326
+
327
+
328
+ Traditional matching function
329
+ -----------------------------
330
+
331
+ The "traditional", and original, matching function is called pcre2_match(), and
332
+ it implements an NFA algorithm, similar to the original Henry Spencer algorithm
333
+ and the way that Perl works. This is not surprising, since it is intended to be
334
+ as compatible with Perl as possible. This is the function most users of PCRE2
335
+ will use most of the time. If PCRE2 is compiled with just-in-time (JIT)
336
+ support, and studying a compiled pattern with JIT is successful, the JIT code
337
+ is run instead of the normal pcre2_match() code, but the result is the same.
338
+
339
+
340
+ Supplementary matching function
341
+ -------------------------------
342
+
343
+ There is also a supplementary matching function called pcre2_dfa_match(). This
344
+ implements a DFA matching algorithm that searches simultaneously for all
345
+ possible matches that start at one point in the subject string. (Going back to
346
+ my roots: see Historical Note 1 above.) This function intreprets the same
347
+ compiled pattern data as pcre2_match(); however, not all the facilities are
348
+ available, and those that are do not always work in quite the same way. See the
349
+ user documentation for details.
350
+
351
+ The algorithm that is used for pcre2_dfa_match() is not a traditional FSM,
352
+ because it may have a number of states active at one time. More work would be
353
+ needed at compile time to produce a traditional FSM where only one state is
354
+ ever active at once. I believe some other regex matchers work this way. JIT
355
+ support is not available for this kind of matching.
356
+
357
+
358
+ Changeable options
359
+ ------------------
360
+
361
+ The /i, /m, or /s options (PCRE2_CASELESS, PCRE2_MULTILINE, PCRE2_DOTALL) and
362
+ some others may be changed in the middle of patterns by items such as (?i).
363
+ Their processing is handled entirely at compile time by generating different
364
+ opcodes for the different settings. The runtime functions do not need to keep
365
+ track of an option's state.
366
+
367
+ PCRE2_DUPNAMES, PCRE2_EXTENDED, PCRE2_EXTENDED_MORE, and PCRE2_NO_AUTO_CAPTURE
368
+ are tracked and processed during the parsing pre-pass. The others are handled
369
+ from META_OPTIONS items during the main compile phase.
370
+
371
+
372
+ Format of compiled patterns
373
+ ---------------------------
374
+
375
+ The compiled form of a pattern is a vector of unsigned code units (bytes in
376
+ 8-bit mode, shorts in 16-bit mode, 32-bit words in 32-bit mode), containing
377
+ items of variable length. The first code unit in an item contains an opcode,
378
+ and the length of the item is either implicit in the opcode or contained in the
379
+ data that follows it.
380
+
381
+ In many cases listed below, LINK_SIZE data values are specified for offsets
382
+ within the compiled pattern. LINK_SIZE always specifies a number of bytes. The
383
+ default value for LINK_SIZE is 2, except for the 32-bit library, where it can
384
+ only be 4. The 8-bit library can be compiled to use 3-byte or 4-byte values,
385
+ and the 16-bit library can be compiled to use 4-byte values, though this
386
+ impairs performance. Specifying a LINK_SIZE larger than 2 for these libraries is
387
+ necessary only when patterns whose compiled length is greater than 65535 code
388
+ units are going to be processed. When a LINK_SIZE value uses more than one code
389
+ unit, the most significant unit is first.
390
+
391
+ In this description, we assume the "normal" compilation options. Data values
392
+ that are counts (e.g. quantifiers) are always two bytes long in 8-bit mode
393
+ (most significant byte first), and one code unit in 16-bit and 32-bit modes.
394
+
395
+
396
+ Opcodes with no following data
397
+ ------------------------------
398
+
399
+ These items are all just one unit long:
400
+
401
+ OP_END end of pattern
402
+ OP_ANY match any one character other than newline
403
+ OP_ALLANY match any one character, including newline
404
+ OP_ANYBYTE match any single code unit, even in UTF-8/16 mode
405
+ OP_SOD match start of data: \A
406
+ OP_SOM, start of match (subject + offset): \G
407
+ OP_SET_SOM, set start of match (\K)
408
+ OP_CIRC ^ (start of data)
409
+ OP_CIRCM ^ multiline mode (start of data or after newline)
410
+ OP_NOT_WORD_BOUNDARY \W
411
+ OP_WORD_BOUNDARY \w
412
+ OP_NOT_DIGIT \D
413
+ OP_DIGIT \d
414
+ OP_NOT_HSPACE \H
415
+ OP_HSPACE \h
416
+ OP_NOT_WHITESPACE \S
417
+ OP_WHITESPACE \s
418
+ OP_NOT_VSPACE \V
419
+ OP_VSPACE \v
420
+ OP_NOT_WORDCHAR \W
421
+ OP_WORDCHAR \w
422
+ OP_EODN match end of data or newline at end: \Z
423
+ OP_EOD match end of data: \z
424
+ OP_DOLL $ (end of data, or before final newline)
425
+ OP_DOLLM $ multiline mode (end of data or before newline)
426
+ OP_EXTUNI match an extended Unicode grapheme cluster
427
+ OP_ANYNL match any Unicode newline sequence
428
+
429
+ OP_ASSERT_ACCEPT )
430
+ OP_ACCEPT ) These are Perl 5.10's "backtracking control
431
+ OP_COMMIT ) verbs". If OP_ACCEPT is inside capturing
432
+ OP_FAIL ) parentheses, it may be preceded by one or more
433
+ OP_PRUNE ) OP_CLOSE, each followed by a number that
434
+ OP_SKIP ) indicates which parentheses must be closed.
435
+ OP_THEN )
436
+
437
+ OP_ASSERT_ACCEPT is used when (*ACCEPT) is encountered within an assertion.
438
+ This ends the assertion, not the entire pattern match. The assertion (?!) is
439
+ always optimized to OP_FAIL.
440
+
441
+ OP_ALLANY is used for '.' when PCRE2_DOTALL is set. It is also used for \C in
442
+ non-UTF modes and in UTF-32 mode (since one code unit still equals one
443
+ character). Another use is for [^] when empty classes are permitted
444
+ (PCRE2_ALLOW_EMPTY_CLASS is set).
445
+
446
+
447
+ Backtracking control verbs
448
+ --------------------------
449
+
450
+ Verbs with no arguments generate opcodes with no following data (as listed
451
+ in the section above).
452
+
453
+ (*MARK:NAME) generates OP_MARK followed by the mark name, preceded by a
454
+ length in one code unit, and followed by a binary zero. The name length is
455
+ limited by the size of the code unit.
456
+
457
+ (*ACCEPT:NAME) and (*FAIL:NAME) are compiled as (*MARK:NAME)(*ACCEPT) and
458
+ (*MARK:NAME)(*FAIL) respectively.
459
+
460
+ For (*COMMIT:NAME), (*PRUNE:NAME), (*SKIP:NAME), and (*THEN:NAME), the opcodes
461
+ OP_COMMIT_ARG, OP_PRUNE_ARG, OP_SKIP_ARG, and OP_THEN_ARG are used, with the
462
+ name following in the same format as for OP_MARK.
463
+
464
+
465
+ Matching literal characters
466
+ ---------------------------
467
+
468
+ The OP_CHAR opcode is followed by a single character that is to be matched
469
+ casefully. For caseless matching of characters that have at most two
470
+ case-equivalent code points, OP_CHARI is used. In UTF-8 or UTF-16 modes, the
471
+ character may be more than one code unit long. In UTF-32 mode, characters are
472
+ always exactly one code unit long.
473
+
474
+ If there is only one character in a character class, OP_CHAR or OP_CHARI is
475
+ used for a positive class, and OP_NOT or OP_NOTI for a negative one (that is,
476
+ for something like [^a]).
477
+
478
+ Caseless matching (positive or negative) of characters that have more than two
479
+ case-equivalent code points (which is possible only in UTF mode) is handled by
480
+ compiling a Unicode property item (see below), with the pseudo-property
481
+ PT_CLIST. The value of this property is an offset in a vector called
482
+ "ucd_caseless_sets" which identifies the start of a short list of case
483
+ equivalent characters, terminated by the value NOTACHAR (0xffffffff).
484
+
485
+
486
+ Repeating single characters
487
+ ---------------------------
488
+
489
+ The common repeats (*, +, ?), when applied to a single character, use the
490
+ following opcodes, which come in caseful and caseless versions:
491
+
492
+ Caseful Caseless
493
+ OP_STAR OP_STARI
494
+ OP_MINSTAR OP_MINSTARI
495
+ OP_POSSTAR OP_POSSTARI
496
+ OP_PLUS OP_PLUSI
497
+ OP_MINPLUS OP_MINPLUSI
498
+ OP_POSPLUS OP_POSPLUSI
499
+ OP_QUERY OP_QUERYI
500
+ OP_MINQUERY OP_MINQUERYI
501
+ OP_POSQUERY OP_POSQUERYI
502
+
503
+ Each opcode is followed by the character that is to be repeated. In ASCII or
504
+ UTF-32 modes, these are two-code-unit items; in UTF-8 or UTF-16 modes, the
505
+ length is variable. Those with "MIN" in their names are the minimizing
506
+ versions. Those with "POS" in their names are possessive versions. Other kinds
507
+ of repeat make use of these opcodes:
508
+
509
+ Caseful Caseless
510
+ OP_UPTO OP_UPTOI
511
+ OP_MINUPTO OP_MINUPTOI
512
+ OP_POSUPTO OP_POSUPTOI
513
+ OP_EXACT OP_EXACTI
514
+
515
+ Each of these is followed by a count and then the repeated character. The count
516
+ is two bytes long in 8-bit mode (most significant byte first), or one code unit
517
+ in 16-bit and 32-bit modes.
518
+
519
+ OP_UPTO matches from 0 to the given number. A repeat with a non-zero minimum
520
+ and a fixed maximum is coded as an OP_EXACT followed by an OP_UPTO (or
521
+ OP_MINUPTO or OPT_POSUPTO).
522
+
523
+ Another set of matching repeating opcodes (called OP_NOTSTAR, OP_NOTSTARI,
524
+ etc.) are used for repeated, negated, single-character classes such as [^a]*.
525
+ The normal single-character opcodes (OP_STAR, etc.) are used for repeated
526
+ positive single-character classes.
527
+
528
+
529
+ Repeating character types
530
+ -------------------------
531
+
532
+ Repeats of things like \d are done exactly as for single characters, except
533
+ that instead of a character, the opcode for the type (e.g. OP_DIGIT) is stored
534
+ in the next code unit. The opcodes are:
535
+
536
+ OP_TYPESTAR
537
+ OP_TYPEMINSTAR
538
+ OP_TYPEPOSSTAR
539
+ OP_TYPEPLUS
540
+ OP_TYPEMINPLUS
541
+ OP_TYPEPOSPLUS
542
+ OP_TYPEQUERY
543
+ OP_TYPEMINQUERY
544
+ OP_TYPEPOSQUERY
545
+ OP_TYPEUPTO
546
+ OP_TYPEMINUPTO
547
+ OP_TYPEPOSUPTO
548
+ OP_TYPEEXACT
549
+
550
+
551
+ Match by Unicode property
552
+ -------------------------
553
+
554
+ OP_PROP and OP_NOTPROP are used for positive and negative matches of a
555
+ character by testing its Unicode property (the \p and \P escape sequences).
556
+ Each is followed by two code units that encode the desired property as a type
557
+ and a value. The types are a set of #defines of the form PT_xxx, and the values
558
+ are enumerations of the form ucp_xx, defined in the pcre2_ucp.h source file.
559
+ The value is relevant only for PT_GC (General Category), PT_PC (Particular
560
+ Category), PT_SC (Script), PT_BIDICL (Bidi Class), PT_BOOL (Boolean property),
561
+ and the pseudo-property PT_CLIST, which is used to identify a list of
562
+ case-equivalent characters when there are three or more (see above).
563
+
564
+ Repeats of these items use the OP_TYPESTAR etc. set of opcodes, followed by
565
+ three code units: OP_PROP or OP_NOTPROP, and then the desired property type and
566
+ value.
567
+
568
+
569
+ Character classes
570
+ -----------------
571
+
572
+ If there is only one character in a class, OP_CHAR or OP_CHARI is used for a
573
+ positive class, and OP_NOT or OP_NOTI for a negative one (that is, for
574
+ something like [^a]), except when caselessly matching a character that has more
575
+ than two case-equivalent code points (which can happen only in UTF mode). In
576
+ this case a Unicode property item is used, as described above in "Matching
577
+ literal characters".
578
+
579
+ A set of repeating opcodes (called OP_NOTSTAR etc.) are used for repeated,
580
+ negated, single-character classes. The normal single-character opcodes
581
+ (OP_STAR, etc.) are used for repeated positive single-character classes.
582
+
583
+ When there is more than one character in a class, and all the code points are
584
+ less than 256, OP_CLASS is used for a positive class, and OP_NCLASS for a
585
+ negative one. In either case, the opcode is followed by a 32-byte (16-short,
586
+ 8-word) bit map containing a 1 bit for every character that is acceptable. The
587
+ bits are counted from the least significant end of each unit. In caseless mode,
588
+ bits for both cases are set.
589
+
590
+ The reason for having both OP_CLASS and OP_NCLASS is so that, in UTF-8 and
591
+ 16-bit and 32-bit modes, subject characters with values greater than 255 can be
592
+ handled correctly. For OP_CLASS they do not match, whereas for OP_NCLASS they
593
+ do.
594
+
595
+ For classes containing characters with values greater than 255 or that contain
596
+ \p or \P, OP_XCLASS is used. It optionally uses a bit map if any acceptable
597
+ code points are less than 256, followed by a list of pairs (for a range) and/or
598
+ single characters and/or properties. In caseless mode, all equivalent
599
+ characters are explicitly listed.
600
+
601
+ OP_XCLASS is followed by a LINK_SIZE value containing the total length of the
602
+ opcode and its data. This is followed by a code unit containing flag bits:
603
+ XCL_NOT indicates that this is a negative class, and XCL_MAP indicates that a
604
+ bit map is present. There follows the bit map, if XCL_MAP is set, and then a
605
+ sequence of items coded as follows:
606
+
607
+ XCL_END marks the end of the list
608
+ XCL_SINGLE one character follows
609
+ XCL_RANGE two characters follow
610
+ XCL_PROP a Unicode property (type, value) follows
611
+ XCL_NOTPROP a Unicode property (type, value) follows
612
+
613
+ If a range starts with a code point less than 256 and ends with one greater
614
+ than 255, it is split into two ranges, with characters less than 256 being
615
+ indicated in the bit map, and the rest with XCL_RANGE.
616
+
617
+ When XCL_NOT is set, the bit map, if present, contains bits for characters that
618
+ are allowed (exactly as for OP_NCLASS), but the list of items that follow it
619
+ specifies characters and properties that are not allowed.
620
+
621
+
622
+ Back references
623
+ ---------------
624
+
625
+ OP_REF (caseful) or OP_REFI (caseless) is followed by a count containing the
626
+ reference number when the reference is to a unique capturing group (either by
627
+ number or by name). When named groups are used, there may be more than one
628
+ group with the same name. In this case, a reference to such a group by name
629
+ generates OP_DNREF or OP_DNREFI. These are followed by two counts: the index
630
+ (not the byte offset) in the group name table of the first entry for the
631
+ required name, followed by the number of groups with the same name. The
632
+ matching code can then search for the first one that is set.
633
+
634
+
635
+ Repeating character classes and back references
636
+ -----------------------------------------------
637
+
638
+ Single-character classes are handled specially (see above). This section
639
+ applies to other classes and also to back references. In both cases, the repeat
640
+ information follows the base item. The matching code looks at the following
641
+ opcode to see if it is one of these:
642
+
643
+ OP_CRSTAR
644
+ OP_CRMINSTAR
645
+ OP_CRPOSSTAR
646
+ OP_CRPLUS
647
+ OP_CRMINPLUS
648
+ OP_CRPOSPLUS
649
+ OP_CRQUERY
650
+ OP_CRMINQUERY
651
+ OP_CRPOSQUERY
652
+ OP_CRRANGE
653
+ OP_CRMINRANGE
654
+ OP_CRPOSRANGE
655
+
656
+ All but the last three are single-code-unit items, with no data. The range
657
+ opcodes are followed by the minimum and maximum repeat counts.
658
+
659
+
660
+ Brackets and alternation
661
+ ------------------------
662
+
663
+ A pair of non-capturing round brackets is wrapped round each expression at
664
+ compile time, so alternation always happens in the context of brackets.
665
+
666
+ [Note for North Americans: "bracket" to some English speakers, including
667
+ myself, can be round, square, curly, or pointy. Hence this usage rather than
668
+ "parentheses".]
669
+
670
+ Non-capturing brackets use the opcode OP_BRA, capturing brackets use OP_CBRA. A
671
+ bracket opcode is followed by a LINK_SIZE value which gives the offset to the
672
+ next alternative OP_ALT or, if there aren't any branches, to the terminating
673
+ opcode. Each OP_ALT is followed by a LINK_SIZE value giving the offset to the
674
+ next one, or to the final opcode. For capturing brackets, the bracket number is
675
+ a count that immediately follows the offset.
676
+
677
+ There are several opcodes that mark the end of a subpattern group. OP_KET is
678
+ used for subpatterns that do not repeat indefinitely, OP_KETRMIN and
679
+ OP_KETRMAX are used for indefinite repetitions, minimally or maximally
680
+ respectively, and OP_KETRPOS for possessive repetitions (see below for more
681
+ details). All four are followed by a LINK_SIZE value giving (as a positive
682
+ number) the offset back to the matching opening bracket opcode.
683
+
684
+ If a subpattern is quantified such that it is permitted to match zero times, it
685
+ is preceded by one of OP_BRAZERO, OP_BRAMINZERO, or OP_SKIPZERO. These are
686
+ single-unit opcodes that tell the matcher that skipping the following
687
+ subpattern entirely is a valid match. In the case of the first two, not
688
+ skipping the pattern is also valid (greedy and non-greedy). The third is used
689
+ when a pattern has the quantifier {0,0}. It cannot be entirely discarded,
690
+ because it may be called as a subroutine from elsewhere in the pattern.
691
+
692
+ A subpattern with an indefinite maximum repetition is replicated in the
693
+ compiled data its minimum number of times (or once with OP_BRAZERO if the
694
+ minimum is zero), with the final copy terminating with OP_KETRMIN or OP_KETRMAX
695
+ as appropriate.
696
+
697
+ A subpattern with a bounded maximum repetition is replicated in a nested
698
+ fashion up to the maximum number of times, with OP_BRAZERO or OP_BRAMINZERO
699
+ before each replication after the minimum, so that, for example, (abc){2,5} is
700
+ compiled as (abc)(abc)((abc)((abc)(abc)?)?)?, except that each bracketed group
701
+ has the same number.
702
+
703
+ When a repeated subpattern has an unbounded upper limit, it is checked to see
704
+ whether it could match an empty string. If this is the case, the opcode in the
705
+ final replication is changed to OP_SBRA or OP_SCBRA. This tells the matcher
706
+ that it needs to check for matching an empty string when it hits OP_KETRMIN or
707
+ OP_KETRMAX, and if so, to break the loop.
708
+
709
+
710
+ Possessive brackets
711
+ -------------------
712
+
713
+ When a repeated group (capturing or non-capturing) is marked as possessive by
714
+ the "+" notation, e.g. (abc)++, different opcodes are used. Their names all
715
+ have POS on the end, e.g. OP_BRAPOS instead of OP_BRA and OP_SCBRAPOS instead
716
+ of OP_SCBRA. The end of such a group is marked by OP_KETRPOS. If the minimum
717
+ repetition is zero, the group is preceded by OP_BRAPOSZERO.
718
+
719
+
720
+ Once-only (atomic) groups
721
+ -------------------------
722
+
723
+ These are just like other subpatterns, but they start with the opcode OP_ONCE.
724
+ The check for matching an empty string in an unbounded repeat is handled
725
+ entirely at runtime, so there is just this one opcode for atomic groups.
726
+
727
+
728
+ Assertions
729
+ ----------
730
+
731
+ Forward assertions are also just like other subpatterns, but starting with one
732
+ of the opcodes OP_ASSERT, OP_ASSERT_NA (non-atomic assertion), or
733
+ OP_ASSERT_NOT.
734
+
735
+ Backward assertions use the opcodes OP_ASSERTBACK, OP_ASSERTBACK_NA, and
736
+ OP_ASSERTBACK_NOT. If all the branches of a backward assertion are of fixed
737
+ length (not necessarily the same), the first opcode inside each branch is
738
+ OP_REVERSE, followed by an IMM2_SIZE count of the number of characters to move
739
+ back the pointer in the subject string, thus allowing each branch to have a
740
+ different (but fixed) length.
741
+
742
+ Variable-length backward assertions whose maximum matching length is limited
743
+ are also supported. For such assertions, the first opcode inside each branch is
744
+ OP_VREVERSE, followed by the minimum and maximum lengths for that branch,
745
+ unless these happen to be equal, in which case OP_REVERSE is used. These
746
+ IMM2_SIZE values occupy two code units each in 8-bit mode, and 1 code unit in
747
+ 16/32 bit modes.
748
+
749
+ In ASCII or UTF-32 mode, the character counts in OP_REVERSE and OP_VREVERSE are
750
+ also the number of code units, but in UTF-8/16 mode each character may occupy
751
+ more than one code unit.
752
+
753
+
754
+ Conditional subpatterns
755
+ -----------------------
756
+
757
+ These are like other subpatterns, but they start with the opcode OP_COND, or
758
+ OP_SCOND for one that might match an empty string in an unbounded repeat.
759
+
760
+ If the condition is a back reference, this is stored at the start of the
761
+ subpattern using the opcode OP_CREF followed by a count containing the
762
+ reference number, provided that the reference is to a unique capturing group.
763
+ If the reference was by name and there is more than one group with that name,
764
+ OP_DNCREF is used instead. It is followed by two counts: the index in the group
765
+ names table, and the number of groups with the same name. The allows the
766
+ matcher to check if any group with the given name is set.
767
+
768
+ If the condition is "in recursion" (coded as "(?(R)"), or "in recursion of
769
+ group x" (coded as "(?(Rx)"), the group number is stored at the start of the
770
+ subpattern using the opcode OP_RREF (with a value of RREF_ANY (0xffff) for "the
771
+ whole pattern") or OP_DNRREF (with data as for OP_DNCREF).
772
+
773
+ For a DEFINE condition, OP_FALSE is used (with no associated data). During
774
+ compilation, however, a DEFINE condition is coded as OP_DEFINE so that, when
775
+ the conditional group is complete, there can be a check to ensure that it
776
+ contains only one top-level branch. Once this has happened, the opcode is
777
+ changed to OP_FALSE, so the matcher never sees OP_DEFINE.
778
+
779
+ There is a special PCRE2-specific condition of the form (VERSION[>]=x.y), which
780
+ tests the PCRE2 version number. This compiles into one of the opcodes OP_TRUE
781
+ or OP_FALSE.
782
+
783
+ If a condition is not a back reference, recursion test, DEFINE, or VERSION, it
784
+ must start with a parenthesized atomic assertion, whose opcode normally
785
+ immediately follows OP_COND or OP_SCOND. However, if automatic callouts are
786
+ enabled, a callout is inserted immediately before the assertion. It is also
787
+ possible to insert a manual callout at this point. Only assertion conditions
788
+ may have callouts preceding the condition.
789
+
790
+ A condition that is the negative assertion (?!) is optimized to OP_FAIL in all
791
+ parts of the pattern, so this is another opcode that may appear as a condition.
792
+ It is treated the same as OP_FALSE.
793
+
794
+
795
+ Recursion
796
+ ---------
797
+
798
+ Recursion either matches the current pattern, or some subexpression. The opcode
799
+ OP_RECURSE is followed by a LINK_SIZE value that is the offset to the starting
800
+ bracket from the start of the whole pattern. OP_RECURSE is also used for
801
+ "subroutine" calls, even though they are not strictly a recursion. Up till
802
+ release 10.30 recursions were treated as atomic groups, making them
803
+ incompatible with Perl (but PCRE had them well before Perl did). From 10.30,
804
+ backtracking into recursions is supported.
805
+
806
+ Repeated recursions used to be wrapped inside OP_ONCE brackets, which not only
807
+ forced no backtracking, but also allowed repetition to be handled as for other
808
+ bracketed groups. From 10.30 onwards, repeated recursions are duplicated for
809
+ their minimum repetitions, and then wrapped in non-capturing brackets for the
810
+ remainder. For example, (?1){3} is treated as (?1)(?1)(?1), and (?1){2,4} is
811
+ treated as (?1)(?1)(?:(?1)){0,2}.
812
+
813
+
814
+ Callouts
815
+ --------
816
+
817
+ A callout may have either a numerical argument or a string argument. These use
818
+ OP_CALLOUT or OP_CALLOUT_STR, respectively. In each case these are followed by
819
+ two LINK_SIZE values giving the offset in the pattern string to the start of
820
+ the following item, and another count giving the length of this item. These
821
+ values make it possible for pcre2test to output useful tracing information
822
+ using callouts.
823
+
824
+ In the case of a numeric callout, after these two values there is a single code
825
+ unit containing the callout number, in the range 0-255, with 255 being used for
826
+ callouts that are automatically inserted as a result of the PCRE2_AUTO_CALLOUT
827
+ option. Thus, this opcode item is of fixed length:
828
+
829
+ [OP_CALLOUT] [PATTERN_OFFSET] [PATTERN_LENGTH] [NUMBER]
830
+
831
+ For callouts with string arguments, OP_CALLOUT_STR has three more data items:
832
+ a LINK_SIZE value giving the complete length of the entire opcode item, a
833
+ LINK_SIZE item containing the offset within the pattern string to the start of
834
+ the string argument, and the string itself, preceded by its starting delimiter
835
+ and followed by a binary zero. When a callout function is called, a pointer to
836
+ the actual string is passed, but the delimiter can be accessed as string[-1] if
837
+ the application needs it. In the 8-bit library, the callout in /X(?C'abc')Y/ is
838
+ compiled as the following bytes (decimal numbers represent binary values):
839
+
840
+ [OP_CALLOUT_STR] [0] [10] [0] [1] [0] [14] [0] [5] ['] [a] [b] [c] [0]
841
+ -------- ------- -------- -------
842
+ | | | |
843
+ ------- LINK_SIZE items ------
844
+
845
+ Opcode table checking
846
+ ---------------------
847
+
848
+ The last opcode that is defined in pcre2_internal.h is OP_TABLE_LENGTH. This is
849
+ not a real opcode, but is used to check at compile time that tables indexed by
850
+ opcode are the correct length, in order to catch updating errors.
851
+
852
+ Philip Hazel
853
+ November 2023