Files
scriptc/tests/library-mode/contract-int-libcall/lib.ts
T
Chris Tate 383f43bdeb Keep integer-slot checking working in the native compiler for library calls with bytes or array arguments
The global-effects summary typed each library-call argument as a
structural `{ kind: string }`. The native compiler extracted that one
record arm from the IrType union and threw on bytes, array and other
arms with more fields, so `scriptc build --lib` failed with SC3004 for
integer-slot profiles that call, for example, `Buffer.alloc` or
`String.fromCharCode`. The helper now takes `IrType`, and the bootstrap
test compares native and Node sidecars for such a profile.
2026-10-16 02:51:23 -05:00

28 lines
878 B
TypeScript

// Integer-slot attestation over a program whose library calls take
// non-scalar arguments: Buffer.alloc lowers to buffer.brand over a bytes
// value, and String.fromCharCode to a call over an array. The slot check
// summarizes which globals every call may write, reading each argument's
// IR type; the native compiler must produce the same sidecar as Node.
export const scratch = Buffer.alloc(8);
export const letter = String.fromCharCode(65);
export interface Model {
readonly phase: number;
}
export type Msg = { readonly kind: "next" } | { readonly kind: "reset" };
export function init(): Model {
return { phase: 0 };
}
export function update(model: Model, msg: Msg): Model {
switch (msg.kind) {
case "next":
return { phase: model.phase >= 0 && model.phase < 3 ? Math.trunc(model.phase + 1) : 0 };
case "reset":
return { phase: 0 };
}
}