x-lang

← Index

x/type/obj

Raw object layer: construction, slot and metadata access, FFI handles, on the Obj class.

ns obj is de-registered – no bare names; boot/hot callers fetch from the catalog.

Class Obj

(Obj make ts n)

Allocate a raw typed object with N nil slots (the Vector pattern: slot 0 = length).

GC CONTRACT: raw slots are traced only if the TYPE declares units – ((prim-ref ‘type ‘set-units!) ts -1) for slot-0-counted sizes (the Vector convention), or a fixed count. Without it a collect frees the payloads under the object (the Dict-across-a-REPL-turn segfault class).

Parameters:

Returns: ANY — The new object

(Obj ref obj i)

Read slot I of a raw object.

Parameters:

Returns: ANY — The slot value

(Obj set! obj i v)

Write slot I of a raw object.

Parameters:

Returns: ANY — nil

(Obj ->ptr obj)

The raw pointer of an object (FFI handle; see also Ptr).

Parameters:

Returns: ANY — A PTR to the object’s storage

(Obj meta-count)

The base-wide extra-metadata slot count (0 = metadata disabled).

Returns: INT — Current extra-slot count

(Obj meta-count! n)

Set the base-wide extra-metadata slot count; objects allocated afterwards carry N extra slots. BOOT-TIME POLICY: setting a width DIFFERENT from the current one while allocated objects are live is undefined – the engine frees each object’s prefix at the width current at COLLECT time, so older objects are freed at the wrong address (x-engine-c#21). Setting the value it already holds is safe.

Parameters:

Returns: INT — The previous extra-slot count

(Obj meta-ref obj i)

Read metadata slot I of an object (e.g. coverage flags, source line).

Parameters:

Returns: ANY — The metadata value

(Obj meta-set! obj i v)

Write metadata slot I of an object.

Parameters:

Returns: ANY — nil

(Obj make-callable p)

Wrap a C function pointer as a callable primitive object.

Parameters:

Returns: CALLABLE — The new callable