Skip to content

Commit

Permalink
Cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-M-Lucas committed Aug 7, 2024
1 parent 7dde459 commit a9bb4d2
Show file tree
Hide file tree
Showing 16 changed files with 162 additions and 101 deletions.
32 changes: 17 additions & 15 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::root::compiler::compile::compile;
use crate::root::errors::{WErr, WErrContext};
use crate::root::name_resolver::resolve::resolve;
use crate::root::parser::parse::parse;
use crate::root::parser::path_storage::PathStorage;
use crate::root::runner::{assemble, link_gcc, run};
use crate::time;
use clap::Parser;
Expand All @@ -13,7 +14,6 @@ use std::fs::File;
use std::io::ErrorKind;
use std::path::PathBuf;
use std::time::Instant;
use crate::root::parser::path_storage::PathStorage;

#[cfg(debug_assertions)]
pub const DEBUG_ON_ERROR: bool = false;
Expand Down Expand Up @@ -64,10 +64,9 @@ pub fn main_args(args: Args) -> Result<(), String> {
}
}


print!("Parsing files... ");
time!(
let mut path_storage = PathStorage::new(&args.input).unwrap(); // TODO:
let mut path_storage = PathStorage::new(&args.input).unwrap(); // TODO:
let toplevel_tokens = parse(&mut path_storage)
.map_err(|e| e.with_context(&path_storage).to_string())?;
);
Expand Down
3 changes: 1 addition & 2 deletions src/root/builtin/core/referencing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ pub fn set_reference(
into: AddressedTypeRef,
global_table: &GlobalDefinitionTable,
) -> Result<String, WErr> {
let new_type = to_ref
.type_ref().plus_one_indirect();
let new_type = to_ref.type_ref().plus_one_indirect();
if new_type != *into.type_ref() {
return WErr::ne(
EvalErrs::OpWrongReturnType(
Expand Down
2 changes: 1 addition & 1 deletion src/root/compiler/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::root::unrandom::{new_hashmap, new_hashset};
pub fn compile(
mut global_table: GlobalDefinitionTable,
unprocessed_functions: HashMap<FunctionID, FunctionToken>,
path_storage: &PathStorage
path_storage: &PathStorage,
) -> Result<String, WErr> {
let mut unprocessed_functions = unprocessed_functions;
let mut compiled_functions = new_hashmap();
Expand Down
12 changes: 8 additions & 4 deletions src/root/compiler/compile_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ fn recursively_compile_lines(
)?);
}
LineTokens::If(if_token) => {
let condition_addr = global_table
.add_local_variable_unnamed_base(BoolType::id().immediate_single(), local_variables);
let condition_addr = global_table.add_local_variable_unnamed_base(
BoolType::id().immediate_single(),
local_variables,
);
contents.other(&compile_evaluable_into(
fid,
if_token.if_condition(),
Expand Down Expand Up @@ -225,8 +227,10 @@ fn recursively_compile_lines(

contents.line(&format!("{start_tag}:"));

let condition_addr = global_table
.add_local_variable_unnamed_base(BoolType::id().immediate_single(), local_variables);
let condition_addr = global_table.add_local_variable_unnamed_base(
BoolType::id().immediate_single(),
local_variables,
);
contents.other(&compile_evaluable_into(
fid,
while_token.condition(),
Expand Down
10 changes: 6 additions & 4 deletions src/root/compiler/compile_function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ pub fn call_function(
if into.type_ref().type_id() != signature_args[i].type_id() {
return WErr::ne(
EvalErrs::ExpectedDifferentType(
global_table
.get_type_name(&into.type_ref().type_id().immediate_single()),
global_table.get_type_name(
&into.type_ref().type_id().immediate_single(),
),
global_table.get_type_name(
&signature_args[i].type_id().immediate_single(),
),
Expand Down Expand Up @@ -228,8 +229,9 @@ pub fn call_function(
if into.type_ref().type_id() != signature_args[i].type_id() {
return WErr::ne(
EvalErrs::ExpectedDifferentType(
global_table
.get_type_name(&into.type_ref().type_id().immediate_single()),
global_table.get_type_name(
&into.type_ref().type_id().immediate_single(),
),
global_table.get_type_name(
&signature_args[i].type_id().immediate_single(),
),
Expand Down
4 changes: 2 additions & 2 deletions src/root/compiler/global_tracker.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::root::parser::path_storage::PathStorage;
use crate::root::shared::common::FunctionID;
use derive_getters::{Dissolve, Getters};
use std::collections::HashSet;
use crate::root::parser::path_storage::PathStorage;

/// Tracks data between function compilations
#[derive(Dissolve, Getters)]
Expand All @@ -23,7 +23,7 @@ impl<'a> GlobalTracker<'a> {
unique_tag_counter: 0,
}
}

pub fn functions_mut(&mut self) -> &mut HashSet<FunctionID> {
&mut self.function_calls
}
Expand Down
13 changes: 8 additions & 5 deletions src/root/errors/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
use crate::root::parser::location::{ErrorL, Location, LocationTyped};
use crate::root::parser::path_storage::PathStorage;
#[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};
use crate::root::parser::path_storage::PathStorage;

pub mod evaluable_errors;
pub mod name_resolver_errors;
pub mod parser_errors;


/// Universal error for Whython-8
#[derive(Debug)]
pub struct WErr {
Expand Down Expand Up @@ -77,7 +76,11 @@ impl WErr {

fn fmt(&self, f: &mut Formatter<'_>, path_storage: &PathStorage) -> std::fmt::Result {
let text = if let Some(location) = &self.location {
cformat!("<r,bold>Error:</>\n {}\n{}\n", self.error, location.with_context(path_storage))
cformat!(
"<r,bold>Error:</>\n {}\n{}\n",
self.error,
location.with_context(path_storage)
)
} else {
cformat!("<r,bold>Error:</>\n {}", self.error)
};
Expand All @@ -87,11 +90,11 @@ impl WErr {

pub struct WErrContext<'a> {
err: &'a WErr,
path_storage: &'a PathStorage
path_storage: &'a PathStorage,
}

impl<'a> Display for WErrContext<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
self.err.fmt(f, self.path_storage)
}
}
}
7 changes: 2 additions & 5 deletions src/root/name_resolver/name_resolvers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ use crate::root::parser::parse_function::parse_operator::{OperatorToken, PrefixO
use crate::root::parser::parse_function::FunctionToken;
use crate::root::parser::parse_name::SimpleNameToken;
use crate::root::parser::parse_struct::StructToken;
use crate::root::parser::path_storage::FileID;
use crate::root::shared::common::{AddressedTypeRef, ByteSize, FunctionID, TypeID, TypeRef};
use crate::root::shared::types::Type;
use crate::root::POINTER_SIZE;
use std::collections::HashMap;
use std::path::PathBuf;
use std::rc::Rc;
use crate::root::parser::path_storage::FileID;

#[derive(Debug)]
enum NameTreeEntry {
Expand Down Expand Up @@ -235,10 +235,7 @@ impl GlobalDefinitionTable {
}

/// Takes a name and resolves it to a type (or error)
pub fn resolve_to_type_ref(
&mut self,
name: &UnresolvedTypeRefToken,
) -> Result<TypeRef, WErr> {
pub fn resolve_to_type_ref(&mut self, name: &UnresolvedTypeRefToken) -> Result<TypeRef, WErr> {
let (indirection, full_name) = (name.indirection(), name.inner());

fn find_error_point(name: &FullNameToken, prev_location: &Location) -> Location {
Expand Down
21 changes: 17 additions & 4 deletions src/root/parser/handle_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use crate::root::parser::location::Location;
use crate::root::parser::parse::{ErrorTree, ParseResult};
use crate::root::parser::path_storage::PathStorage;

pub fn handle_error<A, B>(res: ParseResult<A, B>, path_storage: &PathStorage) -> Result<(A, B), WErr> {
pub fn handle_error<A, B>(
res: ParseResult<A, B>,
path_storage: &PathStorage,
) -> Result<(A, B), WErr> {
match res {
Ok(v) => Ok(v),
Err(e) => match &e {
Expand Down Expand Up @@ -34,7 +37,11 @@ fn handle_error_tree(e: &ErrorTree, path_storage: &PathStorage) -> WErr {
},
ErrorTree::Stack { base, contexts } => {
let mut sb = "Base Error:\n".to_string();
for l in handle_error_tree(base, path_storage).with_context(path_storage).to_string().lines() {
for l in handle_error_tree(base, path_storage)
.with_context(path_storage)
.to_string()
.lines()
{
sb += " ";
sb += l;
sb += "\n";
Expand All @@ -48,7 +55,11 @@ fn handle_error_tree(e: &ErrorTree, path_storage: &PathStorage) -> WErr {
StackContext::Context(c) => c.to_string(),
};

for l in WErr::n(e, Location::from_span(s)).with_context(path_storage).to_string().lines() {
for l in WErr::n(e, Location::from_span(s))
.with_context(path_storage)
.to_string()
.lines()
{
sb += " ";
sb += l;
sb += "\n";
Expand All @@ -63,7 +74,9 @@ fn handle_error_tree(e: &ErrorTree, path_storage: &PathStorage) -> WErr {
for (i, e) in z.iter().enumerate() {
sb += &format!("{}:\n", i + 1);

let werr = handle_error_tree(e, path_storage).with_context(path_storage).to_string();
let werr = handle_error_tree(e, path_storage)
.with_context(path_storage)
.to_string();
for line in werr.lines() {
sb += " ";
sb += line;
Expand Down
20 changes: 14 additions & 6 deletions src/root/parser/location.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::root::parser::parse::Span;
use crate::root::parser::path_storage::{FileID, PathStorage};
use color_print::cformat;
use nom::InputTake;
use std::cmp::min;
Expand All @@ -7,7 +8,6 @@ use std::fs;
use std::marker::PhantomData;
use std::path::PathBuf;
use std::rc::Rc;
use crate::root::parser::path_storage::{FileID, PathStorage};

pub enum ToLocation<'a> {
Location(Location),
Expand Down Expand Up @@ -104,10 +104,13 @@ impl<ErrorType> LocationTyped<ErrorType> {
}
}

pub fn with_context<'a>(&'a self, path_storage: &'a PathStorage) -> LocationContext<'a, ErrorType> {
pub fn with_context<'a>(
&'a self,
path_storage: &'a PathStorage,
) -> LocationContext<'a, ErrorType> {
LocationContext {
location: self,
path_storage
path_storage,
}
}

Expand All @@ -129,7 +132,12 @@ impl<ErrorType> LocationTyped<ErrorType> {
!matches!(self.inner_location, ErrorLocation::None)
}

fn fmt_choice(&self, f: &mut Formatter<'_>, is_warning: bool, path_storage: &PathStorage) -> std::fmt::Result {
fn fmt_choice(
&self,
f: &mut Formatter<'_>,
is_warning: bool,
path_storage: &PathStorage,
) -> std::fmt::Result {
let location = match &self.inner_location {
ErrorLocation::Builtin => {
writeln!(f, "{}", cformat!("<c,bold>Builtin Definition</>"))?;
Expand Down Expand Up @@ -306,7 +314,7 @@ impl LocationFilledFmt for LocationTyped<WarningL> {

pub struct LocationContext<'a, ErrorType> {
location: &'a LocationTyped<ErrorType>,
path_storage: &'a PathStorage
path_storage: &'a PathStorage,
}

impl<'a> Display for LocationContext<'a, ErrorL> {
Expand All @@ -319,4 +327,4 @@ impl<'a> Display for LocationContext<'a, WarningL> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
self.location.fmt(f, self.path_storage)
}
}
}
2 changes: 1 addition & 1 deletion src/root/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ pub mod parse_parameters;
pub mod parse_struct;
pub mod parse_toplevel;
pub mod parse_util;
pub mod path_storage;
pub mod soft_alt;
mod use_parser;
pub mod path_storage;
Loading

0 comments on commit a9bb4d2

Please sign in to comment.