Skip to content

Commit fa4a082

Browse files
committed
---
yaml --- r: 1508 b: refs/heads/master c: 652cb48 h: refs/heads/master v: v3
1 parent c2cabea commit fa4a082

File tree

4 files changed

+74
-27
lines changed

4 files changed

+74
-27
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: 629eba1d066ba4295baf4bfed41cae240c527af5
2+
refs/heads/master: 652cb484758a72811e16a574805ce60827daa153

trunk/src/comp/back/abi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ 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";
74+
fn vec_append_glue_name() -> str {
75+
ret "rust_vec_append_glue";
7676
}
7777

7878
fn upcall_glue_name(int n) -> str {

trunk/src/comp/middle/trans.rs

Lines changed: 62 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type glue_fns = rec(ValueRef activate_glue,
5858
ValueRef no_op_type_glue,
5959
ValueRef memcpy_glue,
6060
ValueRef bzero_glue,
61-
ValueRef vec_grow_glue);
61+
ValueRef vec_append_glue);
6262

6363
type tag_info = rec(type_handle th);
6464

@@ -2296,17 +2296,39 @@ fn trans_integral_compare(@block_ctxt cx, ast.binop op, @ty.t intype,
22962296
ret cx.build.ICmp(cmp, lhs, rhs);
22972297
}
22982298

2299-
fn trans_sequence_append(@block_ctxt cx, @ty.t t,
2300-
ValueRef lhs, ValueRef rhs) -> result {
2301-
cx.fcx.ccx.sess.unimpl("sequence append");
2302-
fail;
2299+
fn trans_vec_append(@block_ctxt cx, @ty.t t,
2300+
ValueRef lhs, ValueRef rhs) -> result {
2301+
2302+
auto elt_ty = ty.sequence_element_type(t);
2303+
2304+
auto skip_null = C_bool(false);
2305+
alt (t.struct) {
2306+
case (ty.ty_str) { skip_null = C_bool(true); }
2307+
case (_) { }
2308+
}
2309+
2310+
auto bcx = cx;
2311+
2312+
auto llvec_tydesc = get_tydesc(bcx, t);
2313+
bcx = llvec_tydesc.bcx;
2314+
2315+
auto llelt_tydesc = get_tydesc(bcx, elt_ty);
2316+
bcx = llelt_tydesc.bcx;
2317+
2318+
ret res(cx, cx.build.FastCall(cx.fcx.ccx.glues.memcpy_glue,
2319+
vec(cx.fcx.lltaskptr,
2320+
llvec_tydesc.val,
2321+
llelt_tydesc.val,
2322+
lhs,
2323+
load_scalar_or_boxed(cx, rhs, t),
2324+
skip_null)));
23032325
}
23042326

2305-
fn trans_sequence_add(@block_ctxt cx, @ty.t t,
2306-
ValueRef lhs, ValueRef rhs) -> result {
2327+
fn trans_vec_add(@block_ctxt cx, @ty.t t,
2328+
ValueRef lhs, ValueRef rhs) -> result {
23072329
auto r = alloc_ty(cx, t);
23082330
r = copy_ty(r.bcx, INIT, r.val, lhs, t);
2309-
ret trans_sequence_append(r.bcx, t, lhs, rhs);
2331+
ret trans_vec_append(r.bcx, t, lhs, rhs);
23102332
}
23112333

23122334

@@ -2316,7 +2338,7 @@ fn trans_eager_binop(@block_ctxt cx, ast.binop op, @ty.t intype,
23162338
alt (op) {
23172339
case (ast.add) {
23182340
if (ty.type_is_sequence(intype)) {
2319-
ret trans_sequence_add(cx, intype, lhs, rhs);
2341+
ret trans_vec_add(cx, intype, lhs, rhs);
23202342
}
23212343
ret res(cx, cx.build.Add(lhs, rhs));
23222344
}
@@ -5296,9 +5318,9 @@ fn make_bzero_glue(ModuleRef llmod) -> ValueRef {
52965318
ret fun;
52975319
}
52985320

5299-
fn make_vec_grow_glue(ModuleRef llmod, type_names tn) -> ValueRef {
5321+
fn make_vec_append_glue(ModuleRef llmod, type_names tn) -> ValueRef {
53005322
/*
5301-
* Args to vec_grow_glue:
5323+
* Args to vec_append_glue:
53025324
*
53035325
* 0. (Implicit) task ptr
53045326
*
@@ -5309,31 +5331,35 @@ fn make_vec_grow_glue(ModuleRef llmod, type_names tn) -> ValueRef {
53095331
* elements can be copied to a newly alloc'ed vec if one must be
53105332
* created.
53115333
*
5312-
* 3. Alias to vec that needs to grow (i.e. ptr to ptr to rust_vec).
5334+
* 3. Dst vec alias (i.e. ptr to ptr to rust_vec, we will mutate it).
5335+
*
5336+
* 4. Src vec (i.e. ptr to rust_vec).
53135337
*
5314-
* 4. Number of bytes of growth requested
5338+
* 5. Flag indicating whether to skip trailing null on dst.
53155339
*
53165340
*/
53175341

53185342
auto ty = T_fn(vec(T_taskptr(tn),
53195343
T_ptr(T_tydesc(tn)),
53205344
T_ptr(T_tydesc(tn)),
53215345
T_ptr(T_ptr(T_vec(T_int()))), // a lie.
5322-
T_int()), T_void());
5346+
T_ptr(T_vec(T_int())), // a lie.
5347+
T_bool()), T_void());
53235348

5324-
auto llfn = decl_fastcall_fn(llmod, abi.vec_grow_glue_name(), ty);
5349+
auto llfn = decl_fastcall_fn(llmod, abi.vec_append_glue_name(), ty);
53255350
ret llfn;
53265351
}
53275352

5328-
fn trans_vec_grow_glue(@crate_ctxt cx) {
5353+
fn trans_vec_append_glue(@crate_ctxt cx) {
53295354

5330-
auto llfn = cx.glues.vec_grow_glue;
5355+
auto llfn = cx.glues.vec_append_glue;
53315356

53325357
let ValueRef lltaskptr = llvm.LLVMGetParam(llfn, 0u);
53335358
let ValueRef llvec_tydesc = llvm.LLVMGetParam(llfn, 1u);
53345359
let ValueRef llelt_tydesc = llvm.LLVMGetParam(llfn, 2u);
5335-
let ValueRef llvec_ptr = llvm.LLVMGetParam(llfn, 3u);
5336-
let ValueRef llnbytes = llvm.LLVMGetParam(llfn, 4u);
5360+
let ValueRef lldst_vec_ptr = llvm.LLVMGetParam(llfn, 3u);
5361+
let ValueRef llsrc_vec = llvm.LLVMGetParam(llfn, 4u);
5362+
let ValueRef llskipnull = llvm.LLVMGetParam(llfn, 5u);
53375363

53385364
auto fcx = @rec(llfn=llfn,
53395365
lltaskptr=lltaskptr,
@@ -5349,12 +5375,23 @@ fn trans_vec_grow_glue(@crate_ctxt cx) {
53495375

53505376
auto bcx = new_top_block_ctxt(fcx);
53515377

5352-
auto llneed_copy_ptr = bcx.build.Alloca(T_int());
5378+
// First the dst vec needs to grow to accommodate the src vec.
5379+
// To do this we have to figure out how many bytes to add.
5380+
auto n_bytes =
5381+
bcx.build.Load(bcx.build.GEP(llsrc_vec,
5382+
vec(C_int(0),
5383+
C_int(abi.vec_elt_fill))));
53535384

5385+
n_bytes = bcx.build.Select(llskipnull,
5386+
bcx.build.Sub(n_bytes, C_int(1)),
5387+
n_bytes);
5388+
5389+
5390+
auto llneed_copy_ptr = bcx.build.Alloca(T_int());
53545391
auto llnew_vec_res =
53555392
trans_upcall(bcx, "upcall_vec_grow",
5356-
vec(vp2i(bcx, bcx.build.Load(llvec_ptr)),
5357-
llnbytes,
5393+
vec(vp2i(bcx, bcx.build.Load(lldst_vec_ptr)),
5394+
n_bytes,
53585395
vp2i(bcx, llneed_copy_ptr),
53595396
vp2i(bcx, llvec_tydesc)));
53605397

@@ -5364,6 +5401,7 @@ fn trans_vec_grow_glue(@crate_ctxt cx) {
53645401
T_ptr(T_vec(T_int())) // a lie.
53655402
);
53665403

5404+
53675405
// FIXME: complete this.
53685406

53695407
bcx.build.RetVoid();
@@ -5396,7 +5434,7 @@ fn make_glues(ModuleRef llmod, type_names tn) -> @glue_fns {
53965434
no_op_type_glue = make_no_op_type_glue(llmod, tn),
53975435
memcpy_glue = make_memcpy_glue(llmod),
53985436
bzero_glue = make_bzero_glue(llmod),
5399-
vec_grow_glue = make_vec_grow_glue(llmod, tn));
5437+
vec_append_glue = make_vec_append_glue(llmod, tn));
54005438
}
54015439

54025440
fn trans_crate(session.session sess, @ast.crate crate, str output,
@@ -5456,7 +5494,7 @@ fn trans_crate(session.session sess, @ast.crate crate, str output,
54565494

54575495
trans_mod(cx, crate.node.module);
54585496
trans_exit_task_glue(cx);
5459-
trans_vec_grow_glue(cx);
5497+
trans_vec_append_glue(cx);
54605498
create_crate_constant(cx);
54615499
if (!shared) {
54625500
trans_main_fn(cx, cx.crate_ptr);

trunk/src/comp/middle/ty.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,15 @@ fn type_is_sequence(@t ty) -> bool {
417417
fail;
418418
}
419419

420+
fn sequence_element_type(@t ty) -> @t {
421+
alt (ty.struct) {
422+
case (ty_str) { ret plain_ty(ty_machine(common.ty_u8)); }
423+
case (ty_vec(?e)) { ret e; }
424+
}
425+
fail;
426+
}
427+
428+
420429
fn type_is_tup_like(@t ty) -> bool {
421430
alt (ty.struct) {
422431
case (ty_box(_)) { ret true; }

0 commit comments

Comments
 (0)