nimlang 0.0.1__py3-none-win_amd64.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 (384) hide show
  1. nimlang/__init__.py +30 -0
  2. nimlang/__main__.py +3 -0
  3. nimlang/_build.py +65 -0
  4. nimlang/_project.py +143 -0
  5. nimlang/_toolchain.py +206 -0
  6. nimlang/cli.py +173 -0
  7. nimlang/hatch_hook.py +118 -0
  8. nimlang/nim/bin/7-zip.dll +0 -0
  9. nimlang/nim/bin/7z.dll +0 -0
  10. nimlang/nim/bin/SDL2.dll +0 -0
  11. nimlang/nim/bin/SDL2_ttf.dll +0 -0
  12. nimlang/nim/bin/atlas.exe +0 -0
  13. nimlang/nim/bin/boehmgc.dll +0 -0
  14. nimlang/nim/bin/boehmgc64.dll +0 -0
  15. nimlang/nim/bin/cacert.pem +3228 -0
  16. nimlang/nim/bin/libcrypto-1_1-x64.dll +0 -0
  17. nimlang/nim/bin/libcrypto-1_1.dll +0 -0
  18. nimlang/nim/bin/libcurl.dll +0 -0
  19. nimlang/nim/bin/libpng12.dll +0 -0
  20. nimlang/nim/bin/libpng3.dll +0 -0
  21. nimlang/nim/bin/libssl-1_1-x64.dll +0 -0
  22. nimlang/nim/bin/libssl-1_1.dll +0 -0
  23. nimlang/nim/bin/libui.dll +0 -0
  24. nimlang/nim/bin/nim.exe +0 -0
  25. nimlang/nim/bin/nimble.exe +0 -0
  26. nimlang/nim/bin/nimgrep.exe +0 -0
  27. nimlang/nim/bin/nimpretty.exe +0 -0
  28. nimlang/nim/bin/nimsuggest.exe +0 -0
  29. nimlang/nim/bin/pcre.dll +0 -0
  30. nimlang/nim/bin/pcre3.dll +0 -0
  31. nimlang/nim/bin/pcre32.dll +0 -0
  32. nimlang/nim/bin/pcre64.dll +0 -0
  33. nimlang/nim/bin/pdcurses.dll +0 -0
  34. nimlang/nim/bin/pdcurses32.dll +0 -0
  35. nimlang/nim/bin/pdcurses64.dll +0 -0
  36. nimlang/nim/bin/png.dll +0 -0
  37. nimlang/nim/bin/sqlite3_32.dll +0 -0
  38. nimlang/nim/bin/sqlite3_64.dll +0 -0
  39. nimlang/nim/bin/zlib1.dll +0 -0
  40. nimlang/nim/config/config.nims +23 -0
  41. nimlang/nim/config/nim.cfg +366 -0
  42. nimlang/nim/config/nimdoc.cfg +264 -0
  43. nimlang/nim/config/nimdoc.tex.cfg +85 -0
  44. nimlang/nim/config/rename.rules.cfg +9 -0
  45. nimlang/nim/copying.txt +24 -0
  46. nimlang/nim/lib/arch/x86/amd64.S +96 -0
  47. nimlang/nim/lib/arch/x86/i386.S +64 -0
  48. nimlang/nim/lib/core/hotcodereloading.nim +41 -0
  49. nimlang/nim/lib/core/locks.nim +90 -0
  50. nimlang/nim/lib/core/macrocache.nim +249 -0
  51. nimlang/nim/lib/core/macros.nim +1818 -0
  52. nimlang/nim/lib/core/rlocks.nim +57 -0
  53. nimlang/nim/lib/core/typeinfo.nim +722 -0
  54. nimlang/nim/lib/cycle.h +514 -0
  55. nimlang/nim/lib/deprecated/pure/future.nim +6 -0
  56. nimlang/nim/lib/deprecated/pure/mersenne.nim +51 -0
  57. nimlang/nim/lib/deprecated/pure/ospaths.nim +22 -0
  58. nimlang/nim/lib/deprecated/pure/oswalkdir.nim +13 -0
  59. nimlang/nim/lib/deprecated/pure/sums.nim +80 -0
  60. nimlang/nim/lib/deps.txt +14 -0
  61. nimlang/nim/lib/experimental/diff.nim +340 -0
  62. nimlang/nim/lib/genode/alloc.nim +119 -0
  63. nimlang/nim/lib/genode/constructibles.nim +21 -0
  64. nimlang/nim/lib/genode/entrypoints.nim +22 -0
  65. nimlang/nim/lib/genode/env.nim +29 -0
  66. nimlang/nim/lib/genode/signals.nim +77 -0
  67. nimlang/nim/lib/genode_cpp/signals.h +39 -0
  68. nimlang/nim/lib/genode_cpp/syslocks.h +81 -0
  69. nimlang/nim/lib/genode_cpp/threads.h +73 -0
  70. nimlang/nim/lib/impure/nre/private/util.nim +51 -0
  71. nimlang/nim/lib/impure/nre.nim +772 -0
  72. nimlang/nim/lib/impure/rdstdin.nim +74 -0
  73. nimlang/nim/lib/impure/re.nim +611 -0
  74. nimlang/nim/lib/js/asyncjs.nim +269 -0
  75. nimlang/nim/lib/js/dom.nim +1843 -0
  76. nimlang/nim/lib/js/jsconsole.nim +125 -0
  77. nimlang/nim/lib/js/jscore.nim +153 -0
  78. nimlang/nim/lib/js/jsffi.nim +527 -0
  79. nimlang/nim/lib/js/jsre.nim +97 -0
  80. nimlang/nim/lib/nimbase.h +620 -0
  81. nimlang/nim/lib/nimhcr.nim +671 -0
  82. nimlang/nim/lib/nimhcr.nim.cfg +5 -0
  83. nimlang/nim/lib/nimrtl.nim +40 -0
  84. nimlang/nim/lib/nimrtl.nim.cfg +6 -0
  85. nimlang/nim/lib/packages/docutils/dochelpers.nim +298 -0
  86. nimlang/nim/lib/packages/docutils/docutils.nimble.old +7 -0
  87. nimlang/nim/lib/packages/docutils/highlite.nim +1041 -0
  88. nimlang/nim/lib/packages/docutils/rst.nim +3886 -0
  89. nimlang/nim/lib/packages/docutils/rstast.nim +444 -0
  90. nimlang/nim/lib/packages/docutils/rstgen.nim +1566 -0
  91. nimlang/nim/lib/packages/docutils/rstidx.nim +141 -0
  92. nimlang/nim/lib/posix/epoll.nim +99 -0
  93. nimlang/nim/lib/posix/inotify.nim +111 -0
  94. nimlang/nim/lib/posix/kqueue.nim +161 -0
  95. nimlang/nim/lib/posix/linux.nim +39 -0
  96. nimlang/nim/lib/posix/posix.nim +1195 -0
  97. nimlang/nim/lib/posix/posix_freertos_consts.nim +506 -0
  98. nimlang/nim/lib/posix/posix_haiku.nim +601 -0
  99. nimlang/nim/lib/posix/posix_linux_amd64.nim +585 -0
  100. nimlang/nim/lib/posix/posix_linux_amd64_consts.nim +730 -0
  101. nimlang/nim/lib/posix/posix_macos_amd64.nim +618 -0
  102. nimlang/nim/lib/posix/posix_nintendoswitch.nim +504 -0
  103. nimlang/nim/lib/posix/posix_nintendoswitch_consts.nim +587 -0
  104. nimlang/nim/lib/posix/posix_openbsd_amd64.nim +563 -0
  105. nimlang/nim/lib/posix/posix_other.nim +699 -0
  106. nimlang/nim/lib/posix/posix_other_consts.nim +757 -0
  107. nimlang/nim/lib/posix/posix_utils.nim +133 -0
  108. nimlang/nim/lib/posix/termios.nim +256 -0
  109. nimlang/nim/lib/pure/algorithm.nim +917 -0
  110. nimlang/nim/lib/pure/async.nim +9 -0
  111. nimlang/nim/lib/pure/asyncdispatch.nim +2066 -0
  112. nimlang/nim/lib/pure/asyncdispatch.nim.cfg +3 -0
  113. nimlang/nim/lib/pure/asyncfile.nim +537 -0
  114. nimlang/nim/lib/pure/asyncfutures.nim +516 -0
  115. nimlang/nim/lib/pure/asynchttpserver.nim +441 -0
  116. nimlang/nim/lib/pure/asyncmacro.nim +396 -0
  117. nimlang/nim/lib/pure/asyncnet.nim +1017 -0
  118. nimlang/nim/lib/pure/asyncstreams.nim +147 -0
  119. nimlang/nim/lib/pure/base64.nim +275 -0
  120. nimlang/nim/lib/pure/bitops.nim +883 -0
  121. nimlang/nim/lib/pure/browsers.nim +112 -0
  122. nimlang/nim/lib/pure/cgi.nim +320 -0
  123. nimlang/nim/lib/pure/collections/chains.nim +44 -0
  124. nimlang/nim/lib/pure/collections/critbits.nim +537 -0
  125. nimlang/nim/lib/pure/collections/deques.nim +486 -0
  126. nimlang/nim/lib/pure/collections/hashcommon.nim +76 -0
  127. nimlang/nim/lib/pure/collections/heapqueue.nim +266 -0
  128. nimlang/nim/lib/pure/collections/intsets.nim +23 -0
  129. nimlang/nim/lib/pure/collections/lists.nim +1017 -0
  130. nimlang/nim/lib/pure/collections/rtarrays.nim +37 -0
  131. nimlang/nim/lib/pure/collections/sequtils.nim +1228 -0
  132. nimlang/nim/lib/pure/collections/setimpl.nim +156 -0
  133. nimlang/nim/lib/pure/collections/sets.nim +930 -0
  134. nimlang/nim/lib/pure/collections/sharedlist.nim +105 -0
  135. nimlang/nim/lib/pure/collections/sharedtables.nim +252 -0
  136. nimlang/nim/lib/pure/collections/tableimpl.nim +231 -0
  137. nimlang/nim/lib/pure/collections/tables.nim +3024 -0
  138. nimlang/nim/lib/pure/colors.nim +507 -0
  139. nimlang/nim/lib/pure/complex.nim +473 -0
  140. nimlang/nim/lib/pure/concurrency/atomics.nim +433 -0
  141. nimlang/nim/lib/pure/concurrency/cpuinfo.nim +110 -0
  142. nimlang/nim/lib/pure/concurrency/cpuload.nim +106 -0
  143. nimlang/nim/lib/pure/concurrency/threadpool.nim +608 -0
  144. nimlang/nim/lib/pure/concurrency/threadpool.nim.cfg +1 -0
  145. nimlang/nim/lib/pure/cookies.nim +81 -0
  146. nimlang/nim/lib/pure/coro.nim +345 -0
  147. nimlang/nim/lib/pure/coro.nimcfg +1 -0
  148. nimlang/nim/lib/pure/cstrutils.nim +126 -0
  149. nimlang/nim/lib/pure/distros.nim +279 -0
  150. nimlang/nim/lib/pure/dynlib.nim +196 -0
  151. nimlang/nim/lib/pure/encodings.nim +511 -0
  152. nimlang/nim/lib/pure/endians.nim +148 -0
  153. nimlang/nim/lib/pure/fenv.nim +182 -0
  154. nimlang/nim/lib/pure/hashes.nim +777 -0
  155. nimlang/nim/lib/pure/htmlgen.nim +814 -0
  156. nimlang/nim/lib/pure/htmlparser.nim +2079 -0
  157. nimlang/nim/lib/pure/httpclient.nim +1443 -0
  158. nimlang/nim/lib/pure/httpcore.nim +370 -0
  159. nimlang/nim/lib/pure/includes/unicode_ranges.nim +2007 -0
  160. nimlang/nim/lib/pure/ioselects/ioselectors_epoll.nim +534 -0
  161. nimlang/nim/lib/pure/ioselects/ioselectors_kqueue.nim +639 -0
  162. nimlang/nim/lib/pure/ioselects/ioselectors_poll.nim +324 -0
  163. nimlang/nim/lib/pure/ioselects/ioselectors_select.nim +454 -0
  164. nimlang/nim/lib/pure/json.nim +1397 -0
  165. nimlang/nim/lib/pure/lenientops.nim +58 -0
  166. nimlang/nim/lib/pure/lexbase.nim +167 -0
  167. nimlang/nim/lib/pure/logging.nim +908 -0
  168. nimlang/nim/lib/pure/marshal.nim +367 -0
  169. nimlang/nim/lib/pure/math.nim +1388 -0
  170. nimlang/nim/lib/pure/md5.nim +335 -0
  171. nimlang/nim/lib/pure/memfiles.nim +567 -0
  172. nimlang/nim/lib/pure/mimetypes.nim +1071 -0
  173. nimlang/nim/lib/pure/nativesockets.nim +890 -0
  174. nimlang/nim/lib/pure/net.nim +2177 -0
  175. nimlang/nim/lib/pure/nimprof.nim +234 -0
  176. nimlang/nim/lib/pure/nimprof.nim.cfg +1 -0
  177. nimlang/nim/lib/pure/oids.nim +101 -0
  178. nimlang/nim/lib/pure/options.nim +381 -0
  179. nimlang/nim/lib/pure/os.nim +1041 -0
  180. nimlang/nim/lib/pure/osproc.nim +1582 -0
  181. nimlang/nim/lib/pure/parsecfg.nim +666 -0
  182. nimlang/nim/lib/pure/parsecsv.nim +361 -0
  183. nimlang/nim/lib/pure/parsejson.nim +522 -0
  184. nimlang/nim/lib/pure/parseopt.nim +522 -0
  185. nimlang/nim/lib/pure/parsesql.nim +1590 -0
  186. nimlang/nim/lib/pure/parseutils.nim +1104 -0
  187. nimlang/nim/lib/pure/parsexml.nim +824 -0
  188. nimlang/nim/lib/pure/pathnorm.nim +122 -0
  189. nimlang/nim/lib/pure/pegs.nim +2082 -0
  190. nimlang/nim/lib/pure/prelude.nim +28 -0
  191. nimlang/nim/lib/pure/random.nim +755 -0
  192. nimlang/nim/lib/pure/rationals.nim +340 -0
  193. nimlang/nim/lib/pure/reservedmem.nim +229 -0
  194. nimlang/nim/lib/pure/ropes.nim +400 -0
  195. nimlang/nim/lib/pure/segfaults.nim +88 -0
  196. nimlang/nim/lib/pure/selectors.nim +381 -0
  197. nimlang/nim/lib/pure/ssl_certs.nim +172 -0
  198. nimlang/nim/lib/pure/ssl_config.nim +51 -0
  199. nimlang/nim/lib/pure/stats.nim +338 -0
  200. nimlang/nim/lib/pure/streams.nim +1547 -0
  201. nimlang/nim/lib/pure/streamwrapper.nim +122 -0
  202. nimlang/nim/lib/pure/strformat.nim +788 -0
  203. nimlang/nim/lib/pure/strmisc.nim +83 -0
  204. nimlang/nim/lib/pure/strscans.nim +696 -0
  205. nimlang/nim/lib/pure/strtabs.nim +422 -0
  206. nimlang/nim/lib/pure/strutils.nim +3069 -0
  207. nimlang/nim/lib/pure/sugar.nim +429 -0
  208. nimlang/nim/lib/pure/terminal.nim +1032 -0
  209. nimlang/nim/lib/pure/times.nim +2896 -0
  210. nimlang/nim/lib/pure/typetraits.nim +376 -0
  211. nimlang/nim/lib/pure/unicode.nim +1523 -0
  212. nimlang/nim/lib/pure/unidecode/gen.py +30 -0
  213. nimlang/nim/lib/pure/unidecode/unidecode.dat +65408 -0
  214. nimlang/nim/lib/pure/unidecode/unidecode.nim +64 -0
  215. nimlang/nim/lib/pure/unittest.nim +835 -0
  216. nimlang/nim/lib/pure/uri.nim +573 -0
  217. nimlang/nim/lib/pure/volatile.nim +34 -0
  218. nimlang/nim/lib/pure/xmlparser.nim +178 -0
  219. nimlang/nim/lib/pure/xmltree.nim +949 -0
  220. nimlang/nim/lib/std/appdirs.nim +94 -0
  221. nimlang/nim/lib/std/assertions.nim +122 -0
  222. nimlang/nim/lib/std/cmdline.nim +311 -0
  223. nimlang/nim/lib/std/compilesettings.nim +71 -0
  224. nimlang/nim/lib/std/decls.nim +31 -0
  225. nimlang/nim/lib/std/dirs.nim +192 -0
  226. nimlang/nim/lib/std/editdistance.nim +266 -0
  227. nimlang/nim/lib/std/effecttraits.nim +66 -0
  228. nimlang/nim/lib/std/enumerate.nim +70 -0
  229. nimlang/nim/lib/std/enumutils.nim +202 -0
  230. nimlang/nim/lib/std/envvars.nim +224 -0
  231. nimlang/nim/lib/std/exitprocs.nim +87 -0
  232. nimlang/nim/lib/std/files.nim +164 -0
  233. nimlang/nim/lib/std/formatfloat.nim +147 -0
  234. nimlang/nim/lib/std/genasts.nim +89 -0
  235. nimlang/nim/lib/std/importutils.nim +44 -0
  236. nimlang/nim/lib/std/isolation.nim +49 -0
  237. nimlang/nim/lib/std/jsbigints.nim +228 -0
  238. nimlang/nim/lib/std/jsfetch.nim +202 -0
  239. nimlang/nim/lib/std/jsformdata.nim +69 -0
  240. nimlang/nim/lib/std/jsheaders.nim +83 -0
  241. nimlang/nim/lib/std/jsonutils.nim +495 -0
  242. nimlang/nim/lib/std/logic.nim +10 -0
  243. nimlang/nim/lib/std/monotimes.nim +160 -0
  244. nimlang/nim/lib/std/objectdollar.nim +13 -0
  245. nimlang/nim/lib/std/oserrors.nim +117 -0
  246. nimlang/nim/lib/std/outparams.nim +38 -0
  247. nimlang/nim/lib/std/packedsets.nim +601 -0
  248. nimlang/nim/lib/std/paths.nim +302 -0
  249. nimlang/nim/lib/std/private/asciitables.nim +84 -0
  250. nimlang/nim/lib/std/private/bitops_utils.nim +22 -0
  251. nimlang/nim/lib/std/private/decode_helpers.nim +42 -0
  252. nimlang/nim/lib/std/private/digitsutils.nim +116 -0
  253. nimlang/nim/lib/std/private/dragonbox.nim +1316 -0
  254. nimlang/nim/lib/std/private/gitutils.nim +75 -0
  255. nimlang/nim/lib/std/private/globs.nim +70 -0
  256. nimlang/nim/lib/std/private/jsutils.nim +103 -0
  257. nimlang/nim/lib/std/private/miscdollars.nim +39 -0
  258. nimlang/nim/lib/std/private/ntpath.nim +61 -0
  259. nimlang/nim/lib/std/private/osappdirs.nim +177 -0
  260. nimlang/nim/lib/std/private/oscommon.nim +176 -0
  261. nimlang/nim/lib/std/private/osdirs.nim +564 -0
  262. nimlang/nim/lib/std/private/osfiles.nim +414 -0
  263. nimlang/nim/lib/std/private/ospaths2.nim +1030 -0
  264. nimlang/nim/lib/std/private/osseps.nim +113 -0
  265. nimlang/nim/lib/std/private/ossymlinks.nim +77 -0
  266. nimlang/nim/lib/std/private/schubfach.nim +436 -0
  267. nimlang/nim/lib/std/private/since.nim +33 -0
  268. nimlang/nim/lib/std/private/strimpl.nim +111 -0
  269. nimlang/nim/lib/std/private/syslocks.nim +234 -0
  270. nimlang/nim/lib/std/private/threadtypes.nim +176 -0
  271. nimlang/nim/lib/std/private/underscored_calls.nim +56 -0
  272. nimlang/nim/lib/std/private/win_getsysteminfo.nim +15 -0
  273. nimlang/nim/lib/std/private/win_setenv.nim +106 -0
  274. nimlang/nim/lib/std/setutils.nim +105 -0
  275. nimlang/nim/lib/std/sha1.nim +287 -0
  276. nimlang/nim/lib/std/socketstreams.nim +183 -0
  277. nimlang/nim/lib/std/stackframes.nim +30 -0
  278. nimlang/nim/lib/std/staticos.nim +38 -0
  279. nimlang/nim/lib/std/strbasics.nim +119 -0
  280. nimlang/nim/lib/std/symlinks.nim +33 -0
  281. nimlang/nim/lib/std/syncio.nim +968 -0
  282. nimlang/nim/lib/std/sysatomics.nim +376 -0
  283. nimlang/nim/lib/std/sysrand.nim +327 -0
  284. nimlang/nim/lib/std/tasks.nim +312 -0
  285. nimlang/nim/lib/std/tempfiles.nim +193 -0
  286. nimlang/nim/lib/std/time_t.nim +23 -0
  287. nimlang/nim/lib/std/typedthreads.nim +305 -0
  288. nimlang/nim/lib/std/varints.nim +115 -0
  289. nimlang/nim/lib/std/vmutils.nim +11 -0
  290. nimlang/nim/lib/std/widestrs.nim +241 -0
  291. nimlang/nim/lib/std/with.nim +48 -0
  292. nimlang/nim/lib/std/wordwrap.nim +74 -0
  293. nimlang/nim/lib/std/wrapnils.nim +194 -0
  294. nimlang/nim/lib/stdlib.nimble +5 -0
  295. nimlang/nim/lib/system/alloc.nim +1314 -0
  296. nimlang/nim/lib/system/ansi_c.nim +230 -0
  297. nimlang/nim/lib/system/arc.nim +275 -0
  298. nimlang/nim/lib/system/arithmetics.nim +405 -0
  299. nimlang/nim/lib/system/assign.nim +298 -0
  300. nimlang/nim/lib/system/avltree.nim +97 -0
  301. nimlang/nim/lib/system/basic_types.nim +94 -0
  302. nimlang/nim/lib/system/bitmasks.nim +39 -0
  303. nimlang/nim/lib/system/cellseqs_v1.nim +46 -0
  304. nimlang/nim/lib/system/cellseqs_v2.nim +54 -0
  305. nimlang/nim/lib/system/cellsets.nim +268 -0
  306. nimlang/nim/lib/system/cgprocs.nim +10 -0
  307. nimlang/nim/lib/system/channels_builtin.nim +457 -0
  308. nimlang/nim/lib/system/chcks.nim +166 -0
  309. nimlang/nim/lib/system/comparisons.nim +337 -0
  310. nimlang/nim/lib/system/compilation.nim +209 -0
  311. nimlang/nim/lib/system/coro_detection.nim +20 -0
  312. nimlang/nim/lib/system/countbits_impl.nim +93 -0
  313. nimlang/nim/lib/system/ctypes.nim +115 -0
  314. nimlang/nim/lib/system/cyclebreaker.nim +184 -0
  315. nimlang/nim/lib/system/deepcopy.nim +207 -0
  316. nimlang/nim/lib/system/dollars.nim +157 -0
  317. nimlang/nim/lib/system/dyncalls.nim +200 -0
  318. nimlang/nim/lib/system/embedded.nim +62 -0
  319. nimlang/nim/lib/system/exceptions.nim +122 -0
  320. nimlang/nim/lib/system/excpt.nim +724 -0
  321. nimlang/nim/lib/system/fatal.nim +58 -0
  322. nimlang/nim/lib/system/formatfloat.nim +6 -0
  323. nimlang/nim/lib/system/gc.nim +919 -0
  324. nimlang/nim/lib/system/gc_common.nim +482 -0
  325. nimlang/nim/lib/system/gc_hooks.nim +53 -0
  326. nimlang/nim/lib/system/gc_interface.nim +100 -0
  327. nimlang/nim/lib/system/gc_ms.nim +526 -0
  328. nimlang/nim/lib/system/gc_regions.nim +436 -0
  329. nimlang/nim/lib/system/hti.nim +123 -0
  330. nimlang/nim/lib/system/inclrtl.nim +48 -0
  331. nimlang/nim/lib/system/indexerrors.nim +15 -0
  332. nimlang/nim/lib/system/indices.nim +164 -0
  333. nimlang/nim/lib/system/integerops.nim +133 -0
  334. nimlang/nim/lib/system/iterators.nim +353 -0
  335. nimlang/nim/lib/system/iterators_1.nim +180 -0
  336. nimlang/nim/lib/system/jssys.nim +795 -0
  337. nimlang/nim/lib/system/memalloc.nim +432 -0
  338. nimlang/nim/lib/system/memory.nim +55 -0
  339. nimlang/nim/lib/system/memtracker.nim +106 -0
  340. nimlang/nim/lib/system/mm/boehm.nim +140 -0
  341. nimlang/nim/lib/system/mm/go.nim +153 -0
  342. nimlang/nim/lib/system/mm/malloc.nim +97 -0
  343. nimlang/nim/lib/system/mm/none.nim +46 -0
  344. nimlang/nim/lib/system/mmdisp.nim +121 -0
  345. nimlang/nim/lib/system/nimscript.nim +452 -0
  346. nimlang/nim/lib/system/orc.nim +555 -0
  347. nimlang/nim/lib/system/osalloc.nim +218 -0
  348. nimlang/nim/lib/system/platforms.nim +105 -0
  349. nimlang/nim/lib/system/profiler.nim +103 -0
  350. nimlang/nim/lib/system/ptrarith.nim +17 -0
  351. nimlang/nim/lib/system/rawquits.nim +25 -0
  352. nimlang/nim/lib/system/repr.nim +327 -0
  353. nimlang/nim/lib/system/repr_impl.nim +15 -0
  354. nimlang/nim/lib/system/repr_v2.nim +201 -0
  355. nimlang/nim/lib/system/reprjs.nim +251 -0
  356. nimlang/nim/lib/system/seqs_v2.nim +224 -0
  357. nimlang/nim/lib/system/seqs_v2_reimpl.nim +24 -0
  358. nimlang/nim/lib/system/setops.nim +89 -0
  359. nimlang/nim/lib/system/sets.nim +28 -0
  360. nimlang/nim/lib/system/stacktraces.nim +83 -0
  361. nimlang/nim/lib/system/strmantle.nim +262 -0
  362. nimlang/nim/lib/system/strs_v2.nim +225 -0
  363. nimlang/nim/lib/system/sysstr.nim +363 -0
  364. nimlang/nim/lib/system/threadids.nim +113 -0
  365. nimlang/nim/lib/system/threadimpl.nim +111 -0
  366. nimlang/nim/lib/system/threadlocalstorage.nim +126 -0
  367. nimlang/nim/lib/system/timers.nim +99 -0
  368. nimlang/nim/lib/system.nim +3093 -0
  369. nimlang/nim/lib/system_overview.rst +178 -0
  370. nimlang/nim/lib/windows/registry.nim +83 -0
  371. nimlang/nim/lib/windows/winlean.nim +1068 -0
  372. nimlang/nim/lib/wrappers/linenoise/LICENSE.txt +25 -0
  373. nimlang/nim/lib/wrappers/linenoise/README.markdown +52 -0
  374. nimlang/nim/lib/wrappers/linenoise/linenoise.c +1207 -0
  375. nimlang/nim/lib/wrappers/linenoise/linenoise.h +84 -0
  376. nimlang/nim/lib/wrappers/linenoise/linenoise.nim +72 -0
  377. nimlang/nim/lib/wrappers/openssl.nim +913 -0
  378. nimlang/nim/lib/wrappers/pcre.nim +473 -0
  379. nimlang/nim/lib/wrappers/tinyc.nim +107 -0
  380. nimlang-0.0.1.dist-info/METADATA +65 -0
  381. nimlang-0.0.1.dist-info/RECORD +384 -0
  382. nimlang-0.0.1.dist-info/WHEEL +4 -0
  383. nimlang-0.0.1.dist-info/entry_points.txt +7 -0
  384. nimlang-0.0.1.dist-info/licenses/LICENSE +21 -0
nimlang/__init__.py ADDED
@@ -0,0 +1,30 @@
1
+ """nimlang: a Nim toolchain for Python projects.
2
+
3
+ The Nim compiler is shipped inside platform wheels (see ``scripts/make_wheels.py``)
4
+ and C compilation is delegated to ``zig cc`` from the ``ziglang`` wheel, so a
5
+ working Nim setup needs nothing but ``uv add nimlang``.
6
+ """
7
+
8
+ from nimlang._toolchain import (
9
+ NimlangError,
10
+ cc_args,
11
+ nim_exe,
12
+ nim_home,
13
+ nim_version,
14
+ nimble_exe,
15
+ zig_exe,
16
+ zigcc_shim,
17
+ )
18
+
19
+ __version__ = "0.0.1"
20
+
21
+ __all__ = [
22
+ "NimlangError",
23
+ "cc_args",
24
+ "nim_exe",
25
+ "nim_home",
26
+ "nim_version",
27
+ "nimble_exe",
28
+ "zig_exe",
29
+ "zigcc_shim",
30
+ ]
nimlang/__main__.py ADDED
@@ -0,0 +1,3 @@
1
+ from nimlang.cli import main
2
+
3
+ raise SystemExit(main())
nimlang/_build.py ADDED
@@ -0,0 +1,65 @@
1
+ """Compile Nim sources into Python extension modules and executables."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import subprocess
6
+ import sysconfig
7
+ from pathlib import Path
8
+
9
+ from nimlang._project import find_root, path_args
10
+ from nimlang._toolchain import EXE, NimlangError, cc_args, nim_exe
11
+
12
+ # nimpy resolves the Python C API at runtime, so one build works for every
13
+ # CPython 3 version: the module only needs the platform's plain extension suffix.
14
+ EXTENSION_FLAGS = ["--app:lib", "--threads:on", "--tlsEmulation:off", "-d:release"]
15
+ BINARY_FLAGS = ["-d:release"]
16
+
17
+
18
+ def extension_suffix(target: str | None = None) -> str:
19
+ if target is None:
20
+ return sysconfig.get_config_var("EXT_SUFFIX") or ".so"
21
+ return ".pyd" if "-windows" in target else ".so"
22
+
23
+
24
+ def nim_compile_command(args: list[str], *, target: str | None = None, root: Path | None = None) -> list[str]:
25
+ """``nim c`` command line with zig cc and the project's Nim dependencies wired in."""
26
+ return [str(nim_exe()), "c", *cc_args(target), *path_args(root), *args]
27
+
28
+
29
+ def compile_nim(
30
+ source: Path,
31
+ output: Path,
32
+ *,
33
+ kind: str,
34
+ target: str | None = None,
35
+ extra: list[str] = (),
36
+ root: Path | None = None,
37
+ ) -> Path:
38
+ """Compile ``source`` to ``output``; ``kind`` is ``"extension"`` or ``"binary"``."""
39
+ flags = {"extension": EXTENSION_FLAGS, "binary": BINARY_FLAGS}[kind]
40
+ root = root or find_root(source.parent)
41
+ output.parent.mkdir(parents=True, exist_ok=True)
42
+ cmd = nim_compile_command([*flags, f"--out:{output}", *extra, str(source)], target=target, root=root)
43
+ result = subprocess.run(cmd)
44
+ if result.returncode != 0:
45
+ raise NimlangError(f"nim failed to compile {source} (exit code {result.returncode})")
46
+ return output
47
+
48
+
49
+ def build_extension(
50
+ source: Path, out_dir: Path | None = None, *, target: str | None = None, extra: list[str] = ()
51
+ ) -> Path:
52
+ source = Path(source).resolve()
53
+ out_dir = Path(out_dir) if out_dir else source.parent
54
+ output = out_dir.resolve() / f"{source.stem}{extension_suffix(target)}"
55
+ return compile_nim(source, output, kind="extension", target=target, extra=extra)
56
+
57
+
58
+ def build_binary(
59
+ source: Path, out_dir: Path | None = None, *, target: str | None = None, extra: list[str] = ()
60
+ ) -> Path:
61
+ source = Path(source).resolve()
62
+ out_dir = Path(out_dir) if out_dir else source.parent
63
+ suffix = ".exe" if (target and "-windows" in target) or (not target and EXE) else ""
64
+ output = out_dir.resolve() / f"{source.stem}{suffix}"
65
+ return compile_nim(source, output, kind="binary", target=target, extra=extra)
nimlang/_project.py ADDED
@@ -0,0 +1,143 @@
1
+ """Project-level state: Nim dependencies declared in pyproject.toml.
2
+
3
+ Dependencies live in ``[tool.nimlang] dependencies`` as nimble requirement
4
+ strings (``"nimpy"``, ``"nimpy >= 0.2.0"``, ``"nimpy@#head"``) and are installed
5
+ by nimble into ``.nimlang/nimble`` next to pyproject.toml.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import re
11
+ import subprocess
12
+ from pathlib import Path
13
+
14
+ import tomlkit
15
+
16
+ from nimlang._toolchain import nim_shim_path, nimble_exe
17
+
18
+ STATE_DIR = ".nimlang"
19
+
20
+
21
+ def find_root(start: Path | None = None) -> Path | None:
22
+ """Closest directory at or above ``start`` holding a pyproject.toml."""
23
+ here = (start or Path.cwd()).resolve()
24
+ for folder in (here, *here.parents):
25
+ if (folder / "pyproject.toml").is_file():
26
+ return folder
27
+ return None
28
+
29
+
30
+ def nimble_dir(root: Path) -> Path:
31
+ return root / STATE_DIR / "nimble"
32
+
33
+
34
+ def dep_name(requirement: str) -> str:
35
+ """``"nimpy >= 0.2"`` -> ``"nimpy"``; also handles ``pkg@#rev`` and URLs."""
36
+ req = requirement.strip()
37
+ if "://" in req:
38
+ req = req.rstrip("/").rsplit("/", 1)[-1].removesuffix(".git")
39
+ return re.split(r"[\s@<>=~^#]", req, maxsplit=1)[0].lower()
40
+
41
+
42
+ def _load(root: Path) -> tomlkit.TOMLDocument:
43
+ return tomlkit.parse((root / "pyproject.toml").read_text(encoding="utf-8"))
44
+
45
+
46
+ def read_deps(root: Path) -> list[str]:
47
+ tool = _load(root).get("tool", {})
48
+ return [str(d) for d in tool.get("nimlang", {}).get("dependencies", [])]
49
+
50
+
51
+ def write_deps(root: Path, deps: list[str]) -> None:
52
+ doc = _load(root)
53
+ tool = doc.setdefault("tool", tomlkit.table(is_super_table=True))
54
+ section = tool.setdefault("nimlang", tomlkit.table())
55
+ array = tomlkit.array()
56
+ array.extend(deps)
57
+ if len(deps) > 1:
58
+ array.multiline(True)
59
+ section["dependencies"] = array
60
+ (root / "pyproject.toml").write_text(tomlkit.dumps(doc), encoding="utf-8")
61
+
62
+
63
+ def add_deps(root: Path, requirements: list[str]) -> list[str]:
64
+ """Add or replace requirements (matched by package name); returns the new list."""
65
+ deps = read_deps(root)
66
+ for req in requirements:
67
+ name = dep_name(req)
68
+ deps = [d for d in deps if dep_name(d) != name] + [req.strip()]
69
+ write_deps(root, deps)
70
+ return deps
71
+
72
+
73
+ def remove_deps(root: Path, names: list[str]) -> list[str]:
74
+ drop = {dep_name(n) for n in names}
75
+ deps = [d for d in read_deps(root) if dep_name(d) not in drop]
76
+ write_deps(root, deps)
77
+ return deps
78
+
79
+
80
+ def _version_key(version: str) -> tuple:
81
+ return tuple(int(p) if p.isdigit() else -1 for p in re.split(r"[.\-]", version))
82
+
83
+
84
+ def installed_packages(root: Path) -> dict[str, Path]:
85
+ """Installed package name -> directory, keeping the highest version of each.
86
+
87
+ Nimble 0.14+ installs into ``pkgs2/<name>-<version>-<checksum>``; older
88
+ layouts use ``pkgs/<name>-<version>``.
89
+ """
90
+ best: dict[str, tuple[tuple, Path]] = {}
91
+ for sub in ("pkgs", "pkgs2"):
92
+ base = nimble_dir(root) / sub
93
+ if not base.is_dir():
94
+ continue
95
+ for pkg in base.iterdir():
96
+ if not pkg.is_dir():
97
+ continue
98
+ parts = pkg.name.split("-")
99
+ if sub == "pkgs2" and len(parts) >= 3:
100
+ name, version = "-".join(parts[:-2]), parts[-2]
101
+ elif len(parts) >= 2:
102
+ name, version = "-".join(parts[:-1]), parts[-1]
103
+ else:
104
+ continue
105
+ key = _version_key(version)
106
+ if name.lower() not in best or key > best[name.lower()][0]:
107
+ best[name.lower()] = (key, pkg)
108
+ return {name: path for name, (_, path) in best.items()}
109
+
110
+
111
+ def path_args(root: Path | None) -> list[str]:
112
+ """Nim flags exposing exactly this project's installed Nim dependencies.
113
+
114
+ ``--noNimblePath`` hides packages from the global ~/.nimble so builds only
115
+ see what pyproject.toml declares.
116
+ """
117
+ if root is None or not nimble_dir(root).is_dir():
118
+ return []
119
+ return ["--noNimblePath"] + [f"--path:{p}" for p in installed_packages(root).values()]
120
+
121
+
122
+ def run_nimble(args: list[str]) -> int:
123
+ """Run the bundled nimble, compiling through nimlang's nim (and so zig cc)."""
124
+ return subprocess.run([str(nimble_exe()), f"--nim:{nim_shim_path()}", *args]).returncode
125
+
126
+
127
+ def sync(root: Path) -> int:
128
+ """Install the declared Nim dependencies into the project's private nimble dir."""
129
+ deps = read_deps(root)
130
+ if not deps:
131
+ print("nimlang: no Nim dependencies declared in [tool.nimlang]")
132
+ return 0
133
+ folder = nimble_dir(root)
134
+ folder.mkdir(parents=True, exist_ok=True)
135
+ gitignore = folder.parent / ".gitignore"
136
+ if not gitignore.exists():
137
+ gitignore.write_text("*\n")
138
+ return run_nimble([f"--nimbleDir:{folder}", "install", "-y", *deps])
139
+
140
+
141
+ def missing_deps(root: Path) -> list[str]:
142
+ installed = installed_packages(root)
143
+ return [d for d in read_deps(root) if dep_name(d) not in installed]
nimlang/_toolchain.py ADDED
@@ -0,0 +1,206 @@
1
+ """Locate the Nim and Zig toolchains and wire them together."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import hashlib
6
+ import json
7
+ import os
8
+ import re
9
+ import shutil
10
+ import subprocess
11
+ import sys
12
+ import sysconfig
13
+ from pathlib import Path
14
+
15
+ PKG_DIR = Path(__file__).resolve().parent
16
+ BUNDLED_NIM = PKG_DIR / "nim"
17
+ EXE = ".exe" if os.name == "nt" else ""
18
+
19
+ # zig target arch/os -> Nim --cpu/--os
20
+ ZIG_TO_NIM_CPU = {
21
+ "x86_64": "amd64",
22
+ "aarch64": "arm64",
23
+ "x86": "i386",
24
+ "arm": "arm",
25
+ "riscv64": "riscv64",
26
+ "powerpc64le": "powerpc64el",
27
+ }
28
+ ZIG_TO_NIM_OS = {
29
+ "linux": "linux",
30
+ "windows": "windows",
31
+ "macos": "macosx",
32
+ "freebsd": "freebsd",
33
+ }
34
+
35
+
36
+ class NimlangError(RuntimeError):
37
+ pass
38
+
39
+
40
+ def _scripts_dir() -> Path:
41
+ return Path(sysconfig.get_path("scripts")).resolve()
42
+
43
+
44
+ def _is_nim_home(path: Path) -> bool:
45
+ return (path / "bin" / f"nim{EXE}").is_file() and (path / "lib" / "system.nim").is_file()
46
+
47
+
48
+ def nim_home() -> Path:
49
+ """Root of the Nim distribution (the directory holding ``bin/`` and ``lib/``).
50
+
51
+ Lookup order: ``$NIMLANG_NIM_HOME``, the distribution bundled in the wheel,
52
+ then a ``nim`` found on ``PATH`` (skipping nimlang's own ``nim`` shim).
53
+ """
54
+ env = os.environ.get("NIMLANG_NIM_HOME")
55
+ if env:
56
+ home = Path(env).expanduser().resolve()
57
+ if not _is_nim_home(home):
58
+ raise NimlangError(f"NIMLANG_NIM_HOME={env} does not contain bin/nim and lib/system.nim")
59
+ return home
60
+ if _is_nim_home(BUNDLED_NIM):
61
+ return BUNDLED_NIM
62
+ scripts = _scripts_dir()
63
+ for entry in os.environ.get("PATH", "").split(os.pathsep):
64
+ if not entry or Path(entry).resolve() == scripts:
65
+ continue
66
+ candidate = Path(entry) / f"nim{EXE}"
67
+ if candidate.is_file():
68
+ home = candidate.resolve().parent.parent
69
+ if _is_nim_home(home):
70
+ return home
71
+ home = _ask_prefix(candidate) # e.g. choosenim's proxy executables
72
+ if home and _is_nim_home(home):
73
+ return home
74
+ raise NimlangError(
75
+ "No Nim compiler found. This nimlang install has no bundled Nim (no wheel for "
76
+ "this platform, or a source build); set NIMLANG_NIM_HOME or put nim on PATH."
77
+ )
78
+
79
+
80
+ def _ask_prefix(nim: Path) -> Path | None:
81
+ try:
82
+ out = subprocess.run(
83
+ [str(nim), "dump", "--dump.format:json", "-"],
84
+ capture_output=True,
85
+ text=True,
86
+ stdin=subprocess.DEVNULL,
87
+ timeout=60,
88
+ ).stdout
89
+ return Path(json.loads(out)["prefixdir"]).resolve()
90
+ except (OSError, ValueError, KeyError, subprocess.SubprocessError):
91
+ return None
92
+
93
+
94
+ def nim_exe() -> Path:
95
+ return nim_home() / "bin" / f"nim{EXE}"
96
+
97
+
98
+ def nim_version(home: Path | None = None) -> str:
99
+ """Version of the Nim distribution, read from its stdlib (works for any platform's build)."""
100
+ source = (home or nim_home()) / "lib" / "system" / "compilation.nim"
101
+ parts = {}
102
+ for name in ("NimMajor", "NimMinor", "NimPatch"):
103
+ match = re.search(rf"{name}\*.*?=\s*(\d+)", source.read_text(encoding="utf-8"))
104
+ if not match:
105
+ raise NimlangError(f"cannot read {name} from {source}")
106
+ parts[name] = match.group(1)
107
+ return ".".join(parts.values())
108
+
109
+
110
+ def nimble_exe() -> Path:
111
+ path = nim_home() / "bin" / f"nimble{EXE}"
112
+ if not path.is_file():
113
+ raise NimlangError(f"nimble not found next to nim in {path.parent}")
114
+ return path
115
+
116
+
117
+ def zig_exe() -> Path:
118
+ try:
119
+ import ziglang
120
+ except ImportError as e: # pragma: no cover - ziglang is a hard dependency
121
+ raise NimlangError("the ziglang package is not installed") from e
122
+ path = Path(ziglang.__file__).resolve().parent / f"zig{EXE}"
123
+ if not path.is_file():
124
+ raise NimlangError(f"zig binary missing from ziglang package at {path}")
125
+ return path
126
+
127
+
128
+ def _cache_dir() -> Path:
129
+ if os.name == "nt":
130
+ base = Path(os.environ.get("LOCALAPPDATA", Path.home() / "AppData" / "Local"))
131
+ elif sys.platform == "darwin":
132
+ base = Path.home() / "Library" / "Caches"
133
+ else:
134
+ base = Path(os.environ.get("XDG_CACHE_HOME", Path.home() / ".cache"))
135
+ return base / "nimlang"
136
+
137
+
138
+ def zigcc_shim() -> Path:
139
+ """A tiny executable script that forwards to ``zig cc``.
140
+
141
+ Nim invokes the C compiler as a single executable, so we cannot point it at
142
+ ``zig`` directly. The shim embeds the absolute path of this environment's zig
143
+ and is cached per zig location.
144
+ """
145
+ zig = zig_exe()
146
+ key = hashlib.sha256(str(zig).encode()).hexdigest()[:12]
147
+ folder = _cache_dir() / f"zigcc-{key}"
148
+ if os.name == "nt":
149
+ shim = folder / "zigcc.cmd"
150
+ content = f'@"{zig}" cc %*\r\n'
151
+ else:
152
+ shim = folder / "zigcc"
153
+ content = f'#!/bin/sh\nexec "{zig}" cc "$@"\n'
154
+ if shim.is_file() and shim.read_text() == content:
155
+ return shim
156
+ folder.mkdir(parents=True, exist_ok=True)
157
+ tmp = folder / f".{shim.name}.{os.getpid()}"
158
+ tmp.write_text(content)
159
+ tmp.chmod(0o755)
160
+ os.replace(tmp, shim)
161
+ return shim
162
+
163
+
164
+ def target_args(target: str) -> list[str]:
165
+ """Nim flags to cross-compile for a zig target triple such as ``aarch64-macos``
166
+ or ``x86_64-linux-gnu.2.17`` (the glibc suffix gives manylinux-compatible output)."""
167
+ parts = target.split("-")
168
+ if len(parts) < 2:
169
+ raise NimlangError(f"invalid zig target {target!r}, expected <arch>-<os>[-<abi>]")
170
+ arch, os_name = parts[0], parts[1]
171
+ if arch not in ZIG_TO_NIM_CPU or os_name not in ZIG_TO_NIM_OS:
172
+ raise NimlangError(f"unsupported zig target {target!r}")
173
+ return [
174
+ f"--cpu:{ZIG_TO_NIM_CPU[arch]}",
175
+ f"--os:{ZIG_TO_NIM_OS[os_name]}",
176
+ f"--passC:-target {target}",
177
+ f"--passL:-target {target}",
178
+ ]
179
+
180
+
181
+ def cc_args(target: str | None = None) -> list[str]:
182
+ """Nim command-line flags that make it compile C through ``zig cc``.
183
+
184
+ Set ``NIMLANG_CC=system`` to keep Nim's default C compiler instead.
185
+ """
186
+ if os.environ.get("NIMLANG_CC", "zig") == "system":
187
+ if target:
188
+ raise NimlangError("cross-compiling with a target requires zig cc (unset NIMLANG_CC)")
189
+ return []
190
+ shim = zigcc_shim()
191
+ args = ["--cc:clang", f"--clang.exe:{shim}", f"--clang.linkerexe:{shim}"]
192
+ if target:
193
+ args += target_args(target)
194
+ return args
195
+
196
+
197
+ def nim_shim_path() -> str:
198
+ """Path of nimlang's ``nim`` console script if installed, else the raw compiler.
199
+
200
+ Handed to nimble so that packages it builds also compile through zig cc.
201
+ """
202
+ shim = _scripts_dir() / f"nim{EXE}"
203
+ if shim.is_file():
204
+ return str(shim)
205
+ found = shutil.which("nim")
206
+ return found or str(nim_exe())
nimlang/cli.py ADDED
@@ -0,0 +1,173 @@
1
+ """Command-line entry points: ``nimlang``, plus ``nim`` and ``nimble`` shims."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import subprocess
7
+ import sys
8
+ from pathlib import Path
9
+
10
+ from nimlang import _project
11
+ from nimlang._build import build_binary, build_extension
12
+ from nimlang._toolchain import (
13
+ NimlangError,
14
+ cc_args,
15
+ nim_exe,
16
+ nim_home,
17
+ nim_version,
18
+ zig_exe,
19
+ zigcc_shim,
20
+ )
21
+
22
+ # Commands that invoke the C compiler get zig cc; commands that only resolve
23
+ # imports get the project's dependency paths. Everything else (notably `nim e`,
24
+ # which nimble uses to evaluate .nimble files) passes through untouched, since
25
+ # NimScript sees every command-line argument.
26
+ _C_COMMANDS = {"c", "cc", "cpp", "objc", "compile", "compiletoc", "compiletocpp", "compiletooc", "r", "run"}
27
+ _PATH_COMMANDS = {"js", "check", "doc", "doc2", "jsondoc", "ctags", "dump"}
28
+
29
+
30
+ def _run(cmd: list[str]) -> int:
31
+ try:
32
+ return subprocess.run(cmd).returncode
33
+ except KeyboardInterrupt:
34
+ return 130
35
+
36
+
37
+ def nim_args(args: list[str]) -> list[str]:
38
+ """Insert nimlang's flags right after the command, so user flags still override them."""
39
+ index = next((i for i, a in enumerate(args) if not a.startswith("-")), None)
40
+ if index is None:
41
+ return args
42
+ command = args[index].lower()
43
+ if command in _C_COMMANDS:
44
+ extra = cc_args() + _project.path_args(_project.find_root())
45
+ elif command in _PATH_COMMANDS:
46
+ extra = _project.path_args(_project.find_root())
47
+ else:
48
+ return args
49
+ return [*args[: index + 1], *extra, *args[index + 1 :]]
50
+
51
+
52
+ def run_nim(args: list[str]) -> int:
53
+ return _run([str(nim_exe()), *nim_args(args)])
54
+
55
+
56
+ def run_nimble(args: list[str]) -> int:
57
+ try:
58
+ return _project.run_nimble(args)
59
+ except KeyboardInterrupt:
60
+ return 130
61
+
62
+
63
+ def _require_root() -> Path:
64
+ root = _project.find_root()
65
+ if root is None:
66
+ raise NimlangError("no pyproject.toml found in this directory or its parents")
67
+ return root
68
+
69
+
70
+ def cmd_add(ns: argparse.Namespace) -> int:
71
+ root = _require_root()
72
+ deps = _project.add_deps(root, ns.packages)
73
+ print(f"nimlang: Nim dependencies: {', '.join(deps)}")
74
+ return 0 if ns.no_sync else _project.sync(root)
75
+
76
+
77
+ def cmd_remove(ns: argparse.Namespace) -> int:
78
+ root = _require_root()
79
+ deps = _project.remove_deps(root, ns.packages)
80
+ print(f"nimlang: Nim dependencies: {', '.join(deps) or '(none)'}")
81
+ return 0
82
+
83
+
84
+ def cmd_sync(ns: argparse.Namespace) -> int:
85
+ return _project.sync(_require_root())
86
+
87
+
88
+ def cmd_build_ext(ns: argparse.Namespace) -> int:
89
+ for source in ns.sources:
90
+ out = build_extension(Path(source), ns.out_dir, target=ns.target, extra=ns.nim_args)
91
+ print(f"nimlang: built {out}")
92
+ return 0
93
+
94
+
95
+ def cmd_build_bin(ns: argparse.Namespace) -> int:
96
+ for source in ns.sources:
97
+ out = build_binary(Path(source), ns.out_dir, target=ns.target, extra=ns.nim_args)
98
+ print(f"nimlang: built {out}")
99
+ return 0
100
+
101
+
102
+ def cmd_info(ns: argparse.Namespace) -> int:
103
+ root = _project.find_root()
104
+ rows = [
105
+ ("nim", f"{nim_version()} at {nim_home()}"),
106
+ ("zig", zig_exe()),
107
+ ("zigcc shim", zigcc_shim()),
108
+ ("project", root or "(none)"),
109
+ ]
110
+ if root:
111
+ rows.append(("nim deps", ", ".join(_project.read_deps(root)) or "(none)"))
112
+ rows.append(("installed", ", ".join(sorted(_project.installed_packages(root))) or "(none)"))
113
+ for key, value in rows:
114
+ print(f"{key:>11}: {value}")
115
+ return 0
116
+
117
+
118
+ def _parser() -> argparse.ArgumentParser:
119
+ p = argparse.ArgumentParser(prog="nimlang", description="Nim toolchain for Python projects.")
120
+ sub = p.add_subparsers(dest="command", required=True)
121
+
122
+ s = sub.add_parser("add", help="add Nim dependencies to pyproject.toml and install them")
123
+ s.add_argument("packages", nargs="+", help='nimble requirements, e.g. nimpy or "nimpy >= 0.2"')
124
+ s.add_argument("--no-sync", action="store_true", help="only edit pyproject.toml")
125
+ s.set_defaults(func=cmd_add)
126
+
127
+ s = sub.add_parser("remove", help="remove Nim dependencies from pyproject.toml")
128
+ s.add_argument("packages", nargs="+")
129
+ s.set_defaults(func=cmd_remove)
130
+
131
+ s = sub.add_parser("sync", help="install the Nim dependencies declared in pyproject.toml")
132
+ s.set_defaults(func=cmd_sync)
133
+
134
+ for name, func, help_ in (
135
+ ("build-ext", cmd_build_ext, "compile .nim files into Python extension modules (nimpy)"),
136
+ ("build-bin", cmd_build_bin, "compile .nim files into executables"),
137
+ ):
138
+ s = sub.add_parser(name, help=help_)
139
+ s.add_argument("sources", nargs="+")
140
+ s.add_argument("-o", "--out-dir", type=Path, help="output directory (default: next to source)")
141
+ s.add_argument("--target", help="zig target to cross-compile for, e.g. aarch64-macos")
142
+ s.add_argument("--nim-arg", dest="nim_args", action="append", default=[], help="extra flag for nim")
143
+ s.set_defaults(func=func)
144
+
145
+ s = sub.add_parser("info", help="show where the toolchain lives")
146
+ s.set_defaults(func=cmd_info)
147
+
148
+ # Passthroughs are handled before argparse so their flags are not parsed.
149
+ sub.add_parser("nim", help="run the Nim compiler (same as the `nim` command)")
150
+ sub.add_parser("nimble", help="run nimble (same as the `nimble` command)")
151
+ return p
152
+
153
+
154
+ def main(argv: list[str] | None = None) -> int:
155
+ argv = sys.argv[1:] if argv is None else argv
156
+ try:
157
+ if argv and argv[0] == "nim":
158
+ return run_nim(argv[1:])
159
+ if argv and argv[0] == "nimble":
160
+ return run_nimble(argv[1:])
161
+ ns = _parser().parse_args(argv)
162
+ return ns.func(ns)
163
+ except NimlangError as e:
164
+ print(f"nimlang: error: {e}", file=sys.stderr)
165
+ return 1
166
+
167
+
168
+ def nim_main() -> int:
169
+ return main(["nim", *sys.argv[1:]])
170
+
171
+
172
+ def nimble_main() -> int:
173
+ return main(["nimble", *sys.argv[1:]])