@scriptc/cli-darwin-x64 0.2.3 → 0.2.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/dist/THIRD_PARTY_NOTICES +1 -1
- package/dist/bin/scriptc +0 -0
- package/dist/bin/scriptc.json +1 -1
- package/dist/lib/declarations/scriptc-node-fallback.d.ts +915 -215
- package/dist/lib/declarations/scriptc-overrides.d.ts +5 -1
- package/dist/lib/declarations/scriptc.d.ts +22 -2
- package/dist/lib/llvm/bin/scriptc-llvm-codegen +0 -0
- package/dist/lib/llvm/package.json +1 -1
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_array.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_bigint.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_copying.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_cycle.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_map.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_number.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_string.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_util_compare.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_array.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_bigint.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_copying.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_cycle.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_map.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_number.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_string.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_util_compare.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic-text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_array.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_bigint.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_copying.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_cycle.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_map.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_number.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_string.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_array.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_bigint.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_copying.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_cycle.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_map.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_number.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_string.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_array.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_bigint.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_copying.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_cycle.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_map.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_number.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_string.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_array.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_bigint.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_copying.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_cycle.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_map.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_number.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_string.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_array.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_bigint.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_copying.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_cycle.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_map.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_number.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_string.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_util_compare.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_array.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_bigint.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_copying.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_cycle.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_map.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_number.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_string.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_util_compare.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic-text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/package.json +1 -1
- package/dist/lib/runtime-darwin-x64/runtime-pack.json +215 -215
- package/dist/lib/runtime-sources/package.json +1 -1
- package/dist/lib/runtime-sources/src/scr_array.c +317 -40
- package/dist/lib/runtime-sources/src/scr_async.test.ts +16 -6
- package/dist/lib/runtime-sources/src/scr_bigint.c +15 -0
- package/dist/lib/runtime-sources/src/scr_bytes.c +437 -216
- package/dist/lib/runtime-sources/src/scr_bytes.test.c +85 -0
- package/dist/lib/runtime-sources/src/scr_bytes_io.c +0 -34
- package/dist/lib/runtime-sources/src/scr_copying.c +12 -2
- package/dist/lib/runtime-sources/src/scr_cycle.c +84 -60
- package/dist/lib/runtime-sources/src/scr_json.c +494 -161
- package/dist/lib/runtime-sources/src/scr_json.test.c +323 -1
- package/dist/lib/runtime-sources/src/scr_json.test.ts +58 -25
- package/dist/lib/runtime-sources/src/scr_key.h +68 -0
- package/dist/lib/runtime-sources/src/scr_lib.c +177 -89
- package/dist/lib/runtime-sources/src/scr_map.c +268 -96
- package/dist/lib/runtime-sources/src/scr_number.c +2 -4
- package/dist/lib/runtime-sources/src/scr_numeric.h +25 -0
- package/dist/lib/runtime-sources/src/scr_numeric.test.c +37 -0
- package/dist/lib/runtime-sources/src/scr_numeric.test.ts +33 -0
- package/dist/lib/runtime-sources/src/scr_regex.c +255 -145
- package/dist/lib/runtime-sources/src/scr_runtime.h +76 -19
- package/dist/lib/runtime-sources/src/scr_string.c +184 -42
- package/package.json +1 -1
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#include "scr_runtime.h"
|
|
2
|
+
#include <assert.h>
|
|
3
|
+
#include <math.h>
|
|
4
|
+
#include <string.h>
|
|
5
|
+
|
|
6
|
+
long scr_bytes_live_count(void);
|
|
7
|
+
|
|
8
|
+
/* Foreign wrappers may alias without a shared owner and may be unaligned. */
|
|
9
|
+
static ScrBytes *external(uint8_t *data, ScrBytesElem elem, size_t count) {
|
|
10
|
+
ScrBytes *view = scr_bytes_from_external(data, count * scr_bytes_elem_size(elem));
|
|
11
|
+
view->elem = elem;
|
|
12
|
+
view->len = count;
|
|
13
|
+
return view;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static void external_set(void) {
|
|
17
|
+
const size_t starts[] = {1, 9, 41, 3001};
|
|
18
|
+
uint8_t storage[6000], expected[6000];
|
|
19
|
+
for (ScrBytesElem from = SCR_BYTES_U8; from <= SCR_BYTES_U8C; from++) {
|
|
20
|
+
for (ScrBytesElem to = SCR_BYTES_U8; to <= SCR_BYTES_U8C; to++) {
|
|
21
|
+
for (size_t j = 0; j < sizeof starts / sizeof starts[0]; j++) {
|
|
22
|
+
memset(storage, 0x5a, sizeof storage);
|
|
23
|
+
ScrBytes *src = external(storage + 9, from, 259);
|
|
24
|
+
ScrBytes *dst = external(storage + starts[j], to, 263);
|
|
25
|
+
for (size_t i = 0; i < src->len; i++) scr_bytes_set(src, i, (double)i * 3.5 - 257);
|
|
26
|
+
memcpy(expected, storage, sizeof storage);
|
|
27
|
+
ScrBytes *want = external(expected + starts[j], to, 263);
|
|
28
|
+
for (size_t i = 0; i < src->len; i++) scr_bytes_set(want, i + 2, scr_bytes_get(src, i));
|
|
29
|
+
scr_bytes_set_from(dst, src, 2);
|
|
30
|
+
assert(!scr_exc_pending());
|
|
31
|
+
assert(memcmp(storage, expected, sizeof storage) == 0);
|
|
32
|
+
scr_bytes_release(want);
|
|
33
|
+
scr_bytes_release(dst);
|
|
34
|
+
scr_bytes_release(src);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static void copied_storage(void) {
|
|
41
|
+
/* Same-kind copies preserve NaN payloads, signed zero and ownership. */
|
|
42
|
+
const uint64_t bits[] = {UINT64_C(0x7ff8000000000042), UINT64_C(0x8000000000000000),
|
|
43
|
+
UINT64_C(0xfff0000000000000)};
|
|
44
|
+
ScrBytes *src = scr_bytes_new(SCR_BYTES_F64, 3);
|
|
45
|
+
memcpy(src->data, bits, sizeof bits);
|
|
46
|
+
ScrBytes *copy = scr_bytes_convert(SCR_BYTES_F64, src);
|
|
47
|
+
ScrBytes *slice = scr_bytes_slice(src, 0, 3);
|
|
48
|
+
assert(copy->data != src->data && slice->data != src->data);
|
|
49
|
+
assert(memcmp(copy->data, bits, sizeof bits) == 0);
|
|
50
|
+
assert(memcmp(slice->data, bits, sizeof bits) == 0);
|
|
51
|
+
ScrBytes *view = scr_bytes_subarray(copy, 1, 3);
|
|
52
|
+
scr_bytes_release(copy);
|
|
53
|
+
scr_bytes_release(src);
|
|
54
|
+
assert(memcmp(view->data, bits + 1, sizeof bits - sizeof bits[0]) == 0);
|
|
55
|
+
scr_bytes_release(view);
|
|
56
|
+
scr_bytes_release(slice);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
static void filled_storage(void) {
|
|
60
|
+
uint8_t storage[2200], expected[2200];
|
|
61
|
+
const double values[] = {-0.0, -1.5, 2.5, 255.5, 4294967297.0, NAN, INFINITY};
|
|
62
|
+
for (ScrBytesElem elem = SCR_BYTES_U8; elem <= SCR_BYTES_U8C; elem++) {
|
|
63
|
+
for (size_t j = 0; j < sizeof values / sizeof values[0]; j++) {
|
|
64
|
+
memset(storage, 0xa5, sizeof storage);
|
|
65
|
+
memcpy(expected, storage, sizeof storage);
|
|
66
|
+
ScrBytes *dst = external(storage + 1, elem, 263);
|
|
67
|
+
ScrBytes *want = external(expected + 1, elem, 263);
|
|
68
|
+
for (size_t i = 2; i < 261; i++) scr_bytes_set(want, i, values[j]);
|
|
69
|
+
ScrBytes *result = scr_bytes_fill_elem(dst, values[j], 2, 261);
|
|
70
|
+
assert(result == dst && dst->rc == 2);
|
|
71
|
+
assert(memcmp(storage, expected, sizeof storage) == 0);
|
|
72
|
+
scr_bytes_release(result);
|
|
73
|
+
scr_bytes_release(dst);
|
|
74
|
+
scr_bytes_release(want);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
void scr_bytes_test_bulk_storage(void) {
|
|
80
|
+
long before = scr_bytes_live_count();
|
|
81
|
+
external_set();
|
|
82
|
+
copied_storage();
|
|
83
|
+
filled_storage();
|
|
84
|
+
assert(scr_bytes_live_count() == before);
|
|
85
|
+
}
|
|
@@ -37,40 +37,6 @@ static void scr_bytes_io_oom(void) {
|
|
|
37
37
|
|
|
38
38
|
/* ── fs (the Buffer forms of scr_lib.c's utf8 pair) ────────────────────── */
|
|
39
39
|
|
|
40
|
-
ScrBytes *scr_fs_read_file_bytes(ScrStr *path) {
|
|
41
|
-
FILE *f = fopen(path->data, "rb");
|
|
42
|
-
if (!f) {
|
|
43
|
-
scr_fs_throw(errno, "open", path);
|
|
44
|
-
return NULL;
|
|
45
|
-
}
|
|
46
|
-
size_t cap = 4096, len = 0;
|
|
47
|
-
uint8_t *buf = malloc(cap);
|
|
48
|
-
if (!buf) scr_bytes_io_oom();
|
|
49
|
-
for (;;) {
|
|
50
|
-
if (cap - len < 2048) {
|
|
51
|
-
cap *= 2;
|
|
52
|
-
uint8_t *grown = realloc(buf, cap);
|
|
53
|
-
if (!grown) scr_bytes_io_oom();
|
|
54
|
-
buf = grown;
|
|
55
|
-
}
|
|
56
|
-
size_t n = fread(buf + len, 1, cap - len, f);
|
|
57
|
-
len += n;
|
|
58
|
-
if (n == 0) break;
|
|
59
|
-
}
|
|
60
|
-
if (ferror(f)) {
|
|
61
|
-
int e = errno;
|
|
62
|
-
fclose(f);
|
|
63
|
-
free(buf);
|
|
64
|
-
scr_fs_throw(e, "read", path);
|
|
65
|
-
return NULL;
|
|
66
|
-
}
|
|
67
|
-
fclose(f);
|
|
68
|
-
ScrBytes *b = scr_bytes_new(SCR_BYTES_U8, (double)len);
|
|
69
|
-
memcpy(b->data, buf, len);
|
|
70
|
-
free(buf);
|
|
71
|
-
return b;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
40
|
/* readFileSync's runtime-encoding form (a JS helper's untyped `enc`
|
|
75
41
|
* parameter — test/common fixtures.js): undefined/null answer a Buffer,
|
|
76
42
|
* utf8 answers a string, Node's other real encodings meet the loud
|
|
@@ -125,9 +125,19 @@ ScrArr *scr_arr_with_undefined(ScrArr *a, double index) {
|
|
|
125
125
|
|
|
126
126
|
ScrBytes *scr_bytes_to_reversed(const ScrBytes *b) {
|
|
127
127
|
ScrBytes *out = scr_bytes_new(b->elem, (double)b->len);
|
|
128
|
+
size_t width = scr_bytes_elem_size(b->elem);
|
|
129
|
+
/* Copy the stored representation without numeric conversion. Views may
|
|
130
|
+
* be unaligned, so fixed-width memcpy preserves both alignment safety
|
|
131
|
+
* and floating-point payload bits. The width is invariant for the loop. */
|
|
128
132
|
for (size_t i = 0; i < b->len; i++) {
|
|
129
|
-
|
|
130
|
-
|
|
133
|
+
const uint8_t *source = b->data + (b->len - i - 1) * width;
|
|
134
|
+
uint8_t *target = out->data + i * width;
|
|
135
|
+
switch (width) {
|
|
136
|
+
case 1: *target = *source; break;
|
|
137
|
+
case 2: memcpy(target, source, 2); break;
|
|
138
|
+
case 4: memcpy(target, source, 4); break;
|
|
139
|
+
case 8: memcpy(target, source, 8); break;
|
|
140
|
+
}
|
|
131
141
|
}
|
|
132
142
|
return out;
|
|
133
143
|
}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* markGray trial-delete: decrement rc once per internal edge;
|
|
10
10
|
* scan nodes still rc > 0 are externally referenced — re-blacken
|
|
11
11
|
* their subgraph and restore the trial decrements;
|
|
12
|
-
*
|
|
12
|
+
* gather filter the scanned white set, then free it, releasing
|
|
13
13
|
* only edges that LEAVE the white set (each member's
|
|
14
14
|
* teardown releases its untraced children; traced edges were
|
|
15
15
|
* already accounted by markGray).
|
|
@@ -26,9 +26,10 @@
|
|
|
26
26
|
* count was already given up (which would over-decrement and free live
|
|
27
27
|
* data).
|
|
28
28
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
29
|
+
* The main graph phases keep a bounded depth-first walk and defer deeper
|
|
30
|
+
* traces to reusable worklists. Ordinary RC destruction and cross-generation
|
|
31
|
+
* releases are separate paths. White candidates are recorded during scan
|
|
32
|
+
* and filtered after outside roots settle, avoiding a separate gather walk.
|
|
32
33
|
*
|
|
33
34
|
* ── generations ──────────────────────────────────────────────────────
|
|
34
35
|
* A pass costs O(objects reachable from its candidates), and a candidate
|
|
@@ -154,6 +155,12 @@ static SCR_TL ScrVec scr_cands;
|
|
|
154
155
|
/* Nursery survivors awaiting promotion (see scr_scan_black). */
|
|
155
156
|
static SCR_TL ScrVec scr_promote;
|
|
156
157
|
|
|
158
|
+
/* Deferred traces cap recursive traversal without changing the common
|
|
159
|
+
* depth-first walk. Restore can run inside scan, so it has its own stack. */
|
|
160
|
+
static SCR_TL ScrVec scr_pending;
|
|
161
|
+
static SCR_TL ScrVec scr_restore_pending;
|
|
162
|
+
#define SCR_CYC_WALK_DEPTH 64
|
|
163
|
+
|
|
157
164
|
/* The gathered white set (freed after the walk completes). */
|
|
158
165
|
static SCR_TL ScrVec scr_white;
|
|
159
166
|
|
|
@@ -281,14 +288,15 @@ void scr_cyc_on_dead(void *obj) {
|
|
|
281
288
|
void scr_cyc_on_release(void *obj) {
|
|
282
289
|
ScrCycHdr *h = scr_cyc_hdr(obj);
|
|
283
290
|
h->color = SCR_CYC_PURPLE;
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
291
|
+
/* Releasing an existing candidate cannot advance the trigger. A pass
|
|
292
|
+
* always re-arms after its teardowns, including any candidates they add. */
|
|
293
|
+
if (h->buffered) return;
|
|
294
|
+
ScrVec *b = &scr_roots[h->gen];
|
|
295
|
+
if (b->n == b->cap) scr_cyc_grow(b);
|
|
296
|
+
h->buffered = 1;
|
|
297
|
+
h->buf_index = b->n;
|
|
298
|
+
b->v[b->n++] = obj;
|
|
299
|
+
scr_cyc_nbuffered++;
|
|
292
300
|
/* Never re-entered: a teardown's releases of untraced children can buffer
|
|
293
301
|
* new candidates mid-collection, but they only wait for the next pass. */
|
|
294
302
|
if (!scr_collecting && scr_cyc_nbuffered >= scr_cyc_trigger)
|
|
@@ -306,69 +314,68 @@ void scr_cyc_on_release(void *obj) {
|
|
|
306
314
|
((child) == NULL || SCR_RC(child) == SIZE_MAX \
|
|
307
315
|
|| scr_cyc_hdr(child)->gen > scr_gen_limit)
|
|
308
316
|
|
|
309
|
-
|
|
317
|
+
/* Trace callbacks forward an integer depth through their opaque context;
|
|
318
|
+
* it is never dereferenced. The ABI already carries it through every edge. */
|
|
319
|
+
static void scr_mark_gray(void *obj, uintptr_t depth);
|
|
310
320
|
static void scr_mg_visit(void *child, void *ctx) {
|
|
311
|
-
(void)ctx;
|
|
312
321
|
if (SCR_CYC_SKIP(child)) return;
|
|
313
|
-
SCR_RC(child) -= 1;
|
|
314
|
-
scr_mark_gray(child);
|
|
322
|
+
SCR_RC(child) -= 1;
|
|
323
|
+
scr_mark_gray(child, (uintptr_t)ctx);
|
|
315
324
|
}
|
|
316
|
-
static void scr_mark_gray(void *obj) {
|
|
325
|
+
static void scr_mark_gray(void *obj, uintptr_t depth) {
|
|
317
326
|
ScrCycHdr *h = scr_cyc_hdr(obj);
|
|
318
327
|
if (h->color == SCR_CYC_GRAY) return;
|
|
319
328
|
h->color = SCR_CYC_GRAY;
|
|
320
|
-
|
|
329
|
+
if (depth == SCR_CYC_WALK_DEPTH) {
|
|
330
|
+
scr_cyc_push(&scr_pending, obj);
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
h->trace(obj, scr_mg_visit, (void *)(depth + 1));
|
|
321
334
|
}
|
|
322
335
|
|
|
323
|
-
static void scr_scan_black(void *obj);
|
|
336
|
+
static void scr_scan_black(void *obj, uintptr_t depth);
|
|
324
337
|
static void scr_sb_visit(void *child, void *ctx) {
|
|
325
|
-
(void)ctx;
|
|
326
338
|
if (SCR_CYC_SKIP(child)) return;
|
|
327
|
-
SCR_RC(child) += 1;
|
|
328
|
-
if (scr_cyc_hdr(child)->color != SCR_CYC_BLACK)
|
|
339
|
+
SCR_RC(child) += 1;
|
|
340
|
+
if (scr_cyc_hdr(child)->color != SCR_CYC_BLACK)
|
|
341
|
+
scr_scan_black(child, (uintptr_t)ctx);
|
|
329
342
|
}
|
|
330
|
-
static void scr_scan_black(void *obj) {
|
|
343
|
+
static void scr_scan_black(void *obj, uintptr_t depth) {
|
|
331
344
|
ScrCycHdr *h = scr_cyc_hdr(obj);
|
|
332
345
|
h->color = SCR_CYC_BLACK;
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
h->trace(obj, scr_sb_visit, NULL);
|
|
346
|
+
if (h->gen < SCR_CYC_MATURE) scr_cyc_push(&scr_promote, obj);
|
|
347
|
+
if (depth == SCR_CYC_WALK_DEPTH) {
|
|
348
|
+
scr_cyc_push(&scr_restore_pending, obj);
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
h->trace(obj, scr_sb_visit, (void *)(depth + 1));
|
|
340
352
|
}
|
|
341
353
|
|
|
342
|
-
static void scr_scan(void *obj);
|
|
354
|
+
static void scr_scan(void *obj, uintptr_t depth);
|
|
343
355
|
static void scr_scan_visit(void *child, void *ctx) {
|
|
344
|
-
(void)ctx;
|
|
345
356
|
if (SCR_CYC_SKIP(child)) return;
|
|
346
|
-
scr_scan(child);
|
|
357
|
+
scr_scan(child, (uintptr_t)ctx);
|
|
347
358
|
}
|
|
348
|
-
static void scr_scan(void *obj) {
|
|
359
|
+
static void scr_scan(void *obj, uintptr_t depth) {
|
|
349
360
|
ScrCycHdr *h = scr_cyc_hdr(obj);
|
|
350
361
|
if (h->color != SCR_CYC_GRAY) return;
|
|
351
362
|
if (SCR_RC(obj) > 0) {
|
|
352
|
-
|
|
353
|
-
|
|
363
|
+
scr_scan_black(obj, 0);
|
|
364
|
+
while (scr_restore_pending.n) {
|
|
365
|
+
void *next = scr_restore_pending.v[--scr_restore_pending.n];
|
|
366
|
+
scr_cyc_hdr(next)->trace(next, scr_sb_visit, NULL);
|
|
367
|
+
}
|
|
354
368
|
return;
|
|
355
369
|
}
|
|
356
370
|
h->color = SCR_CYC_WHITE;
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
static void scr_collect_white(void *obj);
|
|
361
|
-
static void scr_cw_visit(void *child, void *ctx) {
|
|
362
|
-
(void)ctx;
|
|
363
|
-
if (SCR_CYC_SKIP(child)) return;
|
|
364
|
-
scr_collect_white(child);
|
|
365
|
-
}
|
|
366
|
-
static void scr_collect_white(void *obj) {
|
|
367
|
-
ScrCycHdr *h = scr_cyc_hdr(obj);
|
|
368
|
-
if (h->color != SCR_CYC_WHITE || h->buffered) return;
|
|
369
|
-
h->color = SCR_CYC_DOOMED; /* gathered — don't gather twice */
|
|
370
|
-
h->trace(obj, scr_cw_visit, NULL);
|
|
371
|
+
/* Record each whitened object once. A later outside root can restore it;
|
|
372
|
+
* filter the list only after every scan finishes. No gather trace needed. */
|
|
371
373
|
scr_cyc_push(&scr_white, obj);
|
|
374
|
+
if (depth == SCR_CYC_WALK_DEPTH) {
|
|
375
|
+
scr_cyc_push(&scr_pending, obj);
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
h->trace(obj, scr_scan_visit, (void *)(depth + 1));
|
|
372
379
|
}
|
|
373
380
|
|
|
374
381
|
/* ── cross-generation edges ───────────────────────────────────────────── */
|
|
@@ -443,12 +450,10 @@ static size_t scr_cyc_pass(unsigned gen_limit) {
|
|
|
443
450
|
scr_gen_limit = gen_limit;
|
|
444
451
|
|
|
445
452
|
/* markRoots: keep live candidates (still purple), drop the rest — an
|
|
446
|
-
* object re-retained since buffering is black
|
|
447
|
-
*
|
|
448
|
-
*
|
|
449
|
-
*
|
|
450
|
-
* to gather members of an earlier root's cycle. Candidates ABOVE the
|
|
451
|
-
* limit keep their buffer slots and wait for a full pass. */
|
|
453
|
+
* object re-retained since buffering is black. Drain the buffers before
|
|
454
|
+
* walking: tracing only adjusts counts and worklists, so nothing can
|
|
455
|
+
* re-buffer underneath us. Candidates ABOVE the limit keep their slots
|
|
456
|
+
* and wait for a full pass. */
|
|
452
457
|
scr_cands.n = 0;
|
|
453
458
|
for (unsigned g = 0; g <= gen_limit; g++) {
|
|
454
459
|
for (size_t i = 0; i < scr_roots[g].n; i++) {
|
|
@@ -460,12 +465,31 @@ static size_t scr_cyc_pass(unsigned gen_limit) {
|
|
|
460
465
|
}
|
|
461
466
|
scr_roots[g].n = 0;
|
|
462
467
|
}
|
|
463
|
-
for (size_t i = 0; i < scr_cands.n; i++) scr_mark_gray(scr_cands.v[i]);
|
|
464
|
-
|
|
465
|
-
|
|
468
|
+
for (size_t i = 0; i < scr_cands.n; i++) scr_mark_gray(scr_cands.v[i], 0);
|
|
469
|
+
while (scr_pending.n) {
|
|
470
|
+
void *obj = scr_pending.v[--scr_pending.n];
|
|
471
|
+
scr_cyc_hdr(obj)->trace(obj, scr_mg_visit, NULL);
|
|
472
|
+
}
|
|
466
473
|
|
|
467
474
|
scr_white.n = 0;
|
|
468
|
-
for (size_t i = 0; i < scr_cands.n; i++)
|
|
475
|
+
for (size_t i = 0; i < scr_cands.n; i++) scr_scan(scr_cands.v[i], 0);
|
|
476
|
+
while (scr_pending.n) {
|
|
477
|
+
void *obj = scr_pending.v[--scr_pending.n];
|
|
478
|
+
/* A later outside root may have restored this deferred white node and
|
|
479
|
+
* its descendants already. Never scan a black node's edges again. */
|
|
480
|
+
if (scr_cyc_hdr(obj)->color == SCR_CYC_WHITE)
|
|
481
|
+
scr_cyc_hdr(obj)->trace(obj, scr_scan_visit, NULL);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
size_t dead = 0;
|
|
485
|
+
for (size_t i = 0; i < scr_white.n; i++) {
|
|
486
|
+
void *obj = scr_white.v[i];
|
|
487
|
+
ScrCycHdr *h = scr_cyc_hdr(obj);
|
|
488
|
+
if (h->color != SCR_CYC_WHITE) continue;
|
|
489
|
+
h->color = SCR_CYC_DOOMED;
|
|
490
|
+
scr_white.v[dead++] = obj;
|
|
491
|
+
}
|
|
492
|
+
scr_white.n = dead;
|
|
469
493
|
|
|
470
494
|
/* Pin the cross-generation targets of everything about to be freed, while
|
|
471
495
|
* `gen` still holds the values the walk filtered on (promotion below is
|