Pass the abi of native functions all the way to codegen.
This commit is contained in:
parent
f8f6f078c5
commit
081c3aa76d
4 changed files with 51 additions and 32 deletions
|
|
@ -1818,8 +1818,8 @@ impure fn parse_item_native_mod(parser p) -> @ast.item {
|
|||
auto abi = ast.native_abi_cdecl;
|
||||
if (p.peek() != token.MOD) {
|
||||
auto t = parse_str_lit(p);
|
||||
if (t == "cdecl") {
|
||||
} else if (t == "rust") {
|
||||
if (_str.eq(t, "cdecl")) {
|
||||
} else if (_str.eq(t, "rust")) {
|
||||
abi = ast.native_abi_rust;
|
||||
} else {
|
||||
p.err("unsupported abi: " + t);
|
||||
|
|
|
|||
|
|
@ -516,7 +516,8 @@ fn type_of_fn(@crate_ctxt cx,
|
|||
ret type_of_fn_full(cx, proto, none[TypeRef], inputs, output);
|
||||
}
|
||||
|
||||
fn type_of_native_fn(@crate_ctxt cx, vec[ty.arg] inputs,
|
||||
fn type_of_native_fn(@crate_ctxt cx, ast.native_abi abi,
|
||||
vec[ty.arg] inputs,
|
||||
@ty.t output) -> TypeRef {
|
||||
let vec[TypeRef] atys = type_of_explicit_args(cx, inputs);
|
||||
ret T_fn(atys, type_of(cx, output));
|
||||
|
|
@ -571,8 +572,8 @@ fn type_of_inner(@crate_ctxt cx, @ty.t t) -> TypeRef {
|
|||
case (ty.ty_fn(?proto, ?args, ?out)) {
|
||||
ret T_fn_pair(cx.tn, type_of_fn(cx, proto, args, out));
|
||||
}
|
||||
case (ty.ty_native_fn(?args, ?out)) {
|
||||
ret T_fn_pair(cx.tn, type_of_native_fn(cx, args, out));
|
||||
case (ty.ty_native_fn(?abi, ?args, ?out)) {
|
||||
ret T_fn_pair(cx.tn, type_of_native_fn(cx, abi, args, out));
|
||||
}
|
||||
case (ty.ty_obj(?meths)) {
|
||||
auto th = mk_type_handle();
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ tag sty {
|
|||
ty_tup(vec[@t]);
|
||||
ty_rec(vec[field]);
|
||||
ty_fn(ast.proto, vec[arg], @t); // TODO: effect
|
||||
ty_native_fn(vec[arg], @t); // TODO: effect
|
||||
ty_native_fn(ast.native_abi, 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
|
||||
|
|
@ -261,7 +261,7 @@ fn ty_to_str(&@t typ) -> str {
|
|||
s = fn_to_str(proto, none[ast.ident], inputs, output);
|
||||
}
|
||||
|
||||
case (ty_native_fn(?inputs, ?output)) {
|
||||
case (ty_native_fn(_, ?inputs, ?output)) {
|
||||
s = fn_to_str(ast.proto_fn, none[ast.ident], inputs, output);
|
||||
}
|
||||
|
||||
|
|
@ -346,13 +346,13 @@ fn fold_ty(ty_fold fld, @t ty) -> @t {
|
|||
}
|
||||
ret rewrap(ty, ty_fn(proto, new_args, fold_ty(fld, ret_ty)));
|
||||
}
|
||||
case (ty_native_fn(?args, ?ret_ty)) {
|
||||
case (ty_native_fn(?abi, ?args, ?ret_ty)) {
|
||||
let vec[arg] new_args = vec();
|
||||
for (arg a in args) {
|
||||
auto new_ty = fold_ty(fld, a.ty);
|
||||
new_args += vec(rec(mode=a.mode, ty=new_ty));
|
||||
}
|
||||
ret rewrap(ty, ty_native_fn(new_args, fold_ty(fld, ret_ty)));
|
||||
ret rewrap(ty, ty_native_fn(abi, new_args, fold_ty(fld, ret_ty)));
|
||||
}
|
||||
case (ty_obj(?methods)) {
|
||||
let vec[method] new_methods = vec();
|
||||
|
|
@ -596,7 +596,7 @@ fn count_ty_params(@t ty) -> uint {
|
|||
fn ty_fn_args(@t fty) -> vec[arg] {
|
||||
alt (fty.struct) {
|
||||
case (ty.ty_fn(_, ?a, _)) { ret a; }
|
||||
case (ty.ty_native_fn(?a, _)) { ret a; }
|
||||
case (ty.ty_native_fn(_, ?a, _)) { ret a; }
|
||||
}
|
||||
fail;
|
||||
}
|
||||
|
|
@ -611,7 +611,7 @@ fn ty_fn_proto(@t fty) -> ast.proto {
|
|||
fn ty_fn_ret(@t fty) -> @t {
|
||||
alt (fty.struct) {
|
||||
case (ty.ty_fn(_, _, ?r)) { ret r; }
|
||||
case (ty.ty_native_fn(_, ?r)) { ret r; }
|
||||
case (ty.ty_native_fn(_, _, ?r)) { ret r; }
|
||||
}
|
||||
fail;
|
||||
}
|
||||
|
|
@ -619,7 +619,7 @@ fn ty_fn_ret(@t fty) -> @t {
|
|||
fn is_fn_ty(@t fty) -> bool {
|
||||
alt (fty.struct) {
|
||||
case (ty.ty_fn(_, _, _)) { ret true; }
|
||||
case (ty.ty_native_fn(_, _)) { ret true; }
|
||||
case (ty.ty_native_fn(_, _, _)) { ret true; }
|
||||
case (_) { ret false; }
|
||||
}
|
||||
ret false;
|
||||
|
|
@ -938,12 +938,18 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
|
|||
}
|
||||
|
||||
fn unify_native_fn(@hashmap[int,@ty.t] bindings,
|
||||
ast.native_abi e_abi,
|
||||
ast.native_abi a_abi,
|
||||
@ty.t expected,
|
||||
@ty.t actual,
|
||||
&unify_handler handler,
|
||||
vec[arg] expected_inputs, @t expected_output,
|
||||
vec[arg] actual_inputs, @t actual_output)
|
||||
-> unify_result {
|
||||
if (e_abi != a_abi) {
|
||||
ret ures_err(terr_mismatch, expected, actual);
|
||||
}
|
||||
|
||||
auto t = unify_fn_common(bindings, expected, actual,
|
||||
handler, expected_inputs, expected_output,
|
||||
actual_inputs, actual_output);
|
||||
|
|
@ -952,7 +958,8 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
|
|||
ret r;
|
||||
}
|
||||
case (fn_common_res_ok(?result_ins, ?result_out)) {
|
||||
auto t2 = plain_ty(ty.ty_native_fn(result_ins, result_out));
|
||||
auto t2 = plain_ty(ty.ty_native_fn(e_abi, result_ins,
|
||||
result_out));
|
||||
ret ures_ok(t2);
|
||||
}
|
||||
}
|
||||
|
|
@ -1314,10 +1321,12 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
|
|||
}
|
||||
}
|
||||
|
||||
case (ty.ty_native_fn(?expected_inputs, ?expected_output)) {
|
||||
case (ty.ty_native_fn(?e_abi, ?expected_inputs,
|
||||
?expected_output)) {
|
||||
alt (actual.struct) {
|
||||
case (ty.ty_native_fn(?actual_inputs, ?actual_output)) {
|
||||
ret unify_native_fn(bindings,
|
||||
case (ty.ty_native_fn(?a_abi, ?actual_inputs,
|
||||
?actual_output)) {
|
||||
ret unify_native_fn(bindings, e_abi, a_abi,
|
||||
expected, actual, handler,
|
||||
expected_inputs, expected_output,
|
||||
actual_inputs, actual_output);
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ type ty_table = hashmap[ast.def_id, @ty.t];
|
|||
|
||||
tag any_item {
|
||||
any_item_rust(@ast.item);
|
||||
any_item_native(@ast.native_item);
|
||||
any_item_native(@ast.native_item, ast.native_abi);
|
||||
}
|
||||
|
||||
type ty_item_table = hashmap[ast.def_id,any_item];
|
||||
|
|
@ -272,7 +272,7 @@ fn ast_ty_to_ty_crate(@crate_ctxt ccx, &@ast.ty ast_ty) -> @ty.t {
|
|||
ty = actual_type(ty, item);
|
||||
params = ty_params_of_item(item);
|
||||
}
|
||||
case (any_item_native(?native_item)) {
|
||||
case (any_item_native(?native_item, _)) {
|
||||
params = ty_params_of_native_item(native_item);
|
||||
}
|
||||
}
|
||||
|
|
@ -346,10 +346,11 @@ fn ty_of_native_fn_decl(@ty_item_table id_to_ty_item,
|
|||
fn(&@ast.ty ast_ty) -> @ty.t convert,
|
||||
fn(&ast.arg a) -> arg ty_of_arg,
|
||||
&ast.fn_decl decl,
|
||||
ast.native_abi abi,
|
||||
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));
|
||||
auto t_fn = plain_ty(ty.ty_native_fn(abi, input_tys, output_ty));
|
||||
item_to_ty.insert(def_id, t_fn);
|
||||
ret t_fn;
|
||||
}
|
||||
|
|
@ -370,9 +371,9 @@ fn collect_item_types(session.session sess, @ast.crate crate)
|
|||
ty = actual_type(ty, item);
|
||||
params = ty_params_of_item(item);
|
||||
}
|
||||
case (any_item_native(?native_item)) {
|
||||
case (any_item_native(?native_item, ?abi)) {
|
||||
ty = ty_of_native_item(id_to_ty_item, item_to_ty,
|
||||
native_item);
|
||||
native_item, abi);
|
||||
params = ty_params_of_native_item(native_item);
|
||||
}
|
||||
}
|
||||
|
|
@ -490,14 +491,15 @@ fn collect_item_types(session.session sess, @ast.crate crate)
|
|||
|
||||
fn ty_of_native_item(@ty_item_table id_to_ty_item,
|
||||
@ty_table item_to_ty,
|
||||
@ast.native_item it) -> @ty.t {
|
||||
@ast.native_item it,
|
||||
ast.native_abi abi) -> @ty.t {
|
||||
alt (it.node) {
|
||||
case (ast.native_item_fn(?ident, ?fn_decl, ?params, ?def_id, _)) {
|
||||
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_native_fn_decl(id_to_ty_item, item_to_ty, convert,
|
||||
f, fn_decl, def_id);
|
||||
f, fn_decl, abi, def_id);
|
||||
}
|
||||
case (ast.native_item_ty(_, ?def_id)) {
|
||||
if (item_to_ty.contains_key(def_id)) {
|
||||
|
|
@ -578,7 +580,10 @@ fn collect_item_types(session.session sess, @ast.crate crate)
|
|||
-> @ty_item_table {
|
||||
alt (i.node) {
|
||||
case (ast.native_item_ty(_, ?def_id)) {
|
||||
id_to_ty_item.insert(def_id, any_item_native(i));
|
||||
// The abi of types is not used.
|
||||
id_to_ty_item.insert(def_id,
|
||||
any_item_native(i,
|
||||
ast.native_abi_cdecl));
|
||||
}
|
||||
case (_) {
|
||||
}
|
||||
|
|
@ -598,18 +603,22 @@ fn collect_item_types(session.session sess, @ast.crate crate)
|
|||
|
||||
type env = rec(session.session sess,
|
||||
@ty_item_table id_to_ty_item,
|
||||
@ty_table item_to_ty);
|
||||
@ty_table item_to_ty,
|
||||
ast.native_abi abi);
|
||||
let @env e = @rec(sess=sess,
|
||||
id_to_ty_item=id_to_ty_item,
|
||||
item_to_ty=item_to_ty);
|
||||
item_to_ty=item_to_ty,
|
||||
abi=ast.native_abi_cdecl);
|
||||
|
||||
fn convert(&@env e, @ast.item i) -> @env {
|
||||
auto abi = e.abi;
|
||||
alt (i.node) {
|
||||
case (ast.item_mod(_, _, _)) {
|
||||
// ignore item_mod, it has no type.
|
||||
}
|
||||
case (ast.item_native_mod(_, _, _)) {
|
||||
case (ast.item_native_mod(_, ?native_mod, _)) {
|
||||
// ignore item_native_mod, it has no type.
|
||||
abi = native_mod.abi;
|
||||
}
|
||||
case (_) {
|
||||
// This call populates the ty_table with the converted type of
|
||||
|
|
@ -617,11 +626,11 @@ fn collect_item_types(session.session sess, @ast.crate crate)
|
|||
ty_of_item(e.id_to_ty_item, e.item_to_ty, i);
|
||||
}
|
||||
}
|
||||
ret e;
|
||||
ret @rec(abi=abi with *e);
|
||||
}
|
||||
|
||||
fn convert_native(&@env e, @ast.native_item i) -> @env {
|
||||
ty_of_native_item(e.id_to_ty_item, e.item_to_ty, i);
|
||||
ty_of_native_item(e.id_to_ty_item, e.item_to_ty, i, e.abi);
|
||||
ret e;
|
||||
}
|
||||
|
||||
|
|
@ -1322,8 +1331,8 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
|
|||
case (ty.ty_fn(?proto, _, _)) {
|
||||
t_0 = plain_ty(ty.ty_fn(proto, arg_tys_0, rt_0));
|
||||
}
|
||||
case (ty.ty_native_fn(_, _)) {
|
||||
t_0 = plain_ty(ty.ty_native_fn(arg_tys_0, rt_0));
|
||||
case (ty.ty_native_fn(?abi, _, _)) {
|
||||
t_0 = plain_ty(ty.ty_native_fn(abi, arg_tys_0, rt_0));
|
||||
}
|
||||
case (_) {
|
||||
log "check_call_or_bind(): fn expr doesn't have fn type";
|
||||
|
|
@ -1807,7 +1816,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
|
|||
auto rt_1 = plain_ty(ty.ty_nil); // FIXME: typestate botch
|
||||
alt (expr_ty(result._0).struct) {
|
||||
case (ty.ty_fn(_,_,?rt)) { rt_1 = rt; }
|
||||
case (ty.ty_native_fn(_,?rt)) { rt_1 = rt; }
|
||||
case (ty.ty_native_fn(_, _, ?rt)) { rt_1 = rt; }
|
||||
case (_) {
|
||||
log "LHS of call expr didn't have a function type?!";
|
||||
fail;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue