@@ -57,7 +57,8 @@ type glue_fns = rec(ValueRef activate_glue,
57
57
vec[ ValueRef ] upcall_glues ,
58
58
ValueRef no_op_type_glue ,
59
59
ValueRef memcpy_glue ,
60
- ValueRef bzero_glue ) ;
60
+ ValueRef bzero_glue ,
61
+ ValueRef vec_grow_glue ) ;
61
62
62
63
type tag_info = rec (
63
64
type_handle th,
@@ -809,7 +810,7 @@ fn trans_upcall(@block_ctxt cx, str name, vec[ValueRef] args) -> result {
809
810
}
810
811
811
812
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 ) ,
813
814
C_int ( 0 ) ) ) ;
814
815
}
815
816
@@ -1065,7 +1066,7 @@ fn trans_malloc_inner(@block_ctxt cx, TypeRef llptr_ty) -> result {
1065
1066
auto tydesc = C_int ( 0 ) ;
1066
1067
auto sz = llsize_of ( llbody_ty) ;
1067
1068
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) ;
1069
1070
ret sub;
1070
1071
}
1071
1072
@@ -1181,10 +1182,10 @@ fn get_tydesc(&@block_ctxt cx, @ty.t t) -> result {
1181
1182
sz. val,
1182
1183
align. val,
1183
1184
C_int ( ( 1 u + n_params) as int) ,
1184
- bcx . build . PtrToInt ( tydescs , T_int ( ) ) ) ) ;
1185
+ vp2i ( bcx , tydescs ) ) ) ;
1185
1186
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) ) ) ) ;
1188
1189
}
1189
1190
1190
1191
// Otherwise, generate a tydesc if necessary, and return it.
@@ -1829,9 +1830,9 @@ fn call_tydesc_glue_full(@block_ctxt cx, ValueRef v,
1829
1830
// glue-pointer-constants in the tydesc records: They are tydesc-relative
1830
1831
// displacements. This is purely for compatibility with rustboot and
1831
1832
// 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) ) ;
1835
1836
1836
1837
cx. build. FastCall ( llfn, vec( C_null ( T_ptr ( T_nil ( ) ) ) ,
1837
1838
cx. fcx. lltaskptr,
@@ -2221,11 +2222,30 @@ fn trans_integral_compare(@block_ctxt cx, ast.binop op, @ty.t intype,
2221
2222
ret cx. build. ICmp ( cmp, lhs, rhs) ;
2222
2223
}
2223
2224
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
+
2224
2239
fn trans_eager_binop( @block_ctxt cx, ast. binop op, @ty. t intype,
2225
2240
ValueRef lhs, ValueRef rhs) -> result {
2226
2241
2227
2242
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
+ }
2229
2249
case ( ast. sub) { ret res( cx, cx. build. Sub ( lhs, rhs) ) ; }
2230
2250
2231
2251
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,
3539
3559
bcx = sub. bcx;
3540
3560
3541
3561
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) ;
3543
3563
find_scope_cx( bcx) . cleanups += clean( bind drop_ty( _, vec_val, t) ) ;
3544
3564
3545
3565
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 {
3782
3802
auto e_ty = ty. expr_ty( e) ;
3783
3803
alt ( e_ty. struct ) {
3784
3804
case ( ty. ty_str) {
3785
- auto v = sub. bcx. build . PtrToInt ( sub. val, T_int ( ) ) ;
3805
+ auto v = vp2i ( sub. bcx, sub. val) ;
3786
3806
ret trans_upcall( sub. bcx,
3787
3807
"upcall_log_str",
3788
3808
vec( v) ) ;
@@ -4907,6 +4927,16 @@ fn trans_constants(@crate_ctxt cx, @ast.crate crate) {
4907
4927
fold. fold_crate [ @crate_ctxt] ( cx, fld, crate ) ;
4908
4928
}
4909
4929
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
+
4910
4940
fn p2i ( ValueRef v) -> ValueRef {
4911
4941
ret llvm. LLVMConstPtrToInt ( v, T_int ( ) ) ;
4912
4942
}
@@ -5172,6 +5202,80 @@ fn make_bzero_glue(ModuleRef llmod) -> ValueRef {
5172
5202
ret fun;
5173
5203
}
5174
5204
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, 0 u) ;
5239
+ let ValueRef llvec_tydesc = llvm. LLVMGetParam ( llfn, 1 u) ;
5240
+ let ValueRef llelt_tydesc = llvm. LLVMGetParam ( llfn, 2 u) ;
5241
+ let ValueRef llvec_ptr = llvm. LLVMGetParam ( llfn, 3 u) ;
5242
+ let ValueRef llnbytes = llvm. LLVMGetParam ( llfn, 4 u) ;
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
+
5175
5279
fn make_glues ( ModuleRef llmod, type_names tn) -> @glue_fns {
5176
5280
ret @rec( activate_glue = decl_glue ( llmod, tn, abi. activate_glue_name ( ) ) ,
5177
5281
yield_glue = decl_glue ( llmod, tn, abi. yield_glue_name ( ) ) ,
@@ -5197,7 +5301,8 @@ fn make_glues(ModuleRef llmod, type_names tn) -> @glue_fns {
5197
5301
abi. n_upcall_glues as uint ) ,
5198
5302
no_op_type_glue = make_no_op_type_glue ( llmod, tn) ,
5199
5303
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) ) ;
5201
5306
}
5202
5307
5203
5308
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,
5256
5361
5257
5362
trans_mod ( cx, crate . node . module ) ;
5258
5363
trans_exit_task_glue ( cx) ;
5364
+ trans_vec_grow_glue ( cx) ;
5259
5365
create_crate_constant ( cx) ;
5260
5366
if ( !shared) {
5261
5367
trans_main_fn ( cx, cx. crate_ptr ) ;
0 commit comments