ffi M1.2 A.1 follow-up: struct args/returns in Obj-C type encoding
`appendObjcEncoding` previously bailed on `.@"struct"`, which blocked
sx-defined `#objc_class` methods from declaring CGPoint / CGRect /
NSRange-shape signatures — the `class_addMethod` registration path
would emit a "type kind not yet supported by Obj-C encoding"
diagnostic. The helper now emits Apple's `{Name=field0field1...}`
form recursively, with a small `ObjcEncodingStack` (cap 16) that
breaks transitive struct→struct cycles by emitting the abbreviated
`{Name}` form instead of recursing forever.
`{Point=dd}`, `{_NSRange=QQ}`, `{CGRect={CGPoint=dd}{CGSize=dd}}`
all flow through the existing `objc_msg_send` + `class_addMethod`
path with no further plumbing.
Tests:
- `lower.test.zig` gains four cases: optional unwrap (single + nested),
flat struct (CGPoint, NSRange shape), nested struct (CGRect with
CGPoint+CGSize), bringing the helper's test coverage from
primitives + pointers to the full encoding table.
- `examples/ffi-objc-defined-class-02-struct-encoding.sx` exercises
a sx-defined `SxMover` class with `goto(p: Point)` setter and
`here() -> Point` getter end-to-end on macOS; the IR snapshot
confirms `v@:{Point=dd}` and `{Point=dd}@:` land in
`OBJC_METH_VAR_TYPE_` constants wired to `class_addMethod`.
Checkpoint cleanup: the "Next step (M1.2 A.1 — type-encoding
derivation table)" header in CHECKPOINT-FFI.md was stale (A.1
shipped in 6cc016c; A.0–A.7 all done; commit list now linked).
The encoding table stays as reference material.
224/224 example tests pass; zig build test green.
This commit is contained in:
@@ -1095,27 +1095,26 @@ after target dealloc) both pass.
|
||||
- Active forward plan: 6-month Obj-C FFI roadmap at
|
||||
`~/.claude/plans/lets-see-options-for-merry-dijkstra.md`.
|
||||
|
||||
## Next step (M1.2 A.1 — type-encoding derivation table)
|
||||
## M1.2 A.0–A.7 complete (historical planning block follows)
|
||||
|
||||
The synthesized `+alloc` (A.5), `-dealloc` (A.6), and every
|
||||
instance-method IMP (A.2) need to call `class_addMethod(cls, sel,
|
||||
imp, types)` with a type-encoding string in Apple's runtime DSL:
|
||||
A.0 through A.7 all shipped — see Log entries `61a2593` (A.0),
|
||||
`6cc016c` (A.1), `7b98b3a` (A.2a), `ae1072d` (A.2b), `659cdc2`
|
||||
(A.2c + A.3), `b98a22e` (A.4), `c2178c0` (A.4b.i), `c0b338e`
|
||||
(A.4b.ii), `8757257` (A.4b.iii), `a1736f3` (A.5), `c107aa4` (A.6),
|
||||
`51277af` (A.7), plus `f75923a` (uikit struct field types +
|
||||
optional-in-encoding follow-up). The Apple type-encoding helper
|
||||
table below stays here as reference material — every encoding it
|
||||
describes is implemented in [src/ir/lower.zig](../src/ir/lower.zig)
|
||||
`appendObjcEncoding` and exercised by `lower.test.zig` +
|
||||
`examples/ffi-objc-defined-class-{01-instance,02-struct-encoding}.sx`.
|
||||
|
||||
Apple's runtime DSL encoding table:
|
||||
|
||||
- `v` = void, `i` = s32, `q` = s64, `f` = f32, `d` = f64, `B` = bool,
|
||||
- `c` = s8/BOOL, `C` = u8, `s` = s16, `S` = u16, `l/L` = long,
|
||||
`Q` = u64, `*` = `[*]u8`,
|
||||
- `@` = id (object), `#` = Class, `:` = SEL, `^v` = `*void`.
|
||||
- Struct: `{Name=field1field2...}`.
|
||||
|
||||
A.1 = `objcTypeEncodingFromSignature` helper in
|
||||
[src/ir/lower.zig](../src/ir/lower.zig). Inputs: receiver-as-`@`,
|
||||
`_cmd` selector slot `:`, then return type + arg types from the
|
||||
IR signature. Lookup table over `TypeId`. No emission yet — A.1
|
||||
is a pure helper that A.2-A.6 will call.
|
||||
|
||||
Bounded slice: probably 100-200 lines of Zig, one-pass switch
|
||||
over TypeId. No cadence-rule test needed (helper has no observable
|
||||
output on its own; tested via integration with A.2+).
|
||||
- Struct: `{Name=field0field1...}`, nested + cycle-broken.
|
||||
|
||||
## Phase 1B complete (1.6–1.14)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user