From cffdb66aa42b6c5a1d30a1b4364d65f409976202 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Wed, 24 Nov 2010 18:10:52 -0800 Subject: [PATCH] Translate tuple-expressions. --- src/comp/middle/trans.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 6f0e6a63242..c49ddb1b531 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -1141,6 +1141,24 @@ impure fn trans_call(@block_ctxt cx, &ast.expr f, args_res._0.build.FastCall(f_res._0.val, llargs)); } +impure fn trans_tup(@block_ctxt cx, vec[tup(bool, @ast.expr)] args, + &ast.ann ann) -> result { + auto ty = node_type(cx.fcx.ccx, ann); + auto tup_val = cx.build.Alloca(ty); + let int i = 0; + auto r = res(cx, C_nil()); + for (tup(bool, @ast.expr) arg in args) { + auto t = typeck.expr_ty(arg._1); + auto src_res = trans_expr(r.bcx, *arg._1); + auto dst_elt = r.bcx.build.GEP(tup_val, vec(C_int(0), C_int(i))); + // FIXME: calculate copy init-ness in typestate. + r = copy_ty(src_res.bcx, true, dst_elt, src_res.val, t); + i += 1; + } + ret res(r.bcx, tup_val); +} + + impure fn trans_expr(@block_ctxt cx, &ast.expr e) -> result { alt (e.node) { case (ast.expr_lit(?lit, _)) { @@ -1192,6 +1210,7 @@ impure fn trans_expr(@block_ctxt cx, &ast.expr e) -> result { check (lhs_res._1); auto rhs_res = trans_expr(lhs_res._0.bcx, *src); auto t = node_ann_type(cx.fcx.ccx, ann); + // FIXME: calculate copy init-ness in typestate. ret copy_ty(rhs_res.bcx, true, lhs_res._0.val, rhs_res.val, t); } @@ -1202,6 +1221,10 @@ impure fn trans_expr(@block_ctxt cx, &ast.expr e) -> result { case (ast.expr_cast(?e, _, ?ann)) { ret trans_cast(cx, *e, ann); } + + case (ast.expr_tup(?args, ?ann)) { + ret trans_tup(cx, args, ann); + } } cx.fcx.ccx.sess.unimpl("expr variant in trans_expr"); fail;