diff --git a/src/jit/helpers.rs b/src/jit/helpers.rs index a5591b8..931fa12 100644 --- a/src/jit/helpers.rs +++ b/src/jit/helpers.rs @@ -103,7 +103,12 @@ impl<'ctx> Helpers<'ctx> { let call = module.add_function( "call", value_type.fn_type( - &[value_type.into(), value_type.into(), ptr_type.into(), ptr_type.into()], + &[ + value_type.into(), + value_type.into(), + ptr_type.into(), + ptr_type.into(), + ], false, ), None, @@ -115,7 +120,15 @@ impl<'ctx> Helpers<'ctx> { ); let force = module.add_function( "force", - value_type.fn_type(&[value_type.into(), ptr_type.into(), ptr_type.into(), ptr_type.into()], false), + value_type.fn_type( + &[ + value_type.into(), + ptr_type.into(), + ptr_type.into(), + ptr_type.into(), + ], + false, + ), None, ); @@ -341,7 +354,12 @@ extern "C" fn helper_lookup(sym: usize, env: *const VmEnv) -> JITValue { val } -extern "C" fn helper_force<'gc>(thunk: JITValue, vm: *const VM<'gc>, mc: *const Mutation<'gc>, jit: *const JITContext<'gc>) -> JITValue { +extern "C" fn helper_force<'gc>( + thunk: JITValue, + vm: *const VM<'gc>, + mc: *const Mutation<'gc>, + jit: *const JITContext<'gc>, +) -> JITValue { if !matches!(thunk.tag, ValueTag::Thunk) { return thunk; } @@ -350,10 +368,13 @@ extern "C" fn helper_force<'gc>(thunk: JITValue, vm: *const VM<'gc>, mc: *const let mc = unsafe { mc.as_ref() }.unwrap(); let thunk = Value::from(thunk).unwrap_thunk(); if let Some(val) = thunk.get_value() { - return val.into() + return val.into(); } let (opcodes, env) = thunk.suspend(mc).unwrap(); - let func = unsafe { jit.as_ref() }.unwrap().compile_seq(opcodes.iter().copied(), vm).unwrap(); + let func = unsafe { jit.as_ref() } + .unwrap() + .compile_seq(opcodes.iter().copied(), vm) + .unwrap(); let val = unsafe { func.call(env.as_ref() as *const _, mc as *const _) }; thunk.insert_value(val.into(), mc); val diff --git a/src/ty/internal/mod.rs b/src/ty/internal/mod.rs index 0ce0c63..84e9f42 100644 --- a/src/ty/internal/mod.rs +++ b/src/ty/internal/mod.rs @@ -427,7 +427,7 @@ impl<'gc> Value<'gc> { (Value::String(a), Value::String(b)) => { let mut a = a.clone(); a.make_mut(mc).push_str(b.as_str()) - }, + } (_, Value::Catchable(_)) => *self = other, (Value::Catchable(_), _) => (), _ => todo!(), @@ -608,7 +608,7 @@ impl<'gc> Thunk<'gc> { let _Thunk::Code(opcodes, env) = std::mem::replace(&mut *self.thunk.borrow_mut(mc), _Thunk::Suspended) else { - return Err(Error::EvalError("infinite recursion occured".into())) + return Err(Error::EvalError("infinite recursion occured".into())); }; Ok((opcodes, env.unwrap())) } diff --git a/src/vm/mod.rs b/src/vm/mod.rs index e175382..f391f99 100644 --- a/src/vm/mod.rs +++ b/src/vm/mod.rs @@ -34,7 +34,9 @@ pub fn run(mut prog: Program) -> Result { 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 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 { 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() } }