Skip to main content

litex/module_manager/
module_manager.rs

1use crate::prelude::*;
2use std::collections::HashMap;
3use std::rc::Rc;
4
5pub struct ImportedModuleEnvironment {
6    pub environment: Environment,
7    pub name_scope: HashMap<String, LineFile>,
8}
9
10pub struct ModuleManager {
11    pub run_file_paths: Vec<Rc<str>>,
12    pub module_name_and_path_map: HashMap<String, String>,
13    pub module_path_and_names_map: HashMap<String, Vec<String>>,
14    pub current_module_path: String,
15    pub current_module_name: String,
16    pub current_file_index: usize,
17    pub entry_path: String,
18    /// Same `Rc` as the user entry slot in `run_file_paths` when set (file path, `repl`, `-e`, ...).
19    pub display_entry_rc: Option<Rc<str>>,
20    pub imported_module_environments: HashMap<String, Box<ImportedModuleEnvironment>>,
21}
22
23impl ModuleManager {
24    pub fn new_empty_module_manager(initial_path: &str) -> Self {
25        ModuleManager {
26            run_file_paths: vec![Rc::from(initial_path)],
27            module_name_and_path_map: HashMap::new(),
28            module_path_and_names_map: HashMap::new(),
29            current_module_path: String::new(),
30            current_module_name: String::new(),
31            current_file_index: FILE_INDEX_FOR_BUILTIN,
32            entry_path: initial_path.to_string(),
33            display_entry_rc: None,
34            imported_module_environments: HashMap::new(),
35        }
36    }
37
38    pub fn current_file_path_rc(&self) -> Rc<str> {
39        self.run_file_paths[self.current_file_index].clone()
40    }
41}