feat: generalize Stack

This commit is contained in:
2025-05-15 11:20:59 +08:00
parent 2293b9e2de
commit 3e7a8a1c05
3 changed files with 17 additions and 18 deletions

View File

@@ -7,18 +7,19 @@ use crate::ty::common::Symbol;
use crate::ty::internal::*;
use crate::ty::public as p;
use stack::{STACK_SIZE, Stack};
use crate::stack::Stack;
pub use env::Env;
pub use jit::JITContext;
mod env;
mod jit;
mod stack;
#[cfg(test)]
mod test;
const STACK_SIZE: usize = 8 * 1024 / size_of::<Value>();
pub fn run(prog: Program, jit: JITContext<'_>) -> Result<p::Value> {
let vm = VM::new(
prog.thunks,
@@ -57,7 +58,7 @@ impl<'vm, 'jit: 'vm> VM<'jit> {
}
pub fn eval(&'vm self, opcodes: OpCodes, env: Rc<Env<'vm>>) -> Result<Value<'vm>> {
let mut stack = Stack::<STACK_SIZE>::new();
let mut stack = Stack::<_, STACK_SIZE>::new();
let mut iter = opcodes.into_iter();
while let Some(opcode) = iter.next() {
let jmp = self.single_op(opcode, &mut stack, &env)?;
@@ -75,7 +76,7 @@ impl<'vm, 'jit: 'vm> VM<'jit> {
fn single_op<'s, const CAP: usize>(
&'vm self,
opcode: OpCode,
stack: &'s mut Stack<'vm, CAP>,
stack: &'s mut Stack<Value<'vm>, CAP>,
env: &Rc<Env<'vm>>,
) -> Result<usize> {
match opcode {