feat: less gc (WIP)

This commit is contained in:
2025-06-02 14:18:59 +08:00
parent d3442e87e7
commit 51f8df9cca
11 changed files with 125 additions and 179 deletions

View File

@@ -1,3 +1,5 @@
use std::rc::Rc;
use derive_more::Constructor;
use gc_arena::Collect;
use gc_arena::Mutation;
@@ -5,7 +7,6 @@ use gc_arena::Mutation;
use crate::error::Result;
use crate::vm::VM;
use super::CoW;
use super::Value;
#[derive(Debug, Clone, Constructor, Collect)]
@@ -27,14 +28,13 @@ impl PrimOp {
let mut args = Vec::with_capacity(self.arity);
args.push(arg);
if self.arity > 1 {
Value::PartialPrimOp(CoW::new(
Value::PartialPrimOp(Rc::new(
PartialPrimOp {
name: self.name,
arity: self.arity - 1,
args,
func: self.func,
},
mc,
))
.ok()
} else {
@@ -67,13 +67,14 @@ impl PartialEq for PartialPrimOp<'_> {
impl<'gc> PartialPrimOp<'gc> {
pub fn call(
self: &mut CoW<'gc, Self>,
self: &mut Rc<Self>,
arg: Value<'gc>,
vm: &VM,
mc: &Mutation<'gc>,
) -> Result<Value<'gc>> {
let func = self.func;
let Some(ret) = self.make_mut(|self_mut| {
let Some(ret) = ({
let self_mut = Rc::make_mut(self);
self_mut.args.push(arg);
self_mut.arity -= 1;
if self_mut.arity == 0 {
@@ -81,7 +82,7 @@ impl<'gc> PartialPrimOp<'gc> {
} else {
None
}
}, mc) else {
}) else {
return Value::PartialPrimOp(self.clone()).ok();
};
ret