Step 3b code is wired across UIRenderer + GlyphCache + UIPipeline +
chess game (gpu_mode = .metal on iOS, MetalGPU bound via the GPU
protocol). macOS GL chess, iOS-sim GLES chess, and iOS-sim Metal
triangle (63-metal-clear.sx) all still render.
iOS-sim Metal chess crashes inside replaceRegion uploading the 1MB
font atlas. Bisecting that crash exposed several sx-language issues
where mid-bisect tracers (NSLog inside if/else branch bodies) didn't
produce output, blocking further investigation.
Filing each finding as examples/issue-NNNN.sx rather than working
around piecemeal:
Bugs:
- 0024 NSLog/foreign-call inside if/else body not producing output
- 0025 C-ABI param coercion incomplete for composites >16B
(combined direct-call abiCoerceParamType TODO + call_indirect
path that doesn't apply C-ABI coercion at all)
- 0026 replaceRegion 1MB upload crash (likely downstream of 0025)
Features needed for step 4 + cleanup:
- 0027 Obj-C block bridge (^{...}) for animateWithDuration:
- 0028 Optional protocol box (?GPU = null) replaces T = ---; has_T: bool
- 0029 destroy_texture/buffer/shader on GPU protocol
- 0030 extern cross-file globals
Library-side: renderer.sx + glyph_cache.sx + pipeline.sx gain a
`gpu: GPU = ---; has_gpu: bool` field pair + branches that route every
GL touchpoint through the protocol when has_gpu. glyph_cache.init
saves/restores those fields around its memset. pipeline.set_gpu()
propagates to renderer + font. Renderer's MSL shader source added as
UI_MSL_SRC using packed_float2/packed_float4 to keep the 12-float
interleaved vertex layout tight (48 bytes).
metal.sx: dual-phase init (init(null, 0, 0) for eager device+queue,
re-init with the layer once UIKit installs the SxMetalView).
setStorageMode:.shared on every texture descriptor to ensure CPU-
writable atlas pixels on Apple Silicon iOS-sim.
Regression suite: 68 passing, 0 failed. WASM chess build currently
broken under step 3b state (silent compiler crash); documented in
CHECKPOINT.md, likely fallout from one of the filed issues (probably
0028 — the verbose protocol-box pattern). Step 3b resumes after
0024-0030 land.
58 lines
2.6 KiB
Plaintext
58 lines
2.6 KiB
Plaintext
// issue-0030: Feature — support `extern` global declarations so a global
|
|
// declared in one sx source file can be referenced from another without
|
|
// parameter threading.
|
|
//
|
|
// ── Use case from the Metal port ──────────────────────────────────────────
|
|
//
|
|
// // game/main.sx
|
|
// g_metal_gpu : *MetalGPU = null;
|
|
//
|
|
// // game/chess/pieces.sx
|
|
// extern g_metal_gpu : *MetalGPU;
|
|
//
|
|
// load :: (self: *ChessPieces, path: [:0]u8) {
|
|
// ...
|
|
// inline if OS == .ios {
|
|
// tex := g_metal_gpu.create_texture(w, h, .rgba8, xx pixels);
|
|
// } else {
|
|
// // GL path
|
|
// }
|
|
// }
|
|
//
|
|
// Today, pieces.load takes `has_gpu: bool, gpu: GPU` parameters and
|
|
// game/main.sx threads them through. Cross-file `extern` globals would
|
|
// let us drop those parameters.
|
|
//
|
|
// ── Implementation sketch ─────────────────────────────────────────────────
|
|
//
|
|
// Mirror how foreign function declarations work — declared in one file,
|
|
// defined elsewhere, linker resolves. Globals already have first-class
|
|
// addresses in the IR; just add an "extern" flag that says "don't emit
|
|
// storage, emit a reference."
|
|
//
|
|
// Files:
|
|
// - parser (sx surface syntax for `extern G : T;`)
|
|
// - src/ir/lower.zig (record an extern global stub that resolves at
|
|
// module-link time)
|
|
// - src/ir/emit_llvm.zig (emit an `external` LLVM global)
|
|
//
|
|
// ── Syntax constraint ─────────────────────────────────────────────────────
|
|
//
|
|
// `extern G : T;` is a NEW top-level form. Must not clash with:
|
|
// - `G :: T;` (type alias)
|
|
// - `G : T = ---;` (uninitialized global with explicit type)
|
|
// - `G : T;` (does this currently parse as anything?)
|
|
//
|
|
// The parser MUST reject `extern G : T = expr;` — extern cannot have an
|
|
// initializer (the definition lives elsewhere).
|
|
//
|
|
// ── Caveat ────────────────────────────────────────────────────────────────
|
|
//
|
|
// Encourages spaghetti globals. Documentation should steer callers toward
|
|
// explicit parameter passing where reasonable. Useful for genuine
|
|
// process-singletons (the active GPU, the active platform, etc.) where
|
|
// threading them through every call site is more noise than signal.
|
|
|
|
#import "modules/std.sx";
|
|
main :: () -> s32 { 0; }
|