text_fonts

module pkg::alloy::objcsource

Objective-C from Alloy (PLAN.md, F7), the package pkg::alloy::objc: the runtime's C functions, loaded while running, for AppKit and Metal on Apple systems. Every message is objc_msgSend read as the method's exact C prototype (F0 question 4), so arguments pass as the method declares them:

const set_frame = o.send<extern (c_pointer, c_pointer, Rect, bool)>();
set_frame(window, o.sel(&"setFrame:display:"), frame, true);

Classes the system calls back into are made while running, their methods C functions (lambdas capturing nothing) or blocks holding the Alloy value they reach, and their objects may keep a c_pointer of their own in an instance variable. Blocks, the callbacks some APIs take, are built in the blocks ABI's layout as global blocks, which the runtime never copies. On Linux the same functions come from GNUstep's runtime (libobjc2), which the tests run this module against.

## How it was built

Notes kept from each stage as it was finished, the sizes and numbers of their day; what changed since is in REVIEW.md and the history.

Built in F7a inside window and moved here in F7b: see pkg::alloy::window's notes.

type Objcsource

exp type Objc = struct

The runtime's functions, and objc_msgSend's addresses, read as a prototype per call.

Fields

exp library: Library
exp message: c_pointer

objc_msgSend

exp message_struct: c_pointer

objc_msgSend_stret on x86-64, objc_msgSend on ARM64

exp get_class: extern (c_string) -> c_pointer
exp register_selector: extern (c_string) -> c_pointer
exp allocate_class: extern (c_pointer, c_string, c_size) -> c_pointer
exp register_class: extern (c_pointer)
exp add_method: extern (c_pointer, c_pointer, c_pointer, c_string) -> bool
exp add_ivar: extern (c_pointer, c_string, c_size, u8, c_string) -> bool
exp instance_variable: extern (c_pointer, c_string) -> c_pointer
exp ivar_offset: extern (c_pointer) -> c_ssize
exp class_of: extern (c_pointer) -> c_pointer
exp get_protocol: extern (c_string) -> c_pointer
exp add_protocol: extern (c_pointer, c_pointer) -> bool
exp pool_push: extern () -> c_pointer
exp pool_pop: extern (c_pointer)
exp global_block: c_pointer

_NSConcreteGlobalBlock's address

exp block_method: extern (c_pointer) -> c_pointer

imp_implementationWithBlock

exp block_of: extern (c_pointer) -> c_pointer

imp_getBlock

exp implementation: extern (c_pointer, c_pointer) -> c_pointer

class_getMethodImplementation

Functions

fn Objc::loadsource

exp fn Objc::load() -> Option<Objc>

The runtime, or None where it cannot be loaded.

fn requiredsource

exp fn required<F: CFunction>(library: &Library, name: &[u8]) -> F

The library's function of that name, as the C prototype F; a library lacking it is older than any this package supports.

fn address_ofsource

exp fn address_of(library: &Library, name: &[u8]) -> c_pointer

The address of a library's symbol, a function or data; 0 when it has none. Data symbols (_NSConcreteGlobalBlock, AppKit's string constants) come through symbol read as a function, whose value is the address alone.

fn pointer_atsource

exp fn pointer_at(library: &Library, name: &[u8]) -> c_pointer

The value a data symbol holds, a pointer: AppKit's NSString * constants, 0 when the library has no such symbol.

fn sendsource

exp fn send<F: CFunction>(self o: &Objc) -> F

objc_msgSend as the prototype F, whose first two parameters are the receiver and the selector.

fn send_structsource

exp fn send_struct<F: CFunction>(self o: &Objc) -> F

objc_msgSend for a method returning a struct larger than 16 bytes (NSRect), as the prototype F.

fn selsource

exp fn sel(self o: &Objc, name: &[u8]) -> c_pointer

The selector of the name, setFrame:display:. Names shorter than 128 bytes, every one used, take their NUL in a buffer on the stack, so no message allocates.

fn classsource

exp fn class(self o: &Objc, name: &[u8]) -> c_pointer

The class of the name, 0 when none is loaded.

fn callsource

exp fn call(self o: &Objc, receiver: c_pointer, selector: &[u8]) -> c_pointer

A message taking nothing and giving an object: [x alloc], [x init].

fn call_withsource

exp fn call_with(
    self o: &Objc,
    receiver: c_pointer,
    selector: &[u8],
    argument: c_pointer
) -> c_pointer

A message taking an object and giving one.

fn call_integersource

exp fn call_integer(
    self o: &Objc,
    receiver: c_pointer,
    selector: &[u8],
    argument: u64
) -> c_pointer

A message taking an integer (NSInteger, NSUInteger, a BOOL widened) and giving an object or nothing.

fn call_boolsource

exp fn call_bool(self o: &Objc, receiver: c_pointer, selector: &[u8], argument: bool)

A message taking a BOOL.

fn integersource

exp fn integer(self o: &Objc, receiver: c_pointer, selector: &[u8]) -> u64

A message giving an integer (NSInteger, NSUInteger).

fn booleansource

exp fn boolean(self o: &Objc, receiver: c_pointer, selector: &[u8]) -> bool

A message giving a BOOL.

fn numbersource

exp fn number(self o: &Objc, receiver: c_pointer, selector: &[u8]) -> f64

A message giving a double (CGFloat, NSTimeInterval).

fn makesource

exp fn make(self o: &Objc, class: c_pointer) -> c_pointer

[[class alloc] init].

fn releasesource

exp fn release(self o: &Objc, object: c_pointer)

fn stringsource

exp fn string(self o: &Objc, text: &[u8]) -> c_pointer

An autoreleased NSString of the UTF-8 text.

fn text_ofsource

exp fn text_of(self o: &Objc, string: c_pointer) -> String

An NSString's text as UTF-8; empty for nil.

type NewClasssource

exp type NewClass = struct

A new class of the name below the superclass, to give methods and register; the class already registered under that name when there is one (a second window in the same process), which is_new tells.

Fields

exp class: c_pointer
exp is_new: bool

fn subclasssource

exp fn subclass(self o: &Objc, name: &[u8], superclass: c_pointer) -> NewClass

fn methodsource

exp fn method<F: CFunction>(self o: &Objc, class: c_pointer, selector: &[u8], types: &[u8], f: F)

Adds the method, a C function taking the receiver and the selector first, whose types are written as the runtime encodes them (v@:@).

fn method_withsource

exp fn method_with<F: CFunction>(
    self o: &Objc,
    class: c_pointer,
    selector: &[u8],
    types: &[u8],
    invoke: F,
    state: c_pointer
) -> c_pointer

Adds the method as a block holding state: the block's function is called with the block, the receiver and the method's arguments (no selector), and reads the state back with block_state. A class's methods reach the Alloy value that made it this way. Gives the block, which free_block frees once the class is no longer used; a class made for the process keeps its blocks.

fn add_statesource

exp fn add_state(self o: &Objc, class: c_pointer)

Adds the instance variable holding the object's Alloy state, before the class is registered.

fn adoptsource

exp fn adopt(self o: &Objc, class: c_pointer, protocol: &[u8])

fn statesource

exp fn state(self o: &Objc, object: c_pointer) -> c_pointer

The state kept in an object of a class add_state gave a place for.

fn set_statesource

exp fn set_state(self o: &Objc, object: c_pointer, state: c_pointer)

fn blocksource

exp fn block<F: CFunction>(self o: &Objc, invoke: F, state: c_pointer) -> c_pointer

A block calling invoke with itself and the arguments the caller passes, holding state.

fn struct_blocksource

exp fn struct_block<F: CFunction>(
    self o: &Objc,
    invoke: F,
    state: c_pointer,
    signature: &[u8]
) -> c_pointer

A block whose function gives a struct too large for registers, which x86-64 returns through memory: the block says so (BLOCK_USE_STRET and its signature, as clang writes them), so a method made of it is called through objc_msgSend_stret. signature is the block's type encoding.

fn block_signaturesource

exp fn block_signature(method_types: &[u8]) -> String

A block's type encoding from a method's ({CGRect=...}@:{_NSRange=QQ} gives {CGRect=...}@?@{_NSRange=QQ}): the block, then the receiver, with no selector.

fn struct_method_withsource

exp fn struct_method_with<F: CFunction>(
    self o: &Objc,
    class: c_pointer,
    selector: &[u8],
    types: &[u8],
    invoke: F,
    state: c_pointer
) -> c_pointer

Adds the method as a block, as method_with, for one returning a struct larger than 16 bytes (NSRect).

fn bool_codesource

exp fn bool_code() -> &[u8]

BOOL's type encoding: B on ARM64, where it is C's bool, c on x86-64, where it is a signed char.

fn block_statesource

exp fn block_state(block: c_pointer) -> c_pointer

The state a block holds, read by its function.

fn free_blocksource

exp fn free_block(block: c_pointer)

Frees a block block made, once nothing calls it any more.

fn method_blocksource

exp fn method_block(self o: &Objc, class: c_pointer, selector: &[u8]) -> c_pointer

The block a method method_with added runs, 0 for another kind.

fn lastingsource

exp fn lasting(size: u64) -> c_pointer

C's heap, for values the runtime holds past what Alloy's ownership sees: zeroed bytes, never freed.