Files
scriptc/examples/native-object
Malte Ubl fa55ce6b07 Keep the RC entry points of array elements in one shared descriptor
Every SCR_ELEM_REF array stored its element type's retain, release and trace entry points in its own header (24 bytes), so ScrArr was 80 bytes: an 80-byte block for arrays of acyclic elements and a 96-byte block for cycle-capable ones. The three pointers now live in one constant ScrArrOps descriptor per element type, which the compiler emits once per module (@sc_arrops.*) and the runtime keeps static, and the header holds a pointer to it plus a 4-byte `cyc` flag beside `elem` that the inline RC fast paths test. ScrArr is 64 bytes: arrays take 64- and 80-byte blocks.

scr_arr_new_ref(retain, release, trace, cap) becomes scr_arr_new_ops(ops, cap); scr_set_to_arr_ref takes the result's descriptor from its caller instead of building an array from the set's key adapters. The backend names the %ScrArr fields in SCR_ARR_FIELD. The layout change bumps the runtime ABI marker to scr_runtime_abi_v13.
2026-10-11 19:46:48 -07:00
..
2026-09-29 20:54:09 -05:00

External program object

This macOS arm64 example links a scriptc program object, a small C FFI implementation, and the exact installed precompiled runtime pack. It uses no scriptc cache path.

$ clang -target arm64-apple-macosx14.0.0 -O2 -c native.c -o native.o
$ scriptc build main.ts --ffi ffi.json --print=native-link-info -o app.o > link-info.json
$ node link.mjs cc link-info.json app-cc
$ ./app-cc
42
$ node link.mjs ld link-info.json app-ld
$ ./app-ld
42

cc uses the C compiler as a linker driver. ld links the same precompiled runtime objects directly with the selected Apple SDK. The object defines main; it is a complete program object, not a library to load into another process. Use scriptc build --lib --profile ... for a host-callable static library.

The external object ABI is experimental. Always consume the runtime pack at the exact runtime_pack.version reported by the same scriptc installation. The object requires scr_runtime_abi_v13, so a mismatched runtime fails during the link instead of starting with an incompatible ABI.