From d296771ea7229a62ee26e818aea483456bc64187 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 30 Apr 2016 22:46:29 +0800 Subject: Resolve - Fleshing out absolute --- src/resolve/absolute.cpp | 134 ++++++++++++++++++++++++++++++++++++++++++++++- src/resolve/index.cpp | 3 +- src/types.hpp | 2 +- 3 files changed, 136 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/resolve/absolute.cpp b/src/resolve/absolute.cpp index dd0c5f0d..c965d2ee 100644 --- a/src/resolve/absolute.cpp +++ b/src/resolve/absolute.cpp @@ -1,16 +1,148 @@ /* * Convert all paths in AST into absolute form (or to the relevant local item) + * - NOTE: This is the core of the 'resolve' pass. * * After complete there should be no: * - Relative/super/self paths * - MaybeBind patterns */ #include +#include #include +struct GenericSlot +{ + enum class Level + { + Impl, + Function, + } level; + unsigned short index; +}; +template +struct Named +{ + ::std::string name; + Val value; +}; + +struct Context +{ + TAGGED_UNION(Ent, Module, + (Module, struct { + const ::AST::Module* mod; + }), + (VarBlock, struct { + // "Map" of names to function-level variable slots + ::std::vector< Named< unsigned int > > variables; + }), + (Generic, struct { + // Map of names to slots + ::std::vector< Named< GenericSlot > > types; + ::std::vector< Named< GenericSlot > > constants; + ::std::vector< Named< GenericSlot > > lifetimes; + }) + ); + + const ::AST::Module& m_mod; + ::std::vector m_name_context; + + Context(const::AST::Module& mod): + m_mod(mod) + {} +}; + +void Resolve_Absolute_Type(const ::AST::Crate& crate, const Context& context, TypeRef& type) +{ + TU_MATCH(TypeData, (type.m_data), (e), + (None, + // ! type + ), + (Any, + // _ type + ), + (Unit, + ), + (Macro, + BUG(Span(), "Resolve_Absolute_Type - Encountered an unexpanded macro"); + ), + (Primitive, + ), + (Function, + TODO(Span(), "Resolve_Absolute_Type - Function - " << type); + ), + (Tuple, + for(auto& t : e.inner_types) + Resolve_Absolute_Type(crate, context, t); + ), + (Borrow, + Resolve_Absolute_Type(crate, context, *e.inner); + ), + (Pointer, + Resolve_Absolute_Type(crate, context, *e.inner); + ), + (Array, + Resolve_Absolute_Type(crate, context, *e.inner); + ), + (Generic, + TODO(Span(), "Resolve_Absolute_Type - Encountered generic"); + ), + (Path, + TODO(Span(), "Resolve_Absolute_Type - Path"); + ), + (TraitObject, + TODO(Span(), "Resolve_Absolute_Type - TraitObject"); + ) + ) +} + +void Resolve_Absolute_Expr(const ::AST::Crate& crate, const Context& context, ::AST::Expr& expr) +{ + if( expr.is_valid() ) + { + TODO(Span(), "Resolve_Absolute_Expr"); + } +} + +void Resolve_Absolute_Mod(const ::AST::Crate& crate, ::AST::Module& mod) +{ + for( auto& i : mod.items() ) + { + TU_MATCH(AST::Item, (i.data), (e), + (None, + ), + (Module, + Resolve_Absolute_Mod(crate, e); + ), + (Crate, + // - Nothing + ), + (Enum, + TODO(Span(), "Resolve_Absolute_Mod - Enum"); + ), + (Trait, + TODO(Span(), "Resolve_Absolute_Mod - Trait"); + ), + (Type, + TODO(Span(), "Resolve_Absolute_Mod - Type"); + ), + (Struct, + TODO(Span(), "Resolve_Absolute_Mod - Struct"); + ), + (Function, + TODO(Span(), "Resolve_Absolute_Mod - Function"); + ), + (Static, + Resolve_Absolute_Type( crate, Context(mod), e.type() ); + Resolve_Absolute_Expr( crate, Context(mod), e.value() ); + ) + ) + } +} + void Resolve_Absolutise(AST::Crate& crate) { - TODO(Span(), "Run 'absolutise' resolve pass"); + Resolve_Absolute_Mod(crate, crate.root_module()); } diff --git a/src/resolve/index.cpp b/src/resolve/index.cpp index cb4ffc6b..b5fdbf33 100644 --- a/src/resolve/index.cpp +++ b/src/resolve/index.cpp @@ -59,7 +59,8 @@ void Resolve_Index_Module_Base(AST::Module& mod) // - Mixed (Struct, _add_item_type(mod, i.name, i.is_pub, ::AST::PathBinding::make_Struct({&e})); - if( e.m_data.is_Struct() ) { + // - If the struct is a tuple-like struct, it presents in the value namespace + if( e.m_data.is_Tuple() ) { _add_item_value(mod, i.name, i.is_pub, ::AST::PathBinding::make_Struct({&e})); } ), diff --git a/src/types.hpp b/src/types.hpp index ba20aa26..2c59e8b6 100644 --- a/src/types.hpp +++ b/src/types.hpp @@ -68,7 +68,7 @@ TAGGED_UNION(TypeData, None, enum eCoreType core_type; }), (Function, struct { - Type_Function info; + Type_Function info; }), (Tuple, struct { ::std::vector inner_types; -- cgit v1.2.3