Skip to content

Commit

Permalink
Remove UnresolvedFunctionImplementation.decorators as it's not needed…
Browse files Browse the repository at this point in the history
… now. Improve a few error messages.
  • Loading branch information
Ivorforce committed Apr 28, 2024
1 parent 5df6c91 commit e0a19f9
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/interpreter/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn get_main_function(module: &Module) -> RResult<Option<&Rc<FunctionHead>>>
let entry_function = match &module.main_functions[..] {
[] => return Ok(None),
[f] => f,
functions => return Err(RuntimeError::error(format!("Too many @main functions declared: {:?}", functions).as_str()).to_array()),
functions => return Err(RuntimeError::error(format!("Too many !main functions declared: {:?}", functions).as_str()).to_array()),
};
if !entry_function.interface.parameters.is_empty() {
return Err(RuntimeError::error("main! function has parameters.").to_array());
Expand Down
12 changes: 12 additions & 0 deletions src/parser/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ impl From<Vec<Box<Positioned<Term>>>> for Expression {
}
}

impl Array {
pub fn empty() -> Array {
Array { arguments: vec![] }
}
}

impl Struct {
pub fn empty() -> Struct {
Struct { arguments: vec![] }
}
}

#[derive(Eq, PartialEq, Clone)]
pub enum Term {
Error(RuntimeError),
Expand Down
6 changes: 5 additions & 1 deletion src/resolver/ambiguous/function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ impl ResolverAmbiguity for AmbiguousFunctionCall {
types: &resolver.types,
};
Err(
RuntimeError::error(format!("function {} could not be resolved. {} candidates failed type / requirements test.", signature, cs.len()).as_str()).to_array()
RuntimeError::error(format!("function {} could not be resolved. ", signature).as_str())
.with_note(
RuntimeError::info(format!("{} candidates failed type / requirements test.", cs.len()).as_str())
)
.to_array()
)
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/resolver/conformance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use crate::refactor::monomorphize::map_interface_types;
pub struct UnresolvedFunctionImplementation<'a> {
pub function: Rc<FunctionHead>,
pub representation: FunctionRepresentation,
pub decorators: Vec<String>,
pub body: &'a Option<ast::Expression>,
}

Expand All @@ -40,17 +39,16 @@ impl <'a, 'b> ConformanceResolver<'a, 'b> {
function,
representation,
body: &syntax.body,
decorators: vec![],
});
}
ast::Statement::Expression(e) => {
return Err(
RuntimeError::error(format!("Expression {} not valid in a conformance context.", statement).as_str()).to_array()
RuntimeError::error("Expression not valid in a conformance context.").to_array()
);
}
_ => {
return Err(
RuntimeError::error(format!("Statement {} not valid in a conformance context.", statement).as_str()).to_array()
RuntimeError::error("Statement {} not valid in a conformance context.").to_array()
);
}
}
Expand Down
18 changes: 6 additions & 12 deletions src/resolver/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl <'a> GlobalResolver<'a> {
self.global_variables.add_pattern(pattern)?;
}
self.schedule_function_body(&fun, syntax.body.as_ref(), pstatement.value.position.clone());
self.add_function_interface(fun, representation, &vec![])?;
self.add_function_interface(fun, representation)?;
}
ast::Statement::Trait(syntax) => {
pstatement.no_decorations()?;
Expand Down Expand Up @@ -192,7 +192,7 @@ impl <'a> GlobalResolver<'a> {
self.schedule_function_body(&fun.function, fun.body.as_ref(), pstatement.value.position.clone());
// TODO Instead of adding conformance functions statically, we should add the abstract function to the scope.
// This will allow the compiler to determine "function exists but no declaration exists" in the future.
self.add_function_interface(fun.function, fun.representation.clone(), &fun.decorators)?;
self.add_function_interface(fun.function, fun.representation.clone())?;
}
}
ast::Statement::Expression(e) => {
Expand Down Expand Up @@ -237,12 +237,12 @@ impl <'a> GlobalResolver<'a> {
}

return Err(
RuntimeError::error(format!("Expression {} is not supported in a global context.", e).as_str()).to_array()
RuntimeError::error("Expression is not supported in a global context.").to_array()
)
}
statement => {
_ => {
return Err(
RuntimeError::error(format!("Statement {} is not supported in a global context.", statement).as_str()).to_array()
RuntimeError::error("Statement is not supported in a global context.").to_array()
)
}
}
Expand All @@ -263,13 +263,7 @@ impl <'a> GlobalResolver<'a> {
Ok(())
}

pub fn add_function_interface(&mut self, pointer: Rc<FunctionHead>, representation: FunctionRepresentation, decorators: &Vec<String>) -> RResult<()> {
for decorator in decorators.iter() {
return Err(
RuntimeError::error(format!("Decorator could not be resolved: {}", decorator).as_str()).to_array()
)
}

pub fn add_function_interface(&mut self, pointer: Rc<FunctionHead>, representation: FunctionRepresentation) -> RResult<()> {
referencible::add_function(self.runtime, &mut self.module, Some(&mut self.global_variables), pointer, representation)?;

Ok(())
Expand Down
8 changes: 3 additions & 5 deletions src/resolver/grammar/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,16 @@ pub fn resolve_expression_to_tokens(resolver: &mut ImperativeResolver, syntax: &

match next_token.map(|t| &t.value) {
Some(ast::Term::Struct(s)) => {
let range = &next_token.unwrap().position;

// The next token is a struct; we can immediately call it!
let struct_ = resolver.resolve_struct(scope, s).err_in_range(range)?;
let struct_ = resolver.resolve_struct(scope, s).err_in_range(&next_token.unwrap().position)?;

let expression_id = resolver.resolve_function_call(
overload.functions.iter(),
overload.representation.clone(),
[ParameterKey::Positional].into_iter().chain(struct_.keys.clone()).collect_vec(),
[target.clone()].into_iter().chain(struct_.values.clone()).collect_vec(),
scope,
ast_token.position.clone(),
range.clone(),
).err_in_range(range)?;

Token::Value(expression_id)
Expand All @@ -151,7 +149,7 @@ pub fn resolve_expression_to_tokens(resolver: &mut ImperativeResolver, syntax: &
vec![ParameterKey::Positional],
vec![target.clone()],
scope,
ast_token.position.clone()
range.clone()
).err_in_range(range)?
)
}
Expand Down
9 changes: 3 additions & 6 deletions src/resolver/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ impl <'a> TraitResolver<'a> {
}
ast::Statement::Expression(e) => {
return Err(
RuntimeError::error(format!("Expression {} not valid in a trait context.", statement).as_str()).to_array()
RuntimeError::error("Expression not valid in a trait context.").to_array()
);
}
_ => {
return Err(
RuntimeError::error(format!("Statement {} not valid in a trait context.", statement).as_str()).to_array()
RuntimeError::error("Statement not valid in a trait context.").to_array()
);
}
}
Expand Down Expand Up @@ -180,7 +180,6 @@ pub fn try_make_struct(trait_: &Rc<Trait>, resolver: &mut GlobalResolver) -> RRe
resolver.add_function_interface(
Rc::clone(&struct_.constructor),
FunctionRepresentation::new("call_as_function", FunctionTargetType::Member, FunctionCallExplicity::Explicit),
&vec![],
)?;

for (ref_, head) in struct_.field_getters.iter() {
Expand All @@ -193,8 +192,7 @@ pub fn try_make_struct(trait_: &Rc<Trait>, resolver: &mut GlobalResolver) -> RRe
resolver.add_function_interface(
Rc::clone(head),
FunctionRepresentation::new(name, FunctionTargetType::Member, FunctionCallExplicity::Implicit),
&vec![])?
;
)?;
}

for (ref_, head) in struct_.field_setters.iter() {
Expand All @@ -207,7 +205,6 @@ pub fn try_make_struct(trait_: &Rc<Trait>, resolver: &mut GlobalResolver) -> RRe
resolver.add_function_interface(
Rc::clone(head),
FunctionRepresentation::new(name, FunctionTargetType::Member, FunctionCallExplicity::Implicit),
&vec![]
)?;
}

Expand Down

0 comments on commit e0a19f9

Please sign in to comment.