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
@@ -3,16 +3,17 @@
3
3
  ;; (dependencies (name (path "directory") (hash "sha256:hex")) (name (url "address") (hash "sha256:hex")) ...)
4
4
  ;; (tests "path" ... (browser))
5
5
  ;; (sites (name "program.sub" (html "file.html") (files "/dir" (from "directory") "path" ...)) ...))
6
- ;; The substrate clause gives the oldest substrate the package builds with. Every clause but version is optional, and so
7
- ;; are a path dependency's hash and a site's html and files. A files part gives the program the files matching its
8
- ;; paths, from its from directory, under the directory it names; * matches any text in a name and ** any directories.
9
- ;; (browser) says that the package's tests open browsers with std/test/browser.sub.
6
+ ;; The substrate clause gives the oldest substrate the package builds with. (substrate "0.10.0") also takes later 0.10
7
+ ;; releases, and (substrate "1.2.0") takes later 1.x releases. Every clause but version is optional, and so are a path
8
+ ;; dependency's hash and a site's html and files. A files part gives the program the files matching its paths, from its
9
+ ;; from directory, under the directory it names; * matches any text in a name and ** any directories. (browser) says
10
+ ;; that the package's tests open browsers with std/test/browser.sub.
10
11
  (require-unqualified "read.sub")
11
12
  (require-unqualified host/fs)
12
13
  (require-unqualified "path.sub")
13
14
 
14
15
  (provide manifest dependency declared-site site-files manifest-read manifest-of-program manifest-find package-holding
15
- package-name? full-hash? version-before?)
16
+ package-name? full-hash? version-before? version-compatible?)
16
17
 
17
18
  (struct dependency [name string] [path string] [url string] [hash string] [line u32] [column u32])
18
19
  (struct site-files [dir string] [from string] [patterns (slice string)])
@@ -24,55 +25,66 @@
24
25
  (define default-tests (array string 1))
25
26
 
26
27
  (define (manifest-read [a (ptr arena)] [file string] [m (ptr manifest)] [err (ptr buffer)]) -> bool
27
- (let ([forms (slice data)] [e data-error])
28
- (cond [(not (read-forms a file #f (& forms) (& e) err)) #f]
29
- [(!= (-> e line) 0) (failed! err file (-> e line) (-> e column) (-> e message))]
30
- [(!= (-> forms length) 1) (failed! err file 1 1 "a package.sub holds one form, (package ...)")]
31
- [else (manifest-of file (& (@ forms 0)) a m err)])))
28
+ (let* ([forms (slice data)] [e data-error]
29
+ [ok (cond [(not (read-forms a file #f (& forms) (& e) err)) #f]
30
+ [(!= (-> e line) 0) (failed! err file (-> e line) (-> e column) (error-text (& (-> e error))))]
31
+ [(!= (-> forms length) 1) (failed! err file 1 1 "a package.sub holds one form, (package ...)")]
32
+ [else (manifest-of file (& (@ forms 0)) a m err)])])
33
+ (error-free! (& (-> e error)))
34
+ ok))
32
35
 
33
- (define (manifest-of-program [a (ptr arena)] [file string] [m (ptr manifest)] [err (ptr buffer)]) -> i32
34
- (let ([text (slice u8)] [why string] [forms (slice data)] [e data-error] [found i32 -1])
35
- (when (< (fs-read-file file (& text) (& why)) 0)
36
+ (define (manifest-of-program [a (ptr arena)] [file string] [m (ptr manifest)] [found (ptr bool)] [err (ptr buffer)])
37
+ -> bool
38
+ (let ([text (slice u8)] [why error] [forms (slice data)] [e data-error] [ok #t])
39
+ (set! (@ found) #f)
40
+ (unless (fs-read-file file (& text) (& why))
36
41
  (buffer-add-string! err "cannot read ")
37
- (buffer-add-string! err why)
38
- (free (-> why bytes))
39
- (return -1))
40
- (cond [(!= (data-head a (cast string text)) "package") (set! found 0)]
41
- [(not (data-read a (cast string text) #t (& forms) (& e))) (failed! err file (-> e line) (-> e column) (-> e message))]
42
- [(manifest-of file (& (@ forms 0)) a m err) (set! found 1)])
42
+ (buffer-add-string! err (error-text (& why)))
43
+ (error-free! (& why))
44
+ (return #f))
45
+ (cond [(!= (data-head a (cast string text)) "package") (begin)]
46
+ [(not (data-read a (cast string text) #t (& forms) (& e)))
47
+ (set! ok (failed! err file (-> e line) (-> e column) (error-text (& (-> e error)))))]
48
+ [(manifest-of file (& (@ forms 0)) a m err) (set! (@ found) #t)]
49
+ [else (set! ok #f)])
50
+ (error-free! (& (-> e error)))
43
51
  (free (-> text items))
44
- found))
52
+ ok))
45
53
 
46
- ;; manifest-find finds the manifest of the package that holds the program in file, given from /: the program's own,
47
- ;; giving 1, or the nearest package.sub above it, giving 2, with the package's directory added to dir. It gives 0 when
48
- ;; there is none, and -1 with err saying why when the manifest is wrong.
49
- (define (manifest-find [a (ptr arena)] [file string] [m (ptr manifest)] [dir (ptr buffer)] [err (ptr buffer)]) -> i32
50
- (let ([own (manifest-of-program a file m err)] [d string] [found i32 0])
51
- (when (!= own 0) (return own))
54
+ ;; manifest-find finds the manifest for the program in file, given from /. found is 1 for the program's own manifest,
55
+ ;; 2 for the nearest package.sub above it, whose directory goes into dir, and 0 when there is none.
56
+ (define (manifest-find [a (ptr arena)] [file string] [m (ptr manifest)] [dir (ptr buffer)] [found (ptr i32)]
57
+ [err (ptr buffer)]) -> bool
58
+ (let ([own #f] [d string])
59
+ (set! (@ found) 0)
60
+ (unless (manifest-of-program a file m (& own) err) (return #f))
61
+ (when own
62
+ (set! (@ found) 1)
63
+ (return #t))
52
64
  (set! d (package-holding a (parent-of file)))
53
65
  (when (> (-> d length) 0)
54
- (set! found (if (manifest-read a (joined-path d "package.sub") m err) 2 -1))
55
- (when (== found 2) (buffer-add-string! dir d)))
56
- found))
66
+ (unless (manifest-read a (joined-path d "package.sub") m err) (return #f))
67
+ (set! (@ found) 2)
68
+ (buffer-add-string! dir d))
69
+ #t))
57
70
 
58
71
  (define (package-holding [a (ptr arena)] [dir string]) -> string
59
72
  (let ([d dir] [info fs-info] [found ""])
60
73
  (while (> (-> d length) 0)
61
- (when (and (== (fs-stat (joined-path d "package.sub") (& info) 0) 0) (== (-> info kind) fs-file))
62
- (set! found (cast string (slice (cast (ptr u8) (arena-alloc a (-> d length))) (-> d length))))
63
- (memcpy (-> found bytes) (-> d bytes) (-> d length))
74
+ (when (and (fs-stat (joined-path d "package.sub") (& info) 0) (== (-> info kind) fs-file))
75
+ (set! found (copy a d))
64
76
  (break))
65
77
  (set! d (if (root-path? d) "" (parent-of d))))
66
78
  found))
67
79
 
68
80
  (define (read-forms [a (ptr arena)] [file string] [first bool] [into (ptr (slice data))] [e (ptr data-error)]
69
81
  [err (ptr buffer)]) -> bool
70
- (let ([text (slice u8)] [why string])
82
+ (let ([text (slice u8)] [why error])
71
83
  (set! (-> e line) 0)
72
- (when (< (fs-read-file file (& text) (& why)) 0)
84
+ (unless (fs-read-file file (& text) (& why))
73
85
  (buffer-add-string! err "cannot read ")
74
- (buffer-add-string! err why)
75
- (free (-> why bytes))
86
+ (buffer-add-string! err (error-text (& why)))
87
+ (error-free! (& why))
76
88
  (return #f))
77
89
  (unless (data-read a (cast string text) first into e)
78
90
  (when (== (-> e line) 0) (set! (-> e line) 1)))
@@ -133,17 +145,29 @@
133
145
 
134
146
  ;; version-before? is whether version a comes before version b, both major.minor.patch. No version comes before "".
135
147
  (define (version-before? [a string] [b string]) -> bool
136
- (let ([i u32 0] [j u32 0] [x i64 0] [y i64 0])
148
+ (let ([i u32 0] [j u32 0])
137
149
  (for ([k u32 0]) (< k 3) (+= k 1)
138
- (set! x 0)
139
- (set! y 0)
140
- (while (and (< i (-> a length)) (!= (@ a i) #\.)) (set! x (+ (* x 10) (cast i64 (- (@ a i) #\0)))) (+= i 1))
141
- (while (and (< j (-> b length)) (!= (@ b j) #\.)) (set! y (+ (* y 10) (cast i64 (- (@ b j) #\0)))) (+= j 1))
142
- (+= i 1)
143
- (+= j 1)
144
- (when (!= x y) (return (< x y))))
150
+ (let ([x (version-part a (& i))] [y (version-part b (& j))])
151
+ (when (!= x y) (return (< x y)))))
145
152
  #f))
146
153
 
154
+ (define (version-compatible? [a string] [b string]) -> bool
155
+ (let ([i u32 0] [j u32 0])
156
+ (when (== (-> b length) 0) (return #t))
157
+ (for ([k u32 0]) (< k 2) (+= k 1)
158
+ (let ([x (version-part a (& i))] [y (version-part b (& j))])
159
+ (when (!= x y) (return #f))
160
+ (when (!= y 0) (break))))
161
+ (not (version-before? a b))))
162
+
163
+ (define (version-part [s string] [at (ptr u32)]) -> i64
164
+ (let ([n i64 0])
165
+ (while (and (< (@ at) (-> s length)) (!= (@ s (@ at)) #\.))
166
+ (set! n (+ (* n 10) (cast i64 (- (@ s (@ at)) #\0))))
167
+ (+= (@ at) 1))
168
+ (+= (@ at) 1)
169
+ n))
170
+
147
171
  (define (manifest-of [file string] [f (ptr data)] [a (ptr arena)] [m (ptr manifest)] [err (ptr buffer)]) -> bool
148
172
  (let ([items (items-of f)] [versioned #f] [needed #f] [exported #f] [listed #f] [tested #f] [sited #f] [major i64 0])
149
173
  (set! (-> m substrate) "")
@@ -190,7 +214,7 @@
190
214
  (if versioned #t (failed-at! err file f "the package has no (version \"major.minor.patch\")"))))
191
215
 
192
216
  (define (exports-of [file string] [c (ptr data)] [a (ptr arena)] [m (ptr manifest)] [err (ptr buffer)]) -> bool
193
- (let* ([items (items-of c)] [n (- (-> items length) 1)] [es (cast (ptr string) (arena-alloc a (* n (sizeof string))))])
217
+ (let* ([items (items-of c)] [n (- (-> items length) 1)] [es (new a string n)])
194
218
  (for ([i u32 0]) (< i n) (+= i 1)
195
219
  (let ([d (& (@ items (+ i 1)))])
196
220
  (set! (@ es i) (symbol-of d))
@@ -198,11 +222,11 @@
198
222
  (return (failed-at! err file d "an export is the name of a module in the package, as text or lib/value")))
199
223
  (for ([k u32 0]) (< k i) (+= k 1)
200
224
  (when (== (@ es k) (@ es i)) (return (failed-at! err file d "this export is given twice"))))))
201
- (set! (-> m exports) (slice es n))
225
+ (set! (-> m exports) es)
202
226
  #t))
203
227
 
204
228
  (define (tests-of [file string] [c (ptr data)] [a (ptr arena)] [m (ptr manifest)] [err (ptr buffer)]) -> bool
205
- (let* ([items (items-of c)] [n u32 0] [ts (cast (ptr string) (arena-alloc a (* (-> items length) (sizeof string))))])
229
+ (let* ([items (items-of c)] [n u32 0] [ts (new a string (-> items length))])
206
230
  (for ([i u32 1]) (< i (-> items length)) (+= i 1)
207
231
  (let ([d (& (@ items i))])
208
232
  (cond [(and (list-of? d "browser" 1) (not (-> m test-browser))) (set! (-> m test-browser) #t)]
@@ -210,15 +234,15 @@
210
234
  [else
211
235
  (return (failed-at! err file d
212
236
  "a test module is a path in the package, with * for any text, as \"tests/*.sub\", and (browser) comes at most once"))])))
213
- (when (> n 0) (set! (-> m tests) (slice ts n)))
237
+ (when (> n 0) (set! (-> m tests) (slice ts 0 n)))
214
238
  #t))
215
239
 
216
240
  (define (sites-of [file string] [c (ptr data)] [a (ptr arena)] [m (ptr manifest)] [err (ptr buffer)]) -> bool
217
241
  (let* ([items (items-of c)] [n (- (-> items length) 1)]
218
- [ss (cast (ptr declared-site) (arena-alloc a (* n (sizeof declared-site))))])
242
+ [ss (new a declared-site n)])
219
243
  (for ([i u32 0]) (< i n) (+= i 1)
220
- (let* ([d (& (@ items (+ i 1)))] [parts (items-of d)] [s (& (@ ss i))]
221
- [groups (cast (ptr site-files) (arena-alloc a (* (-> parts length) (sizeof site-files))))] [g u32 0])
244
+ (let* ([d (& (@ items (+ i 1)))] [parts (items-of d)] [s (& (@ ss i))] [groups (new a site-files (-> parts length))]
245
+ [g u32 0])
222
246
  (set! (-> s html) "")
223
247
  (match d [(data-list p line column) (set! (-> s line) line) (set! (-> s column) column)] [_ (begin)])
224
248
  (unless (and (>= (-> parts length) 2) (package-name? (symbol-of (& (@ parts 0))))
@@ -236,12 +260,12 @@
236
260
  (unless (files-of file p a (& (@ groups g)) err) (return #f))
237
261
  (+= g 1)]
238
262
  [else (return (failed-at! err file p site-form))])))
239
- (set! (-> s files) (slice groups g))))
240
- (set! (-> m sites) (slice ss n))
263
+ (set! (-> s files) (slice groups 0 g))))
264
+ (set! (-> m sites) ss)
241
265
  #t))
242
266
 
243
267
  (define (files-of [file string] [c (ptr data)] [a (ptr arena)] [f (ptr site-files)] [err (ptr buffer)]) -> bool
244
- (let* ([items (items-of c)] [k u32 2] [n u32 0] [ps (cast (ptr string) (arena-alloc a (* (-> items length) (sizeof string))))])
268
+ (let* ([items (items-of c)] [k u32 2] [n u32 0] [ps (new a string (-> items length))])
245
269
  (set! (-> f from) "")
246
270
  (unless (and (>= (-> items length) 3) (string-of (& (@ items 1)) (& (-> f dir))) (starts? (-> f dir) "/"))
247
271
  (return (failed-at! err file c files-form)))
@@ -253,7 +277,7 @@
253
277
  (return (failed-at! err file (& (@ items i)) files-form)))
254
278
  (+= n 1))
255
279
  (when (== n 0) (return (failed-at! err file c files-form)))
256
- (set! (-> f patterns) (slice ps n))
280
+ (set! (-> f patterns) (slice ps 0 n))
257
281
  #t))
258
282
 
259
283
  (define site-form string
@@ -272,7 +296,7 @@
272
296
 
273
297
  (define (dependencies-of [file string] [c (ptr data)] [a (ptr arena)] [m (ptr manifest)] [err (ptr buffer)]) -> bool
274
298
  (let* ([items (items-of c)] [n (- (-> items length) 1)]
275
- [ds (cast (ptr dependency) (arena-alloc a (* n (sizeof dependency))))])
299
+ [ds (new a dependency n)])
276
300
  (for ([i u32 0]) (< i n) (+= i 1)
277
301
  (let* ([d (& (@ items (+ i 1)))] [parts (items-of d)] [dep (& (@ ds i))])
278
302
  (set! (-> dep path) "")
@@ -302,7 +326,7 @@
302
326
  (return (failed-at! err file d "a dependency's url starts with http:// or https://")))
303
327
  (when (and (> (-> dep url length) 0) (not (full-hash? (-> dep hash))))
304
328
  (return (failed-at! err file d "a url's hash is sha256: and 64 hex digits, as substrate hash prints it")))))
305
- (set! (-> m dependencies) (slice ds n))
329
+ (set! (-> m dependencies) ds)
306
330
  #t))
307
331
 
308
332
  (define dependency-form string
@@ -58,15 +58,12 @@
58
58
  (define (visit! [a (ptr arena)] [dir string] [file string] [m (ptr manifest)] [store string] [g (ptr graph)]
59
59
  [err (ptr buffer)]) -> (ptr reached)
60
60
  (let* ([deps (-> m dependencies)] [n (-> deps length)]
61
- [dirs (cast (ptr string) (arena-alloc a (* n (sizeof string))))]
62
- [ms (cast (ptr manifest) (arena-alloc a (* n (sizeof manifest))))]
63
- [me (cast (ptr reached) (arena-alloc a (sizeof reached)))] [other (ptr reached) 0])
61
+ [dirs (new a string n)] [ms (new a manifest n)] [me (new a reached)] [other (ptr reached) 0])
64
62
  (set! (-> me m) m)
65
63
  (set! (-> me r dir) dir)
66
64
  (set! (-> me r file) file)
67
65
  (set! (-> me r substrate) (-> m substrate))
68
- (set! (-> me r exports) (slice (cast (ptr string) 0) 0))
69
- (set! (-> me deps) (cast (ptr (ptr reached)) (arena-alloc a (* n (sizeof (ptr reached))))))
66
+ (set! (-> me deps) (-> (new a (ptr reached) n) items))
70
67
  (set! (-> me hash) "")
71
68
  (set! (-> me open) #t)
72
69
  (set! (-> me next) 0)
@@ -81,7 +78,7 @@
81
78
  (set! (@ dirs i) (normal-path a full))
82
79
  (free (-> full bytes))))
83
80
  (when (and (> (-> d url length) 0)
84
- (or (!= (fs-stat (@ dirs i) (& info) 0) 0) (!= (-> info kind) fs-directory)))
81
+ (or (not (fs-stat (@ dirs i) (& info) 0)) (!= (-> info kind) fs-directory)))
85
82
  (buffer-add-string! err (-> d name))
86
83
  (buffer-add-string! err ", from ")
87
84
  (buffer-add-string! err (-> d url))
@@ -207,13 +204,12 @@
207
204
  ok))
208
205
 
209
206
  (define (under [a (ptr arena)] [dir string] [b (ptr buffer)]) -> (slice string)
210
- (let* ([n (/ (-> b length) (sizeof string))] [ps (cast (ptr string) (-> b bytes))]
211
- [out (cast (ptr string) (arena-alloc a (* n (sizeof string))))])
207
+ (let* ([n (/ (-> b length) (sizeof string))] [ps (cast (ptr string) (-> b bytes))] [out (new a string n)])
212
208
  (for ([i u32 0]) (< i n) (+= i 1)
213
209
  (let ([full (joined-path dir (@ ps i))])
214
210
  (set! (@ out i) (normal-path a full))
215
211
  (free (-> full bytes))))
216
- (slice out n)))
212
+ out))
217
213
 
218
214
  (define (rules! [b (ptr buffer)] [r (ptr package-root)])
219
215
  (if (> (-> r file length) 0)
@@ -23,9 +23,9 @@
23
23
  (let ([pack (make-buffer)] [ok #t] [fs (cast (ptr packed-file) (-> files bytes))]
24
24
  [n (/ (-> files length) (sizeof packed-file))])
25
25
  (for ([k u32 0]) (and ok (< k n)) (+= k 1)
26
- (let ([name (-> (@ fs k) name)] [why string] [bytes (slice u8)])
27
- (if (< (fs-read-file (-> (@ fs k) path) (& bytes) (& why)) 0)
28
- (set! ok (failed! err "cannot read " why))
26
+ (let ([name (-> (@ fs k) name)] [why error] [bytes (slice u8)])
27
+ (if (not (fs-read-file (-> (@ fs k) path) (& bytes) (& why)))
28
+ (set! ok (failed! err "cannot read " (& why)))
29
29
  (begin
30
30
  (buffer-add-u32! (& pack) (-> name length))
31
31
  (buffer-add-string! (& pack) name)
@@ -33,8 +33,8 @@
33
33
  (buffer-add! (& pack) bytes)
34
34
  (free (-> bytes items))))))
35
35
  (when ok
36
- (let ([why string])
37
- (when (< (fs-write-file out (buffer-bytes (& pack)) (& why)) 0) (set! ok (failed! err "cannot write " why)))))
36
+ (let ([why error])
37
+ (unless (fs-write-file out (buffer-bytes (& pack)) (& why)) (set! ok (failed! err "cannot write " (& why))))))
38
38
  (for ([k u32 0]) (< k n) (+= k 1)
39
39
  (free (-> (-> (@ fs k) name) bytes))
40
40
  (free (-> (-> (@ fs k) path) bytes)))
@@ -50,22 +50,22 @@
50
50
  (buffer-add-string! (& b) name)
51
51
  (buffer-string (& b))))
52
52
 
53
- (define (failed! [err (ptr buffer)] [what string] [why string]) -> bool
53
+ (define (failed! [err (ptr buffer)] [what string] [why (ptr error)]) -> bool
54
54
  (buffer-add-string! err what)
55
- (buffer-add-string! err why)
56
- (free (-> why bytes))
55
+ (buffer-add-string! err (error-text why))
56
+ (error-free! why)
57
57
  #f)
58
58
 
59
59
  (define (add! [dir string] [name string] [at string] [files (ptr buffer)] [err (ptr buffer)]) -> bool
60
- (let* ([full (joined dir name)] [why string] [info fs-info] [ok #t])
61
- (cond [(< (fs-stat full (& info) (& why)) 0)
62
- (set! ok (failed! err "cannot read " why))
60
+ (let* ([full (joined dir name)] [why error] [info fs-info] [ok #t])
61
+ (cond [(not (fs-stat full (& info) (& why)))
62
+ (set! ok (failed! err "cannot read " (& why)))
63
63
  (free (-> name bytes))
64
64
  (free (-> full bytes))]
65
65
  [(== (-> info kind) fs-directory)
66
66
  (let ([listed (slice string)])
67
- (if (< (fs-list full (& listed) (& why)) 0)
68
- (set! ok (failed! err "cannot read " why))
67
+ (if (not (fs-list full (& listed) (& why)))
68
+ (set! ok (failed! err "cannot read " (& why)))
69
69
  (begin
70
70
  (for ([j u32 0]) (and ok (< j (-> listed length))) (+= j 1)
71
71
  (set! ok (add! dir (joined name (@ listed j)) at files err)))
@@ -21,10 +21,7 @@
21
21
 
22
22
  (define (root-path? [p string]) -> bool (path-same? (path-windows?) (path-parent (path-windows?) p) p))
23
23
 
24
- (define (kept [a (ptr arena)] [s string]) -> string
25
- (let ([out (cast string (slice (cast (ptr u8) (arena-alloc a (-> s length))) (-> s length)))])
26
- (memcpy (-> out bytes) (-> s bytes) (-> s length))
27
- out))
24
+ (define (kept [a (ptr arena)] [s string]) -> string (copy a s))
28
25
 
29
26
  (define (within? [p string] [dir string]) -> bool (path-within? (path-windows?) p dir))
30
27
 
@@ -7,7 +7,7 @@
7
7
  [data-symbol [text string] [line u32] [column u32]]
8
8
  [data-string [text string] [line u32] [column u32]])
9
9
 
10
- (struct data-error [message string] [line u32] [column u32])
10
+ (struct data-error [error error] [line u32] [column u32])
11
11
 
12
12
  (struct data-reader [text string] [at u32] [line u32] [column u32] [arena (ptr arena)] [error (ptr data-error)])
13
13
 
@@ -34,13 +34,13 @@
34
34
  #t))
35
35
 
36
36
  (define (data-head [a (ptr arena)] [text string]) -> string
37
- (let ([r data-reader] [e data-error] [start u32 0])
37
+ (let ([r data-reader] [start u32 0])
38
38
  (set! (-> r text) text)
39
39
  (set! (-> r at) 0)
40
40
  (set! (-> r line) 1)
41
41
  (set! (-> r column) 1)
42
42
  (set! (-> r arena) a)
43
- (set! (-> r error) (& e))
43
+ (set! (-> r error) 0)
44
44
  (unless (and (skip-space! (& r)) (more? (& r)) (or (== (here (& r)) #\() (== (here (& r)) #\[))) (return ""))
45
45
  (advance! (& r))
46
46
  (unless (skip-space! (& r)) (return ""))
@@ -48,10 +48,7 @@
48
48
  (while (and (more? (& r)) (not (delimiter? (here (& r))))) (advance! (& r)))
49
49
  (slice text start (-> r at))))
50
50
 
51
- (define (copied [a (ptr arena)] [b (slice u8)]) -> (ptr u8)
52
- (let ([p (cast (ptr u8) (arena-alloc a (-> b length)))])
53
- (memcpy p (-> b items) (-> b length))
54
- p))
51
+ (define (copied [a (ptr arena)] [b (slice u8)]) -> (ptr u8) (-> (copy a b) items))
55
52
 
56
53
  (define (here [r (ptr data-reader)]) -> u32 (@ (-> r text) (-> r at)))
57
54
 
@@ -96,9 +93,10 @@
96
93
  (or (== c 32) (and (>= c 9) (<= c 13)) (== c #\() (== c #\)) (== c #\[) (== c #\]) (== c #\") (== c 59)))
97
94
 
98
95
  (define (failed! [r (ptr data-reader)] [message string] [line u32] [column u32]) -> bool
99
- (set! (-> r error message) message)
100
- (set! (-> r error line) line)
101
- (set! (-> r error column) column)
96
+ (unless (== (-> r error) 0)
97
+ (error-fail! (& (-> r error error)) error-invalid message)
98
+ (set! (-> r error line) line)
99
+ (set! (-> r error column) column))
102
100
  #f)
103
101
 
104
102
  (define (read-one! [r (ptr data-reader)] [into (ptr data)]) -> bool
@@ -110,9 +108,7 @@
110
108
  [else
111
109
  (let ([start (-> r at)])
112
110
  (while (and (more? r) (not (delimiter? (here r)))) (advance! r))
113
- (set! (@ into) (data-symbol (cast string (slice (copied (-> r arena) (cast (slice u8) (slice (-> r text) start (-> r at))))
114
- (- (-> r at) start)))
115
- line column))
111
+ (set! (@ into) (data-symbol (copy (-> r arena) (slice (-> r text) start (-> r at))) line column))
116
112
  #t)])))
117
113
 
118
114
  (define (read-list! [r (ptr data-reader)] [close u32] [line u32] [column u32] [into (ptr data)]) -> bool
@@ -162,7 +158,7 @@
162
158
  (return (failed! r "a string's escapes are \\\", \\\\, \\n, \\t, \\r, \\0, and \\x with hex digits and ;" l k))])
163
159
  (advance! r))]
164
160
  [else (buffer-add-byte! (& b) (cast i32 c)) (advance! r)]))
165
- (set! (@ into) (data-string (cast string (slice (copied (-> r arena) (buffer-bytes (& b))) (-> b length))) line column))
161
+ (set! (@ into) (data-string (cast string (copy (-> r arena) (buffer-bytes (& b)))) line column))
166
162
  (buffer-free! (& b))
167
163
  #t))
168
164
 
@@ -19,22 +19,22 @@
19
19
  (buffer-add-string! (& out) b)
20
20
  (buffer-string (& out))))
21
21
 
22
- (define (kind-of [path string]) -> i32
23
- (let ([info fs-info]) (if (< (fs-stat path (& info) 0) 0) 0 (-> info kind))))
22
+ (define (kind-of [path string]) -> fs-kind
23
+ (let ([info fs-info]) (fs-stat path (& info) 0) (-> info kind)))
24
24
 
25
25
  (define (made! [path string])
26
- (let ([why string]) (when (< (fs-make-dir path (& why)) 0) (throw site-failed why))))
26
+ (let ([why error]) (unless (fs-make-dir path (& why)) (throw site-failed (error-text (& why))))))
27
27
 
28
28
  (define (copied! [from string] [to string])
29
- (let ([why string]) (when (< (fs-copy from to (& why)) 0) (throw site-failed why))))
29
+ (let ([why error]) (unless (fs-copy from to (& why)) (throw site-failed (error-text (& why))))))
30
30
 
31
31
  (define (names-in [dir string]) -> (slice string)
32
- (let ([names (slice string)] [why string])
33
- (when (< (fs-list dir (& names) (& why)) 0) (throw site-failed why))
32
+ (let ([names (slice string)] [why error])
33
+ (unless (fs-list dir (& names) (& why)) (throw site-failed (error-text (& why))))
34
34
  names))
35
35
 
36
36
  (define (written! [path string] [b (slice u8)])
37
- (let ([why string]) (when (< (fs-write-file path b (& why)) 0) (throw site-failed why))))
37
+ (let ([why error]) (unless (fs-write-file path b (& why)) (throw site-failed (error-text (& why))))))
38
38
 
39
39
  (define (copy-tree! [from string] [to string] [base string] [files (ptr buffer)])
40
40
  (let ([names (names-in from)])
@@ -84,7 +84,7 @@
84
84
  ;; Collects the paths under base that match parts k onward; rel is the part of the path matched so far.
85
85
  (define (matched! [base string] [rel string] [parts (slice string)] [k u32] [into (ptr buffer)])
86
86
  (let ([here (if (== (-> rel length) 0) base (joined-path base rel))])
87
- (cond [(== k (-> parts length)) (when (!= (kind-of here) 0) (kept! into rel))]
87
+ (cond [(== k (-> parts length)) (when (!= (kind-of here) fs-none) (kept! into rel))]
88
88
  [(== (@ parts k) "**")
89
89
  (matched! base rel parts (+ k 1) into)
90
90
  (when (== (kind-of here) fs-directory)
@@ -131,12 +131,12 @@
131
131
  #f]))
132
132
 
133
133
  (define (site-written! [p (ptr site-plan)] [out string] [toolchain string])
134
- (let ([list (make-buffer)] [files (make-buffer)] [packed (make-buffer)] [err (make-buffer)] [why string])
135
- (when (and (!= (kind-of out) 0)
134
+ (let ([list (make-buffer)] [files (make-buffer)] [packed (make-buffer)] [err (make-buffer)] [why error])
135
+ (when (and (!= (kind-of out) fs-none)
136
136
  (or (!= (kind-of out) fs-directory)
137
137
  (and (> (-> (names-in out) length) 0) (!= (kind-of (joined-path out ".site")) fs-file))))
138
138
  (throw site-failed (joined (joined "site: " out) " is not a site, so it is not replaced")))
139
- (when (and (!= (kind-of out) 0) (< (fs-remove out #t (& why)) 0)) (throw site-failed why))
139
+ (when (and (!= (kind-of out) fs-none) (not (fs-remove out #t (& why)))) (throw site-failed (error-text (& why))))
140
140
  (made! (joined-path out "host/modules"))
141
141
  (made! (joined-path out "host/web"))
142
142
  (written! (joined-path out ".site") (cast (slice u8) (joined (-> p program) "\n")))
@@ -24,7 +24,7 @@
24
24
  (let* ([d (& (@ deps i))] [url (> (-> d url length) 0)] [dm manifest] [err (make-buffer)] [info fs-info]
25
25
  [next (if url (store-entry a store (-> d hash)) (dependency-dir a dir (-> d path)))]
26
26
  [file (joined-path next "package.sub")])
27
- (if (and url (or (!= (fs-stat next (& info) 0) 0) (!= (-> info kind) fs-directory)))
27
+ (if (and url (or (not (fs-stat next (& info) 0)) (!= (-> info kind) fs-directory)))
28
28
  (let ([w wanted])
29
29
  (set! (-> w name) (-> d name))
30
30
  (set! (-> w url) (-> d url))
@@ -45,8 +45,8 @@
45
45
  (define (store-install! [a (ptr arena)] [store string] [staging string] [pin string] [m (ptr manifest)]
46
46
  [into (ptr buffer)] [err (ptr buffer)]) -> bool
47
47
  (let ([file (joined-path staging "package.sub")] [info fs-info] [h (make-buffer)] [hash string] [entry string]
48
- [kept string] [why string])
49
- (unless (and (== (fs-stat file (& info) 0) 0) (== (-> info kind) fs-file))
48
+ [kept string] [why error])
49
+ (unless (and (fs-stat file (& info) 0) (== (-> info kind) fs-file))
50
50
  (return (not-installed! staging err "it has no package.sub at its top")))
51
51
  (unless (manifest-read a file m err) (return (not-installed! staging err "")))
52
52
  (let ([deps (-> m dependencies)])
@@ -64,18 +64,21 @@
64
64
  (buffer-add-string! err ", not the one its dependency pins, ")
65
65
  (return (not-installed! staging err pin)))
66
66
  (set! entry (store-entry a store hash))
67
- (when (< (fs-make-temp-dir store ".staging-" "" (& kept) (& why)) 0)
68
- (buffer-add-string! err why)
67
+ (unless (fs-make-temp-dir store ".staging-" "" (& kept) (& why))
68
+ (buffer-add-string! err (error-text (& why)))
69
+ (error-free! (& why))
69
70
  (return (not-installed! staging err "")))
70
71
  (unless (copied! a staging staging kept err)
71
72
  (fs-remove kept #t 0)
72
73
  (return (not-installed! staging err "")))
73
74
  (fs-remove staging #t 0)
74
- (when (< (fs-rename kept entry (& why)) 0)
75
+ (unless (fs-rename kept entry (& why))
75
76
  (fs-remove kept #t 0)
76
- (unless (and (== (fs-stat entry (& info) 0) 0) (== (-> info kind) fs-directory))
77
- (buffer-add-string! err why)
78
- (return #f)))
77
+ (unless (and (fs-stat entry (& info) 0) (== (-> info kind) fs-directory))
78
+ (buffer-add-string! err (error-text (& why)))
79
+ (error-free! (& why))
80
+ (return #f))
81
+ (error-free! (& why)))
79
82
  (buffer-add-string! into hash)
80
83
  #t))
81
84
 
@@ -95,9 +98,10 @@
95
98
  ok))
96
99
 
97
100
  (define (copied-file! [top string] [dir string] [p string] [to string] [err (ptr buffer)]) -> bool
98
- (let* ([from (joined-path dir p)] [dest (joined-path to (slice from (+ (-> top length) 1)))] [why string] [ok #t])
99
- (when (or (< (fs-make-dir (parent-of dest) (& why)) 0) (< (fs-copy from dest (& why)) 0))
100
- (buffer-add-string! err why)
101
+ (let* ([from (joined-path dir p)] [dest (joined-path to (slice from (+ (-> top length) 1)))] [why error] [ok #t])
102
+ (unless (and (fs-make-dir (parent-of dest) (& why)) (fs-copy from dest (& why)))
103
+ (buffer-add-string! err (error-text (& why)))
104
+ (error-free! (& why))
101
105
  (set! ok #f))
102
106
  (free (-> from bytes))
103
107
  (free (-> dest bytes))
package/std/package.sub CHANGED
@@ -1,13 +1,13 @@
1
1
  (package std
2
- (version "0.9.0")
3
- (substrate "0.9.0")
2
+ (version "0.10.0")
3
+ (substrate "0.10.0")
4
4
  (exports archive/tar browser/chromium browser/devtools compress/deflate compress/gzip compress/inflate crypto/hmac
5
5
  crypto/password crypto/sha1
6
6
  crypto/sha256 crypto/sha512 doc/doc doc/html doc/root doc/text encoding/base64 encoding/json encoding/utf8
7
7
  encoding/wire html/html http/checks http/conditional http/cookie http/form http/http http/multipart
8
8
  http/route http/server http/session http/sse http/sse-client http/static http/test http/token http/url
9
- http/websocket log/log meta/derive meta/equal meta/type-info package/files package/hash package/manifest
10
- package/map package/pack package/path package/read package/site package/store test/browser test/build
11
- test/run test/session test/test web/canvas web/dom web/gpu web/patches)
9
+ http/websocket log/log meta/derive meta/equal meta/method meta/type-info package/files package/hash
10
+ package/manifest package/map package/pack package/path package/read package/site package/store test/browser
11
+ test/build test/run test/session test/test vector/vector web/canvas web/dom web/gpu web/patches)
12
12
  (tests "tests/archive/*.sub" "tests/compress/*.sub" "tests/crypto/*.sub" "tests/encoding/*.sub" "tests/http/*.sub"
13
- "tests/log/*.sub" "tests/meta/*.sub" "tests/test/*.sub"))
13
+ "tests/log/*.sub" "tests/meta/*.sub" "tests/test/*.sub" "tests/vector/*.sub"))
@@ -111,8 +111,9 @@
111
111
  (unless (env-get "SUBSTRATE_DEVTOOLS" (& address) 0)
112
112
  (throw test-failed (lines-joined message "a test that opens a browser needs (browser) in the tests clause of its package's package.sub")))
113
113
  (when (== (-> address length) 0) (throw test-skipped "need Chromium"))
114
- (let* ([dir (site-built spec html message)] [why string] [p (page-open dir (with-args url args) address server (& why))])
115
- (when (== (cast u32 p) 0) (throw test-failed (lines-joined message why)))
114
+ (let ([dir (site-built spec html message)] [why error] [p (ptr page) 0])
115
+ (unless (page-open dir (with-args url args) address server (& p) (& why))
116
+ (throw test-failed (lines-joined message (error-text (& why)))))
116
117
  (browser #:page p))))
117
118
 
118
119
  ;; Adds args to url as arg parameters, which a site passes to its program as its arguments.
@@ -143,7 +144,7 @@
143
144
  (when (> (-> html length) 0) (set! (-> p html) html))
144
145
  (unless (site-write! (& p) dir (toolchain) (& err))
145
146
  (throw test-failed (lines-joined message (buffer-string (& err)))))
146
- (unless (and (== (fs-stat (-> p program) (& info) 0) 0) (== (-> info kind) fs-directory))
147
+ (unless (and (fs-stat (-> p program) (& info) 0) (== (-> info kind) fs-directory))
147
148
  (unless (program-write! (-> p program) (joined-path dir "program") (& err))
148
149
  (throw test-failed (lines-joined message (buffer-string (& err)))))))
149
150
  (set! b (built #:spec spec #:html html #:dir dir))
@@ -152,8 +153,8 @@
152
153
 
153
154
  ;; spec is the name of a site the package declares, or else the path of a program.
154
155
  (define (planned [spec string] [name string] [message string]) -> site-plan
155
- (let ([p site-plan] [a (make-arena)] [here string] [why string] [err (make-buffer)])
156
- (when (< (fs-cwd (& here) (& why)) 0) (throw test-failed (lines-joined message why)))
156
+ (let ([p site-plan] [a (make-arena)] [here string] [why error] [err (make-buffer)])
157
+ (unless (fs-cwd (& here) (& why)) (throw test-failed (lines-joined message (error-text (& why)))))
157
158
  (if (site-named? spec)
158
159
  (unless (site-declared (& a) here spec (& p) (& err)) (throw test-failed (lines-joined message (buffer-string (& err)))))
159
160
  (set! p (site-plan #:name name #:program (resolved-path here spec) #:html ""
@@ -173,12 +174,12 @@
173
174
 
174
175
  ;; Saves a PNG of the browser's window as build/test/screenshots/name.png in the package, and gives that path.
175
176
  (define (browser-screenshot [b browser] [name string]) -> string
176
- (let* ([dir "build/test/screenshots"] [file (make-buffer)] [why string] [png (page-screenshot (-> b page))])
177
+ (let* ([dir "build/test/screenshots"] [file (make-buffer)] [why error] [png (page-screenshot (-> b page))])
177
178
  (buffer-add-string! (& file) name)
178
179
  (buffer-add-string! (& file) ".png")
179
180
  (let ([path (joined-path dir (buffer-string (& file)))])
180
- (when (or (< (fs-make-dir dir (& why)) 0) (< (fs-write-file path png (& why)) 0))
181
- (throw test-failed (page-stepped why)))
181
+ (unless (and (fs-make-dir dir (& why)) (fs-write-file path png (& why)))
182
+ (throw test-failed (page-stepped (error-text (& why)))))
182
183
  path)))
183
184
 
184
185
  (define (lines-joined [a string] [b string]) -> string
@@ -17,8 +17,8 @@
17
17
  (define (ready!)
18
18
  (unless ready
19
19
  (set! ready #t)
20
- (let ([why string] [toolchain string] [map-file string] [cache string])
21
- (when (< (fs-cwd (& directory) (& why)) 0) (throw test-failed why))
20
+ (let ([why error] [toolchain string] [map-file string] [cache string])
21
+ (unless (fs-cwd (& directory) (& why)) (throw test-failed (error-text (& why))))
22
22
  (env-get "SUBSTRATE_TOOLCHAIN" (& toolchain) 0)
23
23
  (env-get "SUBSTRATE_MODULE_MAP" (& map-file) 0)
24
24
  (env-get "SUBSTRATE_CACHE" (& cache) 0)