diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-01-16 17:25:12 +0000 |
---|---|---|
committer | Philip Herron <herron.philip@googlemail.com> | 2021-01-17 14:20:45 +0000 |
commit | b06df5d4a95ec728ade9230bec945d5d3661f87d (patch) | |
tree | 51a94e9f8118c84893b10ed61d46fd7fd9f30323 /gcc/rust/backend/rust-compile-expr.h | |
parent | e4a2a52b35e99a40f8bd3992a6b53650908fd188 (diff) | |
download | gcc-b06df5d4a95ec728ade9230bec945d5d3661f87d.zip gcc-b06df5d4a95ec728ade9230bec945d5d3661f87d.tar.gz gcc-b06df5d4a95ec728ade9230bec945d5d3661f87d.tar.bz2 |
This adds supports for tuples
More testing is required but this adds tuples apart from TupleStructs
which are parsed as CallExpr. This will be the primitives required to
finish that work.
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.h')
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.h | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h index d38ef04..0d3d9e8 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -46,7 +46,29 @@ public: return; } - gcc_unreachable (); + TyTy::TyBase *tyty = nullptr; + if (!ctx->get_tyctx ()->lookup_type (expr.get_mappings ().get_hirid (), + &tyty)) + { + rust_fatal_error (expr.get_locus (), + "did not resolve type for this TupleExpr"); + return; + } + + Btype *tuple_type = TyTyResolveCompile::compile (ctx, tyty); + rust_assert (tuple_type != nullptr); + + // this assumes all fields are in order from type resolution + std::vector<Bexpression *> vals; + for (auto &elem : expr.get_tuple_elems ()) + { + auto e = CompileExpr::Compile (elem.get (), ctx); + vals.push_back (e); + } + + translated + = ctx->get_backend ()->constructor_expression (tuple_type, vals, + expr.get_locus ()); } void visit (HIR::ReturnExpr &expr) |