1use super::store::Store;
5use crate::{errors::error::Error, values::value::Value};
6use std::{cell::RefCell, rc::Rc};
7
8#[derive(Debug, PartialEq)]
9pub struct Frame {
10 caller_position: usize,
11 pub name: String,
12 pub current_store: Rc<RefCell<Store>>,
13}
14
15impl Frame {
16 pub fn new(
24 caller_position: usize,
25 name: &str,
26 parent_store: Option<&Rc<RefCell<Store>>>,
27 ) -> Frame {
28 Frame {
29 caller_position,
30 name: name.to_owned(),
31 current_store: Rc::new(RefCell::new(Store::new(parent_store.cloned()))),
32 }
33 }
34
35 pub fn find(&self, name: &str, pos: usize) -> Result<Rc<Value>, Error> {
36 self.current_store.borrow().get(name, pos)
37 }
38
39 pub fn define(&mut self, name: &str, value: Rc<Value>) {
40 self.current_store.borrow_mut().define(name, value);
41 }
42
43 pub fn get_caller_position(&self) -> usize {
45 self.caller_position
46 }
47}