From dc3821aeb089ae7eb8b2b06c994d7fe8cc35edf6 Mon Sep 17 00:00:00 2001 From: agra Date: Wed, 20 May 2026 10:11:50 +0300 Subject: [PATCH] ffi 2.7 xfail: other six type-introducer directive forms parse MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #jni_interface, #objc_class, #objc_protocol, #swift_class, #swift_struct, #swift_protocol — each with the same body grammar as #jni_class. Today the lexer doesn't recognise any of these directives and the parser errors at the first one (`#jni_interface`). The make-green follow-up adds the six lexer tokens and refactors `JniClassDecl` into `ForeignClassDecl` with a `runtime` discriminator so all seven forms share one AST shape and one parser path. --- examples/ffi-jni-class-07-all-runtimes.sx | 47 +++++++++++++++++++ .../ffi-jni-class-07-all-runtimes.exit | 1 + .../ffi-jni-class-07-all-runtimes.txt | 1 + 3 files changed, 49 insertions(+) create mode 100644 examples/ffi-jni-class-07-all-runtimes.sx create mode 100644 tests/expected/ffi-jni-class-07-all-runtimes.exit create mode 100644 tests/expected/ffi-jni-class-07-all-runtimes.txt diff --git a/examples/ffi-jni-class-07-all-runtimes.sx b/examples/ffi-jni-class-07-all-runtimes.sx new file mode 100644 index 0000000..d0ec4dc --- /dev/null +++ b/examples/ffi-jni-class-07-all-runtimes.sx @@ -0,0 +1,47 @@ +// Phase 2 step 2.7 (PLAN-FFI.md): xfail then green for the remaining +// six type-introducer directive forms parsing with the same body +// grammar as `#jni_class`. No codegen yet — Phase 3 picks up Obj-C +// codegen, Phase 4 picks up Swift. +// +// The directives this step turns on: +// #jni_interface — Java interface binding +// #objc_class — Obj-C class binding +// #objc_protocol — Obj-C protocol binding +// #swift_class — Swift class binding (via @_cdecl bridge) +// #swift_struct — Swift @frozen value-type binding +// #swift_protocol — Swift @objc-bridgeable protocol binding +// +// Internally the AST collapses into one `foreign_class_decl` node +// carrying a `runtime` discriminator. Today the parser rejects each +// of these because the lexer doesn't recognise the directive name. + +#import "modules/std.sx"; + +IFoo :: #jni_interface("com/example/IFoo") { + bar :: (self: *Self) -> s32; +} + +NSString :: #objc_class("NSString") { + length :: (self: *Self) -> s32; +} + +NSCopying :: #objc_protocol("NSCopying") { + copy :: (self: *Self) -> *Self; +} + +URL :: #swift_class("Foundation.URL") { + absoluteString :: (self: *Self) -> *void; +} + +Date :: #swift_struct("Foundation.Date") { + timeIntervalSince1970 :: (self: *Self) -> f64; +} + +Hashable :: #swift_protocol("Swift.Hashable") { + hash :: (self: *Self) -> s32; +} + +main :: () -> s32 { + print("parse-only ok\n"); + 0; +} diff --git a/tests/expected/ffi-jni-class-07-all-runtimes.exit b/tests/expected/ffi-jni-class-07-all-runtimes.exit new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/tests/expected/ffi-jni-class-07-all-runtimes.exit @@ -0,0 +1 @@ +1 diff --git a/tests/expected/ffi-jni-class-07-all-runtimes.txt b/tests/expected/ffi-jni-class-07-all-runtimes.txt new file mode 100644 index 0000000..9a9558e --- /dev/null +++ b/tests/expected/ffi-jni-class-07-all-runtimes.txt @@ -0,0 +1 @@ +/Users/agra/projects/sx/examples/ffi-jni-class-07-all-runtimes.sx:20:9: error: unexpected token in expression