@grain/stdlib 0.4.4 → 0.5.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 +87 -0
- package/LICENSE +1 -1
- package/array.gr +92 -73
- package/array.md +18 -18
- package/bigint.gr +497 -0
- package/bigint.md +811 -0
- package/buffer.gr +56 -217
- package/buffer.md +24 -17
- package/bytes.gr +103 -205
- package/bytes.md +19 -0
- package/char.gr +152 -166
- package/char.md +200 -0
- 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 +53 -49
- package/int32.gr +479 -230
- package/int32.md +937 -0
- package/int64.gr +479 -230
- package/int64.md +937 -0
- package/list.gr +530 -116
- package/list.md +1141 -0
- package/map.gr +302 -121
- package/map.md +525 -0
- package/number.gr +51 -57
- package/number.md +37 -3
- package/option.gr +25 -25
- package/option.md +1 -1
- package/package.json +3 -3
- package/pervasives.gr +504 -52
- package/pervasives.md +1116 -0
- package/queue.gr +8 -1
- package/queue.md +10 -0
- package/random.gr +196 -0
- package/random.md +179 -0
- package/range.gr +26 -26
- 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 -279
- package/runtime/dataStructures.md +391 -0
- package/runtime/debug.gr +0 -1
- package/runtime/debug.md +6 -0
- package/runtime/equal.gr +40 -37
- package/runtime/equal.md +6 -0
- package/runtime/exception.gr +28 -15
- package/runtime/exception.md +30 -0
- package/runtime/gc.gr +50 -20
- package/runtime/gc.md +36 -0
- package/runtime/malloc.gr +32 -22
- package/runtime/malloc.md +55 -0
- package/runtime/numberUtils.gr +297 -142
- package/runtime/numberUtils.md +54 -0
- package/runtime/numbers.gr +1204 -453
- package/runtime/numbers.md +300 -0
- package/runtime/string.gr +193 -228
- package/runtime/string.md +24 -0
- package/runtime/stringUtils.gr +62 -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.gr +10 -10
- package/runtime/unsafe/conv.md +71 -0
- package/runtime/unsafe/errors.md +204 -0
- package/runtime/unsafe/memory.gr +14 -3
- package/runtime/unsafe/memory.md +54 -0
- package/runtime/unsafe/printWasm.gr +4 -4
- package/runtime/unsafe/printWasm.md +24 -0
- package/runtime/unsafe/tags.gr +11 -10
- package/runtime/unsafe/tags.md +120 -0
- package/runtime/unsafe/wasmf32.gr +9 -2
- package/runtime/unsafe/wasmf32.md +168 -0
- package/runtime/unsafe/wasmf64.gr +9 -2
- package/runtime/unsafe/wasmf64.md +168 -0
- package/runtime/unsafe/wasmi32.gr +65 -47
- package/runtime/unsafe/wasmi32.md +282 -0
- package/runtime/unsafe/wasmi64.gr +78 -50
- 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 +200 -46
- package/runtime/wasi.md +839 -0
- package/set.gr +125 -121
- package/set.md +24 -21
- package/stack.gr +29 -29
- package/stack.md +4 -6
- package/string.gr +434 -415
- package/string.md +3 -3
- package/sys/file.gr +477 -482
- package/sys/process.gr +33 -47
- package/sys/random.gr +48 -20
- package/sys/random.md +38 -0
- package/sys/time.gr +12 -28
package/buffer.gr
CHANGED
|
@@ -14,22 +14,20 @@ 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
|
-
record Buffer {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
record Buffer {
|
|
21
|
+
mut len: Number,
|
|
22
|
+
initialSize: Number,
|
|
23
|
+
mut data: Bytes,
|
|
24
|
+
}
|
|
23
25
|
|
|
24
|
-
@
|
|
25
|
-
let mut
|
|
26
|
+
@unsafe
|
|
27
|
+
let mut _SIZE_OFFSET = 4n
|
|
26
28
|
|
|
27
|
-
@
|
|
28
|
-
let
|
|
29
|
-
_SIZE_OFFSET = 4n
|
|
30
|
-
_VALUE_OFFSET = 8n
|
|
31
|
-
}
|
|
32
|
-
initOffsets()
|
|
29
|
+
@unsafe
|
|
30
|
+
let mut _VALUE_OFFSET = 8n
|
|
33
31
|
|
|
34
32
|
let _8BIT_LEN = 1
|
|
35
33
|
|
|
@@ -40,45 +38,34 @@ let _32BIT_LEN = 4
|
|
|
40
38
|
let _64BIT_LEN = 8
|
|
41
39
|
|
|
42
40
|
/* Gets the size of a Bytes via its ptr */
|
|
43
|
-
@
|
|
41
|
+
@unsafe
|
|
44
42
|
let getSize = ptr => WasmI32.load(ptr, _SIZE_OFFSET)
|
|
45
43
|
|
|
46
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 */
|
|
47
45
|
let autogrow = (len, buf) => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (n == 0) n = 4
|
|
51
|
-
// Make sure bytes of 0 length grow too
|
|
52
|
-
buf.data = Bytes.resize(0, n, buf.data)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
46
|
+
let requiredMinimumSize = buf.len + len
|
|
47
|
+
let currentSize = Bytes.length(buf.data)
|
|
55
48
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
+
}
|
|
62
56
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
1n
|
|
71
|
-
} else if ((byte & 0xF0n) == 0xF0n) {
|
|
72
|
-
4n
|
|
73
|
-
} else if ((byte & 0xE0n) == 0xE0n) {
|
|
74
|
-
3n
|
|
75
|
-
} else {
|
|
76
|
-
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)
|
|
77
64
|
}
|
|
78
65
|
}
|
|
79
66
|
|
|
80
67
|
/* Memcopies bytes from a source byte sequence to a destination byte sequence via pointers */
|
|
81
|
-
@
|
|
68
|
+
@unsafe
|
|
82
69
|
let rec appendBytes = (srcOff, dstOff, len, src, dst) => {
|
|
83
70
|
let (+) = WasmI32.add
|
|
84
71
|
Memory.copy(dst + _VALUE_OFFSET + dstOff, src + _VALUE_OFFSET + srcOff, len)
|
|
@@ -130,9 +117,8 @@ let addInt32help = (value, buffer) => {
|
|
|
130
117
|
* @since v0.4.0
|
|
131
118
|
*/
|
|
132
119
|
export let make = initialSize => {
|
|
133
|
-
if (initialSize < 0)
|
|
134
|
-
"Buffers size must be >= 0"
|
|
135
|
-
)
|
|
120
|
+
if (initialSize < 0)
|
|
121
|
+
throw Exception.InvalidArgument("Buffers size must be >= 0")
|
|
136
122
|
{ len: 0, initialSize, data: Bytes.make(initialSize) }
|
|
137
123
|
}
|
|
138
124
|
|
|
@@ -156,7 +142,7 @@ export let length = buffer => buffer.len
|
|
|
156
142
|
* @since v0.4.0
|
|
157
143
|
*/
|
|
158
144
|
export let clear = buffer => {
|
|
159
|
-
Bytes.
|
|
145
|
+
Bytes.clear(buffer.data)
|
|
160
146
|
buffer.len = 0
|
|
161
147
|
}
|
|
162
148
|
|
|
@@ -184,10 +170,8 @@ export let reset = buffer => {
|
|
|
184
170
|
*
|
|
185
171
|
* @since v0.4.0
|
|
186
172
|
*/
|
|
187
|
-
@
|
|
188
|
-
export let
|
|
189
|
-
Memory.incRef(WasmI32.fromGrain((<)))
|
|
190
|
-
Memory.incRef(WasmI32.fromGrain((>)))
|
|
173
|
+
@unsafe
|
|
174
|
+
export let truncate = (length, buffer) => {
|
|
191
175
|
if (length < 0 || length > buffer.len) throw Exception.IndexOutOfBounds
|
|
192
176
|
|
|
193
177
|
let (+) = WasmI32.add
|
|
@@ -196,11 +180,6 @@ export let rec truncate = (length, buffer) => {
|
|
|
196
180
|
let off = coerceNumberToWasmI32(length)
|
|
197
181
|
let ret = Memory.fill(src + _VALUE_OFFSET + off, 0n, size)
|
|
198
182
|
buffer.len = length
|
|
199
|
-
|
|
200
|
-
Memory.decRef(WasmI32.fromGrain(length))
|
|
201
|
-
Memory.decRef(WasmI32.fromGrain(buffer))
|
|
202
|
-
Memory.decRef(WasmI32.fromGrain(truncate))
|
|
203
|
-
void
|
|
204
183
|
}
|
|
205
184
|
|
|
206
185
|
/**
|
|
@@ -212,12 +191,7 @@ export let rec truncate = (length, buffer) => {
|
|
|
212
191
|
* @since v0.4.0
|
|
213
192
|
*/
|
|
214
193
|
export let toBytes = buffer => {
|
|
215
|
-
|
|
216
|
-
if (buffer.len == len) {
|
|
217
|
-
buffer.data
|
|
218
|
-
} else {
|
|
219
|
-
Bytes.slice(0, buffer.len, buffer.data)
|
|
220
|
-
}
|
|
194
|
+
Bytes.slice(0, buffer.len, buffer.data)
|
|
221
195
|
}
|
|
222
196
|
|
|
223
197
|
/**
|
|
@@ -261,70 +235,6 @@ export let toStringSlice = (start, length, buffer) => {
|
|
|
261
235
|
Bytes.toString(toBytesSlice(start, length, buffer))
|
|
262
236
|
}
|
|
263
237
|
|
|
264
|
-
/**
|
|
265
|
-
* Appends the bytes of a char to a buffer.
|
|
266
|
-
*
|
|
267
|
-
* @param char: The character to append to the buffer
|
|
268
|
-
* @param buffer: The buffer to mutate
|
|
269
|
-
*
|
|
270
|
-
* @since v0.4.0
|
|
271
|
-
*/
|
|
272
|
-
@disableGC
|
|
273
|
-
export let rec addChar = (char: Char, buffer: Buffer) => {
|
|
274
|
-
let n = getCharAsWasmI32(char)
|
|
275
|
-
let bytelen = getCharByteLength(n)
|
|
276
|
-
match (bytelen) {
|
|
277
|
-
1n => {
|
|
278
|
-
let c = Conv.toInt32(n)
|
|
279
|
-
Memory.incRef(WasmI32.fromGrain(addInt8help))
|
|
280
|
-
Memory.incRef(WasmI32.fromGrain(c))
|
|
281
|
-
Memory.incRef(WasmI32.fromGrain(buffer))
|
|
282
|
-
addInt8help(c, buffer)
|
|
283
|
-
Memory.decRef(WasmI32.fromGrain(c))
|
|
284
|
-
void
|
|
285
|
-
},
|
|
286
|
-
2n => {
|
|
287
|
-
let c = Conv.toInt32(n)
|
|
288
|
-
Memory.incRef(WasmI32.fromGrain(addInt16help))
|
|
289
|
-
Memory.incRef(WasmI32.fromGrain(c))
|
|
290
|
-
Memory.incRef(WasmI32.fromGrain(buffer))
|
|
291
|
-
addInt16help(c, buffer)
|
|
292
|
-
Memory.decRef(WasmI32.fromGrain(c))
|
|
293
|
-
void
|
|
294
|
-
},
|
|
295
|
-
3n => {
|
|
296
|
-
let (<) = WasmI32.ltU
|
|
297
|
-
let (+) = WasmI32.add
|
|
298
|
-
let (*) = WasmI32.mul
|
|
299
|
-
let (&) = WasmI32.and
|
|
300
|
-
let (>>) = WasmI32.shrU
|
|
301
|
-
for (let mut i = 0n; i < 3n; i += 1n) {
|
|
302
|
-
let c = Conv.toInt32(n >> i * 8n & 0xffn)
|
|
303
|
-
Memory.incRef(WasmI32.fromGrain(addInt8help))
|
|
304
|
-
Memory.incRef(WasmI32.fromGrain(c))
|
|
305
|
-
Memory.incRef(WasmI32.fromGrain(buffer))
|
|
306
|
-
addInt8help(c, buffer)
|
|
307
|
-
Memory.decRef(WasmI32.fromGrain(c))
|
|
308
|
-
void
|
|
309
|
-
}
|
|
310
|
-
},
|
|
311
|
-
_ => {
|
|
312
|
-
let c = Conv.toInt32(n)
|
|
313
|
-
Memory.incRef(WasmI32.fromGrain(addInt32help))
|
|
314
|
-
Memory.incRef(WasmI32.fromGrain(c))
|
|
315
|
-
Memory.incRef(WasmI32.fromGrain(buffer))
|
|
316
|
-
addInt32help(c, buffer)
|
|
317
|
-
Memory.decRef(WasmI32.fromGrain(c))
|
|
318
|
-
void
|
|
319
|
-
},
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
Memory.decRef(WasmI32.fromGrain(char))
|
|
323
|
-
Memory.decRef(WasmI32.fromGrain(buffer))
|
|
324
|
-
Memory.decRef(WasmI32.fromGrain(addChar))
|
|
325
|
-
void
|
|
326
|
-
}
|
|
327
|
-
|
|
328
238
|
/**
|
|
329
239
|
* Appends a byte sequence to a buffer.
|
|
330
240
|
*
|
|
@@ -333,15 +243,10 @@ export let rec addChar = (char: Char, buffer: Buffer) => {
|
|
|
333
243
|
*
|
|
334
244
|
* @since v0.4.0
|
|
335
245
|
*/
|
|
336
|
-
@
|
|
337
|
-
export let
|
|
338
|
-
Memory.incRef(WasmI32.fromGrain(Bytes.length))
|
|
339
|
-
Memory.incRef(WasmI32.fromGrain(bytes))
|
|
246
|
+
@unsafe
|
|
247
|
+
export let addBytes = (bytes, buffer) => {
|
|
340
248
|
let bytelen = Bytes.length(bytes)
|
|
341
249
|
|
|
342
|
-
Memory.incRef(WasmI32.fromGrain(autogrow))
|
|
343
|
-
Memory.incRef(WasmI32.fromGrain(bytelen))
|
|
344
|
-
Memory.incRef(WasmI32.fromGrain(buffer))
|
|
345
250
|
autogrow(bytelen, buffer)
|
|
346
251
|
|
|
347
252
|
let off = coerceNumberToWasmI32(buffer.len)
|
|
@@ -350,15 +255,7 @@ export let rec addBytes = (bytes, buffer) => {
|
|
|
350
255
|
let dst = WasmI32.fromGrain(buffer.data)
|
|
351
256
|
appendBytes(0n, off, len, src, dst)
|
|
352
257
|
|
|
353
|
-
Memory.incRef(WasmI32.fromGrain((+)))
|
|
354
|
-
Memory.incRef(WasmI32.fromGrain(buffer.len))
|
|
355
|
-
Memory.incRef(WasmI32.fromGrain(bytelen))
|
|
356
258
|
buffer.len = buffer.len + bytelen
|
|
357
|
-
|
|
358
|
-
Memory.decRef(WasmI32.fromGrain(bytes))
|
|
359
|
-
Memory.decRef(WasmI32.fromGrain(buffer))
|
|
360
|
-
Memory.decRef(WasmI32.fromGrain(addBytes))
|
|
361
|
-
void
|
|
362
259
|
}
|
|
363
260
|
|
|
364
261
|
/**
|
|
@@ -369,15 +266,10 @@ export let rec addBytes = (bytes, buffer) => {
|
|
|
369
266
|
*
|
|
370
267
|
* @since v0.4.0
|
|
371
268
|
*/
|
|
372
|
-
@
|
|
373
|
-
export let
|
|
374
|
-
Memory.incRef(WasmI32.fromGrain(String.byteLength))
|
|
375
|
-
Memory.incRef(WasmI32.fromGrain(string))
|
|
269
|
+
@unsafe
|
|
270
|
+
export let addString = (string, buffer) => {
|
|
376
271
|
let bytelen = String.byteLength(string)
|
|
377
272
|
|
|
378
|
-
Memory.incRef(WasmI32.fromGrain(autogrow))
|
|
379
|
-
Memory.incRef(WasmI32.fromGrain(bytelen))
|
|
380
|
-
Memory.incRef(WasmI32.fromGrain(buffer))
|
|
381
273
|
autogrow(bytelen, buffer)
|
|
382
274
|
|
|
383
275
|
let off = coerceNumberToWasmI32(buffer.len)
|
|
@@ -386,66 +278,38 @@ export let rec addString = (string, buffer) => {
|
|
|
386
278
|
let dst = WasmI32.fromGrain(buffer.data)
|
|
387
279
|
appendBytes(0n, off, len, src, dst)
|
|
388
280
|
|
|
389
|
-
Memory.incRef(WasmI32.fromGrain((+)))
|
|
390
|
-
Memory.incRef(WasmI32.fromGrain(buffer.len))
|
|
391
|
-
Memory.incRef(WasmI32.fromGrain(bytelen))
|
|
392
281
|
buffer.len = buffer.len + bytelen
|
|
282
|
+
}
|
|
393
283
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
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)
|
|
398
294
|
}
|
|
399
295
|
|
|
400
296
|
/**
|
|
401
297
|
* Appends the bytes of a subset of a string to a buffer.
|
|
402
298
|
*
|
|
403
299
|
* @param start: The char offset into the string
|
|
404
|
-
* @param
|
|
300
|
+
* @param end: The end offset into the string
|
|
405
301
|
* @param string: The string to append
|
|
406
302
|
* @param buffer: The buffer to mutate
|
|
407
303
|
*
|
|
408
304
|
* @since v0.4.0
|
|
305
|
+
* @history v0.5.0: Now takes the end offset instead of length
|
|
409
306
|
*/
|
|
410
|
-
@
|
|
411
|
-
export let
|
|
412
|
-
// Handle negative start index (needed before #1071 is fixed)
|
|
413
|
-
let start = {
|
|
414
|
-
// this is a block to avoid making all of these operators
|
|
415
|
-
// overriden in the whole function
|
|
416
|
-
let (<<) = WasmI32.shl
|
|
417
|
-
let (>>) = WasmI32.shrS
|
|
418
|
-
let (+) = WasmI32.add
|
|
419
|
-
let (!=) = WasmI32.ne
|
|
420
|
-
let (&) = WasmI32.and
|
|
421
|
-
Memory.incRef(WasmI32.fromGrain(String.length))
|
|
422
|
-
Memory.incRef(WasmI32.fromGrain(string))
|
|
423
|
-
let strlen = WasmI32.fromGrain(String.length(string)) >> 1n
|
|
424
|
-
let mut startW = WasmI32.fromGrain(start)
|
|
425
|
-
if ((startW & 1n) != 1n) {
|
|
426
|
-
throw InvalidArgument("Invalid start index")
|
|
427
|
-
}
|
|
428
|
-
startW = startW >> 1n
|
|
429
|
-
if (WasmI32.ltS(startW, 0n)) {
|
|
430
|
-
WasmI32.toGrain(WasmI32.shl(startW + strlen, 1n) + 1n)
|
|
431
|
-
} else {
|
|
432
|
-
start
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
let end = start + length
|
|
436
|
-
Memory.incRef(WasmI32.fromGrain(String.slice))
|
|
437
|
-
// no incref for start since we know it's a simple num. Add back for good measure after #1071 is fixed!
|
|
438
|
-
Memory.incRef(WasmI32.fromGrain(end))
|
|
439
|
-
Memory.incRef(WasmI32.fromGrain(string))
|
|
307
|
+
@unsafe
|
|
308
|
+
export let addStringSlice = (start: Number, end, string, buffer) => {
|
|
440
309
|
let slice = String.slice(start, end, string)
|
|
441
310
|
|
|
442
|
-
Memory.incRef(WasmI32.fromGrain(String.byteLength))
|
|
443
|
-
Memory.incRef(WasmI32.fromGrain(slice))
|
|
444
311
|
let bytelen = String.byteLength(slice)
|
|
445
312
|
|
|
446
|
-
Memory.incRef(WasmI32.fromGrain(autogrow))
|
|
447
|
-
Memory.incRef(WasmI32.fromGrain(bytelen))
|
|
448
|
-
Memory.incRef(WasmI32.fromGrain(buffer))
|
|
449
313
|
autogrow(bytelen, buffer)
|
|
450
314
|
|
|
451
315
|
let srcOff = 0n
|
|
@@ -453,24 +317,12 @@ export let rec addStringSlice = (start: Number, length, string, buffer) => {
|
|
|
453
317
|
let src = WasmI32.fromGrain(slice)
|
|
454
318
|
let dst = WasmI32.fromGrain(buffer.data)
|
|
455
319
|
appendBytes(srcOff, dstOff, coerceNumberToWasmI32(bytelen), src, dst)
|
|
456
|
-
Memory.decRef(WasmI32.fromGrain(slice))
|
|
457
320
|
|
|
458
|
-
Memory.incRef(WasmI32.fromGrain((+)))
|
|
459
|
-
Memory.incRef(WasmI32.fromGrain(buffer.len))
|
|
460
|
-
Memory.incRef(WasmI32.fromGrain(bytelen))
|
|
461
321
|
buffer.len = buffer.len + bytelen
|
|
462
|
-
Memory.decRef(WasmI32.fromGrain(bytelen))
|
|
463
|
-
|
|
464
|
-
Memory.decRef(WasmI32.fromGrain(start))
|
|
465
|
-
Memory.decRef(WasmI32.fromGrain(length))
|
|
466
|
-
Memory.decRef(WasmI32.fromGrain(string))
|
|
467
|
-
Memory.decRef(WasmI32.fromGrain(buffer))
|
|
468
|
-
Memory.decRef(WasmI32.fromGrain(addStringSlice))
|
|
469
|
-
void
|
|
470
322
|
}
|
|
471
323
|
|
|
472
324
|
/**
|
|
473
|
-
* Appends the bytes of a subset of a byte
|
|
325
|
+
* Appends the bytes of a subset of a byte sequence to a buffer.
|
|
474
326
|
*
|
|
475
327
|
* @param start: The byte offset into the byte sequence
|
|
476
328
|
* @param length: The number of bytes to append
|
|
@@ -479,8 +331,8 @@ export let rec addStringSlice = (start: Number, length, string, buffer) => {
|
|
|
479
331
|
*
|
|
480
332
|
* @since v0.4.0
|
|
481
333
|
*/
|
|
482
|
-
@
|
|
483
|
-
export let
|
|
334
|
+
@unsafe
|
|
335
|
+
export let addBytesSlice =
|
|
484
336
|
(
|
|
485
337
|
start: Number,
|
|
486
338
|
length: Number,
|
|
@@ -505,9 +357,6 @@ export let rec addBytesSlice =
|
|
|
505
357
|
throw Exception.IndexOutOfBounds
|
|
506
358
|
}
|
|
507
359
|
|
|
508
|
-
Memory.incRef(WasmI32.fromGrain(autogrow))
|
|
509
|
-
Memory.incRef(WasmI32.fromGrain(length))
|
|
510
|
-
Memory.incRef(WasmI32.fromGrain(buffer))
|
|
511
360
|
autogrow(length, buffer)
|
|
512
361
|
|
|
513
362
|
let dstOff = coerceNumberToWasmI32(buffer.len)
|
|
@@ -515,17 +364,7 @@ export let rec addBytesSlice =
|
|
|
515
364
|
let dst = WasmI32.fromGrain(buffer.data)
|
|
516
365
|
appendBytes(srcOff, dstOff, len, src, dst)
|
|
517
366
|
|
|
518
|
-
Memory.incRef(WasmI32.fromGrain((+)))
|
|
519
|
-
Memory.incRef(WasmI32.fromGrain(buffer.len))
|
|
520
|
-
Memory.incRef(WasmI32.fromGrain(length))
|
|
521
367
|
buffer.len = buffer.len + length
|
|
522
|
-
|
|
523
|
-
Memory.decRef(WasmI32.fromGrain(start))
|
|
524
|
-
Memory.decRef(WasmI32.fromGrain(length))
|
|
525
|
-
Memory.decRef(WasmI32.fromGrain(bytes))
|
|
526
|
-
Memory.decRef(WasmI32.fromGrain(buffer))
|
|
527
|
-
Memory.decRef(WasmI32.fromGrain(addBytesSlice))
|
|
528
|
-
void
|
|
529
368
|
}
|
|
530
369
|
|
|
531
370
|
/**
|
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>next</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
|
|