Files
ziran/tests/callback_record_layout.sh
T
waozi da76a21675 Remove the C++, Rust and Plan 9 targets
Ziran now generates C, Go, Python and portable .zx. zi2cpp, zi2rust, the
C++ mode of the shared C emitter, the Plan 9 post-pass and the std Plan 9
modules are gone; --target=cpp|rust|plan9-c and zi2c --plan9 are rejected
as unknown targets. Generated C headers keep avoiding C++ keywords in
exported names, so C++ hosts can still include them.
2026-10-24 00:57:29 -03:00

37 lines
1.2 KiB
Bash

#!/bin/sh
set -eu
repo=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
bin=$(dirname "${1:-$repo/build/bin/ziran}")
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT HUP INT TERM
cat > "$work/packet.zi" <<'ZI'
Packet :: struct { guard: u64; value: s32; trailer: u64; }
ZI
cat > "$work/app.zi" <<'ZI'
#import "packet"
Visit :: #type (packet: *Packet) -> s32 #c_call;
Envelope :: struct { callback: Visit; }
native :: #system_library "native";
Submit :: (envelope: Envelope) -> s32 #foreign native;
Read :: (packet: *Packet) -> s32 { return packet.value }
#program_export
Answer :: () -> s32 {
envelope: Envelope
envelope.callback = Read
return Submit(envelope)
}
ZI
"$bin/zi2c" --no-main --entry app:Answer --root "$work" -o "$work/c" "$work/app.zi"
cat > "$work/c/host.c" <<'C'
#include "app.h"
_Static_assert(sizeof(Packet) == 24, "Native callbacks must retain the complete record ABI");
int32_t Submit(Envelope envelope) {
Packet packet = {99, 42, 1};
return envelope.callback(&packet);
}
int main(void) { return Answer() == 42 ? 0 : 1; }
C
"${CC:-cc}" -std=c11 -I"$repo/include" -I"$work/c" "$work"/c/*.c -o "$work/app"
"$work/app"
echo "Native callback records preserve unused fields and their C ABI"