GizStack
View .mdOpen in ChatGPTOpen in Claude

gizlang/objc

Objective-C's runtime as a macOS process has it, through gizlang/native, so nothing links at build time. Its users (gizlang/window's macOS window, gizhw/metal) call what Objc gives: system gives the runtime's own, a test gives a fake that records the calls. A message is integer words: the target, the selector, then each integer or pointer argument; a floating-point or struct value goes through key-value coding and NSValue instead (Objc.box, Objc.unbox), so no call depends on how an ABI passes a double or a struct.

gizlang
import * as Objc from "gizlang/objc";

Types

Objc

gizlang
type Objc = { send: (words: Vec<u64>) => u64 effects {io, fail, read, write}; selector: (name: string) => u64 effects {io, fail, read, write}; find: (name: string) => u64 effects {io, fail, read, write}; push: () => u64 effects {io, fail, read, write}; pop: (pool: u64) => void effects {io, fail, read, write}; text: (address: u64) => string effects {io, fail, read, write}; sendAddress: u64; freeAddress: u64; }

Objective-C's runtime. send is objc_msgSend (words: target, selector, integer arguments); selector is sel_registerName, find objc_getClass, push and pop an autorelease pool; text is the C string at an address. sendAddress and freeAddress are objc_msgSend and free, the functions a Gizlang value can own memory with.

  • send: (arg0: Vec<u64>) => u64 effects { fail, read, write, io }
  • selector: (arg0: string) => u64 effects { fail, read, write, io }
  • find: (arg0: string) => u64 effects { fail, read, write, io }
  • push: () => u64 effects { fail, read, write, io }
  • pop: (arg0: u64) => void effects { fail, read, write, io }
  • text: (arg0: u64) => string effects { fail, read, write, io }
  • sendAddress: u64
  • freeAddress: u64

Functions

system

gizlang
function system(nat: Native): Option<Objc>

Objective-C's runtime as this process has it, or none (not macOS).

Effects: fail, io, alloc.

Methods

Objc.call

gizlang
function Objc.call(self: Objc, target: u64, selector: string, arguments: Vec<u64> = []): u64

The message SELECTOR (a name) to TARGET with integer ARGUMENTS.

Effects: fail, read, write, io, alloc.

Objc.string

gizlang
function Objc.string(self: Objc, nat: Native, text: string): u64

A new NSString of TEXT, autoreleased.

Effects: fail, read, write, io, alloc.

Objc.box

gizlang
function Objc.box(self: Objc, nat: Native, value: bytes, type: string): u64

An NSValue of the bytes VALUE whose Objective-C type is TYPE ({CGSize=dd}), autoreleased: how a struct or a double reaches a setter by key-value coding.

Effects: fail, read, write, io, alloc.

Objc.unbox

gizlang
function Objc.unbox(self: Objc, nat: Native, target: u64, key: string, size: i64): bytes

The SIZE bytes of the property KEY of TARGET, read by key-value coding: a struct or a number, boxed by the getter and copied out of its NSValue.

Effects: fail, read, write, io, alloc.