Skip to main content

gc/
frame.rs

1use crate::value::GcClosure;
2use compiler::op_code::Instructions;
3
4#[derive(Debug, Clone)]
5pub struct Frame {
6    /// Borrowed closure refs. Frames do not own or free these handles; the
7    /// callee stack slot, main function root, or closure object keeps them live.
8    pub cl: GcClosure,
9    pub ip: i32,
10    pub base_pointer: usize,
11    pub instructions: Vec<u8>,
12    /// One flag per local slot: has the slot been written since the frame was
13    /// pushed? Parameters (including a method's `this`) arrive initialized;
14    /// `let` slots hold a prefilled null the debugger must not present as a
15    /// user value until `OpSetLocal` marks them.
16    pub initialized: Vec<bool>,
17}
18
19impl Frame {
20    pub fn new(
21        closure: GcClosure,
22        instructions: Vec<u8>,
23        base_pointer: usize,
24        num_locals: usize,
25        num_parameters: usize,
26    ) -> Self {
27        Frame {
28            cl: closure,
29            ip: -1,
30            base_pointer,
31            instructions,
32            initialized: (0..num_locals).map(|slot| slot < num_parameters).collect(),
33        }
34    }
35
36    pub fn instruction_view(&self) -> Instructions {
37        Instructions {
38            data: self.instructions.clone(),
39        }
40    }
41}