feat: better builtins implementaion

get rid of circular references
This commit is contained in:
2025-05-17 18:31:36 +08:00
parent 8480e0891b
commit ff9afd0cc1
19 changed files with 191 additions and 244 deletions

View File

@@ -2,8 +2,8 @@ use std::rc::Rc;
use derive_more::Constructor;
use crate::vm::VM;
use crate::error::Result;
use crate::vm::VM;
use super::Value;
@@ -23,12 +23,16 @@ impl PartialEq for PrimOp<'_> {
impl<'vm> PrimOp<'vm> {
pub fn call(&self, vm: &'vm VM<'_>, args: Vec<Value<'vm>>) -> Result<Value<'vm>> {
if (args.len()) < self.arity {
Value::PartialPrimOp(PartialPrimOp {
name: self.name,
arity: self.arity - args.len(),
args,
func: self.func,
}.into()).ok()
Value::PartialPrimOp(
PartialPrimOp {
name: self.name,
arity: self.arity - args.len(),
args,
func: self.func,
}
.into(),
)
.ok()
} else if args.len() == self.arity {
(self.func)(vm, args)
} else {