Collect obj items, translate obj-name references and obj-ctor types.

This commit is contained in:
Graydon Hoare 2010-12-16 10:23:47 -08:00
parent d8d2220b30
commit 7d2feae857

View file

@ -267,6 +267,31 @@ fn type_of(@crate_ctxt cx, @typeck.ty t) -> TypeRef {
ret llty; ret llty;
} }
fn type_of_fn(@crate_ctxt cx,
vec[typeck.arg] inputs,
@typeck.ty output) -> TypeRef {
let vec[TypeRef] atys = vec(T_taskptr());
for (typeck.arg arg in inputs) {
let TypeRef t = type_of(cx, arg.ty);
alt (arg.mode) {
case (ast.alias) {
t = T_ptr(t);
}
case (_) { /* fall through */ }
}
atys += t;
}
auto ret_ty;
if (typeck.type_is_nil(output)) {
ret_ty = llvm.LLVMVoidType();
} else {
ret_ty = type_of(cx, output);
}
ret T_fn(atys, ret_ty);
}
fn type_of_inner(@crate_ctxt cx, @typeck.ty t) -> TypeRef { fn type_of_inner(@crate_ctxt cx, @typeck.ty t) -> TypeRef {
alt (t.struct) { alt (t.struct) {
case (typeck.ty_nil) { ret T_nil(); } case (typeck.ty_nil) { ret T_nil(); }
@ -313,26 +338,19 @@ fn type_of_inner(@crate_ctxt cx, @typeck.ty t) -> TypeRef {
ret T_struct(tys); ret T_struct(tys);
} }
case (typeck.ty_fn(?args, ?out)) { case (typeck.ty_fn(?args, ?out)) {
let vec[TypeRef] atys = vec(T_taskptr()); ret type_of_fn(cx, args, out);
for (typeck.arg arg in args) { }
let TypeRef t = type_of(cx, arg.ty); case (typeck.ty_obj(?meths)) {
alt (arg.mode) { let vec[TypeRef] mtys = vec();
case (ast.alias) { for (typeck.method m in meths) {
t = T_ptr(t); let TypeRef mty = type_of_fn(cx, m.inputs, m.output);
} mtys += T_ptr(mty);
case (_) { /* fall through */ }
}
atys += t;
} }
let TypeRef vtbl = T_struct(mtys);
auto ret_ty; let TypeRef pair =
if (typeck.type_is_nil(out)) { T_struct(vec(T_ptr(vtbl),
ret_ty = llvm.LLVMVoidType(); T_ptr(T_box(T_opaque()))));
} else { ret pair;
ret_ty = type_of(cx, out);
}
ret T_fn(atys, ret_ty);
} }
case (typeck.ty_var(_)) { case (typeck.ty_var(_)) {
// FIXME: implement. // FIXME: implement.
@ -1496,6 +1514,11 @@ fn trans_name(@block_ctxt cx, &ast.name n, &option.t[ast.def] dopt)
ret tup(res(cx, cx.fcx.ccx.item_ids.get(did)), ret tup(res(cx, cx.fcx.ccx.item_ids.get(did)),
false); false);
} }
case (ast.def_obj(?did)) {
check (cx.fcx.ccx.item_ids.contains_key(did));
ret tup(res(cx, cx.fcx.ccx.item_ids.get(did)),
false);
}
case (ast.def_variant(?tid, ?vid)) { case (ast.def_variant(?tid, ?vid)) {
check (cx.fcx.ccx.tags.contains_key(tid)); check (cx.fcx.ccx.tags.contains_key(tid));
check (cx.fcx.ccx.item_ids.contains_key(vid)); check (cx.fcx.ccx.item_ids.contains_key(vid));
@ -2360,6 +2383,15 @@ fn collect_item(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {
cx.item_ids.insert(fid, llfn); cx.item_ids.insert(fid, llfn);
} }
case (ast.item_obj(?name, ?ob, _, ?oid, ?ann)) {
// TODO: type-params
cx.items.insert(oid, i);
auto llty = node_type(cx, ann);
let str s = cx.names.next("_rust_obj_ctor") + "." + name;
let ValueRef llfn = decl_fastcall_fn(cx.llmod, s, llty);
cx.item_ids.insert(oid, llfn);
}
case (ast.item_const(?name, _, _, ?cid, _)) { case (ast.item_const(?name, _, _, ?cid, _)) {
cx.items.insert(cid, i); cx.items.insert(cid, i);
} }