substrate-lang 0.9.4 → 0.10.1
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/README.md +1 -1
- package/build/compiler/{binary.cdd2ffb408dd@0+0.wasm → binary.2d43b43d1600@0+0.wasm} +0 -0
- package/build/compiler/checker.4dd4556dd421@0+0.wasm +0 -0
- package/build/compiler/{compile.da85f9bc4478@0+0.wasm → compile.5d8f6407af2a@0+0.wasm} +0 -0
- package/build/compiler/{core.0410ffbdc488@0+0.wasm → core.f2defb75e00b@0+0.wasm} +0 -0
- package/build/compiler/expander.967ce443d379@0+0.wasm +0 -0
- package/build/compiler/fs.01b8aab4a9a8@0+0.wasm +0 -0
- package/build/compiler/{leb128.ba77430f659f@0+0.wasm → leb128.15d814b7b4f2@0+0.wasm} +0 -0
- package/build/compiler/{link.be6e641afa93@0+0.wasm → link.b826ea7c8f17@0+0.wasm} +0 -0
- package/build/compiler/{macros.b695763c0ca3@0+0.wasm → macros.b269e0c42784@0+0.wasm} +0 -0
- package/build/compiler/{main.cbbdf42e34c2@0+0.wasm → main.4fc52f204d54@0+0.wasm} +0 -0
- package/build/compiler/{ops.324f0a665fab@0+0.wasm → ops.515b5e05f646@0+0.wasm} +0 -0
- package/build/compiler/{path.1b5fd988b6f3@0+0.wasm → path.5a6286472cd4@0+0.wasm} +0 -0
- package/build/compiler/program +21 -21
- package/build/compiler/{prune.29dde307bdee@0+0.wasm → prune.406215c3e4f8@0+0.wasm} +0 -0
- package/build/compiler/reader.694b03770bf0@0+0.wasm +0 -0
- package/build/compiler/roots.cefd10e93684@0+0.wasm +0 -0
- package/build/compiler/{running.b99787c2d180@0+0.wasm → running.0d25dbaec018@0+0.wasm} +0 -0
- package/build/compiler/serialize.b0d82f3d63d2@0+0.wasm +0 -0
- package/build/compiler/{sha256.f6c742932dde@0+0.wasm → sha256.a6c32b04d799@0+0.wasm} +0 -0
- package/build/compiler/substrate.5ee5d0b4d3e7@0+0.wasm +0 -0
- package/build/compiler/{syntax.fadc832db29f@0+0.wasm → syntax.32f3e40b61c7@0+0.wasm} +0 -0
- package/build/compiler/{writer.550227768eb9@0+0.wasm → writer.00b7802cbe39@0+0.wasm} +0 -0
- package/build/sub/{base64.454b045156d2@0+0.wasm → base64.a26bdcf60a2d@0+0.wasm} +0 -0
- package/build/sub/build.459c5b9412bd@0+0.wasm +0 -0
- package/build/sub/chromium.3d5818f2707d@0+0.wasm +0 -0
- package/build/sub/common.1edc613607a0@0+0.wasm +0 -0
- package/build/sub/deflate.23f7c4679260@0+0.wasm +0 -0
- package/build/sub/doc.0775df5de6fe@0+0.wasm +0 -0
- package/build/sub/{doc.f18ad14060e9@0+0.wasm → doc.ef9965d5d402@0+0.wasm} +0 -0
- package/build/sub/env.e5451da6e747@0+0.wasm +0 -0
- package/build/sub/events.bf5473ebf220@0+0.wasm +0 -0
- package/build/sub/fetch.7790d4943758@0+0.wasm +0 -0
- package/build/sub/fetch.96b2d10f025e@0+0.wasm +0 -0
- package/build/sub/files.ad0469fdf6fa@0+0.wasm +0 -0
- package/build/sub/fs.01b8aab4a9a8@0+0.wasm +0 -0
- package/build/sub/git.dc4c0e757ebe@0+0.wasm +0 -0
- package/build/sub/grants.c54776c0d7e3@0+0.wasm +0 -0
- package/build/sub/gzip.16e372eda1cf@0+0.wasm +0 -0
- package/build/sub/hash.660682e4f491@0+0.wasm +0 -0
- package/build/sub/{html.0b0362932a75@0+0.wasm → html.a23126eb949a@0+0.wasm} +0 -0
- package/build/sub/{html.3b3c8d7d9971@0+0.wasm → html.e9ed37f34977@0+0.wasm} +0 -0
- package/build/sub/{inflate.3cfa17586072@0+0.wasm → inflate.59bb61f14001@0+0.wasm} +0 -0
- package/build/sub/json.55590d2f518a@0+0.wasm +0 -0
- package/build/sub/manifest.ef317480deb0@0+0.wasm +0 -0
- package/build/sub/{map.e582eae03ec2@0+0.wasm → map.f455cca6a42a@0+0.wasm} +0 -0
- package/build/sub/pack.e02836264f6a@0+0.wasm +0 -0
- package/build/sub/{path.1b5fd988b6f3@0+0.wasm → path.5a6286472cd4@0+0.wasm} +0 -0
- package/build/sub/path.6891ffea73ca@0+0.wasm +0 -0
- package/build/sub/process.7106571fa723@0+0.wasm +0 -0
- package/build/sub/program +48 -48
- package/build/sub/read.0b93933d62a2@0+0.wasm +0 -0
- package/build/sub/{reader.d256e69e09e2@0+0.wasm → reader.694b03770bf0@0+0.wasm} +0 -0
- package/build/sub/{root.02141d04d568@0+0.wasm → root.f10a4906f460@0+0.wasm} +0 -0
- package/build/sub/{roots.e366210c01d6@0+0.wasm → roots.cefd10e93684@0+0.wasm} +0 -0
- package/build/sub/{sha256.f6c742932dde@0+0.wasm → sha256.a6c32b04d799@0+0.wasm} +0 -0
- package/build/sub/{sha512.9fee24e95460@0+0.wasm → sha512.c24a792d7891@0+0.wasm} +0 -0
- package/build/sub/site.1732b58ec0e8@0+0.wasm +0 -0
- package/build/sub/site.ae3913b0b0f4@0+0.wasm +0 -0
- package/build/sub/store.a24d7a25daa6@0+0.wasm +0 -0
- package/build/sub/stream.126e3bd5d626@0+0.wasm +0 -0
- package/build/sub/sub.2e3092140706@0+0.wasm +0 -0
- package/build/sub/substrate.5ee5d0b4d3e7@0+0.wasm +0 -0
- package/build/sub/{syntax.fadc832db29f@0+0.wasm → syntax.32f3e40b61c7@0+0.wasm} +0 -0
- package/build/sub/tar.2a633861e654@0+0.wasm +0 -0
- package/build/sub/test.9bd59c73f65e@0+0.wasm +0 -0
- package/build/sub/{text.8ff142d72fd7@0+0.wasm → text.1bc90482bd43@0+0.wasm} +0 -0
- package/build/sub/{timer.d3454726b3bf@0+0.wasm → timer.f35eb62ae446@0+0.wasm} +0 -0
- package/build/sub/upgrade.39ee449b00d5@0+0.wasm +0 -0
- package/build/sub/{utf8.e82afeb9e953@0+0.wasm → utf8.e7216bd054e1@0+0.wasm} +0 -0
- package/build/sub/worker.762a9d642af0@0+0.wasm +0 -0
- package/build/sub/writer.00b7802cbe39@0+0.wasm +0 -0
- package/package.json +1 -1
- package/std/archive/tar.sub +30 -23
- package/std/browser/chromium.sub +5 -4
- package/std/browser/devtools.sub +24 -19
- package/std/compress/gzip.sub +18 -16
- package/std/compress/inflate.sub +7 -4
- package/std/crypto/password.sub +3 -3
- package/std/doc/doc.sub +2 -2
- package/std/encoding/json.sub +20 -8
- package/std/encoding/wire.sub +9 -7
- package/std/http/form.sub +2 -2
- package/std/http/multipart.sub +8 -10
- package/std/http/route.sub +9 -4
- package/std/http/server.sub +14 -11
- package/std/http/session.sub +2 -2
- package/std/http/static.sub +5 -5
- package/std/meta/derive.sub +0 -2
- package/std/meta/method.sub +41 -0
- package/std/meta/type-info.sub +30 -37
- package/std/package/files.sub +24 -25
- package/std/package/git.sub +26 -33
- package/std/package/hash.sub +8 -8
- package/std/package/manifest.sub +67 -42
- package/std/package/map.sub +1 -1
- package/std/package/pack.sub +13 -13
- package/std/package/read.sub +7 -6
- package/std/package/site.sub +7 -7
- package/std/package/store.sub +16 -12
- package/std/package.sub +7 -6
- package/std/test/browser.sub +9 -8
- package/std/test/build.sub +2 -2
- package/std/test/page.sub +31 -26
- package/std/test/run.sub +8 -7
- package/std/test/test.sub +12 -13
- package/std/vector/vector.sub +75 -0
- package/std/web/canvas.sub +3 -3
- package/std/web/dom.sub +45 -11
- package/std/web/gpu-commands.sub +439 -0
- package/std/web/gpu.sub +17 -424
- package/std/web/patches.sub +45 -10
- package/substrate/VERSION +1 -1
- package/substrate/compiler/checker.sub +40 -212
- package/substrate/compiler/compile.sub +3 -3
- package/substrate/compiler/expander.sub +32 -50
- package/substrate/compiler/main.sub +9 -9
- package/substrate/compiler/reader.sub +4 -4
- package/substrate/compiler/roots.sub +8 -8
- package/substrate/compiler/running.sub +1 -1
- package/substrate/compiler/serialize.sub +56 -49
- package/substrate/compiler/substrate.sub +53 -11
- package/substrate/host/errors.mjs +3 -2
- package/substrate/host/events.sub +3 -16
- package/substrate/host/fs.mjs +5 -4
- package/substrate/host/fs.sub +135 -102
- package/substrate/host/grants.mjs +1 -1
- package/substrate/host/grants.sub +8 -7
- package/substrate/host/modules/fake.mjs +1 -1
- package/substrate/host/modules/websocket.mjs +4 -4
- package/substrate/host/modules/websocket.sub +8 -6
- package/substrate/host/node/env.mjs +12 -6
- package/substrate/host/node/env.sub +21 -16
- package/substrate/host/node/fs.mjs +1 -1
- package/substrate/host/node/net.mjs +2 -2
- package/substrate/host/node/net.sub +13 -6
- package/substrate/host/node/process.mjs +4 -4
- package/substrate/host/node/process.sub +25 -24
- package/substrate/host/node/signal.mjs +3 -2
- package/substrate/host/node/signal.sub +9 -6
- package/substrate/host/node/watch.mjs +1 -1
- package/substrate/host/node/watch.sub +11 -9
- package/substrate/host/stream.sub +2 -0
- package/substrate/host/subhost-core.mjs +9 -1
- package/substrate/host/web/audio.mjs +17 -9
- package/substrate/host/web/audio.sub +9 -3
- package/substrate/host/web/clipboard.mjs +2 -2
- package/substrate/host/web/clipboard.sub +10 -3
- package/substrate/host/web/dom.mjs +165 -64
- package/substrate/host/web/dom.sub +9 -27
- package/substrate/host/web/files.mjs +2 -2
- package/substrate/host/web/files.sub +6 -2
- package/substrate/host/web/fs.mjs +3 -3
- package/substrate/host/web/gpu.mjs +63 -25
- package/substrate/host/web/gpu.sub +18 -4
- package/substrate/host/web/location.mjs +18 -2
- package/substrate/host/web/location.sub +19 -7
- package/substrate/host/worker-side.mjs +3 -1
- package/substrate/host/worker.mjs +6 -5
- package/substrate/host/worker.sub +10 -10
- package/build/compiler/checker.2b0ea87ed311@0+0.wasm +0 -0
- package/build/compiler/expander.80707e1666d6@0+0.wasm +0 -0
- package/build/compiler/fs.5017b627cbd2@0+0.wasm +0 -0
- package/build/compiler/reader.d256e69e09e2@0+0.wasm +0 -0
- package/build/compiler/roots.e366210c01d6@0+0.wasm +0 -0
- package/build/compiler/serialize.a12536bbbe9a@0+0.wasm +0 -0
- package/build/compiler/substrate.728c690187f2@0+0.wasm +0 -0
- package/build/sub/build.115aeefc15e8@0+0.wasm +0 -0
- package/build/sub/chromium.fc0bfea0fbe6@0+0.wasm +0 -0
- package/build/sub/common.997c21b0b8cf@0+0.wasm +0 -0
- package/build/sub/deflate.3138a38325a1@0+0.wasm +0 -0
- package/build/sub/doc.e3f9a998cd91@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.b0ce8f8b3da8@0+0.wasm +0 -0
- package/build/sub/fetch.d62aa5fc9623@0+0.wasm +0 -0
- package/build/sub/files.1706cc0941c0@0+0.wasm +0 -0
- package/build/sub/fs.5017b627cbd2@0+0.wasm +0 -0
- package/build/sub/git.1c5791236e35@0+0.wasm +0 -0
- package/build/sub/grants.cd99dff2854e@0+0.wasm +0 -0
- package/build/sub/gzip.9ebea150f218@0+0.wasm +0 -0
- package/build/sub/hash.ba8330dad9ff@0+0.wasm +0 -0
- package/build/sub/json.af2e0ae20084@0+0.wasm +0 -0
- package/build/sub/manifest.6e014ac19e5d@0+0.wasm +0 -0
- package/build/sub/pack.4295e4f5bdbd@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/read.279fafcda508@0+0.wasm +0 -0
- package/build/sub/site.76aa8286c257@0+0.wasm +0 -0
- package/build/sub/site.e6e415bc3170@0+0.wasm +0 -0
- package/build/sub/store.c48db3345968@0+0.wasm +0 -0
- package/build/sub/stream.27fd2fe858e1@0+0.wasm +0 -0
- package/build/sub/sub.c0fb7310de12@0+0.wasm +0 -0
- package/build/sub/substrate.728c690187f2@0+0.wasm +0 -0
- package/build/sub/tar.692c0e8827cd@0+0.wasm +0 -0
- package/build/sub/test.1fd2ff8123bf@0+0.wasm +0 -0
- package/build/sub/upgrade.2a9219e6a45d@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
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
;; ---- uses ----
|
|
10
10
|
|
|
11
|
-
(struct checking [phase i32] [counter i32] [
|
|
11
|
+
(struct checking [phase i32] [counter i32] [throwers (ptr hash-table)]
|
|
12
12
|
[strings (ptr hash-table)] [copies (ptr hash-table)] [layouts (ptr hash-table)] [types (ptr hash-table)]
|
|
13
13
|
[rethrown datum] [datum datum] [next (ptr checking)])
|
|
14
14
|
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
(define meaning-of (fn (datum) -> datum) 0)
|
|
24
24
|
(define inline-call-of (fn (datum datum) -> datum) 0)
|
|
25
25
|
(define inline-copy-of (fn (datum) -> datum) 0)
|
|
26
|
-
(define expand-head-of (fn (datum
|
|
27
|
-
(define scope-shape-of (fn (datum
|
|
28
|
-
(define apply-form-of (fn (datum datum
|
|
26
|
+
(define expand-head-of (fn (datum) -> datum) 0)
|
|
27
|
+
(define scope-shape-of (fn (datum) -> datum) 0)
|
|
28
|
+
(define apply-form-of (fn (datum datum) -> datum) 0)
|
|
29
29
|
(define prune-local-scopes (fn (datum) -> datum) 0)
|
|
30
30
|
(define facts-of (fn (datum) -> datum) 0)
|
|
31
31
|
(define datum-type-of (fn () -> datum) 0)
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
|
|
34
34
|
(define (set-expander! [meaning (fn (datum) -> datum)]
|
|
35
35
|
[inline-call (fn (datum datum) -> datum)] [inline-copy (fn (datum) -> datum)]
|
|
36
|
-
[head (fn (datum
|
|
37
|
-
[apply (fn (datum datum
|
|
36
|
+
[head (fn (datum) -> datum)] [shape (fn (datum) -> datum)]
|
|
37
|
+
[apply (fn (datum datum) -> datum)] [prune (fn (datum) -> datum)] [facts (fn (datum) -> datum)]
|
|
38
38
|
[quoted (fn () -> datum)] [syntax-function (fn (datum i32) -> datum)])
|
|
39
39
|
(set! meaning-of meaning)
|
|
40
40
|
(set! inline-call-of inline-call)
|
|
@@ -48,12 +48,10 @@
|
|
|
48
48
|
(set! syntax-function-of syntax-function)
|
|
49
49
|
(set-type-query! local-type-of))
|
|
50
50
|
|
|
51
|
-
(define
|
|
52
|
-
|
|
53
|
-
(define (expand-head [s datum]) -> datum (expand-head-of s (!= twice 0)))
|
|
51
|
+
(define (expand-head [s datum]) -> datum (expand-head-of s))
|
|
54
52
|
(define (expand-in [s datum] [env datum]) -> datum (set! scope-env env) (expand-head s))
|
|
55
|
-
(define (scope-shape! [m datum]) -> datum (scope-shape-of m
|
|
56
|
-
(define (apply-form! [t datum] [s datum]) -> datum (apply-form-of t s
|
|
53
|
+
(define (scope-shape! [m datum]) -> datum (scope-shape-of m))
|
|
54
|
+
(define (apply-form! [t datum] [s datum]) -> datum (apply-form-of t s))
|
|
57
55
|
|
|
58
56
|
(define (substrate-expansion [kind datum] [env datum] [s datum] [context datum] [states (ptr (ptr void))] [phase i32]) -> datum
|
|
59
57
|
(let ([outer-here here] [outer-state state] [outer-env scope-env] [out datum 0])
|
|
@@ -103,9 +101,7 @@
|
|
|
103
101
|
|
|
104
102
|
(define (checker-recover!)
|
|
105
103
|
(set! here 0)
|
|
106
|
-
(set! state 0)
|
|
107
|
-
(set! twice 0)
|
|
108
|
-
(set! type-arguments nil))
|
|
104
|
+
(set! state 0))
|
|
109
105
|
|
|
110
106
|
(define (state-at [states (ptr (ptr void))] [phase i32]) -> (ptr checking)
|
|
111
107
|
(let ([s (cast (ptr checking) (@ states))])
|
|
@@ -114,7 +110,6 @@
|
|
|
114
110
|
(set! s (new (current-arena) checking))
|
|
115
111
|
(set! (-> s phase) phase)
|
|
116
112
|
(set! (-> s counter) 0)
|
|
117
|
-
(set! (-> s instances) (make-table))
|
|
118
113
|
(set! (-> s throwers) (make-table))
|
|
119
114
|
(set! (-> s strings) (make-table))
|
|
120
115
|
(set! (-> s copies) (make-table))
|
|
@@ -254,11 +249,7 @@
|
|
|
254
249
|
`(,(car t) ,(for/list ([u (cadr t)]) (shown-as u full))
|
|
255
250
|
,@(if (== (caddr t) 'void) nil `(-> ,(shown-as (caddr t) full))))]
|
|
256
251
|
[(array-type? t) `(array ,(shown-as (cadr t) full) ,(caddr t))]
|
|
257
|
-
[(struct-type? t)
|
|
258
|
-
(let ([name (if full (cadr t) (caddr t))])
|
|
259
|
-
(if (pair? (cdddr t)) (cons name (for/list ([u (cadddr t)]) (shown-as u full))) name))]
|
|
260
|
-
[(enum-type? t) (if full (cadr t) (caddr t))]
|
|
261
|
-
[(and (pair? t) (== (car t) 'tvar)) (cadr t)]
|
|
252
|
+
[(or (struct-type? t) (enum-type? t)) (if full (cadr t) (caddr t))]
|
|
262
253
|
[(values-type? t) (cons 'values (for/list ([u (cdr t)]) (shown-as u full)))]
|
|
263
254
|
[(== t 'none) 'void]
|
|
264
255
|
[else (settled-type t)]))
|
|
@@ -267,25 +258,11 @@
|
|
|
267
258
|
(let ([a (shown t)] [b (shown u)])
|
|
268
259
|
(if (equal? a b) `(,(shown-as t #t) ,(shown-as u #t)) `(,a ,b))))
|
|
269
260
|
|
|
270
|
-
(define type-arguments datum nil)
|
|
271
|
-
|
|
272
|
-
(define (type-variables [ps datum]) -> datum (for/list ([p ps]) (cons p `(tvar ,p))))
|
|
273
|
-
|
|
274
|
-
(define (parse-types-with [s datum] [ts datum]) -> datum
|
|
275
|
-
(let ([saved type-arguments] [r datum 0])
|
|
276
|
-
(set! type-arguments s)
|
|
277
|
-
(set! r (try (for/list ([t ts]) (parse-type t)) [catch-all (set! type-arguments saved) (rethrow)]))
|
|
278
|
-
(set! type-arguments saved)
|
|
279
|
-
r))
|
|
280
|
-
|
|
281
261
|
(define (parse-type [s datum]) -> datum
|
|
282
262
|
(syntax-match s
|
|
283
263
|
[('quote t) (syntax->datum t)]
|
|
284
264
|
[(? identifier? x)
|
|
285
|
-
(
|
|
286
|
-
(cond [bound (cdr bound)]
|
|
287
|
-
[(memq (syntax-e x) '(void i8 u8 i16 u16 i32 u32 i64 u64 f32 f64 exnref bool string)) (syntax-e x)]
|
|
288
|
-
[else (named-type x)]))]
|
|
265
|
+
(if (memq (syntax-e x) '(void i8 u8 i16 u16 i32 u32 i64 u64 f32 f64 exnref bool string)) (syntax-e x) (named-type x))]
|
|
289
266
|
[('ptr t) `(ptr ,(parse-type t))]
|
|
290
267
|
[('slice t)
|
|
291
268
|
(let ([u (kept! (parse-type t) t)])
|
|
@@ -302,22 +279,11 @@
|
|
|
302
279
|
[('values t ...)
|
|
303
280
|
(when (null? t) (substrate-error s "expected a type" nil))
|
|
304
281
|
`(values ,@(for/list ([u t]) (scalar! (parse-type u) u)))]
|
|
305
|
-
[((? identifier? h) a ...) (applied-type s h a)]
|
|
306
282
|
[_ (substrate-error s "expected a type" nil)]))
|
|
307
283
|
|
|
308
|
-
(define (
|
|
309
|
-
(let ([v (type-binding h)])
|
|
310
|
-
(unless (and v (== (car v) 'substrate-struct) (pair? (parameters-of v)))
|
|
311
|
-
(substrate-error h "~a is not a type that takes types" `(,(syntax-e h))))
|
|
312
|
-
(unless (== (length a) (length (parameters-of v)))
|
|
313
|
-
(substrate-error s "~a takes ~a type~a, not ~a"
|
|
314
|
-
`(,(syntax-e h) ,(fixnum (length (parameters-of v))) ,(plural (length (parameters-of v))) ,(fixnum (length a)))))
|
|
315
|
-
`(struct ,(identifier-name h) ,(cadr v) ,(for/list ([t a]) (kept! (complete! (parse-type t) t) t)))))
|
|
284
|
+
(define (numbers-of [v datum]) -> datum (if (> (length v) 4) (list-ref v 4) 0))
|
|
316
285
|
|
|
317
|
-
|
|
318
|
-
(define (numbers-of [v datum]) -> datum (if (> (length v) 5) (list-ref v 5) 0))
|
|
319
|
-
|
|
320
|
-
;; A type's compile-time value: (substrate-struct name (field ...) kind (parameter ...)) or
|
|
286
|
+
;; A type's compile-time value: (substrate-struct name (field ...) kind), with an enum's case numbers after the kind, or
|
|
321
287
|
;; (substrate-typedef type).
|
|
322
288
|
(define (type-binding [x datum]) -> datum
|
|
323
289
|
(if (== (identifier-binding-kind x) 'compile-time-value) (type-value (syntax-local-value x)) 0))
|
|
@@ -328,9 +294,9 @@
|
|
|
328
294
|
known
|
|
329
295
|
(let* ([l (syntax->list v)]
|
|
330
296
|
[t datum (syntax-match (if (!= l 0) l nil)
|
|
331
|
-
[('substrate-struct n fs k
|
|
332
|
-
[('substrate-struct n fs k (
|
|
333
|
-
`(substrate-struct ,(syntax-e n) ,fs ,(syntax-e k) ,(for/list ([
|
|
297
|
+
[('substrate-struct n fs k) `(substrate-struct ,(syntax-e n) ,fs ,(syntax-e k))]
|
|
298
|
+
[('substrate-struct n fs k (x ...))
|
|
299
|
+
`(substrate-struct ,(syntax-e n) ,fs ,(syntax-e k) ,(for/list ([y x]) (syntax-e y)))]
|
|
334
300
|
[('substrate-typedef t) `(substrate-typedef ,(syntax->datum t))]
|
|
335
301
|
[_ 0])])
|
|
336
302
|
(when (!= t 0) (hash-set! (-> state types) (cast u64 v) (cast u32 t)))
|
|
@@ -340,7 +306,6 @@
|
|
|
340
306
|
(let ([v (type-binding x)])
|
|
341
307
|
(when (== v 0) (substrate-error x "~a is not a type" `(,(syntax-e x))))
|
|
342
308
|
(cond [(== (car v) 'substrate-typedef) (cadr v)]
|
|
343
|
-
[(pair? (parameters-of v)) (substrate-error x "~a takes types: write (~a type ...)" `(,(syntax-e x) ,(syntax-e x)))]
|
|
344
309
|
[(!= (numbers-of v) 0) `(enum ,(identifier-name x) ,(cadr v))]
|
|
345
310
|
[else `(struct ,(identifier-name x) ,(cadr v))])))
|
|
346
311
|
|
|
@@ -348,15 +313,11 @@
|
|
|
348
313
|
(syntax-match s
|
|
349
314
|
[(? identifier? x) (or (memq (syntax-e x) '(i8 u8 i16 u16 i32 u32 i64 u64 f32 f64 bool string)) (type-binding x))]
|
|
350
315
|
[('slice t) (type-syntax? t)]
|
|
351
|
-
[((? identifier? h) a ...)
|
|
352
|
-
(or (memq (syntax-e h) '(ptr array fn closure))
|
|
353
|
-
(let ([v (type-binding h)])
|
|
354
|
-
(and v (== (car v) 'substrate-struct) (pair? (parameters-of v))
|
|
355
|
-
(not (ormap (lambda ([x datum]) -> bool (keyword? (syntax-e x))) a)))))]
|
|
316
|
+
[((? identifier? h) a ...) (!= (memq (syntax-e h) '(ptr array fn closure)) 0)]
|
|
356
317
|
[_ #f]))
|
|
357
318
|
|
|
358
319
|
(define (scalar! [t datum] [where datum]) -> datum
|
|
359
|
-
(unless (or (arithmetic? t) (address-type? t) (== t 'exnref) (== t 'bool) (view-type? t) (enum-type? t)
|
|
320
|
+
(unless (or (arithmetic? t) (address-type? t) (== t 'exnref) (== t 'bool) (view-type? t) (enum-type? t))
|
|
360
321
|
(substrate-error where "expected a number or pointer type, not ~s" `(,(shown t))))
|
|
361
322
|
t)
|
|
362
323
|
|
|
@@ -401,15 +362,12 @@
|
|
|
401
362
|
(let ([known (datum-get (-> state layouts) (cdr t))])
|
|
402
363
|
(when (!= known 0) (return known))
|
|
403
364
|
(let* ([v (type-value (syntax-local-value (name-identifier (cadr t))))] [items (syntax->list (caddr v))]
|
|
404
|
-
[
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
`(,(fixnum (round-up (fixnum-value (car r)) (fixnum-value (cadr r)))) ,(cadr r) ,(caddr r))))
|
|
411
|
-
[catch-all (set! type-arguments saved) (rethrow)]))
|
|
412
|
-
(set! type-arguments saved)
|
|
365
|
+
[l (begin
|
|
366
|
+
(datum-put! (-> state layouts) (cdr t) 'laying-out)
|
|
367
|
+
(if (memq (cadddr v) '(variant enum))
|
|
368
|
+
(variant-layout items)
|
|
369
|
+
(let ([r (lay-out items (== (cadddr v) 'union))])
|
|
370
|
+
`(,(fixnum (round-up (fixnum-value (car r)) (fixnum-value (cadr r)))) ,(cadr r) ,(caddr r)))))])
|
|
413
371
|
(datum-put! (-> state layouts) (cdr t) l)
|
|
414
372
|
l)))
|
|
415
373
|
|
|
@@ -444,8 +402,6 @@
|
|
|
444
402
|
|
|
445
403
|
(define (substrate-define [s datum]) -> datum
|
|
446
404
|
(syntax-match s
|
|
447
|
-
[(_ #:forall ((? identifier? p) ...) ((? identifier? f) ((? identifier? x) t) ...) rest ...)
|
|
448
|
-
(let ([r (result-and-body rest)]) (generic s p f x t (car r) (cdr r)))]
|
|
449
405
|
[(_ ((? identifier? f) ((? identifier? x) t) ...) (? placement? k) rest ...)
|
|
450
406
|
(let ([r (result-and-body rest)]) (function s f x t (car r) (cdr r) f k))]
|
|
451
407
|
[(_ ((? identifier? f) ((? identifier? x) t) ...) rest ...)
|
|
@@ -472,11 +428,6 @@
|
|
|
472
428
|
,(at s (syn `(#%checked body ,definer (,@xs) ,(if (!= to 0) to '#f) (quote ,(cons rt ps)) ,@body))))))
|
|
473
429
|
(#%fact ,f (quote (substrate-function ,ps ,rt)))))))
|
|
474
430
|
|
|
475
|
-
(define (generic [s datum] [ps datum] [f datum] [xs datum] [ts datum] [r datum] [body datum]) -> datum
|
|
476
|
-
(parse-types-with (type-variables (for/list ([p ps]) (syntax-e p))) (cons r ts))
|
|
477
|
-
(syn `(define-syntax ,f
|
|
478
|
-
(quote-syntax (#%form mark (#%substrate-generic (,f (,@ps) (,@(for/list ([x xs] [t ts]) `(,x ,t))) ,r (,@body) ,s)))))))
|
|
479
|
-
|
|
480
431
|
(define (global-definition [s datum] [x datum] [t datum] [init datum]) -> datum
|
|
481
432
|
(let ([ty (kept! (complete! (parse-type t) t) t)])
|
|
482
433
|
(syn `(begin
|
|
@@ -545,12 +496,11 @@
|
|
|
545
496
|
|
|
546
497
|
(define (aggregate-type [s datum] [kind datum]) -> datum
|
|
547
498
|
(syntax-match s
|
|
548
|
-
[(_
|
|
549
|
-
[(_ (? identifier? name) field ...) (aggregate name field kind nil)]))
|
|
499
|
+
[(_ (? identifier? name) field ...) (aggregate name field kind)]))
|
|
550
500
|
|
|
551
|
-
(define (aggregate [name datum] [fields datum] [kind datum]
|
|
501
|
+
(define (aggregate [name datum] [fields datum] [kind datum]) -> datum
|
|
552
502
|
(distinct! (for/list ([f fields]) (syntax-match f [((? identifier? g) _) g] [_ (substrate-error f "expected [field type]" nil)])) '"field")
|
|
553
|
-
(syn `(begin (define-syntax ,name (quote-syntax (substrate-struct ,name (,@fields) ,kind
|
|
503
|
+
(syn `(begin (define-syntax ,name (quote-syntax (substrate-struct ,name (,@fields) ,kind)))
|
|
554
504
|
,(second-pass (syn `(substrate-struct-check ,name))))))
|
|
555
505
|
|
|
556
506
|
(define (distinct! [ids datum] [what datum])
|
|
@@ -561,10 +511,9 @@
|
|
|
561
511
|
|
|
562
512
|
(define (substrate-variant [s datum]) -> datum
|
|
563
513
|
(syntax-match s
|
|
564
|
-
[(_
|
|
565
|
-
[(_ (? identifier? name) c ...) (variant-form name c nil)]))
|
|
514
|
+
[(_ (? identifier? name) c ...) (variant-form name c)]))
|
|
566
515
|
|
|
567
|
-
(define (variant-form [name datum] [cs datum]
|
|
516
|
+
(define (variant-form [name datum] [cs datum]) -> datum
|
|
568
517
|
(let ([cases (for/list ([c cs])
|
|
569
518
|
(syntax-match c
|
|
570
519
|
[((? identifier? n) f ...)
|
|
@@ -574,7 +523,7 @@
|
|
|
574
523
|
[(? identifier? n) `(,n)]
|
|
575
524
|
[_ (substrate-error c "expected [case [field type] ...]" nil)]))])
|
|
576
525
|
(distinct! (for/list ([c cases]) (car c)) '"case")
|
|
577
|
-
(syn `(begin (define-syntax ,name (quote-syntax (substrate-struct ,name (,@(for/list ([c cases]) `(,@c))) variant
|
|
526
|
+
(syn `(begin (define-syntax ,name (quote-syntax (substrate-struct ,name (,@(for/list ([c cases]) `(,@c))) variant)))
|
|
578
527
|
,@(for/list ([c cases] [i (numbers-below (length cases))])
|
|
579
528
|
`(define-syntax ,(car c) (quote-syntax (#%form mark (#%substrate-construct ,name ,i ,(car c))))))
|
|
580
529
|
,(second-pass (syn `(substrate-struct-check ,name)))))))
|
|
@@ -582,7 +531,7 @@
|
|
|
582
531
|
(define (substrate-struct-check [s datum]) -> datum
|
|
583
532
|
(syntax-match s
|
|
584
533
|
[(_ name)
|
|
585
|
-
(
|
|
534
|
+
(layout (named-type name))
|
|
586
535
|
(syn '(begin))]))
|
|
587
536
|
|
|
588
537
|
(define (substrate-exception [s datum]) -> datum
|
|
@@ -775,9 +724,6 @@
|
|
|
775
724
|
[('offsetof)
|
|
776
725
|
(unless (and (== n 3) (identifier? (caddr l))) (substrate-error s "expected (offsetof type field)" nil))
|
|
777
726
|
(use `(,(piece 'type 0 (cadr l)) ,(piece 'name 0 (caddr l))))]
|
|
778
|
-
[('inst)
|
|
779
|
-
(unless (and (>= n 2) (identifier? (cadr l))) (substrate-error s "expected (inst generic type ...)" nil))
|
|
780
|
-
(use (cons (piece 'name 0 (cadr l)) (for/list ([t (cddr l)]) (piece 'type 0 t))))]
|
|
781
727
|
[('throw)
|
|
782
728
|
(unless (and (>= n 2) (identifier? (cadr l))) (substrate-error s "expected (throw exception value ...)" nil))
|
|
783
729
|
(use (cons (piece 'name 0 (cadr l)) (exprs-in 0 (cddr l))))]
|
|
@@ -1318,33 +1264,21 @@
|
|
|
1318
1264
|
(let* ([t (piece-at m 1)] [ty (parse-type t)])
|
|
1319
1265
|
(unless (struct-type? ty) (substrate-error t "~s is not a struct" `(,(shown ty))))
|
|
1320
1266
|
(cons 'lit (caddr (field-of ty (piece-at m 2)))))]
|
|
1321
|
-
[('inst) (check-inst s m)]
|
|
1322
1267
|
[('#%datum) (literal s (syntax-e (piece-at m 1)))]
|
|
1323
1268
|
[('new) (check-new m env)]
|
|
1324
1269
|
[('copy) (check-copy m env)]
|
|
1325
|
-
[else (check-marked s fenv (mark-arguments m) env
|
|
1270
|
+
[else (check-marked s fenv (mark-arguments m) env)]))))
|
|
1326
1271
|
|
|
1327
1272
|
(define (mark-arguments [m datum]) -> datum (if (== (car m) 'group) (pieces-from m 1) nil))
|
|
1328
1273
|
|
|
1329
|
-
(define (check-marked [s datum] [fenv datum] [args datum] [env datum]
|
|
1274
|
+
(define (check-marked [s datum] [fenv datum] [args datum] [env datum]) -> datum
|
|
1330
1275
|
(syntax-match fenv
|
|
1331
|
-
[('#%substrate-generic g)
|
|
1332
|
-
(if (pair? (syntax-e s))
|
|
1333
|
-
(check-generic-call s g args env hint)
|
|
1334
|
-
(syntax-match g [(f . _) (substrate-error s "~a is generic: give its types, (inst ~a type ...)" `(,(syntax-e f) ,(syntax-e f)))]))]
|
|
1335
1276
|
[('#%substrate-construct v i n)
|
|
1336
|
-
(let ([t (
|
|
1277
|
+
(let ([t (named-type v)])
|
|
1337
1278
|
(if (enum-type? t)
|
|
1338
1279
|
(begin (case-fields s t (syntax-e i) n args) (cons t (enum-constant t (syntax-e i))))
|
|
1339
1280
|
(cons t (construct s t i n args env (temp t)))))]))
|
|
1340
1281
|
|
|
1341
|
-
(define (check-inst [s datum] [m datum]) -> datum
|
|
1342
|
-
(let* ([f (piece-at m 1)] [h (expand-head f)])
|
|
1343
|
-
(syntax-match (if (== (car h) 'form) (caddr h) 0)
|
|
1344
|
-
[('#%substrate-generic g)
|
|
1345
|
-
(let ([i (instance g (for/list ([u (pieces-from m 2)]) (parse-type u)) s)]) (cons (cons 'fn (function-type i)) (function-ref i)))]
|
|
1346
|
-
[_ (substrate-error f "~a is not a generic function" `(,(syntax->datum f)))])))
|
|
1347
|
-
|
|
1348
1282
|
(define (check-core [name datum] [e datum] [env datum] [hint datum]) -> datum
|
|
1349
1283
|
(let ([m (if (== name 'let*) 0 (core-shape name e))])
|
|
1350
1284
|
(when (and (== m 0) (!= name 'let*)) (substrate-error e "~a is only allowed at module level" `(,name)))
|
|
@@ -1353,7 +1287,7 @@
|
|
|
1353
1287
|
[('#%app)
|
|
1354
1288
|
(let* ([f (piece-at m 1)] [fm (if (identifier? f) (meaning-of f) 0)])
|
|
1355
1289
|
(if (literal-head? f fm)
|
|
1356
|
-
(check-literal e f (cddr (syntax->list e)) env
|
|
1290
|
+
(check-literal e f (cddr (syntax->list e)) env)
|
|
1357
1291
|
(check-call e f (callee f fm env) (pieces-from m 2) env)))]
|
|
1358
1292
|
[('quote) (cons (datum-type) `(quote ,(syntax->datum (piece-at m 1))))]
|
|
1359
1293
|
[('quote-syntax) (cons (datum-type) `(quote ,(syntax-local-introduce (prune-local-scopes (piece-at m 1)))))]
|
|
@@ -1714,89 +1648,10 @@
|
|
|
1714
1648
|
(case (car p)
|
|
1715
1649
|
[('call) (cadr (cadddr p))]
|
|
1716
1650
|
[('array) (array-of-type (cadr p) (caddr p))]
|
|
1717
|
-
[else (
|
|
1651
|
+
[else (let ([t (named-type (cadr p))]) (if (enum-type? t) 0 t))])))
|
|
1718
1652
|
|
|
1719
1653
|
(define (temp [t datum]) -> datum (address (frame-place t (frame-slot! t)) 0))
|
|
1720
1654
|
|
|
1721
|
-
;; ---- generics ----
|
|
1722
|
-
|
|
1723
|
-
(define (check-generic-call [e datum] [g datum] [args datum] [env datum] [hint datum]) -> datum
|
|
1724
|
-
(syntax-match g
|
|
1725
|
-
[(f (p ...) ((x a) ...) r _ _)
|
|
1726
|
-
(let* ([ps (for/list ([q p]) (syntax-e q))]
|
|
1727
|
-
[s (begin (set! twice (+ twice 1)) (infer e (parse-types-with (type-variables ps) a) args env))]
|
|
1728
|
-
[i (instance g (for/list ([q ps]) (bound-type e s q (syntax-e f))) e)]
|
|
1729
|
-
[r (check-call e i `(,(function-type i) #f direct ,(info-of i 'func "a function")) args env)])
|
|
1730
|
-
(set! twice (- twice 1))
|
|
1731
|
-
r)]))
|
|
1732
|
-
|
|
1733
|
-
(define (infer [e datum] [ts datum] [args datum] [env datum]) -> datum
|
|
1734
|
-
(unless (== (length ts) (length args))
|
|
1735
|
-
(substrate-error e "expected ~a argument~a, got ~a" `(,(fixnum (length ts)) ,(plural (length ts)) ,(fixnum (length args)))))
|
|
1736
|
-
(infer-from ts args env (infer-from ts args env nil #f) #t))
|
|
1737
|
-
|
|
1738
|
-
(define (infer-from [ts datum] [args datum] [env datum] [s datum] [constants bool]) -> datum
|
|
1739
|
-
(cond [(null? ts) s]
|
|
1740
|
-
[(known-type? (car ts) s) (infer-from (cdr ts) (cdr args) env s constants)]
|
|
1741
|
-
[else
|
|
1742
|
-
(let ([r (check (car args) env 0)])
|
|
1743
|
-
(infer-from (cdr ts) (cdr args) env
|
|
1744
|
-
(if (and (not constants) (literal-type? (car r)))
|
|
1745
|
-
s
|
|
1746
|
-
(let ([u (unify (car ts) (settled-type (car r)) s)])
|
|
1747
|
-
(if (!= u 0)
|
|
1748
|
-
u
|
|
1749
|
-
(substrate-error (car args) "expected ~s, got ~s" (shown-apart (applied (car ts) s) (car r))))))
|
|
1750
|
-
constants))]))
|
|
1751
|
-
|
|
1752
|
-
(define (known-type? [t datum] [s datum]) -> bool
|
|
1753
|
-
(cond [(and (pair? t) (== (car t) 'tvar)) (!= (assq (cadr t) s) 0)]
|
|
1754
|
-
[(pair? t) (andmap (lambda ([u datum]) -> bool (known-type? u s)) t)]
|
|
1755
|
-
[else #t]))
|
|
1756
|
-
|
|
1757
|
-
(define (applied [t datum] [s datum]) -> datum
|
|
1758
|
-
(cond [(and (pair? t) (== (car t) 'tvar)) (let ([b (assq (cadr t) s)]) (if (!= b 0) (cdr b) t))]
|
|
1759
|
-
[(pair? t) (for/list ([u t]) (applied u s))]
|
|
1760
|
-
[else t]))
|
|
1761
|
-
|
|
1762
|
-
(define (unify [t datum] [u datum] [s datum]) -> datum
|
|
1763
|
-
(cond [(and (pair? t) (== (car t) 'tvar))
|
|
1764
|
-
(let ([b (assq (cadr t) s)])
|
|
1765
|
-
(cond [(== b 0) (cons (cons (cadr t) u) s)]
|
|
1766
|
-
[(equal? (cdr b) u) s]
|
|
1767
|
-
[else 0]))]
|
|
1768
|
-
[(and (pair? t) (pair? u) (== (length t) (length u))) (unify-each t u s)]
|
|
1769
|
-
[(equal? t u) s]
|
|
1770
|
-
[else 0]))
|
|
1771
|
-
|
|
1772
|
-
(define (unify-each [t datum] [u datum] [s datum]) -> datum
|
|
1773
|
-
(if (null? t) s (let ([s2 (unify (car t) (car u) s)]) (if (!= s2 0) (unify-each (cdr t) (cdr u) s2) 0))))
|
|
1774
|
-
|
|
1775
|
-
(define (bound-type [e datum] [s datum] [p datum] [f datum]) -> datum
|
|
1776
|
-
(let ([b (assq p s)])
|
|
1777
|
-
(if (!= b 0) (cdr b) (substrate-error e "~a's type ~a is not known from its arguments: give it, (inst ~a type ...)" `(,f ,p ,f)))))
|
|
1778
|
-
|
|
1779
|
-
(define (instance [g datum] [ts datum] [where datum]) -> datum
|
|
1780
|
-
(syntax-match g
|
|
1781
|
-
[(f (p ...) ((x a) ...) r (body ...) s)
|
|
1782
|
-
(let* ([key (cons (identifier-name f) ts)] [known (datum-get (-> state instances) key)])
|
|
1783
|
-
(if (!= known 0)
|
|
1784
|
-
known
|
|
1785
|
-
(let ([name (fresh (format "~a<~a>" `(,(syntax-e f) ,(joined (for/list ([t ts]) (format "~s" `(,(shown t))))))))]
|
|
1786
|
-
[sub (for/list ([q p] [t ts]) (cons (syntax-e q) t))])
|
|
1787
|
-
(datum-put! (-> state instances) key (syntax-local-introduce name))
|
|
1788
|
-
(let ([saved (body-state)])
|
|
1789
|
-
(syntax-local-lift-definition
|
|
1790
|
-
(at s (function s name x (for/list ([y a]) (replace y sub)) (replace r sub) (for/list ([b body]) (replace b sub)) f 0)))
|
|
1791
|
-
(restore-body! saved))
|
|
1792
|
-
(syntax-local-introduce name))))]))
|
|
1793
|
-
|
|
1794
|
-
(define (replace [x datum] [sub datum]) -> datum
|
|
1795
|
-
(cond [(identifier? x)
|
|
1796
|
-
(let ([b (assq (syntax-e x) sub)]) (if (!= b 0) (datum->syntax x (cons 'quote (cons (cdr b) nil)) x) x))]
|
|
1797
|
-
[(!= (syntax->list x) 0) (syntax-rewrap x (for/list ([y (syntax->list x)]) (replace y sub)))]
|
|
1798
|
-
[else x]))
|
|
1799
|
-
|
|
1800
1655
|
;; ---- closures ----
|
|
1801
1656
|
|
|
1802
1657
|
(define (check-lambda [e datum] [m datum] [env datum]) -> datum
|
|
@@ -1900,8 +1755,8 @@
|
|
|
1900
1755
|
(define (literal-head? [f datum] [fm datum]) -> bool
|
|
1901
1756
|
(and (!= fm 0) (== (car fm) 'compile-time-value) (!= (struct-binding f) 0)))
|
|
1902
1757
|
|
|
1903
|
-
(define (check-literal [e datum] [f datum] [args datum] [env datum]
|
|
1904
|
-
(let* ([pairs (literal-pairs e f args)] [t (
|
|
1758
|
+
(define (check-literal [e datum] [f datum] [args datum] [env datum]) -> datum
|
|
1759
|
+
(let* ([pairs (literal-pairs e f args)] [t (named-type f)])
|
|
1905
1760
|
(cons t (construct-literal t pairs env (temp t)))))
|
|
1906
1761
|
|
|
1907
1762
|
(define (literal-pairs [e datum] [f datum] [args datum]) -> datum
|
|
@@ -1920,21 +1775,6 @@
|
|
|
1920
1775
|
(when (pair? missing) (substrate-error e "~a needs ~a" `(,(syntax-e f) ,(joined missing)))))
|
|
1921
1776
|
(reverse out)))
|
|
1922
1777
|
|
|
1923
|
-
(define (literal-type [e datum] [f datum] [pairs datum] [env datum] [hint datum]) -> datum
|
|
1924
|
-
(let ([v (struct-binding f)])
|
|
1925
|
-
(cond [(null? (parameters-of v)) (named-type f)]
|
|
1926
|
-
[(and (struct-type? hint) (== (cadr hint) (identifier-name f))) hint]
|
|
1927
|
-
[else
|
|
1928
|
-
(let* ([ps (parameters-of v)]
|
|
1929
|
-
[types (parse-types-with (type-variables ps) (for/list ([p pairs]) (declared-type v (car p))))]
|
|
1930
|
-
[s (infer e types (for/list ([p pairs]) (cdr p)) env)])
|
|
1931
|
-
`(struct ,(identifier-name f) ,(cadr v) ,(for/list ([p ps]) (bound-type e s p (syntax-e f)))))])))
|
|
1932
|
-
|
|
1933
|
-
(define (declared-type [v datum] [name datum]) -> datum
|
|
1934
|
-
(for/each ([d (syntax->list (caddr v))])
|
|
1935
|
-
(syntax-match d [(g gt) (when (== (syntax-e g) name) (return gt))]))
|
|
1936
|
-
0)
|
|
1937
|
-
|
|
1938
1778
|
(define (construct-literal [t datum] [pairs datum] [env datum] [dst datum]) -> datum
|
|
1939
1779
|
(let ([d (fresh-key!)] [fields (caddr (layout t))])
|
|
1940
1780
|
`(let ((,d i32 ,dst to))
|
|
@@ -2015,18 +1855,6 @@
|
|
|
2015
1855
|
hint)
|
|
2016
1856
|
hint c)))))
|
|
2017
1857
|
|
|
2018
|
-
(define (construct-type [e datum] [v datum] [i datum] [args datum] [env datum] [hint datum]) -> datum
|
|
2019
|
-
(let ([b (type-binding v)])
|
|
2020
|
-
(cond [(null? (parameters-of b)) (named-type v)]
|
|
2021
|
-
[(and (struct-type? hint) (== (cadr hint) (identifier-name v))) hint]
|
|
2022
|
-
[else
|
|
2023
|
-
(let* ([ps (parameters-of b)]
|
|
2024
|
-
[fields (parse-types-with (type-variables ps)
|
|
2025
|
-
(for/list ([f (cdr (syntax->list (list-ref (syntax->list (caddr b)) (fixnum-value (syntax-e i)))))])
|
|
2026
|
-
(syntax-match f [(_ ft) ft])))]
|
|
2027
|
-
[s (infer e fields args env)])
|
|
2028
|
-
`(struct ,(identifier-name v) ,(cadr b) ,(for/list ([p ps]) (bound-type e s p (syntax-e v)))))])))
|
|
2029
|
-
|
|
2030
1858
|
(define (case-index [n datum] [t datum]) -> datum
|
|
2031
1859
|
(syntax-match (let ([h (expand-head n)]) (if (== (car h) 'form) (caddr h) 0))
|
|
2032
1860
|
[('#%substrate-construct v i _)
|
|
@@ -2900,7 +2728,7 @@
|
|
|
2900
2728
|
[_ (substrate-error c "expected a case or [case number]" nil)]))]
|
|
2901
2729
|
[given (for/list ([c cs]) (syntax-match c [(_ k) k] [_ 0]))])
|
|
2902
2730
|
(distinct! names '"case")
|
|
2903
|
-
(syn `(begin (define-syntax ,name (quote-syntax (substrate-struct ,name (,@(for/list ([n names]) `(,n))) enum
|
|
2731
|
+
(syn `(begin (define-syntax ,name (quote-syntax (substrate-struct ,name (,@(for/list ([n names]) `(,n))) enum ,(case-numbers cs given))))
|
|
2904
2732
|
,@(for/list ([n names] [i (numbers-below (length names))])
|
|
2905
2733
|
`(define-syntax ,n (quote-syntax (#%form mark (#%substrate-construct ,name ,i ,n)))))))))
|
|
2906
2734
|
|
|
@@ -933,9 +933,9 @@
|
|
|
933
933
|
;; ---- linking ----
|
|
934
934
|
|
|
935
935
|
(define (index-of [t (ptr hash-table)] [key datum] [what string]) -> datum
|
|
936
|
-
(let ([i (hash-
|
|
936
|
+
(let ([i (hash-find t (cast u64 key))])
|
|
937
937
|
(when (== i 0) (fail "internal: ~a has no index" (cons (string->datum what) nil)))
|
|
938
|
-
(small (
|
|
938
|
+
(small (@ i))))
|
|
939
939
|
|
|
940
940
|
(define (type-index [lk (ptr linker)] [sig datum]) -> datum
|
|
941
941
|
(let ([known (datum-get (-> lk func-type-index) sig)])
|
|
@@ -965,7 +965,7 @@
|
|
|
965
965
|
|
|
966
966
|
(define (number! [t (ptr hash-table)] [items datum] [n u32]) -> u32
|
|
967
967
|
(while (pair? items)
|
|
968
|
-
(hash-set! t (cast u64 (car items))
|
|
968
|
+
(hash-set! t (cast u64 (car items)) n)
|
|
969
969
|
(+= n 1)
|
|
970
970
|
(set! items (cdr items)))
|
|
971
971
|
n)
|