Skip to content

Commit 43f83e5

Browse files
committed
---
yaml --- r: 1105 b: refs/heads/master c: 31f0642 h: refs/heads/master i: 1103: 86a3aaa v: v3
1 parent 454d47d commit 43f83e5

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 51782d2c21b275b8c9fcbf6cf05222d24aa1ada9
2+
refs/heads/master: 31f0642da3519985e69235be6cc30fc3f574ba95

trunk/src/comp/middle/trans.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2253,6 +2253,15 @@ fn arg_tys_of_fn(ast.ann ann) -> vec[typeck.arg] {
22532253
fail;
22542254
}
22552255

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+
22562265
impure fn trans_fn(@crate_ctxt cx, &ast._fn f, ast.def_id fid,
22572266
&ast.ann ann) {
22582267

@@ -2274,6 +2283,33 @@ impure fn trans_fn(@crate_ctxt cx, &ast._fn f, ast.def_id fid,
22742283
}
22752284
}
22762285

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+
22772313
fn trans_tag_variant(@crate_ctxt cx, ast.def_id tag_id,
22782314
&ast.variant variant, int index) {
22792315
if (_vec.len[ast.variant_arg](variant.args) == 0u) {
@@ -2351,6 +2387,10 @@ impure fn trans_item(@crate_ctxt cx, &ast.item item) {
23512387
auto sub_cx = @rec(path=cx.path + "." + name with *cx);
23522388
trans_fn(sub_cx, f, fid, ann);
23532389
}
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+
}
23542394
case (ast.item_mod(?name, ?m, _)) {
23552395
auto sub_cx = @rec(path=cx.path + "." + name with *cx);
23562396
trans_mod(sub_cx, m);

0 commit comments

Comments
 (0)