Compile a program's import closure (primary plus every qualified `import("...")` module), link it against the cached stdlib, and run. Backward-compatible with single-TU programs.
(
src: &str,
source_path: Option<&str>,
max_steps: u64,
)
| 119 | /// Compile a program's import closure (primary plus every qualified `import("...")` module), |
| 120 | /// link it against the cached stdlib, and run. Backward-compatible with single-TU programs. |
| 121 | fn run_hll_closure_with_path( |
| 122 | src: &str, |
| 123 | source_path: Option<&str>, |
| 124 | max_steps: u64, |
| 125 | ) -> (StepOutcome, String) { |
| 126 | let mut pipeline = CompilationPipeline::new(); |
| 127 | pipeline.set_write_artifacts(false); |
| 128 | pipeline.set_current_source_path(source_path.map(str::to_owned)); |
| 129 | let closure = pipeline |
| 130 | .compile_program_closure("user", src) |
| 131 | .expect("closure compile failed"); |
| 132 | |
| 133 | let mut modules: Vec<(&str, &AssembledOutput)> = cached_stdlib_objs() |
| 134 | .iter() |
| 135 | .map(|(n, o)| (n.as_str(), o)) |
| 136 | .collect(); |
| 137 | for (name, obj) in &closure { |
| 138 | modules.push((name.as_str(), obj)); |
| 139 | } |
| 140 | let assembled = pipeline |
| 141 | .link_assembled_objects(&modules) |
| 142 | .expect("link failed"); |
| 143 | let mut vm = VirtualMachine::new(&assembled); |
| 144 | let run = vm.run(max_steps); |
| 145 | (run.outcome, run.uart_output.clone()) |
| 146 | } |
| 147 | |
| 148 | // A qualified `alias := import("path")` program links and runs its imported module: the |
| 149 | // closure compiles `mathlib` alongside the primary, so `mathlib.add` resolves at link. |