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(
"call",
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,
),
None,
@@ -207,9 +212,7 @@ extern "C" fn helper_debug(value: JITValue) {
#[unsafe(no_mangle)]
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 env = unsafe {
Rc::from_raw(env)
};
let env = unsafe { Rc::from_raw(env) };
thunk.capture(env.clone());
std::mem::forget(env);
}
@@ -328,7 +331,10 @@ extern "C" fn helper_call<'jit, 'vm>(
vm: *const VM<'jit>,
) -> JITValue {
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 {
Function => {
let func: Value = func.into();

View File

@@ -1,3 +1,5 @@
#![allow(unused)]
extern crate test;
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>> {
self.data.get(&sym).cloned().map(|val| match val {
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::*;
let env = match self.func.param.clone() {
Ident(ident) => self
.env
.clone()
.enter_arg(ident.into(), arg),
Ident(ident) => self.env.clone().enter_arg(ident.into(), arg),
Formals {
formals,
ellipsis,
@@ -92,7 +89,8 @@ impl<'vm, 'jit: 'vm> Func<'jit, 'vm> {
}
self.env.clone().enter_attrs(AttrSet::new(new).into())
}
}.into();
}
.into();
let count = self.count.get();
self.count.replace(count + 1);

View File

@@ -26,22 +26,29 @@ enum Env<'jit, 'vm> {
pub enum Type {
Arg,
Let,
With
With,
}
impl<'jit, 'vm> LetEnv<'jit, 'vm> {
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>> {
use Env::*;
match &self.map {
Let(map) | MultiArg(map) => if let Some(val) = map.select(symbol) {
return Some(val)
Let(map) | MultiArg(map) => {
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()

View File

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

View File

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