@greenpandastudios/aug-cli 0.19.0 → 0.21.0

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 (628) hide show
  1. package/README.md +9 -6
  2. package/THIRD_PARTY_NOTICES.md +4 -0
  3. package/bin/aug.mjs +12 -2
  4. package/docs/about.md +27 -0
  5. package/docs/api/crypto.md +103 -69
  6. package/docs/api/io.md +35 -33
  7. package/docs/api/json.md +3 -3
  8. package/docs/api/memory.md +23 -19
  9. package/docs/api/time.md +10 -9
  10. package/docs/api/web.md +33 -38
  11. package/docs/assets/benchmarks/execution.svg +774 -637
  12. package/docs/assets/benchmarks/http.svg +278 -249
  13. package/docs/assets/benchmarks/improvements.svg +66 -66
  14. package/docs/assets/benchmarks/kernels-mobile.svg +1 -0
  15. package/docs/assets/benchmarks/kernels.svg +1 -0
  16. package/docs/assets/benchmarks/memory.svg +153 -153
  17. package/docs/benchmark-results.json +227089 -90363
  18. package/docs/compatibility.md +8 -8
  19. package/docs/contributing-benchmarks.md +68 -0
  20. package/docs/dev-containers.md +88 -0
  21. package/docs/dgx-consumers.json +122 -0
  22. package/docs/dgx-gyms.json +784 -0
  23. package/docs/dgx-kernels.json +1170 -0
  24. package/docs/dgx-performance.json +227849 -0
  25. package/docs/dgx-spark.md +64 -0
  26. package/docs/diagnostics.md +15 -5
  27. package/docs/docker.md +173 -12
  28. package/docs/editor.md +35 -0
  29. package/docs/example-projects.json +238 -24
  30. package/docs/examples/approved-design/counters.md +34 -126
  31. package/docs/examples/approved-design/dependencies/august/0.21.0/io/contracts.md +178 -0
  32. package/docs/examples/approved-design/domain/app.md +13 -77
  33. package/docs/examples/approved-design/domain/export.md +5 -19
  34. package/docs/examples/approved-design/domain/models.md +4 -23
  35. package/docs/examples/approved-design/domain/numbers.md +24 -114
  36. package/docs/examples/approved-design/index.md +16 -7
  37. package/docs/examples/approved-design/main.md +19 -96
  38. package/docs/examples/benchmark/index.md +6 -5
  39. package/docs/examples/benchmark/main.md +7 -35
  40. package/docs/examples/calls-benchmark/index.md +36 -0
  41. package/docs/examples/calls-benchmark/main.md +78 -0
  42. package/docs/examples/calls-benchmark/operations.md +60 -0
  43. package/docs/examples/cli-args/index.md +6 -5
  44. package/docs/examples/cli-args/main.md +6 -31
  45. package/docs/examples/collections/index.md +6 -5
  46. package/docs/examples/collections/main.md +7 -35
  47. package/docs/examples/collections-benchmark/index.md +6 -5
  48. package/docs/examples/collections-benchmark/main.md +7 -35
  49. package/docs/examples/cpu-benchmark/index.md +6 -5
  50. package/docs/examples/cpu-benchmark/main.md +5 -24
  51. package/docs/examples/developer-workflow/calculator.md +39 -186
  52. package/docs/examples/developer-workflow/dependencies/august/0.21.0/io/contracts.md +178 -0
  53. package/docs/examples/developer-workflow/index.md +16 -7
  54. package/docs/examples/developer-workflow/logging/console.md +10 -56
  55. package/docs/examples/developer-workflow/logging/export.md +4 -14
  56. package/docs/examples/developer-workflow/logging/logger.md +7 -43
  57. package/docs/examples/developer-workflow/main.md +17 -69
  58. package/docs/examples/drop/index.md +6 -5
  59. package/docs/examples/drop/main.md +7 -27
  60. package/docs/examples/drop/resource.md +7 -30
  61. package/docs/examples/errors/errors.md +7 -27
  62. package/docs/examples/errors/index.md +6 -5
  63. package/docs/examples/errors/main.md +7 -28
  64. package/docs/examples/errors-benchmark/index.md +36 -0
  65. package/docs/examples/errors-benchmark/main.md +92 -0
  66. package/docs/examples/errors-benchmark/operations.md +65 -0
  67. package/docs/examples/ffi/index.md +6 -5
  68. package/docs/examples/ffi/main.md +6 -20
  69. package/docs/examples/ffi/native.md +8 -34
  70. package/docs/examples/float-benchmark/index.md +35 -0
  71. package/docs/examples/float-benchmark/main.md +75 -0
  72. package/docs/examples/generic-di/dependencies/august/0.21.0/io/contracts.md +178 -0
  73. package/docs/examples/generic-di/index.md +6 -5
  74. package/docs/examples/generic-di/main.md +9 -39
  75. package/docs/examples/generic-di/types.md +23 -92
  76. package/docs/examples/generics/index.md +6 -5
  77. package/docs/examples/generics/main.md +10 -47
  78. package/docs/examples/generics/types.md +25 -100
  79. package/docs/examples/hello/app/export.md +4 -12
  80. package/docs/examples/hello/app/greeter.md +13 -91
  81. package/docs/examples/hello/dependencies/august/0.21.0/io/contracts.md +178 -0
  82. package/docs/examples/hello/index.md +17 -6
  83. package/docs/examples/hello/logging/console.md +10 -54
  84. package/docs/examples/hello/logging/export.md +4 -14
  85. package/docs/examples/hello/logging/logger.md +7 -45
  86. package/docs/examples/hello/main.md +9 -39
  87. package/docs/examples/http-benchmark/index.md +6 -5
  88. package/docs/examples/http-benchmark/main.md +6 -20
  89. package/docs/examples/http-benchmark/routes.md +9 -31
  90. package/docs/examples/index.md +63 -29
  91. package/docs/examples/interceptors/app.md +20 -139
  92. package/docs/examples/interceptors/dependencies/august/0.21.0/io/contracts.md +178 -0
  93. package/docs/examples/interceptors/index.md +6 -5
  94. package/docs/examples/interceptors/interceptors.md +24 -148
  95. package/docs/examples/interceptors/logging.md +13 -76
  96. package/docs/examples/interceptors/main.md +10 -65
  97. package/docs/examples/json-benchmark/data.md +4 -20
  98. package/docs/examples/json-benchmark/dependencies/packages/@git/url_2d3c37c690c0fa115be1/0.0.0-git.a39fc582565d4fca40be4f75fa304d71adc69301/contracts.md +67 -0
  99. package/docs/examples/json-benchmark/index.md +7 -5
  100. package/docs/examples/json-benchmark/main-yaml.md +20 -0
  101. package/docs/examples/json-benchmark/main.md +10 -49
  102. package/docs/examples/list-benchmark/index.md +35 -0
  103. package/docs/examples/list-benchmark/main.md +78 -0
  104. package/docs/examples/map-churn-benchmark/index.md +35 -0
  105. package/docs/examples/map-churn-benchmark/main.md +106 -0
  106. package/docs/examples/native-blake3/dependencies/packages/@greenpandastudios/aug-blake3/0.1.3/api.md +104 -0
  107. package/docs/examples/native-blake3/dependencies/packages/@greenpandastudios/aug-blake3/0.1.3/contracts.md +54 -0
  108. package/docs/examples/native-blake3/dependencies/packages/@greenpandastudios/aug-blake3/0.1.3/native.abi-json.md +48 -0
  109. package/docs/examples/native-blake3/hashing.md +93 -0
  110. package/docs/examples/native-blake3/index.md +38 -0
  111. package/docs/examples/native-blake3/main.md +73 -0
  112. package/docs/examples/native-pytorch/dependencies/packages/@greenpandastudios/aug-pytorch/0.1.4/api.md +406 -0
  113. package/docs/examples/native-pytorch/dependencies/packages/@greenpandastudios/aug-pytorch/0.1.4/bindings.md +51 -0
  114. package/docs/examples/native-pytorch/dependencies/packages/@greenpandastudios/aug-pytorch/0.1.4/contracts.md +63 -0
  115. package/docs/examples/native-pytorch/dependencies/packages/@greenpandastudios/aug-pytorch/0.1.4/native.abi-json.md +161 -0
  116. package/docs/examples/native-pytorch/index.md +38 -0
  117. package/docs/examples/native-pytorch/main.md +73 -0
  118. package/docs/examples/native-pytorch/tensors.md +123 -0
  119. package/docs/examples/native-sqlite/database.md +116 -0
  120. package/docs/examples/native-sqlite/dependencies/packages/@greenpandastudios/aug-sqlite/0.1.3/api.md +284 -0
  121. package/docs/examples/native-sqlite/dependencies/packages/@greenpandastudios/aug-sqlite/0.1.3/bindings.md +51 -0
  122. package/docs/examples/native-sqlite/dependencies/packages/@greenpandastudios/aug-sqlite/0.1.3/contracts.md +75 -0
  123. package/docs/examples/native-sqlite/dependencies/packages/@greenpandastudios/aug-sqlite/0.1.3/native.abi-json.md +119 -0
  124. package/docs/examples/native-sqlite/index.md +38 -0
  125. package/docs/examples/native-sqlite/main.md +73 -0
  126. package/docs/examples/native-zlib/compression.md +99 -0
  127. package/docs/examples/native-zlib/dependencies/packages/@greenpandastudios/aug-zlib/0.1.3/api.md +153 -0
  128. package/docs/examples/native-zlib/dependencies/packages/@greenpandastudios/aug-zlib/0.1.3/contracts.md +54 -0
  129. package/docs/examples/native-zlib/dependencies/packages/@greenpandastudios/aug-zlib/0.1.3/native.abi-json.md +76 -0
  130. package/docs/examples/native-zlib/index.md +38 -0
  131. package/docs/examples/native-zlib/main.md +78 -0
  132. package/docs/examples/new-syntax/console.md +10 -52
  133. package/docs/examples/new-syntax/dependencies/august/0.21.0/io/contracts.md +178 -0
  134. package/docs/examples/new-syntax/greeter.md +13 -71
  135. package/docs/examples/new-syntax/index.md +6 -5
  136. package/docs/examples/new-syntax/logger.md +7 -43
  137. package/docs/examples/new-syntax/main.md +10 -53
  138. package/docs/examples/new-syntax/math.md +6 -24
  139. package/docs/examples/oidc-login/client/contracts.md +10 -61
  140. package/docs/examples/oidc-login/client/endpoints.md +32 -154
  141. package/docs/examples/oidc-login/client/export.md +5 -23
  142. package/docs/examples/oidc-login/client/login.md +234 -344
  143. package/docs/examples/oidc-login/client/logout.md +38 -143
  144. package/docs/examples/oidc-login/client/protocol.md +183 -304
  145. package/docs/examples/oidc-login/client/session.md +41 -149
  146. package/docs/examples/oidc-login/client/views.md +13 -58
  147. package/docs/examples/oidc-login/common/export.md +6 -26
  148. package/docs/examples/oidc-login/common/headers.md +42 -72
  149. package/docs/examples/oidc-login/common/keys.md +40 -164
  150. package/docs/examples/oidc-login/common/settings.md +24 -40
  151. package/docs/examples/oidc-login/common/views.md +7 -28
  152. package/docs/examples/oidc-login/dependencies/packages/@git/url_0eb7c89453c87681ed15/0.0.0-git.a39fc582565d4fca40be4f75fa304d71adc69301/store.md +205 -0
  153. package/docs/examples/oidc-login/dependencies/packages/@git/url_2d3c37c690c0fa115be1/0.0.0-git.a39fc582565d4fca40be4f75fa304d71adc69301/contracts.md +67 -0
  154. package/docs/examples/oidc-login/dependencies/packages/@git/url_897efafd565158fc4908/0.0.0-git.a39fc582565d4fca40be4f75fa304d71adc69301/contracts.md +267 -0
  155. package/docs/examples/oidc-login/dependencies/packages/@git/url_9ef654c66d34ab8f5527/0.0.0-git.b14a0f9aa41f1ce58bd51133bcdc424033e40d40/contracts.md +415 -0
  156. package/docs/examples/oidc-login/dependencies/packages/@git/url_9ef654c66d34ab8f5527/0.0.0-git.b14a0f9aa41f1ce58bd51133bcdc424033e40d40/jose.md +271 -0
  157. package/docs/examples/oidc-login/dependencies/packages/@git/url_c092cd151499c4e1d8a1/0.0.0-git.a39fc582565d4fca40be4f75fa304d71adc69301/contracts.md +89 -0
  158. package/docs/examples/oidc-login/index.md +8 -7
  159. package/docs/examples/oidc-login/main-yaml.md +7 -0
  160. package/docs/examples/oidc-login/main.md +26 -153
  161. package/docs/examples/oidc-login/provider/authorization.md +232 -275
  162. package/docs/examples/oidc-login/provider/contracts.md +24 -146
  163. package/docs/examples/oidc-login/provider/credentials.md +24 -57
  164. package/docs/examples/oidc-login/provider/discovery.md +48 -122
  165. package/docs/examples/oidc-login/provider/export.md +11 -37
  166. package/docs/examples/oidc-login/provider/token.md +159 -237
  167. package/docs/examples/oidc-login/provider/userinfo.md +47 -102
  168. package/docs/examples/oidc-login/provider/views.md +13 -53
  169. package/docs/examples/ownership/counter.md +17 -63
  170. package/docs/examples/ownership/index.md +6 -5
  171. package/docs/examples/ownership/main.md +7 -30
  172. package/docs/examples/ownership-transfer/dependencies/august/0.21.0/io/contracts.md +178 -0
  173. package/docs/examples/ownership-transfer/index.md +6 -5
  174. package/docs/examples/ownership-transfer/main.md +10 -52
  175. package/docs/examples/ownership-transfer/resource.md +15 -67
  176. package/docs/examples/packages-app/dependencies/packages/@example/aug-math/0.1.0/arithmetic.md +12 -50
  177. package/docs/examples/packages-app/index.md +7 -6
  178. package/docs/examples/packages-app/main.md +7 -25
  179. package/docs/examples/packages-math/aug-package-json.md +1 -1
  180. package/docs/examples/packages-math/index.md +7 -6
  181. package/docs/examples/packages-math/src/arithmetic.md +12 -50
  182. package/docs/examples/packages-math/src/export.md +4 -12
  183. package/docs/examples/records-benchmark/data.md +55 -0
  184. package/docs/examples/records-benchmark/index.md +36 -0
  185. package/docs/examples/records-benchmark/main.md +85 -0
  186. package/docs/examples/startup-benchmark/index.md +6 -5
  187. package/docs/examples/startup-benchmark/main.md +5 -17
  188. package/docs/examples/strings-benchmark/index.md +35 -0
  189. package/docs/examples/strings-benchmark/main.md +76 -0
  190. package/docs/examples/tasks-benchmark/index.md +36 -0
  191. package/docs/examples/tasks-benchmark/main.md +89 -0
  192. package/docs/examples/tasks-benchmark/operations.md +58 -0
  193. package/docs/examples/visibility/counter.md +19 -67
  194. package/docs/examples/visibility/index.md +6 -5
  195. package/docs/examples/visibility/main.md +7 -31
  196. package/docs/examples/weather-api/forecasts.md +168 -0
  197. package/docs/examples/weather-api/index.md +42 -0
  198. package/docs/examples/weather-api/main-yaml.md +21 -0
  199. package/docs/examples/weather-api/main.md +65 -0
  200. package/docs/examples.json +10 -0
  201. package/docs/getting-started.md +105 -2
  202. package/docs/grammar.md +7 -5
  203. package/docs/guides/change-a-module.md +64 -0
  204. package/docs/guides/index.md +27 -0
  205. package/docs/gym-results.json +784 -0
  206. package/docs/implementation-map.md +6 -0
  207. package/docs/index.md +51 -29
  208. package/docs/kernel-results.json +1170 -0
  209. package/docs/language-conformance.md +7 -1
  210. package/docs/language-constructs.md +30 -22
  211. package/docs/language-design-audit.md +1 -1
  212. package/docs/learn/data-and-errors.md +77 -0
  213. package/docs/learn/index.md +30 -0
  214. package/docs/learn/modules-and-dependencies.md +73 -0
  215. package/docs/learn/state-and-tests.md +71 -0
  216. package/docs/learn/values-and-functions.md +62 -0
  217. package/docs/lesson-failures.json +8 -0
  218. package/docs/maintaining-docs.md +16 -4
  219. package/docs/native-implementation.md +276 -0
  220. package/docs/native-interop-llvm-plan.md +342 -0
  221. package/docs/native-package-examples.md +684 -0
  222. package/docs/native-packages.md +179 -0
  223. package/docs/packages.md +72 -126
  224. package/docs/performance.md +61 -68
  225. package/docs/production-readiness.md +16 -5
  226. package/docs/public/downloads/approved-design.zip +0 -0
  227. package/docs/public/downloads/benchmark.zip +0 -0
  228. package/docs/public/downloads/calls-benchmark.zip +0 -0
  229. package/docs/public/downloads/cli-args.zip +0 -0
  230. package/docs/public/downloads/collections-benchmark.zip +0 -0
  231. package/docs/public/downloads/collections.zip +0 -0
  232. package/docs/public/downloads/cpu-benchmark.zip +0 -0
  233. package/docs/public/downloads/developer-workflow.zip +0 -0
  234. package/docs/public/downloads/drop.zip +0 -0
  235. package/docs/public/downloads/errors-benchmark.zip +0 -0
  236. package/docs/public/downloads/errors.zip +0 -0
  237. package/docs/public/downloads/ffi.zip +0 -0
  238. package/docs/public/downloads/float-benchmark.zip +0 -0
  239. package/docs/public/downloads/generic-di.zip +0 -0
  240. package/docs/public/downloads/generics.zip +0 -0
  241. package/docs/public/downloads/hello.zip +0 -0
  242. package/docs/public/downloads/http-benchmark.zip +0 -0
  243. package/docs/public/downloads/interceptors.zip +0 -0
  244. package/docs/public/downloads/json-benchmark.zip +0 -0
  245. package/docs/public/downloads/list-benchmark.zip +0 -0
  246. package/docs/public/downloads/map-churn-benchmark.zip +0 -0
  247. package/docs/public/downloads/native-blake3.zip +0 -0
  248. package/docs/public/downloads/native-pytorch.zip +0 -0
  249. package/docs/public/downloads/native-sqlite.zip +0 -0
  250. package/docs/public/downloads/native-zlib.zip +0 -0
  251. package/docs/public/downloads/new-syntax.zip +0 -0
  252. package/docs/public/downloads/oidc-login.zip +0 -0
  253. package/docs/public/downloads/ownership-transfer.zip +0 -0
  254. package/docs/public/downloads/ownership.zip +0 -0
  255. package/docs/public/downloads/packages-app.zip +0 -0
  256. package/docs/public/downloads/packages-math.zip +0 -0
  257. package/docs/public/downloads/records-benchmark.zip +0 -0
  258. package/docs/public/downloads/startup-benchmark.zip +0 -0
  259. package/docs/public/downloads/strings-benchmark.zip +0 -0
  260. package/docs/public/downloads/tasks-benchmark.zip +0 -0
  261. package/docs/public/downloads/visibility.zip +0 -0
  262. package/docs/public/downloads/weather-api.zip +0 -0
  263. package/docs/qualification-results.md +66 -0
  264. package/docs/reference.md +47 -17
  265. package/docs/releasing.md +105 -16
  266. package/docs/research/code-to-natural-language.md +108 -0
  267. package/docs/research/ecosystem-workflow.md +41 -0
  268. package/docs/research/libtorch-native-qualification.md +115 -0
  269. package/docs/research/native-interop-llvm.md +197 -0
  270. package/docs/research/qualification-methods.md +15 -0
  271. package/docs/research/wiki-editorial-design.md +71 -0
  272. package/docs/roadmap.md +2 -1
  273. package/docs/safety-gyms.md +41 -0
  274. package/docs/specifications.md +27 -11
  275. package/docs/testing.md +19 -5
  276. package/docs/tooling.md +36 -22
  277. package/docs/weather-api.md +65 -0
  278. package/docs/web-library-gaps.md +1 -1
  279. package/docs/web.md +54 -18
  280. package/docs/writing-docs.md +49 -0
  281. package/examples/{hello/.aug-spec/august/0.19.0 → approved-design/.aug-spec/august/0.21.0}/io/contracts.aug +4 -3
  282. package/examples/approved-design/.aug-spec/august/0.21.0/io/contracts.aug.md +82 -0
  283. package/examples/approved-design/.aug-spec/manifest.json +3 -3
  284. package/examples/approved-design/counters.aug +5 -4
  285. package/examples/approved-design/counters.aug.md +25 -132
  286. package/examples/approved-design/domain/app.aug +2 -1
  287. package/examples/approved-design/domain/app.aug.md +10 -80
  288. package/examples/approved-design/domain/export.aug +1 -0
  289. package/examples/approved-design/domain/export.aug.md +4 -20
  290. package/examples/approved-design/domain/models.aug +1 -0
  291. package/examples/approved-design/domain/models.aug.md +3 -25
  292. package/examples/approved-design/domain/numbers.aug +3 -2
  293. package/examples/approved-design/domain/numbers.aug.md +19 -116
  294. package/examples/approved-design/main.aug +1 -0
  295. package/examples/approved-design/main.aug.md +12 -95
  296. package/examples/benchmark/.aug-spec/manifest.json +1 -1
  297. package/examples/benchmark/main.aug +1 -0
  298. package/examples/benchmark/main.aug.md +6 -36
  299. package/examples/cli-args/.aug-spec/manifest.json +1 -1
  300. package/examples/cli-args/main.aug +1 -0
  301. package/examples/cli-args/main.aug.md +5 -32
  302. package/examples/collections/.aug-spec/manifest.json +1 -1
  303. package/examples/collections/main.aug +1 -0
  304. package/examples/collections/main.aug.md +6 -36
  305. package/examples/{generic-di/.aug-spec/august/0.19.0 → developer-workflow/.aug-spec/august/0.21.0}/io/contracts.aug +4 -3
  306. package/examples/developer-workflow/.aug-spec/august/0.21.0/io/contracts.aug.md +82 -0
  307. package/examples/developer-workflow/.aug-spec/manifest.json +3 -3
  308. package/examples/developer-workflow/calculator.aug +3 -2
  309. package/examples/developer-workflow/calculator.aug.md +28 -189
  310. package/examples/developer-workflow/logging/console.aug +2 -1
  311. package/examples/developer-workflow/logging/console.aug.md +7 -57
  312. package/examples/developer-workflow/logging/export.aug +1 -0
  313. package/examples/developer-workflow/logging/export.aug.md +3 -15
  314. package/examples/developer-workflow/logging/logger.aug +1 -0
  315. package/examples/developer-workflow/logging/logger.aug.md +6 -46
  316. package/examples/developer-workflow/main.aug +1 -0
  317. package/examples/developer-workflow/main.aug.md +10 -68
  318. package/examples/drop/.aug-spec/manifest.json +1 -1
  319. package/examples/drop/main.aug +1 -0
  320. package/examples/drop/main.aug.md +6 -28
  321. package/examples/drop/resource.aug +1 -0
  322. package/examples/drop/resource.aug.md +6 -34
  323. package/examples/errors/.aug-spec/manifest.json +1 -1
  324. package/examples/errors/errors.aug +2 -1
  325. package/examples/errors/errors.aug.md +4 -27
  326. package/examples/errors/main.aug +1 -0
  327. package/examples/errors/main.aug.md +6 -29
  328. package/examples/ffi/.aug-spec/manifest.json +1 -1
  329. package/examples/ffi/main.aug +1 -0
  330. package/examples/ffi/main.aug.md +5 -21
  331. package/examples/ffi/native.aug +2 -1
  332. package/examples/ffi/native.aug.md +5 -35
  333. package/examples/{approved-design/.aug-spec/august/0.19.0 → generic-di/.aug-spec/august/0.21.0}/io/contracts.aug +4 -3
  334. package/examples/generic-di/.aug-spec/august/0.21.0/io/contracts.aug.md +82 -0
  335. package/examples/generic-di/.aug-spec/manifest.json +3 -3
  336. package/examples/generic-di/main.aug +1 -0
  337. package/examples/generic-di/main.aug.md +8 -40
  338. package/examples/generic-di/types.aug +3 -2
  339. package/examples/generic-di/types.aug.md +18 -97
  340. package/examples/generics/.aug-spec/manifest.json +1 -1
  341. package/examples/generics/main.aug +1 -0
  342. package/examples/generics/main.aug.md +9 -48
  343. package/examples/generics/types.aug +4 -3
  344. package/examples/generics/types.aug.md +18 -104
  345. package/examples/{developer-workflow/.aug-spec/august/0.19.0 → hello/.aug-spec/august/0.21.0}/io/contracts.aug +4 -3
  346. package/examples/hello/.aug-spec/august/0.21.0/io/contracts.aug.md +82 -0
  347. package/examples/hello/.aug-spec/manifest.json +3 -3
  348. package/examples/hello/app/export.aug +1 -0
  349. package/examples/hello/app/export.aug.md +3 -13
  350. package/examples/hello/app/greeter.aug +2 -1
  351. package/examples/hello/app/greeter.aug.md +10 -94
  352. package/examples/hello/logging/console.aug +2 -1
  353. package/examples/hello/logging/console.aug.md +7 -55
  354. package/examples/hello/logging/export.aug +1 -0
  355. package/examples/hello/logging/export.aug.md +3 -15
  356. package/examples/hello/logging/logger.aug +1 -0
  357. package/examples/hello/logging/logger.aug.md +6 -48
  358. package/examples/hello/main.aug +1 -0
  359. package/examples/hello/main.aug.md +8 -40
  360. package/examples/interceptors/.aug-spec/august/0.21.0/io/contracts.aug +37 -0
  361. package/examples/interceptors/.aug-spec/august/0.21.0/io/contracts.aug.md +82 -0
  362. package/examples/interceptors/.aug-spec/manifest.json +3 -3
  363. package/examples/interceptors/app.aug +3 -2
  364. package/examples/interceptors/app.aug.md +15 -141
  365. package/examples/interceptors/interceptors.aug +3 -2
  366. package/examples/interceptors/interceptors.aug.md +19 -152
  367. package/examples/interceptors/logging.aug +2 -1
  368. package/examples/interceptors/logging.aug.md +10 -79
  369. package/examples/interceptors/main.aug +1 -0
  370. package/examples/interceptors/main.aug.md +9 -66
  371. package/examples/native-blake3/.aug-spec/manifest.json +16 -0
  372. package/examples/native-blake3/.aug-spec/packages/@greenpandastudios/aug-blake3/0.1.1/native.abi.json +29 -0
  373. package/examples/native-blake3/.aug-spec/packages/@greenpandastudios/aug-blake3/0.1.3/api.aug +14 -0
  374. package/examples/native-blake3/.aug-spec/packages/@greenpandastudios/aug-blake3/0.1.3/api.aug.md +34 -0
  375. package/examples/native-blake3/.aug-spec/packages/@greenpandastudios/aug-blake3/0.1.3/contracts.aug +4 -0
  376. package/examples/native-blake3/.aug-spec/packages/@greenpandastudios/aug-blake3/0.1.3/contracts.aug.md +8 -0
  377. package/examples/native-blake3/.aug-spec/packages/@greenpandastudios/aug-blake3/0.1.3/native.abi.json +29 -0
  378. package/examples/native-blake3/AGENTS.md +5 -0
  379. package/examples/native-blake3/aug.lock.json +253 -0
  380. package/examples/native-blake3/hashing.aug +11 -0
  381. package/examples/native-blake3/hashing.aug.md +25 -0
  382. package/examples/native-blake3/main.aug +8 -0
  383. package/examples/native-blake3/main.aug.md +13 -0
  384. package/examples/native-pytorch/.aug-spec/manifest.json +18 -0
  385. package/examples/native-pytorch/.aug-spec/packages/@greenpandastudios/aug-pytorch/0.1.1/native.abi.json +142 -0
  386. package/examples/native-pytorch/.aug-spec/packages/@greenpandastudios/aug-pytorch/0.1.3/native.abi.json +142 -0
  387. package/examples/native-pytorch/.aug-spec/packages/@greenpandastudios/aug-pytorch/0.1.4/api.aug +101 -0
  388. package/examples/native-pytorch/.aug-spec/packages/@greenpandastudios/aug-pytorch/0.1.4/api.aug.md +160 -0
  389. package/examples/native-pytorch/.aug-spec/packages/@greenpandastudios/aug-pytorch/0.1.4/bindings.aug +3 -0
  390. package/examples/native-pytorch/.aug-spec/packages/@greenpandastudios/aug-pytorch/0.1.4/bindings.aug.md +8 -0
  391. package/examples/native-pytorch/.aug-spec/packages/@greenpandastudios/aug-pytorch/0.1.4/contracts.aug +6 -0
  392. package/examples/native-pytorch/.aug-spec/packages/@greenpandastudios/aug-pytorch/0.1.4/contracts.aug.md +13 -0
  393. package/examples/native-pytorch/.aug-spec/packages/@greenpandastudios/aug-pytorch/0.1.4/native.abi.json +142 -0
  394. package/examples/native-pytorch/AGENTS.md +5 -0
  395. package/examples/native-pytorch/aug.lock.json +309 -0
  396. package/examples/native-pytorch/main.aug +8 -0
  397. package/examples/native-pytorch/main.aug.md +13 -0
  398. package/examples/native-pytorch/tensors.aug +23 -0
  399. package/examples/native-pytorch/tensors.aug.md +35 -0
  400. package/examples/native-sqlite/.aug-spec/manifest.json +18 -0
  401. package/examples/native-sqlite/.aug-spec/packages/@greenpandastudios/aug-sqlite/0.1.2/native.abi.json +100 -0
  402. package/examples/native-sqlite/.aug-spec/packages/@greenpandastudios/aug-sqlite/0.1.3/api.aug +48 -0
  403. package/examples/native-sqlite/.aug-spec/packages/@greenpandastudios/aug-sqlite/0.1.3/api.aug.md +91 -0
  404. package/examples/native-sqlite/.aug-spec/packages/@greenpandastudios/aug-sqlite/0.1.3/bindings.aug +3 -0
  405. package/examples/native-sqlite/.aug-spec/packages/@greenpandastudios/aug-sqlite/0.1.3/bindings.aug.md +8 -0
  406. package/examples/native-sqlite/.aug-spec/packages/@greenpandastudios/aug-sqlite/0.1.3/contracts.aug +8 -0
  407. package/examples/native-sqlite/.aug-spec/packages/@greenpandastudios/aug-sqlite/0.1.3/contracts.aug.md +22 -0
  408. package/examples/native-sqlite/.aug-spec/packages/@greenpandastudios/aug-sqlite/0.1.3/native.abi.json +100 -0
  409. package/examples/native-sqlite/AGENTS.md +5 -0
  410. package/examples/native-sqlite/aug.lock.json +236 -0
  411. package/examples/native-sqlite/database.aug +15 -0
  412. package/examples/native-sqlite/database.aug.md +27 -0
  413. package/examples/native-sqlite/main.aug +8 -0
  414. package/examples/native-sqlite/main.aug.md +13 -0
  415. package/examples/native-zlib/.aug-spec/manifest.json +16 -0
  416. package/examples/native-zlib/.aug-spec/packages/@greenpandastudios/aug-zlib/0.1.1/native.abi.json +57 -0
  417. package/examples/native-zlib/.aug-spec/packages/@greenpandastudios/aug-zlib/0.1.3/api.aug +29 -0
  418. package/examples/native-zlib/.aug-spec/packages/@greenpandastudios/aug-zlib/0.1.3/api.aug.md +54 -0
  419. package/examples/native-zlib/.aug-spec/packages/@greenpandastudios/aug-zlib/0.1.3/contracts.aug +4 -0
  420. package/examples/native-zlib/.aug-spec/packages/@greenpandastudios/aug-zlib/0.1.3/contracts.aug.md +8 -0
  421. package/examples/native-zlib/.aug-spec/packages/@greenpandastudios/aug-zlib/0.1.3/native.abi.json +57 -0
  422. package/examples/native-zlib/AGENTS.md +5 -0
  423. package/examples/native-zlib/aug.lock.json +236 -0
  424. package/examples/native-zlib/compression.aug +15 -0
  425. package/examples/native-zlib/compression.aug.md +27 -0
  426. package/examples/native-zlib/main.aug +10 -0
  427. package/examples/native-zlib/main.aug.md +13 -0
  428. package/examples/new-syntax/.aug-spec/august/0.21.0/io/contracts.aug +37 -0
  429. package/examples/new-syntax/.aug-spec/august/0.21.0/io/contracts.aug.md +82 -0
  430. package/examples/new-syntax/.aug-spec/manifest.json +3 -3
  431. package/examples/new-syntax/console.aug +2 -1
  432. package/examples/new-syntax/console.aug.md +7 -53
  433. package/examples/new-syntax/greeter.aug +2 -1
  434. package/examples/new-syntax/greeter.aug.md +10 -74
  435. package/examples/new-syntax/logger.aug +1 -0
  436. package/examples/new-syntax/logger.aug.md +6 -46
  437. package/examples/new-syntax/main.aug +1 -0
  438. package/examples/new-syntax/main.aug.md +9 -54
  439. package/examples/new-syntax/math.aug +2 -1
  440. package/examples/new-syntax/math.aug.md +3 -24
  441. package/examples/oidc-login/.aug-spec/manifest.json +13 -13
  442. package/examples/oidc-login/.aug-spec/packages/@git/url_0eb7c89453c87681ed15/0.0.0-git.a39fc582565d4fca40be4f75fa304d71adc69301/store.aug.md +71 -0
  443. package/examples/oidc-login/.aug-spec/packages/@git/url_2d3c37c690c0fa115be1/0.0.0-git.a39fc582565d4fca40be4f75fa304d71adc69301/contracts.aug.md +17 -0
  444. package/examples/oidc-login/.aug-spec/packages/@git/url_897efafd565158fc4908/0.0.0-git.a39fc582565d4fca40be4f75fa304d71adc69301/contracts.aug.md +125 -0
  445. package/examples/oidc-login/.aug-spec/{august/0.19.0/crypto → packages/@git/url_9ef654c66d34ab8f5527/0.0.0-git.b14a0f9aa41f1ce58bd51133bcdc424033e40d40}/contracts.aug +12 -11
  446. package/examples/oidc-login/.aug-spec/packages/@git/url_9ef654c66d34ab8f5527/0.0.0-git.b14a0f9aa41f1ce58bd51133bcdc424033e40d40/contracts.aug.md +244 -0
  447. package/examples/oidc-login/.aug-spec/{august/0.19.0/crypto → packages/@git/url_9ef654c66d34ab8f5527/0.0.0-git.b14a0f9aa41f1ce58bd51133bcdc424033e40d40}/jose.aug +6 -5
  448. package/examples/oidc-login/.aug-spec/packages/@git/url_9ef654c66d34ab8f5527/0.0.0-git.b14a0f9aa41f1ce58bd51133bcdc424033e40d40/jose.aug.md +71 -0
  449. package/examples/oidc-login/.aug-spec/packages/@git/url_c092cd151499c4e1d8a1/0.0.0-git.a39fc582565d4fca40be4f75fa304d71adc69301/contracts.aug.md +30 -0
  450. package/examples/oidc-login/aug.lock.json +100 -0
  451. package/examples/oidc-login/client/contracts.aug +1 -0
  452. package/examples/oidc-login/client/contracts.aug.md +9 -66
  453. package/examples/oidc-login/client/endpoints.aug +6 -5
  454. package/examples/oidc-login/client/endpoints.aug.md +13 -145
  455. package/examples/oidc-login/client/export.aug +1 -0
  456. package/examples/oidc-login/client/export.aug.md +4 -24
  457. package/examples/oidc-login/client/login.aug +7 -6
  458. package/examples/oidc-login/client/login.aug.md +25 -303
  459. package/examples/oidc-login/client/logout.aug +5 -4
  460. package/examples/oidc-login/client/logout.aug.md +13 -135
  461. package/examples/oidc-login/client/protocol.aug +7 -6
  462. package/examples/oidc-login/client/protocol.aug.md +36 -283
  463. package/examples/oidc-login/client/session.aug +5 -4
  464. package/examples/oidc-login/client/session.aug.md +12 -139
  465. package/examples/oidc-login/client/views.aug +3 -2
  466. package/examples/oidc-login/client/views.aug.md +8 -57
  467. package/examples/oidc-login/common/export.aug +1 -0
  468. package/examples/oidc-login/common/export.aug.md +5 -27
  469. package/examples/oidc-login/common/headers.aug +4 -3
  470. package/examples/oidc-login/common/headers.aug.md +9 -67
  471. package/examples/oidc-login/common/keys.aug +6 -5
  472. package/examples/oidc-login/common/keys.aug.md +29 -165
  473. package/examples/oidc-login/common/settings.aug +2 -1
  474. package/examples/oidc-login/common/settings.aug.md +5 -39
  475. package/examples/oidc-login/common/views.aug +2 -1
  476. package/examples/oidc-login/common/views.aug.md +4 -28
  477. package/examples/oidc-login/main.aug +6 -16
  478. package/examples/oidc-login/main.aug.md +17 -146
  479. package/examples/oidc-login/main.yaml +7 -0
  480. package/examples/oidc-login/provider/authorization.aug +7 -6
  481. package/examples/oidc-login/provider/authorization.aug.md +23 -238
  482. package/examples/oidc-login/provider/contracts.aug +1 -0
  483. package/examples/oidc-login/provider/contracts.aug.md +23 -158
  484. package/examples/oidc-login/provider/credentials.aug +3 -2
  485. package/examples/oidc-login/provider/credentials.aug.md +9 -53
  486. package/examples/oidc-login/provider/discovery.aug +4 -3
  487. package/examples/oidc-login/provider/discovery.aug.md +11 -118
  488. package/examples/oidc-login/provider/export.aug +1 -0
  489. package/examples/oidc-login/provider/export.aug.md +6 -34
  490. package/examples/oidc-login/provider/token.aug +6 -5
  491. package/examples/oidc-login/provider/token.aug.md +16 -204
  492. package/examples/oidc-login/provider/userinfo.aug +4 -3
  493. package/examples/oidc-login/provider/userinfo.aug.md +10 -92
  494. package/examples/oidc-login/provider/views.aug +3 -2
  495. package/examples/oidc-login/provider/views.aug.md +8 -52
  496. package/examples/ownership/.aug-spec/manifest.json +1 -1
  497. package/examples/ownership/counter.aug +3 -2
  498. package/examples/ownership/counter.aug.md +12 -66
  499. package/examples/ownership/main.aug +1 -0
  500. package/examples/ownership/main.aug.md +6 -31
  501. package/examples/ownership-transfer/.aug-spec/august/0.21.0/io/contracts.aug +37 -0
  502. package/examples/ownership-transfer/.aug-spec/august/0.21.0/io/contracts.aug.md +82 -0
  503. package/examples/ownership-transfer/.aug-spec/manifest.json +3 -3
  504. package/examples/ownership-transfer/main.aug +1 -0
  505. package/examples/ownership-transfer/main.aug.md +9 -53
  506. package/examples/ownership-transfer/resource.aug +2 -1
  507. package/examples/ownership-transfer/resource.aug.md +12 -71
  508. package/examples/packages/app/.aug-spec/manifest.json +1 -1
  509. package/examples/packages/app/.aug-spec/packages/@example/aug-math/0.1.0/arithmetic.aug +2 -1
  510. package/examples/packages/app/.aug-spec/packages/@example/aug-math/0.1.0/arithmetic.aug.md +9 -51
  511. package/examples/packages/app/main.aug +1 -0
  512. package/examples/packages/app/main.aug.md +6 -26
  513. package/examples/packages/math/.aug-spec/manifest.json +1 -1
  514. package/examples/packages/math/aug-package.json +1 -1
  515. package/examples/packages/math/src/arithmetic.aug +2 -1
  516. package/examples/packages/math/src/arithmetic.aug.md +9 -51
  517. package/examples/packages/math/src/export.aug +1 -0
  518. package/examples/packages/math/src/export.aug.md +3 -13
  519. package/examples/visibility/.aug-spec/manifest.json +1 -1
  520. package/examples/visibility/counter.aug +4 -3
  521. package/examples/visibility/counter.aug.md +12 -68
  522. package/examples/visibility/main.aug +1 -0
  523. package/examples/visibility/main.aug.md +6 -32
  524. package/examples/weather-api/.aug-spec/manifest.json +8 -0
  525. package/examples/weather-api/AGENTS.md +17 -0
  526. package/examples/weather-api/README.md +19 -0
  527. package/examples/weather-api/forecasts.aug +47 -0
  528. package/examples/weather-api/forecasts.aug.md +32 -0
  529. package/examples/weather-api/main.aug +4 -0
  530. package/examples/weather-api/main.aug.md +15 -0
  531. package/examples/weather-api/main.yaml +5 -0
  532. package/examples/weather-api/weather.http +5 -0
  533. package/native/compiler-packs.json +43 -0
  534. package/package.json +4 -4
  535. package/runtime/aug_http.c +48 -21
  536. package/runtime/aug_http_ir.c +30 -0
  537. package/runtime/aug_http_ir.h +18 -0
  538. package/runtime/aug_ir.c +209 -0
  539. package/runtime/aug_ir.h +89 -0
  540. package/runtime/aug_json.c +6 -1
  541. package/runtime/aug_runtime.c +82 -16
  542. package/runtime/aug_runtime.h +16 -2
  543. package/runtime/aug_tasks.c +38 -7
  544. package/runtime/aug_values.c +12 -6
  545. package/scripts/bootstrap-native.mjs +184 -106
  546. package/scripts/native-setup.mjs +98 -0
  547. package/scripts/native-toolchain.mjs +28 -0
  548. package/src/ast.js +1 -1
  549. package/src/builtins.js +1 -1
  550. package/src/checker.js +369 -100
  551. package/src/cli.js +198 -26
  552. package/src/codegen.js +32 -7
  553. package/src/compiler-packs.js +66 -0
  554. package/src/config.js +3 -3
  555. package/src/contracts.js +10 -0
  556. package/src/editor.js +86 -22
  557. package/src/fixes.js +90 -2
  558. package/src/formatter.js +23 -10
  559. package/src/git-http.js +137 -0
  560. package/src/git-packages.js +118 -0
  561. package/src/help.js +33 -24
  562. package/src/http-contracts.js +14 -0
  563. package/src/http-policies.js +5 -5
  564. package/src/ir-types.js +5 -0
  565. package/src/ir-verify.js +277 -0
  566. package/src/ir.js +962 -0
  567. package/src/libraries.js +1 -1
  568. package/src/llvm-debug.js +101 -0
  569. package/src/llvm-native.js +152 -0
  570. package/src/llvm-platform.js +20 -0
  571. package/src/llvm.js +781 -0
  572. package/src/lsp.js +14 -5
  573. package/src/native-artifacts.js +207 -0
  574. package/src/native-bindings.js +189 -0
  575. package/src/native-contracts.js +295 -0
  576. package/src/native-declarations.js +68 -0
  577. package/src/native-facts.js +63 -0
  578. package/src/native.js +19 -13
  579. package/src/navigation.js +4 -2
  580. package/src/openapi.js +5 -4
  581. package/src/package-locking.js +88 -0
  582. package/src/package-manager.js +267 -68
  583. package/src/parser.js +32 -6
  584. package/src/policies.js +3 -3
  585. package/src/project-init.js +78 -4
  586. package/src/project.js +11 -9
  587. package/src/runtime-abi.js +23 -0
  588. package/src/runtime-adapters.js +18 -0
  589. package/src/schemas.js +24 -17
  590. package/src/semantic.js +54 -5
  591. package/src/snippets.js +60 -0
  592. package/src/spec-hints.js +56 -0
  593. package/src/spec-tree.js +241 -0
  594. package/src/spec.js +669 -305
  595. package/docs/examples/approved-design/dependencies/august/0.19.0/io/contracts.md +0 -395
  596. package/docs/examples/developer-workflow/dependencies/august/0.19.0/io/contracts.md +0 -395
  597. package/docs/examples/generic-di/dependencies/august/0.19.0/io/contracts.md +0 -395
  598. package/docs/examples/hello/dependencies/august/0.19.0/io/contracts.md +0 -395
  599. package/docs/examples/interceptors/dependencies/august/0.19.0/io/contracts.md +0 -395
  600. package/docs/examples/json-benchmark/dependencies/august/0.19.0/json/contracts.md +0 -103
  601. package/docs/examples/new-syntax/dependencies/august/0.19.0/io/contracts.md +0 -395
  602. package/docs/examples/oidc-login/dependencies/august/0.19.0/crypto/contracts.md +0 -925
  603. package/docs/examples/oidc-login/dependencies/august/0.19.0/crypto/jose.md +0 -434
  604. package/docs/examples/oidc-login/dependencies/august/0.19.0/json/contracts.md +0 -103
  605. package/docs/examples/oidc-login/dependencies/august/0.19.0/memory/store.md +0 -374
  606. package/docs/examples/oidc-login/dependencies/august/0.19.0/time/contracts.md +0 -150
  607. package/docs/examples/oidc-login/dependencies/august/0.19.0/web/contracts.md +0 -532
  608. package/docs/examples/ownership-transfer/dependencies/august/0.19.0/io/contracts.md +0 -395
  609. package/examples/approved-design/.aug-spec/august/0.19.0/io/contracts.aug.md +0 -316
  610. package/examples/developer-workflow/.aug-spec/august/0.19.0/io/contracts.aug.md +0 -316
  611. package/examples/generic-di/.aug-spec/august/0.19.0/io/contracts.aug.md +0 -316
  612. package/examples/hello/.aug-spec/august/0.19.0/io/contracts.aug.md +0 -316
  613. package/examples/interceptors/.aug-spec/august/0.19.0/io/contracts.aug +0 -36
  614. package/examples/interceptors/.aug-spec/august/0.19.0/io/contracts.aug.md +0 -316
  615. package/examples/new-syntax/.aug-spec/august/0.19.0/io/contracts.aug +0 -36
  616. package/examples/new-syntax/.aug-spec/august/0.19.0/io/contracts.aug.md +0 -316
  617. package/examples/oidc-login/.aug-spec/august/0.19.0/crypto/contracts.aug.md +0 -791
  618. package/examples/oidc-login/.aug-spec/august/0.19.0/crypto/jose.aug.md +0 -266
  619. package/examples/oidc-login/.aug-spec/august/0.19.0/json/contracts.aug.md +0 -55
  620. package/examples/oidc-login/.aug-spec/august/0.19.0/memory/store.aug.md +0 -250
  621. package/examples/oidc-login/.aug-spec/august/0.19.0/time/contracts.aug.md +0 -96
  622. package/examples/oidc-login/.aug-spec/august/0.19.0/web/contracts.aug.md +0 -420
  623. package/examples/ownership-transfer/.aug-spec/august/0.19.0/io/contracts.aug +0 -36
  624. package/examples/ownership-transfer/.aug-spec/august/0.19.0/io/contracts.aug.md +0 -316
  625. /package/examples/oidc-login/.aug-spec/{august/0.19.0/memory → packages/@git/url_0eb7c89453c87681ed15/0.0.0-git.a39fc582565d4fca40be4f75fa304d71adc69301}/store.aug +0 -0
  626. /package/examples/oidc-login/.aug-spec/{august/0.19.0/json → packages/@git/url_2d3c37c690c0fa115be1/0.0.0-git.a39fc582565d4fca40be4f75fa304d71adc69301}/contracts.aug +0 -0
  627. /package/examples/oidc-login/.aug-spec/{august/0.19.0/web → packages/@git/url_897efafd565158fc4908/0.0.0-git.a39fc582565d4fca40be4f75fa304d71adc69301}/contracts.aug +0 -0
  628. /package/examples/oidc-login/.aug-spec/{august/0.19.0/time → packages/@git/url_c092cd151499c4e1d8a1/0.0.0-git.a39fc582565d4fca40be4f75fa304d71adc69301}/contracts.aug +0 -0
package/src/llvm.js ADDED
@@ -0,0 +1,781 @@
1
+ import { runtimeOperations as operations, httpOperations, schemaKinds } from "./runtime-abi.js";
2
+ import { verifyIR } from "./ir-verify.js";
3
+ import { DebugMetadata } from "./llvm-debug.js";
4
+ export const runtimeLayout = { abi: 'compiler-private-runtime-v1', valueSize: 16, valueAlignment: 8, valuePayloadOffset: 8, frameSize: 24, methodEntrySize: 24, pointerSize: 8, schemaSize: 48, schemaPointerMakerOffset: 40, routeSize: 56, routePointerHandlerOffset: 48, policySize: 56, httpErrorSize: 16, executionErrorOffset: 40, executionCancelledOffset: 41, executionFiberOffset: 48, booleanSize: 1 };
5
+ const symbol = (name) => '@' + name;
6
+ /** Emit LLVM directly from checked August execution IR. No application C is generated. */
7
+ export function generateLLVM(ir, options = {}) {
8
+ verifyIR(ir);
9
+ if (JSON.stringify(options.layout ?? runtimeLayout) !== JSON.stringify(runtimeLayout))
10
+ throw new Error('NATIVE_ABI: Runtime pack layout differs from this compiler');
11
+ const module = new ModuleEmitter(ir, options.triple ?? 'arm64-apple-macosx14.0.0', !!options.release);
12
+ return module.generate();
13
+ }
14
+ class ModuleEmitter {
15
+ ir;
16
+ triple;
17
+ globals = [];
18
+ declarations = new Map();
19
+ debug;
20
+ strings = new Map();
21
+ sequence = 0;
22
+ constructor(ir, triple, release) { this.ir = ir; this.triple = triple; this.debug = new DebugMetadata(ir, release); }
23
+ text(value) {
24
+ const found = this.strings.get(value);
25
+ if (found)
26
+ return found;
27
+ const name = '@aug_text_' + this.sequence++, bytes = Buffer.from(value + '\0', 'utf8');
28
+ const escaped = [...bytes].map(b => b >= 32 && b < 127 && b !== 34 && b !== 92 ? String.fromCharCode(b) : '\\' + b.toString(16).padStart(2, '0').toUpperCase()).join('');
29
+ this.globals.push(`${name} = private unnamed_addr constant [${bytes.length} x i8] c"${escaped}", align 1`);
30
+ this.strings.set(value, name);
31
+ return name;
32
+ }
33
+ declare(name, result, params) {
34
+ const signature = `declare ${result} @${name}(${params.join(', ')})`;
35
+ const previous = this.declarations.get(name);
36
+ if (previous && previous !== signature)
37
+ throw new Error('NATIVE_ABI: Conflicting physical signatures for ' + name);
38
+ this.declarations.set(name, signature);
39
+ }
40
+ table(prefix, fields, owned, methods) {
41
+ const name = '@aug_table_' + this.sequence++, names = name + '_names', mask = name + '_owned';
42
+ this.globals.push(`${names} = private constant [${Math.max(1, fields.length)} x ptr] [${fields.length ? fields.map(f => 'ptr ' + this.text(f)).join(', ') : 'ptr null'}]`);
43
+ this.globals.push(`${mask} = private constant [${Math.max(1, owned.length)} x i8] [${owned.length ? owned.map(o => 'i8 ' + (o ? 1 : 0)).join(', ') : 'i8 0'}]`);
44
+ this.globals.push(`${name} = private constant [${Math.max(1, methods.length)} x %AugMethodEntry] [${methods.length ? methods.map(m => `%AugMethodEntry {ptr ${this.text(m.name)}, ptr null, ptr @${m.function}}`).join(', ') : '%AugMethodEntry zeroinitializer'}]`);
45
+ return { name, names, mask };
46
+ }
47
+ policyValue(policy) { return `{i32 ${policy.kind}, ptr ${this.text(policy.permission)}, i64 ${policy.amount}, i64 ${policy.seconds}, i8 ${policy.credentials ? 1 : 0}, ptr ${this.text(policy.origins)}, ptr ${this.text(policy.headers)}}`; }
48
+ policy(policy) { const name = '@aug_policy_' + this.sequence++; this.globals.push(`${name} = private constant %AugHttpPolicy ${this.policyValue(policy)}, align 8`); return name; }
49
+ generate() {
50
+ const bodies = this.ir.functions.map(fn => new FunctionEmitter(this, fn).generate());
51
+ const kinds = schemaKinds;
52
+ for (const schema of this.ir.schemas) {
53
+ const kind = kinds.indexOf(schema.kind);
54
+ if (kind < 0)
55
+ throw new Error('Unknown IR schema kind ' + schema.kind);
56
+ const fields = '@' + schema.name + '_fields', names = '@' + schema.name + '_names';
57
+ if (schema.fields.length)
58
+ this.globals.push(`${fields} = private constant [${schema.fields.length} x ptr] [${schema.fields.map(field => 'ptr @' + field).join(', ')}]`);
59
+ if (schema.labels.length)
60
+ this.globals.push(`${names} = private constant [${schema.labels.length} x ptr] [${schema.labels.map(name => 'ptr ' + this.text(name)).join(', ')}]`);
61
+ this.globals.push(`@${schema.name} = private constant %AugSchema {i32 ${kind}, i8 ${schema.nullable ? 1 : 0}, i8 ${schema.optional ? 1 : 0}, i64 ${schema.fields.length}, ptr ${schema.fields.length ? fields : 'null'}, ptr ${schema.labels.length ? names : 'null'}, ptr null, ptr ${schema.maker ? '@' + schema.maker : 'null'}}, align 8`);
62
+ }
63
+ for (const table of this.ir.routes) {
64
+ const routes = table.items.map((route, index) => {
65
+ const policies = '@' + table.name + '_policies_' + index;
66
+ if (route.policies.length)
67
+ this.globals.push(`${policies} = private constant [${route.policies.length} x %AugHttpPolicy] [${route.policies.map(policy => '%AugHttpPolicy ' + this.policyValue(policy)).join(', ')}], align 8`);
68
+ return `%AugRoute {ptr ${this.text(route.method)}, ptr ${this.text(route.path)}, ptr null, i32 ${route.stream}, i32 ${route.status}, ptr ${route.policies.length ? policies : 'null'}, i64 ${route.policies.length}, ptr @${route.function}}`;
69
+ });
70
+ this.globals.push(`@${table.name} = private constant [${routes.length} x %AugRoute] [${routes.join(', ')}], align 8`);
71
+ }
72
+ this.declare('aug_register_globals', 'void', ['ptr', 'i64']);
73
+ this.declare('aug_set_cli_args', 'void', ['i32', 'ptr']);
74
+ this.declare('aug_ir_exit_status', 'i32', ['i1 zeroext']);
75
+ this.declare('aug_shutdown', 'void', []);
76
+ const globalCount = this.ir.bindings.length;
77
+ const coverage = this.ir.coverage.map(point => ` call void @aug_coverage_register(ptr ${this.text(point.file)}, i64 ${point.line})`);
78
+ if (coverage.length)
79
+ this.declare('aug_coverage_register', 'void', ['ptr', 'i64']);
80
+ const web = this.ir.web, configure = this.ir.components.includes('http') ? [
81
+ ` call void @aug_http_configure(ptr ${this.text(web.host)}, ptr ${this.text(web.tls.certificate)}, ptr ${this.text(web.tls.private_key)}, ptr ${this.text(web.tls.ca)}, i64 ${web.body_limit}, i64 ${web.response_limit}, i1 zeroext ${web.http3 ? 'true' : 'false'})`
82
+ ] : [];
83
+ if (configure.length)
84
+ this.declare('aug_http_configure', 'void', ['ptr', 'ptr', 'ptr', 'ptr', 'i64', 'i64', 'i1 zeroext']);
85
+ const startup = this.ir.bindings.filter(b => b.shared).flatMap((b, i) => [
86
+ ` call void @${b.function}(ptr %result, ptr null, ptr null, i32 0)`,
87
+ ` %binding_error_${i} = call zeroext i1 @aug_ir_has_error()`,
88
+ ` br i1 %binding_error_${i}, label %done, label %binding_ready_${i}`,
89
+ `binding_ready_${i}:`
90
+ ]);
91
+ const entryFunction = { ...this.ir.functions.find(fn => fn.name === this.ir.main), name: 'main', sourceName: 'August entry' };
92
+ const entrySubprogram = this.debug.function(entryFunction), entryLocation = this.debug.location(entryFunction, entryFunction.span);
93
+ const main = [`define i32 @main(i32 %argc, ptr %argv) !dbg ${entrySubprogram} {`, `entry:`, ` %result = alloca %AugValue, align 8`, ` store %AugValue zeroinitializer, ptr %result, align 8`,
94
+ ` call void @aug_register_globals(ptr @aug_globals, i64 ${globalCount})`, ` call void @aug_set_cli_args(i32 %argc, ptr %argv)`, ...coverage, ...configure, ...startup,
95
+ ` %startup_error = call zeroext i1 @aug_ir_has_error()`, ` br i1 %startup_error, label %done, label %run`, `run:`,
96
+ ` call void @${this.ir.main}(ptr %result, ptr null, ptr null, i32 0)`, ` br label %done`, `done:`,
97
+ ` %status = call i32 @aug_ir_exit_status(i1 zeroext ${this.ir.test ? 'true' : 'false'})`, ` call void @aug_shutdown()`, ` ret i32 %status`, `}`].map(line => line.startsWith(' ') ? line + ', !dbg ' + entryLocation : line).join('\n');
98
+ this.declare('aug_ir_has_error', 'zeroext i1', []);
99
+ return [`; August checked execution IR ${this.ir.format}; source revision ${this.ir.sourceRevision}`, `target triple = "${this.triple}"`,
100
+ `%AugValue = type {i32, i64}`, `%AugFrame = type {ptr, i64, ptr}`, `%AugMethodEntry = type {ptr, ptr, ptr}`, `%AugSchema = type {i32, i8, i8, i64, ptr, ptr, ptr, ptr}`, `%NativeError = type {i32, i32, [512 x i8]}`,
101
+ `%AugRoute = type {ptr, ptr, ptr, i32, i32, ptr, i64, ptr}`, `%AugHttpPolicy = type {i32, ptr, i64, i64, i8, ptr, ptr}`, `%AugHttpError = type {ptr, i32}`,
102
+ `@aug_globals = internal global [${Math.max(1, globalCount)} x %AugValue] zeroinitializer, align 8`,
103
+ `@aug_task_checkpoint_hook = external global ptr, align 8`,
104
+ `@aug_scoped = private constant [${Math.max(1, globalCount)} x i8] [${globalCount ? this.ir.scoped.map(scoped => 'i8 ' + (scoped ? 1 : 0)).join(', ') : 'i8 0'}]`, ...this.globals, ...this.declarations.values(), ...bodies, main, this.debug.generate(), ''].join('\n\n');
105
+ }
106
+ }
107
+ class FunctionEmitter {
108
+ module;
109
+ fn;
110
+ sequence = 0;
111
+ lines = [];
112
+ allocations = [];
113
+ debugLocation;
114
+ pairedStates = new Map();
115
+ errorStates = new Map();
116
+ constructor(module, fn) {
117
+ this.module = module;
118
+ this.fn = fn;
119
+ const incoming = new Map(), blocks = new Map(fn.blocks.map(block => [block.name, block]));
120
+ for (const block of fn.blocks) {
121
+ const t = block.terminator;
122
+ const targets = t.op === 'jump' ? [t.target] : t.op === 'return' ? [] : t.op === 'error' ? [t.failed, t.success] : [t.then, t.otherwise];
123
+ for (const target of targets)
124
+ incoming.set(target, (incoming.get(target) ?? 0) + 1);
125
+ }
126
+ for (const block of fn.blocks) {
127
+ const t = block.terminator;
128
+ if (t.op !== 'cancel')
129
+ continue;
130
+ const next = blocks.get(t.otherwise);
131
+ if (next && incoming.get(next.name) === 1 && !next.instructions.length && next.terminator.op === 'error') {
132
+ const state = this.temp('state');
133
+ this.pairedStates.set(block.name, state);
134
+ this.errorStates.set(next.name, state);
135
+ }
136
+ }
137
+ }
138
+ temp(prefix = 'value') { return '%' + prefix + '_' + this.sequence++; }
139
+ label(prefix = 'native') { return prefix + '_' + this.sequence++; }
140
+ line(value) { this.lines.push(' ' + value + (this.debugLocation ? ', !dbg ' + this.debugLocation : '')); }
141
+ allocate(type) { const name = this.temp('storage'); this.allocations.push(` ${name} = alloca ${type}, align 8`); return name; }
142
+ ptr(slot) { return '%slot_' + slot; }
143
+ /** The maintainer pack measures these private offsets on the target. A
144
+ * function keeps its own execution pointer across cooperative suspension,
145
+ * matching the existing C backend; another fiber cannot dispose its frame. */
146
+ executionFlag(offset) {
147
+ const value = this.temp(), condition = this.temp();
148
+ this.line(`${value} = load i8, ptr ${offset === runtimeLayout.executionErrorOffset ? '%execution_error' : '%execution_cancelled'}, align 1`);
149
+ this.line(`${condition} = icmp ne i8 ${value}, 0`);
150
+ return condition;
151
+ }
152
+ load(slot) { const name = this.temp(); this.line(`${name} = load %AugValue, ptr ${this.ptr(slot)}, align 8`); return name; }
153
+ store(slot, value) { this.line(`store %AugValue ${value}, ptr ${this.ptr(slot)}, align 8`); }
154
+ clear(slot) { this.store(slot, 'zeroinitializer'); }
155
+ call(name, result, params) {
156
+ this.module.declare(name, result, params.map(p => p.type));
157
+ const target = result === 'void' ? '' : this.temp('call');
158
+ this.line(`${target ? target + ' = ' : ''}call ${result} @${name}(${params.map(p => p.type + ' ' + p.value).join(', ')})`);
159
+ return target;
160
+ }
161
+ args(slots) {
162
+ if (!slots.length)
163
+ return 'null';
164
+ const array = this.allocate(`[${slots.length} x %AugValue]`);
165
+ slots.forEach((slot, i) => { const ptr = this.temp('arg'); this.line(`${ptr} = getelementptr [${slots.length} x %AugValue], ptr ${array}, i64 0, i64 ${i}`); this.line(`store %AugValue ${this.load(slot)}, ptr ${ptr}, align 8`); });
166
+ return array;
167
+ }
168
+ boxed(out, tag, payload) { const a = this.temp(), b = this.temp(); this.line(`${a} = insertvalue %AugValue zeroinitializer, i32 ${tag}, 0`); this.line(`${b} = insertvalue %AugValue ${a}, i64 ${payload}, 1`); this.store(out, b); }
169
+ integer(slot) { return this.call('aug_ir_integer', 'i64', [{ type: 'ptr', value: this.ptr(slot) }]); }
170
+ float(slot) { return this.call('aug_ir_float', 'double', [{ type: 'ptr', value: this.ptr(slot) }]); }
171
+ floats(bits) { const value = this.temp(); this.line(`${value} = bitcast double ${bits} to i64`); return value; }
172
+ directType(type) { return type === 'int' ? 'i64' : type === 'c_int' ? 'i32' : type === 'float' ? 'double' : type === 'bool' ? 'i1' : type === 'string' ? 'ptr' : 'void'; }
173
+ nativeType(view) { return view.kind === 'i64' ? 'i64' : view.kind === 'i32' ? 'i32' : view.kind === 'f64' ? 'double' : view.kind === 'bool' ? 'i8' : view.kind === 'void' ? 'void' : 'ptr'; }
174
+ scalarKind(slot) {
175
+ const type = this.fn.values[slot].type;
176
+ return this.fn.values[slot].storage === 'scalar-value' && ['int', 'float', 'bool'].includes(type.name) ? type.name : undefined;
177
+ }
178
+ payload(slot) { const value = this.temp(); this.line(`${value} = extractvalue %AugValue ${this.load(slot)}, 1`); return value; }
179
+ scalarBoolean(slot) { const byte = this.temp(), condition = this.temp(); this.line(`${byte} = trunc i64 ${this.payload(slot)} to i8`); this.line(`${condition} = icmp ne i8 ${byte}, 0`); return condition; }
180
+ boxBoolean(out, condition) { const payload = this.temp(); this.line(`${payload} = zext i1 ${condition} to i64`); this.boxed(out, 3, payload); }
181
+ /** A widened float slot can still contain an integer. Preserve that case,
182
+ * including integer division and wraparound, before emitting strict FP IR. */
183
+ floatingOperation(i, left, right) {
184
+ const operator = i.text, arithmetic = { '+': 'fadd', '-': 'fsub', '*': 'fmul', '/': 'fdiv' }, comparisons = { '==': 'oeq', '!=': 'une', '<': 'olt', '>': 'ogt', '<=': 'ole', '>=': 'oge' };
185
+ if (!operator || (!arithmetic[operator] && !comparisons[operator]))
186
+ return false;
187
+ const number = (slot) => {
188
+ const stored = this.load(slot), tag = this.temp(), payload = this.temp(), integer = this.temp(), converted = this.temp(), bits = this.temp(), value = this.temp();
189
+ this.line(`${tag} = extractvalue %AugValue ${stored}, 0`);
190
+ this.line(`${payload} = extractvalue %AugValue ${stored}, 1`);
191
+ this.line(`${integer} = icmp eq i32 ${tag}, 1`);
192
+ this.line(`${converted} = sitofp i64 ${payload} to double`);
193
+ this.line(`${bits} = bitcast i64 ${payload} to double`);
194
+ this.line(`${value} = select i1 ${integer}, double ${converted}, double ${bits}`);
195
+ return { integer, value };
196
+ };
197
+ const a = number(left), b = number(right), both = this.temp(), fallback = this.label('number_runtime'), native = this.label('number_native'), done = this.label('number_done');
198
+ this.line(`${both} = and i1 ${a.integer}, ${b.integer}`);
199
+ let slow = both;
200
+ if (operator === '/') {
201
+ const zero = this.temp();
202
+ slow = this.temp();
203
+ this.line(`${zero} = fcmp oeq double ${b.value}, 0.0`);
204
+ this.line(`${slow} = or i1 ${both}, ${zero}`);
205
+ }
206
+ this.line(`br i1 ${slow}, label %${fallback}, label %${native}`);
207
+ this.lines.push(fallback + ':');
208
+ this.call('aug_ir_binary', 'void', [{ type: 'ptr', value: this.ptr(i.out) }, { type: 'ptr', value: this.module.text(operator) }, ...i.args.map(slot => ({ type: 'ptr', value: this.ptr(slot) }))]);
209
+ this.line(`br label %${done}`);
210
+ this.lines.push(native + ':');
211
+ const result = this.temp();
212
+ if (comparisons[operator]) {
213
+ this.line(`${result} = fcmp ${comparisons[operator]} double ${a.value}, ${b.value}`);
214
+ this.boxBoolean(i.out, result);
215
+ }
216
+ else {
217
+ this.line(`${result} = ${arithmetic[operator]} double ${a.value}, ${b.value}`);
218
+ const payload = this.temp();
219
+ this.line(`${payload} = bitcast double ${result} to i64`);
220
+ this.boxed(i.out, 2, payload);
221
+ }
222
+ this.line(`br label %${done}`);
223
+ this.lines.push(done + ':');
224
+ return true;
225
+ }
226
+ /** Preserve wrapping integer operations and the actual widened numeric tags. */
227
+ scalarOperation(i) {
228
+ const [left, right] = i.args, kind = this.scalarKind(left), operator = i.text;
229
+ if (i.operation === 'UNARY') {
230
+ if (operator === '!' && kind === 'bool') {
231
+ const result = this.temp();
232
+ this.line(`${result} = xor i1 ${this.scalarBoolean(left)}, true`);
233
+ this.boxBoolean(i.out, result);
234
+ return true;
235
+ }
236
+ if (operator === '-' && kind === 'int') {
237
+ const result = this.temp(), value = this.payload(left);
238
+ this.line(`${result} = sub i64 0, ${value}`);
239
+ this.boxed(i.out, 1, result);
240
+ return true;
241
+ }
242
+ return false;
243
+ }
244
+ if (i.operation !== 'BINARY')
245
+ return false;
246
+ const other = this.scalarKind(right), comparisons = { '==': 'eq', '!=': 'ne', '<': 'slt', '>': 'sgt', '<=': 'sle', '>=': 'sge' };
247
+ if (kind === 'bool' && other === 'bool' && (operator === '==' || operator === '!=')) {
248
+ const a = this.scalarBoolean(left), b = this.scalarBoolean(right), result = this.temp();
249
+ this.line(`${result} = icmp ${comparisons[operator]} i1 ${a}, ${b}`);
250
+ this.boxBoolean(i.out, result);
251
+ return true;
252
+ }
253
+ if (['int', 'float'].includes(kind ?? '') && ['int', 'float'].includes(other ?? '') && (kind === 'float' || other === 'float'))
254
+ return this.floatingOperation(i, left, right);
255
+ if (kind !== 'int' || other !== 'int')
256
+ return false;
257
+ const comparison = operator && comparisons[operator], arithmetic = { '+': 'add', '-': 'sub', '*': 'mul' };
258
+ if (operator === '/') {
259
+ const a = this.payload(left), b = this.payload(right), zero = this.temp(), failed = this.label('division_zero'), success = this.label('division_value'), done = this.label('division_done');
260
+ this.line(`${zero} = icmp eq i64 ${b}, 0`);
261
+ this.line(`br i1 ${zero}, label %${failed}, label %${success}`);
262
+ this.lines.push(failed + ':');
263
+ this.call('aug_ir_binary', 'void', [{ type: 'ptr', value: this.ptr(i.out) }, { type: 'ptr', value: this.module.text('/') }, ...i.args.map(slot => ({ type: 'ptr', value: this.ptr(slot) }))]);
264
+ this.line(`br label %${done}`);
265
+ this.lines.push(success + ':');
266
+ const minimum = this.temp(), negativeOne = this.temp(), overflow = this.temp(), safeDivisor = this.temp(), result = this.temp();
267
+ this.line(`${minimum} = icmp eq i64 ${a}, -9223372036854775808`);
268
+ this.line(`${negativeOne} = icmp eq i64 ${b}, -1`);
269
+ this.line(`${overflow} = and i1 ${minimum}, ${negativeOne}`);
270
+ this.line(`${safeDivisor} = select i1 ${overflow}, i64 1, i64 ${b}`);
271
+ this.line(`${result} = sdiv i64 ${a}, ${safeDivisor}`);
272
+ this.boxed(i.out, 1, result);
273
+ this.line(`br label %${done}`);
274
+ this.lines.push(done + ':');
275
+ return true;
276
+ }
277
+ if (!comparison && !arithmetic[operator ?? ''])
278
+ return false;
279
+ const a = this.payload(left), b = this.payload(right), result = this.temp();
280
+ if (comparison) {
281
+ this.line(`${result} = icmp ${comparison} i64 ${a}, ${b}`);
282
+ this.boxBoolean(i.out, result);
283
+ }
284
+ else {
285
+ this.line(`${result} = ${arithmetic[operator]} i64 ${a}, ${b}`);
286
+ this.boxed(i.out, 1, result);
287
+ }
288
+ return true;
289
+ }
290
+ instruction(i) {
291
+ switch (i.op) {
292
+ case 'literal': {
293
+ if (i.numeric) {
294
+ if (i.numeric.kind === 'int')
295
+ this.boxed(i.out, 1, i.numeric.text);
296
+ else {
297
+ const bytes = Buffer.alloc(8);
298
+ bytes.writeDoubleBE(Number(i.numeric.text));
299
+ this.boxed(i.out, 2, this.floats('0x' + bytes.toString('hex').toUpperCase()));
300
+ }
301
+ }
302
+ else if (typeof i.value === 'string')
303
+ this.call('aug_ir_string', 'void', [{ type: 'ptr', value: this.ptr(i.out) }, { type: 'ptr', value: this.module.text(i.value) }, { type: 'i64', value: String(Buffer.byteLength(i.value)) }]);
304
+ else if (typeof i.value === 'boolean')
305
+ this.boxed(i.out, 3, i.value ? '1' : '0');
306
+ else
307
+ this.clear(i.out);
308
+ return;
309
+ }
310
+ case 'copy':
311
+ this.store(i.out, this.load(i.input));
312
+ return;
313
+ case 'clear':
314
+ this.clear(i.slot);
315
+ return;
316
+ case 'cover':
317
+ this.call('aug_cover', 'void', [{ type: 'ptr', value: this.module.text(i.file) }, { type: 'i64', value: String(i.line) }]);
318
+ return;
319
+ case 'debug-variable':
320
+ this.lines.push(this.variable(this.fn.variables[i.variable]));
321
+ return;
322
+ case 'runtime': {
323
+ if ((i.operation === 'BINARY' || i.operation === 'UNARY') && this.scalarOperation(i))
324
+ return;
325
+ if (i.operation === 'BINARY' || i.operation === 'UNARY') {
326
+ this.call('aug_ir_' + i.operation.toLowerCase(), 'void', [{ type: 'ptr', value: this.ptr(i.out) }, { type: 'ptr', value: this.module.text(i.text) }, ...i.args.map(slot => ({ type: 'ptr', value: this.ptr(slot) }))]);
327
+ return;
328
+ }
329
+ if (['LIST', 'TUPLE', 'SET'].includes(i.operation)) {
330
+ this.call('aug_ir_' + i.operation.toLowerCase() + '_new', 'void', [{ type: 'ptr', value: this.ptr(i.out) }, { type: 'ptr', value: this.args(i.args) }, { type: 'i32', value: String(i.args.length) }]);
331
+ return;
332
+ }
333
+ const services = { PRINT: 'void', MAP: 'value', ITER: 'value', MAP_ITER: 'value', LIST_APPEND: 'void', TUPLE_LENGTH: 'i64', TUPLE_GET: 'value', STRING_LENGTH: 'i64', STRING_BYTES: 'value', STRING_SPLIT: 'value', MAP_SET: 'void', SET_ADD: 'void', SET_CONTAINS: 'i8', MAP_CONTAINS: 'i8', LIST_LENGTH: 'i64', SET_LENGTH: 'i64', MAP_LENGTH: 'i64', LIST_GET: 'value', LIST_AT: 'value', MAP_GET: 'value', MAP_TAKE: 'value' };
334
+ const result = services[i.operation];
335
+ if (result) {
336
+ const args = i.args.map(slot => ({ type: 'ptr', value: this.ptr(slot) }));
337
+ const value = this.call('aug_ir_' + i.operation.toLowerCase(), result === 'value' ? 'void' : result, result === 'value' ? [{ type: 'ptr', value: this.ptr(i.out) }, ...args] : args);
338
+ if (result === 'void')
339
+ this.clear(i.out);
340
+ else if (result === 'i64')
341
+ this.boxed(i.out, 1, value);
342
+ else if (result === 'i8') {
343
+ const payload = this.temp();
344
+ this.line(`${payload} = zext i8 ${value} to i64`);
345
+ this.boxed(i.out, 3, payload);
346
+ }
347
+ return;
348
+ }
349
+ const http = i.operation.startsWith('HTTP_'), catalog = http ? httpOperations : operations, op = catalog.indexOf(i.operation) + 1;
350
+ if (!op)
351
+ throw new Error('Unknown IR runtime operation ' + i.operation);
352
+ this.call(http ? 'aug_ir_http_operation' : 'aug_ir_operation', 'void', [{ type: 'ptr', value: this.ptr(i.out) }, { type: 'i32', value: String(op) }, { type: 'ptr', value: this.args(i.args) }, { type: 'i32', value: String(i.args.length) }, { type: 'ptr', value: i.text === undefined ? 'null' : this.module.text(i.text) }, { type: 'i64', value: String(i.number ?? 0) }]);
353
+ return;
354
+ }
355
+ case 'decode':
356
+ this.call(i.format === 'form' ? 'aug_ir_http_form' : 'aug_ir_json_decode', 'void', [{ type: 'ptr', value: this.ptr(i.out) }, { type: 'ptr', value: this.ptr(i.input) }, { type: 'ptr', value: '@' + i.schema }]);
357
+ return;
358
+ case 'adapter':
359
+ this.call(i.name, 'void', [{ type: 'ptr', value: this.ptr(i.out) }, { type: 'ptr', value: this.args(i.args) }, { type: 'i32', value: String(i.args.length) }]);
360
+ return;
361
+ case 'html':
362
+ this.call('aug_ir_html', 'void', [{ type: 'ptr', value: this.ptr(i.out) }, { type: 'ptr', value: this.module.text(i.tag) }, { type: 'ptr', value: this.args(i.attributes) }, { type: 'i32', value: String(i.attributes.length / 2) }, { type: 'ptr', value: this.args(i.children) }, { type: 'i32', value: String(i.children.length) }]);
363
+ return;
364
+ case 'http-bind':
365
+ this.call('aug_ir_http_bind', 'void', [{ type: 'ptr', value: this.ptr(i.out) }, { type: 'ptr', value: this.ptr(i.request) }, { type: 'ptr', value: this.module.text(i.source) }, { type: 'ptr', value: this.module.text(i.name) }, { type: 'ptr', value: i.schema ? '@' + i.schema : 'null' }]);
366
+ return;
367
+ case 'http-policy':
368
+ this.call('aug_ir_http_policy', 'void', [{ type: 'ptr', value: this.module.policy(i.policy) }, { type: 'ptr', value: this.args(i.args) }]);
369
+ return;
370
+ case 'http-failure': {
371
+ const errors = this.allocate(`[${Math.max(1, i.errors.length)} x %AugHttpError]`);
372
+ this.line(`store [${Math.max(1, i.errors.length)} x %AugHttpError] [${i.errors.length ? i.errors.map(error => `%AugHttpError {ptr ${this.module.text(error.type)}, i32 ${error.status}}`).join(', ') : '%AugHttpError zeroinitializer'}], ptr ${errors}, align 8`);
373
+ this.call('aug_ir_http_failure', 'void', [{ type: 'ptr', value: this.ptr(i.out) }, { type: 'ptr', value: errors }, { type: 'i32', value: String(i.errors.length) }]);
374
+ return;
375
+ }
376
+ case 'routes': {
377
+ const count = this.module.ir.routes.find(table => table.name === i.name).items.length;
378
+ if (i.port !== undefined)
379
+ this.call('aug_ir_http_serve', 'void', [{ type: 'ptr', value: '@' + i.name }, { type: 'i32', value: String(count) }, { type: 'ptr', value: this.ptr(i.port) }]);
380
+ else
381
+ this.call('aug_ir_http_test_client', 'void', [{ type: 'ptr', value: this.ptr(i.out) }, { type: 'ptr', value: '@' + i.name }, { type: 'i32', value: String(count) }]);
382
+ return;
383
+ }
384
+ case 'call':
385
+ this.line(`call void @${i.function}(ptr ${this.ptr(i.out)}, ptr ${i.receiver === undefined ? 'null' : this.ptr(i.receiver)}, ptr ${this.args(i.args)}, i32 ${i.args.length})`);
386
+ return;
387
+ case 'method':
388
+ this.call('aug_ir_method', 'void', [{ type: 'ptr', value: this.ptr(i.out) }, { type: 'ptr', value: this.ptr(i.receiver) }, { type: 'ptr', value: this.module.text(i.name) }, { type: 'ptr', value: this.args(i.args) }, { type: 'i32', value: String(i.args.length) }]);
389
+ return;
390
+ case 'start': {
391
+ const mask = this.allocate(`[${Math.max(1, i.owned.length)} x i8]`);
392
+ this.line(`store [${Math.max(1, i.owned.length)} x i8] [${i.owned.length ? i.owned.map(own => 'i8 ' + (own ? 1 : 0)).join(', ') : 'i8 0'}], ptr ${mask}, align 1`);
393
+ this.call('aug_task_start_pointer', 'void', [{ type: 'ptr', value: this.ptr(i.out) }, { type: 'ptr', value: '@' + i.function }, { type: 'ptr', value: i.receiver === undefined ? 'null' : this.ptr(i.receiver) }, { type: 'ptr', value: this.args(i.args) }, { type: 'i32', value: String(i.args.length) }, { type: 'ptr', value: mask }]);
394
+ return;
395
+ }
396
+ case 'wait':
397
+ this.call('aug_ir_task_wait', 'void', [{ type: 'ptr', value: this.ptr(i.out) }, { type: 'ptr', value: this.args(i.tasks) }, { type: 'i32', value: String(i.tasks.length) }]);
398
+ return;
399
+ case 'checkpoint': {
400
+ const fiber = this.temp(), hook = this.temp(), active = this.temp(), observed = this.temp(), needed = this.temp(), run = this.label('checkpoint'), done = this.label('checkpoint_done');
401
+ this.line(`${fiber} = load ptr, ptr %execution_fiber, align 8`);
402
+ this.line(`${hook} = load ptr, ptr @aug_task_checkpoint_hook, align 8`);
403
+ this.line(`${active} = icmp ne ptr ${fiber}, null`);
404
+ this.line(`${observed} = icmp ne ptr ${hook}, null`);
405
+ this.line(`${needed} = or i1 ${active}, ${observed}`);
406
+ this.line(`br i1 ${needed}, label %${run}, label %${done}`);
407
+ this.lines.push(run + ':');
408
+ this.call('aug_task_checkpoint', 'void', []);
409
+ this.line(`br label %${done}`);
410
+ this.lines.push(done + ':');
411
+ return;
412
+ }
413
+ case 'drop':
414
+ this.call('aug_ir_drop', 'void', [{ type: 'ptr', value: this.ptr(i.slot) }]);
415
+ return;
416
+ case 'throw':
417
+ this.call('aug_ir_throw', 'void', [{ type: 'ptr', value: this.ptr(i.input) }]);
418
+ return;
419
+ case 'take-error':
420
+ this.call('aug_ir_take_error', 'void', [{ type: 'ptr', value: this.ptr(i.out) }]);
421
+ return;
422
+ case 'assert':
423
+ this.call('aug_ir_assert', 'void', [{ type: 'ptr', value: this.ptr(i.input) }, { type: 'ptr', value: this.module.text(i.expression) }, { type: 'ptr', value: this.module.text(i.span.file) }, { type: 'i32', value: String(i.span.line) }]);
424
+ return;
425
+ case 'object': {
426
+ const table = this.module.table(this.fn.name, i.fields, i.owned, i.methods);
427
+ this.call('aug_ir_object', 'void', [{ type: 'ptr', value: this.ptr(i.out) }, { type: 'ptr', value: this.module.text(i.type) }, { type: 'i64', value: String(i.fields.length) }, { type: 'ptr', value: table.mask }, { type: 'ptr', value: table.name }, { type: 'i64', value: String(i.methods.length) }, { type: 'ptr', value: table.names }, { type: 'i1 zeroext', value: i.record ? 'true' : 'false' }]);
428
+ return;
429
+ }
430
+ case 'binding-get':
431
+ this.call('aug_ir_binding_get', 'void', [{ type: 'ptr', value: this.ptr(i.out) }, { type: 'i64', value: String(i.index) }]);
432
+ return;
433
+ case 'binding-set':
434
+ this.call('aug_ir_binding_set', 'void', [{ type: 'i64', value: String(i.index) }, { type: 'ptr', value: this.ptr(i.input) }]);
435
+ return;
436
+ case 'scope-depth':
437
+ this.boxed(i.out, 1, this.call('aug_scope_depth', 'i64', []));
438
+ return;
439
+ case 'lock-depth':
440
+ this.boxed(i.out, 1, this.call('aug_lock_depth', 'i64', []));
441
+ return;
442
+ case 'lock':
443
+ this.call(i.action === 'leave' ? 'aug_lock_leave' : 'aug_lock_restore', 'void', i.depth === undefined ? [] : [{ type: 'i64', value: this.integer(i.depth) }]);
444
+ return;
445
+ case 'error-state':
446
+ this.call(i.action === 'save' ? 'aug_ir_save_error_state' : 'aug_ir_restore_error_state', 'void', [{ type: 'ptr', value: this.ptr(i.error) }, { type: 'ptr', value: this.ptr(i.cancelled) }]);
447
+ return;
448
+ case 'scope': {
449
+ if (i.action === 'enter')
450
+ this.call('aug_scope_enter', 'void', [{ type: 'ptr', value: '@aug_scoped' }]);
451
+ else if (i.action === 'leave')
452
+ this.call('aug_scope_leave', 'void', []);
453
+ else {
454
+ let depth;
455
+ if (i.depth === undefined) {
456
+ const current = this.call('aug_scope_depth', 'i64', []);
457
+ depth = this.temp('scope_parent');
458
+ this.line(`${depth} = sub i64 ${current}, 1`);
459
+ }
460
+ else
461
+ depth = this.integer(i.depth);
462
+ this.call(i.action === 'join' ? 'aug_scope_join_to' : 'aug_scope_restore', 'void', [{ type: 'i64', value: depth }]);
463
+ }
464
+ return;
465
+ }
466
+ case 'native':
467
+ this.native(i);
468
+ return;
469
+ case 'extern': {
470
+ const params = i.types.map((type, n) => {
471
+ const native = this.directType(type);
472
+ let value;
473
+ if (type === 'string') {
474
+ const data = this.allocate('ptr'), length = this.allocate('i64');
475
+ this.call('aug_ir_data', 'zeroext i1', [{ type: 'ptr', value: this.ptr(i.args[n]) }, { type: 'ptr', value: data }, { type: 'ptr', value: length }]);
476
+ value = this.temp();
477
+ this.line(`${value} = load ptr, ptr ${data}`);
478
+ }
479
+ else if (type === 'float')
480
+ value = this.float(i.args[n]);
481
+ else if (type === 'bool')
482
+ value = this.call('aug_ir_truthy', 'zeroext i1', [{ type: 'ptr', value: this.ptr(i.args[n]) }]);
483
+ else {
484
+ value = this.integer(i.args[n]);
485
+ if (type === 'c_int') {
486
+ const narrow = this.temp();
487
+ this.line(`${narrow} = trunc i64 ${value} to i32`);
488
+ value = narrow;
489
+ }
490
+ }
491
+ return { type: native, value };
492
+ });
493
+ const result = this.directType(i.result), value = this.call(i.name, result, params);
494
+ if (result === 'void')
495
+ this.clear(i.out);
496
+ else if (result === 'double')
497
+ this.boxed(i.out, 2, this.floats(value));
498
+ else if (result === 'ptr')
499
+ throw new Error('FFI_PROFILE: Direct C string returns need an explicit descriptor lifetime');
500
+ else if (result === 'i32' || result === 'i1') {
501
+ const wide = this.temp();
502
+ this.line(`${wide} = ${result === 'i32' ? 'sext' : 'zext'} ${result} ${value} to i64`);
503
+ this.boxed(i.out, result === 'i1' ? 3 : 1, wide);
504
+ }
505
+ else
506
+ this.boxed(i.out, 1, value);
507
+ return;
508
+ }
509
+ }
510
+ }
511
+ native(i) {
512
+ const fn = i.binding, params = [], temporary = [], error = this.allocate('%NativeError'), statusSlot = this.allocate('i32');
513
+ const failed = this.label('native_failed'), success = this.label('native_success'), done = this.label('native_done');
514
+ this.line(`store %NativeError zeroinitializer, ptr ${error}, align 8`);
515
+ this.line(`store i32 -1, ptr ${statusSlot}`);
516
+ const cleanupSlots = [];
517
+ const guard = (condition) => { const next = this.label('native_input'); this.line(`br i1 ${condition}, label %${next}, label %${failed}`); this.lines.push(next + ':'); };
518
+ // Allocate all temporary pointer cells first, so a failed earlier conversion
519
+ // can release every initialized cell without reading an uninitialized one.
520
+ const storage = fn.params.map(view => {
521
+ if (['utf8', 'bytes', 'f64-list', 'utf8-list'].includes(view.kind)) {
522
+ const data = this.allocate('ptr'), count = this.allocate('i64'), lengths = view.kind === 'utf8-list' ? this.allocate('ptr') : undefined;
523
+ this.line(`store ptr null, ptr ${data}`);
524
+ this.line(`store i64 0, ptr ${count}`);
525
+ if (lengths)
526
+ this.line(`store ptr null, ptr ${lengths}`);
527
+ if (view.kind === 'f64-list' || view.kind === 'utf8-list')
528
+ cleanupSlots.push(data);
529
+ if (lengths)
530
+ cleanupSlots.push(lengths);
531
+ return { data, count, lengths };
532
+ }
533
+ return undefined;
534
+ });
535
+ const resultType = this.nativeType(fn.result), result = fn.result.kind === 'void' ? undefined : this.allocate(resultType), resultLength = ['utf8', 'bytes', 'f64-list'].includes(fn.result.kind) ? this.allocate('i64') : undefined;
536
+ if (result)
537
+ this.line(`store ${resultType} ${resultType === 'ptr' ? 'null' : resultType === 'double' ? '0.0' : '0'}, ptr ${result}`);
538
+ if (resultLength)
539
+ this.line(`store i64 0, ptr ${resultLength}`);
540
+ fn.params.forEach((view, n) => {
541
+ const slot = i.args[n], cell = storage[n];
542
+ if (cell) {
543
+ const ok = this.call(view.kind === 'f64-list' ? 'aug_ir_floats' : view.kind === 'utf8-list' ? 'aug_ir_strings' : 'aug_ir_data', 'zeroext i1', [
544
+ { type: 'ptr', value: this.ptr(slot) }, { type: 'ptr', value: cell.data }, ...(cell.lengths ? [{ type: 'ptr', value: cell.lengths }] : []), { type: 'ptr', value: cell.count }
545
+ ]);
546
+ guard(ok);
547
+ const data = this.temp(), count = this.temp();
548
+ this.line(`${data} = load ptr, ptr ${cell.data}`);
549
+ this.line(`${count} = load i64, ptr ${cell.count}`);
550
+ params.push({ type: 'ptr', value: data });
551
+ if (cell.lengths) {
552
+ const lengths = this.temp();
553
+ this.line(`${lengths} = load ptr, ptr ${cell.lengths}`);
554
+ params.push({ type: 'ptr', value: lengths });
555
+ }
556
+ params.push({ type: 'i64', value: count });
557
+ }
558
+ else if (view.kind === 'resource') {
559
+ const resource = i.resources[view.resource];
560
+ if (!resource)
561
+ throw new Error('NATIVE_ABI: Missing resource identity ' + view.resource);
562
+ const pointer = this.call('aug_ir_resource_pointer', 'ptr', [{ type: 'ptr', value: this.ptr(slot) }, { type: 'ptr', value: this.module.text(resource.id) }]);
563
+ const valid = this.temp();
564
+ this.line(`${valid} = icmp ne ptr ${pointer}, null`);
565
+ guard(valid);
566
+ params.push({ type: 'ptr', value: pointer });
567
+ }
568
+ else if (view.kind === 'f64')
569
+ params.push({ type: 'double', value: this.float(slot) });
570
+ else if (view.kind === 'bool') {
571
+ const b = this.call('aug_ir_truthy', 'zeroext i1', [{ type: 'ptr', value: this.ptr(slot) }]), wide = this.temp();
572
+ this.line(`${wide} = zext i1 ${b} to i8`);
573
+ params.push({ type: 'i8', value: wide });
574
+ }
575
+ else {
576
+ const value = this.integer(slot);
577
+ const minimum = view.minimum ?? (view.kind === 'i32' ? -2147483648 : undefined), maximum = view.maximum ?? (view.kind === 'i32' ? 2147483647 : undefined);
578
+ if (minimum !== undefined) {
579
+ const valid = this.temp();
580
+ this.line(`${valid} = icmp sge i64 ${value}, ${minimum}`);
581
+ guard(valid);
582
+ }
583
+ if (maximum !== undefined) {
584
+ const valid = this.temp();
585
+ this.line(`${valid} = icmp sle i64 ${value}, ${maximum}`);
586
+ guard(valid);
587
+ }
588
+ if (view.kind === 'i32') {
589
+ const narrow = this.temp();
590
+ this.line(`${narrow} = trunc i64 ${value} to i32`);
591
+ params.push({ type: 'i32', value: narrow });
592
+ }
593
+ else
594
+ params.push({ type: 'i64', value });
595
+ }
596
+ });
597
+ fn.params.forEach((view, n) => { if (view.kind === 'resource' && view.ownership === 'consume')
598
+ this.call('aug_ir_resource_move', 'void', [{ type: 'ptr', value: this.ptr(i.args[n]) }]); });
599
+ if (fn.status === 'direct') {
600
+ const value = this.call(fn.symbol, resultType, params);
601
+ if (result)
602
+ this.line(`store ${resultType} ${value}, ptr ${result}`);
603
+ this.line(`br label %${success}`);
604
+ }
605
+ else {
606
+ if (result)
607
+ params.push({ type: 'ptr', value: result });
608
+ if (resultLength)
609
+ params.push({ type: 'ptr', value: resultLength });
610
+ params.push({ type: 'ptr', value: error });
611
+ const status = this.call(fn.symbol, 'i32', params);
612
+ this.line(`store i32 ${status}, ptr ${statusSlot}`);
613
+ const ok = this.temp();
614
+ this.line(`${ok} = icmp eq i32 ${status}, 0`);
615
+ this.line(`br i1 ${ok}, label %${success}, label %${failed}`);
616
+ }
617
+ this.lines.push(success + ':');
618
+ if (!result)
619
+ this.clear(i.out);
620
+ else {
621
+ const value = this.temp();
622
+ this.line(`${value} = load ${resultType}, ptr ${result}`);
623
+ if (fn.result.kind === 'resource') {
624
+ const resource = i.resources[fn.result.resource];
625
+ this.module.declare(resource.release, 'void', ['ptr']);
626
+ this.call('aug_ir_resource', 'void', [{ type: 'ptr', value: this.ptr(i.out) }, { type: 'ptr', value }, { type: 'ptr', value: this.module.text(resource.id) }, { type: 'ptr', value: symbol(resource.release) }]);
627
+ this.line(`store ptr null, ptr ${result}`);
628
+ }
629
+ else if (resultLength) {
630
+ const length = this.temp();
631
+ this.line(`${length} = load i64, ptr ${resultLength}`);
632
+ this.call(fn.result.kind === 'utf8' ? 'aug_ir_copy_utf8' : fn.result.kind === 'bytes' ? 'aug_ir_copy_bytes' : 'aug_ir_copy_floats', 'void', [{ type: 'ptr', value: this.ptr(i.out) }, { type: 'ptr', value }, { type: 'i64', value: length }]);
633
+ }
634
+ else if (resultType === 'double')
635
+ this.boxed(i.out, 2, this.floats(value));
636
+ else if (resultType === 'i8')
637
+ this.call('aug_ir_copy_bool', 'void', [{ type: 'ptr', value: this.ptr(i.out) }, { type: 'i8', value }]);
638
+ else if (resultType === 'i32') {
639
+ const wide = this.temp();
640
+ this.line(`${wide} = sext i32 ${value} to i64`);
641
+ this.boxed(i.out, 1, wide);
642
+ }
643
+ else
644
+ this.boxed(i.out, 1, value);
645
+ }
646
+ this.line(`br label %${done}`);
647
+ this.lines.push(failed + ':');
648
+ if (fn.status === 'i32') {
649
+ const code = this.temp(), payloadCode = this.temp(), status = this.temp(), hasCode = this.temp(), lengthPtr = this.temp(), length = this.temp(), bounded = this.temp(), isBounded = this.temp(), wide = this.temp(), message = this.temp();
650
+ this.line(`${payloadCode} = load i32, ptr ${error}`);
651
+ this.line(`${status} = load i32, ptr ${statusSlot}`);
652
+ this.line(`${hasCode} = icmp ne i32 ${payloadCode}, 0`);
653
+ this.line(`${code} = select i1 ${hasCode}, i32 ${payloadCode}, i32 ${status}`);
654
+ this.line(`${lengthPtr} = getelementptr %NativeError, ptr ${error}, i32 0, i32 1`);
655
+ this.line(`${length} = load i32, ptr ${lengthPtr}`);
656
+ this.line(`${isBounded} = icmp ule i32 ${length}, 512`);
657
+ this.line(`${bounded} = select i1 ${isBounded}, i32 ${length}, i32 512`);
658
+ this.line(`${wide} = zext i32 ${bounded} to i64`);
659
+ this.line(`${message} = getelementptr %NativeError, ptr ${error}, i32 0, i32 2`);
660
+ this.call('aug_ir_native_error', 'void', [{ type: 'ptr', value: this.ptr(i.out) }, { type: 'ptr', value: i.errorFactory ? symbol(i.errorFactory) : 'null' }, { type: 'i32', value: code }, { type: 'ptr', value: message }, { type: 'i64', value: wide }]);
661
+ }
662
+ else
663
+ this.call('aug_ir_contract_error', 'void', [{ type: 'ptr', value: this.ptr(i.out) }]);
664
+ this.line(`br label %${done}`);
665
+ this.lines.push(done + ':');
666
+ for (const cell of cleanupSlots) {
667
+ const value = this.temp();
668
+ this.line(`${value} = load ptr, ptr ${cell}`);
669
+ this.call('aug_ir_free', 'void', [{ type: 'ptr', value }]);
670
+ }
671
+ if (result && (fn.result.release || fn.result.kind === 'resource')) {
672
+ const value = this.temp(), nonnull = this.temp(), release = this.label('native_release'), after = this.label('native_released');
673
+ this.line(`${value} = load ptr, ptr ${result}`);
674
+ this.line(`${nonnull} = icmp ne ptr ${value}, null`);
675
+ this.line(`br i1 ${nonnull}, label %${release}, label %${after}`);
676
+ this.lines.push(release + ':');
677
+ const args = [{ type: 'ptr', value }];
678
+ if (fn.result.releaseLength && resultLength) {
679
+ const length = this.temp();
680
+ this.line(`${length} = load i64, ptr ${resultLength}`);
681
+ args.push({ type: 'i64', value: length });
682
+ }
683
+ this.call(fn.result.release ?? i.resources[fn.result.resource].release, 'void', args);
684
+ this.line(`br label %${after}`);
685
+ this.lines.push(after + ':');
686
+ }
687
+ }
688
+ terminator(t, blockName) {
689
+ if (t.op === 'jump') {
690
+ this.line('br label %' + t.target);
691
+ return;
692
+ }
693
+ if (t.op === 'return') {
694
+ this.call('aug_lock_restore', 'void', [{ type: 'i64', value: '%lock_base' }]);
695
+ this.call('aug_scope_join_to', 'void', [{ type: 'i64', value: '%scope_base' }]);
696
+ for (const slot of this.fn.owned)
697
+ this.call('aug_ir_drop', 'void', [{ type: 'ptr', value: this.ptr(slot) }]);
698
+ for (const slot of this.fn.constructorResults)
699
+ this.call('aug_ir_constructor_result', 'void', [{ type: 'ptr', value: this.ptr(slot) }, { type: 'ptr', value: this.ptr(0) }]);
700
+ if (this.fn.failedResult)
701
+ this.call('aug_ir_failed_result', 'void', [{ type: 'ptr', value: this.ptr(0) }]);
702
+ this.call('aug_scope_restore', 'void', [{ type: 'i64', value: '%scope_base' }]);
703
+ this.line(`store %AugValue ${this.load(0)}, ptr %out, align 8`);
704
+ this.call('aug_frame_leave', 'void', [{ type: 'ptr', value: '%frame' }]);
705
+ this.line('ret void');
706
+ return;
707
+ }
708
+ let condition, yes, no;
709
+ if (t.op === 'error') {
710
+ const state = this.errorStates.get(blockName);
711
+ if (state) {
712
+ condition = this.temp();
713
+ this.line(`${condition} = icmp eq i8 ${state}, 2`);
714
+ }
715
+ else
716
+ condition = this.executionFlag(runtimeLayout.executionErrorOffset);
717
+ yes = t.failed;
718
+ no = t.success;
719
+ }
720
+ else if (t.op === 'cancel') {
721
+ const paired = this.pairedStates.get(blockName);
722
+ if (paired) {
723
+ const cancelled = this.executionFlag(runtimeLayout.executionCancelledOffset), failed = this.executionFlag(runtimeLayout.executionErrorOffset), error = this.temp();
724
+ this.line(`${error} = select i1 ${failed}, i8 2, i8 0`);
725
+ this.line(`${paired} = select i1 ${cancelled}, i8 1, i8 ${error}`);
726
+ condition = cancelled;
727
+ }
728
+ else
729
+ condition = this.executionFlag(runtimeLayout.executionCancelledOffset);
730
+ yes = t.then;
731
+ no = t.otherwise;
732
+ }
733
+ else if (t.op === 'error-type') {
734
+ condition = this.call('aug_error_is', 'zeroext i1', [{ type: 'ptr', value: this.module.text(t.type) }]);
735
+ yes = t.then;
736
+ no = t.otherwise;
737
+ }
738
+ else if (t.op === 'null') {
739
+ condition = this.call('aug_ir_is_null', 'zeroext i1', [{ type: 'ptr', value: this.ptr(t.input) }]);
740
+ yes = t.then;
741
+ no = t.otherwise;
742
+ }
743
+ else {
744
+ condition = this.scalarKind(t.condition) === 'bool' ? this.scalarBoolean(t.condition) : this.call('aug_ir_truthy', 'zeroext i1', [{ type: 'ptr', value: this.ptr(t.condition) }]);
745
+ yes = t.then;
746
+ no = t.otherwise;
747
+ }
748
+ this.line(`br i1 ${condition}, label %${yes}, label %${no}`);
749
+ }
750
+ generate() {
751
+ const subprogram = this.module.debug.function(this.fn);
752
+ for (const block of this.fn.blocks) {
753
+ this.lines.push(block.name + ':');
754
+ for (const instruction of block.instructions) {
755
+ this.debugLocation = this.module.debug.location(this.fn, instruction.span, instruction.debugScope);
756
+ this.instruction(instruction);
757
+ }
758
+ this.terminator(block.terminator, block.name);
759
+ }
760
+ const variables = this.fn.variables.filter(variable => variable.argument).map(variable => this.variable(variable));
761
+ const prologue = [`define internal void @${this.fn.name}(ptr %out, ptr %self, ptr %args, i32 %count) !dbg ${subprogram} {`, `entry:`,
762
+ ` %roots = alloca [${this.fn.slots} x %AugValue], align 8`, ` %frame = alloca %AugFrame, align 8`, ...this.allocations,
763
+ ` store [${this.fn.slots} x %AugValue] zeroinitializer, ptr %roots, align 8`,
764
+ ...this.fn.values.flatMap((value, i) => value.storage === 'scalar-value' ? [` %slot_${i} = alloca %AugValue, align 8`, ` store %AugValue zeroinitializer, ptr %slot_${i}, align 8`] : [` %slot_${i} = getelementptr [${this.fn.slots} x %AugValue], ptr %roots, i64 0, i64 ${i}`]),
765
+ ...this.fn.parameters.flatMap((slot, i) => [` %parameter_ptr_${i} = getelementptr %AugValue, ptr %args, i64 ${i}`, ` %parameter_${i} = load %AugValue, ptr %parameter_ptr_${i}, align 8`, ` store %AugValue %parameter_${i}, ptr %slot_${slot}, align 8`]),
766
+ ...(this.fn.receiver === undefined ? [] : [` %receiver = load %AugValue, ptr %self, align 8`, ` store %AugValue %receiver, ptr %slot_${this.fn.receiver}, align 8`]),
767
+ ...variables,
768
+ ` call void @aug_ir_frame_enter(ptr %frame, ptr %roots, i64 ${this.fn.slots})`, ` %scope_base = call i64 @aug_scope_depth()`, ` %lock_base = call i64 @aug_lock_depth()`, ` br label %entry_body`];
769
+ prologue.splice(-1, 0, ` %execution = call ptr @aug_execution_current()`, ` %execution_error = getelementptr i8, ptr %execution, i64 ${runtimeLayout.executionErrorOffset}`, ` %execution_cancelled = getelementptr i8, ptr %execution, i64 ${runtimeLayout.executionCancelledOffset}`, ` %execution_fiber = getelementptr i8, ptr %execution, i64 ${runtimeLayout.executionFiberOffset}`);
770
+ this.module.declare('aug_execution_current', 'ptr', []);
771
+ this.module.declare('aug_scope_depth', 'i64', []);
772
+ this.module.declare('aug_lock_depth', 'i64', []);
773
+ this.module.declare('aug_ir_frame_enter', 'void', ['ptr', 'ptr', 'i64']);
774
+ return [...prologue, ...this.lines, '}'].join('\n');
775
+ }
776
+ variable(variable) {
777
+ if (this.fn.values[variable.slot].storage === 'scalar-value')
778
+ return ` #dbg_declare(ptr %slot_${variable.slot}, ${this.module.debug.variable(this.fn, variable)}, !DIExpression(), ${this.module.debug.location(this.fn, variable.span, variable.scope)})`;
779
+ return ` #dbg_declare(ptr %roots, ${this.module.debug.variable(this.fn, variable)}, !DIExpression(DW_OP_plus_uconst, ${variable.slot * runtimeLayout.valueSize}), ${this.module.debug.location(this.fn, variable.span, variable.scope)})`;
780
+ }
781
+ }