Skip to content

Commit 56e040e

Browse files
committed
Trans methods more correctly, and store vtbl pointer in pair returned from obj ctor.
1 parent 62d62ce commit 56e040e

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/comp/middle/trans.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,14 +2310,20 @@ impure fn trans_fn(@crate_ctxt cx, &ast._fn f, ast.def_id fid,
23102310
impure fn trans_vtbl(@crate_ctxt cx, &ast._obj ob) -> ValueRef {
23112311
let vec[ValueRef] methods = vec();
23122312
for (@ast.method m in ob.methods) {
2313+
2314+
auto llfnty = node_type(cx, m.node.ann);
2315+
let str s = cx.names.next("_rust_method") + "." + cx.path;
2316+
let ValueRef llfn = decl_fastcall_fn(cx.llmod, s, llfnty);
2317+
cx.item_ids.insert(m.node.id, llfn);
2318+
23132319
trans_fn(cx, m.node.meth, m.node.id, m.node.ann);
2314-
methods += cx.item_ids.get(m.node.id);
2320+
methods += llfn;
23152321
}
23162322
ret C_struct(methods);
23172323
}
23182324

2319-
fn trans_obj(@crate_ctxt cx, &ast._obj ob, ast.def_id oid,
2320-
&ast.ann ann) {
2325+
impure fn trans_obj(@crate_ctxt cx, &ast._obj ob, ast.def_id oid,
2326+
&ast.ann ann) {
23212327

23222328
auto llctor_decl = cx.item_ids.get(oid);
23232329
cx.item_names.insert(cx.path, llctor_decl);
@@ -2339,7 +2345,11 @@ fn trans_obj(@crate_ctxt cx, &ast._obj ob, ast.def_id oid,
23392345
copy_args_to_allocas(bcx, fn_args, arg_tys_of_fn(ann));
23402346

23412347
auto pair = bcx.build.Alloca(type_of(cx, ret_ty_of_fn(ann)));
2342-
2348+
auto vtbl = trans_vtbl(cx, ob);
2349+
auto pair_vtbl = bcx.build.GEP(pair,
2350+
vec(C_int(0),
2351+
C_int(abi.obj_field_vtbl)));
2352+
bcx.build.Store(vtbl, pair_vtbl);
23432353
bcx.build.Ret(pair);
23442354
}
23452355

0 commit comments

Comments
 (0)