optimize: make all call single arg

to allow more aggressive optimization
This commit is contained in:
2025-05-23 09:21:40 +08:00
parent f380e5fd70
commit 53cbb37b00
8 changed files with 60 additions and 101 deletions

View File

@@ -21,22 +21,22 @@ impl PartialEq for PrimOp<'_, '_> {
}
impl<'jit, 'vm> PrimOp<'jit, 'vm> {
pub fn call(&self, vm: &'vm VM<'jit>, args: Vec<Value<'jit, 'vm>>) -> Result<Value<'jit, 'vm>> {
if (args.len()) < self.arity {
pub fn call(&self, vm: &'vm VM<'jit>, arg: Value<'jit, 'vm>) -> Result<Value<'jit, 'vm>> {
let mut args = Vec::with_capacity(self.arity);
args.push(arg);
if self.arity > 1 {
Value::PartialPrimOp(
PartialPrimOp {
name: self.name,
arity: self.arity - args.len(),
arity: self.arity - 1,
args,
func: self.func,
}
.into(),
)
.ok()
} else if args.len() == self.arity {
(self.func)(vm, args)
} else {
unimplemented!()
(self.func)(vm, args)
}
}
}
@@ -57,22 +57,18 @@ impl PartialEq for PartialPrimOp<'_, '_> {
impl<'jit: 'vm, 'vm> PartialPrimOp<'jit, 'vm> {
pub fn call(
self: &Rc<Self>,
self: &mut Rc<Self>,
vm: &'vm VM<'jit>,
args: Vec<Value<'jit, 'vm>>,
arg: Value<'jit, 'vm>,
) -> Result<Value<'jit, 'vm>> {
let len = args.len();
let mut self_clone = self.clone();
let self_mut = Rc::make_mut(&mut self_clone);
self_mut.args.extend(args);
self_mut.arity -= len;
let self_mut = Rc::make_mut(self);
self_mut.args.push(arg);
self_mut.arity -= 1;
if self_mut.arity > 0 {
Value::PartialPrimOp(self_clone).ok()
} else if self_mut.arity == 0 {
Value::PartialPrimOp(self.clone()).ok()
} else {
let args = std::mem::take(&mut self_mut.args);
(self.func)(vm, args)
} else {
unimplemented!()
}
}
}
}