substrate-lang 0.9.3 → 0.10.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 (208) hide show
  1. package/README.md +1 -1
  2. package/build/compiler/binary.2d43b43d1600@0+0.wasm +0 -0
  3. package/build/compiler/checker.4dd4556dd421@0+0.wasm +0 -0
  4. package/build/compiler/compile.5d8f6407af2a@0+0.wasm +0 -0
  5. package/build/compiler/{core.fc3dab9d1846@0+0.wasm → core.f2defb75e00b@0+0.wasm} +0 -0
  6. package/build/compiler/expander.967ce443d379@0+0.wasm +0 -0
  7. package/build/compiler/fs.01b8aab4a9a8@0+0.wasm +0 -0
  8. package/build/compiler/{leb128.748b1c37277a@0+0.wasm → leb128.15d814b7b4f2@0+0.wasm} +0 -0
  9. package/build/compiler/{link.11b643d35670@0+0.wasm → link.b826ea7c8f17@0+0.wasm} +0 -0
  10. package/build/compiler/{macros.4083601c00db@0+0.wasm → macros.b269e0c42784@0+0.wasm} +0 -0
  11. package/build/compiler/{main.ed62cce43000@0+0.wasm → main.4fc52f204d54@0+0.wasm} +0 -0
  12. package/build/compiler/{ops.b361e858d8e1@0+0.wasm → ops.515b5e05f646@0+0.wasm} +0 -0
  13. package/build/compiler/{path.dcc4712bcc7b@0+0.wasm → path.5a6286472cd4@0+0.wasm} +0 -0
  14. package/build/compiler/program +21 -21
  15. package/build/compiler/prune.406215c3e4f8@0+0.wasm +0 -0
  16. package/build/compiler/reader.694b03770bf0@0+0.wasm +0 -0
  17. package/build/compiler/roots.cefd10e93684@0+0.wasm +0 -0
  18. package/build/compiler/{running.d73f7826cb74@0+0.wasm → running.0d25dbaec018@0+0.wasm} +0 -0
  19. package/build/compiler/serialize.b0d82f3d63d2@0+0.wasm +0 -0
  20. package/build/compiler/{sha256.5fc9d60f8bb2@0+0.wasm → sha256.a6c32b04d799@0+0.wasm} +0 -0
  21. package/build/compiler/substrate.5ee5d0b4d3e7@0+0.wasm +0 -0
  22. package/build/compiler/syntax.32f3e40b61c7@0+0.wasm +0 -0
  23. package/build/compiler/{writer.806bc85aa684@0+0.wasm → writer.00b7802cbe39@0+0.wasm} +0 -0
  24. package/build/sub/{base64.8fba03e1be0a@0+0.wasm → base64.a26bdcf60a2d@0+0.wasm} +0 -0
  25. package/build/sub/build.459c5b9412bd@0+0.wasm +0 -0
  26. package/build/sub/chromium.3d5818f2707d@0+0.wasm +0 -0
  27. package/build/sub/common.1edc613607a0@0+0.wasm +0 -0
  28. package/build/sub/deflate.23f7c4679260@0+0.wasm +0 -0
  29. package/build/sub/doc.0775df5de6fe@0+0.wasm +0 -0
  30. package/build/sub/{doc.566f9861828e@0+0.wasm → doc.ef9965d5d402@0+0.wasm} +0 -0
  31. package/build/sub/env.e5451da6e747@0+0.wasm +0 -0
  32. package/build/sub/events.bf5473ebf220@0+0.wasm +0 -0
  33. package/build/sub/fetch.7790d4943758@0+0.wasm +0 -0
  34. package/build/sub/fetch.96b2d10f025e@0+0.wasm +0 -0
  35. package/build/sub/files.ad0469fdf6fa@0+0.wasm +0 -0
  36. package/build/sub/fs.01b8aab4a9a8@0+0.wasm +0 -0
  37. package/build/sub/git.dc4c0e757ebe@0+0.wasm +0 -0
  38. package/build/sub/grants.c54776c0d7e3@0+0.wasm +0 -0
  39. package/build/sub/gzip.16e372eda1cf@0+0.wasm +0 -0
  40. package/build/sub/hash.660682e4f491@0+0.wasm +0 -0
  41. package/build/sub/{html.20baa1dc7ca6@0+0.wasm → html.a23126eb949a@0+0.wasm} +0 -0
  42. package/build/sub/{html.c1671a102b4d@0+0.wasm → html.e9ed37f34977@0+0.wasm} +0 -0
  43. package/build/sub/{inflate.8899e0933792@0+0.wasm → inflate.59bb61f14001@0+0.wasm} +0 -0
  44. package/build/sub/json.55590d2f518a@0+0.wasm +0 -0
  45. package/build/sub/manifest.ef317480deb0@0+0.wasm +0 -0
  46. package/build/sub/map.f455cca6a42a@0+0.wasm +0 -0
  47. package/build/sub/pack.e02836264f6a@0+0.wasm +0 -0
  48. package/build/sub/{path.dcc4712bcc7b@0+0.wasm → path.5a6286472cd4@0+0.wasm} +0 -0
  49. package/build/sub/path.6891ffea73ca@0+0.wasm +0 -0
  50. package/build/sub/process.7106571fa723@0+0.wasm +0 -0
  51. package/build/sub/program +48 -48
  52. package/build/sub/read.0b93933d62a2@0+0.wasm +0 -0
  53. package/build/sub/{reader.b535e61f99f4@0+0.wasm → reader.694b03770bf0@0+0.wasm} +0 -0
  54. package/build/sub/{root.9b713ec588c1@0+0.wasm → root.f10a4906f460@0+0.wasm} +0 -0
  55. package/build/sub/{roots.6d2942578055@0+0.wasm → roots.cefd10e93684@0+0.wasm} +0 -0
  56. package/build/sub/{sha256.5fc9d60f8bb2@0+0.wasm → sha256.a6c32b04d799@0+0.wasm} +0 -0
  57. package/build/sub/{sha512.b988b9dc6114@0+0.wasm → sha512.c24a792d7891@0+0.wasm} +0 -0
  58. package/build/sub/site.1732b58ec0e8@0+0.wasm +0 -0
  59. package/build/sub/site.ae3913b0b0f4@0+0.wasm +0 -0
  60. package/build/sub/store.a24d7a25daa6@0+0.wasm +0 -0
  61. package/build/sub/stream.126e3bd5d626@0+0.wasm +0 -0
  62. package/build/sub/sub.2e3092140706@0+0.wasm +0 -0
  63. package/build/sub/substrate.5ee5d0b4d3e7@0+0.wasm +0 -0
  64. package/build/sub/{syntax.9857f6784d63@0+0.wasm → syntax.32f3e40b61c7@0+0.wasm} +0 -0
  65. package/build/sub/tar.2a633861e654@0+0.wasm +0 -0
  66. package/build/sub/test.9bd59c73f65e@0+0.wasm +0 -0
  67. package/build/sub/{text.4ab70ac35b5a@0+0.wasm → text.1bc90482bd43@0+0.wasm} +0 -0
  68. package/build/sub/{timer.3809bb17a7a1@0+0.wasm → timer.f35eb62ae446@0+0.wasm} +0 -0
  69. package/build/sub/upgrade.39ee449b00d5@0+0.wasm +0 -0
  70. package/build/sub/{utf8.524c475ecd40@0+0.wasm → utf8.e7216bd054e1@0+0.wasm} +0 -0
  71. package/build/sub/worker.762a9d642af0@0+0.wasm +0 -0
  72. package/build/sub/writer.00b7802cbe39@0+0.wasm +0 -0
  73. package/package.json +1 -1
  74. package/std/archive/tar.sub +44 -44
  75. package/std/browser/chromium.sub +5 -4
  76. package/std/browser/devtools.sub +24 -19
  77. package/std/compress/deflate.sub +10 -12
  78. package/std/compress/gzip.sub +18 -16
  79. package/std/compress/inflate.sub +7 -4
  80. package/std/crypto/password.sub +3 -3
  81. package/std/doc/doc.sub +2 -2
  82. package/std/encoding/json.sub +64 -73
  83. package/std/encoding/wire.sub +15 -15
  84. package/std/http/checks.sub +3 -3
  85. package/std/http/conditional.sub +2 -4
  86. package/std/http/cookie.sub +5 -7
  87. package/std/http/form.sub +9 -12
  88. package/std/http/http.sub +17 -24
  89. package/std/http/multipart.sub +13 -15
  90. package/std/http/route.sub +18 -13
  91. package/std/http/server.sub +21 -23
  92. package/std/http/session.sub +3 -6
  93. package/std/http/sse-client.sub +9 -14
  94. package/std/http/static.sub +5 -5
  95. package/std/http/url.sub +10 -10
  96. package/std/http/websocket.sub +2 -5
  97. package/std/meta/derive.sub +0 -2
  98. package/std/meta/method.sub +41 -0
  99. package/std/meta/type-info.sub +30 -37
  100. package/std/package/files.sub +24 -25
  101. package/std/package/git.sub +26 -33
  102. package/std/package/hash.sub +9 -9
  103. package/std/package/manifest.sub +81 -57
  104. package/std/package/map.sub +5 -9
  105. package/std/package/pack.sub +13 -13
  106. package/std/package/path.sub +1 -4
  107. package/std/package/read.sub +10 -14
  108. package/std/package/site.sub +11 -11
  109. package/std/package/store.sub +16 -12
  110. package/std/package.sub +6 -6
  111. package/std/test/browser.sub +9 -8
  112. package/std/test/build.sub +2 -2
  113. package/std/test/compare.sub +9 -10
  114. package/std/test/page.sub +32 -27
  115. package/std/test/run.sub +9 -8
  116. package/std/test/test.sub +36 -30
  117. package/std/vector/vector.sub +75 -0
  118. package/substrate/VERSION +1 -1
  119. package/substrate/compiler/binary.sub +5 -14
  120. package/substrate/compiler/checker.sub +235 -222
  121. package/substrate/compiler/compile.sub +11 -11
  122. package/substrate/compiler/expander.sub +52 -78
  123. package/substrate/compiler/link.sub +2 -2
  124. package/substrate/compiler/main.sub +9 -9
  125. package/substrate/compiler/ops.sub +1 -1
  126. package/substrate/compiler/prune.sub +12 -17
  127. package/substrate/compiler/reader.sub +4 -4
  128. package/substrate/compiler/roots.sub +11 -10
  129. package/substrate/compiler/running.sub +1 -1
  130. package/substrate/compiler/serialize.sub +57 -50
  131. package/substrate/compiler/substrate.sub +60 -23
  132. package/substrate/compiler/syntax.sub +8 -21
  133. package/substrate/host/errors.mjs +3 -2
  134. package/substrate/host/events.sub +3 -16
  135. package/substrate/host/fs.mjs +5 -4
  136. package/substrate/host/fs.sub +142 -112
  137. package/substrate/host/grants.mjs +1 -1
  138. package/substrate/host/grants.sub +33 -33
  139. package/substrate/host/modules/fake.mjs +1 -1
  140. package/substrate/host/modules/websocket.mjs +4 -4
  141. package/substrate/host/modules/websocket.sub +8 -6
  142. package/substrate/host/node/env.mjs +12 -6
  143. package/substrate/host/node/env.sub +21 -16
  144. package/substrate/host/node/fs.mjs +1 -1
  145. package/substrate/host/node/net.mjs +2 -2
  146. package/substrate/host/node/net.sub +13 -6
  147. package/substrate/host/node/process.mjs +4 -4
  148. package/substrate/host/node/process.sub +28 -28
  149. package/substrate/host/node/signal.mjs +3 -2
  150. package/substrate/host/node/signal.sub +9 -6
  151. package/substrate/host/node/watch.mjs +1 -1
  152. package/substrate/host/node/watch.sub +11 -9
  153. package/substrate/host/stream.sub +2 -0
  154. package/substrate/host/subhost-core.mjs +9 -1
  155. package/substrate/host/web/clipboard.mjs +2 -2
  156. package/substrate/host/web/clipboard.sub +10 -3
  157. package/substrate/host/web/files.mjs +2 -2
  158. package/substrate/host/web/files.sub +6 -2
  159. package/substrate/host/web/fs.mjs +3 -3
  160. package/substrate/host/web/location.mjs +3 -1
  161. package/substrate/host/web/location.sub +8 -4
  162. package/substrate/host/worker-side.mjs +3 -1
  163. package/substrate/host/worker.mjs +6 -5
  164. package/substrate/host/worker.sub +10 -10
  165. package/build/compiler/binary.3823f89ce414@0+0.wasm +0 -0
  166. package/build/compiler/checker.592d37dcbec9@0+0.wasm +0 -0
  167. package/build/compiler/compile.86a2b03b0c9b@0+0.wasm +0 -0
  168. package/build/compiler/expander.689d326e5a1b@0+0.wasm +0 -0
  169. package/build/compiler/fs.563034be70c3@0+0.wasm +0 -0
  170. package/build/compiler/prune.d4a3f9834095@0+0.wasm +0 -0
  171. package/build/compiler/reader.b535e61f99f4@0+0.wasm +0 -0
  172. package/build/compiler/roots.6d2942578055@0+0.wasm +0 -0
  173. package/build/compiler/serialize.b2196de75bc8@0+0.wasm +0 -0
  174. package/build/compiler/substrate.4c780d6dd6d4@0+0.wasm +0 -0
  175. package/build/compiler/syntax.9857f6784d63@0+0.wasm +0 -0
  176. package/build/sub/build.84ac996eda63@0+0.wasm +0 -0
  177. package/build/sub/chromium.e4db7d29897c@0+0.wasm +0 -0
  178. package/build/sub/common.91ddee6b7a67@0+0.wasm +0 -0
  179. package/build/sub/deflate.fc8075e3aed1@0+0.wasm +0 -0
  180. package/build/sub/doc.0b48bbac404b@0+0.wasm +0 -0
  181. package/build/sub/env.f051f8166526@0+0.wasm +0 -0
  182. package/build/sub/events.f952172735e0@0+0.wasm +0 -0
  183. package/build/sub/fetch.097f1cc9502d@0+0.wasm +0 -0
  184. package/build/sub/fetch.5d2f427c995e@0+0.wasm +0 -0
  185. package/build/sub/files.30e55182c5df@0+0.wasm +0 -0
  186. package/build/sub/fs.563034be70c3@0+0.wasm +0 -0
  187. package/build/sub/git.48aefa1644be@0+0.wasm +0 -0
  188. package/build/sub/grants.5bf25700d47c@0+0.wasm +0 -0
  189. package/build/sub/gzip.69588e97c35a@0+0.wasm +0 -0
  190. package/build/sub/hash.3f0d118da63f@0+0.wasm +0 -0
  191. package/build/sub/json.f15a29d99d8d@0+0.wasm +0 -0
  192. package/build/sub/manifest.cf7471880377@0+0.wasm +0 -0
  193. package/build/sub/map.dc516eec27ff@0+0.wasm +0 -0
  194. package/build/sub/pack.55992e8cc09c@0+0.wasm +0 -0
  195. package/build/sub/path.b7a8e1cf3aaa@0+0.wasm +0 -0
  196. package/build/sub/process.aea2c88cb7a0@0+0.wasm +0 -0
  197. package/build/sub/read.cd1e693f4fb4@0+0.wasm +0 -0
  198. package/build/sub/site.7c6d8c7747af@0+0.wasm +0 -0
  199. package/build/sub/site.81548474c323@0+0.wasm +0 -0
  200. package/build/sub/store.d4e845ff24ac@0+0.wasm +0 -0
  201. package/build/sub/stream.4c07247477f7@0+0.wasm +0 -0
  202. package/build/sub/sub.b57e17b6876b@0+0.wasm +0 -0
  203. package/build/sub/substrate.4c780d6dd6d4@0+0.wasm +0 -0
  204. package/build/sub/tar.e482cf873cfc@0+0.wasm +0 -0
  205. package/build/sub/test.0d9c079bb309@0+0.wasm +0 -0
  206. package/build/sub/upgrade.18a5aa0dae89@0+0.wasm +0 -0
  207. package/build/sub/worker.f1190de21b21@0+0.wasm +0 -0
  208. package/build/sub/writer.806bc85aa684@0+0.wasm +0 -0
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # substrate-lang
2
2
 
3
3
  Substrate is a Lisp for writing WebAssembly. It has C-like semantics
4
- (modernized with generics, variants, bounds-checked slices), combined with
4
+ (modernized with variants and bounds-checked slices), combined with
5
5
  Racket-style hygienic macros and module hooks for defining new languages and
6
6
  DSLs. Its compiler is small (~11k LOC, <600 KiB of Wasm), very fast,
7
7
  self-hosted, and runs in the browser.
@@ -1,21 +1,21 @@
1
- substrate.4c780d6dd6d4@0+0
2
- writer.806bc85aa684@0+0
3
- syntax.9857f6784d63@0+0
4
- path.dcc4712bcc7b@0+0
5
- fs.563034be70c3@0+0
6
- reader.b535e61f99f4@0+0
7
- roots.6d2942578055@0+0
8
- running.d73f7826cb74@0+0
9
- core.fc3dab9d1846@0+0
10
- ops.b361e858d8e1@0+0
11
- checker.592d37dcbec9@0+0
12
- leb128.748b1c37277a@0+0
13
- binary.3823f89ce414@0+0
14
- serialize.b2196de75bc8@0+0
15
- compile.86a2b03b0c9b@0+0
16
- sha256.5fc9d60f8bb2@0+0
17
- link.11b643d35670@0+0
18
- macros.4083601c00db@0+0
19
- expander.689d326e5a1b@0+0
20
- prune.d4a3f9834095@0+0
21
- main.ed62cce43000@0+0
1
+ substrate.5ee5d0b4d3e7@0+0
2
+ writer.00b7802cbe39@0+0
3
+ syntax.32f3e40b61c7@0+0
4
+ path.5a6286472cd4@0+0
5
+ fs.01b8aab4a9a8@0+0
6
+ reader.694b03770bf0@0+0
7
+ roots.cefd10e93684@0+0
8
+ running.0d25dbaec018@0+0
9
+ core.f2defb75e00b@0+0
10
+ ops.515b5e05f646@0+0
11
+ checker.4dd4556dd421@0+0
12
+ leb128.15d814b7b4f2@0+0
13
+ binary.2d43b43d1600@0+0
14
+ serialize.b0d82f3d63d2@0+0
15
+ compile.5d8f6407af2a@0+0
16
+ sha256.a6c32b04d799@0+0
17
+ link.b826ea7c8f17@0+0
18
+ macros.b269e0c42784@0+0
19
+ expander.967ce443d379@0+0
20
+ prune.406215c3e4f8@0+0
21
+ main.4fc52f204d54@0+0
package/build/sub/program CHANGED
@@ -1,48 +1,48 @@
1
- substrate.4c780d6dd6d4@0+0
2
- process.aea2c88cb7a0@0+0
3
- path.dcc4712bcc7b@0+0
4
- path.b7a8e1cf3aaa@0+0
5
- fs.563034be70c3@0+0
6
- common.91ddee6b7a67@0+0
7
- grants.5bf25700d47c@0+0
8
- writer.806bc85aa684@0+0
9
- syntax.9857f6784d63@0+0
10
- reader.b535e61f99f4@0+0
11
- roots.6d2942578055@0+0
12
- read.cd1e693f4fb4@0+0
13
- manifest.cf7471880377@0+0
14
- git.48aefa1644be@0+0
15
- files.30e55182c5df@0+0
16
- sha256.5fc9d60f8bb2@0+0
17
- hash.3f0d118da63f@0+0
18
- store.d4e845ff24ac@0+0
19
- map.dc516eec27ff@0+0
20
- env.f051f8166526@0+0
21
- events.f952172735e0@0+0
22
- build.84ac996eda63@0+0
23
- pack.55992e8cc09c@0+0
24
- site.7c6d8c7747af@0+0
25
- site.81548474c323@0+0
26
- fetch.097f1cc9502d@0+0
27
- stream.4c07247477f7@0+0
28
- worker.f1190de21b21@0+0
29
- deflate.fc8075e3aed1@0+0
30
- inflate.8899e0933792@0+0
31
- gzip.69588e97c35a@0+0
32
- tar.e482cf873cfc@0+0
33
- fetch.5d2f427c995e@0+0
34
- doc.566f9861828e@0+0
35
- html.c1671a102b4d@0+0
36
- html.20baa1dc7ca6@0+0
37
- text.4ab70ac35b5a@0+0
38
- root.9b713ec588c1@0+0
39
- doc.0b48bbac404b@0+0
40
- timer.3809bb17a7a1@0+0
41
- chromium.e4db7d29897c@0+0
42
- test.0d9c079bb309@0+0
43
- utf8.524c475ecd40@0+0
44
- json.f15a29d99d8d@0+0
45
- sha512.b988b9dc6114@0+0
46
- base64.8fba03e1be0a@0+0
47
- upgrade.18a5aa0dae89@0+0
48
- sub.b57e17b6876b@0+0
1
+ substrate.5ee5d0b4d3e7@0+0
2
+ process.7106571fa723@0+0
3
+ path.5a6286472cd4@0+0
4
+ path.6891ffea73ca@0+0
5
+ fs.01b8aab4a9a8@0+0
6
+ common.1edc613607a0@0+0
7
+ grants.c54776c0d7e3@0+0
8
+ writer.00b7802cbe39@0+0
9
+ syntax.32f3e40b61c7@0+0
10
+ reader.694b03770bf0@0+0
11
+ roots.cefd10e93684@0+0
12
+ read.0b93933d62a2@0+0
13
+ manifest.ef317480deb0@0+0
14
+ git.dc4c0e757ebe@0+0
15
+ files.ad0469fdf6fa@0+0
16
+ sha256.a6c32b04d799@0+0
17
+ hash.660682e4f491@0+0
18
+ store.a24d7a25daa6@0+0
19
+ map.f455cca6a42a@0+0
20
+ env.e5451da6e747@0+0
21
+ events.bf5473ebf220@0+0
22
+ build.459c5b9412bd@0+0
23
+ pack.e02836264f6a@0+0
24
+ site.ae3913b0b0f4@0+0
25
+ site.1732b58ec0e8@0+0
26
+ fetch.7790d4943758@0+0
27
+ stream.126e3bd5d626@0+0
28
+ worker.762a9d642af0@0+0
29
+ deflate.23f7c4679260@0+0
30
+ inflate.59bb61f14001@0+0
31
+ gzip.16e372eda1cf@0+0
32
+ tar.2a633861e654@0+0
33
+ fetch.96b2d10f025e@0+0
34
+ doc.ef9965d5d402@0+0
35
+ html.e9ed37f34977@0+0
36
+ html.a23126eb949a@0+0
37
+ text.1bc90482bd43@0+0
38
+ root.f10a4906f460@0+0
39
+ doc.0775df5de6fe@0+0
40
+ timer.f35eb62ae446@0+0
41
+ chromium.3d5818f2707d@0+0
42
+ test.9bd59c73f65e@0+0
43
+ utf8.e7216bd054e1@0+0
44
+ json.55590d2f518a@0+0
45
+ sha512.c24a792d7891@0+0
46
+ base64.a26bdcf60a2d@0+0
47
+ upgrade.39ee449b00d5@0+0
48
+ sub.2e3092140706@0+0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "substrate-lang",
3
- "version": "0.9.3",
3
+ "version": "0.10.0",
4
4
  "description": "A Lisp for writing WebAssembly, and the substrate command that builds, runs and tests it",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -2,13 +2,11 @@
2
2
  ;; names. tar-next! gives each entry in turn: a file with its bytes, a directory, or another kind, with its path.
3
3
  (require-unqualified host/fs)
4
4
 
5
- (provide tar-reader tar-entry tar-reader-init! tar-next! tar-file tar-directory tar-other tar-unpack!)
5
+ (provide tar-reader tar-entry tar-reader-init! tar-next! tar-kind tar-file tar-directory tar-other tar-unpack!)
6
6
 
7
- (const tar-file i32 1)
8
- (const tar-directory i32 2)
9
- (const tar-other i32 3)
7
+ (enum tar-kind [tar-file 1] tar-directory tar-other)
10
8
 
11
- (struct tar-entry [kind i32] [path string] [bytes (slice u8)])
9
+ (struct tar-entry [kind tar-kind] [path string] [bytes (slice u8)])
12
10
  (struct tar-reader [data (slice u8)] [at u32])
13
11
 
14
12
  (define (tar-reader-init! [r (ptr tar-reader)] [data (slice u8)])
@@ -16,15 +14,17 @@
16
14
  (set! (-> r at) 0))
17
15
 
18
16
  ;; An entry's path is in a or the data, and a file's bytes are in the data.
19
- (define (tar-next! [a (ptr arena)] [r (ptr tar-reader)] [e (ptr tar-entry)] [err (ptr buffer)]) -> i32
17
+ (define (tar-next! [a (ptr arena)] [r (ptr tar-reader)] [e (ptr tar-entry)] [found (ptr bool)] [err (ptr buffer)])
18
+ -> bool
20
19
  (let ([long string] [sized #f] [given-size u64 0])
20
+ (set! (@ found) #f)
21
21
  (while #t
22
22
  (let* ([data (-> r data)] [at (-> r at)] [left (- (-> data length) at)] [h (slice u8)] [size u64 0] [type u8 0]
23
23
  [body (slice u8)] [next u64 0])
24
- (when (== left 0) (return 0))
24
+ (when (== left 0) (return #t))
25
25
  (when (< left 512) (return (bad! err "the archive is cut short")))
26
26
  (set! h (slice data at (+ at 512)))
27
- (when (zeros? h) (return 0))
27
+ (when (zeros? h) (return #t))
28
28
  (unless (summed? h) (return (bad! err "a header's checksum is wrong")))
29
29
  (unless (octal h 124 12 (& size)) (return (bad! err "a header's size is not a number")))
30
30
  (when sized (set! size given-size))
@@ -36,45 +36,50 @@
36
36
  (cond [(== type #\x)
37
37
  (unless (pax! a body (& long) (& sized) (& given-size)) (return (bad! err "a pax header is not key=value records")))]
38
38
  [(or (== type #\g) (== type #\K)) (begin)]
39
- [(== type #\L) (set! long (copied a (until-zero body)))]
39
+ [(== type #\L) (set! long (cast string (copy a (until-zero body))))]
40
40
  [else
41
41
  (set! (-> e kind) (cond [(or (== type #\0) (== type 0) (== type #\7)) tar-file]
42
42
  [(== type #\5) tar-directory]
43
43
  [else tar-other]))
44
44
  (set! (-> e path) (if (> (-> long length) 0) long (header-path a h)))
45
45
  (set! (-> e bytes) (if (== (-> e kind) tar-file) body (slice body 0 0)))
46
- (return 1)])))))
46
+ (set! (@ found) #t)
47
+ (return #t)])))))
47
48
 
48
- ;; tar-unpack! gives 0, or -1 when data is not a tar archive and -2 when a file cannot be written, with err saying why.
49
- (define (tar-unpack! [a (ptr arena)] [data (slice u8)] [dir string] [err (ptr buffer)]) -> i32
50
- (let ([r tar-reader] [e tar-entry] [got i32 1] [top ""] [one #t] [why string])
49
+ (define (tar-unpack! [a (ptr arena)] [data (slice u8)] [dir string] [err (ptr buffer)]) -> bool
50
+ (let ([r tar-reader] [e tar-entry] [found #t] [top ""] [one #t] [why error] [reason (make-buffer)])
51
51
  (tar-reader-init! (& r) data)
52
- (while (== got 1)
53
- (set! got (tar-next! a (& r) (& e) err))
54
- (when (and (== got 1) (!= (-> e kind) tar-other))
52
+ (while found
53
+ (unless (tar-next! a (& r) (& e) (& found) (& reason))
54
+ (buffer-add-string! err "not a tar archive: ")
55
+ (buffer-add! err (buffer-bytes (& reason)))
56
+ (buffer-free! (& reason))
57
+ (return #f))
58
+ (when (and found (!= (-> e kind) tar-other))
55
59
  (let ([p (cleaned (-> e path))])
56
60
  (when (> (-> p length) 0)
57
61
  (when (== (-> top length) 0) (set! top (first-part p)))
58
62
  (unless (or (and (== p top) (== (-> e kind) tar-directory)) (inside-top? p top)) (set! one #f))))))
59
- (when (< got 0) (return -1))
63
+ (buffer-free! (& reason))
60
64
  (tar-reader-init! (& r) data)
61
- (set! got 1)
62
- (while (== got 1)
63
- (set! got (tar-next! a (& r) (& e) err))
64
- (when (and (== got 1) (!= (-> e kind) tar-other))
65
+ (set! found #t)
66
+ (while found
67
+ (tar-next! a (& r) (& e) (& found) err)
68
+ (when (and found (!= (-> e kind) tar-other))
65
69
  (let ([p (cleaned (-> e path))])
66
70
  (when (and one (> (-> top length) 0)) (set! p (if (== p top) "" (slice p (+ (-> top length) 1)))))
67
71
  (when (> (-> p length) 0)
68
72
  (let ([full (under a dir p)])
69
- (when (or (and (== (-> e kind) tar-directory) (< (fs-make-dir full (& why)) 0))
73
+ (when (or (and (== (-> e kind) tar-directory) (not (fs-make-dir full (& why))))
70
74
  (and (== (-> e kind) tar-file)
71
- (or (< (fs-make-dir (up-to-last-slash full) (& why)) 0)
72
- (< (fs-write-file full (-> e bytes) (& why)) 0))))
75
+ (not (and (fs-make-dir (up-to-last-slash full) (& why))
76
+ (fs-write-file full (-> e bytes) (& why))))))
73
77
  (buffer-add-string! err p)
74
78
  (buffer-add-string! err ": ")
75
- (buffer-add-string! err why)
76
- (return -2)))))))
77
- 0))
79
+ (buffer-add-string! err (error-text (& why)))
80
+ (error-free! (& why))
81
+ (return #f)))))))
82
+ #t))
78
83
 
79
84
  (define (cleaned [p string]) -> string
80
85
  (let ([s p])
@@ -91,20 +96,20 @@
91
96
  (and (> (-> p length) (-> top length)) (== (slice p 0 (-> top length)) top) (== (@ p (-> top length)) #\/)))
92
97
 
93
98
  (define (under [a (ptr arena)] [dir string] [p string]) -> string
94
- (let ([out (cast (ptr u8) (arena-alloc a (+ (-> dir length) 1 (-> p length))))])
95
- (memcpy out (-> dir bytes) (-> dir length))
99
+ (let ([out (new a u8 (+ (-> dir length) 1 (-> p length)))])
100
+ (memcpy (-> out items) (-> dir bytes) (-> dir length))
96
101
  (set! (@ out (-> dir length)) #\/)
97
- (memcpy (+ out (-> dir length) 1) (-> p bytes) (-> p length))
98
- (cast string (slice out (+ (-> dir length) 1 (-> p length))))))
102
+ (memcpy (+ (-> out items) (-> dir length) 1) (-> p bytes) (-> p length))
103
+ (cast string out)))
99
104
 
100
105
  (define (up-to-last-slash [p string]) -> string
101
106
  (let ([i (-> p length)])
102
107
  (while (and (> i 0) (!= (@ p (- i 1)) #\/)) (-= i 1))
103
108
  (if (<= i 1) "/" (slice p 0 (- i 1)))))
104
109
 
105
- (define (bad! [err (ptr buffer)] [why string]) -> i32
110
+ (define (bad! [err (ptr buffer)] [why string]) -> bool
106
111
  (buffer-add-string! err why)
107
- -1)
112
+ #f)
108
113
 
109
114
  (define (zeros? [h (slice u8)]) -> bool
110
115
  (for ([i u32 0]) (< i (-> h length)) (+= i 1) (when (!= (@ h i) 0) (return #f)))
@@ -154,7 +159,7 @@
154
159
  (while (and (< eq (- end 1)) (!= (@ body eq) #\=)) (+= eq 1))
155
160
  (when (>= eq (- end 1)) (return #f))
156
161
  (let ([key (cast string (slice body (+ i 1) eq))] [value (cast string (slice body (+ eq 1) (- end 1)))])
157
- (cond [(== key "path") (set! (@ path) (copied a (cast (slice u8) value)))]
162
+ (cond [(== key "path") (set! (@ path) (copy a value))]
158
163
  [(== key "size")
159
164
  (unless (decimal value size) (return #f))
160
165
  (set! (@ sized) #t)]))
@@ -164,19 +169,14 @@
164
169
  (define (header-path [a (ptr arena)] [h (slice u8)]) -> string
165
170
  (let ([name (until-zero (slice h 0 100))] [prefix (until-zero (slice h 345 500))])
166
171
  (if (and (== (cast string (slice h 257 263)) "ustar\x00;") (> (-> prefix length) 0))
167
- (let ([out (cast (ptr u8) (arena-alloc a (+ (-> prefix length) 1 (-> name length))))])
168
- (memcpy out (-> prefix items) (-> prefix length))
172
+ (let ([out (new a u8 (+ (-> prefix length) 1 (-> name length)))])
173
+ (memcpy (-> out items) (-> prefix items) (-> prefix length))
169
174
  (set! (@ out (-> prefix length)) #\/)
170
- (memcpy (+ out (-> prefix length) 1) (-> name items) (-> name length))
171
- (cast string (slice out (+ (-> prefix length) 1 (-> name length)))))
172
- (copied a name))))
175
+ (memcpy (+ (-> out items) (-> prefix length) 1) (-> name items) (-> name length))
176
+ (cast string out))
177
+ (cast string (copy a name)))))
173
178
 
174
179
  (define (until-zero [s (slice u8)]) -> (slice u8)
175
180
  (let ([i u32 0])
176
181
  (while (and (< i (-> s length)) (!= (@ s i) 0)) (+= i 1))
177
182
  (slice s 0 i)))
178
-
179
- (define (copied [a (ptr arena)] [s (slice u8)]) -> string
180
- (let ([out (cast (ptr u8) (arena-alloc a (-> s length)))])
181
- (memcpy out (-> s items) (-> s length))
182
- (cast string (slice out (-> s length)))))
@@ -16,7 +16,7 @@
16
16
  [stopped (fn ((ptr chromium)))])
17
17
 
18
18
  (define (chromium-start [c (ptr chromium)] [file string] [profile string] [args (slice string)] [ms f64]
19
- [started (fn ((ptr chromium)))] [err (ptr string)]) -> bool
19
+ [started (fn ((ptr chromium)))] [err (ptr error)]) -> bool
20
20
  (let ([argv (make-buffer)] [o process-options] [profile-flag (make-buffer)]
21
21
  [fixed (slice (array-of string "--headless=new" "--remote-debugging-port=0" "--no-first-run"
22
22
  "--no-default-browser-check" "--no-sandbox" "--mute-audio"
@@ -41,9 +41,10 @@
41
41
  (process-options-init! (& o))
42
42
  (set! (-> o stdin) process-ignore)
43
43
  (set! (-> o stdout) process-ignore)
44
- (set! (-> c id) (process-spawn file (strings-in (& argv)) (& o) (cast (ptr void) (& (-> c head))) err))
45
- (buffer-free! (& argv))
46
- (when (== (-> c id) 0) (return #f))
44
+ (let ([spawned (process-spawn file (strings-in (& argv)) (& o) (cast (ptr void) (& (-> c head))) (& (-> c id))
45
+ err)])
46
+ (buffer-free! (& argv))
47
+ (unless spawned (return #f)))
47
48
  (set! (-> c running) #t)
48
49
  (stream-tag! (process-stderr (-> c id)) (cast (ptr void) (& (-> c head))))
49
50
  (stream-read! (process-stderr (-> c id)) (slice (-> c chunk)))