chore: cargo fmt

This commit is contained in:
2025-05-20 18:30:24 +08:00
parent b4249ccd11
commit 736402dc53
7 changed files with 35 additions and 23 deletions

View File

@@ -93,7 +93,12 @@ impl<'ctx> Helpers<'ctx> {
let call = module.add_function( let call = module.add_function(
"call", "call",
value_type.fn_type( value_type.fn_type(
&[value_type.into(), ptr_type.into(), ptr_int_type.into(), ptr_type.into()], &[
value_type.into(),
ptr_type.into(),
ptr_int_type.into(),
ptr_type.into(),
],
false, false,
), ),
None, None,
@@ -207,9 +212,7 @@ extern "C" fn helper_debug(value: JITValue) {
#[unsafe(no_mangle)] #[unsafe(no_mangle)]
extern "C" fn helper_capture_env(thunk: JITValue, env: *const LetEnv) { extern "C" fn helper_capture_env(thunk: JITValue, env: *const LetEnv) {
let thunk: &Thunk = unsafe { std::mem::transmute(thunk.data.ptr.as_ref().unwrap()) }; let thunk: &Thunk = unsafe { std::mem::transmute(thunk.data.ptr.as_ref().unwrap()) };
let env = unsafe { let env = unsafe { Rc::from_raw(env) };
Rc::from_raw(env)
};
thunk.capture(env.clone()); thunk.capture(env.clone());
std::mem::forget(env); std::mem::forget(env);
} }
@@ -328,7 +331,10 @@ extern "C" fn helper_call<'jit, 'vm>(
vm: *const VM<'jit>, vm: *const VM<'jit>,
) -> JITValue { ) -> JITValue {
use ValueTag::*; use ValueTag::*;
let args = unsafe { Vec::from_raw_parts(args, arity, arity) }.into_iter().map(Value::from).collect(); let args = unsafe { Vec::from_raw_parts(args, arity, arity) }
.into_iter()
.map(Value::from)
.collect();
match func.tag { match func.tag {
Function => { Function => {
let func: Value = func.into(); let func: Value = func.into();

View File

@@ -1,3 +1,5 @@
#![allow(unused)]
extern crate test; extern crate test;
use hashbrown::{HashMap, HashSet}; use hashbrown::{HashMap, HashSet};

View File

@@ -44,7 +44,7 @@ impl<'jit: 'vm, 'vm> AttrSet<'jit, 'vm> {
pub fn select(&self, sym: usize) -> Option<Value<'jit, 'vm>> { pub fn select(&self, sym: usize) -> Option<Value<'jit, 'vm>> {
self.data.get(&sym).cloned().map(|val| match val { self.data.get(&sym).cloned().map(|val| match val {
Value::Builtins(x) => Value::AttrSet(x.upgrade().unwrap()), Value::Builtins(x) => Value::AttrSet(x.upgrade().unwrap()),
val => val val => val,
}) })
} }

View File

@@ -56,10 +56,7 @@ impl<'vm, 'jit: 'vm> Func<'jit, 'vm> {
use Param::*; use Param::*;
let env = match self.func.param.clone() { let env = match self.func.param.clone() {
Ident(ident) => self Ident(ident) => self.env.clone().enter_arg(ident.into(), arg),
.env
.clone()
.enter_arg(ident.into(), arg),
Formals { Formals {
formals, formals,
ellipsis, ellipsis,
@@ -92,7 +89,8 @@ impl<'vm, 'jit: 'vm> Func<'jit, 'vm> {
} }
self.env.clone().enter_attrs(AttrSet::new(new).into()) self.env.clone().enter_attrs(AttrSet::new(new).into())
} }
}.into(); }
.into();
let count = self.count.get(); let count = self.count.get();
self.count.replace(count + 1); self.count.replace(count + 1);

View File

@@ -26,22 +26,29 @@ enum Env<'jit, 'vm> {
pub enum Type { pub enum Type {
Arg, Arg,
Let, Let,
With With,
} }
impl<'jit, 'vm> LetEnv<'jit, 'vm> { impl<'jit, 'vm> LetEnv<'jit, 'vm> {
pub fn new(map: Rc<AttrSet<'jit, 'vm>>) -> Self { pub fn new(map: Rc<AttrSet<'jit, 'vm>>) -> Self {
Self { map: Env::Let(map), last: None } Self {
map: Env::Let(map),
last: None,
}
} }
pub fn lookup(&self, symbol: usize) -> Option<Value<'jit, 'vm>> { pub fn lookup(&self, symbol: usize) -> Option<Value<'jit, 'vm>> {
use Env::*; use Env::*;
match &self.map { match &self.map {
Let(map) | MultiArg(map) => if let Some(val) = map.select(symbol) { Let(map) | MultiArg(map) => {
return Some(val) if let Some(val) = map.select(symbol) {
return Some(val);
}
}
SingleArg(sym, val) => {
if *sym == symbol {
return Some(val.clone());
} }
SingleArg(sym, val) => if *sym == symbol {
return Some(val.clone())
} }
} }
self.last.as_ref().map(|env| env.lookup(symbol)).flatten() self.last.as_ref().map(|env| env.lookup(symbol)).flatten()

View File

@@ -189,12 +189,9 @@ impl<'vm, 'jit: 'vm> VM<'jit> {
stack.push(Value::AttrSet(AttrSet::with_capacity(cap).into()))?; stack.push(Value::AttrSet(AttrSet::with_capacity(cap).into()))?;
} }
OpCode::FinalizeRec => { OpCode::FinalizeRec => {
let env = env.clone().enter_attrs( let env = env
stack
.tos()?
.clone() .clone()
.unwrap_attr_set() .enter_attrs(stack.tos()?.clone().unwrap_attr_set());
);
stack.tos_mut()?.as_mut().unwrap_attr_set().capture(&env); stack.tos_mut()?.as_mut().unwrap_attr_set().capture(&env);
} }
OpCode::PushStaticAttr { name } => { OpCode::PushStaticAttr { name } => {

View File

@@ -1,3 +1,5 @@
#![allow(unused_macros)]
extern crate test; extern crate test;
use hashbrown::HashMap; use hashbrown::HashMap;