chore: cargo clippy
This commit is contained in:
@@ -13,6 +13,12 @@ pub struct Env {
|
||||
args: Vec<Value>,
|
||||
}
|
||||
|
||||
impl Default for Env {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Env {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use cranelift::codegen::ir::{self, BlockCall, StackSlot, ValueListPool};
|
||||
use cranelift::codegen::ir::{self, StackSlot};
|
||||
use cranelift::prelude::*;
|
||||
|
||||
use crate::eval::Evaluate;
|
||||
use crate::ir::*;
|
||||
use crate::ty::common as c;
|
||||
use crate::ty::internal::Value;
|
||||
@@ -493,7 +492,7 @@ impl JITCompile for Const {
|
||||
}
|
||||
Int(x) => {
|
||||
let tag = ctx.builder.ins().iconst(types::I64, Value::INT as i64);
|
||||
let val = ctx.builder.ins().iconst(types::I64, x as i64);
|
||||
let val = ctx.builder.ins().iconst(types::I64, x);
|
||||
ctx.builder.ins().stack_store(tag, slot, 0);
|
||||
ctx.builder.ins().stack_store(val, slot, 8);
|
||||
}
|
||||
|
||||
@@ -21,12 +21,12 @@ pub extern "C" fn helper_call(
|
||||
// TODO: Error Handling
|
||||
let args = core::ptr::slice_from_raw_parts_mut(args_ptr, args_len);
|
||||
let args = unsafe { Box::from_raw(args) };
|
||||
func.call(args.into_iter().map(Value::from).collect(), engine, env)
|
||||
func.call(args.into_iter().collect(), engine, env)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
pub extern "C" fn helper_lookup_arg(env: &Env, level: usize, ret: &mut MaybeUninit<Value>) {
|
||||
ret.write(env.lookup_arg(level as usize));
|
||||
ret.write(env.lookup_arg(level));
|
||||
}
|
||||
|
||||
pub extern "C" fn helper_lookup(
|
||||
|
||||
@@ -348,13 +348,19 @@ pub struct JITCompiler {
|
||||
dbg: FuncId,
|
||||
}
|
||||
|
||||
impl Default for JITCompiler {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl JITCompiler {
|
||||
pub fn new() -> Self {
|
||||
let mut flag_builder = settings::builder();
|
||||
flag_builder.set("use_colocated_libcalls", "false").unwrap();
|
||||
flag_builder.set("is_pic", "false").unwrap();
|
||||
let isa_builder = cranelift_native::builder().unwrap_or_else(|msg| {
|
||||
panic!("host machine is not supported: {}", msg);
|
||||
panic!("host machine is not supported: {msg}");
|
||||
});
|
||||
let isa = isa_builder
|
||||
.finish(settings::Flags::new(flag_builder))
|
||||
@@ -650,7 +656,7 @@ impl JITCompiler {
|
||||
|
||||
let strings = ctx.strings;
|
||||
if cfg!(debug_assertions) {
|
||||
println!("{:?}", ir);
|
||||
println!("{ir:?}");
|
||||
println!("{}", func.display());
|
||||
}
|
||||
self.ctx.func = func;
|
||||
|
||||
@@ -42,8 +42,8 @@ impl Evaluate for ir::List {
|
||||
.items
|
||||
.iter()
|
||||
.map(|val| {
|
||||
let eval_result = val.eval(engine, env);
|
||||
eval_result
|
||||
|
||||
val.eval(engine, env)
|
||||
})
|
||||
.collect::<Result<EcoVec<_>>>()?;
|
||||
let result = Value::List(List::from(items)).ok();
|
||||
@@ -186,12 +186,12 @@ impl Evaluate for ir::If {
|
||||
let mut cond = self.cond.eval(engine, env)?;
|
||||
cond.force(engine, env)?;
|
||||
let cond = cond.unwrap_bool();
|
||||
let result = if cond {
|
||||
|
||||
if cond {
|
||||
self.consq.eval(engine, env)
|
||||
} else {
|
||||
self.alter.eval(engine, env)
|
||||
};
|
||||
result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,13 +284,13 @@ impl Evaluate for ir::Const {
|
||||
|
||||
impl Evaluate for ir::Var {
|
||||
fn eval(&self, _: &mut Engine, env: &mut Env) -> Result<Value> {
|
||||
let result = env.lookup_with(&self.sym).ok_or_else(|| {
|
||||
|
||||
env.lookup_with(&self.sym).ok_or_else(|| {
|
||||
Error::EvalError(format!(
|
||||
"variable {} not found",
|
||||
Symbol::from(self.sym.clone())
|
||||
))
|
||||
});
|
||||
result
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,12 +315,12 @@ impl Evaluate for ir::Thunk {
|
||||
|
||||
impl Evaluate for ir::MaybeThunk {
|
||||
fn eval(&self, engine: &mut Engine, env: &mut Env) -> Result<Value> {
|
||||
let result = match self {
|
||||
|
||||
match self {
|
||||
ir::MaybeThunk::Const(cnst) => cnst.eval(engine, env),
|
||||
ir::MaybeThunk::String(string) => string.eval(engine, env),
|
||||
ir::MaybeThunk::Thunk(thunk) => thunk.eval(engine, env),
|
||||
};
|
||||
result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -136,6 +136,12 @@ impl<'a, 'env> Env<'a, 'env> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for DowngradeContext {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl DowngradeContext {
|
||||
pub fn new() -> Self {
|
||||
DowngradeContext {
|
||||
|
||||
@@ -200,7 +200,6 @@ impl Attrs {
|
||||
mut path: impl Iterator<Item = Attr>,
|
||||
name: Attr,
|
||||
value: Ir,
|
||||
ctx: &mut DowngradeContext,
|
||||
) -> Result<()> {
|
||||
if let Some(attr) = path.next() {
|
||||
match attr {
|
||||
@@ -222,13 +221,13 @@ impl Attrs {
|
||||
Symbol::from(ident)
|
||||
))
|
||||
})
|
||||
.and_then(|attrs: &mut Attrs| attrs._insert(path, name, value, ctx)),
|
||||
.and_then(|attrs: &mut Attrs| attrs._insert(path, name, value)),
|
||||
Attr::Strs(string) => {
|
||||
let mut attrs = Attrs {
|
||||
stcs: HashMap::new(),
|
||||
dyns: Vec::new(),
|
||||
};
|
||||
attrs._insert(path, name, value, ctx)?;
|
||||
attrs._insert(path, name, value)?;
|
||||
self.dyns.push(DynAttr(string.ir(), attrs.ir()));
|
||||
Ok(())
|
||||
}
|
||||
@@ -237,7 +236,7 @@ impl Attrs {
|
||||
stcs: HashMap::new(),
|
||||
dyns: Vec::new(),
|
||||
};
|
||||
attrs._insert(path, name, value, ctx)?;
|
||||
attrs._insert(path, name, value)?;
|
||||
self.dyns.push(DynAttr(dynamic, attrs.ir()));
|
||||
Ok(())
|
||||
}
|
||||
@@ -263,10 +262,10 @@ impl Attrs {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, path: Vec<Attr>, value: Ir, ctx: &mut DowngradeContext) -> Result<()> {
|
||||
pub fn insert(&mut self, path: Vec<Attr>, value: Ir) -> Result<()> {
|
||||
let mut path = path.into_iter();
|
||||
let name = path.next_back().unwrap();
|
||||
self._insert(path, name, value, ctx)
|
||||
self._insert(path, name, value)
|
||||
}
|
||||
|
||||
fn _has_attr(&self, mut path: std::slice::Iter<Attr>, name: Attr) -> Option<bool> {
|
||||
@@ -310,7 +309,7 @@ impl Attrs {
|
||||
.map(|res| Some(res.clone()))
|
||||
.map_or_else(
|
||||
|| {
|
||||
if self.dyns.len() > 0 {
|
||||
if !self.dyns.is_empty() {
|
||||
Ok(None)
|
||||
} else {
|
||||
Err(Error::DowngradeError(format!(
|
||||
@@ -556,7 +555,7 @@ impl Downgrade for ast::Path {
|
||||
.parts()
|
||||
.map(|part| match part {
|
||||
ast::InterpolPart::Literal(lit) => Str {
|
||||
val: lit.to_string().into(),
|
||||
val: lit.to_string(),
|
||||
}
|
||||
.ir()
|
||||
.ok(),
|
||||
@@ -600,7 +599,7 @@ impl Downgrade for ast::Str {
|
||||
.normalized_parts()
|
||||
.into_iter()
|
||||
.map(|part| match part {
|
||||
ast::InterpolPart::Literal(lit) => Str { val: lit.into() }.ir().ok(),
|
||||
ast::InterpolPart::Literal(lit) => Str { val: lit }.ir().ok(),
|
||||
ast::InterpolPart::Interpolation(interpol) => {
|
||||
interpol.expr().unwrap().downgrade(ctx)
|
||||
}
|
||||
@@ -639,7 +638,7 @@ impl Downgrade for ast::Literal {
|
||||
ast::LiteralKind::Integer(int) => Const::from(int.value().unwrap()).ir(),
|
||||
ast::LiteralKind::Float(float) => Const::from(float.value().unwrap()).ir(),
|
||||
ast::LiteralKind::Uri(uri) => Str {
|
||||
val: uri.to_string().into(),
|
||||
val: uri.to_string(),
|
||||
}
|
||||
.ir(),
|
||||
}
|
||||
@@ -671,7 +670,7 @@ impl Str {
|
||||
|
||||
impl Downgrade for ast::Ident {
|
||||
fn downgrade(self, _: &mut DowngradeContext) -> Result<Ir> {
|
||||
let sym = self.ident_token().unwrap().to_string().into();
|
||||
let sym = self.ident_token().unwrap().to_string();
|
||||
Var { sym }.ir().ok()
|
||||
}
|
||||
}
|
||||
@@ -1061,14 +1060,12 @@ impl Let {
|
||||
env: &Env<'a, 'env>,
|
||||
) -> Result<Ir> {
|
||||
let map = self.bindings.clone();
|
||||
let mut env = env.enter_let(&map);
|
||||
let env = env.enter_let(&map);
|
||||
self.bindings
|
||||
.into_iter()
|
||||
.map(|(_, ir)| {
|
||||
ir.resolve(self_idx, ctx, &mut env)?;
|
||||
.into_iter().try_for_each(|(_, ir)| {
|
||||
ir.resolve(self_idx, ctx, &env)?;
|
||||
Ok(())
|
||||
})
|
||||
.collect::<Result<()>>()?;
|
||||
})?;
|
||||
self.expr.resolve(self_idx, ctx, &env)?.ok()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use super::*;
|
||||
|
||||
pub fn downgrade_param(param: ast::Param, ctx: &mut DowngradeContext) -> Result<Param> {
|
||||
match param {
|
||||
ast::Param::IdentParam(ident) => Ok(Param::Ident(ident.to_string().into())),
|
||||
ast::Param::IdentParam(ident) => Ok(Param::Ident(ident.to_string())),
|
||||
ast::Param::Pattern(pattern) => downgrade_pattern(pattern, ctx),
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ pub fn downgrade_pattern(pattern: ast::Pattern, ctx: &mut DowngradeContext) -> R
|
||||
let formals = pattern
|
||||
.pat_entries()
|
||||
.map(|entry| {
|
||||
let ident = entry.ident().unwrap().to_string().into();
|
||||
let ident = entry.ident().unwrap().to_string();
|
||||
if entry.default().is_none() {
|
||||
Ok((ident, None))
|
||||
} else {
|
||||
@@ -28,7 +28,7 @@ pub fn downgrade_pattern(pattern: ast::Pattern, ctx: &mut DowngradeContext) -> R
|
||||
let ellipsis = pattern.ellipsis_token().is_some();
|
||||
let alias = pattern
|
||||
.pat_bind()
|
||||
.map(|alias| alias.ident().unwrap().to_string().into());
|
||||
.map(|alias| alias.ident().unwrap().to_string());
|
||||
Ok(Param::Formals {
|
||||
formals,
|
||||
ellipsis,
|
||||
@@ -94,14 +94,14 @@ pub fn downgrade_attr(attr: ast::Attr, ctx: &mut DowngradeContext) -> Result<Att
|
||||
use ast::Attr::*;
|
||||
use ast::InterpolPart::*;
|
||||
match attr {
|
||||
Ident(ident) => Ok(Attr::Str(ident.to_string().into())),
|
||||
Ident(ident) => Ok(Attr::Str(ident.to_string())),
|
||||
Str(string) => {
|
||||
let parts = string.normalized_parts();
|
||||
if parts.is_empty() {
|
||||
Ok(Attr::Str("".into()))
|
||||
} else if parts.len() == 1 {
|
||||
match parts.into_iter().next().unwrap() {
|
||||
Literal(ident) => Ok(Attr::Str(ident.into())),
|
||||
Literal(ident) => Ok(Attr::Str(ident)),
|
||||
Interpolation(interpol) => {
|
||||
Ok(Attr::Dynamic(interpol.expr().unwrap().downgrade(ctx)?))
|
||||
}
|
||||
@@ -110,7 +110,7 @@ pub fn downgrade_attr(attr: ast::Attr, ctx: &mut DowngradeContext) -> Result<Att
|
||||
let parts = parts
|
||||
.into_iter()
|
||||
.map(|part| match part {
|
||||
Literal(lit) => self::Str { val: lit.into() }.ir().ok(),
|
||||
Literal(lit) => self::Str { val: lit }.ir().ok(),
|
||||
Interpolation(interpol) => interpol.expr().unwrap().downgrade(ctx),
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
@@ -142,5 +142,5 @@ pub fn downgrade_attrpathvalue(
|
||||
x @ Ir::Const(_) => x,
|
||||
x => ctx.new_thunk(x).ir(),
|
||||
};
|
||||
attrs.insert(path, value, ctx)
|
||||
attrs.insert(path, value)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ impl Default for List {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'gc, T: Into<EcoVec<Value>>> From<T> for List {
|
||||
impl<T: Into<EcoVec<Value>>> From<T> for List {
|
||||
fn from(value: T) -> Self {
|
||||
Self { data: value.into() }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user