aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2010-12-10 17:25:11 -0800
committerGraydon Hoare <[email protected]>2010-12-10 17:25:22 -0800
commit60affafdcdc5a2f2174502b08f696b1aaf89c33b (patch)
tree72106756c8793b14d6efa172c140fa0b971446ee
parentFix trans_index implementation. (diff)
downloadrust-60affafdcdc5a2f2174502b08f696b1aaf89c33b.tar.xz
rust-60affafdcdc5a2f2174502b08f696b1aaf89c33b.zip
Implement expr_vec.
-rw-r--r--src/comp/middle/trans.rs43
1 files changed, 42 insertions, 1 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 51941242..34325d48 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -1539,13 +1539,50 @@ impure fn trans_tup(@block_ctxt cx, vec[ast.elt] elts,
auto t = typeck.expr_ty(e.expr);
auto src_res = trans_expr(r.bcx, e.expr);
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_vec(@block_ctxt cx, vec[@ast.expr] args,
+ &ast.ann ann) -> result {
+ auto ty = node_ann_type(cx.fcx.ccx, ann);
+ auto unit_ty = ty;
+ alt (ty.struct) {
+ case (typeck.ty_vec(?t)) {
+ unit_ty = t;
+ }
+ case (_) {
+ cx.fcx.ccx.sess.bug("non-vec type in trans_vec");
+ }
+ }
+
+ auto llunit_ty = type_of(cx.fcx.ccx, unit_ty);
+ auto unit_sz = llvm.LLVMConstIntCast(llvm.LLVMSizeOf(llunit_ty),
+ T_int(), False);
+ auto data_sz = llvm.LLVMConstMul(C_int(_vec.len[@ast.expr](args) as int),
+ unit_sz);
+
+ // FIXME: pass tydesc properly.
+ auto sub = trans_upcall(cx, "upcall_new_vec", vec(data_sz, C_int(0)));
+
+ auto llty = type_of(cx.fcx.ccx, ty);
+ auto vec_val = sub.bcx.build.IntToPtr(sub.val, llty);
+ find_scope_cx(cx).cleanups += clean(bind drop_ty(_, vec_val, ty));
+
+ auto body = sub.bcx.build.GEP(vec_val, vec(C_int(0),
+ C_int(abi.vec_elt_data)));
+ let int i = 0;
+ for (@ast.expr e in args) {
+ auto src_res = trans_expr(sub.bcx, e);
+ auto dst_elt = sub.bcx.build.GEP(body, vec(C_int(0), C_int(i)));
+ sub = copy_ty(src_res.bcx, true, dst_elt, src_res.val, unit_ty);
+ i += 1;
+ }
+ ret res(sub.bcx, vec_val);
+}
+
impure fn trans_rec(@block_ctxt cx, vec[ast.field] fields,
&ast.ann ann) -> result {
auto ty = node_ann_type(cx.fcx.ccx, ann);
@@ -1633,6 +1670,10 @@ impure fn trans_expr(@block_ctxt cx, @ast.expr e) -> result {
ret trans_cast(cx, e, ann);
}
+ case (ast.expr_vec(?args, ?ann)) {
+ ret trans_vec(cx, args, ann);
+ }
+
case (ast.expr_tup(?args, ?ann)) {
ret trans_tup(cx, args, ann);
}