mirror of
https://github.com/exoticorn/curlywas.git
synced 2026-01-20 19:56:42 +01:00
clippy fixes
This commit is contained in:
@@ -288,7 +288,7 @@ impl Expr {
|
||||
Expression {
|
||||
type_: None,
|
||||
expr: self,
|
||||
span: span,
|
||||
span,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ pub fn emit(script: &ast::Script, module_name: &str, options: &Options) -> Vec<u
|
||||
function_map.insert(name.clone(), function_map.len() as u32);
|
||||
EntityType::Function(
|
||||
*function_types
|
||||
.get(&(params.clone(), result.clone()))
|
||||
.get(&(params.clone(), *result))
|
||||
.unwrap() as u32,
|
||||
)
|
||||
}
|
||||
@@ -255,7 +255,7 @@ fn collect_function_types(script: &ast::Script) -> HashMap<FunctionTypeKey, usiz
|
||||
{
|
||||
let index = types.len();
|
||||
types
|
||||
.entry((params.clone(), result.clone()))
|
||||
.entry((params.clone(), *result))
|
||||
.or_insert(index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,20 +9,18 @@ pub fn resolve_includes(script: &mut ast::Script, path: &Path) -> Result<()> {
|
||||
let script_dir = path.parent().expect("Script path has no parent");
|
||||
for data in &mut script.data {
|
||||
for values in &mut data.data {
|
||||
match values {
|
||||
ast::DataValues::File {
|
||||
ref path,
|
||||
ref mut data,
|
||||
} => {
|
||||
let mut full_path = script_dir.to_path_buf();
|
||||
full_path.push(path);
|
||||
File::open(&full_path)
|
||||
.map_err(|e| {
|
||||
anyhow!("Failed to load data from {}: {}", full_path.display(), e)
|
||||
})?
|
||||
.read_to_end(data)?;
|
||||
}
|
||||
_ => (),
|
||||
if let ast::DataValues::File {
|
||||
ref path,
|
||||
ref mut data,
|
||||
} = values
|
||||
{
|
||||
let mut full_path = script_dir.to_path_buf();
|
||||
full_path.push(path);
|
||||
File::open(&full_path)
|
||||
.map_err(|e| {
|
||||
anyhow!("Failed to load data from {}: {}", full_path.display(), e)
|
||||
})?
|
||||
.read_to_end(data)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,10 +20,7 @@ pub struct Options {
|
||||
|
||||
impl Options {
|
||||
pub fn with_debug(self) -> Self {
|
||||
Options {
|
||||
debug: true,
|
||||
..self
|
||||
}
|
||||
Options { debug: true }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +33,7 @@ pub fn compile_file<P: AsRef<Path>>(path: P, options: Options) -> Result<Vec<u8>
|
||||
}
|
||||
|
||||
pub fn compile_str(input: &str, path: &Path, options: Options) -> Result<Vec<u8>> {
|
||||
let mut script = match parser::parse(&input) {
|
||||
let mut script = match parser::parse(input) {
|
||||
Ok(script) => script,
|
||||
Err(_) => bail!("Parse failed"),
|
||||
};
|
||||
@@ -44,7 +41,7 @@ pub fn compile_str(input: &str, path: &Path, options: Options) -> Result<Vec<u8>
|
||||
includes::resolve_includes(&mut script, path)?;
|
||||
|
||||
constfold::fold_script(&mut script);
|
||||
if let Err(_) = typecheck::tc_script(&mut script, &input) {
|
||||
if typecheck::tc_script(&mut script, input).is_err() {
|
||||
bail!("Type check failed");
|
||||
}
|
||||
let wasm = emit::emit(
|
||||
|
||||
@@ -183,7 +183,8 @@ fn lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = Simple<char>> {
|
||||
u64::from_str_radix(&n, 16).map_err(|err| Simple::custom(span, err.to_string()))
|
||||
})
|
||||
.or(text::int(10).try_map(|n: String, span: Span| {
|
||||
u64::from_str_radix(&n, 10).map_err(|err| Simple::custom(span, err.to_string()))
|
||||
n.parse::<u64>()
|
||||
.map_err(|err| Simple::custom(span, err.to_string()))
|
||||
}))
|
||||
.boxed();
|
||||
|
||||
@@ -358,7 +359,7 @@ fn script_parser() -> impl Parser<Token, ast::Script, Error = Simple<Token>> + C
|
||||
|
||||
let branch = just(Token::Branch)
|
||||
.ignore_then(identifier)
|
||||
.map(|label| ast::Expr::Branch(label));
|
||||
.map(ast::Expr::Branch);
|
||||
|
||||
let branch_if = just(Token::BranchIf)
|
||||
.ignore_then(expression.clone())
|
||||
@@ -377,7 +378,7 @@ fn script_parser() -> impl Parser<Token, ast::Script, Error = Simple<Token>> + C
|
||||
.or(just(Token::Inline).to(ast::LetType::Inline)))
|
||||
.or_not(),
|
||||
)
|
||||
.then(identifier.clone())
|
||||
.then(identifier)
|
||||
.then(just(Token::Ctrl(':')).ignore_then(type_parser()).or_not())
|
||||
.then(
|
||||
just(Token::Op("=".to_string()))
|
||||
@@ -394,7 +395,6 @@ fn script_parser() -> impl Parser<Token, ast::Script, Error = Simple<Token>> + C
|
||||
.boxed();
|
||||
|
||||
let assign = identifier
|
||||
.clone()
|
||||
.then_ignore(just(Token::Op("=".to_string())))
|
||||
.then(expression.clone())
|
||||
.map(|(name, value)| ast::Expr::Assign {
|
||||
@@ -422,7 +422,6 @@ fn script_parser() -> impl Parser<Token, ast::Script, Error = Simple<Token>> + C
|
||||
.boxed();
|
||||
|
||||
let function_call = identifier
|
||||
.clone()
|
||||
.then(
|
||||
expression
|
||||
.clone()
|
||||
@@ -676,7 +675,7 @@ fn script_parser() -> impl Parser<Token, ast::Script, Error = Simple<Token>> + C
|
||||
})
|
||||
.boxed();
|
||||
|
||||
let op_first = op_bit
|
||||
op_bit
|
||||
.clone()
|
||||
.then(
|
||||
just(Token::Op("<|".to_string()))
|
||||
@@ -691,9 +690,7 @@ fn script_parser() -> impl Parser<Token, ast::Script, Error = Simple<Token>> + C
|
||||
}
|
||||
.with_span(span)
|
||||
})
|
||||
.boxed();
|
||||
|
||||
op_first
|
||||
.boxed()
|
||||
});
|
||||
|
||||
expression_out = Some(expression.clone());
|
||||
@@ -718,7 +715,7 @@ fn script_parser() -> impl Parser<Token, ast::Script, Error = Simple<Token>> + C
|
||||
}
|
||||
ast::Expr::Block {
|
||||
statements: statements.into_iter().map(|(expr, _)| expr).collect(),
|
||||
final_expression: final_expression.map(|e| Box::new(e)),
|
||||
final_expression: final_expression.map(Box::new),
|
||||
}
|
||||
.with_span(span)
|
||||
})
|
||||
@@ -740,7 +737,7 @@ fn script_parser() -> impl Parser<Token, ast::Script, Error = Simple<Token>> + C
|
||||
|
||||
let import_global = just(Token::Global)
|
||||
.ignore_then(just(Token::Mut).or_not())
|
||||
.then(identifier.clone())
|
||||
.then(identifier)
|
||||
.then_ignore(just(Token::Ctrl(':')))
|
||||
.then(type_parser())
|
||||
.map(|((mut_opt, name), type_)| ast::ImportType::Variable {
|
||||
@@ -751,7 +748,7 @@ fn script_parser() -> impl Parser<Token, ast::Script, Error = Simple<Token>> + C
|
||||
.boxed();
|
||||
|
||||
let import_function = just(Token::Fn)
|
||||
.ignore_then(identifier.clone())
|
||||
.ignore_then(identifier)
|
||||
.then(
|
||||
type_parser()
|
||||
.separated_by(just(Token::Ctrl(',')))
|
||||
@@ -783,7 +780,6 @@ fn script_parser() -> impl Parser<Token, ast::Script, Error = Simple<Token>> + C
|
||||
.boxed();
|
||||
|
||||
let parameter = identifier
|
||||
.clone()
|
||||
.then_ignore(just(Token::Ctrl(':')))
|
||||
.then(type_parser())
|
||||
.boxed();
|
||||
@@ -792,7 +788,7 @@ fn script_parser() -> impl Parser<Token, ast::Script, Error = Simple<Token>> + C
|
||||
.or_not()
|
||||
.then(just(Token::Ident("start".to_string())).or_not())
|
||||
.then_ignore(just(Token::Fn))
|
||||
.then(identifier.clone())
|
||||
.then(identifier)
|
||||
.then(
|
||||
parameter
|
||||
.separated_by(just(Token::Ctrl(',')))
|
||||
@@ -820,7 +816,7 @@ fn script_parser() -> impl Parser<Token, ast::Script, Error = Simple<Token>> + C
|
||||
|
||||
let global = just(Token::Global)
|
||||
.ignore_then(just(Token::Mut).or_not())
|
||||
.then(identifier.clone())
|
||||
.then(identifier)
|
||||
.then(just(Token::Ctrl(':')).ignore_then(type_parser()).or_not())
|
||||
.then(just(Token::Op("=".to_string())).ignore_then(expression.clone()))
|
||||
.then_ignore(just(Token::Ctrl(';')))
|
||||
@@ -850,7 +846,7 @@ fn script_parser() -> impl Parser<Token, ast::Script, Error = Simple<Token>> + C
|
||||
)
|
||||
.map(|(type_, values)| ast::DataValues::Array { type_, values });
|
||||
|
||||
let data_string = string.clone().map(|s| ast::DataValues::String(s));
|
||||
let data_string = string.clone().map(ast::DataValues::String);
|
||||
|
||||
let data_file = just(Token::Ident("file".to_string()))
|
||||
.ignore_then(
|
||||
|
||||
@@ -160,7 +160,7 @@ pub fn tc_script(script: &mut ast::Script, source: &str) -> Result<()> {
|
||||
context.locals.locals[index].index = Some((locals_start + id) as u32);
|
||||
}
|
||||
|
||||
f.locals = std::mem::replace(&mut context.locals, ast::Locals::default());
|
||||
f.locals = std::mem::take(&mut context.locals);
|
||||
|
||||
if f.body.type_ != f.type_ {
|
||||
result = type_mismatch(f.type_, &f.span, f.body.type_, &f.body.span, source);
|
||||
@@ -333,7 +333,7 @@ fn type_mismatch(
|
||||
"Expected type {:?}...",
|
||||
type1
|
||||
.map(|t| format!("{:?}", t))
|
||||
.unwrap_or("void".to_string())
|
||||
.unwrap_or_else(|| "void".to_string())
|
||||
))
|
||||
.with_color(Color::Yellow),
|
||||
)
|
||||
@@ -343,7 +343,7 @@ fn type_mismatch(
|
||||
"...but found type {}",
|
||||
type2
|
||||
.map(|t| format!("{:?}", t))
|
||||
.unwrap_or("void".to_string())
|
||||
.unwrap_or_else(|| "void".to_string())
|
||||
))
|
||||
.with_color(Color::Red),
|
||||
)
|
||||
@@ -406,7 +406,7 @@ fn missing_label(span: &Span, source: &str) -> Result<()> {
|
||||
.finish()
|
||||
.eprint(Source::from(source))
|
||||
.unwrap();
|
||||
return Err(());
|
||||
Err(())
|
||||
}
|
||||
|
||||
fn tc_expression(context: &mut Context, expr: &mut ast::Expression) -> Result<()> {
|
||||
|
||||
Reference in New Issue
Block a user