@effekt-lang/effekt 0.2.2 → 0.4.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 +6 -18
- 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 +68 -0
- package/libraries/common/array.effekt +220 -0
- package/libraries/common/bench.effekt +86 -0
- package/libraries/common/buffer.effekt +123 -0
- package/libraries/common/bytes.effekt +125 -0
- package/libraries/{js/immutable → common}/dequeue.effekt +18 -4
- package/libraries/common/effekt.effekt +725 -0
- package/libraries/common/exception.effekt +121 -0
- package/libraries/common/io/console.effekt +62 -0
- package/libraries/common/io/error.effekt +474 -0
- package/libraries/common/io/filesystem.effekt +274 -0
- package/libraries/common/io/network.effekt +81 -0
- package/libraries/common/io/time.effekt +12 -0
- package/libraries/common/io.effekt +88 -0
- package/libraries/{llvm/immutable → common}/list.effekt +101 -74
- package/libraries/common/option.effekt +72 -0
- package/libraries/common/process.effekt +9 -0
- package/libraries/common/queue.effekt +140 -0
- package/libraries/common/ref.effekt +60 -0
- package/libraries/common/result.effekt +45 -0
- package/libraries/{ml/immutable → common}/seq.effekt +30 -19
- package/libraries/common/string/tty.effekt +66 -0
- package/libraries/common/string.effekt +361 -0
- package/libraries/common/test.effekt +160 -0
- package/libraries/js/effekt_builtins.js +37 -6
- 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 +423 -1
- package/libraries/llvm/main.c +6 -1
- package/libraries/llvm/ref.c +45 -0
- package/libraries/llvm/rts.ll +515 -354
- package/libraries/llvm/types.c +32 -0
- package/licenses/eclipse public license, version 2.0 - epl-2.0.html +4 -4
- package/licenses/mit license - mit-license.html +532 -62
- package/licenses/the bsd license - bsd-license.html +535 -60
- package/licenses/the mit license - mit.html +532 -62
- 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/dequeue.effekt +0 -78
- 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/lift/effekt.ss +0 -118
- 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/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/effekt.sml +0 -63
- 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/random.effekt +0 -85
- package/libraries/ml/test.effekt +0 -60
- package/libraries/ml/text/regex.effekt +0 -107
- package/libraries/ml/text/string.effekt +0 -81
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
module bytes
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A memory managed, mutable, fixed-length buffer of bytes.
|
|
5
|
+
*/
|
|
6
|
+
extern type Bytes
|
|
7
|
+
// = llvm "%Pos"
|
|
8
|
+
// = js "Uint8Array"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Allocates new bytes with the given `capacity`, setting its values to `0`.
|
|
12
|
+
*/
|
|
13
|
+
extern io def bytes(capacity: Int): Bytes =
|
|
14
|
+
js "(new Uint8Array(${capacity}))"
|
|
15
|
+
llvm """
|
|
16
|
+
%buf = call %Pos @c_buffer_construct_uninitialized(i64 ${capacity})
|
|
17
|
+
ret %Pos %buf
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
def copy(b: Bytes): Bytes = {
|
|
21
|
+
val len = b.size
|
|
22
|
+
val clone = bytes(len)
|
|
23
|
+
copy(b, clone, 0, 0, len)
|
|
24
|
+
clone
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
extern io def copy(from: Bytes, to: Bytes, startFrom: Int, startTo: Int, length: Int): Unit =
|
|
28
|
+
js "bytes$copy(${from}, ${to}, ${startFrom}, ${startTo}, ${length})"
|
|
29
|
+
llvm """
|
|
30
|
+
call void @c_buffer_copy(%Pos ${from}, %Pos ${to}, i64 ${startFrom}, i64 ${startTo}, i64 ${length})
|
|
31
|
+
; return Unit
|
|
32
|
+
ret %Pos zeroinitializer
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
extern pure def size(b: Bytes): Int =
|
|
36
|
+
js "${b}.length"
|
|
37
|
+
llvm """
|
|
38
|
+
%size = call i64 @c_buffer_length(%Pos ${b})
|
|
39
|
+
ret i64 %size
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
extern io def read(b: Bytes, index: Int): Byte =
|
|
43
|
+
js "(${b})[${index}]"
|
|
44
|
+
llvm """
|
|
45
|
+
%byte = call i8 @c_buffer_index(%Pos ${b}, i64 ${index})
|
|
46
|
+
ret i8 %byte
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
// TODO should return the number of bytes written.
|
|
50
|
+
extern io def write(b: Bytes, index: Int, value: Byte): Unit =
|
|
51
|
+
js "bytes$set(${b}, ${index}, ${value})"
|
|
52
|
+
llvm """
|
|
53
|
+
call void @c_buffer_set(%Pos ${b}, i64 ${index}, i8 ${value})
|
|
54
|
+
; return Unit
|
|
55
|
+
ret %Pos zeroinitializer
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Returns an *aliased* slice of b starting at offset with the given length
|
|
60
|
+
*/
|
|
61
|
+
def slice(b: Bytes, offset: Int, length: Int): Bytes = {
|
|
62
|
+
def validOffset() = offset >= 0 && offset < b.size
|
|
63
|
+
def validLength() = length >= 0 && (offset + length) <= b.size
|
|
64
|
+
if (validOffset() && validLength()) unsafe::slice(b, offset, length)
|
|
65
|
+
else panic("Invalid slice of bytes (size: " ++ b.size.show ++ ", offset: " ++ offset.show ++ ", length: " ++ length.show ++ ")")
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Returns a view into the buffer, with the length truncated to n
|
|
71
|
+
*/
|
|
72
|
+
def truncated(b: Bytes, n: Int): Bytes =
|
|
73
|
+
b.slice(0, n)
|
|
74
|
+
|
|
75
|
+
extern pure def fromUTF8(s: String): Bytes =
|
|
76
|
+
js "(new TextEncoder().encode(${s}))"
|
|
77
|
+
llvm """
|
|
78
|
+
%copy = call %Pos @c_buffer_clone(%Pos ${s})
|
|
79
|
+
ret %Pos %copy
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
extern pure def toUTF8(b: Bytes): String =
|
|
83
|
+
js "(new TextDecoder('utf-8').decode(${b}))"
|
|
84
|
+
// assuming the buffer is already in UTF-8
|
|
85
|
+
llvm """
|
|
86
|
+
%copy = call %Pos @c_buffer_clone(%Pos ${b})
|
|
87
|
+
ret %Pos %copy
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
namespace unsafe {
|
|
91
|
+
/**
|
|
92
|
+
* Unsafe: offset and length are not checked.
|
|
93
|
+
*/
|
|
94
|
+
extern io def slice(b: Bytes, offset: Int, length: Int): Bytes =
|
|
95
|
+
js "new Uint8Array(${b}.buffer, ${offset}, ${length})"
|
|
96
|
+
llvm """
|
|
97
|
+
%buf = call %Pos @c_buffer_slice(%Pos ${b}, i64 ${offset}, i64 ${length})
|
|
98
|
+
ret %Pos %buf
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
extern js """
|
|
105
|
+
function bytes$set(bytes, index, value) {
|
|
106
|
+
bytes[index] = value;
|
|
107
|
+
return $effekt.unit;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function bytes$clone(original) {
|
|
111
|
+
let copy = new Uint8Array(original.length);
|
|
112
|
+
copy.set(original);
|
|
113
|
+
return copy;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function bytes$copy(from, to, startFrom, startTo, length) {
|
|
117
|
+
// Check bounds
|
|
118
|
+
if (startFrom + length > from.length || startTo + length > to.length) {
|
|
119
|
+
throw new RangeError('Index out of bounds');
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Create a subarray of 'from' and set it into 'to'
|
|
123
|
+
to.set(from.subarray(startFrom, startFrom + length), startTo);
|
|
124
|
+
}
|
|
125
|
+
"""
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
module
|
|
1
|
+
module dequeue
|
|
2
2
|
|
|
3
|
-
import immutable/list
|
|
4
|
-
import immutable/option
|
|
5
3
|
|
|
6
4
|
// An implementation of a functional dequeue, using Okasaki's
|
|
7
5
|
// bankers dequeue implementation.
|
|
@@ -12,7 +10,7 @@ record Dequeue[R](front: List[R], frontSize: Int, rear: List[R], rearSize: Int)
|
|
|
12
10
|
|
|
13
11
|
def emptyQueue[R](): Dequeue[R] = Dequeue(Nil(), 0, Nil(), 0)
|
|
14
12
|
|
|
15
|
-
def isEmpty[R](dq: Dequeue[R]):
|
|
13
|
+
def isEmpty[R](dq: Dequeue[R]): Bool = dq match {
|
|
16
14
|
case Dequeue(f, fs, r, rs) => (fs == 0) && (rs == 0)
|
|
17
15
|
}
|
|
18
16
|
|
|
@@ -76,3 +74,19 @@ def popBack[R](dq: Dequeue[R]): Option[(R, Dequeue[R])] = dq match {
|
|
|
76
74
|
case Dequeue(f, fs, Cons(x, rest), rs) =>
|
|
77
75
|
Some((x, Dequeue(f, fs, rest, rs - 1).check))
|
|
78
76
|
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def show[A](d: Dequeue[A]) { showA: A => String }: String = {
|
|
80
|
+
val Dequeue(front, frontSize, rear, rearSize) = d;
|
|
81
|
+
"Dequeue(" ++ show(front){showA} ++ ", " ++ show(frontSize) ++ ", " ++
|
|
82
|
+
show(rear){showA} ++ ", " ++ show(rearSize) ++ ")"
|
|
83
|
+
}
|
|
84
|
+
def show(l: Dequeue[Int]): String = show(l) { e => show(e) }
|
|
85
|
+
def show(l: Dequeue[Double]): String = show(l) { e => show(e) }
|
|
86
|
+
def show(l: Dequeue[Bool]): String = show(l) { e => show(e) }
|
|
87
|
+
def show(l: Dequeue[String]): String = show(l) { e => e }
|
|
88
|
+
|
|
89
|
+
def println(l: Dequeue[Int]): Unit = println(show(l))
|
|
90
|
+
def println(l: Dequeue[Double]): Unit = println(show(l))
|
|
91
|
+
def println(l: Dequeue[Bool]): Unit = println(show(l))
|
|
92
|
+
def println(l: Dequeue[String]): Unit = println(show(l))
|