Skip to content

Commit b52e014

Browse files
committed
---
yaml --- r: 1437 b: refs/heads/master c: 081c3aa h: refs/heads/master i: 1435: 5cd4ac0 v: v3
1 parent 82c4f71 commit b52e014

File tree

5 files changed

+52
-33
lines changed

5 files changed

+52
-33
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: f8f6f078c505dd0f20526e3ad86c360605fce109
2+
refs/heads/master: 081c3aa76dd0805767e0233c0cc6ccf313cf44ba

trunk/src/comp/front/parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,8 +1818,8 @@ impure fn parse_item_native_mod(parser p) -> @ast.item {
18181818
auto abi = ast.native_abi_cdecl;
18191819
if (p.peek() != token.MOD) {
18201820
auto t = parse_str_lit(p);
1821-
if (t == "cdecl") {
1822-
} else if (t == "rust") {
1821+
if (_str.eq(t, "cdecl")) {
1822+
} else if (_str.eq(t, "rust")) {
18231823
abi = ast.native_abi_rust;
18241824
} else {
18251825
p.err("unsupported abi: " + t);

trunk/src/comp/middle/trans.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,8 @@ fn type_of_fn(@crate_ctxt cx,
516516
ret type_of_fn_full(cx, proto, none[TypeRef], inputs, output);
517517
}
518518

519-
fn type_of_native_fn(@crate_ctxt cx, vec[ty.arg] inputs,
519+
fn type_of_native_fn(@crate_ctxt cx, ast.native_abi abi,
520+
vec[ty.arg] inputs,
520521
@ty.t output) -> TypeRef {
521522
let vec[TypeRef] atys = type_of_explicit_args(cx, inputs);
522523
ret T_fn(atys, type_of(cx, output));
@@ -571,8 +572,8 @@ fn type_of_inner(@crate_ctxt cx, @ty.t t) -> TypeRef {
571572
case (ty.ty_fn(?proto, ?args, ?out)) {
572573
ret T_fn_pair(cx.tn, type_of_fn(cx, proto, args, out));
573574
}
574-
case (ty.ty_native_fn(?args, ?out)) {
575-
ret T_fn_pair(cx.tn, type_of_native_fn(cx, args, out));
575+
case (ty.ty_native_fn(?abi, ?args, ?out)) {
576+
ret T_fn_pair(cx.tn, type_of_native_fn(cx, abi, args, out));
576577
}
577578
case (ty.ty_obj(?meths)) {
578579
auto th = mk_type_handle();

trunk/src/comp/middle/ty.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ tag sty {
4141
ty_tup(vec[@t]);
4242
ty_rec(vec[field]);
4343
ty_fn(ast.proto, vec[arg], @t); // TODO: effect
44-
ty_native_fn(vec[arg], @t); // TODO: effect
44+
ty_native_fn(ast.native_abi, vec[arg], @t); // TODO: effect
4545
ty_obj(vec[method]);
4646
ty_var(int); // ephemeral type var
4747
ty_local(ast.def_id); // type of a local var
@@ -261,7 +261,7 @@ fn ty_to_str(&@t typ) -> str {
261261
s = fn_to_str(proto, none[ast.ident], inputs, output);
262262
}
263263

264-
case (ty_native_fn(?inputs, ?output)) {
264+
case (ty_native_fn(_, ?inputs, ?output)) {
265265
s = fn_to_str(ast.proto_fn, none[ast.ident], inputs, output);
266266
}
267267

@@ -346,13 +346,13 @@ fn fold_ty(ty_fold fld, @t ty) -> @t {
346346
}
347347
ret rewrap(ty, ty_fn(proto, new_args, fold_ty(fld, ret_ty)));
348348
}
349-
case (ty_native_fn(?args, ?ret_ty)) {
349+
case (ty_native_fn(?abi, ?args, ?ret_ty)) {
350350
let vec[arg] new_args = vec();
351351
for (arg a in args) {
352352
auto new_ty = fold_ty(fld, a.ty);
353353
new_args += vec(rec(mode=a.mode, ty=new_ty));
354354
}
355-
ret rewrap(ty, ty_native_fn(new_args, fold_ty(fld, ret_ty)));
355+
ret rewrap(ty, ty_native_fn(abi, new_args, fold_ty(fld, ret_ty)));
356356
}
357357
case (ty_obj(?methods)) {
358358
let vec[method] new_methods = vec();
@@ -596,7 +596,7 @@ fn count_ty_params(@t ty) -> uint {
596596
fn ty_fn_args(@t fty) -> vec[arg] {
597597
alt (fty.struct) {
598598
case (ty.ty_fn(_, ?a, _)) { ret a; }
599-
case (ty.ty_native_fn(?a, _)) { ret a; }
599+
case (ty.ty_native_fn(_, ?a, _)) { ret a; }
600600
}
601601
fail;
602602
}
@@ -611,15 +611,15 @@ fn ty_fn_proto(@t fty) -> ast.proto {
611611
fn ty_fn_ret(@t fty) -> @t {
612612
alt (fty.struct) {
613613
case (ty.ty_fn(_, _, ?r)) { ret r; }
614-
case (ty.ty_native_fn(_, ?r)) { ret r; }
614+
case (ty.ty_native_fn(_, _, ?r)) { ret r; }
615615
}
616616
fail;
617617
}
618618

619619
fn is_fn_ty(@t fty) -> bool {
620620
alt (fty.struct) {
621621
case (ty.ty_fn(_, _, _)) { ret true; }
622-
case (ty.ty_native_fn(_, _)) { ret true; }
622+
case (ty.ty_native_fn(_, _, _)) { ret true; }
623623
case (_) { ret false; }
624624
}
625625
ret false;
@@ -938,12 +938,18 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
938938
}
939939

940940
fn unify_native_fn(@hashmap[int,@ty.t] bindings,
941+
ast.native_abi e_abi,
942+
ast.native_abi a_abi,
941943
@ty.t expected,
942944
@ty.t actual,
943945
&unify_handler handler,
944946
vec[arg] expected_inputs, @t expected_output,
945947
vec[arg] actual_inputs, @t actual_output)
946948
-> unify_result {
949+
if (e_abi != a_abi) {
950+
ret ures_err(terr_mismatch, expected, actual);
951+
}
952+
947953
auto t = unify_fn_common(bindings, expected, actual,
948954
handler, expected_inputs, expected_output,
949955
actual_inputs, actual_output);
@@ -952,7 +958,8 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
952958
ret r;
953959
}
954960
case (fn_common_res_ok(?result_ins, ?result_out)) {
955-
auto t2 = plain_ty(ty.ty_native_fn(result_ins, result_out));
961+
auto t2 = plain_ty(ty.ty_native_fn(e_abi, result_ins,
962+
result_out));
956963
ret ures_ok(t2);
957964
}
958965
}
@@ -1314,10 +1321,12 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
13141321
}
13151322
}
13161323

1317-
case (ty.ty_native_fn(?expected_inputs, ?expected_output)) {
1324+
case (ty.ty_native_fn(?e_abi, ?expected_inputs,
1325+
?expected_output)) {
13181326
alt (actual.struct) {
1319-
case (ty.ty_native_fn(?actual_inputs, ?actual_output)) {
1320-
ret unify_native_fn(bindings,
1327+
case (ty.ty_native_fn(?a_abi, ?actual_inputs,
1328+
?actual_output)) {
1329+
ret unify_native_fn(bindings, e_abi, a_abi,
13211330
expected, actual, handler,
13221331
expected_inputs, expected_output,
13231332
actual_inputs, actual_output);

trunk/src/comp/middle/typeck.rs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type ty_table = hashmap[ast.def_id, @ty.t];
3535

3636
tag any_item {
3737
any_item_rust(@ast.item);
38-
any_item_native(@ast.native_item);
38+
any_item_native(@ast.native_item, ast.native_abi);
3939
}
4040

4141
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 {
272272
ty = actual_type(ty, item);
273273
params = ty_params_of_item(item);
274274
}
275-
case (any_item_native(?native_item)) {
275+
case (any_item_native(?native_item, _)) {
276276
params = ty_params_of_native_item(native_item);
277277
}
278278
}
@@ -346,10 +346,11 @@ fn ty_of_native_fn_decl(@ty_item_table id_to_ty_item,
346346
fn(&@ast.ty ast_ty) -> @ty.t convert,
347347
fn(&ast.arg a) -> arg ty_of_arg,
348348
&ast.fn_decl decl,
349+
ast.native_abi abi,
349350
ast.def_id def_id) -> @ty.t {
350351
auto input_tys = _vec.map[ast.arg,arg](ty_of_arg, decl.inputs);
351352
auto output_ty = convert(decl.output);
352-
auto t_fn = plain_ty(ty.ty_native_fn(input_tys, output_ty));
353+
auto t_fn = plain_ty(ty.ty_native_fn(abi, input_tys, output_ty));
353354
item_to_ty.insert(def_id, t_fn);
354355
ret t_fn;
355356
}
@@ -370,9 +371,9 @@ fn collect_item_types(session.session sess, @ast.crate crate)
370371
ty = actual_type(ty, item);
371372
params = ty_params_of_item(item);
372373
}
373-
case (any_item_native(?native_item)) {
374+
case (any_item_native(?native_item, ?abi)) {
374375
ty = ty_of_native_item(id_to_ty_item, item_to_ty,
375-
native_item);
376+
native_item, abi);
376377
params = ty_params_of_native_item(native_item);
377378
}
378379
}
@@ -490,14 +491,15 @@ fn collect_item_types(session.session sess, @ast.crate crate)
490491

491492
fn ty_of_native_item(@ty_item_table id_to_ty_item,
492493
@ty_table item_to_ty,
493-
@ast.native_item it) -> @ty.t {
494+
@ast.native_item it,
495+
ast.native_abi abi) -> @ty.t {
494496
alt (it.node) {
495497
case (ast.native_item_fn(?ident, ?fn_decl, ?params, ?def_id, _)) {
496498
auto get = bind getter(id_to_ty_item, item_to_ty, _);
497499
auto convert = bind ast_ty_to_ty(get, _);
498500
auto f = bind ty_of_arg(id_to_ty_item, item_to_ty, _);
499501
ret ty_of_native_fn_decl(id_to_ty_item, item_to_ty, convert,
500-
f, fn_decl, def_id);
502+
f, fn_decl, abi, def_id);
501503
}
502504
case (ast.native_item_ty(_, ?def_id)) {
503505
if (item_to_ty.contains_key(def_id)) {
@@ -578,7 +580,10 @@ fn collect_item_types(session.session sess, @ast.crate crate)
578580
-> @ty_item_table {
579581
alt (i.node) {
580582
case (ast.native_item_ty(_, ?def_id)) {
581-
id_to_ty_item.insert(def_id, any_item_native(i));
583+
// The abi of types is not used.
584+
id_to_ty_item.insert(def_id,
585+
any_item_native(i,
586+
ast.native_abi_cdecl));
582587
}
583588
case (_) {
584589
}
@@ -598,30 +603,34 @@ fn collect_item_types(session.session sess, @ast.crate crate)
598603

599604
type env = rec(session.session sess,
600605
@ty_item_table id_to_ty_item,
601-
@ty_table item_to_ty);
606+
@ty_table item_to_ty,
607+
ast.native_abi abi);
602608
let @env e = @rec(sess=sess,
603609
id_to_ty_item=id_to_ty_item,
604-
item_to_ty=item_to_ty);
610+
item_to_ty=item_to_ty,
611+
abi=ast.native_abi_cdecl);
605612

606613
fn convert(&@env e, @ast.item i) -> @env {
614+
auto abi = e.abi;
607615
alt (i.node) {
608616
case (ast.item_mod(_, _, _)) {
609617
// ignore item_mod, it has no type.
610618
}
611-
case (ast.item_native_mod(_, _, _)) {
619+
case (ast.item_native_mod(_, ?native_mod, _)) {
612620
// ignore item_native_mod, it has no type.
621+
abi = native_mod.abi;
613622
}
614623
case (_) {
615624
// This call populates the ty_table with the converted type of
616625
// the item in passing; we don't need to do anything else.
617626
ty_of_item(e.id_to_ty_item, e.item_to_ty, i);
618627
}
619628
}
620-
ret e;
629+
ret @rec(abi=abi with *e);
621630
}
622631

623632
fn convert_native(&@env e, @ast.native_item i) -> @env {
624-
ty_of_native_item(e.id_to_ty_item, e.item_to_ty, i);
633+
ty_of_native_item(e.id_to_ty_item, e.item_to_ty, i, e.abi);
625634
ret e;
626635
}
627636

@@ -1322,8 +1331,8 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
13221331
case (ty.ty_fn(?proto, _, _)) {
13231332
t_0 = plain_ty(ty.ty_fn(proto, arg_tys_0, rt_0));
13241333
}
1325-
case (ty.ty_native_fn(_, _)) {
1326-
t_0 = plain_ty(ty.ty_native_fn(arg_tys_0, rt_0));
1334+
case (ty.ty_native_fn(?abi, _, _)) {
1335+
t_0 = plain_ty(ty.ty_native_fn(abi, arg_tys_0, rt_0));
13271336
}
13281337
case (_) {
13291338
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 {
18071816
auto rt_1 = plain_ty(ty.ty_nil); // FIXME: typestate botch
18081817
alt (expr_ty(result._0).struct) {
18091818
case (ty.ty_fn(_,_,?rt)) { rt_1 = rt; }
1810-
case (ty.ty_native_fn(_,?rt)) { rt_1 = rt; }
1819+
case (ty.ty_native_fn(_, _, ?rt)) { rt_1 = rt; }
18111820
case (_) {
18121821
log "LHS of call expr didn't have a function type?!";
18131822
fail;

0 commit comments

Comments
 (0)