@grain/stdlib 0.5.3 → 0.5.5
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 +61 -0
- package/array.gr +65 -57
- package/array.md +54 -6
- package/buffer.gr +71 -1
- package/buffer.md +142 -0
- package/bytes.gr +52 -3
- package/bytes.md +117 -0
- package/char.gr +23 -20
- package/char.md +18 -3
- package/immutablemap.gr +493 -0
- package/immutablemap.md +479 -0
- package/immutablepriorityqueue.gr +44 -16
- package/immutablepriorityqueue.md +44 -1
- package/immutableset.gr +498 -0
- package/immutableset.md +449 -0
- package/int32.gr +39 -37
- package/int32.md +6 -0
- package/int64.gr +39 -37
- package/int64.md +6 -0
- package/list.gr +33 -24
- package/list.md +39 -10
- package/map.gr +19 -28
- package/marshal.gr +4 -4
- package/number.gr +727 -26
- package/number.md +345 -23
- package/option.gr +30 -26
- package/option.md +12 -0
- package/package.json +1 -1
- package/path.gr +787 -0
- package/path.md +727 -0
- package/pervasives.gr +3 -4
- package/pervasives.md +6 -1
- package/priorityqueue.gr +25 -5
- package/priorityqueue.md +30 -0
- package/queue.gr +22 -7
- package/queue.md +18 -1
- package/regex.gr +161 -65
- package/regex.md +70 -0
- package/result.gr +24 -20
- package/result.md +12 -0
- package/runtime/atof/common.gr +198 -0
- package/runtime/atof/common.md +243 -0
- package/runtime/atof/decimal.gr +663 -0
- package/runtime/atof/decimal.md +59 -0
- package/runtime/atof/lemire.gr +264 -0
- package/runtime/atof/lemire.md +6 -0
- package/runtime/atof/parse.gr +615 -0
- package/runtime/atof/parse.md +12 -0
- package/runtime/atof/slow.gr +238 -0
- package/runtime/atof/slow.md +6 -0
- package/runtime/atof/table.gr +2016 -0
- package/runtime/atof/table.md +12 -0
- package/runtime/{stringUtils.gr → atoi/parse.gr} +1 -1
- package/runtime/{stringUtils.md → atoi/parse.md} +1 -1
- package/runtime/bigint.gr +7 -7
- package/runtime/compare.gr +2 -1
- package/runtime/equal.gr +3 -2
- package/runtime/exception.gr +9 -5
- package/runtime/exception.md +8 -2
- package/runtime/gc.gr +2 -1
- package/runtime/malloc.gr +1 -3
- package/runtime/numberUtils.gr +13 -13
- package/runtime/numberUtils.md +6 -0
- package/runtime/numbers.gr +123 -39
- package/runtime/numbers.md +26 -0
- package/runtime/string.gr +4 -2
- package/runtime/unsafe/conv.gr +21 -41
- package/runtime/unsafe/conv.md +0 -3
- package/runtime/unsafe/printWasm.gr +4 -40
- package/runtime/utils/printing.gr +3 -3
- package/set.gr +25 -25
- package/stack.gr +14 -0
- package/stack.md +17 -0
- package/string.gr +313 -39
- package/string.md +99 -0
- package/sys/file.gr +1 -1
- package/sys/time.gr +4 -4
|
@@ -18,7 +18,7 @@ import BI from "runtime/bigint"
|
|
|
18
18
|
import { reducedInteger } from "runtime/numbers"
|
|
19
19
|
|
|
20
20
|
@unsafe
|
|
21
|
-
export let
|
|
21
|
+
export let parseInt = (string: String, radix: Number) => {
|
|
22
22
|
let _CHAR_0 = 0x30n
|
|
23
23
|
let _CHAR_B = 0x42n
|
|
24
24
|
let _CHAR_b = 0x62n
|
package/runtime/bigint.gr
CHANGED
|
@@ -786,7 +786,7 @@ let _SIZES = [>
|
|
|
786
786
|
]
|
|
787
787
|
|
|
788
788
|
@unsafe
|
|
789
|
-
export let
|
|
789
|
+
export let bigIntToString = (num: WasmI32, base: WasmI32) => {
|
|
790
790
|
let getDigit = n =>
|
|
791
791
|
WasmI32.load8U(WasmI32.add(WasmI32.fromGrain(_DIGITS), n), 8n)
|
|
792
792
|
if (WasmI32.ltS(base, 2n) || WasmI32.gtS(base, 32n)) {
|
|
@@ -1339,7 +1339,7 @@ export let shl = (num: WasmI32, places: WasmI32) => {
|
|
|
1339
1339
|
let (&) = WasmI64.and
|
|
1340
1340
|
let a = places / 32n
|
|
1341
1341
|
let b = places % 32n
|
|
1342
|
-
let mask = (1N << WasmI64.extendI32U(b)) - 1N << 64N - WasmI64.extendI32U(b)
|
|
1342
|
+
let mask = ((1N << WasmI64.extendI32U(b)) - 1N) << 64N - WasmI64.extendI32U(b)
|
|
1343
1343
|
let result = init(numLimbs + a)
|
|
1344
1344
|
setFlag(result, _IS_NEGATIVE, getFlag(num, _IS_NEGATIVE))
|
|
1345
1345
|
let numHalfLimbs = WasmI32.shl(numLimbs, 1n)
|
|
@@ -1350,7 +1350,7 @@ export let shl = (num: WasmI32, places: WasmI32) => {
|
|
|
1350
1350
|
setHalfLimb(
|
|
1351
1351
|
result,
|
|
1352
1352
|
i + a,
|
|
1353
|
-
WasmI32.wrapI64(acc << WasmI64.extendI32U(b) >> 32N)
|
|
1353
|
+
WasmI32.wrapI64((acc << WasmI64.extendI32U(b)) >> 32N)
|
|
1354
1354
|
)
|
|
1355
1355
|
}
|
|
1356
1356
|
let (>) = WasmI64.gtU
|
|
@@ -1827,10 +1827,10 @@ let baseCaseDivRem = (a: WasmI32, b: WasmI32, result: WasmI32) => {
|
|
|
1827
1827
|
let n = getHalfSize(b)
|
|
1828
1828
|
let m = getHalfSize(a) - n
|
|
1829
1829
|
let qsize = (if (WasmI32.eqz(WasmI32.and(m + 1n, 1n))) {
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1830
|
+
m + 1n
|
|
1831
|
+
} else {
|
|
1832
|
+
m + 2n
|
|
1833
|
+
}) >>
|
|
1834
1834
|
1n
|
|
1835
1835
|
let mut q = init(qsize)
|
|
1836
1836
|
let mut a = 0n
|
package/runtime/compare.gr
CHANGED
|
@@ -146,7 +146,8 @@ let rec heapCompareHelp = (heapTag, xptr, yptr) => {
|
|
|
146
146
|
tagSimpleNumber(xptr - yptr)
|
|
147
147
|
},
|
|
148
148
|
}
|
|
149
|
-
},
|
|
149
|
+
},
|
|
150
|
+
compareHelp = (x, y) => {
|
|
150
151
|
let xtag = x & Tags._GRAIN_GENERIC_TAG_MASK
|
|
151
152
|
let ytag = y & Tags._GRAIN_GENERIC_TAG_MASK
|
|
152
153
|
if ((xtag & ytag) != Tags._GRAIN_GENERIC_HEAP_TAG_TYPE) {
|
package/runtime/equal.gr
CHANGED
|
@@ -189,7 +189,8 @@ let rec heapEqualHelp = (heapTag, xptr, yptr) => {
|
|
|
189
189
|
xptr == yptr
|
|
190
190
|
},
|
|
191
191
|
}
|
|
192
|
-
},
|
|
192
|
+
},
|
|
193
|
+
equalHelp = (x, y) => {
|
|
193
194
|
if (
|
|
194
195
|
(x & Tags._GRAIN_GENERIC_TAG_MASK) != 0n &&
|
|
195
196
|
(y & Tags._GRAIN_GENERIC_TAG_MASK) != 0n
|
|
@@ -207,6 +208,6 @@ let rec heapEqualHelp = (heapTag, xptr, yptr) => {
|
|
|
207
208
|
}
|
|
208
209
|
|
|
209
210
|
@unsafe
|
|
210
|
-
export let
|
|
211
|
+
export let equal = (x: a, y: a) => {
|
|
211
212
|
equalHelp(WasmI32.fromGrain(x), WasmI32.fromGrain(y))
|
|
212
213
|
}
|
package/runtime/exception.gr
CHANGED
|
@@ -9,6 +9,8 @@ import foreign wasm fd_write: (
|
|
|
9
9
|
WasmI32,
|
|
10
10
|
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
11
11
|
|
|
12
|
+
primitive unreachable: () -> a = "@unreachable"
|
|
13
|
+
|
|
12
14
|
enum Option<a> {
|
|
13
15
|
Some(a),
|
|
14
16
|
None,
|
|
@@ -79,8 +81,8 @@ let exceptionToString = (e: Exception) => {
|
|
|
79
81
|
// the runtime heap, but this is the only module that needs to do it
|
|
80
82
|
let iov = WasmI32.fromGrain([> 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n])
|
|
81
83
|
|
|
82
|
-
export let
|
|
83
|
-
let ptr = WasmI32.fromGrain(
|
|
84
|
+
export let panic = (msg: String) => {
|
|
85
|
+
let ptr = WasmI32.fromGrain(msg)
|
|
84
86
|
let written = iov + 32n
|
|
85
87
|
let lf = iov + 36n
|
|
86
88
|
WasmI32.store(iov, ptr + 8n, 0n)
|
|
@@ -89,7 +91,11 @@ export let printException = (e: Exception) => {
|
|
|
89
91
|
WasmI32.store(iov, lf, 8n)
|
|
90
92
|
WasmI32.store(iov, 1n, 12n)
|
|
91
93
|
fd_write(2n, iov, 2n, written)
|
|
92
|
-
|
|
94
|
+
unreachable()
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export let panicWithException = (e: Exception) => {
|
|
98
|
+
panic(exceptionToString(e))
|
|
93
99
|
}
|
|
94
100
|
|
|
95
101
|
export exception IndexOutOfBounds
|
|
@@ -109,7 +115,6 @@ export exception MatchFailure
|
|
|
109
115
|
*/
|
|
110
116
|
export exception AssertionError(String)
|
|
111
117
|
export exception InvalidArgument(String)
|
|
112
|
-
export exception OutOfMemory
|
|
113
118
|
|
|
114
119
|
let runtimeErrorPrinter = e => {
|
|
115
120
|
match (e) {
|
|
@@ -123,7 +128,6 @@ let runtimeErrorPrinter = e => {
|
|
|
123
128
|
Some("NumberNotRational: Can't coerce number to rational"),
|
|
124
129
|
MatchFailure => Some("MatchFailure: No matching pattern"),
|
|
125
130
|
AssertionError(s) => Some(s),
|
|
126
|
-
OutOfMemory => Some("OutOfMemory: Maximum memory size exceeded"),
|
|
127
131
|
InvalidArgument(msg) => Some(msg),
|
|
128
132
|
_ => None,
|
|
129
133
|
}
|
package/runtime/exception.md
CHANGED
|
@@ -22,9 +22,15 @@ dangerouslyRegisterBasePrinter : a -> Void
|
|
|
22
22
|
dangerouslyRegisterPrinter : a -> Void
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
### Exception.**
|
|
25
|
+
### Exception.**panic**
|
|
26
26
|
|
|
27
27
|
```grain
|
|
28
|
-
|
|
28
|
+
panic : String -> a
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Exception.**panicWithException**
|
|
32
|
+
|
|
33
|
+
```grain
|
|
34
|
+
panicWithException : Exception -> a
|
|
29
35
|
```
|
|
30
36
|
|
package/runtime/gc.gr
CHANGED
|
@@ -213,7 +213,8 @@ let rec decRef = (userPtr: WasmI32, ignoreZeros: Bool) => {
|
|
|
213
213
|
} else {
|
|
214
214
|
userPtr
|
|
215
215
|
}
|
|
216
|
-
},
|
|
216
|
+
},
|
|
217
|
+
decRefChildren = (userPtr: WasmI32) => {
|
|
217
218
|
match (WasmI32.load(userPtr, 0n)) {
|
|
218
219
|
t when t == Tags._GRAIN_BOXED_NUM_HEAP_TAG => {
|
|
219
220
|
let tag = WasmI32.load(userPtr, 4n)
|
package/runtime/malloc.gr
CHANGED
|
@@ -28,8 +28,6 @@ primitive (!): Bool -> Bool = "@not"
|
|
|
28
28
|
primitive (&&): (Bool, Bool) -> Bool = "@and"
|
|
29
29
|
primitive (||): (Bool, Bool) -> Bool = "@or"
|
|
30
30
|
|
|
31
|
-
primitive throw: Exception -> a = "@throw"
|
|
32
|
-
|
|
33
31
|
primitive heapBase: WasmI32 = "@heap.base"
|
|
34
32
|
|
|
35
33
|
/* UNDERSTANDING THE STRUCTURE OF THE FREE LIST
|
|
@@ -221,7 +219,7 @@ let morecore = (nbytes: WasmI32) => {
|
|
|
221
219
|
|
|
222
220
|
// If there was an error, fail
|
|
223
221
|
if (cp == -1n) {
|
|
224
|
-
|
|
222
|
+
Exception.panic("OutOfMemory: Maximum memory size exceeded")
|
|
225
223
|
} else {
|
|
226
224
|
// Set the size of the new block to the amount the
|
|
227
225
|
// heap was grown.
|
package/runtime/numberUtils.gr
CHANGED
|
@@ -46,7 +46,7 @@ let _I32_MAX = 0xffffffffN
|
|
|
46
46
|
let mut _POWERS10 = -1n
|
|
47
47
|
|
|
48
48
|
@unsafe
|
|
49
|
-
let get_POWERS10 = () => {
|
|
49
|
+
export let get_POWERS10 = () => {
|
|
50
50
|
if (_POWERS10 == -1n) {
|
|
51
51
|
_POWERS10 = Memory.malloc(40n)
|
|
52
52
|
WasmI32.store(_POWERS10, 1n, 0n)
|
|
@@ -728,16 +728,16 @@ export let decimalCount32 = value => {
|
|
|
728
728
|
1n + (if (WasmI32.geU(value, 10n)) 1n else 0n)
|
|
729
729
|
} else {
|
|
730
730
|
3n +
|
|
731
|
-
|
|
732
|
-
|
|
731
|
+
(if (WasmI32.geU(value, 10000n)) 1n else 0n) +
|
|
732
|
+
(if (WasmI32.geU(value, 1000n)) 1n else 0n)
|
|
733
733
|
}
|
|
734
734
|
} else {
|
|
735
735
|
if (WasmI32.ltU(value, 10000000n)) {
|
|
736
736
|
6n + (if (WasmI32.geU(value, 1000000n)) 1n else 0n)
|
|
737
737
|
} else {
|
|
738
738
|
8n +
|
|
739
|
-
|
|
740
|
-
|
|
739
|
+
(if (WasmI32.geU(value, 1000000000n)) 1n else 0n) +
|
|
740
|
+
(if (WasmI32.geU(value, 100000000n)) 1n else 0n)
|
|
741
741
|
}
|
|
742
742
|
}
|
|
743
743
|
}
|
|
@@ -749,20 +749,20 @@ let decimalCount64High = value => {
|
|
|
749
749
|
if (WasmI64.ltU(value, 1000000000000000N)) {
|
|
750
750
|
if (WasmI64.ltU(value, 1000000000000N)) {
|
|
751
751
|
10n +
|
|
752
|
-
|
|
753
|
-
|
|
752
|
+
(if (WasmI64.geU(value, 100000000000N)) 1n else 0n) +
|
|
753
|
+
(if (WasmI64.geU(value, 10000000000N)) 1n else 0n)
|
|
754
754
|
} else {
|
|
755
755
|
13n +
|
|
756
|
-
|
|
757
|
-
|
|
756
|
+
(if (WasmI64.geU(value, 100000000000000N)) 1n else 0n) +
|
|
757
|
+
(if (WasmI64.geU(value, 10000000000000N)) 1n else 0n)
|
|
758
758
|
}
|
|
759
759
|
} else {
|
|
760
760
|
if (WasmI64.ltU(value, 100000000000000000N)) {
|
|
761
761
|
16n + (if (WasmI64.geU(value, 10000000000000000N)) 1n else 0n)
|
|
762
762
|
} else {
|
|
763
763
|
18n +
|
|
764
|
-
|
|
765
|
-
|
|
764
|
+
(if (WasmI64.geU(value, 0x8AC7230489E80000N)) 1n else 0n) +
|
|
765
|
+
(if (WasmI64.geU(value, 1000000000000000000N)) 1n else 0n)
|
|
766
766
|
}
|
|
767
767
|
}
|
|
768
768
|
}
|
|
@@ -774,7 +774,7 @@ let ulog_base = (num, base) => {
|
|
|
774
774
|
63n - WasmI32.wrapI64(WasmI64.clz(num)),
|
|
775
775
|
31n - WasmI32.clz(base)
|
|
776
776
|
) +
|
|
777
|
-
|
|
777
|
+
1n
|
|
778
778
|
} else {
|
|
779
779
|
let b64 = WasmI64.extendI32U(base)
|
|
780
780
|
let mut b = b64
|
|
@@ -1277,7 +1277,7 @@ let genDigits = (buffer, w_frc, mp_frc, mp_exp, delta, sign) => {
|
|
|
1277
1277
|
wp_w_frc = WasmI64.mul(
|
|
1278
1278
|
wp_w_frc,
|
|
1279
1279
|
WasmI64.extendI32U(
|
|
1280
|
-
WasmI32.load(get_POWERS10() + (0n - kappa << 2n), 0n)
|
|
1280
|
+
WasmI32.load(get_POWERS10() + ((0n - kappa) << 2n), 0n)
|
|
1281
1281
|
)
|
|
1282
1282
|
)
|
|
1283
1283
|
grisuRound(buffer, len, delta, p2, one_frc, wp_w_frc)
|