substrate-lang 0.9.2 → 0.9.4
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.
- package/build/compiler/binary.cdd2ffb408dd@0+0.wasm +0 -0
- package/build/compiler/checker.2b0ea87ed311@0+0.wasm +0 -0
- package/build/compiler/compile.da85f9bc4478@0+0.wasm +0 -0
- package/build/compiler/{core.11abd90bead5@0+0.wasm → core.0410ffbdc488@0+0.wasm} +0 -0
- package/build/compiler/expander.80707e1666d6@0+0.wasm +0 -0
- package/build/compiler/{fs.3f7cf768e7ed@0+0.wasm → fs.5017b627cbd2@0+0.wasm} +0 -0
- package/build/compiler/{leb128.0d2a247f239f@0+0.wasm → leb128.ba77430f659f@0+0.wasm} +0 -0
- package/build/compiler/{link.3c4158bb6ba3@0+0.wasm → link.be6e641afa93@0+0.wasm} +0 -0
- package/build/compiler/{macros.6f0e1a78d640@0+0.wasm → macros.b695763c0ca3@0+0.wasm} +0 -0
- package/build/compiler/main.cbbdf42e34c2@0+0.wasm +0 -0
- package/build/compiler/{ops.a5b9269c5240@0+0.wasm → ops.324f0a665fab@0+0.wasm} +0 -0
- package/build/compiler/{path.ec5532669c81@0+0.wasm → path.1b5fd988b6f3@0+0.wasm} +0 -0
- package/build/compiler/program +21 -20
- package/build/compiler/prune.29dde307bdee@0+0.wasm +0 -0
- package/build/compiler/{reader.f4378a1f91d1@0+0.wasm → reader.d256e69e09e2@0+0.wasm} +0 -0
- package/build/compiler/roots.e366210c01d6@0+0.wasm +0 -0
- package/build/compiler/{running.7f03ff780e03@0+0.wasm → running.b99787c2d180@0+0.wasm} +0 -0
- package/build/compiler/serialize.a12536bbbe9a@0+0.wasm +0 -0
- package/build/compiler/sha256.f6c742932dde@0+0.wasm +0 -0
- package/build/compiler/substrate.728c690187f2@0+0.wasm +0 -0
- package/build/compiler/syntax.fadc832db29f@0+0.wasm +0 -0
- package/build/compiler/{writer.b698107b491f@0+0.wasm → writer.550227768eb9@0+0.wasm} +0 -0
- package/build/sub/{base64.fc39f9b2a664@0+0.wasm → base64.454b045156d2@0+0.wasm} +0 -0
- package/build/sub/build.115aeefc15e8@0+0.wasm +0 -0
- package/build/sub/{chromium.0cdcaad35704@0+0.wasm → chromium.fc0bfea0fbe6@0+0.wasm} +0 -0
- package/build/sub/{common.9ea008df47e6@0+0.wasm → common.997c21b0b8cf@0+0.wasm} +0 -0
- package/build/sub/deflate.3138a38325a1@0+0.wasm +0 -0
- package/build/sub/{doc.e0af22e9d586@0+0.wasm → doc.e3f9a998cd91@0+0.wasm} +0 -0
- package/build/sub/{doc.49b234ac4521@0+0.wasm → doc.f18ad14060e9@0+0.wasm} +0 -0
- package/build/sub/env.861d55fff974@0+0.wasm +0 -0
- package/build/sub/events.2c981f6f1ec7@0+0.wasm +0 -0
- package/build/sub/{fetch.59ad8bf17eeb@0+0.wasm → fetch.b0ce8f8b3da8@0+0.wasm} +0 -0
- package/build/sub/fetch.d62aa5fc9623@0+0.wasm +0 -0
- package/build/sub/{files.25d3fe28ff57@0+0.wasm → files.1706cc0941c0@0+0.wasm} +0 -0
- package/build/sub/{fs.3f7cf768e7ed@0+0.wasm → fs.5017b627cbd2@0+0.wasm} +0 -0
- package/build/sub/{git.c47e41fed371@0+0.wasm → git.1c5791236e35@0+0.wasm} +0 -0
- package/build/sub/{grants.e7dc20c93375@0+0.wasm → grants.cd99dff2854e@0+0.wasm} +0 -0
- package/build/sub/{gzip.0bacbb40f6e2@0+0.wasm → gzip.9ebea150f218@0+0.wasm} +0 -0
- package/build/sub/hash.ba8330dad9ff@0+0.wasm +0 -0
- package/build/sub/{html.1ab670c5f861@0+0.wasm → html.0b0362932a75@0+0.wasm} +0 -0
- package/build/sub/{html.a860b2ff2c4e@0+0.wasm → html.3b3c8d7d9971@0+0.wasm} +0 -0
- package/build/sub/{inflate.16c735654147@0+0.wasm → inflate.3cfa17586072@0+0.wasm} +0 -0
- package/build/sub/{json.74966c67a96d@0+0.wasm → json.af2e0ae20084@0+0.wasm} +0 -0
- package/build/sub/manifest.6e014ac19e5d@0+0.wasm +0 -0
- package/build/sub/map.e582eae03ec2@0+0.wasm +0 -0
- package/build/sub/{pack.a62f186e997c@0+0.wasm → pack.4295e4f5bdbd@0+0.wasm} +0 -0
- package/build/sub/{path.ec5532669c81@0+0.wasm → path.1b5fd988b6f3@0+0.wasm} +0 -0
- package/build/sub/path.de22f6659534@0+0.wasm +0 -0
- package/build/sub/process.ca10ac0b8a62@0+0.wasm +0 -0
- package/build/sub/program +48 -48
- package/build/sub/read.279fafcda508@0+0.wasm +0 -0
- package/build/sub/{reader.f4378a1f91d1@0+0.wasm → reader.d256e69e09e2@0+0.wasm} +0 -0
- package/build/sub/{root.5a3e4a594d25@0+0.wasm → root.02141d04d568@0+0.wasm} +0 -0
- package/build/sub/roots.e366210c01d6@0+0.wasm +0 -0
- package/build/sub/{sha256.92185201fb4b@0+0.wasm → sha256.f6c742932dde@0+0.wasm} +0 -0
- package/build/sub/{sha512.bf0d4c469a96@0+0.wasm → sha512.9fee24e95460@0+0.wasm} +0 -0
- package/build/sub/site.76aa8286c257@0+0.wasm +0 -0
- package/build/sub/{site.81b7f3938874@0+0.wasm → site.e6e415bc3170@0+0.wasm} +0 -0
- package/build/sub/{store.128b4d772823@0+0.wasm → store.c48db3345968@0+0.wasm} +0 -0
- package/build/sub/{stream.d95d09173ea2@0+0.wasm → stream.27fd2fe858e1@0+0.wasm} +0 -0
- package/build/sub/{sub.84126bd636af@0+0.wasm → sub.c0fb7310de12@0+0.wasm} +0 -0
- package/build/sub/{substrate.b31300129ffb@0+0.wasm → substrate.728c690187f2@0+0.wasm} +0 -0
- package/build/sub/{syntax.500cf1bcecd4@0+0.wasm → syntax.fadc832db29f@0+0.wasm} +0 -0
- package/build/sub/tar.692c0e8827cd@0+0.wasm +0 -0
- package/build/sub/{test.eed7cfa3264c@0+0.wasm → test.1fd2ff8123bf@0+0.wasm} +0 -0
- package/build/sub/{text.ca2b0668e319@0+0.wasm → text.8ff142d72fd7@0+0.wasm} +0 -0
- package/build/sub/{timer.21d74714d40b@0+0.wasm → timer.d3454726b3bf@0+0.wasm} +0 -0
- package/build/sub/{upgrade.61c36d2a50cf@0+0.wasm → upgrade.2a9219e6a45d@0+0.wasm} +0 -0
- package/build/sub/{utf8.b61525c6fb12@0+0.wasm → utf8.e82afeb9e953@0+0.wasm} +0 -0
- package/build/sub/worker.ea1e11f8f5e2@0+0.wasm +0 -0
- package/build/sub/writer.550227768eb9@0+0.wasm +0 -0
- package/package.json +1 -1
- package/std/archive/tar.sub +14 -21
- package/std/compress/deflate.sub +10 -12
- package/std/crypto/sha256.sub +3 -109
- package/std/encoding/json.sub +44 -65
- package/std/encoding/wire.sub +6 -8
- package/std/http/checks.sub +3 -3
- package/std/http/conditional.sub +2 -4
- package/std/http/cookie.sub +5 -7
- package/std/http/form.sub +7 -10
- package/std/http/http.sub +17 -24
- package/std/http/multipart.sub +5 -5
- package/std/http/route.sub +9 -9
- package/std/http/server.sub +7 -12
- package/std/http/session.sub +1 -4
- package/std/http/sse-client.sub +9 -14
- package/std/http/url.sub +10 -10
- package/std/http/websocket.sub +2 -5
- package/std/meta/type-info.sub +10 -10
- package/std/package/hash.sub +1 -1
- package/std/package/manifest.sub +14 -15
- package/std/package/map.sub +4 -8
- package/std/package/path.sub +1 -4
- package/std/package/read.sub +3 -8
- package/std/package/site.sub +5 -5
- package/std/test/compare.sub +9 -10
- package/std/test/page.sub +1 -1
- package/std/test/run.sub +1 -1
- package/std/test/session.sub +0 -1
- package/std/test/test.sub +24 -17
- package/substrate/VERSION +1 -1
- package/substrate/compiler/binary.sub +5 -14
- package/substrate/compiler/checker.sub +204 -19
- package/substrate/compiler/compile.sub +8 -8
- package/substrate/compiler/expander.sub +208 -84
- package/substrate/compiler/link.sub +2 -2
- package/substrate/compiler/main.sub +15 -2
- package/substrate/compiler/ops.sub +1 -1
- package/substrate/compiler/prune.sub +12 -17
- package/substrate/compiler/roots.sub +93 -26
- package/substrate/compiler/serialize.sub +1 -1
- package/substrate/compiler/sha256.sub +110 -0
- package/substrate/compiler/substrate.sub +14 -14
- package/substrate/compiler/syntax.sub +8 -21
- package/substrate/host/fs.sub +8 -11
- package/substrate/host/grants.sub +25 -26
- package/substrate/host/node/process.sub +5 -6
- package/substrate/host/node/worker-thread.mjs +1 -1
- package/substrate/host/node/worker.mjs +1 -0
- package/substrate/host/subhost-core.mjs +10 -3
- package/substrate/host/subhost.mjs +13 -1
- package/substrate/host/web/subhost-web.mjs +13 -2
- package/substrate/host/web/worker-script.mjs +1 -0
- package/substrate/host/web/worker.mjs +1 -0
- package/substrate/host/worker.mjs +3 -1
- package/build/compiler/binary.5d81a93450b2@0+0.wasm +0 -0
- package/build/compiler/checker.343075746d8c@0+0.wasm +0 -0
- package/build/compiler/compile.2db0f824839f@0+0.wasm +0 -0
- package/build/compiler/expander.c0f36d0bd5fc@0+0.wasm +0 -0
- package/build/compiler/main.cf521803fc5e@0+0.wasm +0 -0
- package/build/compiler/prune.f800615ca8cc@0+0.wasm +0 -0
- package/build/compiler/roots.02808ca2c6a7@0+0.wasm +0 -0
- package/build/compiler/serialize.f4354af92feb@0+0.wasm +0 -0
- package/build/compiler/substrate.b31300129ffb@0+0.wasm +0 -0
- package/build/compiler/syntax.500cf1bcecd4@0+0.wasm +0 -0
- package/build/sub/build.3a016536f5a5@0+0.wasm +0 -0
- package/build/sub/deflate.67457f2269ae@0+0.wasm +0 -0
- package/build/sub/env.d4a2d3ca5408@0+0.wasm +0 -0
- package/build/sub/events.ee8945a7ea00@0+0.wasm +0 -0
- package/build/sub/fetch.22f5c88f8a7b@0+0.wasm +0 -0
- package/build/sub/hash.75dc86b3dd19@0+0.wasm +0 -0
- package/build/sub/manifest.0c0fe02b1e58@0+0.wasm +0 -0
- package/build/sub/map.b767b94ffe7f@0+0.wasm +0 -0
- package/build/sub/path.b98f74b36b19@0+0.wasm +0 -0
- package/build/sub/process.94378bb2ecf2@0+0.wasm +0 -0
- package/build/sub/read.4b71de2f3337@0+0.wasm +0 -0
- package/build/sub/roots.02808ca2c6a7@0+0.wasm +0 -0
- package/build/sub/site.b678ce0b53b9@0+0.wasm +0 -0
- package/build/sub/tar.9c01735ea170@0+0.wasm +0 -0
- package/build/sub/worker.5ced1d8ab0d4@0+0.wasm +0 -0
- package/build/sub/writer.b698107b491f@0+0.wasm +0 -0
package/substrate/host/fs.sub
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
;; 0, or -1 when they fail, and store a failure's reason at err.
|
|
6
6
|
(provide fs-read-file fs-write-file fs-make-dir fs-info fs-stat fs-lstat fs-list fs-remove fs-rename
|
|
7
7
|
fs-read-link fs-real-path fs-symlink fs-copy fs-chmod fs-make-temp-dir fs-make-temp-file
|
|
8
|
-
fs-cwd fs-file fs-directory fs-link fs-other
|
|
8
|
+
fs-cwd fs-kind fs-none fs-file fs-directory fs-link fs-other
|
|
9
9
|
fs-open-file fs-read-at fs-write-at fs-set-size fs-sync fs-size fs-close-file fs-read-stream fs-write-stream
|
|
10
10
|
fs-read-flag fs-write-flag fs-append-flag fs-truncate-flag fs-create-flag fs-create-new-flag)
|
|
11
11
|
|
|
@@ -32,20 +32,17 @@
|
|
|
32
32
|
(import file_stream "fs" "file_stream" (i32 i32 f64 i32 i32 -> i32))
|
|
33
33
|
|
|
34
34
|
;; An fs-info's kind.
|
|
35
|
-
(
|
|
36
|
-
(const fs-directory i32 2)
|
|
37
|
-
(const fs-link i32 3)
|
|
38
|
-
(const fs-other i32 4)
|
|
35
|
+
(enum fs-kind fs-none fs-file fs-directory fs-link fs-other)
|
|
39
36
|
|
|
40
37
|
;; modified is in milliseconds since 1970, and mode is the file's mode bits, its type's included.
|
|
41
|
-
(struct fs-info [kind
|
|
38
|
+
(struct fs-info [kind fs-kind] [size i64] [modified f64] [mode u32])
|
|
42
39
|
|
|
43
40
|
(define (fs-make-dir [path string] [err (ptr string)]) -> i32
|
|
44
41
|
(make_dir (cast i32 (-> path bytes)) (cast i32 (-> path length)) (cast i32 err)))
|
|
45
42
|
|
|
46
43
|
(define (stat-of [path string] [follow bool] [i (ptr fs-info)] [err (ptr string)]) -> i32
|
|
47
44
|
(let ([(kind size modified mode) (info (cast i32 (-> path bytes)) (cast i32 (-> path length)) follow (cast i32 err))])
|
|
48
|
-
(set! (-> i kind) kind)
|
|
45
|
+
(set! (-> i kind) (cast fs-kind kind))
|
|
49
46
|
(set! (-> i size) (cast i64 size))
|
|
50
47
|
(set! (-> i modified) modified)
|
|
51
48
|
(set! (-> i mode) (cast u32 mode))
|
|
@@ -155,11 +152,11 @@
|
|
|
155
152
|
(when (== h 0) (return -1))
|
|
156
153
|
(set! size (fs-size h err))
|
|
157
154
|
(set! room (if (> size 0) (+ (cast u32 (if (> size 2147483583) 2147483583 size)) 1) 4096))
|
|
158
|
-
(set! p (
|
|
155
|
+
(set! p (try-malloc room))
|
|
159
156
|
(while (!= p 0)
|
|
160
157
|
(set! got (fs-read-at h (slice (+ p n) (- room n)) (cast i64 n) err))
|
|
161
158
|
(when (< got 0)
|
|
162
|
-
(free
|
|
159
|
+
(free p)
|
|
163
160
|
(fs-close-file h 0)
|
|
164
161
|
(return -1))
|
|
165
162
|
(+= n (cast u32 got))
|
|
@@ -167,8 +164,8 @@
|
|
|
167
164
|
(fs-close-file h 0)
|
|
168
165
|
(set! (@ into) (slice p n))
|
|
169
166
|
(return 0))
|
|
170
|
-
(set! more (
|
|
171
|
-
(when (== more 0) (free
|
|
167
|
+
(set! more (try-realloc p (* room 2)))
|
|
168
|
+
(when (== more 0) (free p))
|
|
172
169
|
(set! p more)
|
|
173
170
|
(set! room (* room 2)))
|
|
174
171
|
(fs-close-file h 0)
|
|
@@ -8,18 +8,14 @@
|
|
|
8
8
|
;; tls-cert tls-key a file
|
|
9
9
|
;; grants-parse! reads flags as people type them, like -R=a,b, where ",," is a comma inside an item, and grants-add! a
|
|
10
10
|
;; clause as manifests and tests write one, like (read "a" "b"), (all net) or (tls "cert.pem" "key.pem").
|
|
11
|
-
(provide grant grants grant-read grant-write grant-net grant-env grant-run make-grants grants-allow! grants-deny!
|
|
11
|
+
(provide grant grants grant-kind grant-read grant-write grant-net grant-env grant-run make-grants grants-allow! grants-deny!
|
|
12
12
|
grants-allow-all! grants-deny-all! grants-all! grants-inherit! grants-fake! grants-fetch! grants-tls!
|
|
13
13
|
grants-join! grants-parse! grants-flag? grants-add! grants-entries! grants-arguments)
|
|
14
14
|
|
|
15
15
|
(struct grant [kind string] [item string])
|
|
16
16
|
(struct grants [list buffer])
|
|
17
17
|
|
|
18
|
-
(
|
|
19
|
-
(const grant-write u32 1)
|
|
20
|
-
(const grant-net u32 2)
|
|
21
|
-
(const grant-env u32 3)
|
|
22
|
-
(const grant-run u32 4)
|
|
18
|
+
(enum grant-kind grant-read grant-write grant-net grant-env grant-run)
|
|
23
19
|
|
|
24
20
|
(define (make-grants) -> grants
|
|
25
21
|
(let ([g grants])
|
|
@@ -30,22 +26,24 @@
|
|
|
30
26
|
(let ([e (grant #:kind kind #:item item)])
|
|
31
27
|
(buffer-add! (& (-> g list)) (slice (cast (ptr u8) (& e)) (sizeof grant)))))
|
|
32
28
|
|
|
33
|
-
(define (allowed [k
|
|
29
|
+
(define (allowed [k grant-kind]) -> string
|
|
30
|
+
(match k [grant-read "read"] [grant-write "write"] [grant-net "net"] [grant-env "env"] [grant-run "run"]))
|
|
34
31
|
|
|
35
|
-
(define (denied [k
|
|
36
|
-
(
|
|
32
|
+
(define (denied [k grant-kind]) -> string
|
|
33
|
+
(match k [grant-read "deny-read"] [grant-write "deny-write"] [grant-net "deny-net"] [grant-env "deny-env"] [grant-run "deny-run"]))
|
|
37
34
|
|
|
38
|
-
(define (grants-allow! [g (ptr grants)] [k
|
|
35
|
+
(define (grants-allow! [g (ptr grants)] [k grant-kind] [item string]) (added! g (allowed k) item))
|
|
39
36
|
|
|
40
|
-
(define (grants-deny! [g (ptr grants)] [k
|
|
37
|
+
(define (grants-deny! [g (ptr grants)] [k grant-kind] [item string]) (added! g (denied k) item))
|
|
41
38
|
|
|
42
|
-
(define (grants-allow-all! [g (ptr grants)] [k
|
|
39
|
+
(define (grants-allow-all! [g (ptr grants)] [k grant-kind]) (added! g "all" (allowed k)))
|
|
43
40
|
|
|
44
|
-
(define (grants-deny-all! [g (ptr grants)] [k
|
|
41
|
+
(define (grants-deny-all! [g (ptr grants)] [k grant-kind]) (added! g "all" (denied k)))
|
|
45
42
|
|
|
46
|
-
(define (grants-all! [g (ptr grants)]) (for ([k u32 0]) (< k 5) (+= k 1) (grants-allow-all! g k)))
|
|
43
|
+
(define (grants-all! [g (ptr grants)]) (for ([k u32 0]) (< k 5) (+= k 1) (grants-allow-all! g (cast grant-kind k))))
|
|
47
44
|
|
|
48
|
-
(define (grants-inherit! [g (ptr grants)])
|
|
45
|
+
(define (grants-inherit! [g (ptr grants)])
|
|
46
|
+
(for ([k u32 0]) (< k 5) (+= k 1) (added! g "inherit" (allowed (cast grant-kind k)))))
|
|
49
47
|
|
|
50
48
|
(define (grants-fake! [g (ptr grants)] [name string]) (added! g "fake" name))
|
|
51
49
|
|
|
@@ -87,20 +85,20 @@
|
|
|
87
85
|
(for ([i u32 0]) (< i (-> s length)) (+= i 1) (when (== (@ s i) #\=) (return i)))
|
|
88
86
|
(-> s length))
|
|
89
87
|
|
|
90
|
-
(define (kind-of [name string] [k (ptr
|
|
88
|
+
(define (kind-of [name string] [k (ptr grant-kind)]) -> bool
|
|
91
89
|
(let ([shorts (array-of string "-R" "-W" "-N" "-E" "--allow-run")]
|
|
92
90
|
[longs (array-of string "--allow-read" "--allow-write" "--allow-net" "--allow-env" "--allow-run")])
|
|
93
91
|
(for ([i u32 0]) (< i 5) (+= i 1)
|
|
94
92
|
(when (or (== name (@ shorts i)) (== name (@ longs i)))
|
|
95
|
-
(set! (@ k) i)
|
|
93
|
+
(set! (@ k) (cast grant-kind i))
|
|
96
94
|
(return #t)))
|
|
97
95
|
#f))
|
|
98
96
|
|
|
99
|
-
(define (denial-of [name string] [k (ptr
|
|
97
|
+
(define (denial-of [name string] [k (ptr grant-kind)]) -> bool
|
|
100
98
|
(let ([names (array-of string "--deny-read" "--deny-write" "--deny-net" "--deny-env" "--deny-run")])
|
|
101
99
|
(for ([i u32 0]) (< i 5) (+= i 1)
|
|
102
100
|
(when (== name (@ names i))
|
|
103
|
-
(set! (@ k) i)
|
|
101
|
+
(set! (@ k) (cast grant-kind i))
|
|
104
102
|
(return #t)))
|
|
105
103
|
#f))
|
|
106
104
|
|
|
@@ -160,7 +158,7 @@
|
|
|
160
158
|
(define (grants-parse! [g (ptr grants)] [flags (slice string)] [err (ptr string)]) -> bool
|
|
161
159
|
(for ([i u32 0]) (< i (-> flags length)) (+= i 1)
|
|
162
160
|
(let* ([flag (@ flags i)] [eq (equals-at flag)] [name (slice flag 0 eq)] [listed (< eq (-> flag length))]
|
|
163
|
-
[value (if listed (slice flag (+ eq 1) (-> flag length)) "")] [k
|
|
161
|
+
[value (if listed (slice flag (+ eq 1) (-> flag length)) "")] [k grant-kind])
|
|
164
162
|
(cond [(or (== name "-A") (== name "--allow-all"))
|
|
165
163
|
(when listed (return (refused err name " takes no list")))
|
|
166
164
|
(grants-all! g)]
|
|
@@ -178,21 +176,22 @@
|
|
|
178
176
|
#t)
|
|
179
177
|
|
|
180
178
|
(define (grants-flag? [s string]) -> bool
|
|
181
|
-
(let ([name (slice s 0 (equals-at s))] [k
|
|
179
|
+
(let ([name (slice s 0 (equals-at s))] [k grant-kind])
|
|
182
180
|
(or (== name "-A") (== name "--allow-all") (kind-of name (& k)) (denial-of name (& k)) (== name "--fake")
|
|
183
181
|
(== name "--tls-cert") (== name "--tls-key"))))
|
|
184
182
|
|
|
185
183
|
;; ---- clauses ----
|
|
186
184
|
|
|
187
|
-
(define (kind-named [name string] [deny bool] [k (ptr
|
|
185
|
+
(define (kind-named [name string] [deny bool] [k (ptr grant-kind)]) -> bool
|
|
188
186
|
(for ([i u32 0]) (< i 5) (+= i 1)
|
|
189
|
-
(
|
|
190
|
-
(
|
|
191
|
-
|
|
187
|
+
(let ([c (cast grant-kind i)])
|
|
188
|
+
(when (== name (if deny (denied c) (allowed c)))
|
|
189
|
+
(set! (@ k) c)
|
|
190
|
+
(return #t))))
|
|
192
191
|
#f)
|
|
193
192
|
|
|
194
193
|
(define (grants-add! [g (ptr grants)] [head string] [items (slice string)] [err (ptr string)]) -> bool
|
|
195
|
-
(let ([k
|
|
194
|
+
(let ([k grant-kind] [n (-> items length)])
|
|
196
195
|
(when (== n 0) (return (refused err head " has no items")))
|
|
197
196
|
(for ([i u32 0]) (< i n) (+= i 1)
|
|
198
197
|
(when (== (-> (@ items i) length) 0) (return (refused err head " has an empty item"))))
|
|
@@ -20,11 +20,10 @@
|
|
|
20
20
|
(const process-source u32 10)
|
|
21
21
|
(const process-exit u32 1)
|
|
22
22
|
(const process-failed u32 2)
|
|
23
|
-
(
|
|
24
|
-
(const process-ignore i32 1)
|
|
25
|
-
(const process-inherit i32 2)
|
|
23
|
+
(enum process-stdio process-pipe process-ignore process-inherit)
|
|
26
24
|
|
|
27
|
-
(struct process-options [dir string] [env (slice string)] [clear bool] [stdin
|
|
25
|
+
(struct process-options [dir string] [env (slice string)] [clear bool] [stdin process-stdio] [stdout process-stdio]
|
|
26
|
+
[stderr process-stdio])
|
|
28
27
|
|
|
29
28
|
(define (process-options-init! [o (ptr process-options)])
|
|
30
29
|
(set! (-> o dir) "")
|
|
@@ -44,8 +43,8 @@
|
|
|
44
43
|
(buffer-add-entries! (& e) (-> p env))
|
|
45
44
|
(set! id (cast u32 (spawn (cast i32 (-> program bytes)) (cast i32 (-> program length)) (cast i32 (-> a bytes))
|
|
46
45
|
(cast i32 (-> a length)) (cast i32 (-> p dir bytes)) (cast i32 (-> p dir length))
|
|
47
|
-
(cast i32 (-> e bytes)) (cast i32 (-> e length)) (-> p clear) (
|
|
48
|
-
(-> p stderr) (cast i32 tag) (cast i32 err))))
|
|
46
|
+
(cast i32 (-> e bytes)) (cast i32 (-> e length)) (-> p clear) (cast i32 (-> p stdin))
|
|
47
|
+
(cast i32 (-> p stdout)) (cast i32 (-> p stderr)) (cast i32 tag) (cast i32 err))))
|
|
49
48
|
(buffer-free! (& a))
|
|
50
49
|
(buffer-free! (& e))
|
|
51
50
|
id))
|
|
@@ -44,7 +44,7 @@ parentPort.on('message', (m) => {
|
|
|
44
44
|
absent: new Set(['stdin', 'signal']),
|
|
45
45
|
memoryPages: m.pages,
|
|
46
46
|
});
|
|
47
|
-
const entry = host.load([...wasm.keys()], (name) => wasm.get(name));
|
|
47
|
+
const entry = host.load([...wasm.keys()], (name) => wasm.get(name), m.compiled);
|
|
48
48
|
if (!entry) {
|
|
49
49
|
side.ended(2, host.lastError);
|
|
50
50
|
return;
|
|
@@ -174,9 +174,11 @@ export function createHost(platform) {
|
|
|
174
174
|
// A memory's malloc, from the module that exports both.
|
|
175
175
|
const allocators = new WeakMap();
|
|
176
176
|
let lastError = '';
|
|
177
|
-
// The running program: its
|
|
177
|
+
// The running program: its module names in load order, a function that returns a module's bytes, and the files of
|
|
178
|
+
// the compiled modules its build wrote, keyed by file name (null if it wrote none).
|
|
178
179
|
let programNames = [];
|
|
179
180
|
let programBytes = null;
|
|
181
|
+
let programCompiled = null;
|
|
180
182
|
let entry = null;
|
|
181
183
|
let onEvent = null;
|
|
182
184
|
let onTrap = null;
|
|
@@ -344,7 +346,7 @@ export function createHost(platform) {
|
|
|
344
346
|
parseGrants: (list) => platform.parseGrants(list),
|
|
345
347
|
moduleNames: () => (platform.modules ? [...platform.modules.keys()] : []),
|
|
346
348
|
module: (name) => (platform.modules ? platform.modules.get(name) : undefined),
|
|
347
|
-
program: () => ({ names: programNames, bytes: programBytes }),
|
|
349
|
+
program: () => ({ names: programNames, bytes: programBytes, compiled: programCompiled }),
|
|
348
350
|
// named gives the module and the export name of the program's function at the index in the table, or null.
|
|
349
351
|
named(index) {
|
|
350
352
|
const table = self.exports.table;
|
|
@@ -412,6 +414,10 @@ export function createHost(platform) {
|
|
|
412
414
|
const name = string(np, nl);
|
|
413
415
|
return programNames.includes(name) ? give(programBytes(name), out) : 0;
|
|
414
416
|
},
|
|
417
|
+
compiled_file(np, nl, out) {
|
|
418
|
+
const bytes = programCompiled && programCompiled.get(string(np, nl));
|
|
419
|
+
return bytes ? give(bytes, out) : 0;
|
|
420
|
+
},
|
|
415
421
|
};
|
|
416
422
|
}
|
|
417
423
|
|
|
@@ -499,9 +505,10 @@ export function createHost(platform) {
|
|
|
499
505
|
return true;
|
|
500
506
|
}
|
|
501
507
|
|
|
502
|
-
function load(names, bytesOf) {
|
|
508
|
+
function load(names, bytesOf, compiled = null) {
|
|
503
509
|
programNames = names;
|
|
504
510
|
programBytes = bytesOf;
|
|
511
|
+
programCompiled = compiled;
|
|
505
512
|
running = true;
|
|
506
513
|
try {
|
|
507
514
|
for (const name of names) {
|
|
@@ -61,6 +61,18 @@ const names = read(`${dir}/program`).toString().split(/\r?\n/).filter((n) => n !
|
|
|
61
61
|
const outside = names.find((name) => /[/\\]/.test(name));
|
|
62
62
|
if (outside !== undefined) fail(`${dir}/program lists ${outside}, which is not in ${dir}`);
|
|
63
63
|
const bytes = new Map(names.map((name) => [name, read(`${dir}/${name}.wasm`)]));
|
|
64
|
+
// The compiled modules for sessions: the compiled file lists them, each one is in <hash>.subc, and compiled.map holds
|
|
65
|
+
// their module map.
|
|
66
|
+
const compiled = new Map();
|
|
67
|
+
if (fs.existsSync(`${dir}/compiled`)) {
|
|
68
|
+
const list = read(`${dir}/compiled`);
|
|
69
|
+
const hashes = list.toString().split(/\r?\n/).filter((l) => l !== '').map((l) => l.slice(0, l.indexOf(' ')));
|
|
70
|
+
const bad = hashes.find((h) => !/^[0-9a-f]+$/.test(h));
|
|
71
|
+
if (bad !== undefined) fail(`${dir}/compiled lists ${bad}, which is not a hash`);
|
|
72
|
+
compiled.set('compiled', list);
|
|
73
|
+
if (hashes.length > 0) compiled.set('compiled.map', read(`${dir}/compiled.map`));
|
|
74
|
+
for (const h of hashes) compiled.set(`${h}.subc`, read(`${dir}/${h}.subc`));
|
|
75
|
+
}
|
|
64
76
|
|
|
65
77
|
// The program process.exec_at_end kept (node/process.mjs).
|
|
66
78
|
const atEnd = () => {
|
|
@@ -93,7 +105,7 @@ const host = createHost({
|
|
|
93
105
|
keyOf: (bytes) => crypto.createHash('sha256').update(bytes).digest('hex'),
|
|
94
106
|
});
|
|
95
107
|
|
|
96
|
-
const entry = host.load(names, (name) => bytes.get(name));
|
|
108
|
+
const entry = host.load(names, (name) => bytes.get(name), compiled);
|
|
97
109
|
if (!entry) {
|
|
98
110
|
process.stderr.write(`error: ${host.lastError}\n`);
|
|
99
111
|
process.exit(2);
|
|
@@ -110,7 +110,18 @@ export async function boot(options) {
|
|
|
110
110
|
for (const bytes of wasm.values()) for (const name of importedModules(bytes)) wanted.add(name);
|
|
111
111
|
modules = await modules(wanted);
|
|
112
112
|
}
|
|
113
|
-
|
|
113
|
+
// The compiled modules for sessions: the compiled file lists them, each one is in <hash>.subc, and compiled.map holds
|
|
114
|
+
// their module map.
|
|
115
|
+
const compiled = new Map();
|
|
116
|
+
const listed = await fetch(`${base}compiled`);
|
|
117
|
+
if (listed.ok) {
|
|
118
|
+
const list = new Uint8Array(await listed.arrayBuffer());
|
|
119
|
+
const hashes = text.decode(list).split('\n').filter((l) => l !== '').map((l) => l.slice(0, l.indexOf(' ')));
|
|
120
|
+
compiled.set('compiled', list);
|
|
121
|
+
if (hashes.length > 0) compiled.set('compiled.map', await fetchBytes(`${base}compiled.map`));
|
|
122
|
+
await Promise.all(hashes.map(async (h) => compiled.set(`${h}.subc`, await fetchBytes(`${base}${h}.subc`))));
|
|
123
|
+
}
|
|
124
|
+
return run({ ...options, files, modules, compiled }, names, wasm);
|
|
114
125
|
}
|
|
115
126
|
|
|
116
127
|
export function run(options, names, wasm) {
|
|
@@ -157,7 +168,7 @@ export function run(options, names, wasm) {
|
|
|
157
168
|
return host.call(f, args);
|
|
158
169
|
};
|
|
159
170
|
|
|
160
|
-
app.entry = host.load(names, (name) => wasm.get(name));
|
|
171
|
+
app.entry = host.load(names, (name) => wasm.get(name), options.compiled || null);
|
|
161
172
|
if (!app.entry && options.entry) {
|
|
162
173
|
ended(2, host.lastError);
|
|
163
174
|
} else if (!app.entry) {
|
|
@@ -63,9 +63,11 @@ export function workerModule({ spawn }) {
|
|
|
63
63
|
function start(entry, argument, time, pages, heard, tag, app, err, grants, setup) {
|
|
64
64
|
const program = caller.program();
|
|
65
65
|
const modules = program.names.map((name) => [name, program.bytes(name)]);
|
|
66
|
+
const { compiled } = program;
|
|
66
67
|
let thread;
|
|
67
68
|
try {
|
|
68
|
-
thread = spawn({ modules, entry, argument, grants, names: caller.moduleNames(), pages, heard, ...setup },
|
|
69
|
+
thread = spawn({ modules, compiled, entry, argument, grants, names: caller.moduleNames(), pages, heard, ...setup },
|
|
70
|
+
app);
|
|
69
71
|
} catch (e) {
|
|
70
72
|
caller.fail(err, e.message);
|
|
71
73
|
return 0;
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|