@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.
Files changed (96) hide show
  1. package/bin/effekt +0 -0
  2. package/bin/effekt.sh +1 -1
  3. package/libraries/chez/common/effekt_primitives.ss +10 -2
  4. package/libraries/chez/common/immutable/cslist.effekt +13 -7
  5. package/libraries/chez/common/mutable/dict.effekt +8 -10
  6. package/libraries/chez/common/text/regex.effekt +7 -9
  7. package/libraries/common/args.effekt +95 -0
  8. package/libraries/common/array.effekt +225 -0
  9. package/libraries/common/bench.effekt +60 -0
  10. package/libraries/common/buffer.effekt +123 -0
  11. package/libraries/common/bytes.effekt +125 -0
  12. package/libraries/{chez/common/immutable → common}/dequeue.effekt +18 -4
  13. package/libraries/common/effekt.effekt +764 -0
  14. package/libraries/common/exception.effekt +122 -0
  15. package/libraries/common/io/console.effekt +66 -0
  16. package/libraries/common/io/error.effekt +365 -0
  17. package/libraries/common/io/files.effekt +282 -0
  18. package/libraries/common/io/network.effekt +105 -0
  19. package/libraries/common/io/time.effekt +15 -0
  20. package/libraries/common/io.effekt +158 -0
  21. package/libraries/{llvm/immutable → common}/list.effekt +83 -74
  22. package/libraries/common/option.effekt +72 -0
  23. package/libraries/common/process.effekt +10 -0
  24. package/libraries/common/queue.effekt +140 -0
  25. package/libraries/common/ref.effekt +63 -0
  26. package/libraries/common/result.effekt +45 -0
  27. package/libraries/{ml/immutable → common}/seq.effekt +30 -19
  28. package/libraries/common/string.effekt +395 -0
  29. package/libraries/common/test.effekt +98 -0
  30. package/libraries/js/effekt_builtins.js +37 -6
  31. package/libraries/js/io.js +143 -0
  32. package/libraries/js/mutable/map.effekt +8 -9
  33. package/libraries/js/text/regex.effekt +7 -8
  34. package/libraries/js/unsafe/cont.effekt +2 -2
  35. package/libraries/js/web/dom.effekt +13 -13
  36. package/libraries/llvm/array.c +53 -0
  37. package/libraries/llvm/buffer.c +181 -76
  38. package/libraries/llvm/forward-declare-c.ll +27 -8
  39. package/libraries/llvm/io.c +543 -1
  40. package/libraries/llvm/io.ll +19 -0
  41. package/libraries/llvm/main.c +3 -1
  42. package/libraries/llvm/ref.c +45 -0
  43. package/libraries/llvm/rts.ll +496 -354
  44. package/libraries/llvm/types.c +23 -0
  45. package/libraries/ml/effekt.sml +2 -0
  46. package/libraries/ml/internal/mllist.effekt +9 -0
  47. package/libraries/ml/internal/mloption.effekt +18 -0
  48. package/libraries/ml/random.effekt +9 -9
  49. package/libraries/ml/text/regex.effekt +14 -19
  50. package/licenses/eclipse public license, version 2.0 - epl-2.0.html +2 -2
  51. package/licenses/mit license - mit-license.html +527 -57
  52. package/licenses/the bsd license - bsd-license.html +530 -55
  53. package/licenses/the mit license - mit.html +528 -58
  54. package/package.json +2 -2
  55. package/libraries/chez/callcc/effekt.effekt +0 -221
  56. package/libraries/chez/common/effekt_matching.ss +0 -100
  57. package/libraries/chez/common/immutable/list.effekt +0 -643
  58. package/libraries/chez/common/immutable/option.effekt +0 -39
  59. package/libraries/chez/common/immutable/result.effekt +0 -29
  60. package/libraries/chez/common/io/args.effekt +0 -20
  61. package/libraries/chez/common/mutable/array.effekt +0 -27
  62. package/libraries/chez/common/mutable/heap.effekt +0 -12
  63. package/libraries/chez/common/test.effekt +0 -59
  64. package/libraries/chez/common/text/string.effekt +0 -46
  65. package/libraries/chez/lift/effekt.effekt +0 -217
  66. package/libraries/chez/monadic/effekt.effekt +0 -218
  67. package/libraries/js/effekt.effekt +0 -284
  68. package/libraries/js/effekt_matching.js +0 -79
  69. package/libraries/js/immutable/dequeue.effekt +0 -78
  70. package/libraries/js/immutable/list.effekt +0 -643
  71. package/libraries/js/immutable/option.effekt +0 -49
  72. package/libraries/js/immutable/result.effekt +0 -29
  73. package/libraries/js/io/args.effekt +0 -9
  74. package/libraries/js/io/async.effekt +0 -28
  75. package/libraries/js/io/async.js +0 -2
  76. package/libraries/js/io/file.effekt +0 -50
  77. package/libraries/js/io/file_include.js +0 -13
  78. package/libraries/js/mutable/array.effekt +0 -98
  79. package/libraries/js/mutable/heap.effekt +0 -32
  80. package/libraries/js/test.effekt +0 -59
  81. package/libraries/js/text/string.effekt +0 -64
  82. package/libraries/llvm/effekt.effekt +0 -243
  83. package/libraries/llvm/immutable/option.effekt +0 -53
  84. package/libraries/llvm/immutable/result.effekt +0 -29
  85. package/libraries/llvm/io/args.effekt +0 -24
  86. package/libraries/llvm/text/string.effekt +0 -179
  87. package/libraries/ml/effekt.effekt +0 -267
  88. package/libraries/ml/immutable/dequeue.effekt +0 -81
  89. package/libraries/ml/immutable/list.effekt +0 -674
  90. package/libraries/ml/immutable/option.effekt +0 -53
  91. package/libraries/ml/immutable/result.effekt +0 -29
  92. package/libraries/ml/internal/option.effekt +0 -18
  93. package/libraries/ml/io/args.effekt +0 -41
  94. package/libraries/ml/mutable/array.effekt +0 -43
  95. package/libraries/ml/test.effekt +0 -60
  96. 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 immutable/dequeue
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]): Boolean = dq match {
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))