diff --git a/.idea/workspace.xml b/.idea/workspace.xml index b62dbd8..86e8152 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -7,20 +7,14 @@ - - + - - - - - - - - - - - + + + + + + + - @@ -682,7 +715,8 @@ - diff --git a/src/root/compiler/compiler_errors.rs b/src/root/compiler/compiler_errors.rs index 8a2e4df..e69623a 100644 --- a/src/root/compiler/compiler_errors.rs +++ b/src/root/compiler/compiler_errors.rs @@ -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) } diff --git a/src/root/compiler/evaluation/into.rs b/src/root/compiler/evaluation/into.rs index 016fbde..ac27395 100644 --- a/src/root/compiler/evaluation/into.rs +++ b/src/root/compiler/evaluation/into.rs @@ -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( @@ -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 { @@ -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() { diff --git a/src/root/compiler/evaluation/new.rs b/src/root/compiler/evaluation/new.rs index 4cd0efb..2fdad5b 100644 --- a/src/root/compiler/evaluation/new.rs +++ b/src/root/compiler/evaluation/new.rs @@ -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; @@ -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; @@ -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() { diff --git a/src/root/compiler/evaluation/type_only.rs b/src/root/compiler/evaluation/type_only.rs index 4c57c84..ac797cf 100644 --- a/src/root/compiler/evaluation/type_only.rs +++ b/src/root/compiler/evaluation/type_only.rs @@ -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; diff --git a/src/root/name_resolver/resolve_names.rs b/src/root/name_resolver/resolve_names.rs index 1f5d8a9..7bbcdaf 100644 --- a/src/root/name_resolver/resolve_names.rs +++ b/src/root/name_resolver/resolve_names.rs @@ -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) } diff --git a/src/root/shared/types.rs b/src/root/shared/types.rs index 6bac332..2132cd3 100644 --- a/src/root/shared/types.rs +++ b/src/root/shared/types.rs @@ -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}; @@ -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(