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
|
@@ -251,8 +251,8 @@
|
|
|
251
251
|
[nkept u32 0] [base u32 0])
|
|
252
252
|
(set! (-> k nf) (+ (-> s nfimports) ndefined))
|
|
253
253
|
(set! (-> k ng) (+ (-> s ngimports) (length (-> s globals))))
|
|
254
|
-
(set! (-> k fmap) (
|
|
255
|
-
(set! (-> k gmap) (
|
|
254
|
+
(set! (-> k fmap) (-> (new 0 u32 (+ (-> k nf) 1)) items))
|
|
255
|
+
(set! (-> k gmap) (-> (new 0 u32 (+ (-> k ng) 1)) items))
|
|
256
256
|
(set! (-> k kept) nil)
|
|
257
257
|
(set! (-> k hooks) nil)
|
|
258
258
|
(set! (-> k sp) 0)
|
|
@@ -100,15 +100,28 @@
|
|
|
100
100
|
[else ""]))
|
|
101
101
|
""))
|
|
102
102
|
|
|
103
|
+
;; write-program! writes the built program to dir: its wasm modules and the program file that lists them, plus the
|
|
104
|
+
;; compiled modules its sessions can load. Each compiled module is saved as <hash>.subc, where hash is the SHA-256 of
|
|
105
|
+
;; its contents, and listed in the compiled file. compiled.map holds the module map they were built with.
|
|
103
106
|
(define (write-program! [root datum] [file datum] [dir datum] [strip bool])
|
|
104
107
|
(let* ([m (compile-module-file root file)] [pruned-modules (pruned (program-wasm-modules m))]
|
|
105
|
-
[ls (if strip (stripped pruned-modules) pruned-modules)] [names nil])
|
|
108
|
+
[ls (if strip (stripped pruned-modules) pruned-modules)] [names nil] [compiled (program-compiled-modules m)]
|
|
109
|
+
[listed nil])
|
|
106
110
|
(make-dir dir)
|
|
107
111
|
(while (pair? ls)
|
|
108
112
|
(write-file (joined `(,dir "/" ,(car (car ls)) ".wasm")) (datum->bytes (cdr (car ls))))
|
|
109
113
|
(set! names (cons '"\n" (cons (car (car ls)) names)))
|
|
110
114
|
(set! ls (cdr ls)))
|
|
111
|
-
(write-file (joined `(,dir "/program")) (cast (slice u8) (datum->string (joined (reverse names)))))
|
|
115
|
+
(write-file (joined `(,dir "/program")) (cast (slice u8) (datum->string (joined (reverse names)))))
|
|
116
|
+
(for-each (lambda ([c datum])
|
|
117
|
+
(write-file (joined `(,dir "/" ,(cadr c) ".subc")) (datum->bytes (caddr c)))
|
|
118
|
+
(set! listed (cons '"\n" (cons (car c) (cons '" " (cons (cadr c) listed))))))
|
|
119
|
+
compiled)
|
|
120
|
+
(unless (null? compiled)
|
|
121
|
+
(write-file (joined `(,dir "/compiled.map"))
|
|
122
|
+
(cast (slice u8) (datum->string (joined (map (lambda ([f datum]) -> datum (format "~s\n" (cons f nil)))
|
|
123
|
+
(compiled-module-map)))))))
|
|
124
|
+
(write-file (joined `(,dir "/compiled")) (cast (slice u8) (datum->string (joined (reverse listed)))))))
|
|
112
125
|
|
|
113
126
|
(define (print-expanded [form datum])
|
|
114
127
|
(let ([b (make-buffer)])
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
memory.copy memory.fill))
|
|
16
16
|
|
|
17
17
|
(define (def! [name datum] [code datum] [params datum] [results datum] [align i32])
|
|
18
|
-
(let ([op (
|
|
18
|
+
(let ([op (new (& run-arena) prim-op)])
|
|
19
19
|
(set! (-> op name) name)
|
|
20
20
|
(set! (-> op code) code)
|
|
21
21
|
(set! (-> op params) params)
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
(define (unreadable) (raise-compile-error 0 "internal: a program's wasm module cannot be read"))
|
|
19
19
|
|
|
20
20
|
(define (new-wasm [name datum] [bytes datum]) -> (ptr wasm)
|
|
21
|
-
(let ([w (
|
|
21
|
+
(let ([w (new (current-arena) wasm)] [id u32 0] [head u32 0] [next u32 0])
|
|
22
22
|
(set! (-> w name) name)
|
|
23
23
|
(set! (-> w bytes) (datum->bytes bytes))
|
|
24
24
|
(set! (-> w sections) nil)
|
|
@@ -66,20 +66,15 @@
|
|
|
66
66
|
[(== id 9) (read-elems!)]
|
|
67
67
|
[(== id 10) (read-bodies! w)])
|
|
68
68
|
(set! ss (cdr ss)))
|
|
69
|
-
(set! (-> w live) (
|
|
70
|
-
(
|
|
71
|
-
(set! (-> w table-functions) (cast (ptr bool) (arena-alloc (current-arena) (+ (-> w nimports) (-> w count) 1))))
|
|
72
|
-
(memset (-> w table-functions) 0 (+ (-> w nimports) (-> w count) 1))
|
|
69
|
+
(set! (-> w live) (-> (new (current-arena) bool (+ (-> w nimports) (-> w count) 1)) items))
|
|
70
|
+
(set! (-> w table-functions) (-> (new (current-arena) bool (+ (-> w nimports) (-> w count) 1)) items))
|
|
73
71
|
(for-each (lambda ([t datum]) (set! (@ (-> w table-functions) (cast u32 (integer-value (car t)))) #t)) (-> w tables))
|
|
74
|
-
(set! (-> w valued) (
|
|
75
|
-
(
|
|
76
|
-
(set! (-> w read-
|
|
77
|
-
(memset (-> w read-globals) 0 (+ (-> w nglobals) 1))
|
|
78
|
-
(set! (-> w read-datas) (cast (ptr bool) (arena-alloc (current-arena) (+ (-> w ndatas) 1))))
|
|
79
|
-
(memset (-> w read-datas) 0 (+ (-> w ndatas) 1))
|
|
72
|
+
(set! (-> w valued) (-> (new (current-arena) bool (+ (-> w nimports) (-> w count) 1)) items))
|
|
73
|
+
(set! (-> w read-globals) (-> (new (current-arena) bool (+ (-> w nglobals) 1)) items))
|
|
74
|
+
(set! (-> w read-datas) (-> (new (current-arena) bool (+ (-> w ndatas) 1)) items))
|
|
80
75
|
(set! (-> w sites) (make-buffer))
|
|
81
|
-
(set! (-> w site-starts) (
|
|
82
|
-
(set! (-> w site-ends) (
|
|
76
|
+
(set! (-> w site-starts) (-> (new (current-arena) u32 (+ (-> w count) 1)) items))
|
|
77
|
+
(set! (-> w site-ends) (-> (new (current-arena) u32 (+ (-> w count) 1)) items))))
|
|
83
78
|
|
|
84
79
|
;; Each import's span is its kind and its bytes' start and end.
|
|
85
80
|
(define (read-imports! [w (ptr wasm)])
|
|
@@ -125,8 +120,8 @@
|
|
|
125
120
|
(define (read-bodies! [w (ptr wasm)])
|
|
126
121
|
(let ([n (uleb)] [size u32 0])
|
|
127
122
|
(set! (-> w count) n)
|
|
128
|
-
(set! (-> w starts) (
|
|
129
|
-
(set! (-> w ends) (
|
|
123
|
+
(set! (-> w starts) (-> (new (current-arena) u32 (+ n 1)) items))
|
|
124
|
+
(set! (-> w ends) (-> (new (current-arena) u32 (+ n 1)) items))
|
|
130
125
|
(for ([k u32 0]) (< k n) (+= k 1)
|
|
131
126
|
(set! size (uleb))
|
|
132
127
|
(set! (@ (-> w starts) k) (position))
|
|
@@ -335,7 +330,7 @@
|
|
|
335
330
|
|
|
336
331
|
(define (renumber! [w (ptr wasm)])
|
|
337
332
|
(let ([total (+ (-> w nimports) (-> w count))] [next u32 0])
|
|
338
|
-
(set! (-> w indexes) (
|
|
333
|
+
(set! (-> w indexes) (-> (new (current-arena) u32 (+ total 1)) items))
|
|
339
334
|
(for ([i u32 0]) (< i total) (+= i 1)
|
|
340
335
|
(set! (@ (-> w indexes) i) next)
|
|
341
336
|
(when (@ (-> w live) i) (+= next 1)))))
|
|
@@ -371,7 +366,7 @@
|
|
|
371
366
|
(define (rewritten [w (ptr wasm)]) -> datum
|
|
372
367
|
(let ([out (make-buffer)] [ss (-> w sections)] [news (ptr u32) 0] [s datum 0])
|
|
373
368
|
(renumber! w)
|
|
374
|
-
(set! news (
|
|
369
|
+
(set! news (-> (new (current-arena) u32 (+ (-> w count) 1)) items))
|
|
375
370
|
(buffer-add! (& out) (slice (-> w bytes) 0 8))
|
|
376
371
|
(while (pair? ss)
|
|
377
372
|
(let* ([sec (car ss)] [id (integer-value (car sec))] [head (cast u32 (integer-value (cadr sec)))]
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
(provide set-toolchain-directory! set-module-map! set-module-map-text! set-display-directory! toolchain-root? toolchain-roots
|
|
10
10
|
toolchain-holding root-directories root-under-test? identity identity-label host-file entry-identity program-identity
|
|
11
|
-
module-source-file module-path-from
|
|
11
|
+
set-compiled-module-map! compiled-module-map compiled-module compiled-root? module-source-file module-path-from
|
|
12
12
|
module-identity named-file program-forms language-path compiler-file module-source? string-literal? displayed
|
|
13
13
|
write-error fail-at read-text file-text host-error module-refusal)
|
|
14
14
|
|
|
@@ -76,35 +76,46 @@
|
|
|
76
76
|
(set! toolchain-directory (keep (absolute dir)))
|
|
77
77
|
(set! roots (keep (toolchain-roots)))
|
|
78
78
|
(set! shared-uses nil)
|
|
79
|
-
(set! test-labels nil)
|
|
79
|
+
(set! test-labels nil)
|
|
80
|
+
(set! compiled nil))
|
|
80
81
|
|
|
81
82
|
;; A root is (label directory uses rules): uses is ((name label) ...), and rules is () or (exports file packages), with
|
|
82
83
|
;; paths relative to the directory. A module's identity is label/path in its root, or ./path or ../path from the first
|
|
83
|
-
;; file's directory when no root holds it.
|
|
84
|
+
;; file's directory when no root holds it. A root of compiled modules has #f instead of a directory.
|
|
84
85
|
(define roots datum nil)
|
|
85
86
|
(define shared-uses datum nil)
|
|
86
87
|
(define test-labels datum nil)
|
|
87
88
|
(define loose-directory datum 0)
|
|
88
89
|
(define display-directory datum 0)
|
|
89
90
|
|
|
91
|
+
;; compiled holds the compiled modules from the program's build, as (identity hash) pairs, where hash is the SHA-256 of
|
|
92
|
+
;; the module's file.
|
|
93
|
+
(define compiled datum nil)
|
|
94
|
+
|
|
90
95
|
(define toolchain-labels datum '("host" "compiler"))
|
|
91
96
|
|
|
92
97
|
(define (toolchain-root? [label datum]) -> bool (!= (member label toolchain-labels) 0))
|
|
93
98
|
|
|
94
|
-
(define (toolchain-roots) -> datum
|
|
99
|
+
(define (toolchain-roots) -> datum
|
|
100
|
+
(map (lambda ([l datum]) -> datum `(,l ,(if (== toolchain-directory 0) '#f (file-in toolchain-directory l)) () ()))
|
|
101
|
+
toolchain-labels))
|
|
95
102
|
|
|
96
|
-
(define (root-directories) -> datum
|
|
103
|
+
(define (root-directories) -> datum
|
|
104
|
+
(filter (lambda ([d datum]) -> bool (not (equal? d '#f))) (map (lambda ([r datum]) -> datum (cadr r)) roots)))
|
|
97
105
|
|
|
98
106
|
(define (root-under-test? [label datum]) -> bool (!= (member label test-labels) 0))
|
|
99
107
|
|
|
100
|
-
;; set-module-map! replaces the roots with a module map
|
|
101
|
-
;; (uses (name label) ...) forms.
|
|
108
|
+
;; set-module-map! replaces the roots with those of a module map, which is made of (root label "directory" clause ...),
|
|
109
|
+
;; (uses (name label) ...) and (program label) forms. A root of compiled modules has no directory.
|
|
102
110
|
(define (set-module-map! [forms datum])
|
|
103
111
|
(set! roots (keep (toolchain-roots)))
|
|
104
112
|
(set! shared-uses nil)
|
|
105
113
|
(set! test-labels nil)
|
|
106
114
|
(for-each (lambda ([f datum])
|
|
107
|
-
(
|
|
115
|
+
(cond [(and (pair? f) (equal? (car f) 'uses)) (set! shared-uses (keep (uses-in f shared-uses)))]
|
|
116
|
+
[(and (pair? f) (equal? (car f) 'program) (pair? (cdr f)) (symbol? (cadr f)) (null? (cddr f)))
|
|
117
|
+
(set! program-label (keep (string->datum (symbol->string (cadr f)))))]
|
|
118
|
+
[else (add-root! f)]))
|
|
108
119
|
forms)
|
|
109
120
|
(for-each (lambda ([r datum])
|
|
110
121
|
(for-each (lambda ([u datum])
|
|
@@ -117,13 +128,16 @@
|
|
|
117
128
|
shared-uses))
|
|
118
129
|
|
|
119
130
|
(define (add-root! [f datum])
|
|
120
|
-
(let ([label datum 0] [uses nil] [exports nil] [one '""] [nested nil] [restricted #f] [cs datum 0])
|
|
121
|
-
(unless (and (pair? f) (equal? (car f) 'root) (pair? (cdr f)) (symbol? (cadr f))
|
|
131
|
+
(let ([label datum 0] [dir datum '#f] [uses nil] [exports nil] [one '""] [nested nil] [restricted #f] [cs datum 0])
|
|
132
|
+
(unless (and (pair? f) (equal? (car f) 'root) (pair? (cdr f)) (symbol? (cadr f)))
|
|
122
133
|
(fail-at 0 "expected (root label \"directory\" clause ...) or (uses (name label) ...), not ~s" (list1 f)))
|
|
123
134
|
(set! label (string->datum (symbol->string (cadr f))))
|
|
124
135
|
(when (or (toolchain-root? label) (!= (assoc label roots) 0))
|
|
125
136
|
(fail-at 0 "the module map gives a root named ~a twice, or names a root host or compiler" (list1 label)))
|
|
126
|
-
(set! cs (
|
|
137
|
+
(set! cs (cddr f))
|
|
138
|
+
(when (and (pair? cs) (string? (car cs)))
|
|
139
|
+
(set! dir (absolute (car cs)))
|
|
140
|
+
(set! cs (cdr cs)))
|
|
127
141
|
(while (pair? cs)
|
|
128
142
|
(let ([c (car cs)])
|
|
129
143
|
(cond [(and (pair? c) (equal? (car c) 'uses)) (set! uses (uses-in c uses))]
|
|
@@ -141,7 +155,7 @@
|
|
|
141
155
|
(fail-at 0 "a root's clauses are (uses (name label) ...), (exports \"path\" ...), (file \"path\"), (packages (name \"path\") ...) and (test), not ~s"
|
|
142
156
|
(list1 c))]))
|
|
143
157
|
(set! cs (cdr cs)))
|
|
144
|
-
(set! roots (keep (cons `(,label ,
|
|
158
|
+
(set! roots (keep (cons `(,label ,dir ,uses ,(if restricted `(,exports ,one ,nested) nil)) roots)))))
|
|
145
159
|
|
|
146
160
|
(define (nested? [l datum]) -> bool
|
|
147
161
|
(while (pair? l)
|
|
@@ -169,6 +183,44 @@
|
|
|
169
183
|
(define (set-module-map-text! [text datum] [source datum])
|
|
170
184
|
(set-module-map! (map (lambda ([f datum]) -> datum (syntax->datum f)) (read-text text (symbol-of source)))))
|
|
171
185
|
|
|
186
|
+
;; set-compiled-module-map! replaces the roots with those of the program's compiled modules, which have no directories.
|
|
187
|
+
(define (set-compiled-module-map! [forms datum] [modules datum])
|
|
188
|
+
(set! toolchain-directory 0)
|
|
189
|
+
(set-module-map! forms)
|
|
190
|
+
(set! compiled (keep modules)))
|
|
191
|
+
|
|
192
|
+
;; compiled-module-map returns the module map without directories, which a build writes next to the program's compiled
|
|
193
|
+
;; modules.
|
|
194
|
+
(define (compiled-module-map) -> datum
|
|
195
|
+
(let ([out (if (== program-label 0) nil `((program ,(symbol-of program-label))))])
|
|
196
|
+
(unless (null? shared-uses) (set! out (cons (cons 'uses (uses-forms shared-uses)) out)))
|
|
197
|
+
(for-each (lambda ([r datum])
|
|
198
|
+
(unless (toolchain-root? (car r))
|
|
199
|
+
(set! out (cons (append `(root ,(symbol-of (car r)) ,(cons 'uses (uses-forms (caddr r))))
|
|
200
|
+
(append (rules-forms (cadddr r)) (if (root-under-test? (car r)) '((test)) nil)))
|
|
201
|
+
out))))
|
|
202
|
+
roots)
|
|
203
|
+
out))
|
|
204
|
+
|
|
205
|
+
(define (uses-forms [uses datum]) -> datum
|
|
206
|
+
(map (lambda ([u datum]) -> datum `(,(symbol-of (car u)) ,(symbol-of (cadr u)))) uses))
|
|
207
|
+
|
|
208
|
+
(define (rules-forms [rules datum]) -> datum
|
|
209
|
+
(if (null? rules)
|
|
210
|
+
nil
|
|
211
|
+
(append (list1 (cons 'exports (car rules)))
|
|
212
|
+
(append (if (equal? (cadr rules) '"") nil `((file ,(cadr rules))))
|
|
213
|
+
(if (null? (caddr rules))
|
|
214
|
+
nil
|
|
215
|
+
(list1 (cons 'packages (map (lambda ([p datum]) -> datum `(,(symbol-of (car p)) ,(cadr p)))
|
|
216
|
+
(caddr rules)))))))))
|
|
217
|
+
|
|
218
|
+
(define (compiled-module [id datum]) -> datum (assoc id compiled))
|
|
219
|
+
|
|
220
|
+
(define (compiled-root? [id datum]) -> bool
|
|
221
|
+
(let* ([label (identity-label id)] [r (if (== label 0) 0 (assoc label roots))])
|
|
222
|
+
(and (!= r 0) (equal? (cadr r) '#f))))
|
|
223
|
+
|
|
172
224
|
(define (set-display-directory! [dir datum]) (set! display-directory (keep (absolute dir))))
|
|
173
225
|
|
|
174
226
|
(define (root-of [label datum]) -> datum (root-in label roots))
|
|
@@ -205,12 +257,13 @@
|
|
|
205
257
|
[else id])))
|
|
206
258
|
|
|
207
259
|
(define (host-file [id datum]) -> datum
|
|
208
|
-
(let ([label (identity-label id)])
|
|
209
|
-
(
|
|
210
|
-
|
|
211
|
-
|
|
260
|
+
(let ([label (identity-label id)] [dir datum 0])
|
|
261
|
+
(when (== label 0) (return (resolve-segments (concat (loose-root) (concat '"/" (identity-path id))))))
|
|
262
|
+
(set! dir (cadr (root-of label)))
|
|
263
|
+
(if (equal? dir '#f) '#f (file-in dir (identity-path id)))))
|
|
212
264
|
|
|
213
|
-
(define (inside? [file datum] [dir datum]) -> bool
|
|
265
|
+
(define (inside? [file datum] [dir datum]) -> bool
|
|
266
|
+
(and (not (equal? dir '#f)) (path-within? (path-windows?) (datum->string file) (datum->string dir))))
|
|
214
267
|
|
|
215
268
|
(define (toolchain-holding [file datum]) -> datum
|
|
216
269
|
(let ([l roots] [found datum 0])
|
|
@@ -228,7 +281,9 @@
|
|
|
228
281
|
found))
|
|
229
282
|
|
|
230
283
|
(define (holds? [r datum] [file datum]) -> bool
|
|
231
|
-
(
|
|
284
|
+
(cond [(equal? (cadr r) '#f) #f]
|
|
285
|
+
[(equal? (one-file r) '"") (inside? file (cadr r))]
|
|
286
|
+
[else (same? file (file-in (cadr r) (one-file r)))]))
|
|
232
287
|
|
|
233
288
|
(define (same? [a datum] [b datum]) -> bool (path-same? (path-windows?) (datum->string a) (datum->string b)))
|
|
234
289
|
|
|
@@ -286,7 +341,7 @@
|
|
|
286
341
|
|
|
287
342
|
(define (displayed [source datum]) -> datum
|
|
288
343
|
(let ([label (identity-label source)])
|
|
289
|
-
(cond [(and (!= label 0) (== (assoc label roots) 0)) source]
|
|
344
|
+
(cond [(and (!= label 0) (or (== (assoc label roots) 0) (compiled-root? source))) source]
|
|
290
345
|
[(!= display-directory 0) (relative-path display-directory (host-file source))]
|
|
291
346
|
[(== label 0) (identity-path source)]
|
|
292
347
|
[else source])))
|
|
@@ -296,9 +351,10 @@
|
|
|
296
351
|
name
|
|
297
352
|
(string->datum (path-joined (path-windows?) (datum->string dir) (datum->string name)))))
|
|
298
353
|
|
|
299
|
-
(define (kind-of [path datum]) ->
|
|
354
|
+
(define (kind-of [path datum]) -> fs-kind
|
|
300
355
|
(let ([info fs-info])
|
|
301
|
-
(
|
|
356
|
+
(fs-stat (datum->string path) (& info) 0)
|
|
357
|
+
(-> info kind)))
|
|
302
358
|
|
|
303
359
|
(define (clean-name? [s string]) -> bool
|
|
304
360
|
(let ([start u32 0])
|
|
@@ -318,9 +374,10 @@
|
|
|
318
374
|
(let* ([s (symbol->string (syntax-e id))] [n (-> s length)] [slash u32 0] [label datum 0])
|
|
319
375
|
(unless (clean-name? s) (fail-at id "~a is not a module name: its parts may not be empty, . or .." (list1 (syntax-e id))))
|
|
320
376
|
(while (and (< slash n) (!= (@ s slash) #\/)) (+= slash 1))
|
|
321
|
-
(set! label (named-root id (string->datum (slice s 0 slash)) (
|
|
377
|
+
(set! label (named-root id (string->datum (slice s 0 slash)) (naming-label from) rs))
|
|
322
378
|
(when (== slash n) (return (identity label (concat (label-name label) '".sub"))))
|
|
323
|
-
(
|
|
379
|
+
(let ([dir (cadr (root-in label rs))] [rest (string->datum (slice s (+ slash 1) n))])
|
|
380
|
+
(identity label (if (equal? dir '#f) (compiled-file label rest) (named-file dir rest))))))
|
|
324
381
|
|
|
325
382
|
(define (named-file [dir datum] [rest datum]) -> datum
|
|
326
383
|
(let ([file (concat rest '".sub")])
|
|
@@ -328,6 +385,16 @@
|
|
|
328
385
|
(file-in rest (concat (last-part rest) '".sub"))
|
|
329
386
|
file)))
|
|
330
387
|
|
|
388
|
+
;; compiled-file does what named-file does, for a root of compiled modules.
|
|
389
|
+
(define (compiled-file [label datum] [rest datum]) -> datum
|
|
390
|
+
(let ([file (concat rest '".sub")] [inner (file-in rest (concat (last-part rest) '".sub"))])
|
|
391
|
+
(if (and (== (compiled-module (identity label file)) 0) (!= (compiled-module (identity label inner)) 0)) inner file)))
|
|
392
|
+
|
|
393
|
+
;; naming-label returns the root used to resolve module names in code from a given module: that module's root, or the
|
|
394
|
+
;; program's root for code outside any root, such as session input.
|
|
395
|
+
(define (naming-label [from datum]) -> datum
|
|
396
|
+
(let ([label (if (== from 0) 0 (identity-label from))]) (if (== label 0) program-label label)))
|
|
397
|
+
|
|
331
398
|
(define (named-root [id datum] [head datum] [from datum] [rs datum]) -> datum
|
|
332
399
|
(let ([r (if (or (== from 0) (toolchain-root? from)) 0 (root-in from rs))] [u datum 0])
|
|
333
400
|
(cond [(toolchain-root? head) head]
|
|
@@ -395,13 +462,13 @@
|
|
|
395
462
|
[else (package-refusal subject id r (if (== from 0) program-label (identity-label from)))])))
|
|
396
463
|
|
|
397
464
|
(define (package-refusal [subject datum] [id datum] [r datum] [from-label datum]) -> datum
|
|
398
|
-
(let* ([rules (cadddr r)] [exports (car rules)] [one (cadr rules)] [path (identity-path id)]
|
|
399
|
-
[holder (root-holding (host-file id))] [inner (nested-holding (caddr rules) path)])
|
|
465
|
+
(let* ([rules (cadddr r)] [exports (car rules)] [one (cadr rules)] [path (identity-path id)] [files (not (equal? (cadr r) '#f))]
|
|
466
|
+
[holder (if files (root-holding (host-file id)) 0)] [inner (nested-holding (caddr rules) path)])
|
|
400
467
|
(cond [(not (equal? one '""))
|
|
401
468
|
(if (equal? path one) 0 (format "~a is not part of ~a, a package of one file" `(,subject ,(car r))))]
|
|
402
469
|
[(!= inner 0) (format "~a is in the package ~a, which is required by name" `(,subject ,(car inner)))]
|
|
403
470
|
[(and (!= holder 0) (not (equal? (cadr holder) (cadr r)))) (by-name subject holder)]
|
|
404
|
-
[(linked-under? (cadr r) path)
|
|
471
|
+
[(and files (linked-under? (cadr r) path))
|
|
405
472
|
(format "~a goes through a link in the package ~a, which packages do not allow" `(,subject ,(car r)))]
|
|
406
473
|
[(or (and (!= from-label 0) (equal? from-label (car r))) (!= (member path exports) 0)) 0]
|
|
407
474
|
[else (format "~a is not one of the modules ~a exports" `(,subject ,(car r)))])))
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
[atoms (ptr hash-table)] [pairs (ptr hash-table)] [scopes (ptr hash-table)] [table datum])
|
|
9
9
|
|
|
10
10
|
(define (make-serializer) -> (ptr serializer)
|
|
11
|
-
(let ([s (
|
|
11
|
+
(let ([s (new (current-arena) serializer)])
|
|
12
12
|
(set! (-> s out) (make-buffer))
|
|
13
13
|
(set! (-> s count) 0)
|
|
14
14
|
(set! (-> s shared) (make-table))
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
;; SHA-256 (FIPS 180-4), over bytes added in pieces or given at once.
|
|
2
|
+
(provide sha256 sha256-init! sha256-add! sha256-end! sha256-of)
|
|
3
|
+
|
|
4
|
+
(struct sha256 [state (array u32 8)] [block (array u8 64)] [filled u32] [length u64])
|
|
5
|
+
|
|
6
|
+
(define k (array u32 64)
|
|
7
|
+
(array-of u32 #x428a2f98 #x71374491 #xb5c0fbcf #xe9b5dba5 #x3956c25b #x59f111f1 #x923f82a4 #xab1c5ed5
|
|
8
|
+
#xd807aa98 #x12835b01 #x243185be #x550c7dc3 #x72be5d74 #x80deb1fe #x9bdc06a7 #xc19bf174
|
|
9
|
+
#xe49b69c1 #xefbe4786 #x0fc19dc6 #x240ca1cc #x2de92c6f #x4a7484aa #x5cb0a9dc #x76f988da
|
|
10
|
+
#x983e5152 #xa831c66d #xb00327c8 #xbf597fc7 #xc6e00bf3 #xd5a79147 #x06ca6351 #x14292967
|
|
11
|
+
#x27b70a85 #x2e1b2138 #x4d2c6dfc #x53380d13 #x650a7354 #x766a0abb #x81c2c92e #x92722c85
|
|
12
|
+
#xa2bfe8a1 #xa81a664b #xc24b8b70 #xc76c51a3 #xd192e819 #xd6990624 #xf40e3585 #x106aa070
|
|
13
|
+
#x19a4c116 #x1e376c08 #x2748774c #x34b0bcb5 #x391c0cb3 #x4ed8aa4a #x5b9cca4f #x682e6ff3
|
|
14
|
+
#x748f82ee #x78a5636f #x84c87814 #x8cc70208 #x90befffa #xa4506ceb #xbef9a3f7 #xc67178f2))
|
|
15
|
+
|
|
16
|
+
(define (rotr [x u32] [n u32]) #:inline -> u32 (bit-or (>> x n) (<< x (- 32 n))))
|
|
17
|
+
|
|
18
|
+
(define (word [p (ptr u8)]) #:inline -> u32
|
|
19
|
+
(bit-or (<< (cast u32 (@ p 0)) 24) (<< (cast u32 (@ p 1)) 16) (<< (cast u32 (@ p 2)) 8) (cast u32 (@ p 3))))
|
|
20
|
+
|
|
21
|
+
(define (compress! [s (ptr sha256)] [p (ptr u8)])
|
|
22
|
+
(let ([w (array u32 64)]
|
|
23
|
+
[a (@ (-> s state) 0)] [b (@ (-> s state) 1)] [c (@ (-> s state) 2)] [d (@ (-> s state) 3)]
|
|
24
|
+
[e (@ (-> s state) 4)] [f (@ (-> s state) 5)] [g (@ (-> s state) 6)] [hh (@ (-> s state) 7)])
|
|
25
|
+
(for ([i u32 0]) (< i 16) (+= i 1) (set! (@ w i) (word (+ p (* i 4)))))
|
|
26
|
+
(for ([i u32 16]) (< i 64) (+= i 1)
|
|
27
|
+
(let ([x (@ w (- i 15))] [y (@ w (- i 2))])
|
|
28
|
+
(set! (@ w i) (+ (@ w (- i 16)) (bit-xor (rotr x 7) (rotr x 18) (>> x 3)) (@ w (- i 7))
|
|
29
|
+
(bit-xor (rotr y 17) (rotr y 19) (>> y 10))))))
|
|
30
|
+
(for ([i u32 0]) (< i 64) (+= i 1)
|
|
31
|
+
(let* ([t1 (+ hh (bit-xor (rotr e 6) (rotr e 11) (rotr e 25)) (bit-xor (bit-and e f) (bit-and (bit-not e) g))
|
|
32
|
+
(@ k i) (@ w i))]
|
|
33
|
+
[t2 (+ (bit-xor (rotr a 2) (rotr a 13) (rotr a 22)) (bit-xor (bit-and a b) (bit-and a c) (bit-and b c)))])
|
|
34
|
+
(set! hh g)
|
|
35
|
+
(set! g f)
|
|
36
|
+
(set! f e)
|
|
37
|
+
(set! e (+ d t1))
|
|
38
|
+
(set! d c)
|
|
39
|
+
(set! c b)
|
|
40
|
+
(set! b a)
|
|
41
|
+
(set! a (+ t1 t2))))
|
|
42
|
+
(+= (@ (-> s state) 0) a)
|
|
43
|
+
(+= (@ (-> s state) 1) b)
|
|
44
|
+
(+= (@ (-> s state) 2) c)
|
|
45
|
+
(+= (@ (-> s state) 3) d)
|
|
46
|
+
(+= (@ (-> s state) 4) e)
|
|
47
|
+
(+= (@ (-> s state) 5) f)
|
|
48
|
+
(+= (@ (-> s state) 6) g)
|
|
49
|
+
(+= (@ (-> s state) 7) hh)))
|
|
50
|
+
|
|
51
|
+
(define (sha256-init! [s (ptr sha256)])
|
|
52
|
+
(set! (@ (-> s state) 0) #x6a09e667)
|
|
53
|
+
(set! (@ (-> s state) 1) #xbb67ae85)
|
|
54
|
+
(set! (@ (-> s state) 2) #x3c6ef372)
|
|
55
|
+
(set! (@ (-> s state) 3) #xa54ff53a)
|
|
56
|
+
(set! (@ (-> s state) 4) #x510e527f)
|
|
57
|
+
(set! (@ (-> s state) 5) #x9b05688c)
|
|
58
|
+
(set! (@ (-> s state) 6) #x1f83d9ab)
|
|
59
|
+
(set! (@ (-> s state) 7) #x5be0cd19)
|
|
60
|
+
(set! (-> s filled) 0)
|
|
61
|
+
(set! (-> s length) 0))
|
|
62
|
+
|
|
63
|
+
(define (sha256-add! [s (ptr sha256)] [b (slice u8)])
|
|
64
|
+
(let ([p (-> b items)] [n (-> b length)] [i u32 0])
|
|
65
|
+
(+= (-> s length) (cast u64 n))
|
|
66
|
+
(when (> (-> s filled) 0)
|
|
67
|
+
(while (and (< i n) (< (-> s filled) 64))
|
|
68
|
+
(set! (@ (-> s block) (-> s filled)) (@ p i))
|
|
69
|
+
(+= (-> s filled) 1)
|
|
70
|
+
(+= i 1))
|
|
71
|
+
(when (== (-> s filled) 64)
|
|
72
|
+
(compress! s (-> s block))
|
|
73
|
+
(set! (-> s filled) 0)))
|
|
74
|
+
(while (<= (+ i 64) n)
|
|
75
|
+
(compress! s (+ p i))
|
|
76
|
+
(+= i 64))
|
|
77
|
+
(while (< i n)
|
|
78
|
+
(set! (@ (-> s block) (-> s filled)) (@ p i))
|
|
79
|
+
(+= (-> s filled) 1)
|
|
80
|
+
(+= i 1))))
|
|
81
|
+
|
|
82
|
+
;; into takes the 32 bytes of the digest.
|
|
83
|
+
(define (sha256-end! [s (ptr sha256)] [into (slice u8)])
|
|
84
|
+
(let ([bits (* (-> s length) 8)])
|
|
85
|
+
(set! (@ (-> s block) (-> s filled)) 128)
|
|
86
|
+
(+= (-> s filled) 1)
|
|
87
|
+
(when (> (-> s filled) 56)
|
|
88
|
+
(while (< (-> s filled) 64)
|
|
89
|
+
(set! (@ (-> s block) (-> s filled)) 0)
|
|
90
|
+
(+= (-> s filled) 1))
|
|
91
|
+
(compress! s (-> s block))
|
|
92
|
+
(set! (-> s filled) 0))
|
|
93
|
+
(while (< (-> s filled) 56)
|
|
94
|
+
(set! (@ (-> s block) (-> s filled)) 0)
|
|
95
|
+
(+= (-> s filled) 1))
|
|
96
|
+
(for ([i u32 0]) (< i 8) (+= i 1)
|
|
97
|
+
(set! (@ (-> s block) (+ 56 i)) (cast u8 (>> bits (* 8 (- 7 i))))))
|
|
98
|
+
(compress! s (-> s block))
|
|
99
|
+
(for ([i u32 0]) (< i 8) (+= i 1)
|
|
100
|
+
(let ([h (@ (-> s state) i)])
|
|
101
|
+
(set! (@ into (* i 4)) (cast u8 (>> h 24)))
|
|
102
|
+
(set! (@ into (+ (* i 4) 1)) (cast u8 (>> h 16)))
|
|
103
|
+
(set! (@ into (+ (* i 4) 2)) (cast u8 (>> h 8)))
|
|
104
|
+
(set! (@ into (+ (* i 4) 3)) (cast u8 h))))))
|
|
105
|
+
|
|
106
|
+
(define (sha256-of [b (slice u8)] [into (slice u8)])
|
|
107
|
+
(let ([s sha256])
|
|
108
|
+
(sha256-init! (& s))
|
|
109
|
+
(sha256-add! (& s) b)
|
|
110
|
+
(sha256-end! (& s) into)))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
;; Substrate in one module: the language, its runtime and its library.
|
|
2
2
|
|
|
3
|
-
(provide define struct union variant match exception throw try lambda inst typedef const let let* set!
|
|
3
|
+
(provide define struct union variant enum match exception throw try lambda inst typedef const let let* set!
|
|
4
4
|
if return values import supply
|
|
5
5
|
#%datum #%top-interaction #%module-begin
|
|
6
6
|
when unless cond case while for break continue rethrow and or not cast sizeof offsetof array-of slice @ & ->
|
|
@@ -8,12 +8,13 @@
|
|
|
8
8
|
+= -= *= /= %= <<= >>= bit-and= bit-or= bit-xor=
|
|
9
9
|
heap-start sbrk reset-stack!
|
|
10
10
|
host-write host-trap host-args host-os host-exit host-instantiate host-export-index
|
|
11
|
-
host-program-modules host-module-bytes handler event-head untagged-handler! trap-handler!
|
|
11
|
+
host-program-modules host-module-bytes host-compiled-file handler event-head untagged-handler! trap-handler!
|
|
12
|
+
printf print-bytes
|
|
12
13
|
output-to! test expect expect-equal test-failed test-skipped
|
|
13
14
|
buffer-add-entries! entry-strings
|
|
14
15
|
sqrt fabs floor ceil trunc nearbyint copysign sqrtf fabsf floorf ceilf truncf nearbyintf copysignf
|
|
15
16
|
malloc calloc realloc free try-malloc try-calloc try-realloc memcpy memset memcmp
|
|
16
|
-
arena make-arena arena-alloc arena-start! arena-free new
|
|
17
|
+
arena make-arena arena-alloc arena-start! arena-free new copy
|
|
17
18
|
buffer make-buffer buffer-add! buffer-add-byte! buffer-add-string! buffer-add-utf-8! buffer-add-u32! buffer-add-f32!
|
|
18
19
|
buffer-bytes buffer-string
|
|
19
20
|
buffer-reserve buffer-free! buffer-trim! hash-bytes hash-table hash-ref hash-set! hash-clear! hash-free!
|
|
@@ -24,9 +25,9 @@
|
|
|
24
25
|
;; ---- the forms ----
|
|
25
26
|
|
|
26
27
|
(define-syntax forms (quote-syntax (#%form forms)))
|
|
27
|
-
(forms #%module-begin #%top-interaction define struct union variant match exception
|
|
28
|
+
(forms #%module-begin #%top-interaction define struct union variant enum match exception
|
|
28
29
|
throw try lambda inst substrate-struct-check typedef const let let* #%datum when unless cond case array-of slice
|
|
29
|
-
while for cast sizeof offsetof -> & set! @ break continue rethrow new printf test expect expect-equal
|
|
30
|
+
while for cast sizeof offsetof -> & set! @ break continue rethrow new copy printf test expect expect-equal
|
|
30
31
|
+ - * / % == != < <= > >= and or not bit-and bit-or bit-xor bit-not << >>
|
|
31
32
|
+= -= *= /= %= <<= >>= bit-and= bit-or= bit-xor=)
|
|
32
33
|
|
|
@@ -43,6 +44,7 @@
|
|
|
43
44
|
(constant (const NAME TYPE VALUE))
|
|
44
45
|
(type (struct NAME FIELD ...))
|
|
45
46
|
(type (variant NAME CASE ...))
|
|
47
|
+
(type (enum NAME CASE ...))
|
|
46
48
|
(type (typedef NAME TYPE))
|
|
47
49
|
(exception (exception NAME TYPE ...))
|
|
48
50
|
(macro (define-syntax NAME _))
|
|
@@ -98,6 +100,7 @@
|
|
|
98
100
|
(import export_index "host" "export_index" (i32 i32 i32 i32 -> i32))
|
|
99
101
|
(import program_modules "host" "program_modules" (i32 -> i32))
|
|
100
102
|
(import module_bytes "host" "module_bytes" (i32 i32 i32 -> i32))
|
|
103
|
+
(import compiled_file "host" "compiled_file" (i32 i32 i32 -> i32))
|
|
101
104
|
|
|
102
105
|
(define (host-write [fd i32] [b (slice u8)]) #:inline -> i32 (write fd (cast i32 (-> b items)) (cast i32 (-> b length))))
|
|
103
106
|
(define (host-trap [s string]) #:inline (trap (cast i32 (-> s bytes)) (cast i32 (-> s length))))
|
|
@@ -142,6 +145,9 @@
|
|
|
142
145
|
(define (host-module-bytes [name string]) -> (slice u8)
|
|
143
146
|
(let* ([n u32 0] [p (module_bytes (cast i32 (-> name bytes)) (cast i32 (-> name length)) (cast i32 (& n)))])
|
|
144
147
|
(slice (cast (ptr u8) p) n)))
|
|
148
|
+
(define (host-compiled-file [name string]) -> (slice u8)
|
|
149
|
+
(let* ([n u32 0] [p (compiled_file (cast i32 (-> name bytes)) (cast i32 (-> name length)) (cast i32 (& n)))])
|
|
150
|
+
(slice (cast (ptr u8) p) n)))
|
|
145
151
|
|
|
146
152
|
;; ---- output ----
|
|
147
153
|
|
|
@@ -178,10 +184,7 @@
|
|
|
178
184
|
|
|
179
185
|
;; ---- strings and slices ----
|
|
180
186
|
|
|
181
|
-
(define (string-copy [s string]) -> string
|
|
182
|
-
(let ([p (cast (ptr u8) (malloc (-> s length)))])
|
|
183
|
-
(memcpy p (-> s bytes) (-> s length))
|
|
184
|
-
(cast string (slice p (-> s length)))))
|
|
187
|
+
(define (string-copy [s string]) -> string (copy 0 s))
|
|
185
188
|
|
|
186
189
|
;; The checker's code calls these to compare strings by their bytes, and to trap on an index or a part out of range.
|
|
187
190
|
|
|
@@ -972,7 +975,7 @@
|
|
|
972
975
|
(+ ten-powers (* 2 (+ q 348))))
|
|
973
976
|
|
|
974
977
|
(define (make-ten-powers) -> (ptr u64)
|
|
975
|
-
(let* ([t (
|
|
978
|
+
(let* ([t (-> (new 0 u64 1392) items)] [limbs (array u64 44)] [x (slice limbs)])
|
|
976
979
|
(memset limbs 0 352)
|
|
977
980
|
(set! (@ x 0) 1)
|
|
978
981
|
(for ([q 0]) (<= q 347) (+= q 1)
|
|
@@ -1015,10 +1018,7 @@
|
|
|
1015
1018
|
[else (bit-or (<< (cast u64 (+ e2 1075)) 52) (- mant 4503599627370496))])))
|
|
1016
1019
|
|
|
1017
1020
|
;; A number is 32-bit limbs, least significant first, each in a u64.
|
|
1018
|
-
(define (big-new [a (ptr arena)] [len u32]) -> (slice u64)
|
|
1019
|
-
(let ([x (cast (ptr u64) (arena-alloc a (* 8 len)))])
|
|
1020
|
-
(memset x 0 (* 8 len))
|
|
1021
|
-
(slice x len)))
|
|
1021
|
+
(define (big-new [a (ptr arena)] [len u32]) -> (slice u64) (new a u64 len))
|
|
1022
1022
|
|
|
1023
1023
|
(define (big-mul-add! [x (slice u64)] [k u64] [c u64])
|
|
1024
1024
|
(for ([i u32 0]) (< i (-> x length)) (+= i 1)
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
(define (in-run-arena?) -> bool (== current (& run-arena)))
|
|
91
91
|
|
|
92
92
|
(define (begin-module-arena)
|
|
93
|
-
(let ([m (
|
|
93
|
+
(let ([m (new 0 module-arena)])
|
|
94
94
|
(set! (-> m arena) (make-arena))
|
|
95
95
|
(set! (-> m outer) innermost)
|
|
96
96
|
(set! innermost m)
|
|
@@ -302,7 +302,7 @@
|
|
|
302
302
|
|
|
303
303
|
;; ---- tables in an arena ----
|
|
304
304
|
(define (make-table) -> (ptr hash-table)
|
|
305
|
-
(let ([t (
|
|
305
|
+
(let ([t (new current hash-table)])
|
|
306
306
|
(set! (-> t arena) current)
|
|
307
307
|
t))
|
|
308
308
|
|
|
@@ -322,7 +322,7 @@
|
|
|
322
322
|
(set! (-> e value) value)
|
|
323
323
|
(return))
|
|
324
324
|
(set! e (-> e next)))
|
|
325
|
-
(set! e (
|
|
325
|
+
(set! e (new (-> t arena) entry))
|
|
326
326
|
(set! (-> e key) key)
|
|
327
327
|
(set! (-> e value) value)
|
|
328
328
|
(set! (-> e next) first)
|
|
@@ -341,10 +341,7 @@
|
|
|
341
341
|
(define symbols hash-table)
|
|
342
342
|
(define keywords hash-table)
|
|
343
343
|
|
|
344
|
-
(define (kept-text [s string]) -> string
|
|
345
|
-
(let ([p (cast (ptr u8) (arena-alloc (& run-arena) (-> s length)))])
|
|
346
|
-
(memcpy p (-> s bytes) (-> s length))
|
|
347
|
-
(cast string (slice p (-> s length)))))
|
|
344
|
+
(define (kept-text [s string]) -> string (copy (& run-arena) s))
|
|
348
345
|
|
|
349
346
|
(define (held-text [s string]) -> string
|
|
350
347
|
(let ([p (held-bytes (-> s length))])
|
|
@@ -519,11 +516,7 @@
|
|
|
519
516
|
;; ---- changes to scopes ----
|
|
520
517
|
|
|
521
518
|
(define (new-change [sc u32] [kind u32] [next (ptr change)]) -> (ptr change)
|
|
522
|
-
(
|
|
523
|
-
(set! (-> c scope) sc)
|
|
524
|
-
(set! (-> c kind) kind)
|
|
525
|
-
(set! (-> c next) next)
|
|
526
|
-
c))
|
|
519
|
+
(new current (change #:scope sc #:kind kind #:next next)))
|
|
527
520
|
|
|
528
521
|
(define (changes-add [cs (ptr change)] [sc u32] [kind u32]) -> (ptr change)
|
|
529
522
|
(cond [(== cs 0) (new-change sc kind 0)]
|
|
@@ -600,13 +593,7 @@
|
|
|
600
593
|
(make-cell (syntax e scopes loc props 0)))
|
|
601
594
|
|
|
602
595
|
(define (make-srcloc [source datum] [line u32] [col u32] [pos u32] [span u32]) -> (ptr srcloc)
|
|
603
|
-
(
|
|
604
|
-
(set! (-> l source) source)
|
|
605
|
-
(set! (-> l line) line)
|
|
606
|
-
(set! (-> l col) col)
|
|
607
|
-
(set! (-> l pos) pos)
|
|
608
|
-
(set! (-> l span) span)
|
|
609
|
-
l))
|
|
596
|
+
(new current (srcloc #:source source #:line line #:col col #:pos pos #:span span)))
|
|
610
597
|
|
|
611
598
|
(define (syntax-e [s datum]) #:copied -> datum
|
|
612
599
|
(match (cell-of s)
|
|
@@ -730,7 +717,7 @@
|
|
|
730
717
|
(define (keep-srcloc [l (ptr srcloc)]) -> (ptr srcloc)
|
|
731
718
|
(if (== l 0)
|
|
732
719
|
0
|
|
733
|
-
(let ([kept (
|
|
720
|
+
(let ([kept (new (& run-arena) srcloc)])
|
|
734
721
|
(set! (@ kept) (@ l))
|
|
735
722
|
kept)))
|
|
736
723
|
|
|
@@ -1098,7 +1085,7 @@
|
|
|
1098
1085
|
(define (deserialize [bytes (ptr u8)] [n u32]) -> (ptr datum)
|
|
1099
1086
|
(set! in-bytes bytes)
|
|
1100
1087
|
(set! in-at 0)
|
|
1101
|
-
(let* ([count (cast u32 (in-uleb))] [objs (
|
|
1088
|
+
(let* ([count (cast u32 (in-uleb))] [objs (-> (new current u32 (+ count 1)) items)])
|
|
1102
1089
|
(for ([i u32 0]) (< i count) (+= i 1) (set! (@ objs i) (in-entry objs)))
|
|
1103
1090
|
(cast (ptr datum) objs)))
|
|
1104
1091
|
|