@grain/stdlib 0.4.6 → 0.5.2
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 +93 -0
- package/array.gr +18 -18
- package/array.md +18 -18
- package/bigint.gr +497 -0
- package/bigint.md +811 -0
- package/buffer.gr +59 -223
- package/buffer.md +24 -17
- package/bytes.gr +100 -202
- package/bytes.md +19 -0
- package/char.gr +63 -133
- package/exception.gr +28 -2
- package/exception.md +43 -0
- package/float32.gr +76 -95
- package/float32.md +69 -30
- package/float64.gr +81 -95
- package/float64.md +69 -30
- package/hash.gr +37 -37
- package/int32.gr +152 -198
- package/int32.md +104 -0
- package/int64.gr +151 -197
- package/int64.md +104 -0
- package/list.gr +467 -70
- package/list.md +1141 -0
- package/map.gr +192 -7
- package/map.md +525 -0
- package/number.gr +111 -54
- package/number.md +100 -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 +91 -41
- package/runtime/numberUtils.md +54 -0
- package/runtime/numbers.gr +1049 -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 +194 -329
- package/string.md +3 -3
- package/sys/file.gr +245 -429
- 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/buffer.gr
CHANGED
|
@@ -14,6 +14,7 @@ import Exception from "runtime/exception"
|
|
|
14
14
|
import Int32 from "int32"
|
|
15
15
|
import Bytes from "bytes"
|
|
16
16
|
import String from "string"
|
|
17
|
+
import Char from "char"
|
|
17
18
|
import { coerceNumberToWasmI32 } from "runtime/numbers"
|
|
18
19
|
|
|
19
20
|
record Buffer {
|
|
@@ -22,18 +23,11 @@ record Buffer {
|
|
|
22
23
|
mut data: Bytes,
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
@
|
|
26
|
-
let mut _SIZE_OFFSET =
|
|
26
|
+
@unsafe
|
|
27
|
+
let mut _SIZE_OFFSET = 4n
|
|
27
28
|
|
|
28
|
-
@
|
|
29
|
-
let mut _VALUE_OFFSET =
|
|
30
|
-
|
|
31
|
-
@disableGC
|
|
32
|
-
let initOffsets = () => {
|
|
33
|
-
_SIZE_OFFSET = 4n
|
|
34
|
-
_VALUE_OFFSET = 8n
|
|
35
|
-
}
|
|
36
|
-
initOffsets()
|
|
29
|
+
@unsafe
|
|
30
|
+
let mut _VALUE_OFFSET = 8n
|
|
37
31
|
|
|
38
32
|
let _8BIT_LEN = 1
|
|
39
33
|
|
|
@@ -44,45 +38,34 @@ let _32BIT_LEN = 4
|
|
|
44
38
|
let _64BIT_LEN = 8
|
|
45
39
|
|
|
46
40
|
/* Gets the size of a Bytes via its ptr */
|
|
47
|
-
@
|
|
41
|
+
@unsafe
|
|
48
42
|
let getSize = ptr => WasmI32.load(ptr, _SIZE_OFFSET)
|
|
49
43
|
|
|
50
44
|
/* Doubles the size of buffer's underlying byte sequence, if the given size is larger than the size of a buffer's underlying byte sequence */
|
|
51
45
|
let autogrow = (len, buf) => {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (n == 0) n = 4
|
|
55
|
-
// Make sure bytes of 0 length grow too
|
|
56
|
-
buf.data = Bytes.resize(0, n, buf.data)
|
|
57
|
-
}
|
|
58
|
-
}
|
|
46
|
+
let requiredMinimumSize = buf.len + len
|
|
47
|
+
let currentSize = Bytes.length(buf.data)
|
|
59
48
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
49
|
+
if (requiredMinimumSize > currentSize) {
|
|
50
|
+
let mut newSize = if (currentSize > 0) {
|
|
51
|
+
currentSize
|
|
52
|
+
} else {
|
|
53
|
+
// Make sure bytes of 0 length grow too
|
|
54
|
+
4
|
|
55
|
+
}
|
|
66
56
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
1n
|
|
75
|
-
} else if ((byte & 0xF0n) == 0xF0n) {
|
|
76
|
-
4n
|
|
77
|
-
} else if ((byte & 0xE0n) == 0xE0n) {
|
|
78
|
-
3n
|
|
79
|
-
} else {
|
|
80
|
-
2n
|
|
57
|
+
while (newSize < requiredMinimumSize) {
|
|
58
|
+
newSize *= 2
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let growBy = newSize - currentSize
|
|
62
|
+
|
|
63
|
+
buf.data = Bytes.resize(0, growBy, buf.data)
|
|
81
64
|
}
|
|
82
65
|
}
|
|
83
66
|
|
|
84
67
|
/* Memcopies bytes from a source byte sequence to a destination byte sequence via pointers */
|
|
85
|
-
@
|
|
68
|
+
@unsafe
|
|
86
69
|
let rec appendBytes = (srcOff, dstOff, len, src, dst) => {
|
|
87
70
|
let (+) = WasmI32.add
|
|
88
71
|
Memory.copy(dst + _VALUE_OFFSET + dstOff, src + _VALUE_OFFSET + srcOff, len)
|
|
@@ -100,21 +83,21 @@ let checkIsIndexInBounds = (i, len, buf) => {
|
|
|
100
83
|
let addInt8help = (value, buffer) => {
|
|
101
84
|
autogrow(_8BIT_LEN, buffer)
|
|
102
85
|
let index = buffer.len
|
|
103
|
-
buffer.len
|
|
86
|
+
buffer.len += _8BIT_LEN
|
|
104
87
|
Bytes.setInt8(index, value, buffer.data)
|
|
105
88
|
}
|
|
106
89
|
|
|
107
90
|
let addInt16help = (value, buffer) => {
|
|
108
91
|
autogrow(_16BIT_LEN, buffer)
|
|
109
92
|
let index = buffer.len
|
|
110
|
-
buffer.len
|
|
93
|
+
buffer.len += _16BIT_LEN
|
|
111
94
|
Bytes.setInt16(index, value, buffer.data)
|
|
112
95
|
}
|
|
113
96
|
|
|
114
97
|
let addInt32help = (value, buffer) => {
|
|
115
98
|
autogrow(_32BIT_LEN, buffer)
|
|
116
99
|
let index = buffer.len
|
|
117
|
-
buffer.len
|
|
100
|
+
buffer.len += _32BIT_LEN
|
|
118
101
|
Bytes.setInt32(index, value, buffer.data)
|
|
119
102
|
}
|
|
120
103
|
|
|
@@ -159,7 +142,7 @@ export let length = buffer => buffer.len
|
|
|
159
142
|
* @since v0.4.0
|
|
160
143
|
*/
|
|
161
144
|
export let clear = buffer => {
|
|
162
|
-
Bytes.
|
|
145
|
+
Bytes.clear(buffer.data)
|
|
163
146
|
buffer.len = 0
|
|
164
147
|
}
|
|
165
148
|
|
|
@@ -187,10 +170,8 @@ export let reset = buffer => {
|
|
|
187
170
|
*
|
|
188
171
|
* @since v0.4.0
|
|
189
172
|
*/
|
|
190
|
-
@
|
|
191
|
-
export let
|
|
192
|
-
Memory.incRef(WasmI32.fromGrain((<)))
|
|
193
|
-
Memory.incRef(WasmI32.fromGrain((>)))
|
|
173
|
+
@unsafe
|
|
174
|
+
export let truncate = (length, buffer) => {
|
|
194
175
|
if (length < 0 || length > buffer.len) throw Exception.IndexOutOfBounds
|
|
195
176
|
|
|
196
177
|
let (+) = WasmI32.add
|
|
@@ -199,11 +180,6 @@ export let rec truncate = (length, buffer) => {
|
|
|
199
180
|
let off = coerceNumberToWasmI32(length)
|
|
200
181
|
let ret = Memory.fill(src + _VALUE_OFFSET + off, 0n, size)
|
|
201
182
|
buffer.len = length
|
|
202
|
-
|
|
203
|
-
Memory.decRef(WasmI32.fromGrain(length))
|
|
204
|
-
Memory.decRef(WasmI32.fromGrain(buffer))
|
|
205
|
-
Memory.decRef(WasmI32.fromGrain(truncate))
|
|
206
|
-
void
|
|
207
183
|
}
|
|
208
184
|
|
|
209
185
|
/**
|
|
@@ -215,12 +191,7 @@ export let rec truncate = (length, buffer) => {
|
|
|
215
191
|
* @since v0.4.0
|
|
216
192
|
*/
|
|
217
193
|
export let toBytes = buffer => {
|
|
218
|
-
|
|
219
|
-
if (buffer.len == len) {
|
|
220
|
-
buffer.data
|
|
221
|
-
} else {
|
|
222
|
-
Bytes.slice(0, buffer.len, buffer.data)
|
|
223
|
-
}
|
|
194
|
+
Bytes.slice(0, buffer.len, buffer.data)
|
|
224
195
|
}
|
|
225
196
|
|
|
226
197
|
/**
|
|
@@ -264,70 +235,6 @@ export let toStringSlice = (start, length, buffer) => {
|
|
|
264
235
|
Bytes.toString(toBytesSlice(start, length, buffer))
|
|
265
236
|
}
|
|
266
237
|
|
|
267
|
-
/**
|
|
268
|
-
* Appends the bytes of a char to a buffer.
|
|
269
|
-
*
|
|
270
|
-
* @param char: The character to append to the buffer
|
|
271
|
-
* @param buffer: The buffer to mutate
|
|
272
|
-
*
|
|
273
|
-
* @since v0.4.0
|
|
274
|
-
*/
|
|
275
|
-
@disableGC
|
|
276
|
-
export let rec addChar = (char: Char, buffer: Buffer) => {
|
|
277
|
-
let n = getCharAsWasmI32(char)
|
|
278
|
-
let bytelen = getCharByteLength(n)
|
|
279
|
-
match (bytelen) {
|
|
280
|
-
1n => {
|
|
281
|
-
let c = Conv.toInt32(n)
|
|
282
|
-
Memory.incRef(WasmI32.fromGrain(addInt8help))
|
|
283
|
-
Memory.incRef(WasmI32.fromGrain(c))
|
|
284
|
-
Memory.incRef(WasmI32.fromGrain(buffer))
|
|
285
|
-
addInt8help(c, buffer)
|
|
286
|
-
Memory.decRef(WasmI32.fromGrain(c))
|
|
287
|
-
void
|
|
288
|
-
},
|
|
289
|
-
2n => {
|
|
290
|
-
let c = Conv.toInt32(n)
|
|
291
|
-
Memory.incRef(WasmI32.fromGrain(addInt16help))
|
|
292
|
-
Memory.incRef(WasmI32.fromGrain(c))
|
|
293
|
-
Memory.incRef(WasmI32.fromGrain(buffer))
|
|
294
|
-
addInt16help(c, buffer)
|
|
295
|
-
Memory.decRef(WasmI32.fromGrain(c))
|
|
296
|
-
void
|
|
297
|
-
},
|
|
298
|
-
3n => {
|
|
299
|
-
let (<) = WasmI32.ltU
|
|
300
|
-
let (+) = WasmI32.add
|
|
301
|
-
let (*) = WasmI32.mul
|
|
302
|
-
let (&) = WasmI32.and
|
|
303
|
-
let (>>) = WasmI32.shrU
|
|
304
|
-
for (let mut i = 0n; i < 3n; i += 1n) {
|
|
305
|
-
let c = Conv.toInt32(n >> i * 8n & 0xffn)
|
|
306
|
-
Memory.incRef(WasmI32.fromGrain(addInt8help))
|
|
307
|
-
Memory.incRef(WasmI32.fromGrain(c))
|
|
308
|
-
Memory.incRef(WasmI32.fromGrain(buffer))
|
|
309
|
-
addInt8help(c, buffer)
|
|
310
|
-
Memory.decRef(WasmI32.fromGrain(c))
|
|
311
|
-
void
|
|
312
|
-
}
|
|
313
|
-
},
|
|
314
|
-
_ => {
|
|
315
|
-
let c = Conv.toInt32(n)
|
|
316
|
-
Memory.incRef(WasmI32.fromGrain(addInt32help))
|
|
317
|
-
Memory.incRef(WasmI32.fromGrain(c))
|
|
318
|
-
Memory.incRef(WasmI32.fromGrain(buffer))
|
|
319
|
-
addInt32help(c, buffer)
|
|
320
|
-
Memory.decRef(WasmI32.fromGrain(c))
|
|
321
|
-
void
|
|
322
|
-
},
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
Memory.decRef(WasmI32.fromGrain(char))
|
|
326
|
-
Memory.decRef(WasmI32.fromGrain(buffer))
|
|
327
|
-
Memory.decRef(WasmI32.fromGrain(addChar))
|
|
328
|
-
void
|
|
329
|
-
}
|
|
330
|
-
|
|
331
238
|
/**
|
|
332
239
|
* Appends a byte sequence to a buffer.
|
|
333
240
|
*
|
|
@@ -336,15 +243,10 @@ export let rec addChar = (char: Char, buffer: Buffer) => {
|
|
|
336
243
|
*
|
|
337
244
|
* @since v0.4.0
|
|
338
245
|
*/
|
|
339
|
-
@
|
|
340
|
-
export let
|
|
341
|
-
Memory.incRef(WasmI32.fromGrain(Bytes.length))
|
|
342
|
-
Memory.incRef(WasmI32.fromGrain(bytes))
|
|
246
|
+
@unsafe
|
|
247
|
+
export let addBytes = (bytes, buffer) => {
|
|
343
248
|
let bytelen = Bytes.length(bytes)
|
|
344
249
|
|
|
345
|
-
Memory.incRef(WasmI32.fromGrain(autogrow))
|
|
346
|
-
Memory.incRef(WasmI32.fromGrain(bytelen))
|
|
347
|
-
Memory.incRef(WasmI32.fromGrain(buffer))
|
|
348
250
|
autogrow(bytelen, buffer)
|
|
349
251
|
|
|
350
252
|
let off = coerceNumberToWasmI32(buffer.len)
|
|
@@ -353,15 +255,7 @@ export let rec addBytes = (bytes, buffer) => {
|
|
|
353
255
|
let dst = WasmI32.fromGrain(buffer.data)
|
|
354
256
|
appendBytes(0n, off, len, src, dst)
|
|
355
257
|
|
|
356
|
-
|
|
357
|
-
Memory.incRef(WasmI32.fromGrain(buffer.len))
|
|
358
|
-
Memory.incRef(WasmI32.fromGrain(bytelen))
|
|
359
|
-
buffer.len = buffer.len + bytelen
|
|
360
|
-
|
|
361
|
-
Memory.decRef(WasmI32.fromGrain(bytes))
|
|
362
|
-
Memory.decRef(WasmI32.fromGrain(buffer))
|
|
363
|
-
Memory.decRef(WasmI32.fromGrain(addBytes))
|
|
364
|
-
void
|
|
258
|
+
buffer.len += bytelen
|
|
365
259
|
}
|
|
366
260
|
|
|
367
261
|
/**
|
|
@@ -372,15 +266,10 @@ export let rec addBytes = (bytes, buffer) => {
|
|
|
372
266
|
*
|
|
373
267
|
* @since v0.4.0
|
|
374
268
|
*/
|
|
375
|
-
@
|
|
376
|
-
export let
|
|
377
|
-
Memory.incRef(WasmI32.fromGrain(String.byteLength))
|
|
378
|
-
Memory.incRef(WasmI32.fromGrain(string))
|
|
269
|
+
@unsafe
|
|
270
|
+
export let addString = (string, buffer) => {
|
|
379
271
|
let bytelen = String.byteLength(string)
|
|
380
272
|
|
|
381
|
-
Memory.incRef(WasmI32.fromGrain(autogrow))
|
|
382
|
-
Memory.incRef(WasmI32.fromGrain(bytelen))
|
|
383
|
-
Memory.incRef(WasmI32.fromGrain(buffer))
|
|
384
273
|
autogrow(bytelen, buffer)
|
|
385
274
|
|
|
386
275
|
let off = coerceNumberToWasmI32(buffer.len)
|
|
@@ -389,66 +278,38 @@ export let rec addString = (string, buffer) => {
|
|
|
389
278
|
let dst = WasmI32.fromGrain(buffer.data)
|
|
390
279
|
appendBytes(0n, off, len, src, dst)
|
|
391
280
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
Memory.incRef(WasmI32.fromGrain(bytelen))
|
|
395
|
-
buffer.len = buffer.len + bytelen
|
|
281
|
+
buffer.len += bytelen
|
|
282
|
+
}
|
|
396
283
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
284
|
+
/**
|
|
285
|
+
* Appends the bytes of a char to a buffer.
|
|
286
|
+
*
|
|
287
|
+
* @param char: The character to append to the buffer
|
|
288
|
+
* @param buffer: The buffer to mutate
|
|
289
|
+
*
|
|
290
|
+
* @since v0.4.0
|
|
291
|
+
*/
|
|
292
|
+
export let addChar = (char, buffer) => {
|
|
293
|
+
addString(Char.toString(char), buffer)
|
|
401
294
|
}
|
|
402
295
|
|
|
403
296
|
/**
|
|
404
297
|
* Appends the bytes of a subset of a string to a buffer.
|
|
405
298
|
*
|
|
406
299
|
* @param start: The char offset into the string
|
|
407
|
-
* @param
|
|
300
|
+
* @param end: The end offset into the string
|
|
408
301
|
* @param string: The string to append
|
|
409
302
|
* @param buffer: The buffer to mutate
|
|
410
303
|
*
|
|
411
304
|
* @since v0.4.0
|
|
305
|
+
* @history v0.5.0: Now takes the end offset instead of length
|
|
412
306
|
*/
|
|
413
|
-
@
|
|
414
|
-
export let
|
|
415
|
-
// Handle negative start index (needed before #1071 is fixed)
|
|
416
|
-
let start = {
|
|
417
|
-
// this is a block to avoid making all of these operators
|
|
418
|
-
// overriden in the whole function
|
|
419
|
-
let (<<) = WasmI32.shl
|
|
420
|
-
let (>>) = WasmI32.shrS
|
|
421
|
-
let (+) = WasmI32.add
|
|
422
|
-
let (!=) = WasmI32.ne
|
|
423
|
-
let (&) = WasmI32.and
|
|
424
|
-
Memory.incRef(WasmI32.fromGrain(String.length))
|
|
425
|
-
Memory.incRef(WasmI32.fromGrain(string))
|
|
426
|
-
let strlen = WasmI32.fromGrain(String.length(string)) >> 1n
|
|
427
|
-
let mut startW = WasmI32.fromGrain(start)
|
|
428
|
-
if ((startW & 1n) != 1n) {
|
|
429
|
-
throw InvalidArgument("Invalid start index")
|
|
430
|
-
}
|
|
431
|
-
startW = startW >> 1n
|
|
432
|
-
if (WasmI32.ltS(startW, 0n)) {
|
|
433
|
-
WasmI32.toGrain(WasmI32.shl(startW + strlen, 1n) + 1n)
|
|
434
|
-
} else {
|
|
435
|
-
start
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
let end = start + length
|
|
439
|
-
Memory.incRef(WasmI32.fromGrain(String.slice))
|
|
440
|
-
// no incref for start since we know it's a simple num. Add back for good measure after #1071 is fixed!
|
|
441
|
-
Memory.incRef(WasmI32.fromGrain(end))
|
|
442
|
-
Memory.incRef(WasmI32.fromGrain(string))
|
|
307
|
+
@unsafe
|
|
308
|
+
export let addStringSlice = (start: Number, end, string, buffer) => {
|
|
443
309
|
let slice = String.slice(start, end, string)
|
|
444
310
|
|
|
445
|
-
Memory.incRef(WasmI32.fromGrain(String.byteLength))
|
|
446
|
-
Memory.incRef(WasmI32.fromGrain(slice))
|
|
447
311
|
let bytelen = String.byteLength(slice)
|
|
448
312
|
|
|
449
|
-
Memory.incRef(WasmI32.fromGrain(autogrow))
|
|
450
|
-
Memory.incRef(WasmI32.fromGrain(bytelen))
|
|
451
|
-
Memory.incRef(WasmI32.fromGrain(buffer))
|
|
452
313
|
autogrow(bytelen, buffer)
|
|
453
314
|
|
|
454
315
|
let srcOff = 0n
|
|
@@ -456,24 +317,12 @@ export let rec addStringSlice = (start: Number, length, string, buffer) => {
|
|
|
456
317
|
let src = WasmI32.fromGrain(slice)
|
|
457
318
|
let dst = WasmI32.fromGrain(buffer.data)
|
|
458
319
|
appendBytes(srcOff, dstOff, coerceNumberToWasmI32(bytelen), src, dst)
|
|
459
|
-
Memory.decRef(WasmI32.fromGrain(slice))
|
|
460
320
|
|
|
461
|
-
|
|
462
|
-
Memory.incRef(WasmI32.fromGrain(buffer.len))
|
|
463
|
-
Memory.incRef(WasmI32.fromGrain(bytelen))
|
|
464
|
-
buffer.len = buffer.len + bytelen
|
|
465
|
-
Memory.decRef(WasmI32.fromGrain(bytelen))
|
|
466
|
-
|
|
467
|
-
Memory.decRef(WasmI32.fromGrain(start))
|
|
468
|
-
Memory.decRef(WasmI32.fromGrain(length))
|
|
469
|
-
Memory.decRef(WasmI32.fromGrain(string))
|
|
470
|
-
Memory.decRef(WasmI32.fromGrain(buffer))
|
|
471
|
-
Memory.decRef(WasmI32.fromGrain(addStringSlice))
|
|
472
|
-
void
|
|
321
|
+
buffer.len += bytelen
|
|
473
322
|
}
|
|
474
323
|
|
|
475
324
|
/**
|
|
476
|
-
* Appends the bytes of a subset of a byte
|
|
325
|
+
* Appends the bytes of a subset of a byte sequence to a buffer.
|
|
477
326
|
*
|
|
478
327
|
* @param start: The byte offset into the byte sequence
|
|
479
328
|
* @param length: The number of bytes to append
|
|
@@ -482,8 +331,8 @@ export let rec addStringSlice = (start: Number, length, string, buffer) => {
|
|
|
482
331
|
*
|
|
483
332
|
* @since v0.4.0
|
|
484
333
|
*/
|
|
485
|
-
@
|
|
486
|
-
export let
|
|
334
|
+
@unsafe
|
|
335
|
+
export let addBytesSlice =
|
|
487
336
|
(
|
|
488
337
|
start: Number,
|
|
489
338
|
length: Number,
|
|
@@ -508,9 +357,6 @@ export let rec addBytesSlice =
|
|
|
508
357
|
throw Exception.IndexOutOfBounds
|
|
509
358
|
}
|
|
510
359
|
|
|
511
|
-
Memory.incRef(WasmI32.fromGrain(autogrow))
|
|
512
|
-
Memory.incRef(WasmI32.fromGrain(length))
|
|
513
|
-
Memory.incRef(WasmI32.fromGrain(buffer))
|
|
514
360
|
autogrow(length, buffer)
|
|
515
361
|
|
|
516
362
|
let dstOff = coerceNumberToWasmI32(buffer.len)
|
|
@@ -518,17 +364,7 @@ export let rec addBytesSlice =
|
|
|
518
364
|
let dst = WasmI32.fromGrain(buffer.data)
|
|
519
365
|
appendBytes(srcOff, dstOff, len, src, dst)
|
|
520
366
|
|
|
521
|
-
|
|
522
|
-
Memory.incRef(WasmI32.fromGrain(buffer.len))
|
|
523
|
-
Memory.incRef(WasmI32.fromGrain(length))
|
|
524
|
-
buffer.len = buffer.len + length
|
|
525
|
-
|
|
526
|
-
Memory.decRef(WasmI32.fromGrain(start))
|
|
527
|
-
Memory.decRef(WasmI32.fromGrain(length))
|
|
528
|
-
Memory.decRef(WasmI32.fromGrain(bytes))
|
|
529
|
-
Memory.decRef(WasmI32.fromGrain(buffer))
|
|
530
|
-
Memory.decRef(WasmI32.fromGrain(addBytesSlice))
|
|
531
|
-
void
|
|
367
|
+
buffer.len += length
|
|
532
368
|
}
|
|
533
369
|
|
|
534
370
|
/**
|
|
@@ -752,7 +588,7 @@ export let setFloat32 = (index, value, buffer) => {
|
|
|
752
588
|
export let addFloat32 = (value, buffer) => {
|
|
753
589
|
autogrow(_32BIT_LEN, buffer)
|
|
754
590
|
let index = buffer.len
|
|
755
|
-
buffer.len
|
|
591
|
+
buffer.len += _32BIT_LEN
|
|
756
592
|
setFloat32(index, value, buffer)
|
|
757
593
|
}
|
|
758
594
|
|
|
@@ -795,7 +631,7 @@ export let setInt64 = (index, value, buffer) => {
|
|
|
795
631
|
export let addInt64 = (value, buffer) => {
|
|
796
632
|
autogrow(_64BIT_LEN, buffer)
|
|
797
633
|
let index = buffer.len
|
|
798
|
-
buffer.len
|
|
634
|
+
buffer.len += _64BIT_LEN
|
|
799
635
|
setInt64(index, value, buffer)
|
|
800
636
|
}
|
|
801
637
|
|
|
@@ -838,6 +674,6 @@ export let setFloat64 = (index, value, buffer) => {
|
|
|
838
674
|
export let addFloat64 = (value, buffer) => {
|
|
839
675
|
autogrow(_64BIT_LEN, buffer)
|
|
840
676
|
let index = buffer.len
|
|
841
|
-
buffer.len
|
|
677
|
+
buffer.len += _64BIT_LEN
|
|
842
678
|
setFloat64(index, value, buffer)
|
|
843
679
|
}
|
package/buffer.md
CHANGED
|
@@ -240,7 +240,7 @@ Returns:
|
|
|
240
240
|
|----|-----------|
|
|
241
241
|
|`String`|A string made with a subset of data copied from the buffer|
|
|
242
242
|
|
|
243
|
-
### Buffer.**
|
|
243
|
+
### Buffer.**addBytes**
|
|
244
244
|
|
|
245
245
|
<details disabled>
|
|
246
246
|
<summary tabindex="-1">Added in <code>0.4.0</code></summary>
|
|
@@ -248,19 +248,19 @@ No other changes yet.
|
|
|
248
248
|
</details>
|
|
249
249
|
|
|
250
250
|
```grain
|
|
251
|
-
|
|
251
|
+
addBytes : (Bytes, Buffer) -> Void
|
|
252
252
|
```
|
|
253
253
|
|
|
254
|
-
Appends
|
|
254
|
+
Appends a byte sequence to a buffer.
|
|
255
255
|
|
|
256
256
|
Parameters:
|
|
257
257
|
|
|
258
258
|
|param|type|description|
|
|
259
259
|
|-----|----|-----------|
|
|
260
|
-
|`
|
|
260
|
+
|`bytes`|`Bytes`|The byte sequence to append|
|
|
261
261
|
|`buffer`|`Buffer`|The buffer to mutate|
|
|
262
262
|
|
|
263
|
-
### Buffer.**
|
|
263
|
+
### Buffer.**addString**
|
|
264
264
|
|
|
265
265
|
<details disabled>
|
|
266
266
|
<summary tabindex="-1">Added in <code>0.4.0</code></summary>
|
|
@@ -268,19 +268,19 @@ No other changes yet.
|
|
|
268
268
|
</details>
|
|
269
269
|
|
|
270
270
|
```grain
|
|
271
|
-
|
|
271
|
+
addString : (String, Buffer) -> Void
|
|
272
272
|
```
|
|
273
273
|
|
|
274
|
-
Appends a
|
|
274
|
+
Appends the bytes of a string to a buffer.
|
|
275
275
|
|
|
276
276
|
Parameters:
|
|
277
277
|
|
|
278
278
|
|param|type|description|
|
|
279
279
|
|-----|----|-----------|
|
|
280
|
-
|`
|
|
280
|
+
|`string`|`String`|The string to append|
|
|
281
281
|
|`buffer`|`Buffer`|The buffer to mutate|
|
|
282
282
|
|
|
283
|
-
### Buffer.**
|
|
283
|
+
### Buffer.**addChar**
|
|
284
284
|
|
|
285
285
|
<details disabled>
|
|
286
286
|
<summary tabindex="-1">Added in <code>0.4.0</code></summary>
|
|
@@ -288,23 +288,30 @@ No other changes yet.
|
|
|
288
288
|
</details>
|
|
289
289
|
|
|
290
290
|
```grain
|
|
291
|
-
|
|
291
|
+
addChar : (Char, Buffer) -> Void
|
|
292
292
|
```
|
|
293
293
|
|
|
294
|
-
Appends the bytes of a
|
|
294
|
+
Appends the bytes of a char to a buffer.
|
|
295
295
|
|
|
296
296
|
Parameters:
|
|
297
297
|
|
|
298
298
|
|param|type|description|
|
|
299
299
|
|-----|----|-----------|
|
|
300
|
-
|`
|
|
300
|
+
|`char`|`Char`|The character to append to the buffer|
|
|
301
301
|
|`buffer`|`Buffer`|The buffer to mutate|
|
|
302
302
|
|
|
303
303
|
### Buffer.**addStringSlice**
|
|
304
304
|
|
|
305
|
-
<details
|
|
306
|
-
<summary
|
|
307
|
-
|
|
305
|
+
<details>
|
|
306
|
+
<summary>Added in <code>0.4.0</code></summary>
|
|
307
|
+
<table>
|
|
308
|
+
<thead>
|
|
309
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
310
|
+
</thead>
|
|
311
|
+
<tbody>
|
|
312
|
+
<tr><td><code>0.5.0</code></td><td>Now takes the end offset instead of length</td></tr>
|
|
313
|
+
</tbody>
|
|
314
|
+
</table>
|
|
308
315
|
</details>
|
|
309
316
|
|
|
310
317
|
```grain
|
|
@@ -318,7 +325,7 @@ Parameters:
|
|
|
318
325
|
|param|type|description|
|
|
319
326
|
|-----|----|-----------|
|
|
320
327
|
|`start`|`Number`|The char offset into the string|
|
|
321
|
-
|`
|
|
328
|
+
|`end`|`Number`|The end offset into the string|
|
|
322
329
|
|`string`|`String`|The string to append|
|
|
323
330
|
|`buffer`|`Buffer`|The buffer to mutate|
|
|
324
331
|
|
|
@@ -333,7 +340,7 @@ No other changes yet.
|
|
|
333
340
|
addBytesSlice : (Number, Number, Bytes, Buffer) -> Void
|
|
334
341
|
```
|
|
335
342
|
|
|
336
|
-
Appends the bytes of a subset of a byte
|
|
343
|
+
Appends the bytes of a subset of a byte sequence to a buffer.
|
|
337
344
|
|
|
338
345
|
Parameters:
|
|
339
346
|
|