litex/module_manager/
module_manager.rs1use crate::prelude::*;
2use std::collections::HashMap;
3use std::rc::Rc;
4
5pub const BUILTIN_CODE_PATH: &str = "builtin_code";
7
8pub struct ImportedModuleEnvironment {
9 pub environment: Environment,
10 pub name_scope: HashMap<String, LineFile>,
11}
12
13pub struct ModuleManager {
14 pub run_file_paths: Vec<Rc<str>>,
15 pub module_name_and_path_map: HashMap<String, String>,
16 pub module_path_and_names_map: HashMap<String, Vec<String>>,
17 pub current_module_path: String,
18 pub current_module_name: String,
19 pub current_file_index: usize,
20 pub entry_path: String,
21 pub display_entry_rc: Option<Rc<str>>,
23 pub imported_module_environments: HashMap<String, Box<ImportedModuleEnvironment>>,
24}
25
26impl ModuleManager {
27 pub fn new_empty_module_manager(initial_path: &str) -> Self {
28 ModuleManager {
29 run_file_paths: vec![Rc::from(initial_path)],
30 module_name_and_path_map: HashMap::new(),
31 module_path_and_names_map: HashMap::new(),
32 current_module_path: String::new(),
33 current_module_name: String::new(),
34 current_file_index: FILE_INDEX_FOR_BUILTIN,
35 entry_path: initial_path.to_string(),
36 display_entry_rc: None,
37 imported_module_environments: HashMap::new(),
38 }
39 }
40
41 pub fn current_file_path_rc(&self) -> Rc<str> {
42 self.run_file_paths[self.current_file_index].clone()
43 }
44}