Skip to main content

byteflow/jit/
frame.rs

1//! Execution frame passed into compiled traces.
2
3/// Byte offsets for [`JitFrame`] fields (must match `repr(C)` layout).
4pub const OFF_REGISTER_COUNT: i32 = 8;
5pub const OFF_PC: i32 = 12;
6pub const OFF_BUDGET: i32 = 16;
7pub const OFF_FUNCTION: i32 = 20;
8pub const OFF_EXIT_KIND: i32 = 24;
9pub const OFF_RETURN_REG: i32 = 28;
10pub const OFF_CALL_DEPTH: i32 = 32;
11pub const OFF_CALL_STACK: i32 = 40;
12
13/// Maximum nested intra-chunk calls handled inside one compiled trace.
14pub const MAX_JIT_CALL_DEPTH: usize = 32;
15
16/// Saved caller state for one `Opcode::Call`.
17#[repr(C)]
18#[derive(Clone, Copy, Debug)]
19pub struct JitCallRecord {
20    pub return_pc: u32,
21    pub return_function: u32,
22    pub dest_reg: u32,
23    pub caller_register_count: u32,
24}
25
26/// Mutable state for one JIT invocation on the current bytecode frame.
27///
28/// v1 keeps scalar work in a parallel `i64` slot table (Int specialization).
29/// The dispatcher copies [`crate::Value::Int`] in before the call and
30/// writes results back after `Return`.
31#[repr(C)]
32pub struct JitFrame {
33    pub slots: *mut i64,
34    pub register_count: u32,
35    pub pc: u32,
36    pub budget: u32,
37    pub function: u32,
38    pub exit_kind: u32,
39    pub return_reg: u32,
40    pub call_depth: u32,
41    pub call_stack: *mut JitCallRecord,
42}
43
44pub type JitEntry = unsafe extern "C" fn(*mut JitFrame);