@effekt-lang/effekt 0.45.0 → 0.47.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/libraries/chez/common/immutable/cslist.effekt +6 -6
- package/libraries/chez/common/mutable/dict.effekt +7 -7
- package/libraries/common/args.effekt +10 -10
- package/libraries/common/array.effekt +4 -4
- package/libraries/common/bench.effekt +2 -2
- package/libraries/common/buffer.effekt +3 -3
- package/libraries/common/bytearray.effekt +14 -7
- package/libraries/common/char.effekt +8 -8
- package/libraries/common/effekt.effekt +71 -71
- package/libraries/common/exception.effekt +1 -1
- package/libraries/common/io/console.effekt +4 -4
- package/libraries/common/io/error.effekt +1 -1
- package/libraries/common/io/filesystem.effekt +7 -7
- package/libraries/common/io/network.effekt +5 -5
- package/libraries/common/io/time.effekt +1 -1
- package/libraries/common/io.effekt +6 -6
- package/libraries/common/process.effekt +1 -1
- package/libraries/common/queue.effekt +2 -2
- package/libraries/common/ref.effekt +4 -4
- package/libraries/common/regex.effekt +4 -4
- package/libraries/common/string.effekt +5 -5
- package/libraries/js/mutable/map.effekt +5 -5
- package/libraries/js/web/dom.effekt +11 -11
- package/licenses/eclipse public license, version 2.0 - epl-2.0.html +2 -2
- package/licenses/mit license - mit-license.html +22 -16
- package/licenses/the bsd license - bsd-license.html +22 -16
- package/licenses/the mit license - mit.html +19 -19
- package/package.json +1 -1
package/bin/effekt
CHANGED
|
Binary file
|
|
@@ -5,21 +5,21 @@ import array
|
|
|
5
5
|
|
|
6
6
|
// a chez scheme cons list
|
|
7
7
|
extern type CSList[A]
|
|
8
|
-
extern
|
|
8
|
+
extern def cons[A](el: A, rest: CSList[A]) at {}: CSList[A] =
|
|
9
9
|
chez "(cons ${el} ${rest})"
|
|
10
10
|
|
|
11
|
-
extern
|
|
11
|
+
extern def nil[A]() at {}: CSList[A] =
|
|
12
12
|
chez "(list)"
|
|
13
13
|
|
|
14
|
-
extern
|
|
14
|
+
extern def isEmpty[A](l: CSList[A]) at {}: Bool =
|
|
15
15
|
chez "(null? ${l})"
|
|
16
16
|
|
|
17
17
|
// unsafe!
|
|
18
|
-
extern
|
|
18
|
+
extern def head[A](l: CSList[A]) at {}: A =
|
|
19
19
|
chez "(car ${l})"
|
|
20
20
|
|
|
21
21
|
// unsafe!
|
|
22
|
-
extern
|
|
22
|
+
extern def tail[A](l: CSList[A]) at {}: CSList[A] =
|
|
23
23
|
chez "(cdr ${l})"
|
|
24
24
|
|
|
25
25
|
|
|
@@ -33,5 +33,5 @@ def fromChez[A](l: CSList[A]): List[A] =
|
|
|
33
33
|
|
|
34
34
|
// Old From Chez
|
|
35
35
|
// -------------
|
|
36
|
-
extern
|
|
36
|
+
extern def toArray[A](l: CSList[A]) at {}: Array[A] =
|
|
37
37
|
chez "(list->vector ${l})"
|
|
@@ -3,25 +3,25 @@ module mutable/dict
|
|
|
3
3
|
// https://cisco.github.io/ChezScheme/csug9.5/compat.html#g148
|
|
4
4
|
extern type Dict[K, V]
|
|
5
5
|
|
|
6
|
-
extern
|
|
6
|
+
extern def emptyDict[K, V]() at io: Dict[K, V] =
|
|
7
7
|
chez "(make-eq-hashtable)"
|
|
8
8
|
|
|
9
|
-
extern
|
|
9
|
+
extern def emptyWeakDict[K, V]() at io: Dict[K, V] =
|
|
10
10
|
chez "(make-hash-table #t)"
|
|
11
11
|
|
|
12
|
-
extern
|
|
12
|
+
extern def put[K, V](d: Dict[K, V], key: K, value: V) at io: Unit =
|
|
13
13
|
chez "(put-hash-table! ${d} ${key} ${value})"
|
|
14
14
|
|
|
15
|
-
extern
|
|
15
|
+
extern def get[K, V](d: Dict[K, V], key: K, default: V) at io: V =
|
|
16
16
|
chez "(hashtable-ref ${d} ${key} ${default})"
|
|
17
17
|
|
|
18
|
-
extern
|
|
18
|
+
extern def unsafeGet[K, V](d: Dict[K, V], key: K) at io: V =
|
|
19
19
|
chez "(hashtable-ref ${d} ${key} #f)"
|
|
20
20
|
|
|
21
|
-
extern
|
|
21
|
+
extern def contains[K, V](d: Dict[K, V], key: K) at io: Bool =
|
|
22
22
|
chez "(hashtable-contains? ${d} ${key})"
|
|
23
23
|
|
|
24
|
-
extern
|
|
24
|
+
extern def remove[K, V](d: Dict[K, V], key: K) at io: Unit =
|
|
25
25
|
chez "(remove-hash-table! ${d} ${key})"
|
|
26
26
|
|
|
27
27
|
def get[K, V](d: Dict[K, V], key: K): Option[V] =
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module args
|
|
2
2
|
|
|
3
|
-
extern
|
|
3
|
+
extern def commandLineArgs() at io: List[String] =
|
|
4
4
|
js { js::commandLineArgs() }
|
|
5
5
|
chez { chez::commandLineArgs() }
|
|
6
6
|
llvm { llvm::commandLineArgs() }
|
|
@@ -9,11 +9,11 @@ extern io def commandLineArgs(): List[String] =
|
|
|
9
9
|
namespace js {
|
|
10
10
|
extern type Args // = Array[String]
|
|
11
11
|
|
|
12
|
-
extern
|
|
12
|
+
extern def nativeArgs() at io: Args = js "process.argv.slice(1)"
|
|
13
13
|
|
|
14
|
-
extern
|
|
14
|
+
extern def argCount(args: Args) at io: Int = js "${args}.length"
|
|
15
15
|
|
|
16
|
-
extern
|
|
16
|
+
extern def argument(args: Args, i: Int) at io: String = js "${args}[${i}]"
|
|
17
17
|
|
|
18
18
|
def commandLineArgs(): List[String] = {
|
|
19
19
|
def toList(args: Args, start: Int, acc: List[String]): List[String] =
|
|
@@ -28,16 +28,16 @@ namespace js {
|
|
|
28
28
|
namespace chez {
|
|
29
29
|
extern type Args // = CSList[String]
|
|
30
30
|
|
|
31
|
-
extern
|
|
31
|
+
extern def nativeArgs() at io: Args =
|
|
32
32
|
chez "(cdr (command-line))"
|
|
33
33
|
|
|
34
|
-
extern
|
|
34
|
+
extern def isEmpty(l: Args) at {}: Bool =
|
|
35
35
|
chez "(null? ${l})"
|
|
36
36
|
|
|
37
|
-
extern
|
|
37
|
+
extern def head(l: Args) at {}: String =
|
|
38
38
|
chez "(car ${l})"
|
|
39
39
|
|
|
40
|
-
extern
|
|
40
|
+
extern def tail(l: Args) at {}: Args =
|
|
41
41
|
chez "(cdr ${l})"
|
|
42
42
|
|
|
43
43
|
def toList(l: Args): List[String] =
|
|
@@ -47,13 +47,13 @@ namespace chez {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
namespace llvm {
|
|
50
|
-
extern
|
|
50
|
+
extern def argCount() at io: Int =
|
|
51
51
|
llvm """
|
|
52
52
|
%c = call %Int @c_get_argc()
|
|
53
53
|
ret %Int %c
|
|
54
54
|
"""
|
|
55
55
|
|
|
56
|
-
extern
|
|
56
|
+
extern def argument(i: Int) at io: String =
|
|
57
57
|
llvm """
|
|
58
58
|
%s = call %Pos @c_get_arg(%Int ${i})
|
|
59
59
|
ret %Pos %s
|
|
@@ -42,7 +42,7 @@ exit:
|
|
|
42
42
|
|
|
43
43
|
/// Allocates a new array of size `size`, keeping its values _undefined_.
|
|
44
44
|
/// Prefer using `array` constructor instead to ensure that values are defined.
|
|
45
|
-
extern
|
|
45
|
+
extern def allocate[T](size: Int) at global: Array[T] =
|
|
46
46
|
js "(new Array(${size}))"
|
|
47
47
|
chez "(make-vector ${size})" // creates an array filled with 0s on CS
|
|
48
48
|
llvm """
|
|
@@ -85,7 +85,7 @@ def fromList[T](list: List[T]): Array[T] = {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
/// Gets the length of the array in constant time.
|
|
88
|
-
extern
|
|
88
|
+
extern def size[T](arr: Array[T]) at {}: Int =
|
|
89
89
|
js "${arr}.length"
|
|
90
90
|
chez "(vector-length ${arr})"
|
|
91
91
|
llvm """
|
|
@@ -102,7 +102,7 @@ extern pure def size[T](arr: Array[T]): Int =
|
|
|
102
102
|
/// Unchecked Precondition: `index` is in bounds (0 ≤ index < arr.size)
|
|
103
103
|
///
|
|
104
104
|
/// Prefer using `get` instead.
|
|
105
|
-
extern
|
|
105
|
+
extern def unsafeGet[T](arr: Array[T], index: Int) at global: T =
|
|
106
106
|
js "${arr}[${index}]"
|
|
107
107
|
chez "(vector-ref ${arr} ${index})"
|
|
108
108
|
llvm """
|
|
@@ -129,7 +129,7 @@ extern js """
|
|
|
129
129
|
/// Unchecked Precondition: `index` is in bounds (0 ≤ index < arr.size)
|
|
130
130
|
///
|
|
131
131
|
/// Prefer using `set` instead.
|
|
132
|
-
extern
|
|
132
|
+
extern def unsafeSet[T](arr: Array[T], index: Int, value: T) at global: Unit =
|
|
133
133
|
js "array$set(${arr}, ${index}, ${value})"
|
|
134
134
|
chez "(begin (vector-set! ${arr} ${index} ${value}) #f)"
|
|
135
135
|
llvm """
|
|
@@ -7,7 +7,7 @@ type Nanos = Int
|
|
|
7
7
|
/// The actual precision varies across the different backends.
|
|
8
8
|
/// - js: Milliseconds
|
|
9
9
|
/// - chez: Microseconds
|
|
10
|
-
extern
|
|
10
|
+
extern def timestamp() at io: Nanos =
|
|
11
11
|
js "Date.now() * 1000000"
|
|
12
12
|
chez "(timestamp)"
|
|
13
13
|
llvm """
|
|
@@ -34,7 +34,7 @@ extern jsNode """
|
|
|
34
34
|
///
|
|
35
35
|
/// This timestamp should only be used for **relative** measurements,
|
|
36
36
|
/// as gives no guarantees on the absolute time (unlike a UNIX timestamp).
|
|
37
|
-
extern
|
|
37
|
+
extern def relativeTimestamp() at io: Nanos =
|
|
38
38
|
js "Math.round(performance.now() * 1000000)"
|
|
39
39
|
default { timestamp() }
|
|
40
40
|
|
|
@@ -27,11 +27,11 @@ interface Buffer[T] {
|
|
|
27
27
|
def write(el: T): Unit / Exception[BufferOverflow]
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
def emptyBuffer[T](capacity: Int): Buffer[T] at
|
|
30
|
+
def emptyBuffer[T](capacity: Int): Buffer[T] at global = {
|
|
31
31
|
if (capacity == 1) refBuffer()
|
|
32
32
|
else arrayBuffer(capacity)
|
|
33
33
|
}
|
|
34
|
-
def arrayBuffer[T](initialCapacity: Int): Buffer[T] at
|
|
34
|
+
def arrayBuffer[T](initialCapacity: Int): Buffer[T] at global = {
|
|
35
35
|
// TODO allocate buffer (and array) into a region r.
|
|
36
36
|
val contents = array::allocate[T](initialCapacity)
|
|
37
37
|
val head = ref(0)
|
|
@@ -64,7 +64,7 @@ def arrayBuffer[T](initialCapacity: Int): Buffer[T] at {global} = {
|
|
|
64
64
|
}
|
|
65
65
|
buffer
|
|
66
66
|
}
|
|
67
|
-
def refBuffer[T](): Buffer[T] at
|
|
67
|
+
def refBuffer[T](): Buffer[T] at global = {
|
|
68
68
|
val content = ref(None())
|
|
69
69
|
new Buffer[T] {
|
|
70
70
|
def capacity() = if (content.get.isEmpty) 1 else 0
|
|
@@ -20,7 +20,7 @@ extern type ByteArray
|
|
|
20
20
|
// = chez "bytevector"
|
|
21
21
|
|
|
22
22
|
/// Allocates a new bytearray with the given `size`, its values are undefined.
|
|
23
|
-
extern
|
|
23
|
+
extern def allocate(size: Int) at global: ByteArray =
|
|
24
24
|
js "(new Uint8Array(${size}))"
|
|
25
25
|
llvm """
|
|
26
26
|
%object_size = add i64 ${size}, 16
|
|
@@ -33,8 +33,9 @@ extern global def allocate(size: Int): ByteArray =
|
|
|
33
33
|
ret %Pos %ret_object2
|
|
34
34
|
"""
|
|
35
35
|
chez "(make-bytevector ${size})"
|
|
36
|
+
vm "bytearray::allocate(Int)"
|
|
36
37
|
|
|
37
|
-
extern
|
|
38
|
+
extern def size(arr: ByteArray) at {}: Int =
|
|
38
39
|
js "${arr}.length"
|
|
39
40
|
llvm """
|
|
40
41
|
%size = extractvalue %Pos ${arr}, 0
|
|
@@ -42,8 +43,9 @@ extern pure def size(arr: ByteArray): Int =
|
|
|
42
43
|
ret i64 %size
|
|
43
44
|
"""
|
|
44
45
|
chez "(bytevector-length ${arr})"
|
|
46
|
+
vm "bytearray::size(ByteArray)"
|
|
45
47
|
|
|
46
|
-
extern
|
|
48
|
+
extern def unsafeGet(arr: ByteArray, index: Int) at global: Byte =
|
|
47
49
|
js "(${arr})[${index}]"
|
|
48
50
|
llvm """
|
|
49
51
|
%arr_ptr = extractvalue %Pos ${arr}, 1
|
|
@@ -54,8 +56,9 @@ extern global def unsafeGet(arr: ByteArray, index: Int): Byte =
|
|
|
54
56
|
ret i8 %element
|
|
55
57
|
"""
|
|
56
58
|
chez "(bytevector-u8-ref ${arr} ${index})"
|
|
59
|
+
vm "bytearray::unsafeGet(ByteArray, Int)"
|
|
57
60
|
|
|
58
|
-
extern
|
|
61
|
+
extern def unsafeSet(arr: ByteArray, index: Int, value: Byte) at global: Unit =
|
|
59
62
|
js "bytearray$set(${arr}, ${index}, ${value})"
|
|
60
63
|
llvm """
|
|
61
64
|
%arr_ptr = extractvalue %Pos ${arr}, 1
|
|
@@ -66,6 +69,7 @@ extern global def unsafeSet(arr: ByteArray, index: Int, value: Byte): Unit =
|
|
|
66
69
|
ret %Pos zeroinitializer
|
|
67
70
|
"""
|
|
68
71
|
chez "(bytevector-u8-set! ${arr} ${index} ${value})"
|
|
72
|
+
vm "bytearray::unsafeSet(ByteArray, Int, Byte)"
|
|
69
73
|
|
|
70
74
|
/// Creates a new ByteArray of size `size` filled with the value `init`
|
|
71
75
|
def bytearray(size: Int, init: Byte): ByteArray = {
|
|
@@ -109,20 +113,22 @@ def foreachIndex(arr: ByteArray){ action: (Int, Byte) {Control} => Unit }: Unit
|
|
|
109
113
|
action(i, arr.unsafeGet(i)) {label}
|
|
110
114
|
}
|
|
111
115
|
|
|
112
|
-
extern
|
|
116
|
+
extern def fromString(str: String) at {}: ByteArray =
|
|
113
117
|
js "(new TextEncoder().encode(${str}))"
|
|
114
118
|
llvm """
|
|
115
119
|
ret %Pos ${str}
|
|
116
120
|
"""
|
|
117
121
|
chez "(string->utf8 ${str})"
|
|
122
|
+
vm "bytearray::fromString(String)"
|
|
118
123
|
|
|
119
|
-
extern
|
|
124
|
+
extern def toString(arr: ByteArray) at {}: String =
|
|
120
125
|
js "(new TextDecoder('utf-8').decode(${arr}))"
|
|
121
126
|
// assuming the buffer is already in UTF-8
|
|
122
127
|
llvm """
|
|
123
128
|
ret %Pos ${arr}
|
|
124
129
|
"""
|
|
125
130
|
chez "(utf8->string ${arr})"
|
|
131
|
+
vm "bytearray::toString(ByteArray)"
|
|
126
132
|
|
|
127
133
|
extern js """
|
|
128
134
|
function bytearray$set(bytes, index, value) {
|
|
@@ -169,13 +175,14 @@ extern chez """
|
|
|
169
175
|
[else (loop (+ i 1))]))))
|
|
170
176
|
"""
|
|
171
177
|
|
|
172
|
-
extern
|
|
178
|
+
extern def compareByteArrayImpl(b1: ByteArray, b2: ByteArray) at {}: Int =
|
|
173
179
|
js "bytearray$compare(${b1}, ${b2})"
|
|
174
180
|
llvm """
|
|
175
181
|
%x = call %Int @c_bytearray_compare(%Pos ${b1}, %Pos ${b2})
|
|
176
182
|
ret %Int %x
|
|
177
183
|
"""
|
|
178
184
|
chez "(bytearray$compare ${b1} ${b2})"
|
|
185
|
+
vm "bytearray::compare(ByteArray, ByteArray)"
|
|
179
186
|
|
|
180
187
|
def compareByteArray(b1: ByteArray, b2: ByteArray): Ordering = {
|
|
181
188
|
val ret = compareByteArrayImpl(b1, b2)
|
|
@@ -86,7 +86,7 @@ def isAlphabetic(c: Char): Bool = isLower(c) || isUpper(c)
|
|
|
86
86
|
// Chez: ?
|
|
87
87
|
// LLVM: i64 representing utf-8 (varying length 1-4 bytes)
|
|
88
88
|
|
|
89
|
-
extern
|
|
89
|
+
extern def toString(ch: Char) at {}: String =
|
|
90
90
|
js "String.fromCodePoint(${ch})"
|
|
91
91
|
chez "(string (integer->char ${ch}))"
|
|
92
92
|
llvm """
|
|
@@ -95,20 +95,20 @@ extern pure def toString(ch: Char): String =
|
|
|
95
95
|
"""
|
|
96
96
|
|
|
97
97
|
// Since we currently represent Char by integers in all backends, we could reuse comparison
|
|
98
|
-
extern
|
|
98
|
+
extern def toInt(ch: Char) at {}: Int =
|
|
99
99
|
js "${ch}"
|
|
100
100
|
chez "${ch}"
|
|
101
101
|
llvm "ret %Int ${ch}"
|
|
102
102
|
vm "string::toInt(Char)"
|
|
103
103
|
|
|
104
|
-
extern
|
|
104
|
+
extern def toChar(codepoint: Int) at {}: Char =
|
|
105
105
|
js "${codepoint}"
|
|
106
106
|
chez "${codepoint}"
|
|
107
107
|
llvm "ret %Int ${codepoint}"
|
|
108
108
|
vm "string::toChar(Int)"
|
|
109
109
|
|
|
110
110
|
|
|
111
|
-
extern
|
|
111
|
+
extern def infixLt(x: Char, y: Char) at {}: Bool =
|
|
112
112
|
js "(${x} < ${y})"
|
|
113
113
|
chez "(< ${x} ${y})"
|
|
114
114
|
llvm """
|
|
@@ -119,7 +119,7 @@ extern pure def infixLt(x: Char, y: Char): Bool =
|
|
|
119
119
|
"""
|
|
120
120
|
vm "string::infixLt(Char, Char)"
|
|
121
121
|
|
|
122
|
-
extern
|
|
122
|
+
extern def infixLte(x: Char, y: Char) at {}: Bool =
|
|
123
123
|
js "(${x} <= ${y})"
|
|
124
124
|
chez "(<= ${x} ${y})"
|
|
125
125
|
llvm """
|
|
@@ -130,7 +130,7 @@ extern pure def infixLte(x: Char, y: Char): Bool =
|
|
|
130
130
|
"""
|
|
131
131
|
vm "string::infixLte(Char, Char)"
|
|
132
132
|
|
|
133
|
-
extern
|
|
133
|
+
extern def infixGt(x: Char, y: Char) at {}: Bool =
|
|
134
134
|
js "(${x} > ${y})"
|
|
135
135
|
chez "(> ${x} ${y})"
|
|
136
136
|
llvm """
|
|
@@ -141,7 +141,7 @@ extern pure def infixGt(x: Char, y: Char): Bool =
|
|
|
141
141
|
"""
|
|
142
142
|
vm "string::infixGt(Char, Char)"
|
|
143
143
|
|
|
144
|
-
extern
|
|
144
|
+
extern def infixGte(x: Char, y: Char) at {}: Bool =
|
|
145
145
|
js "(${x} >= ${y})"
|
|
146
146
|
chez "(>= ${x} ${y})"
|
|
147
147
|
llvm """
|
|
@@ -172,6 +172,6 @@ def utf16UnitCount(codepoint: Char): Int = codepoint match {
|
|
|
172
172
|
case c => panic("Not a valid code point")
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
extern
|
|
175
|
+
extern def charWidth(c: Char) at {}: Int =
|
|
176
176
|
// JavaScript strings are UTF-16 where every unicode character after 0xffff takes two units
|
|
177
177
|
js "(${c} > 0xffff) ? 2 : 1"
|