1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use crate::runtime::instruction_pointer::InstructionPointer;
use std::fmt;
use std::fmt::{Display, Formatter};

pub struct CallFrame {
    pub chunk_id: usize,
    pub name: String,
    pub instruction_pointer: InstructionPointer,
    pub start_slot: usize,
}

impl CallFrame {
    pub fn new(chunk_id: usize, name: String, start_slot: usize) -> CallFrame {
        CallFrame {
            chunk_id,
            name,
            instruction_pointer: InstructionPointer::new(chunk_id),
            start_slot,
        }
    }
}

impl Display for CallFrame {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "{} (#{}:{})",
            self.name, self.chunk_id, self.instruction_pointer.instruction_pointer
        )
    }
}