use crate::interpreter::Interpreter;
use arcis_compiler::core::global_value::global_expr_store::with_global_expr_store_as_local;
use quote::ToTokens;

fn get_global_expr_store_size() -> usize {
    with_global_expr_store_as_local(|expr_store| expr_store.len())
}

impl<'ast> Interpreter<'ast> {
    pub fn with_profile<T>(
        &mut self,
        stmt: &dyn ToTokens,
        f: impl FnOnce(&mut Interpreter<'ast>) -> T,
    ) -> T {
        let before_size = get_global_expr_store_size();
        let res = f(self);
        let after_size = get_global_expr_store_size();
        let code_idx = self.code_store.push(stmt);
        self.profile.push(code_idx, before_size, after_size);
        res
    }
}
