mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-13 02:17:41 +00:00
Add load_non_structural and use it.
This commit is contained in:
parent
5347cac92d
commit
aeef8cee29
@ -553,7 +553,9 @@ fn iter_structural_ty(@block_ctxt cx,
|
|||||||
let int i = 0;
|
let int i = 0;
|
||||||
for (@typeck.ty arg in args) {
|
for (@typeck.ty arg in args) {
|
||||||
auto elt = r.bcx.build.GEP(v, vec(C_int(0), C_int(i)));
|
auto elt = r.bcx.build.GEP(v, vec(C_int(0), C_int(i)));
|
||||||
r = f(r.bcx, elt, arg);
|
r = f(r.bcx,
|
||||||
|
load_non_structural(r.bcx, elt, arg),
|
||||||
|
arg);
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -561,7 +563,9 @@ fn iter_structural_ty(@block_ctxt cx,
|
|||||||
let int i = 0;
|
let int i = 0;
|
||||||
for (typeck.field fld in fields) {
|
for (typeck.field fld in fields) {
|
||||||
auto llfld = r.bcx.build.GEP(v, vec(C_int(0), C_int(i)));
|
auto llfld = r.bcx.build.GEP(v, vec(C_int(0), C_int(i)));
|
||||||
r = f(r.bcx, llfld, fld.ty);
|
r = f(r.bcx,
|
||||||
|
load_non_structural(r.bcx, llfld, fld.ty),
|
||||||
|
fld.ty);
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -608,7 +612,7 @@ fn iter_structural_ty(@block_ctxt cx,
|
|||||||
C_int(i as int));
|
C_int(i as int));
|
||||||
auto llvar = variant_cx.build.GEP(v, vals);
|
auto llvar = variant_cx.build.GEP(v, vals);
|
||||||
|
|
||||||
auto fn_ty = typeck.ann_to_type(variants.(i).ann);
|
auto fn_ty = typeck.ann_to_type(variants.(i).ann);
|
||||||
alt (fn_ty.struct) {
|
alt (fn_ty.struct) {
|
||||||
case (typeck.ty_fn(?args, _)) {
|
case (typeck.ty_fn(?args, _)) {
|
||||||
auto j = 0u;
|
auto j = 0u;
|
||||||
@ -616,7 +620,10 @@ fn iter_structural_ty(@block_ctxt cx,
|
|||||||
auto idx = vec(C_int(0), C_int(j as int));
|
auto idx = vec(C_int(0), C_int(j as int));
|
||||||
auto llfp = variant_cx.build.GEP(llvar,
|
auto llfp = variant_cx.build.GEP(llvar,
|
||||||
idx);
|
idx);
|
||||||
auto llfld = variant_cx.build.Load(llfp);
|
auto llfld =
|
||||||
|
load_non_structural(variant_cx,
|
||||||
|
llfp, a.ty);
|
||||||
|
|
||||||
auto res = f(variant_cx, llfld, a.ty);
|
auto res = f(variant_cx, llfld, a.ty);
|
||||||
variant_cx = res.bcx;
|
variant_cx = res.bcx;
|
||||||
j += 1u;
|
j += 1u;
|
||||||
@ -1483,17 +1490,28 @@ impure fn trans_expr(@block_ctxt cx, @ast.expr e) -> result {
|
|||||||
case (_) {
|
case (_) {
|
||||||
auto t = typeck.expr_ty(e);
|
auto t = typeck.expr_ty(e);
|
||||||
auto sub = trans_lval(cx, e);
|
auto sub = trans_lval(cx, e);
|
||||||
if (sub._1 && ! typeck.type_is_structural(t)) {
|
ret res(sub._0.bcx,
|
||||||
ret res(sub._0.bcx, cx.build.Load(sub._0.val));
|
load_non_structural(sub._0.bcx, sub._0.val, t));
|
||||||
} else {
|
|
||||||
ret sub._0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cx.fcx.ccx.sess.unimpl("expr variant in trans_expr");
|
cx.fcx.ccx.sess.unimpl("expr variant in trans_expr");
|
||||||
fail;
|
fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We pass structural values around the compiler "by pointer" and
|
||||||
|
// non-structural values "by value". This function selects whether
|
||||||
|
// to load a pointer or pass it.
|
||||||
|
|
||||||
|
fn load_non_structural(@block_ctxt cx,
|
||||||
|
ValueRef v,
|
||||||
|
@typeck.ty t) -> ValueRef {
|
||||||
|
if (typeck.type_is_structural(t)) {
|
||||||
|
ret v;
|
||||||
|
} else {
|
||||||
|
ret cx.build.Load(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impure fn trans_log(@block_ctxt cx, @ast.expr e) -> result {
|
impure fn trans_log(@block_ctxt cx, @ast.expr e) -> result {
|
||||||
alt (e.node) {
|
alt (e.node) {
|
||||||
case (ast.expr_lit(?lit, _)) {
|
case (ast.expr_lit(?lit, _)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user