diff options
author | John Hodge <tpg@mutabah.net> | 2016-05-16 20:37:31 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-05-16 20:37:31 +0800 |
commit | 2b74d7274d0b9a0d96401749c0cd345972567c88 (patch) | |
tree | bc9079aa3f637157e49cc2bd729f5c9410a4b33c /src | |
parent | 0733ed89c69f6488e4c1a6c18a51e355231c1969 (diff) | |
download | mrust-2b74d7274d0b9a0d96401749c0cd345972567c88.tar.gz |
HIR - Slowly fleshing out
Diffstat (limited to 'src')
-rw-r--r-- | src/hir/from_ast.cpp | 64 | ||||
-rw-r--r-- | src/hir/hir.hpp | 7 | ||||
-rw-r--r-- | src/hir/type.hpp | 3 | ||||
-rw-r--r-- | src/main.cpp | 5 |
4 files changed, 71 insertions, 8 deletions
diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp index 28fa490c..fa10c344 100644 --- a/src/hir/from_ast.cpp +++ b/src/hir/from_ast.cpp @@ -35,7 +35,22 @@ // -------------------------------------------------------------------- ::HIR::GenericParams LowerHIR_GenericParams(const ::AST::GenericParams& gp) { - throw ::std::runtime_error("TODO: LowerHIR_GenericParams"); + ::HIR::GenericParams rv; + + if( gp.ty_params().size() > 0 ) + { + throw ::std::runtime_error("TODO: LowerHIR_GenericParams - types"); + } + if( gp.lft_params().size() > 0 ) + { + throw ::std::runtime_error("TODO: LowerHIR_GenericParams - lifetimes"); + } + if( gp.bounds().size() > 0 ) + { + throw ::std::runtime_error("TODO: LowerHIR_GenericParams - bounds"); + } + + return rv; } ::HIR::Pattern LowerHIR_Pattern(const ::AST::Pattern& pat) @@ -107,7 +122,7 @@ throw "BUG: Encountered Invalid path in LowerHIR_Path"; ), (Local, - throw "TODO: What to do wth Path::Class::Local in LowerHIR_Path"; + BUG(Span(), "TODO: What to do wth Path::Class::Local in LowerHIR_Path - " << path); ), (Relative, throw "BUG: Encountered `Relative` path in LowerHIR_Path"; @@ -132,7 +147,7 @@ ); ) ) - throw ::std::runtime_error("TODO: LowerHIR_Path"); + throw "BUGCHECK: Reached end of LowerHIR_Path"; } ::HIR::TypeRef LowerHIR_Type(const ::TypeRef& ty) @@ -198,7 +213,20 @@ ), (Path, - return ::HIR::TypeRef( LowerHIR_Path(e.path) ); + TU_IFLET(::AST::Path::Class, e.path.m_class, Local, l, + unsigned int slot; + // NOTE: TypeParameter is unused + TU_IFLET(::AST::PathBinding, e.path.binding(), Variable, p, + slot = p.slot; + ) + else { + BUG(ty.span(), "Unbound local encountered in " << e.path); + } + return ::HIR::TypeRef( l.name, slot ); + ) + else { + return ::HIR::TypeRef( LowerHIR_Path(e.path) ); + } ), (TraitObject, if( e.hrls.size() > 0 ) @@ -226,14 +254,34 @@ throw ::std::runtime_error("TODO: LowerHIR_TypeAlias"); } -::HIR::Struct LowerHIR_Struct(const ::AST::Struct& ta) +::HIR::Struct LowerHIR_Struct(const ::AST::Struct& ent) { ::HIR::Struct::Data data; - - throw ::std::runtime_error("TODO: LowerHIR_Struct"); + TU_MATCH(::AST::StructData, (ent.m_data), (e), + (Tuple, + if( e.ents.size() == 0 ) { + data = ::HIR::Struct::Data::make_Unit({}); + } + else { + ::HIR::Struct::Data::Data_Tuple fields; + + for(const auto& field : e.ents) + fields.push_back( { field.m_is_public, LowerHIR_Type(field.m_type) } ); + + data = ::HIR::Struct::Data::make_Tuple( mv$(fields) ); + } + ), + (Struct, + ::HIR::Struct::Data::Data_Named fields; + for(const auto& field : e.ents) + fields.push_back( ::std::make_pair( field.m_name, ::HIR::VisEnt< ::HIR::TypeRef> { field.m_is_public, LowerHIR_Type(field.m_type) } ) ); + data = ::HIR::Struct::Data::make_Named( mv$(fields) ); + ) + ) + return ::HIR::Struct { - LowerHIR_GenericParams(ta.params()), + LowerHIR_GenericParams(ent.params()), mv$(data) }; } diff --git a/src/hir/hir.hpp b/src/hir/hir.hpp index b55194e6..5592cd9b 100644 --- a/src/hir/hir.hpp +++ b/src/hir/hir.hpp @@ -91,6 +91,13 @@ struct Enum }; struct Struct { + enum class Repr + { + Rust, + C, + Packed, + //Union, + }; TAGGED_UNION(Data, Unit, (Unit, struct {}), (Tuple, ::std::vector< VisEnt<::HIR::TypeRef> >), diff --git a/src/hir/type.hpp b/src/hir/type.hpp index 953224f3..dc1f204f 100644 --- a/src/hir/type.hpp +++ b/src/hir/type.hpp @@ -90,6 +90,9 @@ struct TypeRef TypeRef(TypeRef&& ) = default; TypeRef(const TypeRef& ) = delete; + TypeRef(::std::string name, unsigned int slot): + m_data( Data::make_Generic({ mv$(name), slot }) ) + {} TypeRef(::HIR::TypeRef::Data x): m_data( mv$(x) ) {} diff --git a/src/main.cpp b/src/main.cpp index 74e92f76..369b1185 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -191,6 +191,11 @@ int main(int argc, char *argv[]) ::std::cerr << "Misc Error: " << e.what() << ::std::endl;
return 2;
}
+ //catch(const char* e)
+ //{
+ // ::std::cerr << "Internal Compiler Error: " << e << ::std::endl;
+ // return 2;
+ //}
return 0;
}
|