Skip to content

Commit

Permalink
Improved name evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-M-Lucas committed Jun 5, 2024
1 parent d15ab64 commit 0c481eb
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 48 deletions.
20 changes: 16 additions & 4 deletions .idea/workspace.xml

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

2 changes: 1 addition & 1 deletion src/root/compiler/compile_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::root::compiler::assembly::utils::{align_16_bytes, align_16_bytes_plus
use crate::root::compiler::compile_evaluable::compile_evaluable;
use crate::root::compiler::local_variable_table::LocalVariableTable;
use crate::root::errors::WError;
use crate::root::name_resolver::name_resolvers::{GlobalDefinitionTable, NameResultId};
use crate::root::name_resolver::name_resolvers::{GlobalDefinitionTable};
use crate::root::parser::parse_function::FunctionToken;
use crate::root::parser::parse_function::parse_line::LineTokens;
use crate::root::shared::common::{FunctionID, LocalAddress};
Expand Down
10 changes: 3 additions & 7 deletions src/root/name_resolver/name_resolvers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::root::name_resolver::resolve_function_signatures::FunctionSignature;
use crate::root::parser::parse::Location;
use crate::root::shared::types::Type;
use crate::root::parser::parse_function::FunctionToken;
use crate::root::parser::parse_function::parse_evaluable::FullNameWithIndirectionToken;
use crate::root::parser::parse_struct::StructToken;
use crate::root::shared::common::{AddressedTypeRef, FunctionID, TypeID, TypeRef};

Expand Down Expand Up @@ -99,12 +100,6 @@ pub enum NameResult<'a> {
NotFound
}

pub enum NameResultId {
Function(FunctionID),
Type(TypeRef),
NotFound
}

impl GlobalDefinitionTable {
pub fn new() -> GlobalDefinitionTable {
GlobalDefinitionTable {
Expand Down Expand Up @@ -178,7 +173,8 @@ impl GlobalDefinitionTable {
todo!()
}

pub fn resolve_global_name_to_id(&self, name: &UnresolvedNameToken, location: &Location) -> Result<NameResultId, WError> {
pub fn resolve_global_name_to_id(&self, name: &FullNameWithIndirectionToken) -> Result<TypeRef, WError> {
let (indirection, full_name) = (name.indirection(), name.inner());
let path = name.location().path();

fn search_file_level_tree(tree: &Box<FileLevelTree>, name: &UnresolvedNameToken, location: &Location) -> Result<Option<NameResultId>, WError> {
Expand Down
22 changes: 7 additions & 15 deletions src/root/name_resolver/resolve_function_signatures.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use derive_getters::Getters;
use crate::root::errors::WError;
use crate::root::name_resolver::name_resolvers::{GlobalDefinitionTable, NameResult, NameResultId};
use crate::root::name_resolver::name_resolvers::{GlobalDefinitionTable};
use crate::root::shared::common::TypeRef;
use crate::root::parser::parse_function::FunctionToken;
use crate::root::parser::parse_name::SimpleNameToken;

#[derive(Getters)]
pub struct FunctionSignature {
args: Vec<(String, TypeRef)>,
args: Vec<(SimpleNameToken, TypeRef)>,
return_type: Option<TypeRef>
}

Expand All @@ -15,24 +16,15 @@ pub fn resolve_function_signature(function_token: &FunctionToken, global_table:

let return_type = if let Some((type_name, location)) = function_token.return_type() {
// TODO
Some(match global_table.resolve_global_name_to_id(type_name, location)? {
NameResultId::Function(_) => todo!(),
NameResultId::Type(type_id) => type_id,
NameResultId::NotFound => todo!()
})
Some(global_table.resolve_global_name_to_id(type_name)?)
} else {
None
};

for (arg_name, (arg_type, arg_type_loc)) in function_token.parameters() {
for (arg_name, arg_type) in function_token.parameters() {
args.push((
arg_name.0.clone(),
// TODO
match global_table.resolve_global_name_to_id(arg_type, arg_type_loc)? {
NameResultId::Function(_) => todo!(),
NameResultId::Type(type_ref) => type_ref,
NameResultId::NotFound => todo!()
}
arg_name.clone(),
global_table.resolve_global_name_to_id(arg_type)?
))
}

Expand Down
27 changes: 10 additions & 17 deletions src/root/name_resolver/resolve_names.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use std::any::Any;
use std::collections::HashMap;

use derive_getters::Getters;
use itertools::Itertools;
use crate::root::errors::name_resolver_errors::NRErrors;
use crate::root::errors::WError;

use crate::root::name_resolver::name_resolvers::{GlobalDefinitionTable, NameResultId};
use crate::root::name_resolver::name_resolvers::{GlobalDefinitionTable};
use crate::root::name_resolver::resolve_function_signatures::resolve_function_signature;
use crate::root::name_resolver::resolve_type_sizes::{resolve_type_sizes, UnsizedUserType};
use crate::root::parser::parse::Location;
use crate::root::parser::parse_function::FunctionToken;
use crate::root::parser::parse_function::parse_evaluable::{FullNameToken, FullNameTokens};
use crate::root::parser::parse_function::parse_literal::LiteralToken;
use crate::root::parser::parse_toplevel::TopLevelTokens;
use crate::root::shared::common::{LocalAddress, TypeRef};
Expand Down Expand Up @@ -117,11 +119,7 @@ pub fn resolve_names(ast: Vec<TopLevelTokens>, global_table: &mut GlobalDefiniti

let mut p_attributes = Vec::new();
for ((name, name_loc), (type_name, type_name_loc)) in attributes {
let type_ref = match global_table.resolve_global_name_to_id(&type_name, &type_name_loc)? {
NameResultId::Type(type_ref) => type_ref,
NameResultId::Function(_) => todo!(),
NameResultId::NotFound => todo!(),
};
let type_ref = global_table.resolve_global_name_to_id(&type_name)?;

for (e_name, _) in &p_attributes {
if e_name == &name {
Expand All @@ -133,19 +131,14 @@ pub fn resolve_names(ast: Vec<TopLevelTokens>, global_table: &mut GlobalDefiniti
unsized_final_types.insert(id, UnsizedUserType::new(id, p_attributes, location));
}
TopLevelTokens::Impl(it) => {
// TODO
let type_ref = match global_table.resolve_global_name_to_id(&UnresolvedNameToken::new_unresolved_top(it.name().clone(), it.location().clone()), it.location())? {
NameResultId::Function(_) => todo!(),
NameResultId::Type(type_ref) => type_ref,
NameResultId::NotFound => todo!(),
};

if type_ref.indirection().has_indirection() {
return Err(WError::n(NRErrors::IndirectImpl, it.location().clone()));
}
let (location, name, functions) = it.dissolve();
let type_id = *global_table.resolve_global_name_to_id(FullNameToken::new(
location.clone(),
FullNameTokens::Name(name, None)
).with_no_indirection())?.type_id();

for ft in it.dissolve().2 {
let function_id = global_table.add_from_function_token(&ft, Some(*type_ref.type_id()));
let function_id = global_table.add_from_function_token(&ft, Some(type_id));
global_table.add_function_signature(function_id, resolve_function_signature(&ft, &global_table)?);
unprocessed_functions.insert(function_id, ft);
}
Expand Down
2 changes: 1 addition & 1 deletion src/root/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ pub mod parse_struct;
pub mod parse_toplevel;
pub mod parse_util;
pub mod soft_alt;
mod parse_name;
pub mod parse_name;
13 changes: 10 additions & 3 deletions src/root/parser/parse_function/parse_evaluable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,21 @@ pub struct FullNameToken {
}

impl FullNameToken {
pub fn new(s: &Span, token: FullNameTokens) -> FullNameToken {
pub fn new(location: Location, token: FullNameTokens) -> FullNameToken {
FullNameToken {
location: Location::from_span(s),
location,
token,
}
}

fn to_evaluable(self) -> EvaluableToken {
pub fn with_no_indirection(self) -> FullNameWithIndirectionToken {
FullNameWithIndirectionToken {
indirection: Indirection(0),
inner: self
}
}

pub fn to_evaluable(self) -> EvaluableToken {
let (location, token) = (self.location, self.token);
let token = token.to_evaluable_token();
EvaluableToken {
Expand Down

0 comments on commit 0c481eb

Please sign in to comment.