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