Skip to main content

runmat_runtime/native/
frame.rs

1use super::{NativeRootSet, NativeSourceLocation, NativeValueRef};
2
3#[repr(transparent)]
4#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5pub struct NativeFrameKind(pub u32);
6
7impl NativeFrameKind {
8    pub const FUNCTION: Self = Self(0);
9    pub const SCRIPT: Self = Self(1);
10    pub const CALLBACK: Self = Self(2);
11    pub const CONTINUATION: Self = Self(3);
12
13    pub const fn is_known(self) -> bool {
14        self.0 <= Self::CONTINUATION.0
15    }
16}
17
18/// Exact interpreter-materializable state at a native program point.
19///
20/// `pc`, stack depth, locals, side-effect epoch, and source location are all
21/// explicit so resume/deoptimization never replays a completed effect.
22#[repr(C)]
23#[derive(Clone, Copy, Debug, Default)]
24pub struct NativeResumeState {
25    pub function: u32,
26    pub block: u32,
27    pub position: u32,
28    pub phase: u32,
29    pub ordinal: u32,
30    pub flags: u32,
31    pub reserved: u32,
32    pub bytecode_pc: u64,
33    pub operand_depth: u32,
34    pub local_count: u32,
35    pub side_effect_epoch: u64,
36    pub source: NativeSourceLocation,
37}
38
39/// Runtime-owned frame visible to generated code and host helpers.
40#[repr(C)]
41#[derive(Clone, Copy, Debug)]
42pub struct NativeFrame {
43    pub abi_version: u32,
44    pub kind: NativeFrameKind,
45    pub flags: u32,
46    pub reserved: u32,
47    pub caller: *mut NativeFrame,
48    pub locals: *mut NativeValueRef,
49    pub local_count: usize,
50    pub operands: *mut NativeValueRef,
51    pub operand_capacity: usize,
52    pub roots: NativeRootSet,
53    pub resume: *mut NativeResumeState,
54}
55
56impl Default for NativeFrame {
57    fn default() -> Self {
58        Self {
59            abi_version: super::NATIVE_ABI_VERSION.encoded(),
60            kind: NativeFrameKind::FUNCTION,
61            flags: 0,
62            reserved: 0,
63            caller: std::ptr::null_mut(),
64            locals: std::ptr::null_mut(),
65            local_count: 0,
66            operands: std::ptr::null_mut(),
67            operand_capacity: 0,
68            roots: NativeRootSet::default(),
69            resume: std::ptr::null_mut(),
70        }
71    }
72}