Remove all uses of tuples from the compiler and stdlib

This commit is contained in:
Marijn Haverbeke 2011-07-26 14:06:02 +02:00
parent e123366bff
commit aea537779e
45 changed files with 759 additions and 723 deletions

View file

@ -128,7 +128,7 @@ fn default_native_lib_naming(session::session sess, bool static) ->
fn find_library_crate(&session::session sess, &ast::ident ident,
&(@ast::meta_item)[] metas,
&str[] library_search_paths)
-> option::t[tup(str, @u8[])] {
-> option::t[rec(str ident, @u8[] data)] {
attr::require_unique_names(sess, metas);
@ -161,8 +161,8 @@ fn find_library_crate(&session::session sess, &ast::ident ident,
fn find_library_crate_aux(&rec(str prefix, str suffix) nn, str crate_name,
&(@ast::meta_item)[] metas,
&str[] library_search_paths) ->
option::t[tup(str, @u8[])] {
&str[] library_search_paths)
-> option::t[rec(str ident, @u8[] data)] {
let str prefix = nn.prefix + crate_name;
// FIXME: we could probably use a 'glob' function in std::fs but it will
// be much easier to write once the unsafe module knows more about FFI
@ -188,7 +188,7 @@ fn find_library_crate_aux(&rec(str prefix, str suffix) nn, str crate_name,
cont;
}
log #fmt("found %s with matching metadata", path);
ret some(tup(path, cvec));
ret some(rec(ident=path, data=cvec));
}
case (_) { }
}
@ -219,7 +219,8 @@ fn get_metadata_section(str filename) -> option::t[@u8[]] {
fn load_library_crate(&session::session sess, span span,
&ast::ident ident, &(@ast::meta_item)[] metas,
&str[] library_search_paths) -> tup(str, @u8[]) {
&str[] library_search_paths)
-> rec(str ident, @u8[] data) {
alt (find_library_crate(sess, ident, metas, library_search_paths)) {
case (some(?t)) {
@ -237,8 +238,8 @@ fn resolve_crate(env e, ast::ident ident, (@ast::meta_item)[] metas,
auto cinfo = load_library_crate(e.sess, span, ident, metas,
e.library_search_paths);
auto cfilename = cinfo._0;
auto cdata = cinfo._1;
auto cfilename = cinfo.ident;
auto cdata = cinfo.data;
// Claim this crate number and cache it
auto cnum = e.next_crate_num;
@ -268,8 +269,8 @@ fn resolve_crate_deps(env e, &@u8[] cdata) -> cstore::cnum_map {
// numbers
auto cnum_map = new_int_hash[ast::crate_num]();
for (decoder::crate_dep dep in decoder::get_crate_deps(cdata)) {
auto extrn_cnum = dep._0;
auto cname = dep._1;
auto extrn_cnum = dep.cnum;
auto cname = dep.ident;
log #fmt("resolving dep %s", cname);
if (e.crate_cache.contains_key(cname)) {
log "already have it";

View file

@ -12,17 +12,13 @@ export get_tag_variants;
export get_type;
fn get_symbol(&cstore::cstore cstore, ast::def_id def) -> str {
auto cnum = def._0;
auto node_id = def._1;
auto cdata = cstore::get_crate_data(cstore, cnum).data;
ret decoder::get_symbol(cdata, node_id);
auto cdata = cstore::get_crate_data(cstore, def.crate).data;
ret decoder::get_symbol(cdata, def.node);
}
fn get_type_param_count(&cstore::cstore cstore, &ast::def_id def) -> uint {
auto cnum = def._0;
auto node_id = def._1;
auto cdata = cstore::get_crate_data(cstore, cnum).data;
ret decoder::get_type_param_count(cdata, node_id);
auto cdata = cstore::get_crate_data(cstore, def.crate).data;
ret decoder::get_type_param_count(cdata, def.node);
}
fn lookup_defs(&cstore::cstore cstore, ast::crate_num cnum,
@ -33,7 +29,7 @@ fn lookup_defs(&cstore::cstore cstore, ast::crate_num cnum,
fn get_tag_variants(ty::ctxt tcx, ast::def_id def) -> ty::variant_info[] {
auto cstore = tcx.sess.get_cstore();
auto cnum = def._0;
auto cnum = def.crate;
auto cdata = cstore::get_crate_data(cstore, cnum).data;
auto resolver = bind translate_def_id(tcx.sess, cnum, _);
ret decoder::get_tag_variants(cdata, def, tcx, resolver)
@ -41,7 +37,7 @@ fn get_tag_variants(ty::ctxt tcx, ast::def_id def) -> ty::variant_info[] {
fn get_type(ty::ctxt tcx, ast::def_id def) -> ty::ty_param_count_and_ty {
auto cstore = tcx.sess.get_cstore();
auto cnum = def._0;
auto cnum = def.crate;
auto cdata = cstore::get_crate_data(cstore, cnum).data;
auto resolver = bind translate_def_id(tcx.sess, cnum, _);
decoder::get_type(cdata, def, tcx, resolver)
@ -56,8 +52,8 @@ fn translate_def_id(&session::session sess,
ast::crate_num searched_crate,
&ast::def_id def_id) -> ast::def_id {
auto ext_cnum = def_id._0;
auto node_id = def_id._1;
auto ext_cnum = def_id.crate;
auto node_id = def_id.node;
assert searched_crate != ast::local_crate;
assert ext_cnum != ast::local_crate;
@ -72,7 +68,7 @@ fn translate_def_id(&session::session sess,
}
};
ret tup(local_cnum, node_id);
ret rec(crate=local_cnum, node=node_id);
}
// Local Variables:

View file

@ -78,8 +78,9 @@ fn have_crate_data(&cstore cstore, ast::crate_num cnum) -> bool {
ret p(cstore).metas.contains_key(cnum);
}
iter iter_crate_data(&cstore cstore) -> @tup(ast::crate_num, crate_metadata) {
for each (@tup(ast::crate_num, crate_metadata) kv
iter iter_crate_data(&cstore cstore)
-> @rec(ast::crate_num key, crate_metadata val) {
for each (@rec(ast::crate_num key, crate_metadata val) kv
in p(cstore).metas.items()) {
put kv;
}

View file

@ -102,8 +102,8 @@ fn item_type(&ebmlivec::doc item, ast::crate_num this_cnum,
// This item was defined in the crate we're searching if it's has the
// local crate number, otherwise we need to search a different crate
if (external_def_id._0 == ast::local_crate) {
ret tup(this_cnum, external_def_id._1);
if (external_def_id.crate == ast::local_crate) {
ret rec(crate=this_cnum, node=external_def_id.node);
} else {
ret extres(external_def_id);
}
@ -118,7 +118,7 @@ fn item_ty_param_count(&ebmlivec::doc item) -> uint {
let uint ty_param_count = 0u;
auto tp = tag_items_data_item_ty_param_count;
for each (ebmlivec::doc p in ebmlivec::tagged_docs(item, tp)) {
ty_param_count = ebmlivec::vint_at(ebmlivec::doc_data(p), 0u)._0;
ty_param_count = ebmlivec::vint_at(ebmlivec::doc_data(p), 0u).val;
}
ret ty_param_count;
}
@ -129,7 +129,7 @@ fn tag_variant_ids(&ebmlivec::doc item,
auto v = tag_items_data_item_variant;
for each (ebmlivec::doc p in ebmlivec::tagged_docs(item, v)) {
auto ext = parse_def_id(ebmlivec::doc_data(p));
ids += ~[tup(this_cnum, ext._1)];
ids += ~[rec(crate=this_cnum, node=ext.node)];
}
ret ids;
}
@ -162,9 +162,9 @@ fn lookup_defs(&@u8[] data, ast::crate_num cnum, &ast::ident[] path)
// FIXME doesn't yet handle re-exported externals
fn lookup_def(ast::crate_num cnum, @u8[] data, &ast::def_id did_)
-> ast::def {
auto item = lookup_item(did_._1, data);
auto item = lookup_item(did_.node, data);
auto kind_ch = item_kind(item);
auto did = tup(cnum, did_._1);
auto did = rec(crate=cnum, node=did_.node);
auto def =
alt (kind_ch as char) {
case ('c') { ast::def_const(did) }
@ -179,7 +179,7 @@ fn lookup_def(ast::crate_num cnum, @u8[] data, &ast::def_id did_)
case ('n') { ast::def_native_mod(did) }
case ('v') {
auto tid = variant_tag_id(item);
tid = tup(cnum, tid._1);
tid = rec(crate=cnum, node=tid.node);
ast::def_variant(tid, did)
}
};
@ -188,8 +188,8 @@ fn lookup_def(ast::crate_num cnum, @u8[] data, &ast::def_id did_)
fn get_type(@u8[] data, ast::def_id def, &ty::ctxt tcx,
&external_resolver extres) -> ty::ty_param_count_and_ty {
auto this_cnum = def._0;
auto node_id = def._1;
auto this_cnum = def.crate;
auto node_id = def.node;
auto item = lookup_item(node_id, data);
auto t = item_type(item, this_cnum, tcx, extres);
auto tp_count;
@ -198,7 +198,7 @@ fn get_type(@u8[] data, ast::def_id def, &ty::ctxt tcx,
if (has_ty_params) {
tp_count = item_ty_param_count(item);
} else { tp_count = 0u; }
ret tup(tp_count, t);
ret rec(count=tp_count, ty=t);
}
fn get_type_param_count(@u8[] data, ast::node_id id) -> uint {
@ -212,15 +212,15 @@ fn get_symbol(@u8[] data, ast::node_id id) -> str {
fn get_tag_variants(&@u8[] data, ast::def_id def,
&ty::ctxt tcx,
&external_resolver extres) -> ty::variant_info[] {
auto external_crate_id = def._0;
auto external_crate_id = def.crate;
auto data = cstore::get_crate_data(tcx.sess.get_cstore(),
external_crate_id).data;
auto items = ebmlivec::get_doc(ebmlivec::new_doc(data), tag_items);
auto item = find_item(def._1, items);
auto item = find_item(def.node, items);
let ty::variant_info[] infos = ~[];
auto variant_ids = tag_variant_ids(item, external_crate_id);
for (ast::def_id did in variant_ids) {
auto item = find_item(did._1, items);
auto item = find_item(did.node, items);
auto ctor_ty = item_type(item, external_crate_id, tcx, extres);
let ty::t[] arg_tys = ~[];
alt (ty::struct(tcx, ctor_ty)) {
@ -252,17 +252,17 @@ fn kind_has_type_params(u8 kind_ch) -> bool {
};
}
fn read_path(&ebmlivec::doc d) -> tup(str, uint) {
fn read_path(&ebmlivec::doc d) -> rec(str path, uint pos) {
auto desc = ebmlivec::doc_data(d);
auto pos = ebmlivec::be_uint_from_bytes(@desc, 0u, 4u);
auto pathbytes = ivec::slice[u8](desc, 4u, ivec::len[u8](desc));
auto path = str::unsafe_from_bytes_ivec(pathbytes);
ret tup(path, pos);
ret rec(path=path, pos=pos);
}
fn describe_def(&ebmlivec::doc items, ast::def_id id) -> str {
if (id._0 != 0) { ret "external"; }
ret item_kind_to_str(item_kind(find_item(id._1, items)));
if (id.crate != ast::local_crate) { ret "external"; }
ret item_kind_to_str(item_kind(find_item(id.node, items)));
}
fn item_kind_to_str(u8 kind) -> str {
@ -349,7 +349,7 @@ fn get_crate_attributes(@u8[] data) -> ast::attribute[] {
ret get_attributes(ebmlivec::new_doc(data));
}
type crate_dep = tup(ast::crate_num, str);
type crate_dep = rec(ast::crate_num cnum, str ident);
fn get_crate_deps(@u8[] data) -> crate_dep[] {
let crate_dep[] deps = ~[];
@ -360,7 +360,7 @@ fn get_crate_deps(@u8[] data) -> crate_dep[] {
ebmlivec::tagged_docs(depsdoc, tag_crate_dep)) {
auto depname =
str::unsafe_from_bytes_ivec(ebmlivec::doc_data(depdoc));
deps += ~[tup(crate_num, depname)];
deps += ~[rec(cnum=crate_num, ident=depname)];
crate_num += 1;
}
ret deps;
@ -370,7 +370,7 @@ fn list_crate_deps(@u8[] data, ioivec::writer out) {
out.write_str("=External Dependencies=\n");
for (crate_dep dep in get_crate_deps(data)) {
out.write_str(#fmt("%d %s\n", dep._0, dep._1));
out.write_str(#fmt("%d %s\n", dep.cnum, dep.ident));
}
out.write_str("\n");
@ -387,10 +387,10 @@ fn list_crate_items(&@u8[] bytes, &ebmlivec::doc md, ioivec::writer out) {
auto et = tag_index_buckets_bucket_elt;
for each (ebmlivec::doc elt in ebmlivec::tagged_docs(bucket, et)) {
auto data = read_path(elt);
auto def = ebmlivec::doc_at(bytes, data._1);
auto def = ebmlivec::doc_at(bytes, data.pos);
auto did_doc = ebmlivec::get_doc(def, tag_def_id);
auto did = parse_def_id(ebmlivec::doc_data(did_doc));
out.write_str(#fmt("%s (%s)\n", data._0,
out.write_str(#fmt("%s (%s)\n", data.path,
describe_def(items, did)));
}
}

View file

@ -37,9 +37,11 @@ fn encode_def_id(&ebmlivec::writer ebml_w, &def_id id) {
ebmlivec::end_tag(ebml_w);
}
type entry[T] = rec(T val, uint pos);
fn encode_tag_variant_paths(&ebmlivec::writer ebml_w, &variant[] variants,
&str[] path,
&mutable (tup(str, uint))[] index) {
&mutable (entry[str])[] index) {
for (variant variant in variants) {
add_to_index(ebml_w, path, index, variant.node.name);
ebmlivec::start_tag(ebml_w, tag_paths_data_item);
@ -50,14 +52,15 @@ fn encode_tag_variant_paths(&ebmlivec::writer ebml_w, &variant[] variants,
}
fn add_to_index(&ebmlivec::writer ebml_w, &str[] path,
&mutable (tup(str, uint))[] index, &str name) {
&mutable (entry[str])[] index, &str name) {
auto full_path = path + ~[name];
index += ~[tup(str::connect_ivec(full_path, "::"), ebml_w.writer.tell())];
index += ~[rec(val=str::connect_ivec(full_path, "::"),
pos=ebml_w.writer.tell())];
}
fn encode_native_module_item_paths(&ebmlivec::writer ebml_w,
&native_mod nmod, &str[] path,
&mutable (tup(str, uint))[] index) {
fn encode_native_module_item_paths
(&ebmlivec::writer ebml_w, &native_mod nmod, &str[] path,
&mutable (entry[str])[] index) {
for (@native_item nitem in nmod.items) {
add_to_index(ebml_w, path, index, nitem.ident);
ebmlivec::start_tag(ebml_w, tag_paths_data_item);
@ -69,7 +72,7 @@ fn encode_native_module_item_paths(&ebmlivec::writer ebml_w,
fn encode_module_item_paths(&ebmlivec::writer ebml_w, &_mod module,
&str[] path,
&mutable (tup(str, uint))[] index) {
&mutable (entry[str])[] index) {
for (@item it in module.items) {
if (!is_exported(it.ident, module)) { cont; }
alt (it.node) {
@ -149,8 +152,8 @@ fn encode_module_item_paths(&ebmlivec::writer ebml_w, &_mod module,
}
fn encode_item_paths(&ebmlivec::writer ebml_w, &@crate crate)
-> (tup(str, uint))[] {
let (tup(str, uint))[] index = ~[];
-> (entry[str])[] {
let (entry[str])[] index = ~[];
let str[] path = ~[];
ebmlivec::start_tag(ebml_w, tag_paths);
encode_module_item_paths(ebml_w, crate.node.module, path, index);
@ -166,7 +169,7 @@ fn encode_kind(&ebmlivec::writer ebml_w, u8 c) {
ebmlivec::end_tag(ebml_w);
}
fn def_to_str(&def_id did) -> str { ret #fmt("%d:%d", did._0, did._1); }
fn def_to_str(&def_id did) -> str { ret #fmt("%d:%d", did.crate, did.node); }
fn encode_type_param_count(&ebmlivec::writer ebml_w, &ty_param[] tps) {
ebmlivec::start_tag(ebml_w, tag_items_data_item_ty_param_count);
@ -212,10 +215,10 @@ fn encode_tag_id(&ebmlivec::writer ebml_w, &def_id id) {
fn encode_tag_variant_info(&@encode_ctxt ecx, &ebmlivec::writer ebml_w,
node_id id, &variant[] variants,
&mutable (tup(int, uint))[] index,
&mutable (entry[int])[] index,
&ty_param[] ty_params) {
for (variant variant in variants) {
index += ~[tup(variant.node.id, ebml_w.writer.tell())];
index += ~[rec(val=variant.node.id, pos=ebml_w.writer.tell())];
ebmlivec::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, local_def(variant.node.id));
encode_kind(ebml_w, 'v' as u8);
@ -232,7 +235,7 @@ fn encode_tag_variant_info(&@encode_ctxt ecx, &ebmlivec::writer ebml_w,
}
fn encode_info_for_item(@encode_ctxt ecx, &ebmlivec::writer ebml_w,
@item item, &mutable (tup(int, uint))[] index) {
@item item, &mutable (entry[int])[] index) {
alt (item.node) {
case (item_const(_, _)) {
ebmlivec::start_tag(ebml_w, tag_items_data_item);
@ -301,7 +304,7 @@ fn encode_info_for_item(@encode_ctxt ecx, &ebmlivec::writer ebml_w,
encode_symbol(ecx, ebml_w, item.id);
ebmlivec::end_tag(ebml_w);
index += ~[tup(ctor_id, ebml_w.writer.tell())];
index += ~[rec(val=ctor_id, pos=ebml_w.writer.tell())];
ebmlivec::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, local_def(ctor_id));
encode_kind(ebml_w, 'f' as u8);
@ -320,7 +323,7 @@ fn encode_info_for_item(@encode_ctxt ecx, &ebmlivec::writer ebml_w,
encode_type(ecx, ebml_w, ty::ty_fn_ret(ecx.ccx.tcx, fn_ty));
ebmlivec::end_tag(ebml_w);
index += ~[tup(ctor_id, ebml_w.writer.tell())];
index += ~[rec(val=ctor_id, pos=ebml_w.writer.tell())];
ebmlivec::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, local_def(ctor_id));
encode_kind(ebml_w, 'f' as u8);
@ -355,18 +358,18 @@ fn encode_info_for_native_item(&@encode_ctxt ecx, &ebmlivec::writer ebml_w,
}
fn encode_info_for_items(&@encode_ctxt ecx, &ebmlivec::writer ebml_w)
-> (tup(int, uint))[] {
let (tup(int, uint))[] index = ~[];
-> (entry[int])[] {
let (entry[int])[] index = ~[];
ebmlivec::start_tag(ebml_w, tag_items_data);
for each (@tup(node_id, middle::ast_map::ast_node) kvp in
ecx.ccx.ast_map.items()) {
alt (kvp._1) {
for each (@rec(node_id key, middle::ast_map::ast_node val) kvp
in ecx.ccx.ast_map.items()) {
alt (kvp.val) {
case (middle::ast_map::node_item(?i)) {
index += ~[tup(kvp._0, ebml_w.writer.tell())];
index += ~[rec(val=kvp.key, pos=ebml_w.writer.tell())];
encode_info_for_item(ecx, ebml_w, i, index);
}
case (middle::ast_map::node_native_item(?i)) {
index += ~[tup(kvp._0, ebml_w.writer.tell())];
index += ~[rec(val=kvp.key, pos=ebml_w.writer.tell())];
encode_info_for_native_item(ecx, ebml_w, i);
}
case (_) {}
@ -379,35 +382,35 @@ fn encode_info_for_items(&@encode_ctxt ecx, &ebmlivec::writer ebml_w)
// Path and definition ID indexing
fn create_index[T](&(tup(T, uint))[] index, fn(&T) -> uint hash_fn)
-> (@(tup(T, uint))[])[] {
let (@mutable (tup(T,uint))[])[] buckets = ~[];
fn create_index[T](&(entry[T])[] index, fn(&T) -> uint hash_fn)
-> (@(entry[T])[])[] {
let (@mutable (entry[T])[])[] buckets = ~[];
for each (uint i in uint::range(0u, 256u)) { buckets += ~[@mutable ~[]]; }
for (tup(T, uint) elt in index) {
auto h = hash_fn(elt._0);
for (entry[T] elt in index) {
auto h = hash_fn(elt.val);
*(buckets.(h % 256u)) += ~[elt];
}
auto buckets_frozen = ~[];
for (@mutable (tup(T, uint))[] bucket in buckets) {
for (@mutable (entry[T])[] bucket in buckets) {
buckets_frozen += ~[@*bucket];
}
ret buckets_frozen;
}
fn encode_index[T](&ebmlivec::writer ebml_w, &(@(tup(T, uint))[])[] buckets,
fn encode_index[T](&ebmlivec::writer ebml_w, &(@(entry[T])[])[] buckets,
fn(&ioivec::writer, &T) write_fn) {
auto writer = ioivec::new_writer_(ebml_w.writer);
ebmlivec::start_tag(ebml_w, tag_index);
let uint[] bucket_locs = ~[];
ebmlivec::start_tag(ebml_w, tag_index_buckets);
for (@(tup(T, uint))[] bucket in buckets) {
for (@(entry[T])[] bucket in buckets) {
bucket_locs += ~[ebml_w.writer.tell()];
ebmlivec::start_tag(ebml_w, tag_index_buckets_bucket);
for (tup(T, uint) elt in *bucket) {
for (entry[T] elt in *bucket) {
ebmlivec::start_tag(ebml_w, tag_index_buckets_bucket_elt);
writer.write_be_uint(elt._1, 4u);
write_fn(writer, elt._0);
writer.write_be_uint(elt.pos, 4u);
write_fn(writer, elt.val);
ebmlivec::end_tag(ebml_w);
}
ebmlivec::end_tag(ebml_w);
@ -527,28 +530,28 @@ fn synthesize_crate_attrs(&@encode_ctxt ecx,
fn encode_crate_deps(&ebmlivec::writer ebml_w, &cstore::cstore cstore) {
fn get_ordered_names(&cstore::cstore cstore) -> str[] {
type hashkv = @tup(crate_num, cstore::crate_metadata);
type numname = tup(crate_num, str);
type hashkv = @rec(crate_num key, cstore::crate_metadata val);
type numname = rec(crate_num crate, str ident);
// Pull the cnums and names out of cstore
let numname[mutable] pairs = ~[mutable];
for each (hashkv hashkv in cstore::iter_crate_data(cstore)) {
pairs += ~[mutable tup(hashkv._0, hashkv._1.name)];
pairs += ~[mutable rec(crate=hashkv.key, ident=hashkv.val.name)];
}
// Sort by cnum
fn lteq(&numname kv1, &numname kv2) -> bool { kv1._0 <= kv2._0 }
fn lteq(&numname kv1, &numname kv2) -> bool { kv1.crate <= kv2.crate }
std::sort::ivector::quick_sort(lteq, pairs);
// Sanity-check the crate numbers
auto expected_cnum = 1;
for (numname n in pairs) {
assert n._0 == expected_cnum;
assert n.crate == expected_cnum;
expected_cnum += 1;
}
// Return just the names
fn name(&numname kv) -> str { kv._1 }
fn name(&numname kv) -> str { kv.ident }
// mutable -> immutable hack for ivec::map
auto immpairs = ivec::slice(pairs, 0u, ivec::len(pairs));
ret ivec::map(name, immpairs);

View file

@ -249,13 +249,13 @@ fn parse_ty(@pstate st, str_def sd) -> ty::t {
}
case ('F') {
auto func = parse_ty_fn(st, sd);
ret ty::mk_fn(st.tcx, ast::proto_fn, func._0, func._1, func._2,
func._3);
ret ty::mk_fn(st.tcx, ast::proto_fn, func.args, func.ty, func.cf,
func.cs);
}
case ('W') {
auto func = parse_ty_fn(st, sd);
ret ty::mk_fn(st.tcx, ast::proto_iter, func._0, func._1, func._2,
func._3);
ret ty::mk_fn(st.tcx, ast::proto_iter, func.args, func.ty,
func.cf, func.cs);
}
case ('N') {
auto abi;
@ -267,7 +267,7 @@ fn parse_ty(@pstate st, str_def sd) -> ty::t {
case ('s') { abi = ast::native_abi_x86stdcall; }
}
auto func = parse_ty_fn(st, sd);
ret ty::mk_native_fn(st.tcx, abi, func._0, func._1);
ret ty::mk_native_fn(st.tcx, abi, func.args, func.ty);
}
case ('O') {
assert (next(st) as char == '[');
@ -286,10 +286,10 @@ fn parse_ty(@pstate st, str_def sd) -> ty::t {
methods +=
~[rec(proto=proto,
ident=name,
inputs=func._0,
output=func._1,
cf=func._2,
constrs=func._3)];
inputs=func.args,
output=func.ty,
cf=func.cf,
constrs=func.cs)];
}
st.pos += 1u;
ret ty::mk_obj(st.tcx, methods);
@ -314,12 +314,13 @@ fn parse_ty(@pstate st, str_def sd) -> ty::t {
assert (next(st) as char == ':');
auto len = parse_hex(st);
assert (next(st) as char == '#');
alt (st.tcx.rcache.find(tup(st.crate, pos, len))) {
alt (st.tcx.rcache.find(rec(cnum=st.crate, pos=pos, len=len))) {
case (some(?tt)) { ret tt; }
case (none) {
auto ps = @rec(pos=pos, len=len with *st);
auto tt = parse_ty(ps, sd);
st.tcx.rcache.insert(tup(st.crate, pos, len), tt);
st.tcx.rcache.insert(rec(cnum=st.crate, pos=pos, len=len),
tt);
ret tt;
}
}
@ -385,7 +386,7 @@ fn parse_hex(@pstate st) -> uint {
}
fn parse_ty_fn(@pstate st, str_def sd) ->
tup(ty::arg[], ty::t, ast::controlflow, (@ty::constr)[]) {
rec(ty::arg[] args, ty::t ty, ast::controlflow cf, (@ty::constr)[] cs) {
assert (next(st) as char == '[');
let ty::arg[] inputs = ~[];
while (peek(st) as char != ']') {
@ -404,9 +405,12 @@ fn parse_ty_fn(@pstate st, str_def sd) ->
auto cs = parse_constrs(st, sd);
alt (parse_ty_or_bang(st, sd)) {
case (a_bang) {
ret tup(inputs, ty::mk_bot(st.tcx), ast::noreturn, cs);
ret rec(args=inputs, ty=ty::mk_bot(st.tcx),
cf=ast::noreturn, cs=cs);
}
case (a_ty(?t)) {
ret rec(args=inputs, ty=t, cf=ast::return, cs=cs);
}
case (a_ty(?t)) { ret tup(inputs, t, ast::return, cs); }
}
}
@ -431,8 +435,8 @@ fn parse_def_id(&u8[] buf) -> ast::def_id {
for (u8 b in def_part) { def_part_vec += [b]; }
auto crate_num = uint::parse_buf(crate_part_vec, 10u) as int;
auto def_id = uint::parse_buf(def_part_vec, 10u) as int;
ret tup(crate_num, def_id);
auto def_num = uint::parse_buf(def_part_vec, 10u) as int;
ret rec(crate=crate_num, node=def_num);
}
//