Skip to content

Commit

Permalink
Added more errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-M-Lucas committed Aug 1, 2024
1 parent 0c4e67c commit 6dd310f
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 54 deletions.
35 changes: 22 additions & 13 deletions .idea/workspace.xml

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

10 changes: 4 additions & 6 deletions main.why
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@ struct Test {
}

impl Test {
fn test(self) {
printi(*self.a);
self.a += 1;
printi(*self.a);
fn static() {

}
}

fn main() -> int {
let x: Test = Test { a: 3 };
x::test();
printi(*x.a);

+ a +

return 8;
}
26 changes: 21 additions & 5 deletions src/root/compiler/compile_function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn call_function(

let self_type = *global_table.get_function_signature(fid).self_type();
if uses_self && matches!(self_type, SelfType::None) {
todo!()
todo!() // ?
}

if let Some(inline) = global_table.get_function(fid).1 {
Expand Down Expand Up @@ -107,9 +107,17 @@ pub fn call_function(
global_tracker,
)?;
code.other(&c);
let Some(into) = into else { todo!() };
let Some(into) = into else {
return WErr::ne(EvalErrs::ExpectedNotNone, eval.location().clone());
};
if into.type_ref().type_id() != signature_args[i].type_id() {
todo!()
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()),
),
location.clone(),
);
}
into
} else {
Expand Down Expand Up @@ -205,9 +213,17 @@ pub fn call_function(
global_tracker,
)?;
code.other(&c);
let Some(into) = into else { todo!() };
let Some(into) = into else {
return WErr::ne(EvalErrs::ExpectedNotNone, eval.location().clone());
};
if into.type_ref().type_id() != signature_args[i].type_id() {
todo!()
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()),
),
location.clone(),
);
}
into
} else {
Expand Down
15 changes: 13 additions & 2 deletions src/root/compiler/evaluation/function_only.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::root::compiler::evaluation::type_only::compile_evaluable_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::ExpectedFunctionName;
use crate::root::errors::WErr;
use crate::root::name_resolver::name_resolvers::{GlobalDefinitionTable, NameResult};
Expand Down Expand Up @@ -32,7 +33,12 @@ 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 { todo!() };
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());
};

(None, function, access.name().clone())
}
Expand All @@ -46,7 +52,12 @@ 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 { todo!() };
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());
};

(Some(inner), function, access.name().clone())
}
Expand Down
65 changes: 51 additions & 14 deletions src/root/compiler/evaluation/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ 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 @@ -264,22 +265,26 @@ pub fn compile_evaluable_into(
)?;
c
}
EvaluableTokens::DynamicAccess(inner, access) => {
EvaluableTokens::DynamicAccess(inner_eval, access) => {
let mut ab = AssemblyBuilder::new();
let (c, inner) = compile_evaluable_reference(
fid,
inner,
inner_eval,
local_variables,
global_table,
global_tracker,
)?;
ab.other(&c);

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

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

let t = global_table.get_type(*inner.type_ref().type_id());
let attribs = t.get_attributes(access.location())?;
Expand All @@ -288,18 +293,26 @@ pub fn compile_evaluable_into(
for (offset, name, t) in attribs {
if name.name() == access.name() {
if &t.plus_one_indirect() != target.type_ref() {
todo!()
return WErr::ne(
EvalErrs::ExpectedDifferentType(
global_table.get_type_name(target.type_ref()),
global_table.get_type_name(&t.plus_one_indirect()),
), access.location().clone()
)
}
found_offset = Some(*offset);
}
}

let Some(found_offset) = found_offset else {
todo!()
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() {
// TODO: Not 64 bit!
// TODO: This is not full 64 bit!
ab.line(&format!("mov rax, {}", inner.local_address()));
ab.line(&format!("add rax, {}", found_offset.0));
ab.line(&format!("mov qword {}, rax", target.local_address()));
Expand Down Expand Up @@ -386,7 +399,13 @@ pub fn compile_evaluable_into(

if *struct_init.heap_alloc() {
if target.type_ref() != &t.plus_one_indirect() {
todo!()
return WErr::ne(
EvalErrs::ExpectedDifferentType(
global_table.get_type_name(target.type_ref()),
global_table.get_type_name(&t.plus_one_indirect()),
),
struct_init.location().clone(),
);
}
let mut ab = AssemblyBuilder::new();
let (c, sr) =
Expand All @@ -403,10 +422,22 @@ pub fn compile_evaluable_into(
debug_assert!(!t.indirection().has_indirection());

if *struct_init.heap_alloc() && &t.plus_one_indirect() != target.type_ref() {
todo!()
return WErr::ne(
EvalErrs::ExpectedDifferentType(
global_table.get_type_name(target.type_ref()),
global_table.get_type_name(&t.plus_one_indirect()),
),
struct_init.location().clone(),
);
}
if !struct_init.heap_alloc() && &t != target.type_ref() {
todo!();
return WErr::ne(
EvalErrs::ExpectedDifferentType(
global_table.get_type_name(target.type_ref()),
global_table.get_type_name(&t),
),
struct_init.location().clone(),
);
}

let tt = global_table.get_type(t.type_id().clone());
Expand All @@ -424,7 +455,10 @@ pub fn compile_evaluable_into(
let give_attrs = struct_init.contents();

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

let mut code = AssemblyBuilder::new();
Expand All @@ -433,7 +467,10 @@ pub fn compile_evaluable_into(
for ((offset, t_name, t_type), (name, val)) in attributes.iter().zip(give_attrs.iter())
{
if t_name.name() != name.name() {
todo!()
return WErr::ne(
WrongAttributeNameInInit(t_name.name().clone(), name.name().clone()),
name.location().clone()
);
}

let new_addr = AddressedTypeRef::new(
Expand Down
2 changes: 1 addition & 1 deletion src/root/compiler/evaluation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ pub fn expect_addr(
//
// let et = et.token();
//
// todo!()
//
// }
Loading

0 comments on commit 6dd310f

Please sign in to comment.