feat(jit): fib!

This commit is contained in:
2025-05-19 19:29:25 +08:00
parent 6d26716412
commit 9e172bf013
10 changed files with 363 additions and 166 deletions

View File

@@ -13,7 +13,7 @@ use crate::ty::public::{self as p, Symbol};
use derive_more::Constructor;
use ecow::EcoString;
pub use env::Env;
pub use env::LetEnv;
mod env;
@@ -82,7 +82,7 @@ impl<'vm, 'jit: 'vm> VM<'jit> {
pub fn eval(
&'vm self,
opcodes: impl Iterator<Item = OpCode>,
mut env: Env<'jit, 'vm>,
mut env: LetEnv<'jit, 'vm>,
) -> Result<Value<'jit, 'vm>> {
let mut stack = Stack::<_, STACK_SIZE>::new();
let mut iter = opcodes.into_iter();
@@ -103,7 +103,7 @@ impl<'vm, 'jit: 'vm> VM<'jit> {
&'vm self,
opcode: OpCode,
stack: &'s mut Stack<Value<'jit, 'vm>, CAP>,
env: &mut Env<'jit, 'vm>,
env: &mut LetEnv<'jit, 'vm>,
) -> Result<usize> {
match opcode {
OpCode::Illegal => panic!("illegal opcode"),
@@ -121,11 +121,6 @@ impl<'vm, 'jit: 'vm> VM<'jit> {
stack.tos_mut()?.force(self)?;
}
OpCode::Jmp { step } => return Ok(step),
OpCode::JmpIfTrue { step } => {
if let Value::Const(Const::Bool(true)) = stack.pop() {
return Ok(step);
}
}
OpCode::JmpIfFalse { step } => {
if let Value::Const(Const::Bool(false)) = stack.pop() {
return Ok(step);
@@ -193,7 +188,7 @@ impl<'vm, 'jit: 'vm> VM<'jit> {
stack.push(Value::AttrSet(AttrSet::with_capacity(cap).into()))?;
}
OpCode::FinalizeRec => {
let env = env.clone().enter(
let env = env.clone().enter_let(
stack
.tos()?
.clone()