feat(vm): threaded VM
This commit is contained in:
+18
-1
@@ -2,6 +2,7 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use bumpalo::Bump;
|
||||
use fix_codegen::disassembler::{Disassembler, DisassemblerContext};
|
||||
use fix_codegen::{BytecodeContext, InstructionPtr};
|
||||
use fix_common::{StringId, Symbol};
|
||||
use fix_error::{Error, Result, Source};
|
||||
@@ -10,7 +11,7 @@ use fix_ir::{Ir, IrRef, RawIrRef, ThunkId};
|
||||
use fix_vm::{ForceMode, StaticValue, Vm, VmContext};
|
||||
use ghost_cell::{GhostCell, GhostToken};
|
||||
use hashbrown::{HashMap, HashSet};
|
||||
use string_interner::DefaultStringInterner;
|
||||
use string_interner::{DefaultStringInterner, Symbol as _};
|
||||
|
||||
// mod fetcher;
|
||||
// mod nar;
|
||||
@@ -105,6 +106,10 @@ impl Evaluator {
|
||||
Ok(ip)
|
||||
}
|
||||
|
||||
pub fn disassemble_colored(&self, ip: InstructionPtr) -> String {
|
||||
Disassembler::new(ip, self).disassemble_colored()
|
||||
}
|
||||
|
||||
fn downgrade_ctx<'a, 'bump, 'id>(
|
||||
&'a mut self,
|
||||
bump: &'bump Bump,
|
||||
@@ -553,3 +558,15 @@ impl BytecodeContext for Evaluator {
|
||||
self.constants.insert(val)
|
||||
}
|
||||
}
|
||||
|
||||
impl DisassemblerContext for Evaluator {
|
||||
fn get_code(&self) -> &[u8] {
|
||||
&self.bytecode
|
||||
}
|
||||
|
||||
#[allow(clippy::unwrap_used)]
|
||||
fn resolve_string(&self, id: u32) -> &str {
|
||||
let id = string_interner::symbol::SymbolU32::try_from_usize(id as usize).unwrap();
|
||||
self.strings.resolve(id).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -40,7 +40,7 @@ struct ExprSource {
|
||||
file: Option<PathBuf>,
|
||||
}
|
||||
|
||||
fn run_compile(eval: &mut Evaluator, src: ExprSource, _silent: bool) -> Result<()> {
|
||||
fn run_compile(eval: &mut Evaluator, src: ExprSource, silent: bool) -> Result<()> {
|
||||
let src = if let Some(expr) = src.expr {
|
||||
Source::new_eval(expr)?
|
||||
} else if let Some(file) = src.file {
|
||||
@@ -49,10 +49,10 @@ fn run_compile(eval: &mut Evaluator, src: ExprSource, _silent: bool) -> Result<(
|
||||
unreachable!()
|
||||
};
|
||||
match eval.compile_bytecode(src) {
|
||||
Ok(_ip) => {
|
||||
// if !silent {
|
||||
// println!("{}", eval.disassemble_colored(ip));
|
||||
// }
|
||||
Ok(ip) => {
|
||||
if !silent {
|
||||
println!("{}", eval.disassemble_colored(ip));
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("{:?}", miette::Report::new(*err));
|
||||
|
||||
Reference in New Issue
Block a user