ffi 2.11 green: DSL call sites on #jni_class-typed receivers lower to JNI dispatch
`inst.method(args)` on a value typed as a foreign-class alias
(`Activity :: #jni_class("android/app/Activity") { getWindow ::
(self: *Self) -> *Window; }` etc.) now lowers to `jni_msg_send`
with descriptor auto-derived from the sx signature, env from the
enclosing `#jni_env` scope (lexical-direct via 2.16b), and slot
interning re-used from Phase 1C.
Touch surface:
- `Lowering` gains `foreign_class_map: StringHashMap(*const
ForeignClassDecl)` populated in `scanDecls` + `lowerDecls`.
- New `registerForeignClassDecl` records each declared alias; the
type-bridge fallback already interns the alias as a 0-field
struct, so `*Activity` resolves cleanly through `getStructTypeName`.
- New `lowerForeignMethodCall` looks up the method in
`ForeignClassDecl.members`, derives the descriptor via
`jni_descriptor.deriveMethod` (with a `ClassRegistry` built from
`foreign_class_map`), and emits `jni_msg_send` directly. Filters
by runtime — `jni_class`/`jni_interface` lower; `objc_class` etc.
surface a clear "not yet supported" diagnostic until Phase 3/4.
- `lowerCall`'s method-dispatch arm inserts the foreign-class
check before the standard struct-method resolution.
JNI descriptor derivation gains `*void → Ljava/lang/Object;` (the
opaque-jobject convention) — common when sx code doesn't have a
precise Java type for the value. Locked in with a unit test.
IR snapshot at `tests/expected/ffi-jni-class-08-call.ir` shows the
full lowering: env from the enclosing fn param, target from the
foreign-class arg, slot-interned `(class, method, sig)` cache
pair, jni_msg_send to `CallObjectMethod` (slot 34). Mangled slot
names `@SX_JNI_CLS_getWindow____Ljava_lang_Object_` confirm the
derived descriptor.
129/129 examples + 16 jni_descriptor unit tests green.
This commit is contained in:
@@ -79,12 +79,16 @@ pub fn writeType(
|
||||
try writeType(allocator, buf, ctx, arr.element_type);
|
||||
},
|
||||
.pointer_type_expr => |ptr| {
|
||||
// *Self → L<enclosing>;, *Foo → L<Foo's foreign path>;
|
||||
// *Self → L<enclosing>;, *Foo → L<Foo's foreign path>;,
|
||||
// *void → Ljava/lang/Object; (opaque jobject — common when
|
||||
// users don't have a precise Java type for the value).
|
||||
const inner = ptr.pointee_type;
|
||||
if (inner.data != .type_expr) return DeriveError.UnsupportedType;
|
||||
const target_name = inner.data.type_expr.name;
|
||||
const target_path: []const u8 = if (std.mem.eql(u8, target_name, "Self"))
|
||||
ctx.enclosing_path
|
||||
else if (std.mem.eql(u8, target_name, "void"))
|
||||
"java/lang/Object"
|
||||
else if (ctx.classes) |reg|
|
||||
reg.get(target_name) orelse return DeriveError.UnknownClassAlias
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user