@grain/stdlib 0.5.12 → 0.6.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/CHANGELOG.md +200 -0
- package/LICENSE +1 -1
- package/README.md +25 -2
- package/array.gr +1512 -199
- package/array.md +2032 -94
- package/bigint.gr +239 -140
- package/bigint.md +450 -106
- package/buffer.gr +595 -102
- package/buffer.md +903 -145
- package/bytes.gr +401 -110
- package/bytes.md +551 -63
- package/char.gr +228 -49
- package/char.md +373 -7
- package/exception.gr +26 -12
- package/exception.md +29 -5
- package/float32.gr +130 -109
- package/float32.md +185 -57
- package/float64.gr +112 -99
- package/float64.md +185 -57
- package/hash.gr +47 -37
- package/hash.md +21 -3
- package/int16.gr +430 -0
- package/int16.md +618 -0
- package/int32.gr +200 -269
- package/int32.md +254 -289
- package/int64.gr +142 -225
- package/int64.md +254 -289
- package/int8.gr +511 -0
- package/int8.md +786 -0
- package/json.gr +2084 -0
- package/json.md +608 -0
- package/list.gr +120 -68
- package/list.md +125 -80
- package/map.gr +560 -57
- package/map.md +672 -56
- package/marshal.gr +239 -227
- package/marshal.md +36 -4
- package/number.gr +626 -676
- package/number.md +738 -153
- package/option.gr +33 -35
- package/option.md +58 -42
- package/package.json +2 -2
- package/path.gr +148 -187
- package/path.md +47 -96
- package/pervasives.gr +75 -416
- package/pervasives.md +85 -180
- package/priorityqueue.gr +433 -74
- package/priorityqueue.md +422 -54
- package/queue.gr +362 -80
- package/queue.md +433 -38
- package/random.gr +67 -75
- package/random.md +68 -40
- package/range.gr +135 -63
- package/range.md +198 -43
- package/rational.gr +284 -0
- package/rational.md +545 -0
- package/regex.gr +933 -1066
- package/regex.md +59 -60
- package/result.gr +23 -25
- package/result.md +54 -39
- package/runtime/atof/common.gr +78 -82
- package/runtime/atof/common.md +22 -10
- package/runtime/atof/decimal.gr +102 -127
- package/runtime/atof/decimal.md +28 -7
- package/runtime/atof/lemire.gr +56 -71
- package/runtime/atof/lemire.md +9 -1
- package/runtime/atof/parse.gr +83 -110
- package/runtime/atof/parse.md +12 -2
- package/runtime/atof/slow.gr +28 -35
- package/runtime/atof/slow.md +9 -1
- package/runtime/atof/table.gr +19 -18
- package/runtime/atof/table.md +10 -2
- package/runtime/atoi/parse.gr +153 -136
- package/runtime/atoi/parse.md +50 -1
- package/runtime/bigint.gr +410 -517
- package/runtime/bigint.md +71 -57
- package/runtime/compare.gr +176 -85
- package/runtime/compare.md +31 -1
- package/runtime/dataStructures.gr +144 -32
- package/runtime/dataStructures.md +267 -31
- package/runtime/debugPrint.gr +34 -15
- package/runtime/debugPrint.md +37 -5
- package/runtime/equal.gr +53 -52
- package/runtime/equal.md +30 -1
- package/runtime/exception.gr +38 -47
- package/runtime/exception.md +10 -8
- package/runtime/gc.gr +23 -152
- package/runtime/gc.md +13 -17
- package/runtime/malloc.gr +31 -31
- package/runtime/malloc.md +11 -3
- package/runtime/numberUtils.gr +191 -172
- package/runtime/numberUtils.md +17 -9
- package/runtime/numbers.gr +1695 -1021
- package/runtime/numbers.md +1098 -134
- package/runtime/string.gr +540 -242
- package/runtime/string.md +76 -6
- package/runtime/unsafe/constants.gr +30 -13
- package/runtime/unsafe/constants.md +80 -0
- package/runtime/unsafe/conv.gr +55 -28
- package/runtime/unsafe/conv.md +41 -9
- package/runtime/unsafe/memory.gr +10 -30
- package/runtime/unsafe/memory.md +15 -19
- package/runtime/unsafe/tags.gr +37 -21
- package/runtime/unsafe/tags.md +88 -8
- package/runtime/unsafe/wasmf32.gr +30 -36
- package/runtime/unsafe/wasmf32.md +64 -56
- package/runtime/unsafe/wasmf64.gr +30 -36
- package/runtime/unsafe/wasmf64.md +64 -56
- package/runtime/unsafe/wasmi32.gr +49 -66
- package/runtime/unsafe/wasmi32.md +102 -94
- package/runtime/unsafe/wasmi64.gr +52 -79
- package/runtime/unsafe/wasmi64.md +108 -100
- package/runtime/utils/printing.gr +13 -15
- package/runtime/utils/printing.md +11 -3
- package/runtime/wasi.gr +294 -295
- package/runtime/wasi.md +62 -42
- package/set.gr +574 -64
- package/set.md +634 -54
- package/stack.gr +181 -64
- package/stack.md +271 -42
- package/string.gr +453 -533
- package/string.md +241 -151
- package/uint16.gr +369 -0
- package/uint16.md +585 -0
- package/uint32.gr +470 -0
- package/uint32.md +737 -0
- package/uint64.gr +471 -0
- package/uint64.md +737 -0
- package/uint8.gr +369 -0
- package/uint8.md +585 -0
- package/uri.gr +1093 -0
- package/uri.md +477 -0
- package/{sys → wasi}/file.gr +914 -500
- package/{sys → wasi}/file.md +454 -50
- package/wasi/process.gr +292 -0
- package/{sys → wasi}/process.md +164 -6
- package/wasi/random.gr +77 -0
- package/wasi/random.md +80 -0
- package/{sys → wasi}/time.gr +15 -22
- package/{sys → wasi}/time.md +5 -5
- package/immutablearray.gr +0 -929
- package/immutablearray.md +0 -1038
- package/immutablemap.gr +0 -493
- package/immutablemap.md +0 -479
- package/immutablepriorityqueue.gr +0 -360
- package/immutablepriorityqueue.md +0 -291
- package/immutableset.gr +0 -498
- package/immutableset.md +0 -449
- package/runtime/debug.gr +0 -2
- package/runtime/debug.md +0 -6
- package/runtime/unsafe/errors.gr +0 -36
- package/runtime/unsafe/errors.md +0 -204
- package/sys/process.gr +0 -254
- package/sys/random.gr +0 -79
- package/sys/random.md +0 -66
package/pervasives.gr
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* This module is automatically imported into every Grain program. You can think of it as the global environment. Although it is automatically imported, it can still be imported manually.
|
|
3
3
|
*
|
|
4
|
-
* @example
|
|
4
|
+
* @example from "pervasives" include Pervasives
|
|
5
5
|
*
|
|
6
6
|
* @since v0.1.0
|
|
7
7
|
*/
|
|
8
|
+
@noPervasives
|
|
9
|
+
module Pervasives
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
from "runtime/exception" include Exception
|
|
12
|
+
from "runtime/unsafe/memory" include Memory
|
|
13
|
+
from "runtime/unsafe/wasmi32" include WasmI32
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
from "runtime/equal" include Equal
|
|
16
|
+
use Equal.{ equal as (==) }
|
|
17
|
+
from "runtime/compare" include Compare
|
|
18
|
+
use Compare.{ compare }
|
|
15
19
|
|
|
16
|
-
|
|
20
|
+
from "runtime/numbers" include Numbers
|
|
21
|
+
use Numbers.{
|
|
17
22
|
incr,
|
|
18
23
|
decr,
|
|
19
24
|
(+),
|
|
@@ -21,6 +26,7 @@ import {
|
|
|
21
26
|
(*),
|
|
22
27
|
(/),
|
|
23
28
|
(%),
|
|
29
|
+
(**),
|
|
24
30
|
(<),
|
|
25
31
|
(>),
|
|
26
32
|
(<=),
|
|
@@ -32,56 +38,15 @@ import {
|
|
|
32
38
|
(<<),
|
|
33
39
|
(>>>),
|
|
34
40
|
(>>),
|
|
35
|
-
} from "runtime/numbers"
|
|
36
|
-
import { toString, print, concat as (++) } from "runtime/string"
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @section Types: Type declarations included in the Pervasives module.
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* The type of Grain lists.
|
|
44
|
-
*
|
|
45
|
-
* @example [1, 2, 3]
|
|
46
|
-
* @example []
|
|
47
|
-
*
|
|
48
|
-
* @since v0.1.0
|
|
49
|
-
*/
|
|
50
|
-
export enum List<a> {
|
|
51
|
-
[],
|
|
52
|
-
[...](a, List<a>),
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Grain's type representing something that may or may not contain data.
|
|
57
|
-
* Think of this like a better, type-safe "null".
|
|
58
|
-
*
|
|
59
|
-
* @since v0.2.0
|
|
60
|
-
*/
|
|
61
|
-
export enum Option<a> {
|
|
62
|
-
Some(a),
|
|
63
|
-
None,
|
|
64
41
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
* Grain's type representing the result of something that might error.
|
|
68
|
-
*
|
|
69
|
-
* @since v0.2.0
|
|
70
|
-
*/
|
|
71
|
-
export enum Result<t, e> {
|
|
72
|
-
Ok(t),
|
|
73
|
-
Err(e),
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* @section Boolean operations: Infix functions for working with Boolean values.
|
|
78
|
-
*/
|
|
42
|
+
from "runtime/string" include String
|
|
43
|
+
use String.{ toString, print, concat as (++) }
|
|
79
44
|
|
|
80
45
|
/**
|
|
81
46
|
* Computes the logical NOT (`!`) of the given operand.
|
|
82
47
|
* Inverts the given Boolean value.
|
|
83
48
|
*
|
|
84
|
-
* @param
|
|
49
|
+
* @param bool: The operand
|
|
85
50
|
* @returns The inverted value
|
|
86
51
|
*
|
|
87
52
|
* @example !true // false
|
|
@@ -89,7 +54,7 @@ export enum Result<t, e> {
|
|
|
89
54
|
*
|
|
90
55
|
* @since v0.1.0
|
|
91
56
|
*/
|
|
92
|
-
|
|
57
|
+
provide primitive (!) = "@not"
|
|
93
58
|
|
|
94
59
|
/**
|
|
95
60
|
* Computes the logical AND (`&&`) of the given operands.
|
|
@@ -97,13 +62,13 @@ export primitive (!): Bool -> Bool = "@not"
|
|
|
97
62
|
* If the first operand is `false`, returns `false` without evaluating the second operand.
|
|
98
63
|
* If the first operand is `true`, returns the value of the second operand.
|
|
99
64
|
*
|
|
100
|
-
* @param
|
|
101
|
-
* @param
|
|
65
|
+
* @param left: The first operand
|
|
66
|
+
* @param right: The second operand
|
|
102
67
|
* @returns The first operand if it is `false` or the value of the second operand otherwise
|
|
103
68
|
*
|
|
104
69
|
* @since v0.1.0
|
|
105
70
|
*/
|
|
106
|
-
|
|
71
|
+
provide primitive (&&) = "@and"
|
|
107
72
|
|
|
108
73
|
/**
|
|
109
74
|
* Computes the logical OR `||` of the given operands.
|
|
@@ -111,29 +76,15 @@ export primitive (&&): (Bool, Bool) -> Bool = "@and"
|
|
|
111
76
|
* If the first operand is `true`, returns `true` without evaluating the second operand.
|
|
112
77
|
* If the first operand is `false`, returns the value of the second operand.
|
|
113
78
|
*
|
|
114
|
-
* @param
|
|
115
|
-
* @param
|
|
79
|
+
* @param left: The first operand
|
|
80
|
+
* @param right: The second operand
|
|
116
81
|
* @returns The first operand if it is `true` or the value of the second operand otherwise
|
|
117
82
|
*
|
|
118
83
|
* @since v0.1.0
|
|
119
84
|
*/
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* @section Comparison operations: Infix functions for comparing values.
|
|
124
|
-
*/
|
|
85
|
+
provide primitive (||) = "@or"
|
|
125
86
|
|
|
126
|
-
|
|
127
|
-
* Check that two values are equal. This checks for structural equality,
|
|
128
|
-
* so it also works for comparing things like tuples and lists.
|
|
129
|
-
*
|
|
130
|
-
* @param value1: The first operand
|
|
131
|
-
* @param value2: The second operand
|
|
132
|
-
* @returns `true` if the values are structurally equal or `false` otherwise
|
|
133
|
-
*
|
|
134
|
-
* @since v0.1.0
|
|
135
|
-
*/
|
|
136
|
-
export (==)
|
|
87
|
+
provide { (==) }
|
|
137
88
|
|
|
138
89
|
/**
|
|
139
90
|
* Check that two values are **not** equal. This checks for structural equality,
|
|
@@ -145,19 +96,19 @@ export (==)
|
|
|
145
96
|
*
|
|
146
97
|
* @since v0.2.0
|
|
147
98
|
*/
|
|
148
|
-
|
|
99
|
+
provide let (!=) = (value1, value2) => !(value1 == value2)
|
|
149
100
|
|
|
150
101
|
/**
|
|
151
102
|
* Checks that two values are physically equal.
|
|
152
103
|
* Use this operator if you don’t need or want structural equality.
|
|
153
104
|
*
|
|
154
|
-
* @param
|
|
155
|
-
* @param
|
|
105
|
+
* @param left: The first operand
|
|
106
|
+
* @param right: The second operand
|
|
156
107
|
* @returns `true` if the values are physically equal or `false` otherwise
|
|
157
108
|
*
|
|
158
109
|
* @since v0.1.0
|
|
159
110
|
*/
|
|
160
|
-
|
|
111
|
+
provide primitive (is) = "@is"
|
|
161
112
|
|
|
162
113
|
/**
|
|
163
114
|
* Checks that two values are **not** physically equal.
|
|
@@ -169,294 +120,39 @@ export primitive (is): (a, a) -> Bool = "@is"
|
|
|
169
120
|
*
|
|
170
121
|
* @since v0.2.0
|
|
171
122
|
*/
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* @section Number comparisons: Infix functions for comparing Number values.
|
|
176
|
-
*/
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Checks if the first operand is less than the second operand.
|
|
180
|
-
*
|
|
181
|
-
* @param num1: The first operand
|
|
182
|
-
* @param num2: The second operand
|
|
183
|
-
* @returns `true` if the first operand is less than the second operand or `false` otherwise
|
|
184
|
-
*
|
|
185
|
-
* @since v0.1.0
|
|
186
|
-
*/
|
|
187
|
-
export (<)
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Checks if the first operand is greater than the second operand.
|
|
191
|
-
*
|
|
192
|
-
* @param num1: The first operand
|
|
193
|
-
* @param num2: The second operand
|
|
194
|
-
* @returns `true` if the first operand is greater than the second operand or `false` otherwise
|
|
195
|
-
*
|
|
196
|
-
* @since v0.1.0
|
|
197
|
-
*/
|
|
198
|
-
export (>)
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Checks if the first operand is less than or equal to the second operand.
|
|
202
|
-
*
|
|
203
|
-
* @param num1: The first operand
|
|
204
|
-
* @param num2: The second operand
|
|
205
|
-
* @returns `true` if the first operand is less than or equal to the second operand or `false` otherwise
|
|
206
|
-
*
|
|
207
|
-
* @since v0.1.0
|
|
208
|
-
*/
|
|
209
|
-
export (<=)
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Checks if the first operand is greater than or equal to the second operand.
|
|
213
|
-
*
|
|
214
|
-
* @param num1: The first operand
|
|
215
|
-
* @param num2: The second operand
|
|
216
|
-
* @returns `true` if the first operand is greater than or equal to the second operand or `false` otherwise
|
|
217
|
-
*
|
|
218
|
-
* @since v0.1.0
|
|
219
|
-
*/
|
|
220
|
-
export (>=)
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* Compares the first argument to the second argument and produces an integer result.
|
|
224
|
-
* Provides a consistent ordering over all types and is suitable for sorting and other kinds of ordering.
|
|
225
|
-
* `compare` treats `NaN` differently than the other comparison operators in that it considers `NaN` equal to itself and smaller than any other number.
|
|
226
|
-
*
|
|
227
|
-
* @param num1: The first operand
|
|
228
|
-
* @param num2: The second operand
|
|
229
|
-
* @returns A negative integer if the first operand is less than the second operand, `0` if they are equal, or a positive integer otherwise
|
|
230
|
-
*
|
|
231
|
-
* @since v0.5.3
|
|
232
|
-
*/
|
|
233
|
-
export compare
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* @section Math operations: Infix functions for working with Number values.
|
|
237
|
-
*/
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Computes the sum of its operands.
|
|
241
|
-
*
|
|
242
|
-
* @param num1: The first operand
|
|
243
|
-
* @param num2: The second operand
|
|
244
|
-
* @returns The sum of the two operands
|
|
245
|
-
*
|
|
246
|
-
* @since v0.1.0
|
|
247
|
-
*/
|
|
248
|
-
export (+)
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Computes the difference of its operands.
|
|
252
|
-
*
|
|
253
|
-
* @param num1: The first operand
|
|
254
|
-
* @param num2: The second operand
|
|
255
|
-
* @returns The difference of the two operands
|
|
256
|
-
*
|
|
257
|
-
* @since v0.1.0
|
|
258
|
-
*/
|
|
259
|
-
export (-)
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Computes the product of its operands.
|
|
263
|
-
*
|
|
264
|
-
* @param num1: The first operand
|
|
265
|
-
* @param num2: The second operand
|
|
266
|
-
* @returns The product of the two operands
|
|
267
|
-
*
|
|
268
|
-
* @since v0.1.0
|
|
269
|
-
*/
|
|
270
|
-
export (*)
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Computes the quotient of its operands.
|
|
274
|
-
*
|
|
275
|
-
* @param num1: The first operand
|
|
276
|
-
* @param num2: The second operand
|
|
277
|
-
* @returns The quotient of the two operands
|
|
278
|
-
*
|
|
279
|
-
* @since v0.1.0
|
|
280
|
-
*/
|
|
281
|
-
export (/)
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Computes the remainder of the division of the first operand by the second.
|
|
285
|
-
* The result will have the sign of the second operand.
|
|
286
|
-
*
|
|
287
|
-
* @param num1: The first operand
|
|
288
|
-
* @param num2: The second operand
|
|
289
|
-
* @returns The modulus of its operands
|
|
290
|
-
*
|
|
291
|
-
* @since v0.1.0
|
|
292
|
-
*/
|
|
293
|
-
export (%)
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* Increments the value by one.
|
|
297
|
-
*
|
|
298
|
-
* @param value: The value to increment
|
|
299
|
-
* @returns The incremented value
|
|
300
|
-
*
|
|
301
|
-
* @since v0.1.0
|
|
302
|
-
*/
|
|
303
|
-
export incr
|
|
123
|
+
provide let (isnt) = (value1, value2) => !(value1 is value2)
|
|
304
124
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
* @since v0.2.0
|
|
329
|
-
*/
|
|
330
|
-
export (++)
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* @section Bitwise operations: Infix functions for operating on bits of Number values.
|
|
334
|
-
*/
|
|
335
|
-
|
|
336
|
-
/**
|
|
337
|
-
* Computes the bitwise NOT of the operand.
|
|
338
|
-
*
|
|
339
|
-
* @param value: The operand
|
|
340
|
-
* @returns Containing the inverted bits of the operand
|
|
341
|
-
*
|
|
342
|
-
* @since v0.2.0
|
|
343
|
-
*/
|
|
344
|
-
export lnot
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Computes the bitwise AND (`&`) on the given operands.
|
|
348
|
-
*
|
|
349
|
-
* @param value1: The first operand
|
|
350
|
-
* @param value2: The second operand
|
|
351
|
-
* @returns Containing a `1` in each bit position for which the corresponding bits of both operands are `1`
|
|
352
|
-
*
|
|
353
|
-
* @since v0.3.0
|
|
354
|
-
* @history v0.2.0: Originally named `land`
|
|
355
|
-
* @history v0.3.0: Renamed to `&`
|
|
356
|
-
*/
|
|
357
|
-
export (&)
|
|
358
|
-
|
|
359
|
-
/**
|
|
360
|
-
* Computes the bitwise OR (`|`) on the given operands.
|
|
361
|
-
*
|
|
362
|
-
* @param value1: The first operand
|
|
363
|
-
* @param value2: The second operand
|
|
364
|
-
* @returns Containing a `1` in each bit position for which the corresponding bits of either or both operands are `1`
|
|
365
|
-
*
|
|
366
|
-
* @since v0.3.0
|
|
367
|
-
* @history v0.2.0: Originally named `lor`
|
|
368
|
-
* @history v0.3.0: Renamed to `|`
|
|
369
|
-
*/
|
|
370
|
-
export (|)
|
|
371
|
-
|
|
372
|
-
/**
|
|
373
|
-
* Computes the bitwise XOR (`^`) on the given operands.
|
|
374
|
-
*
|
|
375
|
-
* @param value1: The first operand
|
|
376
|
-
* @param value2: The second operand
|
|
377
|
-
* @returns Containing a `1` in each bit position for which the corresponding bits of either but not both operands are `1`
|
|
378
|
-
*
|
|
379
|
-
* @since v0.3.0
|
|
380
|
-
* @history v0.1.0: The `^` operator was originally an alias of `unbox`
|
|
381
|
-
* @history v0.2.0: Originally named `lxor`
|
|
382
|
-
* @history v0.3.0: Renamed to `^`
|
|
383
|
-
*/
|
|
384
|
-
export (^)
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* Shifts the bits of the value left by the given number of bits.
|
|
388
|
-
*
|
|
389
|
-
* @param value: The value to shift
|
|
390
|
-
* @param amount: The number of bits to shift by
|
|
391
|
-
* @returns The shifted value
|
|
392
|
-
*
|
|
393
|
-
* @since v0.3.0
|
|
394
|
-
* @history v0.2.0: Originally named `lsl`
|
|
395
|
-
* @history v0.3.0: Renamed to `<<`
|
|
396
|
-
*/
|
|
397
|
-
export (<<)
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
* Shifts the bits of the value right by the given number of bits, preserving the sign bit.
|
|
401
|
-
*
|
|
402
|
-
* @param value: The value to shift
|
|
403
|
-
* @param amount: The amount to shift by
|
|
404
|
-
* @returns The shifted value
|
|
405
|
-
*
|
|
406
|
-
* @since v0.3.0
|
|
407
|
-
* @history v0.2.0: Originally named `lsr`
|
|
408
|
-
* @history v0.3.0: Renamed to `>>>`
|
|
409
|
-
*/
|
|
410
|
-
export (>>>)
|
|
411
|
-
|
|
412
|
-
/**
|
|
413
|
-
* Shifts the bits of the value right by the given number of bits.
|
|
414
|
-
*
|
|
415
|
-
* @param value: The value to shift
|
|
416
|
-
* @param amount: The amount to shift by
|
|
417
|
-
* @returns The shifted value
|
|
418
|
-
*
|
|
419
|
-
* @since v0.3.0
|
|
420
|
-
* @history v0.2.0: Originally named `asr`
|
|
421
|
-
* @history v0.3.0: Renamed to `>>`
|
|
422
|
-
*/
|
|
423
|
-
export (>>)
|
|
125
|
+
provide {
|
|
126
|
+
(<),
|
|
127
|
+
(>),
|
|
128
|
+
(<=),
|
|
129
|
+
(>=),
|
|
130
|
+
compare,
|
|
131
|
+
(+),
|
|
132
|
+
(-),
|
|
133
|
+
(*),
|
|
134
|
+
(/),
|
|
135
|
+
(%),
|
|
136
|
+
(**),
|
|
137
|
+
incr,
|
|
138
|
+
decr,
|
|
139
|
+
(++),
|
|
140
|
+
lnot,
|
|
141
|
+
(&),
|
|
142
|
+
(|),
|
|
143
|
+
(^),
|
|
144
|
+
(<<),
|
|
145
|
+
(>>>),
|
|
146
|
+
(>>),
|
|
147
|
+
}
|
|
424
148
|
|
|
425
149
|
// Number coercions & conversions
|
|
426
150
|
|
|
427
151
|
// TODO(#311): Commented until we nail down semantics
|
|
428
|
-
//
|
|
429
|
-
//
|
|
152
|
+
// foreign wasm convertExactToInexact : Number => Number as inexact from "stdlib-external/runtime"
|
|
153
|
+
// foreign wasm convertInexactToExact : Number => Number as exact from "stdlib-external/runtime"
|
|
430
154
|
|
|
431
|
-
|
|
432
|
-
* @section Printing: Functions that deal with printing.
|
|
433
|
-
*/
|
|
434
|
-
|
|
435
|
-
/**
|
|
436
|
-
* Converts the given operand to a string.
|
|
437
|
-
* Provides a better representation of data types if those types are exported from the module.
|
|
438
|
-
*
|
|
439
|
-
* @param value: The operand
|
|
440
|
-
* @returns The operand, as a string
|
|
441
|
-
*
|
|
442
|
-
* @since v0.1.0
|
|
443
|
-
*/
|
|
444
|
-
export toString
|
|
445
|
-
|
|
446
|
-
/**
|
|
447
|
-
* Prints the given operand to the console. Works for any type. Internally, calls `toString`
|
|
448
|
-
* on the operand, so a better representation of data type will be printed if those types
|
|
449
|
-
* are exported from the module.
|
|
450
|
-
*
|
|
451
|
-
* @param value: The operand
|
|
452
|
-
*
|
|
453
|
-
* @since v0.1.0
|
|
454
|
-
*/
|
|
455
|
-
export print
|
|
456
|
-
|
|
457
|
-
/**
|
|
458
|
-
* @section Type helpers: Functions that help with typechecking.
|
|
459
|
-
*/
|
|
155
|
+
provide { toString, print }
|
|
460
156
|
|
|
461
157
|
/**
|
|
462
158
|
* Accepts any value and always returns `void`.
|
|
@@ -465,11 +161,7 @@ export print
|
|
|
465
161
|
*
|
|
466
162
|
* @since v0.1.0
|
|
467
163
|
*/
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
/**
|
|
471
|
-
* @section Assertions: Functions that raise if conditions are not met.
|
|
472
|
-
*/
|
|
164
|
+
provide primitive ignore = "@ignore"
|
|
473
165
|
|
|
474
166
|
/**
|
|
475
167
|
* Assert that the given Boolean condition is `true`.
|
|
@@ -483,25 +175,21 @@ export primitive ignore: a -> Void = "@ignore"
|
|
|
483
175
|
*
|
|
484
176
|
* @since v0.1.0
|
|
485
177
|
*/
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
/**
|
|
489
|
-
* @section Failures: Functions that throw an Exception unconditionally.
|
|
490
|
-
*/
|
|
178
|
+
provide primitive assert = "@assert"
|
|
491
179
|
|
|
492
180
|
// Exceptions
|
|
493
|
-
|
|
494
|
-
|
|
181
|
+
provide exception Failure(String)
|
|
182
|
+
provide exception InvalidArgument(String)
|
|
495
183
|
|
|
496
184
|
/**
|
|
497
185
|
* Throw an exception. Currently, exceptions cannot be caught and will crash your program.
|
|
498
186
|
*
|
|
499
|
-
* @param
|
|
187
|
+
* @param exn: The exception to be thrown
|
|
500
188
|
* @returns Anything and nothing—your program won't continue past a throw
|
|
501
189
|
*
|
|
502
190
|
* @since v0.3.0
|
|
503
191
|
*/
|
|
504
|
-
|
|
192
|
+
provide primitive throw = "@throw"
|
|
505
193
|
|
|
506
194
|
/**
|
|
507
195
|
* Unconditionally throw a `Failure` exception with a message.
|
|
@@ -510,11 +198,7 @@ export primitive throw: Exception -> a = "@throw"
|
|
|
510
198
|
* @param message: The reason for the failure
|
|
511
199
|
* @returns Anything and nothing—your program won't continue past a fail expression
|
|
512
200
|
*/
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
/**
|
|
516
|
-
* @section Other: Other functions on values.
|
|
517
|
-
*/
|
|
201
|
+
provide let fail = message => throw Failure(message)
|
|
518
202
|
|
|
519
203
|
/**
|
|
520
204
|
* Provides the operand untouched.
|
|
@@ -524,63 +208,34 @@ export let fail: String -> a = msg => throw Failure(msg)
|
|
|
524
208
|
*
|
|
525
209
|
* @since v0.2.0
|
|
526
210
|
*/
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
/**
|
|
530
|
-
* @section Box operations: Functions for working with Box values.
|
|
531
|
-
*/
|
|
211
|
+
provide let identity = value => value
|
|
532
212
|
|
|
533
213
|
/**
|
|
534
214
|
* Creates a box containing the given initial value.
|
|
535
215
|
* Values inside a box can be swapped out with the `:=` operator.
|
|
536
216
|
* Generally, `let mut` expressions are preferable to using a Box.
|
|
537
217
|
*
|
|
538
|
-
* @param
|
|
218
|
+
* @param value: The initial value inside the box
|
|
539
219
|
* @returns The box containing the initial value
|
|
540
220
|
*
|
|
541
221
|
* @since v0.1.0
|
|
542
222
|
*/
|
|
543
|
-
|
|
223
|
+
provide primitive box = "@box"
|
|
544
224
|
|
|
545
225
|
/**
|
|
546
226
|
* Retrieves the current value from a box.
|
|
547
227
|
*
|
|
548
|
-
* @param
|
|
228
|
+
* @param value: The box to unwrap
|
|
549
229
|
* @returns The value inside the box
|
|
550
230
|
*
|
|
551
231
|
* @since v0.1.0
|
|
552
232
|
*/
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
/**
|
|
556
|
-
* @section List operations: Functions for working with List values.
|
|
557
|
-
*/
|
|
558
|
-
|
|
559
|
-
/**
|
|
560
|
-
* The list spread syntax (`[a, ...b]`) provided as a function.
|
|
561
|
-
*
|
|
562
|
-
* @param a: The head of the list
|
|
563
|
-
* @param b: The tail of the list
|
|
564
|
-
* @returns The new list
|
|
565
|
-
*
|
|
566
|
-
* @deprecated This will be removed in a future release of Grain.
|
|
567
|
-
*
|
|
568
|
-
* @since v0.4.0
|
|
569
|
-
*/
|
|
570
|
-
export let cons = (a, b) =>
|
|
571
|
-
[a, ...b] // TODO(#802): Remove workaround after 802 is completed
|
|
572
|
-
/**
|
|
573
|
-
* The empty list syntax (`[]`) provided as a value.
|
|
574
|
-
*
|
|
575
|
-
* @deprecated This will be removed in a future release of Grain.
|
|
576
|
-
*
|
|
577
|
-
* @since v0.4.0
|
|
578
|
-
*/
|
|
579
|
-
export let empty = [] // <- for parity with `cons`, but should be deleted as well
|
|
233
|
+
provide primitive unbox = "@unbox"
|
|
580
234
|
|
|
581
235
|
// Setup exception printing
|
|
236
|
+
primitive elideTypeInfo = "@meta.elide_type_info"
|
|
582
237
|
@unsafe
|
|
583
|
-
let
|
|
238
|
+
let setupExceptions = () => {
|
|
584
239
|
Exception.dangerouslyRegisterPrinter(e => {
|
|
585
240
|
match (e) {
|
|
586
241
|
Failure(msg) => Some("Failure: " ++ msg),
|
|
@@ -589,7 +244,11 @@ let rec setupExceptions = () => {
|
|
|
589
244
|
}
|
|
590
245
|
})
|
|
591
246
|
|
|
592
|
-
|
|
247
|
+
// If type information is elided, remove dependency on toString as
|
|
248
|
+
// it will have no effect on exceptions
|
|
249
|
+
if (!elideTypeInfo) {
|
|
250
|
+
Exception.dangerouslyRegisterBasePrinter(e => Some(toString(e)))
|
|
251
|
+
}
|
|
593
252
|
}
|
|
594
253
|
|
|
595
254
|
setupExceptions()
|