feat: JIT (WIP)

This commit is contained in:
2025-05-17 22:38:05 +08:00
parent 95ebddf272
commit 29e959894d
7 changed files with 320 additions and 103 deletions

View File

@@ -8,7 +8,7 @@ use crate::ty::internal::*;
use crate::ty::common::Const;
use crate::ty::public::{self as p, Symbol};
use crate::stack::Stack;
use crate::jit::JITContext;
use crate::jit::{JITContext, JITFunc};
use derive_more::Constructor;
use ecow::EcoString;
@@ -74,6 +74,10 @@ impl<'vm, 'jit: 'vm> VM<'jit> {
}
}
pub fn get_const(&self, idx: usize) -> Const {
self.consts[idx].clone()
}
pub fn eval(
&'vm self,
opcodes: impl Iterator<Item = OpCode>,
@@ -102,7 +106,7 @@ impl<'vm, 'jit: 'vm> VM<'jit> {
) -> Result<usize> {
match opcode {
OpCode::Illegal => panic!("illegal opcode"),
OpCode::Const { idx } => stack.push(Value::Const(self.consts[idx].clone()))?,
OpCode::Const { idx } => stack.push(Value::Const(self.get_const(idx)))?,
OpCode::LoadThunk { idx } => {
stack.push(Value::Thunk(Thunk::new(self.get_thunk(idx)).into()))?
}
@@ -262,4 +266,8 @@ impl<'vm, 'jit: 'vm> VM<'jit> {
}
Ok(0)
}
pub fn compile_func(&'vm self, func: &Func<'vm>) -> JITFunc {
self.jit.compile_function(func, self).unwrap()
}
}