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

@@ -175,38 +175,27 @@ impl<'jit, 'vm> Value<'jit, 'vm> {
}
}
pub fn call(&self, vm: &'vm VM<'jit>, args: Vec<Self>) -> Result<Self> {
pub fn call(&mut self, vm: &'vm VM<'jit>, arg: Self) -> Result<()> {
use Value::*;
match self {
PrimOp(func) => func.call(vm, args),
PartialPrimOp(func) => func.call(vm, args),
func @ Value::Func(_) => {
let mut iter = args.into_iter();
let mut func = func.clone();
while let Some(arg) = iter.next() {
func = match func {
PrimOp(func) => {
return func.call(vm, [arg].into_iter().chain(iter).collect());
}
PartialPrimOp(func) => {
return func.call(vm, [arg].into_iter().chain(iter).collect());
}
Func(func) => func.call(vm, arg)?,
_ => todo!(),
}
}
func.ok()
}
x @ Catchable(_) => x.clone().ok(),
_ => todo!(),
if matches!(arg, Value::Catchable(_)) {
*self = arg;
return Ok(());
}
*self = match self {
PrimOp(func) => func.call(vm, arg),
PartialPrimOp(func) => func.call(vm, arg),
Value::Func(func) => func.call(vm, arg),
Catchable(_) => return Ok(()),
_ => todo!(),
}?;
Ok(())
}
pub fn not(self) -> Self {
pub fn not(&mut self) {
use Const::*;
match self {
*self = match &*self {
VmConst(Bool(bool)) => VmConst(Bool(!bool)),
x @ Value::Catchable(_) => x,
Value::Catchable(_) => return,
_ => todo!(),
}
}
@@ -257,12 +246,12 @@ impl<'jit, 'vm> Value<'jit, 'vm> {
}))
}
pub fn neg(self) -> Self {
pub fn neg(&mut self) {
use Const::*;
match self {
*self = match &*self {
VmConst(Int(int)) => VmConst(Int(-int)),
VmConst(Float(float)) => VmConst(Float(-float)),
x @ Value::Catchable(_) => x,
Value::Catchable(_) => return,
_ => todo!(),
}
}