@effekt-lang/effekt 0.2.2 → 0.3.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/bin/effekt +0 -0
- package/bin/effekt.sh +1 -1
- package/libraries/chez/common/effekt_primitives.ss +10 -2
- package/libraries/chez/common/immutable/cslist.effekt +13 -7
- package/libraries/chez/common/mutable/dict.effekt +8 -10
- package/libraries/chez/common/text/regex.effekt +7 -9
- package/libraries/common/args.effekt +95 -0
- package/libraries/common/array.effekt +225 -0
- package/libraries/common/bench.effekt +60 -0
- package/libraries/common/buffer.effekt +123 -0
- package/libraries/common/bytes.effekt +125 -0
- package/libraries/{chez/common/immutable → common}/dequeue.effekt +18 -4
- package/libraries/common/effekt.effekt +764 -0
- package/libraries/common/exception.effekt +122 -0
- package/libraries/common/io/console.effekt +66 -0
- package/libraries/common/io/error.effekt +365 -0
- package/libraries/common/io/files.effekt +282 -0
- package/libraries/common/io/network.effekt +105 -0
- package/libraries/common/io/time.effekt +15 -0
- package/libraries/common/io.effekt +158 -0
- package/libraries/{llvm/immutable → common}/list.effekt +83 -74
- package/libraries/common/option.effekt +72 -0
- package/libraries/common/process.effekt +10 -0
- package/libraries/common/queue.effekt +140 -0
- package/libraries/common/ref.effekt +63 -0
- package/libraries/common/result.effekt +45 -0
- package/libraries/{ml/immutable → common}/seq.effekt +30 -19
- package/libraries/common/string.effekt +395 -0
- package/libraries/common/test.effekt +98 -0
- package/libraries/js/effekt_builtins.js +37 -6
- package/libraries/js/io.js +143 -0
- package/libraries/js/mutable/map.effekt +8 -9
- package/libraries/js/text/regex.effekt +7 -8
- package/libraries/js/unsafe/cont.effekt +2 -2
- package/libraries/js/web/dom.effekt +13 -13
- package/libraries/llvm/array.c +53 -0
- package/libraries/llvm/buffer.c +181 -76
- package/libraries/llvm/forward-declare-c.ll +27 -8
- package/libraries/llvm/io.c +543 -1
- package/libraries/llvm/io.ll +19 -0
- package/libraries/llvm/main.c +3 -1
- package/libraries/llvm/ref.c +45 -0
- package/libraries/llvm/rts.ll +496 -354
- package/libraries/llvm/types.c +23 -0
- package/libraries/ml/effekt.sml +2 -0
- package/libraries/ml/internal/mllist.effekt +9 -0
- package/libraries/ml/internal/mloption.effekt +18 -0
- package/libraries/ml/random.effekt +9 -9
- package/libraries/ml/text/regex.effekt +14 -19
- package/licenses/eclipse public license, version 2.0 - epl-2.0.html +2 -2
- package/licenses/mit license - mit-license.html +527 -57
- package/licenses/the bsd license - bsd-license.html +530 -55
- package/licenses/the mit license - mit.html +528 -58
- package/package.json +2 -2
- package/libraries/chez/callcc/effekt.effekt +0 -221
- package/libraries/chez/common/effekt_matching.ss +0 -100
- package/libraries/chez/common/immutable/list.effekt +0 -643
- package/libraries/chez/common/immutable/option.effekt +0 -39
- package/libraries/chez/common/immutable/result.effekt +0 -29
- package/libraries/chez/common/io/args.effekt +0 -20
- package/libraries/chez/common/mutable/array.effekt +0 -27
- package/libraries/chez/common/mutable/heap.effekt +0 -12
- package/libraries/chez/common/test.effekt +0 -59
- package/libraries/chez/common/text/string.effekt +0 -46
- package/libraries/chez/lift/effekt.effekt +0 -217
- package/libraries/chez/monadic/effekt.effekt +0 -218
- package/libraries/js/effekt.effekt +0 -284
- package/libraries/js/effekt_matching.js +0 -79
- package/libraries/js/immutable/dequeue.effekt +0 -78
- package/libraries/js/immutable/list.effekt +0 -643
- package/libraries/js/immutable/option.effekt +0 -49
- package/libraries/js/immutable/result.effekt +0 -29
- package/libraries/js/io/args.effekt +0 -9
- package/libraries/js/io/async.effekt +0 -28
- package/libraries/js/io/async.js +0 -2
- package/libraries/js/io/file.effekt +0 -50
- package/libraries/js/io/file_include.js +0 -13
- package/libraries/js/mutable/array.effekt +0 -98
- package/libraries/js/mutable/heap.effekt +0 -32
- package/libraries/js/test.effekt +0 -59
- package/libraries/js/text/string.effekt +0 -64
- package/libraries/llvm/effekt.effekt +0 -243
- package/libraries/llvm/immutable/option.effekt +0 -53
- package/libraries/llvm/immutable/result.effekt +0 -29
- package/libraries/llvm/io/args.effekt +0 -24
- package/libraries/llvm/text/string.effekt +0 -179
- package/libraries/ml/effekt.effekt +0 -267
- package/libraries/ml/immutable/dequeue.effekt +0 -81
- package/libraries/ml/immutable/list.effekt +0 -674
- package/libraries/ml/immutable/option.effekt +0 -53
- package/libraries/ml/immutable/result.effekt +0 -29
- package/libraries/ml/internal/option.effekt +0 -18
- package/libraries/ml/io/args.effekt +0 -41
- package/libraries/ml/mutable/array.effekt +0 -43
- package/libraries/ml/test.effekt +0 -60
- package/libraries/ml/text/string.effekt +0 -81
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effekt-lang/effekt",
|
|
3
3
|
"author": "Jonathan Brachthäuser",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/effekt-lang/effekt.git"
|
|
8
8
|
},
|
|
9
|
-
"description": "A language with
|
|
9
|
+
"description": "A language with lexical effect handlers and lightweight effect polymorphism",
|
|
10
10
|
"main": "index.js",
|
|
11
11
|
"scripts": {},
|
|
12
12
|
"bin": {
|
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
module effekt
|
|
2
|
-
|
|
3
|
-
// shift-0 based implementation
|
|
4
|
-
extern include "../common/effekt_primitives.ss"
|
|
5
|
-
// extern include "datatype.ss"
|
|
6
|
-
extern include "seq0.ss"
|
|
7
|
-
extern include "tail0.ss"
|
|
8
|
-
extern include "effekt.ss"
|
|
9
|
-
extern include "../common/effekt_matching.ss"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def locally[R] { f: => R }: R = f()
|
|
13
|
-
|
|
14
|
-
// String ops
|
|
15
|
-
// ==========
|
|
16
|
-
extern pure def infixConcat(s1: String, s2: String): String =
|
|
17
|
-
"(string-append ${s1} ${s2})"
|
|
18
|
-
|
|
19
|
-
// TODO implement
|
|
20
|
-
extern pure def show[R](value: R): String =
|
|
21
|
-
"(show_impl ${value})"
|
|
22
|
-
|
|
23
|
-
extern io def println[R](r: R): Unit =
|
|
24
|
-
"(println_impl ${r})"
|
|
25
|
-
|
|
26
|
-
extern io def error[R](msg: String): R =
|
|
27
|
-
"(raise ${msg})"
|
|
28
|
-
|
|
29
|
-
extern io def random(): Double =
|
|
30
|
-
"(random 1.0)"
|
|
31
|
-
|
|
32
|
-
// Math ops
|
|
33
|
-
// ========
|
|
34
|
-
extern pure def infixAdd(x: Int, y: Int): Int =
|
|
35
|
-
"(+ ${x} ${y})"
|
|
36
|
-
|
|
37
|
-
extern pure def infixMul(x: Int, y: Int): Int =
|
|
38
|
-
"(* ${x} ${y})"
|
|
39
|
-
|
|
40
|
-
extern pure def infixDiv(x: Int, y: Int): Int =
|
|
41
|
-
"(floor (/ ${x} ${y}))"
|
|
42
|
-
|
|
43
|
-
extern pure def infixSub(x: Int, y: Int): Int =
|
|
44
|
-
"(- ${x} ${y})"
|
|
45
|
-
|
|
46
|
-
extern pure def mod(x: Int, y: Int): Int =
|
|
47
|
-
"(modulo ${x} ${y})"
|
|
48
|
-
|
|
49
|
-
extern pure def infixAdd(x: Double, y: Double): Double =
|
|
50
|
-
"(+ ${x} ${y})"
|
|
51
|
-
|
|
52
|
-
extern pure def infixMul(x: Double, y: Double): Double =
|
|
53
|
-
"(* ${x} ${y})"
|
|
54
|
-
|
|
55
|
-
extern pure def infixDiv(x: Double, y: Double): Double =
|
|
56
|
-
"(/ ${x} ${y})"
|
|
57
|
-
|
|
58
|
-
extern pure def infixSub(x: Double, y: Double): Double =
|
|
59
|
-
"(- ${x} ${y})"
|
|
60
|
-
|
|
61
|
-
extern pure def cos(x: Double): Double =
|
|
62
|
-
"(cos ${x})"
|
|
63
|
-
|
|
64
|
-
extern pure def sin(x: Double): Double =
|
|
65
|
-
"(sin ${x})"
|
|
66
|
-
|
|
67
|
-
extern pure def atan(x: Double): Double =
|
|
68
|
-
"(atan ${x})"
|
|
69
|
-
|
|
70
|
-
extern pure def tan(x: Double): Double =
|
|
71
|
-
"(tan ${x})"
|
|
72
|
-
|
|
73
|
-
extern pure def sqrt(x: Double): Double =
|
|
74
|
-
"(sqrt ${x})"
|
|
75
|
-
|
|
76
|
-
extern pure def square(x: Double): Double =
|
|
77
|
-
"(* ${x} ${x})"
|
|
78
|
-
|
|
79
|
-
extern pure def log(x: Double): Double =
|
|
80
|
-
"(log ${x})"
|
|
81
|
-
|
|
82
|
-
extern pure def log1p(x: Double): Double =
|
|
83
|
-
"(log (+ ${x} 1))"
|
|
84
|
-
|
|
85
|
-
extern pure def exp(x: Double): Double =
|
|
86
|
-
"(exp ${x})"
|
|
87
|
-
|
|
88
|
-
// since we do not have "extern val", yet
|
|
89
|
-
extern pure def _pi(): Double =
|
|
90
|
-
"(* 4 (atan 1))"
|
|
91
|
-
|
|
92
|
-
val PI: Double = _pi()
|
|
93
|
-
|
|
94
|
-
extern pure def toInt(d: Double): Int =
|
|
95
|
-
"(round ${d})"
|
|
96
|
-
|
|
97
|
-
extern pure def toDouble(d: Int): Double =
|
|
98
|
-
"${d}"
|
|
99
|
-
|
|
100
|
-
def min(n: Int, m: Int): Int =
|
|
101
|
-
if (n < m) n else m
|
|
102
|
-
|
|
103
|
-
def max(n: Int, m: Int): Int =
|
|
104
|
-
if (n > m) n else m
|
|
105
|
-
|
|
106
|
-
// Comparison ops
|
|
107
|
-
// ==============
|
|
108
|
-
extern pure def infixEq[R](x: R, y: R): Boolean =
|
|
109
|
-
"(equal_impl ${x} ${y})"
|
|
110
|
-
|
|
111
|
-
extern pure def infixNeq[R](x: R, y: R): Boolean =
|
|
112
|
-
"(not (equal_impl ${x} ${y}))"
|
|
113
|
-
|
|
114
|
-
extern pure def infixLt(x: Int, y: Int): Boolean =
|
|
115
|
-
"(< ${x} ${y})"
|
|
116
|
-
|
|
117
|
-
extern pure def infixLte(x: Int, y: Int): Boolean =
|
|
118
|
-
"(<= ${x} ${y})"
|
|
119
|
-
|
|
120
|
-
extern pure def infixGt(x: Int, y: Int): Boolean =
|
|
121
|
-
"(> ${x} ${y})"
|
|
122
|
-
|
|
123
|
-
extern pure def infixGte(x: Int, y: Int): Boolean =
|
|
124
|
-
"(>= ${x} ${y})"
|
|
125
|
-
|
|
126
|
-
extern pure def infixLt(x: Double, y: Double): Boolean =
|
|
127
|
-
"(< ${x} ${y})"
|
|
128
|
-
|
|
129
|
-
extern pure def infixLte(x: Double, y: Double): Boolean =
|
|
130
|
-
"(<= ${x} ${y})"
|
|
131
|
-
|
|
132
|
-
extern pure def infixGt(x: Double, y: Double): Boolean =
|
|
133
|
-
"(> ${x} ${y})"
|
|
134
|
-
|
|
135
|
-
extern pure def infixGte(x: Double, y: Double): Boolean =
|
|
136
|
-
"(>= ${x} ${y})"
|
|
137
|
-
|
|
138
|
-
// Boolean ops
|
|
139
|
-
// ===========
|
|
140
|
-
// for now those are considered eager
|
|
141
|
-
extern pure def not(b: Boolean): Boolean =
|
|
142
|
-
"(not ${b})"
|
|
143
|
-
|
|
144
|
-
extern pure def infixOr(x: Boolean, y: Boolean): Boolean =
|
|
145
|
-
"(or ${x} ${y})"
|
|
146
|
-
|
|
147
|
-
extern pure def infixAnd(x: Boolean, y: Boolean): Boolean =
|
|
148
|
-
"(and ${x} ${y})"
|
|
149
|
-
|
|
150
|
-
// Should only be used internally since values in Effekt should not be undefined
|
|
151
|
-
extern pure def isUndefined[A](value: A): Boolean =
|
|
152
|
-
"(eq? ${value} #f)"
|
|
153
|
-
|
|
154
|
-
// Pairs
|
|
155
|
-
// =====
|
|
156
|
-
record Tuple2[A, B](first: A, second: B)
|
|
157
|
-
record Tuple3[A, B, C](first: A, second: B, third: C)
|
|
158
|
-
record Tuple4[A, B, C, D](first: A, second: B, third: C, fourth: D)
|
|
159
|
-
record Tuple5[A, B, C, D, E](first: A, second: B, third: C, fourth: D, fifth: E)
|
|
160
|
-
record Tuple6[A, B, C, D, E, F](first: A, second: B, third: C, fourth: D, fifth: E, sixth: F)
|
|
161
|
-
|
|
162
|
-
// Exceptions
|
|
163
|
-
// ==========
|
|
164
|
-
// a fatal runtime error that cannot be caught
|
|
165
|
-
extern io def panic[R](msg: String): R =
|
|
166
|
-
"(raise ${msg})"
|
|
167
|
-
|
|
168
|
-
interface Exception[E] {
|
|
169
|
-
def raise(exception: E, msg: String): Nothing
|
|
170
|
-
}
|
|
171
|
-
record RuntimeError()
|
|
172
|
-
|
|
173
|
-
def raise[A](msg: String): A / Exception[RuntimeError] = do raise(RuntimeError(), msg) match {}
|
|
174
|
-
def raise[A, E](exception: E, msg: String): A / Exception[E] = do raise(exception, msg) match {}
|
|
175
|
-
|
|
176
|
-
// converts exceptions of (static) type E to an uncatchable panic that aborts the program
|
|
177
|
-
def panicOn[E] { prog: => Unit / Exception[E] }: Unit =
|
|
178
|
-
try { prog() } with Exception[E] { def raise(exception: E, msg: String) = panic(msg) }
|
|
179
|
-
|
|
180
|
-
// reports exceptions of (static) type E to the console
|
|
181
|
-
def report[E] { prog: => Unit / Exception[E] }: Unit =
|
|
182
|
-
try { prog() } with Exception[E] { def raise(exception: E, msg: String) = println(msg) }
|
|
183
|
-
|
|
184
|
-
// ignores exceptions of (static) type E
|
|
185
|
-
// TODO this should be called "ignore" but that name currently clashes with internal pattern matching names on $effekt
|
|
186
|
-
def ignoring[E] { prog: => Unit / Exception[E] }: Unit =
|
|
187
|
-
try { prog() } with Exception[E] { def raise(exception: E, msg: String) = () }
|
|
188
|
-
|
|
189
|
-
// Control Flow
|
|
190
|
-
// ============
|
|
191
|
-
interface Control {
|
|
192
|
-
def break(): Unit
|
|
193
|
-
def continue(): Unit
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
def loop { f: () => Unit / Control }: Unit = try {
|
|
197
|
-
def go(): Unit = { f(); go() }
|
|
198
|
-
go()
|
|
199
|
-
} with Control {
|
|
200
|
-
def break() = ()
|
|
201
|
-
def continue() = loop { f }
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Calls provided action repeatedly. `start` is inclusive, `end` is not.
|
|
206
|
-
*/
|
|
207
|
-
def each(start: Int, end: Int) { action: (Int) => Unit / Control } = {
|
|
208
|
-
var i = start;
|
|
209
|
-
loop {
|
|
210
|
-
if (i < end) { val el = i; i = i + 1; action(el) }
|
|
211
|
-
else { do break() }
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
def repeat(n: Int) { action: () => Unit / Control } = each(0, n) { n => action() }
|
|
216
|
-
|
|
217
|
-
// Benchmarking
|
|
218
|
-
// ============
|
|
219
|
-
// should only be used with pure blocks
|
|
220
|
-
extern control def measure(warmup: Int, iterations: Int) { block: => Unit }: Unit =
|
|
221
|
-
"(display (measure ${box block} ${warmup} ${iterations}))"
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
; Matcher = (SCRUTINEE, ANS -> () -> R, () -> R, (ANS -> () -> R) -> R) -> R
|
|
2
|
-
|
|
3
|
-
(define done (lambda (matched) (matched)))
|
|
4
|
-
|
|
5
|
-
(define (any m matched failed k)
|
|
6
|
-
(k (matched m)))
|
|
7
|
-
|
|
8
|
-
(define (ignore m matched failed k)
|
|
9
|
-
(k matched))
|
|
10
|
-
|
|
11
|
-
(define (literal l)
|
|
12
|
-
(lambda (m matched failed k)
|
|
13
|
-
(if (equal_impl m l)
|
|
14
|
-
(k matched)
|
|
15
|
-
(failed))))
|
|
16
|
-
|
|
17
|
-
(define (bind p)
|
|
18
|
-
(lambda (m matched failed k)
|
|
19
|
-
(p m (matched m) failed k)))
|
|
20
|
-
|
|
21
|
-
;; for this record
|
|
22
|
-
; (define-record Pair (fst snd))
|
|
23
|
-
|
|
24
|
-
;; this is what we need to generate
|
|
25
|
-
; (define (match-Pair p1 p2)
|
|
26
|
-
; (lambda (m matched failed k)
|
|
27
|
-
; (if (Pair? m)
|
|
28
|
-
; (p1 (Pair-fst m) matched failed (lambda (matched)
|
|
29
|
-
; (p2 (Pair-snd m) matched failed k)))
|
|
30
|
-
; (failed))))
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
(define-syntax define-matcher
|
|
34
|
-
(syntax-rules ()
|
|
35
|
-
[(_ name pred ())
|
|
36
|
-
(define (name)
|
|
37
|
-
(lambda (sc matched failed k)
|
|
38
|
-
(if (pred sc) (k matched) (failed))))]
|
|
39
|
-
[(_ name pred ((p1 sel1) (p2 sel2) ...))
|
|
40
|
-
(define (name p1 p2 ...)
|
|
41
|
-
(lambda (m matched failed k)
|
|
42
|
-
;; has correct tag?
|
|
43
|
-
(if (pred m)
|
|
44
|
-
(match-fields m matched failed k ([p1 sel1] [p2 sel2] ...))
|
|
45
|
-
(failed))))]))
|
|
46
|
-
|
|
47
|
-
(define-syntax match-fields
|
|
48
|
-
(syntax-rules ()
|
|
49
|
-
[(_ m matched failed k ()) (k matched)]
|
|
50
|
-
[(_ m matched failed k ([p1 sel1] [p2 sel2] ...))
|
|
51
|
-
(p1 (sel1 m) matched failed (lambda (matched)
|
|
52
|
-
(match-fields m matched failed k ([p2 sel2] ...))))]))
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
; forces the pattern match
|
|
56
|
-
(define-syntax pattern-match
|
|
57
|
-
(syntax-rules ()
|
|
58
|
-
[(_ m ()) (raise "no patterns provided")]
|
|
59
|
-
[(_ m ([p1 k1] [p2 k2]...))
|
|
60
|
-
(p1 m k1 (lambda () (pattern-match m ([p2 k2] ...))) done)]))
|
|
61
|
-
|
|
62
|
-
;; Examples
|
|
63
|
-
|
|
64
|
-
; (define-matcher match-Pair2 Pair? ([p1 Pair-fst] [p2 Pair-snd]))
|
|
65
|
-
|
|
66
|
-
; (define (match sc p matched)
|
|
67
|
-
; (p sc matched abort done))
|
|
68
|
-
|
|
69
|
-
; (display (match (make-Pair 1 2)
|
|
70
|
-
; (match-Pair2 any any)
|
|
71
|
-
; (lambda (x) (lambda (y) (lambda () (+ x y))))))
|
|
72
|
-
|
|
73
|
-
; (display (match 3
|
|
74
|
-
; (match-Pair2 any any)
|
|
75
|
-
; (lambda (x) (lambda (y) (lambda () (+ x y))))))
|
|
76
|
-
|
|
77
|
-
; (display (match (make-Pair 1 2)
|
|
78
|
-
; (match-Pair2 any (match-Pair2 ignore any))
|
|
79
|
-
; (lambda (x) (lambda (y) (lambda () (+ x y))))))
|
|
80
|
-
|
|
81
|
-
; (display (match (make-Pair 1 (make-Pair 2 3))
|
|
82
|
-
; (match-Pair2 any (match-Pair2 ignore any))
|
|
83
|
-
; (lambda (x) (lambda (y) (lambda () (+ x y))))))
|
|
84
|
-
|
|
85
|
-
; (display (match (make-Pair (make-Pair 1 2) (make-Pair 3 4))
|
|
86
|
-
; (match-Pair (match-Pair ignore any) (match-Pair ignore any))
|
|
87
|
-
; (lambda (x) (lambda (y) (lambda () (+ x y))))))
|
|
88
|
-
|
|
89
|
-
; (display (match (make-Pair (make-Pair 1 2) (make-Pair 10 15))
|
|
90
|
-
; (match-Pair2 (match-Pair2 any ignore) (match-Pair2 ignore any))
|
|
91
|
-
; (lambda (x) (lambda (y) (lambda () (+ x y))))))
|
|
92
|
-
|
|
93
|
-
; (display (match (make-Pair (make-Pair 1 2) (make-Pair 10 15))
|
|
94
|
-
; (match-Pair2 (match-Pair2 any ignore) (match-Pair2 ignore any))
|
|
95
|
-
; (lambda (x) (lambda (y) (lambda () (+ x y))))))
|
|
96
|
-
|
|
97
|
-
; (display (pattern-match (make-Pair 1 2)
|
|
98
|
-
; ([(match-Pair2 (match-Pair2 any ignore) (match-Pair2 ignore any))
|
|
99
|
-
; (lambda (x) (lambda (y) (lambda () (+ x y))))]
|
|
100
|
-
; [any (lambda (x) (lambda () (Pair-snd x)))])))
|