From ec10c9f939e26541d634551de1112b8339bf059a Mon Sep 17 00:00:00 2001 From: Robert-M-Lucas <100799838+Robert-M-Lucas@users.noreply.github.com> Date: Fri, 2 Aug 2024 12:45:50 +0100 Subject: [PATCH] Refactoring --- .idea/workspace.xml | 90 +++++++++++++++--- main.why | 2 - src/main.rs | 4 - src/root.rs | 17 ++-- src/root/builtin/core/referencing.rs | 2 +- src/root/builtin/functions/exit.rs | 2 +- src/root/builtin/types/bool/and.rs | 8 +- src/root/builtin/types/bool/mod.rs | 20 ++-- src/root/builtin/types/bool/not.rs | 6 +- src/root/builtin/types/bool/or.rs | 9 +- src/root/builtin/types/int/add.rs | 2 +- src/root/builtin/types/int/div.rs | 2 +- src/root/builtin/types/int/mod.rs | 7 +- src/root/builtin/types/int/modulo.rs | 2 +- src/root/builtin/types/int/mul.rs | 2 +- src/root/builtin/types/int/p_add.rs | 7 +- src/root/builtin/types/int/p_sub.rs | 2 +- src/root/compiler/assembly/heap.rs | 4 +- src/root/compiler/assembly/null.rs | 2 +- src/root/compiler/assembly/utils.rs | 1 + src/root/compiler/compile.rs | 9 +- src/root/compiler/compile_function.rs | 7 +- src/root/compiler/compiler_errors.rs | 4 +- src/root/compiler/evaluation/function_only.rs | 2 +- src/root/compiler/evaluation/into.rs | 27 +++--- src/root/compiler/evaluation/mod.rs | 15 ++- src/root/compiler/evaluation/new.rs | 78 +++++++-------- src/root/compiler/evaluation/reference.rs | 8 +- src/root/compiler/evaluation/type_only.rs | 10 +- src/root/errors/mod.rs | 1 + src/root/errors/parser_errors.rs | 2 +- src/root/name_resolver/name_resolvers.rs | 8 +- src/root/name_resolver/resolve_names.rs | 3 +- src/root/name_resolver/resolve_type_sizes.rs | 7 +- src/root/parser/handle_errors.rs | 6 +- src/root/parser/parse.rs | 27 +++--- src/root/parser/parse_arguments.rs | 4 +- src/root/parser/parse_blocks.rs | 36 +++---- src/root/parser/parse_function.rs | 2 +- src/root/parser/parse_function/parse_break.rs | 1 - .../parser/parse_function/parse_evaluable.rs | 94 ++++++++++--------- src/root/parser/parse_function/parse_if.rs | 6 +- .../parse_function/parse_initialisation.rs | 6 +- src/root/parser/parse_function/parse_line.rs | 20 ++-- .../parser/parse_function/parse_literal.rs | 1 - .../parser/parse_function/parse_marker.rs | 20 ++-- .../parser/parse_function/parse_operator.rs | 1 - .../parser/parse_function/parse_return.rs | 6 +- .../parse_function/parse_struct_init.rs | 20 ++-- src/root/parser/parse_function/parse_while.rs | 7 +- src/root/parser/parse_parameters.rs | 7 +- src/root/parser/parse_util.rs | 53 +++++------ src/root/runner.rs | 2 +- src/root/shared/common.rs | 3 +- src/root/shared/types.rs | 1 - src/root/unrandom.rs | 4 + src/root/utils.rs | 5 +- 57 files changed, 367 insertions(+), 337 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index c306b79..a09d2e1 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -7,7 +7,65 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -714,7 +776,6 @@ - @@ -739,7 +800,8 @@ - diff --git a/main.why b/main.why index 9411b23..47a811a 100644 --- a/main.why +++ b/main.why @@ -11,7 +11,5 @@ impl Test { fn main() -> int { let x: Test = Test { a: 3 }; - ::a; - return 8; } diff --git a/src/main.rs b/src/main.rs index 4f08836..ea21d62 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,3 @@ -use crate::root::parser::parse::ErrorTree; -use nom::character::complete::anychar; -use nom::{AsBytes, IResult}; - mod root; fn main() { diff --git a/src/root.rs b/src/root.rs index 589402d..58c1691 100644 --- a/src/root.rs +++ b/src/root.rs @@ -109,21 +109,18 @@ pub fn main_args(args: Args) -> Result<(), WErr> { link_gcc(&args.output).unwrap(); let end = t.elapsed(); // TODO: Don't unwrap - let size = format!( - "{}", - File::open(format!("{}.out", args.output)) - .unwrap() - .metadata() - .unwrap() - .len() - .to_formatted_string(&Locale::en) - ); + let size = File::open(format!("{}.out", args.output)) + .unwrap() + .metadata() + .unwrap() + .len() + .to_formatted_string(&Locale::en); cprintln!("Completed [{:?}] - {} bytes", end, size); if args.build { println!("Skipping execution") } else { - let termsize::Size { rows, cols } = termsize::get().unwrap(); + let termsize::Size { rows: _, cols } = termsize::get().unwrap(); const EXECUTING: &str = "Executing"; if cols < EXECUTING.len() as u16 || cols > 300 { cprintln!("Executing..."); diff --git a/src/root/builtin/core/referencing.rs b/src/root/builtin/core/referencing.rs index 2bcc7bf..49d4132 100644 --- a/src/root/builtin/core/referencing.rs +++ b/src/root/builtin/core/referencing.rs @@ -1,4 +1,4 @@ -use crate::root::compiler::assembly::utils::{copy_from_indirect, copy_from_indirect_fixed_offset}; +use crate::root::compiler::assembly::utils::copy_from_indirect; use crate::root::errors::evaluable_errors::EvalErrs; use crate::root::errors::WErr; use crate::root::name_resolver::name_resolvers::GlobalDefinitionTable; diff --git a/src/root/builtin/functions/exit.rs b/src/root/builtin/functions/exit.rs index 5812965..1f69f67 100644 --- a/src/root/builtin/functions/exit.rs +++ b/src/root/builtin/functions/exit.rs @@ -33,7 +33,7 @@ impl BuiltinInlineFunction for ExitFunction { } fn inline(&self) -> InlineFunctionGenerator { - |args: &[LocalAddress], _, gt, sz| -> String { + |args: &[LocalAddress], _, _, _| -> String { let lhs = &args[0]; // 0 us exit syscall diff --git a/src/root/builtin/types/bool/and.rs b/src/root/builtin/types/bool/and.rs index 49847ec..910e33c 100644 --- a/src/root/builtin/types/bool/and.rs +++ b/src/root/builtin/types/bool/and.rs @@ -1,11 +1,11 @@ +use unique_type_id::UniqueTypeId; + use crate::root::builtin::types::bool::printb::PrintB; use crate::root::builtin::types::bool::{bool_op_sig, BoolType}; -use crate::root::builtin::types::int::IntType; use crate::root::builtin::{f_id, BuiltinInlineFunction, InlineFunctionGenerator}; use crate::root::name_resolver::resolve_function_signatures::FunctionSignature; use crate::root::parser::parse_parameters::SelfType; use crate::root::shared::common::{FunctionID, LocalAddress, TypeID}; -use unique_type_id::UniqueTypeId; #[derive(UniqueTypeId)] #[UniqueTypeIdType = "u16"] @@ -25,7 +25,7 @@ impl BuiltinInlineFunction for BoolAnd { } fn inline(&self) -> InlineFunctionGenerator { - |args: &[LocalAddress], return_into, gt, sz| -> String { + |args, return_into, gt, _| -> String { let jmp_false = gt.get_unique_tag(PrintB::id()); let jmp_end = gt.get_unique_tag(PrintB::id()); @@ -77,7 +77,7 @@ impl BuiltinInlineFunction for BoolAsAnd { } fn inline(&self) -> InlineFunctionGenerator { - |args: &[LocalAddress], _, gt, sz| -> String { + |args: &[LocalAddress], _, gt, _| -> String { let jmp_true = gt.get_unique_tag(PrintB::id()); let lhs = args[0]; diff --git a/src/root/builtin/types/bool/mod.rs b/src/root/builtin/types/bool/mod.rs index 1627763..a01d11e 100644 --- a/src/root/builtin/types/bool/mod.rs +++ b/src/root/builtin/types/bool/mod.rs @@ -1,25 +1,25 @@ -mod and; -mod comparators; -mod not; -mod or; -mod printb; +use b_box::b; +use unique_type_id::UniqueTypeId; +use crate::root::builtin::t_id; use crate::root::builtin::types::bool::and::{BoolAnd, BoolAsAnd}; use crate::root::builtin::types::bool::comparators::{BoolEq, BoolNE}; use crate::root::builtin::types::bool::not::BoolNot; use crate::root::builtin::types::bool::or::{BoolAsOr, BoolOr}; use crate::root::builtin::types::bool::printb::PrintB; -use crate::root::builtin::types::int::IntType; -use crate::root::builtin::{f_id, t_id, BuiltinInlineFunction, InlineFunctionGenerator}; use crate::root::errors::WErr; use crate::root::name_resolver::name_resolvers::GlobalDefinitionTable; use crate::root::name_resolver::resolve_function_signatures::FunctionSignature; use crate::root::parser::parse_function::parse_literal::{LiteralToken, LiteralTokens}; use crate::root::parser::parse_parameters::SelfType; -use crate::root::shared::common::{ByteSize, FunctionID, LocalAddress, TypeID}; +use crate::root::shared::common::{ByteSize, LocalAddress, TypeID}; use crate::root::shared::types::Type; -use b_box::b; -use unique_type_id::UniqueTypeId; + +mod and; +mod comparators; +mod not; +mod or; +mod printb; fn bool_op_sig() -> FunctionSignature { FunctionSignature::new_inline_builtin( diff --git a/src/root/builtin/types/bool/not.rs b/src/root/builtin/types/bool/not.rs index 8db25af..fa84e02 100644 --- a/src/root/builtin/types/bool/not.rs +++ b/src/root/builtin/types/bool/not.rs @@ -1,11 +1,11 @@ +use unique_type_id::UniqueTypeId; + use crate::root::builtin::types::bool::printb::PrintB; use crate::root::builtin::types::bool::BoolType; -use crate::root::builtin::types::int::IntType; use crate::root::builtin::{f_id, BuiltinInlineFunction, InlineFunctionGenerator}; use crate::root::name_resolver::resolve_function_signatures::FunctionSignature; use crate::root::parser::parse_parameters::SelfType; use crate::root::shared::common::{FunctionID, LocalAddress, TypeID}; -use unique_type_id::UniqueTypeId; #[derive(UniqueTypeId)] #[UniqueTypeIdType = "u16"] @@ -29,7 +29,7 @@ impl BuiltinInlineFunction for BoolNot { } fn inline(&self) -> InlineFunctionGenerator { - |args: &[LocalAddress], return_into, gt, sz| -> String { + |args: &[LocalAddress], return_into, gt, _| -> String { let jmp_false = gt.get_unique_tag(PrintB::id()); let jmp_end = gt.get_unique_tag(PrintB::id()); diff --git a/src/root/builtin/types/bool/or.rs b/src/root/builtin/types/bool/or.rs index 0d9c3d4..75b98ff 100644 --- a/src/root/builtin/types/bool/or.rs +++ b/src/root/builtin/types/bool/or.rs @@ -1,11 +1,10 @@ -use crate::root::builtin::types::bool::printb::PrintB; +use unique_type_id::UniqueTypeId; + use crate::root::builtin::types::bool::{bool_op_sig, BoolType}; -use crate::root::builtin::types::int::IntType; use crate::root::builtin::{f_id, BuiltinInlineFunction, InlineFunctionGenerator}; use crate::root::name_resolver::resolve_function_signatures::FunctionSignature; use crate::root::parser::parse_parameters::SelfType; use crate::root::shared::common::{FunctionID, LocalAddress, TypeID}; -use unique_type_id::UniqueTypeId; #[derive(UniqueTypeId)] #[UniqueTypeIdType = "u16"] @@ -25,7 +24,7 @@ impl BuiltinInlineFunction for BoolOr { } fn inline(&self) -> InlineFunctionGenerator { - |args: &[LocalAddress], return_into, gt, sz| -> String { + |args: &[LocalAddress], return_into, _, _| -> String { let lhs = args[0]; let rhs = args[1]; let return_into = return_into.unwrap(); @@ -68,7 +67,7 @@ impl BuiltinInlineFunction for BoolAsOr { } fn inline(&self) -> InlineFunctionGenerator { - |args: &[LocalAddress], _, gt, sz| -> String { + |args: &[LocalAddress], _, _, _| -> String { let lhs = args[0]; let rhs = args[1]; format!( diff --git a/src/root/builtin/types/int/add.rs b/src/root/builtin/types/int/add.rs index 956c19e..598c3c2 100644 --- a/src/root/builtin/types/int/add.rs +++ b/src/root/builtin/types/int/add.rs @@ -72,7 +72,7 @@ impl BuiltinInlineFunction for IntAsAdd { } fn inline(&self) -> InlineFunctionGenerator { - |args: &[LocalAddress], return_into: Option, _, _| -> String { + |args: &[LocalAddress], _, _, _| -> String { let lhs = args[0]; let rhs = args[1]; format!( diff --git a/src/root/builtin/types/int/div.rs b/src/root/builtin/types/int/div.rs index cad586d..9c8e912 100644 --- a/src/root/builtin/types/int/div.rs +++ b/src/root/builtin/types/int/div.rs @@ -74,7 +74,7 @@ impl BuiltinInlineFunction for IntAsDiv { } fn inline(&self) -> InlineFunctionGenerator { - |args: &[LocalAddress], return_into: Option, _, _| -> String { + |args: &[LocalAddress], _, _, _| -> String { let lhs = args[0]; let rhs = args[1]; format!( diff --git a/src/root/builtin/types/int/mod.rs b/src/root/builtin/types/int/mod.rs index fb4c273..1007e4f 100644 --- a/src/root/builtin/types/int/mod.rs +++ b/src/root/builtin/types/int/mod.rs @@ -1,7 +1,7 @@ use b_box::b; use unique_type_id::UniqueTypeId; -use crate::root::builtin::types::bool::BoolType; +use crate::root::builtin::t_id; use crate::root::builtin::types::int::add::{IntAdd, IntAsAdd}; use crate::root::builtin::types::int::comparators::{IntEq, IntGE, IntGT, IntLE, IntLT, IntNE}; use crate::root::builtin::types::int::div::{IntAsDiv, IntDiv}; @@ -11,15 +11,12 @@ use crate::root::builtin::types::int::p_add::IntPAdd; use crate::root::builtin::types::int::p_sub::{IntAsSub, IntPSub}; use crate::root::builtin::types::int::printi::PrintI; use crate::root::builtin::types::int::sub::IntSub; -use crate::root::builtin::{f_id, t_id, BuiltinInlineFunction, InlineFunctionGenerator}; use crate::root::compiler::assembly::utils::write_64bit_int; use crate::root::compiler::compiler_errors::CompErrs; -use crate::root::errors::evaluable_errors::EvalErrs; use crate::root::errors::WErr; use crate::root::name_resolver::name_resolvers::GlobalDefinitionTable; -use crate::root::name_resolver::resolve_function_signatures::FunctionSignature; use crate::root::parser::parse_function::parse_literal::{LiteralToken, LiteralTokens}; -use crate::root::shared::common::{ByteSize, FunctionID, LocalAddress, TypeID}; +use crate::root::shared::common::{ByteSize, LocalAddress, TypeID}; use crate::root::shared::types::Type; mod add; diff --git a/src/root/builtin/types/int/modulo.rs b/src/root/builtin/types/int/modulo.rs index c15527b..5aeecfd 100644 --- a/src/root/builtin/types/int/modulo.rs +++ b/src/root/builtin/types/int/modulo.rs @@ -74,7 +74,7 @@ impl BuiltinInlineFunction for IntAsMod { } fn inline(&self) -> InlineFunctionGenerator { - |args: &[LocalAddress], return_into: Option, _, _| -> String { + |args: &[LocalAddress], _, _, _| -> String { let lhs = args[0]; let rhs = args[1]; format!( diff --git a/src/root/builtin/types/int/mul.rs b/src/root/builtin/types/int/mul.rs index 0483d0a..216491b 100644 --- a/src/root/builtin/types/int/mul.rs +++ b/src/root/builtin/types/int/mul.rs @@ -73,7 +73,7 @@ impl BuiltinInlineFunction for IntAsMul { } fn inline(&self) -> InlineFunctionGenerator { - |args: &[LocalAddress], return_into: Option, _, _| -> String { + |args: &[LocalAddress], _, _, _| -> String { let lhs = args[0]; let rhs = args[1]; format!( diff --git a/src/root/builtin/types/int/p_add.rs b/src/root/builtin/types/int/p_add.rs index 84227cc..658574b 100644 --- a/src/root/builtin/types/int/p_add.rs +++ b/src/root/builtin/types/int/p_add.rs @@ -1,9 +1,10 @@ +use unique_type_id::UniqueTypeId; + use crate::root::builtin::types::int::IntType; use crate::root::builtin::{f_id, BuiltinInlineFunction, InlineFunctionGenerator}; use crate::root::name_resolver::resolve_function_signatures::FunctionSignature; use crate::root::parser::parse_parameters::SelfType; -use crate::root::shared::common::{FunctionID, LocalAddress, TypeID}; -use unique_type_id::UniqueTypeId; +use crate::root::shared::common::{FunctionID, TypeID}; #[derive(UniqueTypeId)] #[UniqueTypeIdType = "u16"] @@ -27,7 +28,7 @@ impl BuiltinInlineFunction for IntPAdd { } fn inline(&self) -> InlineFunctionGenerator { - |args: &[LocalAddress], return_into: Option, _, _| -> String { String::new() } + |_, _, _, _| -> String { String::new() } } fn parent_type(&self) -> Option { diff --git a/src/root/builtin/types/int/p_sub.rs b/src/root/builtin/types/int/p_sub.rs index 9adc70b..2ed4c73 100644 --- a/src/root/builtin/types/int/p_sub.rs +++ b/src/root/builtin/types/int/p_sub.rs @@ -68,7 +68,7 @@ impl BuiltinInlineFunction for IntAsSub { } fn inline(&self) -> InlineFunctionGenerator { - |args: &[LocalAddress], return_into: Option, _, _| -> String { + |args: &[LocalAddress], _, _, _| -> String { let lhs = args[0]; let rhs = args[1]; format!( diff --git a/src/root/compiler/assembly/heap.rs b/src/root/compiler/assembly/heap.rs index 412edb6..8391f98 100644 --- a/src/root/compiler/assembly/heap.rs +++ b/src/root/compiler/assembly/heap.rs @@ -1,12 +1,10 @@ -use crate::root::assembler::assembly_builder::AssemblyBuilder; use crate::root::builtin::{BuiltinInlineFunction, InlineFunctionGenerator}; use crate::root::compiler::local_variable_table::LocalVariableTable; use crate::root::name_resolver::name_resolvers::GlobalDefinitionTable; use crate::root::name_resolver::resolve_function_signatures::FunctionSignature; use crate::root::parser::parse_name::SimpleNameToken; use crate::root::parser::parse_parameters::SelfType; -use crate::root::shared::common::{AddressedTypeRef, FunctionID, LocalAddress, TypeID, TypeRef}; -use num_format::Locale::se; +use crate::root::shared::common::{AddressedTypeRef, FunctionID, TypeID, TypeRef}; pub fn heap_alloc( t: TypeRef, diff --git a/src/root/compiler/assembly/null.rs b/src/root/compiler/assembly/null.rs index 53d1ceb..0399adf 100644 --- a/src/root/compiler/assembly/null.rs +++ b/src/root/compiler/assembly/null.rs @@ -81,7 +81,7 @@ impl BuiltinInlineFunction for IsNullFunction { } fn inline(&self) -> InlineFunctionGenerator { - |args: &[LocalAddress], return_into, gt, sz| -> String { + |args: &[LocalAddress], return_into, gt, _| -> String { let jmp_false = gt.get_unique_tag(IsNullFunction::const_id()); let jmp_end = gt.get_unique_tag(IsNullFunction::const_id()); diff --git a/src/root/compiler/assembly/utils.rs b/src/root/compiler/assembly/utils.rs index bf74908..92fef23 100644 --- a/src/root/compiler/assembly/utils.rs +++ b/src/root/compiler/assembly/utils.rs @@ -140,6 +140,7 @@ pub fn copy_from_indirect( /// Copies data. Expects `from` to be the address of a pointer pointing to the data to move /// and `to` to be the target +#[allow(dead_code)] pub fn copy_from_indirect_fixed_offset( from: LocalAddress, offset: ByteSize, diff --git a/src/root/compiler/compile.rs b/src/root/compiler/compile.rs index d9dc5fa..790f566 100644 --- a/src/root/compiler/compile.rs +++ b/src/root/compiler/compile.rs @@ -1,3 +1,8 @@ +use std::collections::HashMap; + +#[cfg(debug_assertions)] +use itertools::Itertools; + use crate::root::compiler::compile_function::compile_function; use crate::root::compiler::global_tracker::GlobalTracker; use crate::root::errors::WErr; @@ -5,8 +10,6 @@ use crate::root::name_resolver::name_resolvers::GlobalDefinitionTable; use crate::root::parser::parse_function::FunctionToken; use crate::root::shared::common::FunctionID; use crate::root::unrandom::{new_hashmap, new_hashset}; -use itertools::Itertools; -use std::collections::{HashMap, HashSet}; /// Compiles the entire program. Returns assembly. pub fn compile( @@ -67,7 +70,7 @@ section .text .iter() .sorted_by(|(x, _), (y, _)| x.0.cmp(&y.0)) { - s += &f; + s += f; s += "\n\n"; } diff --git a/src/root/compiler/compile_function.rs b/src/root/compiler/compile_function.rs index da8202f..f44a5ea 100644 --- a/src/root/compiler/compile_function.rs +++ b/src/root/compiler/compile_function.rs @@ -1,3 +1,6 @@ +#[cfg(debug_assertions)] +use color_print::cprintln; + use crate::root::assembler::assembly_builder::AssemblyBuilder; use crate::root::builtin::types::bool::BoolType; use crate::root::builtin::types::int::IntType; @@ -6,7 +9,6 @@ use crate::root::compiler::evaluation::into::compile_evaluable_into; use crate::root::compiler::evaluation::reference::compile_evaluable_reference; use crate::root::compiler::global_tracker::GlobalTracker; use crate::root::compiler::local_variable_table::LocalVariableTable; -use crate::root::errors::evaluable_errors::EvalErrs; use crate::root::errors::WErr; use crate::root::name_resolver::name_resolvers::GlobalDefinitionTable; use crate::root::parser::parse_function::parse_line::LineTokens; @@ -14,7 +16,6 @@ use crate::root::parser::parse_function::FunctionToken; use crate::root::shared::common::AddressedTypeRef; use crate::root::shared::common::{FunctionID, Indirection, LocalAddress, TypeRef}; use crate::root::utils::warn; -use color_print::cprintln; /// Compiles a given function into assembly pub fn compile_function( @@ -307,7 +308,7 @@ fn recursively_compile_lines( contents.line("ret"); if line_i != lines.len() - 1 { - warn(&format!("Return isn't the last instruction in the block. Following lines in block will not be compiled/run.\n{}", rt.location().clone().to_warning())) + warn(&format!("Return isn't the last instruction in the block. Following lines in block will not be compiled/run.\n{}", rt.location().clone().into_warning())) } break; } diff --git a/src/root/compiler/compiler_errors.rs b/src/root/compiler/compiler_errors.rs index b286a91..b393a18 100644 --- a/src/root/compiler/compiler_errors.rs +++ b/src/root/compiler/compiler_errors.rs @@ -9,8 +9,8 @@ pub enum CompErrs { IntLiteralBelowMin(i128, i128), #[error("Expected return ({0})")] ExpectedReturn(String), - #[error("Expected return type ({0}) but found ({1})")] - ExpectedReturnType(String, String), + // #[error("Expected return type ({0}) but found ({1})")] + // ExpectedReturnType(String, String), #[error("Expected return type ({0}), not none")] ExpectedSomeReturn(String), #[error("Expected return with no value")] diff --git a/src/root/compiler/evaluation/function_only.rs b/src/root/compiler/evaluation/function_only.rs index 85de4d2..628723a 100644 --- a/src/root/compiler/evaluation/function_only.rs +++ b/src/root/compiler/evaluation/function_only.rs @@ -6,7 +6,7 @@ use crate::root::errors::evaluable_errors::EvalErrs::ExpectedFunctionName; use crate::root::errors::WErr; use crate::root::name_resolver::name_resolvers::{GlobalDefinitionTable, NameResult}; use crate::root::parser::parse_function::parse_evaluable::{EvaluableToken, EvaluableTokens}; -use crate::root::shared::common::{AddressedTypeRef, FunctionID}; +use crate::root::shared::common::FunctionID; /// Evaluates `name` into a `FunctionID` pub fn compile_evaluable_function_only<'a>( diff --git a/src/root/compiler/evaluation/into.rs b/src/root/compiler/evaluation/into.rs index 6ce9fd1..043cc2c 100644 --- a/src/root/compiler/evaluation/into.rs +++ b/src/root/compiler/evaluation/into.rs @@ -1,8 +1,10 @@ +use either::{Left, Right}; +use itertools::Itertools; + use crate::root::assembler::assembly_builder::AssemblyBuilder; use crate::root::builtin::core::referencing::{set_deref, set_reference}; -use crate::root::compiler::assembly::utils::{copy, copy_from_indirect_fixed_offset}; +use crate::root::compiler::assembly::utils::copy; use crate::root::compiler::compile_function_call::call_function; -use crate::root::compiler::compiler_errors::CompErrs; use crate::root::compiler::evaluation::coerce_self::coerce_self; use crate::root::compiler::evaluation::new::compile_evaluable_new; use crate::root::compiler::evaluation::reference::compile_evaluable_reference; @@ -19,10 +21,6 @@ use crate::root::parser::parse_function::parse_evaluable::{EvaluableToken, Evalu use crate::root::parser::parse_function::parse_operator::{OperatorTokens, PrefixOrInfixEx}; use crate::root::parser::parse_parameters::SelfType; use crate::root::shared::common::{AddressedTypeRef, FunctionID, LocalAddress}; -use crate::root::shared::types::Type; -use either::{Left, Right}; -use itertools::Itertools; -use std::any::Any; /// Evaluates `et` putting the result into `target` pub fn compile_evaluable_into( @@ -80,14 +78,11 @@ pub fn compile_evaluable_into( t.instantiate_from_literal(target.local_address(), literal)? } EvaluableTokens::InfixOperator(lhs, op, rhs) => { - match op.operator() { - OperatorTokens::Assign => { - return WErr::ne( - EvalErrs::ExpectedType(global_table.get_type_name(target.type_ref())), - et.location().clone(), - ); - } - _ => {} + if op.operator() == &OperatorTokens::Assign { + return WErr::ne( + EvalErrs::ExpectedType(global_table.get_type_name(target.type_ref())), + et.location().clone(), + ); }; let lhs_type = type_only::compile_evaluable_type_only( @@ -447,7 +442,7 @@ pub fn compile_evaluable_into( ); } - let tt = global_table.get_type(t.type_id().clone()); + let tt = global_table.get_type(*t.type_id()); let attributes = tt .get_attributes(struct_init.location()) .map_err(|_| { @@ -457,7 +452,7 @@ pub fn compile_evaluable_into( ) })? .iter() - .map(|x| x.clone()) + .cloned() .collect_vec(); let give_attrs = struct_init.contents(); diff --git a/src/root/compiler/evaluation/mod.rs b/src/root/compiler/evaluation/mod.rs index c68f254..c30f590 100644 --- a/src/root/compiler/evaluation/mod.rs +++ b/src/root/compiler/evaluation/mod.rs @@ -1,6 +1,3 @@ -use crate::root::errors::WErr; -use crate::root::shared::common::AddressedTypeRef; - pub mod coerce_self; pub mod function_only; pub mod into; @@ -8,12 +5,12 @@ pub mod new; pub mod reference; pub mod type_only; -/// Error on an empty address -pub fn expect_addr( - r: (String, Option), -) -> Result<(String, AddressedTypeRef), WErr> { - Ok((r.0, r.1.unwrap())) // TODO -} +// Error on an empty address +// pub fn expect_addr( +// r: (String, Option), +// ) -> Result<(String, AddressedTypeRef), WErr> { +// Ok((r.0, r.1.unwrap())) // TODO +// } // Will ignore everything other than type with a target type // pub fn compile_evaluable_type_only_into( diff --git a/src/root/compiler/evaluation/new.rs b/src/root/compiler/evaluation/new.rs index 46ebbf4..6b8773e 100644 --- a/src/root/compiler/evaluation/new.rs +++ b/src/root/compiler/evaluation/new.rs @@ -6,7 +6,6 @@ use crate::root::builtin::core::referencing::{set_deref, set_reference}; use crate::root::compiler::assembly::heap::heap_alloc; use crate::root::compiler::assembly::utils::{copy, copy_to_indirect}; use crate::root::compiler::compile_function_call::call_function; -use crate::root::compiler::compiler_errors::CompErrs; use crate::root::compiler::evaluation::coerce_self::coerce_self; use crate::root::compiler::evaluation::reference::compile_evaluable_reference; use crate::root::compiler::evaluation::{function_only, into, reference, type_only}; @@ -24,7 +23,6 @@ use crate::root::parser::parse_parameters::SelfType; use crate::root::shared::common::{ AddressedTypeRef, FunctionID, Indirection, LocalAddress, TypeRef, }; -use crate::root::shared::types::Type; /// Evaluates `et` into a new address pub fn compile_evaluable_new( @@ -81,49 +79,39 @@ pub fn compile_evaluable_new( ) } EvaluableTokens::InfixOperator(lhs, op, rhs) => { - match op.operator() { - OperatorTokens::Assign => { - let (mut c, into) = compile_evaluable_new( - fid, - lhs, - local_variables, - global_table, - global_tracker, - )?; - - let Some(into) = into else { - return WErr::ne(EvalErrs::ExpectedNotNone, lhs.location().clone()); - }; - if !into.type_ref().indirection().has_indirection() { - return WErr::ne( - EvalErrs::ExpectedReference( - global_table.get_type_name(into.type_ref()), - ), - lhs.location().clone(), - ); - } - - let val = global_table.add_local_variable_unnamed_base( - into.type_ref().minus_one_indirect(), - local_variables, - ); - c += &into::compile_evaluable_into( - fid, - rhs, - val.clone(), - local_variables, - global_table, - global_tracker, - )?; - - c += ©_to_indirect( - *val.local_address(), - *into.local_address(), - global_table.get_size(val.type_ref()), + if op.operator() == &OperatorTokens::Assign { + let (mut c, into) = + compile_evaluable_new(fid, lhs, local_variables, global_table, global_tracker)?; + + let Some(into) = into else { + return WErr::ne(EvalErrs::ExpectedNotNone, lhs.location().clone()); + }; + if !into.type_ref().indirection().has_indirection() { + return WErr::ne( + EvalErrs::ExpectedReference(global_table.get_type_name(into.type_ref())), + lhs.location().clone(), ); - return Ok((c, None)); } - _ => {} + + let val = global_table.add_local_variable_unnamed_base( + into.type_ref().minus_one_indirect(), + local_variables, + ); + c += &into::compile_evaluable_into( + fid, + rhs, + val.clone(), + local_variables, + global_table, + global_tracker, + )?; + + c += ©_to_indirect( + *val.local_address(), + *into.local_address(), + global_table.get_size(val.type_ref()), + ); + return Ok((c, None)); }; let lhs_type = type_only::compile_evaluable_type_only( @@ -438,7 +426,7 @@ pub fn compile_evaluable_new( global_table.add_local_variable_unnamed_base(t.clone(), local_variables) /* } */; - let tt = global_table.get_type(t.type_id().clone()); + let tt = global_table.get_type(*t.type_id()); let attributes = tt .get_attributes(struct_init.location()) .map_err(|_| { @@ -448,7 +436,7 @@ pub fn compile_evaluable_new( ) })? .iter() - .map(|x| x.clone()) + .cloned() .collect_vec(); let give_attrs = struct_init.contents(); diff --git a/src/root/compiler/evaluation/reference.rs b/src/root/compiler/evaluation/reference.rs index 9f78a1b..f35dd47 100644 --- a/src/root/compiler/evaluation/reference.rs +++ b/src/root/compiler/evaluation/reference.rs @@ -1,6 +1,3 @@ -use crate::root::assembler::assembly_builder::AssemblyBuilder; -use crate::root::builtin::core::referencing::set_reference; -use crate::root::compiler::evaluation::new; use crate::root::compiler::evaluation::new::compile_evaluable_new; use crate::root::compiler::global_tracker::GlobalTracker; use crate::root::compiler::local_variable_table::LocalVariableTable; @@ -8,9 +5,8 @@ use crate::root::errors::evaluable_errors::EvalErrs; use crate::root::errors::name_resolver_errors::NRErrs; use crate::root::errors::WErr; use crate::root::name_resolver::name_resolvers::{GlobalDefinitionTable, NameResult}; -use crate::root::parser::parse::Location; use crate::root::parser::parse_function::parse_evaluable::{EvaluableToken, EvaluableTokens}; -use crate::root::shared::common::{AddressedTypeRef, FunctionID, LocalAddress}; +use crate::root::shared::common::{AddressedTypeRef, FunctionID}; /// Evaluates `et` attempting to return a reference to an existing variable as opposed to allocating pub fn compile_evaluable_reference( @@ -61,7 +57,7 @@ pub fn compile_evaluable_reference( EvaluableTokens::FunctionCall(_, _) => { compile_evaluable_new(fid, et, local_variables, global_table, global_tracker)? } - EvaluableTokens::StructInitialiser(struct_init) => { + EvaluableTokens::StructInitialiser(_struct_init) => { compile_evaluable_new(fid, et, local_variables, global_table, global_tracker)? } EvaluableTokens::None => (String::new(), None), diff --git a/src/root/compiler/evaluation/type_only.rs b/src/root/compiler/evaluation/type_only.rs index bfb253b..5adcea7 100644 --- a/src/root/compiler/evaluation/type_only.rs +++ b/src/root/compiler/evaluation/type_only.rs @@ -1,6 +1,4 @@ -use crate::root::assembler::assembly_builder::AssemblyBuilder; use crate::root::compiler::evaluation::function_only; -use crate::root::compiler::evaluation::reference::compile_evaluable_reference; use crate::root::compiler::global_tracker::GlobalTracker; use crate::root::compiler::local_variable_table::LocalVariableTable; use crate::root::errors::evaluable_errors::EvalErrs; @@ -10,9 +8,7 @@ use crate::root::errors::WErr; use crate::root::name_resolver::name_resolvers::{GlobalDefinitionTable, NameResult}; use crate::root::parser::parse_function::parse_evaluable::{EvaluableToken, EvaluableTokens}; use crate::root::parser::parse_function::parse_operator::{OperatorTokens, PrefixOrInfixEx}; -use crate::root::shared::common::{ - AddressedTypeRef, FunctionID, Indirection, LocalAddress, TypeRef, -}; +use crate::root::shared::common::{FunctionID, Indirection, TypeRef}; /// Evaluates the type `et` evaluates to. Does not generate any assembly. pub fn compile_evaluable_type_only( @@ -143,8 +139,8 @@ pub fn compile_evaluable_type_only( n.location().clone(), ) } // Accessed methods must be called - EvaluableTokens::FunctionCall(inner, args) => { - let (slf, ifid, _) = function_only::compile_evaluable_function_only( + EvaluableTokens::FunctionCall(inner, _args) => { + let (_slf, ifid, _) = function_only::compile_evaluable_function_only( fid, inner, local_variables, diff --git a/src/root/errors/mod.rs b/src/root/errors/mod.rs index c529e13..2392bb2 100644 --- a/src/root/errors/mod.rs +++ b/src/root/errors/mod.rs @@ -2,6 +2,7 @@ use crate::root::parser::parse::Location; #[cfg(debug_assertions)] use crate::root::DEBUG_ON_ERROR; use color_print::cformat; +#[cfg(debug_assertions)] use std::backtrace::Backtrace; use std::fmt::{Display, Formatter}; diff --git a/src/root/errors/parser_errors.rs b/src/root/errors/parser_errors.rs index 664c97c..3e76768 100644 --- a/src/root/errors/parser_errors.rs +++ b/src/root/errors/parser_errors.rs @@ -28,7 +28,7 @@ pub fn create_custom_error_tree(e: String, l: Span) -> ErrorTree { pub fn to_error_tree<'a>(e: nom::Err>, s: Span<'a>) -> ErrorTree<'a> { match e { - nom::Err::Incomplete(i) => { + nom::Err::Incomplete(_n) => { create_custom_error_tree("Expected more characters".to_string(), s) } nom::Err::Error(e) => e, diff --git a/src/root/name_resolver/name_resolvers.rs b/src/root/name_resolver/name_resolvers.rs index d26f4bc..dbca7cf 100644 --- a/src/root/name_resolver/name_resolvers.rs +++ b/src/root/name_resolver/name_resolvers.rs @@ -152,7 +152,7 @@ impl GlobalDefinitionTable { self.impl_definitions .get(&base) .and_then(|i| i.get(name)) - .map(|f| *f) + .copied() } /// Adds a type from a `StructToken` @@ -296,7 +296,7 @@ impl GlobalDefinitionTable { return Ok(TypeRef::new(*r, *indirection)); } - if let Some(r) = self.builtin_function_name_table.get(name.name()) { + if let Some(_fid) = self.builtin_function_name_table.get(name.name()) { return WErr::ne( NRErrs::FoundFunctionNotType(name.name().clone()), full_name.location().clone(), @@ -376,7 +376,7 @@ impl GlobalDefinitionTable { pub fn get_type_name(&self, type_ref: &TypeRef) -> String { format!( "{}{}", - unsafe { String::from_utf8_unchecked(vec!['&' as u8; type_ref.indirection().0]) }, + unsafe { String::from_utf8_unchecked(vec![b'&'; type_ref.indirection().0]) }, self.get_type(*type_ref.type_id()).name() ) } @@ -385,7 +385,7 @@ impl GlobalDefinitionTable { pub fn resolve_name( &mut self, name: &SimpleNameToken, - containing_class: Option<&SimpleNameToken>, + _containing_class: Option<&SimpleNameToken>, local_variable_table: &LocalVariableTable, ) -> Result { if let Some(variable) = local_variable_table.get(name.name()) { diff --git a/src/root/name_resolver/resolve_names.rs b/src/root/name_resolver/resolve_names.rs index c6b1c35..8a3bb74 100644 --- a/src/root/name_resolver/resolve_names.rs +++ b/src/root/name_resolver/resolve_names.rs @@ -1,4 +1,3 @@ -use std::any::Any; use std::collections::HashMap; use crate::root::errors::evaluable_errors::EvalErrs; @@ -70,7 +69,7 @@ impl Type for UserType { fn instantiate_from_literal( &self, - location: &LocalAddress, + _location: &LocalAddress, literal: &LiteralToken, ) -> Result { WErr::ne( diff --git a/src/root/name_resolver/resolve_type_sizes.rs b/src/root/name_resolver/resolve_type_sizes.rs index d61158e..4be56b6 100644 --- a/src/root/name_resolver/resolve_type_sizes.rs +++ b/src/root/name_resolver/resolve_type_sizes.rs @@ -1,4 +1,7 @@ -use crate::root::errors::name_resolver_errors::NRErrs; +use std::collections::HashMap; + +use derive_getters::Dissolve; + use crate::root::errors::WErr; use crate::root::name_resolver::name_resolvers::GlobalDefinitionTable; use crate::root::name_resolver::resolve_names::UserType; @@ -7,8 +10,6 @@ use crate::root::parser::parse_name::SimpleNameToken; use crate::root::shared::common::TypeRef; use crate::root::shared::common::{ByteSize, TypeID}; use crate::root::POINTER_SIZE; -use derive_getters::Dissolve; -use std::collections::HashMap; #[derive(Dissolve)] /// A user type with TBD size diff --git a/src/root/parser/handle_errors.rs b/src/root/parser/handle_errors.rs index 5d6dd08..503482f 100644 --- a/src/root/parser/handle_errors.rs +++ b/src/root/parser/handle_errors.rs @@ -1,9 +1,9 @@ +use nom_supreme::error::{BaseErrorKind, StackContext}; + use crate::root::errors::parser_errors::ParseError; use crate::root::errors::WErr; use crate::root::parser::parse::{ErrorTree, Location, ParseResult, Span}; use crate::root::parser::parse_toplevel::TopLevelTokens; -use nom::error::ErrorKind; -use nom_supreme::error::{BaseErrorKind, StackContext}; pub fn handle_error<'a>( res: ParseResult<'a, Span<'a>, Vec>, @@ -11,7 +11,7 @@ pub fn handle_error<'a>( match res { Ok(v) => Ok(v), Err(e) => match &e { - nom::Err::Incomplete(x) => WErr::ne( + nom::Err::Incomplete(_n) => WErr::ne( ParseError::ParserIncompleteErrorsNotImplemented, // TODO Location::builtin(), ), diff --git a/src/root/parser/parse.rs b/src/root/parser/parse.rs index 03f6206..b06943b 100644 --- a/src/root/parser/parse.rs +++ b/src/root/parser/parse.rs @@ -1,21 +1,22 @@ -use crate::root::errors::parser_errors::ParseError; -use crate::root::errors::WErr; -use crate::root::parser::handle_errors::handle_error; -use crate::root::parser::parse_toplevel; -use crate::root::parser::parse_toplevel::TopLevelTokens; -use color_print::cformat; -use lazy_static::lazy_static; -use nom::{IResult, InputTake}; -use nom_locate::LocatedSpan; -use nom_supreme::error::{BaseErrorKind, GenericErrorTree}; use std::cmp::min; use std::ffi::OsStr; -use std::fmt::{Display, Formatter, Write}; +use std::fmt::{Display, Formatter}; use std::fs; use std::marker::PhantomData; use std::path::PathBuf; use std::rc::Rc; +use color_print::cformat; +use lazy_static::lazy_static; +use nom::{IResult, InputTake}; +use nom_locate::LocatedSpan; +use nom_supreme::error::GenericErrorTree; + +use crate::root::errors::WErr; +use crate::root::parser::handle_errors::handle_error; +use crate::root::parser::parse_toplevel; +use crate::root::parser::parse_toplevel::TopLevelTokens; + pub type Span<'a> = LocatedSpan<&'a str, &'a Rc>; pub type ParseResult<'a, I = Span<'a>, O = Span<'a>, E = ErrorTree<'a>> = IResult; @@ -42,7 +43,7 @@ pub struct WarningL; pub type Location = LocationTyped; #[derive(Debug, Clone, Hash)] -pub enum ErrorLocation { +enum ErrorLocation { Location(InnerLocation), Builtin, None, @@ -55,7 +56,7 @@ pub struct LocationTyped { } impl LocationTyped { - pub fn to_warning(self) -> LocationTyped { + pub fn into_warning(self) -> LocationTyped { LocationTyped { error_type: Default::default(), inner_location: self.inner_location, diff --git a/src/root/parser/parse_arguments.rs b/src/root/parser/parse_arguments.rs index 70c67c5..cda7c9e 100644 --- a/src/root/parser/parse_arguments.rs +++ b/src/root/parser/parse_arguments.rs @@ -4,9 +4,9 @@ use crate::root::parser::parse_function::parse_evaluable::{parse_evaluable, Eval use crate::root::parser::parse_name::SimpleNameToken; use crate::root::parser::parse_util::discard_ignored; -pub fn parse_arguments<'a, 'b>( +pub fn parse_arguments<'a>( s: Span<'a>, - containing_class: Option<&'b SimpleNameToken>, + containing_class: Option<&SimpleNameToken>, ) -> ParseResult<'a, (), Vec> { let mut s = s; let mut args = Vec::new(); diff --git a/src/root/parser/parse_blocks.rs b/src/root/parser/parse_blocks.rs index 2ea091e..9121f9b 100644 --- a/src/root/parser/parse_blocks.rs +++ b/src/root/parser/parse_blocks.rs @@ -1,14 +1,16 @@ -use crate::root::errors::parser_errors::create_custom_error; -use crate::root::parser::parse::{ErrorTree, ParseResult, Span}; -use crate::root::parser::parse_util::discard_ignored; -use itertools::Itertools; -use nom::bytes::complete::{tag, take_until}; +use std::path::PathBuf; +use std::rc::Rc; + +use nom::bytes::complete::tag; use nom::character::complete::{anychar, char as nchar}; use nom::error::{ErrorKind, ParseError}; use nom::{InputTake, Offset}; use nom_locate::LocatedSpan; -use std::path::PathBuf; -use std::rc::Rc; + +use crate::root::errors::parser_errors::create_custom_error; +use crate::root::parser::parse::{ErrorTree, ParseResult, Span}; +use crate::root::parser::parse_util::discard_ignored; + // ! BROKEN pub struct Terminator { @@ -42,17 +44,14 @@ pub const STRING_TERMINATOR: Terminator = Terminator { pub const DEFAULT_TERMINATORS: [Terminator; 3] = [BRACE_TERMINATOR, BRACKET_TERMINATOR, STRING_TERMINATOR]; -pub fn parse_terminator_default_set<'a, 'b>( - s: Span<'a>, - terminator: &'b Terminator, -) -> ParseResult<'a> { +pub fn parse_terminator_default_set<'a>(s: Span<'a>, terminator: &Terminator) -> ParseResult<'a> { parse_terminator(s, terminator, &DEFAULT_TERMINATORS) } -pub fn parse_terminator<'a, 'b, 'c>( +pub fn parse_terminator<'a>( s: Span<'a>, - terminator: &'b Terminator, - all_terminators: &'c [Terminator], + terminator: &Terminator, + all_terminators: &[Terminator], ) -> ParseResult<'a> { let (initial_span, _) = nchar(terminator.opening)(s)?; @@ -96,12 +95,12 @@ pub fn parse_terminator<'a, 'b, 'c>( if terminator.code_inner { for t in all_terminators { - if let Ok(_) = nchar::<_, ErrorTree>(t.opening)(s) { + if nchar::<_, ErrorTree>(t.opening)(s).is_ok() { s = parse_terminator(s, t, all_terminators)?.0; continue 'main; } - if let Ok(_) = nchar::<_, ErrorTree>(t.closing)(s) { + if nchar::<_, ErrorTree>(t.closing)(s).is_ok() { // Unopened section closed return Err(create_custom_error( format!( @@ -123,7 +122,7 @@ pub fn parse_terminator<'a, 'b, 'c>( } pub fn take_until_or_end_discard_smart<'a>(s: Span<'a>, until: &str) -> ParseResult<'a> { - let original = s.clone(); + let original = s; let mut s = s; let mut found = false; 'outer: while !s.is_empty() { @@ -154,8 +153,9 @@ pub fn take_until_or_end_discard_smart<'a>(s: Span<'a>, until: &str) -> ParseRes Ok((end, inner)) } +#[allow(dead_code)] pub fn take_until_discard_smart<'a>(s: Span<'a>, until: &str) -> ParseResult<'a> { - let original = s.clone(); + let original = s; let mut s = s; 'outer: loop { if s.is_empty() { diff --git a/src/root/parser/parse_function.rs b/src/root/parser/parse_function.rs index b8c149b..5c44e0e 100644 --- a/src/root/parser/parse_function.rs +++ b/src/root/parser/parse_function.rs @@ -70,7 +70,7 @@ pub fn parse_function<'a>( let (s, return_type) = if let Ok((s, _)) = tag::<_, _, ErrorTree>("->")(s) { let (s, _) = discard_ignored(s)?; - let location = Location::from_span(&s); + // let location = Location::from_span(&s); let (s, return_type) = parse_full_name(s, allow_self)?; (discard_ignored(s)?.0, Some(return_type)) } else { diff --git a/src/root/parser/parse_function/parse_break.rs b/src/root/parser/parse_function/parse_break.rs index 73ff912..ecdde0f 100644 --- a/src/root/parser/parse_function/parse_break.rs +++ b/src/root/parser/parse_function/parse_break.rs @@ -1,6 +1,5 @@ use derive_getters::Getters; use nom::character::complete::char; -use nom::Parser; use nom_supreme::tag::complete::tag; use crate::root::parser::parse::{Location, ParseResult, Span}; diff --git a/src/root/parser/parse_function/parse_evaluable.rs b/src/root/parser/parse_function/parse_evaluable.rs index e8c8e50..d1f1e2e 100644 --- a/src/root/parser/parse_function/parse_evaluable.rs +++ b/src/root/parser/parse_function/parse_evaluable.rs @@ -1,21 +1,19 @@ +use b_box::b; +use derive_getters::Getters; +use nom::branch::alt; +use nom::bytes::complete::tag; +use nom::character::complete::char; + use crate::root::errors::parser_errors::create_custom_error; use crate::root::parser::parse::{ErrorTree, Location, ParseResult, Span}; use crate::root::parser::parse_arguments::parse_arguments; -use crate::root::parser::parse_blocks::{ - parse_terminator_default_set, BRACE_TERMINATOR, BRACKET_TERMINATOR, -}; +use crate::root::parser::parse_blocks::{parse_terminator_default_set, BRACKET_TERMINATOR}; use crate::root::parser::parse_function::parse_literal::{parse_literal, LiteralToken}; use crate::root::parser::parse_function::parse_operator::{parse_operator, OperatorToken}; use crate::root::parser::parse_function::parse_struct_init::{parse_struct_init, StructInitToken}; use crate::root::parser::parse_name::{parse_simple_name, SimpleNameToken}; -use crate::root::parser::parse_struct::StructToken; use crate::root::parser::parse_util::discard_ignored; use crate::root::shared::common::Indirection; -use b_box::b; -use derive_getters::Getters; -use nom::branch::alt; -use nom::bytes::complete::tag; -use nom::character::complete::char; #[derive(Debug, Getters)] pub struct EvaluableToken { @@ -287,7 +285,7 @@ pub fn parse_evaluable<'a, 'b>( }, |x| parse_operator(x).map(|(s, t)| (s, TempEvaluableTokensOne::Operator(t))), |x| { - parse_struct_init(x, containing_class.clone()).map(|(s, t)| { + parse_struct_init(x, containing_class).map(|(s, t)| { (s, temp_from_token(s, EvaluableTokens::StructInitialiser(t))) }) }, @@ -359,15 +357,17 @@ pub fn parse_evaluable<'a, 'b>( let Some((token, t2_span)) = new_evaluables.pop() else { return Err(create_custom_error( "Must have something to perform a static access on".to_string(), - t1_span + t1_span, )); }; match token { - TempEvaluableTokensTwo::Operator(_) => return Err(create_custom_error( - "Cannot perform a static access on an operator".to_string(), - t2_span - )), + TempEvaluableTokensTwo::Operator(_) => { + return Err(create_custom_error( + "Cannot perform a static access on an operator".to_string(), + t2_span, + )) + } TempEvaluableTokensTwo::EvaluableToken(e) => new_evaluables.push(( TempEvaluableTokensTwo::EvaluableToken(EvaluableToken { location: e.location.clone(), @@ -381,15 +381,17 @@ pub fn parse_evaluable<'a, 'b>( let Some((token, t2_span)) = new_evaluables.pop() else { return Err(create_custom_error( "Must have something to perform a dynamic access on".to_string(), - t1_span + t1_span, )); }; match token { - TempEvaluableTokensTwo::Operator(_) => return Err(create_custom_error( - "Cannot perform a dynamic access on an operator".to_string(), - t2_span - )), + TempEvaluableTokensTwo::Operator(_) => { + return Err(create_custom_error( + "Cannot perform a dynamic access on an operator".to_string(), + t2_span, + )) + } TempEvaluableTokensTwo::EvaluableToken(e) => new_evaluables.push(( TempEvaluableTokensTwo::EvaluableToken(EvaluableToken { location: e.location.clone(), @@ -416,15 +418,17 @@ pub fn parse_evaluable<'a, 'b>( let Some((token, t2_span)) = new_evaluables.pop() else { return Err(create_custom_error( "Must have something to perform a method call on".to_string(), - t1_span + t1_span, )); }; match token { - TempEvaluableTokensTwo::Operator(_) => return Err(create_custom_error( - "Cannot perform a method on an operator".to_string(), - t2_span - )), + TempEvaluableTokensTwo::Operator(_) => { + return Err(create_custom_error( + "Cannot perform a method on an operator".to_string(), + t2_span, + )) + } TempEvaluableTokensTwo::EvaluableToken(e) => new_evaluables.push( ( TempEvaluableTokensTwo::EvaluableToken(EvaluableToken { @@ -446,30 +450,30 @@ pub fn parse_evaluable<'a, 'b>( let Some((token, t2_span)) = new_evaluables.pop() else { return Err(create_custom_error( "Must have something to perform a static function call on".to_string(), - t1_span + t1_span, )); }; match token { - TempEvaluableTokensTwo::Operator(_) => return Err(create_custom_error( - "Cannot perform a static function call on an operator".to_string(), - t2_span + TempEvaluableTokensTwo::Operator(_) => { + return Err(create_custom_error( + "Cannot perform a static function call on an operator".to_string(), + t2_span, + )) + } + TempEvaluableTokensTwo::EvaluableToken(e) => new_evaluables.push(( + TempEvaluableTokensTwo::EvaluableToken(EvaluableToken { + location: e.location.clone(), + token: EvaluableTokens::FunctionCall( + b!(EvaluableToken { + location: n.location().clone(), + token: EvaluableTokens::StaticAccess(b!(e), n) + }), + a, + ), + }), + t1_span, )), - TempEvaluableTokensTwo::EvaluableToken(e) => new_evaluables.push( - ( - TempEvaluableTokensTwo::EvaluableToken(EvaluableToken { - location: e.location.clone(), - token: EvaluableTokens::FunctionCall( - b!(EvaluableToken { - location: n.location().clone(), - token: EvaluableTokens::StaticAccess(b!(e), n) - }), - a, - ), - }), - t1_span, - ), - ), } } TempEvaluableTokensOne::EvaluableToken(e) => { @@ -535,7 +539,7 @@ pub fn parse_evaluable<'a, 'b>( enumerated_slice = &enumerated_slice[1..]; Some((op.clone(), *span)) } - (_, (TempEvaluableTokensTwo::EvaluableToken(e), span)) => { + (_, (TempEvaluableTokensTwo::EvaluableToken(_e), span)) => { return Err(create_custom_error( "Expected infix operator between previous and this evaluable".to_string(), *span, diff --git a/src/root/parser/parse_function/parse_if.rs b/src/root/parser/parse_function/parse_if.rs index b046273..6c22064 100644 --- a/src/root/parser/parse_function/parse_if.rs +++ b/src/root/parser/parse_function/parse_if.rs @@ -20,7 +20,7 @@ pub struct IfToken { else_contents: Option>, } -pub fn test_parse_if<'a, 'b>(s: Span<'a>) -> ParseResult> { +pub fn test_parse_if<'b>(s: Span<'_>) -> ParseResult> { match tag("if")(s) { Ok(_) => Ok((s, |x, c| { parse_if(x, c).map(|(s, x)| (s, LineTokens::If(x))) @@ -29,9 +29,9 @@ pub fn test_parse_if<'a, 'b>(s: Span<'a>) -> ParseResult( +pub fn parse_if<'a>( s: Span<'a>, - containing_class: Option<&'b SimpleNameToken>, + containing_class: Option<&SimpleNameToken>, ) -> ParseResult<'a, Span<'a>, IfToken> { let (s, l) = tag("if")(s)?; let (s, _) = discard_ignored(s)?; diff --git a/src/root/parser/parse_function/parse_initialisation.rs b/src/root/parser/parse_function/parse_initialisation.rs index 325b37c..eaa7b3c 100644 --- a/src/root/parser/parse_function/parse_initialisation.rs +++ b/src/root/parser/parse_function/parse_initialisation.rs @@ -18,7 +18,7 @@ pub struct InitialisationToken { value: EvaluableToken, } -pub fn test_parse_initialisation<'a, 'b>(s: Span<'a>) -> ParseResult> { +pub fn test_parse_initialisation<'b>(s: Span<'_>) -> ParseResult> { match (tag("let"), require_ignored).parse(s) { Ok(_) => Ok((s, |x, c| { parse_initialisation(x, c).map(|(s, x)| (s, LineTokens::Initialisation(x))) @@ -27,9 +27,9 @@ pub fn test_parse_initialisation<'a, 'b>(s: Span<'a>) -> ParseResult( +pub fn parse_initialisation<'a>( s: Span<'a>, - containing_class: Option<&'b SimpleNameToken>, + containing_class: Option<&SimpleNameToken>, ) -> ParseResult<'a, Span<'a>, InitialisationToken> { let (s, l) = tag("let")(s)?; let (s, _) = require_ignored(s)?; diff --git a/src/root/parser/parse_function/parse_line.rs b/src/root/parser/parse_function/parse_line.rs index 3d0728f..41ca54c 100644 --- a/src/root/parser/parse_function/parse_line.rs +++ b/src/root/parser/parse_function/parse_line.rs @@ -1,6 +1,7 @@ -use crate::root::errors::parser_errors::{ - create_custom_error, create_custom_error_tree, to_error_tree, -}; +use nom::branch::alt; +use nom::Parser; + +use crate::root::errors::parser_errors::{create_custom_error_tree, to_error_tree}; use crate::root::parser::parse::{ErrorTree, ParseResult, Span}; use crate::root::parser::parse_function::parse_break::{test_parse_break, BreakToken}; use crate::root::parser::parse_function::parse_evaluable::{parse_evaluable, EvaluableToken}; @@ -14,9 +15,6 @@ use crate::root::parser::parse_function::parse_return::{test_parse_return, Retur use crate::root::parser::parse_function::parse_while::{test_parse_while, WhileToken}; use crate::root::parser::parse_name::SimpleNameToken; use crate::root::parser::parse_util::discard_ignored; -use nom::branch::alt; -use nom::{IResult, Parser}; -use nom_supreme::error::BaseErrorKind; #[derive(Debug)] pub enum LineTokens { @@ -34,9 +32,9 @@ pub enum LineTokens { pub type LineTestFn<'a, 'b> = fn(Span<'a>, Option<&'b SimpleNameToken>) -> ParseResult<'a, Span<'a>, LineTokens>; -pub fn parse_lines<'a, 'b>( +pub fn parse_lines<'a>( contents: Span<'a>, - containing_class: Option<&'b SimpleNameToken>, + containing_class: Option<&SimpleNameToken>, ) -> ParseResult<'a, (), Vec> { let mut lines = Vec::new(); @@ -56,9 +54,9 @@ pub fn parse_lines<'a, 'b>( Ok(((), lines)) } -pub fn parse_line<'a, 'b>( +pub fn parse_line<'a>( s: Span<'a>, - containing_class: Option<&'b SimpleNameToken>, + containing_class: Option<&SimpleNameToken>, ) -> ParseResult<'a, Span<'a>, LineTokens> { match alt(( test_parse_break, @@ -72,7 +70,7 @@ pub fn parse_line<'a, 'b>( .parse(s) { Ok((_, parser)) => parser(s, containing_class), - Err(e) => { + Err(_e) => { match parse_evaluable(s, containing_class, true).map(|(s, e)| (s, LineTokens::NoOp(e))) { Ok(x) => Ok(x), diff --git a/src/root/parser/parse_function/parse_literal.rs b/src/root/parser/parse_function/parse_literal.rs index 5395045..c1143b6 100644 --- a/src/root/parser/parse_function/parse_literal.rs +++ b/src/root/parser/parse_function/parse_literal.rs @@ -3,7 +3,6 @@ use crate::root::builtin::types::int::IntType; use crate::root::parser::parse::{Location, ParseResult, Span}; use crate::root::parser::parse_util::discard_ignored; use crate::root::shared::common::TypeID; -use crate::root::shared::types::Type; use derive_getters::{Dissolve, Getters}; use nom::branch::alt; use nom::bytes::complete::tag; diff --git a/src/root/parser/parse_function/parse_marker.rs b/src/root/parser/parse_function/parse_marker.rs index 3fa6985..53f5fc8 100644 --- a/src/root/parser/parse_function/parse_marker.rs +++ b/src/root/parser/parse_function/parse_marker.rs @@ -1,21 +1,27 @@ -use crate::root::parser::parse::{ErrorTree, Location, ParseResult, Span}; -use crate::root::parser::parse_function::parse_evaluable::{parse_evaluable, EvaluableToken}; -use crate::root::parser::parse_function::parse_line::{LineTestFn, LineTokens}; -use crate::root::parser::parse_name::SimpleNameToken; -use crate::root::parser::parse_util::{discard_ignored, require_ignored}; +#[cfg(debug_assertions)] use derive_getters::Getters; +#[cfg(debug_assertions)] use nom::bytes::complete::take_till; +#[cfg(debug_assertions)] use nom::character::complete::char; +#[cfg(debug_assertions)] use nom::sequence::Tuple; -use nom_supreme::tag::complete::tag; +#[cfg(debug_assertions)] +use crate::root::parser::parse::{ParseResult, Span}; +#[cfg(debug_assertions)] +use crate::root::parser::parse_function::parse_line::{LineTestFn, LineTokens}; +#[cfg(debug_assertions)] +use crate::root::parser::parse_util::{discard_ignored, require_ignored}; + +#[cfg(debug_assertions)] #[derive(Debug, Getters)] pub struct MarkerToken { value: String, } #[cfg(debug_assertions)] -pub fn test_parse_marker<'a, 'b>(s: Span<'a>) -> ParseResult> { +pub fn test_parse_marker<'b>(s: Span) -> ParseResult> { match (char('@'), require_ignored).parse(s) { Ok(_) => Ok((s, |x, _| { parse_marker(x).map(|(s, x)| (s, LineTokens::Marker(x))) diff --git a/src/root/parser/parse_function/parse_operator.rs b/src/root/parser/parse_function/parse_operator.rs index e5634d1..295cfc1 100644 --- a/src/root/parser/parse_function/parse_operator.rs +++ b/src/root/parser/parse_function/parse_operator.rs @@ -1,7 +1,6 @@ use crate::root::parser::parse::{ErrorTree, Location, ParseResult, Span}; use derive_getters::Getters; use nom::Err::Error; -use nom::Parser; use nom_supreme::error::GenericErrorTree; use nom_supreme::tag::complete::tag; use nom_supreme::tag::TagError; diff --git a/src/root/parser/parse_function/parse_return.rs b/src/root/parser/parse_function/parse_return.rs index 1abd28a..66ebd45 100644 --- a/src/root/parser/parse_function/parse_return.rs +++ b/src/root/parser/parse_function/parse_return.rs @@ -15,7 +15,7 @@ pub struct ReturnToken { return_value: Option, } -pub fn test_parse_return<'a, 'b>(s: Span<'a>) -> ParseResult> { +pub fn test_parse_return<'b>(s: Span) -> ParseResult> { match (tag("return"), require_ignored).parse(s) { Ok(_) => Ok((s, |x, c| { parse_return(x, c).map(|(s, x)| (s, LineTokens::Return(x))) @@ -24,9 +24,9 @@ pub fn test_parse_return<'a, 'b>(s: Span<'a>) -> ParseResult( +pub fn parse_return<'a>( s: Span<'a>, - containing_class: Option<&'b SimpleNameToken>, + containing_class: Option<&SimpleNameToken>, ) -> ParseResult<'a, Span<'a>, ReturnToken> { let (s, l) = tag("return")(s)?; let (s, _) = require_ignored(s)?; diff --git a/src/root/parser/parse_function/parse_struct_init.rs b/src/root/parser/parse_function/parse_struct_init.rs index 9a95e2b..b905978 100644 --- a/src/root/parser/parse_function/parse_struct_init.rs +++ b/src/root/parser/parse_function/parse_struct_init.rs @@ -1,21 +1,17 @@ +use derive_getters::{Dissolve, Getters}; +use nom::bytes::complete::tag; +use nom::character::streaming::char; + use crate::root::parser::parse::{ErrorTree, Location, ParseResult, Span}; use crate::root::parser::parse_blocks::{ parse_terminator_default_set, take_until_or_end_discard_smart, BRACE_TERMINATOR, }; use crate::root::parser::parse_function::parse_evaluable::{ - parse_evaluable, parse_full_name, EvaluableToken, EvaluableTokens, FullNameToken, - FullNameWithIndirectionToken, + parse_evaluable, parse_full_name, EvaluableToken, FullNameWithIndirectionToken, }; -use crate::root::parser::parse_function::parse_literal::{LiteralToken, LiteralTokens}; use crate::root::parser::parse_name::{parse_simple_name, SimpleNameToken}; -use crate::root::parser::parse_parameters::parse_parameters; use crate::root::parser::parse_util::discard_ignored; use crate::root::shared::common::Indirection; -use derive_getters::{Dissolve, Getters}; -use nom::branch::alt; -use nom::bytes::complete::{tag, take_till}; -use nom::bytes::streaming::take_until; -use nom::character::streaming::char; #[derive(Debug, Dissolve, Getters)] pub struct StructInitToken { @@ -25,9 +21,9 @@ pub struct StructInitToken { contents: Vec<(SimpleNameToken, EvaluableToken)>, } -pub fn parse_struct_init<'a, 'b>( +pub fn parse_struct_init<'a>( s: Span<'a>, - containing_class: Option<&'b SimpleNameToken>, + containing_class: Option<&SimpleNameToken>, ) -> ParseResult<'a, Span<'a>, StructInitToken> { let (s, _) = discard_ignored(s)?; @@ -35,7 +31,7 @@ pub fn parse_struct_init<'a, 'b>( .map(|(ns, _)| (ns, true)) .unwrap_or((s, false)); - let (s, struct_name) = parse_full_name(s, containing_class.clone())?; + let (s, struct_name) = parse_full_name(s, containing_class)?; debug_assert!(*struct_name.indirection() == Indirection(0)); // TODO let (s, _) = discard_ignored(s)?; diff --git a/src/root/parser/parse_function/parse_while.rs b/src/root/parser/parse_function/parse_while.rs index 7387810..0870ca0 100644 --- a/src/root/parser/parse_function/parse_while.rs +++ b/src/root/parser/parse_function/parse_while.rs @@ -1,6 +1,5 @@ use derive_getters::Getters; use nom::sequence::Tuple; -use nom::Parser; use nom_supreme::tag::complete::tag; use crate::root::parser::parse::{Location, ParseResult, Span}; @@ -19,7 +18,7 @@ pub struct WhileToken { contents: Vec, } -pub fn test_parse_while<'a, 'b>(s: Span<'a>) -> ParseResult> { +pub fn test_parse_while<'b>(s: Span) -> ParseResult> { match (tag("while"), require_ignored).parse(s) { Ok(_) => Ok((s, |x, c| { parse_while(x, c).map(|(s, x)| (s, LineTokens::While(x))) @@ -28,9 +27,9 @@ pub fn test_parse_while<'a, 'b>(s: Span<'a>) -> ParseResult( +pub fn parse_while<'a>( s: Span<'a>, - containing_class: Option<&'b SimpleNameToken>, + containing_class: Option<&SimpleNameToken>, ) -> ParseResult<'a, Span<'a>, WhileToken> { let (s, l) = tag("while")(s)?; let (s, _) = discard_ignored(s)?; diff --git a/src/root/parser/parse_parameters.rs b/src/root/parser/parse_parameters.rs index e066167..fc09219 100644 --- a/src/root/parser/parse_parameters.rs +++ b/src/root/parser/parse_parameters.rs @@ -1,11 +1,12 @@ -use crate::root::parser::parse::{ErrorTree, Location, ParseResult, Span}; +use nom::character::complete::char; + +use crate::root::parser::parse::{ErrorTree, ParseResult, Span}; use crate::root::parser::parse_function::parse_evaluable::{ parse_full_name, FullNameWithIndirectionToken, }; use crate::root::parser::parse_name::{parse_simple_name, SimpleNameToken}; use crate::root::parser::parse_util::discard_ignored; use crate::root::shared::common::Indirection; -use nom::character::complete::char; pub type Parameters = Vec<(SimpleNameToken, FullNameWithIndirectionToken)>; @@ -71,7 +72,7 @@ pub fn parse_parameters<'a>( let (ns, _) = discard_ignored(ns)?; let (ns, _) = char(':')(ns)?; let (ns, _) = discard_ignored(ns)?; - let t_location = Location::from_span(&ns); + // let t_location = Location::from_span(&ns); let (ns, type_name_token) = parse_full_name(ns, allow_self)?; let (ns, _) = discard_ignored(ns)?; (ns, type_name_token) diff --git a/src/root/parser/parse_util.rs b/src/root/parser/parse_util.rs index 3da0b6e..3049ce2 100644 --- a/src/root/parser/parse_util.rs +++ b/src/root/parser/parse_util.rs @@ -1,8 +1,6 @@ -use nom::bytes::complete::{take_till, take_while}; use nom::character::complete::multispace1; use nom::error::{ErrorKind, ParseError}; use nom::Err::Error; -use nom::Parser; use super::parse::ErrorTree; use super::{ @@ -10,26 +8,26 @@ use super::{ parse_comments, }; -pub fn take_whitespace(s: Span) -> ParseResult { - take_while(|c: char| c.is_whitespace())(s) -} +// pub fn take_whitespace(s: Span) -> ParseResult { +// take_while(|c: char| c.is_whitespace())(s) +// } pub fn discard_ignored(s: Span) -> ParseResult { let mut s = s; - let mut ever_found = false; + // let mut ever_found = false; let mut found = true; while found { found = false; if let Ok((ns, _)) = parse_comments::parse_comment(s) { s = ns; found = true; - ever_found = true; + // ever_found = true; } if let Ok((ns, _)) = multispace1::<_, ErrorTree>(s) { s = ns; found = true; - ever_found = true; + // ever_found = true; } } @@ -62,25 +60,24 @@ pub fn require_ignored(s: Span) -> ParseResult { Ok((s, ())) } -pub fn take_till_whitespace(s: Span) -> ParseResult { - take_till(|c: char| c.is_whitespace())(s) -} +// pub fn take_till_whitespace(s: Span) -> ParseResult { +// take_till(|c: char| c.is_whitespace())(s) +// } // ? Source: https://stackoverflow.com/a/76759023/10619498 -// TODO: Does this work with -pub fn alt_many(mut parsers: Ps) -> impl Parser -where - P: Parser, - I: Clone, - for<'a> &'a mut Ps: IntoIterator, - E: ParseError, -{ - move |input: I| { - for parser in &mut parsers { - if let r @ Ok(_) = parser.parse(input.clone()) { - return r; - } - } - nom::combinator::fail::(input) - } -} +// pub fn alt_many(mut parsers: Ps) -> impl Parser +// where +// P: Parser, +// I: Clone, +// for<'a> &'a mut Ps: IntoIterator, +// E: ParseError, +// { +// move |input: I| { +// for parser in &mut parsers { +// if let r @ Ok(_) = parser.parse(input.clone()) { +// return r; +// } +// } +// nom::combinator::fail::(input) +// } +// } diff --git a/src/root/runner.rs b/src/root/runner.rs index 059fe55..5bc6043 100644 --- a/src/root/runner.rs +++ b/src/root/runner.rs @@ -66,7 +66,7 @@ pub fn run(output: &str) { }; ); - let termsize::Size { rows, cols } = termsize::get().unwrap(); + let termsize::Size { rows: _, cols } = termsize::get().unwrap(); const EXITED: &str = "Exited"; if cols > EXITED.len() as u16 && cols < 300 { let padl = (cols - EXITED.len() as u16) / 2; diff --git a/src/root/shared/common.rs b/src/root/shared/common.rs index e085df0..cb8a8e6 100644 --- a/src/root/shared/common.rs +++ b/src/root/shared/common.rs @@ -1,7 +1,6 @@ use derive_getters::{Dissolve, Getters}; use derive_more::{Add, AddAssign, Display, Sub, SubAssign}; use std::fmt::{Display, Formatter}; -use std::ops::Add; #[derive(Debug, PartialEq, Eq, Hash, Display, Copy, Clone)] #[display(fmt = "TypeID: {}", .0)] @@ -85,7 +84,7 @@ pub struct TypeRef { impl TypeRef { pub fn new(type_id: TypeID, indirection: Indirection) -> TypeRef { TypeRef { - type_id: type_id, + type_id, indirection, } } diff --git a/src/root/shared/types.rs b/src/root/shared/types.rs index fb1a32e..a5fc3ae 100644 --- a/src/root/shared/types.rs +++ b/src/root/shared/types.rs @@ -1,4 +1,3 @@ -use crate::root::compiler::compiler_errors::CompErrs; use crate::root::errors::evaluable_errors::EvalErrs; use crate::root::errors::WErr; use crate::root::parser::parse::Location; diff --git a/src/root/unrandom.rs b/src/root/unrandom.rs index 61386b0..3d3d51c 100644 --- a/src/root/unrandom.rs +++ b/src/root/unrandom.rs @@ -1,5 +1,7 @@ use std::collections::{HashMap, HashSet}; +#[cfg(debug_assertions)] use std::hash::RandomState; +#[cfg(debug_assertions)] use std::mem::size_of; #[inline] @@ -14,6 +16,7 @@ pub fn new_hashmap() -> HashMap { } } +#[cfg(debug_assertions)] #[inline] pub fn unrandom_hashmap() -> HashMap { let r: RandomState = unsafe { std::mem::transmute([0u8; size_of::()]) }; @@ -33,6 +36,7 @@ pub fn new_hashset() -> HashSet { } } +#[cfg(debug_assertions)] #[inline] pub fn unrandom_hashset() -> HashSet { let r: RandomState = unsafe { std::mem::transmute([0u8; size_of::()]) }; diff --git a/src/root/utils.rs b/src/root/utils.rs index c8588d4..e079951 100644 --- a/src/root/utils.rs +++ b/src/root/utils.rs @@ -49,7 +49,10 @@ macro_rules! ret_time { ($out: expr, $($tts:tt)*) => { let t = std::time::Instant::now(); $($tts)* - $out = t.elapsed(); + #[allow(clippy::needless_late_init)] + { + $out = t.elapsed(); + } }; }