(
&self,
mode: Mode,
module_name: String,
compiler: &dyn Compiler,
)
| 93 | } |
| 94 | |
| 95 | fn compile_single( |
| 96 | &self, |
| 97 | mode: Mode, |
| 98 | module_name: String, |
| 99 | compiler: &dyn Compiler, |
| 100 | ) -> Result<CodeObject, Diagnostic> { |
| 101 | match &self.kind { |
| 102 | CompilationSourceKind::File { base, rel_path } => { |
| 103 | let path = base.join(rel_path); |
| 104 | let source = fs::read_to_string(&path).map_err(|err| { |
| 105 | Diagnostic::spans_error( |
| 106 | self.span, |
| 107 | format!("Error reading file {path:?}: {err}"), |
| 108 | ) |
| 109 | })?; |
| 110 | self.compile_string(&source, mode, module_name, compiler, || rel_path.display()) |
| 111 | } |
| 112 | CompilationSourceKind::SourceCode(code) => self.compile_string( |
| 113 | &textwrap::dedent(code), |
| 114 | mode, |
| 115 | module_name, |
| 116 | compiler, |
| 117 | || "string literal", |
| 118 | ), |
| 119 | CompilationSourceKind::Dir { .. } => { |
| 120 | unreachable!("Can't use compile_single with directory source") |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | fn compile_dir( |
| 126 | &self, |
no test coverage detected