@@ -2253,6 +2253,15 @@ fn arg_tys_of_fn(ast.ann ann) -> vec[typeck.arg] {
2253
2253
fail;
2254
2254
}
2255
2255
2256
+ fn ret_ty_of_fn ( ast. ann ann ) -> @typeck . ty {
2257
+ alt ( typeck. ann_to_type ( ann) . struct ) {
2258
+ case ( typeck. ty_fn ( _, ?ret_ty) ) {
2259
+ ret ret_ty;
2260
+ }
2261
+ }
2262
+ fail;
2263
+ }
2264
+
2256
2265
impure fn trans_fn ( @crate_ctxt cx , & ast . _fn f, ast. def_id fid ,
2257
2266
& ast. ann ann ) {
2258
2267
@@ -2274,6 +2283,33 @@ impure fn trans_fn(@crate_ctxt cx, &ast._fn f, ast.def_id fid,
2274
2283
}
2275
2284
}
2276
2285
2286
+ fn trans_obj ( @crate_ctxt cx , & ast. _obj ob , ast. def_id oid ,
2287
+ & ast. ann ann ) {
2288
+
2289
+ auto llctor_decl = cx. item_ids . get ( oid) ;
2290
+ cx. item_names . insert ( cx. path , llctor_decl) ;
2291
+
2292
+ // Translate obj ctor fields to function arguments.
2293
+ let vec[ ast. arg ] fn_args = vec ( ) ;
2294
+ for ( ast. obj_field f in ob. fields) {
2295
+ fn_args += vec ( rec ( mode=ast. alias ,
2296
+ ty=f. ty ,
2297
+ ident=f. ident ,
2298
+ id=f. id ) ) ;
2299
+ }
2300
+
2301
+ auto fcx = new_fn_ctxt ( cx, cx. path , llctor_decl) ;
2302
+ create_llargs_for_fn_args ( fcx, fn_args) ;
2303
+
2304
+ auto bcx = new_top_block_ctxt ( fcx) ;
2305
+
2306
+ copy_args_to_allocas ( bcx, fn_args, arg_tys_of_fn ( ann) ) ;
2307
+
2308
+ auto pair = bcx. build . Alloca ( type_of ( cx, ret_ty_of_fn ( ann) ) ) ;
2309
+
2310
+ bcx. build . Ret ( pair) ;
2311
+ }
2312
+
2277
2313
fn trans_tag_variant ( @crate_ctxt cx , ast. def_id tag_id ,
2278
2314
& ast. variant variant , int index ) {
2279
2315
if ( _vec. len [ ast. variant_arg ] ( variant. args ) == 0 u) {
@@ -2351,6 +2387,10 @@ impure fn trans_item(@crate_ctxt cx, &ast.item item) {
2351
2387
auto sub_cx = @rec( path=cx. path + "." + name with * cx) ;
2352
2388
trans_fn( sub_cx, f, fid, ann) ;
2353
2389
}
2390
+ case ( ast. item_obj( ?name, ?ob, _, ?oid, ?ann) ) {
2391
+ auto sub_cx = @rec( path=cx. path + "." + name with * cx) ;
2392
+ trans_obj( sub_cx, ob, oid, ann) ;
2393
+ }
2354
2394
case ( ast. item_mod( ?name, ?m, _) ) {
2355
2395
auto sub_cx = @rec( path=cx. path + "." + name with * cx) ;
2356
2396
trans_mod( sub_cx, m) ;
0 commit comments