More typechecking for native types and the needed plumbing in codegen.
This commit is contained in:
parent
d4bf67dde6
commit
012fa69ea5
@ -263,7 +263,7 @@ tag item_ {
|
||||
type native_item = spanned[native_item_];
|
||||
tag native_item_ {
|
||||
native_item_ty(ident, def_id);
|
||||
native_item_fn(ident, fn_decl, vec[ty_param], def_id);
|
||||
native_item_fn(ident, fn_decl, vec[ty_param], def_id, ann);
|
||||
}
|
||||
|
||||
fn index_view_item(mod_index index, @view_item it) {
|
||||
@ -314,7 +314,7 @@ fn index_native_item(native_mod_index index, @native_item it) {
|
||||
case (ast.native_item_ty(?id, _)) {
|
||||
index.insert(id, it);
|
||||
}
|
||||
case (ast.native_item_fn(?id, _, _, _)) {
|
||||
case (ast.native_item_fn(?id, _, _, _, _)) {
|
||||
index.insert(id, it);
|
||||
}
|
||||
}
|
||||
|
@ -1693,7 +1693,8 @@ impure fn parse_item_native_fn(parser p, ast.effect eff) -> @ast.native_item {
|
||||
auto decl = parse_fn_decl(p, eff);
|
||||
auto hi = p.get_span();
|
||||
expect(p, token.SEMI);
|
||||
auto item = ast.native_item_fn(t._1, decl, t._2, p.next_def_id());
|
||||
auto item = ast.native_item_fn(t._1, decl, t._2, p.next_def_id(),
|
||||
ast.ann_none);
|
||||
ret @spanned(t._0, hi, item);
|
||||
}
|
||||
|
||||
|
@ -214,7 +214,7 @@ type ast_fold[ENV] =
|
||||
(fn(&ENV e, &span sp, ident ident,
|
||||
&ast.fn_decl decl,
|
||||
vec[ast.ty_param] ty_params,
|
||||
def_id id) -> @native_item) fold_native_item_fn,
|
||||
def_id id, ann a) -> @native_item) fold_native_item_fn,
|
||||
|
||||
(fn(&ENV e, &span sp, ident ident,
|
||||
&ast._mod m, def_id id) -> @item) fold_item_mod,
|
||||
@ -921,10 +921,10 @@ fn fold_native_item[ENV](&ENV env, ast_fold[ENV] fld,
|
||||
case (ast.native_item_ty(?ident, ?id)) {
|
||||
ret fld.fold_native_item_ty(env_, i.span, ident, id);
|
||||
}
|
||||
case (ast.native_item_fn(?ident, ?fn_decl, ?ty_params, ?id)) {
|
||||
case (ast.native_item_fn(?ident, ?fn_decl, ?ty_params, ?id, ?ann)) {
|
||||
auto d = fold_fn_decl[ENV](env_, fld, fn_decl);
|
||||
ret fld.fold_native_item_fn(env_, i.span, ident, d,
|
||||
ty_params, id);
|
||||
ty_params, id, ann);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1240,8 +1240,8 @@ fn identity_fold_item_fn[ENV](&ENV e, &span sp, ident i,
|
||||
fn identity_fold_native_item_fn[ENV](&ENV e, &span sp, ident i,
|
||||
&ast.fn_decl decl,
|
||||
vec[ast.ty_param] ty_params,
|
||||
def_id id) -> @native_item {
|
||||
ret @respan(sp, ast.native_item_fn(i, decl, ty_params, id));
|
||||
def_id id, ann a) -> @native_item {
|
||||
ret @respan(sp, ast.native_item_fn(i, decl, ty_params, id, a));
|
||||
}
|
||||
|
||||
fn identity_fold_item_mod[ENV](&ENV e, &span sp, ident i,
|
||||
@ -1454,7 +1454,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
|
||||
fold_item_const= bind identity_fold_item_const[ENV](_,_,_,_,_,_,_),
|
||||
fold_item_fn = bind identity_fold_item_fn[ENV](_,_,_,_,_,_,_),
|
||||
fold_native_item_fn =
|
||||
bind identity_fold_native_item_fn[ENV](_,_,_,_,_,_),
|
||||
bind identity_fold_native_item_fn[ENV](_,_,_,_,_,_,_),
|
||||
fold_item_mod = bind identity_fold_item_mod[ENV](_,_,_,_,_),
|
||||
fold_item_native_mod =
|
||||
bind identity_fold_item_native_mod[ENV](_,_,_,_,_),
|
||||
|
@ -233,7 +233,7 @@ fn lookup_name_wrapped(&env e, ast.ident i) -> option.t[tup(@env, def_wrap)] {
|
||||
case (ast.native_item_ty(_, ?id)) {
|
||||
ret def_wrap_other(ast.def_native_ty(id));
|
||||
}
|
||||
case (ast.native_item_fn(_, _, _, ?id)) {
|
||||
case (ast.native_item_fn(_, _, _, ?id, _)) {
|
||||
ret def_wrap_other(ast.def_native_fn(id));
|
||||
}
|
||||
}
|
||||
@ -381,7 +381,7 @@ fn lookup_name_wrapped(&env e, ast.ident i) -> option.t[tup(@env, def_wrap)] {
|
||||
|
||||
case (scope_native_item(?it)) {
|
||||
alt (it.node) {
|
||||
case (ast.native_item_fn(_, ?decl, ?ty_params, _)) {
|
||||
case (ast.native_item_fn(_, ?decl, ?ty_params, _, _)) {
|
||||
ret handle_fn_decl(i, decl, ty_params);
|
||||
}
|
||||
}
|
||||
|
@ -70,6 +70,7 @@ state type crate_ctxt = rec(session.session sess,
|
||||
hashmap[str, ValueRef] item_names,
|
||||
hashmap[ast.def_id, ValueRef] item_ids,
|
||||
hashmap[ast.def_id, @ast.item] items,
|
||||
hashmap[ast.def_id, @ast.native_item] native_items,
|
||||
hashmap[ast.def_id, @tag_info] tags,
|
||||
hashmap[ast.def_id, ValueRef] fn_pairs,
|
||||
hashmap[ast.def_id, ValueRef] consts,
|
||||
@ -440,6 +441,7 @@ fn type_of_fn(@crate_ctxt cx, vec[ty.arg] inputs, @ty.t output) -> TypeRef {
|
||||
|
||||
fn type_of_inner(@crate_ctxt cx, @ty.t t) -> TypeRef {
|
||||
alt (t.struct) {
|
||||
case (ty.ty_native) { ret T_ptr(T_i8()); }
|
||||
case (ty.ty_nil) { ret T_nil(); }
|
||||
case (ty.ty_bool) { ret T_bool(); }
|
||||
case (ty.ty_int) { ret T_int(); }
|
||||
@ -2429,6 +2431,12 @@ fn trans_path(@block_ctxt cx, &ast.path p, &option.t[ast.def] dopt,
|
||||
check (cx.fcx.ccx.consts.contains_key(did));
|
||||
ret lval_mem(cx, cx.fcx.ccx.consts.get(did));
|
||||
}
|
||||
case (ast.def_native_fn(?did)) {
|
||||
check (cx.fcx.ccx.native_items.contains_key(did));
|
||||
auto fn_item = cx.fcx.ccx.native_items.get(did);
|
||||
ret lval_generic_fn(cx, ty.native_item_ty(fn_item),
|
||||
did, ann);
|
||||
}
|
||||
case (_) {
|
||||
cx.fcx.ccx.sess.unimpl("def variant in trans");
|
||||
}
|
||||
@ -4053,6 +4061,18 @@ fn decl_fn_and_pair(@crate_ctxt cx,
|
||||
cx.fn_pairs.insert(id, gvar);
|
||||
}
|
||||
|
||||
fn collect_native_item(&@crate_ctxt cx, @ast.native_item i) -> @crate_ctxt {
|
||||
alt (i.node) {
|
||||
case (ast.native_item_fn(?name, _, _, ?fid, ?ann)) {
|
||||
cx.native_items.insert(fid, i);
|
||||
if (! cx.obj_methods.contains_key(fid)) {
|
||||
decl_fn_and_pair(cx, "fn", name, ann, fid);
|
||||
}
|
||||
}
|
||||
case (_) { /* fall through */ }
|
||||
}
|
||||
ret cx;
|
||||
}
|
||||
|
||||
fn collect_item(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {
|
||||
|
||||
@ -4101,7 +4121,8 @@ fn collect_items(@crate_ctxt cx, @ast.crate crate) {
|
||||
let fold.ast_fold[@crate_ctxt] fld =
|
||||
fold.new_identity_fold[@crate_ctxt]();
|
||||
|
||||
fld = @rec( update_env_for_item = bind collect_item(_,_)
|
||||
fld = @rec( update_env_for_item = bind collect_item(_,_),
|
||||
update_env_for_native_item = bind collect_native_item(_,_)
|
||||
with *fld );
|
||||
|
||||
fold.fold_crate[@crate_ctxt](cx, fld, crate);
|
||||
@ -4559,6 +4580,7 @@ fn trans_crate(session.session sess, @ast.crate crate, str output,
|
||||
item_names = new_str_hash[ValueRef](),
|
||||
item_ids = new_def_hash[ValueRef](),
|
||||
items = new_def_hash[@ast.item](),
|
||||
native_items = new_def_hash[@ast.native_item](),
|
||||
tags = new_def_hash[@tag_info](),
|
||||
fn_pairs = new_def_hash[ValueRef](),
|
||||
consts = new_def_hash[ValueRef](),
|
||||
|
@ -599,6 +599,22 @@ fn is_fn_ty(@t fty) -> bool {
|
||||
// Given an item, returns the associated type as well as a list of the IDs of
|
||||
// its type parameters.
|
||||
type ty_params_and_ty = tup(vec[ast.def_id], @t);
|
||||
fn native_item_ty(@ast.native_item it) -> ty_params_and_ty {
|
||||
auto ty_params;
|
||||
auto result_ty;
|
||||
alt (it.node) {
|
||||
case (ast.native_item_fn(_, _, ?tps, _, ?ann)) {
|
||||
ty_params = tps;
|
||||
result_ty = ann_to_type(ann);
|
||||
}
|
||||
}
|
||||
let vec[ast.def_id] ty_param_ids = vec();
|
||||
for (ast.ty_param tp in ty_params) {
|
||||
ty_param_ids += vec(tp.id);
|
||||
}
|
||||
ret tup(ty_param_ids, result_ty);
|
||||
}
|
||||
|
||||
fn item_ty(@ast.item it) -> ty_params_and_ty {
|
||||
let vec[ast.ty_param] ty_params;
|
||||
auto result_ty;
|
||||
|
@ -266,7 +266,7 @@ fn ty_params_of_item(@ast.item item) -> vec[ast.ty_param] {
|
||||
|
||||
fn ty_params_of_native_item(@ast.native_item item) -> vec[ast.ty_param] {
|
||||
alt (item.node) {
|
||||
case (ast.native_item_fn(_, _, ?p, _)) {
|
||||
case (ast.native_item_fn(_, _, ?p, _, _)) {
|
||||
ret p;
|
||||
}
|
||||
case (_) {
|
||||
@ -432,7 +432,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
|
||||
@ty_table item_to_ty,
|
||||
@ast.native_item it) -> @ty.t {
|
||||
alt (it.node) {
|
||||
case (ast.native_item_fn(?ident, ?fn_decl, ?params, ?def_id)) {
|
||||
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, _);
|
||||
@ -512,8 +512,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
|
||||
case (ast.native_item_ty(_, ?def_id)) {
|
||||
id_to_ty_item.insert(def_id, any_item_native(i));
|
||||
}
|
||||
case (ast.native_item_fn(_, _, _, ?def_id)) {
|
||||
id_to_ty_item.insert(def_id, any_item_native(i));
|
||||
case (_) {
|
||||
}
|
||||
}
|
||||
ret id_to_ty_item;
|
||||
@ -578,6 +577,16 @@ fn collect_item_types(session.session sess, @ast.crate crate)
|
||||
ret @fold.respan[ast.item_](sp, item);
|
||||
}
|
||||
|
||||
fn fold_native_item_fn(&@env e, &span sp, ast.ident i,
|
||||
&ast.fn_decl d, vec[ast.ty_param] ty_params,
|
||||
ast.def_id id, ast.ann a) -> @ast.native_item {
|
||||
check (e.item_to_ty.contains_key(id));
|
||||
auto ty = e.item_to_ty.get(id);
|
||||
auto item = ast.native_item_fn(i, d, ty_params, id,
|
||||
ast.ann_type(ty));
|
||||
ret @fold.respan[ast.native_item_](sp, item);
|
||||
}
|
||||
|
||||
fn get_ctor_obj_methods(@ty.t t) -> vec[method] {
|
||||
alt (t.struct) {
|
||||
case (ty.ty_fn(_,?tobj)) {
|
||||
@ -663,6 +672,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
|
||||
update_env_for_native_item = bind convert_native(_,_),
|
||||
fold_item_const = bind fold_item_const(_,_,_,_,_,_,_),
|
||||
fold_item_fn = bind fold_item_fn(_,_,_,_,_,_,_),
|
||||
fold_native_item_fn = bind fold_native_item_fn(_,_,_,_,_,_,_),
|
||||
fold_item_obj = bind fold_item_obj(_,_,_,_,_,_,_),
|
||||
fold_item_ty = bind fold_item_ty(_,_,_,_,_,_,_),
|
||||
fold_item_tag = bind fold_item_tag(_,_,_,_,_,_)
|
||||
|
Loading…
Reference in New Issue
Block a user