Skip to content

Commit

Permalink
Resolved some todos
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-M-Lucas committed Jul 31, 2024
1 parent 627c3ed commit 9025401
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 34 deletions.
84 changes: 59 additions & 25 deletions .idea/workspace.xml

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

4 changes: 4 additions & 0 deletions src/root/compiler/compiler_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ pub enum CErrs {
ExpectedFunctionReturn(String),
#[error("Function ({0}) expects ({1}) arguments but found ({2})")]
BadFunctionArgCount(String, usize, usize),
#[error("Type ({0}) does not have attributes")]
TypeDoesntHaveAttributes(String),
#[error("Type ({0}) cannot be initialised")]
TypeCannotBeInitialised(String)
}
8 changes: 5 additions & 3 deletions src/root/compiler/evaluation/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::root::shared::types::Type;
use either::{Left, Right};
use itertools::Itertools;
use std::any::Any;
use crate::root::compiler::compiler_errors::CErrs;

/// Evaluates `et` putting the result into `target`
pub fn compile_evaluable_into(
Expand Down Expand Up @@ -284,8 +285,7 @@ pub fn compile_evaluable_into(
}

let t = global_table.get_type(*inner.type_ref().type_id());
let attribs = t.get_attributes()?;

let attribs = t.get_attributes(access.location())?;
let mut found_offset = None;

for (offset, name, t) in attribs {
Expand Down Expand Up @@ -413,7 +413,9 @@ pub fn compile_evaluable_into(
}

let tt = global_table.get_type(t.type_id().clone());
let attributes = tt.get_attributes()?.iter().map(|x| x.clone()).collect_vec();
let attributes = tt.get_attributes(struct_init.location())
.map_err(|_| WErr::n(CErrs::TypeCannotBeInitialised(tt.name().to_string()), struct_init.location().clone()))?
.iter().map(|x| x.clone()).collect_vec();
let give_attrs = struct_init.contents();

if attributes.len() != give_attrs.len() {
Expand Down
7 changes: 5 additions & 2 deletions src/root/compiler/evaluation/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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::CErrs;
use crate::root::compiler::evaluation::reference::compile_evaluable_reference;
use crate::root::compiler::evaluation::{function_only, into, reference, type_only};
use crate::root::compiler::global_tracker::GlobalTracker;
Expand Down Expand Up @@ -300,7 +301,7 @@ pub fn compile_evaluable_new(
}

let t = global_table.get_type(*inner.type_ref().type_id());
let attribs = t.get_attributes()?;
let attribs = t.get_attributes(access.location())?;

let mut found = None;

Expand Down Expand Up @@ -424,7 +425,9 @@ pub fn compile_evaluable_new(
/* } */;

let tt = global_table.get_type(t.type_id().clone());
let attributes = tt.get_attributes()?.iter().map(|x| x.clone()).collect_vec();
let attributes = tt.get_attributes(struct_init.location())
.map_err(|_| WErr::n(CErrs::TypeCannotBeInitialised(tt.name().to_string()), struct_init.location().clone()))?
.iter().map(|x| x.clone()).collect_vec();
let give_attrs = struct_init.contents();

if attributes.len() != give_attrs.len() {
Expand Down
2 changes: 1 addition & 1 deletion src/root/compiler/evaluation/type_only.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub fn compile_evaluable_type_only(
)?;

let t = global_table.get_type(*t.type_id());
let attribs = t.get_attributes()?;
let attribs = t.get_attributes(access.location())?;

let mut out = None;

Expand Down
2 changes: 1 addition & 1 deletion src/root/name_resolver/resolve_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Type for UserType {
&self.name
}

fn get_attributes(&self) -> Result<&[(ByteSize, SimpleNameToken, TypeRef)], WErr> {
fn get_attributes(&self, _: &Location) -> Result<&[(ByteSize, SimpleNameToken, TypeRef)], WErr> {
Ok(&self.attributes)
}

Expand Down
6 changes: 4 additions & 2 deletions src/root/shared/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::root::compiler::compiler_errors::CErrs;
use crate::root::errors::WErr;
use crate::root::parser::parse::Location;
use crate::root::parser::parse_function::parse_literal::LiteralToken;
use crate::root::parser::parse_name::SimpleNameToken;
use crate::root::shared::common::{ByteSize, LocalAddress, TypeID, TypeRef};
Expand All @@ -11,8 +13,8 @@ pub trait Type {

fn name(&self) -> &str;

fn get_attributes(&self) -> Result<&[(ByteSize, SimpleNameToken, TypeRef)], WErr> {
Err(todo!())
fn get_attributes(&self, location: &Location) -> Result<&[(ByteSize, SimpleNameToken, TypeRef)], WErr> {
WErr::ne(CErrs::TypeDoesntHaveAttributes(self.name().to_string()), location.clone())
}

fn instantiate_from_literal(
Expand Down

0 comments on commit 9025401

Please sign in to comment.