Skip to content

Commit dd8c6fc

Browse files
committed
---
yaml --- r: 1493 b: refs/heads/master c: dddeba1 h: refs/heads/master i: 1491: b471059 v: v3
1 parent ca5be83 commit dd8c6fc

File tree

4 files changed

+134
-14
lines changed

4 files changed

+134
-14
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 5ebb91f24d84391f6c821c54fb8c497964eac6c3
2+
refs/heads/master: dddeba19d33a1aa2e7681ae84424dbe4d7b510b7

trunk/src/comp/back/abi.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ fn bzero_glue_name() -> str {
7171
ret "rust_bzero_glue";
7272
}
7373

74+
fn vec_grow_glue_name() -> str {
75+
ret "rust_vec_grow_glue";
76+
}
77+
7478
fn upcall_glue_name(int n) -> str {
7579
ret "rust_upcall_" + util.common.istr(n);
7680
}

trunk/src/comp/middle/trans.rs

Lines changed: 119 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ type glue_fns = rec(ValueRef activate_glue,
5757
vec[ValueRef] upcall_glues,
5858
ValueRef no_op_type_glue,
5959
ValueRef memcpy_glue,
60-
ValueRef bzero_glue);
60+
ValueRef bzero_glue,
61+
ValueRef vec_grow_glue);
6162

6263
type tag_info = rec(
6364
type_handle th,
@@ -809,7 +810,7 @@ fn trans_upcall(@block_ctxt cx, str name, vec[ValueRef] args) -> result {
809810
}
810811

811812
fn trans_non_gc_free(@block_ctxt cx, ValueRef v) -> result {
812-
ret trans_upcall(cx, "upcall_free", vec(cx.build.PtrToInt(v, T_int()),
813+
ret trans_upcall(cx, "upcall_free", vec(vp2i(cx, v),
813814
C_int(0)));
814815
}
815816

@@ -1065,7 +1066,7 @@ fn trans_malloc_inner(@block_ctxt cx, TypeRef llptr_ty) -> result {
10651066
auto tydesc = C_int(0);
10661067
auto sz = llsize_of(llbody_ty);
10671068
auto sub = trans_upcall(cx, "upcall_malloc", vec(sz, tydesc));
1068-
sub.val = sub.bcx.build.IntToPtr(sub.val, llptr_ty);
1069+
sub.val = vi2p(sub.bcx, sub.val, llptr_ty);
10691070
ret sub;
10701071
}
10711072

@@ -1181,10 +1182,10 @@ fn get_tydesc(&@block_ctxt cx, @ty.t t) -> result {
11811182
sz.val,
11821183
align.val,
11831184
C_int((1u + n_params) as int),
1184-
bcx.build.PtrToInt(tydescs, T_int())));
1185+
vp2i(bcx, tydescs)));
11851186

1186-
ret res(v.bcx, v.bcx.build.IntToPtr(v.val,
1187-
T_ptr(T_tydesc(cx.fcx.ccx.tn))));
1187+
ret res(v.bcx, vi2p(v.bcx, v.val,
1188+
T_ptr(T_tydesc(cx.fcx.ccx.tn))));
11881189
}
11891190

11901191
// Otherwise, generate a tydesc if necessary, and return it.
@@ -1829,9 +1830,9 @@ fn call_tydesc_glue_full(@block_ctxt cx, ValueRef v,
18291830
// glue-pointer-constants in the tydesc records: They are tydesc-relative
18301831
// displacements. This is purely for compatibility with rustboot and
18311832
// should go when it is discarded.
1832-
llfn = cx.build.IntToPtr(cx.build.Add(cx.build.PtrToInt(llfn, T_int()),
1833-
cx.build.PtrToInt(tydesc, T_int())),
1834-
val_ty(llfn));
1833+
llfn = vi2p(cx, cx.build.Add(vp2i(cx, llfn),
1834+
vp2i(cx, tydesc)),
1835+
val_ty(llfn));
18351836

18361837
cx.build.FastCall(llfn, vec(C_null(T_ptr(T_nil())),
18371838
cx.fcx.lltaskptr,
@@ -2221,11 +2222,30 @@ fn trans_integral_compare(@block_ctxt cx, ast.binop op, @ty.t intype,
22212222
ret cx.build.ICmp(cmp, lhs, rhs);
22222223
}
22232224

2225+
fn trans_sequence_append(@block_ctxt cx, @ty.t t,
2226+
ValueRef lhs, ValueRef rhs) -> result {
2227+
cx.fcx.ccx.sess.unimpl("sequence append");
2228+
fail;
2229+
}
2230+
2231+
fn trans_sequence_add(@block_ctxt cx, @ty.t t,
2232+
ValueRef lhs, ValueRef rhs) -> result {
2233+
auto r = alloc_ty(cx, t);
2234+
r = copy_ty(r.bcx, INIT, r.val, lhs, t);
2235+
ret trans_sequence_append(r.bcx, t, lhs, rhs);
2236+
}
2237+
2238+
22242239
fn trans_eager_binop(@block_ctxt cx, ast.binop op, @ty.t intype,
22252240
ValueRef lhs, ValueRef rhs) -> result {
22262241

22272242
alt (op) {
2228-
case (ast.add) { ret res(cx, cx.build.Add(lhs, rhs)); }
2243+
case (ast.add) {
2244+
if (ty.type_is_sequence(intype)) {
2245+
ret trans_sequence_add(cx, intype, lhs, rhs);
2246+
}
2247+
ret res(cx, cx.build.Add(lhs, rhs));
2248+
}
22292249
case (ast.sub) { ret res(cx, cx.build.Sub(lhs, rhs)); }
22302250

22312251
case (ast.mul) { ret res(cx, cx.build.Mul(lhs, rhs)); }
@@ -3539,7 +3559,7 @@ fn trans_vec(@block_ctxt cx, vec[@ast.expr] args,
35393559
bcx = sub.bcx;
35403560

35413561
auto llty = type_of(bcx.fcx.ccx, t);
3542-
auto vec_val = bcx.build.IntToPtr(sub.val, llty);
3562+
auto vec_val = vi2p(bcx, sub.val, llty);
35433563
find_scope_cx(bcx).cleanups += clean(bind drop_ty(_, vec_val, t));
35443564

35453565
auto body = bcx.build.GEP(vec_val, vec(C_int(0),
@@ -3782,7 +3802,7 @@ fn trans_log(@block_ctxt cx, @ast.expr e) -> result {
37823802
auto e_ty = ty.expr_ty(e);
37833803
alt (e_ty.struct) {
37843804
case (ty.ty_str) {
3785-
auto v = sub.bcx.build.PtrToInt(sub.val, T_int());
3805+
auto v = vp2i(sub.bcx, sub.val);
37863806
ret trans_upcall(sub.bcx,
37873807
"upcall_log_str",
37883808
vec(v));
@@ -4907,6 +4927,16 @@ fn trans_constants(@crate_ctxt cx, @ast.crate crate) {
49074927
fold.fold_crate[@crate_ctxt](cx, fld, crate);
49084928
}
49094929

4930+
4931+
fn vp2i(@block_ctxt cx, ValueRef v) -> ValueRef {
4932+
ret cx.build.PtrToInt(v, T_int());
4933+
}
4934+
4935+
4936+
fn vi2p(@block_ctxt cx, ValueRef v, TypeRef t) -> ValueRef {
4937+
ret cx.build.IntToPtr(v, t);
4938+
}
4939+
49104940
fn p2i(ValueRef v) -> ValueRef {
49114941
ret llvm.LLVMConstPtrToInt(v, T_int());
49124942
}
@@ -5172,6 +5202,80 @@ fn make_bzero_glue(ModuleRef llmod) -> ValueRef {
51725202
ret fun;
51735203
}
51745204

5205+
fn make_vec_grow_glue(ModuleRef llmod, type_names tn) -> ValueRef {
5206+
/*
5207+
* Args to vec_grow_glue:
5208+
*
5209+
* 0. (Implicit) task ptr
5210+
*
5211+
* 1. Pointer to the tydesc of the vec, so that we can tell if it's gc
5212+
* mem, and have a tydesc to pass to malloc if we're allocating anew.
5213+
*
5214+
* 2. Pointer to the tydesc of the vec's stored element type, so that
5215+
* elements can be copied to a newly alloc'ed vec if one must be
5216+
* created.
5217+
*
5218+
* 3. Alias to vec that needs to grow (i.e. ptr to ptr to rust_vec).
5219+
*
5220+
* 4. Number of bytes of growth requested
5221+
*
5222+
*/
5223+
5224+
auto ty = T_fn(vec(T_taskptr(tn),
5225+
T_ptr(T_tydesc(tn)),
5226+
T_ptr(T_tydesc(tn)),
5227+
T_ptr(T_ptr(T_vec(T_int()))), // a lie.
5228+
T_int()), T_void());
5229+
5230+
auto llfn = decl_fastcall_fn(llmod, abi.vec_grow_glue_name(), ty);
5231+
ret llfn;
5232+
}
5233+
5234+
fn trans_vec_grow_glue(@crate_ctxt cx) {
5235+
5236+
auto llfn = cx.glues.vec_grow_glue;
5237+
5238+
let ValueRef lltaskptr = llvm.LLVMGetParam(llfn, 0u);
5239+
let ValueRef llvec_tydesc = llvm.LLVMGetParam(llfn, 1u);
5240+
let ValueRef llelt_tydesc = llvm.LLVMGetParam(llfn, 2u);
5241+
let ValueRef llvec_ptr = llvm.LLVMGetParam(llfn, 3u);
5242+
let ValueRef llnbytes = llvm.LLVMGetParam(llfn, 4u);
5243+
5244+
auto fcx = @rec(llfn=llfn,
5245+
lltaskptr=lltaskptr,
5246+
llenv=C_null(T_ptr(T_nil())),
5247+
llretptr=C_null(T_ptr(T_nil())),
5248+
mutable llself=none[ValueRef],
5249+
mutable lliterbody=none[ValueRef],
5250+
llargs=new_def_hash[ValueRef](),
5251+
llobjfields=new_def_hash[ValueRef](),
5252+
lllocals=new_def_hash[ValueRef](),
5253+
lltydescs=new_def_hash[ValueRef](),
5254+
ccx=cx);
5255+
5256+
auto bcx = new_top_block_ctxt(fcx);
5257+
5258+
auto llneed_copy_ptr = bcx.build.Alloca(T_int());
5259+
5260+
auto llnew_vec_res =
5261+
trans_upcall(bcx, "upcall_vec_grow",
5262+
vec(vp2i(bcx, bcx.build.Load(llvec_ptr)),
5263+
llnbytes,
5264+
vp2i(bcx, llneed_copy_ptr),
5265+
vp2i(bcx, llvec_tydesc)));
5266+
5267+
bcx = llnew_vec_res.bcx;
5268+
auto llnew_vec = vi2p(bcx,
5269+
llnew_vec_res.val,
5270+
T_ptr(T_vec(T_int())) // a lie.
5271+
);
5272+
5273+
// FIXME: complete this.
5274+
5275+
bcx.build.RetVoid();
5276+
}
5277+
5278+
51755279
fn make_glues(ModuleRef llmod, type_names tn) -> @glue_fns {
51765280
ret @rec(activate_glue = decl_glue(llmod, tn, abi.activate_glue_name()),
51775281
yield_glue = decl_glue(llmod, tn, abi.yield_glue_name()),
@@ -5197,7 +5301,8 @@ fn make_glues(ModuleRef llmod, type_names tn) -> @glue_fns {
51975301
abi.n_upcall_glues as uint),
51985302
no_op_type_glue = make_no_op_type_glue(llmod, tn),
51995303
memcpy_glue = make_memcpy_glue(llmod),
5200-
bzero_glue = make_bzero_glue(llmod));
5304+
bzero_glue = make_bzero_glue(llmod),
5305+
vec_grow_glue = make_vec_grow_glue(llmod, tn));
52015306
}
52025307

52035308
fn trans_crate(session.session sess, @ast.crate crate, str output,
@@ -5256,6 +5361,7 @@ fn trans_crate(session.session sess, @ast.crate crate, str output,
52565361

52575362
trans_mod(cx, crate.node.module);
52585363
trans_exit_task_glue(cx);
5364+
trans_vec_grow_glue(cx);
52595365
create_crate_constant(cx);
52605366
if (!shared) {
52615367
trans_main_fn(cx, cx.crate_ptr);

trunk/src/comp/middle/ty.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ fn type_is_nil(@t ty) -> bool {
395395
fail;
396396
}
397397

398+
398399
fn type_is_structural(@t ty) -> bool {
399400
alt (ty.struct) {
400401
case (ty_tup(_)) { ret true; }
@@ -407,6 +408,15 @@ fn type_is_structural(@t ty) -> bool {
407408
fail;
408409
}
409410

411+
fn type_is_sequence(@t ty) -> bool {
412+
alt (ty.struct) {
413+
case (ty_str) { ret true; }
414+
case (ty_vec(_)) { ret true; }
415+
case (_) { ret false; }
416+
}
417+
fail;
418+
}
419+
410420
fn type_is_tup_like(@t ty) -> bool {
411421
alt (ty.struct) {
412422
case (ty_box(_)) { ret true; }

0 commit comments

Comments
 (0)