Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-M-Lucas committed Oct 20, 2024
2 parents 9168a1c + 6624661 commit 9fb9f4e
Show file tree
Hide file tree
Showing 19 changed files with 610 additions and 517 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/root/assembler/assembly_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ impl AssemblyBuilder {
}

/// Adds a single, non-indented line with a trailing newline
#[allow(dead_code)]
pub fn toplevel(&mut self, line: AssemblyRef) {
self.inner += line;
self.inner.push('\n');
Expand Down
1 change: 0 additions & 1 deletion src/root/compiler/compile_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ fn recursively_compile_lines(
name.name().clone(),
type_name,
local_variables,
global_tracker,
)?;
contents.other(&compile_evaluable_into(
fid,
Expand Down
1 change: 1 addition & 0 deletions src/root/compiler/global_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ impl<'a> GlobalTracker<'a> {
}
}

#[allow(dead_code)]
pub fn functions_mut(&mut self) -> &mut HashSet<FunctionID> {
&mut self.function_calls
}
Expand Down
11 changes: 6 additions & 5 deletions src/root/name_resolver/name_resolvers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub enum NameResult {
Function(FunctionID),
Type(TypeID),
Variable(AddressedTypeRef),
#[allow(dead_code)]
File(FileID),
}

Expand Down Expand Up @@ -290,14 +291,14 @@ impl GlobalTable {

fn find_error_point(name: &FullNameToken, prev_location: &Location) -> Location {
match name.token() {
FullNameTokens::Name(_, _) => prev_location.clone(),
FullNameTokens::StaticAccess(n, _) => find_error_point(n, name.location()),
FullNameTokens::DynamicAccess(n, _) => find_error_point(n, name.location()),
FullNameTokens::Name { name: _, containing_class: _ } => prev_location.clone(),
FullNameTokens::StaticAccess { inner: n, name: _ } => find_error_point(n, name.location()),
FullNameTokens::DynamicAccess { inner: n, name: _ } => find_error_point(n, name.location()),
}
}

let (name, containing) = match full_name.token() {
FullNameTokens::Name(n, c) => (n, c),
FullNameTokens::Name { name: n, containing_class: c } => (n, c),
_ => WErr::ne(
NRErrs::ExpectedTypeNotMethodOrAttribute,
find_error_point(full_name, full_name.location()),
Expand Down Expand Up @@ -389,6 +390,7 @@ impl GlobalTable {
}

/// Adds a local, unnamed variable to the `LocalVariableTable` and returns the address
#[allow(dead_code)]
pub fn add_local_variable_unnamed_from_token(
&mut self,
t: &UnresolvedTypeRefToken,
Expand All @@ -404,7 +406,6 @@ impl GlobalTable {
name: String,
t: &UnresolvedTypeRefToken,
local_variable_table: &mut LocalVariableTable,
global_tracker: &GlobalTracker,
) -> Result<AddressedTypeRef, WErr> {
let t = self.resolve_to_type_ref(t, None)?;
let size = self.get_size(&t);
Expand Down
3 changes: 0 additions & 3 deletions src/root/name_resolver/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ pub fn resolve(

resolve_file(
file,
true,
first,
&mut ast,
&mut global_table,
Expand All @@ -49,7 +48,6 @@ pub fn resolve(
/// Processes a file handling its imports
fn resolve_file(
file_id: FileID,
main_file: bool,
tokens: Vec<TopLevelTokens>,
ast: &mut HashMap<FileID, Vec<TopLevelTokens>>,
global_table: &mut GlobalTable,
Expand Down Expand Up @@ -115,7 +113,6 @@ fn process_if_needed(
if let Some((file_id, tokens)) = ast.remove_entry(&file_id) {
resolve_file(
file_id,
false,
tokens,
ast,
global_table,
Expand Down
6 changes: 5 additions & 1 deletion src/root/name_resolver/resolve_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub struct UserType {
name: String,
size: ByteSize,
attributes: Vec<(ByteSize, SimpleNameToken, TypeRef)>,
#[allow(dead_code)]
location: Location,
}

Expand Down Expand Up @@ -143,7 +144,10 @@ pub fn resolve_names(
let (location, name, functions) = it.dissolve();
let type_id = *global_table
.resolve_to_type_ref(
&FullNameToken::new(location.clone(), FullNameTokens::Name(name, None))
&FullNameToken::new(location.clone(), FullNameTokens::Name {
name: name,
containing_class: None
})
.with_no_indirection(),
None,
)?
Expand Down
4 changes: 4 additions & 0 deletions src/root/parser/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub enum ToLocation<'a> {
Span(Span<'a>),
}

#[allow(dead_code)]
impl<'a> ToLocation<'a> {
pub fn from_location(location: Location) -> ToLocation<'a> {
ToLocation::Location(location)
Expand Down Expand Up @@ -59,6 +60,7 @@ pub type Location = LocationTyped<ErrorL>;
enum ErrorLocation {
Location(InnerLocation),
Builtin,
#[allow(dead_code)]
None,
}

Expand Down Expand Up @@ -134,6 +136,7 @@ impl<ErrorType> LocationTyped<ErrorType> {
}

/// Creates a 'none' location
#[allow(dead_code)]
pub fn none() -> LocationTyped<ErrorType> {
LocationTyped {
error_type: Default::default(),
Expand All @@ -142,6 +145,7 @@ impl<ErrorType> LocationTyped<ErrorType> {
}

/// Checks if a location is not 'none'
#[allow(dead_code)]
pub fn has_location(&self) -> bool {
!matches!(self.inner_location, ErrorLocation::None)
}
Expand Down
49 changes: 34 additions & 15 deletions src/root/parser/parse_function/parse_evaluable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub struct UnresolvedTypeRefToken {
}

impl UnresolvedTypeRefToken {
#[allow(dead_code)]
pub fn from_simple(
simple: SimpleNameToken,
containing_class: Option<SimpleNameToken>,
Expand All @@ -72,7 +73,10 @@ impl UnresolvedTypeRefToken {
indirection: Indirection(0),
inner: FullNameToken {
location,
token: FullNameTokens::Name(simple, containing_class),
token: FullNameTokens::Name {
name: simple,
containing_class
},
},
}
}
Expand All @@ -87,11 +91,15 @@ impl UnresolvedTypeRefToken {
indirection,
inner: FullNameToken {
location,
token: FullNameTokens::Name(simple, containing_class),
token: FullNameTokens::Name {
name: simple,
containing_class
},
},
}
}

#[allow(dead_code)]
pub fn into_inner(self) -> FullNameToken {
self.inner
}
Expand Down Expand Up @@ -126,22 +134,24 @@ impl FullNameToken {
/// A token representing a name (e.g `a`, `a.b`, `a::b`)
#[derive(Debug)]
pub enum FullNameTokens {
Name(SimpleNameToken, Option<SimpleNameToken>),
StaticAccess(Box<FullNameToken>, SimpleNameToken),
DynamicAccess(Box<FullNameToken>, SimpleNameToken),
Name { name: SimpleNameToken, containing_class: Option<SimpleNameToken> },
StaticAccess { inner: Box<FullNameToken>, name: SimpleNameToken },
#[allow(dead_code)]
DynamicAccess { inner: Box<FullNameToken>, name: SimpleNameToken },
}

impl FullNameTokens {
#[allow(dead_code)]
pub fn into_evaluable_token(self) -> EvaluableTokens {
match self {
FullNameTokens::Name(n, c) => EvaluableTokens::Name(n, c),
FullNameTokens::StaticAccess(e, n) => EvaluableTokens::StaticAccess {
parent: b!(e.into_evaluable()),
section: n,
FullNameTokens::Name { name, containing_class } => EvaluableTokens::Name(name, containing_class),
FullNameTokens::StaticAccess { inner, name } => EvaluableTokens::StaticAccess {
parent: b!(inner.into_evaluable()),
section: name,
},
FullNameTokens::DynamicAccess(e, n) => EvaluableTokens::DynamicAccess {
parent: b!(e.into_evaluable()),
section: n,
FullNameTokens::DynamicAccess { inner, name } => EvaluableTokens::DynamicAccess {
parent: b!(inner.into_evaluable()),
section: name,
},
}
}
Expand Down Expand Up @@ -196,7 +206,10 @@ pub fn parse_full_name<'a>(

let mut current = FullNameToken {
location: section.location().clone(),
token: FullNameTokens::Name(section, containing_class.cloned()),
token: FullNameTokens::Name {
name: section,
containing_class: containing_class.cloned()
},
};

let mut s = s;
Expand All @@ -208,7 +221,10 @@ pub fn parse_full_name<'a>(
let (ns, section) = parse_simple_name(ns)?;
current = FullNameToken {
location: section.location().clone(),
token: FullNameTokens::StaticAccess(b!(current), section),
token: FullNameTokens::StaticAccess {
inner: b!(current),
name: section
},
};
s = ns;
}
Expand All @@ -217,7 +233,10 @@ pub fn parse_full_name<'a>(
let (ns, section) = parse_simple_name(ns)?;
current = FullNameToken {
location: section.location().clone(),
token: FullNameTokens::DynamicAccess(b!(current), section),
token: FullNameTokens::DynamicAccess {
inner: b!(current),
name: section
},
};
s = ns;
}
Expand Down
1 change: 1 addition & 0 deletions src/root/parser/parse_function/parse_if.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use nom_supreme::tag::complete::tag;
/// Token holding an if statement
#[derive(Debug, Getters)]
pub struct IfToken {
#[allow(dead_code)]
location: Location,
if_condition: EvaluableToken,
if_contents: Vec<LineTokens>,
Expand Down
1 change: 1 addition & 0 deletions src/root/parser/parse_function/parse_initialisation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use nom_supreme::tag::complete::tag;
// Token holding an initialiser
#[derive(Debug, Getters)]
pub struct InitialisationToken {
#[allow(dead_code)]
location: Location,
name: SimpleNameToken,
type_name: UnresolvedTypeRefToken,
Expand Down
5 changes: 4 additions & 1 deletion src/root/parser/parse_function/parse_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub struct OperatorToken {
}

impl OperatorToken {
#[allow(dead_code)]
pub fn is_prefix(&self) -> bool {
self.operator.is_prefix()
}
Expand Down Expand Up @@ -100,6 +101,7 @@ pub enum OperatorTokens {
}

impl OperatorTokens {
#[allow(dead_code)]
pub fn is_prefix(&self) -> bool {
for (_, op, prefix, _) in &OPERATOR_MAPS {
if self == op {
Expand All @@ -112,7 +114,8 @@ impl OperatorTokens {
}
panic!()
}


#[allow(dead_code)]
pub fn is_infix(&self) -> bool {
for (_, op, prefix, _) in &OPERATOR_MAPS {
if self == op {
Expand Down
1 change: 1 addition & 0 deletions src/root/parser/parse_function/parse_while.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use nom_supreme::tag::complete::tag;
/// Token representing a while statement with location
#[derive(Debug, Getters)]
pub struct WhileToken {
#[allow(dead_code)]
location: Location,
condition: EvaluableToken,
contents: Vec<LineTokens>,
Expand Down
Loading

0 comments on commit 9fb9f4e

Please sign in to comment.