Don't add the rust arguments to native functions. We now produce the

correct arguments for native functions.
This commit is contained in:
Rafael Avila de Espindola 2011-02-16 16:16:11 -05:00
parent a63696dfe2
commit 07c7888037
3 changed files with 50 additions and 17 deletions

View file

@ -370,6 +370,26 @@ fn type_of(@crate_ctxt cx, @ty.t t) -> TypeRef {
ret llty;
}
fn type_of_explicit_args(@crate_ctxt cx,
vec[ty.arg] inputs) -> vec[TypeRef] {
let vec[TypeRef] atys = vec();
for (ty.arg arg in inputs) {
if (ty.type_has_dynamic_size(arg.ty)) {
check (arg.mode == ast.alias);
atys += T_typaram_ptr();
} else {
let TypeRef t = type_of(cx, arg.ty);
alt (arg.mode) {
case (ast.alias) {
t = T_ptr(t);
}
case (_) { /* fall through */ }
}
atys += t;
}
}
ret atys;
}
// NB: must keep 4 fns in sync:
//
@ -417,21 +437,7 @@ fn type_of_fn_full(@crate_ctxt cx,
}
// ... then explicit args.
for (ty.arg arg in inputs) {
if (ty.type_has_dynamic_size(arg.ty)) {
check (arg.mode == ast.alias);
atys += T_typaram_ptr();
} else {
let TypeRef t = type_of(cx, arg.ty);
alt (arg.mode) {
case (ast.alias) {
t = T_ptr(t);
}
case (_) { /* fall through */ }
}
atys += t;
}
}
atys += type_of_explicit_args(cx, inputs);
ret T_fn(atys, llvm.LLVMVoidType());
}
@ -440,6 +446,12 @@ fn type_of_fn(@crate_ctxt cx, vec[ty.arg] inputs, @ty.t output) -> TypeRef {
ret type_of_fn_full(cx, none[TypeRef], inputs, output);
}
fn type_of_native_fn(@crate_ctxt cx, vec[ty.arg] inputs,
@ty.t output) -> TypeRef {
let vec[TypeRef] atys = type_of_explicit_args(cx, inputs);
ret T_fn(atys, llvm.LLVMVoidType());
}
fn type_of_inner(@crate_ctxt cx, @ty.t t) -> TypeRef {
alt (t.struct) {
case (ty.ty_native) { ret T_ptr(T_i8()); }
@ -489,6 +501,9 @@ fn type_of_inner(@crate_ctxt cx, @ty.t t) -> TypeRef {
case (ty.ty_fn(?args, ?out)) {
ret T_fn_pair(type_of_fn(cx, args, out));
}
case (ty.ty_native_fn(?args, ?out)) {
ret T_fn_pair(type_of_native_fn(cx, args, out));
}
case (ty.ty_obj(?meths)) {
auto th = mk_type_handle();
auto self_ty = llvm.LLVMResolveTypeHandle(th.llth);

View file

@ -38,6 +38,7 @@ tag sty {
ty_tup(vec[@t]);
ty_rec(vec[field]);
ty_fn(vec[arg], @t); // TODO: effect
ty_native_fn(vec[arg], @t); // TODO: effect
ty_obj(vec[method]);
ty_var(int); // ephemeral type var
ty_local(ast.def_id); // type of a local var
@ -243,6 +244,10 @@ fn ty_to_str(&@t typ) -> str {
s = fn_to_str(none[ast.ident], inputs, output);
}
case (ty_native_fn(?inputs, ?output)) {
s = fn_to_str(none[ast.ident], inputs, output);
}
case (ty_obj(?meths)) {
auto f = method_to_str;
auto m = _vec.map[method,str](f, meths);

View file

@ -300,6 +300,19 @@ fn ty_of_fn_decl(@ty_item_table id_to_ty_item,
ret t_fn;
}
fn ty_of_native_fn_decl(@ty_item_table id_to_ty_item,
@ty_table item_to_ty,
fn(&@ast.ty ast_ty) -> @ty.t convert,
fn(&ast.arg a) -> arg ty_of_arg,
&ast.fn_decl decl,
ast.def_id def_id) -> @ty.t {
auto input_tys = _vec.map[ast.arg,arg](ty_of_arg, decl.inputs);
auto output_ty = convert(decl.output);
auto t_fn = plain_ty(ty.ty_native_fn(input_tys, output_ty));
item_to_ty.insert(def_id, t_fn);
ret t_fn;
}
fn collect_item_types(session.session sess, @ast.crate crate)
-> tup(@ast.crate, @ty_table, @ty_item_table) {
@ -436,8 +449,8 @@ fn collect_item_types(session.session sess, @ast.crate crate)
auto get = bind getter(id_to_ty_item, item_to_ty, _);
auto convert = bind ast_ty_to_ty(get, _);
auto f = bind ty_of_arg(id_to_ty_item, item_to_ty, _);
ret ty_of_fn_decl(id_to_ty_item, item_to_ty, convert, f,
fn_decl, def_id);
ret ty_of_native_fn_decl(id_to_ty_item, item_to_ty, convert,
f, fn_decl, def_id);
}
case (ast.native_item_ty(_, ?def_id)) {
if (item_to_ty.contains_key(def_id)) {