diff --git a/library/modules/platform/android.sx b/library/modules/platform/android.sx index f2c4a28..c6e1273 100644 --- a/library/modules/platform/android.sx +++ b/library/modules/platform/android.sx @@ -38,31 +38,31 @@ // ── Foreign Java types ────────────────────────────────────────────────── -Bundle :: #foreign #jni_class("android/os/Bundle") { } -JContext :: #foreign #jni_class("android/content/Context") { +Bundle :: #jni_class("android/os/Bundle") extern { } +JContext :: #jni_class("android/content/Context") extern { getAssets :: (self: *Self) -> *AssetManagerJ; } -AssetManagerJ :: #foreign #jni_class("android/content/res/AssetManager") { } +AssetManagerJ :: #jni_class("android/content/res/AssetManager") extern { } -Surface :: #foreign #jni_class("android/view/Surface") { } -SurfaceHolder :: #foreign #jni_class("android/view/SurfaceHolder") { +Surface :: #jni_class("android/view/Surface") extern { } +SurfaceHolder :: #jni_class("android/view/SurfaceHolder") extern { getSurface :: (self: *Self) -> *Surface; addCallback :: (self: *Self, cb: *SurfaceHolderCallback); } -SurfaceView :: #foreign #jni_class("android/view/SurfaceView") { +SurfaceView :: #jni_class("android/view/SurfaceView") extern { new :: (ctx: *JContext) -> *Self; // no `self: *Self` → class method getHolder :: (self: *Self) -> *SurfaceHolder; } -SurfaceHolderCallback :: #foreign #jni_class("android/view/SurfaceHolder$Callback") { } +SurfaceHolderCallback :: #jni_class("android/view/SurfaceHolder$Callback") extern { } -MotionEvent :: #foreign #jni_class("android/view/MotionEvent") { +MotionEvent :: #jni_class("android/view/MotionEvent") extern { getAction :: (self: *Self) -> i32; getX :: (self: *Self) -> f32; getY :: (self: *Self) -> f32; } -JView :: #foreign #jni_class("android/view/View") { } -ActivityClass :: #foreign #jni_class("android/app/Activity") { +JView :: #jni_class("android/view/View") extern { } +ActivityClass :: #jni_class("android/app/Activity") extern { setContentView :: (self: *Self, v: *JView); } @@ -70,25 +70,25 @@ ActivityClass :: #foreign #jni_class("android/app/Activity") { // C side of file_utils — installs the AAssetManager so `read_file_bytes` // can route through `AAssetManager_open` when running on Android. -sx_android_set_asset_manager :: (mgr: *void) #foreign; +sx_android_set_asset_manager :: (mgr: *void) extern; -__android_log_print :: (prio: i32, tag: *u8, fmt: *u8) -> i32 #foreign; -usleep :: (us: u32) -> i32 #foreign; +__android_log_print :: (prio: i32, tag: *u8, fmt: *u8) -> i32 extern; +usleep :: (us: u32) -> i32 extern; // libandroid -ANativeWindow_fromSurface :: (env: *void, surface: *void) -> *void #foreign; -ANativeWindow_release :: (window: *void) #foreign; -ANativeWindow_getWidth :: (window: *void) -> i32 #foreign; -ANativeWindow_getHeight :: (window: *void) -> i32 #foreign; -ANativeWindow_setBuffersGeometry :: (w: *void, width: i32, height: i32, fmt: i32) -> i32 #foreign; +ANativeWindow_fromSurface :: (env: *void, surface: *void) -> *void extern; +ANativeWindow_release :: (window: *void) extern; +ANativeWindow_getWidth :: (window: *void) -> i32 extern; +ANativeWindow_getHeight :: (window: *void) -> i32 extern; +ANativeWindow_setBuffersGeometry :: (w: *void, width: i32, height: i32, fmt: i32) -> i32 extern; -AAssetManager_fromJava :: (env: *void, mgr: *void) -> *void #foreign; +AAssetManager_fromJava :: (env: *void, mgr: *void) -> *void extern; // pthread (link libpthread is built into bionic). -pthread_create :: (thread: *u64, attr: *void, start: (*void) -> *void callconv(.c), arg: *void) -> i32 #foreign; -pthread_mutex_init :: (m: *void, attr: *void) -> i32 #foreign; -pthread_mutex_lock :: (m: *void) -> i32 #foreign; -pthread_mutex_unlock :: (m: *void) -> i32 #foreign; +pthread_create :: (thread: *u64, attr: *void, start: (*void) -> *void callconv(.c), arg: *void) -> i32 extern; +pthread_mutex_init :: (m: *void, attr: *void) -> i32 extern; +pthread_mutex_lock :: (m: *void) -> i32 extern; +pthread_mutex_unlock :: (m: *void) -> i32 extern; // EGL. Constants from . We bring up an ES3 context with a // 24-bit RGB framebuffer + 24-bit depth (same shape chess used under @@ -112,17 +112,17 @@ EGL_WINDOW_BIT :i32: 0x0004; EGL_NATIVE_VISUAL_ID :i32: 0x302E; EGL_CONTEXT_CLIENT_VERSION :i32: 0x3098; -eglGetDisplay :: (id: u64) -> *void #foreign; -eglInitialize :: (d: *void, major: *i32, minor: *i32) -> u32 #foreign; -eglChooseConfig :: (d: *void, attrs: *i32, configs: **void, sz: i32, num: *i32) -> u32 #foreign; -eglGetConfigAttrib :: (d: *void, cfg: *void, attr: i32, value: *i32) -> u32 #foreign; -eglCreateContext :: (d: *void, cfg: *void, share: *void, attrs: *i32) -> *void #foreign; -eglCreateWindowSurface :: (d: *void, cfg: *void, window: *void, attrs: *i32) -> *void #foreign; -eglMakeCurrent :: (d: *void, draw: *void, read: *void, ctx: *void) -> u32 #foreign; -eglSwapBuffers :: (d: *void, surface: *void) -> u32 #foreign; -eglDestroyContext :: (d: *void, ctx: *void) -> u32 #foreign; -eglDestroySurface :: (d: *void, surface: *void) -> u32 #foreign; -eglTerminate :: (d: *void) -> u32 #foreign; +eglGetDisplay :: (id: u64) -> *void extern; +eglInitialize :: (d: *void, major: *i32, minor: *i32) -> u32 extern; +eglChooseConfig :: (d: *void, attrs: *i32, configs: **void, sz: i32, num: *i32) -> u32 extern; +eglGetConfigAttrib :: (d: *void, cfg: *void, attr: i32, value: *i32) -> u32 extern; +eglCreateContext :: (d: *void, cfg: *void, share: *void, attrs: *i32) -> *void extern; +eglCreateWindowSurface :: (d: *void, cfg: *void, window: *void, attrs: *i32) -> *void extern; +eglMakeCurrent :: (d: *void, draw: *void, read: *void, ctx: *void) -> u32 extern; +eglSwapBuffers :: (d: *void, surface: *void) -> u32 extern; +eglDestroyContext :: (d: *void, ctx: *void) -> u32 extern; +eglDestroySurface :: (d: *void, surface: *void) -> u32 extern; +eglTerminate :: (d: *void) -> u32 extern; // ── Touch ring ────────────────────────────────────────────────────────── diff --git a/library/modules/platform/android_jni.sx b/library/modules/platform/android_jni.sx index 2e9a26b..2f4ea5b 100644 --- a/library/modules/platform/android_jni.sx +++ b/library/modules/platform/android_jni.sx @@ -11,21 +11,21 @@ // signatures (`getWindow :: (self: *Self) -> *Window`) still resolve // against the bare name within the namespace. -WindowInsets :: #foreign #jni_class("android/view/WindowInsets") { +WindowInsets :: #jni_class("android/view/WindowInsets") extern { getSystemWindowInsetTop :: (self: *Self) -> i32; getSystemWindowInsetLeft :: (self: *Self) -> i32; getSystemWindowInsetBottom :: (self: *Self) -> i32; getSystemWindowInsetRight :: (self: *Self) -> i32; } -View :: #foreign #jni_class("android/view/View") { +View :: #jni_class("android/view/View") extern { getRootWindowInsets :: (self: *Self) -> *WindowInsets; } -Window :: #foreign #jni_class("android/view/Window") { +Window :: #jni_class("android/view/Window") extern { getDecorView :: (self: *Self) -> *View; } -Activity :: #foreign #jni_class("android/app/Activity") { +Activity :: #jni_class("android/app/Activity") extern { getWindow :: (self: *Self) -> *Window; } diff --git a/library/modules/platform/sdl3.sx b/library/modules/platform/sdl3.sx index 35258c8..5dd0631 100644 --- a/library/modules/platform/sdl3.sx +++ b/library/modules/platform/sdl3.sx @@ -11,8 +11,8 @@ g_sdl_plat : *SdlPlatform = null; -chdir :: (path: [*]u8) -> i32 #foreign; -SDL_GetBasePath :: () -> [*]u8 #foreign; +chdir :: (path: [*]u8) -> i32 extern; +SDL_GetBasePath :: () -> [*]u8 extern; // A macOS `.app` launched via Finder / `open` starts with CWD=`/`, so a // game's CWD-relative asset loads (`read_file_bytes("assets/...")`) miss and diff --git a/library/modules/platform/uikit.sx b/library/modules/platform/uikit.sx index bdbac23..bd1900d 100644 --- a/library/modules/platform/uikit.sx +++ b/library/modules/platform/uikit.sx @@ -15,14 +15,14 @@ #import "modules/platform/types.sx"; #import "modules/platform/api.sx"; -UIApplicationMain :: (argc: i32, argv: *void, principal_class: *NSString, delegate_class: *NSString) -> i32 #foreign; -dlsym :: (handle: *void, name: [*]u8) -> *void #foreign; -chdir :: (path: [*]u8) -> i32 #foreign; +UIApplicationMain :: (argc: i32, argv: *void, principal_class: *NSString, delegate_class: *NSString) -> i32 extern; +dlsym :: (handle: *void, name: [*]u8) -> *void extern; +chdir :: (path: [*]u8) -> i32 extern; // QuartzCore's wall-clock helper used by CoreAnimation. Seconds since boot, // monotonic. We use it as the timebase for keyboard-inset lockstep so the // per-frame interpolation lines up with UIKit's own animation timestamp. -CACurrentMediaTime :: () -> f64 #foreign; +CACurrentMediaTime :: () -> f64 extern; // kEAGLRenderingAPIOpenGLES3 = 3 @@ -58,13 +58,13 @@ CGRect :: struct { // side name maps to its Obj-C selector via the default mangling rule // (split on `_`; each piece becomes a keyword with `:`). -NSValue :: #foreign #objc_class("NSValue") { +NSValue :: #objc_class("NSValue") extern { #extends NSObject; // CGRect unboxing — returns by value via the sret/HFA path. CGRectValue :: (self: *Self) -> CGRect; } -NSNumber :: #foreign #objc_class("NSNumber") { +NSNumber :: #objc_class("NSNumber") extern { #extends NSObject; // Class method (no `self: *Self` first param → static dispatch). numberWithBool :: (b: i8) -> *NSNumber; @@ -73,36 +73,36 @@ NSNumber :: #foreign #objc_class("NSNumber") { unsignedLongValue :: (self: *Self) -> u64; } -NSDictionary :: #foreign #objc_class("NSDictionary") { +NSDictionary :: #objc_class("NSDictionary") extern { #extends NSObject; objectForKey :: (self: *Self, key: *NSString) -> *void; } -NSMutableDictionary :: #foreign #objc_class("NSMutableDictionary") { +NSMutableDictionary :: #objc_class("NSMutableDictionary") extern { #extends NSDictionary; dictionary :: () -> *NSMutableDictionary; setObject_forKey :: (self: *Self, obj: *void, key: *void); } -NSSet :: #foreign #objc_class("NSSet") { +NSSet :: #objc_class("NSSet") extern { #extends NSObject; anyObject :: (self: *Self) -> *void; } // ── Notifications + Bundle (Phase 3.2 C2) ────────────────────────────── -NSNotification :: #foreign #objc_class("NSNotification") { +NSNotification :: #objc_class("NSNotification") extern { #extends NSObject; userInfo :: (self: *Self) -> *NSDictionary; } -NSBundle :: #foreign #objc_class("NSBundle") { +NSBundle :: #objc_class("NSBundle") extern { #extends NSObject; mainBundle :: () -> *NSBundle; resourcePath :: (self: *Self) -> *NSString; } -NSNotificationCenter :: #foreign #objc_class("NSNotificationCenter") { +NSNotificationCenter :: #objc_class("NSNotificationCenter") extern { #extends NSObject; defaultCenter :: () -> *NSNotificationCenter; addObserver_selector_name_object :: (self: *Self, observer: *void, sel: *void, name: *NSString, obj: *void); @@ -110,12 +110,12 @@ NSNotificationCenter :: #foreign #objc_class("NSNotificationCenter") { // ── RunLoop + display timing (Phase 3.2 C3) ──────────────────────────── -NSRunLoop :: #foreign #objc_class("NSRunLoop") { +NSRunLoop :: #objc_class("NSRunLoop") extern { #extends NSObject; currentRunLoop :: () -> *NSRunLoop; } -CADisplayLink :: #foreign #objc_class("CADisplayLink") { +CADisplayLink :: #objc_class("CADisplayLink") extern { #extends NSObject; displayLinkWithTarget_selector :: (target: *void, sel: *void) -> *CADisplayLink; addToRunLoop_forMode :: (self: *Self, runloop: *NSRunLoop, mode: *NSString); @@ -126,23 +126,23 @@ CADisplayLink :: #foreign #objc_class("CADisplayLink") { // ── View tree + GL drawables (Phase 3.2 C5) ──────────────────────────── // (Declared before UIView so `layer :: (...) -> *CALayer` can reference it.) -CALayer :: #foreign #objc_class("CALayer") { +CALayer :: #objc_class("CALayer") extern { #extends NSObject; setOpaque :: (self: *Self, opaque: i8); } -CAEAGLLayer :: #foreign #objc_class("CAEAGLLayer") { +CAEAGLLayer :: #objc_class("CAEAGLLayer") extern { #extends CALayer; class :: () -> *void; setDrawableProperties :: (self: *Self, props: *void); } -CAMetalLayer :: #foreign #objc_class("CAMetalLayer") { +CAMetalLayer :: #objc_class("CAMetalLayer") extern { #extends CALayer; class :: () -> *void; } -EAGLContext :: #foreign #objc_class("EAGLContext") { +EAGLContext :: #objc_class("EAGLContext") extern { #extends NSObject; alloc :: () -> *EAGLContext; initWithAPI :: (self: *Self, api: i32) -> *EAGLContext; @@ -153,7 +153,7 @@ EAGLContext :: #foreign #objc_class("EAGLContext") { // ── UIKit chrome (Phase 3.2 C4) ──────────────────────────────────────── -UIScreen :: #foreign #objc_class("UIScreen") { +UIScreen :: #objc_class("UIScreen") extern { #extends NSObject; mainScreen :: () -> *UIScreen; nativeScale :: (self: *Self) -> f64; @@ -164,13 +164,13 @@ UIScreen :: #foreign #objc_class("UIScreen") { // Most UIKit classes inherit from it; sx-defined classes that // participate in lifecycle callbacks (delegates, scene delegates) // extend it so the runtime picks up the responder-chain behavior. -UIResponder :: #foreign #objc_class("UIResponder") { +UIResponder :: #objc_class("UIResponder") extern { #extends NSObject; becomeFirstResponder :: (self: *Self) -> i8; resignFirstResponder :: (self: *Self) -> i8; } -UIView :: #foreign #objc_class("UIView") { +UIView :: #objc_class("UIView") extern { #extends UIResponder; safeAreaInsets :: (self: *Self) -> UIEdgeInsets; addSubview :: (self: *Self, view: *void); @@ -178,7 +178,7 @@ UIView :: #foreign #objc_class("UIView") { setContentScaleFactor :: (self: *Self, scale: f64); } -UIWindow :: #foreign #objc_class("UIWindow") { +UIWindow :: #objc_class("UIWindow") extern { #extends UIView; alloc :: () -> *UIWindow; initWithWindowScene :: (self: *Self, scene: *void) -> *UIWindow; @@ -187,14 +187,14 @@ UIWindow :: #foreign #objc_class("UIWindow") { screen :: (self: *Self) -> *UIScreen; } -UIViewController :: #foreign #objc_class("UIViewController") { +UIViewController :: #objc_class("UIViewController") extern { #extends UIResponder; alloc :: () -> *UIViewController; init :: (self: *Self) -> *UIViewController; setView :: (self: *Self, view: *void); } -UITextField :: #foreign #objc_class("UITextField") { +UITextField :: #objc_class("UITextField") extern { #extends UIResponder; alloc :: () -> *UITextField; init :: (self: *Self) -> *UITextField; @@ -203,7 +203,7 @@ UITextField :: #foreign #objc_class("UITextField") { // SxAppDelegate — UIApplicationMain's delegate class (the app delegate, a // UIResponder — NOT the UIApplication principal class). Method bodies // dispatch to UIKitPlatform methods on the shared `g_uikit_plat`. -SxAppDelegate :: #objc_class("SxAppDelegate") { +SxAppDelegate :: #objc_class("SxAppDelegate") export { #extends UIResponder; application_didFinishLaunchingWithOptions :: (self: *Self, app: *void, opts: *void) -> BOOL { @@ -233,7 +233,7 @@ SxAppDelegate :: #objc_class("SxAppDelegate") { // SxSceneDelegate — iOS 13+ scene-based lifecycle delegate. Two // `#implements` declarations formally conform to the scene-delegate // protocols — iOS rejects the class otherwise. -SxSceneDelegate :: #objc_class("SxSceneDelegate") { +SxSceneDelegate :: #objc_class("SxSceneDelegate") export { #extends UIResponder; #implements UISceneDelegate; #implements UIWindowSceneDelegate; @@ -827,7 +827,7 @@ uikit_chdir_to_bundle :: () { // M3.3 — migrated to declarative `#objc_class` form. The compiler // synthesises class-pair init, metaclass `+layerClass`, and the // instance-method IMP trampolines at module init. -SxGLView :: #objc_class("SxGLView") { +SxGLView :: #objc_class("SxGLView") export { #extends UIView; layerClass :: () => CAEAGLLayer.class(); @@ -886,7 +886,7 @@ uikit_first_touch :: (touches: *void) -> *void { // // M3.4 — migrated to declarative `#objc_class`. Only `+layerClass` // differs from SxGLView (returns CAMetalLayer instead of CAEAGLLayer). -SxMetalView :: #objc_class("SxMetalView") { +SxMetalView :: #objc_class("SxMetalView") export { #extends UIView; layerClass :: () => CAMetalLayer.class();