objk iconmacOS arm64

objk

Objective-K — a Krypton ↔ Objective-C / Cocoa bridge built into the Mach-O backend. It lets pure Krypton programs call macOS AppKit & Foundation directly, so a real native GUI app can ship with no Obj-C, no Swift source. It is what stem and brain are built on.

How it worksView stdlib

Krypton calling Cocoa, with no Objective-C

The backend dyld-binds libobjc / Foundation / AppKit, then lowers a small family of objc_msgSend calls. Krypton's register calling convention already matches the arm64 ABI, so a Krypton function is usable directly as an Objective-C method IMP — that is how callbacks, data sources and delegates work.

objc_msgSend family

Dispatch wrappers for 0–6 args, plus NSRect (d0–d3), CGFloat, NSSize, NSPoint+ptr, 256-colour RGBA, and NSTimer variants — each one is a tiny lowering in the backend.

Funcs as IMPs

A Krypton func onClick(self, cmd, sender) is registered with class_addMethod and called by Cocoa with no shim. Multi-method delegates (table data sources, text-storage) work the same way.

Runtime class synthesis

Build Obj-C classes at runtime (objc_allocateClassPair) whose methods are Krypton funcs — custom NSViews with drawRect:, delegates, targets.

Ergonomic stdlib

stdlib/cocoa.k + stdlib/objc.k wrap it: windows, buttons, text views, tables, menus, colours, fonts, timers — msg(obj, "setTitle:", nsString(s)) reads like Swift.

Strings are C strings

Krypton strings are NUL-terminated, so a string literal IS a valid char* — no marshalling to pass selectors, class names or text to Cocoa.

Self-host safe

Programs with no foreign calls stay byte-identical (N=0 invariant), so adding the FFI never disturbs the bootstrapping compiler.

What it powers

Real, shipping apps — not demos:

stem · a terminal (NSWindow + grid + pty). brain · an IDE (NSTextView, NSTableView, tabs, menus). Both pure Krypton.