@grain/stdlib 0.4.4 → 0.4.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 +7 -0
- package/array.gr +76 -57
- package/buffer.gr +7 -4
- package/bytes.gr +10 -10
- package/char.gr +112 -56
- package/char.md +200 -0
- package/hash.gr +17 -13
- package/list.gr +78 -61
- package/map.gr +106 -110
- package/number.gr +25 -7
- package/number.md +34 -0
- package/option.gr +25 -25
- package/package.json +1 -1
- package/pervasives.gr +32 -20
- package/queue.gr +4 -1
- package/range.gr +26 -26
- package/runtime/dataStructures.gr +28 -29
- package/runtime/debug.gr +0 -1
- package/runtime/equal.gr +37 -16
- package/runtime/exception.gr +28 -15
- package/runtime/gc.gr +31 -18
- package/runtime/malloc.gr +19 -11
- package/runtime/numberUtils.gr +208 -105
- package/runtime/numbers.gr +217 -118
- package/runtime/string.gr +98 -39
- package/runtime/stringUtils.gr +6 -2
- package/runtime/unsafe/conv.gr +10 -10
- package/runtime/unsafe/memory.gr +14 -3
- package/runtime/unsafe/printWasm.gr +4 -4
- package/runtime/unsafe/tags.gr +2 -2
- package/runtime/unsafe/wasmf32.gr +9 -2
- package/runtime/unsafe/wasmf64.gr +9 -2
- package/runtime/unsafe/wasmi32.gr +65 -47
- package/runtime/unsafe/wasmi64.gr +78 -50
- package/runtime/wasi.gr +199 -45
- package/set.gr +111 -116
- package/stack.gr +26 -26
- package/string.gr +273 -119
- package/sys/file.gr +356 -177
- package/sys/process.gr +10 -6
- package/sys/random.gr +3 -6
- package/sys/time.gr +3 -3
package/option.gr
CHANGED
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
*
|
|
24
24
|
* @since v0.2.0
|
|
25
25
|
*/
|
|
26
|
-
export let isSome =
|
|
26
|
+
export let isSome = option => {
|
|
27
27
|
match (option) {
|
|
28
28
|
Some(_) => true,
|
|
29
|
-
None => false
|
|
29
|
+
None => false,
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -38,10 +38,10 @@ export let isSome = (option) => {
|
|
|
38
38
|
*
|
|
39
39
|
* @since v0.2.0
|
|
40
40
|
*/
|
|
41
|
-
export let isNone =
|
|
41
|
+
export let isNone = option => {
|
|
42
42
|
match (option) {
|
|
43
43
|
None => true,
|
|
44
|
-
Some(_) => false
|
|
44
|
+
Some(_) => false,
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -57,7 +57,7 @@ export let isNone = (option) => {
|
|
|
57
57
|
export let contains = (value, option) => {
|
|
58
58
|
match (option) {
|
|
59
59
|
Some(x) => x == value,
|
|
60
|
-
None => false
|
|
60
|
+
None => false,
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -74,7 +74,7 @@ export let contains = (value, option) => {
|
|
|
74
74
|
export let expect = (msg, option) => {
|
|
75
75
|
match (option) {
|
|
76
76
|
Some(x) => x,
|
|
77
|
-
None => fail msg
|
|
77
|
+
None => fail msg,
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
|
|
@@ -87,7 +87,7 @@ export let expect = (msg, option) => {
|
|
|
87
87
|
*
|
|
88
88
|
* @since v0.2.0
|
|
89
89
|
*/
|
|
90
|
-
export let unwrap =
|
|
90
|
+
export let unwrap = option => {
|
|
91
91
|
expect("Could not unwrap None value", option)
|
|
92
92
|
}
|
|
93
93
|
|
|
@@ -103,7 +103,7 @@ export let unwrap = (option) => {
|
|
|
103
103
|
export let unwrapWithDefault = (default, option) => {
|
|
104
104
|
match (option) {
|
|
105
105
|
Some(x) => x,
|
|
106
|
-
None => default
|
|
106
|
+
None => default,
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
|
|
@@ -119,7 +119,7 @@ export let unwrapWithDefault = (default, option) => {
|
|
|
119
119
|
export let map = (fn, option) => {
|
|
120
120
|
match (option) {
|
|
121
121
|
Some(x) => Some(fn(x)),
|
|
122
|
-
None => None
|
|
122
|
+
None => None,
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
|
|
@@ -137,7 +137,7 @@ export let map = (fn, option) => {
|
|
|
137
137
|
export let mapWithDefault = (fn, default, option) => {
|
|
138
138
|
match (option) {
|
|
139
139
|
Some(x) => fn(x),
|
|
140
|
-
None => default
|
|
140
|
+
None => default,
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
|
|
@@ -156,7 +156,7 @@ export let mapWithDefault = (fn, default, option) => {
|
|
|
156
156
|
export let mapWithDefaultFn = (fn, defaultFn, option) => {
|
|
157
157
|
match (option) {
|
|
158
158
|
Some(x) => fn(x),
|
|
159
|
-
None => defaultFn()
|
|
159
|
+
None => defaultFn(),
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
|
|
@@ -172,7 +172,7 @@ export let mapWithDefaultFn = (fn, defaultFn, option) => {
|
|
|
172
172
|
export let flatMap = (fn, option) => {
|
|
173
173
|
match (option) {
|
|
174
174
|
Some(x) => fn(x),
|
|
175
|
-
None => None
|
|
175
|
+
None => None,
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
|
|
@@ -194,7 +194,7 @@ export let filter = (fn, option) => {
|
|
|
194
194
|
} else {
|
|
195
195
|
None
|
|
196
196
|
},
|
|
197
|
-
None => None
|
|
197
|
+
None => None,
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
200
|
|
|
@@ -210,7 +210,7 @@ export let filter = (fn, option) => {
|
|
|
210
210
|
export let zip = (optionA, optionB) => {
|
|
211
211
|
match ((optionA, optionB)) {
|
|
212
212
|
(Some(a), Some(b)) => Some((a, b)),
|
|
213
|
-
_ => None
|
|
213
|
+
_ => None,
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
|
|
@@ -227,7 +227,7 @@ export let zip = (optionA, optionB) => {
|
|
|
227
227
|
export let zipWith = (fn, optionA, optionB) => {
|
|
228
228
|
match ((optionA, optionB)) {
|
|
229
229
|
(Some(a), Some(b)) => Some(fn(a, b)),
|
|
230
|
-
_ => None
|
|
230
|
+
_ => None,
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
233
|
|
|
@@ -241,10 +241,10 @@ export let zipWith = (fn, optionA, optionB) => {
|
|
|
241
241
|
*
|
|
242
242
|
* @since v0.2.0
|
|
243
243
|
*/
|
|
244
|
-
export let flatten =
|
|
244
|
+
export let flatten = option => {
|
|
245
245
|
match (option) {
|
|
246
246
|
Some(Some(x)) => Some(x),
|
|
247
|
-
_ => None
|
|
247
|
+
_ => None,
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
250
|
|
|
@@ -256,10 +256,10 @@ export let flatten = (option) => {
|
|
|
256
256
|
*
|
|
257
257
|
* @since v0.2.0
|
|
258
258
|
*/
|
|
259
|
-
export let toList =
|
|
259
|
+
export let toList = option => {
|
|
260
260
|
match (option) {
|
|
261
261
|
Some(x) => [x],
|
|
262
|
-
None => []
|
|
262
|
+
None => [],
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
265
|
|
|
@@ -271,10 +271,10 @@ export let toList = (option) => {
|
|
|
271
271
|
*
|
|
272
272
|
* @since v0.2.0
|
|
273
273
|
*/
|
|
274
|
-
export let toArray =
|
|
274
|
+
export let toArray = option => {
|
|
275
275
|
match (option) {
|
|
276
276
|
Some(x) => [> x],
|
|
277
|
-
None => [>]
|
|
277
|
+
None => [>],
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
280
|
|
|
@@ -290,7 +290,7 @@ export let toArray = (option) => {
|
|
|
290
290
|
export let toResult = (err, option) => {
|
|
291
291
|
match (option) {
|
|
292
292
|
Some(a) => Ok(a),
|
|
293
|
-
None
|
|
293
|
+
None => Err(err),
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
296
|
|
|
@@ -305,7 +305,7 @@ export let toResult = (err, option) => {
|
|
|
305
305
|
export let sideEffect = (fn, option) => {
|
|
306
306
|
match (option) {
|
|
307
307
|
Some(x) => fn(x),
|
|
308
|
-
None => void
|
|
308
|
+
None => void,
|
|
309
309
|
}
|
|
310
310
|
}
|
|
311
311
|
|
|
@@ -336,7 +336,7 @@ export let peek = (fn, option) => {
|
|
|
336
336
|
export let or = (optionA, optionB) => {
|
|
337
337
|
match (optionA) {
|
|
338
338
|
Some(x) => optionA,
|
|
339
|
-
None => optionB
|
|
339
|
+
None => optionB,
|
|
340
340
|
}
|
|
341
341
|
}
|
|
342
342
|
|
|
@@ -352,6 +352,6 @@ export let or = (optionA, optionB) => {
|
|
|
352
352
|
export let and = (optionA, optionB) => {
|
|
353
353
|
match (optionA) {
|
|
354
354
|
Some(_) => optionB,
|
|
355
|
-
None => optionA
|
|
355
|
+
None => optionA,
|
|
356
356
|
}
|
|
357
357
|
}
|
package/package.json
CHANGED
package/pervasives.gr
CHANGED
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
(^),
|
|
25
25
|
(<<),
|
|
26
26
|
(>>>),
|
|
27
|
-
(>>)
|
|
27
|
+
(>>),
|
|
28
28
|
} from "runtime/numbers"
|
|
29
29
|
|
|
30
30
|
// Math operations
|
|
@@ -53,7 +53,6 @@ export (<<)
|
|
|
53
53
|
export (>>>)
|
|
54
54
|
export (>>)
|
|
55
55
|
|
|
56
|
-
|
|
57
56
|
// Number coercions & conversions
|
|
58
57
|
|
|
59
58
|
// [TODO] (#311) Commented until we nail down semantics
|
|
@@ -61,23 +60,23 @@ export (>>)
|
|
|
61
60
|
// import foreign wasm convertInexactToExact : Number -> Number as exact from "stdlib-external/runtime"
|
|
62
61
|
|
|
63
62
|
// Boolean operations
|
|
64
|
-
primitive (!)
|
|
65
|
-
primitive (&&)
|
|
66
|
-
primitive (||)
|
|
63
|
+
primitive (!): Bool -> Bool = "@not"
|
|
64
|
+
primitive (&&): (Bool, Bool) -> Bool = "@and"
|
|
65
|
+
primitive (||): (Bool, Bool) -> Bool = "@or"
|
|
67
66
|
|
|
68
67
|
// Box operations
|
|
69
|
-
primitive box
|
|
70
|
-
primitive unbox
|
|
68
|
+
primitive box: a -> Box<a> = "@box"
|
|
69
|
+
primitive unbox: Box<a> -> a = "@unbox"
|
|
71
70
|
|
|
72
71
|
// Exceptions
|
|
73
72
|
exception Failure(String)
|
|
74
73
|
exception InvalidArgument(String)
|
|
75
74
|
|
|
76
75
|
// Other operations
|
|
77
|
-
primitive ignore
|
|
78
|
-
primitive assert
|
|
79
|
-
primitive throw
|
|
80
|
-
let fail
|
|
76
|
+
primitive ignore: a -> Void = "@ignore"
|
|
77
|
+
primitive assert: Bool -> Void = "@assert"
|
|
78
|
+
primitive throw: Exception -> a = "@throw"
|
|
79
|
+
let fail: String -> a = msg => throw Failure(msg)
|
|
81
80
|
|
|
82
81
|
import { toString, print, concat as (++) } from "runtime/string"
|
|
83
82
|
|
|
@@ -91,28 +90,41 @@ export (++)
|
|
|
91
90
|
|
|
92
91
|
// Checks the given items for structural equality.
|
|
93
92
|
export (==)
|
|
94
|
-
let (!=)
|
|
93
|
+
let (!=): (a, a) -> Bool = (x, y) => !(x == y)
|
|
95
94
|
// Checks the given items for physical equality.
|
|
96
|
-
primitive (is)
|
|
95
|
+
primitive (is): (a, a) -> Bool = "@is"
|
|
97
96
|
// The opposite of is operator
|
|
98
|
-
let (isnt)
|
|
97
|
+
let (isnt): (a, a) -> Bool = (x, y) => !(x is y)
|
|
99
98
|
|
|
100
|
-
export enum List<a> {
|
|
99
|
+
export enum List<a> {
|
|
100
|
+
[],
|
|
101
|
+
[...](a, List<a>),
|
|
102
|
+
}
|
|
101
103
|
|
|
102
104
|
/**
|
|
103
105
|
* @deprecated This will be removed in a future release of Grain.
|
|
104
106
|
*/
|
|
105
|
-
let cons = (a, b) =>
|
|
107
|
+
let cons = (a, b) =>
|
|
108
|
+
[
|
|
109
|
+
a,
|
|
110
|
+
...b
|
|
111
|
+
] // <- workaround for (grain-lang/grain#802) [TODO] fix #802 and delete
|
|
106
112
|
let empty = [] // <- for parity with `cons`, but should be deleted as well
|
|
107
113
|
|
|
108
114
|
// Maybe some data, maybe not!
|
|
109
|
-
enum Option<a> {
|
|
115
|
+
enum Option<a> {
|
|
116
|
+
Some(a),
|
|
117
|
+
None,
|
|
118
|
+
}
|
|
110
119
|
|
|
111
120
|
// Maybe some data, maybe an error!
|
|
112
|
-
enum Result<t, e> {
|
|
121
|
+
enum Result<t, e> {
|
|
122
|
+
Ok(t),
|
|
123
|
+
Err(e),
|
|
124
|
+
}
|
|
113
125
|
|
|
114
126
|
// Identity function
|
|
115
|
-
let identity =
|
|
127
|
+
let identity = x => x
|
|
116
128
|
|
|
117
129
|
// Setup exception printing
|
|
118
130
|
@disableGC
|
|
@@ -121,7 +133,7 @@ let rec setupExceptions = () => {
|
|
|
121
133
|
match (e) {
|
|
122
134
|
Failure(msg) => Some("Failure: " ++ msg),
|
|
123
135
|
InvalidArgument(msg) => Some("Invalid argument: " ++ msg),
|
|
124
|
-
_ => None
|
|
136
|
+
_ => None,
|
|
125
137
|
}
|
|
126
138
|
})
|
|
127
139
|
|
package/queue.gr
CHANGED
package/range.gr
CHANGED
|
@@ -38,7 +38,7 @@ export let inRange = (value, range) => {
|
|
|
38
38
|
Inclusive(upper, lower) when value >= lower && value <= upper => true,
|
|
39
39
|
Exclusive(lower, upper) when value >= lower && value < upper => true,
|
|
40
40
|
Exclusive(upper, lower) when value >= lower && value < upper => true,
|
|
41
|
-
_ => false
|
|
41
|
+
_ => false,
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -52,34 +52,34 @@ export let inRange = (value, range) => {
|
|
|
52
52
|
*
|
|
53
53
|
* @since v0.3.0
|
|
54
54
|
*/
|
|
55
|
-
export let forEach = (fn:
|
|
55
|
+
export let forEach = (fn: Number -> Void, range) => {
|
|
56
56
|
match (range) {
|
|
57
57
|
Inclusive(lower, upper) when lower <= upper => {
|
|
58
|
-
let mut idx = lower
|
|
58
|
+
let mut idx = lower
|
|
59
59
|
while (idx <= upper) {
|
|
60
|
-
fn(idx)
|
|
61
|
-
idx += 1
|
|
60
|
+
fn(idx)
|
|
61
|
+
idx += 1
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
64
|
Inclusive(upper, lower) => {
|
|
65
|
-
let mut idx = upper
|
|
65
|
+
let mut idx = upper
|
|
66
66
|
while (idx >= lower) {
|
|
67
|
-
fn(idx)
|
|
68
|
-
idx -= 1
|
|
67
|
+
fn(idx)
|
|
68
|
+
idx -= 1
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
71
|
Exclusive(lower, upper) when lower <= upper => {
|
|
72
|
-
let mut idx = lower
|
|
72
|
+
let mut idx = lower
|
|
73
73
|
while (idx < upper) {
|
|
74
|
-
fn(idx)
|
|
75
|
-
idx += 1
|
|
74
|
+
fn(idx)
|
|
75
|
+
idx += 1
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
78
|
Exclusive(upper, lower) => {
|
|
79
|
-
let mut idx = upper
|
|
79
|
+
let mut idx = upper
|
|
80
80
|
while (idx > lower) {
|
|
81
|
-
fn(idx)
|
|
82
|
-
idx -= 1
|
|
81
|
+
fn(idx)
|
|
82
|
+
idx -= 1
|
|
83
83
|
}
|
|
84
84
|
},
|
|
85
85
|
}
|
|
@@ -100,31 +100,31 @@ export let map = (fn, range) => {
|
|
|
100
100
|
let mut result = []
|
|
101
101
|
match (range) {
|
|
102
102
|
Inclusive(lower, upper) when lower <= upper => {
|
|
103
|
-
let mut idx = upper
|
|
103
|
+
let mut idx = upper
|
|
104
104
|
while (idx >= lower) {
|
|
105
|
-
result = [fn(idx), ...result]
|
|
106
|
-
idx -= 1
|
|
105
|
+
result = [fn(idx), ...result]
|
|
106
|
+
idx -= 1
|
|
107
107
|
}
|
|
108
108
|
},
|
|
109
109
|
Inclusive(upper, lower) => {
|
|
110
|
-
let mut idx = lower
|
|
110
|
+
let mut idx = lower
|
|
111
111
|
while (idx <= upper) {
|
|
112
|
-
result = [fn(idx), ...result]
|
|
113
|
-
idx += 1
|
|
112
|
+
result = [fn(idx), ...result]
|
|
113
|
+
idx += 1
|
|
114
114
|
}
|
|
115
115
|
},
|
|
116
116
|
Exclusive(lower, upper) when lower <= upper => {
|
|
117
|
-
let mut idx = upper - 1
|
|
117
|
+
let mut idx = upper - 1
|
|
118
118
|
while (idx >= lower) {
|
|
119
|
-
result = [fn(idx), ...result]
|
|
120
|
-
idx -= 1
|
|
119
|
+
result = [fn(idx), ...result]
|
|
120
|
+
idx -= 1
|
|
121
121
|
}
|
|
122
122
|
},
|
|
123
123
|
Exclusive(upper, lower) => {
|
|
124
|
-
let mut idx = lower + 1
|
|
124
|
+
let mut idx = lower + 1
|
|
125
125
|
while (idx <= upper) {
|
|
126
|
-
result = [fn(idx), ...result]
|
|
127
|
-
idx += 1
|
|
126
|
+
result = [fn(idx), ...result]
|
|
127
|
+
idx += 1
|
|
128
128
|
}
|
|
129
129
|
},
|
|
130
130
|
}
|
|
@@ -6,7 +6,7 @@ import WasmI32, {
|
|
|
6
6
|
add as (+),
|
|
7
7
|
mul as (*),
|
|
8
8
|
xor as (^),
|
|
9
|
-
shl as (<<)
|
|
9
|
+
shl as (<<),
|
|
10
10
|
} from "runtime/unsafe/wasmi32"
|
|
11
11
|
import WasmI64 from "runtime/unsafe/wasmi64"
|
|
12
12
|
import WasmF32 from "runtime/unsafe/wasmf32"
|
|
@@ -23,7 +23,7 @@ import WasmF64 from "runtime/unsafe/wasmf64"
|
|
|
23
23
|
* @param {WasmI32} numElts The number of elements to be contained in this array
|
|
24
24
|
* @returns {WasmI32} The pointer to the array
|
|
25
25
|
*/
|
|
26
|
-
export let allocateArray =
|
|
26
|
+
export let allocateArray = numElts => {
|
|
27
27
|
let arr = Memory.malloc((numElts + 2n) * 4n)
|
|
28
28
|
|
|
29
29
|
WasmI32.store(arr, Tags._GRAIN_ARRAY_HEAP_TAG, 0n)
|
|
@@ -49,7 +49,7 @@ export let storeInArray = (arr, idx, item) => {
|
|
|
49
49
|
* @param {WasmI32} numElts The number of elements to be contained in this tuple
|
|
50
50
|
* @returns {WasmI32} The pointer to the tuple
|
|
51
51
|
*/
|
|
52
|
-
export let allocateTuple =
|
|
52
|
+
export let allocateTuple = numElts => {
|
|
53
53
|
let tuple = Memory.malloc((numElts + 2n) * 4n)
|
|
54
54
|
|
|
55
55
|
WasmI32.store(tuple, Tags._GRAIN_TUPLE_HEAP_TAG, 0n)
|
|
@@ -75,7 +75,7 @@ export let storeInTuple = (tuple, idx, item) => {
|
|
|
75
75
|
* @param {WasmI32} size The number of bytes to be contained in this buffer
|
|
76
76
|
* @returns {WasmI32} The pointer to the bytes
|
|
77
77
|
*/
|
|
78
|
-
export let allocateBytes =
|
|
78
|
+
export let allocateBytes = size => {
|
|
79
79
|
let len = size + 8n
|
|
80
80
|
let bytes = Memory.malloc(len)
|
|
81
81
|
Memory.fill(bytes, 0n, len)
|
|
@@ -90,7 +90,7 @@ export let allocateBytes = (size) => {
|
|
|
90
90
|
* @param {WasmI32} size The size (in bytes) of the string to allocate
|
|
91
91
|
* @returns {WasmI32} The pointer to the string
|
|
92
92
|
*/
|
|
93
|
-
export let allocateString =
|
|
93
|
+
export let allocateString = size => {
|
|
94
94
|
let str = Memory.malloc(size + 8n)
|
|
95
95
|
|
|
96
96
|
WasmI32.store(str, Tags._GRAIN_STRING_HEAP_TAG, 0n)
|
|
@@ -105,7 +105,7 @@ export let allocateString = (size) => {
|
|
|
105
105
|
* @param {WasmI32} c The character for which to allocate a string
|
|
106
106
|
* @returns {WasmI32} The pointer to the string
|
|
107
107
|
*/
|
|
108
|
-
export let singleByteString =
|
|
108
|
+
export let singleByteString = c => {
|
|
109
109
|
let str = Memory.malloc(9n)
|
|
110
110
|
|
|
111
111
|
WasmI32.store(str, Tags._GRAIN_STRING_HEAP_TAG, 0n)
|
|
@@ -148,7 +148,7 @@ export let allocateInt64 = () => {
|
|
|
148
148
|
* Allocates a new Int64 with a prepopulated value
|
|
149
149
|
* @param value The value to store
|
|
150
150
|
*/
|
|
151
|
-
export let newInt64 =
|
|
151
|
+
export let newInt64 = value => {
|
|
152
152
|
let ptr = allocateInt64()
|
|
153
153
|
WasmI64.store(ptr, value, 8n)
|
|
154
154
|
ptr
|
|
@@ -158,11 +158,11 @@ export let newInt64 = (value) => {
|
|
|
158
158
|
* Returns a pointer to the heap location containing this boxed number's Int64
|
|
159
159
|
* @param wrappedInt64 The boxed int64 to return
|
|
160
160
|
*/
|
|
161
|
-
export let rawInt64Ptr =
|
|
161
|
+
export let rawInt64Ptr = wrappedInt64 => {
|
|
162
162
|
wrappedInt64 + 8n
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
export let loadInt64 =
|
|
165
|
+
export let loadInt64 = xptr => {
|
|
166
166
|
WasmI64.load(xptr, 8n)
|
|
167
167
|
}
|
|
168
168
|
|
|
@@ -184,7 +184,7 @@ export let allocateInt32 = () => {
|
|
|
184
184
|
* Allocates a new Int32 with a prepopulated value
|
|
185
185
|
* @param value The value to store
|
|
186
186
|
*/
|
|
187
|
-
export let newInt32 =
|
|
187
|
+
export let newInt32 = value => {
|
|
188
188
|
let ptr = allocateInt32()
|
|
189
189
|
WasmI32.store(ptr, value, 8n)
|
|
190
190
|
ptr
|
|
@@ -194,11 +194,11 @@ export let newInt32 = (value) => {
|
|
|
194
194
|
* Returns a pointer to the heap location containing this boxed number's Int32
|
|
195
195
|
* @param wrappedInt32 The boxed int32 to return
|
|
196
196
|
*/
|
|
197
|
-
export let rawInt32Ptr =
|
|
197
|
+
export let rawInt32Ptr = wrappedInt32 => {
|
|
198
198
|
wrappedInt32 + 8n
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
-
export let loadInt32 =
|
|
201
|
+
export let loadInt32 = xptr => {
|
|
202
202
|
WasmI32.load(xptr, 8n)
|
|
203
203
|
}
|
|
204
204
|
|
|
@@ -222,7 +222,7 @@ export let allocateFloat32 = () => {
|
|
|
222
222
|
* Allocates a new Float32 with a prepopulated value
|
|
223
223
|
* @param value The value to store
|
|
224
224
|
*/
|
|
225
|
-
export let newFloat32 =
|
|
225
|
+
export let newFloat32 = value => {
|
|
226
226
|
let ptr = allocateFloat32()
|
|
227
227
|
WasmF32.store(ptr, value, 8n)
|
|
228
228
|
ptr
|
|
@@ -232,11 +232,11 @@ export let newFloat32 = (value) => {
|
|
|
232
232
|
* Returns a pointer to the heap location containing this boxed number's Float32
|
|
233
233
|
* @param wrappedFloat32 The boxed float32 to return
|
|
234
234
|
*/
|
|
235
|
-
export let rawFloat32Ptr =
|
|
235
|
+
export let rawFloat32Ptr = wrappedFloat32 => {
|
|
236
236
|
wrappedFloat32 + 8n
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
-
export let loadFloat32 =
|
|
239
|
+
export let loadFloat32 = xptr => {
|
|
240
240
|
WasmF32.load(xptr, 8n)
|
|
241
241
|
}
|
|
242
242
|
|
|
@@ -258,7 +258,7 @@ export let allocateFloat64 = () => {
|
|
|
258
258
|
* Allocates a new Float64 with a prepopulated value
|
|
259
259
|
* @param value The value to store
|
|
260
260
|
*/
|
|
261
|
-
export let newFloat64 =
|
|
261
|
+
export let newFloat64 = value => {
|
|
262
262
|
let ptr = allocateFloat64()
|
|
263
263
|
WasmF64.store(ptr, value, 8n)
|
|
264
264
|
ptr
|
|
@@ -268,11 +268,11 @@ export let newFloat64 = (value) => {
|
|
|
268
268
|
* Returns a pointer to the heap location containing this boxed number's Float64
|
|
269
269
|
* @param wrappedFloat64 The boxed float64 to return
|
|
270
270
|
*/
|
|
271
|
-
export let rawFloat64Ptr =
|
|
271
|
+
export let rawFloat64Ptr = wrappedFloat64 => {
|
|
272
272
|
wrappedFloat64 + 8n
|
|
273
273
|
}
|
|
274
274
|
|
|
275
|
-
export let loadFloat64 =
|
|
275
|
+
export let loadFloat64 = xptr => {
|
|
276
276
|
WasmF64.load(xptr, 8n)
|
|
277
277
|
}
|
|
278
278
|
|
|
@@ -296,7 +296,7 @@ export let allocateRational = () => {
|
|
|
296
296
|
* Allocates a new Rational with a prepopulated value
|
|
297
297
|
* @param value The value to store
|
|
298
298
|
*/
|
|
299
|
-
export let newRational = (numerator, denominator) =>{
|
|
299
|
+
export let newRational = (numerator, denominator) => {
|
|
300
300
|
let ptr = allocateRational()
|
|
301
301
|
WasmI32.store(ptr, numerator, 8n)
|
|
302
302
|
WasmI32.store(ptr, denominator, 12n)
|
|
@@ -307,7 +307,7 @@ export let newRational = (numerator, denominator) =>{
|
|
|
307
307
|
* Returns a pointer to the heap location containing this boxed number's Rational numerator
|
|
308
308
|
* @param wrappedRational The boxed rational to return
|
|
309
309
|
*/
|
|
310
|
-
export let rawRationalNumeratorPtr =
|
|
310
|
+
export let rawRationalNumeratorPtr = wrappedRational => {
|
|
311
311
|
wrappedRational + 8n
|
|
312
312
|
}
|
|
313
313
|
|
|
@@ -315,19 +315,18 @@ export let rawRationalNumeratorPtr = (wrappedRational) => {
|
|
|
315
315
|
* Returns a pointer to the heap location containing this boxed number's Rational numerator
|
|
316
316
|
* @param wrappedRational The boxed rational to return
|
|
317
317
|
*/
|
|
318
|
-
export let rawRationalDenominatorPtr =
|
|
318
|
+
export let rawRationalDenominatorPtr = wrappedRational => {
|
|
319
319
|
wrappedRational + 12n
|
|
320
320
|
}
|
|
321
321
|
|
|
322
|
-
export let loadRationalNumerator =
|
|
322
|
+
export let loadRationalNumerator = xptr => {
|
|
323
323
|
WasmI32.load(xptr, 8n)
|
|
324
324
|
}
|
|
325
325
|
|
|
326
|
-
export let loadRationalDenominator =
|
|
326
|
+
export let loadRationalDenominator = xptr => {
|
|
327
327
|
WasmI32.load(xptr, 12n)
|
|
328
328
|
}
|
|
329
329
|
|
|
330
|
-
|
|
331
330
|
/**
|
|
332
331
|
* Load a value from an ADT.
|
|
333
332
|
*
|
|
@@ -337,7 +336,7 @@ export let loadRationalDenominator = (xptr) => {
|
|
|
337
336
|
* @returns {WasmI32} The value located at the index
|
|
338
337
|
*/
|
|
339
338
|
export let loadAdtVal = (ptr, idx) => {
|
|
340
|
-
WasmI32.load(ptr +
|
|
339
|
+
WasmI32.load(ptr + idx * 4n, 20n)
|
|
341
340
|
}
|
|
342
341
|
|
|
343
342
|
/**
|
|
@@ -347,7 +346,7 @@ export let loadAdtVal = (ptr, idx) => {
|
|
|
347
346
|
* @param {WasmI32} ptr Untagged pointer to the ADT
|
|
348
347
|
* @returns {WasmI32} The (tagged) ADT variant id
|
|
349
348
|
*/
|
|
350
|
-
export let loadAdtVariant =
|
|
349
|
+
export let loadAdtVariant = ptr => {
|
|
351
350
|
WasmI32.load(ptr, 12n)
|
|
352
351
|
}
|
|
353
352
|
|
|
@@ -358,10 +357,10 @@ export let loadAdtVariant = (ptr) => {
|
|
|
358
357
|
* @param {WasmI32} ptr Untagged pointer to the string
|
|
359
358
|
* @returns {WasmI32} The string size (in bytes)
|
|
360
359
|
*/
|
|
361
|
-
export let stringSize =
|
|
360
|
+
export let stringSize = ptr => {
|
|
362
361
|
WasmI32.load(ptr, 4n)
|
|
363
362
|
}
|
|
364
363
|
|
|
365
|
-
export let tagSimpleNumber =
|
|
366
|
-
WasmI32.toGrain(
|
|
364
|
+
export let tagSimpleNumber = x => {
|
|
365
|
+
WasmI32.toGrain(x << 1n ^ 1n): Number
|
|
367
366
|
}
|
package/runtime/debug.gr
CHANGED