feat: ref

This commit is contained in:
2025-05-11 10:19:55 +08:00
parent cbb29276d8
commit 7cbb082dc4
12 changed files with 180 additions and 165 deletions

View File

@@ -5,20 +5,20 @@ use crate::vm::VM;
use super::Value;
#[derive(Debug, Clone, Constructor)]
pub struct PrimOp {
pub struct PrimOp<'vm> {
pub name: &'static str,
arity: u8,
func: fn(&VM, Vec<Value>) -> Value,
func: fn(&VM<'vm>, Vec<Value<'vm>>) -> Value<'vm>,
}
impl PartialEq for PrimOp {
impl PartialEq for PrimOp<'_> {
fn eq(&self, _: &Self) -> bool {
false
}
}
impl PrimOp {
pub fn call(self, vm: &VM, args: Vec<Value>) -> Value {
impl<'vm> PrimOp<'vm> {
pub fn call(self, vm: &VM<'vm>, args: Vec<Value<'vm>>) -> Value<'vm> {
if (args.len() as u8) < self.arity {
Value::PartialPrimOp(PartialPrimOp {
name: self.name,
@@ -35,21 +35,21 @@ impl PrimOp {
}
#[derive(Debug, Clone)]
pub struct PartialPrimOp {
pub struct PartialPrimOp<'vm> {
pub name: &'static str,
arity: u8,
args: Vec<Value>,
func: fn(&VM, Vec<Value>) -> Value,
args: Vec<Value<'vm>>,
func: fn(&VM<'vm>, Vec<Value<'vm>>) -> Value<'vm>,
}
impl PartialEq for PartialPrimOp {
impl PartialEq for PartialPrimOp<'_> {
fn eq(&self, _: &Self) -> bool {
false
}
}
impl PartialPrimOp {
pub fn call(mut self, vm: &VM, args: Vec<Value>) -> Value {
impl<'vm> PartialPrimOp<'vm> {
pub fn call(mut self, vm: &VM<'vm>, args: Vec<Value<'vm>>) -> Value<'vm> {
let len = args.len() as u8;
self.args.extend(args);
if len < self.arity {