@grain/stdlib 0.4.5 → 0.5.1
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 +87 -0
- package/LICENSE +1 -1
- package/array.gr +18 -18
- package/array.md +18 -18
- package/bigint.gr +497 -0
- package/bigint.md +811 -0
- package/buffer.gr +49 -213
- package/buffer.md +24 -17
- package/bytes.gr +100 -202
- package/bytes.md +19 -0
- package/char.gr +63 -133
- package/exception.md +6 -0
- package/float32.gr +159 -82
- package/float32.md +315 -0
- package/float64.gr +163 -82
- package/float64.md +315 -0
- package/hash.gr +37 -37
- package/int32.gr +479 -230
- package/int32.md +937 -0
- package/int64.gr +479 -230
- package/int64.md +937 -0
- package/list.gr +467 -70
- package/list.md +1141 -0
- package/map.gr +192 -7
- package/map.md +525 -0
- package/number.gr +30 -54
- package/number.md +3 -3
- package/option.md +1 -1
- package/package.json +3 -3
- package/pervasives.gr +499 -59
- package/pervasives.md +1116 -0
- package/queue.gr +4 -0
- package/queue.md +10 -0
- package/random.gr +196 -0
- package/random.md +179 -0
- package/regex.gr +1833 -842
- package/regex.md +11 -11
- package/result.md +1 -1
- package/runtime/bigint.gr +2045 -0
- package/runtime/bigint.md +326 -0
- package/runtime/dataStructures.gr +99 -278
- package/runtime/dataStructures.md +391 -0
- package/runtime/debug.md +6 -0
- package/runtime/equal.gr +5 -23
- package/runtime/equal.md +6 -0
- package/runtime/exception.md +30 -0
- package/runtime/gc.gr +20 -3
- package/runtime/gc.md +36 -0
- package/runtime/malloc.gr +13 -11
- package/runtime/malloc.md +55 -0
- package/runtime/numberUtils.gr +93 -41
- package/runtime/numberUtils.md +54 -0
- package/runtime/numbers.gr +1043 -391
- package/runtime/numbers.md +300 -0
- package/runtime/string.gr +136 -230
- package/runtime/string.md +24 -0
- package/runtime/stringUtils.gr +58 -38
- package/runtime/stringUtils.md +6 -0
- package/runtime/unsafe/constants.gr +17 -0
- package/runtime/unsafe/constants.md +72 -0
- package/runtime/unsafe/conv.md +71 -0
- package/runtime/unsafe/errors.md +204 -0
- package/runtime/unsafe/memory.md +54 -0
- package/runtime/unsafe/printWasm.md +24 -0
- package/runtime/unsafe/tags.gr +9 -8
- package/runtime/unsafe/tags.md +120 -0
- package/runtime/unsafe/wasmf32.md +168 -0
- package/runtime/unsafe/wasmf64.md +168 -0
- package/runtime/unsafe/wasmi32.md +282 -0
- package/runtime/unsafe/wasmi64.md +300 -0
- package/runtime/utils/printing.gr +62 -0
- package/runtime/utils/printing.md +18 -0
- package/runtime/wasi.gr +1 -1
- package/runtime/wasi.md +839 -0
- package/set.gr +17 -8
- package/set.md +24 -21
- package/stack.gr +3 -3
- package/stack.md +4 -6
- package/string.gr +196 -331
- package/string.md +3 -3
- package/sys/file.gr +246 -430
- package/sys/process.gr +27 -45
- package/sys/random.gr +47 -16
- package/sys/random.md +38 -0
- package/sys/time.gr +11 -27
package/bytes.gr
CHANGED
|
@@ -12,48 +12,30 @@ import WasmI64 from "runtime/unsafe/wasmi64"
|
|
|
12
12
|
import WasmF32 from "runtime/unsafe/wasmf32"
|
|
13
13
|
import WasmF64 from "runtime/unsafe/wasmf64"
|
|
14
14
|
import Conv from "runtime/unsafe/conv"
|
|
15
|
-
import {
|
|
16
|
-
tagSimpleNumber,
|
|
17
|
-
allocateBytes,
|
|
18
|
-
allocateString,
|
|
19
|
-
} from "runtime/dataStructures"
|
|
15
|
+
import { allocateBytes, allocateString } from "runtime/dataStructures"
|
|
20
16
|
import Exception from "runtime/exception"
|
|
21
17
|
import Int32 from "int32"
|
|
22
18
|
import { coerceNumberToWasmI32 } from "runtime/numbers"
|
|
23
19
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
let mut _FLOAT64_BYTE_SIZE = 1n
|
|
41
|
-
|
|
42
|
-
@disableGC
|
|
43
|
-
let initVals = () => {
|
|
44
|
-
_SIZE_OFFSET = 4n
|
|
45
|
-
_VALUE_OFFSET = 8n
|
|
46
|
-
_INT8_BYTE_SIZE = 1n
|
|
47
|
-
_INT16_BYTE_SIZE = 2n
|
|
48
|
-
_INT32_BYTE_SIZE = 4n
|
|
49
|
-
_FLOAT32_BYTE_SIZE = 4n
|
|
50
|
-
_INT64_BYTE_SIZE = 8n
|
|
51
|
-
_FLOAT64_BYTE_SIZE = 8n
|
|
52
|
-
}
|
|
53
|
-
initVals()
|
|
20
|
+
@unsafe
|
|
21
|
+
let _SIZE_OFFSET = 4n
|
|
22
|
+
@unsafe
|
|
23
|
+
let _VALUE_OFFSET = 8n
|
|
24
|
+
@unsafe
|
|
25
|
+
let _INT8_BYTE_SIZE = 1n
|
|
26
|
+
@unsafe
|
|
27
|
+
let _INT16_BYTE_SIZE = 2n
|
|
28
|
+
@unsafe
|
|
29
|
+
let _INT32_BYTE_SIZE = 4n
|
|
30
|
+
@unsafe
|
|
31
|
+
let _FLOAT32_BYTE_SIZE = 4n
|
|
32
|
+
@unsafe
|
|
33
|
+
let _INT64_BYTE_SIZE = 8n
|
|
34
|
+
@unsafe
|
|
35
|
+
let _FLOAT64_BYTE_SIZE = 8n
|
|
54
36
|
|
|
55
37
|
/** Throws an exception if the index specified is out-of-bounds */
|
|
56
|
-
@
|
|
38
|
+
@unsafe
|
|
57
39
|
let checkIndexIsInBounds = (i, byteSize, max) => {
|
|
58
40
|
let (+) = WasmI32.add
|
|
59
41
|
let (<) = WasmI32.ltS
|
|
@@ -67,7 +49,7 @@ let checkIndexIsInBounds = (i, byteSize, max) => {
|
|
|
67
49
|
}
|
|
68
50
|
|
|
69
51
|
/** Gets the size of a Bytes via its ptr */
|
|
70
|
-
@
|
|
52
|
+
@unsafe
|
|
71
53
|
let getSize = ptr => WasmI32.load(ptr, _SIZE_OFFSET)
|
|
72
54
|
|
|
73
55
|
/**
|
|
@@ -82,13 +64,10 @@ let getSize = ptr => WasmI32.load(ptr, _SIZE_OFFSET)
|
|
|
82
64
|
*
|
|
83
65
|
* @since v0.3.2
|
|
84
66
|
*/
|
|
85
|
-
@
|
|
86
|
-
export let
|
|
67
|
+
@unsafe
|
|
68
|
+
export let make = (size: Number) => {
|
|
87
69
|
let bytes = allocateBytes(coerceNumberToWasmI32(size))
|
|
88
|
-
|
|
89
|
-
Memory.decRef(WasmI32.fromGrain(size))
|
|
90
|
-
Memory.decRef(WasmI32.fromGrain(make))
|
|
91
|
-
ret
|
|
70
|
+
WasmI32.toGrain(bytes): Bytes
|
|
92
71
|
}
|
|
93
72
|
|
|
94
73
|
/**
|
|
@@ -106,17 +85,14 @@ export let empty = make(0)
|
|
|
106
85
|
*
|
|
107
86
|
* @since v0.3.2
|
|
108
87
|
*/
|
|
109
|
-
@
|
|
110
|
-
export let
|
|
88
|
+
@unsafe
|
|
89
|
+
export let fromString = (string: String) => {
|
|
111
90
|
let (+) = WasmI32.add
|
|
112
91
|
let src = WasmI32.fromGrain(string)
|
|
113
92
|
let size = getSize(src)
|
|
114
93
|
let dst = allocateBytes(size)
|
|
115
94
|
Memory.copy(dst + _VALUE_OFFSET, src + _VALUE_OFFSET, size)
|
|
116
|
-
|
|
117
|
-
Memory.decRef(WasmI32.fromGrain(string))
|
|
118
|
-
Memory.decRef(WasmI32.fromGrain(fromString))
|
|
119
|
-
ret
|
|
95
|
+
WasmI32.toGrain(dst): Bytes
|
|
120
96
|
}
|
|
121
97
|
|
|
122
98
|
/**
|
|
@@ -127,17 +103,14 @@ export let rec fromString = (string: String) => {
|
|
|
127
103
|
*
|
|
128
104
|
* @since v0.3.2
|
|
129
105
|
*/
|
|
130
|
-
@
|
|
131
|
-
export let
|
|
106
|
+
@unsafe
|
|
107
|
+
export let toString = (bytes: Bytes) => {
|
|
132
108
|
let (+) = WasmI32.add
|
|
133
109
|
let src = WasmI32.fromGrain(bytes)
|
|
134
110
|
let size = getSize(src)
|
|
135
111
|
let dst = allocateString(size)
|
|
136
112
|
Memory.copy(dst + _VALUE_OFFSET, src + _VALUE_OFFSET, size)
|
|
137
|
-
|
|
138
|
-
Memory.decRef(WasmI32.fromGrain(bytes))
|
|
139
|
-
Memory.decRef(WasmI32.fromGrain(toString))
|
|
140
|
-
ret
|
|
113
|
+
WasmI32.toGrain(dst): String
|
|
141
114
|
}
|
|
142
115
|
|
|
143
116
|
/**
|
|
@@ -148,13 +121,10 @@ export let rec toString = (bytes: Bytes) => {
|
|
|
148
121
|
*
|
|
149
122
|
* @since v0.3.2
|
|
150
123
|
*/
|
|
151
|
-
@
|
|
152
|
-
export let
|
|
124
|
+
@unsafe
|
|
125
|
+
export let length = (bytes: Bytes) => {
|
|
153
126
|
let b = WasmI32.fromGrain(bytes)
|
|
154
|
-
|
|
155
|
-
Memory.decRef(WasmI32.fromGrain(bytes))
|
|
156
|
-
Memory.decRef(WasmI32.fromGrain(length))
|
|
157
|
-
ret
|
|
127
|
+
Conv.wasmI32ToNumber(getSize(b))
|
|
158
128
|
}
|
|
159
129
|
|
|
160
130
|
/**
|
|
@@ -165,17 +135,14 @@ export let rec length = (bytes: Bytes) => {
|
|
|
165
135
|
*
|
|
166
136
|
* @since v0.3.2
|
|
167
137
|
*/
|
|
168
|
-
@
|
|
169
|
-
export let
|
|
138
|
+
@unsafe
|
|
139
|
+
export let copy = (b: Bytes) => {
|
|
170
140
|
let (+) = WasmI32.add
|
|
171
141
|
let src = WasmI32.fromGrain(b)
|
|
172
142
|
let size = getSize(src)
|
|
173
143
|
let dst = allocateBytes(size)
|
|
174
144
|
Memory.copy(dst + _VALUE_OFFSET, src + _VALUE_OFFSET, size)
|
|
175
|
-
|
|
176
|
-
Memory.decRef(WasmI32.fromGrain(b))
|
|
177
|
-
Memory.decRef(WasmI32.fromGrain(copy))
|
|
178
|
-
ret
|
|
145
|
+
WasmI32.toGrain(dst): Bytes
|
|
179
146
|
}
|
|
180
147
|
|
|
181
148
|
/**
|
|
@@ -188,8 +155,8 @@ export let rec copy = (b: Bytes) => {
|
|
|
188
155
|
*
|
|
189
156
|
* @since v0.3.2
|
|
190
157
|
*/
|
|
191
|
-
@
|
|
192
|
-
export let
|
|
158
|
+
@unsafe
|
|
159
|
+
export let slice = (start: Number, length: Number, bytes: Bytes) => {
|
|
193
160
|
let (>) = WasmI32.gtS
|
|
194
161
|
let (+) = WasmI32.add
|
|
195
162
|
let src = WasmI32.fromGrain(bytes)
|
|
@@ -206,12 +173,7 @@ export let rec slice = (start: Number, length: Number, bytes: Bytes) => {
|
|
|
206
173
|
let dst = allocateBytes(length)
|
|
207
174
|
let offset = start
|
|
208
175
|
Memory.copy(dst + _VALUE_OFFSET, src + _VALUE_OFFSET + start, length)
|
|
209
|
-
|
|
210
|
-
Memory.decRef(WasmI32.fromGrain(iOrig))
|
|
211
|
-
Memory.decRef(WasmI32.fromGrain(lenOrig))
|
|
212
|
-
Memory.decRef(WasmI32.fromGrain(bytes))
|
|
213
|
-
Memory.decRef(WasmI32.fromGrain(slice))
|
|
214
|
-
ret
|
|
176
|
+
WasmI32.toGrain(dst): Bytes
|
|
215
177
|
}
|
|
216
178
|
|
|
217
179
|
/**
|
|
@@ -226,8 +188,8 @@ export let rec slice = (start: Number, length: Number, bytes: Bytes) => {
|
|
|
226
188
|
*
|
|
227
189
|
* @since v0.3.2
|
|
228
190
|
*/
|
|
229
|
-
@
|
|
230
|
-
export let
|
|
191
|
+
@unsafe
|
|
192
|
+
export let resize = (left: Number, right: Number, bytes: Bytes) => {
|
|
231
193
|
let (<) = WasmI32.ltS
|
|
232
194
|
let (>) = WasmI32.gtS
|
|
233
195
|
let (+) = WasmI32.add
|
|
@@ -266,12 +228,7 @@ export let rec resize = (left: Number, right: Number, bytes: Bytes) => {
|
|
|
266
228
|
len
|
|
267
229
|
)
|
|
268
230
|
}
|
|
269
|
-
|
|
270
|
-
Memory.decRef(WasmI32.fromGrain(leftOrig))
|
|
271
|
-
Memory.decRef(WasmI32.fromGrain(rightOrig))
|
|
272
|
-
Memory.decRef(WasmI32.fromGrain(bytes))
|
|
273
|
-
Memory.decRef(WasmI32.fromGrain(resize))
|
|
274
|
-
ret
|
|
231
|
+
WasmI32.toGrain(dst): Bytes
|
|
275
232
|
}
|
|
276
233
|
|
|
277
234
|
/**
|
|
@@ -286,8 +243,8 @@ export let rec resize = (left: Number, right: Number, bytes: Bytes) => {
|
|
|
286
243
|
*
|
|
287
244
|
* @since v0.3.2
|
|
288
245
|
*/
|
|
289
|
-
@
|
|
290
|
-
export let
|
|
246
|
+
@unsafe
|
|
247
|
+
export let move =
|
|
291
248
|
(
|
|
292
249
|
srcIndex: Number,
|
|
293
250
|
dstIndex: Number,
|
|
@@ -314,19 +271,11 @@ export let rec move =
|
|
|
314
271
|
throw Exception.InvalidArgument("Invalid destination bytes range")
|
|
315
272
|
}
|
|
316
273
|
let end = srcIndex + length
|
|
317
|
-
|
|
274
|
+
Memory.copy(
|
|
318
275
|
dst + _VALUE_OFFSET + dstIndex,
|
|
319
276
|
src + _VALUE_OFFSET + srcIndex,
|
|
320
277
|
length
|
|
321
278
|
)
|
|
322
|
-
|
|
323
|
-
Memory.decRef(WasmI32.fromGrain(srcIndexOrig))
|
|
324
|
-
Memory.decRef(WasmI32.fromGrain(dstIndexOrig))
|
|
325
|
-
Memory.decRef(WasmI32.fromGrain(lenthOrig))
|
|
326
|
-
Memory.decRef(WasmI32.fromGrain(src))
|
|
327
|
-
Memory.decRef(WasmI32.fromGrain(dst))
|
|
328
|
-
Memory.decRef(WasmI32.fromGrain(move))
|
|
329
|
-
ret
|
|
330
279
|
}
|
|
331
280
|
|
|
332
281
|
/**
|
|
@@ -354,17 +303,28 @@ export let concat = (bytes1: Bytes, bytes2: Bytes) => {
|
|
|
354
303
|
*
|
|
355
304
|
* @since v0.3.2
|
|
356
305
|
*/
|
|
357
|
-
@
|
|
358
|
-
export let
|
|
306
|
+
@unsafe
|
|
307
|
+
export let fill = (value: Int32, bytes: Bytes) => {
|
|
359
308
|
let (+) = WasmI32.add
|
|
360
309
|
let src = WasmI32.fromGrain(bytes)
|
|
361
310
|
let size = getSize(src)
|
|
362
311
|
let v = Conv.fromInt32(value)
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
312
|
+
Memory.fill(src + _VALUE_OFFSET, v, size)
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Replaces all bytes in a byte sequence with zeroes.
|
|
317
|
+
*
|
|
318
|
+
* @param bytes: The byte sequence to clear
|
|
319
|
+
*
|
|
320
|
+
* @since v0.5.0
|
|
321
|
+
*/
|
|
322
|
+
@unsafe
|
|
323
|
+
export let clear = (bytes: Bytes) => {
|
|
324
|
+
let (+) = WasmI32.add
|
|
325
|
+
let src = WasmI32.fromGrain(bytes)
|
|
326
|
+
let size = getSize(src)
|
|
327
|
+
Memory.fill(src + _VALUE_OFFSET, 0n, size)
|
|
368
328
|
}
|
|
369
329
|
|
|
370
330
|
/**
|
|
@@ -380,19 +340,15 @@ export let rec fill = (value: Int32, bytes: Bytes) => {
|
|
|
380
340
|
*
|
|
381
341
|
* @since v0.3.2
|
|
382
342
|
*/
|
|
383
|
-
@
|
|
384
|
-
export let
|
|
343
|
+
@unsafe
|
|
344
|
+
export let getInt8S = (index: Number, bytes: Bytes) => {
|
|
385
345
|
let (+) = WasmI32.add
|
|
386
346
|
let ptr = WasmI32.fromGrain(bytes)
|
|
387
347
|
let size = getSize(ptr)
|
|
388
348
|
let offset = coerceNumberToWasmI32(index)
|
|
389
349
|
checkIndexIsInBounds(offset, _INT8_BYTE_SIZE, size)
|
|
390
350
|
let n = WasmI32.load8S(ptr + offset, _VALUE_OFFSET)
|
|
391
|
-
|
|
392
|
-
Memory.decRef(WasmI32.fromGrain(index))
|
|
393
|
-
Memory.decRef(WasmI32.fromGrain(bytes))
|
|
394
|
-
Memory.decRef(WasmI32.fromGrain(getInt8S))
|
|
395
|
-
ret
|
|
351
|
+
Conv.toInt32(n)
|
|
396
352
|
}
|
|
397
353
|
|
|
398
354
|
/**
|
|
@@ -404,7 +360,7 @@ export let rec getInt8S = (index: Number, bytes: Bytes) => {
|
|
|
404
360
|
*
|
|
405
361
|
* @since v0.3.2
|
|
406
362
|
*/
|
|
407
|
-
@
|
|
363
|
+
@unsafe
|
|
408
364
|
export let rec getInt8U = (index: Number, bytes: Bytes) => {
|
|
409
365
|
let (+) = WasmI32.add
|
|
410
366
|
let ptr = WasmI32.fromGrain(bytes)
|
|
@@ -412,11 +368,7 @@ export let rec getInt8U = (index: Number, bytes: Bytes) => {
|
|
|
412
368
|
let offset = coerceNumberToWasmI32(index)
|
|
413
369
|
checkIndexIsInBounds(offset, _INT8_BYTE_SIZE, size)
|
|
414
370
|
let n = WasmI32.load8U(ptr + offset, _VALUE_OFFSET)
|
|
415
|
-
|
|
416
|
-
Memory.decRef(WasmI32.fromGrain(index))
|
|
417
|
-
Memory.decRef(WasmI32.fromGrain(bytes))
|
|
418
|
-
Memory.decRef(WasmI32.fromGrain(getInt8U))
|
|
419
|
-
ret
|
|
371
|
+
Conv.toInt32(n)
|
|
420
372
|
}
|
|
421
373
|
|
|
422
374
|
/**
|
|
@@ -428,7 +380,7 @@ export let rec getInt8U = (index: Number, bytes: Bytes) => {
|
|
|
428
380
|
*
|
|
429
381
|
* @since v0.3.2
|
|
430
382
|
*/
|
|
431
|
-
@
|
|
383
|
+
@unsafe
|
|
432
384
|
export let rec setInt8 = (index: Number, value: Int32, bytes: Bytes) => {
|
|
433
385
|
let (+) = WasmI32.add
|
|
434
386
|
let ptr = WasmI32.fromGrain(bytes)
|
|
@@ -436,12 +388,7 @@ export let rec setInt8 = (index: Number, value: Int32, bytes: Bytes) => {
|
|
|
436
388
|
let offset = coerceNumberToWasmI32(index)
|
|
437
389
|
checkIndexIsInBounds(offset, _INT8_BYTE_SIZE, size)
|
|
438
390
|
let v = Conv.fromInt32(value)
|
|
439
|
-
|
|
440
|
-
Memory.decRef(WasmI32.fromGrain(index))
|
|
441
|
-
Memory.decRef(WasmI32.fromGrain(value))
|
|
442
|
-
Memory.decRef(WasmI32.fromGrain(bytes))
|
|
443
|
-
Memory.decRef(WasmI32.fromGrain(setInt8))
|
|
444
|
-
ret
|
|
391
|
+
WasmI32.store8(ptr + offset, v, _VALUE_OFFSET)
|
|
445
392
|
}
|
|
446
393
|
|
|
447
394
|
/**
|
|
@@ -453,19 +400,15 @@ export let rec setInt8 = (index: Number, value: Int32, bytes: Bytes) => {
|
|
|
453
400
|
*
|
|
454
401
|
* @since v0.3.2
|
|
455
402
|
*/
|
|
456
|
-
@
|
|
457
|
-
export let
|
|
403
|
+
@unsafe
|
|
404
|
+
export let getInt16S = (index: Number, bytes: Bytes) => {
|
|
458
405
|
let (+) = WasmI32.add
|
|
459
406
|
let ptr = WasmI32.fromGrain(bytes)
|
|
460
407
|
let size = getSize(ptr)
|
|
461
408
|
let offset = coerceNumberToWasmI32(index)
|
|
462
409
|
checkIndexIsInBounds(offset, _INT16_BYTE_SIZE, size)
|
|
463
410
|
let n = WasmI32.load16S(ptr + offset, _VALUE_OFFSET)
|
|
464
|
-
|
|
465
|
-
Memory.decRef(WasmI32.fromGrain(index))
|
|
466
|
-
Memory.decRef(WasmI32.fromGrain(bytes))
|
|
467
|
-
Memory.decRef(WasmI32.fromGrain(getInt16S))
|
|
468
|
-
ret
|
|
411
|
+
Conv.toInt32(n)
|
|
469
412
|
}
|
|
470
413
|
|
|
471
414
|
/**
|
|
@@ -477,19 +420,15 @@ export let rec getInt16S = (index: Number, bytes: Bytes) => {
|
|
|
477
420
|
*
|
|
478
421
|
* @since v0.3.2
|
|
479
422
|
*/
|
|
480
|
-
@
|
|
481
|
-
export let
|
|
423
|
+
@unsafe
|
|
424
|
+
export let getInt16U = (index: Number, bytes: Bytes) => {
|
|
482
425
|
let (+) = WasmI32.add
|
|
483
426
|
let ptr = WasmI32.fromGrain(bytes)
|
|
484
427
|
let size = getSize(ptr)
|
|
485
428
|
let offset = coerceNumberToWasmI32(index)
|
|
486
429
|
checkIndexIsInBounds(offset, _INT16_BYTE_SIZE, size)
|
|
487
430
|
let n = WasmI32.load16U(ptr + offset, _VALUE_OFFSET)
|
|
488
|
-
|
|
489
|
-
Memory.decRef(WasmI32.fromGrain(index))
|
|
490
|
-
Memory.decRef(WasmI32.fromGrain(bytes))
|
|
491
|
-
Memory.decRef(WasmI32.fromGrain(getInt16U))
|
|
492
|
-
ret
|
|
431
|
+
Conv.toInt32(n)
|
|
493
432
|
}
|
|
494
433
|
|
|
495
434
|
/**
|
|
@@ -501,20 +440,15 @@ export let rec getInt16U = (index: Number, bytes: Bytes) => {
|
|
|
501
440
|
*
|
|
502
441
|
* @since v0.3.2
|
|
503
442
|
*/
|
|
504
|
-
@
|
|
505
|
-
export let
|
|
443
|
+
@unsafe
|
|
444
|
+
export let setInt16 = (index: Number, value: Int32, bytes: Bytes) => {
|
|
506
445
|
let (+) = WasmI32.add
|
|
507
446
|
let ptr = WasmI32.fromGrain(bytes)
|
|
508
447
|
let size = getSize(ptr)
|
|
509
448
|
let offset = coerceNumberToWasmI32(index)
|
|
510
449
|
checkIndexIsInBounds(offset, _INT16_BYTE_SIZE, size)
|
|
511
450
|
let v = Conv.fromInt32(value)
|
|
512
|
-
|
|
513
|
-
Memory.decRef(WasmI32.fromGrain(index))
|
|
514
|
-
Memory.decRef(WasmI32.fromGrain(value))
|
|
515
|
-
Memory.decRef(WasmI32.fromGrain(bytes))
|
|
516
|
-
Memory.decRef(WasmI32.fromGrain(setInt16))
|
|
517
|
-
ret
|
|
451
|
+
WasmI32.store16(ptr + offset, v, _VALUE_OFFSET)
|
|
518
452
|
}
|
|
519
453
|
|
|
520
454
|
/**
|
|
@@ -526,19 +460,15 @@ export let rec setInt16 = (index: Number, value: Int32, bytes: Bytes) => {
|
|
|
526
460
|
*
|
|
527
461
|
* @since v0.3.2
|
|
528
462
|
*/
|
|
529
|
-
@
|
|
530
|
-
export let
|
|
463
|
+
@unsafe
|
|
464
|
+
export let getInt32 = (index: Number, bytes: Bytes) => {
|
|
531
465
|
let (+) = WasmI32.add
|
|
532
466
|
let ptr = WasmI32.fromGrain(bytes)
|
|
533
467
|
let size = getSize(ptr)
|
|
534
468
|
let offset = coerceNumberToWasmI32(index)
|
|
535
469
|
checkIndexIsInBounds(offset, _INT32_BYTE_SIZE, size)
|
|
536
470
|
let n = WasmI32.load(ptr + offset, _VALUE_OFFSET)
|
|
537
|
-
|
|
538
|
-
Memory.decRef(WasmI32.fromGrain(index))
|
|
539
|
-
Memory.decRef(WasmI32.fromGrain(bytes))
|
|
540
|
-
Memory.decRef(WasmI32.fromGrain(getInt32))
|
|
541
|
-
ret
|
|
471
|
+
Conv.toInt32(n)
|
|
542
472
|
}
|
|
543
473
|
|
|
544
474
|
/**
|
|
@@ -550,20 +480,15 @@ export let rec getInt32 = (index: Number, bytes: Bytes) => {
|
|
|
550
480
|
*
|
|
551
481
|
* @since v0.3.2
|
|
552
482
|
*/
|
|
553
|
-
@
|
|
554
|
-
export let
|
|
483
|
+
@unsafe
|
|
484
|
+
export let setInt32 = (index: Number, value: Int32, bytes: Bytes) => {
|
|
555
485
|
let (+) = WasmI32.add
|
|
556
486
|
let ptr = WasmI32.fromGrain(bytes)
|
|
557
487
|
let size = getSize(ptr)
|
|
558
488
|
let offset = coerceNumberToWasmI32(index)
|
|
559
489
|
checkIndexIsInBounds(offset, _INT32_BYTE_SIZE, size)
|
|
560
490
|
let v = Conv.fromInt32(value)
|
|
561
|
-
|
|
562
|
-
Memory.decRef(WasmI32.fromGrain(index))
|
|
563
|
-
Memory.decRef(WasmI32.fromGrain(value))
|
|
564
|
-
Memory.decRef(WasmI32.fromGrain(bytes))
|
|
565
|
-
Memory.decRef(WasmI32.fromGrain(setInt32))
|
|
566
|
-
ret
|
|
491
|
+
WasmI32.store(ptr + offset, v, _VALUE_OFFSET)
|
|
567
492
|
}
|
|
568
493
|
|
|
569
494
|
/**
|
|
@@ -575,19 +500,15 @@ export let rec setInt32 = (index: Number, value: Int32, bytes: Bytes) => {
|
|
|
575
500
|
*
|
|
576
501
|
* @since v0.3.2
|
|
577
502
|
*/
|
|
578
|
-
@
|
|
579
|
-
export let
|
|
503
|
+
@unsafe
|
|
504
|
+
export let getFloat32 = (index: Number, bytes: Bytes) => {
|
|
580
505
|
let (+) = WasmI32.add
|
|
581
506
|
let ptr = WasmI32.fromGrain(bytes)
|
|
582
507
|
let size = getSize(ptr)
|
|
583
508
|
let offset = coerceNumberToWasmI32(index)
|
|
584
509
|
checkIndexIsInBounds(offset, _INT32_BYTE_SIZE, size)
|
|
585
510
|
let n = WasmF32.load(ptr + offset, _VALUE_OFFSET)
|
|
586
|
-
|
|
587
|
-
Memory.decRef(WasmI32.fromGrain(index))
|
|
588
|
-
Memory.decRef(WasmI32.fromGrain(bytes))
|
|
589
|
-
Memory.decRef(WasmI32.fromGrain(getFloat32))
|
|
590
|
-
ret
|
|
511
|
+
Conv.toFloat32(n)
|
|
591
512
|
}
|
|
592
513
|
|
|
593
514
|
/**
|
|
@@ -599,20 +520,15 @@ export let rec getFloat32 = (index: Number, bytes: Bytes) => {
|
|
|
599
520
|
*
|
|
600
521
|
* @since v0.3.2
|
|
601
522
|
*/
|
|
602
|
-
@
|
|
603
|
-
export let
|
|
523
|
+
@unsafe
|
|
524
|
+
export let setFloat32 = (index: Number, value: Float32, bytes: Bytes) => {
|
|
604
525
|
let (+) = WasmI32.add
|
|
605
526
|
let ptr = WasmI32.fromGrain(bytes)
|
|
606
527
|
let size = getSize(ptr)
|
|
607
528
|
let offset = coerceNumberToWasmI32(index)
|
|
608
529
|
checkIndexIsInBounds(offset, _INT32_BYTE_SIZE, size)
|
|
609
530
|
let v = Conv.fromFloat32(value)
|
|
610
|
-
|
|
611
|
-
Memory.decRef(WasmI32.fromGrain(index))
|
|
612
|
-
Memory.decRef(WasmI32.fromGrain(value))
|
|
613
|
-
Memory.decRef(WasmI32.fromGrain(bytes))
|
|
614
|
-
Memory.decRef(WasmI32.fromGrain(setFloat32))
|
|
615
|
-
ret
|
|
531
|
+
WasmF32.store(ptr + offset, v, _VALUE_OFFSET)
|
|
616
532
|
}
|
|
617
533
|
|
|
618
534
|
/**
|
|
@@ -624,19 +540,15 @@ export let rec setFloat32 = (index: Number, value: Float32, bytes: Bytes) => {
|
|
|
624
540
|
*
|
|
625
541
|
* @since v0.3.2
|
|
626
542
|
*/
|
|
627
|
-
@
|
|
628
|
-
export let
|
|
543
|
+
@unsafe
|
|
544
|
+
export let getInt64 = (index: Number, bytes: Bytes) => {
|
|
629
545
|
let (+) = WasmI32.add
|
|
630
546
|
let ptr = WasmI32.fromGrain(bytes)
|
|
631
547
|
let size = getSize(ptr)
|
|
632
548
|
let offset = coerceNumberToWasmI32(index)
|
|
633
549
|
checkIndexIsInBounds(offset, _INT64_BYTE_SIZE, size)
|
|
634
550
|
let n = WasmI64.load(ptr + offset, _VALUE_OFFSET)
|
|
635
|
-
|
|
636
|
-
Memory.decRef(WasmI32.fromGrain(index))
|
|
637
|
-
Memory.decRef(WasmI32.fromGrain(bytes))
|
|
638
|
-
Memory.decRef(WasmI32.fromGrain(getInt64))
|
|
639
|
-
ret
|
|
551
|
+
Conv.toInt64(n)
|
|
640
552
|
}
|
|
641
553
|
|
|
642
554
|
/**
|
|
@@ -648,20 +560,15 @@ export let rec getInt64 = (index: Number, bytes: Bytes) => {
|
|
|
648
560
|
*
|
|
649
561
|
* @since v0.3.2
|
|
650
562
|
*/
|
|
651
|
-
@
|
|
652
|
-
export let
|
|
563
|
+
@unsafe
|
|
564
|
+
export let setInt64 = (index: Number, value: Int64, bytes: Bytes) => {
|
|
653
565
|
let (+) = WasmI32.add
|
|
654
566
|
let ptr = WasmI32.fromGrain(bytes)
|
|
655
567
|
let size = getSize(ptr)
|
|
656
568
|
let offset = coerceNumberToWasmI32(index)
|
|
657
569
|
checkIndexIsInBounds(offset, _INT64_BYTE_SIZE, size)
|
|
658
570
|
let v = Conv.fromInt64(value)
|
|
659
|
-
|
|
660
|
-
Memory.decRef(WasmI32.fromGrain(index))
|
|
661
|
-
Memory.decRef(WasmI32.fromGrain(value))
|
|
662
|
-
Memory.decRef(WasmI32.fromGrain(bytes))
|
|
663
|
-
Memory.decRef(WasmI32.fromGrain(setInt64))
|
|
664
|
-
ret
|
|
571
|
+
WasmI64.store(ptr + offset, v, _VALUE_OFFSET)
|
|
665
572
|
}
|
|
666
573
|
|
|
667
574
|
/**
|
|
@@ -673,19 +580,15 @@ export let rec setInt64 = (index: Number, value: Int64, bytes: Bytes) => {
|
|
|
673
580
|
*
|
|
674
581
|
* @since v0.3.2
|
|
675
582
|
*/
|
|
676
|
-
@
|
|
677
|
-
export let
|
|
583
|
+
@unsafe
|
|
584
|
+
export let getFloat64 = (index: Number, bytes: Bytes) => {
|
|
678
585
|
let (+) = WasmI32.add
|
|
679
586
|
let ptr = WasmI32.fromGrain(bytes)
|
|
680
587
|
let size = getSize(ptr)
|
|
681
588
|
let offset = coerceNumberToWasmI32(index)
|
|
682
589
|
checkIndexIsInBounds(offset, _FLOAT64_BYTE_SIZE, size)
|
|
683
590
|
let n = WasmF64.load(ptr + offset, _VALUE_OFFSET)
|
|
684
|
-
|
|
685
|
-
Memory.decRef(WasmI32.fromGrain(index))
|
|
686
|
-
Memory.decRef(WasmI32.fromGrain(bytes))
|
|
687
|
-
Memory.decRef(WasmI32.fromGrain(getFloat64))
|
|
688
|
-
ret
|
|
591
|
+
Conv.toFloat64(n)
|
|
689
592
|
}
|
|
690
593
|
|
|
691
594
|
/**
|
|
@@ -697,7 +600,7 @@ export let rec getFloat64 = (index: Number, bytes: Bytes) => {
|
|
|
697
600
|
*
|
|
698
601
|
* @since v0.3.2
|
|
699
602
|
*/
|
|
700
|
-
@
|
|
603
|
+
@unsafe
|
|
701
604
|
export let rec setFloat64 = (index: Number, value: Float64, bytes: Bytes) => {
|
|
702
605
|
let (+) = WasmI32.add
|
|
703
606
|
let ptr = WasmI32.fromGrain(bytes)
|
|
@@ -705,10 +608,5 @@ export let rec setFloat64 = (index: Number, value: Float64, bytes: Bytes) => {
|
|
|
705
608
|
let offset = coerceNumberToWasmI32(index)
|
|
706
609
|
checkIndexIsInBounds(offset, _FLOAT64_BYTE_SIZE, size)
|
|
707
610
|
let v = Conv.fromFloat64(value)
|
|
708
|
-
|
|
709
|
-
Memory.decRef(WasmI32.fromGrain(index))
|
|
710
|
-
Memory.decRef(WasmI32.fromGrain(value))
|
|
711
|
-
Memory.decRef(WasmI32.fromGrain(bytes))
|
|
712
|
-
Memory.decRef(WasmI32.fromGrain(setFloat64))
|
|
713
|
-
ret
|
|
611
|
+
WasmF64.store(ptr + offset, v, _VALUE_OFFSET)
|
|
714
612
|
}
|
package/bytes.md
CHANGED
|
@@ -281,6 +281,25 @@ Parameters:
|
|
|
281
281
|
|`value`|`Int32`|The value replacing each byte|
|
|
282
282
|
|`bytes`|`Bytes`|The byte sequence to update|
|
|
283
283
|
|
|
284
|
+
### Bytes.**clear**
|
|
285
|
+
|
|
286
|
+
<details disabled>
|
|
287
|
+
<summary tabindex="-1">Added in <code>next</code></summary>
|
|
288
|
+
No other changes yet.
|
|
289
|
+
</details>
|
|
290
|
+
|
|
291
|
+
```grain
|
|
292
|
+
clear : Bytes -> Void
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Replaces all bytes in a byte sequence with zeroes.
|
|
296
|
+
|
|
297
|
+
Parameters:
|
|
298
|
+
|
|
299
|
+
|param|type|description|
|
|
300
|
+
|-----|----|-----------|
|
|
301
|
+
|`bytes`|`Bytes`|The byte sequence to clear|
|
|
302
|
+
|
|
284
303
|
## Binary operations on integers
|
|
285
304
|
|
|
286
305
|
Functions for encoding and decoding integers stored in a byte sequence.
|