chore: cargo fmt

This commit is contained in:
2025-05-28 21:59:45 +08:00
parent 99dce2e778
commit f3bf44ab97
3 changed files with 48 additions and 20 deletions

View File

@@ -34,7 +34,9 @@ pub fn run(mut prog: Program) -> Result<p::Value> {
let mut thunks = std::mem::take(&mut prog.thunks);
thunks.iter_mut().for_each(|code| code.reverse());
let mut funcs = std::mem::take(&mut prog.funcs);
funcs.iter_mut().for_each(|F { opcodes, .. }| opcodes.reverse());
funcs
.iter_mut()
.for_each(|F { opcodes, .. }| opcodes.reverse());
let symbols = std::mem::take(&mut prog.symbols);
let symmap = std::mem::take(&mut prog.symmap);
let consts = std::mem::take(&mut prog.consts);
@@ -133,8 +135,13 @@ pub fn eval<T, F: for<'gc> FnOnce(Value<'gc>, &mut GcRoot<'gc>, &Mutation<'gc>)
let count = func.count.get();
func.count.set(count + 1);
if count >= 1 {
let compiled = func.compiled.borrow_mut(mc).get_or_insert_with(|| root.vm.compile_func(func.func)).clone();
let ret = unsafe { compiled.call(env.as_ref() as *const VmEnv, mc as *const _) };
let compiled = func
.compiled
.borrow_mut(mc)
.get_or_insert_with(|| root.vm.compile_func(func.func))
.clone();
let ret =
unsafe { compiled.call(env.as_ref() as *const VmEnv, mc as *const _) };
root.stack.push(ret.into())?;
} else {
root.envs.push(env);
@@ -173,15 +180,13 @@ fn single_op<'gc, const CAP: usize>(
) -> Result<Consq> {
match opcode {
OpCode::Illegal => panic!("illegal opcode"),
OpCode::Const { idx } => {
stack.push(match vm.get_const(idx) {
Const::Int(x) => Value::Int(x),
Const::Float(x) => Value::Float(x),
Const::Bool(x) => Value::Bool(x),
Const::String(x) => Value::String(CoW::new(x.into(), mc)),
Const::Null => Value::Null
})?
},
OpCode::Const { idx } => stack.push(match vm.get_const(idx) {
Const::Int(x) => Value::Int(x),
Const::Float(x) => Value::Float(x),
Const::Bool(x) => Value::Bool(x),
Const::String(x) => Value::String(CoW::new(x.into(), mc)),
Const::Null => Value::Null,
})?,
OpCode::LoadThunk { idx } => stack.push(Value::Thunk(Thunk::new(vm.get_thunk(idx), mc)))?,
OpCode::LoadValue { idx } => {
stack.push(Value::Thunk(Thunk::new(vm.get_thunk(idx), mc)))?;
@@ -415,6 +420,8 @@ impl<'gc> VM<'gc> {
}
pub fn compile_func(&'gc self, func: &'gc F) -> JITFunc<'gc> {
self.jit.compile_seq(func.opcodes.iter().copied(), self).unwrap()
self.jit
.compile_seq(func.opcodes.iter().copied(), self)
.unwrap()
}
}