Skip to content

Commit

Permalink
Fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
mrLSD committed Feb 9, 2023
1 parent 3202a32 commit 486fe3d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 34 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
clippy:
@cargo clippy
@cargo clippy -- -D warnings

check:
@cargo check

release:
@cargo build --release

fmt:
@cargo +nightly fmt

Expand All @@ -29,7 +29,7 @@ cover:

tst:
@cargo test test_codegen_variable_let_and_print -- --nocapture

x: release
@target/release/i-lang tst.i
@ls -la build
@ls -la build
3 changes: 3 additions & 0 deletions src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub enum CodegenError {
}

/// Codegen structure
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct Codegen<'a> {
ctx: Context,
Expand All @@ -48,6 +49,7 @@ pub struct Codegen<'a> {
ast: &'a Main<'a>,
}

#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct FunctionDeclaration {
name: String,
Expand Down Expand Up @@ -587,6 +589,7 @@ impl<'a> Codegen<'a> {
pub fn fn_main(ast: &'a Main) -> Result {
#[cfg(feature = "fn_main")]
println!("\t#[call] fn_main");

let mut codegen = Self::new(ast);
let module = codegen.fn_module()?;
let global_let = codegen.fn_global_let()?;
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub fn ar_builder(app_name: String, build_dir: &str) -> Result<(), String> {
let a_file_name = format!("{}/lib{}.a", build_dir, app_name);

Command::new("ar")
.args(&["crs", &a_file_name, &obj_file_name])
.args(["crs", &a_file_name, &obj_file_name])
.spawn()
.map_err(|_| "Failed to run `ar` command".to_string())?
.wait()
Expand All @@ -95,7 +95,7 @@ pub fn ld_builder(app_name: String, build_dir: &str) -> Result<(), String> {
let obj_file = Path::new(&obj_file_name);

Command::new("ld")
.args(&[
.args([
"-o",
&app_file_name,
"-dynamic-linker",
Expand All @@ -121,7 +121,7 @@ pub fn gcc_builder(app_name: String, build_dir: &str) -> Result<(), String> {
let obj_file = Path::new(&obj_file_name);

Command::new("gcc")
.args(&["-o", &app_file_name, &a_file_name])
.args(["-o", &app_file_name, &a_file_name])
.spawn()
.map_err(|_| "Failed to run `gcc` command".to_string())?
.wait()
Expand Down
54 changes: 27 additions & 27 deletions src/llvm/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#[macro_export]
macro_rules! alloca {
($ty:ident $res:expr) => {
crate::llvm::instructions::memory_access_addressing_operations::Alloca {
$crate::llvm::instructions::memory_access_addressing_operations::Alloca {
result: $res.to_string(),
alloc_ty: $ty,
elements: None,
Expand All @@ -22,7 +22,7 @@ macro_rules! alloca {
}
};
($ty:ident $res:expr, $align:expr) => {
crate::llvm::instructions::memory_access_addressing_operations::Alloca {
$crate::llvm::instructions::memory_access_addressing_operations::Alloca {
result: $res.to_string(),
alloc_ty: $ty,
elements: None,
Expand Down Expand Up @@ -50,13 +50,13 @@ macro_rules! alloca {
macro_rules! arg {
($($ty:ident $val:expr)? $(,$ty1:ident $val1:expr)*) => {{
let mut v = vec![];
$( v.push(crate::llvm::functions::ArgumentList {
$( v.push($crate::llvm::functions::ArgumentList {
parameter_type: Some($ty),
attributes: None,
name: Some(format!("%{}", $val)),
variable_argument: false,
});)?
$( v.push(crate::llvm::functions::ArgumentList {
$( v.push($crate::llvm::functions::ArgumentList {
parameter_type: Some($ty1),
attributes: None,
name: Some(format!("%{}", $val1)),
Expand All @@ -66,19 +66,19 @@ macro_rules! arg {
}};
($($ty:ident $val:expr)? $(,$ty1:ident $val1:expr)*, ...) => {{
let mut v = vec![];
$( v.push(crate::llvm::functions::ArgumentList {
$( v.push($crate::llvm::functions::ArgumentList {
parameter_type: Some($ty),
attributes: None,
name: Some(format!("%{}", $val)),
variable_argument: false,
});)?
$( v.push(crate::llvm::functions::ArgumentList {
$( v.push($crate::llvm::functions::ArgumentList {
parameter_type: Some($ty1),
attributes: None,
name: Some(format!("%{}", $val1)),
variable_argument: false,
});)*
v.push(crate::llvm::functions::ArgumentList {
v.push($crate::llvm::functions::ArgumentList {
parameter_type: None,
attributes: None,
name: None,
Expand All @@ -88,13 +88,13 @@ macro_rules! arg {
}};
($($ty:ident)? $(,$ty1:ident)*) => {{
let mut v = vec![];
$( v.push(crate::llvm::functions::ArgumentList {
$( v.push($crate::llvm::functions::ArgumentList {
parameter_type: Some($ty),
attributes: None,
name: None,
variable_argument: false,
});)?
$( v.push(crate::llvm::functions::ArgumentList {
$( v.push($crate::llvm::functions::ArgumentList {
parameter_type: Some($ty1),
attributes: None,
name: None,
Expand All @@ -104,19 +104,19 @@ macro_rules! arg {
}};
($($ty:ident)? $(,$ty1:ident)*, ...) => {{
let mut v = vec![];
$( v.push(crate::llvm::functions::ArgumentList {
$( v.push($crate::llvm::functions::ArgumentList {
parameter_type: Some($ty),
attributes: None,
name: None,
variable_argument: false,
});)?
$( v.push(crate::llvm::functions::ArgumentList {
$( v.push($crate::llvm::functions::ArgumentList {
parameter_type: Some($ty1),
attributes: None,
name: None,
variable_argument: false,
});)*
v.push(crate::llvm::functions::ArgumentList {
v.push($crate::llvm::functions::ArgumentList {
parameter_type: None,
attributes: None,
name: None,
Expand Down Expand Up @@ -146,15 +146,15 @@ macro_rules! def {
$fnval.$attr = Some($val);
}};
($ty:ident $name:ident) => {{
crate::llvm::functions::Function {
definition_type: crate::llvm::functions::FunctionDefinitionType::Define,
$crate::llvm::functions::Function {
definition_type: $crate::llvm::functions::FunctionDefinitionType::Define,
linkage: None,
preemption_specifier: None,
visibility: None,
dll_storage_class: None,
cconv: None,
ret_attrs: None,
result_type: crate::llvm::types::Type::$ty,
result_type: $crate::llvm::types::Type::$ty,
function_name: $name.to_string(),
argument_list: vec![],
unnamed_addr: None,
Expand Down Expand Up @@ -194,7 +194,7 @@ macro_rules! decl {
}};
($ty:ident $name:ident) => {{
let mut f_decl = def!($ty $name);
let d = crate::llvm::functions::FunctionDefinitionType::Declare;
let d = $crate::llvm::functions::FunctionDefinitionType::Declare;
def!(f_decl.definition_type d);
f_decl
}};
Expand All @@ -209,7 +209,7 @@ macro_rules! decl {
#[macro_export]
macro_rules! source_file {
($name:expr) => {
crate::llvm::source_filename::SourceFileName($name.to_string());
$crate::llvm::source_filename::SourceFileName($name.to_string())
};
}

Expand All @@ -222,7 +222,7 @@ macro_rules! source_file {
#[macro_export]
macro_rules! target_triple {
($name:ident) => {
crate::llvm::target_triple::TargetTriple(crate::llvm::target_triple::$name.to_string());
$crate::llvm::target_triple::TargetTriple($crate::llvm::target_triple::$name.to_string())
};
}

Expand All @@ -249,7 +249,7 @@ macro_rules! global {
$var.$attr = Some($val);
}};
($kind:ident $ty:ident $name:expr) => {
crate::llvm::global_variables::GlobalVariable {
$crate::llvm::global_variables::GlobalVariable {
name: $name.to_string(),
linkage: None,
preemption_specifier: None,
Expand All @@ -258,7 +258,7 @@ macro_rules! global {
thread_local: None,
unnamed_addr: None,
addrspace: None,
global_variable_kind: crate::llvm::global_variables::GlobalVariableKind::$kind,
global_variable_kind: $crate::llvm::global_variables::GlobalVariableKind::$kind,
value_type: $ty,
initializer_constant: None,
section: None,
Expand Down Expand Up @@ -286,7 +286,7 @@ macro_rules! store {
$var.$attr = Some($val);
}};
($ty:ident $val:expr, $ptrval:expr) => {{
crate::llvm::instructions::memory_access_addressing_operations::Store {
$crate::llvm::instructions::memory_access_addressing_operations::Store {
volatile: None,
ty: $ty,
value: $val.to_string(),
Expand All @@ -312,7 +312,7 @@ macro_rules! load {
$var.$attr = Some($val);
}};
($ty:ident $res:expr, $ptrval:expr) => {{
crate::llvm::instructions::memory_access_addressing_operations::Load {
$crate::llvm::instructions::memory_access_addressing_operations::Load {
result: $res.to_string(),
volatile: None,
ty: $ty,
Expand All @@ -336,10 +336,10 @@ macro_rules! load {
#[macro_export]
macro_rules! ret {
($ty:ident @ $val:expr) => {{
crate::llvm::instructions::terminator::Ret(Some(($ty, $val.to_string())))
$crate::llvm::instructions::terminator::Ret(Some(($ty, $val.to_string())))
}};
() => {{
crate::llvm::instructions::terminator::Ret(None)
$crate::llvm::instructions::terminator::Ret(None)
}};
}

Expand Down Expand Up @@ -436,12 +436,12 @@ macro_rules! call {
)?

#[allow(unused_mut)]
let mut args: Vec< crate::llvm::instructions::terminator::FunctionArg> = vec![];
let mut args: Vec< $crate::llvm::instructions::terminator::FunctionArg> = vec![];
$(
args.push(crate::llvm::instructions::terminator::FunctionArg($argty1, $argval1));
args.push($crate::llvm::instructions::terminator::FunctionArg($argty1, $argval1));
)?
$(
args.push(crate::llvm::instructions::terminator::FunctionArg($argty2, $argval2));
args.push($crate::llvm::instructions::terminator::FunctionArg($argty2, $argval2));
)*

Call {
Expand Down
1 change: 1 addition & 0 deletions src/parser/ast.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::derive_partial_eq_without_eq)]
//! Full AST representation
//!
//! Based on *EBNF* grammar
Expand Down

0 comments on commit 486fe3d

Please sign in to comment.