feat: gc (does compile, but WIP)
This commit is contained in:
@@ -1,40 +1,41 @@
|
||||
use derive_more::Constructor;
|
||||
use gc_arena::Mutation;
|
||||
use gc_arena::Collect;
|
||||
use gc_arena::Mutation;
|
||||
|
||||
use crate::error::Result;
|
||||
use crate::vm::VM;
|
||||
|
||||
use super::Value;
|
||||
use super::CoW;
|
||||
use super::Value;
|
||||
|
||||
#[derive(Debug, Clone, Constructor, Collect)]
|
||||
#[collect(require_static)]
|
||||
pub struct PrimOp<'gc> {
|
||||
pub struct PrimOp {
|
||||
pub name: &'static str,
|
||||
arity: usize,
|
||||
func: fn(Vec<Value<'gc>>, &VM, &Mutation<'gc>) -> Result<Value<'gc>>,
|
||||
func: for<'gc> fn(Vec<Value<'gc>>, &VM, &Mutation<'gc>) -> Result<Value<'gc>>,
|
||||
}
|
||||
|
||||
impl PartialEq for PrimOp<'_> {
|
||||
impl PartialEq for PrimOp {
|
||||
fn eq(&self, _: &Self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
impl<'gc> PrimOp<'gc> {
|
||||
pub fn call(&self, arg: Value<'gc>, vm: &VM, mc: &Mutation<'gc>) -> Result<Value<'gc>> {
|
||||
impl PrimOp {
|
||||
pub fn call<'gc>(&self, arg: Value<'gc>, vm: &VM, mc: &Mutation<'gc>) -> Result<Value<'gc>> {
|
||||
let mut args = Vec::with_capacity(self.arity);
|
||||
args.push(arg);
|
||||
if self.arity > 1 {
|
||||
Value::PartialPrimOp(
|
||||
CoW::new(PartialPrimOp {
|
||||
Value::PartialPrimOp(CoW::new(
|
||||
PartialPrimOp {
|
||||
name: self.name,
|
||||
arity: self.arity - 1,
|
||||
args,
|
||||
func: self.func,
|
||||
}, mc)
|
||||
)
|
||||
},
|
||||
mc,
|
||||
))
|
||||
.ok()
|
||||
} else {
|
||||
(self.func)(args, vm, mc)
|
||||
@@ -50,8 +51,8 @@ pub struct PartialPrimOp<'gc> {
|
||||
func: fn(Vec<Value<'gc>>, &VM, &Mutation<'gc>) -> Result<Value<'gc>>,
|
||||
}
|
||||
|
||||
unsafe impl<'jit: 'vm, 'vm, 'gc> Collect for PartialPrimOp<'gc> {
|
||||
fn trace(&self, cc: &gc_arena::Collection) {
|
||||
unsafe impl<'jit: 'vm, 'vm, 'gc> Collect<'gc> for PartialPrimOp<'gc> {
|
||||
fn trace<Tr: gc_arena::collect::Trace<'gc>>(&self, cc: &mut Tr) {
|
||||
for v in self.args.iter() {
|
||||
v.trace(cc);
|
||||
}
|
||||
@@ -69,7 +70,7 @@ impl<'gc> PartialPrimOp<'gc> {
|
||||
self: &mut CoW<'gc, Self>,
|
||||
arg: Value<'gc>,
|
||||
vm: &VM,
|
||||
mc: &Mutation<'gc>
|
||||
mc: &Mutation<'gc>,
|
||||
) -> Result<Value<'gc>> {
|
||||
let func = self.func;
|
||||
let self_mut = self.make_mut(mc);
|
||||
|
||||
Reference in New Issue
Block a user