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 1, 2024
1 parent 6dd310f commit d7abd14
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 90 deletions.
37 changes: 13 additions & 24 deletions .idea/workspace.xml

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

7 changes: 6 additions & 1 deletion src/root/compiler/assembly/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ pub fn align_16_bytes_plus_8(bytes: ByteSize) -> ByteSize {

/// Copies data. Expects `from` to be the address of a pointer pointing to the data to move
/// and `to` to be the target
pub fn copy_from_indirect(from: LocalAddress, to: LocalAddress, amount: ByteSize, indirectness: Indirection) -> String {
pub fn copy_from_indirect(
from: LocalAddress,
to: LocalAddress,
amount: ByteSize,
indirectness: Indirection,
) -> String {
if amount == ByteSize(0) {
return String::new();
}
Expand Down
24 changes: 18 additions & 6 deletions src/root/compiler/compile_function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,19 @@ pub fn call_function(
)?;
code.other(&c);
let Some(into) = into else {
return WErr::ne(EvalErrs::ExpectedNotNone, eval.location().clone());
return WErr::ne(
EvalErrs::ExpectedNotNone,
eval.location().clone(),
);
};
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()),
global_table.get_type_name(&signature_args[i].type_id().immediate()),
global_table
.get_type_name(&into.type_ref().type_id().immediate()),
global_table.get_type_name(
&signature_args[i].type_id().immediate(),
),
),
location.clone(),
);
Expand Down Expand Up @@ -214,13 +220,19 @@ pub fn call_function(
)?;
code.other(&c);
let Some(into) = into else {
return WErr::ne(EvalErrs::ExpectedNotNone, eval.location().clone());
return WErr::ne(
EvalErrs::ExpectedNotNone,
eval.location().clone(),
);
};
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()),
global_table.get_type_name(&signature_args[i].type_id().immediate()),
global_table
.get_type_name(&into.type_ref().type_id().immediate()),
global_table.get_type_name(
&signature_args[i].type_id().immediate(),
),
),
location.clone(),
);
Expand Down
33 changes: 19 additions & 14 deletions src/root/compiler/evaluation/coerce_self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ pub fn coerce_self(
local_variables,
);

(copy_from_indirect(
*current_self.local_address(),
*new_self.local_address(),
global_table.get_size(new_self.type_ref()),
Indirection(current_self.type_ref().indirection().0)
), new_self)
}
else {
(
copy_from_indirect(
*current_self.local_address(),
*new_self.local_address(),
global_table.get_size(new_self.type_ref()),
Indirection(current_self.type_ref().indirection().0),
),
new_self,
)
} else {
(String::new(), current_self)
}
}
Expand All @@ -56,12 +58,15 @@ pub fn coerce_self(
local_variables,
);

(copy_from_indirect(
*current_self.local_address(),
*new_self.local_address(),
global_table.get_size(new_self.type_ref()),
Indirection(current_self.type_ref().indirection().0 - 1) // Want a ref, not inner type
), new_self)
(
copy_from_indirect(
*current_self.local_address(),
*new_self.local_address(),
global_table.get_size(new_self.type_ref()),
Indirection(current_self.type_ref().indirection().0 - 1), // Want a ref, not inner type
),
new_self,
)
}
}
})
Expand Down
22 changes: 14 additions & 8 deletions src/root/compiler/evaluation/function_only.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ pub fn compile_evaluable_function_only<'a>(
let function =
global_table.get_impl_function_by_name(*inner_type.type_id(), access.name());
let Some(function) = function else {
return WErr::ne(EvalErrs::TypeDoesntHaveMethod(
global_table.get_type_name(&inner_type.type_id().immediate()),
access.name().clone()
), access.location().clone());
return WErr::ne(
EvalErrs::TypeDoesntHaveMethod(
global_table.get_type_name(&inner_type.type_id().immediate()),
access.name().clone(),
),
access.location().clone(),
);
};

(None, function, access.name().clone())
Expand All @@ -53,10 +56,13 @@ pub fn compile_evaluable_function_only<'a>(
let function =
global_table.get_impl_function_by_name(*inner_type.type_id(), access.name());
let Some(function) = function else {
return WErr::ne(EvalErrs::TypeDoesntHaveMethod(
global_table.get_type_name(&inner_type.type_id().immediate()),
access.name().clone()
), access.location().clone());
return WErr::ne(
EvalErrs::TypeDoesntHaveMethod(
global_table.get_type_name(&inner_type.type_id().immediate()),
access.name().clone(),
),
access.location().clone(),
);
};

(Some(inner), function, access.name().clone())
Expand Down
37 changes: 22 additions & 15 deletions src/root/compiler/evaluation/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::root::compiler::evaluation::{function_only, reference, type_only};
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::evaluable_errors::EvalErrs::WrongAttributeNameInInit;
use crate::root::errors::name_resolver_errors::NRErrs;
use crate::root::errors::WErr;
use crate::root::name_resolver::name_resolvers::{GlobalDefinitionTable, NameResult};
Expand All @@ -22,7 +23,6 @@ use crate::root::shared::types::Type;
use either::{Left, Right};
use itertools::Itertools;
use std::any::Any;
use crate::root::errors::evaluable_errors::EvalErrs::WrongAttributeNameInInit;

/// Evaluates `et` putting the result into `target`
pub fn compile_evaluable_into(
Expand Down Expand Up @@ -277,14 +277,17 @@ pub fn compile_evaluable_into(
ab.other(&c);

let Some(inner) = inner else {
return WErr::ne(EvalErrs::ExpectedNotNone, inner_eval.location().clone())
return WErr::ne(EvalErrs::ExpectedNotNone, inner_eval.location().clone());
};

let inner = if inner.type_ref().indirection().0 > 1 {
let (c, inner) = coerce_self(inner, SelfType::RefSelf, global_table, local_variables)?;
let (c, inner) =
coerce_self(inner, SelfType::RefSelf, global_table, local_variables)?;
ab.other(&c);
inner
} else { inner };
} else {
inner
};

let t = global_table.get_type(*inner.type_ref().type_id());
let attribs = t.get_attributes(access.location())?;
Expand All @@ -297,18 +300,22 @@ pub fn compile_evaluable_into(
EvalErrs::ExpectedDifferentType(
global_table.get_type_name(target.type_ref()),
global_table.get_type_name(&t.plus_one_indirect()),
), access.location().clone()
)
),
access.location().clone(),
);
}
found_offset = Some(*offset);
}
}

let Some(found_offset) = found_offset else {
return WErr::ne(EvalErrs::TypeDoesntHaveAttribute(
global_table.get_type_name(&t.id().immediate()),
access.name().clone()
), access.location().clone());
return WErr::ne(
EvalErrs::TypeDoesntHaveAttribute(
global_table.get_type_name(&t.id().immediate()),
access.name().clone(),
),
access.location().clone(),
);
};

if inner.type_ref().indirection().has_indirection() {
Expand Down Expand Up @@ -455,10 +462,10 @@ pub fn compile_evaluable_into(
let give_attrs = struct_init.contents();

if attributes.len() != give_attrs.len() {
return WErr::ne(EvalErrs::WrongAttributeCount(
attributes.len(),
give_attrs.len()
), struct_init.location().clone());
return WErr::ne(
EvalErrs::WrongAttributeCount(attributes.len(), give_attrs.len()),
struct_init.location().clone(),
);
}

let mut code = AssemblyBuilder::new();
Expand All @@ -469,7 +476,7 @@ pub fn compile_evaluable_into(
if t_name.name() != name.name() {
return WErr::ne(
WrongAttributeNameInInit(t_name.name().clone(), name.name().clone()),
name.location().clone()
name.location().clone(),
);
}

Expand Down
27 changes: 15 additions & 12 deletions src/root/compiler/evaluation/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ 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};
use crate::root::compiler::evaluation::coerce_self::coerce_self;
use crate::root::compiler::global_tracker::GlobalTracker;
use crate::root::compiler::local_variable_table::LocalVariableTable;
use crate::root::errors::evaluable_errors::EvalErrs;
Expand Down Expand Up @@ -303,10 +303,13 @@ pub fn compile_evaluable_new(
};

let inner = if inner.type_ref().indirection().0 > 1 {
let (c, inner) = coerce_self(inner, SelfType::RefSelf, global_table, local_variables)?;
let (c, inner) =
coerce_self(inner, SelfType::RefSelf, global_table, local_variables)?;
ab.other(&c);
inner
} else { inner };
} else {
inner
};

let t = global_table.get_type(*inner.type_ref().type_id());
let attribs = t.get_attributes(access.location())?;
Expand All @@ -320,10 +323,10 @@ pub fn compile_evaluable_new(
}

let Some((found_offset, t)) = found else {
return WErr::ne(EvalErrs::TypeDoesntHaveAttribute(
t.name().to_string(),
access.name().clone()
), access.location().clone())
return WErr::ne(
EvalErrs::TypeDoesntHaveAttribute(t.name().to_string(), access.name().clone()),
access.location().clone(),
);
};

// let t = t.plus_one_indirect();
Expand Down Expand Up @@ -450,18 +453,18 @@ pub fn compile_evaluable_new(
let give_attrs = struct_init.contents();

if attributes.len() != give_attrs.len() {
return WErr::ne(EvalErrs::WrongAttributeCount(
attributes.len(),
give_attrs.len()
), struct_init.location().clone());
return WErr::ne(
EvalErrs::WrongAttributeCount(attributes.len(), give_attrs.len()),
struct_init.location().clone(),
);
}

for ((offset, t_name, t_type), (name, val)) in attributes.iter().zip(give_attrs.iter())
{
if t_name.name() != name.name() {
return WErr::ne(
WrongAttributeNameInInit(t_name.name().clone(), name.name().clone()),
name.location().clone()
name.location().clone(),
);
}

Expand Down
11 changes: 7 additions & 4 deletions src/root/compiler/evaluation/type_only.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,13 @@ pub fn compile_evaluable_type_only(
if let Some(out) = out {
out.plus_one_indirect()
} else {
return WErr::ne(EvalErrs::TypeDoesntHaveAttribute(
global_table.get_type_name(&t.id().immediate()),
access.name().clone()
), access.location().clone());
return WErr::ne(
EvalErrs::TypeDoesntHaveAttribute(
global_table.get_type_name(&t.id().immediate()),
access.name().clone(),
),
access.location().clone(),
);
}
}
EvaluableTokens::StaticAccess(_, n) => {
Expand Down
2 changes: 1 addition & 1 deletion src/root/errors/evaluable_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ pub enum EvalErrs {
#[error("Expected attribute ({0}) to be initialised next, not ({1})")]
WrongAttributeNameInInit(String, String),
#[error("Expected ({0}) attributes to be initialised - found ({1})")]
WrongAttributeCount(usize, usize)
WrongAttributeCount(usize, usize),
}
Loading

0 comments on commit d7abd14

Please sign in to comment.