xbintsc 0.7.7 → 0.7.9
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/src/cli/help.d.ts +1 -1
- package/dist/src/cli/help.js +1 -1
- package/dist/src/codegen/generator/calls/invocation.js +6 -4
- package/dist/src/codegen/generator/calls/invocation.js.map +1 -1
- package/dist/src/codegen/generator/context.d.ts +4 -3
- package/dist/src/codegen/generator/context.js +6 -5
- package/dist/src/codegen/generator/context.js.map +1 -1
- package/dist/src/codegen/generator/expressions/assignment.js +3 -3
- package/dist/src/driver/config.d.ts +1 -1
- package/dist/src/driver/options.d.ts +1 -1
- package/dist/src/driver/version.d.ts +1 -1
- package/dist/src/driver/version.js +1 -1
- package/dist/src/extensions/gui/features.d.ts +14 -6
- package/dist/src/extensions/gui/features.js +34 -6
- package/dist/src/extensions/gui/features.js.map +1 -1
- package/dist/src/extensions/gui/index.js +3 -3
- package/dist/tests/codegen/llvm.test.js +1 -1
- package/dist/tests/e2e/gui-audio.test.js +24 -0
- package/dist/tests/e2e/gui-audio.test.js.map +1 -1
- package/dist/tests/e2e/gui-draw-perf.test.js +9 -0
- package/dist/tests/e2e/gui-draw-perf.test.js.map +1 -1
- package/dist/tests/e2e/gui-font-face.test.d.ts +3 -1
- package/dist/tests/e2e/gui-font-face.test.js +99 -7
- package/dist/tests/e2e/gui-font-face.test.js.map +1 -1
- package/dist/tests/e2e/gui-frame-pacing.test.d.ts +15 -0
- package/dist/tests/e2e/gui-frame-pacing.test.js +68 -0
- package/dist/tests/e2e/gui-frame-pacing.test.js.map +1 -0
- package/dist/tests/e2e/gui-initial-url.test.d.ts +10 -0
- package/dist/tests/e2e/gui-initial-url.test.js +49 -0
- package/dist/tests/e2e/gui-initial-url.test.js.map +1 -0
- package/dist/tests/e2e/gui-layout.test.js +85 -0
- package/dist/tests/e2e/gui-layout.test.js.map +1 -1
- package/dist/tests/e2e/gui-webgl-depth-init.test.d.ts +13 -0
- package/dist/tests/e2e/gui-webgl-depth-init.test.js +144 -0
- package/dist/tests/e2e/gui-webgl-depth-init.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl-depth-range.test.d.ts +18 -0
- package/dist/tests/e2e/gui-webgl-depth-range.test.js +140 -0
- package/dist/tests/e2e/gui-webgl-depth-range.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl.test.js +49 -0
- package/dist/tests/e2e/gui-webgl.test.js.map +1 -1
- package/dist/tests/e2e/gui-webgpu-attachment.test.d.ts +19 -0
- package/dist/tests/e2e/gui-webgpu-attachment.test.js +258 -0
- package/dist/tests/e2e/gui-webgpu-attachment.test.js.map +1 -0
- package/dist/tests/e2e/method-call-cache.test.js +27 -0
- package/dist/tests/e2e/method-call-cache.test.js.map +1 -1
- package/dist/tests/extensions/gui-features.test.js +27 -2
- package/dist/tests/extensions/gui-features.test.js.map +1 -1
- package/doc/ai/extensions.md +10 -4
- package/doc/ai/zh-CN/extensions.md +8 -3
- package/doc/gui/animation.md +1 -1
- package/doc/gui/api.md +35 -2
- package/doc/gui/build.md +34 -15
- package/doc/gui/dom.md +3 -2
- package/doc/gui/known-issues.md +1 -1
- package/doc/gui/layout.md +9 -3
- package/doc/gui/rendering.md +45 -8
- package/doc/gui/runtime.md +13 -0
- package/doc/gui/webgl.md +29 -3
- package/doc/gui/webgpu.md +20 -0
- package/doc/gui.md +9 -4
- package/doc/implemented/codegen.md +4 -3
- package/doc/zh-CN/gui/animation.md +1 -1
- package/doc/zh-CN/gui/api.md +25 -2
- package/doc/zh-CN/gui/build.md +20 -7
- package/doc/zh-CN/gui/dom.md +3 -2
- package/doc/zh-CN/gui/known-issues.md +1 -1
- package/doc/zh-CN/gui/layout.md +7 -4
- package/doc/zh-CN/gui/rendering.md +33 -8
- package/doc/zh-CN/gui/runtime.md +9 -0
- package/doc/zh-CN/gui/webgl.md +7 -4
- package/doc/zh-CN/gui/webgpu.md +18 -0
- package/doc/zh-CN/gui.md +10 -5
- package/doc/zh-CN/implemented/codegen.md +4 -3
- package/package.json +7 -7
- package/runtime/ext_gui/audio_graph_commands.cpp +127 -0
- package/runtime/ext_gui/audio_mixer.cpp +84 -163
- package/runtime/ext_gui/audio_mixer.h +59 -3
- package/runtime/ext_gui/audio_mixer_extra.cpp +8 -0
- package/runtime/ext_gui/audio_param_apply.cpp +160 -0
- package/runtime/ext_gui/browser.cpp +6 -19
- package/runtime/ext_gui/browser_location.cpp +78 -0
- package/runtime/ext_gui/css.cpp +1 -0
- package/runtime/ext_gui/css.h +4 -0
- package/runtime/ext_gui/css_sheet.cpp +4 -2
- package/runtime/ext_gui/document_animation.cpp +7 -0
- package/runtime/ext_gui/dom_api_computed_style.cpp +3 -2
- package/runtime/ext_gui/dom_api_webgl.cpp +39 -2
- package/runtime/ext_gui/dom_api_webgl_extensions.cpp +134 -0
- package/runtime/ext_gui/dom_api_webgl_internal.h +4 -0
- package/runtime/ext_gui/dom_api_webgl_shader.cpp +28 -4
- package/runtime/ext_gui/dom_api_webgl_state.cpp +6 -103
- package/runtime/ext_gui/gui.cpp +100 -1
- package/runtime/ext_gui/gui_events.cpp +8 -2
- package/runtime/ext_gui/layout_flex.cpp +5 -2
- package/runtime/ext_gui/layout_flow.cpp +24 -1
- package/runtime/ext_gui/layout_flow_internal.h +11 -2
- package/runtime/ext_gui/media_query.cpp +3 -0
- package/runtime/ext_gui/perf.cpp +18 -6
- package/runtime/ext_gui/perf.h +37 -0
- package/runtime/ext_gui/style.cpp +28 -10
- package/runtime/ext_gui/style.h +10 -1
- package/runtime/ext_gui/style_length.cpp +4 -0
- package/runtime/ext_gui/style_print.cpp +7 -1
- package/runtime/ext_gui/style_values.cpp +6 -5
- package/runtime/ext_gui/text.cpp +4 -0
- package/runtime/ext_gui/text_font_bytes.cpp +117 -0
- package/runtime/ext_gui/text_font_bytes.h +65 -0
- package/runtime/ext_gui/text_font_db.cpp +5 -0
- package/runtime/ext_gui/text_font_sfnt.cpp +71 -24
- package/runtime/ext_gui/text_font_sfnt.h +5 -2
- package/runtime/ext_gui/text_hb.cpp +34 -5
- package/runtime/ext_gui/text_stb.cpp +7 -30
- package/runtime/ext_gui/text_webfont.cpp +217 -0
- package/runtime/ext_gui/warnings.cpp +26 -0
- package/runtime/ext_gui/warnings.h +8 -0
- package/runtime/ext_gui/webfont_bridge.c +23 -0
- package/runtime/ext_gui/webgl.h +36 -39
- package/runtime/ext_gui/webgl_blit_color.cpp +5 -0
- package/runtime/ext_gui/webgl_buffer_objects.cpp +19 -5
- package/runtime/ext_gui/webgl_context.cpp +2 -0
- package/runtime/ext_gui/webgl_draw.cpp +72 -12
- package/runtime/ext_gui/webgl_draw_setup.cpp +8 -2
- package/runtime/ext_gui/webgl_draw_state.h +13 -2
- package/runtime/ext_gui/webgl_framebuffer.cpp +8 -0
- package/runtime/ext_gui/webgl_objects.h +19 -0
- package/runtime/ext_gui/webgl_program.h +64 -0
- package/runtime/ext_gui/webgl_state.cpp +7 -0
- package/runtime/ext_gui/webgl_targets.cpp +31 -7
- package/runtime/ext_gui/webgl_uniform.cpp +78 -0
- package/runtime/ext_gui/webgpu.h +10 -0
- package/runtime/ext_gui/webgpu_buffer.cpp +3 -1
- package/runtime/ext_gui/webgpu_canvas.cpp +1 -0
- package/runtime/ext_gui/webgpu_command.cpp +51 -11
- package/runtime/ext_gui/webgpu_convert.cpp +7 -2
- package/runtime/ext_gui/webgpu_pass.cpp +12 -0
- package/runtime/ext_gui/webgpu_queue.cpp +3 -0
- package/runtime/ext_gui/webgpu_resources.cpp +1 -0
- package/runtime/ext_gui/window.cpp +6 -0
- package/runtime/rt_object.h +6 -0
- package/runtime/rt_profile.h +6 -0
- package/runtime/xt_containers/access.inc +2 -47
- package/runtime/xt_containers/ic_get.inc +70 -0
- package/runtime/xt_containers/method_cache.inc +42 -11
- package/runtime/xt_containers/objects.inc +12 -1
- package/runtime/xt_containers/shapes.inc +78 -0
- package/runtime/xt_containers.c +1 -0
- package/runtime/xt_profile.c +3 -0
- package/scripts/build-gui.ts +43 -49
- package/scripts/gui-engine-build.ts +58 -0
- package/scripts/gui-vendor-source.ts +53 -0
- package/scripts/gui-webfont-build.ts +138 -0
- package/src/cli/help.ts +1 -1
- package/src/codegen/generator/calls/invocation.ts +6 -4
- package/src/codegen/generator/context.ts +6 -6
- package/src/codegen/generator/expressions/assignment.ts +3 -3
- package/src/driver/config.ts +1 -1
- package/src/driver/options.ts +1 -1
- package/src/driver/version.ts +1 -1
- package/src/extensions/gui/features.ts +34 -6
- package/src/extensions/gui/index.ts +3 -3
|
@@ -423,11 +423,14 @@ static xt_value win_stats(xt_value self, xt_value env, int32_t argc, xt_value *a
|
|
|
423
423
|
* cumulative (diff two calls to get the work one frame did). */
|
|
424
424
|
const xtgui::PerfTimings &ms = xtgui::g_perf_last;
|
|
425
425
|
xt_object_set(object, xt_string_from_cstr("frameMs"), xt_number(ms.frame));
|
|
426
|
+
xt_object_set(object, xt_string_from_cstr("scriptMs"), xt_number(ms.script));
|
|
426
427
|
xt_object_set(object, xt_string_from_cstr("restyleMs"), xt_number(ms.restyle));
|
|
427
428
|
xt_object_set(object, xt_string_from_cstr("layoutMs"), xt_number(ms.layout));
|
|
428
429
|
xt_object_set(object, xt_string_from_cstr("paintMs"), xt_number(ms.paint));
|
|
429
430
|
xt_object_set(object, xt_string_from_cstr("uploadMs"), xt_number(ms.upload));
|
|
430
431
|
xt_object_set(object, xt_string_from_cstr("drawMs"), xt_number(ms.draw));
|
|
432
|
+
xt_object_set(object, xt_string_from_cstr("webglDrawMs"), xt_number(ms.webgl_draw));
|
|
433
|
+
xt_object_set(object, xt_string_from_cstr("webglUniformMs"), xt_number(ms.webgl_uniform));
|
|
431
434
|
const xtgui::PerfCounters &counters = xtgui::g_perf_total;
|
|
432
435
|
auto setCounter = [&object](const char *name, uint64_t value) {
|
|
433
436
|
xt_object_set(object, xt_string_from_cstr(name), xt_number((double)value));
|
|
@@ -463,6 +466,9 @@ static xt_value win_stats(xt_value self, xt_value env, int32_t argc, xt_value *a
|
|
|
463
466
|
setCounter("webglPasses", counters.webglPasses);
|
|
464
467
|
setCounter("webglPipelineMisses", counters.webglPipelineMisses);
|
|
465
468
|
setCounter("webglBufferUploadBytes", counters.webglBufferUploadBytes);
|
|
469
|
+
setCounter("webglSetupMisses", counters.webglSetupMisses);
|
|
470
|
+
setCounter("webglSamplerBinds", counters.webglSamplerBinds);
|
|
471
|
+
setCounter("webglStateBinds", counters.webglStateBinds);
|
|
466
472
|
return object;
|
|
467
473
|
}
|
|
468
474
|
|
package/runtime/rt_object.h
CHANGED
|
@@ -26,12 +26,18 @@ typedef struct {
|
|
|
26
26
|
* (parent, key) transition and never freed, so an object's shape pointer is a
|
|
27
27
|
* stable layout identity. Shape keys are rooted by a collector provider in
|
|
28
28
|
* xt_containers/shapes.inc. */
|
|
29
|
+
struct xt_shape_index;
|
|
29
30
|
typedef struct xt_shape {
|
|
30
31
|
xt_value key;
|
|
31
32
|
uint32_t count;
|
|
32
33
|
struct xt_shape *parent;
|
|
33
34
|
struct xt_shape *next; /* hash-bucket chain */
|
|
34
35
|
struct xt_shape *all_next; /* every shape, for the GC root provider */
|
|
36
|
+
/* Lazily built key -> property-index table for this layout (see
|
|
37
|
+
* `xt_shape_lookup`). NULL until the shape is first looked up in a
|
|
38
|
+
* property-heavy object. The chain order and the object's property order are
|
|
39
|
+
* the same by construction, so the index is a property position too. */
|
|
40
|
+
struct xt_shape_index *index;
|
|
35
41
|
} xt_shape;
|
|
36
42
|
|
|
37
43
|
typedef struct {
|
package/runtime/rt_profile.h
CHANGED
|
@@ -25,6 +25,12 @@ enum {
|
|
|
25
25
|
XT_PROFILE_STRING_CSTR,
|
|
26
26
|
XT_PROFILE_TYPED_READ,
|
|
27
27
|
XT_PROFILE_TYPED_WRITE,
|
|
28
|
+
/* Prepared inline-cache outcome: a hit skips the property lookup, an early
|
|
29
|
+
* out is a receiver/key the cache cannot describe (arrays, host views,
|
|
30
|
+
* symbol arithmetic), a miss performs the lookup and refills. */
|
|
31
|
+
XT_PROFILE_IC_HIT,
|
|
32
|
+
XT_PROFILE_IC_EARLY,
|
|
33
|
+
XT_PROFILE_IC_MISS,
|
|
28
34
|
XT_PROFILE_COUNT
|
|
29
35
|
};
|
|
30
36
|
|
|
@@ -302,49 +302,8 @@ xt_value xt_get(xt_value target, xt_value key) { if (target == XT_UNDEFINED ||
|
|
|
302
302
|
return XT_UNDEFINED;
|
|
303
303
|
}
|
|
304
304
|
|
|
305
|
-
/*
|
|
306
|
-
*
|
|
307
|
-
* and the second the property index. A shape hit is a pointer compare plus one
|
|
308
|
-
* key check, which avoids the linear property scan. Only ordinary objects and
|
|
309
|
-
* errors use the cache; arrays, functions, strings and containers fall back to
|
|
310
|
-
* the generic path. */
|
|
311
|
-
xt_value xt_get_ic(xt_value target, xt_value key, int64_t *cache) {
|
|
312
|
-
XT_PROFILE_TICK(XT_PROFILE_GET_IC);
|
|
313
|
-
if (!cache || !XT_IS_OBJECT(target)) return xt_get(target, key);
|
|
314
|
-
xt_object *obj = (xt_object *)XT_GET_PTR(target);
|
|
315
|
-
if (!xt_kind_is_object(obj->header.kind)) {
|
|
316
|
-
return xt_get(target, key);
|
|
317
|
-
}
|
|
318
|
-
/* A host view answers keys dynamically, outside the shape cache. */
|
|
319
|
-
if (obj->hooks != NULL) return xt_get(target, key);
|
|
320
|
-
if (!XT_IS_STRING(key) && !xt_is_symbol(key)) return xt_get(target, key);
|
|
321
|
-
xt_shape *shape = obj->shape;
|
|
322
|
-
uintptr_t cachedShape = (uintptr_t)cache[0];
|
|
323
|
-
int64_t cachedIndex = cache[1];
|
|
324
|
-
if (shape && cachedShape == (uintptr_t)shape && cachedIndex >= 0 &&
|
|
325
|
-
cachedIndex < (int64_t)obj->count) {
|
|
326
|
-
xt_property *prop = &obj->properties[cachedIndex];
|
|
327
|
-
if (prop->key == key || xt_property_key_equals(prop->key, key)) {
|
|
328
|
-
if (prop->getter != XT_UNDEFINED && XT_IS_FUNCTION(prop->getter)) {
|
|
329
|
-
return xt_call_with_this(prop->getter, target, 0, NULL);
|
|
330
|
-
}
|
|
331
|
-
if (prop->getter != XT_UNDEFINED) return XT_UNDEFINED;
|
|
332
|
-
return prop->value;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
xt_value propertyKey = xt_to_property_key(key);
|
|
336
|
-
xt_property *prop = xt_object_find_property(obj, propertyKey);
|
|
337
|
-
if (prop) {
|
|
338
|
-
cache[0] = (int64_t)(uintptr_t)shape;
|
|
339
|
-
cache[1] = (int64_t)(prop - obj->properties);
|
|
340
|
-
if (prop->getter != XT_UNDEFINED && XT_IS_FUNCTION(prop->getter)) {
|
|
341
|
-
return xt_call_with_this(prop->getter, target, 0, NULL);
|
|
342
|
-
}
|
|
343
|
-
if (prop->getter != XT_UNDEFINED) return XT_UNDEFINED;
|
|
344
|
-
return prop->value;
|
|
345
|
-
}
|
|
346
|
-
return xt_get(target, key);
|
|
347
|
-
}
|
|
305
|
+
/* The property-read inline cache (`xt_get_ic`) lives in `ic_get.inc`; `rt.h`
|
|
306
|
+
* declares it, so the element path below can call it. */
|
|
348
307
|
|
|
349
308
|
/* ------------------------------------------------------------------------- */
|
|
350
309
|
/* Element access (`obj[key]`) */
|
|
@@ -360,10 +319,6 @@ xt_value xt_get_ic(xt_value target, xt_value key, int64_t *cache) {
|
|
|
360
319
|
* `xt_get_ic` / `xt_set` paths, so semantics are unchanged.
|
|
361
320
|
*/
|
|
362
321
|
|
|
363
|
-
/* ------------------------------------------------------------------------- */
|
|
364
|
-
/* Element access (`obj[key]`) */
|
|
365
|
-
/* ------------------------------------------------------------------------- */
|
|
366
|
-
|
|
367
322
|
xt_value xt_get_element(xt_value target, xt_value key, int64_t *cache) {
|
|
368
323
|
uint32_t index = 0;
|
|
369
324
|
if (XT_IS_ARRAY(target)) {
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/* xbintsc runtime — the property-read inline cache.
|
|
2
|
+
*
|
|
3
|
+
* Included by `xt_containers.c` after `access.inc`; split out so the element
|
|
4
|
+
* access unit stays within the repository's file-length budget. `rt.h` declares
|
|
5
|
+
* `xt_get_ic`, which is what generated code calls.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/* Inline-cached property read. The generated code gives every source-level
|
|
9
|
+
* property access four zeroed `(shape, index)` pairs; a shape hit is a pointer
|
|
10
|
+
* compare plus one key check, which avoids the property lookup entirely. Only
|
|
11
|
+
* ordinary objects and errors use the cache; arrays, functions, strings and
|
|
12
|
+
* containers fall back to the generic path. */
|
|
13
|
+
xt_value xt_get_ic(xt_value target, xt_value key, int64_t *cache) {
|
|
14
|
+
XT_PROFILE_TICK(XT_PROFILE_GET_IC);
|
|
15
|
+
if (!cache || !XT_IS_OBJECT(target)) {
|
|
16
|
+
XT_PROFILE_TICK(XT_PROFILE_IC_EARLY);
|
|
17
|
+
return xt_get(target, key);
|
|
18
|
+
}
|
|
19
|
+
xt_object *obj = (xt_object *)XT_GET_PTR(target);
|
|
20
|
+
/* A host view answers keys dynamically, outside the shape cache; arrays,
|
|
21
|
+
* functions and non-string/symbol keys take the generic dispatch too. */
|
|
22
|
+
if (!xt_kind_is_object(obj->header.kind) || obj->hooks != NULL ||
|
|
23
|
+
(!XT_IS_STRING(key) && !xt_is_symbol(key))) {
|
|
24
|
+
XT_PROFILE_TICK(XT_PROFILE_IC_EARLY);
|
|
25
|
+
return xt_get(target, key);
|
|
26
|
+
}
|
|
27
|
+
xt_shape *shape = obj->shape;
|
|
28
|
+
/* Four entries, newest last: real call sites are polymorphic (a helper used
|
|
29
|
+
* by several three.js classes, a generic layout routine), and a single entry
|
|
30
|
+
* made almost every access at those sites miss and pay the full lookup. */
|
|
31
|
+
if (shape != NULL) {
|
|
32
|
+
for (int slot = 3; slot >= 0; slot--) {
|
|
33
|
+
if ((xt_shape *)(uintptr_t)cache[slot * 2] != shape) continue;
|
|
34
|
+
int64_t cachedIndex = cache[slot * 2 + 1];
|
|
35
|
+
if (cachedIndex < 0 || cachedIndex >= (int64_t)obj->count) continue;
|
|
36
|
+
xt_property *prop = &obj->properties[cachedIndex];
|
|
37
|
+
if (prop->key == key || xt_property_key_equals(prop->key, key)) {
|
|
38
|
+
XT_PROFILE_TICK(XT_PROFILE_IC_HIT);
|
|
39
|
+
if (prop->getter != XT_UNDEFINED && XT_IS_FUNCTION(prop->getter)) {
|
|
40
|
+
return xt_call_with_this(prop->getter, target, 0, NULL);
|
|
41
|
+
}
|
|
42
|
+
if (prop->getter != XT_UNDEFINED) return XT_UNDEFINED;
|
|
43
|
+
return prop->value;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
XT_PROFILE_TICK(XT_PROFILE_IC_MISS);
|
|
48
|
+
xt_value propertyKey = xt_to_property_key(key);
|
|
49
|
+
xt_property *prop = xt_object_find_property(obj, propertyKey);
|
|
50
|
+
if (prop) {
|
|
51
|
+
if (shape != NULL) {
|
|
52
|
+
/* FIFO: the oldest entry falls out, so a site that cycles through more
|
|
53
|
+
* than four layouts still converges instead of thrashing one slot. */
|
|
54
|
+
cache[0] = cache[2];
|
|
55
|
+
cache[1] = cache[3];
|
|
56
|
+
cache[2] = cache[4];
|
|
57
|
+
cache[3] = cache[5];
|
|
58
|
+
cache[4] = cache[6];
|
|
59
|
+
cache[5] = cache[7];
|
|
60
|
+
cache[6] = (int64_t)(uintptr_t)shape;
|
|
61
|
+
cache[7] = (int64_t)(prop - obj->properties);
|
|
62
|
+
}
|
|
63
|
+
if (prop->getter != XT_UNDEFINED && XT_IS_FUNCTION(prop->getter)) {
|
|
64
|
+
return xt_call_with_this(prop->getter, target, 0, NULL);
|
|
65
|
+
}
|
|
66
|
+
if (prop->getter != XT_UNDEFINED) return XT_UNDEFINED;
|
|
67
|
+
return prop->value;
|
|
68
|
+
}
|
|
69
|
+
return xt_get(target, key);
|
|
70
|
+
}
|
|
@@ -19,6 +19,11 @@
|
|
|
19
19
|
* - `cache[1]` is the holder's shape pointer and `cache[2]` the property
|
|
20
20
|
* index. The slot's key is compared on every hit, so a slot whose contents
|
|
21
21
|
* were deleted and reused cannot mis-dispatch;
|
|
22
|
+
* - `cache[3]` is the receiver's shape when a prototype method was cached.
|
|
23
|
+
* Adding an own property shadows the prototype method and transitions that
|
|
24
|
+
* shape, so the hit must miss rather than call the prototype method the
|
|
25
|
+
* receiver no longer inherits (three.js installs `_onChangeCallback` as an
|
|
26
|
+
* own property on `Euler` after other Eulers already warmed the site);
|
|
22
27
|
* - the *value* is re-read rather than cached, so reassigning the method
|
|
23
28
|
* (`obj.f = other`) is observed immediately — exactly like the property IC.
|
|
24
29
|
*
|
|
@@ -47,9 +52,13 @@ static void xt_method_cache_fill(int64_t *cache, xt_value target, xt_value name)
|
|
|
47
52
|
}
|
|
48
53
|
if (prop == NULL) return;
|
|
49
54
|
if (!XT_IS_FUNCTION(prop->value) || prop->getter != XT_UNDEFINED) return;
|
|
55
|
+
/* A prototype hit is guarded by the receiver's shape; without one (a
|
|
56
|
+
* dictionary-mode object) an own shadowing property would be invisible. */
|
|
57
|
+
if (holderValue != XT_UNDEFINED && object->shape == NULL) return;
|
|
50
58
|
cache[0] = (int64_t)holderValue;
|
|
51
59
|
cache[1] = (int64_t)(uintptr_t)holder->shape;
|
|
52
60
|
cache[2] = (int64_t)(prop - holder->properties);
|
|
61
|
+
cache[3] = (int64_t)(uintptr_t)object->shape;
|
|
53
62
|
}
|
|
54
63
|
|
|
55
64
|
xt_value xt_call_method_ic(xt_value target, xt_value name, int32_t argc, xt_value *argv,
|
|
@@ -72,7 +81,15 @@ xt_value xt_call_method_ic(xt_value target, xt_value name, int32_t argc, xt_valu
|
|
|
72
81
|
xt_property *prop = &holder->properties[slot];
|
|
73
82
|
if (prop->getter == XT_UNDEFINED && XT_IS_FUNCTION(prop->value) &&
|
|
74
83
|
(prop->key == name || xt_property_key_equals(prop->key, name))) {
|
|
75
|
-
|
|
84
|
+
/* A cached prototype method only still applies while the receiver
|
|
85
|
+
* has the shape it had when the cache was filled. Adding an own
|
|
86
|
+
* method (three.js's Euler `_onChangeCallback`) or any other own
|
|
87
|
+
* property transitions it, and the prototype method is shadowed. */
|
|
88
|
+
if (holder != object &&
|
|
89
|
+
object->shape != (xt_shape *)(uintptr_t)cache[3]) {
|
|
90
|
+
holder = NULL;
|
|
91
|
+
}
|
|
92
|
+
if (holder != NULL) return xt_call_with_this(prop->value, target, argc, argv);
|
|
76
93
|
}
|
|
77
94
|
}
|
|
78
95
|
}
|
|
@@ -98,21 +115,35 @@ xt_value xt_set_ic(xt_value target, xt_value key, xt_value value, int64_t *cache
|
|
|
98
115
|
if (cache != NULL && XT_IS_OBJECT(target)) {
|
|
99
116
|
xt_object *obj = (xt_object *)XT_GET_PTR(target);
|
|
100
117
|
if (obj->header.kind == XT_OBJECT_KIND_OBJECT && obj->hooks == NULL && !obj->frozen &&
|
|
101
|
-
obj->shape != NULL
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
118
|
+
obj->shape != NULL) {
|
|
119
|
+
/* Four entries, newest last: a hot store site in generic code writes
|
|
120
|
+
* fields of several layouts (three.js's Euler/Vector/Matrix helpers),
|
|
121
|
+
* which a single entry could not cache. */
|
|
122
|
+
for (int slot = 3; slot >= 0; slot--) {
|
|
123
|
+
if ((xt_shape *)(uintptr_t)cache[slot * 2] != obj->shape) continue;
|
|
124
|
+
int64_t at = cache[slot * 2 + 1];
|
|
125
|
+
if (at < 0 || at >= (int64_t)obj->count) continue;
|
|
126
|
+
xt_property *prop = &obj->properties[at];
|
|
127
|
+
if ((prop->key == key || xt_property_key_equals(prop->key, key)) &&
|
|
128
|
+
prop->getter == XT_UNDEFINED && prop->setter == XT_UNDEFINED) {
|
|
129
|
+
prop->value = value;
|
|
130
|
+
return value;
|
|
131
|
+
}
|
|
108
132
|
}
|
|
109
133
|
}
|
|
110
134
|
xt_value stored = xt_set(target, key, value);
|
|
111
|
-
if (obj->header.kind == XT_OBJECT_KIND_OBJECT && obj->hooks == NULL && !obj->frozen
|
|
135
|
+
if (obj->header.kind == XT_OBJECT_KIND_OBJECT && obj->hooks == NULL && !obj->frozen &&
|
|
136
|
+
obj->shape != NULL) {
|
|
112
137
|
xt_property *prop = xt_object_find(obj, xt_to_property_key(key));
|
|
113
138
|
if (prop != NULL && prop->getter == XT_UNDEFINED && prop->setter == XT_UNDEFINED) {
|
|
114
|
-
cache[0] =
|
|
115
|
-
cache[1] =
|
|
139
|
+
cache[0] = cache[2];
|
|
140
|
+
cache[1] = cache[3];
|
|
141
|
+
cache[2] = cache[4];
|
|
142
|
+
cache[3] = cache[5];
|
|
143
|
+
cache[4] = cache[6];
|
|
144
|
+
cache[5] = cache[7];
|
|
145
|
+
cache[6] = (int64_t)(uintptr_t)obj->shape;
|
|
146
|
+
cache[7] = (int64_t)(prop - obj->properties);
|
|
116
147
|
}
|
|
117
148
|
}
|
|
118
149
|
return stored;
|
|
@@ -198,6 +198,16 @@ xt_object *xt_as_object(xt_value value) {
|
|
|
198
198
|
|
|
199
199
|
static xt_property *xt_object_find(xt_object *obj, xt_value key) {
|
|
200
200
|
XT_PROFILE_TICK(XT_PROFILE_OBJECT_FIND);
|
|
201
|
+
if (obj == NULL) return NULL;
|
|
202
|
+
/* The shape is the authoritative layout: chain order and property order are
|
|
203
|
+
* the same by construction, and `xt_shape_lookup` is an O(1) hash for a
|
|
204
|
+
* layout with enough keys. Only a shape-less object (interning limit reached)
|
|
205
|
+
* falls back to the scan. */
|
|
206
|
+
if (obj->shape != NULL) {
|
|
207
|
+
uint32_t index = 0;
|
|
208
|
+
if (!xt_shape_lookup(obj->shape, key, &index) || index >= obj->count) return NULL;
|
|
209
|
+
return &obj->properties[index];
|
|
210
|
+
}
|
|
201
211
|
for (uint32_t i = 0; i < obj->count; i++) {
|
|
202
212
|
if (xt_property_key_equals(obj->properties[i].key, key)) return &obj->properties[i];
|
|
203
213
|
}
|
|
@@ -280,8 +290,9 @@ xt_value xt_to_property_key(xt_value key) {
|
|
|
280
290
|
/* Two property keys are equal when they are the same symbol, or equal
|
|
281
291
|
* strings. */
|
|
282
292
|
int xt_property_key_equals(xt_value a, xt_value b) {
|
|
293
|
+
if (a == b) return 1;
|
|
283
294
|
if (XT_IS_STRING(a) && XT_IS_STRING(b)) return xt_string_equals(xt_as_string(a), xt_as_string(b));
|
|
284
|
-
return
|
|
295
|
+
return 0;
|
|
285
296
|
}
|
|
286
297
|
|
|
287
298
|
static int xt_key_is_prototype(xt_value key) {
|
|
@@ -202,6 +202,84 @@ xt_shape *xt_shape_transition(xt_shape *parent, xt_value key) {
|
|
|
202
202
|
return shape;
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
+
/* -- property index -------------------------------------------------------
|
|
206
|
+
*
|
|
207
|
+
* A linear property scan was the dominant cost of a three.js-sized program:
|
|
208
|
+
* the one-entry inline cache is polymorphic on real pages (one call site reads
|
|
209
|
+
* several object layouts), so a large fraction of `obj.prop` reads fell back to
|
|
210
|
+
* walking the whole property array. The shape already describes the layout
|
|
211
|
+
* exactly — chain order *is* property order — so an interned shape can carry a
|
|
212
|
+
* key -> index table built once and shared by every object with that layout.
|
|
213
|
+
* Small objects keep the scan (building a table for 3 properties costs more
|
|
214
|
+
* than the scan); the table is created lazily for layouts with >= 8 keys.
|
|
215
|
+
*/
|
|
216
|
+
|
|
217
|
+
typedef struct {
|
|
218
|
+
xt_value key;
|
|
219
|
+
uint32_t index;
|
|
220
|
+
uint32_t used;
|
|
221
|
+
} xt_shape_slot;
|
|
222
|
+
|
|
223
|
+
typedef struct xt_shape_index {
|
|
224
|
+
uint32_t capacity; /* power of two */
|
|
225
|
+
xt_shape_slot slots[]; /* C99 flexible array member */
|
|
226
|
+
} xt_shape_index;
|
|
227
|
+
|
|
228
|
+
#define XT_SHAPE_INDEX_MIN 8
|
|
229
|
+
|
|
230
|
+
static xt_shape_index *xt_shape_build_index(xt_shape *shape) {
|
|
231
|
+
uint32_t capacity = 8;
|
|
232
|
+
while (capacity < shape->count * 2) capacity <<= 1;
|
|
233
|
+
xt_shape_index *index = (xt_shape_index *)calloc(
|
|
234
|
+
1, sizeof(xt_shape_index) + sizeof(xt_shape_slot) * (size_t)capacity);
|
|
235
|
+
if (!index) abort();
|
|
236
|
+
index->capacity = capacity;
|
|
237
|
+
uint32_t position = shape->count;
|
|
238
|
+
for (xt_shape *node = shape; node != NULL && node->parent != NULL && position > 0;
|
|
239
|
+
node = node->parent) {
|
|
240
|
+
position -= 1;
|
|
241
|
+
xt_shape_slot slot;
|
|
242
|
+
slot.key = node->key;
|
|
243
|
+
slot.index = position;
|
|
244
|
+
slot.used = 1;
|
|
245
|
+
size_t at = (size_t)xt_shape_key_hash(slot.key) & (size_t)(capacity - 1);
|
|
246
|
+
while (index->slots[at].used) at = (at + 1) & (size_t)(capacity - 1);
|
|
247
|
+
index->slots[at] = slot;
|
|
248
|
+
}
|
|
249
|
+
return index;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** Find `key` in `shape`'s layout and return its property index. */
|
|
253
|
+
int xt_shape_lookup(xt_shape *shape, xt_value key, uint32_t *out) {
|
|
254
|
+
if (shape == NULL || out == NULL) return 0;
|
|
255
|
+
if (shape->count < XT_SHAPE_INDEX_MIN) {
|
|
256
|
+
uint32_t position = shape->count;
|
|
257
|
+
for (xt_shape *node = shape; node != NULL && node->parent != NULL && position > 0;
|
|
258
|
+
node = node->parent) {
|
|
259
|
+
position -= 1;
|
|
260
|
+
if (node->key == key || xt_property_key_equals(node->key, key)) {
|
|
261
|
+
*out = position;
|
|
262
|
+
return 1;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return 0;
|
|
266
|
+
}
|
|
267
|
+
if (shape->index == NULL) shape->index = xt_shape_build_index(shape);
|
|
268
|
+
xt_shape_index *index = shape->index;
|
|
269
|
+
const size_t mask = (size_t)(index->capacity - 1);
|
|
270
|
+
size_t at = (size_t)xt_shape_key_hash(key) & mask;
|
|
271
|
+
for (uint32_t probe = 0; probe < index->capacity; probe++) {
|
|
272
|
+
xt_shape_slot *slot = &index->slots[at];
|
|
273
|
+
if (!slot->used) return 0;
|
|
274
|
+
if (slot->key == key || xt_property_key_equals(slot->key, key)) {
|
|
275
|
+
*out = slot->index;
|
|
276
|
+
return 1;
|
|
277
|
+
}
|
|
278
|
+
at = (at + 1) & mask;
|
|
279
|
+
}
|
|
280
|
+
return 0;
|
|
281
|
+
}
|
|
282
|
+
|
|
205
283
|
void xt_object_shape_changed(xt_object *obj) {
|
|
206
284
|
g_shape_rebuilds++;
|
|
207
285
|
xt_shape *shape = xt_shape_empty();
|
package/runtime/xt_containers.c
CHANGED
package/runtime/xt_profile.c
CHANGED
package/scripts/build-gui.ts
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* 2. build `libSDL3.a` with CMake,
|
|
15
15
|
* 2a. fetch + build static HarfBuzz/FreeType (optional `shaping`) and
|
|
16
16
|
* glslang/SPIRV-Cross (GLSL ES -> SPIR-V -> Metal Shading Language),
|
|
17
|
+
* and fetch the Brotli + woff2 sources the `webfonts` feature compiles,
|
|
17
18
|
* 3. compile the engine translation units,
|
|
18
19
|
* 4. merge everything into `gui.a` (libtool on macOS, `ar -M` elsewhere;
|
|
19
20
|
* `gui.lib` on Windows, built from MSVC-compatible COFF objects).
|
|
@@ -31,6 +32,8 @@
|
|
|
31
32
|
* FREETYPE_VERSION FreeType version (default: 2.13.3)
|
|
32
33
|
* HARFBUZZ_VERSION HarfBuzz version (default: 10.1.0)
|
|
33
34
|
* SPIRV_CROSS_VERSION SPIRV-Cross tag (default: vulkan-sdk-1.4.313.0)
|
|
35
|
+
* BROTLI_VERSION Brotli version (default: 1.1.0)
|
|
36
|
+
* WOFF2_VERSION woff2 reference decoder tag (default: 1.0.2)
|
|
34
37
|
*
|
|
35
38
|
* The C/C++ compiler is the same clang the driver resolves (see
|
|
36
39
|
* `src/driver/toolchain-provider.ts`), so the archive always matches the ABI of
|
|
@@ -39,7 +42,7 @@
|
|
|
39
42
|
* `gui.lib`.
|
|
40
43
|
*/
|
|
41
44
|
|
|
42
|
-
import { existsSync, mkdirSync, readdirSync, readFileSync,
|
|
45
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync } from "node:fs";
|
|
43
46
|
import { spawnSync, type SpawnSyncReturns } from "node:child_process";
|
|
44
47
|
import { dirname, join, resolve } from "node:path";
|
|
45
48
|
import { fileURLToPath } from "node:url";
|
|
@@ -49,13 +52,15 @@ import { isMsvcTarget, probeClang, realRunner } from "../src/driver/toolchain.js
|
|
|
49
52
|
import { resolveToolchain } from "../src/driver/toolchain-provider.js";
|
|
50
53
|
import {
|
|
51
54
|
cmakeToolchainArgs,
|
|
52
|
-
cxxCompileFlags,
|
|
53
55
|
HB_LEAN_DEFINES,
|
|
54
56
|
LEAN_SDL_OPTIONS,
|
|
55
57
|
SECTION_CMAKE_FLAGS,
|
|
56
58
|
SECTION_FLAGS,
|
|
57
59
|
} from "./gui-build-options.js";
|
|
58
60
|
import { ensureDeploymentTarget } from "./gui-build-cache.js";
|
|
61
|
+
import { buildEngineObjects } from "./gui-engine-build.js";
|
|
62
|
+
import { buildWebfontObjects, fetchWebfontSources, webfontIncludeFlags } from "./gui-webfont-build.js";
|
|
63
|
+
import { ensureTarballSource } from "./gui-vendor-source.js";
|
|
59
64
|
import { ensureVendoredSources } from "./fetch-vendored.js";
|
|
60
65
|
|
|
61
66
|
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
@@ -102,8 +107,9 @@ const output = join(outDir, isWindows ? "gui.lib" : "gui.a");
|
|
|
102
107
|
* oldest supported macOS, not the build machine's version. */
|
|
103
108
|
applyMacosDeploymentTarget();
|
|
104
109
|
|
|
105
|
-
/* Fetch the stb/NanoSVG headers the engine's default text/image paths include
|
|
106
|
-
|
|
110
|
+
/* Fetch the stb/NanoSVG headers the engine's default text/image paths include,
|
|
111
|
+
* plus the miniz sources the webfont decoder compiles. */
|
|
112
|
+
ensureVendoredSources(["stb", "nanosvg", "miniz"]);
|
|
107
113
|
|
|
108
114
|
const SDL_TAG = process.env.SDL3_TAG || "release-3.2.10";
|
|
109
115
|
const FREETYPE_VERSION = process.env.FREETYPE_VERSION || "2.13.3";
|
|
@@ -141,6 +147,13 @@ function run(
|
|
|
141
147
|
return result;
|
|
142
148
|
}
|
|
143
149
|
|
|
150
|
+
/** Fetching/extracting a vendored tarball, bound to this script's runner. */
|
|
151
|
+
const vendor = {
|
|
152
|
+
vendorDir,
|
|
153
|
+
run: (command: string, args: readonly string[]): void => void run(command, args),
|
|
154
|
+
fail,
|
|
155
|
+
};
|
|
156
|
+
|
|
144
157
|
function isRunnable(candidate: string): boolean {
|
|
145
158
|
return !spawnSync(candidate, ["--version"], { encoding: "utf8" }).error;
|
|
146
159
|
}
|
|
@@ -396,8 +409,8 @@ if (!existingSdlArchive) {
|
|
|
396
409
|
|
|
397
410
|
/* -- 2a. HarfBuzz + FreeType (optional `shaping` feature) ---------------- */
|
|
398
411
|
|
|
399
|
-
ensureTarballSource("freetype", FREETYPE_URL, `freetype-${FREETYPE_VERSION}`);
|
|
400
|
-
ensureTarballSource("harfbuzz", HARFBUZZ_URL, `harfbuzz-${HARFBUZZ_VERSION}`);
|
|
412
|
+
ensureTarballSource(vendor, "freetype", FREETYPE_URL, `freetype-${FREETYPE_VERSION}`);
|
|
413
|
+
ensureTarballSource(vendor, "harfbuzz", HARFBUZZ_URL, `harfbuzz-${HARFBUZZ_VERSION}`);
|
|
401
414
|
|
|
402
415
|
ensureDeploymentTarget("FreeType", freetypeBuild);
|
|
403
416
|
if (!existsSync(freetypeArchive() ?? "")) {
|
|
@@ -439,30 +452,10 @@ if (!existsSync(harfbuzzArchive() ?? "")) {
|
|
|
439
452
|
console.log(`xbintsc: reusing existing ${harfbuzzArchive()}`);
|
|
440
453
|
}
|
|
441
454
|
|
|
442
|
-
/** Download a release tarball into `vendor/` and extract it under `name`.
|
|
443
|
-
* Release tarballs are used (not git clones) because they ship generated
|
|
444
|
-
* sources, so no ragel/autotools step is needed. `marker` is a file that only
|
|
445
|
-
* exists once the tarball has been extracted (e.g. `CMakeLists.txt`). */
|
|
446
|
-
function ensureTarballSource(name: string, url: string, extractedName: string, marker = "CMakeLists.txt"): string {
|
|
447
|
-
const destination = join(vendorDir, name);
|
|
448
|
-
if (existsSync(join(destination, marker))) return destination;
|
|
449
|
-
const tarball = join(vendorDir, `${name}.tar.xz`);
|
|
450
|
-
console.log(`xbintsc: fetching ${name} from ${url}`);
|
|
451
|
-
mkdirSync(vendorDir, { recursive: true });
|
|
452
|
-
run("curl", ["-sL", "--fail", "-o", tarball, url]);
|
|
453
|
-
run("tar", ["-xf", tarball, "-C", vendorDir]);
|
|
454
|
-
const extracted = join(vendorDir, extractedName);
|
|
455
|
-
if (!existsSync(extracted)) fail(`expected ${extractedName} after extracting ${name}`);
|
|
456
|
-
rmSync(destination, { recursive: true, force: true });
|
|
457
|
-
renameSync(extracted, destination);
|
|
458
|
-
rmSync(tarball, { force: true });
|
|
459
|
-
return destination;
|
|
460
|
-
}
|
|
461
|
-
|
|
462
455
|
/* -- 2b. glslang (WebGL GLSL ES -> SPIR-V) -------------------------------- */
|
|
463
456
|
|
|
464
|
-
ensureTarballSource("glslang", GLSLANG_URL, `glslang-${GLSLANG_VERSION}`);
|
|
465
|
-
ensureTarballSource(join("glslang", "External", "spirv-headers"), SPIRV_HEADERS_URL,
|
|
457
|
+
ensureTarballSource(vendor, "glslang", GLSLANG_URL, `glslang-${GLSLANG_VERSION}`);
|
|
458
|
+
ensureTarballSource(vendor, join("glslang", "External", "spirv-headers"), SPIRV_HEADERS_URL,
|
|
466
459
|
`SPIRV-Headers-${SPIRV_HEADERS_VERSION}`);
|
|
467
460
|
|
|
468
461
|
ensureDeploymentTarget("glslang", glslangBuild);
|
|
@@ -492,7 +485,7 @@ if (!existsSync(glslangArchive() ?? "")) {
|
|
|
492
485
|
const metalBackend = process.platform === "darwin";
|
|
493
486
|
|
|
494
487
|
if (metalBackend) {
|
|
495
|
-
ensureTarballSource("spirv-cross", SPIRV_CROSS_URL, `SPIRV-Cross-${SPIRV_CROSS_VERSION}`);
|
|
488
|
+
ensureTarballSource(vendor, "spirv-cross", SPIRV_CROSS_URL, `SPIRV-Cross-${SPIRV_CROSS_VERSION}`);
|
|
496
489
|
|
|
497
490
|
ensureDeploymentTarget("SPIRV-Cross", spirvCrossBuild);
|
|
498
491
|
if (!existsSync(spirvCrossArchive("spirv-cross-msl") ?? "")) {
|
|
@@ -519,10 +512,17 @@ if (metalBackend) {
|
|
|
519
512
|
/* -- 3. engine objects ---------------------------------------------------- */
|
|
520
513
|
|
|
521
514
|
mkdirSync(objDir, { recursive: true });
|
|
515
|
+
const fetchSource = (name: string, url: string, extractedName: string): void => {
|
|
516
|
+
ensureTarballSource(vendor, name, url, extractedName);
|
|
517
|
+
};
|
|
518
|
+
/* The webfont headers are included by an engine translation unit, so the
|
|
519
|
+
* Brotli/woff2 sources must be extracted before the engine compile starts. */
|
|
520
|
+
fetchWebfontSources(fetchSource);
|
|
522
521
|
const includeFlags = [
|
|
523
522
|
"-I", runtimeDir,
|
|
524
523
|
"-I", join(vendorDir, "stb"),
|
|
525
524
|
"-I", join(vendorDir, "nanosvg"),
|
|
525
|
+
...webfontIncludeFlags(vendorDir),
|
|
526
526
|
"-I", join(sdlSrc, "include"),
|
|
527
527
|
"-I", join(freetypeSrc, "include"),
|
|
528
528
|
"-I", join(freetypeBuild, "include"),
|
|
@@ -531,26 +531,20 @@ const includeFlags = [
|
|
|
531
531
|
"-I", join(spirvHeadersSrc, "include"),
|
|
532
532
|
...(metalBackend ? ["-I", spirvCrossSrc] : []),
|
|
533
533
|
];
|
|
534
|
-
const
|
|
535
|
-
|
|
536
|
-
.
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
*
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
for (const source of sources) {
|
|
549
|
-
const object = join(objDir, source.replace(/\.cpp$/, objectSuffix));
|
|
550
|
-
console.log(`xbintsc: compiling ${source}`);
|
|
551
|
-
run(clangxx, [...cxxFlags, "-c", join(engineDir, source), "-o", object]);
|
|
552
|
-
objects.push(object);
|
|
553
|
-
}
|
|
534
|
+
const objects = buildEngineObjects({
|
|
535
|
+
engineDir, objDir, objectSuffix, clangxx, includeFlags,
|
|
536
|
+
sdkRoot: toolchain.sdkRoot, msvc: isWindows,
|
|
537
|
+
run: (command, args) => void run(command, args),
|
|
538
|
+
});
|
|
539
|
+
/* The WOFF/WOFF2 decompression objects for the `webfonts` link feature. They
|
|
540
|
+
* are reachable only through that feature's bridge, so the linker drops them
|
|
541
|
+
* from a program that never loads a compressed font. */
|
|
542
|
+
objects.push(...buildWebfontObjects({
|
|
543
|
+
vendorDir, objDir, objectSuffix, clang, clangxx, includeFlags,
|
|
544
|
+
sdkRoot: toolchain.sdkRoot, msvc: isWindows,
|
|
545
|
+
run: (command, args) => void run(command, args),
|
|
546
|
+
fetchSource,
|
|
547
|
+
}));
|
|
554
548
|
|
|
555
549
|
/* -- 4. merge into gui.a / gui.lib ---------------------------------------- */
|
|
556
550
|
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compile the GUI engine translation units (`runtime/ext_gui/*.cpp`) into the
|
|
3
|
+
* objects that are merged into `gui.a`/`gui.lib`.
|
|
4
|
+
*
|
|
5
|
+
* Split out of `build-gui.ts` (which has a file-size budget) so the engine
|
|
6
|
+
* compile flags live next to the "one function/data item per section, one
|
|
7
|
+
* runtime ABI" policy they implement. The vendored libraries are built by CMake
|
|
8
|
+
* in `build-gui.ts`; this module only covers the engine itself.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { readdirSync } from "node:fs";
|
|
12
|
+
import { join } from "node:path";
|
|
13
|
+
import { cxxCompileFlags } from "./gui-build-options.js";
|
|
14
|
+
|
|
15
|
+
export interface EngineBuildOptions {
|
|
16
|
+
/** `runtime/ext_gui`. */
|
|
17
|
+
readonly engineDir: string;
|
|
18
|
+
/** Directory the objects are written to (`build/gui-obj`). */
|
|
19
|
+
readonly objDir: string;
|
|
20
|
+
/** `.o` or `.obj`, matching the archive's ABI. */
|
|
21
|
+
readonly objectSuffix: string;
|
|
22
|
+
/** `clang++` from the driver's toolchain (never a bare `clang++`). */
|
|
23
|
+
readonly clangxx: string;
|
|
24
|
+
/** macOS SDK for `-isysroot`; absent elsewhere. */
|
|
25
|
+
readonly sdkRoot?: string;
|
|
26
|
+
/** Include directories, including the vendored headers the engine uses. */
|
|
27
|
+
readonly includeFlags: readonly string[];
|
|
28
|
+
/** True for the MSVC ABI: record the static C++ runtime and skip `-fPIC`. */
|
|
29
|
+
readonly msvc: boolean;
|
|
30
|
+
/** Run a compiler command, failing the build on a non-zero exit. */
|
|
31
|
+
run(command: string, args: readonly string[]): void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Compile every engine translation unit and return the object paths. */
|
|
35
|
+
export function buildEngineObjects(options: EngineBuildOptions): string[] {
|
|
36
|
+
const { engineDir, objDir, objectSuffix, clangxx, includeFlags, msvc, run } = options;
|
|
37
|
+
const flags = cxxCompileFlags(options.sdkRoot, includeFlags);
|
|
38
|
+
/* The engine is C++ and the MSVC C++ runtime must match the static C CRT that
|
|
39
|
+
* clang links by default, so let every engine object record `libcpmt` as a
|
|
40
|
+
* default library. The extension itself only contributes the DLL import
|
|
41
|
+
* library (`-lmsvcprt`, `src/extensions/gui/index.ts`), which is inconsistent
|
|
42
|
+
* with that CRT and makes the final link fail with `LNK2038`/unresolved
|
|
43
|
+
* `__imp_*`. */
|
|
44
|
+
if (msvc) flags.push("-Xclang", "--dependent-lib=libcpmt");
|
|
45
|
+
/* The MSVC ABI rejects `-fPIC`; position independence is the default
|
|
46
|
+
* elsewhere. */
|
|
47
|
+
if (!msvc) flags.splice(3, 0, "-fPIC");
|
|
48
|
+
|
|
49
|
+
const sources = readdirSync(engineDir)
|
|
50
|
+
.filter((entry) => entry.endsWith(".cpp"))
|
|
51
|
+
.sort();
|
|
52
|
+
return sources.map((source) => {
|
|
53
|
+
const object = join(objDir, source.replace(/\.cpp$/, objectSuffix));
|
|
54
|
+
console.log(`xbintsc: compiling ${source}`);
|
|
55
|
+
run(clangxx, [...flags, "-c", join(engineDir, source), "-o", object]);
|
|
56
|
+
return object;
|
|
57
|
+
});
|
|
58
|
+
}
|