ffi: drop static keyword on foreign-class methods; param type discriminates
`static name :: ...` was redundant — instance methods always declare `self: *Self` as their first param by convention. The parser now derives `is_static` from the first param's TYPE: if it's `*Self` the method is an instance method; anything else (including no params at all) is a class method. Removes a token from the surface, keeps the dispatch behavior identical. The receiver param's NAME doesn't matter — only its type. Calling the first param `this`, `me`, `receiver`, etc. is fine as long as the type is `*Self`. This mirrors how the rest of sx handles receiver dispatch. Migration of every site that used the keyword: - `library/modules/platform/android.sx` — `SurfaceView.new(ctx)`. - `examples/ffi-jni-class-03-static.sx` — `Math.abs(n)`. - `examples/ffi-jni-main-03-ctor.sx` — `SurfaceView.new(ctx)` in the `#jni_main` body. - `examples/ffi-objc-dsl-05-static.sx` — NSObject's `.class()` / `.description()`. 164/164 example tests; chess clean on macOS / iOS sim / Android via `tools/verify-step.sh`.
This commit is contained in:
@@ -1163,17 +1163,6 @@ pub const Parser = struct {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Optional `static` prefix → class method (no implicit `self`).
|
||||
// Context-sensitive — `static` is a plain identifier elsewhere.
|
||||
var is_static = false;
|
||||
if (self.current.tag == .identifier and
|
||||
std.mem.eql(u8, self.tokenSlice(self.current), "static") and
|
||||
self.peekNext() == .identifier)
|
||||
{
|
||||
is_static = true;
|
||||
self.advance(); // consume `static`
|
||||
}
|
||||
|
||||
// Field: name: Type; (instance field — JNI Get/Set<Type>Field)
|
||||
// Method: name :: (args...) -> Ret;
|
||||
if (self.current.tag != .identifier) {
|
||||
@@ -1183,9 +1172,6 @@ pub const Parser = struct {
|
||||
self.advance();
|
||||
|
||||
if (self.current.tag == .colon) {
|
||||
if (is_static) {
|
||||
return self.fail("static fields not yet supported in '#jni_class' body");
|
||||
}
|
||||
self.advance(); // consume `:`
|
||||
const field_type = try self.parseTypeExpr();
|
||||
try self.expect(.semicolon);
|
||||
@@ -1218,6 +1204,21 @@ pub const Parser = struct {
|
||||
}
|
||||
try self.expect(.r_paren);
|
||||
|
||||
// Instance vs class method is determined by the first param's
|
||||
// TYPE: `*Self` (pointer-to-Self) ⇒ instance method, anything
|
||||
// else (including a method with no params at all) ⇒ class
|
||||
// method. Keying on the type, not the param name, means the
|
||||
// user can call the receiver whatever they like — `this`,
|
||||
// `me`, etc. — without changing the dispatch shape.
|
||||
const is_static = blk: {
|
||||
if (param_types.items.len == 0) break :blk true;
|
||||
const first = param_types.items[0];
|
||||
if (first.data != .pointer_type_expr) break :blk true;
|
||||
const pointee = first.data.pointer_type_expr.pointee_type;
|
||||
if (pointee.data != .type_expr) break :blk true;
|
||||
break :blk !std.mem.eql(u8, pointee.data.type_expr.name, "Self");
|
||||
};
|
||||
|
||||
var return_type: ?*Node = null;
|
||||
if (self.current.tag == .arrow) {
|
||||
self.advance();
|
||||
|
||||
Reference in New Issue
Block a user