@@ -77,6 +77,7 @@ state type fn_ctxt = rec(ValueRef llfn,
77
77
ValueRef lltaskptr ,
78
78
hashmap[ ast. def_id, ValueRef ] llargs ,
79
79
hashmap[ ast. def_id, ValueRef ] lllocals ,
80
+ hashmap[ ast. def_id, ValueRef ] lltydescs ,
80
81
@crate_ctxt ccx ) ;
81
82
82
83
tag cleanup {
@@ -2261,17 +2262,27 @@ fn new_fn_ctxt(@crate_ctxt cx,
2261
2262
2262
2263
let hashmap[ ast. def_id , ValueRef ] lllocals = new_def_hash[ ValueRef ] ( ) ;
2263
2264
let hashmap[ ast. def_id , ValueRef ] llargs = new_def_hash[ ValueRef ] ( ) ;
2265
+ let hashmap[ ast. def_id , ValueRef ] lltydescs = new_def_hash[ ValueRef ] ( ) ;
2264
2266
2265
2267
ret @rec( llfn=llfndecl,
2266
2268
lltaskptr=lltaskptr,
2267
2269
llargs=llargs,
2268
2270
lllocals=lllocals,
2271
+ lltydescs=lltydescs,
2269
2272
ccx=cx) ;
2270
2273
}
2271
2274
2272
2275
2273
- fn create_llargs_for_fn_args ( @fn_ctxt cx , vec[ ast. arg] args ) {
2276
+ fn create_llargs_for_fn_args ( & @fn_ctxt cx , & vec[ ast. arg] args ,
2277
+ & vec[ ast. ty_param] ty_params ) {
2274
2278
let uint arg_n = 1 u;
2279
+ for ( ast. ty_param tp in ty_params) {
2280
+ auto llarg = llvm. LLVMGetParam ( cx. llfn, arg_n) ;
2281
+ check ( llarg as int != 0 ) ;
2282
+ cx. lltydescs. insert( tp. id, llarg) ;
2283
+ arg_n += 1 u;
2284
+ }
2285
+
2275
2286
for ( ast. arg arg in args) {
2276
2287
auto llarg = llvm. LLVMGetParam ( cx. llfn, arg_n) ;
2277
2288
check ( llarg as int != 0 ) ;
@@ -2328,13 +2339,13 @@ fn ret_ty_of_fn(ast.ann ann) -> @typeck.ty {
2328
2339
}
2329
2340
2330
2341
impure fn trans_fn ( @crate_ctxt cx , & ast . _fn f, ast. def_id fid ,
2331
- & ast. ann ann ) {
2342
+ & vec [ ast . ty_param ] ty_params , & ast. ann ann ) {
2332
2343
2333
2344
auto llfndecl = cx. item_ids . get ( fid) ;
2334
2345
cx. item_names . insert ( cx. path , llfndecl) ;
2335
2346
2336
2347
auto fcx = new_fn_ctxt ( cx, cx. path , llfndecl) ;
2337
- create_llargs_for_fn_args ( fcx, f. inputs ) ;
2348
+ create_llargs_for_fn_args ( fcx, f. inputs , ty_params ) ;
2338
2349
2339
2350
auto bcx = new_top_block_ctxt ( fcx) ;
2340
2351
@@ -2348,7 +2359,8 @@ impure fn trans_fn(@crate_ctxt cx, &ast._fn f, ast.def_id fid,
2348
2359
}
2349
2360
}
2350
2361
2351
- impure fn trans_vtbl ( @crate_ctxt cx , & ast. _obj ob ) -> ValueRef {
2362
+ impure fn trans_vtbl ( @crate_ctxt cx , & ast. _obj ob ,
2363
+ & vec[ ast. ty_param] ty_params ) -> ValueRef {
2352
2364
let vec[ ValueRef ] methods = vec ( ) ;
2353
2365
for ( @ast. method m in ob. methods) {
2354
2366
@@ -2357,7 +2369,7 @@ impure fn trans_vtbl(@crate_ctxt cx, &ast._obj ob) -> ValueRef {
2357
2369
let ValueRef llfn = decl_fastcall_fn( cx. llmod, s, llfnty) ;
2358
2370
cx. item_ids. insert( m. node. id, llfn) ;
2359
2371
2360
- trans_fn( cx, m. node. meth, m. node. id, m. node. ann) ;
2372
+ trans_fn( cx, m. node. meth, m. node. id, ty_params , m. node. ann) ;
2361
2373
methods += llfn;
2362
2374
}
2363
2375
auto vtbl = C_struct ( methods) ;
@@ -2370,7 +2382,7 @@ impure fn trans_vtbl(@crate_ctxt cx, &ast._obj ob) -> ValueRef {
2370
2382
}
2371
2383
2372
2384
impure fn trans_obj( @crate_ctxt cx, & ast. _obj ob, ast. def_id oid,
2373
- & ast. ann ann) {
2385
+ & vec [ ast . ty_param ] ty_params , & ast. ann ann) {
2374
2386
2375
2387
auto llctor_decl = cx. item_ids. get( oid) ;
2376
2388
cx. item_names. insert( cx. path, llctor_decl) ;
@@ -2385,14 +2397,14 @@ impure fn trans_obj(@crate_ctxt cx, &ast._obj ob, ast.def_id oid,
2385
2397
}
2386
2398
2387
2399
auto fcx = new_fn_ctxt( cx, cx. path, llctor_decl) ;
2388
- create_llargs_for_fn_args( fcx, fn_args) ;
2400
+ create_llargs_for_fn_args( fcx, fn_args, ty_params ) ;
2389
2401
2390
2402
auto bcx = new_top_block_ctxt( fcx) ;
2391
2403
2392
2404
copy_args_to_allocas( bcx, fn_args, arg_tys_of_fn( ann) ) ;
2393
2405
2394
2406
auto pair = bcx. build. Alloca ( type_of( cx, ret_ty_of_fn( ann) ) ) ;
2395
- auto vtbl = trans_vtbl( cx, ob) ;
2407
+ auto vtbl = trans_vtbl( cx, ob, ty_params ) ;
2396
2408
auto pair_vtbl = bcx. build. GEP ( pair,
2397
2409
vec( C_int ( 0 ) ,
2398
2410
C_int ( abi. obj_field_vtbl) ) ) ;
@@ -2401,7 +2413,8 @@ impure fn trans_obj(@crate_ctxt cx, &ast._obj ob, ast.def_id oid,
2401
2413
}
2402
2414
2403
2415
fn trans_tag_variant( @crate_ctxt cx, ast. def_id tag_id,
2404
- & ast. variant variant, int index) {
2416
+ & ast. variant variant, int index,
2417
+ & vec[ ast. ty_param] ty_params) {
2405
2418
if ( _vec. len[ ast. variant_arg] ( variant. args) == 0 u) {
2406
2419
ret; // nullary constructors are just constants
2407
2420
}
@@ -2427,7 +2440,7 @@ fn trans_tag_variant(@crate_ctxt cx, ast.def_id tag_id,
2427
2440
cx. item_names. insert( cx. path, llfndecl) ;
2428
2441
2429
2442
auto fcx = new_fn_ctxt( cx, cx. path, llfndecl) ;
2430
- create_llargs_for_fn_args( fcx, fn_args) ;
2443
+ create_llargs_for_fn_args( fcx, fn_args, ty_params ) ;
2431
2444
2432
2445
auto bcx = new_top_block_ctxt( fcx) ;
2433
2446
@@ -2473,23 +2486,23 @@ fn trans_tag_variant(@crate_ctxt cx, ast.def_id tag_id,
2473
2486
2474
2487
impure fn trans_item( @crate_ctxt cx, & ast. item item) {
2475
2488
alt ( item. node) {
2476
- case ( ast. item_fn( ?name, ?f, _ , ?fid, ?ann) ) {
2489
+ case ( ast. item_fn( ?name, ?f, ?tps , ?fid, ?ann) ) {
2477
2490
auto sub_cx = @rec( path=cx. path + "." + name with * cx) ;
2478
- trans_fn( sub_cx, f, fid, ann) ;
2491
+ trans_fn( sub_cx, f, fid, tps , ann) ;
2479
2492
}
2480
- case ( ast. item_obj( ?name, ?ob, _ , ?oid, ?ann) ) {
2493
+ case ( ast. item_obj( ?name, ?ob, ?tps , ?oid, ?ann) ) {
2481
2494
auto sub_cx = @rec( path=cx. path + "." + name with * cx) ;
2482
- trans_obj( sub_cx, ob, oid, ann) ;
2495
+ trans_obj( sub_cx, ob, oid, tps , ann) ;
2483
2496
}
2484
2497
case ( ast. item_mod( ?name, ?m, _) ) {
2485
2498
auto sub_cx = @rec( path=cx. path + "." + name with * cx) ;
2486
2499
trans_mod( sub_cx, m) ;
2487
2500
}
2488
- case ( ast. item_tag( ?name, ?variants, _ , ?tag_id) ) {
2501
+ case ( ast. item_tag( ?name, ?variants, ?tps , ?tag_id) ) {
2489
2502
auto sub_cx = @rec( path=cx. path + "." + name with * cx) ;
2490
2503
auto i = 0 ;
2491
2504
for ( ast. variant variant in variants) {
2492
- trans_tag_variant( sub_cx, tag_id, variant, i) ;
2505
+ trans_tag_variant( sub_cx, tag_id, variant, i, tps ) ;
2493
2506
i += 1 ;
2494
2507
}
2495
2508
}
@@ -2694,6 +2707,7 @@ fn trans_exit_task_glue(@crate_ctxt cx) {
2694
2707
lltaskptr=lltaskptr,
2695
2708
llargs=new_def_hash[ ValueRef ] ( ) ,
2696
2709
lllocals=new_def_hash[ ValueRef ] ( ) ,
2710
+ lltydescs=new_def_hash[ ValueRef ] ( ) ,
2697
2711
ccx=cx) ;
2698
2712
2699
2713
auto bcx = new_top_block_ctxt ( fcx) ;
0 commit comments