@@ -9,6 +9,7 @@ import std.option.none;
9
9
10
10
import front. ast ;
11
11
import driver. session ;
12
+ import middle. typeck ;
12
13
import back. x86 ;
13
14
import back. abi ;
14
15
@@ -237,13 +238,13 @@ fn T_taskptr() -> TypeRef {
237
238
ret T_ptr ( T_task ( ) ) ;
238
239
}
239
240
240
- fn type_of ( @trans_ctxt cx , @ast . ty t ) -> TypeRef {
241
- alt ( t. node ) {
242
- case ( ast . ty_nil ) { ret T_nil ( ) ; }
243
- case ( ast . ty_bool ) { ret T_bool ( ) ; }
244
- case ( ast . ty_int ) { ret T_int ( ) ; }
245
- case ( ast . ty_uint ) { ret T_int ( ) ; }
246
- case ( ast . ty_machine ( ?tm) ) {
241
+ fn type_of ( @trans_ctxt cx , @typeck . ty t ) -> TypeRef {
242
+ alt ( t. struct ) {
243
+ case ( typeck . ty_nil ) { ret T_nil ( ) ; }
244
+ case ( typeck . ty_bool ) { ret T_bool ( ) ; }
245
+ case ( typeck . ty_int ) { ret T_int ( ) ; }
246
+ case ( typeck . ty_uint ) { ret T_int ( ) ; }
247
+ case ( typeck . ty_machine ( ?tm) ) {
247
248
alt ( tm) {
248
249
case ( common. ty_i8 ) { ret T_i8 ( ) ; }
249
250
case ( common. ty_u8 ) { ret T_i8 ( ) ; }
@@ -257,24 +258,25 @@ fn type_of(@trans_ctxt cx, @ast.ty t) -> TypeRef {
257
258
case ( common. ty_f64 ) { ret T_f64 ( ) ; }
258
259
}
259
260
}
260
- case ( ast . ty_char ) { ret T_char ( ) ; }
261
- case ( ast . ty_str ) { ret T_str ( 0 u) ; }
262
- case ( ast . ty_box ( ?t) ) {
261
+ case ( typeck . ty_char ) { ret T_char ( ) ; }
262
+ case ( typeck . ty_str ) { ret T_str ( 0 u) ; }
263
+ case ( typeck . ty_box ( ?t) ) {
263
264
ret T_ptr ( T_box ( type_of ( cx, t) ) ) ;
264
265
}
265
- case ( ast . ty_vec ( ?t) ) {
266
+ case ( typeck . ty_vec ( ?t) ) {
266
267
ret T_ptr ( T_vec ( type_of ( cx, t) , 0 u) ) ;
267
268
}
268
- case ( ast . ty_tup ( ?elts) ) {
269
+ case ( typeck . ty_tup ( ?elts) ) {
269
270
let vec[ TypeRef ] tys = vec ( ) ;
270
- for ( tup( bool, @ast . ty) elt in elts) {
271
+ for ( tup( bool, @typeck . ty) elt in elts) {
271
272
tys += type_of ( cx, elt. _1 ) ;
272
273
}
273
274
ret T_struct ( tys) ;
274
275
}
275
- case ( ast . ty_path ( ?pth , ?def ) ) {
276
+ case ( typeck . ty_var ( _ ) ) {
276
277
// FIXME: implement.
277
- cx. sess . unimpl ( "ty_path in trans.type_of" ) ;
278
+ log "ty_var in trans.type_of" ;
279
+ ret T_i8 ( ) ;
278
280
}
279
281
}
280
282
fail;
@@ -340,27 +342,23 @@ fn C_tydesc(TypeRef t) -> ValueRef {
340
342
C_null ( T_opaque ( ) ) ) ) ; // is_stateful
341
343
}
342
344
343
- fn decl_fn ( ModuleRef llmod, str name ,
344
- uint cc, vec[ TypeRef ] inputs , TypeRef output) -> ValueRef {
345
- let TypeRef llty = T_fn ( inputs, output) ;
345
+ fn decl_fn ( ModuleRef llmod, str name , uint cc, TypeRef llty) -> ValueRef {
346
346
let ValueRef llfn =
347
347
llvm. LLVMAddFunction ( llmod, _str. buf ( name) , llty) ;
348
348
llvm. LLVMSetFunctionCallConv ( llfn, cc) ;
349
349
ret llfn;
350
350
}
351
351
352
- fn decl_cdecl_fn ( ModuleRef llmod, str name ,
353
- vec[ TypeRef ] inputs , TypeRef output) -> ValueRef {
354
- ret decl_fn ( llmod, name, lib. llvm . LLVMCCallConv , inputs, output) ;
352
+ fn decl_cdecl_fn ( ModuleRef llmod, str name , TypeRef llty) -> ValueRef {
353
+ ret decl_fn ( llmod, name, lib. llvm . LLVMCCallConv , llty) ;
355
354
}
356
355
357
- fn decl_fastcall_fn ( ModuleRef llmod, str name ,
358
- vec[ TypeRef ] inputs , TypeRef output) -> ValueRef {
359
- ret decl_fn ( llmod, name, lib. llvm . LLVMFastCallConv , inputs, output) ;
356
+ fn decl_fastcall_fn ( ModuleRef llmod, str name , TypeRef llty) -> ValueRef {
357
+ ret decl_fn ( llmod, name, lib. llvm . LLVMFastCallConv , llty) ;
360
358
}
361
359
362
360
fn decl_glue ( ModuleRef llmod, str s) -> ValueRef {
363
- ret decl_cdecl_fn ( llmod, s, vec ( T_taskptr ( ) ) , T_void ( ) ) ;
361
+ ret decl_cdecl_fn ( llmod, s, T_fn ( vec ( T_taskptr ( ) ) , T_void ( ) ) ) ;
364
362
}
365
363
366
364
fn decl_upcall ( ModuleRef llmod, uint _n) -> ValueRef {
@@ -375,7 +373,7 @@ fn decl_upcall(ModuleRef llmod, uint _n) -> ValueRef {
375
373
T_int ( ) ) // callee
376
374
+ _vec. init_elt [ TypeRef ] ( T_int ( ) , n as uint ) ;
377
375
378
- ret decl_fastcall_fn ( llmod, s, args, T_int ( ) ) ;
376
+ ret decl_fastcall_fn ( llmod, s, T_fn ( args, T_int ( ) ) ) ;
379
377
}
380
378
381
379
fn get_upcall ( @trans_ctxt cx , str name , int n_args ) -> ValueRef {
@@ -385,7 +383,7 @@ fn get_upcall(@trans_ctxt cx, str name, int n_args) -> ValueRef {
385
383
auto inputs = vec ( T_taskptr ( ) ) ;
386
384
inputs += _vec. init_elt [ TypeRef ] ( T_int ( ) , n_args as uint ) ;
387
385
auto output = T_int ( ) ;
388
- auto f = decl_cdecl_fn ( cx. llmod , name, inputs, output) ;
386
+ auto f = decl_cdecl_fn ( cx. llmod , name, T_fn ( inputs, output) ) ;
389
387
cx. upcalls . insert ( name, f) ;
390
388
ret f;
391
389
}
@@ -937,6 +935,7 @@ impure fn trans_expr(@block_ctxt cx, &ast.expr e) -> result {
937
935
case ( ast. expr_call ( ?f, ?args, _) ) {
938
936
auto f_res = trans_lval ( cx, * f) ;
939
937
check ( ! f_res. _1 ) ;
938
+
940
939
auto args_res = trans_exprs ( f_res. _0 . bcx , args) ;
941
940
auto llargs = vec ( cx. fcx . lltaskptr ) ;
942
941
llargs += args_res. _1 ;
@@ -1141,15 +1140,7 @@ impure fn trans_block(@block_ctxt cx, &ast.block b) -> result {
1141
1140
auto bcx = cx;
1142
1141
1143
1142
for each ( @ast. local local in block_locals( b) ) {
1144
- auto ty = T_nil ( ) ;
1145
- alt ( local. ty) {
1146
- case ( some[ @ast. ty] ( ?t) ) {
1147
- ty = type_of( cx. fcx. tcx, t) ;
1148
- }
1149
- case ( none[ @ast. ty] ) {
1150
- cx. fcx. tcx. sess. err( "missing type for local " + local. ident) ;
1151
- }
1152
- }
1143
+ auto ty = node_type( cx. fcx. tcx, local. ann) ;
1153
1144
auto val = bcx. build. Alloca ( ty) ;
1154
1145
cx. fcx. lllocals. insert( local. id, val) ;
1155
1146
}
@@ -1236,15 +1227,24 @@ impure fn trans_mod(@trans_ctxt cx, &ast._mod m) {
1236
1227
1237
1228
fn collect_item ( & @trans_ctxt cx , @ast. item i ) -> @trans_ctxt {
1238
1229
alt ( i. node ) {
1239
- case ( ast. item_fn ( ?name, ?f, ?fid, _) ) {
1240
- cx. items . insert ( fid, i) ;
1241
- let TypeRef out = type_of ( cx, f. output ) ;
1242
- auto args = vec ( T_taskptr ( ) ) ;
1243
- for ( ast. arg arg in f. inputs ) {
1244
- args += type_of ( cx, arg. ty ) ;
1230
+ case ( ast. item_fn ( ?name, ?f, ?fid, ?ann) ) {
1231
+ auto fn_inputs;
1232
+ auto fn_output;
1233
+ alt ( typeck. ann_to_type ( ann) . struct ) {
1234
+ case ( typeck. ty_fn ( ?ins, ?out) ) {
1235
+ fn_inputs = ins;
1236
+ fn_output = out;
1237
+ }
1238
+ case ( _) {
1239
+ log "trans: fn item doesn't have function type!" ;
1240
+ fail;
1241
+ }
1245
1242
}
1243
+
1244
+ cx. items . insert ( fid, i) ;
1245
+ auto llty = node_type ( cx, ann) ;
1246
1246
let str s = cx. names . next ( "_rust_fn" ) + "." + name;
1247
- let ValueRef llfn = decl_fastcall_fn ( cx. llmod , s, args , out ) ;
1247
+ let ValueRef llfn = decl_fastcall_fn ( cx. llmod , s, llty ) ;
1248
1248
cx. fn_ids . insert ( fid, llfn) ;
1249
1249
}
1250
1250
@@ -1338,10 +1338,10 @@ fn trans_main_fn(@trans_ctxt cx, ValueRef llcrate) {
1338
1338
}
1339
1339
1340
1340
auto llmain =
1341
- decl_cdecl_fn ( cx. llmod , main_name, T_main_args , T_int ( ) ) ;
1341
+ decl_cdecl_fn ( cx. llmod , main_name, T_fn ( T_main_args , T_int ( ) ) ) ;
1342
1342
1343
- auto llrust_start =
1344
- decl_cdecl_fn ( cx . llmod , "rust_start" , T_rust_start_args , T_int ( ) ) ;
1343
+ auto llrust_start = decl_cdecl_fn ( cx . llmod , "rust_start" ,
1344
+ T_fn ( T_rust_start_args , T_int ( ) ) ) ;
1345
1345
1346
1346
auto llargc = llvm. LLVMGetParam ( llmain, 0 u) ;
1347
1347
auto llargv = llvm. LLVMGetParam ( llmain, 1 u) ;
@@ -1367,7 +1367,7 @@ fn trans_main_fn(@trans_ctxt cx, ValueRef llcrate) {
1367
1367
1368
1368
fn declare_intrinsics ( ModuleRef llmod) {
1369
1369
let vec[ TypeRef ] T_trap_args = vec ( ) ;
1370
- decl_cdecl_fn ( llmod, "llvm.trap" , T_trap_args , T_void ( ) ) ;
1370
+ decl_cdecl_fn ( llmod, "llvm.trap" , T_fn ( T_trap_args , T_void ( ) ) ) ;
1371
1371
}
1372
1372
1373
1373
fn trans_crate ( session . session sess, @ast. crate crate, str output ) {
@@ -1396,7 +1396,7 @@ fn trans_crate(session.session sess, @ast.crate crate, str output) {
1396
1396
*/
1397
1397
exit_task_glue =
1398
1398
decl_cdecl_fn ( llmod, abi. exit_task_glue_name ( ) ,
1399
- vec ( T_taskptr ( ) ) , T_void ( ) ) ,
1399
+ T_fn ( vec ( T_taskptr ( ) ) , T_void ( ) ) ) ,
1400
1400
1401
1401
upcall_glues =
1402
1402
_vec. init_fn [ ValueRef ] ( bind decl_upcall ( llmod, _) ,
0 commit comments