Skip to content

Commit 1d45e2e

Browse files
author
Rafael Avila de Espindola
committed
---
yaml --- r: 1396 b: refs/heads/master c: 07c7888 h: refs/heads/master v: v3
1 parent 87cdff9 commit 1d45e2e

File tree

4 files changed

+51
-18
lines changed

4 files changed

+51
-18
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: a63696dfe2bd47d34925a3ad44db9d2ede949e36
2+
refs/heads/master: 07c7888037cb74ca33459946145608a854aae6ed

trunk/src/comp/middle/trans.rs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,26 @@ fn type_of(@crate_ctxt cx, @ty.t t) -> TypeRef {
370370
ret llty;
371371
}
372372

373+
fn type_of_explicit_args(@crate_ctxt cx,
374+
vec[ty.arg] inputs) -> vec[TypeRef] {
375+
let vec[TypeRef] atys = vec();
376+
for (ty.arg arg in inputs) {
377+
if (ty.type_has_dynamic_size(arg.ty)) {
378+
check (arg.mode == ast.alias);
379+
atys += T_typaram_ptr();
380+
} else {
381+
let TypeRef t = type_of(cx, arg.ty);
382+
alt (arg.mode) {
383+
case (ast.alias) {
384+
t = T_ptr(t);
385+
}
386+
case (_) { /* fall through */ }
387+
}
388+
atys += t;
389+
}
390+
}
391+
ret atys;
392+
}
373393

374394
// NB: must keep 4 fns in sync:
375395
//
@@ -417,21 +437,7 @@ fn type_of_fn_full(@crate_ctxt cx,
417437
}
418438

419439
// ... then explicit args.
420-
for (ty.arg arg in inputs) {
421-
if (ty.type_has_dynamic_size(arg.ty)) {
422-
check (arg.mode == ast.alias);
423-
atys += T_typaram_ptr();
424-
} else {
425-
let TypeRef t = type_of(cx, arg.ty);
426-
alt (arg.mode) {
427-
case (ast.alias) {
428-
t = T_ptr(t);
429-
}
430-
case (_) { /* fall through */ }
431-
}
432-
atys += t;
433-
}
434-
}
440+
atys += type_of_explicit_args(cx, inputs);
435441

436442
ret T_fn(atys, llvm.LLVMVoidType());
437443
}
@@ -440,6 +446,12 @@ fn type_of_fn(@crate_ctxt cx, vec[ty.arg] inputs, @ty.t output) -> TypeRef {
440446
ret type_of_fn_full(cx, none[TypeRef], inputs, output);
441447
}
442448

449+
fn type_of_native_fn(@crate_ctxt cx, vec[ty.arg] inputs,
450+
@ty.t output) -> TypeRef {
451+
let vec[TypeRef] atys = type_of_explicit_args(cx, inputs);
452+
ret T_fn(atys, llvm.LLVMVoidType());
453+
}
454+
443455
fn type_of_inner(@crate_ctxt cx, @ty.t t) -> TypeRef {
444456
alt (t.struct) {
445457
case (ty.ty_native) { ret T_ptr(T_i8()); }
@@ -489,6 +501,9 @@ fn type_of_inner(@crate_ctxt cx, @ty.t t) -> TypeRef {
489501
case (ty.ty_fn(?args, ?out)) {
490502
ret T_fn_pair(type_of_fn(cx, args, out));
491503
}
504+
case (ty.ty_native_fn(?args, ?out)) {
505+
ret T_fn_pair(type_of_native_fn(cx, args, out));
506+
}
492507
case (ty.ty_obj(?meths)) {
493508
auto th = mk_type_handle();
494509
auto self_ty = llvm.LLVMResolveTypeHandle(th.llth);

trunk/src/comp/middle/ty.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ tag sty {
3838
ty_tup(vec[@t]);
3939
ty_rec(vec[field]);
4040
ty_fn(vec[arg], @t); // TODO: effect
41+
ty_native_fn(vec[arg], @t); // TODO: effect
4142
ty_obj(vec[method]);
4243
ty_var(int); // ephemeral type var
4344
ty_local(ast.def_id); // type of a local var
@@ -243,6 +244,10 @@ fn ty_to_str(&@t typ) -> str {
243244
s = fn_to_str(none[ast.ident], inputs, output);
244245
}
245246

247+
case (ty_native_fn(?inputs, ?output)) {
248+
s = fn_to_str(none[ast.ident], inputs, output);
249+
}
250+
246251
case (ty_obj(?meths)) {
247252
auto f = method_to_str;
248253
auto m = _vec.map[method,str](f, meths);

trunk/src/comp/middle/typeck.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,19 @@ fn ty_of_fn_decl(@ty_item_table id_to_ty_item,
300300
ret t_fn;
301301
}
302302

303+
fn ty_of_native_fn_decl(@ty_item_table id_to_ty_item,
304+
@ty_table item_to_ty,
305+
fn(&@ast.ty ast_ty) -> @ty.t convert,
306+
fn(&ast.arg a) -> arg ty_of_arg,
307+
&ast.fn_decl decl,
308+
ast.def_id def_id) -> @ty.t {
309+
auto input_tys = _vec.map[ast.arg,arg](ty_of_arg, decl.inputs);
310+
auto output_ty = convert(decl.output);
311+
auto t_fn = plain_ty(ty.ty_native_fn(input_tys, output_ty));
312+
item_to_ty.insert(def_id, t_fn);
313+
ret t_fn;
314+
}
315+
303316
fn collect_item_types(session.session sess, @ast.crate crate)
304317
-> tup(@ast.crate, @ty_table, @ty_item_table) {
305318

@@ -436,8 +449,8 @@ fn collect_item_types(session.session sess, @ast.crate crate)
436449
auto get = bind getter(id_to_ty_item, item_to_ty, _);
437450
auto convert = bind ast_ty_to_ty(get, _);
438451
auto f = bind ty_of_arg(id_to_ty_item, item_to_ty, _);
439-
ret ty_of_fn_decl(id_to_ty_item, item_to_ty, convert, f,
440-
fn_decl, def_id);
452+
ret ty_of_native_fn_decl(id_to_ty_item, item_to_ty, convert,
453+
f, fn_decl, def_id);
441454
}
442455
case (ast.native_item_ty(_, ?def_id)) {
443456
if (item_to_ty.contains_key(def_id)) {

0 commit comments

Comments
 (0)