chore: cleanup

This commit is contained in:
2025-06-08 00:59:31 +08:00
parent 0fd846e844
commit 3797544fc2
25 changed files with 1028 additions and 1481 deletions

View File

@@ -3,7 +3,7 @@ use std::rc::Rc;
use derive_more::Constructor;
use crate::error::Result;
use crate::vm::VM;
use crate::engine::Engine;
use super::Value;
@@ -11,7 +11,7 @@ use super::Value;
pub struct PrimOp {
pub name: &'static str,
arity: usize,
func: for<'gc> fn(Vec<Value<'gc>>, &VM) -> Result<Value<'gc>>,
func: for<'gc> fn(Vec<Value<'gc>>, &Engine) -> Result<Value<'gc>>,
}
impl PartialEq for PrimOp {
@@ -21,7 +21,7 @@ impl PartialEq for PrimOp {
}
impl PrimOp {
pub fn call<'gc>(&self, arg: Value<'gc>, vm: &VM) -> Result<Value<'gc>> {
pub fn call<'gc>(&self, arg: Value<'gc>, ctx: &Engine) -> Result<Value<'gc>> {
let mut args = Vec::with_capacity(self.arity);
args.push(arg);
if self.arity > 1 {
@@ -33,7 +33,7 @@ impl PrimOp {
}))
.ok()
} else {
(self.func)(args, vm)
(self.func)(args, ctx)
}
}
}
@@ -43,7 +43,7 @@ pub struct PartialPrimOp<'gc> {
pub name: &'static str,
arity: usize,
args: Vec<Value<'gc>>,
func: fn(Vec<Value<'gc>>, &VM) -> Result<Value<'gc>>,
func: fn(Vec<Value<'gc>>, &Engine) -> Result<Value<'gc>>,
}
impl PartialEq for PartialPrimOp<'_> {
@@ -53,14 +53,14 @@ impl PartialEq for PartialPrimOp<'_> {
}
impl<'gc> PartialPrimOp<'gc> {
pub fn call(self: &mut Rc<Self>, arg: Value<'gc>, vm: &VM) -> Result<Value<'gc>> {
pub fn call(self: &mut Rc<Self>, arg: Value<'gc>, ctx: &Engine) -> Result<Value<'gc>> {
let func = self.func;
let Some(ret) = ({
let self_mut = Rc::make_mut(self);
self_mut.args.push(arg);
self_mut.arity -= 1;
if self_mut.arity == 0 {
Some(func(std::mem::take(&mut self_mut.args), vm))
Some(func(std::mem::take(&mut self_mut.args), ctx))
} else {
None
}