substrate-lang 0.9.3 → 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.
Files changed (136) hide show
  1. package/build/compiler/binary.cdd2ffb408dd@0+0.wasm +0 -0
  2. package/build/compiler/checker.2b0ea87ed311@0+0.wasm +0 -0
  3. package/build/compiler/compile.da85f9bc4478@0+0.wasm +0 -0
  4. package/build/compiler/{core.fc3dab9d1846@0+0.wasm → core.0410ffbdc488@0+0.wasm} +0 -0
  5. package/build/compiler/expander.80707e1666d6@0+0.wasm +0 -0
  6. package/build/compiler/{fs.563034be70c3@0+0.wasm → fs.5017b627cbd2@0+0.wasm} +0 -0
  7. package/build/compiler/{leb128.748b1c37277a@0+0.wasm → leb128.ba77430f659f@0+0.wasm} +0 -0
  8. package/build/compiler/{link.11b643d35670@0+0.wasm → link.be6e641afa93@0+0.wasm} +0 -0
  9. package/build/compiler/{macros.4083601c00db@0+0.wasm → macros.b695763c0ca3@0+0.wasm} +0 -0
  10. package/build/compiler/{main.ed62cce43000@0+0.wasm → main.cbbdf42e34c2@0+0.wasm} +0 -0
  11. package/build/compiler/{ops.b361e858d8e1@0+0.wasm → ops.324f0a665fab@0+0.wasm} +0 -0
  12. package/build/compiler/{path.dcc4712bcc7b@0+0.wasm → path.1b5fd988b6f3@0+0.wasm} +0 -0
  13. package/build/compiler/program +21 -21
  14. package/build/compiler/prune.29dde307bdee@0+0.wasm +0 -0
  15. package/build/compiler/{reader.b535e61f99f4@0+0.wasm → reader.d256e69e09e2@0+0.wasm} +0 -0
  16. package/build/compiler/{roots.6d2942578055@0+0.wasm → roots.e366210c01d6@0+0.wasm} +0 -0
  17. package/build/compiler/{running.d73f7826cb74@0+0.wasm → running.b99787c2d180@0+0.wasm} +0 -0
  18. package/build/compiler/serialize.a12536bbbe9a@0+0.wasm +0 -0
  19. package/build/compiler/{sha256.5fc9d60f8bb2@0+0.wasm → sha256.f6c742932dde@0+0.wasm} +0 -0
  20. package/build/compiler/{substrate.4c780d6dd6d4@0+0.wasm → substrate.728c690187f2@0+0.wasm} +0 -0
  21. package/build/compiler/syntax.fadc832db29f@0+0.wasm +0 -0
  22. package/build/compiler/{writer.806bc85aa684@0+0.wasm → writer.550227768eb9@0+0.wasm} +0 -0
  23. package/build/sub/{base64.8fba03e1be0a@0+0.wasm → base64.454b045156d2@0+0.wasm} +0 -0
  24. package/build/sub/build.115aeefc15e8@0+0.wasm +0 -0
  25. package/build/sub/{chromium.e4db7d29897c@0+0.wasm → chromium.fc0bfea0fbe6@0+0.wasm} +0 -0
  26. package/build/sub/{common.91ddee6b7a67@0+0.wasm → common.997c21b0b8cf@0+0.wasm} +0 -0
  27. package/build/sub/deflate.3138a38325a1@0+0.wasm +0 -0
  28. package/build/sub/{doc.0b48bbac404b@0+0.wasm → doc.e3f9a998cd91@0+0.wasm} +0 -0
  29. package/build/sub/{doc.566f9861828e@0+0.wasm → doc.f18ad14060e9@0+0.wasm} +0 -0
  30. package/build/sub/env.861d55fff974@0+0.wasm +0 -0
  31. package/build/sub/events.2c981f6f1ec7@0+0.wasm +0 -0
  32. package/build/sub/{fetch.5d2f427c995e@0+0.wasm → fetch.b0ce8f8b3da8@0+0.wasm} +0 -0
  33. package/build/sub/fetch.d62aa5fc9623@0+0.wasm +0 -0
  34. package/build/sub/{files.30e55182c5df@0+0.wasm → files.1706cc0941c0@0+0.wasm} +0 -0
  35. package/build/sub/{fs.563034be70c3@0+0.wasm → fs.5017b627cbd2@0+0.wasm} +0 -0
  36. package/build/sub/{git.48aefa1644be@0+0.wasm → git.1c5791236e35@0+0.wasm} +0 -0
  37. package/build/sub/{grants.5bf25700d47c@0+0.wasm → grants.cd99dff2854e@0+0.wasm} +0 -0
  38. package/build/sub/{gzip.69588e97c35a@0+0.wasm → gzip.9ebea150f218@0+0.wasm} +0 -0
  39. package/build/sub/hash.ba8330dad9ff@0+0.wasm +0 -0
  40. package/build/sub/{html.20baa1dc7ca6@0+0.wasm → html.0b0362932a75@0+0.wasm} +0 -0
  41. package/build/sub/{html.c1671a102b4d@0+0.wasm → html.3b3c8d7d9971@0+0.wasm} +0 -0
  42. package/build/sub/{inflate.8899e0933792@0+0.wasm → inflate.3cfa17586072@0+0.wasm} +0 -0
  43. package/build/sub/{json.f15a29d99d8d@0+0.wasm → json.af2e0ae20084@0+0.wasm} +0 -0
  44. package/build/sub/manifest.6e014ac19e5d@0+0.wasm +0 -0
  45. package/build/sub/map.e582eae03ec2@0+0.wasm +0 -0
  46. package/build/sub/{pack.55992e8cc09c@0+0.wasm → pack.4295e4f5bdbd@0+0.wasm} +0 -0
  47. package/build/sub/{path.dcc4712bcc7b@0+0.wasm → path.1b5fd988b6f3@0+0.wasm} +0 -0
  48. package/build/sub/path.de22f6659534@0+0.wasm +0 -0
  49. package/build/sub/process.ca10ac0b8a62@0+0.wasm +0 -0
  50. package/build/sub/program +48 -48
  51. package/build/sub/read.279fafcda508@0+0.wasm +0 -0
  52. package/build/sub/{reader.b535e61f99f4@0+0.wasm → reader.d256e69e09e2@0+0.wasm} +0 -0
  53. package/build/sub/{root.9b713ec588c1@0+0.wasm → root.02141d04d568@0+0.wasm} +0 -0
  54. package/build/sub/{roots.6d2942578055@0+0.wasm → roots.e366210c01d6@0+0.wasm} +0 -0
  55. package/build/sub/{sha256.5fc9d60f8bb2@0+0.wasm → sha256.f6c742932dde@0+0.wasm} +0 -0
  56. package/build/sub/{sha512.b988b9dc6114@0+0.wasm → sha512.9fee24e95460@0+0.wasm} +0 -0
  57. package/build/sub/site.76aa8286c257@0+0.wasm +0 -0
  58. package/build/sub/{site.7c6d8c7747af@0+0.wasm → site.e6e415bc3170@0+0.wasm} +0 -0
  59. package/build/sub/{store.d4e845ff24ac@0+0.wasm → store.c48db3345968@0+0.wasm} +0 -0
  60. package/build/sub/{stream.4c07247477f7@0+0.wasm → stream.27fd2fe858e1@0+0.wasm} +0 -0
  61. package/build/sub/{sub.b57e17b6876b@0+0.wasm → sub.c0fb7310de12@0+0.wasm} +0 -0
  62. package/build/sub/{substrate.4c780d6dd6d4@0+0.wasm → substrate.728c690187f2@0+0.wasm} +0 -0
  63. package/build/sub/{syntax.9857f6784d63@0+0.wasm → syntax.fadc832db29f@0+0.wasm} +0 -0
  64. package/build/sub/tar.692c0e8827cd@0+0.wasm +0 -0
  65. package/build/sub/{test.0d9c079bb309@0+0.wasm → test.1fd2ff8123bf@0+0.wasm} +0 -0
  66. package/build/sub/{text.4ab70ac35b5a@0+0.wasm → text.8ff142d72fd7@0+0.wasm} +0 -0
  67. package/build/sub/{timer.3809bb17a7a1@0+0.wasm → timer.d3454726b3bf@0+0.wasm} +0 -0
  68. package/build/sub/{upgrade.18a5aa0dae89@0+0.wasm → upgrade.2a9219e6a45d@0+0.wasm} +0 -0
  69. package/build/sub/{utf8.524c475ecd40@0+0.wasm → utf8.e82afeb9e953@0+0.wasm} +0 -0
  70. package/build/sub/worker.ea1e11f8f5e2@0+0.wasm +0 -0
  71. package/build/sub/writer.550227768eb9@0+0.wasm +0 -0
  72. package/package.json +1 -1
  73. package/std/archive/tar.sub +14 -21
  74. package/std/compress/deflate.sub +10 -12
  75. package/std/encoding/json.sub +44 -65
  76. package/std/encoding/wire.sub +6 -8
  77. package/std/http/checks.sub +3 -3
  78. package/std/http/conditional.sub +2 -4
  79. package/std/http/cookie.sub +5 -7
  80. package/std/http/form.sub +7 -10
  81. package/std/http/http.sub +17 -24
  82. package/std/http/multipart.sub +5 -5
  83. package/std/http/route.sub +9 -9
  84. package/std/http/server.sub +7 -12
  85. package/std/http/session.sub +1 -4
  86. package/std/http/sse-client.sub +9 -14
  87. package/std/http/url.sub +10 -10
  88. package/std/http/websocket.sub +2 -5
  89. package/std/meta/type-info.sub +10 -10
  90. package/std/package/hash.sub +1 -1
  91. package/std/package/manifest.sub +14 -15
  92. package/std/package/map.sub +4 -8
  93. package/std/package/path.sub +1 -4
  94. package/std/package/read.sub +3 -8
  95. package/std/package/site.sub +5 -5
  96. package/std/test/compare.sub +9 -10
  97. package/std/test/page.sub +1 -1
  98. package/std/test/run.sub +1 -1
  99. package/std/test/test.sub +24 -17
  100. package/substrate/VERSION +1 -1
  101. package/substrate/compiler/binary.sub +5 -14
  102. package/substrate/compiler/checker.sub +204 -19
  103. package/substrate/compiler/compile.sub +8 -8
  104. package/substrate/compiler/expander.sub +21 -29
  105. package/substrate/compiler/link.sub +2 -2
  106. package/substrate/compiler/ops.sub +1 -1
  107. package/substrate/compiler/prune.sub +12 -17
  108. package/substrate/compiler/roots.sub +3 -2
  109. package/substrate/compiler/serialize.sub +1 -1
  110. package/substrate/compiler/substrate.sub +8 -13
  111. package/substrate/compiler/syntax.sub +8 -21
  112. package/substrate/host/fs.sub +8 -11
  113. package/substrate/host/grants.sub +25 -26
  114. package/substrate/host/node/process.sub +5 -6
  115. package/build/compiler/binary.3823f89ce414@0+0.wasm +0 -0
  116. package/build/compiler/checker.592d37dcbec9@0+0.wasm +0 -0
  117. package/build/compiler/compile.86a2b03b0c9b@0+0.wasm +0 -0
  118. package/build/compiler/expander.689d326e5a1b@0+0.wasm +0 -0
  119. package/build/compiler/prune.d4a3f9834095@0+0.wasm +0 -0
  120. package/build/compiler/serialize.b2196de75bc8@0+0.wasm +0 -0
  121. package/build/compiler/syntax.9857f6784d63@0+0.wasm +0 -0
  122. package/build/sub/build.84ac996eda63@0+0.wasm +0 -0
  123. package/build/sub/deflate.fc8075e3aed1@0+0.wasm +0 -0
  124. package/build/sub/env.f051f8166526@0+0.wasm +0 -0
  125. package/build/sub/events.f952172735e0@0+0.wasm +0 -0
  126. package/build/sub/fetch.097f1cc9502d@0+0.wasm +0 -0
  127. package/build/sub/hash.3f0d118da63f@0+0.wasm +0 -0
  128. package/build/sub/manifest.cf7471880377@0+0.wasm +0 -0
  129. package/build/sub/map.dc516eec27ff@0+0.wasm +0 -0
  130. package/build/sub/path.b7a8e1cf3aaa@0+0.wasm +0 -0
  131. package/build/sub/process.aea2c88cb7a0@0+0.wasm +0 -0
  132. package/build/sub/read.cd1e693f4fb4@0+0.wasm +0 -0
  133. package/build/sub/site.81548474c323@0+0.wasm +0 -0
  134. package/build/sub/tar.e482cf873cfc@0+0.wasm +0 -0
  135. package/build/sub/worker.f1190de21b21@0+0.wasm +0 -0
  136. package/build/sub/writer.806bc85aa684@0+0.wasm +0 -0
@@ -87,7 +87,7 @@
87
87
  (const unit-kind u32 20)
88
88
 
89
89
  (define (new-unit [path datum] [name datum]) -> datum
90
- (let ([m (cast (ptr unit) (arena-alloc (& run-arena) (sizeof unit)))])
90
+ (let ([m (new (& run-arena) unit)])
91
91
  (set! (-> m self) (make-record unit-kind m))
92
92
  (set! (-> m path) (keep path))
93
93
  (set! (-> m name) (keep name))
@@ -122,7 +122,7 @@
122
122
  (define namespace-counter u32 0)
123
123
 
124
124
  (define (new-comp [m datum]) -> (ptr comp)
125
- (let ([c (cast (ptr comp) (arena-alloc (current-arena) (sizeof comp)))])
125
+ (let ([c (new (current-arena) comp)])
126
126
  (set! (-> c module) m)
127
127
  (set! (-> c use-site-scopes) nil)
128
128
  (set! (-> c phase-forms) nil)
@@ -353,19 +353,16 @@
353
353
  (cast (ptr binding) (hash-ref (& bindings) (slot-key sym slot))))
354
354
 
355
355
  (define (bind-raw! [sym datum] [scopes (ptr scope-set)] [phase i32] [meaning datum]) -> (ptr binding)
356
- (let ([b (cast (ptr binding) (arena-alloc (& run-arena) (sizeof binding)))] [k (slot-key sym (binding-slot scopes))])
357
- (set! (-> b scopes) scopes)
358
- (set! (-> b phase) phase)
359
- (set! (-> b key) (keep (fresh-key!)))
360
- (set! (-> b meaning) (keep meaning))
361
- (set! (-> b next) (cast (ptr binding) (hash-ref (& bindings) k)))
356
+ (let* ([k (slot-key sym (binding-slot scopes))]
357
+ [b (new (& run-arena) (binding #:scopes scopes #:phase phase #:key (keep (fresh-key!)) #:meaning (keep meaning)
358
+ #:next (cast (ptr binding) (hash-ref (& bindings) k))))])
362
359
  (hash-set! (& bindings) k (cast u32 b))
363
360
  b))
364
361
 
365
362
  (define (bind-module-level! [sym datum] [scopes (ptr scope-set)] [phase i32] [meaning datum]) -> (ptr binding)
366
363
  (let ([b (bind-raw! sym scopes phase meaning)])
367
364
  (when (!= current 0)
368
- (let ([e (cast (ptr module-entry) (arena-alloc (& run-arena) (sizeof module-entry)))] [m (the-module)])
365
+ (let ([e (new (& run-arena) module-entry)] [m (the-module)])
369
366
  (set! (-> e symbol) sym)
370
367
  (set! (-> e scopes) scopes)
371
368
  (set! (-> e phase) phase)
@@ -815,7 +812,7 @@
815
812
  (define (imported-kind [kind datum]) -> datum (if (== kind 'memory) 'memory-import 'table-import))
816
813
 
817
814
  (define (add-wasm-module! [m datum] [phase i32] [compiled datum])
818
- (let ([l (cast (ptr wasm-module) (arena-alloc (& run-arena) (sizeof wasm-module)))] [u (unit-of m)])
815
+ (let ([l (new (& run-arena) wasm-module)] [u (unit-of m)])
819
816
  (set! (-> l phase) phase)
820
817
  (set! (-> l bytes) (keep (car compiled)))
821
818
  (set! (-> l imports) (keep (cadr compiled)))
@@ -1391,10 +1388,7 @@
1391
1388
  (define loading datum 0)
1392
1389
  (define loaded-infos (ptr datum) 0)
1393
1390
 
1394
- (define (zeroed-array [n u32]) -> (ptr datum)
1395
- (let ([a (cast (ptr datum) (arena-alloc (current-arena) (* 4 (+ n 1))))])
1396
- (for ([i u32 0]) (< i n) (+= i 1) (set! (@ a i) 0))
1397
- a))
1391
+ (define (zeroed-array [n u32]) -> (ptr datum) (-> (new (current-arena) datum (+ n 1)) items))
1398
1392
 
1399
1393
  (define (load-module! [m datum] [d datum])
1400
1394
  (let* ([u (unit-of m)] [infos (section d 'infos)] [ni (length infos)]
@@ -1423,7 +1417,7 @@
1423
1417
  (for-each (lambda ([e datum])
1424
1418
  (let* ([scopes (scope-set-of (cadr e))] [phase (cast i32 (integer-value (caddr e)))]
1425
1419
  [b (bind-raw! (car e) scopes phase (decode (cadddr e)))]
1426
- [me (cast (ptr module-entry) (arena-alloc (& run-arena) (sizeof module-entry)))])
1420
+ [me (new (& run-arena) module-entry)])
1427
1421
  (set! (-> me symbol) (car e))
1428
1422
  (set! (-> me scopes) scopes)
1429
1423
  (set! (-> me phase) phase)
@@ -1520,7 +1514,7 @@
1520
1514
  (define current-body (ptr body) 0)
1521
1515
 
1522
1516
  (define (expand-body [forms datum] [phase i32]) -> datum
1523
- (let ([b (cast (ptr body) (arena-alloc (current-arena) (sizeof body)))] [saved current-body] [out datum 0])
1517
+ (let ([b (new (current-arena) body)] [saved current-body] [out datum 0])
1524
1518
  (set! (-> b phase) phase)
1525
1519
  (set! (-> b syntax) to-syntax)
1526
1520
  (set! (-> b items) nil)
@@ -2028,29 +2022,27 @@
2028
2022
  (== (host-instantiate name code imports compile-time err) 0))
2029
2023
 
2030
2024
  (define (instantiate! [name datum] [bytes datum] [imports datum] [scopes datum] [t u32] [where datum] [compile-time bool])
2031
- (let* ([map (import-map imports t)] [n (* 2 (length map))] [pairs (cast (ptr string) (malloc (* n 8)))] [i u32 0] [ok #f]
2032
- [why string])
2025
+ (let* ([map (import-map imports t)] [n (* 2 (length map))] [pairs (new 0 string n)] [i u32 0] [ok #f] [why string])
2033
2026
  (while (pair? map)
2034
2027
  (set! (@ pairs i) (datum->string (car (car map))))
2035
2028
  (set! (@ pairs (+ i 1)) (datum->string (cdr (car map))))
2036
2029
  (+= i 2)
2037
2030
  (set! map (cdr map)))
2038
2031
  (set-scope-map! (slice (scope-map-of scopes t) (length scopes)))
2039
- (try (set! ok (instantiate-bytes (datum->string name) (datum->bytes bytes) (slice pairs n) compile-time
2040
- (& why)))
2032
+ (try (set! ok (instantiate-bytes (datum->string name) (datum->bytes bytes) pairs compile-time (& why)))
2041
2033
  [catch compile-error (message blamed loc)
2042
2034
  (set-scope-map! 0)
2043
- (free pairs)
2035
+ (free (-> pairs items))
2044
2036
  (throw compile-error message blamed loc)])
2045
2037
  (set-scope-map! 0)
2046
- (free pairs)
2038
+ (free (-> pairs items))
2047
2039
  (unless ok
2048
2040
  (if session-running
2049
2041
  (fail-at where "~a" (list1 (session-failure (host-error why))))
2050
2042
  (fail-at where "compile-time code failed: ~a" (list1 (host-error why)))))))
2051
2043
 
2052
2044
  (define (scope-map-of [scopes datum] [t u32]) -> (ptr u32)
2053
- (let ([p (cast (ptr u32) (arena-alloc (current-arena) (* 4 (+ (length scopes) 1))))] [i u32 0] [sc u32 0] [o datum 0])
2045
+ (let ([p (-> (new (current-arena) u32 (+ (length scopes) 1)) items)] [i u32 0] [sc u32 0] [o datum 0])
2054
2046
  (while (pair? scopes)
2055
2047
  (set! sc (cast u32 (integer-value (car scopes))))
2056
2048
  (set! o (scope-origin sc))
@@ -2881,23 +2873,23 @@
2881
2873
  (define (module-names [m datum]) -> (ptr names)
2882
2874
  (let ([head (-> (unit-of m) entries)] [known (cast (ptr names) (hash-ref (& name-tables) (cast u64 m)))])
2883
2875
  (when (and (!= known 0) (== (-> known upto) head)) (return known))
2884
- (let ([saved (use-arena (& run-arena))] [n known] [new nil] [e head])
2876
+ (let ([saved (use-arena (& run-arena))] [n known] [added nil] [e head])
2885
2877
  (when (!= n 0)
2886
2878
  (while (and (!= e 0) (!= e (-> n upto)))
2887
- (set! new (cons (cast datum e) new))
2879
+ (set! added (cons (cast datum e) added))
2888
2880
  (set! e (-> e next)))
2889
2881
  (when (!= e (-> n upto)) (set! n 0)))
2890
2882
  (when (== n 0)
2891
- (set! n (cast (ptr names) (arena-alloc (& run-arena) (sizeof names))))
2883
+ (set! n (new (& run-arena) names))
2892
2884
  (set! (-> n by-base) (make-table))
2893
2885
  (set! (-> n by-name) (make-table))
2894
2886
  (set! (-> n counts) (make-table))
2895
- (set! new nil)
2887
+ (set! added nil)
2896
2888
  (set! e head)
2897
2889
  (while (!= e 0)
2898
- (set! new (cons (cast datum e) new))
2890
+ (set! added (cons (cast datum e) added))
2899
2891
  (set! e (-> e next))))
2900
- (name-entries! m n new)
2892
+ (name-entries! m n added)
2901
2893
  (set! (-> n upto) head)
2902
2894
  (hash-set! (& name-tables) (cast u64 m) (cast u32 n))
2903
2895
  (use-arena saved)
@@ -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) (cast (ptr u32) (malloc (* 4 (+ (-> k nf) 1)))))
255
- (set! (-> k gmap) (cast (ptr u32) (malloc (* 4 (+ (-> k ng) 1)))))
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)
@@ -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 (cast (ptr prim-op) (arena-alloc (& run-arena) (sizeof prim-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 (cast (ptr wasm) (arena-alloc (current-arena) (sizeof wasm)))] [id u32 0] [head u32 0] [next u32 0])
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) (cast (ptr bool) (arena-alloc (current-arena) (+ (-> w nimports) (-> w count) 1))))
70
- (memset (-> w live) 0 (+ (-> w nimports) (-> w count) 1))
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) (cast (ptr bool) (arena-alloc (current-arena) (+ (-> w nimports) (-> w count) 1))))
75
- (memset (-> w valued) 0 (+ (-> w nimports) (-> w count) 1))
76
- (set! (-> w read-globals) (cast (ptr bool) (arena-alloc (current-arena) (+ (-> w nglobals) 1))))
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) (cast (ptr u32) (arena-alloc (current-arena) (* 4 (+ (-> w count) 1)))))
82
- (set! (-> w site-ends) (cast (ptr u32) (arena-alloc (current-arena) (* 4 (+ (-> w count) 1)))))))
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) (cast (ptr u32) (arena-alloc (current-arena) (* 4 (+ n 1)))))
129
- (set! (-> w ends) (cast (ptr u32) (arena-alloc (current-arena) (* 4 (+ n 1)))))
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) (cast (ptr u32) (arena-alloc (current-arena) (* 4 (+ total 1)))))
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 (cast (ptr u32) (arena-alloc (current-arena) (* 4 (+ (-> w count) 1)))))
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)))]
@@ -351,9 +351,10 @@
351
351
  name
352
352
  (string->datum (path-joined (path-windows?) (datum->string dir) (datum->string name)))))
353
353
 
354
- (define (kind-of [path datum]) -> i32
354
+ (define (kind-of [path datum]) -> fs-kind
355
355
  (let ([info fs-info])
356
- (if (< (fs-stat (datum->string path) (& info) 0) 0) 0 (-> info kind))))
356
+ (fs-stat (datum->string path) (& info) 0)
357
+ (-> info kind)))
357
358
 
358
359
  (define (clean-name? [s string]) -> bool
359
360
  (let ([start u32 0])
@@ -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 (cast (ptr serializer) (arena-alloc (current-arena) (sizeof serializer)))])
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))
@@ -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 @ & ->
@@ -14,7 +14,7 @@
14
14
  buffer-add-entries! entry-strings
15
15
  sqrt fabs floor ceil trunc nearbyint copysign sqrtf fabsf floorf ceilf truncf nearbyintf copysignf
16
16
  malloc calloc realloc free try-malloc try-calloc try-realloc memcpy memset memcmp
17
- arena make-arena arena-alloc arena-start! arena-free new
17
+ arena make-arena arena-alloc arena-start! arena-free new copy
18
18
  buffer make-buffer buffer-add! buffer-add-byte! buffer-add-string! buffer-add-utf-8! buffer-add-u32! buffer-add-f32!
19
19
  buffer-bytes buffer-string
20
20
  buffer-reserve buffer-free! buffer-trim! hash-bytes hash-table hash-ref hash-set! hash-clear! hash-free!
@@ -25,9 +25,9 @@
25
25
  ;; ---- the forms ----
26
26
 
27
27
  (define-syntax forms (quote-syntax (#%form forms)))
28
- (forms #%module-begin #%top-interaction define struct union variant match exception
28
+ (forms #%module-begin #%top-interaction define struct union variant enum match exception
29
29
  throw try lambda inst substrate-struct-check typedef const let let* #%datum when unless cond case array-of slice
30
- 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
31
31
  + - * / % == != < <= > >= and or not bit-and bit-or bit-xor bit-not << >>
32
32
  += -= *= /= %= <<= >>= bit-and= bit-or= bit-xor=)
33
33
 
@@ -44,6 +44,7 @@
44
44
  (constant (const NAME TYPE VALUE))
45
45
  (type (struct NAME FIELD ...))
46
46
  (type (variant NAME CASE ...))
47
+ (type (enum NAME CASE ...))
47
48
  (type (typedef NAME TYPE))
48
49
  (exception (exception NAME TYPE ...))
49
50
  (macro (define-syntax NAME _))
@@ -183,10 +184,7 @@
183
184
 
184
185
  ;; ---- strings and slices ----
185
186
 
186
- (define (string-copy [s string]) -> string
187
- (let ([p (cast (ptr u8) (malloc (-> s length)))])
188
- (memcpy p (-> s bytes) (-> s length))
189
- (cast string (slice p (-> s length)))))
187
+ (define (string-copy [s string]) -> string (copy 0 s))
190
188
 
191
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.
192
190
 
@@ -977,7 +975,7 @@
977
975
  (+ ten-powers (* 2 (+ q 348))))
978
976
 
979
977
  (define (make-ten-powers) -> (ptr u64)
980
- (let* ([t (cast (ptr u64) (malloc 11136))] [limbs (array u64 44)] [x (slice limbs)])
978
+ (let* ([t (-> (new 0 u64 1392) items)] [limbs (array u64 44)] [x (slice limbs)])
981
979
  (memset limbs 0 352)
982
980
  (set! (@ x 0) 1)
983
981
  (for ([q 0]) (<= q 347) (+= q 1)
@@ -1020,10 +1018,7 @@
1020
1018
  [else (bit-or (<< (cast u64 (+ e2 1075)) 52) (- mant 4503599627370496))])))
1021
1019
 
1022
1020
  ;; A number is 32-bit limbs, least significant first, each in a u64.
1023
- (define (big-new [a (ptr arena)] [len u32]) -> (slice u64)
1024
- (let ([x (cast (ptr u64) (arena-alloc a (* 8 len)))])
1025
- (memset x 0 (* 8 len))
1026
- (slice x len)))
1021
+ (define (big-new [a (ptr arena)] [len u32]) -> (slice u64) (new a u64 len))
1027
1022
 
1028
1023
  (define (big-mul-add! [x (slice u64)] [k u64] [c u64])
1029
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 (cast (ptr module-arena) (malloc (sizeof module-arena)))])
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 (cast (ptr hash-table) (memset (arena-alloc current (sizeof hash-table)) 0 (sizeof hash-table)))])
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 (cast (ptr entry) (arena-alloc (-> t arena) (sizeof entry))))
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
- (let ([c (cast (ptr change) (arena-alloc current (sizeof change)))])
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
- (let ([l (cast (ptr srcloc) (arena-alloc current (sizeof srcloc)))])
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 (cast (ptr srcloc) (arena-alloc (& run-arena) (sizeof srcloc)))])
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 (cast (ptr u32) (arena-alloc current (* 4 (+ count 1))))])
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
 
@@ -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
- (const fs-file i32 1)
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 i32] [size i64] [modified f64] [mode u32])
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 (cast (ptr u8) (try-malloc room)))
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 (cast (ptr void) p))
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 (cast (ptr u8) (try-realloc (cast (ptr void) p) (* room 2))))
171
- (when (== more 0) (free (cast (ptr void) p)))
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
- (const grant-read u32 0)
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 u32]) -> string (let ([names (array-of string "read" "write" "net" "env" "run")]) (@ names 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 u32]) -> string
36
- (let ([names (array-of string "deny-read" "deny-write" "deny-net" "deny-env" "deny-run")]) (@ names k)))
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 u32] [item string]) (added! g (allowed k) item))
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 u32] [item string]) (added! g (denied k) item))
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 u32]) (added! g "all" (allowed 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 u32]) (added! g "all" (denied 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)]) (for ([k u32 0]) (< k 5) (+= k 1) (added! g "inherit" (allowed k))))
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 u32)]) -> bool
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 u32)]) -> bool
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 u32 0])
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 u32 0])
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 u32)]) -> bool
185
+ (define (kind-named [name string] [deny bool] [k (ptr grant-kind)]) -> bool
188
186
  (for ([i u32 0]) (< i 5) (+= i 1)
189
- (when (== name (if deny (denied i) (allowed i)))
190
- (set! (@ k) i)
191
- (return #t)))
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 u32 0] [n (-> items length)])
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
- (const process-pipe i32 0)
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 i32] [stdout i32] [stderr i32])
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) (-> p stdin) (-> p stdout)
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))
Binary file