diff options
author | John Hodge (bugs) <tpg@mutabah.net> | 2017-05-14 12:01:45 +0800 |
---|---|---|
committer | John Hodge (bugs) <tpg@mutabah.net> | 2017-05-14 12:01:45 +0800 |
commit | 1d2fe7681219700998c8ecbdb8ed5acab66578df (patch) | |
tree | 0d38e8ab5fd80c890d3dec67a0596abfc7a4f0cd /src/hir | |
parent | c6fca061dd134068c831aefd88d9535a30f423ed (diff) | |
parent | fde22b3f03d802231985b8ded567cba16cb5aa00 (diff) | |
download | mrust-1d2fe7681219700998c8ecbdb8ed5acab66578df.tar.gz |
Merge branch 'master' of https://github.com/thepowersgang/mrustc
# Conflicts:
# src/common.hpp
# src/hir/deserialise.cpp
# src/hir_typeck/static.cpp
# src/mir/from_hir.cpp
# src/mir/from_hir.hpp
# src/mir/from_hir_match.cpp
# src/mir/helpers.hpp
# src/mir/mir_builder.cpp
Diffstat (limited to 'src/hir')
-rw-r--r-- | src/hir/deserialise.cpp | 6 | ||||
-rw-r--r-- | src/hir/dump.cpp | 40 | ||||
-rw-r--r-- | src/hir/expr.cpp | 2 | ||||
-rw-r--r-- | src/hir/expr.hpp | 9 | ||||
-rw-r--r-- | src/hir/from_ast_expr.cpp | 12 | ||||
-rw-r--r-- | src/hir/hir.cpp | 24 | ||||
-rw-r--r-- | src/hir/hir.hpp | 6 | ||||
-rw-r--r-- | src/hir/serialise.cpp | 6 | ||||
-rw-r--r-- | src/hir/type.cpp | 21 |
9 files changed, 99 insertions, 27 deletions
diff --git a/src/hir/deserialise.cpp b/src/hir/deserialise.cpp index c08f886d..0ff4d63b 100644 --- a/src/hir/deserialise.cpp +++ b/src/hir/deserialise.cpp @@ -586,6 +586,7 @@ namespace { m.dst_type = static_cast< ::HIR::TraitMarkings::DstType>( m_in.read_tag() ); m.coerce_unsized_index = m_in.read_count( ); m.unsized_field = m_in.read_count( ); + m.unsized_param = m_in.read_count(); // TODO: auto_impls return m; } @@ -1009,6 +1010,11 @@ namespace { sdf.other = static_cast<unsigned int>(m_in.read_count()); return ::MIR::Statement::make_SetDropFlag(sdf); } + case 4: + return ::MIR::Statement::make_ScopeEnd({ + deserialise_vec<unsigned int>(), + deserialise_vec<unsigned int>() + }); default: ::std::cerr << "Bad tag for a MIR Statement" << ::std::endl; throw ""; diff --git a/src/hir/dump.cpp b/src/hir/dump.cpp index f00efcd5..8bcffa4e 100644 --- a/src/hir/dump.cpp +++ b/src/hir/dump.cpp @@ -165,7 +165,13 @@ namespace { (Unit, ), (Value, - m_os << " = ?";// << + m_os << " = "; + if( e.val.is_Invalid() ) { + m_os << "?"; + } + else { + m_os << e.val; + } ), (Tuple, m_os << "("; @@ -296,28 +302,28 @@ namespace { void visit(::HIR::ExprNode_Block& node) override { if( node.m_nodes.size() == 0 ) { - m_os << "{ }"; + m_os << "{"; + if( node.m_value_node ) + { + m_os << " "; + this->visit_node_ptr(node.m_value_node); + } + m_os << " }"; } - //else if( node.m_nodes.size() == 1) { - // m_os << "{ "; - // this->visit_node_ptr(node.m_nodes.front()); - // m_os << " }"; - //} else { m_os << "{\n"; inc_indent(); for(auto& sn : node.m_nodes) { + m_os << "\n"; m_os << indent(); this->visit_node_ptr(sn); - if( &sn != &node.m_nodes.back() ) { - m_os << ";\n"; - } - else if( !node.m_yields_final ) { - m_os << ";\n"; - } - else { - m_os << "\n"; - } + m_os << ";\n"; + } + if( node.m_value_node ) + { + m_os << indent(); + this->visit_node_ptr(node.m_value_node); + m_os << "\n"; } dec_indent(); m_os << indent() << "}"; @@ -418,7 +424,7 @@ namespace { void visit(::HIR::ExprNode_Assign& node) override { this->visit_node_ptr(node.m_slot); - m_os << " = "; + m_os << " " << ::HIR::ExprNode_Assign::opname(node.m_op) << "= "; this->visit_node_ptr(node.m_value); } void visit(::HIR::ExprNode_BinOp& node) override diff --git a/src/hir/expr.cpp b/src/hir/expr.cpp index e19e7df6..53f85c42 100644 --- a/src/hir/expr.cpp +++ b/src/hir/expr.cpp @@ -23,6 +23,8 @@ DEF_VISIT(ExprNode_Block, node, for(auto& subnode : node.m_nodes) { visit_node_ptr(subnode); } + if( node.m_value_node ) + visit_node_ptr(node.m_value_node); ) DEF_VISIT(ExprNode_Asm, node, for(auto& v : node.m_outputs) diff --git a/src/hir/expr.hpp b/src/hir/expr.hpp index 81e89b28..3c37a930 100644 --- a/src/hir/expr.hpp +++ b/src/hir/expr.hpp @@ -68,21 +68,20 @@ struct ExprNode_Block: { bool m_is_unsafe; ::std::vector< ExprNodeP > m_nodes; - bool m_yields_final; + ExprNodeP m_value_node; // can be null ::HIR::SimplePath m_local_mod; t_trait_list m_traits; ExprNode_Block(Span sp): ExprNode(mv$(sp)), - m_is_unsafe(false), - m_yields_final(false) + m_is_unsafe(false) {} - ExprNode_Block(Span sp, bool is_unsafe, ::std::vector<ExprNodeP> nodes): + ExprNode_Block(Span sp, bool is_unsafe, ::std::vector<ExprNodeP> nodes, ExprNodeP value_node): ExprNode( mv$(sp) ), m_is_unsafe(is_unsafe), m_nodes( mv$(nodes) ), - m_yields_final(false) + m_value_node( mv$(value_node) ) {} NODE_METHODS(); diff --git a/src/hir/from_ast_expr.cpp b/src/hir/from_ast_expr.cpp index 25f6eade..cd2b27fa 100644 --- a/src/hir/from_ast_expr.cpp +++ b/src/hir/from_ast_expr.cpp @@ -33,7 +33,11 @@ struct LowerHIR_ExprNode_Visitor: ASSERT_BUG(v.get_pos(), n, "NULL node encountered in block"); rv->m_nodes.push_back( LowerHIR_ExprNode_Inner( *n ) ); } - rv->m_yields_final = v.m_yields_final_value; + if( v.m_yields_final_value && ! rv->m_nodes.empty() ) + { + rv->m_value_node = mv$(rv->m_nodes.back()); + rv->m_nodes.pop_back(); + } if( v.m_local_mod ) { @@ -89,8 +93,8 @@ struct LowerHIR_ExprNode_Visitor: case ::AST::ExprNode_Assign::ADD: return ::HIR::ExprNode_Assign::Op::Add; case ::AST::ExprNode_Assign::SUB: return ::HIR::ExprNode_Assign::Op::Sub; - case ::AST::ExprNode_Assign::DIV: return ::HIR::ExprNode_Assign::Op::Mul; - case ::AST::ExprNode_Assign::MUL: return ::HIR::ExprNode_Assign::Op::Div; + case ::AST::ExprNode_Assign::MUL: return ::HIR::ExprNode_Assign::Op::Mul; + case ::AST::ExprNode_Assign::DIV: return ::HIR::ExprNode_Assign::Op::Div; case ::AST::ExprNode_Assign::MOD: return ::HIR::ExprNode_Assign::Op::Mod; case ::AST::ExprNode_Assign::AND: return ::HIR::ExprNode_Assign::Op::And; @@ -328,7 +332,7 @@ struct LowerHIR_ExprNode_Visitor: m_rv.reset( new ::HIR::ExprNode_Loop( v.span(), v.m_label, - ::HIR::ExprNodeP(new ::HIR::ExprNode_Block( v.span(), false, mv$(code))) + ::HIR::ExprNodeP(new ::HIR::ExprNode_Block( v.span(), false, mv$(code), {} )) ) ); break; } case ::AST::ExprNode_Loop::WHILELET: { diff --git a/src/hir/hir.cpp b/src/hir/hir.cpp index 9d1fcf97..d50c3e49 100644 --- a/src/hir/hir.cpp +++ b/src/hir/hir.cpp @@ -93,6 +93,30 @@ const ::HIR::Enum::Variant* ::HIR::Enum::get_variant(const ::std::string& name) return nullptr; return &it->second; } +bool HIR::Enum::is_value() const +{ + return this->m_repr != ::HIR::Enum::Repr::Rust || ::std::all_of(m_variants.begin(), m_variants.end(), [](const auto& x){return x.second.is_Unit() || x.second.is_Value();}); +} +uint32_t HIR::Enum::get_value(size_t idx) const +{ + assert(idx < m_variants.size()); + + if( const auto* e = m_variants[idx].second.opt_Value() ) + { + return e->val.as_Integer(); + } + + uint32_t val = 0; + for(size_t i = 0; i < idx; i ++) + { + if( const auto* e = m_variants[i].second.opt_Value() ) + { + val = e->val.as_Integer(); + } + val ++; + } + return val; +} namespace { bool matches_genericpath(const ::HIR::GenericParams& params, const ::HIR::GenericPath& left, const ::HIR::GenericPath& right, ::HIR::t_cb_resolve_type ty_res, bool expand_generic); diff --git a/src/hir/hir.hpp b/src/hir/hir.hpp index 2f6b37df..304bdd64 100644 --- a/src/hir/hir.hpp +++ b/src/hir/hir.hpp @@ -178,6 +178,7 @@ struct TraitMarkings TraitObject, // (Trait) } dst_type; unsigned int unsized_field = ~0u; + unsigned int unsized_param = ~0u; /// `true` if there is a Copy impl bool is_copy = false; @@ -219,6 +220,11 @@ public: TraitMarkings m_markings; const Variant* get_variant(const ::std::string& ) const; + + /// Returns true if this enum is a C-like enum (has values only) + bool is_value() const; + /// Returns the value for the given variant + uint32_t get_value(size_t variant) const; }; class Struct { diff --git a/src/hir/serialise.cpp b/src/hir/serialise.cpp index 81319c2e..77e17dba 100644 --- a/src/hir/serialise.cpp +++ b/src/hir/serialise.cpp @@ -495,6 +495,11 @@ namespace { m_out.write_count(e.idx); m_out.write_bool(e.new_val); m_out.write_count(e.other); + ), + (ScopeEnd, + m_out.write_tag(4); + serialise_vec(e.vars); + serialise_vec(e.tmps); ) ) } @@ -859,6 +864,7 @@ namespace { m_out.write_tag( static_cast<unsigned int>(m.dst_type) ); m_out.write_count( m.coerce_unsized_index ); m_out.write_count( m.unsized_field ); + m_out.write_count( m.unsized_param ); // TODO: auto_impls } diff --git a/src/hir/type.cpp b/src/hir/type.cpp index dd655ccc..7dd8dc80 100644 --- a/src/hir/type.cpp +++ b/src/hir/type.cpp @@ -606,7 +606,26 @@ bool ::HIR::TypeRef::match_test_generics(const Span& sp, const ::HIR::TypeRef& x return Compare::Unequal; } TU_MATCH(::HIR::TypeRef::Data, (v.m_data, x.m_data), (te, xe), - (Infer, throw "";), + (Infer, + // Both sides are infer + switch(te.ty_class) + { + case ::HIR::InferClass::None: + case ::HIR::InferClass::Diverge: + return Compare::Fuzzy; + default: + switch(xe.ty_class) + { + case ::HIR::InferClass::None: + case ::HIR::InferClass::Diverge: + return Compare::Fuzzy; + default: + if( te.ty_class != xe.ty_class ) + return Compare::Unequal; + return Compare::Fuzzy; + } + } + ), (Generic, throw "";), (Primitive, return (te == xe ? Compare::Equal : Compare::Unequal); |