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
@@ -200,15 +200,15 @@
200
200
  (http-finish! r)]
201
201
  [(<= size whole)
202
202
  (let ([f (slice u8)])
203
- (if (< (fs-read-file name (& f) 0) 0)
203
+ (if (not (fs-read-file name (& f) 0))
204
204
  (failed! r)
205
205
  (begin
206
206
  (head-of! r name partial s size)
207
207
  (http-send! r (slice f (cast u32 (-> s start)) (cast u32 (-> s end))))
208
208
  (free (-> f items)))))]
209
209
  [else
210
- (let* ([h (fs-open-file name fs-read-flag 0)] [file (if (== h 0) 0 (fs-read-stream h (-> s start) 0 0))])
211
- (if (== file 0)
210
+ (let ([h u32 0] [file u32 0])
211
+ (if (not (and (fs-open-file name fs-read-flag (& h) 0) (fs-read-stream h (-> s start) 0 (& file) 0)))
212
212
  (failed! r)
213
213
  (begin
214
214
  (head-of! r name partial s size)
@@ -262,7 +262,7 @@
262
262
  (if (and ok (> n 0) (== (refusal (slice parts n)) 0))
263
263
  (begin
264
264
  (joined! (& name) (slice parts n))
265
- (if (and (>= (fs-stat (buffer-string (& name)) (& info) 0) 0) (== (-> info kind) fs-file))
265
+ (if (and (fs-stat (buffer-string (& name)) (& info) 0) (== (-> info kind) fs-file))
266
266
  (send! r files (buffer-string (& name)) (slice (buffer-string (& name)) (+ prefix 1)) (& info))
267
267
  (not-found! r)))
268
268
  (not-found! r))))
@@ -282,7 +282,7 @@
282
282
  (joined! (& name) parts)
283
283
  (when (== (-> parts length) 0) (buffer-add-byte! (& name) #\/))
284
284
  (when slash (buffer-add-string! (& name) "index.html"))
285
- (let ([found (>= (fs-stat (buffer-string (& name)) (& info) 0) 0)])
285
+ (let ([found (fs-stat (buffer-string (& name)) (& info) 0)])
286
286
  (cond [(and found (== (-> info kind) fs-directory) (not slash)) (moved! r)]
287
287
  [(or (not found) (!= (-> info kind) fs-file)) (not-found! r)]
288
288
  [else
package/std/http/url.sub CHANGED
@@ -26,7 +26,7 @@
26
26
  (for ([i u32 0]) (< i n) (+= i 1)
27
27
  (when (or (escape? s i) (and plus (== (@ s i) #\+))) (set! plain #f)))
28
28
  (when plain (return s))
29
- (let ([p (cast (ptr u8) (arena-alloc a n))] [i u32 0] [k u32 0])
29
+ (let ([p (new a u8 n)] [i u32 0] [k u32 0])
30
30
  (while (< i n)
31
31
  (cond [(escape? s i)
32
32
  (set! (@ p k) (+ (* 16 (digit-value (@ s (+ i 1)) 16)) (digit-value (@ s (+ i 2)) 16)))
@@ -38,7 +38,7 @@
38
38
  (set! (@ p k) (@ s i))
39
39
  (+= i 1)])
40
40
  (+= k 1))
41
- (cast string (slice p k)))))
41
+ (cast string (slice p 0 k)))))
42
42
 
43
43
  ;; A path's segments after its first slash, decoded into the arena: "/" has none, and a final slash gives an empty last
44
44
  ;; segment. It returns 1 when a segment is . or .., or empty before the end, and -1 when the path does not start with a
@@ -49,7 +49,7 @@
49
49
  (when (or (== n 0) (!= (@ path 0) #\/)) (return -1))
50
50
  (when (== n 1) (return 0))
51
51
  (for ([i u32 1]) (< i n) (+= i 1) (when (== (@ path i) #\/) (+= count 1)))
52
- (let ([items (cast (ptr string) (arena-alloc a (* count (sizeof string))))])
52
+ (let ([items (new a string count)])
53
53
  (for ([i u32 1]) (<= i n) (+= i 1)
54
54
  (when (or (== i n) (== (@ path i) #\/))
55
55
  (let ([s (url-unescape a (slice path start i) #f)])
@@ -57,12 +57,12 @@
57
57
  (set! (@ items k) s)
58
58
  (+= k 1)
59
59
  (set! start (+ i 1)))))
60
- (set! (@ to) (slice items k))
60
+ (set! (@ to) (slice items 0 k))
61
61
  (if unclean 1 0))))
62
62
 
63
63
  ;; The path the segments name, resolved as Go's path.Clean does, keeping a final slash.
64
64
  (define (url-add-clean! [b (ptr buffer)] [segments (slice string)])
65
- (let* ([n (-> segments length)] [kept (cast (ptr u32) (malloc (* 4 (+ n 1))))] [k u32 0]
65
+ (let* ([n (-> segments length)] [kept (new 0 u32 (+ n 1))] [k u32 0]
66
66
  [last (if (> n 0) (@ segments (- n 1)) "x")] [slash (or (== last "") (== last ".") (== last ".."))])
67
67
  (for ([i u32 0]) (< i n) (+= i 1)
68
68
  (let ([s (@ segments i)])
@@ -76,7 +76,7 @@
76
76
  (buffer-add-byte! b #\/)
77
77
  (url-add-segment! b (@ segments (@ kept j))))
78
78
  (when (and slash (> k 0)) (buffer-add-byte! b #\/))
79
- (free kept)))
79
+ (free (-> kept items))))
80
80
 
81
81
  (define hex-digits string "0123456789ABCDEF")
82
82
 
@@ -109,17 +109,17 @@
109
109
  (define (url-form-parse [a (ptr arena)] [s string]) -> (slice url-pair)
110
110
  (let ([n (-> s length)] [count u32 1] [k u32 0] [start u32 0])
111
111
  (for ([i u32 0]) (< i n) (+= i 1) (when (== (@ s i) #\&) (+= count 1)))
112
- (let ([pairs (cast (ptr url-pair) (arena-alloc a (* count (sizeof url-pair))))])
112
+ (let ([pairs (new a url-pair count)])
113
113
  (for ([i u32 0]) (<= i n) (+= i 1)
114
114
  (when (or (== i n) (== (@ s i) #\&))
115
115
  (when (> i start)
116
116
  (let ([part (slice s start i)] [e u32 0])
117
117
  (while (and (< e (-> part length)) (!= (@ part e) #\=)) (+= e 1))
118
- (set! (-> (+ pairs k) name) (url-unescape a (slice part 0 e) #t))
119
- (set! (-> (+ pairs k) value) (url-unescape a (if (< e (-> part length)) (slice part (+ e 1)) "") #t))
118
+ (set! (-> (@ pairs k) name) (url-unescape a (slice part 0 e) #t))
119
+ (set! (-> (@ pairs k) value) (url-unescape a (if (< e (-> part length)) (slice part (+ e 1)) "") #t))
120
120
  (+= k 1)))
121
121
  (set! start (+ i 1))))
122
- (slice pairs k))))
122
+ (slice pairs 0 k))))
123
123
 
124
124
  ;; The value of the first pair with the name.
125
125
  (define (url-form-value [pairs (slice url-pair)] [name string] [to (ptr string)]) -> bool
@@ -19,14 +19,11 @@
19
19
  ;; A message beyond this many bytes closes the connection with 1009.
20
20
  (const largest u32 16777216)
21
21
 
22
- (const state-open i32 0)
23
- (const state-closing i32 1)
24
- (const state-finishing i32 2)
25
- (const state-closed i32 3)
22
+ (enum ws-state state-open state-closing state-finishing state-closed)
26
23
 
27
24
  (struct ws-connection [head event-head] [stream u32] [user (ptr void)] [server (ptr http-server)] [ping f64]
28
25
  [hook http-hook] [frames buffer] [message buffer] [out buffer]
29
- [kind i32] [state i32] [code i32] [reading bool] [full bool] [timer u32] [timer-at f64] [heard f64] [pinged bool]
26
+ [kind i32] [state ws-state] [code i32] [reading bool] [full bool] [timer u32] [timer-at f64] [heard f64] [pinged bool]
30
27
  [any-origin bool]
31
28
  [on-message (fn ((ptr ws-connection) (slice u8) i32))]
32
29
  [on-closed (fn ((ptr ws-connection) i32))]
@@ -21,7 +21,6 @@
21
21
  (while (< i (length wanted))
22
22
  (let* ([u (list-ref wanted i)] [info (type-info u)])
23
23
  (when (or (== info 0) (== (car info) 'union)) (raise-syntax-error who "expected a struct or variant type" u))
24
- (unless (null? (cadddr info)) (raise-syntax-error who "expected a type without parameters" u))
25
24
  (set! out (append out (code u info))))
26
25
  (+= i 1))
27
26
  #`(begin #,@out))]
@@ -44,7 +43,6 @@
44
43
  (define (type-syntax [type datum]) -> datum
45
44
  (cond [(symbol? type) (datum->syntax #'here type 0)]
46
45
  [(identifier? type) type]
47
- [(identifier? (car type)) #`(#,(car type) #,@(for/list ([u (cdr type)]) (type-syntax u)))]
48
46
  [(== (car type) 'array) #`(array #,(type-syntax (cadr type)) #,(datum->syntax #'here (caddr type) 0))]
49
47
  [(== (car type) 'other) (cadr type)]
50
48
  [else #`(#,(datum->syntax #'here (car type) 0) #,(type-syntax (cadr type)))]))
@@ -0,0 +1,41 @@
1
+ ;; Operations that pick their function by the type of their first argument, as method calls do. (method form suffix x
2
+ ;; arg ...) calls the function whose name is x's type followed by the suffix, for x a pointer to a named type. With
3
+ ;; suffix -push! and x a (ptr points), it calls points-push!. form is the operation's own form, for errors.
4
+ ;; (define-methods [operation suffix] ...) defines each operation as a macro that calls method with its suffix.
5
+ ;; method-name in std/meta/type-info gives the function's name, for macros that define the functions.
6
+ (provide method define-methods)
7
+
8
+ (begin-for-syntax
9
+ (require-unqualified compiler/macros)
10
+ (require-unqualified "type-info.sub")
11
+
12
+ (define (method-form [s datum]) -> datum
13
+ (syntax-match s
14
+ [(_ form suffix x arg ...) #`(let ([the-receiver #,x]) (method-call #,form #,suffix the-receiver #,@arg))]))
15
+
16
+ (define (method-call-form [s datum]) -> datum
17
+ (syntax-match s
18
+ [(_ form suffix x arg ...)
19
+ (let ([t (variable-type x)] [op (syntax-e (car (syntax->list form)))])
20
+ (unless (and (pair? t) (== (car t) 'ptr) (identifier? (cadr t)))
21
+ (raise-syntax-error op (datum->string (format "expected a pointer to a named type, not ~s" `(,(type-datum t))))
22
+ form))
23
+ (let* ([name (method-name (cadr t) (syntax-e suffix))] [f (datum->syntax name (syntax-e name) form)])
24
+ (when (== (identifier-binding-kind f) '#f)
25
+ (raise-syntax-error op (format-message "~a has no ~a" `(,(syntax-e (cadr t)) ,(syntax-e f))) form))
26
+ #`(#,f #,x #,@arg)))]))
27
+
28
+ (define (operation-form [suffix datum] [s datum]) -> datum
29
+ (syntax-match s
30
+ [(_ x arg ...) #`(method #,s #,(datum->syntax s suffix s) #,x #,@arg)]
31
+ [_ (raise-syntax-error 0 "expected a pointer to a named type" s)]))
32
+
33
+ (define (define-methods-form [s datum]) -> datum
34
+ (syntax-match s
35
+ [(_ ((? identifier? op) (? identifier? suffix)) ...)
36
+ #`(begin #,@(for/list ([o op] [x suffix]) #`(define-syntax #,o operation-form '#,x)))]
37
+ [_ (raise-syntax-error 'define-methods "expected (define-methods [operation suffix] ...)" s)])))
38
+
39
+ (define-syntax method method-form)
40
+ (define-syntax method-call method-call-form)
41
+ (define-syntax define-methods define-methods-form)
@@ -1,54 +1,44 @@
1
1
  ;; Types as data at compile time, for macros that write code from a type's fields.
2
2
  (require-unqualified compiler/macros)
3
3
 
4
- (provide type-info variable-type type-datum)
4
+ (provide type-info variable-type type-datum method-name)
5
5
 
6
- ;; (kind name items parameters), kind struct, union or variant, or 0 when t names none. A struct's or union's items are
7
- ;; (field . type), a variant's (case (field . type) ...). A type is i8 to u64, f32, f64, bool or string, (ptr type),
8
- ;; (slice type), (array type n), a struct's, union's or variant's identifier, (identifier type ...) for one with
9
- ;; parameters, or (other type). For (identifier type ...), the items have those types in place of the parameters, and the
10
- ;; parameters are ().
6
+ ;; (kind name items), kind struct, union, variant or enum, or 0 when t names none. A struct's or union's items are
7
+ ;; (field . type), a variant's (case (field . type) ...) and an enum's (case). A type is i8 to u64, f32, f64, bool or
8
+ ;; string, (ptr type), (slice type), (array type n), a struct's, union's, variant's or enum's identifier, or
9
+ ;; (other type).
11
10
  (define (type-info [t datum]) -> datum
12
- (let ([instance (pair? t)])
13
- (syntax-match (binding-of (if instance (car t) t))
14
- [('substrate-struct name (item ...) kind (p ...))
15
- (let ([k (syntax-e kind)] [env (if instance (for/list ([q p] [a (cdr t)]) (cons (syntax-e q) a)) nil)])
16
- `(,k ,name ,(for/list ([i item]) (if (== k 'variant) (case-info i env) (field-info i env)))
17
- ,(if instance nil p)))]
18
- [('substrate-typedef u)
19
- (let ([d (parsed-type (syntax->datum u))])
20
- (if (or (identifier? d) (and (pair? d) (identifier? (car d)))) (type-info d) 0))]
21
- [_ 0])))
11
+ (syntax-match (binding-of t)
12
+ [('substrate-struct name (item ...) kind . _)
13
+ (let ([k (syntax-e kind)])
14
+ `(,k ,name ,(for/list ([i item]) (if (!= (memq k '(variant enum)) 0) (case-info i) (field-info i)))))]
15
+ [('substrate-typedef u) (let ([d (parsed-type (syntax->datum u))]) (if (identifier? d) (type-info d) 0))]
16
+ [_ 0]))
22
17
 
23
18
  (define (binding-of [t datum]) -> datum
24
19
  (if (and (identifier? t) (== (identifier-binding-kind t) 'compile-time-value)) (syntax-local-value t) 0))
25
20
 
26
- (define (case-info [c datum] [env datum]) -> datum
27
- (let ([l (syntax->list c)]) (cons (car l) (for/list ([f (cdr l)]) (field-info f env)))))
21
+ (define (case-info [c datum]) -> datum
22
+ (let ([l (syntax->list c)]) (cons (car l) (for/list ([f (cdr l)]) (field-info f)))))
28
23
 
29
- (define (field-info [f datum] [env datum]) -> datum
30
- (let ([l (syntax->list f)]) (cons (car l) (type-of (cadr l) env))))
24
+ (define (field-info [f datum]) -> datum
25
+ (let ([l (syntax->list f)]) (cons (car l) (type-of (cadr l)))))
31
26
 
32
27
  (define scalars datum '(i8 u8 i16 u16 i32 u32 i64 u64 f32 f64 bool string))
33
28
 
34
- (define (type-of [t datum] [env datum]) -> datum
29
+ (define (type-of [t datum]) -> datum
35
30
  (syntax-match t
36
31
  [(? identifier? x)
37
- (cond [(!= (memq (syntax-e x) scalars) 0) (syntax-e x)]
38
- [(!= (assq (syntax-e x) env) 0) (cdr (assq (syntax-e x) env))]
39
- [else (syntax-match (binding-of x)
40
- [('substrate-struct _ _ _ ()) x]
41
- [('substrate-typedef u) (parsed-type (syntax->datum u))]
42
- [_ `(other ,t)])])]
43
- [('ptr u) `(ptr ,(type-of u env))]
44
- [('slice u) `(slice ,(type-of u env))]
45
- [('array u n) `(array ,(type-of u env) ,(syntax-e n))]
32
+ (if (!= (memq (syntax-e x) scalars) 0)
33
+ (syntax-e x)
34
+ (syntax-match (binding-of x)
35
+ [('substrate-struct . _) x]
36
+ [('substrate-typedef u) (parsed-type (syntax->datum u))]
37
+ [_ `(other ,t)]))]
38
+ [('ptr u) `(ptr ,(type-of u))]
39
+ [('slice u) `(slice ,(type-of u))]
40
+ [('array u n) `(array ,(type-of u) ,(syntax-e n))]
46
41
  [('quote u) (parsed-type (syntax->datum u))]
47
- [((? identifier? h) a ...)
48
- (syntax-match (binding-of h)
49
- [('substrate-struct _ _ _ (p ...))
50
- (if (and (pair? p) (== (length p) (length a))) `(,h ,@(for/list ([u a]) (type-of u env))) `(other ,t))]
51
- [_ `(other ,t)])]
52
42
  [_ `(other ,t)]))
53
43
 
54
44
  (define (variable-type [x datum]) -> datum
@@ -57,11 +47,14 @@
57
47
  (define (type-datum [t datum]) -> datum
58
48
  (let ([d (syntax->datum (datum->syntax #'here t 0))]) (if (and (pair? d) (== (car d) 'other)) (cadr d) d)))
59
49
 
50
+ ;; The function std/meta/method calls for type t and a suffix: points-push! for points and -push!.
51
+ (define (method-name [t datum] [suffix datum]) -> datum
52
+ (datum->syntax t (string->symbol (format-message "~a~a" `(,(syntax-e t) ,suffix))) t))
53
+
60
54
  ;; A type as the checker holds it.
61
55
  (define (parsed-type [d datum]) -> datum
62
56
  (cond [(and (symbol? d) (!= (memq d scalars) 0)) d]
63
57
  [(and (pair? d) (!= (memq (car d) '(ptr slice)) 0)) `(,(car d) ,(parsed-type (cadr d)))]
64
58
  [(and (pair? d) (== (car d) 'array)) `(array ,(parsed-type (cadr d)) ,(caddr d))]
65
- [(and (pair? d) (== (car d) 'struct) (null? (cdddr d))) (name-identifier (cadr d))]
66
- [(and (pair? d) (== (car d) 'struct)) `(,(name-identifier (cadr d)) ,@(for/list ([a (cadddr d)]) (parsed-type a)))]
59
+ [(and (pair? d) (!= (memq (car d) '(struct enum)) 0)) (name-identifier (cadr d))]
67
60
  [else `(other ,d)]))
@@ -19,17 +19,17 @@
19
19
  ;; tracked-files adds the files package-tree finds. When a git repository tracks dir's marker file, it adds only the files
20
20
  ;; git tracks. It gives #f when it cannot read git's index.
21
21
  (define (tracked-files [a (ptr arena)] [dir string] [marker string] [files (ptr buffer)] [err (ptr buffer)]) -> bool
22
- (let ([all (make-buffer)] [nested (make-buffer)] [tracked (make-buffer)] [got i32 0])
22
+ (let ([all (make-buffer)] [nested (make-buffer)] [tracked (make-buffer)] [marked #f] [ok #f])
23
23
  (package-tree a dir (& all) (& nested))
24
- (set! got (git-tracked a dir marker (& tracked) err))
24
+ (set! ok (git-tracked a dir marker (& tracked) (& marked) err))
25
25
  (let ([ps (cast (ptr string) (-> all bytes))] [ts (cast (ptr string) (-> tracked bytes))]
26
26
  [t (/ (-> tracked length) (sizeof string))])
27
- (for ([i u32 0]) (and (>= got 0) (< i (/ (-> all length) (sizeof string)))) (+= i 1)
28
- (when (or (== got 0) (listed? ts t (@ ps i))) (added! files (@ ps i)))))
27
+ (for ([i u32 0]) (and ok (< i (/ (-> all length) (sizeof string)))) (+= i 1)
28
+ (when (or (not marked) (listed? ts t (@ ps i))) (added! files (@ ps i)))))
29
29
  (buffer-free! (& all))
30
30
  (buffer-free! (& nested))
31
31
  (buffer-free! (& tracked))
32
- (>= got 0)))
32
+ ok))
33
33
 
34
34
  (define (listed? [ts (ptr string)] [n u32] [p string]) -> bool
35
35
  (let ([lo u32 0] [hi n])
@@ -46,25 +46,24 @@
46
46
  (tree! a dir "" files nested))
47
47
 
48
48
  (define (tree! [a (ptr arena)] [dir string] [rel string] [files (ptr buffer)] [nested (ptr buffer)])
49
- (let ([here (if (== (-> rel length) 0) dir (joined-path dir rel))] [names (slice string)] [why string])
50
- (if (< (fs-list here (& names) (& why)) 0)
51
- (free (-> why bytes))
52
- (for ([i u32 0]) (< i (-> names length)) (+= i 1)
53
- (let* ([n (@ names i)] [r (if (== (-> rel length) 0) (kept a n) (kept-joined a rel n))] [full (joined-path dir r)]
54
- [info fs-info])
55
- (when (and (not (and (== (-> rel length) 0) (== n "build"))) (!= n ".git") (== (fs-lstat full (& info) 0) 0))
56
- (cond [(== (-> info kind) fs-file) (when (!= files 0) (added! files r))]
57
- [(== (-> info kind) fs-directory)
58
- (let ([own (joined-path full "package.sub")] [m manifest] [err (make-buffer)] [p nested-package])
59
- (if (and (== (fs-stat own (& info) 0) 0) (== (-> info kind) fs-file))
60
- (begin
61
- (set! (-> p name) (if (manifest-read a own (& m) (& err)) (-> m name) (kept a n)))
62
- (set! (-> p path) r)
63
- (buffer-add! nested (slice (cast (ptr u8) (& p)) (sizeof nested-package))))
64
- (tree! a dir r files nested))
65
- (buffer-free! (& err))
66
- (free (-> own bytes)))]))
67
- (free (-> full bytes)))))
49
+ (let ([here (if (== (-> rel length) 0) dir (joined-path dir rel))] [names (slice string)])
50
+ (when (fs-list here (& names) 0)
51
+ (for ([i u32 0]) (< i (-> names length)) (+= i 1)
52
+ (let* ([n (@ names i)] [r (if (== (-> rel length) 0) (kept a n) (kept-joined a rel n))] [full (joined-path dir r)]
53
+ [info fs-info])
54
+ (when (and (not (and (== (-> rel length) 0) (== n "build"))) (!= n ".git") (fs-lstat full (& info) 0))
55
+ (cond [(== (-> info kind) fs-file) (when (!= files 0) (added! files r))]
56
+ [(== (-> info kind) fs-directory)
57
+ (let ([own (joined-path full "package.sub")] [m manifest] [err (make-buffer)] [p nested-package])
58
+ (if (and (fs-stat own (& info) 0) (== (-> info kind) fs-file))
59
+ (begin
60
+ (set! (-> p name) (if (manifest-read a own (& m) (& err)) (-> m name) (kept a n)))
61
+ (set! (-> p path) r)
62
+ (buffer-add! nested (slice (cast (ptr u8) (& p)) (sizeof nested-package))))
63
+ (tree! a dir r files nested))
64
+ (buffer-free! (& err))
65
+ (free (-> own bytes)))]))
66
+ (free (-> full bytes)))))
68
67
  (unless (== (-> rel length) 0) (free (-> here bytes)))))
69
68
 
70
69
  (define (package-exports [a (ptr arena)] [dir string] [m (ptr manifest)] [exports (ptr buffer)] [err (ptr buffer)]) -> bool
@@ -88,7 +87,7 @@
88
87
 
89
88
  (define (file-in? [dir string] [p string]) -> bool
90
89
  (let ([full (joined-path dir p)] [info fs-info] [found #f])
91
- (set! found (and (== (fs-stat full (& info) 0) 0) (== (-> info kind) fs-file)))
90
+ (set! found (and (fs-stat full (& info) 0) (== (-> info kind) fs-file)))
92
91
  (free (-> full bytes))
93
92
  found))
94
93
 
@@ -5,30 +5,29 @@
5
5
 
6
6
  (provide git-tracked)
7
7
 
8
- ;; git-tracked adds the paths, relative to dir, of the regular files the index lists under dir. It gives 1 when they
9
- ;; include dir's marker file, 0 when they do not or no repository holds dir, and -1, with err set, when it cannot read
10
- ;; the index.
11
- (define (git-tracked [a (ptr arena)] [dir string] [marker string] [into (ptr buffer)] [err (ptr buffer)]) -> i32
12
- (let ([top string] [git string] [b (slice u8)] [why string] [prefix ""] [index string] [name (make-buffer)]
13
- [got i32 0])
14
- (unless (repository a dir (& top) (& git)) (return 0))
8
+ ;; git-tracked adds the paths, relative to dir, of the regular files the index lists under dir. It sets marked when they
9
+ ;; include dir's marker file.
10
+ (define (git-tracked [a (ptr arena)] [dir string] [marker string] [into (ptr buffer)] [marked (ptr bool)]
11
+ [err (ptr buffer)]) -> bool
12
+ (let ([top string] [git string] [b (slice u8)] [prefix ""] [index string] [name (make-buffer)] [got i32 0])
13
+ (set! (@ marked) #f)
14
+ (unless (repository a dir (& top) (& git)) (return #t))
15
15
  (unless (== dir top)
16
16
  (let ([p (joined-path (slice dir (if (== top "/") 1 (+ (-> top length) 1))) "")])
17
17
  (set! prefix (kept a p))
18
18
  (free (-> p bytes))))
19
19
  (set! index (joined-path git "index"))
20
- (if (< (fs-read-file index (& b) (& why)) 0)
21
- (free (-> why bytes))
22
- (begin
23
- (set! got (listed! a b (oid-size git) prefix marker (& name) into))
24
- (free (-> b items))
25
- (when (< got 0)
26
- (buffer-add-string! err "cannot read the git index at ")
27
- (buffer-add-string! err index)
28
- (buffer-add-string! err ": sub reads index versions 2 to 4, but not a split or sparse index"))))
20
+ (when (fs-read-file index (& b) 0)
21
+ (set! got (listed! a b (oid-size git) prefix marker (& name) into))
22
+ (free (-> b items))
23
+ (when (< got 0)
24
+ (buffer-add-string! err "cannot read the git index at ")
25
+ (buffer-add-string! err index)
26
+ (buffer-add-string! err ": sub reads index versions 2 to 4, but not a split or sparse index")))
29
27
  (buffer-free! (& name))
30
28
  (free (-> index bytes))
31
- got))
29
+ (set! (@ marked) (== got 1))
30
+ (>= got 0)))
32
31
 
33
32
  ;; repository finds the working tree holding dir, and its git directory: the .git directory, or the directory a .git file
34
33
  ;; points to.
@@ -36,7 +35,7 @@
36
35
  (let ([d dir] [info fs-info] [found i32 0])
37
36
  (while (== found 0)
38
37
  (let ([dot (joined-path d ".git")])
39
- (cond [(== (fs-lstat dot (& info) 0) 0)
38
+ (cond [(fs-lstat dot (& info) 0)
40
39
  (set! found -1)
41
40
  (cond [(== (-> info kind) fs-directory)
42
41
  (set! (@ git) (kept a dot))
@@ -49,10 +48,8 @@
49
48
  (== found 1)))
50
49
 
51
50
  (define (named-git! [a (ptr arena)] [d string] [dot string] [git (ptr string)]) -> bool
52
- (let ([b (slice u8)] [why string] [s string] [end u32 8] [full string])
53
- (when (< (fs-read-file dot (& b) (& why)) 0)
54
- (free (-> why bytes))
55
- (return #f))
51
+ (let ([b (slice u8)] [s string] [end u32 8] [full string])
52
+ (unless (fs-read-file dot (& b) 0) (return #f))
56
53
  (set! s (cast string b))
57
54
  (unless (starts? s "gitdir: ")
58
55
  (free (-> b items))
@@ -65,24 +62,20 @@
65
62
  #t))
66
63
 
67
64
  (define (oid-size [git string]) -> u32
68
- (let ([common (common-dir git)] [config string] [b (slice u8)] [why string] [size u32 20])
65
+ (let ([common (common-dir git)] [config string] [b (slice u8)] [size u32 20])
69
66
  (set! config (joined-path common "config"))
70
- (if (< (fs-read-file config (& b) (& why)) 0)
71
- (free (-> why bytes))
72
- (begin
73
- (when (sha256-objects? (cast string b)) (set! size 32))
74
- (free (-> b items))))
67
+ (when (fs-read-file config (& b) 0)
68
+ (when (sha256-objects? (cast string b)) (set! size 32))
69
+ (free (-> b items)))
75
70
  (free (-> config bytes))
76
71
  (free (-> common bytes))
77
72
  size))
78
73
 
79
74
  ;; common-dir gives the main git directory of a worktree, which holds the config.
80
75
  (define (common-dir [git string]) -> string
81
- (let ([file (joined-path git "commondir")] [b (slice u8)] [why string] [s string] [end u32 0] [out string])
82
- (if (< (fs-read-file file (& b) (& why)) 0)
83
- (begin
84
- (free (-> why bytes))
85
- (set! out (string-copy git)))
76
+ (let ([file (joined-path git "commondir")] [b (slice u8)] [s string] [end u32 0] [out string])
77
+ (if (not (fs-read-file file (& b) 0))
78
+ (set! out (string-copy git))
86
79
  (begin
87
80
  (set! s (cast string b))
88
81
  (while (and (< end (-> s length)) (!= (@ s end) 10) (!= (@ s end) 13)) (+= end 1))
@@ -19,9 +19,9 @@
19
19
  ok))
20
20
 
21
21
  (define (hash! [a (ptr arena)] [given string] [w (ptr waiting)] [into (ptr buffer)] [err (ptr buffer)]) -> bool
22
- (let ([dir string] [why string] [o w] [m manifest] [paths (make-buffer)] [lines (make-buffer)] [digest (array u8 32)]
23
- [ok #t] [me (cast (ptr waiting) (arena-alloc a (sizeof waiting)))])
24
- (when (< (fs-real-path given (& dir) (& why)) 0) (return (cannot! err why)))
22
+ (let ([dir string] [why error] [o w] [m manifest] [paths (make-buffer)] [lines (make-buffer)] [digest (array u8 32)]
23
+ [ok #t] [me (new a waiting)])
24
+ (unless (fs-real-path given (& dir) (& why)) (return (cannot! err (& why))))
25
25
  (while (and (!= o 0) (!= (-> o dir) dir)) (set! o (-> o next)))
26
26
  (when (!= o 0)
27
27
  (buffer-add-string! err "the package ")
@@ -79,9 +79,9 @@
79
79
  ok))
80
80
 
81
81
  (define (file-line! [dir string] [path string] [lines (ptr buffer)] [err (ptr buffer)]) -> bool
82
- (let ([full (joined-path dir path)] [bytes (slice u8)] [why string] [digest (array u8 32)] [ok #t])
83
- (if (< (fs-read-file full (& bytes) (& why)) 0)
84
- (set! ok (cannot! err why))
82
+ (let ([full (joined-path dir path)] [bytes (slice u8)] [why error] [digest (array u8 32)] [ok #t])
83
+ (if (not (fs-read-file full (& bytes) (& why)))
84
+ (set! ok (cannot! err (& why)))
85
85
  (begin
86
86
  (sha256-of bytes (slice digest))
87
87
  (add-hex! lines (slice digest))
@@ -92,10 +92,10 @@
92
92
  (free (-> full bytes))
93
93
  ok))
94
94
 
95
- (define (cannot! [err (ptr buffer)] [why string]) -> bool
95
+ (define (cannot! [err (ptr buffer)] [why (ptr error)]) -> bool
96
96
  (buffer-add-string! err "cannot read ")
97
- (buffer-add-string! err why)
98
- (free (-> why bytes))
97
+ (buffer-add-string! err (error-text why))
98
+ (error-free! why)
99
99
  #f)
100
100
 
101
101
  (define (add-hex! [b (ptr buffer)] [bytes (slice u8)])