Creates a new compiler instance. `global_defs` provides pre-defined global variables visible to the compiled program. `upcalls` contains the metadata of all built-in callables that the compiled code can use.
(
upcalls: &HashMap<SymbolKey, Rc<dyn Callable>>,
global_defs: &[GlobalDef],
)
| 227 | /// |
| 228 | /// `upcalls` contains the metadata of all built-in callables that the compiled code can use. |
| 229 | pub fn new( |
| 230 | upcalls: &HashMap<SymbolKey, Rc<dyn Callable>>, |
| 231 | global_defs: &[GlobalDef], |
| 232 | ) -> Result<Self> { |
| 233 | let mut upcalls_metadata = HashMap::with_capacity(upcalls.len()); |
| 234 | for (k, v) in upcalls.iter() { |
| 235 | upcalls_metadata.insert(k.clone(), v.metadata()); |
| 236 | } |
| 237 | |
| 238 | let mut context = Context::default(); |
| 239 | |
| 240 | let mut symtable = GlobalSymtable::new(upcalls_metadata); |
| 241 | prepare_globals(&mut context, &mut symtable, global_defs)?; |
| 242 | |
| 243 | Ok(Self { context, symtable, program_scope: LocalSymtableSnapshot::default() }) |
| 244 | } |
| 245 | |
| 246 | /// Compiles a chunk of code. |
| 247 | pub fn compile(mut self, input: &mut dyn io::Read) -> Result<Image> { |
nothing calls this directly
no test coverage detected