aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRafael Avila de Espindola <espindola@dream.(none)>2011-02-16 16:16:11 -0500
committerRafael Avila de Espindola <espindola@dream.(none)>2011-02-16 16:16:11 -0500
commit07c7888037cb74ca33459946145608a854aae6ed (patch)
tree4b46a3f2df3171ad78da0e3943c2e06c795e2210 /src
parentAdd a more specialized decl_native_fn_and_pair. Native functions now have (diff)
downloadrust-07c7888037cb74ca33459946145608a854aae6ed.tar.xz
rust-07c7888037cb74ca33459946145608a854aae6ed.zip
Don't add the rust arguments to native functions. We now produce the
correct arguments for native functions.
Diffstat (limited to 'src')
-rw-r--r--src/comp/middle/trans.rs45
-rw-r--r--src/comp/middle/ty.rs5
-rw-r--r--src/comp/middle/typeck.rs17
3 files changed, 50 insertions, 17 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 94fa9f91..e3e68d4b 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -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);
diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs
index a9be0c36..adda5a8c 100644
--- a/src/comp/middle/ty.rs
+++ b/src/comp/middle/ty.rs
@@ -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);
diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs
index 7ddc1d05..3dab25a7 100644
--- a/src/comp/middle/typeck.rs
+++ b/src/comp/middle/typeck.rs
@@ -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)) {