feat(vm): threaded VM

This commit is contained in:
2026-04-11 10:30:03 +08:00
parent 8e67f9f636
commit 9983458b31
9 changed files with 1253 additions and 1264 deletions
+18 -1
View File
@@ -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()
}
}