Phase 8 step 3a of the Metal renderer port:
- New library/modules/gpu/ with types.sx (handles + ClearColor +
TextureFormat enum), api.sx (GPU :: protocol { ... } covering the
lifecycle / per-frame / resource / per-draw surface), and metal.sx
(MetalGPU backend implementing the protocol against CAMetalLayer).
Resource handles are 1-based indices into backend List(*void) tables.
MTL aggregates >16 bytes (MTLRegion, MTLScissorRect) pass via *T to
match arm64 Apple's indirect-by-reference ABI; MTLClearColor + CGSize
go through the HFA path as direct fn-pointer casts on objc_msgSend.
- UIKitPlatform got a gpu_mode: GpuMode toggle + sibling SxMetalView
class registration. In metal mode init skips EAGL context, the
did_finish_launching IMP skips the EAGL drawable-properties dict,
layoutSubviews reads the layer's bounds * dpi_scale into pixel_w/h
instead of allocating a GL renderbuffer, and end_frame is a no-op
(the MetalGPU owns its own present).
- examples/63-metal-clear.sx verifies the pipeline end-to-end on iOS
sim — compiles a pass-through MSL shader (packed_float2/packed_float4
to avoid alignment padding), uploads 3 vertices, draws a colored
triangle on a dark-blue clear.
Compiler fixes (filed-and-fixed in this branch):
- inline if X { return E; } followed by a fall-through final expression
no longer emits two terminators into the same basic block. Verified
by examples/83-inline-if-return-fallthrough.sx.
- Top-level type alias Name :: u32; now resolves correctly as the type
annotation on a global variable (was treated as ptr {}, breaking
comparisons + initializers). Verified by examples/84-global-type-alias.sx.
Issue->feature promotion:
- 16 historical examples/issue-NNNN.sx repros now confirmed-fixed and
renamed to focused feature names (67-82). Each gains a
tests/expected/*.txt + .exit pair so the regression suite covers them.
- 5 stale issue repros deleted (subsumed by broader tests).
Regression suite: 68 passing, 0 failed. macOS chess builds + runs; wasm
chess builds; iOS sim GLES chess still renders the full board; iOS sim
Metal demo renders the triangle.
57 lines
1.7 KiB
Plaintext
57 lines
1.7 KiB
Plaintext
// Optional `?f32` fields in struct literals — exhaustively combine null/value
|
|
// for both fields, through both direct calls and protocol dispatch.
|
|
|
|
#import "modules/std.sx";
|
|
|
|
ProposedSize :: struct {
|
|
width: ?f32;
|
|
height: ?f32;
|
|
}
|
|
|
|
// Direct function — does it work?
|
|
direct_size :: (proposal: ProposedSize) -> f32 {
|
|
w := if pw := proposal.width { pw; } else { 100.0; };
|
|
h := if ph := proposal.height { ph; } else { 100.0; };
|
|
w + h;
|
|
}
|
|
|
|
Sizable :: protocol {
|
|
size :: (proposal: ProposedSize) -> f32;
|
|
}
|
|
|
|
Widget :: struct {}
|
|
|
|
impl Sizable for Widget {
|
|
size :: (self: *Widget, proposal: ProposedSize) -> f32 {
|
|
w := if pw := proposal.width { pw; } else { 100.0; };
|
|
h := if ph := proposal.height { ph; } else { 100.0; };
|
|
w + h;
|
|
}
|
|
}
|
|
|
|
main :: () -> void {
|
|
// Test 1: Direct call
|
|
print("=== Direct calls ===\n");
|
|
d1 := direct_size(ProposedSize.{ width = 50.0, height = null });
|
|
print("d1 = {}\n", d1);
|
|
d2 := direct_size(ProposedSize.{ width = null, height = 50.0 });
|
|
print("d2 = {}\n", d2);
|
|
d3 := direct_size(ProposedSize.{ width = null, height = null });
|
|
print("d3 = {}\n", d3);
|
|
d4 := direct_size(ProposedSize.{ width = 50.0, height = 60.0 });
|
|
print("d4 = {}\n", d4);
|
|
|
|
// Test 2: Protocol dispatch
|
|
print("=== Protocol dispatch ===\n");
|
|
w := Widget.{};
|
|
s : Sizable = w;
|
|
r1 := s.size(ProposedSize.{ width = 50.0, height = null });
|
|
print("r1 = {}\n", r1);
|
|
r2 := s.size(ProposedSize.{ width = null, height = 50.0 });
|
|
print("r2 = {}\n", r2);
|
|
r3 := s.size(ProposedSize.{ width = null, height = null });
|
|
print("r3 = {}\n", r3);
|
|
r4 := s.size(ProposedSize.{ width = 50.0, height = 60.0 });
|
|
print("r4 = {}\n", r4);
|
|
}
|