@@ -51,7 +51,6 @@ state type trans_ctxt = rec(session.session sess,
51
51
str path) ;
52
52
53
53
state type fn_ctxt = rec ( ValueRef llfn,
54
- ValueRef lloutptr,
55
54
ValueRef lltaskptr ,
56
55
hashmap[ ast. def_id, ValueRef ] llargs ,
57
56
hashmap[ ast. def_id, ValueRef ] lllocals ,
@@ -939,28 +938,13 @@ impure fn trans_expr(@block_ctxt cx, &ast.expr e) -> result {
939
938
case ( ast. expr_call ( ?f, ?args, _) ) {
940
939
auto f_res = trans_lval ( cx, * f) ;
941
940
check ( ! f_res. _1 ) ;
942
-
943
- // FIXME: Revolting hack to get the type of the outptr. Can get a
944
- // variety of other ways; will wait until we have a typechecker
945
- // perhaps to pick a more tasteful one.
946
- auto outptr = cx. fcx . lloutptr ;
947
- alt ( cx. fcx . tcx . items . get ( f_res. _2 ) . node ) {
948
- case ( ast. item_fn ( _, ?ff, _, _) ) {
949
- outptr = cx. build . Alloca ( type_of ( cx. fcx . tcx , ff. output ) ) ;
950
- }
951
- case ( _) {
952
- cx. fcx . tcx . sess . unimpl ( "call to non-item" ) ;
953
- }
954
- }
955
941
auto args_res = trans_exprs ( f_res. _0 . bcx , args) ;
956
- auto llargs = vec ( outptr,
957
- cx. fcx . lltaskptr ) ;
942
+ auto llargs = vec ( cx. fcx . lltaskptr ) ;
958
943
llargs += args_res. _1 ;
959
944
auto call_val = args_res. _0 . build . Call ( f_res. _0 . val , llargs) ;
960
945
llvm. LLVMSetInstructionCallConv ( call_val,
961
946
lib. llvm . LLVMFastCallConv ) ;
962
- ret res( args_res. _0 ,
963
- args_res. _0 . build . Load ( outptr) ) ;
947
+ ret res ( args_res. _0 , call_val) ;
964
948
}
965
949
966
950
}
@@ -1021,7 +1005,6 @@ impure fn trans_ret(@block_ctxt cx, &option.t[@ast.expr] e) -> result {
1021
1005
alt ( e) {
1022
1006
case ( some[ @ast. expr] ( ?x) ) {
1023
1007
r = trans_expr ( cx , * x ) ;
1024
- r. bcx . build . Store ( r. val , cx. fcx . lloutptr ) ;
1025
1008
}
1026
1009
}
1027
1010
@@ -1040,7 +1023,16 @@ impure fn trans_ret(@block_ctxt cx, &option.t[@ast.expr] e) -> result {
1040
1023
}
1041
1024
}
1042
1025
1043
- r. val = r. bcx . build . RetVoid ( ) ;
1026
+ alt ( e) {
1027
+ case ( some[ @ast. expr ] ( _) ) {
1028
+ r. val = r. bcx . build . Ret ( r. val ) ;
1029
+ ret r;
1030
+ }
1031
+ }
1032
+
1033
+ // FIXME: until LLVM has a unit type, we are moving around
1034
+ // C_nil values rather than their void type.
1035
+ r. val = r. bcx . build . Ret ( C_nil ( ) ) ;
1044
1036
ret r;
1045
1037
}
1046
1038
@@ -1188,20 +1180,20 @@ fn new_fn_ctxt(@trans_ctxt cx,
1188
1180
let ValueRef llfn = cx. fn_ids . get ( fid) ;
1189
1181
cx. fn_names . insert ( cx. path , llfn) ;
1190
1182
1191
- let ValueRef lloutptr = llvm. LLVMGetParam ( llfn, 0 u) ;
1192
- let ValueRef lltaskptr = llvm . LLVMGetParam ( llfn , 1 u ) ;
1183
+ let ValueRef lltaskptr = llvm. LLVMGetParam ( llfn, 0 u) ;
1184
+ let uint arg_n = 1 u ;
1193
1185
1194
1186
let hashmap[ ast. def_id , ValueRef ] lllocals = new_def_hash[ ValueRef ] ( ) ;
1195
1187
let hashmap[ ast. def_id , ValueRef ] llargs = new_def_hash[ ValueRef ] ( ) ;
1196
1188
1197
- let uint arg_n = 2 u;
1198
1189
for ( ast. arg arg in f. inputs ) {
1199
- llargs. insert ( arg. id , llvm. LLVMGetParam ( llfn, arg_n) ) ;
1190
+ auto llarg = llvm. LLVMGetParam ( llfn, arg_n) ;
1191
+ check ( llarg as int != 0 ) ;
1192
+ llargs. insert ( arg. id , llarg) ;
1200
1193
arg_n += 1 u;
1201
1194
}
1202
1195
1203
1196
ret @rec( llfn=llfn,
1204
- lloutptr=lloutptr,
1205
1197
lltaskptr=lltaskptr,
1206
1198
llargs=llargs,
1207
1199
lllocals=lllocals,
@@ -1219,7 +1211,9 @@ impure fn trans_fn(@trans_ctxt cx, &ast._fn f, ast.def_id fid) {
1219
1211
auto bcx = new_top_block_ctxt ( fcx) ;
1220
1212
auto res = trans_block ( bcx, f. body ) ;
1221
1213
if ( !is_terminated ( res. bcx ) ) {
1222
- res. bcx . build . RetVoid ( ) ;
1214
+ // FIXME: until LLVM has a unit type, we are moving around
1215
+ // C_nil values rather than their void type.
1216
+ res. bcx . build . Ret ( C_nil ( ) ) ;
1223
1217
}
1224
1218
}
1225
1219
@@ -1247,18 +1241,13 @@ fn collect_item(&@trans_ctxt cx, @ast.item i) -> @trans_ctxt {
1247
1241
alt ( i. node ) {
1248
1242
case ( ast. item_fn ( ?name, ?f, ?fid, _) ) {
1249
1243
cx. items . insert ( fid, i) ;
1250
- let vec[ TypeRef ] args =
1251
- vec ( T_ptr ( type_of ( cx, f. output ) ) , // outptr.
1252
- T_taskptr ( ) // taskptr
1253
- ) ;
1254
- let vec[ TypeRef ] T_explicit_args = vec ( ) ;
1244
+ let TypeRef out = type_of ( cx, f. output ) ;
1245
+ auto args = vec ( T_taskptr ( ) ) ;
1255
1246
for ( ast. arg arg in f. inputs ) {
1256
- T_explicit_args += type_of ( cx, arg. ty ) ;
1247
+ args += type_of ( cx, arg. ty ) ;
1257
1248
}
1258
- args += T_explicit_args ;
1259
-
1260
1249
let str s = cx. names . next ( "_rust_fn" ) + "." + name;
1261
- let ValueRef llfn = decl_fastcall_fn ( cx. llmod , s, args, T_void ( ) ) ;
1250
+ let ValueRef llfn = decl_fastcall_fn ( cx. llmod , s, args, out ) ;
1262
1251
cx. fn_ids . insert ( fid, llfn) ;
1263
1252
}
1264
1253
@@ -1290,10 +1279,8 @@ fn trans_exit_task_glue(@trans_ctxt cx) {
1290
1279
let vec[ ValueRef ] V_args = vec ( ) ;
1291
1280
1292
1281
auto llfn = cx. glues . exit_task_glue ;
1293
- let ValueRef lloutptr = C_null ( T_int ( ) ) ;
1294
1282
let ValueRef lltaskptr = llvm. LLVMGetParam ( llfn, 0 u) ;
1295
1283
auto fcx = @rec ( llfn=llfn,
1296
- lloutptr=lloutptr,
1297
1284
lltaskptr=lltaskptr,
1298
1285
llargs=new_def_hash[ ValueRef ] ( ) ,
1299
1286
lllocals=new_def_hash[ ValueRef ] ( ) ,
0 commit comments