got some basics working!
This commit is contained in:
@@ -33,19 +33,37 @@ fn print_result<E>(result: (Value<E>, String)) {
|
||||
println!("RESULT: {}", result.0);
|
||||
}
|
||||
|
||||
fn main() -> Result<(), anyhow::Error> {
|
||||
fn jit(ir: ngr::ir::Program<ngr::ir::Type>) -> Result<fn(), ngr::backend::BackendError> {
|
||||
let mut backend = Backend::jit(None)?;
|
||||
let function_id = backend.compile_program("gogogo", ir)?;
|
||||
backend.module.finalize_definitions()?;
|
||||
let compiled_bytes = backend.bytes(function_id);
|
||||
Ok(unsafe { std::mem::transmute::<_, fn() -> ()>(compiled_bytes) })
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let cli = CommandLineArguments::parse();
|
||||
let mut file_database = SimpleFiles::new();
|
||||
let mut console = StandardStream::stdout(pretty::termcolor::ColorChoice::Auto);
|
||||
let console_options = codespan_reporting::term::Config::default();
|
||||
let syntax = syntax::Program::parse_file(&mut file_database, cli.file.as_ref())?;
|
||||
let syntax = syntax::Program::parse_file(&mut file_database, cli.file.as_ref());
|
||||
let mut emit = |x| {
|
||||
let _ = codespan_reporting::term::emit(&mut console, &console_options, &file_database, &x);
|
||||
};
|
||||
let syntax = match syntax {
|
||||
Ok(x) => x,
|
||||
Err(e) => {
|
||||
emit((&e).into());
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if cli.interpreter == Interpreter::Syntax {
|
||||
print_result(syntax.eval()?);
|
||||
return Ok(());
|
||||
match syntax.eval() {
|
||||
Err(e) => println!("Evaluation error: {}", e),
|
||||
Ok(v) => print_result(v),
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
let ir = match syntax.type_infer() {
|
||||
@@ -62,21 +80,20 @@ fn main() -> Result<(), anyhow::Error> {
|
||||
for error in errors {
|
||||
emit(error.into());
|
||||
}
|
||||
return Err(anyhow::anyhow!("failed to infer program types"));
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if cli.interpreter == Interpreter::IR {
|
||||
print_result(ir.eval()?);
|
||||
return Ok(());
|
||||
match ir.eval() {
|
||||
Err(e) => println!("Evaluation error: {}", e),
|
||||
Ok(v) => print_result(v),
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
let mut backend = Backend::jit(None)?;
|
||||
let function_id = backend.compile_program("gogogo", ir)?;
|
||||
backend.module.finalize_definitions()?;
|
||||
let compiled_bytes = backend.bytes(function_id);
|
||||
let compiled_function = unsafe { std::mem::transmute::<_, fn() -> ()>(compiled_bytes) };
|
||||
compiled_function();
|
||||
|
||||
Ok(())
|
||||
match jit(ir) {
|
||||
Err(e) => emit(e.into()),
|
||||
Ok(compiled_function) => compiled_function(),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user