lang: require explicit receiver in protocol method declarations
Protocol method declarations now declare their receiver explicitly as the first parameter — 'self: *Self' (or 'self: Self') — matching the impl method signature, instead of the old implicit-receiver form where the listed params were only the extra args. That asymmetry repeatedly caused confusion over whether the first param was the receiver or an argument. The parser validates the first param is 'self' typed Self/*Self, then strips it, so all downstream lowering and the dispatch ABI are unchanged (impl blocks and call sites are unaffected). A protocol method missing the receiver is now a parse error. Migrated all 129 protocol method signatures across library + examples (+ one inline-sx test in sema.zig) to the explicit form. Updated specs.md + readme.md. New: examples/0418-protocols-explicit-receiver.sx (feature), examples/1190-diagnostics-protocol-missing-receiver.sx (negative/diagnostic).
This commit is contained in:
@@ -11,47 +11,47 @@ GPU :: protocol {
|
||||
// Bind the GPU to a backend-specific render target (e.g. a
|
||||
// CAMetalLayer on iOS). pixel_w/pixel_h are the drawable's pixel
|
||||
// dimensions; call resize when they change.
|
||||
init :: (target: *void, pixel_w: i32, pixel_h: i32) -> bool;
|
||||
shutdown :: ();
|
||||
init :: (self: *Self, target: *void, pixel_w: i32, pixel_h: i32) -> bool;
|
||||
shutdown :: (self: *Self);
|
||||
|
||||
resize :: (pixel_w: i32, pixel_h: i32);
|
||||
resize :: (self: *Self, pixel_w: i32, pixel_h: i32);
|
||||
|
||||
begin_frame :: (clear: ClearColor) -> bool;
|
||||
begin_frame :: (self: *Self, clear: ClearColor) -> bool;
|
||||
|
||||
// target_time is the host clock time at which the drawable should be
|
||||
// presented (units match the platform's CADisplayLink.targetTimestamp
|
||||
// on Apple). Metal forwards it to presentDrawable:atTime: to cap the
|
||||
// pipeline at one frame so the inset slide lands on the same vsync as
|
||||
// UIKit's keyboard view. GL backends ignore it.
|
||||
end_frame :: (target_time: f64);
|
||||
end_frame :: (self: *Self, target_time: f64);
|
||||
|
||||
create_shader :: (vsrc: string, fsrc: string) -> ShaderHandle;
|
||||
create_buffer :: (size_bytes: i64) -> BufferHandle;
|
||||
update_buffer :: (buf: BufferHandle, data: *void, size_bytes: i64);
|
||||
create_shader :: (self: *Self, vsrc: string, fsrc: string) -> ShaderHandle;
|
||||
create_buffer :: (self: *Self, size_bytes: i64) -> BufferHandle;
|
||||
update_buffer :: (self: *Self, buf: BufferHandle, data: *void, size_bytes: i64);
|
||||
// Sub-buffer write at a byte offset. Required for Metal where re-using
|
||||
// the same buffer slice across multiple draws in a single command
|
||||
// encoder is a race: the GPU executes draws asynchronously and reads
|
||||
// shared-storage buffer contents at execution time, so the LAST writer
|
||||
// wins if every flush targets offset 0. Renderers that issue more than
|
||||
// one draw per frame must advance their write offset between flushes.
|
||||
update_buffer_at :: (buf: BufferHandle, data: *void, size_bytes: i64, byte_offset: i64);
|
||||
create_texture :: (w: i32, h: i32, format: TextureFormat, pixels: *void) -> TextureHandle;
|
||||
update_texture_region :: (tex: TextureHandle, x: i32, y: i32, w: i32, h: i32, pixels: *void);
|
||||
update_buffer_at :: (self: *Self, buf: BufferHandle, data: *void, size_bytes: i64, byte_offset: i64);
|
||||
create_texture :: (self: *Self, w: i32, h: i32, format: TextureFormat, pixels: *void) -> TextureHandle;
|
||||
update_texture_region :: (self: *Self, tex: TextureHandle, x: i32, y: i32, w: i32, h: i32, pixels: *void);
|
||||
|
||||
// Release a GPU resource. Implementations release the backing object and
|
||||
// null the slot so the handle becomes inert. Calling with handle 0 or
|
||||
// an already-destroyed handle is a no-op. Handles are not re-used; the
|
||||
// backing List entry stays at its index with a null sentinel.
|
||||
destroy_shader :: (sh: ShaderHandle);
|
||||
destroy_buffer :: (buf: BufferHandle);
|
||||
destroy_texture :: (tex: TextureHandle);
|
||||
destroy_shader :: (self: *Self, sh: ShaderHandle);
|
||||
destroy_buffer :: (self: *Self, buf: BufferHandle);
|
||||
destroy_texture :: (self: *Self, tex: TextureHandle);
|
||||
|
||||
set_shader :: (sh: ShaderHandle);
|
||||
set_vertex_buffer :: (buf: BufferHandle);
|
||||
set_texture :: (slot: u32, tex: TextureHandle);
|
||||
set_vertex_constants :: (slot: u32, data: *void, size_bytes: i64);
|
||||
set_scissor :: (x: i32, y: i32, w: i32, h: i32);
|
||||
disable_scissor :: ();
|
||||
set_shader :: (self: *Self, sh: ShaderHandle);
|
||||
set_vertex_buffer :: (self: *Self, buf: BufferHandle);
|
||||
set_texture :: (self: *Self, slot: u32, tex: TextureHandle);
|
||||
set_vertex_constants :: (self: *Self, slot: u32, data: *void, size_bytes: i64);
|
||||
set_scissor :: (self: *Self, x: i32, y: i32, w: i32, h: i32);
|
||||
disable_scissor :: (self: *Self);
|
||||
|
||||
draw_triangles :: (vertex_offset: i32, vertex_count: i32);
|
||||
draw_triangles :: (self: *Self, vertex_offset: i32, vertex_count: i32);
|
||||
}
|
||||
|
||||
@@ -4,24 +4,24 @@
|
||||
#import "modules/platform/types.sx";
|
||||
|
||||
Platform :: protocol {
|
||||
init :: (title: [:0]u8, w: i32, h: i32) -> bool;
|
||||
init :: (self: *Self, title: [:0]u8, w: i32, h: i32) -> bool;
|
||||
|
||||
run_frame_loop :: (frame_fn: Closure());
|
||||
run_frame_loop :: (self: *Self, frame_fn: Closure());
|
||||
|
||||
poll_events :: () -> []Event;
|
||||
poll_events :: (self: *Self) -> []Event;
|
||||
|
||||
begin_frame :: () -> FrameContext;
|
||||
end_frame :: ();
|
||||
begin_frame :: (self: *Self) -> FrameContext;
|
||||
end_frame :: (self: *Self);
|
||||
|
||||
safe_insets :: () -> EdgeInsets;
|
||||
keyboard :: () -> KeyboardState;
|
||||
show_keyboard :: ();
|
||||
hide_keyboard :: ();
|
||||
safe_insets :: (self: *Self) -> EdgeInsets;
|
||||
keyboard :: (self: *Self) -> KeyboardState;
|
||||
show_keyboard :: (self: *Self);
|
||||
hide_keyboard :: (self: *Self);
|
||||
|
||||
// Request the run loop to stop. On iOS/Android this is a no-op
|
||||
// (mobile apps don't quit on user request); on SDL it tears down the
|
||||
// `while !quit` loop.
|
||||
stop :: ();
|
||||
stop :: (self: *Self);
|
||||
|
||||
shutdown :: ();
|
||||
shutdown :: (self: *Self);
|
||||
}
|
||||
|
||||
@@ -60,8 +60,8 @@ string :: []u8 #builtin;
|
||||
// Bytes-level primitives carry the `_bytes` suffix so the typed
|
||||
// helpers in std/mem.sx own the bare names (`alloc(T, n)`, `free(s)`).
|
||||
Allocator :: protocol #inline {
|
||||
alloc_bytes :: (size: i64) -> *void;
|
||||
dealloc_bytes :: (ptr: *void);
|
||||
alloc_bytes :: (self: *Self, size: i64) -> *void;
|
||||
dealloc_bytes :: (self: *Self, ptr: *void);
|
||||
}
|
||||
|
||||
// --- Io capability protocol (impls live in std/io.sx) ---
|
||||
@@ -98,12 +98,12 @@ ParkToken :: struct {
|
||||
}
|
||||
|
||||
Io :: protocol #inline {
|
||||
spawn_raw :: (entry: *void, arg: *void, opts: SpawnOpts) -> *void;
|
||||
suspend_raw :: (park: ParkToken) -> !;
|
||||
ready :: (park: ParkToken);
|
||||
poll :: (deadline_ms: i64) -> i64;
|
||||
now_ms :: () -> i64;
|
||||
arm_timer :: (deadline_ms: i64, park: ParkToken) -> *void;
|
||||
spawn_raw :: (self: *Self, entry: *void, arg: *void, opts: SpawnOpts) -> *void;
|
||||
suspend_raw :: (self: *Self, park: ParkToken) -> !;
|
||||
ready :: (self: *Self, park: ParkToken);
|
||||
poll :: (self: *Self, deadline_ms: i64) -> i64;
|
||||
now_ms :: (self: *Self) -> i64;
|
||||
arm_timer :: (self: *Self, deadline_ms: i64, park: ParkToken) -> *void;
|
||||
}
|
||||
|
||||
// --- Context ---
|
||||
@@ -127,5 +127,5 @@ Context :: struct {
|
||||
// and emits a direct call. Compile-time only — no vtable, no runtime
|
||||
// dispatch.
|
||||
Into :: protocol(Target: Type) {
|
||||
convert :: () -> Target;
|
||||
convert :: (self: *Self) -> Target;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// --- Lerpable protocol (inline — static dispatch, no vtable) ---
|
||||
|
||||
Lerpable :: protocol #inline {
|
||||
lerp :: (b: Self, t: f32) -> Self;
|
||||
lerp :: (self: *Self, b: Self, t: f32) -> Self;
|
||||
}
|
||||
|
||||
// --- Easing Functions ---
|
||||
|
||||
@@ -4,16 +4,16 @@
|
||||
|
||||
View :: protocol {
|
||||
// Measure: given a size proposal, return desired size
|
||||
size_that_fits :: (proposal: ProposedSize) -> Size;
|
||||
size_that_fits :: (self: *Self, proposal: ProposedSize) -> Size;
|
||||
|
||||
// Place: position children within the given bounds
|
||||
layout :: (bounds: Frame);
|
||||
layout :: (self: *Self, bounds: Frame);
|
||||
|
||||
// Render: emit render nodes
|
||||
render :: (ctx: *RenderContext, frame: Frame);
|
||||
render :: (self: *Self, ctx: *RenderContext, frame: Frame);
|
||||
|
||||
// Event handling: return true if the event was consumed
|
||||
handle_event :: (event: *Event, frame: Frame) -> bool;
|
||||
handle_event :: (self: *Self, event: *Event, frame: Frame) -> bool;
|
||||
}
|
||||
|
||||
// A child view with its computed frame (set during layout)
|
||||
|
||||
Reference in New Issue
Block a user