substrate-lang 0.9.4 → 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 (188) hide show
  1. package/README.md +1 -1
  2. package/build/compiler/{binary.cdd2ffb408dd@0+0.wasm → binary.2d43b43d1600@0+0.wasm} +0 -0
  3. package/build/compiler/checker.4dd4556dd421@0+0.wasm +0 -0
  4. package/build/compiler/{compile.da85f9bc4478@0+0.wasm → compile.5d8f6407af2a@0+0.wasm} +0 -0
  5. package/build/compiler/{core.0410ffbdc488@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.ba77430f659f@0+0.wasm → leb128.15d814b7b4f2@0+0.wasm} +0 -0
  9. package/build/compiler/{link.be6e641afa93@0+0.wasm → link.b826ea7c8f17@0+0.wasm} +0 -0
  10. package/build/compiler/{macros.b695763c0ca3@0+0.wasm → macros.b269e0c42784@0+0.wasm} +0 -0
  11. package/build/compiler/{main.cbbdf42e34c2@0+0.wasm → main.4fc52f204d54@0+0.wasm} +0 -0
  12. package/build/compiler/{ops.324f0a665fab@0+0.wasm → ops.515b5e05f646@0+0.wasm} +0 -0
  13. package/build/compiler/{path.1b5fd988b6f3@0+0.wasm → path.5a6286472cd4@0+0.wasm} +0 -0
  14. package/build/compiler/program +21 -21
  15. package/build/compiler/{prune.29dde307bdee@0+0.wasm → 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.b99787c2d180@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.f6c742932dde@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.fadc832db29f@0+0.wasm → syntax.32f3e40b61c7@0+0.wasm} +0 -0
  23. package/build/compiler/{writer.550227768eb9@0+0.wasm → writer.00b7802cbe39@0+0.wasm} +0 -0
  24. package/build/sub/{base64.454b045156d2@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.f18ad14060e9@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.0b0362932a75@0+0.wasm → html.a23126eb949a@0+0.wasm} +0 -0
  42. package/build/sub/{html.3b3c8d7d9971@0+0.wasm → html.e9ed37f34977@0+0.wasm} +0 -0
  43. package/build/sub/{inflate.3cfa17586072@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.e582eae03ec2@0+0.wasm → map.f455cca6a42a@0+0.wasm} +0 -0
  47. package/build/sub/pack.e02836264f6a@0+0.wasm +0 -0
  48. package/build/sub/{path.1b5fd988b6f3@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.d256e69e09e2@0+0.wasm → reader.694b03770bf0@0+0.wasm} +0 -0
  54. package/build/sub/{root.02141d04d568@0+0.wasm → root.f10a4906f460@0+0.wasm} +0 -0
  55. package/build/sub/{roots.e366210c01d6@0+0.wasm → roots.cefd10e93684@0+0.wasm} +0 -0
  56. package/build/sub/{sha256.f6c742932dde@0+0.wasm → sha256.a6c32b04d799@0+0.wasm} +0 -0
  57. package/build/sub/{sha512.9fee24e95460@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.fadc832db29f@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.8ff142d72fd7@0+0.wasm → text.1bc90482bd43@0+0.wasm} +0 -0
  68. package/build/sub/{timer.d3454726b3bf@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.e82afeb9e953@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 +30 -23
  75. package/std/browser/chromium.sub +5 -4
  76. package/std/browser/devtools.sub +24 -19
  77. package/std/compress/gzip.sub +18 -16
  78. package/std/compress/inflate.sub +7 -4
  79. package/std/crypto/password.sub +3 -3
  80. package/std/doc/doc.sub +2 -2
  81. package/std/encoding/json.sub +20 -8
  82. package/std/encoding/wire.sub +9 -7
  83. package/std/http/form.sub +2 -2
  84. package/std/http/multipart.sub +8 -10
  85. package/std/http/route.sub +9 -4
  86. package/std/http/server.sub +14 -11
  87. package/std/http/session.sub +2 -2
  88. package/std/http/static.sub +5 -5
  89. package/std/meta/derive.sub +0 -2
  90. package/std/meta/method.sub +41 -0
  91. package/std/meta/type-info.sub +30 -37
  92. package/std/package/files.sub +24 -25
  93. package/std/package/git.sub +26 -33
  94. package/std/package/hash.sub +8 -8
  95. package/std/package/manifest.sub +67 -42
  96. package/std/package/map.sub +1 -1
  97. package/std/package/pack.sub +13 -13
  98. package/std/package/read.sub +7 -6
  99. package/std/package/site.sub +7 -7
  100. package/std/package/store.sub +16 -12
  101. package/std/package.sub +6 -6
  102. package/std/test/browser.sub +9 -8
  103. package/std/test/build.sub +2 -2
  104. package/std/test/page.sub +31 -26
  105. package/std/test/run.sub +8 -7
  106. package/std/test/test.sub +12 -13
  107. package/std/vector/vector.sub +75 -0
  108. package/substrate/VERSION +1 -1
  109. package/substrate/compiler/checker.sub +40 -212
  110. package/substrate/compiler/compile.sub +3 -3
  111. package/substrate/compiler/expander.sub +32 -50
  112. package/substrate/compiler/main.sub +9 -9
  113. package/substrate/compiler/reader.sub +4 -4
  114. package/substrate/compiler/roots.sub +8 -8
  115. package/substrate/compiler/running.sub +1 -1
  116. package/substrate/compiler/serialize.sub +56 -49
  117. package/substrate/compiler/substrate.sub +53 -11
  118. package/substrate/host/errors.mjs +3 -2
  119. package/substrate/host/events.sub +3 -16
  120. package/substrate/host/fs.mjs +5 -4
  121. package/substrate/host/fs.sub +135 -102
  122. package/substrate/host/grants.mjs +1 -1
  123. package/substrate/host/grants.sub +8 -7
  124. package/substrate/host/modules/fake.mjs +1 -1
  125. package/substrate/host/modules/websocket.mjs +4 -4
  126. package/substrate/host/modules/websocket.sub +8 -6
  127. package/substrate/host/node/env.mjs +12 -6
  128. package/substrate/host/node/env.sub +21 -16
  129. package/substrate/host/node/fs.mjs +1 -1
  130. package/substrate/host/node/net.mjs +2 -2
  131. package/substrate/host/node/net.sub +13 -6
  132. package/substrate/host/node/process.mjs +4 -4
  133. package/substrate/host/node/process.sub +25 -24
  134. package/substrate/host/node/signal.mjs +3 -2
  135. package/substrate/host/node/signal.sub +9 -6
  136. package/substrate/host/node/watch.mjs +1 -1
  137. package/substrate/host/node/watch.sub +11 -9
  138. package/substrate/host/stream.sub +2 -0
  139. package/substrate/host/subhost-core.mjs +9 -1
  140. package/substrate/host/web/clipboard.mjs +2 -2
  141. package/substrate/host/web/clipboard.sub +10 -3
  142. package/substrate/host/web/files.mjs +2 -2
  143. package/substrate/host/web/files.sub +6 -2
  144. package/substrate/host/web/fs.mjs +3 -3
  145. package/substrate/host/web/location.mjs +3 -1
  146. package/substrate/host/web/location.sub +8 -4
  147. package/substrate/host/worker-side.mjs +3 -1
  148. package/substrate/host/worker.mjs +6 -5
  149. package/substrate/host/worker.sub +10 -10
  150. package/build/compiler/checker.2b0ea87ed311@0+0.wasm +0 -0
  151. package/build/compiler/expander.80707e1666d6@0+0.wasm +0 -0
  152. package/build/compiler/fs.5017b627cbd2@0+0.wasm +0 -0
  153. package/build/compiler/reader.d256e69e09e2@0+0.wasm +0 -0
  154. package/build/compiler/roots.e366210c01d6@0+0.wasm +0 -0
  155. package/build/compiler/serialize.a12536bbbe9a@0+0.wasm +0 -0
  156. package/build/compiler/substrate.728c690187f2@0+0.wasm +0 -0
  157. package/build/sub/build.115aeefc15e8@0+0.wasm +0 -0
  158. package/build/sub/chromium.fc0bfea0fbe6@0+0.wasm +0 -0
  159. package/build/sub/common.997c21b0b8cf@0+0.wasm +0 -0
  160. package/build/sub/deflate.3138a38325a1@0+0.wasm +0 -0
  161. package/build/sub/doc.e3f9a998cd91@0+0.wasm +0 -0
  162. package/build/sub/env.861d55fff974@0+0.wasm +0 -0
  163. package/build/sub/events.2c981f6f1ec7@0+0.wasm +0 -0
  164. package/build/sub/fetch.b0ce8f8b3da8@0+0.wasm +0 -0
  165. package/build/sub/fetch.d62aa5fc9623@0+0.wasm +0 -0
  166. package/build/sub/files.1706cc0941c0@0+0.wasm +0 -0
  167. package/build/sub/fs.5017b627cbd2@0+0.wasm +0 -0
  168. package/build/sub/git.1c5791236e35@0+0.wasm +0 -0
  169. package/build/sub/grants.cd99dff2854e@0+0.wasm +0 -0
  170. package/build/sub/gzip.9ebea150f218@0+0.wasm +0 -0
  171. package/build/sub/hash.ba8330dad9ff@0+0.wasm +0 -0
  172. package/build/sub/json.af2e0ae20084@0+0.wasm +0 -0
  173. package/build/sub/manifest.6e014ac19e5d@0+0.wasm +0 -0
  174. package/build/sub/pack.4295e4f5bdbd@0+0.wasm +0 -0
  175. package/build/sub/path.de22f6659534@0+0.wasm +0 -0
  176. package/build/sub/process.ca10ac0b8a62@0+0.wasm +0 -0
  177. package/build/sub/read.279fafcda508@0+0.wasm +0 -0
  178. package/build/sub/site.76aa8286c257@0+0.wasm +0 -0
  179. package/build/sub/site.e6e415bc3170@0+0.wasm +0 -0
  180. package/build/sub/store.c48db3345968@0+0.wasm +0 -0
  181. package/build/sub/stream.27fd2fe858e1@0+0.wasm +0 -0
  182. package/build/sub/sub.c0fb7310de12@0+0.wasm +0 -0
  183. package/build/sub/substrate.728c690187f2@0+0.wasm +0 -0
  184. package/build/sub/tar.692c0e8827cd@0+0.wasm +0 -0
  185. package/build/sub/test.1fd2ff8123bf@0+0.wasm +0 -0
  186. package/build/sub/upgrade.2a9219e6a45d@0+0.wasm +0 -0
  187. package/build/sub/worker.ea1e11f8f5e2@0+0.wasm +0 -0
  188. package/build/sub/writer.550227768eb9@0+0.wasm +0 -0
package/std/test/page.sub CHANGED
@@ -62,12 +62,14 @@
62
62
 
63
63
  ;; ---- opening and closing ----
64
64
 
65
- (define (page-open [dir string] [url string] [address string] [server (fn ())] [err (ptr string)]) -> (ptr page)
66
- (let ([b (ptr page) 0])
67
- (try (set! b (opened! dir url address server))
68
- [catch page-failed (why) (set! (@ err) why)])
65
+ (define (page-open [dir string] [url string] [address string] [server (fn ())] [b (ptr (ptr page))] [err (ptr error)])
66
+ -> bool
67
+ (let ([ok #t])
68
+ (set! (@ b) 0)
69
+ (try (set! (@ b) (opened! dir url address server))
70
+ [catch page-failed (why) (set! ok (error-fail! err error-other why))])
69
71
  (arena-free (& work))
70
- b))
72
+ ok))
71
73
 
72
74
  (define (page-close [b (ptr page)])
73
75
  (closed! b)
@@ -75,8 +77,8 @@
75
77
 
76
78
  (define (opened! [dir string] [url string] [address string] [server (fn ())]) -> (ptr page)
77
79
  (unless connected
78
- (let ([why string])
79
- (unless (devtools-connect (& connection) address heard 0 (& why)) (throw page-failed why))
80
+ (let ([why error])
81
+ (unless (devtools-connect (& connection) address heard 0 (& why)) (throw page-failed (error-text (& why))))
80
82
  (set! connected #t)))
81
83
  (let ([b (new 0 page)])
82
84
  (+= opened 1)
@@ -134,7 +136,7 @@
134
136
  (loaded! b "Page.navigate" (params-text (& p)))))
135
137
 
136
138
  (define (closed! [b (ptr page)])
137
- (let ([all (opened-pages)] [r (ptr json-value) 0] [why string] [p (params-of)])
139
+ (let ([all (opened-pages)] [r (ptr json-value) 0] [p (params-of)])
138
140
  (for ([i u32 0]) (< i (-> all length)) (+= i 1)
139
141
  (when (== (@ all i) (cast u32 b))
140
142
  (memcpy (cast (ptr u8) (+ (-> all items) i)) (cast (ptr u8) (+ (-> all items) (+ i 1))) (* (- (-> all length) (+ i 1)) 4))
@@ -142,7 +144,7 @@
142
144
  (break)))
143
145
  (when (and connected (> (-> b context length) 0))
144
146
  (param-string! (& p) "browserContextId" (-> b context))
145
- (devtools-call (& connection) (& work) "Target.disposeBrowserContext" (params-text (& p)) "" (& r) (& why)))
147
+ (devtools-call (& connection) (& work) "Target.disposeBrowserContext" (params-text (& p)) "" (& r) 0))
146
148
  (when (> (-> b downloads-dir length) 0) (fs-remove (-> b downloads-dir) #t 0))
147
149
  (unless (== (-> b server) 0) (worker-stop (-> b server)))
148
150
  (when (and connected (== (-> pages length) 0))
@@ -158,12 +160,13 @@
158
160
  ;; Starts the server on a worker with the site's directory as its argument, and gives the first line it prints, its
159
161
  ;; address, with index.html after it.
160
162
  (define (served-from! [b (ptr page)] [server (fn ())]) -> string
161
- (let ([o worker-options] [why string] [line (make-buffer)] [said (make-buffer)] [until (+ (clock-monotonic) 60000.0)])
163
+ (let ([o worker-options] [why error] [line (make-buffer)] [said (make-buffer)] [until (+ (clock-monotonic) 60000.0)])
162
164
  (worker-options-init! (& o))
163
165
  (set! (-> o output) #t)
164
166
  (set! (-> server-head handle) unheard)
165
- (set! (-> b server) (worker-start server (cast (slice u8) (-> b site)) (& o) (cast (ptr void) (& server-head)) (& why)))
166
- (when (== (-> b server) 0) (throw page-failed why))
167
+ (unless (worker-start server (cast (slice u8) (-> b site)) (& o) (cast (ptr void) (& server-head)) (& (-> b server))
168
+ (& why))
169
+ (throw page-failed (error-text (& why))))
167
170
  (while #t
168
171
  (let ([left (- until (clock-monotonic))] [value i32 0] [bytes (slice u8)] [kind i32 0] [ended string ""])
169
172
  (when (<= left 0.0) (throw page-failed "the server did not print its address within 60 s"))
@@ -365,9 +368,9 @@
365
368
 
366
369
  (define (page-choose-files! [b (ptr page)] [paths (slice string)])
367
370
  (guarded b
368
- (let ([out (make-buffer)] [info fs-info] [why string])
371
+ (let ([out (make-buffer)] [info fs-info] [why error])
369
372
  (for ([i u32 0]) (< i (-> paths length)) (+= i 1)
370
- (when (< (fs-stat (@ paths i) (& info) (& why)) 0) (throw page-failed why))
373
+ (unless (fs-stat (@ paths i) (& info) (& why)) (throw page-failed (error-text (& why))))
371
374
  (pushed-text! (& out) (native-path (absolute (@ paths i)))))
372
375
  (set! (-> b chosen) (strings-in (& out)))
373
376
  (set! (-> b choosing) #t))))
@@ -563,8 +566,8 @@
563
566
  (try (evaluated b "window.ready = false") [catch page-failed (why) (begin)])
564
567
  (set! (-> b thrown) #f)
565
568
  (set! (-> b errors length) 0)
566
- (let ([error (text-at (page-call b method parameters) "errorText")])
567
- (when (> (-> error length) 0) (throw page-failed (cat "the browser cannot open the page: " error))))
569
+ (let ([refusal (text-at (page-call b method parameters) "errorText")])
570
+ (when (> (-> refusal length) 0) (throw page-failed (cat "the browser cannot open the page: " refusal))))
568
571
  (started! b))
569
572
 
570
573
  ;; Asks the agent in the page to carry out the request, and gives its answer.
@@ -621,10 +624,10 @@
621
624
  (while #t
622
625
  (let ([all (cast (ptr download) (-> b downloads bytes))] [n (/ (-> b downloads length) (sizeof download))])
623
626
  (for ([i u32 0]) (< i n) (+= i 1)
624
- (let ([d (+ all i)] [bytes (slice u8)] [why string])
627
+ (let ([d (+ all i)] [bytes (slice u8)] [why error])
625
628
  (when (and (== (-> d name) name) (== (-> d state) "completed"))
626
- (when (< (fs-read-file (joined-path (-> b downloads-dir) (-> d guid)) (& bytes) (& why)) 0)
627
- (throw page-failed why))
629
+ (unless (fs-read-file (joined-path (-> b downloads-dir) (-> d guid)) (& bytes) (& why))
630
+ (throw page-failed (error-text (& why))))
628
631
  (return bytes)))))
629
632
  (when (>= (clock-monotonic) until) (throw page-failed (cat (cat "no file named " (quoted name)) " was downloaded")))
630
633
  (devtools-pump (& connection) 20.0))
@@ -689,7 +692,7 @@
689
692
  [(== from origin)
690
693
  (let* ([file (if (== path "/") "/index.html" path)] [bytes (slice u8)]
691
694
  [full (resolved-path (-> b site) (slice file 1 (-> file length)))])
692
- (if (and (within? full (-> b site)) (>= (fs-read-file full (& bytes) 0) 0))
695
+ (if (and (within? full (-> b site)) (fs-read-file full (& bytes) 0))
693
696
  (fulfilled! session request 200 (type-of file) bytes #f)
694
697
  (fulfilled! session request 404 "text/plain" (cast (slice u8) "not found") #f)))]
695
698
  [(and (> (-> b server-host length) 0) (== (host-of from) (-> b server-host)))
@@ -722,7 +725,7 @@
722
725
 
723
726
  ;; A file picker that opened gives the files the test chose, or else is cancelled.
724
727
  (define (chose! [b (ptr page)] [node f64])
725
- (let ([q (params-of)] [a (make-arena)] [r (ptr json-value) 0] [why string])
728
+ (let ([q (params-of)] [a (make-arena)] [r (ptr json-value) 0] [why error])
726
729
  (param-number! (& q) "backendNodeId" node)
727
730
  (if (-> b choosing)
728
731
  (let ([files (make-buffer)])
@@ -734,21 +737,23 @@
734
737
  (buffer-add-byte! (& files) #\])
735
738
  (param-raw! (& q) "files" (buffer-string (& files)))
736
739
  (unless (devtools-call (& connection) (& a) "DOM.setFileInputFiles" (params-text (& q)) (-> b session) (& r) (& why))
737
- (pushed-text! (& (-> b lines)) (cat "files: " why))))
740
+ (pushed-text! (& (-> b lines)) (cat "files: " (error-text (& why))))))
738
741
  (if (devtools-call (& connection) (& a) "DOM.resolveNode" (params-text (& q)) (-> b session) (& r) (& why))
739
742
  (let ([p (params-of)])
740
743
  (param-string! (& p) "objectId" (text-at (json-get r "object") "objectId"))
741
744
  (param-string! (& p) "functionDeclaration" "function () { this.dispatchEvent(new Event('cancel')); }")
742
745
  (unless (devtools-call (& connection) (& a) "Runtime.callFunctionOn" (params-text (& p)) (-> b session) (& r) (& why))
743
- (pushed-text! (& (-> b lines)) (cat "files: " why))))
744
- (pushed-text! (& (-> b lines)) (cat "files: " why))))
746
+ (pushed-text! (& (-> b lines)) (cat "files: " (error-text (& why))))))
747
+ (pushed-text! (& (-> b lines)) (cat "files: " (error-text (& why))))))
748
+ (error-free! (& why))
745
749
  (arena-free (& a))))
746
750
 
747
751
  ;; ---- helpers ----
748
752
 
749
753
  (define (call [method string] [parameters string] [session string]) -> (ptr json-value)
750
- (let ([r (ptr json-value) 0] [why string])
751
- (unless (devtools-call (& connection) (& work) method parameters session (& r) (& why)) (throw page-failed why))
754
+ (let ([r (ptr json-value) 0] [why error])
755
+ (unless (devtools-call (& connection) (& work) method parameters session (& r) (& why))
756
+ (throw page-failed (error-text (& why))))
752
757
  r))
753
758
 
754
759
  (define (page-call [b (ptr page)] [method string] [parameters string]) -> (ptr json-value)
package/std/test/run.sub CHANGED
@@ -21,20 +21,21 @@
21
21
  ;; ---- running ----
22
22
 
23
23
  (define (program-in [dir string] [program string] [env (slice string)] [args (slice string)] [input (slice u8)]) -> ran
24
- (let ([o process-options] [r ran] [bytes (slice u8)] [why string])
24
+ (let ([o process-options] [r ran] [bytes (slice u8)] [why error])
25
25
  (process-options-init! (& o))
26
26
  (set! (-> o dir) dir)
27
27
  (set! (-> o env) env)
28
- (set! (-> r code) (process-run program args (& o) input 60000 (& bytes) (& why)))
29
- (when (< (-> r code) 0) (throw test-failed (joined (joined program ": ") why)))
28
+ (unless (process-run program args (& o) input 60000 (& bytes) (& (-> r code)) (& why))
29
+ (throw test-failed (joined (joined program ": ") (error-text (& why)))))
30
30
  (set! (-> r output) (cast string bytes))
31
31
  r))
32
32
 
33
33
  (define (granted [clauses (slice (slice string))]) -> grants
34
- (let ([g (make-grants)] [why string])
34
+ (let ([g (make-grants)] [why error])
35
35
  (for ([i u32 0]) (< i (-> clauses length)) (+= i 1)
36
36
  (let ([c (@ clauses i)])
37
- (unless (grants-add! (& g) (@ c 0) (slice c 1 (-> c length)) (& why)) (throw test-failed why))))
37
+ (unless (grants-add! (& g) (@ c 0) (slice c 1 (-> c length)) (& why))
38
+ (throw test-failed (error-text (& why))))))
38
39
  g))
39
40
 
40
41
  (define (host-in [dir string] [env (slice string)] [g (ptr grants)] [args (slice string)] [input (slice u8)]) -> ran
@@ -72,8 +73,8 @@
72
73
  [compare (compare-output! (-> r output) expected message)]))
73
74
 
74
75
  (define (expected-text [path string]) -> string
75
- (let ([bytes (slice u8)] [why string])
76
- (when (< (fs-read-file path (& bytes) (& why)) 0) (throw test-failed (joined (joined path ": ") why)))
76
+ (let ([bytes (slice u8)] [why error])
77
+ (unless (fs-read-file path (& bytes) (& why)) (throw test-failed (joined (joined path ": ") (error-text (& why)))))
77
78
  (cast string bytes)))
78
79
 
79
80
  (define (sub-run-in [dir string] [name string] [grants (slice string)]) -> ran
package/std/test/test.sub CHANGED
@@ -98,12 +98,12 @@
98
98
  (when (and (digits-integer (option "-t") 10 #f (& n)) (> n 0)) (set! at-once (cast u32 n)))
99
99
  (when (digits-integer (option "--timeout-ms") 10 #f (& n)) (set! time-limit n)))
100
100
  (for ([i u32 0]) (< i (-> arguments length)) (+= i 1)
101
- (let ([a (@ arguments i)] [why string])
101
+ (let ([a (@ arguments i)])
102
102
  (cond [(== a "-v") (set! verbose #t)]
103
103
  [(== a "--ignored") (set! ignored-only #t)]
104
104
  [(== a "--nocapture") (set! capturing #f)]
105
105
  [(and (== a "--grant") (< (+ i 2) (-> arguments length)))
106
- (grants-add! (& needs) (@ arguments (+ i 1)) (slice (& (@ arguments (+ i 2))) 1) (& why))
106
+ (grants-add! (& needs) (@ arguments (+ i 1)) (slice (& (@ arguments (+ i 2))) 1) 0)
107
107
  (+= i 2)]))))
108
108
 
109
109
  (define (valued? [a string]) -> bool (or (== a "--name") (== a "-t") (== a "--timeout-ms")))
@@ -205,9 +205,9 @@
205
205
  ;; Returns #t if the test is now running in slot s, or #f if it could not start.
206
206
  (define (started! [s (ptr slot)] [e (ptr entry)]) -> bool
207
207
  (set! (-> s captured length) 0)
208
- (let ([o worker-options] [why string] [scratch (scratch-of e)])
209
- (when (< (fs-make-dir scratch (& why)) 0)
210
- (failed! e why "")
208
+ (let ([o worker-options] [why error] [scratch (scratch-of e)])
209
+ (unless (fs-make-dir scratch (& why))
210
+ (failed! e (error-text (& why)) "")
211
211
  (return #f))
212
212
  (env-set "SUBSTRATE_SCRATCH" scratch 0)
213
213
  (worker-options-init! (& o))
@@ -226,14 +226,13 @@
226
226
  (pushed! (& items) (toolchain-host)))
227
227
  (for ([j u32 1]) (< j (-> c length)) (+= j 1) (pushed! (& items) (scratch-placed (@ c j) scratch))))
228
228
  (unless (grants-add! (& (-> o grants)) kind (strings-in (& items)) (& why))
229
- (failed! e why "")
229
+ (failed! e (error-text (& why)) "")
230
230
  (return #f))))
231
231
  (set! (-> s entry) e)
232
232
  (set! (-> s head handle) heard)
233
- (set! (-> s worker) (worker-start (-> e run) (slice (cast (ptr u8) 0) 0) (& o) (cast (ptr void) (& (-> s head)))
234
- (& why)))
235
- (when (== (-> s worker) 0)
236
- (failed! e (beyond why) "")
233
+ (unless (worker-start (-> e run) (slice (cast (ptr u8) 0) 0) (& o) (cast (ptr void) (& (-> s head)))
234
+ (& (-> s worker)) (& why))
235
+ (failed! e (beyond (error-text (& why))) "")
237
236
  (return #f))
238
237
  (when (> time-limit 0)
239
238
  (set! (-> s clock handle) out-of-time)
@@ -426,12 +425,12 @@
426
425
  (output-differs! got expected message)))
427
426
 
428
427
  (define (compare-output-file! [got string] [module string] [file string] [message string])
429
- (let ([why string] [bytes (slice u8)] [path (test-path module file)])
430
- (when (< (fs-read-file path (& bytes) (& why)) 0)
428
+ (let ([why error] [bytes (slice u8)] [path (test-path module file)])
429
+ (unless (fs-read-file path (& bytes) (& why))
431
430
  (let ([b (make-buffer)])
432
431
  (buffer-add-string! (& b) message)
433
432
  (buffer-add-byte! (& b) 10)
434
- (buffer-add-string! (& b) why)
433
+ (buffer-add-string! (& b) (error-text (& why)))
435
434
  (throw test-failed (buffer-string (& b)))))
436
435
  (unless (== (trimmed got) (trimmed (cast string bytes))) (output-differs! got (cast string bytes) message))
437
436
  (free (-> bytes items))))
@@ -0,0 +1,75 @@
1
+ ;; Vectors: growable arrays of one type, on the heap. (define-vector name type) declares the type name, whose zero value
2
+ ;; is an empty vector, and its functions name-count, name-items, name-at, name-at-unchecked, name-add!, name-push!,
3
+ ;; name-pop!, name-clear!, name-reserve! and name-free!. vector-count, vector-at and the others call the function of
4
+ ;; their first argument's type, and vector-each runs its body for each item. Growing may move the items, so a pointer
5
+ ;; to an item lasts until the vector next grows.
6
+ (require-unqualified std/meta/method)
7
+
8
+ (provide define-vector vector-count vector-items vector-at vector-at-unchecked vector-add! vector-push! vector-pop!
9
+ vector-clear! vector-reserve! vector-free! vector-each)
10
+
11
+ (begin-for-syntax
12
+ (require-unqualified compiler/macros)
13
+ (require-unqualified std/meta/type-info)
14
+
15
+ (define (define-vector-form [s datum]) -> datum
16
+ (syntax-match s
17
+ [(_ (? identifier? name) t)
18
+ (let ([count (method-name name '-count)] [items (method-name name '-items)] [at (method-name name '-at)]
19
+ [at-unchecked (method-name name '-at-unchecked)] [add (method-name name '-add!)]
20
+ [push (method-name name '-push!)] [pop (method-name name '-pop!)] [clear (method-name name '-clear!)]
21
+ [reserve (method-name name '-reserve!)] [free! (method-name name '-free!)])
22
+ #`(begin
23
+ (struct #,name [items (ptr #,t)] [count u32] [room u32])
24
+ (define (#,count [v (ptr #,name)]) -> u32 (-> v count))
25
+ (define (#,items [v (ptr #,name)]) -> (slice #,t) (slice (-> v items) (-> v count)))
26
+ (define (#,at [v (ptr #,name)] [i u32]) -> (ptr #,t) (& (@ (slice (-> v items) (-> v count)) i)))
27
+ (define (#,at-unchecked [v (ptr #,name)] [i u32]) -> (ptr #,t) (+ (-> v items) i))
28
+ (define (#,reserve [v (ptr #,name)] [n u32])
29
+ (when (> n (-> v room))
30
+ (let ([room u64 (if (== (-> v room) 0) 4 (cast u64 (-> v room)))])
31
+ (while (< room (cast u64 n)) (set! room (* room 2)))
32
+ (let ([bytes (* room (cast u64 (sizeof #,t)))])
33
+ (set! (-> v items)
34
+ (cast (ptr #,t) (realloc (-> v items) (if (< bytes 2147483584) (cast u32 bytes) 2147483584))))
35
+ (set! (-> v room) (cast u32 room))))))
36
+ (define (#,push [v (ptr #,name)] [x #,t])
37
+ (when (== (-> v count) (-> v room)) (#,reserve v (+ (-> v count) 1)))
38
+ (set! (@ (+ (-> v items) (-> v count))) x)
39
+ (+= (-> v count) 1))
40
+ (define (#,add [v (ptr #,name)]) -> (ptr #,t)
41
+ (when (== (-> v count) (-> v room)) (#,reserve v (+ (-> v count) 1)))
42
+ (let ([p (+ (-> v items) (-> v count))])
43
+ (memset p 0 (sizeof #,t))
44
+ (+= (-> v count) 1)
45
+ p))
46
+ (define (#,pop [v (ptr #,name)]) -> #,t
47
+ (when (== (-> v count) 0) (host-trap "vector-pop!: the vector is empty"))
48
+ (-= (-> v count) 1)
49
+ (@ (+ (-> v items) (-> v count))))
50
+ (define (#,clear [v (ptr #,name)]) (set! (-> v count) 0))
51
+ (define (#,free! [v (ptr #,name)])
52
+ (free (-> v items))
53
+ (set! (-> v items) 0)
54
+ (set! (-> v count) 0)
55
+ (set! (-> v room) 0))))]
56
+ [_ (raise-syntax-error 'define-vector "expected (define-vector name type)" s)]))
57
+
58
+ (define (vector-each-form [s datum]) -> datum
59
+ (syntax-match s
60
+ [(_ (((? identifier? x) v)) body0 body ...)
61
+ #`(let ([the-vector #,v])
62
+ (for ([i u32 0]) (< i (vector-count the-vector)) (+= i 1)
63
+ (let ([#,x (vector-at-unchecked the-vector i)]) #,body0 #,@body)))]
64
+ [(_ (((? identifier? x) (? identifier? i) v)) body0 body ...)
65
+ #`(let ([the-vector #,v])
66
+ (for ([#,i u32 0]) (< #,i (vector-count the-vector)) (+= #,i 1)
67
+ (let ([#,x (vector-at-unchecked the-vector #,i)]) #,body0 #,@body)))]
68
+ [_ (raise-syntax-error
69
+ 'vector-each "expected (vector-each ([item vector]) body ...) or (vector-each ([item index vector]) body ...)" s)])))
70
+
71
+ (define-syntax define-vector define-vector-form)
72
+ (define-syntax vector-each vector-each-form)
73
+ (define-methods [vector-count -count] [vector-items -items] [vector-at -at] [vector-at-unchecked -at-unchecked]
74
+ [vector-add! -add!] [vector-push! -push!] [vector-pop! -pop!] [vector-clear! -clear!]
75
+ [vector-reserve! -reserve!] [vector-free! -free!])
package/substrate/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.4
1
+ 0.10.0