ZX revision 30 runs ordinary main(argc, argv) programs unchanged: the guest sees its own bundle as its executable, checked program exports link to their foreign declarations, and declared native support libraries travel as verified bundle assets with per-target library and symbol mappings. Linux x86-64 bridges variadic and indirect C calls, callbacks from native threads, naturally aligned records and checked C pointers. Each native entry keeps its runtime state in R13, so packaged runtimes load after threads start without static TLS; inline assembly meters fuel through the same prefix. Authored C free and realloc accept runtime builder storage, checked TextFromCString measures C strings through libc strlen, and copied deferred cleanup loops keep their own identities. Pointer-type interning removes repeated full-table scans in large programs. Runtime ABI 3, machine image 4 and lowered schema 7 require fresh bundles and native caches. Bootstrap seeds refreshed for 89 roots.
37 lines
1.0 KiB
Ziran
37 lines
1.0 KiB
Ziran
// Borrow UTF-8 bytes as a Ziran string at native foreign-function boundaries.
|
|
// The caller must keep the byte storage alive while the string is in use.
|
|
TextDescriptor :: struct {
|
|
data: *u8
|
|
length: usize
|
|
}
|
|
|
|
ByteDescriptor :: struct {
|
|
data: *u8
|
|
length: s64
|
|
}
|
|
|
|
#program_export
|
|
TextFromBytes :: (buffer: []u8) -> string {
|
|
return TextView(buffer)
|
|
}
|
|
|
|
// Borrow native storage at a foreign-function boundary. The caller must keep
|
|
// it allocated and writable throughout the slice's use.
|
|
#program_export
|
|
BytesFromPointer :: (data: *u8, count: u64) -> []u8 {
|
|
result: []u8
|
|
if data == null || count > cast(u64)9223372036854775807 { return result }
|
|
return data[0:cast(s64)count]
|
|
}
|
|
|
|
libc :: #system_library "c";
|
|
CStringLengthRaw :: (value: *u8) -> usize #reads #foreign libc "strlen";
|
|
|
|
// The returned string borrows the C buffer and retains its lifetime.
|
|
#program_export
|
|
TextFromCString :: (value: *u8) -> string {
|
|
if value == null { return "" }
|
|
length := CStringLengthRaw(value)
|
|
return TextView(value[0:cast(s64)length])
|
|
}
|