@effekt-lang/effekt 0.82.0 → 0.83.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -8
- package/bin/effekt +0 -0
- package/libraries/chez/callcc/seq0.ss +8 -9
- package/libraries/chez/callcc/tail0.ss +35 -19
- package/libraries/chez/common/effekt_primitives.ss +19 -3
- package/libraries/chez/cps/effekt.ss +180 -165
- package/libraries/chez/monadic/effekt.ss +28 -13
- package/libraries/chez/monadic/seq0.ss +8 -9
- package/libraries/common/bench.effekt +1 -0
- package/libraries/common/char.effekt +4 -4
- package/libraries/common/effekt.effekt +44 -44
- package/libraries/common/string.effekt +1 -1
- package/libraries/js/effekt_runtime.js +2 -4
- package/libraries/llvm/forward-declare-c.ll +3 -2
- package/libraries/llvm/panic.c +9 -2
- package/libraries/llvm/rts.ll +2 -4
- package/licenses/eclipse public license, version 2.0 - epl-2.0.html +3 -3
- package/licenses/mit license - mit-license.html +120 -91
- package/licenses/the bsd license - bsd-license.html +120 -91
- package/licenses/the mit license - mit.html +121 -92
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,14 +3,6 @@
|
|
|
3
3
|
Compared to other languages with effect handlers (and support for polymorphic effects) the Effekt language
|
|
4
4
|
aims to be significantly more lightweight in its concepts.
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
## Disclaimer: Use at your own risk
|
|
8
|
-
|
|
9
|
-
**Effekt is a research-level language. We are actively working on it and the language (and everything else) is very likely to change.**
|
|
10
|
-
|
|
11
|
-
Also, Effekt comes with no warranty and there are (probably) many bugs -- If this does not discourage you, feel free to
|
|
12
|
-
play with it and give us your feedback :)
|
|
13
|
-
|
|
14
6
|
## Examples
|
|
15
7
|
|
|
16
8
|
If you are looking for examples of the Effekt language, we invite you to look at the [casestudies](https://github.com/effekt-lang/effekt/tree/main/examples/casestudies) and the [language tour](https://effekt-lang.org/tour).
|
package/bin/effekt
CHANGED
|
Binary file
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
; [ [f1, f2, f3, f4| fields | prompt], [f1, f2, f3, f4| fields | prompt]... ]
|
|
2
|
-
(define-record Stack
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
(define-record-type Stack
|
|
3
|
+
(fields frames arena prompt)
|
|
4
|
+
(nongenerative)
|
|
5
|
+
(sealed #t))
|
|
6
6
|
|
|
7
|
-
(define-record Substack
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
[immutable prompt]))
|
|
7
|
+
(define-record-type Substack
|
|
8
|
+
(fields frames arena field-backup prompt)
|
|
9
|
+
(nongenerative)
|
|
10
|
+
(sealed #t))
|
|
12
11
|
|
|
13
12
|
; MetaCont = (non-empty-list-of Stack)
|
|
14
13
|
; SubCont = (non-empty-list-of Stack)
|
|
@@ -58,25 +58,39 @@
|
|
|
58
58
|
(define (run th)
|
|
59
59
|
(define global (make-Stack '() (make-arena) (newPrompt)))
|
|
60
60
|
(set! mk (list global))
|
|
61
|
-
(
|
|
62
|
-
(
|
|
63
|
-
|
|
64
|
-
(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
(call-with-values
|
|
62
|
+
(lambda ()
|
|
63
|
+
(call/cc
|
|
64
|
+
(lambda (k_1)
|
|
65
|
+
(set! base-k k_1)
|
|
66
|
+
((call/cc (lambda (k_2)
|
|
67
|
+
(set! abort k_2)
|
|
68
|
+
(abort th)))))))
|
|
69
|
+
underflow))
|
|
68
70
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
71
|
+
; The single-value case is kept separate, since it does not allocate.
|
|
72
|
+
(define underflow
|
|
73
|
+
(case-lambda
|
|
74
|
+
[(v)
|
|
75
|
+
(if (null? mk) v
|
|
76
|
+
(let* ([stack (car mk)]
|
|
77
|
+
[frames (Stack-frames stack)]
|
|
78
|
+
[arena (Stack-arena stack)]
|
|
79
|
+
[prompt (Stack-prompt stack)]
|
|
80
|
+
[rest (cdr mk)])
|
|
81
|
+
(if (null? frames) (begin (set! mk rest) (underflow v))
|
|
82
|
+
(begin
|
|
83
|
+
(set! mk (cons (make-Stack (cdr frames) arena prompt) rest))
|
|
84
|
+
((car frames) v)))))]
|
|
85
|
+
[vs
|
|
86
|
+
(if (null? mk) (apply values vs)
|
|
87
|
+
(let* ([stack (car mk)]
|
|
88
|
+
[frames (Stack-frames stack)]
|
|
89
|
+
[rest (cdr mk)])
|
|
90
|
+
(if (null? frames) (begin (set! mk rest) (apply underflow vs))
|
|
91
|
+
(begin
|
|
92
|
+
(set! mk (cons (make-Stack (cdr frames) (Stack-arena stack) (Stack-prompt stack)) rest))
|
|
93
|
+
(apply (car frames) vs)))))]))
|
|
80
94
|
|
|
81
95
|
|
|
82
96
|
(define-syntax shift0-at
|
|
@@ -85,5 +99,7 @@
|
|
|
85
99
|
(withSubCont
|
|
86
100
|
P
|
|
87
101
|
(lambda (s)
|
|
88
|
-
(let ([id (lambda
|
|
102
|
+
(let ([id (case-lambda
|
|
103
|
+
[(v) (pushSubCont s v)]
|
|
104
|
+
[vs (pushSubCont s (apply values vs))])])
|
|
89
105
|
exp ...)))]))
|
|
@@ -109,16 +109,32 @@
|
|
|
109
109
|
|
|
110
110
|
; time in milliseconds
|
|
111
111
|
(define (timed block)
|
|
112
|
-
(let ([before (current-time)])
|
|
112
|
+
(let ([before (current-time 'time-monotonic)])
|
|
113
113
|
(block)
|
|
114
|
-
(let ([after (current-time)])
|
|
114
|
+
(let ([after (current-time 'time-monotonic)])
|
|
115
115
|
(seconds (time-difference after before)))))
|
|
116
116
|
|
|
117
117
|
(define (seconds diff)
|
|
118
118
|
(+ (time-second diff) (/ (time-nanosecond diff) 1000000000.0)))
|
|
119
119
|
|
|
120
|
+
; An Int is a fixnum, so the nanoseconds since the epoch (which exceed it) wrap into one,
|
|
121
|
+
; but differences between nearby timestamps are unaffected.
|
|
120
122
|
(define (timestamp)
|
|
121
123
|
(let ([t (current-time)])
|
|
124
|
+
(fixnum-wrap (+ (* (time-second t) 1000000000) (time-nanosecond t)))))
|
|
125
|
+
|
|
126
|
+
; Integer -> Fixnum, two's complement in (fixnum-width) bits
|
|
127
|
+
(define (fixnum-wrap n)
|
|
128
|
+
(let ([half (expt 2 (- (fixnum-width) 1))])
|
|
129
|
+
(- (modulo (+ n half) (* 2 half)) half)))
|
|
130
|
+
|
|
131
|
+
; Fixnum, Fixnum -> Fixnum
|
|
132
|
+
; `fxquotient` does not check for zero at optimize-level 3; `quotient` raises the usual error.
|
|
133
|
+
(define (int-quotient x y)
|
|
134
|
+
(if (fx= y 0) (quotient x y) (fxquotient x y)))
|
|
135
|
+
|
|
136
|
+
(define (relative-timestamp)
|
|
137
|
+
(let ([t (current-time 'time-monotonic)])
|
|
122
138
|
(+ (* (time-second t) 1000000000) (time-nanosecond t))))
|
|
123
139
|
|
|
124
140
|
(define (measure block warmup iterations)
|
|
@@ -142,4 +158,4 @@
|
|
|
142
158
|
(raise
|
|
143
159
|
(condition
|
|
144
160
|
(make-error)
|
|
145
|
-
(make-message-condition
|
|
161
|
+
(make-message-condition "should not be reachable!"))))
|
|
@@ -1,165 +1,180 @@
|
|
|
1
|
-
; Value = Any
|
|
2
|
-
; Generation = Int
|
|
3
|
-
|
|
4
|
-
; Ref = Store * Value * Generation
|
|
5
|
-
(define-record-type ref (fields store (mutable value) (mutable generation)))
|
|
6
|
-
|
|
7
|
-
; Node = box MEM | box Diff
|
|
8
|
-
|
|
9
|
-
; MEM
|
|
10
|
-
; Means the correct values are in MEMory
|
|
11
|
-
(define-record-type mem (fields))
|
|
12
|
-
|
|
13
|
-
; Diff = Ref * Value * Generation * Node
|
|
14
|
-
; Notes the DIFFerences between root and the current state in MEMory
|
|
15
|
-
(define-record-type diff (fields ref value generation root))
|
|
16
|
-
|
|
17
|
-
; Store = Node * Generation
|
|
18
|
-
(define-record-type store (fields (mutable root) (mutable generation)))
|
|
19
|
-
|
|
20
|
-
; Snapshot = Store * Node * Generation
|
|
21
|
-
(define-record-type snap (fields store root generation))
|
|
22
|
-
|
|
23
|
-
; -> Store
|
|
24
|
-
(define (create-store) (make-store (box (make-mem)) 0))
|
|
25
|
-
|
|
26
|
-
; Store -> Snapshot
|
|
27
|
-
(define (snapshot store)
|
|
28
|
-
(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
[
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
[
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
[
|
|
48
|
-
[
|
|
49
|
-
|
|
50
|
-
(ref-
|
|
51
|
-
(set
|
|
52
|
-
(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
[
|
|
63
|
-
|
|
64
|
-
(
|
|
65
|
-
(store-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
(
|
|
77
|
-
(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
(
|
|
103
|
-
|
|
104
|
-
; Ref
|
|
105
|
-
(define (
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
(define (
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
;
|
|
137
|
-
(define (
|
|
138
|
-
(
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
; MetaCont,
|
|
158
|
-
(define (
|
|
159
|
-
(
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
(
|
|
165
|
-
|
|
1
|
+
; Value = Any
|
|
2
|
+
; Generation = Int
|
|
3
|
+
|
|
4
|
+
; Ref = Store * Value * Generation
|
|
5
|
+
(define-record-type ref (fields store (mutable value) (mutable generation)) (nongenerative) (sealed #t))
|
|
6
|
+
|
|
7
|
+
; Node = box MEM | box Diff
|
|
8
|
+
|
|
9
|
+
; MEM
|
|
10
|
+
; Means the correct values are in MEMory
|
|
11
|
+
(define-record-type mem (fields) (nongenerative) (sealed #t))
|
|
12
|
+
|
|
13
|
+
; Diff = Ref * Value * Generation * Node
|
|
14
|
+
; Notes the DIFFerences between root and the current state in MEMory
|
|
15
|
+
(define-record-type diff (fields ref value generation root) (nongenerative) (sealed #t))
|
|
16
|
+
|
|
17
|
+
; Store = Node * Generation
|
|
18
|
+
(define-record-type store (fields (mutable root) (mutable generation)) (nongenerative) (sealed #t))
|
|
19
|
+
|
|
20
|
+
; Snapshot = Store * Node * Generation
|
|
21
|
+
(define-record-type snap (fields store root generation) (nongenerative) (sealed #t))
|
|
22
|
+
|
|
23
|
+
; -> Store
|
|
24
|
+
(define (create-store) (make-store (box (make-mem)) 0))
|
|
25
|
+
|
|
26
|
+
; Store | #f -> Snapshot | #f
|
|
27
|
+
(define (snapshot store)
|
|
28
|
+
(and store ; no need to snapshot if the store is empty
|
|
29
|
+
(let* ([sGen (store-generation store)]
|
|
30
|
+
[snap (make-snap store (store-root store) sGen)])
|
|
31
|
+
(store-generation-set! store (+ sGen 1))
|
|
32
|
+
snap)))
|
|
33
|
+
|
|
34
|
+
; Node, [box Diff] -> [box Diff]
|
|
35
|
+
(define (collectDiffs n acc)
|
|
36
|
+
(let ([unboxedN (unbox n)])
|
|
37
|
+
(cond
|
|
38
|
+
[(mem? unboxedN) acc]
|
|
39
|
+
[else (collectDiffs (diff-root unboxedN) (cons n acc))])))
|
|
40
|
+
|
|
41
|
+
; Node, [Diff] -> void
|
|
42
|
+
(define (applyDiffs n diffs)
|
|
43
|
+
(cond
|
|
44
|
+
[(null? diffs) (set-box! n (make-mem))]
|
|
45
|
+
[else
|
|
46
|
+
(let* ([currentDiff (car diffs)]
|
|
47
|
+
[realDiff (unbox currentDiff)]
|
|
48
|
+
[r (diff-ref realDiff)]
|
|
49
|
+
[oldValue (ref-value r)])
|
|
50
|
+
(ref-value-set! r (diff-value realDiff))
|
|
51
|
+
(ref-generation-set! r (diff-generation realDiff))
|
|
52
|
+
(set-box! n (make-diff r oldValue (ref-generation r) currentDiff))
|
|
53
|
+
(applyDiffs currentDiff (cdr diffs)))]))
|
|
54
|
+
|
|
55
|
+
; Node, Node -> void
|
|
56
|
+
(define (reroot newRoot oldRoot)
|
|
57
|
+
(applyDiffs oldRoot (collectDiffs newRoot '())))
|
|
58
|
+
|
|
59
|
+
; Store, Snapshot -> void
|
|
60
|
+
(define (restore snap)
|
|
61
|
+
(let* ([snapRoot (snap-root snap)]
|
|
62
|
+
[store (snap-store snap)]
|
|
63
|
+
[storeRoot (store-root store)])
|
|
64
|
+
(reroot snapRoot storeRoot)
|
|
65
|
+
(store-root-set! store snapRoot)
|
|
66
|
+
(store-generation-set! store (+ (snap-generation snap) 1))))
|
|
67
|
+
|
|
68
|
+
; Cont a = a, MetaCont -> #
|
|
69
|
+
; Prompt = Symbol
|
|
70
|
+
|
|
71
|
+
; MetaCont = Cont * Prompt * (Store | #f) | (Snapshot | #f) * MetaCont?
|
|
72
|
+
; Holds a "copy" of k, as well as its prompt and store.
|
|
73
|
+
; A segment's store is #f until its first variable or region creates it.
|
|
74
|
+
(define-record-type meta-cont
|
|
75
|
+
(fields (mutable cont) prompt (mutable store) (mutable rest))
|
|
76
|
+
(nongenerative)
|
|
77
|
+
(sealed #t))
|
|
78
|
+
|
|
79
|
+
; MetaCont -> Store
|
|
80
|
+
(define (segment-store ks)
|
|
81
|
+
(or (meta-cont-store ks) ; if there is a store, use it
|
|
82
|
+
(let ([store (create-store)]) ; otherwise, create it
|
|
83
|
+
(meta-cont-store-set! ks store)
|
|
84
|
+
store)))
|
|
85
|
+
|
|
86
|
+
; Value, MetaCont -> Ref
|
|
87
|
+
(define (var init ks)
|
|
88
|
+
(let ([store (segment-store ks)])
|
|
89
|
+
(make-ref store init (store-generation store))))
|
|
90
|
+
|
|
91
|
+
; Ref -> Value
|
|
92
|
+
(define (get ref) (ref-value ref))
|
|
93
|
+
|
|
94
|
+
; Ref, Value -> void
|
|
95
|
+
(define-syntax put
|
|
96
|
+
(syntax-rules ()
|
|
97
|
+
[(_ ref-expr value-expr)
|
|
98
|
+
(let ([ref ref-expr] [value value-expr])
|
|
99
|
+
(let ([store (ref-store ref)])
|
|
100
|
+
(if (= (ref-generation ref) (store-generation store))
|
|
101
|
+
(ref-value-set! ref value)
|
|
102
|
+
(put-recording ref value store))))]))
|
|
103
|
+
|
|
104
|
+
; Ref, Value, Store -> void
|
|
105
|
+
(define (put-recording ref value store)
|
|
106
|
+
(let ([rGen (ref-generation ref)]
|
|
107
|
+
[sGen (store-generation store)]
|
|
108
|
+
[oldVal (ref-value ref)]
|
|
109
|
+
[newRoot (box (make-mem))]
|
|
110
|
+
[oldRoot (store-root store)])
|
|
111
|
+
(ref-value-set! ref value)
|
|
112
|
+
(ref-generation-set! ref sGen)
|
|
113
|
+
(set-box! oldRoot (make-diff ref oldVal rGen newRoot))
|
|
114
|
+
(store-root-set! store newRoot)))
|
|
115
|
+
|
|
116
|
+
; MetaCont -> Store
|
|
117
|
+
(define (create-region ks) (segment-store ks))
|
|
118
|
+
|
|
119
|
+
; Value, Store -> Ref
|
|
120
|
+
(define (allocate init store) (make-ref store init (store-generation store)))
|
|
121
|
+
|
|
122
|
+
; Ref | Store -> void
|
|
123
|
+
(define (deallocate _) (void))
|
|
124
|
+
|
|
125
|
+
(define (top-level-k x _) x)
|
|
126
|
+
(define top-level-ks (make-meta-cont top-level-k (gensym "toplevel") #f '()))
|
|
127
|
+
|
|
128
|
+
; Program a b = a, Cont b, MetaCont -> #
|
|
129
|
+
|
|
130
|
+
; Program Prompt b, (b, MetaCont -> #), MetaCont, Cont b -> #
|
|
131
|
+
(define (reset prog ret ks k)
|
|
132
|
+
(let ([prompt (gensym)])
|
|
133
|
+
(meta-cont-cont-set! ks k)
|
|
134
|
+
(prog prompt (make-meta-cont ret prompt #f ks) ret)))
|
|
135
|
+
|
|
136
|
+
; MetaCont, Prompt -> MetaCont * MetaCont
|
|
137
|
+
(define (split-stack ks p)
|
|
138
|
+
(define (worker above below)
|
|
139
|
+
(let ([new-below (meta-cont-rest below)]
|
|
140
|
+
[snap (snapshot (meta-cont-store below))])
|
|
141
|
+
(meta-cont-store-set! below snap)
|
|
142
|
+
(meta-cont-rest-set! below above)
|
|
143
|
+
(if (symbol=? (meta-cont-prompt below) p)
|
|
144
|
+
(values below new-below)
|
|
145
|
+
(worker below new-below))))
|
|
146
|
+
(worker '() ks))
|
|
147
|
+
|
|
148
|
+
; Prompt, Program MetaCont b, MetaCont, Cont b -> #
|
|
149
|
+
(define-syntax shift
|
|
150
|
+
(syntax-rules ()
|
|
151
|
+
[(_ p-expr prog-expr ks-expr k-expr)
|
|
152
|
+
(let ([p p-expr] [prog prog-expr] [ks ks-expr] [k k-expr])
|
|
153
|
+
(meta-cont-cont-set! ks k)
|
|
154
|
+
(let-values ([(c underC) (split-stack ks p)])
|
|
155
|
+
(prog c underC (meta-cont-cont underC))))]))
|
|
156
|
+
|
|
157
|
+
; MetaCont, MetaCont -> MetaCont
|
|
158
|
+
(define (rewind cont ks)
|
|
159
|
+
(if (null? cont)
|
|
160
|
+
ks
|
|
161
|
+
(let* ([snap (meta-cont-store cont)]
|
|
162
|
+
[next (meta-cont-rest cont)]
|
|
163
|
+
[newKs (make-meta-cont (meta-cont-cont cont)
|
|
164
|
+
(meta-cont-prompt cont)
|
|
165
|
+
(and snap (snap-store snap))
|
|
166
|
+
ks)])
|
|
167
|
+
(when snap (restore snap))
|
|
168
|
+
(rewind next newKs))))
|
|
169
|
+
|
|
170
|
+
; Block b = Cont b, MetaCont -> #
|
|
171
|
+
|
|
172
|
+
; MetaCont, Block, MetaCont, Cont -> #
|
|
173
|
+
(define (resume cont block ks k)
|
|
174
|
+
(meta-cont-cont-set! ks k)
|
|
175
|
+
(let ([rewinded (rewind cont ks)])
|
|
176
|
+
(block rewinded (meta-cont-cont rewinded))))
|
|
177
|
+
|
|
178
|
+
; Block b -> b
|
|
179
|
+
(define (run-top-level p)
|
|
180
|
+
(p top-level-ks top-level-k))
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
(define-syntax delayed
|
|
2
2
|
(syntax-rules ()
|
|
3
3
|
[(_ e)
|
|
4
|
-
(lambda (mk) (underflow e
|
|
4
|
+
(lambda (mk) (underflow mk e))]))
|
|
5
5
|
|
|
6
6
|
; Control = MetaCont -> Step
|
|
7
7
|
|
|
8
|
-
; a -> Control a
|
|
9
|
-
(define
|
|
10
|
-
(lambda
|
|
8
|
+
; a ... -> Control a ...
|
|
9
|
+
(define pure
|
|
10
|
+
(case-lambda
|
|
11
|
+
[(v) (lambda (mk) (underflow mk v))]
|
|
12
|
+
[vs (lambda (mk) (apply underflow mk vs))]))
|
|
11
13
|
|
|
12
14
|
; Step a = (a | Control x), MetaCont x a
|
|
13
15
|
|
|
@@ -18,16 +20,27 @@
|
|
|
18
20
|
(lambda () (c mk))
|
|
19
21
|
trampoline)))
|
|
20
22
|
|
|
21
|
-
;
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
; MetaCont -> (Frame | #f), MetaCont
|
|
24
|
+
; Pops the topmost frame, or returns #f if the meta continuation is exhausted.
|
|
25
|
+
(define (pop-frame mk)
|
|
26
|
+
(if (null? mk) (values #f mk)
|
|
24
27
|
(let* ([stack (car mk)]
|
|
25
28
|
[rest (cdr mk)]
|
|
26
|
-
[frames (Stack-frames stack)]
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
[frames (Stack-frames stack)])
|
|
30
|
+
(if (null? frames) (pop-frame rest)
|
|
31
|
+
(values (car frames) (cons (make-Stack (cdr frames) (Stack-arena stack) (Stack-prompt stack)) rest))))))
|
|
32
|
+
|
|
33
|
+
; MetaCont, a ... -> Step
|
|
34
|
+
; The single-value case is kept separate, since it does not allocate.
|
|
35
|
+
(define underflow
|
|
36
|
+
(case-lambda
|
|
37
|
+
[(mk v)
|
|
38
|
+
(let-values ([(frame rest) (pop-frame mk)])
|
|
39
|
+
(if frame (values (frame v) rest) (values v rest)))]
|
|
40
|
+
[(mk . vs)
|
|
41
|
+
(let-values ([(frame rest) (pop-frame mk)])
|
|
42
|
+
(if frame (values (apply frame vs) rest)
|
|
43
|
+
(error 'underflow "cannot return ~s values to the toplevel" (length vs))))]))
|
|
31
44
|
|
|
32
45
|
; Control -> Control
|
|
33
46
|
(define (reset c)
|
|
@@ -39,7 +52,9 @@
|
|
|
39
52
|
(define (shift p f)
|
|
40
53
|
(lambda (mk)
|
|
41
54
|
(let-values ([(k mkrest) (splitSeq p mk)])
|
|
42
|
-
(let ([cont (lambda
|
|
55
|
+
(let ([cont (case-lambda
|
|
56
|
+
[(a) (lambda (mk) (underflow (appendSeq k mk) a))]
|
|
57
|
+
[as (lambda (mk) (apply underflow (appendSeq k mk) as))])])
|
|
43
58
|
(values (f cont) mkrest)))))
|
|
44
59
|
|
|
45
60
|
; Frame, MetaCont -> MetaCont
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
; [ [f1, f2, f3, f4| fields | prompt], [f1, f2, f3, f4| fields | prompt]... ]
|
|
2
|
-
(define-record Stack
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
(define-record-type Stack
|
|
3
|
+
(fields frames arena prompt)
|
|
4
|
+
(nongenerative)
|
|
5
|
+
(sealed #t))
|
|
6
6
|
|
|
7
|
-
(define-record Substack
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
[immutable prompt]))
|
|
7
|
+
(define-record-type Substack
|
|
8
|
+
(fields frames arena field-backup prompt)
|
|
9
|
+
(nongenerative)
|
|
10
|
+
(sealed #t))
|
|
12
11
|
|
|
13
12
|
; MetaCont = (non-empty-list-of Stack)
|
|
14
13
|
; SubCont = (non-empty-list-of Stack)
|
|
@@ -36,6 +36,7 @@ extern jsNode """
|
|
|
36
36
|
/// as gives no guarantees on the absolute time (unlike a UNIX timestamp).
|
|
37
37
|
extern def relativeTimestamp() at io: Nanos =
|
|
38
38
|
js "Math.round(performance.now() * 1000000)"
|
|
39
|
+
chez "(relative-timestamp)"
|
|
39
40
|
default { timestamp() }
|
|
40
41
|
|
|
41
42
|
type Duration = Int
|
|
@@ -106,7 +106,7 @@ extern def toChar(codepoint: Int) at {}: Char =
|
|
|
106
106
|
|
|
107
107
|
extern def infixLt(x: Char, y: Char) at {}: Bool =
|
|
108
108
|
js "(${x} < ${y})"
|
|
109
|
-
chez "(< ${x} ${y})"
|
|
109
|
+
chez "(fx< ${x} ${y})"
|
|
110
110
|
llvm """
|
|
111
111
|
%z = icmp slt %Int ${x}, ${y}
|
|
112
112
|
%fat_z = zext i1 %z to i64
|
|
@@ -116,7 +116,7 @@ extern def infixLt(x: Char, y: Char) at {}: Bool =
|
|
|
116
116
|
|
|
117
117
|
extern def infixLte(x: Char, y: Char) at {}: Bool =
|
|
118
118
|
js "(${x} <= ${y})"
|
|
119
|
-
chez "(<= ${x} ${y})"
|
|
119
|
+
chez "(fx<= ${x} ${y})"
|
|
120
120
|
llvm """
|
|
121
121
|
%z = icmp sle %Int ${x}, ${y}
|
|
122
122
|
%fat_z = zext i1 %z to i64
|
|
@@ -126,7 +126,7 @@ extern def infixLte(x: Char, y: Char) at {}: Bool =
|
|
|
126
126
|
|
|
127
127
|
extern def infixGt(x: Char, y: Char) at {}: Bool =
|
|
128
128
|
js "(${x} > ${y})"
|
|
129
|
-
chez "(> ${x} ${y})"
|
|
129
|
+
chez "(fx> ${x} ${y})"
|
|
130
130
|
llvm """
|
|
131
131
|
%z = icmp sgt %Int ${x}, ${y}
|
|
132
132
|
%fat_z = zext i1 %z to i64
|
|
@@ -136,7 +136,7 @@ extern def infixGt(x: Char, y: Char) at {}: Bool =
|
|
|
136
136
|
|
|
137
137
|
extern def infixGte(x: Char, y: Char) at {}: Bool =
|
|
138
138
|
js "(${x} >= ${y})"
|
|
139
|
-
chez "(>= ${x} ${y})"
|
|
139
|
+
chez "(fx>= ${x} ${y})"
|
|
140
140
|
llvm """
|
|
141
141
|
%z = icmp sge %Int ${x}, ${y}
|
|
142
142
|
%fat_z = zext i1 %z to i64
|