feat: add experimental tailcall vm backend

This commit is contained in:
2026-04-19 22:13:54 +08:00
parent 800249cb1e
commit 98b07f00e4
16 changed files with 501 additions and 111 deletions
+17 -4
View File
@@ -12,6 +12,7 @@ pub(crate) struct BytecodeReader<'a> {
}
impl<'a> BytecodeReader<'a> {
#[cfg_attr(feature = "tailcall", allow(dead_code))]
pub(crate) fn new(bytecode: &'a [u8], pc: usize) -> Self {
Self {
bytecode,
@@ -20,6 +21,16 @@ impl<'a> BytecodeReader<'a> {
}
}
#[inline(always)]
#[cfg_attr(not(feature = "tailcall"), allow(dead_code))]
pub(crate) fn from_after_op(bytecode: &'a [u8], inst_start_pc: usize) -> Self {
Self {
bytecode,
pc: inst_start_pc + 1,
inst_start_pc,
}
}
#[inline(always)]
#[cfg_attr(debug_assertions, track_caller)]
fn read_array<const N: usize>(&mut self) -> [u8; N] {
@@ -31,6 +42,7 @@ impl<'a> BytecodeReader<'a> {
}
#[inline(always)]
#[cfg_attr(feature = "tailcall", allow(dead_code))]
pub(crate) fn read_op(&mut self) -> fix_codegen::Op {
use fix_codegen::Op;
self.inst_start_pc = self.pc;
@@ -105,16 +117,17 @@ impl<'a> BytecodeReader<'a> {
}
#[inline(always)]
pub(crate) fn read_attr_key_data<C: crate::VmContext>(&mut self, ctx: &C) -> crate::AttrKeyData {
pub(crate) fn read_attr_key_data<C: crate::VmContext>(
&mut self,
ctx: &C,
) -> crate::AttrKeyData {
use fix_codegen::AttrKeyType;
let tag = self.read_u8();
let ty = AttrKeyType::try_from_primitive(tag)
.unwrap_or_else(|err| panic!("unknown key tag: {:#04x}", err.number));
match ty {
AttrKeyType::Static => crate::AttrKeyData::Static(self.read_string_id()),
AttrKeyType::Dynamic => {
crate::AttrKeyData::Dynamic(self.read_operand_data(ctx))
}
AttrKeyType::Dynamic => crate::AttrKeyData::Dynamic(self.read_operand_data(ctx)),
}
}