diff --git a/src/jit/mod.rs b/src/jit/mod.rs index bf86ccc..feb05f1 100644 --- a/src/jit/mod.rs +++ b/src/jit/mod.rs @@ -73,11 +73,14 @@ impl JIT { /// Compile source code into machine code. pub fn compile( &mut self, - input: &str, namespace: ModulePath, id: SourceId, + mut source_cache: &mut SourceCache, ) -> Result<*const u8, String> { - let mut source_cache = (0u32, ariadne::Source::from(input)); + let input = source_cache + .fetch(&id) + .map(|s| s.text()) + .map_err(|e| format!("{e:?}"))?; // Parse the source code into an AST let mut ast = self @@ -85,13 +88,12 @@ impl JIT { .parse_as_module(input, namespace, id) .map_err(|x| format!("Parsing error: {x}"))?; - ast.type_check() - .map_err(|errors| { - errors - .iter() - .for_each(|e| e.to_report(&ast).eprint(&mut source_cache).unwrap()); - }) - .unwrap(); + ast.type_check().map_err(|errors| { + errors + .iter() + .for_each(|e| e.to_report(&ast).eprint(&mut source_cache).unwrap()); + "Typing errors, cannot compile" + })?; // Translate the AST into Cranelift IR self.translate(&ast)?; @@ -117,12 +119,9 @@ impl JIT { source_cache: &mut SourceCache, ) -> Result<*const u8, String> { self.compile( - source_cache - .fetch(&id) - .map(|s| s.text()) - .map_err(|e| format!("{:?}", e))?, AsRef::::as_ref(path).into(), id, + source_cache, ) }