refactor(jit): use source cache instead of string
This commit is contained in:
parent
efb8607569
commit
f5f4da31e5
1 changed files with 12 additions and 13 deletions
|
|
@ -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| {
|
||||
ast.type_check().map_err(|errors| {
|
||||
errors
|
||||
.iter()
|
||||
.for_each(|e| e.to_report(&ast).eprint(&mut source_cache).unwrap());
|
||||
})
|
||||
.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::<std::path::Path>::as_ref(path).into(),
|
||||
id,
|
||||
source_cache,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue