use crate::{NodeOp, Program};
use rustc_hash::FxHashMap;
use std::path::PathBuf;
#[derive(Clone)]
pub struct Context {
pub globals: FxHashMap<String, u32>,
pub custom_targets: Vec<Vec<NodeOp>>,
pub program: Program,
pub imported_paths: Vec<PathBuf>,
}
impl Context {
pub fn new(globals: FxHashMap<String, u32>) -> Self {
Self {
program: Program::new(),
globals,
imported_paths: vec![],
custom_targets: vec![],
}
}
pub fn add_custom_target(&mut self) {
self.custom_targets.push(vec![]);
}
pub fn take_last_custom_target(&mut self) -> Option<Vec<NodeOp>> {
self.custom_targets.pop()
}
pub fn emit(&mut self, op: NodeOp) {
if let Some(custom) = self.custom_targets.last_mut() {
custom.push(op.clone());
return;
}
self.program.body.push(op);
}
}