diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/hir/hir.cpp | 4 | ||||
-rw-r--r-- | src/hir/type.cpp | 26 | ||||
-rw-r--r-- | src/hir/type.hpp | 8 | ||||
-rw-r--r-- | src/hir/visitor.cpp | 6 | ||||
-rw-r--r-- | src/hir_typeck/expr.cpp | 39 | ||||
-rw-r--r-- | src/hir_typeck/outer.cpp | 3 |
6 files changed, 84 insertions, 2 deletions
diff --git a/src/hir/hir.cpp b/src/hir/hir.cpp index d9f85a53..9b00bcc0 100644 --- a/src/hir/hir.cpp +++ b/src/hir/hir.cpp @@ -130,6 +130,10 @@ namespace { (Function, DEBUG("TODO: Compare " << left << " and " << right); return false; + ), + (Closure, + DEBUG("TODO: Compare " << left << " and " << right); + return false; ) ) return false; diff --git a/src/hir/type.cpp b/src/hir/type.cpp index a4f96fa0..14424dab 100644 --- a/src/hir/type.cpp +++ b/src/hir/type.cpp @@ -119,6 +119,12 @@ void ::HIR::TypeRef::fmt(::std::ostream& os) const for(const auto& t : e.m_arg_types) os << t << ", "; os << ") -> " << *e.m_rettype; + ), + (Closure, + os << "closure["<<e.node<<"]("; + for(const auto& t : e.m_arg_types) + os << t << ", "; + os << ") -> " << *e.m_rettype; ) ) } @@ -237,6 +243,12 @@ bool ::HIR::TypeRef::operator==(const ::HIR::TypeRef& x) const return false; } return te.m_rettype == xe.m_rettype; + ), + (Closure, + if( te.node != xe.node ) + return false; + assert( te.m_rettype == xe.m_rettype ); + return true; ) ) throw ""; @@ -329,6 +341,9 @@ void ::HIR::TypeRef::match_generics(const Span& sp, const ::HIR::TypeRef& x_in, ), (Function, TODO(sp, "Function"); + ), + (Closure, + TODO(sp, "Closure"); ) ) } @@ -410,6 +425,14 @@ namespace { for(const auto& a : e.m_arg_types) ft.m_arg_types.push_back( a.clone() ); return ::HIR::TypeRef(Data::make_Function( mv$(ft) )); + ), + (Closure, + Data::Data_Closure oe; + oe.node = e.node; + oe.m_rettype = box$( e.m_rettype->clone() ); + for(const auto& a : e.m_arg_types) + oe.m_arg_types.push_back( a.clone() ); + return ::HIR::TypeRef(Data::make_Closure( mv$(oe) )); ) ) throw ""; @@ -520,6 +543,9 @@ namespace { ), (Function, TODO(sp, "Compare " << *this << " and " << right); + ), + (Closure, + TODO(sp, "Compare " << *this << " and " << right); ) ) throw ""; diff --git a/src/hir/type.hpp b/src/hir/type.hpp index b3dd0fc8..8c3e1919 100644 --- a/src/hir/type.hpp +++ b/src/hir/type.hpp @@ -14,6 +14,7 @@ class Struct; class Enum; class TypeRef; +class ExprNode_Closure; enum class InferClass { @@ -113,7 +114,12 @@ public: ::HIR::BorrowType type; ::std::unique_ptr<TypeRef> inner; }), - (Function, FunctionType) + (Function, FunctionType), + (Closure, struct { + const ::HIR::ExprNode_Closure* node; + ::std::unique_ptr<TypeRef> m_rettype; + ::std::vector<TypeRef> m_arg_types; + }) ); Data m_data; diff --git a/src/hir/visitor.cpp b/src/hir/visitor.cpp index cb9874c2..2d879d7f 100644 --- a/src/hir/visitor.cpp +++ b/src/hir/visitor.cpp @@ -300,6 +300,12 @@ void ::HIR::Visitor::visit_type(::HIR::TypeRef& ty) this->visit_type(t); } this->visit_type(*e.m_rettype); + ), + (Closure, + for(auto& t : e.m_arg_types) { + this->visit_type(t); + } + this->visit_type(*e.m_rettype); ) ) } diff --git a/src/hir_typeck/expr.cpp b/src/hir_typeck/expr.cpp index 5d6bf59d..bef598ce 100644 --- a/src/hir_typeck/expr.cpp +++ b/src/hir_typeck/expr.cpp @@ -77,6 +77,9 @@ namespace { ), (Function, TODO(Span(), "Function - " << tpl); + ), + (Closure, + TODO(Span(), "Closure - " << tpl); ) ) throw ""; @@ -168,6 +171,14 @@ namespace { ), (Function, TODO(sp, "Function"); + ), + (Closure, + ::HIR::TypeRef::Data::Data_Closure oe; + oe.node = e.node; + oe.m_rettype = box$( monomorphise_type_with(sp, *e.m_rettype, callback) ); + for(const auto& a : e.m_arg_types) + oe.m_arg_types.push_back( monomorphise_type_with(sp, a, callback) ); + return ::HIR::TypeRef(::HIR::TypeRef::Data::make_Closure( mv$(oe) )); ) ) throw ""; @@ -346,6 +357,9 @@ namespace { (Function, // No ivars allowed // TODO: Check? + ), + (Closure, + // Shouldn't be possible ) ) } @@ -1134,6 +1148,9 @@ namespace { for(unsigned int i = 0; i < l_e.m_arg_types.size(); i ++ ) { this->apply_equality(sp, l_e.m_arg_types[i], cb_left, r_e.m_arg_types[i], cb_right, nullptr); } + ), + (Closure, + TODO(sp, "apply_equality - Closure"); ) ) } @@ -1396,6 +1413,9 @@ namespace { ), (Function, // Recurse? + ), + (Closure, + // Recurse? ) ) return input; @@ -1943,13 +1963,21 @@ namespace { } void visit(::HIR::ExprNode_Closure& node) override { + ::HIR::TypeRef::Data::Data_Closure ty_data; + ty_data.node = &node; + for(auto& a : node.m_args) { this->context.add_ivars(a.second); this->context.add_binding(node.span(), a.first, a.second); + ty_data.m_arg_types.push_back( a.second.clone() ); } this->context.add_ivars(node.m_return); + ty_data.m_rettype = box$( node.m_return.clone() ); + node.m_code->m_res_type = node.m_return.clone(); + this->context.apply_equality( node.span(), node.m_res_type, ::HIR::TypeRef( ::HIR::TypeRef::Data::make_Closure(mv$(ty_data)) ) ); + ::HIR::ExprVisitorDef::visit(node); } // - Variable: Bind to same ivar @@ -2615,6 +2643,8 @@ namespace { const auto& fcn = trait.m_values.at(e.item).as_Function(); this->fix_param_count(sp, path, fcn.m_params, e.params); + // TODO: Check/apply trait bounds (apply = closure arguments or fixed trait args) + fcn_ptr = &fcn; const auto& trait_params = e.trait.m_params; @@ -3018,7 +3048,14 @@ namespace { this->check_type_resolved(sp, *e.inner, top_type); ), (Function, - // TODO: + this->check_type_resolved(sp, *e.m_rettype, top_type); + for(auto& st : e.m_arg_types) + this->check_type_resolved(sp, st, top_type); + ), + (Closure, + this->check_type_resolved(sp, *e.m_rettype, top_type); + for(auto& st : e.m_arg_types) + this->check_type_resolved(sp, st, top_type); ) ) } diff --git a/src/hir_typeck/outer.cpp b/src/hir_typeck/outer.cpp index e1c83f55..211f9007 100644 --- a/src/hir_typeck/outer.cpp +++ b/src/hir_typeck/outer.cpp @@ -155,6 +155,9 @@ namespace { ), (Function, TODO(sp, "update_self_type - Function"); + ), + (Closure, + TODO(sp, "update_self_type - Closure"); ) ) } |