Reformat for new syntax
diff --git a/src/comp/back/abi.rs b/src/comp/back/abi.rs
index 6d0098f..fc6385d 100644
--- a/src/comp/back/abi.rs
+++ b/src/comp/back/abi.rs
@@ -2,126 +2,126 @@
// FIXME: Most of these should be uints.
-const int rc_base_field_refcnt = 0;
+const rc_base_field_refcnt: int = 0;
// FIXME: import from std::dbg when imported consts work.
-const uint const_refcount = 0x7bad_face_u;
+const const_refcount: uint = 0x7bad_face_u;
-const int task_field_refcnt = 0;
+const task_field_refcnt: int = 0;
-const int task_field_stk = 2;
+const task_field_stk: int = 2;
-const int task_field_runtime_sp = 3;
+const task_field_runtime_sp: int = 3;
-const int task_field_rust_sp = 4;
+const task_field_rust_sp: int = 4;
-const int task_field_gc_alloc_chain = 5;
+const task_field_gc_alloc_chain: int = 5;
-const int task_field_dom = 6;
+const task_field_dom: int = 6;
-const int n_visible_task_fields = 7;
+const n_visible_task_fields: int = 7;
-const int dom_field_interrupt_flag = 1;
+const dom_field_interrupt_flag: int = 1;
-const int frame_glue_fns_field_mark = 0;
+const frame_glue_fns_field_mark: int = 0;
-const int frame_glue_fns_field_drop = 1;
+const frame_glue_fns_field_drop: int = 1;
-const int frame_glue_fns_field_reloc = 2;
+const frame_glue_fns_field_reloc: int = 2;
-const int box_rc_field_refcnt = 0;
+const box_rc_field_refcnt: int = 0;
-const int box_rc_field_body = 1;
+const box_rc_field_body: int = 1;
-const int general_code_alignment = 16;
+const general_code_alignment: int = 16;
-const int vec_elt_rc = 0;
+const vec_elt_rc: int = 0;
-const int vec_elt_alloc = 1;
+const vec_elt_alloc: int = 1;
-const int vec_elt_fill = 2;
+const vec_elt_fill: int = 2;
-const int vec_elt_pad = 3;
+const vec_elt_pad: int = 3;
-const int vec_elt_data = 4;
+const vec_elt_data: int = 4;
-const int tydesc_field_first_param = 0;
+const tydesc_field_first_param: int = 0;
-const int tydesc_field_size = 1;
+const tydesc_field_size: int = 1;
-const int tydesc_field_align = 2;
+const tydesc_field_align: int = 2;
-const int tydesc_field_copy_glue = 3;
+const tydesc_field_copy_glue: int = 3;
-const int tydesc_field_drop_glue = 4;
+const tydesc_field_drop_glue: int = 4;
-const int tydesc_field_free_glue = 5;
+const tydesc_field_free_glue: int = 5;
-const int tydesc_field_sever_glue = 6;
+const tydesc_field_sever_glue: int = 6;
-const int tydesc_field_mark_glue = 7;
+const tydesc_field_mark_glue: int = 7;
// FIXME no longer used in rustc, drop when rustboot is gone
-const int tydesc_field_obj_drop_glue = 8;
+const tydesc_field_obj_drop_glue: int = 8;
-const int tydesc_field_is_stateful = 9;
+const tydesc_field_is_stateful: int = 9;
-const int tydesc_field_cmp_glue = 10;
+const tydesc_field_cmp_glue: int = 10;
-const int n_tydesc_fields = 11;
+const n_tydesc_fields: int = 11;
-const uint cmp_glue_op_eq = 0u;
+const cmp_glue_op_eq: uint = 0u;
-const uint cmp_glue_op_lt = 1u;
+const cmp_glue_op_lt: uint = 1u;
-const uint cmp_glue_op_le = 2u;
+const cmp_glue_op_le: uint = 2u;
-const int obj_field_vtbl = 0;
+const obj_field_vtbl: int = 0;
-const int obj_field_box = 1;
+const obj_field_box: int = 1;
-const int obj_body_elt_tydesc = 0;
+const obj_body_elt_tydesc: int = 0;
-const int obj_body_elt_typarams = 1;
+const obj_body_elt_typarams: int = 1;
-const int obj_body_elt_fields = 2;
+const obj_body_elt_fields: int = 2;
// The base object to which an anonymous object is attached.
-const int obj_body_elt_with_obj = 3;
+const obj_body_elt_with_obj: int = 3;
// The two halves of a closure: code and environment.
-const int fn_field_code = 0;
-const int fn_field_box = 1;
+const fn_field_code: int = 0;
+const fn_field_box: int = 1;
-const int closure_elt_tydesc = 0;
+const closure_elt_tydesc: int = 0;
-const int closure_elt_target = 1;
+const closure_elt_target: int = 1;
-const int closure_elt_bindings = 2;
+const closure_elt_bindings: int = 2;
-const int closure_elt_ty_params = 3;
+const closure_elt_ty_params: int = 3;
-const uint ivec_default_length = 4u;
+const ivec_default_length: uint = 4u;
-const uint ivec_elt_len = 0u;
+const ivec_elt_len: uint = 0u;
-const uint ivec_elt_alen = 1u;
+const ivec_elt_alen: uint = 1u;
-const uint ivec_elt_elems = 2u;
+const ivec_elt_elems: uint = 2u;
-const uint ivec_heap_stub_elt_zero = 0u;
+const ivec_heap_stub_elt_zero: uint = 0u;
-const uint ivec_heap_stub_elt_alen = 1u;
+const ivec_heap_stub_elt_alen: uint = 1u;
-const uint ivec_heap_stub_elt_ptr = 2u;
+const ivec_heap_stub_elt_ptr: uint = 2u;
-const uint ivec_heap_elt_len = 0u;
+const ivec_heap_elt_len: uint = 0u;
-const uint ivec_heap_elt_elems = 1u;
+const ivec_heap_elt_elems: uint = 1u;
-const int worst_case_glue_call_args = 7;
+const worst_case_glue_call_args: int = 7;
fn memcpy_glue_name() -> str { ret "rust_memcpy_glue"; }
diff --git a/src/comp/back/link.rs b/src/comp/back/link.rs
index 2b61ca6..20cf266 100644
--- a/src/comp/back/link.rs
+++ b/src/comp/back/link.rs
@@ -31,40 +31,40 @@
output_type_exe;
}
-fn llvm_err(session::session sess, str msg) {
- auto buf = llvm::LLVMRustGetLastError();
- if (buf as uint == 0u) {
+fn llvm_err(sess: session::session, msg: str) {
+ let buf = llvm::LLVMRustGetLastError();
+ if buf as uint == 0u {
sess.fatal(msg);
} else { sess.fatal(msg + ": " + str::str_from_cstr(buf)); }
fail;
}
-fn link_intrinsics(session::session sess, ModuleRef llmod) {
- auto path = fs::connect(sess.get_opts().sysroot, "lib/intrinsics.bc");
- auto membuf =
+fn link_intrinsics(sess: session::session, llmod: ModuleRef) {
+ let path = fs::connect(sess.get_opts().sysroot, "lib/intrinsics.bc");
+ let membuf =
llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(str::buf(path));
- if (membuf as uint == 0u) {
+ if membuf as uint == 0u {
llvm_err(sess, "installation problem: couldn't open " + path);
fail;
}
- auto llintrinsicsmod = llvm::LLVMRustParseBitcode(membuf);
+ let llintrinsicsmod = llvm::LLVMRustParseBitcode(membuf);
llvm::LLVMDisposeMemoryBuffer(membuf);
- if (llintrinsicsmod as uint == 0u) {
+ if llintrinsicsmod as uint == 0u {
llvm_err(sess, "installation problem: couldn't parse intrinsics.bc");
fail;
}
- auto linkres = llvm::LLVMLinkModules(llmod, llintrinsicsmod);
+ let linkres = llvm::LLVMLinkModules(llmod, llintrinsicsmod);
llvm::LLVMDisposeModule(llintrinsicsmod);
- if (linkres == False) {
+ if linkres == False {
llvm_err(sess, "couldn't link the module with the intrinsics");
fail;
}
}
mod write {
- fn is_object_or_assembly_or_exe(output_type ot) -> bool {
- if (ot == output_type_assembly || ot == output_type_object ||
- ot == output_type_exe) {
+ fn is_object_or_assembly_or_exe(ot: output_type) -> bool {
+ if ot == output_type_assembly || ot == output_type_object ||
+ ot == output_type_exe {
ret true;
}
ret false;
@@ -72,20 +72,20 @@
// Decides what to call an intermediate file, given the name of the output
// and the extension to use.
- fn mk_intermediate_name(str output_path, str extension) -> str {
- auto dot_pos = str::index(output_path, '.' as u8);
- auto stem;
- if (dot_pos < 0) {
+ fn mk_intermediate_name(output_path: str, extension: str) -> str {
+ let dot_pos = str::index(output_path, '.' as u8);
+ let stem;
+ if dot_pos < 0 {
stem = output_path;
} else { stem = str::substr(output_path, 0u, dot_pos as uint); }
ret stem + "." + extension;
}
- fn run_passes(session::session sess, ModuleRef llmod, str output) {
- auto opts = sess.get_opts();
- if (opts.time_llvm_passes) { llvm::LLVMRustEnableTimePasses(); }
+ fn run_passes(sess: session::session, llmod: ModuleRef, output: str) {
+ let opts = sess.get_opts();
+ if opts.time_llvm_passes { llvm::LLVMRustEnableTimePasses(); }
link_intrinsics(sess, llmod);
- auto pm = mk_pass_manager();
- auto td = mk_target_data(x86::get_data_layout());
+ let pm = mk_pass_manager();
+ let td = mk_target_data(x86::get_data_layout());
llvm::LLVMAddTargetData(td.lltd, pm.llpm);
// TODO: run the linter here also, once there are llvm-c bindings for
// it.
@@ -93,23 +93,21 @@
// Generate a pre-optimization intermediate file if -save-temps was
// specified.
- if (opts.save_temps) {
- alt (opts.output_type) {
- case (output_type_bitcode) {
- if (opts.optimize != 0u) {
- auto filename =
- mk_intermediate_name(output, "no-opt.bc");
- llvm::LLVMWriteBitcodeToFile(llmod,
- str::buf(filename));
- }
- }
- case (_) {
- auto filename = mk_intermediate_name(output, "bc");
+ if opts.save_temps {
+ alt opts.output_type {
+ output_type_bitcode. {
+ if opts.optimize != 0u {
+ let filename = mk_intermediate_name(output, "no-opt.bc");
llvm::LLVMWriteBitcodeToFile(llmod, str::buf(filename));
}
+ }
+ _ {
+ let filename = mk_intermediate_name(output, "bc");
+ llvm::LLVMWriteBitcodeToFile(llmod, str::buf(filename));
+ }
}
}
- if (opts.verify) { llvm::LLVMAddVerifierPass(pm.llpm); }
+ if opts.verify { llvm::LLVMAddVerifierPass(pm.llpm); }
// FIXME: This is mostly a copy of the bits of opt's -O2 that are
// available in the C api.
// FIXME2: We might want to add optimization levels like -O1, -O2,
@@ -117,69 +115,59 @@
// FIXME3: Should we expose and use the pass lists used by the opt
// tool?
- if (opts.optimize != 0u) {
- auto fpm = mk_pass_manager();
+ if opts.optimize != 0u {
+ let fpm = mk_pass_manager();
llvm::LLVMAddTargetData(td.lltd, fpm.llpm);
llvm::LLVMAddStandardFunctionPasses(fpm.llpm, 2u);
llvm::LLVMRunPassManager(fpm.llpm, llmod);
- let uint threshold = 225u;
- if (opts.optimize == 3u) { threshold = 275u; }
+ let threshold: uint = 225u;
+ if opts.optimize == 3u { threshold = 275u; }
llvm::LLVMAddStandardModulePasses(pm.llpm,
// optimization level
opts.optimize,
False, // optimize for size
- True, // unit-at-a-time
- True, // unroll loops
- True, // simplify lib calls
- threshold); // inline threshold
+ True, // unit-at-a-time
+ True, // unroll loops
+ True, // simplify lib calls
+ threshold); // inline threshold
}
- if (opts.verify) { llvm::LLVMAddVerifierPass(pm.llpm); }
- if (is_object_or_assembly_or_exe(opts.output_type)) {
- let int LLVMAssemblyFile = 0;
- let int LLVMObjectFile = 1;
- let int LLVMOptNone = 0; // -O0
- let int LLVMOptLess = 1; // -O1
- let int LLVMOptDefault = 2; // -O2, -Os
- let int LLVMOptAggressive = 3; // -O3
+ if opts.verify { llvm::LLVMAddVerifierPass(pm.llpm); }
+ if is_object_or_assembly_or_exe(opts.output_type) {
+ let LLVMAssemblyFile: int = 0;
+ let LLVMObjectFile: int = 1;
+ let LLVMOptNone: int = 0; // -O0
+ let LLVMOptLess: int = 1; // -O1
+ let LLVMOptDefault: int = 2; // -O2, -Os
+ let LLVMOptAggressive: int = 3; // -O3
- auto CodeGenOptLevel;
- alt (opts.optimize) {
- case (0u) {
- CodeGenOptLevel = LLVMOptNone;
- }
- case (1u) {
- CodeGenOptLevel = LLVMOptLess;
- }
- case (2u) {
- CodeGenOptLevel = LLVMOptDefault;
- }
- case (3u) {
- CodeGenOptLevel = LLVMOptAggressive;
- }
- case (_) {
- fail;
- }
+ let CodeGenOptLevel;
+ alt opts.optimize {
+ 0u { CodeGenOptLevel = LLVMOptNone; }
+ 1u { CodeGenOptLevel = LLVMOptLess; }
+ 2u { CodeGenOptLevel = LLVMOptDefault; }
+ 3u { CodeGenOptLevel = LLVMOptAggressive; }
+ _ { fail; }
}
- auto FileType;
- if (opts.output_type == output_type_object ||
- opts.output_type == output_type_exe) {
+ let FileType;
+ if opts.output_type == output_type_object ||
+ opts.output_type == output_type_exe {
FileType = LLVMObjectFile;
} else { FileType = LLVMAssemblyFile; }
// Write optimized bitcode if --save-temps was on.
- if (opts.save_temps) {
+ if opts.save_temps {
// Always output the bitcode file with --save-temps
- auto filename = mk_intermediate_name(output, "opt.bc");
+ let filename = mk_intermediate_name(output, "opt.bc");
llvm::LLVMRunPassManager(pm.llpm, llmod);
llvm::LLVMWriteBitcodeToFile(llmod, str::buf(filename));
pm = mk_pass_manager();
// Save the assembly file if -S is used
- if (opts.output_type == output_type_assembly) {
- auto triple = x86::get_target_triple();
+ if opts.output_type == output_type_assembly {
+ let triple = x86::get_target_triple();
llvm::LLVMRustWriteOutputFile(pm.llpm, llmod,
str::buf(triple),
str::buf(output),
@@ -187,11 +175,12 @@
CodeGenOptLevel);
}
+
// Save the object file for -c or --save-temps alone
// This .o is needed when an exe is built
- if (opts.output_type == output_type_object ||
- opts.output_type == output_type_exe) {
- auto triple = x86::get_target_triple();
+ if opts.output_type == output_type_object ||
+ opts.output_type == output_type_exe {
+ let triple = x86::get_target_triple();
llvm::LLVMRustWriteOutputFile(pm.llpm, llmod,
str::buf(triple),
str::buf(output),
@@ -202,7 +191,7 @@
// If we aren't saving temps then just output the file
// type corresponding to the '-c' or '-S' flag used
- auto triple = x86::get_target_triple();
+ let triple = x86::get_target_triple();
llvm::LLVMRustWriteOutputFile(pm.llpm, llmod,
str::buf(triple),
str::buf(output), FileType,
@@ -211,7 +200,7 @@
// Clean up and return
llvm::LLVMDisposeModule(llmod);
- if (opts.time_llvm_passes) { llvm::LLVMRustPrintPassTimings(); }
+ if opts.time_llvm_passes { llvm::LLVMRustPrintPassTimings(); }
ret;
}
// If only a bitcode file is asked for by using the '--emit-llvm'
@@ -220,7 +209,7 @@
llvm::LLVMRunPassManager(pm.llpm, llmod);
llvm::LLVMWriteBitcodeToFile(llmod, str::buf(output));
llvm::LLVMDisposeModule(llmod);
- if (opts.time_llvm_passes) { llvm::LLVMRustPrintPassTimings(); }
+ if opts.time_llvm_passes { llvm::LLVMRustPrintPassTimings(); }
}
}
@@ -276,132 +265,128 @@
*
*/
-type link_meta = rec(str name,
- str vers,
- str extras_hash);
+type link_meta = {name: str, vers: str, extras_hash: str};
-fn build_link_meta(&session::session sess, &ast::crate c,
- &str output, sha1 sha) -> link_meta {
+fn build_link_meta(sess: &session::session, c: &ast::crate, output: &str,
+ sha: sha1) -> link_meta {
- type provided_metas = rec(option::t[str] name,
- option::t[str] vers,
- (@ast::meta_item)[] cmh_items);
+ type provided_metas =
+ {name: option::t[str],
+ vers: option::t[str],
+ cmh_items: (@ast::meta_item)[]};
- fn provided_link_metas(&session::session sess,
- &ast::crate c) -> provided_metas {
- let option::t[str] name = none;
- let option::t[str] vers = none;
- let (@ast::meta_item)[] cmh_items = ~[];
- auto linkage_metas = attr::find_linkage_metas(c.node.attrs);
+ fn provided_link_metas(sess: &session::session, c: &ast::crate) ->
+ provided_metas {
+ let name: option::t[str] = none;
+ let vers: option::t[str] = none;
+ let cmh_items: (@ast::meta_item)[] = ~[];
+ let linkage_metas = attr::find_linkage_metas(c.node.attrs);
attr::require_unique_names(sess, linkage_metas);
- for (@ast::meta_item meta in linkage_metas) {
- if (attr::get_meta_item_name(meta) == "name") {
- alt (attr::get_meta_item_value_str(meta)) {
- case (some(?v)) { name = some(v); }
- case (none) { cmh_items += ~[meta]; }
+ for meta: @ast::meta_item in linkage_metas {
+ if attr::get_meta_item_name(meta) == "name" {
+ alt attr::get_meta_item_value_str(meta) {
+ some(v) { name = some(v); }
+ none. { cmh_items += ~[meta]; }
}
} else if (attr::get_meta_item_name(meta) == "vers") {
- alt (attr::get_meta_item_value_str(meta)) {
- case (some(?v)) { vers = some(v); }
- case (none) { cmh_items += ~[meta]; }
+ alt attr::get_meta_item_value_str(meta) {
+ some(v) { vers = some(v); }
+ none. { cmh_items += ~[meta]; }
}
- } else {
- cmh_items += ~[meta];
- }
+ } else { cmh_items += ~[meta]; }
}
- ret rec(name = name,
- vers = vers,
- cmh_items = cmh_items);
+ ret {name: name, vers: vers, cmh_items: cmh_items};
}
// This calculates CMH as defined above
- fn crate_meta_extras_hash(sha1 sha, &ast::crate crate,
- &provided_metas metas) -> str {
- fn len_and_str(&str s) -> str {
+ fn crate_meta_extras_hash(sha: sha1, crate: &ast::crate,
+ metas: &provided_metas) -> str {
+ fn len_and_str(s: &str) -> str {
ret #fmt("%u_%s", str::byte_len(s), s);
}
- fn len_and_str_lit(&ast::lit l) -> str {
+ fn len_and_str_lit(l: &ast::lit) -> str {
ret len_and_str(pprust::lit_to_str(@l));
}
- auto cmh_items = attr::sort_meta_items(metas.cmh_items);
+ let cmh_items = attr::sort_meta_items(metas.cmh_items);
sha.reset();
- for (@ast::meta_item m_ in cmh_items) {
- auto m = m_;
- alt (m.node) {
- case (ast::meta_name_value(?key, ?value)) {
- sha.input_str(len_and_str(key));
- sha.input_str(len_and_str_lit(value));
- }
- case (ast::meta_word(?name)) {
- sha.input_str(len_and_str(name));
- }
- case (ast::meta_list(_, _)) {
- // FIXME (#607): Implement this
- fail "unimplemented meta_item variant";
- }
+ for m_: @ast::meta_item in cmh_items {
+ let m = m_;
+ alt m.node {
+ ast::meta_name_value(key, value) {
+ sha.input_str(len_and_str(key));
+ sha.input_str(len_and_str_lit(value));
+ }
+ ast::meta_word(name) { sha.input_str(len_and_str(name)); }
+ ast::meta_list(_, _) {
+ // FIXME (#607): Implement this
+ fail "unimplemented meta_item variant";
+ }
}
}
ret truncated_sha1_result(sha);
}
- fn warn_missing(&session::session sess, str name, str default) {
- if (!sess.get_opts().library) { ret; }
+ fn warn_missing(sess: &session::session, name: str, default: str) {
+ if !sess.get_opts().library { ret; }
sess.warn(#fmt("missing crate link meta '%s', using '%s' as default",
name, default));
}
- fn crate_meta_name(&session::session sess, &ast::crate crate,
- &str output, &provided_metas metas) -> str {
- ret alt (metas.name) {
- case (some(?v)) { v }
- case (none) {
- auto name = {
- auto os_vec = str::split(fs::basename(output), '.' as u8);
+ fn crate_meta_name(sess: &session::session, crate: &ast::crate,
+ output: &str, metas: &provided_metas) -> str {
+ ret alt metas.name {
+ some(v) { v }
+ none. {
+ let
// FIXME: Remove this vec->ivec conversion.
- auto os = ~[];
- for (str s in os_vec) { os += ~[s]; }
- assert (ivec::len(os) >= 2u);
- ivec::pop(os);
- str::connect_ivec(os, ".")
- };
+ name =
+ {
+ let os_vec =
+ str::split(fs::basename(output), '.' as u8);
+ let os = ~[];
+ for s: str in os_vec { os += ~[s]; }
+ assert (ivec::len(os) >= 2u);
+ ivec::pop(os);
+ str::connect_ivec(os, ".")
+ };
warn_missing(sess, "name", name);
name
- }
- };
+ }
+ };
}
- fn crate_meta_vers(&session::session sess, &ast::crate crate,
- &provided_metas metas) -> str {
- ret alt (metas.vers) {
- case (some(?v)) { v }
- case (none) {
- auto vers = "0.0";
+ fn crate_meta_vers(sess: &session::session, crate: &ast::crate,
+ metas: &provided_metas) -> str {
+ ret alt metas.vers {
+ some(v) { v }
+ none. {
+ let vers = "0.0";
warn_missing(sess, "vers", vers);
vers
- }
- };
+ }
+ };
}
- auto provided_metas = provided_link_metas(sess, c);
- auto name = crate_meta_name(sess, c, output, provided_metas);
- auto vers = crate_meta_vers(sess, c, provided_metas);
- auto extras_hash = crate_meta_extras_hash(sha, c, provided_metas);
+ let provided_metas = provided_link_metas(sess, c);
+ let name = crate_meta_name(sess, c, output, provided_metas);
+ let vers = crate_meta_vers(sess, c, provided_metas);
+ let extras_hash = crate_meta_extras_hash(sha, c, provided_metas);
- ret rec(name = name, vers = vers, extras_hash = extras_hash);
+ ret {name: name, vers: vers, extras_hash: extras_hash};
}
-fn truncated_sha1_result(sha1 sha) -> str {
+fn truncated_sha1_result(sha: sha1) -> str {
ret str::substr(sha.result_str(), 0u, 16u);
}
// This calculates STH for a symbol, as defined above
-fn symbol_hash(ty::ctxt tcx, sha1 sha, &ty::t t,
- &link_meta link_meta) -> str {
+fn symbol_hash(tcx: ty::ctxt, sha: sha1, t: &ty::t, link_meta: &link_meta) ->
+ str {
// NB: do *not* use abbrevs here as we want the symbol names
// to be independent of one another in the crate.
@@ -412,66 +397,64 @@
sha.input_str(link_meta.name);
sha.input_str("-");
sha.input_str(encoder::encoded_ty(tcx, t));
- auto hash = truncated_sha1_result(sha);
+ let hash = truncated_sha1_result(sha);
// Prefix with _ so that it never blends into adjacent digits
ret "_" + hash;
}
-fn get_symbol_hash(&@crate_ctxt ccx, &ty::t t) -> str {
- auto hash = "";
- alt (ccx.type_sha1s.find(t)) {
- case (some(?h)) { hash = h; }
- case (none) {
- hash =
- symbol_hash(ccx.tcx, ccx.sha, t,
- ccx.link_meta);
- ccx.type_sha1s.insert(t, hash);
- }
+fn get_symbol_hash(ccx: &@crate_ctxt, t: &ty::t) -> str {
+ let hash = "";
+ alt ccx.type_sha1s.find(t) {
+ some(h) { hash = h; }
+ none. {
+ hash = symbol_hash(ccx.tcx, ccx.sha, t, ccx.link_meta);
+ ccx.type_sha1s.insert(t, hash);
+ }
}
ret hash;
}
-fn mangle(&str[] ss) -> str {
+fn mangle(ss: &str[]) -> str {
// Follow C++ namespace-mangling style
- auto n = "_ZN"; // Begin name-sequence.
+ let n = "_ZN"; // Begin name-sequence.
- for (str s in ss) { n += #fmt("%u%s", str::byte_len(s), s); }
+ for s: str in ss { n += #fmt("%u%s", str::byte_len(s), s); }
n += "E"; // End name-sequence.
ret n;
}
-fn exported_name(&str[] path, &str hash, &str vers) -> str {
+fn exported_name(path: &str[], hash: &str, vers: &str) -> str {
// FIXME: versioning isn't working yet
ret mangle(path + ~[hash]); // + "@" + vers;
}
-fn mangle_exported_name(&@crate_ctxt ccx, &str[] path, &ty::t t) -> str {
- auto hash = get_symbol_hash(ccx, t);
+fn mangle_exported_name(ccx: &@crate_ctxt, path: &str[], t: &ty::t) -> str {
+ let hash = get_symbol_hash(ccx, t);
ret exported_name(path, hash, ccx.link_meta.vers);
}
-fn mangle_internal_name_by_type_only(&@crate_ctxt ccx, &ty::t t, &str name) ->
- str {
- auto s = util::ppaux::ty_to_short_str(ccx.tcx, t);
- auto hash = get_symbol_hash(ccx, t);
+fn mangle_internal_name_by_type_only(ccx: &@crate_ctxt, t: &ty::t, name: &str)
+ -> str {
+ let s = util::ppaux::ty_to_short_str(ccx.tcx, t);
+ let hash = get_symbol_hash(ccx, t);
ret mangle(~[name, s, hash]);
}
-fn mangle_internal_name_by_path_and_seq(&@crate_ctxt ccx, &str[] path,
- &str flav) -> str {
+fn mangle_internal_name_by_path_and_seq(ccx: &@crate_ctxt, path: &str[],
+ flav: &str) -> str {
ret mangle(path + ~[ccx.names.next(flav)]);
}
-fn mangle_internal_name_by_path(&@crate_ctxt ccx, &str[] path) -> str {
+fn mangle_internal_name_by_path(ccx: &@crate_ctxt, path: &str[]) -> str {
ret mangle(path);
}
-fn mangle_internal_name_by_seq(&@crate_ctxt ccx, &str flav) -> str {
+fn mangle_internal_name_by_seq(ccx: &@crate_ctxt, flav: &str) -> str {
ret ccx.names.next(flav);
}
//
diff --git a/src/comp/back/upcall.rs b/src/comp/back/upcall.rs
index 0237037..b12ceba 100644
--- a/src/comp/back/upcall.rs
+++ b/src/comp/back/upcall.rs
@@ -24,121 +24,124 @@
import lib::llvm::llvm::TypeRef;
type upcalls =
- rec(ValueRef grow_task,
- ValueRef log_int,
- ValueRef log_float,
- ValueRef log_double,
- ValueRef log_str,
- ValueRef log_istr,
- ValueRef trace_word,
- ValueRef trace_str,
- ValueRef new_port,
- ValueRef del_port,
- ValueRef new_chan,
- ValueRef flush_chan,
- ValueRef del_chan,
- ValueRef clone_chan,
- ValueRef chan_target_task,
- ValueRef _yield,
- ValueRef sleep,
- ValueRef send,
- ValueRef recv,
- ValueRef _fail,
- ValueRef kill,
- ValueRef exit,
- ValueRef malloc,
- ValueRef free,
- ValueRef shared_malloc,
- ValueRef shared_free,
- ValueRef mark,
- ValueRef new_str,
- ValueRef dup_str,
- ValueRef new_vec,
- ValueRef vec_append,
- ValueRef get_type_desc,
- ValueRef new_task,
- ValueRef start_task,
- ValueRef ivec_resize,
- ValueRef ivec_spill,
- ValueRef ivec_resize_shared,
- ValueRef ivec_spill_shared);
+ {grow_task: ValueRef,
+ log_int: ValueRef,
+ log_float: ValueRef,
+ log_double: ValueRef,
+ log_str: ValueRef,
+ log_istr: ValueRef,
+ trace_word: ValueRef,
+ trace_str: ValueRef,
+ new_port: ValueRef,
+ del_port: ValueRef,
+ new_chan: ValueRef,
+ flush_chan: ValueRef,
+ del_chan: ValueRef,
+ clone_chan: ValueRef,
+ chan_target_task: ValueRef,
+ _yield: ValueRef,
+ sleep: ValueRef,
+ send: ValueRef,
+ recv: ValueRef,
+ _fail: ValueRef,
+ kill: ValueRef,
+ exit: ValueRef,
+ malloc: ValueRef,
+ free: ValueRef,
+ shared_malloc: ValueRef,
+ shared_free: ValueRef,
+ mark: ValueRef,
+ new_str: ValueRef,
+ dup_str: ValueRef,
+ new_vec: ValueRef,
+ vec_append: ValueRef,
+ get_type_desc: ValueRef,
+ new_task: ValueRef,
+ start_task: ValueRef,
+ ivec_resize: ValueRef,
+ ivec_spill: ValueRef,
+ ivec_resize_shared: ValueRef,
+ ivec_spill_shared: ValueRef};
-fn declare_upcalls(type_names tn, TypeRef tydesc_type, TypeRef taskptr_type,
- ModuleRef llmod)
- -> @upcalls {
- fn decl(type_names tn, TypeRef tydesc_type, TypeRef taskptr_type,
- ModuleRef llmod, str name, TypeRef[] tys,
- TypeRef rv) -> ValueRef {
- let TypeRef[] arg_tys = ~[taskptr_type];
- for (TypeRef t in tys) { arg_tys += ~[t]; }
- auto fn_ty = T_fn(arg_tys, rv);
+fn declare_upcalls(tn: type_names, tydesc_type: TypeRef,
+ taskptr_type: TypeRef, llmod: ModuleRef) -> @upcalls {
+ fn decl(tn: type_names, tydesc_type: TypeRef, taskptr_type: TypeRef,
+ llmod: ModuleRef, name: str, tys: TypeRef[], rv: TypeRef) ->
+ ValueRef {
+ let arg_tys: TypeRef[] = ~[taskptr_type];
+ for t: TypeRef in tys { arg_tys += ~[t]; }
+ let fn_ty = T_fn(arg_tys, rv);
ret trans::decl_cdecl_fn(llmod, "upcall_" + name, fn_ty);
}
- auto dv = bind decl(tn, tydesc_type, taskptr_type, llmod, _, _, T_void());
- auto d = bind decl(tn, tydesc_type, taskptr_type, llmod, _, _, _);
+ let dv = bind decl(tn, tydesc_type, taskptr_type, llmod, _, _, T_void());
+ let d = bind decl(tn, tydesc_type, taskptr_type, llmod, _, _, _);
// FIXME: Sigh:.. remove this when I fix the typechecker pushdown.
// --pcwalton
- let TypeRef[] empty_vec = ~[];
- ret @rec(grow_task=dv("grow_task", ~[T_size_t()]),
- log_int=dv("log_int", ~[T_i32(), T_i32()]),
- log_float=dv("log_float", ~[T_i32(), T_f32()]),
- log_double=dv("log_double", ~[T_i32(), T_ptr(T_f64())]),
- log_str=dv("log_str", ~[T_i32(), T_ptr(T_str())]),
- log_istr=dv("log_istr", ~[T_i32(), T_ptr(T_ivec(T_i8()))]),
- trace_word=dv("trace_word", ~[T_int()]),
- trace_str=dv("trace_str", ~[T_ptr(T_i8())]),
- new_port=d("new_port", ~[T_size_t()], T_opaque_port_ptr()),
- del_port=dv("del_port", ~[T_opaque_port_ptr()]),
- new_chan=d("new_chan", ~[T_opaque_port_ptr()],
- T_opaque_chan_ptr()),
- flush_chan=dv("flush_chan", ~[T_opaque_chan_ptr()]),
- del_chan=dv("del_chan", ~[T_opaque_chan_ptr()]),
- clone_chan=d("clone_chan", ~[taskptr_type, T_opaque_chan_ptr()],
- T_opaque_chan_ptr()),
- chan_target_task=d("chan_target_task",
- ~[T_opaque_chan_ptr()],
- taskptr_type),
- _yield=dv("yield", empty_vec),
- sleep=dv("sleep", ~[T_size_t()]),
- send=dv("send", ~[T_opaque_chan_ptr(), T_ptr(T_i8())]),
- recv=dv("recv", ~[T_ptr(T_ptr(T_i8())), T_opaque_port_ptr()]),
- _fail=dv("fail", ~[T_ptr(T_i8()), T_ptr(T_i8()), T_size_t()]),
- kill=dv("kill", ~[taskptr_type]),
- exit=dv("exit", empty_vec),
- malloc=d("malloc", ~[T_size_t(), T_ptr(tydesc_type)],
- T_ptr(T_i8())),
- free=dv("free", ~[T_ptr(T_i8()), T_int()]),
- shared_malloc=d("shared_malloc",
- ~[T_size_t(), T_ptr(tydesc_type)], T_ptr(T_i8())),
- shared_free=dv("shared_free", ~[T_ptr(T_i8())]),
- mark=d("mark", ~[T_ptr(T_i8())], T_int()),
- new_str=d("new_str", ~[T_ptr(T_i8()), T_size_t()],
- T_ptr(T_str())),
- dup_str=d("dup_str", ~[taskptr_type, T_ptr(T_str())],
- T_ptr(T_str())),
- new_vec=d("new_vec", ~[T_size_t(), T_ptr(tydesc_type)],
- T_opaque_vec_ptr()),
- vec_append=d("vec_append",
- ~[T_ptr(tydesc_type), T_ptr(tydesc_type),
- T_ptr(T_opaque_vec_ptr()), T_opaque_vec_ptr(),
- T_bool()], T_void()),
- get_type_desc=d("get_type_desc",
- ~[T_ptr(T_nil()), T_size_t(), T_size_t(),
- T_size_t(), T_ptr(T_ptr(tydesc_type))],
- T_ptr(tydesc_type)),
- new_task=d("new_task", ~[T_ptr(T_str())], taskptr_type),
- start_task=d("start_task",
- ~[taskptr_type, T_int(), T_int(), T_size_t()],
- taskptr_type),
- ivec_resize=d("ivec_resize", ~[T_ptr(T_opaque_ivec()), T_int()],
- T_void()),
- ivec_spill=d("ivec_spill", ~[T_ptr(T_opaque_ivec()), T_int()],
- T_void()),
- ivec_resize_shared=d("ivec_resize_shared",
- ~[T_ptr(T_opaque_ivec()), T_int()], T_void()),
- ivec_spill_shared=d("ivec_spill_shared",
- ~[T_ptr(T_opaque_ivec()), T_int()], T_void()));
+ let empty_vec: TypeRef[] = ~[];
+ ret @{grow_task: dv("grow_task", ~[T_size_t()]),
+ log_int: dv("log_int", ~[T_i32(), T_i32()]),
+ log_float: dv("log_float", ~[T_i32(), T_f32()]),
+ log_double: dv("log_double", ~[T_i32(), T_ptr(T_f64())]),
+ log_str: dv("log_str", ~[T_i32(), T_ptr(T_str())]),
+ log_istr: dv("log_istr", ~[T_i32(), T_ptr(T_ivec(T_i8()))]),
+ trace_word: dv("trace_word", ~[T_int()]),
+ trace_str: dv("trace_str", ~[T_ptr(T_i8())]),
+ new_port: d("new_port", ~[T_size_t()], T_opaque_port_ptr()),
+ del_port: dv("del_port", ~[T_opaque_port_ptr()]),
+ new_chan:
+ d("new_chan", ~[T_opaque_port_ptr()], T_opaque_chan_ptr()),
+ flush_chan: dv("flush_chan", ~[T_opaque_chan_ptr()]),
+ del_chan: dv("del_chan", ~[T_opaque_chan_ptr()]),
+ clone_chan:
+ d("clone_chan", ~[taskptr_type, T_opaque_chan_ptr()],
+ T_opaque_chan_ptr()),
+ chan_target_task:
+ d("chan_target_task", ~[T_opaque_chan_ptr()], taskptr_type),
+ _yield: dv("yield", empty_vec),
+ sleep: dv("sleep", ~[T_size_t()]),
+ send: dv("send", ~[T_opaque_chan_ptr(), T_ptr(T_i8())]),
+ recv: dv("recv", ~[T_ptr(T_ptr(T_i8())), T_opaque_port_ptr()]),
+ _fail: dv("fail", ~[T_ptr(T_i8()), T_ptr(T_i8()), T_size_t()]),
+ kill: dv("kill", ~[taskptr_type]),
+ exit: dv("exit", empty_vec),
+ malloc:
+ d("malloc", ~[T_size_t(), T_ptr(tydesc_type)], T_ptr(T_i8())),
+ free: dv("free", ~[T_ptr(T_i8()), T_int()]),
+ shared_malloc:
+ d("shared_malloc", ~[T_size_t(), T_ptr(tydesc_type)],
+ T_ptr(T_i8())),
+ shared_free: dv("shared_free", ~[T_ptr(T_i8())]),
+ mark: d("mark", ~[T_ptr(T_i8())], T_int()),
+ new_str: d("new_str", ~[T_ptr(T_i8()), T_size_t()], T_ptr(T_str())),
+ dup_str:
+ d("dup_str", ~[taskptr_type, T_ptr(T_str())], T_ptr(T_str())),
+ new_vec:
+ d("new_vec", ~[T_size_t(), T_ptr(tydesc_type)],
+ T_opaque_vec_ptr()),
+ vec_append:
+ d("vec_append",
+ ~[T_ptr(tydesc_type), T_ptr(tydesc_type),
+ T_ptr(T_opaque_vec_ptr()), T_opaque_vec_ptr(), T_bool()],
+ T_void()),
+ get_type_desc:
+ d("get_type_desc",
+ ~[T_ptr(T_nil()), T_size_t(), T_size_t(), T_size_t(),
+ T_ptr(T_ptr(tydesc_type))], T_ptr(tydesc_type)),
+ new_task: d("new_task", ~[T_ptr(T_str())], taskptr_type),
+ start_task:
+ d("start_task", ~[taskptr_type, T_int(), T_int(), T_size_t()],
+ taskptr_type),
+ ivec_resize:
+ d("ivec_resize", ~[T_ptr(T_opaque_ivec()), T_int()], T_void()),
+ ivec_spill:
+ d("ivec_spill", ~[T_ptr(T_opaque_ivec()), T_int()], T_void()),
+ ivec_resize_shared:
+ d("ivec_resize_shared", ~[T_ptr(T_opaque_ivec()), T_int()],
+ T_void()),
+ ivec_spill_shared:
+ d("ivec_spill_shared", ~[T_ptr(T_opaque_ivec()), T_int()],
+ T_void())};
}
//
// Local Variables:
diff --git a/src/comp/back/x86.rs b/src/comp/back/x86.rs
index 903a548..80f0245 100644
--- a/src/comp/back/x86.rs
+++ b/src/comp/back/x86.rs
@@ -7,26 +7,26 @@
fn get_module_asm() -> str { ret ""; }
fn get_meta_sect_name() -> str {
- if (str::eq(target_os(), "macos")) { ret "__DATA,__note.rustc"; }
- if (str::eq(target_os(), "win32")) { ret ".note.rustc"; }
+ if str::eq(target_os(), "macos") { ret "__DATA,__note.rustc"; }
+ if str::eq(target_os(), "win32") { ret ".note.rustc"; }
ret ".note.rustc";
}
fn get_data_layout() -> str {
- if (str::eq(target_os(), "macos")) {
+ if str::eq(target_os(), "macos") {
ret "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16" + "-i32:32:32-i64:32:64" +
"-f32:32:32-f64:32:64-v64:64:64" +
"-v128:128:128-a0:0:64-f80:128:128" + "-n8:16:32";
}
- if (str::eq(target_os(), "win32")) {
+ if str::eq(target_os(), "win32") {
ret "e-p:32:32-f64:64:64-i64:64:64-f80:32:32-n8:16:32";
}
ret "e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32";
}
fn get_target_triple() -> str {
- if (str::eq(target_os(), "macos")) { ret "i686-apple-darwin"; }
- if (str::eq(target_os(), "win32")) { ret "i686-pc-mingw32"; }
+ if str::eq(target_os(), "macos") { ret "i686-apple-darwin"; }
+ if str::eq(target_os(), "win32") { ret "i686-pc-mingw32"; }
ret "i686-unknown-linux-gnu";
}
//
diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs
index 2891cd8..34c8f7f 100644
--- a/src/comp/driver/rustc.rs
+++ b/src/comp/driver/rustc.rs
@@ -40,198 +40,191 @@
tag pp_mode { ppm_normal; ppm_typed; ppm_identified; }
-fn default_configuration(session::session sess, str argv0, str input) ->
- ast::crate_cfg {
- auto libc =
- alt (sess.get_targ_cfg().os) {
- case (session::os_win32) { "msvcrt.dll" }
- case (session::os_macos) { "libc.dylib" }
- case (session::os_linux) { "libc.so.6" }
- case (_) { "libc.so" }
+fn default_configuration(sess: session::session, argv0: str, input: str) ->
+ ast::crate_cfg {
+ let libc =
+ alt sess.get_targ_cfg().os {
+ session::os_win32. { "msvcrt.dll" }
+ session::os_macos. { "libc.dylib" }
+ session::os_linux. { "libc.so.6" }
+ _ { "libc.so" }
};
- auto mk = attr::mk_name_value_item_str;
+ let mk = attr::mk_name_value_item_str;
ret ~[ // Target bindings.
- mk("target_os", std::os::target_os()),
- mk("target_arch", "x86"),
+ mk("target_os", std::os::target_os()), mk("target_arch", "x86"),
mk("target_libc", libc),
// Build bindings.
- mk("build_compiler", argv0),
- mk("build_input", input)];
+ mk("build_compiler", argv0), mk("build_input", input)];
}
-fn build_configuration(session::session sess, str argv0,
- str input) -> ast::crate_cfg {
+fn build_configuration(sess: session::session, argv0: str, input: str) ->
+ ast::crate_cfg {
// Combine the configuration requested by the session (command line) with
// some default and generated configuration items
- auto default_cfg = default_configuration(sess, argv0, input);
- auto user_cfg = sess.get_opts().cfg;
- auto gen_cfg = {
+ let default_cfg = default_configuration(sess, argv0, input);
+ let user_cfg = sess.get_opts().cfg;
+ let
// If the user wants a test runner, then add the test cfg
- if (sess.get_opts().test
- && !attr::contains_name(user_cfg, "test")) {
- ~[attr::mk_word_item("test")]
- } else {
- ~[]
- }
- };
+ gen_cfg =
+ {
+ if sess.get_opts().test && !attr::contains_name(user_cfg, "test")
+ {
+ ~[attr::mk_word_item("test")]
+ } else { ~[] }
+ };
ret user_cfg + gen_cfg + default_cfg;
}
// Convert strings provided as --cfg [cfgspec] into a crate_cfg
-fn parse_cfgspecs(&vec[str] cfgspecs) -> ast::crate_cfg {
+fn parse_cfgspecs(cfgspecs: &vec[str]) -> ast::crate_cfg {
// FIXME: It would be nice to use the parser to parse all varieties of
// meta_item here. At the moment we just support the meta_word variant.
- auto words = ~[];
- for (str s in cfgspecs) { words += ~[attr::mk_word_item(s)]; }
+ let words = ~[];
+ for s: str in cfgspecs { words += ~[attr::mk_word_item(s)]; }
ret words;
}
-fn parse_input(session::session sess, &ast::crate_cfg cfg, str input)
- -> @ast::crate {
- ret if (str::ends_with(input, ".rc")) {
- parser::parse_crate_from_crate_file
- (input, cfg, sess.get_parse_sess())
+fn parse_input(sess: session::session, cfg: &ast::crate_cfg, input: str) ->
+ @ast::crate {
+ ret if str::ends_with(input, ".rc") {
+ parser::parse_crate_from_crate_file(input, cfg,
+ sess.get_parse_sess())
} else if (str::ends_with(input, ".rs")) {
- parser::parse_crate_from_source_file
- (input, cfg, sess.get_parse_sess())
+ parser::parse_crate_from_source_file(input, cfg,
+ sess.get_parse_sess())
} else { sess.fatal("unknown input file type: " + input); fail };
}
-fn time[T](bool do_it, str what, fn() -> T thunk) -> T {
- if (!do_it) { ret thunk(); }
- auto start = std::time::get_time();
- auto rv = thunk();
- auto end = std::time::get_time();
+fn time[T](do_it: bool, what: str, thunk: fn() -> T ) -> T {
+ if !do_it { ret thunk(); }
+ let start = std::time::get_time();
+ let rv = thunk();
+ let end = std::time::get_time();
// FIXME: Actually do timeval math.
log_err #fmt("time: %s took %u s", what, end.sec - start.sec as uint);
ret rv;
}
-fn compile_input(session::session sess, ast::crate_cfg cfg, str input,
- str output) {
- auto time_passes = sess.get_opts().time_passes;
- auto crate =
+fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
+ output: str) {
+ let time_passes = sess.get_opts().time_passes;
+ let crate =
time(time_passes, "parsing", bind parse_input(sess, cfg, input));
- if (sess.get_opts().output_type == link::output_type_none) { ret; }
- crate = time(time_passes, "configuration",
- bind front::config::strip_unconfigured_items(crate));
- if (sess.get_opts().test) {
- crate = time(time_passes, "building test harness",
- bind front::test::modify_for_testing(crate));
+ if sess.get_opts().output_type == link::output_type_none { ret; }
+ crate =
+ time(time_passes, "configuration",
+ bind front::config::strip_unconfigured_items(crate));
+ if sess.get_opts().test {
+ crate =
+ time(time_passes, "building test harness",
+ bind front::test::modify_for_testing(crate));
}
- crate = time(time_passes, "expansion",
- bind syntax::ext::expand::expand_crate(sess, crate));
+ crate =
+ time(time_passes, "expansion",
+ bind syntax::ext::expand::expand_crate(sess, crate));
- auto ast_map = time(time_passes, "ast indexing",
- bind middle::ast_map::map_crate(*crate));
+ let ast_map =
+ time(time_passes, "ast indexing",
+ bind middle::ast_map::map_crate(*crate));
time(time_passes, "external crate/lib resolution",
bind creader::read_crates(sess, *crate));
- auto d =
+ let d =
time(time_passes, "resolution",
bind resolve::resolve_crate(sess, ast_map, crate));
- auto freevars =
+ let freevars =
time(time_passes, "freevar finding",
bind freevars::annotate_freevars(sess, d, crate));
- auto ty_cx = ty::mk_ctxt(sess, d, ast_map, freevars);
+ let ty_cx = ty::mk_ctxt(sess, d, ast_map, freevars);
time[()](time_passes, "typechecking",
bind typeck::check_crate(ty_cx, crate));
time[()](time_passes, "alt checking",
bind middle::check_alt::check_crate(ty_cx, crate));
- if (sess.get_opts().run_typestate) {
+ if sess.get_opts().run_typestate {
time(time_passes, "typestate checking",
bind middle::tstate::ck::check_crate(ty_cx, crate));
}
time(time_passes, "alias checking",
bind middle::alias::check_crate(ty_cx, crate));
- auto llmod =
+ let llmod =
time[llvm::llvm::ModuleRef](time_passes, "translation",
- bind trans::trans_crate
- (sess, crate, ty_cx, output, ast_map));
+ bind trans::trans_crate(sess, crate,
+ ty_cx, output,
+ ast_map));
time[()](time_passes, "LLVM passes",
bind link::write::run_passes(sess, llmod, output));
}
-fn pretty_print_input(session::session sess, ast::crate_cfg cfg,
- str input, pp_mode ppm, bool expand) {
- fn ann_paren_for_expr(&pprust::ann_node node) {
- alt (node) {
- case (pprust::node_expr(?s, ?expr)) {
- pprust::popen(s);
- }
- case (_) {}
+fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg, input: str,
+ ppm: pp_mode, expand: bool) {
+ fn ann_paren_for_expr(node: &pprust::ann_node) {
+ alt node { pprust::node_expr(s, expr) { pprust::popen(s); } _ { } }
+ }
+ fn ann_typed_post(tcx: &ty::ctxt, node: &pprust::ann_node) {
+ alt node {
+ pprust::node_expr(s, expr) {
+ pp::space(s.s);
+ pp::word(s.s, "as");
+ pp::space(s.s);
+ pp::word(s.s, ppaux::ty_to_str(tcx, ty::expr_ty(tcx, expr)));
+ pprust::pclose(s);
+ }
+ _ { }
}
}
- fn ann_typed_post(&ty::ctxt tcx, &pprust::ann_node node) {
- alt (node) {
- case (pprust::node_expr(?s, ?expr)) {
- pp::space(s.s);
- pp::word(s.s, "as");
- pp::space(s.s);
- pp::word(s.s, ppaux::ty_to_str(tcx, ty::expr_ty(tcx, expr)));
- pprust::pclose(s);
- }
- case (_) {}
- }
- }
- fn ann_identified_post(&pprust::ann_node node) {
- alt (node) {
- case (pprust::node_item(?s, ?item)) {
- pp::space(s.s);
- pprust::synth_comment(s, int::to_str(item.id, 10u));
- }
- case (pprust::node_block(?s, ?blk)) {
- pp::space(s.s);
- pprust::synth_comment(s, "block " +
- int::to_str(blk.node.id, 10u));
- }
- case (pprust::node_expr(?s, ?expr)) {
- pp::space(s.s);
- pprust::synth_comment(s, int::to_str(expr.id, 10u));
- pprust::pclose(s);
- }
- case (_) {}
+ fn ann_identified_post(node: &pprust::ann_node) {
+ alt node {
+ pprust::node_item(s, item) {
+ pp::space(s.s);
+ pprust::synth_comment(s, int::to_str(item.id, 10u));
+ }
+ pprust::node_block(s, blk) {
+ pp::space(s.s);
+ pprust::synth_comment(s,
+ "block " + int::to_str(blk.node.id, 10u));
+ }
+ pprust::node_expr(s, expr) {
+ pp::space(s.s);
+ pprust::synth_comment(s, int::to_str(expr.id, 10u));
+ pprust::pclose(s);
+ }
+ _ { }
}
}
- auto crate = parse_input(sess, cfg, input);
- if(expand) { crate = syntax::ext::expand::expand_crate(sess, crate); }
- auto ann;
- alt (ppm) {
- case (ppm_typed) {
- auto amap = middle::ast_map::map_crate(*crate);
- auto d = resolve::resolve_crate(sess, amap, crate);
- auto freevars = freevars::annotate_freevars(sess, d, crate);
- auto ty_cx = ty::mk_ctxt(sess, d, amap, freevars);
- typeck::check_crate(ty_cx, crate);
- ann = rec(pre=ann_paren_for_expr,
- post=bind ann_typed_post(ty_cx, _));
- }
- case (ppm_identified) {
- ann = rec(pre=ann_paren_for_expr,
- post=ann_identified_post);
- }
- case (ppm_normal) {
- ann = pprust::no_ann();
- }
+ let crate = parse_input(sess, cfg, input);
+ if expand { crate = syntax::ext::expand::expand_crate(sess, crate); }
+ let ann;
+ alt ppm {
+ ppm_typed. {
+ let amap = middle::ast_map::map_crate(*crate);
+ let d = resolve::resolve_crate(sess, amap, crate);
+ let freevars = freevars::annotate_freevars(sess, d, crate);
+ let ty_cx = ty::mk_ctxt(sess, d, amap, freevars);
+ typeck::check_crate(ty_cx, crate);
+ ann = {pre: ann_paren_for_expr, post: bind ann_typed_post(ty_cx, _)};
+ }
+ ppm_identified. {
+ ann = {pre: ann_paren_for_expr, post: ann_identified_post};
+ }
+ ppm_normal. { ann = pprust::no_ann(); }
}
pprust::print_crate(sess.get_codemap(), crate, input,
- ioivec::file_reader(input),
- ioivec::stdout(), ann);
+ ioivec::file_reader(input), ioivec::stdout(), ann);
}
-fn version(str argv0) {
- auto vers = "unknown version";
- auto env_vers = #env("CFG_VERSION");
- if (str::byte_len(env_vers) != 0u) { vers = env_vers; }
+fn version(argv0: str) {
+ let vers = "unknown version";
+ let env_vers = #env("CFG_VERSION");
+ if str::byte_len(env_vers) != 0u { vers = env_vers; }
ioivec::stdout().write_str(#fmt("%s %s\n", argv0, vers));
}
-fn usage(str argv0) {
+fn usage(argv0: str) {
ioivec::stdout().write_str(#fmt("usage: %s [options] <input>\n", argv0) +
- "
+ "
options:
-h --help display this message
@@ -267,9 +260,9 @@
");
}
-fn get_os(str triple) -> session::os {
- ret if (str::find(triple, "win32") >= 0 ||
- str::find(triple, "mingw32") >= 0) {
+fn get_os(triple: str) -> session::os {
+ ret if str::find(triple, "win32") >= 0 ||
+ str::find(triple, "mingw32") >= 0 {
session::os_win32
} else if (str::find(triple, "darwin") >= 0) {
session::os_macos
@@ -278,11 +271,11 @@
} else { log_err "Unknown operating system!"; fail };
}
-fn get_arch(str triple) -> session::arch {
- ret if (str::find(triple, "i386") >= 0 || str::find(triple, "i486") >= 0
- || str::find(triple, "i586") >= 0 ||
- str::find(triple, "i686") >= 0 ||
- str::find(triple, "i786") >= 0) {
+fn get_arch(triple: str) -> session::arch {
+ ret if str::find(triple, "i386") >= 0 || str::find(triple, "i486") >= 0 ||
+ str::find(triple, "i586") >= 0 ||
+ str::find(triple, "i686") >= 0 ||
+ str::find(triple, "i786") >= 0 {
session::arch_x86
} else if (str::find(triple, "x86_64") >= 0) {
session::arch_x64
@@ -292,36 +285,36 @@
} else { log_err "Unknown architecture! " + triple; fail };
}
-fn get_default_sysroot(str binary) -> str {
- auto dirname = fs::dirname(binary);
- if (str::eq(dirname, binary)) { ret "."; }
+fn get_default_sysroot(binary: str) -> str {
+ let dirname = fs::dirname(binary);
+ if str::eq(dirname, binary) { ret "."; }
ret dirname;
}
fn build_target_config() -> @session::config {
- let str triple =
+ let triple: str =
std::str::rustrt::str_from_cstr(llvm::llvm::LLVMRustGetHostTriple());
- let @session::config target_cfg =
- @rec(os=get_os(triple),
- arch=get_arch(triple),
- int_type=ast::ty_i32,
- uint_type=ast::ty_u32,
- float_type=ast::ty_f64);
+ let target_cfg: @session::config =
+ @{os: get_os(triple),
+ arch: get_arch(triple),
+ int_type: ast::ty_i32,
+ uint_type: ast::ty_u32,
+ float_type: ast::ty_f64};
ret target_cfg;
}
-fn build_session_options(str binary, getopts::match match, str binary_dir) ->
- @session::options {
- auto library = opt_present(match, "lib");
- auto static = opt_present(match, "static");
+fn build_session_options(binary: str, match: getopts::match, binary_dir: str)
+ -> @session::options {
+ let library = opt_present(match, "lib");
+ let static = opt_present(match, "static");
- auto library_search_paths = ~[binary_dir + "/lib"];
+ let library_search_paths = ~[binary_dir + "/lib"];
// FIXME: Remove this vec->ivec conversion.
- auto lsp_vec = getopts::opt_strs(match, "L");
- for (str lsp in lsp_vec) { library_search_paths += ~[lsp]; }
+ let lsp_vec = getopts::opt_strs(match, "L");
+ for lsp: str in lsp_vec { library_search_paths += ~[lsp]; }
- auto output_type =
- if (opt_present(match, "parse-only")) {
+ let output_type =
+ if opt_present(match, "parse-only") {
link::output_type_none
} else if (opt_present(match, "S")) {
link::output_type_assembly
@@ -330,78 +323,78 @@
} else if (opt_present(match, "emit-llvm")) {
link::output_type_bitcode
} else { link::output_type_exe };
- auto verify = !opt_present(match, "noverify");
- auto save_temps = opt_present(match, "save-temps");
- auto debuginfo = opt_present(match, "g");
- auto stats = opt_present(match, "stats");
- auto time_passes = opt_present(match, "time-passes");
- auto time_llvm_passes = opt_present(match, "time-llvm-passes");
- auto run_typestate = !opt_present(match, "no-typestate");
- auto sysroot_opt = getopts::opt_maybe_str(match, "sysroot");
- let uint opt_level =
- if (opt_present(match, "O")) {
- if (opt_present(match, "OptLevel")) {
+ let verify = !opt_present(match, "noverify");
+ let save_temps = opt_present(match, "save-temps");
+ let debuginfo = opt_present(match, "g");
+ let stats = opt_present(match, "stats");
+ let time_passes = opt_present(match, "time-passes");
+ let time_llvm_passes = opt_present(match, "time-llvm-passes");
+ let run_typestate = !opt_present(match, "no-typestate");
+ let sysroot_opt = getopts::opt_maybe_str(match, "sysroot");
+ let opt_level: uint =
+ if opt_present(match, "O") {
+ if opt_present(match, "OptLevel") {
log_err "error: -O and --OptLevel both provided";
fail;
}
2u
} else if (opt_present(match, "OptLevel")) {
- alt (getopts::opt_str(match, "OptLevel")) {
- case ("0") { 0u }
- case ("1") { 1u }
- case ("2") { 2u }
- case ("3") { 3u }
- case (_) {
- log_err "error: optimization level needs " +
- "to be between 0-3";
- fail
- }
+ alt getopts::opt_str(match, "OptLevel") {
+ "0" { 0u }
+ "1" { 1u }
+ "2" { 2u }
+ "3" { 3u }
+ _ {
+ log_err "error: optimization level needs " +
+ "to be between 0-3";
+ fail
+ }
}
} else { 0u };
- auto sysroot =
- alt (sysroot_opt) {
- case (none) { get_default_sysroot(binary) }
- case (some(?s)) { s }
+ let sysroot =
+ alt sysroot_opt {
+ none. { get_default_sysroot(binary) }
+ some(s) { s }
};
- auto cfg = parse_cfgspecs(getopts::opt_strs(match, "cfg"));
- auto test = opt_present(match, "test");
- auto dps = opt_present(match, "dps");
- let @session::options sopts =
- @rec(library=library,
- static=static,
- optimize=opt_level,
- debuginfo=debuginfo,
- verify=verify,
- run_typestate=run_typestate,
- save_temps=save_temps,
- stats=stats,
- time_passes=time_passes,
- time_llvm_passes=time_llvm_passes,
- output_type=output_type,
- library_search_paths=library_search_paths,
- sysroot=sysroot,
- cfg=cfg,
- test=test,
- dps=dps);
+ let cfg = parse_cfgspecs(getopts::opt_strs(match, "cfg"));
+ let test = opt_present(match, "test");
+ let dps = opt_present(match, "dps");
+ let sopts: @session::options =
+ @{library: library,
+ static: static,
+ optimize: opt_level,
+ debuginfo: debuginfo,
+ verify: verify,
+ run_typestate: run_typestate,
+ save_temps: save_temps,
+ stats: stats,
+ time_passes: time_passes,
+ time_llvm_passes: time_llvm_passes,
+ output_type: output_type,
+ library_search_paths: library_search_paths,
+ sysroot: sysroot,
+ cfg: cfg,
+ test: test,
+ dps: dps};
ret sopts;
}
-fn build_session(@session::options sopts) -> session::session {
- auto target_cfg = build_target_config();
- auto cstore = cstore::mk_cstore();
+fn build_session(sopts: @session::options) -> session::session {
+ let target_cfg = build_target_config();
+ let cstore = cstore::mk_cstore();
ret session::session(target_cfg, sopts, cstore,
- @rec(cm=codemap::new_codemap(), mutable next_id=0),
+ @{cm: codemap::new_codemap(), mutable next_id: 0},
none, 0u);
}
-fn parse_pretty(session::session sess, &str name) -> pp_mode {
- if (str::eq(name, "normal")) {
+fn parse_pretty(sess: session::session, name: &str) -> pp_mode {
+ if str::eq(name, "normal") {
ret ppm_normal;
} else if (str::eq(name, "typed")) {
ret ppm_typed;
} else if (str::eq(name, "identified")) { ret ppm_identified; }
- sess.fatal("argument to `pretty` or `expand` must be one of `normal`, "
- + "`typed`, or `identified`");
+ sess.fatal("argument to `pretty` or `expand` must be one of `normal`, " +
+ "`typed`, or `identified`");
}
fn opts() -> vec[getopts::opt] {
@@ -416,184 +409,174 @@
optflag("lib"), optflag("static"), optflag("dps")];
}
-fn main(vec[str] args) {
- auto binary = vec::shift(args);
- auto binary_dir = fs::dirname(binary);
- auto match =
- alt (getopts::getopts(args, opts())) {
- case (getopts::success(?m)) { m }
- case (getopts::failure(?f)) {
- log_err #fmt("error: %s", getopts::fail_str(f));
- fail
- }
+fn main(args: vec[str]) {
+ let binary = vec::shift(args);
+ let binary_dir = fs::dirname(binary);
+ let match =
+ alt getopts::getopts(args, opts()) {
+ getopts::success(m) { m }
+ getopts::failure(f) {
+ log_err #fmt("error: %s", getopts::fail_str(f));
+ fail
+ }
};
- if (opt_present(match, "h") || opt_present(match, "help")) {
+ if opt_present(match, "h") || opt_present(match, "help") {
usage(binary);
ret;
}
- if (opt_present(match, "v") || opt_present(match, "version")) {
+ if opt_present(match, "v") || opt_present(match, "version") {
version(binary);
ret;
}
- auto sopts = build_session_options(binary, match, binary_dir);
- auto sess = build_session(sopts);
- auto n_inputs = vec::len[str](match.free);
- auto output_file = getopts::opt_maybe_str(match, "o");
- auto glue = opt_present(match, "glue");
- if (glue) {
- if (n_inputs > 0u) {
+ let sopts = build_session_options(binary, match, binary_dir);
+ let sess = build_session(sopts);
+ let n_inputs = vec::len[str](match.free);
+ let output_file = getopts::opt_maybe_str(match, "o");
+ let glue = opt_present(match, "glue");
+ if glue {
+ if n_inputs > 0u {
sess.fatal("No input files allowed with --glue.");
}
- auto out = option::from_maybe[str]("glue.bc", output_file);
+ let out = option::from_maybe[str]("glue.bc", output_file);
middle::trans::make_common_glue(sess, out);
ret;
}
- if (n_inputs == 0u) {
+ if n_inputs == 0u {
sess.fatal("No input filename given.");
} else if (n_inputs > 1u) {
sess.fatal("Multiple input filenames provided.");
}
- auto ifile = match.free.(0);
- let str saved_out_filename = "";
- auto cfg = build_configuration(sess, binary, ifile);
- auto expand =
+ let ifile = match.free.(0);
+ let saved_out_filename: str = "";
+ let cfg = build_configuration(sess, binary, ifile);
+ let expand =
option::map[str,
pp_mode](bind parse_pretty(sess, _),
getopts::opt_default(match, "expand", "normal"));
- alt (expand) {
- case (some[pp_mode](?ppm)) {
- pretty_print_input(sess, cfg, ifile, ppm, true);
- ret;
- }
- case (none[pp_mode]) {/* continue */ }
+ alt expand {
+ some[pp_mode](ppm) {
+ pretty_print_input(sess, cfg, ifile, ppm, true);
+ ret;
+ }
+ none[pp_mode]. {/* continue */ }
}
- auto pretty =
+ let pretty =
option::map[str,
pp_mode](bind parse_pretty(sess, _),
getopts::opt_default(match, "pretty", "normal"));
- alt (pretty) {
- case (some[pp_mode](?ppm)) {
- pretty_print_input(sess, cfg, ifile, ppm, false);
- ret;
- }
- case (none[pp_mode]) {/* continue */ }
+ alt pretty {
+ some[pp_mode](ppm) {
+ pretty_print_input(sess, cfg, ifile, ppm, false);
+ ret;
+ }
+ none[pp_mode]. {/* continue */ }
}
- auto ls = opt_present(match, "ls");
- if (ls) {
+ let ls = opt_present(match, "ls");
+ if ls {
metadata::creader::list_file_metadata(ifile, ioivec::stdout());
ret;
}
- auto stop_after_codegen = sopts.output_type != link::output_type_exe ||
- (sopts.static && sopts.library);
+ let stop_after_codegen =
+ sopts.output_type != link::output_type_exe ||
+ sopts.static && sopts.library;
- alt (output_file) {
- case (none) {
- let vec[str] parts = str::split(ifile, '.' as u8);
- vec::pop[str](parts);
- saved_out_filename = parts.(0);
- alt (sopts.output_type) {
- case (link::output_type_none) { parts += ["pp"]; }
- case (link::output_type_bitcode) { parts += ["bc"]; }
- case (link::output_type_assembly) { parts += ["s"]; }
- case (
- // Object and exe output both use the '.o' extension here
- link::output_type_object) {
- parts += ["o"];
- }
- case (link::output_type_exe) { parts += ["o"]; }
- }
- auto ofile = str::connect(parts, ".");
- compile_input(sess, cfg, ifile, ofile);
- }
- case (some(?ofile)) {
- // FIXME: what about windows? This will create a foo.exe.o.
+ alt output_file {
+ none. {
+ let parts: vec[str] = str::split(ifile, '.' as u8);
+ vec::pop[str](parts);
+ saved_out_filename = parts.(0);
+ alt sopts.output_type {
+ link::output_type_none. { parts += ["pp"]; }
+ link::output_type_bitcode. { parts += ["bc"]; }
+ link::output_type_assembly. { parts += ["s"]; }
- saved_out_filename = ofile;
- auto temp_filename;
- if (!stop_after_codegen) {
- temp_filename = ofile + ".o";
- } else {
- temp_filename = ofile;
- }
- compile_input(sess, cfg, ifile, temp_filename);
+ // Object and exe output both use the '.o' extension here
+ link::output_type_object. {
+ parts += ["o"];
+ }
+ link::output_type_exe. { parts += ["o"]; }
}
+ let ofile = str::connect(parts, ".");
+ compile_input(sess, cfg, ifile, ofile);
+ }
+ some(ofile) {
+ // FIXME: what about windows? This will create a foo.exe.o.
+
+ saved_out_filename = ofile;
+ let temp_filename;
+ if !stop_after_codegen {
+ temp_filename = ofile + ".o";
+ } else { temp_filename = ofile; }
+ compile_input(sess, cfg, ifile, temp_filename);
+ }
}
// If the user wants an exe generated we need to invoke
// gcc to link the object file with some libs
//
// TODO: Factor this out of main.
- if (stop_after_codegen) {
- ret;
- }
+ if stop_after_codegen { ret; }
- let str glu = binary_dir + "/lib/glue.o";
- let str main = binary_dir + "/lib/main.o";
- let str stage = "-L" + binary_dir + "/lib";
- let str prog = "gcc";
+ let glu: str = binary_dir + "/lib/glue.o";
+ let main: str = binary_dir + "/lib/main.o";
+ let stage: str = "-L" + binary_dir + "/lib";
+ let prog: str = "gcc";
// The invocations of gcc share some flags across platforms
- let vec[str] gcc_args =
- [stage, "-Lrt", "-lrustrt", glu, "-m32", "-o",
- saved_out_filename, saved_out_filename + ".o"];
- auto lib_cmd;
+ let gcc_args: vec[str] =
+ [stage, "-Lrt", "-lrustrt", glu, "-m32", "-o", saved_out_filename,
+ saved_out_filename + ".o"];
+ let lib_cmd;
- auto os = sess.get_targ_cfg().os;
- if (os == session::os_macos) {
- lib_cmd = "-dynamiclib";
- } else {
- lib_cmd = "-shared";
- }
+ let os = sess.get_targ_cfg().os;
+ if os == session::os_macos {
+ lib_cmd = "-dynamiclib";
+ } else { lib_cmd = "-shared"; }
// Converts a library file name into a gcc -l argument
- fn unlib(@session::config config, str filename) -> str {
- auto rmlib = bind fn(@session::config config,
- str filename) -> str {
- if (config.os == session::os_macos
- || config.os == session::os_linux
- && str::find(filename, "lib") == 0) {
- ret str::slice(filename, 3u, str::byte_len(filename));
- } else {
- ret filename;
- }
- } (config, _);
- fn rmext(str filename) -> str {
- auto parts = str::split(filename, '.' as u8);
+ fn unlib(config: @session::config, filename: str) -> str {
+ let rmlib =
+ bind fn (config: @session::config, filename: str) -> str {
+ if config.os == session::os_macos ||
+ config.os == session::os_linux &&
+ str::find(filename, "lib") == 0 {
+ ret str::slice(filename, 3u,
+ str::byte_len(filename));
+ } else { ret filename; }
+ }(config, _);
+ fn rmext(filename: str) -> str {
+ let parts = str::split(filename, '.' as u8);
vec::pop(parts);
ret str::connect(parts, ".");
}
- ret alt (config.os) {
- case (session::os_macos) { rmext(rmlib(filename)) }
- case (session::os_linux) { rmext(rmlib(filename)) }
- case (_) { rmext(filename) }
- };
+ ret alt config.os {
+ session::os_macos. { rmext(rmlib(filename)) }
+ session::os_linux. { rmext(rmlib(filename)) }
+ _ { rmext(filename) }
+ };
}
- auto cstore = sess.get_cstore();
- for (str cratepath in cstore::get_used_crate_files(cstore)) {
- if (str::ends_with(cratepath, ".rlib")) {
+ let cstore = sess.get_cstore();
+ for cratepath: str in cstore::get_used_crate_files(cstore) {
+ if str::ends_with(cratepath, ".rlib") {
gcc_args += [cratepath];
cont;
}
- auto dir = fs::dirname(cratepath);
- if (dir != "") {
- gcc_args += ["-L" + dir];
- }
- auto libarg = unlib(sess.get_targ_cfg(), fs::basename(cratepath));
+ let dir = fs::dirname(cratepath);
+ if dir != "" { gcc_args += ["-L" + dir]; }
+ let libarg = unlib(sess.get_targ_cfg(), fs::basename(cratepath));
gcc_args += ["-l" + libarg];
}
// FIXME: Remove this ivec->vec conversion.
- auto ula = cstore::get_used_link_args(cstore);
- for (str arg in ula) { gcc_args += [arg]; }
+ let ula = cstore::get_used_link_args(cstore);
+ for arg: str in ula { gcc_args += [arg]; }
- auto used_libs = cstore::get_used_libraries(cstore);
- for (str l in used_libs) {
- gcc_args += ["-l" + l];
- }
+ let used_libs = cstore::get_used_libraries(cstore);
+ for l: str in used_libs { gcc_args += ["-l" + l]; }
- if (sopts.library) {
+ if sopts.library {
gcc_args += [lib_cmd];
} else {
// FIXME: why do we hardcode -lm?
@@ -601,20 +584,21 @@
}
// We run 'gcc' here
- auto err_code = run::run_program(prog, gcc_args);
- if (0 != err_code) {
+ let err_code = run::run_program(prog, gcc_args);
+ if 0 != err_code {
sess.err(#fmt("linking with gcc failed with code %d", err_code));
sess.note(#fmt("gcc arguments: %s", str::connect(gcc_args, " ")));
sess.abort_if_errors();
}
// Clean up on Darwin
- if (sess.get_targ_cfg().os == session::os_macos) {
+ if sess.get_targ_cfg().os == session::os_macos {
run::run_program("dsymutil", [saved_out_filename]);
}
+
// Remove the temporary object file if we aren't saving temps
- if (!sopts.save_temps) {
+ if !sopts.save_temps {
run::run_program("rm", [saved_out_filename + ".o"]);
}
}
@@ -627,28 +611,29 @@
// When the user supplies --test we should implicitly supply --cfg test
#[test]
fn test_switch_implies_cfg_test() {
- auto match = alt (getopts::getopts(["--test"], opts())) {
- getopts::success(?m) { m }
- };
- auto sessopts = build_session_options("whatever", match, "whatever");
- auto sess = build_session(sessopts);
- auto cfg = build_configuration(sess, "whatever", "whatever");
- assert attr::contains_name(cfg, "test");
+ let match =
+ alt getopts::getopts(["--test"], opts()) {
+ getopts::success(m) { m }
+ };
+ let sessopts = build_session_options("whatever", match, "whatever");
+ let sess = build_session(sessopts);
+ let cfg = build_configuration(sess, "whatever", "whatever");
+ assert (attr::contains_name(cfg, "test"));
}
// When the user supplies --test and --cfg test, don't implicitly add
// another --cfg test
#[test]
fn test_switch_implies_cfg_test_unless_cfg_test() {
- auto match = alt (getopts::getopts(["--test",
- "--cfg=test"], opts())) {
- getopts::success(?m) { m }
- };
- auto sessopts = build_session_options("whatever", match, "whatever");
- auto sess = build_session(sessopts);
- auto cfg = build_configuration(sess, "whatever", "whatever");
- auto test_items = attr::find_meta_items_by_name(cfg, "test");
- assert ivec::len(test_items) == 1u;
+ let match =
+ alt getopts::getopts(["--test", "--cfg=test"], opts()) {
+ getopts::success(m) { m }
+ };
+ let sessopts = build_session_options("whatever", match, "whatever");
+ let sess = build_session(sessopts);
+ let cfg = build_configuration(sess, "whatever", "whatever");
+ let test_items = attr::find_meta_items_by_name(cfg, "test");
+ assert (ivec::len(test_items) == 1u);
}
}
diff --git a/src/comp/driver/session.rs b/src/comp/driver/session.rs
index b8db7ad..003584e 100644
--- a/src/comp/driver/session.rs
+++ b/src/comp/driver/session.rs
@@ -17,104 +17,97 @@
tag arch { arch_x86; arch_x64; arch_arm; }
type config =
- rec(os os,
- arch arch,
- ty_mach int_type,
- ty_mach uint_type,
- ty_mach float_type);
+ {os: os,
+ arch: arch,
+ int_type: ty_mach,
+ uint_type: ty_mach,
+ float_type: ty_mach};
type options =
- rec(bool library,
- bool static,
- uint optimize,
- bool debuginfo,
- bool verify,
- bool run_typestate,
- bool save_temps,
- bool stats,
- bool time_passes,
- bool time_llvm_passes,
- back::link::output_type output_type,
- str[] library_search_paths,
- str sysroot,
- // The crate config requested for the session, which may be combined
- // with additional crate configurations during the compile process
- ast::crate_cfg cfg,
- bool test,
- bool dps);
+ // The crate config requested for the session, which may be combined
+ // with additional crate configurations during the compile process
+ {library: bool,
+ static: bool,
+ optimize: uint,
+ debuginfo: bool,
+ verify: bool,
+ run_typestate: bool,
+ save_temps: bool,
+ stats: bool,
+ time_passes: bool,
+ time_llvm_passes: bool,
+ output_type: back::link::output_type,
+ library_search_paths: str[],
+ sysroot: str,
+ cfg: ast::crate_cfg,
+ test: bool,
+ dps: bool};
-type crate_metadata = rec(str name, u8[] data);
+type crate_metadata = {name: str, data: u8[]};
-obj session(@config targ_cfg,
- @options opts,
- metadata::cstore::cstore cstore,
- parse_sess parse_sess,
+obj session(targ_cfg: @config,
+ opts: @options,
+ cstore: metadata::cstore::cstore,
+ parse_sess: parse_sess,
+
// For a library crate, this is always none
- mutable option::t[node_id] main_fn,
- mutable uint err_count) {
+ mutable main_fn: option::t[node_id],
+ mutable err_count: uint) {
fn get_targ_cfg() -> @config { ret targ_cfg; }
fn get_opts() -> @options { ret opts; }
fn get_cstore() -> metadata::cstore::cstore { cstore }
- fn span_fatal(span sp, str msg) -> ! {
+ fn span_fatal(sp: span, msg: str) -> ! {
// FIXME: Use constants, but rustboot doesn't know how to export them.
codemap::emit_error(some(sp), msg, parse_sess.cm);
fail;
}
- fn fatal(str msg) -> ! {
+ fn fatal(msg: str) -> ! {
codemap::emit_error(none, msg, parse_sess.cm);
fail;
}
- fn span_err(span sp, str msg) {
+ fn span_err(sp: span, msg: str) {
codemap::emit_error(some(sp), msg, parse_sess.cm);
err_count += 1u;
}
- fn err(str msg) {
+ fn err(msg: str) {
codemap::emit_error(none, msg, parse_sess.cm);
err_count += 1u;
}
fn abort_if_errors() {
- if (err_count > 0u) {
- self.fatal("aborting due to previous errors");
- }
+ if err_count > 0u { self.fatal("aborting due to previous errors"); }
}
- fn span_warn(span sp, str msg) {
+ fn span_warn(sp: span, msg: str) {
// FIXME: Use constants, but rustboot doesn't know how to export them.
codemap::emit_warning(some(sp), msg, parse_sess.cm);
}
- fn warn(str msg) {
- codemap::emit_warning(none, msg, parse_sess.cm);
- }
- fn span_note(span sp, str msg) {
+ fn warn(msg: str) { codemap::emit_warning(none, msg, parse_sess.cm); }
+ fn span_note(sp: span, msg: str) {
// FIXME: Use constants, but rustboot doesn't know how to export them.
codemap::emit_note(some(sp), msg, parse_sess.cm);
}
- fn note(str msg) {
- codemap::emit_note(none, msg, parse_sess.cm);
- }
- fn span_bug(span sp, str msg) -> ! {
+ fn note(msg: str) { codemap::emit_note(none, msg, parse_sess.cm); }
+ fn span_bug(sp: span, msg: str) -> ! {
self.span_fatal(sp, #fmt("internal compiler error %s", msg));
}
- fn bug(str msg) -> ! {
+ fn bug(msg: str) -> ! {
self.fatal(#fmt("internal compiler error %s", msg));
}
- fn span_unimpl(span sp, str msg) -> ! {
+ fn span_unimpl(sp: span, msg: str) -> ! {
self.span_bug(sp, "unimplemented " + msg);
}
- fn unimpl(str msg) -> ! { self.bug("unimplemented " + msg); }
+ fn unimpl(msg: str) -> ! { self.bug("unimplemented " + msg); }
fn get_codemap() -> codemap::codemap { ret parse_sess.cm; }
- fn lookup_pos(uint pos) -> codemap::loc {
+ fn lookup_pos(pos: uint) -> codemap::loc {
ret codemap::lookup_char_pos(parse_sess.cm, pos);
}
fn get_parse_sess() -> parse_sess { ret parse_sess; }
fn next_node_id() -> ast::node_id {
ret syntax::parse::parser::next_node_id(parse_sess);
}
- fn span_str(span sp) -> str {
+ fn span_str(sp: span) -> str {
ret codemap::span_to_str(sp, self.get_codemap());
}
- fn set_main_id(node_id d) {
- main_fn = some(d);
- }
+ fn set_main_id(d: node_id) { main_fn = some(d); }
fn get_main_id() -> option::t[node_id] { main_fn }
}
// Local Variables:
diff --git a/src/comp/front/attr.rs b/src/comp/front/attr.rs
index 667c785..a8361ba 100644
--- a/src/comp/front/attr.rs
+++ b/src/comp/front/attr.rs
@@ -29,182 +29,159 @@
// From a list of crate attributes get only the meta_items that impact crate
// linkage
-fn find_linkage_metas(&ast::attribute[] attrs) -> (@ast::meta_item)[] {
- let (@ast::meta_item)[] metas = ~[];
- for (ast::attribute attr in find_attrs_by_name(attrs, "link")) {
- alt (attr.node.value.node) {
- case (ast::meta_list(_, ?items)) { metas += items; }
- case (_) {
- log "ignoring link attribute that has incorrect type";
- }
+fn find_linkage_metas(attrs: &ast::attribute[]) -> (@ast::meta_item)[] {
+ let metas: (@ast::meta_item)[] = ~[];
+ for attr: ast::attribute in find_attrs_by_name(attrs, "link") {
+ alt attr.node.value.node {
+ ast::meta_list(_, items) { metas += items; }
+ _ { log "ignoring link attribute that has incorrect type"; }
}
}
ret metas;
}
// Search a list of attributes and return only those with a specific name
-fn find_attrs_by_name(&ast::attribute[] attrs,
- ast::ident name) -> ast::attribute[] {
- auto filter = bind fn(&ast::attribute a,
- ast::ident name) -> option::t[ast::attribute] {
- if (get_attr_name(a) == name) {
- option::some(a)
- } else {
- option::none
- }
- } (_, name);
+fn find_attrs_by_name(attrs: &ast::attribute[], name: ast::ident) ->
+ ast::attribute[] {
+ let filter =
+ bind fn (a: &ast::attribute, name: ast::ident) ->
+ option::t[ast::attribute] {
+ if get_attr_name(a) == name {
+ option::some(a)
+ } else { option::none }
+ }(_, name);
ret ivec::filter_map(filter, attrs);
}
-fn get_attr_name(&ast::attribute attr) -> ast::ident {
+fn get_attr_name(attr: &ast::attribute) -> ast::ident {
get_meta_item_name(@attr.node.value)
}
-fn find_meta_items_by_name(&(@ast::meta_item)[] metas,
- ast::ident name) -> (@ast::meta_item)[] {
- auto filter = bind fn(&@ast::meta_item m,
- ast::ident name) -> option::t[@ast::meta_item] {
- if (get_meta_item_name(m) == name) {
- option::some(m)
- } else {
- option::none
- }
- } (_, name);
+fn find_meta_items_by_name(metas: &(@ast::meta_item)[], name: ast::ident) ->
+ (@ast::meta_item)[] {
+ let filter =
+ bind fn (m: &@ast::meta_item, name: ast::ident) ->
+ option::t[@ast::meta_item] {
+ if get_meta_item_name(m) == name {
+ option::some(m)
+ } else { option::none }
+ }(_, name);
ret ivec::filter_map(filter, metas);
}
-fn get_meta_item_name(&@ast::meta_item meta) -> ast::ident {
- alt (meta.node) {
- case (ast::meta_word(?n)) { n }
- case (ast::meta_name_value(?n, _)) { n }
- case (ast::meta_list(?n, _)) { n }
+fn get_meta_item_name(meta: &@ast::meta_item) -> ast::ident {
+ alt meta.node {
+ ast::meta_word(n) { n }
+ ast::meta_name_value(n, _) { n }
+ ast::meta_list(n, _) { n }
}
}
// Gets the string value if the meta_item is a meta_name_value variant
// containing a string, otherwise none
-fn get_meta_item_value_str(&@ast::meta_item meta) -> option::t[str] {
- alt (meta.node) {
- case (ast::meta_name_value(_, ?v)) {
- alt (v.node) {
- case (ast::lit_str(?s, _)) {
- option::some(s)
- }
- case (_) { option::none }
- }
+fn get_meta_item_value_str(meta: &@ast::meta_item) -> option::t[str] {
+ alt meta.node {
+ ast::meta_name_value(_, v) {
+ alt v.node {
+ ast::lit_str(s, _) { option::some(s) }
+ _ { option::none }
}
- case (_) { option::none }
+ }
+ _ { option::none }
}
}
-fn attr_meta(&ast::attribute attr) -> @ast::meta_item { @attr.node.value }
+fn attr_meta(attr: &ast::attribute) -> @ast::meta_item { @attr.node.value }
// Get the meta_items from inside a vector of attributes
-fn attr_metas(&ast::attribute[] attrs) -> (@ast::meta_item)[] {
- auto mitems = ~[];
- for (ast::attribute a in attrs) { mitems += ~[attr_meta(a)]; }
+fn attr_metas(attrs: &ast::attribute[]) -> (@ast::meta_item)[] {
+ let mitems = ~[];
+ for a: ast::attribute in attrs { mitems += ~[attr_meta(a)]; }
ret mitems;
}
-fn eq(@ast::meta_item a, @ast::meta_item b) -> bool {
- ret alt (a.node) {
- case (ast::meta_word(?na)) {
- alt (b.node) {
- case(ast::meta_word(?nb)) { na == nb }
- case(_) { false }
+fn eq(a: @ast::meta_item, b: @ast::meta_item) -> bool {
+ ret alt a.node {
+ ast::meta_word(na) {
+ alt b.node { ast::meta_word(nb) { na == nb } _ { false } }
+ }
+ ast::meta_name_value(na, va) {
+ alt b.node {
+ ast::meta_name_value(nb, vb) { na == nb && va.node == vb.node }
+ _ { false }
}
- }
- case (ast::meta_name_value(?na, ?va)) {
- alt (b.node) {
- case (ast::meta_name_value(?nb, ?vb)) {
- na == nb && va.node == vb.node
- }
- case (_) { false }
- }
- }
- case (ast::meta_list(?na, ?la)) {
+ }
+ ast::meta_list(na, la) {
+
// FIXME (#607): Needs implementing
// This involves probably sorting the list by name and
// meta_item variant
fail "unimplemented meta_item variant"
+ }
}
- }
}
-fn contains(&(@ast::meta_item)[] haystack, @ast::meta_item needle) -> bool {
+fn contains(haystack: &(@ast::meta_item)[], needle: @ast::meta_item) -> bool {
log #fmt("looking for %s",
syntax::print::pprust::meta_item_to_str(*needle));
- for (@ast::meta_item item in haystack) {
+ for item: @ast::meta_item in haystack {
log #fmt("looking in %s",
syntax::print::pprust::meta_item_to_str(*item));
- if (eq(item, needle)) {
- log "found it!";
- ret true;
- }
+ if eq(item, needle) { log "found it!"; ret true; }
}
log "found it not :(";
ret false;
}
-fn contains_name(&(@ast::meta_item)[] metas, ast::ident name) -> bool {
- auto matches = find_meta_items_by_name(metas, name);
+fn contains_name(metas: &(@ast::meta_item)[], name: ast::ident) -> bool {
+ let matches = find_meta_items_by_name(metas, name);
ret ivec::len(matches) > 0u;
}
// FIXME: This needs to sort by meta_item variant in addition to the item name
-fn sort_meta_items(&(@ast::meta_item)[] items) -> (@ast::meta_item)[] {
- fn lteq(&@ast::meta_item ma, &@ast::meta_item mb) -> bool {
- fn key(&@ast::meta_item m) -> ast::ident {
- alt (m.node) {
- case (ast::meta_word(?name)) {
- name
- }
- case (ast::meta_name_value(?name, _)) {
- name
- }
- case (ast::meta_list(?name, _)) {
- name
- }
+fn sort_meta_items(items: &(@ast::meta_item)[]) -> (@ast::meta_item)[] {
+ fn lteq(ma: &@ast::meta_item, mb: &@ast::meta_item) -> bool {
+ fn key(m: &@ast::meta_item) -> ast::ident {
+ alt m.node {
+ ast::meta_word(name) { name }
+ ast::meta_name_value(name, _) { name }
+ ast::meta_list(name, _) { name }
}
}
ret key(ma) <= key(mb);
}
// This is sort of stupid here, converting to a vec of mutables and back
- let (@ast::meta_item)[mutable] v = ~[mutable];
- for (@ast::meta_item mi in items) {
- v += ~[mutable mi];
- }
+ let v: (@ast::meta_item)[mutable ] = ~[mutable ];
+ for mi: @ast::meta_item in items { v += ~[mutable mi]; }
std::sort::ivector::quick_sort(lteq, v);
- let (@ast::meta_item)[] v2 = ~[];
- for (@ast::meta_item mi in v) {
- v2 += ~[mi];
- }
+ let v2: (@ast::meta_item)[] = ~[];
+ for mi: @ast::meta_item in v { v2 += ~[mi]; }
ret v2;
}
-fn remove_meta_items_by_name(&(@ast::meta_item)[] items,
- str name) -> (@ast::meta_item)[] {
+fn remove_meta_items_by_name(items: &(@ast::meta_item)[], name: str) ->
+ (@ast::meta_item)[] {
- auto filter = bind fn(&@ast::meta_item item,
- str name) -> option::t[@ast::meta_item] {
- if (get_meta_item_name(item) != name) {
- option::some(item)
- } else {
- option::none
- }
- } (_, name);
+ let filter =
+ bind fn (item: &@ast::meta_item, name: str) ->
+ option::t[@ast::meta_item] {
+ if get_meta_item_name(item) != name {
+ option::some(item)
+ } else { option::none }
+ }(_, name);
ret ivec::filter_map(filter, items);
}
-fn require_unique_names(&session::session sess, &(@ast::meta_item)[] metas) {
- auto map = map::mk_hashmap[str, ()](str::hash, str::eq);
- for (@ast::meta_item meta in metas) {
- auto name = get_meta_item_name(meta);
- if (map.contains_key(name)) {
+fn require_unique_names(sess: &session::session,
+ metas: &(@ast::meta_item)[]) {
+ let map = map::mk_hashmap[str, ()](str::hash, str::eq);
+ for meta: @ast::meta_item in metas {
+ let name = get_meta_item_name(meta);
+ if map.contains_key(name) {
sess.span_fatal(meta.span,
#fmt("duplicate meta item `%s`", name));
}
@@ -212,31 +189,30 @@
}
}
-fn span[T](&T item) -> ast::spanned[T] {
- ret rec(node=item, span=rec(lo=0u, hi=0u));
+fn span[T](item: &T) -> ast::spanned[T] {
+ ret {node: item, span: {lo: 0u, hi: 0u}};
}
-fn mk_name_value_item_str(ast::ident name, str value) -> @ast::meta_item {
- auto value_lit = span(ast::lit_str(value, ast::sk_rc));
+fn mk_name_value_item_str(name: ast::ident, value: str) -> @ast::meta_item {
+ let value_lit = span(ast::lit_str(value, ast::sk_rc));
ret mk_name_value_item(name, value_lit);
}
-fn mk_name_value_item(ast::ident name, ast::lit value) -> @ast::meta_item {
+fn mk_name_value_item(name: ast::ident, value: ast::lit) -> @ast::meta_item {
ret @span(ast::meta_name_value(name, value));
}
-fn mk_list_item(ast::ident name, &(@ast::meta_item)[] items)
- -> @ast::meta_item {
+fn mk_list_item(name: ast::ident, items: &(@ast::meta_item)[]) ->
+ @ast::meta_item {
ret @span(ast::meta_list(name, items));
}
-fn mk_word_item(ast::ident name) -> @ast::meta_item {
+fn mk_word_item(name: ast::ident) -> @ast::meta_item {
ret @span(ast::meta_word(name));
}
-fn mk_attr(@ast::meta_item item) -> ast::attribute {
- ret span(rec(style = ast::attr_inner,
- value = *item));
+fn mk_attr(item: @ast::meta_item) -> ast::attribute {
+ ret span({style: ast::attr_inner, value: *item});
}
//
diff --git a/src/comp/front/config.rs b/src/comp/front/config.rs
index 592305b..1107e69 100644
--- a/src/comp/front/config.rs
+++ b/src/comp/front/config.rs
@@ -8,124 +8,120 @@
// Support conditional compilation by transforming the AST, stripping out
// any items that do not belong in the current configuration
-fn strip_unconfigured_items(@ast::crate crate) -> @ast::crate {
- auto cfg = crate.node.config;
+fn strip_unconfigured_items(crate: @ast::crate) -> @ast::crate {
+ let cfg = crate.node.config;
- auto precursor = rec(fold_mod = bind fold_mod(cfg, _, _),
- fold_block = bind fold_block(cfg, _, _),
- fold_native_mod = bind fold_native_mod(cfg, _, _)
- with *fold::default_ast_fold());
+ let precursor =
+ {fold_mod: bind fold_mod(cfg, _, _),
+ fold_block: bind fold_block(cfg, _, _),
+ fold_native_mod: bind fold_native_mod(cfg, _, _)
+ with *fold::default_ast_fold()};
- auto fold = fold::make_fold(precursor);
- auto res = @fold.fold_crate(*crate);
+ let fold = fold::make_fold(precursor);
+ let res = @fold.fold_crate(*crate);
// FIXME: This is necessary to break a circular reference
fold::dummy_out(fold);
ret res;
}
-fn filter_item(&ast::crate_cfg cfg,
- &@ast::item item) -> option::t[@ast::item] {
- if (item_in_cfg(cfg, item)) {
+fn filter_item(cfg: &ast::crate_cfg, item: &@ast::item) ->
+ option::t[@ast::item] {
+ if item_in_cfg(cfg, item) { option::some(item) } else { option::none }
+}
+
+fn fold_mod(cfg: &ast::crate_cfg, m: &ast::_mod, fld: fold::ast_fold) ->
+ ast::_mod {
+ let filter = bind filter_item(cfg, _);
+ let filtered_items = ivec::filter_map(filter, m.items);
+ ret {view_items: ivec::map(fld.fold_view_item, m.view_items),
+ items: ivec::map(fld.fold_item, filtered_items)};
+}
+
+fn filter_native_item(cfg: &ast::crate_cfg, item: &@ast::native_item) ->
+ option::t[@ast::native_item] {
+ if native_item_in_cfg(cfg, item) {
option::some(item)
- } else {
- option::none
- }
+ } else { option::none }
}
-fn fold_mod(&ast::crate_cfg cfg, &ast::_mod m,
- fold::ast_fold fld) -> ast::_mod {
- auto filter = bind filter_item(cfg, _);
- auto filtered_items = ivec::filter_map(filter, m.items);
- ret rec(view_items=ivec::map(fld.fold_view_item, m.view_items),
- items=ivec::map(fld.fold_item, filtered_items));
+fn fold_native_mod(cfg: &ast::crate_cfg, nm: &ast::native_mod,
+ fld: fold::ast_fold) -> ast::native_mod {
+ let filter = bind filter_native_item(cfg, _);
+ let filtered_items = ivec::filter_map(filter, nm.items);
+ ret {native_name: nm.native_name,
+ abi: nm.abi,
+ view_items: ivec::map(fld.fold_view_item, nm.view_items),
+ items: filtered_items};
}
-fn filter_native_item(&ast::crate_cfg cfg, &@ast::native_item item)
- -> option::t[@ast::native_item] {
- if (native_item_in_cfg(cfg, item)) {
- option::some(item)
- } else {
- option::none
- }
-}
-
-fn fold_native_mod(&ast::crate_cfg cfg, &ast::native_mod nm,
- fold::ast_fold fld) -> ast::native_mod {
- auto filter = bind filter_native_item(cfg, _);
- auto filtered_items = ivec::filter_map(filter, nm.items);
- ret rec(native_name=nm.native_name,
- abi=nm.abi,
- view_items=ivec::map(fld.fold_view_item, nm.view_items),
- items=filtered_items);
-}
-
-fn filter_stmt(&ast::crate_cfg cfg,
- &@ast::stmt stmt) -> option::t[@ast::stmt] {
- alt (stmt.node) {
- case (ast::stmt_decl(?decl, _)) {
- alt (decl.node) {
- case (ast::decl_item(?item)) {
- if (item_in_cfg(cfg, item)) {
- option::some(stmt)
- } else {
- option::none
- }
- }
- case (_) { option::some(stmt) }
- }
+fn filter_stmt(cfg: &ast::crate_cfg, stmt: &@ast::stmt) ->
+ option::t[@ast::stmt] {
+ alt stmt.node {
+ ast::stmt_decl(decl, _) {
+ alt decl.node {
+ ast::decl_item(item) {
+ if item_in_cfg(cfg, item) {
+ option::some(stmt)
+ } else { option::none }
+ }
+ _ { option::some(stmt) }
}
- case (_) { option::some(stmt) }
+ }
+ _ { option::some(stmt) }
}
}
-fn fold_block(&ast::crate_cfg cfg, &ast::blk_ b,
- fold::ast_fold fld) -> ast::blk_ {
- auto filter = bind filter_stmt(cfg, _);
- auto filtered_stmts = ivec::filter_map(filter, b.stmts);
- ret rec(stmts=ivec::map(fld.fold_stmt, filtered_stmts),
- expr=option::map(fld.fold_expr, b.expr),
- id=b.id);
+fn fold_block(cfg: &ast::crate_cfg, b: &ast::blk_, fld: fold::ast_fold) ->
+ ast::blk_ {
+ let filter = bind filter_stmt(cfg, _);
+ let filtered_stmts = ivec::filter_map(filter, b.stmts);
+ ret {stmts: ivec::map(fld.fold_stmt, filtered_stmts),
+ expr: option::map(fld.fold_expr, b.expr),
+ id: b.id};
}
-fn item_in_cfg(&ast::crate_cfg cfg, &@ast::item item) -> bool {
+fn item_in_cfg(cfg: &ast::crate_cfg, item: &@ast::item) -> bool {
ret in_cfg(cfg, item.attrs);
}
-fn native_item_in_cfg(&ast::crate_cfg cfg, &@ast::native_item item) -> bool {
+fn native_item_in_cfg(cfg: &ast::crate_cfg, item: &@ast::native_item) ->
+ bool {
ret in_cfg(cfg, item.attrs);
}
// Determine if an item should be translated in the current crate
// configuration based on the item's attributes
-fn in_cfg(&ast::crate_cfg cfg, &ast::attribute[] attrs) -> bool {
+fn in_cfg(cfg: &ast::crate_cfg, attrs: &ast::attribute[]) -> bool {
// The "cfg" attributes on the item
- auto item_cfg_attrs = attr::find_attrs_by_name(attrs, "cfg");
- auto item_has_cfg_attrs = ivec::len(item_cfg_attrs) > 0u;
- if (!item_has_cfg_attrs) { ret true; }
+ let item_cfg_attrs = attr::find_attrs_by_name(attrs, "cfg");
+ let item_has_cfg_attrs = ivec::len(item_cfg_attrs) > 0u;
+ if !item_has_cfg_attrs { ret true; }
// Pull the inner meta_items from the #[cfg(meta_item, ...)] attributes,
// so we can match against them. This is the list of configurations for
// which the item is valid
- auto item_cfg_metas = {
- fn extract_metas(&(@ast::meta_item)[] inner_items,
- &@ast::meta_item cfg_item)
- -> (@ast::meta_item)[] {
+ let
- alt (cfg_item.node) {
- case (ast::meta_list(?name, ?items)) {
- assert name == "cfg";
+ item_cfg_metas =
+ {
+ fn extract_metas(inner_items: &(@ast::meta_item)[],
+ cfg_item: &@ast::meta_item) ->
+ (@ast::meta_item)[] {
+ alt cfg_item.node {
+ ast::meta_list(name, items) {
+ assert (name == "cfg");
inner_items + items
+ }
+ _ { inner_items }
}
- case (_) { inner_items }
}
- }
- auto cfg_metas = attr::attr_metas(item_cfg_attrs);
- ivec::foldl(extract_metas, ~[], cfg_metas)
- };
+ let cfg_metas = attr::attr_metas(item_cfg_attrs);
+ ivec::foldl(extract_metas, ~[], cfg_metas)
+ };
- for (@ast::meta_item cfg_mi in item_cfg_metas) {
- if (attr::contains(cfg, cfg_mi)) { ret true; }
+ for cfg_mi: @ast::meta_item in item_cfg_metas {
+ if attr::contains(cfg, cfg_mi) { ret true; }
}
ret false;
diff --git a/src/comp/front/test.rs b/src/comp/front/test.rs
index dc04c8b..8f4afc8 100644
--- a/src/comp/front/test.rs
+++ b/src/comp/front/test.rs
@@ -9,125 +9,124 @@
export modify_for_testing;
-type node_id_gen = @fn() -> ast::node_id;
+type node_id_gen = @fn() -> ast::node_id ;
-type test = rec(ast::ident[] path,
- bool ignore);
+type test = {path: ast::ident[], ignore: bool};
-type test_ctxt = @rec(node_id_gen next_node_id,
- mutable ast::ident[] path,
- mutable test[] testfns);
+type test_ctxt =
+ @{next_node_id: node_id_gen,
+ mutable path: ast::ident[],
+ mutable testfns: test[]};
// Traverse the crate, collecting all the test functions, eliding any
// existing main functions, and synthesizing a main test harness
-fn modify_for_testing(@ast::crate crate) -> @ast::crate {
+fn modify_for_testing(crate: @ast::crate) -> @ast::crate {
// FIXME: This hackasaurus assumes that 200000 is a safe number to start
// generating node_ids at (which is totally not the case). pauls is going
// to land a patch that puts parse_sess into session, which will give us
// access to the real next node_id.
- auto next_node_id = @mutable 200000;
- auto next_node_id_fn = @bind fn(@mutable ast::node_id next_node_id)
- -> ast::node_id {
- auto this_node_id = *next_node_id;
- *next_node_id = next_node_id + 1;
- ret this_node_id;
- } (next_node_id);
+ let next_node_id = @mutable 200000;
+ let next_node_id_fn =
+ @bind fn (next_node_id: @mutable ast::node_id) -> ast::node_id {
+ let this_node_id = *next_node_id;
+ *next_node_id = next_node_id + 1;
+ ret this_node_id;
+ }(next_node_id);
- let test_ctxt cx = @rec(next_node_id = next_node_id_fn,
- mutable path = ~[],
- mutable testfns = ~[]);
+ let cx: test_ctxt =
+ @{next_node_id: next_node_id_fn,
+ mutable path: ~[],
+ mutable testfns: ~[]};
- auto precursor = rec(fold_crate = bind fold_crate(cx, _, _),
- fold_item = bind fold_item(cx, _, _),
- fold_mod = bind fold_mod(cx, _, _)
- with *fold::default_ast_fold());
+ let precursor =
+ {fold_crate: bind fold_crate(cx, _, _),
+ fold_item: bind fold_item(cx, _, _),
+ fold_mod: bind fold_mod(cx, _, _) with *fold::default_ast_fold()};
- auto fold = fold::make_fold(precursor);
- auto res = @fold.fold_crate(*crate);
+ let fold = fold::make_fold(precursor);
+ let res = @fold.fold_crate(*crate);
// FIXME: This is necessary to break a circular reference
fold::dummy_out(fold);
ret res;
}
-fn fold_mod(&test_ctxt cx, &ast::_mod m,
- fold::ast_fold fld) -> ast::_mod {
+fn fold_mod(cx: &test_ctxt, m: &ast::_mod, fld: fold::ast_fold) -> ast::_mod {
// Remove any defined main function from the AST so it doesn't clash with
// the one we're going to add. FIXME: This is sloppy. Instead we should
// have some mechanism to indicate to the translation pass which function
// we want to be main.
- fn nomain(&@ast::item item) -> option::t[@ast::item] {
- alt (item.node) {
- ast::item_fn(?f, _) {
- if (item.ident == "main") { option::none }
- else { option::some(item) }
- }
- _ { option::some(item) }
+ fn nomain(item: &@ast::item) -> option::t[@ast::item] {
+ alt item.node {
+ ast::item_fn(f, _) {
+ if item.ident == "main" {
+ option::none
+ } else { option::some(item) }
+ }
+ _ { option::some(item) }
}
}
- auto mod_nomain = rec(view_items=m.view_items,
- items=ivec::filter_map(nomain, m.items));
+ let mod_nomain =
+ {view_items: m.view_items, items: ivec::filter_map(nomain, m.items)};
ret fold::noop_fold_mod(mod_nomain, fld);
}
-fn fold_crate(&test_ctxt cx, &ast::crate_ c,
- fold::ast_fold fld) -> ast::crate_ {
- auto folded = fold::noop_fold_crate(c, fld);
+fn fold_crate(cx: &test_ctxt, c: &ast::crate_, fld: fold::ast_fold) ->
+ ast::crate_ {
+ let folded = fold::noop_fold_crate(c, fld);
// Add a special __test module to the crate that will contain code
// generated for the test harness
- ret rec(module = add_test_module(cx, folded.module)
- with folded);
+ ret {module: add_test_module(cx, folded.module) with folded};
}
-fn fold_item(&test_ctxt cx, &@ast::item i,
- fold::ast_fold fld) -> @ast::item {
+fn fold_item(cx: &test_ctxt, i: &@ast::item, fld: fold::ast_fold) ->
+ @ast::item {
cx.path += ~[i.ident];
log #fmt("current path: %s", ast::path_name_i(cx.path));
- if (is_test_fn(i)) {
+ if is_test_fn(i) {
log "this is a test function";
- auto test = rec(path = cx.path,
- ignore = is_ignored(i));
+ let test = {path: cx.path, ignore: is_ignored(i)};
cx.testfns += ~[test];
log #fmt("have %u test functions", ivec::len(cx.testfns));
}
- auto res = fold::noop_fold_item(i, fld);
+ let res = fold::noop_fold_item(i, fld);
ivec::pop(cx.path);
ret res;
}
-fn is_test_fn(&@ast::item i) -> bool {
- auto has_test_attr =
+fn is_test_fn(i: &@ast::item) -> bool {
+ let has_test_attr =
ivec::len(attr::find_attrs_by_name(i.attrs, "test")) > 0u;
- fn has_test_signature(&@ast::item i) -> bool {
- alt (i.node) {
- case (ast::item_fn(?f, ?tps)) {
- auto input_cnt = ivec::len(f.decl.inputs);
- auto no_output = f.decl.output.node == ast::ty_nil;
- auto tparm_cnt = ivec::len(tps);
- input_cnt == 0u && no_output && tparm_cnt == 0u
- }
- case (_) { false }
+ fn has_test_signature(i: &@ast::item) -> bool {
+ alt i.node {
+ ast::item_fn(f, tps) {
+ let input_cnt = ivec::len(f.decl.inputs);
+ let no_output = f.decl.output.node == ast::ty_nil;
+ let tparm_cnt = ivec::len(tps);
+ input_cnt == 0u && no_output && tparm_cnt == 0u
+ }
+ _ { false }
}
}
ret has_test_attr && has_test_signature(i);
}
-fn is_ignored(&@ast::item i) -> bool {
+fn is_ignored(i: &@ast::item) -> bool {
attr::contains_name(attr::attr_metas(i.attrs), "ignore")
}
-fn add_test_module(&test_ctxt cx, &ast::_mod m) -> ast::_mod {
- auto testmod = mk_test_module(cx);
- ret rec(items=m.items + ~[testmod] with m);
+fn add_test_module(cx: &test_ctxt, m: &ast::_mod) -> ast::_mod {
+ let testmod = mk_test_module(cx);
+ ret {items: m.items + ~[testmod] with m};
}
/*
@@ -147,241 +146,231 @@
*/
-fn mk_test_module(&test_ctxt cx) -> @ast::item {
+fn mk_test_module(cx: &test_ctxt) -> @ast::item {
// A function that generates a vector of test descriptors to feed to the
// test runner
- auto testsfn = mk_tests(cx);
+ let testsfn = mk_tests(cx);
// The synthesized main function which will call the console test runner
// with our list of tests
- auto mainfn = mk_main(cx);
- let ast::_mod testmod = rec(view_items=~[],
- items=~[mainfn, testsfn]);
- auto item_ = ast::item_mod(testmod);
- let ast::item item = rec(ident = "__test",
- attrs = ~[],
- id = cx.next_node_id(),
- node = item_,
- span = rec(lo=0u, hi=0u));
+ let mainfn = mk_main(cx);
+ let testmod: ast::_mod = {view_items: ~[], items: ~[mainfn, testsfn]};
+ let item_ = ast::item_mod(testmod);
+ let item: ast::item =
+ {ident: "__test",
+ attrs: ~[],
+ id: cx.next_node_id(),
+ node: item_,
+ span: {lo: 0u, hi: 0u}};
log #fmt("Synthetic test module:\n%s\n", pprust::item_to_str(@item));
ret @item;
}
-fn nospan[T](&T t) -> ast::spanned[T] {
- ret rec(node=t,
- span=rec(lo=0u,hi=0u));
+fn nospan[T](t: &T) -> ast::spanned[T] {
+ ret {node: t, span: {lo: 0u, hi: 0u}};
}
-fn mk_tests(&test_ctxt cx) -> @ast::item {
- auto ret_ty = mk_test_desc_ivec_ty(cx);
+fn mk_tests(cx: &test_ctxt) -> @ast::item {
+ let ret_ty = mk_test_desc_ivec_ty(cx);
- let ast::fn_decl decl = rec(inputs = ~[],
- output = ret_ty,
- purity = ast::impure_fn,
- cf = ast::return,
- constraints = ~[]);
- auto proto = ast::proto_fn;
+ let decl: ast::fn_decl =
+ {inputs: ~[],
+ output: ret_ty,
+ purity: ast::impure_fn,
+ cf: ast::return,
+ constraints: ~[]};
+ let proto = ast::proto_fn;
// The vector of test_descs for this crate
- auto test_descs = mk_test_desc_vec(cx);
+ let test_descs = mk_test_desc_vec(cx);
- let ast::blk_ body_= rec(stmts = ~[],
- expr = option::some(test_descs),
- id = cx.next_node_id());
- auto body = nospan(body_);
+ let body_: ast::blk_ =
+ {stmts: ~[], expr: option::some(test_descs), id: cx.next_node_id()};
+ let body = nospan(body_);
- auto fn_ = rec(decl = decl,
- proto = proto,
- body = body);
+ let fn_ = {decl: decl, proto: proto, body: body};
- auto item_ = ast::item_fn(fn_, ~[]);
- let ast::item item = rec(ident = "tests",
- attrs = ~[],
- id = cx.next_node_id(),
- node = item_,
- span = rec(lo=0u, hi=0u));
+ let item_ = ast::item_fn(fn_, ~[]);
+ let item: ast::item =
+ {ident: "tests",
+ attrs: ~[],
+ id: cx.next_node_id(),
+ node: item_,
+ span: {lo: 0u, hi: 0u}};
ret @item;
}
fn empty_fn_ty() -> ast::ty {
- auto proto = ast::proto_fn;
- auto input_ty = ~[];
- auto ret_ty = @nospan(ast::ty_nil);
- auto cf = ast::return;
- auto constrs = ~[];
+ let proto = ast::proto_fn;
+ let input_ty = ~[];
+ let ret_ty = @nospan(ast::ty_nil);
+ let cf = ast::return;
+ let constrs = ~[];
ret nospan(ast::ty_fn(proto, input_ty, ret_ty, cf, constrs));
}
// The ast::ty of std::test::test_desc[]
-fn mk_test_desc_ivec_ty(&test_ctxt cx) -> @ast::ty {
- let ast::path test_desc_ty_path = nospan(rec(global = false,
- idents = ~["std",
- "test",
- "test_desc"],
- types = ~[]));
+fn mk_test_desc_ivec_ty(cx: &test_ctxt) -> @ast::ty {
+ let test_desc_ty_path: ast::path =
+ nospan({global: false,
+ idents: ~["std", "test", "test_desc"],
+ types: ~[]});
- let ast::ty test_desc_ty = nospan(ast::ty_path(test_desc_ty_path,
- cx.next_node_id()));
+ let test_desc_ty: ast::ty =
+ nospan(ast::ty_path(test_desc_ty_path, cx.next_node_id()));
- let ast::mt ivec_mt = rec(ty = @test_desc_ty,
- mut = ast::imm);
+ let ivec_mt: ast::mt = {ty: @test_desc_ty, mut: ast::imm};
ret @nospan(ast::ty_ivec(ivec_mt));
}
-fn mk_test_desc_vec(&test_ctxt cx) -> @ast::expr {
- log #fmt("building test vector from %u tests",
- ivec::len(cx.testfns));
- auto descs = ~[];
- for (test test in cx.testfns) {
- auto test_ = test; // Satisfy alias analysis
+fn mk_test_desc_vec(cx: &test_ctxt) -> @ast::expr {
+ log #fmt("building test vector from %u tests", ivec::len(cx.testfns));
+ let descs = ~[];
+ for test: test in cx.testfns {
+ let test_ = test; // Satisfy alias analysis
descs += ~[mk_test_desc_rec(cx, test_)];
}
- ret @rec(id = cx.next_node_id(),
- node = ast::expr_vec(descs, ast::imm, ast::sk_unique),
- span = rec(lo=0u,hi=0u));
+ ret @{id: cx.next_node_id(),
+ node: ast::expr_vec(descs, ast::imm, ast::sk_unique),
+ span: {lo: 0u, hi: 0u}};
}
-fn mk_test_desc_rec(&test_ctxt cx, test test) -> @ast::expr {
- auto path = test.path;
+fn mk_test_desc_rec(cx: &test_ctxt, test: test) -> @ast::expr {
+ let path = test.path;
log #fmt("encoding %s", ast::path_name_i(path));
- let ast::lit name_lit = nospan(ast::lit_str(ast::path_name_i(path),
- ast::sk_rc));
- let ast::expr name_expr = rec(id = cx.next_node_id(),
- node = ast::expr_lit(@name_lit),
- span = rec(lo=0u, hi=0u));
+ let name_lit: ast::lit =
+ nospan(ast::lit_str(ast::path_name_i(path), ast::sk_rc));
+ let name_expr: ast::expr =
+ {id: cx.next_node_id(),
+ node: ast::expr_lit(@name_lit),
+ span: {lo: 0u, hi: 0u}};
- let ast::field name_field = nospan(rec(mut = ast::imm,
- ident = "name",
- expr = @name_expr));
+ let name_field: ast::field =
+ nospan({mut: ast::imm, ident: "name", expr: @name_expr});
- let ast::path fn_path = nospan(rec(global = false,
- idents = path,
- types = ~[]));
+ let fn_path: ast::path =
+ nospan({global: false, idents: path, types: ~[]});
- let ast::expr fn_expr = rec(id = cx.next_node_id(),
- node = ast::expr_path(fn_path),
- span = rec(lo=0u, hi=0u));
+ let fn_expr: ast::expr =
+ {id: cx.next_node_id(),
+ node: ast::expr_path(fn_path),
+ span: {lo: 0u, hi: 0u}};
- let ast::field fn_field = nospan(rec(mut = ast::imm,
- ident = "fn",
- expr = @fn_expr));
+ let fn_field: ast::field =
+ nospan({mut: ast::imm, ident: "fn", expr: @fn_expr});
- let ast::lit ignore_lit = nospan(ast::lit_bool(test.ignore));
+ let ignore_lit: ast::lit = nospan(ast::lit_bool(test.ignore));
- let ast::expr ignore_expr = rec(id = cx.next_node_id(),
- node = ast::expr_lit(@ignore_lit),
- span = rec(lo=0u, hi=0u));
+ let ignore_expr: ast::expr =
+ {id: cx.next_node_id(),
+ node: ast::expr_lit(@ignore_lit),
+ span: {lo: 0u, hi: 0u}};
- let ast::field ignore_field = nospan(rec(mut = ast::imm,
- ident = "ignore",
- expr = @ignore_expr));
+ let ignore_field: ast::field =
+ nospan({mut: ast::imm, ident: "ignore", expr: @ignore_expr});
- let ast::expr_ desc_rec_ = ast::expr_rec(~[name_field,
- fn_field,
- ignore_field],
- option::none);
- let ast::expr desc_rec = rec(id = cx.next_node_id(),
- node = desc_rec_,
- span = rec(lo=0u, hi=0u));
+ let desc_rec_: ast::expr_ =
+ ast::expr_rec(~[name_field, fn_field, ignore_field], option::none);
+ let desc_rec: ast::expr =
+ {id: cx.next_node_id(), node: desc_rec_, span: {lo: 0u, hi: 0u}};
ret @desc_rec;
}
-fn mk_main(&test_ctxt cx) -> @ast::item {
+fn mk_main(cx: &test_ctxt) -> @ast::item {
- let ast::mt args_mt = rec(ty = @nospan(ast::ty_str),
- mut = ast::imm);
- let ast::ty args_ty = nospan(ast::ty_vec(args_mt));
+ let args_mt: ast::mt = {ty: @nospan(ast::ty_str), mut: ast::imm};
+ let args_ty: ast::ty = nospan(ast::ty_vec(args_mt));
- let ast::arg args_arg = rec(mode = ast::val,
- ty = @args_ty,
- ident = "args",
- id = cx.next_node_id());
+ let args_arg: ast::arg =
+ {mode: ast::val, ty: @args_ty, ident: "args", id: cx.next_node_id()};
- auto ret_ty = nospan(ast::ty_nil);
+ let ret_ty = nospan(ast::ty_nil);
- let ast::fn_decl decl = rec(inputs = ~[args_arg],
- output = @ret_ty,
- purity = ast::impure_fn,
- cf = ast::return,
- constraints = ~[]);
- auto proto = ast::proto_fn;
+ let decl: ast::fn_decl =
+ {inputs: ~[args_arg],
+ output: @ret_ty,
+ purity: ast::impure_fn,
+ cf: ast::return,
+ constraints: ~[]};
+ let proto = ast::proto_fn;
- auto test_main_call_expr = mk_test_main_call(cx);
+ let test_main_call_expr = mk_test_main_call(cx);
- let ast::blk_ body_ = rec(stmts = ~[],
- expr = option::some(test_main_call_expr),
- id = cx.next_node_id());
- auto body = rec(node = body_, span = rec(lo=0u, hi=0u));
+ let body_: ast::blk_ =
+ {stmts: ~[],
+ expr: option::some(test_main_call_expr),
+ id: cx.next_node_id()};
+ let body = {node: body_, span: {lo: 0u, hi: 0u}};
- auto fn_ = rec(decl = decl,
- proto = proto,
- body = body);
+ let fn_ = {decl: decl, proto: proto, body: body};
- auto item_ = ast::item_fn(fn_, ~[]);
- let ast::item item = rec(ident = "main",
- attrs = ~[],
- id = cx.next_node_id(),
- node = item_,
- span = rec(lo=0u, hi=0u));
+ let item_ = ast::item_fn(fn_, ~[]);
+ let item: ast::item =
+ {ident: "main",
+ attrs: ~[],
+ id: cx.next_node_id(),
+ node: item_,
+ span: {lo: 0u, hi: 0u}};
ret @item;
}
-fn mk_test_main_call(&test_ctxt cx) -> @ast::expr {
+fn mk_test_main_call(cx: &test_ctxt) -> @ast::expr {
// Get the args passed to main so we can pass the to test_main
- let ast::path args_path = nospan(rec(global = false,
- idents = ~["args"],
- types = ~[]));
+ let args_path: ast::path =
+ nospan({global: false, idents: ~["args"], types: ~[]});
- let ast::expr_ args_path_expr_ = ast::expr_path(args_path);
+ let args_path_expr_: ast::expr_ = ast::expr_path(args_path);
- let ast::expr args_path_expr = rec(id = cx.next_node_id(),
- node = args_path_expr_,
- span = rec(lo=0u, hi=0u));
+ let args_path_expr: ast::expr =
+ {id: cx.next_node_id(),
+ node: args_path_expr_,
+ span: {lo: 0u, hi: 0u}};
// Call __test::test to generate the vector of test_descs
- let ast::path test_path = nospan(rec(global = false,
- idents = ~["tests"],
- types = ~[]));
+ let test_path: ast::path =
+ nospan({global: false, idents: ~["tests"], types: ~[]});
- let ast::expr_ test_path_expr_ = ast::expr_path(test_path);
+ let test_path_expr_: ast::expr_ = ast::expr_path(test_path);
- let ast::expr test_path_expr = rec(id = cx.next_node_id(),
- node = test_path_expr_,
- span = rec(lo=0u, hi=0u));
+ let test_path_expr: ast::expr =
+ {id: cx.next_node_id(),
+ node: test_path_expr_,
+ span: {lo: 0u, hi: 0u}};
- let ast::expr_ test_call_expr_ = ast::expr_call(@test_path_expr, ~[]);
+ let test_call_expr_: ast::expr_ = ast::expr_call(@test_path_expr, ~[]);
- let ast::expr test_call_expr = rec(id = cx.next_node_id(),
- node = test_call_expr_,
- span = rec(lo=0u, hi=0u));
+ let test_call_expr: ast::expr =
+ {id: cx.next_node_id(),
+ node: test_call_expr_,
+ span: {lo: 0u, hi: 0u}};
// Call std::test::test_main
- let ast::path test_main_path = nospan(rec(global = false,
- idents = ~["std",
- "test",
- "test_main"],
- types = ~[]));
+ let test_main_path: ast::path =
+ nospan({global: false,
+ idents: ~["std", "test", "test_main"],
+ types: ~[]});
- let ast::expr_ test_main_path_expr_
- = ast::expr_path(test_main_path);
+ let test_main_path_expr_: ast::expr_ = ast::expr_path(test_main_path);
- let ast::expr test_main_path_expr = rec(id = cx.next_node_id(),
- node = test_main_path_expr_,
- span = rec(lo=0u, hi=0u));
+ let test_main_path_expr: ast::expr =
+ {id: cx.next_node_id(),
+ node: test_main_path_expr_,
+ span: {lo: 0u, hi: 0u}};
- let ast::expr_ test_main_call_expr_
- = ast::expr_call(@test_main_path_expr, ~[@args_path_expr,
- @test_call_expr]);
+ let test_main_call_expr_: ast::expr_ =
+ ast::expr_call(@test_main_path_expr,
+ ~[@args_path_expr, @test_call_expr]);
- let ast::expr test_main_call_expr = rec(id = cx.next_node_id(),
- node = test_main_call_expr_,
- span = rec(lo=0u, hi=0u));
+ let test_main_call_expr: ast::expr =
+ {id: cx.next_node_id(),
+ node: test_main_call_expr_,
+ span: {lo: 0u, hi: 0u}};
ret @test_main_call_expr;
}
diff --git a/src/comp/lib/llvm.rs b/src/comp/lib/llvm.rs
index 96c0022..019179d 100644
--- a/src/comp/lib/llvm.rs
+++ b/src/comp/lib/llvm.rs
@@ -30,102 +30,106 @@
type Bool = int;
-const Bool True = 1;
-const Bool False = 0;
+const True: Bool = 1;
+const False: Bool = 0;
// Consts for the LLVM CallConv type, pre-cast to uint.
// FIXME: figure out a way to merge these with the native
// typedef and/or a tag type in the native module below.
-const uint LLVMCCallConv = 0u;
-const uint LLVMFastCallConv = 8u;
-const uint LLVMColdCallConv = 9u;
-const uint LLVMX86StdcallCallConv = 64u;
-const uint LLVMX86FastcallCallConv = 65u;
+const LLVMCCallConv: uint = 0u;
+const LLVMFastCallConv: uint = 8u;
+const LLVMColdCallConv: uint = 9u;
+const LLVMX86StdcallCallConv: uint = 64u;
+const LLVMX86FastcallCallConv: uint = 65u;
-const uint LLVMDefaultVisibility = 0u;
-const uint LLVMHiddenVisibility = 1u;
-const uint LLVMProtectedVisibility = 2u;
+const LLVMDefaultVisibility: uint = 0u;
+const LLVMHiddenVisibility: uint = 1u;
+const LLVMProtectedVisibility: uint = 2u;
-const uint LLVMExternalLinkage = 0u;
-const uint LLVMAvailableExternallyLinkage = 1u;
-const uint LLVMLinkOnceAnyLinkage = 2u;
-const uint LLVMLinkOnceODRLinkage = 3u;
-const uint LLVMWeakAnyLinkage = 4u;
-const uint LLVMWeakODRLinkage = 5u;
-const uint LLVMAppendingLinkage = 6u;
-const uint LLVMInternalLinkage = 7u;
-const uint LLVMPrivateLinkage = 8u;
-const uint LLVMDLLImportLinkage = 9u;
-const uint LLVMDLLExportLinkage = 10u;
-const uint LLVMExternalWeakLinkage = 11u;
-const uint LLVMGhostLinkage = 12u;
-const uint LLVMCommonLinkage = 13u;
-const uint LLVMLinkerPrivateLinkage = 14u;
-const uint LLVMLinkerPrivateWeakLinkage = 15u;
+const LLVMExternalLinkage: uint = 0u;
+const LLVMAvailableExternallyLinkage: uint = 1u;
+const LLVMLinkOnceAnyLinkage: uint = 2u;
+const LLVMLinkOnceODRLinkage: uint = 3u;
+const LLVMWeakAnyLinkage: uint = 4u;
+const LLVMWeakODRLinkage: uint = 5u;
+const LLVMAppendingLinkage: uint = 6u;
+const LLVMInternalLinkage: uint = 7u;
+const LLVMPrivateLinkage: uint = 8u;
+const LLVMDLLImportLinkage: uint = 9u;
+const LLVMDLLExportLinkage: uint = 10u;
+const LLVMExternalWeakLinkage: uint = 11u;
+const LLVMGhostLinkage: uint = 12u;
+const LLVMCommonLinkage: uint = 13u;
+const LLVMLinkerPrivateLinkage: uint = 14u;
+const LLVMLinkerPrivateWeakLinkage: uint = 15u;
-const uint LLVMZExtAttribute = 1u;
-const uint LLVMSExtAttribute = 2u;
-const uint LLVMNoReturnAttribute = 4u;
-const uint LLVMInRegAttribute = 8u;
-const uint LLVMStructRetAttribute = 16u;
-const uint LLVMNoUnwindAttribute = 32u;
-const uint LLVMNoAliasAttribute = 64u;
-const uint LLVMByValAttribute = 128u;
-const uint LLVMNestAttribute = 256u;
-const uint LLVMReadNoneAttribute = 512u;
-const uint LLVMReadOnlyAttribute = 1024u;
-const uint LLVMNoInlineAttribute = 2048u;
-const uint LLVMAlwaysInlineAttribute = 4096u;
-const uint LLVMOptimizeForSizeAttribute = 8192u;
-const uint LLVMStackProtectAttribute = 16384u;
-const uint LLVMStackProtectReqAttribute = 32768u;
-const uint LLVMAlignmentAttribute = 2031616u; // 31 << 16
-const uint LLVMNoCaptureAttribute = 2097152u;
-const uint LLVMNoRedZoneAttribute = 4194304u;
-const uint LLVMNoImplicitFloatAttribute = 8388608u;
-const uint LLVMNakedAttribute = 16777216u;
-const uint LLVMInlineHintAttribute = 33554432u;
-const uint LLVMStackAttribute = 469762048u; // 7 << 26
-const uint LLVMUWTableAttribute = 1073741824u; // 1 << 30
+const LLVMZExtAttribute: uint = 1u;
+const LLVMSExtAttribute: uint = 2u;
+const LLVMNoReturnAttribute: uint = 4u;
+const LLVMInRegAttribute: uint = 8u;
+const LLVMStructRetAttribute: uint = 16u;
+const LLVMNoUnwindAttribute: uint = 32u;
+const LLVMNoAliasAttribute: uint = 64u;
+const LLVMByValAttribute: uint = 128u;
+const LLVMNestAttribute: uint = 256u;
+const LLVMReadNoneAttribute: uint = 512u;
+const LLVMReadOnlyAttribute: uint = 1024u;
+const LLVMNoInlineAttribute: uint = 2048u;
+const LLVMAlwaysInlineAttribute: uint = 4096u;
+const LLVMOptimizeForSizeAttribute: uint = 8192u;
+const LLVMStackProtectAttribute: uint = 16384u;
+const LLVMStackProtectReqAttribute: uint = 32768u;
+const LLVMAlignmentAttribute: uint = 2031616u;
+ // 31 << 16
+const LLVMNoCaptureAttribute: uint = 2097152u;
+const LLVMNoRedZoneAttribute: uint = 4194304u;
+const LLVMNoImplicitFloatAttribute: uint = 8388608u;
+const LLVMNakedAttribute: uint = 16777216u;
+const LLVMInlineHintAttribute: uint = 33554432u;
+const LLVMStackAttribute: uint = 469762048u;
+ // 7 << 26
+const LLVMUWTableAttribute: uint = 1073741824u;
+ // 1 << 30
-// Consts for the LLVM IntPredicate type, pre-cast to uint.
-// FIXME: as above.
+ // Consts for the LLVM IntPredicate type, pre-cast to uint.
+ // FIXME: as above.
-const uint LLVMIntEQ = 32u;
-const uint LLVMIntNE = 33u;
-const uint LLVMIntUGT = 34u;
-const uint LLVMIntUGE = 35u;
-const uint LLVMIntULT = 36u;
-const uint LLVMIntULE = 37u;
-const uint LLVMIntSGT = 38u;
-const uint LLVMIntSGE = 39u;
-const uint LLVMIntSLT = 40u;
-const uint LLVMIntSLE = 41u;
+
+const LLVMIntEQ: uint = 32u;
+const LLVMIntNE: uint = 33u;
+const LLVMIntUGT: uint = 34u;
+const LLVMIntUGE: uint = 35u;
+const LLVMIntULT: uint = 36u;
+const LLVMIntULE: uint = 37u;
+const LLVMIntSGT: uint = 38u;
+const LLVMIntSGE: uint = 39u;
+const LLVMIntSLT: uint = 40u;
+const LLVMIntSLE: uint = 41u;
// Consts for the LLVM RealPredicate type, pre-case to uint.
// FIXME: as above.
-const uint LLVMRealOEQ = 1u;
-const uint LLVMRealOGT = 2u;
-const uint LLVMRealOGE = 3u;
-const uint LLVMRealOLT = 4u;
-const uint LLVMRealOLE = 5u;
-const uint LLVMRealONE = 6u;
+const LLVMRealOEQ: uint = 1u;
+const LLVMRealOGT: uint = 2u;
+const LLVMRealOGE: uint = 3u;
+const LLVMRealOLT: uint = 4u;
+const LLVMRealOLE: uint = 5u;
+const LLVMRealONE: uint = 6u;
-const uint LLVMRealORD = 7u;
-const uint LLVMRealUNO = 8u;
-const uint LLVMRealUEQ = 9u;
-const uint LLVMRealUGT = 10u;
-const uint LLVMRealUGE = 11u;
-const uint LLVMRealULT = 12u;
-const uint LLVMRealULE = 13u;
-const uint LLVMRealUNE = 14u;
+const LLVMRealORD: uint = 7u;
+const LLVMRealUNO: uint = 8u;
+const LLVMRealUEQ: uint = 9u;
+const LLVMRealUGT: uint = 10u;
+const LLVMRealUGE: uint = 11u;
+const LLVMRealULT: uint = 12u;
+const LLVMRealULE: uint = 13u;
+const LLVMRealUNE: uint = 14u;
#[link_args = "-Lrustllvm"]
-native mod llvm = "rustllvm" {
+native "cdecl" mod llvm = "rustllvm" {
type ModuleRef;
type ContextRef;
@@ -152,28 +156,29 @@
/* Create and destroy contexts. */
fn LLVMContextCreate() -> ContextRef;
fn LLVMGetGlobalContext() -> ContextRef;
- fn LLVMContextDispose(ContextRef C);
- fn LLVMGetMDKindIDInContext(ContextRef C, sbuf Name, uint SLen) -> uint;
- fn LLVMGetMDKindID(sbuf Name, uint SLen) -> uint;
+ fn LLVMContextDispose(C: ContextRef);
+ fn LLVMGetMDKindIDInContext(C: ContextRef, Name: sbuf, SLen: uint) ->
+ uint;
+ fn LLVMGetMDKindID(Name: sbuf, SLen: uint) -> uint;
/* Create and destroy modules. */
- fn LLVMModuleCreateWithNameInContext(sbuf ModuleID,
- ContextRef C)-> ModuleRef;
- fn LLVMDisposeModule(ModuleRef M);
+ fn LLVMModuleCreateWithNameInContext(ModuleID: sbuf, C: ContextRef) ->
+ ModuleRef;
+ fn LLVMDisposeModule(M: ModuleRef);
/** Data layout. See Module::getDataLayout. */
- fn LLVMGetDataLayout(ModuleRef M) -> sbuf;
- fn LLVMSetDataLayout(ModuleRef M, sbuf Triple);
+ fn LLVMGetDataLayout(M: ModuleRef) -> sbuf;
+ fn LLVMSetDataLayout(M: ModuleRef, Triple: sbuf);
/** Target triple. See Module::getTargetTriple. */
- fn LLVMGetTarget(ModuleRef M) -> sbuf;
- fn LLVMSetTarget(ModuleRef M, sbuf Triple);
+ fn LLVMGetTarget(M: ModuleRef) -> sbuf;
+ fn LLVMSetTarget(M: ModuleRef, Triple: sbuf);
/** See Module::dump. */
- fn LLVMDumpModule(ModuleRef M);
+ fn LLVMDumpModule(M: ModuleRef);
/** See Module::setModuleInlineAsm. */
- fn LLVMSetModuleInlineAsm(ModuleRef M, sbuf Asm);
+ fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: sbuf);
/** See llvm::LLVMTypeKind::getTypeID. */
@@ -181,33 +186,33 @@
// we directly inspect the values, and casting from
// a native doesn't work yet (only *to* a native).
- fn LLVMGetTypeKind(TypeRef Ty) -> int;
+ fn LLVMGetTypeKind(Ty: TypeRef) -> int;
/** See llvm::LLVMType::getContext. */
- fn LLVMGetTypeContext(TypeRef Ty) -> ContextRef;
+ fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
/* Operations on integer types */
- fn LLVMInt1TypeInContext(ContextRef C) -> TypeRef;
- fn LLVMInt8TypeInContext(ContextRef C) -> TypeRef;
- fn LLVMInt16TypeInContext(ContextRef C) -> TypeRef;
- fn LLVMInt32TypeInContext(ContextRef C) -> TypeRef;
- fn LLVMInt64TypeInContext(ContextRef C) -> TypeRef;
- fn LLVMIntTypeInContext(ContextRef C, uint NumBits) -> TypeRef;
+ fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
+ fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
+ fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
+ fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
+ fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
+ fn LLVMIntTypeInContext(C: ContextRef, NumBits: uint) -> TypeRef;
fn LLVMInt1Type() -> TypeRef;
fn LLVMInt8Type() -> TypeRef;
fn LLVMInt16Type() -> TypeRef;
fn LLVMInt32Type() -> TypeRef;
fn LLVMInt64Type() -> TypeRef;
- fn LLVMIntType(uint NumBits) -> TypeRef;
- fn LLVMGetIntTypeWidth(TypeRef IntegerTy) -> uint;
+ fn LLVMIntType(NumBits: uint) -> TypeRef;
+ fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> uint;
/* Operations on real types */
- fn LLVMFloatTypeInContext(ContextRef C) -> TypeRef;
- fn LLVMDoubleTypeInContext(ContextRef C) -> TypeRef;
- fn LLVMX86FP80TypeInContext(ContextRef C) -> TypeRef;
- fn LLVMFP128TypeInContext(ContextRef C) -> TypeRef;
- fn LLVMPPCFP128TypeInContext(ContextRef C) -> TypeRef;
+ fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
+ fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
+ fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
+ fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
+ fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
fn LLVMFloatType() -> TypeRef;
fn LLVMDoubleType() -> TypeRef;
@@ -216,595 +221,594 @@
fn LLVMPPCFP128Type() -> TypeRef;
/* Operations on function types */
- fn LLVMFunctionType(TypeRef ReturnType, *TypeRef ParamTypes,
- uint ParamCount, Bool IsVarArg) -> TypeRef;
- fn LLVMIsFunctionVarArg(TypeRef FunctionTy) -> Bool;
- fn LLVMGetReturnType(TypeRef FunctionTy) -> TypeRef;
- fn LLVMCountParamTypes(TypeRef FunctionTy) -> uint;
- fn LLVMGetParamTypes(TypeRef FunctionTy, *TypeRef Dest);
+ fn LLVMFunctionType(ReturnType: TypeRef, ParamTypes: *TypeRef,
+ ParamCount: uint, IsVarArg: Bool) -> TypeRef;
+ fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
+ fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
+ fn LLVMCountParamTypes(FunctionTy: TypeRef) -> uint;
+ fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *TypeRef);
/* Operations on struct types */
- fn LLVMStructTypeInContext(ContextRef C, *TypeRef ElementTypes,
- uint ElementCount, Bool Packed) -> TypeRef;
- fn LLVMStructType(*TypeRef ElementTypes, uint ElementCount,
- Bool Packed) -> TypeRef;
- fn LLVMCountStructElementTypes(TypeRef StructTy) -> uint;
- fn LLVMGetStructElementTypes(TypeRef StructTy, *TypeRef Dest);
- fn LLVMIsPackedStruct(TypeRef StructTy) -> Bool;
+ fn LLVMStructTypeInContext(C: ContextRef, ElementTypes: *TypeRef,
+ ElementCount: uint, Packed: Bool) -> TypeRef;
+ fn LLVMStructType(ElementTypes: *TypeRef, ElementCount: uint,
+ Packed: Bool) -> TypeRef;
+ fn LLVMCountStructElementTypes(StructTy: TypeRef) -> uint;
+ fn LLVMGetStructElementTypes(StructTy: TypeRef, Dest: *TypeRef);
+ fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
/* Operations on array, pointer, and vector types (sequence types) */
- fn LLVMArrayType(TypeRef ElementType, uint ElementCount) -> TypeRef;
- fn LLVMPointerType(TypeRef ElementType, uint AddressSpace) -> TypeRef;
- fn LLVMVectorType(TypeRef ElementType, uint ElementCount) -> TypeRef;
+ fn LLVMArrayType(ElementType: TypeRef, ElementCount: uint) -> TypeRef;
+ fn LLVMPointerType(ElementType: TypeRef, AddressSpace: uint) -> TypeRef;
+ fn LLVMVectorType(ElementType: TypeRef, ElementCount: uint) -> TypeRef;
- fn LLVMGetElementType(TypeRef Ty) -> TypeRef;
- fn LLVMGetArrayLength(TypeRef ArrayTy) -> uint;
- fn LLVMGetPointerAddressSpace(TypeRef PointerTy) -> uint;
- fn LLVMGetVectorSize(TypeRef VectorTy) -> uint;
+ fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
+ fn LLVMGetArrayLength(ArrayTy: TypeRef) -> uint;
+ fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> uint;
+ fn LLVMGetVectorSize(VectorTy: TypeRef) -> uint;
/* Operations on other types */
- fn LLVMVoidTypeInContext(ContextRef C) -> TypeRef;
- fn LLVMLabelTypeInContext(ContextRef C) -> TypeRef;
+ fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
+ fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
fn LLVMVoidType() -> TypeRef;
fn LLVMLabelType() -> TypeRef;
/* Operations on all values */
- fn LLVMTypeOf(ValueRef Val) -> TypeRef;
- fn LLVMGetValueName(ValueRef Val) -> sbuf;
- fn LLVMSetValueName(ValueRef Val, sbuf Name);
- fn LLVMDumpValue(ValueRef Val);
- fn LLVMReplaceAllUsesWith(ValueRef OldVal, ValueRef NewVal);
- fn LLVMHasMetadata(ValueRef Val) -> int;
- fn LLVMGetMetadata(ValueRef Val, uint KindID) -> ValueRef;
- fn LLVMSetMetadata(ValueRef Val, uint KindID, ValueRef Node);
+ fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
+ fn LLVMGetValueName(Val: ValueRef) -> sbuf;
+ fn LLVMSetValueName(Val: ValueRef, Name: sbuf);
+ fn LLVMDumpValue(Val: ValueRef);
+ fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
+ fn LLVMHasMetadata(Val: ValueRef) -> int;
+ fn LLVMGetMetadata(Val: ValueRef, KindID: uint) -> ValueRef;
+ fn LLVMSetMetadata(Val: ValueRef, KindID: uint, Node: ValueRef);
/* Operations on Uses */
- fn LLVMGetFirstUse(ValueRef Val) -> UseRef;
- fn LLVMGetNextUse(UseRef U) -> UseRef;
- fn LLVMGetUser(UseRef U) -> ValueRef;
- fn LLVMGetUsedValue(UseRef U) -> ValueRef;
+ fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
+ fn LLVMGetNextUse(U: UseRef) -> UseRef;
+ fn LLVMGetUser(U: UseRef) -> ValueRef;
+ fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
/* Operations on Users */
- fn LLVMGetOperand(ValueRef Val, uint Index) -> ValueRef;
+ fn LLVMGetOperand(Val: ValueRef, Index: uint) -> ValueRef;
/* Operations on constants of any type */
- fn LLVMConstNull(TypeRef Ty) -> ValueRef; /* all zeroes */
- fn LLVMConstAllOnes(TypeRef Ty) -> ValueRef; /* only for int/vector */
- fn LLVMGetUndef(TypeRef Ty) -> ValueRef;
- fn LLVMIsConstant(ValueRef Val) -> Bool;
- fn LLVMIsNull(ValueRef Val) -> Bool;
- fn LLVMIsUndef(ValueRef Val) -> Bool;
- fn LLVMConstPointerNull(TypeRef Ty) -> ValueRef;
+ fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
+ /* all zeroes */
+ fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
+ /* only for int/vector */
+ fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
+ fn LLVMIsConstant(Val: ValueRef) -> Bool;
+ fn LLVMIsNull(Val: ValueRef) -> Bool;
+ fn LLVMIsUndef(Val: ValueRef) -> Bool;
+ fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
/* Operations on metadata */
- fn LLVMMDStringInContext(ContextRef C, sbuf Str, uint SLen) -> ValueRef;
- fn LLVMMDString(sbuf Str, uint SLen) -> ValueRef;
- fn LLVMMDNodeInContext(ContextRef C, *ValueRef Vals, uint Count)
- -> ValueRef;
- fn LLVMMDNode(*ValueRef Vals, uint Count) -> ValueRef;
+ fn LLVMMDStringInContext(C: ContextRef, Str: sbuf, SLen: uint) ->
+ ValueRef;
+ fn LLVMMDString(Str: sbuf, SLen: uint) -> ValueRef;
+ fn LLVMMDNodeInContext(C: ContextRef, Vals: *ValueRef, Count: uint) ->
+ ValueRef;
+ fn LLVMMDNode(Vals: *ValueRef, Count: uint) -> ValueRef;
/* Operations on scalar constants */
- fn LLVMConstInt(TypeRef IntTy, ULongLong N, Bool SignExtend) -> ValueRef;
+ fn LLVMConstInt(IntTy: TypeRef, N: ULongLong, SignExtend: Bool) ->
+ ValueRef;
// FIXME: radix is actually u8, but our native layer can't handle this
// yet. lucky for us we're little-endian. Small miracles.
- fn LLVMConstIntOfString(TypeRef IntTy, sbuf Text, int Radix) -> ValueRef;
- fn LLVMConstIntOfStringAndSize(TypeRef IntTy, sbuf Text,
- uint SLen, u8 Radix) -> ValueRef;
- fn LLVMConstReal(TypeRef RealTy, f64 N) -> ValueRef;
- fn LLVMConstRealOfString(TypeRef RealTy, sbuf Text) -> ValueRef;
- fn LLVMConstRealOfStringAndSize(TypeRef RealTy, sbuf Text,
- uint SLen) -> ValueRef;
- fn LLVMConstIntGetZExtValue(ValueRef ConstantVal) -> ULongLong;
- fn LLVMConstIntGetSExtValue(ValueRef ConstantVal) -> LongLong;
+ fn LLVMConstIntOfString(IntTy: TypeRef, Text: sbuf, Radix: int) ->
+ ValueRef;
+ fn LLVMConstIntOfStringAndSize(IntTy: TypeRef, Text: sbuf, SLen: uint,
+ Radix: u8) -> ValueRef;
+ fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
+ fn LLVMConstRealOfString(RealTy: TypeRef, Text: sbuf) -> ValueRef;
+ fn LLVMConstRealOfStringAndSize(RealTy: TypeRef, Text: sbuf, SLen: uint)
+ -> ValueRef;
+ fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> ULongLong;
+ fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> LongLong;
/* Operations on composite constants */
- fn LLVMConstStringInContext(ContextRef C, sbuf Str, uint Length,
- Bool DontNullTerminate) -> ValueRef;
- fn LLVMConstStructInContext(ContextRef C, *ValueRef ConstantVals,
- uint Count, Bool Packed) -> ValueRef;
+ fn LLVMConstStringInContext(C: ContextRef, Str: sbuf, Length: uint,
+ DontNullTerminate: Bool) -> ValueRef;
+ fn LLVMConstStructInContext(C: ContextRef, ConstantVals: *ValueRef,
+ Count: uint, Packed: Bool) -> ValueRef;
- fn LLVMConstString(sbuf Str, uint Length,
- Bool DontNullTerminate) -> ValueRef;
- fn LLVMConstArray(TypeRef ElementTy,
- *ValueRef ConstantVals, uint Length) -> ValueRef;
- fn LLVMConstStruct(*ValueRef ConstantVals, uint Count,
- Bool Packed) -> ValueRef;
- fn LLVMConstVector(*ValueRef ScalarConstantVals, uint Size) -> ValueRef;
+ fn LLVMConstString(Str: sbuf, Length: uint, DontNullTerminate: Bool) ->
+ ValueRef;
+ fn LLVMConstArray(ElementTy: TypeRef, ConstantVals: *ValueRef,
+ Length: uint) -> ValueRef;
+ fn LLVMConstStruct(ConstantVals: *ValueRef, Count: uint, Packed: Bool) ->
+ ValueRef;
+ fn LLVMConstVector(ScalarConstantVals: *ValueRef, Size: uint) -> ValueRef;
/* Constant expressions */
- fn LLVMAlignOf(TypeRef Ty) -> ValueRef;
- fn LLVMSizeOf(TypeRef Ty) -> ValueRef;
- fn LLVMConstNeg(ValueRef ConstantVal) -> ValueRef;
- fn LLVMConstNSWNeg(ValueRef ConstantVal) -> ValueRef;
- fn LLVMConstNUWNeg(ValueRef ConstantVal) -> ValueRef;
- fn LLVMConstFNeg(ValueRef ConstantVal) -> ValueRef;
- fn LLVMConstNot(ValueRef ConstantVal) -> ValueRef;
- fn LLVMConstAdd(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
- fn LLVMConstNSWAdd(ValueRef LHSConstant,
- ValueRef RHSConstant) -> ValueRef;
- fn LLVMConstNUWAdd(ValueRef LHSConstant,
- ValueRef RHSConstant) -> ValueRef;
- fn LLVMConstFAdd(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
- fn LLVMConstSub(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
- fn LLVMConstNSWSub(ValueRef LHSConstant,
- ValueRef RHSConstant) -> ValueRef;
- fn LLVMConstNUWSub(ValueRef LHSConstant,
- ValueRef RHSConstant) -> ValueRef;
- fn LLVMConstFSub(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
- fn LLVMConstMul(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
- fn LLVMConstNSWMul(ValueRef LHSConstant,
- ValueRef RHSConstant) -> ValueRef;
- fn LLVMConstNUWMul(ValueRef LHSConstant,
- ValueRef RHSConstant) -> ValueRef;
- fn LLVMConstFMul(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
- fn LLVMConstUDiv(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
- fn LLVMConstSDiv(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
- fn LLVMConstExactSDiv(ValueRef LHSConstant,
- ValueRef RHSConstant) -> ValueRef;
- fn LLVMConstFDiv(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
- fn LLVMConstURem(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
- fn LLVMConstSRem(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
- fn LLVMConstFRem(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
- fn LLVMConstAnd(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
- fn LLVMConstOr(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
- fn LLVMConstXor(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
- fn LLVMConstShl(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
- fn LLVMConstLShr(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
- fn LLVMConstAShr(ValueRef LHSConstant, ValueRef RHSConstant) -> ValueRef;
- fn LLVMConstGEP(ValueRef ConstantVal,
- *uint ConstantIndices, uint NumIndices) -> ValueRef;
- fn LLVMConstInBoundsGEP(ValueRef ConstantVal,
- *uint ConstantIndices,
- uint NumIndices) -> ValueRef;
- fn LLVMConstTrunc(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
- fn LLVMConstSExt(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
- fn LLVMConstZExt(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
- fn LLVMConstFPTrunc(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
- fn LLVMConstFPExt(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
- fn LLVMConstUIToFP(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
- fn LLVMConstSIToFP(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
- fn LLVMConstFPToUI(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
- fn LLVMConstFPToSI(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
- fn LLVMConstPtrToInt(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
- fn LLVMConstIntToPtr(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
- fn LLVMConstBitCast(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
- fn LLVMConstZExtOrBitCast(ValueRef ConstantVal,
- TypeRef ToType) -> ValueRef;
- fn LLVMConstSExtOrBitCast(ValueRef ConstantVal,
- TypeRef ToType) -> ValueRef;
- fn LLVMConstTruncOrBitCast(ValueRef ConstantVal,
- TypeRef ToType) -> ValueRef;
- fn LLVMConstPointerCast(ValueRef ConstantVal,
- TypeRef ToType) -> ValueRef;
- fn LLVMConstIntCast(ValueRef ConstantVal, TypeRef ToType,
- Bool isSigned) -> ValueRef;
- fn LLVMConstFPCast(ValueRef ConstantVal, TypeRef ToType) -> ValueRef;
- fn LLVMConstSelect(ValueRef ConstantCondition,
- ValueRef ConstantIfTrue,
- ValueRef ConstantIfFalse) -> ValueRef;
- fn LLVMConstExtractElement(ValueRef VectorConstant,
- ValueRef IndexConstant) -> ValueRef;
- fn LLVMConstInsertElement(ValueRef VectorConstant,
- ValueRef ElementValueConstant,
- ValueRef IndexConstant) -> ValueRef;
- fn LLVMConstShuffleVector(ValueRef VectorAConstant,
- ValueRef VectorBConstant,
- ValueRef MaskConstant) -> ValueRef;
- fn LLVMConstExtractValue(ValueRef AggConstant, *uint IdxList,
- uint NumIdx) -> ValueRef;
- fn LLVMConstInsertValue(ValueRef AggConstant,
- ValueRef ElementValueConstant,
- *uint IdxList, uint NumIdx) -> ValueRef;
- fn LLVMConstInlineAsm(TypeRef Ty,
- sbuf AsmString, sbuf Constraints,
- Bool HasSideEffects, Bool IsAlignStack) -> ValueRef;
- fn LLVMBlockAddress(ValueRef F, BasicBlockRef BB) -> ValueRef;
+ fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
+ fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
+ fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
+ fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
+ fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
+ fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
+ fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
+ fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
+ fn LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
+ ValueRef;
+ fn LLVMConstNUWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
+ ValueRef;
+ fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
+ ValueRef;
+ fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
+ fn LLVMConstNSWSub(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
+ ValueRef;
+ fn LLVMConstNUWSub(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
+ ValueRef;
+ fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
+ ValueRef;
+ fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
+ fn LLVMConstNSWMul(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
+ ValueRef;
+ fn LLVMConstNUWMul(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
+ ValueRef;
+ fn LLVMConstFMul(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
+ ValueRef;
+ fn LLVMConstUDiv(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
+ ValueRef;
+ fn LLVMConstSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
+ ValueRef;
+ fn LLVMConstExactSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
+ ValueRef;
+ fn LLVMConstFDiv(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
+ ValueRef;
+ fn LLVMConstURem(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
+ ValueRef;
+ fn LLVMConstSRem(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
+ ValueRef;
+ fn LLVMConstFRem(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
+ ValueRef;
+ fn LLVMConstAnd(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
+ fn LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
+ fn LLVMConstXor(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
+ fn LLVMConstShl(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
+ fn LLVMConstLShr(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
+ ValueRef;
+ fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
+ ValueRef;
+ fn LLVMConstGEP(ConstantVal: ValueRef, ConstantIndices: *uint,
+ NumIndices: uint) -> ValueRef;
+ fn LLVMConstInBoundsGEP(ConstantVal: ValueRef, ConstantIndices: *uint,
+ NumIndices: uint) -> ValueRef;
+ fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
+ fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
+ fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
+ fn LLVMConstFPTrunc(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
+ fn LLVMConstFPExt(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
+ fn LLVMConstUIToFP(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
+ fn LLVMConstSIToFP(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
+ fn LLVMConstFPToUI(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
+ fn LLVMConstFPToSI(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
+ fn LLVMConstPtrToInt(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
+ fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
+ fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
+ fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef) ->
+ ValueRef;
+ fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef) ->
+ ValueRef;
+ fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef, ToType: TypeRef) ->
+ ValueRef;
+ fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef) ->
+ ValueRef;
+ fn LLVMConstIntCast(ConstantVal: ValueRef, ToType: TypeRef,
+ isSigned: Bool) -> ValueRef;
+ fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
+ fn LLVMConstSelect(ConstantCondition: ValueRef, ConstantIfTrue: ValueRef,
+ ConstantIfFalse: ValueRef) -> ValueRef;
+ fn LLVMConstExtractElement(VectorConstant: ValueRef,
+ IndexConstant: ValueRef) -> ValueRef;
+ fn LLVMConstInsertElement(VectorConstant: ValueRef,
+ ElementValueConstant: ValueRef,
+ IndexConstant: ValueRef) -> ValueRef;
+ fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
+ VectorBConstant: ValueRef,
+ MaskConstant: ValueRef) -> ValueRef;
+ fn LLVMConstExtractValue(AggConstant: ValueRef, IdxList: *uint,
+ NumIdx: uint) -> ValueRef;
+ fn LLVMConstInsertValue(AggConstant: ValueRef,
+ ElementValueConstant: ValueRef, IdxList: *uint,
+ NumIdx: uint) -> ValueRef;
+ fn LLVMConstInlineAsm(Ty: TypeRef, AsmString: sbuf, Constraints: sbuf,
+ HasSideEffects: Bool, IsAlignStack: Bool) ->
+ ValueRef;
+ fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef;
/* Operations on global variables, functions, and aliases (globals) */
- fn LLVMGetGlobalParent(ValueRef Global) -> ModuleRef;
- fn LLVMIsDeclaration(ValueRef Global) -> Bool;
- fn LLVMGetLinkage(ValueRef Global) -> Linkage;
- fn LLVMSetLinkage(ValueRef Global, Linkage Link);
- fn LLVMGetSection(ValueRef Global) -> sbuf;
- fn LLVMSetSection(ValueRef Global, sbuf Section);
- fn LLVMGetVisibility(ValueRef Global) -> Visibility;
- fn LLVMSetVisibility(ValueRef Global, Visibility Viz);
- fn LLVMGetAlignment(ValueRef Global) -> uint;
- fn LLVMSetAlignment(ValueRef Global, uint Bytes);
+ fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
+ fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
+ fn LLVMGetLinkage(Global: ValueRef) -> Linkage;
+ fn LLVMSetLinkage(Global: ValueRef, Link: Linkage);
+ fn LLVMGetSection(Global: ValueRef) -> sbuf;
+ fn LLVMSetSection(Global: ValueRef, Section: sbuf);
+ fn LLVMGetVisibility(Global: ValueRef) -> Visibility;
+ fn LLVMSetVisibility(Global: ValueRef, Viz: Visibility);
+ fn LLVMGetAlignment(Global: ValueRef) -> uint;
+ fn LLVMSetAlignment(Global: ValueRef, Bytes: uint);
/* Operations on global variables */
- fn LLVMAddGlobal(ModuleRef M, TypeRef Ty, sbuf Name) -> ValueRef;
- fn LLVMAddGlobalInAddressSpace(ModuleRef M, TypeRef Ty,
- sbuf Name,
- uint AddressSpace) -> ValueRef;
- fn LLVMGetNamedGlobal(ModuleRef M, sbuf Name) -> ValueRef;
- fn LLVMGetFirstGlobal(ModuleRef M) -> ValueRef;
- fn LLVMGetLastGlobal(ModuleRef M) -> ValueRef;
- fn LLVMGetNextGlobal(ValueRef GlobalVar) -> ValueRef;
- fn LLVMGetPreviousGlobal(ValueRef GlobalVar) -> ValueRef;
- fn LLVMDeleteGlobal(ValueRef GlobalVar);
- fn LLVMGetInitializer(ValueRef GlobalVar) -> ValueRef;
- fn LLVMSetInitializer(ValueRef GlobalVar, ValueRef ConstantVal);
- fn LLVMIsThreadLocal(ValueRef GlobalVar) -> Bool;
- fn LLVMSetThreadLocal(ValueRef GlobalVar, Bool IsThreadLocal);
- fn LLVMIsGlobalConstant(ValueRef GlobalVar) -> Bool;
- fn LLVMSetGlobalConstant(ValueRef GlobalVar, Bool IsConstant);
+ fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: sbuf) -> ValueRef;
+ fn LLVMAddGlobalInAddressSpace(M: ModuleRef, Ty: TypeRef, Name: sbuf,
+ AddressSpace: uint) -> ValueRef;
+ fn LLVMGetNamedGlobal(M: ModuleRef, Name: sbuf) -> ValueRef;
+ fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
+ fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
+ fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
+ fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
+ fn LLVMDeleteGlobal(GlobalVar: ValueRef);
+ fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
+ fn LLVMSetInitializer(GlobalVar: ValueRef, ConstantVal: ValueRef);
+ fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
+ fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
+ fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
+ fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
/* Operations on aliases */
- fn LLVMAddAlias(ModuleRef M, TypeRef Ty, ValueRef Aliasee,
- sbuf Name) -> ValueRef;
+ fn LLVMAddAlias(M: ModuleRef, Ty: TypeRef, Aliasee: ValueRef, Name: sbuf)
+ -> ValueRef;
/* Operations on functions */
- fn LLVMAddFunction(ModuleRef M, sbuf Name,
- TypeRef FunctionTy) -> ValueRef;
- fn LLVMGetNamedFunction(ModuleRef M, sbuf Name) -> ValueRef;
- fn LLVMGetFirstFunction(ModuleRef M) -> ValueRef;
- fn LLVMGetLastFunction(ModuleRef M) -> ValueRef;
- fn LLVMGetNextFunction(ValueRef Fn) -> ValueRef;
- fn LLVMGetPreviousFunction(ValueRef Fn) -> ValueRef;
- fn LLVMDeleteFunction(ValueRef Fn);
- fn LLVMGetIntrinsicID(ValueRef Fn) -> uint;
- fn LLVMGetFunctionCallConv(ValueRef Fn) -> uint;
- fn LLVMSetFunctionCallConv(ValueRef Fn, uint CC);
- fn LLVMGetGC(ValueRef Fn) -> sbuf;
- fn LLVMSetGC(ValueRef Fn, sbuf Name);
- fn LLVMAddFunctionAttr(ValueRef Fn, Attribute PA);
- fn LLVMGetFunctionAttr(ValueRef Fn) -> Attribute;
- fn LLVMRemoveFunctionAttr(ValueRef Fn, Attribute PA);
+ fn LLVMAddFunction(M: ModuleRef, Name: sbuf, FunctionTy: TypeRef) ->
+ ValueRef;
+ fn LLVMGetNamedFunction(M: ModuleRef, Name: sbuf) -> ValueRef;
+ fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
+ fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
+ fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
+ fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
+ fn LLVMDeleteFunction(Fn: ValueRef);
+ fn LLVMGetIntrinsicID(Fn: ValueRef) -> uint;
+ fn LLVMGetFunctionCallConv(Fn: ValueRef) -> uint;
+ fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: uint);
+ fn LLVMGetGC(Fn: ValueRef) -> sbuf;
+ fn LLVMSetGC(Fn: ValueRef, Name: sbuf);
+ fn LLVMAddFunctionAttr(Fn: ValueRef, PA: Attribute);
+ fn LLVMGetFunctionAttr(Fn: ValueRef) -> Attribute;
+ fn LLVMRemoveFunctionAttr(Fn: ValueRef, PA: Attribute);
/* Operations on parameters */
- fn LLVMCountParams(ValueRef Fn) -> uint;
- fn LLVMGetParams(ValueRef Fn, *ValueRef Params);
- fn LLVMGetParam(ValueRef Fn, uint Index) -> ValueRef;
- fn LLVMGetParamParent(ValueRef Inst) -> ValueRef;
- fn LLVMGetFirstParam(ValueRef Fn) -> ValueRef;
- fn LLVMGetLastParam(ValueRef Fn) -> ValueRef;
- fn LLVMGetNextParam(ValueRef Arg) -> ValueRef;
- fn LLVMGetPreviousParam(ValueRef Arg) -> ValueRef;
- fn LLVMAddAttribute(ValueRef Arg, Attribute PA);
- fn LLVMRemoveAttribute(ValueRef Arg, Attribute PA);
- fn LLVMGetAttribute(ValueRef Arg) -> Attribute;
- fn LLVMSetParamAlignment(ValueRef Arg, uint align);
+ fn LLVMCountParams(Fn: ValueRef) -> uint;
+ fn LLVMGetParams(Fn: ValueRef, Params: *ValueRef);
+ fn LLVMGetParam(Fn: ValueRef, Index: uint) -> ValueRef;
+ fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
+ fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
+ fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
+ fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
+ fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
+ fn LLVMAddAttribute(Arg: ValueRef, PA: Attribute);
+ fn LLVMRemoveAttribute(Arg: ValueRef, PA: Attribute);
+ fn LLVMGetAttribute(Arg: ValueRef) -> Attribute;
+ fn LLVMSetParamAlignment(Arg: ValueRef, align: uint);
/* Operations on basic blocks */
- fn LLVMBasicBlockAsValue(BasicBlockRef BB) -> ValueRef;
- fn LLVMValueIsBasicBlock(ValueRef Val) -> Bool;
- fn LLVMValueAsBasicBlock(ValueRef Val) -> BasicBlockRef;
- fn LLVMGetBasicBlockParent(BasicBlockRef BB) -> ValueRef;
- fn LLVMCountBasicBlocks(ValueRef Fn) -> uint;
- fn LLVMGetBasicBlocks(ValueRef Fn, *ValueRef BasicBlocks);
- fn LLVMGetFirstBasicBlock(ValueRef Fn) -> BasicBlockRef;
- fn LLVMGetLastBasicBlock(ValueRef Fn) -> BasicBlockRef;
- fn LLVMGetNextBasicBlock(BasicBlockRef BB) -> BasicBlockRef;
- fn LLVMGetPreviousBasicBlock(BasicBlockRef BB) -> BasicBlockRef;
- fn LLVMGetEntryBasicBlock(ValueRef Fn) -> BasicBlockRef;
+ fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
+ fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
+ fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
+ fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
+ fn LLVMCountBasicBlocks(Fn: ValueRef) -> uint;
+ fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *ValueRef);
+ fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
+ fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
+ fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
+ fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
+ fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
- fn LLVMAppendBasicBlockInContext(ContextRef C, ValueRef Fn,
- sbuf Name) -> BasicBlockRef;
- fn LLVMInsertBasicBlockInContext(ContextRef C, BasicBlockRef BB,
- sbuf Name) -> BasicBlockRef;
+ fn LLVMAppendBasicBlockInContext(C: ContextRef, Fn: ValueRef, Name: sbuf)
+ -> BasicBlockRef;
+ fn LLVMInsertBasicBlockInContext(C: ContextRef, BB: BasicBlockRef,
+ Name: sbuf) -> BasicBlockRef;
- fn LLVMAppendBasicBlock(ValueRef Fn, sbuf Name) -> BasicBlockRef;
- fn LLVMInsertBasicBlock(BasicBlockRef InsertBeforeBB,
- sbuf Name) -> BasicBlockRef;
- fn LLVMDeleteBasicBlock(BasicBlockRef BB);
+ fn LLVMAppendBasicBlock(Fn: ValueRef, Name: sbuf) -> BasicBlockRef;
+ fn LLVMInsertBasicBlock(InsertBeforeBB: BasicBlockRef, Name: sbuf) ->
+ BasicBlockRef;
+ fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
/* Operations on instructions */
- fn LLVMGetInstructionParent(ValueRef Inst) -> BasicBlockRef;
- fn LLVMGetFirstInstruction(BasicBlockRef BB) -> ValueRef;
- fn LLVMGetLastInstruction(BasicBlockRef BB) -> ValueRef;
- fn LLVMGetNextInstruction(ValueRef Inst) -> ValueRef;
- fn LLVMGetPreviousInstruction(ValueRef Inst) -> ValueRef;
+ fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef;
+ fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
+ fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
+ fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
+ fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
/* Operations on call sites */
- fn LLVMSetInstructionCallConv(ValueRef Instr, uint CC);
- fn LLVMGetInstructionCallConv(ValueRef Instr) -> uint;
- fn LLVMAddInstrAttribute(ValueRef Instr, uint index, Attribute IA);
- fn LLVMRemoveInstrAttribute(ValueRef Instr, uint index, Attribute IA);
- fn LLVMSetInstrParamAlignment(ValueRef Instr, uint index, uint align);
+ fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: uint);
+ fn LLVMGetInstructionCallConv(Instr: ValueRef) -> uint;
+ fn LLVMAddInstrAttribute(Instr: ValueRef, index: uint, IA: Attribute);
+ fn LLVMRemoveInstrAttribute(Instr: ValueRef, index: uint, IA: Attribute);
+ fn LLVMSetInstrParamAlignment(Instr: ValueRef, index: uint, align: uint);
/* Operations on call instructions (only) */
- fn LLVMIsTailCall(ValueRef CallInst) -> Bool;
- fn LLVMSetTailCall(ValueRef CallInst, Bool IsTailCall);
+ fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
+ fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
/* Operations on phi nodes */
- fn LLVMAddIncoming(ValueRef PhiNode, *ValueRef IncomingValues,
- *BasicBlockRef IncomingBlocks, uint Count);
- fn LLVMCountIncoming(ValueRef PhiNode) -> uint;
- fn LLVMGetIncomingValue(ValueRef PhiNode, uint Index) -> ValueRef;
- fn LLVMGetIncomingBlock(ValueRef PhiNode, uint Index) -> BasicBlockRef;
+ fn LLVMAddIncoming(PhiNode: ValueRef, IncomingValues: *ValueRef,
+ IncomingBlocks: *BasicBlockRef, Count: uint);
+ fn LLVMCountIncoming(PhiNode: ValueRef) -> uint;
+ fn LLVMGetIncomingValue(PhiNode: ValueRef, Index: uint) -> ValueRef;
+ fn LLVMGetIncomingBlock(PhiNode: ValueRef, Index: uint) -> BasicBlockRef;
/* Instruction builders */
- fn LLVMCreateBuilderInContext(ContextRef C) -> BuilderRef;
+ fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
fn LLVMCreateBuilder() -> BuilderRef;
- fn LLVMPositionBuilder(BuilderRef Builder, BasicBlockRef Block,
- ValueRef Instr);
- fn LLVMPositionBuilderBefore(BuilderRef Builder, ValueRef Instr);
- fn LLVMPositionBuilderAtEnd(BuilderRef Builder, BasicBlockRef Block);
- fn LLVMGetInsertBlock(BuilderRef Builder) -> BasicBlockRef;
- fn LLVMClearInsertionPosition(BuilderRef Builder);
- fn LLVMInsertIntoBuilder(BuilderRef Builder, ValueRef Instr);
- fn LLVMInsertIntoBuilderWithName(BuilderRef Builder, ValueRef Instr,
- sbuf Name);
- fn LLVMDisposeBuilder(BuilderRef Builder);
+ fn LLVMPositionBuilder(Builder: BuilderRef, Block: BasicBlockRef,
+ Instr: ValueRef);
+ fn LLVMPositionBuilderBefore(Builder: BuilderRef, Instr: ValueRef);
+ fn LLVMPositionBuilderAtEnd(Builder: BuilderRef, Block: BasicBlockRef);
+ fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef;
+ fn LLVMClearInsertionPosition(Builder: BuilderRef);
+ fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef);
+ fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef, Instr: ValueRef,
+ Name: sbuf);
+ fn LLVMDisposeBuilder(Builder: BuilderRef);
/* Metadata */
- fn LLVMSetCurrentDebugLocation(BuilderRef Builder, ValueRef L);
- fn LLVMGetCurrentDebugLocation(BuilderRef Builder) -> ValueRef;
- fn LLVMSetInstDebugLocation(BuilderRef Builder, ValueRef Inst);
+ fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef);
+ fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
+ fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);
/* Terminators */
- fn LLVMBuildRetVoid(BuilderRef B) -> ValueRef;
- fn LLVMBuildRet(BuilderRef B, ValueRef V) -> ValueRef;
- fn LLVMBuildAggregateRet(BuilderRef B, *ValueRef RetVals,
- uint N) -> ValueRef;
- fn LLVMBuildBr(BuilderRef B, BasicBlockRef Dest) -> ValueRef;
- fn LLVMBuildCondBr(BuilderRef B, ValueRef If,
- BasicBlockRef Then, BasicBlockRef Else) -> ValueRef;
- fn LLVMBuildSwitch(BuilderRef B, ValueRef V,
- BasicBlockRef Else, uint NumCases) -> ValueRef;
- fn LLVMBuildIndirectBr(BuilderRef B, ValueRef Addr,
- uint NumDests) -> ValueRef;
- fn LLVMBuildInvoke(BuilderRef B, ValueRef Fn,
- *ValueRef Args, uint NumArgs,
- BasicBlockRef Then, BasicBlockRef Catch,
- sbuf Name) -> ValueRef;
- fn LLVMBuildUnwind(BuilderRef B) -> ValueRef;
- fn LLVMBuildUnreachable(BuilderRef B) -> ValueRef;
+ fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
+ fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
+ fn LLVMBuildAggregateRet(B: BuilderRef, RetVals: *ValueRef, N: uint) ->
+ ValueRef;
+ fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef;
+ fn LLVMBuildCondBr(B: BuilderRef, If: ValueRef, Then: BasicBlockRef,
+ Else: BasicBlockRef) -> ValueRef;
+ fn LLVMBuildSwitch(B: BuilderRef, V: ValueRef, Else: BasicBlockRef,
+ NumCases: uint) -> ValueRef;
+ fn LLVMBuildIndirectBr(B: BuilderRef, Addr: ValueRef, NumDests: uint) ->
+ ValueRef;
+ fn LLVMBuildInvoke(B: BuilderRef, Fn: ValueRef, Args: *ValueRef,
+ NumArgs: uint, Then: BasicBlockRef,
+ Catch: BasicBlockRef, Name: sbuf) -> ValueRef;
+ fn LLVMBuildUnwind(B: BuilderRef) -> ValueRef;
+ fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
/* Add a case to the switch instruction */
- fn LLVMAddCase(ValueRef Switch, ValueRef OnVal,
- BasicBlockRef Dest);
+ fn LLVMAddCase(Switch: ValueRef, OnVal: ValueRef, Dest: BasicBlockRef);
/* Add a destination to the indirectbr instruction */
- fn LLVMAddDestination(ValueRef IndirectBr, BasicBlockRef Dest);
+ fn LLVMAddDestination(IndirectBr: ValueRef, Dest: BasicBlockRef);
/* Arithmetic */
- fn LLVMBuildAdd(BuilderRef B, ValueRef LHS, ValueRef RHS,
- sbuf Name) -> ValueRef;
- fn LLVMBuildNSWAdd(BuilderRef B, ValueRef LHS, ValueRef RHS,
- sbuf Name) -> ValueRef;
- fn LLVMBuildNUWAdd(BuilderRef B, ValueRef LHS, ValueRef RHS,
- sbuf Name) -> ValueRef;
- fn LLVMBuildFAdd(BuilderRef B, ValueRef LHS, ValueRef RHS,
- sbuf Name) -> ValueRef;
- fn LLVMBuildSub(BuilderRef B, ValueRef LHS, ValueRef RHS,
- sbuf Name) -> ValueRef;
- fn LLVMBuildNSWSub(BuilderRef B, ValueRef LHS, ValueRef RHS,
- sbuf Name) -> ValueRef;
- fn LLVMBuildNUWSub(BuilderRef B, ValueRef LHS, ValueRef RHS,
- sbuf Name) -> ValueRef;
- fn LLVMBuildFSub(BuilderRef B, ValueRef LHS, ValueRef RHS,
- sbuf Name) -> ValueRef;
- fn LLVMBuildMul(BuilderRef B, ValueRef LHS, ValueRef RHS,
- sbuf Name) -> ValueRef;
- fn LLVMBuildNSWMul(BuilderRef B, ValueRef LHS, ValueRef RHS,
- sbuf Name) -> ValueRef;
- fn LLVMBuildNUWMul(BuilderRef B, ValueRef LHS, ValueRef RHS,
- sbuf Name) -> ValueRef;
- fn LLVMBuildFMul(BuilderRef B, ValueRef LHS, ValueRef RHS,
- sbuf Name) -> ValueRef;
- fn LLVMBuildUDiv(BuilderRef B, ValueRef LHS, ValueRef RHS,
- sbuf Name) -> ValueRef;
- fn LLVMBuildSDiv(BuilderRef B, ValueRef LHS, ValueRef RHS,
- sbuf Name) -> ValueRef;
- fn LLVMBuildExactSDiv(BuilderRef B, ValueRef LHS, ValueRef RHS,
- sbuf Name) -> ValueRef;
- fn LLVMBuildFDiv(BuilderRef B, ValueRef LHS, ValueRef RHS,
- sbuf Name) -> ValueRef;
- fn LLVMBuildURem(BuilderRef B, ValueRef LHS, ValueRef RHS,
- sbuf Name) -> ValueRef;
- fn LLVMBuildSRem(BuilderRef B, ValueRef LHS, ValueRef RHS,
- sbuf Name) -> ValueRef;
- fn LLVMBuildFRem(BuilderRef B, ValueRef LHS, ValueRef RHS,
- sbuf Name) -> ValueRef;
- fn LLVMBuildShl(BuilderRef B, ValueRef LHS, ValueRef RHS,
- sbuf Name) -> ValueRef;
- fn LLVMBuildLShr(BuilderRef B, ValueRef LHS, ValueRef RHS,
- sbuf Name) -> ValueRef;
- fn LLVMBuildAShr(BuilderRef B, ValueRef LHS, ValueRef RHS,
- sbuf Name) -> ValueRef;
- fn LLVMBuildAnd(BuilderRef B, ValueRef LHS, ValueRef RHS,
- sbuf Name) -> ValueRef;
- fn LLVMBuildOr(BuilderRef B, ValueRef LHS, ValueRef RHS,
- sbuf Name) -> ValueRef;
- fn LLVMBuildXor(BuilderRef B, ValueRef LHS, ValueRef RHS,
- sbuf Name) -> ValueRef;
- fn LLVMBuildBinOp(BuilderRef B, Opcode Op,
- ValueRef LHS, ValueRef RHS,
- sbuf Name) -> ValueRef;
- fn LLVMBuildNeg(BuilderRef B, ValueRef V, sbuf Name) -> ValueRef;
- fn LLVMBuildNSWNeg(BuilderRef B, ValueRef V,
- sbuf Name) -> ValueRef;
- fn LLVMBuildNUWNeg(BuilderRef B, ValueRef V,
- sbuf Name) -> ValueRef;
- fn LLVMBuildFNeg(BuilderRef B, ValueRef V, sbuf Name) -> ValueRef;
- fn LLVMBuildNot(BuilderRef B, ValueRef V, sbuf Name) -> ValueRef;
+ fn LLVMBuildAdd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: sbuf)
+ -> ValueRef;
+ fn LLVMBuildNSWAdd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildNUWAdd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildFAdd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: sbuf)
+ -> ValueRef;
+ fn LLVMBuildSub(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: sbuf)
+ -> ValueRef;
+ fn LLVMBuildNSWSub(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildNUWSub(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildFSub(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: sbuf)
+ -> ValueRef;
+ fn LLVMBuildMul(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: sbuf)
+ -> ValueRef;
+ fn LLVMBuildNSWMul(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildNUWMul(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildFMul(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: sbuf)
+ -> ValueRef;
+ fn LLVMBuildUDiv(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: sbuf)
+ -> ValueRef;
+ fn LLVMBuildSDiv(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: sbuf)
+ -> ValueRef;
+ fn LLVMBuildExactSDiv(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildFDiv(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: sbuf)
+ -> ValueRef;
+ fn LLVMBuildURem(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: sbuf)
+ -> ValueRef;
+ fn LLVMBuildSRem(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: sbuf)
+ -> ValueRef;
+ fn LLVMBuildFRem(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: sbuf)
+ -> ValueRef;
+ fn LLVMBuildShl(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: sbuf)
+ -> ValueRef;
+ fn LLVMBuildLShr(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: sbuf)
+ -> ValueRef;
+ fn LLVMBuildAShr(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: sbuf)
+ -> ValueRef;
+ fn LLVMBuildAnd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: sbuf)
+ -> ValueRef;
+ fn LLVMBuildOr(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: sbuf) ->
+ ValueRef;
+ fn LLVMBuildXor(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: sbuf)
+ -> ValueRef;
+ fn LLVMBuildBinOp(B: BuilderRef, Op: Opcode, LHS: ValueRef, RHS: ValueRef,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: sbuf) -> ValueRef;
+ fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: sbuf) -> ValueRef;
+ fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: sbuf) -> ValueRef;
+ fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: sbuf) -> ValueRef;
+ fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: sbuf) -> ValueRef;
/* Memory */
- fn LLVMBuildMalloc(BuilderRef B, TypeRef Ty, sbuf Name) -> ValueRef;
- fn LLVMBuildArrayMalloc(BuilderRef B, TypeRef Ty,
- ValueRef Val, sbuf Name) -> ValueRef;
- fn LLVMBuildAlloca(BuilderRef B, TypeRef Ty, sbuf Name) -> ValueRef;
- fn LLVMBuildArrayAlloca(BuilderRef B, TypeRef Ty,
- ValueRef Val, sbuf Name) -> ValueRef;
- fn LLVMBuildFree(BuilderRef B, ValueRef PointerVal) -> ValueRef;
- fn LLVMBuildLoad(BuilderRef B, ValueRef PointerVal,
- sbuf Name) -> ValueRef;
- fn LLVMBuildStore(BuilderRef B, ValueRef Val, ValueRef Ptr) -> ValueRef;
- fn LLVMBuildGEP(BuilderRef B, ValueRef Pointer,
- *ValueRef Indices, uint NumIndices,
- sbuf Name) -> ValueRef;
- fn LLVMBuildInBoundsGEP(BuilderRef B, ValueRef Pointer,
- *ValueRef Indices, uint NumIndices,
- sbuf Name) -> ValueRef;
- fn LLVMBuildStructGEP(BuilderRef B, ValueRef Pointer,
- uint Idx, sbuf Name) -> ValueRef;
- fn LLVMBuildGlobalString(BuilderRef B, sbuf Str,
- sbuf Name) -> ValueRef;
- fn LLVMBuildGlobalStringPtr(BuilderRef B, sbuf Str,
- sbuf Name) -> ValueRef;
+ fn LLVMBuildMalloc(B: BuilderRef, Ty: TypeRef, Name: sbuf) -> ValueRef;
+ fn LLVMBuildArrayMalloc(B: BuilderRef, Ty: TypeRef, Val: ValueRef,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: sbuf) -> ValueRef;
+ fn LLVMBuildArrayAlloca(B: BuilderRef, Ty: TypeRef, Val: ValueRef,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildFree(B: BuilderRef, PointerVal: ValueRef) -> ValueRef;
+ fn LLVMBuildLoad(B: BuilderRef, PointerVal: ValueRef, Name: sbuf) ->
+ ValueRef;
+ fn LLVMBuildStore(B: BuilderRef, Val: ValueRef, Ptr: ValueRef) ->
+ ValueRef;
+ fn LLVMBuildGEP(B: BuilderRef, Pointer: ValueRef, Indices: *ValueRef,
+ NumIndices: uint, Name: sbuf) -> ValueRef;
+ fn LLVMBuildInBoundsGEP(B: BuilderRef, Pointer: ValueRef,
+ Indices: *ValueRef, NumIndices: uint, Name: sbuf)
+ -> ValueRef;
+ fn LLVMBuildStructGEP(B: BuilderRef, Pointer: ValueRef, Idx: uint,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildGlobalString(B: BuilderRef, Str: sbuf, Name: sbuf) ->
+ ValueRef;
+ fn LLVMBuildGlobalStringPtr(B: BuilderRef, Str: sbuf, Name: sbuf) ->
+ ValueRef;
/* Casts */
- fn LLVMBuildTrunc(BuilderRef B, ValueRef Val,
- TypeRef DestTy, sbuf Name) -> ValueRef;
- fn LLVMBuildZExt(BuilderRef B, ValueRef Val,
- TypeRef DestTy, sbuf Name) -> ValueRef;
- fn LLVMBuildSExt(BuilderRef B, ValueRef Val,
- TypeRef DestTy, sbuf Name) -> ValueRef;
- fn LLVMBuildFPToUI(BuilderRef B, ValueRef Val,
- TypeRef DestTy, sbuf Name) -> ValueRef;
- fn LLVMBuildFPToSI(BuilderRef B, ValueRef Val,
- TypeRef DestTy, sbuf Name) -> ValueRef;
- fn LLVMBuildUIToFP(BuilderRef B, ValueRef Val,
- TypeRef DestTy, sbuf Name) -> ValueRef;
- fn LLVMBuildSIToFP(BuilderRef B, ValueRef Val,
- TypeRef DestTy, sbuf Name) -> ValueRef;
- fn LLVMBuildFPTrunc(BuilderRef B, ValueRef Val,
- TypeRef DestTy, sbuf Name) -> ValueRef;
- fn LLVMBuildFPExt(BuilderRef B, ValueRef Val,
- TypeRef DestTy, sbuf Name) -> ValueRef;
- fn LLVMBuildPtrToInt(BuilderRef B, ValueRef Val,
- TypeRef DestTy, sbuf Name) -> ValueRef;
- fn LLVMBuildIntToPtr(BuilderRef B, ValueRef Val,
- TypeRef DestTy, sbuf Name) -> ValueRef;
- fn LLVMBuildBitCast(BuilderRef B, ValueRef Val,
- TypeRef DestTy, sbuf Name) -> ValueRef;
- fn LLVMBuildZExtOrBitCast(BuilderRef B, ValueRef Val,
- TypeRef DestTy, sbuf Name) -> ValueRef;
- fn LLVMBuildSExtOrBitCast(BuilderRef B, ValueRef Val,
- TypeRef DestTy, sbuf Name) -> ValueRef;
- fn LLVMBuildTruncOrBitCast(BuilderRef B, ValueRef Val,
- TypeRef DestTy, sbuf Name) -> ValueRef;
- fn LLVMBuildCast(BuilderRef B, Opcode Op, ValueRef Val,
- TypeRef DestTy, sbuf Name) -> ValueRef;
- fn LLVMBuildPointerCast(BuilderRef B, ValueRef Val,
- TypeRef DestTy, sbuf Name) -> ValueRef;
- fn LLVMBuildIntCast(BuilderRef B, ValueRef Val,
- TypeRef DestTy, sbuf Name) -> ValueRef;
- fn LLVMBuildFPCast(BuilderRef B, ValueRef Val,
- TypeRef DestTy, sbuf Name) -> ValueRef;
+ fn LLVMBuildTrunc(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildZExt(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildSExt(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildFPToUI(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildFPToSI(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildUIToFP(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildSIToFP(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildFPTrunc(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildFPExt(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildPtrToInt(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildIntToPtr(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildBitCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildZExtOrBitCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildSExtOrBitCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildTruncOrBitCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildCast(B: BuilderRef, Op: Opcode, Val: ValueRef,
+ DestTy: TypeRef, Name: sbuf) -> ValueRef;
+ fn LLVMBuildPointerCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildIntCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildFPCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
+ Name: sbuf) -> ValueRef;
/* Comparisons */
- fn LLVMBuildICmp(BuilderRef B, uint Op,
- ValueRef LHS, ValueRef RHS,
- sbuf Name) -> ValueRef;
- fn LLVMBuildFCmp(BuilderRef B, uint Op,
- ValueRef LHS, ValueRef RHS,
- sbuf Name) -> ValueRef;
+ fn LLVMBuildICmp(B: BuilderRef, Op: uint, LHS: ValueRef, RHS: ValueRef,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildFCmp(B: BuilderRef, Op: uint, LHS: ValueRef, RHS: ValueRef,
+ Name: sbuf) -> ValueRef;
/* Miscellaneous instructions */
- fn LLVMBuildPhi(BuilderRef B, TypeRef Ty, sbuf Name) -> ValueRef;
- fn LLVMBuildCall(BuilderRef B, ValueRef Fn,
- *ValueRef Args, uint NumArgs,
- sbuf Name) -> ValueRef;
- fn LLVMBuildSelect(BuilderRef B, ValueRef If,
- ValueRef Then, ValueRef Else,
- sbuf Name) -> ValueRef;
- fn LLVMBuildVAArg(BuilderRef B, ValueRef list, TypeRef Ty,
- sbuf Name) -> ValueRef;
- fn LLVMBuildExtractElement(BuilderRef B, ValueRef VecVal,
- ValueRef Index, sbuf Name) -> ValueRef;
- fn LLVMBuildInsertElement(BuilderRef B, ValueRef VecVal,
- ValueRef EltVal, ValueRef Index,
- sbuf Name) -> ValueRef;
- fn LLVMBuildShuffleVector(BuilderRef B, ValueRef V1,
- ValueRef V2, ValueRef Mask,
- sbuf Name) -> ValueRef;
- fn LLVMBuildExtractValue(BuilderRef B, ValueRef AggVal,
- uint Index, sbuf Name) -> ValueRef;
- fn LLVMBuildInsertValue(BuilderRef B, ValueRef AggVal,
- ValueRef EltVal, uint Index,
- sbuf Name) -> ValueRef;
+ fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: sbuf) -> ValueRef;
+ fn LLVMBuildCall(B: BuilderRef, Fn: ValueRef, Args: *ValueRef,
+ NumArgs: uint, Name: sbuf) -> ValueRef;
+ fn LLVMBuildSelect(B: BuilderRef, If: ValueRef, Then: ValueRef,
+ Else: ValueRef, Name: sbuf) -> ValueRef;
+ fn LLVMBuildVAArg(B: BuilderRef, list: ValueRef, Ty: TypeRef, Name: sbuf)
+ -> ValueRef;
+ fn LLVMBuildExtractElement(B: BuilderRef, VecVal: ValueRef,
+ Index: ValueRef, Name: sbuf) -> ValueRef;
+ fn LLVMBuildInsertElement(B: BuilderRef, VecVal: ValueRef,
+ EltVal: ValueRef, Index: ValueRef, Name: sbuf)
+ -> ValueRef;
+ fn LLVMBuildShuffleVector(B: BuilderRef, V1: ValueRef, V2: ValueRef,
+ Mask: ValueRef, Name: sbuf) -> ValueRef;
+ fn LLVMBuildExtractValue(B: BuilderRef, AggVal: ValueRef, Index: uint,
+ Name: sbuf) -> ValueRef;
+ fn LLVMBuildInsertValue(B: BuilderRef, AggVal: ValueRef, EltVal: ValueRef,
+ Index: uint, Name: sbuf) -> ValueRef;
- fn LLVMBuildIsNull(BuilderRef B, ValueRef Val,
- sbuf Name) -> ValueRef;
- fn LLVMBuildIsNotNull(BuilderRef B, ValueRef Val,
- sbuf Name) -> ValueRef;
- fn LLVMBuildPtrDiff(BuilderRef B, ValueRef LHS,
- ValueRef RHS, sbuf Name) -> ValueRef;
+ fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: sbuf) -> ValueRef;
+ fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: sbuf) ->
+ ValueRef;
+ fn LLVMBuildPtrDiff(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
+ Name: sbuf) -> ValueRef;
/* Selected entries from the downcasts. */
- fn LLVMIsATerminatorInst(ValueRef Inst) -> ValueRef;
+ fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
/** Writes a module to the specified path. Returns 0 on success. */
- fn LLVMWriteBitcodeToFile(ModuleRef M, sbuf Path) -> int;
+ fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: sbuf) -> int;
/** Creates target data from a target layout string. */
- fn LLVMCreateTargetData(sbuf StringRep) -> TargetDataRef;
+ fn LLVMCreateTargetData(StringRep: sbuf) -> TargetDataRef;
/** Adds the target data to the given pass manager. The pass manager
references the target data only weakly. */
- fn LLVMAddTargetData(TargetDataRef TD, PassManagerRef PM);
+ fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
/** Returns the size of a type. FIXME: rv is actually a ULongLong! */
- fn LLVMStoreSizeOfType(TargetDataRef TD, TypeRef Ty) -> uint;
+ fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef) -> uint;
/** Returns the alignment of a type. */
- fn LLVMPreferredAlignmentOfType(TargetDataRef TD, TypeRef Ty) -> uint;
+ fn LLVMPreferredAlignmentOfType(TD: TargetDataRef, Ty: TypeRef) -> uint;
/** Disposes target data. */
- fn LLVMDisposeTargetData(TargetDataRef TD);
+ fn LLVMDisposeTargetData(TD: TargetDataRef);
/** Creates a pass manager. */
fn LLVMCreatePassManager() -> PassManagerRef;
/** Disposes a pass manager. */
- fn LLVMDisposePassManager(PassManagerRef PM);
+ fn LLVMDisposePassManager(PM: PassManagerRef);
/** Runs a pass manager on a module. */
- fn LLVMRunPassManager(PassManagerRef PM, ModuleRef M) -> Bool;
+ fn LLVMRunPassManager(PM: PassManagerRef, M: ModuleRef) -> Bool;
/** Adds a verification pass. */
- fn LLVMAddVerifierPass(PassManagerRef PM);
+ fn LLVMAddVerifierPass(PM: PassManagerRef);
- fn LLVMAddGlobalOptimizerPass(PassManagerRef PM);
- fn LLVMAddIPSCCPPass(PassManagerRef PM);
- fn LLVMAddDeadArgEliminationPass(PassManagerRef PM);
- fn LLVMAddInstructionCombiningPass(PassManagerRef PM);
- fn LLVMAddCFGSimplificationPass(PassManagerRef PM);
- fn LLVMAddFunctionInliningPass(PassManagerRef PM);
- fn LLVMAddFunctionAttrsPass(PassManagerRef PM);
- fn LLVMAddScalarReplAggregatesPass(PassManagerRef PM);
- fn LLVMAddScalarReplAggregatesPassSSA(PassManagerRef PM);
- fn LLVMAddJumpThreadingPass(PassManagerRef PM);
- fn LLVMAddConstantPropagationPass(PassManagerRef PM);
- fn LLVMAddReassociatePass(PassManagerRef PM);
- fn LLVMAddLoopRotatePass(PassManagerRef PM);
- fn LLVMAddLICMPass(PassManagerRef PM);
- fn LLVMAddLoopUnswitchPass(PassManagerRef PM);
- fn LLVMAddLoopDeletionPass(PassManagerRef PM);
- fn LLVMAddLoopUnrollPass(PassManagerRef PM);
- fn LLVMAddGVNPass(PassManagerRef PM);
- fn LLVMAddMemCpyOptPass(PassManagerRef PM);
- fn LLVMAddSCCPPass(PassManagerRef PM);
- fn LLVMAddDeadStoreEliminationPass(PassManagerRef PM);
- fn LLVMAddStripDeadPrototypesPass(PassManagerRef PM);
- fn LLVMAddConstantMergePass(PassManagerRef PM);
- fn LLVMAddArgumentPromotionPass(PassManagerRef PM);
- fn LLVMAddTailCallEliminationPass(PassManagerRef PM);
- fn LLVMAddIndVarSimplifyPass(PassManagerRef PM);
- fn LLVMAddAggressiveDCEPass(PassManagerRef PM);
- fn LLVMAddGlobalDCEPass(PassManagerRef PM);
- fn LLVMAddCorrelatedValuePropagationPass(PassManagerRef PM);
- fn LLVMAddPruneEHPass(PassManagerRef PM);
- fn LLVMAddSimplifyLibCallsPass(PassManagerRef PM);
- fn LLVMAddLoopIdiomPass(PassManagerRef PM);
- fn LLVMAddEarlyCSEPass(PassManagerRef PM);
- fn LLVMAddTypeBasedAliasAnalysisPass(PassManagerRef PM);
- fn LLVMAddBasicAliasAnalysisPass(PassManagerRef PM);
+ fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
+ fn LLVMAddIPSCCPPass(PM: PassManagerRef);
+ fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
+ fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
+ fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
+ fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
+ fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
+ fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
+ fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
+ fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
+ fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
+ fn LLVMAddReassociatePass(PM: PassManagerRef);
+ fn LLVMAddLoopRotatePass(PM: PassManagerRef);
+ fn LLVMAddLICMPass(PM: PassManagerRef);
+ fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
+ fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
+ fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
+ fn LLVMAddGVNPass(PM: PassManagerRef);
+ fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
+ fn LLVMAddSCCPPass(PM: PassManagerRef);
+ fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
+ fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
+ fn LLVMAddConstantMergePass(PM: PassManagerRef);
+ fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
+ fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
+ fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
+ fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
+ fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
+ fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef);
+ fn LLVMAddPruneEHPass(PM: PassManagerRef);
+ fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
+ fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
+ fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
+ fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
+ fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
- fn LLVMAddStandardFunctionPasses(PassManagerRef PM,
- uint OptimizationLevel);
- fn LLVMAddStandardModulePasses(PassManagerRef PM,
- uint OptimizationLevel,
- Bool OptimizeSize,
- Bool UnitAtATime,
- Bool UnrollLoops,
- Bool SimplifyLibCalls,
- uint InliningThreshold);
+ fn LLVMAddStandardFunctionPasses(PM: PassManagerRef,
+ OptimizationLevel: uint);
+ fn LLVMAddStandardModulePasses(PM: PassManagerRef,
+ OptimizationLevel: uint,
+ OptimizeSize: Bool, UnitAtATime: Bool,
+ UnrollLoops: Bool, SimplifyLibCalls: Bool,
+ InliningThreshold: uint);
/** Destroys a memory buffer. */
- fn LLVMDisposeMemoryBuffer(MemoryBufferRef MemBuf);
+ fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
/* Stuff that's in rustllvm/ because it's not upstream yet. */
@@ -813,37 +817,36 @@
type SectionIteratorRef;
/** Opens an object file. */
- fn LLVMCreateObjectFile(MemoryBufferRef MemBuf) -> ObjectFileRef;
+ fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
/** Closes an object file. */
- fn LLVMDisposeObjectFile(ObjectFileRef ObjectFile);
+ fn LLVMDisposeObjectFile(ObjectFile: ObjectFileRef);
/** Enumerates the sections in an object file. */
- fn LLVMGetSections(ObjectFileRef ObjectFile) -> SectionIteratorRef;
+ fn LLVMGetSections(ObjectFile: ObjectFileRef) -> SectionIteratorRef;
/** Destroys a section iterator. */
- fn LLVMDisposeSectionIterator(SectionIteratorRef SI);
+ fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
/** Returns true if the section iterator is at the end of the section
list: */
- fn LLVMIsSectionIteratorAtEnd(ObjectFileRef ObjectFile,
- SectionIteratorRef SI) -> Bool;
+ fn LLVMIsSectionIteratorAtEnd(ObjectFile: ObjectFileRef,
+ SI: SectionIteratorRef) -> Bool;
/** Moves the section iterator to point to the next section. */
- fn LLVMMoveToNextSection(SectionIteratorRef SI);
+ fn LLVMMoveToNextSection(SI: SectionIteratorRef);
/** Returns the current section name. */
- fn LLVMGetSectionName(SectionIteratorRef SI) -> sbuf;
+ fn LLVMGetSectionName(SI: SectionIteratorRef) -> sbuf;
/** Returns the current section size.
FIXME: The return value is actually a uint64_t! */
- fn LLVMGetSectionSize(SectionIteratorRef SI) -> uint;
+ fn LLVMGetSectionSize(SI: SectionIteratorRef) -> uint;
/** Returns the current section contents as a string buffer. */
- fn LLVMGetSectionContents(SectionIteratorRef SI) -> sbuf;
+ fn LLVMGetSectionContents(SI: SectionIteratorRef) -> sbuf;
/** Reads the given file and returns it as a memory buffer. Use
LLVMDisposeMemoryBuffer() to get rid of it. */
- fn LLVMRustCreateMemoryBufferWithContentsOfFile(sbuf Path) ->
- MemoryBufferRef;
+ fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: sbuf) ->
+ MemoryBufferRef;
/* FIXME: The FileType is an enum.*/
- fn LLVMRustWriteOutputFile(PassManagerRef PM, ModuleRef M,
- sbuf Triple, sbuf Output,
- int FileType, int OptLevel);
+ fn LLVMRustWriteOutputFile(PM: PassManagerRef, M: ModuleRef, Triple: sbuf,
+ Output: sbuf, FileType: int, OptLevel: int);
/** Returns a string describing the last error caused by an LLVMRust*
call. */
@@ -853,11 +856,11 @@
fn LLVMRustGetHostTriple() -> sbuf;
/** Parses the bitcode in the given memory buffer. */
- fn LLVMRustParseBitcode(MemoryBufferRef MemBuf) -> ModuleRef;
+ fn LLVMRustParseBitcode(MemBuf: MemoryBufferRef) -> ModuleRef;
/** FiXME: Hacky adaptor for lack of ULongLong in FFI: */
- fn LLVMRustConstSmallInt(TypeRef IntTy, uint N,
- Bool SignExtend) -> ValueRef;
+ fn LLVMRustConstSmallInt(IntTy: TypeRef, N: uint, SignExtend: Bool) ->
+ ValueRef;
/** Turn on LLVM pass-timing. */
fn LLVMRustEnableTimePasses();
@@ -865,17 +868,17 @@
/** Print the pass timings since static dtors aren't picking them up. */
fn LLVMRustPrintPassTimings();
- fn LLVMStructCreateNamed(ContextRef C, sbuf Name) -> TypeRef;
+ fn LLVMStructCreateNamed(C: ContextRef, Name: sbuf) -> TypeRef;
- fn LLVMStructSetBody(TypeRef StructTy, *TypeRef ElementTypes,
- uint ElementCount, Bool Packed);
+ fn LLVMStructSetBody(StructTy: TypeRef, ElementTypes: *TypeRef,
+ ElementCount: uint, Packed: Bool);
- fn LLVMConstNamedStruct(TypeRef S, *ValueRef ConstantVals,
- uint Count) -> ValueRef;
+ fn LLVMConstNamedStruct(S: TypeRef, ConstantVals: *ValueRef, Count: uint)
+ -> ValueRef;
/** Links LLVM modules together. `Src` is destroyed by this call and
must never be referenced again. */
- fn LLVMLinkModules(ModuleRef Dest, ModuleRef Src) -> Bool;
+ fn LLVMLinkModules(Dest: ModuleRef, Src: ModuleRef) -> Bool;
}
/* Slightly more terse object-interface to LLVM's 'builder' functions. For the
@@ -887,57 +890,55 @@
*/
// FIXME: Do we want to support mutable object fields?
-obj builder(BuilderRef B, @mutable bool terminated) {
+obj builder(B: BuilderRef, terminated: @mutable bool) {
/* Terminators */
- fn RetVoid() -> ValueRef {
+ fn RetVoid() -> ValueRef {
assert (!*terminated);
*terminated = true;
ret llvm::LLVMBuildRetVoid(B);
}
- fn Ret(ValueRef V) -> ValueRef {
+ fn Ret(V: ValueRef) -> ValueRef {
assert (!*terminated);
*terminated = true;
ret llvm::LLVMBuildRet(B, V);
}
- fn AggregateRet(&ValueRef[] RetVals) -> ValueRef {
+ fn AggregateRet(RetVals: &ValueRef[]) -> ValueRef {
assert (!*terminated);
*terminated = true;
ret llvm::LLVMBuildAggregateRet(B, ivec::to_ptr(RetVals),
ivec::len(RetVals));
}
- fn Br(BasicBlockRef Dest) -> ValueRef {
+ fn Br(Dest: BasicBlockRef) -> ValueRef {
assert (!*terminated);
*terminated = true;
ret llvm::LLVMBuildBr(B, Dest);
}
- fn CondBr(ValueRef If, BasicBlockRef Then,
- BasicBlockRef Else) -> ValueRef {
+ fn CondBr(If: ValueRef, Then: BasicBlockRef, Else: BasicBlockRef) ->
+ ValueRef {
assert (!*terminated);
*terminated = true;
ret llvm::LLVMBuildCondBr(B, If, Then, Else);
}
- fn Switch(ValueRef V, BasicBlockRef Else, uint NumCases) -> ValueRef {
+ fn Switch(V: ValueRef, Else: BasicBlockRef, NumCases: uint) -> ValueRef {
assert (!*terminated);
*terminated = true;
ret llvm::LLVMBuildSwitch(B, V, Else, NumCases);
}
- fn IndirectBr(ValueRef Addr, uint NumDests) -> ValueRef {
+ fn IndirectBr(Addr: ValueRef, NumDests: uint) -> ValueRef {
assert (!*terminated);
*terminated = true;
ret llvm::LLVMBuildIndirectBr(B, Addr, NumDests);
}
- fn Invoke(ValueRef Fn,
- &ValueRef[] Args,
- BasicBlockRef Then,
- BasicBlockRef Catch) -> ValueRef {
+ fn Invoke(Fn: ValueRef, Args: &ValueRef[], Then: BasicBlockRef,
+ Catch: BasicBlockRef) -> ValueRef {
assert (!*terminated);
*terminated = true;
ret llvm::LLVMBuildInvoke(B, Fn, ivec::to_ptr(Args), ivec::len(Args),
@@ -957,605 +958,596 @@
}
/* Arithmetic */
- fn Add(ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn Add(LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildAdd(B, LHS, RHS, str::buf(""));
}
- fn NSWAdd(ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn NSWAdd(LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildNSWAdd(B, LHS, RHS, str::buf(""));
}
- fn NUWAdd(ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn NUWAdd(LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildNUWAdd(B, LHS, RHS, str::buf(""));
}
- fn FAdd(ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn FAdd(LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildFAdd(B, LHS, RHS, str::buf(""));
}
- fn Sub(ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn Sub(LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildSub(B, LHS, RHS, str::buf(""));
}
- fn NSWSub(ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn NSWSub(LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildNSWSub(B, LHS, RHS, str::buf(""));
}
- fn NUWSub(ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn NUWSub(LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildNUWSub(B, LHS, RHS, str::buf(""));
}
- fn FSub(ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn FSub(LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildFSub(B, LHS, RHS, str::buf(""));
}
- fn Mul(ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn Mul(LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildMul(B, LHS, RHS, str::buf(""));
}
- fn NSWMul(ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn NSWMul(LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildNSWMul(B, LHS, RHS, str::buf(""));
}
- fn NUWMul(ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn NUWMul(LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildNUWMul(B, LHS, RHS, str::buf(""));
}
- fn FMul(ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn FMul(LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildFMul(B, LHS, RHS, str::buf(""));
}
- fn UDiv(ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn UDiv(LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildUDiv(B, LHS, RHS, str::buf(""));
}
- fn SDiv(ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn SDiv(LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildSDiv(B, LHS, RHS, str::buf(""));
}
- fn ExactSDiv(ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn ExactSDiv(LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildExactSDiv(B, LHS, RHS, str::buf(""));
}
- fn FDiv(ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn FDiv(LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildFDiv(B, LHS, RHS, str::buf(""));
}
- fn URem(ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn URem(LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildURem(B, LHS, RHS, str::buf(""));
}
- fn SRem(ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn SRem(LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildSRem(B, LHS, RHS, str::buf(""));
}
- fn FRem(ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn FRem(LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildFRem(B, LHS, RHS, str::buf(""));
}
- fn Shl(ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn Shl(LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildShl(B, LHS, RHS, str::buf(""));
}
- fn LShr(ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn LShr(LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildLShr(B, LHS, RHS, str::buf(""));
}
- fn AShr(ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn AShr(LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildAShr(B, LHS, RHS, str::buf(""));
}
- fn And(ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn And(LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildAnd(B, LHS, RHS, str::buf(""));
}
- fn Or(ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn Or(LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildOr(B, LHS, RHS, str::buf(""));
}
- fn Xor(ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn Xor(LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildXor(B, LHS, RHS, str::buf(""));
}
- fn BinOp(Opcode Op, ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn BinOp(Op: Opcode, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildBinOp(B, Op, LHS, RHS, str::buf(""));
}
- fn Neg(ValueRef V) -> ValueRef {
+ fn Neg(V: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildNeg(B, V, str::buf(""));
}
- fn NSWNeg(ValueRef V) -> ValueRef {
+ fn NSWNeg(V: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildNSWNeg(B, V, str::buf(""));
}
- fn NUWNeg(ValueRef V) -> ValueRef {
+ fn NUWNeg(V: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildNUWNeg(B, V, str::buf(""));
}
- fn FNeg(ValueRef V) -> ValueRef {
+ fn FNeg(V: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildFNeg(B, V, str::buf(""));
}
- fn Not(ValueRef V) -> ValueRef {
+ fn Not(V: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildNot(B, V, str::buf(""));
}
/* Memory */
- fn Malloc(TypeRef Ty) -> ValueRef {
+ fn Malloc(Ty: TypeRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildMalloc(B, Ty, str::buf(""));
}
- fn ArrayMalloc(TypeRef Ty, ValueRef Val) -> ValueRef {
+ fn ArrayMalloc(Ty: TypeRef, Val: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildArrayMalloc(B, Ty, Val, str::buf(""));
}
- fn Alloca(TypeRef Ty) -> ValueRef {
+ fn Alloca(Ty: TypeRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildAlloca(B, Ty, str::buf(""));
}
- fn ArrayAlloca(TypeRef Ty, ValueRef Val) -> ValueRef {
+ fn ArrayAlloca(Ty: TypeRef, Val: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildArrayAlloca(B, Ty, Val, str::buf(""));
}
- fn Free(ValueRef PointerVal) -> ValueRef {
+ fn Free(PointerVal: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildFree(B, PointerVal);
}
- fn Load(ValueRef PointerVal) -> ValueRef {
+ fn Load(PointerVal: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildLoad(B, PointerVal, str::buf(""));
}
- fn Store(ValueRef Val, ValueRef Ptr) -> ValueRef {
+ fn Store(Val: ValueRef, Ptr: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildStore(B, Val, Ptr);
}
- fn GEP(ValueRef Pointer, &ValueRef[] Indices) -> ValueRef {
+ fn GEP(Pointer: ValueRef, Indices: &ValueRef[]) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildGEP(B, Pointer, ivec::to_ptr(Indices),
ivec::len(Indices), str::buf(""));
}
- fn InBoundsGEP(ValueRef Pointer, &ValueRef[] Indices) -> ValueRef {
+ fn InBoundsGEP(Pointer: ValueRef, Indices: &ValueRef[]) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildInBoundsGEP(B, Pointer, ivec::to_ptr(Indices),
ivec::len(Indices), str::buf(""));
}
- fn StructGEP(ValueRef Pointer, uint Idx) -> ValueRef {
+ fn StructGEP(Pointer: ValueRef, Idx: uint) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildStructGEP(B, Pointer, Idx, str::buf(""));
}
- fn GlobalString(sbuf _Str) -> ValueRef {
+ fn GlobalString(_Str: sbuf) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildGlobalString(B, _Str, str::buf(""));
}
- fn GlobalStringPtr(sbuf _Str) -> ValueRef {
+ fn GlobalStringPtr(_Str: sbuf) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildGlobalStringPtr(B, _Str, str::buf(""));
}
/* Casts */
- fn Trunc(ValueRef Val, TypeRef DestTy) -> ValueRef {
+ fn Trunc(Val: ValueRef, DestTy: TypeRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildTrunc(B, Val, DestTy, str::buf(""));
}
- fn ZExt(ValueRef Val, TypeRef DestTy) -> ValueRef {
+ fn ZExt(Val: ValueRef, DestTy: TypeRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildZExt(B, Val, DestTy, str::buf(""));
}
- fn SExt(ValueRef Val, TypeRef DestTy) -> ValueRef {
+ fn SExt(Val: ValueRef, DestTy: TypeRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildSExt(B, Val, DestTy, str::buf(""));
}
- fn FPToUI(ValueRef Val, TypeRef DestTy) -> ValueRef {
+ fn FPToUI(Val: ValueRef, DestTy: TypeRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildFPToUI(B, Val, DestTy, str::buf(""));
}
- fn FPToSI(ValueRef Val, TypeRef DestTy) -> ValueRef {
+ fn FPToSI(Val: ValueRef, DestTy: TypeRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildFPToSI(B, Val, DestTy, str::buf(""));
}
- fn UIToFP(ValueRef Val, TypeRef DestTy) -> ValueRef {
+ fn UIToFP(Val: ValueRef, DestTy: TypeRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildUIToFP(B, Val, DestTy, str::buf(""));
}
- fn SIToFP(ValueRef Val, TypeRef DestTy) -> ValueRef {
+ fn SIToFP(Val: ValueRef, DestTy: TypeRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildSIToFP(B, Val, DestTy, str::buf(""));
}
- fn FPTrunc(ValueRef Val, TypeRef DestTy) -> ValueRef {
+ fn FPTrunc(Val: ValueRef, DestTy: TypeRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildFPTrunc(B, Val, DestTy, str::buf(""));
}
- fn FPExt(ValueRef Val, TypeRef DestTy) -> ValueRef {
+ fn FPExt(Val: ValueRef, DestTy: TypeRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildFPExt(B, Val, DestTy, str::buf(""));
}
- fn PtrToInt(ValueRef Val, TypeRef DestTy) -> ValueRef {
+ fn PtrToInt(Val: ValueRef, DestTy: TypeRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildPtrToInt(B, Val, DestTy, str::buf(""));
}
- fn IntToPtr(ValueRef Val, TypeRef DestTy) -> ValueRef {
+ fn IntToPtr(Val: ValueRef, DestTy: TypeRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildIntToPtr(B, Val, DestTy, str::buf(""));
}
- fn BitCast(ValueRef Val, TypeRef DestTy) -> ValueRef {
+ fn BitCast(Val: ValueRef, DestTy: TypeRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildBitCast(B, Val, DestTy, str::buf(""));
}
- fn ZExtOrBitCast(ValueRef Val, TypeRef DestTy) -> ValueRef {
+ fn ZExtOrBitCast(Val: ValueRef, DestTy: TypeRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildZExtOrBitCast(B, Val, DestTy, str::buf(""));
}
- fn SExtOrBitCast(ValueRef Val, TypeRef DestTy) -> ValueRef {
+ fn SExtOrBitCast(Val: ValueRef, DestTy: TypeRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildSExtOrBitCast(B, Val, DestTy, str::buf(""));
}
- fn TruncOrBitCast(ValueRef Val, TypeRef DestTy) -> ValueRef {
+ fn TruncOrBitCast(Val: ValueRef, DestTy: TypeRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildTruncOrBitCast(B, Val, DestTy, str::buf(""));
}
- fn Cast(Opcode Op, ValueRef Val, TypeRef DestTy, sbuf Name) -> ValueRef {
+ fn Cast(Op: Opcode, Val: ValueRef, DestTy: TypeRef, Name: sbuf) ->
+ ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildCast(B, Op, Val, DestTy, str::buf(""));
}
- fn PointerCast(ValueRef Val, TypeRef DestTy) -> ValueRef {
+ fn PointerCast(Val: ValueRef, DestTy: TypeRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildPointerCast(B, Val, DestTy, str::buf(""));
}
- fn IntCast(ValueRef Val, TypeRef DestTy) -> ValueRef {
+ fn IntCast(Val: ValueRef, DestTy: TypeRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildIntCast(B, Val, DestTy, str::buf(""));
}
- fn FPCast(ValueRef Val, TypeRef DestTy) -> ValueRef {
+ fn FPCast(Val: ValueRef, DestTy: TypeRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildFPCast(B, Val, DestTy, str::buf(""));
}
/* Comparisons */
- fn ICmp(uint Op, ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn ICmp(Op: uint, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildICmp(B, Op, LHS, RHS, str::buf(""));
}
- fn FCmp(uint Op, ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn FCmp(Op: uint, LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildFCmp(B, Op, LHS, RHS, str::buf(""));
}
/* Miscellaneous instructions */
- fn Phi(TypeRef Ty, &ValueRef[] vals, &BasicBlockRef[] bbs) -> ValueRef {
+ fn Phi(Ty: TypeRef, vals: &ValueRef[], bbs: &BasicBlockRef[]) ->
+ ValueRef {
assert (!*terminated);
- auto phi = llvm::LLVMBuildPhi(B, Ty, str::buf(""));
+ let phi = llvm::LLVMBuildPhi(B, Ty, str::buf(""));
assert (ivec::len[ValueRef](vals) == ivec::len[BasicBlockRef](bbs));
llvm::LLVMAddIncoming(phi, ivec::to_ptr(vals), ivec::to_ptr(bbs),
ivec::len(vals));
ret phi;
}
- fn AddIncomingToPhi(ValueRef phi,
- &ValueRef[] vals,
- &BasicBlockRef[] bbs) {
+ fn AddIncomingToPhi(phi: ValueRef, vals: &ValueRef[],
+ bbs: &BasicBlockRef[]) {
assert (ivec::len[ValueRef](vals) == ivec::len[BasicBlockRef](bbs));
llvm::LLVMAddIncoming(phi, ivec::to_ptr(vals), ivec::to_ptr(bbs),
ivec::len(vals));
}
- fn Call(ValueRef Fn, &ValueRef[] Args) -> ValueRef {
+ fn Call(Fn: ValueRef, Args: &ValueRef[]) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildCall(B, Fn, ivec::to_ptr(Args), ivec::len(Args),
str::buf(""));
}
- fn FastCall(ValueRef Fn, &ValueRef[] Args) -> ValueRef {
+ fn FastCall(Fn: ValueRef, Args: &ValueRef[]) -> ValueRef {
assert (!*terminated);
- auto v = llvm::LLVMBuildCall(B, Fn, ivec::to_ptr(Args),
- ivec::len(Args), str::buf(""));
+ let v =
+ llvm::LLVMBuildCall(B, Fn, ivec::to_ptr(Args), ivec::len(Args),
+ str::buf(""));
llvm::LLVMSetInstructionCallConv(v, LLVMFastCallConv);
ret v;
}
- fn CallWithConv(ValueRef Fn, &ValueRef[] Args,
- uint Conv) -> ValueRef {
- assert !(*terminated);
- auto v = llvm::LLVMBuildCall(B, Fn, ivec::to_ptr(Args),
- ivec::len(Args), str::buf(""));
+ fn CallWithConv(Fn: ValueRef, Args: &ValueRef[], Conv: uint) -> ValueRef {
+ assert (!*terminated);
+ let v =
+ llvm::LLVMBuildCall(B, Fn, ivec::to_ptr(Args), ivec::len(Args),
+ str::buf(""));
llvm::LLVMSetInstructionCallConv(v, Conv);
ret v;
}
- fn Select(ValueRef If, ValueRef Then, ValueRef Else) -> ValueRef {
+ fn Select(If: ValueRef, Then: ValueRef, Else: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildSelect(B, If, Then, Else, str::buf(""));
}
- fn VAArg(ValueRef list, TypeRef Ty) -> ValueRef {
+ fn VAArg(list: ValueRef, Ty: TypeRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildVAArg(B, list, Ty, str::buf(""));
}
- fn ExtractElement(ValueRef VecVal, ValueRef Index) -> ValueRef {
+ fn ExtractElement(VecVal: ValueRef, Index: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildExtractElement(B, VecVal, Index, str::buf(""));
}
- fn InsertElement(ValueRef VecVal, ValueRef EltVal,
- ValueRef Index) -> ValueRef {
+ fn InsertElement(VecVal: ValueRef, EltVal: ValueRef, Index: ValueRef) ->
+ ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildInsertElement(B, VecVal, EltVal, Index,
- str::buf(""));
+ str::buf(""));
}
- fn ShuffleVector(ValueRef V1, ValueRef V2, ValueRef Mask) -> ValueRef {
+ fn ShuffleVector(V1: ValueRef, V2: ValueRef, Mask: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildShuffleVector(B, V1, V2, Mask, str::buf(""));
}
- fn ExtractValue(ValueRef AggVal, uint Index) -> ValueRef {
+ fn ExtractValue(AggVal: ValueRef, Index: uint) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildExtractValue(B, AggVal, Index, str::buf(""));
}
- fn InsertValue(ValueRef AggVal, ValueRef EltVal,
- uint Index) -> ValueRef {
+ fn InsertValue(AggVal: ValueRef, EltVal: ValueRef, Index: uint) ->
+ ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildInsertValue(B, AggVal, EltVal, Index,
str::buf(""));
}
- fn IsNull(ValueRef Val) -> ValueRef {
+ fn IsNull(Val: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildIsNull(B, Val, str::buf(""));
}
- fn IsNotNull(ValueRef Val) -> ValueRef {
+ fn IsNotNull(Val: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildIsNotNull(B, Val, str::buf(""));
}
- fn PtrDiff(ValueRef LHS, ValueRef RHS) -> ValueRef {
+ fn PtrDiff(LHS: ValueRef, RHS: ValueRef) -> ValueRef {
assert (!*terminated);
ret llvm::LLVMBuildPtrDiff(B, LHS, RHS, str::buf(""));
}
fn Trap() -> ValueRef {
assert (!*terminated);
- let BasicBlockRef BB = llvm::LLVMGetInsertBlock(B);
- let ValueRef FN = llvm::LLVMGetBasicBlockParent(BB);
- let ModuleRef M = llvm::LLVMGetGlobalParent(FN);
- let ValueRef T = llvm::LLVMGetNamedFunction(M,
- str::buf("llvm.trap"));
+ let BB: BasicBlockRef = llvm::LLVMGetInsertBlock(B);
+ let FN: ValueRef = llvm::LLVMGetBasicBlockParent(BB);
+ let M: ModuleRef = llvm::LLVMGetGlobalParent(FN);
+ let T: ValueRef =
+ llvm::LLVMGetNamedFunction(M, str::buf("llvm.trap"));
assert (T as int != 0);
- let ValueRef[] Args = ~[];
+ let Args: ValueRef[] = ~[];
ret llvm::LLVMBuildCall(B, T, ivec::to_ptr(Args), ivec::len(Args),
str::buf(""));
}
fn is_terminated() -> bool {
ret *terminated;
- }
+ }drop
- drop {
- llvm::LLVMDisposeBuilder(B);
- }
+ {
+ llvm::LLVMDisposeBuilder(B);
+ }
}
/* Memory-managed object interface to type handles. */
-state obj type_names(std::map::hashmap[TypeRef, str] type_names,
- std::map::hashmap[str, TypeRef] named_types) {
+obj type_names(type_names: std::map::hashmap[TypeRef, str],
+ named_types: std::map::hashmap[str, TypeRef]) {
- fn associate(str s, TypeRef t) {
+ fn associate(s: str, t: TypeRef) {
assert (!named_types.contains_key(s));
assert (!type_names.contains_key(t));
type_names.insert(t, s);
named_types.insert(s, t);
}
- fn type_has_name(TypeRef t) -> bool {
- ret type_names.contains_key(t);
- }
+ fn type_has_name(t: TypeRef) -> bool { ret type_names.contains_key(t); }
- fn get_name(TypeRef t) -> str {
- ret type_names.get(t);
- }
+ fn get_name(t: TypeRef) -> str { ret type_names.get(t); }
- fn name_has_type(str s) -> bool {
- ret named_types.contains_key(s);
- }
+ fn name_has_type(s: str) -> bool { ret named_types.contains_key(s); }
- fn get_type(str s) -> TypeRef {
- ret named_types.get(s);
- }
+ fn get_type(s: str) -> TypeRef { ret named_types.get(s); }
}
fn mk_type_names() -> type_names {
- auto nt = std::map::new_str_hash[TypeRef]();
+ let nt = std::map::new_str_hash[TypeRef]();
- fn hash(&TypeRef t) -> uint {
- ret t as uint;
- }
+ fn hash(t: &TypeRef) -> uint { ret t as uint; }
- fn eq(&TypeRef a, &TypeRef b) -> bool {
- ret (a as uint) == (b as uint);
- }
+ fn eq(a: &TypeRef, b: &TypeRef) -> bool { ret a as uint == b as uint; }
- let std::map::hashfn[TypeRef] hasher = hash;
- let std::map::eqfn[TypeRef] eqer = eq;
- auto tn = std::map::mk_hashmap[TypeRef,str](hasher, eqer);
+ let hasher: std::map::hashfn[TypeRef] = hash;
+ let eqer: std::map::eqfn[TypeRef] = eq;
+ let tn = std::map::mk_hashmap[TypeRef, str](hasher, eqer);
ret type_names(tn, nt);
}
-fn type_to_str(type_names names, TypeRef ty) -> str {
+fn type_to_str(names: type_names, ty: TypeRef) -> str {
ret type_to_str_inner(names, ~[], ty);
}
-fn type_to_str_inner(type_names names, &TypeRef[] outer0, TypeRef ty) -> str {
+fn type_to_str_inner(names: type_names, outer0: &TypeRef[], ty: TypeRef) ->
+ str {
- if (names.type_has_name(ty)) {
- ret names.get_name(ty);
- }
+ if names.type_has_name(ty) { ret names.get_name(ty); }
- auto outer = outer0 + ~[ty];
+ let outer = outer0 + ~[ty];
- let int kind = llvm::LLVMGetTypeKind(ty);
+ let kind: int = llvm::LLVMGetTypeKind(ty);
- fn tys_str(type_names names, &TypeRef[] outer, &TypeRef[] tys) -> str {
- let str s = "";
- let bool first = true;
- for (TypeRef t in tys) {
- if (first) {
- first = false;
- } else {
- s += ", ";
- }
+ fn tys_str(names: type_names, outer: &TypeRef[], tys: &TypeRef[]) -> str {
+ let s: str = "";
+ let first: bool = true;
+ for t: TypeRef in tys {
+ if first { first = false; } else { s += ", "; }
s += type_to_str_inner(names, outer, t);
}
ret s;
}
- alt (kind) {
- // FIXME: more enum-as-int constants determined from Core::h;
- // horrible, horrible. Complete as needed.
+ alt kind {
- case (0) { ret "Void"; }
- case (1) { ret "Float"; }
- case (2) { ret "Double"; }
- case (3) { ret "X86_FP80"; }
- case (4) { ret "FP128"; }
- case (5) { ret "PPC_FP128"; }
- case (6) { ret "Label"; }
- case (7) {
- ret "i" + std::int::str(llvm::LLVMGetIntTypeWidth(ty) as int);
- }
+ // FIXME: more enum-as-int constants determined from Core::h;
+ // horrible, horrible. Complete as needed.
- case (8) {
- auto s = "fn(";
- let TypeRef out_ty = llvm::LLVMGetReturnType(ty);
- let uint n_args = llvm::LLVMCountParamTypes(ty);
- let TypeRef[] args =
- ivec::init_elt[TypeRef](0 as TypeRef, n_args);
- llvm::LLVMGetParamTypes(ty, ivec::to_ptr(args));
- s += tys_str(names, outer, args);
- s += ") -> ";
- s += type_to_str_inner(names, outer, out_ty);
- ret s;
- }
+ 0 {
+ ret "Void";
+ }
+ 1 { ret "Float"; }
+ 2 { ret "Double"; }
+ 3 { ret "X86_FP80"; }
+ 4 { ret "FP128"; }
+ 5 { ret "PPC_FP128"; }
+ 6 { ret "Label"; }
- case (9) {
- let str s = "{";
- let uint n_elts = llvm::LLVMCountStructElementTypes(ty);
- let TypeRef[] elts =
- ivec::init_elt[TypeRef](0 as TypeRef, n_elts);
- llvm::LLVMGetStructElementTypes(ty, ivec::to_ptr(elts));
- s += tys_str(names, outer, elts);
- s += "}";
- ret s;
- }
- case (10) {
- auto el_ty = llvm::LLVMGetElementType(ty);
- ret "[" + type_to_str_inner(names, outer, el_ty) + "]";
- }
+ 7 {
+ ret "i" + std::int::str(llvm::LLVMGetIntTypeWidth(ty) as int);
+ }
- case (11) {
- let uint i = 0u;
- for (TypeRef tout in outer0) {
- i += 1u;
- if (tout as int == ty as int) {
- let uint n = ivec::len[TypeRef](outer0) - i;
- ret "*\\" + std::int::str(n as int);
- }
+
+ 8 {
+ let s = "fn(";
+ let out_ty: TypeRef = llvm::LLVMGetReturnType(ty);
+ let n_args: uint = llvm::LLVMCountParamTypes(ty);
+ let args: TypeRef[] = ivec::init_elt[TypeRef](0 as TypeRef, n_args);
+ llvm::LLVMGetParamTypes(ty, ivec::to_ptr(args));
+ s += tys_str(names, outer, args);
+ s += ") -> ";
+ s += type_to_str_inner(names, outer, out_ty);
+ ret s;
+ }
+
+
+ 9 {
+ let s: str = "{";
+ let n_elts: uint = llvm::LLVMCountStructElementTypes(ty);
+ let elts: TypeRef[] = ivec::init_elt[TypeRef](0 as TypeRef, n_elts);
+ llvm::LLVMGetStructElementTypes(ty, ivec::to_ptr(elts));
+ s += tys_str(names, outer, elts);
+ s += "}";
+ ret s;
+ }
+
+
+ 10 {
+ let el_ty = llvm::LLVMGetElementType(ty);
+ ret "[" + type_to_str_inner(names, outer, el_ty) + "]";
+ }
+
+
+ 11 {
+ let i: uint = 0u;
+ for tout: TypeRef in outer0 {
+ i += 1u;
+ if tout as int == ty as int {
+ let n: uint = ivec::len[TypeRef](outer0) - i;
+ ret "*\\" + std::int::str(n as int);
}
- ret "*" + type_to_str_inner(names, outer,
- llvm::LLVMGetElementType(ty));
}
+ ret "*" +
+ type_to_str_inner(names, outer, llvm::LLVMGetElementType(ty));
+ }
- case (12) { ret "Opaque"; }
- case (13) { ret "Vector"; }
- case (14) { ret "Metadata"; }
- case (_) {
- log_err #fmt("unknown TypeKind %d", kind as int);
- fail;
- }
+
+ 12 {
+ ret "Opaque";
+ }
+ 13 { ret "Vector"; }
+ 14 { ret "Metadata"; }
+ _ { log_err #fmt("unknown TypeKind %d", kind as int); fail; }
}
}
-fn float_width(TypeRef llt) -> uint {
+fn float_width(llt: TypeRef) -> uint {
ret alt llvm::LLVMGetTypeKind(llt) {
- 1 { 32u }
- 2 { 64u }
- 3 { 80u }
- 4 | 5 { 128u }
- _ { fail "llvm_float_width called on a non-float type" }
- };
+ 1 { 32u }
+ 2 { 64u }
+ 3 { 80u }
+ 4 | 5 { 128u }
+ _ { fail "llvm_float_width called on a non-float type" }
+ };
}
-fn fn_ty_param_tys(TypeRef fn_ty) -> TypeRef[] {
- auto args = ivec::init_elt(0 as TypeRef,
- llvm::LLVMCountParamTypes(fn_ty));
+fn fn_ty_param_tys(fn_ty: TypeRef) -> TypeRef[] {
+ let args = ivec::init_elt(0 as TypeRef, llvm::LLVMCountParamTypes(fn_ty));
llvm::LLVMGetParamTypes(fn_ty, ivec::to_ptr(args));
ret args;
}
@@ -1563,54 +1555,54 @@
/* Memory-managed interface to target data. */
-obj target_data_dtor(TargetDataRef TD) {
- drop { llvm::LLVMDisposeTargetData(TD); }
+obj target_data_dtor(TD: TargetDataRef)
+ {drop { llvm::LLVMDisposeTargetData(TD); }
}
-type target_data = rec(TargetDataRef lltd, target_data_dtor dtor);
+type target_data = {lltd: TargetDataRef, dtor: target_data_dtor};
-fn mk_target_data(str string_rep) -> target_data {
- auto lltd = llvm::LLVMCreateTargetData(str::buf(string_rep));
- ret rec(lltd=lltd, dtor=target_data_dtor(lltd));
+fn mk_target_data(string_rep: str) -> target_data {
+ let lltd = llvm::LLVMCreateTargetData(str::buf(string_rep));
+ ret {lltd: lltd, dtor: target_data_dtor(lltd)};
}
/* Memory-managed interface to pass managers. */
-obj pass_manager_dtor(PassManagerRef PM) {
- drop { llvm::LLVMDisposePassManager(PM); }
+obj pass_manager_dtor(PM: PassManagerRef)
+ {drop { llvm::LLVMDisposePassManager(PM); }
}
-type pass_manager = rec(PassManagerRef llpm, pass_manager_dtor dtor);
+type pass_manager = {llpm: PassManagerRef, dtor: pass_manager_dtor};
fn mk_pass_manager() -> pass_manager {
- auto llpm = llvm::LLVMCreatePassManager();
- ret rec(llpm=llpm, dtor=pass_manager_dtor(llpm));
+ let llpm = llvm::LLVMCreatePassManager();
+ ret {llpm: llpm, dtor: pass_manager_dtor(llpm)};
}
/* Memory-managed interface to object files. */
-obj object_file_dtor(ObjectFileRef ObjectFile) {
- drop { llvm::LLVMDisposeObjectFile(ObjectFile); }
+obj object_file_dtor(ObjectFile: ObjectFileRef)
+ {drop { llvm::LLVMDisposeObjectFile(ObjectFile); }
}
-type object_file = rec(ObjectFileRef llof, object_file_dtor dtor);
+type object_file = {llof: ObjectFileRef, dtor: object_file_dtor};
-fn mk_object_file(MemoryBufferRef llmb) -> object_file {
- auto llof = llvm::LLVMCreateObjectFile(llmb);
- ret rec(llof=llof, dtor=object_file_dtor(llof));
+fn mk_object_file(llmb: MemoryBufferRef) -> object_file {
+ let llof = llvm::LLVMCreateObjectFile(llmb);
+ ret {llof: llof, dtor: object_file_dtor(llof)};
}
/* Memory-managed interface to section iterators. */
-obj section_iter_dtor(SectionIteratorRef SI) {
- drop { llvm::LLVMDisposeSectionIterator(SI); }
+obj section_iter_dtor(SI: SectionIteratorRef)
+ {drop { llvm::LLVMDisposeSectionIterator(SI); }
}
-type section_iter = rec(SectionIteratorRef llsi, section_iter_dtor dtor);
+type section_iter = {llsi: SectionIteratorRef, dtor: section_iter_dtor};
-fn mk_section_iter(ObjectFileRef llof) -> section_iter {
- auto llsi = llvm::LLVMGetSections(llof);
- ret rec(llsi=llsi, dtor=section_iter_dtor(llsi));
+fn mk_section_iter(llof: ObjectFileRef) -> section_iter {
+ let llsi = llvm::LLVMGetSections(llof);
+ ret {llsi: llsi, dtor: section_iter_dtor(llsi)};
}
//
diff --git a/src/comp/metadata/common.rs b/src/comp/metadata/common.rs
index 58db989..e8fce2d 100644
--- a/src/comp/metadata/common.rs
+++ b/src/comp/metadata/common.rs
@@ -2,72 +2,72 @@
import std::str;
-const uint tag_paths = 0x01u;
+const tag_paths: uint = 0x01u;
-const uint tag_items = 0x02u;
+const tag_items: uint = 0x02u;
-const uint tag_paths_data = 0x03u;
+const tag_paths_data: uint = 0x03u;
-const uint tag_paths_data_name = 0x04u;
+const tag_paths_data_name: uint = 0x04u;
-const uint tag_paths_data_item = 0x05u;
+const tag_paths_data_item: uint = 0x05u;
-const uint tag_paths_data_mod = 0x06u;
+const tag_paths_data_mod: uint = 0x06u;
-const uint tag_def_id = 0x07u;
+const tag_def_id: uint = 0x07u;
-const uint tag_items_data = 0x08u;
+const tag_items_data: uint = 0x08u;
-const uint tag_items_data_item = 0x09u;
+const tag_items_data_item: uint = 0x09u;
-const uint tag_items_data_item_kind = 0x0au;
+const tag_items_data_item_kind: uint = 0x0au;
-const uint tag_items_data_item_ty_param_count = 0x0bu;
+const tag_items_data_item_ty_param_count: uint = 0x0bu;
-const uint tag_items_data_item_type = 0x0cu;
+const tag_items_data_item_type: uint = 0x0cu;
-const uint tag_items_data_item_symbol = 0x0du;
+const tag_items_data_item_symbol: uint = 0x0du;
-const uint tag_items_data_item_variant = 0x0eu;
+const tag_items_data_item_variant: uint = 0x0eu;
-const uint tag_items_data_item_tag_id = 0x0fu;
+const tag_items_data_item_tag_id: uint = 0x0fu;
-const uint tag_index = 0x11u;
+const tag_index: uint = 0x11u;
-const uint tag_index_buckets = 0x12u;
+const tag_index_buckets: uint = 0x12u;
-const uint tag_index_buckets_bucket = 0x13u;
+const tag_index_buckets_bucket: uint = 0x13u;
-const uint tag_index_buckets_bucket_elt = 0x14u;
+const tag_index_buckets_bucket_elt: uint = 0x14u;
-const uint tag_index_table = 0x15u;
+const tag_index_table: uint = 0x15u;
-const uint tag_meta_item_name_value = 0x18u;
+const tag_meta_item_name_value: uint = 0x18u;
-const uint tag_meta_item_name = 0x19u;
+const tag_meta_item_name: uint = 0x19u;
-const uint tag_meta_item_value = 0x20u;
+const tag_meta_item_value: uint = 0x20u;
-const uint tag_attributes = 0x21u;
+const tag_attributes: uint = 0x21u;
-const uint tag_attribute = 0x22u;
+const tag_attribute: uint = 0x22u;
-const uint tag_meta_item_word = 0x23u;
+const tag_meta_item_word: uint = 0x23u;
-const uint tag_meta_item_list = 0x24u;
+const tag_meta_item_list: uint = 0x24u;
// The list of crates that this crate depends on
-const uint tag_crate_deps = 0x25u;
+const tag_crate_deps: uint = 0x25u;
// A single crate dependency
-const uint tag_crate_dep = 0x26u;
+const tag_crate_dep: uint = 0x26u;
// djb's cdb hashes.
-fn hash_node_id(&int node_id) -> uint { ret 177573u ^ (node_id as uint); }
+fn hash_node_id(node_id: &int) -> uint { ret 177573u ^ (node_id as uint); }
-fn hash_path(&str s) -> uint {
- auto h = 5381u;
- for (u8 ch in str::bytes(s)) { h = (h << 5u) + h ^ (ch as uint); }
+fn hash_path(s: &str) -> uint {
+ let h = 5381u;
+ for ch: u8 in str::bytes(s) { h = (h << 5u) + h ^ (ch as uint); }
ret h;
}
diff --git a/src/comp/metadata/creader.rs b/src/comp/metadata/creader.rs
index 816294a..abbc887 100644
--- a/src/comp/metadata/creader.rs
+++ b/src/comp/metadata/creader.rs
@@ -29,83 +29,75 @@
// Traverses an AST, reading all the information about use'd crates and native
// libraries necessary for later resolving, typechecking, linking, etc.
-fn read_crates(session::session sess,
- &ast::crate crate) {
- auto e =
- @rec(sess=sess,
- crate_cache=@std::map::new_str_hash[int](),
- library_search_paths=sess.get_opts().library_search_paths,
- mutable next_crate_num=1);
- auto v = visit::mk_simple_visitor
- (@rec(visit_view_item=bind visit_view_item(e, _),
- visit_item=bind visit_item(e, _)
- with *visit::default_simple_visitor()));
+fn read_crates(sess: session::session, crate: &ast::crate) {
+ let e =
+ @{sess: sess,
+ crate_cache: @std::map::new_str_hash[int](),
+ library_search_paths: sess.get_opts().library_search_paths,
+ mutable next_crate_num: 1};
+ let v =
+ visit::mk_simple_visitor(@{visit_view_item:
+ bind visit_view_item(e, _),
+ visit_item: bind visit_item(e, _)
+ with *visit::default_simple_visitor()});
visit::visit_crate(crate, (), v);
}
type env =
- @rec(session::session sess,
- @hashmap[str, int] crate_cache,
- str[] library_search_paths,
- mutable ast::crate_num next_crate_num);
+ @{sess: session::session,
+ crate_cache: @hashmap[str, int],
+ library_search_paths: str[],
+ mutable next_crate_num: ast::crate_num};
-fn visit_view_item(env e, &@ast::view_item i) {
- alt (i.node) {
- case (ast::view_item_use(?ident, ?meta_items, ?id)) {
- auto cnum = resolve_crate(e, ident, meta_items, i.span);
- cstore::add_use_stmt_cnum(e.sess.get_cstore(), id, cnum);
- }
- case (_) { }
+fn visit_view_item(e: env, i: &@ast::view_item) {
+ alt i.node {
+ ast::view_item_use(ident, meta_items, id) {
+ let cnum = resolve_crate(e, ident, meta_items, i.span);
+ cstore::add_use_stmt_cnum(e.sess.get_cstore(), id, cnum);
+ }
+ _ { }
}
}
-fn visit_item(env e, &@ast::item i) {
- alt (i.node) {
- case (ast::item_native_mod(?m)) {
- if (m.abi != ast::native_abi_rust &&
- m.abi != ast::native_abi_cdecl) {
- ret;
- }
- auto cstore = e.sess.get_cstore();
- if (!cstore::add_used_library(cstore, m.native_name)) {
- ret;
- }
- for (ast::attribute a in
- attr::find_attrs_by_name(i.attrs, "link_args")) {
- alt (attr::get_meta_item_value_str(attr::attr_meta(a))) {
- case (some(?linkarg)) {
- cstore::add_used_link_args(cstore, linkarg);
- }
- case (none) { /* fallthrough */ }
- }
+fn visit_item(e: env, i: &@ast::item) {
+ alt i.node {
+ ast::item_native_mod(m) {
+ if m.abi != ast::native_abi_rust && m.abi != ast::native_abi_cdecl {
+ ret;
+ }
+ let cstore = e.sess.get_cstore();
+ if !cstore::add_used_library(cstore, m.native_name) { ret; }
+ for a: ast::attribute in
+ attr::find_attrs_by_name(i.attrs, "link_args") {
+ alt attr::get_meta_item_value_str(attr::attr_meta(a)) {
+ some(linkarg) { cstore::add_used_link_args(cstore, linkarg); }
+ none. {/* fallthrough */ }
}
}
- case (_) {
- }
+ }
+ _ { }
}
}
// A diagnostic function for dumping crate metadata to an output stream
-fn list_file_metadata(str path, ioivec::writer out) {
- alt (get_metadata_section(path)) {
- case (option::some(?bytes)) {
- decoder::list_crate_metadata(bytes, out);
- }
- case (option::none) {
- out.write_str("Could not find metadata in " + path + ".\n");
- }
+fn list_file_metadata(path: str, out: ioivec::writer) {
+ alt get_metadata_section(path) {
+ option::some(bytes) { decoder::list_crate_metadata(bytes, out); }
+ option::none. {
+ out.write_str("Could not find metadata in " + path + ".\n");
+ }
}
}
-fn metadata_matches(&@u8[] crate_data, &(@ast::meta_item)[] metas) -> bool {
- auto attrs = decoder::get_crate_attributes(crate_data);
- auto linkage_metas = attr::find_linkage_metas(attrs);
+fn metadata_matches(crate_data: &@u8[], metas: &(@ast::meta_item)[]) -> bool {
+ let attrs = decoder::get_crate_attributes(crate_data);
+ let linkage_metas = attr::find_linkage_metas(attrs);
log #fmt("matching %u metadata requirements against %u items",
ivec::len(metas), ivec::len(linkage_metas));
- for (@ast::meta_item needed in metas) {
- if (!attr::contains(linkage_metas, needed)) {
+ for needed: @ast::meta_item in metas {
+ if !attr::contains(linkage_metas, needed) {
log #fmt("missing %s", pprust::meta_item_to_str(*needed));
ret false;
}
@@ -113,103 +105,99 @@
ret true;
}
-fn default_native_lib_naming(session::session sess, bool static) ->
- rec(str prefix, str suffix) {
- if (static) {
- ret rec(prefix="lib", suffix=".rlib");
- }
- alt (sess.get_targ_cfg().os) {
- case (session::os_win32) { ret rec(prefix="", suffix=".dll"); }
- case (session::os_macos) { ret rec(prefix="lib", suffix=".dylib"); }
- case (session::os_linux) { ret rec(prefix="lib", suffix=".so"); }
+fn default_native_lib_naming(sess: session::session, static: bool) ->
+ {prefix: str, suffix: str} {
+ if static { ret {prefix: "lib", suffix: ".rlib"}; }
+ alt sess.get_targ_cfg().os {
+ session::os_win32. { ret {prefix: "", suffix: ".dll"}; }
+ session::os_macos. { ret {prefix: "lib", suffix: ".dylib"}; }
+ session::os_linux. { ret {prefix: "lib", suffix: ".so"}; }
}
}
-fn find_library_crate(&session::session sess, &ast::ident ident,
- &(@ast::meta_item)[] metas,
- &str[] library_search_paths)
- -> option::t[rec(str ident, @u8[] data)] {
+fn find_library_crate(sess: &session::session, ident: &ast::ident,
+ metas: &(@ast::meta_item)[],
+ library_search_paths: &str[]) ->
+ option::t[{ident: str, data: @u8[]}] {
attr::require_unique_names(sess, metas);
- auto crate_name = {
- auto name_items = attr::find_meta_items_by_name(metas, "name");
- alt (ivec::last(name_items)) {
- case (some(?i)) {
- alt (attr::get_meta_item_value_str(i)) {
- case (some(?n)) { n }
- case (_) {
- // FIXME: Probably want a warning here since the user
- // is using the wrong type of meta item
- ident
- }
+ let
+ // FIXME: Probably want a warning here since the user
+ // is using the wrong type of meta item
+ crate_name =
+ {
+ let name_items = attr::find_meta_items_by_name(metas, "name");
+ alt ivec::last(name_items) {
+ some(i) {
+ alt attr::get_meta_item_value_str(i) {
+ some(n) { n }
+ _ { ident }
}
+ }
+ none. { ident }
}
- case (none) { ident }
- }
- };
+ };
- auto nn = default_native_lib_naming(sess, sess.get_opts().static);
- auto x = find_library_crate_aux(nn, crate_name, metas,
- library_search_paths);
- if (x != none || sess.get_opts().static) {
- ret x;
- }
- auto nn2 = default_native_lib_naming(sess, true);
+ let nn = default_native_lib_naming(sess, sess.get_opts().static);
+ let x =
+ find_library_crate_aux(nn, crate_name, metas, library_search_paths);
+ if x != none || sess.get_opts().static { ret x; }
+ let nn2 = default_native_lib_naming(sess, true);
ret find_library_crate_aux(nn2, crate_name, metas, library_search_paths);
}
-fn find_library_crate_aux(&rec(str prefix, str suffix) nn, str crate_name,
- &(@ast::meta_item)[] metas,
- &str[] library_search_paths)
- -> option::t[rec(str ident, @u8[] data)] {
- let str prefix = nn.prefix + crate_name;
+fn find_library_crate_aux(nn: &{prefix: str, suffix: str}, crate_name: str,
+ metas: &(@ast::meta_item)[],
+ library_search_paths: &str[]) ->
+ option::t[{ident: str, data: @u8[]}] {
+ let prefix: str = 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
// tricks. Currently the glob(3) interface is a bit more than we can
// stomach from here, and writing a C++ wrapper is more work than just
// manually filtering fs::list_dir here.
- for (str library_search_path in library_search_paths) {
+ for library_search_path: str in library_search_paths {
log #fmt("searching %s", library_search_path);
- for (str path in fs::list_dir(library_search_path)) {
+ for path: str in fs::list_dir(library_search_path) {
log #fmt("searching %s", path);
- let str f = fs::basename(path);
- if (!(str::starts_with(f, prefix) &&
- str::ends_with(f, nn.suffix))) {
+ let f: str = fs::basename(path);
+ if !(str::starts_with(f, prefix) && str::ends_with(f, nn.suffix))
+ {
log #fmt("skipping %s, doesn't look like %s*%s", path, prefix,
nn.suffix);
cont;
}
- alt (get_metadata_section(path)) {
- case (option::some(?cvec)) {
- if (!metadata_matches(cvec, metas)) {
- log #fmt("skipping %s, metadata doesn't match", path);
- cont;
- }
- log #fmt("found %s with matching metadata", path);
- ret some(rec(ident=path, data=cvec));
+ alt get_metadata_section(path) {
+ option::some(cvec) {
+ if !metadata_matches(cvec, metas) {
+ log #fmt("skipping %s, metadata doesn't match", path);
+ cont;
}
- case (_) { }
+ log #fmt("found %s with matching metadata", path);
+ ret some({ident: path, data: cvec});
+ }
+ _ { }
}
}
}
ret none;
}
-fn get_metadata_section(str filename) -> option::t[@u8[]] {
- auto b = str::buf(filename);
- auto mb = llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(b);
- if (mb as int == 0) { ret option::none[@u8[]]; }
- auto of = mk_object_file(mb);
- auto si = mk_section_iter(of.llof);
- while (llvm::LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) == False) {
- auto name_buf = llvm::LLVMGetSectionName(si.llsi);
- auto name = str::str_from_cstr(name_buf);
- if (str::eq(name, x86::get_meta_sect_name())) {
- auto cbuf = llvm::LLVMGetSectionContents(si.llsi);
- auto csz = llvm::LLVMGetSectionSize(si.llsi);
- let *u8 cvbuf = std::unsafe::reinterpret_cast(cbuf);
+fn get_metadata_section(filename: str) -> option::t[@u8[]] {
+ let b = str::buf(filename);
+ let mb = llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(b);
+ if mb as int == 0 { ret option::none[@u8[]]; }
+ let of = mk_object_file(mb);
+ let si = mk_section_iter(of.llof);
+ while llvm::LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) == False {
+ let name_buf = llvm::LLVMGetSectionName(si.llsi);
+ let name = str::str_from_cstr(name_buf);
+ if str::eq(name, x86::get_meta_sect_name()) {
+ let cbuf = llvm::LLVMGetSectionContents(si.llsi);
+ let csz = llvm::LLVMGetSectionSize(si.llsi);
+ let cvbuf: *u8 = std::unsafe::reinterpret_cast(cbuf);
ret option::some[@u8[]](@ivec::unsafe::from_buf(cvbuf, csz));
}
llvm::LLVMMoveToNextSection(si.llsi);
@@ -217,72 +205,68 @@
ret option::none[@u8[]];
}
-fn load_library_crate(&session::session sess, span span,
- &ast::ident ident, &(@ast::meta_item)[] metas,
- &str[] library_search_paths)
- -> rec(str ident, @u8[] data) {
+fn load_library_crate(sess: &session::session, span: span, ident: &ast::ident,
+ metas: &(@ast::meta_item)[],
+ library_search_paths: &str[]) ->
+ {ident: str, data: @u8[]} {
- alt (find_library_crate(sess, ident, metas, library_search_paths)) {
- case (some(?t)) {
- ret t;
- }
- case (none) {
- sess.span_fatal(span, #fmt("can't find crate for '%s'", ident));
- }
+
+ alt find_library_crate(sess, ident, metas, library_search_paths) {
+ some(t) { ret t; }
+ none. {
+ sess.span_fatal(span, #fmt("can't find crate for '%s'", ident));
+ }
}
}
-fn resolve_crate(env e, ast::ident ident, (@ast::meta_item)[] metas,
- span span) -> ast::crate_num {
- if (!e.crate_cache.contains_key(ident)) {
- auto cinfo = load_library_crate(e.sess, span, ident, metas,
- e.library_search_paths);
+fn resolve_crate(e: env, ident: ast::ident, metas: (@ast::meta_item)[],
+ span: span) -> ast::crate_num {
+ if !e.crate_cache.contains_key(ident) {
+ let cinfo =
+ load_library_crate(e.sess, span, ident, metas,
+ e.library_search_paths);
- auto cfilename = cinfo.ident;
- auto cdata = cinfo.data;
+ let cfilename = cinfo.ident;
+ let cdata = cinfo.data;
// Claim this crate number and cache it
- auto cnum = e.next_crate_num;
+ let cnum = e.next_crate_num;
e.crate_cache.insert(ident, cnum);
e.next_crate_num += 1;
// Now resolve the crates referenced by this crate
- auto cnum_map = resolve_crate_deps(e, cdata);
+ let cnum_map = resolve_crate_deps(e, cdata);
- auto cmeta = rec(name=ident,
- data=cdata,
- cnum_map=cnum_map);
+ let cmeta = {name: ident, data: cdata, cnum_map: cnum_map};
- auto cstore = e.sess.get_cstore();
+ let cstore = e.sess.get_cstore();
cstore::set_crate_data(cstore, cnum, cmeta);
cstore::add_used_crate_file(cstore, cfilename);
ret cnum;
- } else {
- ret e.crate_cache.get(ident);
- }
+ } else { ret e.crate_cache.get(ident); }
}
// Go through the crate metadata and load any crates that it references
-fn resolve_crate_deps(env e, &@u8[] cdata) -> cstore::cnum_map {
+fn resolve_crate_deps(e: env, cdata: &@u8[]) -> cstore::cnum_map {
log "resolving deps of external crate";
// The map from crate numbers in the crate we're resolving to local crate
// 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.cnum;
- auto cname = dep.ident;
+ let cnum_map = new_int_hash[ast::crate_num]();
+ for dep: decoder::crate_dep in decoder::get_crate_deps(cdata) {
+ let extrn_cnum = dep.cnum;
+ let cname = dep.ident;
log #fmt("resolving dep %s", cname);
- if (e.crate_cache.contains_key(cname)) {
+ if e.crate_cache.contains_key(cname) {
log "already have it";
// We've already seen this crate
- auto local_cnum = e.crate_cache.get(cname);
+ let local_cnum = e.crate_cache.get(cname);
cnum_map.insert(extrn_cnum, local_cnum);
} else {
log "need to load it";
// This is a new one so we've got to load it
// FIXME: Need better error reporting than just a bogus span
- auto fake_span = rec(lo=0u,hi=0u);
- auto local_cnum = resolve_crate(e, cname, ~[], fake_span);
+ let fake_span = {lo: 0u, hi: 0u};
+ let local_cnum = resolve_crate(e, cname, ~[], fake_span);
cnum_map.insert(extrn_cnum, local_cnum);
}
}
diff --git a/src/comp/metadata/csearch.rs b/src/comp/metadata/csearch.rs
index 3519c4e..a608670 100644
--- a/src/comp/metadata/csearch.rs
+++ b/src/comp/metadata/csearch.rs
@@ -11,35 +11,35 @@
export get_tag_variants;
export get_type;
-fn get_symbol(&cstore::cstore cstore, ast::def_id def) -> str {
- auto cdata = cstore::get_crate_data(cstore, def.crate).data;
+fn get_symbol(cstore: &cstore::cstore, def: ast::def_id) -> str {
+ let 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 cdata = cstore::get_crate_data(cstore, def.crate).data;
+fn get_type_param_count(cstore: &cstore::cstore, def: &ast::def_id) -> uint {
+ let 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,
- &ast::ident[] path) -> ast::def[] {
- auto cdata = cstore::get_crate_data(cstore, cnum).data;
+fn lookup_defs(cstore: &cstore::cstore, cnum: ast::crate_num,
+ path: &ast::ident[]) -> ast::def[] {
+ let cdata = cstore::get_crate_data(cstore, cnum).data;
ret decoder::lookup_defs(cdata, cnum, path);
}
-fn get_tag_variants(ty::ctxt tcx, ast::def_id def) -> ty::variant_info[] {
- auto cstore = tcx.sess.get_cstore();
- auto cnum = def.crate;
- auto cdata = cstore::get_crate_data(cstore, cnum).data;
- auto resolver = bind translate_def_id(tcx.sess, cnum, _);
+fn get_tag_variants(tcx: ty::ctxt, def: ast::def_id) -> ty::variant_info[] {
+ let cstore = tcx.sess.get_cstore();
+ let cnum = def.crate;
+ let cdata = cstore::get_crate_data(cstore, cnum).data;
+ let resolver = bind translate_def_id(tcx.sess, cnum, _);
ret decoder::get_tag_variants(cdata, def, tcx, resolver)
}
-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.crate;
- auto cdata = cstore::get_crate_data(cstore, cnum).data;
- auto resolver = bind translate_def_id(tcx.sess, cnum, _);
+fn get_type(tcx: ty::ctxt, def: ast::def_id) -> ty::ty_param_count_and_ty {
+ let cstore = tcx.sess.get_cstore();
+ let cnum = def.crate;
+ let cdata = cstore::get_crate_data(cstore, cnum).data;
+ let resolver = bind translate_def_id(tcx.sess, cnum, _);
decoder::get_type(cdata, def, tcx, resolver)
}
@@ -48,27 +48,25 @@
// external crates - if those types further refer to types in other crates
// then we must translate the crate number from that encoded in the external
// crate to the correct local crate number.
-fn translate_def_id(&session::session sess,
- ast::crate_num searched_crate,
- &ast::def_id def_id) -> ast::def_id {
+fn translate_def_id(sess: &session::session, searched_crate: ast::crate_num,
+ def_id: &ast::def_id) -> ast::def_id {
- auto ext_cnum = def_id.crate;
- auto node_id = def_id.node;
+ let ext_cnum = def_id.crate;
+ let node_id = def_id.node;
- assert searched_crate != ast::local_crate;
- assert ext_cnum != ast::local_crate;
+ assert (searched_crate != ast::local_crate);
+ assert (ext_cnum != ast::local_crate);
- auto cstore = sess.get_cstore();
- auto cmeta = cstore::get_crate_data(cstore, searched_crate);
+ let cstore = sess.get_cstore();
+ let cmeta = cstore::get_crate_data(cstore, searched_crate);
- auto local_cnum = alt (cmeta.cnum_map.find(ext_cnum)) {
- case (option::some(?n)) { n }
- case (option::none) {
- sess.bug("didn't find a crate in the cnum_map")
- }
- };
+ let local_cnum =
+ alt cmeta.cnum_map.find(ext_cnum) {
+ option::some(n) { n }
+ option::none. { sess.bug("didn't find a crate in the cnum_map") }
+ };
- ret rec(crate=local_cnum, node=node_id);
+ ret {crate: local_cnum, node: node_id};
}
// Local Variables:
diff --git a/src/comp/metadata/cstore.rs b/src/comp/metadata/cstore.rs
index 875eeba..1b1249b 100644
--- a/src/comp/metadata/cstore.rs
+++ b/src/comp/metadata/cstore.rs
@@ -29,106 +29,102 @@
// own crate numbers.
type cnum_map = map::hashmap[ast::crate_num, ast::crate_num];
-type crate_metadata = rec(str name, @u8[] data, cnum_map cnum_map);
+type crate_metadata = {name: str, data: @u8[], cnum_map: cnum_map};
// This is a bit of an experiment at encapsulating the data in cstore. By
// keeping all the data in a non-exported tag variant, it's impossible for
// other modules to access the cstore's private data. This could also be
// achieved with an obj, but at the expense of a vtable. Not sure if this is a
// good pattern or not.
-tag cstore {
- private(cstore_private);
-}
+tag cstore { private(cstore_private); }
-type cstore_private = @rec(map::hashmap[ast::crate_num, crate_metadata] metas,
- use_crate_map use_crate_map,
- mutable str[] used_crate_files,
- mutable str[] used_libraries,
- mutable str[] used_link_args);
+type cstore_private =
+ @{metas: map::hashmap[ast::crate_num, crate_metadata],
+ use_crate_map: use_crate_map,
+ mutable used_crate_files: str[],
+ mutable used_libraries: str[],
+ mutable used_link_args: str[]};
// Map from node_id's of local use statements to crate numbers
type use_crate_map = map::hashmap[ast::node_id, ast::crate_num];
// Internal method to retrieve the data from the cstore
-fn p(&cstore cstore) -> cstore_private {
- alt (cstore) {
- case (private(?p)) { p }
- }
-}
+fn p(cstore: &cstore) -> cstore_private { alt cstore { private(p) { p } } }
fn mk_cstore() -> cstore {
- auto meta_cache = map::new_int_hash[crate_metadata]();
- auto crate_map = map::new_int_hash[ast::crate_num]();
- ret private(@rec(metas = meta_cache,
- use_crate_map = crate_map,
- mutable used_crate_files = ~[],
- mutable used_libraries = ~[],
- mutable used_link_args = ~[]));
+ let meta_cache = map::new_int_hash[crate_metadata]();
+ let crate_map = map::new_int_hash[ast::crate_num]();
+ ret private(@{metas: meta_cache,
+ use_crate_map: crate_map,
+ mutable used_crate_files: ~[],
+ mutable used_libraries: ~[],
+ mutable used_link_args: ~[]});
}
-fn get_crate_data(&cstore cstore, ast::crate_num cnum) -> crate_metadata {
+fn get_crate_data(cstore: &cstore, cnum: ast::crate_num) -> crate_metadata {
ret p(cstore).metas.get(cnum);
}
-fn set_crate_data(&cstore cstore, ast::crate_num cnum, &crate_metadata data) {
+fn set_crate_data(cstore: &cstore, cnum: ast::crate_num,
+ data: &crate_metadata) {
p(cstore).metas.insert(cnum, data);
}
-fn have_crate_data(&cstore cstore, ast::crate_num cnum) -> bool {
+fn have_crate_data(cstore: &cstore, cnum: ast::crate_num) -> bool {
ret p(cstore).metas.contains_key(cnum);
}
-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()) {
+iter iter_crate_data(cstore: &cstore) ->
+ @{key: ast::crate_num, val: crate_metadata} {
+ for each kv: @{key: ast::crate_num, val: crate_metadata} in
+ p(cstore).metas.items() {
put kv;
}
}
-fn add_used_crate_file(&cstore cstore, &str lib) {
- if (!ivec::member(lib, p(cstore).used_crate_files)) {
+fn add_used_crate_file(cstore: &cstore, lib: &str) {
+ if !ivec::member(lib, p(cstore).used_crate_files) {
p(cstore).used_crate_files += ~[lib];
}
}
-fn get_used_crate_files(&cstore cstore) -> str[] {
+fn get_used_crate_files(cstore: &cstore) -> str[] {
ret p(cstore).used_crate_files;
}
-fn add_used_library(&cstore cstore, &str lib) -> bool {
- if (lib == "") { ret false; }
+fn add_used_library(cstore: &cstore, lib: &str) -> bool {
+ if lib == "" { ret false; }
- if (ivec::member(lib, p(cstore).used_libraries)) {
- ret false;
- }
+ if ivec::member(lib, p(cstore).used_libraries) { ret false; }
p(cstore).used_libraries += ~[lib];
ret true;
}
-fn get_used_libraries(&cstore cstore) -> str[] {
+fn get_used_libraries(cstore: &cstore) -> str[] {
ret p(cstore).used_libraries;
}
-fn add_used_link_args(&cstore cstore, &str args) {
- auto used_link_args_vec = str::split(args, ' ' as u8);
+fn add_used_link_args(cstore: &cstore, args: &str) {
+ let used_link_args_vec = str::split(args, ' ' as u8);
+
// TODO: Remove this vec->ivec conversion.
- for (str ula in used_link_args_vec) {
+ for ula: str in used_link_args_vec {
p(cstore).used_link_args += ~[ula];
}
}
-fn get_used_link_args(&cstore cstore) -> str[] {
+fn get_used_link_args(cstore: &cstore) -> str[] {
ret p(cstore).used_link_args;
}
-fn add_use_stmt_cnum(&cstore cstore, ast::node_id use_id,
- ast::crate_num cnum) {
+fn add_use_stmt_cnum(cstore: &cstore, use_id: ast::node_id,
+ cnum: ast::crate_num) {
p(cstore).use_crate_map.insert(use_id, cnum);
}
-fn get_use_stmt_cnum(&cstore cstore, ast::node_id use_id) -> ast::crate_num {
+fn get_use_stmt_cnum(cstore: &cstore, use_id: ast::node_id) ->
+ ast::crate_num {
ret p(cstore).use_crate_map.get(use_id);
}
diff --git a/src/comp/metadata/decoder.rs b/src/comp/metadata/decoder.rs
index 90176a4..d7d82c1 100644
--- a/src/comp/metadata/decoder.rs
+++ b/src/comp/metadata/decoder.rs
@@ -32,364 +32,362 @@
// def_id for an item defined in another crate, somebody needs to figure out
// what crate that's in and give us a def_id that makes sense for the current
// build.
-type external_resolver = fn(&ast::def_id def_id) -> ast::def_id;
+type external_resolver = fn(&ast::def_id) -> ast::def_id ;
-fn lookup_hash(&ebmlivec::doc d, fn(&u8[]) -> bool eq_fn, uint hash) ->
- (ebmlivec::doc)[] {
- auto index = ebmlivec::get_doc(d, tag_index);
- auto table = ebmlivec::get_doc(index, tag_index_table);
- auto hash_pos = table.start + hash % 256u * 4u;
- auto pos = ebmlivec::be_uint_from_bytes(d.data, hash_pos, 4u);
- auto bucket = ebmlivec::doc_at(d.data, pos);
+fn lookup_hash(d: &ebmlivec::doc, eq_fn: fn(&u8[]) -> bool , hash: uint) ->
+ ebmlivec::doc[] {
+ let index = ebmlivec::get_doc(d, tag_index);
+ let table = ebmlivec::get_doc(index, tag_index_table);
+ let hash_pos = table.start + hash % 256u * 4u;
+ let pos = ebmlivec::be_uint_from_bytes(d.data, hash_pos, 4u);
+ let bucket = ebmlivec::doc_at(d.data, pos);
// Awkward logic because we can't ret from foreach yet
- let (ebmlivec::doc)[] result = ~[];
- auto belt = tag_index_buckets_bucket_elt;
- for each (ebmlivec::doc elt in ebmlivec::tagged_docs(bucket, belt)) {
- auto pos = ebmlivec::be_uint_from_bytes(elt.data, elt.start, 4u);
- if (eq_fn(ivec::slice[u8](*elt.data, elt.start + 4u, elt.end))) {
+ let result: ebmlivec::doc[] = ~[];
+ let belt = tag_index_buckets_bucket_elt;
+ for each elt: ebmlivec::doc in ebmlivec::tagged_docs(bucket, belt) {
+ let pos = ebmlivec::be_uint_from_bytes(elt.data, elt.start, 4u);
+ if eq_fn(ivec::slice[u8](*elt.data, elt.start + 4u, elt.end)) {
result += ~[ebmlivec::doc_at(d.data, pos)];
}
}
ret result;
}
-fn maybe_find_item(int item_id, &ebmlivec::doc items)
- -> option::t[ebmlivec::doc] {
- fn eq_item(&u8[] bytes, int item_id) -> bool {
+fn maybe_find_item(item_id: int, items: &ebmlivec::doc) ->
+ option::t[ebmlivec::doc] {
+ fn eq_item(bytes: &u8[], item_id: int) -> bool {
ret ebmlivec::be_uint_from_bytes(@bytes, 0u, 4u) as int == item_id;
}
- auto eqer = bind eq_item(_, item_id);
- auto found = lookup_hash(items, eqer, hash_node_id(item_id));
- if (ivec::len(found) == 0u) {
+ let eqer = bind eq_item(_, item_id);
+ let found = lookup_hash(items, eqer, hash_node_id(item_id));
+ if ivec::len(found) == 0u {
ret option::none[ebmlivec::doc];
} else { ret option::some[ebmlivec::doc](found.(0)); }
}
-fn find_item(int item_id, &ebmlivec::doc items) -> ebmlivec::doc {
+fn find_item(item_id: int, items: &ebmlivec::doc) -> ebmlivec::doc {
ret option::get(maybe_find_item(item_id, items));
}
// Looks up an item in the given metadata and returns an ebmlivec doc pointing
// to the item data.
-fn lookup_item(int item_id, &@u8[] data) -> ebmlivec::doc {
- auto items = ebmlivec::get_doc(ebmlivec::new_doc(data), tag_items);
+fn lookup_item(item_id: int, data: &@u8[]) -> ebmlivec::doc {
+ let items = ebmlivec::get_doc(ebmlivec::new_doc(data), tag_items);
ret find_item(item_id, items);
}
-fn item_kind(&ebmlivec::doc item) -> u8 {
- auto kind = ebmlivec::get_doc(item, tag_items_data_item_kind);
+fn item_kind(item: &ebmlivec::doc) -> u8 {
+ let kind = ebmlivec::get_doc(item, tag_items_data_item_kind);
ret ebmlivec::doc_as_uint(kind) as u8;
}
-fn item_symbol(&ebmlivec::doc item) -> str {
- auto sym = ebmlivec::get_doc(item, tag_items_data_item_symbol);
+fn item_symbol(item: &ebmlivec::doc) -> str {
+ let sym = ebmlivec::get_doc(item, tag_items_data_item_symbol);
ret str::unsafe_from_bytes_ivec(ebmlivec::doc_data(sym));
}
-fn variant_tag_id(&ebmlivec::doc d) -> ast::def_id {
- auto tagdoc = ebmlivec::get_doc(d, tag_items_data_item_tag_id);
+fn variant_tag_id(d: &ebmlivec::doc) -> ast::def_id {
+ let tagdoc = ebmlivec::get_doc(d, tag_items_data_item_tag_id);
ret parse_def_id(ebmlivec::doc_data(tagdoc));
}
-fn item_type(&ebmlivec::doc item, ast::crate_num this_cnum,
- ty::ctxt tcx, &external_resolver extres) -> ty::t {
- fn parse_external_def_id(ast::crate_num this_cnum,
- &external_resolver extres,
- str s) -> ast::def_id {
- auto buf = str::bytes_ivec(s);
- auto external_def_id = parse_def_id(buf);
+fn item_type(item: &ebmlivec::doc, this_cnum: ast::crate_num, tcx: ty::ctxt,
+ extres: &external_resolver) -> ty::t {
+ fn parse_external_def_id(this_cnum: ast::crate_num,
+ extres: &external_resolver, s: str) ->
+ ast::def_id {
+ let buf = str::bytes_ivec(s);
+ let external_def_id = parse_def_id(buf);
+
// 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.crate == ast::local_crate) {
- ret rec(crate=this_cnum, node=external_def_id.node);
- } else {
- ret extres(external_def_id);
- }
+ if external_def_id.crate == ast::local_crate {
+ ret {crate: this_cnum, node: external_def_id.node};
+ } else { ret extres(external_def_id); }
}
- auto tp = ebmlivec::get_doc(item, tag_items_data_item_type);
- auto def_parser = bind parse_external_def_id(this_cnum, extres, _);
+ let tp = ebmlivec::get_doc(item, tag_items_data_item_type);
+ let def_parser = bind parse_external_def_id(this_cnum, extres, _);
ret parse_ty_data(item.data, this_cnum, tp.start, tp.end - tp.start,
def_parser, tcx);
}
-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)) {
+fn item_ty_param_count(item: &ebmlivec::doc) -> uint {
+ let ty_param_count: uint = 0u;
+ let tp = tag_items_data_item_ty_param_count;
+ for each p: ebmlivec::doc in ebmlivec::tagged_docs(item, tp) {
ty_param_count = ebmlivec::vint_at(ebmlivec::doc_data(p), 0u).val;
}
ret ty_param_count;
}
-fn tag_variant_ids(&ebmlivec::doc item,
- ast::crate_num this_cnum) -> ast::def_id[] {
- let ast::def_id[] ids = ~[];
- 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 += ~[rec(crate=this_cnum, node=ext.node)];
+fn tag_variant_ids(item: &ebmlivec::doc, this_cnum: ast::crate_num) ->
+ ast::def_id[] {
+ let ids: ast::def_id[] = ~[];
+ let v = tag_items_data_item_variant;
+ for each p: ebmlivec::doc in ebmlivec::tagged_docs(item, v) {
+ let ext = parse_def_id(ebmlivec::doc_data(p));
+ ids += ~[{crate: this_cnum, node: ext.node}];
}
ret ids;
}
// Given a path and serialized crate metadata, returns the ID of the
// definition the path refers to.
-fn resolve_path(&ast::ident[] path, @u8[] data) -> ast::def_id[] {
- fn eq_item(&u8[] data, str s) -> bool {
+fn resolve_path(path: &ast::ident[], data: @u8[]) -> ast::def_id[] {
+ fn eq_item(data: &u8[], s: str) -> bool {
ret str::eq(str::unsafe_from_bytes_ivec(data), s);
}
- auto s = str::connect_ivec(path, "::");
- auto md = ebmlivec::new_doc(data);
- auto paths = ebmlivec::get_doc(md, tag_paths);
- auto eqer = bind eq_item(_, s);
- let ast::def_id[] result = ~[];
- for (ebmlivec::doc doc in lookup_hash(paths, eqer, hash_path(s))) {
- auto did_doc = ebmlivec::get_doc(doc, tag_def_id);
+ let s = str::connect_ivec(path, "::");
+ let md = ebmlivec::new_doc(data);
+ let paths = ebmlivec::get_doc(md, tag_paths);
+ let eqer = bind eq_item(_, s);
+ let result: ast::def_id[] = ~[];
+ for doc: ebmlivec::doc in lookup_hash(paths, eqer, hash_path(s)) {
+ let did_doc = ebmlivec::get_doc(doc, tag_def_id);
result += ~[parse_def_id(ebmlivec::doc_data(did_doc))];
}
ret result;
}
// Crate metadata queries
-fn lookup_defs(&@u8[] data, ast::crate_num cnum, &ast::ident[] path)
- -> ast::def[] {
+fn lookup_defs(data: &@u8[], cnum: ast::crate_num, path: &ast::ident[]) ->
+ ast::def[] {
ret ivec::map(bind lookup_def(cnum, data, _), resolve_path(path, data));
}
// 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_.node, data);
- auto kind_ch = item_kind(item);
- auto did = rec(crate=cnum, node=did_.node);
- auto def =
- alt (kind_ch as char) {
- case ('c') { ast::def_const(did) }
- case ('f') { ast::def_fn(did, ast::impure_fn) }
- case ('p') { ast::def_fn(did, ast::pure_fn) }
- case ('F') { ast::def_native_fn(did) }
- case ('y') { ast::def_ty(did) }
- case ('T') { ast::def_native_ty(did) }
- // We treat references to tags as references to types.
- case ('t') { ast::def_ty(did) }
- case ('m') { ast::def_mod(did) }
- case ('n') { ast::def_native_mod(did) }
- case ('v') {
- auto tid = variant_tag_id(item);
- tid = rec(crate=cnum, node=tid.node);
- ast::def_variant(tid, did)
- }
+fn lookup_def(cnum: ast::crate_num, data: @u8[], did_: &ast::def_id) ->
+ ast::def {
+ let item = lookup_item(did_.node, data);
+ let kind_ch = item_kind(item);
+ let did = {crate: cnum, node: did_.node};
+ let
+ // We treat references to tags as references to types.
+ def =
+ alt kind_ch as char {
+ 'c' { ast::def_const(did) }
+ 'f' { ast::def_fn(did, ast::impure_fn) }
+ 'p' { ast::def_fn(did, ast::pure_fn) }
+ 'F' { ast::def_native_fn(did) }
+ 'y' { ast::def_ty(did) }
+ 'T' { ast::def_native_ty(did) }
+ 't' { ast::def_ty(did) }
+ 'm' { ast::def_mod(did) }
+ 'n' { ast::def_native_mod(did) }
+ 'v' {
+ let tid = variant_tag_id(item);
+ tid = {crate: cnum, node: tid.node};
+ ast::def_variant(tid, did)
+ }
};
ret def;
}
-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.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;
- auto kind_ch = item_kind(item);
- auto has_ty_params = kind_has_type_params(kind_ch);
- if (has_ty_params) {
+fn get_type(data: @u8[], def: ast::def_id, tcx: &ty::ctxt,
+ extres: &external_resolver) -> ty::ty_param_count_and_ty {
+ let this_cnum = def.crate;
+ let node_id = def.node;
+ let item = lookup_item(node_id, data);
+ let t = item_type(item, this_cnum, tcx, extres);
+ let tp_count;
+ let kind_ch = item_kind(item);
+ let has_ty_params = kind_has_type_params(kind_ch);
+ if has_ty_params {
tp_count = item_ty_param_count(item);
} else { tp_count = 0u; }
- ret rec(count=tp_count, ty=t);
+ ret {count: tp_count, ty: t};
}
-fn get_type_param_count(@u8[] data, ast::node_id id) -> uint {
+fn get_type_param_count(data: @u8[], id: ast::node_id) -> uint {
ret item_ty_param_count(lookup_item(id, data));
}
-fn get_symbol(@u8[] data, ast::node_id id) -> str {
+fn get_symbol(data: @u8[], id: ast::node_id) -> str {
ret item_symbol(lookup_item(id, data));
}
-fn get_tag_variants(&@u8[] data, ast::def_id def,
- &ty::ctxt tcx,
- &external_resolver extres) -> ty::variant_info[] {
- 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.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.node, items);
- auto ctor_ty = item_type(item, external_crate_id, tcx, extres);
- let ty::t[] arg_tys = ~[];
- alt (ty::struct(tcx, ctor_ty)) {
- case (ty::ty_fn(_, ?args, _, _, _)) {
- for (ty::arg a in args) { arg_tys += ~[a.ty]; }
- }
- case (_) {
- // Nullary tag variant.
+fn get_tag_variants(data: &@u8[], def: ast::def_id, tcx: &ty::ctxt,
+ extres: &external_resolver) -> ty::variant_info[] {
+ let external_crate_id = def.crate;
+ let data =
+ cstore::get_crate_data(tcx.sess.get_cstore(), external_crate_id).data;
+ let items = ebmlivec::get_doc(ebmlivec::new_doc(data), tag_items);
+ let item = find_item(def.node, items);
+ let infos: ty::variant_info[] = ~[];
+ let variant_ids = tag_variant_ids(item, external_crate_id);
+ for did: ast::def_id in variant_ids {
+ let item = find_item(did.node, items);
+ let ctor_ty = item_type(item, external_crate_id, tcx, extres);
+ let arg_tys: ty::t[] = ~[];
+ alt ty::struct(tcx, ctor_ty) {
+ ty::ty_fn(_, args, _, _, _) {
+ for a: ty::arg in args { arg_tys += ~[a.ty]; }
+ }
+ _ {
+ // Nullary tag variant.
- }
+ }
}
- infos += ~[rec(args=arg_tys, ctor_ty=ctor_ty, id=did)];
+ infos += ~[{args: arg_tys, ctor_ty: ctor_ty, id: did}];
}
ret infos;
}
-fn kind_has_type_params(u8 kind_ch) -> bool {
- ret alt (kind_ch as char) {
- case ('c') { false }
- case ('f') { true }
- case ('p') { true }
- case ('F') { true }
- case ('y') { true }
- case ('t') { true }
- case ('T') { false }
- case ('m') { false }
- case ('n') { false }
- case ('v') { true }
+fn kind_has_type_params(kind_ch: u8) -> bool {
+ ret alt kind_ch as char {
+ 'c' { false }
+ 'f' { true }
+ 'p' { true }
+ 'F' { true }
+ 'y' { true }
+ 't' { true }
+ 'T' { false }
+ 'm' { false }
+ 'n' { false }
+ 'v' { true }
};
}
-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 rec(path=path, pos=pos);
+fn read_path(d: &ebmlivec::doc) -> {path: str, pos: uint} {
+ let desc = ebmlivec::doc_data(d);
+ let pos = ebmlivec::be_uint_from_bytes(@desc, 0u, 4u);
+ let pathbytes = ivec::slice[u8](desc, 4u, ivec::len[u8](desc));
+ let path = str::unsafe_from_bytes_ivec(pathbytes);
+ ret {path: path, pos: pos};
}
-fn describe_def(&ebmlivec::doc items, ast::def_id id) -> str {
- if (id.crate != ast::local_crate) { ret "external"; }
+fn describe_def(items: &ebmlivec::doc, id: ast::def_id) -> str {
+ 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 {
- alt (kind as char) {
- case ('c') { ret "const"; }
- case ('f') { ret "fn"; }
- case ('p') { ret "pred"; }
- case ('F') { ret "native fn"; }
- case ('y') { ret "type"; }
- case ('T') { ret "native type"; }
- case ('t') { ret "type"; }
- case ('m') { ret "mod"; }
- case ('n') { ret "native mod"; }
- case ('v') { ret "tag"; }
+fn item_kind_to_str(kind: u8) -> str {
+ alt kind as char {
+ 'c' { ret "const"; }
+ 'f' { ret "fn"; }
+ 'p' { ret "pred"; }
+ 'F' { ret "native fn"; }
+ 'y' { ret "type"; }
+ 'T' { ret "native type"; }
+ 't' { ret "type"; }
+ 'm' { ret "mod"; }
+ 'n' { ret "native mod"; }
+ 'v' { ret "tag"; }
}
}
-fn get_meta_items(&ebmlivec::doc md) -> (@ast::meta_item)[] {
- let (@ast::meta_item)[] items = ~[];
- for each (ebmlivec::doc meta_item_doc in
- ebmlivec::tagged_docs(md, tag_meta_item_word)) {
- auto nd = ebmlivec::get_doc(meta_item_doc, tag_meta_item_name);
- auto n = str::unsafe_from_bytes_ivec(ebmlivec::doc_data(nd));
+fn get_meta_items(md: &ebmlivec::doc) -> (@ast::meta_item)[] {
+ let items: (@ast::meta_item)[] = ~[];
+ for each meta_item_doc: ebmlivec::doc in
+ ebmlivec::tagged_docs(md, tag_meta_item_word) {
+ let nd = ebmlivec::get_doc(meta_item_doc, tag_meta_item_name);
+ let n = str::unsafe_from_bytes_ivec(ebmlivec::doc_data(nd));
items += ~[attr::mk_word_item(n)];
}
- for each (ebmlivec::doc meta_item_doc in
- ebmlivec::tagged_docs(md, tag_meta_item_name_value)) {
- auto nd = ebmlivec::get_doc(meta_item_doc, tag_meta_item_name);
- auto vd = ebmlivec::get_doc(meta_item_doc, tag_meta_item_value);
- auto n = str::unsafe_from_bytes_ivec(ebmlivec::doc_data(nd));
- auto v = str::unsafe_from_bytes_ivec(ebmlivec::doc_data(vd));
+ for each meta_item_doc: ebmlivec::doc in
+ ebmlivec::tagged_docs(md, tag_meta_item_name_value) {
+ let nd = ebmlivec::get_doc(meta_item_doc, tag_meta_item_name);
+ let vd = ebmlivec::get_doc(meta_item_doc, tag_meta_item_value);
+ let n = str::unsafe_from_bytes_ivec(ebmlivec::doc_data(nd));
+ let v = str::unsafe_from_bytes_ivec(ebmlivec::doc_data(vd));
// FIXME (#611): Should be able to decode meta_name_value variants,
// but currently they can't be encoded
items += ~[attr::mk_name_value_item_str(n, v)];
}
- for each (ebmlivec::doc meta_item_doc in
- ebmlivec::tagged_docs(md, tag_meta_item_list)) {
- auto nd = ebmlivec::get_doc(meta_item_doc, tag_meta_item_name);
- auto n = str::unsafe_from_bytes_ivec(ebmlivec::doc_data(nd));
- auto subitems = get_meta_items(meta_item_doc);
+ for each meta_item_doc: ebmlivec::doc in
+ ebmlivec::tagged_docs(md, tag_meta_item_list) {
+ let nd = ebmlivec::get_doc(meta_item_doc, tag_meta_item_name);
+ let n = str::unsafe_from_bytes_ivec(ebmlivec::doc_data(nd));
+ let subitems = get_meta_items(meta_item_doc);
items += ~[attr::mk_list_item(n, subitems)];
}
ret items;
}
-fn get_attributes(&ebmlivec::doc md) -> ast::attribute[] {
- let ast::attribute[] attrs = ~[];
- alt (ebmlivec::maybe_get_doc(md, tag_attributes)) {
- case (option::some(?attrs_d)) {
- for each (ebmlivec::doc attr_doc in
- ebmlivec::tagged_docs(attrs_d, tag_attribute)) {
- auto meta_items = get_meta_items(attr_doc);
- // Currently it's only possible to have a single meta item on
- // an attribute
- assert (ivec::len(meta_items) == 1u);
- auto meta_item = meta_items.(0);
- attrs += ~[rec(node=rec(style=ast::attr_outer,
- value=*meta_item),
- span=rec(lo=0u, hi=0u))];
- }
+fn get_attributes(md: &ebmlivec::doc) -> ast::attribute[] {
+ let attrs: ast::attribute[] = ~[];
+ alt ebmlivec::maybe_get_doc(md, tag_attributes) {
+ option::some(attrs_d) {
+ for each attr_doc: ebmlivec::doc in
+ ebmlivec::tagged_docs(attrs_d, tag_attribute) {
+ let meta_items = get_meta_items(attr_doc);
+ // Currently it's only possible to have a single meta item on
+ // an attribute
+ assert (ivec::len(meta_items) == 1u);
+ let meta_item = meta_items.(0);
+ attrs +=
+ ~[{node: {style: ast::attr_outer, value: *meta_item},
+ span: {lo: 0u, hi: 0u}}];
}
- case (option::none) { }
+ }
+ option::none. { }
}
ret attrs;
}
-fn list_meta_items(&ebmlivec::doc meta_items, ioivec::writer out) {
- for (@ast::meta_item mi in get_meta_items(meta_items)) {
+fn list_meta_items(meta_items: &ebmlivec::doc, out: ioivec::writer) {
+ for mi: @ast::meta_item in get_meta_items(meta_items) {
out.write_str(#fmt("%s\n", pprust::meta_item_to_str(*mi)));
}
}
-fn list_crate_attributes(&ebmlivec::doc md, ioivec::writer out) {
+fn list_crate_attributes(md: &ebmlivec::doc, out: ioivec::writer) {
out.write_str("=Crate Attributes=\n");
- for (ast::attribute attr in get_attributes(md)) {
+ for attr: ast::attribute in get_attributes(md) {
out.write_str(#fmt("%s\n", pprust::attribute_to_str(attr)));
}
out.write_str("\n\n");
}
-fn get_crate_attributes(@u8[] data) -> ast::attribute[] {
+fn get_crate_attributes(data: @u8[]) -> ast::attribute[] {
ret get_attributes(ebmlivec::new_doc(data));
}
-type crate_dep = rec(ast::crate_num cnum, str ident);
+type crate_dep = {cnum: ast::crate_num, ident: str};
-fn get_crate_deps(@u8[] data) -> crate_dep[] {
- let crate_dep[] deps = ~[];
- auto cratedoc = ebmlivec::new_doc(data);
- auto depsdoc = ebmlivec::get_doc(cratedoc, tag_crate_deps);
- auto crate_num = 1;
- for each (ebmlivec::doc depdoc in
- ebmlivec::tagged_docs(depsdoc, tag_crate_dep)) {
- auto depname =
- str::unsafe_from_bytes_ivec(ebmlivec::doc_data(depdoc));
- deps += ~[rec(cnum=crate_num, ident=depname)];
+fn get_crate_deps(data: @u8[]) -> crate_dep[] {
+ let deps: crate_dep[] = ~[];
+ let cratedoc = ebmlivec::new_doc(data);
+ let depsdoc = ebmlivec::get_doc(cratedoc, tag_crate_deps);
+ let crate_num = 1;
+ for each depdoc: ebmlivec::doc in
+ ebmlivec::tagged_docs(depsdoc, tag_crate_dep) {
+ let depname = str::unsafe_from_bytes_ivec(ebmlivec::doc_data(depdoc));
+ deps += ~[{cnum: crate_num, ident: depname}];
crate_num += 1;
}
ret deps;
}
-fn list_crate_deps(@u8[] data, ioivec::writer out) {
+fn list_crate_deps(data: @u8[], out: ioivec::writer) {
out.write_str("=External Dependencies=\n");
- for (crate_dep dep in get_crate_deps(data)) {
+ for dep: crate_dep in get_crate_deps(data) {
out.write_str(#fmt("%d %s\n", dep.cnum, dep.ident));
}
out.write_str("\n");
}
-fn list_crate_items(&@u8[] bytes, &ebmlivec::doc md, ioivec::writer out) {
+fn list_crate_items(bytes: &@u8[], md: &ebmlivec::doc, out: ioivec::writer) {
out.write_str("=Items=\n");
- auto paths = ebmlivec::get_doc(md, tag_paths);
- auto items = ebmlivec::get_doc(md, tag_items);
- auto index = ebmlivec::get_doc(paths, tag_index);
- auto bs = ebmlivec::get_doc(index, tag_index_buckets);
- for each (ebmlivec::doc bucket in
- ebmlivec::tagged_docs(bs, tag_index_buckets_bucket)) {
- 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.pos);
- auto did_doc = ebmlivec::get_doc(def, tag_def_id);
- auto did = parse_def_id(ebmlivec::doc_data(did_doc));
+ let paths = ebmlivec::get_doc(md, tag_paths);
+ let items = ebmlivec::get_doc(md, tag_items);
+ let index = ebmlivec::get_doc(paths, tag_index);
+ let bs = ebmlivec::get_doc(index, tag_index_buckets);
+ for each bucket: ebmlivec::doc in
+ ebmlivec::tagged_docs(bs, tag_index_buckets_bucket) {
+ let et = tag_index_buckets_bucket_elt;
+ for each elt: ebmlivec::doc in ebmlivec::tagged_docs(bucket, et) {
+ let data = read_path(elt);
+ let def = ebmlivec::doc_at(bytes, data.pos);
+ let did_doc = ebmlivec::get_doc(def, tag_def_id);
+ let did = parse_def_id(ebmlivec::doc_data(did_doc));
out.write_str(#fmt("%s (%s)\n", data.path,
describe_def(items, did)));
}
@@ -397,8 +395,8 @@
out.write_str("\n");
}
-fn list_crate_metadata(&@u8[] bytes, ioivec::writer out) {
- auto md = ebmlivec::new_doc(bytes);
+fn list_crate_metadata(bytes: &@u8[], out: ioivec::writer) {
+ let md = ebmlivec::new_doc(bytes);
list_crate_attributes(md, out);
list_crate_deps(bytes, out);
list_crate_items(bytes, md, out);
diff --git a/src/comp/metadata/encoder.rs b/src/comp/metadata/encoder.rs
index 042ec6a..f6ad31a 100644
--- a/src/comp/metadata/encoder.rs
+++ b/src/comp/metadata/encoder.rs
@@ -21,28 +21,26 @@
type abbrev_map = map::hashmap[ty::t, tyencode::ty_abbrev];
-type encode_ctxt = rec(@crate_ctxt ccx,
- abbrev_map type_abbrevs);
+type encode_ctxt = {ccx: @crate_ctxt, type_abbrevs: abbrev_map};
// Path table encoding
-fn encode_name(&ebmlivec::writer ebml_w, &str name) {
+fn encode_name(ebml_w: &ebmlivec::writer, name: &str) {
ebmlivec::start_tag(ebml_w, tag_paths_data_name);
ebml_w.writer.write(str::bytes_ivec(name));
ebmlivec::end_tag(ebml_w);
}
-fn encode_def_id(&ebmlivec::writer ebml_w, &def_id id) {
+fn encode_def_id(ebml_w: &ebmlivec::writer, id: &def_id) {
ebmlivec::start_tag(ebml_w, tag_def_id);
ebml_w.writer.write(str::bytes_ivec(def_to_str(id)));
ebmlivec::end_tag(ebml_w);
}
-type entry[T] = rec(T val, uint pos);
+type entry[T] = {val: T, pos: uint};
-fn encode_tag_variant_paths(&ebmlivec::writer ebml_w, &variant[] variants,
- &str[] path,
- &mutable (entry[str])[] index) {
- for (variant variant in variants) {
+fn encode_tag_variant_paths(ebml_w: &ebmlivec::writer, variants: &variant[],
+ path: &str[], index: &mutable (entry[str])[]) {
+ for variant: variant in variants {
add_to_index(ebml_w, path, index, variant.node.name);
ebmlivec::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, variant.node.name);
@@ -51,17 +49,18 @@
}
}
-fn add_to_index(&ebmlivec::writer ebml_w, &str[] path,
- &mutable (entry[str])[] index, &str name) {
- auto full_path = path + ~[name];
- index += ~[rec(val=str::connect_ivec(full_path, "::"),
- pos=ebml_w.writer.tell())];
+fn add_to_index(ebml_w: &ebmlivec::writer, path: &str[],
+ index: &mutable (entry[str])[], name: &str) {
+ let full_path = path + ~[name];
+ index +=
+ ~[{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 (entry[str])[] index) {
- for (@native_item nitem in nmod.items) {
+fn encode_native_module_item_paths(ebml_w: &ebmlivec::writer,
+ nmod: &native_mod, path: &str[],
+ index: &mutable (entry[str])[]) {
+ for nitem: @native_item in nmod.items {
add_to_index(ebml_w, path, index, nitem.ident);
ebmlivec::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, nitem.ident);
@@ -70,91 +69,89 @@
}
}
-fn encode_module_item_paths(&ebmlivec::writer ebml_w, &_mod module,
- &str[] path,
- &mutable (entry[str])[] index) {
- for (@item it in module.items) {
- if (!is_exported(it.ident, module)) { cont; }
- alt (it.node) {
- case (item_const(_, _)) {
- add_to_index(ebml_w, path, index, it.ident);
- ebmlivec::start_tag(ebml_w, tag_paths_data_item);
- encode_name(ebml_w, it.ident);
- encode_def_id(ebml_w, local_def(it.id));
- ebmlivec::end_tag(ebml_w);
- }
- case (item_fn(_, ?tps)) {
- add_to_index(ebml_w, path, index, it.ident);
- ebmlivec::start_tag(ebml_w, tag_paths_data_item);
- encode_name(ebml_w, it.ident);
- encode_def_id(ebml_w, local_def(it.id));
- ebmlivec::end_tag(ebml_w);
- }
- case (item_mod(?_mod)) {
- add_to_index(ebml_w, path, index, it.ident);
- ebmlivec::start_tag(ebml_w, tag_paths_data_mod);
- encode_name(ebml_w, it.ident);
- encode_def_id(ebml_w, local_def(it.id));
- encode_module_item_paths(ebml_w, _mod, path + ~[it.ident],
- index);
- ebmlivec::end_tag(ebml_w);
- }
- case (item_native_mod(?nmod)) {
- add_to_index(ebml_w, path, index, it.ident);
- ebmlivec::start_tag(ebml_w, tag_paths_data_mod);
- encode_name(ebml_w, it.ident);
- encode_def_id(ebml_w, local_def(it.id));
- encode_native_module_item_paths(ebml_w, nmod,
- path + ~[it.ident], index);
- ebmlivec::end_tag(ebml_w);
- }
- case (item_ty(_, ?tps)) {
- add_to_index(ebml_w, path, index, it.ident);
- ebmlivec::start_tag(ebml_w, tag_paths_data_item);
- encode_name(ebml_w, it.ident);
- encode_def_id(ebml_w, local_def(it.id));
- ebmlivec::end_tag(ebml_w);
- }
- case (item_res(_, _, ?tps, ?ctor_id)) {
- add_to_index(ebml_w, path, index, it.ident);
- ebmlivec::start_tag(ebml_w, tag_paths_data_item);
- encode_name(ebml_w, it.ident);
- encode_def_id(ebml_w, local_def(ctor_id));
- ebmlivec::end_tag(ebml_w);
- add_to_index(ebml_w, path, index, it.ident);
- ebmlivec::start_tag(ebml_w, tag_paths_data_item);
- encode_name(ebml_w, it.ident);
- encode_def_id(ebml_w, local_def(it.id));
- ebmlivec::end_tag(ebml_w);
- }
- case (item_tag(?variants, ?tps)) {
- add_to_index(ebml_w, path, index, it.ident);
- ebmlivec::start_tag(ebml_w, tag_paths_data_item);
- encode_name(ebml_w, it.ident);
- encode_def_id(ebml_w, local_def(it.id));
- ebmlivec::end_tag(ebml_w);
- encode_tag_variant_paths(ebml_w, variants, path, index);
- }
- case (item_obj(_, ?tps, ?ctor_id)) {
- add_to_index(ebml_w, path, index, it.ident);
- ebmlivec::start_tag(ebml_w, tag_paths_data_item);
- encode_name(ebml_w, it.ident);
- encode_def_id(ebml_w, local_def(ctor_id));
- ebmlivec::end_tag(ebml_w);
- add_to_index(ebml_w, path, index, it.ident);
- ebmlivec::start_tag(ebml_w, tag_paths_data_item);
- encode_name(ebml_w, it.ident);
- encode_def_id(ebml_w, local_def(it.id));
- ebmlivec::end_tag(ebml_w);
- }
+fn encode_module_item_paths(ebml_w: &ebmlivec::writer, module: &_mod,
+ path: &str[], index: &mutable (entry[str])[]) {
+ for it: @item in module.items {
+ if !is_exported(it.ident, module) { cont; }
+ alt it.node {
+ item_const(_, _) {
+ add_to_index(ebml_w, path, index, it.ident);
+ ebmlivec::start_tag(ebml_w, tag_paths_data_item);
+ encode_name(ebml_w, it.ident);
+ encode_def_id(ebml_w, local_def(it.id));
+ ebmlivec::end_tag(ebml_w);
+ }
+ item_fn(_, tps) {
+ add_to_index(ebml_w, path, index, it.ident);
+ ebmlivec::start_tag(ebml_w, tag_paths_data_item);
+ encode_name(ebml_w, it.ident);
+ encode_def_id(ebml_w, local_def(it.id));
+ ebmlivec::end_tag(ebml_w);
+ }
+ item_mod(_mod) {
+ add_to_index(ebml_w, path, index, it.ident);
+ ebmlivec::start_tag(ebml_w, tag_paths_data_mod);
+ encode_name(ebml_w, it.ident);
+ encode_def_id(ebml_w, local_def(it.id));
+ encode_module_item_paths(ebml_w, _mod, path + ~[it.ident], index);
+ ebmlivec::end_tag(ebml_w);
+ }
+ item_native_mod(nmod) {
+ add_to_index(ebml_w, path, index, it.ident);
+ ebmlivec::start_tag(ebml_w, tag_paths_data_mod);
+ encode_name(ebml_w, it.ident);
+ encode_def_id(ebml_w, local_def(it.id));
+ encode_native_module_item_paths(ebml_w, nmod, path + ~[it.ident],
+ index);
+ ebmlivec::end_tag(ebml_w);
+ }
+ item_ty(_, tps) {
+ add_to_index(ebml_w, path, index, it.ident);
+ ebmlivec::start_tag(ebml_w, tag_paths_data_item);
+ encode_name(ebml_w, it.ident);
+ encode_def_id(ebml_w, local_def(it.id));
+ ebmlivec::end_tag(ebml_w);
+ }
+ item_res(_, _, tps, ctor_id) {
+ add_to_index(ebml_w, path, index, it.ident);
+ ebmlivec::start_tag(ebml_w, tag_paths_data_item);
+ encode_name(ebml_w, it.ident);
+ encode_def_id(ebml_w, local_def(ctor_id));
+ ebmlivec::end_tag(ebml_w);
+ add_to_index(ebml_w, path, index, it.ident);
+ ebmlivec::start_tag(ebml_w, tag_paths_data_item);
+ encode_name(ebml_w, it.ident);
+ encode_def_id(ebml_w, local_def(it.id));
+ ebmlivec::end_tag(ebml_w);
+ }
+ item_tag(variants, tps) {
+ add_to_index(ebml_w, path, index, it.ident);
+ ebmlivec::start_tag(ebml_w, tag_paths_data_item);
+ encode_name(ebml_w, it.ident);
+ encode_def_id(ebml_w, local_def(it.id));
+ ebmlivec::end_tag(ebml_w);
+ encode_tag_variant_paths(ebml_w, variants, path, index);
+ }
+ item_obj(_, tps, ctor_id) {
+ add_to_index(ebml_w, path, index, it.ident);
+ ebmlivec::start_tag(ebml_w, tag_paths_data_item);
+ encode_name(ebml_w, it.ident);
+ encode_def_id(ebml_w, local_def(ctor_id));
+ ebmlivec::end_tag(ebml_w);
+ add_to_index(ebml_w, path, index, it.ident);
+ ebmlivec::start_tag(ebml_w, tag_paths_data_item);
+ encode_name(ebml_w, it.ident);
+ encode_def_id(ebml_w, local_def(it.id));
+ ebmlivec::end_tag(ebml_w);
+ }
}
}
}
-fn encode_item_paths(&ebmlivec::writer ebml_w, &@crate crate)
- -> (entry[str])[] {
- let (entry[str])[] index = ~[];
- let str[] path = ~[];
+fn encode_item_paths(ebml_w: &ebmlivec::writer, crate: &@crate) ->
+ (entry[str])[] {
+ let index: (entry[str])[] = ~[];
+ let path: str[] = ~[];
ebmlivec::start_tag(ebml_w, tag_paths);
encode_module_item_paths(ebml_w, crate.node.module, path, index);
ebmlivec::end_tag(ebml_w);
@@ -163,69 +160,69 @@
// Item info table encoding
-fn encode_kind(&ebmlivec::writer ebml_w, u8 c) {
+fn encode_kind(ebml_w: &ebmlivec::writer, c: u8) {
ebmlivec::start_tag(ebml_w, tag_items_data_item_kind);
ebml_w.writer.write(~[c]);
ebmlivec::end_tag(ebml_w);
}
-fn def_to_str(&def_id did) -> str { ret #fmt("%d:%d", did.crate, did.node); }
+fn def_to_str(did: &def_id) -> str { ret #fmt("%d:%d", did.crate, did.node); }
-fn encode_type_param_count(&ebmlivec::writer ebml_w, &ty_param[] tps) {
+fn encode_type_param_count(ebml_w: &ebmlivec::writer, tps: &ty_param[]) {
ebmlivec::start_tag(ebml_w, tag_items_data_item_ty_param_count);
ebmlivec::write_vint(ebml_w.writer, ivec::len[ty_param](tps));
ebmlivec::end_tag(ebml_w);
}
-fn encode_variant_id(&ebmlivec::writer ebml_w, &def_id vid) {
+fn encode_variant_id(ebml_w: &ebmlivec::writer, vid: &def_id) {
ebmlivec::start_tag(ebml_w, tag_items_data_item_variant);
ebml_w.writer.write(str::bytes_ivec(def_to_str(vid)));
ebmlivec::end_tag(ebml_w);
}
-fn encode_type(&@encode_ctxt ecx, &ebmlivec::writer ebml_w, &ty::t typ) {
+fn encode_type(ecx: &@encode_ctxt, ebml_w: &ebmlivec::writer, typ: &ty::t) {
ebmlivec::start_tag(ebml_w, tag_items_data_item_type);
- auto f = def_to_str;
- auto ty_str_ctxt =
- @rec(ds=f, tcx=ecx.ccx.tcx,
- abbrevs=tyencode::ac_use_abbrevs(ecx.type_abbrevs));
+ let f = def_to_str;
+ let ty_str_ctxt =
+ @{ds: f,
+ tcx: ecx.ccx.tcx,
+ abbrevs: tyencode::ac_use_abbrevs(ecx.type_abbrevs)};
tyencode::enc_ty(ioivec::new_writer_(ebml_w.writer), ty_str_ctxt, typ);
ebmlivec::end_tag(ebml_w);
}
-fn encode_symbol(&@encode_ctxt ecx, &ebmlivec::writer ebml_w,
- node_id id) {
+fn encode_symbol(ecx: &@encode_ctxt, ebml_w: &ebmlivec::writer, id: node_id) {
ebmlivec::start_tag(ebml_w, tag_items_data_item_symbol);
ebml_w.writer.write(str::bytes_ivec(ecx.ccx.item_symbols.get(id)));
ebmlivec::end_tag(ebml_w);
}
-fn encode_discriminant(&@encode_ctxt ecx, &ebmlivec::writer ebml_w,
- node_id id) {
+fn encode_discriminant(ecx: &@encode_ctxt, ebml_w: &ebmlivec::writer,
+ id: node_id) {
ebmlivec::start_tag(ebml_w, tag_items_data_item_symbol);
ebml_w.writer.write(str::bytes_ivec(ecx.ccx.discrim_symbols.get(id)));
ebmlivec::end_tag(ebml_w);
}
-fn encode_tag_id(&ebmlivec::writer ebml_w, &def_id id) {
+fn encode_tag_id(ebml_w: &ebmlivec::writer, id: &def_id) {
ebmlivec::start_tag(ebml_w, tag_items_data_item_tag_id);
ebml_w.writer.write(str::bytes_ivec(def_to_str(id)));
ebmlivec::end_tag(ebml_w);
}
-fn encode_tag_variant_info(&@encode_ctxt ecx, &ebmlivec::writer ebml_w,
- node_id id, &variant[] variants,
- &mutable (entry[int])[] index,
- &ty_param[] ty_params) {
- for (variant variant in variants) {
- index += ~[rec(val=variant.node.id, pos=ebml_w.writer.tell())];
+fn encode_tag_variant_info(ecx: &@encode_ctxt, ebml_w: &ebmlivec::writer,
+ id: node_id, variants: &variant[],
+ index: &mutable (entry[int])[],
+ ty_params: &ty_param[]) {
+ for variant: variant in variants {
+ index += ~[{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);
encode_tag_id(ebml_w, local_def(id));
encode_type(ecx, ebml_w,
node_id_to_monotype(ecx.ccx.tcx, variant.node.id));
- if (ivec::len[variant_arg](variant.node.args) > 0u) {
+ if ivec::len[variant_arg](variant.node.args) > 0u {
encode_symbol(ecx, ebml_w, variant.node.id);
}
encode_discriminant(ecx, ebml_w, variant.node.id);
@@ -234,145 +231,139 @@
}
}
-fn encode_info_for_item(@encode_ctxt ecx, &ebmlivec::writer ebml_w,
- @item item, &mutable (entry[int])[] index) {
- alt (item.node) {
- case (item_const(_, _)) {
- ebmlivec::start_tag(ebml_w, tag_items_data_item);
- encode_def_id(ebml_w, local_def(item.id));
- encode_kind(ebml_w, 'c' as u8);
- encode_type(ecx, ebml_w,
- node_id_to_monotype(ecx.ccx.tcx, item.id));
- encode_symbol(ecx, ebml_w, item.id);
- ebmlivec::end_tag(ebml_w);
+fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: &ebmlivec::writer,
+ item: @item, index: &mutable (entry[int])[]) {
+ alt item.node {
+ item_const(_, _) {
+ ebmlivec::start_tag(ebml_w, tag_items_data_item);
+ encode_def_id(ebml_w, local_def(item.id));
+ encode_kind(ebml_w, 'c' as u8);
+ encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
+ encode_symbol(ecx, ebml_w, item.id);
+ ebmlivec::end_tag(ebml_w);
+ }
+ item_fn(fd, tps) {
+ ebmlivec::start_tag(ebml_w, tag_items_data_item);
+ encode_def_id(ebml_w, local_def(item.id));
+ encode_kind(ebml_w,
+ alt fd.decl.purity { pure_fn. { 'p' } impure_fn. { 'f' } }
+ as u8);
+ encode_type_param_count(ebml_w, tps);
+ encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
+ encode_symbol(ecx, ebml_w, item.id);
+ ebmlivec::end_tag(ebml_w);
+ }
+ item_mod(_) {
+ ebmlivec::start_tag(ebml_w, tag_items_data_item);
+ encode_def_id(ebml_w, local_def(item.id));
+ encode_kind(ebml_w, 'm' as u8);
+ ebmlivec::end_tag(ebml_w);
+ }
+ item_native_mod(_) {
+ ebmlivec::start_tag(ebml_w, tag_items_data_item);
+ encode_def_id(ebml_w, local_def(item.id));
+ encode_kind(ebml_w, 'n' as u8);
+ ebmlivec::end_tag(ebml_w);
+ }
+ item_ty(_, tps) {
+ ebmlivec::start_tag(ebml_w, tag_items_data_item);
+ encode_def_id(ebml_w, local_def(item.id));
+ encode_kind(ebml_w, 'y' as u8);
+ encode_type_param_count(ebml_w, tps);
+ encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
+ ebmlivec::end_tag(ebml_w);
+ }
+ item_tag(variants, tps) {
+ ebmlivec::start_tag(ebml_w, tag_items_data_item);
+ encode_def_id(ebml_w, local_def(item.id));
+ encode_kind(ebml_w, 't' as u8);
+ encode_type_param_count(ebml_w, tps);
+ encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
+ for v: variant in variants {
+ encode_variant_id(ebml_w, local_def(v.node.id));
}
- case (item_fn(?fd, ?tps)) {
- ebmlivec::start_tag(ebml_w, tag_items_data_item);
- encode_def_id(ebml_w, local_def(item.id));
- encode_kind(ebml_w, alt (fd.decl.purity) {
- case (pure_fn) { 'p' }
- case (impure_fn) { 'f' } } as u8);
- encode_type_param_count(ebml_w, tps);
- encode_type(ecx, ebml_w,
- node_id_to_monotype(ecx.ccx.tcx, item.id));
- encode_symbol(ecx, ebml_w, item.id);
- ebmlivec::end_tag(ebml_w);
- }
- case (item_mod(_)) {
- ebmlivec::start_tag(ebml_w, tag_items_data_item);
- encode_def_id(ebml_w, local_def(item.id));
- encode_kind(ebml_w, 'm' as u8);
- ebmlivec::end_tag(ebml_w);
- }
- case (item_native_mod(_)) {
- ebmlivec::start_tag(ebml_w, tag_items_data_item);
- encode_def_id(ebml_w, local_def(item.id));
- encode_kind(ebml_w, 'n' as u8);
- ebmlivec::end_tag(ebml_w);
- }
- case (item_ty(_, ?tps)) {
- ebmlivec::start_tag(ebml_w, tag_items_data_item);
- encode_def_id(ebml_w, local_def(item.id));
- encode_kind(ebml_w, 'y' as u8);
- encode_type_param_count(ebml_w, tps);
- encode_type(ecx, ebml_w,
- node_id_to_monotype(ecx.ccx.tcx, item.id));
- ebmlivec::end_tag(ebml_w);
- }
- case (item_tag(?variants, ?tps)) {
- ebmlivec::start_tag(ebml_w, tag_items_data_item);
- encode_def_id(ebml_w, local_def(item.id));
- encode_kind(ebml_w, 't' as u8);
- encode_type_param_count(ebml_w, tps);
- encode_type(ecx, ebml_w,
- node_id_to_monotype(ecx.ccx.tcx, item.id));
- for (variant v in variants) {
- encode_variant_id(ebml_w, local_def(v.node.id));
- }
- ebmlivec::end_tag(ebml_w);
- encode_tag_variant_info(ecx, ebml_w, item.id, variants, index,
- tps);
- }
- case (item_res(_, _, ?tps, ?ctor_id)) {
- auto fn_ty = node_id_to_monotype(ecx.ccx.tcx, ctor_id);
+ ebmlivec::end_tag(ebml_w);
+ encode_tag_variant_info(ecx, ebml_w, item.id, variants, index, tps);
+ }
+ item_res(_, _, tps, ctor_id) {
+ let fn_ty = node_id_to_monotype(ecx.ccx.tcx, ctor_id);
- ebmlivec::start_tag(ebml_w, tag_items_data_item);
- encode_def_id(ebml_w, local_def(ctor_id));
- encode_kind(ebml_w, 'y' as u8);
- encode_type_param_count(ebml_w, tps);
- encode_type(ecx, ebml_w, ty::ty_fn_ret(ecx.ccx.tcx, fn_ty));
- encode_symbol(ecx, ebml_w, item.id);
- ebmlivec::end_tag(ebml_w);
+ ebmlivec::start_tag(ebml_w, tag_items_data_item);
+ encode_def_id(ebml_w, local_def(ctor_id));
+ encode_kind(ebml_w, 'y' as u8);
+ encode_type_param_count(ebml_w, tps);
+ encode_type(ecx, ebml_w, ty::ty_fn_ret(ecx.ccx.tcx, fn_ty));
+ encode_symbol(ecx, ebml_w, item.id);
+ ebmlivec::end_tag(ebml_w);
- 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);
- encode_type_param_count(ebml_w, tps);
- encode_type(ecx, ebml_w, fn_ty);
- encode_symbol(ecx, ebml_w, ctor_id);
- ebmlivec::end_tag(ebml_w);
- }
- case (item_obj(_, ?tps, ?ctor_id)) {
- auto fn_ty = node_id_to_monotype(ecx.ccx.tcx, ctor_id);
+ index += ~[{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);
+ encode_type_param_count(ebml_w, tps);
+ encode_type(ecx, ebml_w, fn_ty);
+ encode_symbol(ecx, ebml_w, ctor_id);
+ ebmlivec::end_tag(ebml_w);
+ }
+ item_obj(_, tps, ctor_id) {
+ let fn_ty = node_id_to_monotype(ecx.ccx.tcx, ctor_id);
- ebmlivec::start_tag(ebml_w, tag_items_data_item);
- encode_def_id(ebml_w, local_def(item.id));
- encode_kind(ebml_w, 'y' as u8);
- encode_type_param_count(ebml_w, tps);
- encode_type(ecx, ebml_w, ty::ty_fn_ret(ecx.ccx.tcx, fn_ty));
- ebmlivec::end_tag(ebml_w);
+ ebmlivec::start_tag(ebml_w, tag_items_data_item);
+ encode_def_id(ebml_w, local_def(item.id));
+ encode_kind(ebml_w, 'y' as u8);
+ encode_type_param_count(ebml_w, tps);
+ encode_type(ecx, ebml_w, ty::ty_fn_ret(ecx.ccx.tcx, fn_ty));
+ ebmlivec::end_tag(ebml_w);
- 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);
- encode_type_param_count(ebml_w, tps);
- encode_type(ecx, ebml_w, fn_ty);
- encode_symbol(ecx, ebml_w, ctor_id);
- ebmlivec::end_tag(ebml_w);
- }
+ index += ~[{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);
+ encode_type_param_count(ebml_w, tps);
+ encode_type(ecx, ebml_w, fn_ty);
+ encode_symbol(ecx, ebml_w, ctor_id);
+ ebmlivec::end_tag(ebml_w);
+ }
}
}
-fn encode_info_for_native_item(&@encode_ctxt ecx, &ebmlivec::writer ebml_w,
- &@native_item nitem) {
+fn encode_info_for_native_item(ecx: &@encode_ctxt, ebml_w: &ebmlivec::writer,
+ nitem: &@native_item) {
ebmlivec::start_tag(ebml_w, tag_items_data_item);
- alt (nitem.node) {
- case (native_item_ty) {
- encode_def_id(ebml_w, local_def(nitem.id));
- encode_kind(ebml_w, 'T' as u8);
- encode_type(ecx, ebml_w,
- ty::mk_native(ecx.ccx.tcx, local_def(nitem.id)));
- }
- case (native_item_fn(_, _, ?tps)) {
- encode_def_id(ebml_w, local_def(nitem.id));
- encode_kind(ebml_w, 'F' as u8);
- encode_type_param_count(ebml_w, tps);
- encode_type(ecx, ebml_w,
- node_id_to_monotype(ecx.ccx.tcx, nitem.id));
- encode_symbol(ecx, ebml_w, nitem.id);
- }
+ alt nitem.node {
+ native_item_ty. {
+ encode_def_id(ebml_w, local_def(nitem.id));
+ encode_kind(ebml_w, 'T' as u8);
+ encode_type(ecx, ebml_w,
+ ty::mk_native(ecx.ccx.tcx, local_def(nitem.id)));
+ }
+ native_item_fn(_, _, tps) {
+ encode_def_id(ebml_w, local_def(nitem.id));
+ encode_kind(ebml_w, 'F' as u8);
+ encode_type_param_count(ebml_w, tps);
+ encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, nitem.id));
+ encode_symbol(ecx, ebml_w, nitem.id);
+ }
}
ebmlivec::end_tag(ebml_w);
}
-fn encode_info_for_items(&@encode_ctxt ecx, &ebmlivec::writer ebml_w)
- -> (entry[int])[] {
- let (entry[int])[] index = ~[];
+fn encode_info_for_items(ecx: &@encode_ctxt, ebml_w: &ebmlivec::writer) ->
+ (entry[int])[] {
+ let index: (entry[int])[] = ~[];
ebmlivec::start_tag(ebml_w, tag_items_data);
- 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 += ~[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 += ~[rec(val=kvp.key, pos=ebml_w.writer.tell())];
- encode_info_for_native_item(ecx, ebml_w, i);
- }
- case (_) {}
+ for each kvp: @{key: node_id, val: middle::ast_map::ast_node} in
+ ecx.ccx.ast_map.items() {
+ alt kvp.val {
+ middle::ast_map::node_item(i) {
+ index += ~[{val: kvp.key, pos: ebml_w.writer.tell()}];
+ encode_info_for_item(ecx, ebml_w, i, index);
+ }
+ middle::ast_map::node_native_item(i) {
+ index += ~[{val: kvp.key, pos: ebml_w.writer.tell()}];
+ encode_info_for_native_item(ecx, ebml_w, i);
+ }
+ _ { }
}
}
ebmlivec::end_tag(ebml_w);
@@ -382,32 +373,32 @@
// Path and definition ID indexing
-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 (entry[T] elt in index) {
- auto h = hash_fn(elt.val);
- *(buckets.(h % 256u)) += ~[elt];
+fn create_index[T](index: &(entry[T])[], hash_fn: fn(&T) -> uint ) ->
+ (@(entry[T])[])[] {
+ let buckets: (@mutable (entry[T])[])[] = ~[];
+ for each i: uint in uint::range(0u, 256u) { buckets += ~[@mutable ~[]]; }
+ for elt: entry[T] in index {
+ let h = hash_fn(elt.val);
+ *buckets.(h % 256u) += ~[elt];
}
- auto buckets_frozen = ~[];
- for (@mutable (entry[T])[] bucket in buckets) {
+ let buckets_frozen = ~[];
+ for bucket: @mutable (entry[T])[] in buckets {
buckets_frozen += ~[@*bucket];
}
ret buckets_frozen;
}
-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);
+fn encode_index[T](ebml_w: &ebmlivec::writer, buckets: &(@(entry[T])[])[],
+ write_fn: fn(&ioivec::writer, &T) ) {
+ let writer = ioivec::new_writer_(ebml_w.writer);
ebmlivec::start_tag(ebml_w, tag_index);
- let uint[] bucket_locs = ~[];
+ let bucket_locs: uint[] = ~[];
ebmlivec::start_tag(ebml_w, tag_index_buckets);
- for (@(entry[T])[] bucket in buckets) {
+ for bucket: @(entry[T])[] in buckets {
bucket_locs += ~[ebml_w.writer.tell()];
ebmlivec::start_tag(ebml_w, tag_index_buckets_bucket);
- for (entry[T] elt in *bucket) {
+ for elt: entry[T] in *bucket {
ebmlivec::start_tag(ebml_w, tag_index_buckets_bucket_elt);
writer.write_be_uint(elt.pos, 4u);
write_fn(writer, elt.val);
@@ -417,57 +408,57 @@
}
ebmlivec::end_tag(ebml_w);
ebmlivec::start_tag(ebml_w, tag_index_table);
- for (uint pos in bucket_locs) { writer.write_be_uint(pos, 4u); }
+ for pos: uint in bucket_locs { writer.write_be_uint(pos, 4u); }
ebmlivec::end_tag(ebml_w);
ebmlivec::end_tag(ebml_w);
}
-fn write_str(&ioivec::writer writer, &str s) { writer.write_str(s); }
+fn write_str(writer: &ioivec::writer, s: &str) { writer.write_str(s); }
-fn write_int(&ioivec::writer writer, &int n) {
+fn write_int(writer: &ioivec::writer, n: &int) {
writer.write_be_uint(n as uint, 4u);
}
-fn encode_meta_item(&ebmlivec::writer ebml_w, &meta_item mi) {
- alt (mi.node) {
- case (meta_word(?name)) {
- ebmlivec::start_tag(ebml_w, tag_meta_item_word);
+fn encode_meta_item(ebml_w: &ebmlivec::writer, mi: &meta_item) {
+ alt mi.node {
+ meta_word(name) {
+ ebmlivec::start_tag(ebml_w, tag_meta_item_word);
+ ebmlivec::start_tag(ebml_w, tag_meta_item_name);
+ ebml_w.writer.write(str::bytes_ivec(name));
+ ebmlivec::end_tag(ebml_w);
+ ebmlivec::end_tag(ebml_w);
+ }
+ meta_name_value(name, value) {
+ alt value.node {
+ lit_str(value, _) {
+ ebmlivec::start_tag(ebml_w, tag_meta_item_name_value);
ebmlivec::start_tag(ebml_w, tag_meta_item_name);
ebml_w.writer.write(str::bytes_ivec(name));
ebmlivec::end_tag(ebml_w);
+ ebmlivec::start_tag(ebml_w, tag_meta_item_value);
+ ebml_w.writer.write(str::bytes_ivec(value));
ebmlivec::end_tag(ebml_w);
- }
- case (meta_name_value(?name, ?value)) {
- alt (value.node) {
- case (lit_str(?value, _)) {
- ebmlivec::start_tag(ebml_w, tag_meta_item_name_value);
- ebmlivec::start_tag(ebml_w, tag_meta_item_name);
- ebml_w.writer.write(str::bytes_ivec(name));
- ebmlivec::end_tag(ebml_w);
- ebmlivec::start_tag(ebml_w, tag_meta_item_value);
- ebml_w.writer.write(str::bytes_ivec(value));
- ebmlivec::end_tag(ebml_w);
- ebmlivec::end_tag(ebml_w);
- }
- case (_) { /* FIXME (#611) */ }
- }
- }
- case (meta_list(?name, ?items)) {
- ebmlivec::start_tag(ebml_w, tag_meta_item_list);
- ebmlivec::start_tag(ebml_w, tag_meta_item_name);
- ebml_w.writer.write(str::bytes_ivec(name));
ebmlivec::end_tag(ebml_w);
- for (@meta_item inner_item in items) {
- encode_meta_item(ebml_w, *inner_item);
- }
- ebmlivec::end_tag(ebml_w);
+ }
+ _ {/* FIXME (#611) */ }
}
+ }
+ meta_list(name, items) {
+ ebmlivec::start_tag(ebml_w, tag_meta_item_list);
+ ebmlivec::start_tag(ebml_w, tag_meta_item_name);
+ ebml_w.writer.write(str::bytes_ivec(name));
+ ebmlivec::end_tag(ebml_w);
+ for inner_item: @meta_item in items {
+ encode_meta_item(ebml_w, *inner_item);
+ }
+ ebmlivec::end_tag(ebml_w);
+ }
}
}
-fn encode_attributes(&ebmlivec::writer ebml_w, &attribute[] attrs) {
+fn encode_attributes(ebml_w: &ebmlivec::writer, attrs: &attribute[]) {
ebmlivec::start_tag(ebml_w, tag_attributes);
- for (attribute attr in attrs) {
+ for attr: attribute in attrs {
ebmlivec::start_tag(ebml_w, tag_attribute);
encode_meta_item(ebml_w, attr.node.value);
ebmlivec::end_tag(ebml_w);
@@ -479,81 +470,82 @@
// metadata that Rust cares about for linking crates. This attribute requires
// 'name' and 'vers' items, so if the user didn't provide them we will throw
// them in anyway with default values.
-fn synthesize_crate_attrs(&@encode_ctxt ecx,
- &@crate crate) -> attribute[] {
+fn synthesize_crate_attrs(ecx: &@encode_ctxt, crate: &@crate) -> attribute[] {
- fn synthesize_link_attr(&@encode_ctxt ecx, &(@meta_item)[] items)
- -> attribute {
+ fn synthesize_link_attr(ecx: &@encode_ctxt, items: &(@meta_item)[]) ->
+ attribute {
- assert ecx.ccx.link_meta.name != "";
- assert ecx.ccx.link_meta.vers != "";
+ assert (ecx.ccx.link_meta.name != "");
+ assert (ecx.ccx.link_meta.vers != "");
- auto name_item = attr::mk_name_value_item_str("name",
- ecx.ccx.link_meta.name);
- auto vers_item = attr::mk_name_value_item_str("vers",
- ecx.ccx.link_meta.vers);
+ let name_item =
+ attr::mk_name_value_item_str("name", ecx.ccx.link_meta.name);
+ let vers_item =
+ attr::mk_name_value_item_str("vers", ecx.ccx.link_meta.vers);
- auto other_items = {
- auto tmp = attr::remove_meta_items_by_name(items, "name");
- attr::remove_meta_items_by_name(tmp, "vers")
- };
+ let other_items =
+ {
+ let tmp = attr::remove_meta_items_by_name(items, "name");
+ attr::remove_meta_items_by_name(tmp, "vers")
+ };
- auto meta_items = ~[name_item, vers_item] + other_items;
- auto link_item = attr::mk_list_item("link", meta_items);
+ let meta_items = ~[name_item, vers_item] + other_items;
+ let link_item = attr::mk_list_item("link", meta_items);
ret attr::mk_attr(link_item);
}
- let attribute[] attrs = ~[];
- auto found_link_attr = false;
- for (attribute attr in crate.node.attrs) {
- attrs += if (attr::get_attr_name(attr) != "link") {
- ~[attr]
- } else {
- alt (attr.node.value.node) {
- case (meta_list(?n, ?l)) {
+ let attrs: attribute[] = ~[];
+ let found_link_attr = false;
+ for attr: attribute in crate.node.attrs {
+ attrs +=
+ if attr::get_attr_name(attr) != "link" {
+ ~[attr]
+ } else {
+ alt attr.node.value.node {
+ meta_list(n, l) {
found_link_attr = true;
~[synthesize_link_attr(ecx, l)]
+ }
+ _ { ~[attr] }
}
- case (_) { ~[attr] }
}
- }
}
- if (!found_link_attr) {
- attrs += ~[synthesize_link_attr(ecx, ~[])];
- }
+ if !found_link_attr { attrs += ~[synthesize_link_attr(ecx, ~[])]; }
ret attrs;
}
-fn encode_crate_deps(&ebmlivec::writer ebml_w, &cstore::cstore cstore) {
+fn encode_crate_deps(ebml_w: &ebmlivec::writer, cstore: &cstore::cstore) {
- fn get_ordered_names(&cstore::cstore cstore) -> str[] {
- type hashkv = @rec(crate_num key, cstore::crate_metadata val);
- type numname = rec(crate_num crate, str ident);
+ fn get_ordered_names(cstore: &cstore::cstore) -> str[] {
+ type hashkv = @{key: crate_num, val: cstore::crate_metadata};
+ type numname = {crate: crate_num, ident: str};
// 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 rec(crate=hashkv.key, ident=hashkv.val.name)];
+ let pairs: numname[mutable ] = ~[mutable ];
+ for each hashkv: hashkv in cstore::iter_crate_data(cstore) {
+ pairs += ~[mutable {crate: hashkv.key, ident: hashkv.val.name}];
}
// Sort by cnum
- fn lteq(&numname kv1, &numname kv2) -> bool { kv1.crate <= kv2.crate }
+ fn lteq(kv1: &numname, kv2: &numname) -> 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.crate == expected_cnum;
+ let expected_cnum = 1;
+ for n: numname in pairs {
+ assert (n.crate == expected_cnum);
expected_cnum += 1;
}
// Return just the names
- fn name(&numname kv) -> str { kv.ident }
+ fn name(kv: &numname) -> str { kv.ident }
// mutable -> immutable hack for ivec::map
- auto immpairs = ivec::slice(pairs, 0u, ivec::len(pairs));
+ let immpairs = ivec::slice(pairs, 0u, ivec::len(pairs));
ret ivec::map(name, immpairs);
}
@@ -562,7 +554,7 @@
// FIXME: This is not nearly enough to support correct versioning
// but is enough to get transitive crate dependencies working.
ebmlivec::start_tag(ebml_w, tag_crate_deps);
- for (str cname in get_ordered_names(cstore)) {
+ for cname: str in get_ordered_names(cstore) {
ebmlivec::start_tag(ebml_w, tag_crate_dep);
ebml_w.writer.write(str::bytes_ivec(cname));
ebmlivec::end_tag(ebml_w);
@@ -570,16 +562,16 @@
ebmlivec::end_tag(ebml_w);
}
-fn encode_metadata(&@crate_ctxt cx, &@crate crate) -> str {
+fn encode_metadata(cx: &@crate_ctxt, crate: &@crate) -> str {
- auto abbrevs = map::mk_hashmap(ty::hash_ty, ty::eq_ty);
- auto ecx = @rec(ccx = cx, type_abbrevs = abbrevs);
+ let abbrevs = map::mk_hashmap(ty::hash_ty, ty::eq_ty);
+ let ecx = @{ccx: cx, type_abbrevs: abbrevs};
- auto string_w = ioivec::string_writer();
- auto buf_w = string_w.get_writer().get_buf_writer();
- auto ebml_w = ebmlivec::create_writer(buf_w);
+ let string_w = ioivec::string_writer();
+ let buf_w = string_w.get_writer().get_buf_writer();
+ let ebml_w = ebmlivec::create_writer(buf_w);
- auto crate_attrs = synthesize_crate_attrs(ecx, crate);
+ let crate_attrs = synthesize_crate_attrs(ecx, crate);
encode_attributes(ebml_w, crate_attrs);
encode_crate_deps(ebml_w, cx.sess.get_cstore());
@@ -587,15 +579,15 @@
// Encode and index the paths.
ebmlivec::start_tag(ebml_w, tag_paths);
- auto paths_index = encode_item_paths(ebml_w, crate);
- auto paths_buckets = create_index(paths_index, hash_path);
+ let paths_index = encode_item_paths(ebml_w, crate);
+ let paths_buckets = create_index(paths_index, hash_path);
encode_index(ebml_w, paths_buckets, write_str);
ebmlivec::end_tag(ebml_w);
// Encode and index the items.
ebmlivec::start_tag(ebml_w, tag_items);
- auto items_index = encode_info_for_items(ecx, ebml_w);
- auto items_buckets = create_index(items_index, hash_node_id);
+ let items_index = encode_info_for_items(ecx, ebml_w);
+ let items_buckets = create_index(items_index, hash_node_id);
encode_index(ebml_w, items_buckets, write_int);
ebmlivec::end_tag(ebml_w);
// Pad this, since something (LLVM, presumably) is cutting off the
@@ -606,11 +598,9 @@
}
// Get the encoded string for a type
-fn encoded_ty(&ty::ctxt tcx, &ty::t t) -> str {
- auto cx = @rec(ds = def_to_str,
- tcx = tcx,
- abbrevs = tyencode::ac_no_abbrevs);
- auto sw = ioivec::string_writer();
+fn encoded_ty(tcx: &ty::ctxt, t: &ty::t) -> str {
+ let cx = @{ds: def_to_str, tcx: tcx, abbrevs: tyencode::ac_no_abbrevs};
+ let sw = ioivec::string_writer();
tyencode::enc_ty(sw.get_writer(), cx, t);
ret sw.get_str();
}
diff --git a/src/comp/metadata/tydecode.rs b/src/comp/metadata/tydecode.rs
index f08fd5b..d0a00c9 100644
--- a/src/comp/metadata/tydecode.rs
+++ b/src/comp/metadata/tydecode.rs
@@ -22,126 +22,115 @@
type str_def = fn(str) -> ast::def_id ;
type pstate =
- rec(@u8[] data, int crate, mutable uint pos, uint len, ty::ctxt tcx);
+ {data: @u8[], crate: int, mutable pos: uint, len: uint, tcx: ty::ctxt};
tag ty_or_bang { a_ty(ty::t); a_bang; }
-fn peek(@pstate st) -> u8 { ret st.data.(st.pos); }
+fn peek(st: @pstate) -> u8 { ret st.data.(st.pos); }
-fn next(@pstate st) -> u8 {
- auto ch = st.data.(st.pos);
+fn next(st: @pstate) -> u8 {
+ let ch = st.data.(st.pos);
st.pos = st.pos + 1u;
ret ch;
}
-fn parse_ident(@pstate st, str_def sd, char last) -> ast::ident {
- fn is_last(char b, char c) -> bool {
- ret c == b;
- }
+fn parse_ident(st: @pstate, sd: str_def, last: char) -> ast::ident {
+ fn is_last(b: char, c: char) -> bool { ret c == b; }
ret parse_ident_(st, sd, bind is_last(last, _));
}
-fn parse_ident_(@pstate st, str_def sd, fn(char) -> bool is_last)
- -> ast::ident {
- auto rslt = "";
- while (! is_last(peek(st) as char)) {
+fn parse_ident_(st: @pstate, sd: str_def, is_last: fn(char) -> bool ) ->
+ ast::ident {
+ let rslt = "";
+ while !is_last(peek(st) as char) {
rslt += str::unsafe_from_byte(next(st));
}
ret rslt;
}
-fn parse_ty_data(@u8[] data, int crate_num, uint pos, uint len, str_def sd,
- ty::ctxt tcx) -> ty::t {
- auto st =
- @rec(data=data, crate=crate_num, mutable pos=pos, len=len, tcx=tcx);
- auto result = parse_ty(st, sd);
+fn parse_ty_data(data: @u8[], crate_num: int, pos: uint, len: uint,
+ sd: str_def, tcx: ty::ctxt) -> ty::t {
+ let st =
+ @{data: data, crate: crate_num, mutable pos: pos, len: len, tcx: tcx};
+ let result = parse_ty(st, sd);
ret result;
}
-fn parse_ty_or_bang(@pstate st, str_def sd) -> ty_or_bang {
- alt (peek(st) as char) {
- case ('!') { next(st); ret a_bang; }
- case (_) { ret a_ty(parse_ty(st, sd)); }
+fn parse_ty_or_bang(st: @pstate, sd: str_def) -> ty_or_bang {
+ alt peek(st) as char {
+ '!' { next(st); ret a_bang; }
+ _ { ret a_ty(parse_ty(st, sd)); }
}
}
-fn parse_constrs(@pstate st, str_def sd) -> (@ty::constr)[] {
- let (@ty::constr)[] rslt = ~[];
- alt (peek(st) as char) {
- case (':') {
- do {
- next(st);
- let @ty::constr one = parse_constr[uint](st, sd,
- parse_constr_arg);
- rslt += ~[one];
- } while (peek(st) as char == ';')
- }
- case (_) { }
+fn parse_constrs(st: @pstate, sd: str_def) -> (@ty::constr)[] {
+ let rslt: (@ty::constr)[] = ~[];
+ alt peek(st) as char {
+ ':' {
+ do {
+ next(st);
+ let one: @ty::constr =
+ parse_constr[uint](st, sd, parse_constr_arg);
+ rslt += ~[one];
+ } while peek(st) as char == ';'
+ }
+ _ { }
}
ret rslt;
}
// FIXME less copy-and-paste
-fn parse_ty_constrs(@pstate st, str_def sd) -> (@ty::type_constr)[] {
- let (@ty::type_constr)[] rslt = ~[];
- alt (peek(st) as char) {
- case (':') {
- do {
- next(st);
- let @ty::type_constr one = parse_constr[path](st, sd,
- parse_ty_constr_arg);
- rslt += ~[one];
- } while (peek(st) as char == ';')
- }
- case (_) { }
+fn parse_ty_constrs(st: @pstate, sd: str_def) -> (@ty::type_constr)[] {
+ let rslt: (@ty::type_constr)[] = ~[];
+ alt peek(st) as char {
+ ':' {
+ do {
+ next(st);
+ let one: @ty::type_constr =
+ parse_constr[path](st, sd, parse_ty_constr_arg);
+ rslt += ~[one];
+ } while peek(st) as char == ';'
+ }
+ _ { }
}
ret rslt;
}
-fn parse_path(@pstate st, str_def sd) -> ast::path {
- let ast::ident[] idents = ~[];
- fn is_last(char c) -> bool {
- ret (c == '(' || c == ':');
- }
+fn parse_path(st: @pstate, sd: str_def) -> ast::path {
+ let idents: ast::ident[] = ~[];
+ fn is_last(c: char) -> bool { ret c == '(' || c == ':'; }
idents += ~[parse_ident_(st, sd, is_last)];
- while (true) {
- alt (peek(st) as char) {
- case (':') { next(st); next(st); }
- case (?c) {
- if (c == '(') {
- ret respan(rec(lo=0u, hi=0u),
- rec(global=false, idents=idents, types=~[]));
- }
- else {
- idents += ~[parse_ident_(st, sd, is_last)];
- }
- }
+ while true {
+ alt peek(st) as char {
+ ':' { next(st); next(st); }
+ c {
+ if c == '(' {
+ ret respan({lo: 0u, hi: 0u},
+ {global: false, idents: idents, types: ~[]});
+ } else { idents += ~[parse_ident_(st, sd, is_last)]; }
+ }
}
}
fail "parse_path: ill-formed path";
}
-type arg_parser[T] = fn (@pstate st, str_def sd)
- -> ast::constr_arg_general_[T];
+type arg_parser[T] = fn(@pstate, str_def) -> ast::constr_arg_general_[T] ;
-fn parse_constr_arg(@pstate st, str_def sd) -> ast::fn_constr_arg {
- alt (peek(st) as char) {
- case ('*') {
- st.pos += 1u;
- ret ast::carg_base;
- }
- case (?c) {
+fn parse_constr_arg(st: @pstate, sd: str_def) -> ast::fn_constr_arg {
+ alt peek(st) as char {
+ '*' { st.pos += 1u; ret ast::carg_base; }
+ c {
+
/* how will we disambiguate between
an arg index and a lit argument? */
- if (c >= '0' && c <= '9') {
+ if c >= '0' && c <= '9' {
next(st);
- // FIXME
- ret ast::carg_ident((c as uint) - 48u);
- }
- else {
- log_err("Lit args are unimplemented");
- fail; // FIXME
+ // FIXME
+ ret ast::carg_ident((c as uint) - 48u);
+ } else {
+ log_err "Lit args are unimplemented";
+ fail; // FIXME
}
/*
else {
@@ -153,215 +142,200 @@
}
}
-fn parse_ty_constr_arg(@pstate st, str_def sd)
- -> ast::constr_arg_general_[path] {
- alt (peek(st) as char) {
- case ('*') {
- st.pos += 1u;
- ret ast::carg_base;
- }
- case (?c) {
- ret ast::carg_ident(parse_path(st, sd));
- }
+fn parse_ty_constr_arg(st: @pstate, sd: str_def) ->
+ ast::constr_arg_general_[path] {
+ alt peek(st) as char {
+ '*' { st.pos += 1u; ret ast::carg_base; }
+ c { ret ast::carg_ident(parse_path(st, sd)); }
}
}
-fn parse_constr[T](@pstate st, str_def sd, arg_parser[T] pser)
- -> @ty::constr_general[T] {
- auto sp = rec(lo=0u,hi=0u); // FIXME: use a real span
- let (@sp_constr_arg[T])[] args = ~[];
- let path pth = parse_path(st, sd);
- let char ignore = next(st) as char;
- assert(ignore as char == '(');
- auto def = parse_def(st, sd);
- let constr_arg_general_[T] an_arg;
- do {
+fn parse_constr[T](st: @pstate, sd: str_def, pser: arg_parser[T]) ->
+ @ty::constr_general[T] {
+ let sp = {lo: 0u, hi: 0u}; // FIXME: use a real span
+ let args: (@sp_constr_arg[T])[] = ~[];
+ let pth: path = parse_path(st, sd);
+ let ignore: char = next(st) as char;
+ assert (ignore as char == '(');
+ let def = parse_def(st, sd);
+ let an_arg: constr_arg_general_[T];
+ do {
an_arg = pser(st, sd);
// FIXME use a real span
args += ~[@respan(sp, an_arg)];
ignore = next(st) as char;
- } while (ignore == ';');
- assert(ignore == ')');
- ret @respan(sp, rec(path=pth, args=args, id=def));
+ } while ignore == ';'
+ assert (ignore == ')');
+ ret @respan(sp, {path: pth, args: args, id: def});
}
-fn parse_ty(@pstate st, str_def sd) -> ty::t {
- alt (next(st) as char) {
- case ('n') { ret ty::mk_nil(st.tcx); }
- case ('z') { ret ty::mk_bot(st.tcx); }
- case ('b') { ret ty::mk_bool(st.tcx); }
- case ('i') { ret ty::mk_int(st.tcx); }
- case ('u') { ret ty::mk_uint(st.tcx); }
- case ('l') { ret ty::mk_float(st.tcx); }
- case ('M') {
- alt (next(st) as char) {
- case ('b') { ret ty::mk_mach(st.tcx, ast::ty_u8); }
- case ('w') { ret ty::mk_mach(st.tcx, ast::ty_u16); }
- case ('l') { ret ty::mk_mach(st.tcx, ast::ty_u32); }
- case ('d') { ret ty::mk_mach(st.tcx, ast::ty_u64); }
- case ('B') { ret ty::mk_mach(st.tcx, ast::ty_i8); }
- case ('W') { ret ty::mk_mach(st.tcx, ast::ty_i16); }
- case ('L') { ret ty::mk_mach(st.tcx, ast::ty_i32); }
- case ('D') { ret ty::mk_mach(st.tcx, ast::ty_i64); }
- case ('f') { ret ty::mk_mach(st.tcx, ast::ty_f32); }
- case ('F') { ret ty::mk_mach(st.tcx, ast::ty_f64); }
- }
+fn parse_ty(st: @pstate, sd: str_def) -> ty::t {
+ alt next(st) as char {
+ 'n' { ret ty::mk_nil(st.tcx); }
+ 'z' { ret ty::mk_bot(st.tcx); }
+ 'b' { ret ty::mk_bool(st.tcx); }
+ 'i' { ret ty::mk_int(st.tcx); }
+ 'u' { ret ty::mk_uint(st.tcx); }
+ 'l' { ret ty::mk_float(st.tcx); }
+ 'M' {
+ alt next(st) as char {
+ 'b' { ret ty::mk_mach(st.tcx, ast::ty_u8); }
+ 'w' { ret ty::mk_mach(st.tcx, ast::ty_u16); }
+ 'l' { ret ty::mk_mach(st.tcx, ast::ty_u32); }
+ 'd' { ret ty::mk_mach(st.tcx, ast::ty_u64); }
+ 'B' { ret ty::mk_mach(st.tcx, ast::ty_i8); }
+ 'W' { ret ty::mk_mach(st.tcx, ast::ty_i16); }
+ 'L' { ret ty::mk_mach(st.tcx, ast::ty_i32); }
+ 'D' { ret ty::mk_mach(st.tcx, ast::ty_i64); }
+ 'f' { ret ty::mk_mach(st.tcx, ast::ty_f32); }
+ 'F' { ret ty::mk_mach(st.tcx, ast::ty_f64); }
}
- case ('c') { ret ty::mk_char(st.tcx); }
- case ('s') { ret ty::mk_str(st.tcx); }
- case ('S') { ret ty::mk_istr(st.tcx); }
- case ('t') {
- assert (next(st) as char == '[');
- auto def = parse_def(st, sd);
- let ty::t[] params = ~[];
- while (peek(st) as char != ']') { params += ~[parse_ty(st, sd)]; }
- st.pos = st.pos + 1u;
- ret ty::mk_tag(st.tcx, def, params);
- }
- case ('p') { ret ty::mk_param(st.tcx, parse_int(st) as uint); }
- case ('@') { ret ty::mk_box(st.tcx, parse_mt(st, sd)); }
- case ('*') { ret ty::mk_ptr(st.tcx, parse_mt(st, sd)); }
- case ('V') { ret ty::mk_vec(st.tcx, parse_mt(st, sd)); }
- case ('I') { ret ty::mk_ivec(st.tcx, parse_mt(st, sd)); }
- case ('a') { ret ty::mk_task(st.tcx); }
- case ('P') { ret ty::mk_port(st.tcx, parse_ty(st, sd)); }
- case ('C') { ret ty::mk_chan(st.tcx, parse_ty(st, sd)); }
- case ('R') {
- assert (next(st) as char == '[');
- let ty::field[] fields = ~[];
- while (peek(st) as char != ']') {
- auto name = "";
- while (peek(st) as char != '=') {
- name += str::unsafe_from_byte(next(st));
- }
- st.pos = st.pos + 1u;
- fields += ~[rec(ident=name, mt=parse_mt(st, sd))];
+ }
+ 'c' { ret ty::mk_char(st.tcx); }
+ 's' { ret ty::mk_str(st.tcx); }
+ 'S' { ret ty::mk_istr(st.tcx); }
+ 't' {
+ assert (next(st) as char == '[');
+ let def = parse_def(st, sd);
+ let params: ty::t[] = ~[];
+ while peek(st) as char != ']' { params += ~[parse_ty(st, sd)]; }
+ st.pos = st.pos + 1u;
+ ret ty::mk_tag(st.tcx, def, params);
+ }
+ 'p' { ret ty::mk_param(st.tcx, parse_int(st) as uint); }
+ '@' { ret ty::mk_box(st.tcx, parse_mt(st, sd)); }
+ '*' { ret ty::mk_ptr(st.tcx, parse_mt(st, sd)); }
+ 'V' { ret ty::mk_vec(st.tcx, parse_mt(st, sd)); }
+ 'I' { ret ty::mk_ivec(st.tcx, parse_mt(st, sd)); }
+ 'a' { ret ty::mk_task(st.tcx); }
+ 'P' { ret ty::mk_port(st.tcx, parse_ty(st, sd)); }
+ 'C' { ret ty::mk_chan(st.tcx, parse_ty(st, sd)); }
+ 'R' {
+ assert (next(st) as char == '[');
+ let fields: ty::field[] = ~[];
+ while peek(st) as char != ']' {
+ let name = "";
+ while peek(st) as char != '=' {
+ name += str::unsafe_from_byte(next(st));
}
st.pos = st.pos + 1u;
- ret ty::mk_rec(st.tcx, fields);
+ fields += ~[{ident: name, mt: parse_mt(st, sd)}];
}
- case ('F') {
- auto func = parse_ty_fn(st, sd);
- ret ty::mk_fn(st.tcx, ast::proto_fn, func.args, func.ty, func.cf,
- func.cs);
+ st.pos = st.pos + 1u;
+ ret ty::mk_rec(st.tcx, fields);
+ }
+ 'F' {
+ let func = parse_ty_fn(st, sd);
+ ret ty::mk_fn(st.tcx, ast::proto_fn, func.args, func.ty, func.cf,
+ func.cs);
+ }
+ 'W' {
+ let func = parse_ty_fn(st, sd);
+ ret ty::mk_fn(st.tcx, ast::proto_iter, func.args, func.ty, func.cf,
+ func.cs);
+ }
+ 'B' {
+ let func = parse_ty_fn(st, sd);
+ ret ty::mk_fn(st.tcx, ast::proto_block, func.args, func.ty, func.cf,
+ func.cs);
+ }
+ 'N' {
+ let abi;
+ alt next(st) as char {
+ 'r' { abi = ast::native_abi_rust; }
+ 'i' { abi = ast::native_abi_rust_intrinsic; }
+ 'c' { abi = ast::native_abi_cdecl; }
+ 'l' { abi = ast::native_abi_llvm; }
+ 's' { abi = ast::native_abi_x86stdcall; }
}
- case ('W') {
- auto func = parse_ty_fn(st, sd);
- ret ty::mk_fn(st.tcx, ast::proto_iter, func.args, func.ty,
- func.cf, func.cs);
- }
- case ('B') {
- auto func = parse_ty_fn(st, sd);
- ret ty::mk_fn(st.tcx, ast::proto_block, func.args, func.ty,
- func.cf, func.cs);
- }
- case ('N') {
- auto abi;
- alt (next(st) as char) {
- case ('r') { abi = ast::native_abi_rust; }
- case ('i') { abi = ast::native_abi_rust_intrinsic; }
- case ('c') { abi = ast::native_abi_cdecl; }
- case ('l') { abi = ast::native_abi_llvm; }
- case ('s') { abi = ast::native_abi_x86stdcall; }
+ let func = parse_ty_fn(st, sd);
+ ret ty::mk_native_fn(st.tcx, abi, func.args, func.ty);
+ }
+ 'O' {
+ assert (next(st) as char == '[');
+ let methods: ty::method[] = ~[];
+ while peek(st) as char != ']' {
+ let proto;
+ alt next(st) as char {
+ 'W' { proto = ast::proto_iter; }
+ 'F' { proto = ast::proto_fn; }
}
- auto func = parse_ty_fn(st, sd);
- ret ty::mk_native_fn(st.tcx, abi, func.args, func.ty);
- }
- case ('O') {
- assert (next(st) as char == '[');
- let ty::method[] methods = ~[];
- while (peek(st) as char != ']') {
- auto proto;
- alt (next(st) as char) {
- case ('W') { proto = ast::proto_iter; }
- case ('F') { proto = ast::proto_fn; }
- }
- auto name = "";
- while (peek(st) as char != '[') {
- name += str::unsafe_from_byte(next(st));
- }
- auto func = parse_ty_fn(st, sd);
- methods +=
- ~[rec(proto=proto,
- ident=name,
- inputs=func.args,
- output=func.ty,
- cf=func.cf,
- constrs=func.cs)];
+ let name = "";
+ while peek(st) as char != '[' {
+ name += str::unsafe_from_byte(next(st));
}
- st.pos += 1u;
- ret ty::mk_obj(st.tcx, methods);
+ let func = parse_ty_fn(st, sd);
+ methods +=
+ ~[{proto: proto,
+ ident: name,
+ inputs: func.args,
+ output: func.ty,
+ cf: func.cf,
+ constrs: func.cs}];
}
- case ('r') {
- assert (next(st) as char == '[');
- auto def = parse_def(st, sd);
- auto inner = parse_ty(st, sd);
- let ty::t[] params = ~[];
- while (peek(st) as char != ']') { params += ~[parse_ty(st, sd)]; }
- st.pos = st.pos + 1u;
- ret ty::mk_res(st.tcx, def, inner, params);
+ st.pos += 1u;
+ ret ty::mk_obj(st.tcx, methods);
+ }
+ 'r' {
+ assert (next(st) as char == '[');
+ let def = parse_def(st, sd);
+ let inner = parse_ty(st, sd);
+ let params: ty::t[] = ~[];
+ while peek(st) as char != ']' { params += ~[parse_ty(st, sd)]; }
+ st.pos = st.pos + 1u;
+ ret ty::mk_res(st.tcx, def, inner, params);
+ }
+ 'X' { ret ty::mk_var(st.tcx, parse_int(st)); }
+ 'E' { let def = parse_def(st, sd); ret ty::mk_native(st.tcx, def); }
+ 'Y' { ret ty::mk_type(st.tcx); }
+ '#' {
+ let pos = parse_hex(st);
+ assert (next(st) as char == ':');
+ let len = parse_hex(st);
+ assert (next(st) as char == '#');
+ alt st.tcx.rcache.find({cnum: st.crate, pos: pos, len: len}) {
+ some(tt) { ret tt; }
+ none. {
+ let ps = @{pos: pos, len: len with *st};
+ let tt = parse_ty(ps, sd);
+ st.tcx.rcache.insert({cnum: st.crate, pos: pos, len: len}, tt);
+ ret tt;
+ }
}
- case ('X') { ret ty::mk_var(st.tcx, parse_int(st)); }
- case ('E') {
- auto def = parse_def(st, sd);
- ret ty::mk_native(st.tcx, def);
- }
- case ('Y') { ret ty::mk_type(st.tcx); }
- case ('#') {
- auto pos = parse_hex(st);
- assert (next(st) as char == ':');
- auto len = parse_hex(st);
- assert (next(st) as char == '#');
- 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(rec(cnum=st.crate, pos=pos, len=len),
- tt);
- ret tt;
- }
- }
- }
- case ('A') {
- assert (next(st) as char == '[');
- auto tt = parse_ty(st, sd);
- auto tcs = parse_ty_constrs(st, sd);
- assert (next(st) as char == ']');
- ret ty::mk_constr(st.tcx, tt, tcs);
- }
- case (?c) {
- log_err "unexpected char in type string: ";
- log_err c;
- fail;
- }
+ }
+ 'A' {
+ assert (next(st) as char == '[');
+ let tt = parse_ty(st, sd);
+ let tcs = parse_ty_constrs(st, sd);
+ assert (next(st) as char == ']');
+ ret ty::mk_constr(st.tcx, tt, tcs);
+ }
+ c { log_err "unexpected char in type string: "; log_err c; fail; }
}
}
-fn parse_mt(@pstate st, str_def sd) -> ty::mt {
- auto mut;
- alt (peek(st) as char) {
- case ('m') { next(st); mut = ast::mut; }
- case ('?') { next(st); mut = ast::maybe_mut; }
- case (_) { mut = ast::imm; }
+fn parse_mt(st: @pstate, sd: str_def) -> ty::mt {
+ let mut;
+ alt peek(st) as char {
+ 'm' { next(st); mut = ast::mut; }
+ '?' { next(st); mut = ast::maybe_mut; }
+ _ { mut = ast::imm; }
}
- ret rec(ty=parse_ty(st, sd), mut=mut);
+ ret {ty: parse_ty(st, sd), mut: mut};
}
-fn parse_def(@pstate st, str_def sd) -> ast::def_id {
- auto def = "";
- while (peek(st) as char != '|') {
- def += str::unsafe_from_byte(next(st));
- }
+fn parse_def(st: @pstate, sd: str_def) -> ast::def_id {
+ let def = "";
+ while peek(st) as char != '|' { def += str::unsafe_from_byte(next(st)); }
st.pos = st.pos + 1u;
ret sd(def);
}
-fn parse_int(@pstate st) -> int {
- auto n = 0;
- while (true) {
- auto cur = peek(st) as char;
- if (cur < '0' || cur > '9') { break; }
+fn parse_int(st: @pstate) -> int {
+ let n = 0;
+ while true {
+ let cur = peek(st) as char;
+ if cur < '0' || cur > '9' { break; }
st.pos = st.pos + 1u;
n *= 10;
n += (cur as int) - ('0' as int);
@@ -369,72 +343,68 @@
ret n;
}
-fn parse_hex(@pstate st) -> uint {
- auto n = 0u;
- while (true) {
- auto cur = peek(st) as char;
- if ((cur < '0' || cur > '9') && (cur < 'a' || cur > 'f')) { break; }
+fn parse_hex(st: @pstate) -> uint {
+ let n = 0u;
+ while true {
+ let cur = peek(st) as char;
+ if (cur < '0' || cur > '9') && (cur < 'a' || cur > 'f') { break; }
st.pos = st.pos + 1u;
n *= 16u;
- if ('0' <= cur && cur <= '9') {
+ if '0' <= cur && cur <= '9' {
n += (cur as uint) - ('0' as uint);
} else { n += 10u + (cur as uint) - ('a' as uint); }
}
ret n;
}
-fn parse_ty_fn(@pstate st, str_def sd) ->
- rec(ty::arg[] args, ty::t ty, ast::controlflow cf, (@ty::constr)[] cs) {
+fn parse_ty_fn(st: @pstate, sd: str_def) ->
+ {args: ty::arg[], ty: ty::t, cf: ast::controlflow, cs: (@ty::constr)[]} {
assert (next(st) as char == '[');
- let ty::arg[] inputs = ~[];
- while (peek(st) as char != ']') {
- auto mode = ty::mo_val;
- if (peek(st) as char == '&') {
+ let inputs: ty::arg[] = ~[];
+ while peek(st) as char != ']' {
+ let mode = ty::mo_val;
+ if peek(st) as char == '&' {
mode = ty::mo_alias(false);
st.pos += 1u;
- if (peek(st) as char == 'm') {
+ if peek(st) as char == 'm' {
mode = ty::mo_alias(true);
st.pos += 1u;
}
}
- inputs += ~[rec(mode=mode, ty=parse_ty(st, sd))];
+ inputs += ~[{mode: mode, ty: parse_ty(st, sd)}];
}
st.pos += 1u; // eat the ']'
- auto cs = parse_constrs(st, sd);
- alt (parse_ty_or_bang(st, sd)) {
- case (a_bang) {
- 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);
- }
+ let cs = parse_constrs(st, sd);
+ alt parse_ty_or_bang(st, sd) {
+ a_bang. {
+ ret {args: inputs, ty: ty::mk_bot(st.tcx), cf: ast::noreturn, cs: cs};
+ }
+ a_ty(t) { ret {args: inputs, ty: t, cf: ast::return, cs: cs}; }
}
}
// Rust metadata parsing
-fn parse_def_id(&u8[] buf) -> ast::def_id {
- auto colon_idx = 0u;
- auto len = ivec::len[u8](buf);
- while (colon_idx < len && buf.(colon_idx) != ':' as u8) {
- colon_idx += 1u;
- }
- if (colon_idx == len) {
+fn parse_def_id(buf: &u8[]) -> ast::def_id {
+ let colon_idx = 0u;
+ let len = ivec::len[u8](buf);
+ while colon_idx < len && buf.(colon_idx) != ':' as u8 { colon_idx += 1u; }
+ if colon_idx == len {
log_err "didn't find ':' when parsing def id";
fail;
}
- auto crate_part = ivec::slice[u8](buf, 0u, colon_idx);
- auto def_part = ivec::slice[u8](buf, colon_idx + 1u, len);
+ let crate_part = ivec::slice[u8](buf, 0u, colon_idx);
+ let def_part = ivec::slice[u8](buf, colon_idx + 1u, len);
// FIXME: Remove these ivec->vec conversions.
- auto crate_part_vec = []; auto def_part_vec = [];
- for (u8 b in crate_part) { crate_part_vec += [b]; }
- for (u8 b in def_part) { def_part_vec += [b]; }
+ let crate_part_vec = [];
+ let def_part_vec = [];
+ for b: u8 in crate_part { crate_part_vec += [b]; }
+ for b: u8 in def_part { def_part_vec += [b]; }
- auto crate_num = uint::parse_buf(crate_part_vec, 10u) as int;
- auto def_num = uint::parse_buf(def_part_vec, 10u) as int;
- ret rec(crate=crate_num, node=def_num);
+ let crate_num = uint::parse_buf(crate_part_vec, 10u) as int;
+ let def_num = uint::parse_buf(def_part_vec, 10u) as int;
+ ret {crate: crate_num, node: def_num};
}
//
diff --git a/src/comp/metadata/tyencode.rs b/src/comp/metadata/tyencode.rs
index 2935e24..be9837c 100644
--- a/src/comp/metadata/tyencode.rs
+++ b/src/comp/metadata/tyencode.rs
@@ -17,256 +17,237 @@
export ac_use_abbrevs;
export enc_ty;
-type ctxt =
- rec(fn(&def_id) -> str ds, // Def -> str Callback:
- ty::ctxt tcx, // The type context.
- abbrev_ctxt abbrevs);
+type ctxt = // Def -> str Callback:
+ // The type context.
+ {ds: fn(&def_id) -> str , tcx: ty::ctxt, abbrevs: abbrev_ctxt};
// Compact string representation for ty.t values. API ty_str & parse_from_str.
// Extra parameters are for converting to/from def_ids in the string rep.
// Whatever format you choose should not contain pipe characters.
-type ty_abbrev = rec(uint pos, uint len, str s);
+type ty_abbrev = {pos: uint, len: uint, s: str};
tag abbrev_ctxt { ac_no_abbrevs; ac_use_abbrevs(hashmap[ty::t, ty_abbrev]); }
-fn cx_uses_abbrevs(&@ctxt cx) -> bool {
- alt (cx.abbrevs) {
- case (ac_no_abbrevs) { ret false; }
- case (ac_use_abbrevs(_)) { ret true; }
+fn cx_uses_abbrevs(cx: &@ctxt) -> bool {
+ alt cx.abbrevs {
+ ac_no_abbrevs. { ret false; }
+ ac_use_abbrevs(_) { ret true; }
}
}
-fn enc_ty(&ioivec::writer w, &@ctxt cx, &ty::t t) {
- alt (cx.abbrevs) {
- case (ac_no_abbrevs) {
- auto result_str;
- alt (cx.tcx.short_names_cache.find(t)) {
- case (some(?s)) { result_str = s; }
- case (none) {
- auto sw = ioivec::string_writer();
- enc_sty(sw.get_writer(), cx, ty::struct(cx.tcx, t));
- result_str = sw.get_str();
- cx.tcx.short_names_cache.insert(t, result_str);
- }
- }
- w.write_str(result_str);
+fn enc_ty(w: &ioivec::writer, cx: &@ctxt, t: &ty::t) {
+ alt cx.abbrevs {
+ ac_no_abbrevs. {
+ let result_str;
+ alt cx.tcx.short_names_cache.find(t) {
+ some(s) { result_str = s; }
+ none. {
+ let sw = ioivec::string_writer();
+ enc_sty(sw.get_writer(), cx, ty::struct(cx.tcx, t));
+ result_str = sw.get_str();
+ cx.tcx.short_names_cache.insert(t, result_str);
+ }
}
- case (ac_use_abbrevs(?abbrevs)) {
- alt (abbrevs.find(t)) {
- case (some(?a)) { w.write_str(a.s); ret; }
- case (none) {
- auto pos = w.get_buf_writer().tell();
- enc_sty(w, cx, ty::struct(cx.tcx, t));
- auto end = w.get_buf_writer().tell();
- auto len = end - pos;
- fn estimate_sz(uint u) -> uint {
- auto n = u;
- auto len = 0u;
- while (n != 0u) { len += 1u; n = n >> 4u; }
- ret len;
- }
- auto abbrev_len =
- 3u + estimate_sz(pos) + estimate_sz(len);
- if (abbrev_len < len) {
- // I.e. it's actually an abbreviation.
+ w.write_str(result_str);
+ }
+ ac_use_abbrevs(abbrevs) {
+ alt abbrevs.find(t) {
+ some(a) { w.write_str(a.s); ret; }
+ none. {
+ let pos = w.get_buf_writer().tell();
+ enc_sty(w, cx, ty::struct(cx.tcx, t));
+ let end = w.get_buf_writer().tell();
+ let len = end - pos;
+ fn estimate_sz(u: uint) -> uint {
+ let n = u;
+ let len = 0u;
+ while n != 0u { len += 1u; n = n >> 4u; }
+ ret len;
+ }
+ let abbrev_len = 3u + estimate_sz(pos) + estimate_sz(len);
+ if abbrev_len < len {
+ // I.e. it's actually an abbreviation.
- auto s =
- "#" + uint::to_str(pos, 16u) + ":" +
- uint::to_str(len, 16u) + "#";
- auto a = rec(pos=pos, len=len, s=s);
- abbrevs.insert(t, a);
- }
- ret;
- }
+ let s =
+ "#" + uint::to_str(pos, 16u) + ":" +
+ uint::to_str(len, 16u) + "#";
+ let a = {pos: pos, len: len, s: s};
+ abbrevs.insert(t, a);
}
+ ret;
+ }
}
+ }
}
}
-fn enc_mt(&ioivec::writer w, &@ctxt cx, &ty::mt mt) {
- alt (mt.mut) {
- case (imm) { }
- case (mut) { w.write_char('m'); }
- case (maybe_mut) { w.write_char('?'); }
+fn enc_mt(w: &ioivec::writer, cx: &@ctxt, mt: &ty::mt) {
+ alt mt.mut {
+ imm. { }
+ mut. { w.write_char('m'); }
+ maybe_mut. { w.write_char('?'); }
}
enc_ty(w, cx, mt.ty);
}
-fn enc_sty(&ioivec::writer w, &@ctxt cx, &ty::sty st) {
- alt (st) {
- case (ty::ty_nil) { w.write_char('n'); }
- case (ty::ty_bot) { w.write_char('z'); }
- case (ty::ty_bool) { w.write_char('b'); }
- case (ty::ty_int) { w.write_char('i'); }
- case (ty::ty_uint) { w.write_char('u'); }
- case (ty::ty_float) { w.write_char('l'); }
- case (ty::ty_machine(?mach)) {
- alt (mach) {
- case (ty_u8) { w.write_str("Mb"); }
- case (ty_u16) { w.write_str("Mw"); }
- case (ty_u32) { w.write_str("Ml"); }
- case (ty_u64) { w.write_str("Md"); }
- case (ty_i8) { w.write_str("MB"); }
- case (ty_i16) { w.write_str("MW"); }
- case (ty_i32) { w.write_str("ML"); }
- case (ty_i64) { w.write_str("MD"); }
- case (ty_f32) { w.write_str("Mf"); }
- case (ty_f64) { w.write_str("MF"); }
- }
+fn enc_sty(w: &ioivec::writer, cx: &@ctxt, st: &ty::sty) {
+ alt st {
+ ty::ty_nil. { w.write_char('n'); }
+ ty::ty_bot. { w.write_char('z'); }
+ ty::ty_bool. { w.write_char('b'); }
+ ty::ty_int. { w.write_char('i'); }
+ ty::ty_uint. { w.write_char('u'); }
+ ty::ty_float. { w.write_char('l'); }
+ ty::ty_machine(mach) {
+ alt mach {
+ ty_u8. { w.write_str("Mb"); }
+ ty_u16. { w.write_str("Mw"); }
+ ty_u32. { w.write_str("Ml"); }
+ ty_u64. { w.write_str("Md"); }
+ ty_i8. { w.write_str("MB"); }
+ ty_i16. { w.write_str("MW"); }
+ ty_i32. { w.write_str("ML"); }
+ ty_i64. { w.write_str("MD"); }
+ ty_f32. { w.write_str("Mf"); }
+ ty_f64. { w.write_str("MF"); }
}
- case (ty::ty_char) { w.write_char('c'); }
- case (ty::ty_str) { w.write_char('s'); }
- case (ty::ty_istr) { w.write_char('S'); }
- case (ty::ty_tag(?def, ?tys)) {
- w.write_str("t[");
- w.write_str(cx.ds(def));
- w.write_char('|');
- for (ty::t t in tys) { enc_ty(w, cx, t); }
- w.write_char(']');
+ }
+ ty::ty_char. { w.write_char('c'); }
+ ty::ty_str. { w.write_char('s'); }
+ ty::ty_istr. { w.write_char('S'); }
+ ty::ty_tag(def, tys) {
+ w.write_str("t[");
+ w.write_str(cx.ds(def));
+ w.write_char('|');
+ for t: ty::t in tys { enc_ty(w, cx, t); }
+ w.write_char(']');
+ }
+ ty::ty_box(mt) { w.write_char('@'); enc_mt(w, cx, mt); }
+ ty::ty_ptr(mt) { w.write_char('*'); enc_mt(w, cx, mt); }
+ ty::ty_vec(mt) { w.write_char('V'); enc_mt(w, cx, mt); }
+ ty::ty_ivec(mt) { w.write_char('I'); enc_mt(w, cx, mt); }
+ ty::ty_port(t) { w.write_char('P'); enc_ty(w, cx, t); }
+ ty::ty_chan(t) { w.write_char('C'); enc_ty(w, cx, t); }
+ ty::ty_rec(fields) {
+ w.write_str("R[");
+ for field: ty::field in fields {
+ w.write_str(field.ident);
+ w.write_char('=');
+ enc_mt(w, cx, field.mt);
}
- case (ty::ty_box(?mt)) { w.write_char('@'); enc_mt(w, cx, mt); }
- case (ty::ty_ptr(?mt)) { w.write_char('*'); enc_mt(w, cx, mt); }
- case (ty::ty_vec(?mt)) { w.write_char('V'); enc_mt(w, cx, mt); }
- case (ty::ty_ivec(?mt)) { w.write_char('I'); enc_mt(w, cx, mt); }
- case (ty::ty_port(?t)) { w.write_char('P'); enc_ty(w, cx, t); }
- case (ty::ty_chan(?t)) { w.write_char('C'); enc_ty(w, cx, t); }
- case (ty::ty_rec(?fields)) {
- w.write_str("R[");
- for (ty::field field in fields) {
- w.write_str(field.ident);
- w.write_char('=');
- enc_mt(w, cx, field.mt);
- }
- w.write_char(']');
+ w.write_char(']');
+ }
+ ty::ty_fn(proto, args, out, cf, constrs) {
+ enc_proto(w, proto);
+ enc_ty_fn(w, cx, args, out, cf, constrs);
+ }
+ ty::ty_native_fn(abi, args, out) {
+ w.write_char('N');
+ alt abi {
+ native_abi_rust. { w.write_char('r'); }
+ native_abi_rust_intrinsic. { w.write_char('i'); }
+ native_abi_cdecl. { w.write_char('c'); }
+ native_abi_llvm. { w.write_char('l'); }
+ native_abi_x86stdcall. { w.write_char('s'); }
}
- case (ty::ty_fn(?proto, ?args, ?out, ?cf, ?constrs)) {
- enc_proto(w, proto);
- enc_ty_fn(w, cx, args, out, cf, constrs);
+ enc_ty_fn(w, cx, args, out, return, ~[]);
+ }
+ ty::ty_obj(methods) {
+ w.write_str("O[");
+ for m: ty::method in methods {
+ enc_proto(w, m.proto);
+ w.write_str(m.ident);
+ enc_ty_fn(w, cx, m.inputs, m.output, m.cf, m.constrs);
}
- case (ty::ty_native_fn(?abi, ?args, ?out)) {
- w.write_char('N');
- alt (abi) {
- case (native_abi_rust) { w.write_char('r'); }
- case (native_abi_rust_intrinsic) {
- w.write_char('i');
- }
- case (native_abi_cdecl) { w.write_char('c'); }
- case (native_abi_llvm) { w.write_char('l'); }
- case (native_abi_x86stdcall) { w.write_char('s'); }
- }
- enc_ty_fn(w, cx, args, out, return, ~[]);
- }
- case (ty::ty_obj(?methods)) {
- w.write_str("O[");
- for (ty::method m in methods) {
- enc_proto(w, m.proto);
- w.write_str(m.ident);
- enc_ty_fn(w, cx, m.inputs, m.output, m.cf, m.constrs);
- }
- w.write_char(']');
- }
- case (ty::ty_res(?def, ?ty, ?tps)) {
- w.write_str("r[");
- w.write_str(cx.ds(def));
- w.write_char('|');
- enc_ty(w, cx, ty);
- for (ty::t t in tps) { enc_ty(w, cx, t); }
- w.write_char(']');
- }
- case (ty::ty_var(?id)) {
- w.write_char('X');
- w.write_str(int::str(id));
- }
- case (ty::ty_native(?def)) {
- w.write_char('E');
- w.write_str(cx.ds(def));
- w.write_char('|');
- }
- case (ty::ty_param(?id)) {
- w.write_char('p');
- w.write_str(uint::str(id));
- }
- case (ty::ty_type) { w.write_char('Y'); }
- case (ty::ty_task) { w.write_char('a'); }
- case (ty::ty_constr(?ty, ?cs)) {
- w.write_str("A[");
- enc_ty(w, cx, ty);
- for (@ty::type_constr tc in cs) {
- enc_ty_constr(w, cx, tc);
- }
- w.write_char(']');
- }
+ w.write_char(']');
+ }
+ ty::ty_res(def, ty, tps) {
+ w.write_str("r[");
+ w.write_str(cx.ds(def));
+ w.write_char('|');
+ enc_ty(w, cx, ty);
+ for t: ty::t in tps { enc_ty(w, cx, t); }
+ w.write_char(']');
+ }
+ ty::ty_var(id) { w.write_char('X'); w.write_str(int::str(id)); }
+ ty::ty_native(def) {
+ w.write_char('E');
+ w.write_str(cx.ds(def));
+ w.write_char('|');
+ }
+ ty::ty_param(id) { w.write_char('p'); w.write_str(uint::str(id)); }
+ ty::ty_type. { w.write_char('Y'); }
+ ty::ty_task. { w.write_char('a'); }
+ ty::ty_constr(ty, cs) {
+ w.write_str("A[");
+ enc_ty(w, cx, ty);
+ for tc: @ty::type_constr in cs { enc_ty_constr(w, cx, tc); }
+ w.write_char(']');
+ }
}
}
-fn enc_proto(&ioivec::writer w, proto proto) {
- alt (proto) {
- case (proto_iter) { w.write_char('W'); }
- case (proto_fn) { w.write_char('F'); }
- case (proto_block) { w.write_char('B'); }
+fn enc_proto(w: &ioivec::writer, proto: proto) {
+ alt proto {
+ proto_iter. { w.write_char('W'); }
+ proto_fn. { w.write_char('F'); }
+ proto_block. { w.write_char('B'); }
}
}
-fn enc_ty_fn(&ioivec::writer w, &@ctxt cx, &ty::arg[] args, &ty::t out,
- &controlflow cf, &(@ty::constr)[] constrs) {
+fn enc_ty_fn(w: &ioivec::writer, cx: &@ctxt, args: &ty::arg[], out: &ty::t,
+ cf: &controlflow, constrs: &(@ty::constr)[]) {
w.write_char('[');
- for (ty::arg arg in args) {
- alt (arg.mode) {
- case (ty::mo_alias(?mut)) {
- w.write_char('&');
- if (mut) { w.write_char('m'); }
- }
- case (ty::mo_val) { }
+ for arg: ty::arg in args {
+ alt arg.mode {
+ ty::mo_alias(mut) {
+ w.write_char('&');
+ if mut { w.write_char('m'); }
+ }
+ ty::mo_val. { }
}
enc_ty(w, cx, arg.ty);
}
w.write_char(']');
- auto colon = true;
- for (@ty::constr c in constrs) {
- if (colon) {
+ let colon = true;
+ for c: @ty::constr in constrs {
+ if colon {
w.write_char(':');
colon = false;
} else { w.write_char(';'); }
enc_constr(w, cx, c);
}
- alt (cf) {
- case (noreturn) { w.write_char('!'); }
- case (_) { enc_ty(w, cx, out); }
- }
+ alt cf { noreturn. { w.write_char('!'); } _ { enc_ty(w, cx, out); } }
}
// FIXME less copy-and-paste
-fn enc_constr(&ioivec::writer w, &@ctxt cx, &@ty::constr c) {
+fn enc_constr(w: &ioivec::writer, cx: &@ctxt, c: &@ty::constr) {
w.write_str(path_to_str(c.node.path));
w.write_char('(');
w.write_str(cx.ds(c.node.id));
w.write_char('|');
- auto semi = false;
- for (@constr_arg a in c.node.args) {
- if (semi) { w.write_char(';'); } else { semi = true; }
- alt (a.node) {
- case (carg_base) { w.write_char('*'); }
- case (carg_ident(?i)) {
- w.write_uint(i);
- }
- case (carg_lit(?l)) { w.write_str(lit_to_str(l)); }
+ let semi = false;
+ for a: @constr_arg in c.node.args {
+ if semi { w.write_char(';'); } else { semi = true; }
+ alt a.node {
+ carg_base. { w.write_char('*'); }
+ carg_ident(i) { w.write_uint(i); }
+ carg_lit(l) { w.write_str(lit_to_str(l)); }
}
}
w.write_char(')');
}
-fn enc_ty_constr(&ioivec::writer w, &@ctxt cx, &@ty::type_constr c) {
+fn enc_ty_constr(w: &ioivec::writer, cx: &@ctxt, c: &@ty::type_constr) {
w.write_str(path_to_str(c.node.path));
w.write_char('(');
w.write_str(cx.ds(c.node.id));
w.write_char('|');
- auto semi = false;
- for (@ty::ty_constr_arg a in c.node.args) {
- if (semi) { w.write_char(';'); } else { semi = true; }
- alt (a.node) {
- case (carg_base) { w.write_char('*'); }
- case (carg_ident(?p)) {
- w.write_str(path_to_str(p));
- }
- case (carg_lit(?l)) { w.write_str(lit_to_str(l)); }
+ let semi = false;
+ for a: @ty::ty_constr_arg in c.node.args {
+ if semi { w.write_char(';'); } else { semi = true; }
+ alt a.node {
+ carg_base. { w.write_char('*'); }
+ carg_ident(p) { w.write_str(path_to_str(p)); }
+ carg_lit(l) { w.write_str(lit_to_str(l)); }
}
}
w.write_char(')');
diff --git a/src/comp/middle/alias.rs b/src/comp/middle/alias.rs
index f66cfb9..f958b88 100644
--- a/src/comp/middle/alias.rs
+++ b/src/comp/middle/alias.rs
@@ -25,192 +25,185 @@
tag valid { valid; overwritten(span, ast::path); val_taken(span, ast::path); }
type restrict =
- @rec(node_id[] root_vars,
- node_id block_defnum,
- node_id[] bindings,
- ty::t[] tys,
- uint[] depends_on,
- mutable valid ok);
+ @{root_vars: node_id[],
+ block_defnum: node_id,
+ bindings: node_id[],
+ tys: ty::t[],
+ depends_on: uint[],
+ mutable ok: valid};
type scope = @restrict[];
tag local_info { arg(ast::mode); objfield(ast::mutability); }
-type ctx = rec(ty::ctxt tcx,
- std::map::hashmap[node_id, local_info] local_map);
+type ctx = {tcx: ty::ctxt, local_map: std::map::hashmap[node_id, local_info]};
-fn check_crate(ty::ctxt tcx, &@ast::crate crate) {
- auto cx = @rec(tcx=tcx,
- // Stores information about object fields and function
- // arguments that's otherwise not easily available.
- local_map=std::map::new_int_hash());
- auto v =
- @rec(visit_fn=bind visit_fn(cx, _, _, _, _, _, _, _),
- visit_item=bind visit_item(cx, _, _, _),
- visit_expr=bind visit_expr(cx, _, _, _),
- visit_decl=bind visit_decl(cx, _, _, _)
- with *visit::default_visitor[scope]());
+fn check_crate(tcx: ty::ctxt, crate: &@ast::crate) {
+ let
+ // Stores information about object fields and function
+ // arguments that's otherwise not easily available.
+ cx =
+ @{tcx: tcx, local_map: std::map::new_int_hash()};
+ let v =
+ @{visit_fn: bind visit_fn(cx, _, _, _, _, _, _, _),
+ visit_item: bind visit_item(cx, _, _, _),
+ visit_expr: bind visit_expr(cx, _, _, _),
+ visit_decl: bind visit_decl(cx, _, _, _)
+ with *visit::default_visitor[scope]()};
visit::visit_crate(*crate, @~[], visit::mk_vt(v));
tcx.sess.abort_if_errors();
}
-fn visit_fn(&@ctx cx, &ast::_fn f, &ast::ty_param[] tp, &span sp,
- &fn_ident name, ast::node_id id, &scope sc, &vt[scope] v) {
+fn visit_fn(cx: &@ctx, f: &ast::_fn, tp: &ast::ty_param[], sp: &span,
+ name: &fn_ident, id: ast::node_id, sc: &scope, v: &vt[scope]) {
visit::visit_fn_decl(f.decl, sc, v);
- for (ast::arg arg_ in f.decl.inputs) {
+ for arg_: ast::arg in f.decl.inputs {
cx.local_map.insert(arg_.id, arg(arg_.mode));
}
v.visit_block(f.body, @~[], v);
}
-fn visit_item(&@ctx cx, &@ast::item i, &scope sc, &vt[scope] v) {
- alt (i.node) {
- case (ast::item_obj(?o, _, _)) {
- for (ast::obj_field f in o.fields) {
- cx.local_map.insert(f.id, objfield(f.mut));
- }
+fn visit_item(cx: &@ctx, i: &@ast::item, sc: &scope, v: &vt[scope]) {
+ alt i.node {
+ ast::item_obj(o, _, _) {
+ for f: ast::obj_field in o.fields {
+ cx.local_map.insert(f.id, objfield(f.mut));
}
- case (_) { }
+ }
+ _ { }
}
visit::visit_item(i, sc, v);
}
-fn visit_expr(&@ctx cx, &@ast::expr ex, &scope sc, &vt[scope] v) {
- auto handled = true;
- alt (ex.node) {
- ast::expr_call(?f, ?args) {
- check_call(*cx, f, args, sc);
- handled = false;
- }
- ast::expr_be(?cl) {
- check_tail_call(*cx, cl);
- visit::visit_expr(cl, sc, v);
- }
- ast::expr_alt(?input, ?arms) {
- check_alt(*cx, input, arms, sc, v);
- }
- ast::expr_put(?val) {
- alt (val) {
- case (some(?ex)) {
- auto root = expr_root(*cx, ex, false);
- if (mut_field(root.ds)) {
- cx.tcx.sess.span_err(ex.span,
- "result of put must be" +
- " immutably rooted");
- }
- visit_expr(cx, ex, sc, v);
- }
- case (_) { }
+fn visit_expr(cx: &@ctx, ex: &@ast::expr, sc: &scope, v: &vt[scope]) {
+ let handled = true;
+ alt ex.node {
+ ast::expr_call(f, args) {
+ check_call(*cx, f, args, sc);
+ handled = false;
+ }
+ ast::expr_be(cl) {
+ check_tail_call(*cx, cl);
+ visit::visit_expr(cl, sc, v);
+ }
+ ast::expr_alt(input, arms) { check_alt(*cx, input, arms, sc, v); }
+ ast::expr_put(val) {
+ alt val {
+ some(ex) {
+ let root = expr_root(*cx, ex, false);
+ if mut_field(root.ds) {
+ cx.tcx.sess.span_err(ex.span,
+ "result of put must be" +
+ " immutably rooted");
}
+ visit_expr(cx, ex, sc, v);
+ }
+ _ { }
}
- ast::expr_for_each(?decl, ?call, ?blk) {
- check_for_each(*cx, decl, call, blk, sc, v);
- }
- ast::expr_for(?decl, ?seq, ?blk) {
- check_for(*cx, decl, seq, blk, sc, v);
- }
- ast::expr_path(?pt) {
- check_var(*cx, ex, pt, ex.id, false, sc);
- handled = false;
- }
- ast::expr_swap(?lhs, ?rhs) {
- check_lval(cx, lhs, sc, v);
- check_lval(cx, rhs, sc, v);
- handled = false;
- }
- ast::expr_move(?dest, ?src) {
- check_assign(cx, dest, src, sc, v);
- check_move_rhs(cx, src, sc, v);
- }
- ast::expr_assign(?dest, ?src) | ast::expr_assign_op(_, ?dest, ?src) {
- check_assign(cx, dest, src, sc, v);
- }
- _ { handled = false; }
+ }
+ ast::expr_for_each(decl, call, blk) {
+ check_for_each(*cx, decl, call, blk, sc, v);
+ }
+ ast::expr_for(decl, seq, blk) { check_for(*cx, decl, seq, blk, sc, v); }
+ ast::expr_path(pt) {
+ check_var(*cx, ex, pt, ex.id, false, sc);
+ handled = false;
+ }
+ ast::expr_swap(lhs, rhs) {
+ check_lval(cx, lhs, sc, v);
+ check_lval(cx, rhs, sc, v);
+ handled = false;
+ }
+ ast::expr_move(dest, src) {
+ check_assign(cx, dest, src, sc, v);
+ check_move_rhs(cx, src, sc, v);
+ }
+ ast::expr_assign(dest, src) | ast::expr_assign_op(_, dest, src) {
+ check_assign(cx, dest, src, sc, v);
+ }
+ _ { handled = false; }
}
- if (!handled) { visit::visit_expr(ex, sc, v); }
+ if !handled { visit::visit_expr(ex, sc, v); }
}
-fn visit_decl(&@ctx cx, &@ast::decl d, &scope sc, &vt[scope] v) {
+fn visit_decl(cx: &@ctx, d: &@ast::decl, sc: &scope, v: &vt[scope]) {
visit::visit_decl(d, sc, v);
- alt (d.node) {
- ast::decl_local(?locs) {
- for (@ast::local loc in locs) {
- alt (loc.node.init) {
- some(?init) {
- if (init.op == ast::init_move) {
+ alt d.node {
+ ast::decl_local(locs) {
+ for loc: @ast::local in locs {
+ alt loc.node.init {
+ some(init) {
+ if init.op == ast::init_move {
check_move_rhs(cx, init.expr, sc, v);
}
}
- none {}
+ none. { }
}
}
}
- _ {}
+ _ { }
}
}
-fn check_call(&ctx cx, &@ast::expr f, &(@ast::expr)[] args, &scope sc) ->
- rec(node_id[] root_vars, ty::t[] unsafe_ts) {
- auto fty = ty::expr_ty(cx.tcx, f);
- auto arg_ts = fty_args(cx, fty);
- let node_id[] roots = ~[];
- let rec(uint arg, node_id node)[] mut_roots = ~[];
- let ty::t[] unsafe_ts = ~[];
- let uint[] unsafe_t_offsets = ~[];
- auto i = 0u;
- for (ty::arg arg_t in arg_ts) {
- if (arg_t.mode != ty::mo_val) {
- auto arg = args.(i);
- auto root = expr_root(cx, arg, false);
- if (arg_t.mode == ty::mo_alias(true)) {
- alt (path_def_id(cx, arg)) {
- some(?did) { mut_roots += ~[rec(arg=i, node=did.node)]; }
+fn check_call(cx: &ctx, f: &@ast::expr, args: &(@ast::expr)[], sc: &scope) ->
+ {root_vars: node_id[], unsafe_ts: ty::t[]} {
+ let fty = ty::expr_ty(cx.tcx, f);
+ let arg_ts = fty_args(cx, fty);
+ let roots: node_id[] = ~[];
+ let mut_roots: {arg: uint, node: node_id}[] = ~[];
+ let unsafe_ts: ty::t[] = ~[];
+ let unsafe_t_offsets: uint[] = ~[];
+ let i = 0u;
+ for arg_t: ty::arg in arg_ts {
+ if arg_t.mode != ty::mo_val {
+ let arg = args.(i);
+ let root = expr_root(cx, arg, false);
+ if arg_t.mode == ty::mo_alias(true) {
+ alt path_def_id(cx, arg) {
+ some(did) { mut_roots += ~[{arg: i, node: did.node}]; }
_ {
- if (!mut_field(root.ds)) {
- auto m = "passing a temporary value or \
+ if !mut_field(root.ds) {
+ let m =
+ "passing a temporary value or \
immutable field by mutable alias";
cx.tcx.sess.span_err(arg.span, m);
}
}
}
}
- alt (path_def_id(cx, root.ex)) {
- some(?did) { roots += ~[did.node]; }
+ alt path_def_id(cx, root.ex) {
+ some(did) { roots += ~[did.node]; }
_ { }
}
- alt (inner_mut(root.ds)) {
- some(?t) {
- unsafe_ts += ~[t];
- unsafe_t_offsets += ~[i];
- }
+ alt inner_mut(root.ds) {
+ some(t) { unsafe_ts += ~[t]; unsafe_t_offsets += ~[i]; }
_ { }
}
}
i += 1u;
}
- if (ivec::len(unsafe_ts) > 0u) {
- alt (f.node) {
- case (ast::expr_path(_)) {
- if (def_is_local(cx.tcx.def_map.get(f.id), true)) {
- cx.tcx.sess.span_err(f.span,
- #fmt("function may alias with \
+ if ivec::len(unsafe_ts) > 0u {
+ alt f.node {
+ ast::expr_path(_) {
+ if def_is_local(cx.tcx.def_map.get(f.id), true) {
+ cx.tcx.sess.span_err(f.span,
+ #fmt("function may alias with \
argument %u, which is not immutably rooted",
- unsafe_t_offsets.(0)));
- }
+ unsafe_t_offsets.(0)));
}
- case (_) { }
+ }
+ _ { }
}
}
- auto j = 0u;
- for (ty::t unsafe in unsafe_ts) {
- auto offset = unsafe_t_offsets.(j);
+ let j = 0u;
+ for unsafe: ty::t in unsafe_ts {
+ let offset = unsafe_t_offsets.(j);
j += 1u;
- auto i = 0u;
- for (ty::arg arg_t in arg_ts) {
- auto mut_alias = arg_t.mode == ty::mo_alias(true);
- if (i != offset &&
- ty_can_unsafely_include(cx, unsafe, arg_t.ty, mut_alias))
- {
+ let i = 0u;
+ for arg_t: ty::arg in arg_ts {
+ let mut_alias = arg_t.mode == ty::mo_alias(true);
+ if i != offset &&
+ ty_can_unsafely_include(cx, unsafe, arg_t.ty, mut_alias) {
cx.tcx.sess.span_err(args.(i).span,
#fmt("argument %u may alias with \
argument %u, which is not immutably rooted",
@@ -221,10 +214,10 @@
}
// Ensure we're not passing a root by mutable alias.
- for (rec(uint arg, node_id node) root in mut_roots) {
- auto mut_alias_to_root = false;
- auto mut_alias_to_root_count = 0u;
- for (node_id r in roots) {
+ for root: {arg: uint, node: node_id} in mut_roots {
+ let mut_alias_to_root = false;
+ let mut_alias_to_root_count = 0u;
+ for r: node_id in roots {
if root.node == r {
mut_alias_to_root_count += 1u;
if mut_alias_to_root_count > 1u {
@@ -234,46 +227,44 @@
}
}
- if (mut_alias_to_root) {
+
+ if mut_alias_to_root {
cx.tcx.sess.span_err(args.(root.arg).span,
"passing a mutable alias to a \
variable that roots another alias");
}
}
- ret rec(root_vars=roots, unsafe_ts=unsafe_ts);
+ ret {root_vars: roots, unsafe_ts: unsafe_ts};
}
-fn check_tail_call(&ctx cx, &@ast::expr call) {
- auto args;
- auto f =
- alt (call.node) {
- case (ast::expr_call(?f, ?args_)) { args = args_; f }
- };
- auto i = 0u;
- for (ty::arg arg_t in fty_args(cx, ty::expr_ty(cx.tcx, f))) {
- if (arg_t.mode != ty::mo_val) {
- auto mut_a = arg_t.mode == ty::mo_alias(true);
- auto ok = true;
- alt (args.(i).node) {
- case (ast::expr_path(_)) {
- auto def = cx.tcx.def_map.get(args.(i).id);
- auto dnum = ast::def_id_of_def(def).node;
- alt (cx.local_map.find(dnum)) {
- case (some(arg(ast::alias(?mut)))) {
- if (mut_a && !mut) {
- cx.tcx.sess.span_err(args.(i).span,
- "passing an immutable \
+fn check_tail_call(cx: &ctx, call: &@ast::expr) {
+ let args;
+ let f = alt call.node { ast::expr_call(f, args_) { args = args_; f } };
+ let i = 0u;
+ for arg_t: ty::arg in fty_args(cx, ty::expr_ty(cx.tcx, f)) {
+ if arg_t.mode != ty::mo_val {
+ let mut_a = arg_t.mode == ty::mo_alias(true);
+ let ok = true;
+ alt args.(i).node {
+ ast::expr_path(_) {
+ let def = cx.tcx.def_map.get(args.(i).id);
+ let dnum = ast::def_id_of_def(def).node;
+ alt cx.local_map.find(dnum) {
+ some(arg(ast::alias(mut))) {
+ if mut_a && !mut {
+ cx.tcx.sess.span_err(args.(i).span,
+ "passing an immutable \
alias by mutable alias");
- }
- }
- case (_) { ok = !def_is_local(def, false); }
}
+ }
+ _ { ok = !def_is_local(def, false); }
}
- case (_) { ok = false; }
+ }
+ _ { ok = false; }
}
- if (!ok) {
+ if !ok {
cx.tcx.sess.span_err(args.(i).span,
- "can not pass a local value by \
+ "can not pass a local value by \
alias to a tail call");
}
}
@@ -281,113 +272,113 @@
}
}
-fn check_alt(&ctx cx, &@ast::expr input, &ast::arm[] arms, &scope sc,
- &vt[scope] v) {
+fn check_alt(cx: &ctx, input: &@ast::expr, arms: &ast::arm[], sc: &scope,
+ v: &vt[scope]) {
visit::visit_expr(input, sc, v);
- auto root = expr_root(cx, input, true);
- auto roots = alt (path_def_id(cx, root.ex)) {
- some(?did) { ~[did.node] }
- _ { ~[] }
- };
- let ty::t[] forbidden_tp =
- alt (inner_mut(root.ds)) { some(?t) { ~[t] } _ { ~[] } };
- for (ast::arm a in arms) {
- auto dnums = arm_defnums(a);
- auto new_sc = sc;
- if (ivec::len(dnums) > 0u) {
- new_sc = @(*sc + ~[@rec(root_vars=roots,
- block_defnum=dnums.(0),
- bindings=dnums,
- tys=forbidden_tp,
- depends_on=deps(sc, roots),
- mutable ok=valid)]);
+ let root = expr_root(cx, input, true);
+ let roots =
+ alt path_def_id(cx, root.ex) { some(did) { ~[did.node] } _ { ~[] } };
+ let forbidden_tp: ty::t[] =
+ alt inner_mut(root.ds) { some(t) { ~[t] } _ { ~[] } };
+ for a: ast::arm in arms {
+ let dnums = arm_defnums(a);
+ let new_sc = sc;
+ if ivec::len(dnums) > 0u {
+ new_sc =
+ @(*sc +
+ ~[@{root_vars: roots,
+ block_defnum: dnums.(0),
+ bindings: dnums,
+ tys: forbidden_tp,
+ depends_on: deps(sc, roots),
+ mutable ok: valid}]);
}
visit::visit_arm(a, new_sc, v);
}
}
-fn arm_defnums(&ast::arm arm) -> node_id[] {
- auto dnums = ~[];
- fn walk_pat(&mutable node_id[] found, &@ast::pat p) {
- alt (p.node) {
- case (ast::pat_bind(_)) { found += ~[p.id]; }
- case (ast::pat_tag(_, ?children)) {
- for (@ast::pat child in children) { walk_pat(found, child); }
- }
- case (ast::pat_rec(?fields, _)) {
- for (ast::field_pat f in fields) { walk_pat(found, f.pat); }
- }
- case (ast::pat_box(?inner)) { walk_pat(found, inner); }
- case (_) { }
+fn arm_defnums(arm: &ast::arm) -> node_id[] {
+ let dnums = ~[];
+ fn walk_pat(found: &mutable node_id[], p: &@ast::pat) {
+ alt p.node {
+ ast::pat_bind(_) { found += ~[p.id]; }
+ ast::pat_tag(_, children) {
+ for child: @ast::pat in children { walk_pat(found, child); }
+ }
+ ast::pat_rec(fields, _) {
+ for f: ast::field_pat in fields { walk_pat(found, f.pat); }
+ }
+ ast::pat_box(inner) { walk_pat(found, inner); }
+ _ { }
}
}
walk_pat(dnums, arm.pats.(0));
ret dnums;
}
-fn check_for_each(&ctx cx, &@ast::local local, &@ast::expr call,
- &ast::blk blk, &scope sc, &vt[scope] v) {
+fn check_for_each(cx: &ctx, local: &@ast::local, call: &@ast::expr,
+ blk: &ast::blk, sc: &scope, v: &vt[scope]) {
visit::visit_expr(call, sc, v);
- alt (call.node) {
- case (ast::expr_call(?f, ?args)) {
- auto data = check_call(cx, f, args, sc);
- auto defnum = local.node.id;
- auto new_sc =
- @rec(root_vars=data.root_vars,
- block_defnum=defnum,
- bindings=~[defnum],
- tys=data.unsafe_ts,
- depends_on=deps(sc, data.root_vars),
- mutable ok=valid);
- visit::visit_block(blk, @(*sc + ~[new_sc]), v);
- }
+ alt call.node {
+ ast::expr_call(f, args) {
+ let data = check_call(cx, f, args, sc);
+ let defnum = local.node.id;
+ let new_sc =
+ @{root_vars: data.root_vars,
+ block_defnum: defnum,
+ bindings: ~[defnum],
+ tys: data.unsafe_ts,
+ depends_on: deps(sc, data.root_vars),
+ mutable ok: valid};
+ visit::visit_block(blk, @(*sc + ~[new_sc]), v);
+ }
}
}
-fn check_for(&ctx cx, &@ast::local local, &@ast::expr seq, &ast::blk blk,
- &scope sc, &vt[scope] v) {
+fn check_for(cx: &ctx, local: &@ast::local, seq: &@ast::expr, blk: &ast::blk,
+ sc: &scope, v: &vt[scope]) {
visit::visit_expr(seq, sc, v);
- auto defnum = local.node.id;
- auto root = expr_root(cx, seq, false);
- auto root_def = alt (path_def_id(cx, root.ex)) {
- some(?did) { ~[did.node] }
- _ { ~[] }
- };
- auto unsafe = alt (inner_mut(root.ds)) { some(?t) { ~[t] } _ { ~[] } };
+ let defnum = local.node.id;
+ let root = expr_root(cx, seq, false);
+ let root_def =
+ alt path_def_id(cx, root.ex) { some(did) { ~[did.node] } _ { ~[] } };
+ let unsafe = alt inner_mut(root.ds) { some(t) { ~[t] } _ { ~[] } };
// If this is a mutable vector, don't allow it to be touched.
- auto seq_t = ty::expr_ty(cx.tcx, seq);
- alt (ty::struct(cx.tcx, seq_t)) {
- ty::ty_vec(?mt) | ty::ty_ivec(?mt) {
- if (mt.mut != ast::imm) { unsafe = ~[seq_t]; }
- }
- ty::ty_str | ty::ty_istr { /* no-op */ }
- _ {
- cx.tcx.sess.span_unimpl(seq.span, "unknown seq type " +
+ let seq_t = ty::expr_ty(cx.tcx, seq);
+ alt ty::struct(cx.tcx, seq_t) {
+ ty::ty_vec(mt) | ty::ty_ivec(mt) {
+ if mt.mut != ast::imm { unsafe = ~[seq_t]; }
+ }
+ ty::ty_str. | ty::ty_istr. {/* no-op */ }
+ _ {
+ cx.tcx.sess.span_unimpl(seq.span,
+ "unknown seq type " +
util::ppaux::ty_to_str(cx.tcx, seq_t));
- }
+ }
}
- auto new_sc =
- @rec(root_vars=root_def,
- block_defnum=defnum,
- bindings=~[defnum],
- tys=unsafe,
- depends_on=deps(sc, root_def),
- mutable ok=valid);
+ let new_sc =
+ @{root_vars: root_def,
+ block_defnum: defnum,
+ bindings: ~[defnum],
+ tys: unsafe,
+ depends_on: deps(sc, root_def),
+ mutable ok: valid};
visit::visit_block(blk, @(*sc + ~[new_sc]), v);
}
-fn check_var(&ctx cx, &@ast::expr ex, &ast::path p, ast::node_id id,
- bool assign, &scope sc) {
- auto def = cx.tcx.def_map.get(id);
- if (!def_is_local(def, true)) { ret; }
- auto my_defnum = ast::def_id_of_def(def).node;
- auto var_t = ty::expr_ty(cx.tcx, ex);
- for (restrict r in *sc) {
+fn check_var(cx: &ctx, ex: &@ast::expr, p: &ast::path, id: ast::node_id,
+ assign: bool, sc: &scope) {
+ let def = cx.tcx.def_map.get(id);
+ if !def_is_local(def, true) { ret; }
+ let my_defnum = ast::def_id_of_def(def).node;
+ let var_t = ty::expr_ty(cx.tcx, ex);
+ for r: restrict in *sc {
+
// excludes variables introduced since the alias was made
- if (my_defnum < r.block_defnum) {
- for (ty::t t in r.tys) {
- if (ty_can_unsafely_include(cx, t, var_t, assign)) {
+ if my_defnum < r.block_defnum {
+ for t: ty::t in r.tys {
+ if ty_can_unsafely_include(cx, t, var_t, assign) {
r.ok = val_taken(ex.span, p);
}
}
@@ -397,114 +388,113 @@
}
}
-fn check_lval(&@ctx cx, &@ast::expr dest, &scope sc, &vt[scope] v) {
- alt (dest.node) {
- case (ast::expr_path(?p)) {
- auto dnum = ast::def_id_of_def(cx.tcx.def_map.get(dest.id)).node;
- if (is_immutable_alias(cx, sc, dnum)) {
- cx.tcx.sess.span_err(dest.span,
- "assigning to immutable alias");
- } else if (is_immutable_objfield(cx, dnum)) {
- cx.tcx.sess.span_err(dest.span,
- "assigning to immutable obj field");
- }
- for (restrict r in *sc) {
- if (ivec::member(dnum, r.root_vars)) {
- r.ok = overwritten(dest.span, p);
- }
+fn check_lval(cx: &@ctx, dest: &@ast::expr, sc: &scope, v: &vt[scope]) {
+ alt dest.node {
+ ast::expr_path(p) {
+ let dnum = ast::def_id_of_def(cx.tcx.def_map.get(dest.id)).node;
+ if is_immutable_alias(cx, sc, dnum) {
+ cx.tcx.sess.span_err(dest.span, "assigning to immutable alias");
+ } else if (is_immutable_objfield(cx, dnum)) {
+ cx.tcx.sess.span_err(dest.span,
+ "assigning to immutable obj field");
+ }
+ for r: restrict in *sc {
+ if ivec::member(dnum, r.root_vars) {
+ r.ok = overwritten(dest.span, p);
}
}
- case (_) {
- auto root = expr_root(*cx, dest, false);
- if (ivec::len(*root.ds) == 0u) {
- cx.tcx.sess.span_err(dest.span, "assignment to non-lvalue");
- } else if (!root.ds.(0).mut) {
- auto name =
- alt (root.ds.(0).kind) {
- case (unbox) { "box" }
- case (field) { "field" }
- case (index) { "vec content" }
- };
- cx.tcx.sess.span_err(dest.span,
- "assignment to immutable " + name);
- }
- visit_expr(cx, dest, sc, v);
+ }
+ _ {
+ let root = expr_root(*cx, dest, false);
+ if ivec::len(*root.ds) == 0u {
+ cx.tcx.sess.span_err(dest.span, "assignment to non-lvalue");
+ } else if (!root.ds.(0).mut) {
+ let name =
+ alt root.ds.(0).kind {
+ unbox. { "box" }
+ field. { "field" }
+ index. { "vec content" }
+ };
+ cx.tcx.sess.span_err(dest.span,
+ "assignment to immutable " + name);
}
+ visit_expr(cx, dest, sc, v);
+ }
}
}
-fn check_move_rhs(&@ctx cx, &@ast::expr src, &scope sc, &vt[scope] v) {
- alt (src.node) {
- case (ast::expr_path(?p)) {
- alt (cx.tcx.def_map.get(src.id)) {
- ast::def_obj_field(_) {
- cx.tcx.sess.span_err
- (src.span, "may not move out of an obj field");
- }
- _ {}
- }
- check_lval(cx, src, sc, v);
+fn check_move_rhs(cx: &@ctx, src: &@ast::expr, sc: &scope, v: &vt[scope]) {
+ alt src.node {
+ ast::expr_path(p) {
+ alt cx.tcx.def_map.get(src.id) {
+ ast::def_obj_field(_) {
+ cx.tcx.sess.span_err(src.span,
+ "may not move out of an obj field");
+ }
+ _ { }
}
- case (_) {
- auto root = expr_root(*cx, src, false);
- // Not a path and no-derefs means this is a temporary.
- if (ivec::len(*root.ds) != 0u) {
- cx.tcx.sess.span_err
- (src.span, "moving out of a data structure");
- }
+ check_lval(cx, src, sc, v);
+ }
+ _ {
+ let root = expr_root(*cx, src, false);
+
+ // Not a path and no-derefs means this is a temporary.
+ if ivec::len(*root.ds) != 0u {
+ cx.tcx.sess.span_err(src.span, "moving out of a data structure");
}
+ }
}
}
-fn check_assign(&@ctx cx, &@ast::expr dest, &@ast::expr src, &scope sc,
- &vt[scope] v) {
+fn check_assign(cx: &@ctx, dest: &@ast::expr, src: &@ast::expr, sc: &scope,
+ v: &vt[scope]) {
visit_expr(cx, src, sc, v);
check_lval(cx, dest, sc, v);
}
-fn is_immutable_alias(&@ctx cx, &scope sc, node_id dnum) -> bool {
- alt (cx.local_map.find(dnum)) {
- case (some(arg(ast::alias(false)))) { ret true; }
- case (_) { }
+fn is_immutable_alias(cx: &@ctx, sc: &scope, dnum: node_id) -> bool {
+ alt cx.local_map.find(dnum) {
+ some(arg(ast::alias(false))) { ret true; }
+ _ { }
}
- for (restrict r in *sc) {
- if (ivec::member(dnum, r.bindings)) { ret true; }
+ for r: restrict in *sc {
+ if ivec::member(dnum, r.bindings) { ret true; }
}
ret false;
}
-fn is_immutable_objfield(&@ctx cx, node_id dnum) -> bool {
+fn is_immutable_objfield(cx: &@ctx, dnum: node_id) -> bool {
ret cx.local_map.find(dnum) == some(objfield(ast::imm));
}
-fn test_scope(&ctx cx, &scope sc, &restrict r, &ast::path p) {
- auto prob = r.ok;
- for (uint dep in r.depends_on) {
- if (prob != valid) { break; }
+fn test_scope(cx: &ctx, sc: &scope, r: &restrict, p: &ast::path) {
+ let prob = r.ok;
+ for dep: uint in r.depends_on {
+ if prob != valid { break; }
prob = sc.(dep).ok;
}
- if (prob != valid) {
- auto msg =
- alt (prob) {
- case (overwritten(?sp, ?wpt)) {
- rec(span=sp, msg="overwriting " + ast::path_name(wpt))
- }
- case (val_taken(?sp, ?vpt)) {
- rec(span=sp, msg="taking the value of " +
- ast::path_name(vpt))
- }
+ if prob != valid {
+ let msg =
+ alt prob {
+ overwritten(sp, wpt) {
+ {span: sp, msg: "overwriting " + ast::path_name(wpt)}
+ }
+ val_taken(sp, vpt) {
+ {span: sp, msg: "taking the value of " + ast::path_name(vpt)}
+ }
};
- cx.tcx.sess.span_err(msg.span, msg.msg + " will invalidate alias " +
- ast::path_name(p) + ", which is still used");
+ cx.tcx.sess.span_err(msg.span,
+ msg.msg + " will invalidate alias " +
+ ast::path_name(p) + ", which is still used");
}
}
-fn deps(&scope sc, &node_id[] roots) -> uint[] {
- auto i = 0u;
- auto result = ~[];
- for (restrict r in *sc) {
- for (node_id dn in roots) {
+fn deps(sc: &scope, roots: &node_id[]) -> uint[] {
+ let i = 0u;
+ let result = ~[];
+ for r: restrict in *sc {
+ for dn: node_id in roots {
if ivec::member(dn, r.bindings) { result += ~[i]; }
}
i += 1u;
@@ -514,178 +504,184 @@
tag deref_t { unbox; field; index; }
-type deref = @rec(bool mut, deref_t kind, ty::t outer_t);
+type deref = @{mut: bool, kind: deref_t, outer_t: ty::t};
// Finds the root (the thing that is dereferenced) for the given expr, and a
// vec of dereferences that were used on this root. Note that, in this vec,
// the inner derefs come in front, so foo.bar.baz becomes rec(ex=foo,
// ds=[field(baz),field(bar)])
-fn expr_root(&ctx cx, @ast::expr ex, bool autoderef) ->
- rec(@ast::expr ex, @deref[] ds) {
- fn maybe_auto_unbox(&ctx cx, ty::t t) -> rec(ty::t t, deref[] ds) {
- auto ds = ~[];
- while (true) {
- alt (ty::struct(cx.tcx, t)) {
- ty::ty_box(?mt) {
- ds += ~[@rec(mut=mt.mut != ast::imm, kind=unbox, outer_t=t)];
+fn expr_root(cx: &ctx, ex: @ast::expr, autoderef: bool) ->
+ {ex: @ast::expr, ds: @deref[]} {
+ fn maybe_auto_unbox(cx: &ctx, t: ty::t) -> {t: ty::t, ds: deref[]} {
+ let ds = ~[];
+ while true {
+ alt ty::struct(cx.tcx, t) {
+ ty::ty_box(mt) {
+ ds += ~[@{mut: mt.mut != ast::imm, kind: unbox, outer_t: t}];
t = mt.ty;
}
- ty::ty_res(_, ?inner, ?tps) {
- ds += ~[@rec(mut=false, kind=unbox, outer_t=t)];
+ ty::ty_res(_, inner, tps) {
+ ds += ~[@{mut: false, kind: unbox, outer_t: t}];
t = ty::substitute_type_params(cx.tcx, tps, inner);
}
- ty::ty_tag(?did, ?tps) {
- auto variants = ty::tag_variants(cx.tcx, did);
- if (ivec::len(variants) != 1u ||
- ivec::len(variants.(0).args) != 1u) {
+ ty::ty_tag(did, tps) {
+ let variants = ty::tag_variants(cx.tcx, did);
+ if ivec::len(variants) != 1u ||
+ ivec::len(variants.(0).args) != 1u {
break;
}
- ds += ~[@rec(mut=false, kind=unbox, outer_t=t)];
- t = ty::substitute_type_params(cx.tcx, tps,
+ ds += ~[@{mut: false, kind: unbox, outer_t: t}];
+ t =
+ ty::substitute_type_params(cx.tcx, tps,
variants.(0).args.(0));
}
_ { break; }
}
}
- ret rec(t=t, ds=ds);
+ ret {t: t, ds: ds};
}
- let deref[] ds = ~[];
- while (true) {
- alt ({ ex.node }) {
- case (ast::expr_field(?base, ?ident)) {
- auto auto_unbox =
- maybe_auto_unbox(cx, ty::expr_ty(cx.tcx, base));
- auto mut = false;
- alt (ty::struct(cx.tcx, auto_unbox.t)) {
- case (ty::ty_rec(?fields)) {
- for (ty::field fld in fields) {
- if (str::eq(ident, fld.ident)) {
- mut = fld.mt.mut != ast::imm;
- break;
- }
- }
- }
- case (ty::ty_obj(_)) { }
- }
- ds += ~[@rec(mut=mut, kind=field, outer_t=auto_unbox.t)];
- ds += auto_unbox.ds;
- ex = base;
- }
- case (ast::expr_index(?base, _)) {
- auto auto_unbox =
- maybe_auto_unbox(cx, ty::expr_ty(cx.tcx, base));
- alt (ty::struct(cx.tcx, auto_unbox.t)) {
- case (ty::ty_vec(?mt)) {
- ds += ~[@rec(mut=mt.mut != ast::imm,
- kind=index,
- outer_t=auto_unbox.t)];
- }
- case (ty::ty_ivec(?mt)) {
- ds += ~[@rec(mut=mt.mut != ast::imm,
- kind=index,
- outer_t=auto_unbox.t)];
+ let ds: deref[] = ~[];
+ while true {
+ alt { ex.node } {
+ ast::expr_field(base, ident) {
+ let auto_unbox = maybe_auto_unbox(cx, ty::expr_ty(cx.tcx, base));
+ let mut = false;
+ alt ty::struct(cx.tcx, auto_unbox.t) {
+ ty::ty_rec(fields) {
+ for fld: ty::field in fields {
+ if str::eq(ident, fld.ident) {
+ mut = fld.mt.mut != ast::imm;
+ break;
}
}
- ds += auto_unbox.ds;
+ }
+ ty::ty_obj(_) { }
+ }
+ ds += ~[@{mut: mut, kind: field, outer_t: auto_unbox.t}];
+ ds += auto_unbox.ds;
+ ex = base;
+ }
+ ast::expr_index(base, _) {
+ let auto_unbox = maybe_auto_unbox(cx, ty::expr_ty(cx.tcx, base));
+ alt ty::struct(cx.tcx, auto_unbox.t) {
+ ty::ty_vec(mt) {
+ ds +=
+ ~[@{mut: mt.mut != ast::imm,
+ kind: index,
+ outer_t: auto_unbox.t}];
+ }
+ ty::ty_ivec(mt) {
+ ds +=
+ ~[@{mut: mt.mut != ast::imm,
+ kind: index,
+ outer_t: auto_unbox.t}];
+ }
+ }
+ ds += auto_unbox.ds;
+ ex = base;
+ }
+ ast::expr_unary(op, base) {
+ if op == ast::deref {
+ let base_t = ty::expr_ty(cx.tcx, base);
+ let mut = false;
+ alt ty::struct(cx.tcx, base_t) {
+ ty::ty_box(mt) { mut = mt.mut != ast::imm; }
+ ty::ty_res(_, _, _) { }
+ ty::ty_tag(_, _) { }
+ ty::ty_ptr(mt) { mut = mt.mut != ast::imm; }
+ }
+ ds += ~[@{mut: mut, kind: unbox, outer_t: base_t}];
ex = base;
- }
- case (ast::expr_unary(?op, ?base)) {
- if (op == ast::deref) {
- auto base_t = ty::expr_ty(cx.tcx, base);
- auto mut = false;
- alt (ty::struct(cx.tcx, base_t)) {
- case (ty::ty_box(?mt)) { mut = mt.mut != ast::imm; }
- case (ty::ty_res(_, _, _)) {}
- case (ty::ty_tag(_, _)) {}
- case (ty::ty_ptr(?mt)) { mut = mt.mut != ast::imm; }
- }
- ds += ~[@rec(mut=mut, kind=unbox, outer_t=base_t)];
- ex = base;
- } else { break; }
- }
- case (_) { break; }
+ } else { break; }
+ }
+ _ { break; }
}
}
- if (autoderef) {
- auto auto_unbox = maybe_auto_unbox(cx, ty::expr_ty(cx.tcx, ex));
+ if autoderef {
+ let auto_unbox = maybe_auto_unbox(cx, ty::expr_ty(cx.tcx, ex));
ds += auto_unbox.ds;
}
- ret rec(ex=ex, ds=@ds);
+ ret {ex: ex, ds: @ds};
}
-fn mut_field(&@deref[] ds) -> bool {
- for (deref d in *ds) { if (d.mut) { ret true; } }
+fn mut_field(ds: &@deref[]) -> bool {
+ for d: deref in *ds { if d.mut { ret true; } }
ret false;
}
-fn inner_mut(&@deref[] ds) -> option::t[ty::t] {
- for (deref d in *ds) { if (d.mut) { ret some(d.outer_t); } }
+fn inner_mut(ds: &@deref[]) -> option::t[ty::t] {
+ for d: deref in *ds { if d.mut { ret some(d.outer_t); } }
ret none;
}
-fn path_def_id(&ctx cx, &@ast::expr ex) -> option::t[ast::def_id] {
- alt (ex.node) {
- case (ast::expr_path(_)) {
- ret some(ast::def_id_of_def(cx.tcx.def_map.get(ex.id)));
- }
- case (_) { ret none; }
+fn path_def_id(cx: &ctx, ex: &@ast::expr) -> option::t[ast::def_id] {
+ alt ex.node {
+ ast::expr_path(_) {
+ ret some(ast::def_id_of_def(cx.tcx.def_map.get(ex.id)));
+ }
+ _ { ret none; }
}
}
-fn ty_can_unsafely_include(&ctx cx, ty::t needle, ty::t haystack, bool mut) ->
- bool {
- fn get_mut(bool cur, &ty::mt mt) -> bool {
+fn ty_can_unsafely_include(cx: &ctx, needle: ty::t, haystack: ty::t,
+ mut: bool) -> bool {
+ fn get_mut(cur: bool, mt: &ty::mt) -> bool {
ret cur || mt.mut != ast::imm;
}
- fn helper(&ty::ctxt tcx, ty::t needle, ty::t haystack, bool mut) -> bool {
- if (needle == haystack) { ret true; }
- alt (ty::struct(tcx, haystack)) {
- ty::ty_tag(_, ?ts) {
- for (ty::t t in ts) {
- if (helper(tcx, needle, t, mut)) { ret true; }
+ fn helper(tcx: &ty::ctxt, needle: ty::t, haystack: ty::t, mut: bool) ->
+ bool {
+ if needle == haystack { ret true; }
+ alt ty::struct(tcx, haystack) {
+ ty::ty_tag(_, ts) {
+ for t: ty::t in ts {
+ if helper(tcx, needle, t, mut) { ret true; }
+ }
+ ret false;
+ }
+ ty::ty_box(mt) | ty::ty_vec(mt) | ty::ty_ptr(mt) {
+ ret helper(tcx, needle, mt.ty, get_mut(mut, mt));
+ }
+ ty::ty_rec(fields) {
+ for f: ty::field in fields {
+ if helper(tcx, needle, f.mt.ty, get_mut(mut, f.mt)) {
+ ret true;
}
- ret false;
}
- ty::ty_box(?mt) | ty::ty_vec(?mt) | ty::ty_ptr(?mt) {
- ret helper(tcx, needle, mt.ty, get_mut(mut, mt));
- }
- ty::ty_rec(?fields) {
- for (ty::field f in fields) {
- if (helper(tcx, needle, f.mt.ty, get_mut(mut, f.mt))) {
- ret true;
- }
- }
- ret false;
- }
- // These may contain anything.
- ty::ty_fn(_, _, _, _, _) {
- ret true;
- }
- ty::ty_obj(_) { ret true; }
- // A type param may include everything, but can only be
- // treated as opaque downstream, and is thus safe unless we
- // saw mutable fields, in which case the whole thing can be
- // overwritten.
- ty::ty_param(_) { ret mut; }
- _ { ret false; }
+ ret false;
+ }
+
+ // These may contain anything.
+ ty::ty_fn(_, _, _, _, _) {
+ ret true;
+ }
+ ty::ty_obj(_) { ret true; }
+
+ // A type param may include everything, but can only be
+ // treated as opaque downstream, and is thus safe unless we
+ // saw mutable fields, in which case the whole thing can be
+ // overwritten.
+ ty::ty_param(_) {
+ ret mut;
+ }
+ _ { ret false; }
}
}
ret helper(cx.tcx, needle, haystack, mut);
}
-fn def_is_local(&ast::def d, bool objfields_count) -> bool {
- ret alt (d) {
- ast::def_local(_) | ast::def_arg(_) | ast::def_binding(_) { true }
- ast::def_obj_field(_) { objfields_count }
- _ { false }
- };
+fn def_is_local(d: &ast::def, objfields_count: bool) -> bool {
+ ret alt d {
+ ast::def_local(_) | ast::def_arg(_) | ast::def_binding(_) { true }
+ ast::def_obj_field(_) { objfields_count }
+ _ { false }
+ };
}
-fn fty_args(&ctx cx, ty::t fty) -> ty::arg[] {
- ret alt (ty::struct(cx.tcx, ty::type_autoderef(cx.tcx, fty))) {
- ty::ty_fn(_, ?args, _, _, _) | ty::ty_native_fn(_, ?args, _) { args }
- };
+fn fty_args(cx: &ctx, fty: ty::t) -> ty::arg[] {
+ ret alt ty::struct(cx.tcx, ty::type_autoderef(cx.tcx, fty)) {
+ ty::ty_fn(_, args, _, _, _) | ty::ty_native_fn(_, args, _) { args }
+ };
}
// Local Variables:
// mode: rust
diff --git a/src/comp/middle/ast_map.rs b/src/comp/middle/ast_map.rs
index 3e47cd0..172c9d9 100644
--- a/src/comp/middle/ast_map.rs
+++ b/src/comp/middle/ast_map.rs
@@ -13,44 +13,43 @@
type map = std::map::hashmap[node_id, ast_node];
-fn map_crate(&crate c) -> map {
+fn map_crate(c: &crate) -> map {
// FIXME: This is using an adapter to convert the smallintmap
// interface to the hashmap interface. It would be better to just
// convert everything to use the smallintmap.
- auto map = new_smallintmap_int_adapter[ast_node]();
+ let map = new_smallintmap_int_adapter[ast_node]();
- auto v_map = @rec(visit_item=bind map_item(map, _, _, _),
- visit_native_item=bind map_native_item(map, _, _, _),
- visit_expr=bind map_expr(map, _, _, _)
- with *visit::default_visitor[()]());
+ let v_map =
+ @{visit_item: bind map_item(map, _, _, _),
+ visit_native_item: bind map_native_item(map, _, _, _),
+ visit_expr: bind map_expr(map, _, _, _)
+ with *visit::default_visitor[()]()};
visit::visit_crate(c, (), visit::mk_vt(v_map));
ret map;
}
-fn map_item(&map map, &@item i, &() e, &vt[()] v) {
+fn map_item(map: &map, i: &@item, e: &(), v: &vt[()]) {
map.insert(i.id, node_item(i));
- alt (i.node) {
- case (item_obj(_, _, ?ctor_id)) {
- map.insert(ctor_id, node_obj_ctor(i));
- }
- case (_) {}
+ alt i.node {
+ item_obj(_, _, ctor_id) { map.insert(ctor_id, node_obj_ctor(i)); }
+ _ { }
}
visit::visit_item(i, e, v);
}
-fn map_native_item(&map map, &@native_item i, &() e, &vt[()] v) {
+fn map_native_item(map: &map, i: &@native_item, e: &(), v: &vt[()]) {
map.insert(i.id, node_native_item(i));
visit::visit_native_item(i, e, v);
}
-fn map_expr(&map map, &@expr ex, &() e, &vt[()] v) {
+fn map_expr(map: &map, ex: &@expr, e: &(), v: &vt[()]) {
map.insert(ex.id, node_expr(ex));
visit::visit_expr(ex, e, v);
}
fn new_smallintmap_int_adapter[V]() -> std::map::hashmap[int, V] {
- auto key_idx = fn(&int key) -> uint { key as uint };
- auto idx_key = fn(&uint idx) -> int { idx as int };
+ let key_idx = fn (key: &int) -> uint { key as uint };
+ let idx_key = fn (idx: &uint) -> int { idx as int };
ret new_smallintmap_adapter(key_idx, idx_key);
}
@@ -59,60 +58,58 @@
// the entire codebase adapting all the callsites to the different
// interface.
// FIXME: hashmap and smallintmap should support the same interface.
-fn new_smallintmap_adapter[K, V](fn(&K) -> uint key_idx,
- fn(&uint) -> K idx_key)
- -> std::map::hashmap[K, V] {
+fn new_smallintmap_adapter[K,
+ V](key_idx: fn(&K) -> uint ,
+ idx_key: fn(&uint) -> K ) ->
+ std::map::hashmap[K, V] {
- obj adapter[K, V](smallintmap::smallintmap[V] map,
- fn(&K) -> uint key_idx,
- fn(&uint) -> K idx_key) {
+ obj adapter[K,
+ V](map: smallintmap::smallintmap[V],
+ key_idx: fn(&K) -> uint ,
+ idx_key: fn(&uint) -> K ) {
fn size() -> uint { fail }
- fn insert(&K key, &V value) -> bool {
- auto exists = smallintmap::contains_key(map, key_idx(key));
+ fn insert(key: &K, value: &V) -> bool {
+ let exists = smallintmap::contains_key(map, key_idx(key));
smallintmap::insert(map, key_idx(key), value);
ret !exists;
}
- fn contains_key(&K key) -> bool {
+ fn contains_key(key: &K) -> bool {
ret smallintmap::contains_key(map, key_idx(key));
}
- fn get(&K key) -> V {
- ret smallintmap::get(map, key_idx(key));
- }
+ fn get(key: &K) -> V { ret smallintmap::get(map, key_idx(key)); }
- fn find(&K key) -> option::t[V] {
+ fn find(key: &K) -> option::t[V] {
ret smallintmap::find(map, key_idx(key));
}
- fn remove(&K key) -> option::t[V] { fail }
+ fn remove(key: &K) -> option::t[V] { fail }
fn rehash() { fail }
- iter items() -> @rec(K key, V val) {
- auto idx = 0u;
- for (option::t[V] item in map.v) {
- alt (item) {
- case (option::some(?elt)) {
- auto value = elt;
- auto key = idx_key(idx);
- put @rec(key=key, val=value);
- }
- case (option::none) { }
+ iter items() -> @{key: K, val: V} {
+ let idx = 0u;
+ for item: option::t[V] in map.v {
+ alt item {
+ option::some(elt) {
+ let value = elt;
+ let key = idx_key(idx);
+ put @{key: key, val: value};
+ }
+ option::none. { }
}
idx += 1u;
}
}
iter keys() -> K {
- for each (@rec(K key, V val) p in self.items()) {
- put p.key;
- }
+ for each p: @{key: K, val: V} in self.items() { put p.key; }
}
}
- auto map = smallintmap::mk[V]();
+ let map = smallintmap::mk[V]();
ret adapter(map, key_idx, idx_key);
}
diff --git a/src/comp/middle/check_alt.rs b/src/comp/middle/check_alt.rs
index 6b7a2e9..5c9b9e9 100644
--- a/src/comp/middle/check_alt.rs
+++ b/src/comp/middle/check_alt.rs
@@ -1,29 +1,27 @@
import syntax::ast::*;
import syntax::visit;
-fn check_crate(&ty::ctxt tcx, &@crate crate) {
- auto v = @rec(visit_expr=bind check_expr(tcx, _, _, _)
- with *visit::default_visitor[()]());
+fn check_crate(tcx: &ty::ctxt, crate: &@crate) {
+ let v =
+ @{visit_expr: bind check_expr(tcx, _, _, _)
+ with *visit::default_visitor[()]()};
visit::visit_crate(*crate, (), visit::mk_vt(v));
tcx.sess.abort_if_errors();
}
-fn check_expr(&ty::ctxt tcx, &@expr ex, &() s, &visit::vt[()] v) {
+fn check_expr(tcx: &ty::ctxt, ex: &@expr, s: &(), v: &visit::vt[()]) {
visit::visit_expr(ex, s, v);
- alt ex.node {
- expr_alt(_, ?arms) { check_arms(tcx, arms); }
- _ {}
- }
+ alt ex.node { expr_alt(_, arms) { check_arms(tcx, arms); } _ { } }
}
-fn check_arms(&ty::ctxt tcx, &arm[] arms) {
- auto i = 0;
- for (arm arm in arms) {
- for (@pat arm_pat in arm.pats) {
- auto reachable = true;
- auto j = 0;
+fn check_arms(tcx: &ty::ctxt, arms: &arm[]) {
+ let i = 0;
+ for arm: arm in arms {
+ for arm_pat: @pat in arm.pats {
+ let reachable = true;
+ let j = 0;
while j < i {
- for (@pat prev_pat in arms.(j).pats) {
+ for prev_pat: @pat in arms.(j).pats {
if pattern_supersedes(tcx, prev_pat, arm_pat) {
reachable = false;
}
@@ -38,21 +36,22 @@
}
}
-fn pattern_supersedes(&ty::ctxt tcx, &@pat a, &@pat b) -> bool {
- fn patterns_supersede(&ty::ctxt tcx, &(@pat)[] as, &(@pat)[] bs) -> bool {
- auto i = 0;
- for (@pat a in as) {
+fn pattern_supersedes(tcx: &ty::ctxt, a: &@pat, b: &@pat) -> bool {
+ fn patterns_supersede(tcx: &ty::ctxt, as: &(@pat)[], bs: &(@pat)[]) ->
+ bool {
+ let i = 0;
+ for a: @pat in as {
if !pattern_supersedes(tcx, a, bs.(i)) { ret false; }
i += 1;
}
ret true;
}
- fn field_patterns_supersede(&ty::ctxt tcx, &field_pat[] fas,
- &field_pat[] fbs) -> bool {
- auto wild = @rec(id=0, node=pat_wild, span=rec(lo=0u, hi=0u));
- for (field_pat fa in fas) {
- auto pb = wild;
- for (field_pat fb in fbs) {
+ fn field_patterns_supersede(tcx: &ty::ctxt, fas: &field_pat[],
+ fbs: &field_pat[]) -> bool {
+ let wild = @{id: 0, node: pat_wild, span: {lo: 0u, hi: 0u}};
+ for fa: field_pat in fas {
+ let pb = wild;
+ for fb: field_pat in fbs {
if fa.ident == fb.ident { pb = fb.pat; }
}
if !pattern_supersedes(tcx, fa.pat, pb) { ret false; }
@@ -60,32 +59,33 @@
ret true;
}
+
alt a.node {
- pat_wild | pat_bind(_) { ret true; }
- pat_lit(?la) {
+ pat_wild. | pat_bind(_) { ret true; }
+ pat_lit(la) {
alt b.node {
- pat_lit(?lb) { ret util::common::lit_eq(la, lb); }
+ pat_lit(lb) { ret util::common::lit_eq(la, lb); }
_ { ret false; }
}
}
- pat_tag(?va, ?suba) {
+ pat_tag(va, suba) {
alt b.node {
- pat_tag(?vb, ?subb) {
+ pat_tag(vb, subb) {
ret tcx.def_map.get(a.id) == tcx.def_map.get(b.id) &&
- patterns_supersede(tcx, suba, subb);
+ patterns_supersede(tcx, suba, subb);
}
_ { ret false; }
}
}
- pat_rec(?suba, _) {
+ pat_rec(suba, _) {
alt b.node {
- pat_rec(?subb, _) { ret field_patterns_supersede(tcx, suba, subb); }
+ pat_rec(subb, _) { ret field_patterns_supersede(tcx, suba, subb); }
_ { ret false; }
}
}
- pat_box(?suba) {
+ pat_box(suba) {
alt b.node {
- pat_box(?subb) { ret pattern_supersedes(tcx, suba, subb); }
+ pat_box(subb) { ret pattern_supersedes(tcx, suba, subb); }
_ { ret pattern_supersedes(tcx, suba, b); }
}
}
diff --git a/src/comp/middle/freevars.rs b/src/comp/middle/freevars.rs
index f20c511..d157499 100644
--- a/src/comp/middle/freevars.rs
+++ b/src/comp/middle/freevars.rs
@@ -24,7 +24,7 @@
export def_lookup;
type freevar_set = hashset[ast::node_id];
-type freevar_info = rec(freevar_set defs, @ast::node_id[] uses);
+type freevar_info = {defs: freevar_set, uses: @ast::node_id[]};
type freevar_map = hashmap[ast::node_id, freevar_info];
// Searches through part of the AST for all references to locals or
@@ -32,75 +32,68 @@
// Since we want to be able to collect upvars in some arbitrary piece
// of the AST, we take a walker function that we invoke with a visitor
// in order to start the search.
-fn collect_freevars(&resolve::def_map def_map, &session::session sess,
- &fn (&visit::vt[()]) walker,
- ast::node_id[] initial_decls) -> freevar_info {
+fn collect_freevars(def_map: &resolve::def_map, sess: &session::session,
+ walker: &fn(&visit::vt[()]) ,
+ initial_decls: ast::node_id[]) -> freevar_info {
type env =
- @rec(mutable ast::node_id[] refs,
- hashset[ast::node_id] decls,
- resolve::def_map def_map,
- session::session sess);
+ @{mutable refs: ast::node_id[],
+ decls: hashset[ast::node_id],
+ def_map: resolve::def_map,
+ sess: session::session};
- fn walk_fn(env e, &ast::_fn f, &ast::ty_param[] tps, &span sp,
- &ast::fn_ident i, ast::node_id nid) {
- for (ast::arg a in f.decl.inputs) { e.decls.insert(a.id, ()); }
+ fn walk_fn(e: env, f: &ast::_fn, tps: &ast::ty_param[], sp: &span,
+ i: &ast::fn_ident, nid: ast::node_id) {
+ for a: ast::arg in f.decl.inputs { e.decls.insert(a.id, ()); }
}
- fn walk_expr(env e, &@ast::expr expr) {
- alt (expr.node) {
- case (ast::expr_path(?path)) {
- if (! e.def_map.contains_key(expr.id)) {
- e.sess.span_fatal(expr.span,
- "internal error in collect_freevars");
- }
- alt (e.def_map.get(expr.id)) {
- case (ast::def_arg(?did)) { e.refs += ~[expr.id]; }
- case (ast::def_local(?did)) { e.refs += ~[expr.id]; }
- case (ast::def_binding(?did)) { e.refs += ~[expr.id]; }
- case (_) { /* no-op */ }
- }
+ fn walk_expr(e: env, expr: &@ast::expr) {
+ alt expr.node {
+ ast::expr_path(path) {
+ if !e.def_map.contains_key(expr.id) {
+ e.sess.span_fatal(expr.span,
+ "internal error in collect_freevars");
}
- case (_) { }
+ alt e.def_map.get(expr.id) {
+ ast::def_arg(did) { e.refs += ~[expr.id]; }
+ ast::def_local(did) { e.refs += ~[expr.id]; }
+ ast::def_binding(did) { e.refs += ~[expr.id]; }
+ _ {/* no-op */ }
+ }
+ }
+ _ { }
}
}
- fn walk_local(env e, &@ast::local local) {
+ fn walk_local(e: env, local: &@ast::local) {
set_add(e.decls, local.node.id);
}
- fn walk_pat(env e, &@ast::pat p) {
- alt (p.node) {
- case (ast::pat_bind(_)) {
- set_add(e.decls, p.id);
- }
- case (_) {}
- }
+ fn walk_pat(e: env, p: &@ast::pat) {
+ alt p.node { ast::pat_bind(_) { set_add(e.decls, p.id); } _ { } }
}
- let hashset[ast::node_id] decls = new_int_hash();
- for (ast::node_id decl in initial_decls) { set_add(decls, decl); }
+ let decls: hashset[ast::node_id] = new_int_hash();
+ for decl: ast::node_id in initial_decls { set_add(decls, decl); }
- let env e = @rec(mutable refs=~[],
- decls=decls,
- def_map=def_map,
- sess=sess);
- walker(visit::mk_simple_visitor(
- @rec(visit_local=bind walk_local(e, _),
- visit_pat=bind walk_pat(e, _),
- visit_expr=bind walk_expr(e, _),
- visit_fn=bind walk_fn(e, _, _, _, _, _)
- with *visit::default_simple_visitor())));
+ let e: env =
+ @{mutable refs: ~[], decls: decls, def_map: def_map, sess: sess};
+ walker(visit::mk_simple_visitor(@{visit_local: bind walk_local(e, _),
+ visit_pat: bind walk_pat(e, _),
+ visit_expr: bind walk_expr(e, _),
+ visit_fn: bind walk_fn(e, _, _, _, _, _)
+ with
+ *visit::default_simple_visitor()}));
// Calculate (refs - decls). This is the set of captured upvars.
// We build a vec of the node ids of the uses and a set of the
// node ids of the definitions.
- auto uses = ~[];
- auto defs = new_int_hash();
- for (ast::node_id ref_id_ in e.refs) {
- auto ref_id = ref_id_;
- auto def_id = ast::def_id_of_def(def_map.get(ref_id)).node;
+ let uses = ~[];
+ let defs = new_int_hash();
+ for ref_id_: ast::node_id in e.refs {
+ let ref_id = ref_id_;
+ let def_id = ast::def_id_of_def(def_map.get(ref_id)).node;
if !decls.contains_key(def_id) {
uses += ~[ref_id];
set_add(defs, def_id);
}
}
- ret rec(defs=defs, uses=@uses);
+ ret {defs: defs, uses: @uses};
}
// Build a map from every function and for-each body to a set of the
@@ -108,75 +101,73 @@
// efficient as it fully recomputes the free variables at every
// node of interest rather than building up the free variables in
// one pass. This could be improved upon if it turns out to matter.
-fn annotate_freevars(&session::session sess, &resolve::def_map def_map,
- &@ast::crate crate) -> freevar_map {
+fn annotate_freevars(sess: &session::session, def_map: &resolve::def_map,
+ crate: &@ast::crate) -> freevar_map {
type env =
- rec(freevar_map freevars,
- resolve::def_map def_map,
- session::session sess);
+ {freevars: freevar_map,
+ def_map: resolve::def_map,
+ sess: session::session};
- fn walk_fn(env e, &ast::_fn f, &ast::ty_param[] tps, &span sp,
- &ast::fn_ident i, ast::node_id nid) {
- fn start_walk(&ast::_fn f, &ast::ty_param[] tps, &span sp,
- &ast::fn_ident i, ast::node_id nid, &visit::vt[()] v) {
+ fn walk_fn(e: env, f: &ast::_fn, tps: &ast::ty_param[], sp: &span,
+ i: &ast::fn_ident, nid: ast::node_id) {
+ fn start_walk(f: &ast::_fn, tps: &ast::ty_param[], sp: &span,
+ i: &ast::fn_ident, nid: ast::node_id,
+ v: &visit::vt[()]) {
v.visit_fn(f, tps, sp, i, nid, (), v);
}
- auto walker = bind start_walk(f, tps, sp, i, nid, _);
- auto vars = collect_freevars(e.def_map, e.sess, walker, ~[]);
+ let walker = bind start_walk(f, tps, sp, i, nid, _);
+ let vars = collect_freevars(e.def_map, e.sess, walker, ~[]);
e.freevars.insert(nid, vars);
}
- fn walk_expr(env e, &@ast::expr expr) {
- alt (expr.node) {
- ast::expr_for_each(?local, _, ?body) {
- fn start_walk(&ast::blk b, &visit::vt[()] v) {
- v.visit_block(b, (), v);
- }
- auto vars = collect_freevars
- (e.def_map, e.sess, bind start_walk(body, _),
- ~[local.node.id]);
- e.freevars.insert(body.node.id, vars);
+ fn walk_expr(e: env, expr: &@ast::expr) {
+ alt expr.node {
+ ast::expr_for_each(local, _, body) {
+ fn start_walk(b: &ast::blk, v: &visit::vt[()]) {
+ v.visit_block(b, (), v);
}
- _ {}
+ let vars =
+ collect_freevars(e.def_map, e.sess, bind start_walk(body, _),
+ ~[local.node.id]);
+ e.freevars.insert(body.node.id, vars);
+ }
+ _ { }
}
}
- let env e =
- rec(freevars = new_int_hash(), def_map=def_map, sess=sess);
- auto visitor = visit::mk_simple_visitor
- (@rec(visit_fn=bind walk_fn(e, _, _, _, _, _),
- visit_expr=bind walk_expr(e, _)
- with *visit::default_simple_visitor()));
+ let e: env = {freevars: new_int_hash(), def_map: def_map, sess: sess};
+ let visitor =
+ visit::mk_simple_visitor(@{visit_fn: bind walk_fn(e, _, _, _, _, _),
+ visit_expr: bind walk_expr(e, _)
+ with *visit::default_simple_visitor()});
visit::visit_crate(*crate, (), visitor);
ret e.freevars;
}
-fn get_freevar_info(&ty::ctxt tcx, ast::node_id fid) -> freevar_info {
- alt (tcx.freevars.find(fid)) {
- none {
- fail "get_freevars: " + int::str(fid) + " has no freevars";
- }
- some(?d) { ret d; }
+fn get_freevar_info(tcx: &ty::ctxt, fid: ast::node_id) -> freevar_info {
+ alt tcx.freevars.find(fid) {
+ none. { fail "get_freevars: " + int::str(fid) + " has no freevars"; }
+ some(d) { ret d; }
}
}
-fn get_freevars(&ty::ctxt tcx, ast::node_id fid) -> freevar_set {
+fn get_freevars(tcx: &ty::ctxt, fid: ast::node_id) -> freevar_set {
ret get_freevar_info(tcx, fid).defs;
}
-fn get_freevar_uses(&ty::ctxt tcx, ast::node_id fid) -> @ast::node_id[] {
+fn get_freevar_uses(tcx: &ty::ctxt, fid: ast::node_id) -> @ast::node_id[] {
ret get_freevar_info(tcx, fid).uses;
}
-fn has_freevars(&ty::ctxt tcx, ast::node_id fid) -> bool {
+fn has_freevars(tcx: &ty::ctxt, fid: ast::node_id) -> bool {
ret get_freevars(tcx, fid).size() != 0u;
}
-fn is_freevar_of(&ty::ctxt tcx, ast::node_id var, ast::node_id f) -> bool {
+fn is_freevar_of(tcx: &ty::ctxt, var: ast::node_id, f: ast::node_id) -> bool {
ret get_freevars(tcx, f).contains_key(var);
}
-fn def_lookup(&ty::ctxt tcx, ast::node_id f, ast::node_id id) ->
- option::t[ast::def] {
- alt (tcx.def_map.find(id)) {
- none { ret none; }
- some(?d) {
- auto did = ast::def_id_of_def(d);
+fn def_lookup(tcx: &ty::ctxt, f: ast::node_id, id: ast::node_id) ->
+ option::t[ast::def] {
+ alt tcx.def_map.find(id) {
+ none. { ret none; }
+ some(d) {
+ let did = ast::def_id_of_def(d);
if is_freevar_of(tcx, did.node, f) {
ret some(ast::def_upvar(did, @d));
} else { ret some(d); }
diff --git a/src/comp/middle/resolve.rs b/src/comp/middle/resolve.rs
index 74fe1c3..443e5cc 100644
--- a/src/comp/middle/resolve.rs
+++ b/src/comp/middle/resolve.rs
@@ -52,6 +52,7 @@
scope_fn(ast::fn_decl, ast::proto, ast::ty_param[]);
scope_native_item(@ast::native_item);
scope_loop(@ast::local); // there's only 1 decl per loop.
+
scope_block(ast::blk);
scope_arm(ast::arm);
}
@@ -60,28 +61,30 @@
tag import_state {
todo(@ast::view_item, scopes); // only used for explicit imports
+
resolving(span);
- resolved(option::t[def], /* value */
- option::t[def], /* type */
+ resolved(option::t[def],
+ /* value */
+ option::t[def],
+ /* type */
option::t[def]); /* module */
}
-type ext_hash = hashmap[rec(def_id did, str ident, namespace ns), def];
+type ext_hash = hashmap[{did: def_id, ident: str, ns: namespace}, def];
fn new_ext_hash() -> ext_hash {
- type key = rec(def_id did, str ident, namespace ns);
- fn hash(&key v) -> uint {
+ type key = {did: def_id, ident: str, ns: namespace};
+ fn hash(v: &key) -> uint {
ret str::hash(v.ident) + util::common::hash_def(v.did) +
- alt (v.ns) {
- case (ns_value) { 1u }
- case (ns_type) { 2u }
- case (ns_module) { 3u }
+ alt v.ns {
+ ns_value. { 1u }
+ ns_type. { 2u }
+ ns_module. { 3u }
};
}
- fn eq(&key v1, &key v2) ->
- bool {
+ fn eq(v1: &key, v2: &key) -> bool {
ret util::common::def_eq(v1.did, v2.did) &&
- str::eq(v1.ident, v2.ident) && v1.ns == v2.ns;
+ str::eq(v1.ident, v2.ident) && v1.ns == v2.ns;
}
ret std::map::mk_hashmap[key, def](hash, eq);
}
@@ -90,19 +93,19 @@
mie_view_item(@ast::view_item);
mie_item(@ast::item);
mie_native_item(@ast::native_item);
- mie_tag_variant(@ast::item /* tag item */, uint /* variant index */);
+ mie_tag_variant(/* tag item */@ast::item, /* variant index */uint);
}
type mod_index = hashmap[ident, list[mod_index_entry]];
// A tuple of an imported def and the import stmt that brung it
-type glob_imp_def = rec(def def, @ast::view_item item);
+type glob_imp_def = {def: def, item: @ast::view_item};
type indexed_mod =
- rec(option::t[ast::_mod] m,
- mod_index index,
- mutable glob_imp_def[] glob_imports,
- hashmap[str, import_state] glob_imported_names);
+ {m: option::t[ast::_mod],
+ index: mod_index,
+ mutable glob_imports: glob_imp_def[],
+ glob_imported_names: hashmap[str, import_state]};
/* native modules can't contain tags, and we don't store their ASTs because we
@@ -111,15 +114,15 @@
type def_map = hashmap[node_id, def];
type env =
- rec(cstore::cstore cstore,
- def_map def_map,
- ast_map::map ast_map,
- hashmap[ast::node_id, import_state] imports,
- hashmap[ast::node_id, @indexed_mod] mod_map,
- hashmap[def_id, ident[]] ext_map,
- ext_hash ext_cache,
- mutable rec(str ident, scope sc)[] reported,
- session sess);
+ {cstore: cstore::cstore,
+ def_map: def_map,
+ ast_map: ast_map::map,
+ imports: hashmap[ast::node_id, import_state],
+ mod_map: hashmap[ast::node_id, @indexed_mod],
+ ext_map: hashmap[def_id, ident[]],
+ ext_cache: ext_hash,
+ mutable reported: {ident: str, sc: scope}[],
+ sess: session};
// Used to distinguish between lookups from outside and from inside modules,
@@ -128,18 +131,18 @@
tag namespace { ns_value; ns_type; ns_module; }
-fn resolve_crate(session sess, &ast_map::map amap, @ast::crate crate)
- -> def_map {
- auto e =
- @rec(cstore=sess.get_cstore(),
- def_map=new_int_hash[def](),
- ast_map=amap,
- imports=new_int_hash[import_state](),
- mod_map=new_int_hash[@indexed_mod](),
- ext_map=new_def_hash[ident[]](),
- ext_cache=new_ext_hash(),
- mutable reported=~[],
- sess=sess);
+fn resolve_crate(sess: session, amap: &ast_map::map, crate: @ast::crate) ->
+ def_map {
+ let e =
+ @{cstore: sess.get_cstore(),
+ def_map: new_int_hash[def](),
+ ast_map: amap,
+ imports: new_int_hash[import_state](),
+ mod_map: new_int_hash[@indexed_mod](),
+ ext_map: new_def_hash[ident[]](),
+ ext_cache: new_ext_hash(),
+ mutable reported: ~[],
+ sess: sess};
map_crate(e, crate);
resolve_imports(*e);
check_for_collisions(e, *crate);
@@ -150,325 +153,318 @@
// Locate all modules and imports and index them, so that the next passes can
// resolve through them.
-fn map_crate(&@env e, &@ast::crate c) {
+fn map_crate(e: &@env, c: &@ast::crate) {
// First, find all the modules, and index the names that they contain
- auto v_map_mod =
- @rec(visit_view_item=bind index_vi(e, _, _, _),
- visit_item=bind index_i(e, _, _, _)
- with *visit::default_visitor[scopes]());
- visit::visit_crate(*c, cons(scope_crate, @nil),
- visit::mk_vt(v_map_mod));
+ let v_map_mod =
+ @{visit_view_item: bind index_vi(e, _, _, _),
+ visit_item: bind index_i(e, _, _, _)
+ with *visit::default_visitor[scopes]()};
+ visit::visit_crate(*c, cons(scope_crate, @nil), visit::mk_vt(v_map_mod));
// Register the top-level mod
e.mod_map.insert(-1,
- @rec(m=some(c.node.module),
- index=index_mod(c.node.module),
- mutable glob_imports=~[],
- glob_imported_names=new_str_hash[import_state]()));
- fn index_vi(@env e, &@ast::view_item i, &scopes sc, &vt[scopes] v) {
- alt (i.node) {
- case (ast::view_item_import(_, ?ids, ?id)) {
- e.imports.insert(id, todo(i, sc));
- }
- case (_) { }
+ @{m: some(c.node.module),
+ index: index_mod(c.node.module),
+ mutable glob_imports: ~[],
+ glob_imported_names: new_str_hash[import_state]()});
+ fn index_vi(e: @env, i: &@ast::view_item, sc: &scopes, v: &vt[scopes]) {
+ alt i.node {
+ ast::view_item_import(_, ids, id) {
+ e.imports.insert(id, todo(i, sc));
+ }
+ _ { }
}
}
- fn index_i(@env e, &@ast::item i, &scopes sc, &vt[scopes] v) {
+ fn index_i(e: @env, i: &@ast::item, sc: &scopes, v: &vt[scopes]) {
visit_item_with_scope(i, sc, v);
- alt (i.node) {
- case (ast::item_mod(?md)) {
- auto s = new_str_hash[import_state]();
- e.mod_map.insert(i.id,
- @rec(m=some(md),
- index=index_mod(md),
- mutable glob_imports=~[],
- glob_imported_names=s));
- }
- case (ast::item_native_mod(?nmd)) {
- auto s = new_str_hash[import_state]();
- e.mod_map.insert(i.id,
- @rec(m=none[ast::_mod],
- index=index_nmod(nmd),
- mutable glob_imports=~[],
- glob_imported_names=s));
- }
- case (_) { }
+ alt i.node {
+ ast::item_mod(md) {
+ let s = new_str_hash[import_state]();
+ e.mod_map.insert(i.id,
+ @{m: some(md),
+ index: index_mod(md),
+ mutable glob_imports: ~[],
+ glob_imported_names: s});
+ }
+ ast::item_native_mod(nmd) {
+ let s = new_str_hash[import_state]();
+ e.mod_map.insert(i.id,
+ @{m: none[ast::_mod],
+ index: index_nmod(nmd),
+ mutable glob_imports: ~[],
+ glob_imported_names: s});
+ }
+ _ { }
}
}
// Next, assemble the links for globbed imports.
- auto v_link_glob =
- @rec(visit_view_item=bind link_glob(e, _, _, _),
- visit_item=visit_item_with_scope
- with *visit::default_visitor[scopes]());
+ let v_link_glob =
+ @{visit_view_item: bind link_glob(e, _, _, _),
+ visit_item: visit_item_with_scope
+ with *visit::default_visitor[scopes]()};
visit::visit_crate(*c, cons(scope_crate, @nil),
visit::mk_vt(v_link_glob));
- fn link_glob(@env e, &@ast::view_item vi, &scopes sc, &vt[scopes] v) {
- fn find_mod(@env e, scopes sc) -> @indexed_mod {
- alt (sc) {
- case (cons(scope_item(?i), ?tl)) {
- alt (i.node) {
- ast::item_mod(_) | ast::item_native_mod(_) {
- ret e.mod_map.get(i.id);
- }
- _ { be find_mod(e, *tl); }
- }
+ fn link_glob(e: @env, vi: &@ast::view_item, sc: &scopes, v: &vt[scopes]) {
+ fn find_mod(e: @env, sc: scopes) -> @indexed_mod {
+ alt sc {
+ cons(scope_item(i), tl) {
+ alt i.node {
+ ast::item_mod(_) | ast::item_native_mod(_) {
+ ret e.mod_map.get(i.id);
+ }
+ _ { be find_mod(e, *tl); }
}
- case (_) {
- ret e.mod_map.get(-1); //top-level
+ }
+ _ {
+ ret e.mod_map.get(-1); //top-level
- }
+ }
}
}
- alt (vi.node) {
- //if it really is a glob import, that is
- case (ast::view_item_import_glob(?path, _)) {
- auto imp = follow_import(*e, sc, path, vi.span);
- if (option::is_some(imp)) {
- find_mod(e, sc).glob_imports +=
- ~[rec(def=option::get(imp), item=vi)];
- }
+ alt vi.node {
+
+ //if it really is a glob import, that is
+ ast::view_item_import_glob(path, _) {
+ let imp = follow_import(*e, sc, path, vi.span);
+ if option::is_some(imp) {
+ find_mod(e, sc).glob_imports +=
+ ~[{def: option::get(imp), item: vi}];
}
- case (_) { }
+ }
+ _ { }
}
}
}
-fn resolve_imports(&env e) {
- for each (@rec(ast::node_id key, import_state val) it
- in e.imports.items()) {
- alt (it.val) {
- case (todo(?item, ?sc)) { resolve_import(e, item, sc); }
- case (resolved(_, _, _)) { }
+fn resolve_imports(e: &env) {
+ for each it: @{key: ast::node_id, val: import_state} in e.imports.items()
+ {
+ alt it.val {
+ todo(item, sc) { resolve_import(e, item, sc); }
+ resolved(_, _, _) { }
}
}
e.sess.abort_if_errors();
}
-fn resolve_names(&@env e, &@ast::crate c) {
- auto v =
- @rec(visit_native_item=visit_native_item_with_scope,
- visit_item=visit_item_with_scope,
- visit_block=visit_block_with_scope,
- visit_arm=bind walk_arm(e, _, _, _),
- visit_expr=bind walk_expr(e, _, _, _),
- visit_ty=bind walk_ty(e, _, _, _),
- visit_constr=bind walk_constr(e, _, _, _, _, _),
- visit_fn=bind visit_fn_with_scope(e, _, _, _, _, _, _, _)
- with *visit::default_visitor());
+fn resolve_names(e: &@env, c: &@ast::crate) {
+ let v =
+ @{visit_native_item: visit_native_item_with_scope,
+ visit_item: visit_item_with_scope,
+ visit_block: visit_block_with_scope,
+ visit_arm: bind walk_arm(e, _, _, _),
+ visit_expr: bind walk_expr(e, _, _, _),
+ visit_ty: bind walk_ty(e, _, _, _),
+ visit_constr: bind walk_constr(e, _, _, _, _, _),
+ visit_fn: bind visit_fn_with_scope(e, _, _, _, _, _, _, _)
+ with *visit::default_visitor()};
visit::visit_crate(*c, cons(scope_crate, @nil), visit::mk_vt(v));
e.sess.abort_if_errors();
- fn walk_expr(@env e, &@ast::expr exp, &scopes sc, &vt[scopes] v) {
+ fn walk_expr(e: @env, exp: &@ast::expr, sc: &scopes, v: &vt[scopes]) {
visit_expr_with_scope(exp, sc, v);
- alt (exp.node) {
- case (ast::expr_path(?p)) {
- maybe_insert(e, exp.id,
- lookup_path_strict(*e, sc, exp.span, p.node,
- ns_value));
- }
- case (_) { }
+ alt exp.node {
+ ast::expr_path(p) {
+ maybe_insert(e, exp.id,
+ lookup_path_strict(*e, sc, exp.span, p.node,
+ ns_value));
+ }
+ _ { }
}
}
- fn walk_ty(@env e, &@ast::ty t, &scopes sc, &vt[scopes] v) {
+ fn walk_ty(e: @env, t: &@ast::ty, sc: &scopes, v: &vt[scopes]) {
visit::visit_ty(t, sc, v);
- alt (t.node) {
- case (ast::ty_path(?p, ?id)) {
- maybe_insert(e, id,
- lookup_path_strict(*e, sc, t.span, p.node,
- ns_type));
- }
- case (_) { }
+ alt t.node {
+ ast::ty_path(p, id) {
+ maybe_insert(e, id,
+ lookup_path_strict(*e, sc, t.span, p.node, ns_type));
+ }
+ _ { }
}
}
- fn walk_constr(@env e, &ast::path p, &span sp, node_id id,
- &scopes sc, &vt[scopes] v) {
+ fn walk_constr(e: @env, p: &ast::path, sp: &span, id: node_id,
+ sc: &scopes, v: &vt[scopes]) {
maybe_insert(e, id, lookup_path_strict(*e, sc, sp, p.node, ns_value));
}
- fn walk_arm(@env e, &ast::arm a, &scopes sc, &vt[scopes] v) {
- for (@ast::pat p in a.pats) { walk_pat(*e, sc, p); }
+ fn walk_arm(e: @env, a: &ast::arm, sc: &scopes, v: &vt[scopes]) {
+ for p: @ast::pat in a.pats { walk_pat(*e, sc, p); }
visit_arm_with_scope(a, sc, v);
}
- fn walk_pat(&env e, &scopes sc, &@ast::pat pat) {
- alt (pat.node) {
- case (ast::pat_tag(?p, ?children)) {
- auto fnd =
- lookup_path_strict(e, sc, p.span, p.node, ns_value);
- if (option::is_some(fnd)) {
- alt (option::get(fnd)) {
- case (ast::def_variant(?did, ?vid)) {
- e.def_map.insert(pat.id, option::get(fnd));
- for (@ast::pat child in children) {
- walk_pat(e, sc, child);
- }
- }
- case (_) {
- e.sess.span_err(p.span,
- "not a tag variant: " +
- ast::path_name(p));
- }
+ fn walk_pat(e: &env, sc: &scopes, pat: &@ast::pat) {
+ alt pat.node {
+ ast::pat_tag(p, children) {
+ let fnd = lookup_path_strict(e, sc, p.span, p.node, ns_value);
+ if option::is_some(fnd) {
+ alt option::get(fnd) {
+ ast::def_variant(did, vid) {
+ e.def_map.insert(pat.id, option::get(fnd));
+ for child: @ast::pat in children {
+ walk_pat(e, sc, child);
}
+ }
+ _ {
+ e.sess.span_err(p.span,
+ "not a tag variant: " +
+ ast::path_name(p));
+ }
}
}
- case (ast::pat_rec(?fields, _)) {
- for (ast::field_pat f in fields) { walk_pat(e, sc, f.pat); }
- }
- case (ast::pat_box(?inner)) { walk_pat(e, sc, inner); }
- case (_) { }
+ }
+ ast::pat_rec(fields, _) {
+ for f: ast::field_pat in fields { walk_pat(e, sc, f.pat); }
+ }
+ ast::pat_box(inner) { walk_pat(e, sc, inner); }
+ _ { }
}
}
- fn maybe_insert(@env e, node_id id,
- option::t[def] def) {
- if (option::is_some(def)) {
- e.def_map.insert(id, option::get(def));
- }
+ fn maybe_insert(e: @env, id: node_id, def: option::t[def]) {
+ if option::is_some(def) { e.def_map.insert(id, option::get(def)); }
}
}
// Visit helper functions
-fn visit_item_with_scope(&@ast::item i, &scopes sc, &vt[scopes] v) {
+fn visit_item_with_scope(i: &@ast::item, sc: &scopes, v: &vt[scopes]) {
visit::visit_item(i, cons(scope_item(i), @sc), v);
}
-fn visit_native_item_with_scope(&@ast::native_item ni, &scopes sc,
- &vt[scopes] v) {
+fn visit_native_item_with_scope(ni: &@ast::native_item, sc: &scopes,
+ v: &vt[scopes]) {
visit::visit_native_item(ni, cons(scope_native_item(ni), @sc), v);
}
-fn visit_fn_with_scope(&@env e, &ast::_fn f, &ast::ty_param[] tp, &span sp,
- &fn_ident name, node_id id, &scopes sc,
- &vt[scopes] v) {
+fn visit_fn_with_scope(e: &@env, f: &ast::_fn, tp: &ast::ty_param[],
+ sp: &span, name: &fn_ident, id: node_id, sc: &scopes,
+ v: &vt[scopes]) {
// is this a main fn declaration?
- alt (name) {
- case (some(?nm)) {
- if (is_main_name(~[nm]) && !e.sess.get_opts().library) {
- // This is a main function -- set it in the session
- // as the main ID
- e.sess.set_main_id(id);
- }
+ alt name {
+ some(nm) {
+ if is_main_name(~[nm]) && !e.sess.get_opts().library {
+ // This is a main function -- set it in the session
+ // as the main ID
+ e.sess.set_main_id(id);
}
- case (_) {}
+ }
+ _ { }
}
// here's where we need to set up the mapping
// for f's constrs in the table.
- for (@ast::constr c in f.decl.constraints) {
+ for c: @ast::constr in f.decl.constraints {
resolve_constr(e, id, c, sc, v);
}
visit::visit_fn(f, tp, sp, name, id,
cons(scope_fn(f.decl, f.proto, tp), @sc), v);
}
-fn visit_block_with_scope(&ast::blk b, &scopes sc, &vt[scopes] v) {
+fn visit_block_with_scope(b: &ast::blk, sc: &scopes, v: &vt[scopes]) {
visit::visit_block(b, cons(scope_block(b), @sc), v);
}
-fn visit_arm_with_scope(&ast::arm a, &scopes sc, &vt[scopes] v) {
+fn visit_arm_with_scope(a: &ast::arm, sc: &scopes, v: &vt[scopes]) {
visit::visit_arm(a, cons(scope_arm(a), @sc), v);
}
-fn visit_expr_with_scope(&@ast::expr x, &scopes sc, &vt[scopes] v) {
- alt (x.node) {
- ast::expr_for(?decl, ?coll, ?blk) |
- ast::expr_for_each(?decl, ?coll, ?blk) {
- auto new_sc = cons[scope](scope_loop(decl), @sc);
+fn visit_expr_with_scope(x: &@ast::expr, sc: &scopes, v: &vt[scopes]) {
+ alt x.node {
+ ast::expr_for(decl, coll, blk) | ast::expr_for_each(decl, coll, blk) {
+ let new_sc = cons[scope](scope_loop(decl), @sc);
v.visit_expr(coll, sc, v);
v.visit_local(decl, new_sc, v);
v.visit_block(blk, new_sc, v);
}
- ast::expr_fn(?f) {
+ ast::expr_fn(f) {
visit::visit_expr(x, cons(scope_fn(f.decl, f.proto, ~[]), @sc), v);
}
_ { visit::visit_expr(x, sc, v); }
- };
+ }
}
-fn follow_import(&env e, &scopes sc, &ident[] path, &span sp)
- -> option::t[def] {
- auto path_len = ivec::len(path);
- auto dcur = lookup_in_scope_strict(e, sc, sp, path.(0), ns_module);
- auto i = 1u;
- while (true && option::is_some(dcur)) {
- if (i == path_len) { break; }
- dcur = lookup_in_mod_strict(e, sc, option::get(dcur),
- sp, path.(i), ns_module, outside);
+fn follow_import(e: &env, sc: &scopes, path: &ident[], sp: &span) ->
+ option::t[def] {
+ let path_len = ivec::len(path);
+ let dcur = lookup_in_scope_strict(e, sc, sp, path.(0), ns_module);
+ let i = 1u;
+ while true && option::is_some(dcur) {
+ if i == path_len { break; }
+ dcur =
+ lookup_in_mod_strict(e, sc, option::get(dcur), sp, path.(i),
+ ns_module, outside);
i += 1u;
}
- if (i == path_len) {
- alt (option::get(dcur)) {
- ast::def_mod(_) | ast::def_native_mod(_) { ret dcur; }
- _ {
- e.sess.span_err(sp, str::connect_ivec(path, "::") +
+ if i == path_len {
+ alt option::get(dcur) {
+ ast::def_mod(_) | ast::def_native_mod(_) { ret dcur; }
+ _ {
+ e.sess.span_err(sp,
+ str::connect_ivec(path, "::") +
" does not name a module.");
- ret none;
- }
+ ret none;
+ }
}
- } else {
- ret none;
- }
+ } else { ret none; }
}
-fn resolve_constr(@env e, node_id id, &@ast::constr c, &scopes sc,
- &vt[scopes] v) {
- auto new_def =
+fn resolve_constr(e: @env, id: node_id, c: &@ast::constr, sc: &scopes,
+ v: &vt[scopes]) {
+ let new_def =
lookup_path_strict(*e, sc, c.span, c.node.path.node, ns_value);
- if (option::is_some(new_def)) {
- alt (option::get(new_def)) {
- case (ast::def_fn(?pred_id, ast::pure_fn)) {
- e.def_map.insert(c.node.id, ast::def_fn(pred_id,
- ast::pure_fn));
- }
- case (_) {
- e.sess.span_err(c.span,
- "Non-predicate in constraint: " +
+ if option::is_some(new_def) {
+ alt option::get(new_def) {
+ ast::def_fn(pred_id, ast::pure_fn.) {
+ e.def_map.insert(c.node.id, ast::def_fn(pred_id, ast::pure_fn));
+ }
+ _ {
+ e.sess.span_err(c.span,
+ "Non-predicate in constraint: " +
path_to_str(c.node.path));
- }
+ }
}
}
}
// Import resolution
-fn resolve_import(&env e, &@ast::view_item it, &scopes sc_in) {
- auto defid;
- auto ids;
- auto name;
- alt (it.node) {
- case (ast::view_item_import(?_name, ?_ids, ?_id)) {
- defid = local_def(_id);
- ids = _ids;
- name = _name;
- }
+fn resolve_import(e: &env, it: &@ast::view_item, sc_in: &scopes) {
+ let defid;
+ let ids;
+ let name;
+ alt it.node {
+ ast::view_item_import(_name, _ids, _id) {
+ defid = local_def(_id);
+ ids = _ids;
+ name = _name;
+ }
}
e.imports.insert(defid.node, resolving(it.span));
- auto n_idents = ivec::len(ids);
- auto end_id = ids.(n_idents - 1u);
+ let n_idents = ivec::len(ids);
+ let end_id = ids.(n_idents - 1u);
// Ignore the current scope if this import would shadow itself.
- auto sc = if str::eq(name, ids.(0)) { std::list::cdr(sc_in) }
- else { sc_in };
- if (n_idents == 1u) {
+ let sc =
+ if str::eq(name, ids.(0)) { std::list::cdr(sc_in) } else { sc_in };
+ if n_idents == 1u {
register(e, defid, it.span, end_id, sc_in,
lookup_in_scope(e, sc, it.span, end_id, ns_value),
lookup_in_scope(e, sc, it.span, end_id, ns_type),
lookup_in_scope(e, sc, it.span, end_id, ns_module));
remove_if_unresolved(e.imports, defid.node);
} else {
- auto dcur = alt(lookup_in_scope(e, sc, it.span, ids.(0), ns_module)) {
- case (some(?dcur)) {
- dcur
- }
- case (none) {
+ let // FIXME (issue #521)
+ dcur =
+ alt lookup_in_scope(e, sc, it.span, ids.(0), ns_module) {
+ some(dcur) { dcur }
+ none. {
unresolved_err(e, sc, it.span, ids.(0), ns_name(ns_module));
remove_if_unresolved(e.imports, defid.node);
- ret () // FIXME (issue #521)
- }
- };
- auto i = 1u;
- while (true) {
- if (i == n_idents - 1u) {
+ ret ()
+ }
+ };
+ let i = 1u;
+ while true {
+ if i == n_idents - 1u {
register(e, defid, it.span, end_id, sc_in,
lookup_in_mod(e, dcur, it.span, end_id, ns_value,
outside),
@@ -479,42 +475,38 @@
remove_if_unresolved(e.imports, defid.node);
break;
} else {
- dcur = alt (lookup_in_mod(e, dcur, it.span, ids.(i),
- ns_module, outside)) {
- case (some(?dcur)) {
- dcur
- }
- case (none) {
+ dcur =
+ alt lookup_in_mod(e, dcur, it.span, ids.(i), ns_module,
+ outside) {
+ some(dcur) { dcur }
+ none. {
unresolved_err(e, sc, it.span, ids.(i),
ns_name(ns_module));
remove_if_unresolved(e.imports, defid.node);
ret () // FIXME (issue #521)
- }
- };
+ }
+ };
i += 1u;
}
}
}
- fn register(&env e, def_id defid, &span sp, &ident name, &scopes sc,
- &option::t[def] val, &option::t[def] typ,
- &option::t[def] md) {
+ fn register(e: &env, defid: def_id, sp: &span, name: &ident, sc: &scopes,
+ val: &option::t[def], typ: &option::t[def],
+ md: &option::t[def]) {
if is_none(val) && is_none(typ) && is_none(md) {
unresolved_err(e, sc, sp, name, "import");
- } else {
- e.imports.insert(defid.node, resolved(val, typ, md));
- }
+ } else { e.imports.insert(defid.node, resolved(val, typ, md)); }
}
- fn remove_if_unresolved(hashmap[ast::node_id, import_state] imports,
- ast::node_id node_id) {
+ fn remove_if_unresolved(imports: hashmap[ast::node_id, import_state],
+ node_id: ast::node_id) {
+
// If we couldn't resolve the import, don't leave it in a partially
// resolved state, to avoid having it reported later as a cyclic
// import
- if (imports.contains_key(node_id)) {
- alt (imports.get(node_id)) {
- case (resolving(_)) {
- imports.remove(node_id);
- }
- case (_) { }
+ if imports.contains_key(node_id) {
+ alt imports.get(node_id) {
+ resolving(_) { imports.remove(node_id); }
+ _ { }
}
}
}
@@ -522,21 +514,21 @@
// Utilities
-fn ns_name(namespace ns) -> str {
- alt (ns) {
- case (ns_type) { ret "typename"; }
- case (ns_value) { ret "name"; }
- case (ns_module) { ret "modulename"; }
+fn ns_name(ns: namespace) -> str {
+ alt ns {
+ ns_type. { ret "typename"; }
+ ns_value. { ret "name"; }
+ ns_module. { ret "modulename"; }
}
}
-fn unresolved_err(&env e, &scopes sc, &span sp, &ident name, &str kind) {
- fn find_fn_or_mod_scope(scopes sc) -> scope {
+fn unresolved_err(e: &env, sc: &scopes, sp: &span, name: &ident, kind: &str) {
+ fn find_fn_or_mod_scope(sc: scopes) -> scope {
while true {
alt sc {
- cons(?cur, ?rest) {
+ cons(cur, rest) {
alt cur {
- scope_crate | scope_fn(_, _, _) |
+ scope_crate. | scope_fn(_, _, _) |
scope_item(@{node: ast::item_mod(_), _}) {
ret cur;
}
@@ -547,617 +539,582 @@
}
fail;
}
- auto err_scope = find_fn_or_mod_scope(sc);
- for (rec(str ident, scope sc) rs in e.reported) {
+ let err_scope = find_fn_or_mod_scope(sc);
+ for rs: {ident: str, sc: scope} in e.reported {
if str::eq(rs.ident, name) && err_scope == rs.sc { ret; }
}
- e.reported += ~[rec(ident=name, sc=err_scope)];
+ e.reported += ~[{ident: name, sc: err_scope}];
e.sess.span_err(sp, mk_unresolved_msg(name, kind));
}
-fn unresolved_fatal(&env e, &span sp, &ident id, &str kind) -> ! {
+fn unresolved_fatal(e: &env, sp: &span, id: &ident, kind: &str) -> ! {
e.sess.span_fatal(sp, mk_unresolved_msg(id, kind));
}
-fn mk_unresolved_msg(&ident id, &str kind) -> str {
+fn mk_unresolved_msg(id: &ident, kind: &str) -> str {
ret #fmt("unresolved %s: %s", kind, id);
}
// Lookup helpers
-fn lookup_path_strict(&env e, &scopes sc, &span sp, &ast::path_ pth,
- namespace ns) -> option::t[def] {
- auto n_idents = ivec::len(pth.idents);
- auto headns = if (n_idents == 1u) { ns } else { ns_module };
+fn lookup_path_strict(e: &env, sc: &scopes, sp: &span, pth: &ast::path_,
+ ns: namespace) -> option::t[def] {
+ let n_idents = ivec::len(pth.idents);
+ let headns = if n_idents == 1u { ns } else { ns_module };
- auto first_scope;
- if (pth.global) {
+ let first_scope;
+ if pth.global {
first_scope = list::cons(scope_crate, @list::nil);
- } else {
- first_scope = sc;
- }
+ } else { first_scope = sc; }
- auto dcur = lookup_in_scope_strict(e, first_scope, sp, pth.idents.(0),
- headns);
+ let dcur =
+ lookup_in_scope_strict(e, first_scope, sp, pth.idents.(0), headns);
- auto i = 1u;
- while (i < n_idents && option::is_some(dcur)) {
- auto curns = if (n_idents == i + 1u) { ns } else { ns_module };
- dcur = lookup_in_mod_strict(e, sc, option::get(dcur),
- sp, pth.idents.(i), curns, outside);
+ let i = 1u;
+ while i < n_idents && option::is_some(dcur) {
+ let curns = if n_idents == i + 1u { ns } else { ns_module };
+ dcur =
+ lookup_in_mod_strict(e, sc, option::get(dcur), sp, pth.idents.(i),
+ curns, outside);
i += 1u;
}
ret dcur;
}
-fn lookup_in_scope_strict(&env e, scopes sc, &span sp, &ident name,
- namespace ns) -> option::t[def] {
- alt (lookup_in_scope(e, sc, sp, name, ns)) {
- case (none) {
- unresolved_err(e, sc, sp, name, ns_name(ns));
- ret none;
- }
- case (some(?d)) { ret some(d); }
+fn lookup_in_scope_strict(e: &env, sc: scopes, sp: &span, name: &ident,
+ ns: namespace) -> option::t[def] {
+ alt lookup_in_scope(e, sc, sp, name, ns) {
+ none. { unresolved_err(e, sc, sp, name, ns_name(ns)); ret none; }
+ some(d) { ret some(d); }
}
}
-fn scope_is_fn(&scope sc) -> bool {
- ret alt (sc) {
- scope_fn(_, ast::proto_iter, _) |
- scope_fn(_, ast::proto_fn, _) |
- scope_native_item(_) { true }
- _ { false }
- };
+fn scope_is_fn(sc: &scope) -> bool {
+ ret alt sc {
+ scope_fn(_, ast::proto_iter., _) | scope_fn(_, ast::proto_fn., _) |
+ scope_native_item(_) {
+ true
+ }
+ _ { false }
+ };
}
-fn def_is_local(&def d) -> bool {
- ret alt (d) {
- ast::def_arg(_) | ast::def_local(_) | ast::def_binding(_) { true }
- _ { false }
- };
+fn def_is_local(d: &def) -> bool {
+ ret alt d {
+ ast::def_arg(_) | ast::def_local(_) | ast::def_binding(_) { true }
+ _ { false }
+ };
}
-fn def_is_obj_field(&def d) -> bool {
- ret alt (d) { case (ast::def_obj_field(_)) { true } case (_) { false } };
+fn def_is_obj_field(d: &def) -> bool {
+ ret alt d { ast::def_obj_field(_) { true } _ { false } };
}
-fn def_is_ty_arg(&def d) -> bool {
- ret alt(d) { case (ast::def_ty_arg(_)) { true } case (_) { false } };
+fn def_is_ty_arg(d: &def) -> bool {
+ ret alt d { ast::def_ty_arg(_) { true } _ { false } };
}
-fn lookup_in_scope(&env e, scopes sc, &span sp, &ident name, namespace ns) ->
- option::t[def] {
- fn in_scope(&env e, &span sp, &ident name, &scope s, namespace ns) ->
+fn lookup_in_scope(e: &env, sc: scopes, sp: &span, name: &ident,
+ ns: namespace) -> option::t[def] {
+ fn in_scope(e: &env, sp: &span, name: &ident, s: &scope, ns: namespace) ->
option::t[def] {
- alt (s) {
- case (scope_crate) {
- ret lookup_in_local_mod(e, -1, sp, name, ns, inside);
+ alt s {
+ scope_crate. {
+ ret lookup_in_local_mod(e, -1, sp, name, ns, inside);
+ }
+ scope_item(it) {
+ alt it.node {
+ ast::item_obj(ob, ty_params, _) {
+ ret lookup_in_obj(name, ob, ty_params, ns);
+ }
+ ast::item_tag(_, ty_params) {
+ if ns == ns_type { ret lookup_in_ty_params(name, ty_params); }
+ }
+ ast::item_mod(_) {
+ ret lookup_in_local_mod(e, it.id, sp, name, ns, inside);
+ }
+ ast::item_native_mod(m) {
+ ret lookup_in_local_native_mod(e, it.id, sp, name, ns);
+ }
+ ast::item_ty(_, ty_params) {
+ if ns == ns_type { ret lookup_in_ty_params(name, ty_params); }
+ }
+ _ { }
}
- case (scope_item(?it)) {
- alt (it.node) {
- case (ast::item_obj(?ob, ?ty_params, _)) {
- ret lookup_in_obj(name, ob, ty_params, ns);
- }
- case (ast::item_tag(_, ?ty_params)) {
- if (ns == ns_type) {
- ret lookup_in_ty_params(name, ty_params);
- }
- }
- case (ast::item_mod(_)) {
- ret lookup_in_local_mod
- (e, it.id, sp, name, ns, inside);
- }
- case (ast::item_native_mod(?m)) {
- ret lookup_in_local_native_mod
- (e, it.id, sp, name, ns);
- }
- case (ast::item_ty(_, ?ty_params)) {
- if (ns == ns_type) {
- ret lookup_in_ty_params(name, ty_params);
- }
- }
- case (_) { }
- }
- }
- case (scope_native_item(?it)) {
- alt (it.node) {
- case (ast::native_item_fn(_, ?decl, ?ty_params)) {
- ret lookup_in_fn(name, decl, ty_params, ns);
- }
- }
- }
- case (scope_fn(?decl, _, ?ty_params)) {
+ }
+ scope_native_item(it) {
+ alt it.node {
+ ast::native_item_fn(_, decl, ty_params) {
ret lookup_in_fn(name, decl, ty_params, ns);
+ }
}
- case (scope_loop(?local)) {
- if (ns == ns_value) {
- if (str::eq(local.node.ident, name)) {
- ret some(ast::def_local(local_def(local.node.id)));
- }
+ }
+ scope_fn(decl, _, ty_params) {
+ ret lookup_in_fn(name, decl, ty_params, ns);
+ }
+ scope_loop(local) {
+ if ns == ns_value {
+ if str::eq(local.node.ident, name) {
+ ret some(ast::def_local(local_def(local.node.id)));
}
}
- case (scope_block(?b)) { ret lookup_in_block(name, b.node, ns); }
- case (scope_arm(?a)) {
- if (ns == ns_value) { ret lookup_in_pat(name, *a.pats.(0)); }
- }
+ }
+ scope_block(b) { ret lookup_in_block(name, b.node, ns); }
+ scope_arm(a) {
+ if ns == ns_value { ret lookup_in_pat(name, *a.pats.(0)); }
+ }
}
ret none[def];
}
- auto left_fn = false;
+ let left_fn = false;
// Used to determine whether obj fields are in scope
- auto left_fn_level2 = false;
- while (true) {
- alt ({ sc }) {
- case (nil) { ret none[def]; }
- case (cons(?hd, ?tl)) {
- auto fnd = in_scope(e, sp, name, hd, ns);
- if (!is_none(fnd)) {
- auto df = option::get(fnd);
- if (left_fn && def_is_local(df) ||
- left_fn_level2 && def_is_obj_field(df)
- || (scope_is_fn(hd) && left_fn
- && def_is_ty_arg(df))) {
- auto msg = alt (ns) {
- case (ns_type) {
- "Attempt to use a type \
+ let left_fn_level2 = false;
+ while true {
+ alt { sc } {
+ nil. { ret none[def]; }
+ cons(hd, tl) {
+ let fnd = in_scope(e, sp, name, hd, ns);
+ if !is_none(fnd) {
+ let df = option::get(fnd);
+ if left_fn && def_is_local(df) ||
+ left_fn_level2 && def_is_obj_field(df) ||
+ scope_is_fn(hd) && left_fn && def_is_ty_arg(df) {
+ let msg =
+ alt ns {
+ ns_type. {
+ "Attempt to use a type \
argument out of scope"
- }
- case (_) { "attempted dynamic \
- environment-capture" }
+ }
+ _ {
+ "attempted dynamic \
+ environment-capture"
+ }
};
- e.sess.span_fatal(sp, msg);
- }
- ret fnd;
+ e.sess.span_fatal(sp, msg);
}
- if (left_fn) { left_fn_level2 = true; }
- if ((ns == ns_value || ns == ns_type) && !left_fn) {
- left_fn = scope_is_fn(hd); }
- sc = *tl;
+ ret fnd;
}
+ if left_fn { left_fn_level2 = true; }
+ if (ns == ns_value || ns == ns_type) && !left_fn {
+ left_fn = scope_is_fn(hd);
+ }
+ sc = *tl;
+ }
}
}
e.sess.bug("reached unreachable code in lookup_in_scope"); // sigh
}
-fn lookup_in_ty_params(&ident name, &ast::ty_param[] ty_params) ->
+fn lookup_in_ty_params(name: &ident, ty_params: &ast::ty_param[]) ->
option::t[def] {
- auto i = 0u;
- for (ast::ty_param tp in ty_params) {
- if (str::eq(tp, name)) { ret some(ast::def_ty_arg(i)); }
+ let i = 0u;
+ for tp: ast::ty_param in ty_params {
+ if str::eq(tp, name) { ret some(ast::def_ty_arg(i)); }
i += 1u;
}
ret none[def];
}
-fn lookup_in_pat(&ident name, &ast::pat pat) -> option::t[def] {
- alt (pat.node) {
- case (ast::pat_bind(?p_name)) {
- if (str::eq(p_name, name)) {
- ret some(ast::def_binding(local_def(pat.id)));
- }
+fn lookup_in_pat(name: &ident, pat: &ast::pat) -> option::t[def] {
+ alt pat.node {
+ ast::pat_bind(p_name) {
+ if str::eq(p_name, name) {
+ ret some(ast::def_binding(local_def(pat.id)));
}
- case (ast::pat_wild) { }
- case (ast::pat_lit(_)) { }
- case (ast::pat_tag(_, ?pats)) {
- for (@ast::pat p in pats) {
- auto found = lookup_in_pat(name, *p);
- if (!is_none(found)) { ret found; }
- }
+ }
+ ast::pat_wild. { }
+ ast::pat_lit(_) { }
+ ast::pat_tag(_, pats) {
+ for p: @ast::pat in pats {
+ let found = lookup_in_pat(name, *p);
+ if !is_none(found) { ret found; }
}
- case (ast::pat_rec(?fields, _)) {
- for (ast::field_pat f in fields) {
- auto found = lookup_in_pat(name, *f.pat);
- if (!is_none(found)) { ret found; }
- }
+ }
+ ast::pat_rec(fields, _) {
+ for f: ast::field_pat in fields {
+ let found = lookup_in_pat(name, *f.pat);
+ if !is_none(found) { ret found; }
}
- case (ast::pat_box(?inner)) { ret lookup_in_pat(name, *inner); }
+ }
+ ast::pat_box(inner) { ret lookup_in_pat(name, *inner); }
}
ret none[def];
}
-fn lookup_in_fn(&ident name, &ast::fn_decl decl,
- &ast::ty_param[] ty_params,
- namespace ns) -> option::t[def] {
- alt (ns) {
- case (ns_value) {
- for (ast::arg a in decl.inputs) {
- if (str::eq(a.ident, name)) {
- ret some(ast::def_arg(local_def(a.id)));
- }
- }
- ret none[def];
- }
- case (ns_type) { ret lookup_in_ty_params(name, ty_params); }
- case (_) { ret none[def]; }
- }
-}
-
-fn lookup_in_obj(&ident name, &ast::_obj ob, &ast::ty_param[] ty_params,
- namespace ns) -> option::t[def] {
- alt (ns) {
- case (ns_value) {
- for (ast::obj_field f in ob.fields) {
- if (str::eq(f.ident, name)) {
- ret some(ast::def_obj_field(local_def(f.id)));
- }
- }
- ret none[def];
- }
- case (ns_type) { ret lookup_in_ty_params(name, ty_params); }
- case (_) { ret none[def]; }
- }
-}
-
-fn lookup_in_block(&ident name, &ast::blk_ b, namespace ns) ->
+fn lookup_in_fn(name: &ident, decl: &ast::fn_decl,
+ ty_params: &ast::ty_param[], ns: namespace) ->
option::t[def] {
- for (@ast::stmt st in b.stmts) {
- alt (st.node) {
- case (ast::stmt_decl(?d, _)) {
- alt (d.node) {
- ast::decl_local(?locs) {
- for (@ast::local loc in locs) {
- if ns == ns_value && str::eq(name, loc.node.ident) {
- ret some(ast::def_local
- (local_def(loc.node.id)));
- }
- }
+ alt ns {
+ ns_value. {
+ for a: ast::arg in decl.inputs {
+ if str::eq(a.ident, name) {
+ ret some(ast::def_arg(local_def(a.id)));
+ }
+ }
+ ret none[def];
+ }
+ ns_type. { ret lookup_in_ty_params(name, ty_params); }
+ _ { ret none[def]; }
+ }
+}
+
+fn lookup_in_obj(name: &ident, ob: &ast::_obj, ty_params: &ast::ty_param[],
+ ns: namespace) -> option::t[def] {
+ alt ns {
+ ns_value. {
+ for f: ast::obj_field in ob.fields {
+ if str::eq(f.ident, name) {
+ ret some(ast::def_obj_field(local_def(f.id)));
+ }
+ }
+ ret none[def];
+ }
+ ns_type. { ret lookup_in_ty_params(name, ty_params); }
+ _ { ret none[def]; }
+ }
+}
+
+fn lookup_in_block(name: &ident, b: &ast::blk_, ns: namespace) ->
+ option::t[def] {
+ for st: @ast::stmt in b.stmts {
+ alt st.node {
+ ast::stmt_decl(d, _) {
+ alt d.node {
+ ast::decl_local(locs) {
+ for loc: @ast::local in locs {
+ if ns == ns_value && str::eq(name, loc.node.ident) {
+ ret some(ast::def_local(local_def(loc.node.id)));
}
- case (ast::decl_item(?it)) {
- alt (it.node) {
- case (ast::item_tag(?variants, _)) {
- if (ns == ns_type) {
- if (str::eq(it.ident, name)) {
- ret some(ast::def_ty
- (local_def(it.id)));
- }
- } else if (ns == ns_value) {
- for (ast::variant v in variants) {
- if (str::eq(v.node.name, name)) {
- auto i = v.node.id;
- ret some(ast::def_variant
- (local_def(it.id),
- local_def(i)));
- }
- }
- }
- }
- case (_) {
- if (str::eq(it.ident, name)) {
- auto found = found_def_item(it, ns);
- if (!is_none(found)) {
- ret found;
- }
- }
+ }
+ }
+ ast::decl_item(it) {
+ alt it.node {
+ ast::item_tag(variants, _) {
+ if ns == ns_type {
+ if str::eq(it.ident, name) {
+ ret some(ast::def_ty(local_def(it.id)));
+ }
+ } else if (ns == ns_value) {
+ for v: ast::variant in variants {
+ if str::eq(v.node.name, name) {
+ let i = v.node.id;
+ ret some(ast::def_variant(local_def(it.id),
+ local_def(i)));
}
}
}
+ }
+ _ {
+ if str::eq(it.ident, name) {
+ let found = found_def_item(it, ns);
+ if !is_none(found) { ret found; }
+ }
+ }
}
+ }
}
- case (_) { }
+ }
+ _ { }
}
}
ret none[def];
}
-fn found_def_item(&@ast::item i, namespace ns) -> option::t[def] {
- alt (i.node) {
- case (ast::item_const(_, _)) {
- if (ns == ns_value) {
- ret some(ast::def_const(local_def(i.id)));
- }
+fn found_def_item(i: &@ast::item, ns: namespace) -> option::t[def] {
+ alt i.node {
+ ast::item_const(_, _) {
+ if ns == ns_value { ret some(ast::def_const(local_def(i.id))); }
+ }
+ ast::item_fn(f, _) {
+ if ns == ns_value {
+ ret some(ast::def_fn(local_def(i.id), f.decl.purity));
}
- case (ast::item_fn(?f, _)) {
- if (ns == ns_value) {
- ret some(ast::def_fn(local_def(i.id), f.decl.purity));
- }
+ }
+ ast::item_mod(_) {
+ if ns == ns_module { ret some(ast::def_mod(local_def(i.id))); }
+ }
+ ast::item_native_mod(_) {
+ if ns == ns_module { ret some(ast::def_native_mod(local_def(i.id))); }
+ }
+ ast::item_ty(_, _) {
+ if ns == ns_type { ret some(ast::def_ty(local_def(i.id))); }
+ }
+ ast::item_res(_, _, _, ctor_id) {
+ alt ns {
+ ns_value. {
+ ret some(ast::def_fn(local_def(ctor_id), ast::impure_fn));
+ }
+ ns_type. { ret some(ast::def_ty(local_def(i.id))); }
+ _ { }
}
- case (ast::item_mod(_)) {
- if (ns == ns_module) {
- ret some(ast::def_mod(local_def(i.id)));
- }
+ }
+ ast::item_tag(_, _) {
+ if ns == ns_type { ret some(ast::def_ty(local_def(i.id))); }
+ }
+ ast::item_obj(_, _, ctor_id) {
+ alt ns {
+ ns_value. {
+ ret some(ast::def_fn(local_def(ctor_id), ast::impure_fn));
+ }
+ ns_type. { ret some(ast::def_ty(local_def(i.id))); }
+ _ { }
}
- case (ast::item_native_mod(_)) {
- if (ns == ns_module) {
- ret some(ast::def_native_mod(local_def(i.id)));
- }
- }
- case (ast::item_ty(_, _)) {
- if (ns == ns_type) {
- ret some(ast::def_ty(local_def(i.id)));
- }
- }
- case (ast::item_res(_, _, _, ?ctor_id)) {
- alt (ns) {
- case (ns_value) { ret some(ast::def_fn(local_def(ctor_id),
- ast::impure_fn)); }
- case (ns_type) { ret some(ast::def_ty(local_def(i.id))); }
- case (_) { }
- }
- }
- case (ast::item_tag(_, _)) {
- if (ns == ns_type) {
- ret some(ast::def_ty(local_def(i.id)));
- }
- }
- case (ast::item_obj(_, _, ?ctor_id)) {
- alt (ns) {
- case (ns_value) { ret some(ast::def_fn(local_def(ctor_id),
- ast::impure_fn)); }
- case (ns_type) { ret some(ast::def_ty(local_def(i.id))); }
- case (_) { }
- }
- }
- case (_) { }
+ }
+ _ { }
}
ret none[def];
}
-fn lookup_in_mod_strict(&env e, &scopes sc, def m, &span sp, &ident name,
- namespace ns, dir dr) -> option::t[def] {
- alt (lookup_in_mod(e, m, sp, name, ns, dr)) {
- case (none) {
- unresolved_err(e, sc, sp, name, ns_name(ns));
- ret none;
- }
- case (some(?d)) { ret some(d); }
+fn lookup_in_mod_strict(e: &env, sc: &scopes, m: def, sp: &span, name: &ident,
+ ns: namespace, dr: dir) -> option::t[def] {
+ alt lookup_in_mod(e, m, sp, name, ns, dr) {
+ none. { unresolved_err(e, sc, sp, name, ns_name(ns)); ret none; }
+ some(d) { ret some(d); }
}
}
-fn lookup_in_mod(&env e, &def m, &span sp, &ident name, namespace ns,
- dir dr) -> option::t[def] {
- auto defid = ast::def_id_of_def(m);
- if (defid.crate != ast::local_crate) {
+fn lookup_in_mod(e: &env, m: &def, sp: &span, name: &ident, ns: namespace,
+ dr: dir) -> option::t[def] {
+ let defid = ast::def_id_of_def(m);
+ if defid.crate != ast::local_crate {
// examining a module in an external crate
- auto cached = e.ext_cache.find(rec(did=defid, ident=name, ns=ns));
- if (!is_none(cached)) { ret cached; }
- auto path = ~[name];
- if (defid.node != -1) { path = e.ext_map.get(defid) + path; }
- auto fnd = lookup_external(e, defid.crate, path, ns);
- if (!is_none(fnd)) {
- e.ext_cache.insert(rec(did=defid, ident=name, ns=ns),
+ let cached = e.ext_cache.find({did: defid, ident: name, ns: ns});
+ if !is_none(cached) { ret cached; }
+ let path = ~[name];
+ if defid.node != -1 { path = e.ext_map.get(defid) + path; }
+ let fnd = lookup_external(e, defid.crate, path, ns);
+ if !is_none(fnd) {
+ e.ext_cache.insert({did: defid, ident: name, ns: ns},
option::get(fnd));
}
ret fnd;
}
- alt (m) {
- case (ast::def_mod(?defid)) {
- ret lookup_in_local_mod(e, defid.node, sp, name, ns, dr);
- }
- case (ast::def_native_mod(?defid)) {
- ret lookup_in_local_native_mod(e, defid.node, sp, name, ns);
- }
+ alt m {
+ ast::def_mod(defid) {
+ ret lookup_in_local_mod(e, defid.node, sp, name, ns, dr);
+ }
+ ast::def_native_mod(defid) {
+ ret lookup_in_local_native_mod(e, defid.node, sp, name, ns);
+ }
}
}
-fn found_view_item(&env e, @ast::view_item vi, namespace ns) ->
+fn found_view_item(e: &env, vi: @ast::view_item, ns: namespace) ->
option::t[def] {
- alt (vi.node) {
- case (ast::view_item_use(_, _, ?id)) {
- auto cnum = cstore::get_use_stmt_cnum(e.cstore, id);
- ret some(ast::def_mod(rec(crate=cnum, node=-1)));
- }
- case (ast::view_item_import(_, _, ?id)) {
- ret lookup_import(e, local_def(id), ns);
- }
- case (ast::view_item_import_glob(_, ?defid)) {
- ret none[def]; //will be handled in the fallback glob pass
+ alt vi.node {
+ ast::view_item_use(_, _, id) {
+ let cnum = cstore::get_use_stmt_cnum(e.cstore, id);
+ ret some(ast::def_mod({crate: cnum, node: -1}));
+ }
+ ast::view_item_import(_, _, id) {
+ ret lookup_import(e, local_def(id), ns);
+ }
+ ast::view_item_import_glob(_, defid) {
+ ret none[def]; //will be handled in the fallback glob pass
- }
+ }
}
}
-fn lookup_import(&env e, def_id defid, namespace ns) -> option::t[def] {
- alt (e.imports.get(defid.node)) {
- case (todo(?item, ?sc)) {
- resolve_import(e, item, sc);
- ret lookup_import(e, defid, ns);
- }
- case (resolving(?sp)) {
- e.sess.span_err(sp, "cyclic import");
- ret none;
- }
- case (resolved(?val, ?typ, ?md)) {
- ret alt (ns) {
- case (ns_value) { val }
- case (ns_type) { typ }
- case (ns_module) { md }
- };
- }
+fn lookup_import(e: &env, defid: def_id, ns: namespace) -> option::t[def] {
+ alt e.imports.get(defid.node) {
+ todo(item, sc) {
+ resolve_import(e, item, sc);
+ ret lookup_import(e, defid, ns);
+ }
+ resolving(sp) { e.sess.span_err(sp, "cyclic import"); ret none; }
+ resolved(val, typ, md) {
+ ret alt ns { ns_value. { val } ns_type. { typ } ns_module. { md } };
+ }
}
}
-fn lookup_in_local_native_mod(&env e, node_id node_id, &span sp, &ident id,
- namespace ns) -> option::t[def] {
+fn lookup_in_local_native_mod(e: &env, node_id: node_id, sp: &span,
+ id: &ident, ns: namespace) -> option::t[def] {
ret lookup_in_local_mod(e, node_id, sp, id, ns, inside);
}
-fn lookup_in_local_mod(&env e, node_id node_id, &span sp, &ident id,
- namespace ns, dir dr) -> option::t[def] {
- auto info = e.mod_map.get(node_id);
- if (dr == outside && !ast::is_exported(id, option::get(info.m))) {
+fn lookup_in_local_mod(e: &env, node_id: node_id, sp: &span, id: &ident,
+ ns: namespace, dr: dir) -> option::t[def] {
+ let info = e.mod_map.get(node_id);
+ if dr == outside && !ast::is_exported(id, option::get(info.m)) {
// if we're in a native mod, then dr==inside, so info.m is some _mod
ret none[def]; // name is not visible
}
- alt (info.index.find(id)) {
- case (none) { }
- case (some(?lst_)) {
- auto lst = lst_;
- while (true) {
- alt (lst) {
- case (nil) { break; }
- case (cons(?hd, ?tl)) {
- auto found = lookup_in_mie(e, hd, ns);
- if (!is_none(found)) { ret found; }
- lst = *tl;
- }
- }
+ alt info.index.find(id) {
+ none. { }
+ some(lst_) {
+ let lst = lst_;
+ while true {
+ alt lst {
+ nil. { break; }
+ cons(hd, tl) {
+ let found = lookup_in_mie(e, hd, ns);
+ if !is_none(found) { ret found; }
+ lst = *tl;
+ }
}
}
+ }
}
// not local or explicitly imported; try globs:
ret lookup_glob_in_mod(e, info, sp, id, ns, outside);
}
-fn lookup_glob_in_mod(&env e, @indexed_mod info, &span sp, &ident id,
- namespace wanted_ns, dir dr) -> option::t[def] {
- fn per_ns(&env e, @indexed_mod info, &span sp, &ident id, namespace ns,
- dir dr) -> option::t[def] {
+fn lookup_glob_in_mod(e: &env, info: @indexed_mod, sp: &span, id: &ident,
+ wanted_ns: namespace, dr: dir) -> option::t[def] {
+ fn per_ns(e: &env, info: @indexed_mod, sp: &span, id: &ident,
+ ns: namespace, dr: dir) -> option::t[def] {
- fn lookup_in_mod_(&env e, &glob_imp_def def, &span sp,
- &ident name, namespace ns,
- dir dr) -> option::t[glob_imp_def] {
- alt (lookup_in_mod(e, def.def, sp, name, ns, dr)) {
- case (option::some(?d)) {
- option::some(rec(def=d, item=def.item))
- }
- case (option::none) {
- option::none
- }
+ fn lookup_in_mod_(e: &env, def: &glob_imp_def, sp: &span,
+ name: &ident, ns: namespace, dr: dir) ->
+ option::t[glob_imp_def] {
+ alt lookup_in_mod(e, def.def, sp, name, ns, dr) {
+ option::some(d) { option::some({def: d, item: def.item}) }
+ option::none. { option::none }
}
}
- auto matches =
+ let matches =
ivec::filter_map(bind lookup_in_mod_(e, _, sp, id, ns, dr),
{ info.glob_imports });
- if (ivec::len(matches) == 0u) {
+ if ivec::len(matches) == 0u {
ret none;
} else if (ivec::len(matches) == 1u) {
ret some(matches.(0).def);
} else {
- for (glob_imp_def match in matches) {
- auto sp = match.item.span;
+ for match: glob_imp_def in matches {
+ let sp = match.item.span;
e.sess.span_note(sp, #fmt("'%s' is imported here", id));
}
e.sess.span_fatal(sp,
- "'" + id + "' is glob-imported from" +
- " multiple different modules.");
+ "'" + id + "' is glob-imported from" +
+ " multiple different modules.");
}
}
// since we don't know what names we have in advance,
// absence takes the place of todo()
- if (!info.glob_imported_names.contains_key(id)) {
+ if !info.glob_imported_names.contains_key(id) {
info.glob_imported_names.insert(id, resolving(sp));
- auto val = per_ns(e, info, sp, id, ns_value, dr);
- auto typ = per_ns(e, info, sp, id, ns_type, dr);
- auto md = per_ns(e, info, sp, id, ns_module, dr);
+ let val = per_ns(e, info, sp, id, ns_value, dr);
+ let typ = per_ns(e, info, sp, id, ns_type, dr);
+ let md = per_ns(e, info, sp, id, ns_module, dr);
info.glob_imported_names.insert(id, resolved(val, typ, md));
}
- alt (info.glob_imported_names.get(id)) {
- case (todo(_, _)) { e.sess.bug("Shouldn't've put a todo in."); }
- case (resolving(?sp)) {
- ret none[def]; //circularity is okay in import globs
+ alt info.glob_imported_names.get(id) {
+ todo(_, _) { e.sess.bug("Shouldn't've put a todo in."); }
+ resolving(sp) {
+ ret none[def]; //circularity is okay in import globs
- }
- case (resolved(?val, ?typ, ?md)) {
- ret alt (wanted_ns) {
- case (ns_value) { val }
- case (ns_type) { typ }
- case (ns_module) { md }
- };
- }
+ }
+ resolved(val, typ, md) {
+ ret alt wanted_ns {
+ ns_value. { val }
+ ns_type. { typ }
+ ns_module. { md }
+ };
+ }
}
}
-fn lookup_in_mie(&env e, &mod_index_entry mie, namespace ns) ->
+fn lookup_in_mie(e: &env, mie: &mod_index_entry, ns: namespace) ->
option::t[def] {
- alt (mie) {
- case (mie_view_item(?view_item)) {
- ret found_view_item(e, view_item, ns);
+ alt mie {
+ mie_view_item(view_item) { ret found_view_item(e, view_item, ns); }
+ mie_item(item) { ret found_def_item(item, ns); }
+ mie_tag_variant(item, variant_idx) {
+ alt item.node {
+ ast::item_tag(variants, _) {
+ if ns == ns_value {
+ let vid = variants.(variant_idx).node.id;
+ ret some(ast::def_variant(local_def(item.id),
+ local_def(vid)));
+ } else { ret none[def]; }
+ }
}
- case (mie_item(?item)) { ret found_def_item(item, ns); }
- case (mie_tag_variant(?item, ?variant_idx)) {
- alt (item.node) {
- case (ast::item_tag(?variants, _)) {
- if (ns == ns_value) {
- auto vid = variants.(variant_idx).node.id;
- ret some(ast::def_variant(local_def(item.id),
- local_def(vid)));
- } else { ret none[def]; }
- }
+ }
+ mie_native_item(native_item) {
+ alt native_item.node {
+ ast::native_item_ty. {
+ if ns == ns_type {
+ ret some(ast::def_native_ty(local_def(native_item.id)));
}
- }
- case (mie_native_item(?native_item)) {
- alt (native_item.node) {
- case (ast::native_item_ty) {
- if (ns == ns_type) {
- ret some(ast::def_native_ty
- (local_def(native_item.id)));
- }
- }
- case (ast::native_item_fn(_, _, _)) {
- if (ns == ns_value) {
- ret some(ast::def_native_fn
- (local_def(native_item.id)));
- }
- }
+ }
+ ast::native_item_fn(_, _, _) {
+ if ns == ns_value {
+ ret some(ast::def_native_fn(local_def(native_item.id)));
}
+ }
}
- case (_) { }
+ }
+ _ { }
}
ret none[def];
}
// Module indexing
-fn add_to_index(&hashmap[ident, list[mod_index_entry]] index, &ident id,
- &mod_index_entry ent) {
- alt (index.find(id)) {
- case (none) { index.insert(id, cons(ent, @nil[mod_index_entry])); }
- case (some(?prev)) { index.insert(id, cons(ent, @prev)); }
+fn add_to_index(index: &hashmap[ident, list[mod_index_entry]], id: &ident,
+ ent: &mod_index_entry) {
+ alt index.find(id) {
+ none. { index.insert(id, cons(ent, @nil[mod_index_entry])); }
+ some(prev) { index.insert(id, cons(ent, @prev)); }
}
}
-fn index_mod(&ast::_mod md) -> mod_index {
- auto index = new_str_hash[list[mod_index_entry]]();
- for (@ast::view_item it in md.view_items) {
- alt (it.node) {
- ast::view_item_import(?ident, _, _) |
- ast::view_item_use(?ident, _, _) {
+fn index_mod(md: &ast::_mod) -> mod_index {
+ let index = new_str_hash[list[mod_index_entry]]();
+ for it: @ast::view_item in md.view_items {
+ alt it.node {
+ ast::view_item_import(ident, _, _) | ast::view_item_use(ident, _, _)
+ {
add_to_index(index, ident, mie_view_item(it));
}
+
//globbed imports have to be resolved lazily.
- ast::view_item_import_glob(_, _) | ast::view_item_export(_, _) {}
+ ast::view_item_import_glob(_, _) | ast::view_item_export(_, _) {
+ }
}
}
- for (@ast::item it in md.items) {
- alt (it.node) {
- ast::item_const(_, _) | ast::item_fn(_, _) | ast::item_mod(_) |
- ast::item_native_mod(_) | ast::item_ty(_, _) |
- ast::item_res(_, _, _, _) | ast::item_obj(_, _, _) {
- add_to_index(index, it.ident, mie_item(it));
+ for it: @ast::item in md.items {
+ alt it.node {
+ ast::item_const(_, _) | ast::item_fn(_, _) | ast::item_mod(_) |
+ ast::item_native_mod(_) | ast::item_ty(_, _) |
+ ast::item_res(_, _, _, _) | ast::item_obj(_, _, _) {
+ add_to_index(index, it.ident, mie_item(it));
+ }
+ ast::item_tag(variants, _) {
+ add_to_index(index, it.ident, mie_item(it));
+ let variant_idx: uint = 0u;
+ for v: ast::variant in variants {
+ add_to_index(index, v.node.name,
+ mie_tag_variant(it, variant_idx));
+ variant_idx += 1u;
}
- ast::item_tag(?variants, _) {
- add_to_index(index, it.ident, mie_item(it));
- let uint variant_idx = 0u;
- for (ast::variant v in variants) {
- add_to_index(index, v.node.name,
- mie_tag_variant(it, variant_idx));
- variant_idx += 1u;
- }
- }
+ }
}
}
ret index;
}
-fn index_nmod(&ast::native_mod md) -> mod_index {
- auto index = new_str_hash[list[mod_index_entry]]();
- for (@ast::view_item it in md.view_items) {
- alt (it.node) {
- ast::view_item_use(?ident, _, _) |
- ast::view_item_import(?ident, _, _) {
+fn index_nmod(md: &ast::native_mod) -> mod_index {
+ let index = new_str_hash[list[mod_index_entry]]();
+ for it: @ast::view_item in md.view_items {
+ alt it.node {
+ ast::view_item_use(ident, _, _) | ast::view_item_import(ident, _, _)
+ {
add_to_index(index, ident, mie_view_item(it));
}
- ast::view_item_import_glob(_, _) | ast::view_item_export(_, _) {}
+ ast::view_item_import_glob(_, _) | ast::view_item_export(_, _) { }
}
}
- for (@ast::native_item it in md.items) {
+ for it: @ast::native_item in md.items {
add_to_index(index, it.ident, mie_native_item(it));
}
ret index;
@@ -1165,262 +1122,255 @@
// External lookups
-fn ns_for_def(def d) -> namespace {
- ret alt (d) {
- case (ast::def_fn(?id, _)) { ns_value }
- case (ast::def_obj_field(?id)) { ns_value }
- case (ast::def_mod(?id)) { ns_module }
- case (ast::def_native_mod(?id)) { ns_module }
- case (ast::def_const(?id)) { ns_value }
- case (ast::def_arg(?id)) { ns_value }
- case (ast::def_local(?id)) { ns_value }
- case (ast::def_variant(_, ?id)) { ns_value }
- case (ast::def_ty(?id)) { ns_type }
- case (ast::def_binding(?id)) { ns_type }
- case (ast::def_use(?id)) { ns_module }
- case (ast::def_native_ty(?id)) { ns_type }
- case (ast::def_native_fn(?id)) { ns_value }
+fn ns_for_def(d: def) -> namespace {
+ ret alt d {
+ ast::def_fn(id, _) { ns_value }
+ ast::def_obj_field(id) { ns_value }
+ ast::def_mod(id) { ns_module }
+ ast::def_native_mod(id) { ns_module }
+ ast::def_const(id) { ns_value }
+ ast::def_arg(id) { ns_value }
+ ast::def_local(id) { ns_value }
+ ast::def_variant(_, id) { ns_value }
+ ast::def_ty(id) { ns_type }
+ ast::def_binding(id) { ns_type }
+ ast::def_use(id) { ns_module }
+ ast::def_native_ty(id) { ns_type }
+ ast::def_native_fn(id) { ns_value }
};
}
-fn lookup_external(&env e, int cnum, &ident[] ids, namespace ns) ->
+fn lookup_external(e: &env, cnum: int, ids: &ident[], ns: namespace) ->
option::t[def] {
- for (def d in csearch::lookup_defs(e.sess.get_cstore(), cnum, ids)) {
+ for d: def in csearch::lookup_defs(e.sess.get_cstore(), cnum, ids) {
e.ext_map.insert(ast::def_id_of_def(d), ids);
- if (ns == ns_for_def(d)) { ret some(d); }
+ if ns == ns_for_def(d) { ret some(d); }
}
ret none[def];
}
// Collision detection
-fn check_for_collisions(&@env e, &ast::crate c) {
+fn check_for_collisions(e: &@env, c: &ast::crate) {
// Module indices make checking those relatively simple -- just check each
// name for multiple entities in the same namespace.
- for each (@rec(ast::node_id key, @indexed_mod val) m
- in e.mod_map.items()) {
- for each (@rec(ident key, list[mod_index_entry] val) name
- in m.val.index.items()) {
+ for each m: @{key: ast::node_id, val: @indexed_mod} in e.mod_map.items()
+ {
+ for each name: @{key: ident, val: list[mod_index_entry]} in
+ m.val.index.items() {
check_mod_name(*e, name.key, name.val);
}
}
// Other scopes have to be checked the hard way.
- auto v =
- @rec(visit_item=bind check_item(e, _, _, _),
- visit_block=bind check_block(e, _, _, _),
- visit_arm=bind check_arm(e, _, _, _),
- visit_expr=bind check_expr(e, _, _, _),
- visit_ty=bind check_ty(e, _, _, _)
- with *visit::default_visitor());
+ let v =
+ @{visit_item: bind check_item(e, _, _, _),
+ visit_block: bind check_block(e, _, _, _),
+ visit_arm: bind check_arm(e, _, _, _),
+ visit_expr: bind check_expr(e, _, _, _),
+ visit_ty: bind check_ty(e, _, _, _) with *visit::default_visitor()};
visit::visit_crate(c, (), visit::mk_vt(v));
}
-fn check_mod_name(&env e, &ident name, list[mod_index_entry] entries) {
- auto saw_mod = false;
- auto saw_type = false;
- auto saw_value = false;
- fn dup(&env e, &span sp, &str word, &ident name) {
+fn check_mod_name(e: &env, name: &ident, entries: list[mod_index_entry]) {
+ let saw_mod = false;
+ let saw_type = false;
+ let saw_value = false;
+ fn dup(e: &env, sp: &span, word: &str, name: &ident) {
e.sess.span_fatal(sp, "duplicate definition of " + word + name);
}
- while (true) {
- alt (entries) {
- case (cons(?entry, ?rest)) {
- if (!is_none(lookup_in_mie(e, entry, ns_value))) {
- if (saw_value) {
- dup(e, mie_span(entry), "", name);
- } else { saw_value = true; }
- }
- if (!is_none(lookup_in_mie(e, entry, ns_type))) {
- if (saw_type) {
- dup(e, mie_span(entry), "type ", name);
- } else { saw_type = true; }
- }
- if (!is_none(lookup_in_mie(e, entry, ns_module))) {
- if (saw_mod) {
- dup(e, mie_span(entry), "module ", name);
- } else { saw_mod = true; }
- }
- entries = *rest;
+ while true {
+ alt entries {
+ cons(entry, rest) {
+ if !is_none(lookup_in_mie(e, entry, ns_value)) {
+ if saw_value {
+ dup(e, mie_span(entry), "", name);
+ } else { saw_value = true; }
}
- case (nil) { break; }
+ if !is_none(lookup_in_mie(e, entry, ns_type)) {
+ if saw_type {
+ dup(e, mie_span(entry), "type ", name);
+ } else { saw_type = true; }
+ }
+ if !is_none(lookup_in_mie(e, entry, ns_module)) {
+ if saw_mod {
+ dup(e, mie_span(entry), "module ", name);
+ } else { saw_mod = true; }
+ }
+ entries = *rest;
+ }
+ nil. { break; }
}
}
}
-fn mie_span(&mod_index_entry mie) -> span {
- ret alt (mie) {
- mie_view_item(?item) { item.span }
- mie_item(?item) { item.span }
- mie_tag_variant(?item, _) { item.span }
- mie_native_item(?item) { item.span }
- };
+fn mie_span(mie: &mod_index_entry) -> span {
+ ret alt mie {
+ mie_view_item(item) { item.span }
+ mie_item(item) { item.span }
+ mie_tag_variant(item, _) { item.span }
+ mie_native_item(item) { item.span }
+ };
}
-fn check_item(&@env e, &@ast::item i, &() x, &vt[()] v) {
+fn check_item(e: &@env, i: &@ast::item, x: &(), v: &vt[()]) {
visit::visit_item(i, x, v);
- alt (i.node) {
- case (ast::item_fn(?f, ?ty_params)) {
- check_fn(*e, i.span, f);
- ensure_unique(*e, i.span, ty_params, ident_id,
- "type parameter");
+ alt i.node {
+ ast::item_fn(f, ty_params) {
+ check_fn(*e, i.span, f);
+ ensure_unique(*e, i.span, ty_params, ident_id, "type parameter");
+ }
+ ast::item_obj(ob, ty_params, _) {
+ fn field_name(field: &ast::obj_field) -> ident { ret field.ident; }
+ ensure_unique(*e, i.span, ob.fields, field_name, "object field");
+ for m: @ast::method in ob.methods {
+ check_fn(*e, m.span, m.node.meth);
}
- case (ast::item_obj(?ob, ?ty_params, _)) {
- fn field_name(&ast::obj_field field) -> ident { ret field.ident; }
- ensure_unique(*e, i.span, ob.fields, field_name,
- "object field");
- for (@ast::method m in ob.methods) {
- check_fn(*e, m.span, m.node.meth);
- }
- ensure_unique(*e, i.span, ty_params, ident_id,
- "type parameter");
- }
- case (ast::item_tag(_, ?ty_params)) {
- ensure_unique(*e, i.span, ty_params, ident_id,
- "type parameter");
- }
- case (_) { }
+ ensure_unique(*e, i.span, ty_params, ident_id, "type parameter");
+ }
+ ast::item_tag(_, ty_params) {
+ ensure_unique(*e, i.span, ty_params, ident_id, "type parameter");
+ }
+ _ { }
}
}
-fn check_arm(&@env e, &ast::arm a, &() x, &vt[()] v) {
+fn check_arm(e: &@env, a: &ast::arm, x: &(), v: &vt[()]) {
visit::visit_arm(a, x, v);
- fn walk_pat(checker ch, &@ast::pat p) {
- alt (p.node) {
- case (ast::pat_bind(?name)) { add_name(ch, p.span, name); }
- case (ast::pat_tag(_, ?children)) {
- for (@ast::pat child in children) { walk_pat(ch, child); }
- }
- case (ast::pat_rec(?fields, _)) {
- for (ast::field_pat f in fields) { walk_pat(ch, f.pat); }
- }
- case (ast::pat_box(?inner)) { walk_pat(ch, inner); }
- case (_) { }
+ fn walk_pat(ch: checker, p: &@ast::pat) {
+ alt p.node {
+ ast::pat_bind(name) { add_name(ch, p.span, name); }
+ ast::pat_tag(_, children) {
+ for child: @ast::pat in children { walk_pat(ch, child); }
+ }
+ ast::pat_rec(fields, _) {
+ for f: ast::field_pat in fields { walk_pat(ch, f.pat); }
+ }
+ ast::pat_box(inner) { walk_pat(ch, inner); }
+ _ { }
}
}
- auto ch0 = checker(*e, "binding");
+ let ch0 = checker(*e, "binding");
walk_pat(ch0, a.pats.(0));
- auto seen0 = ch0.seen;
- auto i = ivec::len(a.pats);
- while (i > 1u) {
+ let seen0 = ch0.seen;
+ let i = ivec::len(a.pats);
+ while i > 1u {
i -= 1u;
- auto ch = checker(*e, "binding");
+ let ch = checker(*e, "binding");
walk_pat(ch, a.pats.(i));
+
// Ensure the bindings introduced in this pattern are the same as in
// the first pattern.
- if (ivec::len(ch.seen) != ivec::len(seen0)) {
+ if ivec::len(ch.seen) != ivec::len(seen0) {
e.sess.span_err(a.pats.(i).span,
"inconsistent number of bindings");
} else {
- for (ident name in ch.seen) {
- if (is_none(ivec::find(bind str::eq(name, _), seen0))) {
+ for name: ident in ch.seen {
+ if is_none(ivec::find(bind str::eq(name, _), seen0)) {
// Fight the alias checker
- auto name_ = name;
- e.sess.span_err
- (a.pats.(i).span, "binding " + name_ +
- " does not occur in first pattern");
+ let name_ = name;
+ e.sess.span_err(a.pats.(i).span,
+ "binding " + name_ +
+ " does not occur in first pattern");
}
}
}
}
}
-fn check_block(&@env e, &ast::blk b, &() x, &vt[()] v) {
+fn check_block(e: &@env, b: &ast::blk, x: &(), v: &vt[()]) {
visit::visit_block(b, x, v);
- auto values = checker(*e, "value");
- auto types = checker(*e, "type");
- auto mods = checker(*e, "module");
- for (@ast::stmt st in b.node.stmts) {
- alt (st.node) {
- case (ast::stmt_decl(?d, _)) {
- alt (d.node) {
- ast::decl_local(?locs) {
- for (@ast::local loc in locs) {
- add_name(values, d.span, loc.node.ident);
- }
- }
- ast::decl_item(?it) {
- alt (it.node) {
- ast::item_tag(?variants, _) {
- add_name(types, it.span, it.ident);
- for (ast::variant v in variants) {
- add_name(values, v.span, v.node.name);
- }
- }
- ast::item_mod(_) | ast::item_native_mod(_) {
- add_name(mods, it.span, it.ident);
- }
- ast::item_const(_, _) | ast::item_fn(_, _) {
- add_name(values, it.span, it.ident);
- }
- ast::item_ty(_, _) {
- add_name(types, it.span, it.ident);
- }
- ast::item_res(_, _, _, _) |
- ast::item_obj(_, _, _) {
- add_name(types, it.span, it.ident);
- add_name(values, it.span, it.ident);
- }
- _ { }
- }
- }
+ let values = checker(*e, "value");
+ let types = checker(*e, "type");
+ let mods = checker(*e, "module");
+ for st: @ast::stmt in b.node.stmts {
+ alt st.node {
+ ast::stmt_decl(d, _) {
+ alt d.node {
+ ast::decl_local(locs) {
+ for loc: @ast::local in locs {
+ add_name(values, d.span, loc.node.ident);
}
+ }
+ ast::decl_item(it) {
+ alt it.node {
+ ast::item_tag(variants, _) {
+ add_name(types, it.span, it.ident);
+ for v: ast::variant in variants {
+ add_name(values, v.span, v.node.name);
+ }
+ }
+ ast::item_mod(_) | ast::item_native_mod(_) {
+ add_name(mods, it.span, it.ident);
+ }
+ ast::item_const(_, _) | ast::item_fn(_, _) {
+ add_name(values, it.span, it.ident);
+ }
+ ast::item_ty(_, _) { add_name(types, it.span, it.ident); }
+ ast::item_res(_, _, _, _) | ast::item_obj(_, _, _) {
+ add_name(types, it.span, it.ident);
+ add_name(values, it.span, it.ident);
+ }
+ _ { }
+ }
+ }
}
- case (_) { }
+ }
+ _ { }
}
}
}
-fn check_fn(&env e, &span sp, &ast::_fn f) {
- fn arg_name(&ast::arg a) -> ident { ret a.ident; }
+fn check_fn(e: &env, sp: &span, f: &ast::_fn) {
+ fn arg_name(a: &ast::arg) -> ident { ret a.ident; }
ensure_unique(e, sp, f.decl.inputs, arg_name, "argument");
}
-fn check_expr(&@env e, &@ast::expr ex, &() x, &vt[()] v) {
+fn check_expr(e: &@env, ex: &@ast::expr, x: &(), v: &vt[()]) {
alt ex.node {
- ast::expr_rec(?fields, _) {
- fn field_name(&ast::field f) -> ident { ret f.node.ident; }
+ ast::expr_rec(fields, _) {
+ fn field_name(f: &ast::field) -> ident { ret f.node.ident; }
ensure_unique(*e, ex.span, fields, field_name, "field");
}
- _ {}
+ _ { }
}
visit::visit_expr(ex, x, v);
}
-fn check_ty(&@env e, &@ast::ty ty, &() x, &vt[()] v) {
+fn check_ty(e: &@env, ty: &@ast::ty, x: &(), v: &vt[()]) {
alt ty.node {
- ast::ty_rec(?fields) {
- fn field_name(&ast::ty_field f) -> ident { ret f.node.ident; }
+ ast::ty_rec(fields) {
+ fn field_name(f: &ast::ty_field) -> ident { ret f.node.ident; }
ensure_unique(*e, ty.span, fields, field_name, "field");
}
- _ {}
+ _ { }
}
visit::visit_ty(ty, x, v);
}
-type checker = @rec(mutable ident[] seen, str kind, session sess);
+type checker = @{mutable seen: ident[], kind: str, sess: session};
-fn checker(&env e, str kind) -> checker {
- let ident[] seen = ~[];
- ret @rec(mutable seen=seen, kind=kind, sess=e.sess);
+fn checker(e: &env, kind: str) -> checker {
+ let seen: ident[] = ~[];
+ ret @{mutable seen: seen, kind: kind, sess: e.sess};
}
-fn add_name(&checker ch, &span sp, &ident name) {
- for (ident s in ch.seen) {
- if (str::eq(s, name)) {
+fn add_name(ch: &checker, sp: &span, name: &ident) {
+ for s: ident in ch.seen {
+ if str::eq(s, name) {
ch.sess.span_fatal(sp, "duplicate " + ch.kind + " name: " + name);
}
}
ch.seen += ~[name];
}
-fn ident_id(&ident i) -> ident { ret i; }
+fn ident_id(i: &ident) -> ident { ret i; }
-fn ensure_unique[T](&env e, &span sp, &T[] elts, fn(&T) -> ident id,
- &str kind) {
- auto ch = checker(e, kind);
- for (T elt in elts) { add_name(ch, sp, id(elt)); }
+fn ensure_unique[T](e: &env, sp: &span, elts: &T[], id: fn(&T) -> ident ,
+ kind: &str) {
+ let ch = checker(e, kind);
+ for elt: T in elts { add_name(ch, sp, id(elt)); }
}
// Local Variables:
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index c78b412..43b6f8d 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -79,29 +79,27 @@
// return value was always meaningless in that case anyhow). Beware!
//
// TODO: Enforce via a predicate.
-fn type_of(&@crate_ctxt cx, &span sp, &ty::t t) -> TypeRef {
- if (ty::type_has_dynamic_size(cx.tcx, t)) {
+fn type_of(cx: &@crate_ctxt, sp: &span, t: &ty::t) -> TypeRef {
+ if ty::type_has_dynamic_size(cx.tcx, t) {
cx.sess.span_fatal(sp,
- "type_of() called on a type with dynamic size: " +
- ty_to_str(cx.tcx, t));
+ "type_of() called on a type with dynamic size: " +
+ ty_to_str(cx.tcx, t));
}
ret type_of_inner(cx, sp, t);
}
-fn type_of_explicit_args(&@crate_ctxt cx, &span sp, &ty::arg[] inputs)
- -> TypeRef[] {
- let TypeRef[] atys = ~[];
- for (ty::arg arg in inputs) {
- if (ty::type_has_dynamic_size(cx.tcx, arg.ty)) {
+fn type_of_explicit_args(cx: &@crate_ctxt, sp: &span, inputs: &ty::arg[]) ->
+ TypeRef[] {
+ let atys: TypeRef[] = ~[];
+ for arg: ty::arg in inputs {
+ if ty::type_has_dynamic_size(cx.tcx, arg.ty) {
assert (arg.mode != ty::mo_val);
atys += ~[T_typaram_ptr(cx.tn)];
} else {
- let TypeRef t;
- alt (arg.mode) {
- case (ty::mo_alias(_)) {
- t = T_ptr(type_of_inner(cx, sp, arg.ty));
- }
- case (_) { t = type_of_inner(cx, sp, arg.ty); }
+ let t: TypeRef;
+ alt arg.mode {
+ ty::mo_alias(_) { t = T_ptr(type_of_inner(cx, sp, arg.ty)); }
+ _ { t = type_of_inner(cx, sp, arg.ty); }
}
atys += ~[t];
}
@@ -116,45 +114,41 @@
// - create_llargs_for_fn_args.
// - new_fn_ctxt
// - trans_args
-fn type_of_fn_full(&@crate_ctxt cx, &span sp, ast::proto proto,
- bool is_method, &ty::arg[] inputs,
- &ty::t output, uint ty_param_count) -> TypeRef {
- let TypeRef[] atys = ~[];
+fn type_of_fn_full(cx: &@crate_ctxt, sp: &span, proto: ast::proto,
+ is_method: bool, inputs: &ty::arg[], output: &ty::t,
+ ty_param_count: uint) -> TypeRef {
+ let atys: TypeRef[] = ~[];
// Arg 0: Output pointer.
- if (ty::type_has_dynamic_size(cx.tcx, output)) {
+ if ty::type_has_dynamic_size(cx.tcx, output) {
atys += ~[T_typaram_ptr(cx.tn)];
- } else {
- atys += ~[T_ptr(type_of_inner(cx, sp, output))];
- }
+ } else { atys += ~[T_ptr(type_of_inner(cx, sp, output))]; }
// Arg 1: task pointer.
atys += ~[T_taskptr(*cx)];
// Arg 2: Env (closure-bindings / self-obj)
- if (is_method) {
+ if is_method {
atys += ~[cx.rust_object_type];
- } else {
- atys += ~[T_opaque_closure_ptr(*cx)];
- }
+ } else { atys += ~[T_opaque_closure_ptr(*cx)]; }
// Args >3: ty params, if not acquired via capture...
- if (!is_method) {
- auto i = 0u;
- while (i < ty_param_count) {
+ if !is_method {
+ let i = 0u;
+ while i < ty_param_count {
atys += ~[T_ptr(cx.tydesc_type)];
i += 1u;
}
}
- if (proto == ast::proto_iter) {
+ if proto == ast::proto_iter {
// If it's an iter, the 'output' type of the iter is actually the
// *input* type of the function we're given as our iter-block
// argument.
atys +=
~[T_fn_pair(*cx,
type_of_fn_full(cx, sp, ast::proto_fn, false,
- ~[rec(mode=ty::mo_alias(false),
- ty=output)], ty::mk_nil(cx.tcx),
+ ~[{mode: ty::mo_alias(false),
+ ty: output}], ty::mk_nil(cx.tcx),
0u))];
}
@@ -163,21 +157,20 @@
ret T_fn(atys, llvm::LLVMVoidType());
}
-fn type_of_fn(&@crate_ctxt cx, &span sp, ast::proto proto,
- &ty::arg[] inputs, &ty::t output, uint ty_param_count) ->
+fn type_of_fn(cx: &@crate_ctxt, sp: &span, proto: ast::proto,
+ inputs: &ty::arg[], output: &ty::t, ty_param_count: uint) ->
TypeRef {
- ret type_of_fn_full(cx, sp, proto, false, inputs, output,
- ty_param_count);
+ ret type_of_fn_full(cx, sp, proto, false, inputs, output, ty_param_count);
}
-fn type_of_native_fn(&@crate_ctxt cx, &span sp, ast::native_abi abi,
- &ty::arg[] inputs, &ty::t output, uint ty_param_count)
+fn type_of_native_fn(cx: &@crate_ctxt, sp: &span, abi: ast::native_abi,
+ inputs: &ty::arg[], output: &ty::t, ty_param_count: uint)
-> TypeRef {
- let TypeRef[] atys = ~[];
- if (abi == ast::native_abi_rust) {
+ let atys: TypeRef[] = ~[];
+ if abi == ast::native_abi_rust {
atys += ~[T_taskptr(*cx)];
- auto i = 0u;
- while (i < ty_param_count) {
+ let i = 0u;
+ while i < ty_param_count {
atys += ~[T_ptr(cx.tydesc_type)];
i += 1u;
}
@@ -186,164 +179,153 @@
ret T_fn(atys, type_of_inner(cx, sp, output));
}
-fn type_of_inner(&@crate_ctxt cx, &span sp, &ty::t t) -> TypeRef {
+fn type_of_inner(cx: &@crate_ctxt, sp: &span, t: &ty::t) -> TypeRef {
// Check the cache.
- if (cx.lltypes.contains_key(t)) { ret cx.lltypes.get(t); }
- let TypeRef llty = 0 as TypeRef;
- alt (ty::struct(cx.tcx, t)) {
- case (ty::ty_native(_)) { llty = T_ptr(T_i8()); }
- case (ty::ty_nil) { llty = T_nil(); }
- case (ty::ty_bot) {
- llty = T_nil(); /* ...I guess? */
+ if cx.lltypes.contains_key(t) { ret cx.lltypes.get(t); }
+ let llty: TypeRef = 0 as TypeRef;
+ alt ty::struct(cx.tcx, t) {
+ ty::ty_native(_) { llty = T_ptr(T_i8()); }
+ ty::ty_nil. { llty = T_nil(); }
+ ty::ty_bot. {
+ llty = T_nil(); /* ...I guess? */
+ }
+ ty::ty_bool. { llty = T_bool(); }
+ ty::ty_int. { llty = T_int(); }
+ ty::ty_float. { llty = T_float(); }
+ ty::ty_uint. { llty = T_int(); }
+ ty::ty_machine(tm) {
+ alt tm {
+ ast::ty_i8. { llty = T_i8(); }
+ ast::ty_u8. { llty = T_i8(); }
+ ast::ty_i16. { llty = T_i16(); }
+ ast::ty_u16. { llty = T_i16(); }
+ ast::ty_i32. { llty = T_i32(); }
+ ast::ty_u32. { llty = T_i32(); }
+ ast::ty_i64. { llty = T_i64(); }
+ ast::ty_u64. { llty = T_i64(); }
+ ast::ty_f32. { llty = T_f32(); }
+ ast::ty_f64. { llty = T_f64(); }
}
- case (ty::ty_bool) { llty = T_bool(); }
- case (ty::ty_int) { llty = T_int(); }
- case (ty::ty_float) { llty = T_float(); }
- case (ty::ty_uint) { llty = T_int(); }
- case (ty::ty_machine(?tm)) {
- alt (tm) {
- case (ast::ty_i8) { llty = T_i8(); }
- case (ast::ty_u8) { llty = T_i8(); }
- case (ast::ty_i16) { llty = T_i16(); }
- case (ast::ty_u16) { llty = T_i16(); }
- case (ast::ty_i32) { llty = T_i32(); }
- case (ast::ty_u32) { llty = T_i32(); }
- case (ast::ty_i64) { llty = T_i64(); }
- case (ast::ty_u64) { llty = T_i64(); }
- case (ast::ty_f32) { llty = T_f32(); }
- case (ast::ty_f64) { llty = T_f64(); }
- }
+ }
+ ty::ty_char. { llty = T_char(); }
+ ty::ty_str. { llty = T_ptr(T_str()); }
+ ty::ty_istr. { llty = T_ivec(T_i8()); }
+ ty::ty_tag(did, _) { llty = type_of_tag(cx, sp, did, t); }
+ ty::ty_box(mt) { llty = T_ptr(T_box(type_of_inner(cx, sp, mt.ty))); }
+ ty::ty_vec(mt) { llty = T_ptr(T_vec(type_of_inner(cx, sp, mt.ty))); }
+ ty::ty_ivec(mt) {
+ if ty::type_has_dynamic_size(cx.tcx, mt.ty) {
+ llty = T_opaque_ivec();
+ } else { llty = T_ivec(type_of_inner(cx, sp, mt.ty)); }
+ }
+ ty::ty_ptr(mt) { llty = T_ptr(type_of_inner(cx, sp, mt.ty)); }
+ ty::ty_port(t) { llty = T_ptr(T_port(type_of_inner(cx, sp, t))); }
+ ty::ty_chan(t) { llty = T_ptr(T_chan(type_of_inner(cx, sp, t))); }
+ ty::ty_task. { llty = T_taskptr(*cx); }
+ ty::ty_rec(fields) {
+ let tys: TypeRef[] = ~[];
+ for f: ty::field in fields {
+ tys += ~[type_of_inner(cx, sp, f.mt.ty)];
}
- case (ty::ty_char) { llty = T_char(); }
- case (ty::ty_str) { llty = T_ptr(T_str()); }
- case (ty::ty_istr) { llty = T_ivec(T_i8()); }
- case (ty::ty_tag(?did, _)) { llty = type_of_tag(cx, sp, did, t); }
- case (ty::ty_box(?mt)) {
- llty = T_ptr(T_box(type_of_inner(cx, sp, mt.ty)));
- }
- case (ty::ty_vec(?mt)) {
- llty = T_ptr(T_vec(type_of_inner(cx, sp, mt.ty)));
- }
- case (ty::ty_ivec(?mt)) {
- if (ty::type_has_dynamic_size(cx.tcx, mt.ty)) {
- llty = T_opaque_ivec();
- } else { llty = T_ivec(type_of_inner(cx, sp, mt.ty)); }
- }
- case (ty::ty_ptr(?mt)) { llty = T_ptr(type_of_inner(cx, sp, mt.ty)); }
- case (ty::ty_port(?t)) {
- llty = T_ptr(T_port(type_of_inner(cx, sp, t)));
- }
- case (ty::ty_chan(?t)) {
- llty = T_ptr(T_chan(type_of_inner(cx, sp, t)));
- }
- case (ty::ty_task) { llty = T_taskptr(*cx); }
- case (ty::ty_rec(?fields)) {
- let TypeRef[] tys = ~[];
- for (ty::field f in fields) {
- tys += ~[type_of_inner(cx, sp, f.mt.ty)];
- }
- llty = T_struct(tys);
- }
- case (ty::ty_fn(?proto, ?args, ?out, _, _)) {
- llty = T_fn_pair(*cx, type_of_fn(cx, sp, proto, args, out, 0u));
- }
- case (ty::ty_native_fn(?abi, ?args, ?out)) {
- auto nft = native_fn_wrapper_type(cx, sp, 0u, t);
- llty = T_fn_pair(*cx, nft);
- }
- case (ty::ty_obj(?meths)) {
- llty = cx.rust_object_type;
- }
- case (ty::ty_res(_, ?sub, ?tps)) {
- auto sub1 = ty::substitute_type_params(cx.tcx, tps, sub);
- ret T_struct(~[T_i32(), type_of_inner(cx, sp, sub1)]);
- }
- case (ty::ty_var(_)) {
- cx.tcx.sess.span_fatal(sp, "trans::type_of called on ty_var");
- }
- case (ty::ty_param(_)) { llty = T_i8(); }
- case (ty::ty_type) { llty = T_ptr(cx.tydesc_type); }
+ llty = T_struct(tys);
+ }
+ ty::ty_fn(proto, args, out, _, _) {
+ llty = T_fn_pair(*cx, type_of_fn(cx, sp, proto, args, out, 0u));
+ }
+ ty::ty_native_fn(abi, args, out) {
+ let nft = native_fn_wrapper_type(cx, sp, 0u, t);
+ llty = T_fn_pair(*cx, nft);
+ }
+ ty::ty_obj(meths) { llty = cx.rust_object_type; }
+ ty::ty_res(_, sub, tps) {
+ let sub1 = ty::substitute_type_params(cx.tcx, tps, sub);
+ ret T_struct(~[T_i32(), type_of_inner(cx, sp, sub1)]);
+ }
+ ty::ty_var(_) {
+ cx.tcx.sess.span_fatal(sp, "trans::type_of called on ty_var");
+ }
+ ty::ty_param(_) { llty = T_i8(); }
+ ty::ty_type. { llty = T_ptr(cx.tydesc_type); }
}
assert (llty as int != 0);
cx.lltypes.insert(t, llty);
ret llty;
}
-fn type_of_tag(&@crate_ctxt cx, &span sp, &ast::def_id did, &ty::t t)
- -> TypeRef {
- auto degen = std::ivec::len(ty::tag_variants(cx.tcx, did)) == 1u;
- if (ty::type_has_dynamic_size(cx.tcx, t)) {
- if (degen) { ret T_i8(); }
- else { ret T_opaque_tag(cx.tn); }
+fn type_of_tag(cx: &@crate_ctxt, sp: &span, did: &ast::def_id, t: &ty::t) ->
+ TypeRef {
+ let degen = std::ivec::len(ty::tag_variants(cx.tcx, did)) == 1u;
+ if ty::type_has_dynamic_size(cx.tcx, t) {
+ if degen { ret T_i8(); } else { ret T_opaque_tag(cx.tn); }
} else {
- auto size = static_size_of_tag(cx, sp, t);
- if (!degen) { ret T_tag(cx.tn, size); }
+ let size = static_size_of_tag(cx, sp, t);
+ if !degen { ret T_tag(cx.tn, size); }
// LLVM does not like 0-size arrays, apparently
- if (size == 0u) { size = 1u; }
+ if size == 0u { size = 1u; }
ret T_array(T_i8(), size);
}
}
-fn type_of_arg(@local_ctxt cx, &span sp, &ty::arg arg) -> TypeRef {
- alt (ty::struct(cx.ccx.tcx, arg.ty)) {
- case (ty::ty_param(_)) {
- if (arg.mode != ty::mo_val) { ret T_typaram_ptr(cx.ccx.tn); }
- }
- case (_) {
- // fall through
+fn type_of_arg(cx: @local_ctxt, sp: &span, arg: &ty::arg) -> TypeRef {
+ alt ty::struct(cx.ccx.tcx, arg.ty) {
+ ty::ty_param(_) {
+ if arg.mode != ty::mo_val { ret T_typaram_ptr(cx.ccx.tn); }
+ }
+ _ {
+ // fall through
- }
+ }
}
- auto typ;
- if (arg.mode != ty::mo_val) {
+ let typ;
+ if arg.mode != ty::mo_val {
typ = T_ptr(type_of_inner(cx.ccx, sp, arg.ty));
} else { typ = type_of_inner(cx.ccx, sp, arg.ty); }
ret typ;
}
-fn type_of_ty_param_count_and_ty(@local_ctxt lcx, &span sp,
- &ty::ty_param_count_and_ty tpt) -> TypeRef {
- alt (ty::struct(lcx.ccx.tcx, tpt.ty)) {
- case (ty::ty_fn(?proto, ?inputs, ?output, _, _)) {
- auto llfnty =
- type_of_fn(lcx.ccx, sp, proto, inputs, output, tpt.count);
- ret T_fn_pair(*lcx.ccx, llfnty);
- }
- case (_) {
- // fall through
+fn type_of_ty_param_count_and_ty(lcx: @local_ctxt, sp: &span,
+ tpt: &ty::ty_param_count_and_ty) -> TypeRef {
+ alt ty::struct(lcx.ccx.tcx, tpt.ty) {
+ ty::ty_fn(proto, inputs, output, _, _) {
+ let llfnty =
+ type_of_fn(lcx.ccx, sp, proto, inputs, output, tpt.count);
+ ret T_fn_pair(*lcx.ccx, llfnty);
+ }
+ _ {
+ // fall through
- }
+ }
}
ret type_of(lcx.ccx, sp, tpt.ty);
}
-fn type_of_or_i8(&@block_ctxt bcx, ty::t typ) -> TypeRef {
- if (ty::type_has_dynamic_size(bcx_tcx(bcx), typ)) { ret T_i8(); }
+fn type_of_or_i8(bcx: &@block_ctxt, typ: ty::t) -> TypeRef {
+ if ty::type_has_dynamic_size(bcx_tcx(bcx), typ) { ret T_i8(); }
ret type_of(bcx_ccx(bcx), bcx.sp, typ);
}
// Name sanitation. LLVM will happily accept identifiers with weird names, but
// gas doesn't!
-fn sanitize(&str s) -> str {
- auto result = "";
- for (u8 c in s) {
- if (c == '@' as u8) {
+fn sanitize(s: &str) -> str {
+ let result = "";
+ for c: u8 in s {
+ if c == '@' as u8 {
result += "boxed_";
} else {
- if (c == ',' as u8) {
+ if c == ',' as u8 {
result += "_";
} else {
- if (c == '{' as u8 || c == '(' as u8) {
+ if c == '{' as u8 || c == '(' as u8 {
result += "_of_";
} else {
- if (c != 10u8 && c != '}' as u8 && c != ')' as u8 &&
- c != ' ' as u8 && c != '\t' as u8 &&
- c != ';' as u8) {
- auto v = [c];
+ if c != 10u8 && c != '}' as u8 && c != ')' as u8 &&
+ c != ' ' as u8 && c != '\t' as u8 && c != ';' as u8
+ {
+ let v = [c];
result += str::from_bytes(v);
}
}
@@ -354,144 +336,145 @@
}
-fn log_fn_time(&@crate_ctxt ccx, str name, &time::timeval start,
- &time::timeval end) {
- auto elapsed = 1000 * ((end.sec - start.sec) as int) +
- ((end.usec as int) - (start.usec as int)) / 1000;
- *ccx.stats.fn_times += ~[rec(ident=name, time=elapsed)];
+fn log_fn_time(ccx: &@crate_ctxt, name: str, start: &time::timeval,
+ end: &time::timeval) {
+ let elapsed =
+ 1000 * (end.sec - start.sec as int) +
+ ((end.usec as int) - (start.usec as int)) / 1000;
+ *ccx.stats.fn_times += ~[{ident: name, time: elapsed}];
}
-fn decl_fn(ModuleRef llmod, &str name, uint cc, TypeRef llty) -> ValueRef {
- let ValueRef llfn = llvm::LLVMAddFunction(llmod, str::buf(name), llty);
+fn decl_fn(llmod: ModuleRef, name: &str, cc: uint, llty: TypeRef) ->
+ ValueRef {
+ let llfn: ValueRef = llvm::LLVMAddFunction(llmod, str::buf(name), llty);
llvm::LLVMSetFunctionCallConv(llfn, cc);
ret llfn;
}
-fn decl_cdecl_fn(ModuleRef llmod, &str name, TypeRef llty) -> ValueRef {
+fn decl_cdecl_fn(llmod: ModuleRef, name: &str, llty: TypeRef) -> ValueRef {
ret decl_fn(llmod, name, lib::llvm::LLVMCCallConv, llty);
}
-fn decl_fastcall_fn(ModuleRef llmod, &str name, TypeRef llty) -> ValueRef {
+fn decl_fastcall_fn(llmod: ModuleRef, name: &str, llty: TypeRef) -> ValueRef {
ret decl_fn(llmod, name, lib::llvm::LLVMFastCallConv, llty);
}
// Only use this if you are going to actually define the function. It's
// not valid to simply declare a function as internal.
-fn decl_internal_fastcall_fn(ModuleRef llmod, &str name, TypeRef llty) ->
+fn decl_internal_fastcall_fn(llmod: ModuleRef, name: &str, llty: TypeRef) ->
ValueRef {
- auto llfn = decl_fn(llmod, name, lib::llvm::LLVMFastCallConv, llty);
+ let llfn = decl_fn(llmod, name, lib::llvm::LLVMFastCallConv, llty);
llvm::LLVMSetLinkage(llfn,
lib::llvm::LLVMInternalLinkage as llvm::Linkage);
ret llfn;
}
-fn decl_glue(ModuleRef llmod, &crate_ctxt cx, &str s) -> ValueRef {
+fn decl_glue(llmod: ModuleRef, cx: &crate_ctxt, s: &str) -> ValueRef {
ret decl_cdecl_fn(llmod, s, T_fn(~[T_taskptr(cx)], T_void()));
}
-fn get_extern_fn(&hashmap[str, ValueRef] externs, ModuleRef llmod, &str name,
- uint cc, TypeRef ty) -> ValueRef {
- if (externs.contains_key(name)) { ret externs.get(name); }
- auto f = decl_fn(llmod, name, cc, ty);
+fn get_extern_fn(externs: &hashmap[str, ValueRef], llmod: ModuleRef,
+ name: &str, cc: uint, ty: TypeRef) -> ValueRef {
+ if externs.contains_key(name) { ret externs.get(name); }
+ let f = decl_fn(llmod, name, cc, ty);
externs.insert(name, f);
ret f;
}
-fn get_extern_const(&hashmap[str, ValueRef] externs, ModuleRef llmod,
- &str name, TypeRef ty) -> ValueRef {
- if (externs.contains_key(name)) { ret externs.get(name); }
- auto c = llvm::LLVMAddGlobal(llmod, ty, str::buf(name));
+fn get_extern_const(externs: &hashmap[str, ValueRef], llmod: ModuleRef,
+ name: &str, ty: TypeRef) -> ValueRef {
+ if externs.contains_key(name) { ret externs.get(name); }
+ let c = llvm::LLVMAddGlobal(llmod, ty, str::buf(name));
externs.insert(name, c);
ret c;
}
-fn get_simple_extern_fn(&hashmap[str, ValueRef] externs, ModuleRef llmod,
- &str name, int n_args) -> ValueRef {
- auto inputs = std::ivec::init_elt[TypeRef](T_int(), n_args as uint);
- auto output = T_int();
- auto t = T_fn(inputs, output);
+fn get_simple_extern_fn(externs: &hashmap[str, ValueRef], llmod: ModuleRef,
+ name: &str, n_args: int) -> ValueRef {
+ let inputs = std::ivec::init_elt[TypeRef](T_int(), n_args as uint);
+ let output = T_int();
+ let t = T_fn(inputs, output);
ret get_extern_fn(externs, llmod, name, lib::llvm::LLVMCCallConv, t);
}
-fn trans_native_call(&builder b, @glue_fns glues, ValueRef lltaskptr,
- &hashmap[str, ValueRef] externs, &type_names tn,
- ModuleRef llmod, &str name, bool pass_task,
- &ValueRef[] args) -> ValueRef {
- let int n = std::ivec::len[ValueRef](args) as int;
- let ValueRef llnative = get_simple_extern_fn(externs, llmod,
- name, n);
- let ValueRef[] call_args = ~[];
- for (ValueRef a in args) { call_args += ~[b.ZExtOrBitCast(a, T_int())]; }
+fn trans_native_call(b: &builder, glues: @glue_fns, lltaskptr: ValueRef,
+ externs: &hashmap[str, ValueRef], tn: &type_names,
+ llmod: ModuleRef, name: &str, pass_task: bool,
+ args: &ValueRef[]) -> ValueRef {
+ let n: int = std::ivec::len[ValueRef](args) as int;
+ let llnative: ValueRef = get_simple_extern_fn(externs, llmod, name, n);
+ let call_args: ValueRef[] = ~[];
+ for a: ValueRef in args { call_args += ~[b.ZExtOrBitCast(a, T_int())]; }
ret b.Call(llnative, call_args);
}
-fn trans_non_gc_free(&@block_ctxt cx, ValueRef v) -> result {
+fn trans_non_gc_free(cx: &@block_ctxt, v: ValueRef) -> result {
cx.build.Call(bcx_ccx(cx).upcalls.free,
~[cx.fcx.lltaskptr, cx.build.PointerCast(v, T_ptr(T_i8())),
C_int(0)]);
ret rslt(cx, C_int(0));
}
-fn trans_shared_free(&@block_ctxt cx, ValueRef v) -> result {
+fn trans_shared_free(cx: &@block_ctxt, v: ValueRef) -> result {
cx.build.Call(bcx_ccx(cx).upcalls.shared_free,
~[cx.fcx.lltaskptr,
cx.build.PointerCast(v, T_ptr(T_i8()))]);
ret rslt(cx, C_int(0));
}
-fn umax(&@block_ctxt cx, ValueRef a, ValueRef b) -> ValueRef {
- auto cond = cx.build.ICmp(lib::llvm::LLVMIntULT, a, b);
+fn umax(cx: &@block_ctxt, a: ValueRef, b: ValueRef) -> ValueRef {
+ let cond = cx.build.ICmp(lib::llvm::LLVMIntULT, a, b);
ret cx.build.Select(cond, b, a);
}
-fn umin(&@block_ctxt cx, ValueRef a, ValueRef b) -> ValueRef {
- auto cond = cx.build.ICmp(lib::llvm::LLVMIntULT, a, b);
+fn umin(cx: &@block_ctxt, a: ValueRef, b: ValueRef) -> ValueRef {
+ let cond = cx.build.ICmp(lib::llvm::LLVMIntULT, a, b);
ret cx.build.Select(cond, a, b);
}
-fn align_to(&@block_ctxt cx, ValueRef off, ValueRef align) -> ValueRef {
- auto mask = cx.build.Sub(align, C_int(1));
- auto bumped = cx.build.Add(off, mask);
+fn align_to(cx: &@block_ctxt, off: ValueRef, align: ValueRef) -> ValueRef {
+ let mask = cx.build.Sub(align, C_int(1));
+ let bumped = cx.build.Add(off, mask);
ret cx.build.And(bumped, cx.build.Not(mask));
}
// Returns the real size of the given type for the current target.
-fn llsize_of_real(&@crate_ctxt cx, TypeRef t) -> uint {
+fn llsize_of_real(cx: &@crate_ctxt, t: TypeRef) -> uint {
ret llvm::LLVMStoreSizeOfType(cx.td.lltd, t);
}
-fn llsize_of(TypeRef t) -> ValueRef {
+fn llsize_of(t: TypeRef) -> ValueRef {
ret llvm::LLVMConstIntCast(lib::llvm::llvm::LLVMSizeOf(t), T_int(),
False);
}
-fn llalign_of(TypeRef t) -> ValueRef {
+fn llalign_of(t: TypeRef) -> ValueRef {
ret llvm::LLVMConstIntCast(lib::llvm::llvm::LLVMAlignOf(t), T_int(),
False);
}
-fn size_of(&@block_ctxt cx, &ty::t t) -> result {
- if (!ty::type_has_dynamic_size(bcx_tcx(cx), t)) {
+fn size_of(cx: &@block_ctxt, t: &ty::t) -> result {
+ if !ty::type_has_dynamic_size(bcx_tcx(cx), t) {
ret rslt(cx, llsize_of(type_of(bcx_ccx(cx), cx.sp, t)));
}
ret dynamic_size_of(cx, t);
}
-fn align_of(&@block_ctxt cx, &ty::t t) -> result {
- if (!ty::type_has_dynamic_size(bcx_tcx(cx), t)) {
+fn align_of(cx: &@block_ctxt, t: &ty::t) -> result {
+ if !ty::type_has_dynamic_size(bcx_tcx(cx), t) {
ret rslt(cx, llalign_of(type_of(bcx_ccx(cx), cx.sp, t)));
}
ret dynamic_align_of(cx, t);
}
-fn alloca(&@block_ctxt cx, TypeRef t) -> ValueRef {
+fn alloca(cx: &@block_ctxt, t: TypeRef) -> ValueRef {
ret new_builder(cx.fcx.llstaticallocas).Alloca(t);
}
-fn array_alloca(&@block_ctxt cx, TypeRef t, ValueRef n) -> ValueRef {
+fn array_alloca(cx: &@block_ctxt, t: TypeRef, n: ValueRef) -> ValueRef {
ret new_builder(cx.fcx.lldynamicallocas).ArrayAlloca(t, n);
}
@@ -500,35 +483,30 @@
// to have (a) the same size as the type that was passed in; (b) to be non-
// recursive. This is done by replacing all boxes in a type with boxed unit
// types.
-fn simplify_type(&@crate_ctxt ccx, &ty::t typ) -> ty::t {
- fn simplifier(@crate_ctxt ccx, ty::t typ) -> ty::t {
- alt (ty::struct(ccx.tcx, typ)) {
- case (ty::ty_box(_)) {
- ret ty::mk_imm_box(ccx.tcx, ty::mk_nil(ccx.tcx));
- }
- case (ty::ty_vec(_)) {
- ret ty::mk_imm_vec(ccx.tcx, ty::mk_nil(ccx.tcx));
- }
- case (ty::ty_fn(_, _, _, _, _)) {
- ret ty::mk_imm_tup(ccx.tcx,
- ~[ty::mk_imm_box(ccx.tcx,
- ty::mk_nil(ccx.tcx)),
- ty::mk_imm_box(ccx.tcx,
- ty::mk_nil(ccx.tcx))]);
- }
- case (ty::ty_obj(_)) {
- ret ty::mk_imm_tup(ccx.tcx,
- ~[ty::mk_imm_box(ccx.tcx,
- ty::mk_nil(ccx.tcx)),
- ty::mk_imm_box(ccx.tcx,
- ty::mk_nil(ccx.tcx))]);
- }
- case (ty::ty_res(_, ?sub, ?tps)) {
- auto sub1 = ty::substitute_type_params(ccx.tcx, tps, sub);
- ret ty::mk_imm_tup(ccx.tcx, ~[ty::mk_int(ccx.tcx),
- simplify_type(ccx, sub1)]);
- }
- case (_) { ret typ; }
+fn simplify_type(ccx: &@crate_ctxt, typ: &ty::t) -> ty::t {
+ fn simplifier(ccx: @crate_ctxt, typ: ty::t) -> ty::t {
+ alt ty::struct(ccx.tcx, typ) {
+ ty::ty_box(_) { ret ty::mk_imm_box(ccx.tcx, ty::mk_nil(ccx.tcx)); }
+ ty::ty_vec(_) { ret ty::mk_imm_vec(ccx.tcx, ty::mk_nil(ccx.tcx)); }
+ ty::ty_fn(_, _, _, _, _) {
+ ret ty::mk_imm_tup(ccx.tcx,
+ ~[ty::mk_imm_box(ccx.tcx, ty::mk_nil(ccx.tcx)),
+ ty::mk_imm_box(ccx.tcx,
+ ty::mk_nil(ccx.tcx))]);
+ }
+ ty::ty_obj(_) {
+ ret ty::mk_imm_tup(ccx.tcx,
+ ~[ty::mk_imm_box(ccx.tcx, ty::mk_nil(ccx.tcx)),
+ ty::mk_imm_box(ccx.tcx,
+ ty::mk_nil(ccx.tcx))]);
+ }
+ ty::ty_res(_, sub, tps) {
+ let sub1 = ty::substitute_type_params(ccx.tcx, tps, sub);
+ ret ty::mk_imm_tup(ccx.tcx,
+ ~[ty::mk_int(ccx.tcx),
+ simplify_type(ccx, sub1)]);
+ }
+ _ { ret typ; }
}
}
ret ty::fold_ty(ccx.tcx, ty::fm_general(bind simplifier(ccx, _)), typ);
@@ -536,42 +514,41 @@
// Computes the size of the data part of a non-dynamically-sized tag.
-fn static_size_of_tag(&@crate_ctxt cx, &span sp, &ty::t t) -> uint {
- if (ty::type_has_dynamic_size(cx.tcx, t)) {
+fn static_size_of_tag(cx: &@crate_ctxt, sp: &span, t: &ty::t) -> uint {
+ if ty::type_has_dynamic_size(cx.tcx, t) {
cx.tcx.sess.span_fatal(sp,
"dynamically sized type passed to \
static_size_of_tag()");
}
- if (cx.tag_sizes.contains_key(t)) { ret cx.tag_sizes.get(t); }
- alt (ty::struct(cx.tcx, t)) {
- case (ty::ty_tag(?tid, ?subtys)) {
- // Compute max(variant sizes).
+ if cx.tag_sizes.contains_key(t) { ret cx.tag_sizes.get(t); }
+ alt ty::struct(cx.tcx, t) {
+ ty::ty_tag(tid, subtys) {
+ // Compute max(variant sizes).
- auto max_size = 0u;
- auto variants = ty::tag_variants(cx.tcx, tid);
- for (ty::variant_info variant in variants) {
- auto tup_ty = simplify_type(cx, ty::mk_imm_tup(cx.tcx,
- variant.args));
- // Perform any type parameter substitutions.
+ let max_size = 0u;
+ let variants = ty::tag_variants(cx.tcx, tid);
+ for variant: ty::variant_info in variants {
+ let tup_ty =
+ simplify_type(cx, ty::mk_imm_tup(cx.tcx, variant.args));
+ // Perform any type parameter substitutions.
- tup_ty = ty::substitute_type_params(cx.tcx, subtys, tup_ty);
- // Here we possibly do a recursive call.
+ tup_ty = ty::substitute_type_params(cx.tcx, subtys, tup_ty);
+ // Here we possibly do a recursive call.
- auto this_size = llsize_of_real(cx, type_of(cx, sp, tup_ty));
- if (max_size < this_size) { max_size = this_size; }
- }
- cx.tag_sizes.insert(t, max_size);
- ret max_size;
+ let this_size = llsize_of_real(cx, type_of(cx, sp, tup_ty));
+ if max_size < this_size { max_size = this_size; }
}
- case (_) {
- cx.tcx.sess.span_fatal(sp,
- "non-tag passed to static_size_of_tag()");
- }
+ cx.tag_sizes.insert(t, max_size);
+ ret max_size;
+ }
+ _ {
+ cx.tcx.sess.span_fatal(sp, "non-tag passed to static_size_of_tag()");
+ }
}
}
-fn dynamic_size_of(&@block_ctxt cx, ty::t t) -> result {
- fn align_elements(&@block_ctxt cx, &ty::t[] elts) -> result {
+fn dynamic_size_of(cx: &@block_ctxt, t: ty::t) -> result {
+ fn align_elements(cx: &@block_ctxt, elts: &ty::t[]) -> result {
//
// C padding rules:
//
@@ -581,99 +558,99 @@
// is aligned to max alignment of interior.
//
- auto off = C_int(0);
- auto max_align = C_int(1);
- auto bcx = cx;
- for (ty::t e in elts) {
- auto elt_align = align_of(bcx, e);
+ let off = C_int(0);
+ let max_align = C_int(1);
+ let bcx = cx;
+ for e: ty::t in elts {
+ let elt_align = align_of(bcx, e);
bcx = elt_align.bcx;
- auto elt_size = size_of(bcx, e);
+ let elt_size = size_of(bcx, e);
bcx = elt_size.bcx;
- auto aligned_off = align_to(bcx, off, elt_align.val);
+ let aligned_off = align_to(bcx, off, elt_align.val);
off = bcx.build.Add(aligned_off, elt_size.val);
max_align = umax(bcx, max_align, elt_align.val);
}
off = align_to(bcx, off, max_align);
ret rslt(bcx, off);
}
- alt (ty::struct(bcx_tcx(cx), t)) {
- case (ty::ty_param(?p)) {
- auto szptr =
- field_of_tydesc(cx, t, false, abi::tydesc_field_size);
- ret rslt(szptr.bcx, szptr.bcx.build.Load(szptr.val));
- }
- case (ty::ty_rec(?flds)) {
- let ty::t[] tys = ~[];
- for (ty::field f in flds) { tys += ~[f.mt.ty]; }
- ret align_elements(cx, tys);
- }
- case (ty::ty_tag(?tid, ?tps)) {
- auto bcx = cx;
- // Compute max(variant sizes).
+ alt ty::struct(bcx_tcx(cx), t) {
+ ty::ty_param(p) {
+ let szptr = field_of_tydesc(cx, t, false, abi::tydesc_field_size);
+ ret rslt(szptr.bcx, szptr.bcx.build.Load(szptr.val));
+ }
+ ty::ty_rec(flds) {
+ let tys: ty::t[] = ~[];
+ for f: ty::field in flds { tys += ~[f.mt.ty]; }
+ ret align_elements(cx, tys);
+ }
+ ty::ty_tag(tid, tps) {
+ let bcx = cx;
+ // Compute max(variant sizes).
- let ValueRef max_size = alloca(bcx, T_int());
- bcx.build.Store(C_int(0), max_size);
- auto variants = ty::tag_variants(bcx_tcx(bcx), tid);
- for (ty::variant_info variant in variants) {
- // Perform type substitution on the raw argument types.
+ let max_size: ValueRef = alloca(bcx, T_int());
+ bcx.build.Store(C_int(0), max_size);
+ let variants = ty::tag_variants(bcx_tcx(bcx), tid);
+ for variant: ty::variant_info in variants {
+ // Perform type substitution on the raw argument types.
- let ty::t[] raw_tys = variant.args;
- let ty::t[] tys = ~[];
- for (ty::t raw_ty in raw_tys) {
- auto t = ty::substitute_type_params(bcx_tcx(cx),
- tps, raw_ty);
- tys += ~[t];
- }
- auto rslt = align_elements(bcx, tys);
- bcx = rslt.bcx;
- auto this_size = rslt.val;
- auto old_max_size = bcx.build.Load(max_size);
- bcx.build.Store(umax(bcx, this_size, old_max_size), max_size);
+ let raw_tys: ty::t[] = variant.args;
+ let tys: ty::t[] = ~[];
+ for raw_ty: ty::t in raw_tys {
+ let t = ty::substitute_type_params(bcx_tcx(cx), tps, raw_ty);
+ tys += ~[t];
}
- auto max_size_val = bcx.build.Load(max_size);
- auto total_size = if (std::ivec::len(variants) != 1u) {
+ let rslt = align_elements(bcx, tys);
+ bcx = rslt.bcx;
+ let this_size = rslt.val;
+ let old_max_size = bcx.build.Load(max_size);
+ bcx.build.Store(umax(bcx, this_size, old_max_size), max_size);
+ }
+ let max_size_val = bcx.build.Load(max_size);
+ let total_size =
+ if std::ivec::len(variants) != 1u {
bcx.build.Add(max_size_val, llsize_of(T_int()))
} else { max_size_val };
- ret rslt(bcx, total_size);
- }
- case (ty::ty_ivec(?mt)) {
- auto rs = size_of(cx, mt.ty);
- auto bcx = rs.bcx;
- auto llunitsz = rs.val;
- auto llsz = bcx.build.Add(llsize_of(T_opaque_ivec()),
- bcx.build.Mul(llunitsz, C_uint(abi::ivec_default_length)));
- ret rslt(bcx, llsz);
- }
+ ret rslt(bcx, total_size);
+ }
+ ty::ty_ivec(mt) {
+ let rs = size_of(cx, mt.ty);
+ let bcx = rs.bcx;
+ let llunitsz = rs.val;
+ let llsz =
+ bcx.build.Add(llsize_of(T_opaque_ivec()),
+ bcx.build.Mul(llunitsz,
+ C_uint(abi::ivec_default_length)));
+ ret rslt(bcx, llsz);
+ }
}
}
-fn dynamic_align_of(&@block_ctxt cx, &ty::t t) -> result {
- alt (ty::struct(bcx_tcx(cx), t)) {
- case (ty::ty_param(?p)) {
- auto aptr =
- field_of_tydesc(cx, t, false, abi::tydesc_field_align);
- ret rslt(aptr.bcx, aptr.bcx.build.Load(aptr.val));
+fn dynamic_align_of(cx: &@block_ctxt, t: &ty::t) -> result {
+ alt ty::struct(bcx_tcx(cx), t) {
+ ty::ty_param(p) {
+ let aptr = field_of_tydesc(cx, t, false, abi::tydesc_field_align);
+ ret rslt(aptr.bcx, aptr.bcx.build.Load(aptr.val));
+ }
+ ty::ty_rec(flds) {
+ let a = C_int(1);
+ let bcx = cx;
+ for f: ty::field in flds {
+ let align = align_of(bcx, f.mt.ty);
+ bcx = align.bcx;
+ a = umax(bcx, a, align.val);
}
- case (ty::ty_rec(?flds)) {
- auto a = C_int(1);
- auto bcx = cx;
- for (ty::field f in flds) {
- auto align = align_of(bcx, f.mt.ty);
- bcx = align.bcx;
- a = umax(bcx, a, align.val);
- }
- ret rslt(bcx, a);
- }
- case (ty::ty_tag(_, _)) {
- ret rslt(cx, C_int(1)); // FIXME: stub
- }
- case (ty::ty_ivec(?tm)) {
- auto rs = align_of(cx, tm.ty);
- auto bcx = rs.bcx;
- auto llunitalign = rs.val;
- auto llalign = umax(bcx, llalign_of(T_int()), llunitalign);
- ret rslt(bcx, llalign);
- }
+ ret rslt(bcx, a);
+ }
+ ty::ty_tag(_, _) {
+ ret rslt(cx, C_int(1)); // FIXME: stub
+ }
+ ty::ty_ivec(tm) {
+ let rs = align_of(cx, tm.ty);
+ let bcx = rs.bcx;
+ let llunitalign = rs.val;
+ let llalign = umax(bcx, llalign_of(T_int()), llunitalign);
+ ret rslt(bcx, llalign);
+ }
}
}
@@ -683,14 +660,14 @@
// ty::struct and knows what to do when it runs into a ty_param stuck in the
// middle of the thing it's GEP'ing into. Much like size_of and align_of,
// above.
-fn GEP_tup_like(&@block_ctxt cx, &ty::t t, ValueRef base, &int[] ixs)
- -> result {
+fn GEP_tup_like(cx: &@block_ctxt, t: &ty::t, base: ValueRef, ixs: &int[]) ->
+ result {
assert (ty::type_is_tup_like(bcx_tcx(cx), t));
// It might be a static-known type. Handle this.
- if (!ty::type_has_dynamic_size(bcx_tcx(cx), t)) {
- let ValueRef[] v = ~[];
- for (int i in ixs) { v += ~[C_int(i)]; }
+ if !ty::type_has_dynamic_size(bcx_tcx(cx), t) {
+ let v: ValueRef[] = ~[];
+ for i: int in ixs { v += ~[C_int(i)]; }
ret rslt(cx, cx.build.GEP(base, v));
}
// It is a dynamic-containing type that, if we convert directly to an LLVM
@@ -709,15 +686,15 @@
// elements of the type and splitting the Xth off. Return the prefix as
// well as the innermost Xth type.
- fn split_type(&@crate_ctxt ccx, &ty::t t, &int[] ixs, uint n)
- -> rec(ty::t[] prefix, ty::t target) {
- let uint len = std::ivec::len[int](ixs);
+ fn split_type(ccx: &@crate_ctxt, t: &ty::t, ixs: &int[], n: uint) ->
+ {prefix: ty::t[], target: ty::t} {
+ let len: uint = std::ivec::len[int](ixs);
// We don't support 0-index or 1-index GEPs: The former is nonsense
// and the latter would only be meaningful if we supported non-0
// values for the 0th index (we don't).
assert (len > 1u);
- if (n == 0u) {
+ if n == 0u {
// Since we're starting from a value that's a pointer to a
// *single* structure, the first index (in GEP-ese) should just be
// 0, to yield the pointee.
@@ -726,47 +703,47 @@
ret split_type(ccx, t, ixs, n + 1u);
}
assert (n < len);
- let int ix = ixs.(n);
- let ty::t[] prefix = ~[];
- let int i = 0;
- while (i < ix) {
+ let ix: int = ixs.(n);
+ let prefix: ty::t[] = ~[];
+ let i: int = 0;
+ while i < ix {
prefix += ~[ty::get_element_type(ccx.tcx, t, i as uint)];
i += 1;
}
- auto selected = ty::get_element_type(ccx.tcx, t, i as uint);
- if (n == len - 1u) {
+ let selected = ty::get_element_type(ccx.tcx, t, i as uint);
+ if n == len - 1u {
// We are at the innermost index.
- ret rec(prefix=prefix, target=selected);
+ ret {prefix: prefix, target: selected};
} else {
// Not the innermost index; call self recursively to dig deeper.
// Once we get an inner result, append it current prefix and
// return to caller.
- auto inner = split_type(ccx, selected, ixs, n + 1u);
+ let inner = split_type(ccx, selected, ixs, n + 1u);
prefix += inner.prefix;
- ret rec(prefix=prefix with inner);
+ ret {prefix: prefix with inner};
}
}
// We make a fake prefix tuple-type here; luckily for measuring sizes
// the tuple parens are associative so it doesn't matter that we've
// flattened the incoming structure.
- auto s = split_type(bcx_ccx(cx), t, ixs, 0u);
+ let s = split_type(bcx_ccx(cx), t, ixs, 0u);
- auto args = ~[];
- for (ty::t typ in s.prefix) { args += ~[typ]; }
- auto prefix_ty = ty::mk_imm_tup(bcx_tcx(cx), args);
+ let args = ~[];
+ for typ: ty::t in s.prefix { args += ~[typ]; }
+ let prefix_ty = ty::mk_imm_tup(bcx_tcx(cx), args);
- auto bcx = cx;
- auto sz = size_of(bcx, prefix_ty);
+ let bcx = cx;
+ let sz = size_of(bcx, prefix_ty);
bcx = sz.bcx;
- auto raw = bcx.build.PointerCast(base, T_ptr(T_i8()));
- auto bumped = bcx.build.GEP(raw, ~[sz.val]);
- if (ty::type_has_dynamic_size(bcx_tcx(cx), s.target)) {
+ let raw = bcx.build.PointerCast(base, T_ptr(T_i8()));
+ let bumped = bcx.build.GEP(raw, ~[sz.val]);
+ if ty::type_has_dynamic_size(bcx_tcx(cx), s.target) {
ret rslt(bcx, bumped);
}
- auto typ = T_ptr(type_of(bcx_ccx(bcx), bcx.sp, s.target));
+ let typ = T_ptr(type_of(bcx_ccx(bcx), bcx.sp, s.target));
ret rslt(bcx, bcx.build.PointerCast(bumped, typ));
}
@@ -775,42 +752,40 @@
// This function uses GEP_tup_like() above and automatically performs casts as
// appropriate. @llblobptr is the data part of a tag value; its actual type is
// meaningless, as it will be cast away.
-fn GEP_tag(@block_ctxt cx, ValueRef llblobptr, &ast::def_id tag_id,
- &ast::def_id variant_id, &ty::t[] ty_substs, int ix) -> result {
- auto variant =
- ty::tag_variant_with_id(bcx_tcx(cx), tag_id, variant_id);
+fn GEP_tag(cx: @block_ctxt, llblobptr: ValueRef, tag_id: &ast::def_id,
+ variant_id: &ast::def_id, ty_substs: &ty::t[], ix: int) -> result {
+ let variant = ty::tag_variant_with_id(bcx_tcx(cx), tag_id, variant_id);
// Synthesize a tuple type so that GEP_tup_like() can work its magic.
// Separately, store the type of the element we're interested in.
- auto arg_tys = variant.args;
- auto elem_ty = ty::mk_nil(bcx_tcx(cx)); // typestate infelicity
+ let arg_tys = variant.args;
+ let elem_ty = ty::mk_nil(bcx_tcx(cx)); // typestate infelicity
- auto i = 0;
- let ty::t[] true_arg_tys = ~[];
- for (ty::t aty in arg_tys) {
- auto arg_ty =
- ty::substitute_type_params(bcx_tcx(cx), ty_substs, aty);
+ let i = 0;
+ let true_arg_tys: ty::t[] = ~[];
+ for aty: ty::t in arg_tys {
+ let arg_ty = ty::substitute_type_params(bcx_tcx(cx), ty_substs, aty);
true_arg_tys += ~[arg_ty];
- if (i == ix) { elem_ty = arg_ty; }
+ if i == ix { elem_ty = arg_ty; }
i += 1;
}
- auto tup_ty = ty::mk_imm_tup(bcx_tcx(cx), true_arg_tys);
+ let tup_ty = ty::mk_imm_tup(bcx_tcx(cx), true_arg_tys);
// Cast the blob pointer to the appropriate type, if we need to (i.e. if
// the blob pointer isn't dynamically sized).
- let ValueRef llunionptr;
- if (!ty::type_has_dynamic_size(bcx_tcx(cx), tup_ty)) {
- auto llty = type_of(bcx_ccx(cx), cx.sp, tup_ty);
+ let llunionptr: ValueRef;
+ if !ty::type_has_dynamic_size(bcx_tcx(cx), tup_ty) {
+ let llty = type_of(bcx_ccx(cx), cx.sp, tup_ty);
llunionptr = cx.build.TruncOrBitCast(llblobptr, T_ptr(llty));
} else { llunionptr = llblobptr; }
// Do the GEP_tup_like().
- auto rs = GEP_tup_like(cx, tup_ty, llunionptr, ~[0, ix]);
+ let rs = GEP_tup_like(cx, tup_ty, llunionptr, ~[0, ix]);
// Cast the result to the appropriate type, if necessary.
- auto val;
- if (!ty::type_has_dynamic_size(bcx_tcx(cx), elem_ty)) {
- auto llelemty = type_of(bcx_ccx(rs.bcx), cx.sp, elem_ty);
+ let val;
+ if !ty::type_has_dynamic_size(bcx_tcx(cx), elem_ty) {
+ let llelemty = type_of(bcx_ccx(rs.bcx), cx.sp, elem_ty);
val = rs.bcx.build.PointerCast(rs.val, T_ptr(llelemty));
} else { val = rs.val; }
ret rslt(rs.bcx, val);
@@ -819,12 +794,12 @@
// trans_raw_malloc: expects a type indicating which pointer type we want and
// a size indicating how much space we want malloc'd.
-fn trans_raw_malloc(&@block_ctxt cx, TypeRef llptr_ty, ValueRef llsize) ->
+fn trans_raw_malloc(cx: &@block_ctxt, llptr_ty: TypeRef, llsize: ValueRef) ->
result {
// FIXME: need a table to collect tydesc globals.
- auto tydesc = C_null(T_ptr(bcx_ccx(cx).tydesc_type));
- auto rval =
+ let tydesc = C_null(T_ptr(bcx_ccx(cx).tydesc_type));
+ let rval =
cx.build.Call(bcx_ccx(cx).upcalls.malloc,
~[cx.fcx.lltaskptr, llsize, tydesc]);
ret rslt(cx, cx.build.PointerCast(rval, llptr_ty));
@@ -832,12 +807,12 @@
// trans_shared_malloc: expects a type indicating which pointer type we want
// and a size indicating how much space we want malloc'd.
-fn trans_shared_malloc(&@block_ctxt cx, TypeRef llptr_ty, ValueRef llsize) ->
- result {
+fn trans_shared_malloc(cx: &@block_ctxt, llptr_ty: TypeRef, llsize: ValueRef)
+ -> result {
// FIXME: need a table to collect tydesc globals.
- auto tydesc = C_null(T_ptr(bcx_ccx(cx).tydesc_type));
- auto rval =
+ let tydesc = C_null(T_ptr(bcx_ccx(cx).tydesc_type));
+ let rval =
cx.build.Call(bcx_ccx(cx).upcalls.shared_malloc,
~[cx.fcx.lltaskptr, llsize, tydesc]);
ret rslt(cx, cx.build.PointerCast(rval, llptr_ty));
@@ -846,7 +821,7 @@
// trans_malloc_boxed: expects an unboxed type and returns a pointer to enough
// space for something of that type, along with space for a reference count;
// in other words, it allocates a box for something of that type.
-fn trans_malloc_boxed(&@block_ctxt cx, ty::t t) -> result {
+fn trans_malloc_boxed(cx: &@block_ctxt, t: ty::t) -> result {
// Synthesize a fake box type structurally so we have something
// to measure the size of.
@@ -855,17 +830,17 @@
// size of; box_ptr is the type that's converted to a TypeRef and used as
// the pointer cast target in trans_raw_malloc.
- auto boxed_body =
- ty::mk_imm_tup(bcx_tcx(cx),
- // The mk_int here is the space being
- // reserved for the refcount.
- ~[ty::mk_int(bcx_tcx(cx)), t]);
- auto box_ptr = ty::mk_imm_box(bcx_tcx(cx), t);
- auto sz = size_of(cx, boxed_body);
+ let
+ // The mk_int here is the space being
+ // reserved for the refcount.
+ boxed_body =
+ ty::mk_imm_tup(bcx_tcx(cx), ~[ty::mk_int(bcx_tcx(cx)), t]);
+ let box_ptr = ty::mk_imm_box(bcx_tcx(cx), t);
+ let sz = size_of(cx, boxed_body);
// Grab the TypeRef type of box_ptr, because that's what trans_raw_malloc
// wants.
- auto llty = type_of(bcx_ccx(cx), cx.sp, box_ptr);
+ let llty = type_of(bcx_ccx(cx), cx.sp, box_ptr);
ret trans_raw_malloc(sz.bcx, llty, sz.val);
}
@@ -875,10 +850,10 @@
// Given a type and a field index into its corresponding type descriptor,
// returns an LLVM ValueRef of that field from the tydesc, generating the
// tydesc if necessary.
-fn field_of_tydesc(&@block_ctxt cx, &ty::t t, bool escapes, int field) ->
+fn field_of_tydesc(cx: &@block_ctxt, t: &ty::t, escapes: bool, field: int) ->
result {
- auto ti = none[@tydesc_info];
- auto tydesc = get_tydesc(cx, t, escapes, ti);
+ let ti = none[@tydesc_info];
+ let tydesc = get_tydesc(cx, t, escapes, ti);
ret rslt(tydesc.bcx,
tydesc.bcx.build.GEP(tydesc.val, ~[C_int(0), C_int(field)]));
}
@@ -888,44 +863,43 @@
// each of the ty params it uses (from the current frame) and a vector of the
// indices of the ty params present in the type. This is used solely for
// constructing derived tydescs.
-fn linearize_ty_params(&@block_ctxt cx, &ty::t t)
- -> rec(uint[] params, ValueRef[] descs) {
- let ValueRef[] param_vals = ~[];
- let uint[] param_defs = ~[];
- type rr = rec(@block_ctxt cx,
- mutable ValueRef[] vals,
- mutable uint[] defs);
+fn linearize_ty_params(cx: &@block_ctxt, t: &ty::t) ->
+ {params: uint[], descs: ValueRef[]} {
+ let param_vals: ValueRef[] = ~[];
+ let param_defs: uint[] = ~[];
+ type rr =
+ {cx: @block_ctxt, mutable vals: ValueRef[], mutable defs: uint[]};
- fn linearizer(@rr r, ty::t t) {
- alt (ty::struct(bcx_tcx(r.cx), t)) {
- case (ty::ty_param(?pid)) {
- let bool seen = false;
- for (uint d in r.defs) { if (d == pid) { seen = true; } }
- if (!seen) {
- r.vals += ~[r.cx.fcx.lltydescs.(pid)];
- r.defs += ~[pid];
- }
+ fn linearizer(r: @rr, t: ty::t) {
+ alt ty::struct(bcx_tcx(r.cx), t) {
+ ty::ty_param(pid) {
+ let seen: bool = false;
+ for d: uint in r.defs { if d == pid { seen = true; } }
+ if !seen {
+ r.vals += ~[r.cx.fcx.lltydescs.(pid)];
+ r.defs += ~[pid];
}
- case (_) { }
+ }
+ _ { }
}
}
- auto x = @rec(cx=cx, mutable vals=param_vals, mutable defs=param_defs);
- auto f = bind linearizer(x, _);
+ let x = @{cx: cx, mutable vals: param_vals, mutable defs: param_defs};
+ let f = bind linearizer(x, _);
ty::walk_ty(bcx_tcx(cx), f, t);
- ret rec(params=x.defs, descs=x.vals);
+ ret {params: x.defs, descs: x.vals};
}
-fn trans_stack_local_derived_tydesc(&@block_ctxt cx, ValueRef llsz,
- ValueRef llalign, ValueRef llroottydesc,
- ValueRef llparamtydescs) -> ValueRef {
- auto llmyroottydesc = alloca(cx, bcx_ccx(cx).tydesc_type);
+fn trans_stack_local_derived_tydesc(cx: &@block_ctxt, llsz: ValueRef,
+ llalign: ValueRef, llroottydesc: ValueRef,
+ llparamtydescs: ValueRef) -> ValueRef {
+ let llmyroottydesc = alloca(cx, bcx_ccx(cx).tydesc_type);
// By convention, desc 0 is the root descriptor.
llroottydesc = cx.build.Load(llroottydesc);
cx.build.Store(llroottydesc, llmyroottydesc);
// Store a pointer to the rest of the descriptors.
- auto llfirstparam = cx.build.GEP(llparamtydescs, ~[C_int(0), C_int(0)]);
+ let llfirstparam = cx.build.GEP(llparamtydescs, ~[C_int(0), C_int(0)]);
cx.build.Store(llfirstparam,
cx.build.GEP(llmyroottydesc, ~[C_int(0), C_int(0)]));
cx.build.Store(llsz, cx.build.GEP(llmyroottydesc, ~[C_int(0), C_int(1)]));
@@ -934,63 +908,63 @@
ret llmyroottydesc;
}
-fn get_derived_tydesc(&@block_ctxt cx, &ty::t t, bool escapes,
- &mutable option::t[@tydesc_info] static_ti) -> result {
- alt (cx.fcx.derived_tydescs.find(t)) {
- case (some(?info)) {
+fn get_derived_tydesc(cx: &@block_ctxt, t: &ty::t, escapes: bool,
+ static_ti: &mutable option::t[@tydesc_info]) -> result {
+ alt cx.fcx.derived_tydescs.find(t) {
+ some(info) {
- // If the tydesc escapes in this context, the cached derived
- // tydesc also has to be one that was marked as escaping.
- if (!(escapes && !info.escapes)) { ret rslt(cx, info.lltydesc); }
- }
- case (none) {/* fall through */ }
+
+ // If the tydesc escapes in this context, the cached derived
+ // tydesc also has to be one that was marked as escaping.
+ if !(escapes && !info.escapes) { ret rslt(cx, info.lltydesc); }
+ }
+ none. {/* fall through */ }
}
bcx_ccx(cx).stats.n_derived_tydescs += 1u;
- auto bcx = new_raw_block_ctxt(cx.fcx, cx.fcx.llderivedtydescs);
- let uint n_params = ty::count_ty_params(bcx_tcx(bcx), t);
- auto tys = linearize_ty_params(bcx, t);
+ let bcx = new_raw_block_ctxt(cx.fcx, cx.fcx.llderivedtydescs);
+ let n_params: uint = ty::count_ty_params(bcx_tcx(bcx), t);
+ let tys = linearize_ty_params(bcx, t);
assert (n_params == std::ivec::len[uint](tys.params));
assert (n_params == std::ivec::len[ValueRef](tys.descs));
- auto root_ti = get_static_tydesc(bcx, t, tys.params);
+ let root_ti = get_static_tydesc(bcx, t, tys.params);
static_ti = some[@tydesc_info](root_ti);
lazily_emit_all_tydesc_glue(cx, static_ti);
- auto root = root_ti.tydesc;
- auto sz = size_of(bcx, t);
+ let root = root_ti.tydesc;
+ let sz = size_of(bcx, t);
bcx = sz.bcx;
- auto align = align_of(bcx, t);
+ let align = align_of(bcx, t);
bcx = align.bcx;
- auto v;
- if (escapes) {
- auto tydescs =
- alloca(bcx, /* for root*/
+ let v;
+ if escapes {
+ let /* for root*/
- T_array(T_ptr(bcx_ccx(bcx).tydesc_type),
- 1u + n_params));
- auto i = 0;
- auto tdp = bcx.build.GEP(tydescs, ~[C_int(0), C_int(i)]);
+ tydescs =
+ alloca(bcx,
+ T_array(T_ptr(bcx_ccx(bcx).tydesc_type), 1u + n_params));
+ let i = 0;
+ let tdp = bcx.build.GEP(tydescs, ~[C_int(0), C_int(i)]);
bcx.build.Store(root, tdp);
i += 1;
- for (ValueRef td in tys.descs) {
- auto tdp = bcx.build.GEP(tydescs, ~[C_int(0), C_int(i)]);
+ for td: ValueRef in tys.descs {
+ let tdp = bcx.build.GEP(tydescs, ~[C_int(0), C_int(i)]);
bcx.build.Store(td, tdp);
i += 1;
}
- auto lltydescsptr =
+ let lltydescsptr =
bcx.build.PointerCast(tydescs,
T_ptr(T_ptr(bcx_ccx(bcx).tydesc_type)));
- auto td_val =
+ let td_val =
bcx.build.Call(bcx_ccx(bcx).upcalls.get_type_desc,
~[bcx.fcx.lltaskptr, C_null(T_ptr(T_nil())),
sz.val, align.val, C_int(1u + n_params as int),
lltydescsptr]);
v = td_val;
} else {
- auto llparamtydescs =
- alloca(bcx,
- T_array(T_ptr(bcx_ccx(bcx).tydesc_type), n_params));
- auto i = 0;
- for (ValueRef td in tys.descs) {
- auto tdp = bcx.build.GEP(llparamtydescs, ~[C_int(0), C_int(i)]);
+ let llparamtydescs =
+ alloca(bcx, T_array(T_ptr(bcx_ccx(bcx).tydesc_type), n_params));
+ let i = 0;
+ for td: ValueRef in tys.descs {
+ let tdp = bcx.build.GEP(llparamtydescs, ~[C_int(0), C_int(i)]);
bcx.build.Store(td, tdp);
i += 1;
}
@@ -998,48 +972,49 @@
trans_stack_local_derived_tydesc(bcx, sz.val, align.val, root,
llparamtydescs);
}
- bcx.fcx.derived_tydescs.insert(t, rec(lltydesc=v, escapes=escapes));
+ bcx.fcx.derived_tydescs.insert(t, {lltydesc: v, escapes: escapes});
ret rslt(cx, v);
}
-fn get_tydesc(&@block_ctxt cx, &ty::t orig_t, bool escapes,
- &mutable option::t[@tydesc_info] static_ti) -> result {
+fn get_tydesc(cx: &@block_ctxt, orig_t: &ty::t, escapes: bool,
+ static_ti: &mutable option::t[@tydesc_info]) -> result {
- auto t = ty::strip_cname(bcx_tcx(cx), orig_t);
+ let t = ty::strip_cname(bcx_tcx(cx), orig_t);
// Is the supplied type a type param? If so, return the passed-in tydesc.
- alt (ty::type_param(bcx_tcx(cx), t)) {
- case (some(?id)) { ret rslt(cx, cx.fcx.lltydescs.(id)); }
- case (none) {/* fall through */ }
+ alt ty::type_param(bcx_tcx(cx), t) {
+ some(id) { ret rslt(cx, cx.fcx.lltydescs.(id)); }
+ none. {/* fall through */ }
}
// Does it contain a type param? If so, generate a derived tydesc.
- if (ty::type_contains_params(bcx_tcx(cx), t)) {
+ if ty::type_contains_params(bcx_tcx(cx), t) {
ret get_derived_tydesc(cx, t, escapes, static_ti);
}
// Otherwise, generate a tydesc if necessary, and return it.
- auto info = get_static_tydesc(cx, t, ~[]);
+ let info = get_static_tydesc(cx, t, ~[]);
static_ti = some[@tydesc_info](info);
ret rslt(cx, info.tydesc);
}
-fn get_static_tydesc(&@block_ctxt cx, &ty::t orig_t, &uint[] ty_params)
- -> @tydesc_info {
- auto t = ty::strip_cname(bcx_tcx(cx), orig_t);
+fn get_static_tydesc(cx: &@block_ctxt, orig_t: &ty::t, ty_params: &uint[]) ->
+ @tydesc_info {
+ let t = ty::strip_cname(bcx_tcx(cx), orig_t);
- alt (bcx_ccx(cx).tydescs.find(t)) {
- case (some(?info)) { ret info; }
- case (none) {
- bcx_ccx(cx).stats.n_static_tydescs += 1u;
- auto info = declare_tydesc(cx.fcx.lcx, cx.sp, t, ty_params);
- bcx_ccx(cx).tydescs.insert(t, info);
- ret info;
- }
+
+ alt bcx_ccx(cx).tydescs.find(t) {
+ some(info) { ret info; }
+ none. {
+ bcx_ccx(cx).stats.n_static_tydescs += 1u;
+ let info = declare_tydesc(cx.fcx.lcx, cx.sp, t, ty_params);
+ bcx_ccx(cx).tydescs.insert(t, info);
+ ret info;
+ }
}
}
-fn set_no_inline(ValueRef f) {
+fn set_no_inline(f: ValueRef) {
llvm::LLVMAddFunctionAttr(f,
lib::llvm::LLVMNoInlineAttribute as
lib::llvm::llvm::Attribute);
@@ -1047,34 +1022,34 @@
// Tell LLVM to emit the information necessary to unwind the stack for the
// function f.
-fn set_uwtable(ValueRef f) {
+fn set_uwtable(f: ValueRef) {
llvm::LLVMAddFunctionAttr(f,
lib::llvm::LLVMUWTableAttribute as
lib::llvm::llvm::Attribute);
}
-fn set_always_inline(ValueRef f) {
+fn set_always_inline(f: ValueRef) {
llvm::LLVMAddFunctionAttr(f,
lib::llvm::LLVMAlwaysInlineAttribute as
lib::llvm::llvm::Attribute);
}
-fn set_glue_inlining(&@local_ctxt cx, ValueRef f, &ty::t t) {
- if (ty::type_is_structural(cx.ccx.tcx, t)) {
+fn set_glue_inlining(cx: &@local_ctxt, f: ValueRef, t: &ty::t) {
+ if ty::type_is_structural(cx.ccx.tcx, t) {
set_no_inline(f);
} else { set_always_inline(f); }
}
// Generates the declaration for (but doesn't emit) a type descriptor.
-fn declare_tydesc(&@local_ctxt cx, &span sp, &ty::t t, &uint[] ty_params)
- -> @tydesc_info {
+fn declare_tydesc(cx: &@local_ctxt, sp: &span, t: &ty::t, ty_params: &uint[])
+ -> @tydesc_info {
log "+++ declare_tydesc " + ty_to_str(cx.ccx.tcx, t);
- auto ccx = cx.ccx;
- auto llsize;
- auto llalign;
- if (!ty::type_has_dynamic_size(ccx.tcx, t)) {
- auto llty = type_of(ccx, sp, t);
+ let ccx = cx.ccx;
+ let llsize;
+ let llalign;
+ if !ty::type_has_dynamic_size(ccx.tcx, t) {
+ let llty = type_of(ccx, sp, t);
llsize = llsize_of(llty);
llalign = llalign_of(llty);
} else {
@@ -1084,23 +1059,23 @@
llsize = C_int(0);
llalign = C_int(0);
}
- auto name;
- if (cx.ccx.sess.get_opts().debuginfo) {
+ let name;
+ if cx.ccx.sess.get_opts().debuginfo {
name = mangle_internal_name_by_type_only(cx.ccx, t, "tydesc");
name = sanitize(name);
} else { name = mangle_internal_name_by_seq(cx.ccx, "tydesc"); }
- auto gvar =
+ let gvar =
llvm::LLVMAddGlobal(ccx.llmod, ccx.tydesc_type, str::buf(name));
- auto info =
- @rec(ty=t,
- tydesc=gvar,
- size=llsize,
- align=llalign,
- mutable copy_glue=none[ValueRef],
- mutable drop_glue=none[ValueRef],
- mutable free_glue=none[ValueRef],
- mutable cmp_glue=none[ValueRef],
- ty_params=ty_params);
+ let info =
+ @{ty: t,
+ tydesc: gvar,
+ size: llsize,
+ align: llalign,
+ mutable copy_glue: none[ValueRef],
+ mutable drop_glue: none[ValueRef],
+ mutable free_glue: none[ValueRef],
+ mutable cmp_glue: none[ValueRef],
+ ty_params: ty_params};
log "--- declare_tydesc " + ty_to_str(cx.ccx.tcx, t);
ret info;
}
@@ -1110,22 +1085,23 @@
mgghf_cmp;
}
-fn declare_generic_glue(&@local_ctxt cx, &ty::t t, TypeRef llfnty, &str name)
- -> ValueRef {
- auto fn_nm;
- if (cx.ccx.sess.get_opts().debuginfo) {
+fn declare_generic_glue(cx: &@local_ctxt, t: &ty::t, llfnty: TypeRef,
+ name: &str) -> ValueRef {
+ let fn_nm;
+ if cx.ccx.sess.get_opts().debuginfo {
fn_nm = mangle_internal_name_by_type_only(cx.ccx, t, "glue_" + name);
fn_nm = sanitize(fn_nm);
} else { fn_nm = mangle_internal_name_by_seq(cx.ccx, "glue_" + name); }
- auto llfn = decl_cdecl_fn(cx.ccx.llmod, fn_nm, llfnty);
+ let llfn = decl_cdecl_fn(cx.ccx.llmod, fn_nm, llfnty);
set_glue_inlining(cx, llfn, t);
ret llfn;
}
-fn make_generic_glue_inner(&@local_ctxt cx, &span sp, &ty::t t, ValueRef llfn,
- &make_generic_glue_helper_fn helper,
- &uint[] ty_params) -> ValueRef {
- auto fcx = new_fn_ctxt(cx, sp, llfn);
+fn make_generic_glue_inner(cx: &@local_ctxt, sp: &span, t: &ty::t,
+ llfn: ValueRef,
+ helper: &make_generic_glue_helper_fn,
+ ty_params: &uint[]) -> ValueRef {
+ let fcx = new_fn_ctxt(cx, sp, llfn);
llvm::LLVMSetLinkage(llfn,
lib::llvm::LLVMInternalLinkage as llvm::Linkage);
cx.ccx.stats.n_glues_created += 1u;
@@ -1134,111 +1110,100 @@
// the caller has no idea if it's dealing with something that can be
// passed by value.
- auto llty;
- if (ty::type_has_dynamic_size(cx.ccx.tcx, t)) {
+ let llty;
+ if ty::type_has_dynamic_size(cx.ccx.tcx, t) {
llty = T_ptr(T_i8());
} else { llty = T_ptr(type_of(cx.ccx, sp, t)); }
- auto ty_param_count = std::ivec::len[uint](ty_params);
- auto lltyparams = llvm::LLVMGetParam(llfn, 3u);
- auto copy_args_bcx = new_raw_block_ctxt(fcx, fcx.llcopyargs);
- auto lltydescs = ~[mutable];
- auto p = 0u;
- while (p < ty_param_count) {
- auto llparam = copy_args_bcx.build.GEP(lltyparams,
- ~[C_int(p as int)]);
+ let ty_param_count = std::ivec::len[uint](ty_params);
+ let lltyparams = llvm::LLVMGetParam(llfn, 3u);
+ let copy_args_bcx = new_raw_block_ctxt(fcx, fcx.llcopyargs);
+ let lltydescs = ~[mutable ];
+ let p = 0u;
+ while p < ty_param_count {
+ let llparam = copy_args_bcx.build.GEP(lltyparams, ~[C_int(p as int)]);
llparam = copy_args_bcx.build.Load(llparam);
std::ivec::grow_set(lltydescs, ty_params.(p), 0 as ValueRef, llparam);
p += 1u;
}
// TODO: Implement some kind of freeze operation in the standard library.
- auto lltydescs_frozen = ~[];
- for (ValueRef lltydesc in lltydescs) { lltydescs_frozen += ~[lltydesc]; }
+ let lltydescs_frozen = ~[];
+ for lltydesc: ValueRef in lltydescs { lltydescs_frozen += ~[lltydesc]; }
fcx.lltydescs = lltydescs_frozen;
- auto bcx = new_top_block_ctxt(fcx);
- auto lltop = bcx.llbb;
- auto llrawptr0 = llvm::LLVMGetParam(llfn, 4u);
- auto llval0 = bcx.build.BitCast(llrawptr0, llty);
- alt (helper) {
- case (mgghf_single(?single_fn)) { single_fn(bcx, llval0, t); }
- case (mgghf_cmp) {
- auto llrawptr1 = llvm::LLVMGetParam(llfn, 5u);
- auto llval1 = bcx.build.BitCast(llrawptr1, llty);
- auto llcmpval = llvm::LLVMGetParam(llfn, 6u);
- make_cmp_glue(bcx, llval0, llval1, t, llcmpval);
- }
+ let bcx = new_top_block_ctxt(fcx);
+ let lltop = bcx.llbb;
+ let llrawptr0 = llvm::LLVMGetParam(llfn, 4u);
+ let llval0 = bcx.build.BitCast(llrawptr0, llty);
+ alt helper {
+ mgghf_single(single_fn) { single_fn(bcx, llval0, t); }
+ mgghf_cmp. {
+ let llrawptr1 = llvm::LLVMGetParam(llfn, 5u);
+ let llval1 = bcx.build.BitCast(llrawptr1, llty);
+ let llcmpval = llvm::LLVMGetParam(llfn, 6u);
+ make_cmp_glue(bcx, llval0, llval1, t, llcmpval);
+ }
}
finish_fn(fcx, lltop);
ret llfn;
}
-fn make_generic_glue(&@local_ctxt cx, &span sp, &ty::t t, ValueRef llfn,
- &make_generic_glue_helper_fn helper,
- &uint[] ty_params, &str name) -> ValueRef {
+fn make_generic_glue(cx: &@local_ctxt, sp: &span, t: &ty::t, llfn: ValueRef,
+ helper: &make_generic_glue_helper_fn, ty_params: &uint[],
+ name: &str) -> ValueRef {
if !cx.ccx.sess.get_opts().stats {
ret make_generic_glue_inner(cx, sp, t, llfn, helper, ty_params);
}
- auto start = time::get_time();
- auto llval = make_generic_glue_inner(cx, sp, t, llfn, helper, ty_params);
- auto end = time::get_time();
+ let start = time::get_time();
+ let llval = make_generic_glue_inner(cx, sp, t, llfn, helper, ty_params);
+ let end = time::get_time();
log_fn_time(cx.ccx, "glue " + name + " " + ty_to_short_str(cx.ccx.tcx, t),
start, end);
ret llval;
}
-fn emit_tydescs(&@crate_ctxt ccx) {
- for each (@rec(ty::t key, @tydesc_info val) pair
- in ccx.tydescs.items()) {
- auto glue_fn_ty = T_ptr(T_glue_fn(*ccx));
- auto cmp_fn_ty = T_ptr(T_cmp_glue_fn(*ccx));
- auto ti = pair.val;
- auto copy_glue =
- alt ({ ti.copy_glue }) {
- case (none) {
- ccx.stats.n_null_glues += 1u;
- C_null(glue_fn_ty)
- }
- case (some(?v)) { ccx.stats.n_real_glues += 1u; v }
+fn emit_tydescs(ccx: &@crate_ctxt) {
+ for each pair: @{key: ty::t, val: @tydesc_info} in ccx.tydescs.items() {
+ let glue_fn_ty = T_ptr(T_glue_fn(*ccx));
+ let cmp_fn_ty = T_ptr(T_cmp_glue_fn(*ccx));
+ let ti = pair.val;
+ let copy_glue =
+ alt { ti.copy_glue } {
+ none. { ccx.stats.n_null_glues += 1u; C_null(glue_fn_ty) }
+ some(v) { ccx.stats.n_real_glues += 1u; v }
};
- auto drop_glue =
- alt ({ ti.drop_glue }) {
- case (none) {
- ccx.stats.n_null_glues += 1u;
- C_null(glue_fn_ty)
- }
- case (some(?v)) { ccx.stats.n_real_glues += 1u; v }
+ let drop_glue =
+ alt { ti.drop_glue } {
+ none. { ccx.stats.n_null_glues += 1u; C_null(glue_fn_ty) }
+ some(v) { ccx.stats.n_real_glues += 1u; v }
};
- auto free_glue =
- alt ({ ti.free_glue }) {
- case (none) {
- ccx.stats.n_null_glues += 1u;
- C_null(glue_fn_ty)
- }
- case (some(?v)) { ccx.stats.n_real_glues += 1u; v }
+ let free_glue =
+ alt { ti.free_glue } {
+ none. { ccx.stats.n_null_glues += 1u; C_null(glue_fn_ty) }
+ some(v) { ccx.stats.n_real_glues += 1u; v }
};
- auto cmp_glue =
- alt ({ ti.cmp_glue }) {
- case (none) {
- ccx.stats.n_null_glues += 1u;
- C_null(cmp_fn_ty)
- }
- case (some(?v)) { ccx.stats.n_real_glues += 1u; v }
+ let cmp_glue =
+ alt { ti.cmp_glue } {
+ none. { ccx.stats.n_null_glues += 1u; C_null(cmp_fn_ty) }
+ some(v) { ccx.stats.n_real_glues += 1u; v }
};
- auto tydesc =
+ let // copy_glue
+ // drop_glue
+ // free_glue
+ // sever_glue
+ // mark_glue
+ // obj_drop_glue
+ // is_stateful
+ tydesc =
C_named_struct(ccx.tydesc_type,
- ~[C_null(T_ptr(T_ptr(ccx.tydesc_type))), ti.size,
- ti.align, copy_glue, // copy_glue
- drop_glue, // drop_glue
- free_glue, // free_glue
- C_null(glue_fn_ty), // sever_glue
- C_null(glue_fn_ty), // mark_glue
- C_null(glue_fn_ty), // obj_drop_glue
- C_null(glue_fn_ty), // is_stateful
- cmp_glue]); // cmp_glue
+ ~[C_null(T_ptr(T_ptr(ccx.tydesc_type))), ti.size,
+ ti.align, copy_glue, drop_glue, free_glue,
+ C_null(glue_fn_ty), C_null(glue_fn_ty),
+ C_null(glue_fn_ty), C_null(glue_fn_ty),
+ cmp_glue]); // cmp_glue
- auto gvar = ti.tydesc;
+ let gvar = ti.tydesc;
llvm::LLVMSetInitializer(gvar, tydesc);
llvm::LLVMSetGlobalConstant(gvar, True);
llvm::LLVMSetLinkage(gvar,
@@ -1246,11 +1211,11 @@
}
}
-fn make_copy_glue(&@block_ctxt cx, ValueRef v, &ty::t t) {
+fn make_copy_glue(cx: &@block_ctxt, v: ValueRef, t: &ty::t) {
// NB: v is an *alias* of type t here, not a direct value.
- auto bcx;
- if (ty::type_is_boxed(bcx_tcx(cx), t)) {
+ let bcx;
+ if ty::type_is_boxed(bcx_tcx(cx), t) {
bcx = incr_refcnt_of_boxed(cx, cx.build.Load(v)).bcx;
} else if (ty::type_is_structural(bcx_tcx(cx), t)) {
bcx = duplicate_heap_parts_if_necessary(cx, v, t).bcx;
@@ -1259,13 +1224,13 @@
bcx.build.RetVoid();
}
-fn incr_refcnt_of_boxed(&@block_ctxt cx, ValueRef box_ptr) -> result {
- auto rc_ptr =
+fn incr_refcnt_of_boxed(cx: &@block_ctxt, box_ptr: ValueRef) -> result {
+ let rc_ptr =
cx.build.GEP(box_ptr, ~[C_int(0), C_int(abi::box_rc_field_refcnt)]);
- auto rc = cx.build.Load(rc_ptr);
- auto rc_adj_cx = new_sub_block_ctxt(cx, "rc++");
- auto next_cx = new_sub_block_ctxt(cx, "next");
- auto const_test =
+ let rc = cx.build.Load(rc_ptr);
+ let rc_adj_cx = new_sub_block_ctxt(cx, "rc++");
+ let next_cx = new_sub_block_ctxt(cx, "next");
+ let const_test =
cx.build.ICmp(lib::llvm::LLVMIntEQ, C_int(abi::const_refcount as int),
rc);
cx.build.CondBr(const_test, next_cx.llbb, rc_adj_cx.llbb);
@@ -1275,221 +1240,221 @@
ret rslt(next_cx, C_nil());
}
-fn make_free_glue(&@block_ctxt cx, ValueRef v0, &ty::t t) {
+fn make_free_glue(cx: &@block_ctxt, v0: ValueRef, t: &ty::t) {
// NB: v is an *alias* of type t here, not a direct value.
- auto rs = alt (ty::struct(bcx_tcx(cx), t)) {
- case (ty::ty_str) {
- auto v = cx.build.Load(v0);
- trans_non_gc_free(cx, v)
- }
- case (ty::ty_vec(_)) {
- auto v = cx.build.Load(v0);
- auto rs = iter_sequence(cx, v, t, bind drop_ty(_, _, _));
- // FIXME: switch gc/non-gc on layer of the type.
+ let
+ // FIXME: switch gc/non-gc on layer of the type.
+ // FIXME: switch gc/non-gc on layer of the type.
+ // TODO: call upcall_kill
+
+
+ // Call through the obj's own fields-drop glue first.
+
+ // Then free the body.
+ // FIXME: switch gc/non-gc on layer of the type.
+ // Call through the closure's own fields-drop glue first.
+
+ // Then free the body.
+ // FIXME: switch gc/non-gc on layer of the type.
+ rs =
+ alt ty::struct(bcx_tcx(cx), t) {
+ ty::ty_str. { let v = cx.build.Load(v0); trans_non_gc_free(cx, v) }
+ ty::ty_vec(_) {
+ let v = cx.build.Load(v0);
+ let rs = iter_sequence(cx, v, t, bind drop_ty(_, _, _));
trans_non_gc_free(rs.bcx, v)
- }
- case (ty::ty_box(?body_mt)) {
- auto v = cx.build.Load(v0);
- auto body =
+ }
+ ty::ty_box(body_mt) {
+ let v = cx.build.Load(v0);
+ let body =
cx.build.GEP(v, ~[C_int(0), C_int(abi::box_rc_field_body)]);
- auto body_ty = body_mt.ty;
- auto body_val = load_if_immediate(cx, body, body_ty);
- auto rs = drop_ty(cx, body_val, body_ty);
- // FIXME: switch gc/non-gc on layer of the type.
+ let body_ty = body_mt.ty;
+ let body_val = load_if_immediate(cx, body, body_ty);
+ let rs = drop_ty(cx, body_val, body_ty);
trans_non_gc_free(rs.bcx, v)
- }
- case (ty::ty_port(_)) {
- auto v = cx.build.Load(v0);
+ }
+ ty::ty_port(_) {
+ let v = cx.build.Load(v0);
cx.build.Call(bcx_ccx(cx).upcalls.del_port,
~[cx.fcx.lltaskptr,
cx.build.PointerCast(v, T_opaque_port_ptr())]);
rslt(cx, C_int(0))
- }
- case (ty::ty_chan(_)) {
- auto v = cx.build.Load(v0);
+ }
+ ty::ty_chan(_) {
+ let v = cx.build.Load(v0);
cx.build.Call(bcx_ccx(cx).upcalls.del_chan,
~[cx.fcx.lltaskptr,
cx.build.PointerCast(v, T_opaque_chan_ptr())]);
rslt(cx, C_int(0))
- }
- case (ty::ty_task) {
- // TODO: call upcall_kill
- rslt(cx, C_nil())
- }
- case (ty::ty_obj(_)) {
- auto box_cell =
+ }
+ ty::ty_task. { rslt(cx, C_nil()) }
+ ty::ty_obj(_) {
+ let box_cell =
cx.build.GEP(v0, ~[C_int(0), C_int(abi::obj_field_box)]);
- auto b = cx.build.Load(box_cell);
-
- auto ccx = bcx_ccx(cx);
- auto llbox_ty = T_opaque_obj_ptr(*ccx);
+ let b = cx.build.Load(box_cell);
+ let ccx = bcx_ccx(cx);
+ let llbox_ty = T_opaque_obj_ptr(*ccx);
b = cx.build.PointerCast(b, llbox_ty);
-
- auto body =
+ let body =
cx.build.GEP(b, ~[C_int(0), C_int(abi::box_rc_field_body)]);
- auto tydescptr =
+ let tydescptr =
cx.build.GEP(body,
~[C_int(0), C_int(abi::obj_body_elt_tydesc)]);
- auto tydesc = cx.build.Load(tydescptr);
- auto cx_ = maybe_call_dtor(cx, v0);
- // Call through the obj's own fields-drop glue first.
-
- auto ti = none[@tydesc_info];
+ let tydesc = cx.build.Load(tydescptr);
+ let cx_ = maybe_call_dtor(cx, v0);
+ let ti = none[@tydesc_info];
call_tydesc_glue_full(cx_, body, tydesc,
abi::tydesc_field_drop_glue, ti);
- // Then free the body.
- // FIXME: switch gc/non-gc on layer of the type.
trans_non_gc_free(cx_, b)
- }
- case (ty::ty_fn(_, _, _, _, _)) {
- auto box_cell =
+ }
+ ty::ty_fn(_, _, _, _, _) {
+ let box_cell =
cx.build.GEP(v0, ~[C_int(0), C_int(abi::fn_field_box)]);
- auto v = cx.build.Load(box_cell);
- // Call through the closure's own fields-drop glue first.
-
- auto body =
+ let v = cx.build.Load(box_cell);
+ let body =
cx.build.GEP(v, ~[C_int(0), C_int(abi::box_rc_field_body)]);
- auto bindings =
+ let bindings =
cx.build.GEP(body,
~[C_int(0), C_int(abi::closure_elt_bindings)]);
- auto tydescptr =
+ let tydescptr =
cx.build.GEP(body,
~[C_int(0), C_int(abi::closure_elt_tydesc)]);
- auto ti = none[@tydesc_info];
+ let ti = none[@tydesc_info];
call_tydesc_glue_full(cx, bindings, cx.build.Load(tydescptr),
abi::tydesc_field_drop_glue, ti);
- // Then free the body.
- // FIXME: switch gc/non-gc on layer of the type.
trans_non_gc_free(cx, v)
- }
- case (_) { rslt(cx, C_nil()) }
- };
+ }
+ _ { rslt(cx, C_nil()) }
+ };
rs.bcx.build.RetVoid();
}
-fn maybe_free_ivec_heap_part(&@block_ctxt cx, ValueRef v0, ty::t unit_ty) ->
- result {
- auto llunitty = type_of_or_i8(cx, unit_ty);
- auto stack_len =
+fn maybe_free_ivec_heap_part(cx: &@block_ctxt, v0: ValueRef, unit_ty: ty::t)
+ -> result {
+ let llunitty = type_of_or_i8(cx, unit_ty);
+ let stack_len =
cx.build.Load(cx.build.InBoundsGEP(v0,
~[C_int(0),
C_uint(abi::ivec_elt_len)]));
- auto maybe_on_heap_cx = new_sub_block_ctxt(cx, "maybe_on_heap");
- auto next_cx = new_sub_block_ctxt(cx, "next");
- auto maybe_on_heap =
+ let maybe_on_heap_cx = new_sub_block_ctxt(cx, "maybe_on_heap");
+ let next_cx = new_sub_block_ctxt(cx, "next");
+ let maybe_on_heap =
cx.build.ICmp(lib::llvm::LLVMIntEQ, stack_len, C_int(0));
cx.build.CondBr(maybe_on_heap, maybe_on_heap_cx.llbb, next_cx.llbb);
// Might be on the heap. Load the heap pointer and free it. (It's ok to
// free a null pointer.)
- auto stub_ptr =
+ let stub_ptr =
maybe_on_heap_cx.build.PointerCast(v0, T_ptr(T_ivec_heap(llunitty)));
- auto heap_ptr =
+ let heap_ptr =
{
- auto v = ~[C_int(0), C_uint(abi::ivec_heap_stub_elt_ptr)];
- auto m = maybe_on_heap_cx.build.InBoundsGEP(stub_ptr, v);
+ let v = ~[C_int(0), C_uint(abi::ivec_heap_stub_elt_ptr)];
+ let m = maybe_on_heap_cx.build.InBoundsGEP(stub_ptr, v);
maybe_on_heap_cx.build.Load(m)
};
- auto after_free_cx = trans_shared_free(maybe_on_heap_cx, heap_ptr).bcx;
+ let after_free_cx = trans_shared_free(maybe_on_heap_cx, heap_ptr).bcx;
after_free_cx.build.Br(next_cx.llbb);
ret rslt(next_cx, C_nil());
}
-fn make_drop_glue(&@block_ctxt cx, ValueRef v0, &ty::t t) {
+fn make_drop_glue(cx: &@block_ctxt, v0: ValueRef, t: &ty::t) {
// NB: v0 is an *alias* of type t here, not a direct value.
- auto ccx = bcx_ccx(cx);
- auto rs = alt (ty::struct(ccx.tcx, t)) {
- case (ty::ty_str) { decr_refcnt_maybe_free(cx, v0, v0, t) }
- case (ty::ty_vec(_)) { decr_refcnt_maybe_free(cx, v0, v0, t) }
- case (ty::ty_ivec(?tm)) {
- auto v1;
- if (ty::type_has_dynamic_size(ccx.tcx, tm.ty)) {
- v1 = cx.build.PointerCast(v0, T_ptr(T_opaque_ivec()));
- } else {
- v1 = v0;
- }
+ let ccx = bcx_ccx(cx);
+ let
- auto rslt = iter_structural_ty(cx, v1, t, drop_ty);
+ rs =
+ alt ty::struct(ccx.tcx, t) {
+ ty::ty_str. { decr_refcnt_maybe_free(cx, v0, v0, t) }
+ ty::ty_vec(_) { decr_refcnt_maybe_free(cx, v0, v0, t) }
+ ty::ty_ivec(tm) {
+ let v1;
+ if ty::type_has_dynamic_size(ccx.tcx, tm.ty) {
+ v1 = cx.build.PointerCast(v0, T_ptr(T_opaque_ivec()));
+ } else { v1 = v0; }
+ let rslt = iter_structural_ty(cx, v1, t, drop_ty);
maybe_free_ivec_heap_part(rslt.bcx, v1, tm.ty)
- }
- case (ty::ty_box(_)) { decr_refcnt_maybe_free(cx, v0, v0, t) }
- case (ty::ty_port(_)) { decr_refcnt_maybe_free(cx, v0, v0, t) }
- case (ty::ty_chan(_)) { decr_refcnt_maybe_free(cx, v0, v0, t) }
- case (ty::ty_task) { decr_refcnt_maybe_free(cx, v0, v0, t) }
- case (ty::ty_obj(_)) {
- auto box_cell =
+ }
+ ty::ty_box(_) { decr_refcnt_maybe_free(cx, v0, v0, t) }
+ ty::ty_port(_) { decr_refcnt_maybe_free(cx, v0, v0, t) }
+ ty::ty_chan(_) { decr_refcnt_maybe_free(cx, v0, v0, t) }
+ ty::ty_task. { decr_refcnt_maybe_free(cx, v0, v0, t) }
+ ty::ty_obj(_) {
+ let box_cell =
cx.build.GEP(v0, ~[C_int(0), C_int(abi::obj_field_box)]);
decr_refcnt_maybe_free(cx, box_cell, v0, t)
- }
- case (ty::ty_res(?did, ?inner, ?tps)) {
+ }
+ ty::ty_res(did, inner, tps) {
trans_res_drop(cx, v0, did, inner, tps)
- }
- case (ty::ty_fn(_, _, _, _, _)) {
- auto box_cell =
+ }
+ ty::ty_fn(_, _, _, _, _) {
+ let box_cell =
cx.build.GEP(v0, ~[C_int(0), C_int(abi::fn_field_box)]);
decr_refcnt_maybe_free(cx, box_cell, v0, t)
- }
- case (_) {
- if (ty::type_has_pointers(ccx.tcx, t) &&
- ty::type_is_structural(ccx.tcx, t)) {
+ }
+ _ {
+ if ty::type_has_pointers(ccx.tcx, t) &&
+ ty::type_is_structural(ccx.tcx, t) {
iter_structural_ty(cx, v0, t, bind drop_ty(_, _, _))
} else { rslt(cx, C_nil()) }
- }
- };
+ }
+ };
rs.bcx.build.RetVoid();
}
-fn trans_res_drop(@block_ctxt cx, ValueRef rs, &ast::def_id did,
- ty::t inner_t, &ty::t[] tps) -> result {
- auto ccx = bcx_ccx(cx);
- auto inner_t_s = ty::substitute_type_params(ccx.tcx, tps, inner_t);
- auto tup_ty = ty::mk_imm_tup(ccx.tcx, ~[ty::mk_int(ccx.tcx), inner_t_s]);
- auto drop_cx = new_sub_block_ctxt(cx, "drop res");
- auto next_cx = new_sub_block_ctxt(cx, "next");
+fn trans_res_drop(cx: @block_ctxt, rs: ValueRef, did: &ast::def_id,
+ inner_t: ty::t, tps: &ty::t[]) -> result {
+ let ccx = bcx_ccx(cx);
+ let inner_t_s = ty::substitute_type_params(ccx.tcx, tps, inner_t);
+ let tup_ty = ty::mk_imm_tup(ccx.tcx, ~[ty::mk_int(ccx.tcx), inner_t_s]);
+ let drop_cx = new_sub_block_ctxt(cx, "drop res");
+ let next_cx = new_sub_block_ctxt(cx, "next");
- auto drop_flag = GEP_tup_like(cx, tup_ty, rs, ~[0, 0]);
+ let drop_flag = GEP_tup_like(cx, tup_ty, rs, ~[0, 0]);
cx = drop_flag.bcx;
- auto null_test = cx.build.IsNull(cx.build.Load(drop_flag.val));
+ let null_test = cx.build.IsNull(cx.build.Load(drop_flag.val));
cx.build.CondBr(null_test, next_cx.llbb, drop_cx.llbb);
cx = drop_cx;
- auto val = GEP_tup_like(cx, tup_ty, rs, ~[0, 1]);
+ let val = GEP_tup_like(cx, tup_ty, rs, ~[0, 1]);
cx = val.bcx;
// Find and call the actual destructor.
- auto dtor_pair = if (did.crate == ast::local_crate) {
- alt (ccx.fn_pairs.find(did.node)) {
- case (some(?x)) { x }
- case (_) { ccx.tcx.sess.bug("internal error in trans_res_drop") }
- }
- } else {
- auto params = csearch::get_type_param_count(ccx.sess.get_cstore(),
- did);
- auto f_t = type_of_fn(ccx, cx.sp, ast::proto_fn,
- ~[rec(mode=ty::mo_alias(false), ty=inner_t)],
- ty::mk_nil(ccx.tcx), params);
- get_extern_const(ccx.externs, ccx.llmod,
- csearch::get_symbol(ccx.sess.get_cstore(), did),
- T_fn_pair(*ccx, f_t))
- };
- auto dtor_addr = cx.build.Load
- (cx.build.GEP(dtor_pair, ~[C_int(0), C_int(abi::fn_field_code)]));
- auto dtor_env = cx.build.Load
- (cx.build.GEP(dtor_pair, ~[C_int(0), C_int(abi::fn_field_box)]));
- auto args = ~[cx.fcx.llretptr, cx.fcx.lltaskptr, dtor_env];
- for (ty::t tp in tps) {
- let option::t[@tydesc_info] ti = none;
- auto td = get_tydesc(cx, tp, false, ti);
+ let dtor_pair =
+ if did.crate == ast::local_crate {
+ alt ccx.fn_pairs.find(did.node) {
+ some(x) { x }
+ _ { ccx.tcx.sess.bug("internal error in trans_res_drop") }
+ }
+ } else {
+ let params =
+ csearch::get_type_param_count(ccx.sess.get_cstore(), did);
+ let f_t =
+ type_of_fn(ccx, cx.sp, ast::proto_fn,
+ ~[{mode: ty::mo_alias(false), ty: inner_t}],
+ ty::mk_nil(ccx.tcx), params);
+ get_extern_const(ccx.externs, ccx.llmod,
+ csearch::get_symbol(ccx.sess.get_cstore(), did),
+ T_fn_pair(*ccx, f_t))
+ };
+ let dtor_addr =
+ cx.build.Load(cx.build.GEP(dtor_pair,
+ ~[C_int(0), C_int(abi::fn_field_code)]));
+ let dtor_env =
+ cx.build.Load(cx.build.GEP(dtor_pair,
+ ~[C_int(0), C_int(abi::fn_field_box)]));
+ let args = ~[cx.fcx.llretptr, cx.fcx.lltaskptr, dtor_env];
+ for tp: ty::t in tps {
+ let ti: option::t[@tydesc_info] = none;
+ let td = get_tydesc(cx, tp, false, ti);
args += ~[td.val];
cx = td.bcx;
}
// Kludge to work around the fact that we know the precise type of the
// value here, but the dtor expects a type that still has opaque pointers
// for type variables.
- auto val_llty = lib::llvm::fn_ty_param_tys
- (llvm::LLVMGetElementType(llvm::LLVMTypeOf(dtor_addr)))
- .(std::ivec::len(args));
- auto val_cast = cx.build.BitCast(val.val, val_llty);
+ let val_llty =
+ lib::llvm::fn_ty_param_tys(llvm::LLVMGetElementType(llvm::LLVMTypeOf(dtor_addr))).(std::ivec::len(args));
+ let val_cast = cx.build.BitCast(val.val, val_llty);
cx.build.FastCall(dtor_addr, args + ~[val_cast]);
cx = drop_slot(cx, val.val, inner_t_s).bcx;
@@ -1498,36 +1463,36 @@
ret rslt(next_cx, C_nil());
}
-fn decr_refcnt_maybe_free(&@block_ctxt cx, ValueRef box_ptr_alias,
- ValueRef full_alias, &ty::t t) -> result {
- auto ccx = bcx_ccx(cx);
- auto load_rc_cx = new_sub_block_ctxt(cx, "load rc");
- auto rc_adj_cx = new_sub_block_ctxt(cx, "rc--");
- auto free_cx = new_sub_block_ctxt(cx, "free");
- auto next_cx = new_sub_block_ctxt(cx, "next");
- auto box_ptr = cx.build.Load(box_ptr_alias);
- auto llbox_ty = T_opaque_obj_ptr(*ccx);
+fn decr_refcnt_maybe_free(cx: &@block_ctxt, box_ptr_alias: ValueRef,
+ full_alias: ValueRef, t: &ty::t) -> result {
+ let ccx = bcx_ccx(cx);
+ let load_rc_cx = new_sub_block_ctxt(cx, "load rc");
+ let rc_adj_cx = new_sub_block_ctxt(cx, "rc--");
+ let free_cx = new_sub_block_ctxt(cx, "free");
+ let next_cx = new_sub_block_ctxt(cx, "next");
+ let box_ptr = cx.build.Load(box_ptr_alias);
+ let llbox_ty = T_opaque_obj_ptr(*ccx);
box_ptr = cx.build.PointerCast(box_ptr, llbox_ty);
- auto null_test = cx.build.IsNull(box_ptr);
+ let null_test = cx.build.IsNull(box_ptr);
cx.build.CondBr(null_test, next_cx.llbb, load_rc_cx.llbb);
- auto rc_ptr =
+ let rc_ptr =
load_rc_cx.build.GEP(box_ptr,
~[C_int(0), C_int(abi::box_rc_field_refcnt)]);
- auto rc = load_rc_cx.build.Load(rc_ptr);
- auto const_test =
+ let rc = load_rc_cx.build.Load(rc_ptr);
+ let const_test =
load_rc_cx.build.ICmp(lib::llvm::LLVMIntEQ,
C_int(abi::const_refcount as int), rc);
load_rc_cx.build.CondBr(const_test, next_cx.llbb, rc_adj_cx.llbb);
rc = rc_adj_cx.build.Sub(rc, C_int(1));
rc_adj_cx.build.Store(rc, rc_ptr);
- auto zero_test = rc_adj_cx.build.ICmp(lib::llvm::LLVMIntEQ, C_int(0), rc);
+ let zero_test = rc_adj_cx.build.ICmp(lib::llvm::LLVMIntEQ, C_int(0), rc);
rc_adj_cx.build.CondBr(zero_test, free_cx.llbb, next_cx.llbb);
- auto free_res =
+ let free_res =
free_ty(free_cx, load_if_immediate(free_cx, full_alias, t), t);
free_res.bcx.build.Br(next_cx.llbb);
- auto t_else = T_nil();
- auto v_else = C_nil();
- auto phi =
+ let t_else = T_nil();
+ let v_else = C_nil();
+ let phi =
next_cx.build.Phi(t_else, ~[v_else, v_else, v_else, free_res.val],
~[cx.llbb, load_rc_cx.llbb, rc_adj_cx.llbb,
free_res.bcx.llbb]);
@@ -1536,32 +1501,30 @@
// Structural comparison: a rather involved form of glue.
-fn maybe_name_value(&@crate_ctxt cx, ValueRef v, &str s) {
- if (cx.sess.get_opts().save_temps) {
+fn maybe_name_value(cx: &@crate_ctxt, v: ValueRef, s: &str) {
+ if cx.sess.get_opts().save_temps {
llvm::LLVMSetValueName(v, str::buf(s));
}
}
-fn make_cmp_glue(&@block_ctxt cx, ValueRef lhs0, ValueRef rhs0, &ty::t t,
- ValueRef llop) {
- auto lhs = load_if_immediate(cx, lhs0, t);
- auto rhs = load_if_immediate(cx, rhs0, t);
- if (ty::type_is_scalar(bcx_tcx(cx), t)) {
+fn make_cmp_glue(cx: &@block_ctxt, lhs0: ValueRef, rhs0: ValueRef, t: &ty::t,
+ llop: ValueRef) {
+ let lhs = load_if_immediate(cx, lhs0, t);
+ let rhs = load_if_immediate(cx, rhs0, t);
+ if ty::type_is_scalar(bcx_tcx(cx), t) {
make_scalar_cmp_glue(cx, lhs, rhs, t, llop);
} else if (ty::type_is_box(bcx_tcx(cx), t)) {
lhs = cx.build.GEP(lhs, ~[C_int(0), C_int(abi::box_rc_field_body)]);
rhs = cx.build.GEP(rhs, ~[C_int(0), C_int(abi::box_rc_field_body)]);
- auto t_inner =
- alt (ty::struct(bcx_tcx(cx), t)) {
- case (ty::ty_box(?ti)) { ti.ty }
- };
- auto rslt = compare(cx, lhs, rhs, t_inner, llop);
+ let t_inner =
+ alt ty::struct(bcx_tcx(cx), t) { ty::ty_box(ti) { ti.ty } };
+ let rslt = compare(cx, lhs, rhs, t_inner, llop);
rslt.bcx.build.Store(rslt.val, cx.fcx.llretptr);
rslt.bcx.build.RetVoid();
} else if (ty::type_is_structural(bcx_tcx(cx), t) ||
ty::type_is_sequence(bcx_tcx(cx), t)) {
- auto scx = new_sub_block_ctxt(cx, "structural compare start");
- auto next = new_sub_block_ctxt(cx, "structural compare end");
+ let scx = new_sub_block_ctxt(cx, "structural compare start");
+ let next = new_sub_block_ctxt(cx, "structural compare end");
cx.build.Br(scx.llbb);
/*
* We're doing lexicographic comparison here. We start with the
@@ -1587,19 +1550,19 @@
* optimize combinations like that, at this level.
*/
- auto flag = alloca(scx, T_i1());
+ let flag = alloca(scx, T_i1());
maybe_name_value(bcx_ccx(cx), flag, "flag");
- auto r;
- if (ty::type_is_sequence(bcx_tcx(cx), t)) {
+ let r;
+ if ty::type_is_sequence(bcx_tcx(cx), t) {
// If we hit == all the way through the minimum-shared-length
// section, default to judging the relative sequence lengths.
- auto lhs_fill;
- auto rhs_fill;
- auto bcx;
- if (ty::sequence_is_interior(bcx_tcx(cx), t)) {
- auto st = ty::sequence_element_type(bcx_tcx(cx), t);
- auto lad = ivec::get_len_and_data(scx, lhs, st);
+ let lhs_fill;
+ let rhs_fill;
+ let bcx;
+ if ty::sequence_is_interior(bcx_tcx(cx), t) {
+ let st = ty::sequence_element_type(bcx_tcx(cx), t);
+ let lad = ivec::get_len_and_data(scx, lhs, st);
bcx = lad.bcx;
lhs_fill = lad.len;
lad = ivec::get_len_and_data(bcx, rhs, st);
@@ -1610,33 +1573,34 @@
rhs_fill = vec_fill(scx, rhs);
bcx = scx;
}
- r = compare_scalar_values(bcx, lhs_fill, rhs_fill,
- unsigned_int, llop);
+ r =
+ compare_scalar_values(bcx, lhs_fill, rhs_fill, unsigned_int,
+ llop);
r.bcx.build.Store(r.val, flag);
} else {
// == and <= default to true if they find == all the way. <
// defaults to false if it finds == all the way.
- auto result_if_equal =
+ let result_if_equal =
scx.build.ICmp(lib::llvm::LLVMIntNE, llop,
C_u8(abi::cmp_glue_op_lt));
scx.build.Store(result_if_equal, flag);
r = rslt(scx, C_nil());
}
- fn inner(@block_ctxt last_cx, bool load_inner, ValueRef flag,
- ValueRef llop, &@block_ctxt cx, ValueRef av0, ValueRef bv0,
- ty::t t) -> result {
- auto cnt_cx = new_sub_block_ctxt(cx, "continue_comparison");
- auto stop_cx = new_sub_block_ctxt(cx, "stop_comparison");
- auto av = av0;
- auto bv = bv0;
- if (load_inner) {
+ fn inner(last_cx: @block_ctxt, load_inner: bool, flag: ValueRef,
+ llop: ValueRef, cx: &@block_ctxt, av0: ValueRef,
+ bv0: ValueRef, t: ty::t) -> result {
+ let cnt_cx = new_sub_block_ctxt(cx, "continue_comparison");
+ let stop_cx = new_sub_block_ctxt(cx, "stop_comparison");
+ let av = av0;
+ let bv = bv0;
+ if load_inner {
// If `load_inner` is true, then the pointer type will always
// be i8, because the data part of a vector always has type
// i8[]. So we need to cast it to the proper type.
- if (!ty::type_has_dynamic_size(bcx_tcx(last_cx), t)) {
- auto llelemty =
+ if !ty::type_has_dynamic_size(bcx_tcx(last_cx), t) {
+ let llelemty =
T_ptr(type_of(bcx_ccx(last_cx), last_cx.sp, t));
av = cx.build.PointerCast(av, llelemty);
bv = cx.build.PointerCast(bv, llelemty);
@@ -1646,27 +1610,27 @@
}
// First 'eq' comparison: if so, continue to next elts.
- auto eq_r = compare(cx, av, bv, t, C_u8(abi::cmp_glue_op_eq));
+ let eq_r = compare(cx, av, bv, t, C_u8(abi::cmp_glue_op_eq));
eq_r.bcx.build.CondBr(eq_r.val, cnt_cx.llbb, stop_cx.llbb);
// Second 'op' comparison: find out how this elt-pair decides.
- auto stop_r = compare(stop_cx, av, bv, t, llop);
+ let stop_r = compare(stop_cx, av, bv, t, llop);
stop_r.bcx.build.Store(stop_r.val, flag);
stop_r.bcx.build.Br(last_cx.llbb);
ret rslt(cnt_cx, C_nil());
}
- if (ty::type_is_structural(bcx_tcx(cx), t)) {
+ if ty::type_is_structural(bcx_tcx(cx), t) {
r =
iter_structural_ty_full(r.bcx, lhs, rhs, t,
bind inner(next, false, flag, llop, _,
_, _, _));
} else {
- auto lhs_p0 = vec_p0(r.bcx, lhs);
- auto rhs_p0 = vec_p0(r.bcx, rhs);
- auto min_len =
+ let lhs_p0 = vec_p0(r.bcx, lhs);
+ let rhs_p0 = vec_p0(r.bcx, rhs);
+ let min_len =
umin(r.bcx, vec_fill(r.bcx, lhs), vec_fill(r.bcx, rhs));
- auto rhs_lim = r.bcx.build.GEP(rhs_p0, ~[min_len]);
- auto elt_ty = ty::sequence_element_type(bcx_tcx(cx), t);
+ let rhs_lim = r.bcx.build.GEP(rhs_p0, ~[min_len]);
+ let elt_ty = ty::sequence_element_type(bcx_tcx(cx), t);
r = size_of(r.bcx, elt_ty);
r =
iter_sequence_raw(r.bcx, lhs_p0, rhs_p0, rhs_lim, r.val,
@@ -1674,7 +1638,7 @@
elt_ty));
}
r.bcx.build.Br(next.llbb);
- auto v = next.build.Load(flag);
+ let v = next.build.Load(flag);
next.build.Store(v, cx.fcx.llretptr);
next.build.RetVoid();
} else {
@@ -1682,7 +1646,7 @@
trans_fail(cx, none[span],
"attempt to compare values of type " +
- ty_to_str(bcx_tcx(cx), t));
+ ty_to_str(bcx_tcx(cx), t));
}
}
@@ -1691,105 +1655,102 @@
tag scalar_type { nil_type; signed_int; unsigned_int; floating_point; }
-fn compare_scalar_types(@block_ctxt cx, ValueRef lhs, ValueRef rhs, &ty::t t,
- ValueRef llop) -> result {
+fn compare_scalar_types(cx: @block_ctxt, lhs: ValueRef, rhs: ValueRef,
+ t: &ty::t, llop: ValueRef) -> result {
// FIXME: this could be a lot shorter if we could combine multiple cases
// of alt expressions (issue #449).
- auto f = bind compare_scalar_values(cx, lhs, rhs, _, llop);
+ let f = bind compare_scalar_values(cx, lhs, rhs, _, llop);
- alt (ty::struct(bcx_tcx(cx), t)) {
- case (ty::ty_nil) { ret f(nil_type); }
- case (ty::ty_bool) { ret f(unsigned_int); }
- case (ty::ty_int) { ret f(signed_int); }
- case (ty::ty_float) { ret f(floating_point); }
- case (ty::ty_uint) { ret f(unsigned_int); }
- case (ty::ty_machine(_)) {
- if (ty::type_is_fp(bcx_tcx(cx), t)) {
- // Floating point machine types
- ret f(floating_point);
- } else if (ty::type_is_signed(bcx_tcx(cx), t)) {
- // Signed, integral machine types
- ret f(signed_int);
- } else {
- // Unsigned, integral machine types
- ret f(unsigned_int);
- }
- }
- case (ty::ty_char) { ret f(unsigned_int); }
- case (ty::ty_type) {
- trans_fail(cx, none[span],
- "attempt to compare values of type type");
+ alt ty::struct(bcx_tcx(cx), t) {
+ ty::ty_nil. { ret f(nil_type); }
+ ty::ty_bool. { ret f(unsigned_int); }
+ ty::ty_int. { ret f(signed_int); }
+ ty::ty_float. { ret f(floating_point); }
+ ty::ty_uint. { ret f(unsigned_int); }
+ ty::ty_machine(_) {
- // This is a bit lame, because we return a dummy block to the
- // caller that's actually unreachable, but I don't think it
- // matters.
- ret rslt(new_sub_block_ctxt(cx, "after_fail_dummy"),
- C_bool(false));
- }
- case (ty::ty_native(_)) {
- trans_fail(cx, none[span],
- "attempt to compare values of type native");
- ret rslt(new_sub_block_ctxt(cx, "after_fail_dummy"),
- C_bool(false));
- }
- case (ty::ty_ptr(_)) {
+
+ if ty::type_is_fp(bcx_tcx(cx), t) {
+ // Floating point machine types
+ ret f(floating_point);
+ } else if (ty::type_is_signed(bcx_tcx(cx), t)) {
+ // Signed, integral machine types
+ ret f(signed_int);
+ } else {
+ // Unsigned, integral machine types
ret f(unsigned_int);
}
- case (_) {
- // Should never get here, because t is scalar.
- bcx_ccx(cx).sess.bug("non-scalar type passed to \
+ }
+ ty::ty_char. { ret f(unsigned_int); }
+ ty::ty_type. {
+ trans_fail(cx, none[span], "attempt to compare values of type type");
+
+ // This is a bit lame, because we return a dummy block to the
+ // caller that's actually unreachable, but I don't think it
+ // matters.
+ ret rslt(new_sub_block_ctxt(cx, "after_fail_dummy"), C_bool(false));
+ }
+ ty::ty_native(_) {
+ trans_fail(cx, none[span],
+ "attempt to compare values of type native");
+ ret rslt(new_sub_block_ctxt(cx, "after_fail_dummy"), C_bool(false));
+ }
+ ty::ty_ptr(_) { ret f(unsigned_int); }
+ _ {
+ // Should never get here, because t is scalar.
+ bcx_ccx(cx).sess.bug("non-scalar type passed to \
compare_scalar_types");
- }
+ }
}
}
// A helper function to create scalar comparison glue.
-fn make_scalar_cmp_glue(&@block_ctxt cx, ValueRef lhs, ValueRef rhs, &ty::t t,
- ValueRef llop) {
- assert ty::type_is_scalar(bcx_tcx(cx), t);
+fn make_scalar_cmp_glue(cx: &@block_ctxt, lhs: ValueRef, rhs: ValueRef,
+ t: &ty::t, llop: ValueRef) {
+ assert (ty::type_is_scalar(bcx_tcx(cx), t));
// In most cases, we need to know whether to do signed, unsigned, or float
// comparison.
- auto rslt = compare_scalar_types(cx, lhs, rhs, t, llop);
- auto bcx = rslt.bcx;
- auto compare_result = rslt.val;
+ let rslt = compare_scalar_types(cx, lhs, rhs, t, llop);
+ let bcx = rslt.bcx;
+ let compare_result = rslt.val;
bcx.build.Store(compare_result, cx.fcx.llretptr);
bcx.build.RetVoid();
}
// A helper function to do the actual comparison of scalar values.
-fn compare_scalar_values(&@block_ctxt cx, ValueRef lhs, ValueRef rhs,
- scalar_type nt, ValueRef llop) -> result {
- auto eq_cmp;
- auto lt_cmp;
- auto le_cmp;
- alt (nt) {
- case (nil_type) {
- // We don't need to do actual comparisons for nil.
- // () == () holds but () < () does not.
- eq_cmp = 1u;
- lt_cmp = 0u;
- le_cmp = 1u;
- }
- case (floating_point) {
- eq_cmp = lib::llvm::LLVMRealUEQ;
- lt_cmp = lib::llvm::LLVMRealULT;
- le_cmp = lib::llvm::LLVMRealULE;
- }
- case (signed_int) {
- eq_cmp = lib::llvm::LLVMIntEQ;
- lt_cmp = lib::llvm::LLVMIntSLT;
- le_cmp = lib::llvm::LLVMIntSLE;
- }
- case (unsigned_int) {
- eq_cmp = lib::llvm::LLVMIntEQ;
- lt_cmp = lib::llvm::LLVMIntULT;
- le_cmp = lib::llvm::LLVMIntULE;
- }
+fn compare_scalar_values(cx: &@block_ctxt, lhs: ValueRef, rhs: ValueRef,
+ nt: scalar_type, llop: ValueRef) -> result {
+ let eq_cmp;
+ let lt_cmp;
+ let le_cmp;
+ alt nt {
+ nil_type. {
+ // We don't need to do actual comparisons for nil.
+ // () == () holds but () < () does not.
+ eq_cmp = 1u;
+ lt_cmp = 0u;
+ le_cmp = 1u;
+ }
+ floating_point. {
+ eq_cmp = lib::llvm::LLVMRealUEQ;
+ lt_cmp = lib::llvm::LLVMRealULT;
+ le_cmp = lib::llvm::LLVMRealULE;
+ }
+ signed_int. {
+ eq_cmp = lib::llvm::LLVMIntEQ;
+ lt_cmp = lib::llvm::LLVMIntSLT;
+ le_cmp = lib::llvm::LLVMIntSLE;
+ }
+ unsigned_int. {
+ eq_cmp = lib::llvm::LLVMIntEQ;
+ lt_cmp = lib::llvm::LLVMIntULT;
+ le_cmp = lib::llvm::LLVMIntULE;
+ }
}
// FIXME: This wouldn't be necessary if we could bind methods off of
// objects and therefore abstract over FCmp and ICmp (issue #435). Then
@@ -1797,33 +1758,33 @@
// the above, and "auto eq_result = cmp_fn(eq_cmp, lhs, rhs);" in the
// below.
- fn generic_cmp(&@block_ctxt cx, scalar_type nt, uint op, ValueRef lhs,
- ValueRef rhs) -> ValueRef {
- let ValueRef r;
- if (nt == nil_type) {
+ fn generic_cmp(cx: &@block_ctxt, nt: scalar_type, op: uint, lhs: ValueRef,
+ rhs: ValueRef) -> ValueRef {
+ let r: ValueRef;
+ if nt == nil_type {
r = C_bool(op != 0u);
} else if (nt == floating_point) {
r = cx.build.FCmp(op, lhs, rhs);
} else { r = cx.build.ICmp(op, lhs, rhs); }
ret r;
}
- auto last_cx = new_sub_block_ctxt(cx, "last");
- auto eq_cx = new_sub_block_ctxt(cx, "eq");
- auto eq_result = generic_cmp(eq_cx, nt, eq_cmp, lhs, rhs);
+ let last_cx = new_sub_block_ctxt(cx, "last");
+ let eq_cx = new_sub_block_ctxt(cx, "eq");
+ let eq_result = generic_cmp(eq_cx, nt, eq_cmp, lhs, rhs);
eq_cx.build.Br(last_cx.llbb);
- auto lt_cx = new_sub_block_ctxt(cx, "lt");
- auto lt_result = generic_cmp(lt_cx, nt, lt_cmp, lhs, rhs);
+ let lt_cx = new_sub_block_ctxt(cx, "lt");
+ let lt_result = generic_cmp(lt_cx, nt, lt_cmp, lhs, rhs);
lt_cx.build.Br(last_cx.llbb);
- auto le_cx = new_sub_block_ctxt(cx, "le");
- auto le_result = generic_cmp(le_cx, nt, le_cmp, lhs, rhs);
+ let le_cx = new_sub_block_ctxt(cx, "le");
+ let le_result = generic_cmp(le_cx, nt, le_cmp, lhs, rhs);
le_cx.build.Br(last_cx.llbb);
- auto unreach_cx = new_sub_block_ctxt(cx, "unreach");
+ let unreach_cx = new_sub_block_ctxt(cx, "unreach");
unreach_cx.build.Unreachable();
- auto llswitch = cx.build.Switch(llop, unreach_cx.llbb, 3u);
+ let llswitch = cx.build.Switch(llop, unreach_cx.llbb, 3u);
llvm::LLVMAddCase(llswitch, C_u8(abi::cmp_glue_op_eq), eq_cx.llbb);
llvm::LLVMAddCase(llswitch, C_u8(abi::cmp_glue_op_lt), lt_cx.llbb);
llvm::LLVMAddCase(llswitch, C_u8(abi::cmp_glue_op_le), le_cx.llbb);
- auto last_result =
+ let last_result =
last_cx.build.Phi(T_i1(), ~[eq_result, lt_result, le_result],
~[eq_cx.llbb, lt_cx.llbb, le_cx.llbb]);
ret rslt(last_cx, last_result);
@@ -1838,105 +1799,106 @@
// Iterates through the elements of a structural type.
-fn iter_structural_ty(&@block_ctxt cx, ValueRef v, &ty::t t, val_and_ty_fn f)
- -> result {
- fn adaptor_fn(val_and_ty_fn f, &@block_ctxt cx, ValueRef av, ValueRef bv,
- ty::t t) -> result {
+fn iter_structural_ty(cx: &@block_ctxt, v: ValueRef, t: &ty::t,
+ f: val_and_ty_fn) -> result {
+ fn adaptor_fn(f: val_and_ty_fn, cx: &@block_ctxt, av: ValueRef,
+ bv: ValueRef, t: ty::t) -> result {
ret f(cx, av, t);
}
ret iter_structural_ty_full(cx, v, v, t, bind adaptor_fn(f, _, _, _, _));
}
-fn load_inbounds(&@block_ctxt cx, ValueRef p, &ValueRef[] idxs) -> ValueRef {
+fn load_inbounds(cx: &@block_ctxt, p: ValueRef, idxs: &ValueRef[]) ->
+ ValueRef {
ret cx.build.Load(cx.build.InBoundsGEP(p, idxs));
}
-fn store_inbounds(&@block_ctxt cx, ValueRef v, ValueRef p, &ValueRef[] idxs) {
+fn store_inbounds(cx: &@block_ctxt, v: ValueRef, p: ValueRef,
+ idxs: &ValueRef[]) {
cx.build.Store(v, cx.build.InBoundsGEP(p, idxs));
}
// This uses store and inboundsGEP, but it only doing so superficially; it's
// really storing an incremented pointer to another pointer.
-fn incr_ptr(&@block_ctxt cx, ValueRef p, ValueRef incr, ValueRef pp) {
+fn incr_ptr(cx: &@block_ctxt, p: ValueRef, incr: ValueRef, pp: ValueRef) {
cx.build.Store(cx.build.InBoundsGEP(p, ~[incr]), pp);
}
-fn iter_structural_ty_full(&@block_ctxt cx, ValueRef av, ValueRef bv,
- &ty::t t, &val_pair_and_ty_fn f) -> result {
- fn iter_boxpp(@block_ctxt cx, ValueRef box_a_cell, ValueRef box_b_cell,
- &val_pair_and_ty_fn f) -> result {
- auto box_a_ptr = cx.build.Load(box_a_cell);
- auto box_b_ptr = cx.build.Load(box_b_cell);
- auto tnil = ty::mk_nil(bcx_tcx(cx));
- auto tbox = ty::mk_imm_box(bcx_tcx(cx), tnil);
- auto inner_cx = new_sub_block_ctxt(cx, "iter box");
- auto next_cx = new_sub_block_ctxt(cx, "next");
- auto null_test = cx.build.IsNull(box_a_ptr);
+fn iter_structural_ty_full(cx: &@block_ctxt, av: ValueRef, bv: ValueRef,
+ t: &ty::t, f: &val_pair_and_ty_fn) -> result {
+ fn iter_boxpp(cx: @block_ctxt, box_a_cell: ValueRef, box_b_cell: ValueRef,
+ f: &val_pair_and_ty_fn) -> result {
+ let box_a_ptr = cx.build.Load(box_a_cell);
+ let box_b_ptr = cx.build.Load(box_b_cell);
+ let tnil = ty::mk_nil(bcx_tcx(cx));
+ let tbox = ty::mk_imm_box(bcx_tcx(cx), tnil);
+ let inner_cx = new_sub_block_ctxt(cx, "iter box");
+ let next_cx = new_sub_block_ctxt(cx, "next");
+ let null_test = cx.build.IsNull(box_a_ptr);
cx.build.CondBr(null_test, next_cx.llbb, inner_cx.llbb);
- auto r = f(inner_cx, box_a_ptr, box_b_ptr, tbox);
+ let r = f(inner_cx, box_a_ptr, box_b_ptr, tbox);
r.bcx.build.Br(next_cx.llbb);
ret rslt(next_cx, C_nil());
}
- fn iter_ivec(@block_ctxt bcx, ValueRef av, ValueRef bv, ty::t unit_ty,
- &val_pair_and_ty_fn f) -> result {
+ fn iter_ivec(bcx: @block_ctxt, av: ValueRef, bv: ValueRef, unit_ty: ty::t,
+ f: &val_pair_and_ty_fn) -> result {
// FIXME: "unimplemented rebinding existing function" workaround
- fn adapter(&@block_ctxt bcx, ValueRef av, ValueRef bv, ty::t unit_ty,
- val_pair_and_ty_fn f) -> result {
+ fn adapter(bcx: &@block_ctxt, av: ValueRef, bv: ValueRef,
+ unit_ty: ty::t, f: val_pair_and_ty_fn) -> result {
ret f(bcx, av, bv, unit_ty);
}
- auto llunitty = type_of_or_i8(bcx, unit_ty);
- auto rs = size_of(bcx, unit_ty);
- auto unit_sz = rs.val;
+ let llunitty = type_of_or_i8(bcx, unit_ty);
+ let rs = size_of(bcx, unit_ty);
+ let unit_sz = rs.val;
bcx = rs.bcx;
- auto a_len_and_data = ivec::get_len_and_data(bcx, av, unit_ty);
- auto a_len = a_len_and_data.len;
- auto a_elem = a_len_and_data.data;
+ let a_len_and_data = ivec::get_len_and_data(bcx, av, unit_ty);
+ let a_len = a_len_and_data.len;
+ let a_elem = a_len_and_data.data;
bcx = a_len_and_data.bcx;
- auto b_len_and_data = ivec::get_len_and_data(bcx, bv, unit_ty);
- auto b_len = b_len_and_data.len;
- auto b_elem = b_len_and_data.data;
+ let b_len_and_data = ivec::get_len_and_data(bcx, bv, unit_ty);
+ let b_len = b_len_and_data.len;
+ let b_elem = b_len_and_data.data;
bcx = b_len_and_data.bcx;
// Calculate the last pointer address we want to handle.
// TODO: Optimize this when the size of the unit type is statically
// known to not use pointer casts, which tend to confuse LLVM.
- auto len = umin(bcx, a_len, b_len);
- auto b_elem_i8 = bcx.build.PointerCast(b_elem, T_ptr(T_i8()));
- auto b_end_i8 = bcx.build.GEP(b_elem_i8, ~[len]);
- auto b_end = bcx.build.PointerCast(b_end_i8, T_ptr(llunitty));
+ let len = umin(bcx, a_len, b_len);
+ let b_elem_i8 = bcx.build.PointerCast(b_elem, T_ptr(T_i8()));
+ let b_end_i8 = bcx.build.GEP(b_elem_i8, ~[len]);
+ let b_end = bcx.build.PointerCast(b_end_i8, T_ptr(llunitty));
- auto dest_elem_ptr = alloca(bcx, T_ptr(llunitty));
- auto src_elem_ptr = alloca(bcx, T_ptr(llunitty));
+ let dest_elem_ptr = alloca(bcx, T_ptr(llunitty));
+ let src_elem_ptr = alloca(bcx, T_ptr(llunitty));
bcx.build.Store(a_elem, dest_elem_ptr);
bcx.build.Store(b_elem, src_elem_ptr);
// Now perform the iteration.
- auto loop_header_cx = new_sub_block_ctxt(bcx,
- "iter_ivec_loop_header");
+ let loop_header_cx = new_sub_block_ctxt(bcx, "iter_ivec_loop_header");
bcx.build.Br(loop_header_cx.llbb);
- auto dest_elem = loop_header_cx.build.Load(dest_elem_ptr);
- auto src_elem = loop_header_cx.build.Load(src_elem_ptr);
- auto not_yet_at_end = loop_header_cx.build.ICmp(lib::llvm::LLVMIntULT,
- dest_elem, b_end);
- auto loop_body_cx = new_sub_block_ctxt(bcx, "iter_ivec_loop_body");
- auto next_cx = new_sub_block_ctxt(bcx, "iter_ivec_next");
+ let dest_elem = loop_header_cx.build.Load(dest_elem_ptr);
+ let src_elem = loop_header_cx.build.Load(src_elem_ptr);
+ let not_yet_at_end =
+ loop_header_cx.build.ICmp(lib::llvm::LLVMIntULT, dest_elem,
+ b_end);
+ let loop_body_cx = new_sub_block_ctxt(bcx, "iter_ivec_loop_body");
+ let next_cx = new_sub_block_ctxt(bcx, "iter_ivec_next");
loop_header_cx.build.CondBr(not_yet_at_end, loop_body_cx.llbb,
next_cx.llbb);
- rs = f(loop_body_cx,
- load_if_immediate(loop_body_cx, dest_elem, unit_ty),
- load_if_immediate(loop_body_cx, src_elem, unit_ty), unit_ty);
+ rs =
+ f(loop_body_cx,
+ load_if_immediate(loop_body_cx, dest_elem, unit_ty),
+ load_if_immediate(loop_body_cx, src_elem, unit_ty), unit_ty);
loop_body_cx = rs.bcx;
- auto increment;
- if (ty::type_has_dynamic_size(bcx_tcx(bcx), unit_ty)) {
+ let increment;
+ if ty::type_has_dynamic_size(bcx_tcx(bcx), unit_ty) {
increment = unit_sz;
- } else {
- increment = C_int(1);
- }
+ } else { increment = C_int(1); }
incr_ptr(loop_body_cx, dest_elem, increment, dest_elem_ptr);
incr_ptr(loop_body_cx, src_elem, increment, src_elem_ptr);
@@ -1945,364 +1907,352 @@
ret rslt(next_cx, C_nil());
}
- fn iter_variant(@block_ctxt cx, ValueRef a_tup, ValueRef b_tup,
- &ty::variant_info variant, &ty::t[] tps,
- &ast::def_id tid, &val_pair_and_ty_fn f) -> result {
- if (std::ivec::len[ty::t](variant.args) == 0u) {
+ fn iter_variant(cx: @block_ctxt, a_tup: ValueRef, b_tup: ValueRef,
+ variant: &ty::variant_info, tps: &ty::t[],
+ tid: &ast::def_id, f: &val_pair_and_ty_fn) -> result {
+ if std::ivec::len[ty::t](variant.args) == 0u {
ret rslt(cx, C_nil());
}
- auto fn_ty = variant.ctor_ty;
- auto ccx = bcx_ccx(cx);
- alt (ty::struct(ccx.tcx, fn_ty)) {
- case (ty::ty_fn(_, ?args, _, _, _)) {
- auto j = 0;
- for (ty::arg a in args) {
- auto rslt = GEP_tag(cx, a_tup, tid, variant.id, tps, j);
- auto llfldp_a = rslt.val;
- cx = rslt.bcx;
- rslt = GEP_tag(cx, b_tup, tid, variant.id, tps, j);
- auto llfldp_b = rslt.val;
- cx = rslt.bcx;
- auto ty_subst =
- ty::substitute_type_params(ccx.tcx, tps, a.ty);
- auto llfld_a =
- load_if_immediate(cx, llfldp_a, ty_subst);
- auto llfld_b =
- load_if_immediate(cx, llfldp_b, ty_subst);
- rslt = f(cx, llfld_a, llfld_b, ty_subst);
- cx = rslt.bcx;
- j += 1;
- }
+ let fn_ty = variant.ctor_ty;
+ let ccx = bcx_ccx(cx);
+ alt ty::struct(ccx.tcx, fn_ty) {
+ ty::ty_fn(_, args, _, _, _) {
+ let j = 0;
+ for a: ty::arg in args {
+ let rslt = GEP_tag(cx, a_tup, tid, variant.id, tps, j);
+ let llfldp_a = rslt.val;
+ cx = rslt.bcx;
+ rslt = GEP_tag(cx, b_tup, tid, variant.id, tps, j);
+ let llfldp_b = rslt.val;
+ cx = rslt.bcx;
+ let ty_subst = ty::substitute_type_params(ccx.tcx, tps, a.ty);
+ let llfld_a = load_if_immediate(cx, llfldp_a, ty_subst);
+ let llfld_b = load_if_immediate(cx, llfldp_b, ty_subst);
+ rslt = f(cx, llfld_a, llfld_b, ty_subst);
+ cx = rslt.bcx;
+ j += 1;
}
+ }
}
ret rslt(cx, C_nil());
}
- let result r = rslt(cx, C_nil());
- alt (ty::struct(bcx_tcx(cx), t)) {
- case (ty::ty_rec(?fields)) {
- let int i = 0;
- for (ty::field fld in fields) {
- r = GEP_tup_like(r.bcx, t, av, ~[0, i]);
- auto llfld_a = r.val;
- r = GEP_tup_like(r.bcx, t, bv, ~[0, i]);
- auto llfld_b = r.val;
- r = f(r.bcx, load_if_immediate(r.bcx, llfld_a, fld.mt.ty),
- load_if_immediate(r.bcx, llfld_b, fld.mt.ty),
- fld.mt.ty);
- i += 1;
- }
+ let r: result = rslt(cx, C_nil());
+ alt ty::struct(bcx_tcx(cx), t) {
+ ty::ty_rec(fields) {
+ let i: int = 0;
+ for fld: ty::field in fields {
+ r = GEP_tup_like(r.bcx, t, av, ~[0, i]);
+ let llfld_a = r.val;
+ r = GEP_tup_like(r.bcx, t, bv, ~[0, i]);
+ let llfld_b = r.val;
+ r =
+ f(r.bcx, load_if_immediate(r.bcx, llfld_a, fld.mt.ty),
+ load_if_immediate(r.bcx, llfld_b, fld.mt.ty), fld.mt.ty);
+ i += 1;
}
- case (ty::ty_res(_, ?inner, ?tps)) {
- auto inner1 = ty::substitute_type_params(bcx_tcx(cx), tps,
- inner);
- r = GEP_tup_like(r.bcx, t, av, ~[0, 1]);
- auto llfld_a = r.val;
- r = GEP_tup_like(r.bcx, t, bv, ~[0, 1]);
- auto llfld_b = r.val;
- f(r.bcx, load_if_immediate(r.bcx, llfld_a, inner1),
- load_if_immediate(r.bcx, llfld_b, inner1), inner1);
- }
- case (ty::ty_tag(?tid, ?tps)) {
- auto variants = ty::tag_variants(bcx_tcx(cx), tid);
- auto n_variants = std::ivec::len(variants);
+ }
+ ty::ty_res(_, inner, tps) {
+ let inner1 = ty::substitute_type_params(bcx_tcx(cx), tps, inner);
+ r = GEP_tup_like(r.bcx, t, av, ~[0, 1]);
+ let llfld_a = r.val;
+ r = GEP_tup_like(r.bcx, t, bv, ~[0, 1]);
+ let llfld_b = r.val;
+ f(r.bcx, load_if_immediate(r.bcx, llfld_a, inner1),
+ load_if_immediate(r.bcx, llfld_b, inner1), inner1);
+ }
+ ty::ty_tag(tid, tps) {
+ let variants = ty::tag_variants(bcx_tcx(cx), tid);
+ let n_variants = std::ivec::len(variants);
- // Cast the tags to types we can GEP into.
- if (n_variants == 1u) {
- ret iter_variant(cx, av, bv, variants.(0), tps, tid, f);
- }
+ // Cast the tags to types we can GEP into.
+ if n_variants == 1u {
+ ret iter_variant(cx, av, bv, variants.(0), tps, tid, f);
+ }
- auto lltagty = T_opaque_tag_ptr(bcx_ccx(cx).tn);
- auto av_tag = cx.build.PointerCast(av, lltagty);
- auto bv_tag = cx.build.PointerCast(bv, lltagty);
- auto lldiscrim_a_ptr = cx.build.GEP(av_tag,
- ~[C_int(0), C_int(0)]);
- auto llunion_a_ptr = cx.build.GEP(av_tag, ~[C_int(0), C_int(1)]);
- auto lldiscrim_a = cx.build.Load(lldiscrim_a_ptr);
- auto lldiscrim_b_ptr = cx.build.GEP(bv_tag,
- ~[C_int(0), C_int(0)]);
- auto llunion_b_ptr = cx.build.GEP(bv_tag, ~[C_int(0), C_int(1)]);
- auto lldiscrim_b = cx.build.Load(lldiscrim_b_ptr);
+ let lltagty = T_opaque_tag_ptr(bcx_ccx(cx).tn);
+ let av_tag = cx.build.PointerCast(av, lltagty);
+ let bv_tag = cx.build.PointerCast(bv, lltagty);
+ let lldiscrim_a_ptr = cx.build.GEP(av_tag, ~[C_int(0), C_int(0)]);
+ let llunion_a_ptr = cx.build.GEP(av_tag, ~[C_int(0), C_int(1)]);
+ let lldiscrim_a = cx.build.Load(lldiscrim_a_ptr);
+ let lldiscrim_b_ptr = cx.build.GEP(bv_tag, ~[C_int(0), C_int(0)]);
+ let llunion_b_ptr = cx.build.GEP(bv_tag, ~[C_int(0), C_int(1)]);
+ let lldiscrim_b = cx.build.Load(lldiscrim_b_ptr);
- // NB: we must hit the discriminant first so that structural
- // comparison know not to proceed when the discriminants differ.
- auto bcx = cx;
- bcx =
- f(bcx, lldiscrim_a, lldiscrim_b,
- ty::mk_int(bcx_tcx(cx))).bcx;
- auto unr_cx = new_sub_block_ctxt(bcx, "tag-iter-unr");
- unr_cx.build.Unreachable();
- auto llswitch =
- bcx.build.Switch(lldiscrim_a, unr_cx.llbb, n_variants);
- auto next_cx = new_sub_block_ctxt(bcx, "tag-iter-next");
- auto i = 0u;
- for (ty::variant_info variant in variants) {
- auto variant_cx =
- new_sub_block_ctxt(bcx,
- "tag-iter-variant-" +
- uint::to_str(i, 10u));
- llvm::LLVMAddCase(llswitch, C_int(i as int), variant_cx.llbb);
- variant_cx = iter_variant
- (variant_cx, llunion_a_ptr, llunion_b_ptr, variant,
- tps, tid, f).bcx;
- variant_cx.build.Br(next_cx.llbb);
- i += 1u;
- }
- ret rslt(next_cx, C_nil());
+ // NB: we must hit the discriminant first so that structural
+ // comparison know not to proceed when the discriminants differ.
+ let bcx = cx;
+ bcx = f(bcx, lldiscrim_a, lldiscrim_b, ty::mk_int(bcx_tcx(cx))).bcx;
+ let unr_cx = new_sub_block_ctxt(bcx, "tag-iter-unr");
+ unr_cx.build.Unreachable();
+ let llswitch = bcx.build.Switch(lldiscrim_a, unr_cx.llbb, n_variants);
+ let next_cx = new_sub_block_ctxt(bcx, "tag-iter-next");
+ let i = 0u;
+ for variant: ty::variant_info in variants {
+ let variant_cx =
+ new_sub_block_ctxt(bcx,
+ "tag-iter-variant-" +
+ uint::to_str(i, 10u));
+ llvm::LLVMAddCase(llswitch, C_int(i as int), variant_cx.llbb);
+ variant_cx =
+ iter_variant(variant_cx, llunion_a_ptr, llunion_b_ptr,
+ variant, tps, tid, f).bcx;
+ variant_cx.build.Br(next_cx.llbb);
+ i += 1u;
}
- case (ty::ty_fn(_, _, _, _, _)) {
- auto box_cell_a =
- cx.build.GEP(av, ~[C_int(0), C_int(abi::fn_field_box)]);
- auto box_cell_b =
- cx.build.GEP(bv, ~[C_int(0), C_int(abi::fn_field_box)]);
- ret iter_boxpp(cx, box_cell_a, box_cell_b, f);
- }
- case (ty::ty_obj(_)) {
- auto box_cell_a =
- cx.build.GEP(av, ~[C_int(0), C_int(abi::obj_field_box)]);
- auto box_cell_b =
- cx.build.GEP(bv, ~[C_int(0), C_int(abi::obj_field_box)]);
- ret iter_boxpp(cx, box_cell_a, box_cell_b, f);
- }
- case (ty::ty_ivec(?unit_tm)) {
- ret iter_ivec(cx, av, bv, unit_tm.ty, f);
- }
- case (ty::ty_istr) {
- auto unit_ty = ty::mk_mach(bcx_tcx(cx), ast::ty_u8);
- ret iter_ivec(cx, av, bv, unit_ty, f);
- }
- case (_) {
- bcx_ccx(cx).sess.unimpl("type in iter_structural_ty_full");
- }
+ ret rslt(next_cx, C_nil());
+ }
+ ty::ty_fn(_, _, _, _, _) {
+ let box_cell_a =
+ cx.build.GEP(av, ~[C_int(0), C_int(abi::fn_field_box)]);
+ let box_cell_b =
+ cx.build.GEP(bv, ~[C_int(0), C_int(abi::fn_field_box)]);
+ ret iter_boxpp(cx, box_cell_a, box_cell_b, f);
+ }
+ ty::ty_obj(_) {
+ let box_cell_a =
+ cx.build.GEP(av, ~[C_int(0), C_int(abi::obj_field_box)]);
+ let box_cell_b =
+ cx.build.GEP(bv, ~[C_int(0), C_int(abi::obj_field_box)]);
+ ret iter_boxpp(cx, box_cell_a, box_cell_b, f);
+ }
+ ty::ty_ivec(unit_tm) { ret iter_ivec(cx, av, bv, unit_tm.ty, f); }
+ ty::ty_istr. {
+ let unit_ty = ty::mk_mach(bcx_tcx(cx), ast::ty_u8);
+ ret iter_ivec(cx, av, bv, unit_ty, f);
+ }
+ _ { bcx_ccx(cx).sess.unimpl("type in iter_structural_ty_full"); }
}
ret r;
}
// Iterates through a pointer range, until the src* hits the src_lim*.
-fn iter_sequence_raw(@block_ctxt cx, ValueRef dst,
+fn iter_sequence_raw(cx: @block_ctxt, dst: ValueRef,
+ src:
// elt*
- ValueRef src,
+ ValueRef,
+ src_lim:
// elt*
- ValueRef src_lim,
+ ValueRef,
+ elt_sz:
// elt*
- ValueRef elt_sz, &val_pair_fn f) -> result {
- auto bcx = cx;
- let ValueRef dst_int = vp2i(bcx, dst);
- let ValueRef src_int = vp2i(bcx, src);
- let ValueRef src_lim_int = vp2i(bcx, src_lim);
- auto cond_cx = new_scope_block_ctxt(cx, "sequence-iter cond");
- auto body_cx = new_scope_block_ctxt(cx, "sequence-iter body");
- auto next_cx = new_sub_block_ctxt(cx, "next");
+ ValueRef, f: &val_pair_fn) -> result {
+ let bcx = cx;
+ let dst_int: ValueRef = vp2i(bcx, dst);
+ let src_int: ValueRef = vp2i(bcx, src);
+ let src_lim_int: ValueRef = vp2i(bcx, src_lim);
+ let cond_cx = new_scope_block_ctxt(cx, "sequence-iter cond");
+ let body_cx = new_scope_block_ctxt(cx, "sequence-iter body");
+ let next_cx = new_sub_block_ctxt(cx, "next");
bcx.build.Br(cond_cx.llbb);
- let ValueRef dst_curr = cond_cx.build.Phi(T_int(), ~[dst_int],
- ~[bcx.llbb]);
- let ValueRef src_curr = cond_cx.build.Phi(T_int(), ~[src_int],
- ~[bcx.llbb]);
- auto end_test =
+ let dst_curr: ValueRef =
+ cond_cx.build.Phi(T_int(), ~[dst_int], ~[bcx.llbb]);
+ let src_curr: ValueRef =
+ cond_cx.build.Phi(T_int(), ~[src_int], ~[bcx.llbb]);
+ let end_test =
cond_cx.build.ICmp(lib::llvm::LLVMIntULT, src_curr, src_lim_int);
cond_cx.build.CondBr(end_test, body_cx.llbb, next_cx.llbb);
- auto dst_curr_ptr = vi2p(body_cx, dst_curr, T_ptr(T_i8()));
- auto src_curr_ptr = vi2p(body_cx, src_curr, T_ptr(T_i8()));
- auto body_res = f(body_cx, dst_curr_ptr, src_curr_ptr);
+ let dst_curr_ptr = vi2p(body_cx, dst_curr, T_ptr(T_i8()));
+ let src_curr_ptr = vi2p(body_cx, src_curr, T_ptr(T_i8()));
+ let body_res = f(body_cx, dst_curr_ptr, src_curr_ptr);
body_cx = body_res.bcx;
- auto dst_next = body_cx.build.Add(dst_curr, elt_sz);
- auto src_next = body_cx.build.Add(src_curr, elt_sz);
+ let dst_next = body_cx.build.Add(dst_curr, elt_sz);
+ let src_next = body_cx.build.Add(src_curr, elt_sz);
body_cx.build.Br(cond_cx.llbb);
cond_cx.build.AddIncomingToPhi(dst_curr, ~[dst_next], ~[body_cx.llbb]);
cond_cx.build.AddIncomingToPhi(src_curr, ~[src_next], ~[body_cx.llbb]);
ret rslt(next_cx, C_nil());
}
-fn iter_sequence_inner(&@block_ctxt cx, ValueRef src,
+fn iter_sequence_inner(cx: &@block_ctxt, src: ValueRef,
+ src_lim:
// elt*
- ValueRef src_lim,
- & // elt*
- ty::t elt_ty, &val_and_ty_fn f) -> result {
- fn adaptor_fn(val_and_ty_fn f, ty::t elt_ty, &@block_ctxt cx,
- ValueRef dst, ValueRef src) -> result {
- auto llptrty;
- if (!ty::type_has_dynamic_size(bcx_tcx(cx), elt_ty)) {
- auto llty = type_of(bcx_ccx(cx), cx.sp, elt_ty);
+ ValueRef,
+ elt_ty: & // elt*
+ ty::t, f: &val_and_ty_fn) -> result {
+ fn adaptor_fn(f: val_and_ty_fn, elt_ty: ty::t, cx: &@block_ctxt,
+ dst: ValueRef, src: ValueRef) -> result {
+ let llptrty;
+ if !ty::type_has_dynamic_size(bcx_tcx(cx), elt_ty) {
+ let llty = type_of(bcx_ccx(cx), cx.sp, elt_ty);
llptrty = T_ptr(llty);
} else { llptrty = T_ptr(T_ptr(T_i8())); }
- auto p = cx.build.PointerCast(src, llptrty);
+ let p = cx.build.PointerCast(src, llptrty);
ret f(cx, load_if_immediate(cx, p, elt_ty), elt_ty);
}
- auto elt_sz = size_of(cx, elt_ty);
+ let elt_sz = size_of(cx, elt_ty);
ret iter_sequence_raw(elt_sz.bcx, src, src, src_lim, elt_sz.val,
bind adaptor_fn(f, elt_ty, _, _, _));
}
// Iterates through the elements of a vec or str.
-fn iter_sequence(@block_ctxt cx, ValueRef v, &ty::t t, &val_and_ty_fn f) ->
- result {
- fn iter_sequence_body(@block_ctxt cx, ValueRef v, &ty::t elt_ty,
- &val_and_ty_fn f, bool trailing_null, bool interior)
- -> result {
- auto p0;
- auto len;
- auto bcx;
- if (!interior) {
+fn iter_sequence(cx: @block_ctxt, v: ValueRef, t: &ty::t, f: &val_and_ty_fn)
+ -> result {
+ fn iter_sequence_body(cx: @block_ctxt, v: ValueRef, elt_ty: &ty::t,
+ f: &val_and_ty_fn, trailing_null: bool,
+ interior: bool) -> result {
+ let p0;
+ let len;
+ let bcx;
+ if !interior {
p0 = cx.build.GEP(v, ~[C_int(0), C_int(abi::vec_elt_data)]);
- auto lp = cx.build.GEP(v, ~[C_int(0), C_int(abi::vec_elt_fill)]);
+ let lp = cx.build.GEP(v, ~[C_int(0), C_int(abi::vec_elt_fill)]);
len = cx.build.Load(lp);
bcx = cx;
} else {
- auto len_and_data_rslt = ivec::get_len_and_data(cx, v, elt_ty);
+ let len_and_data_rslt = ivec::get_len_and_data(cx, v, elt_ty);
len = len_and_data_rslt.len;
p0 = len_and_data_rslt.data;
bcx = len_and_data_rslt.bcx;
}
- auto llunit_ty = type_of_or_i8(cx, elt_ty);
- if (trailing_null) {
- auto unit_sz = size_of(bcx, elt_ty);
+ let llunit_ty = type_of_or_i8(cx, elt_ty);
+ if trailing_null {
+ let unit_sz = size_of(bcx, elt_ty);
bcx = unit_sz.bcx;
len = bcx.build.Sub(len, unit_sz.val);
}
- auto p1 =
+ let p1 =
vi2p(bcx, bcx.build.Add(vp2i(bcx, p0), len), T_ptr(llunit_ty));
ret iter_sequence_inner(bcx, p0, p1, elt_ty, f);
}
- alt (ty::struct(bcx_tcx(cx), t)) {
- case (ty::ty_vec(?elt)) {
- ret iter_sequence_body(cx, v, elt.ty, f, false, false);
- }
- case (ty::ty_str) {
- auto et = ty::mk_mach(bcx_tcx(cx), ast::ty_u8);
- ret iter_sequence_body(cx, v, et, f, true, false);
- }
- case (ty::ty_ivec(?elt)) {
- ret iter_sequence_body(cx, v, elt.ty, f, false, true);
- }
- case (ty::ty_istr) {
- auto et = ty::mk_mach(bcx_tcx(cx), ast::ty_u8);
- ret iter_sequence_body(cx, v, et, f, true, true);
- }
- case (_) {
- bcx_ccx(cx).sess.bug("unexpected type in \
- trans::iter_sequence: " +
- ty_to_str(cx.fcx.lcx.ccx.tcx, t));
- }
+
+ alt ty::struct(bcx_tcx(cx), t) {
+ ty::ty_vec(elt) {
+ ret iter_sequence_body(cx, v, elt.ty, f, false, false);
+ }
+ ty::ty_str. {
+ let et = ty::mk_mach(bcx_tcx(cx), ast::ty_u8);
+ ret iter_sequence_body(cx, v, et, f, true, false);
+ }
+ ty::ty_ivec(elt) {
+ ret iter_sequence_body(cx, v, elt.ty, f, false, true);
+ }
+ ty::ty_istr. {
+ let et = ty::mk_mach(bcx_tcx(cx), ast::ty_u8);
+ ret iter_sequence_body(cx, v, et, f, true, true);
+ }
+ _ {
+ bcx_ccx(cx).sess.bug("unexpected type in \
+ trans::iter_sequence: "
+ + ty_to_str(cx.fcx.lcx.ccx.tcx, t));
+ }
}
}
-fn lazily_emit_all_tydesc_glue(&@block_ctxt cx,
- &option::t[@tydesc_info] static_ti) {
+fn lazily_emit_all_tydesc_glue(cx: &@block_ctxt,
+ static_ti: &option::t[@tydesc_info]) {
lazily_emit_tydesc_glue(cx, abi::tydesc_field_copy_glue, static_ti);
lazily_emit_tydesc_glue(cx, abi::tydesc_field_drop_glue, static_ti);
lazily_emit_tydesc_glue(cx, abi::tydesc_field_free_glue, static_ti);
lazily_emit_tydesc_glue(cx, abi::tydesc_field_cmp_glue, static_ti);
}
-fn lazily_emit_all_generic_info_tydesc_glues(&@block_ctxt cx,
- &generic_info gi) {
- for (option::t[@tydesc_info] ti in gi.static_tis) {
+fn lazily_emit_all_generic_info_tydesc_glues(cx: &@block_ctxt,
+ gi: &generic_info) {
+ for ti: option::t[@tydesc_info] in gi.static_tis {
lazily_emit_all_tydesc_glue(cx, ti);
}
}
-fn lazily_emit_tydesc_glue(&@block_ctxt cx, int field,
- &option::t[@tydesc_info] static_ti) {
- alt (static_ti) {
- case (none) { }
- case (some(?ti)) {
- if (field == abi::tydesc_field_copy_glue) {
- alt ({ ti.copy_glue }) {
- case (some(_)) { }
- case (none) {
- log #fmt("+++ lazily_emit_tydesc_glue TAKE %s",
- ty_to_str(bcx_tcx(cx), ti.ty));
- auto lcx = cx.fcx.lcx;
- auto glue_fn =
- declare_generic_glue(lcx, ti.ty,
- T_glue_fn(*lcx.ccx),
- "copy");
- ti.copy_glue = some[ValueRef](glue_fn);
- make_generic_glue(lcx, cx.sp, ti.ty, glue_fn,
- mgghf_single(make_copy_glue),
- ti.ty_params, "take");
- log #fmt("--- lazily_emit_tydesc_glue TAKE %s",
- ty_to_str(bcx_tcx(cx), ti.ty));
- }
- }
- } else if (field == abi::tydesc_field_drop_glue) {
- alt ({ ti.drop_glue }) {
- case (some(_)) { }
- case (none) {
- log #fmt("+++ lazily_emit_tydesc_glue DROP %s",
- ty_to_str(bcx_tcx(cx), ti.ty));
- auto lcx = cx.fcx.lcx;
- auto glue_fn =
- declare_generic_glue(lcx, ti.ty,
- T_glue_fn(*lcx.ccx),
- "drop");
- ti.drop_glue = some[ValueRef](glue_fn);
- make_generic_glue(lcx, cx.sp, ti.ty, glue_fn,
- mgghf_single(make_drop_glue),
- ti.ty_params, "drop");
- log #fmt("--- lazily_emit_tydesc_glue DROP %s",
- ty_to_str(bcx_tcx(cx), ti.ty));
- }
- }
- } else if (field == abi::tydesc_field_free_glue) {
- alt ({ ti.free_glue }) {
- case (some(_)) { }
- case (none) {
- log #fmt("+++ lazily_emit_tydesc_glue FREE %s",
- ty_to_str(bcx_tcx(cx), ti.ty));
- auto lcx = cx.fcx.lcx;
- auto glue_fn =
- declare_generic_glue(lcx, ti.ty,
- T_glue_fn(*lcx.ccx),
- "free");
- ti.free_glue = some[ValueRef](glue_fn);
- make_generic_glue(lcx, cx.sp, ti.ty, glue_fn,
- mgghf_single(make_free_glue),
- ti.ty_params, "free");
- log #fmt("--- lazily_emit_tydesc_glue FREE %s",
- ty_to_str(bcx_tcx(cx), ti.ty));
- }
- }
- } else if (field == abi::tydesc_field_cmp_glue) {
- alt ({ ti.cmp_glue }) {
- case (some(_)) { }
- case (none) {
- log #fmt("+++ lazily_emit_tydesc_glue CMP %s",
- ty_to_str(bcx_tcx(cx), ti.ty));
- auto lcx = cx.fcx.lcx;
- auto glue_fn =
- declare_generic_glue(lcx, ti.ty,
- T_cmp_glue_fn(*lcx.ccx),
- "cmp");
- ti.cmp_glue = some[ValueRef](glue_fn);
- make_generic_glue(lcx, cx.sp, ti.ty, glue_fn,
- mgghf_cmp, ti.ty_params, "cmp");
- log #fmt("--- lazily_emit_tydesc_glue CMP %s",
- ty_to_str(bcx_tcx(cx), ti.ty));
- }
- }
+fn lazily_emit_tydesc_glue(cx: &@block_ctxt, field: int,
+ static_ti: &option::t[@tydesc_info]) {
+ alt static_ti {
+ none. { }
+ some(ti) {
+ if field == abi::tydesc_field_copy_glue {
+ alt { ti.copy_glue } {
+ some(_) { }
+ none. {
+ log #fmt("+++ lazily_emit_tydesc_glue TAKE %s",
+ ty_to_str(bcx_tcx(cx), ti.ty));
+ let lcx = cx.fcx.lcx;
+ let glue_fn =
+ declare_generic_glue(lcx, ti.ty, T_glue_fn(*lcx.ccx),
+ "copy");
+ ti.copy_glue = some[ValueRef](glue_fn);
+ make_generic_glue(lcx, cx.sp, ti.ty, glue_fn,
+ mgghf_single(make_copy_glue), ti.ty_params,
+ "take");
+ log #fmt("--- lazily_emit_tydesc_glue TAKE %s",
+ ty_to_str(bcx_tcx(cx), ti.ty));
+ }
+ }
+ } else if (field == abi::tydesc_field_drop_glue) {
+ alt { ti.drop_glue } {
+ some(_) { }
+ none. {
+ log #fmt("+++ lazily_emit_tydesc_glue DROP %s",
+ ty_to_str(bcx_tcx(cx), ti.ty));
+ let lcx = cx.fcx.lcx;
+ let glue_fn =
+ declare_generic_glue(lcx, ti.ty, T_glue_fn(*lcx.ccx),
+ "drop");
+ ti.drop_glue = some[ValueRef](glue_fn);
+ make_generic_glue(lcx, cx.sp, ti.ty, glue_fn,
+ mgghf_single(make_drop_glue), ti.ty_params,
+ "drop");
+ log #fmt("--- lazily_emit_tydesc_glue DROP %s",
+ ty_to_str(bcx_tcx(cx), ti.ty));
+ }
+ }
+ } else if (field == abi::tydesc_field_free_glue) {
+ alt { ti.free_glue } {
+ some(_) { }
+ none. {
+ log #fmt("+++ lazily_emit_tydesc_glue FREE %s",
+ ty_to_str(bcx_tcx(cx), ti.ty));
+ let lcx = cx.fcx.lcx;
+ let glue_fn =
+ declare_generic_glue(lcx, ti.ty, T_glue_fn(*lcx.ccx),
+ "free");
+ ti.free_glue = some[ValueRef](glue_fn);
+ make_generic_glue(lcx, cx.sp, ti.ty, glue_fn,
+ mgghf_single(make_free_glue), ti.ty_params,
+ "free");
+ log #fmt("--- lazily_emit_tydesc_glue FREE %s",
+ ty_to_str(bcx_tcx(cx), ti.ty));
+ }
+ }
+ } else if (field == abi::tydesc_field_cmp_glue) {
+ alt { ti.cmp_glue } {
+ some(_) { }
+ none. {
+ log #fmt("+++ lazily_emit_tydesc_glue CMP %s",
+ ty_to_str(bcx_tcx(cx), ti.ty));
+ let lcx = cx.fcx.lcx;
+ let glue_fn =
+ declare_generic_glue(lcx, ti.ty, T_cmp_glue_fn(*lcx.ccx),
+ "cmp");
+ ti.cmp_glue = some[ValueRef](glue_fn);
+ make_generic_glue(lcx, cx.sp, ti.ty, glue_fn, mgghf_cmp,
+ ti.ty_params, "cmp");
+ log #fmt("--- lazily_emit_tydesc_glue CMP %s",
+ ty_to_str(bcx_tcx(cx), ti.ty));
+ }
}
}
+ }
}
}
-fn call_tydesc_glue_full(&@block_ctxt cx, ValueRef v, ValueRef tydesc,
- int field, &option::t[@tydesc_info] static_ti) {
+fn call_tydesc_glue_full(cx: &@block_ctxt, v: ValueRef, tydesc: ValueRef,
+ field: int, static_ti: &option::t[@tydesc_info]) {
lazily_emit_tydesc_glue(cx, field, static_ti);
- auto static_glue_fn = none;
- alt (static_ti) {
- case (none) { /* no-op */ }
- case (some(?sti)) {
- if (field == abi::tydesc_field_copy_glue) {
+ let static_glue_fn = none;
+ alt static_ti {
+ none. {/* no-op */ }
+ some(sti) {
+ if field == abi::tydesc_field_copy_glue {
static_glue_fn = sti.copy_glue;
} else if (field == abi::tydesc_field_drop_glue) {
static_glue_fn = sti.drop_glue;
@@ -2314,19 +2264,19 @@
}
}
- auto llrawptr = cx.build.BitCast(v, T_ptr(T_i8()));
- auto lltydescs =
+ let llrawptr = cx.build.BitCast(v, T_ptr(T_i8()));
+ let lltydescs =
cx.build.GEP(tydesc,
~[C_int(0), C_int(abi::tydesc_field_first_param)]);
lltydescs = cx.build.Load(lltydescs);
- auto llfn;
- alt (static_glue_fn) {
- case (none) {
- auto llfnptr = cx.build.GEP(tydesc, ~[C_int(0), C_int(field)]);
+ let llfn;
+ alt static_glue_fn {
+ none. {
+ let llfnptr = cx.build.GEP(tydesc, ~[C_int(0), C_int(field)]);
llfn = cx.build.Load(llfnptr);
}
- case (some(?sgf)) { llfn = sgf; }
+ some(sgf) { llfn = sgf; }
}
cx.build.Call(llfn,
@@ -2334,68 +2284,67 @@
C_null(T_ptr(T_nil())), lltydescs, llrawptr]);
}
-fn call_tydesc_glue(&@block_ctxt cx, ValueRef v, &ty::t t, int field) ->
+fn call_tydesc_glue(cx: &@block_ctxt, v: ValueRef, t: &ty::t, field: int) ->
result {
- let option::t[@tydesc_info] ti = none[@tydesc_info];
- auto td = get_tydesc(cx, t, false, ti);
+ let ti: option::t[@tydesc_info] = none[@tydesc_info];
+ let td = get_tydesc(cx, t, false, ti);
call_tydesc_glue_full(td.bcx, spill_if_immediate(td.bcx, v, t), td.val,
field, ti);
ret rslt(td.bcx, C_nil());
}
-fn maybe_call_dtor(&@block_ctxt cx, ValueRef v) -> @block_ctxt {
- auto vtbl = cx.build.GEP(v, ~[C_int(0), C_int(abi::obj_field_vtbl)]);
+fn maybe_call_dtor(cx: &@block_ctxt, v: ValueRef) -> @block_ctxt {
+ let vtbl = cx.build.GEP(v, ~[C_int(0), C_int(abi::obj_field_vtbl)]);
vtbl = cx.build.Load(vtbl);
- auto vtbl_type = T_ptr(T_array(T_ptr(T_nil()), 1u));
+ let vtbl_type = T_ptr(T_array(T_ptr(T_nil()), 1u));
vtbl = cx.build.PointerCast(vtbl, vtbl_type);
- auto dtor_ptr = cx.build.GEP(vtbl, ~[C_int(0), C_int(0)]);
+ let dtor_ptr = cx.build.GEP(vtbl, ~[C_int(0), C_int(0)]);
dtor_ptr = cx.build.Load(dtor_ptr);
- dtor_ptr =
- cx.build.BitCast(dtor_ptr,
- T_ptr(T_dtor(bcx_ccx(cx), cx.sp)));
- auto dtor_cx = new_sub_block_ctxt(cx, "dtor");
- auto after_cx = new_sub_block_ctxt(cx, "after_dtor");
- auto test =
+ dtor_ptr = cx.build.BitCast(dtor_ptr, T_ptr(T_dtor(bcx_ccx(cx), cx.sp)));
+ let dtor_cx = new_sub_block_ctxt(cx, "dtor");
+ let after_cx = new_sub_block_ctxt(cx, "after_dtor");
+ let test =
cx.build.ICmp(lib::llvm::LLVMIntNE, dtor_ptr,
C_null(val_ty(dtor_ptr)));
cx.build.CondBr(test, dtor_cx.llbb, after_cx.llbb);
- auto me = dtor_cx.build.Load(v);
+ let me = dtor_cx.build.Load(v);
dtor_cx.build.FastCall(dtor_ptr,
~[C_null(T_ptr(T_nil())), cx.fcx.lltaskptr, me]);
dtor_cx.build.Br(after_cx.llbb);
ret after_cx;
}
-fn call_cmp_glue(&@block_ctxt cx, ValueRef lhs, ValueRef rhs, &ty::t t,
- ValueRef llop) -> result {
+fn call_cmp_glue(cx: &@block_ctxt, lhs: ValueRef, rhs: ValueRef, t: &ty::t,
+ llop: ValueRef) -> result {
// We can't use call_tydesc_glue_full() and friends here because compare
// glue has a special signature.
- auto lllhs = spill_if_immediate(cx, lhs, t);
- auto llrhs = spill_if_immediate(cx, rhs, t);
- auto llrawlhsptr = cx.build.BitCast(lllhs, T_ptr(T_i8()));
- auto llrawrhsptr = cx.build.BitCast(llrhs, T_ptr(T_i8()));
- auto ti = none[@tydesc_info];
- auto r = get_tydesc(cx, t, false, ti);
+ let lllhs = spill_if_immediate(cx, lhs, t);
+ let llrhs = spill_if_immediate(cx, rhs, t);
+ let llrawlhsptr = cx.build.BitCast(lllhs, T_ptr(T_i8()));
+ let llrawrhsptr = cx.build.BitCast(llrhs, T_ptr(T_i8()));
+ let ti = none[@tydesc_info];
+ let r = get_tydesc(cx, t, false, ti);
lazily_emit_tydesc_glue(cx, abi::tydesc_field_cmp_glue, ti);
- auto lltydescs =
+ let lltydescs =
r.bcx.build.GEP(r.val,
~[C_int(0), C_int(abi::tydesc_field_first_param)]);
lltydescs = r.bcx.build.Load(lltydescs);
- auto llfn;
- alt (ti) {
- case (none) {
- auto llfnptr = r.bcx.build.GEP(r.val, ~[C_int(0),
- C_int(abi::tydesc_field_cmp_glue)]);
+ let llfn;
+ alt ti {
+ none. {
+ let llfnptr =
+ r.bcx.build.GEP(r.val,
+ ~[C_int(0), C_int(abi::tydesc_field_cmp_glue)]);
llfn = r.bcx.build.Load(llfnptr);
}
- case (some(?sti)) { llfn = option::get(sti.cmp_glue); }
+ some(sti) { llfn = option::get(sti.cmp_glue); }
}
- auto llcmpresultptr = alloca(r.bcx, T_i1());
- let ValueRef[] llargs =
+ let llcmpresultptr = alloca(r.bcx, T_i1());
+ let llargs: ValueRef[] =
~[llcmpresultptr, r.bcx.fcx.lltaskptr, C_null(T_ptr(T_nil())),
lltydescs, llrawlhsptr, llrawrhsptr, llop];
r.bcx.build.Call(llfn, llargs);
@@ -2404,145 +2353,138 @@
// Compares two values. Performs the simple scalar comparison if the types are
// scalar and calls to comparison glue otherwise.
-fn compare(&@block_ctxt cx, ValueRef lhs, ValueRef rhs, &ty::t t,
- ValueRef llop) -> result {
- if (ty::type_is_scalar(bcx_tcx(cx), t)) {
+fn compare(cx: &@block_ctxt, lhs: ValueRef, rhs: ValueRef, t: &ty::t,
+ llop: ValueRef) -> result {
+ if ty::type_is_scalar(bcx_tcx(cx), t) {
ret compare_scalar_types(cx, lhs, rhs, t, llop);
}
ret call_cmp_glue(cx, lhs, rhs, t, llop);
}
-fn copy_ty(&@block_ctxt cx, ValueRef v, ty::t t) -> result {
- if (ty::type_has_pointers(bcx_tcx(cx), t) ||
- ty::type_owns_heap_mem(bcx_tcx(cx), t)) {
+fn copy_ty(cx: &@block_ctxt, v: ValueRef, t: ty::t) -> result {
+ if ty::type_has_pointers(bcx_tcx(cx), t) ||
+ ty::type_owns_heap_mem(bcx_tcx(cx), t) {
ret call_tydesc_glue(cx, v, t, abi::tydesc_field_copy_glue);
}
ret rslt(cx, C_nil());
}
-fn drop_slot(&@block_ctxt cx, ValueRef slot, &ty::t t) -> result {
- auto llptr = load_if_immediate(cx, slot, t);
- auto re = drop_ty(cx, llptr, t);
- auto llty = val_ty(slot);
- auto llelemty = lib::llvm::llvm::LLVMGetElementType(llty);
+fn drop_slot(cx: &@block_ctxt, slot: ValueRef, t: &ty::t) -> result {
+ let llptr = load_if_immediate(cx, slot, t);
+ let re = drop_ty(cx, llptr, t);
+ let llty = val_ty(slot);
+ let llelemty = lib::llvm::llvm::LLVMGetElementType(llty);
re.bcx.build.Store(C_null(llelemty), slot);
ret re;
}
-fn drop_ty(&@block_ctxt cx, ValueRef v, ty::t t) -> result {
- if (ty::type_has_pointers(bcx_tcx(cx), t)) {
+fn drop_ty(cx: &@block_ctxt, v: ValueRef, t: ty::t) -> result {
+ if ty::type_has_pointers(bcx_tcx(cx), t) {
ret call_tydesc_glue(cx, v, t, abi::tydesc_field_drop_glue);
}
ret rslt(cx, C_nil());
}
-fn free_ty(&@block_ctxt cx, ValueRef v, ty::t t) -> result {
- if (ty::type_has_pointers(bcx_tcx(cx), t)) {
+fn free_ty(cx: &@block_ctxt, v: ValueRef, t: ty::t) -> result {
+ if ty::type_has_pointers(bcx_tcx(cx), t) {
ret call_tydesc_glue(cx, v, t, abi::tydesc_field_free_glue);
}
ret rslt(cx, C_nil());
}
-fn call_memmove(&@block_ctxt cx, ValueRef dst, ValueRef src,
- ValueRef n_bytes) -> result {
+fn call_memmove(cx: &@block_ctxt, dst: ValueRef, src: ValueRef,
+ n_bytes: ValueRef) -> result {
// FIXME: switch to the 64-bit variant when on such a platform.
// TODO: Provide LLVM with better alignment information when the alignment
// is statically known (it must be nothing more than a constant int, or
// LLVM complains -- not even a constant element of a tydesc works).
- auto i = bcx_ccx(cx).intrinsics;
+ let i = bcx_ccx(cx).intrinsics;
assert (i.contains_key("llvm.memmove.p0i8.p0i8.i32"));
- auto memmove = i.get("llvm.memmove.p0i8.p0i8.i32");
- auto src_ptr = cx.build.PointerCast(src, T_ptr(T_i8()));
- auto dst_ptr = cx.build.PointerCast(dst, T_ptr(T_i8()));
- auto size = cx.build.IntCast(n_bytes, T_i32());
- auto align = C_int(0);
- auto volatile = C_bool(false);
+ let memmove = i.get("llvm.memmove.p0i8.p0i8.i32");
+ let src_ptr = cx.build.PointerCast(src, T_ptr(T_i8()));
+ let dst_ptr = cx.build.PointerCast(dst, T_ptr(T_i8()));
+ let size = cx.build.IntCast(n_bytes, T_i32());
+ let align = C_int(0);
+ let volatile = C_bool(false);
ret rslt(cx,
- cx.build.Call(memmove,
- ~[dst_ptr, src_ptr, size, align, volatile]));
+ cx.build.Call(memmove,
+ ~[dst_ptr, src_ptr, size, align, volatile]));
}
-fn call_bzero(&@block_ctxt cx, ValueRef dst, ValueRef n_bytes,
- ValueRef align_bytes) -> result {
+fn call_bzero(cx: &@block_ctxt, dst: ValueRef, n_bytes: ValueRef,
+ align_bytes: ValueRef) -> result {
// FIXME: switch to the 64-bit variant when on such a platform.
- auto i = bcx_ccx(cx).intrinsics;
+ let i = bcx_ccx(cx).intrinsics;
assert (i.contains_key("llvm.memset.p0i8.i32"));
- auto memset = i.get("llvm.memset.p0i8.i32");
- auto dst_ptr = cx.build.PointerCast(dst, T_ptr(T_i8()));
- auto size = cx.build.IntCast(n_bytes, T_i32());
- auto align =
- if (lib::llvm::llvm::LLVMIsConstant(align_bytes) == True) {
+ let memset = i.get("llvm.memset.p0i8.i32");
+ let dst_ptr = cx.build.PointerCast(dst, T_ptr(T_i8()));
+ let size = cx.build.IntCast(n_bytes, T_i32());
+ let align =
+ if lib::llvm::llvm::LLVMIsConstant(align_bytes) == True {
cx.build.IntCast(align_bytes, T_i32())
} else { cx.build.IntCast(C_int(0), T_i32()) };
- auto volatile = C_bool(false);
+ let volatile = C_bool(false);
ret rslt(cx,
- cx.build.Call(memset,
- ~[dst_ptr, C_u8(0u), size, align, volatile]));
+ cx.build.Call(memset,
+ ~[dst_ptr, C_u8(0u), size, align, volatile]));
}
-fn memmove_ty(&@block_ctxt cx, ValueRef dst, ValueRef src, &ty::t t) ->
+fn memmove_ty(cx: &@block_ctxt, dst: ValueRef, src: ValueRef, t: &ty::t) ->
result {
- if (ty::type_has_dynamic_size(bcx_tcx(cx), t)) {
- auto llsz = size_of(cx, t);
+ if ty::type_has_dynamic_size(bcx_tcx(cx), t) {
+ let llsz = size_of(cx, t);
ret call_memmove(llsz.bcx, dst, src, llsz.val);
- } else {
- ret rslt(cx, cx.build.Store(cx.build.Load(src), dst));
- }
+ } else { ret rslt(cx, cx.build.Store(cx.build.Load(src), dst)); }
}
// Duplicates any heap-owned memory owned by a value of the given type.
-fn duplicate_heap_parts_if_necessary(&@block_ctxt cx, ValueRef vptr,
- ty::t typ) -> result {
- alt (ty::struct(bcx_tcx(cx), typ)) {
- case (ty::ty_ivec(?tm)) {
- ret ivec::duplicate_heap_part(cx, vptr, tm.ty);
- }
- case (ty::ty_istr) {
+fn duplicate_heap_parts_if_necessary(cx: &@block_ctxt, vptr: ValueRef,
+ typ: ty::t) -> result {
+ alt ty::struct(bcx_tcx(cx), typ) {
+ ty::ty_ivec(tm) { ret ivec::duplicate_heap_part(cx, vptr, tm.ty); }
+ ty::ty_istr. {
ret ivec::duplicate_heap_part(cx, vptr,
- ty::mk_mach(bcx_tcx(cx), ast::ty_u8));
+ ty::mk_mach(bcx_tcx(cx), ast::ty_u8));
}
- case (_) { ret rslt(cx, C_nil()); }
+ _ { ret rslt(cx, C_nil()); }
}
}
tag copy_action { INIT; DROP_EXISTING; }
-fn copy_val(&@block_ctxt cx, copy_action action, ValueRef dst, ValueRef src,
- &ty::t t) -> result {
- auto ccx = bcx_ccx(cx);
+fn copy_val(cx: &@block_ctxt, action: copy_action, dst: ValueRef,
+ src: ValueRef, t: &ty::t) -> result {
+ let ccx = bcx_ccx(cx);
// FIXME this is just a clunky stopgap. we should do proper checking in an
// earlier pass.
- if (!ty::type_is_copyable(ccx.tcx, t)) {
+ if !ty::type_is_copyable(ccx.tcx, t) {
ccx.sess.span_fatal(cx.sp, "Copying a non-copyable type.");
}
- if (ty::type_is_scalar(ccx.tcx, t) ||
- ty::type_is_native(ccx.tcx, t)) {
+ if ty::type_is_scalar(ccx.tcx, t) || ty::type_is_native(ccx.tcx, t) {
ret rslt(cx, cx.build.Store(src, dst));
- } else if (ty::type_is_nil(ccx.tcx, t) ||
- ty::type_is_bot(ccx.tcx, t)) {
+ } else if (ty::type_is_nil(ccx.tcx, t) || ty::type_is_bot(ccx.tcx, t)) {
ret rslt(cx, C_nil());
} else if (ty::type_is_boxed(ccx.tcx, t)) {
- auto bcx;
- if (action == DROP_EXISTING) {
+ let bcx;
+ if action == DROP_EXISTING {
bcx = drop_ty(cx, cx.build.Load(dst), t).bcx;
- } else {
- bcx = cx;
- }
+ } else { bcx = cx; }
bcx = copy_ty(bcx, src, t).bcx;
ret rslt(bcx, bcx.build.Store(src, dst));
} else if (ty::type_is_structural(ccx.tcx, t) ||
ty::type_has_dynamic_size(ccx.tcx, t)) {
// Check for self-assignment.
- auto do_copy_cx = new_sub_block_ctxt(cx, "do_copy");
- auto next_cx = new_sub_block_ctxt(cx, "next");
- auto self_assigning = cx.build.ICmp(lib::llvm::LLVMIntNE,
- cx.build.PointerCast(dst, val_ty(src)), src);
+ let do_copy_cx = new_sub_block_ctxt(cx, "do_copy");
+ let next_cx = new_sub_block_ctxt(cx, "next");
+ let self_assigning =
+ cx.build.ICmp(lib::llvm::LLVMIntNE,
+ cx.build.PointerCast(dst, val_ty(src)), src);
cx.build.CondBr(self_assigning, do_copy_cx.llbb, next_cx.llbb);
- if (action == DROP_EXISTING) {
+ if action == DROP_EXISTING {
do_copy_cx = drop_ty(do_copy_cx, dst, t).bcx;
}
do_copy_cx = memmove_ty(do_copy_cx, dst, src, t).bcx;
@@ -2552,7 +2494,7 @@
ret rslt(next_cx, C_nil());
}
ccx.sess.bug("unexpected type in trans::copy_val: " +
- ty_to_str(ccx.tcx, t));
+ ty_to_str(ccx.tcx, t));
}
@@ -2561,34 +2503,34 @@
// FIXME: We always zero out the source. Ideally we would detect the
// case where a variable is always deinitialized by block exit and thus
// doesn't need to be dropped.
-fn move_val(@block_ctxt cx, copy_action action, ValueRef dst,
- &lval_result src, &ty::t t) -> result {
- auto src_val = src.res.val;
- if (ty::type_is_scalar(bcx_tcx(cx), t) ||
- ty::type_is_native(bcx_tcx(cx), t)) {
- if (src.is_mem) { src_val = cx.build.Load(src_val); }
+fn move_val(cx: @block_ctxt, action: copy_action, dst: ValueRef,
+ src: &lval_result, t: &ty::t) -> result {
+ let src_val = src.res.val;
+ if ty::type_is_scalar(bcx_tcx(cx), t) ||
+ ty::type_is_native(bcx_tcx(cx), t) {
+ if src.is_mem { src_val = cx.build.Load(src_val); }
cx.build.Store(src_val, dst);
ret rslt(cx, C_nil());
} else if (ty::type_is_nil(bcx_tcx(cx), t) ||
- ty::type_is_bot(bcx_tcx(cx), t)) {
+ ty::type_is_bot(bcx_tcx(cx), t)) {
ret rslt(cx, C_nil());
} else if (ty::type_is_boxed(bcx_tcx(cx), t)) {
- if (src.is_mem) { src_val = cx.build.Load(src_val); }
- if (action == DROP_EXISTING) {
+ if src.is_mem { src_val = cx.build.Load(src_val); }
+ if action == DROP_EXISTING {
cx = drop_ty(cx, cx.build.Load(dst), t).bcx;
}
cx.build.Store(src_val, dst);
- if (src.is_mem) {
+ if src.is_mem {
ret zero_alloca(cx, src.res.val, t);
} else { // It must be a temporary
revoke_clean(cx, src_val);
ret rslt(cx, C_nil());
}
} else if (ty::type_is_structural(bcx_tcx(cx), t) ||
- ty::type_has_dynamic_size(bcx_tcx(cx), t)) {
- if (action == DROP_EXISTING) { cx = drop_ty(cx, dst, t).bcx; }
+ ty::type_has_dynamic_size(bcx_tcx(cx), t)) {
+ if action == DROP_EXISTING { cx = drop_ty(cx, dst, t).bcx; }
cx = memmove_ty(cx, dst, src_val, t).bcx;
- if (src.is_mem) {
+ if src.is_mem {
ret zero_alloca(cx, src_val, t);
} else { // Temporary value
revoke_clean(cx, src_val);
@@ -2596,34 +2538,33 @@
}
}
bcx_ccx(cx).sess.bug("unexpected type in trans::move_val: " +
- ty_to_str(bcx_tcx(cx), t));
+ ty_to_str(bcx_tcx(cx), t));
}
-fn move_val_if_temp(@block_ctxt cx, copy_action action, ValueRef dst,
- &lval_result src, &ty::t t) -> result {
+fn move_val_if_temp(cx: @block_ctxt, action: copy_action, dst: ValueRef,
+ src: &lval_result, t: &ty::t) -> result {
+
// Lvals in memory are not temporaries. Copy them.
- if (src.is_mem) {
- ret copy_val(cx, action, dst,
- load_if_immediate(cx, src.res.val, t), t);
- } else {
- ret move_val(cx, action, dst, src, t);
- }
+ if src.is_mem {
+ ret copy_val(cx, action, dst, load_if_immediate(cx, src.res.val, t),
+ t);
+ } else { ret move_val(cx, action, dst, src, t); }
}
-fn trans_lit_istr(&@block_ctxt cx, str s) -> result {
- auto llstackpart = alloca(cx, T_ivec(T_i8()));
- auto len = str::byte_len(s);
+fn trans_lit_istr(cx: &@block_ctxt, s: str) -> result {
+ let llstackpart = alloca(cx, T_ivec(T_i8()));
+ let len = str::byte_len(s);
- auto bcx;
- if (len < 3u) { // 3 because of the \0
+ let bcx;
+ if len < 3u { // 3 because of the \0
cx.build.Store(C_uint(len + 1u),
cx.build.InBoundsGEP(llstackpart,
~[C_int(0), C_int(0)]));
cx.build.Store(C_int(4),
cx.build.InBoundsGEP(llstackpart,
~[C_int(0), C_int(1)]));
- auto i = 0u;
- while (i < len) {
+ let i = 0u;
+ while i < len {
cx.build.Store(C_u8(s.(i) as uint),
cx.build.InBoundsGEP(llstackpart,
~[C_int(0), C_int(2),
@@ -2637,13 +2578,13 @@
bcx = cx;
} else {
- auto r =
+ let r =
trans_shared_malloc(cx, T_ptr(T_ivec_heap_part(T_i8())),
llsize_of(T_struct(~[T_int(),
T_array(T_i8(),
len + 1u)])));
bcx = r.bcx;
- auto llheappart = r.val;
+ let llheappart = r.val;
bcx.build.Store(C_uint(len + 1u),
bcx.build.InBoundsGEP(llheappart,
@@ -2652,8 +2593,8 @@
bcx.build.InBoundsGEP(llheappart,
~[C_int(0), C_int(1)]));
- auto llspilledstackpart = bcx.build.PointerCast(llstackpart,
- T_ptr(T_ivec_heap(T_i8())));
+ let llspilledstackpart =
+ bcx.build.PointerCast(llstackpart, T_ptr(T_ivec_heap(T_i8())));
bcx.build.Store(C_int(0),
bcx.build.InBoundsGEP(llspilledstackpart,
~[C_int(0), C_int(0)]));
@@ -2668,317 +2609,311 @@
ret rslt(bcx, llstackpart);
}
-fn trans_crate_lit(&@crate_ctxt cx, &ast::lit lit) -> ValueRef {
- alt (lit.node) {
- case (ast::lit_int(?i)) { ret C_int(i); }
- case (ast::lit_uint(?u)) { ret C_int(u as int); }
- case (ast::lit_mach_int(?tm, ?i)) {
- // FIXME: the entire handling of mach types falls apart
- // if target int width is larger than host, at the moment;
- // re-do the mach-int types using 'big' when that works.
+fn trans_crate_lit(cx: &@crate_ctxt, lit: &ast::lit) -> ValueRef {
+ alt lit.node {
+ ast::lit_int(i) { ret C_int(i); }
+ ast::lit_uint(u) { ret C_int(u as int); }
+ ast::lit_mach_int(tm, i) {
+ // FIXME: the entire handling of mach types falls apart
+ // if target int width is larger than host, at the moment;
+ // re-do the mach-int types using 'big' when that works.
- auto t = T_int();
- auto s = True;
- alt (tm) {
- case (ast::ty_u8) { t = T_i8(); s = False; }
- case (ast::ty_u16) { t = T_i16(); s = False; }
- case (ast::ty_u32) { t = T_i32(); s = False; }
- case (ast::ty_u64) { t = T_i64(); s = False; }
- case (ast::ty_i8) { t = T_i8(); }
- case (ast::ty_i16) { t = T_i16(); }
- case (ast::ty_i32) { t = T_i32(); }
- case (ast::ty_i64) { t = T_i64(); }
- }
- ret C_integral(t, i as uint, s);
+ let t = T_int();
+ let s = True;
+ alt tm {
+ ast::ty_u8. { t = T_i8(); s = False; }
+ ast::ty_u16. { t = T_i16(); s = False; }
+ ast::ty_u32. { t = T_i32(); s = False; }
+ ast::ty_u64. { t = T_i64(); s = False; }
+ ast::ty_i8. { t = T_i8(); }
+ ast::ty_i16. { t = T_i16(); }
+ ast::ty_i32. { t = T_i32(); }
+ ast::ty_i64. { t = T_i64(); }
}
- case (ast::lit_float(?fs)) { ret C_float(fs); }
- case (ast::lit_mach_float(?tm, ?s)) {
- auto t = T_float();
- alt (tm) {
- case (ast::ty_f32) { t = T_f32(); }
- case (ast::ty_f64) { t = T_f64(); }
- }
- ret C_floating(s, t);
- }
- case (ast::lit_char(?c)) {
- ret C_integral(T_char(), c as uint, False);
- }
- case (ast::lit_bool(?b)) { ret C_bool(b); }
- case (ast::lit_nil) { ret C_nil(); }
- case (ast::lit_str(?s, ast::sk_rc)) { ret C_str(cx, s); }
- case (ast::lit_str(?s, ast::sk_unique)) {
- cx.sess.span_unimpl(lit.span, "unique string in this context");
- }
+ ret C_integral(t, i as uint, s);
+ }
+ ast::lit_float(fs) { ret C_float(fs); }
+ ast::lit_mach_float(tm, s) {
+ let t = T_float();
+ alt tm { ast::ty_f32. { t = T_f32(); } ast::ty_f64. { t = T_f64(); } }
+ ret C_floating(s, t);
+ }
+ ast::lit_char(c) { ret C_integral(T_char(), c as uint, False); }
+ ast::lit_bool(b) { ret C_bool(b); }
+ ast::lit_nil. { ret C_nil(); }
+ ast::lit_str(s, ast::sk_rc.) { ret C_str(cx, s); }
+ ast::lit_str(s, ast::sk_unique.) {
+ cx.sess.span_unimpl(lit.span, "unique string in this context");
+ }
}
}
-fn trans_lit(&@block_ctxt cx, &ast::lit lit) -> result {
- alt (lit.node) {
- ast::lit_str(?s, ast::sk_unique) { ret trans_lit_istr(cx, s); }
+fn trans_lit(cx: &@block_ctxt, lit: &ast::lit) -> result {
+ alt lit.node {
+ ast::lit_str(s, ast::sk_unique.) { ret trans_lit_istr(cx, s); }
_ { ret rslt(cx, trans_crate_lit(bcx_ccx(cx), lit)); }
}
}
// Converts an annotation to a type
-fn node_id_type(&@crate_ctxt cx, ast::node_id id) -> ty::t {
+fn node_id_type(cx: &@crate_ctxt, id: ast::node_id) -> ty::t {
ret ty::node_id_to_monotype(cx.tcx, id);
}
-fn node_type(&@crate_ctxt cx, &span sp, ast::node_id id) -> TypeRef {
+fn node_type(cx: &@crate_ctxt, sp: &span, id: ast::node_id) -> TypeRef {
ret type_of(cx, sp, node_id_type(cx, id));
}
-fn trans_unary(&@block_ctxt cx, ast::unop op, &@ast::expr e,
- ast::node_id id) -> result {
- auto e_ty = ty::expr_ty(bcx_tcx(cx), e);
- alt (op) {
- case (ast::not) {
- auto sub = trans_expr(cx, e);
- auto dr = autoderef(sub.bcx, sub.val,
- ty::expr_ty(bcx_tcx(cx), e));
- ret rslt(dr.bcx, dr.bcx.build.Not(dr.val));
- }
- case (ast::neg) {
- auto sub = trans_expr(cx, e);
- auto dr = autoderef(sub.bcx, sub.val,
- ty::expr_ty(bcx_tcx(cx), e));
- if (ty::struct(bcx_tcx(cx), e_ty) == ty::ty_float) {
- ret rslt(dr.bcx, dr.bcx.build.FNeg(dr.val));
- } else { ret rslt(dr.bcx, sub.bcx.build.Neg(dr.val)); }
- }
- case (ast::box(_)) {
- auto lv = trans_lval(cx, e);
- auto box_ty = node_id_type(bcx_ccx(lv.res.bcx), id);
- auto sub = trans_malloc_boxed(lv.res.bcx, e_ty);
- add_clean_temp(cx, sub.val, box_ty);
- auto box = sub.val;
- auto rc = sub.bcx.build.GEP
- (box, ~[C_int(0), C_int(abi::box_rc_field_refcnt)]);
- auto body = sub.bcx.build.GEP
- (box, ~[C_int(0), C_int(abi::box_rc_field_body)]);
- sub.bcx.build.Store(C_int(1), rc);
- // Cast the body type to the type of the value. This is needed to
- // make tags work, since tags have a different LLVM type depending
- // on whether they're boxed or not.
+fn trans_unary(cx: &@block_ctxt, op: ast::unop, e: &@ast::expr,
+ id: ast::node_id) -> result {
+ let e_ty = ty::expr_ty(bcx_tcx(cx), e);
+ alt op {
+ ast::not. {
+ let sub = trans_expr(cx, e);
+ let dr = autoderef(sub.bcx, sub.val, ty::expr_ty(bcx_tcx(cx), e));
+ ret rslt(dr.bcx, dr.bcx.build.Not(dr.val));
+ }
+ ast::neg. {
+ let sub = trans_expr(cx, e);
+ let dr = autoderef(sub.bcx, sub.val, ty::expr_ty(bcx_tcx(cx), e));
+ if ty::struct(bcx_tcx(cx), e_ty) == ty::ty_float {
+ ret rslt(dr.bcx, dr.bcx.build.FNeg(dr.val));
+ } else { ret rslt(dr.bcx, sub.bcx.build.Neg(dr.val)); }
+ }
+ ast::box(_) {
+ let lv = trans_lval(cx, e);
+ let box_ty = node_id_type(bcx_ccx(lv.res.bcx), id);
+ let sub = trans_malloc_boxed(lv.res.bcx, e_ty);
+ add_clean_temp(cx, sub.val, box_ty);
+ let box = sub.val;
+ let rc =
+ sub.bcx.build.GEP(box,
+ ~[C_int(0), C_int(abi::box_rc_field_refcnt)]);
+ let body =
+ sub.bcx.build.GEP(box,
+ ~[C_int(0), C_int(abi::box_rc_field_body)]);
+ sub.bcx.build.Store(C_int(1), rc);
+ // Cast the body type to the type of the value. This is needed to
+ // make tags work, since tags have a different LLVM type depending
+ // on whether they're boxed or not.
- if (!ty::type_has_dynamic_size(bcx_tcx(cx), e_ty)) {
- auto llety =
- T_ptr(type_of(bcx_ccx(sub.bcx), e.span, e_ty));
- body = sub.bcx.build.PointerCast(body, llety);
- }
- sub = move_val_if_temp(sub.bcx, INIT, body, lv, e_ty);
- ret rslt(sub.bcx, box);
+ if !ty::type_has_dynamic_size(bcx_tcx(cx), e_ty) {
+ let llety = T_ptr(type_of(bcx_ccx(sub.bcx), e.span, e_ty));
+ body = sub.bcx.build.PointerCast(body, llety);
}
- case (ast::deref) {
- bcx_ccx(cx).sess.bug("deref expressions should have been \
+ sub = move_val_if_temp(sub.bcx, INIT, body, lv, e_ty);
+ ret rslt(sub.bcx, box);
+ }
+ ast::deref. {
+ bcx_ccx(cx).sess.bug("deref expressions should have been \
translated using trans_lval(), not \
trans_unary()");
- }
+ }
}
}
-fn trans_compare(&@block_ctxt cx0, ast::binop op, &ty::t t0, ValueRef lhs0,
- ValueRef rhs0) -> result {
+fn trans_compare(cx0: &@block_ctxt, op: ast::binop, t0: &ty::t,
+ lhs0: ValueRef, rhs0: ValueRef) -> result {
// Autoderef both sides.
- auto cx = cx0;
- auto lhs_r = autoderef(cx, lhs0, t0);
- auto lhs = lhs_r.val;
+ let cx = cx0;
+ let lhs_r = autoderef(cx, lhs0, t0);
+ let lhs = lhs_r.val;
cx = lhs_r.bcx;
- auto rhs_r = autoderef(cx, rhs0, t0);
- auto rhs = rhs_r.val;
+ let rhs_r = autoderef(cx, rhs0, t0);
+ let rhs = rhs_r.val;
cx = rhs_r.bcx;
// Determine the operation we need.
// FIXME: Use or-patterns when we have them.
- auto llop;
- alt (op) {
- case (ast::eq) { llop = C_u8(abi::cmp_glue_op_eq); }
- case (ast::lt) { llop = C_u8(abi::cmp_glue_op_lt); }
- case (ast::le) { llop = C_u8(abi::cmp_glue_op_le); }
- case (ast::ne) { llop = C_u8(abi::cmp_glue_op_eq); }
- case (ast::ge) { llop = C_u8(abi::cmp_glue_op_lt); }
- case (ast::gt) { llop = C_u8(abi::cmp_glue_op_le); }
+ let llop;
+ alt op {
+ ast::eq. { llop = C_u8(abi::cmp_glue_op_eq); }
+ ast::lt. { llop = C_u8(abi::cmp_glue_op_lt); }
+ ast::le. { llop = C_u8(abi::cmp_glue_op_le); }
+ ast::ne. { llop = C_u8(abi::cmp_glue_op_eq); }
+ ast::ge. { llop = C_u8(abi::cmp_glue_op_lt); }
+ ast::gt. { llop = C_u8(abi::cmp_glue_op_le); }
}
- auto rs = compare(cx, lhs, rhs, rhs_r.ty, llop);
+ let rs = compare(cx, lhs, rhs, rhs_r.ty, llop);
+
// Invert the result if necessary.
// FIXME: Use or-patterns when we have them.
- alt (op) {
- case (ast::eq) { ret rslt(rs.bcx, rs.val); }
- case (ast::lt) { ret rslt(rs.bcx, rs.val); }
- case (ast::le) { ret rslt(rs.bcx, rs.val); }
- case (ast::ne) { ret rslt(rs.bcx, rs.bcx.build.Not(rs.val)); }
- case (ast::ge) { ret rslt(rs.bcx, rs.bcx.build.Not(rs.val)); }
- case (ast::gt) { ret rslt(rs.bcx, rs.bcx.build.Not(rs.val)); }
+ alt op {
+ ast::eq. { ret rslt(rs.bcx, rs.val); }
+ ast::lt. { ret rslt(rs.bcx, rs.val); }
+ ast::le. { ret rslt(rs.bcx, rs.val); }
+ ast::ne. { ret rslt(rs.bcx, rs.bcx.build.Not(rs.val)); }
+ ast::ge. { ret rslt(rs.bcx, rs.bcx.build.Not(rs.val)); }
+ ast::gt. { ret rslt(rs.bcx, rs.bcx.build.Not(rs.val)); }
}
}
-fn trans_vec_append(&@block_ctxt cx, &ty::t t, ValueRef lhs, ValueRef rhs) ->
- result {
- auto elt_ty = ty::sequence_element_type(bcx_tcx(cx), t);
- auto skip_null = C_bool(false);
- alt (ty::struct(bcx_tcx(cx), t)) {
- case (ty::ty_str) { skip_null = C_bool(true); }
- case (_) { }
+fn trans_vec_append(cx: &@block_ctxt, t: &ty::t, lhs: ValueRef, rhs: ValueRef)
+ -> result {
+ let elt_ty = ty::sequence_element_type(bcx_tcx(cx), t);
+ let skip_null = C_bool(false);
+ alt ty::struct(bcx_tcx(cx), t) {
+ ty::ty_str. { skip_null = C_bool(true); }
+ _ { }
}
- auto bcx = cx;
- auto ti = none[@tydesc_info];
- auto llvec_tydesc = get_tydesc(bcx, t, false, ti);
+ let bcx = cx;
+ let ti = none[@tydesc_info];
+ let llvec_tydesc = get_tydesc(bcx, t, false, ti);
bcx = llvec_tydesc.bcx;
ti = none[@tydesc_info];
- auto llelt_tydesc = get_tydesc(bcx, elt_ty, false, ti);
+ let llelt_tydesc = get_tydesc(bcx, elt_ty, false, ti);
lazily_emit_tydesc_glue(cx, abi::tydesc_field_copy_glue, ti);
lazily_emit_tydesc_glue(cx, abi::tydesc_field_drop_glue, ti);
lazily_emit_tydesc_glue(cx, abi::tydesc_field_free_glue, ti);
bcx = llelt_tydesc.bcx;
- auto dst = bcx.build.PointerCast(lhs, T_ptr(T_opaque_vec_ptr()));
- auto src = bcx.build.PointerCast(rhs, T_opaque_vec_ptr());
+ let dst = bcx.build.PointerCast(lhs, T_ptr(T_opaque_vec_ptr()));
+ let src = bcx.build.PointerCast(rhs, T_opaque_vec_ptr());
ret rslt(bcx,
- bcx.build.Call(bcx_ccx(cx).upcalls.vec_append,
- ~[cx.fcx.lltaskptr, llvec_tydesc.val,
- llelt_tydesc.val, dst, src, skip_null]));
+ bcx.build.Call(bcx_ccx(cx).upcalls.vec_append,
+ ~[cx.fcx.lltaskptr, llvec_tydesc.val,
+ llelt_tydesc.val, dst, src, skip_null]));
}
mod ivec {
// Returns the length of an interior vector and a pointer to its first
// element, in that order.
- fn get_len_and_data(&@block_ctxt bcx, ValueRef orig_v, ty::t unit_ty)
- -> rec(ValueRef len, ValueRef data, @block_ctxt bcx) {
+ fn get_len_and_data(bcx: &@block_ctxt, orig_v: ValueRef, unit_ty: ty::t)
+ -> {len: ValueRef, data: ValueRef, bcx: @block_ctxt} {
// If this interior vector has dynamic size, we can't assume anything
// about the LLVM type of the value passed in, so we cast it to an
// opaque vector type.
- auto v;
- if (ty::type_has_dynamic_size(bcx_tcx(bcx), unit_ty)) {
+ let v;
+ if ty::type_has_dynamic_size(bcx_tcx(bcx), unit_ty) {
v = bcx.build.PointerCast(orig_v, T_ptr(T_opaque_ivec()));
- } else {
- v = orig_v;
- }
+ } else { v = orig_v; }
- auto llunitty = type_of_or_i8(bcx, unit_ty);
- auto stack_len = load_inbounds(bcx, v, ~[C_int(0),
- C_uint(abi::ivec_elt_len)]);
- auto stack_elem =
+ let llunitty = type_of_or_i8(bcx, unit_ty);
+ let stack_len =
+ load_inbounds(bcx, v, ~[C_int(0), C_uint(abi::ivec_elt_len)]);
+ let stack_elem =
bcx.build.InBoundsGEP(v,
~[C_int(0), C_uint(abi::ivec_elt_elems),
C_int(0)]);
- auto on_heap =
+ let on_heap =
bcx.build.ICmp(lib::llvm::LLVMIntEQ, stack_len, C_int(0));
- auto on_heap_cx = new_sub_block_ctxt(bcx, "on_heap");
- auto next_cx = new_sub_block_ctxt(bcx, "next");
+ let on_heap_cx = new_sub_block_ctxt(bcx, "on_heap");
+ let next_cx = new_sub_block_ctxt(bcx, "next");
bcx.build.CondBr(on_heap, on_heap_cx.llbb, next_cx.llbb);
- auto heap_stub =
+ let heap_stub =
on_heap_cx.build.PointerCast(v, T_ptr(T_ivec_heap(llunitty)));
- auto heap_ptr = load_inbounds(on_heap_cx, heap_stub,
- ~[C_int(0),
- C_uint(abi::ivec_heap_stub_elt_ptr)]);
+ let heap_ptr =
+ load_inbounds(on_heap_cx, heap_stub,
+ ~[C_int(0), C_uint(abi::ivec_heap_stub_elt_ptr)]);
// Check whether the heap pointer is null. If it is, the vector length
// is truly zero.
- auto llstubty = T_ivec_heap(llunitty);
- auto llheapptrty = struct_elt(llstubty, abi::ivec_heap_stub_elt_ptr);
- auto heap_ptr_is_null =
+ let llstubty = T_ivec_heap(llunitty);
+ let llheapptrty = struct_elt(llstubty, abi::ivec_heap_stub_elt_ptr);
+ let heap_ptr_is_null =
on_heap_cx.build.ICmp(lib::llvm::LLVMIntEQ, heap_ptr,
C_null(T_ptr(llheapptrty)));
- auto zero_len_cx = new_sub_block_ctxt(bcx, "zero_len");
- auto nonzero_len_cx = new_sub_block_ctxt(bcx, "nonzero_len");
+ let zero_len_cx = new_sub_block_ctxt(bcx, "zero_len");
+ let nonzero_len_cx = new_sub_block_ctxt(bcx, "nonzero_len");
on_heap_cx.build.CondBr(heap_ptr_is_null, zero_len_cx.llbb,
nonzero_len_cx.llbb);
// Technically this context is unnecessary, but it makes this function
// clearer.
- auto zero_len = C_int(0);
- auto zero_elem = C_null(T_ptr(llunitty));
+ let zero_len = C_int(0);
+ let zero_elem = C_null(T_ptr(llunitty));
zero_len_cx.build.Br(next_cx.llbb);
// If we're here, then we actually have a heapified vector.
- auto heap_len = load_inbounds(nonzero_len_cx, heap_ptr,
- ~[C_int(0),
- C_uint(abi::ivec_heap_elt_len)]);
- auto heap_elem =
+ let heap_len =
+ load_inbounds(nonzero_len_cx, heap_ptr,
+ ~[C_int(0), C_uint(abi::ivec_heap_elt_len)]);
+ let heap_elem =
{
- auto v = ~[C_int(0), C_uint(abi::ivec_heap_elt_elems),
- C_int(0)];
- nonzero_len_cx.build.InBoundsGEP(heap_ptr,v)
+ let v =
+ ~[C_int(0), C_uint(abi::ivec_heap_elt_elems), C_int(0)];
+ nonzero_len_cx.build.InBoundsGEP(heap_ptr, v)
};
nonzero_len_cx.build.Br(next_cx.llbb);
// Now we can figure out the length of `v` and get a pointer to its
// first element.
- auto len =
+ let len =
next_cx.build.Phi(T_int(), ~[stack_len, zero_len, heap_len],
~[bcx.llbb, zero_len_cx.llbb,
nonzero_len_cx.llbb]);
- auto elem =
+ let elem =
next_cx.build.Phi(T_ptr(llunitty),
~[stack_elem, zero_elem, heap_elem],
~[bcx.llbb, zero_len_cx.llbb,
nonzero_len_cx.llbb]);
- ret rec(len=len, data=elem, bcx=next_cx);
+ ret {len: len, data: elem, bcx: next_cx};
}
// Returns a tuple consisting of a pointer to the newly-reserved space and
// a block context. Updates the length appropriately.
- fn reserve_space(&@block_ctxt cx, TypeRef llunitty, ValueRef v,
- ValueRef len_needed) -> result {
- auto stack_len_ptr =
+ fn reserve_space(cx: &@block_ctxt, llunitty: TypeRef, v: ValueRef,
+ len_needed: ValueRef) -> result {
+ let stack_len_ptr =
cx.build.InBoundsGEP(v, ~[C_int(0), C_uint(abi::ivec_elt_len)]);
- auto stack_len = cx.build.Load(stack_len_ptr);
- auto alen = load_inbounds(cx, v, ~[C_int(0),
- C_uint(abi::ivec_elt_alen)]);
+ let stack_len = cx.build.Load(stack_len_ptr);
+ let alen =
+ load_inbounds(cx, v, ~[C_int(0), C_uint(abi::ivec_elt_alen)]);
// There are four cases we have to consider:
// (1) On heap, no resize necessary.
// (2) On heap, need to resize.
// (3) On stack, no resize necessary.
// (4) On stack, need to spill to heap.
- auto maybe_on_heap =
+ let maybe_on_heap =
cx.build.ICmp(lib::llvm::LLVMIntEQ, stack_len, C_int(0));
- auto maybe_on_heap_cx = new_sub_block_ctxt(cx, "maybe_on_heap");
- auto on_stack_cx = new_sub_block_ctxt(cx, "on_stack");
+ let maybe_on_heap_cx = new_sub_block_ctxt(cx, "maybe_on_heap");
+ let on_stack_cx = new_sub_block_ctxt(cx, "on_stack");
cx.build.CondBr(maybe_on_heap, maybe_on_heap_cx.llbb,
on_stack_cx.llbb);
- auto next_cx = new_sub_block_ctxt(cx, "next");
+ let next_cx = new_sub_block_ctxt(cx, "next");
// We're possibly on the heap, unless the vector is zero-length.
- auto stub_p = ~[C_int(0), C_uint(abi::ivec_heap_stub_elt_ptr)];
- auto stub_ptr =
+ let stub_p = ~[C_int(0), C_uint(abi::ivec_heap_stub_elt_ptr)];
+ let stub_ptr =
maybe_on_heap_cx.build.PointerCast(v,
T_ptr(T_ivec_heap(llunitty)));
- auto heap_ptr = load_inbounds(maybe_on_heap_cx, stub_ptr, stub_p);
- auto on_heap =
+ let heap_ptr = load_inbounds(maybe_on_heap_cx, stub_ptr, stub_p);
+ let on_heap =
maybe_on_heap_cx.build.ICmp(lib::llvm::LLVMIntNE, heap_ptr,
C_null(val_ty(heap_ptr)));
- auto on_heap_cx = new_sub_block_ctxt(cx, "on_heap");
+ let on_heap_cx = new_sub_block_ctxt(cx, "on_heap");
maybe_on_heap_cx.build.CondBr(on_heap, on_heap_cx.llbb,
on_stack_cx.llbb);
// We're definitely on the heap. Check whether we need to resize.
- auto heap_len_ptr =
+ let heap_len_ptr =
on_heap_cx.build.InBoundsGEP(heap_ptr,
~[C_int(0),
C_uint(abi::ivec_heap_elt_len)]);
- auto heap_len = on_heap_cx.build.Load(heap_len_ptr);
- auto new_heap_len = on_heap_cx.build.Add(heap_len, len_needed);
- auto heap_len_unscaled =
+ let heap_len = on_heap_cx.build.Load(heap_len_ptr);
+ let new_heap_len = on_heap_cx.build.Add(heap_len, len_needed);
+ let heap_len_unscaled =
on_heap_cx.build.UDiv(heap_len, llsize_of(llunitty));
- auto heap_no_resize_needed =
+ let heap_no_resize_needed =
on_heap_cx.build.ICmp(lib::llvm::LLVMIntULE, new_heap_len, alen);
- auto heap_no_resize_cx = new_sub_block_ctxt(cx, "heap_no_resize");
- auto heap_resize_cx = new_sub_block_ctxt(cx, "heap_resize");
+ let heap_no_resize_cx = new_sub_block_ctxt(cx, "heap_no_resize");
+ let heap_resize_cx = new_sub_block_ctxt(cx, "heap_resize");
on_heap_cx.build.CondBr(heap_no_resize_needed, heap_no_resize_cx.llbb,
heap_resize_cx.llbb);
// Case (1): We're on the heap and don't need to resize.
- auto heap_data_no_resize =
+ let heap_data_no_resize =
{
- auto v = ~[C_int(0), C_uint(abi::ivec_heap_elt_elems),
- heap_len_unscaled];
- heap_no_resize_cx.build.InBoundsGEP(heap_ptr,v)
+ let v =
+ ~[C_int(0), C_uint(abi::ivec_heap_elt_elems),
+ heap_len_unscaled];
+ heap_no_resize_cx.build.InBoundsGEP(heap_ptr, v)
};
heap_no_resize_cx.build.Store(new_heap_len, heap_len_ptr);
heap_no_resize_cx.build.Br(next_cx.llbb);
@@ -2986,37 +2921,37 @@
// so we delegate to cold glue.
{
- auto p =
+ let p =
heap_resize_cx.build.PointerCast(v, T_ptr(T_opaque_ivec()));
- auto upcall = bcx_ccx(cx).upcalls.ivec_resize_shared;
+ let upcall = bcx_ccx(cx).upcalls.ivec_resize_shared;
heap_resize_cx.build.Call(upcall,
~[cx.fcx.lltaskptr, p, new_heap_len]);
}
- auto heap_ptr_resize =
- load_inbounds(heap_resize_cx, stub_ptr, stub_p);
+ let heap_ptr_resize = load_inbounds(heap_resize_cx, stub_ptr, stub_p);
- auto heap_data_resize =
+ let heap_data_resize =
{
- auto v = ~[C_int(0), C_uint(abi::ivec_heap_elt_elems),
- heap_len_unscaled];
+ let v =
+ ~[C_int(0), C_uint(abi::ivec_heap_elt_elems),
+ heap_len_unscaled];
heap_resize_cx.build.InBoundsGEP(heap_ptr_resize, v)
};
heap_resize_cx.build.Br(next_cx.llbb);
// We're on the stack. Check whether we need to spill to the heap.
- auto new_stack_len = on_stack_cx.build.Add(stack_len, len_needed);
- auto stack_no_spill_needed =
+ let new_stack_len = on_stack_cx.build.Add(stack_len, len_needed);
+ let stack_no_spill_needed =
on_stack_cx.build.ICmp(lib::llvm::LLVMIntULE, new_stack_len,
alen);
- auto stack_len_unscaled =
+ let stack_len_unscaled =
on_stack_cx.build.UDiv(stack_len, llsize_of(llunitty));
- auto stack_no_spill_cx = new_sub_block_ctxt(cx, "stack_no_spill");
- auto stack_spill_cx = new_sub_block_ctxt(cx, "stack_spill");
+ let stack_no_spill_cx = new_sub_block_ctxt(cx, "stack_no_spill");
+ let stack_spill_cx = new_sub_block_ctxt(cx, "stack_spill");
on_stack_cx.build.CondBr(stack_no_spill_needed,
stack_no_spill_cx.llbb, stack_spill_cx.llbb);
// Case (3): We're on the stack and don't need to spill.
- auto stack_data_no_spill =
+ let stack_data_no_spill =
stack_no_spill_cx.build.InBoundsGEP(v,
~[C_int(0),
C_uint(abi::ivec_elt_elems),
@@ -3027,28 +2962,29 @@
// path is rare, so we delegate to cold glue.
{
- auto p =
+ let p =
stack_spill_cx.build.PointerCast(v, T_ptr(T_opaque_ivec()));
- auto upcall = bcx_ccx(cx).upcalls.ivec_spill_shared;
+ let upcall = bcx_ccx(cx).upcalls.ivec_spill_shared;
stack_spill_cx.build.Call(upcall,
~[cx.fcx.lltaskptr, p, new_stack_len]);
}
- auto spill_stub =
+ let spill_stub =
stack_spill_cx.build.PointerCast(v, T_ptr(T_ivec_heap(llunitty)));
- auto heap_ptr_spill =
+ let heap_ptr_spill =
load_inbounds(stack_spill_cx, spill_stub, stub_p);
- auto heap_data_spill =
+ let heap_data_spill =
{
- auto v = ~[C_int(0), C_uint(abi::ivec_heap_elt_elems),
- stack_len_unscaled];
+ let v =
+ ~[C_int(0), C_uint(abi::ivec_heap_elt_elems),
+ stack_len_unscaled];
stack_spill_cx.build.InBoundsGEP(heap_ptr_spill, v)
};
stack_spill_cx.build.Br(next_cx.llbb);
// Phi together the different data pointers to get the result.
- auto data_ptr =
+ let data_ptr =
next_cx.build.Phi(T_ptr(llunitty),
~[heap_data_no_resize, heap_data_resize,
stack_data_no_spill, heap_data_spill],
@@ -3056,37 +2992,32 @@
stack_no_spill_cx.llbb, stack_spill_cx.llbb]);
ret rslt(next_cx, data_ptr);
}
- fn trans_append(&@block_ctxt cx, &ty::t t, ValueRef orig_lhs,
- ValueRef orig_rhs) -> result {
+ fn trans_append(cx: &@block_ctxt, t: &ty::t, orig_lhs: ValueRef,
+ orig_rhs: ValueRef) -> result {
// Cast to opaque interior vector types if necessary.
- auto lhs;
- auto rhs;
- if (ty::type_has_dynamic_size(bcx_tcx(cx), t)) {
+ let lhs;
+ let rhs;
+ if ty::type_has_dynamic_size(bcx_tcx(cx), t) {
lhs = cx.build.PointerCast(orig_lhs, T_ptr(T_opaque_ivec()));
rhs = cx.build.PointerCast(orig_rhs, T_ptr(T_opaque_ivec()));
- } else {
- lhs = orig_lhs;
- rhs = orig_rhs;
+ } else { lhs = orig_lhs; rhs = orig_rhs; }
+
+ let unit_ty = ty::sequence_element_type(bcx_tcx(cx), t);
+ let llunitty = type_of_or_i8(cx, unit_ty);
+ alt ty::struct(bcx_tcx(cx), t) {
+ ty::ty_istr. { }
+ ty::ty_ivec(_) { }
+ _ { bcx_tcx(cx).sess.bug("non-istr/ivec in trans_append"); }
}
- auto unit_ty = ty::sequence_element_type(bcx_tcx(cx), t);
- auto llunitty = type_of_or_i8(cx, unit_ty);
- alt (ty::struct(bcx_tcx(cx), t)) {
- case (ty::ty_istr) { }
- case (ty::ty_ivec(_)) { }
- case (_) {
- bcx_tcx(cx).sess.bug("non-istr/ivec in trans_append");
- }
- }
-
- auto rs = size_of(cx, unit_ty);
- auto bcx = rs.bcx;
- auto unit_sz = rs.val;
+ let rs = size_of(cx, unit_ty);
+ let bcx = rs.bcx;
+ let unit_sz = rs.val;
// Gather the various type descriptors we'll need.
// FIXME (issue #511): This is needed to prevent a leak.
- auto no_tydesc_info = none;
+ let no_tydesc_info = none;
rs = get_tydesc(bcx, t, false, no_tydesc_info);
bcx = rs.bcx;
@@ -3095,45 +3026,45 @@
lazily_emit_tydesc_glue(bcx, abi::tydesc_field_copy_glue, none);
lazily_emit_tydesc_glue(bcx, abi::tydesc_field_drop_glue, none);
lazily_emit_tydesc_glue(bcx, abi::tydesc_field_free_glue, none);
- auto rhs_len_and_data = get_len_and_data(bcx, rhs, unit_ty);
- auto rhs_len = rhs_len_and_data.len;
- auto rhs_data = rhs_len_and_data.data;
+ let rhs_len_and_data = get_len_and_data(bcx, rhs, unit_ty);
+ let rhs_len = rhs_len_and_data.len;
+ let rhs_data = rhs_len_and_data.data;
bcx = rhs_len_and_data.bcx;
rs = reserve_space(bcx, llunitty, lhs, rhs_len);
- auto lhs_data = rs.val;
+ let lhs_data = rs.val;
bcx = rs.bcx;
// Work out the end pointer.
- auto lhs_unscaled_idx = bcx.build.UDiv(rhs_len, llsize_of(llunitty));
- auto lhs_end = bcx.build.InBoundsGEP(lhs_data, ~[lhs_unscaled_idx]);
+ let lhs_unscaled_idx = bcx.build.UDiv(rhs_len, llsize_of(llunitty));
+ let lhs_end = bcx.build.InBoundsGEP(lhs_data, ~[lhs_unscaled_idx]);
// Now emit the copy loop.
- auto dest_ptr = alloca(bcx, T_ptr(llunitty));
+ let dest_ptr = alloca(bcx, T_ptr(llunitty));
bcx.build.Store(lhs_data, dest_ptr);
- auto src_ptr = alloca(bcx, T_ptr(llunitty));
+ let src_ptr = alloca(bcx, T_ptr(llunitty));
bcx.build.Store(rhs_data, src_ptr);
- auto copy_loop_header_cx =
- new_sub_block_ctxt(bcx, "copy_loop_header");
+ let copy_loop_header_cx = new_sub_block_ctxt(bcx, "copy_loop_header");
bcx.build.Br(copy_loop_header_cx.llbb);
- auto copy_dest_ptr = copy_loop_header_cx.build.Load(dest_ptr);
- auto not_yet_at_end =
+ let copy_dest_ptr = copy_loop_header_cx.build.Load(dest_ptr);
+ let not_yet_at_end =
copy_loop_header_cx.build.ICmp(lib::llvm::LLVMIntNE,
copy_dest_ptr, lhs_end);
- auto copy_loop_body_cx = new_sub_block_ctxt(bcx, "copy_loop_body");
- auto next_cx = new_sub_block_ctxt(bcx, "next");
+ let copy_loop_body_cx = new_sub_block_ctxt(bcx, "copy_loop_body");
+ let next_cx = new_sub_block_ctxt(bcx, "next");
copy_loop_header_cx.build.CondBr(not_yet_at_end,
copy_loop_body_cx.llbb,
next_cx.llbb);
- auto copy_src_ptr = copy_loop_body_cx.build.Load(src_ptr);
- auto copy_src = load_if_immediate(copy_loop_body_cx, copy_src_ptr,
- unit_ty);
+ let copy_src_ptr = copy_loop_body_cx.build.Load(src_ptr);
+ let copy_src =
+ load_if_immediate(copy_loop_body_cx, copy_src_ptr, unit_ty);
- rs = copy_val(copy_loop_body_cx, INIT, copy_dest_ptr, copy_src,
- unit_ty);
- auto post_copy_cx = rs.bcx;
+ rs =
+ copy_val(copy_loop_body_cx, INIT, copy_dest_ptr, copy_src,
+ unit_ty);
+ let post_copy_cx = rs.bcx;
// Increment both pointers.
- if (ty::type_has_dynamic_size(bcx_tcx(cx), t)) {
+ if ty::type_has_dynamic_size(bcx_tcx(cx), t) {
// We have to increment by the dynamically-computed size.
incr_ptr(post_copy_cx, copy_dest_ptr, unit_sz, dest_ptr);
incr_ptr(post_copy_cx, copy_src_ptr, unit_sz, src_ptr);
@@ -3146,97 +3077,93 @@
ret rslt(next_cx, C_nil());
}
- type alloc_result = rec(@block_ctxt bcx,
- ValueRef llptr,
- ValueRef llunitsz,
- ValueRef llalen);
+ type alloc_result =
+ {bcx: @block_ctxt,
+ llptr: ValueRef,
+ llunitsz: ValueRef,
+ llalen: ValueRef};
- fn alloc(&@block_ctxt cx, ty::t unit_ty) -> alloc_result {
- auto dynamic = ty::type_has_dynamic_size(bcx_tcx(cx), unit_ty);
+ fn alloc(cx: &@block_ctxt, unit_ty: ty::t) -> alloc_result {
+ let dynamic = ty::type_has_dynamic_size(bcx_tcx(cx), unit_ty);
- auto bcx;
- if (dynamic) {
+ let bcx;
+ if dynamic {
bcx = llderivedtydescs_block_ctxt(cx.fcx);
- } else {
- bcx = cx;
- }
+ } else { bcx = cx; }
- auto llunitsz;
- auto rslt = size_of(bcx, unit_ty);
+ let llunitsz;
+ let rslt = size_of(bcx, unit_ty);
bcx = rslt.bcx;
llunitsz = rslt.val;
- if (dynamic) { cx.fcx.llderivedtydescs = bcx.llbb; }
+ if dynamic { cx.fcx.llderivedtydescs = bcx.llbb; }
- auto llalen = bcx.build.Mul(llunitsz,
- C_uint(abi::ivec_default_length));
+ let llalen =
+ bcx.build.Mul(llunitsz, C_uint(abi::ivec_default_length));
- auto llptr;
- auto llunitty = type_of_or_i8(bcx, unit_ty);
- auto bcx_result;
- if (dynamic) {
- auto llarraysz = bcx.build.Add(llsize_of(T_opaque_ivec()),
- llalen);
- auto llvecptr = array_alloca(bcx, T_i8(), llarraysz);
+ let llptr;
+ let llunitty = type_of_or_i8(bcx, unit_ty);
+ let bcx_result;
+ if dynamic {
+ let llarraysz = bcx.build.Add(llsize_of(T_opaque_ivec()), llalen);
+ let llvecptr = array_alloca(bcx, T_i8(), llarraysz);
bcx_result = cx;
- llptr = bcx_result.build.PointerCast(llvecptr,
- T_ptr(T_opaque_ivec()));
- } else {
- llptr = alloca(bcx, T_ivec(llunitty));
- bcx_result = bcx;
- }
+ llptr =
+ bcx_result.build.PointerCast(llvecptr,
+ T_ptr(T_opaque_ivec()));
+ } else { llptr = alloca(bcx, T_ivec(llunitty)); bcx_result = bcx; }
- ret rec(bcx=bcx_result,
- llptr=llptr,
- llunitsz=llunitsz,
- llalen=llalen);
+ ret {bcx: bcx_result,
+ llptr: llptr,
+ llunitsz: llunitsz,
+ llalen: llalen};
}
- fn trans_add(&@block_ctxt cx, ty::t vec_ty, ValueRef lhs, ValueRef rhs)
- -> result {
- auto bcx = cx;
- auto unit_ty = ty::sequence_element_type(bcx_tcx(bcx), vec_ty);
+ fn trans_add(cx: &@block_ctxt, vec_ty: ty::t, lhs: ValueRef,
+ rhs: ValueRef) -> result {
+ let bcx = cx;
+ let unit_ty = ty::sequence_element_type(bcx_tcx(bcx), vec_ty);
- auto ares = alloc(bcx, unit_ty);
+ let ares = alloc(bcx, unit_ty);
bcx = ares.bcx;
- auto llvecptr = ares.llptr;
- auto unit_sz = ares.llunitsz;
- auto llalen = ares.llalen;
+ let llvecptr = ares.llptr;
+ let unit_sz = ares.llunitsz;
+ let llalen = ares.llalen;
add_clean_temp(bcx, llvecptr, vec_ty);
- auto llunitty = type_of_or_i8(bcx, unit_ty);
- auto llheappartty = T_ivec_heap_part(llunitty);
- auto lhs_len_and_data = get_len_and_data(bcx, lhs, unit_ty);
- auto lhs_len = lhs_len_and_data.len;
- auto lhs_data = lhs_len_and_data.data;
+ let llunitty = type_of_or_i8(bcx, unit_ty);
+ let llheappartty = T_ivec_heap_part(llunitty);
+ let lhs_len_and_data = get_len_and_data(bcx, lhs, unit_ty);
+ let lhs_len = lhs_len_and_data.len;
+ let lhs_data = lhs_len_and_data.data;
bcx = lhs_len_and_data.bcx;
- auto rhs_len_and_data = get_len_and_data(bcx, rhs, unit_ty);
- auto rhs_len = rhs_len_and_data.len;
- auto rhs_data = rhs_len_and_data.data;
+ let rhs_len_and_data = get_len_and_data(bcx, rhs, unit_ty);
+ let rhs_len = rhs_len_and_data.len;
+ let rhs_data = rhs_len_and_data.data;
bcx = rhs_len_and_data.bcx;
- auto lllen = bcx.build.Add(lhs_len, rhs_len);
+ let lllen = bcx.build.Add(lhs_len, rhs_len);
// We have three cases to handle here:
// (1) Length is zero ([] + []).
// (2) Copy onto stack.
// (3) Allocate on heap and copy there.
- auto len_is_zero =
+ let len_is_zero =
bcx.build.ICmp(lib::llvm::LLVMIntEQ, lllen, C_int(0));
- auto zero_len_cx = new_sub_block_ctxt(bcx, "zero_len");
- auto nonzero_len_cx = new_sub_block_ctxt(bcx, "nonzero_len");
+ let zero_len_cx = new_sub_block_ctxt(bcx, "zero_len");
+ let nonzero_len_cx = new_sub_block_ctxt(bcx, "nonzero_len");
bcx.build.CondBr(len_is_zero, zero_len_cx.llbb, nonzero_len_cx.llbb);
// Case (1): Length is zero.
- auto stub_z = ~[C_int(0), C_uint(abi::ivec_heap_stub_elt_zero)];
- auto stub_a = ~[C_int(0), C_uint(abi::ivec_heap_stub_elt_alen)];
- auto stub_p = ~[C_int(0), C_uint(abi::ivec_heap_stub_elt_ptr)];
+ let stub_z = ~[C_int(0), C_uint(abi::ivec_heap_stub_elt_zero)];
+ let stub_a = ~[C_int(0), C_uint(abi::ivec_heap_stub_elt_alen)];
+ let stub_p = ~[C_int(0), C_uint(abi::ivec_heap_stub_elt_ptr)];
- auto vec_l = ~[C_int(0), C_uint(abi::ivec_elt_len)];
- auto vec_a = ~[C_int(0), C_uint(abi::ivec_elt_alen)];
+ let vec_l = ~[C_int(0), C_uint(abi::ivec_elt_len)];
+ let vec_a = ~[C_int(0), C_uint(abi::ivec_elt_alen)];
- auto stub_ptr_zero =
+ let stub_ptr_zero =
zero_len_cx.build.PointerCast(llvecptr,
T_ptr(T_ivec_heap(llunitty)));
zero_len_cx.build.Store(C_int(0),
@@ -3248,14 +3175,14 @@
zero_len_cx.build.Store(C_null(T_ptr(llheappartty)),
zero_len_cx.build.InBoundsGEP(stub_ptr_zero,
stub_p));
- auto next_cx = new_sub_block_ctxt(bcx, "next");
+ let next_cx = new_sub_block_ctxt(bcx, "next");
zero_len_cx.build.Br(next_cx.llbb);
// Determine whether we need to spill to the heap.
- auto on_stack =
+ let on_stack =
nonzero_len_cx.build.ICmp(lib::llvm::LLVMIntULE, lllen, llalen);
- auto stack_cx = new_sub_block_ctxt(bcx, "stack");
- auto heap_cx = new_sub_block_ctxt(bcx, "heap");
+ let stack_cx = new_sub_block_ctxt(bcx, "stack");
+ let heap_cx = new_sub_block_ctxt(bcx, "heap");
nonzero_len_cx.build.CondBr(on_stack, stack_cx.llbb, heap_cx.llbb);
// Case (2): Copy onto stack.
@@ -3263,37 +3190,33 @@
stack_cx.build.InBoundsGEP(llvecptr, vec_l));
stack_cx.build.Store(llalen,
stack_cx.build.InBoundsGEP(llvecptr, vec_a));
- auto dest_ptr_stack =
+ let dest_ptr_stack =
stack_cx.build.InBoundsGEP(llvecptr,
~[C_int(0),
C_uint(abi::ivec_elt_elems),
C_int(0)]);
- auto copy_cx = new_sub_block_ctxt(bcx, "copy");
+ let copy_cx = new_sub_block_ctxt(bcx, "copy");
stack_cx.build.Br(copy_cx.llbb);
// Case (3): Allocate on heap and copy there.
- auto stub_ptr_heap =
+ let stub_ptr_heap =
heap_cx.build.PointerCast(llvecptr, T_ptr(T_ivec_heap(llunitty)));
heap_cx.build.Store(C_int(0),
- heap_cx.build.InBoundsGEP(stub_ptr_heap,
- stub_z));
+ heap_cx.build.InBoundsGEP(stub_ptr_heap, stub_z));
heap_cx.build.Store(lllen,
- heap_cx.build.InBoundsGEP(stub_ptr_heap,
- stub_a));
- auto heap_sz = heap_cx.build.Add(llsize_of(llheappartty), lllen);
- auto rs = trans_shared_malloc(heap_cx, T_ptr(llheappartty), heap_sz);
- auto heap_part = rs.val;
+ heap_cx.build.InBoundsGEP(stub_ptr_heap, stub_a));
+ let heap_sz = heap_cx.build.Add(llsize_of(llheappartty), lllen);
+ let rs = trans_shared_malloc(heap_cx, T_ptr(llheappartty), heap_sz);
+ let heap_part = rs.val;
heap_cx = rs.bcx;
heap_cx.build.Store(heap_part,
- heap_cx.build.InBoundsGEP(stub_ptr_heap,
- stub_p));
+ heap_cx.build.InBoundsGEP(stub_ptr_heap, stub_p));
{
- auto v = ~[C_int(0), C_uint(abi::ivec_heap_elt_len)];
+ let v = ~[C_int(0), C_uint(abi::ivec_heap_elt_len)];
heap_cx.build.Store(lllen,
- heap_cx.build.InBoundsGEP(heap_part,
- v));
+ heap_cx.build.InBoundsGEP(heap_part, v));
}
- auto dest_ptr_heap =
+ let dest_ptr_heap =
heap_cx.build.InBoundsGEP(heap_part,
~[C_int(0),
C_uint(abi::ivec_heap_elt_elems),
@@ -3301,50 +3224,52 @@
heap_cx.build.Br(copy_cx.llbb);
// Emit the copy loop.
- auto first_dest_ptr =
+ let first_dest_ptr =
copy_cx.build.Phi(T_ptr(llunitty),
~[dest_ptr_stack, dest_ptr_heap],
~[stack_cx.llbb, heap_cx.llbb]);
- auto lhs_end_ptr; auto rhs_end_ptr;
- if (ty::type_has_dynamic_size(bcx_tcx(cx), unit_ty)) {
+ let lhs_end_ptr;
+ let rhs_end_ptr;
+ if ty::type_has_dynamic_size(bcx_tcx(cx), unit_ty) {
lhs_end_ptr = copy_cx.build.InBoundsGEP(lhs_data, ~[lhs_len]);
rhs_end_ptr = copy_cx.build.InBoundsGEP(rhs_data, ~[rhs_len]);
} else {
- auto lhs_len_unscaled = copy_cx.build.UDiv(lhs_len, unit_sz);
- lhs_end_ptr = copy_cx.build.InBoundsGEP(lhs_data,
- ~[lhs_len_unscaled]);
- auto rhs_len_unscaled = copy_cx.build.UDiv(rhs_len, unit_sz);
- rhs_end_ptr = copy_cx.build.InBoundsGEP(rhs_data,
- ~[rhs_len_unscaled]);
+ let lhs_len_unscaled = copy_cx.build.UDiv(lhs_len, unit_sz);
+ lhs_end_ptr =
+ copy_cx.build.InBoundsGEP(lhs_data, ~[lhs_len_unscaled]);
+ let rhs_len_unscaled = copy_cx.build.UDiv(rhs_len, unit_sz);
+ rhs_end_ptr =
+ copy_cx.build.InBoundsGEP(rhs_data, ~[rhs_len_unscaled]);
}
- auto dest_ptr_ptr = alloca(copy_cx, T_ptr(llunitty));
+ let dest_ptr_ptr = alloca(copy_cx, T_ptr(llunitty));
copy_cx.build.Store(first_dest_ptr, dest_ptr_ptr);
- auto lhs_ptr_ptr = alloca(copy_cx, T_ptr(llunitty));
+ let lhs_ptr_ptr = alloca(copy_cx, T_ptr(llunitty));
copy_cx.build.Store(lhs_data, lhs_ptr_ptr);
- auto rhs_ptr_ptr = alloca(copy_cx, T_ptr(llunitty));
+ let rhs_ptr_ptr = alloca(copy_cx, T_ptr(llunitty));
copy_cx.build.Store(rhs_data, rhs_ptr_ptr);
- auto lhs_copy_cx = new_sub_block_ctxt(bcx, "lhs_copy");
+ let lhs_copy_cx = new_sub_block_ctxt(bcx, "lhs_copy");
copy_cx.build.Br(lhs_copy_cx.llbb);
// Copy in elements from the LHS.
- auto lhs_ptr = lhs_copy_cx.build.Load(lhs_ptr_ptr);
- auto not_at_end_lhs =
+ let lhs_ptr = lhs_copy_cx.build.Load(lhs_ptr_ptr);
+ let not_at_end_lhs =
lhs_copy_cx.build.ICmp(lib::llvm::LLVMIntNE, lhs_ptr,
lhs_end_ptr);
- auto lhs_do_copy_cx = new_sub_block_ctxt(bcx, "lhs_do_copy");
- auto rhs_copy_cx = new_sub_block_ctxt(bcx, "rhs_copy");
+ let lhs_do_copy_cx = new_sub_block_ctxt(bcx, "lhs_do_copy");
+ let rhs_copy_cx = new_sub_block_ctxt(bcx, "rhs_copy");
lhs_copy_cx.build.CondBr(not_at_end_lhs, lhs_do_copy_cx.llbb,
rhs_copy_cx.llbb);
- auto dest_ptr_lhs_copy = lhs_do_copy_cx.build.Load(dest_ptr_ptr);
- auto lhs_val = load_if_immediate(lhs_do_copy_cx, lhs_ptr, unit_ty);
- rs = copy_val(lhs_do_copy_cx, INIT, dest_ptr_lhs_copy, lhs_val,
- unit_ty);
+ let dest_ptr_lhs_copy = lhs_do_copy_cx.build.Load(dest_ptr_ptr);
+ let lhs_val = load_if_immediate(lhs_do_copy_cx, lhs_ptr, unit_ty);
+ rs =
+ copy_val(lhs_do_copy_cx, INIT, dest_ptr_lhs_copy, lhs_val,
+ unit_ty);
lhs_do_copy_cx = rs.bcx;
// Increment both pointers.
- if (ty::type_has_dynamic_size(bcx_tcx(cx), unit_ty)) {
+ if ty::type_has_dynamic_size(bcx_tcx(cx), unit_ty) {
// We have to increment by the dynamically-computed size.
incr_ptr(lhs_do_copy_cx, dest_ptr_lhs_copy, unit_sz,
dest_ptr_ptr);
@@ -3358,22 +3283,22 @@
lhs_do_copy_cx.build.Br(lhs_copy_cx.llbb);
// Copy in elements from the RHS.
- auto rhs_ptr = rhs_copy_cx.build.Load(rhs_ptr_ptr);
- auto not_at_end_rhs =
+ let rhs_ptr = rhs_copy_cx.build.Load(rhs_ptr_ptr);
+ let not_at_end_rhs =
rhs_copy_cx.build.ICmp(lib::llvm::LLVMIntNE, rhs_ptr,
rhs_end_ptr);
- auto rhs_do_copy_cx = new_sub_block_ctxt(bcx, "rhs_do_copy");
+ let rhs_do_copy_cx = new_sub_block_ctxt(bcx, "rhs_do_copy");
rhs_copy_cx.build.CondBr(not_at_end_rhs, rhs_do_copy_cx.llbb,
next_cx.llbb);
- auto dest_ptr_rhs_copy = rhs_do_copy_cx.build.Load(dest_ptr_ptr);
- auto rhs_val = load_if_immediate(rhs_do_copy_cx, rhs_ptr, unit_ty);
+ let dest_ptr_rhs_copy = rhs_do_copy_cx.build.Load(dest_ptr_ptr);
+ let rhs_val = load_if_immediate(rhs_do_copy_cx, rhs_ptr, unit_ty);
rs =
copy_val(rhs_do_copy_cx, INIT, dest_ptr_rhs_copy, rhs_val,
unit_ty);
rhs_do_copy_cx = rs.bcx;
// Increment both pointers.
- if (ty::type_has_dynamic_size(bcx_tcx(cx), unit_ty)) {
+ if ty::type_has_dynamic_size(bcx_tcx(cx), unit_ty) {
// We have to increment by the dynamically-computed size.
incr_ptr(rhs_do_copy_cx, dest_ptr_rhs_copy, unit_sz,
dest_ptr_ptr);
@@ -3392,53 +3317,59 @@
// NB: This does *not* adjust reference counts. The caller must have done
// this via copy_ty() beforehand.
- fn duplicate_heap_part(&@block_ctxt cx, ValueRef orig_vptr,
- ty::t unit_ty) -> result {
+ fn duplicate_heap_part(cx: &@block_ctxt, orig_vptr: ValueRef,
+ unit_ty: ty::t) -> result {
// Cast to an opaque interior vector if we can't trust the pointer
// type.
- auto vptr;
- if (ty::type_has_dynamic_size(bcx_tcx(cx), unit_ty)) {
+ let vptr;
+ if ty::type_has_dynamic_size(bcx_tcx(cx), unit_ty) {
vptr = cx.build.PointerCast(orig_vptr, T_ptr(T_opaque_ivec()));
- } else {
- vptr = orig_vptr;
- }
+ } else { vptr = orig_vptr; }
- auto llunitty = type_of_or_i8(cx, unit_ty);
- auto llheappartty = T_ivec_heap_part(llunitty);
+ let llunitty = type_of_or_i8(cx, unit_ty);
+ let llheappartty = T_ivec_heap_part(llunitty);
// Check to see if the vector is heapified.
- auto stack_len_ptr = cx.build.InBoundsGEP(vptr, ~[C_int(0),
- C_uint(abi::ivec_elt_len)]);
- auto stack_len = cx.build.Load(stack_len_ptr);
- auto stack_len_is_zero = cx.build.ICmp(lib::llvm::LLVMIntEQ,
- stack_len, C_int(0));
- auto maybe_on_heap_cx = new_sub_block_ctxt(cx, "maybe_on_heap");
- auto next_cx = new_sub_block_ctxt(cx, "next");
+ let stack_len_ptr =
+ cx.build.InBoundsGEP(vptr,
+ ~[C_int(0), C_uint(abi::ivec_elt_len)]);
+ let stack_len = cx.build.Load(stack_len_ptr);
+ let stack_len_is_zero =
+ cx.build.ICmp(lib::llvm::LLVMIntEQ, stack_len, C_int(0));
+ let maybe_on_heap_cx = new_sub_block_ctxt(cx, "maybe_on_heap");
+ let next_cx = new_sub_block_ctxt(cx, "next");
cx.build.CondBr(stack_len_is_zero, maybe_on_heap_cx.llbb,
next_cx.llbb);
- auto stub_ptr = maybe_on_heap_cx.build.PointerCast(vptr,
- T_ptr(T_ivec_heap(llunitty)));
- auto heap_ptr_ptr = maybe_on_heap_cx.build.InBoundsGEP(stub_ptr,
- ~[C_int(0), C_uint(abi::ivec_heap_stub_elt_ptr)]);
- auto heap_ptr = maybe_on_heap_cx.build.Load(heap_ptr_ptr);
- auto heap_ptr_is_nonnull = maybe_on_heap_cx.build.ICmp(
- lib::llvm::LLVMIntNE, heap_ptr, C_null(T_ptr(llheappartty)));
- auto on_heap_cx = new_sub_block_ctxt(cx, "on_heap");
+ let stub_ptr =
+ maybe_on_heap_cx.build.PointerCast(vptr,
+ T_ptr(T_ivec_heap(llunitty)));
+ let heap_ptr_ptr =
+ maybe_on_heap_cx.build.InBoundsGEP(stub_ptr,
+ ~[C_int(0),
+ C_uint(abi::ivec_heap_stub_elt_ptr)]);
+ let heap_ptr = maybe_on_heap_cx.build.Load(heap_ptr_ptr);
+ let heap_ptr_is_nonnull =
+ maybe_on_heap_cx.build.ICmp(lib::llvm::LLVMIntNE, heap_ptr,
+ C_null(T_ptr(llheappartty)));
+ let on_heap_cx = new_sub_block_ctxt(cx, "on_heap");
maybe_on_heap_cx.build.CondBr(heap_ptr_is_nonnull, on_heap_cx.llbb,
next_cx.llbb);
// Ok, the vector is on the heap. Copy the heap part.
- auto alen_ptr = on_heap_cx.build.InBoundsGEP(stub_ptr,
- ~[C_int(0), C_uint(abi::ivec_heap_stub_elt_alen)]);
- auto alen = on_heap_cx.build.Load(alen_ptr);
+ let alen_ptr =
+ on_heap_cx.build.InBoundsGEP(stub_ptr,
+ ~[C_int(0),
+ C_uint(abi::ivec_heap_stub_elt_alen)]);
+ let alen = on_heap_cx.build.Load(alen_ptr);
- auto heap_part_sz = on_heap_cx.build.Add(alen,
- llsize_of(T_opaque_ivec_heap_part()));
- auto rs = trans_shared_malloc(on_heap_cx, T_ptr(llheappartty),
- heap_part_sz);
+ let heap_part_sz =
+ on_heap_cx.build.Add(alen, llsize_of(T_opaque_ivec_heap_part()));
+ let rs =
+ trans_shared_malloc(on_heap_cx, T_ptr(llheappartty),
+ heap_part_sz);
on_heap_cx = rs.bcx;
- auto new_heap_ptr = rs.val;
+ let new_heap_ptr = rs.val;
rs = call_memmove(on_heap_cx, new_heap_ptr, heap_ptr, heap_part_sz);
on_heap_cx = rs.bcx;
@@ -3450,276 +3381,275 @@
}
}
-fn trans_vec_add(&@block_ctxt cx, &ty::t t, ValueRef lhs, ValueRef rhs) ->
+fn trans_vec_add(cx: &@block_ctxt, t: &ty::t, lhs: ValueRef, rhs: ValueRef) ->
result {
- auto r = alloc_ty(cx, t);
- auto tmp = r.val;
+ let r = alloc_ty(cx, t);
+ let tmp = r.val;
r = copy_val(r.bcx, INIT, tmp, lhs, t);
- auto bcx = trans_vec_append(r.bcx, t, tmp, rhs).bcx;
+ let bcx = trans_vec_append(r.bcx, t, tmp, rhs).bcx;
tmp = load_if_immediate(bcx, tmp, t);
add_clean_temp(cx, tmp, t);
ret rslt(bcx, tmp);
}
-fn trans_eager_binop(&@block_ctxt cx, ast::binop op, &ty::t intype,
- ValueRef lhs, ValueRef rhs) -> result {
- auto is_float = false;
- alt (ty::struct(bcx_tcx(cx), intype)) {
- case (ty::ty_float) { is_float = true; }
- case (_) { is_float = false; }
+fn trans_eager_binop(cx: &@block_ctxt, op: ast::binop, intype: &ty::t,
+ lhs: ValueRef, rhs: ValueRef) -> result {
+ let is_float = false;
+ alt ty::struct(bcx_tcx(cx), intype) {
+ ty::ty_float. { is_float = true; }
+ _ { is_float = false; }
}
- alt (op) {
- case (ast::add) {
- if (ty::type_is_sequence(bcx_tcx(cx), intype)) {
- if (ty::sequence_is_interior(bcx_tcx(cx), intype)) {
- ret ivec::trans_add(cx, intype, lhs, rhs);
- }
- ret trans_vec_add(cx, intype, lhs, rhs);
+ alt op {
+ ast::add. {
+ if ty::type_is_sequence(bcx_tcx(cx), intype) {
+ if ty::sequence_is_interior(bcx_tcx(cx), intype) {
+ ret ivec::trans_add(cx, intype, lhs, rhs);
}
- if (is_float) {
- ret rslt(cx, cx.build.FAdd(lhs, rhs));
- } else { ret rslt(cx, cx.build.Add(lhs, rhs)); }
+ ret trans_vec_add(cx, intype, lhs, rhs);
}
- case (ast::sub) {
- if (is_float) {
- ret rslt(cx, cx.build.FSub(lhs, rhs));
- } else { ret rslt(cx, cx.build.Sub(lhs, rhs)); }
- }
- case (ast::mul) {
- if (is_float) {
- ret rslt(cx, cx.build.FMul(lhs, rhs));
- } else { ret rslt(cx, cx.build.Mul(lhs, rhs)); }
- }
- case (ast::div) {
- if (is_float) { ret rslt(cx, cx.build.FDiv(lhs, rhs)); }
- if (ty::type_is_signed(bcx_tcx(cx), intype)) {
- ret rslt(cx, cx.build.SDiv(lhs, rhs));
- } else { ret rslt(cx, cx.build.UDiv(lhs, rhs)); }
- }
- case (ast::rem) {
- if (is_float) { ret rslt(cx, cx.build.FRem(lhs, rhs)); }
- if (ty::type_is_signed(bcx_tcx(cx), intype)) {
- ret rslt(cx, cx.build.SRem(lhs, rhs));
- } else { ret rslt(cx, cx.build.URem(lhs, rhs)); }
- }
- case (ast::bitor) { ret rslt(cx, cx.build.Or(lhs, rhs)); }
- case (ast::bitand) { ret rslt(cx, cx.build.And(lhs, rhs)); }
- case (ast::bitxor) { ret rslt(cx, cx.build.Xor(lhs, rhs)); }
- case (ast::lsl) { ret rslt(cx, cx.build.Shl(lhs, rhs)); }
- case (ast::lsr) { ret rslt(cx, cx.build.LShr(lhs, rhs)); }
- case (ast::asr) { ret rslt(cx, cx.build.AShr(lhs, rhs)); }
- case (_) { ret trans_compare(cx, op, intype, lhs, rhs); }
+ if is_float {
+ ret rslt(cx, cx.build.FAdd(lhs, rhs));
+ } else { ret rslt(cx, cx.build.Add(lhs, rhs)); }
+ }
+ ast::sub. {
+ if is_float {
+ ret rslt(cx, cx.build.FSub(lhs, rhs));
+ } else { ret rslt(cx, cx.build.Sub(lhs, rhs)); }
+ }
+ ast::mul. {
+ if is_float {
+ ret rslt(cx, cx.build.FMul(lhs, rhs));
+ } else { ret rslt(cx, cx.build.Mul(lhs, rhs)); }
+ }
+ ast::div. {
+ if is_float { ret rslt(cx, cx.build.FDiv(lhs, rhs)); }
+ if ty::type_is_signed(bcx_tcx(cx), intype) {
+ ret rslt(cx, cx.build.SDiv(lhs, rhs));
+ } else { ret rslt(cx, cx.build.UDiv(lhs, rhs)); }
+ }
+ ast::rem. {
+ if is_float { ret rslt(cx, cx.build.FRem(lhs, rhs)); }
+ if ty::type_is_signed(bcx_tcx(cx), intype) {
+ ret rslt(cx, cx.build.SRem(lhs, rhs));
+ } else { ret rslt(cx, cx.build.URem(lhs, rhs)); }
+ }
+ ast::bitor. { ret rslt(cx, cx.build.Or(lhs, rhs)); }
+ ast::bitand. { ret rslt(cx, cx.build.And(lhs, rhs)); }
+ ast::bitxor. { ret rslt(cx, cx.build.Xor(lhs, rhs)); }
+ ast::lsl. { ret rslt(cx, cx.build.Shl(lhs, rhs)); }
+ ast::lsr. { ret rslt(cx, cx.build.LShr(lhs, rhs)); }
+ ast::asr. { ret rslt(cx, cx.build.AShr(lhs, rhs)); }
+ _ { ret trans_compare(cx, op, intype, lhs, rhs); }
}
}
-fn autoderef(&@block_ctxt cx, ValueRef v, &ty::t t) -> result_t {
- let ValueRef v1 = v;
- let ty::t t1 = t;
- auto ccx = bcx_ccx(cx);
- while (true) {
- alt (ty::struct(ccx.tcx, t1)) {
- case (ty::ty_box(?mt)) {
- auto body =
- cx.build.GEP(v1,
- ~[C_int(0), C_int(abi::box_rc_field_body)]);
- t1 = mt.ty;
- // Since we're changing levels of box indirection, we may have
- // to cast this pointer, since statically-sized tag types have
- // different types depending on whether they're behind a box
- // or not.
- if (!ty::type_has_dynamic_size(ccx.tcx, mt.ty)) {
- auto llty = type_of(ccx, cx.sp, mt.ty);
- v1 = cx.build.PointerCast(body, T_ptr(llty));
- } else { v1 = body; }
+fn autoderef(cx: &@block_ctxt, v: ValueRef, t: &ty::t) -> result_t {
+ let v1: ValueRef = v;
+ let t1: ty::t = t;
+ let ccx = bcx_ccx(cx);
+ while true {
+ alt ty::struct(ccx.tcx, t1) {
+ ty::ty_box(mt) {
+ let body =
+ cx.build.GEP(v1, ~[C_int(0), C_int(abi::box_rc_field_body)]);
+ t1 = mt.ty;
+
+ // Since we're changing levels of box indirection, we may have
+ // to cast this pointer, since statically-sized tag types have
+ // different types depending on whether they're behind a box
+ // or not.
+ if !ty::type_has_dynamic_size(ccx.tcx, mt.ty) {
+ let llty = type_of(ccx, cx.sp, mt.ty);
+ v1 = cx.build.PointerCast(body, T_ptr(llty));
+ } else { v1 = body; }
+ }
+ ty::ty_res(did, inner, tps) {
+ t1 = ty::substitute_type_params(ccx.tcx, tps, inner);
+ v1 = cx.build.GEP(v1, ~[C_int(0), C_int(1)]);
+ }
+ ty::ty_tag(did, tps) {
+ let variants = ty::tag_variants(ccx.tcx, did);
+ if std::ivec::len(variants) != 1u ||
+ std::ivec::len(variants.(0).args) != 1u {
+ break;
}
- case (ty::ty_res(?did, ?inner, ?tps)) {
- t1 = ty::substitute_type_params(ccx.tcx, tps, inner);
- v1 = cx.build.GEP(v1, ~[C_int(0), C_int(1)]);
+ t1 =
+ ty::substitute_type_params(ccx.tcx, tps,
+ variants.(0).args.(0));
+ if !ty::type_has_dynamic_size(ccx.tcx, t1) {
+ v1 = cx.build.PointerCast(v1, T_ptr(type_of(ccx, cx.sp, t1)));
}
- case (ty::ty_tag(?did, ?tps)) {
- auto variants = ty::tag_variants(ccx.tcx, did);
- if (std::ivec::len(variants) != 1u ||
- std::ivec::len(variants.(0).args) != 1u) {
- break;
- }
- t1 = ty::substitute_type_params
- (ccx.tcx, tps, variants.(0).args.(0));
- if (!ty::type_has_dynamic_size(ccx.tcx, t1)) {
- v1 = cx.build.PointerCast
- (v1, T_ptr(type_of(ccx, cx.sp, t1)));
- }
- }
- case (_) { break; }
+ }
+ _ { break; }
}
v1 = load_if_immediate(cx, v1, t1);
}
- ret rec(bcx=cx, val=v1, ty=t1);
+ ret {bcx: cx, val: v1, ty: t1};
}
-fn trans_binary(&@block_ctxt cx, ast::binop op, &@ast::expr a, &@ast::expr b)
- -> result {
+fn trans_binary(cx: &@block_ctxt, op: ast::binop, a: &@ast::expr,
+ b: &@ast::expr) -> result {
+
// First couple cases are lazy:
- alt (op) {
- case (ast::and) {
- // Lazy-eval and
- auto lhs_expr = trans_expr(cx, a);
- auto lhs_res =
- autoderef(lhs_expr.bcx, lhs_expr.val,
- ty::expr_ty(bcx_tcx(cx), a));
- auto rhs_cx = new_scope_block_ctxt(cx, "rhs");
- auto rhs_expr = trans_expr(rhs_cx, b);
- auto rhs_res =
- autoderef(rhs_expr.bcx, rhs_expr.val,
- ty::expr_ty(bcx_tcx(cx), b));
- auto lhs_false_cx = new_scope_block_ctxt(cx, "lhs false");
- auto lhs_false_res = rslt(lhs_false_cx, C_bool(false));
- // The following line ensures that any cleanups for rhs
- // are done within the block for rhs. This is necessary
- // because and/or are lazy. So the rhs may never execute,
- // and the cleanups can't be pushed into later code.
+ alt op {
+ ast::and. {
+ // Lazy-eval and
+ let lhs_expr = trans_expr(cx, a);
+ let lhs_res =
+ autoderef(lhs_expr.bcx, lhs_expr.val,
+ ty::expr_ty(bcx_tcx(cx), a));
+ let rhs_cx = new_scope_block_ctxt(cx, "rhs");
+ let rhs_expr = trans_expr(rhs_cx, b);
+ let rhs_res =
+ autoderef(rhs_expr.bcx, rhs_expr.val,
+ ty::expr_ty(bcx_tcx(cx), b));
+ let lhs_false_cx = new_scope_block_ctxt(cx, "lhs false");
+ let lhs_false_res = rslt(lhs_false_cx, C_bool(false));
+ // The following line ensures that any cleanups for rhs
+ // are done within the block for rhs. This is necessary
+ // because and/or are lazy. So the rhs may never execute,
+ // and the cleanups can't be pushed into later code.
- auto rhs_bcx = trans_block_cleanups(rhs_res.bcx, rhs_cx);
- lhs_res.bcx.build.CondBr(lhs_res.val, rhs_cx.llbb,
- lhs_false_cx.llbb);
- ret join_results(cx, T_bool(),
- ~[lhs_false_res, rec(bcx=rhs_bcx,
- val=rhs_res.val)]);
- }
- case (ast::or) {
- // Lazy-eval or
- auto lhs_expr = trans_expr(cx, a);
- auto lhs_res = autoderef(lhs_expr.bcx, lhs_expr.val,
- ty::expr_ty(bcx_tcx(cx), a));
- auto rhs_cx = new_scope_block_ctxt(cx, "rhs");
- auto rhs_expr = trans_expr(rhs_cx, b);
- auto rhs_res = autoderef(rhs_expr.bcx, rhs_expr.val,
- ty::expr_ty(bcx_tcx(cx), b));
- auto lhs_true_cx = new_scope_block_ctxt(cx, "lhs true");
- auto lhs_true_res = rslt(lhs_true_cx, C_bool(true));
- // see the and case for an explanation
+ let rhs_bcx = trans_block_cleanups(rhs_res.bcx, rhs_cx);
+ lhs_res.bcx.build.CondBr(lhs_res.val, rhs_cx.llbb, lhs_false_cx.llbb);
+ ret join_results(cx, T_bool(),
+ ~[lhs_false_res, {bcx: rhs_bcx, val: rhs_res.val}]);
+ }
+ ast::or. {
+ // Lazy-eval or
+ let lhs_expr = trans_expr(cx, a);
+ let lhs_res =
+ autoderef(lhs_expr.bcx, lhs_expr.val,
+ ty::expr_ty(bcx_tcx(cx), a));
+ let rhs_cx = new_scope_block_ctxt(cx, "rhs");
+ let rhs_expr = trans_expr(rhs_cx, b);
+ let rhs_res =
+ autoderef(rhs_expr.bcx, rhs_expr.val,
+ ty::expr_ty(bcx_tcx(cx), b));
+ let lhs_true_cx = new_scope_block_ctxt(cx, "lhs true");
+ let lhs_true_res = rslt(lhs_true_cx, C_bool(true));
+ // see the and case for an explanation
- auto rhs_bcx = trans_block_cleanups(rhs_res.bcx, rhs_cx);
- lhs_res.bcx.build.CondBr(lhs_res.val, lhs_true_cx.llbb,
- rhs_cx.llbb);
- ret join_results(cx, T_bool(),
- ~[lhs_true_res, rec(bcx=rhs_bcx,
- val=rhs_res.val)]);
- }
- case (_) {
- // Remaining cases are eager:
+ let rhs_bcx = trans_block_cleanups(rhs_res.bcx, rhs_cx);
+ lhs_res.bcx.build.CondBr(lhs_res.val, lhs_true_cx.llbb, rhs_cx.llbb);
+ ret join_results(cx, T_bool(),
+ ~[lhs_true_res, {bcx: rhs_bcx, val: rhs_res.val}]);
+ }
+ _ {
+ // Remaining cases are eager:
- auto lhs_expr = trans_expr(cx, a);
- auto lhty = ty::expr_ty(bcx_tcx(cx), a);
- auto lhs = autoderef(lhs_expr.bcx, lhs_expr.val, lhty);
- auto rhs_expr = trans_expr(lhs.bcx, b);
- auto rhty = ty::expr_ty(bcx_tcx(cx), b);
- auto rhs = autoderef(rhs_expr.bcx, rhs_expr.val, rhty);
- ret trans_eager_binop(rhs.bcx, op, lhs.ty,
- lhs.val, rhs.val);
- }
+ let lhs_expr = trans_expr(cx, a);
+ let lhty = ty::expr_ty(bcx_tcx(cx), a);
+ let lhs = autoderef(lhs_expr.bcx, lhs_expr.val, lhty);
+ let rhs_expr = trans_expr(lhs.bcx, b);
+ let rhty = ty::expr_ty(bcx_tcx(cx), b);
+ let rhs = autoderef(rhs_expr.bcx, rhs_expr.val, rhty);
+ ret trans_eager_binop(rhs.bcx, op, lhs.ty, lhs.val, rhs.val);
+ }
}
}
-fn join_results(&@block_ctxt parent_cx, TypeRef t, &result[] ins) -> result {
- let result[] live = ~[];
- let ValueRef[] vals = ~[];
- let BasicBlockRef[] bbs = ~[];
- for (result r in ins) {
- if (!is_terminated(r.bcx)) {
+fn join_results(parent_cx: &@block_ctxt, t: TypeRef, ins: &result[]) ->
+ result {
+ let live: result[] = ~[];
+ let vals: ValueRef[] = ~[];
+ let bbs: BasicBlockRef[] = ~[];
+ for r: result in ins {
+ if !is_terminated(r.bcx) {
live += ~[r];
vals += ~[r.val];
bbs += ~[r.bcx.llbb];
}
}
- alt (std::ivec::len[result](live)) {
- case (0u) {
- // No incoming edges are live, so we're in dead-code-land.
- // Arbitrarily pick the first dead edge, since the caller
- // is just going to propagate it outward.
+ alt std::ivec::len[result](live) {
+ 0u {
+ // No incoming edges are live, so we're in dead-code-land.
+ // Arbitrarily pick the first dead edge, since the caller
+ // is just going to propagate it outward.
- assert (std::ivec::len[result](ins) >= 1u);
- ret ins.(0);
- }
- case (_) {/* fall through */ }
+ assert (std::ivec::len[result](ins) >= 1u);
+ ret ins.(0);
+ }
+ _ {/* fall through */ }
}
// We have >1 incoming edges. Make a join block and br+phi them into it.
- auto join_cx = new_sub_block_ctxt(parent_cx, "join");
- for (result r in live) { r.bcx.build.Br(join_cx.llbb); }
- auto phi = join_cx.build.Phi(t, vals, bbs);
+ let join_cx = new_sub_block_ctxt(parent_cx, "join");
+ for r: result in live { r.bcx.build.Br(join_cx.llbb); }
+ let phi = join_cx.build.Phi(t, vals, bbs);
ret rslt(join_cx, phi);
}
-fn join_branches(&@block_ctxt parent_cx, &result[] ins) -> @block_ctxt {
- auto out = new_sub_block_ctxt(parent_cx, "join");
- for (result r in ins) {
- if (!is_terminated(r.bcx)) { r.bcx.build.Br(out.llbb); }
+fn join_branches(parent_cx: &@block_ctxt, ins: &result[]) -> @block_ctxt {
+ let out = new_sub_block_ctxt(parent_cx, "join");
+ for r: result in ins {
+ if !is_terminated(r.bcx) { r.bcx.build.Br(out.llbb); }
}
ret out;
}
tag out_method { return; save_in(ValueRef); }
-fn trans_if(&@block_ctxt cx, &@ast::expr cond, &ast::blk thn,
- &option::t[@ast::expr] els, ast::node_id id, &out_method output)
- -> result {
- auto cond_res = trans_expr(cx, cond);
- auto then_cx = new_scope_block_ctxt(cx, "then");
- auto then_res = trans_block(then_cx, thn, output);
- auto else_cx = new_scope_block_ctxt(cx, "else");
- auto else_res = alt (els) {
- case (some(?elexpr)) {
- alt (elexpr.node) {
- case (ast::expr_if(_, _, _)) {
- // Synthesize a block here to act as the else block
- // containing an if expression. Needed in order for the
- // else scope to behave like a normal block scope. A tad
- // ugly.
- auto elseif_blk = ast::block_from_expr(elexpr);
- trans_block(else_cx, elseif_blk, output)
- }
- case (ast::expr_block(?blk)) {
- // Calling trans_block directly instead of trans_expr
- // because trans_expr will create another scope block
- // context for the block, but we've already got the
- // 'else' context
+fn trans_if(cx: &@block_ctxt, cond: &@ast::expr, thn: &ast::blk,
+ els: &option::t[@ast::expr], id: ast::node_id,
+ output: &out_method) -> result {
+ let cond_res = trans_expr(cx, cond);
+ let then_cx = new_scope_block_ctxt(cx, "then");
+ let then_res = trans_block(then_cx, thn, output);
+ let else_cx = new_scope_block_ctxt(cx, "else");
+ let
+ // Synthesize a block here to act as the else block
+ // containing an if expression. Needed in order for the
+ // else scope to behave like a normal block scope. A tad
+ // ugly.
+ // Calling trans_block directly instead of trans_expr
+ // because trans_expr will create another scope block
+ // context for the block, but we've already got the
+ // 'else' context
- trans_block(else_cx, blk, output)
- }
+ else_res =
+ alt els {
+ some(elexpr) {
+ alt elexpr.node {
+ ast::expr_if(_, _, _) {
+ let elseif_blk = ast::block_from_expr(elexpr);
+ trans_block(else_cx, elseif_blk, output)
+ }
+ ast::expr_block(blk) { trans_block(else_cx, blk, output) }
}
- }
- case (_) { rslt(else_cx, C_nil()) }
- };
+ }
+ _ { rslt(else_cx, C_nil()) }
+ };
cond_res.bcx.build.CondBr(cond_res.val, then_cx.llbb, else_cx.llbb);
ret rslt(join_branches(cx, ~[then_res, else_res]), C_nil());
}
-fn trans_for(&@block_ctxt cx, &@ast::local local, &@ast::expr seq,
- &ast::blk body) -> result {
+fn trans_for(cx: &@block_ctxt, local: &@ast::local, seq: &@ast::expr,
+ body: &ast::blk) -> result {
// FIXME: We bind to an alias here to avoid a segfault... this is
// obviously a bug.
- fn inner(&@block_ctxt cx, @ast::local local, ValueRef curr, ty::t t,
- &ast::blk body, @block_ctxt outer_next_cx) -> result {
- auto next_cx = new_sub_block_ctxt(cx, "next");
- auto scope_cx =
+ fn inner(cx: &@block_ctxt, local: @ast::local, curr: ValueRef, t: ty::t,
+ body: &ast::blk, outer_next_cx: @block_ctxt) -> result {
+ let next_cx = new_sub_block_ctxt(cx, "next");
+ let scope_cx =
new_loop_scope_block_ctxt(cx, option::some[@block_ctxt](next_cx),
outer_next_cx, "for loop scope");
cx.build.Br(scope_cx.llbb);
- auto local_res = alloc_local(scope_cx, local);
- auto bcx = copy_val(local_res.bcx, INIT, local_res.val, curr, t).bcx;
+ let local_res = alloc_local(scope_cx, local);
+ let bcx = copy_val(local_res.bcx, INIT, local_res.val, curr, t).bcx;
add_clean(scope_cx, local_res.val, t);
bcx = trans_block(bcx, body, return).bcx;
- if (!bcx.build.is_terminated()) {
+ if !bcx.build.is_terminated() {
bcx.build.Br(next_cx.llbb);
// otherwise, this code is unreachable
}
ret rslt(next_cx, C_nil());
}
- auto next_cx = new_sub_block_ctxt(cx, "next");
- auto seq_ty = ty::expr_ty(bcx_tcx(cx), seq);
- auto seq_res = trans_expr(cx, seq);
- auto it =
+ let next_cx = new_sub_block_ctxt(cx, "next");
+ let seq_ty = ty::expr_ty(bcx_tcx(cx), seq);
+ let seq_res = trans_expr(cx, seq);
+ let it =
iter_sequence(seq_res.bcx, seq_res.val, seq_ty,
bind inner(_, local, _, _, body, next_cx));
it.bcx.build.Br(next_cx.llbb);
@@ -3731,55 +3661,55 @@
// Finds the ValueRef associated with a variable in a function
// context. It checks locals, upvars, and args.
-fn find_variable(&@fn_ctxt fcx, ast::node_id nid) -> ValueRef {
- ret
- alt (fcx.lllocals.find(nid)) {
- case (none) {
- alt (fcx.llupvars.find(nid)) {
- case (none) {
- alt (fcx.llargs.find(nid)) {
- case (some(?llval)) { llval }
- case (_) {
- fcx.lcx.ccx.sess.bug("unbound var \
- in build_environment " + int::str(nid))
- }
- }
- }
- case (some(?llval)) { llval }
+fn find_variable(fcx: &@fn_ctxt, nid: ast::node_id) -> ValueRef {
+ ret alt fcx.lllocals.find(nid) {
+ none. {
+ alt fcx.llupvars.find(nid) {
+ none. {
+ alt fcx.llargs.find(nid) {
+ some(llval) { llval }
+ _ {
+ fcx.lcx.ccx.sess.bug("unbound var \
+ in build_environment "
+ + int::str(nid))
+ }
}
+ }
+ some(llval) { llval }
}
- case (some(?llval)) { llval }
+ }
+ some(llval) { llval }
}
}
// Given a block context and a list of upvars, construct a closure that
// contains pointers to all of the upvars and all of the tydescs in
// scope. Return the ValueRef and TypeRef corresponding to the closure.
-fn build_environment(&@block_ctxt cx, &freevar_set upvars) ->
- rec(ValueRef ptr, TypeRef ptrty) {
- auto has_iterbody = !option::is_none(cx.fcx.lliterbody);
- auto llbindingsptr;
+fn build_environment(cx: &@block_ctxt, upvars: &freevar_set) ->
+ {ptr: ValueRef, ptrty: TypeRef} {
+ let has_iterbody = !option::is_none(cx.fcx.lliterbody);
+ let llbindingsptr;
- if (upvars.size() > 0u || has_iterbody) {
+ if upvars.size() > 0u || has_iterbody {
// Gather up the upvars.
- let ValueRef[] llbindings = ~[];
- let TypeRef[] llbindingtys = ~[];
- if (has_iterbody) {
+ let llbindings: ValueRef[] = ~[];
+ let llbindingtys: TypeRef[] = ~[];
+ if has_iterbody {
llbindings += ~[option::get(cx.fcx.lliterbody)];
llbindingtys += ~[val_ty(llbindings.(0))];
}
- for each (ast::node_id nid in upvars.keys()) {
- auto llbinding = find_variable(cx.fcx, nid);
+ for each nid: ast::node_id in upvars.keys() {
+ let llbinding = find_variable(cx.fcx, nid);
llbindings += ~[llbinding];
llbindingtys += ~[val_ty(llbinding)];
}
// Create an array of bindings and copy in aliases to the upvars.
llbindingsptr = alloca(cx, T_struct(llbindingtys));
- auto upvar_count = std::ivec::len(llbindings);
- auto i = 0u;
- while (i < upvar_count) {
- auto llbindingptr =
+ let upvar_count = std::ivec::len(llbindings);
+ let i = 0u;
+ while i < upvar_count {
+ let llbindingptr =
cx.build.GEP(llbindingsptr, ~[C_int(0), C_int(i as int)]);
cx.build.Store(llbindings.(i), llbindingptr);
i += 1u;
@@ -3790,88 +3720,88 @@
}
// Create an environment and populate it with the bindings.
- auto tydesc_count = std::ivec::len[ValueRef](cx.fcx.lltydescs);
- auto llenvptrty =
- T_closure_ptr(*bcx_ccx(cx), T_ptr(T_nil()),
- val_ty(llbindingsptr), tydesc_count);
- auto llenvptr = alloca(cx, llvm::LLVMGetElementType(llenvptrty));
- auto llbindingsptrptr =
+ let tydesc_count = std::ivec::len[ValueRef](cx.fcx.lltydescs);
+ let llenvptrty =
+ T_closure_ptr(*bcx_ccx(cx), T_ptr(T_nil()), val_ty(llbindingsptr),
+ tydesc_count);
+ let llenvptr = alloca(cx, llvm::LLVMGetElementType(llenvptrty));
+ let llbindingsptrptr =
cx.build.GEP(llenvptr,
~[C_int(0), C_int(abi::box_rc_field_body), C_int(2)]);
cx.build.Store(llbindingsptr, llbindingsptrptr);
// Copy in our type descriptors, in case the iterator body needs to refer
// to them.
- auto lltydescsptr =
+ let lltydescsptr =
cx.build.GEP(llenvptr,
~[C_int(0), C_int(abi::box_rc_field_body),
C_int(abi::closure_elt_ty_params)]);
- auto i = 0u;
- while (i < tydesc_count) {
- auto lltydescptr =
+ let i = 0u;
+ while i < tydesc_count {
+ let lltydescptr =
cx.build.GEP(lltydescsptr, ~[C_int(0), C_int(i as int)]);
cx.build.Store(cx.fcx.lltydescs.(i), lltydescptr);
i += 1u;
}
- ret rec(ptr=llenvptr, ptrty=llenvptrty);
+ ret {ptr: llenvptr, ptrty: llenvptrty};
}
// Given an enclosing block context, a new function context, a closure type,
// and a list of upvars, generate code to load and populate the environment
// with the upvars and type descriptors.
-fn load_environment(&@block_ctxt cx, &@fn_ctxt fcx,
- TypeRef llenvptrty, &freevar_set upvars) {
- auto copy_args_bcx = new_raw_block_ctxt(fcx, fcx.llcopyargs);
+fn load_environment(cx: &@block_ctxt, fcx: &@fn_ctxt, llenvptrty: TypeRef,
+ upvars: &freevar_set) {
+ let copy_args_bcx = new_raw_block_ctxt(fcx, fcx.llcopyargs);
// Populate the upvars from the environment.
- auto llremoteenvptr =
+ let llremoteenvptr =
copy_args_bcx.build.PointerCast(fcx.llenv, llenvptrty);
- auto llremotebindingsptrptr =
+ let llremotebindingsptrptr =
copy_args_bcx.build.GEP(llremoteenvptr,
~[C_int(0), C_int(abi::box_rc_field_body),
C_int(abi::closure_elt_bindings)]);
- auto llremotebindingsptr =
+ let llremotebindingsptr =
copy_args_bcx.build.Load(llremotebindingsptrptr);
- auto i = 0u;
- if (!option::is_none(cx.fcx.lliterbody)) {
+ let i = 0u;
+ if !option::is_none(cx.fcx.lliterbody) {
i += 1u;
- auto lliterbodyptr =
+ let lliterbodyptr =
copy_args_bcx.build.GEP(llremotebindingsptr,
~[C_int(0), C_int(0)]);
- auto lliterbody = copy_args_bcx.build.Load(lliterbodyptr);
+ let lliterbody = copy_args_bcx.build.Load(lliterbodyptr);
fcx.lliterbody = some(lliterbody);
}
- for each (ast::node_id upvar_id in upvars.keys()) {
- auto llupvarptrptr =
+ for each upvar_id: ast::node_id in upvars.keys() {
+ let llupvarptrptr =
copy_args_bcx.build.GEP(llremotebindingsptr,
~[C_int(0), C_int(i as int)]);
- auto llupvarptr = copy_args_bcx.build.Load(llupvarptrptr);
+ let llupvarptr = copy_args_bcx.build.Load(llupvarptrptr);
fcx.llupvars.insert(upvar_id, llupvarptr);
i += 1u;
}
// Populate the type parameters from the environment.
- auto llremotetydescsptr =
+ let llremotetydescsptr =
copy_args_bcx.build.GEP(llremoteenvptr,
~[C_int(0), C_int(abi::box_rc_field_body),
C_int(abi::closure_elt_ty_params)]);
- auto tydesc_count = std::ivec::len(cx.fcx.lltydescs);
+ let tydesc_count = std::ivec::len(cx.fcx.lltydescs);
i = 0u;
- while (i < tydesc_count) {
- auto llremotetydescptr =
+ while i < tydesc_count {
+ let llremotetydescptr =
copy_args_bcx.build.GEP(llremotetydescsptr,
~[C_int(0), C_int(i as int)]);
- auto llremotetydesc = copy_args_bcx.build.Load(llremotetydescptr);
+ let llremotetydesc = copy_args_bcx.build.Load(llremotetydescptr);
fcx.lltydescs += ~[llremotetydesc];
i += 1u;
}
}
-fn trans_for_each(&@block_ctxt cx, &@ast::local local, &@ast::expr seq,
- &ast::blk body) -> result {
+fn trans_for_each(cx: &@block_ctxt, local: &@ast::local, seq: &@ast::expr,
+ body: &ast::blk) -> result {
/*
* The translation is a little .. complex here. Code like:
*
@@ -3896,17 +3826,17 @@
// Step 1: Generate code to build an environment containing pointers
// to all of the upvars
- auto lcx = cx.fcx.lcx;
+ let lcx = cx.fcx.lcx;
// FIXME: possibly support alias-mode here?
- auto decl_ty = node_id_type(lcx.ccx, local.node.id);
- auto decl_id = local.node.id;
- auto upvars = get_freevars(lcx.ccx.tcx, body.node.id);
+ let decl_ty = node_id_type(lcx.ccx, local.node.id);
+ let decl_id = local.node.id;
+ let upvars = get_freevars(lcx.ccx.tcx, body.node.id);
- auto llenv = build_environment(cx, upvars);
+ let llenv = build_environment(cx, upvars);
// Step 2: Declare foreach body function.
- let str s =
+ let s: str =
mangle_internal_name_by_path_and_seq(lcx.ccx, lcx.path, "foreach");
// The 'env' arg entering the body function is a fake env member (as in
@@ -3914,13 +3844,13 @@
// points to a stack allocated env in this frame. We bundle that env
// pointer along with the foreach-body-fn pointer into a 'normal' fn pair
// and pass it in as a first class fn-arg to the iterator.
- auto iter_body_llty =
+ let iter_body_llty =
type_of_fn_full(lcx.ccx, cx.sp, ast::proto_fn, false,
- ~[rec(mode=ty::mo_alias(false), ty=decl_ty)],
+ ~[{mode: ty::mo_alias(false), ty: decl_ty}],
ty::mk_nil(lcx.ccx.tcx), 0u);
- let ValueRef lliterbody =
+ let lliterbody: ValueRef =
decl_internal_fastcall_fn(lcx.ccx.llmod, s, iter_body_llty);
- auto fcx = new_fn_ctxt(lcx, cx.sp, lliterbody);
+ let fcx = new_fn_ctxt(lcx, cx.sp, lliterbody);
// Generate code to load the environment out of the
// environment pointer.
@@ -3928,97 +3858,99 @@
// Add an upvar for the loop variable alias.
fcx.llupvars.insert(decl_id, llvm::LLVMGetParam(fcx.llfn, 3u));
- auto bcx = new_top_block_ctxt(fcx);
- auto lltop = bcx.llbb;
- auto r = trans_block(bcx, body, return);
+ let bcx = new_top_block_ctxt(fcx);
+ let lltop = bcx.llbb;
+ let r = trans_block(bcx, body, return);
finish_fn(fcx, lltop);
- if (!r.bcx.build.is_terminated()) {
+ if !r.bcx.build.is_terminated() {
// if terminated is true, no need for the ret-fail
r.bcx.build.RetVoid();
}
+
// Step 3: Call iter passing [lliterbody, llenv], plus other args.
- alt (seq.node) {
- case (ast::expr_call(?f, ?args)) {
- auto pair = create_real_fn_pair(cx, iter_body_llty,
- lliterbody, llenv.ptr);
- r = trans_call(cx, f, some[ValueRef](cx.build.Load(pair)),
- args, seq.id);
- ret rslt(r.bcx, C_nil());
- }
+ alt seq.node {
+ ast::expr_call(f, args) {
+ let pair =
+ create_real_fn_pair(cx, iter_body_llty, lliterbody, llenv.ptr);
+ r =
+ trans_call(cx, f, some[ValueRef](cx.build.Load(pair)), args,
+ seq.id);
+ ret rslt(r.bcx, C_nil());
+ }
}
}
-fn trans_while(&@block_ctxt cx, &@ast::expr cond, &ast::blk body) ->
+fn trans_while(cx: &@block_ctxt, cond: &@ast::expr, body: &ast::blk) ->
result {
- auto cond_cx = new_scope_block_ctxt(cx, "while cond");
- auto next_cx = new_sub_block_ctxt(cx, "next");
- auto body_cx =
+ let cond_cx = new_scope_block_ctxt(cx, "while cond");
+ let next_cx = new_sub_block_ctxt(cx, "next");
+ let body_cx =
new_loop_scope_block_ctxt(cx, option::none[@block_ctxt], next_cx,
"while loop body");
- auto body_res = trans_block(body_cx, body, return);
- auto cond_res = trans_expr(cond_cx, cond);
+ let body_res = trans_block(body_cx, body, return);
+ let cond_res = trans_expr(cond_cx, cond);
body_res.bcx.build.Br(cond_cx.llbb);
- auto cond_bcx = trans_block_cleanups(cond_res.bcx, cond_cx);
+ let cond_bcx = trans_block_cleanups(cond_res.bcx, cond_cx);
cond_bcx.build.CondBr(cond_res.val, body_cx.llbb, next_cx.llbb);
cx.build.Br(cond_cx.llbb);
ret rslt(next_cx, C_nil());
}
-fn trans_do_while(&@block_ctxt cx, &ast::blk body, &@ast::expr cond) ->
+fn trans_do_while(cx: &@block_ctxt, body: &ast::blk, cond: &@ast::expr) ->
result {
- auto next_cx = new_sub_block_ctxt(cx, "next");
- auto body_cx =
+ let next_cx = new_sub_block_ctxt(cx, "next");
+ let body_cx =
new_loop_scope_block_ctxt(cx, option::none[@block_ctxt], next_cx,
"do-while loop body");
- auto body_res = trans_block(body_cx, body, return);
- auto cond_res = trans_expr(body_res.bcx, cond);
+ let body_res = trans_block(body_cx, body, return);
+ let cond_res = trans_expr(body_res.bcx, cond);
cond_res.bcx.build.CondBr(cond_res.val, body_cx.llbb, next_cx.llbb);
cx.build.Br(body_cx.llbb);
ret rslt(next_cx, body_res.val);
}
type generic_info =
- rec(ty::t item_type,
- (option::t[@tydesc_info])[] static_tis,
- ValueRef[] tydescs);
+ {item_type: ty::t,
+ static_tis: (option::t[@tydesc_info])[],
+ tydescs: ValueRef[]};
type lval_result =
- rec(result res,
- bool is_mem,
- option::t[generic_info] generic,
- option::t[ValueRef] llobj,
- option::t[ty::t] method_ty);
+ {res: result,
+ is_mem: bool,
+ generic: option::t[generic_info],
+ llobj: option::t[ValueRef],
+ method_ty: option::t[ty::t]};
-fn lval_mem(&@block_ctxt cx, ValueRef val) -> lval_result {
- ret rec(res=rslt(cx, val),
- is_mem=true,
- generic=none[generic_info],
- llobj=none[ValueRef],
- method_ty=none[ty::t]);
+fn lval_mem(cx: &@block_ctxt, val: ValueRef) -> lval_result {
+ ret {res: rslt(cx, val),
+ is_mem: true,
+ generic: none[generic_info],
+ llobj: none[ValueRef],
+ method_ty: none[ty::t]};
}
-fn lval_val(&@block_ctxt cx, ValueRef val) -> lval_result {
- ret rec(res=rslt(cx, val),
- is_mem=false,
- generic=none[generic_info],
- llobj=none[ValueRef],
- method_ty=none[ty::t]);
+fn lval_val(cx: &@block_ctxt, val: ValueRef) -> lval_result {
+ ret {res: rslt(cx, val),
+ is_mem: false,
+ generic: none[generic_info],
+ llobj: none[ValueRef],
+ method_ty: none[ty::t]};
}
-fn trans_external_path(&@block_ctxt cx, &ast::def_id did,
- &ty::ty_param_count_and_ty tpt) -> ValueRef {
- auto lcx = cx.fcx.lcx;
- auto name = csearch::get_symbol(lcx.ccx.sess.get_cstore(), did);
+fn trans_external_path(cx: &@block_ctxt, did: &ast::def_id,
+ tpt: &ty::ty_param_count_and_ty) -> ValueRef {
+ let lcx = cx.fcx.lcx;
+ let name = csearch::get_symbol(lcx.ccx.sess.get_cstore(), did);
ret get_extern_const(lcx.ccx.externs, lcx.ccx.llmod, name,
type_of_ty_param_count_and_ty(lcx, cx.sp, tpt));
}
-fn lval_generic_fn(&@block_ctxt cx, &ty::ty_param_count_and_ty tpt,
- &ast::def_id fn_id, ast::node_id id) -> lval_result {
- auto lv;
- if (fn_id.crate == ast::local_crate) {
+fn lval_generic_fn(cx: &@block_ctxt, tpt: &ty::ty_param_count_and_ty,
+ fn_id: &ast::def_id, id: ast::node_id) -> lval_result {
+ let lv;
+ if fn_id.crate == ast::local_crate {
// Internal reference.
assert (bcx_ccx(cx).fn_pairs.contains_key(fn_id.node));
lv = lval_val(cx, bcx_ccx(cx).fn_pairs.get(fn_id.node));
@@ -4026,250 +3958,238 @@
// External reference.
lv = lval_val(cx, trans_external_path(cx, fn_id, tpt));
}
- auto tys = ty::node_id_to_type_params(bcx_tcx(cx), id);
- if (std::ivec::len[ty::t](tys) != 0u) {
- auto bcx = lv.res.bcx;
- let ValueRef[] tydescs = ~[];
- let (option::t[@tydesc_info])[] tis = ~[];
- for (ty::t t in tys) {
+ let tys = ty::node_id_to_type_params(bcx_tcx(cx), id);
+ if std::ivec::len[ty::t](tys) != 0u {
+ let bcx = lv.res.bcx;
+ let tydescs: ValueRef[] = ~[];
+ let tis: (option::t[@tydesc_info])[] = ~[];
+ for t: ty::t in tys {
// TODO: Doesn't always escape.
- auto ti = none[@tydesc_info];
- auto td = get_tydesc(bcx, t, true, ti);
+ let ti = none[@tydesc_info];
+ let td = get_tydesc(bcx, t, true, ti);
tis += ~[ti];
bcx = td.bcx;
tydescs += ~[td.val];
}
- auto gen = rec(item_type=tpt.ty, static_tis=tis, tydescs=tydescs);
- lv = rec(res=rslt(bcx, lv.res.val), generic=some[generic_info](gen)
- with lv);
+ let gen = {item_type: tpt.ty, static_tis: tis, tydescs: tydescs};
+ lv =
+ {res: rslt(bcx, lv.res.val), generic: some[generic_info](gen)
+ with lv};
}
ret lv;
}
-fn lookup_discriminant(&@local_ctxt lcx, &ast::def_id tid, &ast::def_id vid)
- -> ValueRef {
- alt (lcx.ccx.discrims.find(vid.node)) {
- case (none) {
- // It's an external discriminant that we haven't seen yet.
- assert (vid.crate != ast::local_crate);
- auto sym = csearch::get_symbol(lcx.ccx.sess.get_cstore(), vid);
- auto gvar =
- llvm::LLVMAddGlobal(lcx.ccx.llmod, T_int(), str::buf(sym));
- llvm::LLVMSetLinkage(gvar,
- lib::llvm::LLVMExternalLinkage as
- llvm::Linkage);
- llvm::LLVMSetGlobalConstant(gvar, True);
- lcx.ccx.discrims.insert(vid.node, gvar);
- ret gvar;
- }
- case (some(?llval)) { ret llval; }
+fn lookup_discriminant(lcx: &@local_ctxt, tid: &ast::def_id,
+ vid: &ast::def_id) -> ValueRef {
+ alt lcx.ccx.discrims.find(vid.node) {
+ none. {
+ // It's an external discriminant that we haven't seen yet.
+ assert (vid.crate != ast::local_crate);
+ let sym = csearch::get_symbol(lcx.ccx.sess.get_cstore(), vid);
+ let gvar = llvm::LLVMAddGlobal(lcx.ccx.llmod, T_int(), str::buf(sym));
+ llvm::LLVMSetLinkage(gvar,
+ lib::llvm::LLVMExternalLinkage as llvm::Linkage);
+ llvm::LLVMSetGlobalConstant(gvar, True);
+ lcx.ccx.discrims.insert(vid.node, gvar);
+ ret gvar;
+ }
+ some(llval) { ret llval; }
}
}
-fn trans_path(&@block_ctxt cx, &ast::path p, ast::node_id id) -> lval_result {
- auto ccx = bcx_ccx(cx);
- alt (bcx_tcx(cx).def_map.find(id)) {
- case (some(ast::def_arg(?did))) {
- alt (cx.fcx.llargs.find(did.node)) {
- case (none) {
- assert (cx.fcx.llupvars.contains_key(did.node));
- ret lval_mem(cx, cx.fcx.llupvars.get(did.node));
- }
- case (some(?llval)) { ret lval_mem(cx, llval); }
- }
+fn trans_path(cx: &@block_ctxt, p: &ast::path, id: ast::node_id) ->
+ lval_result {
+ let ccx = bcx_ccx(cx);
+ alt bcx_tcx(cx).def_map.find(id) {
+ some(ast::def_arg(did)) {
+ alt cx.fcx.llargs.find(did.node) {
+ none. {
+ assert (cx.fcx.llupvars.contains_key(did.node));
+ ret lval_mem(cx, cx.fcx.llupvars.get(did.node));
+ }
+ some(llval) { ret lval_mem(cx, llval); }
}
- case (some(ast::def_local(?did))) {
- alt (cx.fcx.lllocals.find(did.node)) {
- case (none) {
- assert (cx.fcx.llupvars.contains_key(did.node));
- ret lval_mem(cx, cx.fcx.llupvars.get(did.node));
- }
- case (some(?llval)) { ret lval_mem(cx, llval); }
- }
+ }
+ some(ast::def_local(did)) {
+ alt cx.fcx.lllocals.find(did.node) {
+ none. {
+ assert (cx.fcx.llupvars.contains_key(did.node));
+ ret lval_mem(cx, cx.fcx.llupvars.get(did.node));
+ }
+ some(llval) { ret lval_mem(cx, llval); }
}
- case (some(ast::def_binding(?did))) {
- alt (cx.fcx.lllocals.find(did.node)) {
- case (none) {
- assert (cx.fcx.llupvars.contains_key(did.node));
- ret lval_mem(cx, cx.fcx.llupvars.get(did.node));
- }
- case (some(?llval)) { ret lval_mem(cx, llval); }
- }
+ }
+ some(ast::def_binding(did)) {
+ alt cx.fcx.lllocals.find(did.node) {
+ none. {
+ assert (cx.fcx.llupvars.contains_key(did.node));
+ ret lval_mem(cx, cx.fcx.llupvars.get(did.node));
+ }
+ some(llval) { ret lval_mem(cx, llval); }
}
- case (some(ast::def_obj_field(?did))) {
- assert (cx.fcx.llobjfields.contains_key(did.node));
- ret lval_mem(cx, cx.fcx.llobjfields.get(did.node));
- }
- case (some(ast::def_fn(?did, _))) {
- auto tyt = ty::lookup_item_type(ccx.tcx, did);
- ret lval_generic_fn(cx, tyt, did, id);
- }
- case (some(ast::def_variant(?tid, ?vid))) {
- auto v_tyt = ty::lookup_item_type(ccx.tcx, vid);
- alt (ty::struct(ccx.tcx, v_tyt.ty)) {
- case (ty::ty_fn(_, _, _, _, _)) {
- // N-ary variant.
+ }
+ some(ast::def_obj_field(did)) {
+ assert (cx.fcx.llobjfields.contains_key(did.node));
+ ret lval_mem(cx, cx.fcx.llobjfields.get(did.node));
+ }
+ some(ast::def_fn(did, _)) {
+ let tyt = ty::lookup_item_type(ccx.tcx, did);
+ ret lval_generic_fn(cx, tyt, did, id);
+ }
+ some(ast::def_variant(tid, vid)) {
+ let v_tyt = ty::lookup_item_type(ccx.tcx, vid);
+ alt ty::struct(ccx.tcx, v_tyt.ty) {
+ ty::ty_fn(_, _, _, _, _) {
+ // N-ary variant.
- ret lval_generic_fn(cx, v_tyt, vid, id);
- }
- case (_) {
- // Nullary variant.
- auto tag_ty = node_id_type(ccx, id);
- auto alloc_result = alloc_ty(cx, tag_ty);
- auto lltagblob = alloc_result.val;
- auto lltagty = type_of_tag(ccx, p.span, tid, tag_ty);
- auto bcx = alloc_result.bcx;
- auto lltagptr = bcx.build.PointerCast
- (lltagblob, T_ptr(lltagty));
- if (std::ivec::len(ty::tag_variants(ccx.tcx, tid))
- != 1u) {
- auto lldiscrim_gv =
- lookup_discriminant(bcx.fcx.lcx, tid, vid);
- auto lldiscrim = bcx.build.Load(lldiscrim_gv);
- auto lldiscrimptr = bcx.build.GEP
- (lltagptr, ~[C_int(0), C_int(0)]);
- bcx.build.Store(lldiscrim, lldiscrimptr);
- }
- ret lval_val(bcx, lltagptr);
- }
+ ret lval_generic_fn(cx, v_tyt, vid, id);
+ }
+ _ {
+ // Nullary variant.
+ let tag_ty = node_id_type(ccx, id);
+ let alloc_result = alloc_ty(cx, tag_ty);
+ let lltagblob = alloc_result.val;
+ let lltagty = type_of_tag(ccx, p.span, tid, tag_ty);
+ let bcx = alloc_result.bcx;
+ let lltagptr = bcx.build.PointerCast(lltagblob, T_ptr(lltagty));
+ if std::ivec::len(ty::tag_variants(ccx.tcx, tid)) != 1u {
+ let lldiscrim_gv = lookup_discriminant(bcx.fcx.lcx, tid, vid);
+ let lldiscrim = bcx.build.Load(lldiscrim_gv);
+ let lldiscrimptr =
+ bcx.build.GEP(lltagptr, ~[C_int(0), C_int(0)]);
+ bcx.build.Store(lldiscrim, lldiscrimptr);
}
- }
- case (some(ast::def_const(?did))) {
- if (did.crate == ast::local_crate) {
- assert (ccx.consts.contains_key(did.node));
- ret lval_mem(cx, ccx.consts.get(did.node));
- } else {
- auto tp = ty::node_id_to_monotype(ccx.tcx, id);
- ret lval_val(cx, load_if_immediate
- (cx, trans_external_path
- (cx, did, rec(count=0u, ty=tp)), tp));
+ ret lval_val(bcx, lltagptr);
}
}
- case (some(ast::def_native_fn(?did))) {
- auto tyt = ty::lookup_item_type(ccx.tcx, did);
- ret lval_generic_fn(cx, tyt, did, id);
+ }
+ some(ast::def_const(did)) {
+ if did.crate == ast::local_crate {
+ assert (ccx.consts.contains_key(did.node));
+ ret lval_mem(cx, ccx.consts.get(did.node));
+ } else {
+ let tp = ty::node_id_to_monotype(ccx.tcx, id);
+ ret lval_val(cx,
+ load_if_immediate(cx,
+ trans_external_path(cx, did,
+ {count: 0u,
+ ty: tp}),
+ tp));
}
- case (_) {
- ccx.sess.span_unimpl(cx.sp, "def variant in trans");
- }
+ }
+ some(ast::def_native_fn(did)) {
+ let tyt = ty::lookup_item_type(ccx.tcx, did);
+ ret lval_generic_fn(cx, tyt, did, id);
+ }
+ _ { ccx.sess.span_unimpl(cx.sp, "def variant in trans"); }
}
}
-fn trans_field(&@block_ctxt cx, &span sp, ValueRef v, &ty::t t0,
- &ast::ident field, ast::node_id id) -> lval_result {
- auto r = autoderef(cx, v, t0);
- auto t = r.ty;
- alt (ty::struct(bcx_tcx(cx), t)) {
- case (ty::ty_rec(?fields)) {
- let uint ix =
- ty::field_idx(bcx_ccx(cx).sess, sp, field, fields);
- auto v = GEP_tup_like(r.bcx, t, r.val, ~[0, ix as int]);
- ret lval_mem(v.bcx, v.val);
- }
- case (ty::ty_obj(?methods)) {
- let uint ix =
- ty::method_idx(bcx_ccx(cx).sess, sp, field, methods);
- auto vtbl =
- r.bcx.build.GEP(r.val,
- ~[C_int(0), C_int(abi::obj_field_vtbl)]);
- vtbl = r.bcx.build.Load(vtbl);
+fn trans_field(cx: &@block_ctxt, sp: &span, v: ValueRef, t0: &ty::t,
+ field: &ast::ident, id: ast::node_id) -> lval_result {
+ let r = autoderef(cx, v, t0);
+ let t = r.ty;
+ alt ty::struct(bcx_tcx(cx), t) {
+ ty::ty_rec(fields) {
+ let ix: uint = ty::field_idx(bcx_ccx(cx).sess, sp, field, fields);
+ let v = GEP_tup_like(r.bcx, t, r.val, ~[0, ix as int]);
+ ret lval_mem(v.bcx, v.val);
+ }
+ ty::ty_obj(methods) {
+ let ix: uint = ty::method_idx(bcx_ccx(cx).sess, sp, field, methods);
+ let vtbl =
+ r.bcx.build.GEP(r.val, ~[C_int(0), C_int(abi::obj_field_vtbl)]);
+ vtbl = r.bcx.build.Load(vtbl);
- auto vtbl_type = T_ptr(T_array(T_ptr(T_nil()), ix + 2u));
- vtbl = cx.build.PointerCast(vtbl, vtbl_type);
+ let vtbl_type = T_ptr(T_array(T_ptr(T_nil()), ix + 2u));
+ vtbl = cx.build.PointerCast(vtbl, vtbl_type);
- // +1 because slot #0 contains the destructor
- auto v = r.bcx.build.GEP(vtbl,
- ~[C_int(0), C_int(ix + 1u as int)]);
- let ty::t fn_ty =
- ty::method_ty_to_fn_ty(bcx_tcx(cx), methods.(ix));
- auto tcx = bcx_tcx(cx);
- auto ll_fn_ty = type_of_fn_full(bcx_ccx(cx), sp,
- ty::ty_fn_proto(tcx, fn_ty),
- true,
- ty::ty_fn_args(tcx, fn_ty),
- ty::ty_fn_ret(tcx, fn_ty),
- 0u);
- v = r.bcx.build.PointerCast(v, T_ptr(T_ptr(ll_fn_ty)));
- auto lvo = lval_mem(r.bcx, v);
- ret rec(llobj=some[ValueRef](r.val), method_ty=some[ty::t](fn_ty)
- with lvo);
- }
- case (_) {
- bcx_ccx(cx).sess.unimpl("field variant in trans_field");
- }
+ // +1 because slot #0 contains the destructor
+ let v = r.bcx.build.GEP(vtbl, ~[C_int(0), C_int(ix + 1u as int)]);
+ let fn_ty: ty::t = ty::method_ty_to_fn_ty(bcx_tcx(cx), methods.(ix));
+ let tcx = bcx_tcx(cx);
+ let ll_fn_ty =
+ type_of_fn_full(bcx_ccx(cx), sp, ty::ty_fn_proto(tcx, fn_ty),
+ true, ty::ty_fn_args(tcx, fn_ty),
+ ty::ty_fn_ret(tcx, fn_ty), 0u);
+ v = r.bcx.build.PointerCast(v, T_ptr(T_ptr(ll_fn_ty)));
+ let lvo = lval_mem(r.bcx, v);
+ ret {llobj: some[ValueRef](r.val), method_ty: some[ty::t](fn_ty)
+ with lvo};
+ }
+ _ { bcx_ccx(cx).sess.unimpl("field variant in trans_field"); }
}
}
-fn trans_index(&@block_ctxt cx, &span sp, &@ast::expr base, &@ast::expr idx,
- ast::node_id id) -> lval_result {
+fn trans_index(cx: &@block_ctxt, sp: &span, base: &@ast::expr,
+ idx: &@ast::expr, id: ast::node_id) -> lval_result {
// Is this an interior vector?
- auto base_ty = ty::expr_ty(bcx_tcx(cx), base);
- auto exp = trans_expr(cx, base);
- auto lv = autoderef(exp.bcx, exp.val, base_ty);
- auto base_ty_no_boxes = lv.ty;
- auto is_interior =
- ty::sequence_is_interior(bcx_tcx(cx), base_ty_no_boxes);
- auto ix = trans_expr(lv.bcx, idx);
- auto v = lv.val;
- auto bcx = ix.bcx;
+ let base_ty = ty::expr_ty(bcx_tcx(cx), base);
+ let exp = trans_expr(cx, base);
+ let lv = autoderef(exp.bcx, exp.val, base_ty);
+ let base_ty_no_boxes = lv.ty;
+ let is_interior = ty::sequence_is_interior(bcx_tcx(cx), base_ty_no_boxes);
+ let ix = trans_expr(lv.bcx, idx);
+ let v = lv.val;
+ let bcx = ix.bcx;
// Cast to an LLVM integer. Rust is less strict than LLVM in this regard.
- auto ix_val;
- auto ix_size = llsize_of_real(bcx_ccx(cx), val_ty(ix.val));
- auto int_size = llsize_of_real(bcx_ccx(cx), T_int());
- if (ix_size < int_size) {
+ let ix_val;
+ let ix_size = llsize_of_real(bcx_ccx(cx), val_ty(ix.val));
+ let int_size = llsize_of_real(bcx_ccx(cx), T_int());
+ if ix_size < int_size {
ix_val = bcx.build.ZExt(ix.val, T_int());
} else if (ix_size > int_size) {
ix_val = bcx.build.Trunc(ix.val, T_int());
} else { ix_val = ix.val; }
- auto unit_ty = node_id_type(bcx_ccx(cx), id);
- auto unit_sz = size_of(bcx, unit_ty);
+ let unit_ty = node_id_type(bcx_ccx(cx), id);
+ let unit_sz = size_of(bcx, unit_ty);
bcx = unit_sz.bcx;
maybe_name_value(bcx_ccx(cx), unit_sz.val, "unit_sz");
- auto scaled_ix = bcx.build.Mul(ix_val, unit_sz.val);
+ let scaled_ix = bcx.build.Mul(ix_val, unit_sz.val);
maybe_name_value(bcx_ccx(cx), scaled_ix, "scaled_ix");
- auto interior_len_and_data;
- if (is_interior) {
- auto rslt = ivec::get_len_and_data(bcx, v, unit_ty);
- interior_len_and_data = some(rec(len=rslt.len, data=rslt.data));
+ let interior_len_and_data;
+ if is_interior {
+ let rslt = ivec::get_len_and_data(bcx, v, unit_ty);
+ interior_len_and_data = some({len: rslt.len, data: rslt.data});
bcx = rslt.bcx;
} else { interior_len_and_data = none; }
- auto lim;
- alt (interior_len_and_data) {
- case (some(?lad)) { lim = lad.len; }
- case (none) {
- lim = bcx.build.GEP(v, ~[C_int(0), C_int(abi::vec_elt_fill)]);
- lim = bcx.build.Load(lim);
- }
+ let lim;
+ alt interior_len_and_data {
+ some(lad) { lim = lad.len; }
+ none. {
+ lim = bcx.build.GEP(v, ~[C_int(0), C_int(abi::vec_elt_fill)]);
+ lim = bcx.build.Load(lim);
+ }
}
- auto bounds_check = bcx.build.ICmp(lib::llvm::LLVMIntULT, scaled_ix, lim);
- auto fail_cx = new_sub_block_ctxt(bcx, "fail");
- auto next_cx = new_sub_block_ctxt(bcx, "next");
+ let bounds_check = bcx.build.ICmp(lib::llvm::LLVMIntULT, scaled_ix, lim);
+ let fail_cx = new_sub_block_ctxt(bcx, "fail");
+ let next_cx = new_sub_block_ctxt(bcx, "next");
bcx.build.CondBr(bounds_check, next_cx.llbb, fail_cx.llbb);
// fail: bad bounds check.
trans_fail(fail_cx, some[span](sp), "bounds check");
- auto body;
- alt (interior_len_and_data) {
- case (some(?lad)) { body = lad.data; }
- case (none) {
- body =
- next_cx.build.GEP(v,
- ~[C_int(0), C_int(abi::vec_elt_data),
- C_int(0)]);
- }
+ let body;
+ alt interior_len_and_data {
+ some(lad) { body = lad.data; }
+ none. {
+ body =
+ next_cx.build.GEP(v,
+ ~[C_int(0), C_int(abi::vec_elt_data),
+ C_int(0)]);
+ }
}
- auto elt;
- if (ty::type_has_dynamic_size(bcx_tcx(cx), unit_ty)) {
+ let elt;
+ if ty::type_has_dynamic_size(bcx_tcx(cx), unit_ty) {
body = next_cx.build.PointerCast(body, T_ptr(T_i8()));
elt = next_cx.build.GEP(body, ~[scaled_ix]);
} else {
elt = next_cx.build.GEP(body, ~[ix_val]);
// We're crossing a box boundary here, so we may need to pointer cast.
- auto llunitty = type_of(bcx_ccx(next_cx), sp, unit_ty);
+ let llunitty = type_of(bcx_ccx(next_cx), sp, unit_ty);
elt = next_cx.build.PointerCast(elt, T_ptr(llunitty));
}
ret lval_mem(next_cx, elt);
@@ -4279,159 +4199,164 @@
// The additional bool returned indicates whether it's mem (that is
// represented as an alloca or heap, hence needs a 'load' to be used as an
// immediate).
-fn trans_lval_gen(&@block_ctxt cx, &@ast::expr e) -> lval_result {
- alt (e.node) {
- case (ast::expr_path(?p)) { ret trans_path(cx, p, e.id); }
- case (ast::expr_field(?base, ?ident)) {
- auto r = trans_expr(cx, base);
- auto t = ty::expr_ty(bcx_tcx(cx), base);
- ret trans_field(r.bcx, e.span, r.val, t, ident, e.id);
- }
- case (ast::expr_index(?base, ?idx)) {
- ret trans_index(cx, e.span, base, idx, e.id);
- }
- case (ast::expr_unary(ast::deref, ?base)) {
- auto ccx = bcx_ccx(cx);
- auto sub = trans_expr(cx, base);
- auto t = ty::expr_ty(ccx.tcx, base);
- auto val = alt (ty::struct(ccx.tcx, t)) {
- case (ty::ty_box(_)) {
- sub.bcx.build.InBoundsGEP
- (sub.val, ~[C_int(0), C_int(abi::box_rc_field_body)])
- }
- case (ty::ty_res(_, _, _)) {
- sub.bcx.build.InBoundsGEP(sub.val, ~[C_int(0), C_int(1)])
- }
- case (ty::ty_tag(_, _)) {
- auto ety = ty::expr_ty(ccx.tcx, e);
- auto ellty;
- if (ty::type_has_dynamic_size(ccx.tcx, ety)) {
- ellty = T_typaram_ptr(ccx.tn);
- } else {
- ellty = T_ptr(type_of(ccx, e.span, ety));
- };
- sub.bcx.build.PointerCast(sub.val, ellty)
- }
- case (ty::ty_ptr(_)) { sub.val }
+fn trans_lval_gen(cx: &@block_ctxt, e: &@ast::expr) -> lval_result {
+ alt e.node {
+ ast::expr_path(p) { ret trans_path(cx, p, e.id); }
+ ast::expr_field(base, ident) {
+ let r = trans_expr(cx, base);
+ let t = ty::expr_ty(bcx_tcx(cx), base);
+ ret trans_field(r.bcx, e.span, r.val, t, ident, e.id);
+ }
+ ast::expr_index(base, idx) {
+ ret trans_index(cx, e.span, base, idx, e.id);
+ }
+ ast::expr_unary(ast::deref., base) {
+ let ccx = bcx_ccx(cx);
+ let sub = trans_expr(cx, base);
+ let t = ty::expr_ty(ccx.tcx, base);
+ let val =
+ alt ty::struct(ccx.tcx, t) {
+ ty::ty_box(_) {
+ sub.bcx.build.InBoundsGEP(sub.val,
+ ~[C_int(0),
+ C_int(abi::box_rc_field_body)])
+ }
+ ty::ty_res(_, _, _) {
+ sub.bcx.build.InBoundsGEP(sub.val, ~[C_int(0), C_int(1)])
+ }
+ ty::ty_tag(_, _) {
+ let ety = ty::expr_ty(ccx.tcx, e);
+ let ellty;
+ if ty::type_has_dynamic_size(ccx.tcx, ety) {
+ ellty = T_typaram_ptr(ccx.tn);
+ } else { ellty = T_ptr(type_of(ccx, e.span, ety)); }
+ sub.bcx.build.PointerCast(sub.val, ellty)
+ }
+ ty::ty_ptr(_) { sub.val }
};
- ret lval_mem(sub.bcx, val);
- }
- case (ast::expr_self_method(?ident)) {
- alt ({ cx.fcx.llself }) {
- case (some(?pair)) {
- auto r = pair.v;
- auto t = pair.t;
- ret trans_field(cx, e.span, r, t, ident, e.id);
- }
- case (_) {
- // Shouldn't happen.
- bcx_ccx(cx).sess.bug("trans_lval called on \
+ ret lval_mem(sub.bcx, val);
+ }
+ ast::expr_self_method(ident) {
+ alt { cx.fcx.llself } {
+ some(pair) {
+ let r = pair.v;
+ let t = pair.t;
+ ret trans_field(cx, e.span, r, t, ident, e.id);
+ }
+ _ {
+ // Shouldn't happen.
+ bcx_ccx(cx).sess.bug("trans_lval called on \
expr_self_method in \
a context without llself");
- }
- }
+ }
}
- case (_) {
- ret rec(res=trans_expr(cx, e),
- is_mem=false,
- generic=none,
- llobj=none,
- method_ty=none);
- }
- }
-}
-
-fn trans_lval(&@block_ctxt cx, &@ast::expr e) -> lval_result {
- auto lv = trans_lval_gen(cx, e);
- alt (lv.generic) {
- case (some(?gi)) {
- auto t = ty::expr_ty(bcx_tcx(cx), e);
- auto n_args =
- std::ivec::len(ty::ty_fn_args(bcx_tcx(cx), t));
- auto args = std::ivec::init_elt(none[@ast::expr], n_args);
- auto bound = trans_bind_1(lv.res.bcx, e, lv, args, e.id);
- ret lval_val(bound.bcx, bound.val);
- }
- case (none) {
- ret lv;
- }
- }
-}
-
-fn int_cast(&@block_ctxt bcx, TypeRef lldsttype, TypeRef llsrctype,
- ValueRef llsrc, bool signed) -> ValueRef {
- auto srcsz = llvm::LLVMGetIntTypeWidth(llsrctype);
- auto dstsz = llvm::LLVMGetIntTypeWidth(lldsttype);
- ret if dstsz == srcsz { bcx.build.BitCast(llsrc, lldsttype) }
- else if srcsz > dstsz { bcx.build.TruncOrBitCast(llsrc, lldsttype) }
- else if signed { bcx.build.SExtOrBitCast(llsrc, lldsttype) }
- else { bcx.build.ZExtOrBitCast(llsrc, lldsttype) };
-}
-
-fn float_cast(&@block_ctxt bcx, TypeRef lldsttype, TypeRef llsrctype,
- ValueRef llsrc) -> ValueRef {
- auto srcsz = lib::llvm::float_width(llsrctype);
- auto dstsz = lib::llvm::float_width(lldsttype);
- ret if dstsz > srcsz { bcx.build.FPExt(llsrc, lldsttype) }
- else if srcsz > dstsz { bcx.build.FPTrunc(llsrc, lldsttype) }
- else { llsrc };
-}
-
-fn trans_cast(&@block_ctxt cx, &@ast::expr e, ast::node_id id) -> result {
- auto ccx = bcx_ccx(cx);
- auto e_res = trans_expr(cx, e);
- auto ll_t_in = val_ty(e_res.val);
- auto t_in = ty::expr_ty(ccx.tcx, e);
- auto t_out = node_id_type(ccx, id);
- auto ll_t_out = type_of(ccx, e.span, t_out);
-
- tag kind { native_; integral; float; other; }
- fn t_kind(&ty::ctxt tcx, ty::t t) -> kind {
- ret if ty::type_is_fp(tcx, t) { float }
- else if ty::type_is_native(tcx, t) { native_ }
- else if ty::type_is_integral(tcx, t) { integral }
- else { other };
- }
- auto k_in = t_kind(ccx.tcx, t_in);
- auto k_out = t_kind(ccx.tcx, t_out);
- auto s_in = k_in == integral && ty::type_is_signed(ccx.tcx, t_in);
-
- auto newval = alt rec(in=k_in, out=k_out) {
- {in: integral, out: integral} {
- int_cast(e_res.bcx, ll_t_out, ll_t_in, e_res.val, s_in)
- }
- {in: float, out: float} {
- float_cast(e_res.bcx, ll_t_out, ll_t_in, e_res.val)
- }
- {in: integral, out: float} {
- if s_in { e_res.bcx.build.SIToFP(e_res.val, ll_t_out) }
- else { e_res.bcx.build.UIToFP(e_res.val, ll_t_out) }
- }
- {in: float, out: integral} {
- if ty::type_is_signed(ccx.tcx, t_out) {
- e_res.bcx.build.FPToSI(e_res.val, ll_t_out)
- } else { e_res.bcx.build.FPToUI(e_res.val, ll_t_out) }
- }
- {in: integral, out: native_} {
- e_res.bcx.build.IntToPtr(e_res.val, ll_t_out)
- }
- {in: native_, out: integral} {
- e_res.bcx.build.PtrToInt(e_res.val, ll_t_out)
- }
- {in: native_, out: native_} {
- e_res.bcx.build.PointerCast(e_res.val, ll_t_out)
}
_ {
- ccx.sess.bug("Translating unsupported cast.")
+ ret {res: trans_expr(cx, e),
+ is_mem: false,
+ generic: none,
+ llobj: none,
+ method_ty: none};
}
- };
+ }
+}
+
+fn trans_lval(cx: &@block_ctxt, e: &@ast::expr) -> lval_result {
+ let lv = trans_lval_gen(cx, e);
+ alt lv.generic {
+ some(gi) {
+ let t = ty::expr_ty(bcx_tcx(cx), e);
+ let n_args = std::ivec::len(ty::ty_fn_args(bcx_tcx(cx), t));
+ let args = std::ivec::init_elt(none[@ast::expr], n_args);
+ let bound = trans_bind_1(lv.res.bcx, e, lv, args, e.id);
+ ret lval_val(bound.bcx, bound.val);
+ }
+ none. { ret lv; }
+ }
+}
+
+fn int_cast(bcx: &@block_ctxt, lldsttype: TypeRef, llsrctype: TypeRef,
+ llsrc: ValueRef, signed: bool) -> ValueRef {
+ let srcsz = llvm::LLVMGetIntTypeWidth(llsrctype);
+ let dstsz = llvm::LLVMGetIntTypeWidth(lldsttype);
+ ret if dstsz == srcsz {
+ bcx.build.BitCast(llsrc, lldsttype)
+ } else if (srcsz > dstsz) {
+ bcx.build.TruncOrBitCast(llsrc, lldsttype)
+ } else if (signed) {
+ bcx.build.SExtOrBitCast(llsrc, lldsttype)
+ } else { bcx.build.ZExtOrBitCast(llsrc, lldsttype) };
+}
+
+fn float_cast(bcx: &@block_ctxt, lldsttype: TypeRef, llsrctype: TypeRef,
+ llsrc: ValueRef) -> ValueRef {
+ let srcsz = lib::llvm::float_width(llsrctype);
+ let dstsz = lib::llvm::float_width(lldsttype);
+ ret if dstsz > srcsz {
+ bcx.build.FPExt(llsrc, lldsttype)
+ } else if (srcsz > dstsz) {
+ bcx.build.FPTrunc(llsrc, lldsttype)
+ } else { llsrc };
+}
+
+fn trans_cast(cx: &@block_ctxt, e: &@ast::expr, id: ast::node_id) -> result {
+ let ccx = bcx_ccx(cx);
+ let e_res = trans_expr(cx, e);
+ let ll_t_in = val_ty(e_res.val);
+ let t_in = ty::expr_ty(ccx.tcx, e);
+ let t_out = node_id_type(ccx, id);
+ let ll_t_out = type_of(ccx, e.span, t_out);
+
+ tag kind { native_; integral; float; other; }
+ fn t_kind(tcx: &ty::ctxt, t: ty::t) -> kind {
+ ret if ty::type_is_fp(tcx, t) {
+ float
+ } else if (ty::type_is_native(tcx, t)) {
+ native_
+ } else if (ty::type_is_integral(tcx, t)) {
+ integral
+ } else { other };
+ }
+ let k_in = t_kind(ccx.tcx, t_in);
+ let k_out = t_kind(ccx.tcx, t_out);
+ let s_in = k_in == integral && ty::type_is_signed(ccx.tcx, t_in);
+
+ let newval =
+ alt {in: k_in, out: k_out} {
+ {in: integral., out: integral.} {
+ int_cast(e_res.bcx, ll_t_out, ll_t_in, e_res.val, s_in)
+ }
+ {in: float., out: float.} {
+ float_cast(e_res.bcx, ll_t_out, ll_t_in, e_res.val)
+ }
+ {in: integral., out: float.} {
+ if s_in {
+ e_res.bcx.build.SIToFP(e_res.val, ll_t_out)
+ } else { e_res.bcx.build.UIToFP(e_res.val, ll_t_out) }
+ }
+ {in: float., out: integral.} {
+ if ty::type_is_signed(ccx.tcx, t_out) {
+ e_res.bcx.build.FPToSI(e_res.val, ll_t_out)
+ } else { e_res.bcx.build.FPToUI(e_res.val, ll_t_out) }
+ }
+ {in: integral., out: native_.} {
+ e_res.bcx.build.IntToPtr(e_res.val, ll_t_out)
+ }
+ {in: native_., out: integral.} {
+ e_res.bcx.build.PtrToInt(e_res.val, ll_t_out)
+ }
+ {in: native_., out: native_.} {
+ e_res.bcx.build.PointerCast(e_res.val, ll_t_out)
+ }
+ _ { ccx.sess.bug("Translating unsupported cast.") }
+ };
ret rslt(e_res.bcx, newval);
}
-fn trans_bind_thunk(&@local_ctxt cx, &span sp, &ty::t incoming_fty,
- &ty::t outgoing_fty, &(option::t[@ast::expr])[] args,
- &ty::t closure_ty, &ty::t[] bound_tys,
- uint ty_param_count) -> ValueRef {
+fn trans_bind_thunk(cx: &@local_ctxt, sp: &span, incoming_fty: &ty::t,
+ outgoing_fty: &ty::t, args: &(option::t[@ast::expr])[],
+ closure_ty: &ty::t, bound_tys: &ty::t[],
+ ty_param_count: uint) -> ValueRef {
// Here we're not necessarily constructing a thunk in the sense of
// "function with no arguments". The result of compiling 'bind f(foo,
@@ -4455,23 +4380,23 @@
// construct and return that thunk.
// Give the thunk a name, type, and value.
- let str s =
+ let s: str =
mangle_internal_name_by_path_and_seq(cx.ccx, cx.path, "thunk");
- let TypeRef llthunk_ty =
+ let llthunk_ty: TypeRef =
get_pair_fn_ty(type_of(cx.ccx, sp, incoming_fty));
- let ValueRef llthunk =
+ let llthunk: ValueRef =
decl_internal_fastcall_fn(cx.ccx.llmod, s, llthunk_ty);
// Create a new function context and block context for the thunk, and hold
// onto a pointer to the first block in the function for later use.
- auto fcx = new_fn_ctxt(cx, sp, llthunk);
- auto bcx = new_top_block_ctxt(fcx);
- auto lltop = bcx.llbb;
+ let fcx = new_fn_ctxt(cx, sp, llthunk);
+ let bcx = new_top_block_ctxt(fcx);
+ let lltop = bcx.llbb;
// Since we might need to construct derived tydescs that depend on
// our bound tydescs, we need to load tydescs out of the environment
// before derived tydescs are constructed. To do this, we load them
// in the copy_args block.
- auto copy_args_bcx = new_raw_block_ctxt(fcx, fcx.llcopyargs);
+ let copy_args_bcx = new_raw_block_ctxt(fcx, fcx.llcopyargs);
// The 'llenv' that will arrive in the thunk we're creating is an
// environment that will contain the values of its arguments and a pointer
@@ -4479,123 +4404,123 @@
// The llenv pointer needs to be the correct size. That size is
// 'closure_ty', which was determined by trans_bind.
- auto llclosure_ptr_ty =
+ let llclosure_ptr_ty =
type_of(cx.ccx, sp, ty::mk_imm_box(cx.ccx.tcx, closure_ty));
- auto llclosure = copy_args_bcx.build.PointerCast(fcx.llenv,
- llclosure_ptr_ty);
+ let llclosure =
+ copy_args_bcx.build.PointerCast(fcx.llenv, llclosure_ptr_ty);
// "target", in this context, means the function that's having some of its
// arguments bound and that will be called inside the thunk we're
// creating. (In our running example, target is the function f.) Pick
// out the pointer to the target function from the environment.
- auto lltarget =
+ let lltarget =
GEP_tup_like(bcx, closure_ty, llclosure,
~[0, abi::box_rc_field_body, abi::closure_elt_target]);
bcx = lltarget.bcx;
// And then, pick out the target function's own environment. That's what
// we'll use as the environment the thunk gets.
- auto lltargetclosure =
+ let lltargetclosure =
bcx.build.GEP(lltarget.val, ~[C_int(0), C_int(abi::fn_field_box)]);
lltargetclosure = bcx.build.Load(lltargetclosure);
// Get f's return type, which will also be the return type of the entire
// bind expression.
- auto outgoing_ret_ty = ty::ty_fn_ret(cx.ccx.tcx, outgoing_fty);
+ let outgoing_ret_ty = ty::ty_fn_ret(cx.ccx.tcx, outgoing_fty);
// Get the types of the arguments to f.
- auto outgoing_args = ty::ty_fn_args(cx.ccx.tcx, outgoing_fty);
+ let outgoing_args = ty::ty_fn_args(cx.ccx.tcx, outgoing_fty);
// The 'llretptr' that will arrive in the thunk we're creating also needs
// to be the correct size. Cast it to the size of f's return type, if
// necessary.
- auto llretptr = fcx.llretptr;
- if (ty::type_has_dynamic_size(cx.ccx.tcx, outgoing_ret_ty)) {
+ let llretptr = fcx.llretptr;
+ if ty::type_has_dynamic_size(cx.ccx.tcx, outgoing_ret_ty) {
llretptr = bcx.build.PointerCast(llretptr, T_typaram_ptr(cx.ccx.tn));
}
// Set up the three implicit arguments to the thunk.
- let ValueRef[] llargs = ~[llretptr, fcx.lltaskptr, lltargetclosure];
+ let llargs: ValueRef[] = ~[llretptr, fcx.lltaskptr, lltargetclosure];
// Copy in the type parameters.
- let uint i = 0u;
- while (i < ty_param_count) {
- auto lltyparam_ptr =
+ let i: uint = 0u;
+ while i < ty_param_count {
+ let lltyparam_ptr =
GEP_tup_like(copy_args_bcx, closure_ty, llclosure,
~[0, abi::box_rc_field_body,
abi::closure_elt_ty_params, i as int]);
copy_args_bcx = lltyparam_ptr.bcx;
- auto td = copy_args_bcx.build.Load(lltyparam_ptr.val);
+ let td = copy_args_bcx.build.Load(lltyparam_ptr.val);
llargs += ~[td];
fcx.lltydescs += ~[td];
i += 1u;
}
- let uint a = 3u; // retptr, task ptr, env come first
+ let a: uint = 3u; // retptr, task ptr, env come first
- let int b = 0;
- let uint outgoing_arg_index = 0u;
- let TypeRef[] llout_arg_tys =
+ let b: int = 0;
+ let outgoing_arg_index: uint = 0u;
+ let llout_arg_tys: TypeRef[] =
type_of_explicit_args(cx.ccx, sp, outgoing_args);
- for (option::t[@ast::expr] arg in args) {
- auto out_arg = outgoing_args.(outgoing_arg_index);
- auto llout_arg_ty = llout_arg_tys.(outgoing_arg_index);
- alt (arg) {
- // Arg provided at binding time; thunk copies it from
- // closure.
- case (some(?e)) {
- auto e_ty = ty::expr_ty(cx.ccx.tcx, e);
- auto bound_arg =
- GEP_tup_like(bcx, closure_ty, llclosure,
- ~[0, abi::box_rc_field_body,
- abi::closure_elt_bindings, b]);
- bcx = bound_arg.bcx;
- auto val = bound_arg.val;
- if (out_arg.mode == ty::mo_val) {
- if (type_is_immediate(cx.ccx, e_ty)) {
- val = bcx.build.Load(val);
- bcx = copy_ty(bcx, val, e_ty).bcx;
- } else {
- bcx = copy_ty(bcx, val, e_ty).bcx;
- val = bcx.build.Load(val);
- }
+ for arg: option::t[@ast::expr] in args {
+ let out_arg = outgoing_args.(outgoing_arg_index);
+ let llout_arg_ty = llout_arg_tys.(outgoing_arg_index);
+ alt arg {
+
+ // Arg provided at binding time; thunk copies it from
+ // closure.
+ some(e) {
+ let e_ty = ty::expr_ty(cx.ccx.tcx, e);
+ let bound_arg =
+ GEP_tup_like(bcx, closure_ty, llclosure,
+ ~[0, abi::box_rc_field_body,
+ abi::closure_elt_bindings, b]);
+ bcx = bound_arg.bcx;
+ let val = bound_arg.val;
+ if out_arg.mode == ty::mo_val {
+ if type_is_immediate(cx.ccx, e_ty) {
+ val = bcx.build.Load(val);
+ bcx = copy_ty(bcx, val, e_ty).bcx;
+ } else {
+ bcx = copy_ty(bcx, val, e_ty).bcx;
+ val = bcx.build.Load(val);
}
- // If the type is parameterized, then we need to cast the
- // type we actually have to the parameterized out type.
- if (ty::type_contains_params(cx.ccx.tcx, out_arg.ty)) {
- // FIXME: (#642) This works for boxes and alias params
- // but does not work for bare functions.
- val = bcx.build.PointerCast(val, llout_arg_ty);
- }
- llargs += ~[val];
- b += 1;
}
- case (
- // Arg will be provided when the thunk is invoked.
- none) {
- let ValueRef passed_arg = llvm::LLVMGetParam(llthunk, a);
- if (ty::type_contains_params(cx.ccx.tcx, out_arg.ty)) {
- assert (out_arg.mode != ty::mo_val);
- passed_arg =
- bcx.build.PointerCast(passed_arg, llout_arg_ty);
- }
- llargs += ~[passed_arg];
- a += 1u;
+ // If the type is parameterized, then we need to cast the
+ // type we actually have to the parameterized out type.
+ if ty::type_contains_params(cx.ccx.tcx, out_arg.ty) {
+ // FIXME: (#642) This works for boxes and alias params
+ // but does not work for bare functions.
+ val = bcx.build.PointerCast(val, llout_arg_ty);
}
+ llargs += ~[val];
+ b += 1;
+ }
+
+ // Arg will be provided when the thunk is invoked.
+ none. {
+ let passed_arg: ValueRef = llvm::LLVMGetParam(llthunk, a);
+ if ty::type_contains_params(cx.ccx.tcx, out_arg.ty) {
+ assert (out_arg.mode != ty::mo_val);
+ passed_arg = bcx.build.PointerCast(passed_arg, llout_arg_ty);
+ }
+ llargs += ~[passed_arg];
+ a += 1u;
+ }
}
outgoing_arg_index += 1u;
}
// FIXME: turn this call + ret into a tail call.
- auto lltargetfn =
+ let lltargetfn =
bcx.build.GEP(lltarget.val, ~[C_int(0), C_int(abi::fn_field_code)]);
// Cast the outgoing function to the appropriate type (see the comments in
// trans_bind below for why this is necessary).
- auto lltargetty =
+ let lltargetty =
type_of_fn(bcx_ccx(bcx), sp,
- ty::ty_fn_proto(bcx_tcx(bcx), outgoing_fty),
- outgoing_args, outgoing_ret_ty, ty_param_count);
+ ty::ty_fn_proto(bcx_tcx(bcx), outgoing_fty), outgoing_args,
+ outgoing_ret_ty, ty_param_count);
lltargetfn = bcx.build.PointerCast(lltargetfn, T_ptr(T_ptr(lltargetty)));
lltargetfn = bcx.build.Load(lltargetfn);
bcx.build.FastCall(lltargetfn, llargs);
@@ -4604,55 +4529,50 @@
ret llthunk;
}
-fn trans_bind(&@block_ctxt cx, &@ast::expr f,
- &(option::t[@ast::expr])[] args, ast::node_id id) -> result {
- auto f_res = trans_lval_gen(cx, f);
+fn trans_bind(cx: &@block_ctxt, f: &@ast::expr,
+ args: &(option::t[@ast::expr])[], id: ast::node_id) -> result {
+ let f_res = trans_lval_gen(cx, f);
ret trans_bind_1(cx, f, f_res, args, id);
}
-fn trans_bind_1(&@block_ctxt cx, &@ast::expr f, &lval_result f_res,
- &(option::t[@ast::expr])[] args, ast::node_id id) -> result {
- if (f_res.is_mem) {
+fn trans_bind_1(cx: &@block_ctxt, f: &@ast::expr, f_res: &lval_result,
+ args: &(option::t[@ast::expr])[], id: ast::node_id) ->
+ result {
+ if f_res.is_mem {
bcx_ccx(cx).sess.unimpl("re-binding existing function");
}
- let (@ast::expr)[] bound = ~[];
- for (option::t[@ast::expr] argopt in args) {
- alt (argopt) {
- case (none) { }
- case (some(?e)) { bound += ~[e]; }
- }
+ let bound: (@ast::expr)[] = ~[];
+ for argopt: option::t[@ast::expr] in args {
+ alt argopt { none. { } some(e) { bound += ~[e]; } }
}
// Figure out which tydescs we need to pass, if any.
- let ty::t outgoing_fty;
- let ValueRef[] lltydescs;
- alt (f_res.generic) {
- case (none) {
- outgoing_fty = ty::expr_ty(bcx_tcx(cx), f);
- lltydescs = ~[];
- }
- case (some(?ginfo)) {
+ let outgoing_fty: ty::t;
+ let lltydescs: ValueRef[];
+ alt f_res.generic {
+ none. { outgoing_fty = ty::expr_ty(bcx_tcx(cx), f); lltydescs = ~[]; }
+ some(ginfo) {
lazily_emit_all_generic_info_tydesc_glues(cx, ginfo);
outgoing_fty = ginfo.item_type;
lltydescs = ginfo.tydescs;
}
}
- auto ty_param_count = std::ivec::len[ValueRef](lltydescs);
- if (std::ivec::len[@ast::expr](bound) == 0u && ty_param_count == 0u) {
+ let ty_param_count = std::ivec::len[ValueRef](lltydescs);
+ if std::ivec::len[@ast::expr](bound) == 0u && ty_param_count == 0u {
// Trivial 'binding': just return the static pair-ptr.
ret f_res.res;
}
- auto bcx = f_res.res.bcx;
- auto pair_t = node_type(bcx_ccx(cx), cx.sp, id);
- auto pair_v = alloca(bcx, pair_t);
+ let bcx = f_res.res.bcx;
+ let pair_t = node_type(bcx_ccx(cx), cx.sp, id);
+ let pair_v = alloca(bcx, pair_t);
// Translate the bound expressions.
- let ty::t[] bound_tys = ~[];
- let lval_result[] bound_vals = ~[];
- for (@ast::expr e in bound) {
- auto lv = trans_lval(bcx, e);
+ let bound_tys: ty::t[] = ~[];
+ let bound_vals: lval_result[] = ~[];
+ for e: @ast::expr in bound {
+ let lv = trans_lval(bcx, e);
bcx = lv.res.bcx;
bound_vals += ~[lv];
bound_tys += ~[ty::expr_ty(bcx_tcx(cx), e)];
@@ -4664,7 +4584,7 @@
// bound expressions.
// bindings_ty = ~[bound_ty1, bound_ty2, ...]
- let ty::t bindings_ty = ty::mk_imm_tup(bcx_tcx(cx), bound_tys);
+ let bindings_ty: ty::t = ty::mk_imm_tup(bcx_tcx(cx), bound_tys);
// NB: keep this in sync with T_closure_ptr; we're making
// a ty::t structure that has the same "shape" as the LLVM type
@@ -4672,8 +4592,9 @@
// Make a vector that contains ty_param_count copies of tydesc_ty.
// (We'll need room for that many tydescs in the closure.)
- let ty::t tydesc_ty = ty::mk_type(bcx_tcx(cx));
- let ty::t[] captured_tys = std::ivec::init_elt(tydesc_ty, ty_param_count);
+ let tydesc_ty: ty::t = ty::mk_type(bcx_tcx(cx));
+ let captured_tys: ty::t[] =
+ std::ivec::init_elt(tydesc_ty, ty_param_count);
// Get all the types we've got (some of which we synthesized
// ourselves) into a vector. The whole things ends up looking
@@ -4681,32 +4602,30 @@
// closure_tys = [tydesc_ty, outgoing_fty, [bound_ty1, bound_ty2,
// ...], [tydesc_ty, tydesc_ty, ...]]
- let ty::t[] closure_tys =
+ let closure_tys: ty::t[] =
~[tydesc_ty, outgoing_fty, bindings_ty,
ty::mk_imm_tup(bcx_tcx(cx), captured_tys)];
// Finally, synthesize a type for that whole vector.
- let ty::t closure_ty =
- ty::mk_imm_tup(bcx_tcx(cx), closure_tys);
+ let closure_ty: ty::t = ty::mk_imm_tup(bcx_tcx(cx), closure_tys);
// Allocate a box that can hold something closure-sized, including
// space for a refcount.
- auto r = trans_malloc_boxed(bcx, closure_ty);
- auto box = r.val;
+ let r = trans_malloc_boxed(bcx, closure_ty);
+ let box = r.val;
bcx = r.bcx;
// Grab onto the refcount and body parts of the box we allocated.
- auto rc =
- bcx.build.GEP(box, ~[C_int(0), C_int(abi::box_rc_field_refcnt)]);
- auto closure =
+ let rc = bcx.build.GEP(box, ~[C_int(0), C_int(abi::box_rc_field_refcnt)]);
+ let closure =
bcx.build.GEP(box, ~[C_int(0), C_int(abi::box_rc_field_body)]);
bcx.build.Store(C_int(1), rc);
// Store bindings tydesc.
- auto bound_tydesc =
+ let bound_tydesc =
bcx.build.GEP(closure, ~[C_int(0), C_int(abi::closure_elt_tydesc)]);
- auto ti = none;
- auto bindings_tydesc = get_tydesc(bcx, bindings_ty, true, ti);
+ let ti = none;
+ let bindings_tydesc = get_tydesc(bcx, bindings_ty, true, ti);
lazily_emit_tydesc_glue(bcx, abi::tydesc_field_drop_glue, ti);
lazily_emit_tydesc_glue(bcx, abi::tydesc_field_free_glue, ti);
bcx = bindings_tydesc.bcx;
@@ -4718,46 +4637,43 @@
// specifically, we know how many type descriptors the outgoing
// function has, which type_of() doesn't, as only we know which
// item the function refers to.
- auto llfnty =
+ let llfnty =
type_of_fn(bcx_ccx(bcx), cx.sp,
ty::ty_fn_proto(bcx_tcx(bcx), outgoing_fty),
ty::ty_fn_args(bcx_tcx(bcx), outgoing_fty),
- ty::ty_fn_ret(bcx_tcx(bcx), outgoing_fty),
- ty_param_count);
- auto llclosurety = T_ptr(T_fn_pair(*bcx_ccx(bcx), llfnty));
+ ty::ty_fn_ret(bcx_tcx(bcx), outgoing_fty), ty_param_count);
+ let llclosurety = T_ptr(T_fn_pair(*bcx_ccx(bcx), llfnty));
// Store thunk-target.
- auto bound_target =
+ let bound_target =
bcx.build.GEP(closure, ~[C_int(0), C_int(abi::closure_elt_target)]);
- auto src = bcx.build.Load(f_res.res.val);
+ let src = bcx.build.Load(f_res.res.val);
bound_target = bcx.build.PointerCast(bound_target, llclosurety);
bcx.build.Store(src, bound_target);
// Copy expr values into boxed bindings.
- auto i = 0u;
- auto bindings =
- bcx.build.GEP(closure,
- ~[C_int(0), C_int(abi::closure_elt_bindings)]);
- for (lval_result lv in bound_vals) {
- auto bound =
- bcx.build.GEP(bindings, ~[C_int(0), C_int(i as int)]);
+ let i = 0u;
+ let bindings =
+ bcx.build.GEP(closure, ~[C_int(0), C_int(abi::closure_elt_bindings)]);
+ for lv: lval_result in bound_vals {
+ let bound = bcx.build.GEP(bindings, ~[C_int(0), C_int(i as int)]);
bcx = move_val_if_temp(bcx, INIT, bound, lv, bound_tys.(i)).bcx;
i += 1u;
}
// If necessary, copy tydescs describing type parameters into the
// appropriate slot in the closure.
- alt (f_res.generic) {
- case (none) {/* nothing to do */ }
- case (some(?ginfo)) {
+ alt f_res.generic {
+ none. {/* nothing to do */ }
+ some(ginfo) {
lazily_emit_all_generic_info_tydesc_glues(cx, ginfo);
- auto ty_params_slot =
+ let ty_params_slot =
bcx.build.GEP(closure,
~[C_int(0), C_int(abi::closure_elt_ty_params)]);
- auto i = 0;
- for (ValueRef td in ginfo.tydescs) {
- auto ty_param_slot = bcx.build.GEP(ty_params_slot,
- ~[C_int(0), C_int(i)]);
+ let i = 0;
+ for td: ValueRef in ginfo.tydescs {
+ let ty_param_slot =
+ bcx.build.GEP(ty_params_slot, ~[C_int(0), C_int(i)]);
bcx.build.Store(td, ty_param_slot);
i += 1;
}
@@ -4766,44 +4682,43 @@
}
// Make thunk and store thunk-ptr in outer pair's code slot.
- auto pair_code =
+ let pair_code =
bcx.build.GEP(pair_v, ~[C_int(0), C_int(abi::fn_field_code)]);
// The type of the entire bind expression.
- let ty::t pair_ty = node_id_type(bcx_ccx(cx), id);
+ let pair_ty: ty::t = node_id_type(bcx_ccx(cx), id);
- let ValueRef llthunk =
- trans_bind_thunk(cx.fcx.lcx, cx.sp, pair_ty, outgoing_fty,
- args, closure_ty, bound_tys, ty_param_count);
+ let llthunk: ValueRef =
+ trans_bind_thunk(cx.fcx.lcx, cx.sp, pair_ty, outgoing_fty, args,
+ closure_ty, bound_tys, ty_param_count);
bcx.build.Store(llthunk, pair_code);
// Store box ptr in outer pair's box slot.
- auto ccx = *bcx_ccx(bcx);
- auto pair_box =
+ let ccx = *bcx_ccx(bcx);
+ let pair_box =
bcx.build.GEP(pair_v, ~[C_int(0), C_int(abi::fn_field_box)]);
- bcx.build.Store(
- bcx.build.PointerCast(box, T_opaque_closure_ptr(ccx)),
- pair_box);
+ bcx.build.Store(bcx.build.PointerCast(box, T_opaque_closure_ptr(ccx)),
+ pair_box);
add_clean_temp(cx, pair_v, pair_ty);
ret rslt(bcx, pair_v);
}
-fn trans_arg_expr(&@block_ctxt cx, &ty::arg arg, TypeRef lldestty0,
- &@ast::expr e) -> result {
- auto ccx = bcx_ccx(cx);
- auto e_ty = ty::expr_ty(ccx.tcx, e);
- auto is_bot = ty::type_is_bot(ccx.tcx, e_ty);
- auto lv = trans_lval(cx, e);
- auto bcx = lv.res.bcx;
- auto val = lv.res.val;
- if (is_bot) {
+fn trans_arg_expr(cx: &@block_ctxt, arg: &ty::arg, lldestty0: TypeRef,
+ e: &@ast::expr) -> result {
+ let ccx = bcx_ccx(cx);
+ let e_ty = ty::expr_ty(ccx.tcx, e);
+ let is_bot = ty::type_is_bot(ccx.tcx, e_ty);
+ let lv = trans_lval(cx, e);
+ let bcx = lv.res.bcx;
+ let val = lv.res.val;
+ if is_bot {
// For values of type _|_, we generate an
// "undef" value, as such a value should never
// be inspected. It's important for the value
// to have type lldestty0 (the callee's expected type).
val = llvm::LLVMGetUndef(lldestty0);
} else if (arg.mode == ty::mo_val) {
- if (ty::type_owns_heap_mem(ccx.tcx, e_ty)) {
- auto dst = alloc_ty(bcx, e_ty);
+ if ty::type_owns_heap_mem(ccx.tcx, e_ty) {
+ let dst = alloc_ty(bcx, e_ty);
val = dst.val;
bcx = move_val_if_temp(dst.bcx, INIT, val, lv, e_ty).bcx;
} else if (lv.is_mem) {
@@ -4814,30 +4729,30 @@
// corrupts memory. I can't figure out why, and external vectors
// are on the way out anyway, so this simply turns off the
// optimization for that case.
- auto is_ext_vec_plus = alt (e.node) {
- case (ast::expr_binary(_, _, _)) {
+ let is_ext_vec_plus =
+ alt e.node {
+ ast::expr_binary(_, _, _) {
ty::type_is_sequence(ccx.tcx, e_ty) &&
- !ty::sequence_is_interior(ccx.tcx, e_ty)
- }
- case (_) { false }
- };
- if (is_ext_vec_plus) { bcx = copy_ty(bcx, val, e_ty).bcx; }
- else { revoke_clean(bcx, val); }
+ !ty::sequence_is_interior(ccx.tcx, e_ty)
+ }
+ _ { false }
+ };
+ if is_ext_vec_plus {
+ bcx = copy_ty(bcx, val, e_ty).bcx;
+ } else { revoke_clean(bcx, val); }
}
} else if (type_is_immediate(ccx, e_ty) && !lv.is_mem) {
val = do_spill(bcx, val);
}
- if (!is_bot && ty::type_contains_params(ccx.tcx, arg.ty)) {
- auto lldestty = lldestty0;
- if (arg.mode == ty::mo_val
- && ty::type_is_structural(ccx.tcx, e_ty)) {
+ if !is_bot && ty::type_contains_params(ccx.tcx, arg.ty) {
+ let lldestty = lldestty0;
+ if arg.mode == ty::mo_val && ty::type_is_structural(ccx.tcx, e_ty) {
lldestty = T_ptr(lldestty);
}
val = bcx.build.PointerCast(val, lldestty);
}
- if (arg.mode == ty::mo_val
- && ty::type_is_structural(ccx.tcx, e_ty)) {
+ if arg.mode == ty::mo_val && ty::type_is_structural(ccx.tcx, e_ty) {
// Until here we've been treating structures by pointer;
// we are now passing it as an arg, so need to load it.
val = bcx.build.Load(val);
@@ -4852,38 +4767,38 @@
// - create_llargs_for_fn_args.
// - new_fn_ctxt
// - trans_args
-fn trans_args(&@block_ctxt cx, ValueRef llenv, &option::t[ValueRef] llobj,
- &option::t[generic_info] gen, &option::t[ValueRef] lliterbody,
- &(@ast::expr)[] es, &ty::t fn_ty)
- -> rec(@block_ctxt bcx, ValueRef[] args, ValueRef retslot) {
- let ty::arg[] args = ty::ty_fn_args(bcx_tcx(cx), fn_ty);
- let ValueRef[] llargs = ~[];
- let ValueRef[] lltydescs = ~[];
- let @block_ctxt bcx = cx;
+fn trans_args(cx: &@block_ctxt, llenv: ValueRef, llobj: &option::t[ValueRef],
+ gen: &option::t[generic_info], lliterbody: &option::t[ValueRef],
+ es: &(@ast::expr)[], fn_ty: &ty::t) ->
+ {bcx: @block_ctxt, args: ValueRef[], retslot: ValueRef} {
+ let args: ty::arg[] = ty::ty_fn_args(bcx_tcx(cx), fn_ty);
+ let llargs: ValueRef[] = ~[];
+ let lltydescs: ValueRef[] = ~[];
+ let bcx: @block_ctxt = cx;
// Arg 0: Output pointer.
// FIXME: test case looks like
// f(1, fail, @42);
- if (bcx.build.is_terminated()) {
+ if bcx.build.is_terminated() {
// This means an earlier arg was divergent.
// So this arg can't be evaluated.
- ret rec(bcx=bcx, args=~[], retslot=C_nil());
+ ret {bcx: bcx, args: ~[], retslot: C_nil()};
}
- auto retty = ty::ty_fn_ret(bcx_tcx(cx), fn_ty);
- auto llretslot_res = alloc_ty(bcx, retty);
+ let retty = ty::ty_fn_ret(bcx_tcx(cx), fn_ty);
+ let llretslot_res = alloc_ty(bcx, retty);
bcx = llretslot_res.bcx;
- auto llretslot = llretslot_res.val;
- alt (gen) {
- case (some(?g)) {
- lazily_emit_all_generic_info_tydesc_glues(cx, g);
- lltydescs = g.tydescs;
- args = ty::ty_fn_args(bcx_tcx(cx), g.item_type);
- retty = ty::ty_fn_ret(bcx_tcx(cx), g.item_type);
- }
- case (_) { }
+ let llretslot = llretslot_res.val;
+ alt gen {
+ some(g) {
+ lazily_emit_all_generic_info_tydesc_glues(cx, g);
+ lltydescs = g.tydescs;
+ args = ty::ty_fn_args(bcx_tcx(cx), g.item_type);
+ retty = ty::ty_fn_ret(bcx_tcx(cx), g.item_type);
+ }
+ _ { }
}
- if (ty::type_has_dynamic_size(bcx_tcx(cx), retty)) {
+ if ty::type_has_dynamic_size(bcx_tcx(cx), retty) {
llargs +=
~[bcx.build.PointerCast(llretslot,
T_typaram_ptr(bcx_ccx(cx).tn))];
@@ -4904,101 +4819,96 @@
llargs += ~[bcx.fcx.lltaskptr];
// Arg 2: Env (closure-bindings / self-obj)
- alt (llobj) {
- case (some(?ob)) {
- // Every object is always found in memory,
- // and not-yet-loaded (as part of an lval x.y
- // doted method-call).
+ alt llobj {
+ some(ob) {
+ // Every object is always found in memory,
+ // and not-yet-loaded (as part of an lval x.y
+ // doted method-call).
- llargs += ~[bcx.build.Load(ob)];
- }
- case (_) { llargs += ~[llenv]; }
+ llargs += ~[bcx.build.Load(ob)];
+ }
+ _ { llargs += ~[llenv]; }
}
// Args >3: ty_params ...
llargs += lltydescs;
// ... then possibly an lliterbody argument.
- alt (lliterbody) {
- case (none) { }
- case (some(?lli)) { llargs += ~[lli]; }
- }
+ alt lliterbody { none. { } some(lli) { llargs += ~[lli]; } }
// ... then explicit args.
// First we figure out the caller's view of the types of the arguments.
// This will be needed if this is a generic call, because the callee has
// to cast her view of the arguments to the caller's view.
- auto arg_tys = type_of_explicit_args(bcx_ccx(cx), cx.sp, args);
- auto i = 0u;
- for (@ast::expr e in es) {
- if (bcx.build.is_terminated()) {
+ let arg_tys = type_of_explicit_args(bcx_ccx(cx), cx.sp, args);
+ let i = 0u;
+ for e: @ast::expr in es {
+ if bcx.build.is_terminated() {
// This means an earlier arg was divergent.
// So this arg can't be evaluated.
break;
}
- auto r = trans_arg_expr(bcx, args.(i), arg_tys.(i), e);
+ let r = trans_arg_expr(bcx, args.(i), arg_tys.(i), e);
bcx = r.bcx;
llargs += ~[r.val];
i += 1u;
}
- ret rec(bcx=bcx, args=llargs, retslot=llretslot);
+ ret {bcx: bcx, args: llargs, retslot: llretslot};
}
-fn trans_call(&@block_ctxt cx, &@ast::expr f, &option::t[ValueRef] lliterbody,
- &(@ast::expr)[] args, ast::node_id id) -> result {
+fn trans_call(cx: &@block_ctxt, f: &@ast::expr,
+ lliterbody: &option::t[ValueRef], args: &(@ast::expr)[],
+ id: ast::node_id) -> result {
// NB: 'f' isn't necessarily a function; it might be an entire self-call
// expression because of the hack that allows us to process self-calls
// with trans_call.
- auto f_res = trans_lval_gen(cx, f);
- let ty::t fn_ty;
- alt (f_res.method_ty) {
- case (some(?meth)) {
- // self-call
- fn_ty = meth;
- }
- case (_) {
- fn_ty = ty::expr_ty(bcx_tcx(cx), f);
- }
+ let f_res = trans_lval_gen(cx, f);
+ let fn_ty: ty::t;
+ alt f_res.method_ty {
+ some(meth) {
+ // self-call
+ fn_ty = meth;
+ }
+ _ { fn_ty = ty::expr_ty(bcx_tcx(cx), f); }
}
- auto bcx = f_res.res.bcx;
+ let bcx = f_res.res.bcx;
- auto faddr = f_res.res.val;
- auto llenv = C_null(T_opaque_closure_ptr(*bcx_ccx(cx)));
- alt (f_res.llobj) {
- case (some(_)) {
- // It's a vtbl entry.
- faddr = bcx.build.Load(faddr);
- }
- case (none) {
- // It's a closure. We have to autoderef.
- if (f_res.is_mem) { faddr = load_if_immediate(bcx, faddr, fn_ty);}
- auto res = autoderef(bcx, faddr, fn_ty);
- bcx = res.bcx;
- fn_ty = res.ty;
+ let faddr = f_res.res.val;
+ let llenv = C_null(T_opaque_closure_ptr(*bcx_ccx(cx)));
+ alt f_res.llobj {
+ some(_) {
+ // It's a vtbl entry.
+ faddr = bcx.build.Load(faddr);
+ }
+ none. {
+ // It's a closure. We have to autoderef.
+ if f_res.is_mem { faddr = load_if_immediate(bcx, faddr, fn_ty); }
+ let res = autoderef(bcx, faddr, fn_ty);
+ bcx = res.bcx;
+ fn_ty = res.ty;
- auto pair = res.val;
- faddr =
- bcx.build.GEP(pair, ~[C_int(0), C_int(abi::fn_field_code)]);
- faddr = bcx.build.Load(faddr);
- auto llclosure =
- bcx.build.GEP(pair, ~[C_int(0), C_int(abi::fn_field_box)]);
- llenv = bcx.build.Load(llclosure);
- }
+ let pair = res.val;
+ faddr = bcx.build.GEP(pair, ~[C_int(0), C_int(abi::fn_field_code)]);
+ faddr = bcx.build.Load(faddr);
+ let llclosure =
+ bcx.build.GEP(pair, ~[C_int(0), C_int(abi::fn_field_box)]);
+ llenv = bcx.build.Load(llclosure);
+ }
}
- auto ret_ty = ty::node_id_to_type(bcx_tcx(cx), id);
- auto args_res =
- trans_args(bcx, llenv, f_res.llobj, f_res.generic,
- lliterbody, args, fn_ty);
+ let ret_ty = ty::node_id_to_type(bcx_tcx(cx), id);
+ let args_res =
+ trans_args(bcx, llenv, f_res.llobj, f_res.generic, lliterbody, args,
+ fn_ty);
bcx = args_res.bcx;
- auto llargs = args_res.args;
- auto llretslot = args_res.retslot;
+ let llargs = args_res.args;
+ let llretslot = args_res.retslot;
/*
log "calling: " + val_str(bcx_ccx(cx).tn, faddr);
-
+
for (ValueRef arg in llargs) {
log "arg: " + val_str(bcx_ccx(cx).tn, arg);
}
@@ -5008,61 +4918,61 @@
then one or more of the args has
type _|_. Since that means it diverges, the code
for the call itself is unreachable. */
- auto retval = C_nil();
- if (!bcx.build.is_terminated()) {
+ let retval = C_nil();
+ if !bcx.build.is_terminated() {
bcx.build.FastCall(faddr, llargs);
- alt (lliterbody) {
- case (none) {
- if (!ty::type_is_nil(bcx_tcx(cx), ret_ty)) {
- retval = load_if_immediate(bcx, llretslot, ret_ty);
- // Retval doesn't correspond to anything really tangible
- // in the frame, but it's a ref all the same, so we put a
- // note here to drop it when we're done in this scope.
- add_clean_temp(cx, retval, ret_ty);
- }
+ alt lliterbody {
+ none. {
+ if !ty::type_is_nil(bcx_tcx(cx), ret_ty) {
+ retval = load_if_immediate(bcx, llretslot, ret_ty);
+ // Retval doesn't correspond to anything really tangible
+ // in the frame, but it's a ref all the same, so we put a
+ // note here to drop it when we're done in this scope.
+ add_clean_temp(cx, retval, ret_ty);
}
- case (some(_)) {
- // If there was an lliterbody, it means we were calling an
- // iter, and we are *not* the party using its 'output' value,
- // we should ignore llretslot.
- }
+ }
+ some(_) {
+ // If there was an lliterbody, it means we were calling an
+ // iter, and we are *not* the party using its 'output' value,
+ // we should ignore llretslot.
+ }
}
}
ret rslt(bcx, retval);
}
-fn trans_vec(&@block_ctxt cx, &(@ast::expr)[] args, ast::node_id id) ->
+fn trans_vec(cx: &@block_ctxt, args: &(@ast::expr)[], id: ast::node_id) ->
result {
- auto t = node_id_type(bcx_ccx(cx), id);
- auto unit_ty = t;
- alt (ty::struct(bcx_tcx(cx), t)) {
- case (ty::ty_vec(?mt)) { unit_ty = mt.ty; }
- case (_) { bcx_ccx(cx).sess.bug("non-vec type in trans_vec"); }
+ let t = node_id_type(bcx_ccx(cx), id);
+ let unit_ty = t;
+ alt ty::struct(bcx_tcx(cx), t) {
+ ty::ty_vec(mt) { unit_ty = mt.ty; }
+ _ { bcx_ccx(cx).sess.bug("non-vec type in trans_vec"); }
}
- auto bcx = cx;
- auto unit_sz = size_of(bcx, unit_ty);
+ let bcx = cx;
+ let unit_sz = size_of(bcx, unit_ty);
bcx = unit_sz.bcx;
- auto data_sz =
+ let data_sz =
bcx.build.Mul(C_uint(std::ivec::len[@ast::expr](args)), unit_sz.val);
// FIXME: pass tydesc properly.
- auto vec_val =
+ let vec_val =
bcx.build.Call(bcx_ccx(bcx).upcalls.new_vec,
~[bcx.fcx.lltaskptr, data_sz,
C_null(T_ptr(bcx_ccx(bcx).tydesc_type))]);
- auto llty = type_of(bcx_ccx(bcx), bcx.sp, t);
+ let llty = type_of(bcx_ccx(bcx), bcx.sp, t);
vec_val = bcx.build.PointerCast(vec_val, llty);
add_clean_temp(bcx, vec_val, t);
- auto body = bcx.build.GEP(vec_val, ~[C_int(0), C_int(abi::vec_elt_data)]);
- auto pseudo_tup_ty =
+ let body = bcx.build.GEP(vec_val, ~[C_int(0), C_int(abi::vec_elt_data)]);
+ let pseudo_tup_ty =
ty::mk_imm_tup(bcx_tcx(cx),
std::ivec::init_elt[ty::t](unit_ty,
std::ivec::len(args)));
- let int i = 0;
- for (@ast::expr e in args) {
- auto src = trans_lval(bcx, e);
+ let i: int = 0;
+ for e: @ast::expr in args {
+ let src = trans_lval(bcx, e);
bcx = src.res.bcx;
- auto dst_res = GEP_tup_like(bcx, pseudo_tup_ty, body, ~[0, i]);
+ let dst_res = GEP_tup_like(bcx, pseudo_tup_ty, body, ~[0, i]);
bcx = dst_res.bcx;
// Cast the destination type to the source type. This is needed to
// make tags work, for a subtle combination of reasons:
@@ -5076,45 +4986,45 @@
// considered boxes.
// (5) "src_res" is derived from "unit_ty", which is not behind a box.
- auto dst_val;
- if (!ty::type_has_dynamic_size(bcx_tcx(cx), unit_ty)) {
- auto llunit_ty = type_of(bcx_ccx(cx), bcx.sp, unit_ty);
+ let dst_val;
+ if !ty::type_has_dynamic_size(bcx_tcx(cx), unit_ty) {
+ let llunit_ty = type_of(bcx_ccx(cx), bcx.sp, unit_ty);
dst_val = bcx.build.PointerCast(dst_res.val, T_ptr(llunit_ty));
} else { dst_val = dst_res.val; }
bcx = move_val_if_temp(bcx, INIT, dst_val, src, unit_ty).bcx;
i += 1;
}
- auto fill = bcx.build.GEP(vec_val, ~[C_int(0), C_int(abi::vec_elt_fill)]);
+ let fill = bcx.build.GEP(vec_val, ~[C_int(0), C_int(abi::vec_elt_fill)]);
bcx.build.Store(data_sz, fill);
ret rslt(bcx, vec_val);
}
// TODO: Move me to ivec::
-fn trans_ivec(@block_ctxt bcx, &(@ast::expr)[] args, ast::node_id id) ->
- result {
- auto typ = node_id_type(bcx_ccx(bcx), id);
- auto unit_ty;
- alt (ty::struct(bcx_tcx(bcx), typ)) {
- case (ty::ty_ivec(?mt)) { unit_ty = mt.ty; }
- case (_) { bcx_ccx(bcx).sess.bug("non-ivec type in trans_ivec"); }
+fn trans_ivec(bcx: @block_ctxt, args: &(@ast::expr)[], id: ast::node_id) ->
+ result {
+ let typ = node_id_type(bcx_ccx(bcx), id);
+ let unit_ty;
+ alt ty::struct(bcx_tcx(bcx), typ) {
+ ty::ty_ivec(mt) { unit_ty = mt.ty; }
+ _ { bcx_ccx(bcx).sess.bug("non-ivec type in trans_ivec"); }
}
- auto llunitty = type_of_or_i8(bcx, unit_ty);
+ let llunitty = type_of_or_i8(bcx, unit_ty);
- auto ares = ivec::alloc(bcx, unit_ty);
+ let ares = ivec::alloc(bcx, unit_ty);
bcx = ares.bcx;
- auto llvecptr = ares.llptr;
- auto unit_sz = ares.llunitsz;
- auto llalen = ares.llalen;
+ let llvecptr = ares.llptr;
+ let unit_sz = ares.llunitsz;
+ let llalen = ares.llalen;
add_clean_temp(bcx, llvecptr, typ);
- auto lllen = bcx.build.Mul(C_uint(std::ivec::len(args)), unit_sz);
+ let lllen = bcx.build.Mul(C_uint(std::ivec::len(args)), unit_sz);
// Allocate the vector pieces and store length and allocated length.
- auto llfirsteltptr;
- if (std::ivec::len(args) > 0u &&
- std::ivec::len(args) <= abi::ivec_default_length) {
+ let llfirsteltptr;
+ if std::ivec::len(args) > 0u &&
+ std::ivec::len(args) <= abi::ivec_default_length {
// Interior case.
bcx.build.Store(lllen,
@@ -5132,14 +5042,14 @@
} else {
// Heap case.
- auto stub_z = ~[C_int(0), C_uint(abi::ivec_heap_stub_elt_zero)];
- auto stub_a = ~[C_int(0), C_uint(abi::ivec_heap_stub_elt_alen)];
- auto stub_p = ~[C_int(0), C_uint(abi::ivec_heap_stub_elt_ptr)];
- auto llstubty = T_ivec_heap(llunitty);
- auto llstubptr = bcx.build.PointerCast(llvecptr, T_ptr(llstubty));
+ let stub_z = ~[C_int(0), C_uint(abi::ivec_heap_stub_elt_zero)];
+ let stub_a = ~[C_int(0), C_uint(abi::ivec_heap_stub_elt_alen)];
+ let stub_p = ~[C_int(0), C_uint(abi::ivec_heap_stub_elt_ptr)];
+ let llstubty = T_ivec_heap(llunitty);
+ let llstubptr = bcx.build.PointerCast(llvecptr, T_ptr(llstubty));
bcx.build.Store(C_int(0), bcx.build.InBoundsGEP(llstubptr, stub_z));
- auto llheapty = T_ivec_heap_part(llunitty);
- if (std::ivec::len(args) == 0u) {
+ let llheapty = T_ivec_heap_part(llunitty);
+ if std::ivec::len(args) == 0u {
// Null heap pointer indicates a zero-length vector.
bcx.build.Store(llalen, bcx.build.InBoundsGEP(llstubptr, stub_a));
@@ -5149,13 +5059,13 @@
} else {
bcx.build.Store(lllen, bcx.build.InBoundsGEP(llstubptr, stub_a));
- auto llheapsz = bcx.build.Add(llsize_of(llheapty), lllen);
- auto rslt = trans_shared_malloc(bcx, T_ptr(llheapty), llheapsz);
+ let llheapsz = bcx.build.Add(llsize_of(llheapty), lllen);
+ let rslt = trans_shared_malloc(bcx, T_ptr(llheapty), llheapsz);
bcx = rslt.bcx;
- auto llheapptr = rslt.val;
+ let llheapptr = rslt.val;
bcx.build.Store(llheapptr,
bcx.build.InBoundsGEP(llstubptr, stub_p));
- auto heap_l = ~[C_int(0), C_uint(abi::ivec_heap_elt_len)];
+ let heap_l = ~[C_int(0), C_uint(abi::ivec_heap_elt_len)];
bcx.build.Store(lllen, bcx.build.InBoundsGEP(llheapptr, heap_l));
llfirsteltptr =
bcx.build.InBoundsGEP(llheapptr,
@@ -5166,12 +5076,12 @@
}
// Store the individual elements.
- auto i = 0u;
- for (@ast::expr e in args) {
- auto lv = trans_lval(bcx, e);
+ let i = 0u;
+ for e: @ast::expr in args {
+ let lv = trans_lval(bcx, e);
bcx = lv.res.bcx;
- auto lleltptr;
- if (ty::type_has_dynamic_size(bcx_tcx(bcx), unit_ty)) {
+ let lleltptr;
+ if ty::type_has_dynamic_size(bcx_tcx(bcx), unit_ty) {
lleltptr =
bcx.build.InBoundsGEP(llfirsteltptr,
~[bcx.build.Mul(C_uint(i), unit_sz)]);
@@ -5184,304 +5094,280 @@
ret rslt(bcx, llvecptr);
}
-fn trans_rec(&@block_ctxt cx, &ast::field[] fields,
- &option::t[@ast::expr] base, ast::node_id id) -> result {
- auto bcx = cx;
- auto t = node_id_type(bcx_ccx(bcx), id);
- auto rec_res = alloc_ty(bcx, t);
- auto rec_val = rec_res.val;
+fn trans_rec(cx: &@block_ctxt, fields: &ast::field[],
+ base: &option::t[@ast::expr], id: ast::node_id) -> result {
+ let bcx = cx;
+ let t = node_id_type(bcx_ccx(bcx), id);
+ let rec_res = alloc_ty(bcx, t);
+ let rec_val = rec_res.val;
bcx = rec_res.bcx;
add_clean_temp(cx, rec_val, t);
- let int i = 0;
- auto base_val = C_nil();
- alt (base) {
- case (none) { }
- case (some(?bexp)) {
- auto base_res = trans_expr(bcx, bexp);
- bcx = base_res.bcx;
- base_val = base_res.val;
- }
+ let i: int = 0;
+ let base_val = C_nil();
+ alt base {
+ none. { }
+ some(bexp) {
+ let base_res = trans_expr(bcx, bexp);
+ bcx = base_res.bcx;
+ base_val = base_res.val;
+ }
}
- let ty::field[] ty_fields = ~[];
- alt (ty::struct(bcx_tcx(cx), t)) {
- case (ty::ty_rec(?flds)) { ty_fields = flds; }
- }
- for (ty::field tf in ty_fields) {
- auto e_ty = tf.mt.ty;
- auto dst_res = GEP_tup_like(bcx, t, rec_val, ~[0, i]);
+ let ty_fields: ty::field[] = ~[];
+ alt ty::struct(bcx_tcx(cx), t) { ty::ty_rec(flds) { ty_fields = flds; } }
+ for tf: ty::field in ty_fields {
+ let e_ty = tf.mt.ty;
+ let dst_res = GEP_tup_like(bcx, t, rec_val, ~[0, i]);
bcx = dst_res.bcx;
- auto expr_provided = false;
- for (ast::field f in fields) {
- if (str::eq(f.node.ident, tf.ident)) {
+ let expr_provided = false;
+ for f: ast::field in fields {
+ if str::eq(f.node.ident, tf.ident) {
expr_provided = true;
- auto lv = trans_lval(bcx, f.node.expr);
- bcx = move_val_if_temp(lv.res.bcx, INIT, dst_res.val, lv,
- e_ty).bcx;
+ let lv = trans_lval(bcx, f.node.expr);
+ bcx =
+ move_val_if_temp(lv.res.bcx, INIT, dst_res.val, lv,
+ e_ty).bcx;
break;
}
}
- if (!expr_provided) {
- auto src_res = GEP_tup_like(bcx, t, base_val, ~[0, i]);
+ if !expr_provided {
+ let src_res = GEP_tup_like(bcx, t, base_val, ~[0, i]);
src_res =
rslt(src_res.bcx, load_if_immediate(bcx, src_res.val, e_ty));
- bcx = copy_val(src_res.bcx, INIT, dst_res.val, src_res.val,
- e_ty).bcx;
+ bcx =
+ copy_val(src_res.bcx, INIT, dst_res.val, src_res.val,
+ e_ty).bcx;
}
i += 1;
}
ret rslt(bcx, rec_val);
}
-fn trans_expr(&@block_ctxt cx, &@ast::expr e) -> result {
+fn trans_expr(cx: &@block_ctxt, e: &@ast::expr) -> result {
ret trans_expr_out(cx, e, return);
}
-fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output) ->
+fn trans_expr_out(cx: &@block_ctxt, e: &@ast::expr, output: out_method) ->
result {
// FIXME Fill in cx.sp
- alt (e.node) {
- case (ast::expr_lit(?lit)) { ret trans_lit(cx, *lit); }
- case (ast::expr_unary(?op, ?x)) {
- if (op != ast::deref) { ret trans_unary(cx, op, x, e.id); }
- }
- case (ast::expr_binary(?op, ?x, ?y)) {
- ret trans_binary(cx, op, x, y);
- }
- case (ast::expr_if(?cond, ?thn, ?els)) {
- ret with_out_method(bind trans_if(cx, cond, thn, els, e.id, _),
- cx, e.id, output);
- }
- case (ast::expr_if_check(?cond, ?thn, ?els)) {
- ret with_out_method(bind trans_if(cx, cond, thn, els, e.id, _),
- cx, e.id, output);
- }
- case (ast::expr_ternary(_, _, _)) {
- ret trans_expr_out(cx, ast::ternary_to_if(e), output);
- }
- case (ast::expr_for(?decl, ?seq, ?body)) {
- ret trans_for(cx, decl, seq, body);
- }
- case (ast::expr_for_each(?decl, ?seq, ?body)) {
- ret trans_for_each(cx, decl, seq, body);
- }
- case (ast::expr_while(?cond, ?body)) {
- ret trans_while(cx, cond, body);
- }
- case (ast::expr_do_while(?body, ?cond)) {
- ret trans_do_while(cx, body, cond);
- }
- case (ast::expr_alt(?expr, ?arms)) {
- ret with_out_method(bind trans_alt::trans_alt(cx, expr,
- arms, e.id, _),
- cx, e.id, output);
- }
- case (ast::expr_fn(?f)) {
- auto ccx = bcx_ccx(cx);
- let TypeRef llfnty =
- alt (ty::struct(ccx.tcx, node_id_type(ccx, e.id))) {
- case (ty::ty_fn(?proto, ?inputs, ?output, _, _)) {
- type_of_fn_full(ccx, e.span, proto, false, inputs,
- output, 0u)
- }
- };
- auto sub_cx = extend_path(cx.fcx.lcx, ccx.names.next("anon"));
- auto s = mangle_internal_name_by_path(ccx, sub_cx.path);
- auto llfn = decl_internal_fastcall_fn(ccx.llmod, s, llfnty);
-
- auto fn_res = trans_closure(some(cx), some(llfnty), sub_cx,
- e.span, f, llfn, none, ~[], e.id);
- auto fn_pair = alt (fn_res) {
- some(?fn_pair) { fn_pair }
- none { create_fn_pair(ccx, s, llfnty, llfn, false) }
+ alt e.node {
+ ast::expr_lit(lit) { ret trans_lit(cx, *lit); }
+ ast::expr_unary(op, x) {
+ if op != ast::deref { ret trans_unary(cx, op, x, e.id); }
+ }
+ ast::expr_binary(op, x, y) { ret trans_binary(cx, op, x, y); }
+ ast::expr_if(cond, thn, els) {
+ ret with_out_method(bind trans_if(cx, cond, thn, els, e.id, _), cx,
+ e.id, output);
+ }
+ ast::expr_if_check(cond, thn, els) {
+ ret with_out_method(bind trans_if(cx, cond, thn, els, e.id, _), cx,
+ e.id, output);
+ }
+ ast::expr_ternary(_, _, _) {
+ ret trans_expr_out(cx, ast::ternary_to_if(e), output);
+ }
+ ast::expr_for(decl, seq, body) { ret trans_for(cx, decl, seq, body); }
+ ast::expr_for_each(decl, seq, body) {
+ ret trans_for_each(cx, decl, seq, body);
+ }
+ ast::expr_while(cond, body) { ret trans_while(cx, cond, body); }
+ ast::expr_do_while(body, cond) { ret trans_do_while(cx, body, cond); }
+ ast::expr_alt(expr, arms) {
+ ret with_out_method(bind trans_alt::trans_alt(cx, expr, arms, e.id,
+ _), cx, e.id, output);
+ }
+ ast::expr_fn(f) {
+ let ccx = bcx_ccx(cx);
+ let llfnty: TypeRef =
+ alt ty::struct(ccx.tcx, node_id_type(ccx, e.id)) {
+ ty::ty_fn(proto, inputs, output, _, _) {
+ type_of_fn_full(ccx, e.span, proto, false, inputs, output, 0u)
+ }
};
- ret rslt(cx, fn_pair);
- }
- case (ast::expr_block(?blk)) {
- auto sub_cx = new_scope_block_ctxt(cx, "block-expr body");
- auto next_cx = new_sub_block_ctxt(cx, "next");
- auto sub =
- with_out_method(bind trans_block(sub_cx, blk, _), cx, e.id,
- output);
- cx.build.Br(sub_cx.llbb);
- sub.bcx.build.Br(next_cx.llbb);
- ret rslt(next_cx, sub.val);
- }
- case (ast::expr_move(?dst, ?src)) {
- auto lhs_res = trans_lval(cx, dst);
- assert (lhs_res.is_mem);
- // FIXME Fill in lhs_res.res.bcx.sp
+ let sub_cx = extend_path(cx.fcx.lcx, ccx.names.next("anon"));
+ let s = mangle_internal_name_by_path(ccx, sub_cx.path);
+ let llfn = decl_internal_fastcall_fn(ccx.llmod, s, llfnty);
- auto rhs_res = trans_lval(lhs_res.res.bcx, src);
- auto t = ty::expr_ty(bcx_tcx(cx), src);
- // FIXME: calculate copy init-ness in typestate.
+ let fn_res =
+ trans_closure(some(cx), some(llfnty), sub_cx, e.span, f, llfn,
+ none, ~[], e.id);
+ let fn_pair =
+ alt fn_res {
+ some(fn_pair) { fn_pair }
+ none. { create_fn_pair(ccx, s, llfnty, llfn, false) }
+ };
+ ret rslt(cx, fn_pair);
+ }
+ ast::expr_block(blk) {
+ let sub_cx = new_scope_block_ctxt(cx, "block-expr body");
+ let next_cx = new_sub_block_ctxt(cx, "next");
+ let sub =
+ with_out_method(bind trans_block(sub_cx, blk, _), cx, e.id,
+ output);
+ cx.build.Br(sub_cx.llbb);
+ sub.bcx.build.Br(next_cx.llbb);
+ ret rslt(next_cx, sub.val);
+ }
+ ast::expr_move(dst, src) {
+ let lhs_res = trans_lval(cx, dst);
+ assert (lhs_res.is_mem);
+ // FIXME Fill in lhs_res.res.bcx.sp
- auto move_res =
- move_val(rhs_res.res.bcx, DROP_EXISTING, lhs_res.res.val,
- rhs_res, t);
- ret rslt(move_res.bcx, C_nil());
- }
- case (ast::expr_assign(?dst, ?src)) {
- auto lhs_res = trans_lval(cx, dst);
- assert (lhs_res.is_mem);
- // FIXME Fill in lhs_res.res.bcx.sp
- auto rhs = trans_lval(lhs_res.res.bcx, src);
- auto t = ty::expr_ty(bcx_tcx(cx), src);
- // FIXME: calculate copy init-ness in typestate.
- auto copy_res = move_val_if_temp
- (rhs.res.bcx, DROP_EXISTING, lhs_res.res.val, rhs, t);
- ret rslt(copy_res.bcx, C_nil());
- }
- case (ast::expr_swap(?dst, ?src)) {
- auto lhs_res = trans_lval(cx, dst);
- assert (lhs_res.is_mem);
- // FIXME Fill in lhs_res.res.bcx.sp
+ let rhs_res = trans_lval(lhs_res.res.bcx, src);
+ let t = ty::expr_ty(bcx_tcx(cx), src);
+ // FIXME: calculate copy init-ness in typestate.
- auto rhs_res = trans_lval(lhs_res.res.bcx, src);
- auto t = ty::expr_ty(bcx_tcx(cx), src);
- auto tmp_res = alloc_ty(rhs_res.res.bcx, t);
- // Swap through a temporary.
+ let move_res =
+ move_val(rhs_res.res.bcx, DROP_EXISTING, lhs_res.res.val, rhs_res,
+ t);
+ ret rslt(move_res.bcx, C_nil());
+ }
+ ast::expr_assign(dst, src) {
+ let lhs_res = trans_lval(cx, dst);
+ assert (lhs_res.is_mem);
+ // FIXME Fill in lhs_res.res.bcx.sp
+ let rhs = trans_lval(lhs_res.res.bcx, src);
+ let t = ty::expr_ty(bcx_tcx(cx), src);
+ // FIXME: calculate copy init-ness in typestate.
+ let copy_res =
+ move_val_if_temp(rhs.res.bcx, DROP_EXISTING, lhs_res.res.val, rhs,
+ t);
+ ret rslt(copy_res.bcx, C_nil());
+ }
+ ast::expr_swap(dst, src) {
+ let lhs_res = trans_lval(cx, dst);
+ assert (lhs_res.is_mem);
+ // FIXME Fill in lhs_res.res.bcx.sp
- auto move1_res =
- memmove_ty(tmp_res.bcx, tmp_res.val, lhs_res.res.val, t);
- auto move2_res =
- memmove_ty(move1_res.bcx, lhs_res.res.val, rhs_res.res.val,
- t);
- auto move3_res =
- memmove_ty(move2_res.bcx, rhs_res.res.val, tmp_res.val, t);
- ret rslt(move3_res.bcx, C_nil());
- }
- case (ast::expr_assign_op(?op, ?dst, ?src)) {
- auto t = ty::expr_ty(bcx_tcx(cx), src);
- auto lhs_res = trans_lval(cx, dst);
- assert (lhs_res.is_mem);
- // FIXME Fill in lhs_res.res.bcx.sp
+ let rhs_res = trans_lval(lhs_res.res.bcx, src);
+ let t = ty::expr_ty(bcx_tcx(cx), src);
+ let tmp_res = alloc_ty(rhs_res.res.bcx, t);
+ // Swap through a temporary.
- auto rhs_res = trans_expr(lhs_res.res.bcx, src);
- if (ty::type_is_sequence(bcx_tcx(cx), t)) {
- alt (op) {
- case (ast::add) {
- if (ty::sequence_is_interior(bcx_tcx(cx), t)) {
- ret ivec::trans_append(rhs_res.bcx, t,
- lhs_res.res.val,
- rhs_res.val);
- }
- ret trans_vec_append(rhs_res.bcx, t, lhs_res.res.val,
- rhs_res.val);
- }
- case (_) { }
+ let move1_res =
+ memmove_ty(tmp_res.bcx, tmp_res.val, lhs_res.res.val, t);
+ let move2_res =
+ memmove_ty(move1_res.bcx, lhs_res.res.val, rhs_res.res.val, t);
+ let move3_res =
+ memmove_ty(move2_res.bcx, rhs_res.res.val, tmp_res.val, t);
+ ret rslt(move3_res.bcx, C_nil());
+ }
+ ast::expr_assign_op(op, dst, src) {
+ let t = ty::expr_ty(bcx_tcx(cx), src);
+ let lhs_res = trans_lval(cx, dst);
+ assert (lhs_res.is_mem);
+ // FIXME Fill in lhs_res.res.bcx.sp
+
+ let rhs_res = trans_expr(lhs_res.res.bcx, src);
+ if ty::type_is_sequence(bcx_tcx(cx), t) {
+ alt op {
+ ast::add. {
+ if ty::sequence_is_interior(bcx_tcx(cx), t) {
+ ret ivec::trans_append(rhs_res.bcx, t, lhs_res.res.val,
+ rhs_res.val);
}
+ ret trans_vec_append(rhs_res.bcx, t, lhs_res.res.val,
+ rhs_res.val);
+ }
+ _ { }
}
- auto lhs_val = load_if_immediate(rhs_res.bcx, lhs_res.res.val, t);
- auto v =
- trans_eager_binop(rhs_res.bcx, op, t, lhs_val, rhs_res.val);
- // FIXME: calculate copy init-ness in typestate.
- // This is always a temporary, so can always be safely moved
- auto move_res = move_val(v.bcx, DROP_EXISTING, lhs_res.res.val,
- lval_val(v.bcx, v.val), t);
- ret rslt(move_res.bcx, C_nil());
}
- case (ast::expr_bind(?f, ?args)) {
- ret trans_bind(cx, f, args, e.id);
- }
- case (ast::expr_call(?f, ?args)) {
- ret trans_call(cx, f, none[ValueRef], args, e.id);
- }
- case (ast::expr_cast(?val, _)) { ret trans_cast(cx, val, e.id); }
- case (ast::expr_vec(?args, _, ast::sk_rc)) {
- ret trans_vec(cx, args, e.id);
- }
- case (ast::expr_vec(?args, _, ast::sk_unique)) {
- ret trans_ivec(cx, args, e.id);
- }
- case (ast::expr_rec(?args, ?base)) {
- ret trans_rec(cx, args, base, e.id);
- }
- case (ast::expr_mac(_)) {
- ret bcx_ccx(cx).sess.bug("unexpanded macro");
- }
- case (ast::expr_fail(?expr)) {
- ret trans_fail_expr(cx, some(e.span), expr);
- }
- case (ast::expr_log(?lvl, ?a)) { ret trans_log(lvl, cx, a); }
- case (ast::expr_assert(?a)) {
- ret trans_check_expr(cx, a, "Assertion");
- }
- case (ast::expr_check(ast::checked, ?a)) {
- ret trans_check_expr(cx, a, "Predicate");
- }
- case (ast::expr_check(ast::unchecked, ?a)) {
- /* Claims are turned on and off by a global variable
- that the RTS sets. This case generates code to
- check the value of that variable, doing nothing
- if it's set to false and acting like a check
- otherwise. */
- auto c = get_extern_const(bcx_ccx(cx).externs,
- bcx_ccx(cx).llmod,
- "check_claims", T_bool());
- auto cond = cx.build.Load(c);
+ let lhs_val = load_if_immediate(rhs_res.bcx, lhs_res.res.val, t);
+ let v = trans_eager_binop(rhs_res.bcx, op, t, lhs_val, rhs_res.val);
+ // FIXME: calculate copy init-ness in typestate.
+ // This is always a temporary, so can always be safely moved
+ let move_res =
+ move_val(v.bcx, DROP_EXISTING, lhs_res.res.val,
+ lval_val(v.bcx, v.val), t);
+ ret rslt(move_res.bcx, C_nil());
+ }
+ ast::expr_bind(f, args) { ret trans_bind(cx, f, args, e.id); }
+ ast::expr_call(f, args) {
+ ret trans_call(cx, f, none[ValueRef], args, e.id);
+ }
+ ast::expr_cast(val, _) { ret trans_cast(cx, val, e.id); }
+ ast::expr_vec(args, _, ast::sk_rc.) { ret trans_vec(cx, args, e.id); }
+ ast::expr_vec(args, _, ast::sk_unique.) {
+ ret trans_ivec(cx, args, e.id);
+ }
+ ast::expr_rec(args, base) { ret trans_rec(cx, args, base, e.id); }
+ ast::expr_mac(_) { ret bcx_ccx(cx).sess.bug("unexpanded macro"); }
+ ast::expr_fail(expr) { ret trans_fail_expr(cx, some(e.span), expr); }
+ ast::expr_log(lvl, a) { ret trans_log(lvl, cx, a); }
+ ast::expr_assert(a) { ret trans_check_expr(cx, a, "Assertion"); }
+ ast::expr_check(ast::checked., a) {
+ ret trans_check_expr(cx, a, "Predicate");
+ }
+ ast::expr_check(ast::unchecked., a) {
+ /* Claims are turned on and off by a global variable
+ that the RTS sets. This case generates code to
+ check the value of that variable, doing nothing
+ if it's set to false and acting like a check
+ otherwise. */
+ let c =
+ get_extern_const(bcx_ccx(cx).externs, bcx_ccx(cx).llmod,
+ "check_claims", T_bool());
+ let cond = cx.build.Load(c);
- auto then_cx = new_scope_block_ctxt(cx, "claim_then");
- auto check_res = trans_check_expr(then_cx, a, "Claim");
- auto else_cx = new_scope_block_ctxt(cx, "else");
- auto els = rslt(else_cx, C_nil());
+ let then_cx = new_scope_block_ctxt(cx, "claim_then");
+ let check_res = trans_check_expr(then_cx, a, "Claim");
+ let else_cx = new_scope_block_ctxt(cx, "else");
+ let els = rslt(else_cx, C_nil());
- cx.build.CondBr(cond, then_cx.llbb, else_cx.llbb);
- ret rslt(join_branches(cx, ~[check_res, els]), C_nil());
- }
- case (ast::expr_break) { ret trans_break(e.span, cx); }
- case (ast::expr_cont) { ret trans_cont(e.span, cx); }
- case (ast::expr_ret(?ex)) { ret trans_ret(cx, ex); }
- case (ast::expr_put(?ex)) { ret trans_put(cx, ex); }
- case (ast::expr_be(?ex)) { ret trans_be(cx, ex); }
- case (ast::expr_port(_)) { ret trans_port(cx, e.id); }
- case (ast::expr_chan(?ex)) { ret trans_chan(cx, ex, e.id); }
- case (ast::expr_send(?lhs, ?rhs)) {
- ret trans_send(cx, lhs, rhs, e.id);
- }
- case (ast::expr_recv(?lhs, ?rhs)) {
- ret trans_recv(cx, lhs, rhs, e.id);
- }
- case (ast::expr_spawn(?dom, ?name, ?func, ?args)) {
- ret trans_spawn(cx, dom, name, func, args, e.id);
- }
- case (ast::expr_anon_obj(?anon_obj)) {
- ret trans_anon_obj(cx, e.span, anon_obj, e.id);
- }
- case (_) {
- // The expression is an lvalue. Fall through.
- assert (ty::is_lval(e)); // make sure it really is and that we
- // didn't forget to add a case for a new expr!
- }
+ cx.build.CondBr(cond, then_cx.llbb, else_cx.llbb);
+ ret rslt(join_branches(cx, ~[check_res, els]), C_nil());
+ }
+ ast::expr_break. { ret trans_break(e.span, cx); }
+ ast::expr_cont. { ret trans_cont(e.span, cx); }
+ ast::expr_ret(ex) { ret trans_ret(cx, ex); }
+ ast::expr_put(ex) { ret trans_put(cx, ex); }
+ ast::expr_be(ex) { ret trans_be(cx, ex); }
+ ast::expr_port(_) { ret trans_port(cx, e.id); }
+ ast::expr_chan(ex) { ret trans_chan(cx, ex, e.id); }
+ ast::expr_send(lhs, rhs) { ret trans_send(cx, lhs, rhs, e.id); }
+ ast::expr_recv(lhs, rhs) { ret trans_recv(cx, lhs, rhs, e.id); }
+ ast::expr_spawn(dom, name, func, args) {
+ ret trans_spawn(cx, dom, name, func, args, e.id);
+ }
+ ast::expr_anon_obj(anon_obj) {
+ ret trans_anon_obj(cx, e.span, anon_obj, e.id);
+ }
+ _ {
+ // The expression is an lvalue. Fall through.
+ assert (ty::is_lval(e)); // make sure it really is and that we
+ // didn't forget to add a case for a new expr!
+
+ }
}
// lval cases fall through to trans_lval and then
// possibly load the result (if it's non-structural).
- auto t = ty::expr_ty(bcx_tcx(cx), e);
- auto sub = trans_lval(cx, e);
- auto v = sub.res.val;
- if (sub.is_mem) { v = load_if_immediate(sub.res.bcx, v, t); }
+ let t = ty::expr_ty(bcx_tcx(cx), e);
+ let sub = trans_lval(cx, e);
+ let v = sub.res.val;
+ if sub.is_mem { v = load_if_immediate(sub.res.bcx, v, t); }
ret rslt(sub.res.bcx, v);
}
-fn with_out_method(fn(&out_method) -> result work, @block_ctxt cx,
- ast::node_id id, &out_method outer_output) -> result {
- auto ccx = bcx_ccx(cx);
- if (outer_output != return) {
+fn with_out_method(work: fn(&out_method) -> result , cx: @block_ctxt,
+ id: ast::node_id, outer_output: &out_method) -> result {
+ let ccx = bcx_ccx(cx);
+ if outer_output != return {
ret work(outer_output);
} else {
- auto tp = node_id_type(ccx, id);
- if (ty::type_is_nil(ccx.tcx, tp)) { ret work(return); }
- auto res_alloca = alloc_ty(cx, tp);
+ let tp = node_id_type(ccx, id);
+ if ty::type_is_nil(ccx.tcx, tp) { ret work(return); }
+ let res_alloca = alloc_ty(cx, tp);
cx = zero_alloca(res_alloca.bcx, res_alloca.val, tp).bcx;
- fn drop_hoisted_ty(&@block_ctxt cx, ValueRef target, ty::t t) ->
+ fn drop_hoisted_ty(cx: &@block_ctxt, target: ValueRef, t: ty::t) ->
result {
- auto reg_val = load_if_immediate(cx, target, t);
+ let reg_val = load_if_immediate(cx, target, t);
ret drop_ty(cx, reg_val, t);
}
- auto done = work(save_in(res_alloca.val));
- auto loaded = load_if_immediate(done.bcx, res_alloca.val, tp);
+ let done = work(save_in(res_alloca.val));
+ let loaded = load_if_immediate(done.bcx, res_alloca.val, tp);
add_clean_temp(cx, loaded, tp);
- ret rslt(done.bcx, loaded);;
+ ret rslt(done.bcx, loaded);
}
}
@@ -5491,37 +5377,37 @@
// latter group "immediates" and, in some circumstances when we know we have a
// pointer (or need one), perform load/store operations based on the
// immediate-ness of the type.
-fn type_is_immediate(&@crate_ctxt ccx, &ty::t t) -> bool {
+fn type_is_immediate(ccx: &@crate_ctxt, t: &ty::t) -> bool {
ret ty::type_is_scalar(ccx.tcx, t) || ty::type_is_boxed(ccx.tcx, t) ||
ty::type_is_native(ccx.tcx, t);
}
-fn do_spill(&@block_ctxt cx, ValueRef v) -> ValueRef {
+fn do_spill(cx: &@block_ctxt, v: ValueRef) -> ValueRef {
// We have a value but we have to spill it to pass by alias.
- auto llptr = alloca(cx, val_ty(v));
+ let llptr = alloca(cx, val_ty(v));
cx.build.Store(v, llptr);
ret llptr;
}
-fn spill_if_immediate(&@block_ctxt cx, ValueRef v, &ty::t t) -> ValueRef {
- if (type_is_immediate(bcx_ccx(cx), t)) { ret do_spill(cx, v); }
+fn spill_if_immediate(cx: &@block_ctxt, v: ValueRef, t: &ty::t) -> ValueRef {
+ if type_is_immediate(bcx_ccx(cx), t) { ret do_spill(cx, v); }
ret v;
}
-fn load_if_immediate(&@block_ctxt cx, ValueRef v, &ty::t t) -> ValueRef {
- if (type_is_immediate(bcx_ccx(cx), t)) { ret cx.build.Load(v); }
+fn load_if_immediate(cx: &@block_ctxt, v: ValueRef, t: &ty::t) -> ValueRef {
+ if type_is_immediate(bcx_ccx(cx), t) { ret cx.build.Load(v); }
ret v;
}
-fn trans_log(int lvl, &@block_ctxt cx, &@ast::expr e) -> result {
- auto lcx = cx.fcx.lcx;
- auto modname = str::connect_ivec(lcx.module_path, "::");
- auto global;
- if (lcx.ccx.module_data.contains_key(modname)) {
+fn trans_log(lvl: int, cx: &@block_ctxt, e: &@ast::expr) -> result {
+ let lcx = cx.fcx.lcx;
+ let modname = str::connect_ivec(lcx.module_path, "::");
+ let global;
+ if lcx.ccx.module_data.contains_key(modname) {
global = lcx.ccx.module_data.get(modname);
} else {
- auto s =
+ let s =
link::mangle_internal_name_by_path_and_seq(lcx.ccx,
lcx.module_path,
"loglevel");
@@ -5532,32 +5418,29 @@
lib::llvm::LLVMInternalLinkage as llvm::Linkage);
lcx.ccx.module_data.insert(modname, global);
}
- auto log_cx = new_scope_block_ctxt(cx, "log");
- auto after_cx = new_sub_block_ctxt(cx, "after");
- auto load = cx.build.Load(global);
- auto test = cx.build.ICmp(lib::llvm::LLVMIntSGE, load, C_int(lvl));
+ let log_cx = new_scope_block_ctxt(cx, "log");
+ let after_cx = new_sub_block_ctxt(cx, "after");
+ let load = cx.build.Load(global);
+ let test = cx.build.ICmp(lib::llvm::LLVMIntSGE, load, C_int(lvl));
cx.build.CondBr(test, log_cx.llbb, after_cx.llbb);
- auto sub = trans_expr(log_cx, e);
- auto e_ty = ty::expr_ty(bcx_tcx(cx), e);
- auto log_bcx = sub.bcx;
- if (ty::type_is_fp(bcx_tcx(cx), e_ty)) {
- let TypeRef tr;
- let bool is32bit = false;
- alt (ty::struct(bcx_tcx(cx), e_ty)) {
- case (ty::ty_machine(ast::ty_f32)) {
- tr = T_f32();
- is32bit = true;
- }
- case (ty::ty_machine(ast::ty_f64)) { tr = T_f64(); }
- case (_) { tr = T_float(); }
+ let sub = trans_expr(log_cx, e);
+ let e_ty = ty::expr_ty(bcx_tcx(cx), e);
+ let log_bcx = sub.bcx;
+ if ty::type_is_fp(bcx_tcx(cx), e_ty) {
+ let tr: TypeRef;
+ let is32bit: bool = false;
+ alt ty::struct(bcx_tcx(cx), e_ty) {
+ ty::ty_machine(ast::ty_f32.) { tr = T_f32(); is32bit = true; }
+ ty::ty_machine(ast::ty_f64.) { tr = T_f64(); }
+ _ { tr = T_float(); }
}
- if (is32bit) {
+ if is32bit {
log_bcx.build.Call(bcx_ccx(log_bcx).upcalls.log_float,
~[log_bcx.fcx.lltaskptr, C_int(lvl), sub.val]);
} else {
// FIXME: Eliminate this level of indirection.
- auto tmp = alloca(log_bcx, tr);
+ let tmp = alloca(log_bcx, tr);
sub.bcx.build.Store(sub.val, tmp);
log_bcx.build.Call(bcx_ccx(log_bcx).upcalls.log_double,
~[log_bcx.fcx.lltaskptr, C_int(lvl), tmp]);
@@ -5566,26 +5449,23 @@
ty::type_is_bool(bcx_tcx(cx), e_ty)) {
// FIXME: Handle signedness properly.
- auto llintval =
+ let llintval =
int_cast(log_bcx, T_int(), val_ty(sub.val), sub.val, false);
log_bcx.build.Call(bcx_ccx(log_bcx).upcalls.log_int,
~[log_bcx.fcx.lltaskptr, C_int(lvl), llintval]);
} else {
- alt (ty::struct(bcx_tcx(cx), e_ty)) {
- case (ty::ty_str) {
- log_bcx.build.Call(bcx_ccx(log_bcx).upcalls.log_str,
- ~[log_bcx.fcx.lltaskptr, C_int(lvl),
- sub.val]);
- }
- case (_) {
- // FIXME: Support these types.
+ alt ty::struct(bcx_tcx(cx), e_ty) {
+ ty::ty_str. {
+ log_bcx.build.Call(bcx_ccx(log_bcx).upcalls.log_str,
+ ~[log_bcx.fcx.lltaskptr, C_int(lvl), sub.val]);
+ }
+ _ {
+ // FIXME: Support these types.
- bcx_ccx(cx).sess.span_fatal(e.span,
- "log called on unsupported type "
- +
- ty_to_str(bcx_tcx(cx),
- e_ty));
- }
+ bcx_ccx(cx).sess.span_fatal(e.span,
+ "log called on unsupported type " +
+ ty_to_str(bcx_tcx(cx), e_ty));
+ }
}
}
log_bcx = trans_block_cleanups(log_bcx, log_cx);
@@ -5593,140 +5473,131 @@
ret rslt(after_cx, C_nil());
}
-fn trans_check_expr(&@block_ctxt cx, &@ast::expr e, &str s) -> result {
- auto cond_res = trans_expr(cx, e);
- auto expr_str = s + " " + expr_to_str(e) + " failed";
- auto fail_cx = new_sub_block_ctxt(cx, "fail");
+fn trans_check_expr(cx: &@block_ctxt, e: &@ast::expr, s: &str) -> result {
+ let cond_res = trans_expr(cx, e);
+ let expr_str = s + " " + expr_to_str(e) + " failed";
+ let fail_cx = new_sub_block_ctxt(cx, "fail");
trans_fail(fail_cx, some[span](e.span), expr_str);
- auto next_cx = new_sub_block_ctxt(cx, "next");
+ let next_cx = new_sub_block_ctxt(cx, "next");
cond_res.bcx.build.CondBr(cond_res.val, next_cx.llbb, fail_cx.llbb);
ret rslt(next_cx, C_nil());
}
-fn trans_fail_expr(&@block_ctxt cx, &option::t[span] sp_opt,
- &option::t[@ast::expr] fail_expr)
- -> result {
- auto bcx = cx;
- alt (fail_expr) {
- case (some(?expr)) {
- auto tcx = bcx_tcx(bcx);
- auto expr_res = trans_expr(bcx, expr);
- auto e_ty = ty::expr_ty(tcx, expr);
- bcx = expr_res.bcx;
+fn trans_fail_expr(cx: &@block_ctxt, sp_opt: &option::t[span],
+ fail_expr: &option::t[@ast::expr]) -> result {
+ let bcx = cx;
+ alt fail_expr {
+ some(expr) {
+ let tcx = bcx_tcx(bcx);
+ let expr_res = trans_expr(bcx, expr);
+ let e_ty = ty::expr_ty(tcx, expr);
+ bcx = expr_res.bcx;
- if (ty::type_is_str(tcx, e_ty)) {
- auto elt = bcx.build.GEP(expr_res.val,
- ~[C_int(0),
- C_int(abi::vec_elt_data)]);
- ret trans_fail_value(bcx, sp_opt, elt);
- } else {
- bcx_ccx(cx).sess.span_bug(expr.span,
- "fail called with unsupported \
- type " + ty_to_str(tcx, e_ty));
- }
+
+ if ty::type_is_str(tcx, e_ty) {
+ let elt =
+ bcx.build.GEP(expr_res.val,
+ ~[C_int(0), C_int(abi::vec_elt_data)]);
+ ret trans_fail_value(bcx, sp_opt, elt);
+ } else {
+ bcx_ccx(cx).sess.span_bug(expr.span,
+ "fail called with unsupported \
+ type "
+ + ty_to_str(tcx, e_ty));
}
- case (_) {
- ret trans_fail(bcx, sp_opt, "explicit failure");
- }
+ }
+ _ { ret trans_fail(bcx, sp_opt, "explicit failure"); }
}
}
-fn trans_fail(&@block_ctxt cx, &option::t[span] sp_opt, &str fail_str)
- -> result {
- auto V_fail_str = C_cstr(bcx_ccx(cx), fail_str);
+fn trans_fail(cx: &@block_ctxt, sp_opt: &option::t[span], fail_str: &str) ->
+ result {
+ let V_fail_str = C_cstr(bcx_ccx(cx), fail_str);
ret trans_fail_value(cx, sp_opt, V_fail_str);
}
-fn trans_fail_value(&@block_ctxt cx, &option::t[span] sp_opt,
- &ValueRef V_fail_str)
- -> result {
- auto V_filename;
- auto V_line;
- alt (sp_opt) {
- case (some(?sp)) {
- auto loc = bcx_ccx(cx).sess.lookup_pos(sp.lo);
- V_filename = C_cstr(bcx_ccx(cx), loc.filename);
- V_line = loc.line as int;
- }
- case (none) {
- V_filename = C_cstr(bcx_ccx(cx), "<runtime>");
- V_line = 0;
- }
+fn trans_fail_value(cx: &@block_ctxt, sp_opt: &option::t[span],
+ V_fail_str: &ValueRef) -> result {
+ let V_filename;
+ let V_line;
+ alt sp_opt {
+ some(sp) {
+ let loc = bcx_ccx(cx).sess.lookup_pos(sp.lo);
+ V_filename = C_cstr(bcx_ccx(cx), loc.filename);
+ V_line = loc.line as int;
+ }
+ none. { V_filename = C_cstr(bcx_ccx(cx), "<runtime>"); V_line = 0; }
}
- auto V_str = cx.build.PointerCast(V_fail_str, T_ptr(T_i8()));
+ let V_str = cx.build.PointerCast(V_fail_str, T_ptr(T_i8()));
V_filename = cx.build.PointerCast(V_filename, T_ptr(T_i8()));
- auto args = ~[cx.fcx.lltaskptr, V_str, V_filename, C_int(V_line)];
+ let args = ~[cx.fcx.lltaskptr, V_str, V_filename, C_int(V_line)];
cx.build.Call(bcx_ccx(cx).upcalls._fail, args);
cx.build.Unreachable();
ret rslt(cx, C_nil());
}
-fn trans_put(&@block_ctxt cx, &option::t[@ast::expr] e) -> result {
- auto llcallee = C_nil();
- auto llenv = C_nil();
- alt ({ cx.fcx.lliterbody }) {
- case (some(?lli)) {
- auto slot = alloca(cx, val_ty(lli));
- cx.build.Store(lli, slot);
- llcallee =
- cx.build.GEP(slot, ~[C_int(0), C_int(abi::fn_field_code)]);
- llcallee = cx.build.Load(llcallee);
- llenv = cx.build.GEP(slot, ~[C_int(0), C_int(abi::fn_field_box)]);
- llenv = cx.build.Load(llenv);
- }
+fn trans_put(cx: &@block_ctxt, e: &option::t[@ast::expr]) -> result {
+ let llcallee = C_nil();
+ let llenv = C_nil();
+ alt { cx.fcx.lliterbody } {
+ some(lli) {
+ let slot = alloca(cx, val_ty(lli));
+ cx.build.Store(lli, slot);
+ llcallee = cx.build.GEP(slot, ~[C_int(0), C_int(abi::fn_field_code)]);
+ llcallee = cx.build.Load(llcallee);
+ llenv = cx.build.GEP(slot, ~[C_int(0), C_int(abi::fn_field_box)]);
+ llenv = cx.build.Load(llenv);
+ }
}
- auto bcx = cx;
- auto dummy_retslot = alloca(bcx, T_nil());
- let ValueRef[] llargs = ~[dummy_retslot, cx.fcx.lltaskptr, llenv];
- alt (e) {
- case (none) { }
- case (some(?x)) {
- auto e_ty = ty::expr_ty(bcx_tcx(cx), x);
- auto arg = rec(mode=ty::mo_alias(false), ty=e_ty);
- auto arg_tys =
- type_of_explicit_args(bcx_ccx(cx), x.span, ~[arg]);
- auto r = trans_arg_expr(bcx, arg, arg_tys.(0), x);
- bcx = r.bcx;
- llargs += ~[r.val];
- }
+ let bcx = cx;
+ let dummy_retslot = alloca(bcx, T_nil());
+ let llargs: ValueRef[] = ~[dummy_retslot, cx.fcx.lltaskptr, llenv];
+ alt e {
+ none. { }
+ some(x) {
+ let e_ty = ty::expr_ty(bcx_tcx(cx), x);
+ let arg = {mode: ty::mo_alias(false), ty: e_ty};
+ let arg_tys = type_of_explicit_args(bcx_ccx(cx), x.span, ~[arg]);
+ let r = trans_arg_expr(bcx, arg, arg_tys.(0), x);
+ bcx = r.bcx;
+ llargs += ~[r.val];
+ }
}
ret rslt(bcx, bcx.build.FastCall(llcallee, llargs));
}
-fn trans_break_cont(&span sp, &@block_ctxt cx, bool to_end) -> result {
- auto bcx = cx;
+fn trans_break_cont(sp: &span, cx: &@block_ctxt, to_end: bool) -> result {
+ let bcx = cx;
// Locate closest loop block, outputting cleanup as we go.
- auto cleanup_cx = cx;
- while (true) {
+ let cleanup_cx = cx;
+ while true {
bcx = trans_block_cleanups(bcx, cleanup_cx);
- alt ({ cleanup_cx.kind }) {
- case (LOOP_SCOPE_BLOCK(?_cont, ?_break)) {
- if (to_end) {
- bcx.build.Br(_break.llbb);
- } else {
- alt (_cont) {
- case (option::some(?_cont)) {
- bcx.build.Br(_cont.llbb);
- }
- case (_) { bcx.build.Br(cleanup_cx.llbb); }
- }
- }
- ret rslt(new_sub_block_ctxt(bcx, "break_cont.unreachable"),
- C_nil());
- }
- case (_) {
- alt ({ cleanup_cx.parent }) {
- case (parent_some(?cx)) { cleanup_cx = cx; }
- case (parent_none) {
- bcx_ccx(cx).sess.span_fatal(sp,
- if (to_end) {
- "Break"
- } else { "Cont" } +
- " outside a loop");
- }
+ alt { cleanup_cx.kind } {
+ LOOP_SCOPE_BLOCK(_cont, _break) {
+ if to_end {
+ bcx.build.Br(_break.llbb);
+ } else {
+ alt _cont {
+ option::some(_cont) { bcx.build.Br(_cont.llbb); }
+ _ { bcx.build.Br(cleanup_cx.llbb); }
}
}
+ ret rslt(new_sub_block_ctxt(bcx, "break_cont.unreachable"),
+ C_nil());
+ }
+ _ {
+ alt { cleanup_cx.parent } {
+ parent_some(cx) { cleanup_cx = cx; }
+ parent_none. {
+ bcx_ccx(cx).sess.span_fatal(sp,
+ if to_end {
+ "Break"
+ } else { "Cont" } +
+ " outside a loop");
+ }
+ }
+ }
}
}
// If we get here without returning, it's a bug
@@ -5734,44 +5605,44 @@
bcx_ccx(cx).sess.bug("in trans::trans_break_cont()");
}
-fn trans_break(&span sp, &@block_ctxt cx) -> result {
+fn trans_break(sp: &span, cx: &@block_ctxt) -> result {
ret trans_break_cont(sp, cx, true);
}
-fn trans_cont(&span sp, &@block_ctxt cx) -> result {
+fn trans_cont(sp: &span, cx: &@block_ctxt) -> result {
ret trans_break_cont(sp, cx, false);
}
-fn trans_ret(&@block_ctxt cx, &option::t[@ast::expr] e) -> result {
- auto bcx = cx;
- alt (e) {
- case (some(?x)) {
- auto t = ty::expr_ty(bcx_tcx(cx), x);
- auto lv = trans_lval(cx, x);
- bcx = lv.res.bcx;
- bcx = move_val_if_temp(bcx, INIT, cx.fcx.llretptr, lv, t).bcx;
- }
- case (_) {
- auto t = llvm::LLVMGetElementType(val_ty(cx.fcx.llretptr));
- bcx.build.Store(C_null(t), cx.fcx.llretptr);
- }
+fn trans_ret(cx: &@block_ctxt, e: &option::t[@ast::expr]) -> result {
+ let bcx = cx;
+ alt e {
+ some(x) {
+ let t = ty::expr_ty(bcx_tcx(cx), x);
+ let lv = trans_lval(cx, x);
+ bcx = lv.res.bcx;
+ bcx = move_val_if_temp(bcx, INIT, cx.fcx.llretptr, lv, t).bcx;
+ }
+ _ {
+ let t = llvm::LLVMGetElementType(val_ty(cx.fcx.llretptr));
+ bcx.build.Store(C_null(t), cx.fcx.llretptr);
+ }
}
// run all cleanups and back out.
- let bool more_cleanups = true;
- auto cleanup_cx = cx;
- while (more_cleanups) {
+ let more_cleanups: bool = true;
+ let cleanup_cx = cx;
+ while more_cleanups {
bcx = trans_block_cleanups(bcx, cleanup_cx);
- alt ({ cleanup_cx.parent }) {
- case (parent_some(?b)) { cleanup_cx = b; }
- case (parent_none) { more_cleanups = false; }
+ alt { cleanup_cx.parent } {
+ parent_some(b) { cleanup_cx = b; }
+ parent_none. { more_cleanups = false; }
}
}
bcx.build.RetVoid();
ret rslt(new_sub_block_ctxt(bcx, "ret.unreachable"), C_nil());
}
-fn trans_be(&@block_ctxt cx, &@ast::expr e) -> result {
+fn trans_be(cx: &@block_ctxt, e: &@ast::expr) -> result {
// FIXME: This should be a typestate precondition
assert (ast::is_call_expr(e));
@@ -5818,97 +5689,98 @@
// function and putting it in the generated code as an object item, we are
// instead "inlining" the construction of the object and returning the object
// itself.
-fn trans_anon_obj(@block_ctxt bcx, &span sp, &ast::anon_obj anon_obj,
- ast::node_id id) -> result {
+fn trans_anon_obj(bcx: @block_ctxt, sp: &span, anon_obj: &ast::anon_obj,
+ id: ast::node_id) -> result {
- auto ccx = bcx_ccx(bcx);
+ let ccx = bcx_ccx(bcx);
// Fields.
// FIXME (part of issue #538): Where do we fill in the field *values* from
// the outer object?
- let ast::anon_obj_field[] additional_fields = ~[];
- let result[] additional_field_vals = ~[];
- let ty::t[] additional_field_tys = ~[];
- alt (anon_obj.fields) {
- case (none) { }
- case (some(?fields)) {
- additional_fields = fields;
- for (ast::anon_obj_field f in fields) {
- additional_field_tys += ~[node_id_type(ccx, f.id)];
- additional_field_vals += ~[trans_expr(bcx, f.expr)];
- }
+ let additional_fields: ast::anon_obj_field[] = ~[];
+ let additional_field_vals: result[] = ~[];
+ let additional_field_tys: ty::t[] = ~[];
+ alt anon_obj.fields {
+ none. { }
+ some(fields) {
+ additional_fields = fields;
+ for f: ast::anon_obj_field in fields {
+ additional_field_tys += ~[node_id_type(ccx, f.id)];
+ additional_field_vals += ~[trans_expr(bcx, f.expr)];
}
+ }
}
// Get the type of the eventual entire anonymous object, possibly with
// extensions. NB: This type includes both inner and outer methods.
- auto outer_obj_ty = ty::node_id_to_type(ccx.tcx, id);
+ let outer_obj_ty = ty::node_id_to_type(ccx.tcx, id);
// Create a vtable for the anonymous object.
// create_vtbl() wants an ast::_obj and all we have is an ast::anon_obj,
// so we need to roll our own.
- let ast::_obj wrapper_obj = rec(
- fields = std::ivec::map(ast::obj_field_from_anon_obj_field,
- additional_fields),
- methods = anon_obj.methods,
- dtor = none[@ast::method]);
+ let wrapper_obj: ast::_obj =
+ {fields:
+ std::ivec::map(ast::obj_field_from_anon_obj_field,
+ additional_fields),
+ methods: anon_obj.methods,
+ dtor: none[@ast::method]};
- let ty::t with_obj_ty;
- auto vtbl;
- alt (anon_obj.with_obj) {
- case (none) {
- // If there's no with_obj -- that is, if we're just adding new
- // fields rather than extending an existing object -- then we just
- // pass the outer object to create_vtbl(). Our vtable won't need
- // to have any forwarding slots.
+ let with_obj_ty: ty::t;
+ let vtbl;
+ alt anon_obj.with_obj {
+ none. {
+ // If there's no with_obj -- that is, if we're just adding new
+ // fields rather than extending an existing object -- then we just
+ // pass the outer object to create_vtbl(). Our vtable won't need
+ // to have any forwarding slots.
- // We need a dummy with_obj_ty for setting up the object body
- // later.
- with_obj_ty = ty::mk_type(ccx.tcx);
+ // We need a dummy with_obj_ty for setting up the object body
+ // later.
+ with_obj_ty = ty::mk_type(ccx.tcx);
- // This seems a little strange, because it'll come into
- // create_vtbl() with no "additional methods". What's happening
- // is that, since *all* of the methods are "additional", we can
- // get away with acting like none of them are.
- vtbl = create_vtbl(bcx.fcx.lcx, sp, outer_obj_ty,
- wrapper_obj, ~[], none,
- additional_field_tys);
- }
- case (some(?e)) {
- // TODO: What makes more sense to get the type of an expr --
- // calling ty::expr_ty(ccx.tcx, e) on it or calling
- // ty::node_id_to_type(ccx.tcx, id) on its id?
- with_obj_ty = ty::expr_ty(ccx.tcx, e);
- //with_obj_ty = ty::node_id_to_type(ccx.tcx, e.id);
+ // This seems a little strange, because it'll come into
+ // create_vtbl() with no "additional methods". What's happening
+ // is that, since *all* of the methods are "additional", we can
+ // get away with acting like none of them are.
+ vtbl =
+ create_vtbl(bcx.fcx.lcx, sp, outer_obj_ty, wrapper_obj, ~[], none,
+ additional_field_tys);
+ }
+ some(e) {
+ // TODO: What makes more sense to get the type of an expr --
+ // calling ty::expr_ty(ccx.tcx, e) on it or calling
+ // ty::node_id_to_type(ccx.tcx, id) on its id?
+ with_obj_ty = ty::expr_ty(ccx.tcx, e);
+ //with_obj_ty = ty::node_id_to_type(ccx.tcx, e.id);
- // If there's a with_obj, we pass its type along to create_vtbl().
- // Part of what create_vtbl() will do is take the set difference
- // of methods defined on the original and methods being added.
- // For every method defined on the original that does *not* have
- // one with a matching name and type being added, we'll need to
- // create a forwarding slot. And, of course, we need to create a
- // normal vtable entry for every method being added.
- vtbl = create_vtbl(bcx.fcx.lcx, sp, outer_obj_ty,
- wrapper_obj, ~[], some(with_obj_ty),
- additional_field_tys);
- }
+ // If there's a with_obj, we pass its type along to create_vtbl().
+ // Part of what create_vtbl() will do is take the set difference
+ // of methods defined on the original and methods being added.
+ // For every method defined on the original that does *not* have
+ // one with a matching name and type being added, we'll need to
+ // create a forwarding slot. And, of course, we need to create a
+ // normal vtable entry for every method being added.
+ vtbl =
+ create_vtbl(bcx.fcx.lcx, sp, outer_obj_ty, wrapper_obj, ~[],
+ some(with_obj_ty), additional_field_tys);
+ }
}
// Allocate the object that we're going to return.
- auto pair = alloca(bcx, ccx.rust_object_type);
+ let pair = alloca(bcx, ccx.rust_object_type);
// Take care of cleanups.
- auto t = node_id_type(ccx, id);
+ let t = node_id_type(ccx, id);
add_clean_temp(bcx, pair, t);
// Grab onto the first and second elements of the pair.
// abi::obj_field_vtbl and abi::obj_field_box simply specify words 0 and 1
// of 'pair'.
- auto pair_vtbl =
+ let pair_vtbl =
bcx.build.GEP(pair, ~[C_int(0), C_int(abi::obj_field_vtbl)]);
- auto pair_box =
+ let pair_box =
bcx.build.GEP(pair, ~[C_int(0), C_int(abi::obj_field_box)]);
vtbl = bcx.build.PointerCast(vtbl, T_ptr(T_empty_struct()));
@@ -5917,47 +5789,47 @@
// Next we have to take care of the other half of the pair we're
// returning: a boxed (reference-counted) tuple containing a tydesc,
// typarams, fields, and a pointer to our with_obj.
- let TypeRef llbox_ty = T_ptr(T_empty_struct());
+ let llbox_ty: TypeRef = T_ptr(T_empty_struct());
- if (std::ivec::len[ast::anon_obj_field](additional_fields) == 0u &&
- anon_obj.with_obj == none) {
+ if std::ivec::len[ast::anon_obj_field](additional_fields) == 0u &&
+ anon_obj.with_obj == none {
// If the object we're translating has no fields and no with_obj,
// there's not much to do.
bcx.build.Store(C_null(llbox_ty), pair_box);
} else {
// Synthesize a tuple type for fields: [field, ...]
- let ty::t fields_ty = ty::mk_imm_tup(ccx.tcx, additional_field_tys);
+ let fields_ty: ty::t = ty::mk_imm_tup(ccx.tcx, additional_field_tys);
// Type for tydescs.
- let ty::t tydesc_ty = ty::mk_type(ccx.tcx);
+ let tydesc_ty: ty::t = ty::mk_type(ccx.tcx);
// Placeholder for non-existent typarams, since anon objs don't have
// them.
- let ty::t typarams_ty = ty::mk_imm_tup(ccx.tcx, ~[]);
+ let typarams_ty: ty::t = ty::mk_imm_tup(ccx.tcx, ~[]);
// Tuple type for body:
// [tydesc, [typaram, ...], [field, ...], with_obj]
- let ty::t body_ty =
- ty::mk_imm_tup(ccx.tcx, ~[tydesc_ty, typarams_ty,
- fields_ty, with_obj_ty]);
+ let body_ty: ty::t =
+ ty::mk_imm_tup(ccx.tcx,
+ ~[tydesc_ty, typarams_ty, fields_ty, with_obj_ty]);
// Hand this type we've synthesized off to trans_malloc_boxed, which
// allocates a box, including space for a refcount.
- auto box = trans_malloc_boxed(bcx, body_ty);
+ let box = trans_malloc_boxed(bcx, body_ty);
bcx = box.bcx;
// mk_imm_box throws a refcount into the type we're synthesizing,
// so that it looks like:
// [rc, [tydesc, [typaram, ...], [field, ...], with_obj]]
- let ty::t boxed_body_ty = ty::mk_imm_box(ccx.tcx, body_ty);
+ let boxed_body_ty: ty::t = ty::mk_imm_box(ccx.tcx, body_ty);
// Grab onto the refcount and body parts of the box we allocated.
- auto rc =
+ let rc =
GEP_tup_like(bcx, boxed_body_ty, box.val,
~[0, abi::box_rc_field_refcnt]);
bcx = rc.bcx;
- auto body =
+ let body =
GEP_tup_like(bcx, boxed_body_ty, box.val,
~[0, abi::box_rc_field_body]);
bcx = body.bcx;
@@ -5971,12 +5843,12 @@
// the user of the object. So the tydesc is needed to keep track of
// the types of the object's fields, so that the fields can be freed
// later.
- auto body_tydesc =
+ let body_tydesc =
GEP_tup_like(bcx, body_ty, body.val,
~[0, abi::obj_body_elt_tydesc]);
bcx = body_tydesc.bcx;
- auto ti = none[@tydesc_info];
- auto body_td = get_tydesc(bcx, body_ty, true, ti);
+ let ti = none[@tydesc_info];
+ let body_td = get_tydesc(bcx, body_ty, true, ti);
lazily_emit_tydesc_glue(bcx, abi::tydesc_field_drop_glue, ti);
lazily_emit_tydesc_glue(bcx, abi::tydesc_field_free_glue, ti);
bcx = body_td.bcx;
@@ -5986,48 +5858,47 @@
// body. (This is something like saving the lexical environment of a
// function in its closure: the fields were passed to the object
// constructor and are now available to the object's methods.
- auto body_fields =
+ let body_fields =
GEP_tup_like(bcx, body_ty, body.val,
~[0, abi::obj_body_elt_fields]);
bcx = body_fields.bcx;
- let int i = 0;
- for (ast::anon_obj_field f in additional_fields) {
+ let i: int = 0;
+ for f: ast::anon_obj_field in additional_fields {
// FIXME (part of issue #538): make this work eventually, when we
// have additional field exprs in the AST.
- load_if_immediate(
- bcx,
- additional_field_vals.(i).val,
- additional_field_tys.(i));
+ load_if_immediate(bcx, additional_field_vals.(i).val,
+ additional_field_tys.(i));
- auto field =
+ let field =
GEP_tup_like(bcx, fields_ty, body_fields.val, ~[0, i]);
bcx = field.bcx;
- bcx = copy_val(bcx, INIT, field.val,
- additional_field_vals.(i).val,
- additional_field_tys.(i)).bcx;
+ bcx =
+ copy_val(bcx, INIT, field.val, additional_field_vals.(i).val,
+ additional_field_tys.(i)).bcx;
i += 1;
}
// If there's a with_obj, copy a pointer to it into the object's body.
- alt (anon_obj.with_obj) {
- case (none) { }
- case (some(?e)) {
- // If with_obj (the object being extended) exists, translate
- // it. Translating with_obj returns a ValueRef (pointer to a
- // 2-word value) wrapped in a result.
- let result with_obj_val = trans_expr(bcx, e);
+ alt anon_obj.with_obj {
+ none. { }
+ some(e) {
+ // If with_obj (the object being extended) exists, translate
+ // it. Translating with_obj returns a ValueRef (pointer to a
+ // 2-word value) wrapped in a result.
+ let with_obj_val: result = trans_expr(bcx, e);
- auto body_with_obj =
- GEP_tup_like(bcx, body_ty, body.val,
- ~[0, abi::obj_body_elt_with_obj]);
- bcx = body_with_obj.bcx;
- bcx = copy_val(bcx, INIT, body_with_obj.val,
- with_obj_val.val, with_obj_ty).bcx;
- }
+ let body_with_obj =
+ GEP_tup_like(bcx, body_ty, body.val,
+ ~[0, abi::obj_body_elt_with_obj]);
+ bcx = body_with_obj.bcx;
+ bcx =
+ copy_val(bcx, INIT, body_with_obj.val, with_obj_val.val,
+ with_obj_ty).bcx;
+ }
}
// Store box ptr in outer pair.
- auto p = bcx.build.PointerCast(box.val, llbox_ty);
+ let p = bcx.build.PointerCast(box.val, llbox_ty);
bcx.build.Store(p, pair_box);
}
@@ -6035,75 +5906,73 @@
ret rslt(bcx, pair);
}
-fn init_local(&@block_ctxt cx, &@ast::local local) -> result {
+fn init_local(cx: &@block_ctxt, local: &@ast::local) -> result {
// Make a note to drop this slot on the way out.
assert (cx.fcx.lllocals.contains_key(local.node.id));
- auto llptr = cx.fcx.lllocals.get(local.node.id);
- auto ty = node_id_type(bcx_ccx(cx), local.node.id);
- auto bcx = cx;
+ let llptr = cx.fcx.lllocals.get(local.node.id);
+ let ty = node_id_type(bcx_ccx(cx), local.node.id);
+ let bcx = cx;
add_clean(cx, llptr, ty);
- alt (local.node.init) {
- case (some(?init)) {
- alt (init.op) {
- case (ast::init_assign) {
- // Use the type of the RHS because if it's _|_, the LHS
- // type might be something else, but we don't want to copy
- // the value.
+ alt local.node.init {
+ some(init) {
+ alt init.op {
+ ast::init_assign. {
+ // Use the type of the RHS because if it's _|_, the LHS
+ // type might be something else, but we don't want to copy
+ // the value.
- ty =
- node_id_type(bcx_ccx(cx), init.expr.id);
- auto sub = trans_lval(bcx, init.expr);
- bcx = move_val_if_temp(sub.res.bcx, INIT, llptr,
- sub, ty).bcx;
- }
- case (ast::init_move) {
- auto sub = trans_lval(bcx, init.expr);
- bcx = move_val(sub.res.bcx, INIT, llptr, sub, ty).bcx;
- }
- }
+ ty = node_id_type(bcx_ccx(cx), init.expr.id);
+ let sub = trans_lval(bcx, init.expr);
+ bcx = move_val_if_temp(sub.res.bcx, INIT, llptr, sub, ty).bcx;
+ }
+ ast::init_move. {
+ let sub = trans_lval(bcx, init.expr);
+ bcx = move_val(sub.res.bcx, INIT, llptr, sub, ty).bcx;
+ }
}
- case (_) { bcx = zero_alloca(bcx, llptr, ty).bcx; }
+ }
+ _ { bcx = zero_alloca(bcx, llptr, ty).bcx; }
}
ret rslt(bcx, llptr);
}
-fn zero_alloca(&@block_ctxt cx, ValueRef llptr, ty::t t) -> result {
- auto bcx = cx;
- if (ty::type_has_dynamic_size(bcx_tcx(cx), t)) {
- auto llsz = size_of(bcx, t);
- auto llalign = align_of(llsz.bcx, t);
+fn zero_alloca(cx: &@block_ctxt, llptr: ValueRef, t: ty::t) -> result {
+ let bcx = cx;
+ if ty::type_has_dynamic_size(bcx_tcx(cx), t) {
+ let llsz = size_of(bcx, t);
+ let llalign = align_of(llsz.bcx, t);
bcx = call_bzero(llalign.bcx, llptr, llsz.val, llalign.val).bcx;
} else {
- auto llty = type_of(bcx_ccx(bcx), cx.sp, t);
+ let llty = type_of(bcx_ccx(bcx), cx.sp, t);
bcx.build.Store(C_null(llty), llptr);
}
ret rslt(bcx, llptr);
}
-fn trans_stmt(&@block_ctxt cx, &ast::stmt s) -> result {
+fn trans_stmt(cx: &@block_ctxt, s: &ast::stmt) -> result {
// FIXME Fill in cx.sp
- auto bcx = cx;
- alt (s.node) {
- case (ast::stmt_expr(?e, _)) { bcx = trans_expr(cx, e).bcx; }
- case (ast::stmt_decl(?d, _)) {
- alt (d.node) {
- case (ast::decl_local(?locals)) {
- for (@ast::local local in locals) {
- bcx = init_local(bcx, local).bcx;
- }
- }
- case (ast::decl_item(?i)) { trans_item(cx.fcx.lcx, *i); }
+ let bcx = cx;
+ alt s.node {
+ ast::stmt_expr(e, _) { bcx = trans_expr(cx, e).bcx; }
+ ast::stmt_decl(d, _) {
+ alt d.node {
+ ast::decl_local(locals) {
+ for local: @ast::local in locals {
+ bcx = init_local(bcx, local).bcx;
}
+ }
+ ast::decl_item(i) { trans_item(cx.fcx.lcx, *i); }
}
- case (_) { bcx_ccx(cx).sess.unimpl("stmt variant"); }
+ }
+ _ { bcx_ccx(cx).sess.unimpl("stmt variant"); }
}
ret rslt(bcx, C_nil());
}
-fn new_builder(BasicBlockRef llbb) -> builder {
- let BuilderRef llbuild = llvm::LLVMCreateBuilder();
+fn new_builder(llbb: BasicBlockRef) -> builder {
+ let llbuild: BuilderRef = llvm::LLVMCreateBuilder();
llvm::LLVMPositionBuilderAtEnd(llbuild, llbb);
ret builder(llbuild, @mutable false);
}
@@ -6111,57 +5980,58 @@
// You probably don't want to use this one. See the
// next three functions instead.
-fn new_block_ctxt(&@fn_ctxt cx, &block_parent parent, block_kind kind,
- &str name) -> @block_ctxt {
- let cleanup[] cleanups = ~[];
- auto s = str::buf("");
- if (cx.lcx.ccx.sess.get_opts().save_temps ||
- cx.lcx.ccx.sess.get_opts().debuginfo) {
+fn new_block_ctxt(cx: &@fn_ctxt, parent: &block_parent, kind: block_kind,
+ name: &str) -> @block_ctxt {
+ let cleanups: cleanup[] = ~[];
+ let s = str::buf("");
+ if cx.lcx.ccx.sess.get_opts().save_temps ||
+ cx.lcx.ccx.sess.get_opts().debuginfo {
s = str::buf(cx.lcx.ccx.names.next(name));
}
- let BasicBlockRef llbb = llvm::LLVMAppendBasicBlock(cx.llfn, s);
- ret @rec(llbb=llbb,
- build=new_builder(llbb),
- parent=parent,
- kind=kind,
- mutable cleanups=cleanups,
- sp=cx.sp,
- fcx=cx);
+ let llbb: BasicBlockRef = llvm::LLVMAppendBasicBlock(cx.llfn, s);
+ ret @{llbb: llbb,
+ build: new_builder(llbb),
+ parent: parent,
+ kind: kind,
+ mutable cleanups: cleanups,
+ sp: cx.sp,
+ fcx: cx};
}
// Use this when you're at the top block of a function or the like.
-fn new_top_block_ctxt(&@fn_ctxt fcx) -> @block_ctxt {
+fn new_top_block_ctxt(fcx: &@fn_ctxt) -> @block_ctxt {
ret new_block_ctxt(fcx, parent_none, SCOPE_BLOCK, "function top level");
}
// Use this when you're at a curly-brace or similar lexical scope.
-fn new_scope_block_ctxt(&@block_ctxt bcx, &str n) -> @block_ctxt {
+fn new_scope_block_ctxt(bcx: &@block_ctxt, n: &str) -> @block_ctxt {
ret new_block_ctxt(bcx.fcx, parent_some(bcx), SCOPE_BLOCK, n);
}
-fn new_loop_scope_block_ctxt(&@block_ctxt bcx, &option::t[@block_ctxt] _cont,
- &@block_ctxt _break, &str n) -> @block_ctxt {
+fn new_loop_scope_block_ctxt(bcx: &@block_ctxt,
+ _cont: &option::t[@block_ctxt],
+ _break: &@block_ctxt, n: &str) -> @block_ctxt {
ret new_block_ctxt(bcx.fcx, parent_some(bcx),
LOOP_SCOPE_BLOCK(_cont, _break), n);
}
// Use this when you're making a general CFG BB within a scope.
-fn new_sub_block_ctxt(&@block_ctxt bcx, &str n) -> @block_ctxt {
+fn new_sub_block_ctxt(bcx: &@block_ctxt, n: &str) -> @block_ctxt {
ret new_block_ctxt(bcx.fcx, parent_some(bcx), NON_SCOPE_BLOCK, n);
}
-fn new_raw_block_ctxt(&@fn_ctxt fcx, BasicBlockRef llbb) -> @block_ctxt {
- let cleanup[] cleanups = ~[];
- ret @rec(llbb=llbb,
- build=new_builder(llbb),
- parent=parent_none,
- kind=NON_SCOPE_BLOCK,
- mutable cleanups=cleanups,
- sp=fcx.sp,
- fcx=fcx);
+fn new_raw_block_ctxt(fcx: &@fn_ctxt, llbb: BasicBlockRef) -> @block_ctxt {
+ let cleanups: cleanup[] = ~[];
+ ret @{llbb: llbb,
+ build: new_builder(llbb),
+ parent: parent_none,
+ kind: NON_SCOPE_BLOCK,
+ mutable cleanups: cleanups,
+ sp: fcx.sp,
+ fcx: fcx};
}
@@ -6172,88 +6042,87 @@
// need to make sure those variables go out of scope when the block ends. We
// do that by running a 'cleanup' function for each variable.
// trans_block_cleanups runs all the cleanup functions for the block.
-fn trans_block_cleanups(&@block_ctxt cx, &@block_ctxt cleanup_cx)
- -> @block_ctxt {
- auto bcx = cx;
- if (cleanup_cx.kind == NON_SCOPE_BLOCK) {
+fn trans_block_cleanups(cx: &@block_ctxt, cleanup_cx: &@block_ctxt) ->
+ @block_ctxt {
+ let bcx = cx;
+ if cleanup_cx.kind == NON_SCOPE_BLOCK {
assert (std::ivec::len[cleanup](cleanup_cx.cleanups) == 0u);
}
- auto i = std::ivec::len[cleanup](cleanup_cx.cleanups);
- while (i > 0u) {
+ let i = std::ivec::len[cleanup](cleanup_cx.cleanups);
+ while i > 0u {
i -= 1u;
- auto c = cleanup_cx.cleanups.(i);
- alt (c) {
- case (clean(?cfn)) { bcx = cfn(bcx).bcx; }
- case (clean_temp(_, ?cfn)) { bcx = cfn(bcx).bcx; }
+ let c = cleanup_cx.cleanups.(i);
+ alt c {
+ clean(cfn) { bcx = cfn(bcx).bcx; }
+ clean_temp(_, cfn) { bcx = cfn(bcx).bcx; }
}
}
ret bcx;
}
-iter block_locals(&ast::blk b) -> @ast::local {
+iter block_locals(b: &ast::blk) -> @ast::local {
+
// FIXME: putting from inside an iter block doesn't work, so we can't
// use the index here.
- for (@ast::stmt s in b.node.stmts) {
- alt (s.node) {
- case (ast::stmt_decl(?d, _)) {
- alt (d.node) {
- case (ast::decl_local(?locals)) {
- for (@ast::local local in locals) {
- put local;
- }
- }
- case (_) {/* fall through */ }
- }
+ for s: @ast::stmt in b.node.stmts {
+ alt s.node {
+ ast::stmt_decl(d, _) {
+ alt d.node {
+ ast::decl_local(locals) {
+ for local: @ast::local in locals { put local; }
+ }
+ _ {/* fall through */ }
}
- case (_) {/* fall through */ }
+ }
+ _ {/* fall through */ }
}
}
}
-fn llstaticallocas_block_ctxt(&@fn_ctxt fcx) -> @block_ctxt {
- let cleanup[] cleanups = ~[];
- ret @rec(llbb=fcx.llstaticallocas,
- build=new_builder(fcx.llstaticallocas),
- parent=parent_none,
- kind=SCOPE_BLOCK,
- mutable cleanups=cleanups,
- sp=fcx.sp,
- fcx=fcx);
+fn llstaticallocas_block_ctxt(fcx: &@fn_ctxt) -> @block_ctxt {
+ let cleanups: cleanup[] = ~[];
+ ret @{llbb: fcx.llstaticallocas,
+ build: new_builder(fcx.llstaticallocas),
+ parent: parent_none,
+ kind: SCOPE_BLOCK,
+ mutable cleanups: cleanups,
+ sp: fcx.sp,
+ fcx: fcx};
}
-fn llderivedtydescs_block_ctxt(&@fn_ctxt fcx) -> @block_ctxt {
- let cleanup[] cleanups = ~[];
- ret @rec(llbb=fcx.llderivedtydescs,
- build=new_builder(fcx.llderivedtydescs),
- parent=parent_none,
- kind=SCOPE_BLOCK,
- mutable cleanups=cleanups,
- sp=fcx.sp,
- fcx=fcx);
+fn llderivedtydescs_block_ctxt(fcx: &@fn_ctxt) -> @block_ctxt {
+ let cleanups: cleanup[] = ~[];
+ ret @{llbb: fcx.llderivedtydescs,
+ build: new_builder(fcx.llderivedtydescs),
+ parent: parent_none,
+ kind: SCOPE_BLOCK,
+ mutable cleanups: cleanups,
+ sp: fcx.sp,
+ fcx: fcx};
}
-fn lldynamicallocas_block_ctxt(&@fn_ctxt fcx) -> @block_ctxt {
- let cleanup[] cleanups = ~[];
- ret @rec(llbb=fcx.lldynamicallocas,
- build=new_builder(fcx.lldynamicallocas),
- parent=parent_none,
- kind=SCOPE_BLOCK,
- mutable cleanups=cleanups,
- sp=fcx.sp,
- fcx=fcx);
+fn lldynamicallocas_block_ctxt(fcx: &@fn_ctxt) -> @block_ctxt {
+ let cleanups: cleanup[] = ~[];
+ ret @{llbb: fcx.lldynamicallocas,
+ build: new_builder(fcx.lldynamicallocas),
+ parent: parent_none,
+ kind: SCOPE_BLOCK,
+ mutable cleanups: cleanups,
+ sp: fcx.sp,
+ fcx: fcx};
}
-fn alloc_ty(&@block_ctxt cx, &ty::t t) -> result {
- auto val = C_int(0);
- if (ty::type_has_dynamic_size(bcx_tcx(cx), t)) {
+fn alloc_ty(cx: &@block_ctxt, t: &ty::t) -> result {
+ let val = C_int(0);
+ if ty::type_has_dynamic_size(bcx_tcx(cx), t) {
// NB: we have to run this particular 'size_of' in a
// block_ctxt built on the llderivedtydescs block for the fn,
// so that the size dominates the array_alloca that
// comes next.
- auto n = size_of(llderivedtydescs_block_ctxt(cx.fcx), t);
+ let n = size_of(llderivedtydescs_block_ctxt(cx.fcx), t);
cx.fcx.llderivedtydescs = n.bcx.llbb;
val = array_alloca(cx, T_i8(), n.val);
} else { val = alloca(cx, type_of(bcx_ccx(cx), cx.sp, t)); }
@@ -6267,95 +6136,94 @@
ret rslt(cx, val);
}
-fn alloc_local(&@block_ctxt cx, &@ast::local local) -> result {
- auto t = node_id_type(bcx_ccx(cx), local.node.id);
- auto r = alloc_ty(cx, t);
- if (bcx_ccx(cx).sess.get_opts().debuginfo) {
+fn alloc_local(cx: &@block_ctxt, local: &@ast::local) -> result {
+ let t = node_id_type(bcx_ccx(cx), local.node.id);
+ let r = alloc_ty(cx, t);
+ if bcx_ccx(cx).sess.get_opts().debuginfo {
llvm::LLVMSetValueName(r.val, str::buf(local.node.ident));
}
r.bcx.fcx.lllocals.insert(local.node.id, r.val);
ret r;
}
-fn trans_block(&@block_ctxt cx, &ast::blk b, &out_method output) -> result {
- auto bcx = cx;
- for each (@ast::local local in block_locals(b)) {
+fn trans_block(cx: &@block_ctxt, b: &ast::blk, output: &out_method) ->
+ result {
+ let bcx = cx;
+ for each local: @ast::local in block_locals(b) {
// FIXME Update bcx.sp
bcx = alloc_local(bcx, local).bcx;
}
- auto r = rslt(bcx, C_nil());
- for (@ast::stmt s in b.node.stmts) {
+ let r = rslt(bcx, C_nil());
+ for s: @ast::stmt in b.node.stmts {
r = trans_stmt(bcx, *s);
bcx = r.bcx;
+
// If we hit a terminator, control won't go any further so
// we're in dead-code land. Stop here.
- if (is_terminated(bcx)) { ret r; }
+ if is_terminated(bcx) { ret r; }
}
- fn accept_out_method(&@ast::expr expr) -> bool {
- ret alt (expr.node) {
- case (ast::expr_if(_, _, _)) { true }
- case (ast::expr_alt(_, _)) { true }
- case (ast::expr_block(_)) { true }
- case (_) { false }
+ fn accept_out_method(expr: &@ast::expr) -> bool {
+ ret alt expr.node {
+ ast::expr_if(_, _, _) { true }
+ ast::expr_alt(_, _) { true }
+ ast::expr_block(_) { true }
+ _ { false }
};
}
- alt (b.node.expr) {
- case (some(?e)) {
- auto ccx = bcx_ccx(cx);
- auto r_ty = ty::expr_ty(ccx.tcx, e);
- auto pass = output != return && accept_out_method(e);
- if (pass) {
- r = trans_expr_out(bcx, e, output);
- bcx = r.bcx;
- if (is_terminated(bcx) || ty::type_is_bot(ccx.tcx, r_ty)) {
- ret r;
- }
- } else {
- auto lv = trans_lval(bcx, e);
- r = lv.res;
- bcx = r.bcx;
- if (is_terminated(bcx) || ty::type_is_bot(ccx.tcx, r_ty)) {
- ret r;
- }
- alt (output) {
- case (save_in(?target)) {
- // The output method is to save the value at target,
- // and we didn't pass it to the recursive trans_expr
- // call.
- bcx = move_val_if_temp(bcx, INIT, target,
- lv, r_ty).bcx;
- r = rslt(bcx, C_nil());
- }
- case (return) { }
- }
+ alt b.node.expr {
+ some(e) {
+ let ccx = bcx_ccx(cx);
+ let r_ty = ty::expr_ty(ccx.tcx, e);
+ let pass = output != return && accept_out_method(e);
+ if pass {
+ r = trans_expr_out(bcx, e, output);
+ bcx = r.bcx;
+ if is_terminated(bcx) || ty::type_is_bot(ccx.tcx, r_ty) { ret r; }
+ } else {
+ let lv = trans_lval(bcx, e);
+ r = lv.res;
+ bcx = r.bcx;
+ if is_terminated(bcx) || ty::type_is_bot(ccx.tcx, r_ty) { ret r; }
+ alt output {
+ save_in(target) {
+ // The output method is to save the value at target,
+ // and we didn't pass it to the recursive trans_expr
+ // call.
+ bcx = move_val_if_temp(bcx, INIT, target, lv, r_ty).bcx;
+ r = rslt(bcx, C_nil());
+ }
+ return. { }
}
}
- case (none) { r = rslt(bcx, C_nil()); }
+ }
+ none. { r = rslt(bcx, C_nil()); }
}
bcx = trans_block_cleanups(bcx, find_scope_cx(bcx));
ret rslt(bcx, r.val);
}
-fn new_local_ctxt(&@crate_ctxt ccx) -> @local_ctxt {
- let str[] pth = ~[];
- ret @rec(path=pth,
- module_path=~[ccx.link_meta.name],
- obj_typarams=~[],
- obj_fields=~[],
- ccx=ccx);
+fn new_local_ctxt(ccx: &@crate_ctxt) -> @local_ctxt {
+ let pth: str[] = ~[];
+ ret @{path: pth,
+ module_path: ~[ccx.link_meta.name],
+ obj_typarams: ~[],
+ obj_fields: ~[],
+ ccx: ccx};
}
// Creates the standard quartet of basic blocks: static allocas, copy args,
// derived tydescs, and dynamic allocas.
-fn mk_standard_basic_blocks(ValueRef llfn) ->
- rec(BasicBlockRef sa, BasicBlockRef ca,
- BasicBlockRef dt, BasicBlockRef da) {
- ret rec(sa=llvm::LLVMAppendBasicBlock(llfn, str::buf("static_allocas")),
- ca=llvm::LLVMAppendBasicBlock(llfn, str::buf("copy_args")),
- dt=llvm::LLVMAppendBasicBlock(llfn, str::buf("derived_tydescs")),
- da=llvm::LLVMAppendBasicBlock(llfn, str::buf("dynamic_allocas")));
+fn mk_standard_basic_blocks(llfn: ValueRef) ->
+ {sa: BasicBlockRef,
+ ca: BasicBlockRef,
+ dt: BasicBlockRef,
+ da: BasicBlockRef} {
+ ret {sa: llvm::LLVMAppendBasicBlock(llfn, str::buf("static_allocas")),
+ ca: llvm::LLVMAppendBasicBlock(llfn, str::buf("copy_args")),
+ dt: llvm::LLVMAppendBasicBlock(llfn, str::buf("derived_tydescs")),
+ da: llvm::LLVMAppendBasicBlock(llfn, str::buf("dynamic_allocas"))};
}
@@ -6365,37 +6233,37 @@
// - create_llargs_for_fn_args.
// - new_fn_ctxt
// - trans_args
-fn new_fn_ctxt(@local_ctxt cx, &span sp, ValueRef llfndecl) -> @fn_ctxt {
- let ValueRef llretptr = llvm::LLVMGetParam(llfndecl, 0u);
- let ValueRef lltaskptr = llvm::LLVMGetParam(llfndecl, 1u);
- let ValueRef llenv = llvm::LLVMGetParam(llfndecl, 2u);
- let hashmap[ast::node_id, ValueRef] llargs = new_int_hash[ValueRef]();
- let hashmap[ast::node_id, ValueRef] llobjfields =
+fn new_fn_ctxt(cx: @local_ctxt, sp: &span, llfndecl: ValueRef) -> @fn_ctxt {
+ let llretptr: ValueRef = llvm::LLVMGetParam(llfndecl, 0u);
+ let lltaskptr: ValueRef = llvm::LLVMGetParam(llfndecl, 1u);
+ let llenv: ValueRef = llvm::LLVMGetParam(llfndecl, 2u);
+ let llargs: hashmap[ast::node_id, ValueRef] = new_int_hash[ValueRef]();
+ let llobjfields: hashmap[ast::node_id, ValueRef] =
new_int_hash[ValueRef]();
- let hashmap[ast::node_id, ValueRef] lllocals = new_int_hash[ValueRef]();
- let hashmap[ast::node_id, ValueRef] llupvars = new_int_hash[ValueRef]();
- auto derived_tydescs =
+ let lllocals: hashmap[ast::node_id, ValueRef] = new_int_hash[ValueRef]();
+ let llupvars: hashmap[ast::node_id, ValueRef] = new_int_hash[ValueRef]();
+ let derived_tydescs =
map::mk_hashmap[ty::t, derived_tydesc_info](ty::hash_ty, ty::eq_ty);
- auto llbbs = mk_standard_basic_blocks(llfndecl);
- ret @rec(llfn=llfndecl,
- lltaskptr=lltaskptr,
- llenv=llenv,
- llretptr=llretptr,
- mutable llstaticallocas=llbbs.sa,
- mutable llcopyargs=llbbs.ca,
- mutable llderivedtydescs_first=llbbs.dt,
- mutable llderivedtydescs=llbbs.dt,
- mutable lldynamicallocas=llbbs.da,
- mutable llself=none[val_self_pair],
- mutable lliterbody=none[ValueRef],
- llargs=llargs,
- llobjfields=llobjfields,
- lllocals=lllocals,
- llupvars=llupvars,
- mutable lltydescs=~[],
- derived_tydescs=derived_tydescs,
- sp=sp,
- lcx=cx);
+ let llbbs = mk_standard_basic_blocks(llfndecl);
+ ret @{llfn: llfndecl,
+ lltaskptr: lltaskptr,
+ llenv: llenv,
+ llretptr: llretptr,
+ mutable llstaticallocas: llbbs.sa,
+ mutable llcopyargs: llbbs.ca,
+ mutable llderivedtydescs_first: llbbs.dt,
+ mutable llderivedtydescs: llbbs.dt,
+ mutable lldynamicallocas: llbbs.da,
+ mutable llself: none[val_self_pair],
+ mutable lliterbody: none[ValueRef],
+ llargs: llargs,
+ llobjfields: llobjfields,
+ lllocals: lllocals,
+ llupvars: llupvars,
+ mutable lltydescs: ~[],
+ derived_tydescs: derived_tydescs,
+ sp: sp,
+ lcx: cx};
}
@@ -6413,45 +6281,43 @@
// spaces that have been created for them (by code in the llallocas field of
// the function's fn_ctxt). create_llargs_for_fn_args populates the llargs
// field of the fn_ctxt with
-fn create_llargs_for_fn_args(&@fn_ctxt cx, ast::proto proto,
- option::t[ty::t] ty_self, ty::t ret_ty,
- &ast::arg[] args,
- &ast::ty_param[] ty_params) {
+fn create_llargs_for_fn_args(cx: &@fn_ctxt, proto: ast::proto,
+ ty_self: option::t[ty::t], ret_ty: ty::t,
+ args: &ast::arg[], ty_params: &ast::ty_param[]) {
// Skip the implicit arguments 0, 1, and 2. TODO: Pull out 3u and define
// it as a constant, since we're using it in several places in trans this
// way.
- auto arg_n = 3u;
- alt (ty_self) {
- case (some(?tt)) {
- cx.llself = some[val_self_pair](rec(v=cx.llenv, t=tt));
+ let arg_n = 3u;
+ alt ty_self {
+ some(tt) { cx.llself = some[val_self_pair]({v: cx.llenv, t: tt}); }
+ none. {
+ let i = 0u;
+ for tp: ast::ty_param in ty_params {
+ let llarg = llvm::LLVMGetParam(cx.llfn, arg_n);
+ assert (llarg as int != 0);
+ cx.lltydescs += ~[llarg];
+ arg_n += 1u;
+ i += 1u;
}
- case (none) {
- auto i = 0u;
- for (ast::ty_param tp in ty_params) {
- auto llarg = llvm::LLVMGetParam(cx.llfn, arg_n);
- assert (llarg as int != 0);
- cx.lltydescs += ~[llarg];
- arg_n += 1u;
- i += 1u;
- }
- }
+ }
}
// If the function is actually an iter, populate the lliterbody field of
// the function context with the ValueRef that we get from
// llvm::LLVMGetParam for the iter's body.
- if (proto == ast::proto_iter) {
- auto llarg = llvm::LLVMGetParam(cx.llfn, arg_n);
+ if proto == ast::proto_iter {
+ let llarg = llvm::LLVMGetParam(cx.llfn, arg_n);
assert (llarg as int != 0);
cx.lliterbody = some[ValueRef](llarg);
arg_n += 1u;
}
+
// Populate the llargs field of the function context with the ValueRefs
// that we get from llvm::LLVMGetParam for each argument.
- for (ast::arg arg in args) {
- auto llarg = llvm::LLVMGetParam(cx.llfn, arg_n);
+ for arg: ast::arg in args {
+ let llarg = llvm::LLVMGetParam(cx.llfn, arg_n);
assert (llarg as int != 0);
cx.llargs.insert(arg.id, llarg);
arg_n += 1u;
@@ -6462,30 +6328,33 @@
// Recommended LLVM style, strange though this is, is to copy from args to
// allocas immediately upon entry; this permits us to GEP into structures we
// were passed and whatnot. Apparently mem2reg will mop up.
-fn copy_any_self_to_alloca(@fn_ctxt fcx) {
- auto bcx = llstaticallocas_block_ctxt(fcx);
- alt ({ fcx.llself }) {
- case (some(?pair)) {
- auto a = alloca(bcx, fcx.lcx.ccx.rust_object_type);
- bcx.build.Store(pair.v, a);
- fcx.llself = some[val_self_pair](rec(v=a, t=pair.t));
- }
- case (_) { }
+fn copy_any_self_to_alloca(fcx: @fn_ctxt) {
+ let bcx = llstaticallocas_block_ctxt(fcx);
+ alt { fcx.llself } {
+ some(pair) {
+ let a = alloca(bcx, fcx.lcx.ccx.rust_object_type);
+ bcx.build.Store(pair.v, a);
+ fcx.llself = some[val_self_pair]({v: a, t: pair.t});
+ }
+ _ { }
}
}
-fn copy_args_to_allocas(@fn_ctxt fcx, &ast::arg[] args, &ty::arg[] arg_tys) {
- auto bcx = new_raw_block_ctxt(fcx, fcx.llcopyargs);
- let uint arg_n = 0u;
- for (ast::arg aarg in args) {
- if (aarg.mode == ast::val) {
- auto arg_t = type_of_arg(bcx.fcx.lcx, fcx.sp, arg_tys.(arg_n));
- auto a = alloca(bcx, arg_t);
- auto argval;
- alt (bcx.fcx.llargs.find(aarg.id)) {
- case (some(?x)) { argval = x; }
- case (_) { bcx_ccx(bcx).sess.span_fatal(aarg.ty.span,
- "unbound arg ID in copy_args_to_allocas"); }
+fn copy_args_to_allocas(fcx: @fn_ctxt, args: &ast::arg[],
+ arg_tys: &ty::arg[]) {
+ let bcx = new_raw_block_ctxt(fcx, fcx.llcopyargs);
+ let arg_n: uint = 0u;
+ for aarg: ast::arg in args {
+ if aarg.mode == ast::val {
+ let arg_t = type_of_arg(bcx.fcx.lcx, fcx.sp, arg_tys.(arg_n));
+ let a = alloca(bcx, arg_t);
+ let argval;
+ alt bcx.fcx.llargs.find(aarg.id) {
+ some(x) { argval = x; }
+ _ {
+ bcx_ccx(bcx).sess.span_fatal(aarg.ty.span,
+ "unbound arg ID in copy_args_to_allocas");
+ }
}
bcx.build.Store(argval, a);
// Overwrite the llargs entry for this arg with its alloca.
@@ -6496,16 +6365,18 @@
}
}
-fn add_cleanups_for_args(&@block_ctxt bcx, &ast::arg[] args,
- &ty::arg[] arg_tys) {
- let uint arg_n = 0u;
- for (ast::arg aarg in args) {
- if (aarg.mode == ast::val) {
- auto argval;
- alt (bcx.fcx.llargs.find(aarg.id)) {
- case (some(?x)) { argval = x; }
- case (_) { bcx_ccx(bcx).sess.span_fatal(aarg.ty.span,
- "unbound arg ID in copy_args_to_allocas"); }
+fn add_cleanups_for_args(bcx: &@block_ctxt, args: &ast::arg[],
+ arg_tys: &ty::arg[]) {
+ let arg_n: uint = 0u;
+ for aarg: ast::arg in args {
+ if aarg.mode == ast::val {
+ let argval;
+ alt bcx.fcx.llargs.find(aarg.id) {
+ some(x) { argval = x; }
+ _ {
+ bcx_ccx(bcx).sess.span_fatal(aarg.ty.span,
+ "unbound arg ID in copy_args_to_allocas");
+ }
}
add_clean(bcx, argval, arg_tys.(arg_n).ty);
}
@@ -6513,63 +6384,63 @@
}
}
-fn is_terminated(&@block_ctxt cx) -> bool {
- auto inst = llvm::LLVMGetLastInstruction(cx.llbb);
+fn is_terminated(cx: &@block_ctxt) -> bool {
+ let inst = llvm::LLVMGetLastInstruction(cx.llbb);
ret llvm::LLVMIsATerminatorInst(inst) as int != 0;
}
-fn arg_tys_of_fn(&@crate_ctxt ccx,ast::node_id id) -> ty::arg[] {
- alt (ty::struct(ccx.tcx, ty::node_id_to_type(ccx.tcx, id))) {
- case (ty::ty_fn(_, ?arg_tys, _, _, _)) { ret arg_tys; }
+fn arg_tys_of_fn(ccx: &@crate_ctxt, id: ast::node_id) -> ty::arg[] {
+ alt ty::struct(ccx.tcx, ty::node_id_to_type(ccx.tcx, id)) {
+ ty::ty_fn(_, arg_tys, _, _, _) { ret arg_tys; }
}
}
-fn populate_fn_ctxt_from_llself(@fn_ctxt fcx, val_self_pair llself) {
- auto bcx = llstaticallocas_block_ctxt(fcx);
- let ty::t[] field_tys = ~[];
- for (ast::obj_field f in bcx.fcx.lcx.obj_fields) {
+fn populate_fn_ctxt_from_llself(fcx: @fn_ctxt, llself: val_self_pair) {
+ let bcx = llstaticallocas_block_ctxt(fcx);
+ let field_tys: ty::t[] = ~[];
+ for f: ast::obj_field in bcx.fcx.lcx.obj_fields {
field_tys += ~[node_id_type(bcx_ccx(bcx), f.id)];
}
// Synthesize a tuple type for the fields so that GEP_tup_like() can work
// its magic.
- auto fields_tup_ty = ty::mk_imm_tup(fcx.lcx.ccx.tcx, field_tys);
- auto n_typarams = std::ivec::len[ast::ty_param](bcx.fcx.lcx.obj_typarams);
- let TypeRef llobj_box_ty = T_obj_ptr(*bcx_ccx(bcx), n_typarams);
- auto box_cell =
+ let fields_tup_ty = ty::mk_imm_tup(fcx.lcx.ccx.tcx, field_tys);
+ let n_typarams = std::ivec::len[ast::ty_param](bcx.fcx.lcx.obj_typarams);
+ let llobj_box_ty: TypeRef = T_obj_ptr(*bcx_ccx(bcx), n_typarams);
+ let box_cell =
bcx.build.GEP(llself.v, ~[C_int(0), C_int(abi::obj_field_box)]);
- auto box_ptr = bcx.build.Load(box_cell);
+ let box_ptr = bcx.build.Load(box_cell);
box_ptr = bcx.build.PointerCast(box_ptr, llobj_box_ty);
- auto obj_typarams =
+ let obj_typarams =
bcx.build.GEP(box_ptr,
~[C_int(0), C_int(abi::box_rc_field_body),
- C_int(abi::obj_body_elt_typarams)]);
+ C_int(abi::obj_body_elt_typarams)]);
// The object fields immediately follow the type parameters, so we skip
// over them to get the pointer.
- auto et = llvm::LLVMGetElementType(val_ty(obj_typarams));
- auto obj_fields = bcx.build.Add(vp2i(bcx, obj_typarams), llsize_of(et));
+ let et = llvm::LLVMGetElementType(val_ty(obj_typarams));
+ let obj_fields = bcx.build.Add(vp2i(bcx, obj_typarams), llsize_of(et));
// If we can (i.e. the type is statically sized), then cast the resulting
// fields pointer to the appropriate LLVM type. If not, just leave it as
// i8 *.
- if (!ty::type_has_dynamic_size(fcx.lcx.ccx.tcx, fields_tup_ty)) {
- auto llfields_ty = type_of(fcx.lcx.ccx, fcx.sp, fields_tup_ty);
+ if !ty::type_has_dynamic_size(fcx.lcx.ccx.tcx, fields_tup_ty) {
+ let llfields_ty = type_of(fcx.lcx.ccx, fcx.sp, fields_tup_ty);
obj_fields = vi2p(bcx, obj_fields, T_ptr(llfields_ty));
} else { obj_fields = vi2p(bcx, obj_fields, T_ptr(T_i8())); }
- let int i = 0;
- for (ast::ty_param p in fcx.lcx.obj_typarams) {
- let ValueRef lltyparam =
+ let i: int = 0;
+ for p: ast::ty_param in fcx.lcx.obj_typarams {
+ let lltyparam: ValueRef =
bcx.build.GEP(obj_typarams, ~[C_int(0), C_int(i)]);
lltyparam = bcx.build.Load(lltyparam);
fcx.lltydescs += ~[lltyparam];
i += 1;
}
i = 0;
- for (ast::obj_field f in fcx.lcx.obj_fields) {
- auto rslt = GEP_tup_like(bcx, fields_tup_ty, obj_fields, ~[0, i]);
+ for f: ast::obj_field in fcx.lcx.obj_fields {
+ let rslt = GEP_tup_like(bcx, fields_tup_ty, obj_fields, ~[0, i]);
bcx = llstaticallocas_block_ctxt(fcx);
- auto llfield = rslt.val;
+ let llfield = rslt.val;
fcx.llobjfields.insert(f.id, llfield);
i += 1;
}
@@ -6579,7 +6450,7 @@
// Ties up the llstaticallocas -> llcopyargs -> llderivedtydescs ->
// lldynamicallocas -> lltop edges.
-fn finish_fn(&@fn_ctxt fcx, BasicBlockRef lltop) {
+fn finish_fn(fcx: &@fn_ctxt, lltop: BasicBlockRef) {
new_builder(fcx.llstaticallocas).Br(fcx.llcopyargs);
new_builder(fcx.llcopyargs).Br(fcx.llderivedtydescs_first);
new_builder(fcx.llderivedtydescs).Br(fcx.lldynamicallocas);
@@ -6589,78 +6460,75 @@
// trans_closure: Builds an LLVM function out of a source function.
// If the function closes over its environment a closure will be
// returned.
-fn trans_closure(&option::t[@block_ctxt] bcx_maybe,
- &option::t[TypeRef] llfnty,
- @local_ctxt cx,
- &span sp, &ast::_fn f, ValueRef llfndecl,
- option::t[ty::t] ty_self,
- &ast::ty_param[] ty_params, ast::node_id id)
- -> option::t[ValueRef] {
+fn trans_closure(bcx_maybe: &option::t[@block_ctxt],
+ llfnty: &option::t[TypeRef], cx: @local_ctxt, sp: &span,
+ f: &ast::_fn, llfndecl: ValueRef, ty_self: option::t[ty::t],
+ ty_params: &ast::ty_param[], id: ast::node_id) ->
+ option::t[ValueRef] {
set_uwtable(llfndecl);
// Set up arguments to the function.
- auto fcx = new_fn_ctxt(cx, sp, llfndecl);
+ let fcx = new_fn_ctxt(cx, sp, llfndecl);
create_llargs_for_fn_args(fcx, f.proto, ty_self,
- ty::ret_ty_of_fn(cx.ccx.tcx, id),
- f.decl.inputs, ty_params);
+ ty::ret_ty_of_fn(cx.ccx.tcx, id), f.decl.inputs,
+ ty_params);
copy_any_self_to_alloca(fcx);
- alt ({ fcx.llself }) {
- some(?llself) { populate_fn_ctxt_from_llself(fcx, llself); }
- _ { }
+ alt { fcx.llself } {
+ some(llself) { populate_fn_ctxt_from_llself(fcx, llself); }
+ _ { }
}
- auto arg_tys = arg_tys_of_fn(fcx.lcx.ccx, id);
+ let arg_tys = arg_tys_of_fn(fcx.lcx.ccx, id);
copy_args_to_allocas(fcx, f.decl.inputs, arg_tys);
// Figure out if we need to build a closure and act accordingly
- auto closure = none;
- alt(f.proto) {
- ast::proto_block {
- auto bcx = option::get(bcx_maybe);
- auto upvars = get_freevars(cx.ccx.tcx, id);
+ let closure = none;
+ alt f.proto {
+ ast::proto_block. {
+ let bcx = option::get(bcx_maybe);
+ let upvars = get_freevars(cx.ccx.tcx, id);
- auto llenv = build_environment(bcx, upvars);
+ let llenv = build_environment(bcx, upvars);
- // Generate code to load the environment out of the
- // environment pointer.
- load_environment(bcx, fcx, llenv.ptrty, upvars);
- // Build the closure.
- closure = some(create_real_fn_pair(bcx, option::get(llfnty),
- llfndecl, llenv.ptr));
- }
- ast::proto_closure {
- fail "copy capture not implemented yet";
- }
- _ {}
+ // Generate code to load the environment out of the
+ // environment pointer.
+ load_environment(bcx, fcx, llenv.ptrty, upvars);
+ // Build the closure.
+ closure =
+ some(create_real_fn_pair(bcx, option::get(llfnty), llfndecl,
+ llenv.ptr));
+ }
+ ast::proto_closure. { fail "copy capture not implemented yet"; }
+ _ { }
}
// Create the first basic block in the function and keep a handle on it to
// pass to finish_fn later.
- auto bcx = new_top_block_ctxt(fcx);
+ let bcx = new_top_block_ctxt(fcx);
add_cleanups_for_args(bcx, f.decl.inputs, arg_tys);
- auto lltop = bcx.llbb;
- auto block_ty = node_id_type(cx.ccx, f.body.node.id);
+ let lltop = bcx.llbb;
+ let block_ty = node_id_type(cx.ccx, f.body.node.id);
- if (cx.ccx.sess.get_opts().dps) {
+ if cx.ccx.sess.get_opts().dps {
// Call into the new destination-passing-style translation engine.
- auto dest = trans_dps::dest_move(cx.ccx.tcx, fcx.llretptr, block_ty);
+ let dest = trans_dps::dest_move(cx.ccx.tcx, fcx.llretptr, block_ty);
bcx = trans_dps::trans_block(bcx, dest, f.body);
} else {
// This call to trans_block is the place where we bridge between
// translation calls that don't have a return value (trans_crate,
// trans_mod, trans_item, trans_obj, et cetera) and those that do
// (trans_block, trans_expr, et cetera).
- auto rslt =
- if (!ty::type_is_nil(cx.ccx.tcx, block_ty) &&
- !ty::type_is_bot(cx.ccx.tcx, block_ty)) {
+ let rslt =
+ if !ty::type_is_nil(cx.ccx.tcx, block_ty) &&
+ !ty::type_is_bot(cx.ccx.tcx, block_ty) {
trans_block(bcx, f.body, save_in(fcx.llretptr))
} else { trans_block(bcx, f.body, return) };
bcx = rslt.bcx;
}
- if (!is_terminated(bcx)) {
+ if !is_terminated(bcx) {
// FIXME: until LLVM has a unit type, we are moving around
// C_nil values rather than their void type.
- bcx.build.RetVoid();
+ bcx.build.RetVoid();
}
// Insert the mandatory first few basic blocks before lltop.
@@ -6669,36 +6537,35 @@
ret closure;
}
-fn trans_fn_inner(@local_ctxt cx, &span sp, &ast::_fn f, ValueRef llfndecl,
- option::t[ty::t] ty_self, &ast::ty_param[] ty_params,
- ast::node_id id) {
+fn trans_fn_inner(cx: @local_ctxt, sp: &span, f: &ast::_fn,
+ llfndecl: ValueRef, ty_self: option::t[ty::t],
+ ty_params: &ast::ty_param[], id: ast::node_id) {
trans_closure(none, none, cx, sp, f, llfndecl, ty_self, ty_params, id);
}
// trans_fn: creates an LLVM function corresponding to a source language
// function.
-fn trans_fn(@local_ctxt cx, &span sp, &ast::_fn f, ValueRef llfndecl,
- option::t[ty::t] ty_self, &ast::ty_param[] ty_params,
- ast::node_id id) {
+fn trans_fn(cx: @local_ctxt, sp: &span, f: &ast::_fn, llfndecl: ValueRef,
+ ty_self: option::t[ty::t], ty_params: &ast::ty_param[],
+ id: ast::node_id) {
if !cx.ccx.sess.get_opts().stats {
trans_fn_inner(cx, sp, f, llfndecl, ty_self, ty_params, id);
ret;
}
- auto start = time::get_time();
+ let start = time::get_time();
trans_fn_inner(cx, sp, f, llfndecl, ty_self, ty_params, id);
- auto end = time::get_time();
+ let end = time::get_time();
log_fn_time(cx.ccx, str::connect_ivec(cx.path, "::"), start, end);
}
// process_fwding_mthd: Create the forwarding function that appears in a
// vtable slot for method calls that "fall through" to an inner object. A
// helper function for create_vtbl.
-fn process_fwding_mthd(@local_ctxt cx, &span sp, @ty::method m,
- &ast::ty_param[] ty_params,
- ty::t with_obj_ty,
- &ty::t[] additional_field_tys) -> ValueRef {
+fn process_fwding_mthd(cx: @local_ctxt, sp: &span, m: @ty::method,
+ ty_params: &ast::ty_param[], with_obj_ty: ty::t,
+ additional_field_tys: &ty::t[]) -> ValueRef {
// The method m is being called on the outer object, but the outer object
@@ -6713,45 +6580,42 @@
// Create a local context that's aware of the name of the method we're
// creating.
- let @local_ctxt mcx =
- @rec(path=cx.path + ~["method", m.ident] with *cx);
+ let mcx: @local_ctxt = @{path: cx.path + ~["method", m.ident] with *cx};
// Make up a name for the forwarding function.
- let str s = mangle_internal_name_by_path_and_seq(mcx.ccx, mcx.path,
- "forwarding_fn");
+ let s: str =
+ mangle_internal_name_by_path_and_seq(mcx.ccx, mcx.path,
+ "forwarding_fn");
// Get the forwarding function's type and declare it.
- let TypeRef llforwarding_fn_ty =
- type_of_fn_full(
- cx.ccx, sp, m.proto,
- true, m.inputs, m.output,
- std::ivec::len[ast::ty_param](ty_params));
- let ValueRef llforwarding_fn =
+ let llforwarding_fn_ty: TypeRef =
+ type_of_fn_full(cx.ccx, sp, m.proto, true, m.inputs, m.output,
+ std::ivec::len[ast::ty_param](ty_params));
+ let llforwarding_fn: ValueRef =
decl_internal_fastcall_fn(cx.ccx.llmod, s, llforwarding_fn_ty);
// Create a new function context and block context for the forwarding
// function, holding onto a pointer to the first block.
- auto fcx = new_fn_ctxt(cx, sp, llforwarding_fn);
- auto bcx = new_top_block_ctxt(fcx);
- auto lltop = bcx.llbb;
+ let fcx = new_fn_ctxt(cx, sp, llforwarding_fn);
+ let bcx = new_top_block_ctxt(fcx);
+ let lltop = bcx.llbb;
// The outer object will arrive in the forwarding function via the llenv
// argument. Put it in an alloca so that we can GEP into it later.
- auto llself_obj_ptr = alloca(bcx, fcx.lcx.ccx.rust_object_type);
+ let llself_obj_ptr = alloca(bcx, fcx.lcx.ccx.rust_object_type);
bcx.build.Store(fcx.llenv, llself_obj_ptr);
// Grab hold of the outer object so we can pass it into the inner object,
// in case that inner object needs to make any self-calls. (Such calls
// will need to dispatch back through the outer object.)
- auto llself_obj = bcx.build.Load(llself_obj_ptr);
+ let llself_obj = bcx.build.Load(llself_obj_ptr);
// The 'llretptr' that will arrive in the forwarding function we're
// creating also needs to be the correct size. Cast it to the size of the
// method's return type, if necessary.
- auto llretptr = fcx.llretptr;
- if (ty::type_has_dynamic_size(cx.ccx.tcx, m.output)) {
- llretptr = bcx.build.PointerCast(llretptr,
- T_typaram_ptr(cx.ccx.tn));
+ let llretptr = fcx.llretptr;
+ if ty::type_has_dynamic_size(cx.ccx.tcx, m.output) {
+ llretptr = bcx.build.PointerCast(llretptr, T_typaram_ptr(cx.ccx.tn));
}
// Now, we have to get the the with_obj's vtbl out of the self_obj. This
@@ -6759,19 +6623,18 @@
// First, grab the box out of the self_obj. It contains a refcount and a
// body.
- auto llself_obj_box =
- bcx.build.GEP(llself_obj_ptr, ~[C_int(0),
- C_int(abi::obj_field_box)]);
+ let llself_obj_box =
+ bcx.build.GEP(llself_obj_ptr, ~[C_int(0), C_int(abi::obj_field_box)]);
llself_obj_box = bcx.build.Load(llself_obj_box);
- auto ccx = bcx_ccx(bcx);
- auto llbox_ty = T_opaque_obj_ptr(*ccx);
+ let ccx = bcx_ccx(bcx);
+ let llbox_ty = T_opaque_obj_ptr(*ccx);
llself_obj_box = bcx.build.PointerCast(llself_obj_box, llbox_ty);
// Now, reach into the box and grab the body.
- auto llself_obj_body =
- bcx.build.GEP(llself_obj_box, ~[C_int(0),
- C_int(abi::box_rc_field_body)]);
+ let llself_obj_body =
+ bcx.build.GEP(llself_obj_box,
+ ~[C_int(0), C_int(abi::box_rc_field_body)]);
// Now, we need to figure out exactly what type the body is supposed to be
// cast to.
@@ -6780,30 +6643,28 @@
// It would be great to factor this out.
// Synthesize a tuple type for fields: [field, ...]
- let ty::t fields_ty = ty::mk_imm_tup(cx.ccx.tcx, additional_field_tys);
+ let fields_ty: ty::t = ty::mk_imm_tup(cx.ccx.tcx, additional_field_tys);
// Type for tydescs.
- let ty::t tydesc_ty = ty::mk_type(cx.ccx.tcx);
+ let tydesc_ty: ty::t = ty::mk_type(cx.ccx.tcx);
// Placeholder for non-existent typarams, since anon objs don't have them.
- let ty::t typarams_ty = ty::mk_imm_tup(cx.ccx.tcx, ~[]);
+ let typarams_ty: ty::t = ty::mk_imm_tup(cx.ccx.tcx, ~[]);
// Tuple type for body:
// [tydesc, [typaram, ...], [field, ...], with_obj]
- let ty::t body_ty =
- ty::mk_imm_tup(cx.ccx.tcx, ~[tydesc_ty, typarams_ty,
- fields_ty, with_obj_ty]);
+ let body_ty: ty::t =
+ ty::mk_imm_tup(cx.ccx.tcx,
+ ~[tydesc_ty, typarams_ty, fields_ty, with_obj_ty]);
// And cast to that type.
- llself_obj_body = bcx.build.PointerCast(llself_obj_body,
- T_ptr(type_of(cx.ccx, sp,
- body_ty)));
+ llself_obj_body =
+ bcx.build.PointerCast(llself_obj_body,
+ T_ptr(type_of(cx.ccx, sp, body_ty)));
// Now, reach into the body and grab the with_obj.
- auto llwith_obj =
- GEP_tup_like(bcx,
- body_ty,
- llself_obj_body,
+ let llwith_obj =
+ GEP_tup_like(bcx, body_ty, llself_obj_body,
~[0, abi::obj_body_elt_with_obj]);
bcx = llwith_obj.bcx;
@@ -6811,56 +6672,54 @@
// method we want. First, pick out the vtable, and then pluck that
// method's entry out of the vtable so that the forwarding function can
// call it.
- auto llwith_obj_vtbl =
- bcx.build.GEP(llwith_obj.val, ~[C_int(0),
- C_int(abi::obj_field_vtbl)]);
+ let llwith_obj_vtbl =
+ bcx.build.GEP(llwith_obj.val,
+ ~[C_int(0), C_int(abi::obj_field_vtbl)]);
llwith_obj_vtbl = bcx.build.Load(llwith_obj_vtbl);
// Get the index of the method we want.
- let uint ix = 0u;
- alt (ty::struct(bcx_tcx(bcx), with_obj_ty)) {
- case (ty::ty_obj(?methods)) {
- ix = ty::method_idx(cx.ccx.sess, sp, m.ident, methods);
- }
- case (_) {
- // Shouldn't happen.
- cx.ccx.sess.bug("process_fwding_mthd(): non-object type passed "
- + "as with_obj_ty");
- }
+ let ix: uint = 0u;
+ alt ty::struct(bcx_tcx(bcx), with_obj_ty) {
+ ty::ty_obj(methods) {
+ ix = ty::method_idx(cx.ccx.sess, sp, m.ident, methods);
+ }
+ _ {
+ // Shouldn't happen.
+ cx.ccx.sess.bug("process_fwding_mthd(): non-object type passed " +
+ "as with_obj_ty");
+ }
}
// Pick out the original method from the vtable. The +1 is because slot
// #0 contains the destructor.
- auto vtbl_type = T_ptr(T_array(T_ptr(T_nil()), ix + 2u));
+ let vtbl_type = T_ptr(T_array(T_ptr(T_nil()), ix + 2u));
llwith_obj_vtbl = bcx.build.PointerCast(llwith_obj_vtbl, vtbl_type);
- auto llorig_mthd = bcx.build.GEP(llwith_obj_vtbl,
- ~[C_int(0), C_int(ix + 1u as int)]);
+ let llorig_mthd =
+ bcx.build.GEP(llwith_obj_vtbl, ~[C_int(0), C_int(ix + 1u as int)]);
// Set up the original method to be called.
- auto orig_mthd_ty = ty::method_ty_to_fn_ty(cx.ccx.tcx, *m);
- auto llorig_mthd_ty =
+ let orig_mthd_ty = ty::method_ty_to_fn_ty(cx.ccx.tcx, *m);
+ let llorig_mthd_ty =
type_of_fn_full(bcx_ccx(bcx), sp,
- ty::ty_fn_proto(bcx_tcx(bcx), orig_mthd_ty),
- true,
- m.inputs,
- m.output,
+ ty::ty_fn_proto(bcx_tcx(bcx), orig_mthd_ty), true,
+ m.inputs, m.output,
std::ivec::len[ast::ty_param](ty_params));
- llorig_mthd = bcx.build.PointerCast(llorig_mthd,
- T_ptr(T_ptr(llorig_mthd_ty)));
+ llorig_mthd =
+ bcx.build.PointerCast(llorig_mthd, T_ptr(T_ptr(llorig_mthd_ty)));
llorig_mthd = bcx.build.Load(llorig_mthd);
// Set up the three implicit arguments to the original method we'll need
// to call.
- let ValueRef[] llorig_mthd_args = ~[llretptr, fcx.lltaskptr, llself_obj];
+ let llorig_mthd_args: ValueRef[] = ~[llretptr, fcx.lltaskptr, llself_obj];
// Copy the explicit arguments that are being passed into the forwarding
// function (they're in fcx.llargs) to llorig_mthd_args.
- let uint a = 3u; // retptr, task ptr, env come first
- let ValueRef passed_arg = llvm::LLVMGetParam(llforwarding_fn, a);
- for (ty::arg arg in m.inputs) {
- if (arg.mode == ty::mo_val) {
+ let a: uint = 3u; // retptr, task ptr, env come first
+ let passed_arg: ValueRef = llvm::LLVMGetParam(llforwarding_fn, a);
+ for arg: ty::arg in m.inputs {
+ if arg.mode == ty::mo_val {
passed_arg = load_if_immediate(bcx, passed_arg, arg.ty);
}
llorig_mthd_args += ~[passed_arg];
@@ -6878,208 +6737,194 @@
// process_normal_mthd: Create the contents of a normal vtable slot. A helper
// function for create_vtbl.
-fn process_normal_mthd(@local_ctxt cx, @ast::method m,
- ty::t self_ty, &ast::ty_param[] ty_params)
- -> ValueRef {
+fn process_normal_mthd(cx: @local_ctxt, m: @ast::method, self_ty: ty::t,
+ ty_params: &ast::ty_param[]) -> ValueRef {
- auto llfnty = T_nil();
- alt (ty::struct(cx.ccx.tcx, node_id_type(cx.ccx, m.node.id))){
- case (ty::ty_fn(?proto, ?inputs, ?output, _, _)) {
- llfnty =
- type_of_fn_full(
- cx.ccx, m.span, proto,
- true, inputs, output,
- std::ivec::len[ast::ty_param](ty_params));
- }
+ let llfnty = T_nil();
+ alt ty::struct(cx.ccx.tcx, node_id_type(cx.ccx, m.node.id)) {
+ ty::ty_fn(proto, inputs, output, _, _) {
+ llfnty =
+ type_of_fn_full(cx.ccx, m.span, proto, true, inputs, output,
+ std::ivec::len[ast::ty_param](ty_params));
+ }
}
- let @local_ctxt mcx =
- @rec(path=cx.path + ~["method", m.node.ident] with *cx);
- let str s = mangle_internal_name_by_path(mcx.ccx, mcx.path);
- let ValueRef llfn =
- decl_internal_fastcall_fn(cx.ccx.llmod, s, llfnty);
+ let mcx: @local_ctxt =
+ @{path: cx.path + ~["method", m.node.ident] with *cx};
+ let s: str = mangle_internal_name_by_path(mcx.ccx, mcx.path);
+ let llfn: ValueRef = decl_internal_fastcall_fn(cx.ccx.llmod, s, llfnty);
// Every method on an object gets its node_id inserted into the
// crate-wide item_ids map, together with the ValueRef that points to
// where that method's definition will be in the executable.
cx.ccx.item_ids.insert(m.node.id, llfn);
cx.ccx.item_symbols.insert(m.node.id, s);
- trans_fn(mcx, m.span, m.node.meth, llfn,
- some(self_ty),
- ty_params, m.node.id);
+ trans_fn(mcx, m.span, m.node.meth, llfn, some(self_ty), ty_params,
+ m.node.id);
ret llfn;
}
// Create a vtable for an object being translated. Returns a pointer into
// read-only memory.
-fn create_vtbl(@local_ctxt cx, &span sp, ty::t self_ty,
- &ast::_obj ob, &ast::ty_param[] ty_params,
- option::t[ty::t] with_obj_ty,
- &ty::t[] additional_field_tys) -> ValueRef {
+fn create_vtbl(cx: @local_ctxt, sp: &span, self_ty: ty::t, ob: &ast::_obj,
+ ty_params: &ast::ty_param[], with_obj_ty: option::t[ty::t],
+ additional_field_tys: &ty::t[]) -> ValueRef {
// Used only inside create_vtbl to distinguish different kinds of slots
// we'll have to create.
tag vtbl_mthd {
+
// Normal methods are complete AST nodes, but for forwarding methods,
// the only information we'll have about them is their type.
normal_mthd(@ast::method);
fwding_mthd(@ty::method);
}
- auto dtor = C_null(T_ptr(T_i8()));
- alt (ob.dtor) {
- case (some(?d)) {
- auto dtor_1 = trans_dtor(cx, self_ty, ty_params, d);
- dtor = llvm::LLVMConstBitCast(dtor_1, val_ty(dtor));
- }
- case (none) { }
+ let dtor = C_null(T_ptr(T_i8()));
+ alt ob.dtor {
+ some(d) {
+ let dtor_1 = trans_dtor(cx, self_ty, ty_params, d);
+ dtor = llvm::LLVMConstBitCast(dtor_1, val_ty(dtor));
+ }
+ none. { }
}
- let ValueRef[] llmethods = ~[dtor];
- let vtbl_mthd[] meths = ~[];
+ let llmethods: ValueRef[] = ~[dtor];
+ let meths: vtbl_mthd[] = ~[];
- alt (with_obj_ty) {
- case (none) {
- // If there's no with_obj, then we don't need any forwarding
- // slots. Just use the object's regular methods.
- for (@ast::method m in ob.methods) { meths += ~[normal_mthd(m)]; }
+ alt with_obj_ty {
+ none. {
+
+ // If there's no with_obj, then we don't need any forwarding
+ // slots. Just use the object's regular methods.
+ for m: @ast::method in ob.methods { meths += ~[normal_mthd(m)]; }
+ }
+ some(with_obj_ty) {
+ // Handle forwarding slots.
+
+ // If this vtable is being created for an extended object, then
+ // the vtable needs to contain 'forwarding slots' for methods that
+ // were on the original object and are not being overloaded by the
+ // extended one. So, to find the set of methods that we need
+ // forwarding slots for, we need to take the set difference of
+ // with_obj_methods (methods on the original object) and
+ // ob.methods (methods on the object being added).
+
+ // If we're here, then with_obj_ty and llwith_obj_ty are the type
+ // of the inner object, and "ob" is the wrapper object. We need
+ // to take apart with_obj_ty (it had better have an object type
+ // with methods!) and put those original methods onto the list of
+ // methods we need forwarding methods for.
+
+ // Gather up methods on the original object in 'meths'.
+ alt ty::struct(cx.ccx.tcx, with_obj_ty) {
+ ty::ty_obj(with_obj_methods) {
+ for m: ty::method in with_obj_methods {
+ meths += ~[fwding_mthd(@m)];
+ }
+ }
+ _ {
+ // Shouldn't happen.
+ cx.ccx.sess.bug("create_vtbl(): trying to extend a " +
+ "non-object");
+ }
}
- case (some(?with_obj_ty)) {
- // Handle forwarding slots.
- // If this vtable is being created for an extended object, then
- // the vtable needs to contain 'forwarding slots' for methods that
- // were on the original object and are not being overloaded by the
- // extended one. So, to find the set of methods that we need
- // forwarding slots for, we need to take the set difference of
- // with_obj_methods (methods on the original object) and
- // ob.methods (methods on the object being added).
+ // Now, filter out any methods that we don't need forwarding slots
+ // for, because they're being replaced.
+ fn filtering_fn(cx: @local_ctxt, m: &vtbl_mthd,
+ addtl_meths: (@ast::method)[]) ->
+ option::t[vtbl_mthd] {
- // If we're here, then with_obj_ty and llwith_obj_ty are the type
- // of the inner object, and "ob" is the wrapper object. We need
- // to take apart with_obj_ty (it had better have an object type
- // with methods!) and put those original methods onto the list of
- // methods we need forwarding methods for.
- // Gather up methods on the original object in 'meths'.
- alt (ty::struct(cx.ccx.tcx, with_obj_ty)) {
- case (ty::ty_obj(?with_obj_methods)) {
- for (ty::method m in with_obj_methods) {
- meths += ~[fwding_mthd(@m)];
- }
+ alt m {
+ fwding_mthd(fm) {
+ // Since fm is a fwding_mthd, and we're checking to
+ // see if it's in addtl_meths (which only contains
+ // normal_mthds), we can't just check if fm is a
+ // member of addtl_meths. Instead, we have to go
+ // through addtl_meths and see if there's some method
+ // in it that has the same name as fm.
+
+ // FIXME (part of #543): We're only checking names
+ // here. If a method is replacing another, it also
+ // needs to have the same type, but this should
+ // probably be enforced in typechecking.
+ for am: @ast::method in addtl_meths {
+ if str::eq(am.node.ident, fm.ident) { ret none; }
}
- case (_) {
- // Shouldn't happen.
- cx.ccx.sess.bug("create_vtbl(): trying to extend a "
- + "non-object");
- }
- }
-
- // Now, filter out any methods that we don't need forwarding slots
- // for, because they're being replaced.
- fn filtering_fn(@local_ctxt cx, &vtbl_mthd m,
- (@ast::method)[] addtl_meths)
- -> option::t[vtbl_mthd] {
-
- alt (m) {
- case (fwding_mthd(?fm)) {
- // Since fm is a fwding_mthd, and we're checking to
- // see if it's in addtl_meths (which only contains
- // normal_mthds), we can't just check if fm is a
- // member of addtl_meths. Instead, we have to go
- // through addtl_meths and see if there's some method
- // in it that has the same name as fm.
-
- // FIXME (part of #543): We're only checking names
- // here. If a method is replacing another, it also
- // needs to have the same type, but this should
- // probably be enforced in typechecking.
- for (@ast::method am in addtl_meths) {
- if (str::eq(am.node.ident, fm.ident)) {
- ret none;
- }
- }
- ret some(fwding_mthd(fm));
- }
- case (normal_mthd(_)) {
- // Should never happen.
- cx.ccx.sess.bug("create_vtbl(): shouldn't be any"
- + " normal_mthds in meths here");
- }
- }
- }
- auto f = bind filtering_fn(cx, _, ob.methods);
- meths = std::ivec::filter_map[vtbl_mthd, vtbl_mthd](f, meths);
-
- // And now add the additional ones (both replacements and entirely
- // new ones). These'll just be normal methods.
- for (@ast::method m in ob.methods) {
- meths += ~[normal_mthd(m)];
+ ret some(fwding_mthd(fm));
+ }
+ normal_mthd(_) {
+ // Should never happen.
+ cx.ccx.sess.bug("create_vtbl(): shouldn't be any" +
+ " normal_mthds in meths here");
+ }
}
}
+ let f = bind filtering_fn(cx, _, ob.methods);
+ meths = std::ivec::filter_map[vtbl_mthd, vtbl_mthd](f, meths);
+
+
+ // And now add the additional ones (both replacements and entirely
+ // new ones). These'll just be normal methods.
+ for m: @ast::method in ob.methods { meths += ~[normal_mthd(m)]; }
+ }
}
// Sort all the methods.
- fn vtbl_mthd_lteq(&vtbl_mthd a, &vtbl_mthd b) -> bool {
- alt (a) {
- case (normal_mthd(?ma)) {
- alt (b) {
- case (normal_mthd(?mb)) {
- ret str::lteq(ma.node.ident, mb.node.ident);
- }
- case (fwding_mthd(?mb)) {
- ret str::lteq(ma.node.ident, mb.ident);
- }
- }
+ fn vtbl_mthd_lteq(a: &vtbl_mthd, b: &vtbl_mthd) -> bool {
+ alt a {
+ normal_mthd(ma) {
+ alt b {
+ normal_mthd(mb) { ret str::lteq(ma.node.ident, mb.node.ident); }
+ fwding_mthd(mb) { ret str::lteq(ma.node.ident, mb.ident); }
}
- case (fwding_mthd(?ma)) {
- alt (b) {
- case (normal_mthd(?mb)) {
- ret str::lteq(ma.ident, mb.node.ident);
- }
- case (fwding_mthd(?mb)) {
- ret str::lteq(ma.ident, mb.ident);
- }
- }
+ }
+ fwding_mthd(ma) {
+ alt b {
+ normal_mthd(mb) { ret str::lteq(ma.ident, mb.node.ident); }
+ fwding_mthd(mb) { ret str::lteq(ma.ident, mb.ident); }
}
+ }
}
}
- meths = std::sort::ivector::merge_sort[vtbl_mthd]
- (bind vtbl_mthd_lteq(_, _), meths);
+ meths =
+ std::sort::ivector::merge_sort[vtbl_mthd](bind vtbl_mthd_lteq(_, _),
+ meths);
// Now that we have our list of methods, we can process them in order.
- for (vtbl_mthd m in meths) {
- alt (m) {
- case (normal_mthd(?nm)) {
- llmethods += ~[process_normal_mthd(cx, nm, self_ty,
- ty_params)];
+ for m: vtbl_mthd in meths {
+ alt m {
+ normal_mthd(nm) {
+ llmethods += ~[process_normal_mthd(cx, nm, self_ty, ty_params)];
+ }
+
+ // If we have to process a forwarding method, then we need to know
+ // about the with_obj's type as well as the outer object's type.
+ fwding_mthd(fm) {
+ alt with_obj_ty {
+ none. {
+ // This shouldn't happen; if we're trying to process a
+ // forwarding method, then we should always have a
+ // with_obj_ty.
+ cx.ccx.sess.bug("create_vtbl(): trying to create " +
+ "forwarding method without a type " +
+ "of object to forward to");
+ }
+ some(t) {
+ llmethods +=
+ ~[process_fwding_mthd(cx, sp, fm, ty_params, t,
+ additional_field_tys)];
+ }
}
- // If we have to process a forwarding method, then we need to know
- // about the with_obj's type as well as the outer object's type.
- case (fwding_mthd(?fm)) {
- alt (with_obj_ty) {
- case (none) {
- // This shouldn't happen; if we're trying to process a
- // forwarding method, then we should always have a
- // with_obj_ty.
- cx.ccx.sess.bug("create_vtbl(): trying to create "
- + "forwarding method without a type "
- + "of object to forward to");
- }
- case (some(?t)) {
- llmethods += ~[process_fwding_mthd(
- cx, sp, fm, ty_params, t,
- additional_field_tys)];
- }
- }
- }
+ }
}
}
- auto vtbl = C_struct(llmethods);
- auto vtbl_name = mangle_internal_name_by_path(cx.ccx,
- cx.path + ~["vtbl"]);
- auto gvar =
+ let vtbl = C_struct(llmethods);
+ let vtbl_name = mangle_internal_name_by_path(cx.ccx, cx.path + ~["vtbl"]);
+ let gvar =
llvm::LLVMAddGlobal(cx.ccx.llmod, val_ty(vtbl), str::buf(vtbl_name));
llvm::LLVMSetInitializer(gvar, vtbl);
llvm::LLVMSetGlobalConstant(gvar, True);
@@ -7088,32 +6933,30 @@
ret gvar;
}
-fn trans_dtor(@local_ctxt cx, ty::t self_ty,
- &ast::ty_param[] ty_params, &@ast::method dtor) -> ValueRef {
- auto llfnty = T_dtor(cx.ccx, dtor.span);
- let str s = mangle_internal_name_by_path(cx.ccx, cx.path + ~["drop"]);
- let ValueRef llfn = decl_internal_fastcall_fn(cx.ccx.llmod, s, llfnty);
+fn trans_dtor(cx: @local_ctxt, self_ty: ty::t, ty_params: &ast::ty_param[],
+ dtor: &@ast::method) -> ValueRef {
+ let llfnty = T_dtor(cx.ccx, dtor.span);
+ let s: str = mangle_internal_name_by_path(cx.ccx, cx.path + ~["drop"]);
+ let llfn: ValueRef = decl_internal_fastcall_fn(cx.ccx.llmod, s, llfnty);
cx.ccx.item_ids.insert(dtor.node.id, llfn);
cx.ccx.item_symbols.insert(dtor.node.id, s);
- trans_fn(cx, dtor.span, dtor.node.meth, llfn,
- some(self_ty), ty_params,
+ trans_fn(cx, dtor.span, dtor.node.meth, llfn, some(self_ty), ty_params,
dtor.node.id);
ret llfn;
}
// trans_obj: creates an LLVM function that is the object constructor for the
// object being translated.
-fn trans_obj(@local_ctxt cx, &span sp, &ast::_obj ob, ast::node_id ctor_id,
- &ast::ty_param[] ty_params) {
+fn trans_obj(cx: @local_ctxt, sp: &span, ob: &ast::_obj,
+ ctor_id: ast::node_id, ty_params: &ast::ty_param[]) {
// To make a function, we have to create a function context and, inside
// that, a number of block contexts for which code is generated.
- auto ccx = cx.ccx;
- auto llctor_decl;
- alt (ccx.item_ids.find(ctor_id)) {
- case (some(?x)) { llctor_decl = x; }
- case (_) { cx.ccx.sess.span_fatal(sp,
- "unbound llctor_decl in trans_obj"); }
+ let ccx = cx.ccx;
+ let llctor_decl;
+ alt ccx.item_ids.find(ctor_id) {
+ some(x) { llctor_decl = x; }
+ _ { cx.ccx.sess.span_fatal(sp, "unbound llctor_decl in trans_obj"); }
}
// Much like trans_fn, we must create an LLVM function, but since we're
// starting with an ast::_obj rather than an ast::_fn, we have some setup
@@ -7122,50 +6965,49 @@
// The fields of our object will become the arguments to the function
// we're creating.
- let ast::arg[] fn_args = ~[];
- for (ast::obj_field f in ob.fields) {
+ let fn_args: ast::arg[] = ~[];
+ for f: ast::obj_field in ob.fields {
fn_args +=
- ~[rec(mode=ast::alias(false), ty=f.ty, ident=f.ident, id=f.id)];
+ ~[{mode: ast::alias(false), ty: f.ty, ident: f.ident, id: f.id}];
}
- auto fcx = new_fn_ctxt(cx, sp, llctor_decl);
+ let fcx = new_fn_ctxt(cx, sp, llctor_decl);
// Both regular arguments and type parameters are handled here.
create_llargs_for_fn_args(fcx, ast::proto_fn, none[ty::t],
- ty::ret_ty_of_fn(ccx.tcx, ctor_id),
- fn_args, ty_params);
- let ty::arg[] arg_tys = arg_tys_of_fn(ccx, ctor_id);
+ ty::ret_ty_of_fn(ccx.tcx, ctor_id), fn_args,
+ ty_params);
+ let arg_tys: ty::arg[] = arg_tys_of_fn(ccx, ctor_id);
copy_args_to_allocas(fcx, fn_args, arg_tys);
// Create the first block context in the function and keep a handle on it
// to pass to finish_fn later.
- auto bcx = new_top_block_ctxt(fcx);
- auto lltop = bcx.llbb;
+ let bcx = new_top_block_ctxt(fcx);
+ let lltop = bcx.llbb;
// Pick up the type of this object by looking at our own output type, that
// is, the output type of the object constructor we're building.
- auto self_ty = ty::ret_ty_of_fn(ccx.tcx, ctor_id);
+ let self_ty = ty::ret_ty_of_fn(ccx.tcx, ctor_id);
// Set up the two-word pair that we're going to return from the object
// constructor we're building. The two elements of this pair will be a
// vtable pointer and a body pointer. (llretptr already points to the
// place where this two-word pair should go; it was pre-allocated by the
// caller of the function.)
- auto pair = bcx.fcx.llretptr;
+ let pair = bcx.fcx.llretptr;
// Grab onto the first and second elements of the pair.
// abi::obj_field_vtbl and abi::obj_field_box simply specify words 0 and 1
// of 'pair'.
- auto pair_vtbl =
+ let pair_vtbl =
bcx.build.GEP(pair, ~[C_int(0), C_int(abi::obj_field_vtbl)]);
- auto pair_box =
+ let pair_box =
bcx.build.GEP(pair, ~[C_int(0), C_int(abi::obj_field_box)]);
// Make a vtable for this object: a static array of pointers to functions.
// It will be located in the read-only memory of the executable we're
// creating and will contain ValueRefs for all of this object's methods.
// create_vtbl returns a pointer to the vtable, which we store.
- auto vtbl = create_vtbl(cx, sp, self_ty, ob, ty_params, none,
- ~[]);
+ let vtbl = create_vtbl(cx, sp, self_ty, ob, ty_params, none, ~[]);
vtbl = bcx.build.PointerCast(vtbl, T_ptr(T_empty_struct()));
bcx.build.Store(vtbl, pair_vtbl);
@@ -7177,13 +7019,13 @@
// FIXME: What about with_obj? Do we have to think about it here?
// (Pertains to issues #538/#539/#540/#543.)
- let TypeRef llbox_ty = T_ptr(T_empty_struct());
+ let llbox_ty: TypeRef = T_ptr(T_empty_struct());
// FIXME: we should probably also allocate a box for empty objs that have
// a dtor, since otherwise they are never dropped, and the dtor never
// runs.
- if (std::ivec::len[ast::ty_param](ty_params) == 0u &&
- std::ivec::len[ty::arg](arg_tys) == 0u) {
+ if std::ivec::len[ast::ty_param](ty_params) == 0u &&
+ std::ivec::len[ty::arg](arg_tys) == 0u {
// If the object we're translating has no fields or type parameters,
// there's not much to do.
@@ -7192,38 +7034,38 @@
} else {
// Otherwise, we have to synthesize a big structural type for the
// object body.
- let ty::t[] obj_fields = ~[];
- for (ty::arg a in arg_tys) { obj_fields += ~[a.ty]; }
+ let obj_fields: ty::t[] = ~[];
+ for a: ty::arg in arg_tys { obj_fields += ~[a.ty]; }
// Tuple type for fields: [field, ...]
- let ty::t fields_ty = ty::mk_imm_tup(ccx.tcx, obj_fields);
+ let fields_ty: ty::t = ty::mk_imm_tup(ccx.tcx, obj_fields);
- auto tydesc_ty = ty::mk_type(ccx.tcx);
- let ty::t[] tps = ~[];
- for (ast::ty_param tp in ty_params) { tps += ~[tydesc_ty]; }
+ let tydesc_ty = ty::mk_type(ccx.tcx);
+ let tps: ty::t[] = ~[];
+ for tp: ast::ty_param in ty_params { tps += ~[tydesc_ty]; }
// Tuple type for typarams: [typaram, ...]
- let ty::t typarams_ty = ty::mk_imm_tup(ccx.tcx, tps);
+ let typarams_ty: ty::t = ty::mk_imm_tup(ccx.tcx, tps);
// Tuple type for body: [tydesc_ty, [typaram, ...], [field, ...]]
- let ty::t body_ty =
+ let body_ty: ty::t =
ty::mk_imm_tup(ccx.tcx, ~[tydesc_ty, typarams_ty, fields_ty]);
// Hand this type we've synthesized off to trans_malloc_boxed, which
// allocates a box, including space for a refcount.
- auto box = trans_malloc_boxed(bcx, body_ty);
+ let box = trans_malloc_boxed(bcx, body_ty);
bcx = box.bcx;
// mk_imm_box throws a refcount into the type we're synthesizing, so
// that it looks like: [rc, [tydesc_ty, [typaram, ...], [field, ...]]]
- let ty::t boxed_body_ty = ty::mk_imm_box(ccx.tcx, body_ty);
+ let boxed_body_ty: ty::t = ty::mk_imm_box(ccx.tcx, body_ty);
// Grab onto the refcount and body parts of the box we allocated.
- auto rc =
+ let rc =
GEP_tup_like(bcx, boxed_body_ty, box.val,
~[0, abi::box_rc_field_refcnt]);
bcx = rc.bcx;
- auto body =
+ let body =
GEP_tup_like(bcx, boxed_body_ty, box.val,
~[0, abi::box_rc_field_body]);
bcx = body.bcx;
@@ -7238,12 +7080,12 @@
// the types of the object's fields, so that the fields can be freed
// later.
- auto body_tydesc =
+ let body_tydesc =
GEP_tup_like(bcx, body_ty, body.val,
~[0, abi::obj_body_elt_tydesc]);
bcx = body_tydesc.bcx;
- auto ti = none[@tydesc_info];
- auto body_td = get_tydesc(bcx, body_ty, true, ti);
+ let ti = none[@tydesc_info];
+ let body_td = get_tydesc(bcx, body_ty, true, ti);
lazily_emit_tydesc_glue(bcx, abi::tydesc_field_drop_glue, ti);
lazily_emit_tydesc_glue(bcx, abi::tydesc_field_free_glue, ti);
bcx = body_td.bcx;
@@ -7257,14 +7099,14 @@
// Likewise for the object's fields.)
// Copy typarams into captured typarams.
- auto body_typarams =
+ let body_typarams =
GEP_tup_like(bcx, body_ty, body.val,
~[0, abi::obj_body_elt_typarams]);
bcx = body_typarams.bcx;
- let int i = 0;
- for (ast::ty_param tp in ty_params) {
- auto typaram = bcx.fcx.lltydescs.(i);
- auto capture =
+ let i: int = 0;
+ for tp: ast::ty_param in ty_params {
+ let typaram = bcx.fcx.lltydescs.(i);
+ let capture =
GEP_tup_like(bcx, typarams_ty, body_typarams.val, ~[0, i]);
bcx = capture.bcx;
bcx = copy_val(bcx, INIT, capture.val, typaram, tydesc_ty).bcx;
@@ -7272,32 +7114,30 @@
}
// Copy args into body fields.
- auto body_fields =
+ let body_fields =
GEP_tup_like(bcx, body_ty, body.val,
~[0, abi::obj_body_elt_fields]);
bcx = body_fields.bcx;
i = 0;
- for (ast::obj_field f in ob.fields) {
- alt (bcx.fcx.llargs.find(f.id)) {
- case (some(?arg1)) {
- auto arg = load_if_immediate(bcx, arg1, arg_tys.(i).ty);
- auto field =
- GEP_tup_like(bcx, fields_ty, body_fields.val,
- ~[0, i]);
- bcx = field.bcx;
- bcx = copy_val(bcx, INIT, field.val, arg,
- arg_tys.(i).ty).bcx;
- i += 1;
- }
- case (none) {
- bcx_ccx(bcx).sess.span_fatal(f.ty.span,
- "internal error in trans_obj");
- }
+ for f: ast::obj_field in ob.fields {
+ alt bcx.fcx.llargs.find(f.id) {
+ some(arg1) {
+ let arg = load_if_immediate(bcx, arg1, arg_tys.(i).ty);
+ let field =
+ GEP_tup_like(bcx, fields_ty, body_fields.val, ~[0, i]);
+ bcx = field.bcx;
+ bcx = copy_val(bcx, INIT, field.val, arg, arg_tys.(i).ty).bcx;
+ i += 1;
+ }
+ none. {
+ bcx_ccx(bcx).sess.span_fatal(f.ty.span,
+ "internal error in trans_obj");
+ }
}
}
// Store box ptr in outer pair.
- auto p = bcx.build.PointerCast(box.val, llbox_ty);
+ let p = bcx.build.PointerCast(box.val, llbox_ty);
bcx.build.Store(p, pair_box);
}
bcx.build.RetVoid();
@@ -7306,42 +7146,38 @@
finish_fn(fcx, lltop);
}
-fn trans_res_ctor(@local_ctxt cx, &span sp, &ast::_fn dtor,
- ast::node_id ctor_id, &ast::ty_param[] ty_params) {
+fn trans_res_ctor(cx: @local_ctxt, sp: &span, dtor: &ast::_fn,
+ ctor_id: ast::node_id, ty_params: &ast::ty_param[]) {
// Create a function for the constructor
- auto llctor_decl;
- alt (cx.ccx.item_ids.find(ctor_id)) {
- case (some(?x)) { llctor_decl = x; }
- case (_) {
- cx.ccx.sess.span_fatal(sp, "unbound ctor_id in trans_res_ctor");
- }
+ let llctor_decl;
+ alt cx.ccx.item_ids.find(ctor_id) {
+ some(x) { llctor_decl = x; }
+ _ { cx.ccx.sess.span_fatal(sp, "unbound ctor_id in trans_res_ctor"); }
}
- auto fcx = new_fn_ctxt(cx, sp, llctor_decl);
- auto ret_t = ty::ret_ty_of_fn(cx.ccx.tcx, ctor_id);
- create_llargs_for_fn_args(fcx, ast::proto_fn, none[ty::t],
- ret_t, dtor.decl.inputs, ty_params);
- auto bcx = new_top_block_ctxt(fcx);
- auto lltop = bcx.llbb;
- auto arg_t = arg_tys_of_fn(cx.ccx, ctor_id).(0).ty;
- auto tup_t = ty::mk_imm_tup(cx.ccx.tcx, ~[ty::mk_int(cx.ccx.tcx), arg_t]);
- auto arg;
- alt (fcx.llargs.find(dtor.decl.inputs.(0).id)) {
- case (some(?x)) { arg = load_if_immediate(bcx, x, arg_t); }
- case (_) {
- cx.ccx.sess.span_fatal(sp, "unbound dtor decl in trans_res_ctor");
- }
+ let fcx = new_fn_ctxt(cx, sp, llctor_decl);
+ let ret_t = ty::ret_ty_of_fn(cx.ccx.tcx, ctor_id);
+ create_llargs_for_fn_args(fcx, ast::proto_fn, none[ty::t], ret_t,
+ dtor.decl.inputs, ty_params);
+ let bcx = new_top_block_ctxt(fcx);
+ let lltop = bcx.llbb;
+ let arg_t = arg_tys_of_fn(cx.ccx, ctor_id).(0).ty;
+ let tup_t = ty::mk_imm_tup(cx.ccx.tcx, ~[ty::mk_int(cx.ccx.tcx), arg_t]);
+ let arg;
+ alt fcx.llargs.find(dtor.decl.inputs.(0).id) {
+ some(x) { arg = load_if_immediate(bcx, x, arg_t); }
+ _ { cx.ccx.sess.span_fatal(sp, "unbound dtor decl in trans_res_ctor"); }
}
- auto llretptr = fcx.llretptr;
- if (ty::type_has_dynamic_size(cx.ccx.tcx, ret_t)) {
- auto llret_t = T_ptr(T_struct(~[T_i32(), llvm::LLVMTypeOf(arg)]));
+ let llretptr = fcx.llretptr;
+ if ty::type_has_dynamic_size(cx.ccx.tcx, ret_t) {
+ let llret_t = T_ptr(T_struct(~[T_i32(), llvm::LLVMTypeOf(arg)]));
llretptr = bcx.build.BitCast(llretptr, llret_t);
}
- auto dst = GEP_tup_like(bcx, tup_t, llretptr, ~[0, 1]);
+ let dst = GEP_tup_like(bcx, tup_t, llretptr, ~[0, 1]);
bcx = dst.bcx;
bcx = copy_val(bcx, INIT, dst.val, arg, arg_t).bcx;
- auto flag = GEP_tup_like(bcx, tup_t, llretptr, ~[0, 0]);
+ let flag = GEP_tup_like(bcx, tup_t, llretptr, ~[0, 0]);
bcx = flag.bcx;
bcx.build.Store(C_int(1), flag.val);
bcx.build.RetVoid();
@@ -7349,84 +7185,85 @@
}
-fn trans_tag_variant(@local_ctxt cx, ast::node_id tag_id,
- &ast::variant variant, int index, bool is_degen,
- &ast::ty_param[] ty_params) {
- if (std::ivec::len[ast::variant_arg](variant.node.args) == 0u) {
+fn trans_tag_variant(cx: @local_ctxt, tag_id: ast::node_id,
+ variant: &ast::variant, index: int, is_degen: bool,
+ ty_params: &ast::ty_param[]) {
+ if std::ivec::len[ast::variant_arg](variant.node.args) == 0u {
ret; // nullary constructors are just constants
}
// Translate variant arguments to function arguments.
- let ast::arg[] fn_args = ~[];
- auto i = 0u;
- for (ast::variant_arg varg in variant.node.args) {
+ let fn_args: ast::arg[] = ~[];
+ let i = 0u;
+ for varg: ast::variant_arg in variant.node.args {
fn_args +=
- ~[rec(mode=ast::alias(false),
- ty=varg.ty,
- ident="arg" + uint::to_str(i, 10u),
- id=varg.id)];
+ ~[{mode: ast::alias(false),
+ ty: varg.ty,
+ ident: "arg" + uint::to_str(i, 10u),
+ id: varg.id}];
}
assert (cx.ccx.item_ids.contains_key(variant.node.id));
- let ValueRef llfndecl;
- alt (cx.ccx.item_ids.find(variant.node.id)) {
- case (some(?x)) { llfndecl = x; }
- case (_) {
- cx.ccx.sess.span_fatal(variant.span,
+ let llfndecl: ValueRef;
+ alt cx.ccx.item_ids.find(variant.node.id) {
+ some(x) { llfndecl = x; }
+ _ {
+ cx.ccx.sess.span_fatal(variant.span,
"unbound variant id in trans_tag_variant");
- }
+ }
}
- auto fcx = new_fn_ctxt(cx, variant.span, llfndecl);
+ let fcx = new_fn_ctxt(cx, variant.span, llfndecl);
create_llargs_for_fn_args(fcx, ast::proto_fn, none[ty::t],
ty::ret_ty_of_fn(cx.ccx.tcx, variant.node.id),
fn_args, ty_params);
- let ty::t[] ty_param_substs = ~[];
+ let ty_param_substs: ty::t[] = ~[];
i = 0u;
- for (ast::ty_param tp in ty_params) {
+ for tp: ast::ty_param in ty_params {
ty_param_substs += ~[ty::mk_param(cx.ccx.tcx, i)];
i += 1u;
}
- auto arg_tys = arg_tys_of_fn(cx.ccx, variant.node.id);
+ let arg_tys = arg_tys_of_fn(cx.ccx, variant.node.id);
copy_args_to_allocas(fcx, fn_args, arg_tys);
- auto bcx = new_top_block_ctxt(fcx);
- auto lltop = bcx.llbb;
+ let bcx = new_top_block_ctxt(fcx);
+ let lltop = bcx.llbb;
- auto llblobptr = if (is_degen) {
- fcx.llretptr
- } else {
+ let
// Cast the tag to a type we can GEP into.
- auto lltagptr = bcx.build.PointerCast
- (fcx.llretptr, T_opaque_tag_ptr(fcx.lcx.ccx.tn));
- auto lldiscrimptr = bcx.build.GEP(lltagptr, ~[C_int(0), C_int(0)]);
- bcx.build.Store(C_int(index), lldiscrimptr);
- bcx.build.GEP(lltagptr, ~[C_int(0), C_int(1)])
- };
+ llblobptr =
+ if is_degen {
+ fcx.llretptr
+ } else {
+ let lltagptr =
+ bcx.build.PointerCast(fcx.llretptr,
+ T_opaque_tag_ptr(fcx.lcx.ccx.tn));
+ let lldiscrimptr = bcx.build.GEP(lltagptr, ~[C_int(0), C_int(0)]);
+ bcx.build.Store(C_int(index), lldiscrimptr);
+ bcx.build.GEP(lltagptr, ~[C_int(0), C_int(1)])
+ };
i = 0u;
- for (ast::variant_arg va in variant.node.args) {
- auto rslt =
+ for va: ast::variant_arg in variant.node.args {
+ let rslt =
GEP_tag(bcx, llblobptr, ast::local_def(tag_id),
ast::local_def(variant.node.id), ty_param_substs,
i as int);
bcx = rslt.bcx;
- auto lldestptr = rslt.val;
+ let lldestptr = rslt.val;
// If this argument to this function is a tag, it'll have come in to
// this function as an opaque blob due to the way that type_of()
// works. So we have to cast to the destination's view of the type.
- auto llargptr;
- alt (fcx.llargs.find(va.id)) {
- case (some(?x)) {
- llargptr = bcx.build.PointerCast(x, val_ty(lldestptr));
- }
- case (none) {
- bcx_ccx(bcx).sess.bug("unbound argptr in \
+ let llargptr;
+ alt fcx.llargs.find(va.id) {
+ some(x) { llargptr = bcx.build.PointerCast(x, val_ty(lldestptr)); }
+ none. {
+ bcx_ccx(bcx).sess.bug("unbound argptr in \
trans_tag_variant");
- }
+ }
}
- auto arg_ty = arg_tys.(i).ty;
- auto llargval;
- if (ty::type_is_structural(cx.ccx.tcx, arg_ty) ||
- ty::type_has_dynamic_size(cx.ccx.tcx, arg_ty)) {
+ let arg_ty = arg_tys.(i).ty;
+ let llargval;
+ if ty::type_is_structural(cx.ccx.tcx, arg_ty) ||
+ ty::type_has_dynamic_size(cx.ccx.tcx, arg_ty) {
llargval = llargptr;
} else { llargval = bcx.build.Load(llargptr); }
rslt = copy_val(bcx, INIT, lldestptr, llargval, arg_ty);
@@ -7442,83 +7279,78 @@
// FIXME: this should do some structural hash-consing to avoid
// duplicate constants. I think. Maybe LLVM has a magical mode
// that does so later on?
-fn trans_const_expr(&@crate_ctxt cx, @ast::expr e) -> ValueRef {
- alt (e.node) {
- case (ast::expr_lit(?lit)) { ret trans_crate_lit(cx, *lit); }
- case (_) {
- cx.sess.span_unimpl(e.span, "consts that's not a plain literal");
- }
+fn trans_const_expr(cx: &@crate_ctxt, e: @ast::expr) -> ValueRef {
+ alt e.node {
+ ast::expr_lit(lit) { ret trans_crate_lit(cx, *lit); }
+ _ { cx.sess.span_unimpl(e.span, "consts that's not a plain literal"); }
}
}
-fn trans_const(&@crate_ctxt cx, @ast::expr e, ast::node_id id) {
- auto v = trans_const_expr(cx, e);
+fn trans_const(cx: &@crate_ctxt, e: @ast::expr, id: ast::node_id) {
+ let v = trans_const_expr(cx, e);
+
// The scalars come back as 1st class LLVM vals
// which we have to stick into global constants.
- alt (cx.consts.find(id)) {
- case (some(?g)) {
- llvm::LLVMSetInitializer(g, v);
- llvm::LLVMSetGlobalConstant(g, True);
- }
- case (_) {
- cx.sess.span_fatal(e.span, "Unbound const in trans_const");
- }
+ alt cx.consts.find(id) {
+ some(g) {
+ llvm::LLVMSetInitializer(g, v);
+ llvm::LLVMSetGlobalConstant(g, True);
+ }
+ _ { cx.sess.span_fatal(e.span, "Unbound const in trans_const"); }
}
}
-fn trans_item(@local_ctxt cx, &ast::item item) {
- alt (item.node) {
- case (ast::item_fn(?f, ?tps)) {
- auto sub_cx = extend_path(cx, item.ident);
- alt (cx.ccx.item_ids.find(item.id)) {
- case (some(?llfndecl)) {
- trans_fn(sub_cx, item.span, f, llfndecl,
- none, tps, item.id);
- }
- case (_) {
- cx.ccx.sess.span_fatal(item.span,
- "unbound function item in trans_item");
- }
- }
+fn trans_item(cx: @local_ctxt, item: &ast::item) {
+ alt item.node {
+ ast::item_fn(f, tps) {
+ let sub_cx = extend_path(cx, item.ident);
+ alt cx.ccx.item_ids.find(item.id) {
+ some(llfndecl) {
+ trans_fn(sub_cx, item.span, f, llfndecl, none, tps, item.id);
+ }
+ _ {
+ cx.ccx.sess.span_fatal(item.span,
+ "unbound function item in trans_item");
+ }
}
- case (ast::item_obj(?ob, ?tps, ?ctor_id)) {
- auto sub_cx =
- @rec(obj_typarams=tps, obj_fields=ob.fields
- with *extend_path(cx, item.ident));
- trans_obj(sub_cx, item.span, ob, ctor_id, tps);
+ }
+ ast::item_obj(ob, tps, ctor_id) {
+ let sub_cx =
+ @{obj_typarams: tps, obj_fields: ob.fields
+ with *extend_path(cx, item.ident)};
+ trans_obj(sub_cx, item.span, ob, ctor_id, tps);
+ }
+ ast::item_res(dtor, dtor_id, tps, ctor_id) {
+ trans_res_ctor(cx, item.span, dtor, ctor_id, tps);
+
+ // Create a function for the destructor
+ alt cx.ccx.item_ids.find(item.id) {
+ some(lldtor_decl) {
+ trans_fn(cx, item.span, dtor, lldtor_decl, none, tps, dtor_id);
+ }
+ _ {
+ cx.ccx.sess.span_fatal(item.span, "unbound dtor in trans_item");
+ }
}
- case (ast::item_res(?dtor, ?dtor_id, ?tps, ?ctor_id)) {
- trans_res_ctor(cx, item.span, dtor, ctor_id, tps);
- // Create a function for the destructor
- alt (cx.ccx.item_ids.find(item.id)) {
- case (some(?lldtor_decl)) {
- trans_fn(cx, item.span, dtor, lldtor_decl, none, tps,
- dtor_id);
- }
- case (_) { cx.ccx.sess.span_fatal(item.span,
- "unbound dtor in trans_item"); }
- }
+ }
+ ast::item_mod(m) {
+ let sub_cx =
+ @{path: cx.path + ~[item.ident],
+ module_path: cx.module_path + ~[item.ident] with *cx};
+ trans_mod(sub_cx, m);
+ }
+ ast::item_tag(variants, tps) {
+ let sub_cx = extend_path(cx, item.ident);
+ let degen = std::ivec::len(variants) == 1u;
+ let i = 0;
+ for variant: ast::variant in variants {
+ trans_tag_variant(sub_cx, item.id, variant, i, degen, tps);
+ i += 1;
}
- case (ast::item_mod(?m)) {
- auto sub_cx =
- @rec(path=cx.path + ~[item.ident],
- module_path=cx.module_path + ~[item.ident] with *cx);
- trans_mod(sub_cx, m);
- }
- case (ast::item_tag(?variants, ?tps)) {
- auto sub_cx = extend_path(cx, item.ident);
- auto degen = std::ivec::len(variants) == 1u;
- auto i = 0;
- for (ast::variant variant in variants) {
- trans_tag_variant(sub_cx, item.id, variant, i, degen, tps);
- i += 1;
- }
- }
- case (ast::item_const(_, ?expr)) {
- trans_const(cx.ccx, expr, item.id);
- }
- case (_) {/* fall through */ }
+ }
+ ast::item_const(_, expr) { trans_const(cx.ccx, expr, item.id); }
+ _ {/* fall through */ }
}
}
@@ -7528,50 +7360,48 @@
// separate modules in the compiled program. That's because modules exist
// only as a convenience for humans working with the code, to organize names
// and control visibility.
-fn trans_mod(@local_ctxt cx, &ast::_mod m) {
- for (@ast::item item in m.items) { trans_item(cx, *item); }
+fn trans_mod(cx: @local_ctxt, m: &ast::_mod) {
+ for item: @ast::item in m.items { trans_item(cx, *item); }
}
-fn get_pair_fn_ty(TypeRef llpairty) -> TypeRef {
+fn get_pair_fn_ty(llpairty: TypeRef) -> TypeRef {
// Bit of a kludge: pick the fn typeref out of the pair.
ret struct_elt(llpairty, 0u);
}
-fn decl_fn_and_pair(&@crate_ctxt ccx, &span sp, &str[] path, str flav,
- &ast::ty_param[] ty_params, ast::node_id node_id) {
+fn decl_fn_and_pair(ccx: &@crate_ctxt, sp: &span, path: &str[], flav: str,
+ ty_params: &ast::ty_param[], node_id: ast::node_id) {
decl_fn_and_pair_full(ccx, sp, path, flav, ty_params, node_id,
node_id_type(ccx, node_id));
}
-fn decl_fn_and_pair_full(&@crate_ctxt ccx, &span sp, &str[] path, str flav,
- &ast::ty_param[] ty_params, ast::node_id node_id,
- ty::t node_type) {
- auto llfty;
- alt (ty::struct(ccx.tcx, node_type)) {
- case (ty::ty_fn(?proto, ?inputs, ?output, _, _)) {
- llfty =
- type_of_fn(ccx, sp, proto, inputs, output,
- std::ivec::len[ast::ty_param](ty_params));
- }
- case (_) {
- ccx.sess.bug("decl_fn_and_pair(): fn item doesn't have fn type!");
- }
+fn decl_fn_and_pair_full(ccx: &@crate_ctxt, sp: &span, path: &str[],
+ flav: str, ty_params: &ast::ty_param[],
+ node_id: ast::node_id, node_type: ty::t) {
+ let llfty;
+ alt ty::struct(ccx.tcx, node_type) {
+ ty::ty_fn(proto, inputs, output, _, _) {
+ llfty =
+ type_of_fn(ccx, sp, proto, inputs, output,
+ std::ivec::len[ast::ty_param](ty_params));
+ }
+ _ { ccx.sess.bug("decl_fn_and_pair(): fn item doesn't have fn type!"); }
}
- let bool is_main = is_main_name(path) && !ccx.sess.get_opts().library;
+ let is_main: bool = is_main_name(path) && !ccx.sess.get_opts().library;
// Declare the function itself.
- let str s =
- if (is_main) {
+ let s: str =
+ if is_main {
"_rust_main"
} else { mangle_internal_name_by_path(ccx, path) };
- let ValueRef llfn = decl_internal_fastcall_fn(ccx.llmod, s, llfty);
+ let llfn: ValueRef = decl_internal_fastcall_fn(ccx.llmod, s, llfty);
// Declare the global constant pair that points to it.
- let str ps = mangle_exported_name(ccx, path, node_type);
+ let ps: str = mangle_exported_name(ccx, path, node_type);
register_fn_pair(ccx, ps, llfty, llfn, node_id);
- if (is_main) {
- if (ccx.main_fn != none[ValueRef]) {
+ if is_main {
+ if ccx.main_fn != none[ValueRef] {
ccx.sess.span_fatal(sp, "multiple 'main' functions");
}
llvm::LLVMSetLinkage(llfn,
@@ -7583,14 +7413,14 @@
// Create a closure: a pair containing (1) a ValueRef, pointing to where the
// fn's definition is in the executable we're creating, and (2) a pointer to
// space for the function's environment.
-fn create_fn_pair(&@crate_ctxt cx, str ps, TypeRef llfnty, ValueRef llfn,
- bool external) -> ValueRef {
- auto gvar =
+fn create_fn_pair(cx: &@crate_ctxt, ps: str, llfnty: TypeRef, llfn: ValueRef,
+ external: bool) -> ValueRef {
+ let gvar =
llvm::LLVMAddGlobal(cx.llmod, T_fn_pair(*cx, llfnty), str::buf(ps));
- auto pair = C_struct(~[llfn, C_null(T_opaque_closure_ptr(*cx))]);
+ let pair = C_struct(~[llfn, C_null(T_opaque_closure_ptr(*cx))]);
llvm::LLVMSetInitializer(gvar, pair);
llvm::LLVMSetGlobalConstant(gvar, True);
- if (!external) {
+ if !external {
llvm::LLVMSetLinkage(gvar,
lib::llvm::LLVMInternalLinkage as llvm::Linkage);
}
@@ -7600,28 +7430,26 @@
// Create a /real/ closure: this is like create_fn_pair, but creates a
// a fn value on the stack with a specified environment (which need not be
// on the stack).
-fn create_real_fn_pair(&@block_ctxt cx, TypeRef llfnty,
- ValueRef llfn, ValueRef llenvptr) -> ValueRef {
- auto lcx = cx.fcx.lcx;
+fn create_real_fn_pair(cx: &@block_ctxt, llfnty: TypeRef, llfn: ValueRef,
+ llenvptr: ValueRef) -> ValueRef {
+ let lcx = cx.fcx.lcx;
- auto pair = alloca(cx, T_fn_pair(*lcx.ccx, llfnty));
- auto code_cell =
+ let pair = alloca(cx, T_fn_pair(*lcx.ccx, llfnty));
+ let code_cell =
cx.build.GEP(pair, ~[C_int(0), C_int(abi::fn_field_code)]);
cx.build.Store(llfn, code_cell);
- auto env_cell =
- cx.build.GEP(pair, ~[C_int(0), C_int(abi::fn_field_box)]);
- auto llenvblobptr =
- cx.build.PointerCast(llenvptr,
- T_opaque_closure_ptr(*lcx.ccx));
+ let env_cell = cx.build.GEP(pair, ~[C_int(0), C_int(abi::fn_field_box)]);
+ let llenvblobptr =
+ cx.build.PointerCast(llenvptr, T_opaque_closure_ptr(*lcx.ccx));
cx.build.Store(llenvblobptr, env_cell);
ret pair;
}
-fn register_fn_pair(&@crate_ctxt cx, str ps, TypeRef llfnty, ValueRef llfn,
- ast::node_id id) {
+fn register_fn_pair(cx: &@crate_ctxt, ps: str, llfnty: TypeRef,
+ llfn: ValueRef, id: ast::node_id) {
// FIXME: We should also hide the unexported pairs in crates.
- auto gvar =
+ let gvar =
create_fn_pair(cx, ps, llfnty, llfn, cx.sess.get_opts().library);
cx.item_ids.insert(id, llfn);
cx.item_symbols.insert(id, ps);
@@ -7630,142 +7458,140 @@
// Returns the number of type parameters that the given native function has.
-fn native_fn_ty_param_count(&@crate_ctxt cx, ast::node_id id) -> uint {
- auto count;
- auto native_item = alt (cx.ast_map.find(id)) {
- case (some(ast_map::node_native_item(?i))) { i }
- };
- alt (native_item.node) {
- case (ast::native_item_ty) {
- cx.sess.bug("decl_native_fn_and_pair(): native fn isn't \
+fn native_fn_ty_param_count(cx: &@crate_ctxt, id: ast::node_id) -> uint {
+ let count;
+ let native_item =
+ alt cx.ast_map.find(id) { some(ast_map::node_native_item(i)) { i } };
+ alt native_item.node {
+ ast::native_item_ty. {
+ cx.sess.bug("decl_native_fn_and_pair(): native fn isn't \
actually a fn");
- }
- case (ast::native_item_fn(_, _, ?tps)) {
- count = std::ivec::len[ast::ty_param](tps);
- }
+ }
+ ast::native_item_fn(_, _, tps) {
+ count = std::ivec::len[ast::ty_param](tps);
+ }
}
ret count;
}
-fn native_fn_wrapper_type(&@crate_ctxt cx, &span sp, uint ty_param_count,
- ty::t x) -> TypeRef {
- alt (ty::struct(cx.tcx, x)) {
- case (ty::ty_native_fn(?abi, ?args, ?out)) {
- ret type_of_fn(cx, sp, ast::proto_fn, args, out, ty_param_count);
- }
+fn native_fn_wrapper_type(cx: &@crate_ctxt, sp: &span, ty_param_count: uint,
+ x: ty::t) -> TypeRef {
+ alt ty::struct(cx.tcx, x) {
+ ty::ty_native_fn(abi, args, out) {
+ ret type_of_fn(cx, sp, ast::proto_fn, args, out, ty_param_count);
+ }
}
}
-fn decl_native_fn_and_pair(&@crate_ctxt ccx, &span sp, &str[] path, str name,
- ast::node_id id) {
- auto num_ty_param = native_fn_ty_param_count(ccx, id);
+fn decl_native_fn_and_pair(ccx: &@crate_ctxt, sp: &span, path: &str[],
+ name: str, id: ast::node_id) {
+ let num_ty_param = native_fn_ty_param_count(ccx, id);
// Declare the wrapper.
- auto t = node_id_type(ccx, id);
- auto wrapper_type = native_fn_wrapper_type(ccx, sp, num_ty_param, t);
- let str s = mangle_internal_name_by_path(ccx, path);
- let ValueRef wrapper_fn =
+ let t = node_id_type(ccx, id);
+ let wrapper_type = native_fn_wrapper_type(ccx, sp, num_ty_param, t);
+ let s: str = mangle_internal_name_by_path(ccx, path);
+ let wrapper_fn: ValueRef =
decl_internal_fastcall_fn(ccx.llmod, s, wrapper_type);
// Declare the global constant pair that points to it.
- let str ps = mangle_exported_name(ccx, path, node_id_type(ccx, id));
+ let ps: str = mangle_exported_name(ccx, path, node_id_type(ccx, id));
register_fn_pair(ccx, ps, wrapper_type, wrapper_fn, id);
// Build the wrapper.
- auto fcx = new_fn_ctxt(new_local_ctxt(ccx), sp, wrapper_fn);
- auto bcx = new_top_block_ctxt(fcx);
- auto lltop = bcx.llbb;
+ let fcx = new_fn_ctxt(new_local_ctxt(ccx), sp, wrapper_fn);
+ let bcx = new_top_block_ctxt(fcx);
+ let lltop = bcx.llbb;
// Declare the function itself.
- auto fn_type = node_id_type(ccx, id); // NB: has no type params
+ let fn_type = node_id_type(ccx, id); // NB: has no type params
- auto abi = ty::ty_fn_abi(ccx.tcx, fn_type);
+ let abi = ty::ty_fn_abi(ccx.tcx, fn_type);
// FIXME: If the returned type is not nil, then we assume it's 32 bits
// wide. This is obviously wildly unsafe. We should have a better FFI
// that allows types of different sizes to be returned.
- auto rty = ty::ty_fn_ret(ccx.tcx, fn_type);
- auto rty_is_nil = ty::type_is_nil(ccx.tcx, rty);
+ let rty = ty::ty_fn_ret(ccx.tcx, fn_type);
+ let rty_is_nil = ty::type_is_nil(ccx.tcx, rty);
- auto pass_task;
- auto uses_retptr;
- auto cast_to_i32;
- alt (abi) {
- case (ast::native_abi_rust) {
+ let pass_task;
+ let uses_retptr;
+ let cast_to_i32;
+ alt abi {
+ ast::native_abi_rust. {
pass_task = true;
uses_retptr = false;
cast_to_i32 = true;
}
- case (ast::native_abi_rust_intrinsic) {
+ ast::native_abi_rust_intrinsic. {
pass_task = true;
uses_retptr = true;
cast_to_i32 = false;
}
- case (ast::native_abi_cdecl) {
+ ast::native_abi_cdecl. {
pass_task = false;
uses_retptr = false;
cast_to_i32 = true;
}
- case (ast::native_abi_llvm) {
+ ast::native_abi_llvm. {
pass_task = false;
uses_retptr = false;
cast_to_i32 = false;
}
- case (ast::native_abi_x86stdcall) {
+ ast::native_abi_x86stdcall. {
pass_task = false;
uses_retptr = false;
cast_to_i32 = true;
}
}
- auto lltaskptr;
- if (cast_to_i32) {
+ let lltaskptr;
+ if cast_to_i32 {
lltaskptr = vp2i(bcx, fcx.lltaskptr);
} else { lltaskptr = fcx.lltaskptr; }
- let ValueRef[] call_args = ~[];
- if (pass_task) { call_args += ~[lltaskptr]; }
- if (uses_retptr) { call_args += ~[bcx.fcx.llretptr]; }
+ let call_args: ValueRef[] = ~[];
+ if pass_task { call_args += ~[lltaskptr]; }
+ if uses_retptr { call_args += ~[bcx.fcx.llretptr]; }
- auto arg_n = 3u;
- for each (uint i in uint::range(0u, num_ty_param)) {
- auto llarg = llvm::LLVMGetParam(fcx.llfn, arg_n);
+ let arg_n = 3u;
+ for each i: uint in uint::range(0u, num_ty_param) {
+ let llarg = llvm::LLVMGetParam(fcx.llfn, arg_n);
fcx.lltydescs += ~[llarg];
assert (llarg as int != 0);
- if (cast_to_i32) {
+ if cast_to_i32 {
call_args += ~[vp2i(bcx, llarg)];
} else { call_args += ~[llarg]; }
arg_n += 1u;
}
- fn convert_arg_to_i32(&@block_ctxt cx, ValueRef v, ty::t t, ty::mode mode)
- -> ValueRef {
- if (mode == ty::mo_val) {
- if (ty::type_is_integral(bcx_tcx(cx), t)) {
- auto lldsttype = T_int();
- auto llsrctype = type_of(bcx_ccx(cx), cx.sp, t);
- if (llvm::LLVMGetIntTypeWidth(lldsttype) >
- llvm::LLVMGetIntTypeWidth(llsrctype)) {
+ fn convert_arg_to_i32(cx: &@block_ctxt, v: ValueRef, t: ty::t,
+ mode: ty::mode) -> ValueRef {
+ if mode == ty::mo_val {
+ if ty::type_is_integral(bcx_tcx(cx), t) {
+ let lldsttype = T_int();
+ let llsrctype = type_of(bcx_ccx(cx), cx.sp, t);
+ if llvm::LLVMGetIntTypeWidth(lldsttype) >
+ llvm::LLVMGetIntTypeWidth(llsrctype) {
ret cx.build.ZExtOrBitCast(v, T_int());
}
ret cx.build.TruncOrBitCast(v, T_int());
}
- if (ty::type_is_fp(bcx_tcx(cx), t)) {
+ if ty::type_is_fp(bcx_tcx(cx), t) {
ret cx.build.FPToSI(v, T_int());
}
}
ret vp2i(cx, v);
}
- fn trans_simple_native_abi(&@block_ctxt bcx, str name,
- &mutable ValueRef[] call_args,
- ty::t fn_type, uint first_arg_n,
- bool uses_retptr, uint cc)
- -> rec(ValueRef val, ValueRef rptr) {
- let TypeRef[] call_arg_tys = ~[];
- for (ValueRef arg in call_args) { call_arg_tys += ~[val_ty(arg)]; }
+ fn trans_simple_native_abi(bcx: &@block_ctxt, name: str,
+ call_args: &mutable ValueRef[], fn_type: ty::t,
+ first_arg_n: uint, uses_retptr: bool, cc: uint)
+ -> {val: ValueRef, rptr: ValueRef} {
+ let call_arg_tys: TypeRef[] = ~[];
+ for arg: ValueRef in call_args { call_arg_tys += ~[val_ty(arg)]; }
- auto llnativefnty;
- if (uses_retptr) {
+ let llnativefnty;
+ if uses_retptr {
llnativefnty = T_fn(call_arg_tys, T_void());
} else {
llnativefnty =
@@ -7774,253 +7600,252 @@
ty::ty_fn_ret(bcx_tcx(bcx), fn_type)));
}
- auto llnativefn =
- get_extern_fn(bcx_ccx(bcx).externs, bcx_ccx(bcx).llmod,
- name, cc, llnativefnty);
- auto r = if (cc == lib::llvm::LLVMCCallConv) {
- bcx.build.Call(llnativefn, call_args)
- } else {
- bcx.build.CallWithConv(llnativefn, call_args, cc)
- };
- auto rptr = bcx.fcx.llretptr;
- ret rec(val=r, rptr=rptr);
+ let llnativefn =
+ get_extern_fn(bcx_ccx(bcx).externs, bcx_ccx(bcx).llmod, name, cc,
+ llnativefnty);
+ let r =
+ if cc == lib::llvm::LLVMCCallConv {
+ bcx.build.Call(llnativefn, call_args)
+ } else { bcx.build.CallWithConv(llnativefn, call_args, cc) };
+ let rptr = bcx.fcx.llretptr;
+ ret {val: r, rptr: rptr};
}
- auto args = ty::ty_fn_args(ccx.tcx, fn_type);
+ let args = ty::ty_fn_args(ccx.tcx, fn_type);
// Build up the list of arguments.
- let (rec(ValueRef val, ty::t ty))[] drop_args = ~[];
- auto i = arg_n;
- for (ty::arg arg in args) {
- auto llarg = llvm::LLVMGetParam(fcx.llfn, i);
+ let drop_args: {val: ValueRef, ty: ty::t}[] = ~[];
+ let i = arg_n;
+ for arg: ty::arg in args {
+ let llarg = llvm::LLVMGetParam(fcx.llfn, i);
assert (llarg as int != 0);
- if (cast_to_i32) {
- auto llarg_i32 = convert_arg_to_i32(bcx, llarg, arg.ty, arg.mode);
+ if cast_to_i32 {
+ let llarg_i32 = convert_arg_to_i32(bcx, llarg, arg.ty, arg.mode);
call_args += ~[llarg_i32];
- } else {
- call_args += ~[llarg];
- }
- if (arg.mode == ty::mo_val) {
- drop_args += ~[rec(val=llarg, ty=arg.ty)];
+ } else { call_args += ~[llarg]; }
+ if arg.mode == ty::mo_val {
+ drop_args += ~[{val: llarg, ty: arg.ty}];
}
i += 1u;
}
- auto r;
- auto rptr;
- alt (abi) {
- case (ast::native_abi_llvm) {
- auto result =
- trans_simple_native_abi(bcx, name, call_args, fn_type, arg_n,
- uses_retptr,
- lib::llvm::LLVMCCallConv);
- r = result.val;
- rptr = result.rptr;
- }
- case (ast::native_abi_rust_intrinsic) {
- auto external_name = "rust_intrinsic_" + name;
- auto result =
- trans_simple_native_abi(bcx, external_name, call_args,
- fn_type, arg_n, uses_retptr,
- lib::llvm::LLVMCCallConv);
- r = result.val;
- rptr = result.rptr;
- }
- case (ast::native_abi_x86stdcall) {
- auto result =
- trans_simple_native_abi(bcx, name, call_args, fn_type, arg_n,
- uses_retptr,
- lib::llvm::LLVMX86StdcallCallConv);
- r = result.val;
- rptr = result.rptr;
- }
- case (_) {
- r =
- trans_native_call(bcx.build, ccx.glues, lltaskptr,
- ccx.externs, ccx.tn, ccx.llmod, name,
- pass_task, call_args);
- rptr = bcx.build.BitCast(fcx.llretptr, T_ptr(T_i32()));
- }
+ let r;
+ let rptr;
+ alt abi {
+ ast::native_abi_llvm. {
+ let result =
+ trans_simple_native_abi(bcx, name, call_args, fn_type, arg_n,
+ uses_retptr, lib::llvm::LLVMCCallConv);
+ r = result.val;
+ rptr = result.rptr;
+ }
+ ast::native_abi_rust_intrinsic. {
+ let external_name = "rust_intrinsic_" + name;
+ let result =
+ trans_simple_native_abi(bcx, external_name, call_args, fn_type,
+ arg_n, uses_retptr,
+ lib::llvm::LLVMCCallConv);
+ r = result.val;
+ rptr = result.rptr;
+ }
+ ast::native_abi_x86stdcall. {
+ let result =
+ trans_simple_native_abi(bcx, name, call_args, fn_type, arg_n,
+ uses_retptr,
+ lib::llvm::LLVMX86StdcallCallConv);
+ r = result.val;
+ rptr = result.rptr;
+ }
+ _ {
+ r =
+ trans_native_call(bcx.build, ccx.glues, lltaskptr, ccx.externs,
+ ccx.tn, ccx.llmod, name, pass_task, call_args);
+ rptr = bcx.build.BitCast(fcx.llretptr, T_ptr(T_i32()));
+ }
}
// We don't store the return value if it's nil, to avoid stomping on a nil
// pointer. This is the only concession made to non-i32 return values. See
// the FIXME above.
- if (!rty_is_nil && !uses_retptr) { bcx.build.Store(r, rptr); }
+ if !rty_is_nil && !uses_retptr { bcx.build.Store(r, rptr); }
- for (rec(ValueRef val, ty::t ty) d in drop_args) {
+ for d: {val: ValueRef, ty: ty::t} in drop_args {
bcx = drop_ty(bcx, d.val, d.ty).bcx;
}
bcx.build.RetVoid();
finish_fn(fcx, lltop);
}
-fn item_path(&@ast::item item) -> str[] { ret ~[item.ident]; }
+fn item_path(item: &@ast::item) -> str[] { ret ~[item.ident]; }
-fn collect_native_item(@crate_ctxt ccx, &@ast::native_item i, &str[] pt,
- &vt[str[]] v) {
- alt (i.node) {
- case (ast::native_item_fn(_, _, _)) {
- if (!ccx.obj_methods.contains_key(i.id)) {
- decl_native_fn_and_pair(ccx, i.span, pt, i.ident, i.id);
- }
+fn collect_native_item(ccx: @crate_ctxt, i: &@ast::native_item, pt: &str[],
+ v: &vt[str[]]) {
+ alt i.node {
+ ast::native_item_fn(_, _, _) {
+ if !ccx.obj_methods.contains_key(i.id) {
+ decl_native_fn_and_pair(ccx, i.span, pt, i.ident, i.id);
}
- case (_) {}
+ }
+ _ { }
}
}
-fn collect_item_1(@crate_ctxt ccx, &@ast::item i, &str[] pt, &vt[str[]] v) {
+fn collect_item_1(ccx: @crate_ctxt, i: &@ast::item, pt: &str[],
+ v: &vt[str[]]) {
visit::visit_item(i, pt + item_path(i), v);
- alt (i.node) {
- case (ast::item_const(_, _)) {
- auto typ = node_id_type(ccx, i.id);
- auto s = mangle_exported_name(ccx, pt + ~[i.ident],
- node_id_type(ccx, i.id));
- auto g = llvm::LLVMAddGlobal(ccx.llmod, type_of(ccx, i.span, typ),
- str::buf(s));
- ccx.item_symbols.insert(i.id, s);
- ccx.consts.insert(i.id, g);
- }
- case (_) { }
+ alt i.node {
+ ast::item_const(_, _) {
+ let typ = node_id_type(ccx, i.id);
+ let s =
+ mangle_exported_name(ccx, pt + ~[i.ident],
+ node_id_type(ccx, i.id));
+ let g =
+ llvm::LLVMAddGlobal(ccx.llmod, type_of(ccx, i.span, typ),
+ str::buf(s));
+ ccx.item_symbols.insert(i.id, s);
+ ccx.consts.insert(i.id, g);
+ }
+ _ { }
}
}
-fn collect_item_2(&@crate_ctxt ccx, &@ast::item i, &str[] pt, &vt[str[]] v) {
- auto new_pt = pt + item_path(i);
+fn collect_item_2(ccx: &@crate_ctxt, i: &@ast::item, pt: &str[],
+ v: &vt[str[]]) {
+ let new_pt = pt + item_path(i);
visit::visit_item(i, new_pt, v);
- alt (i.node) {
- case (ast::item_fn(?f, ?tps)) {
- if (!ccx.obj_methods.contains_key(i.id)) {
- decl_fn_and_pair(ccx, i.span, new_pt, "fn", tps, i.id);
- }
+ alt i.node {
+ ast::item_fn(f, tps) {
+ if !ccx.obj_methods.contains_key(i.id) {
+ decl_fn_and_pair(ccx, i.span, new_pt, "fn", tps, i.id);
}
- case (ast::item_obj(?ob, ?tps, ?ctor_id)) {
- decl_fn_and_pair(ccx, i.span, new_pt, "obj_ctor", tps, ctor_id);
- for (@ast::method m in ob.methods) {
- ccx.obj_methods.insert(m.node.id, ());
- }
+ }
+ ast::item_obj(ob, tps, ctor_id) {
+ decl_fn_and_pair(ccx, i.span, new_pt, "obj_ctor", tps, ctor_id);
+ for m: @ast::method in ob.methods {
+ ccx.obj_methods.insert(m.node.id, ());
}
- case (ast::item_res(_, ?dtor_id, ?tps, ?ctor_id)) {
- decl_fn_and_pair(ccx, i.span, new_pt, "res_ctor", tps, ctor_id);
- // Note that the destructor is associated with the item's id, not
- // the dtor_id. This is a bit counter-intuitive, but simplifies
- // ty_res, which would have to carry around two def_ids otherwise
- // -- one to identify the type, and one to find the dtor symbol.
- decl_fn_and_pair_full(ccx, i.span, new_pt, "res_dtor", tps, i.id,
- node_id_type(ccx, dtor_id));
- }
- case (_) { }
+ }
+ ast::item_res(_, dtor_id, tps, ctor_id) {
+ decl_fn_and_pair(ccx, i.span, new_pt, "res_ctor", tps, ctor_id);
+ // Note that the destructor is associated with the item's id, not
+ // the dtor_id. This is a bit counter-intuitive, but simplifies
+ // ty_res, which would have to carry around two def_ids otherwise
+ // -- one to identify the type, and one to find the dtor symbol.
+ decl_fn_and_pair_full(ccx, i.span, new_pt, "res_dtor", tps, i.id,
+ node_id_type(ccx, dtor_id));
+ }
+ _ { }
}
}
-fn collect_items(&@crate_ctxt ccx, @ast::crate crate) {
- auto visitor0 = visit::default_visitor();
- auto visitor1 =
- @rec(visit_native_item=bind collect_native_item(ccx, _, _, _),
- visit_item=bind collect_item_1(ccx, _, _, _) with *visitor0);
- auto visitor2 =
- @rec(visit_item=bind collect_item_2(ccx, _, _, _) with *visitor0);
+fn collect_items(ccx: &@crate_ctxt, crate: @ast::crate) {
+ let visitor0 = visit::default_visitor();
+ let visitor1 =
+ @{visit_native_item: bind collect_native_item(ccx, _, _, _),
+ visit_item: bind collect_item_1(ccx, _, _, _) with *visitor0};
+ let visitor2 =
+ @{visit_item: bind collect_item_2(ccx, _, _, _) with *visitor0};
visit::visit_crate(*crate, ~[], visit::mk_vt(visitor1));
visit::visit_crate(*crate, ~[], visit::mk_vt(visitor2));
}
-fn collect_tag_ctor(@crate_ctxt ccx, &@ast::item i, &str[] pt, &vt[str[]] v) {
- auto new_pt = pt + item_path(i);
+fn collect_tag_ctor(ccx: @crate_ctxt, i: &@ast::item, pt: &str[],
+ v: &vt[str[]]) {
+ let new_pt = pt + item_path(i);
visit::visit_item(i, new_pt, v);
- alt (i.node) {
- case (ast::item_tag(?variants, ?tps)) {
- for (ast::variant variant in variants) {
- if (std::ivec::len(variant.node.args) != 0u) {
- decl_fn_and_pair(ccx, i.span,
- new_pt + ~[variant.node.name], "tag",
- tps, variant.node.id);
- }
+ alt i.node {
+ ast::item_tag(variants, tps) {
+ for variant: ast::variant in variants {
+ if std::ivec::len(variant.node.args) != 0u {
+ decl_fn_and_pair(ccx, i.span, new_pt + ~[variant.node.name],
+ "tag", tps, variant.node.id);
}
}
- case (_) {/* fall through */ }
+ }
+ _ {/* fall through */ }
}
}
-fn collect_tag_ctors(&@crate_ctxt ccx, @ast::crate crate) {
- auto visitor =
- @rec(visit_item=bind collect_tag_ctor(ccx, _, _, _)
- with *visit::default_visitor());
+fn collect_tag_ctors(ccx: &@crate_ctxt, crate: @ast::crate) {
+ let visitor =
+ @{visit_item: bind collect_tag_ctor(ccx, _, _, _)
+ with *visit::default_visitor()};
visit::visit_crate(*crate, ~[], visit::mk_vt(visitor));
}
// The constant translation pass.
-fn trans_constant(@crate_ctxt ccx, &@ast::item it, &str[] pt, &vt[str[]] v) {
- auto new_pt = pt + item_path(it);
+fn trans_constant(ccx: @crate_ctxt, it: &@ast::item, pt: &str[],
+ v: &vt[str[]]) {
+ let new_pt = pt + item_path(it);
visit::visit_item(it, new_pt, v);
- alt (it.node) {
- case (ast::item_tag(?variants, _)) {
- auto i = 0u;
- auto n_variants = std::ivec::len[ast::variant](variants);
- while (i < n_variants) {
- auto variant = variants.(i);
- auto p = new_pt + ~[it.ident, variant.node.name, "discrim"];
- auto s = mangle_exported_name(ccx, p, ty::mk_int(ccx.tcx));
- auto discrim_gvar =
- llvm::LLVMAddGlobal(ccx.llmod, T_int(), str::buf(s));
- if (n_variants != 1u) {
- llvm::LLVMSetInitializer(discrim_gvar, C_int(i as int));
- llvm::LLVMSetGlobalConstant(discrim_gvar, True);
- }
- ccx.discrims.insert(variant.node.id, discrim_gvar);
- ccx.discrim_symbols.insert(variant.node.id, s);
- i += 1u;
+ alt it.node {
+ ast::item_tag(variants, _) {
+ let i = 0u;
+ let n_variants = std::ivec::len[ast::variant](variants);
+ while i < n_variants {
+ let variant = variants.(i);
+ let p = new_pt + ~[it.ident, variant.node.name, "discrim"];
+ let s = mangle_exported_name(ccx, p, ty::mk_int(ccx.tcx));
+ let discrim_gvar =
+ llvm::LLVMAddGlobal(ccx.llmod, T_int(), str::buf(s));
+ if n_variants != 1u {
+ llvm::LLVMSetInitializer(discrim_gvar, C_int(i as int));
+ llvm::LLVMSetGlobalConstant(discrim_gvar, True);
}
+ ccx.discrims.insert(variant.node.id, discrim_gvar);
+ ccx.discrim_symbols.insert(variant.node.id, s);
+ i += 1u;
}
- case (_) { }
+ }
+ _ { }
}
}
-fn trans_constants(&@crate_ctxt ccx, @ast::crate crate) {
- auto visitor =
- @rec(visit_item=bind trans_constant(ccx, _, _, _)
- with *visit::default_visitor());
+fn trans_constants(ccx: &@crate_ctxt, crate: @ast::crate) {
+ let visitor =
+ @{visit_item: bind trans_constant(ccx, _, _, _)
+ with *visit::default_visitor()};
visit::visit_crate(*crate, ~[], visit::mk_vt(visitor));
}
-fn vp2i(&@block_ctxt cx, ValueRef v) -> ValueRef {
+fn vp2i(cx: &@block_ctxt, v: ValueRef) -> ValueRef {
ret cx.build.PtrToInt(v, T_int());
}
-fn vi2p(&@block_ctxt cx, ValueRef v, TypeRef t) -> ValueRef {
+fn vi2p(cx: &@block_ctxt, v: ValueRef, t: TypeRef) -> ValueRef {
ret cx.build.IntToPtr(v, t);
}
-fn p2i(ValueRef v) -> ValueRef { ret llvm::LLVMConstPtrToInt(v, T_int()); }
+fn p2i(v: ValueRef) -> ValueRef { ret llvm::LLVMConstPtrToInt(v, T_int()); }
-fn i2p(ValueRef v, TypeRef t) -> ValueRef {
+fn i2p(v: ValueRef, t: TypeRef) -> ValueRef {
ret llvm::LLVMConstIntToPtr(v, t);
}
-fn declare_intrinsics(ModuleRef llmod) -> hashmap[str, ValueRef] {
- let TypeRef[] T_memmove32_args =
+fn declare_intrinsics(llmod: ModuleRef) -> hashmap[str, ValueRef] {
+ let T_memmove32_args: TypeRef[] =
~[T_ptr(T_i8()), T_ptr(T_i8()), T_i32(), T_i32(), T_i1()];
- let TypeRef[] T_memmove64_args =
+ let T_memmove64_args: TypeRef[] =
~[T_ptr(T_i8()), T_ptr(T_i8()), T_i64(), T_i32(), T_i1()];
- let TypeRef[] T_memset32_args =
+ let T_memset32_args: TypeRef[] =
~[T_ptr(T_i8()), T_i8(), T_i32(), T_i32(), T_i1()];
- let TypeRef[] T_memset64_args =
+ let T_memset64_args: TypeRef[] =
~[T_ptr(T_i8()), T_i8(), T_i64(), T_i32(), T_i1()];
- let TypeRef[] T_trap_args = ~[];
- auto memmove32 =
+ let T_trap_args: TypeRef[] = ~[];
+ let memmove32 =
decl_cdecl_fn(llmod, "llvm.memmove.p0i8.p0i8.i32",
T_fn(T_memmove32_args, T_void()));
- auto memmove64 =
+ let memmove64 =
decl_cdecl_fn(llmod, "llvm.memmove.p0i8.p0i8.i64",
T_fn(T_memmove64_args, T_void()));
- auto memset32 =
+ let memset32 =
decl_cdecl_fn(llmod, "llvm.memset.p0i8.i32",
T_fn(T_memset32_args, T_void()));
- auto memset64 =
+ let memset64 =
decl_cdecl_fn(llmod, "llvm.memset.p0i8.i64",
T_fn(T_memset64_args, T_void()));
- auto trap =
- decl_cdecl_fn(llmod, "llvm.trap", T_fn(T_trap_args, T_void()));
- auto intrinsics = new_str_hash[ValueRef]();
+ let trap = decl_cdecl_fn(llmod, "llvm.trap", T_fn(T_trap_args, T_void()));
+ let intrinsics = new_str_hash[ValueRef]();
intrinsics.insert("llvm.memmove.p0i8.p0i8.i32", memmove32);
intrinsics.insert("llvm.memmove.p0i8.p0i8.i64", memmove64);
intrinsics.insert("llvm.memset.p0i8.i32", memset32);
@@ -8029,60 +7854,60 @@
ret intrinsics;
}
-fn trace_str(&@block_ctxt cx, str s) {
+fn trace_str(cx: &@block_ctxt, s: str) {
cx.build.Call(bcx_ccx(cx).upcalls.trace_str,
~[cx.fcx.lltaskptr, C_cstr(bcx_ccx(cx), s)]);
}
-fn trace_word(&@block_ctxt cx, ValueRef v) {
+fn trace_word(cx: &@block_ctxt, v: ValueRef) {
cx.build.Call(bcx_ccx(cx).upcalls.trace_word, ~[cx.fcx.lltaskptr, v]);
}
-fn trace_ptr(&@block_ctxt cx, ValueRef v) {
+fn trace_ptr(cx: &@block_ctxt, v: ValueRef) {
trace_word(cx, cx.build.PtrToInt(v, T_int()));
}
-fn trap(&@block_ctxt bcx) {
- let ValueRef[] v = ~[];
- alt (bcx_ccx(bcx).intrinsics.find("llvm.trap")) {
- case (some(?x)) { bcx.build.Call(x, v); }
- case (_) { bcx_ccx(bcx).sess.bug("unbound llvm.trap in trap"); }
+fn trap(bcx: &@block_ctxt) {
+ let v: ValueRef[] = ~[];
+ alt bcx_ccx(bcx).intrinsics.find("llvm.trap") {
+ some(x) { bcx.build.Call(x, v); }
+ _ { bcx_ccx(bcx).sess.bug("unbound llvm.trap in trap"); }
}
}
-fn decl_no_op_type_glue(ModuleRef llmod, TypeRef taskptr_type) -> ValueRef {
- auto ty = T_fn(~[taskptr_type, T_ptr(T_i8())], T_void());
+fn decl_no_op_type_glue(llmod: ModuleRef, taskptr_type: TypeRef) -> ValueRef {
+ let ty = T_fn(~[taskptr_type, T_ptr(T_i8())], T_void());
ret decl_fastcall_fn(llmod, abi::no_op_type_glue_name(), ty);
}
-fn make_no_op_type_glue(ValueRef fun) {
- auto bb_name = str::buf("_rust_no_op_type_glue_bb");
- auto llbb = llvm::LLVMAppendBasicBlock(fun, bb_name);
+fn make_no_op_type_glue(fun: ValueRef) {
+ let bb_name = str::buf("_rust_no_op_type_glue_bb");
+ let llbb = llvm::LLVMAppendBasicBlock(fun, bb_name);
new_builder(llbb).RetVoid();
}
-fn vec_fill(&@block_ctxt bcx, ValueRef v) -> ValueRef {
+fn vec_fill(bcx: &@block_ctxt, v: ValueRef) -> ValueRef {
ret bcx.build.Load(bcx.build.GEP(v,
~[C_int(0), C_int(abi::vec_elt_fill)]));
}
-fn vec_p0(&@block_ctxt bcx, ValueRef v) -> ValueRef {
- auto p = bcx.build.GEP(v, ~[C_int(0), C_int(abi::vec_elt_data)]);
+fn vec_p0(bcx: &@block_ctxt, v: ValueRef) -> ValueRef {
+ let p = bcx.build.GEP(v, ~[C_int(0), C_int(abi::vec_elt_data)]);
ret bcx.build.PointerCast(p, T_ptr(T_i8()));
}
-fn make_glues(ModuleRef llmod, TypeRef taskptr_type) -> @glue_fns {
- ret @rec(no_op_type_glue=decl_no_op_type_glue(llmod, taskptr_type));
+fn make_glues(llmod: ModuleRef, taskptr_type: TypeRef) -> @glue_fns {
+ ret @{no_op_type_glue: decl_no_op_type_glue(llmod, taskptr_type)};
}
-fn make_common_glue(&session::session sess, &str output) {
+fn make_common_glue(sess: &session::session, output: &str) {
// FIXME: part of this is repetitive and is probably a good idea
// to autogen it.
- auto task_type = T_task();
- auto taskptr_type = T_ptr(task_type);
+ let task_type = T_task();
+ let taskptr_type = T_ptr(task_type);
- auto llmod =
+ let llmod =
llvm::LLVMModuleCreateWithNameInContext(str::buf("rust_out"),
llvm::LLVMGetGlobalContext());
llvm::LLVMSetDataLayout(llmod, str::buf(x86::get_data_layout()));
@@ -8094,20 +7919,19 @@
link::write::run_passes(sess, llmod, output);
}
-fn create_module_map(&@crate_ctxt ccx) -> ValueRef {
- auto elttype = T_struct(~[T_int(), T_int()]);
- auto maptype = T_array(elttype, ccx.module_data.size() + 1u);
- auto map =
+fn create_module_map(ccx: &@crate_ctxt) -> ValueRef {
+ let elttype = T_struct(~[T_int(), T_int()]);
+ let maptype = T_array(elttype, ccx.module_data.size() + 1u);
+ let map =
llvm::LLVMAddGlobal(ccx.llmod, maptype, str::buf("_rust_mod_map"));
llvm::LLVMSetLinkage(map,
- lib::llvm::LLVMInternalLinkage as
- llvm::Linkage);
- let ValueRef[] elts = ~[];
- for each (@rec(str key, ValueRef val) item in ccx.module_data.items()) {
- auto elt = C_struct(~[p2i(C_cstr(ccx, item.key)), p2i(item.val)]);
+ lib::llvm::LLVMInternalLinkage as llvm::Linkage);
+ let elts: ValueRef[] = ~[];
+ for each item: @{key: str, val: ValueRef} in ccx.module_data.items() {
+ let elt = C_struct(~[p2i(C_cstr(ccx, item.key)), p2i(item.val)]);
elts += ~[elt];
}
- auto term = C_struct(~[C_int(0), C_int(0)]);
+ let term = C_struct(~[C_int(0), C_int(0)]);
elts += ~[term];
llvm::LLVMSetInitializer(map, C_array(elttype, elts));
ret map;
@@ -8115,27 +7939,27 @@
// FIXME use hashed metadata instead of crate names once we have that
-fn create_crate_map(&@crate_ctxt ccx) -> ValueRef {
- let ValueRef[] subcrates = ~[];
- auto i = 1;
- auto cstore = ccx.sess.get_cstore();
- while (cstore::have_crate_data(cstore, i)) {
- auto name = cstore::get_crate_data(cstore, i).name;
- auto cr =
+fn create_crate_map(ccx: &@crate_ctxt) -> ValueRef {
+ let subcrates: ValueRef[] = ~[];
+ let i = 1;
+ let cstore = ccx.sess.get_cstore();
+ while cstore::have_crate_data(cstore, i) {
+ let name = cstore::get_crate_data(cstore, i).name;
+ let cr =
llvm::LLVMAddGlobal(ccx.llmod, T_int(),
str::buf("_rust_crate_map_" + name));
subcrates += ~[p2i(cr)];
i += 1;
}
subcrates += ~[C_int(0)];
- auto mapname;
- if (ccx.sess.get_opts().library) {
+ let mapname;
+ if ccx.sess.get_opts().library {
mapname = ccx.link_meta.name;
} else { mapname = "toplevel"; }
- auto sym_name = "_rust_crate_map_" + mapname;
- auto arrtype = T_array(T_int(), std::ivec::len[ValueRef](subcrates));
- auto maptype = T_struct(~[T_int(), arrtype]);
- auto map = llvm::LLVMAddGlobal(ccx.llmod, maptype, str::buf(sym_name));
+ let sym_name = "_rust_crate_map_" + mapname;
+ let arrtype = T_array(T_int(), std::ivec::len[ValueRef](subcrates));
+ let maptype = T_struct(~[T_int(), arrtype]);
+ let map = llvm::LLVMAddGlobal(ccx.llmod, maptype, str::buf(sym_name));
llvm::LLVMSetLinkage(map,
lib::llvm::LLVMExternalLinkage as llvm::Linkage);
llvm::LLVMSetInitializer(map,
@@ -8144,11 +7968,11 @@
ret map;
}
-fn write_metadata(&@crate_ctxt cx, &@ast::crate crate) {
- if (!cx.sess.get_opts().library) { ret; }
- auto llmeta = C_postr(metadata::encoder::encode_metadata(cx, crate));
- auto llconst = trans_common::C_struct(~[llmeta]);
- auto llglobal =
+fn write_metadata(cx: &@crate_ctxt, crate: &@ast::crate) {
+ if !cx.sess.get_opts().library { ret; }
+ let llmeta = C_postr(metadata::encoder::encode_metadata(cx, crate));
+ let llconst = trans_common::C_struct(~[llmeta]);
+ let llglobal =
llvm::LLVMAddGlobal(cx.llmod, val_ty(llconst),
str::buf("rust_metadata"));
llvm::LLVMSetInitializer(llglobal, llconst);
@@ -8156,9 +7980,9 @@
llvm::LLVMSetLinkage(llglobal,
lib::llvm::LLVMInternalLinkage as llvm::Linkage);
- auto t_ptr_i8 = T_ptr(T_i8());
+ let t_ptr_i8 = T_ptr(T_i8());
llglobal = llvm::LLVMConstBitCast(llglobal, t_ptr_i8);
- auto llvm_used =
+ let llvm_used =
llvm::LLVMAddGlobal(cx.llmod, T_array(t_ptr_i8, 1u),
str::buf("llvm.used"));
llvm::LLVMSetLinkage(llvm_used,
@@ -8166,67 +7990,68 @@
llvm::LLVMSetInitializer(llvm_used, C_array(t_ptr_i8, ~[llglobal]));
}
-fn trans_crate(&session::session sess, &@ast::crate crate, &ty::ctxt tcx,
- &str output, &ast_map::map amap) -> ModuleRef {
- auto llmod =
+fn trans_crate(sess: &session::session, crate: &@ast::crate, tcx: &ty::ctxt,
+ output: &str, amap: &ast_map::map) -> ModuleRef {
+ let llmod =
llvm::LLVMModuleCreateWithNameInContext(str::buf("rust_out"),
llvm::LLVMGetGlobalContext());
llvm::LLVMSetDataLayout(llmod, str::buf(x86::get_data_layout()));
llvm::LLVMSetTarget(llmod, str::buf(x86::get_target_triple()));
- auto td = mk_target_data(x86::get_data_layout());
- auto tn = mk_type_names();
- auto intrinsics = declare_intrinsics(llmod);
- auto task_type = T_task();
- auto taskptr_type = T_ptr(task_type);
- auto tydesc_type = T_tydesc(taskptr_type);
- auto glues = make_glues(llmod, taskptr_type);
- auto hasher = ty::hash_ty;
- auto eqer = ty::eq_ty;
- auto tag_sizes = map::mk_hashmap[ty::t, uint](hasher, eqer);
- auto tydescs = map::mk_hashmap[ty::t, @tydesc_info](hasher, eqer);
- auto lltypes = map::mk_hashmap[ty::t, TypeRef](hasher, eqer);
- auto sha1s = map::mk_hashmap[ty::t, str](hasher, eqer);
- auto short_names = map::mk_hashmap[ty::t, str](hasher, eqer);
- auto sha = std::sha1::mk_sha1();
- auto ccx =
- @rec(sess=sess,
- llmod=llmod,
- td=td,
- tn=tn,
- externs=new_str_hash[ValueRef](),
- intrinsics=intrinsics,
- item_ids=new_int_hash[ValueRef](),
- ast_map=amap,
- item_symbols=new_int_hash[str](),
- mutable main_fn=none[ValueRef],
- link_meta=link::build_link_meta(sess, *crate, output, sha),
- tag_sizes=tag_sizes,
- discrims=new_int_hash[ValueRef](),
- discrim_symbols=new_int_hash[str](),
- fn_pairs=new_int_hash[ValueRef](),
- consts=new_int_hash[ValueRef](),
- obj_methods=new_int_hash[()](),
- tydescs=tydescs,
- module_data=new_str_hash[ValueRef](),
- lltypes=lltypes,
- glues=glues,
- names=namegen(0),
- sha=sha,
- type_sha1s=sha1s,
- type_short_names=short_names,
- tcx=tcx,
- stats=rec(mutable n_static_tydescs=0u,
- mutable n_derived_tydescs=0u,
- mutable n_glues_created=0u,
- mutable n_null_glues=0u,
- mutable n_real_glues=0u,
- fn_times=@mutable ~[]),
- upcalls=upcall::declare_upcalls(tn, tydesc_type, taskptr_type,
- llmod),
- rust_object_type=T_rust_object(),
- tydesc_type=tydesc_type,
- task_type=task_type);
- auto cx = new_local_ctxt(ccx);
+ let td = mk_target_data(x86::get_data_layout());
+ let tn = mk_type_names();
+ let intrinsics = declare_intrinsics(llmod);
+ let task_type = T_task();
+ let taskptr_type = T_ptr(task_type);
+ let tydesc_type = T_tydesc(taskptr_type);
+ let glues = make_glues(llmod, taskptr_type);
+ let hasher = ty::hash_ty;
+ let eqer = ty::eq_ty;
+ let tag_sizes = map::mk_hashmap[ty::t, uint](hasher, eqer);
+ let tydescs = map::mk_hashmap[ty::t, @tydesc_info](hasher, eqer);
+ let lltypes = map::mk_hashmap[ty::t, TypeRef](hasher, eqer);
+ let sha1s = map::mk_hashmap[ty::t, str](hasher, eqer);
+ let short_names = map::mk_hashmap[ty::t, str](hasher, eqer);
+ let sha = std::sha1::mk_sha1();
+ let ccx =
+ @{sess: sess,
+ llmod: llmod,
+ td: td,
+ tn: tn,
+ externs: new_str_hash[ValueRef](),
+ intrinsics: intrinsics,
+ item_ids: new_int_hash[ValueRef](),
+ ast_map: amap,
+ item_symbols: new_int_hash[str](),
+ mutable main_fn: none[ValueRef],
+ link_meta: link::build_link_meta(sess, *crate, output, sha),
+ tag_sizes: tag_sizes,
+ discrims: new_int_hash[ValueRef](),
+ discrim_symbols: new_int_hash[str](),
+ fn_pairs: new_int_hash[ValueRef](),
+ consts: new_int_hash[ValueRef](),
+ obj_methods: new_int_hash[()](),
+ tydescs: tydescs,
+ module_data: new_str_hash[ValueRef](),
+ lltypes: lltypes,
+ glues: glues,
+ names: namegen(0),
+ sha: sha,
+ type_sha1s: sha1s,
+ type_short_names: short_names,
+ tcx: tcx,
+ stats:
+ {mutable n_static_tydescs: 0u,
+ mutable n_derived_tydescs: 0u,
+ mutable n_glues_created: 0u,
+ mutable n_null_glues: 0u,
+ mutable n_real_glues: 0u,
+ fn_times: @mutable ~[]},
+ upcalls:
+ upcall::declare_upcalls(tn, tydesc_type, taskptr_type, llmod),
+ rust_object_type: T_rust_object(),
+ tydesc_type: tydesc_type,
+ task_type: task_type};
+ let cx = new_local_ctxt(ccx);
collect_items(ccx, crate);
collect_tag_ctors(ccx, crate);
trans_constants(ccx, crate);
@@ -8236,7 +8061,7 @@
// Translate the metadata:
write_metadata(cx.ccx, crate);
- if (ccx.sess.get_opts().stats) {
+ if ccx.sess.get_opts().stats {
log_err "--- trans stats ---";
log_err #fmt("n_static_tydescs: %u", ccx.stats.n_static_tydescs);
log_err #fmt("n_derived_tydescs: %u", ccx.stats.n_derived_tydescs);
@@ -8244,7 +8069,8 @@
log_err #fmt("n_null_glues: %u", ccx.stats.n_null_glues);
log_err #fmt("n_real_glues: %u", ccx.stats.n_real_glues);
- for (rec(str ident, int time) timing in *ccx.stats.fn_times) {
+
+ for timing: {ident: str, time: int} in *ccx.stats.fn_times {
log_err #fmt("time: %s took %d ms", timing.ident, timing.time);
}
}
diff --git a/src/comp/middle/trans_alt.rs b/src/comp/middle/trans_alt.rs
index f88ec69c..dbf8e47 100644
--- a/src/comp/middle/trans_alt.rs
+++ b/src/comp/middle/trans_alt.rs
@@ -23,262 +23,246 @@
// An option identifying a branch (either a literal or a tag variant)
tag opt {
lit(@ast::lit);
- var(uint /* variant id */, rec(def_id tg, def_id var) /* variant dids */);
+ var(/* variant id */uint, /* variant dids */{tg: def_id, var: def_id});
}
-fn opt_eq(&opt a, &opt b) -> bool {
- alt (a) {
- lit(?la) {
- ret alt (b) { lit(?lb) { lit_eq(la, lb) } var(_, _) { false } };
- }
- var(?ida, _) {
- ret alt (b) { lit(_) { false } var(?idb, _) { ida == idb } };
- }
+fn opt_eq(a: &opt, b: &opt) -> bool {
+ alt a {
+ lit(la) {
+ ret alt b { lit(lb) { lit_eq(la, lb) } var(_, _) { false } };
+ }
+ var(ida, _) {
+ ret alt b { lit(_) { false } var(idb, _) { ida == idb } };
+ }
}
}
-fn trans_opt(&@block_ctxt bcx, &opt o) -> result {
- alt (o) {
- lit(?l) { ret trans::trans_lit(bcx, *l); }
- var(?id, _) { ret rslt(bcx, C_int(id as int)); }
+fn trans_opt(bcx: &@block_ctxt, o: &opt) -> result {
+ alt o {
+ lit(l) { ret trans::trans_lit(bcx, *l); }
+ var(id, _) { ret rslt(bcx, C_int(id as int)); }
}
}
-fn variant_opt(&@crate_ctxt ccx, ast::node_id pat_id) -> opt {
- auto vdef = ast::variant_def_ids(ccx.tcx.def_map.get(pat_id));
- auto variants = ty::tag_variants(ccx.tcx, vdef.tg);
- auto i = 0u;
- for (ty::variant_info v in variants) {
- if (vdef.var == v.id) { ret var(i, vdef); }
+fn variant_opt(ccx: &@crate_ctxt, pat_id: ast::node_id) -> opt {
+ let vdef = ast::variant_def_ids(ccx.tcx.def_map.get(pat_id));
+ let variants = ty::tag_variants(ccx.tcx, vdef.tg);
+ let i = 0u;
+ for v: ty::variant_info in variants {
+ if vdef.var == v.id { ret var(i, vdef); }
i += 1u;
}
fail;
}
-type bind_map = rec(ast::ident ident, ValueRef val)[];
-type match_branch = @rec((@ast::pat)[] pats,
- BasicBlockRef body,
- mutable bind_map bound);
+type bind_map = {ident: ast::ident, val: ValueRef}[];
+type match_branch =
+ @{pats: (@ast::pat)[], body: BasicBlockRef, mutable bound: bind_map};
type match = match_branch[];
-fn matches_always(&@ast::pat p) -> bool {
+fn matches_always(p: &@ast::pat) -> bool {
ret alt p.node {
- ast::pat_wild { true }
- ast::pat_bind(_) { true }
- ast::pat_rec(_, _) { true }
- _ { false }
- };
+ ast::pat_wild. { true }
+ ast::pat_bind(_) { true }
+ ast::pat_rec(_, _) { true }
+ _ { false }
+ };
}
-fn bind_for_pat(&@ast::pat p, &match_branch br, ValueRef val) {
+fn bind_for_pat(p: &@ast::pat, br: &match_branch, val: ValueRef) {
alt p.node {
- ast::pat_bind(?name) {
- br.bound += ~[rec(ident=name, val=val)];
- }
- _ {}
+ ast::pat_bind(name) { br.bound += ~[{ident: name, val: val}]; }
+ _ { }
}
}
-type enter_pat = fn(&@ast::pat) -> option::t[(@ast::pat)[]];
+type enter_pat = fn(&@ast::pat) -> option::t[(@ast::pat)[]] ;
-fn enter_match(&match m, uint col, ValueRef val, &enter_pat e) -> match {
- auto result = ~[];
- for (match_branch br in m) {
- alt (e(br.pats.(col))) {
- some(?sub) {
- auto pats = ivec::slice(br.pats, 0u, col) +
- sub + ivec::slice(br.pats, col + 1u, ivec::len(br.pats));
- auto new_br = @rec(pats=pats with *br);
- result += ~[new_br];
- bind_for_pat(br.pats.(col), new_br, val);
- }
- none {}
+fn enter_match(m: &match, col: uint, val: ValueRef, e: &enter_pat) -> match {
+ let result = ~[];
+ for br: match_branch in m {
+ alt e(br.pats.(col)) {
+ some(sub) {
+ let pats =
+ ivec::slice(br.pats, 0u, col) + sub +
+ ivec::slice(br.pats, col + 1u, ivec::len(br.pats));
+ let new_br = @{pats: pats with *br};
+ result += ~[new_br];
+ bind_for_pat(br.pats.(col), new_br, val);
+ }
+ none. { }
}
}
ret result;
}
-fn enter_default(&match m, uint col, ValueRef val) -> match {
- fn e(&@ast::pat p) -> option::t[(@ast::pat)[]] {
- ret if (matches_always(p)) { some(~[]) }
- else { none };
+fn enter_default(m: &match, col: uint, val: ValueRef) -> match {
+ fn e(p: &@ast::pat) -> option::t[(@ast::pat)[]] {
+ ret if matches_always(p) { some(~[]) } else { none };
}
ret enter_match(m, col, val, e);
}
-fn enter_opt(&@crate_ctxt ccx, &match m, &opt opt,
- uint col, uint tag_size, ValueRef val) -> match {
- auto dummy = @rec(id=0, node=ast::pat_wild, span=rec(lo=0u, hi=0u));
- fn e(&@crate_ctxt ccx, &@ast::pat dummy, &opt opt, uint size,
- &@ast::pat p) -> option::t[(@ast::pat)[]] {
- alt (p.node) {
- ast::pat_tag(?ctor, ?subpats) {
- ret if (opt_eq(variant_opt(ccx, p.id), opt)) { some(subpats) }
- else { none };
- }
- ast::pat_lit(?l) {
- ret if (opt_eq(lit(l), opt)) { some(~[]) }
- else { none };
- }
- _ { ret some(ivec::init_elt(dummy, size)); }
+fn enter_opt(ccx: &@crate_ctxt, m: &match, opt: &opt, col: uint,
+ tag_size: uint, val: ValueRef) -> match {
+ let dummy = @{id: 0, node: ast::pat_wild, span: {lo: 0u, hi: 0u}};
+ fn e(ccx: &@crate_ctxt, dummy: &@ast::pat, opt: &opt, size: uint,
+ p: &@ast::pat) -> option::t[(@ast::pat)[]] {
+ alt p.node {
+ ast::pat_tag(ctor, subpats) {
+ ret if opt_eq(variant_opt(ccx, p.id), opt) {
+ some(subpats)
+ } else { none };
+ }
+ ast::pat_lit(l) {
+ ret if opt_eq(lit(l), opt) { some(~[]) } else { none };
+ }
+ _ { ret some(ivec::init_elt(dummy, size)); }
}
}
ret enter_match(m, col, val, bind e(ccx, dummy, opt, tag_size, _));
}
-fn enter_rec(&match m, uint col, &ast::ident[] fields,
- ValueRef val) -> match {
- auto dummy = @rec(id=0, node=ast::pat_wild, span=rec(lo=0u, hi=0u));
- fn e(&@ast::pat dummy, &ast::ident[] fields, &@ast::pat p)
- -> option::t[(@ast::pat)[]] {
- alt (p.node) {
- ast::pat_rec(?fpats, _) {
- auto pats = ~[];
- for (ast::ident fname in fields) {
- auto pat = dummy;
- for (ast::field_pat fpat in fpats) {
- if (str::eq(fpat.ident, fname)) {
- pat = fpat.pat;
- break;
- }
- }
- pats += ~[pat];
+fn enter_rec(m: &match, col: uint, fields: &ast::ident[], val: ValueRef) ->
+ match {
+ let dummy = @{id: 0, node: ast::pat_wild, span: {lo: 0u, hi: 0u}};
+ fn e(dummy: &@ast::pat, fields: &ast::ident[], p: &@ast::pat) ->
+ option::t[(@ast::pat)[]] {
+ alt p.node {
+ ast::pat_rec(fpats, _) {
+ let pats = ~[];
+ for fname: ast::ident in fields {
+ let pat = dummy;
+ for fpat: ast::field_pat in fpats {
+ if str::eq(fpat.ident, fname) { pat = fpat.pat; break; }
}
- ret some(pats);
+ pats += ~[pat];
}
- _ { ret some(ivec::init_elt(dummy, ivec::len(fields))); }
+ ret some(pats);
+ }
+ _ { ret some(ivec::init_elt(dummy, ivec::len(fields))); }
}
}
ret enter_match(m, col, val, bind e(dummy, fields, _));
}
-fn enter_box(&match m, uint col, ValueRef val) -> match {
- auto dummy = @rec(id=0, node=ast::pat_wild, span=rec(lo=0u, hi=0u));
- fn e(&@ast::pat dummy, &@ast::pat p) -> option::t[(@ast::pat)[]] {
- alt (p.node) {
- ast::pat_box(?sub) { ret some(~[sub]); }
- _ { ret some(~[dummy]); }
+fn enter_box(m: &match, col: uint, val: ValueRef) -> match {
+ let dummy = @{id: 0, node: ast::pat_wild, span: {lo: 0u, hi: 0u}};
+ fn e(dummy: &@ast::pat, p: &@ast::pat) -> option::t[(@ast::pat)[]] {
+ alt p.node {
+ ast::pat_box(sub) { ret some(~[sub]); }
+ _ { ret some(~[dummy]); }
}
}
ret enter_match(m, col, val, bind e(dummy, _));
}
-fn get_options(&@crate_ctxt ccx, &match m, uint col) -> opt[] {
- fn add_to_set(&mutable opt[] set, &opt val) {
- for (opt l in set) {
- if (opt_eq(l, val)) { ret; }
- }
+fn get_options(ccx: &@crate_ctxt, m: &match, col: uint) -> opt[] {
+ fn add_to_set(set: &mutable opt[], val: &opt) {
+ for l: opt in set { if opt_eq(l, val) { ret; } }
set += ~[val];
}
- auto found = ~[];
- for (match_branch br in m) {
- alt (br.pats.(col).node) {
- ast::pat_lit(?l) { add_to_set(found, lit(l)); }
- ast::pat_tag(_, _) {
- add_to_set(found, variant_opt(ccx, br.pats.(col).id));
- }
- _ {}
+ let found = ~[];
+ for br: match_branch in m {
+ alt br.pats.(col).node {
+ ast::pat_lit(l) { add_to_set(found, lit(l)); }
+ ast::pat_tag(_, _) {
+ add_to_set(found, variant_opt(ccx, br.pats.(col).id));
+ }
+ _ { }
}
}
ret found;
}
-fn extract_variant_args(@block_ctxt bcx, ast::node_id pat_id,
- &rec(def_id tg, def_id var) vdefs, ValueRef val)
- -> rec(ValueRef[] vals, @block_ctxt bcx) {
- auto ccx = bcx.fcx.lcx.ccx;
- auto ty_param_substs = ty::node_id_to_type_params(ccx.tcx, pat_id);
- auto blobptr = val;
- auto variants = ty::tag_variants(ccx.tcx, vdefs.tg);
- auto args = ~[];
- auto size = ivec::len(ty::tag_variant_with_id
- (ccx.tcx, vdefs.tg, vdefs.var).args);
- if (size > 0u && ivec::len(variants) != 1u) {
- auto tagptr = bcx.build.PointerCast
- (val, trans_common::T_opaque_tag_ptr(ccx.tn));
+fn extract_variant_args(bcx: @block_ctxt, pat_id: ast::node_id,
+ vdefs: &{tg: def_id, var: def_id}, val: ValueRef) ->
+ {vals: ValueRef[], bcx: @block_ctxt} {
+ let ccx = bcx.fcx.lcx.ccx;
+ let ty_param_substs = ty::node_id_to_type_params(ccx.tcx, pat_id);
+ let blobptr = val;
+ let variants = ty::tag_variants(ccx.tcx, vdefs.tg);
+ let args = ~[];
+ let size =
+ ivec::len(ty::tag_variant_with_id(ccx.tcx, vdefs.tg, vdefs.var).args);
+ if size > 0u && ivec::len(variants) != 1u {
+ let tagptr =
+ bcx.build.PointerCast(val,
+ trans_common::T_opaque_tag_ptr(ccx.tn));
blobptr = bcx.build.GEP(tagptr, ~[C_int(0), C_int(1)]);
}
- auto i = 0u;
- while (i < size) {
- auto r = trans::GEP_tag(bcx, blobptr, vdefs.tg, vdefs.var,
- ty_param_substs, i as int);
+ let i = 0u;
+ while i < size {
+ let r =
+ trans::GEP_tag(bcx, blobptr, vdefs.tg, vdefs.var, ty_param_substs,
+ i as int);
bcx = r.bcx;
args += ~[r.val];
i += 1u;
}
- ret rec(vals=args, bcx=bcx);
+ ret {vals: args, bcx: bcx};
}
-fn collect_record_fields(&match m, uint col) -> ast::ident[] {
- auto fields = ~[];
- for (match_branch br in m) {
- alt (br.pats.(col).node) {
- ast::pat_rec(?fs, _) {
- for (ast::field_pat f in fs) {
- if (!ivec::any(bind str::eq(f.ident, _), fields)) {
- fields += ~[f.ident];
- }
+fn collect_record_fields(m: &match, col: uint) -> ast::ident[] {
+ let fields = ~[];
+ for br: match_branch in m {
+ alt br.pats.(col).node {
+ ast::pat_rec(fs, _) {
+ for f: ast::field_pat in fs {
+ if !ivec::any(bind str::eq(f.ident, _), fields) {
+ fields += ~[f.ident];
}
}
- _ {}
+ }
+ _ { }
}
}
ret fields;
}
-fn any_box_pat(&match m, uint col) -> bool {
- for (match_branch br in m) {
- alt (br.pats.(col).node) {
- ast::pat_box(_) { ret true; }
- _ {}
- }
+fn any_box_pat(m: &match, col: uint) -> bool {
+ for br: match_branch in m {
+ alt br.pats.(col).node { ast::pat_box(_) { ret true; } _ { } }
}
ret false;
}
-type exit_node = rec(bind_map bound,
- BasicBlockRef from,
- BasicBlockRef to);
-type mk_fail = fn() -> BasicBlockRef;
+type exit_node = {bound: bind_map, from: BasicBlockRef, to: BasicBlockRef};
+type mk_fail = fn() -> BasicBlockRef ;
-fn compile_submatch(@block_ctxt bcx, &match m, ValueRef[] vals, &mk_fail f,
- &mutable exit_node[] exits) {
- if (ivec::len(m) == 0u) {
- bcx.build.Br(f());
- ret;
- }
- if (ivec::len(m.(0).pats) == 0u) {
- exits += ~[rec(bound=m.(0).bound,
- from=bcx.llbb,
- to=m.(0).body)];
+fn compile_submatch(bcx: @block_ctxt, m: &match, vals: ValueRef[],
+ f: &mk_fail, exits: &mutable exit_node[]) {
+ if ivec::len(m) == 0u { bcx.build.Br(f()); ret; }
+ if ivec::len(m.(0).pats) == 0u {
+ exits += ~[{bound: m.(0).bound, from: bcx.llbb, to: m.(0).body}];
bcx.build.Br(m.(0).body);
ret;
}
// FIXME maybe be clever about picking a column.
- auto col = 0u;
- auto val = vals.(col);
- auto vals_left = ivec::slice(vals, 1u, ivec::len(vals));
- auto ccx = bcx.fcx.lcx.ccx;
- auto pat_id = 0;
- for (match_branch br in m) {
+ let col = 0u;
+ let val = vals.(col);
+ let vals_left = ivec::slice(vals, 1u, ivec::len(vals));
+ let ccx = bcx.fcx.lcx.ccx;
+ let pat_id = 0;
+ for br: match_branch in m {
+
// Find a real id (we're adding placeholder wildcard patterns, but
// each column is guaranteed to have at least one real pattern)
- if (pat_id == 0) { pat_id = br.pats.(col).id; }
+ if pat_id == 0 { pat_id = br.pats.(col).id; }
}
- auto rec_fields = collect_record_fields(m, col);
+ let rec_fields = collect_record_fields(m, col);
// Separate path for extracting and binding record fields
- if (ivec::len(rec_fields) > 0u) {
- auto rec_ty = ty::node_id_to_monotype(ccx.tcx, pat_id);
- auto fields = alt (ty::struct(ccx.tcx, rec_ty)) {
- ty::ty_rec(?fields) { fields }
- };
- auto rec_vals = ~[];
- for (ast::ident field_name in rec_fields) {
- let uint ix = ty::field_idx(ccx.sess, rec(lo=0u, hi=0u),
- field_name, fields);
- auto r = trans::GEP_tup_like(bcx, rec_ty, val, ~[0, ix as int]);
+ if ivec::len(rec_fields) > 0u {
+ let rec_ty = ty::node_id_to_monotype(ccx.tcx, pat_id);
+ let fields =
+ alt ty::struct(ccx.tcx, rec_ty) { ty::ty_rec(fields) { fields } };
+ let rec_vals = ~[];
+ for field_name: ast::ident in rec_fields {
+ let ix: uint =
+ ty::field_idx(ccx.sess, {lo: 0u, hi: 0u}, field_name, fields);
+ let r = trans::GEP_tup_like(bcx, rec_ty, val, ~[0, ix as int]);
rec_vals += ~[r.val];
bcx = r.bcx;
}
@@ -288,171 +272,162 @@
}
// Unbox in case of a box field
- if (any_box_pat(m, col)) {
- auto box = bcx.build.Load(val);
- auto unboxed = bcx.build.InBoundsGEP
- (box, ~[C_int(0), C_int(back::abi::box_rc_field_body)]);
- compile_submatch(bcx, enter_box(m, col, val),
- ~[unboxed] + vals_left, f, exits);
+ if any_box_pat(m, col) {
+ let box = bcx.build.Load(val);
+ let unboxed =
+ bcx.build.InBoundsGEP(box,
+ ~[C_int(0),
+ C_int(back::abi::box_rc_field_body)]);
+ compile_submatch(bcx, enter_box(m, col, val), ~[unboxed] + vals_left,
+ f, exits);
ret;
}
// Decide what kind of branch we need
- auto opts = get_options(ccx, m, col);
+ let opts = get_options(ccx, m, col);
tag branch_kind { no_branch; single; switch; compare; }
- auto kind = no_branch;
- auto test_val = val;
- if (ivec::len(opts) > 0u) {
- alt (opts.(0)) {
- var(_, ?vdef) {
- if (ivec::len(ty::tag_variants(ccx.tcx, vdef.tg)) == 1u) {
- kind = single;
- } else {
- auto tagptr = bcx.build.PointerCast
- (val, trans_common::T_opaque_tag_ptr(ccx.tn));
- auto discrimptr = bcx.build.GEP
- (tagptr, ~[C_int(0), C_int(0)]);
- test_val = bcx.build.Load(discrimptr);
- kind = switch;
- }
+ let kind = no_branch;
+ let test_val = val;
+ if ivec::len(opts) > 0u {
+ alt opts.(0) {
+ var(_, vdef) {
+ if ivec::len(ty::tag_variants(ccx.tcx, vdef.tg)) == 1u {
+ kind = single;
+ } else {
+ let tagptr =
+ bcx.build.PointerCast(val,
+ trans_common::T_opaque_tag_ptr(ccx.tn));
+ let discrimptr = bcx.build.GEP(tagptr, ~[C_int(0), C_int(0)]);
+ test_val = bcx.build.Load(discrimptr);
+ kind = switch;
}
- lit(?l) {
- test_val = bcx.build.Load(val);
- kind = alt (l.node) {
- ast::lit_str(_, _) { compare }
- _ { switch }
- };
- }
+ }
+ lit(l) {
+ test_val = bcx.build.Load(val);
+ kind = alt l.node { ast::lit_str(_, _) { compare } _ { switch } };
+ }
}
}
- auto else_cx = alt (kind) {
- no_branch | single { bcx }
- _ { new_sub_block_ctxt(bcx, "match_else") }
- };
- auto sw = if (kind == switch) {
- bcx.build.Switch(test_val, else_cx.llbb, ivec::len(opts))
- } else { C_int(0) }; // Placeholder for when not using a switch
+ let else_cx =
+ alt kind {
+ no_branch. | single. { bcx }
+ _ { new_sub_block_ctxt(bcx, "match_else") }
+ };
+ let sw =
+ if kind == switch {
+ bcx.build.Switch(test_val, else_cx.llbb, ivec::len(opts))
+ } else { C_int(0) }; // Placeholder for when not using a switch
- // Compile subtrees for each option
- for (opt opt in opts) {
- auto opt_cx = new_sub_block_ctxt(bcx, "match_case");
- alt (kind) {
- single { bcx.build.Br(opt_cx.llbb); }
- switch {
- auto r = trans_opt(bcx, opt);
- bcx = r.bcx;
- llvm::LLVMAddCase(sw, r.val, opt_cx.llbb);
- }
- compare {
- auto r = trans_opt(bcx, opt);
- bcx = r.bcx;
- auto t = ty::node_id_to_type(ccx.tcx, pat_id);
- auto eq = trans::trans_compare(bcx, ast::eq, t, test_val,
- r.val);
- bcx = new_sub_block_ctxt(bcx, "next");
- eq.bcx.build.CondBr(eq.val, opt_cx.llbb, bcx.llbb);
- }
- _ {}
+ // Compile subtrees for each option
+ for opt: opt in opts {
+ let opt_cx = new_sub_block_ctxt(bcx, "match_case");
+ alt kind {
+ single. { bcx.build.Br(opt_cx.llbb); }
+ switch. {
+ let r = trans_opt(bcx, opt);
+ bcx = r.bcx;
+ llvm::LLVMAddCase(sw, r.val, opt_cx.llbb);
+ }
+ compare. {
+ let r = trans_opt(bcx, opt);
+ bcx = r.bcx;
+ let t = ty::node_id_to_type(ccx.tcx, pat_id);
+ let eq = trans::trans_compare(bcx, ast::eq, t, test_val, r.val);
+ bcx = new_sub_block_ctxt(bcx, "next");
+ eq.bcx.build.CondBr(eq.val, opt_cx.llbb, bcx.llbb);
+ }
+ _ { }
}
- auto size = 0u;
- auto unpacked = ~[];
+ let size = 0u;
+ let unpacked = ~[];
alt opt {
- var(_, ?vdef) {
- auto args = extract_variant_args(opt_cx, pat_id, vdef, val);
- size = ivec::len(args.vals);
- unpacked = args.vals;
- opt_cx = args.bcx;
- }
- lit(_) { }
+ var(_, vdef) {
+ let args = extract_variant_args(opt_cx, pat_id, vdef, val);
+ size = ivec::len(args.vals);
+ unpacked = args.vals;
+ opt_cx = args.bcx;
+ }
+ lit(_) { }
}
compile_submatch(opt_cx, enter_opt(ccx, m, opt, col, size, val),
unpacked + vals_left, f, exits);
}
// Compile the fall-through case
- if (kind == compare) { bcx.build.Br(else_cx.llbb); }
- if (kind != single) {
- compile_submatch(else_cx, enter_default(m, col, val), vals_left,
- f, exits);
+ if kind == compare { bcx.build.Br(else_cx.llbb); }
+ if kind != single {
+ compile_submatch(else_cx, enter_default(m, col, val), vals_left, f,
+ exits);
}
}
// Returns false for unreachable blocks
-fn make_phi_bindings(&@block_ctxt bcx, &exit_node[] map,
- &ast::pat_id_map ids) -> bool {
- fn assoc(str key, &bind_map list)
- -> option::t[ValueRef] {
- for (rec(ast::ident ident, ValueRef val) elt in list) {
- if (str::eq(elt.ident, key)) { ret some(elt.val); }
+fn make_phi_bindings(bcx: &@block_ctxt, map: &exit_node[],
+ ids: &ast::pat_id_map) -> bool {
+ fn assoc(key: str, list: &bind_map) -> option::t[ValueRef] {
+ for elt: {ident: ast::ident, val: ValueRef} in list {
+ if str::eq(elt.ident, key) { ret some(elt.val); }
}
ret none;
}
- auto our_block = bcx.llbb as uint;
- auto success = true;
- for each (@rec(ast::ident key, ast::node_id val) item
- in ids.items()) {
- auto llbbs = ~[];
- auto vals = ~[];
- for (exit_node ex in map) {
- if (ex.to as uint == our_block) {
- alt (assoc(item.key, ex.bound)) {
- some(?val) {
- llbbs += ~[ex.from];
- vals += ~[val];
- }
- none {}
+ let our_block = bcx.llbb as uint;
+ let success = true;
+ for each item: @{key: ast::ident, val: ast::node_id} in ids.items() {
+ let llbbs = ~[];
+ let vals = ~[];
+ for ex: exit_node in map {
+ if ex.to as uint == our_block {
+ alt assoc(item.key, ex.bound) {
+ some(val) { llbbs += ~[ex.from]; vals += ~[val]; }
+ none. { }
}
}
}
- if (ivec::len(vals) > 0u) {
- auto phi = bcx.build.Phi(val_ty(vals.(0)), vals, llbbs);
+ if ivec::len(vals) > 0u {
+ let phi = bcx.build.Phi(val_ty(vals.(0)), vals, llbbs);
bcx.fcx.lllocals.insert(item.val, phi);
} else { success = false; }
}
ret success;
}
-fn trans_alt(&@block_ctxt cx, &@ast::expr expr, &ast::arm[] arms,
- ast::node_id id, &trans::out_method output) -> result {
- auto bodies = ~[];
- let match match = ~[];
- for (ast::arm a in arms) {
- auto body = new_scope_block_ctxt(cx, "case_body");
+fn trans_alt(cx: &@block_ctxt, expr: &@ast::expr, arms: &ast::arm[],
+ id: ast::node_id, output: &trans::out_method) -> result {
+ let bodies = ~[];
+ let match: match = ~[];
+ for a: ast::arm in arms {
+ let body = new_scope_block_ctxt(cx, "case_body");
bodies += ~[body];
- for (@ast::pat p in a.pats) {
- match += ~[@rec(pats=~[p], body=body.llbb, mutable bound=~[])];
+ for p: @ast::pat in a.pats {
+ match += ~[@{pats: ~[p], body: body.llbb, mutable bound: ~[]}];
}
}
// Cached fail-on-fallthrough block
- auto fail_cx = @mutable none;
- fn mk_fail(&@block_ctxt cx, &span sp,
- @mutable option::t[BasicBlockRef] done) -> BasicBlockRef {
- alt (*done) {
- some(?bb) { ret bb; }
- _ {}
- }
- auto fail_cx = new_sub_block_ctxt(cx, "case_fallthrough");
+ let fail_cx = @mutable none;
+ fn mk_fail(cx: &@block_ctxt, sp: &span,
+ done: @mutable option::t[BasicBlockRef]) -> BasicBlockRef {
+ alt *done { some(bb) { ret bb; } _ { } }
+ let fail_cx = new_sub_block_ctxt(cx, "case_fallthrough");
trans::trans_fail(fail_cx, some(sp), "non-exhaustive match failure");
*done = some(fail_cx.llbb);
ret fail_cx.llbb;
}
- auto exit_map = ~[];
- auto er = trans::trans_expr(cx, expr);
- auto t = trans::node_id_type(cx.fcx.lcx.ccx, expr.id);
- auto v = trans::spill_if_immediate(er.bcx, er.val, t);
+ let exit_map = ~[];
+ let er = trans::trans_expr(cx, expr);
+ let t = trans::node_id_type(cx.fcx.lcx.ccx, expr.id);
+ let v = trans::spill_if_immediate(er.bcx, er.val, t);
compile_submatch(er.bcx, match, ~[v],
bind mk_fail(cx, expr.span, fail_cx), exit_map);
- auto i = 0u;
- auto arm_results = ~[];
- for (ast::arm a in arms) {
- auto body_cx = bodies.(i);
- if (make_phi_bindings(body_cx, exit_map,
- ast::pat_id_map(a.pats.(0)))) {
- auto block_res = trans::trans_block(body_cx, a.block, output);
+ let i = 0u;
+ let arm_results = ~[];
+ for a: ast::arm in arms {
+ let body_cx = bodies.(i);
+ if make_phi_bindings(body_cx, exit_map, ast::pat_id_map(a.pats.(0))) {
+ let block_res = trans::trans_block(body_cx, a.block, output);
arm_results += ~[block_res];
} else { // Unreachable
arm_results += ~[rslt(body_cx, C_nil())];
diff --git a/src/comp/middle/trans_comm.rs b/src/comp/middle/trans_comm.rs
index a52a2c6..17285b9 100644
--- a/src/comp/middle/trans_comm.rs
+++ b/src/comp/middle/trans_comm.rs
@@ -28,54 +28,53 @@
export trans_send;
export trans_recv;
-fn trans_port(&@block_ctxt cx, ast::node_id id) -> result {
- auto t = node_id_type(cx.fcx.lcx.ccx, id);
- auto unit_ty;
- alt (ty::struct(cx.fcx.lcx.ccx.tcx, t)) {
- case (ty::ty_port(?t)) { unit_ty = t; }
- case (_) { cx.fcx.lcx.ccx.sess.bug("non-port type in trans_port"); }
+fn trans_port(cx: &@block_ctxt, id: ast::node_id) -> result {
+ let t = node_id_type(cx.fcx.lcx.ccx, id);
+ let unit_ty;
+ alt ty::struct(cx.fcx.lcx.ccx.tcx, t) {
+ ty::ty_port(t) { unit_ty = t; }
+ _ { cx.fcx.lcx.ccx.sess.bug("non-port type in trans_port"); }
}
- auto bcx = cx;
- auto unit_sz = size_of(bcx, unit_ty);
+ let bcx = cx;
+ let unit_sz = size_of(bcx, unit_ty);
bcx = unit_sz.bcx;
- auto port_raw_val =
+ let port_raw_val =
bcx.build.Call(bcx.fcx.lcx.ccx.upcalls.new_port,
~[bcx.fcx.lltaskptr, unit_sz.val]);
- auto llty = type_of(cx.fcx.lcx.ccx, cx.sp, t);
- auto port_val = bcx.build.PointerCast(port_raw_val, llty);
+ let llty = type_of(cx.fcx.lcx.ccx, cx.sp, t);
+ let port_val = bcx.build.PointerCast(port_raw_val, llty);
add_clean_temp(bcx, port_val, t);
ret rslt(bcx, port_val);
}
-fn trans_chan(&@block_ctxt cx, &@ast::expr e, ast::node_id id) -> result {
- auto bcx = cx;
- auto prt = trans_expr(bcx, e);
+fn trans_chan(cx: &@block_ctxt, e: &@ast::expr, id: ast::node_id) -> result {
+ let bcx = cx;
+ let prt = trans_expr(bcx, e);
bcx = prt.bcx;
- auto prt_val = bcx.build.PointerCast(prt.val, T_opaque_port_ptr());
- auto chan_raw_val =
+ let prt_val = bcx.build.PointerCast(prt.val, T_opaque_port_ptr());
+ let chan_raw_val =
bcx.build.Call(bcx.fcx.lcx.ccx.upcalls.new_chan,
~[bcx.fcx.lltaskptr, prt_val]);
- auto chan_ty = node_id_type(bcx.fcx.lcx.ccx, id);
- auto chan_llty = type_of(bcx.fcx.lcx.ccx, e.span, chan_ty);
- auto chan_val = bcx.build.PointerCast(chan_raw_val, chan_llty);
+ let chan_ty = node_id_type(bcx.fcx.lcx.ccx, id);
+ let chan_llty = type_of(bcx.fcx.lcx.ccx, e.span, chan_ty);
+ let chan_val = bcx.build.PointerCast(chan_raw_val, chan_llty);
add_clean_temp(bcx, chan_val, chan_ty);
ret rslt(bcx, chan_val);
}
-fn trans_spawn(&@block_ctxt cx, &ast::spawn_dom dom, &option::t[str] name,
- &@ast::expr func, &(@ast::expr)[] args, ast::node_id id)
- -> result {
- auto bcx = cx;
+fn trans_spawn(cx: &@block_ctxt, dom: &ast::spawn_dom, name: &option::t[str],
+ func: &@ast::expr, args: &(@ast::expr)[], id: ast::node_id) ->
+ result {
+ let bcx = cx;
// Make the task name
- auto tname =
- alt (name) {
- case (none) {
- auto argss = std::ivec::map(expr_to_str, args);
- #fmt("%s(%s)", expr_to_str(func),
- str::connect_ivec(argss, ", "))
- }
- case (some(?n)) { n }
+ let tname =
+ alt name {
+ none. {
+ let argss = std::ivec::map(expr_to_str, args);
+ #fmt("%s(%s)", expr_to_str(func), str::connect_ivec(argss, ", "))
+ }
+ some(n) { n }
};
// Generate code
//
@@ -100,19 +99,19 @@
// But first, we'll create a task.
- let ValueRef lltname = C_str(bcx.fcx.lcx.ccx, tname);
- auto new_task =
+ let lltname: ValueRef = C_str(bcx.fcx.lcx.ccx, tname);
+ let new_task =
bcx.build.Call(bcx.fcx.lcx.ccx.upcalls.new_task,
~[bcx.fcx.lltaskptr, lltname]);
// Translate the arguments, remembering their types and where the values
// ended up.
- let ty::t[] arg_tys = ~[];
- let ValueRef[] arg_vals = ~[];
- for (@ast::expr e in args) {
- auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e);
- auto arg = trans_expr(bcx, e);
+ let arg_tys: ty::t[] = ~[];
+ let arg_vals: ValueRef[] = ~[];
+ for e: @ast::expr in args {
+ let e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e);
+ let arg = trans_expr(bcx, e);
arg = deep_copy(arg.bcx, arg.val, e_ty, new_task);
@@ -123,74 +122,74 @@
}
// Make the tuple.
- auto args_ty = ty::mk_imm_tup(cx.fcx.lcx.ccx.tcx, arg_tys);
+ let args_ty = ty::mk_imm_tup(cx.fcx.lcx.ccx.tcx, arg_tys);
// Allocate and fill the tuple.
- auto llargs = alloc_ty(bcx, args_ty);
- auto i = 0u;
- for (ValueRef v in arg_vals) {
- auto target = bcx.build.GEP(llargs.val, ~[C_int(0), C_int(i as int)]);
+ let llargs = alloc_ty(bcx, args_ty);
+ let i = 0u;
+ for v: ValueRef in arg_vals {
+ let target = bcx.build.GEP(llargs.val, ~[C_int(0), C_int(i as int)]);
bcx.build.Store(v, target);
i += 1u;
}
// Generate the wrapper function
- auto wrapper = mk_spawn_wrapper(bcx, func, args_ty);
+ let wrapper = mk_spawn_wrapper(bcx, func, args_ty);
bcx = wrapper.bcx;
- auto llfnptr_i = bcx.build.PointerCast(wrapper.val, T_int());
+ let llfnptr_i = bcx.build.PointerCast(wrapper.val, T_int());
// And start the task
- auto llargs_i = bcx.build.PointerCast(llargs.val, T_int());
- auto args_size = size_of(bcx, args_ty).val;
+ let llargs_i = bcx.build.PointerCast(llargs.val, T_int());
+ let args_size = size_of(bcx, args_ty).val;
bcx.build.Call(bcx.fcx.lcx.ccx.upcalls.start_task,
~[bcx.fcx.lltaskptr, new_task, llfnptr_i, llargs_i,
args_size]);
- auto task_ty = node_id_type(bcx.fcx.lcx.ccx, id);
+ let task_ty = node_id_type(bcx.fcx.lcx.ccx, id);
add_clean_temp(bcx, new_task, task_ty);
ret rslt(bcx, new_task);
}
-fn mk_spawn_wrapper(&@block_ctxt cx, &@ast::expr func, &ty::t args_ty) ->
+fn mk_spawn_wrapper(cx: &@block_ctxt, func: &@ast::expr, args_ty: &ty::t) ->
result {
- auto llmod = cx.fcx.lcx.ccx.llmod;
- auto wrapper_fn_type =
+ let llmod = cx.fcx.lcx.ccx.llmod;
+ let wrapper_fn_type =
type_of_fn(cx.fcx.lcx.ccx, cx.sp, ast::proto_fn,
- ~[rec(mode=ty::mo_alias(false), ty=args_ty)], ty::idx_nil,
+ ~[{mode: ty::mo_alias(false), ty: args_ty}], ty::idx_nil,
0u);
// TODO: construct a name based on tname
- let str wrap_name =
+ let wrap_name: str =
mangle_internal_name_by_path_and_seq(cx.fcx.lcx.ccx, cx.fcx.lcx.path,
"spawn_wrapper");
- auto llfndecl = decl_cdecl_fn(llmod, wrap_name, wrapper_fn_type);
- auto fcx = new_fn_ctxt(cx.fcx.lcx, cx.sp, llfndecl);
- auto fbcx = new_top_block_ctxt(fcx);
+ let llfndecl = decl_cdecl_fn(llmod, wrap_name, wrapper_fn_type);
+ let fcx = new_fn_ctxt(cx.fcx.lcx, cx.sp, llfndecl);
+ let fbcx = new_top_block_ctxt(fcx);
// 3u to skip the three implicit args
- let ValueRef arg = llvm::LLVMGetParam(fcx.llfn, 3u);
- let ValueRef[] child_args =
+ let arg: ValueRef = llvm::LLVMGetParam(fcx.llfn, 3u);
+ let child_args: ValueRef[] =
~[llvm::LLVMGetParam(fcx.llfn, 0u), llvm::LLVMGetParam(fcx.llfn, 1u),
llvm::LLVMGetParam(fcx.llfn, 2u)];
// unpack the arguments
- alt (ty::struct(fcx.lcx.ccx.tcx, args_ty)) {
- case (ty::ty_rec(?fields)) {
- auto i = 0;
- for (ty::field f in fields) {
- auto src = fbcx.build.GEP(arg, ~[C_int(0), C_int(i)]);
- i += 1;
- auto child_arg = fbcx.build.Load(src);
- child_args += ~[child_arg];
- }
+ alt ty::struct(fcx.lcx.ccx.tcx, args_ty) {
+ ty::ty_rec(fields) {
+ let i = 0;
+ for f: ty::field in fields {
+ let src = fbcx.build.GEP(arg, ~[C_int(0), C_int(i)]);
+ i += 1;
+ let child_arg = fbcx.build.Load(src);
+ child_args += ~[child_arg];
}
+ }
}
// Find the function
- auto fnptr = trans_lval(fbcx, func).res;
+ let fnptr = trans_lval(fbcx, func).res;
fbcx = fnptr.bcx;
- auto llfnptr = fbcx.build.GEP(fnptr.val, ~[C_int(0), C_int(0)]);
- auto llfn = fbcx.build.Load(llfnptr);
+ let llfnptr = fbcx.build.GEP(fnptr.val, ~[C_int(0), C_int(0)]);
+ let llfn = fbcx.build.Load(llfnptr);
fbcx.build.FastCall(llfn, child_args);
fbcx.build.RetVoid();
finish_fn(fcx, fbcx.llbb);
@@ -199,25 +198,24 @@
ret rslt(cx, llfndecl);
}
-fn trans_send(&@block_ctxt cx, &@ast::expr lhs, &@ast::expr rhs,
- ast::node_id id) -> result {
- auto bcx = cx;
- auto chn = trans_expr(bcx, lhs);
+fn trans_send(cx: &@block_ctxt, lhs: &@ast::expr, rhs: &@ast::expr,
+ id: ast::node_id) -> result {
+ let bcx = cx;
+ let chn = trans_expr(bcx, lhs);
bcx = chn.bcx;
- auto data = trans_lval(bcx, rhs);
+ let data = trans_lval(bcx, rhs);
bcx = data.res.bcx;
- auto chan_ty = node_id_type(cx.fcx.lcx.ccx, id);
- alt (ty::struct(cx.fcx.lcx.ccx.tcx, chan_ty)) {
- case (ty::ty_chan(?t)) { unit_ty = t; }
- case (_) { bcx.fcx.lcx.ccx.sess.bug("non-chan type in trans_send"); }
+ let chan_ty = node_id_type(cx.fcx.lcx.ccx, id);
+ alt ty::struct(cx.fcx.lcx.ccx.tcx, chan_ty) {
+ ty::ty_chan(t) { unit_ty = t; }
+ _ { bcx.fcx.lcx.ccx.sess.bug("non-chan type in trans_send"); }
}
- auto data_alloc = alloc_ty(bcx, unit_ty);
+ let data_alloc = alloc_ty(bcx, unit_ty);
bcx = data_alloc.bcx;
- auto data_tmp = move_val_if_temp(bcx, INIT, data_alloc.val,
- data, unit_ty);
+ let data_tmp = move_val_if_temp(bcx, INIT, data_alloc.val, data, unit_ty);
bcx = data_tmp.bcx;
- auto llchanval = bcx.build.PointerCast(chn.val, T_opaque_chan_ptr());
- auto lldataptr = bcx.build.PointerCast(data_alloc.val, T_ptr(T_i8()));
+ let llchanval = bcx.build.PointerCast(chn.val, T_opaque_chan_ptr());
+ let lldataptr = bcx.build.PointerCast(data_alloc.val, T_ptr(T_i8()));
bcx.build.Call(bcx.fcx.lcx.ccx.upcalls.send,
~[bcx.fcx.lltaskptr, llchanval, lldataptr]);
@@ -225,22 +223,21 @@
bcx = zero_alloca(bcx, data_alloc.val, unit_ty).bcx;
ret rslt(bcx, chn.val);
- auto unit_ty;
+ let unit_ty;
}
-fn trans_recv(&@block_ctxt cx, &@ast::expr lhs, &@ast::expr rhs,
- ast::node_id id) -> result {
- auto bcx = cx;
- auto data = trans_lval(bcx, rhs);
+fn trans_recv(cx: &@block_ctxt, lhs: &@ast::expr, rhs: &@ast::expr,
+ id: ast::node_id) -> result {
+ let bcx = cx;
+ let data = trans_lval(bcx, rhs);
assert (data.is_mem);
bcx = data.res.bcx;
// FIXME: calculate copy init-ness in typestate.
- auto prt = trans_expr(bcx, lhs);
+ let prt = trans_expr(bcx, lhs);
bcx = prt.bcx;
- auto lldataptr = bcx.build.PointerCast(data.res.val,
- T_ptr(T_ptr(T_i8())));
- auto llportptr = bcx.build.PointerCast(prt.val, T_opaque_port_ptr());
+ let lldataptr = bcx.build.PointerCast(data.res.val, T_ptr(T_ptr(T_i8())));
+ let llportptr = bcx.build.PointerCast(prt.val, T_opaque_port_ptr());
bcx.build.Call(bcx.fcx.lcx.ccx.upcalls.recv,
~[bcx.fcx.lltaskptr, lldataptr, llportptr]);
@@ -251,48 +248,42 @@
// tasks, and for sending things through channels. There are probably some
// uniqueness optimizations and things we can do here for tasks in the same
// domain.
-fn deep_copy(&@block_ctxt bcx, ValueRef v, ty::t t, ValueRef target_task)
- -> result
-{
+fn deep_copy(bcx: &@block_ctxt, v: ValueRef, t: ty::t, target_task: ValueRef)
+ -> result {
// TODO: make sure all paths add any reference counting that they need to.
// TODO: Teach deep copy to understand everything else it needs to.
- auto tcx = bcx.fcx.lcx.ccx.tcx;
- if(ty::type_is_scalar(tcx, t)) {
+ let tcx = bcx.fcx.lcx.ccx.tcx;
+ if ty::type_is_scalar(tcx, t) {
ret rslt(bcx, v);
- }
- else if(ty::type_is_str(tcx, t)) {
+ } else if (ty::type_is_str(tcx, t)) {
ret rslt(bcx,
- bcx.build.Call(bcx.fcx.lcx.ccx.upcalls.dup_str,
- ~[bcx.fcx.lltaskptr, target_task, v]));
- }
- else if(ty::type_is_chan(tcx, t)) {
+ bcx.build.Call(bcx.fcx.lcx.ccx.upcalls.dup_str,
+ ~[bcx.fcx.lltaskptr, target_task, v]));
+ } else if (ty::type_is_chan(tcx, t)) {
// If this is a channel, we need to clone it.
- auto chan_ptr = bcx.build.PointerCast(v, T_opaque_chan_ptr());
+ let chan_ptr = bcx.build.PointerCast(v, T_opaque_chan_ptr());
- auto chan_raw_val =
+ let chan_raw_val =
bcx.build.Call(bcx.fcx.lcx.ccx.upcalls.clone_chan,
~[bcx.fcx.lltaskptr, target_task, chan_ptr]);
// Cast back to the type the context was expecting.
- auto chan_val = bcx.build.PointerCast(chan_raw_val,
- val_ty(v));
+ let chan_val = bcx.build.PointerCast(chan_raw_val, val_ty(v));
ret rslt(bcx, chan_val);
- }
- else if(ty::type_is_structural(tcx, t)) {
- fn inner_deep_copy(&@block_ctxt bcx, ValueRef v, ty::t t) -> result {
+ } else if (ty::type_is_structural(tcx, t)) {
+ fn inner_deep_copy(bcx: &@block_ctxt, v: ValueRef, t: ty::t) ->
+ result {
log_err "Unimplemented type for deep_copy.";
fail;
}
ret iter_structural_ty(bcx, v, t, inner_deep_copy);
- }
- else {
- bcx.fcx.lcx.ccx.sess.bug("unexpected type in " +
- "trans::deep_copy: " +
- ty_to_str(tcx, t));
+ } else {
+ bcx.fcx.lcx.ccx.sess.bug("unexpected type in " + "trans::deep_copy: "
+ + ty_to_str(tcx, t));
}
}
diff --git a/src/comp/middle/trans_common.rs b/src/comp/middle/trans_common.rs
index 5df95fd..7f63923 100644
--- a/src/comp/middle/trans_common.rs
+++ b/src/comp/middle/trans_common.rs
@@ -61,24 +61,24 @@
import trans::drop_slot;
import trans::drop_ty;
-obj namegen(mutable int i) {
- fn next(str prefix) -> str { i += 1; ret prefix + int::str(i); }
+obj namegen(mutable i: int) {
+ fn next(prefix: str) -> str { i += 1; ret prefix + int::str(i); }
}
-type derived_tydesc_info = rec(ValueRef lltydesc, bool escapes);
+type derived_tydesc_info = {lltydesc: ValueRef, escapes: bool};
-type glue_fns = rec(ValueRef no_op_type_glue);
+type glue_fns = {no_op_type_glue: ValueRef};
type tydesc_info =
- rec(ty::t ty,
- ValueRef tydesc,
- ValueRef size,
- ValueRef align,
- mutable option::t[ValueRef] copy_glue,
- mutable option::t[ValueRef] drop_glue,
- mutable option::t[ValueRef] free_glue,
- mutable option::t[ValueRef] cmp_glue,
- uint[] ty_params);
+ {ty: ty::t,
+ tydesc: ValueRef,
+ size: ValueRef,
+ align: ValueRef,
+ mutable copy_glue: option::t[ValueRef],
+ mutable drop_glue: option::t[ValueRef],
+ mutable free_glue: option::t[ValueRef],
+ mutable cmp_glue: option::t[ValueRef],
+ ty_params: uint[]};
/*
* A note on nomenclature of linking: "upcall", "extern" and "native".
@@ -96,224 +96,227 @@
*
*/
type stats =
- rec(mutable uint n_static_tydescs,
- mutable uint n_derived_tydescs,
- mutable uint n_glues_created,
- mutable uint n_null_glues,
- mutable uint n_real_glues,
- @mutable (rec(str ident, int time)[]) fn_times);
+ {mutable n_static_tydescs: uint,
+ mutable n_derived_tydescs: uint,
+ mutable n_glues_created: uint,
+ mutable n_null_glues: uint,
+ mutable n_real_glues: uint,
+ fn_times: @mutable {ident: str, time: int}[]};
// Crate context. Every crate we compile has one of these.
type crate_ctxt =
- rec(session::session sess,
- ModuleRef llmod,
- target_data td,
- type_names tn,
- hashmap[str, ValueRef] externs,
- hashmap[str, ValueRef] intrinsics,
- // A mapping from the def_id of each item in this crate to the address
- // of the first instruction of the item's definition in the executable
- // we're generating.
- hashmap[ast::node_id, ValueRef] item_ids,
- ast_map::map ast_map,
- hashmap[ast::node_id, str] item_symbols,
- mutable option::t[ValueRef] main_fn,
- link::link_meta link_meta,
+ // A mapping from the def_id of each item in this crate to the address
+ // of the first instruction of the item's definition in the executable
+ // we're generating.
- // TODO: hashmap[tup(tag_id,subtys), @tag_info]
- hashmap[ty::t, uint] tag_sizes,
- hashmap[ast::node_id, ValueRef] discrims,
- hashmap[ast::node_id, str] discrim_symbols,
- hashmap[ast::node_id, ValueRef] fn_pairs,
- hashmap[ast::node_id, ValueRef] consts,
- hashmap[ast::node_id, ()] obj_methods,
- hashmap[ty::t, @tydesc_info] tydescs,
- hashmap[str, ValueRef] module_data,
- hashmap[ty::t, TypeRef] lltypes,
- @glue_fns glues,
- namegen names,
- std::sha1::sha1 sha,
- hashmap[ty::t, str] type_sha1s,
- hashmap[ty::t, str] type_short_names,
- ty::ctxt tcx,
- stats stats,
- @upcall::upcalls upcalls,
- TypeRef rust_object_type,
- TypeRef tydesc_type,
- TypeRef task_type);
+ // TODO: hashmap[tup(tag_id,subtys), @tag_info]
+ {sess: session::session,
+ llmod: ModuleRef,
+ td: target_data,
+ tn: type_names,
+ externs: hashmap[str, ValueRef],
+ intrinsics: hashmap[str, ValueRef],
+ item_ids: hashmap[ast::node_id, ValueRef],
+ ast_map: ast_map::map,
+ item_symbols: hashmap[ast::node_id, str],
+ mutable main_fn: option::t[ValueRef],
+ link_meta: link::link_meta,
+ tag_sizes: hashmap[ty::t, uint],
+ discrims: hashmap[ast::node_id, ValueRef],
+ discrim_symbols: hashmap[ast::node_id, str],
+ fn_pairs: hashmap[ast::node_id, ValueRef],
+ consts: hashmap[ast::node_id, ValueRef],
+ obj_methods: hashmap[ast::node_id, ()],
+ tydescs: hashmap[ty::t, @tydesc_info],
+ module_data: hashmap[str, ValueRef],
+ lltypes: hashmap[ty::t, TypeRef],
+ glues: @glue_fns,
+ names: namegen,
+ sha: std::sha1::sha1,
+ type_sha1s: hashmap[ty::t, str],
+ type_short_names: hashmap[ty::t, str],
+ tcx: ty::ctxt,
+ stats: stats,
+ upcalls: @upcall::upcalls,
+ rust_object_type: TypeRef,
+ tydesc_type: TypeRef,
+ task_type: TypeRef};
type local_ctxt =
- rec(str[] path,
- str[] module_path,
- ast::ty_param[] obj_typarams,
- ast::obj_field[] obj_fields,
- @crate_ctxt ccx);
+ {path: str[],
+ module_path: str[],
+ obj_typarams: ast::ty_param[],
+ obj_fields: ast::obj_field[],
+ ccx: @crate_ctxt};
// Types used for llself.
-type val_self_pair = rec(ValueRef v, ty::t t);
+type val_self_pair = {v: ValueRef, t: ty::t};
// Function context. Every LLVM function we create will have one of these.
type fn_ctxt =
- rec(
- // The ValueRef returned from a call to llvm::LLVMAddFunction; the
- // address of the first instruction in the sequence of instructions
- // for this function that will go in the .text section of the
- // executable we're generating.
- ValueRef llfn,
+ // The ValueRef returned from a call to llvm::LLVMAddFunction; the
+ // address of the first instruction in the sequence of instructions
+ // for this function that will go in the .text section of the
+ // executable we're generating.
- // The three implicit arguments that arrive in the function we're
- // creating. For instance, foo(int, int) is really foo(ret*, task*,
- // env*, int, int). These are also available via
- // llvm::LLVMGetParam(llfn, uint) where uint = 1, 2, 0 respectively,
- // but we unpack them into these fields for convenience.
+ // The three implicit arguments that arrive in the function we're
+ // creating. For instance, foo(int, int) is really foo(ret*, task*,
+ // env*, int, int). These are also available via
+ // llvm::LLVMGetParam(llfn, uint) where uint = 1, 2, 0 respectively,
+ // but we unpack them into these fields for convenience.
- // Points to the current task.
- ValueRef lltaskptr,
+ // Points to the current task.
- // Points to the current environment (bindings of variables to
- // values), if this is a regular function; points to the current
- // object, if this is a method.
- ValueRef llenv,
+ // Points to the current environment (bindings of variables to
+ // values), if this is a regular function; points to the current
+ // object, if this is a method.
- // Points to where the return value of this function should end up.
- ValueRef llretptr,
+ // Points to where the return value of this function should end up.
- // The next three elements: "hoisted basic blocks" containing
- // administrative activities that have to happen in only one place in
- // the function, due to LLVM's quirks.
+ // The next three elements: "hoisted basic blocks" containing
+ // administrative activities that have to happen in only one place in
+ // the function, due to LLVM's quirks.
- // A block for all the function's static allocas, so that LLVM will
- // coalesce them into a single alloca call.
- mutable BasicBlockRef llstaticallocas,
+ // A block for all the function's static allocas, so that LLVM will
+ // coalesce them into a single alloca call.
- // A block containing code that copies incoming arguments to space
- // already allocated by code in one of the llallocas blocks. (LLVM
- // requires that arguments be copied to local allocas before allowing
- // most any operation to be performed on them.)
- mutable BasicBlockRef llcopyargs,
+ // A block containing code that copies incoming arguments to space
+ // already allocated by code in one of the llallocas blocks. (LLVM
+ // requires that arguments be copied to local allocas before allowing
+ // most any operation to be performed on them.)
- // The first block containing derived tydescs received from the
- // runtime. See description of derived_tydescs, below.
- mutable BasicBlockRef llderivedtydescs_first,
+ // The first block containing derived tydescs received from the
+ // runtime. See description of derived_tydescs, below.
- // The last block of the llderivedtydescs group.
- mutable BasicBlockRef llderivedtydescs,
+ // The last block of the llderivedtydescs group.
- // A block for all of the dynamically sized allocas. This must be
- // after llderivedtydescs, because these sometimes depend on
- // information computed from derived tydescs.
- mutable BasicBlockRef lldynamicallocas,
+ // A block for all of the dynamically sized allocas. This must be
+ // after llderivedtydescs, because these sometimes depend on
+ // information computed from derived tydescs.
- // FIXME: Is llcopyargs actually the block containing the allocas for
- // incoming function arguments? Or is it merely the block containing
- // code that copies incoming args to space already alloca'd by code in
- // llallocas?
+ // FIXME: Is llcopyargs actually the block containing the allocas for
+ // incoming function arguments? Or is it merely the block containing
+ // code that copies incoming args to space already alloca'd by code in
+ // llallocas?
- // The 'self' object currently in use in this function, if there is
- // one.
- mutable option::t[val_self_pair] llself,
+ // The 'self' object currently in use in this function, if there is
+ // one.
- // If this function is actually a iter, a block containing the code
- // called whenever the iter calls 'put'.
- mutable option::t[ValueRef] lliterbody,
+ // If this function is actually a iter, a block containing the code
+ // called whenever the iter calls 'put'.
- // The next four items: hash tables mapping from AST def_ids to
- // LLVM-stuff-in-the-frame.
+ // The next four items: hash tables mapping from AST def_ids to
+ // LLVM-stuff-in-the-frame.
- // Maps arguments to allocas created for them in llallocas.
- hashmap[ast::node_id, ValueRef] llargs,
+ // Maps arguments to allocas created for them in llallocas.
- // Maps fields in objects to pointers into the interior of llself's
- // body.
- hashmap[ast::node_id, ValueRef] llobjfields,
+ // Maps fields in objects to pointers into the interior of llself's
+ // body.
- // Maps the def_ids for local variables to the allocas created for
- // them in llallocas.
- hashmap[ast::node_id, ValueRef] lllocals,
+ // Maps the def_ids for local variables to the allocas created for
+ // them in llallocas.
- // The same as above, but for variables accessed via the frame pointer
- // we pass into an iter, for access to the static environment of the
- // iter-calling frame.
- hashmap[ast::node_id, ValueRef] llupvars,
+ // The same as above, but for variables accessed via the frame pointer
+ // we pass into an iter, for access to the static environment of the
+ // iter-calling frame.
- // For convenience, a vector of the incoming tydescs for each of this
- // functions type parameters, fetched via llvm::LLVMGetParam. For
- // example, for a function foo[A, B, C](), lltydescs contains the
- // ValueRefs for the tydescs for A, B, and C.
- mutable ValueRef[] lltydescs,
+ // For convenience, a vector of the incoming tydescs for each of this
+ // functions type parameters, fetched via llvm::LLVMGetParam. For
+ // example, for a function foo[A, B, C](), lltydescs contains the
+ // ValueRefs for the tydescs for A, B, and C.
- // Derived tydescs are tydescs created at runtime, for types that
- // involve type parameters inside type constructors. For example,
- // suppose a function parameterized by T creates a vector of type
- // [T]. The function doesn't know what T is until runtime, and the
- // function's caller knows T but doesn't know that a vector is
- // involved. So a tydesc for [T] can't be created until runtime,
- // when information about both "[T]" and "T" are available. When such
- // a tydesc is created, we cache it in the derived_tydescs table for
- // the next time that such a tydesc is needed.
- hashmap[ty::t, derived_tydesc_info] derived_tydescs,
+ // Derived tydescs are tydescs created at runtime, for types that
+ // involve type parameters inside type constructors. For example,
+ // suppose a function parameterized by T creates a vector of type
+ // [T]. The function doesn't know what T is until runtime, and the
+ // function's caller knows T but doesn't know that a vector is
+ // involved. So a tydesc for [T] can't be created until runtime,
+ // when information about both "[T]" and "T" are available. When such
+ // a tydesc is created, we cache it in the derived_tydescs table for
+ // the next time that such a tydesc is needed.
- // The source span where this function comes from, for error
- // reporting.
- span sp,
+ // The source span where this function comes from, for error
+ // reporting.
- // This function's enclosing local context.
- @local_ctxt lcx);
+ // This function's enclosing local context.
+ {llfn: ValueRef,
+ lltaskptr: ValueRef,
+ llenv: ValueRef,
+ llretptr: ValueRef,
+ mutable llstaticallocas: BasicBlockRef,
+ mutable llcopyargs: BasicBlockRef,
+ mutable llderivedtydescs_first: BasicBlockRef,
+ mutable llderivedtydescs: BasicBlockRef,
+ mutable lldynamicallocas: BasicBlockRef,
+ mutable llself: option::t[val_self_pair],
+ mutable lliterbody: option::t[ValueRef],
+ llargs: hashmap[ast::node_id, ValueRef],
+ llobjfields: hashmap[ast::node_id, ValueRef],
+ lllocals: hashmap[ast::node_id, ValueRef],
+ llupvars: hashmap[ast::node_id, ValueRef],
+ mutable lltydescs: ValueRef[],
+ derived_tydescs: hashmap[ty::t, derived_tydesc_info],
+ sp: span,
+ lcx: @local_ctxt};
tag cleanup {
- clean(fn(&@block_ctxt) -> result);
- clean_temp(ValueRef, fn(&@block_ctxt) -> result);
+ clean(fn(&@block_ctxt) -> result );
+ clean_temp(ValueRef, fn(&@block_ctxt) -> result );
}
-fn add_clean(&@block_ctxt cx, ValueRef val, ty::t ty) {
+fn add_clean(cx: &@block_ctxt, val: ValueRef, ty: ty::t) {
find_scope_cx(cx).cleanups += ~[clean(bind drop_slot(_, val, ty))];
}
-fn add_clean_temp(&@block_ctxt cx, ValueRef val, ty::t ty) {
- find_scope_cx(cx).cleanups += ~[clean_temp(val,
- bind drop_ty(_, val, ty))];
+fn add_clean_temp(cx: &@block_ctxt, val: ValueRef, ty: ty::t) {
+ find_scope_cx(cx).cleanups +=
+ ~[clean_temp(val, bind drop_ty(_, val, ty))];
}
// Note that this only works for temporaries. We should, at some point, move
// to a system where we can also cancel the cleanup on local variables, but
// this will be more involved. For now, we simply zero out the local, and the
// drop glue checks whether it is zero.
-fn revoke_clean(&@block_ctxt cx, ValueRef val) {
- auto sc_cx = find_scope_cx(cx);
- auto found = -1;
- auto i = 0;
- for (cleanup c in sc_cx.cleanups) {
- alt (c) {
- case (clean_temp(?v, _)) {
- if (v as uint == val as uint) { found = i; break; }
- }
- case (_) {}
+fn revoke_clean(cx: &@block_ctxt, val: ValueRef) {
+ let sc_cx = find_scope_cx(cx);
+ let found = -1;
+ let i = 0;
+ for c: cleanup in sc_cx.cleanups {
+ alt c {
+ clean_temp(v, _) {
+ if v as uint == val as uint { found = i; break; }
+ }
+ _ { }
}
i += 1;
}
// The value does not have a cleanup associated with it. Might be a
// constant or some immediate value.
- if (found == -1) { ret; }
+ if found == -1 { ret; }
// We found the cleanup and remove it
- sc_cx.cleanups = std::ivec::slice(sc_cx.cleanups, 0u, found as uint) +
- std::ivec::slice(sc_cx.cleanups, found as uint + 1u,
- std::ivec::len(sc_cx.cleanups));
+ sc_cx.cleanups =
+ std::ivec::slice(sc_cx.cleanups, 0u, found as uint) +
+ std::ivec::slice(sc_cx.cleanups, (found as uint) + 1u,
+ std::ivec::len(sc_cx.cleanups));
}
tag block_kind {
+
// A scope block is a basic block created by translating a block { ... }
// the the source language. Since these blocks create variable scope, any
// variables created in them that are still live at the end of the block
// must be dropped and cleaned up when the block ends.
SCOPE_BLOCK;
+
// A basic block created from the body of a loop. Contains pointers to
// which block to jump to in the case of "continue" or "break", with the
// "continue" block optional, because "while" and "do while" don't support
// "continue" (TODO: is this intentional?)
LOOP_SCOPE_BLOCK(option::t[@block_ctxt], @block_ctxt);
+
// A non-scope block is a basic block created as a translation artifact
// from translating code that expresses conditional logic rather than by
// explicit { ... } block structure in the source language. It's called a
@@ -328,87 +331,86 @@
// with many basic blocks per function. All the basic blocks attached to a
// function are organized as a directed graph.
type block_ctxt =
- rec(
- // The BasicBlockRef returned from a call to
- // llvm::LLVMAppendBasicBlock(llfn, name), which adds a basic block to
- // the function pointed to by llfn. We insert instructions into that
- // block by way of this block context.
- BasicBlockRef llbb,
+ // The BasicBlockRef returned from a call to
+ // llvm::LLVMAppendBasicBlock(llfn, name), which adds a basic block to
+ // the function pointed to by llfn. We insert instructions into that
+ // block by way of this block context.
- // The llvm::builder object serving as an interface to LLVM's
- // LLVMBuild* functions.
- builder build,
+ // The llvm::builder object serving as an interface to LLVM's
+ // LLVMBuild* functions.
- // The block pointing to this one in the function's digraph.
- block_parent parent,
+ // The block pointing to this one in the function's digraph.
- // The 'kind' of basic block this is.
- block_kind kind,
+ // The 'kind' of basic block this is.
- // A list of functions that run at the end of translating this block,
- // cleaning up any variables that were introduced in the block and
- // need to go out of scope at the end of it.
- mutable cleanup[] cleanups,
+ // A list of functions that run at the end of translating this block,
+ // cleaning up any variables that were introduced in the block and
+ // need to go out of scope at the end of it.
- // The source span where this block comes from, for error reporting.
- span sp,
+ // The source span where this block comes from, for error reporting.
- // The function context for the function to which this block is
- // attached.
- @fn_ctxt fcx);
+ // The function context for the function to which this block is
+ // attached.
+ {llbb: BasicBlockRef,
+ build: builder,
+ parent: block_parent,
+ kind: block_kind,
+ mutable cleanups: cleanup[],
+ sp: span,
+ fcx: @fn_ctxt};
// FIXME: we should be able to use option::t[@block_parent] here but
// the infinite-tag check in rustboot gets upset.
tag block_parent { parent_none; parent_some(@block_ctxt); }
-type result = rec(@block_ctxt bcx, ValueRef val);
-type result_t = rec(@block_ctxt bcx, ValueRef val, ty::t ty);
+type result = {bcx: @block_ctxt, val: ValueRef};
+type result_t = {bcx: @block_ctxt, val: ValueRef, ty: ty::t};
-fn extend_path(@local_ctxt cx, &str name) -> @local_ctxt {
- ret @rec(path=cx.path + ~[name] with *cx);
+fn extend_path(cx: @local_ctxt, name: &str) -> @local_ctxt {
+ ret @{path: cx.path + ~[name] with *cx};
}
-fn rslt(@block_ctxt bcx, ValueRef val) -> result {
- ret rec(bcx=bcx, val=val);
+fn rslt(bcx: @block_ctxt, val: ValueRef) -> result {
+ ret {bcx: bcx, val: val};
}
-fn ty_str(type_names tn, TypeRef t) -> str {
+fn ty_str(tn: type_names, t: TypeRef) -> str {
ret lib::llvm::type_to_str(tn, t);
}
-fn val_ty(ValueRef v) -> TypeRef { ret llvm::LLVMTypeOf(v); }
+fn val_ty(v: ValueRef) -> TypeRef { ret llvm::LLVMTypeOf(v); }
-fn val_str(type_names tn, ValueRef v) -> str { ret ty_str(tn, val_ty(v)); }
+fn val_str(tn: type_names, v: ValueRef) -> str { ret ty_str(tn, val_ty(v)); }
// Returns the nth element of the given LLVM structure type.
-fn struct_elt(TypeRef llstructty, uint n) -> TypeRef {
- auto elt_count = llvm::LLVMCountStructElementTypes(llstructty);
+fn struct_elt(llstructty: TypeRef, n: uint) -> TypeRef {
+ let elt_count = llvm::LLVMCountStructElementTypes(llstructty);
assert (n < elt_count);
- auto elt_tys = std::ivec::init_elt(T_nil(), elt_count);
+ let elt_tys = std::ivec::init_elt(T_nil(), elt_count);
llvm::LLVMGetStructElementTypes(llstructty, std::ivec::to_ptr(elt_tys));
ret llvm::LLVMGetElementType(elt_tys.(n));
}
-fn find_scope_cx(&@block_ctxt cx) -> @block_ctxt {
- if (cx.kind != NON_SCOPE_BLOCK) { ret cx; }
- alt (cx.parent) {
- case (parent_some(?b)) { ret find_scope_cx(b); }
- case (parent_none) {
- cx.fcx.lcx.ccx.sess.bug("trans::find_scope_cx() " +
- "called on parentless block_ctxt");
- }
+fn find_scope_cx(cx: &@block_ctxt) -> @block_ctxt {
+ if cx.kind != NON_SCOPE_BLOCK { ret cx; }
+ alt cx.parent {
+ parent_some(b) { ret find_scope_cx(b); }
+ parent_none. {
+ cx.fcx.lcx.ccx.sess.bug("trans::find_scope_cx() " +
+ "called on parentless block_ctxt");
+ }
}
}
// Accessors
// TODO: When we have overloading, simplify these names!
-fn bcx_tcx(&@block_ctxt bcx) -> ty::ctxt { ret bcx.fcx.lcx.ccx.tcx; }
-fn bcx_ccx(&@block_ctxt bcx) -> @crate_ctxt { ret bcx.fcx.lcx.ccx; }
-fn bcx_lcx(&@block_ctxt bcx) -> @local_ctxt { ret bcx.fcx.lcx; }
-fn bcx_fcx(&@block_ctxt bcx) -> @fn_ctxt { ret bcx.fcx; }
-fn lcx_ccx(&@local_ctxt lcx) -> @crate_ctxt { ret lcx.ccx; }
-fn ccx_tcx(&@crate_ctxt ccx) -> ty::ctxt { ret ccx.tcx; }
+fn bcx_tcx(bcx: &@block_ctxt) -> ty::ctxt { ret bcx.fcx.lcx.ccx.tcx; }
+fn bcx_ccx(bcx: &@block_ctxt) -> @crate_ctxt { ret bcx.fcx.lcx.ccx; }
+fn bcx_lcx(bcx: &@block_ctxt) -> @local_ctxt { ret bcx.fcx.lcx; }
+fn bcx_fcx(bcx: &@block_ctxt) -> @fn_ctxt { ret bcx.fcx; }
+fn lcx_ccx(lcx: &@local_ctxt) -> @crate_ctxt { ret lcx.ccx; }
+fn ccx_tcx(ccx: &@crate_ctxt) -> ty::ctxt { ret ccx.tcx; }
// LLVM type constructors.
fn T_void() -> TypeRef {
@@ -467,28 +469,28 @@
ret T_i32();
}
-fn T_fn(&TypeRef[] inputs, TypeRef output) -> TypeRef {
+fn T_fn(inputs: &TypeRef[], output: TypeRef) -> TypeRef {
ret llvm::LLVMFunctionType(output, std::ivec::to_ptr(inputs),
std::ivec::len[TypeRef](inputs), False);
}
-fn T_fn_pair(&crate_ctxt cx, TypeRef tfn) -> TypeRef {
+fn T_fn_pair(cx: &crate_ctxt, tfn: TypeRef) -> TypeRef {
ret T_struct(~[T_ptr(tfn), T_opaque_closure_ptr(cx)]);
}
-fn T_ptr(TypeRef t) -> TypeRef { ret llvm::LLVMPointerType(t, 0u); }
+fn T_ptr(t: TypeRef) -> TypeRef { ret llvm::LLVMPointerType(t, 0u); }
-fn T_struct(&TypeRef[] elts) -> TypeRef {
+fn T_struct(elts: &TypeRef[]) -> TypeRef {
ret llvm::LLVMStructType(std::ivec::to_ptr(elts), std::ivec::len(elts),
False);
}
-fn T_named_struct(&str name) -> TypeRef {
- auto c = llvm::LLVMGetGlobalContext();
+fn T_named_struct(name: &str) -> TypeRef {
+ let c = llvm::LLVMGetGlobalContext();
ret llvm::LLVMStructCreateNamed(c, str::buf(name));
}
-fn set_struct_body(TypeRef t, &TypeRef[] elts) {
+fn set_struct_body(t: TypeRef, elts: &TypeRef[]) {
llvm::LLVMStructSetBody(t, std::ivec::to_ptr(elts), std::ivec::len(elts),
False);
}
@@ -496,97 +498,101 @@
fn T_empty_struct() -> TypeRef { ret T_struct(~[]); }
fn T_rust_object() -> TypeRef {
- auto t = T_named_struct("rust_object");
- auto e = T_ptr(T_empty_struct());
- set_struct_body(t, ~[e,e]);
+ let t = T_named_struct("rust_object");
+ let e = T_ptr(T_empty_struct());
+ set_struct_body(t, ~[e, e]);
ret t;
}
fn T_task() -> TypeRef {
- auto t = T_named_struct("task");
+ let t = T_named_struct("task");
- auto elems = ~[T_int(), // Refcount
- T_int(), // Delegate pointer
- T_int(), // Stack segment pointer
- T_int(), // Runtime SP
- T_int(), // Rust SP
- T_int(), // GC chain
+ let // Refcount
+ // Delegate pointer
+ // Stack segment pointer
+ // Runtime SP
+ // Rust SP
+ // GC chain
- T_int(), // Domain pointer
- // Crate cache pointer
- T_int()];
+ // Domain pointer
+ // Crate cache pointer
+ elems =
+ ~[T_int(), T_int(), T_int(), T_int(), T_int(), T_int(), T_int(),
+ T_int()];
set_struct_body(t, elems);
ret t;
}
-fn T_tydesc_field(&crate_ctxt cx, int field) -> TypeRef {
+fn T_tydesc_field(cx: &crate_ctxt, field: int) -> TypeRef {
// Bit of a kludge: pick the fn typeref out of the tydesc..
- let TypeRef[] tydesc_elts =
+ let tydesc_elts: TypeRef[] =
std::ivec::init_elt[TypeRef](T_nil(), abi::n_tydesc_fields as uint);
llvm::LLVMGetStructElementTypes(cx.tydesc_type,
std::ivec::to_ptr[TypeRef](tydesc_elts));
- auto t = llvm::LLVMGetElementType(tydesc_elts.(field));
+ let t = llvm::LLVMGetElementType(tydesc_elts.(field));
ret t;
}
-fn T_glue_fn(&crate_ctxt cx) -> TypeRef {
- auto s = "glue_fn";
- if (cx.tn.name_has_type(s)) { ret cx.tn.get_type(s); }
- auto t = T_tydesc_field(cx, abi::tydesc_field_drop_glue);
+fn T_glue_fn(cx: &crate_ctxt) -> TypeRef {
+ let s = "glue_fn";
+ if cx.tn.name_has_type(s) { ret cx.tn.get_type(s); }
+ let t = T_tydesc_field(cx, abi::tydesc_field_drop_glue);
cx.tn.associate(s, t);
ret t;
}
-fn T_dtor(&@crate_ctxt ccx, &span sp) -> TypeRef {
- ret type_of_fn_full(ccx, sp, ast::proto_fn, true,
- ~[], ty::mk_nil(ccx.tcx), 0u);
+fn T_dtor(ccx: &@crate_ctxt, sp: &span) -> TypeRef {
+ ret type_of_fn_full(ccx, sp, ast::proto_fn, true, ~[],
+ ty::mk_nil(ccx.tcx), 0u);
}
-fn T_cmp_glue_fn(&crate_ctxt cx) -> TypeRef {
- auto s = "cmp_glue_fn";
- if (cx.tn.name_has_type(s)) { ret cx.tn.get_type(s); }
- auto t = T_tydesc_field(cx, abi::tydesc_field_cmp_glue);
+fn T_cmp_glue_fn(cx: &crate_ctxt) -> TypeRef {
+ let s = "cmp_glue_fn";
+ if cx.tn.name_has_type(s) { ret cx.tn.get_type(s); }
+ let t = T_tydesc_field(cx, abi::tydesc_field_cmp_glue);
cx.tn.associate(s, t);
ret t;
}
-fn T_tydesc(TypeRef taskptr_type) -> TypeRef {
- auto tydesc = T_named_struct("tydesc");
- auto tydescpp = T_ptr(T_ptr(tydesc));
- auto pvoid = T_ptr(T_i8());
- auto glue_fn_ty =
+fn T_tydesc(taskptr_type: TypeRef) -> TypeRef {
+ let tydesc = T_named_struct("tydesc");
+ let tydescpp = T_ptr(T_ptr(tydesc));
+ let pvoid = T_ptr(T_i8());
+ let glue_fn_ty =
T_ptr(T_fn(~[T_ptr(T_nil()), taskptr_type, T_ptr(T_nil()), tydescpp,
pvoid], T_void()));
- auto cmp_glue_fn_ty =
+ let cmp_glue_fn_ty =
T_ptr(T_fn(~[T_ptr(T_i1()), taskptr_type, T_ptr(T_nil()), tydescpp,
pvoid, pvoid, T_i8()], T_void()));
- auto elems = ~[tydescpp, // first_param
- T_int(), // size
- T_int(), // align
- glue_fn_ty, // copy_glue
- glue_fn_ty, // drop_glue
- glue_fn_ty, // free_glue
- glue_fn_ty, // sever_glue
- glue_fn_ty, // mark_glue
- glue_fn_ty, // obj_drop_glue
- glue_fn_ty, // is_stateful
- cmp_glue_fn_ty];
+ let // first_param
+ // size
+ // align
+ // copy_glue
+ // drop_glue
+ // free_glue
+ // sever_glue
+ // mark_glue
+ // obj_drop_glue
+ // is_stateful
+ elems =
+ ~[tydescpp, T_int(), T_int(), glue_fn_ty, glue_fn_ty, glue_fn_ty,
+ glue_fn_ty, glue_fn_ty, glue_fn_ty, glue_fn_ty, cmp_glue_fn_ty];
set_struct_body(tydesc, elems);
ret tydesc;
}
-fn T_array(TypeRef t, uint n) -> TypeRef { ret llvm::LLVMArrayType(t, n); }
+fn T_array(t: TypeRef, n: uint) -> TypeRef { ret llvm::LLVMArrayType(t, n); }
-fn T_vec(TypeRef t) -> TypeRef {
+fn T_vec(t: TypeRef) -> TypeRef {
ret T_struct(~[T_int(), // Refcount
T_int(), // Alloc
T_int(), // Fill
T_int(), // Pad
- // Body elements
- T_array(t, 0u)]);
+ // Body elements
+ T_array(t, 0u)]);
}
fn T_opaque_vec_ptr() -> TypeRef { ret T_ptr(T_vec(T_int())); }
@@ -595,7 +601,7 @@
// Interior vector.
//
// TODO: Support user-defined vector sizes.
-fn T_ivec(TypeRef t) -> TypeRef {
+fn T_ivec(t: TypeRef) -> TypeRef {
ret T_struct(~[T_int(), // Length ("fill"; if zero, heapified)
T_int(), // Alloc
T_array(t, abi::ivec_default_length)]); // Body elements
@@ -611,7 +617,7 @@
}
-fn T_ivec_heap_part(TypeRef t) -> TypeRef {
+fn T_ivec_heap_part(t: TypeRef) -> TypeRef {
ret T_struct(~[T_int(), // Real length
T_array(t, 0u)]); // Body elements
@@ -620,7 +626,7 @@
// Interior vector on the heap, also known as the "stub". Cast to this when
// the allocated length (second element of T_ivec above) is zero.
-fn T_ivec_heap(TypeRef t) -> TypeRef {
+fn T_ivec_heap(t: TypeRef) -> TypeRef {
ret T_struct(~[T_int(), // Length (zero)
T_int(), // Alloc
T_ptr(T_ivec_heap_part(t))]); // Pointer
@@ -642,34 +648,34 @@
fn T_str() -> TypeRef { ret T_vec(T_i8()); }
-fn T_box(TypeRef t) -> TypeRef { ret T_struct(~[T_int(), t]); }
+fn T_box(t: TypeRef) -> TypeRef { ret T_struct(~[T_int(), t]); }
-fn T_port(TypeRef t) -> TypeRef {
+fn T_port(t: TypeRef) -> TypeRef {
ret T_struct(~[T_int()]); // Refcount
}
-fn T_chan(TypeRef t) -> TypeRef {
+fn T_chan(t: TypeRef) -> TypeRef {
ret T_struct(~[T_int()]); // Refcount
}
-fn T_taskptr(&crate_ctxt cx) -> TypeRef { ret T_ptr(cx.task_type); }
+fn T_taskptr(cx: &crate_ctxt) -> TypeRef { ret T_ptr(cx.task_type); }
// This type must never be used directly; it must always be cast away.
-fn T_typaram(&type_names tn) -> TypeRef {
- auto s = "typaram";
- if (tn.name_has_type(s)) { ret tn.get_type(s); }
- auto t = T_i8();
+fn T_typaram(tn: &type_names) -> TypeRef {
+ let s = "typaram";
+ if tn.name_has_type(s) { ret tn.get_type(s); }
+ let t = T_i8();
tn.associate(s, t);
ret t;
}
-fn T_typaram_ptr(&type_names tn) -> TypeRef { ret T_ptr(T_typaram(tn)); }
+fn T_typaram_ptr(tn: &type_names) -> TypeRef { ret T_ptr(T_typaram(tn)); }
-fn T_closure_ptr(&crate_ctxt cx, TypeRef lltarget_ty, TypeRef llbindings_ty,
- uint n_ty_params) -> TypeRef {
+fn T_closure_ptr(cx: &crate_ctxt, lltarget_ty: TypeRef,
+ llbindings_ty: TypeRef, n_ty_params: uint) -> TypeRef {
// NB: keep this in sync with code in trans_bind; we're making
// an LLVM typeref structure that has the same "shape" as the ty::t
// it constructs.
@@ -679,54 +685,52 @@
T_captured_tydescs(cx, n_ty_params)])));
}
-fn T_opaque_closure_ptr(&crate_ctxt cx) -> TypeRef {
- auto s = "*closure";
- if (cx.tn.name_has_type(s)) { ret cx.tn.get_type(s); }
- auto t =
- T_closure_ptr(cx,
- T_struct(~[T_ptr(T_nil()), T_ptr(T_nil())]),
- T_nil(),
- 0u);
+fn T_opaque_closure_ptr(cx: &crate_ctxt) -> TypeRef {
+ let s = "*closure";
+ if cx.tn.name_has_type(s) { ret cx.tn.get_type(s); }
+ let t =
+ T_closure_ptr(cx, T_struct(~[T_ptr(T_nil()), T_ptr(T_nil())]),
+ T_nil(), 0u);
cx.tn.associate(s, t);
ret t;
}
-fn T_tag(&type_names tn, uint size) -> TypeRef {
- auto s = "tag_" + uint::to_str(size, 10u);
- if (tn.name_has_type(s)) { ret tn.get_type(s); }
- auto t = T_struct(~[T_int(), T_array(T_i8(), size)]);
+fn T_tag(tn: &type_names, size: uint) -> TypeRef {
+ let s = "tag_" + uint::to_str(size, 10u);
+ if tn.name_has_type(s) { ret tn.get_type(s); }
+ let t = T_struct(~[T_int(), T_array(T_i8(), size)]);
tn.associate(s, t);
ret t;
}
-fn T_opaque_tag(&type_names tn) -> TypeRef {
- auto s = "opaque_tag";
- if (tn.name_has_type(s)) { ret tn.get_type(s); }
- auto t = T_struct(~[T_int(), T_i8()]);
+fn T_opaque_tag(tn: &type_names) -> TypeRef {
+ let s = "opaque_tag";
+ if tn.name_has_type(s) { ret tn.get_type(s); }
+ let t = T_struct(~[T_int(), T_i8()]);
tn.associate(s, t);
ret t;
}
-fn T_opaque_tag_ptr(&type_names tn) -> TypeRef {
+fn T_opaque_tag_ptr(tn: &type_names) -> TypeRef {
ret T_ptr(T_opaque_tag(tn));
}
-fn T_captured_tydescs(&crate_ctxt cx, uint n) -> TypeRef {
+fn T_captured_tydescs(cx: &crate_ctxt, n: uint) -> TypeRef {
ret T_struct(std::ivec::init_elt[TypeRef](T_ptr(cx.tydesc_type), n));
}
-fn T_obj_ptr(&crate_ctxt cx, uint n_captured_tydescs) -> TypeRef {
+fn T_obj_ptr(cx: &crate_ctxt, n_captured_tydescs: uint) -> TypeRef {
// This function is not publicly exposed because it returns an incomplete
// type. The dynamically-sized fields follow the captured tydescs.
- fn T_obj(&crate_ctxt cx, uint n_captured_tydescs) -> TypeRef {
+ fn T_obj(cx: &crate_ctxt, n_captured_tydescs: uint) -> TypeRef {
ret T_struct(~[T_ptr(cx.tydesc_type),
T_captured_tydescs(cx, n_captured_tydescs)]);
}
ret T_ptr(T_box(T_obj(cx, n_captured_tydescs)));
}
-fn T_opaque_obj_ptr(&crate_ctxt cx) -> TypeRef { ret T_obj_ptr(cx, 0u); }
+fn T_opaque_obj_ptr(cx: &crate_ctxt) -> TypeRef { ret T_obj_ptr(cx, 0u); }
fn T_opaque_port_ptr() -> TypeRef { ret T_ptr(T_i8()); }
@@ -734,9 +738,9 @@
// LLVM constant constructors.
-fn C_null(TypeRef t) -> ValueRef { ret llvm::LLVMConstNull(t); }
+fn C_null(t: TypeRef) -> ValueRef { ret llvm::LLVMConstNull(t); }
-fn C_integral(TypeRef t, uint u, Bool sign_extend) -> ValueRef {
+fn C_integral(t: TypeRef, u: uint, sign_extend: Bool) -> ValueRef {
// FIXME: We can't use LLVM::ULongLong with our existing minimal native
// API, which only knows word-sized args.
//
@@ -746,11 +750,11 @@
ret llvm::LLVMRustConstSmallInt(t, u, sign_extend);
}
-fn C_float(&str s) -> ValueRef {
+fn C_float(s: &str) -> ValueRef {
ret llvm::LLVMConstRealOfString(T_float(), str::buf(s));
}
-fn C_floating(&str s, TypeRef t) -> ValueRef {
+fn C_floating(s: &str, t: TypeRef) -> ValueRef {
ret llvm::LLVMConstRealOfString(t, str::buf(s));
}
@@ -760,24 +764,24 @@
ret C_integral(T_i1(), 0u, False);
}
-fn C_bool(bool b) -> ValueRef {
- if (b) {
+fn C_bool(b: bool) -> ValueRef {
+ if b {
ret C_integral(T_bool(), 1u, False);
} else { ret C_integral(T_bool(), 0u, False); }
}
-fn C_int(int i) -> ValueRef { ret C_integral(T_int(), i as uint, True); }
+fn C_int(i: int) -> ValueRef { ret C_integral(T_int(), i as uint, True); }
-fn C_uint(uint i) -> ValueRef { ret C_integral(T_int(), i, False); }
+fn C_uint(i: uint) -> ValueRef { ret C_integral(T_int(), i, False); }
-fn C_u8(uint i) -> ValueRef { ret C_integral(T_i8(), i, False); }
+fn C_u8(i: uint) -> ValueRef { ret C_integral(T_i8(), i, False); }
// This is a 'c-like' raw string, which differs from
// our boxed-and-length-annotated strings.
-fn C_cstr(&@crate_ctxt cx, &str s) -> ValueRef {
- auto sc = llvm::LLVMConstString(str::buf(s), str::byte_len(s), False);
- auto g =
+fn C_cstr(cx: &@crate_ctxt, s: &str) -> ValueRef {
+ let sc = llvm::LLVMConstString(str::buf(s), str::byte_len(s), False);
+ let g =
llvm::LLVMAddGlobal(cx.llmod, val_ty(sc),
str::buf(cx.names.next("str")));
llvm::LLVMSetInitializer(g, sc);
@@ -788,15 +792,16 @@
// A rust boxed-and-length-annotated string.
-fn C_str(&@crate_ctxt cx, &str s) -> ValueRef {
- auto len = str::byte_len(s);
- auto box =
- C_struct(~[C_int(abi::const_refcount as int),
- C_int(len + 1u as int), // 'alloc'
- C_int(len + 1u as int), // 'fill'
- C_int(0), // 'pad'
+fn C_str(cx: &@crate_ctxt, s: &str) -> ValueRef {
+ let len = str::byte_len(s);
+ let // 'alloc'
+ // 'fill'
+ // 'pad'
+ box =
+ C_struct(~[C_int(abi::const_refcount as int), C_int(len + 1u as int),
+ C_int(len + 1u as int), C_int(0),
llvm::LLVMConstString(str::buf(s), len, False)]);
- auto g =
+ let g =
llvm::LLVMAddGlobal(cx.llmod, val_ty(box),
str::buf(cx.names.next("str")));
llvm::LLVMSetInitializer(g, box);
@@ -806,29 +811,29 @@
}
// Returns a Plain Old LLVM String:
-fn C_postr(&str s) -> ValueRef {
+fn C_postr(s: &str) -> ValueRef {
ret llvm::LLVMConstString(str::buf(s), str::byte_len(s), False);
}
-fn C_zero_byte_arr(uint size) -> ValueRef {
- auto i = 0u;
- let ValueRef[] elts = ~[];
- while (i < size) { elts += ~[C_u8(0u)]; i += 1u; }
+fn C_zero_byte_arr(size: uint) -> ValueRef {
+ let i = 0u;
+ let elts: ValueRef[] = ~[];
+ while i < size { elts += ~[C_u8(0u)]; i += 1u; }
ret llvm::LLVMConstArray(T_i8(), std::ivec::to_ptr(elts),
std::ivec::len(elts));
}
-fn C_struct(&ValueRef[] elts) -> ValueRef {
+fn C_struct(elts: &ValueRef[]) -> ValueRef {
ret llvm::LLVMConstStruct(std::ivec::to_ptr(elts), std::ivec::len(elts),
False);
}
-fn C_named_struct(TypeRef T, &ValueRef[] elts) -> ValueRef {
+fn C_named_struct(T: TypeRef, elts: &ValueRef[]) -> ValueRef {
ret llvm::LLVMConstNamedStruct(T, std::ivec::to_ptr(elts),
std::ivec::len(elts));
}
-fn C_array(TypeRef ty, &ValueRef[] elts) -> ValueRef {
+fn C_array(ty: TypeRef, elts: &ValueRef[]) -> ValueRef {
ret llvm::LLVMConstArray(ty, std::ivec::to_ptr(elts),
std::ivec::len(elts));
-}
+}
\ No newline at end of file
diff --git a/src/comp/middle/trans_dps.rs b/src/comp/middle/trans_dps.rs
index 331b7d9..4e65934 100644
--- a/src/comp/middle/trans_dps.rs
+++ b/src/comp/middle/trans_dps.rs
@@ -29,22 +29,22 @@
// LLVM utilities
-fn llelement_type(TypeRef llty) -> TypeRef {
+fn llelement_type(llty: TypeRef) -> TypeRef {
lib::llvm::llvm::LLVMGetElementType(llty)
}
-fn llalign_of(&@crate_ctxt ccx, TypeRef llty) -> uint {
+fn llalign_of(ccx: &@crate_ctxt, llty: TypeRef) -> uint {
ret llvm::LLVMPreferredAlignmentOfType(ccx.td.lltd, llty);
}
-fn llsize_of(&@crate_ctxt ccx, TypeRef llty) -> uint {
+fn llsize_of(ccx: &@crate_ctxt, llty: TypeRef) -> uint {
ret llvm::LLVMStoreSizeOfType(ccx.td.lltd, llty);
}
-fn mk_const(&@crate_ctxt ccx, &str name, bool exported, ValueRef llval)
- -> ValueRef {
- auto llglobal = llvm::LLVMAddGlobal(ccx.llmod, tc::val_ty(llval),
- str::buf(name));
+fn mk_const(ccx: &@crate_ctxt, name: &str, exported: bool, llval: ValueRef) ->
+ ValueRef {
+ let llglobal =
+ llvm::LLVMAddGlobal(ccx.llmod, tc::val_ty(llval), str::buf(name));
llvm::LLVMSetInitializer(llglobal, llval);
llvm::LLVMSetGlobalConstant(llglobal, LLTrue);
@@ -60,10 +60,10 @@
// Type utilities
-fn size_of(&@crate_ctxt ccx, &span sp, ty::t t) -> uint {
+fn size_of(ccx: &@crate_ctxt, sp: &span, t: ty::t) -> uint {
if ty::type_has_dynamic_size(ccx.tcx, t) {
ccx.sess.bug("trans_dps::size_of() called on a type with dynamic " +
- "size");
+ "size");
}
ret llsize_of(ccx, trans::type_of_inner(ccx, sp, t));
}
@@ -72,105 +72,109 @@
// Destination utilities
tag dest {
- dst_nil; // Unit destination; ignore.
- dst_imm(@mutable option[ValueRef]); // Fill with an immediate value.
- dst_alias(@mutable option[ValueRef]); // Fill with an alias pointer.
- dst_copy(ValueRef); // Copy to the given address.
- dst_move(ValueRef); // Move to the given address.
+ dst_nil; // Unit destination; ignore.
+
+ dst_imm(@mutable option[ValueRef]); // Fill with an immediate value.
+
+ dst_alias(@mutable option[ValueRef]); // Fill with an alias pointer.
+
+ dst_copy(ValueRef); // Copy to the given address.
+
+ dst_move(ValueRef); // Move to the given address.
}
-fn dest_imm(&ty::ctxt tcx, ty::t t) -> dest {
+fn dest_imm(tcx: &ty::ctxt, t: ty::t) -> dest {
if ty::type_is_nil(tcx, t) { dst_nil } else { dst_imm(@mutable none) }
}
-fn dest_alias(&ty::ctxt tcx, ty::t t) -> dest {
+fn dest_alias(tcx: &ty::ctxt, t: ty::t) -> dest {
if ty::type_is_nil(tcx, t) { dst_nil } else { dst_alias(@mutable none) }
}
-fn dest_copy(&ty::ctxt tcx, ValueRef llptr, ty::t t) -> dest {
+fn dest_copy(tcx: &ty::ctxt, llptr: ValueRef, t: ty::t) -> dest {
if ty::type_is_nil(tcx, t) { dst_nil } else { dst_copy(llptr) }
}
-fn dest_move(&ty::ctxt tcx, ValueRef llptr, ty::t t) -> dest {
+fn dest_move(tcx: &ty::ctxt, llptr: ValueRef, t: ty::t) -> dest {
if ty::type_is_nil(tcx, t) { dst_nil } else { dst_move(llptr) }
}
// Invariant: the type of the destination must be structural (non-immediate).
-fn dest_ptr(&dest dest) -> ValueRef {
- alt (dest) {
- dst_nil { fail "nil dest in dest_ptr" }
+fn dest_ptr(dest: &dest) -> ValueRef {
+ alt dest {
+ dst_nil. { fail "nil dest in dest_ptr" }
dst_imm(_) { fail "immediate dest in dest_ptr" }
- dst_alias(?box) {
- alt (*box) {
- none { fail "alias wasn't filled in prior to dest_ptr" }
- some(?llval) { llval }
+ dst_alias(box) {
+ alt *box {
+ none. { fail "alias wasn't filled in prior to dest_ptr" }
+ some(llval) { llval }
}
}
- dst_copy(?llptr) { llptr }
- dst_move(?llptr) { llptr }
+ dst_copy(llptr) { llptr }
+ dst_move(llptr) { llptr }
}
}
-fn dest_llval(&dest dest) -> ValueRef {
- alt (dest) {
- dst_nil { ret tc::C_nil(); }
- dst_imm(?box) {
- alt (*box) {
- none { fail "immediate wasn't filled in prior to dest_llval"; }
- some(?llval) { ret llval; }
+fn dest_llval(dest: &dest) -> ValueRef {
+ alt dest {
+ dst_nil. { ret tc::C_nil(); }
+ dst_imm(box) {
+ alt *box {
+ none. { fail "immediate wasn't filled in prior to dest_llval"; }
+ some(llval) { ret llval; }
}
}
- dst_alias(?box) {
- alt (*box) {
- none { fail "alias wasn't filled in prior to dest_llval"; }
- some(?llval) { ret llval; }
+ dst_alias(box) {
+ alt *box {
+ none. { fail "alias wasn't filled in prior to dest_llval"; }
+ some(llval) { ret llval; }
}
}
- dst_copy(?llptr) { ret llptr; }
- dst_move(?llptr) { ret llptr; }
+ dst_copy(llptr) { ret llptr; }
+ dst_move(llptr) { ret llptr; }
}
}
-fn dest_is_alias(&dest dest) -> bool {
- alt (dest) { dst_alias(_) { true } _ { false } }
+fn dest_is_alias(dest: &dest) -> bool {
+ alt dest { dst_alias(_) { true } _ { false } }
}
// Common operations
-fn memmove(&@block_ctxt bcx, ValueRef lldestptr, ValueRef llsrcptr,
- ValueRef llsz) {
- auto lldestty = llelement_type(tc::val_ty(lldestptr));
- auto llsrcty = llelement_type(tc::val_ty(llsrcptr));
- auto dest_align = llalign_of(bcx_ccx(bcx), lldestty);
- auto src_align = llalign_of(bcx_ccx(bcx), llsrcty);
- auto align = uint::min(dest_align, src_align);
- auto llfn = bcx_ccx(bcx).intrinsics.get("llvm.memmove.p0i8.p0i8.i32");
- auto lldestptr_i8 = bcx.build.PointerCast(lldestptr,
- tc::T_ptr(tc::T_i8()));
- auto llsrcptr_i8 = bcx.build.PointerCast(llsrcptr,
- tc::T_ptr(tc::T_i8()));
- bcx.build.Call(llfn, ~[lldestptr_i8, llsrcptr_i8, llsz, tc::C_uint(align),
- tc::C_bool(false)]);
+fn memmove(bcx: &@block_ctxt, lldestptr: ValueRef, llsrcptr: ValueRef,
+ llsz: ValueRef) {
+ let lldestty = llelement_type(tc::val_ty(lldestptr));
+ let llsrcty = llelement_type(tc::val_ty(llsrcptr));
+ let dest_align = llalign_of(bcx_ccx(bcx), lldestty);
+ let src_align = llalign_of(bcx_ccx(bcx), llsrcty);
+ let align = uint::min(dest_align, src_align);
+ let llfn = bcx_ccx(bcx).intrinsics.get("llvm.memmove.p0i8.p0i8.i32");
+ let lldestptr_i8 =
+ bcx.build.PointerCast(lldestptr, tc::T_ptr(tc::T_i8()));
+ let llsrcptr_i8 = bcx.build.PointerCast(llsrcptr, tc::T_ptr(tc::T_i8()));
+ bcx.build.Call(llfn,
+ ~[lldestptr_i8, llsrcptr_i8, llsz, tc::C_uint(align),
+ tc::C_bool(false)]);
}
// If "cast" is true, casts dest appropriately before the store.
-fn store_imm(&@block_ctxt bcx, &dest dest, ValueRef llsrc, bool cast)
- -> @block_ctxt {
- alt (dest) {
- dst_nil { /* no-op */ }
- dst_imm(?box) {
+fn store_imm(bcx: &@block_ctxt, dest: &dest, llsrc: ValueRef, cast: bool) ->
+ @block_ctxt {
+ alt dest {
+ dst_nil. {/* no-op */ }
+ dst_imm(box) {
assert (std::option::is_none(*box));
*box = some(llsrc);
}
- dst_alias(?box) {
+ dst_alias(box) {
bcx_ccx(bcx).sess.unimpl("dst_alias spill in store_imm");
}
- dst_copy(?lldestptr_orig) | dst_move(?lldestptr_orig) {
- auto lldestptr = lldestptr_orig;
+ dst_copy(lldestptr_orig) | dst_move(lldestptr_orig) {
+ let lldestptr = lldestptr_orig;
if cast {
- lldestptr = bcx.build.PointerCast(lldestptr,
- tc::T_ptr(lltype_of(llsrc)));
+ lldestptr =
+ bcx.build.PointerCast(lldestptr, tc::T_ptr(lltype_of(llsrc)));
}
bcx.build.Store(llsrc, lldestptr);
}
@@ -178,20 +182,21 @@
ret bcx;
}
-fn store_ptr(&@block_ctxt bcx, &dest dest, ValueRef llsrcptr) -> @block_ctxt {
- alt (dest) {
- dst_nil { /* no-op */ }
- dst_imm(?box) {
+fn store_ptr(bcx: &@block_ctxt, dest: &dest, llsrcptr: ValueRef) ->
+ @block_ctxt {
+ alt dest {
+ dst_nil. {/* no-op */ }
+ dst_imm(box) {
assert (std::option::is_none(*box));
*box = some(bcx.build.Load(llsrcptr));
}
- dst_alias(?box) {
+ dst_alias(box) {
assert (std::option::is_none(*box));
*box = some(llsrcptr);
}
- dst_copy(?lldestptr) | dst_move(?lldestptr) {
- auto llsrcty = llelement_type(tc::val_ty(llsrcptr));
- auto llsz = tc::C_uint(llsize_of(bcx_ccx(bcx), llsrcty));
+ dst_copy(lldestptr) | dst_move(lldestptr) {
+ let llsrcty = llelement_type(tc::val_ty(llsrcptr));
+ let llsz = tc::C_uint(llsize_of(bcx_ccx(bcx), llsrcty));
memmove(bcx, lldestptr, llsrcptr, llsz);
ret bcx;
}
@@ -205,27 +210,28 @@
// TODO: This should *not* use destination-passing style, because doing so
// makes callers incur an extra load.
tag heap { hp_task; hp_shared; }
-fn malloc(&@block_ctxt bcx, ValueRef lldest, heap heap,
- option[ValueRef] llcustom_size_opt) -> @block_ctxt {
- auto llptrty = llelement_type(lltype_of(lldest));
- auto llty = llelement_type(llptrty);
+fn malloc(bcx: &@block_ctxt, lldest: ValueRef, heap: heap,
+ llcustom_size_opt: option[ValueRef]) -> @block_ctxt {
+ let llptrty = llelement_type(lltype_of(lldest));
+ let llty = llelement_type(llptrty);
- auto lltydescptr = tc::C_null(tc::T_ptr(bcx_ccx(bcx).tydesc_type));
+ let lltydescptr = tc::C_null(tc::T_ptr(bcx_ccx(bcx).tydesc_type));
- auto llsize;
- alt (llcustom_size_opt) {
- none { llsize = trans::llsize_of(llty); }
- some(?llcustom_size) { llsize = llcustom_size; }
+ let llsize;
+ alt llcustom_size_opt {
+ none. { llsize = trans::llsize_of(llty); }
+ some(llcustom_size) { llsize = llcustom_size; }
}
- auto llupcall;
- alt (heap) {
- hp_task { llupcall = bcx_ccx(bcx).upcalls.malloc; }
- hp_shared { llupcall = bcx_ccx(bcx).upcalls.shared_malloc; }
+ let llupcall;
+ alt heap {
+ hp_task. { llupcall = bcx_ccx(bcx).upcalls.malloc; }
+ hp_shared. { llupcall = bcx_ccx(bcx).upcalls.shared_malloc; }
}
- auto llresult = bcx.build.Call(llupcall, ~[bcx_fcx(bcx).lltaskptr, llsize,
- lltydescptr]);
+ let llresult =
+ bcx.build.Call(llupcall,
+ ~[bcx_fcx(bcx).lltaskptr, llsize, lltydescptr]);
llresult = bcx.build.PointerCast(llresult, llptrty);
bcx.build.Store(llresult, lldest);
ret bcx;
@@ -233,191 +239,195 @@
// If the supplied destination is an alias, spills to a temporary. Returns the
// new destination.
-fn spill_alias(&@block_ctxt cx, &dest dest, ty::t t)
- -> rec(@block_ctxt bcx, dest dest) {
- auto bcx = cx;
- alt (dest) {
- dst_alias(?box) {
+fn spill_alias(cx: &@block_ctxt, dest: &dest, t: ty::t) ->
+ {bcx: @block_ctxt, dest: dest} {
+ let bcx = cx;
+ alt dest {
+ dst_alias(box) {
// TODO: Mark the alias as needing a cleanup.
assert (std::option::is_none(*box));
- auto r = trans::alloc_ty(cx, t);
- bcx = r.bcx; auto llptr = r.val;
+ let r = trans::alloc_ty(cx, t);
+ bcx = r.bcx;
+ let llptr = r.val;
*box = some(llptr);
- ret rec(bcx=bcx, dest=dst_move(llptr));
+ ret {bcx: bcx, dest: dst_move(llptr)};
}
- _ { ret rec(bcx=bcx, dest=dest); }
+ _ { ret {bcx: bcx, dest: dest}; }
}
}
-fn mk_temp(&@block_ctxt cx, ty::t t) -> rec(@block_ctxt bcx, dest dest) {
- auto bcx = cx;
- if ty::type_is_nil(bcx_tcx(bcx), t) { ret rec(bcx=bcx, dest=dst_nil); }
+fn mk_temp(cx: &@block_ctxt, t: ty::t) -> {bcx: @block_ctxt, dest: dest} {
+ let bcx = cx;
+ if ty::type_is_nil(bcx_tcx(bcx), t) { ret {bcx: bcx, dest: dst_nil}; }
if trans::type_is_immediate(bcx_ccx(bcx), t) {
- ret rec(bcx=bcx, dest=dst_imm(@mutable none));
+ ret {bcx: bcx, dest: dst_imm(@mutable none)};
}
- auto r = trans::alloc_ty(cx, t);
- bcx = r.bcx; auto llptr = r.val;
- ret rec(bcx=bcx, dest=dst_copy(llptr));
+ let r = trans::alloc_ty(cx, t);
+ bcx = r.bcx;
+ let llptr = r.val;
+ ret {bcx: bcx, dest: dst_copy(llptr)};
}
// AST substructure translation, with destinations
-fn trans_lit(&@block_ctxt cx, &dest dest, &ast::lit lit) -> @block_ctxt {
- auto bcx = cx;
- alt (lit.node) {
- ast::lit_str(?s, ast::sk_unique) {
- auto r = trans_lit_str_common(bcx_ccx(bcx), s, dest_is_alias(dest));
- auto llstackpart = r.stack; auto llheappartopt = r.heap;
+fn trans_lit(cx: &@block_ctxt, dest: &dest, lit: &ast::lit) -> @block_ctxt {
+ let bcx = cx;
+ alt lit.node {
+ ast::lit_str(s, ast::sk_unique.) {
+ let r = trans_lit_str_common(bcx_ccx(bcx), s, dest_is_alias(dest));
+ let llstackpart = r.stack;
+ let llheappartopt = r.heap;
bcx = store_ptr(bcx, dest, llstackpart);
- alt (llheappartopt) {
- none { /* no-op */ }
- some(?llheappart) {
- auto lldestptrptr =
+ alt llheappartopt {
+ none. {/* no-op */ }
+ some(llheappart) {
+ let lldestptrptr =
bcx.build.InBoundsGEP(dest_ptr(dest),
~[tc::C_int(0),
tc::C_uint(abi::ivec_elt_elems)]);
- auto llheappartty = lltype_of(llheappart);
+ let llheappartty = lltype_of(llheappart);
lldestptrptr =
bcx.build.PointerCast(lldestptrptr,
tc::T_ptr(tc::T_ptr(llheappartty)));
malloc(bcx, lldestptrptr, hp_shared, none);
- auto lldestptr = bcx.build.Load(lldestptrptr);
+ let lldestptr = bcx.build.Load(lldestptrptr);
store_ptr(bcx, dst_copy(lldestptr), llheappart);
}
}
}
_ {
- bcx = store_imm(bcx, dest, trans_lit_common(bcx_ccx(bcx), lit),
- false);
+ bcx =
+ store_imm(bcx, dest, trans_lit_common(bcx_ccx(bcx), lit), false);
}
}
ret bcx;
}
-fn trans_binary(&@block_ctxt cx, &dest dest, &span sp, ast::binop op,
- &@ast::expr lhs, &@ast::expr rhs) -> @block_ctxt {
- auto bcx = cx;
- alt (op) {
- ast::add {
- bcx = trans_vec::trans_concat(bcx, dest, sp,
- ty::expr_ty(bcx_tcx(bcx), rhs), lhs,
- rhs);
+fn trans_binary(cx: &@block_ctxt, dest: &dest, sp: &span, op: ast::binop,
+ lhs: &@ast::expr, rhs: &@ast::expr) -> @block_ctxt {
+ let bcx = cx;
+ alt op {
+ ast::add. {
+ bcx =
+ trans_vec::trans_concat(bcx, dest, sp,
+ ty::expr_ty(bcx_tcx(bcx), rhs), lhs, rhs);
}
- // TODO: Many more to add here.
}
+ // TODO: Many more to add here.
ret bcx;
}
-fn trans_log(&@block_ctxt cx, &span sp, int level, &@ast::expr expr)
- -> @block_ctxt {
- fn trans_log_level(&@local_ctxt lcx) -> ValueRef {
- auto modname = str::connect_ivec(lcx.module_path, "::");
+fn trans_log(cx: &@block_ctxt, sp: &span, level: int, expr: &@ast::expr) ->
+ @block_ctxt {
+ fn trans_log_level(lcx: &@local_ctxt) -> ValueRef {
+ let modname = str::connect_ivec(lcx.module_path, "::");
- if (lcx_ccx(lcx).module_data.contains_key(modname)) {
+ if lcx_ccx(lcx).module_data.contains_key(modname) {
ret lcx_ccx(lcx).module_data.get(modname);
}
- auto s =
+ let s =
link::mangle_internal_name_by_path_and_seq(lcx_ccx(lcx),
lcx.module_path,
"loglevel");
- auto lllevelptr = llvm::LLVMAddGlobal(lcx.ccx.llmod, tc::T_int(),
- str::buf(s));
+ let lllevelptr =
+ llvm::LLVMAddGlobal(lcx.ccx.llmod, tc::T_int(), str::buf(s));
llvm::LLVMSetGlobalConstant(lllevelptr, LLFalse);
llvm::LLVMSetInitializer(lllevelptr, tc::C_int(0));
- llvm::LLVMSetLinkage(lllevelptr, lib::llvm::LLVMInternalLinkage as
- llvm::Linkage);
+ llvm::LLVMSetLinkage(lllevelptr,
+ lib::llvm::LLVMInternalLinkage as llvm::Linkage);
lcx_ccx(lcx).module_data.insert(modname, lllevelptr);
ret lllevelptr;
}
tag upcall_style { us_imm; us_imm_i32_zext; us_alias; us_alias_istr; }
- fn get_upcall(&@crate_ctxt ccx, &span sp, ty::t t)
- -> rec(ValueRef val, upcall_style st) {
- alt (ty::struct(ccx_tcx(ccx), t)) {
- ty::ty_machine(ast::ty_f32) {
- ret rec(val=ccx.upcalls.log_float, st=us_imm);
+ fn get_upcall(ccx: &@crate_ctxt, sp: &span, t: ty::t) ->
+ {val: ValueRef, st: upcall_style} {
+ alt ty::struct(ccx_tcx(ccx), t) {
+ ty::ty_machine(ast::ty_f32.) {
+ ret {val: ccx.upcalls.log_float, st: us_imm};
}
- ty::ty_machine(ast::ty_f64) | ty::ty_float {
+ ty::ty_machine(ast::ty_f64.) | ty::ty_float. {
// TODO: We have to spill due to legacy calling conventions that
// should probably be modernized.
- ret rec(val=ccx.upcalls.log_double, st=us_alias);
+ ret {val: ccx.upcalls.log_double, st: us_alias};
}
- ty::ty_bool | ty::ty_machine(ast::ty_i8) |
- ty::ty_machine(ast::ty_i16) | ty::ty_machine(ast::ty_u8) |
- ty::ty_machine(ast::ty_u16) {
- ret rec(val=ccx.upcalls.log_int, st=us_imm_i32_zext);
+ ty::ty_bool. | ty::ty_machine(ast::ty_i8.) |
+ ty::ty_machine(ast::ty_i16.) | ty::ty_machine(ast::ty_u8.) |
+ ty::ty_machine(ast::ty_u16.) {
+ ret {val: ccx.upcalls.log_int, st: us_imm_i32_zext};
}
- ty::ty_int | ty::ty_machine(ast::ty_i32) |
- ty::ty_machine(ast::ty_u32) {
- ret rec(val=ccx.upcalls.log_int, st=us_imm);
+ ty::ty_int. | ty::ty_machine(ast::ty_i32.) |
+ ty::ty_machine(ast::ty_u32.) {
+ ret {val: ccx.upcalls.log_int, st: us_imm};
}
- ty::ty_istr {
- ret rec(val=ccx.upcalls.log_istr, st=us_alias_istr);
- }
+ ty::ty_istr. { ret {val: ccx.upcalls.log_istr, st: us_alias_istr}; }
_ {
- ccx.sess.span_unimpl(sp, "logging for values of type " +
- ppaux::ty_to_str(ccx_tcx(ccx), t));
+ ccx.sess.span_unimpl(sp,
+ "logging for values of type " +
+ ppaux::ty_to_str(ccx_tcx(ccx), t));
}
}
}
- auto bcx = cx;
+ let bcx = cx;
- auto lllevelptr = trans_log_level(bcx_lcx(bcx));
+ let lllevelptr = trans_log_level(bcx_lcx(bcx));
- auto log_bcx = trans::new_scope_block_ctxt(bcx, "log");
- auto next_bcx = trans::new_scope_block_ctxt(bcx, "next_log");
+ let log_bcx = trans::new_scope_block_ctxt(bcx, "log");
+ let next_bcx = trans::new_scope_block_ctxt(bcx, "next_log");
- auto should_log = bcx.build.ICmp(ll::LLVMIntSGE,
- bcx.build.Load(lllevelptr),
- tc::C_int(level));
+ let should_log =
+ bcx.build.ICmp(ll::LLVMIntSGE, bcx.build.Load(lllevelptr),
+ tc::C_int(level));
bcx.build.CondBr(should_log, log_bcx.llbb, next_bcx.llbb);
- auto expr_t = ty::expr_ty(bcx_tcx(log_bcx), expr);
- auto r = get_upcall(bcx_ccx(bcx), sp, expr_t);
- auto llupcall = r.val; auto style = r.st;
+ let expr_t = ty::expr_ty(bcx_tcx(log_bcx), expr);
+ let r = get_upcall(bcx_ccx(bcx), sp, expr_t);
+ let llupcall = r.val;
+ let style = r.st;
- auto arg_dest;
- alt (style) {
- us_imm | us_imm_i32_zext {
+ let arg_dest;
+ alt style {
+ us_imm. | us_imm_i32_zext. {
arg_dest = dest_imm(bcx_tcx(log_bcx), expr_t);
}
- us_alias | us_alias_istr {
+ us_alias. | us_alias_istr. {
arg_dest = dest_alias(bcx_tcx(log_bcx), expr_t);
}
}
log_bcx = trans_expr(log_bcx, arg_dest, expr);
- auto llarg = dest_llval(arg_dest);
- alt (style) {
- us_imm | us_alias { /* no-op */ }
- us_imm_i32_zext { llarg = log_bcx.build.ZExt(llarg, tc::T_i32()); }
- us_alias_istr {
- llarg = log_bcx.build.PointerCast(llarg,
- tc::T_ptr(tc::T_ivec(tc::T_i8())));
+ let llarg = dest_llval(arg_dest);
+ alt style {
+ us_imm. | us_alias. {/* no-op */ }
+ us_imm_i32_zext. { llarg = log_bcx.build.ZExt(llarg, tc::T_i32()); }
+ us_alias_istr. {
+ llarg =
+ log_bcx.build.PointerCast(llarg,
+ tc::T_ptr(tc::T_ivec(tc::T_i8())));
}
}
log_bcx.build.Call(llupcall,
~[bcx_fcx(bcx).lltaskptr, tc::C_int(level), llarg]);
- log_bcx = trans::trans_block_cleanups(log_bcx,
- tc::find_scope_cx(log_bcx));
+ log_bcx =
+ trans::trans_block_cleanups(log_bcx, tc::find_scope_cx(log_bcx));
log_bcx.build.Br(next_bcx.llbb);
ret next_bcx;
}
-fn trans_path(&@block_ctxt bcx, &dest dest, &ast::path path, ast::node_id id)
- -> @block_ctxt {
- alt (bcx_tcx(bcx).def_map.get(id)) {
- ast::def_local(?def_id) {
- alt (bcx_fcx(bcx).lllocals.find(def_id.node)) {
- none { bcx_ccx(bcx).sess.unimpl("upvar in trans_path"); }
- some(?llptr) {
+fn trans_path(bcx: &@block_ctxt, dest: &dest, path: &ast::path,
+ id: ast::node_id) -> @block_ctxt {
+ alt bcx_tcx(bcx).def_map.get(id) {
+ ast::def_local(def_id) {
+ alt bcx_fcx(bcx).lllocals.find(def_id.node) {
+ none. { bcx_ccx(bcx).sess.unimpl("upvar in trans_path"); }
+ some(llptr) {
// TODO: Copy hooks.
store_ptr(bcx, dest, llptr);
}
@@ -428,42 +438,44 @@
ret bcx;
}
-fn trans_expr(&@block_ctxt bcx, &dest dest, &@ast::expr expr) -> @block_ctxt {
- alt (expr.node) {
- ast::expr_lit(?lit) { trans_lit(bcx, dest, *lit); ret bcx; }
- ast::expr_log(?level, ?operand) {
+fn trans_expr(bcx: &@block_ctxt, dest: &dest, expr: &@ast::expr) ->
+ @block_ctxt {
+ alt expr.node {
+ ast::expr_lit(lit) { trans_lit(bcx, dest, *lit); ret bcx; }
+ ast::expr_log(level, operand) {
ret trans_log(bcx, expr.span, level, operand);
}
- ast::expr_binary(?op, ?lhs, ?rhs) {
+ ast::expr_binary(op, lhs, rhs) {
ret trans_binary(bcx, dest, expr.span, op, lhs, rhs);
}
- ast::expr_path(?path) { ret trans_path(bcx, dest, path, expr.id); }
+ ast::expr_path(path) { ret trans_path(bcx, dest, path, expr.id); }
_ { fail "unhandled expr type in trans_expr"; }
}
}
-fn trans_recv(&@block_ctxt bcx, &dest dest, &@ast::expr expr) -> @block_ctxt {
- ret bcx; // TODO
+fn trans_recv(bcx: &@block_ctxt, dest: &dest, expr: &@ast::expr) ->
+ @block_ctxt {
+ ret bcx; // TODO
}
-fn trans_block(&@block_ctxt cx, &dest dest, &ast::blk blk)
- -> @block_ctxt {
- auto bcx = cx;
- for each (@ast::local local in trans::block_locals(blk)) {
+fn trans_block(cx: &@block_ctxt, dest: &dest, blk: &ast::blk) -> @block_ctxt {
+ let bcx = cx;
+ for each local: @ast::local in trans::block_locals(blk) {
bcx = trans::alloc_local(bcx, local).bcx;
}
- for (@ast::stmt stmt in blk.node.stmts) {
+ for stmt: @ast::stmt in blk.node.stmts {
bcx = trans_stmt(bcx, stmt);
+
// If we hit a terminator, control won't go any further so
// we're in dead-code land. Stop here.
if trans::is_terminated(bcx) { ret bcx; }
}
- alt (blk.node.expr) {
- some(?e) { bcx = trans_expr(bcx, dest, e); }
- none { /* no-op */ }
+ alt blk.node.expr {
+ some(e) { bcx = trans_expr(bcx, dest, e); }
+ none. {/* no-op */ }
}
bcx = trans::trans_block_cleanups(bcx, tc::find_scope_cx(bcx));
@@ -480,131 +492,133 @@
//
// If |expand| is true, we never spill to the heap. This should be used
// whenever the destination size isn't fixed.
-fn trans_lit_str_common(&@crate_ctxt ccx, &str s, bool expand)
- -> rec(ValueRef stack, option[ValueRef] heap) {
- auto llstackpart; auto llheappartopt;
+fn trans_lit_str_common(ccx: &@crate_ctxt, s: &str, expand: bool) ->
+ {stack: ValueRef, heap: option[ValueRef]} {
+ let llstackpart;
+ let llheappartopt;
- auto len = str::byte_len(s);
+ let len = str::byte_len(s);
- auto array = ~[];
- for (u8 ch in s) { array += ~[tc::C_u8(ch as uint)]; }
+ let array = ~[];
+ for ch: u8 in s { array += ~[tc::C_u8(ch as uint)]; }
array += ~[tc::C_u8(0u)];
if expand {
- llstackpart = tc::C_struct(~[tc::C_uint(len + 1u),
- tc::C_uint(len + 1u),
- tc::C_array(tc::T_i8(), array)]);
+ llstackpart =
+ tc::C_struct(~[tc::C_uint(len + 1u), tc::C_uint(len + 1u),
+ tc::C_array(tc::T_i8(), array)]);
llheappartopt = none;
- } else if len < abi::ivec_default_length - 1u { // minus one for the null
- while (ivec::len(array) < abi::ivec_default_length) {
+ } else if (len < abi::ivec_default_length - 1u)
+ { // minus one for the null
+ while ivec::len(array) < abi::ivec_default_length {
array += ~[tc::C_u8(0u)];
}
- llstackpart = tc::C_struct(~[tc::C_uint(len + 1u),
- tc::C_uint(abi::ivec_default_length),
- tc::C_array(tc::T_i8(), array)]);
+ llstackpart =
+ tc::C_struct(~[tc::C_uint(len + 1u),
+ tc::C_uint(abi::ivec_default_length),
+ tc::C_array(tc::T_i8(), array)]);
llheappartopt = none;
} else {
- auto llheappart = tc::C_struct(~[tc::C_uint(len),
- tc::C_array(tc::T_i8(), array)]);
+ let llheappart =
+ tc::C_struct(~[tc::C_uint(len), tc::C_array(tc::T_i8(), array)]);
llstackpart =
tc::C_struct(~[tc::C_uint(0u),
tc::C_uint(abi::ivec_default_length),
tc::C_null(tc::T_ptr(lltype_of(llheappart)))]);
- llheappartopt = some(mk_const(ccx, "const_istr_heap", false,
- llheappart));
+ llheappartopt =
+ some(mk_const(ccx, "const_istr_heap", false, llheappart));
}
- ret rec(stack=mk_const(ccx, "const_istr_stack", false, llstackpart),
- heap=llheappartopt);
+ ret {stack: mk_const(ccx, "const_istr_stack", false, llstackpart),
+ heap: llheappartopt};
}
// As above, we don't use destination-passing style here.
-fn trans_lit_common(&@crate_ctxt ccx, &ast::lit lit) -> ValueRef {
- alt (lit.node) {
- ast::lit_int(?i) { ret tc::C_int(i); }
- ast::lit_uint(?u) { ret tc::C_int(u as int); }
- ast::lit_mach_int(?tm, ?i) {
+fn trans_lit_common(ccx: &@crate_ctxt, lit: &ast::lit) -> ValueRef {
+ alt lit.node {
+ ast::lit_int(i) { ret tc::C_int(i); }
+ ast::lit_uint(u) { ret tc::C_int(u as int); }
+ ast::lit_mach_int(tm, i) {
// FIXME: the entire handling of mach types falls apart
// if target int width is larger than host, at the moment;
// re-do the mach-int types using 'big' when that works.
- auto t = tc::T_int();
- auto s = LLTrue;
- alt (tm) {
- ast::ty_u8 { t = tc::T_i8(); s = LLFalse; }
- ast::ty_u16 { t = tc::T_i16(); s = LLFalse; }
- ast::ty_u32 { t = tc::T_i32(); s = LLFalse; }
- ast::ty_u64 { t = tc::T_i64(); s = LLFalse; }
- ast::ty_i8 { t = tc::T_i8(); }
- ast::ty_i16 { t = tc::T_i16(); }
- ast::ty_i32 { t = tc::T_i32(); }
- ast::ty_i64 { t = tc::T_i64(); }
+ let t = tc::T_int();
+ let s = LLTrue;
+ alt tm {
+ ast::ty_u8. { t = tc::T_i8(); s = LLFalse; }
+ ast::ty_u16. { t = tc::T_i16(); s = LLFalse; }
+ ast::ty_u32. { t = tc::T_i32(); s = LLFalse; }
+ ast::ty_u64. { t = tc::T_i64(); s = LLFalse; }
+ ast::ty_i8. { t = tc::T_i8(); }
+ ast::ty_i16. { t = tc::T_i16(); }
+ ast::ty_i32. { t = tc::T_i32(); }
+ ast::ty_i64. { t = tc::T_i64(); }
}
ret tc::C_integral(t, i as uint, s);
}
- ast::lit_float(?fs) { ret tc::C_float(fs); }
- ast::lit_mach_float(?tm, ?s) {
- auto t = tc::T_float();
- alt (tm) {
- ast::ty_f32 { t = tc::T_f32(); }
- ast::ty_f64 { t = tc::T_f64(); }
+ ast::lit_float(fs) { ret tc::C_float(fs); }
+ ast::lit_mach_float(tm, s) {
+ let t = tc::T_float();
+ alt tm {
+ ast::ty_f32. { t = tc::T_f32(); }
+ ast::ty_f64. { t = tc::T_f64(); }
}
ret tc::C_floating(s, t);
}
- ast::lit_char(?c) {
+ ast::lit_char(c) {
ret tc::C_integral(tc::T_char(), c as uint, LLFalse);
}
- ast::lit_bool(?b) { ret tc::C_bool(b); }
- ast::lit_nil { ret tc::C_nil(); }
- ast::lit_str(?s, ast::sk_rc) { ret tc::C_str(ccx, s); }
- ast::lit_str(?s, ast::sk_unique) {
+ ast::lit_bool(b) { ret tc::C_bool(b); }
+ ast::lit_nil. { ret tc::C_nil(); }
+ ast::lit_str(s, ast::sk_rc.) { ret tc::C_str(ccx, s); }
+ ast::lit_str(s, ast::sk_unique.) {
fail "unique str in trans_lit_common";
}
}
}
-fn trans_init_local(&@block_ctxt bcx, &@ast::local local) -> @block_ctxt {
- auto llptr = bcx_fcx(bcx).lllocals.get(local.node.id);
+fn trans_init_local(bcx: &@block_ctxt, local: &@ast::local) -> @block_ctxt {
+ let llptr = bcx_fcx(bcx).lllocals.get(local.node.id);
- auto t = type_of_node(bcx_ccx(bcx), local.node.id);
+ let t = type_of_node(bcx_ccx(bcx), local.node.id);
tc::add_clean(bcx, llptr, t);
- alt (local.node.init) {
- some(?init) {
- alt (init.op) {
- ast::init_assign {
+
+ alt local.node.init {
+ some(init) {
+ alt init.op {
+ ast::init_assign. {
ret trans_expr(bcx, dest_copy(bcx_tcx(bcx), llptr, t), init.expr);
}
- ast::init_move {
+ ast::init_move. {
ret trans_expr(bcx, dest_move(bcx_tcx(bcx), llptr, t), init.expr);
}
- ast::init_recv {
+ ast::init_recv. {
ret trans_recv(bcx, dest_copy(bcx_tcx(bcx), llptr, t), init.expr);
}
}
}
- none { ret bcx; }
+ none. { ret bcx; }
}
}
-fn trans_stmt(&@block_ctxt cx, &@ast::stmt stmt) -> @block_ctxt {
- auto bcx = cx;
- alt (stmt.node) {
- ast::stmt_expr(?e, _) {
- auto tmp = dest_alias(bcx_tcx(bcx), ty::expr_ty(bcx_tcx(bcx), e));
+fn trans_stmt(cx: &@block_ctxt, stmt: &@ast::stmt) -> @block_ctxt {
+ let bcx = cx;
+ alt stmt.node {
+ ast::stmt_expr(e, _) {
+ let tmp = dest_alias(bcx_tcx(bcx), ty::expr_ty(bcx_tcx(bcx), e));
ret trans_expr(bcx, tmp, e);
}
- ast::stmt_decl(?d, _) {
- alt (d.node) {
- ast::decl_local(?locals) {
- for (@ast::local local in locals) {
+ ast::stmt_decl(d, _) {
+ alt d.node {
+ ast::decl_local(locals) {
+ for local: @ast::local in locals {
bcx = trans_init_local(bcx, local);
}
}
- ast::decl_item(?item) {
- trans::trans_item(bcx_lcx(bcx), *item);
- }
+ ast::decl_item(item) { trans::trans_item(bcx_lcx(bcx), *item); }
}
ret bcx;
}
diff --git a/src/comp/middle/trans_vec.rs b/src/comp/middle/trans_vec.rs
index 2105fd8..d2b3059 100644
--- a/src/comp/middle/trans_vec.rs
+++ b/src/comp/middle/trans_vec.rs
@@ -38,67 +38,63 @@
//
// TODO: We can optimize this in the cases in which we statically know the
// vector must be on the stack.
-fn get_len_and_data(&@block_ctxt cx, ty::t t, ValueRef llvecptr)
- -> rec(@block_ctxt bcx, ValueRef len, ValueRef data) {
- auto bcx = cx;
+fn get_len_and_data(cx: &@block_ctxt, t: ty::t, llvecptr: ValueRef) ->
+ {bcx: @block_ctxt, len: ValueRef, data: ValueRef} {
+ let bcx = cx;
// If this interior vector has dynamic size, we can't assume anything
// about the LLVM type of the value passed in, so we cast it to an
// opaque vector type.
- auto unit_ty = ty::sequence_element_type(bcx_tcx(bcx), t);
- auto v;
- if (ty::type_has_dynamic_size(bcx_tcx(bcx), unit_ty)) {
+ let unit_ty = ty::sequence_element_type(bcx_tcx(bcx), t);
+ let v;
+ if ty::type_has_dynamic_size(bcx_tcx(bcx), unit_ty) {
v = bcx.build.PointerCast(llvecptr, T_ptr(T_opaque_ivec()));
- } else {
- v = llvecptr;
- }
+ } else { v = llvecptr; }
- auto llunitty = type_of_or_i8(bcx, unit_ty);
- auto stack_len = load_inbounds(bcx, v, ~[C_int(0),
- C_uint(abi::ivec_elt_len)]);
- auto stack_elem =
+ let llunitty = type_of_or_i8(bcx, unit_ty);
+ let stack_len =
+ load_inbounds(bcx, v, ~[C_int(0), C_uint(abi::ivec_elt_len)]);
+ let stack_elem =
bcx.build.InBoundsGEP(v,
~[C_int(0), C_uint(abi::ivec_elt_elems),
C_int(0)]);
- auto on_heap =
- bcx.build.ICmp(lib::llvm::LLVMIntEQ, stack_len, C_int(0));
- auto on_heap_cx = new_sub_block_ctxt(bcx, "on_heap");
- auto next_cx = new_sub_block_ctxt(bcx, "next");
+ let on_heap = bcx.build.ICmp(lib::llvm::LLVMIntEQ, stack_len, C_int(0));
+ let on_heap_cx = new_sub_block_ctxt(bcx, "on_heap");
+ let next_cx = new_sub_block_ctxt(bcx, "next");
bcx.build.CondBr(on_heap, on_heap_cx.llbb, next_cx.llbb);
- auto heap_stub =
+ let heap_stub =
on_heap_cx.build.PointerCast(v, T_ptr(T_ivec_heap(llunitty)));
- auto heap_ptr = load_inbounds(on_heap_cx, heap_stub,
- ~[C_int(0),
- C_uint(abi::ivec_heap_stub_elt_ptr)]);
+ let heap_ptr =
+ load_inbounds(on_heap_cx, heap_stub,
+ ~[C_int(0), C_uint(abi::ivec_heap_stub_elt_ptr)]);
// Check whether the heap pointer is null. If it is, the vector length
// is truly zero.
- auto llstubty = T_ivec_heap(llunitty);
- auto llheapptrty = struct_elt(llstubty, abi::ivec_heap_stub_elt_ptr);
- auto heap_ptr_is_null =
+ let llstubty = T_ivec_heap(llunitty);
+ let llheapptrty = struct_elt(llstubty, abi::ivec_heap_stub_elt_ptr);
+ let heap_ptr_is_null =
on_heap_cx.build.ICmp(lib::llvm::LLVMIntEQ, heap_ptr,
C_null(T_ptr(llheapptrty)));
- auto zero_len_cx = new_sub_block_ctxt(bcx, "zero_len");
- auto nonzero_len_cx = new_sub_block_ctxt(bcx, "nonzero_len");
+ let zero_len_cx = new_sub_block_ctxt(bcx, "zero_len");
+ let nonzero_len_cx = new_sub_block_ctxt(bcx, "nonzero_len");
on_heap_cx.build.CondBr(heap_ptr_is_null, zero_len_cx.llbb,
nonzero_len_cx.llbb);
// Technically this context is unnecessary, but it makes this function
// clearer.
- auto zero_len = C_int(0);
- auto zero_elem = C_null(T_ptr(llunitty));
+ let zero_len = C_int(0);
+ let zero_elem = C_null(T_ptr(llunitty));
zero_len_cx.build.Br(next_cx.llbb);
// If we're here, then we actually have a heapified vector.
- auto heap_len = load_inbounds(nonzero_len_cx, heap_ptr,
- ~[C_int(0),
- C_uint(abi::ivec_heap_elt_len)]);
- auto heap_elem =
+ let heap_len =
+ load_inbounds(nonzero_len_cx, heap_ptr,
+ ~[C_int(0), C_uint(abi::ivec_heap_elt_len)]);
+ let heap_elem =
{
- auto v = ~[C_int(0), C_uint(abi::ivec_heap_elt_elems),
- C_int(0)];
- nonzero_len_cx.build.InBoundsGEP(heap_ptr,v)
+ let v = ~[C_int(0), C_uint(abi::ivec_heap_elt_elems), C_int(0)];
+ nonzero_len_cx.build.InBoundsGEP(heap_ptr, v)
};
nonzero_len_cx.build.Br(next_cx.llbb);
@@ -106,71 +102,75 @@
// Now we can figure out the length of |v| and get a pointer to its
// first element.
- auto len =
+ let len =
next_cx.build.Phi(T_int(), ~[stack_len, zero_len, heap_len],
- ~[bcx.llbb, zero_len_cx.llbb,
- nonzero_len_cx.llbb]);
- auto elem =
+ ~[bcx.llbb, zero_len_cx.llbb, nonzero_len_cx.llbb]);
+ let elem =
next_cx.build.Phi(T_ptr(llunitty),
~[stack_elem, zero_elem, heap_elem],
- ~[bcx.llbb, zero_len_cx.llbb,
- nonzero_len_cx.llbb]);
- ret rec(bcx=next_cx, len=len, data=elem);
+ ~[bcx.llbb, zero_len_cx.llbb, nonzero_len_cx.llbb]);
+ ret {bcx: next_cx, len: len, data: elem};
}
-fn trans_concat(&@block_ctxt cx, &dest in_dest, &span sp, ty::t t,
- &@ast::expr lhs, &@ast::expr rhs) -> @block_ctxt {
- auto bcx = cx;
+fn trans_concat(cx: &@block_ctxt, in_dest: &dest, sp: &span, t: ty::t,
+ lhs: &@ast::expr, rhs: &@ast::expr) -> @block_ctxt {
+ let bcx = cx;
// TODO: Detect "a = a + b" and promote to trans_append.
// TODO: Detect "a + [ literal ]" and optimize to copying the literal
// elements in directly.
- auto t = ty::expr_ty(bcx_tcx(bcx), lhs);
- auto skip_null = ty::type_is_str(bcx_tcx(bcx), t);
+ let t = ty::expr_ty(bcx_tcx(bcx), lhs);
+ let skip_null = ty::type_is_str(bcx_tcx(bcx), t);
// Translate the LHS and RHS. Pull out their length and data.
- auto lhs_tmp = trans_dps::dest_alias(bcx_tcx(bcx), t);
+ let lhs_tmp = trans_dps::dest_alias(bcx_tcx(bcx), t);
bcx = trans_dps::trans_expr(bcx, lhs_tmp, lhs);
- auto lllhsptr = trans_dps::dest_ptr(lhs_tmp);
+ let lllhsptr = trans_dps::dest_ptr(lhs_tmp);
- auto rhs_tmp = trans_dps::dest_alias(bcx_tcx(bcx), t);
+ let rhs_tmp = trans_dps::dest_alias(bcx_tcx(bcx), t);
bcx = trans_dps::trans_expr(bcx, rhs_tmp, rhs);
- auto llrhsptr = trans_dps::dest_ptr(rhs_tmp);
+ let llrhsptr = trans_dps::dest_ptr(rhs_tmp);
- auto r0 = get_len_and_data(bcx, t, lllhsptr);
- bcx = r0.bcx; auto lllhslen = r0.len; auto lllhsdata = r0.data;
+ let r0 = get_len_and_data(bcx, t, lllhsptr);
+ bcx = r0.bcx;
+ let lllhslen = r0.len;
+ let lllhsdata = r0.data;
r0 = get_len_and_data(bcx, t, llrhsptr);
- bcx = r0.bcx; auto llrhslen = r0.len; auto llrhsdata = r0.data;
+ bcx = r0.bcx;
+ let llrhslen = r0.len;
+ let llrhsdata = r0.data;
if skip_null { lllhslen = bcx.build.Sub(lllhslen, C_int(1)); }
// Allocate the destination.
- auto r1 = trans_dps::spill_alias(bcx, in_dest, t);
- bcx = r1.bcx; auto dest = r1.dest;
+ let r1 = trans_dps::spill_alias(bcx, in_dest, t);
+ bcx = r1.bcx;
+ let dest = r1.dest;
- auto unit_t = ty::sequence_element_type(bcx_tcx(bcx), t);
- auto unit_sz = trans_dps::size_of(bcx_ccx(bcx), sp, unit_t);
+ let unit_t = ty::sequence_element_type(bcx_tcx(bcx), t);
+ let unit_sz = trans_dps::size_of(bcx_ccx(bcx), sp, unit_t);
- auto stack_elems_sz = unit_sz * abi::ivec_default_length;
- auto lldestptr = trans_dps::dest_ptr(dest);
- auto llunitty = trans::type_of(bcx_ccx(bcx), sp, unit_t);
+ let stack_elems_sz = unit_sz * abi::ivec_default_length;
+ let lldestptr = trans_dps::dest_ptr(dest);
+ let llunitty = trans::type_of(bcx_ccx(bcx), sp, unit_t);
// Decide whether to allocate the result on the stack or on the heap.
- auto llnewlen = bcx.build.Add(lllhslen, llrhslen);
- auto llonstack = bcx.build.ICmp(lib::llvm::LLVMIntULE, llnewlen,
- C_uint(stack_elems_sz));
- auto on_stack_bcx = new_sub_block_ctxt(bcx, "on_stack");
- auto on_heap_bcx = new_sub_block_ctxt(bcx, "on_heap");
+ let llnewlen = bcx.build.Add(lllhslen, llrhslen);
+ let llonstack =
+ bcx.build.ICmp(lib::llvm::LLVMIntULE, llnewlen,
+ C_uint(stack_elems_sz));
+ let on_stack_bcx = new_sub_block_ctxt(bcx, "on_stack");
+ let on_heap_bcx = new_sub_block_ctxt(bcx, "on_heap");
bcx.build.CondBr(llonstack, on_stack_bcx.llbb, on_heap_bcx.llbb);
// On-stack case.
- auto next_bcx = new_sub_block_ctxt(bcx, "next");
+ let next_bcx = new_sub_block_ctxt(bcx, "next");
trans::store_inbounds(on_stack_bcx, llnewlen, lldestptr,
~[C_int(0), C_uint(abi::ivec_elt_len)]);
trans::store_inbounds(on_stack_bcx, C_uint(stack_elems_sz), lldestptr,
~[C_int(0), C_uint(abi::ivec_elt_alen)]);
- auto llonstackdataptr =
+ let llonstackdataptr =
on_stack_bcx.build.InBoundsGEP(lldestptr,
~[C_int(0),
C_uint(abi::ivec_elt_elems),
@@ -178,27 +178,26 @@
on_stack_bcx.build.Br(next_bcx.llbb);
// On-heap case.
- auto llheappartty = tc::T_ivec_heap(llunitty);
- auto lldeststubptr =
+ let llheappartty = tc::T_ivec_heap(llunitty);
+ let lldeststubptr =
on_heap_bcx.build.PointerCast(lldestptr, tc::T_ptr(llheappartty));
trans::store_inbounds(on_heap_bcx, C_int(0), lldeststubptr,
~[C_int(0), C_uint(abi::ivec_elt_len)]);
trans::store_inbounds(on_heap_bcx, llnewlen, lldeststubptr,
~[C_int(0), C_uint(abi::ivec_elt_alen)]);
- auto llheappartptrptr =
+ let llheappartptrptr =
on_heap_bcx.build.InBoundsGEP(lldeststubptr,
~[C_int(0),
C_uint(abi::ivec_elt_elems)]);
- auto llsizeofint = C_uint(llsize_of(bcx_ccx(bcx), tc::T_int()));
- on_heap_bcx = trans_dps::malloc(on_heap_bcx, llheappartptrptr,
- trans_dps::hp_shared,
- some(on_heap_bcx.build.Add(llnewlen,
- llsizeofint)));
- auto llheappartptr = on_heap_bcx.build.Load(llheappartptrptr);
+ let llsizeofint = C_uint(llsize_of(bcx_ccx(bcx), tc::T_int()));
+ on_heap_bcx =
+ trans_dps::malloc(on_heap_bcx, llheappartptrptr, trans_dps::hp_shared,
+ some(on_heap_bcx.build.Add(llnewlen, llsizeofint)));
+ let llheappartptr = on_heap_bcx.build.Load(llheappartptrptr);
trans::store_inbounds(on_heap_bcx, llnewlen, llheappartptr,
~[C_int(0), C_uint(abi::ivec_heap_elt_len)]);
- auto llheapdataptr =
+ let llheapdataptr =
on_heap_bcx.build.InBoundsGEP(llheappartptr,
~[C_int(0),
C_uint(abi::ivec_heap_elt_elems),
@@ -206,7 +205,7 @@
on_heap_bcx.build.Br(next_bcx.llbb);
// Perform the memmove.
- auto lldataptr =
+ let lldataptr =
next_bcx.build.Phi(T_ptr(llunitty),
~[llonstackdataptr, llheapdataptr],
~[on_stack_bcx.llbb, on_heap_bcx.llbb]);
diff --git a/src/comp/middle/tstate/ann.rs b/src/comp/middle/tstate/ann.rs
index 6a46603..f88d803 100644
--- a/src/comp/middle/tstate/ann.rs
+++ b/src/comp/middle/tstate/ann.rs
@@ -31,226 +31,216 @@
*/
/* named thus so as not to confuse with prestate and poststate */
-type pre_and_post = @rec(precond precondition, postcond postcondition);
+type pre_and_post = @{precondition: precond, postcondition: postcond};
/* FIXME: once it's implemented: */
// : ((*.precondition).nbits == (*.postcondition).nbits);
-type pre_and_post_state = rec(prestate prestate, poststate poststate);
+type pre_and_post_state = {prestate: prestate, poststate: poststate};
-type ts_ann = @rec(pre_and_post conditions, pre_and_post_state states);
+type ts_ann = @{conditions: pre_and_post, states: pre_and_post_state};
-fn true_precond(uint num_vars) -> precond {
- be create_tritv(num_vars);
-}
+fn true_precond(num_vars: uint) -> precond { be create_tritv(num_vars); }
-fn true_postcond(uint num_vars) -> postcond { be true_precond(num_vars); }
+fn true_postcond(num_vars: uint) -> postcond { be true_precond(num_vars); }
-fn empty_prestate(uint num_vars) -> prestate { be true_precond(num_vars); }
+fn empty_prestate(num_vars: uint) -> prestate { be true_precond(num_vars); }
-fn empty_poststate(uint num_vars) -> poststate { be true_precond(num_vars); }
+fn empty_poststate(num_vars: uint) -> poststate { be true_precond(num_vars); }
-fn false_postcond(uint num_vars) -> postcond {
- auto rslt = create_tritv(num_vars);
+fn false_postcond(num_vars: uint) -> postcond {
+ let rslt = create_tritv(num_vars);
tritv_set_all(rslt);
ret rslt;
}
-fn empty_pre_post(uint num_vars) -> pre_and_post {
- ret @rec(precondition=empty_prestate(num_vars),
- postcondition=empty_poststate(num_vars));
+fn empty_pre_post(num_vars: uint) -> pre_and_post {
+ ret @{precondition: empty_prestate(num_vars),
+ postcondition: empty_poststate(num_vars)};
}
-fn empty_states(uint num_vars) -> pre_and_post_state {
- ret rec(prestate=true_precond(num_vars),
- poststate=true_postcond(num_vars));
+fn empty_states(num_vars: uint) -> pre_and_post_state {
+ ret {prestate: true_precond(num_vars),
+ poststate: true_postcond(num_vars)};
}
-fn empty_ann(uint num_vars) -> ts_ann {
- ret @rec(conditions=empty_pre_post(num_vars),
- states=empty_states(num_vars));
+fn empty_ann(num_vars: uint) -> ts_ann {
+ ret @{conditions: empty_pre_post(num_vars),
+ states: empty_states(num_vars)};
}
-fn get_pre(&pre_and_post p) -> precond { ret p.precondition; }
+fn get_pre(p: &pre_and_post) -> precond { ret p.precondition; }
-fn get_post(&pre_and_post p) -> postcond { ret p.postcondition; }
+fn get_post(p: &pre_and_post) -> postcond { ret p.postcondition; }
-fn difference(&precond p1, &precond p2) -> bool {
+fn difference(p1: &precond, p2: &precond) -> bool {
ret tritv_difference(p1, p2);
}
-fn union(&precond p1, &precond p2) -> bool {
- ret tritv_union(p1, p2);
-}
+fn union(p1: &precond, p2: &precond) -> bool { ret tritv_union(p1, p2); }
-fn intersect(&precond p1, &precond p2) -> bool {
+fn intersect(p1: &precond, p2: &precond) -> bool {
ret tritv_intersect(p1, p2);
}
-fn pps_len(&pre_and_post p) -> uint {
+fn pps_len(p: &pre_and_post) -> uint {
// gratuitous check
assert (p.precondition.nbits == p.postcondition.nbits);
ret p.precondition.nbits;
}
-fn require(uint i, &pre_and_post p) {
+fn require(i: uint, p: &pre_and_post) {
// sets the ith bit in p's pre
tritv_set(i, p.precondition, ttrue);
}
-fn require_and_preserve(uint i, &pre_and_post p) {
+fn require_and_preserve(i: uint, p: &pre_and_post) {
// sets the ith bit in p's pre and post
tritv_set(i, p.precondition, ttrue);
tritv_set(i, p.postcondition, ttrue);
}
-fn set_in_postcond(uint i, &pre_and_post p) -> bool {
+fn set_in_postcond(i: uint, p: &pre_and_post) -> bool {
// sets the ith bit in p's post
ret set_in_postcond_(i, p.postcondition);
}
-fn set_in_postcond_(uint i, &postcond p) -> bool {
- auto was_set = tritv_get(p, i);
+fn set_in_postcond_(i: uint, p: &postcond) -> bool {
+ let was_set = tritv_get(p, i);
tritv_set(i, p, ttrue);
ret was_set != ttrue;
}
-fn set_in_poststate(uint i, &pre_and_post_state s) -> bool {
+fn set_in_poststate(i: uint, s: &pre_and_post_state) -> bool {
// sets the ith bit in p's post
ret set_in_poststate_(i, s.poststate);
}
-fn set_in_poststate_(uint i, &poststate p) -> bool {
- auto was_set = tritv_get(p, i);
+fn set_in_poststate_(i: uint, p: &poststate) -> bool {
+ let was_set = tritv_get(p, i);
tritv_set(i, p, ttrue);
ret was_set != ttrue;
}
-fn clear_in_poststate(uint i, &pre_and_post_state s) -> bool {
+fn clear_in_poststate(i: uint, s: &pre_and_post_state) -> bool {
// sets the ith bit in p's post
ret clear_in_poststate_(i, s.poststate);
}
-fn clear_in_poststate_(uint i, &poststate s) -> bool {
- auto was_set = tritv_get(s, i);
+fn clear_in_poststate_(i: uint, s: &poststate) -> bool {
+ let was_set = tritv_get(s, i);
tritv_set(i, s, tfalse);
ret was_set != tfalse;
}
-fn clear_in_prestate(uint i, &pre_and_post_state s) -> bool {
+fn clear_in_prestate(i: uint, s: &pre_and_post_state) -> bool {
// sets the ith bit in p's pre
ret clear_in_prestate_(i, s.prestate);
}
-fn clear_in_prestate_(uint i, &prestate s) -> bool {
- auto was_set = tritv_get(s, i);
+fn clear_in_prestate_(i: uint, s: &prestate) -> bool {
+ let was_set = tritv_get(s, i);
tritv_set(i, s, tfalse);
ret was_set != tfalse;
}
-fn clear_in_postcond(uint i, &pre_and_post s) -> bool {
+fn clear_in_postcond(i: uint, s: &pre_and_post) -> bool {
// sets the ith bit in p's post
- auto was_set = tritv_get(s.postcondition, i);
+ let was_set = tritv_get(s.postcondition, i);
tritv_set(i, s.postcondition, tfalse);
ret was_set != tfalse;
}
// Sets all the bits in a's precondition to equal the
// corresponding bit in p's precondition.
-fn set_precondition(ts_ann a, &precond p) {
+fn set_precondition(a: ts_ann, p: &precond) {
tritv_copy(a.conditions.precondition, p);
}
// Sets all the bits in a's postcondition to equal the
// corresponding bit in p's postcondition.
-fn set_postcondition(ts_ann a, &postcond p) {
+fn set_postcondition(a: ts_ann, p: &postcond) {
tritv_copy(a.conditions.postcondition, p);
}
// Sets all the bits in a's prestate to equal the
// corresponding bit in p's prestate.
-fn set_prestate(ts_ann a, &prestate p) -> bool {
+fn set_prestate(a: ts_ann, p: &prestate) -> bool {
ret tritv_copy(a.states.prestate, p);
}
// Sets all the bits in a's postcondition to equal the
// corresponding bit in p's postcondition.
-fn set_poststate(ts_ann a, &poststate p) -> bool {
+fn set_poststate(a: ts_ann, p: &poststate) -> bool {
ret tritv_copy(a.states.poststate, p);
}
// Set all the bits in p that are set in new
-fn extend_prestate(&prestate p, &poststate new) -> bool {
+fn extend_prestate(p: &prestate, new: &poststate) -> bool {
ret tritv_union(p, new);
}
// Set all the bits in p that are set in new
-fn extend_poststate(&poststate p, &poststate new) -> bool {
+fn extend_poststate(p: &poststate, new: &poststate) -> bool {
ret tritv_union(p, new);
}
// Sets the given bit in p to "don't care"
// FIXME: is this correct?
-fn relax_prestate(uint i, &prestate p) -> bool {
- auto was_set = tritv_get(p, i);
+fn relax_prestate(i: uint, p: &prestate) -> bool {
+ let was_set = tritv_get(p, i);
tritv_set(i, p, dont_care);
ret was_set != dont_care;
}
// Clears the given bit in p
-fn relax_poststate(uint i, &poststate p) -> bool {
+fn relax_poststate(i: uint, p: &poststate) -> bool {
ret relax_prestate(i, p);
}
// Clears the given bit in p
-fn relax_precond(uint i, &precond p) {
- relax_prestate(i, p);
-}
+fn relax_precond(i: uint, p: &precond) { relax_prestate(i, p); }
// Sets all the bits in p to "don't care"
-fn clear(&precond p) { tritv_clear(p); }
+fn clear(p: &precond) { tritv_clear(p); }
// Sets all the bits in p to true
-fn set(&precond p) { tritv_set_all(p); }
+fn set(p: &precond) { tritv_set_all(p); }
-fn ann_precond(&ts_ann a) -> precond { ret a.conditions.precondition; }
+fn ann_precond(a: &ts_ann) -> precond { ret a.conditions.precondition; }
-fn ann_prestate(&ts_ann a) -> prestate { ret a.states.prestate; }
+fn ann_prestate(a: &ts_ann) -> prestate { ret a.states.prestate; }
-fn ann_poststate(&ts_ann a) -> poststate { ret a.states.poststate; }
+fn ann_poststate(a: &ts_ann) -> poststate { ret a.states.poststate; }
-fn pp_clone(&pre_and_post p) -> pre_and_post {
- ret @rec(precondition=clone(p.precondition),
- postcondition=clone(p.postcondition));
+fn pp_clone(p: &pre_and_post) -> pre_and_post {
+ ret @{precondition: clone(p.precondition),
+ postcondition: clone(p.postcondition)};
}
-fn clone(prestate p) -> prestate { ret tritv_clone(p); }
+fn clone(p: prestate) -> prestate { ret tritv_clone(p); }
// returns true if a implies b
// that is, returns true except if for some bits c and d,
// c = 1 and d = either 0 or "don't know"
// FIXME: is this correct?
-fn implies(t a, t b) -> bool {
- auto tmp = tritv_clone(b);
+fn implies(a: t, b: t) -> bool {
+ let tmp = tritv_clone(b);
tritv_difference(tmp, a);
ret tritv_doesntcare(tmp);
}
-fn trit_str(trit t) -> str {
- alt (t) {
- case (dont_care) { "?" }
- case (ttrue) { "1" }
- case (tfalse) { "0" }
- }
+fn trit_str(t: trit) -> str {
+ alt t { dont_care. { "?" } ttrue. { "1" } tfalse. { "0" } }
}
//
// Local Variables:
diff --git a/src/comp/middle/tstate/annotate.rs b/src/comp/middle/tstate/annotate.rs
index 22be906..03f5f2d 100644
--- a/src/comp/middle/tstate/annotate.rs
+++ b/src/comp/middle/tstate/annotate.rs
@@ -23,70 +23,67 @@
import aux::add_node;
import middle::tstate::ann::empty_ann;
-fn collect_ids_expr(&@expr e, @mutable node_id[] rs) {
- *rs += ~[e.id];
-}
+fn collect_ids_expr(e: &@expr, rs: @mutable node_id[]) { *rs += ~[e.id]; }
-fn collect_ids_block(&blk b, @mutable node_id[] rs) {
- *rs += ~[b.node.id];
-}
+fn collect_ids_block(b: &blk, rs: @mutable node_id[]) { *rs += ~[b.node.id]; }
-fn collect_ids_stmt(&@stmt s, @mutable node_id[] rs) {
- alt (s.node) {
- case (stmt_decl(_, ?id)) {
- log "node_id " + int::str(id);
- log_stmt(*s);
- *rs += ~[id];
- }
- case (stmt_expr(_, ?id)) {
- log "node_id " + int::str(id);
- log_stmt(*s);
- *rs += ~[id];
- }
- case (_) { }
+fn collect_ids_stmt(s: &@stmt, rs: @mutable node_id[]) {
+ alt s.node {
+ stmt_decl(_, id) {
+ log "node_id " + int::str(id);
+ log_stmt(*s);
+ *rs += ~[id];
+ }
+ stmt_expr(_, id) {
+ log "node_id " + int::str(id);
+ log_stmt(*s);
+ *rs += ~[id];
+ }
+ _ { }
}
}
-fn collect_ids_local(&@local l, @mutable node_id[] rs) {
+fn collect_ids_local(l: &@local, rs: @mutable node_id[]) {
*rs += ~[l.node.id];
}
-fn node_ids_in_fn(&_fn f, &ty_param[] tps, &span sp, &fn_ident i,
- node_id id, @mutable node_id[] rs) {
- auto collect_ids = visit::mk_simple_visitor
- (@rec(visit_expr=bind collect_ids_expr(_, rs),
- visit_block=bind collect_ids_block(_, rs),
- visit_stmt=bind collect_ids_stmt(_, rs),
- visit_local=bind collect_ids_local(_, rs)
- with *visit::default_simple_visitor()));
+fn node_ids_in_fn(f: &_fn, tps: &ty_param[], sp: &span, i: &fn_ident,
+ id: node_id, rs: @mutable node_id[]) {
+ let collect_ids =
+ visit::mk_simple_visitor(@{visit_expr: bind collect_ids_expr(_, rs),
+ visit_block: bind collect_ids_block(_, rs),
+ visit_stmt: bind collect_ids_stmt(_, rs),
+ visit_local: bind collect_ids_local(_, rs)
+ with *visit::default_simple_visitor()});
visit::visit_fn(f, tps, sp, i, id, (), collect_ids);
}
-fn init_vecs(&crate_ctxt ccx, &node_id[] node_ids, uint len) {
- for (node_id i in node_ids) {
+fn init_vecs(ccx: &crate_ctxt, node_ids: &node_id[], len: uint) {
+ for i: node_id in node_ids {
log int::str(i) + " |-> " + uint::str(len);
add_node(ccx, i, empty_ann(len));
}
}
-fn visit_fn(&crate_ctxt ccx, uint num_constraints, &_fn f, &ty_param[] tps,
- &span sp, &fn_ident i, node_id id) {
- let @mutable node_id[] node_ids = @mutable ~[];
+fn visit_fn(ccx: &crate_ctxt, num_constraints: uint, f: &_fn,
+ tps: &ty_param[], sp: &span, i: &fn_ident, id: node_id) {
+ let node_ids: @mutable node_id[] = @mutable ~[];
node_ids_in_fn(f, tps, sp, i, id, node_ids);
- auto node_id_vec = *node_ids;
+ let node_id_vec = *node_ids;
init_vecs(ccx, node_id_vec, num_constraints);
}
-fn annotate_in_fn(&crate_ctxt ccx, &_fn f, &ty_param[] tps,
- &span sp, &fn_ident i, node_id id) {
- auto f_info = get_fn_info(ccx, id);
+fn annotate_in_fn(ccx: &crate_ctxt, f: &_fn, tps: &ty_param[], sp: &span,
+ i: &fn_ident, id: node_id) {
+ let f_info = get_fn_info(ccx, id);
visit_fn(ccx, num_constraints(f_info), f, tps, sp, i, id);
}
-fn annotate_crate(&crate_ctxt ccx, &crate crate) {
- auto do_ann = visit::mk_simple_visitor
- (@rec(visit_fn=bind annotate_in_fn(ccx, _, _, _, _, _)
- with *visit::default_simple_visitor()));
+fn annotate_crate(ccx: &crate_ctxt, crate: &crate) {
+ let do_ann =
+ visit::mk_simple_visitor(@{visit_fn:
+ bind annotate_in_fn(ccx, _, _, _, _, _)
+ with *visit::default_simple_visitor()});
visit::visit_crate(crate, (), do_ann);
}
//
diff --git a/src/comp/middle/tstate/auxiliary.rs b/src/comp/middle/tstate/auxiliary.rs
index e129fda..44eaa53 100644
--- a/src/comp/middle/tstate/auxiliary.rs
+++ b/src/comp/middle/tstate/auxiliary.rs
@@ -54,121 +54,123 @@
}
/* logging funs */
-fn def_id_to_str(def_id d) -> str {
+fn def_id_to_str(d: def_id) -> str {
ret int::str(d.crate) + "," + int::str(d.node);
}
-fn comma_str(&(@constr_arg_use)[] args) -> str {
- auto rslt = "";
- auto comma = false;
- for (@constr_arg_use a in args) {
- if (comma) { rslt += ", "; } else { comma = true; }
- alt (a.node) {
- case (carg_base) { rslt += "*"; }
- case (carg_ident(?i)) { rslt += i.ident; }
- case (carg_lit(?l)) { rslt += lit_to_str(l); }
+fn comma_str(args: &(@constr_arg_use)[]) -> str {
+ let rslt = "";
+ let comma = false;
+ for a: @constr_arg_use in args {
+ if comma { rslt += ", "; } else { comma = true; }
+ alt a.node {
+ carg_base. { rslt += "*"; }
+ carg_ident(i) { rslt += i.ident; }
+ carg_lit(l) { rslt += lit_to_str(l); }
}
}
ret rslt;
}
-fn constraint_to_str(&ty::ctxt tcx, &sp_constr c) -> str {
- alt (c.node) {
- case (ninit(_,?i)) {
- ret "init(" + i + " [" + tcx.sess.span_str(c.span) + "])";
- }
- case (npred(?p, _, ?args)) {
- ret path_to_str(p) + "(" + comma_str(args) + ")" + "[" +
- tcx.sess.span_str(c.span) + "]";
- }
+fn constraint_to_str(tcx: &ty::ctxt, c: &sp_constr) -> str {
+ alt c.node {
+ ninit(_, i) {
+ ret "init(" + i + " [" + tcx.sess.span_str(c.span) + "])";
+ }
+ npred(p, _, args) {
+ ret path_to_str(p) + "(" + comma_str(args) + ")" + "[" +
+ tcx.sess.span_str(c.span) + "]";
+ }
}
}
-fn tritv_to_str(fn_ctxt fcx, &tritv::t v) -> str {
- auto s = "";
- auto comma = false;
- for (norm_constraint p in constraints(fcx)) {
- alt (tritv_get(v, p.bit_num)) {
- case (dont_care) { }
- case (?t) {
- s +=
- if (comma) { ", " } else { comma = true; "" } +
- if (t == tfalse) { "!" } else { "" } +
+fn tritv_to_str(fcx: fn_ctxt, v: &tritv::t) -> str {
+ let s = "";
+ let comma = false;
+ for p: norm_constraint in constraints(fcx) {
+ alt tritv_get(v, p.bit_num) {
+ dont_care. { }
+ t {
+ s +=
+ if comma { ", " } else { comma = true; "" } +
+ if t == tfalse { "!" } else { "" } +
constraint_to_str(fcx.ccx.tcx, p.c);
- }
+ }
}
}
ret s;
}
-fn log_tritv(&fn_ctxt fcx, &tritv::t v) { log tritv_to_str(fcx, v); }
+fn log_tritv(fcx: &fn_ctxt, v: &tritv::t) { log tritv_to_str(fcx, v); }
-fn first_difference_string(&fn_ctxt fcx, &tritv::t expected, &tritv::t actual)
- -> str {
- let str s = "";
- for (norm_constraint c in constraints(fcx)) {
- if (tritv_get(expected, c.bit_num) == ttrue &&
- tritv_get(actual, c.bit_num) != ttrue) {
+fn first_difference_string(fcx: &fn_ctxt, expected: &tritv::t,
+ actual: &tritv::t) -> str {
+ let s: str = "";
+ for c: norm_constraint in constraints(fcx) {
+ if tritv_get(expected, c.bit_num) == ttrue &&
+ tritv_get(actual, c.bit_num) != ttrue {
ret constraint_to_str(fcx.ccx.tcx, c.c);
}
}
ret s;
}
-fn log_tritv_err(fn_ctxt fcx, tritv::t v) { log_err tritv_to_str(fcx, v); }
+fn log_tritv_err(fcx: fn_ctxt, v: tritv::t) { log_err tritv_to_str(fcx, v); }
-fn tos(&uint[] v) -> str {
- auto rslt = "";
- for (uint i in v) { if (i == 0u) { rslt += "0"; }
- else if (i == 1u) { rslt += "1"; }
- else { rslt += "?"; } }
+fn tos(v: &uint[]) -> str {
+ let rslt = "";
+ for i: uint in v {
+ if i == 0u {
+ rslt += "0";
+ } else if (i == 1u) { rslt += "1"; } else { rslt += "?"; }
+ }
ret rslt;
}
-fn log_cond(&uint[] v) { log tos(v); }
+fn log_cond(v: &uint[]) { log tos(v); }
-fn log_cond_err(&uint[] v) { log_err tos(v); }
+fn log_cond_err(v: &uint[]) { log_err tos(v); }
-fn log_pp(&pre_and_post pp) {
- auto p1 = tritv::to_vec(pp.precondition);
- auto p2 = tritv::to_vec(pp.postcondition);
+fn log_pp(pp: &pre_and_post) {
+ let p1 = tritv::to_vec(pp.precondition);
+ let p2 = tritv::to_vec(pp.postcondition);
log "pre:";
log_cond(p1);
log "post:";
log_cond(p2);
}
-fn log_pp_err(&pre_and_post pp) {
- auto p1 = tritv::to_vec(pp.precondition);
- auto p2 = tritv::to_vec(pp.postcondition);
+fn log_pp_err(pp: &pre_and_post) {
+ let p1 = tritv::to_vec(pp.precondition);
+ let p2 = tritv::to_vec(pp.postcondition);
log_err "pre:";
log_cond_err(p1);
log_err "post:";
log_cond_err(p2);
}
-fn log_states(&pre_and_post_state pp) {
- auto p1 = tritv::to_vec(pp.prestate);
- auto p2 = tritv::to_vec(pp.poststate);
+fn log_states(pp: &pre_and_post_state) {
+ let p1 = tritv::to_vec(pp.prestate);
+ let p2 = tritv::to_vec(pp.poststate);
log "prestate:";
log_cond(p1);
log "poststate:";
log_cond(p2);
}
-fn log_states_err(&pre_and_post_state pp) {
- auto p1 = tritv::to_vec(pp.prestate);
- auto p2 = tritv::to_vec(pp.poststate);
+fn log_states_err(pp: &pre_and_post_state) {
+ let p1 = tritv::to_vec(pp.prestate);
+ let p2 = tritv::to_vec(pp.poststate);
log_err "prestate:";
log_cond_err(p1);
log_err "poststate:";
log_cond_err(p2);
}
-fn print_ident(&ident i) { log " " + i + " "; }
+fn print_ident(i: &ident) { log " " + i + " "; }
-fn print_idents(&mutable ident[] idents) {
- if (ivec::len[ident](idents) == 0u) { ret; }
+fn print_idents(idents: &mutable ident[]) {
+ if ivec::len[ident](idents) == 0u { ret; }
log "an ident: " + ivec::pop[ident](idents);
print_idents(idents);
}
@@ -204,7 +206,7 @@
Both types store an ident and span, for error-logging purposes.
*/
-type pred_args_ = rec((@constr_arg_use)[] args, uint bit_num);
+type pred_args_ = {args: (@constr_arg_use)[], bit_num: uint};
type pred_args = spanned[pred_args_];
@@ -214,9 +216,10 @@
tag constraint {
cinit(uint, span, ident);
+
// FIXME: really only want it to be mutable during collect_locals.
// freeze it after that.
- cpred(path, @mutable (pred_args[]));
+ cpred(path, @mutable pred_args[]);
}
// An ninit variant has a node_id because it refers to a local var.
@@ -231,308 +234,307 @@
type sp_constr = spanned[tsconstr];
-type norm_constraint = rec(uint bit_num, sp_constr c);
+type norm_constraint = {bit_num: uint, c: sp_constr};
type constr_map = @std::map::hashmap[def_id, constraint];
-type fn_info = rec(constr_map constrs,
- uint num_constraints,
- controlflow cf,
- /* list, accumulated during pre/postcondition
- computation, of all local variables that may be
- used*/
- // Doesn't seem to work without the @ --
- // bug?
- @mutable node_id[] used_vars);
+type fn_info =
+ /* list, accumulated during pre/postcondition
+ computation, of all local variables that may be
+ used*/
+ // Doesn't seem to work without the @ --
+ // bug?
+ {constrs: constr_map,
+ num_constraints: uint,
+ cf: controlflow,
+ used_vars: @mutable node_id[]};
-fn tsconstr_to_def_id(&tsconstr t) -> def_id {
- alt (t) {
- case (ninit(?id,_)) { local_def(id) }
- case (npred(_,?id,_)) { id }
- }
+fn tsconstr_to_def_id(t: &tsconstr) -> def_id {
+ alt t { ninit(id, _) { local_def(id) } npred(_, id, _) { id } }
}
/* mapping from node ID to typestate annotation */
-type node_ann_table = @mutable ts_ann[mutable];
+type node_ann_table = @mutable ts_ann[mutable ];
/* mapping from function name to fn_info map */
type fn_info_map = @std::map::hashmap[node_id, fn_info];
-type fn_ctxt = rec(fn_info enclosing, node_id id, ident name, crate_ctxt ccx);
+type fn_ctxt =
+ {enclosing: fn_info, id: node_id, name: ident, ccx: crate_ctxt};
-type crate_ctxt = rec(ty::ctxt tcx, node_ann_table node_anns, fn_info_map fm);
+type crate_ctxt = {tcx: ty::ctxt, node_anns: node_ann_table, fm: fn_info_map};
-fn get_fn_info(&crate_ctxt ccx, node_id id) -> fn_info {
+fn get_fn_info(ccx: &crate_ctxt, id: node_id) -> fn_info {
assert (ccx.fm.contains_key(id));
ret ccx.fm.get(id);
}
-fn add_node(&crate_ctxt ccx, node_id i, &ts_ann a) {
- auto sz = ivec::len(*ccx.node_anns);
- if (sz <= i as uint) {
+fn add_node(ccx: &crate_ctxt, i: node_id, a: &ts_ann) {
+ let sz = ivec::len(*ccx.node_anns);
+ if sz <= i as uint {
ivec::grow_mut(*ccx.node_anns, (i as uint) - sz + 1u, empty_ann(0u));
}
ccx.node_anns.(i) = a;
}
-fn get_ts_ann(&crate_ctxt ccx, node_id i) -> option::t[ts_ann] {
- if (i as uint < ivec::len(*ccx.node_anns)) {
+fn get_ts_ann(ccx: &crate_ctxt, i: node_id) -> option::t[ts_ann] {
+ if i as uint < ivec::len(*ccx.node_anns) {
ret some[ts_ann](ccx.node_anns.(i));
} else { ret none[ts_ann]; }
}
/********* utils ********/
-fn node_id_to_ts_ann(&crate_ctxt ccx, node_id id) -> ts_ann {
- alt (get_ts_ann(ccx, id)) {
- case (none) {
- log_err "node_id_to_ts_ann: no ts_ann for node_id " +
- int::str(id);
- fail;
- }
- case (some(?t)) { ret t; }
+fn node_id_to_ts_ann(ccx: &crate_ctxt, id: node_id) -> ts_ann {
+ alt get_ts_ann(ccx, id) {
+ none. {
+ log_err "node_id_to_ts_ann: no ts_ann for node_id " + int::str(id);
+ fail;
+ }
+ some(t) { ret t; }
}
}
-fn node_id_to_poststate(&crate_ctxt ccx, node_id id) -> poststate {
+fn node_id_to_poststate(ccx: &crate_ctxt, id: node_id) -> poststate {
log "node_id_to_poststate";
ret node_id_to_ts_ann(ccx, id).states.poststate;
}
-fn stmt_to_ann(&crate_ctxt ccx, &stmt s) -> ts_ann {
+fn stmt_to_ann(ccx: &crate_ctxt, s: &stmt) -> ts_ann {
log "stmt_to_ann";
- alt (s.node) {
- case (stmt_decl(_, ?id)) { ret node_id_to_ts_ann(ccx, id); }
- case (stmt_expr(_, ?id)) { ret node_id_to_ts_ann(ccx, id); }
- case (stmt_crate_directive(_)) {
- log_err "expecting an annotated statement here";
- fail;
- }
+ alt s.node {
+ stmt_decl(_, id) { ret node_id_to_ts_ann(ccx, id); }
+ stmt_expr(_, id) { ret node_id_to_ts_ann(ccx, id); }
+ stmt_crate_directive(_) {
+ log_err "expecting an annotated statement here";
+ fail;
+ }
}
}
/* fails if e has no annotation */
-fn expr_states(&crate_ctxt ccx, @expr e) -> pre_and_post_state {
+fn expr_states(ccx: &crate_ctxt, e: @expr) -> pre_and_post_state {
log "expr_states";
ret node_id_to_ts_ann(ccx, e.id).states;
}
/* fails if e has no annotation */
-fn expr_pp(&crate_ctxt ccx, @expr e) -> pre_and_post {
+fn expr_pp(ccx: &crate_ctxt, e: @expr) -> pre_and_post {
log "expr_pp";
ret node_id_to_ts_ann(ccx, e.id).conditions;
}
-fn stmt_pp(&crate_ctxt ccx, &stmt s) -> pre_and_post {
+fn stmt_pp(ccx: &crate_ctxt, s: &stmt) -> pre_and_post {
ret stmt_to_ann(ccx, s).conditions;
}
/* fails if b has no annotation */
-fn block_pp(&crate_ctxt ccx, &blk b) -> pre_and_post {
+fn block_pp(ccx: &crate_ctxt, b: &blk) -> pre_and_post {
log "block_pp";
ret node_id_to_ts_ann(ccx, b.node.id).conditions;
}
-fn clear_pp(pre_and_post pp) {
+fn clear_pp(pp: pre_and_post) {
ann::clear(pp.precondition);
ann::clear(pp.postcondition);
}
-fn clear_precond(&crate_ctxt ccx, node_id id) {
- auto pp = node_id_to_ts_ann(ccx, id);
+fn clear_precond(ccx: &crate_ctxt, id: node_id) {
+ let pp = node_id_to_ts_ann(ccx, id);
ann::clear(pp.conditions.precondition);
}
-fn block_states(&crate_ctxt ccx, &blk b) -> pre_and_post_state {
+fn block_states(ccx: &crate_ctxt, b: &blk) -> pre_and_post_state {
log "block_states";
ret node_id_to_ts_ann(ccx, b.node.id).states;
}
-fn stmt_states(&crate_ctxt ccx, &stmt s) -> pre_and_post_state {
+fn stmt_states(ccx: &crate_ctxt, s: &stmt) -> pre_and_post_state {
ret stmt_to_ann(ccx, s).states;
}
-fn expr_precond(&crate_ctxt ccx, @expr e) -> precond {
+fn expr_precond(ccx: &crate_ctxt, e: @expr) -> precond {
ret expr_pp(ccx, e).precondition;
}
-fn expr_postcond(&crate_ctxt ccx, @expr e) -> postcond {
+fn expr_postcond(ccx: &crate_ctxt, e: @expr) -> postcond {
ret expr_pp(ccx, e).postcondition;
}
-fn expr_prestate(&crate_ctxt ccx, @expr e) -> prestate {
+fn expr_prestate(ccx: &crate_ctxt, e: @expr) -> prestate {
ret expr_states(ccx, e).prestate;
}
-fn expr_poststate(&crate_ctxt ccx, @expr e) -> poststate {
+fn expr_poststate(ccx: &crate_ctxt, e: @expr) -> poststate {
ret expr_states(ccx, e).poststate;
}
-fn stmt_precond(&crate_ctxt ccx, &stmt s) -> precond {
+fn stmt_precond(ccx: &crate_ctxt, s: &stmt) -> precond {
ret stmt_pp(ccx, s).precondition;
}
-fn stmt_postcond(&crate_ctxt ccx, &stmt s) -> postcond {
+fn stmt_postcond(ccx: &crate_ctxt, s: &stmt) -> postcond {
ret stmt_pp(ccx, s).postcondition;
}
-fn states_to_poststate(&pre_and_post_state ss) -> poststate {
+fn states_to_poststate(ss: &pre_and_post_state) -> poststate {
ret ss.poststate;
}
-fn stmt_prestate(&crate_ctxt ccx, &stmt s) -> prestate {
+fn stmt_prestate(ccx: &crate_ctxt, s: &stmt) -> prestate {
ret stmt_states(ccx, s).prestate;
}
-fn stmt_poststate(&crate_ctxt ccx, &stmt s) -> poststate {
+fn stmt_poststate(ccx: &crate_ctxt, s: &stmt) -> poststate {
ret stmt_states(ccx, s).poststate;
}
-fn block_precond(&crate_ctxt ccx, &blk b) -> precond {
+fn block_precond(ccx: &crate_ctxt, b: &blk) -> precond {
ret block_pp(ccx, b).precondition;
}
-fn block_postcond(&crate_ctxt ccx, &blk b) -> postcond {
+fn block_postcond(ccx: &crate_ctxt, b: &blk) -> postcond {
ret block_pp(ccx, b).postcondition;
}
-fn block_prestate(&crate_ctxt ccx, &blk b) -> prestate {
+fn block_prestate(ccx: &crate_ctxt, b: &blk) -> prestate {
ret block_states(ccx, b).prestate;
}
-fn block_poststate(&crate_ctxt ccx, &blk b) -> poststate {
+fn block_poststate(ccx: &crate_ctxt, b: &blk) -> poststate {
ret block_states(ccx, b).poststate;
}
-fn set_prestate_ann(&crate_ctxt ccx, node_id id, &prestate pre) -> bool {
+fn set_prestate_ann(ccx: &crate_ctxt, id: node_id, pre: &prestate) -> bool {
log "set_prestate_ann";
ret set_prestate(node_id_to_ts_ann(ccx, id), pre);
}
-fn extend_prestate_ann(&crate_ctxt ccx, node_id id, &prestate pre) -> bool {
+fn extend_prestate_ann(ccx: &crate_ctxt, id: node_id, pre: &prestate) ->
+ bool {
log "extend_prestate_ann";
ret extend_prestate(node_id_to_ts_ann(ccx, id).states.prestate, pre);
}
-fn set_poststate_ann(&crate_ctxt ccx, node_id id, &poststate post) -> bool {
+fn set_poststate_ann(ccx: &crate_ctxt, id: node_id, post: &poststate) ->
+ bool {
log "set_poststate_ann";
ret set_poststate(node_id_to_ts_ann(ccx, id), post);
}
-fn extend_poststate_ann(&crate_ctxt ccx, node_id id, &poststate post)
- -> bool {
+fn extend_poststate_ann(ccx: &crate_ctxt, id: node_id, post: &poststate) ->
+ bool {
log "extend_poststate_ann";
ret extend_poststate(node_id_to_ts_ann(ccx, id).states.poststate, post);
}
-fn set_pre_and_post(&crate_ctxt ccx, node_id id, &precond pre,
- &postcond post) {
+fn set_pre_and_post(ccx: &crate_ctxt, id: node_id, pre: &precond,
+ post: &postcond) {
log "set_pre_and_post";
- auto t = node_id_to_ts_ann(ccx, id);
+ let t = node_id_to_ts_ann(ccx, id);
set_precondition(t, pre);
set_postcondition(t, post);
}
-fn copy_pre_post(&crate_ctxt ccx, node_id id, &@expr sub) {
+fn copy_pre_post(ccx: &crate_ctxt, id: node_id, sub: &@expr) {
log "set_pre_and_post";
- auto p = expr_pp(ccx, sub);
+ let p = expr_pp(ccx, sub);
copy_pre_post_(ccx, id, p.precondition, p.postcondition);
}
-fn copy_pre_post_(&crate_ctxt ccx, node_id id, &prestate pre,
- &poststate post) {
+fn copy_pre_post_(ccx: &crate_ctxt, id: node_id, pre: &prestate,
+ post: &poststate) {
log "set_pre_and_post";
- auto t = node_id_to_ts_ann(ccx, id);
+ let t = node_id_to_ts_ann(ccx, id);
set_precondition(t, pre);
set_postcondition(t, post);
}
/* sets all bits to *1* */
-fn set_postcond_false(&crate_ctxt ccx, node_id id) {
- auto p = node_id_to_ts_ann(ccx, id);
+fn set_postcond_false(ccx: &crate_ctxt, id: node_id) {
+ let p = node_id_to_ts_ann(ccx, id);
ann::set(p.conditions.postcondition);
}
-fn pure_exp(&crate_ctxt ccx, node_id id, &prestate p) -> bool {
- ret set_prestate_ann(ccx, id, p) |
- set_poststate_ann(ccx, id, p);
+fn pure_exp(ccx: &crate_ctxt, id: node_id, p: &prestate) -> bool {
+ ret set_prestate_ann(ccx, id, p) | set_poststate_ann(ccx, id, p);
}
-fn num_constraints(fn_info m) -> uint { ret m.num_constraints; }
+fn num_constraints(m: fn_info) -> uint { ret m.num_constraints; }
-fn new_crate_ctxt(ty::ctxt cx) -> crate_ctxt {
- let ts_ann[mutable] na = ~[mutable];
- ret rec(tcx=cx, node_anns=@mutable na, fm=@new_int_hash[fn_info]());
+fn new_crate_ctxt(cx: ty::ctxt) -> crate_ctxt {
+ let na: ts_ann[mutable ] = ~[mutable ];
+ ret {tcx: cx, node_anns: @mutable na, fm: @new_int_hash[fn_info]()};
}
/* Use e's type to determine whether it returns.
If it has a function type with a ! annotation,
the answer is noreturn. */
-fn controlflow_expr(&crate_ctxt ccx, @expr e) -> controlflow {
- alt (ty::struct(ccx.tcx, ty::node_id_to_type(ccx.tcx, e.id))) {
- case (ty::ty_fn(_, _, _, ?cf, _)) { ret cf; }
- case (_) { ret return; }
+fn controlflow_expr(ccx: &crate_ctxt, e: @expr) -> controlflow {
+ alt ty::struct(ccx.tcx, ty::node_id_to_type(ccx.tcx, e.id)) {
+ ty::ty_fn(_, _, _, cf, _) { ret cf; }
+ _ { ret return; }
}
}
-fn constraints_expr(&ty::ctxt cx, @expr e) -> (@ty::constr)[] {
- alt (ty::struct(cx, ty::node_id_to_type(cx, e.id))) {
- case (ty::ty_fn(_, _, _, _, ?cs)) { ret cs; }
- case (_) { ret ~[]; }
+fn constraints_expr(cx: &ty::ctxt, e: @expr) -> (@ty::constr)[] {
+ alt ty::struct(cx, ty::node_id_to_type(cx, e.id)) {
+ ty::ty_fn(_, _, _, _, cs) { ret cs; }
+ _ { ret ~[]; }
}
}
-fn node_id_to_def_upvar_strict(&fn_ctxt cx, node_id id) -> def {
- alt (freevars::def_lookup(cx.ccx.tcx, cx.id, id)) {
- case (none) {
- log_err "node_id_to_def: node_id " + int::str(id) + " has no def";
- fail;
- }
- case (some(?d)) { ret d; }
+fn node_id_to_def_upvar_strict(cx: &fn_ctxt, id: node_id) -> def {
+ alt freevars::def_lookup(cx.ccx.tcx, cx.id, id) {
+ none. {
+ log_err "node_id_to_def: node_id " + int::str(id) + " has no def";
+ fail;
+ }
+ some(d) { ret d; }
}
}
-fn node_id_to_def_strict(&ty::ctxt cx, node_id id) -> def {
- alt (cx.def_map.find(id)) {
- case (none) {
- log_err "node_id_to_def: node_id " + int::str(id) + " has no def";
- fail;
- }
- case (some(?d)) { ret d; }
+fn node_id_to_def_strict(cx: &ty::ctxt, id: node_id) -> def {
+ alt cx.def_map.find(id) {
+ none. {
+ log_err "node_id_to_def: node_id " + int::str(id) + " has no def";
+ fail;
+ }
+ some(d) { ret d; }
}
}
-fn node_id_to_def(&crate_ctxt ccx, node_id id) -> option::t[def] {
+fn node_id_to_def(ccx: &crate_ctxt, id: node_id) -> option::t[def] {
ret ccx.tcx.def_map.find(id);
}
-fn norm_a_constraint(def_id id, &constraint c) -> norm_constraint[] {
- alt (c) {
- case (cinit(?n, ?sp, ?i)) {
- ret ~[rec(bit_num=n, c=respan(sp, ninit(id.node, i)))];
+fn norm_a_constraint(id: def_id, c: &constraint) -> norm_constraint[] {
+ alt c {
+ cinit(n, sp, i) {
+ ret ~[{bit_num: n, c: respan(sp, ninit(id.node, i))}];
+ }
+ cpred(p, descs) {
+ let rslt: norm_constraint[] = ~[];
+ for pd: pred_args in *descs {
+ rslt +=
+ ~[{bit_num: pd.node.bit_num,
+ c: respan(pd.span, npred(p, id, pd.node.args))}];
}
- case (cpred(?p, ?descs)) {
- let norm_constraint[] rslt = ~[];
- for (pred_args pd in *descs) {
- rslt += ~[rec(bit_num=pd.node.bit_num,
- c=respan(pd.span,
- npred(p, id, pd.node.args)))];
- }
- ret rslt;
- }
+ ret rslt;
+ }
}
}
// Tried to write this as an iterator, but I got a
// non-exhaustive match in trans.
-fn constraints(&fn_ctxt fcx) -> norm_constraint[] {
- let norm_constraint[] rslt = ~[];
- for each (@rec(def_id key, constraint val) p
- in fcx.enclosing.constrs.items()) {
+fn constraints(fcx: &fn_ctxt) -> norm_constraint[] {
+ let rslt: norm_constraint[] = ~[];
+ for each p: @{key: def_id, val: constraint} in
+ fcx.enclosing.constrs.items() {
rslt += norm_a_constraint(p.key, p.val);
}
ret rslt;
@@ -541,254 +543,225 @@
// FIXME
// Would rather take an immutable vec as an argument,
// should freeze it at some earlier point.
-fn match_args(&fn_ctxt fcx, &(@mutable pred_args[]) occs,
- &(@constr_arg_use)[] occ) ->
- uint {
+fn match_args(fcx: &fn_ctxt, occs: &@mutable pred_args[],
+ occ: &(@constr_arg_use)[]) -> uint {
log "match_args: looking at " +
- constr_args_to_str(fn(&inst i) -> str { ret i.ident; }, occ);
- for (pred_args pd in *occs) {
+ constr_args_to_str(fn (i: &inst) -> str { ret i.ident; }, occ);
+ for pd: pred_args in *occs {
log "match_args: candidate " + pred_args_to_str(pd);
- fn eq(&inst p, &inst q) -> bool {
- ret p.node == q.node;
- }
- if (ty::args_eq(eq, pd.node.args, occ)) { ret pd.node.bit_num; }
+ fn eq(p: &inst, q: &inst) -> bool { ret p.node == q.node; }
+ if ty::args_eq(eq, pd.node.args, occ) { ret pd.node.bit_num; }
}
fcx.ccx.tcx.sess.bug("match_args: no match for occurring args");
}
-fn def_id_for_constr(ty::ctxt tcx, node_id t) -> def_id {
- alt (tcx.def_map.find(t)) {
- case (none) {
- tcx.sess.bug("node_id_for_constr: bad node_id " + int::str(t));
- }
- case (some(def_fn(?i,_))) { ret i; }
- case (_) {
- tcx.sess.bug("node_id_for_constr: pred is not a function");
- }
+fn def_id_for_constr(tcx: ty::ctxt, t: node_id) -> def_id {
+ alt tcx.def_map.find(t) {
+ none. {
+ tcx.sess.bug("node_id_for_constr: bad node_id " + int::str(t));
+ }
+ some(def_fn(i, _)) { ret i; }
+ _ { tcx.sess.bug("node_id_for_constr: pred is not a function"); }
}
}
-fn expr_to_constr_arg(ty::ctxt tcx, &@expr e) -> @constr_arg_use {
- alt (e.node) {
- case (expr_path(?p)) {
- alt (tcx.def_map.find(e.id)) {
- case (some(def_local(?l_id))) {
- ret @respan(p.span,
- carg_ident(rec(ident=p.node.idents.(0),
- node=l_id.node)));
- }
- case (some(def_arg(?a_id))) {
- ret @respan(p.span,
- carg_ident(rec(ident=p.node.idents.(0),
- node=a_id.node)));
- }
- case (_) {
- tcx.sess.bug("exprs_to_constr_args: non-local variable " +
- "as pred arg");
+fn expr_to_constr_arg(tcx: ty::ctxt, e: &@expr) -> @constr_arg_use {
+ alt e.node {
+ expr_path(p) {
+ alt tcx.def_map.find(e.id) {
+ some(def_local(l_id)) {
+ ret @respan(p.span,
+ carg_ident({ident: p.node.idents.(0),
+ node: l_id.node}));
+ }
+ some(def_arg(a_id)) {
+ ret @respan(p.span,
+ carg_ident({ident: p.node.idents.(0),
+ node: a_id.node}));
+ }
+ _ {
+ tcx.sess.bug("exprs_to_constr_args: non-local variable " +
+ "as pred arg");
- }
- }
+ }
}
- case (expr_lit(?l)) { ret @respan(e.span, carg_lit(l)); }
- case (_) {
- tcx.sess.span_fatal(e.span,
- "Arguments to constrained functions must be "
- + "literals or local variables");
- }
+ }
+ expr_lit(l) { ret @respan(e.span, carg_lit(l)); }
+ _ {
+ tcx.sess.span_fatal(e.span,
+ "Arguments to constrained functions must be " +
+ "literals or local variables");
+ }
}
}
-fn exprs_to_constr_args(ty::ctxt tcx, &(@expr)[] args)
- -> (@constr_arg_use)[] {
- auto f = bind expr_to_constr_arg(tcx, _);
- let (@constr_arg_use)[] rslt = ~[];
- for (@expr e in args) {
- rslt += ~[f(e)];
- }
+fn exprs_to_constr_args(tcx: ty::ctxt, args: &(@expr)[]) ->
+ (@constr_arg_use)[] {
+ let f = bind expr_to_constr_arg(tcx, _);
+ let rslt: (@constr_arg_use)[] = ~[];
+ for e: @expr in args { rslt += ~[f(e)]; }
rslt
}
-fn expr_to_constr(ty::ctxt tcx, &@expr e) -> sp_constr {
- alt (e.node) {
- case (
- // FIXME change the first pattern to expr_path to test a
- // typechecker bug
- expr_call(?operator, ?args)) {
- alt (operator.node) {
- case (expr_path(?p)) {
- ret respan(e.span,
- npred(p, def_id_for_constr(tcx, operator.id),
- exprs_to_constr_args(tcx, args)));
- }
- case (_) {
- tcx.sess.span_fatal(operator.span,
- "Internal error: " +
- " ill-formed operator \
+fn expr_to_constr(tcx: ty::ctxt, e: &@expr) -> sp_constr {
+ alt e.node {
+
+ // FIXME change the first pattern to expr_path to test a
+ // typechecker bug
+ expr_call(operator, args) {
+ alt operator.node {
+ expr_path(p) {
+ ret respan(e.span,
+ npred(p, def_id_for_constr(tcx, operator.id),
+ exprs_to_constr_args(tcx, args)));
+ }
+ _ {
+ tcx.sess.span_fatal(operator.span,
+ "Internal error: " +
+ " ill-formed operator \
in predicate");
- }
- }
+ }
}
- case (_) {
- tcx.sess.span_fatal(e.span,
- "Internal error: " + " ill-formed predicate");
- }
+ }
+ _ {
+ tcx.sess.span_fatal(e.span,
+ "Internal error: " + " ill-formed predicate");
+ }
}
}
-fn pred_args_to_str(&pred_args p) -> str {
+fn pred_args_to_str(p: &pred_args) -> str {
"<" + uint::str(p.node.bit_num) + ", " +
- constr_args_to_str(fn(&inst i) -> str { ret i.ident; },
- p.node.args) + ">"
+ constr_args_to_str(fn (i: &inst) -> str { ret i.ident; }, p.node.args)
+ + ">"
}
-fn substitute_constr_args(&ty::ctxt cx, &(@expr)[] actuals,
- &@ty::constr c) -> tsconstr {
- let (@constr_arg_use)[] rslt = ~[];
- for (@constr_arg a in c.node.args) {
+fn substitute_constr_args(cx: &ty::ctxt, actuals: &(@expr)[], c: &@ty::constr)
+ -> tsconstr {
+ let rslt: (@constr_arg_use)[] = ~[];
+ for a: @constr_arg in c.node.args {
rslt += ~[substitute_arg(cx, actuals, a)];
}
ret npred(c.node.path, c.node.id, rslt);
}
-fn substitute_arg(&ty::ctxt cx, &(@expr)[] actuals, @constr_arg a) ->
+fn substitute_arg(cx: &ty::ctxt, actuals: &(@expr)[], a: @constr_arg) ->
@constr_arg_use {
- auto num_actuals = ivec::len(actuals);
- alt (a.node) {
- case (carg_ident(?i)) {
- if (i < num_actuals) {
- ret expr_to_constr_arg(cx, actuals.(i));
- } else {
- cx.sess.span_fatal(a.span,
- "Constraint argument out of bounds");
- }
+ let num_actuals = ivec::len(actuals);
+ alt a.node {
+ carg_ident(i) {
+ if i < num_actuals {
+ ret expr_to_constr_arg(cx, actuals.(i));
+ } else {
+ cx.sess.span_fatal(a.span, "Constraint argument out of bounds");
}
- case (carg_base) { ret @respan(a.span, carg_base); }
- case (carg_lit(?l)) { ret @respan(a.span, carg_lit(l)); }
+ }
+ carg_base. { ret @respan(a.span, carg_base); }
+ carg_lit(l) { ret @respan(a.span, carg_lit(l)); }
}
}
-fn pred_args_matches(&(constr_arg_general_[inst])[] pattern,
- &pred_args desc) -> bool {
- auto i = 0u;
- for (@constr_arg_use c in desc.node.args) {
- auto n = pattern.(i);
- alt (c.node) {
- case (carg_ident(?p)) {
- alt (n) {
- case (carg_ident(?q)) {
- if (p.node != q.node) {
- ret false;
- }
- }
- case (_) { ret false; }
- }
+fn pred_args_matches(pattern: &(constr_arg_general_[inst])[],
+ desc: &pred_args) -> bool {
+ let i = 0u;
+ for c: @constr_arg_use in desc.node.args {
+ let n = pattern.(i);
+ alt c.node {
+ carg_ident(p) {
+ alt n {
+ carg_ident(q) { if p.node != q.node { ret false; } }
+ _ { ret false; }
}
- case (carg_base) {
- if (n != carg_base) {
- ret false;
- }
+ }
+ carg_base. { if n != carg_base { ret false; } }
+ carg_lit(l) {
+ alt n {
+ carg_lit(m) { if !lit_eq(l, m) { ret false; } }
+ _ { ret false; }
}
- case (carg_lit(?l)) {
- alt (n) {
- case (carg_lit(?m)) {
- if (!lit_eq(l, m)) {
- ret false;
- }
- }
- case (_) { ret false; }
- }
- }
+ }
}
i += 1u;
}
ret true;
}
-fn find_instance_(&(constr_arg_general_[inst])[] pattern,
- &pred_args[] descs) -> option::t[uint] {
- for (pred_args d in descs) {
- if (pred_args_matches(pattern, d)) {
- ret some(d.node.bit_num);
- }
+fn find_instance_(pattern: &(constr_arg_general_[inst])[],
+ descs: &pred_args[]) -> option::t[uint] {
+ for d: pred_args in descs {
+ if pred_args_matches(pattern, d) { ret some(d.node.bit_num); }
}
ret none;
}
-type inst = rec(ident ident, node_id node);
-type subst = rec(inst from, inst to)[];
+type inst = {ident: ident, node: node_id};
+type subst = {from: inst, to: inst}[];
-fn find_instances(&fn_ctxt fcx, &subst subst, &constraint c)
- -> (rec(uint from, uint to))[] {
+fn find_instances(fcx: &fn_ctxt, subst: &subst, c: &constraint) ->
+ {from: uint, to: uint}[] {
- auto rslt = ~[];
- if (ivec::len(subst) == 0u) {
- ret rslt;
- }
+ let rslt = ~[];
+ if ivec::len(subst) == 0u { ret rslt; }
- alt (c) {
- case (cinit(_,_,_)) { /* this is dealt with separately */ }
- case (cpred(?p, ?descs)) {
- for (pred_args d in *descs) {
- if (args_mention(d.node.args, find_in_subst_bool, subst)) {
- auto old_bit_num = d.node.bit_num;
- auto new = replace(subst, d);
- alt (find_instance_(new, *descs)) {
- case (some(?d1)) {
- rslt += ~[rec(from=old_bit_num, to=d1)];
- }
- case (_) { }
- }
+ alt c {
+ cinit(_, _, _) {/* this is dealt with separately */ }
+ cpred(p, descs) {
+ for d: pred_args in *descs {
+ if args_mention(d.node.args, find_in_subst_bool, subst) {
+ let old_bit_num = d.node.bit_num;
+ let new = replace(subst, d);
+ alt find_instance_(new, *descs) {
+ some(d1) { rslt += ~[{from: old_bit_num, to: d1}]; }
+ _ { }
}
}
}
+ }
}
rslt
}
-fn find_in_subst(node_id id, &subst s) -> option::t[inst] {
- for (rec(inst from, inst to) p in s) {
- if (id == p.from.node) {
- ret some(p.to);
- }
+fn find_in_subst(id: node_id, s: &subst) -> option::t[inst] {
+ for p: {from: inst, to: inst} in s {
+ if id == p.from.node { ret some(p.to); }
}
ret none;
}
-fn find_in_subst_bool(&subst s, node_id id) -> bool {
+fn find_in_subst_bool(s: &subst, id: node_id) -> bool {
is_some(find_in_subst(id, s))
}
-fn insts_to_str(&(constr_arg_general_[inst])[] stuff) -> str {
- auto rslt = "<";
- for (constr_arg_general_[inst] i in stuff) {
- rslt += " " + alt(i) {
- case (carg_ident(?p)) { p.ident }
- case (carg_base) { "*" }
- case (carg_lit(_)) { "[lit]" } } + " ";
+fn insts_to_str(stuff: &(constr_arg_general_[inst])[]) -> str {
+ let rslt = "<";
+ for i: constr_arg_general_[inst] in stuff {
+ rslt +=
+ " " +
+ alt i {
+ carg_ident(p) { p.ident }
+ carg_base. { "*" }
+ carg_lit(_) { "[lit]" }
+ } + " ";
}
rslt += ">";
rslt
}
-fn replace(subst subst, pred_args d) -> (constr_arg_general_[inst])[] {
- let (constr_arg_general_[inst])[] rslt = ~[];
- for (@constr_arg_use c in d.node.args) {
- alt (c.node) {
- case (carg_ident(?p)) {
- alt (find_in_subst(p.node, subst)) {
- case (some(?new)) {
- rslt += ~[carg_ident(new)];
- }
- case (_) {
- rslt += ~[c.node];
- }
- }
+fn replace(subst: subst, d: pred_args) -> (constr_arg_general_[inst])[] {
+ let rslt: (constr_arg_general_[inst])[] = ~[];
+ for c: @constr_arg_use in d.node.args {
+ alt c.node {
+ carg_ident(p) {
+ alt find_in_subst(p.node, subst) {
+ some(new) { rslt += ~[carg_ident(new)]; }
+ _ { rslt += ~[c.node]; }
}
- case (_) {
- // log_err "##";
- rslt += ~[c.node];
- }
- }
+ }
+ _ {
+ // log_err "##";
+ rslt += ~[c.node];
+ }
+ }
}
/*
@@ -805,69 +778,65 @@
ret rslt;
}
-fn path_to_ident(&ty::ctxt cx, &path p) -> ident {
- alt (ivec::last(p.node.idents)) {
- case (none) { cx.sess.span_fatal(p.span, "Malformed path"); }
- case (some(?i)) { ret i; }
+fn path_to_ident(cx: &ty::ctxt, p: &path) -> ident {
+ alt ivec::last(p.node.idents) {
+ none. { cx.sess.span_fatal(p.span, "Malformed path"); }
+ some(i) { ret i; }
}
}
-tag if_ty {
- if_check;
- plain_if;
-}
+tag if_ty { if_check; plain_if; }
-fn local_node_id_to_def_id_strict(&fn_ctxt fcx, &span sp, &node_id i)
- -> def_id {
- alt (local_node_id_to_def(fcx, i)) {
- case (some(def_local(?d_id))) {
- ret d_id;
- }
- case (some (def_arg(?a_id))) {
- ret a_id;
- }
- case (some(_)) {
- fcx.ccx.tcx.sess.span_fatal(sp, "local_node_id_to_def_id: id \
+fn local_node_id_to_def_id_strict(fcx: &fn_ctxt, sp: &span, i: &node_id) ->
+ def_id {
+ alt local_node_id_to_def(fcx, i) {
+ some(def_local(d_id)) { ret d_id; }
+ some(def_arg(a_id)) { ret a_id; }
+ some(_) {
+ fcx.ccx.tcx.sess.span_fatal(sp,
+ "local_node_id_to_def_id: id \
isn't a local");
- }
- case (none) {
- // should really be bug. span_bug()?
- fcx.ccx.tcx.sess.span_fatal(sp, "local_node_id_to_def_id: id \
+ }
+ none. {
+ // should really be bug. span_bug()?
+ fcx.ccx.tcx.sess.span_fatal(sp,
+ "local_node_id_to_def_id: id \
is unbound");
- }
+ }
}
}
-fn local_node_id_to_def(&fn_ctxt fcx, &node_id i) -> option::t[def]
- { fcx.ccx.tcx.def_map.find(i) }
+fn local_node_id_to_def(fcx: &fn_ctxt, i: &node_id) -> option::t[def] {
+ fcx.ccx.tcx.def_map.find(i)
+}
-fn local_node_id_to_def_id(&fn_ctxt fcx, &node_id i) -> option::t[def_id] {
- alt (local_node_id_to_def(fcx, i)) {
- case (some(def_local(?d_id))) { some(d_id) }
- case (some (def_arg(?a_id))) { some(a_id) }
- case (_) { none }
+fn local_node_id_to_def_id(fcx: &fn_ctxt, i: &node_id) -> option::t[def_id] {
+ alt local_node_id_to_def(fcx, i) {
+ some(def_local(d_id)) { some(d_id) }
+ some(def_arg(a_id)) { some(a_id) }
+ _ { none }
}
}
-fn local_node_id_to_local_def_id(&fn_ctxt fcx, &node_id i)
- -> option::t[node_id] {
- alt (local_node_id_to_def(fcx, i)) {
- case (some (def_local(?d_id))) { some(d_id.node) }
- case (some (def_arg(?a_id))) { some(a_id.node) }
- case (_) { none }
+fn local_node_id_to_local_def_id(fcx: &fn_ctxt, i: &node_id) ->
+ option::t[node_id] {
+ alt local_node_id_to_def(fcx, i) {
+ some(def_local(d_id)) { some(d_id.node) }
+ some(def_arg(a_id)) { some(a_id.node) }
+ _ { none }
}
}
-fn copy_in_postcond(&fn_ctxt fcx, node_id parent_exp, inst dest, inst src,
- oper_type ty) {
- auto post = node_id_to_ts_ann(fcx.ccx, parent_exp).conditions.
- postcondition;
+fn copy_in_postcond(fcx: &fn_ctxt, parent_exp: node_id, dest: inst, src: inst,
+ ty: oper_type) {
+ let post =
+ node_id_to_ts_ann(fcx.ccx, parent_exp).conditions.postcondition;
copy_in_poststate_two(fcx, post, post, dest, src, ty);
}
// FIXME refactor
-fn copy_in_poststate(&fn_ctxt fcx, &poststate post, inst dest, inst src,
- oper_type ty) {
+fn copy_in_poststate(fcx: &fn_ctxt, post: &poststate, dest: inst, src: inst,
+ ty: oper_type) {
copy_in_poststate_two(fcx, post, post, dest, src, ty);
}
@@ -876,30 +845,26 @@
// dest substituted for src.
// (This doesn't create any new constraints. If a new, substituted
// constraint isn't already in the bit vector, it's ignored.)
-fn copy_in_poststate_two(&fn_ctxt fcx, &poststate src_post,
- &poststate target_post, inst dest, inst src,
- oper_type ty) {
- auto subst;
- alt (ty) {
- case (oper_swap) {
- subst = ~[rec(from=dest, to=src),
- rec(from=src, to=dest)];
- }
- case (oper_assign_op) {
- ret; // Don't do any propagation
- }
- case (_) {
- subst = ~[rec(from=src, to=dest)];
- }
+fn copy_in_poststate_two(fcx: &fn_ctxt, src_post: &poststate,
+ target_post: &poststate, dest: inst, src: inst,
+ ty: oper_type) {
+ let subst;
+ alt ty {
+ oper_swap. { subst = ~[{from: dest, to: src}, {from: src, to: dest}]; }
+ oper_assign_op. {
+ ret; // Don't do any propagation
+ }
+ _ { subst = ~[{from: src, to: dest}]; }
}
- for each (@rec(def_id key, constraint val) p in
- fcx.enclosing.constrs.items()) {
+
+ for each p: @{key: def_id, val: constraint} in
+ fcx.enclosing.constrs.items() {
// replace any occurrences of the src def_id with the
// dest def_id
- auto insts = find_instances(fcx, subst, p.val);
- for (rec(uint from, uint to) p in insts) {
- if (promises_(p.from, src_post)) {
+ let insts = find_instances(fcx, subst, p.val);
+ for p: {from: uint, to: uint} in insts {
+ if promises_(p.from, src_post) {
set_in_poststate_(p.to, target_post);
}
}
@@ -908,108 +873,104 @@
/* FIXME should refactor this better */
-fn forget_in_postcond(&fn_ctxt fcx, node_id parent_exp, node_id dead_v) {
+fn forget_in_postcond(fcx: &fn_ctxt, parent_exp: node_id, dead_v: node_id) {
// In the postcondition given by parent_exp, clear the bits
// for any constraints mentioning dead_v
- auto d = local_node_id_to_local_def_id(fcx, dead_v);
- alt (d) {
- case (some(?d_id)) {
- for (norm_constraint c in constraints(fcx)) {
- if (constraint_mentions(fcx, c, d_id)) {
- clear_in_postcond(c.bit_num,
- node_id_to_ts_ann(fcx.ccx, parent_exp).conditions);
- }
+ let d = local_node_id_to_local_def_id(fcx, dead_v);
+ alt d {
+ some(d_id) {
+ for c: norm_constraint in constraints(fcx) {
+ if constraint_mentions(fcx, c, d_id) {
+ clear_in_postcond(c.bit_num,
+ node_id_to_ts_ann(fcx.ccx,
+ parent_exp).conditions);
}
}
- case (_) {}
+ }
+ _ { }
}
}
-fn forget_in_postcond_still_init(&fn_ctxt fcx, node_id parent_exp,
- node_id dead_v) {
+fn forget_in_postcond_still_init(fcx: &fn_ctxt, parent_exp: node_id,
+ dead_v: node_id) {
// In the postcondition given by parent_exp, clear the bits
// for any constraints mentioning dead_v
- auto d = local_node_id_to_local_def_id(fcx, dead_v);
- alt (d) {
- case (some(?d_id)) {
- for (norm_constraint c in constraints(fcx)) {
- if (non_init_constraint_mentions(fcx, c, d_id)) {
- clear_in_postcond(c.bit_num,
- node_id_to_ts_ann(fcx.ccx, parent_exp).conditions);
- }
+ let d = local_node_id_to_local_def_id(fcx, dead_v);
+ alt d {
+ some(d_id) {
+ for c: norm_constraint in constraints(fcx) {
+ if non_init_constraint_mentions(fcx, c, d_id) {
+ clear_in_postcond(c.bit_num,
+ node_id_to_ts_ann(fcx.ccx,
+ parent_exp).conditions);
}
}
- case (_) { }
+ }
+ _ { }
}
}
-fn forget_in_poststate(&fn_ctxt fcx, &poststate p, node_id dead_v) -> bool {
+fn forget_in_poststate(fcx: &fn_ctxt, p: &poststate, dead_v: node_id) ->
+ bool {
// In the poststate given by parent_exp, clear the bits
// for any constraints mentioning dead_v
- auto d = local_node_id_to_local_def_id(fcx, dead_v);
- auto changed = false;
- alt (d) {
- case (some(?d_id)) {
- for (norm_constraint c in constraints(fcx)) {
- if (constraint_mentions(fcx, c, d_id)) {
- changed |= clear_in_poststate_(c.bit_num, p);
- }
+ let d = local_node_id_to_local_def_id(fcx, dead_v);
+ let changed = false;
+ alt d {
+ some(d_id) {
+ for c: norm_constraint in constraints(fcx) {
+ if constraint_mentions(fcx, c, d_id) {
+ changed |= clear_in_poststate_(c.bit_num, p);
}
}
- case (_) {}
+ }
+ _ { }
}
ret changed;
}
-fn forget_in_poststate_still_init(&fn_ctxt fcx, &poststate p, node_id dead_v)
- -> bool {
+fn forget_in_poststate_still_init(fcx: &fn_ctxt, p: &poststate,
+ dead_v: node_id) -> bool {
// In the poststate given by parent_exp, clear the bits
// for any constraints mentioning dead_v
- auto d = local_node_id_to_local_def_id(fcx, dead_v);
- auto changed = false;
- alt (d) {
- case (some(?d_id)) {
- for (norm_constraint c in constraints(fcx)) {
- if (non_init_constraint_mentions(fcx, c, d_id)) {
- changed |= clear_in_poststate_(c.bit_num, p);
- }
+ let d = local_node_id_to_local_def_id(fcx, dead_v);
+ let changed = false;
+ alt d {
+ some(d_id) {
+ for c: norm_constraint in constraints(fcx) {
+ if non_init_constraint_mentions(fcx, c, d_id) {
+ changed |= clear_in_poststate_(c.bit_num, p);
}
}
- case (_) {}
+ }
+ _ { }
}
ret changed;
}
-fn any_eq(&(node_id)[] v, node_id d) -> bool {
- for (node_id i in v) {
- if (i == d) { ret true; }
- }
+fn any_eq(v: &node_id[], d: node_id) -> bool {
+ for i: node_id in v { if i == d { ret true; } }
false
}
-fn constraint_mentions(&fn_ctxt fcx, &norm_constraint c, node_id v) -> bool {
- ret (alt (c.c.node) {
- case (ninit(?id,_)) { v == id }
- case (npred(_, _, ?args)) {
- args_mention(args, any_eq, ~[v])
- }
- });
+fn constraint_mentions(fcx: &fn_ctxt, c: &norm_constraint, v: node_id) ->
+ bool {
+ ret alt c.c.node {
+ ninit(id, _) { v == id }
+ npred(_, _, args) { args_mention(args, any_eq, ~[v]) }
+ };
}
-fn non_init_constraint_mentions(&fn_ctxt fcx, &norm_constraint c,
- &node_id v) -> bool {
- ret (alt (c.c.node) {
- case (ninit(_,_)) {
- false
- }
- case (npred(_, _, ?args)) {
- args_mention(args, any_eq, ~[v])
- }
- });
+fn non_init_constraint_mentions(fcx: &fn_ctxt, c: &norm_constraint,
+ v: &node_id) -> bool {
+ ret alt c.c.node {
+ ninit(_, _) { false }
+ npred(_, _, args) { args_mention(args, any_eq, ~[v]) }
+ };
}
-fn args_mention[T](&(@constr_arg_use)[] args, fn(&(T)[], node_id) -> bool q,
- &(T)[] s) -> bool {
+fn args_mention[T](args: &(@constr_arg_use)[], q: fn(&T[], node_id) -> bool ,
+ s: &T[]) -> bool {
/*
FIXME
The following version causes an assertion in trans to fail
@@ -1028,62 +989,48 @@
ret ivec::any(bind mentions(s,q,_), args);
*/
- for (@constr_arg_use a in args) {
- alt (a.node) {
- case (carg_ident(?p1)) {
- if (q(s, p1.node)) {
- ret true;
- }
- }
- case (_) {}
- }
+ for a: @constr_arg_use in args {
+ alt a.node { carg_ident(p1) { if q(s, p1.node) { ret true; } } _ { } }
}
ret false;
}
-fn use_var(&fn_ctxt fcx, &node_id v) {
- *fcx.enclosing.used_vars += ~[v];
-}
+fn use_var(fcx: &fn_ctxt, v: &node_id) { *fcx.enclosing.used_vars += ~[v]; }
// FIXME: This should be a function in std::ivec::.
-fn vec_contains(&@mutable (node_id[]) v, &node_id i) -> bool {
- for (node_id d in *v) {
- if (d == i) { ret true; }
- }
+fn vec_contains(v: &@mutable node_id[], i: &node_id) -> bool {
+ for d: node_id in *v { if d == i { ret true; } }
ret false;
}
-fn op_to_oper_ty(init_op io) -> oper_type {
- alt (io) {
- case (init_move) { oper_move }
- case (_) { oper_assign }
- }
+fn op_to_oper_ty(io: init_op) -> oper_type {
+ alt io { init_move. { oper_move } _ { oper_assign } }
}
// default function visitor
-fn do_nothing[T](&_fn f, &ty_param[] tp, &span sp, &fn_ident i,
- node_id iid, &T cx, &visit::vt[T] v) {
+fn do_nothing[T](f: &_fn, tp: &ty_param[], sp: &span, i: &fn_ident,
+ iid: node_id, cx: &T, v: &visit::vt[T]) {
}
-fn args_to_constr_args(&span sp, &arg[] args) -> (@constr_arg_use)[] {
- let (@constr_arg_use)[] actuals = ~[];
- for (arg a in args) {
- actuals += ~[@respan(sp, carg_ident(rec(ident=a.ident, node=a.id)))];
+fn args_to_constr_args(sp: &span, args: &arg[]) -> (@constr_arg_use)[] {
+ let actuals: (@constr_arg_use)[] = ~[];
+ for a: arg in args {
+ actuals += ~[@respan(sp, carg_ident({ident: a.ident, node: a.id}))];
}
ret actuals;
}
-fn ast_constr_to_ts_constr(&ty::ctxt tcx, &arg[] args, &@constr c)
- -> tsconstr {
- auto tconstr = ty::ast_constr_to_constr(tcx, c);
+fn ast_constr_to_ts_constr(tcx: &ty::ctxt, args: &arg[], c: &@constr) ->
+ tsconstr {
+ let tconstr = ty::ast_constr_to_constr(tcx, c);
ret npred(tconstr.node.path, tconstr.node.id,
- args_to_constr_args(tconstr.span, args));
+ args_to_constr_args(tconstr.span, args));
}
-fn ast_constr_to_sp_constr(&ty::ctxt tcx, &arg[] args, &@constr c)
- -> sp_constr {
- auto tconstr = ast_constr_to_ts_constr(tcx, args, c);
+fn ast_constr_to_sp_constr(tcx: &ty::ctxt, args: &arg[], c: &@constr) ->
+ sp_constr {
+ let tconstr = ast_constr_to_ts_constr(tcx, args, c);
ret respan(c.span, tconstr);
}
diff --git a/src/comp/middle/tstate/bitvectors.rs b/src/comp/middle/tstate/bitvectors.rs
index c9cf002..a14a7a2 100644
--- a/src/comp/middle/tstate/bitvectors.rs
+++ b/src/comp/middle/tstate/bitvectors.rs
@@ -26,224 +26,206 @@
import tstate::ann::clear_in_poststate_;
import tritv::*;
-fn bit_num(&fn_ctxt fcx, &tsconstr c) -> uint {
- auto d = tsconstr_to_def_id(c);
+fn bit_num(fcx: &fn_ctxt, c: &tsconstr) -> uint {
+ let d = tsconstr_to_def_id(c);
assert (fcx.enclosing.constrs.contains_key(d));
- auto rslt = fcx.enclosing.constrs.get(d);
- alt (c) {
- case (ninit(_,_)) {
- alt (rslt) {
- case (cinit(?n, _, _)) { ret n; }
- case (_) {
- fcx.ccx.tcx.sess.bug("bit_num: asked for init constraint,"
- + " found a pred constraint");
- }
- }
+ let rslt = fcx.enclosing.constrs.get(d);
+ alt c {
+ ninit(_, _) {
+ alt rslt {
+ cinit(n, _, _) { ret n; }
+ _ {
+ fcx.ccx.tcx.sess.bug("bit_num: asked for init constraint," +
+ " found a pred constraint");
+ }
}
- case (npred(_, _, ?args)) {
- alt (rslt) {
- case (cpred(_, ?descs)) {
- ret match_args(fcx, descs, args);
- }
- case (_) {
- fcx.ccx.tcx.sess.bug("bit_num: asked for pred constraint,"
- + " found an init constraint");
- }
- }
+ }
+ npred(_, _, args) {
+ alt rslt {
+ cpred(_, descs) { ret match_args(fcx, descs, args); }
+ _ {
+ fcx.ccx.tcx.sess.bug("bit_num: asked for pred constraint," +
+ " found an init constraint");
+ }
}
+ }
}
}
-fn promises(&fn_ctxt fcx, &poststate p, &tsconstr c) -> bool {
+fn promises(fcx: &fn_ctxt, p: &poststate, c: &tsconstr) -> bool {
ret promises_(bit_num(fcx, c), p);
}
-fn promises_(uint n, &poststate p) -> bool {
- ret tritv_get(p, n) == ttrue;
-}
+fn promises_(n: uint, p: &poststate) -> bool { ret tritv_get(p, n) == ttrue; }
// v "happens after" u
-fn seq_trit(trit u, trit v) -> trit {
- alt (v) {
- case (ttrue) { ttrue }
- case (tfalse) { tfalse }
- case (dont_care) { u }
- }
+fn seq_trit(u: trit, v: trit) -> trit {
+ alt v { ttrue. { ttrue } tfalse. { tfalse } dont_care. { u } }
}
// idea: q "happens after" p -- so if something is
// 1 in q and 0 in p, it's 1 in the result; however,
// if it's 0 in q and 1 in p, it's 0 in the result
-fn seq_tritv(&postcond p, &postcond q) {
- auto i = 0u;
+fn seq_tritv(p: &postcond, q: &postcond) {
+ let i = 0u;
assert (p.nbits == q.nbits);
- while (i < p.nbits) {
+ while i < p.nbits {
tritv_set(i, p, seq_trit(tritv_get(p, i), tritv_get(q, i)));
i += 1u;
}
}
-fn seq_postconds(&fn_ctxt fcx, &postcond[] ps) -> postcond {
- auto sz = ivec::len(ps);
- if (sz >= 1u) {
- auto prev = tritv_clone(ps.(0));
- for (postcond p in ivec::slice(ps, 1u, sz)) {
- seq_tritv(prev, p);
- }
+fn seq_postconds(fcx: &fn_ctxt, ps: &postcond[]) -> postcond {
+ let sz = ivec::len(ps);
+ if sz >= 1u {
+ let prev = tritv_clone(ps.(0));
+ for p: postcond in ivec::slice(ps, 1u, sz) { seq_tritv(prev, p); }
ret prev;
- }
- else {
- ret ann::empty_poststate(num_constraints(fcx.enclosing));
- }
+ } else { ret ann::empty_poststate(num_constraints(fcx.enclosing)); }
}
// Given a list of pres and posts for exprs e0 ... en,
// return the precondition for evaluating each expr in order.
// So, if e0's post is {x} and e1's pre is {x, y, z}, the entire
// precondition shouldn't include x.
-fn seq_preconds(&fn_ctxt fcx, &pre_and_post[] pps) -> precond {
- let uint sz = ivec::len(pps);
- let uint num_vars = num_constraints(fcx.enclosing);
+fn seq_preconds(fcx: &fn_ctxt, pps: &pre_and_post[]) -> precond {
+ let sz: uint = ivec::len(pps);
+ let num_vars: uint = num_constraints(fcx.enclosing);
- fn seq_preconds_go(&fn_ctxt fcx, &pre_and_post[] pps,
- &pre_and_post first)
- -> precond {
- let uint sz = ivec::len(pps);
- if (sz >= 1u) {
- auto second = pps.(0);
+ fn seq_preconds_go(fcx: &fn_ctxt, pps: &pre_and_post[],
+ first: &pre_and_post) -> precond {
+ let sz: uint = ivec::len(pps);
+ if sz >= 1u {
+ let second = pps.(0);
assert (pps_len(second) == num_constraints(fcx.enclosing));
- auto second_pre = clone(second.precondition);
+ let second_pre = clone(second.precondition);
difference(second_pre, first.postcondition);
- auto next_first = clone(first.precondition);
+ let next_first = clone(first.precondition);
union(next_first, second_pre);
- auto next_first_post = clone(first.postcondition);
+ let next_first_post = clone(first.postcondition);
seq_tritv(next_first_post, second.postcondition);
ret seq_preconds_go(fcx, ivec::slice(pps, 1u, sz),
- @rec(precondition=next_first,
- postcondition=next_first_post));
- }
- else {
- ret first.precondition;
- }
+ @{precondition: next_first,
+ postcondition: next_first_post});
+ } else { ret first.precondition; }
}
- if (sz >= 1u) {
- auto first = pps.(0);
+
+ if sz >= 1u {
+ let first = pps.(0);
assert (pps_len(first) == num_vars);
ret seq_preconds_go(fcx, ivec::slice(pps, 1u, sz), first);
} else { ret true_precond(num_vars); }
}
-fn intersect_states(&prestate p, &prestate q) -> prestate {
- auto rslt = tritv_clone(p);
+fn intersect_states(p: &prestate, q: &prestate) -> prestate {
+ let rslt = tritv_clone(p);
tritv_intersect(rslt, q);
ret rslt;
}
-fn gen(&fn_ctxt fcx, node_id id, &tsconstr c) -> bool {
+fn gen(fcx: &fn_ctxt, id: node_id, c: &tsconstr) -> bool {
ret set_in_postcond(bit_num(fcx, c),
node_id_to_ts_ann(fcx.ccx, id).conditions);
}
-fn declare_var(&fn_ctxt fcx, &tsconstr c, prestate pre) -> prestate {
- auto rslt = clone(pre);
+fn declare_var(fcx: &fn_ctxt, c: &tsconstr, pre: prestate) -> prestate {
+ let rslt = clone(pre);
relax_prestate(bit_num(fcx, c), rslt);
// idea is this is scoped
relax_poststate(bit_num(fcx, c), rslt);
ret rslt;
}
-fn relax_precond_block_non_recursive(&fn_ctxt fcx, node_id i, &blk b) {
+fn relax_precond_block_non_recursive(fcx: &fn_ctxt, i: node_id, b: &blk) {
relax_precond(i as uint, block_precond(fcx.ccx, b));
}
-fn relax_precond_expr(&fn_ctxt fcx, node_id i, &@expr e) {
+fn relax_precond_expr(fcx: &fn_ctxt, i: node_id, e: &@expr) {
relax_precond(i as uint, expr_precond(fcx.ccx, e));
}
-fn relax_precond_stmt(&fn_ctxt fcx, node_id i, &@stmt s) {
+fn relax_precond_stmt(fcx: &fn_ctxt, i: node_id, s: &@stmt) {
relax_precond(i as uint, stmt_precond(fcx.ccx, *s));
}
-fn relax_precond_block(&fn_ctxt fcx, node_id i, &blk b) {
+fn relax_precond_block(fcx: &fn_ctxt, i: node_id, b: &blk) {
relax_precond_block_non_recursive(fcx, i, b);
// FIXME: should use visit instead
// could at least generalize this pattern
// (also seen in ck::check_states_against_conditions)
- let @mutable bool keepgoing = @mutable true;
+ let keepgoing: @mutable bool = @mutable true;
- fn quit(@mutable bool keepgoing, &@item i) {
- *keepgoing = false;
- }
- fn kg(@mutable bool keepgoing) -> bool { ret *keepgoing; }
+ fn quit(keepgoing: @mutable bool, i: &@item) { *keepgoing = false; }
+ fn kg(keepgoing: @mutable bool) -> bool { ret *keepgoing; }
- auto v = rec(visit_block_pre = bind
- relax_precond_block_non_recursive(fcx, i, _),
- visit_expr_pre = bind relax_precond_expr(fcx, i, _),
- visit_stmt_pre = bind relax_precond_stmt(fcx, i, _),
- visit_item_pre=bind quit(keepgoing, _),
- keep_going=bind kg(keepgoing)
+ let
- with walk::default_visitor());
+ v =
+ {visit_block_pre: bind relax_precond_block_non_recursive(fcx, i, _),
+ visit_expr_pre: bind relax_precond_expr(fcx, i, _),
+ visit_stmt_pre: bind relax_precond_stmt(fcx, i, _),
+ visit_item_pre: bind quit(keepgoing, _),
+ keep_going: bind kg(keepgoing) with walk::default_visitor()};
walk::walk_block(v, b);
}
-fn gen_poststate(&fn_ctxt fcx, node_id id, &tsconstr c) -> bool {
+fn gen_poststate(fcx: &fn_ctxt, id: node_id, c: &tsconstr) -> bool {
log "gen_poststate";
ret set_in_poststate(bit_num(fcx, c),
node_id_to_ts_ann(fcx.ccx, id).states);
}
-fn kill_prestate(&fn_ctxt fcx, node_id id, &tsconstr c) -> bool {
+fn kill_prestate(fcx: &fn_ctxt, id: node_id, c: &tsconstr) -> bool {
ret clear_in_prestate(bit_num(fcx, c),
- node_id_to_ts_ann(fcx.ccx, id).states);
+ node_id_to_ts_ann(fcx.ccx, id).states);
}
-fn kill_poststate(&fn_ctxt fcx, node_id id, &tsconstr c) -> bool {
+fn kill_poststate(fcx: &fn_ctxt, id: node_id, c: &tsconstr) -> bool {
log "kill_poststate";
ret clear_in_poststate(bit_num(fcx, c),
node_id_to_ts_ann(fcx.ccx, id).states);
}
-fn clear_in_poststate_expr(&fn_ctxt fcx, &@expr e, &poststate t) {
- alt (e.node) {
- case (expr_path(?p)) {
- alt (ivec::last(p.node.idents)) {
- case (some(?i)) {
- alt (local_node_id_to_def(fcx, e.id)) {
- case (some(def_local(?d_id))) {
- clear_in_poststate_(
- bit_num(fcx,ninit(d_id.node, i)), t);
- }
- case (some(_)) { /* ignore args (for now...) */ }
- case (_) {
- fcx.ccx.tcx.sess.bug("clear_in_poststate_expr: \
- unbound var"); }
- }
- }
- case (_) { fcx.ccx.tcx.sess.bug("clear_in_poststate_expr"); }
+fn clear_in_poststate_expr(fcx: &fn_ctxt, e: &@expr, t: &poststate) {
+ alt e.node {
+ expr_path(p) {
+ alt ivec::last(p.node.idents) {
+ some(i) {
+ alt local_node_id_to_def(fcx, e.id) {
+ some(def_local(d_id)) {
+ clear_in_poststate_(bit_num(fcx, ninit(d_id.node, i)), t);
+ }
+ some(_) {/* ignore args (for now...) */ }
+ _ {
+ fcx.ccx.tcx.sess.bug("clear_in_poststate_expr: \
+ unbound var");
+ }
}
+ }
+ _ { fcx.ccx.tcx.sess.bug("clear_in_poststate_expr"); }
}
- case (_) { /* do nothing */ }
+ }
+ _ {/* do nothing */ }
}
}
-fn set_in_poststate_ident(&fn_ctxt fcx, &node_id id, &ident ident,
- &poststate t) -> bool {
+fn set_in_poststate_ident(fcx: &fn_ctxt, id: &node_id, ident: &ident,
+ t: &poststate) -> bool {
ret set_in_poststate_(bit_num(fcx, ninit(id, ident)), t);
}
-fn set_in_prestate_constr(&fn_ctxt fcx, &tsconstr c, &prestate t) -> bool {
+fn set_in_prestate_constr(fcx: &fn_ctxt, c: &tsconstr, t: &prestate) -> bool {
ret set_in_poststate_(bit_num(fcx, c), t);
}
-fn clear_in_poststate_ident(&fn_ctxt fcx, &node_id id, &ident ident,
- &node_id parent) -> bool {
+fn clear_in_poststate_ident(fcx: &fn_ctxt, id: &node_id, ident: &ident,
+ parent: &node_id) -> bool {
ret kill_poststate(fcx, parent, ninit(id, ident));
}
-fn clear_in_prestate_ident(&fn_ctxt fcx, &node_id id, &ident ident,
- &node_id parent) -> bool {
+fn clear_in_prestate_ident(fcx: &fn_ctxt, id: &node_id, ident: &ident,
+ parent: &node_id) -> bool {
ret kill_prestate(fcx, parent, ninit(id, ident));
}
diff --git a/src/comp/middle/tstate/ck.rs b/src/comp/middle/tstate/ck.rs
index 503fbf8..37eace6 100644
--- a/src/comp/middle/tstate/ck.rs
+++ b/src/comp/middle/tstate/ck.rs
@@ -46,26 +46,27 @@
import pre_post_conditions::fn_pre_post;
import states::find_pre_post_state_fn;
-fn check_unused_vars(&fn_ctxt fcx) {
+fn check_unused_vars(fcx: &fn_ctxt) {
+
// FIXME: could be more efficient
- for (norm_constraint c in constraints(fcx)) {
- alt (c.c.node) {
- case (ninit(?id, ?v)) {
- if (!vec_contains(fcx.enclosing.used_vars, id)) {
- fcx.ccx.tcx.sess.span_warn(c.c.span,
- "Unused variable " + v);
- }
+ for c: norm_constraint in constraints(fcx) {
+ alt c.c.node {
+ ninit(id, v) {
+ if !vec_contains(fcx.enclosing.used_vars, id) {
+ fcx.ccx.tcx.sess.span_warn(c.c.span, "Unused variable " + v);
}
- case (_) { /* ignore pred constraints */ }
+ }
+ _ {/* ignore pred constraints */ }
}
}
}
-fn check_states_expr(&@expr e, &fn_ctxt fcx, &visit::vt[fn_ctxt] v) {
+fn check_states_expr(e: &@expr, fcx: &fn_ctxt, v: &visit::vt[fn_ctxt]) {
visit::visit_expr(e, fcx, v);
- let precond prec = expr_precond(fcx.ccx, e);
- let prestate pres = expr_prestate(fcx.ccx, e);
+ let prec: precond = expr_precond(fcx.ccx, e);
+ let pres: prestate = expr_prestate(fcx.ccx, e);
+
/*
log_err("check_states_expr:");
@@ -76,9 +77,9 @@
log_tritv_err(fcx, pres);
*/
- if (!implies(pres, prec)) {
- auto s = "";
- auto diff = first_difference_string(fcx, prec, pres);
+ if !implies(pres, prec) {
+ let s = "";
+ let diff = first_difference_string(fcx, prec, pres);
s +=
"Unsatisfied precondition constraint (for example, " + diff +
") for expression:\n";
@@ -91,12 +92,13 @@
}
}
-fn check_states_stmt(&@stmt s, &fn_ctxt fcx, &visit::vt[fn_ctxt] v) {
+fn check_states_stmt(s: &@stmt, fcx: &fn_ctxt, v: &visit::vt[fn_ctxt]) {
visit::visit_stmt(s, fcx, v);
- auto a = stmt_to_ann(fcx.ccx, *s);
- let precond prec = ann_precond(a);
- let prestate pres = ann_prestate(a);
+ let a = stmt_to_ann(fcx.ccx, *s);
+ let prec: precond = ann_precond(a);
+ let pres: prestate = ann_prestate(a);
+
/*
log_err("check_states_stmt:");
@@ -107,9 +109,9 @@
log_tritv_err(fcx, pres);
*/
- if (!implies(pres, prec)) {
- auto ss = "";
- auto diff = first_difference_string(fcx, prec, pres);
+ if !implies(pres, prec) {
+ let ss = "";
+ let diff = first_difference_string(fcx, prec, pres);
ss +=
"Unsatisfied precondition constraint (for example, " + diff +
") for statement:\n";
@@ -122,44 +124,45 @@
}
}
-fn check_states_against_conditions(&fn_ctxt fcx, &_fn f,
- &ast::ty_param[] tps,
- node_id id, &span sp, &fn_ident i) {
+fn check_states_against_conditions(fcx: &fn_ctxt, f: &_fn,
+ tps: &ast::ty_param[], id: node_id,
+ sp: &span, i: &fn_ident) {
/* Postorder traversal instead of pre is important
because we want the smallest possible erroneous statement
or expression. */
- auto visitor = visit::default_visitor[fn_ctxt]();
+ let visitor = visit::default_visitor[fn_ctxt]();
- visitor = @rec(visit_stmt=check_states_stmt,
- visit_expr=check_states_expr,
- visit_fn=do_nothing
- with *visitor);
+ visitor =
+ @{visit_stmt: check_states_stmt,
+ visit_expr: check_states_expr,
+ visit_fn: do_nothing with *visitor};
visit::visit_fn(f, tps, sp, i, id, fcx, visit::mk_vt(visitor));
/* Check that the return value is initialized */
- auto post = aux::block_poststate(fcx.ccx, f.body);
- let tsconstr ret_c = ninit(fcx.id, fcx.name);
- if (f.proto == ast::proto_fn && !promises(fcx, post, ret_c) &&
- !type_is_nil(fcx.ccx.tcx, ret_ty_of_fn(fcx.ccx.tcx, id)) &&
- f.decl.cf == return) {
+ let post = aux::block_poststate(fcx.ccx, f.body);
+ let ret_c: tsconstr = ninit(fcx.id, fcx.name);
+ if f.proto == ast::proto_fn && !promises(fcx, post, ret_c) &&
+ !type_is_nil(fcx.ccx.tcx, ret_ty_of_fn(fcx.ccx.tcx, id)) &&
+ f.decl.cf == return {
fcx.ccx.tcx.sess.span_note(f.body.span,
"In function " + fcx.name +
", not all control paths \
return a value");
fcx.ccx.tcx.sess.span_fatal(f.decl.output.span,
- "see declared return type of '" +
- ty_to_str(*f.decl.output) + "'");
+ "see declared return type of '" +
+ ty_to_str(*f.decl.output) + "'");
} else if (f.decl.cf == noreturn) {
+
// check that this really always fails
// the fcx.id bit means "returns" for a returning fn,
// "diverges" for a non-returning fn
- if (!promises(fcx, post, ret_c)) {
+ if !promises(fcx, post, ret_c) {
fcx.ccx.tcx.sess.span_fatal(f.body.span,
- "In non-returning function " + fcx.name
- +
- ", some control paths may \
+ "In non-returning function " +
+ fcx.name +
+ ", some control paths may \
return to the caller");
}
}
@@ -168,12 +171,12 @@
check_unused_vars(fcx);
}
-fn check_fn_states(&fn_ctxt fcx, &_fn f, &ast::ty_param[] tps,
- node_id id, &span sp, &fn_ident i) {
+fn check_fn_states(fcx: &fn_ctxt, f: &_fn, tps: &ast::ty_param[], id: node_id,
+ sp: &span, i: &fn_ident) {
/* Compute the pre- and post-states for this function */
// Fixpoint iteration
- while (find_pre_post_state_fn(fcx, f)) {}
+ while find_pre_post_state_fn(fcx, f) { }
/* Now compare each expr's pre-state to its precondition
and post-state to its postcondition */
@@ -181,21 +184,20 @@
check_states_against_conditions(fcx, f, tps, id, sp, i);
}
-fn fn_states(&_fn f, &ast::ty_param[] tps,
- &span sp, &fn_ident i, node_id id, &crate_ctxt ccx,
- &visit::vt[crate_ctxt] v) {
+fn fn_states(f: &_fn, tps: &ast::ty_param[], sp: &span, i: &fn_ident,
+ id: node_id, ccx: &crate_ctxt, v: &visit::vt[crate_ctxt]) {
visit::visit_fn(f, tps, sp, i, id, ccx, v);
/* Look up the var-to-bit-num map for this function */
assert (ccx.fm.contains_key(id));
- auto f_info = ccx.fm.get(id);
- auto name = option::from_maybe("anon", i);
- auto fcx = rec(enclosing=f_info, id=id, name=name, ccx=ccx);
+ let f_info = ccx.fm.get(id);
+ let name = option::from_maybe("anon", i);
+ let fcx = {enclosing: f_info, id: id, name: name, ccx: ccx};
check_fn_states(fcx, f, tps, id, sp, i);
}
-fn check_crate(ty::ctxt cx, @crate crate) {
- let crate_ctxt ccx = new_crate_ctxt(cx);
+fn check_crate(cx: ty::ctxt, crate: @crate) {
+ let ccx: crate_ctxt = new_crate_ctxt(cx);
/* Build the global map from function id to var-to-bit-num-map */
mk_f_to_fn_info(ccx, crate);
@@ -204,13 +206,13 @@
annotate_crate(ccx, *crate);
/* Compute the pre and postcondition for every subexpression */
- auto vtor = visit::default_visitor[crate_ctxt]();
- vtor = @rec(visit_fn=fn_pre_post with *vtor);
+ let vtor = visit::default_visitor[crate_ctxt]();
+ vtor = @{visit_fn: fn_pre_post with *vtor};
visit::visit_crate(*crate, ccx, visit::mk_vt(vtor));
/* Check the pre- and postcondition against the pre- and poststate
for every expression */
- vtor = @rec(visit_fn=fn_states with *vtor);
+ vtor = @{visit_fn: fn_states with *vtor};
visit::visit_crate(*crate, ccx, visit::mk_vt(vtor));
}
//
diff --git a/src/comp/middle/tstate/collect_locals.rs b/src/comp/middle/tstate/collect_locals.rs
index d1f2118..f9b3012 100644
--- a/src/comp/middle/tstate/collect_locals.rs
+++ b/src/comp/middle/tstate/collect_locals.rs
@@ -11,79 +11,73 @@
import syntax::codemap::span;
import syntax::ast::respan;
-type ctxt = rec(@mutable (sp_constr[]) cs, ty::ctxt tcx);
+type ctxt = {cs: @mutable sp_constr[], tcx: ty::ctxt};
-fn collect_local(&@local loc, &ctxt cx, &visit::vt[ctxt] v) {
+fn collect_local(loc: &@local, cx: &ctxt, v: &visit::vt[ctxt]) {
log "collect_local: pushing " + loc.node.ident;
*cx.cs += ~[respan(loc.span, ninit(loc.node.id, loc.node.ident))];
visit::visit_local(loc, cx, v);
}
-fn collect_pred(&@expr e, &ctxt cx, &visit::vt[ctxt] v) {
- alt (e.node) {
- case (expr_check(_, ?ch)) {
- *cx.cs += ~[expr_to_constr(cx.tcx, ch)];
+fn collect_pred(e: &@expr, cx: &ctxt, v: &visit::vt[ctxt]) {
+ alt e.node {
+ expr_check(_, ch) { *cx.cs += ~[expr_to_constr(cx.tcx, ch)]; }
+ expr_if_check(ex, _, _) { *cx.cs += ~[expr_to_constr(cx.tcx, ex)]; }
+
+ // If it's a call, generate appropriate instances of the
+ // call's constraints.
+ expr_call(operator, operands) {
+ for c: @ty::constr in constraints_expr(cx.tcx, operator) {
+ let ct: sp_constr =
+ respan(c.span,
+ aux::substitute_constr_args(cx.tcx, operands, c));
+ *cx.cs += ~[ct];
}
- case (expr_if_check(?ex, _, _)) {
- *cx.cs += ~[expr_to_constr(cx.tcx, ex)];
- }
- // If it's a call, generate appropriate instances of the
- // call's constraints.
- case (expr_call(?operator, ?operands)) {
- for (@ty::constr c in constraints_expr(cx.tcx, operator)) {
- let sp_constr ct = respan(c.span,
- aux::substitute_constr_args(cx.tcx, operands,
- c));
- *cx.cs += ~[ct];
- }
- }
- case (_) { }
+ }
+ _ { }
}
// visit subexpressions
visit::visit_expr(e, cx, v);
}
-fn find_locals(&ty::ctxt tcx, &_fn f, &ty_param[] tps, &span sp, &fn_ident i,
- node_id id) -> ctxt {
- let ctxt cx = rec(cs=@mutable ~[], tcx=tcx);
- auto visitor = visit::default_visitor[ctxt]();
+fn find_locals(tcx: &ty::ctxt, f: &_fn, tps: &ty_param[], sp: &span,
+ i: &fn_ident, id: node_id) -> ctxt {
+ let cx: ctxt = {cs: @mutable ~[], tcx: tcx};
+ let visitor = visit::default_visitor[ctxt]();
- visitor = @rec(visit_local=collect_local,
- visit_expr=collect_pred,
- visit_fn=do_nothing
- with *visitor);
+ visitor =
+ @{visit_local: collect_local,
+ visit_expr: collect_pred,
+ visit_fn: do_nothing with *visitor};
visit::visit_fn(f, tps, sp, i, id, cx, visit::mk_vt(visitor));
ret cx;
}
-fn add_constraint(&ty::ctxt tcx, sp_constr c, uint next, constr_map tbl) ->
- uint {
+fn add_constraint(tcx: &ty::ctxt, c: sp_constr, next: uint, tbl: constr_map)
+ -> uint {
log constraint_to_str(tcx, c) + " |-> " + std::uint::str(next);
- alt (c.node) {
- case (ninit(?id, ?i)) { tbl.insert(local_def(id),
- cinit(next, c.span, i)); }
- case (npred(?p, ?d_id, ?args)) {
- alt (tbl.find(d_id)) {
- case (some(?ct)) {
- alt (ct) {
- case (cinit(_, _, _)) {
- tcx.sess.bug("add_constraint: same def_id used" +
- " as a variable and a pred");
- }
- case (cpred(_, ?pds)) {
- *pds += ~[respan(c.span,
- rec(args=args, bit_num=next))];
- }
- }
- }
- case (none) {
- let @mutable(pred_args[]) rslt = @mutable(~[respan(c.span,
- rec(args=args,
- bit_num=next))]);
- tbl.insert(d_id, cpred(p, rslt));
- }
+ alt c.node {
+ ninit(id, i) { tbl.insert(local_def(id), cinit(next, c.span, i)); }
+ npred(p, d_id, args) {
+ alt tbl.find(d_id) {
+ some(ct) {
+ alt ct {
+ cinit(_, _, _) {
+ tcx.sess.bug("add_constraint: same def_id used" +
+ " as a variable and a pred");
+ }
+ cpred(_, pds) {
+ *pds += ~[respan(c.span, {args: args, bit_num: next})];
+ }
}
+ }
+ none. {
+ let rslt: @mutable pred_args[] =
+ @mutable ~[respan(c.span, {args: args, bit_num: next})];
+ tbl.insert(d_id, cpred(p, rslt));
+ }
}
+ }
}
ret next + 1u;
}
@@ -91,23 +85,23 @@
/* builds a table mapping each local var defined in f
to a bit number in the precondition/postcondition vectors */
-fn mk_fn_info(&crate_ctxt ccx, &_fn f, &ty_param[] tp,
- &span f_sp, &fn_ident f_name, node_id id) {
- auto name = fn_ident_to_string(id, f_name);
- auto res_map = @new_def_hash[constraint]();
- let uint next = 0u;
+fn mk_fn_info(ccx: &crate_ctxt, f: &_fn, tp: &ty_param[], f_sp: &span,
+ f_name: &fn_ident, id: node_id) {
+ let name = fn_ident_to_string(id, f_name);
+ let res_map = @new_def_hash[constraint]();
+ let next: uint = 0u;
- let ctxt cx = find_locals(ccx.tcx, f, tp, f_sp, f_name, id);
+ let cx: ctxt = find_locals(ccx.tcx, f, tp, f_sp, f_name, id);
/* now we have to add bit nums for both the constraints
and the variables... */
- for (sp_constr c in { *cx.cs }) {
+ for c: sp_constr in { *cx.cs } {
next = add_constraint(cx.tcx, c, next, res_map);
}
/* if this function has any constraints, instantiate them to the
argument names and add them */
- auto sc;
- for (@constr c in f.decl.constraints) {
+ let sc;
+ for c: @constr in f.decl.constraints {
sc = ast_constr_to_sp_constr(cx.tcx, f.decl.inputs, c);
next = add_constraint(cx.tcx, sc, next, res_map);
}
@@ -116,26 +110,27 @@
we can safely use the function's name itself for this purpose */
add_constraint(cx.tcx, respan(f_sp, ninit(id, name)), next, res_map);
- let @mutable node_id[] v = @mutable ~[];
- auto rslt =
- rec(constrs=res_map,
- num_constraints=ivec::len(*cx.cs) + ivec::len(f.decl.constraints)
- + 1u,
- cf=f.decl.cf,
- used_vars=v);
+ let v: @mutable node_id[] = @mutable ~[];
+ let rslt =
+ {constrs: res_map,
+ num_constraints:
+ ivec::len(*cx.cs) + ivec::len(f.decl.constraints) + 1u,
+ cf: f.decl.cf,
+ used_vars: v};
ccx.fm.insert(id, rslt);
log name + " has " + std::uint::str(num_constraints(rslt)) +
- " constraints";
+ " constraints";
}
/* initializes the global fn_info_map (mapping each function ID, including
nested locally defined functions, onto a mapping from local variable name
to bit number) */
-fn mk_f_to_fn_info(&crate_ctxt ccx, @crate c) {
- auto visitor = visit::mk_simple_visitor
- (@rec(visit_fn=bind mk_fn_info(ccx, _, _, _, _, _)
- with *visit::default_simple_visitor()));
+fn mk_f_to_fn_info(ccx: &crate_ctxt, c: @crate) {
+ let visitor =
+ visit::mk_simple_visitor(@{visit_fn:
+ bind mk_fn_info(ccx, _, _, _, _, _)
+ with *visit::default_simple_visitor()});
visit::visit_crate(*c, (), visitor);
}
//
diff --git a/src/comp/middle/tstate/pre_post_conditions.rs b/src/comp/middle/tstate/pre_post_conditions.rs
index 4082502..c849ac8b 100644
--- a/src/comp/middle/tstate/pre_post_conditions.rs
+++ b/src/comp/middle/tstate/pre_post_conditions.rs
@@ -46,66 +46,65 @@
import syntax::codemap::span;
import util::ppaux::fn_ident_to_string;
-fn find_pre_post_mod(&_mod m) -> _mod {
+fn find_pre_post_mod(m: &_mod) -> _mod {
log "implement find_pre_post_mod!";
fail;
}
-fn find_pre_post_native_mod(&native_mod m) -> native_mod {
+fn find_pre_post_native_mod(m: &native_mod) -> native_mod {
log "implement find_pre_post_native_mod";
fail;
}
-fn find_pre_post_obj(&crate_ctxt ccx, _obj o) {
- fn do_a_method(crate_ctxt ccx, &@method m) {
+fn find_pre_post_obj(ccx: &crate_ctxt, o: _obj) {
+ fn do_a_method(ccx: crate_ctxt, m: &@method) {
assert (ccx.fm.contains_key(m.node.id));
- let fn_ctxt fcx =
- rec(enclosing=ccx.fm.get(m.node.id),
- id=m.node.id,
- name=m.node.ident,
- ccx=ccx);
+ let fcx: fn_ctxt =
+ {enclosing: ccx.fm.get(m.node.id),
+ id: m.node.id,
+ name: m.node.ident,
+ ccx: ccx};
find_pre_post_fn(fcx, m.node.meth);
}
- for (@method m in o.methods) { do_a_method(ccx, m); }
+ for m: @method in o.methods { do_a_method(ccx, m); }
option::map[@method, ()](bind do_a_method(ccx, _), o.dtor);
}
-fn find_pre_post_item(&crate_ctxt ccx, &item i) {
- alt (i.node) {
- case (item_const(_, ?e)) {
- // make a fake fcx
- let @mutable node_id[] v = @mutable ~[];
- auto fake_fcx =
- rec(enclosing=rec(constrs=@new_def_hash[constraint](),
- num_constraints=0u,
- cf=return,
- used_vars=v),
- id=0,
- name="",
- ccx=ccx);
- find_pre_post_expr(fake_fcx, e);
- }
- case (item_fn(?f, _)) {
- assert (ccx.fm.contains_key(i.id));
- auto fcx =
- rec(enclosing=ccx.fm.get(i.id),
- id=i.id,
- name=i.ident,
- ccx=ccx);
- find_pre_post_fn(fcx, f);
- }
- case (item_mod(?m)) { find_pre_post_mod(m); }
- case (item_native_mod(?nm)) { find_pre_post_native_mod(nm); }
- case (item_ty(_, _)) { ret; }
- case (item_tag(_, _)) { ret; }
- case (item_res(?dtor, ?dtor_id, _, _)) {
- auto fcx = rec(enclosing=ccx.fm.get(dtor_id),
- id=dtor_id,
- name=i.ident,
- ccx=ccx);
- find_pre_post_fn(fcx, dtor);
- }
- case (item_obj(?o, _, _)) { find_pre_post_obj(ccx, o); }
+fn find_pre_post_item(ccx: &crate_ctxt, i: &item) {
+ alt i.node {
+ item_const(_, e) {
+ // make a fake fcx
+ let v: @mutable node_id[] = @mutable ~[];
+ let fake_fcx =
+ {enclosing:
+ {constrs: @new_def_hash[constraint](),
+ num_constraints: 0u,
+ cf: return,
+ used_vars: v},
+ id: 0,
+ name: "",
+ ccx: ccx};
+ find_pre_post_expr(fake_fcx, e);
+ }
+ item_fn(f, _) {
+ assert (ccx.fm.contains_key(i.id));
+ let fcx =
+ {enclosing: ccx.fm.get(i.id), id: i.id, name: i.ident, ccx: ccx};
+ find_pre_post_fn(fcx, f);
+ }
+ item_mod(m) { find_pre_post_mod(m); }
+ item_native_mod(nm) { find_pre_post_native_mod(nm); }
+ item_ty(_, _) { ret; }
+ item_tag(_, _) { ret; }
+ item_res(dtor, dtor_id, _, _) {
+ let fcx =
+ {enclosing: ccx.fm.get(dtor_id),
+ id: dtor_id,
+ name: i.ident,
+ ccx: ccx};
+ find_pre_post_fn(fcx, dtor);
+ }
+ item_obj(o, _, _) { find_pre_post_obj(ccx, o); }
}
}
@@ -114,545 +113,521 @@
sets the precondition in a to be the result of combining
the preconditions for <args>, and the postcondition in a to
be the union of all postconditions for <args> */
-fn find_pre_post_exprs(&fn_ctxt fcx, &(@expr)[] args, node_id id) {
- if (ivec::len[@expr](args) > 0u) {
+fn find_pre_post_exprs(fcx: &fn_ctxt, args: &(@expr)[], id: node_id) {
+ if ivec::len[@expr](args) > 0u {
log "find_pre_post_exprs: oper =";
log_expr(*args.(0));
}
- fn do_one(fn_ctxt fcx, &@expr e) { find_pre_post_expr(fcx, e); }
- for (@expr e in args) { do_one(fcx, e); }
+ fn do_one(fcx: fn_ctxt, e: &@expr) { find_pre_post_expr(fcx, e); }
+ for e: @expr in args { do_one(fcx, e); }
- fn get_pp(crate_ctxt ccx, &@expr e) -> pre_and_post {
+ fn get_pp(ccx: crate_ctxt, e: &@expr) -> pre_and_post {
ret expr_pp(ccx, e);
}
- auto pps = ivec::map[@expr, pre_and_post](bind get_pp(fcx.ccx, _), args);
+ let pps = ivec::map[@expr, pre_and_post](bind get_pp(fcx.ccx, _), args);
set_pre_and_post(fcx.ccx, id, seq_preconds(fcx, pps),
seq_postconds(fcx, ivec::map(get_post, pps)));
}
-fn find_pre_post_loop(&fn_ctxt fcx, &@local l, &@expr index, &blk body,
- node_id id) {
+fn find_pre_post_loop(fcx: &fn_ctxt, l: &@local, index: &@expr, body: &blk,
+ id: node_id) {
find_pre_post_expr(fcx, index);
find_pre_post_block(fcx, body);
- auto v_init = ninit(l.node.id, l.node.ident);
+ let v_init = ninit(l.node.id, l.node.ident);
relax_precond_block(fcx, bit_num(fcx, v_init) as node_id, body);
// Hack: for-loop index variables are frequently ignored,
// so we pretend they're used
use_var(fcx, l.node.id);
- auto loop_precond = seq_preconds(fcx, ~[expr_pp(fcx.ccx, index),
- block_pp(fcx.ccx, body)]);
- auto loop_postcond = intersect_states(expr_postcond(fcx.ccx, index),
- block_postcond(fcx.ccx, body));
+ let loop_precond =
+ seq_preconds(fcx,
+ ~[expr_pp(fcx.ccx, index), block_pp(fcx.ccx, body)]);
+ let loop_postcond =
+ intersect_states(expr_postcond(fcx.ccx, index),
+ block_postcond(fcx.ccx, body));
copy_pre_post_(fcx.ccx, id, loop_precond, loop_postcond);
}
// Generates a pre/post assuming that a is the
// annotation for an if-expression with consequent conseq
// and alternative maybe_alt
-fn join_then_else(&fn_ctxt fcx, &@expr antec, &blk conseq,
- &option::t[@expr] maybe_alt, node_id id, &if_ty chck) {
+fn join_then_else(fcx: &fn_ctxt, antec: &@expr, conseq: &blk,
+ maybe_alt: &option::t[@expr], id: node_id, chck: &if_ty) {
find_pre_post_expr(fcx, antec);
find_pre_post_block(fcx, conseq);
- alt (maybe_alt) {
- case (none) {
- alt (chck) {
- case (if_check) {
- let sp_constr c = expr_to_constr(fcx.ccx.tcx, antec);
- gen(fcx, antec.id, c.node);
- }
- case (_) {}
- }
-
- auto precond_res = seq_preconds(fcx,
- ~[expr_pp(fcx.ccx, antec), block_pp(fcx.ccx, conseq)]);
- set_pre_and_post(fcx.ccx, id, precond_res,
- expr_poststate(fcx.ccx, antec));
+ alt maybe_alt {
+ none. {
+ alt chck {
+ if_check. {
+ let c: sp_constr = expr_to_constr(fcx.ccx.tcx, antec);
+ gen(fcx, antec.id, c.node);
+ }
+ _ { }
}
- case (some(?altern)) {
- /*
- if check = if_check, then
- be sure that the predicate implied by antec
- is *not* true in the alternative
- */
- find_pre_post_expr(fcx, altern);
- auto precond_false_case = seq_preconds(fcx,
- ~[expr_pp(fcx.ccx, antec), expr_pp(fcx.ccx, altern)]);
- auto postcond_false_case = seq_postconds(fcx,
- ~[expr_postcond(fcx.ccx, antec),
- expr_postcond(fcx.ccx, altern)]);
- /* Be sure to set the bit for the check condition here,
- so that it's *not* set in the alternative. */
- alt (chck) {
- case (if_check) {
- let sp_constr c = expr_to_constr(fcx.ccx.tcx, antec);
- gen(fcx, antec.id, c.node);
- }
- case (_) {}
- }
- auto precond_true_case = seq_preconds(fcx,
- ~[expr_pp(fcx.ccx, antec), block_pp(fcx.ccx, conseq)]);
- auto postcond_true_case = seq_postconds(fcx,
- ~[expr_postcond(fcx.ccx, antec),
- block_postcond(fcx.ccx, conseq)]);
+ let precond_res =
+ seq_preconds(fcx,
+ ~[expr_pp(fcx.ccx, antec),
+ block_pp(fcx.ccx, conseq)]);
+ set_pre_and_post(fcx.ccx, id, precond_res,
+ expr_poststate(fcx.ccx, antec));
+ }
+ some(altern) {
+ /*
+ if check = if_check, then
+ be sure that the predicate implied by antec
+ is *not* true in the alternative
+ */
+ find_pre_post_expr(fcx, altern);
+ let precond_false_case =
+ seq_preconds(fcx,
+ ~[expr_pp(fcx.ccx, antec),
+ expr_pp(fcx.ccx, altern)]);
+ let postcond_false_case =
+ seq_postconds(fcx,
+ ~[expr_postcond(fcx.ccx, antec),
+ expr_postcond(fcx.ccx, altern)]);
- auto precond_res = seq_postconds(fcx, ~[precond_true_case,
- precond_false_case]);
- auto postcond_res =
- intersect_states(postcond_true_case, postcond_false_case);
- set_pre_and_post(fcx.ccx, id, precond_res, postcond_res);
+ /* Be sure to set the bit for the check condition here,
+ so that it's *not* set in the alternative. */
+ alt chck {
+ if_check. {
+ let c: sp_constr = expr_to_constr(fcx.ccx.tcx, antec);
+ gen(fcx, antec.id, c.node);
+ }
+ _ { }
}
+ let precond_true_case =
+ seq_preconds(fcx,
+ ~[expr_pp(fcx.ccx, antec),
+ block_pp(fcx.ccx, conseq)]);
+ let postcond_true_case =
+ seq_postconds(fcx,
+ ~[expr_postcond(fcx.ccx, antec),
+ block_postcond(fcx.ccx, conseq)]);
+
+ let precond_res =
+ seq_postconds(fcx, ~[precond_true_case, precond_false_case]);
+ let postcond_res =
+ intersect_states(postcond_true_case, postcond_false_case);
+ set_pre_and_post(fcx.ccx, id, precond_res, postcond_res);
+ }
}
}
-fn gen_if_local(&fn_ctxt fcx, @expr lhs, @expr rhs, node_id larger_id,
- node_id new_var, &path pth) {
- alt (node_id_to_def(fcx.ccx, new_var)) {
- case (some(?d)) {
- alt (d) {
- case (def_local(?d_id)) {
- find_pre_post_expr(fcx, rhs);
- auto p = expr_pp(fcx.ccx, rhs);
- set_pre_and_post(fcx.ccx, larger_id, p.precondition,
- p.postcondition);
- gen(fcx, larger_id,
- ninit(d_id.node, path_to_ident(fcx.ccx.tcx, pth)));
- }
- case (_) { find_pre_post_exprs(fcx, ~[lhs, rhs], larger_id); }
- }
+fn gen_if_local(fcx: &fn_ctxt, lhs: @expr, rhs: @expr, larger_id: node_id,
+ new_var: node_id, pth: &path) {
+ alt node_id_to_def(fcx.ccx, new_var) {
+ some(d) {
+ alt d {
+ def_local(d_id) {
+ find_pre_post_expr(fcx, rhs);
+ let p = expr_pp(fcx.ccx, rhs);
+ set_pre_and_post(fcx.ccx, larger_id, p.precondition,
+ p.postcondition);
+ gen(fcx, larger_id,
+ ninit(d_id.node, path_to_ident(fcx.ccx.tcx, pth)));
+ }
+ _ { find_pre_post_exprs(fcx, ~[lhs, rhs], larger_id); }
}
- case (_) { find_pre_post_exprs(fcx, ~[lhs, rhs], larger_id); }
+ }
+ _ { find_pre_post_exprs(fcx, ~[lhs, rhs], larger_id); }
}
}
-fn handle_update(&fn_ctxt fcx, &@expr parent,
- &@expr lhs, &@expr rhs, oper_type ty) {
+fn handle_update(fcx: &fn_ctxt, parent: &@expr, lhs: &@expr, rhs: &@expr,
+ ty: oper_type) {
find_pre_post_expr(fcx, rhs);
- alt (lhs.node) {
- case (expr_path(?p)) {
- auto post = expr_postcond(fcx.ccx, parent);
- auto tmp = tritv_clone(post);
+ alt lhs.node {
+ expr_path(p) {
+ let post = expr_postcond(fcx.ccx, parent);
+ let tmp = tritv_clone(post);
- alt (ty) {
- case (oper_move) {
- if (is_path(rhs)) {
- forget_in_postcond(fcx, parent.id, rhs.id);
- }
- }
- case (oper_swap) {
- forget_in_postcond_still_init(fcx, parent.id, lhs.id);
- forget_in_postcond_still_init(fcx, parent.id, rhs.id);
- }
- case (oper_assign) {
- forget_in_postcond_still_init(fcx, parent.id, lhs.id);
- }
- case (_) {
- // pure and assign_op require the lhs to be init'd
- auto df = node_id_to_def_strict(fcx.ccx.tcx, lhs.id);
- alt (df) {
- case (def_local(?d_id)) {
- auto i =
- bit_num(fcx, ninit(d_id.node,
- path_to_ident(fcx.ccx.tcx, p)));
- require_and_preserve(i, expr_pp(fcx.ccx, lhs));
- }
- case (_) {}
- }
- }
+ alt ty {
+ oper_move. {
+ if is_path(rhs) { forget_in_postcond(fcx, parent.id, rhs.id); }
+ }
+ oper_swap. {
+ forget_in_postcond_still_init(fcx, parent.id, lhs.id);
+ forget_in_postcond_still_init(fcx, parent.id, rhs.id);
+ }
+ oper_assign. {
+ forget_in_postcond_still_init(fcx, parent.id, lhs.id);
+ }
+ _ {
+ // pure and assign_op require the lhs to be init'd
+ let df = node_id_to_def_strict(fcx.ccx.tcx, lhs.id);
+ alt df {
+ def_local(d_id) {
+ let i =
+ bit_num(fcx,
+ ninit(d_id.node, path_to_ident(fcx.ccx.tcx, p)));
+ require_and_preserve(i, expr_pp(fcx.ccx, lhs));
+ }
+ _ { }
}
+ }
+ }
- gen_if_local(fcx, lhs, rhs, parent.id, lhs.id, p);
- alt (rhs.node) {
- case (expr_path(?p1)) {
- auto d = local_node_id_to_local_def_id(fcx, lhs.id);
- auto d1 = local_node_id_to_local_def_id(fcx, rhs.id);
- alt (d) {
- case (some(?id)) {
- alt (d1) {
- case (some(?id1)) {
- auto instlhs =
- rec(ident=path_to_ident
- (fcx.ccx.tcx, p),
- node=id);
- auto instrhs =
- rec(ident=path_to_ident
- (fcx.ccx.tcx, p1),
- node=id1);
- copy_in_poststate_two(fcx, tmp,
- post, instlhs, instrhs, ty);
- }
- case (_) {}
- }
- }
- case (_) {}
- }
+ gen_if_local(fcx, lhs, rhs, parent.id, lhs.id, p);
+ alt rhs.node {
+ expr_path(p1) {
+ let d = local_node_id_to_local_def_id(fcx, lhs.id);
+ let d1 = local_node_id_to_local_def_id(fcx, rhs.id);
+ alt d {
+ some(id) {
+ alt d1 {
+ some(id1) {
+ let instlhs =
+ {ident: path_to_ident(fcx.ccx.tcx, p), node: id};
+ let instrhs =
+ {ident: path_to_ident(fcx.ccx.tcx, p1), node: id1};
+ copy_in_poststate_two(fcx, tmp, post, instlhs, instrhs,
+ ty);
+ }
+ _ { }
}
- case (_) { /* do nothing */ }
+ }
+ _ { }
}
+ }
+ _ {/* do nothing */ }
}
- case (_) {
- find_pre_post_expr(fcx, lhs);
- }
+ }
+ _ { find_pre_post_expr(fcx, lhs); }
}
}
-fn handle_var(&fn_ctxt fcx, &pre_and_post rslt, node_id id, ident name) {
- auto df = node_id_to_def_upvar_strict(fcx, id);
- alt (df) {
- case (def_local(?d_id)) {
- auto i = bit_num(fcx, ninit(d_id.node, name));
- use_var(fcx, d_id.node);
- require_and_preserve(i, rslt);
- }
- case (_) {/* nothing to check */ }
+fn handle_var(fcx: &fn_ctxt, rslt: &pre_and_post, id: node_id, name: ident) {
+ let df = node_id_to_def_upvar_strict(fcx, id);
+ alt df {
+ def_local(d_id) {
+ let i = bit_num(fcx, ninit(d_id.node, name));
+ use_var(fcx, d_id.node);
+ require_and_preserve(i, rslt);
+ }
+ _ {/* nothing to check */ }
}
}
/* Fills in annotations as a side effect. Does not rebuild the expr */
-fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
- auto enclosing = fcx.enclosing;
- auto num_local_vars = num_constraints(enclosing);
- fn do_rand_(fn_ctxt fcx, &@expr e) { find_pre_post_expr(fcx, e); }
+fn find_pre_post_expr(fcx: &fn_ctxt, e: @expr) {
+ let enclosing = fcx.enclosing;
+ let num_local_vars = num_constraints(enclosing);
+ fn do_rand_(fcx: fn_ctxt, e: &@expr) { find_pre_post_expr(fcx, e); }
- alt (e.node) {
- case (expr_call(?operator, ?operands)) {
- auto args = /* copy */ operands;
- args += ~[operator];
- find_pre_post_exprs(fcx, args, e.id);
- /* see if the call has any constraints on its type */
- for (@ty::constr c in constraints_expr(fcx.ccx.tcx, operator))
- {
- auto i =
- bit_num(fcx, substitute_constr_args(fcx.ccx.tcx,
- args, c));
- require(i, expr_pp(fcx.ccx, e));
- }
+ alt e.node {
+ expr_call(operator, operands) {
+ let /* copy */args = operands;
+ args += ~[operator];
- /* if this is a failing call, its postcondition sets everything */
- alt (controlflow_expr(fcx.ccx, operator)) {
- case (noreturn) { set_postcond_false(fcx.ccx, e.id); }
- case (_) { }
- }
+ find_pre_post_exprs(fcx, args, e.id);
+ /* see if the call has any constraints on its type */
+ for c: @ty::constr in constraints_expr(fcx.ccx.tcx, operator) {
+ let i =
+ bit_num(fcx, substitute_constr_args(fcx.ccx.tcx, args, c));
+ require(i, expr_pp(fcx.ccx, e));
}
- case (expr_spawn(_, _, ?operator, ?operands)) {
- auto args = /* copy */ operands;
- args += ~[operator];
- find_pre_post_exprs(fcx, args, e.id);
+
+
+ /* if this is a failing call, its postcondition sets everything */
+ alt controlflow_expr(fcx.ccx, operator) {
+ noreturn. { set_postcond_false(fcx.ccx, e.id); }
+ _ { }
}
- case (expr_vec(?args, _, _)) {
- find_pre_post_exprs(fcx, args, e.id);
- }
- case (expr_path(?p)) {
- auto rslt = expr_pp(fcx.ccx, e);
- clear_pp(rslt);
- handle_var(fcx, rslt, e.id, path_to_ident(fcx.ccx.tcx, p));
- }
- case (expr_self_method(?v)) { clear_pp(expr_pp(fcx.ccx, e)); }
- case (expr_log(_, ?arg)) {
+ }
+ expr_spawn(_, _, operator, operands) {
+ let /* copy */args = operands;
+ args += ~[operator];
+ find_pre_post_exprs(fcx, args, e.id);
+ }
+ expr_vec(args, _, _) { find_pre_post_exprs(fcx, args, e.id); }
+ expr_path(p) {
+ let rslt = expr_pp(fcx.ccx, e);
+ clear_pp(rslt);
+ handle_var(fcx, rslt, e.id, path_to_ident(fcx.ccx.tcx, p));
+ }
+ expr_self_method(v) { clear_pp(expr_pp(fcx.ccx, e)); }
+ expr_log(_, arg) {
+ find_pre_post_expr(fcx, arg);
+ copy_pre_post(fcx.ccx, e.id, arg);
+ }
+ expr_chan(arg) {
+ find_pre_post_expr(fcx, arg);
+ copy_pre_post(fcx.ccx, e.id, arg);
+ }
+ expr_put(opt) {
+ alt opt {
+ some(arg) {
find_pre_post_expr(fcx, arg);
copy_pre_post(fcx.ccx, e.id, arg);
+ }
+ none. { clear_pp(expr_pp(fcx.ccx, e)); }
}
- case (expr_chan(?arg)) {
- find_pre_post_expr(fcx, arg);
- copy_pre_post(fcx.ccx, e.id, arg);
- }
- case (expr_put(?opt)) {
- alt (opt) {
- case (some(?arg)) {
- find_pre_post_expr(fcx, arg);
- copy_pre_post(fcx.ccx, e.id, arg);
- }
- case (none) { clear_pp(expr_pp(fcx.ccx, e)); }
- }
- }
- case (expr_fn(?f)) {
- auto rslt = expr_pp(fcx.ccx, e);
- clear_pp(rslt);
- auto upvars = freevars::get_freevar_uses(fcx.ccx.tcx, e.id);
- for (node_id id in *upvars) {
- handle_var(fcx, rslt, id, "upvar");
- }
- }
- case (expr_block(?b)) {
- find_pre_post_block(fcx, b);
- auto p = block_pp(fcx.ccx, b);
- set_pre_and_post(fcx.ccx, e.id, p.precondition, p.postcondition);
- }
- case (expr_rec(?fields, ?maybe_base)) {
- auto es = field_exprs(fields);
- alt (maybe_base) {
- case (none) { /* no-op */ }
- case (some(?b)) { es += ~[b]; }
- }
- find_pre_post_exprs(fcx, es, e.id);
- }
- case (expr_move(?lhs, ?rhs)) {
- handle_update(fcx, e, lhs, rhs, oper_move);
- }
- case (expr_swap(?lhs, ?rhs)) {
- handle_update(fcx, e, lhs, rhs, oper_swap);
- }
- case (expr_assign(?lhs, ?rhs)) {
- handle_update(fcx, e, lhs, rhs, oper_assign);
- }
- case (expr_recv(?lhs, ?rhs)) {
- // note inversion of lhs and rhs
- handle_update(fcx, e, rhs, lhs, oper_assign);
- }
- case (expr_assign_op(_, ?lhs, ?rhs)) {
- /* Different from expr_assign in that the lhs *must*
- already be initialized */
+ }
+ expr_fn(f) {
+ let rslt = expr_pp(fcx.ccx, e);
+ clear_pp(rslt);
+ let upvars = freevars::get_freevar_uses(fcx.ccx.tcx, e.id);
+ for id: node_id in *upvars { handle_var(fcx, rslt, id, "upvar"); }
+ }
+ expr_block(b) {
+ find_pre_post_block(fcx, b);
+ let p = block_pp(fcx.ccx, b);
+ set_pre_and_post(fcx.ccx, e.id, p.precondition, p.postcondition);
+ }
+ expr_rec(fields, maybe_base) {
+ let es = field_exprs(fields);
+ alt maybe_base { none. {/* no-op */ } some(b) { es += ~[b]; } }
+ find_pre_post_exprs(fcx, es, e.id);
+ }
+ expr_move(lhs, rhs) { handle_update(fcx, e, lhs, rhs, oper_move); }
+ expr_swap(lhs, rhs) { handle_update(fcx, e, lhs, rhs, oper_swap); }
+ expr_assign(lhs, rhs) { handle_update(fcx, e, lhs, rhs, oper_assign); }
+ expr_recv(lhs, rhs) {
+ // note inversion of lhs and rhs
+ handle_update(fcx, e, rhs, lhs, oper_assign);
+ }
+ expr_assign_op(_, lhs, rhs) {
+ /* Different from expr_assign in that the lhs *must*
+ already be initialized */
- find_pre_post_exprs(fcx, ~[lhs, rhs], e.id);
- forget_in_postcond_still_init(fcx, e.id, lhs.id);
+ find_pre_post_exprs(fcx, ~[lhs, rhs], e.id);
+ forget_in_postcond_still_init(fcx, e.id, lhs.id);
+ }
+ expr_lit(_) { clear_pp(expr_pp(fcx.ccx, e)); }
+ expr_ret(maybe_val) {
+ alt maybe_val {
+ none. {
+ clear_precond(fcx.ccx, e.id);
+ set_postcond_false(fcx.ccx, e.id);
+ }
+ some(ret_val) {
+ find_pre_post_expr(fcx, ret_val);
+ set_precondition(node_id_to_ts_ann(fcx.ccx, e.id),
+ expr_precond(fcx.ccx, ret_val));
+ set_postcond_false(fcx.ccx, e.id);
+ }
}
- case (expr_lit(_)) { clear_pp(expr_pp(fcx.ccx, e)); }
- case (expr_ret(?maybe_val)) {
- alt (maybe_val) {
- case (none) {
- clear_precond(fcx.ccx, e.id);
- set_postcond_false(fcx.ccx, e.id);
- }
- case (some(?ret_val)) {
- find_pre_post_expr(fcx, ret_val);
- set_precondition(node_id_to_ts_ann(fcx.ccx, e.id),
- expr_precond(fcx.ccx, ret_val));
- set_postcond_false(fcx.ccx, e.id);
- }
- }
- }
- case (expr_be(?val)) {
- find_pre_post_expr(fcx, val);
- set_pre_and_post(fcx.ccx, e.id, expr_prestate(fcx.ccx, val),
- false_postcond(num_local_vars));
- }
- case (expr_if(?antec, ?conseq, ?maybe_alt)) {
- join_then_else(fcx, antec, conseq, maybe_alt, e.id, plain_if);
- }
- case (expr_ternary(_, _, _)) {
- find_pre_post_expr(fcx, ternary_to_if(e));
- }
- case (expr_binary(?bop, ?l, ?r)) {
- if (lazy_binop(bop)) {
- find_pre_post_expr(fcx, l);
- find_pre_post_expr(fcx, r);
- auto overall_pre = seq_preconds(fcx,
- ~[expr_pp(fcx.ccx, l), expr_pp(fcx.ccx, r)]);
- set_precondition(node_id_to_ts_ann(fcx.ccx, e.id),
- overall_pre);
- set_postcondition(node_id_to_ts_ann(fcx.ccx, e.id),
- expr_postcond(fcx.ccx, l));
- }
- else {
- find_pre_post_exprs(fcx, ~[l, r], e.id);
- }
- }
- case (expr_send(?l, ?r)) {
- find_pre_post_exprs(fcx, ~[l, r], e.id);
- }
- case (expr_unary(_, ?operand)) {
- find_pre_post_expr(fcx, operand);
- copy_pre_post(fcx.ccx, e.id, operand);
- }
- case (expr_cast(?operand, _)) {
- find_pre_post_expr(fcx, operand);
- copy_pre_post(fcx.ccx, e.id, operand);
- }
- case (expr_while(?test, ?body)) {
- find_pre_post_expr(fcx, test);
- find_pre_post_block(fcx, body);
- set_pre_and_post(fcx.ccx, e.id,
- seq_preconds(fcx, ~[expr_pp(fcx.ccx, test),
- block_pp(fcx.ccx, body)]),
- intersect_states(expr_postcond(fcx.ccx, test),
- block_postcond(fcx.ccx, body)));
- }
- case (expr_do_while(?body, ?test)) {
- find_pre_post_block(fcx, body);
- find_pre_post_expr(fcx, test);
- auto loop_postcond = seq_postconds(fcx,
- ~[block_postcond(fcx.ccx, body),
- expr_postcond(fcx.ccx, test)]);
- /* conservative approximation: if the body
- could break or cont, the test may never be executed */
+ }
+ expr_be(val) {
+ find_pre_post_expr(fcx, val);
+ set_pre_and_post(fcx.ccx, e.id, expr_prestate(fcx.ccx, val),
+ false_postcond(num_local_vars));
+ }
+ expr_if(antec, conseq, maybe_alt) {
+ join_then_else(fcx, antec, conseq, maybe_alt, e.id, plain_if);
+ }
+ expr_ternary(_, _, _) { find_pre_post_expr(fcx, ternary_to_if(e)); }
+ expr_binary(bop, l, r) {
+ if lazy_binop(bop) {
+ find_pre_post_expr(fcx, l);
+ find_pre_post_expr(fcx, r);
+ let overall_pre =
+ seq_preconds(fcx,
+ ~[expr_pp(fcx.ccx, l), expr_pp(fcx.ccx, r)]);
+ set_precondition(node_id_to_ts_ann(fcx.ccx, e.id), overall_pre);
+ set_postcondition(node_id_to_ts_ann(fcx.ccx, e.id),
+ expr_postcond(fcx.ccx, l));
+ } else { find_pre_post_exprs(fcx, ~[l, r], e.id); }
+ }
+ expr_send(l, r) { find_pre_post_exprs(fcx, ~[l, r], e.id); }
+ expr_unary(_, operand) {
+ find_pre_post_expr(fcx, operand);
+ copy_pre_post(fcx.ccx, e.id, operand);
+ }
+ expr_cast(operand, _) {
+ find_pre_post_expr(fcx, operand);
+ copy_pre_post(fcx.ccx, e.id, operand);
+ }
+ expr_while(test, body) {
+ find_pre_post_expr(fcx, test);
+ find_pre_post_block(fcx, body);
+ set_pre_and_post(fcx.ccx, e.id,
+ seq_preconds(fcx,
+ ~[expr_pp(fcx.ccx, test),
+ block_pp(fcx.ccx, body)]),
+ intersect_states(expr_postcond(fcx.ccx, test),
+ block_postcond(fcx.ccx, body)));
+ }
+ expr_do_while(body, test) {
+ find_pre_post_block(fcx, body);
+ find_pre_post_expr(fcx, test);
+ let loop_postcond =
+ seq_postconds(fcx,
+ ~[block_postcond(fcx.ccx, body),
+ expr_postcond(fcx.ccx, test)]);
+ /* conservative approximation: if the body
+ could break or cont, the test may never be executed */
- if (has_nonlocal_exits(body)) {
- loop_postcond = empty_poststate(num_local_vars);
+ if has_nonlocal_exits(body) {
+ loop_postcond = empty_poststate(num_local_vars);
+ }
+ set_pre_and_post(fcx.ccx, e.id,
+ seq_preconds(fcx,
+ ~[block_pp(fcx.ccx, body),
+ expr_pp(fcx.ccx, test)]),
+ loop_postcond);
+ }
+ expr_for(d, index, body) {
+ find_pre_post_loop(fcx, d, index, body, e.id);
+ }
+ expr_for_each(d, index, body) {
+ find_pre_post_loop(fcx, d, index, body, e.id);
+ }
+ expr_index(val, sub) { find_pre_post_exprs(fcx, ~[val, sub], e.id); }
+ expr_alt(ex, alts) {
+ find_pre_post_expr(fcx, ex);
+ fn do_an_alt(fcx: &fn_ctxt, an_alt: &arm) -> pre_and_post {
+ find_pre_post_block(fcx, an_alt.block);
+ ret block_pp(fcx.ccx, an_alt.block);
+ }
+ let alt_pps = ~[];
+ for a: arm in alts { alt_pps += ~[do_an_alt(fcx, a)]; }
+ fn combine_pp(antec: pre_and_post, fcx: fn_ctxt, pp: &pre_and_post,
+ next: &pre_and_post) -> pre_and_post {
+ union(pp.precondition, seq_preconds(fcx, ~[antec, next]));
+ intersect(pp.postcondition, next.postcondition);
+ ret pp;
+ }
+ let antec_pp = pp_clone(expr_pp(fcx.ccx, ex));
+ let e_pp =
+ @{precondition: empty_prestate(num_local_vars),
+ postcondition: false_postcond(num_local_vars)};
+ let g = bind combine_pp(antec_pp, fcx, _, _);
+ let alts_overall_pp =
+ ivec::foldl[pre_and_post, pre_and_post](g, e_pp, alt_pps);
+ set_pre_and_post(fcx.ccx, e.id, alts_overall_pp.precondition,
+ alts_overall_pp.postcondition);
+ }
+ expr_field(operator, _) {
+ find_pre_post_expr(fcx, operator);
+ copy_pre_post(fcx.ccx, e.id, operator);
+ }
+ expr_fail(maybe_val) {
+ let prestate;
+ alt maybe_val {
+ none. { prestate = empty_prestate(num_local_vars); }
+ some(fail_val) {
+ find_pre_post_expr(fcx, fail_val);
+ prestate = expr_precond(fcx.ccx, fail_val);
+ }
+ }
+ set_pre_and_post(fcx.ccx, e.id,
+ /* if execution continues after fail,
+ then everything is true! */
+ prestate, false_postcond(num_local_vars));
+ }
+ expr_assert(p) {
+ find_pre_post_expr(fcx, p);
+ copy_pre_post(fcx.ccx, e.id, p);
+ }
+ expr_check(_, p) {
+ find_pre_post_expr(fcx, p);
+ copy_pre_post(fcx.ccx, e.id, p);
+ /* predicate p holds after this expression executes */
+
+ let c: sp_constr = expr_to_constr(fcx.ccx.tcx, p);
+ gen(fcx, e.id, c.node);
+ }
+ expr_if_check(p, conseq, maybe_alt) {
+ join_then_else(fcx, p, conseq, maybe_alt, e.id, if_check);
+ }
+
+
+ expr_bind(operator, maybe_args) {
+ let args = ~[];
+ for expr_opt: option::t[@expr] in maybe_args {
+ alt expr_opt {
+ none. {/* no-op */ }
+ some(expr) { args += ~[expr]; }
}
- set_pre_and_post(fcx.ccx, e.id,
- seq_preconds(fcx,
- ~[block_pp(fcx.ccx, body),
- expr_pp(fcx.ccx, test)]),
- loop_postcond);
}
- case (expr_for(?d, ?index, ?body)) {
- find_pre_post_loop(fcx, d, index, body, e.id);
- }
- case (expr_for_each(?d, ?index, ?body)) {
- find_pre_post_loop(fcx, d, index, body, e.id);
- }
- case (expr_index(?val, ?sub)) {
- find_pre_post_exprs(fcx, ~[val, sub], e.id);
- }
- case (expr_alt(?ex, ?alts)) {
+ args += ~[operator]; /* ??? order of eval? */
+
+ find_pre_post_exprs(fcx, args, e.id);
+ }
+ expr_break. { clear_pp(expr_pp(fcx.ccx, e)); }
+ expr_cont. { clear_pp(expr_pp(fcx.ccx, e)); }
+ expr_port(_) { clear_pp(expr_pp(fcx.ccx, e)); }
+ expr_mac(_) { fcx.ccx.tcx.sess.bug("unexpanded macro"); }
+ expr_anon_obj(anon_obj) {
+ alt anon_obj.with_obj {
+ some(ex) {
find_pre_post_expr(fcx, ex);
- fn do_an_alt(&fn_ctxt fcx, &arm an_alt) -> pre_and_post {
- find_pre_post_block(fcx, an_alt.block);
- ret block_pp(fcx.ccx, an_alt.block);
- }
- auto alt_pps = ~[];
- for (arm a in alts) { alt_pps += ~[do_an_alt(fcx, a)]; }
- fn combine_pp(pre_and_post antec, fn_ctxt fcx, &pre_and_post pp,
- &pre_and_post next) -> pre_and_post {
- union(pp.precondition, seq_preconds(fcx, ~[antec, next]));
- intersect(pp.postcondition, next.postcondition);
- ret pp;
- }
- auto antec_pp = pp_clone(expr_pp(fcx.ccx, ex));
- auto e_pp =
- @rec(precondition=empty_prestate(num_local_vars),
- postcondition=false_postcond(num_local_vars));
- auto g = bind combine_pp(antec_pp, fcx, _, _);
- auto alts_overall_pp =
- ivec::foldl[pre_and_post, pre_and_post](g, e_pp, alt_pps);
- set_pre_and_post(fcx.ccx, e.id, alts_overall_pp.precondition,
- alts_overall_pp.postcondition);
+ copy_pre_post(fcx.ccx, e.id, ex);
+ }
+ none. { clear_pp(expr_pp(fcx.ccx, e)); }
}
- case (expr_field(?operator, _)) {
- find_pre_post_expr(fcx, operator);
- copy_pre_post(fcx.ccx, e.id, operator);
- }
- case (expr_fail(?maybe_val)) {
- auto prestate;
- alt (maybe_val) {
- case (none) { prestate = empty_prestate(num_local_vars); }
- case (some(?fail_val)) {
- find_pre_post_expr(fcx, fail_val);
- prestate = expr_precond(fcx.ccx, fail_val);
- }
- }
- set_pre_and_post(fcx.ccx, e.id,
- /* if execution continues after fail,
- then everything is true! */
- prestate,
- false_postcond(num_local_vars));
- }
- case (expr_assert(?p)) {
- find_pre_post_expr(fcx, p);
- copy_pre_post(fcx.ccx, e.id, p);
- }
- case (expr_check(_, ?p)) {
- find_pre_post_expr(fcx, p);
- copy_pre_post(fcx.ccx, e.id, p);
- /* predicate p holds after this expression executes */
-
- let sp_constr c = expr_to_constr(fcx.ccx.tcx, p);
- gen(fcx, e.id, c.node);
- }
- case (expr_if_check(?p, ?conseq, ?maybe_alt)) {
- join_then_else(fcx, p, conseq, maybe_alt, e.id, if_check);
- }
-
- case (expr_bind(?operator, ?maybe_args)) {
- auto args = ~[];
- for (option::t[@expr] expr_opt in maybe_args) {
- alt (expr_opt) {
- case (none) { /* no-op */ }
- case (some(?expr)) { args += ~[expr]; }
- }
- }
- args += ~[operator]; /* ??? order of eval? */
-
- find_pre_post_exprs(fcx, args, e.id);
- }
- case (expr_break) { clear_pp(expr_pp(fcx.ccx, e)); }
- case (expr_cont) { clear_pp(expr_pp(fcx.ccx, e)); }
- case (expr_port(_)) { clear_pp(expr_pp(fcx.ccx, e)); }
- case (expr_mac(_)) {
- fcx.ccx.tcx.sess.bug("unexpanded macro");
- }
- case (expr_anon_obj(?anon_obj)) {
- alt (anon_obj.with_obj) {
- case (some(?ex)) {
- find_pre_post_expr(fcx, ex);
- copy_pre_post(fcx.ccx, e.id, ex);
- }
- case (none) { clear_pp(expr_pp(fcx.ccx, e)); }
- }
- }
+ }
}
}
-fn find_pre_post_stmt(&fn_ctxt fcx, &stmt s) {
+fn find_pre_post_stmt(fcx: &fn_ctxt, s: &stmt) {
log "stmt =";
log_stmt(s);
- alt (s.node) {
- case (stmt_decl(?adecl, ?id)) {
- alt (adecl.node) {
- case (decl_local(?alocals)) {
- for (@local alocal in alocals) {
- alt (alocal.node.init) {
- case (some(?an_init)) {
- /* LHS always becomes initialized,
- whether or not this is a move */
+ alt s.node {
+ stmt_decl(adecl, id) {
+ alt adecl.node {
+ decl_local(alocals) {
+ for alocal: @local in alocals {
+ alt alocal.node.init {
+ some(an_init) {
+ /* LHS always becomes initialized,
+ whether or not this is a move */
- find_pre_post_expr(fcx, an_init.expr);
- copy_pre_post(fcx.ccx, alocal.node.id,
- an_init.expr);
- /* Inherit ann from initializer, and add var being
- initialized to the postcondition */
+ find_pre_post_expr(fcx, an_init.expr);
+ copy_pre_post(fcx.ccx, alocal.node.id, an_init.expr);
+ /* Inherit ann from initializer, and add var being
+ initialized to the postcondition */
- copy_pre_post(fcx.ccx, id, an_init.expr);
+ copy_pre_post(fcx.ccx, id, an_init.expr);
- alt (an_init.expr.node) {
- case (expr_path(?p)) {
- copy_in_postcond(fcx, id,
- rec(ident=alocal.node.ident,
- node=alocal.node.id),
- rec(ident=path_to_ident(fcx.ccx.tcx, p),
- node=an_init.expr.id),
- op_to_oper_ty(an_init.op));
- }
- case (_) {}
- }
+ alt an_init.expr.node {
+ expr_path(p) {
+ copy_in_postcond(fcx, id,
+ {ident: alocal.node.ident,
+ node: alocal.node.id},
+ {ident:
+ path_to_ident(fcx.ccx.tcx, p),
+ node: an_init.expr.id},
+ op_to_oper_ty(an_init.op));
+ }
+ _ { }
+ }
- gen(fcx, id,
- ninit(alocal.node.id,
- alocal.node.ident));
+ gen(fcx, id, ninit(alocal.node.id, alocal.node.ident));
- if (an_init.op == init_move &&
- is_path(an_init.expr)) {
- forget_in_postcond(fcx, id, an_init.expr.id);
- }
- }
- case (none) {
- clear_pp(node_id_to_ts_ann(fcx.ccx,
- alocal.node.id)
- .conditions);
- clear_pp(node_id_to_ts_ann(fcx.ccx, id)
- .conditions);
- }
+
+ if an_init.op == init_move && is_path(an_init.expr) {
+ forget_in_postcond(fcx, id, an_init.expr.id);
}
}
- }
- case (decl_item(?anitem)) {
+ none. {
+ clear_pp(node_id_to_ts_ann(fcx.ccx,
+ alocal.node.id).conditions);
clear_pp(node_id_to_ts_ann(fcx.ccx, id).conditions);
- find_pre_post_item(fcx.ccx, *anitem);
+ }
}
}
+ }
+ decl_item(anitem) {
+ clear_pp(node_id_to_ts_ann(fcx.ccx, id).conditions);
+ find_pre_post_item(fcx.ccx, *anitem);
+ }
}
- case (stmt_expr(?e, ?id)) {
- find_pre_post_expr(fcx, e);
- copy_pre_post(fcx.ccx, id, e);
- }
+ }
+ stmt_expr(e, id) {
+ find_pre_post_expr(fcx, e);
+ copy_pre_post(fcx.ccx, id, e);
+ }
}
}
-fn find_pre_post_block(&fn_ctxt fcx, blk b) {
+fn find_pre_post_block(fcx: &fn_ctxt, b: blk) {
/* Want to say that if there is a break or cont in this
block, then that invalidates the poststate upheld by
any of the stmts after it.
@@ -666,70 +641,71 @@
This will mean that:
x = 0;
break;
-
+
won't have a postcondition that says x is initialized, but that's ok.
*/
- auto nv = num_constraints(fcx.enclosing);
- fn do_one_(fn_ctxt fcx, &@stmt s) {
+ let nv = num_constraints(fcx.enclosing);
+ fn do_one_(fcx: fn_ctxt, s: &@stmt) {
find_pre_post_stmt(fcx, *s);
log "pre_post for stmt:";
log_stmt(*s);
log "is:";
log_pp(stmt_pp(fcx.ccx, *s));
}
- for (@stmt s in b.node.stmts) { do_one_(fcx, s); }
- fn do_inner_(fn_ctxt fcx, &@expr e) { find_pre_post_expr(fcx, e); }
- auto do_inner = bind do_inner_(fcx, _);
+ for s: @stmt in b.node.stmts { do_one_(fcx, s); }
+ fn do_inner_(fcx: fn_ctxt, e: &@expr) { find_pre_post_expr(fcx, e); }
+ let do_inner = bind do_inner_(fcx, _);
option::map[@expr, ()](do_inner, b.node.expr);
- let pre_and_post[] pps = ~[];
- for (@stmt s in b.node.stmts) { pps += ~[stmt_pp(fcx.ccx, *s)]; }
- alt (b.node.expr) {
- case (none) { /* no-op */ }
- case (some(?e)) { pps += ~[expr_pp(fcx.ccx, e)]; }
+ let pps: pre_and_post[] = ~[];
+ for s: @stmt in b.node.stmts { pps += ~[stmt_pp(fcx.ccx, *s)]; }
+ alt b.node.expr {
+ none. {/* no-op */ }
+ some(e) { pps += ~[expr_pp(fcx.ccx, e)]; }
}
- auto block_precond = seq_preconds(fcx, pps);
+ let block_precond = seq_preconds(fcx, pps);
- auto postconds = ~[];
- for (pre_and_post pp in pps) { postconds += ~[get_post(pp)]; }
+ let postconds = ~[];
+ for pp: pre_and_post in pps { postconds += ~[get_post(pp)]; }
/* A block may be empty, so this next line ensures that the postconds
vector is non-empty. */
postconds += ~[block_precond];
- auto block_postcond = empty_poststate(nv);
+ let block_postcond = empty_poststate(nv);
/* conservative approximation */
- if (!has_nonlocal_exits(b)) {
+ if !has_nonlocal_exits(b) {
block_postcond = seq_postconds(fcx, postconds);
}
set_pre_and_post(fcx.ccx, b.node.id, block_precond, block_postcond);
}
-fn find_pre_post_fn(&fn_ctxt fcx, &_fn f) {
+fn find_pre_post_fn(fcx: &fn_ctxt, f: &_fn) {
// hack
use_var(fcx, fcx.id);
find_pre_post_block(fcx, f.body);
+
// Treat the tail expression as a return statement
- alt (f.body.node.expr) {
- case (some(?tailexpr)) {
- set_postcond_false(fcx.ccx, tailexpr.id);
- }
- case (none) {/* fallthrough */ }
+ alt f.body.node.expr {
+ some(tailexpr) { set_postcond_false(fcx.ccx, tailexpr.id); }
+ none. {/* fallthrough */ }
}
}
-fn fn_pre_post(&_fn f, &ty_param[] tps,
- &span sp, &fn_ident i, node_id id, &crate_ctxt ccx,
- &visit::vt[crate_ctxt] v) {
+fn fn_pre_post(f: &_fn, tps: &ty_param[], sp: &span, i: &fn_ident,
+ id: node_id, ccx: &crate_ctxt, v: &visit::vt[crate_ctxt]) {
visit::visit_fn(f, tps, sp, i, id, ccx, v);
assert (ccx.fm.contains_key(id));
- auto fcx = rec(enclosing=ccx.fm.get(id), id=id,
- name=fn_ident_to_string(id, i), ccx=ccx);
+ let fcx =
+ {enclosing: ccx.fm.get(id),
+ id: id,
+ name: fn_ident_to_string(id, i),
+ ccx: ccx};
find_pre_post_fn(fcx, f);
}
//
diff --git a/src/comp/middle/tstate/states.rs b/src/comp/middle/tstate/states.rs
index bc9864a..b2ab7fd 100644
--- a/src/comp/middle/tstate/states.rs
+++ b/src/comp/middle/tstate/states.rs
@@ -53,178 +53,169 @@
import util::common::log_stmt_err;
import util::common::log_expr_err;
-fn seq_states(&fn_ctxt fcx, prestate pres, &(@expr)[] exprs) ->
- rec(bool changed, poststate post) {
- auto changed = false;
- auto post = pres;
- for (@expr e in exprs) {
+fn seq_states(fcx: &fn_ctxt, pres: prestate, exprs: &(@expr)[]) ->
+ {changed: bool, post: poststate} {
+ let changed = false;
+ let post = pres;
+ for e: @expr in exprs {
changed |= find_pre_post_state_expr(fcx, post, e) || changed;
// log_err("Seq_states: changed =");
// log_err changed;
post = expr_poststate(fcx.ccx, e);
}
- ret rec(changed=changed, post=post);
+ ret {changed: changed, post: post};
}
-fn find_pre_post_state_sub(&fn_ctxt fcx, &prestate pres, &@expr e,
- node_id parent, option::t[tsconstr] c) -> bool {
- auto changed = find_pre_post_state_expr(fcx, pres, e);
+fn find_pre_post_state_sub(fcx: &fn_ctxt, pres: &prestate, e: &@expr,
+ parent: node_id, c: option::t[tsconstr]) -> bool {
+ let changed = find_pre_post_state_expr(fcx, pres, e);
changed = set_prestate_ann(fcx.ccx, parent, pres) || changed;
- auto post = tritv_clone(expr_poststate(fcx.ccx, e));
- alt (c) {
- case (none) {}
- case (some(?c1)) {
- set_in_poststate_(bit_num(fcx, c1), post);
- }
+ let post = tritv_clone(expr_poststate(fcx.ccx, e));
+ alt c {
+ none. { }
+ some(c1) { set_in_poststate_(bit_num(fcx, c1), post); }
}
changed = set_poststate_ann(fcx.ccx, parent, post) || changed;
ret changed;
}
-fn find_pre_post_state_two(&fn_ctxt fcx, &prestate pres, &@expr lhs,
- &@expr rhs, node_id parent, oper_type ty)
- -> bool {
- auto changed = set_prestate_ann(fcx.ccx, parent, pres);
+fn find_pre_post_state_two(fcx: &fn_ctxt, pres: &prestate, lhs: &@expr,
+ rhs: &@expr, parent: node_id, ty: oper_type) ->
+ bool {
+ let changed = set_prestate_ann(fcx.ccx, parent, pres);
changed = find_pre_post_state_expr(fcx, pres, lhs) || changed;
- changed = find_pre_post_state_expr(fcx, expr_poststate(fcx.ccx, lhs), rhs)
- || changed;
+ changed =
+ find_pre_post_state_expr(fcx, expr_poststate(fcx.ccx, lhs), rhs) ||
+ changed;
- auto post = tritv_clone(expr_poststate(fcx.ccx, rhs));
+ let post = tritv_clone(expr_poststate(fcx.ccx, rhs));
- alt (lhs.node) {
- case (expr_path(?p)) {
- // for termination, need to make sure intermediate changes don't set
- // changed flag
- // tmp remembers "old" constraints we'd otherwise forget,
- // for substitution purposes
- auto tmp = tritv_clone(post);
+ alt lhs.node {
+ expr_path(p) {
+ // for termination, need to make sure intermediate changes don't set
+ // changed flag
+ // tmp remembers "old" constraints we'd otherwise forget,
+ // for substitution purposes
+ let tmp = tritv_clone(post);
- alt (ty) {
- case (oper_move) {
- if (is_path(rhs)) {
- forget_in_poststate(fcx, post, rhs.id);
- }
- forget_in_poststate_still_init(fcx, post, lhs.id);
- }
- case (oper_swap) {
- forget_in_poststate_still_init(fcx, post, lhs.id);
- forget_in_poststate_still_init(fcx, post, rhs.id);
- }
- case (_) {
- forget_in_poststate_still_init(fcx, post, lhs.id);
- }
- }
-
- gen_if_local(fcx, post, lhs);
- alt (rhs.node) {
- case (expr_path(?p1)) {
- auto d = local_node_id_to_local_def_id(fcx, lhs.id);
- auto d1 = local_node_id_to_local_def_id(fcx, rhs.id);
- alt (d) {
- case (some(?id)) {
- alt (d1) {
- case (some(?id1)) {
- auto instlhs =
- rec(ident=path_to_ident
- (fcx.ccx.tcx, p),
- node=id);
- auto instrhs =
- rec(ident=path_to_ident
- (fcx.ccx.tcx, p1),
- node=id1);
- copy_in_poststate_two(fcx, tmp,
- post, instlhs, instrhs, ty);
- }
- case (_) {}
- }
- }
- case (_) {}
- }
- }
- case (_) { /* do nothing */ }
- }
+ alt ty {
+ oper_move. {
+ if is_path(rhs) { forget_in_poststate(fcx, post, rhs.id); }
+ forget_in_poststate_still_init(fcx, post, lhs.id);
+ }
+ oper_swap. {
+ forget_in_poststate_still_init(fcx, post, lhs.id);
+ forget_in_poststate_still_init(fcx, post, rhs.id);
+ }
+ _ { forget_in_poststate_still_init(fcx, post, lhs.id); }
}
- case (_) { }
+
+ gen_if_local(fcx, post, lhs);
+ alt rhs.node {
+ expr_path(p1) {
+ let d = local_node_id_to_local_def_id(fcx, lhs.id);
+ let d1 = local_node_id_to_local_def_id(fcx, rhs.id);
+ alt d {
+ some(id) {
+ alt d1 {
+ some(id1) {
+ let instlhs =
+ {ident: path_to_ident(fcx.ccx.tcx, p), node: id};
+ let instrhs =
+ {ident: path_to_ident(fcx.ccx.tcx, p1), node: id1};
+ copy_in_poststate_two(fcx, tmp, post, instlhs, instrhs,
+ ty);
+ }
+ _ { }
+ }
+ }
+ _ { }
+ }
+ }
+ _ {/* do nothing */ }
+ }
+ }
+ _ { }
}
changed = set_poststate_ann(fcx.ccx, parent, post) || changed;
ret changed;
}
-fn find_pre_post_state_call(&fn_ctxt fcx, &prestate pres, &@expr a,
- node_id id, &(@expr)[] bs,
- controlflow cf) -> bool {
- auto changed = find_pre_post_state_expr(fcx, pres, a);
- ret find_pre_post_state_exprs(fcx,
- expr_poststate(fcx.ccx, a), id, bs, cf) || changed;
+fn find_pre_post_state_call(fcx: &fn_ctxt, pres: &prestate, a: &@expr,
+ id: node_id, bs: &(@expr)[], cf: controlflow) ->
+ bool {
+ let changed = find_pre_post_state_expr(fcx, pres, a);
+ ret find_pre_post_state_exprs(fcx, expr_poststate(fcx.ccx, a), id, bs, cf)
+ || changed;
}
-fn find_pre_post_state_exprs(&fn_ctxt fcx, &prestate pres, node_id id,
- &(@expr)[] es, controlflow cf) -> bool {
- auto rs = seq_states(fcx, pres, es);
- auto changed = rs.changed | set_prestate_ann(fcx.ccx, id, pres);
+fn find_pre_post_state_exprs(fcx: &fn_ctxt, pres: &prestate, id: node_id,
+ es: &(@expr)[], cf: controlflow) -> bool {
+ let rs = seq_states(fcx, pres, es);
+ let changed = rs.changed | set_prestate_ann(fcx.ccx, id, pres);
/* if this is a failing call, it sets everything as initialized */
- alt (cf) {
- case (noreturn) {
- changed |= set_poststate_ann
- (fcx.ccx, id, false_postcond(num_constraints(fcx.enclosing)));
- }
- case (_) {
- changed |= set_poststate_ann(fcx.ccx, id, rs.post);
- }
+ alt cf {
+ noreturn. {
+ changed |=
+ set_poststate_ann(fcx.ccx, id,
+ false_postcond(num_constraints(fcx.enclosing)));
+ }
+ _ { changed |= set_poststate_ann(fcx.ccx, id, rs.post); }
}
ret changed;
}
-fn find_pre_post_state_loop(&fn_ctxt fcx, prestate pres, &@local l,
- &@expr index, &blk body, node_id id)
- -> bool {
- auto loop_pres = intersect_states(pres,
- block_poststate(fcx.ccx, body));
+fn find_pre_post_state_loop(fcx: &fn_ctxt, pres: prestate, l: &@local,
+ index: &@expr, body: &blk, id: node_id) -> bool {
+ let loop_pres = intersect_states(pres, block_poststate(fcx.ccx, body));
- auto changed = set_prestate_ann(fcx.ccx, id, loop_pres) |
- find_pre_post_state_expr(fcx, pres, index);
+ let changed =
+ set_prestate_ann(fcx.ccx, id, loop_pres) |
+ find_pre_post_state_expr(fcx, pres, index);
// Make sure the index var is considered initialized
// in the body
- auto index_post = tritv_clone(expr_poststate(fcx.ccx, index));
+ let index_post = tritv_clone(expr_poststate(fcx.ccx, index));
set_in_poststate_ident(fcx, l.node.id, l.node.ident, index_post);
changed |= find_pre_post_state_block(fcx, index_post, body);
- if (has_nonlocal_exits(body)) {
+
+ if has_nonlocal_exits(body) {
// See [Break-unsound]
- ret (changed | set_poststate_ann(fcx.ccx, id, pres));
- }
- else {
- auto res_p = intersect_states(expr_poststate(fcx.ccx, index),
- block_poststate(fcx.ccx, body));
+ ret changed | set_poststate_ann(fcx.ccx, id, pres);
+ } else {
+ let res_p =
+ intersect_states(expr_poststate(fcx.ccx, index),
+ block_poststate(fcx.ccx, body));
ret changed | set_poststate_ann(fcx.ccx, id, res_p);
}
}
-fn gen_if_local(&fn_ctxt fcx, &poststate p, &@expr e) -> bool {
- alt (e.node) {
- case (expr_path(?pth)) {
- alt (freevars::def_lookup(fcx.ccx.tcx, fcx.id, e.id)) {
- case (some(def_local(?loc))) {
- ret set_in_poststate_ident(fcx, loc.node,
- path_to_ident(fcx.ccx.tcx, pth), p);
- }
- case (_) { ret false; }
- }
+fn gen_if_local(fcx: &fn_ctxt, p: &poststate, e: &@expr) -> bool {
+ alt e.node {
+ expr_path(pth) {
+ alt freevars::def_lookup(fcx.ccx.tcx, fcx.id, e.id) {
+ some(def_local(loc)) {
+ ret set_in_poststate_ident(fcx, loc.node,
+ path_to_ident(fcx.ccx.tcx, pth), p);
+ }
+ _ { ret false; }
}
- case (_) { ret false; }
+ }
+ _ { ret false; }
}
}
-fn join_then_else(&fn_ctxt fcx, &@expr antec, &blk conseq,
- &option::t[@expr] maybe_alt, node_id id, &if_ty chk,
- &prestate pres) -> bool {
- auto changed = set_prestate_ann(fcx.ccx, id, pres) |
- find_pre_post_state_expr(fcx, pres, antec);
+fn join_then_else(fcx: &fn_ctxt, antec: &@expr, conseq: &blk,
+ maybe_alt: &option::t[@expr], id: node_id, chk: &if_ty,
+ pres: &prestate) -> bool {
+ let changed =
+ set_prestate_ann(fcx.ccx, id, pres) |
+ find_pre_post_state_expr(fcx, pres, antec);
/*
log_err("join_then_else:");
@@ -241,345 +232,339 @@
log_bitv_err(fcx, block_postcond(fcx.ccx, conseq));
*/
- alt (maybe_alt) {
- case (none) {
- changed |= find_pre_post_state_block
- (fcx, expr_poststate(fcx.ccx, antec), conseq) |
+ alt maybe_alt {
+ none. {
+ changed |=
+ find_pre_post_state_block(fcx, expr_poststate(fcx.ccx, antec),
+ conseq) |
set_poststate_ann(fcx.ccx, id,
expr_poststate(fcx.ccx, antec));
+ }
+ some(altern) {
+ changed |=
+ find_pre_post_state_expr(fcx, expr_poststate(fcx.ccx, antec),
+ altern);
+
+ let conseq_prestate = expr_poststate(fcx.ccx, antec);
+ alt chk {
+ if_check. {
+ let c: sp_constr = expr_to_constr(fcx.ccx.tcx, antec);
+ conseq_prestate = tritv_clone(conseq_prestate);
+ tritv_set(bit_num(fcx, c.node), conseq_prestate, ttrue);
+ }
+ _ { }
}
- case (some(?altern)) {
- changed |= find_pre_post_state_expr
- (fcx, expr_poststate(fcx.ccx, antec), altern);
-
- auto conseq_prestate = expr_poststate(fcx.ccx, antec);
- alt (chk) {
- case (if_check) {
- let sp_constr c = expr_to_constr(fcx.ccx.tcx, antec);
- conseq_prestate = tritv_clone(conseq_prestate);
- tritv_set(bit_num(fcx, c.node), conseq_prestate, ttrue);
- }
- case (_) {}
- }
- changed |=
- find_pre_post_state_block(fcx, conseq_prestate, conseq);
+ changed |= find_pre_post_state_block(fcx, conseq_prestate, conseq);
- auto poststate_res =
- intersect_states(block_poststate(fcx.ccx, conseq),
- expr_poststate(fcx.ccx, altern));
- /*
- fcx.ccx.tcx.sess.span_note(antec.span,
- "poststate_res = " + aux::tritv_to_str(fcx, poststate_res));
- fcx.ccx.tcx.sess.span_note(antec.span,
- "altern poststate = " +
- aux::tritv_to_str(fcx, expr_poststate(fcx.ccx, altern)));
- fcx.ccx.tcx.sess.span_note(antec.span,
- "conseq poststate = " + aux::tritv_to_str(fcx,
- block_poststate(fcx.ccx, conseq)));
- */
+ let poststate_res =
+ intersect_states(block_poststate(fcx.ccx, conseq),
+ expr_poststate(fcx.ccx, altern));
+ /*
+ fcx.ccx.tcx.sess.span_note(antec.span,
+ "poststate_res = " + aux::tritv_to_str(fcx, poststate_res));
+ fcx.ccx.tcx.sess.span_note(antec.span,
+ "altern poststate = " +
+ aux::tritv_to_str(fcx, expr_poststate(fcx.ccx, altern)));
+ fcx.ccx.tcx.sess.span_note(antec.span,
+ "conseq poststate = " + aux::tritv_to_str(fcx,
+ block_poststate(fcx.ccx, conseq)));
+ */
- changed |= set_poststate_ann(fcx.ccx, id, poststate_res);
- }
+ changed |= set_poststate_ann(fcx.ccx, id, poststate_res);
+ }
}
ret changed;
}
-fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool {
- auto num_constrs = num_constraints(fcx.enclosing);
+fn find_pre_post_state_expr(fcx: &fn_ctxt, pres: &prestate, e: @expr) ->
+ bool {
+ let num_constrs = num_constraints(fcx.enclosing);
- alt (e.node) {
- case (expr_vec(?elts, _, _)) {
- ret find_pre_post_state_exprs(fcx, pres, e.id, elts, return);
- }
- case (expr_call(?operator, ?operands)) {
- ret find_pre_post_state_call
- (fcx, pres, operator, e.id, operands,
- controlflow_expr(fcx.ccx, operator));
- }
- case (expr_spawn(_, _, ?operator, ?operands)) {
- ret find_pre_post_state_call(fcx, pres, operator, e.id, operands,
- return);
- }
- case (expr_bind(?operator, ?maybe_args)) {
- auto args = ~[];
- for (option::t[@expr] a_opt in maybe_args) {
- alt (a_opt) {
- case (none) { /* no-op */ }
- case (some(?a)) { args += ~[a]; }
- }
- }
- ret find_pre_post_state_call(fcx, pres, operator, e.id, args,
- return);
+ alt e.node {
+ expr_vec(elts, _, _) {
+ ret find_pre_post_state_exprs(fcx, pres, e.id, elts, return);
+ }
+ expr_call(operator, operands) {
+ ret find_pre_post_state_call(fcx, pres, operator, e.id, operands,
+ controlflow_expr(fcx.ccx, operator));
+ }
+ expr_spawn(_, _, operator, operands) {
+ ret find_pre_post_state_call(fcx, pres, operator, e.id, operands,
+ return);
+ }
+ expr_bind(operator, maybe_args) {
+ let args = ~[];
+ for a_opt: option::t[@expr] in maybe_args {
+ alt a_opt { none. {/* no-op */ } some(a) { args += ~[a]; } }
}
- case (expr_path(_)) { ret pure_exp(fcx.ccx, e.id, pres); }
- case (expr_log(_, ?ex)) {
- ret find_pre_post_state_sub(fcx, pres, ex, e.id, none);
+
+ ret find_pre_post_state_call(fcx, pres, operator, e.id, args, return);
+ }
+ expr_path(_) { ret pure_exp(fcx.ccx, e.id, pres); }
+ expr_log(_, ex) {
+ ret find_pre_post_state_sub(fcx, pres, ex, e.id, none);
+ }
+ expr_chan(ex) {
+ ret find_pre_post_state_sub(fcx, pres, ex, e.id, none);
+ }
+ expr_mac(_) { fcx.ccx.tcx.sess.bug("unexpanded macro"); }
+ expr_put(maybe_e) {
+ alt maybe_e {
+ some(arg) {
+ ret find_pre_post_state_sub(fcx, pres, arg, e.id, none);
+ }
+ none. { ret pure_exp(fcx.ccx, e.id, pres); }
}
- case (expr_chan(?ex)) {
- ret find_pre_post_state_sub(fcx, pres, ex, e.id, none);
- }
- case (expr_mac(_)) {
- fcx.ccx.tcx.sess.bug("unexpanded macro");
- }
- case (expr_put(?maybe_e)) {
- alt (maybe_e) {
- case (some(?arg)) {
- ret find_pre_post_state_sub(fcx, pres, arg, e.id, none);
- }
- case (none) { ret pure_exp(fcx.ccx, e.id, pres); }
- }
- }
- case (expr_lit(?l)) { ret pure_exp(fcx.ccx, e.id, pres); }
- case (expr_fn(?f)) { ret pure_exp(fcx.ccx, e.id, pres); }
- case (expr_block(?b)) {
- ret find_pre_post_state_block(fcx, pres, b) |
+ }
+ expr_lit(l) { ret pure_exp(fcx.ccx, e.id, pres); }
+ expr_fn(f) { ret pure_exp(fcx.ccx, e.id, pres); }
+ expr_block(b) {
+ ret find_pre_post_state_block(fcx, pres, b) |
set_prestate_ann(fcx.ccx, e.id, pres) |
set_poststate_ann(fcx.ccx, e.id, block_poststate(fcx.ccx, b));
+ }
+ expr_rec(fields, maybe_base) {
+ let changed =
+ find_pre_post_state_exprs(fcx, pres, e.id, field_exprs(fields),
+ return);
+ alt maybe_base {
+ none. {/* do nothing */ }
+ some(base) {
+ changed |=
+ find_pre_post_state_expr(fcx, pres, base) |
+ set_poststate_ann(fcx.ccx, e.id,
+ expr_poststate(fcx.ccx, base));
+ }
}
- case (expr_rec(?fields, ?maybe_base)) {
- auto changed = find_pre_post_state_exprs
- (fcx, pres, e.id, field_exprs(fields), return);
- alt (maybe_base) {
- case (none) {/* do nothing */ }
- case (some(?base)) {
- changed |= find_pre_post_state_expr(fcx, pres, base) |
- set_poststate_ann(fcx.ccx, e.id,
- expr_poststate(fcx.ccx, base));
- }
- }
- ret changed;
- }
- case (expr_move(?lhs, ?rhs)) {
- ret find_pre_post_state_two(fcx, pres, lhs, rhs,
- e.id, oper_move);
- }
- case (expr_assign(?lhs, ?rhs)) {
- ret find_pre_post_state_two(fcx, pres, lhs, rhs,
- e.id, oper_assign);
- }
- case (expr_swap(?lhs, ?rhs)) {
- ret find_pre_post_state_two(fcx, pres, lhs, rhs, e.id,
- oper_swap);
- // Could be more precise and actually swap the role of
- // lhs and rhs in constraints
- }
- case (expr_recv(?lhs, ?rhs)) {
- // Opposite order as most other binary operations,
- // so not using find_pre_post_state_two
- auto changed = set_prestate_ann(fcx.ccx, e.id, pres) |
+ ret changed;
+ }
+ expr_move(lhs, rhs) {
+ ret find_pre_post_state_two(fcx, pres, lhs, rhs, e.id, oper_move);
+ }
+ expr_assign(lhs, rhs) {
+ ret find_pre_post_state_two(fcx, pres, lhs, rhs, e.id, oper_assign);
+ }
+ expr_swap(lhs, rhs) {
+ ret find_pre_post_state_two(fcx, pres, lhs, rhs, e.id, oper_swap);
+ // Could be more precise and actually swap the role of
+ // lhs and rhs in constraints
+ }
+ expr_recv(lhs, rhs) {
+ // Opposite order as most other binary operations,
+ // so not using find_pre_post_state_two
+ let changed =
+ set_prestate_ann(fcx.ccx, e.id, pres) |
find_pre_post_state_expr(fcx, pres, lhs) |
- find_pre_post_state_expr
- (fcx, expr_poststate(fcx.ccx, lhs), rhs);
- auto post = tritv_clone(expr_poststate(fcx.ccx, rhs));
- forget_in_poststate_still_init(fcx, post, rhs.id);
- gen_if_local(fcx, post, rhs);
- ret changed | set_poststate_ann(fcx.ccx, e.id, post);
- }
- case (expr_ret(?maybe_ret_val)) {
- auto changed = set_prestate_ann(fcx.ccx, e.id, pres);
- /* normally, everything is true if execution continues after
- a ret expression (since execution never continues locally
- after a ret expression */
+ find_pre_post_state_expr(fcx, expr_poststate(fcx.ccx, lhs),
+ rhs);
+ let post = tritv_clone(expr_poststate(fcx.ccx, rhs));
+ forget_in_poststate_still_init(fcx, post, rhs.id);
+ gen_if_local(fcx, post, rhs);
+ ret changed | set_poststate_ann(fcx.ccx, e.id, post);
+ }
+ expr_ret(maybe_ret_val) {
+ let changed = set_prestate_ann(fcx.ccx, e.id, pres);
+ /* normally, everything is true if execution continues after
+ a ret expression (since execution never continues locally
+ after a ret expression */
- set_poststate_ann(fcx.ccx, e.id, false_postcond(num_constrs));
- /* return from an always-failing function clears the return bit */
+ set_poststate_ann(fcx.ccx, e.id, false_postcond(num_constrs));
+ /* return from an always-failing function clears the return bit */
- alt (fcx.enclosing.cf) {
- case (noreturn) {
- kill_poststate(fcx, e.id, ninit(fcx.id, fcx.name));
- }
- case (_) { }
- }
- alt (maybe_ret_val) {
- case (none) {/* do nothing */ }
- case (some(?ret_val)) {
- changed |= find_pre_post_state_expr(fcx, pres, ret_val);
- }
- }
- ret changed;
+ alt fcx.enclosing.cf {
+ noreturn. { kill_poststate(fcx, e.id, ninit(fcx.id, fcx.name)); }
+ _ { }
}
- case (expr_be(?val)) {
- auto changed = set_prestate_ann(fcx.ccx, e.id, pres);
- set_poststate_ann(fcx.ccx, e.id, false_postcond(num_constrs));
- ret changed | find_pre_post_state_expr(fcx, pres, val);
+ alt maybe_ret_val {
+ none. {/* do nothing */ }
+ some(ret_val) {
+ changed |= find_pre_post_state_expr(fcx, pres, ret_val);
+ }
}
- case (expr_if(?antec, ?conseq, ?maybe_alt)) {
- ret join_then_else
- (fcx, antec, conseq, maybe_alt, e.id, plain_if, pres);
- }
- case (expr_ternary(_, _, _)) {
- ret find_pre_post_state_expr(fcx, pres, ternary_to_if(e));
- }
- case (expr_binary(?bop, ?l, ?r)) {
- if (lazy_binop(bop)) {
- auto changed = find_pre_post_state_expr(fcx, pres, l);
- changed |= find_pre_post_state_expr(fcx,
- expr_poststate(fcx.ccx, l), r);
- ret changed
- | set_prestate_ann(fcx.ccx, e.id, pres)
- | set_poststate_ann(fcx.ccx, e.id,
- expr_poststate(fcx.ccx, l));
- }
- else {
- ret find_pre_post_state_two(fcx, pres, l, r, e.id, oper_pure);
- }
- }
- case (expr_send(?l, ?r)) {
+ ret changed;
+ }
+ expr_be(val) {
+ let changed = set_prestate_ann(fcx.ccx, e.id, pres);
+ set_poststate_ann(fcx.ccx, e.id, false_postcond(num_constrs));
+ ret changed | find_pre_post_state_expr(fcx, pres, val);
+ }
+ expr_if(antec, conseq, maybe_alt) {
+ ret join_then_else(fcx, antec, conseq, maybe_alt, e.id, plain_if,
+ pres);
+ }
+ expr_ternary(_, _, _) {
+ ret find_pre_post_state_expr(fcx, pres, ternary_to_if(e));
+ }
+ expr_binary(bop, l, r) {
+ if lazy_binop(bop) {
+ let changed = find_pre_post_state_expr(fcx, pres, l);
+ changed |=
+ find_pre_post_state_expr(fcx, expr_poststate(fcx.ccx, l), r);
+ ret changed | set_prestate_ann(fcx.ccx, e.id, pres) |
+ set_poststate_ann(fcx.ccx, e.id,
+ expr_poststate(fcx.ccx, l));
+ } else {
ret find_pre_post_state_two(fcx, pres, l, r, e.id, oper_pure);
}
- case (expr_assign_op(?op, ?lhs, ?rhs)) {
- ret find_pre_post_state_two(fcx, pres, lhs, rhs, e.id,
- oper_assign_op);
- }
- case (expr_while(?test, ?body)) {
- /*
- log_err "in a while loop:";
- log_expr_err(*e);
- aux::log_tritv_err(fcx, block_poststate(fcx.ccx, body));
- aux::log_tritv_err(fcx, pres);
- */
- auto loop_pres = intersect_states
- (block_poststate(fcx.ccx, body), pres);
- // aux::log_tritv_err(fcx, loop_pres);
- // log_err "---------------";
+ }
+ expr_send(l, r) {
+ ret find_pre_post_state_two(fcx, pres, l, r, e.id, oper_pure);
+ }
+ expr_assign_op(op, lhs, rhs) {
+ ret find_pre_post_state_two(fcx, pres, lhs, rhs, e.id,
+ oper_assign_op);
+ }
+ expr_while(test, body) {
+ /*
+ log_err "in a while loop:";
+ log_expr_err(*e);
+ aux::log_tritv_err(fcx, block_poststate(fcx.ccx, body));
+ aux::log_tritv_err(fcx, pres);
+ */
+ let loop_pres =
+ intersect_states(block_poststate(fcx.ccx, body), pres);
+ // aux::log_tritv_err(fcx, loop_pres);
+ // log_err "---------------";
- auto changed = set_prestate_ann(fcx.ccx, e.id, loop_pres) |
+ let changed =
+ set_prestate_ann(fcx.ccx, e.id, loop_pres) |
find_pre_post_state_expr(fcx, loop_pres, test) |
find_pre_post_state_block(fcx, expr_poststate(fcx.ccx, test),
body);
- /* conservative approximation: if a loop contains a break
- or cont, we assume nothing about the poststate */
- /* which is still unsound -- see [Break-unsound] */
- if (has_nonlocal_exits(body)) {
- ret changed | set_poststate_ann(fcx.ccx, e.id, pres);
- }
- else {
- auto e_post = expr_poststate(fcx.ccx, test);
- auto b_post = block_poststate(fcx.ccx, body);
- ret changed | set_poststate_ann
- (fcx.ccx, e.id, intersect_states(e_post, b_post));
- }
- }
- case (expr_do_while(?body, ?test)) {
- auto loop_pres = intersect_states(expr_poststate(fcx.ccx, test),
- pres);
- auto changed = set_prestate_ann(fcx.ccx, e.id, loop_pres);
- changed |= find_pre_post_state_block(fcx, loop_pres, body);
- /* conservative approximination: if the body of the loop
- could break or cont, we revert to the prestate
- (TODO: could treat cont differently from break, since
- if there's a cont, the test will execute) */
+ /* conservative approximation: if a loop contains a break
+ or cont, we assume nothing about the poststate */
+ /* which is still unsound -- see [Break-unsound] */
+ if has_nonlocal_exits(body) {
+ ret changed | set_poststate_ann(fcx.ccx, e.id, pres);
+ } else {
+ let e_post = expr_poststate(fcx.ccx, test);
+ let b_post = block_poststate(fcx.ccx, body);
+ ret changed |
+ set_poststate_ann(fcx.ccx, e.id,
+ intersect_states(e_post, b_post));
+ }
+ }
+ expr_do_while(body, test) {
+ let loop_pres = intersect_states(expr_poststate(fcx.ccx, test), pres);
- changed |= find_pre_post_state_expr
- (fcx, block_poststate(fcx.ccx, body), test);
+ let changed = set_prestate_ann(fcx.ccx, e.id, loop_pres);
+ changed |= find_pre_post_state_block(fcx, loop_pres, body);
+ /* conservative approximination: if the body of the loop
+ could break or cont, we revert to the prestate
+ (TODO: could treat cont differently from break, since
+ if there's a cont, the test will execute) */
- auto breaks = has_nonlocal_exits(body);
- if (breaks) {
- // this should probably be true_poststate and not pres,
- // b/c the body could invalidate stuff
- // FIXME [Break-unsound]
- // This is unsound as it is -- consider
- // while (true) {
- // x <- y;
- // break;
- // }
- // The poststate wouldn't take into account that
- // y gets deinitialized
- changed |= set_poststate_ann(fcx.ccx, e.id, pres);
- }
- else {
- changed |= set_poststate_ann
- (fcx.ccx, e.id, expr_poststate(fcx.ccx, test));
- }
- ret changed;
- }
- case (expr_for(?d, ?index, ?body)) {
- ret find_pre_post_state_loop(fcx, pres, d, index, body, e.id);
- }
- case (expr_for_each(?d, ?index, ?body)) {
- ret find_pre_post_state_loop(fcx, pres, d, index, body, e.id);
- }
- case (expr_index(?val, ?sub)) {
- ret find_pre_post_state_two(fcx, pres, val, sub, e.id, oper_pure);
- }
- case (expr_alt(?val, ?alts)) {
- auto changed = set_prestate_ann(fcx.ccx, e.id, pres) |
- find_pre_post_state_expr(fcx, pres, val);
- auto e_post = expr_poststate(fcx.ccx, val);
- auto a_post;
- if (ivec::len(alts) > 0u) {
- a_post = false_postcond(num_constrs);
- for (arm an_alt in alts) {
- changed |= find_pre_post_state_block
- (fcx, e_post, an_alt.block);
- intersect(a_post, block_poststate(fcx.ccx, an_alt.block));
- // We deliberately do *not* update changed here, because
- // we'd go into an infinite loop that way, and the change
- // gets made after the if expression.
+ changed |=
+ find_pre_post_state_expr(fcx, block_poststate(fcx.ccx, body),
+ test);
- }
- } else {
- // No alts; poststate is the poststate of the test
-
- a_post = e_post;
- }
- ret changed | set_poststate_ann(fcx.ccx, e.id, a_post);
- }
- case (expr_field(?val, _)) {
- ret find_pre_post_state_sub(fcx, pres, val, e.id, none);
- }
- case (expr_unary(_, ?operand)) {
- ret find_pre_post_state_sub(fcx, pres, operand, e.id, none);
- }
- case (expr_cast(?operand, _)) {
- ret find_pre_post_state_sub(fcx, pres, operand, e.id, none);
- }
- case (expr_fail(?maybe_fail_val)) {
- ret set_prestate_ann(fcx.ccx, e.id, pres) |
- /* if execution continues after fail, then everything is true!
- woo! */
+ let breaks = has_nonlocal_exits(body);
+ if breaks {
+ // this should probably be true_poststate and not pres,
+ // b/c the body could invalidate stuff
+ // FIXME [Break-unsound]
+ // This is unsound as it is -- consider
+ // while (true) {
+ // x <- y;
+ // break;
+ // }
+ // The poststate wouldn't take into account that
+ // y gets deinitialized
+ changed |= set_poststate_ann(fcx.ccx, e.id, pres);
+ } else {
+ changed |=
set_poststate_ann(fcx.ccx, e.id,
- false_postcond(num_constrs)) |
- alt(maybe_fail_val) {
- case (none) { false }
- case (some(?fail_val)) {
- find_pre_post_state_expr(fcx, pres, fail_val)
- }
- }
+ expr_poststate(fcx.ccx, test));
}
- case (expr_assert(?p)) {
- ret find_pre_post_state_sub(fcx, pres, p, e.id, none);
- }
- case (expr_check(_, ?p)) {
- /* predicate p holds after this expression executes */
- let sp_constr c = expr_to_constr(fcx.ccx.tcx, p);
- ret find_pre_post_state_sub(fcx, pres, p, e.id, some(c.node));
- }
- case (expr_if_check(?p, ?conseq, ?maybe_alt)) {
- ret join_then_else
- (fcx, p, conseq, maybe_alt, e.id, if_check, pres);
- }
- case (expr_break) { ret pure_exp(fcx.ccx, e.id, pres); }
- case (expr_cont) { ret pure_exp(fcx.ccx, e.id, pres); }
- case (expr_port(_)) { ret pure_exp(fcx.ccx, e.id, pres); }
- case (expr_self_method(_)) { ret pure_exp(fcx.ccx, e.id, pres); }
- case (expr_anon_obj(?anon_obj)) {
- alt (anon_obj.with_obj) {
- case (some(?wt)) {
- ret find_pre_post_state_sub(fcx, pres, wt, e.id, none);
- }
- case (none) { ret pure_exp(fcx.ccx, e.id, pres); }
+ ret changed;
+ }
+ expr_for(d, index, body) {
+ ret find_pre_post_state_loop(fcx, pres, d, index, body, e.id);
+ }
+ expr_for_each(d, index, body) {
+ ret find_pre_post_state_loop(fcx, pres, d, index, body, e.id);
+ }
+ expr_index(val, sub) {
+ ret find_pre_post_state_two(fcx, pres, val, sub, e.id, oper_pure);
+ }
+ expr_alt(val, alts) {
+ let changed =
+ set_prestate_ann(fcx.ccx, e.id, pres) |
+ find_pre_post_state_expr(fcx, pres, val);
+ let e_post = expr_poststate(fcx.ccx, val);
+ let a_post;
+ if ivec::len(alts) > 0u {
+ a_post = false_postcond(num_constrs);
+ for an_alt: arm in alts {
+ changed |=
+ find_pre_post_state_block(fcx, e_post, an_alt.block);
+ intersect(a_post, block_poststate(fcx.ccx, an_alt.block));
+ // We deliberately do *not* update changed here, because
+ // we'd go into an infinite loop that way, and the change
+ // gets made after the if expression.
+
}
+ } else {
+ // No alts; poststate is the poststate of the test
+
+ a_post = e_post;
}
+ ret changed | set_poststate_ann(fcx.ccx, e.id, a_post);
+ }
+ expr_field(val, _) {
+ ret find_pre_post_state_sub(fcx, pres, val, e.id, none);
+ }
+ expr_unary(_, operand) {
+ ret find_pre_post_state_sub(fcx, pres, operand, e.id, none);
+ }
+ expr_cast(operand, _) {
+ ret find_pre_post_state_sub(fcx, pres, operand, e.id, none);
+ }
+ expr_fail(maybe_fail_val) {
+ ret set_prestate_ann(fcx.ccx, e.id, pres) |
+ /* if execution continues after fail, then everything is true!
+ woo! */
+ set_poststate_ann(fcx.ccx, e.id, false_postcond(num_constrs))
+ |
+ alt maybe_fail_val {
+ none. { false }
+ some(fail_val) {
+ find_pre_post_state_expr(fcx, pres, fail_val)
+ }
+ }
+ }
+ expr_assert(p) {
+ ret find_pre_post_state_sub(fcx, pres, p, e.id, none);
+ }
+ expr_check(_, p) {
+ /* predicate p holds after this expression executes */
+ let c: sp_constr = expr_to_constr(fcx.ccx.tcx, p);
+ ret find_pre_post_state_sub(fcx, pres, p, e.id, some(c.node));
+ }
+ expr_if_check(p, conseq, maybe_alt) {
+ ret join_then_else(fcx, p, conseq, maybe_alt, e.id, if_check, pres);
+ }
+ expr_break. { ret pure_exp(fcx.ccx, e.id, pres); }
+ expr_cont. { ret pure_exp(fcx.ccx, e.id, pres); }
+ expr_port(_) { ret pure_exp(fcx.ccx, e.id, pres); }
+ expr_self_method(_) { ret pure_exp(fcx.ccx, e.id, pres); }
+ expr_anon_obj(anon_obj) {
+ alt anon_obj.with_obj {
+ some(wt) { ret find_pre_post_state_sub(fcx, pres, wt, e.id, none); }
+ none. { ret pure_exp(fcx.ccx, e.id, pres); }
+ }
+ }
}
}
-fn find_pre_post_state_stmt(&fn_ctxt fcx, &prestate pres, @stmt s) -> bool {
- auto stmt_ann = stmt_to_ann(fcx.ccx, *s);
+fn find_pre_post_state_stmt(fcx: &fn_ctxt, pres: &prestate, s: @stmt) ->
+ bool {
+ let stmt_ann = stmt_to_ann(fcx.ccx, *s);
+
/*
log_err "*At beginning: stmt = ";
@@ -592,127 +577,123 @@
log_err tritv::to_str(pres);
*/
- alt (s.node) {
- case (stmt_decl(?adecl, ?id)) {
- alt (adecl.node) {
- case (decl_local(?alocals)) {
- auto changed = false;
- for (@local alocal in alocals) {
- alt (alocal.node.init) {
- case (some(?an_init)) {
- auto changed = set_prestate(stmt_ann, pres) |
- find_pre_post_state_expr(fcx, pres,
- an_init.expr);
+ alt s.node {
+ stmt_decl(adecl, id) {
+ alt adecl.node {
+ decl_local(alocals) {
+ let changed = false;
+ for alocal: @local in alocals {
+ alt alocal.node.init {
+ some(an_init) {
+ let changed =
+ set_prestate(stmt_ann, pres) |
+ find_pre_post_state_expr(fcx, pres, an_init.expr);
- auto post = tritv_clone(expr_poststate(fcx.ccx,
- an_init.expr));
- alt (an_init.expr.node) {
- case (expr_path(?p)) {
+ let post =
+ tritv_clone(expr_poststate(fcx.ccx, an_init.expr));
+ alt an_init.expr.node {
+ expr_path(p) {
- auto instlhs =
- rec(ident=alocal.node.ident,
- node=alocal.node.id);
- auto rhs_d = local_node_id_to_local_def_id
- (fcx, an_init.expr.id);
- alt (rhs_d) {
- case (some(?rhsid)) {
- auto instrhs =
- rec(ident=path_to_ident
- (fcx.ccx.tcx, p),
- node=rhsid);
- copy_in_poststate(fcx, post,
- instlhs, instrhs,
- op_to_oper_ty(an_init.op));
- }
- case (_) { }
- }
- }
- case (_) { }
- }
- if (an_init.op == init_move) {
- forget_in_poststate(fcx, post,
- an_init.expr.id);
- }
- set_in_poststate_ident(fcx, alocal.node.id,
- alocal.node.ident, post);
- /*
- log_err "Summary: stmt = ";
- log_stmt_err(*s);
- log_err "prestate = ";
- log_tritv_err(fcx, stmt_ann.states.prestate);
- log_err "poststate =";
- log_tritv_err(fcx, post);
- log_err "changed =";
- log_err changed;
- */
- /* important to do this in one step to ensure
- termination (don't want to set changed to true
- for intermediate changes) */
- changed |= set_poststate(stmt_ann, post);
+ let instlhs =
+ {ident: alocal.node.ident, node: alocal.node.id};
+ let rhs_d =
+ local_node_id_to_local_def_id(fcx,
+ an_init.expr.id);
+ alt rhs_d {
+ some(rhsid) {
+ let instrhs =
+ {ident: path_to_ident(fcx.ccx.tcx, p),
+ node: rhsid};
+ copy_in_poststate(fcx, post, instlhs, instrhs,
+ op_to_oper_ty(an_init.op));
+ }
+ _ { }
}
- case (none) {
- // let int = x; => x is uninit in poststate
- set_poststate_ann(fcx.ccx, id, pres);
- clear_in_poststate_ident(fcx, alocal.node.id,
- alocal.node.ident, id);
- set_prestate(stmt_ann, pres);
- }
+ }
+ _ { }
}
+ if an_init.op == init_move {
+ forget_in_poststate(fcx, post, an_init.expr.id);
+ }
+ set_in_poststate_ident(fcx, alocal.node.id,
+ alocal.node.ident, post);
+ /*
+ log_err "Summary: stmt = ";
+ log_stmt_err(*s);
+ log_err "prestate = ";
+ log_tritv_err(fcx, stmt_ann.states.prestate);
+ log_err "poststate =";
+ log_tritv_err(fcx, post);
+ log_err "changed =";
+ log_err changed;
+ */
+ /* important to do this in one step to ensure
+ termination (don't want to set changed to true
+ for intermediate changes) */
+ changed |= set_poststate(stmt_ann, post);
}
- ret changed;
- }
- case (decl_item(?an_item)) {
- ret set_prestate(stmt_ann, pres) |
- set_poststate(stmt_ann, pres);
- /* the outer "walk" will recurse into the item */
+ none. {
+ // let int = x; => x is uninit in poststate
+ set_poststate_ann(fcx.ccx, id, pres);
+ clear_in_poststate_ident(fcx, alocal.node.id,
+ alocal.node.ident, id);
+ set_prestate(stmt_ann, pres);
+ }
}
}
+ ret changed;
+ }
+ decl_item(an_item) {
+ ret set_prestate(stmt_ann, pres) | set_poststate(stmt_ann, pres);
+ /* the outer "walk" will recurse into the item */
+ }
}
- case (stmt_expr(?ex, _)) {
- ret find_pre_post_state_expr(fcx, pres, ex) |
+ }
+ stmt_expr(ex, _) {
+ ret find_pre_post_state_expr(fcx, pres, ex) |
set_prestate(stmt_ann, expr_prestate(fcx.ccx, ex)) |
set_poststate(stmt_ann, expr_poststate(fcx.ccx, ex));
- /*
- log_err "Finally:";
- log_stmt_err(*s);
- log_err("prestate = ");
- // log_err(bitv::to_str(stmt_ann.states.prestate));
- log_tritv_err(fcx, stmt_ann.states.prestate);
- log_err("poststate =");
- // log_err(bitv::to_str(stmt_ann.states.poststate));
- log_tritv_err(fcx, stmt_ann.states.poststate);
- log_err("changed =");
- log_err(changed);
- */
- }
- case (_) { ret false; }
+ /*
+ log_err "Finally:";
+ log_stmt_err(*s);
+ log_err("prestate = ");
+ // log_err(bitv::to_str(stmt_ann.states.prestate));
+ log_tritv_err(fcx, stmt_ann.states.prestate);
+ log_err("poststate =");
+ // log_err(bitv::to_str(stmt_ann.states.poststate));
+ log_tritv_err(fcx, stmt_ann.states.poststate);
+ log_err("changed =");
+ log_err(changed);
+ */
+ }
+ _ { ret false; }
}
}
/* Updates the pre- and post-states of statements in the block,
returns a boolean flag saying whether any pre- or poststates changed */
-fn find_pre_post_state_block(&fn_ctxt fcx, &prestate pres0, &blk b)
- -> bool {
+fn find_pre_post_state_block(fcx: &fn_ctxt, pres0: &prestate, b: &blk) ->
+ bool {
/* First, set the pre-states and post-states for every expression */
- auto pres = pres0;
+ let pres = pres0;
/* Iterate over each stmt. The new prestate is <pres>. The poststate
consist of improving <pres> with whatever variables this stmt
initializes. Then <pres> becomes the new poststate. */
- auto changed = false;
- for (@stmt s in b.node.stmts) {
+ let changed = false;
+ for s: @stmt in b.node.stmts {
changed |= find_pre_post_state_stmt(fcx, pres, s);
pres = stmt_poststate(fcx.ccx, *s);
}
- auto post = pres;
- alt (b.node.expr) {
- case (none) { }
- case (some(?e)) {
- changed |= find_pre_post_state_expr(fcx, pres, e);
- post = expr_poststate(fcx.ccx, e);
- }
+ let post = pres;
+ alt b.node.expr {
+ none. { }
+ some(e) {
+ changed |= find_pre_post_state_expr(fcx, pres, e);
+ post = expr_poststate(fcx.ccx, e);
+ }
}
set_prestate_ann(fcx.ccx, b.node.id, pres0);
@@ -732,43 +713,44 @@
ret changed;
}
-fn find_pre_post_state_fn(&fn_ctxt fcx, &_fn f) -> bool {
- auto num_local_vars = num_constraints(fcx.enclosing);
+fn find_pre_post_state_fn(fcx: &fn_ctxt, f: &_fn) -> bool {
+ let num_local_vars = num_constraints(fcx.enclosing);
// make sure the return bit starts out False
clear_in_prestate_ident(fcx, fcx.id, fcx.name, f.body.node.id);
// Instantiate any constraints on the arguments so we can use them
- auto block_pre = block_prestate(fcx.ccx, f.body);
- auto tsc;
- for (@constr c in f.decl.constraints) {
+ let block_pre = block_prestate(fcx.ccx, f.body);
+ let tsc;
+ for c: @constr in f.decl.constraints {
tsc = ast_constr_to_ts_constr(fcx.ccx.tcx, f.decl.inputs, c);
set_in_prestate_constr(fcx, tsc, block_pre);
}
- auto changed = find_pre_post_state_block(fcx, block_pre, f.body);
+ let changed = find_pre_post_state_block(fcx, block_pre, f.body);
// Treat the tail expression as a return statement
- alt (f.body.node.expr) {
- case (some(?tailexpr)) {
- auto tailty = expr_ty(fcx.ccx.tcx, tailexpr);
+ alt f.body.node.expr {
+ some(tailexpr) {
+ let tailty = expr_ty(fcx.ccx.tcx, tailexpr);
- // Since blocks and alts and ifs that don't have results
- // implicitly result in nil, we have to be careful to not
- // interpret nil-typed block results as the result of a
- // function with some other return type
- if (!type_is_nil(fcx.ccx.tcx, tailty) &&
- !type_is_bot(fcx.ccx.tcx, tailty)) {
- auto p = false_postcond(num_local_vars);
- set_poststate_ann(fcx.ccx, f.body.node.id, p);
- }
+
+ // Since blocks and alts and ifs that don't have results
+ // implicitly result in nil, we have to be careful to not
+ // interpret nil-typed block results as the result of a
+ // function with some other return type
+ if !type_is_nil(fcx.ccx.tcx, tailty) &&
+ !type_is_bot(fcx.ccx.tcx, tailty) {
+ let p = false_postcond(num_local_vars);
+ set_poststate_ann(fcx.ccx, f.body.node.id, p);
}
- case (none) {/* fallthrough */ }
+ }
+ none. {/* fallthrough */ }
}
-/*
- log_err "find_pre_post_state_fn";
- log_err changed;
- fcx.ccx.tcx.sess.span_note(f.body.span, fcx.name);
-*/
+ /*
+ log_err "find_pre_post_state_fn";
+ log_err changed;
+ fcx.ccx.tcx.sess.span_note(f.body.span, fcx.name);
+ */
ret changed;
}
diff --git a/src/comp/middle/tstate/tritv.rs b/src/comp/middle/tstate/tritv.rs
index 26ae3f49..7615b84 100644
--- a/src/comp/middle/tstate/tritv.rs
+++ b/src/comp/middle/tstate/tritv.rs
@@ -28,21 +28,18 @@
have the same length; 11 should never appear in a given position)
*/
-type t = rec(bitv::t uncertain, bitv::t val, uint nbits);
-tag trit {
- ttrue;
- tfalse;
- dont_care;
-}
+type t = {uncertain: bitv::t, val: bitv::t, nbits: uint};
+tag trit { ttrue; tfalse; dont_care; }
-fn create_tritv(uint len) -> t {
- ret rec(uncertain=bitv::create(len, true),
- val=bitv::create(len, false),
- nbits=len);
+fn create_tritv(len: uint) -> t {
+ ret {uncertain: bitv::create(len, true),
+ val: bitv::create(len, false),
+ nbits: len};
}
-fn trit_minus(trit a, trit b) -> trit {
+fn trit_minus(a: trit, b: trit) -> trit {
+
/* 2 - anything = 2
1 - 1 = 2
1 - 0 is an error
@@ -50,36 +47,45 @@
0 - 1 is an error
0 - anything else - 0
*/
- alt (a) {
- case (dont_care) { dont_care }
- case (ttrue) {
- alt (b) {
- case (ttrue) { dont_care }
- case (tfalse) { ttrue } /* internally contradictory, but
- I guess it'll get flagged? */
- case (dont_care) { ttrue }
+ alt a {
+ dont_care. { dont_care }
+ ttrue. {
+ alt b {
+ ttrue. { dont_care }
+ tfalse. { ttrue }
+ /* internally contradictory, but
+ I guess it'll get flagged? */
+ dont_care. {
+ ttrue
+ }
+ }
+ }
+ tfalse. {
+ alt b {
+ ttrue. { tfalse }
+ /* see above comment */
+ _ {
+ tfalse
+ }
+ }
}
}
- case (tfalse) {
- alt (b) {
- case (ttrue) { tfalse } /* see above comment */
- case (_) { tfalse }
- }
- }
- }
}
-fn trit_or(trit a, trit b) -> trit {
- alt (a) {
- case (dont_care) { b }
- case (ttrue) { ttrue }
- case (tfalse) {
- alt (b) {
- case (ttrue) { dont_care } /* FIXME: ?????? */
- case (_) { tfalse }
+fn trit_or(a: trit, b: trit) -> trit {
+ alt a {
+ dont_care. { b }
+ ttrue. { ttrue }
+ tfalse. {
+ alt b {
+ ttrue. { dont_care }
+ /* FIXME: ?????? */
+ _ {
+ tfalse
+ }
+ }
}
}
- }
}
// FIXME: This still seems kind of dodgy to me (that is,
@@ -87,170 +93,174 @@
// all variables start out in a 0 state. Probably I need
// to make it so that all constraints start out in a 0 state
// (we consider a constraint false until proven true), too.
-fn trit_and(trit a, trit b) -> trit {
- alt (a) {
- case (dont_care) { b } // also seems wrong for case b = ttrue
- case (ttrue) {
- alt (b) {
- case (dont_care) { ttrue } // ??? Seems wrong
- case (ttrue) { ttrue }
- // false wins, since if something is uninit
- // on one path, we care
- // (Rationale: it's always safe to assume that
- // a var is uninitialized or that a constraint
- // needs to be re-established)
- case (tfalse) { tfalse }
+fn trit_and(a: trit, b: trit) -> trit {
+ alt a {
+ dont_care. { b }
+ // also seems wrong for case b = ttrue
+ ttrue. {
+ alt b {
+ dont_care. { ttrue }
+ // ??? Seems wrong
+ ttrue. {
+ ttrue
}
+
+ // false wins, since if something is uninit
+ // on one path, we care
+ // (Rationale: it's always safe to assume that
+ // a var is uninitialized or that a constraint
+ // needs to be re-established)
+ tfalse. {
+ tfalse
+ }
+ }
}
+
// Rationale: if it's uninit on one path,
// we can consider it as uninit on all paths
- case (tfalse) { tfalse }
- }
- // if the result is dont_care, that means
- // a and b were both dont_care
+ tfalse. {
+ tfalse
+ }
+ }
+ // if the result is dont_care, that means
+ // a and b were both dont_care
}
-fn change(bool changed, trit old, trit new) -> bool { changed || new != old }
+fn change(changed: bool, old: trit, new: trit) -> bool {
+ changed || new != old
+}
-fn tritv_difference(&t p1, &t p2) -> bool {
- let uint i = 0u;
+fn tritv_difference(p1: &t, p2: &t) -> bool {
+ let i: uint = 0u;
assert (p1.nbits == p2.nbits);
- let uint sz = p1.nbits;
- auto changed = false;
- while (i < sz) {
- auto old = tritv_get(p1, i);
- auto new = trit_minus(old, tritv_get(p2, i));
- changed = change(changed, old, new);
- tritv_set(i, p1, new);
- i += 1u;
+ let sz: uint = p1.nbits;
+ let changed = false;
+ while i < sz {
+ let old = tritv_get(p1, i);
+ let new = trit_minus(old, tritv_get(p2, i));
+ changed = change(changed, old, new);
+ tritv_set(i, p1, new);
+ i += 1u;
}
ret changed;
}
-fn tritv_union(&t p1, &t p2) -> bool {
- let uint i = 0u;
+fn tritv_union(p1: &t, p2: &t) -> bool {
+ let i: uint = 0u;
assert (p1.nbits == p2.nbits);
- let uint sz = p1.nbits;
- auto changed = false;
- while (i < sz) {
- auto old = tritv_get(p1, i);
- auto new = trit_or(old, tritv_get(p2, i));
- changed = change(changed, old, new);
- tritv_set(i, p1, new);
- i += 1u;
+ let sz: uint = p1.nbits;
+ let changed = false;
+ while i < sz {
+ let old = tritv_get(p1, i);
+ let new = trit_or(old, tritv_get(p2, i));
+ changed = change(changed, old, new);
+ tritv_set(i, p1, new);
+ i += 1u;
}
ret changed;
}
-fn tritv_intersect(&t p1, &t p2) -> bool {
- let uint i = 0u;
+fn tritv_intersect(p1: &t, p2: &t) -> bool {
+ let i: uint = 0u;
assert (p1.nbits == p2.nbits);
- let uint sz = p1.nbits;
- auto changed = false;
- while (i < sz) {
- auto old = tritv_get(p1, i);
- auto new = trit_and(old, tritv_get(p2, i));
- changed = change(changed, old, new);
- tritv_set(i, p1, new);
- i += 1u;
+ let sz: uint = p1.nbits;
+ let changed = false;
+ while i < sz {
+ let old = tritv_get(p1, i);
+ let new = trit_and(old, tritv_get(p2, i));
+ changed = change(changed, old, new);
+ tritv_set(i, p1, new);
+ i += 1u;
}
ret changed;
}
-fn tritv_get(&t v, uint i) -> trit {
- auto b1 = bitv::get(v.uncertain, i);
- auto b2 = bitv::get(v.val, i);
- assert (! (b1 && b2));
- if (b1) { dont_care }
- else if (b2) { ttrue }
- else { tfalse}
+fn tritv_get(v: &t, i: uint) -> trit {
+ let b1 = bitv::get(v.uncertain, i);
+ let b2 = bitv::get(v.val, i);
+ assert (!(b1 && b2));
+ if b1 { dont_care } else if (b2) { ttrue } else { tfalse }
}
-fn tritv_set(uint i, &t v, trit t) -> bool {
- auto old = tritv_get(v, i);
- alt (t) {
- case (dont_care) {
- bitv::set(v.uncertain, i, true);
- bitv::set(v.val, i, false);
+fn tritv_set(i: uint, v: &t, t: trit) -> bool {
+ let old = tritv_get(v, i);
+ alt t {
+ dont_care. {
+ bitv::set(v.uncertain, i, true);
+ bitv::set(v.val, i, false);
+ }
+ ttrue. { bitv::set(v.uncertain, i, false); bitv::set(v.val, i, true); }
+ tfalse. {
+ bitv::set(v.uncertain, i, false);
+ bitv::set(v.val, i, false);
+ }
}
- case (ttrue) {
- bitv::set(v.uncertain, i, false);
- bitv::set(v.val, i, true);
+ ret change(false, old, t);
+}
+
+fn tritv_copy(target: &t, source: &t) -> bool {
+ assert (target.nbits == source.nbits);
+ let changed =
+ !bitv::equal(target.uncertain, source.uncertain) ||
+ !bitv::equal(target.val, source.val);
+ bitv::copy(target.uncertain, source.uncertain);
+ bitv::copy(target.val, source.val);
+ ret changed;
+}
+
+fn tritv_set_all(v: &t) {
+ let i: uint = 0u;
+ while i < v.nbits { tritv_set(i, v, ttrue); i += 1u; }
+}
+
+fn tritv_clear(v: &t) {
+ let i: uint = 0u;
+ while i < v.nbits { tritv_set(i, v, dont_care); i += 1u; }
+}
+
+fn tritv_clone(v: &t) -> t {
+ ret {uncertain: bitv::clone(v.uncertain),
+ val: bitv::clone(v.val),
+ nbits: v.nbits};
+}
+
+fn tritv_doesntcare(v: &t) -> bool {
+ let i: uint = 0u;
+ while i < v.nbits {
+ if tritv_get(v, i) != dont_care { ret false; }
+ i += 1u;
}
- case (tfalse) {
- bitv::set(v.uncertain, i, false);
- bitv::set(v.val, i, false);
+ ret true;
+}
+
+fn to_vec(v: &t) -> uint[] {
+ let i: uint = 0u;
+ let rslt: uint[] = ~[];
+ while i < v.nbits {
+ rslt +=
+ ~[alt tritv_get(v, i) {
+ dont_care. { 2u }
+ ttrue. { 1u }
+ tfalse. { 0u }
+ }];
+ i += 1u;
}
- }
- ret change(false, old, t);
+ ret rslt;
}
-fn tritv_copy(&t target, &t source) -> bool {
- assert (target.nbits == source.nbits);
- auto changed = !bitv::equal(target.uncertain, source.uncertain) ||
- !bitv::equal(target.val, source.val);
- bitv::copy(target.uncertain, source.uncertain);
- bitv::copy(target.val, source.val);
- ret changed;
-}
-
-fn tritv_set_all(&t v) {
- let uint i = 0u;
- while (i < v.nbits) {
- tritv_set(i, v, ttrue);
- i += 1u;
- }
-}
-
-fn tritv_clear(&t v) {
- let uint i = 0u;
- while (i < v.nbits) {
- tritv_set(i, v, dont_care);
- i += 1u;
- }
-}
-
-fn tritv_clone(&t v) -> t {
- ret rec(uncertain=bitv::clone(v.uncertain),
- val=bitv::clone(v.val),
- nbits=v.nbits);
-}
-
-fn tritv_doesntcare(&t v) -> bool {
- let uint i = 0u;
- while (i < v.nbits) {
- if (tritv_get(v, i) != dont_care) {
- ret false;
+fn to_str(v: &t) -> str {
+ let i: uint = 0u;
+ let rs: str = "";
+ while i < v.nbits {
+ rs +=
+ alt tritv_get(v, i) {
+ dont_care. { "?" }
+ ttrue. { "1" }
+ tfalse. { "0" }
+ };
+ i += 1u;
}
- i += 1u;
- }
- ret true;
-}
-
-fn to_vec(&t v) -> uint[] {
- let uint i = 0u;
- let uint[] rslt = ~[];
- while (i < v.nbits) {
- rslt += ~[alt (tritv_get(v, i)) {
- case (dont_care) { 2u }
- case (ttrue) { 1u }
- case (tfalse) { 0u } }];
- i += 1u;
- }
- ret rslt;
-}
-
-fn to_str(&t v) -> str {
- let uint i = 0u;
- let str rs = "";
- while (i < v.nbits) {
- rs += alt (tritv_get(v, i)) {
- case (dont_care) { "?" }
- case (ttrue) { "1" }
- case (tfalse) { "0" } };
- i += 1u;
- }
- ret rs;
+ ret rs;
}
//
diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs
index 6c29b20..1b3bc84 100644
--- a/src/comp/middle/ty.rs
+++ b/src/comp/middle/ty.rs
@@ -182,42 +182,42 @@
// Data types
tag mode { mo_val; mo_alias(bool); }
-type arg = rec(mode mode, t ty);
+type arg = {mode: mode, ty: t};
-type field = rec(ast::ident ident, mt mt);
+type field = {ident: ast::ident, mt: mt};
type method =
- rec(ast::proto proto,
- ast::ident ident,
- arg[] inputs,
- t output,
- controlflow cf,
- (@constr)[] constrs);
+ {proto: ast::proto,
+ ident: ast::ident,
+ inputs: arg[],
+ output: t,
+ cf: controlflow,
+ constrs: (@constr)[]};
type constr_table = hashmap[ast::node_id, constr[]];
-type mt = rec(t ty, ast::mutability mut);
+type mt = {ty: t, mut: ast::mutability};
// Contains information needed to resolve types and (in the future) look up
// the types of AST nodes.
-type creader_cache = hashmap[rec(int cnum, uint pos, uint len), ty::t];
+type creader_cache = hashmap[{cnum: int, pos: uint, len: uint}, ty::t];
type ctxt =
- @rec(@type_store ts,
- session::session sess,
- resolve::def_map def_map,
- node_type_table node_types,
- ast_map::map items,
- freevars::freevar_map freevars,
- // constr_table fn_constrs,
- type_cache tcache,
- creader_cache rcache,
- hashmap[t, str] short_names_cache,
- hashmap[t, bool] has_pointer_cache,
- hashmap[t, bool] owns_heap_mem_cache,
- hashmap[@ast::ty, option::t[t]] ast_ty_to_ty_cache);
+ // constr_table fn_constrs,
+ @{ts: @type_store,
+ sess: session::session,
+ def_map: resolve::def_map,
+ node_types: node_type_table,
+ items: ast_map::map,
+ freevars: freevars::freevar_map,
+ tcache: type_cache,
+ rcache: creader_cache,
+ short_names_cache: hashmap[t, str],
+ has_pointer_cache: hashmap[t, bool],
+ owns_heap_mem_cache: hashmap[t, bool],
+ ast_ty_to_ty_cache: hashmap[@ast::ty, option::t[t]]};
type ty_ctxt = ctxt;
@@ -225,18 +225,18 @@
// Needed for disambiguation from unify::ctxt.
// Convert from method type to function type. Pretty easy; we just drop
// 'ident'.
-fn method_ty_to_fn_ty(&ctxt cx, method m) -> t {
+fn method_ty_to_fn_ty(cx: &ctxt, m: method) -> t {
ret mk_fn(cx, m.proto, m.inputs, m.output, m.cf, m.constrs);
}
// Never construct these manually. These are interned.
type raw_t =
- rec(sty struct,
- option::t[str] cname,
- uint hash,
- bool has_params,
- bool has_vars);
+ {struct: sty,
+ cname: option::t[str],
+ hash: uint,
+ has_params: bool,
+ has_vars: bool};
type t = uint;
@@ -268,7 +268,9 @@
ty_obj(method[]);
ty_res(def_id, t, t[]);
ty_var(int); // type variable
+
ty_param(uint); // fn/tag type param
+
ty_type;
ty_native(def_id);
ty_constr(t, (@type_constr)[]);
@@ -298,62 +300,62 @@
terr_constr_mismatch(@type_constr, @type_constr);
}
-type ty_param_count_and_ty = rec(uint count, t ty);
+type ty_param_count_and_ty = {count: uint, ty: t};
type type_cache = hashmap[ast::def_id, ty_param_count_and_ty];
-const uint idx_nil = 0u;
+const idx_nil: uint = 0u;
-const uint idx_bool = 1u;
+const idx_bool: uint = 1u;
-const uint idx_int = 2u;
+const idx_int: uint = 2u;
-const uint idx_float = 3u;
+const idx_float: uint = 3u;
-const uint idx_uint = 4u;
+const idx_uint: uint = 4u;
-const uint idx_i8 = 5u;
+const idx_i8: uint = 5u;
-const uint idx_i16 = 6u;
+const idx_i16: uint = 6u;
-const uint idx_i32 = 7u;
+const idx_i32: uint = 7u;
-const uint idx_i64 = 8u;
+const idx_i64: uint = 8u;
-const uint idx_u8 = 9u;
+const idx_u8: uint = 9u;
-const uint idx_u16 = 10u;
+const idx_u16: uint = 10u;
-const uint idx_u32 = 11u;
+const idx_u32: uint = 11u;
-const uint idx_u64 = 12u;
+const idx_u64: uint = 12u;
-const uint idx_f32 = 13u;
+const idx_f32: uint = 13u;
-const uint idx_f64 = 14u;
+const idx_f64: uint = 14u;
-const uint idx_char = 15u;
+const idx_char: uint = 15u;
-const uint idx_str = 16u;
+const idx_str: uint = 16u;
-const uint idx_istr = 17u;
+const idx_istr: uint = 17u;
-const uint idx_task = 18u;
+const idx_task: uint = 18u;
-const uint idx_type = 19u;
+const idx_type: uint = 19u;
-const uint idx_bot = 20u;
+const idx_bot: uint = 20u;
-const uint idx_first_others = 21u;
+const idx_first_others: uint = 21u;
type type_store = interner::interner[@raw_t];
-type ty_param_substs_opt_and_ty = rec(option::t[ty::t[]] substs, ty::t ty);
+type ty_param_substs_opt_and_ty = {substs: option::t[ty::t[]], ty: ty::t};
type node_type_table =
@smallintmap::smallintmap[ty::ty_param_substs_opt_and_ty];
-fn populate_type_store(&ctxt cx) {
+fn populate_type_store(cx: &ctxt) {
intern(cx, ty_nil, none);
intern(cx, ty_bool, none);
intern(cx, ty_int, none);
@@ -379,252 +381,241 @@
}
fn mk_rcache() -> creader_cache {
- type val = rec(int cnum, uint pos, uint len);
- fn hash_cache_entry(&val k) -> uint {
+ type val = {cnum: int, pos: uint, len: uint};
+ fn hash_cache_entry(k: &val) -> uint {
ret (k.cnum as uint) + k.pos + k.len;
}
- fn eq_cache_entries(&val a, &val b) ->
- bool {
+ fn eq_cache_entries(a: &val, b: &val) -> bool {
ret a.cnum == b.cnum && a.pos == b.pos && a.len == b.len;
}
ret map::mk_hashmap(hash_cache_entry, eq_cache_entries);
}
-fn mk_ctxt(session::session s, resolve::def_map dm,
- ast_map::map amap, freevars::freevar_map freevars) -> ctxt {
- let node_type_table ntt =
+fn mk_ctxt(s: session::session, dm: resolve::def_map, amap: ast_map::map,
+ freevars: freevars::freevar_map) -> ctxt {
+ let ntt: node_type_table =
@smallintmap::mk[ty::ty_param_substs_opt_and_ty]();
- auto tcache = new_def_hash[ty::ty_param_count_and_ty]();
- auto ts = @interner::mk[@raw_t](hash_raw_ty, eq_raw_ty);
- auto cx =
- @rec(ts=ts,
- sess=s,
- def_map=dm,
- node_types=ntt,
- items=amap,
- freevars=freevars,
- tcache=tcache,
- rcache=mk_rcache(),
- short_names_cache=map::mk_hashmap(ty::hash_ty, ty::eq_ty),
- has_pointer_cache=map::mk_hashmap(ty::hash_ty, ty::eq_ty),
- owns_heap_mem_cache=map::mk_hashmap(ty::hash_ty, ty::eq_ty),
- ast_ty_to_ty_cache=map::mk_hashmap(ast::hash_ty, ast::eq_ty));
+ let tcache = new_def_hash[ty::ty_param_count_and_ty]();
+ let ts = @interner::mk[@raw_t](hash_raw_ty, eq_raw_ty);
+ let cx =
+ @{ts: ts,
+ sess: s,
+ def_map: dm,
+ node_types: ntt,
+ items: amap,
+ freevars: freevars,
+ tcache: tcache,
+ rcache: mk_rcache(),
+ short_names_cache: map::mk_hashmap(ty::hash_ty, ty::eq_ty),
+ has_pointer_cache: map::mk_hashmap(ty::hash_ty, ty::eq_ty),
+ owns_heap_mem_cache: map::mk_hashmap(ty::hash_ty, ty::eq_ty),
+ ast_ty_to_ty_cache: map::mk_hashmap(ast::hash_ty, ast::eq_ty)};
populate_type_store(cx);
ret cx;
}
// Type constructors
-fn mk_raw_ty(&ctxt cx, &sty st, &option::t[str] in_cname) -> @raw_t {
- auto cname = none;
- auto h = hash_type_info(st, cname);
- let bool has_params = false;
- let bool has_vars = false;
- fn derive_flags_t(&ctxt cx, &mutable bool has_params,
- &mutable bool has_vars, &t tt) {
- auto rt = interner::get[@raw_t](*cx.ts, tt);
+fn mk_raw_ty(cx: &ctxt, st: &sty, in_cname: &option::t[str]) -> @raw_t {
+ let cname = none;
+ let h = hash_type_info(st, cname);
+ let has_params: bool = false;
+ let has_vars: bool = false;
+ fn derive_flags_t(cx: &ctxt, has_params: &mutable bool,
+ has_vars: &mutable bool, tt: &t) {
+ let rt = interner::get[@raw_t](*cx.ts, tt);
has_params = has_params || rt.has_params;
has_vars = has_vars || rt.has_vars;
}
- fn derive_flags_mt(&ctxt cx, &mutable bool has_params,
- &mutable bool has_vars, &mt m) {
+ fn derive_flags_mt(cx: &ctxt, has_params: &mutable bool,
+ has_vars: &mutable bool, m: &mt) {
derive_flags_t(cx, has_params, has_vars, m.ty);
}
- fn derive_flags_arg(&ctxt cx, &mutable bool has_params,
- &mutable bool has_vars, &arg a) {
+ fn derive_flags_arg(cx: &ctxt, has_params: &mutable bool,
+ has_vars: &mutable bool, a: &arg) {
derive_flags_t(cx, has_params, has_vars, a.ty);
}
- fn derive_flags_sig(&ctxt cx, &mutable bool has_params,
- &mutable bool has_vars, &arg[] args, &t tt) {
- for (arg a in args) { derive_flags_arg(cx, has_params, has_vars, a); }
+ fn derive_flags_sig(cx: &ctxt, has_params: &mutable bool,
+ has_vars: &mutable bool, args: &arg[], tt: &t) {
+ for a: arg in args { derive_flags_arg(cx, has_params, has_vars, a); }
derive_flags_t(cx, has_params, has_vars, tt);
}
- alt (st) {
- case (ty_nil) {/* no-op */ }
- case (ty_bot) {/* no-op */ }
- case (ty_bool) {/* no-op */ }
- case (ty_int) {/* no-op */ }
- case (ty_float) {/* no-op */ }
- case (ty_uint) {/* no-op */ }
- case (ty_machine(_)) {/* no-op */ }
- case (ty_char) {/* no-op */ }
- case (ty_str) {/* no-op */ }
- case (ty_istr) {/* no-op */ }
- case (ty_task) {/* no-op */ }
- case (ty_type) {/* no-op */ }
- case (ty_native(_)) {/* no-op */ }
- case (ty_param(_)) { has_params = true; }
- case (ty_var(_)) { has_vars = true; }
- case (ty_tag(_, ?tys)) {
- for (t tt in tys) {
- derive_flags_t(cx, has_params, has_vars, tt);
- }
+ alt st {
+ ty_nil. {/* no-op */ }
+ ty_bot. {/* no-op */ }
+ ty_bool. {/* no-op */ }
+ ty_int. {/* no-op */ }
+ ty_float. {/* no-op */ }
+ ty_uint. {/* no-op */ }
+ ty_machine(_) {/* no-op */ }
+ ty_char. {/* no-op */ }
+ ty_str. {/* no-op */ }
+ ty_istr. {/* no-op */ }
+ ty_task. {/* no-op */ }
+ ty_type. {/* no-op */ }
+ ty_native(_) {/* no-op */ }
+ ty_param(_) { has_params = true; }
+ ty_var(_) { has_vars = true; }
+ ty_tag(_, tys) {
+ for tt: t in tys { derive_flags_t(cx, has_params, has_vars, tt); }
+ }
+ ty_box(m) { derive_flags_mt(cx, has_params, has_vars, m); }
+ ty_vec(m) { derive_flags_mt(cx, has_params, has_vars, m); }
+ ty_ivec(m) { derive_flags_mt(cx, has_params, has_vars, m); }
+ ty_ptr(m) { derive_flags_mt(cx, has_params, has_vars, m); }
+ ty_port(tt) { derive_flags_t(cx, has_params, has_vars, tt); }
+ ty_chan(tt) { derive_flags_t(cx, has_params, has_vars, tt); }
+ ty_rec(flds) {
+ for f: field in flds {
+ derive_flags_mt(cx, has_params, has_vars, f.mt);
}
- case (ty_box(?m)) { derive_flags_mt(cx, has_params, has_vars, m); }
- case (ty_vec(?m)) { derive_flags_mt(cx, has_params, has_vars, m); }
- case (ty_ivec(?m)) { derive_flags_mt(cx, has_params, has_vars, m); }
- case (ty_ptr(?m)) { derive_flags_mt(cx, has_params, has_vars, m); }
- case (ty_port(?tt)) { derive_flags_t(cx, has_params, has_vars, tt); }
- case (ty_chan(?tt)) { derive_flags_t(cx, has_params, has_vars, tt); }
- case (ty_rec(?flds)) {
- for (field f in flds) {
- derive_flags_mt(cx, has_params, has_vars, f.mt);
- }
+ }
+ ty_fn(_, args, tt, _, _) {
+ derive_flags_sig(cx, has_params, has_vars, args, tt);
+ }
+ ty_native_fn(_, args, tt) {
+ derive_flags_sig(cx, has_params, has_vars, args, tt);
+ }
+ ty_obj(meths) {
+ for m: method in meths {
+ derive_flags_sig(cx, has_params, has_vars, m.inputs, m.output);
}
- case (ty_fn(_, ?args, ?tt, _, _)) {
- derive_flags_sig(cx, has_params, has_vars, args, tt);
- }
- case (ty_native_fn(_, ?args, ?tt)) {
- derive_flags_sig(cx, has_params, has_vars, args, tt);
- }
- case (ty_obj(?meths)) {
- for (method m in meths) {
- derive_flags_sig(cx, has_params, has_vars, m.inputs,
- m.output);
- }
- }
- case (ty_res(_, ?tt, ?tps)) {
- derive_flags_t(cx, has_params, has_vars, tt);
- for (t tt in tps) {
- derive_flags_t(cx, has_params, has_vars, tt);
- }
- }
- case (ty_constr(?tt, _)) {
- derive_flags_t(cx, has_params, has_vars, tt);
- }
+ }
+ ty_res(_, tt, tps) {
+ derive_flags_t(cx, has_params, has_vars, tt);
+ for tt: t in tps { derive_flags_t(cx, has_params, has_vars, tt); }
+ }
+ ty_constr(tt, _) { derive_flags_t(cx, has_params, has_vars, tt); }
}
- ret @rec(struct=st,
- cname=cname,
- hash=h,
- has_params=has_params,
- has_vars=has_vars);
+ ret @{struct: st,
+ cname: cname,
+ hash: h,
+ has_params: has_params,
+ has_vars: has_vars};
}
-fn intern(&ctxt cx, &sty st, &option::t[str] cname) {
+fn intern(cx: &ctxt, st: &sty, cname: &option::t[str]) {
interner::intern(*cx.ts, mk_raw_ty(cx, st, cname));
}
-fn gen_ty_full(&ctxt cx, &sty st, &option::t[str] cname) -> t {
- auto raw_type = mk_raw_ty(cx, st, cname);
+fn gen_ty_full(cx: &ctxt, st: &sty, cname: &option::t[str]) -> t {
+ let raw_type = mk_raw_ty(cx, st, cname);
ret interner::intern(*cx.ts, raw_type);
}
// These are private constructors to this module. External users should always
// use the mk_foo() functions below.
-fn gen_ty(&ctxt cx, &sty st) -> t { ret gen_ty_full(cx, st, none); }
+fn gen_ty(cx: &ctxt, st: &sty) -> t { ret gen_ty_full(cx, st, none); }
-fn mk_nil(&ctxt cx) -> t { ret idx_nil; }
+fn mk_nil(cx: &ctxt) -> t { ret idx_nil; }
-fn mk_bot(&ctxt cx) -> t { ret idx_bot; }
+fn mk_bot(cx: &ctxt) -> t { ret idx_bot; }
-fn mk_bool(&ctxt cx) -> t { ret idx_bool; }
+fn mk_bool(cx: &ctxt) -> t { ret idx_bool; }
-fn mk_int(&ctxt cx) -> t { ret idx_int; }
+fn mk_int(cx: &ctxt) -> t { ret idx_int; }
-fn mk_float(&ctxt cx) -> t { ret idx_float; }
+fn mk_float(cx: &ctxt) -> t { ret idx_float; }
-fn mk_uint(&ctxt cx) -> t { ret idx_uint; }
+fn mk_uint(cx: &ctxt) -> t { ret idx_uint; }
-fn mk_mach(&ctxt cx, &ast::ty_mach tm) -> t {
- alt (tm) {
- case (ast::ty_u8) { ret idx_u8; }
- case (ast::ty_u16) { ret idx_u16; }
- case (ast::ty_u32) { ret idx_u32; }
- case (ast::ty_u64) { ret idx_u64; }
- case (ast::ty_i8) { ret idx_i8; }
- case (ast::ty_i16) { ret idx_i16; }
- case (ast::ty_i32) { ret idx_i32; }
- case (ast::ty_i64) { ret idx_i64; }
- case (ast::ty_f32) { ret idx_f32; }
- case (ast::ty_f64) { ret idx_f64; }
+fn mk_mach(cx: &ctxt, tm: &ast::ty_mach) -> t {
+ alt tm {
+ ast::ty_u8. { ret idx_u8; }
+ ast::ty_u16. { ret idx_u16; }
+ ast::ty_u32. { ret idx_u32; }
+ ast::ty_u64. { ret idx_u64; }
+ ast::ty_i8. { ret idx_i8; }
+ ast::ty_i16. { ret idx_i16; }
+ ast::ty_i32. { ret idx_i32; }
+ ast::ty_i64. { ret idx_i64; }
+ ast::ty_f32. { ret idx_f32; }
+ ast::ty_f64. { ret idx_f64; }
}
}
-fn mk_char(&ctxt cx) -> t { ret idx_char; }
+fn mk_char(cx: &ctxt) -> t { ret idx_char; }
-fn mk_str(&ctxt cx) -> t { ret idx_str; }
+fn mk_str(cx: &ctxt) -> t { ret idx_str; }
-fn mk_istr(&ctxt cx) -> t { ret idx_istr; }
+fn mk_istr(cx: &ctxt) -> t { ret idx_istr; }
-fn mk_tag(&ctxt cx, &ast::def_id did, &t[] tys) -> t {
+fn mk_tag(cx: &ctxt, did: &ast::def_id, tys: &t[]) -> t {
ret gen_ty(cx, ty_tag(did, tys));
}
-fn mk_box(&ctxt cx, &mt tm) -> t { ret gen_ty(cx, ty_box(tm)); }
+fn mk_box(cx: &ctxt, tm: &mt) -> t { ret gen_ty(cx, ty_box(tm)); }
-fn mk_ptr(&ctxt cx, &mt tm) -> t { ret gen_ty(cx, ty_ptr(tm)); }
+fn mk_ptr(cx: &ctxt, tm: &mt) -> t { ret gen_ty(cx, ty_ptr(tm)); }
-fn mk_imm_box(&ctxt cx, &t ty) -> t {
- ret mk_box(cx, rec(ty=ty, mut=ast::imm));
+fn mk_imm_box(cx: &ctxt, ty: &t) -> t {
+ ret mk_box(cx, {ty: ty, mut: ast::imm});
}
-fn mk_vec(&ctxt cx, &mt tm) -> t { ret gen_ty(cx, ty_vec(tm)); }
+fn mk_vec(cx: &ctxt, tm: &mt) -> t { ret gen_ty(cx, ty_vec(tm)); }
-fn mk_ivec(&ctxt cx, &mt tm) -> t { ret gen_ty(cx, ty_ivec(tm)); }
+fn mk_ivec(cx: &ctxt, tm: &mt) -> t { ret gen_ty(cx, ty_ivec(tm)); }
-fn mk_imm_vec(&ctxt cx, &t typ) -> t {
- ret gen_ty(cx, ty_vec(rec(ty=typ, mut=ast::imm)));
+fn mk_imm_vec(cx: &ctxt, typ: &t) -> t {
+ ret gen_ty(cx, ty_vec({ty: typ, mut: ast::imm}));
}
-fn mk_port(&ctxt cx, &t ty) -> t { ret gen_ty(cx, ty_port(ty)); }
+fn mk_port(cx: &ctxt, ty: &t) -> t { ret gen_ty(cx, ty_port(ty)); }
-fn mk_chan(&ctxt cx, &t ty) -> t { ret gen_ty(cx, ty_chan(ty)); }
+fn mk_chan(cx: &ctxt, ty: &t) -> t { ret gen_ty(cx, ty_chan(ty)); }
-fn mk_task(&ctxt cx) -> t { ret gen_ty(cx, ty_task); }
+fn mk_task(cx: &ctxt) -> t { ret gen_ty(cx, ty_task); }
-fn mk_rec(&ctxt cx, &field[] fs) -> t { ret gen_ty(cx, ty_rec(fs)); }
+fn mk_rec(cx: &ctxt, fs: &field[]) -> t { ret gen_ty(cx, ty_rec(fs)); }
-fn mk_imm_tup(&ctxt cx, &t[] tys) -> t {
- auto fields = ~[];
- auto i = 0u;
- for (t typ in tys) {
- fields += ~[rec(ident=#fmt("_%u", i),
- mt=rec(ty=typ, mut=ast::imm))];
+fn mk_imm_tup(cx: &ctxt, tys: &t[]) -> t {
+ let fields = ~[];
+ let i = 0u;
+ for typ: t in tys {
+ fields += ~[{ident: #fmt("_%u", i), mt: {ty: typ, mut: ast::imm}}];
i += 1u;
}
ret gen_ty(cx, ty_rec(fields));
}
-fn mk_constr(&ctxt cx, &t t, &(@type_constr)[] cs) -> t {
+fn mk_constr(cx: &ctxt, t: &t, cs: &(@type_constr)[]) -> t {
ret gen_ty(cx, ty_constr(t, cs));
}
-fn mk_fn(&ctxt cx, &ast::proto proto, &arg[] args, &t ty, &controlflow cf,
- &(@constr)[] constrs) -> t {
+fn mk_fn(cx: &ctxt, proto: &ast::proto, args: &arg[], ty: &t,
+ cf: &controlflow, constrs: &(@constr)[]) -> t {
ret gen_ty(cx, ty_fn(proto, args, ty, cf, constrs));
}
-fn mk_native_fn(&ctxt cx, &ast::native_abi abi, &arg[] args, &t ty) -> t {
+fn mk_native_fn(cx: &ctxt, abi: &ast::native_abi, args: &arg[], ty: &t) -> t {
ret gen_ty(cx, ty_native_fn(abi, args, ty));
}
-fn mk_obj(&ctxt cx, &method[] meths) -> t {
- ret gen_ty(cx, ty_obj(meths));
-}
+fn mk_obj(cx: &ctxt, meths: &method[]) -> t { ret gen_ty(cx, ty_obj(meths)); }
-fn mk_res(&ctxt cx, &ast::def_id did, &t inner, &t[] tps) -> t {
+fn mk_res(cx: &ctxt, did: &ast::def_id, inner: &t, tps: &t[]) -> t {
ret gen_ty(cx, ty_res(did, inner, tps));
}
-fn mk_var(&ctxt cx, int v) -> t { ret gen_ty(cx, ty_var(v)); }
+fn mk_var(cx: &ctxt, v: int) -> t { ret gen_ty(cx, ty_var(v)); }
-fn mk_param(&ctxt cx, uint n) -> t { ret gen_ty(cx, ty_param(n)); }
+fn mk_param(cx: &ctxt, n: uint) -> t { ret gen_ty(cx, ty_param(n)); }
-fn mk_type(&ctxt cx) -> t { ret idx_type; }
+fn mk_type(cx: &ctxt) -> t { ret idx_type; }
-fn mk_native(&ctxt cx, &def_id did) -> t { ret gen_ty(cx, ty_native(did)); }
+fn mk_native(cx: &ctxt, did: &def_id) -> t { ret gen_ty(cx, ty_native(did)); }
// Returns the one-level-deep type structure of the given type.
-fn struct(&ctxt cx, &t typ) -> sty {
+fn struct(cx: &ctxt, typ: &t) -> sty {
ret interner::get(*cx.ts, typ).struct;
}
// Returns the canonical name of the given type.
-fn cname(&ctxt cx, &t typ) -> option::t[str] {
+fn cname(cx: &ctxt, typ: &t) -> option::t[str] {
ret interner::get(*cx.ts, typ).cname;
}
@@ -632,52 +623,52 @@
// Type folds
type ty_walk = fn(t) ;
-fn walk_ty(&ctxt cx, ty_walk walker, t ty) {
- alt (struct(cx, ty)) {
- case (ty_nil) {/* no-op */ }
- case (ty_bot) {/* no-op */ }
- case (ty_bool) {/* no-op */ }
- case (ty_int) {/* no-op */ }
- case (ty_uint) {/* no-op */ }
- case (ty_float) {/* no-op */ }
- case (ty_machine(_)) {/* no-op */ }
- case (ty_char) {/* no-op */ }
- case (ty_str) {/* no-op */ }
- case (ty_istr) {/* no-op */ }
- case (ty_type) {/* no-op */ }
- case (ty_native(_)) {/* no-op */ }
- case (ty_box(?tm)) { walk_ty(cx, walker, tm.ty); }
- case (ty_vec(?tm)) { walk_ty(cx, walker, tm.ty); }
- case (ty_ivec(?tm)) { walk_ty(cx, walker, tm.ty); }
- case (ty_ptr(?tm)) { walk_ty(cx, walker, tm.ty); }
- case (ty_port(?subty)) { walk_ty(cx, walker, subty); }
- case (ty_chan(?subty)) { walk_ty(cx, walker, subty); }
- case (ty_tag(?tid, ?subtys)) {
- for (t subty in subtys) { walk_ty(cx, walker, subty); }
+fn walk_ty(cx: &ctxt, walker: ty_walk, ty: t) {
+ alt struct(cx, ty) {
+ ty_nil. {/* no-op */ }
+ ty_bot. {/* no-op */ }
+ ty_bool. {/* no-op */ }
+ ty_int. {/* no-op */ }
+ ty_uint. {/* no-op */ }
+ ty_float. {/* no-op */ }
+ ty_machine(_) {/* no-op */ }
+ ty_char. {/* no-op */ }
+ ty_str. {/* no-op */ }
+ ty_istr. {/* no-op */ }
+ ty_type. {/* no-op */ }
+ ty_native(_) {/* no-op */ }
+ ty_box(tm) { walk_ty(cx, walker, tm.ty); }
+ ty_vec(tm) { walk_ty(cx, walker, tm.ty); }
+ ty_ivec(tm) { walk_ty(cx, walker, tm.ty); }
+ ty_ptr(tm) { walk_ty(cx, walker, tm.ty); }
+ ty_port(subty) { walk_ty(cx, walker, subty); }
+ ty_chan(subty) { walk_ty(cx, walker, subty); }
+ ty_tag(tid, subtys) {
+ for subty: t in subtys { walk_ty(cx, walker, subty); }
+ }
+ ty_rec(fields) {
+ for fl: field in fields { walk_ty(cx, walker, fl.mt.ty); }
+ }
+ ty_fn(proto, args, ret_ty, _, _) {
+ for a: arg in args { walk_ty(cx, walker, a.ty); }
+ walk_ty(cx, walker, ret_ty);
+ }
+ ty_native_fn(abi, args, ret_ty) {
+ for a: arg in args { walk_ty(cx, walker, a.ty); }
+ walk_ty(cx, walker, ret_ty);
+ }
+ ty_obj(methods) {
+ for m: method in methods {
+ for a: arg in m.inputs { walk_ty(cx, walker, a.ty); }
+ walk_ty(cx, walker, m.output);
}
- case (ty_rec(?fields)) {
- for (field fl in fields) { walk_ty(cx, walker, fl.mt.ty); }
- }
- case (ty_fn(?proto, ?args, ?ret_ty, _, _)) {
- for (arg a in args) { walk_ty(cx, walker, a.ty); }
- walk_ty(cx, walker, ret_ty);
- }
- case (ty_native_fn(?abi, ?args, ?ret_ty)) {
- for (arg a in args) { walk_ty(cx, walker, a.ty); }
- walk_ty(cx, walker, ret_ty);
- }
- case (ty_obj(?methods)) {
- for (method m in methods) {
- for (arg a in m.inputs) { walk_ty(cx, walker, a.ty); }
- walk_ty(cx, walker, m.output);
- }
- }
- case (ty_res(_, ?sub, ?tps)) {
- walk_ty(cx, walker, sub);
- for (t tp in tps) { walk_ty(cx, walker, tp); }
- }
- case (ty_var(_)) {/* no-op */ }
- case (ty_param(_)) {/* no-op */ }
+ }
+ ty_res(_, sub, tps) {
+ walk_ty(cx, walker, sub);
+ for tp: t in tps { walk_ty(cx, walker, tp); }
+ }
+ ty_var(_) {/* no-op */ }
+ ty_param(_) {/* no-op */ }
}
walker(ty);
}
@@ -688,354 +679,326 @@
fm_general(fn(t) -> t );
}
-fn fold_ty(&ctxt cx, fold_mode fld, t ty_0) -> t {
- auto ty = ty_0;
+fn fold_ty(cx: &ctxt, fld: fold_mode, ty_0: t) -> t {
+ let ty = ty_0;
// Fast paths.
- alt (fld) {
- case (fm_var(_)) { if (!type_contains_vars(cx, ty)) { ret ty; } }
- case (fm_param(_)) { if (!type_contains_params(cx, ty)) { ret ty; } }
- case (fm_general(_)) {/* no fast path */ }
+ alt fld {
+ fm_var(_) { if !type_contains_vars(cx, ty) { ret ty; } }
+ fm_param(_) { if !type_contains_params(cx, ty) { ret ty; } }
+ fm_general(_) {/* no fast path */ }
}
- alt (struct(cx, ty)) {
- case (ty_nil) {/* no-op */ }
- case (ty_bot) {/* no-op */ }
- case (ty_bool) {/* no-op */ }
- case (ty_int) {/* no-op */ }
- case (ty_uint) {/* no-op */ }
- case (ty_float) {/* no-op */ }
- case (ty_machine(_)) {/* no-op */ }
- case (ty_char) {/* no-op */ }
- case (ty_str) {/* no-op */ }
- case (ty_istr) {/* no-op */ }
- case (ty_type) {/* no-op */ }
- case (ty_native(_)) {/* no-op */ }
- case (ty_task) {/* no-op */ }
- case (ty_box(?tm)) {
- ty =
- copy_cname(cx,
- mk_box(cx,
- rec(ty=fold_ty(cx, fld, tm.ty),
- mut=tm.mut)), ty);
+ alt struct(cx, ty) {
+ ty_nil. {/* no-op */ }
+ ty_bot. {/* no-op */ }
+ ty_bool. {/* no-op */ }
+ ty_int. {/* no-op */ }
+ ty_uint. {/* no-op */ }
+ ty_float. {/* no-op */ }
+ ty_machine(_) {/* no-op */ }
+ ty_char. {/* no-op */ }
+ ty_str. {/* no-op */ }
+ ty_istr. {/* no-op */ }
+ ty_type. {/* no-op */ }
+ ty_native(_) {/* no-op */ }
+ ty_task. {/* no-op */ }
+ ty_box(tm) {
+ ty =
+ copy_cname(cx,
+ mk_box(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut}),
+ ty);
+ }
+ ty_ptr(tm) {
+ ty =
+ copy_cname(cx,
+ mk_ptr(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut}),
+ ty);
+ }
+ ty_vec(tm) {
+ ty =
+ copy_cname(cx,
+ mk_vec(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut}),
+ ty);
+ }
+ ty_ivec(tm) {
+ ty =
+ copy_cname(cx,
+ mk_ivec(cx,
+ {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut}),
+ ty);
+ }
+ ty_port(subty) {
+ ty = copy_cname(cx, mk_port(cx, fold_ty(cx, fld, subty)), ty);
+ }
+ ty_chan(subty) {
+ ty = copy_cname(cx, mk_chan(cx, fold_ty(cx, fld, subty)), ty);
+ }
+ ty_tag(tid, subtys) {
+ let new_subtys: t[] = ~[];
+ for subty: t in subtys { new_subtys += ~[fold_ty(cx, fld, subty)]; }
+ ty = copy_cname(cx, mk_tag(cx, tid, new_subtys), ty);
+ }
+ ty_rec(fields) {
+ let new_fields: field[] = ~[];
+ for fl: field in fields {
+ let new_ty = fold_ty(cx, fld, fl.mt.ty);
+ let new_mt = {ty: new_ty, mut: fl.mt.mut};
+ new_fields += ~[{ident: fl.ident, mt: new_mt}];
}
- case (ty_ptr(?tm)) {
- ty =
- copy_cname(cx,
- mk_ptr(cx,
- rec(ty=fold_ty(cx, fld, tm.ty),
- mut=tm.mut)), ty);
+ ty = copy_cname(cx, mk_rec(cx, new_fields), ty);
+ }
+ ty_fn(proto, args, ret_ty, cf, constrs) {
+ let new_args: arg[] = ~[];
+ for a: arg in args {
+ let new_ty = fold_ty(cx, fld, a.ty);
+ new_args += ~[{mode: a.mode, ty: new_ty}];
}
- case (ty_vec(?tm)) {
- ty =
- copy_cname(cx,
- mk_vec(cx,
- rec(ty=fold_ty(cx, fld, tm.ty),
- mut=tm.mut)), ty);
+ ty =
+ copy_cname(cx,
+ mk_fn(cx, proto, new_args, fold_ty(cx, fld, ret_ty),
+ cf, constrs), ty);
+ }
+ ty_native_fn(abi, args, ret_ty) {
+ let new_args: arg[] = ~[];
+ for a: arg in args {
+ let new_ty = fold_ty(cx, fld, a.ty);
+ new_args += ~[{mode: a.mode, ty: new_ty}];
}
- case (ty_ivec(?tm)) {
- ty =
- copy_cname(cx,
- mk_ivec(cx,
- rec(ty=fold_ty(cx, fld, tm.ty),
- mut=tm.mut)), ty);
- }
- case (ty_port(?subty)) {
- ty = copy_cname(cx, mk_port(cx, fold_ty(cx, fld, subty)), ty);
- }
- case (ty_chan(?subty)) {
- ty = copy_cname(cx, mk_chan(cx, fold_ty(cx, fld, subty)), ty);
- }
- case (ty_tag(?tid, ?subtys)) {
- let t[] new_subtys = ~[];
- for (t subty in subtys) {
- new_subtys += ~[fold_ty(cx, fld, subty)];
+ ty =
+ copy_cname(cx,
+ mk_native_fn(cx, abi, new_args,
+ fold_ty(cx, fld, ret_ty)), ty);
+ }
+ ty_obj(methods) {
+ let new_methods: method[] = ~[];
+ for m: method in methods {
+ let new_args: arg[] = ~[];
+ for a: arg in m.inputs {
+ new_args += ~[{mode: a.mode, ty: fold_ty(cx, fld, a.ty)}];
}
- ty = copy_cname(cx, mk_tag(cx, tid, new_subtys), ty);
+ new_methods +=
+ ~[{proto: m.proto,
+ ident: m.ident,
+ inputs: new_args,
+ output: fold_ty(cx, fld, m.output),
+ cf: m.cf,
+ constrs: m.constrs}];
}
- case (ty_rec(?fields)) {
- let field[] new_fields = ~[];
- for (field fl in fields) {
- auto new_ty = fold_ty(cx, fld, fl.mt.ty);
- auto new_mt = rec(ty=new_ty, mut=fl.mt.mut);
- new_fields += ~[rec(ident=fl.ident, mt=new_mt)];
- }
- ty = copy_cname(cx, mk_rec(cx, new_fields), ty);
- }
- case (ty_fn(?proto, ?args, ?ret_ty, ?cf, ?constrs)) {
- let arg[] new_args = ~[];
- for (arg a in args) {
- auto new_ty = fold_ty(cx, fld, a.ty);
- new_args += ~[rec(mode=a.mode, ty=new_ty)];
- }
- ty =
- copy_cname(cx,
- mk_fn(cx, proto, new_args,
- fold_ty(cx, fld, ret_ty), cf, constrs), ty);
- }
- case (ty_native_fn(?abi, ?args, ?ret_ty)) {
- let arg[] new_args = ~[];
- for (arg a in args) {
- auto new_ty = fold_ty(cx, fld, a.ty);
- new_args += ~[rec(mode=a.mode, ty=new_ty)];
- }
- ty =
- copy_cname(cx,
- mk_native_fn(cx, abi, new_args,
- fold_ty(cx, fld, ret_ty)), ty);
- }
- case (ty_obj(?methods)) {
- let method[] new_methods = ~[];
- for (method m in methods) {
- let arg[] new_args = ~[];
- for (arg a in m.inputs) {
- new_args += ~[rec(mode=a.mode,
- ty=fold_ty(cx, fld, a.ty))];
- }
- new_methods +=
- ~[rec(proto=m.proto,
- ident=m.ident,
- inputs=new_args,
- output=fold_ty(cx, fld, m.output),
- cf=m.cf,
- constrs=m.constrs)];
- }
- ty = copy_cname(cx, mk_obj(cx, new_methods), ty);
- }
- case (ty_res(?did, ?subty, ?tps)) {
- auto new_tps = ~[];
- for (t tp in tps) { new_tps += ~[fold_ty(cx, fld, tp)]; }
- ty = copy_cname(cx, mk_res(cx, did, fold_ty(cx, fld, subty),
- new_tps), ty);
- }
- case (ty_var(?id)) {
- alt (fld) {
- case (fm_var(?folder)) { ty = folder(id); }
- case (_) {/* no-op */ }
- }
- }
- case (ty_param(?id)) {
- alt (fld) {
- case (fm_param(?folder)) { ty = folder(id); }
- case (_) {/* no-op */ }
- }
- }
+ ty = copy_cname(cx, mk_obj(cx, new_methods), ty);
+ }
+ ty_res(did, subty, tps) {
+ let new_tps = ~[];
+ for tp: t in tps { new_tps += ~[fold_ty(cx, fld, tp)]; }
+ ty =
+ copy_cname(cx, mk_res(cx, did, fold_ty(cx, fld, subty), new_tps),
+ ty);
+ }
+ ty_var(id) {
+ alt fld { fm_var(folder) { ty = folder(id); } _ {/* no-op */ } }
+ }
+ ty_param(id) {
+ alt fld { fm_param(folder) { ty = folder(id); } _ {/* no-op */ } }
+ }
}
+
// If this is a general type fold, then we need to run it now.
- alt (fld) {
- case (fm_general(?folder)) { ret folder(ty); }
- case (_) { ret ty; }
- }
+ alt fld { fm_general(folder) { ret folder(ty); } _ { ret ty; } }
}
// Type utilities
-fn rename(&ctxt cx, t typ, str new_cname) -> t {
+fn rename(cx: &ctxt, typ: t, new_cname: str) -> t {
ret gen_ty_full(cx, struct(cx, typ), some(new_cname));
}
-fn strip_cname(&ctxt cx, t typ) -> t {
+fn strip_cname(cx: &ctxt, typ: t) -> t {
ret gen_ty_full(cx, struct(cx, typ), none);
}
// Returns a type with the structural part taken from `struct_ty` and the
// canonical name from `cname_ty`.
-fn copy_cname(&ctxt cx, t struct_ty, t cname_ty) -> t {
+fn copy_cname(cx: &ctxt, struct_ty: t, cname_ty: t) -> t {
ret gen_ty_full(cx, struct(cx, struct_ty), cname(cx, cname_ty));
}
-fn type_is_nil(&ctxt cx, &t ty) -> bool {
- alt (struct(cx, ty)) {
- case (ty_nil) { ret true; }
- case (_) { ret false; }
+fn type_is_nil(cx: &ctxt, ty: &t) -> bool {
+ alt struct(cx, ty) { ty_nil. { ret true; } _ { ret false; } }
+}
+
+fn type_is_bot(cx: &ctxt, ty: &t) -> bool {
+ alt struct(cx, ty) { ty_bot. { ret true; } _ { ret false; } }
+}
+
+fn type_is_bool(cx: &ctxt, ty: &t) -> bool {
+ alt struct(cx, ty) { ty_bool. { ret true; } _ { ret false; } }
+}
+
+fn type_is_chan(cx: &ctxt, ty: &t) -> bool {
+ alt struct(cx, ty) { ty_chan(_) { ret true; } _ { ret false; } }
+}
+
+fn type_is_structural(cx: &ctxt, ty: &t) -> bool {
+ alt struct(cx, ty) {
+ ty_rec(_) { ret true; }
+ ty_tag(_, _) { ret true; }
+ ty_fn(_, _, _, _, _) { ret true; }
+ ty_obj(_) { ret true; }
+ ty_res(_, _, _) { ret true; }
+ ty_ivec(_) { ret true; }
+ ty_istr. { ret true; }
+ _ { ret false; }
}
}
-fn type_is_bot(&ctxt cx, &t ty) -> bool {
- alt (struct(cx, ty)) {
- case (ty_bot) { ret true; }
- case (_) { ret false; }
+fn type_is_copyable(cx: &ctxt, ty: &t) -> bool {
+ ret alt struct(cx, ty) {
+ ty_res(_, _, _) { false }
+ ty_fn(proto_block., _, _, _, _) { false }
+ _ { true }
+ };
+}
+
+fn type_is_sequence(cx: &ctxt, ty: &t) -> bool {
+ alt struct(cx, ty) {
+ ty_str. { ret true; }
+ ty_istr. { ret true; }
+ ty_vec(_) { ret true; }
+ ty_ivec(_) { ret true; }
+ _ { ret false; }
}
}
-fn type_is_bool(&ctxt cx, &t ty) -> bool {
- alt (struct(cx, ty)) {
- case (ty_bool) { ret true; }
- case (_) { ret false; }
+fn type_is_str(cx: &ctxt, ty: &t) -> bool {
+ alt struct(cx, ty) {
+ ty_str. { ret true; }
+ ty_istr. { ret true; }
+ _ { ret false; }
}
}
-fn type_is_chan(&ctxt cx, &t ty) -> bool {
- alt (struct(cx, ty)) {
- case (ty_chan(_)) { ret true; }
- case (_) { ret false; }
+fn sequence_is_interior(cx: &ctxt, ty: &t) -> bool {
+ alt struct(cx, ty) {
+
+ // TODO: Or-patterns
+ ty::ty_vec(_) {
+ ret false;
+ }
+ ty::ty_str. { ret false; }
+ ty::ty_ivec(_) { ret true; }
+ ty::ty_istr. { ret true; }
+ _ { cx.sess.bug("sequence_is_interior called on non-sequence type"); }
}
}
-fn type_is_structural(&ctxt cx, &t ty) -> bool {
- alt (struct(cx, ty)) {
- case (ty_rec(_)) { ret true; }
- case (ty_tag(_, _)) { ret true; }
- case (ty_fn(_, _, _, _, _)) { ret true; }
- case (ty_obj(_)) { ret true; }
- case (ty_res(_, _, _)) { ret true; }
- case (ty_ivec(_)) { ret true; }
- case (ty_istr) { ret true; }
- case (_) { ret false; }
+fn sequence_element_type(cx: &ctxt, ty: &t) -> t {
+ alt struct(cx, ty) {
+ ty_str. { ret mk_mach(cx, ast::ty_u8); }
+ ty_istr. { ret mk_mach(cx, ast::ty_u8); }
+ ty_vec(mt) { ret mt.ty; }
+ ty_ivec(mt) { ret mt.ty; }
+ _ { cx.sess.bug("sequence_element_type called on non-sequence value"); }
}
}
-fn type_is_copyable(&ctxt cx, &t ty) -> bool {
- ret alt (struct(cx, ty)) {
- case (ty_res(_, _, _)) { false }
- case (ty_fn(proto_block, _, _, _, _)) { false }
- case (_) { true }
- };
-}
-
-fn type_is_sequence(&ctxt cx, &t ty) -> bool {
- alt (struct(cx, ty)) {
- case (ty_str) { ret true; }
- case (ty_istr) { ret true; }
- case (ty_vec(_)) { ret true; }
- case (ty_ivec(_)) { ret true; }
- case (_) { ret false; }
+fn type_is_tup_like(cx: &ctxt, ty: &t) -> bool {
+ alt struct(cx, ty) {
+ ty_box(_) { ret true; }
+ ty_rec(_) { ret true; }
+ ty_tag(_, _) { ret true; }
+ _ { ret false; }
}
}
-fn type_is_str(&ctxt cx, &t ty) -> bool {
- alt (struct(cx, ty)) {
- case (ty_str) { ret true; }
- case (ty_istr) { ret true; }
- case (_) { ret false; }
- }
-}
-
-fn sequence_is_interior(&ctxt cx, &t ty) -> bool {
- alt (struct(cx, ty)) {
- case (
- // TODO: Or-patterns
- ty::ty_vec(_)) {
- ret false;
- }
- case (ty::ty_str) { ret false; }
- case (ty::ty_ivec(_)) { ret true; }
- case (ty::ty_istr) { ret true; }
- case (_) {
- cx.sess.bug("sequence_is_interior called on non-sequence type");
- }
- }
-}
-
-fn sequence_element_type(&ctxt cx, &t ty) -> t {
- alt (struct(cx, ty)) {
- case (ty_str) { ret mk_mach(cx, ast::ty_u8); }
- case (ty_istr) { ret mk_mach(cx, ast::ty_u8); }
- case (ty_vec(?mt)) { ret mt.ty; }
- case (ty_ivec(?mt)) { ret mt.ty; }
- case (_) {
- cx.sess.bug("sequence_element_type called on non-sequence value");
- }
- }
-}
-
-fn type_is_tup_like(&ctxt cx, &t ty) -> bool {
- alt (struct(cx, ty)) {
- case (ty_box(_)) { ret true; }
- case (ty_rec(_)) { ret true; }
- case (ty_tag(_, _)) { ret true; }
- case (_) { ret false; }
- }
-}
-
-fn get_element_type(&ctxt cx, &t ty, uint i) -> t {
- alt (struct(cx, ty)) {
- case (ty_rec(?flds)) { ret flds.(i).mt.ty; }
- case (_) {
- cx.sess.bug("get_element_type called on type "
- + ty_to_str(cx, ty) + " - expected a \
+fn get_element_type(cx: &ctxt, ty: &t, i: uint) -> t {
+ alt struct(cx, ty) {
+ ty_rec(flds) { ret flds.(i).mt.ty; }
+ _ {
+ cx.sess.bug("get_element_type called on type " + ty_to_str(cx, ty) +
+ " - expected a \
tuple or record");
- }
+ }
}
// NB: This is not exhaustive -- struct(cx, ty) could be a box or a
// tag.
}
-fn type_is_box(&ctxt cx, &t ty) -> bool {
- alt (struct(cx, ty)) {
- case (ty_box(_)) { ret true; }
- case (_) { ret false; }
+fn type_is_box(cx: &ctxt, ty: &t) -> bool {
+ alt struct(cx, ty) { ty_box(_) { ret true; } _ { ret false; } }
+}
+
+fn type_is_boxed(cx: &ctxt, ty: &t) -> bool {
+ alt struct(cx, ty) {
+ ty_str. { ret true; }
+ ty_vec(_) { ret true; }
+ ty_box(_) { ret true; }
+ ty_port(_) { ret true; }
+ ty_chan(_) { ret true; }
+ ty_task. { ret true; }
+ _ { ret false; }
}
}
-fn type_is_boxed(&ctxt cx, &t ty) -> bool {
- alt (struct(cx, ty)) {
- case (ty_str) { ret true; }
- case (ty_vec(_)) { ret true; }
- case (ty_box(_)) { ret true; }
- case (ty_port(_)) { ret true; }
- case (ty_chan(_)) { ret true; }
- case (ty_task) { ret true; }
- case (_) { ret false; }
+fn type_is_scalar(cx: &ctxt, ty: &t) -> bool {
+ alt struct(cx, ty) {
+ ty_nil. { ret true; }
+ ty_bool. { ret true; }
+ ty_int. { ret true; }
+ ty_float. { ret true; }
+ ty_uint. { ret true; }
+ ty_machine(_) { ret true; }
+ ty_char. { ret true; }
+ ty_type. { ret true; }
+ ty_native(_) { ret true; }
+ ty_ptr(_) { ret true; }
+ _ { ret false; }
}
}
-fn type_is_scalar(&ctxt cx, &t ty) -> bool {
- alt (struct(cx, ty)) {
- case (ty_nil) { ret true; }
- case (ty_bool) { ret true; }
- case (ty_int) { ret true; }
- case (ty_float) { ret true; }
- case (ty_uint) { ret true; }
- case (ty_machine(_)) { ret true; }
- case (ty_char) { ret true; }
- case (ty_type) { ret true; }
- case (ty_native(_)) { ret true; }
- case (ty_ptr(_)) { ret true; }
- case (_) { ret false; }
- }
-}
-
-fn type_has_pointers(&ctxt cx, &t ty) -> bool {
- alt (cx.has_pointer_cache.find(ty)) {
- case (some(?result)) { ret result; }
- case (none) { /* fall through */ }
+fn type_has_pointers(cx: &ctxt, ty: &t) -> bool {
+ alt cx.has_pointer_cache.find(ty) {
+ some(result) { ret result; }
+ none. {/* fall through */ }
}
- auto result = false;
- alt (struct(cx, ty)) {
- // scalar types
- case (ty_nil) { /* no-op */ }
- case (ty_bot) { /* no-op */ }
- case (ty_bool) { /* no-op */ }
- case (ty_int) { /* no-op */ }
- case (ty_float) { /* no-op */ }
- case (ty_uint) { /* no-op */ }
- case (ty_machine(_)) { /* no-op */ }
- case (ty_char) { /* no-op */ }
- case (ty_type) { /* no-op */ }
- case (ty_native(_)) { /* no-op */ }
- case (ty_rec(?flds)) {
- for (field f in flds) {
- if (type_has_pointers(cx, f.mt.ty)) { result = true; }
+ let result = false;
+ alt struct(cx, ty) {
+
+ // scalar types
+ ty_nil. {
+ /* no-op */
+
+ }
+ ty_bot. {/* no-op */ }
+ ty_bool. {/* no-op */ }
+ ty_int. {/* no-op */ }
+ ty_float. {/* no-op */ }
+ ty_uint. {/* no-op */ }
+ ty_machine(_) {/* no-op */ }
+ ty_char. {/* no-op */ }
+ ty_type. {/* no-op */ }
+ ty_native(_) {/* no-op */ }
+ ty_rec(flds) {
+ for f: field in flds {
+ if type_has_pointers(cx, f.mt.ty) { result = true; }
+ }
+ }
+ ty_tag(did, tps) {
+ let variants = tag_variants(cx, did);
+ for variant: variant_info in variants {
+ for aty: t in variant.args {
+ // Perform any type parameter substitutions.
+ let arg_ty = substitute_type_params(cx, tps, aty);
+ if type_has_pointers(cx, arg_ty) { result = true; }
}
}
- case (ty_tag(?did, ?tps)) {
- auto variants = tag_variants(cx, did);
- for (variant_info variant in variants) {
- for (t aty in variant.args) {
- // Perform any type parameter substitutions.
- auto arg_ty = substitute_type_params(cx, tps, aty);
- if (type_has_pointers(cx, arg_ty)) { result = true; }
- }
- }
- }
- case (ty_res(?did, ?inner, ?tps)) {
- result = type_has_pointers(cx,
- substitute_type_params(cx, tps, inner));
- }
- case (_) { result = true; }
+ }
+ ty_res(did, inner, tps) {
+ result =
+ type_has_pointers(cx, substitute_type_params(cx, tps, inner));
+ }
+ _ { result = true; }
}
cx.has_pointer_cache.insert(ty, result);
@@ -1045,206 +1008,211 @@
// FIXME: should we just return true for native types in
// type_is_scalar?
-fn type_is_native(&ctxt cx, &t ty) -> bool {
- alt (struct(cx, ty)) {
- case (ty_native(_)) { ret true; }
- case (_) { ret false; }
+fn type_is_native(cx: &ctxt, ty: &t) -> bool {
+ alt struct(cx, ty) { ty_native(_) { ret true; } _ { ret false; } }
+}
+
+fn type_has_dynamic_size(cx: &ctxt, ty: &t) -> bool {
+ alt struct(cx, ty) {
+ ty_nil. { ret false; }
+ ty_bot. { ret false; }
+ ty_bool. { ret false; }
+ ty_int. { ret false; }
+ ty_float. { ret false; }
+ ty_uint. { ret false; }
+ ty_machine(_) { ret false; }
+ ty_char. { ret false; }
+ ty_str. { ret false; }
+ ty_istr. { ret false; }
+ ty_tag(_, subtys) {
+ let i = 0u;
+ while i < ivec::len[t](subtys) {
+ if type_has_dynamic_size(cx, subtys.(i)) { ret true; }
+ i += 1u;
+ }
+ ret false;
+ }
+ ty_box(_) { ret false; }
+ ty_vec(_) { ret false; }
+ ty_ivec(mt) { ret type_has_dynamic_size(cx, mt.ty); }
+ ty_ptr(_) { ret false; }
+ ty_port(_) { ret false; }
+ ty_chan(_) { ret false; }
+ ty_task. { ret false; }
+ ty_rec(fields) {
+ let i = 0u;
+ while i < ivec::len[field](fields) {
+ if type_has_dynamic_size(cx, fields.(i).mt.ty) { ret true; }
+ i += 1u;
+ }
+ ret false;
+ }
+ ty_fn(_, _, _, _, _) { ret false; }
+ ty_native_fn(_, _, _) { ret false; }
+ ty_obj(_) { ret false; }
+ ty_res(_, sub, tps) {
+ for tp: t in tps { if type_has_dynamic_size(cx, tp) { ret true; } }
+ ret type_has_dynamic_size(cx, sub);
+ }
+ ty_var(_) { fail "ty_var in type_has_dynamic_size()"; }
+ ty_param(_) { ret true; }
+ ty_type. { ret false; }
+ ty_native(_) { ret false; }
}
}
-fn type_has_dynamic_size(&ctxt cx, &t ty) -> bool {
- alt (struct(cx, ty)) {
- case (ty_nil) { ret false; }
- case (ty_bot) { ret false; }
- case (ty_bool) { ret false; }
- case (ty_int) { ret false; }
- case (ty_float) { ret false; }
- case (ty_uint) { ret false; }
- case (ty_machine(_)) { ret false; }
- case (ty_char) { ret false; }
- case (ty_str) { ret false; }
- case (ty_istr) { ret false; }
- case (ty_tag(_, ?subtys)) {
- auto i = 0u;
- while (i < ivec::len[t](subtys)) {
- if (type_has_dynamic_size(cx, subtys.(i))) { ret true; }
- i += 1u;
- }
- ret false;
+fn type_is_integral(cx: &ctxt, ty: &t) -> bool {
+ alt struct(cx, ty) {
+ ty_int. { ret true; }
+ ty_uint. { ret true; }
+ ty_machine(m) {
+ alt m {
+ ast::ty_i8. { ret true; }
+ ast::ty_i16. { ret true; }
+ ast::ty_i32. { ret true; }
+ ast::ty_i64. { ret true; }
+ ast::ty_u8. { ret true; }
+ ast::ty_u16. { ret true; }
+ ast::ty_u32. { ret true; }
+ ast::ty_u64. { ret true; }
+ _ { ret false; }
}
- case (ty_box(_)) { ret false; }
- case (ty_vec(_)) { ret false; }
- case (ty_ivec(?mt)) { ret type_has_dynamic_size(cx, mt.ty); }
- case (ty_ptr(_)) { ret false; }
- case (ty_port(_)) { ret false; }
- case (ty_chan(_)) { ret false; }
- case (ty_task) { ret false; }
- case (ty_rec(?fields)) {
- auto i = 0u;
- while (i < ivec::len[field](fields)) {
- if (type_has_dynamic_size(cx, fields.(i).mt.ty)) { ret true; }
- i += 1u;
- }
- ret false;
- }
- case (ty_fn(_,_,_,_,_)) { ret false; }
- case (ty_native_fn(_,_,_)) { ret false; }
- case (ty_obj(_)) { ret false; }
- case (ty_res(_, ?sub, ?tps)) {
- for (t tp in tps) {
- if (type_has_dynamic_size(cx, tp)) { ret true; }
- }
- ret type_has_dynamic_size(cx, sub);
- }
- case (ty_var(_)) { fail "ty_var in type_has_dynamic_size()"; }
- case (ty_param(_)) { ret true; }
- case (ty_type) { ret false; }
- case (ty_native(_)) { ret false; }
+ }
+ ty_char. { ret true; }
+ ty_bool. { ret true; }
+ _ { ret false; }
}
}
-fn type_is_integral(&ctxt cx, &t ty) -> bool {
- alt (struct(cx, ty)) {
- case (ty_int) { ret true; }
- case (ty_uint) { ret true; }
- case (ty_machine(?m)) {
- alt (m) {
- case (ast::ty_i8) { ret true; }
- case (ast::ty_i16) { ret true; }
- case (ast::ty_i32) { ret true; }
- case (ast::ty_i64) { ret true; }
- case (ast::ty_u8) { ret true; }
- case (ast::ty_u16) { ret true; }
- case (ast::ty_u32) { ret true; }
- case (ast::ty_u64) { ret true; }
- case (_) { ret false; }
- }
+fn type_is_fp(cx: &ctxt, ty: &t) -> bool {
+ alt struct(cx, ty) {
+ ty_machine(tm) {
+ alt tm {
+ ast::ty_f32. { ret true; }
+ ast::ty_f64. { ret true; }
+ _ { ret false; }
}
- case (ty_char) { ret true; }
- case (ty_bool) { ret true; }
- case (_) { ret false; }
+ }
+ ty_float. { ret true; }
+ _ { ret false; }
}
}
-fn type_is_fp(&ctxt cx, &t ty) -> bool {
- alt (struct(cx, ty)) {
- case (ty_machine(?tm)) {
- alt (tm) {
- case (ast::ty_f32) { ret true; }
- case (ast::ty_f64) { ret true; }
- case (_) { ret false; }
- }
+fn type_is_signed(cx: &ctxt, ty: &t) -> bool {
+ alt struct(cx, ty) {
+ ty_int. { ret true; }
+ ty_machine(tm) {
+ alt tm {
+ ast::ty_i8. { ret true; }
+ ast::ty_i16. { ret true; }
+ ast::ty_i32. { ret true; }
+ ast::ty_i64. { ret true; }
+ _ { ret false; }
}
- case (ty_float) { ret true; }
- case (_) { ret false; }
+ }
+ _ { ret false; }
}
}
-fn type_is_signed(&ctxt cx, &t ty) -> bool {
- alt (struct(cx, ty)) {
- case (ty_int) { ret true; }
- case (ty_machine(?tm)) {
- alt (tm) {
- case (ast::ty_i8) { ret true; }
- case (ast::ty_i16) { ret true; }
- case (ast::ty_i32) { ret true; }
- case (ast::ty_i64) { ret true; }
- case (_) { ret false; }
- }
- }
- case (_) { ret false; }
- }
-}
-
-fn type_owns_heap_mem(&ctxt cx, &t ty) -> bool {
- alt (cx.owns_heap_mem_cache.find(ty)) {
- case (some(?result)) { ret result; }
- case (none) { /* fall through */ }
+fn type_owns_heap_mem(cx: &ctxt, ty: &t) -> bool {
+ alt cx.owns_heap_mem_cache.find(ty) {
+ some(result) { ret result; }
+ none. {/* fall through */ }
}
- auto result = false;
- alt (struct(cx, ty)) {
- case (ty_ivec(_)) { result = true; }
- case (ty_istr) { result = true; }
+ let result = false;
+ alt struct(cx, ty) {
+ ty_ivec(_) { result = true; }
+ ty_istr. { result = true; }
- // scalar types
- case (ty_nil) { result = false; }
- case (ty_bot) { result = false; }
- case (ty_bool) { result = false; }
- case (ty_int) { result = false; }
- case (ty_float) { result = false; }
- case (ty_uint) { result = false; }
- case (ty_machine(_)) { result = false; }
- case (ty_char) { result = false; }
- case (ty_type) { result = false; }
- case (ty_native(_)) { result = false; }
- // boxed types
- case (ty_str) { result = false; }
- case (ty_box(_)) { result = false; }
- case (ty_vec(_)) { result = false; }
- case (ty_fn(_,_,_,_,_)) { result = false; }
- case (ty_native_fn(_,_,_)) { result = false; }
- case (ty_obj(_)) { result = false; }
+ // scalar types
+ ty_nil. {
+ result = false;
+ }
+ ty_bot. { result = false; }
+ ty_bool. { result = false; }
+ ty_int. { result = false; }
+ ty_float. { result = false; }
+ ty_uint. { result = false; }
+ ty_machine(_) { result = false; }
+ ty_char. { result = false; }
+ ty_type. { result = false; }
+ ty_native(_) { result = false; }
- // structural types
- case (ty_tag(?did, ?tps)) {
- auto variants = tag_variants(cx, did);
- for (variant_info variant in variants) {
- for (t aty in variant.args) {
- // Perform any type parameter substitutions.
- auto arg_ty = substitute_type_params(cx, tps, aty);
- if (type_owns_heap_mem(cx, arg_ty)) { result = true; }
- }
+
+ // boxed types
+ ty_str. {
+ result = false;
+ }
+ ty_box(_) { result = false; }
+ ty_vec(_) { result = false; }
+ ty_fn(_, _, _, _, _) { result = false; }
+ ty_native_fn(_, _, _) { result = false; }
+ ty_obj(_) { result = false; }
+
+
+ // structural types
+ ty_tag(did, tps) {
+ let variants = tag_variants(cx, did);
+ for variant: variant_info in variants {
+ for aty: t in variant.args {
+ // Perform any type parameter substitutions.
+ let arg_ty = substitute_type_params(cx, tps, aty);
+ if type_owns_heap_mem(cx, arg_ty) { result = true; }
}
}
- case (ty_rec(?flds)) {
- for (field f in flds) {
- if (type_owns_heap_mem(cx, f.mt.ty)) { result = true; }
- }
+ }
+ ty_rec(flds) {
+ for f: field in flds {
+ if type_owns_heap_mem(cx, f.mt.ty) { result = true; }
}
- case (ty_res(_, ?inner, ?tps)) {
- result = type_owns_heap_mem(cx,
- substitute_type_params(cx, tps, inner));
- }
+ }
+ ty_res(_, inner, tps) {
+ result =
+ type_owns_heap_mem(cx, substitute_type_params(cx, tps, inner));
+ }
- case (ty_ptr(_)) { result = false; }
- case (ty_port(_)) { result = false; }
- case (ty_chan(_)) { result = false; }
- case (ty_task) { result = false; }
- case (ty_var(_)) { fail "ty_var in type_owns_heap_mem"; }
- case (ty_param(_)) { result = false; }
+
+ ty_ptr(_) {
+ result = false;
+ }
+ ty_port(_) { result = false; }
+ ty_chan(_) { result = false; }
+ ty_task. { result = false; }
+ ty_var(_) { fail "ty_var in type_owns_heap_mem"; }
+ ty_param(_) { result = false; }
}
cx.owns_heap_mem_cache.insert(ty, result);
ret result;
}
-fn type_param(&ctxt cx, &t ty) -> option::t[uint] {
- alt (struct(cx, ty)) {
- case (ty_param(?id)) { ret some(id); }
- case (_) {/* fall through */ }
+fn type_param(cx: &ctxt, ty: &t) -> option::t[uint] {
+ alt struct(cx, ty) {
+ ty_param(id) { ret some(id); }
+ _ {/* fall through */ }
}
ret none;
}
-fn type_autoderef(&ctxt cx, &ty::t t) -> ty::t {
- let ty::t t1 = t;
- while (true) {
- alt (struct(cx, t1)) {
- case (ty::ty_box(?mt)) { t1 = mt.ty; }
- case (ty::ty_res(_, ?inner, ?tps)) {
- t1 = substitute_type_params(cx, tps, inner);
+fn type_autoderef(cx: &ctxt, t: &ty::t) -> ty::t {
+ let t1: ty::t = t;
+ while true {
+ alt struct(cx, t1) {
+ ty::ty_box(mt) { t1 = mt.ty; }
+ ty::ty_res(_, inner, tps) {
+ t1 = substitute_type_params(cx, tps, inner);
+ }
+ ty::ty_tag(did, tps) {
+ let variants = tag_variants(cx, did);
+ if ivec::len(variants) != 1u || ivec::len(variants.(0).args) != 1u
+ {
+ break;
}
- case (ty::ty_tag(?did, ?tps)) {
- auto variants = tag_variants(cx, did);
- if (ivec::len(variants) != 1u ||
- ivec::len(variants.(0).args) != 1u) {
- break;
- }
- t1 = substitute_type_params(cx, tps, variants.(0).args.(0));
- }
- case (_) { break; }
+ t1 = substitute_type_params(cx, tps, variants.(0).args.(0));
+ }
+ _ { break; }
}
}
ret t1;
@@ -1252,406 +1220,342 @@
// Type hashing. This function is private to this module (and slow); external
// users should use `hash_ty()` instead.
-fn hash_type_structure(&sty st) -> uint {
- fn hash_uint(uint id, uint n) -> uint {
- auto h = id;
+fn hash_type_structure(st: &sty) -> uint {
+ fn hash_uint(id: uint, n: uint) -> uint {
+ let h = id;
h += h << 5u + n;
ret h;
}
- fn hash_def(uint id, ast::def_id did) -> uint {
- auto h = id;
+ fn hash_def(id: uint, did: ast::def_id) -> uint {
+ let h = id;
h += h << 5u + (did.crate as uint);
h += h << 5u + (did.node as uint);
ret h;
}
- fn hash_subty(uint id, &t subty) -> uint {
- auto h = id;
+ fn hash_subty(id: uint, subty: &t) -> uint {
+ let h = id;
h += h << 5u + hash_ty(subty);
ret h;
}
- fn hash_type_constr(uint id, &@type_constr c)
- -> uint {
- auto h = id;
+ fn hash_type_constr(id: uint, c: &@type_constr) -> uint {
+ let h = id;
h += h << 5u + hash_def(h, c.node.id);
ret hash_type_constr_args(h, c.node.args);
}
- fn hash_type_constr_args(uint id, (@ty_constr_arg)[] args) -> uint {
- auto h = id;
- for (@ty_constr_arg a in args) {
- alt (a.node) {
- case (carg_base) {
- h += h << 5u;
- }
- case (carg_lit(_)) {
- // FIXME
- fail "lit args not implemented yet";
- }
- case (carg_ident(?p)) {
- // FIXME: Not sure what to do here.
- h += h << 5u;
- }
+ fn hash_type_constr_args(id: uint, args: (@ty_constr_arg)[]) -> uint {
+ let h = id;
+ for a: @ty_constr_arg in args {
+ alt a.node {
+ carg_base. { h += h << 5u; }
+ carg_lit(_) {
+ // FIXME
+ fail "lit args not implemented yet";
+ }
+ carg_ident(p) {
+ // FIXME: Not sure what to do here.
+ h += h << 5u;
+ }
}
}
ret h;
}
- fn hash_fn(uint id, &arg[] args, &t rty) -> uint {
- auto h = id;
- for (arg a in args) { h += h << 5u + hash_ty(a.ty); }
+ fn hash_fn(id: uint, args: &arg[], rty: &t) -> uint {
+ let h = id;
+ for a: arg in args { h += h << 5u + hash_ty(a.ty); }
h += h << 5u + hash_ty(rty);
ret h;
}
- alt (st) {
- case (ty_nil) { ret 0u; }
- case (ty_bool) { ret 1u; }
- case (ty_int) { ret 2u; }
- case (ty_float) { ret 3u; }
- case (ty_uint) { ret 4u; }
- case (ty_machine(?tm)) {
- alt (tm) {
- case (ast::ty_i8) { ret 5u; }
- case (ast::ty_i16) { ret 6u; }
- case (ast::ty_i32) { ret 7u; }
- case (ast::ty_i64) { ret 8u; }
- case (ast::ty_u8) { ret 9u; }
- case (ast::ty_u16) { ret 10u; }
- case (ast::ty_u32) { ret 11u; }
- case (ast::ty_u64) { ret 12u; }
- case (ast::ty_f32) { ret 13u; }
- case (ast::ty_f64) { ret 14u; }
- }
+ alt st {
+ ty_nil. { ret 0u; }
+ ty_bool. { ret 1u; }
+ ty_int. { ret 2u; }
+ ty_float. { ret 3u; }
+ ty_uint. { ret 4u; }
+ ty_machine(tm) {
+ alt tm {
+ ast::ty_i8. { ret 5u; }
+ ast::ty_i16. { ret 6u; }
+ ast::ty_i32. { ret 7u; }
+ ast::ty_i64. { ret 8u; }
+ ast::ty_u8. { ret 9u; }
+ ast::ty_u16. { ret 10u; }
+ ast::ty_u32. { ret 11u; }
+ ast::ty_u64. { ret 12u; }
+ ast::ty_f32. { ret 13u; }
+ ast::ty_f64. { ret 14u; }
}
- case (ty_char) { ret 15u; }
- case (ty_str) { ret 16u; }
- case (ty_istr) { ret 17u; }
- case (ty_tag(?did, ?tys)) {
- auto h = hash_def(18u, did);
- for (t typ in tys) { h += h << 5u + hash_ty(typ); }
- ret h;
- }
- case (ty_box(?mt)) { ret hash_subty(19u, mt.ty); }
- case (ty_vec(?mt)) { ret hash_subty(20u, mt.ty); }
- case (ty_ivec(?mt)) { ret hash_subty(21u, mt.ty); }
- case (ty_port(?typ)) { ret hash_subty(22u, typ); }
- case (ty_chan(?typ)) { ret hash_subty(23u, typ); }
- case (ty_task) { ret 24u; }
- case (ty_rec(?fields)) {
- auto h = 26u;
- for (field f in fields) { h += h << 5u + hash_ty(f.mt.ty); }
- ret h;
- }
- // ???
- case (ty_fn(_, ?args, ?rty, _, _)) {
- ret hash_fn(27u, args, rty);
- }
- case (ty_native_fn(_, ?args, ?rty)) { ret hash_fn(28u, args, rty); }
- case (ty_obj(?methods)) {
- auto h = 29u;
- for (method m in methods) { h += h << 5u + str::hash(m.ident); }
- ret h;
- }
- case (ty_var(?v)) { ret hash_uint(30u, v as uint); }
- case (ty_param(?pid)) { ret hash_uint(31u, pid); }
- case (ty_type) { ret 32u; }
- case (ty_native(?did)) { ret hash_def(33u, did); }
- case (ty_bot) { ret 34u; }
- case (ty_ptr(?mt)) { ret hash_subty(35u, mt.ty); }
- case (ty_res(?did, ?sub, ?tps)) {
- auto h = hash_subty(hash_def(18u, did), sub);
- for (t tp in tps) { h += h << 5u + hash_ty(tp); }
- ret h;
- }
- case (ty_constr(?t, ?cs)) {
- auto h = 36u;
- for (@type_constr c in cs) {
- h += h << 5u + hash_type_constr(h, c);
- }
- ret h;
- }
+ }
+ ty_char. { ret 15u; }
+ ty_str. { ret 16u; }
+ ty_istr. { ret 17u; }
+ ty_tag(did, tys) {
+ let h = hash_def(18u, did);
+ for typ: t in tys { h += h << 5u + hash_ty(typ); }
+ ret h;
+ }
+ ty_box(mt) { ret hash_subty(19u, mt.ty); }
+ ty_vec(mt) { ret hash_subty(20u, mt.ty); }
+ ty_ivec(mt) { ret hash_subty(21u, mt.ty); }
+ ty_port(typ) { ret hash_subty(22u, typ); }
+ ty_chan(typ) { ret hash_subty(23u, typ); }
+ ty_task. { ret 24u; }
+ ty_rec(fields) {
+ let h = 26u;
+ for f: field in fields { h += h << 5u + hash_ty(f.mt.ty); }
+ ret h;
+ }
+
+ // ???
+ ty_fn(_, args, rty, _, _) {
+ ret hash_fn(27u, args, rty);
+ }
+ ty_native_fn(_, args, rty) { ret hash_fn(28u, args, rty); }
+ ty_obj(methods) {
+ let h = 29u;
+ for m: method in methods { h += h << 5u + str::hash(m.ident); }
+ ret h;
+ }
+ ty_var(v) { ret hash_uint(30u, v as uint); }
+ ty_param(pid) { ret hash_uint(31u, pid); }
+ ty_type. { ret 32u; }
+ ty_native(did) { ret hash_def(33u, did); }
+ ty_bot. { ret 34u; }
+ ty_ptr(mt) { ret hash_subty(35u, mt.ty); }
+ ty_res(did, sub, tps) {
+ let h = hash_subty(hash_def(18u, did), sub);
+ for tp: t in tps { h += h << 5u + hash_ty(tp); }
+ ret h;
+ }
+ ty_constr(t, cs) {
+ let h = 36u;
+ for c: @type_constr in cs { h += h << 5u + hash_type_constr(h, c); }
+ ret h;
+ }
}
}
-fn hash_type_info(&sty st, &option::t[str] cname_opt) -> uint {
- auto h = hash_type_structure(st);
- alt (cname_opt) {
- case (none) {/* no-op */ }
- case (some(?s)) { h += h << 5u + str::hash(s); }
+fn hash_type_info(st: &sty, cname_opt: &option::t[str]) -> uint {
+ let h = hash_type_structure(st);
+ alt cname_opt {
+ none. {/* no-op */ }
+ some(s) { h += h << 5u + str::hash(s); }
}
ret h;
}
-fn hash_raw_ty(&@raw_t rt) -> uint { ret rt.hash; }
+fn hash_raw_ty(rt: &@raw_t) -> uint { ret rt.hash; }
-fn hash_ty(&t typ) -> uint { ret typ; }
+fn hash_ty(typ: &t) -> uint { ret typ; }
// Type equality. This function is private to this module (and slow); external
// users should use `eq_ty()` instead.
-fn eq_int(&uint x, &uint y) -> bool { ret x == y; }
+fn eq_int(x: &uint, y: &uint) -> bool { ret x == y; }
-fn arg_eq[T](&fn(&T, &T) -> bool eq, @sp_constr_arg[T] a,
- @sp_constr_arg[T] b) -> bool {
- alt (a.node) {
- case (ast::carg_base) {
- alt (b.node) {
- case (ast::carg_base) { ret true; }
- case (_) { ret false; }
- }
- }
- case (ast::carg_ident(?s)) {
- alt (b.node) {
- case (ast::carg_ident(?t)) { ret eq(s, t); }
- case (_) { ret false; }
- }
- }
- case (ast::carg_lit(?l)) {
- alt (b.node) {
- case (ast::carg_lit(?m)) { ret lit_eq(l, m); }
- case (_) { ret false; }
- }
- }
+fn arg_eq[T](eq: &fn(&T, &T) -> bool , a: @sp_constr_arg[T],
+ b: @sp_constr_arg[T]) -> bool {
+ alt a.node {
+ ast::carg_base. {
+ alt b.node { ast::carg_base. { ret true; } _ { ret false; } }
+ }
+ ast::carg_ident(s) {
+ alt b.node { ast::carg_ident(t) { ret eq(s, t); } _ { ret false; } }
+ }
+ ast::carg_lit(l) {
+ alt b.node { ast::carg_lit(m) { ret lit_eq(l, m); } _ { ret false; } }
+ }
}
}
-fn args_eq[T](fn(&T, &T) -> bool eq,
- &(@sp_constr_arg[T])[] a, &(@sp_constr_arg[T])[] b) -> bool {
- let uint i = 0u;
- for (@sp_constr_arg[T] arg in a) {
- if (!arg_eq(eq, arg, b.(i))) { ret false; }
+fn args_eq[T](eq: fn(&T, &T) -> bool , a: &(@sp_constr_arg[T])[],
+ b: &(@sp_constr_arg[T])[]) -> bool {
+ let i: uint = 0u;
+ for arg: @sp_constr_arg[T] in a {
+ if !arg_eq(eq, arg, b.(i)) { ret false; }
i += 1u;
}
ret true;
}
-fn constr_eq(&@constr c, &@constr d) -> bool {
+fn constr_eq(c: &@constr, d: &@constr) -> bool {
ret path_to_str(c.node.path) == path_to_str(d.node.path) &&
// FIXME: hack
args_eq(eq_int, c.node.args, d.node.args);
}
-fn constrs_eq(&(@constr)[] cs, &(@constr)[] ds) -> bool {
- if (ivec::len(cs) != ivec::len(ds)) { ret false; }
- auto i = 0u;
- for (@constr c in cs) {
- if (!constr_eq(c, ds.(i))) { ret false; }
- i += 1u;
- }
+fn constrs_eq(cs: &(@constr)[], ds: &(@constr)[]) -> bool {
+ if ivec::len(cs) != ivec::len(ds) { ret false; }
+ let i = 0u;
+ for c: @constr in cs { if !constr_eq(c, ds.(i)) { ret false; } i += 1u; }
ret true;
}
-fn equal_type_structures(&sty a, &sty b) -> bool {
- fn equal_mt(&mt a, &mt b) -> bool {
+fn equal_type_structures(a: &sty, b: &sty) -> bool {
+ fn equal_mt(a: &mt, b: &mt) -> bool {
ret a.mut == b.mut && eq_ty(a.ty, b.ty);
}
- fn equal_fn(&arg[] args_a, &t rty_a, &arg[] args_b, &t rty_b) ->
+ fn equal_fn(args_a: &arg[], rty_a: &t, args_b: &arg[], rty_b: &t) ->
bool {
- if (!eq_ty(rty_a, rty_b)) { ret false; }
- auto len = ivec::len[arg](args_a);
- if (len != ivec::len[arg](args_b)) { ret false; }
- auto i = 0u;
- while (i < len) {
- auto arg_a = args_a.(i);
- auto arg_b = args_b.(i);
- if (arg_a.mode != arg_b.mode) { ret false; }
- if (!eq_ty(arg_a.ty, arg_b.ty)) { ret false; }
+ if !eq_ty(rty_a, rty_b) { ret false; }
+ let len = ivec::len[arg](args_a);
+ if len != ivec::len[arg](args_b) { ret false; }
+ let i = 0u;
+ while i < len {
+ let arg_a = args_a.(i);
+ let arg_b = args_b.(i);
+ if arg_a.mode != arg_b.mode { ret false; }
+ if !eq_ty(arg_a.ty, arg_b.ty) { ret false; }
i += 1u;
}
ret true;
}
- fn equal_def(&ast::def_id did_a, &ast::def_id did_b) -> bool {
+ fn equal_def(did_a: &ast::def_id, did_b: &ast::def_id) -> bool {
ret did_a.crate == did_b.crate && did_a.node == did_b.node;
}
- alt (a) {
- case (ty_nil) {
- alt (b) { case (ty_nil) { ret true; } case (_) { ret false; } }
+ alt a {
+ ty_nil. { alt b { ty_nil. { ret true; } _ { ret false; } } }
+ ty_bot. { alt b { ty_bot. { ret true; } _ { ret false; } } }
+ ty_bool. { alt b { ty_bool. { ret true; } _ { ret false; } } }
+ ty_int. { alt b { ty_int. { ret true; } _ { ret false; } } }
+ ty_float. { alt b { ty_float. { ret true; } _ { ret false; } } }
+ ty_uint. { alt b { ty_uint. { ret true; } _ { ret false; } } }
+ ty_machine(tm_a) {
+ alt b {
+ ty_machine(tm_b) {
+ ret hash_type_structure(a) == hash_type_structure(b);
+ }
+ _ { ret false; }
}
- case (ty_bot) {
- alt (b) { case (ty_bot) { ret true; } case (_) { ret false; } }
+ }
+ ty_char. { alt b { ty_char. { ret true; } _ { ret false; } } }
+ ty_str. { alt b { ty_str. { ret true; } _ { ret false; } } }
+ ty_istr. { alt b { ty_istr. { ret true; } _ { ret false; } } }
+ ty_tag(id_a, tys_a) {
+ alt b {
+ ty_tag(id_b, tys_b) {
+ if !equal_def(id_a, id_b) { ret false; }
+ let len = ivec::len[t](tys_a);
+ if len != ivec::len[t](tys_b) { ret false; }
+ let i = 0u;
+ while i < len {
+ if !eq_ty(tys_a.(i), tys_b.(i)) { ret false; }
+ i += 1u;
+ }
+ ret true;
+ }
+ _ { ret false; }
}
- case (ty_bool) {
- alt (b) { case (ty_bool) { ret true; } case (_) { ret false; } }
- }
- case (ty_int) {
- alt (b) { case (ty_int) { ret true; } case (_) { ret false; } }
- }
- case (ty_float) {
- alt (b) { case (ty_float) { ret true; } case (_) { ret false; } }
- }
- case (ty_uint) {
- alt (b) { case (ty_uint) { ret true; } case (_) { ret false; } }
- }
- case (ty_machine(?tm_a)) {
- alt (b) {
- case (ty_machine(?tm_b)) {
- ret hash_type_structure(a) == hash_type_structure(b);
+ }
+ ty_box(mt_a) {
+ alt b { ty_box(mt_b) { ret equal_mt(mt_a, mt_b); } _ { ret false; } }
+ }
+ ty_vec(mt_a) {
+ alt b { ty_vec(mt_b) { ret equal_mt(mt_a, mt_b); } _ { ret false; } }
+ }
+ ty_ivec(mt_a) {
+ alt b { ty_ivec(mt_b) { ret equal_mt(mt_a, mt_b); } _ { ret false; } }
+ }
+ ty_ptr(mt_a) {
+ alt b { ty_ptr(mt_b) { ret equal_mt(mt_a, mt_b); } _ { ret false; } }
+ }
+ ty_port(t_a) {
+ alt b { ty_port(t_b) { ret eq_ty(t_a, t_b); } _ { ret false; } }
+ }
+ ty_chan(t_a) {
+ alt b { ty_chan(t_b) { ret eq_ty(t_a, t_b); } _ { ret false; } }
+ }
+ ty_task. { alt b { ty_task. { ret true; } _ { ret false; } } }
+ ty_rec(flds_a) {
+ alt b {
+ ty_rec(flds_b) {
+ let len = ivec::len[field](flds_a);
+ if len != ivec::len[field](flds_b) { ret false; }
+ let i = 0u;
+ while i < len {
+ let fld_a = flds_a.(i);
+ let fld_b = flds_b.(i);
+ if !str::eq(fld_a.ident, fld_b.ident) ||
+ !equal_mt(fld_a.mt, fld_b.mt) {
+ ret false;
}
- case (_) { ret false; }
+ i += 1u;
}
+ ret true;
+ }
+ _ { ret false; }
}
- case (ty_char) {
- alt (b) { case (ty_char) { ret true; } case (_) { ret false; } }
+ }
+ ty_fn(p_a, args_a, rty_a, cf_a, constrs_a) {
+ alt b {
+ ty_fn(p_b, args_b, rty_b, cf_b, constrs_b) {
+ ret p_a == p_b && cf_a == cf_b && constrs_eq(constrs_a, constrs_b)
+ && equal_fn(args_a, rty_a, args_b, rty_b);
+ }
+ _ { ret false; }
}
- case (ty_str) {
- alt (b) { case (ty_str) { ret true; } case (_) { ret false; } }
+ }
+ ty_native_fn(abi_a, args_a, rty_a) {
+ alt b {
+ ty_native_fn(abi_b, args_b, rty_b) {
+ ret abi_a == abi_b && equal_fn(args_a, rty_a, args_b, rty_b);
+ }
+ _ { ret false; }
}
- case (ty_istr) {
- alt (b) { case (ty_istr) { ret true; } case (_) { ret false; } }
- }
- case (ty_tag(?id_a, ?tys_a)) {
- alt (b) {
- case (ty_tag(?id_b, ?tys_b)) {
- if (!equal_def(id_a, id_b)) { ret false; }
- auto len = ivec::len[t](tys_a);
- if (len != ivec::len[t](tys_b)) { ret false; }
- auto i = 0u;
- while (i < len) {
- if (!eq_ty(tys_a.(i), tys_b.(i))) { ret false; }
- i += 1u;
- }
- ret true;
+ }
+ ty_obj(methods_a) {
+ alt b {
+ ty_obj(methods_b) {
+ let len = ivec::len[method](methods_a);
+ if len != ivec::len[method](methods_b) { ret false; }
+ let i = 0u;
+ while i < len {
+ let m_a = methods_a.(i);
+ let m_b = methods_b.(i);
+ if m_a.proto != m_b.proto || !str::eq(m_a.ident, m_b.ident) ||
+ !equal_fn(m_a.inputs, m_a.output, m_b.inputs,
+ m_b.output) {
+ ret false;
}
- case (_) { ret false; }
+ i += 1u;
}
+ ret true;
+ }
+ _ { ret false; }
}
- case (ty_box(?mt_a)) {
- alt (b) {
- case (ty_box(?mt_b)) { ret equal_mt(mt_a, mt_b); }
- case (_) { ret false; }
+ }
+ ty_res(id_a, inner_a, tps_a) {
+ alt b {
+ ty_res(id_b, inner_b, tps_b) {
+ if !equal_def(id_a, id_b) || !eq_ty(inner_a, inner_b) {
+ ret false;
}
- }
- case (ty_vec(?mt_a)) {
- alt (b) {
- case (ty_vec(?mt_b)) { ret equal_mt(mt_a, mt_b); }
- case (_) { ret false; }
+ let i = 0u;
+ for tp_a: t in tps_a {
+ if !eq_ty(tp_a, tps_b.(i)) { ret false; }
+ i += 1u;
}
+ ret true;
+ }
+ _ { ret false; }
}
- case (ty_ivec(?mt_a)) {
- alt (b) {
- case (ty_ivec(?mt_b)) { ret equal_mt(mt_a, mt_b); }
- case (_) { ret false; }
- }
+ }
+ ty_var(v_a) {
+ alt b { ty_var(v_b) { ret v_a == v_b; } _ { ret false; } }
+ }
+ ty_param(pid_a) {
+ alt b { ty_param(pid_b) { ret pid_a == pid_b; } _ { ret false; } }
+ }
+ ty_type. { alt b { ty_type. { ret true; } _ { ret false; } } }
+ ty_native(a_id) {
+ alt b {
+ ty_native(b_id) {
+ ret a_id.crate == b_id.crate && a_id.node == b_id.node;
+ }
+ _ { ret false; }
}
- case (ty_ptr(?mt_a)) {
- alt (b) {
- case (ty_ptr(?mt_b)) { ret equal_mt(mt_a, mt_b); }
- case (_) { ret false; }
- }
- }
- case (ty_port(?t_a)) {
- alt (b) {
- case (ty_port(?t_b)) { ret eq_ty(t_a, t_b); }
- case (_) { ret false; }
- }
- }
- case (ty_chan(?t_a)) {
- alt (b) {
- case (ty_chan(?t_b)) { ret eq_ty(t_a, t_b); }
- case (_) { ret false; }
- }
- }
- case (ty_task) {
- alt (b) { case (ty_task) { ret true; } case (_) { ret false; } }
- }
- case (ty_rec(?flds_a)) {
- alt (b) {
- case (ty_rec(?flds_b)) {
- auto len = ivec::len[field](flds_a);
- if (len != ivec::len[field](flds_b)) { ret false; }
- auto i = 0u;
- while (i < len) {
- auto fld_a = flds_a.(i);
- auto fld_b = flds_b.(i);
- if (!str::eq(fld_a.ident, fld_b.ident) ||
- !equal_mt(fld_a.mt, fld_b.mt)) {
- ret false;
- }
- i += 1u;
- }
- ret true;
- }
- case (_) { ret false; }
- }
- }
- case (ty_fn(?p_a, ?args_a, ?rty_a, ?cf_a, ?constrs_a)) {
- alt (b) {
- case (ty_fn(?p_b, ?args_b, ?rty_b, ?cf_b, ?constrs_b)) {
- ret p_a == p_b && cf_a == cf_b &&
- constrs_eq(constrs_a, constrs_b) &&
- equal_fn(args_a, rty_a, args_b, rty_b);
- }
- case (_) { ret false; }
- }
- }
- case (ty_native_fn(?abi_a, ?args_a, ?rty_a)) {
- alt (b) {
- case (ty_native_fn(?abi_b, ?args_b, ?rty_b)) {
- ret abi_a == abi_b &&
- equal_fn(args_a, rty_a, args_b, rty_b);
- }
- case (_) { ret false; }
- }
- }
- case (ty_obj(?methods_a)) {
- alt (b) {
- case (ty_obj(?methods_b)) {
- auto len = ivec::len[method](methods_a);
- if (len != ivec::len[method](methods_b)) { ret false; }
- auto i = 0u;
- while (i < len) {
- auto m_a = methods_a.(i);
- auto m_b = methods_b.(i);
- if (m_a.proto != m_b.proto ||
- !str::eq(m_a.ident, m_b.ident) ||
- !equal_fn(m_a.inputs, m_a.output, m_b.inputs,
- m_b.output)) {
- ret false;
- }
- i += 1u;
- }
- ret true;
- }
- case (_) { ret false; }
- }
- }
- case (ty_res(?id_a, ?inner_a, ?tps_a)) {
- alt (b) {
- case (ty_res(?id_b, ?inner_b, ?tps_b)) {
- if (!equal_def(id_a, id_b) || !eq_ty(inner_a, inner_b)) {
- ret false;
- }
- auto i = 0u;
- for (t tp_a in tps_a) {
- if (!eq_ty(tp_a, tps_b.(i))) { ret false; }
- i += 1u;
- }
- ret true;
- }
- case (_) { ret false; }
- }
- }
- case (ty_var(?v_a)) {
- alt (b) {
- case (ty_var(?v_b)) { ret v_a == v_b; }
- case (_) { ret false; }
- }
- }
- case (ty_param(?pid_a)) {
- alt (b) {
- case (ty_param(?pid_b)) { ret pid_a == pid_b; }
- case (_) { ret false; }
- }
- }
- case (ty_type) {
- alt (b) { case (ty_type) { ret true; } case (_) { ret false; } }
- }
- case (ty_native(?a_id)) {
- alt (b) {
- case (ty_native(?b_id)) {
- ret a_id.crate == b_id.crate && a_id.node == b_id.node;
- }
- case (_) { ret false; } }
- }
+ }
}
}
@@ -1660,25 +1564,20 @@
// module.
//
// FIXME: Use structural comparison, but this loops forever and segfaults.
-fn eq_raw_ty(&@raw_t a, &@raw_t b) -> bool {
+fn eq_raw_ty(a: &@raw_t, b: &@raw_t) -> bool {
// Check hashes (fast path).
- if (a.hash != b.hash) { ret false; }
+ if a.hash != b.hash { ret false; }
// Check canonical names.
- alt (a.cname) {
- case (none) {
- alt (b.cname) {
- case (none) { /* ok */ }
- case (_) { ret false; }
- }
+ alt a.cname {
+ none. { alt b.cname { none. {/* ok */ } _ { ret false; } } }
+ some(s_a) {
+ alt b.cname {
+ some(s_b) { if !str::eq(s_a, s_b) { ret false; } }
+ _ { ret false; }
}
- case (some(?s_a)) {
- alt (b.cname) {
- case (some(?s_b)) { if (!str::eq(s_a, s_b)) { ret false; } }
- case (_) { ret false; }
- }
- }
+ }
}
// Check structures.
@@ -1688,139 +1587,142 @@
// This is the equality function the public should use. It works as long as
// the types are interned.
-fn eq_ty(&t a, &t b) -> bool { ret a == b; }
+fn eq_ty(a: &t, b: &t) -> bool { ret a == b; }
// Type lookups
-fn node_id_to_ty_param_substs_opt_and_ty(&ctxt cx, &ast::node_id id) ->
+fn node_id_to_ty_param_substs_opt_and_ty(cx: &ctxt, id: &ast::node_id) ->
ty_param_substs_opt_and_ty {
+
// Pull out the node type table.
- alt (smallintmap::find(*cx.node_types, id as uint)) {
- case (none) {
- cx.sess.bug("node_id_to_ty_param_substs_opt_and_ty() called on " +
- "an untyped node (" + std::int::to_str(id, 10u) + ")");
- }
- case (some(?tpot)) { ret tpot; }
+ alt smallintmap::find(*cx.node_types, id as uint) {
+ none. {
+ cx.sess.bug("node_id_to_ty_param_substs_opt_and_ty() called on " +
+ "an untyped node (" + std::int::to_str(id, 10u) +
+ ")");
+ }
+ some(tpot) { ret tpot; }
}
}
-fn node_id_to_type(&ctxt cx, &ast::node_id id) -> t {
+fn node_id_to_type(cx: &ctxt, id: &ast::node_id) -> t {
ret node_id_to_ty_param_substs_opt_and_ty(cx, id).ty;
}
-fn node_id_to_type_params(&ctxt cx, &ast::node_id id) -> t[] {
- alt (node_id_to_ty_param_substs_opt_and_ty(cx, id).substs) {
- case (none) { ret ~[]; }
- case (some(?tps)) { ret tps; }
+fn node_id_to_type_params(cx: &ctxt, id: &ast::node_id) -> t[] {
+ alt node_id_to_ty_param_substs_opt_and_ty(cx, id).substs {
+ none. { ret ~[]; }
+ some(tps) { ret tps; }
}
}
-fn node_id_has_type_params(&ctxt cx, &ast::node_id id) -> bool {
- auto tpt = node_id_to_ty_param_substs_opt_and_ty(cx, id);
+fn node_id_has_type_params(cx: &ctxt, id: &ast::node_id) -> bool {
+ let tpt = node_id_to_ty_param_substs_opt_and_ty(cx, id);
ret !option::is_none[t[]](tpt.substs);
}
// Returns a type with type parameter substitutions performed if applicable.
-fn ty_param_substs_opt_and_ty_to_monotype
- (&ctxt cx, &ty_param_substs_opt_and_ty tpot) -> t {
- alt (tpot.substs) {
- case (none) { ret tpot.ty; }
- case (some(?tps)) { ret substitute_type_params(cx, tps, tpot.ty); }
+fn ty_param_substs_opt_and_ty_to_monotype(cx: &ctxt,
+ tpot: &ty_param_substs_opt_and_ty)
+ -> t {
+ alt tpot.substs {
+ none. { ret tpot.ty; }
+ some(tps) { ret substitute_type_params(cx, tps, tpot.ty); }
}
}
// Returns the type of an annotation, with type parameter substitutions
// performed if applicable.
-fn node_id_to_monotype(&ctxt cx, ast::node_id id) -> t {
- auto tpot = node_id_to_ty_param_substs_opt_and_ty(cx, id);
+fn node_id_to_monotype(cx: &ctxt, id: ast::node_id) -> t {
+ let tpot = node_id_to_ty_param_substs_opt_and_ty(cx, id);
ret ty_param_substs_opt_and_ty_to_monotype(cx, tpot);
}
// Returns the number of distinct type parameters in the given type.
-fn count_ty_params(&ctxt cx, t ty) -> uint {
- fn counter(&ctxt cx, @mutable (uint[]) param_indices, t ty) {
- alt (struct(cx, ty)) {
- case (ty_param(?param_idx)) {
- auto seen = false;
- for (uint other_param_idx in *param_indices) {
- if (param_idx == other_param_idx) { seen = true; }
- }
- if (!seen) { *param_indices += ~[param_idx]; }
+fn count_ty_params(cx: &ctxt, ty: t) -> uint {
+ fn counter(cx: &ctxt, param_indices: @mutable uint[], ty: t) {
+ alt struct(cx, ty) {
+ ty_param(param_idx) {
+ let seen = false;
+ for other_param_idx: uint in *param_indices {
+ if param_idx == other_param_idx { seen = true; }
}
- case (_) {/* fall through */ }
+ if !seen { *param_indices += ~[param_idx]; }
+ }
+ _ {/* fall through */ }
}
}
- let @mutable (uint[]) param_indices = @mutable ~[];
- auto f = bind counter(cx, param_indices, _);
+ let param_indices: @mutable uint[] = @mutable ~[];
+ let f = bind counter(cx, param_indices, _);
walk_ty(cx, f, ty);
ret ivec::len[uint](*param_indices);
}
-fn type_contains_vars(&ctxt cx, &t typ) -> bool {
+fn type_contains_vars(cx: &ctxt, typ: &t) -> bool {
ret interner::get(*cx.ts, typ).has_vars;
}
-fn type_contains_params(&ctxt cx, &t typ) -> bool {
+fn type_contains_params(cx: &ctxt, typ: &t) -> bool {
ret interner::get(*cx.ts, typ).has_params;
}
// Type accessors for substructures of types
-fn ty_fn_args(&ctxt cx, &t fty) -> arg[] {
- alt (struct(cx, fty)) {
- case (ty::ty_fn(_, ?a, _, _, _)) { ret a; }
- case (ty::ty_native_fn(_, ?a, _)) { ret a; }
+fn ty_fn_args(cx: &ctxt, fty: &t) -> arg[] {
+ alt struct(cx, fty) {
+ ty::ty_fn(_, a, _, _, _) { ret a; }
+ ty::ty_native_fn(_, a, _) { ret a; }
}
cx.sess.bug("ty_fn_args() called on non-fn type");
}
-fn ty_fn_proto(&ctxt cx, &t fty) -> ast::proto {
- alt (struct(cx, fty)) { case (ty::ty_fn(?p, _, _, _, _)) { ret p; } }
+fn ty_fn_proto(cx: &ctxt, fty: &t) -> ast::proto {
+ alt struct(cx, fty) { ty::ty_fn(p, _, _, _, _) { ret p; } }
cx.sess.bug("ty_fn_proto() called on non-fn type");
}
-fn ty_fn_abi(&ctxt cx, &t fty) -> ast::native_abi {
- alt (struct(cx, fty)) { case (ty::ty_native_fn(?a, _, _)) { ret a; } }
+fn ty_fn_abi(cx: &ctxt, fty: &t) -> ast::native_abi {
+ alt struct(cx, fty) { ty::ty_native_fn(a, _, _) { ret a; } }
cx.sess.bug("ty_fn_abi() called on non-native-fn type");
}
-fn ty_fn_ret(&ctxt cx, &t fty) -> t {
- alt (struct(cx, fty)) {
- case (ty::ty_fn(_, _, ?r, _, _)) { ret r; }
- case (ty::ty_native_fn(_, _, ?r)) { ret r; }
+fn ty_fn_ret(cx: &ctxt, fty: &t) -> t {
+ alt struct(cx, fty) {
+ ty::ty_fn(_, _, r, _, _) { ret r; }
+ ty::ty_native_fn(_, _, r) { ret r; }
}
cx.sess.bug("ty_fn_ret() called on non-fn type");
}
-fn is_fn_ty(&ctxt cx, &t fty) -> bool {
- alt (struct(cx, fty)) {
- case (ty::ty_fn(_, _, _, _, _)) { ret true; }
- case (ty::ty_native_fn(_, _, _)) { ret true; }
- case (_) { ret false; }
+fn is_fn_ty(cx: &ctxt, fty: &t) -> bool {
+ alt struct(cx, fty) {
+ ty::ty_fn(_, _, _, _, _) { ret true; }
+ ty::ty_native_fn(_, _, _) { ret true; }
+ _ { ret false; }
}
}
-fn ty_var_id(&ctxt cx, t typ) -> int {
- alt (struct(cx, typ)) {
- case (ty::ty_var(?vid)) { ret vid; }
- case (_) { log_err "ty_var_id called on non-var ty"; fail; }
+fn ty_var_id(cx: &ctxt, typ: t) -> int {
+ alt struct(cx, typ) {
+ ty::ty_var(vid) { ret vid; }
+ _ { log_err "ty_var_id called on non-var ty"; fail; }
}
}
// Type accessors for AST nodes
-fn block_ty(&ctxt cx, &ast::blk b) -> t {
+fn block_ty(cx: &ctxt, b: &ast::blk) -> t {
ret node_id_to_type(cx, b.node.id);
}
// Returns the type of a pattern as a monotype. Like @expr_ty, this function
// doesn't provide type parameter substitutions.
-fn pat_ty(&ctxt cx, &@ast::pat pat) -> t {
+fn pat_ty(cx: &ctxt, pat: &@ast::pat) -> t {
ret node_id_to_monotype(cx, pat.id);
}
@@ -1831,63 +1733,63 @@
// ask for the type of "id" in "id(3)", it will return "fn(&int) -> int"
// instead of "fn(&T) -> T with T = int". If this isn't what you want, see
// expr_ty_params_and_ty() below.
-fn expr_ty(&ctxt cx, &@ast::expr expr) -> t {
+fn expr_ty(cx: &ctxt, expr: &@ast::expr) -> t {
ret node_id_to_monotype(cx, expr.id);
}
-fn expr_ty_params_and_ty(&ctxt cx, &@ast::expr expr)
- -> rec(t[] params, t ty) {
- ret rec(params=node_id_to_type_params(cx, expr.id),
- ty=node_id_to_type(cx, expr.id));
+fn expr_ty_params_and_ty(cx: &ctxt, expr: &@ast::expr) ->
+ {params: t[], ty: t} {
+ ret {params: node_id_to_type_params(cx, expr.id),
+ ty: node_id_to_type(cx, expr.id)};
}
-fn expr_has_ty_params(&ctxt cx, &@ast::expr expr) -> bool {
+fn expr_has_ty_params(cx: &ctxt, expr: &@ast::expr) -> bool {
ret node_id_has_type_params(cx, expr.id);
}
-fn decl_local_ty(&ctxt cx, &@ast::local l) -> t {
+fn decl_local_ty(cx: &ctxt, l: &@ast::local) -> t {
ret node_id_to_type(cx, l.node.id);
}
-fn stmt_node_id(&@ast::stmt s) -> ast::node_id {
- alt (s.node) {
- case (ast::stmt_decl(_, ?id)) { ret id; }
- case (ast::stmt_expr(_, ?id)) { ret id; }
- case (ast::stmt_crate_directive(_)) {
- log_err "ty::stmt_node_id(): crate directive found";
- fail;
- }
+fn stmt_node_id(s: &@ast::stmt) -> ast::node_id {
+ alt s.node {
+ ast::stmt_decl(_, id) { ret id; }
+ ast::stmt_expr(_, id) { ret id; }
+ ast::stmt_crate_directive(_) {
+ log_err "ty::stmt_node_id(): crate directive found";
+ fail;
+ }
}
}
-fn field_idx(&session::session sess, &span sp, &ast::ident id,
- &field[] fields) -> uint {
- let uint i = 0u;
- for (field f in fields) { if (str::eq(f.ident, id)) { ret i; } i += 1u; }
+fn field_idx(sess: &session::session, sp: &span, id: &ast::ident,
+ fields: &field[]) -> uint {
+ let i: uint = 0u;
+ for f: field in fields { if str::eq(f.ident, id) { ret i; } i += 1u; }
sess.span_fatal(sp, "unknown field '" + id + "' of record");
}
-fn method_idx(&session::session sess, &span sp, &ast::ident id,
- &method[] meths) -> uint {
- let uint i = 0u;
- for (method m in meths) { if (str::eq(m.ident, id)) { ret i; } i += 1u; }
+fn method_idx(sess: &session::session, sp: &span, id: &ast::ident,
+ meths: &method[]) -> uint {
+ let i: uint = 0u;
+ for m: method in meths { if str::eq(m.ident, id) { ret i; } i += 1u; }
sess.span_fatal(sp, "unknown method '" + id + "' of obj");
}
-fn sort_methods(&method[] meths) -> method[] {
- fn method_lteq(&method a, &method b) -> bool {
+fn sort_methods(meths: &method[]) -> method[] {
+ fn method_lteq(a: &method, b: &method) -> bool {
ret str::lteq(a.ident, b.ident);
}
ret std::sort::ivector::merge_sort[method](bind method_lteq(_, _), meths);
}
-fn is_lval(&@ast::expr expr) -> bool {
- alt (expr.node) {
- case (ast::expr_field(_, _)) { ret true; }
- case (ast::expr_index(_, _)) { ret true; }
- case (ast::expr_path(_)) { ret true; }
- case (ast::expr_unary(ast::deref, _)) { ret true; }
- case (_) { ret false; }
+fn is_lval(expr: &@ast::expr) -> bool {
+ alt expr.node {
+ ast::expr_field(_, _) { ret true; }
+ ast::expr_index(_, _) { ret true; }
+ ast::expr_path(_) { ret true; }
+ ast::expr_unary(ast::deref., _) { ret true; }
+ _ { ret false; }
}
}
@@ -1917,77 +1819,69 @@
tag fixup_result {
fix_ok(t); // fixup succeeded
+
+
fix_err(int); // fixup failed because a type variable was unresolved
}
type var_bindings =
- rec(ufindivec::ufind sets, smallintmap::smallintmap[t] types);
+ {sets: ufindivec::ufind, types: smallintmap::smallintmap[t]};
- type ctxt = rec(@var_bindings vb, ty_ctxt tcx);
+ type ctxt = {vb: @var_bindings, tcx: ty_ctxt};
fn mk_var_bindings() -> @var_bindings {
- ret @rec(sets=ufindivec::make(), types=smallintmap::mk[t]());
+ ret @{sets: ufindivec::make(), types: smallintmap::mk[t]()};
}
// Unifies two sets.
- fn union(&@ctxt cx, uint set_a, uint set_b) -> union_result {
+ fn union(cx: &@ctxt, set_a: uint, set_b: uint) -> union_result {
ufindivec::grow(cx.vb.sets, uint::max(set_a, set_b) + 1u);
- auto root_a = ufindivec::find(cx.vb.sets, set_a);
- auto root_b = ufindivec::find(cx.vb.sets, set_b);
+ let root_a = ufindivec::find(cx.vb.sets, set_a);
+ let root_b = ufindivec::find(cx.vb.sets, set_b);
- auto replace_type = bind fn (&@ctxt cx, t t, uint set_a, uint set_b) {
- ufindivec::union(cx.vb.sets, set_a, set_b);
- let uint root_c = ufindivec::find(cx.vb.sets, set_a);
- smallintmap::insert[t](cx.vb.types, root_c, t);
- } (_, _, set_a, set_b);
+ let replace_type =
+ bind fn (cx: &@ctxt, t: t, set_a: uint, set_b: uint) {
+ ufindivec::union(cx.vb.sets, set_a, set_b);
+ let root_c: uint = ufindivec::find(cx.vb.sets, set_a);
+ smallintmap::insert[t](cx.vb.types, root_c, t);
+ }(_, _, set_a, set_b);
- alt (smallintmap::find(cx.vb.types, root_a)) {
- case (none) {
- alt (smallintmap::find(cx.vb.types, root_b)) {
- case (none) {
- ufindivec::union(cx.vb.sets, set_a, set_b);
- ret unres_ok; }
- case (some(?t_b)) {
- replace_type(cx, t_b);
- ret unres_ok;
- }
- }
+
+ alt smallintmap::find(cx.vb.types, root_a) {
+ none. {
+ alt smallintmap::find(cx.vb.types, root_b) {
+ none. {
+ ufindivec::union(cx.vb.sets, set_a, set_b);
+ ret unres_ok;
+ }
+ some(t_b) { replace_type(cx, t_b); ret unres_ok; }
}
- case (some(?t_a)) {
- alt (smallintmap::find(cx.vb.types, root_b)) {
- case (none) {
- replace_type(cx, t_a);
- ret unres_ok;
- }
- case (some(?t_b)) {
- alt (unify_step(cx, t_a, t_b)) {
- case (ures_ok(?t_c)) {
- replace_type(cx, t_c);
- ret unres_ok;
- }
- case (ures_err(?terr)) {
- ret unres_err(terr);
- }
- }
- }
+ }
+ some(t_a) {
+ alt smallintmap::find(cx.vb.types, root_b) {
+ none. { replace_type(cx, t_a); ret unres_ok; }
+ some(t_b) {
+ alt unify_step(cx, t_a, t_b) {
+ ures_ok(t_c) { replace_type(cx, t_c); ret unres_ok; }
+ ures_err(terr) { ret unres_err(terr); }
}
+ }
}
+ }
}
}
- fn record_var_binding(&@ctxt cx, int key, t typ) -> result {
+ fn record_var_binding(cx: &@ctxt, key: int, typ: t) -> result {
ufindivec::grow(cx.vb.sets, (key as uint) + 1u);
- auto root = ufindivec::find(cx.vb.sets, key as uint);
- auto result_type = typ;
- alt (smallintmap::find[t](cx.vb.types, root)) {
- case (some(?old_type)) {
- alt (unify_step(cx, old_type, typ)) {
- case (ures_ok(?unified_type)) {
- result_type = unified_type;
- }
- case (?rs) { ret rs; }
- }
+ let root = ufindivec::find(cx.vb.sets, key as uint);
+ let result_type = typ;
+ alt smallintmap::find[t](cx.vb.types, root) {
+ some(old_type) {
+ alt unify_step(cx, old_type, typ) {
+ ures_ok(unified_type) { result_type = unified_type; }
+ rs { ret rs; }
}
- case (none) {/* fall through */ }
+ }
+ none. {/* fall through */ }
}
smallintmap::insert[t](cx.vb.types, root, result_type);
ret ures_ok(typ);
@@ -2001,8 +1895,8 @@
// something we'll probably need to develop over time.
// Simple structural type comparison.
- fn struct_cmp(@ctxt cx, t expected, t actual) -> result {
- if (struct(cx.tcx, expected) == struct(cx.tcx, actual)) {
+ fn struct_cmp(cx: @ctxt, expected: t, actual: t) -> result {
+ if struct(cx.tcx, expected) == struct(cx.tcx, actual) {
ret ures_ok(expected);
}
ret ures_err(terr_mismatch);
@@ -2010,68 +1904,51 @@
// Right now this just checks that the lists of constraints are
// pairwise equal.
- fn unify_constrs(&t base_t, (@type_constr)[] expected,
- &(@type_constr)[] actual) -> result {
- auto expected_len = ivec::len(expected);
- auto actual_len = ivec::len(actual);
+ fn unify_constrs(base_t: &t, expected: (@type_constr)[],
+ actual: &(@type_constr)[]) -> result {
+ let expected_len = ivec::len(expected);
+ let actual_len = ivec::len(actual);
- if (expected_len != actual_len) {
+ if expected_len != actual_len {
ret ures_err(terr_constr_len(expected_len, actual_len));
}
- auto i = 0u;
- auto rslt;
- for (@type_constr c in expected) {
+ let i = 0u;
+ let rslt;
+ for c: @type_constr in expected {
rslt = unify_constr(base_t, c, actual.(i));
- alt (rslt) {
- case (ures_ok(_)) { }
- case (ures_err(_)) { ret rslt; }
- }
+ alt rslt { ures_ok(_) { } ures_err(_) { ret rslt; } }
i += 1u;
}
ret ures_ok(base_t);
}
- fn unify_constr(&t base_t, @type_constr expected,
- &@type_constr actual_constr) -> result {
- auto ok_res = ures_ok(base_t);
- auto err_res = ures_err(terr_constr_mismatch(expected,
- actual_constr));
- if (expected.node.id != actual_constr.node.id) {
- ret err_res;
- }
- auto expected_arg_len = ivec::len(expected.node.args);
- auto actual_arg_len = ivec::len(actual_constr.node.args);
- if (expected_arg_len != actual_arg_len) {
- ret err_res;
- }
- auto i = 0u;
- auto actual;
- for (@ty_constr_arg a in expected.node.args) {
+ fn unify_constr(base_t: &t, expected: @type_constr,
+ actual_constr: &@type_constr) -> result {
+ let ok_res = ures_ok(base_t);
+ let err_res = ures_err(terr_constr_mismatch(expected, actual_constr));
+ if expected.node.id != actual_constr.node.id { ret err_res; }
+ let expected_arg_len = ivec::len(expected.node.args);
+ let actual_arg_len = ivec::len(actual_constr.node.args);
+ if expected_arg_len != actual_arg_len { ret err_res; }
+ let i = 0u;
+ let actual;
+ for a: @ty_constr_arg in expected.node.args {
actual = actual_constr.node.args.(i);
- alt (a.node) {
- case (carg_base) {
- alt (actual.node) {
- case (carg_base) { }
- case (_) { ret err_res; }
- }
+ alt a.node {
+ carg_base. {
+ alt actual.node { carg_base. { } _ { ret err_res; } }
+ }
+ carg_lit(l) {
+ alt actual.node {
+ carg_lit(m) { if l != m { ret err_res; } }
+ _ { ret err_res; }
}
- case (carg_lit(?l)) {
- alt (actual.node) {
- case (carg_lit(?m)) {
- if (l != m) { ret err_res; }
- }
- case (_) { ret err_res; }
- }
+ }
+ carg_ident(p) {
+ alt actual.node {
+ carg_ident(q) { if p.node != q.node { ret err_res; } }
+ _ { ret err_res; }
}
- case (carg_ident(?p)) {
- alt (actual.node) {
- case (carg_ident(?q)) {
- if (p.node != q.node) {
- ret err_res;
- }
- }
- case (_) { ret err_res; }
- }
- }
+ }
}
i += 1u;
}
@@ -2079,171 +1956,167 @@
}
// Unifies two mutability flags.
- fn unify_mut(ast::mutability expected, ast::mutability actual) ->
+ fn unify_mut(expected: ast::mutability, actual: ast::mutability) ->
option::t[ast::mutability] {
- if (expected == actual) { ret some(expected); }
- if (expected == ast::maybe_mut) { ret some(actual); }
- if (actual == ast::maybe_mut) { ret some(expected); }
+ if expected == actual { ret some(expected); }
+ if expected == ast::maybe_mut { ret some(actual); }
+ if actual == ast::maybe_mut { ret some(expected); }
ret none;
}
tag fn_common_res {
fn_common_res_err(result);
fn_common_res_ok(arg[], t);
}
- fn unify_fn_common(&@ctxt cx, &t expected, &t actual,
- &arg[] expected_inputs, &t expected_output,
- &arg[] actual_inputs, &t actual_output) ->
+ fn unify_fn_common(cx: &@ctxt, expected: &t, actual: &t,
+ expected_inputs: &arg[], expected_output: &t,
+ actual_inputs: &arg[], actual_output: &t) ->
fn_common_res {
- auto expected_len = ivec::len[arg](expected_inputs);
- auto actual_len = ivec::len[arg](actual_inputs);
- if (expected_len != actual_len) {
+ let expected_len = ivec::len[arg](expected_inputs);
+ let actual_len = ivec::len[arg](actual_inputs);
+ if expected_len != actual_len {
ret fn_common_res_err(ures_err(terr_arg_count));
}
// TODO: as above, we should have an iter2 iterator.
- let arg[] result_ins = ~[];
- auto i = 0u;
- while (i < expected_len) {
- auto expected_input = expected_inputs.(i);
- auto actual_input = actual_inputs.(i);
+ let result_ins: arg[] = ~[];
+ let i = 0u;
+ while i < expected_len {
+ let expected_input = expected_inputs.(i);
+ let actual_input = actual_inputs.(i);
// Unify the result modes.
- auto result_mode;
- if (expected_input.mode != actual_input.mode) {
- ret fn_common_res_err(ures_err(terr_mode_mismatch(
- expected_input.mode, actual_input.mode)));
+ let result_mode;
+ if expected_input.mode != actual_input.mode {
+ ret fn_common_res_err(ures_err(terr_mode_mismatch(expected_input.mode,
+ actual_input.mode)));
} else { result_mode = expected_input.mode; }
- auto result = unify_step(cx, expected_input.ty, actual_input.ty);
- alt (result) {
- case (ures_ok(?rty)) {
- result_ins += ~[rec(mode=result_mode, ty=rty)];
- }
- case (_) { ret fn_common_res_err(result); }
+ let result = unify_step(cx, expected_input.ty, actual_input.ty);
+ alt result {
+ ures_ok(rty) { result_ins += ~[{mode: result_mode, ty: rty}]; }
+ _ { ret fn_common_res_err(result); }
}
i += 1u;
}
// Check the output.
- auto result = unify_step(cx, expected_output, actual_output);
- alt (result) {
- case (ures_ok(?rty)) { ret fn_common_res_ok(result_ins, rty); }
- case (_) { ret fn_common_res_err(result); }
+ let result = unify_step(cx, expected_output, actual_output);
+ alt result {
+ ures_ok(rty) { ret fn_common_res_ok(result_ins, rty); }
+ _ { ret fn_common_res_err(result); }
}
}
- fn unify_fn(&@ctxt cx, &ast::proto e_proto, &ast::proto a_proto,
- &t expected, &t actual, &arg[] expected_inputs,
- &t expected_output, &arg[] actual_inputs, &t actual_output,
- &controlflow expected_cf, &controlflow actual_cf,
- &(@constr)[] expected_constrs,
- &(@constr)[] actual_constrs) -> result {
- if (e_proto != a_proto) { ret ures_err(terr_mismatch); }
- alt (expected_cf) {
- case (ast::return) { }
- case ( // ok
- ast::noreturn) {
- alt (actual_cf) {
- case (ast::noreturn) {
- // ok
+ fn unify_fn(cx: &@ctxt, e_proto: &ast::proto, a_proto: &ast::proto,
+ expected: &t, actual: &t, expected_inputs: &arg[],
+ expected_output: &t, actual_inputs: &arg[], actual_output: &t,
+ expected_cf: &controlflow, actual_cf: &controlflow,
+ expected_constrs: &(@constr)[], actual_constrs: &(@constr)[])
+ -> result {
+ if e_proto != a_proto { ret ures_err(terr_mismatch); }
+ alt expected_cf {
+ ast::return. { }
+ // ok
+ ast::noreturn. {
+ alt actual_cf {
+ ast::noreturn. {
+ // ok
- }
- case (_) {
- /* even though typestate checking is mostly
- responsible for checking control flow annotations,
- this check is necessary to ensure that the
- annotation in an object method matches the
- declared object type */
+ }
+ _ {
+ /* even though typestate checking is mostly
+ responsible for checking control flow annotations,
+ this check is necessary to ensure that the
+ annotation in an object method matches the
+ declared object type */
- ret ures_err(terr_controlflow_mismatch);
- }
- }
+ ret ures_err(terr_controlflow_mismatch);
+ }
}
+ }
}
- auto t =
+ let t =
unify_fn_common(cx, expected, actual, expected_inputs,
expected_output, actual_inputs, actual_output);
- alt (t) {
- case (fn_common_res_err(?r)) { ret r; }
- case (fn_common_res_ok(?result_ins, ?result_out)) {
- auto t2 =
- mk_fn(cx.tcx, e_proto, result_ins, result_out, actual_cf,
- actual_constrs);
- ret ures_ok(t2);
- }
+ alt t {
+ fn_common_res_err(r) { ret r; }
+ fn_common_res_ok(result_ins, result_out) {
+ let t2 =
+ mk_fn(cx.tcx, e_proto, result_ins, result_out, actual_cf,
+ actual_constrs);
+ ret ures_ok(t2);
+ }
}
}
- fn unify_native_fn(&@ctxt cx, &ast::native_abi e_abi,
- &ast::native_abi a_abi, &t expected, &t actual,
- &arg[] expected_inputs, &t expected_output,
- &arg[] actual_inputs, &t actual_output) -> result {
- if (e_abi != a_abi) { ret ures_err(terr_mismatch); }
- auto t =
+ fn unify_native_fn(cx: &@ctxt, e_abi: &ast::native_abi,
+ a_abi: &ast::native_abi, expected: &t, actual: &t,
+ expected_inputs: &arg[], expected_output: &t,
+ actual_inputs: &arg[], actual_output: &t) -> result {
+ if e_abi != a_abi { ret ures_err(terr_mismatch); }
+ let t =
unify_fn_common(cx, expected, actual, expected_inputs,
expected_output, actual_inputs, actual_output);
- alt (t) {
- case (fn_common_res_err(?r)) { ret r; }
- case (fn_common_res_ok(?result_ins, ?result_out)) {
- auto t2 = mk_native_fn(cx.tcx, e_abi, result_ins, result_out);
- ret ures_ok(t2);
- }
+ alt t {
+ fn_common_res_err(r) { ret r; }
+ fn_common_res_ok(result_ins, result_out) {
+ let t2 = mk_native_fn(cx.tcx, e_abi, result_ins, result_out);
+ ret ures_ok(t2);
+ }
}
}
- fn unify_obj(&@ctxt cx, &t expected, &t actual,
- &method[] expected_meths, &method[] actual_meths) ->
+ fn unify_obj(cx: &@ctxt, expected: &t, actual: &t,
+ expected_meths: &method[], actual_meths: &method[]) ->
result {
- let method[] result_meths = ~[];
- let uint i = 0u;
- let uint expected_len = ivec::len[method](expected_meths);
- let uint actual_len = ivec::len[method](actual_meths);
- if (expected_len != actual_len) { ret ures_err(terr_meth_count); }
- while (i < expected_len) {
- auto e_meth = expected_meths.(i);
- auto a_meth = actual_meths.(i);
- if (!str::eq(e_meth.ident, a_meth.ident)) {
+ let result_meths: method[] = ~[];
+ let i: uint = 0u;
+ let expected_len: uint = ivec::len[method](expected_meths);
+ let actual_len: uint = ivec::len[method](actual_meths);
+ if expected_len != actual_len { ret ures_err(terr_meth_count); }
+ while i < expected_len {
+ let e_meth = expected_meths.(i);
+ let a_meth = actual_meths.(i);
+ if !str::eq(e_meth.ident, a_meth.ident) {
ret ures_err(terr_obj_meths(e_meth.ident, a_meth.ident));
}
- auto r =
+ let r =
unify_fn(cx, e_meth.proto, a_meth.proto, expected, actual,
e_meth.inputs, e_meth.output, a_meth.inputs,
a_meth.output, e_meth.cf, a_meth.cf, e_meth.constrs,
a_meth.constrs);
- alt (r) {
- case (ures_ok(?tfn)) {
- alt (struct(cx.tcx, tfn)) {
- case (ty_fn(?proto, ?ins, ?out, ?cf, ?constrs)) {
- result_meths +=
- ~[rec(inputs=ins,
- output=out,
- cf=cf,
- constrs=constrs with e_meth)];
- }
- }
+ alt r {
+ ures_ok(tfn) {
+ alt struct(cx.tcx, tfn) {
+ ty_fn(proto, ins, out, cf, constrs) {
+ result_meths +=
+ ~[{inputs: ins, output: out, cf: cf, constrs: constrs
+ with e_meth}];
+ }
}
- case (_) { ret r; }
+ }
+ _ { ret r; }
}
i += 1u;
}
- auto t = mk_obj(cx.tcx, result_meths);
+ let t = mk_obj(cx.tcx, result_meths);
ret ures_ok(t);
}
// If the given type is a variable, returns the structure of that type.
- fn resolve_type_structure(&ty_ctxt tcx, &@var_bindings vb, t typ) ->
+ fn resolve_type_structure(tcx: &ty_ctxt, vb: &@var_bindings, typ: t) ->
fixup_result {
- alt (struct(tcx, typ)) {
- case (ty_var(?vid)) {
- if (vid as uint >= ufindivec::set_count(vb.sets)) {
- ret fix_err(vid);
- }
- auto root_id = ufindivec::find(vb.sets, vid as uint);
- alt (smallintmap::find[t](vb.types, root_id)) {
- case (none) { ret fix_err(vid); }
- case (some(?rt)) { ret fix_ok(rt); }
- }
+ alt struct(tcx, typ) {
+ ty_var(vid) {
+ if vid as uint >= ufindivec::set_count(vb.sets) {
+ ret fix_err(vid);
}
- case (_) { ret fix_ok(typ); }
+ let root_id = ufindivec::find(vb.sets, vid as uint);
+ alt smallintmap::find[t](vb.types, root_id) {
+ none. { ret fix_err(vid); }
+ some(rt) { ret fix_ok(rt); }
+ }
+ }
+ _ { ret fix_ok(typ); }
}
}
- fn unify_step(&@ctxt cx, &t expected, &t actual) -> result {
+ fn unify_step(cx: &@ctxt, expected: &t, actual: &t) -> result {
// TODO: rewrite this using tuple pattern matching when available, to
// avoid all this rightward drift and spikiness.
@@ -2252,396 +2125,370 @@
// Fast path.
- if (eq_ty(expected, actual)) { ret ures_ok(expected); }
+ if eq_ty(expected, actual) { ret ures_ok(expected); }
// Stage 1: Handle the cases in which one side or another is a type
// variable.
- alt (struct(cx.tcx, actual)) {
- case (
- // If the RHS is a variable type, then just do the
- // appropriate binding.
- ty::ty_var(?actual_id)) {
- auto actual_n = actual_id as uint;
- alt (struct(cx.tcx, expected)) {
- case (ty::ty_var(?expected_id)) {
- auto expected_n = expected_id as uint;
- alt(union(cx, expected_n, actual_n)) {
- case (unres_ok) { /* fall through */ }
- case (unres_err(?t_e)) {
- ret ures_err(t_e);
- }
- }
- }
- case (_) {
+ alt struct(cx.tcx, actual) {
- // Just bind the type variable to the expected type.
- alt (record_var_binding(cx, actual_id, expected)) {
- case (ures_ok(_)) {/* fall through */ }
- case (?rs) { ret rs; }
- }
- }
+ // If the RHS is a variable type, then just do the
+ // appropriate binding.
+ ty::ty_var(actual_id) {
+ let actual_n = actual_id as uint;
+ alt struct(cx.tcx, expected) {
+ ty::ty_var(expected_id) {
+ let expected_n = expected_id as uint;
+ alt union(cx, expected_n, actual_n) {
+ unres_ok. {/* fall through */ }
+ unres_err(t_e) { ret ures_err(t_e); }
}
- ret ures_ok(mk_var(cx.tcx, actual_id));
+ }
+ _ {
+
+
+ // Just bind the type variable to the expected type.
+ alt record_var_binding(cx, actual_id, expected) {
+ ures_ok(_) {/* fall through */ }
+ rs { ret rs; }
+ }
+ }
}
- case (_) {/* empty */ }
+ ret ures_ok(mk_var(cx.tcx, actual_id));
+ }
+ _ {/* empty */ }
}
- alt (struct(cx.tcx, expected)) {
- case (ty::ty_var(?expected_id)) {
- // Add a binding. (`actual` can't actually be a var here.)
+ alt struct(cx.tcx, expected) {
+ ty::ty_var(expected_id) {
+ // Add a binding. (`actual` can't actually be a var here.)
- alt (record_var_binding(cx, expected_id, actual)) {
- case (ures_ok(_)) {/* fall through */ }
- case (?rs) { ret rs; }
- }
- ret ures_ok(mk_var(cx.tcx, expected_id));
+ alt record_var_binding(cx, expected_id, actual) {
+ ures_ok(_) {/* fall through */ }
+ rs { ret rs; }
}
- case (_) {/* fall through */ }
+ ret ures_ok(mk_var(cx.tcx, expected_id));
+ }
+ _ {/* fall through */ }
}
// Stage 2: Handle all other cases.
- alt (struct(cx.tcx, actual)) {
- case (ty::ty_bot) { ret ures_ok(expected); }
- case (_) {/* fall through */ }
+ alt struct(cx.tcx, actual) {
+ ty::ty_bot. { ret ures_ok(expected); }
+ _ {/* fall through */ }
}
- alt (struct(cx.tcx, expected)) {
- case (ty::ty_nil) { ret struct_cmp(cx, expected, actual); }
- // _|_ unifies with anything
- case (ty::ty_bot) {
- ret ures_ok(actual);
- }
- case (ty::ty_bool) { ret struct_cmp(cx, expected, actual); }
- case (ty::ty_int) { ret struct_cmp(cx, expected, actual); }
- case (ty::ty_uint) { ret struct_cmp(cx, expected, actual); }
- case (ty::ty_machine(_)) { ret struct_cmp(cx, expected, actual); }
- case (ty::ty_float) { ret struct_cmp(cx, expected, actual); }
- case (ty::ty_char) { ret struct_cmp(cx, expected, actual); }
- case (ty::ty_str) { ret struct_cmp(cx, expected, actual); }
- case (ty::ty_istr) { ret struct_cmp(cx, expected, actual); }
- case (ty::ty_type) { ret struct_cmp(cx, expected, actual); }
- case (ty::ty_native(?ex_id)) {
- alt (struct(cx.tcx, actual)) {
- case (ty_native(?act_id)) {
- if (ex_id.crate == act_id.crate &&
- ex_id.node == act_id.node) {
- ret ures_ok(actual);
- } else {
- ret ures_err(terr_mismatch);
- }
- }
- case (_) { ret ures_err(terr_mismatch); }
- }
- }
- case (ty::ty_param(_)) { ret struct_cmp(cx, expected, actual); }
- case (ty::ty_tag(?expected_id, ?expected_tps)) {
- alt (struct(cx.tcx, actual)) {
- case (ty::ty_tag(?actual_id, ?actual_tps)) {
- if (expected_id.crate != actual_id.crate ||
- expected_id.node != actual_id.node) {
- ret ures_err(terr_mismatch);
- }
- // TODO: factor this cruft out
- let t[] result_tps = ~[];
- auto i = 0u;
- auto expected_len = ivec::len[t](expected_tps);
- while (i < expected_len) {
- auto expected_tp = expected_tps.(i);
- auto actual_tp = actual_tps.(i);
- auto result =
- unify_step(cx, expected_tp, actual_tp);
- alt (result) {
- case (ures_ok(?rty)) { result_tps += ~[rty]; }
- case (_) { ret result; }
- }
- i += 1u;
- }
- ret ures_ok(mk_tag(cx.tcx, expected_id, result_tps));
- }
- case (_) {/* fall through */ }
- }
- ret ures_err(terr_mismatch);
- }
- case (ty::ty_box(?expected_mt)) {
- alt (struct(cx.tcx, actual)) {
- case (ty::ty_box(?actual_mt)) {
- auto mut;
- alt (unify_mut(expected_mt.mut, actual_mt.mut)) {
- case (none) { ret ures_err(terr_box_mutability); }
- case (some(?m)) { mut = m; }
- }
- auto result =
- unify_step(cx, expected_mt.ty, actual_mt.ty);
- alt (result) {
- case (ures_ok(?result_sub)) {
- auto mt = rec(ty=result_sub, mut=mut);
- ret ures_ok(mk_box(cx.tcx, mt));
- }
- case (_) { ret result; }
- }
- }
- case (_) { ret ures_err(terr_mismatch); }
- }
- }
- case (ty::ty_vec(?expected_mt)) {
- alt (struct(cx.tcx, actual)) {
- case (ty::ty_vec(?actual_mt)) {
- auto mut;
- alt (unify_mut(expected_mt.mut, actual_mt.mut)) {
- case (none) { ret ures_err(terr_vec_mutability); }
- case (some(?m)) { mut = m; }
- }
- auto result =
- unify_step(cx, expected_mt.ty, actual_mt.ty);
- alt (result) {
- case (ures_ok(?result_sub)) {
- auto mt = rec(ty=result_sub, mut=mut);
- ret ures_ok(mk_vec(cx.tcx, mt));
- }
- case (_) { ret result; }
- }
- }
- case (_) { ret ures_err(terr_mismatch); }
- }
- }
- case (ty::ty_ivec(?expected_mt)) {
- alt (struct(cx.tcx, actual)) {
- case (ty::ty_ivec(?actual_mt)) {
- auto mut;
- alt (unify_mut(expected_mt.mut, actual_mt.mut)) {
- case (none) { ret ures_err(terr_vec_mutability); }
- case (some(?m)) { mut = m; }
- }
- auto result =
- unify_step(cx, expected_mt.ty, actual_mt.ty);
- alt (result) {
- case (ures_ok(?result_sub)) {
- auto mt = rec(ty=result_sub, mut=mut);
- ret ures_ok(mk_ivec(cx.tcx, mt));
- }
- case (_) { ret result; }
- }
- }
- case (_) { ret ures_err(terr_mismatch); }
- }
- }
- case (ty::ty_ptr(?expected_mt)) {
- alt (struct(cx.tcx, actual)) {
- case (ty::ty_ptr(?actual_mt)) {
- auto mut;
- alt (unify_mut(expected_mt.mut, actual_mt.mut)) {
- case (none) { ret ures_err(terr_vec_mutability); }
- case (some(?m)) { mut = m; }
- }
- auto result =
- unify_step(cx, expected_mt.ty, actual_mt.ty);
- alt (result) {
- case (ures_ok(?result_sub)) {
- auto mt = rec(ty=result_sub, mut=mut);
- ret ures_ok(mk_ptr(cx.tcx, mt));
- }
- case (_) { ret result; }
- }
- }
- case (_) { ret ures_err(terr_mismatch); }
- }
- }
- case (ty::ty_port(?expected_sub)) {
- alt (struct(cx.tcx, actual)) {
- case (ty::ty_port(?actual_sub)) {
- auto result =
- unify_step(cx, expected_sub, actual_sub);
- alt (result) {
- case (ures_ok(?result_sub)) {
- ret ures_ok(mk_port(cx.tcx, result_sub));
- }
- case (_) { ret result; }
- }
- }
- case (_) { ret ures_err(terr_mismatch); }
- }
- }
- case (ty::ty_res(?ex_id, ?ex_inner, ?ex_tps)) {
- alt (struct(cx.tcx, actual)) {
- case (ty::ty_res(?act_id, ?act_inner, ?act_tps)) {
- if (ex_id.crate != act_id.crate ||
- ex_id.node != act_id.node) {
- ret ures_err(terr_mismatch);
- }
- auto result = unify_step(cx, ex_inner, act_inner);
- alt (result) {
- case (ures_ok(?res_inner)) {
- auto i = 0u;
- auto res_tps = ~[];
- for (t ex_tp in ex_tps) {
- auto result =
- unify_step(cx, ex_tp, act_tps.(i));
- alt (result) {
- case (ures_ok(?rty)) {
- res_tps += ~[rty];
- }
- case (_) { ret result; }
- }
- i += 1u;
- }
- ret ures_ok(mk_res(cx.tcx, act_id, res_inner,
- res_tps));
- }
- case (_) { ret result; }
- }
- }
- case (_) { ret ures_err(terr_mismatch); }
- }
- }
- case (ty::ty_chan(?expected_sub)) {
- alt (struct(cx.tcx, actual)) {
- case (ty::ty_chan(?actual_sub)) {
- auto result =
- unify_step(cx, expected_sub, actual_sub);
- alt (result) {
- case (ures_ok(?result_sub)) {
- ret ures_ok(mk_chan(cx.tcx, result_sub));
- }
- case (_) { ret result; }
- }
- }
- case (_) { ret ures_err(terr_mismatch); }
- }
- }
- case (ty::ty_rec(?expected_fields)) {
- alt (struct(cx.tcx, actual)) {
- case (ty::ty_rec(?actual_fields)) {
- auto expected_len = ivec::len[field](expected_fields);
- auto actual_len = ivec::len[field](actual_fields);
- if (expected_len != actual_len) {
- auto err =
- terr_record_size(expected_len, actual_len);
- ret ures_err(err);
- }
- // TODO: implement an iterator that can iterate over
- // two arrays simultaneously.
+ alt struct(cx.tcx, expected) {
+ ty::ty_nil. { ret struct_cmp(cx, expected, actual); }
- let field[] result_fields = ~[];
- auto i = 0u;
- while (i < expected_len) {
- auto expected_field = expected_fields.(i);
- auto actual_field = actual_fields.(i);
- auto mut;
- alt (unify_mut(expected_field.mt.mut,
- actual_field.mt.mut)) {
- case (none) {
- ret ures_err(terr_record_mutability);
- }
- case (some(?m)) { mut = m; }
- }
- if (!str::eq(expected_field.ident,
- actual_field.ident)) {
- auto err =
- terr_record_fields(expected_field.ident,
- actual_field.ident);
- ret ures_err(err);
- }
- auto result =
- unify_step(cx, expected_field.mt.ty,
- actual_field.mt.ty);
- alt (result) {
- case (ures_ok(?rty)) {
- auto mt = rec(ty=rty, mut=mut);
- result_fields +=
- ~[rec(mt=mt with expected_field)];
- }
- case (_) { ret result; }
- }
- i += 1u;
+ // _|_ unifies with anything
+ ty::ty_bot. {
+ ret ures_ok(actual);
+ }
+ ty::ty_bool. { ret struct_cmp(cx, expected, actual); }
+ ty::ty_int. { ret struct_cmp(cx, expected, actual); }
+ ty::ty_uint. { ret struct_cmp(cx, expected, actual); }
+ ty::ty_machine(_) { ret struct_cmp(cx, expected, actual); }
+ ty::ty_float. { ret struct_cmp(cx, expected, actual); }
+ ty::ty_char. { ret struct_cmp(cx, expected, actual); }
+ ty::ty_str. { ret struct_cmp(cx, expected, actual); }
+ ty::ty_istr. { ret struct_cmp(cx, expected, actual); }
+ ty::ty_type. { ret struct_cmp(cx, expected, actual); }
+ ty::ty_native(ex_id) {
+ alt struct(cx.tcx, actual) {
+ ty_native(act_id) {
+ if ex_id.crate == act_id.crate && ex_id.node == act_id.node {
+ ret ures_ok(actual);
+ } else { ret ures_err(terr_mismatch); }
+ }
+ _ { ret ures_err(terr_mismatch); }
+ }
+ }
+ ty::ty_param(_) { ret struct_cmp(cx, expected, actual); }
+ ty::ty_tag(expected_id, expected_tps) {
+ alt struct(cx.tcx, actual) {
+ ty::ty_tag(actual_id, actual_tps) {
+ if expected_id.crate != actual_id.crate ||
+ expected_id.node != actual_id.node {
+ ret ures_err(terr_mismatch);
+ }
+ // TODO: factor this cruft out
+ let result_tps: t[] = ~[];
+ let i = 0u;
+ let expected_len = ivec::len[t](expected_tps);
+ while i < expected_len {
+ let expected_tp = expected_tps.(i);
+ let actual_tp = actual_tps.(i);
+ let result = unify_step(cx, expected_tp, actual_tp);
+ alt result {
+ ures_ok(rty) { result_tps += ~[rty]; }
+ _ { ret result; }
+ }
+ i += 1u;
+ }
+ ret ures_ok(mk_tag(cx.tcx, expected_id, result_tps));
+ }
+ _ {/* fall through */ }
+ }
+ ret ures_err(terr_mismatch);
+ }
+ ty::ty_box(expected_mt) {
+ alt struct(cx.tcx, actual) {
+ ty::ty_box(actual_mt) {
+ let mut;
+ alt unify_mut(expected_mt.mut, actual_mt.mut) {
+ none. { ret ures_err(terr_box_mutability); }
+ some(m) { mut = m; }
+ }
+ let result = unify_step(cx, expected_mt.ty, actual_mt.ty);
+ alt result {
+ ures_ok(result_sub) {
+ let mt = {ty: result_sub, mut: mut};
+ ret ures_ok(mk_box(cx.tcx, mt));
+ }
+ _ { ret result; }
+ }
+ }
+ _ { ret ures_err(terr_mismatch); }
+ }
+ }
+ ty::ty_vec(expected_mt) {
+ alt struct(cx.tcx, actual) {
+ ty::ty_vec(actual_mt) {
+ let mut;
+ alt unify_mut(expected_mt.mut, actual_mt.mut) {
+ none. { ret ures_err(terr_vec_mutability); }
+ some(m) { mut = m; }
+ }
+ let result = unify_step(cx, expected_mt.ty, actual_mt.ty);
+ alt result {
+ ures_ok(result_sub) {
+ let mt = {ty: result_sub, mut: mut};
+ ret ures_ok(mk_vec(cx.tcx, mt));
+ }
+ _ { ret result; }
+ }
+ }
+ _ { ret ures_err(terr_mismatch); }
+ }
+ }
+ ty::ty_ivec(expected_mt) {
+ alt struct(cx.tcx, actual) {
+ ty::ty_ivec(actual_mt) {
+ let mut;
+ alt unify_mut(expected_mt.mut, actual_mt.mut) {
+ none. { ret ures_err(terr_vec_mutability); }
+ some(m) { mut = m; }
+ }
+ let result = unify_step(cx, expected_mt.ty, actual_mt.ty);
+ alt result {
+ ures_ok(result_sub) {
+ let mt = {ty: result_sub, mut: mut};
+ ret ures_ok(mk_ivec(cx.tcx, mt));
+ }
+ _ { ret result; }
+ }
+ }
+ _ { ret ures_err(terr_mismatch); }
+ }
+ }
+ ty::ty_ptr(expected_mt) {
+ alt struct(cx.tcx, actual) {
+ ty::ty_ptr(actual_mt) {
+ let mut;
+ alt unify_mut(expected_mt.mut, actual_mt.mut) {
+ none. { ret ures_err(terr_vec_mutability); }
+ some(m) { mut = m; }
+ }
+ let result = unify_step(cx, expected_mt.ty, actual_mt.ty);
+ alt result {
+ ures_ok(result_sub) {
+ let mt = {ty: result_sub, mut: mut};
+ ret ures_ok(mk_ptr(cx.tcx, mt));
+ }
+ _ { ret result; }
+ }
+ }
+ _ { ret ures_err(terr_mismatch); }
+ }
+ }
+ ty::ty_port(expected_sub) {
+ alt struct(cx.tcx, actual) {
+ ty::ty_port(actual_sub) {
+ let result = unify_step(cx, expected_sub, actual_sub);
+ alt result {
+ ures_ok(result_sub) {
+ ret ures_ok(mk_port(cx.tcx, result_sub));
+ }
+ _ { ret result; }
+ }
+ }
+ _ { ret ures_err(terr_mismatch); }
+ }
+ }
+ ty::ty_res(ex_id, ex_inner, ex_tps) {
+ alt struct(cx.tcx, actual) {
+ ty::ty_res(act_id, act_inner, act_tps) {
+ if ex_id.crate != act_id.crate || ex_id.node != act_id.node {
+ ret ures_err(terr_mismatch);
+ }
+ let result = unify_step(cx, ex_inner, act_inner);
+ alt result {
+ ures_ok(res_inner) {
+ let i = 0u;
+ let res_tps = ~[];
+ for ex_tp: t in ex_tps {
+ let result = unify_step(cx, ex_tp, act_tps.(i));
+ alt result {
+ ures_ok(rty) { res_tps += ~[rty]; }
+ _ { ret result; }
}
- ret ures_ok(mk_rec(cx.tcx, result_fields));
+ i += 1u;
}
- case (_) { ret ures_err(terr_mismatch); }
+ ret ures_ok(mk_res(cx.tcx, act_id, res_inner, res_tps));
+ }
+ _ { ret result; }
}
+ }
+ _ { ret ures_err(terr_mismatch); }
}
- case (ty::ty_fn(?ep, ?expected_inputs, ?expected_output,
- ?expected_cf, ?expected_constrs)) {
- alt (struct(cx.tcx, actual)) {
- case (ty::ty_fn(?ap, ?actual_inputs, ?actual_output,
- ?actual_cf, ?actual_constrs)) {
- ret unify_fn(cx, ep, ap, expected, actual,
- expected_inputs, expected_output,
- actual_inputs, actual_output,
- expected_cf, actual_cf, expected_constrs,
- actual_constrs);
- }
- case (_) { ret ures_err(terr_mismatch); }
+ }
+ ty::ty_chan(expected_sub) {
+ alt struct(cx.tcx, actual) {
+ ty::ty_chan(actual_sub) {
+ let result = unify_step(cx, expected_sub, actual_sub);
+ alt result {
+ ures_ok(result_sub) {
+ ret ures_ok(mk_chan(cx.tcx, result_sub));
+ }
+ _ { ret result; }
}
+ }
+ _ { ret ures_err(terr_mismatch); }
}
- case (ty::ty_native_fn(?e_abi, ?expected_inputs,
- ?expected_output)) {
- alt (struct(cx.tcx, actual)) {
- case (ty::ty_native_fn(?a_abi, ?actual_inputs,
- ?actual_output)) {
- ret unify_native_fn(cx, e_abi, a_abi, expected,
- actual, expected_inputs,
- expected_output, actual_inputs,
- actual_output);
- }
- case (_) { ret ures_err(terr_mismatch); }
+ }
+ ty::ty_rec(expected_fields) {
+ alt struct(cx.tcx, actual) {
+ ty::ty_rec(actual_fields) {
+ let expected_len = ivec::len[field](expected_fields);
+ let actual_len = ivec::len[field](actual_fields);
+ if expected_len != actual_len {
+ let err = terr_record_size(expected_len, actual_len);
+ ret ures_err(err);
}
- }
- case (ty::ty_obj(?expected_meths)) {
- alt (struct(cx.tcx, actual)) {
- case (ty::ty_obj(?actual_meths)) {
- ret unify_obj(cx, expected, actual, expected_meths,
- actual_meths);
+ // TODO: implement an iterator that can iterate over
+ // two arrays simultaneously.
+
+ let result_fields: field[] = ~[];
+ let i = 0u;
+ while i < expected_len {
+ let expected_field = expected_fields.(i);
+ let actual_field = actual_fields.(i);
+ let mut;
+ alt unify_mut(expected_field.mt.mut, actual_field.mt.mut)
+ {
+ none. { ret ures_err(terr_record_mutability); }
+ some(m) { mut = m; }
}
- case (_) { ret ures_err(terr_mismatch); }
+ if !str::eq(expected_field.ident, actual_field.ident) {
+ let err =
+ terr_record_fields(expected_field.ident,
+ actual_field.ident);
+ ret ures_err(err);
+ }
+ let result =
+ unify_step(cx, expected_field.mt.ty,
+ actual_field.mt.ty);
+ alt result {
+ ures_ok(rty) {
+ let mt = {ty: rty, mut: mut};
+ result_fields += ~[{mt: mt with expected_field}];
+ }
+ _ { ret result; }
+ }
+ i += 1u;
}
+ ret ures_ok(mk_rec(cx.tcx, result_fields));
+ }
+ _ { ret ures_err(terr_mismatch); }
}
- case (ty::ty_constr(?expected_t, ?expected_constrs)) {
- // unify the base types...
- alt (struct(cx.tcx, actual)) {
- case (ty::ty_constr(?actual_t, ?actual_constrs)) {
- auto rslt = unify_step(cx, expected_t, actual_t);
- alt (rslt) {
- case (ures_ok(?rty)) {
- // FIXME: probably too restrictive --
- // requires the constraints to be
- // syntactically equal
- ret unify_constrs(expected,
- expected_constrs,
- actual_constrs);
- }
- case (_) { ret rslt; }
- }
- }
- case (_) {
- // If the actual type is *not* a constrained type,
- // then we go ahead and just ignore the constraints on
- // the expected type. typestate handles the rest.
- ret unify_step(cx, expected_t, actual);
- }
+ }
+ ty::ty_fn(ep, expected_inputs, expected_output, expected_cf,
+ expected_constrs) {
+ alt struct(cx.tcx, actual) {
+ ty::ty_fn(ap, actual_inputs, actual_output, actual_cf,
+ actual_constrs) {
+ ret unify_fn(cx, ep, ap, expected, actual, expected_inputs,
+ expected_output, actual_inputs, actual_output,
+ expected_cf, actual_cf, expected_constrs,
+ actual_constrs);
+ }
+ _ { ret ures_err(terr_mismatch); }
+ }
+ }
+ ty::ty_native_fn(e_abi, expected_inputs, expected_output) {
+ alt struct(cx.tcx, actual) {
+ ty::ty_native_fn(a_abi, actual_inputs, actual_output) {
+ ret unify_native_fn(cx, e_abi, a_abi, expected, actual,
+ expected_inputs, expected_output,
+ actual_inputs, actual_output);
+ }
+ _ { ret ures_err(terr_mismatch); }
+ }
+ }
+ ty::ty_obj(expected_meths) {
+ alt struct(cx.tcx, actual) {
+ ty::ty_obj(actual_meths) {
+ ret unify_obj(cx, expected, actual, expected_meths,
+ actual_meths);
+ }
+ _ { ret ures_err(terr_mismatch); }
+ }
+ }
+ ty::ty_constr(expected_t, expected_constrs) {
+
+ // unify the base types...
+ alt struct(cx.tcx, actual) {
+ ty::ty_constr(actual_t, actual_constrs) {
+ let rslt = unify_step(cx, expected_t, actual_t);
+ alt rslt {
+ ures_ok(rty) {
+ // FIXME: probably too restrictive --
+ // requires the constraints to be
+ // syntactically equal
+ ret unify_constrs(expected, expected_constrs,
+ actual_constrs);
+ }
+ _ { ret rslt; }
}
+ }
+ _ {
+ // If the actual type is *not* a constrained type,
+ // then we go ahead and just ignore the constraints on
+ // the expected type. typestate handles the rest.
+ ret unify_step(cx, expected_t, actual);
+ }
}
+ }
}
}
- fn unify(&t expected, &t actual, &@var_bindings vb, &ty_ctxt tcx) ->
+ fn unify(expected: &t, actual: &t, vb: &@var_bindings, tcx: &ty_ctxt) ->
result {
- auto cx = @rec(vb=vb, tcx=tcx);
+ let cx = @{vb: vb, tcx: tcx};
ret unify_step(cx, expected, actual);
}
- fn dump_var_bindings(ty_ctxt tcx, @var_bindings vb) {
- auto i = 0u;
- while (i < ivec::len[ufindivec::node](vb.sets.nodes)) {
- auto sets = "";
- auto j = 0u;
- while (j < ivec::len[option::t[uint]](vb.sets.nodes)) {
- if (ufindivec::find(vb.sets, j) == i) {
+ fn dump_var_bindings(tcx: ty_ctxt, vb: @var_bindings) {
+ let i = 0u;
+ while i < ivec::len[ufindivec::node](vb.sets.nodes) {
+ let sets = "";
+ let j = 0u;
+ while j < ivec::len[option::t[uint]](vb.sets.nodes) {
+ if ufindivec::find(vb.sets, j) == i {
sets += #fmt(" %u", j);
}
j += 1u;
}
- auto typespec;
- alt (smallintmap::find[t](vb.types, i)) {
- case (none) { typespec = ""; }
- case (some(?typ)) {
- typespec = " =" + ty_to_str(tcx, typ);
- }
+ let typespec;
+ alt smallintmap::find[t](vb.types, i) {
+ none. { typespec = ""; }
+ some(typ) { typespec = " =" + ty_to_str(tcx, typ); }
}
log_err #fmt("set %u:%s%s", i, typespec, sets);
i += 1u;
@@ -2649,203 +2496,187 @@
}
// Fixups and substitutions
- fn fixup_vars(ty_ctxt tcx, @var_bindings vb, t typ) -> fixup_result {
- fn subst_vars(ty_ctxt tcx, @var_bindings vb,
- @mutable option::t[int] unresolved, int vid) -> t {
- if (vid as uint >= ufindivec::set_count(vb.sets)) {
+ fn fixup_vars(tcx: ty_ctxt, vb: @var_bindings, typ: t) -> fixup_result {
+ fn subst_vars(tcx: ty_ctxt, vb: @var_bindings,
+ unresolved: @mutable option::t[int], vid: int) -> t {
+ if vid as uint >= ufindivec::set_count(vb.sets) {
*unresolved = some(vid);
ret ty::mk_var(tcx, vid);
}
- auto root_id = ufindivec::find(vb.sets, vid as uint);
- alt (smallintmap::find[t](vb.types, root_id)) {
- case (none) {
- *unresolved = some(vid);
- ret ty::mk_var(tcx, vid);
- }
- case (some(?rt)) {
- ret fold_ty(tcx,
- fm_var(bind subst_vars(tcx, vb, unresolved,
- _)), rt);
- }
+ let root_id = ufindivec::find(vb.sets, vid as uint);
+ alt smallintmap::find[t](vb.types, root_id) {
+ none. { *unresolved = some(vid); ret ty::mk_var(tcx, vid); }
+ some(rt) {
+ ret fold_ty(tcx,
+ fm_var(bind subst_vars(tcx, vb, unresolved, _)),
+ rt);
+ }
}
}
- auto unresolved = @mutable none[int];
- auto rty =
+ let unresolved = @mutable none[int];
+ let rty =
fold_ty(tcx, fm_var(bind subst_vars(tcx, vb, unresolved, _)),
typ);
- auto ur = *unresolved;
- alt (ur) {
- case (none) { ret fix_ok(rty); }
- case (some(?var_id)) { ret fix_err(var_id); }
+ let ur = *unresolved;
+ alt ur {
+ none. { ret fix_ok(rty); }
+ some(var_id) { ret fix_err(var_id); }
}
}
- fn resolve_type_var(&ty_ctxt tcx, &@var_bindings vb, int vid) ->
+ fn resolve_type_var(tcx: &ty_ctxt, vb: &@var_bindings, vid: int) ->
fixup_result {
- if (vid as uint >= ufindivec::set_count(vb.sets)) {
- ret fix_err(vid);
- }
- auto root_id = ufindivec::find(vb.sets, vid as uint);
- alt (smallintmap::find[t](vb.types, root_id)) {
- case (none) { ret fix_err(vid); }
- case (some(?rt)) { ret fixup_vars(tcx, vb, rt); }
+ if vid as uint >= ufindivec::set_count(vb.sets) { ret fix_err(vid); }
+ let root_id = ufindivec::find(vb.sets, vid as uint);
+ alt smallintmap::find[t](vb.types, root_id) {
+ none. { ret fix_err(vid); }
+ some(rt) { ret fixup_vars(tcx, vb, rt); }
}
}
}
-fn type_err_to_str(&ty::type_err err) -> str {
- alt (err) {
- case (terr_mismatch) { ret "types differ"; }
- case (terr_controlflow_mismatch) {
- ret "returning function used where non-returning function" +
- " was expected";
- }
- case (terr_box_mutability) {
- ret "boxed values differ in mutability";
- }
- case (terr_vec_mutability) { ret "vectors differ in mutability"; }
- case (terr_record_size(?e_sz, ?a_sz)) {
- ret "expected a record with " + uint::to_str(e_sz, 10u) +
- " fields but found one with " + uint::to_str(a_sz, 10u) +
- " fields";
- }
- case (terr_record_mutability) {
- ret "record elements differ in mutability";
- }
- case (terr_record_fields(?e_fld, ?a_fld)) {
- ret "expected a record with field '" + e_fld +
- "' but found one with field '" + a_fld + "'";
- }
- case (terr_arg_count) {
- ret "incorrect number of function parameters";
- }
- case (terr_meth_count) { ret "incorrect number of object methods"; }
- case (terr_obj_meths(?e_meth, ?a_meth)) {
- ret "expected an obj with method '" + e_meth +
- "' but found one with method '" + a_meth + "'";
- }
- case (terr_mode_mismatch(?e_mode, ?a_mode)) {
- ret "expected argument mode " + mode_str_1(e_mode) + " but found "
- + mode_str_1(a_mode);
- fail;
- }
- case (terr_constr_len(?e_len, ?a_len)) {
- ret "Expected a type with " + uint::str(e_len) + " constraints, \
- but found one with " + uint::str(a_len) + " constraints";
- }
- case (terr_constr_mismatch(?e_constr, ?a_constr)) {
- ret "Expected a type with constraint "
- + ty_constr_to_str(e_constr) + " but found one with constraint "
- + ty_constr_to_str(a_constr);
- }
+fn type_err_to_str(err: &ty::type_err) -> str {
+ alt err {
+ terr_mismatch. { ret "types differ"; }
+ terr_controlflow_mismatch. {
+ ret "returning function used where non-returning function" +
+ " was expected";
+ }
+ terr_box_mutability. { ret "boxed values differ in mutability"; }
+ terr_vec_mutability. { ret "vectors differ in mutability"; }
+ terr_record_size(e_sz, a_sz) {
+ ret "expected a record with " + uint::to_str(e_sz, 10u) +
+ " fields but found one with " + uint::to_str(a_sz, 10u) +
+ " fields";
+ }
+ terr_record_mutability. { ret "record elements differ in mutability"; }
+ terr_record_fields(e_fld, a_fld) {
+ ret "expected a record with field '" + e_fld +
+ "' but found one with field '" + a_fld + "'";
+ }
+ terr_arg_count. { ret "incorrect number of function parameters"; }
+ terr_meth_count. { ret "incorrect number of object methods"; }
+ terr_obj_meths(e_meth, a_meth) {
+ ret "expected an obj with method '" + e_meth +
+ "' but found one with method '" + a_meth + "'";
+ }
+ terr_mode_mismatch(e_mode, a_mode) {
+ ret "expected argument mode " + mode_str_1(e_mode) + " but found " +
+ mode_str_1(a_mode);
+ fail;
+ }
+ terr_constr_len(e_len, a_len) {
+ ret "Expected a type with " + uint::str(e_len) +
+ " constraints, \
+ but found one with " +
+ uint::str(a_len) + " constraints";
+ }
+ terr_constr_mismatch(e_constr, a_constr) {
+ ret "Expected a type with constraint " + ty_constr_to_str(e_constr) +
+ " but found one with constraint " +
+ ty_constr_to_str(a_constr);
+ }
}
}
// Converts type parameters in a type to type variables and returns the
// resulting type along with a list of type variable IDs.
-fn bind_params_in_type(&span sp, &ctxt cx, fn() -> int next_ty_var, t typ,
- uint ty_param_count) -> rec(int[] ids, t ty) {
- let @mutable int[] param_var_ids = @mutable ~[];
- auto i = 0u;
- while (i < ty_param_count) {
- *param_var_ids += ~[next_ty_var()];
- i += 1u;
- }
- fn binder(span sp, ctxt cx, @mutable int[] param_var_ids,
- fn() -> int next_ty_var, uint index) -> t {
- if (index < ivec::len(*param_var_ids)) {
+fn bind_params_in_type(sp: &span, cx: &ctxt, next_ty_var: fn() -> int ,
+ typ: t, ty_param_count: uint) -> {ids: int[], ty: t} {
+ let param_var_ids: @mutable int[] = @mutable ~[];
+ let i = 0u;
+ while i < ty_param_count { *param_var_ids += ~[next_ty_var()]; i += 1u; }
+ fn binder(sp: span, cx: ctxt, param_var_ids: @mutable int[],
+ next_ty_var: fn() -> int , index: uint) -> t {
+ if index < ivec::len(*param_var_ids) {
ret mk_var(cx, param_var_ids.(index));
- }
- else {
+ } else {
cx.sess.span_fatal(sp, "Unbound type parameter in callee's type");
}
}
- auto new_typ =
- fold_ty(cx, fm_param(bind binder(sp, cx, param_var_ids,
- next_ty_var, _)), typ);
- ret rec(ids=*param_var_ids, ty=new_typ);
+ let new_typ =
+ fold_ty(cx,
+ fm_param(bind binder(sp, cx, param_var_ids, next_ty_var, _)),
+ typ);
+ ret {ids: *param_var_ids, ty: new_typ};
}
// Replaces type parameters in the given type using the given list of
// substitions.
-fn substitute_type_params(&ctxt cx, &ty::t[] substs, t typ) -> t {
- if (!type_contains_params(cx, typ)) { ret typ; }
- fn substituter(ctxt cx, @ty::t[] substs, uint idx) -> t {
+fn substitute_type_params(cx: &ctxt, substs: &ty::t[], typ: t) -> t {
+ if !type_contains_params(cx, typ) { ret typ; }
+ fn substituter(cx: ctxt, substs: @ty::t[], idx: uint) -> t {
// FIXME: bounds check can fail
ret substs.(idx);
}
ret fold_ty(cx, fm_param(bind substituter(cx, @substs, _)), typ);
}
-fn def_has_ty_params(&ast::def def) -> bool {
- alt (def) {
- case (ast::def_fn(_,_)) { ret true; }
- case (ast::def_obj_field(_)) { ret false; }
- case (ast::def_mod(_)) { ret false; }
- case (ast::def_const(_)) { ret false; }
- case (ast::def_arg(_)) { ret false; }
- case (ast::def_local(_)) { ret false; }
- case (ast::def_variant(_, _)) { ret true; }
- case (ast::def_ty(_)) { ret false; }
- case (ast::def_ty_arg(_)) { ret false; }
- case (ast::def_binding(_)) { ret false; }
- case (ast::def_use(_)) { ret false; }
- case (ast::def_native_ty(_)) { ret false; }
- case (ast::def_native_fn(_)) { ret true; }
+fn def_has_ty_params(def: &ast::def) -> bool {
+ alt def {
+ ast::def_fn(_, _) { ret true; }
+ ast::def_obj_field(_) { ret false; }
+ ast::def_mod(_) { ret false; }
+ ast::def_const(_) { ret false; }
+ ast::def_arg(_) { ret false; }
+ ast::def_local(_) { ret false; }
+ ast::def_variant(_, _) { ret true; }
+ ast::def_ty(_) { ret false; }
+ ast::def_ty_arg(_) { ret false; }
+ ast::def_binding(_) { ret false; }
+ ast::def_use(_) { ret false; }
+ ast::def_native_ty(_) { ret false; }
+ ast::def_native_fn(_) { ret true; }
}
}
// Tag information
-type variant_info = rec(ty::t[] args, ty::t ctor_ty, ast::def_id id);
+type variant_info = {args: ty::t[], ctor_ty: ty::t, id: ast::def_id};
-fn tag_variants(&ctxt cx, &ast::def_id id) -> variant_info[] {
- if (ast::local_crate != id.crate) {
- ret csearch::get_tag_variants(cx, id);
- }
- auto item = alt (cx.items.find(id.node)) {
- case (some(?i)) { i }
- case (none) {
- cx.sess.bug("expected to find cached node_item")
- }
- };
- alt (item) {
- case (ast_map::node_item(?item)) {
- alt (item.node) {
- case (ast::item_tag(?variants, _)) {
- let variant_info[] result = ~[];
- for (ast::variant variant in variants) {
- auto ctor_ty = node_id_to_monotype
- (cx, variant.node.id);
- let t[] arg_tys = ~[];
- if (std::ivec::len(variant.node.args) > 0u) {
- for (arg a in ty_fn_args(cx, ctor_ty)) {
- arg_tys += ~[a.ty];
- }
- }
- auto did = variant.node.id;
- result +=
- ~[rec(args=arg_tys,
- ctor_ty=ctor_ty,
- id=ast::local_def(did))];
+fn tag_variants(cx: &ctxt, id: &ast::def_id) -> variant_info[] {
+ if ast::local_crate != id.crate { ret csearch::get_tag_variants(cx, id); }
+ let item =
+ alt cx.items.find(id.node) {
+ some(i) { i }
+ none. { cx.sess.bug("expected to find cached node_item") }
+ };
+ alt item {
+ ast_map::node_item(item) {
+ alt item.node {
+ ast::item_tag(variants, _) {
+ let result: variant_info[] = ~[];
+ for variant: ast::variant in variants {
+ let ctor_ty = node_id_to_monotype(cx, variant.node.id);
+ let arg_tys: t[] = ~[];
+ if std::ivec::len(variant.node.args) > 0u {
+ for a: arg in ty_fn_args(cx, ctor_ty) {
+ arg_tys += ~[a.ty];
}
- ret result;
}
+ let did = variant.node.id;
+ result +=
+ ~[{args: arg_tys,
+ ctor_ty: ctor_ty,
+ id: ast::local_def(did)}];
}
+ ret result;
+ }
}
+ }
}
}
// Returns information about the tag variant with the given ID:
-fn tag_variant_with_id(&ctxt cx, &ast::def_id tag_id, &ast::def_id variant_id)
- -> variant_info {
- auto variants = tag_variants(cx, tag_id);
- auto i = 0u;
- while (i < ivec::len[variant_info](variants)) {
- auto variant = variants.(i);
- if (def_eq(variant.id, variant_id)) { ret variant; }
+fn tag_variant_with_id(cx: &ctxt, tag_id: &ast::def_id,
+ variant_id: &ast::def_id) -> variant_info {
+ let variants = tag_variants(cx, tag_id);
+ let i = 0u;
+ while i < ivec::len[variant_info](variants) {
+ let variant = variants.(i);
+ if def_eq(variant.id, variant_id) { ret variant; }
i += 1u;
}
cx.sess.bug("tag_variant_with_id(): no variant exists with that ID");
@@ -2854,139 +2685,143 @@
// If the given item is in an external crate, looks up its type and adds it to
// the type cache. Returns the type parameters and type.
-fn lookup_item_type(ctxt cx, ast::def_id did) -> ty_param_count_and_ty {
- if (did.crate == ast::local_crate) {
+fn lookup_item_type(cx: ctxt, did: ast::def_id) -> ty_param_count_and_ty {
+ if did.crate == ast::local_crate {
// The item is in this crate. The caller should have added it to the
// type cache already; we simply return it.
ret cx.tcache.get(did);
}
- alt (cx.tcache.find(did)) {
- case (some(?tpt)) { ret tpt; }
- case (none) {
- auto tyt = csearch::get_type(cx, did);
- cx.tcache.insert(did, tyt);
- ret tyt;
- }
+ alt cx.tcache.find(did) {
+ some(tpt) { ret tpt; }
+ none. {
+ let tyt = csearch::get_type(cx, did);
+ cx.tcache.insert(did, tyt);
+ ret tyt;
+ }
}
}
-fn ret_ty_of_fn_ty(ctxt cx, t a_ty) -> t {
- alt (ty::struct(cx, a_ty)) {
- case (ty::ty_fn(_, _, ?ret_ty, _, _)) { ret ret_ty; }
- case (ty::ty_native_fn(_, _, ?ret_ty)) { ret ret_ty; }
- case (_) {
- cx.sess.bug("ret_ty_of_fn_ty() called on non-function type: " +
+fn ret_ty_of_fn_ty(cx: ctxt, a_ty: t) -> t {
+ alt ty::struct(cx, a_ty) {
+ ty::ty_fn(_, _, ret_ty, _, _) { ret ret_ty; }
+ ty::ty_native_fn(_, _, ret_ty) { ret ret_ty; }
+ _ {
+ cx.sess.bug("ret_ty_of_fn_ty() called on non-function type: " +
ty_to_str(cx, a_ty));
- }
+ }
}
}
-fn ret_ty_of_fn(ctxt cx, ast::node_id id) -> t {
+fn ret_ty_of_fn(cx: ctxt, id: ast::node_id) -> t {
ret ret_ty_of_fn_ty(cx, node_id_to_type(cx, id));
}
-fn is_binopable(&ctxt cx, t ty, ast::binop op) -> bool {
+fn is_binopable(cx: &ctxt, ty: t, op: ast::binop) -> bool {
- const int tycat_other = 0;
- const int tycat_bool = 1;
- const int tycat_int = 2;
- const int tycat_float = 3;
- const int tycat_str = 4;
- const int tycat_vec = 5;
- const int tycat_struct = 6;
+ const tycat_other: int = 0;
+ const tycat_bool: int = 1;
+ const tycat_int: int = 2;
+ const tycat_float: int = 3;
+ const tycat_str: int = 4;
+ const tycat_vec: int = 5;
+ const tycat_struct: int = 6;
- const int opcat_add = 0;
- const int opcat_sub = 1;
- const int opcat_mult = 2;
- const int opcat_shift = 3;
- const int opcat_rel = 4;
- const int opcat_eq = 5;
- const int opcat_bit = 6;
- const int opcat_logic = 7;
+ const opcat_add: int = 0;
+ const opcat_sub: int = 1;
+ const opcat_mult: int = 2;
+ const opcat_shift: int = 3;
+ const opcat_rel: int = 4;
+ const opcat_eq: int = 5;
+ const opcat_bit: int = 6;
+ const opcat_logic: int = 7;
- fn opcat(ast::binop op) -> int {
- alt (op) {
- case (ast::add) { opcat_add }
- case (ast::sub) { opcat_sub }
- case (ast::mul) { opcat_mult }
- case (ast::div) { opcat_mult }
- case (ast::rem) { opcat_mult }
- case (ast::and) { opcat_logic }
- case (ast::or) { opcat_logic }
- case (ast::bitxor) { opcat_bit }
- case (ast::bitand) { opcat_bit }
- case (ast::bitor) { opcat_bit }
- case (ast::lsl) { opcat_shift }
- case (ast::lsr) { opcat_shift }
- case (ast::asr) { opcat_shift }
- case (ast::eq) { opcat_eq }
- case (ast::ne) { opcat_eq }
- case (ast::lt) { opcat_rel }
- case (ast::le) { opcat_rel }
- case (ast::ge) { opcat_rel }
- case (ast::gt) { opcat_rel }
+ fn opcat(op: ast::binop) -> int {
+ alt op {
+ ast::add. { opcat_add }
+ ast::sub. { opcat_sub }
+ ast::mul. { opcat_mult }
+ ast::div. { opcat_mult }
+ ast::rem. { opcat_mult }
+ ast::and. { opcat_logic }
+ ast::or. { opcat_logic }
+ ast::bitxor. { opcat_bit }
+ ast::bitand. { opcat_bit }
+ ast::bitor. { opcat_bit }
+ ast::lsl. { opcat_shift }
+ ast::lsr. { opcat_shift }
+ ast::asr. { opcat_shift }
+ ast::eq. { opcat_eq }
+ ast::ne. { opcat_eq }
+ ast::lt. { opcat_rel }
+ ast::le. { opcat_rel }
+ ast::ge. { opcat_rel }
+ ast::gt. { opcat_rel }
}
}
- fn tycat(&ctxt cx, t ty) -> int {
- alt (struct(cx, ty)) {
- case (ty_bool) { tycat_bool }
- case (ty_int) { tycat_int }
- case (ty_uint) { tycat_int }
- case (ty_machine(ast::ty_i8)) { tycat_int }
- case (ty_machine(ast::ty_i16)) { tycat_int }
- case (ty_machine(ast::ty_i32)) { tycat_int }
- case (ty_machine(ast::ty_i64)) { tycat_int }
- case (ty_machine(ast::ty_u8)) { tycat_int }
- case (ty_machine(ast::ty_u16)) { tycat_int }
- case (ty_machine(ast::ty_u32)) { tycat_int }
- case (ty_machine(ast::ty_u64)) { tycat_int }
- case (ty_float) { tycat_float }
- case (ty_machine(ast::ty_f32)) { tycat_float }
- case (ty_machine(ast::ty_f64)) { tycat_float }
- case (ty_char) { tycat_int }
- case (ty_ptr(_)) { tycat_int }
- case (ty_str) { tycat_str }
- case (ty_istr) { tycat_str }
- case (ty_vec(_)) { tycat_vec }
- case (ty_ivec(_)) { tycat_vec }
- case (ty_rec(_)) { tycat_struct }
- case (ty_tag(_, _)) { tycat_struct }
- case (_) { tycat_other }
+ fn tycat(cx: &ctxt, ty: t) -> int {
+ alt struct(cx, ty) {
+ ty_bool. { tycat_bool }
+ ty_int. { tycat_int }
+ ty_uint. { tycat_int }
+ ty_machine(ast::ty_i8.) { tycat_int }
+ ty_machine(ast::ty_i16.) { tycat_int }
+ ty_machine(ast::ty_i32.) { tycat_int }
+ ty_machine(ast::ty_i64.) { tycat_int }
+ ty_machine(ast::ty_u8.) { tycat_int }
+ ty_machine(ast::ty_u16.) { tycat_int }
+ ty_machine(ast::ty_u32.) { tycat_int }
+ ty_machine(ast::ty_u64.) { tycat_int }
+ ty_float. { tycat_float }
+ ty_machine(ast::ty_f32.) { tycat_float }
+ ty_machine(ast::ty_f64.) { tycat_float }
+ ty_char. { tycat_int }
+ ty_ptr(_) { tycat_int }
+ ty_str. { tycat_str }
+ ty_istr. { tycat_str }
+ ty_vec(_) { tycat_vec }
+ ty_ivec(_) { tycat_vec }
+ ty_rec(_) { tycat_struct }
+ ty_tag(_, _) { tycat_struct }
+ _ { tycat_other }
}
}
- const bool t = true;
- const bool f = false;
+ const t: bool = true;
+ const f: bool = false;
/*. add, shift, bit
. sub, rel, logic
. mult, eq, */
- auto tbl = [[f, f, f, f, t, t, f, f], /*other*/
- [f, f, f, f, t, t, t, t], /*bool*/
- [t, t, t, t, t, t, t, f], /*int*/
- [t, t, t, f, t, t, f, f], /*float*/
- [t, f, f, f, t, t, f, f], /*str*/
- [t, f, f, f, t, t, f, f], /*vec*/
- [f, f, f, f, t, t, f, f]];/*struct*/
+ let /*other*/
+ /*bool*/
+ /*int*/
+ /*float*/
+ /*str*/
+ /*vec*/
+ tbl =
+ [[f, f, f, f, t, t, f, f], [f, f, f, f, t, t, t, t],
+ [t, t, t, t, t, t, t, f], [t, t, t, f, t, t, f, f],
+ [t, f, f, f, t, t, f, f], [t, f, f, f, t, t, f, f],
+ [f, f, f, f, t, t, f, f]]; /*struct*/
ret tbl.(tycat(cx, ty)).(opcat(op));
}
-fn ast_constr_to_constr[T](ty::ctxt tcx, &@ast::constr_general[T] c)
- -> @ty::constr_general[T] {
- alt (tcx.def_map.find(c.node.id)) {
- case (some(ast::def_fn(?pred_id, ast::pure_fn))) {
- ret @respan(c.span, rec(path=c.node.path, args=c.node.args,
- id=pred_id));
- }
- case (_) {
- tcx.sess.span_fatal(c.span, "Predicate "
- + path_to_str(c.node.path)
- + " is unbound or bound to a non-function or an \
+fn ast_constr_to_constr[T](tcx: ty::ctxt, c: &@ast::constr_general[T]) ->
+ @ty::constr_general[T] {
+ alt tcx.def_map.find(c.node.id) {
+ some(ast::def_fn(pred_id, ast::pure_fn.)) {
+ ret @respan(c.span,
+ {path: c.node.path, args: c.node.args, id: pred_id});
+ }
+ _ {
+ tcx.sess.span_fatal(c.span,
+ "Predicate " + path_to_str(c.node.path) +
+ " is unbound or bound to a non-function or an \
impure function");
- }
+ }
}
}
diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs
index a205ebf..432930b 100644
--- a/src/comp/middle/typeck.rs
+++ b/src/comp/middle/typeck.rs
@@ -53,212 +53,206 @@
// Used for typechecking the methods of an object.
tag obj_info {
+
// Regular objects have a node_id at compile time.
regular_obj(ast::obj_field[], ast::node_id);
+
// Anonymous objects only have a type at compile time. It's optional
// because not all anonymous objects have a with_obj to attach to.
anon_obj(ast::obj_field[], option::t[ty::sty]);
}
-type crate_ctxt = rec(mutable obj_info[] obj_infos, ty::ctxt tcx);
+type crate_ctxt = {mutable obj_infos: obj_info[], tcx: ty::ctxt};
type fn_ctxt =
- rec(ty::t ret_ty,
- ast::purity purity,
- // var_bindings, locals, local_names, and next_var_id are shared
- // with any nested functions that capture the environment
- // (and with any functions whose environment is being captured).
- @ty::unify::var_bindings var_bindings,
- hashmap[ast::node_id, int] locals,
- hashmap[ast::node_id, ast::ident] local_names,
- @mutable int next_var_id,
- mutable ast::node_id[] fixups,
- @crate_ctxt ccx);
+ // var_bindings, locals, local_names, and next_var_id are shared
+ // with any nested functions that capture the environment
+ // (and with any functions whose environment is being captured).
+ {ret_ty: ty::t,
+ purity: ast::purity,
+ var_bindings: @ty::unify::var_bindings,
+ locals: hashmap[ast::node_id, int],
+ local_names: hashmap[ast::node_id, ast::ident],
+ next_var_id: @mutable int,
+ mutable fixups: ast::node_id[],
+ ccx: @crate_ctxt};
// Used for ast_ty_to_ty() below.
-type ty_getter = fn(&ast::def_id) -> ty::ty_param_count_and_ty;
+type ty_getter = fn(&ast::def_id) -> ty::ty_param_count_and_ty ;
-fn lookup_local(&@fn_ctxt fcx, &span sp, ast::node_id id) -> int {
- alt (fcx.locals.find(id)) {
- case (some(?x)) { x }
- case (_) {
- fcx.ccx.tcx.sess.span_fatal(sp, "internal error looking up a \
+fn lookup_local(fcx: &@fn_ctxt, sp: &span, id: ast::node_id) -> int {
+ alt fcx.locals.find(id) {
+ some(x) { x }
+ _ {
+ fcx.ccx.tcx.sess.span_fatal(sp,
+ "internal error looking up a \
local var")
- }
+ }
}
}
-fn lookup_def(&@fn_ctxt fcx, &span sp, ast::node_id id) -> ast::def {
- alt (fcx.ccx.tcx.def_map.find(id)) {
- case (some(?x)) { x }
- case (_) {
- fcx.ccx.tcx.sess.span_fatal(sp, "internal error looking up \
+fn lookup_def(fcx: &@fn_ctxt, sp: &span, id: ast::node_id) -> ast::def {
+ alt fcx.ccx.tcx.def_map.find(id) {
+ some(x) { x }
+ _ {
+ fcx.ccx.tcx.sess.span_fatal(sp,
+ "internal error looking up \
a definition")
- }
+ }
}
}
// Returns the type parameter count and the type for the given definition.
-fn ty_param_count_and_ty_for_def(&@fn_ctxt fcx, &span sp, &ast::def defn) ->
- ty_param_count_and_ty {
- alt (defn) {
- case (ast::def_arg(?id)) {
- assert (fcx.locals.contains_key(id.node));
- auto typ = ty::mk_var(fcx.ccx.tcx,
- lookup_local(fcx, sp, id.node));
- ret rec(count=0u, ty=typ);
- }
- case (ast::def_local(?id)) {
- assert (fcx.locals.contains_key(id.node));
- auto typ = ty::mk_var(fcx.ccx.tcx,
- lookup_local(fcx, sp, id.node));
- ret rec(count=0u, ty=typ);
- }
- case (ast::def_obj_field(?id)) {
- assert (fcx.locals.contains_key(id.node));
- auto typ = ty::mk_var(fcx.ccx.tcx,
- lookup_local(fcx, sp, id.node));
- ret rec(count=0u, ty=typ);
- }
- case (ast::def_fn(?id, _)) {
- ret ty::lookup_item_type(fcx.ccx.tcx, id);
- }
- case (ast::def_native_fn(?id)) {
- ret ty::lookup_item_type(fcx.ccx.tcx, id);
- }
- case (ast::def_const(?id)) {
- ret ty::lookup_item_type(fcx.ccx.tcx, id);
- }
- case (ast::def_variant(_, ?vid)) {
- ret ty::lookup_item_type(fcx.ccx.tcx, vid);
- }
- case (ast::def_binding(?id)) {
- assert (fcx.locals.contains_key(id.node));
- auto typ = ty::mk_var(fcx.ccx.tcx,
- lookup_local(fcx, sp, id.node));
- ret rec(count=0u, ty=typ);
- }
- case (ast::def_mod(_)) {
- // Hopefully part of a path.
- // TODO: return a type that's more poisonous, perhaps?
+fn ty_param_count_and_ty_for_def(fcx: &@fn_ctxt, sp: &span, defn: &ast::def)
+ -> ty_param_count_and_ty {
+ alt defn {
+ ast::def_arg(id) {
+ assert (fcx.locals.contains_key(id.node));
+ let typ = ty::mk_var(fcx.ccx.tcx, lookup_local(fcx, sp, id.node));
+ ret {count: 0u, ty: typ};
+ }
+ ast::def_local(id) {
+ assert (fcx.locals.contains_key(id.node));
+ let typ = ty::mk_var(fcx.ccx.tcx, lookup_local(fcx, sp, id.node));
+ ret {count: 0u, ty: typ};
+ }
+ ast::def_obj_field(id) {
+ assert (fcx.locals.contains_key(id.node));
+ let typ = ty::mk_var(fcx.ccx.tcx, lookup_local(fcx, sp, id.node));
+ ret {count: 0u, ty: typ};
+ }
+ ast::def_fn(id, _) { ret ty::lookup_item_type(fcx.ccx.tcx, id); }
+ ast::def_native_fn(id) { ret ty::lookup_item_type(fcx.ccx.tcx, id); }
+ ast::def_const(id) { ret ty::lookup_item_type(fcx.ccx.tcx, id); }
+ ast::def_variant(_, vid) { ret ty::lookup_item_type(fcx.ccx.tcx, vid); }
+ ast::def_binding(id) {
+ assert (fcx.locals.contains_key(id.node));
+ let typ = ty::mk_var(fcx.ccx.tcx, lookup_local(fcx, sp, id.node));
+ ret {count: 0u, ty: typ};
+ }
+ ast::def_mod(_) {
+ // Hopefully part of a path.
+ // TODO: return a type that's more poisonous, perhaps?
- ret rec(count=0u, ty=ty::mk_nil(fcx.ccx.tcx));
- }
- case (ast::def_ty(_)) {
- fcx.ccx.tcx.sess.span_fatal(sp, "expected value but found type");
- }
- case (_) {
- // FIXME: handle other names.
+ ret {count: 0u, ty: ty::mk_nil(fcx.ccx.tcx)};
+ }
+ ast::def_ty(_) {
+ fcx.ccx.tcx.sess.span_fatal(sp, "expected value but found type");
+ }
+ _ {
+ // FIXME: handle other names.
- fcx.ccx.tcx.sess.unimpl("definition variant");
- }
+ fcx.ccx.tcx.sess.unimpl("definition variant");
+ }
}
}
// Instantiates the given path, which must refer to an item with the given
// number of type parameters and type.
-fn instantiate_path(&@fn_ctxt fcx, &ast::path pth, &ty_param_count_and_ty tpt,
- &span sp) -> ty_param_substs_opt_and_ty {
- auto ty_param_count = tpt.count;
- auto bind_result =
+fn instantiate_path(fcx: &@fn_ctxt, pth: &ast::path,
+ tpt: &ty_param_count_and_ty, sp: &span) ->
+ ty_param_substs_opt_and_ty {
+ let ty_param_count = tpt.count;
+ let bind_result =
bind_params_in_type(sp, fcx.ccx.tcx, bind next_ty_var_id(fcx), tpt.ty,
ty_param_count);
- auto ty_param_vars = bind_result.ids;
- auto ty_substs_opt;
- auto ty_substs_len = ivec::len[@ast::ty](pth.node.types);
- if (ty_substs_len > 0u) {
- auto param_var_len = ivec::len(ty_param_vars);
- if (param_var_len == 0u) {
- fcx.ccx.tcx.sess.span_fatal
- (sp, "this item does not take type parameters");
+ let ty_param_vars = bind_result.ids;
+ let ty_substs_opt;
+ let ty_substs_len = ivec::len[@ast::ty](pth.node.types);
+ if ty_substs_len > 0u {
+ let param_var_len = ivec::len(ty_param_vars);
+ if param_var_len == 0u {
+ fcx.ccx.tcx.sess.span_fatal(sp,
+ "this item does not take type parameters");
} else if (ty_substs_len > param_var_len) {
- fcx.ccx.tcx.sess.span_fatal
- (sp, "too many type parameter provided for this item");
+ fcx.ccx.tcx.sess.span_fatal(sp,
+ "too many type parameter provided for this item");
} else if (ty_substs_len < param_var_len) {
- fcx.ccx.tcx.sess.span_fatal
- (sp, "not enough type parameters provided for this item");
+ fcx.ccx.tcx.sess.span_fatal(sp,
+ "not enough type parameters provided for this item");
}
- let ty::t[] ty_substs = ~[];
- auto i = 0u;
- while (i < ty_substs_len) {
- auto ty_var = ty::mk_var(fcx.ccx.tcx, ty_param_vars.(i));
- auto ty_subst = ast_ty_to_ty_crate(fcx.ccx, pth.node.types.(i));
- auto res_ty = demand::simple(fcx, pth.span, ty_var, ty_subst);
+ let ty_substs: ty::t[] = ~[];
+ let i = 0u;
+ while i < ty_substs_len {
+ let ty_var = ty::mk_var(fcx.ccx.tcx, ty_param_vars.(i));
+ let ty_subst = ast_ty_to_ty_crate(fcx.ccx, pth.node.types.(i));
+ let res_ty = demand::simple(fcx, pth.span, ty_var, ty_subst);
ty_substs += ~[res_ty];
i += 1u;
}
ty_substs_opt = some[ty::t[]](ty_substs);
- if (ty_param_count == 0u) {
+ if ty_param_count == 0u {
fcx.ccx.tcx.sess.span_fatal(sp,
- "this item does not take type \
+ "this item does not take type \
parameters");
fail;
}
} else {
// We will acquire the type parameters through unification.
- let ty::t[] ty_substs = ~[];
- auto i = 0u;
- while (i < ty_param_count) {
+ let ty_substs: ty::t[] = ~[];
+ let i = 0u;
+ while i < ty_param_count {
ty_substs += ~[ty::mk_var(fcx.ccx.tcx, ty_param_vars.(i))];
i += 1u;
}
ty_substs_opt = some[ty::t[]](ty_substs);
}
- ret rec(substs=ty_substs_opt, ty=tpt.ty);
+ ret {substs: ty_substs_opt, ty: tpt.ty};
}
-fn ast_mode_to_mode(ast::mode mode) -> ty::mode {
- auto ty_mode;
- alt (mode) {
- case (ast::val) { ty_mode = mo_val; }
- case (ast::alias(?mut)) { ty_mode = mo_alias(mut); }
+fn ast_mode_to_mode(mode: ast::mode) -> ty::mode {
+ let ty_mode;
+ alt mode {
+ ast::val. { ty_mode = mo_val; }
+ ast::alias(mut) { ty_mode = mo_alias(mut); }
}
ret ty_mode;
}
// Type tests
-fn structurally_resolved_type(&@fn_ctxt fcx, &span sp, ty::t typ) -> ty::t {
- auto r =
+fn structurally_resolved_type(fcx: &@fn_ctxt, sp: &span, typ: ty::t) ->
+ ty::t {
+ let r =
ty::unify::resolve_type_structure(fcx.ccx.tcx, fcx.var_bindings, typ);
- alt (r) {
- case (fix_ok(?typ_s)) { ret typ_s; }
- case (fix_err(_)) {
- fcx.ccx.tcx.sess.span_fatal(sp,
- "the type of this value must be \
+ alt r {
+ fix_ok(typ_s) { ret typ_s; }
+ fix_err(_) {
+ fcx.ccx.tcx.sess.span_fatal(sp,
+ "the type of this value must be \
known in this context");
- }
+ }
}
}
// Returns the one-level-deep structure of the given type.
-fn structure_of(&@fn_ctxt fcx, &span sp, ty::t typ) -> ty::sty {
+fn structure_of(fcx: &@fn_ctxt, sp: &span, typ: ty::t) -> ty::sty {
ret ty::struct(fcx.ccx.tcx, structurally_resolved_type(fcx, sp, typ));
}
// Returns the one-level-deep structure of the given type or none if it
// is not known yet.
-fn structure_of_maybe(&@fn_ctxt fcx, &span sp, ty::t typ)
- -> option::t[ty::sty] {
- auto r =
+fn structure_of_maybe(fcx: &@fn_ctxt, sp: &span, typ: ty::t) ->
+ option::t[ty::sty] {
+ let r =
ty::unify::resolve_type_structure(fcx.ccx.tcx, fcx.var_bindings, typ);
- ret alt (r) {
- case (fix_ok(?typ_s)) { some(ty::struct(fcx.ccx.tcx, typ_s)) }
- case (fix_err(_)) { none }
- }
+ ret alt r {
+ fix_ok(typ_s) { some(ty::struct(fcx.ccx.tcx, typ_s)) }
+ fix_err(_) { none }
+ }
}
-fn type_is_integral(&@fn_ctxt fcx, &span sp, ty::t typ) -> bool {
- auto typ_s = structurally_resolved_type(fcx, sp, typ);
+fn type_is_integral(fcx: &@fn_ctxt, sp: &span, typ: ty::t) -> bool {
+ let typ_s = structurally_resolved_type(fcx, sp, typ);
ret ty::type_is_integral(fcx.ccx.tcx, typ_s);
}
-fn type_is_scalar(&@fn_ctxt fcx, &span sp, ty::t typ) -> bool {
- auto typ_s = structurally_resolved_type(fcx, sp, typ);
+fn type_is_scalar(fcx: &@fn_ctxt, sp: &span, typ: ty::t) -> bool {
+ let typ_s = structurally_resolved_type(fcx, sp, typ);
ret ty::type_is_scalar(fcx.ccx.tcx, typ_s);
}
@@ -266,161 +260,159 @@
// Parses the programmer's textual representation of a type into our internal
// notion of a type. `getter` is a function that returns the type
// corresponding to a definition ID:
-fn ast_ty_to_ty(&ty::ctxt tcx, &ty_getter getter, &@ast::ty ast_ty) -> ty::t {
- alt (tcx.ast_ty_to_ty_cache.find(ast_ty)) {
- case (some(some(?ty))) { ret ty; }
- case (some(none)) {
- tcx.sess.span_fatal(ast_ty.span,
- "illegal recursive type \
+fn ast_ty_to_ty(tcx: &ty::ctxt, getter: &ty_getter, ast_ty: &@ast::ty) ->
+ ty::t {
+ alt tcx.ast_ty_to_ty_cache.find(ast_ty) {
+ some(some(ty)) { ret ty; }
+ some(none.) {
+ tcx.sess.span_fatal(ast_ty.span,
+ "illegal recursive type \
insert a tag in the cycle, \
if this is desired)");
- }
- case (none) { }
+ }
+ none. { }
} /* go on */
tcx.ast_ty_to_ty_cache.insert(ast_ty, none[ty::t]);
- fn ast_arg_to_arg(&ty::ctxt tcx, &ty_getter getter, &ast::ty_arg arg) ->
- rec(ty::mode mode, ty::t ty) {
- auto ty_mode = ast_mode_to_mode(arg.node.mode);
- ret rec(mode=ty_mode, ty=ast_ty_to_ty(tcx, getter, arg.node.ty));
+ fn ast_arg_to_arg(tcx: &ty::ctxt, getter: &ty_getter, arg: &ast::ty_arg)
+ -> {mode: ty::mode, ty: ty::t} {
+ let ty_mode = ast_mode_to_mode(arg.node.mode);
+ ret {mode: ty_mode, ty: ast_ty_to_ty(tcx, getter, arg.node.ty)};
}
- fn ast_mt_to_mt(&ty::ctxt tcx, &ty_getter getter, &ast::mt mt) -> ty::mt {
- ret rec(ty=ast_ty_to_ty(tcx, getter, mt.ty), mut=mt.mut);
+ fn ast_mt_to_mt(tcx: &ty::ctxt, getter: &ty_getter, mt: &ast::mt) ->
+ ty::mt {
+ ret {ty: ast_ty_to_ty(tcx, getter, mt.ty), mut: mt.mut};
}
- fn instantiate(&ty::ctxt tcx, &span sp, &ty_getter getter,
- &ast::def_id id, &(@ast::ty)[] args) -> ty::t {
+ fn instantiate(tcx: &ty::ctxt, sp: &span, getter: &ty_getter,
+ id: &ast::def_id, args: &(@ast::ty)[]) -> ty::t {
// TODO: maybe record cname chains so we can do
// "foo = int" like OCaml?
- auto params_opt_and_ty = getter(id);
- if (params_opt_and_ty.count == 0u) { ret params_opt_and_ty.ty; }
+ let params_opt_and_ty = getter(id);
+ if params_opt_and_ty.count == 0u { ret params_opt_and_ty.ty; }
// The typedef is type-parametric. Do the type substitution.
//
- let ty::t[] param_bindings = ~[];
- for (@ast::ty ast_ty in args) {
+ let param_bindings: ty::t[] = ~[];
+ for ast_ty: @ast::ty in args {
param_bindings += ~[ast_ty_to_ty(tcx, getter, ast_ty)];
}
- if (ivec::len(param_bindings) !=
- ty::count_ty_params(tcx, params_opt_and_ty.ty)) {
+ if ivec::len(param_bindings) !=
+ ty::count_ty_params(tcx, params_opt_and_ty.ty) {
tcx.sess.span_fatal(sp,
"Wrong number of type arguments for a \
polymorphic tag");
}
- auto typ =
+ let typ =
ty::substitute_type_params(tcx, param_bindings,
params_opt_and_ty.ty);
ret typ;
}
- auto typ;
- auto cname = none[str];
- alt (ast_ty.node) {
- case (ast::ty_nil) { typ = ty::mk_nil(tcx); }
- case (ast::ty_bot) { typ = ty::mk_bot(tcx); }
- case (ast::ty_bool) { typ = ty::mk_bool(tcx); }
- case (ast::ty_int) { typ = ty::mk_int(tcx); }
- case (ast::ty_uint) { typ = ty::mk_uint(tcx); }
- case (ast::ty_float) { typ = ty::mk_float(tcx); }
- case (ast::ty_machine(?tm)) { typ = ty::mk_mach(tcx, tm); }
- case (ast::ty_char) { typ = ty::mk_char(tcx); }
- case (ast::ty_str) { typ = ty::mk_str(tcx); }
- case (ast::ty_istr) { typ = ty::mk_istr(tcx); }
- case (ast::ty_box(?mt)) {
- typ = ty::mk_box(tcx, ast_mt_to_mt(tcx, getter, mt));
+ let typ;
+ let cname = none[str];
+ alt ast_ty.node {
+ ast::ty_nil. { typ = ty::mk_nil(tcx); }
+ ast::ty_bot. { typ = ty::mk_bot(tcx); }
+ ast::ty_bool. { typ = ty::mk_bool(tcx); }
+ ast::ty_int. { typ = ty::mk_int(tcx); }
+ ast::ty_uint. { typ = ty::mk_uint(tcx); }
+ ast::ty_float. { typ = ty::mk_float(tcx); }
+ ast::ty_machine(tm) { typ = ty::mk_mach(tcx, tm); }
+ ast::ty_char. { typ = ty::mk_char(tcx); }
+ ast::ty_str. { typ = ty::mk_str(tcx); }
+ ast::ty_istr. { typ = ty::mk_istr(tcx); }
+ ast::ty_box(mt) {
+ typ = ty::mk_box(tcx, ast_mt_to_mt(tcx, getter, mt));
+ }
+ ast::ty_vec(mt) {
+ typ = ty::mk_vec(tcx, ast_mt_to_mt(tcx, getter, mt));
+ }
+ ast::ty_ivec(mt) {
+ typ = ty::mk_ivec(tcx, ast_mt_to_mt(tcx, getter, mt));
+ }
+ ast::ty_ptr(mt) {
+ typ = ty::mk_ptr(tcx, ast_mt_to_mt(tcx, getter, mt));
+ }
+ ast::ty_task. { typ = ty::mk_task(tcx); }
+ ast::ty_port(t) {
+ typ = ty::mk_port(tcx, ast_ty_to_ty(tcx, getter, t));
+ }
+ ast::ty_chan(t) {
+ typ = ty::mk_chan(tcx, ast_ty_to_ty(tcx, getter, t));
+ }
+ ast::ty_rec(fields) {
+ let flds: field[] = ~[];
+ for f: ast::ty_field in fields {
+ let tm = ast_mt_to_mt(tcx, getter, f.node.mt);
+ flds += ~[{ident: f.node.ident, mt: tm}];
}
- case (ast::ty_vec(?mt)) {
- typ = ty::mk_vec(tcx, ast_mt_to_mt(tcx, getter, mt));
+ typ = ty::mk_rec(tcx, flds);
+ }
+ ast::ty_fn(proto, inputs, output, cf, constrs) {
+ let i = ~[];
+ for ta: ast::ty_arg in inputs {
+ i += ~[ast_arg_to_arg(tcx, getter, ta)];
}
- case (ast::ty_ivec(?mt)) {
- typ = ty::mk_ivec(tcx, ast_mt_to_mt(tcx, getter, mt));
- }
- case (ast::ty_ptr(?mt)) {
- typ = ty::mk_ptr(tcx, ast_mt_to_mt(tcx, getter, mt));
- }
- case (ast::ty_task) { typ = ty::mk_task(tcx); }
- case (ast::ty_port(?t)) {
- typ = ty::mk_port(tcx, ast_ty_to_ty(tcx, getter, t));
- }
- case (ast::ty_chan(?t)) {
- typ = ty::mk_chan(tcx, ast_ty_to_ty(tcx, getter, t));
- }
- case (ast::ty_rec(?fields)) {
- let field[] flds = ~[];
- for (ast::ty_field f in fields) {
- auto tm = ast_mt_to_mt(tcx, getter, f.node.mt);
- flds += ~[rec(ident=f.node.ident, mt=tm)];
- }
- typ = ty::mk_rec(tcx, flds);
- }
- case (ast::ty_fn(?proto, ?inputs, ?output, ?cf, ?constrs)) {
- auto i = ~[];
- for (ast::ty_arg ta in inputs) {
- i += ~[ast_arg_to_arg(tcx, getter, ta)];
- }
- auto out_ty = ast_ty_to_ty(tcx, getter, output);
+ let out_ty = ast_ty_to_ty(tcx, getter, output);
- auto out_constrs = ~[];
- for (@ast::constr constr in constrs) {
+ let out_constrs = ~[];
+ for constr: @ast::constr in constrs {
+ out_constrs += ~[ty::ast_constr_to_constr(tcx, constr)];
+ }
+ typ = ty::mk_fn(tcx, proto, i, out_ty, cf, out_constrs);
+ }
+ ast::ty_path(path, id) {
+ alt tcx.def_map.find(id) {
+ some(ast::def_ty(id)) {
+ typ = instantiate(tcx, ast_ty.span, getter, id, path.node.types);
+ }
+ some(ast::def_native_ty(id)) { typ = getter(id).ty; }
+ some(ast::def_ty_arg(id)) { typ = ty::mk_param(tcx, id); }
+ some(_) {
+ tcx.sess.span_fatal(ast_ty.span,
+ "found type name used as a variable");
+ }
+ _ {
+ tcx.sess.span_fatal(ast_ty.span, "internal error in instantiate");
+ }
+ }
+ cname = some(path_to_str(path));
+ }
+ ast::ty_obj(meths) {
+ let tmeths: ty::method[] = ~[];
+ for m: ast::ty_method in meths {
+ let ins = ~[];
+ for ta: ast::ty_arg in m.node.inputs {
+ ins += ~[ast_arg_to_arg(tcx, getter, ta)];
+ }
+ let out = ast_ty_to_ty(tcx, getter, m.node.output);
+
+ let out_constrs = ~[];
+ for constr: @ast::constr in m.node.constrs {
out_constrs += ~[ty::ast_constr_to_constr(tcx, constr)];
}
- typ = ty::mk_fn(tcx, proto, i, out_ty, cf, out_constrs);
+ let new_m: ty::method =
+ {proto: m.node.proto,
+ ident: m.node.ident,
+ inputs: ins,
+ output: out,
+ cf: m.node.cf,
+ constrs: out_constrs};
+ tmeths += ~[new_m];
}
- case (ast::ty_path(?path, ?id)) {
- alt (tcx.def_map.find(id)) {
- case (some(ast::def_ty(?id))) {
- typ = instantiate(tcx, ast_ty.span, getter, id,
- path.node.types);
- }
- case (some(ast::def_native_ty(?id))) { typ = getter(id).ty; }
- case (some(ast::def_ty_arg(?id))) {
- typ = ty::mk_param(tcx, id);
- }
- case (some(_)) {
- tcx.sess.span_fatal(ast_ty.span,
- "found type name used as a variable");
- }
- case (_) {
- tcx.sess.span_fatal(ast_ty.span,
- "internal error in instantiate");
- }
- }
- cname = some(path_to_str(path));
+ typ = ty::mk_obj(tcx, ty::sort_methods(tmeths));
+ }
+ ast::ty_constr(t, cs) {
+ let out_cs = ~[];
+ for constr: @ast::ty_constr in cs {
+ out_cs += ~[ty::ast_constr_to_constr(tcx, constr)];
}
- case (ast::ty_obj(?meths)) {
- let ty::method[] tmeths = ~[];
- for (ast::ty_method m in meths) {
- auto ins = ~[];
- for (ast::ty_arg ta in m.node.inputs) {
- ins += ~[ast_arg_to_arg(tcx, getter, ta)];
- }
- auto out = ast_ty_to_ty(tcx, getter, m.node.output);
-
- auto out_constrs = ~[];
- for (@ast::constr constr in m.node.constrs) {
- out_constrs += ~[ty::ast_constr_to_constr(tcx, constr)];
- }
- let ty::method new_m =
- rec(proto=m.node.proto,
- ident=m.node.ident,
- inputs=ins,
- output=out,
- cf=m.node.cf,
- constrs=out_constrs);
- tmeths += ~[new_m];
- }
- typ = ty::mk_obj(tcx, ty::sort_methods(tmeths));
- }
- case (ast::ty_constr(?t, ?cs)) {
- auto out_cs = ~[];
- for (@ast::ty_constr constr in cs) {
- out_cs += ~[ty::ast_constr_to_constr(tcx, constr)];
- }
- typ = ty::mk_constr(tcx, ast_ty_to_ty(tcx, getter, t), out_cs);
- }
+ typ = ty::mk_constr(tcx, ast_ty_to_ty(tcx, getter, t), out_cs);
+ }
}
- alt (cname) {
- case (none) {/* no-op */ }
- case (some(?cname_str)) { typ = ty::rename(tcx, typ, cname_str); }
+ alt cname {
+ none. {/* no-op */ }
+ some(cname_str) { typ = ty::rename(tcx, typ, cname_str); }
}
tcx.ast_ty_to_ty_cache.insert(ast_ty, some(typ));
ret typ;
@@ -429,25 +421,26 @@
// A convenience function to use a crate_ctxt to resolve names for
// ast_ty_to_ty.
-fn ast_ty_to_ty_crate(@crate_ctxt ccx, &@ast::ty ast_ty) -> ty::t {
- fn getter(@crate_ctxt ccx, &ast::def_id id) -> ty::ty_param_count_and_ty {
+fn ast_ty_to_ty_crate(ccx: @crate_ctxt, ast_ty: &@ast::ty) -> ty::t {
+ fn getter(ccx: @crate_ctxt, id: &ast::def_id) ->
+ ty::ty_param_count_and_ty {
ret ty::lookup_item_type(ccx.tcx, id);
}
- auto f = bind getter(ccx, _);
+ let f = bind getter(ccx, _);
ret ast_ty_to_ty(ccx.tcx, f, ast_ty);
}
// Functions that write types into the node type table.
mod write {
- fn inner(&node_type_table ntt, ast::node_id node_id,
- &ty_param_substs_opt_and_ty tpot) {
+ fn inner(ntt: &node_type_table, node_id: ast::node_id,
+ tpot: &ty_param_substs_opt_and_ty) {
smallintmap::insert(*ntt, node_id as uint, tpot);
}
// Writes a type parameter count and type pair into the node type table.
- fn ty(&ty::ctxt tcx, ast::node_id node_id,
- &ty_param_substs_opt_and_ty tpot) {
+ fn ty(tcx: &ty::ctxt, node_id: ast::node_id,
+ tpot: &ty_param_substs_opt_and_ty) {
assert (!ty::type_contains_vars(tcx, tpot.ty));
inner(tcx.node_types, node_id, tpot);
}
@@ -455,44 +448,44 @@
// Writes a type parameter count and type pair into the node type table.
// This function allows for the possibility of type variables, which will
// be rewritten later during the fixup phase.
- fn ty_fixup(@fn_ctxt fcx, ast::node_id node_id,
- &ty_param_substs_opt_and_ty tpot) {
+ fn ty_fixup(fcx: @fn_ctxt, node_id: ast::node_id,
+ tpot: &ty_param_substs_opt_and_ty) {
inner(fcx.ccx.tcx.node_types, node_id, tpot);
- if (ty::type_contains_vars(fcx.ccx.tcx, tpot.ty)) {
+ if ty::type_contains_vars(fcx.ccx.tcx, tpot.ty) {
fcx.fixups += ~[node_id];
}
}
// Writes a type with no type parameters into the node type table.
- fn ty_only(&ty::ctxt tcx, ast::node_id node_id, ty::t typ) {
- ty(tcx, node_id, rec(substs=none[ty::t[]], ty=typ));
+ fn ty_only(tcx: &ty::ctxt, node_id: ast::node_id, typ: ty::t) {
+ ty(tcx, node_id, {substs: none[ty::t[]], ty: typ});
}
// Writes a type with no type parameters into the node type table. This
// function allows for the possibility of type variables.
- fn ty_only_fixup(@fn_ctxt fcx, ast::node_id node_id, ty::t typ) {
- ret ty_fixup(fcx, node_id, rec(substs=none[ty::t[]], ty=typ));
+ fn ty_only_fixup(fcx: @fn_ctxt, node_id: ast::node_id, typ: ty::t) {
+ ret ty_fixup(fcx, node_id, {substs: none[ty::t[]], ty: typ});
}
// Writes a nil type into the node type table.
- fn nil_ty(&ty::ctxt tcx, ast::node_id node_id) {
- ret ty(tcx, node_id, rec(substs=none[ty::t[]], ty=ty::mk_nil(tcx)));
+ fn nil_ty(tcx: &ty::ctxt, node_id: ast::node_id) {
+ ret ty(tcx, node_id, {substs: none[ty::t[]], ty: ty::mk_nil(tcx)});
}
// Writes the bottom type into the node type table.
- fn bot_ty(&ty::ctxt tcx, ast::node_id node_id) {
- ret ty(tcx, node_id, rec(substs=none[ty::t[]], ty=ty::mk_bot(tcx)));
+ fn bot_ty(tcx: &ty::ctxt, node_id: ast::node_id) {
+ ret ty(tcx, node_id, {substs: none[ty::t[]], ty: ty::mk_bot(tcx)});
}
}
// Determine the proto for a fn type given the proto for its associated
// code. This is needed because fn and lambda have fn type while iter
// has iter type and block has block type. This may end up changing.
-fn proto_to_ty_proto(&ast::proto proto) -> ast::proto {
- ret alt (proto) {
- ast::proto_iter | ast::proto_block { proto }
- _ { ast::proto_fn }
- };
+fn proto_to_ty_proto(proto: &ast::proto) -> ast::proto {
+ ret alt proto {
+ ast::proto_iter. | ast::proto_block. { proto }
+ _ { ast::proto_fn }
+ };
}
// Item collection - a pair of bootstrap passes:
@@ -510,377 +503,376 @@
// actually wrote types directly into the AST and didn't have a type cache.
// Could use some cleanup. Consider topologically sorting in phase (1) above.
mod collect {
- type ctxt = rec(ty::ctxt tcx);
+ type ctxt = {tcx: ty::ctxt};
- fn mk_ty_params(&@ctxt cx, uint n) -> ty::t[] {
- auto tps = ~[];
- auto i = 0u;
- while (i < n) {
- tps += ~[ty::mk_param(cx.tcx, i)];
- i += 1u;
- }
+ fn mk_ty_params(cx: &@ctxt, n: uint) -> ty::t[] {
+ let tps = ~[];
+ let i = 0u;
+ while i < n { tps += ~[ty::mk_param(cx.tcx, i)]; i += 1u; }
ret tps;
}
- fn ty_of_fn_decl(&@ctxt cx, &fn(&@ast::ty) -> ty::t convert,
- &fn(&ast::arg) -> arg ty_of_arg, &ast::fn_decl decl,
- ast::proto proto, &ast::ty_param[] ty_params,
- &option::t[ast::def_id] def_id) ->
+ fn ty_of_fn_decl(cx: &@ctxt, convert: &fn(&@ast::ty) -> ty::t ,
+ ty_of_arg: &fn(&ast::arg) -> arg , decl: &ast::fn_decl,
+ proto: ast::proto, ty_params: &ast::ty_param[],
+ def_id: &option::t[ast::def_id]) ->
ty::ty_param_count_and_ty {
- auto input_tys = ~[];
- for (ast::arg a in decl.inputs) { input_tys += ~[ty_of_arg(a)]; }
- auto output_ty = convert(decl.output);
+ let input_tys = ~[];
+ for a: ast::arg in decl.inputs { input_tys += ~[ty_of_arg(a)]; }
+ let output_ty = convert(decl.output);
- auto out_constrs = ~[];
- for (@ast::constr constr in decl.constraints) {
+ let out_constrs = ~[];
+ for constr: @ast::constr in decl.constraints {
out_constrs += ~[ty::ast_constr_to_constr(cx.tcx, constr)];
}
- auto t_fn =
- ty::mk_fn(cx.tcx, proto_to_ty_proto(proto), input_tys,
- output_ty, decl.cf, out_constrs);
- auto ty_param_count = ivec::len[ast::ty_param](ty_params);
- auto tpt = rec(count=ty_param_count, ty=t_fn);
- alt (def_id) {
- case (some(?did)) { cx.tcx.tcache.insert(did, tpt); }
- case (_) { }
- }
+ let t_fn =
+ ty::mk_fn(cx.tcx, proto_to_ty_proto(proto), input_tys, output_ty,
+ decl.cf, out_constrs);
+ let ty_param_count = ivec::len[ast::ty_param](ty_params);
+ let tpt = {count: ty_param_count, ty: t_fn};
+ alt def_id { some(did) { cx.tcx.tcache.insert(did, tpt); } _ { } }
ret tpt;
}
- fn ty_of_native_fn_decl(&@ctxt cx, &fn(&@ast::ty) -> ty::t convert,
- &fn(&ast::arg) -> arg ty_of_arg,
- &ast::fn_decl decl, ast::native_abi abi,
- &ast::ty_param[] ty_params,
- &ast::def_id def_id) ->
- ty::ty_param_count_and_ty {
- auto input_tys = ~[];
- for (ast::arg a in decl.inputs) { input_tys += ~[ty_of_arg(a)]; }
- auto output_ty = convert(decl.output);
+ fn ty_of_native_fn_decl(cx: &@ctxt, convert: &fn(&@ast::ty) -> ty::t ,
+ ty_of_arg: &fn(&ast::arg) -> arg ,
+ decl: &ast::fn_decl, abi: ast::native_abi,
+ ty_params: &ast::ty_param[], def_id: &ast::def_id)
+ -> ty::ty_param_count_and_ty {
+ let input_tys = ~[];
+ for a: ast::arg in decl.inputs { input_tys += ~[ty_of_arg(a)]; }
+ let output_ty = convert(decl.output);
- auto t_fn = ty::mk_native_fn(cx.tcx, abi, input_tys, output_ty);
- auto ty_param_count = ivec::len[ast::ty_param](ty_params);
- auto tpt = rec(count=ty_param_count, ty=t_fn);
+ let t_fn = ty::mk_native_fn(cx.tcx, abi, input_tys, output_ty);
+ let ty_param_count = ivec::len[ast::ty_param](ty_params);
+ let tpt = {count: ty_param_count, ty: t_fn};
cx.tcx.tcache.insert(def_id, tpt);
ret tpt;
}
- fn getter(@ctxt cx, &ast::def_id id) -> ty::ty_param_count_and_ty {
- if (id.crate != ast::local_crate) {
+ fn getter(cx: @ctxt, id: &ast::def_id) -> ty::ty_param_count_and_ty {
+ if id.crate != ast::local_crate {
// This is a type we need to load in from the crate reader.
ret csearch::get_type(cx.tcx, id);
}
- auto it = cx.tcx.items.find(id.node);
- auto tpt;
- alt (it) {
- case (some(ast_map::node_item(?item))) {
- tpt = ty_of_item(cx, item);
- }
- case (some(ast_map::node_native_item(?native_item))) {
- tpt = ty_of_native_item(cx, native_item,
- ast::native_abi_cdecl);
- }
- case (_) {
- cx.tcx.sess.fatal("internal error " +
- std::int::str(id.node));
- }
+ let it = cx.tcx.items.find(id.node);
+ let tpt;
+ alt it {
+ some(ast_map::node_item(item)) { tpt = ty_of_item(cx, item); }
+ some(ast_map::node_native_item(native_item)) {
+ tpt = ty_of_native_item(cx, native_item, ast::native_abi_cdecl);
+ }
+ _ { cx.tcx.sess.fatal("internal error " + std::int::str(id.node)); }
}
ret tpt;
}
- fn ty_of_arg(@ctxt cx, &ast::arg a) -> ty::arg {
- auto ty_mode = ast_mode_to_mode(a.mode);
- auto f = bind getter(cx, _);
- auto tt = ast_ty_to_ty(cx.tcx, f, a.ty);
- if (ty::type_has_dynamic_size(cx.tcx, tt)) {
- alt (ty_mode) {
- case (mo_val) {
- cx.tcx.sess.span_fatal(a.ty.span,
- "Dynamically sized arguments \
+ fn ty_of_arg(cx: @ctxt, a: &ast::arg) -> ty::arg {
+ let ty_mode = ast_mode_to_mode(a.mode);
+ let f = bind getter(cx, _);
+ let tt = ast_ty_to_ty(cx.tcx, f, a.ty);
+ if ty::type_has_dynamic_size(cx.tcx, tt) {
+ alt ty_mode {
+ mo_val. {
+ cx.tcx.sess.span_fatal(a.ty.span,
+ "Dynamically sized arguments \
must be passed by alias");
- }
- case (_) { }
+ }
+ _ { }
}
}
- ret rec(mode=ty_mode, ty=tt);
+ ret {mode: ty_mode, ty: tt};
}
- fn ty_of_method(@ctxt cx, &@ast::method m) -> ty::method {
- auto get = bind getter(cx, _);
- auto convert = bind ast_ty_to_ty(cx.tcx, get, _);
+ fn ty_of_method(cx: @ctxt, m: &@ast::method) -> ty::method {
+ let get = bind getter(cx, _);
+ let convert = bind ast_ty_to_ty(cx.tcx, get, _);
- auto inputs = ~[];
- for (ast::arg a in m.node.meth.decl.inputs) {
+ let inputs = ~[];
+ for a: ast::arg in m.node.meth.decl.inputs {
inputs += ~[ty_of_arg(cx, a)];
}
- auto output = convert(m.node.meth.decl.output);
+ let output = convert(m.node.meth.decl.output);
- auto out_constrs = ~[];
- for (@ast::constr constr in m.node.meth.decl.constraints) {
+ let out_constrs = ~[];
+ for constr: @ast::constr in m.node.meth.decl.constraints {
out_constrs += ~[ty::ast_constr_to_constr(cx.tcx, constr)];
}
- ret rec(proto=proto_to_ty_proto(m.node.meth.proto),
- ident=m.node.ident, inputs=inputs, output=output,
- cf=m.node.meth.decl.cf, constrs=out_constrs);
+ ret {proto: proto_to_ty_proto(m.node.meth.proto),
+ ident: m.node.ident,
+ inputs: inputs,
+ output: output,
+ cf: m.node.meth.decl.cf,
+ constrs: out_constrs};
}
- fn ty_of_obj(@ctxt cx, &ast::ident id, &ast::_obj ob,
- &ast::ty_param[] ty_params) -> ty::ty_param_count_and_ty {
- auto methods = get_obj_method_types(cx, ob);
- auto t_obj = ty::mk_obj(cx.tcx, ty::sort_methods(methods));
+ fn ty_of_obj(cx: @ctxt, id: &ast::ident, ob: &ast::_obj,
+ ty_params: &ast::ty_param[]) -> ty::ty_param_count_and_ty {
+ let methods = get_obj_method_types(cx, ob);
+ let t_obj = ty::mk_obj(cx.tcx, ty::sort_methods(methods));
t_obj = ty::rename(cx.tcx, t_obj, id);
- ret rec(count=ivec::len(ty_params), ty=t_obj);
+ ret {count: ivec::len(ty_params), ty: t_obj};
}
- fn ty_of_obj_ctor(@ctxt cx, &ast::ident id, &ast::_obj ob,
- ast::node_id ctor_id, &ast::ty_param[] ty_params) ->
+ fn ty_of_obj_ctor(cx: @ctxt, id: &ast::ident, ob: &ast::_obj,
+ ctor_id: ast::node_id, ty_params: &ast::ty_param[]) ->
ty::ty_param_count_and_ty {
- auto t_obj = ty_of_obj(cx, id, ob, ty_params);
+ let t_obj = ty_of_obj(cx, id, ob, ty_params);
- let arg[] t_inputs = ~[];
- for (ast::obj_field f in ob.fields) {
- auto g = bind getter(cx, _);
- auto t_field = ast_ty_to_ty(cx.tcx, g, f.ty);
- t_inputs += ~[rec(mode=ty::mo_alias(false), ty=t_field)];
+ let t_inputs: arg[] = ~[];
+ for f: ast::obj_field in ob.fields {
+ let g = bind getter(cx, _);
+ let t_field = ast_ty_to_ty(cx.tcx, g, f.ty);
+ t_inputs += ~[{mode: ty::mo_alias(false), ty: t_field}];
}
- auto t_fn = ty::mk_fn(cx.tcx, ast::proto_fn, t_inputs, t_obj.ty,
- ast::return, ~[]);
- auto tpt = rec(count=t_obj.count, ty=t_fn);
+ let t_fn =
+ ty::mk_fn(cx.tcx, ast::proto_fn, t_inputs, t_obj.ty, ast::return,
+ ~[]);
+ let tpt = {count: t_obj.count, ty: t_fn};
cx.tcx.tcache.insert(local_def(ctor_id), tpt);
ret tpt;
}
- fn ty_of_item(&@ctxt cx, &@ast::item it) -> ty::ty_param_count_and_ty {
- auto get = bind getter(cx, _);
- auto convert = bind ast_ty_to_ty(cx.tcx, get, _);
- alt (it.node) {
- case (ast::item_const(?t, _)) {
- auto typ = convert(t);
- auto tpt = rec(count=0u, ty=typ);
- cx.tcx.tcache.insert(local_def(it.id), tpt);
- ret tpt;
+ fn ty_of_item(cx: &@ctxt, it: &@ast::item) -> ty::ty_param_count_and_ty {
+ let get = bind getter(cx, _);
+ let convert = bind ast_ty_to_ty(cx.tcx, get, _);
+ alt it.node {
+ ast::item_const(t, _) {
+ let typ = convert(t);
+ let tpt = {count: 0u, ty: typ};
+ cx.tcx.tcache.insert(local_def(it.id), tpt);
+ ret tpt;
+ }
+ ast::item_fn(fn_info, tps) {
+ let f = bind ty_of_arg(cx, _);
+ ret ty_of_fn_decl(cx, convert, f, fn_info.decl, fn_info.proto,
+ tps, some(local_def(it.id)));
+ }
+ ast::item_obj(ob, tps, _) {
+ let t_obj = ty_of_obj(cx, it.ident, ob, tps);
+ cx.tcx.tcache.insert(local_def(it.id), t_obj);
+ ret t_obj;
+ }
+ ast::item_ty(t, tps) {
+ alt cx.tcx.tcache.find(local_def(it.id)) {
+ some(tpt) { ret tpt; }
+ none. { }
}
- case (ast::item_fn(?fn_info, ?tps)) {
- auto f = bind ty_of_arg(cx, _);
- ret ty_of_fn_decl(cx, convert, f, fn_info.decl, fn_info.proto,
- tps, some(local_def(it.id)));
- }
- case (ast::item_obj(?ob, ?tps, _)) {
- auto t_obj = ty_of_obj(cx, it.ident, ob, tps);
- cx.tcx.tcache.insert(local_def(it.id), t_obj);
- ret t_obj;
- }
- case (ast::item_ty(?t, ?tps)) {
- alt (cx.tcx.tcache.find(local_def(it.id))) {
- case (some(?tpt)) { ret tpt; }
- case (none) { }
- }
- // Tell ast_ty_to_ty() that we want to perform a recursive
- // call to resolve any named types.
+ // Tell ast_ty_to_ty() that we want to perform a recursive
+ // call to resolve any named types.
- auto typ = convert(t);
- auto ty_param_count = ivec::len[ast::ty_param](tps);
- auto tpt = rec(count=ty_param_count, ty=typ);
- cx.tcx.tcache.insert(local_def(it.id), tpt);
- ret tpt;
- }
- case (ast::item_res(?f, _, ?tps, _)) {
- auto t_arg = ty_of_arg(cx, f.decl.inputs.(0));
- auto t_res = rec(count=ivec::len(tps),
- ty=ty::mk_res
- (cx.tcx, local_def(it.id), t_arg.ty,
- mk_ty_params(cx, ivec::len(tps))));
- cx.tcx.tcache.insert(local_def(it.id), t_res);
- ret t_res;
- }
- case (ast::item_tag(_, ?tps)) {
- // Create a new generic polytype.
+ let typ = convert(t);
+ let ty_param_count = ivec::len[ast::ty_param](tps);
+ let tpt = {count: ty_param_count, ty: typ};
+ cx.tcx.tcache.insert(local_def(it.id), tpt);
+ ret tpt;
+ }
+ ast::item_res(f, _, tps, _) {
+ let t_arg = ty_of_arg(cx, f.decl.inputs.(0));
+ let t_res =
+ {count: ivec::len(tps),
+ ty:
+ ty::mk_res(cx.tcx, local_def(it.id), t_arg.ty,
+ mk_ty_params(cx, ivec::len(tps)))};
+ cx.tcx.tcache.insert(local_def(it.id), t_res);
+ ret t_res;
+ }
+ ast::item_tag(_, tps) {
+ // Create a new generic polytype.
- auto ty_param_count = ivec::len[ast::ty_param](tps);
+ let ty_param_count = ivec::len[ast::ty_param](tps);
- let ty::t[] subtys = mk_ty_params(cx, ty_param_count);
- auto t = ty::mk_tag(cx.tcx, local_def(it.id), subtys);
- auto tpt = rec(count=ty_param_count, ty=t);
- cx.tcx.tcache.insert(local_def(it.id), tpt);
- ret tpt;
- }
- case (ast::item_mod(_)) { fail; }
- case (ast::item_native_mod(_)) { fail; }
+ let subtys: ty::t[] = mk_ty_params(cx, ty_param_count);
+ let t = ty::mk_tag(cx.tcx, local_def(it.id), subtys);
+ let tpt = {count: ty_param_count, ty: t};
+ cx.tcx.tcache.insert(local_def(it.id), tpt);
+ ret tpt;
+ }
+ ast::item_mod(_) { fail; }
+ ast::item_native_mod(_) { fail; }
}
}
- fn ty_of_native_item(&@ctxt cx, &@ast::native_item it,
- ast::native_abi abi) -> ty::ty_param_count_and_ty {
- alt (it.node) {
- case (ast::native_item_fn(_, ?fn_decl, ?params)) {
- auto get = bind getter(cx, _);
- auto convert = bind ast_ty_to_ty(cx.tcx, get, _);
- auto f = bind ty_of_arg(cx, _);
- ret ty_of_native_fn_decl(cx, convert, f, fn_decl, abi, params,
- ast::local_def(it.id));
+ fn ty_of_native_item(cx: &@ctxt, it: &@ast::native_item,
+ abi: ast::native_abi) -> ty::ty_param_count_and_ty {
+ alt it.node {
+ ast::native_item_fn(_, fn_decl, params) {
+ let get = bind getter(cx, _);
+ let convert = bind ast_ty_to_ty(cx.tcx, get, _);
+ let f = bind ty_of_arg(cx, _);
+ ret ty_of_native_fn_decl(cx, convert, f, fn_decl, abi, params,
+ ast::local_def(it.id));
+ }
+ ast::native_item_ty. {
+ alt cx.tcx.tcache.find(local_def(it.id)) {
+ some(tpt) { ret tpt; }
+ none. { }
}
- case (ast::native_item_ty) {
- alt (cx.tcx.tcache.find(local_def(it.id))) {
- case (some(?tpt)) { ret tpt; }
- case (none) { }
- }
- auto t = ty::mk_native(cx.tcx, ast::local_def(it.id));
- auto tpt = rec(count=0u, ty=t);
- cx.tcx.tcache.insert(local_def(it.id), tpt);
- ret tpt;
- }
+ let t = ty::mk_native(cx.tcx, ast::local_def(it.id));
+ let tpt = {count: 0u, ty: t};
+ cx.tcx.tcache.insert(local_def(it.id), tpt);
+ ret tpt;
+ }
}
}
- fn get_tag_variant_types(&@ctxt cx, &ast::def_id tag_id,
- &ast::variant[] variants,
- &ast::ty_param[] ty_params) {
+ fn get_tag_variant_types(cx: &@ctxt, tag_id: &ast::def_id,
+ variants: &ast::variant[],
+ ty_params: &ast::ty_param[]) {
// Create a set of parameter types shared among all the variants.
- auto ty_param_count = ivec::len[ast::ty_param](ty_params);
- let ty::t[] ty_param_tys = mk_ty_params(cx, ty_param_count);
- for (ast::variant variant in variants) {
+ let ty_param_count = ivec::len[ast::ty_param](ty_params);
+ let ty_param_tys: ty::t[] = mk_ty_params(cx, ty_param_count);
+ for variant: ast::variant in variants {
// Nullary tag constructors get turned into constants; n-ary tag
// constructors get turned into functions.
- auto result_ty;
- if (ivec::len[ast::variant_arg](variant.node.args) == 0u) {
+ let result_ty;
+ if ivec::len[ast::variant_arg](variant.node.args) == 0u {
result_ty = ty::mk_tag(cx.tcx, tag_id, ty_param_tys);
} else {
// As above, tell ast_ty_to_ty() that trans_ty_item_to_ty()
// should be called to resolve named types.
- auto f = bind getter(cx, _);
- let arg[] args = ~[];
- for (ast::variant_arg va in variant.node.args) {
- auto arg_ty = ast_ty_to_ty(cx.tcx, f, va.ty);
- args += ~[rec(mode=ty::mo_alias(false), ty=arg_ty)];
+ let f = bind getter(cx, _);
+ let args: arg[] = ~[];
+ for va: ast::variant_arg in variant.node.args {
+ let arg_ty = ast_ty_to_ty(cx.tcx, f, va.ty);
+ args += ~[{mode: ty::mo_alias(false), ty: arg_ty}];
}
- auto tag_t = ty::mk_tag(cx.tcx, tag_id, ty_param_tys);
+ let tag_t = ty::mk_tag(cx.tcx, tag_id, ty_param_tys);
// FIXME: this will be different for constrained types
- result_ty = ty::mk_fn(cx.tcx, ast::proto_fn, args, tag_t,
- ast::return, ~[]);
+ result_ty =
+ ty::mk_fn(cx.tcx, ast::proto_fn, args, tag_t, ast::return,
+ ~[]);
}
- auto tpt = rec(count=ty_param_count, ty=result_ty);
+ let tpt = {count: ty_param_count, ty: result_ty};
cx.tcx.tcache.insert(local_def(variant.node.id), tpt);
write::ty_only(cx.tcx, variant.node.id, result_ty);
}
}
- fn get_obj_method_types(&@ctxt cx, &ast::_obj object) -> ty::method[] {
- auto meths = ~[];
- for (@ast::method m in object.methods) {
+ fn get_obj_method_types(cx: &@ctxt, object: &ast::_obj) -> ty::method[] {
+ let meths = ~[];
+ for m: @ast::method in object.methods {
meths += ~[ty_of_method(cx, m)];
}
ret meths;
}
- fn convert(@ctxt cx, @mutable option::t[ast::native_abi] abi,
- &@ast::item it) {
- alt (it.node) {
- case (ast::item_mod(_)) {
- // ignore item_mod, it has no type.
+ fn convert(cx: @ctxt, abi: @mutable option::t[ast::native_abi],
+ it: &@ast::item) {
+ alt it.node {
+ ast::item_mod(_) {
+ // ignore item_mod, it has no type.
+ }
+ ast::item_native_mod(native_mod) {
+ // Propagate the native ABI down to convert_native() below,
+ // but otherwise do nothing, as native modules have no types.
+
+ *abi = some[ast::native_abi](native_mod.abi);
+ }
+ ast::item_tag(variants, ty_params) {
+ let tpt = ty_of_item(cx, it);
+ write::ty_only(cx.tcx, it.id, tpt.ty);
+ get_tag_variant_types(cx, local_def(it.id), variants, ty_params);
+ }
+ ast::item_obj(object, ty_params, ctor_id) {
+ // Now we need to call ty_of_obj_ctor(); this is the type that
+ // we write into the table for this item.
+
+ ty_of_item(cx, it);
+
+ let tpt =
+ ty_of_obj_ctor(cx, it.ident, object, ctor_id, ty_params);
+ write::ty_only(cx.tcx, ctor_id, tpt.ty);
+ // Write the methods into the type table.
+ //
+ // FIXME: Inefficient; this ends up calling
+ // get_obj_method_types() twice. (The first time was above in
+ // ty_of_obj().)
+
+ let method_types = get_obj_method_types(cx, object);
+ let i = 0u;
+ while i < ivec::len[@ast::method](object.methods) {
+ write::ty_only(cx.tcx, object.methods.(i).node.id,
+ ty::method_ty_to_fn_ty(cx.tcx,
+ method_types.(i)));
+ i += 1u;
}
- case (ast::item_native_mod(?native_mod)) {
- // Propagate the native ABI down to convert_native() below,
- // but otherwise do nothing, as native modules have no types.
+ // Write in the types of the object fields.
+ //
+ // FIXME: We want to use uint::range() here, but that causes
+ // an assertion in trans.
- *abi = some[ast::native_abi](native_mod.abi);
+ let args = ty::ty_fn_args(cx.tcx, tpt.ty);
+ i = 0u;
+ while i < ivec::len[ty::arg](args) {
+ let fld = object.fields.(i);
+ write::ty_only(cx.tcx, fld.id, args.(i).ty);
+ i += 1u;
}
- case (ast::item_tag(?variants, ?ty_params)) {
- auto tpt = ty_of_item(cx, it);
- write::ty_only(cx.tcx, it.id, tpt.ty);
- get_tag_variant_types(cx, local_def(it.id), variants,
- ty_params);
+
+
+ // Finally, write in the type of the destructor.
+ alt object.dtor {
+ none. {/* nothing to do */ }
+ some(m) {
+ let t =
+ ty::mk_fn(cx.tcx, ast::proto_fn, ~[], ty::mk_nil(cx.tcx),
+ ast::return, ~[]);
+ write::ty_only(cx.tcx, m.node.id, t);
+ }
}
- case (ast::item_obj(?object, ?ty_params, ?ctor_id)) {
- // Now we need to call ty_of_obj_ctor(); this is the type that
- // we write into the table for this item.
+ }
+ ast::item_res(f, dtor_id, tps, ctor_id) {
+ let t_arg = ty_of_arg(cx, f.decl.inputs.(0));
+ let t_res =
+ ty::mk_res(cx.tcx, local_def(it.id), t_arg.ty,
+ mk_ty_params(cx, ivec::len(tps)));
+ let t_ctor =
+ ty::mk_fn(cx.tcx, ast::proto_fn, ~[t_arg], t_res, ast::return,
+ ~[]);
+ let t_dtor =
+ ty::mk_fn(cx.tcx, ast::proto_fn, ~[t_arg], ty::mk_nil(cx.tcx),
+ ast::return, ~[]);
+ write::ty_only(cx.tcx, it.id, t_res);
+ write::ty_only(cx.tcx, ctor_id, t_ctor);
+ cx.tcx.tcache.insert(local_def(ctor_id),
+ {count: ivec::len(tps), ty: t_ctor});
+ write::ty_only(cx.tcx, dtor_id, t_dtor);
+ }
+ _ {
+ // This call populates the type cache with the converted type
+ // of the item in passing. All we have to do here is to write
+ // it into the node type table.
- ty_of_item(cx, it);
-
- auto tpt =
- ty_of_obj_ctor(cx, it.ident, object, ctor_id, ty_params);
- write::ty_only(cx.tcx, ctor_id, tpt.ty);
- // Write the methods into the type table.
- //
- // FIXME: Inefficient; this ends up calling
- // get_obj_method_types() twice. (The first time was above in
- // ty_of_obj().)
-
- auto method_types = get_obj_method_types(cx, object);
- auto i = 0u;
- while (i < ivec::len[@ast::method](object.methods)) {
- write::ty_only(cx.tcx, object.methods.(i).node.id,
- ty::method_ty_to_fn_ty(cx.tcx,
- method_types.(i)));
- i += 1u;
- }
- // Write in the types of the object fields.
- //
- // FIXME: We want to use uint::range() here, but that causes
- // an assertion in trans.
-
- auto args = ty::ty_fn_args(cx.tcx, tpt.ty);
- i = 0u;
- while (i < ivec::len[ty::arg](args)) {
- auto fld = object.fields.(i);
- write::ty_only(cx.tcx, fld.id, args.(i).ty);
- i += 1u;
- }
-
- // Finally, write in the type of the destructor.
- alt (object.dtor) {
- case (none) {/* nothing to do */ }
- case (some(?m)) {
- auto t = ty::mk_fn(cx.tcx, ast::proto_fn, ~[],
- ty::mk_nil(cx.tcx), ast::return, ~[]);
- write::ty_only(cx.tcx, m.node.id, t);
- }
- }
- }
- case (ast::item_res(?f, ?dtor_id, ?tps, ?ctor_id)) {
- auto t_arg = ty_of_arg(cx, f.decl.inputs.(0));
- auto t_res = ty::mk_res(cx.tcx, local_def(it.id), t_arg.ty,
- mk_ty_params(cx, ivec::len(tps)));
- auto t_ctor = ty::mk_fn(cx.tcx, ast::proto_fn, ~[t_arg],
- t_res, ast::return, ~[]);
- auto t_dtor = ty::mk_fn(cx.tcx, ast::proto_fn, ~[t_arg],
- ty::mk_nil(cx.tcx), ast::return, ~[]);
- write::ty_only(cx.tcx, it.id, t_res);
- write::ty_only(cx.tcx, ctor_id, t_ctor);
- cx.tcx.tcache.insert(local_def(ctor_id),
- rec(count=ivec::len(tps), ty=t_ctor));
- write::ty_only(cx.tcx, dtor_id, t_dtor);
- }
- case (_) {
- // This call populates the type cache with the converted type
- // of the item in passing. All we have to do here is to write
- // it into the node type table.
-
- auto tpt = ty_of_item(cx, it);
- write::ty_only(cx.tcx, it.id, tpt.ty);
- }
+ let tpt = ty_of_item(cx, it);
+ write::ty_only(cx.tcx, it.id, tpt.ty);
+ }
}
}
- fn convert_native(@ctxt cx, @mutable option::t[ast::native_abi] abi,
- &@ast::native_item i) {
+ fn convert_native(cx: @ctxt, abi: @mutable option::t[ast::native_abi],
+ i: &@ast::native_item) {
// As above, this call populates the type table with the converted
// type of the native item. We simply write it into the node type
// table.
- auto tpt =
+ let tpt =
ty_of_native_item(cx, i, option::get[ast::native_abi]({ *abi }));
- alt (i.node) {
- case (ast::native_item_ty) {
- // FIXME: Native types have no annotation. Should they? --pcw
+ alt i.node {
+ ast::native_item_ty. {
+ // FIXME: Native types have no annotation. Should they? --pcw
- }
- case (ast::native_item_fn(_, _, _)) {
- write::ty_only(cx.tcx, i.id, tpt.ty);
- }
+ }
+ ast::native_item_fn(_, _, _) {
+ write::ty_only(cx.tcx, i.id, tpt.ty);
+ }
}
}
- fn collect_item_types(&ty::ctxt tcx, &@ast::crate crate) {
+ fn collect_item_types(tcx: &ty::ctxt, crate: &@ast::crate) {
// We have to propagate the surrounding ABI to the native items
// contained within the native module.
- auto abi = @mutable none[ast::native_abi];
- auto cx = @rec(tcx=tcx);
- auto visit = visit::mk_simple_visitor
- (@rec(visit_item=bind convert(cx, abi, _),
- visit_native_item=bind convert_native(cx, abi, _)
- with *visit::default_simple_visitor()));
+ let abi = @mutable none[ast::native_abi];
+ let cx = @{tcx: tcx};
+ let visit =
+ visit::mk_simple_visitor(@{visit_item: bind convert(cx, abi, _),
+ visit_native_item:
+ bind convert_native(cx, abi, _)
+ with
+ *visit::default_simple_visitor()});
visit::visit_crate(*crate, (), visit);
}
}
@@ -890,7 +882,7 @@
// TODO: rename to just "unify"
mod unify {
- fn simple(&@fn_ctxt fcx, &ty::t expected, &ty::t actual) ->
+ fn simple(fcx: &@fn_ctxt, expected: &ty::t, actual: &ty::t) ->
ty::unify::result {
ret ty::unify::unify(expected, actual, fcx.var_bindings, fcx.ccx.tcx);
}
@@ -900,183 +892,184 @@
// FIXME This is almost a duplicate of ty::type_autoderef, with structure_of
// instead of ty::struct.
-fn do_autoderef(&@fn_ctxt fcx, &span sp, &ty::t t) -> ty::t {
- auto t1 = t;
- while (true) {
- alt (structure_of(fcx, sp, t1)) {
- case (ty::ty_box(?inner)) { t1 = inner.ty; }
- case (ty::ty_res(_, ?inner, ?tps)) {
- t1 = ty::substitute_type_params(fcx.ccx.tcx, tps, inner);
+fn do_autoderef(fcx: &@fn_ctxt, sp: &span, t: &ty::t) -> ty::t {
+ let t1 = t;
+ while true {
+ alt structure_of(fcx, sp, t1) {
+ ty::ty_box(inner) { t1 = inner.ty; }
+ ty::ty_res(_, inner, tps) {
+ t1 = ty::substitute_type_params(fcx.ccx.tcx, tps, inner);
+ }
+ ty::ty_tag(did, tps) {
+ let variants = ty::tag_variants(fcx.ccx.tcx, did);
+ if ivec::len(variants) != 1u || ivec::len(variants.(0).args) != 1u
+ {
+ ret t1;
}
- case (ty::ty_tag(?did, ?tps)) {
- auto variants = ty::tag_variants(fcx.ccx.tcx, did);
- if (ivec::len(variants) != 1u ||
- ivec::len(variants.(0).args) != 1u) {
- ret t1;
- }
- t1 = ty::substitute_type_params(fcx.ccx.tcx, tps,
- variants.(0).args.(0));
- }
- case (_) { ret t1; }
+ t1 =
+ ty::substitute_type_params(fcx.ccx.tcx, tps,
+ variants.(0).args.(0));
+ }
+ _ { ret t1; }
}
}
fail;
}
-fn add_boxes(&@crate_ctxt ccx, uint n, &ty::t t) -> ty::t {
- auto t1 = t;
- while (n != 0u) { t1 = ty::mk_imm_box(ccx.tcx, t1); n -= 1u; }
+fn add_boxes(ccx: &@crate_ctxt, n: uint, t: &ty::t) -> ty::t {
+ let t1 = t;
+ while n != 0u { t1 = ty::mk_imm_box(ccx.tcx, t1); n -= 1u; }
ret t1;
}
-fn count_boxes(&@fn_ctxt fcx, &span sp, &ty::t t) -> uint {
- auto n = 0u;
- auto t1 = t;
- while (true) {
- alt (structure_of(fcx, sp, t1)) {
- case (ty::ty_box(?inner)) { n += 1u; t1 = inner.ty; }
- case (_) { ret n; }
+fn count_boxes(fcx: &@fn_ctxt, sp: &span, t: &ty::t) -> uint {
+ let n = 0u;
+ let t1 = t;
+ while true {
+ alt structure_of(fcx, sp, t1) {
+ ty::ty_box(inner) { n += 1u; t1 = inner.ty; }
+ _ { ret n; }
}
}
fail;
}
-fn do_fn_block_coerce(&@fn_ctxt fcx, &span sp,
- &ty::t actual, &ty::t expected) -> ty::t {
+fn do_fn_block_coerce(fcx: &@fn_ctxt, sp: &span, actual: &ty::t,
+ expected: &ty::t) -> ty::t {
+
// fns can be silently coerced to blocks when being used as
// function call or bind arguments, but not the reverse.
// If our actual type is a fn and our expected type is a block,
// build up a new expected type that is identical to the old one
// except for its proto. If we don't know the expected or actual
// types, that's fine, but we can't do the coercion.
- ret alt (structure_of_maybe(fcx, sp, actual)) {
- some(ty::ty_fn(ast::proto_fn, ?args, ?ret_ty, ?cf, ?constrs)) {
- alt (structure_of_maybe(fcx, sp, expected)) {
- some(ty::ty_fn(ast::proto_block, _, _, _, _)) {
- ty::mk_fn(fcx.ccx.tcx,
- ast::proto_block, args, ret_ty, cf, constrs)
+ ret alt structure_of_maybe(fcx, sp, actual) {
+ some(ty::ty_fn(ast::proto_fn., args, ret_ty, cf, constrs)) {
+ alt structure_of_maybe(fcx, sp, expected) {
+ some(ty::ty_fn(ast::proto_block., _, _, _, _)) {
+ ty::mk_fn(fcx.ccx.tcx, ast::proto_block, args, ret_ty, cf,
+ constrs)
+ }
+ _ { actual }
+ }
}
_ { actual }
}
- }
- _ { actual }
- }
}
-fn resolve_type_vars_if_possible(&@fn_ctxt fcx, ty::t typ) -> ty::t {
- alt (ty::unify::fixup_vars(fcx.ccx.tcx, fcx.var_bindings, typ)) {
- case (fix_ok(?new_type)) { ret new_type; }
- case (fix_err(_)) { ret typ; }
+fn resolve_type_vars_if_possible(fcx: &@fn_ctxt, typ: ty::t) -> ty::t {
+ alt ty::unify::fixup_vars(fcx.ccx.tcx, fcx.var_bindings, typ) {
+ fix_ok(new_type) { ret new_type; }
+ fix_err(_) { ret typ; }
}
}
// Demands - procedures that require that two types unify and emit an error
// message if they don't.
-type ty_param_substs_and_ty = rec(ty::t[] substs, ty::t ty);
+type ty_param_substs_and_ty = {substs: ty::t[], ty: ty::t};
mod demand {
- fn simple(&@fn_ctxt fcx, &span sp, &ty::t expected, &ty::t actual) ->
+ fn simple(fcx: &@fn_ctxt, sp: &span, expected: &ty::t, actual: &ty::t) ->
ty::t {
ret full(fcx, sp, expected, actual, ~[], NO_AUTODEREF).ty;
}
- fn autoderef(&@fn_ctxt fcx, &span sp, &ty::t expected, &ty::t actual,
- autoderef_kind adk) -> ty::t {
+ fn autoderef(fcx: &@fn_ctxt, sp: &span, expected: &ty::t, actual: &ty::t,
+ adk: autoderef_kind) -> ty::t {
ret full(fcx, sp, expected, actual, ~[], adk).ty;
}
// Requires that the two types unify, and prints an error message if they
// don't. Returns the unified type and the type parameter substitutions.
- fn full(&@fn_ctxt fcx, &span sp, &ty::t expected, &ty::t actual,
- &ty::t[] ty_param_substs_0, autoderef_kind adk) ->
+ fn full(fcx: &@fn_ctxt, sp: &span, expected: &ty::t, actual: &ty::t,
+ ty_param_substs_0: &ty::t[], adk: autoderef_kind) ->
ty_param_substs_and_ty {
- auto expected_1 = expected;
- auto actual_1 = actual;
- auto implicit_boxes = 0u;
- if (adk == AUTODEREF_OK) {
+ let expected_1 = expected;
+ let actual_1 = actual;
+ let implicit_boxes = 0u;
+ if adk == AUTODEREF_OK {
expected_1 = do_autoderef(fcx, sp, expected_1);
actual_1 = do_autoderef(fcx, sp, actual_1);
implicit_boxes = count_boxes(fcx, sp, actual);
} else if (adk == AUTODEREF_BLOCK_COERCE) {
actual_1 = do_fn_block_coerce(fcx, sp, actual, expected);
}
- let ty::t[mutable] ty_param_substs = ~[mutable];
- let int[] ty_param_subst_var_ids = ~[];
- for (ty::t ty_param_subst in ty_param_substs_0) {
+ let ty_param_substs: ty::t[mutable ] = ~[mutable ];
+ let ty_param_subst_var_ids: int[] = ~[];
+ for ty_param_subst: ty::t in ty_param_substs_0 {
// Generate a type variable and unify it with the type parameter
// substitution. We will then pull out these type variables.
- auto t_0 = next_ty_var(fcx);
+ let t_0 = next_ty_var(fcx);
ty_param_substs += ~[mutable t_0];
ty_param_subst_var_ids += ~[ty::ty_var_id(fcx.ccx.tcx, t_0)];
simple(fcx, sp, ty_param_subst, t_0);
}
- fn mk_result(&@fn_ctxt fcx, &ty::t result_ty,
- &int[] ty_param_subst_var_ids,
- uint implicit_boxes) -> ty_param_substs_and_ty {
- let ty::t[] result_ty_param_substs = ~[];
- for (int var_id in ty_param_subst_var_ids) {
- auto tp_subst = ty::mk_var(fcx.ccx.tcx, var_id);
+ fn mk_result(fcx: &@fn_ctxt, result_ty: &ty::t,
+ ty_param_subst_var_ids: &int[], implicit_boxes: uint) ->
+ ty_param_substs_and_ty {
+ let result_ty_param_substs: ty::t[] = ~[];
+ for var_id: int in ty_param_subst_var_ids {
+ let tp_subst = ty::mk_var(fcx.ccx.tcx, var_id);
result_ty_param_substs += ~[tp_subst];
}
- ret rec(substs=result_ty_param_substs,
- ty=add_boxes(fcx.ccx, implicit_boxes, result_ty));
+ ret {substs: result_ty_param_substs,
+ ty: add_boxes(fcx.ccx, implicit_boxes, result_ty)};
}
- alt (unify::simple(fcx, expected_1, actual_1)) {
- case (ures_ok(?t)) {
- ret mk_result(fcx, t, ty_param_subst_var_ids,
- implicit_boxes);
- }
- case (ures_err(?err)) {
- auto e_err = resolve_type_vars_if_possible(fcx, expected_1);
- auto a_err = resolve_type_vars_if_possible(fcx, actual_1);
- fcx.ccx.tcx.sess.span_err(sp,
- "mismatched types: expected " +
+
+ alt unify::simple(fcx, expected_1, actual_1) {
+ ures_ok(t) {
+ ret mk_result(fcx, t, ty_param_subst_var_ids, implicit_boxes);
+ }
+ ures_err(err) {
+ let e_err = resolve_type_vars_if_possible(fcx, expected_1);
+ let a_err = resolve_type_vars_if_possible(fcx, actual_1);
+ fcx.ccx.tcx.sess.span_err(sp,
+ "mismatched types: expected " +
ty_to_str(fcx.ccx.tcx, e_err) +
" but found " +
- ty_to_str(fcx.ccx.tcx, a_err) +
- " (" + ty::type_err_to_str(err)
- + ")");
- ret mk_result(fcx, expected_1,
- ty_param_subst_var_ids, implicit_boxes);
- }
+ ty_to_str(fcx.ccx.tcx, a_err) + " ("
+ + ty::type_err_to_str(err) + ")");
+ ret mk_result(fcx, expected_1, ty_param_subst_var_ids,
+ implicit_boxes);
+ }
}
}
}
// Returns true if the two types unify and false if they don't.
-fn are_compatible(&@fn_ctxt fcx, &ty::t expected, &ty::t actual) -> bool {
- alt (unify::simple(fcx, expected, actual)) {
- case (ures_ok(_)) { ret true; }
- case (ures_err(_)) { ret false; }
+fn are_compatible(fcx: &@fn_ctxt, expected: &ty::t, actual: &ty::t) -> bool {
+ alt unify::simple(fcx, expected, actual) {
+ ures_ok(_) { ret true; }
+ ures_err(_) { ret false; }
}
}
// Returns the types of the arguments to a tag variant.
-fn variant_arg_types(&@crate_ctxt ccx, &span sp, &ast::def_id vid,
- &ty::t[] tag_ty_params) -> ty::t[] {
- let ty::t[] result = ~[];
- auto tpt = ty::lookup_item_type(ccx.tcx, vid);
- alt (ty::struct(ccx.tcx, tpt.ty)) {
- case (ty::ty_fn(_, ?ins, _, _, _)) {
+fn variant_arg_types(ccx: &@crate_ctxt, sp: &span, vid: &ast::def_id,
+ tag_ty_params: &ty::t[]) -> ty::t[] {
+ let result: ty::t[] = ~[];
+ let tpt = ty::lookup_item_type(ccx.tcx, vid);
+ alt ty::struct(ccx.tcx, tpt.ty) {
+ ty::ty_fn(_, ins, _, _, _) {
- // N-ary variant.
- for (ty::arg arg in ins) {
- auto arg_ty =
- ty::substitute_type_params(ccx.tcx, tag_ty_params,
- arg.ty);
- result += ~[arg_ty];
- }
- }
- case (_) {
- // Nullary variant. Do nothing, as there are no arguments.
+ // N-ary variant.
+ for arg: ty::arg in ins {
+ let arg_ty =
+ ty::substitute_type_params(ccx.tcx, tag_ty_params, arg.ty);
+ result += ~[arg_ty];
}
+ }
+ _ {
+ // Nullary variant. Do nothing, as there are no arguments.
+
+ }
}
/* result is a vector of the *expected* types of all the fields */
@@ -1094,124 +1087,108 @@
export resolve_type_vars_in_block;
- fn resolve_type_vars_in_type(&@fn_ctxt fcx, &span sp, ty::t typ) ->
- option::t[ty::t] {
- if (!ty::type_contains_vars(fcx.ccx.tcx, typ)) { ret some(typ); }
- alt (ty::unify::fixup_vars(fcx.ccx.tcx, fcx.var_bindings, typ)) {
- case (fix_ok(?new_type)) { ret some(new_type); }
- case (fix_err(?vid)) {
- fcx.ccx.tcx.sess.span_err(sp,
- "cannot determine a type \
+ fn resolve_type_vars_in_type(fcx: &@fn_ctxt, sp: &span, typ: ty::t) ->
+ option::t[ty::t] {
+ if !ty::type_contains_vars(fcx.ccx.tcx, typ) { ret some(typ); }
+ alt ty::unify::fixup_vars(fcx.ccx.tcx, fcx.var_bindings, typ) {
+ fix_ok(new_type) { ret some(new_type); }
+ fix_err(vid) {
+ fcx.ccx.tcx.sess.span_err(sp,
+ "cannot determine a type \
for this expression");
- ret none;
- }
+ ret none;
+ }
}
}
- fn resolve_type_vars_for_node(&@wb_ctxt wbcx,
- &span sp, ast::node_id id) {
- auto fcx = wbcx.fcx;
- auto tpot = ty::node_id_to_ty_param_substs_opt_and_ty
- (fcx.ccx.tcx, id);
- auto new_ty = alt (resolve_type_vars_in_type(fcx, sp, tpot.ty)) {
- case (some(?t)) { t }
- case (none) {
- wbcx.success = false;
- ret
- }
- };
- auto new_substs_opt;
- alt (tpot.substs) {
- case (none[ty::t[]]) { new_substs_opt = none[ty::t[]]; }
- case (some[ty::t[]](?substs)) {
- let ty::t[] new_substs = ~[];
- for (ty::t subst in substs) {
- alt (resolve_type_vars_in_type(fcx, sp, subst)) {
- case (some(?t)) {
- new_substs += ~[t];
- }
- case (none) {
- wbcx.success = false;
- ret;
- }
- }
+ fn resolve_type_vars_for_node(wbcx: &@wb_ctxt, sp: &span,
+ id: ast::node_id) {
+ let fcx = wbcx.fcx;
+ let tpot = ty::node_id_to_ty_param_substs_opt_and_ty(fcx.ccx.tcx, id);
+ let new_ty =
+ alt resolve_type_vars_in_type(fcx, sp, tpot.ty) {
+ some(t) { t }
+ none. { wbcx.success = false; ret }
+ };
+ let new_substs_opt;
+ alt tpot.substs {
+ none[ty::t[]]. { new_substs_opt = none[ty::t[]]; }
+ some[ty::t[]](substs) {
+ let new_substs: ty::t[] = ~[];
+ for subst: ty::t in substs {
+ alt resolve_type_vars_in_type(fcx, sp, subst) {
+ some(t) { new_substs += ~[t]; }
+ none. { wbcx.success = false; ret; }
}
- new_substs_opt = some[ty::t[]](new_substs);
}
+ new_substs_opt = some[ty::t[]](new_substs);
+ }
}
- write::ty(fcx.ccx.tcx, id, rec(substs=new_substs_opt, ty=new_ty));
+ write::ty(fcx.ccx.tcx, id, {substs: new_substs_opt, ty: new_ty});
}
- type wb_ctxt = rec(@fn_ctxt fcx,
- // A flag to ignore contained items and lambdas
- mutable bool ignore,
- // As soon as we hit an error we have to stop resolving
- // the entire function
- mutable bool success);
+ type wb_ctxt =
+ // A flag to ignore contained items and lambdas
+ // As soon as we hit an error we have to stop resolving
+ // the entire function
+ {fcx: @fn_ctxt, mutable ignore: bool, mutable success: bool};
- fn visit_stmt_pre(@wb_ctxt wbcx, &@ast::stmt s) {
+ fn visit_stmt_pre(wbcx: @wb_ctxt, s: &@ast::stmt) {
resolve_type_vars_for_node(wbcx, s.span, ty::stmt_node_id(s));
}
- fn visit_expr_pre(@wb_ctxt wbcx, &@ast::expr e) {
+ fn visit_expr_pre(wbcx: @wb_ctxt, e: &@ast::expr) {
resolve_type_vars_for_node(wbcx, e.span, e.id);
}
- fn visit_block_pre(@wb_ctxt wbcx, &ast::blk b) {
+ fn visit_block_pre(wbcx: @wb_ctxt, b: &ast::blk) {
resolve_type_vars_for_node(wbcx, b.span, b.node.id);
}
- fn visit_pat_pre(@wb_ctxt wbcx, &@ast::pat p) {
+ fn visit_pat_pre(wbcx: @wb_ctxt, p: &@ast::pat) {
resolve_type_vars_for_node(wbcx, p.span, p.id);
}
- fn visit_local_pre(@wb_ctxt wbcx, &@ast::local l) {
- auto var_id = lookup_local(wbcx.fcx, l.span, l.node.id);
- auto fix_rslt =
+ fn visit_local_pre(wbcx: @wb_ctxt, l: &@ast::local) {
+ let var_id = lookup_local(wbcx.fcx, l.span, l.node.id);
+ let fix_rslt =
ty::unify::resolve_type_var(wbcx.fcx.ccx.tcx,
- wbcx.fcx.var_bindings,
- var_id);
- alt (fix_rslt) {
- case (fix_ok(?lty)) {
- write::ty_only(wbcx.fcx.ccx.tcx, l.node.id, lty);
- }
- case (fix_err(_)) {
- wbcx.fcx.ccx.tcx.sess.span_err(l.span,
- "cannot determine a type \
+ wbcx.fcx.var_bindings, var_id);
+ alt fix_rslt {
+ fix_ok(lty) { write::ty_only(wbcx.fcx.ccx.tcx, l.node.id, lty); }
+ fix_err(_) {
+ wbcx.fcx.ccx.tcx.sess.span_err(l.span,
+ "cannot determine a type \
for this local variable");
- wbcx.success = false;
- }
+ wbcx.success = false;
+ }
}
}
- fn visit_item_pre(@wb_ctxt wbcx, &@ast::item item) {
+ fn visit_item_pre(wbcx: @wb_ctxt, item: &@ast::item) {
wbcx.ignore = true;
}
- fn visit_item_post(@wb_ctxt wbcx, &@ast::item item) {
+ fn visit_item_post(wbcx: @wb_ctxt, item: &@ast::item) {
wbcx.ignore = false;
}
- fn visit_fn_pre(@wb_ctxt wbcx, &ast::_fn f,
- &ast::ty_param[] tps, &span sp,
- &ast::fn_ident i, ast::node_id d) {
+ fn visit_fn_pre(wbcx: @wb_ctxt, f: &ast::_fn, tps: &ast::ty_param[],
+ sp: &span, i: &ast::fn_ident, d: ast::node_id) {
wbcx.ignore = true;
}
- fn visit_fn_post(@wb_ctxt wbcx, &ast::_fn f,
- &ast::ty_param[] tps, &span sp,
- &ast::fn_ident i, ast::node_id d) {
+ fn visit_fn_post(wbcx: @wb_ctxt, f: &ast::_fn, tps: &ast::ty_param[],
+ sp: &span, i: &ast::fn_ident, d: ast::node_id) {
wbcx.ignore = false;
}
- fn keep_going(@wb_ctxt wbcx) -> bool { !wbcx.ignore && wbcx.success }
+ fn keep_going(wbcx: @wb_ctxt) -> bool { !wbcx.ignore && wbcx.success }
- fn resolve_type_vars_in_block(&@fn_ctxt fcx, &ast::blk blk) -> bool {
- auto wbcx = @rec(fcx = fcx,
- mutable ignore = false,
- mutable success = true);
- auto visit =
- rec(keep_going=bind keep_going(wbcx),
- visit_item_pre=bind visit_item_pre(wbcx, _),
- visit_item_post=bind visit_item_post(wbcx, _),
- visit_fn_pre=bind visit_fn_pre(wbcx, _, _, _, _, _),
- visit_fn_post=bind visit_fn_post(wbcx, _, _, _, _, _),
- visit_stmt_pre=bind visit_stmt_pre(wbcx, _),
- visit_expr_pre=bind visit_expr_pre(wbcx, _),
- visit_block_pre=bind visit_block_pre(wbcx, _),
- visit_pat_pre=bind visit_pat_pre(wbcx, _),
- visit_local_pre=bind visit_local_pre(wbcx, _)
- with walk::default_visitor());
+ fn resolve_type_vars_in_block(fcx: &@fn_ctxt, blk: &ast::blk) -> bool {
+ let wbcx = @{fcx: fcx, mutable ignore: false, mutable success: true};
+ let visit =
+ {keep_going: bind keep_going(wbcx),
+ visit_item_pre: bind visit_item_pre(wbcx, _),
+ visit_item_post: bind visit_item_post(wbcx, _),
+ visit_fn_pre: bind visit_fn_pre(wbcx, _, _, _, _, _),
+ visit_fn_post: bind visit_fn_post(wbcx, _, _, _, _, _),
+ visit_stmt_pre: bind visit_stmt_pre(wbcx, _),
+ visit_expr_pre: bind visit_expr_pre(wbcx, _),
+ visit_block_pre: bind visit_block_pre(wbcx, _),
+ visit_pat_pre: bind visit_pat_pre(wbcx, _),
+ visit_local_pre: bind visit_local_pre(wbcx, _)
+ with walk::default_visitor()};
walk::walk_block(visit, blk);
ret wbcx.success;
}
@@ -1221,439 +1198,436 @@
// Local variable gathering. We gather up all locals and create variable IDs
// for them before typechecking the function.
type gather_result =
- rec(@ty::unify::var_bindings var_bindings,
- hashmap[ast::node_id, int] locals,
- hashmap[ast::node_id, ast::ident] local_names,
- @mutable int next_var_id);
+ {var_bindings: @ty::unify::var_bindings,
+ locals: hashmap[ast::node_id, int],
+ local_names: hashmap[ast::node_id, ast::ident],
+ next_var_id: @mutable int};
// Used only as a helper for check_fn.
-fn gather_locals(&@crate_ctxt ccx, &ast::_fn f,
- &ast::node_id id, &option::t[@fn_ctxt] old_fcx)
- -> gather_result {
- fn next_var_id(@mutable int nvi) -> int {
- auto rv = *nvi;
+fn gather_locals(ccx: &@crate_ctxt, f: &ast::_fn, id: &ast::node_id,
+ old_fcx: &option::t[@fn_ctxt]) -> gather_result {
+ fn next_var_id(nvi: @mutable int) -> int {
+ let rv = *nvi;
*nvi += 1;
ret rv;
}
- fn assign(&ty::ctxt tcx, &@ty::unify::var_bindings var_bindings,
- &hashmap[ast::node_id, int] locals,
- &hashmap[ast::node_id, ast::ident] local_names,
- @mutable int nvi,
- ast::node_id nid, &ast::ident ident, option::t[ty::t] ty_opt) {
- auto var_id = next_var_id(nvi);
+ fn assign(tcx: &ty::ctxt, var_bindings: &@ty::unify::var_bindings,
+ locals: &hashmap[ast::node_id, int],
+ local_names: &hashmap[ast::node_id, ast::ident],
+ nvi: @mutable int, nid: ast::node_id, ident: &ast::ident,
+ ty_opt: option::t[ty::t]) {
+ let var_id = next_var_id(nvi);
locals.insert(nid, var_id);
local_names.insert(nid, ident);
- alt (ty_opt) {
- case (none[ty::t]) {/* nothing to do */ }
- case (some[ty::t](?typ)) {
- ty::unify::unify(ty::mk_var(tcx, var_id), typ, var_bindings,
- tcx);
- }
+ alt ty_opt {
+ none[ty::t]. {/* nothing to do */ }
+ some[ty::t](typ) {
+ ty::unify::unify(ty::mk_var(tcx, var_id), typ, var_bindings, tcx);
+ }
}
}
- auto vb; auto locals; auto local_names; auto nvi;
- alt (old_fcx) {
- none {
- vb = ty::unify::mk_var_bindings();
- locals = new_int_hash[int]();
- local_names = new_int_hash[ast::ident]();
- nvi = @mutable 0;
- }
- some(?fcx) {
- vb = fcx.var_bindings;
- locals = fcx.locals;
- local_names = fcx.local_names;
- nvi = fcx.next_var_id;
- }
+ let vb;
+ let locals;
+ let local_names;
+ let nvi;
+ alt old_fcx {
+ none. {
+ vb = ty::unify::mk_var_bindings();
+ locals = new_int_hash[int]();
+ local_names = new_int_hash[ast::ident]();
+ nvi = @mutable 0;
+ }
+ some(fcx) {
+ vb = fcx.var_bindings;
+ locals = fcx.locals;
+ local_names = fcx.local_names;
+ nvi = fcx.next_var_id;
+ }
}
// Add object fields, if any.
- auto obj_fields = ~[];
- alt (get_obj_info(ccx)) {
- some(?oinfo) {
- alt (oinfo) {
- regular_obj(?ofs, _) { obj_fields = ofs; }
- anon_obj(?ofs, _) { obj_fields = ofs; }
- }
+ let obj_fields = ~[];
+ alt get_obj_info(ccx) {
+ some(oinfo) {
+ alt oinfo {
+ regular_obj(ofs, _) { obj_fields = ofs; }
+ anon_obj(ofs, _) { obj_fields = ofs; }
}
- none { /* no fields */ }
+ }
+ none. {/* no fields */ }
}
- for (ast::obj_field f in obj_fields) {
- auto field_ty = ty::node_id_to_type(ccx.tcx, f.id);
+ for f: ast::obj_field in obj_fields {
+ let field_ty = ty::node_id_to_type(ccx.tcx, f.id);
assign(ccx.tcx, vb, locals, local_names, nvi, f.id, f.ident,
some(field_ty));
}
// Add formal parameters.
- auto args = ty::ty_fn_args(ccx.tcx, ty::node_id_to_type(ccx.tcx, id));
- auto i = 0u;
- for (ty::arg arg in args) {
+ let args = ty::ty_fn_args(ccx.tcx, ty::node_id_to_type(ccx.tcx, id));
+ let i = 0u;
+ for arg: ty::arg in args {
assign(ccx.tcx, vb, locals, local_names, nvi, f.decl.inputs.(i).id,
f.decl.inputs.(i).ident, some[ty::t](arg.ty));
i += 1u;
}
// Add explicitly-declared locals.
- fn visit_local(@crate_ctxt ccx, @ty::unify::var_bindings vb,
- hashmap[ast::node_id, int] locals,
- hashmap[ast::node_id, ast::ident] local_names,
- @mutable int nvi, &@ast::local local,
- &() e, &visit::vt[()] v) {
- alt (local.node.ty) {
- case (none) {
- // Auto slot.
- assign(ccx.tcx, vb, locals, local_names, nvi, local.node.id,
- local.node.ident, none);
- }
- case (some(?ast_ty)) {
- // Explicitly typed slot.
- auto local_ty = ast_ty_to_ty_crate(ccx, ast_ty);
- assign(ccx.tcx, vb, locals, local_names, nvi, local.node.id,
- local.node.ident, some[ty::t](local_ty));
- }
+ fn visit_local(ccx: @crate_ctxt, vb: @ty::unify::var_bindings,
+ locals: hashmap[ast::node_id, int],
+ local_names: hashmap[ast::node_id, ast::ident],
+ nvi: @mutable int, local: &@ast::local, e: &(),
+ v: &visit::vt[()]) {
+ alt local.node.ty {
+ none. {
+ // Auto slot.
+ assign(ccx.tcx, vb, locals, local_names, nvi, local.node.id,
+ local.node.ident, none);
+ }
+ some(ast_ty) {
+ // Explicitly typed slot.
+ let local_ty = ast_ty_to_ty_crate(ccx, ast_ty);
+ assign(ccx.tcx, vb, locals, local_names, nvi, local.node.id,
+ local.node.ident, some[ty::t](local_ty));
+ }
}
visit::visit_local(local, e, v);
}
// Add pattern bindings.
- fn visit_pat(@crate_ctxt ccx, @ty::unify::var_bindings vb,
- hashmap[ast::node_id, int] locals,
- hashmap[ast::node_id, ast::ident] local_names,
- @mutable int nvi, &@ast::pat p,
- &() e, &visit::vt[()] v) {
- alt (p.node) {
- case (ast::pat_bind(?ident)) {
- assign(ccx.tcx, vb, locals, local_names, nvi,
- p.id, ident, none);
- }
- case (_) {/* no-op */ }
+ fn visit_pat(ccx: @crate_ctxt, vb: @ty::unify::var_bindings,
+ locals: hashmap[ast::node_id, int],
+ local_names: hashmap[ast::node_id, ast::ident],
+ nvi: @mutable int, p: &@ast::pat, e: &(),
+ v: &visit::vt[()]) {
+ alt p.node {
+ ast::pat_bind(ident) {
+ assign(ccx.tcx, vb, locals, local_names, nvi, p.id, ident, none);
+ }
+ _ {/* no-op */ }
}
visit::visit_pat(p, e, v);
}
// Don't descend into fns and items
- fn visit_fn[E](&ast::_fn f, &ast::ty_param[] tp, &span sp,
- &ast::fn_ident i, ast::node_id id, &E e,
- &visit::vt[E] v) {}
- fn visit_item[E](&@ast::item i, &E e, &visit::vt[E] v) {}
+ fn visit_fn[E](f: &ast::_fn, tp: &ast::ty_param[], sp: &span,
+ i: &ast::fn_ident, id: ast::node_id, e: &E,
+ v: &visit::vt[E]) {
+ }
+ fn visit_item[E](i: &@ast::item, e: &E, v: &visit::vt[E]) { }
- auto visit =
- @rec(visit_local=bind visit_local(ccx, vb, locals, local_names,
- nvi, _, _, _),
- visit_pat=bind visit_pat(ccx, vb, locals, local_names,
- nvi, _, _, _),
- visit_fn=visit_fn,
- visit_item=visit_item
- with *visit::default_visitor());
+ let visit =
+ @{visit_local:
+ bind visit_local(ccx, vb, locals, local_names, nvi, _, _, _),
+ visit_pat:
+ bind visit_pat(ccx, vb, locals, local_names, nvi, _, _, _),
+ visit_fn: visit_fn,
+ visit_item: visit_item with *visit::default_visitor()};
visit::visit_block(f.body, (), visit::mk_vt(visit));
- ret rec(var_bindings=vb,
- locals=locals,
- local_names=local_names,
- next_var_id=nvi);
+ ret {var_bindings: vb,
+ locals: locals,
+ local_names: local_names,
+ next_var_id: nvi};
}
// AST fragment checking
-fn check_lit(@crate_ctxt ccx, &@ast::lit lit) -> ty::t {
- alt (lit.node) {
- case (ast::lit_str(_, ast::sk_rc)) { ret ty::mk_str(ccx.tcx); }
- case (ast::lit_str(_, ast::sk_unique)) { ret ty::mk_istr(ccx.tcx); }
- case (ast::lit_char(_)) { ret ty::mk_char(ccx.tcx); }
- case (ast::lit_int(_)) { ret ty::mk_int(ccx.tcx); }
- case (ast::lit_float(_)) { ret ty::mk_float(ccx.tcx); }
- case (ast::lit_mach_float(?tm, _)) { ret ty::mk_mach(ccx.tcx, tm); }
- case (ast::lit_uint(_)) { ret ty::mk_uint(ccx.tcx); }
- case (ast::lit_mach_int(?tm, _)) { ret ty::mk_mach(ccx.tcx, tm); }
- case (ast::lit_nil) { ret ty::mk_nil(ccx.tcx); }
- case (ast::lit_bool(_)) { ret ty::mk_bool(ccx.tcx); }
+fn check_lit(ccx: @crate_ctxt, lit: &@ast::lit) -> ty::t {
+ alt lit.node {
+ ast::lit_str(_, ast::sk_rc.) { ret ty::mk_str(ccx.tcx); }
+ ast::lit_str(_, ast::sk_unique.) { ret ty::mk_istr(ccx.tcx); }
+ ast::lit_char(_) { ret ty::mk_char(ccx.tcx); }
+ ast::lit_int(_) { ret ty::mk_int(ccx.tcx); }
+ ast::lit_float(_) { ret ty::mk_float(ccx.tcx); }
+ ast::lit_mach_float(tm, _) { ret ty::mk_mach(ccx.tcx, tm); }
+ ast::lit_uint(_) { ret ty::mk_uint(ccx.tcx); }
+ ast::lit_mach_int(tm, _) { ret ty::mk_mach(ccx.tcx, tm); }
+ ast::lit_nil. { ret ty::mk_nil(ccx.tcx); }
+ ast::lit_bool(_) { ret ty::mk_bool(ccx.tcx); }
}
}
// Pattern checking is top-down rather than bottom-up so that bindings get
// their types immediately.
-fn check_pat(&@fn_ctxt fcx, &ast::pat_id_map map, &@ast::pat pat,
- ty::t expected) {
- alt (pat.node) {
- case (ast::pat_wild) {
- write::ty_only_fixup(fcx, pat.id, expected);
+fn check_pat(fcx: &@fn_ctxt, map: &ast::pat_id_map, pat: &@ast::pat,
+ expected: ty::t) {
+ alt pat.node {
+ ast::pat_wild. { write::ty_only_fixup(fcx, pat.id, expected); }
+ ast::pat_lit(lt) {
+ let typ = check_lit(fcx.ccx, lt);
+ typ = demand::simple(fcx, pat.span, expected, typ);
+ write::ty_only_fixup(fcx, pat.id, typ);
+ }
+ ast::pat_bind(name) {
+ let vid = lookup_local(fcx, pat.span, pat.id);
+ let typ = ty::mk_var(fcx.ccx.tcx, vid);
+ typ = demand::simple(fcx, pat.span, expected, typ);
+ let canon_id = map.get(name);
+ if canon_id != pat.id {
+ let ct =
+ ty::mk_var(fcx.ccx.tcx,
+ lookup_local(fcx, pat.span, canon_id));
+ typ = demand::simple(fcx, pat.span, ct, typ);
}
- case (ast::pat_lit(?lt)) {
- auto typ = check_lit(fcx.ccx, lt);
- typ = demand::simple(fcx, pat.span, expected, typ);
- write::ty_only_fixup(fcx, pat.id, typ);
- }
- case (ast::pat_bind(?name)) {
- auto vid = lookup_local(fcx, pat.span, pat.id);
- auto typ = ty::mk_var(fcx.ccx.tcx, vid);
- typ = demand::simple(fcx, pat.span, expected, typ);
- auto canon_id = map.get(name);
- if (canon_id != pat.id) {
- auto ct = ty::mk_var(fcx.ccx.tcx,
- lookup_local(fcx, pat.span, canon_id));
- typ = demand::simple(fcx, pat.span, ct, typ);
- }
- write::ty_only_fixup(fcx, pat.id, typ);
- }
- case (ast::pat_tag(?path, ?subpats)) {
- // Typecheck the path.
- auto v_def = lookup_def(fcx, path.span, pat.id);
- auto v_def_ids = ast::variant_def_ids(v_def);
- auto tag_tpt = ty::lookup_item_type(fcx.ccx.tcx, v_def_ids.tg);
- auto path_tpot = instantiate_path(fcx, path, tag_tpt, pat.span);
- // Take the tag type params out of `expected`.
+ write::ty_only_fixup(fcx, pat.id, typ);
+ }
+ ast::pat_tag(path, subpats) {
+ // Typecheck the path.
+ let v_def = lookup_def(fcx, path.span, pat.id);
+ let v_def_ids = ast::variant_def_ids(v_def);
+ let tag_tpt = ty::lookup_item_type(fcx.ccx.tcx, v_def_ids.tg);
+ let path_tpot = instantiate_path(fcx, path, tag_tpt, pat.span);
+ // Take the tag type params out of `expected`.
- alt (structure_of(fcx, pat.span, expected)) {
- case (ty::ty_tag(_, ?expected_tps)) {
- // Unify with the expected tag type.
+ alt structure_of(fcx, pat.span, expected) {
+ ty::ty_tag(_, expected_tps) {
+ // Unify with the expected tag type.
- auto ctor_ty =
- ty::ty_param_substs_opt_and_ty_to_monotype(fcx.ccx.tcx,
- path_tpot);
+ let ctor_ty =
+ ty::ty_param_substs_opt_and_ty_to_monotype(fcx.ccx.tcx,
+ path_tpot);
- auto path_tpt =
- demand::full(fcx, pat.span, expected, ctor_ty,
- expected_tps, NO_AUTODEREF);
- path_tpot = rec(substs=some[ty::t[]](path_tpt.substs),
- ty=path_tpt.ty);
- // Get the number of arguments in this tag variant.
+ let path_tpt =
+ demand::full(fcx, pat.span, expected, ctor_ty, expected_tps,
+ NO_AUTODEREF);
+ path_tpot =
+ {substs: some[ty::t[]](path_tpt.substs), ty: path_tpt.ty};
+ // Get the number of arguments in this tag variant.
- auto arg_types =
- variant_arg_types(fcx.ccx, pat.span, v_def_ids.var,
- expected_tps);
- auto subpats_len = std::ivec::len[@ast::pat](subpats);
- if (std::ivec::len[ty::t](arg_types) > 0u) {
- // N-ary variant.
+ let arg_types =
+ variant_arg_types(fcx.ccx, pat.span, v_def_ids.var,
+ expected_tps);
+ let subpats_len = std::ivec::len[@ast::pat](subpats);
+ if std::ivec::len[ty::t](arg_types) > 0u {
+ // N-ary variant.
- auto arg_len = ivec::len[ty::t](arg_types);
- if (arg_len != subpats_len) {
- // TODO: note definition of tag variant
- // TODO (issue #448): Wrap a #fmt string over multiple
- // lines...
- auto s = #fmt("this pattern has %u field%s, but the \
- corresponding variant has %u field%s",
- subpats_len,
- if (subpats_len == 1u) {
- ""
- } else { "s" }, arg_len,
- if (arg_len == 1u) {
- ""
- } else { "s" });
- fcx.ccx.tcx.sess.span_fatal(pat.span, s);
- }
-
- // TODO: ivec::iter2
-
- auto i = 0u;
- for (@ast::pat subpat in subpats) {
- check_pat(fcx, map, subpat, arg_types.(i));
- i += 1u;
- }
- } else if (subpats_len > 0u) {
+ let arg_len = ivec::len[ty::t](arg_types);
+ if arg_len != subpats_len {
// TODO: note definition of tag variant
// TODO (issue #448): Wrap a #fmt string over multiple
// lines...
+ let s =
+ #fmt("this pattern has %u field%s, but the \
+ corresponding variant has %u field%s",
+ subpats_len,
+ if subpats_len == 1u { "" } else { "s" },
+ arg_len, if arg_len == 1u { "" } else { "s" });
+ fcx.ccx.tcx.sess.span_fatal(pat.span, s);
+ }
- fcx.ccx.tcx.sess.span_fatal(pat.span,
- #fmt("this pattern has %u field%s, \
+ // TODO: ivec::iter2
+
+ let i = 0u;
+ for subpat: @ast::pat in subpats {
+ check_pat(fcx, map, subpat, arg_types.(i));
+ i += 1u;
+ }
+ } else if (subpats_len > 0u) {
+ // TODO: note definition of tag variant
+ // TODO (issue #448): Wrap a #fmt string over multiple
+ // lines...
+
+ fcx.ccx.tcx.sess.span_fatal(pat.span,
+ #fmt("this pattern has %u field%s, \
but the corresponding \
variant has no fields",
- subpats_len,
- if (subpats_len == 1u) {
- ""
- } else { "s" }));
- }
- write::ty_fixup(fcx, pat.id, path_tpot);
- }
- case (_) {
- // FIXME: Switch expected and actual in this message? I
- // can never tell.
- fcx.ccx.tcx.sess.span_fatal(pat.span,
- #fmt("mismatched types: \
- expected %s, found tag",
- ty_to_str(fcx.ccx.tcx,
- expected)));
- }
+ subpats_len,
+ if subpats_len == 1u {
+ ""
+ } else { "s" }));
}
write::ty_fixup(fcx, pat.id, path_tpot);
+ }
+ _ {
+ // FIXME: Switch expected and actual in this message? I
+ // can never tell.
+ fcx.ccx.tcx.sess.span_fatal(pat.span,
+ #fmt("mismatched types: \
+ expected %s, found tag",
+ ty_to_str(fcx.ccx.tcx,
+ expected)));
+ }
}
- case (ast::pat_rec(?fields, ?etc)) {
- auto ex_fields;
- alt (structure_of(fcx, pat.span, expected)) {
- case (ty::ty_rec(?fields)) { ex_fields = fields; }
- case (_) {
- fcx.ccx.tcx.sess.span_fatal
- (pat.span, #fmt("mismatched types: expected %s, \
+ write::ty_fixup(fcx, pat.id, path_tpot);
+ }
+ ast::pat_rec(fields, etc) {
+ let ex_fields;
+ alt structure_of(fcx, pat.span, expected) {
+ ty::ty_rec(fields) { ex_fields = fields; }
+ _ {
+ fcx.ccx.tcx.sess.span_fatal(pat.span,
+ #fmt("mismatched types: expected %s, \
found record",
- ty_to_str(fcx.ccx.tcx, expected)));
- }
- };
- auto f_count = ivec::len(fields);
- auto ex_f_count = ivec::len(ex_fields);
- if (ex_f_count < f_count || (!etc && ex_f_count > f_count)) {
- fcx.ccx.tcx.sess.span_fatal
- (pat.span, #fmt("mismatched types: expected a record \
+ ty_to_str(fcx.ccx.tcx,
+ expected)));
+ }
+ }
+ let f_count = ivec::len(fields);
+ let ex_f_count = ivec::len(ex_fields);
+ if ex_f_count < f_count || !etc && ex_f_count > f_count {
+ fcx.ccx.tcx.sess.span_fatal(pat.span,
+ #fmt("mismatched types: expected a record \
with %u fields, found one with %u \
- fields", ex_f_count, f_count));
- }
- fn matches(&str name, &ty::field f) -> bool {
- ret str::eq(name, f.ident);
- }
- for (ast::field_pat f in fields) {
- alt (ivec::find(bind matches(f.ident, _), ex_fields)) {
- some(?field) {
- check_pat(fcx, map, f.pat, field.mt.ty);
- }
- none {
- fcx.ccx.tcx.sess.span_fatal
- (pat.span, #fmt("mismatched types: did not \
+ fields",
+ ex_f_count, f_count));
+ }
+ fn matches(name: &str, f: &ty::field) -> bool {
+ ret str::eq(name, f.ident);
+ }
+ for f: ast::field_pat in fields {
+ alt ivec::find(bind matches(f.ident, _), ex_fields) {
+ some(field) { check_pat(fcx, map, f.pat, field.mt.ty); }
+ none. {
+ fcx.ccx.tcx.sess.span_fatal(pat.span,
+ #fmt("mismatched types: did not \
expect a record with a field %s",
- f.ident));
- }
- }
+ f.ident));
+ }
}
+ }
+ write::ty_only_fixup(fcx, pat.id, expected);
+ }
+ ast::pat_box(inner) {
+ alt structure_of(fcx, pat.span, expected) {
+ ty::ty_box(e_inner) {
+ check_pat(fcx, map, inner, e_inner.ty);
write::ty_only_fixup(fcx, pat.id, expected);
+ }
+ _ {
+ fcx.ccx.tcx.sess.span_fatal(pat.span,
+ "mismatched types: expected " +
+ ty_to_str(fcx.ccx.tcx, expected) +
+ " found box");
+ }
}
- case (ast::pat_box(?inner)) {
- alt (structure_of(fcx, pat.span, expected)) {
- case (ty::ty_box(?e_inner)) {
- check_pat(fcx, map, inner, e_inner.ty);
- write::ty_only_fixup(fcx, pat.id, expected);
- }
- case (_) {
- fcx.ccx.tcx.sess.span_fatal
- (pat.span, "mismatched types: expected " +
- ty_to_str(fcx.ccx.tcx, expected) +
- " found box");
- }
- }
- }
+ }
}
}
-fn require_impure(&session::session sess, &ast::purity f_purity, &span sp) {
- alt (f_purity) {
- case (ast::impure_fn) { ret; }
- case (ast::pure_fn) {
- sess.span_fatal(sp,
- "Found impure expression in pure function decl");
- }
+fn require_impure(sess: &session::session, f_purity: &ast::purity,
+ sp: &span) {
+ alt f_purity {
+ ast::impure_fn. { ret; }
+ ast::pure_fn. {
+ sess.span_fatal(sp, "Found impure expression in pure function decl");
+ }
}
}
-fn require_pure_call(@crate_ctxt ccx, &ast::purity caller_purity,
- &@ast::expr callee, &span sp) {
- alt (caller_purity) {
- case (ast::impure_fn) { ret; }
- case (ast::pure_fn) {
- alt (ccx.tcx.def_map.find(callee.id)) {
- case (some(ast::def_fn(_, ast::pure_fn))) {
- ret;
- }
- case (_) {
- ccx.tcx.sess.span_fatal(sp,
- "Pure function calls function not known to be pure");
- }
- }
+fn require_pure_call(ccx: @crate_ctxt, caller_purity: &ast::purity,
+ callee: &@ast::expr, sp: &span) {
+ alt caller_purity {
+ ast::impure_fn. { ret; }
+ ast::pure_fn. {
+ alt ccx.tcx.def_map.find(callee.id) {
+ some(ast::def_fn(_, ast::pure_fn.)) { ret; }
+ _ {
+ ccx.tcx.sess.span_fatal(sp,
+ "Pure function calls function not known to be pure");
+ }
}
+ }
}
}
-fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
+fn check_expr(fcx: &@fn_ctxt, expr: &@ast::expr) {
// fcx.ccx.tcx.sess.span_warn(expr.span, "typechecking expr " +
// syntax::print::pprust::expr_to_str(expr));
// A generic function to factor out common logic from call and bind
// expressions.
- fn check_call_or_bind(&@fn_ctxt fcx, &span sp, &@ast::expr f,
- &(option::t[@ast::expr])[] args, call_kind call_kind) {
+ fn check_call_or_bind(fcx: &@fn_ctxt, sp: &span, f: &@ast::expr,
+ args: &(option::t[@ast::expr])[],
+ call_kind: call_kind) {
// Check the function.
check_expr(fcx, f);
// Get the function type.
- auto fty = expr_ty(fcx.ccx.tcx, f);
+ let fty = expr_ty(fcx.ccx.tcx, f);
// We want to autoderef calls but not binds
- auto fty_stripped = alt (call_kind) {
- case (kind_call) { do_autoderef(fcx, sp, fty) }
- case (_) { fty } };
+ let fty_stripped =
+ alt call_kind {
+ kind_call. { do_autoderef(fcx, sp, fty) }
+ _ { fty }
+ };
// Grab the argument types and the return type.
- auto arg_tys;
- alt (structure_of(fcx, sp, fty_stripped)) {
- case (ty::ty_fn(_, ?arg_tys_0, _, _, _)) { arg_tys = arg_tys_0; }
- case (ty::ty_native_fn(_, ?arg_tys_0, _)) { arg_tys = arg_tys_0; }
- case (_) {
- fcx.ccx.tcx.sess.span_fatal(f.span,
- "mismatched types: \
+ let arg_tys;
+ alt structure_of(fcx, sp, fty_stripped) {
+ ty::ty_fn(_, arg_tys_0, _, _, _) { arg_tys = arg_tys_0; }
+ ty::ty_native_fn(_, arg_tys_0, _) { arg_tys = arg_tys_0; }
+ _ {
+ fcx.ccx.tcx.sess.span_fatal(f.span,
+ "mismatched types: \
expected function or native \
function but found "
- + ty_to_str(fcx.ccx.tcx, fty));
- }
+ + ty_to_str(fcx.ccx.tcx, fty));
+ }
}
// Check that the correct number of arguments were supplied.
- auto expected_arg_count = ivec::len[ty::arg](arg_tys);
- auto supplied_arg_count = ivec::len[option::t[@ast::expr]](args);
- if (expected_arg_count != supplied_arg_count) {
+ let expected_arg_count = ivec::len[ty::arg](arg_tys);
+ let supplied_arg_count = ivec::len[option::t[@ast::expr]](args);
+ if expected_arg_count != supplied_arg_count {
fcx.ccx.tcx.sess.span_fatal(sp,
- #fmt("this function takes %u \
+ #fmt("this function takes %u \
parameter%s but %u parameter%s \
supplied",
- expected_arg_count,
- if (expected_arg_count == 1u) {
- ""
- } else { "s" }, supplied_arg_count,
- if (supplied_arg_count == 1u) {
- " was"
- } else { "s were" }));
+ expected_arg_count,
+ if expected_arg_count == 1u {
+ ""
+ } else { "s" },
+ supplied_arg_count,
+ if supplied_arg_count == 1u {
+ " was"
+ } else { "s were" }));
}
// Check the arguments.
// TODO: iter2
- auto i = 0u;
- for (option::t[@ast::expr] a_opt in args) {
- auto check_ty_vars = call_kind == kind_spawn;
- alt (a_opt) {
- case (some(?a)) {
- check_expr(fcx, a);
- demand::full(fcx, a.span, arg_tys.(i).ty,
- expr_ty(fcx.ccx.tcx, a), ~[],
- AUTODEREF_BLOCK_COERCE);
- }
- case (none) {
- check_ty_vars = true;
- }
+ let i = 0u;
+ for a_opt: option::t[@ast::expr] in args {
+ let check_ty_vars = call_kind == kind_spawn;
+ alt a_opt {
+ some(a) {
+ check_expr(fcx, a);
+ demand::full(fcx, a.span, arg_tys.(i).ty,
+ expr_ty(fcx.ccx.tcx, a), ~[],
+ AUTODEREF_BLOCK_COERCE);
+ }
+ none. { check_ty_vars = true; }
}
/* If this argument is going to be a thunk argument
(that is, it's an underscore-bind thing or a spawn
argument), then it has to be either passed by reference,
or have a statically known size. */
- alt (call_kind) {
- case (kind_call) { }
- case (_) { /* bind or spawn */
- if (check_ty_vars &&
- ((ty::type_contains_params(fcx.ccx.tcx,
- arg_tys.(i).ty))
- || ty::type_contains_vars(fcx.ccx.tcx,
- arg_tys.(i).ty))
- && arg_tys.(i).mode == mo_val) {
- // For why the check is necessary, see the
- // none case in trans_bind_thunk
- fcx.ccx.tcx.sess.span_fatal(sp,
- call_kind_str(call_kind) +
- " arguments with types containing parameters \
+ alt call_kind {
+ kind_call. { }
+ _ {
+ /* bind or spawn */
+ if check_ty_vars &&
+ (ty::type_contains_params(fcx.ccx.tcx, arg_tys.(i).ty)
+ ||
+ ty::type_contains_vars(fcx.ccx.tcx,
+ arg_tys.(i).ty)) &&
+ arg_tys.(i).mode == mo_val {
+ // For why the check is necessary, see the
+ // none case in trans_bind_thunk
+ fcx.ccx.tcx.sess.span_fatal(sp,
+ call_kind_str(call_kind) +
+ " arguments with types containing parameters \
must be passed by alias");
- }
}
+ }
}
i += 1u;
}
}
// A generic function for checking assignment expressions
- fn check_assignment(&@fn_ctxt fcx, &span sp, &@ast::expr lhs,
- &@ast::expr rhs, &ast::node_id id) {
+ fn check_assignment(fcx: &@fn_ctxt, sp: &span, lhs: &@ast::expr,
+ rhs: &@ast::expr, id: &ast::node_id) {
check_expr(fcx, lhs);
check_expr(fcx, rhs);
demand::simple(fcx, sp, expr_ty(fcx.ccx.tcx, lhs),
@@ -1662,10 +1636,10 @@
}
// A generic function for checking call expressions
- fn check_call(&@fn_ctxt fcx, &span sp, &@ast::expr f,
- &(@ast::expr)[] args, call_kind call_kind) {
- let (option::t[@ast::expr])[] args_opt_0 = ~[];
- for (@ast::expr arg in args) {
+ fn check_call(fcx: &@fn_ctxt, sp: &span, f: &@ast::expr,
+ args: &(@ast::expr)[], call_kind: call_kind) {
+ let args_opt_0: (option::t[@ast::expr])[] = ~[];
+ for arg: @ast::expr in args {
args_opt_0 += ~[some[@ast::expr](arg)];
}
// Call the generic checker.
@@ -1674,1121 +1648,1066 @@
}
// A generic function for checking for or for-each loops
- fn check_for_or_for_each(&@fn_ctxt fcx, &@ast::local local,
- &ty::t element_ty, &ast::blk body,
- ast::node_id node_id) {
+ fn check_for_or_for_each(fcx: &@fn_ctxt, local: &@ast::local,
+ element_ty: &ty::t, body: &ast::blk,
+ node_id: ast::node_id) {
check_decl_local(fcx, local);
check_block(fcx, body);
// Unify type of decl with element type of the seq
- demand::simple(fcx, local.span,
- ty::decl_local_ty(fcx.ccx.tcx, local),
+ demand::simple(fcx, local.span, ty::decl_local_ty(fcx.ccx.tcx, local),
element_ty);
- auto typ = ty::mk_nil(fcx.ccx.tcx);
+ let typ = ty::mk_nil(fcx.ccx.tcx);
write::ty_only_fixup(fcx, node_id, typ);
}
// A generic function for checking the pred in a check
// or if-check
- fn check_pred_expr(&@fn_ctxt fcx, &@ast::expr e) {
+ fn check_pred_expr(fcx: &@fn_ctxt, e: &@ast::expr) {
check_expr(fcx, e);
demand::simple(fcx, e.span, ty::mk_bool(fcx.ccx.tcx),
expr_ty(fcx.ccx.tcx, e));
+
/* e must be a call expr where all arguments are either
literals or slots */
- alt (e.node) {
- case (ast::expr_call(?operator, ?operands)) {
- alt (operator.node) {
- case (ast::expr_path(?oper_name)) {
- alt (fcx.ccx.tcx.def_map.find(operator.id)) {
- case (some(ast::def_fn(_, ast::pure_fn))) {
- // do nothing
- }
- case (_) {
- fcx.ccx.tcx.sess.span_fatal(operator.span,
- "non-predicate as operator \
+ alt e.node {
+ ast::expr_call(operator, operands) {
+ alt operator.node {
+ ast::expr_path(oper_name) {
+ alt fcx.ccx.tcx.def_map.find(operator.id) {
+ some(ast::def_fn(_, ast::pure_fn.)) {
+ // do nothing
+ }
+ _ {
+ fcx.ccx.tcx.sess.span_fatal(operator.span,
+ "non-predicate as operator \
in constraint");
- }
- }
- for (@ast::expr operand in operands) {
- if (!ast::is_constraint_arg(operand)) {
- auto s = "Constraint args must be \
+ }
+ }
+ for operand: @ast::expr in operands {
+ if !ast::is_constraint_arg(operand) {
+ let s =
+ "Constraint args must be \
slot variables or literals";
- fcx.ccx.tcx.sess.span_fatal(e.span, s);
- }
- }
- }
- case (_) {
- auto s = "In a constraint, expected the \
- constraint name to be an explicit name";
- fcx.ccx.tcx.sess.span_fatal(e.span,s);
- }
+ fcx.ccx.tcx.sess.span_fatal(e.span, s);
}
}
- case (_) {
- fcx.ccx.tcx.sess.span_fatal(e.span,
- "check on non-predicate");
- }
+ }
+ _ {
+ let s =
+ "In a constraint, expected the \
+ constraint name to be an explicit name";
+ fcx.ccx.tcx.sess.span_fatal(e.span, s);
+ }
}
+ }
+ _ { fcx.ccx.tcx.sess.span_fatal(e.span, "check on non-predicate"); }
+ }
}
// A generic function for checking the then and else in an if
// or if-check
- fn check_then_else(&@fn_ctxt fcx, &ast::blk thn,
- &option::t[@ast::expr] elsopt,
- ast::node_id id, &span sp) {
+ fn check_then_else(fcx: &@fn_ctxt, thn: &ast::blk,
+ elsopt: &option::t[@ast::expr], id: ast::node_id,
+ sp: &span) {
check_block(fcx, thn);
- auto if_t =
- alt (elsopt) {
- case (some(?els)) {
- check_expr(fcx, els);
- auto thn_t = block_ty(fcx.ccx.tcx, thn);
- auto elsopt_t = expr_ty(fcx.ccx.tcx, els);
- demand::simple(fcx, sp, thn_t, elsopt_t);
- if (!ty::type_is_bot(fcx.ccx.tcx, elsopt_t)) {
- elsopt_t
- } else { thn_t }
- }
- case (none) { ty::mk_nil(fcx.ccx.tcx) }
+ let if_t =
+ alt elsopt {
+ some(els) {
+ check_expr(fcx, els);
+ let thn_t = block_ty(fcx.ccx.tcx, thn);
+ let elsopt_t = expr_ty(fcx.ccx.tcx, els);
+ demand::simple(fcx, sp, thn_t, elsopt_t);
+ if !ty::type_is_bot(fcx.ccx.tcx, elsopt_t) {
+ elsopt_t
+ } else { thn_t }
+ }
+ none. { ty::mk_nil(fcx.ccx.tcx) }
};
write::ty_only_fixup(fcx, id, if_t);
}
// Checks the compatibility
- fn check_binop_type_compat(&@fn_ctxt fcx, span span,
- ty::t ty, ast::binop binop) {
- auto resolved_t = resolve_type_vars_if_possible(fcx, ty);
- if (!ty::is_binopable(fcx.ccx.tcx, resolved_t, binop)) {
- auto binopstr = ast::binop_to_str(binop);
- auto t_str = ty_to_str(fcx.ccx.tcx, resolved_t);
- auto errmsg = "binary operation " + binopstr
- + " cannot be applied to type `" + t_str + "`";
+ fn check_binop_type_compat(fcx: &@fn_ctxt, span: span, ty: ty::t,
+ binop: ast::binop) {
+ let resolved_t = resolve_type_vars_if_possible(fcx, ty);
+ if !ty::is_binopable(fcx.ccx.tcx, resolved_t, binop) {
+ let binopstr = ast::binop_to_str(binop);
+ let t_str = ty_to_str(fcx.ccx.tcx, resolved_t);
+ let errmsg =
+ "binary operation " + binopstr +
+ " cannot be applied to type `" + t_str + "`";
fcx.ccx.tcx.sess.span_fatal(span, errmsg);
}
}
- auto id = expr.id;
- alt (expr.node) {
- case (ast::expr_lit(?lit)) {
- auto typ = check_lit(fcx.ccx, lit);
- write::ty_only_fixup(fcx, id, typ);
- }
- case (ast::expr_binary(?binop, ?lhs, ?rhs)) {
- check_expr(fcx, lhs);
- check_expr(fcx, rhs);
+ let id = expr.id;
+ alt expr.node {
+ ast::expr_lit(lit) {
+ let typ = check_lit(fcx.ccx, lit);
+ write::ty_only_fixup(fcx, id, typ);
+ }
+ ast::expr_binary(binop, lhs, rhs) {
+ check_expr(fcx, lhs);
+ check_expr(fcx, rhs);
- auto lhs_t = expr_ty(fcx.ccx.tcx, lhs);
- auto rhs_t = expr_ty(fcx.ccx.tcx, rhs);
+ let lhs_t = expr_ty(fcx.ccx.tcx, lhs);
+ let rhs_t = expr_ty(fcx.ccx.tcx, rhs);
- demand::autoderef(fcx, rhs.span, lhs_t, rhs_t, AUTODEREF_OK);
- auto deref_t = do_autoderef(fcx, expr.span, lhs_t);
- check_binop_type_compat(fcx, expr.span, deref_t, binop);
+ demand::autoderef(fcx, rhs.span, lhs_t, rhs_t, AUTODEREF_OK);
+ let deref_t = do_autoderef(fcx, expr.span, lhs_t);
+ check_binop_type_compat(fcx, expr.span, deref_t, binop);
- auto t = alt (binop) {
- case (ast::eq) { ty::mk_bool(fcx.ccx.tcx) }
- case (ast::lt) { ty::mk_bool(fcx.ccx.tcx) }
- case (ast::le) { ty::mk_bool(fcx.ccx.tcx) }
- case (ast::ne) { ty::mk_bool(fcx.ccx.tcx) }
- case (ast::ge) { ty::mk_bool(fcx.ccx.tcx) }
- case (ast::gt) { ty::mk_bool(fcx.ccx.tcx) }
- case (_) { deref_t }
+ let t =
+ alt binop {
+ ast::eq. { ty::mk_bool(fcx.ccx.tcx) }
+ ast::lt. { ty::mk_bool(fcx.ccx.tcx) }
+ ast::le. { ty::mk_bool(fcx.ccx.tcx) }
+ ast::ne. { ty::mk_bool(fcx.ccx.tcx) }
+ ast::ge. { ty::mk_bool(fcx.ccx.tcx) }
+ ast::gt. { ty::mk_bool(fcx.ccx.tcx) }
+ _ { deref_t }
};
- write::ty_only_fixup(fcx, id, t);
- }
- case (ast::expr_unary(?unop, ?oper)) {
- check_expr(fcx, oper);
- auto oper_t = expr_ty(fcx.ccx.tcx, oper);
- alt (unop) {
- case (ast::box(?mut)) {
- oper_t = ty::mk_box(fcx.ccx.tcx, rec(ty=oper_t, mut=mut));
+ write::ty_only_fixup(fcx, id, t);
+ }
+ ast::expr_unary(unop, oper) {
+ check_expr(fcx, oper);
+ let oper_t = expr_ty(fcx.ccx.tcx, oper);
+ alt unop {
+ ast::box(mut) {
+ oper_t = ty::mk_box(fcx.ccx.tcx, {ty: oper_t, mut: mut});
+ }
+ ast::deref. {
+ alt structure_of(fcx, expr.span, oper_t) {
+ ty::ty_box(inner) { oper_t = inner.ty; }
+ ty::ty_res(_, inner, _) { oper_t = inner; }
+ ty::ty_tag(id, tps) {
+ let variants = ty::tag_variants(fcx.ccx.tcx, id);
+ if ivec::len(variants) != 1u ||
+ ivec::len(variants.(0).args) != 1u {
+ fcx.ccx.tcx.sess.span_fatal(expr.span,
+ "can only dereference tags " +
+ "with a single variant which has a "
+ + "single argument");
}
- case (ast::deref) {
- alt (structure_of(fcx, expr.span, oper_t)) {
- case (ty::ty_box(?inner)) { oper_t = inner.ty; }
- case (ty::ty_res(_, ?inner, _)) { oper_t = inner; }
- case (ty::ty_tag(?id, ?tps)) {
- auto variants = ty::tag_variants(fcx.ccx.tcx, id);
- if (ivec::len(variants) != 1u ||
- ivec::len(variants.(0).args) != 1u) {
- fcx.ccx.tcx.sess.span_fatal
- (expr.span, "can only dereference tags " +
- "with a single variant which has a " +
- "single argument");
- }
- oper_t = ty::substitute_type_params
- (fcx.ccx.tcx, tps, variants.(0).args.(0));
- }
- case (ty::ty_ptr(?inner)) { oper_t = inner.ty; }
- case (_) {
- fcx.ccx.tcx.sess.span_fatal
- (expr.span, "dereferencing non-" +
- "dereferenceable type: " +
- ty_to_str(fcx.ccx.tcx, oper_t));
- }
- }
- }
- case (ast::not) {
- if (!type_is_integral(fcx, oper.span, oper_t) &&
- structure_of(fcx, oper.span, oper_t) !=
- ty::ty_bool) {
- fcx.ccx.tcx.sess.span_fatal(expr.span,
- #fmt("mismatched types: \
+ oper_t =
+ ty::substitute_type_params(fcx.ccx.tcx, tps,
+ variants.(0).args.(0));
+ }
+ ty::ty_ptr(inner) { oper_t = inner.ty; }
+ _ {
+ fcx.ccx.tcx.sess.span_fatal(expr.span,
+ "dereferencing non-" +
+ "dereferenceable type: " +
+ ty_to_str(fcx.ccx.tcx,
+ oper_t));
+ }
+ }
+ }
+ ast::not. {
+ if !type_is_integral(fcx, oper.span, oper_t) &&
+ structure_of(fcx, oper.span, oper_t) != ty::ty_bool {
+ fcx.ccx.tcx.sess.span_fatal(expr.span,
+ #fmt("mismatched types: \
expected bool or \
integer but found %s",
- ty_to_str(fcx.ccx.tcx,
- oper_t)));
- }
- }
- case (_) { oper_t = do_autoderef(fcx, expr.span, oper_t); }
+ ty_to_str(fcx.ccx.tcx,
+ oper_t)));
}
- write::ty_only_fixup(fcx, id, oper_t);
+ }
+ _ { oper_t = do_autoderef(fcx, expr.span, oper_t); }
}
- case (ast::expr_path(?pth)) {
- auto defn = lookup_def(fcx, pth.span, id);
- auto tpt = ty_param_count_and_ty_for_def(fcx, expr.span, defn);
- if (ty::def_has_ty_params(defn)) {
- auto path_tpot = instantiate_path(fcx, pth, tpt, expr.span);
- write::ty_fixup(fcx, id, path_tpot);
- ret;
- }
- // The definition doesn't take type parameters. If the programmer
- // supplied some, that's an error.
+ write::ty_only_fixup(fcx, id, oper_t);
+ }
+ ast::expr_path(pth) {
+ let defn = lookup_def(fcx, pth.span, id);
+ let tpt = ty_param_count_and_ty_for_def(fcx, expr.span, defn);
+ if ty::def_has_ty_params(defn) {
+ let path_tpot = instantiate_path(fcx, pth, tpt, expr.span);
+ write::ty_fixup(fcx, id, path_tpot);
+ ret;
+ }
+ // The definition doesn't take type parameters. If the programmer
+ // supplied some, that's an error.
- if (ivec::len[@ast::ty](pth.node.types) > 0u) {
- fcx.ccx.tcx.sess.span_fatal(expr.span,
- "this kind of value does not \
+ if ivec::len[@ast::ty](pth.node.types) > 0u {
+ fcx.ccx.tcx.sess.span_fatal(expr.span,
+ "this kind of value does not \
take type parameters");
- }
- write::ty_only_fixup(fcx, id, tpt.ty);
}
- case (ast::expr_mac(_)) {
- fcx.ccx.tcx.sess.bug("unexpanded macro");
+ write::ty_only_fixup(fcx, id, tpt.ty);
+ }
+ ast::expr_mac(_) { fcx.ccx.tcx.sess.bug("unexpanded macro"); }
+ ast::expr_fail(expr_opt) {
+ alt expr_opt {
+ none. {/* do nothing */ }
+ some(e) {
+ check_expr(fcx, e);
+ let tcx = fcx.ccx.tcx;
+ let ety = expr_ty(tcx, e);
+ demand::simple(fcx, e.span, ty::mk_str(tcx), ety);
+ }
}
- case (ast::expr_fail(?expr_opt)) {
- alt (expr_opt) {
- case (none) { /* do nothing */ }
- case (some(?e)) {
- check_expr(fcx, e);
- auto tcx = fcx.ccx.tcx;
- auto ety = expr_ty(tcx, e);
- demand::simple(fcx, e.span, ty::mk_str(tcx), ety);
- }
+ write::bot_ty(fcx.ccx.tcx, id);
+ }
+ ast::expr_break. { write::bot_ty(fcx.ccx.tcx, id); }
+ ast::expr_cont. { write::bot_ty(fcx.ccx.tcx, id); }
+ ast::expr_ret(expr_opt) {
+ alt expr_opt {
+ none. {
+ let nil = ty::mk_nil(fcx.ccx.tcx);
+ if !are_compatible(fcx, fcx.ret_ty, nil) {
+ fcx.ccx.tcx.sess.span_fatal(expr.span,
+ "ret; in function \
+ returning non-nil");
}
write::bot_ty(fcx.ccx.tcx, id);
- }
- case (ast::expr_break) { write::bot_ty(fcx.ccx.tcx, id); }
- case (ast::expr_cont) { write::bot_ty(fcx.ccx.tcx, id); }
- case (ast::expr_ret(?expr_opt)) {
- alt (expr_opt) {
- case (none) {
- auto nil = ty::mk_nil(fcx.ccx.tcx);
- if (!are_compatible(fcx, fcx.ret_ty, nil)) {
- fcx.ccx.tcx.sess.span_fatal(expr.span,
- "ret; in function \
- returning non-nil");
- }
- write::bot_ty(fcx.ccx.tcx, id);
- }
- case (some(?e)) {
- check_expr(fcx, e);
- demand::simple(fcx, expr.span, fcx.ret_ty,
- expr_ty(fcx.ccx.tcx, e));
- write::bot_ty(fcx.ccx.tcx, id);
- }
- }
- }
- case (ast::expr_put(?expr_opt)) {
- require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span);
- alt (expr_opt) {
- case (none) {
- auto nil = ty::mk_nil(fcx.ccx.tcx);
- if (!are_compatible(fcx, fcx.ret_ty, nil)) {
- fcx.ccx.tcx.sess.span_fatal(expr.span,
- "put; in iterator \
- yielding non-nil");
- }
- write::nil_ty(fcx.ccx.tcx, id);
- }
- case (some(?e)) {
- check_expr(fcx, e);
- demand::simple(fcx, expr.span, fcx.ret_ty,
- expr_ty(fcx.ccx.tcx, e));
- write::nil_ty(fcx.ccx.tcx, id);
- }
- }
- }
- case (ast::expr_be(?e)) {
- // FIXME: prove instead of assert
-
- assert (ast::is_call_expr(e));
+ }
+ some(e) {
check_expr(fcx, e);
- demand::simple(fcx, e.span, fcx.ret_ty, expr_ty(fcx.ccx.tcx, e));
- write::nil_ty(fcx.ccx.tcx, id);
+ demand::simple(fcx, expr.span, fcx.ret_ty,
+ expr_ty(fcx.ccx.tcx, e));
+ write::bot_ty(fcx.ccx.tcx, id);
+ }
}
- case (ast::expr_log(?l, ?e)) {
- check_expr(fcx, e);
- write::nil_ty(fcx.ccx.tcx, id);
- }
- case (ast::expr_check(_, ?e)) {
- check_pred_expr(fcx, e);
- write::nil_ty(fcx.ccx.tcx, id);
- }
- case (ast::expr_if_check(?cond, ?thn, ?elsopt)) {
- check_pred_expr(fcx, cond);
- check_then_else(fcx, thn, elsopt, id, expr.span);
- }
- case (ast::expr_ternary(_, _, _)) {
- check_expr(fcx, ast::ternary_to_if(expr));
- }
- case (ast::expr_assert(?e)) {
- check_expr(fcx, e);
- auto ety = expr_ty(fcx.ccx.tcx, e);
- demand::simple(fcx, expr.span, ty::mk_bool(fcx.ccx.tcx), ety);
- write::nil_ty(fcx.ccx.tcx, id);
- }
- case (ast::expr_move(?lhs, ?rhs)) {
- require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span);
- check_assignment(fcx, expr.span, lhs, rhs, id);
- }
- case (ast::expr_assign(?lhs, ?rhs)) {
- require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span);
- check_assignment(fcx, expr.span, lhs, rhs, id);
- }
- case (ast::expr_swap(?lhs, ?rhs)) {
- require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span);
- check_assignment(fcx, expr.span, lhs, rhs, id);
- }
- case (ast::expr_assign_op(?op, ?lhs, ?rhs)) {
- require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span);
- check_assignment(fcx, expr.span, lhs, rhs, id);
- check_binop_type_compat(fcx, expr.span,
- expr_ty(fcx.ccx.tcx, lhs), op);
- }
- case (ast::expr_send(?lhs, ?rhs)) {
- require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span);
- check_expr(fcx, lhs);
- check_expr(fcx, rhs);
- auto rhs_t = expr_ty(fcx.ccx.tcx, rhs);
- auto chan_t = ty::mk_chan(fcx.ccx.tcx, rhs_t);
- auto lhs_t = expr_ty(fcx.ccx.tcx, lhs);
- alt (structure_of(fcx, expr.span, lhs_t)) {
- case (ty::ty_chan(?it)) { }
- case (_) {
- auto s = #fmt("mismatched types: expected chan \
- but found %s",
- ty_to_str(fcx.ccx.tcx,
- lhs_t));
- fcx.ccx.tcx.sess.span_fatal(expr.span,s);
- }
- }
- demand::simple(fcx, expr.span, chan_t, lhs_t);
- write::ty_only_fixup(fcx, id, chan_t);
- }
- case (ast::expr_recv(?lhs, ?rhs)) {
- require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span);
- check_expr(fcx, lhs);
- check_expr(fcx, rhs);
- auto item_t = expr_ty(fcx.ccx.tcx, rhs);
- auto port_t = ty::mk_port(fcx.ccx.tcx, item_t);
- demand::simple(fcx, expr.span, port_t, expr_ty(fcx.ccx.tcx, lhs));
- write::ty_only_fixup(fcx, id, item_t);
- }
- case (ast::expr_if(?cond, ?thn, ?elsopt)) {
- check_expr(fcx, cond);
- demand::simple(fcx, cond.span,
- ty::mk_bool(fcx.ccx.tcx),
- expr_ty(fcx.ccx.tcx, cond));
- check_then_else(fcx, thn, elsopt, id, expr.span);
- }
- case (ast::expr_for(?decl, ?seq, ?body)) {
- check_expr(fcx, seq);
- auto elt_ty;
- auto ety = expr_ty(fcx.ccx.tcx, seq);
- alt (structure_of(fcx, expr.span, ety)) {
- case (ty::ty_vec(?vec_elt_ty)) { elt_ty = vec_elt_ty.ty; }
- case (ty::ty_str) {
- elt_ty = ty::mk_mach(fcx.ccx.tcx, ast::ty_u8);
- }
- case (ty::ty_ivec(?vec_elt_ty)) { elt_ty = vec_elt_ty.ty; }
- case (ty::ty_istr) {
- elt_ty = ty::mk_mach(fcx.ccx.tcx, ast::ty_u8);
- }
- case (_) {
- fcx.ccx.tcx.sess.span_fatal(expr.span,
- "mismatched types: expected vector or string but " +
- "found " + ty_to_str(fcx.ccx.tcx, ety));
- }
- }
- check_for_or_for_each(fcx, decl, elt_ty, body, id);
- }
- case (ast::expr_for_each(?decl, ?seq, ?body)) {
- check_expr(fcx, seq);
- check_for_or_for_each(fcx, decl, expr_ty(fcx.ccx.tcx, seq), body,
- id);
- }
- case (ast::expr_while(?cond, ?body)) {
- check_expr(fcx, cond);
- check_block(fcx, body);
- demand::simple(fcx, cond.span, ty::mk_bool(fcx.ccx.tcx),
- expr_ty(fcx.ccx.tcx, cond));
- auto typ = ty::mk_nil(fcx.ccx.tcx);
- write::ty_only_fixup(fcx, id, typ);
- }
- case (ast::expr_do_while(?body, ?cond)) {
- check_expr(fcx, cond);
- check_block(fcx, body);
- auto typ = block_ty(fcx.ccx.tcx, body);
- write::ty_only_fixup(fcx, id, typ);
- }
- case (ast::expr_alt(?expr, ?arms)) {
- check_expr(fcx, expr);
- // Typecheck the patterns first, so that we get types for all the
- // bindings.
-
- auto pattern_ty = ty::expr_ty(fcx.ccx.tcx, expr);
- for (ast::arm arm in arms) {
- auto id_map = ast::pat_id_map(arm.pats.(0));
- for (@ast::pat p in arm.pats) {
- check_pat(fcx, id_map, p, pattern_ty);
- }
- }
- // Now typecheck the blocks.
-
- auto result_ty = next_ty_var(fcx);
- for (ast::arm arm in arms) {
- check_block(fcx, arm.block);
- auto bty = block_ty(fcx.ccx.tcx, arm.block);
-
- // Failing alt arms don't need to have a matching type
- if (!ty::type_is_bot(fcx.ccx.tcx, bty)) {
- result_ty =
- demand::simple(fcx, arm.block.span, result_ty, bty);
- }
- }
- write::ty_only_fixup(fcx, id, result_ty);
- }
- case (ast::expr_fn(?f)) {
- auto cx = @rec(tcx=fcx.ccx.tcx);
- auto convert =
- bind ast_ty_to_ty(cx.tcx, bind collect::getter(cx, _), _);
- auto ty_of_arg = bind collect::ty_of_arg(cx, _);
- auto fty =
- collect::ty_of_fn_decl(cx, convert, ty_of_arg, f.decl,
- f.proto, ~[], none).ty;
- write::ty_only_fixup(fcx, id, fty);
- check_fn(fcx.ccx, f, id, some(fcx));
- }
- case (ast::expr_block(?b)) {
- check_block(fcx, b);
- alt (b.node.expr) {
- case (some(?expr)) {
- auto typ = expr_ty(fcx.ccx.tcx, expr);
- write::ty_only_fixup(fcx, id, typ);
- }
- case (none) {
- auto typ = ty::mk_nil(fcx.ccx.tcx);
- write::ty_only_fixup(fcx, id, typ);
- }
- }
- }
- case (ast::expr_bind(?f, ?args)) {
- // Call the generic checker.
-
- check_call_or_bind(fcx, expr.span, f, args, kind_bind);
- // Pull the argument and return types out.
-
- auto proto_1;
- let ty::arg[] arg_tys_1 = ~[];
- auto rt_1;
- auto fty = expr_ty(fcx.ccx.tcx, f);
- auto t_1;
- alt (structure_of(fcx, expr.span, fty)) {
- case (ty::ty_fn(?proto, ?arg_tys, ?rt, ?cf, ?constrs)) {
- proto_1 = proto;
- rt_1 = rt;
- // FIXME:
- // probably need to munge the constrs to drop constraints
- // for any bound args
-
- // For each blank argument, add the type of that argument
- // to the resulting function type.
-
- auto i = 0u;
- while (i < ivec::len[option::t[@ast::expr]](args)) {
- alt (args.(i)) {
- case (some(_)) {/* no-op */ }
- case (none) { arg_tys_1 += ~[arg_tys.(i)]; }
- }
- i += 1u;
- }
- t_1 =
- ty::mk_fn(fcx.ccx.tcx, proto_1, arg_tys_1, rt_1, cf,
- constrs);
- }
- case (_) {
- log_err "LHS of bind expr didn't have a function type?!";
- fail;
- }
- }
- write::ty_only_fixup(fcx, id, t_1);
- }
- case (ast::expr_call(?f, ?args)) {
- /* here we're kind of hosed, as f can be any expr
- need to restrict it to being an explicit expr_path if we're
- inside a pure function, and need an environment mapping from
- function name onto purity-designation */
-
- require_pure_call(fcx.ccx, fcx.purity, f, expr.span);
- check_call(fcx, expr.span, f, args, kind_call);
- // Pull the return type out of the type of the function.
-
- auto rt_1;
- auto fty = do_autoderef(fcx, expr.span,
- ty::expr_ty(fcx.ccx.tcx, f));
- alt (structure_of(fcx, expr.span, fty)) {
- case (ty::ty_fn(_, _, ?rt, _, _)) { rt_1 = rt; }
- case (ty::ty_native_fn(_, _, ?rt)) { rt_1 = rt; }
- case (_) {
- log_err "LHS of call expr didn't have a function type?!";
- fail;
- }
- }
- write::ty_only_fixup(fcx, id, rt_1);
- }
- case (ast::expr_self_method(?ident)) {
- auto t = ty::mk_nil(fcx.ccx.tcx);
- let option::t[ty::sty] this_obj_sty =
- some(structure_of(fcx, expr.span, ty::mk_nil(fcx.ccx.tcx)));
- let option::t[obj_info] this_obj_info = get_obj_info(fcx.ccx);
- alt (this_obj_info) {
- case (some(?oinfo)) {
- alt (oinfo) {
- case (regular_obj(_, ?obj_id)) {
- auto did = local_def(obj_id);
- // Try looking up the current object in the type
- // cache.
- alt (fcx.ccx.tcx.tcache.find(did)) {
- case (some(?tpt)) {
- // If we're typechecking a self-method on
- // a regular object, this lookup should
- // succeed.
- this_obj_sty =
- some(structure_of(fcx,
- expr.span,
- tpt.ty));
- }
- case (none) {
- fcx.ccx.tcx.sess.bug(
- "didn't find " + int::str(did.node) +
- " in type cache");
- }
- }
- }
- case (anon_obj(_, ?obj_sty)) {
- this_obj_sty = obj_sty;
- }
- }
- }
- case (none) {
- // Shouldn't happen.
- fcx.ccx.tcx.sess.span_err(expr.span,
- "self-call in non-object \
- context");
- }
- }
-
- // Grab this method's type out of the current object type.
- alt (this_obj_sty) {
- case (some(?sty)) {
- alt (sty) {
- case (ty::ty_obj(?methods)) {
- for (ty::method method in methods) {
- if (method.ident == ident) {
- t = ty::method_ty_to_fn_ty(fcx.ccx.tcx,
- method);
- }
- }
- }
- case (_) { fail; }
- }
- }
- case (none) { }
- }
- write::ty_only_fixup(fcx, id, t);
- require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span);
- }
- case (ast::expr_spawn(_, _, ?f, ?args)) {
- check_call(fcx, expr.span, f, args, kind_spawn);
- auto fty = expr_ty(fcx.ccx.tcx, f);
- auto ret_ty = ty::ret_ty_of_fn_ty(fcx.ccx.tcx, fty);
- demand::simple(fcx, f.span, ty::mk_nil(fcx.ccx.tcx), ret_ty);
- // FIXME: Other typechecks needed
-
- auto typ = ty::mk_task(fcx.ccx.tcx);
- write::ty_only_fixup(fcx, id, typ);
- }
- case (ast::expr_cast(?e, ?t)) {
- check_expr(fcx, e);
- auto t_1 = ast_ty_to_ty_crate(fcx.ccx, t);
- // FIXME: there are more forms of cast to support, eventually.
-
- if (!(type_is_scalar(fcx, expr.span, expr_ty(fcx.ccx.tcx, e)) &&
- type_is_scalar(fcx, expr.span, t_1))) {
+ }
+ ast::expr_put(expr_opt) {
+ require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span);
+ alt expr_opt {
+ none. {
+ let nil = ty::mk_nil(fcx.ccx.tcx);
+ if !are_compatible(fcx, fcx.ret_ty, nil) {
fcx.ccx.tcx.sess.span_fatal(expr.span,
- "non-scalar cast: " +
- ty_to_str(fcx.ccx.tcx,
- expr_ty(fcx.ccx.tcx,
- e)) + " as " +
- ty_to_str(fcx.ccx.tcx, t_1));
+ "put; in iterator \
+ yielding non-nil");
}
- write::ty_only_fixup(fcx, id, t_1);
+ write::nil_ty(fcx.ccx.tcx, id);
+ }
+ some(e) {
+ check_expr(fcx, e);
+ demand::simple(fcx, expr.span, fcx.ret_ty,
+ expr_ty(fcx.ccx.tcx, e));
+ write::nil_ty(fcx.ccx.tcx, id);
+ }
}
- case (ast::expr_vec(?args, ?mut, ?kind)) {
- let ty::t t;
- if (ivec::len[@ast::expr](args) == 0u) {
- t = next_ty_var(fcx);
- } else {
- check_expr(fcx, args.(0));
- t = expr_ty(fcx.ccx.tcx, args.(0));
+ }
+ ast::expr_be(e) {
+ // FIXME: prove instead of assert
+
+ assert (ast::is_call_expr(e));
+ check_expr(fcx, e);
+ demand::simple(fcx, e.span, fcx.ret_ty, expr_ty(fcx.ccx.tcx, e));
+ write::nil_ty(fcx.ccx.tcx, id);
+ }
+ ast::expr_log(l, e) {
+ check_expr(fcx, e);
+ write::nil_ty(fcx.ccx.tcx, id);
+ }
+ ast::expr_check(_, e) {
+ check_pred_expr(fcx, e);
+ write::nil_ty(fcx.ccx.tcx, id);
+ }
+ ast::expr_if_check(cond, thn, elsopt) {
+ check_pred_expr(fcx, cond);
+ check_then_else(fcx, thn, elsopt, id, expr.span);
+ }
+ ast::expr_ternary(_, _, _) {
+ check_expr(fcx, ast::ternary_to_if(expr));
+ }
+ ast::expr_assert(e) {
+ check_expr(fcx, e);
+ let ety = expr_ty(fcx.ccx.tcx, e);
+ demand::simple(fcx, expr.span, ty::mk_bool(fcx.ccx.tcx), ety);
+ write::nil_ty(fcx.ccx.tcx, id);
+ }
+ ast::expr_move(lhs, rhs) {
+ require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span);
+ check_assignment(fcx, expr.span, lhs, rhs, id);
+ }
+ ast::expr_assign(lhs, rhs) {
+ require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span);
+ check_assignment(fcx, expr.span, lhs, rhs, id);
+ }
+ ast::expr_swap(lhs, rhs) {
+ require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span);
+ check_assignment(fcx, expr.span, lhs, rhs, id);
+ }
+ ast::expr_assign_op(op, lhs, rhs) {
+ require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span);
+ check_assignment(fcx, expr.span, lhs, rhs, id);
+ check_binop_type_compat(fcx, expr.span, expr_ty(fcx.ccx.tcx, lhs),
+ op);
+ }
+ ast::expr_send(lhs, rhs) {
+ require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span);
+ check_expr(fcx, lhs);
+ check_expr(fcx, rhs);
+ let rhs_t = expr_ty(fcx.ccx.tcx, rhs);
+ let chan_t = ty::mk_chan(fcx.ccx.tcx, rhs_t);
+ let lhs_t = expr_ty(fcx.ccx.tcx, lhs);
+ alt structure_of(fcx, expr.span, lhs_t) {
+ ty::ty_chan(it) { }
+ _ {
+ let s =
+ #fmt("mismatched types: expected chan \
+ but found %s",
+ ty_to_str(fcx.ccx.tcx, lhs_t));
+ fcx.ccx.tcx.sess.span_fatal(expr.span, s);
+ }
+ }
+ demand::simple(fcx, expr.span, chan_t, lhs_t);
+ write::ty_only_fixup(fcx, id, chan_t);
+ }
+ ast::expr_recv(lhs, rhs) {
+ require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span);
+ check_expr(fcx, lhs);
+ check_expr(fcx, rhs);
+ let item_t = expr_ty(fcx.ccx.tcx, rhs);
+ let port_t = ty::mk_port(fcx.ccx.tcx, item_t);
+ demand::simple(fcx, expr.span, port_t, expr_ty(fcx.ccx.tcx, lhs));
+ write::ty_only_fixup(fcx, id, item_t);
+ }
+ ast::expr_if(cond, thn, elsopt) {
+ check_expr(fcx, cond);
+ demand::simple(fcx, cond.span, ty::mk_bool(fcx.ccx.tcx),
+ expr_ty(fcx.ccx.tcx, cond));
+ check_then_else(fcx, thn, elsopt, id, expr.span);
+ }
+ ast::expr_for(decl, seq, body) {
+ check_expr(fcx, seq);
+ let elt_ty;
+ let ety = expr_ty(fcx.ccx.tcx, seq);
+ alt structure_of(fcx, expr.span, ety) {
+ ty::ty_vec(vec_elt_ty) { elt_ty = vec_elt_ty.ty; }
+ ty::ty_str. { elt_ty = ty::mk_mach(fcx.ccx.tcx, ast::ty_u8); }
+ ty::ty_ivec(vec_elt_ty) { elt_ty = vec_elt_ty.ty; }
+ ty::ty_istr. { elt_ty = ty::mk_mach(fcx.ccx.tcx, ast::ty_u8); }
+ _ {
+ fcx.ccx.tcx.sess.span_fatal(expr.span,
+ "mismatched types: expected vector or string but "
+ + "found " +
+ ty_to_str(fcx.ccx.tcx, ety));
+ }
+ }
+ check_for_or_for_each(fcx, decl, elt_ty, body, id);
+ }
+ ast::expr_for_each(decl, seq, body) {
+ check_expr(fcx, seq);
+ check_for_or_for_each(fcx, decl, expr_ty(fcx.ccx.tcx, seq), body, id);
+ }
+ ast::expr_while(cond, body) {
+ check_expr(fcx, cond);
+ check_block(fcx, body);
+ demand::simple(fcx, cond.span, ty::mk_bool(fcx.ccx.tcx),
+ expr_ty(fcx.ccx.tcx, cond));
+ let typ = ty::mk_nil(fcx.ccx.tcx);
+ write::ty_only_fixup(fcx, id, typ);
+ }
+ ast::expr_do_while(body, cond) {
+ check_expr(fcx, cond);
+ check_block(fcx, body);
+ let typ = block_ty(fcx.ccx.tcx, body);
+ write::ty_only_fixup(fcx, id, typ);
+ }
+ ast::expr_alt(expr, arms) {
+ check_expr(fcx, expr);
+ // Typecheck the patterns first, so that we get types for all the
+ // bindings.
+
+ let pattern_ty = ty::expr_ty(fcx.ccx.tcx, expr);
+ for arm: ast::arm in arms {
+ let id_map = ast::pat_id_map(arm.pats.(0));
+ for p: @ast::pat in arm.pats {
+ check_pat(fcx, id_map, p, pattern_ty);
}
- for (@ast::expr e in args) {
- check_expr(fcx, e);
- auto expr_t = expr_ty(fcx.ccx.tcx, e);
- demand::simple(fcx, expr.span, t, expr_t);
+ }
+ // Now typecheck the blocks.
+
+ let result_ty = next_ty_var(fcx);
+ for arm: ast::arm in arms {
+ check_block(fcx, arm.block);
+ let bty = block_ty(fcx.ccx.tcx, arm.block);
+
+
+ // Failing alt arms don't need to have a matching type
+ if !ty::type_is_bot(fcx.ccx.tcx, bty) {
+ result_ty =
+ demand::simple(fcx, arm.block.span, result_ty, bty);
}
- auto typ;
- alt (kind) {
- case (ast::sk_rc) {
- typ = ty::mk_vec(fcx.ccx.tcx, rec(ty=t, mut=mut));
- }
- case (ast::sk_unique) {
- typ = ty::mk_ivec(fcx.ccx.tcx, rec(ty=t, mut=mut));
- }
- }
+ }
+ write::ty_only_fixup(fcx, id, result_ty);
+ }
+ ast::expr_fn(f) {
+ let cx = @{tcx: fcx.ccx.tcx};
+ let convert =
+ bind ast_ty_to_ty(cx.tcx, bind collect::getter(cx, _), _);
+ let ty_of_arg = bind collect::ty_of_arg(cx, _);
+ let fty =
+ collect::ty_of_fn_decl(cx, convert, ty_of_arg, f.decl, f.proto,
+ ~[], none).ty;
+ write::ty_only_fixup(fcx, id, fty);
+ check_fn(fcx.ccx, f, id, some(fcx));
+ }
+ ast::expr_block(b) {
+ check_block(fcx, b);
+ alt b.node.expr {
+ some(expr) {
+ let typ = expr_ty(fcx.ccx.tcx, expr);
write::ty_only_fixup(fcx, id, typ);
+ }
+ none. {
+ let typ = ty::mk_nil(fcx.ccx.tcx);
+ write::ty_only_fixup(fcx, id, typ);
+ }
}
- case (ast::expr_rec(?fields, ?base)) {
- alt (base) {
- case (none) {/* no-op */ }
- case (some(?b_0)) { check_expr(fcx, b_0); }
- }
- let (spanned[field])[] fields_t = ~[];
- for (ast::field f in fields) {
- check_expr(fcx, f.node.expr);
- auto expr_t = expr_ty(fcx.ccx.tcx, f.node.expr);
- auto expr_mt = rec(ty=expr_t, mut=f.node.mut);
- // for the most precise error message,
- // should be f.node.expr.span, not f.span
- fields_t += ~[respan(f.node.expr.span,
- rec(ident=f.node.ident, mt=expr_mt))];
- }
- alt (base) {
- case (none) {
- fn get_node(&spanned[field] f) -> field { f.node }
- auto typ = ty::mk_rec(fcx.ccx.tcx,
- ivec::map(get_node, fields_t));
- write::ty_only_fixup(fcx, id, typ);
+ }
+ ast::expr_bind(f, args) {
+ // Call the generic checker.
+
+ check_call_or_bind(fcx, expr.span, f, args, kind_bind);
+ // Pull the argument and return types out.
+
+ let proto_1;
+ let arg_tys_1: ty::arg[] = ~[];
+ let rt_1;
+ let fty = expr_ty(fcx.ccx.tcx, f);
+ let t_1;
+ alt structure_of(fcx, expr.span, fty) {
+ ty::ty_fn(proto, arg_tys, rt, cf, constrs) {
+ proto_1 = proto;
+ rt_1 = rt;
+ // FIXME:
+ // probably need to munge the constrs to drop constraints
+ // for any bound args
+
+ // For each blank argument, add the type of that argument
+ // to the resulting function type.
+
+ let i = 0u;
+ while i < ivec::len[option::t[@ast::expr]](args) {
+ alt args.(i) {
+ some(_) {/* no-op */ }
+ none. { arg_tys_1 += ~[arg_tys.(i)]; }
}
- case (some(?bexpr)) {
- check_expr(fcx, bexpr);
- auto bexpr_t = expr_ty(fcx.ccx.tcx, bexpr);
- let field[] base_fields = ~[];
- alt (structure_of(fcx, expr.span, bexpr_t)) {
- case (ty::ty_rec(?flds)) { base_fields = flds; }
- case (_) {
- fcx.ccx.tcx.sess.span_fatal(expr.span,
- "record update \
- non-record base");
- }
- }
- write::ty_only_fixup(fcx, id, bexpr_t);
- for (spanned[ty::field] f in fields_t) {
- auto found = false;
- for (ty::field bf in base_fields) {
- if (str::eq(f.node.ident, bf.ident)) {
- demand::simple(fcx, f.span, bf.mt.ty,
- f.node.mt.ty);
- found = true;
- }
- }
- if (!found) {
- fcx.ccx.tcx.sess.span_fatal(f.span,
- "unknown field in \
- record update: "
- + f.node.ident);
- }
- }
- }
- }
- }
- case (ast::expr_field(?base, ?field)) {
- check_expr(fcx, base);
- auto base_t = expr_ty(fcx.ccx.tcx, base);
- base_t = do_autoderef(fcx, expr.span, base_t);
- alt (structure_of(fcx, expr.span, base_t)) {
- case (ty::ty_rec(?fields)) {
- let uint ix =
- ty::field_idx(fcx.ccx.tcx.sess, expr.span, field,
- fields);
- if (ix >= ivec::len[ty::field](fields)) {
- fcx.ccx.tcx.sess.span_fatal(expr.span,
- "bad index on record");
- }
- write::ty_only_fixup(fcx, id, fields.(ix).mt.ty);
- }
- case (ty::ty_obj(?methods)) {
- let uint ix =
- ty::method_idx(fcx.ccx.tcx.sess, expr.span, field,
- methods);
- if (ix >= ivec::len[ty::method](methods)) {
- fcx.ccx.tcx.sess.span_fatal(expr.span,
- "bad index on obj");
- }
- auto meth = methods.(ix);
- auto t =
- ty::mk_fn(fcx.ccx.tcx, meth.proto, meth.inputs,
- meth.output, meth.cf, meth.constrs);
- write::ty_only_fixup(fcx, id, t);
- }
- case (_) {
- auto t_err = resolve_type_vars_if_possible(fcx, base_t);
- auto msg = #fmt("attempted field access on type %s",
- ty_to_str(fcx.ccx.tcx, t_err));
- fcx.ccx.tcx.sess.span_fatal(expr.span, msg);
- }
- }
- }
- case (ast::expr_index(?base, ?idx)) {
- check_expr(fcx, base);
- auto base_t = expr_ty(fcx.ccx.tcx, base);
- base_t = do_autoderef(fcx, expr.span, base_t);
- check_expr(fcx, idx);
- auto idx_t = expr_ty(fcx.ccx.tcx, idx);
- if (!type_is_integral(fcx, idx.span, idx_t)) {
- fcx.ccx.tcx.sess.span_fatal(idx.span,
- "mismatched types: expected \
- integer but found "
- + ty_to_str(fcx.ccx.tcx, idx_t));
- }
- alt (structure_of(fcx, expr.span, base_t)) {
- case (ty::ty_vec(?mt)) {
- write::ty_only_fixup(fcx, id, mt.ty);
- }
- case (ty::ty_ivec(?mt)) {
- write::ty_only_fixup(fcx, id, mt.ty);
- }
- case (ty::ty_str) {
- auto typ = ty::mk_mach(fcx.ccx.tcx, ast::ty_u8);
- write::ty_only_fixup(fcx, id, typ);
- }
- case (ty::ty_istr) {
- auto typ = ty::mk_mach(fcx.ccx.tcx, ast::ty_u8);
- write::ty_only_fixup(fcx, id, typ);
- }
- case (_) {
- fcx.ccx.tcx.sess.span_fatal(expr.span,
- "vector-indexing bad type: " +
- ty_to_str(fcx.ccx.tcx,
- base_t));
- }
- }
- }
- case (ast::expr_port(?typ)) {
- auto t = next_ty_var(fcx);
- alt(typ) {
- case (some(?_t)) {
- demand::simple(fcx, expr.span,
- ast_ty_to_ty_crate(fcx.ccx, _t),
- t);
- }
- case (none) {}
- }
- auto pt = ty::mk_port(fcx.ccx.tcx, t);
- write::ty_only_fixup(fcx, id, pt);
- }
- case (ast::expr_chan(?x)) {
- check_expr(fcx, x);
- auto port_t = expr_ty(fcx.ccx.tcx, x);
- alt (structure_of(fcx, expr.span, port_t)) {
- case (ty::ty_port(?subtype)) {
- auto ct = ty::mk_chan(fcx.ccx.tcx, subtype);
- write::ty_only_fixup(fcx, id, ct);
- }
- case (_) {
- fcx.ccx.tcx.sess.span_fatal(expr.span,
- "bad port type: " +
- ty_to_str(fcx.ccx.tcx,
- port_t));
- }
- }
- }
- case (ast::expr_anon_obj(?ao)) {
-
- let ast::anon_obj_field[] fields = ~[];
- alt (ao.fields) {
- case (none) { }
- case (some(?v)) { fields = v; }
- }
-
- // FIXME: These next three functions are largely ripped off from
- // similar ones in collect::. Is there a better way to do this?
- fn ty_of_arg(@crate_ctxt ccx, &ast::arg a) -> ty::arg {
- auto ty_mode = ast_mode_to_mode(a.mode);
- ret rec(mode=ty_mode, ty=ast_ty_to_ty_crate(ccx, a.ty));
- }
-
- fn ty_of_method(@crate_ctxt ccx, &@ast::method m) -> ty::method {
- auto convert = bind ast_ty_to_ty_crate(ccx, _);
-
- auto inputs = ~[];
- for (ast::arg aa in m.node.meth.decl.inputs) {
- inputs += ~[ty_of_arg(ccx, aa)];
- }
-
- auto output = convert(m.node.meth.decl.output);
-
- auto out_constrs = ~[];
- for (@ast::constr constr in m.node.meth.decl.constraints) {
- out_constrs +=
- ~[ty::ast_constr_to_constr(ccx.tcx, constr)];
- }
-
- ret rec(proto=m.node.meth.proto, ident=m.node.ident,
- inputs=inputs, output=output, cf=m.node.meth.decl.cf,
- constrs=out_constrs);
- }
-
- fn get_anon_obj_method_types(@fn_ctxt fcx,
- &ast::anon_obj ao,
- &ast::anon_obj_field[] fields)
- -> ty::method[] {
-
- let ty::method[] methods = ~[];
-
- // Outer methods.
- for (@ast::method m in ao.methods) {
- methods += ~[ty_of_method(fcx.ccx, m)];
- }
-
- // Inner methods.
-
- // Typecheck 'with_obj'. If it exists, it had better have
- // object type.
- let ty::method[] with_obj_methods = ~[];
- let ty::t with_obj_ty = ty::mk_nil(fcx.ccx.tcx);
- let option::t[ty::sty] with_obj_sty = none;
- alt (ao.with_obj) {
- case (none) { }
- case (some(?e)) {
- // If there's a with_obj, we push it onto the
- // obj_infos stack so that self-calls can be checked
- // within its context later.
- check_expr(fcx, e);
- with_obj_ty = expr_ty(fcx.ccx.tcx, e);
- with_obj_sty = some(structure_of(fcx, e.span,
- with_obj_ty));
-
- alt (with_obj_sty) {
- case (none) { }
- case (some(?sty)) {
- alt (sty) {
- case (ty::ty_obj(?ms)) {
- with_obj_methods = ms;
- }
- case (_) {
- // The user is trying to extend a
- // non-object.
- fcx.ccx.tcx.sess.span_fatal(
- e.span,
- syntax::print::pprust::expr_to_str(e) +
- " does not have object type");
- }
- }
- }
- }
- }
- }
-
- fcx.ccx.obj_infos +=
- ~[anon_obj(ivec::map(ast::obj_field_from_anon_obj_field,
- fields),
- with_obj_sty)];
-
- methods += with_obj_methods;
- ret methods;
- }
-
- auto method_types = get_anon_obj_method_types(fcx, ao,
- fields);
- auto ot = ty::mk_obj(fcx.ccx.tcx, ty::sort_methods(method_types));
-
- write::ty_only_fixup(fcx, id, ot);
-
- // Write the methods into the node type table. (This happens in
- // collect::convert for regular objects.)
- auto i = 0u;
- while (i < ivec::len[@ast::method](ao.methods)) {
- write::ty_only(fcx.ccx.tcx, ao.methods.(i).node.id,
- ty::method_ty_to_fn_ty(fcx.ccx.tcx,
- method_types.(i)));
i += 1u;
}
+ t_1 =
+ ty::mk_fn(fcx.ccx.tcx, proto_1, arg_tys_1, rt_1, cf, constrs);
+ }
+ _ {
+ log_err "LHS of bind expr didn't have a function type?!";
+ fail;
+ }
+ }
+ write::ty_only_fixup(fcx, id, t_1);
+ }
+ ast::expr_call(f, args) {
+ /* here we're kind of hosed, as f can be any expr
+ need to restrict it to being an explicit expr_path if we're
+ inside a pure function, and need an environment mapping from
+ function name onto purity-designation */
- // Typecheck the methods.
- for (@ast::method method in ao.methods) {
- check_method(fcx.ccx, method);
+ require_pure_call(fcx.ccx, fcx.purity, f, expr.span);
+ check_call(fcx, expr.span, f, args, kind_call);
+ // Pull the return type out of the type of the function.
+
+ let rt_1;
+ let fty = do_autoderef(fcx, expr.span, ty::expr_ty(fcx.ccx.tcx, f));
+ alt structure_of(fcx, expr.span, fty) {
+ ty::ty_fn(_, _, rt, _, _) { rt_1 = rt; }
+ ty::ty_native_fn(_, _, rt) { rt_1 = rt; }
+ _ {
+ log_err "LHS of call expr didn't have a function type?!";
+ fail;
+ }
+ }
+ write::ty_only_fixup(fcx, id, rt_1);
+ }
+ ast::expr_self_method(ident) {
+ let t = ty::mk_nil(fcx.ccx.tcx);
+ let this_obj_sty: option::t[ty::sty] =
+ some(structure_of(fcx, expr.span, ty::mk_nil(fcx.ccx.tcx)));
+ let this_obj_info: option::t[obj_info] = get_obj_info(fcx.ccx);
+ alt this_obj_info {
+ some(oinfo) {
+ alt oinfo {
+ regular_obj(_, obj_id) {
+ let did = local_def(obj_id);
+
+ // Try looking up the current object in the type
+ // cache.
+ alt fcx.ccx.tcx.tcache.find(did) {
+ some(tpt) {
+ // If we're typechecking a self-method on
+ // a regular object, this lookup should
+ // succeed.
+ this_obj_sty = some(structure_of(fcx, expr.span, tpt.ty));
+ }
+ none. {
+ fcx.ccx.tcx.sess.bug("didn't find " + int::str(did.node) +
+ " in type cache");
+ }
+ }
+ }
+ anon_obj(_, obj_sty) { this_obj_sty = obj_sty; }
}
- next_ty_var(fcx);
+ }
+ none. {
+ // Shouldn't happen.
+ fcx.ccx.tcx.sess.span_err(expr.span,
+ "self-call in non-object \
+ context");
+ }
+ }
- // Now remove the info from the stack.
- ivec::pop[obj_info](fcx.ccx.obj_infos);
+ // Grab this method's type out of the current object type.
+ alt this_obj_sty {
+ some(sty) {
+ alt sty {
+ ty::ty_obj(methods) {
+ for method: ty::method in methods {
+ if method.ident == ident {
+ t = ty::method_ty_to_fn_ty(fcx.ccx.tcx, method);
+ }
+ }
+ }
+ _ { fail; }
+ }
+ }
+ none. { }
}
- case (_) {
- fcx.ccx.tcx.sess.unimpl("expr type in typeck::check_expr");
+ write::ty_only_fixup(fcx, id, t);
+ require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span);
+ }
+ ast::expr_spawn(_, _, f, args) {
+ check_call(fcx, expr.span, f, args, kind_spawn);
+ let fty = expr_ty(fcx.ccx.tcx, f);
+ let ret_ty = ty::ret_ty_of_fn_ty(fcx.ccx.tcx, fty);
+ demand::simple(fcx, f.span, ty::mk_nil(fcx.ccx.tcx), ret_ty);
+ // FIXME: Other typechecks needed
+
+ let typ = ty::mk_task(fcx.ccx.tcx);
+ write::ty_only_fixup(fcx, id, typ);
+ }
+ ast::expr_cast(e, t) {
+ check_expr(fcx, e);
+ let t_1 = ast_ty_to_ty_crate(fcx.ccx, t);
+ // FIXME: there are more forms of cast to support, eventually.
+
+ if !(type_is_scalar(fcx, expr.span, expr_ty(fcx.ccx.tcx, e)) &&
+ type_is_scalar(fcx, expr.span, t_1)) {
+ fcx.ccx.tcx.sess.span_fatal(expr.span,
+ "non-scalar cast: " +
+ ty_to_str(fcx.ccx.tcx,
+ expr_ty(fcx.ccx.tcx, e))
+ + " as " +
+ ty_to_str(fcx.ccx.tcx, t_1));
}
+ write::ty_only_fixup(fcx, id, t_1);
+ }
+ ast::expr_vec(args, mut, kind) {
+ let t: ty::t;
+ if ivec::len[@ast::expr](args) == 0u {
+ t = next_ty_var(fcx);
+ } else {
+ check_expr(fcx, args.(0));
+ t = expr_ty(fcx.ccx.tcx, args.(0));
+ }
+ for e: @ast::expr in args {
+ check_expr(fcx, e);
+ let expr_t = expr_ty(fcx.ccx.tcx, e);
+ demand::simple(fcx, expr.span, t, expr_t);
+ }
+ let typ;
+ alt kind {
+ ast::sk_rc. { typ = ty::mk_vec(fcx.ccx.tcx, {ty: t, mut: mut}); }
+ ast::sk_unique. {
+ typ = ty::mk_ivec(fcx.ccx.tcx, {ty: t, mut: mut});
+ }
+ }
+ write::ty_only_fixup(fcx, id, typ);
+ }
+ ast::expr_rec(fields, base) {
+ alt base { none. {/* no-op */ } some(b_0) { check_expr(fcx, b_0); } }
+ let fields_t: (spanned[field])[] = ~[];
+ for f: ast::field in fields {
+ check_expr(fcx, f.node.expr);
+ let expr_t = expr_ty(fcx.ccx.tcx, f.node.expr);
+ let expr_mt = {ty: expr_t, mut: f.node.mut};
+ // for the most precise error message,
+ // should be f.node.expr.span, not f.span
+ fields_t +=
+ ~[respan(f.node.expr.span,
+ {ident: f.node.ident, mt: expr_mt})];
+ }
+ alt base {
+ none. {
+ fn get_node(f: &spanned[field]) -> field { f.node }
+ let typ = ty::mk_rec(fcx.ccx.tcx, ivec::map(get_node, fields_t));
+ write::ty_only_fixup(fcx, id, typ);
+ }
+ some(bexpr) {
+ check_expr(fcx, bexpr);
+ let bexpr_t = expr_ty(fcx.ccx.tcx, bexpr);
+ let base_fields: field[] = ~[];
+ alt structure_of(fcx, expr.span, bexpr_t) {
+ ty::ty_rec(flds) { base_fields = flds; }
+ _ {
+ fcx.ccx.tcx.sess.span_fatal(expr.span,
+ "record update \
+ non-record base");
+ }
+ }
+ write::ty_only_fixup(fcx, id, bexpr_t);
+ for f: spanned[ty::field] in fields_t {
+ let found = false;
+ for bf: ty::field in base_fields {
+ if str::eq(f.node.ident, bf.ident) {
+ demand::simple(fcx, f.span, bf.mt.ty, f.node.mt.ty);
+ found = true;
+ }
+ }
+ if !found {
+ fcx.ccx.tcx.sess.span_fatal(f.span,
+ "unknown field in \
+ record update: "
+ + f.node.ident);
+ }
+ }
+ }
+ }
+ }
+ ast::expr_field(base, field) {
+ check_expr(fcx, base);
+ let base_t = expr_ty(fcx.ccx.tcx, base);
+ base_t = do_autoderef(fcx, expr.span, base_t);
+ alt structure_of(fcx, expr.span, base_t) {
+ ty::ty_rec(fields) {
+ let ix: uint =
+ ty::field_idx(fcx.ccx.tcx.sess, expr.span, field, fields);
+ if ix >= ivec::len[ty::field](fields) {
+ fcx.ccx.tcx.sess.span_fatal(expr.span, "bad index on record");
+ }
+ write::ty_only_fixup(fcx, id, fields.(ix).mt.ty);
+ }
+ ty::ty_obj(methods) {
+ let ix: uint =
+ ty::method_idx(fcx.ccx.tcx.sess, expr.span, field, methods);
+ if ix >= ivec::len[ty::method](methods) {
+ fcx.ccx.tcx.sess.span_fatal(expr.span, "bad index on obj");
+ }
+ let meth = methods.(ix);
+ let t =
+ ty::mk_fn(fcx.ccx.tcx, meth.proto, meth.inputs, meth.output,
+ meth.cf, meth.constrs);
+ write::ty_only_fixup(fcx, id, t);
+ }
+ _ {
+ let t_err = resolve_type_vars_if_possible(fcx, base_t);
+ let msg =
+ #fmt("attempted field access on type %s",
+ ty_to_str(fcx.ccx.tcx, t_err));
+ fcx.ccx.tcx.sess.span_fatal(expr.span, msg);
+ }
+ }
+ }
+ ast::expr_index(base, idx) {
+ check_expr(fcx, base);
+ let base_t = expr_ty(fcx.ccx.tcx, base);
+ base_t = do_autoderef(fcx, expr.span, base_t);
+ check_expr(fcx, idx);
+ let idx_t = expr_ty(fcx.ccx.tcx, idx);
+ if !type_is_integral(fcx, idx.span, idx_t) {
+ fcx.ccx.tcx.sess.span_fatal(idx.span,
+ "mismatched types: expected \
+ integer but found "
+ + ty_to_str(fcx.ccx.tcx, idx_t));
+ }
+ alt structure_of(fcx, expr.span, base_t) {
+ ty::ty_vec(mt) { write::ty_only_fixup(fcx, id, mt.ty); }
+ ty::ty_ivec(mt) { write::ty_only_fixup(fcx, id, mt.ty); }
+ ty::ty_str. {
+ let typ = ty::mk_mach(fcx.ccx.tcx, ast::ty_u8);
+ write::ty_only_fixup(fcx, id, typ);
+ }
+ ty::ty_istr. {
+ let typ = ty::mk_mach(fcx.ccx.tcx, ast::ty_u8);
+ write::ty_only_fixup(fcx, id, typ);
+ }
+ _ {
+ fcx.ccx.tcx.sess.span_fatal(expr.span,
+ "vector-indexing bad type: " +
+ ty_to_str(fcx.ccx.tcx, base_t));
+ }
+ }
+ }
+ ast::expr_port(typ) {
+ let t = next_ty_var(fcx);
+ alt typ {
+ some(_t) {
+ demand::simple(fcx, expr.span, ast_ty_to_ty_crate(fcx.ccx, _t),
+ t);
+ }
+ none. { }
+ }
+ let pt = ty::mk_port(fcx.ccx.tcx, t);
+ write::ty_only_fixup(fcx, id, pt);
+ }
+ ast::expr_chan(x) {
+ check_expr(fcx, x);
+ let port_t = expr_ty(fcx.ccx.tcx, x);
+ alt structure_of(fcx, expr.span, port_t) {
+ ty::ty_port(subtype) {
+ let ct = ty::mk_chan(fcx.ccx.tcx, subtype);
+ write::ty_only_fixup(fcx, id, ct);
+ }
+ _ {
+ fcx.ccx.tcx.sess.span_fatal(expr.span,
+ "bad port type: " +
+ ty_to_str(fcx.ccx.tcx, port_t));
+ }
+ }
+ }
+ ast::expr_anon_obj(ao) {
+
+ let fields: ast::anon_obj_field[] = ~[];
+ alt ao.fields { none. { } some(v) { fields = v; } }
+
+ // FIXME: These next three functions are largely ripped off from
+ // similar ones in collect::. Is there a better way to do this?
+ fn ty_of_arg(ccx: @crate_ctxt, a: &ast::arg) -> ty::arg {
+ let ty_mode = ast_mode_to_mode(a.mode);
+ ret {mode: ty_mode, ty: ast_ty_to_ty_crate(ccx, a.ty)};
+ }
+
+ fn ty_of_method(ccx: @crate_ctxt, m: &@ast::method) -> ty::method {
+ let convert = bind ast_ty_to_ty_crate(ccx, _);
+
+ let inputs = ~[];
+ for aa: ast::arg in m.node.meth.decl.inputs {
+ inputs += ~[ty_of_arg(ccx, aa)];
+ }
+
+ let output = convert(m.node.meth.decl.output);
+
+ let out_constrs = ~[];
+ for constr: @ast::constr in m.node.meth.decl.constraints {
+ out_constrs += ~[ty::ast_constr_to_constr(ccx.tcx, constr)];
+ }
+
+ ret {proto: m.node.meth.proto,
+ ident: m.node.ident,
+ inputs: inputs,
+ output: output,
+ cf: m.node.meth.decl.cf,
+ constrs: out_constrs};
+ }
+
+ fn get_anon_obj_method_types(fcx: @fn_ctxt, ao: &ast::anon_obj,
+ fields: &ast::anon_obj_field[]) ->
+ ty::method[] {
+
+ let methods: ty::method[] = ~[];
+
+ // Outer methods.
+ for m: @ast::method in ao.methods {
+ methods += ~[ty_of_method(fcx.ccx, m)];
+ }
+
+ // Inner methods.
+
+ // Typecheck 'with_obj'. If it exists, it had better have
+ // object type.
+ let with_obj_methods: ty::method[] = ~[];
+ let with_obj_ty: ty::t = ty::mk_nil(fcx.ccx.tcx);
+ let with_obj_sty: option::t[ty::sty] = none;
+ alt ao.with_obj {
+ none. { }
+ some(e) {
+ // If there's a with_obj, we push it onto the
+ // obj_infos stack so that self-calls can be checked
+ // within its context later.
+ check_expr(fcx, e);
+ with_obj_ty = expr_ty(fcx.ccx.tcx, e);
+ with_obj_sty = some(structure_of(fcx, e.span, with_obj_ty));
+
+
+ alt with_obj_sty {
+ none. { }
+ some(sty) {
+ alt sty {
+ ty::ty_obj(ms) { with_obj_methods = ms; }
+ _ {
+ // The user is trying to extend a
+ // non-object.
+ fcx.ccx.tcx.sess.span_fatal(e.span,
+ syntax::print::pprust::expr_to_str(e)
+ +
+ " does not have object type");
+ }
+ }
+ }
+ }
+ }
+ }
+
+ fcx.ccx.obj_infos +=
+ ~[anon_obj(ivec::map(ast::obj_field_from_anon_obj_field,
+ fields), with_obj_sty)];
+
+ methods += with_obj_methods;
+ ret methods;
+ }
+
+ let method_types = get_anon_obj_method_types(fcx, ao, fields);
+ let ot = ty::mk_obj(fcx.ccx.tcx, ty::sort_methods(method_types));
+
+ write::ty_only_fixup(fcx, id, ot);
+
+ // Write the methods into the node type table. (This happens in
+ // collect::convert for regular objects.)
+ let i = 0u;
+ while i < ivec::len[@ast::method](ao.methods) {
+ write::ty_only(fcx.ccx.tcx, ao.methods.(i).node.id,
+ ty::method_ty_to_fn_ty(fcx.ccx.tcx,
+ method_types.(i)));
+ i += 1u;
+ }
+
+ // Typecheck the methods.
+ for method: @ast::method in ao.methods {
+ check_method(fcx.ccx, method);
+ }
+ next_ty_var(fcx);
+
+ // Now remove the info from the stack.
+ ivec::pop[obj_info](fcx.ccx.obj_infos);
+ }
+ _ { fcx.ccx.tcx.sess.unimpl("expr type in typeck::check_expr"); }
}
}
-fn next_ty_var_id(@fn_ctxt fcx) -> int {
- auto id = *fcx.next_var_id;
+fn next_ty_var_id(fcx: @fn_ctxt) -> int {
+ let id = *fcx.next_var_id;
*fcx.next_var_id = fcx.next_var_id + 1;
ret id;
}
-fn next_ty_var(&@fn_ctxt fcx) -> ty::t {
+fn next_ty_var(fcx: &@fn_ctxt) -> ty::t {
ret ty::mk_var(fcx.ccx.tcx, next_ty_var_id(fcx));
}
-fn get_obj_info(&@crate_ctxt ccx) -> option::t[obj_info] {
+fn get_obj_info(ccx: &@crate_ctxt) -> option::t[obj_info] {
ret ivec::last[obj_info](ccx.obj_infos);
}
-fn check_decl_initializer(&@fn_ctxt fcx, ast::node_id nid,
- &ast::initializer init) {
+fn check_decl_initializer(fcx: &@fn_ctxt, nid: ast::node_id,
+ init: &ast::initializer) {
check_expr(fcx, init.expr);
- auto lty = ty::mk_var(fcx.ccx.tcx,
- lookup_local(fcx, init.expr.span, nid));
- alt (init.op) {
- case (ast::init_assign) {
- demand::simple(fcx, init.expr.span, lty,
- expr_ty(fcx.ccx.tcx, init.expr));
- }
- case (ast::init_move) {
- demand::simple(fcx, init.expr.span, lty,
- expr_ty(fcx.ccx.tcx, init.expr));
- }
- case (ast::init_recv) {
- auto port_ty = ty::mk_port(fcx.ccx.tcx, lty);
- demand::simple(fcx, init.expr.span, port_ty,
- expr_ty(fcx.ccx.tcx, init.expr));
- }
+ let lty = ty::mk_var(fcx.ccx.tcx, lookup_local(fcx, init.expr.span, nid));
+ alt init.op {
+ ast::init_assign. {
+ demand::simple(fcx, init.expr.span, lty,
+ expr_ty(fcx.ccx.tcx, init.expr));
+ }
+ ast::init_move. {
+ demand::simple(fcx, init.expr.span, lty,
+ expr_ty(fcx.ccx.tcx, init.expr));
+ }
+ ast::init_recv. {
+ let port_ty = ty::mk_port(fcx.ccx.tcx, lty);
+ demand::simple(fcx, init.expr.span, port_ty,
+ expr_ty(fcx.ccx.tcx, init.expr));
+ }
}
}
-fn check_decl_local(&@fn_ctxt fcx, &@ast::local local) {
- auto a_id = local.node.id;
- alt (fcx.locals.find(a_id)) {
- case (none) {
- fcx.ccx.tcx.sess.bug("check_decl_local: local id not found " +
+fn check_decl_local(fcx: &@fn_ctxt, local: &@ast::local) {
+ let a_id = local.node.id;
+ alt fcx.locals.find(a_id) {
+ none. {
+ fcx.ccx.tcx.sess.bug("check_decl_local: local id not found " +
local.node.ident);
+ }
+ some(i) {
+ let t = ty::mk_var(fcx.ccx.tcx, i);
+ write::ty_only_fixup(fcx, a_id, t);
+ alt local.node.init {
+ some(init) { check_decl_initializer(fcx, local.node.id, init); }
+ _ {/* fall through */ }
}
- case (some(?i)) {
- auto t = ty::mk_var(fcx.ccx.tcx, i);
- write::ty_only_fixup(fcx, a_id, t);
- alt (local.node.init) {
- case (some(?init)) {
- check_decl_initializer(fcx, local.node.id, init);
- }
- case (_) {/* fall through */ }
- }
- }
+ }
}
}
-fn check_stmt(&@fn_ctxt fcx, &@ast::stmt stmt) {
- auto node_id;
- alt (stmt.node) {
- case (ast::stmt_decl(?decl, ?id)) {
- node_id = id;
- alt (decl.node) {
- case (ast::decl_local(?ls)) {
- for (@ast::local l in ls) { check_decl_local(fcx, l); }
- }
- case (ast::decl_item(_)) {/* ignore for now */ }
- }
+fn check_stmt(fcx: &@fn_ctxt, stmt: &@ast::stmt) {
+ let node_id;
+ alt stmt.node {
+ ast::stmt_decl(decl, id) {
+ node_id = id;
+ alt decl.node {
+ ast::decl_local(ls) {
+ for l: @ast::local in ls { check_decl_local(fcx, l); }
+ }
+ ast::decl_item(_) {/* ignore for now */ }
}
- case (ast::stmt_expr(?expr, ?id)) {
- node_id = id;
- check_expr(fcx, expr);
- }
+ }
+ ast::stmt_expr(expr, id) { node_id = id; check_expr(fcx, expr); }
}
write::nil_ty(fcx.ccx.tcx, node_id);
}
-fn check_block(&@fn_ctxt fcx, &ast::blk blk) {
- for (@ast::stmt s in blk.node.stmts) { check_stmt(fcx, s); }
- alt (blk.node.expr) {
- case (none) { write::nil_ty(fcx.ccx.tcx, blk.node.id); }
- case (some(?e)) {
- check_expr(fcx, e);
- auto ety = expr_ty(fcx.ccx.tcx, e);
- write::ty_only_fixup(fcx, blk.node.id, ety);
- }
+fn check_block(fcx: &@fn_ctxt, blk: &ast::blk) {
+ for s: @ast::stmt in blk.node.stmts { check_stmt(fcx, s); }
+ alt blk.node.expr {
+ none. { write::nil_ty(fcx.ccx.tcx, blk.node.id); }
+ some(e) {
+ check_expr(fcx, e);
+ let ety = expr_ty(fcx.ccx.tcx, e);
+ write::ty_only_fixup(fcx, blk.node.id, ety);
+ }
}
}
-fn check_const(&@crate_ctxt ccx, &span sp, &@ast::expr e, &ast::node_id id) {
+fn check_const(ccx: &@crate_ctxt, sp: &span, e: &@ast::expr,
+ id: &ast::node_id) {
// FIXME: this is kinda a kludge; we manufacture a fake function context
// and statement context for checking the initializer expression.
- auto rty = node_id_to_type(ccx.tcx, id);
- let ast::node_id[] fixups = ~[];
- let @fn_ctxt fcx =
- @rec(ret_ty=rty,
- purity=ast::pure_fn,
- var_bindings=ty::unify::mk_var_bindings(),
- locals=new_int_hash[int](),
- local_names=new_int_hash[ast::ident](),
- next_var_id=@mutable 0,
- mutable fixups=fixups,
- ccx=ccx);
+ let rty = node_id_to_type(ccx.tcx, id);
+ let fixups: ast::node_id[] = ~[];
+ let fcx: @fn_ctxt =
+ @{ret_ty: rty,
+ purity: ast::pure_fn,
+ var_bindings: ty::unify::mk_var_bindings(),
+ locals: new_int_hash[int](),
+ local_names: new_int_hash[ast::ident](),
+ next_var_id: @mutable 0,
+ mutable fixups: fixups,
+ ccx: ccx};
check_expr(fcx, e);
}
-fn check_fn(&@crate_ctxt ccx, &ast::_fn f, &ast::node_id id,
- &option::t[@fn_ctxt] old_fcx) {
- auto decl = f.decl;
- auto body = f.body;
- auto gather_result = gather_locals(ccx, f, id, old_fcx);
- let ast::node_id[] fixups = ~[];
- let @fn_ctxt fcx =
- @rec(ret_ty=ast_ty_to_ty_crate(ccx, decl.output),
- purity=decl.purity,
- var_bindings=gather_result.var_bindings,
- locals=gather_result.locals,
- local_names=gather_result.local_names,
- next_var_id=gather_result.next_var_id,
- mutable fixups=fixups,
- ccx=ccx);
+fn check_fn(ccx: &@crate_ctxt, f: &ast::_fn, id: &ast::node_id,
+ old_fcx: &option::t[@fn_ctxt]) {
+ let decl = f.decl;
+ let body = f.body;
+ let gather_result = gather_locals(ccx, f, id, old_fcx);
+ let fixups: ast::node_id[] = ~[];
+ let fcx: @fn_ctxt =
+ @{ret_ty: ast_ty_to_ty_crate(ccx, decl.output),
+ purity: decl.purity,
+ var_bindings: gather_result.var_bindings,
+ locals: gather_result.locals,
+ local_names: gather_result.local_names,
+ next_var_id: gather_result.next_var_id,
+ mutable fixups: fixups,
+ ccx: ccx};
check_block(fcx, body);
- alt (decl.purity) {
- case (ast::pure_fn) {
- // This just checks that the declared type is bool, and trusts
- // that that's the actual return type.
- if (!ty::type_is_bool(ccx.tcx, fcx.ret_ty)) {
- ccx.tcx.sess.span_fatal(body.span,
- "Non-boolean return type in pred");
- }
+ alt decl.purity {
+ ast::pure_fn. {
+
+ // This just checks that the declared type is bool, and trusts
+ // that that's the actual return type.
+ if !ty::type_is_bool(ccx.tcx, fcx.ret_ty) {
+ ccx.tcx.sess.span_fatal(body.span,
+ "Non-boolean return type in pred");
}
- case (_) { }
+ }
+ _ { }
}
- if (option::is_some(body.node.expr)) {
- auto tail_expr = option::get(body.node.expr);
- auto tail_expr_ty = expr_ty(ccx.tcx, tail_expr);
+ if option::is_some(body.node.expr) {
+ let tail_expr = option::get(body.node.expr);
+ let tail_expr_ty = expr_ty(ccx.tcx, tail_expr);
// Have to exclude ty_nil to allow functions to end in
// while expressions, etc.
- auto nil = ty::mk_nil(fcx.ccx.tcx);
- if (!are_compatible(fcx, nil, tail_expr_ty)) {
- demand::simple(fcx, tail_expr.span,
- fcx.ret_ty, tail_expr_ty);
+ let nil = ty::mk_nil(fcx.ccx.tcx);
+ if !are_compatible(fcx, nil, tail_expr_ty) {
+ demand::simple(fcx, tail_expr.span, fcx.ret_ty, tail_expr_ty);
}
}
writeback::resolve_type_vars_in_block(fcx, body);
}
-fn check_method(&@crate_ctxt ccx, &@ast::method method) {
+fn check_method(ccx: &@crate_ctxt, method: &@ast::method) {
check_fn(ccx, method.node.meth, method.node.id, none);
}
-fn check_item(@crate_ctxt ccx, &@ast::item it) {
- alt (it.node) {
- case (ast::item_const(_, ?e)) {
- check_const(ccx, it.span, e, it.id);
- }
- case (ast::item_fn(?f, _)) {
- check_fn(ccx, f, it.id, none);
- }
- case (ast::item_res(?f, ?dtor_id, _, _)) {
- check_fn(ccx, f, dtor_id, none);
- }
- case (ast::item_obj(?ob, _, _)) {
- // We're entering an object, so gather up the info we need.
- ccx.obj_infos += ~[regular_obj(ob.fields, it.id)];
+fn check_item(ccx: @crate_ctxt, it: &@ast::item) {
+ alt it.node {
+ ast::item_const(_, e) { check_const(ccx, it.span, e, it.id); }
+ ast::item_fn(f, _) { check_fn(ccx, f, it.id, none); }
+ ast::item_res(f, dtor_id, _, _) { check_fn(ccx, f, dtor_id, none); }
+ ast::item_obj(ob, _, _) {
+ // We're entering an object, so gather up the info we need.
+ ccx.obj_infos += ~[regular_obj(ob.fields, it.id)];
- // Typecheck the methods.
- for (@ast::method method in ob.methods) {
- check_method(ccx, method);
- }
- option::may[@ast::method](bind check_method(ccx, _), ob.dtor);
+ // Typecheck the methods.
+ for method: @ast::method in ob.methods { check_method(ccx, method); }
+ option::may[@ast::method](bind check_method(ccx, _), ob.dtor);
- // Now remove the info from the stack.
- ivec::pop[obj_info](ccx.obj_infos);
- }
- case (_) {/* nothing to do */ }
+ // Now remove the info from the stack.
+ ivec::pop[obj_info](ccx.obj_infos);
+ }
+ _ {/* nothing to do */ }
}
}
-fn arg_is_argv_ty(&ty::ctxt tcx, &ty::arg a) -> bool {
- alt (ty::struct(tcx, a.ty)) {
- case (ty::ty_vec(?mt)) {
- if (mt.mut != ast::imm) { ret false; }
- alt (ty::struct(tcx, mt.ty)) {
- case (ty::ty_str) { ret true; }
- case (_) { ret false; }
- }
+fn arg_is_argv_ty(tcx: &ty::ctxt, a: &ty::arg) -> bool {
+ alt ty::struct(tcx, a.ty) {
+ ty::ty_vec(mt) {
+ if mt.mut != ast::imm { ret false; }
+ alt ty::struct(tcx, mt.ty) {
+ ty::ty_str. { ret true; }
+ _ { ret false; }
}
- case (_) { ret false; }
+ }
+ _ { ret false; }
}
}
-fn check_main_fn_ty(&ty::ctxt tcx, &ast::node_id main_id) {
- auto main_t = ty::node_id_to_monotype(tcx, main_id);
- alt (ty::struct(tcx, main_t)) {
- case (ty::ty_fn(ast::proto_fn, ?args, ?rs, ast::return, ?constrs)) {
- auto ok = ivec::len(constrs) == 0u;
- ok &= ty::type_is_nil(tcx, rs);
- auto num_args = ivec::len(args);
- ok &= num_args == 0u || (num_args == 1u &&
- arg_is_argv_ty(tcx, args.(0)));
- if (!ok) {
- tcx.sess.err("Wrong type in main function: found "
- + ty_to_str(tcx, main_t));
- }
+fn check_main_fn_ty(tcx: &ty::ctxt, main_id: &ast::node_id) {
+ let main_t = ty::node_id_to_monotype(tcx, main_id);
+ alt ty::struct(tcx, main_t) {
+ ty::ty_fn(ast::proto_fn., args, rs, ast::return., constrs) {
+ let ok = ivec::len(constrs) == 0u;
+ ok &= ty::type_is_nil(tcx, rs);
+ let num_args = ivec::len(args);
+ ok &=
+ num_args == 0u || num_args == 1u && arg_is_argv_ty(tcx, args.(0));
+ if !ok {
+ tcx.sess.err("Wrong type in main function: found " +
+ ty_to_str(tcx, main_t));
}
- case (_) {
- tcx.sess.err("Main has a non-function type: found"
- + ty_to_str(tcx, main_t));
+ }
+ _ {
+ tcx.sess.err("Main has a non-function type: found" +
+ ty_to_str(tcx, main_t));
+ }
+ }
+}
+
+fn check_for_main_fn(tcx: &ty::ctxt, crate: &@ast::crate) {
+ if !tcx.sess.get_opts().library {
+ alt tcx.sess.get_main_id() {
+ some(id) { check_main_fn_ty(tcx, id); }
+ none. { tcx.sess.span_err(crate.span, "Main function not found"); }
}
}
}
-fn check_for_main_fn(&ty::ctxt tcx, &@ast::crate crate) {
- if (!tcx.sess.get_opts().library) {
- alt (tcx.sess.get_main_id()) {
- case (some(?id)) {
- check_main_fn_ty(tcx, id);
- }
- case (none) {
- tcx.sess.span_err(crate.span,
- "Main function not found");
- }
- }
- }
-}
-
-fn check_crate(&ty::ctxt tcx, &@ast::crate crate) {
+fn check_crate(tcx: &ty::ctxt, crate: &@ast::crate) {
collect::collect_item_types(tcx, crate);
- let obj_info[] obj_infos = ~[];
+ let obj_infos: obj_info[] = ~[];
- auto ccx =
- @rec(mutable obj_infos=obj_infos, tcx=tcx);
- auto visit =
- rec(visit_item_pre=bind check_item(ccx, _)
- with walk::default_visitor());
+ let ccx = @{mutable obj_infos: obj_infos, tcx: tcx};
+ let visit =
+ {visit_item_pre: bind check_item(ccx, _)
+ with walk::default_visitor()};
walk::walk_crate(visit, *crate);
check_for_main_fn(tcx, crate);
tcx.sess.abort_if_errors();
diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs
index ca12c15..14375e5 100644
--- a/src/comp/syntax/ast.rs
+++ b/src/comp/syntax/ast.rs
@@ -6,8 +6,8 @@
import codemap::span;
import codemap::filename;
-type spanned[T] = rec(T node, span span);
-fn respan[T](&span sp, &T t) -> spanned[T] { ret rec(node=t, span=sp); }
+type spanned[T] = {node: T, span: span};
+fn respan[T](sp: &span, t: &T) -> spanned[T] { ret {node: t, span: sp}; }
type ident = str;
// Functions may or may not have names.
@@ -16,22 +16,20 @@
// FIXME: with typestate constraint, could say
// idents and types are the same length, and are
// non-empty
-type path_ = rec(bool global, ident[] idents, (@ty)[] types);
+type path_ = {global: bool, idents: ident[], types: (@ty)[]};
type path = spanned[path_];
-fn path_name(&path p) -> str { path_name_i(p.node.idents) }
+fn path_name(p: &path) -> str { path_name_i(p.node.idents) }
-fn path_name_i(&ident[] idents) -> str { str::connect_ivec(idents, "::") }
+fn path_name_i(idents: &ident[]) -> str { str::connect_ivec(idents, "::") }
type crate_num = int;
type node_id = int;
-type def_id = rec(crate_num crate, node_id node);
+type def_id = {crate: crate_num, node: node_id};
-const crate_num local_crate = 0;
-fn local_def(node_id id) -> def_id {
- ret rec(crate=local_crate, node=id);
-}
+const local_crate: crate_num = 0;
+fn local_def(id: node_id) -> def_id { ret {crate: local_crate, node: id}; }
type ty_param = ident;
@@ -45,6 +43,7 @@
def_local(def_id);
def_variant(def_id, /* tag */def_id);
+
/* variant */
def_ty(def_id);
def_ty_arg(uint);
@@ -53,37 +52,34 @@
def_native_ty(def_id);
def_native_fn(def_id);
+
/* A "fake" def for upvars. This never appears in the def_map, but
* freevars::def_lookup will return it for a def that is an upvar.
* It contains the actual def. */
def_upvar(def_id, @def);
}
-fn variant_def_ids(&def d) -> rec(def_id tg, def_id var) {
- alt (d) {
- case (def_variant(?tag_id, ?var_id)) {
- ret rec(tg=tag_id, var=var_id);
- }
- }
+fn variant_def_ids(d: &def) -> {tg: def_id, var: def_id} {
+ alt d { def_variant(tag_id, var_id) { ret {tg: tag_id, var: var_id}; } }
}
-fn def_id_of_def(def d) -> def_id {
- alt (d) {
- case (def_fn(?id,_)) { ret id; }
- case (def_obj_field(?id)) { ret id; }
- case (def_mod(?id)) { ret id; }
- case (def_native_mod(?id)) { ret id; }
- case (def_const(?id)) { ret id; }
- case (def_arg(?id)) { ret id; }
- case (def_local(?id)) { ret id; }
- case (def_variant(_, ?id)) { ret id; }
- case (def_ty(?id)) { ret id; }
- case (def_ty_arg(_)) { fail; }
- case (def_binding(?id)) { ret id; }
- case (def_use(?id)) { ret id; }
- case (def_native_ty(?id)) { ret id; }
- case (def_native_fn(?id)) { ret id; }
- case (def_upvar(?id, _)) { ret id; }
+fn def_id_of_def(d: def) -> def_id {
+ alt d {
+ def_fn(id, _) { ret id; }
+ def_obj_field(id) { ret id; }
+ def_mod(id) { ret id; }
+ def_native_mod(id) { ret id; }
+ def_const(id) { ret id; }
+ def_arg(id) { ret id; }
+ def_local(id) { ret id; }
+ def_variant(_, id) { ret id; }
+ def_ty(id) { ret id; }
+ def_ty_arg(_) { fail; }
+ def_binding(id) { ret id; }
+ def_use(id) { ret id; }
+ def_native_ty(id) { ret id; }
+ def_native_fn(id) { ret id; }
+ def_upvar(id, _) { ret id; }
}
fail;
}
@@ -94,15 +90,18 @@
type crate = spanned[crate_];
-type crate_ = rec((@crate_directive)[] directives,
- _mod module,
- attribute[] attrs,
- crate_cfg config);
+type crate_ =
+ {directives: (@crate_directive)[],
+ module: _mod,
+ attrs: attribute[],
+ config: crate_cfg};
tag crate_directive_ {
cdir_src_mod(ident, option::t[filename], attribute[]);
- cdir_dir_mod(ident, option::t[filename],
- (@crate_directive)[], attribute[]);
+ cdir_dir_mod(ident,
+ option::t[filename],
+ (@crate_directive)[],
+ attribute[]);
cdir_view_item(@view_item);
cdir_syntax(path);
cdir_auth(path, _auth);
@@ -120,13 +119,11 @@
type blk = spanned[blk_];
-type blk_ = rec((@stmt)[] stmts, option::t[@expr] expr, node_id id);
+type blk_ = {stmts: (@stmt)[], expr: option::t[@expr], id: node_id};
-type pat = rec(node_id id,
- pat_ node,
- span span);
+type pat = {id: node_id, node: pat_, span: span};
-type field_pat = rec(ident ident, @pat pat);
+type field_pat = {ident: ident, pat: @pat};
tag pat_ {
pat_wild;
@@ -141,19 +138,17 @@
// This is used because same-named variables in alternative patterns need to
// use the node_id of their namesake in the first pattern.
-fn pat_id_map(&@pat pat) -> pat_id_map {
- auto map = std::map::new_str_hash[node_id]();
- fn walk(&pat_id_map map, &@pat pat) {
- alt (pat.node) {
- pat_bind(?name) { map.insert(name, pat.id); }
- pat_tag(_, ?sub) {
- for (@pat p in sub) { walk(map, p); }
- }
- pat_rec(?fields, _) {
- for (field_pat f in fields) { walk(map, f.pat); }
- }
- pat_box(?inner) { walk(map, inner); }
- _ {}
+fn pat_id_map(pat: &@pat) -> pat_id_map {
+ let map = std::map::new_str_hash[node_id]();
+ fn walk(map: &pat_id_map, pat: &@pat) {
+ alt pat.node {
+ pat_bind(name) { map.insert(name, pat.id); }
+ pat_tag(_, sub) { for p: @pat in sub { walk(map, p); } }
+ pat_rec(fields, _) {
+ for f: field_pat in fields { walk(map, f.pat); }
+ }
+ pat_box(inner) { walk(map, inner); }
+ _ { }
}
}
walk(map, pat);
@@ -190,46 +185,42 @@
gt;
}
-fn binop_to_str(binop op) -> str {
- alt (op) {
- case (add) { ret "+"; }
- case (sub) { ret "-"; }
- case (mul) { ret "*"; }
- case (div) { ret "/"; }
- case (rem) { ret "%"; }
- case (and) { ret "&&"; }
- case (or) { ret "||"; }
- case (bitxor) { ret "^"; }
- case (bitand) { ret "&"; }
- case (bitor) { ret "|"; }
- case (lsl) { ret "<<"; }
- case (lsr) { ret ">>"; }
- case (asr) { ret ">>>"; }
- case (eq) { ret "=="; }
- case (lt) { ret "<"; }
- case (le) { ret "<="; }
- case (ne) { ret "!="; }
- case (ge) { ret ">="; }
- case (gt) { ret ">"; }
+fn binop_to_str(op: binop) -> str {
+ alt op {
+ add. { ret "+"; }
+ sub. { ret "-"; }
+ mul. { ret "*"; }
+ div. { ret "/"; }
+ rem. { ret "%"; }
+ and. { ret "&&"; }
+ or. { ret "||"; }
+ bitxor. { ret "^"; }
+ bitand. { ret "&"; }
+ bitor. { ret "|"; }
+ lsl. { ret "<<"; }
+ lsr. { ret ">>"; }
+ asr. { ret ">>>"; }
+ eq. { ret "=="; }
+ lt. { ret "<"; }
+ le. { ret "<="; }
+ ne. { ret "!="; }
+ ge. { ret ">="; }
+ gt. { ret ">"; }
}
}
-pred lazy_binop(binop b) -> bool {
- alt (b) {
- case (and) { true }
- case (or) { true }
- case (_) { false }
- }
+pred lazy_binop(b: binop) -> bool {
+ alt b { and. { true } or. { true } _ { false } }
}
tag unop { box(mutability); deref; not; neg; }
-fn unop_to_str(unop op) -> str {
- alt (op) {
- case (box(?mt)) { if (mt == mut) { ret "@mutable "; } ret "@"; }
- case (deref) { ret "*"; }
- case (not) { ret "!"; }
- case (neg) { ret "-"; }
+fn unop_to_str(op: unop) -> str {
+ alt op {
+ box(mt) { if mt == mut { ret "@mutable "; } ret "@"; }
+ deref. { ret "*"; }
+ not. { ret "!"; }
+ neg. { ret "-"; }
}
}
@@ -241,20 +232,21 @@
stmt_decl(@decl, node_id);
stmt_expr(@expr, node_id);
+
// These only exist in crate-level blocks.
stmt_crate_directive(@crate_directive);
}
tag init_op { init_assign; init_recv; init_move; }
-type initializer = rec(init_op op, @expr expr);
+type initializer = {op: init_op, expr: @expr};
type local_ =
- rec(option::t[@ty] ty,
- bool infer,
- ident ident,
- option::t[initializer] init,
- node_id id);
+ {ty: option::t[@ty],
+ infer: bool,
+ ident: ident,
+ init: option::t[initializer],
+ id: node_id};
type local = spanned[local_];
@@ -262,11 +254,11 @@
tag decl_ { decl_local((@local)[]); decl_item(@item); }
-type arm = rec((@pat)[] pats, blk block);
+type arm = {pats: (@pat)[], block: blk};
-type elt = rec(mutability mut, @expr expr);
+type elt = {mut: mutability, expr: @expr};
-type field_ = rec(mutability mut, ident ident, @expr expr);
+type field_ = {mut: mutability, ident: ident, expr: @expr};
type field = spanned[field_];
@@ -277,9 +269,7 @@
// FIXME: temporary
tag seq_kind { sk_unique; sk_rc; }
-type expr = rec(node_id id,
- expr_ node,
- span span);
+type expr = {id: node_id, node: expr_, span: span};
tag expr_ {
expr_vec((@expr)[], mutability, seq_kind);
@@ -301,12 +291,13 @@
expr_alt(@expr, arm[]);
expr_fn(_fn);
expr_block(blk);
+
/*
* FIXME: many of these @exprs should be constrained with
* is_lval once we have constrained types working.
*/
expr_move(@expr, @expr);
- expr_assign(@expr,@expr);
+ expr_assign(@expr, @expr);
expr_swap(@expr, @expr);
expr_assign_op(binop, @expr, @expr);
expr_send(@expr, @expr);
@@ -322,13 +313,16 @@
expr_be(@expr);
expr_log(int, @expr);
+
/* just an assert, no significance to typestate */
expr_assert(@expr);
+
/* preds that typestate is aware of */
expr_check(check_mode, @expr);
- /* FIXME Would be nice if expr_check desugared
- to expr_if_check. */
+
+ /* FIXME Would be nice if expr_check desugared
+ to expr_if_check. */
expr_if_check(@expr, blk, option::t[@expr]);
expr_port(option::t[@ty]);
expr_chan(@expr);
@@ -359,29 +353,26 @@
lit_bool(bool);
}
-fn is_path(&@expr e) -> bool {
- ret alt (e.node) {
- case (expr_path(_)) { true }
- case (_) { false }
- };
+fn is_path(e: &@expr) -> bool {
+ ret alt e.node { expr_path(_) { true } _ { false } };
}
// NB: If you change this, you'll probably want to change the corresponding
// type structure in middle/ty.rs as well.
-type mt = rec(@ty ty, mutability mut);
+type mt = {ty: @ty, mut: mutability};
-type ty_field_ = rec(ident ident, mt mt);
+type ty_field_ = {ident: ident, mt: mt};
-type ty_arg_ = rec(mode mode, @ty ty);
+type ty_arg_ = {mode: mode, ty: @ty};
type ty_method_ =
- rec(proto proto,
- ident ident,
- ty_arg[] inputs,
- @ty output,
- controlflow cf,
- (@constr)[] constrs);
+ {proto: proto,
+ ident: ident,
+ inputs: ty_arg[],
+ output: @ty,
+ cf: controlflow,
+ constrs: (@constr)[]};
type ty_field = spanned[ty_field_];
@@ -402,18 +393,18 @@
ty_f64;
}
-fn ty_mach_to_str(ty_mach tm) -> str {
- alt (tm) {
- case (ty_u8) { ret "u8"; }
- case (ty_u16) { ret "u16"; }
- case (ty_u32) { ret "u32"; }
- case (ty_u64) { ret "u64"; }
- case (ty_i8) { ret "i8"; }
- case (ty_i16) { ret "i16"; }
- case (ty_i32) { ret "i32"; }
- case (ty_i64) { ret "i64"; }
- case (ty_f32) { ret "f32"; }
- case (ty_f64) { ret "f64"; }
+fn ty_mach_to_str(tm: ty_mach) -> str {
+ alt tm {
+ ty_u8. { ret "u8"; }
+ ty_u16. { ret "u16"; }
+ ty_u32. { ret "u32"; }
+ ty_u64. { ret "u64"; }
+ ty_i8. { ret "i8"; }
+ ty_i16. { ret "i16"; }
+ ty_i32. { ret "i32"; }
+ ty_i64. { ret "i64"; }
+ ty_f32. { ret "f32"; }
+ ty_f64. { ret "f64"; }
}
}
@@ -425,10 +416,12 @@
ret/fail/break/cont. there is no syntax
for this type. */
+
+
/* bot represents the value of functions that don't return a value
locally to their context. in contrast, things like log that do
return, but don't return a meaningful value, have result type nil. */
- ty_bool;
+ ty_bool;
ty_int;
ty_uint;
ty_float;
@@ -437,10 +430,14 @@
ty_str;
ty_istr; // interior string
+
+
ty_box(mt);
ty_vec(mt);
ty_ivec(mt); // interior vector
+
+
ty_ptr(mt);
ty_task;
ty_port(@ty);
@@ -475,8 +472,8 @@
// The implicit root of such path, in the constraint-list for a
// constrained type, is * (referring to the base record)
-type constr_general_[ARG, ID] = rec(path path,
- (@(spanned[constr_arg_general_[ARG]]))[] args, ID id);
+type constr_general_[ARG, ID] =
+ {path: path, args: (@spanned[constr_arg_general_[ARG]])[], id: ID};
// In the front end, constraints have a node ID attached.
// Typeck turns this to a def_id, using the output of resolve.
@@ -489,18 +486,20 @@
/* The parser generates ast::constrs; resolve generates
a mapping from each function to a list of ty::constr_defs,
corresponding to these. */
-type arg = rec(mode mode, @ty ty, ident ident, node_id id);
+type arg = {mode: mode, ty: @ty, ident: ident, id: node_id};
type fn_decl =
- rec(arg[] inputs,
- @ty output,
- purity purity,
- controlflow cf,
- (@constr)[] constraints);
+ {inputs: arg[],
+ output: @ty,
+ purity: purity,
+ cf: controlflow,
+ constraints: (@constr)[]};
tag purity {
pure_fn; // declared with "pred"
+
+
impure_fn; // declared with "fn"
}
@@ -509,33 +508,34 @@
noreturn; // functions with return type _|_ that always
// raise an error or exit (i.e. never return to the caller)
+
+
return; // everything else
}
-type _fn = rec(fn_decl decl, proto proto, blk body);
+type _fn = {decl: fn_decl, proto: proto, body: blk};
-type method_ = rec(ident ident, _fn meth, node_id id);
+type method_ = {ident: ident, meth: _fn, id: node_id};
type method = spanned[method_];
-type obj_field = rec(mutability mut, @ty ty, ident ident, node_id id);
-type anon_obj_field = rec(mutability mut, @ty ty, @expr expr, ident ident,
- node_id id);
+type obj_field = {mut: mutability, ty: @ty, ident: ident, id: node_id};
+type anon_obj_field =
+ {mut: mutability, ty: @ty, expr: @expr, ident: ident, id: node_id};
type _obj =
- rec(obj_field[] fields, (@method)[] methods, option::t[@method] dtor);
+ {fields: obj_field[], methods: (@method)[], dtor: option::t[@method]};
type anon_obj =
- rec(
- // New fields and methods, if they exist.
- option::t[anon_obj_field[]] fields,
- (@method)[] methods,
+ // New fields and methods, if they exist.
- // with_obj: the original object being extended, if it exists.
- option::t[@expr] with_obj);
+ // with_obj: the original object being extended, if it exists.
+ {fields: option::t[anon_obj_field[]],
+ methods: (@method)[],
+ with_obj: option::t[@expr]};
-type _mod = rec((@view_item)[] view_items, (@item)[] items);
+type _mod = {view_items: (@view_item)[], items: (@item)[]};
tag native_abi {
native_abi_rust;
@@ -546,14 +546,14 @@
}
type native_mod =
- rec(str native_name,
- native_abi abi,
- (@view_item)[] view_items,
- (@native_item)[] items);
+ {native_name: str,
+ abi: native_abi,
+ view_items: (@view_item)[],
+ items: (@native_item)[]};
-type variant_arg = rec(@ty ty, node_id id);
+type variant_arg = {ty: @ty, id: node_id};
-type variant_ = rec(str name, (variant_arg)[] args, node_id id);
+type variant_ = {name: str, args: variant_arg[], id: node_id};
type variant = spanned[variant_];
@@ -566,7 +566,7 @@
view_item_export(ident, node_id);
}
-type obj_def_ids = rec(node_id ty, node_id ctor);
+type obj_def_ids = {ty: node_id, ctor: node_id};
// Meta-data associated with an item
@@ -578,13 +578,10 @@
// distinguished for pretty-printing.
tag attr_style { attr_outer; attr_inner; }
-type attribute_ = rec(attr_style style, meta_item value);
+type attribute_ = {style: attr_style, value: meta_item};
-type item = rec(ident ident,
- attribute[] attrs,
- node_id id, // For objs and resources, this is the type def_id
- item_ node,
- span span);
+type item = // For objs and resources, this is the type def_id
+ {ident: ident, attrs: attribute[], id: node_id, node: item_, span: span};
tag item_ {
item_const(@ty, @expr);
@@ -593,48 +590,57 @@
item_native_mod(native_mod);
item_ty(@ty, ty_param[]);
item_tag(variant[], ty_param[]);
- item_obj(_obj, ty_param[], node_id /* constructor id */);
- item_res(_fn /* dtor */, node_id /* dtor id */,
- ty_param[], node_id /* ctor id */);
+ item_obj(_obj, ty_param[], /* constructor id */node_id);
+ item_res(
+ /* dtor */
+ _fn,
+
+ /* dtor id */
+ node_id,
+ ty_param[],
+
+ /* ctor id */
+ node_id);
}
-type native_item = rec(ident ident,
- attribute[] attrs,
- native_item_ node,
- node_id id,
- span span);
+type native_item =
+ {ident: ident,
+ attrs: attribute[],
+ node: native_item_,
+ id: node_id,
+ span: span};
tag native_item_ {
native_item_ty;
native_item_fn(option::t[str], fn_decl, ty_param[]);
}
-fn is_exported(ident i, _mod m) -> bool {
- auto nonlocal = true;
- for (@ast::item it in m.items) {
- if (it.ident == i) { nonlocal = false; }
- alt (it.node) {
- case (item_tag(?variants, _)) {
- for (variant v in variants) {
- if (v.node.name == i) { nonlocal = false; }
- }
+fn is_exported(i: ident, m: _mod) -> bool {
+ let nonlocal = true;
+ for it: @ast::item in m.items {
+ if it.ident == i { nonlocal = false; }
+ alt it.node {
+ item_tag(variants, _) {
+ for v: variant in variants {
+ if v.node.name == i { nonlocal = false; }
}
- case (_) { }
+ }
+ _ { }
}
- if (!nonlocal) { break; }
+ if !nonlocal { break; }
}
- auto count = 0u;
- for (@ast::view_item vi in m.view_items) {
- alt (vi.node) {
- case (ast::view_item_export(?id, _)) {
- if (str::eq(i, id)) {
- // even if it's nonlocal (since it's explicit)
+ let count = 0u;
+ for vi: @ast::view_item in m.view_items {
+ alt vi.node {
+ ast::view_item_export(id, _) {
+ if str::eq(i, id) {
+ // even if it's nonlocal (since it's explicit)
- ret true;
- }
- count += 1u;
+ ret true;
}
- case (_) {/* fall through */ }
+ count += 1u;
+ }
+ _ {/* fall through */ }
}
}
// If there are no declared exports then
@@ -643,52 +649,46 @@
ret count == 0u && !nonlocal;
}
-fn is_call_expr(@expr e) -> bool {
- alt (e.node) {
- case (expr_call(_, _)) { ret true; }
- case (_) { ret false; }
+fn is_call_expr(e: @expr) -> bool {
+ alt e.node { expr_call(_, _) { ret true; } _ { ret false; } }
+}
+
+fn is_constraint_arg(e: @expr) -> bool {
+ alt e.node {
+ expr_lit(_) { ret true; }
+ expr_path(_) { ret true; }
+ _ { ret false; }
}
}
-fn is_constraint_arg(@expr e) -> bool {
- alt (e.node) {
- case (expr_lit(_)) { ret true; }
- case (expr_path(_)) { ret true; }
- case (_) { ret false; }
- }
-}
+fn eq_ty(a: &@ty, b: &@ty) -> bool { ret std::box::ptr_eq(a, b); }
-fn eq_ty(&@ty a, &@ty b) -> bool { ret std::box::ptr_eq(a, b); }
+fn hash_ty(t: &@ty) -> uint { ret t.span.lo << 16u + t.span.hi; }
-fn hash_ty(&@ty t) -> uint { ret t.span.lo << 16u + t.span.hi; }
-
-fn block_from_expr(@expr e) -> blk {
- auto blk_ =
- rec(stmts=~[],
- expr=option::some[@expr](e),
- id=e.id);
- ret rec(node=blk_, span=e.span);
+fn block_from_expr(e: @expr) -> blk {
+ let blk_ = {stmts: ~[], expr: option::some[@expr](e), id: e.id};
+ ret {node: blk_, span: e.span};
}
-fn obj_field_from_anon_obj_field(&anon_obj_field f) -> obj_field {
- ret rec(mut=f.mut, ty=f.ty, ident=f.ident, id=f.id);
+fn obj_field_from_anon_obj_field(f: &anon_obj_field) -> obj_field {
+ ret {mut: f.mut, ty: f.ty, ident: f.ident, id: f.id};
}
// This is a convenience function to transfor ternary expressions to if
// expressions so that they can be treated the same
-fn ternary_to_if(&@expr e) -> @ast::expr {
- alt (e.node) {
- case (expr_ternary(?cond, ?then, ?els)) {
- auto then_blk = block_from_expr(then);
- auto els_blk = block_from_expr(els);
- auto els_expr = @rec(id=els.id, node=expr_block(els_blk),
- span=els.span);
- ret @rec(id=e.id,
- node=expr_if(cond, then_blk, option::some(els_expr)),
- span=e.span);
- }
- case (_) { fail; }
+fn ternary_to_if(e: &@expr) -> @ast::expr {
+ alt e.node {
+ expr_ternary(cond, then, els) {
+ let then_blk = block_from_expr(then);
+ let els_blk = block_from_expr(els);
+ let els_expr =
+ @{id: els.id, node: expr_block(els_blk), span: els.span};
+ ret @{id: e.id,
+ node: expr_if(cond, then_blk, option::some(els_expr)),
+ span: e.span};
+ }
+ _ { fail; }
}
}
diff --git a/src/comp/syntax/codemap.rs b/src/comp/syntax/codemap.rs
index 9ace393..3904bd8 100644
--- a/src/comp/syntax/codemap.rs
+++ b/src/comp/syntax/codemap.rs
@@ -9,210 +9,196 @@
type filename = str;
-type file_pos = rec(uint ch, uint byte);
+type file_pos = {ch: uint, byte: uint};
/* A codemap is a thing that maps uints to file/line/column positions
* in a crate. This to make it possible to represent the positions
* with single-word things, rather than passing records all over the
* compiler.
*/
-type filemap = @rec(filename name, file_pos start_pos,
- mutable file_pos[] lines);
+type filemap =
+ @{name: filename, start_pos: file_pos, mutable lines: file_pos[]};
-type codemap = @rec(mutable filemap[] files);
+type codemap = @{mutable files: filemap[]};
-type loc = rec(filename filename, uint line, uint col);
+type loc = {filename: filename, line: uint, col: uint};
-fn new_codemap() -> codemap {
- ret @rec(mutable files=~[]);
+fn new_codemap() -> codemap { ret @{mutable files: ~[]}; }
+
+fn new_filemap(filename: filename, start_pos_ch: uint, start_pos_byte: uint)
+ -> filemap {
+ ret @{name: filename,
+ start_pos: {ch: start_pos_ch, byte: start_pos_byte},
+ mutable lines: ~[{ch: start_pos_ch, byte: start_pos_byte}]};
}
-fn new_filemap(filename filename, uint start_pos_ch, uint start_pos_byte)
- -> filemap {
- ret @rec(name=filename, start_pos=rec(ch=start_pos_ch,
- byte=start_pos_byte),
- mutable lines=~[rec(ch=start_pos_ch, byte=start_pos_byte)]);
+fn next_line(file: filemap, chpos: uint, byte_pos: uint) {
+ file.lines += ~[{ch: chpos, byte: byte_pos}];
}
-fn next_line(filemap file, uint chpos, uint byte_pos) {
- file.lines += ~[rec(ch=chpos, byte=byte_pos)];
-}
+type lookup_fn = fn(file_pos) -> uint ;
-type lookup_fn = fn (file_pos pos) -> uint;
-
-fn lookup_pos(codemap map, uint pos, lookup_fn lookup) -> loc {
- auto a = 0u;
- auto b = ivec::len(map.files);
- while (b - a > 1u) {
- auto m = (a + b) / 2u;
- if (lookup(map.files.(m).start_pos) > pos) { b = m; } else { a = m; }
+fn lookup_pos(map: codemap, pos: uint, lookup: lookup_fn) -> loc {
+ let a = 0u;
+ let b = ivec::len(map.files);
+ while b - a > 1u {
+ let m = (a + b) / 2u;
+ if lookup(map.files.(m).start_pos) > pos { b = m; } else { a = m; }
}
- auto f = map.files.(a);
+ let f = map.files.(a);
a = 0u;
b = ivec::len(f.lines);
- while (b - a > 1u) {
- auto m = (a + b) / 2u;
- if (lookup(f.lines.(m)) > pos) { b = m; } else { a = m; }
+ while b - a > 1u {
+ let m = (a + b) / 2u;
+ if lookup(f.lines.(m)) > pos { b = m; } else { a = m; }
}
- ret rec(filename=f.name, line=a + 1u, col=pos - lookup(f.lines.(a)));
+ ret {filename: f.name, line: a + 1u, col: pos - lookup(f.lines.(a))};
}
-fn lookup_char_pos(codemap map, uint pos) -> loc {
- fn lookup(file_pos pos) -> uint { ret pos.ch; }
+fn lookup_char_pos(map: codemap, pos: uint) -> loc {
+ fn lookup(pos: file_pos) -> uint { ret pos.ch; }
ret lookup_pos(map, pos, lookup);
}
-fn lookup_byte_pos(codemap map, uint pos) -> loc {
- fn lookup(file_pos pos) -> uint { ret pos.byte; }
+fn lookup_byte_pos(map: codemap, pos: uint) -> loc {
+ fn lookup(pos: file_pos) -> uint { ret pos.byte; }
ret lookup_pos(map, pos, lookup);
}
-type span = rec(uint lo, uint hi);
+type span = {lo: uint, hi: uint};
-fn span_to_str(&span sp, &codemap cm) -> str {
- auto lo = lookup_char_pos(cm, sp.lo);
- auto hi = lookup_char_pos(cm, sp.hi);
+fn span_to_str(sp: &span, cm: &codemap) -> str {
+ let lo = lookup_char_pos(cm, sp.lo);
+ let hi = lookup_char_pos(cm, sp.hi);
ret #fmt("%s:%u:%u:%u:%u", lo.filename, lo.line, lo.col, hi.line, hi.col);
}
-fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
- &codemap cm) {
- auto ss = "<input>:0:0:0:0";
- let option::t[@file_lines] maybe_lines = none;
- alt (sp) {
- case (some(?ssp)) {
- ss = span_to_str(ssp, cm);
- maybe_lines = some(span_to_lines(ssp, cm));
- }
- case (none) { }
+fn emit_diagnostic(sp: &option::t[span], msg: &str, kind: &str, color: u8,
+ cm: &codemap) {
+ let ss = "<input>:0:0:0:0";
+ let maybe_lines: option::t[@file_lines] = none;
+ alt sp {
+ some(ssp) {
+ ss = span_to_str(ssp, cm);
+ maybe_lines = some(span_to_lines(ssp, cm));
+ }
+ none. { }
}
ioivec::stdout().write_str(ss + ": ");
- if (termivec::color_supported()) {
+ if termivec::color_supported() {
termivec::fg(ioivec::stdout().get_buf_writer(), color);
}
ioivec::stdout().write_str(#fmt("%s:", kind));
- if (termivec::color_supported()) {
+ if termivec::color_supported() {
termivec::reset(ioivec::stdout().get_buf_writer());
}
ioivec::stdout().write_str(#fmt(" %s\n", msg));
- alt (maybe_lines) {
- case (some(?lines)) {
- // FIXME: reading in the entire file is the worst possible way to
- // get access to the necessary lines.
- auto rdr = ioivec::file_reader(lines.name);
- auto file = str::unsafe_from_bytes_ivec(rdr.read_whole_stream());
- auto fm = get_filemap(cm, lines.name);
+ alt maybe_lines {
+ some(lines) {
+ // FIXME: reading in the entire file is the worst possible way to
+ // get access to the necessary lines.
+ let rdr = ioivec::file_reader(lines.name);
+ let file = str::unsafe_from_bytes_ivec(rdr.read_whole_stream());
+ let fm = get_filemap(cm, lines.name);
- // arbitrarily only print up to six lines of the error
- auto max_lines = 6u;
- auto elided = false;
- auto display_lines = lines.lines;
- if (ivec::len(display_lines) > max_lines) {
- display_lines = ivec::slice(display_lines, 0u, max_lines);
- elided = true;
- }
- // Print the offending lines
- for (uint line in display_lines) {
- ioivec::stdout().write_str(#fmt("%s:%u ", fm.name,
- line + 1u));
- auto s = get_line(fm, line as int, file);
- if (!str::ends_with(s, "\n")) {
- s += "\n";
- }
- ioivec::stdout().write_str(s);
- }
- if (elided) {
- auto last_line = display_lines.(ivec::len(display_lines) -
- 1u);
- auto s = #fmt("%s:%u ", fm.name, last_line + 1u);
- auto indent = str::char_len(s);
- auto out = "";
- while (indent > 0u) { out += " "; indent -= 1u; }
- out += "...\n";
- ioivec::stdout().write_str(out);
- }
-
- // If there's one line at fault we can easily point to the problem
- if (ivec::len(lines.lines) == 1u) {
- auto lo = lookup_char_pos(cm, option::get(sp).lo);
- auto digits = 0u;
- auto num = lines.lines.(0) / 10u;
-
- // how many digits must be indent past?
- while (num > 0u) { num /= 10u; digits += 1u; }
-
- // indent past |name:## | and the 0-offset column location
- auto left = str::char_len(fm.name) + digits + lo.col + 3u;
- auto s = "";
- while (left > 0u) { str::push_char(s, ' '); left -= 1u; }
-
- s += "^";
- auto hi = lookup_char_pos(cm, option::get(sp).hi);
- if (hi.col != lo.col) {
- // the ^ already takes up one space
- auto width = hi.col - lo.col - 1u;
- while (width > 0u) {
- str::push_char(s, '~');
- width -= 1u;
- }
- }
- ioivec::stdout().write_str(s + "\n");
- }
+ // arbitrarily only print up to six lines of the error
+ let max_lines = 6u;
+ let elided = false;
+ let display_lines = lines.lines;
+ if ivec::len(display_lines) > max_lines {
+ display_lines = ivec::slice(display_lines, 0u, max_lines);
+ elided = true;
}
- case (_) {}
+ // Print the offending lines
+ for line: uint in display_lines {
+ ioivec::stdout().write_str(#fmt("%s:%u ", fm.name, line + 1u));
+ let s = get_line(fm, line as int, file);
+ if !str::ends_with(s, "\n") { s += "\n"; }
+ ioivec::stdout().write_str(s);
+ }
+ if elided {
+ let last_line = display_lines.(ivec::len(display_lines) - 1u);
+ let s = #fmt("%s:%u ", fm.name, last_line + 1u);
+ let indent = str::char_len(s);
+ let out = "";
+ while indent > 0u { out += " "; indent -= 1u; }
+ out += "...\n";
+ ioivec::stdout().write_str(out);
+ }
+
+
+ // If there's one line at fault we can easily point to the problem
+ if ivec::len(lines.lines) == 1u {
+ let lo = lookup_char_pos(cm, option::get(sp).lo);
+ let digits = 0u;
+ let num = lines.lines.(0) / 10u;
+
+ // how many digits must be indent past?
+ while num > 0u { num /= 10u; digits += 1u; }
+
+ // indent past |name:## | and the 0-offset column location
+ let left = str::char_len(fm.name) + digits + lo.col + 3u;
+ let s = "";
+ while left > 0u { str::push_char(s, ' '); left -= 1u; }
+
+ s += "^";
+ let hi = lookup_char_pos(cm, option::get(sp).hi);
+ if hi.col != lo.col {
+ // the ^ already takes up one space
+ let width = hi.col - lo.col - 1u;
+ while width > 0u { str::push_char(s, '~'); width -= 1u; }
+ }
+ ioivec::stdout().write_str(s + "\n");
+ }
+ }
+ _ { }
}
}
-fn emit_warning(&option::t[span] sp, &str msg, &codemap cm) {
+fn emit_warning(sp: &option::t[span], msg: &str, cm: &codemap) {
emit_diagnostic(sp, msg, "warning", 11u8, cm);
}
-fn emit_error(&option::t[span] sp, &str msg, &codemap cm) {
+fn emit_error(sp: &option::t[span], msg: &str, cm: &codemap) {
emit_diagnostic(sp, msg, "error", 9u8, cm);
}
-fn emit_note(&option::t[span] sp, &str msg, &codemap cm) {
+fn emit_note(sp: &option::t[span], msg: &str, cm: &codemap) {
emit_diagnostic(sp, msg, "note", 10u8, cm);
}
-type file_lines = rec(str name, uint[] lines);
+type file_lines = {name: str, lines: uint[]};
-fn span_to_lines(span sp, codemap::codemap cm) -> @file_lines {
- auto lo = lookup_char_pos(cm, sp.lo);
- auto hi = lookup_char_pos(cm, sp.hi);
- auto lines = ~[];
- for each (uint i in uint::range(lo.line - 1u, hi.line as uint)) {
+fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines {
+ let lo = lookup_char_pos(cm, sp.lo);
+ let hi = lookup_char_pos(cm, sp.hi);
+ let lines = ~[];
+ for each i: uint in uint::range(lo.line - 1u, hi.line as uint) {
lines += ~[i];
}
- ret @rec(name=lo.filename, lines=lines);
+ ret @{name: lo.filename, lines: lines};
}
-fn get_line(filemap fm, int line, &str file) -> str {
- let uint begin = fm.lines.(line).byte - fm.start_pos.byte;
- let uint end;
- if (line as uint < ivec::len(fm.lines) - 1u) {
+fn get_line(fm: filemap, line: int, file: &str) -> str {
+ let begin: uint = fm.lines.(line).byte - fm.start_pos.byte;
+ let end: uint;
+ if line as uint < ivec::len(fm.lines) - 1u {
end = fm.lines.(line + 1).byte - fm.start_pos.byte;
} else {
// If we're not done parsing the file, we're at the limit of what's
// parsed. If we just slice the rest of the string, we'll print out
// the remainder of the file, which is undesirable.
end = str::byte_len(file);
- auto rest = str::slice(file, begin, end);
- auto newline = str::index(rest, '\n' as u8);
- if (newline != -1) {
- end = begin + (newline as uint);
- }
+ let rest = str::slice(file, begin, end);
+ let newline = str::index(rest, '\n' as u8);
+ if newline != -1 { end = begin + (newline as uint); }
}
ret str::slice(file, begin, end);
}
-fn get_filemap(codemap cm, str filename) -> filemap {
- for (filemap fm in cm.files) {
- if (fm.name == filename) {
- ret fm;
- }
- }
+fn get_filemap(cm: codemap, filename: str) -> filemap {
+ for fm: filemap in cm.files { if fm.name == filename { ret fm; } }
//XXjdm the following triggers a mismatched type bug
// (or expected function, found _|_)
- fail;// ("asking for " + filename + " which we don't know about");
+ fail; // ("asking for " + filename + " which we don't know about");
}
//
diff --git a/src/comp/syntax/ext/base.rs b/src/comp/syntax/ext/base.rs
index ac970c6..ed869e7 100644
--- a/src/comp/syntax/ext/base.rs
+++ b/src/comp/syntax/ext/base.rs
@@ -7,10 +7,10 @@
import codemap;
type syntax_expander =
- fn(&ext_ctxt, span, &(@ast::expr)[], option::t[str]) -> @ast::expr;
-type macro_def = rec(str ident, syntax_extension ext);
-type macro_definer = fn(&ext_ctxt, span, &(@ast::expr)[],
- option::t[str]) -> macro_def;
+ fn(&ext_ctxt, span, &(@ast::expr)[], option::t[str]) -> @ast::expr ;
+type macro_def = {ident: str, ext: syntax_extension};
+type macro_definer =
+ fn(&ext_ctxt, span, &(@ast::expr)[], option::t[str]) -> macro_def ;
tag syntax_extension {
normal(syntax_expander);
@@ -20,7 +20,7 @@
// A temporary hard-coded map of methods for expanding syntax extension
// AST nodes into full ASTs
fn syntax_expander_table() -> hashmap[str, syntax_extension] {
- auto syntax_expanders = new_str_hash[syntax_extension]();
+ let syntax_expanders = new_str_hash[syntax_extension]();
syntax_expanders.insert("fmt", normal(ext::fmt::expand_syntax_ext));
syntax_expanders.insert("env", normal(ext::env::expand_syntax_ext));
syntax_expanders.insert("macro",
@@ -37,34 +37,31 @@
// Provides a limited set of services necessary for syntax extensions
// to do their thing
type ext_ctxt =
- rec(str crate_file_name_hack,
- span_msg_fn span_fatal,
- span_msg_fn span_unimpl,
- span_msg_fn span_bug,
- msg_fn bug,
- next_id_fn next_id);
+ {crate_file_name_hack: str,
+ span_fatal: span_msg_fn,
+ span_unimpl: span_msg_fn,
+ span_bug: span_msg_fn,
+ bug: msg_fn,
+ next_id: next_id_fn};
-fn mk_ctxt(&session sess) -> ext_ctxt {
- fn ext_span_fatal_(&session sess, span sp, str msg) -> ! {
+fn mk_ctxt(sess: &session) -> ext_ctxt {
+ fn ext_span_fatal_(sess: &session, sp: span, msg: str) -> ! {
sess.span_err(sp, msg);
fail;
}
- auto ext_span_fatal = bind ext_span_fatal_(sess, _, _);
- fn ext_span_unimpl_(&session sess, span sp, str msg) -> ! {
+ let ext_span_fatal = bind ext_span_fatal_(sess, _, _);
+ fn ext_span_unimpl_(sess: &session, sp: span, msg: str) -> ! {
sess.span_err(sp, "unimplemented " + msg);
fail;
}
- auto ext_span_unimpl = bind ext_span_unimpl_(sess, _, _);
- fn ext_span_bug_(&session sess, span sp, str msg) -> ! {
+ let ext_span_unimpl = bind ext_span_unimpl_(sess, _, _);
+ fn ext_span_bug_(sess: &session, sp: span, msg: str) -> ! {
sess.span_bug(sp, msg);
fail;
}
- auto ext_span_bug = bind ext_span_bug_(sess, _, _);
- fn ext_bug_(&session sess, str msg) -> ! {
- sess.bug(msg);
- fail;
- }
- auto ext_bug = bind ext_bug_(sess, _);
+ let ext_span_bug = bind ext_span_bug_(sess, _, _);
+ fn ext_bug_(sess: &session, msg: str) -> ! { sess.bug(msg); fail; }
+ let ext_bug = bind ext_bug_(sess, _);
// FIXME: Some extensions work by building ASTs with paths to functions
@@ -74,45 +71,40 @@
// the extensions the file name of the crate being compiled so they can
// use it to guess whether paths should be prepended with "std::". This is
// super-ugly and needs a better solution.
- auto crate_file_name_hack = sess.get_codemap().files.(0).name;
+ let crate_file_name_hack = sess.get_codemap().files.(0).name;
- fn ext_next_id_(&session sess) -> ast::node_id {
+ fn ext_next_id_(sess: &session) -> ast::node_id {
ret sess.next_node_id(); // temporary, until bind works better
}
- auto ext_next_id = bind ext_next_id_(sess);
- ret rec(crate_file_name_hack=crate_file_name_hack,
- span_fatal=ext_span_fatal,
- span_unimpl=ext_span_unimpl,
- span_bug=ext_span_bug,
- bug=ext_bug,
- next_id=ext_next_id);
+ let ext_next_id = bind ext_next_id_(sess);
+ ret {crate_file_name_hack: crate_file_name_hack,
+ span_fatal: ext_span_fatal,
+ span_unimpl: ext_span_unimpl,
+ span_bug: ext_span_bug,
+ bug: ext_bug,
+ next_id: ext_next_id};
}
-fn expr_to_str(&ext_ctxt cx, @ast::expr expr, str error) -> str {
- alt (expr.node) {
- case (ast::expr_lit(?l)) {
- alt (l.node) {
- case (ast::lit_str(?s, _)) { ret s; }
- case (_) { cx.span_fatal(l.span, error); }
- }
+fn expr_to_str(cx: &ext_ctxt, expr: @ast::expr, error: str) -> str {
+ alt expr.node {
+ ast::expr_lit(l) {
+ alt l.node {
+ ast::lit_str(s, _) { ret s; }
+ _ { cx.span_fatal(l.span, error); }
}
- case (_) { cx.span_fatal(expr.span, error); }
+ }
+ _ { cx.span_fatal(expr.span, error); }
}
}
-fn expr_to_ident(&ext_ctxt cx, @ast::expr expr, str error) -> ast::ident {
- alt(expr.node) {
- case (ast::expr_path(?p)) {
- if (ivec::len(p.node.types) > 0u
- || ivec::len(p.node.idents) != 1u) {
- cx.span_fatal(expr.span, error);
- } else {
- ret p.node.idents.(0);
- }
- }
- case (_) {
+fn expr_to_ident(cx: &ext_ctxt, expr: @ast::expr, error: str) -> ast::ident {
+ alt expr.node {
+ ast::expr_path(p) {
+ if ivec::len(p.node.types) > 0u || ivec::len(p.node.idents) != 1u {
cx.span_fatal(expr.span, error);
- }
+ } else { ret p.node.idents.(0); }
+ }
+ _ { cx.span_fatal(expr.span, error); }
}
}
diff --git a/src/comp/syntax/ext/env.rs b/src/comp/syntax/ext/env.rs
index 8c02d2e..88b3e3a 100644
--- a/src/comp/syntax/ext/env.rs
+++ b/src/comp/syntax/ext/env.rs
@@ -12,27 +12,28 @@
import base::*;
export expand_syntax_ext;
-fn expand_syntax_ext(&ext_ctxt cx, codemap::span sp, &(@ast::expr)[] args,
- option::t[str] body) -> @ast::expr {
- if (ivec::len[@ast::expr](args) != 1u) {
+fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, args: &(@ast::expr)[],
+ body: option::t[str]) -> @ast::expr {
+ if ivec::len[@ast::expr](args) != 1u {
cx.span_fatal(sp, "malformed #env call");
}
// FIXME: if this was more thorough it would manufacture an
// option::t[str] rather than just an maybe-empty string.
- auto var = expr_to_str(cx, args.(0), "#env requires a string");
- alt (generic_os::getenv(var)) {
- case (option::none) { ret make_new_str(cx, sp, ""); }
- case (option::some(?s)) { ret make_new_str(cx, sp, s); }
+ let var = expr_to_str(cx, args.(0), "#env requires a string");
+ alt generic_os::getenv(var) {
+ option::none. { ret make_new_str(cx, sp, ""); }
+ option::some(s) { ret make_new_str(cx, sp, s); }
}
}
-fn make_new_lit(&ext_ctxt cx, codemap::span sp, ast::lit_ lit) -> @ast::expr {
- auto sp_lit = @rec(node=lit, span=sp);
- ret @rec(id=cx.next_id(), node=ast::expr_lit(sp_lit), span=sp);
+fn make_new_lit(cx: &ext_ctxt, sp: codemap::span, lit: ast::lit_) ->
+ @ast::expr {
+ let sp_lit = @{node: lit, span: sp};
+ ret @{id: cx.next_id(), node: ast::expr_lit(sp_lit), span: sp};
}
-fn make_new_str(&ext_ctxt cx, codemap::span sp, str s) -> @ast::expr {
+fn make_new_str(cx: &ext_ctxt, sp: codemap::span, s: str) -> @ast::expr {
ret make_new_lit(cx, sp, ast::lit_str(s, ast::sk_rc));
}
//
diff --git a/src/comp/syntax/ext/expand.rs b/src/comp/syntax/ext/expand.rs
index d6fbae8..e47a0fc 100644
--- a/src/comp/syntax/ext/expand.rs
+++ b/src/comp/syntax/ext/expand.rs
@@ -13,56 +13,54 @@
import std::map::hashmap;
import std::ivec;
-fn expand_expr(&hashmap[str, base::syntax_extension] exts,
- &session::session sess, &expr_ e, ast_fold fld,
- &fn(&ast::expr_, ast_fold) -> expr_ orig) -> expr_ {
- ret alt(e) {
- case (expr_mac(?mac)) {
- alt(mac.node) {
- case (mac_invoc(?pth, ?args, ?body)) {
- assert(ivec::len(pth.node.idents) > 0u);
- auto extname = pth.node.idents.(0);
- auto ext_cx = base::mk_ctxt(sess);
- alt (exts.find(extname)) {
- case (none) {
- emit_error(some(pth.span),
- "unknown syntax expander: '"
- + extname + "'", sess.get_codemap());
- fail
- }
- case (some(base::normal(?ext))) {
- //keep going, outside-in
- fld.fold_expr(ext(ext_cx, pth.span,
- args, body)).node
- }
- case (some(base::macro_defining(?ext))) {
- auto named_extension
- = ext(ext_cx, pth.span, args, body);
- exts.insert(named_extension.ident,
- named_extension.ext);
- ast::expr_rec(~[], none)
- }
- }
- }
- case (_) {
- emit_error(some(mac.span), "naked syntactic bit",
+fn expand_expr(exts: &hashmap[str, base::syntax_extension],
+ sess: &session::session, e: &expr_, fld: ast_fold,
+ orig: &fn(&ast::expr_, ast_fold) -> expr_ ) -> expr_ {
+ ret alt e {
+ expr_mac(mac) {
+ alt mac.node {
+ mac_invoc(pth, args, body) {
+ assert (ivec::len(pth.node.idents) > 0u);
+ let extname = pth.node.idents.(0);
+ let ext_cx = base::mk_ctxt(sess);
+ alt exts.find(extname) {
+ none. {
+ emit_error(some(pth.span),
+ "unknown syntax expander: '" + extname + "'",
sess.get_codemap());
fail
+ }
+ some(base::normal(ext)) {
+
+ //keep going, outside-in
+ fld.fold_expr(ext(ext_cx, pth.span, args, body)).node
+ }
+ some(base::macro_defining(ext)) {
+ let named_extension = ext(ext_cx, pth.span, args, body);
+ exts.insert(named_extension.ident, named_extension.ext);
+ ast::expr_rec(~[], none)
+ }
}
+ }
+ _ {
+ emit_error(some(mac.span), "naked syntactic bit",
+ sess.get_codemap());
+ fail
+ }
}
- }
- case (_) { orig(e, fld) }
- };
+ }
+ _ { orig(e, fld) }
+ };
}
-fn expand_crate(&session::session sess, &@crate c) -> @crate {
- auto exts = ext::base::syntax_expander_table();
- auto afp = default_ast_fold();
- auto f_pre =
- rec(fold_expr = bind expand_expr(exts, sess, _, _, afp.fold_expr)
- with *afp);
- auto f = make_fold(f_pre);
- auto res = @f.fold_crate(*c);
+fn expand_crate(sess: &session::session, c: &@crate) -> @crate {
+ let exts = ext::base::syntax_expander_table();
+ let afp = default_ast_fold();
+ let f_pre =
+ {fold_expr: bind expand_expr(exts, sess, _, _, afp.fold_expr)
+ with *afp};
+ let f = make_fold(f_pre);
+ let res = @f.fold_crate(*c);
dummy_out(f); //temporary: kill circular reference
ret res;
diff --git a/src/comp/syntax/ext/fmt.rs b/src/comp/syntax/ext/fmt.rs
index b69b27f..4374030 100644
--- a/src/comp/syntax/ext/fmt.rs
+++ b/src/comp/syntax/ext/fmt.rs
@@ -16,116 +16,110 @@
import codemap::span;
export expand_syntax_ext;
-fn expand_syntax_ext(&ext_ctxt cx, span sp, &(@ast::expr)[] args,
- option::t[str] body) -> @ast::expr {
- if (ivec::len[@ast::expr](args) == 0u) {
+fn expand_syntax_ext(cx: &ext_ctxt, sp: span, args: &(@ast::expr)[],
+ body: option::t[str]) -> @ast::expr {
+ if ivec::len[@ast::expr](args) == 0u {
cx.span_fatal(sp, "#fmt requires a format string");
}
- auto fmt = expr_to_str(cx, args.(0), "first argument to #fmt must be a "
- + "string literal.");
- auto fmtspan = args.(0).span;
+ let fmt =
+ expr_to_str(cx, args.(0),
+ "first argument to #fmt must be a " + "string literal.");
+ let fmtspan = args.(0).span;
log "Format string:";
log fmt;
- fn parse_fmt_err_(&ext_ctxt cx, span sp, str msg) -> ! {
+ fn parse_fmt_err_(cx: &ext_ctxt, sp: span, msg: str) -> ! {
cx.span_fatal(sp, msg);
}
- auto parse_fmt_err = bind parse_fmt_err_(cx, fmtspan, _);
- auto pieces = parse_fmt_string(fmt, parse_fmt_err);
+ let parse_fmt_err = bind parse_fmt_err_(cx, fmtspan, _);
+ let pieces = parse_fmt_string(fmt, parse_fmt_err);
ret pieces_to_expr(cx, sp, pieces, args);
}
// FIXME: A lot of these functions for producing expressions can probably
// be factored out in common with other code that builds expressions.
// FIXME: Cleanup the naming of these functions
-fn pieces_to_expr(&ext_ctxt cx, span sp, vec[piece] pieces,
- &(@ast::expr)[] args) -> @ast::expr {
- fn make_new_lit(&ext_ctxt cx, span sp, ast::lit_ lit) ->
+fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: vec[piece],
+ args: &(@ast::expr)[]) -> @ast::expr {
+ fn make_new_lit(cx: &ext_ctxt, sp: span, lit: ast::lit_) -> @ast::expr {
+ let sp_lit = @{node: lit, span: sp};
+ ret @{id: cx.next_id(), node: ast::expr_lit(sp_lit), span: sp};
+ }
+ fn make_new_str(cx: &ext_ctxt, sp: span, s: str) -> @ast::expr {
+ let lit = ast::lit_str(s, ast::sk_rc);
+ ret make_new_lit(cx, sp, lit);
+ }
+ fn make_new_int(cx: &ext_ctxt, sp: span, i: int) -> @ast::expr {
+ let lit = ast::lit_int(i);
+ ret make_new_lit(cx, sp, lit);
+ }
+ fn make_new_uint(cx: &ext_ctxt, sp: span, u: uint) -> @ast::expr {
+ let lit = ast::lit_uint(u);
+ ret make_new_lit(cx, sp, lit);
+ }
+ fn make_add_expr(cx: &ext_ctxt, sp: span, lhs: @ast::expr,
+ rhs: @ast::expr) -> @ast::expr {
+ let binexpr = ast::expr_binary(ast::add, lhs, rhs);
+ ret @{id: cx.next_id(), node: binexpr, span: sp};
+ }
+ fn make_path_expr(cx: &ext_ctxt, sp: span, idents: &ast::ident[]) ->
@ast::expr {
- auto sp_lit = @rec(node=lit, span=sp);
- ret @rec(id=cx.next_id(), node=ast::expr_lit(sp_lit), span=sp);
+ let path = {global: false, idents: idents, types: ~[]};
+ let sp_path = {node: path, span: sp};
+ let pathexpr = ast::expr_path(sp_path);
+ ret @{id: cx.next_id(), node: pathexpr, span: sp};
}
- fn make_new_str(&ext_ctxt cx, span sp, str s) -> @ast::expr {
- auto lit = ast::lit_str(s, ast::sk_rc);
- ret make_new_lit(cx, sp, lit);
- }
- fn make_new_int(&ext_ctxt cx, span sp, int i) -> @ast::expr {
- auto lit = ast::lit_int(i);
- ret make_new_lit(cx, sp, lit);
- }
- fn make_new_uint(&ext_ctxt cx, span sp, uint u) -> @ast::expr {
- auto lit = ast::lit_uint(u);
- ret make_new_lit(cx, sp, lit);
- }
- fn make_add_expr(&ext_ctxt cx, span sp, @ast::expr lhs,
- @ast::expr rhs) -> @ast::expr {
- auto binexpr = ast::expr_binary(ast::add, lhs, rhs);
- ret @rec(id=cx.next_id(), node=binexpr, span=sp);
- }
- fn make_path_expr(&ext_ctxt cx, span sp, &ast::ident[] idents)
- -> @ast::expr {
- auto path = rec(global=false, idents=idents, types=~[]);
- auto sp_path = rec(node=path, span=sp);
- auto pathexpr = ast::expr_path(sp_path);
- ret @rec(id=cx.next_id(), node=pathexpr, span=sp);
- }
- fn make_vec_expr(&ext_ctxt cx, span sp, &(@ast::expr)[] exprs) ->
+ fn make_vec_expr(cx: &ext_ctxt, sp: span, exprs: &(@ast::expr)[]) ->
@ast::expr {
- auto vecexpr = ast::expr_vec(exprs, ast::imm, ast::sk_rc);
- ret @rec(id=cx.next_id(), node=vecexpr, span=sp);
+ let vecexpr = ast::expr_vec(exprs, ast::imm, ast::sk_rc);
+ ret @{id: cx.next_id(), node: vecexpr, span: sp};
}
- fn make_call(&ext_ctxt cx, span sp, &ast::ident[] fn_path,
- &(@ast::expr)[] args) -> @ast::expr {
- auto pathexpr = make_path_expr(cx, sp, fn_path);
- auto callexpr = ast::expr_call(pathexpr, args);
- ret @rec(id=cx.next_id(), node=callexpr, span=sp);
+ fn make_call(cx: &ext_ctxt, sp: span, fn_path: &ast::ident[],
+ args: &(@ast::expr)[]) -> @ast::expr {
+ let pathexpr = make_path_expr(cx, sp, fn_path);
+ let callexpr = ast::expr_call(pathexpr, args);
+ ret @{id: cx.next_id(), node: callexpr, span: sp};
}
- fn make_rec_expr(&ext_ctxt cx, span sp,
- vec[rec(ast::ident ident, @ast::expr ex)] fields)
- -> @ast::expr {
- let ast::field[] astfields = ~[];
- for (rec(ast::ident ident, @ast::expr ex) field in fields) {
- auto ident = field.ident;
- auto val = field.ex;
- auto astfield =
- rec(node=rec(mut=ast::imm, ident=ident, expr=val), span=sp);
+ fn make_rec_expr(cx: &ext_ctxt, sp: span,
+ fields: vec[{ident: ast::ident, ex: @ast::expr}]) ->
+ @ast::expr {
+ let astfields: ast::field[] = ~[];
+ for field: {ident: ast::ident, ex: @ast::expr} in fields {
+ let ident = field.ident;
+ let val = field.ex;
+ let astfield =
+ {node: {mut: ast::imm, ident: ident, expr: val}, span: sp};
astfields += ~[astfield];
}
- auto recexpr = ast::expr_rec(astfields, option::none[@ast::expr]);
- ret @rec(id=cx.next_id(), node=recexpr, span=sp);
+ let recexpr = ast::expr_rec(astfields, option::none[@ast::expr]);
+ ret @{id: cx.next_id(), node: recexpr, span: sp};
}
- fn make_path_vec(&ext_ctxt cx, str ident) -> str[] {
- fn compiling_std(&ext_ctxt cx) -> bool {
+ fn make_path_vec(cx: &ext_ctxt, ident: str) -> str[] {
+ fn compiling_std(cx: &ext_ctxt) -> bool {
ret str::find(cx.crate_file_name_hack, "std.rc") >= 0;
}
- if (compiling_std(cx)) {
+ if compiling_std(cx) {
ret ~["extfmt", "rt", ident];
- } else {
- ret ~["std", "extfmt", "rt", ident];
- }
+ } else { ret ~["std", "extfmt", "rt", ident]; }
}
- fn make_rt_path_expr(&ext_ctxt cx, span sp, str ident) ->
- @ast::expr {
- auto path = make_path_vec(cx, ident);
+ fn make_rt_path_expr(cx: &ext_ctxt, sp: span, ident: str) -> @ast::expr {
+ let path = make_path_vec(cx, ident);
ret make_path_expr(cx, sp, path);
}
// Produces an AST expression that represents a RT::conv record,
// which tells the RT::conv* functions how to perform the conversion
- fn make_rt_conv_expr(&ext_ctxt cx, span sp, &conv cnv) ->
- @ast::expr {
- fn make_flags(&ext_ctxt cx, span sp, vec[flag] flags) ->
+ fn make_rt_conv_expr(cx: &ext_ctxt, sp: span, cnv: &conv) -> @ast::expr {
+ fn make_flags(cx: &ext_ctxt, sp: span, flags: vec[flag]) ->
@ast::expr {
- let (@ast::expr)[] flagexprs = ~[];
- for (flag f in flags) {
- auto fstr;
- alt (f) {
- case (flag_left_justify) { fstr = "flag_left_justify"; }
- case (flag_left_zero_pad) { fstr = "flag_left_zero_pad"; }
- case (flag_space_for_sign) {
- fstr = "flag_space_for_sign";
- }
- case (flag_sign_always) { fstr = "flag_sign_always"; }
- case (flag_alternate) { fstr = "flag_alternate"; }
+ let flagexprs: (@ast::expr)[] = ~[];
+ for f: flag in flags {
+ let fstr;
+ alt f {
+ flag_left_justify. { fstr = "flag_left_justify"; }
+ flag_left_zero_pad. { fstr = "flag_left_zero_pad"; }
+ flag_space_for_sign. { fstr = "flag_space_for_sign"; }
+ flag_sign_always. { fstr = "flag_sign_always"; }
+ flag_alternate. { fstr = "flag_alternate"; }
}
flagexprs += ~[make_rt_path_expr(cx, sp, fstr)];
}
@@ -133,235 +127,211 @@
// through the rec that these flags are a member of, so
// this is a hack placeholder flag
- if (ivec::len[@ast::expr](flagexprs) == 0u) {
+ if ivec::len[@ast::expr](flagexprs) == 0u {
flagexprs += ~[make_rt_path_expr(cx, sp, "flag_none")];
}
ret make_vec_expr(cx, sp, flagexprs);
}
- fn make_count(&ext_ctxt cx, span sp, &count cnt) ->
- @ast::expr {
- alt (cnt) {
- case (count_implied) {
- ret make_rt_path_expr(cx, sp, "count_implied");
- }
- case (count_is(?c)) {
- auto count_lit = make_new_int(cx, sp, c);
- auto count_is_path = make_path_vec(cx, "count_is");
- auto count_is_args = ~[count_lit];
- ret make_call(cx, sp, count_is_path, count_is_args);
- }
- case (_) {
- cx.span_unimpl(sp, "unimplemented #fmt conversion");
- }
+ fn make_count(cx: &ext_ctxt, sp: span, cnt: &count) -> @ast::expr {
+ alt cnt {
+ count_implied. {
+ ret make_rt_path_expr(cx, sp, "count_implied");
+ }
+ count_is(c) {
+ let count_lit = make_new_int(cx, sp, c);
+ let count_is_path = make_path_vec(cx, "count_is");
+ let count_is_args = ~[count_lit];
+ ret make_call(cx, sp, count_is_path, count_is_args);
+ }
+ _ { cx.span_unimpl(sp, "unimplemented #fmt conversion"); }
}
}
- fn make_ty(&ext_ctxt cx, span sp, &ty t) -> @ast::expr {
- auto rt_type;
- alt (t) {
- case (ty_hex(?c)) {
- alt (c) {
- case (case_upper) { rt_type = "ty_hex_upper"; }
- case (case_lower) { rt_type = "ty_hex_lower"; }
- }
+ fn make_ty(cx: &ext_ctxt, sp: span, t: &ty) -> @ast::expr {
+ let rt_type;
+ alt t {
+ ty_hex(c) {
+ alt c {
+ case_upper. { rt_type = "ty_hex_upper"; }
+ case_lower. { rt_type = "ty_hex_lower"; }
}
- case (ty_bits) { rt_type = "ty_bits"; }
- case (ty_octal) { rt_type = "ty_octal"; }
- case (_) { rt_type = "ty_default"; }
+ }
+ ty_bits. { rt_type = "ty_bits"; }
+ ty_octal. { rt_type = "ty_octal"; }
+ _ { rt_type = "ty_default"; }
}
ret make_rt_path_expr(cx, sp, rt_type);
}
- fn make_conv_rec(&ext_ctxt cx, span sp, @ast::expr flags_expr,
- @ast::expr width_expr, @ast::expr precision_expr,
- @ast::expr ty_expr) -> @ast::expr {
+ fn make_conv_rec(cx: &ext_ctxt, sp: span, flags_expr: @ast::expr,
+ width_expr: @ast::expr, precision_expr: @ast::expr,
+ ty_expr: @ast::expr) -> @ast::expr {
ret make_rec_expr(cx, sp,
- [rec(ident="flags", ex=flags_expr),
- rec(ident="width", ex=width_expr),
- rec(ident="precision", ex=precision_expr),
- rec(ident="ty", ex=ty_expr)]);
+ [{ident: "flags", ex: flags_expr},
+ {ident: "width", ex: width_expr},
+ {ident: "precision", ex: precision_expr},
+ {ident: "ty", ex: ty_expr}]);
}
- auto rt_conv_flags = make_flags(cx, sp, cnv.flags);
- auto rt_conv_width = make_count(cx, sp, cnv.width);
- auto rt_conv_precision = make_count(cx, sp, cnv.precision);
- auto rt_conv_ty = make_ty(cx, sp, cnv.ty);
+ let rt_conv_flags = make_flags(cx, sp, cnv.flags);
+ let rt_conv_width = make_count(cx, sp, cnv.width);
+ let rt_conv_precision = make_count(cx, sp, cnv.precision);
+ let rt_conv_ty = make_ty(cx, sp, cnv.ty);
ret make_conv_rec(cx, sp, rt_conv_flags, rt_conv_width,
rt_conv_precision, rt_conv_ty);
}
- fn make_conv_call(&ext_ctxt cx, span sp, str conv_type, &conv cnv,
- @ast::expr arg) -> @ast::expr {
- auto fname = "conv_" + conv_type;
- auto path = make_path_vec(cx, fname);
- auto cnv_expr = make_rt_conv_expr(cx, sp, cnv);
- auto args = ~[cnv_expr, arg];
+ fn make_conv_call(cx: &ext_ctxt, sp: span, conv_type: str, cnv: &conv,
+ arg: @ast::expr) -> @ast::expr {
+ let fname = "conv_" + conv_type;
+ let path = make_path_vec(cx, fname);
+ let cnv_expr = make_rt_conv_expr(cx, sp, cnv);
+ let args = ~[cnv_expr, arg];
ret make_call(cx, arg.span, path, args);
}
- fn make_new_conv(&ext_ctxt cx, span sp, conv cnv, @ast::expr arg)
- -> @ast::expr {
+ fn make_new_conv(cx: &ext_ctxt, sp: span, cnv: conv, arg: @ast::expr) ->
+ @ast::expr {
// FIXME: Extract all this validation into extfmt::ct
- fn is_signed_type(conv cnv) -> bool {
- alt (cnv.ty) {
- case (ty_int(?s)) {
- alt (s) {
- case (signed) { ret true; }
- case (unsigned) { ret false; }
- }
- }
- case (_) { ret false; }
+ fn is_signed_type(cnv: conv) -> bool {
+ alt cnv.ty {
+ ty_int(s) {
+ alt s { signed. { ret true; } unsigned. { ret false; } }
+ }
+ _ { ret false; }
}
}
- auto unsupported = "conversion not supported in #fmt string";
- alt (cnv.param) {
- case (option::none) { }
- case (_) { cx.span_unimpl(sp, unsupported); }
+ let unsupported = "conversion not supported in #fmt string";
+ alt cnv.param {
+ option::none. { }
+ _ { cx.span_unimpl(sp, unsupported); }
}
- for (flag f in cnv.flags) {
- alt (f) {
- case (flag_left_justify) { }
- case (flag_sign_always) {
- if (!is_signed_type(cnv)) {
- cx.span_fatal(sp,
- "+ flag only valid in " +
- "signed #fmt conversion");
- }
- }
- case (flag_space_for_sign) {
- if (!is_signed_type(cnv)) {
- cx.span_fatal(sp,
- "space flag only valid in " +
- "signed #fmt conversions");
- }
- }
- case (flag_left_zero_pad) { }
- case (_) { cx.span_unimpl(sp, unsupported); }
- }
- }
- alt (cnv.width) {
- case (count_implied) { }
- case (count_is(_)) { }
- case (_) { cx.span_unimpl(sp, unsupported); }
- }
- alt (cnv.precision) {
- case (count_implied) { }
- case (count_is(_)) { }
- case (_) { cx.span_unimpl(sp, unsupported); }
- }
- alt (cnv.ty) {
- case (ty_str) {
- ret make_conv_call(cx, arg.span, "str", cnv, arg);
- }
- case (ty_int(?sign)) {
- alt (sign) {
- case (signed) {
- ret make_conv_call(cx, arg.span, "int", cnv, arg);
- }
- case (unsigned) {
- ret make_conv_call(cx, arg.span, "uint", cnv, arg);
- }
- }
- }
- case (ty_bool) {
- ret make_conv_call(cx, arg.span, "bool", cnv, arg);
- }
- case (ty_char) {
- ret make_conv_call(cx, arg.span, "char", cnv, arg);
- }
- case (ty_hex(_)) {
- ret make_conv_call(cx, arg.span, "uint", cnv, arg);
- }
- case (ty_bits) {
- ret make_conv_call(cx, arg.span, "uint", cnv, arg);
- }
- case (ty_octal) {
- ret make_conv_call(cx, arg.span, "uint", cnv, arg);
- }
- case (_) { cx.span_unimpl(sp, unsupported); }
- }
- }
- fn log_conv(conv c) {
- alt (c.param) {
- case (some(?p)) { log "param: " + std::int::to_str(p, 10u); }
- case (_) { log "param: none"; }
- }
- for (flag f in c.flags) {
- alt (f) {
- case (flag_left_justify) { log "flag: left justify"; }
- case (flag_left_zero_pad) { log "flag: left zero pad"; }
- case (flag_space_for_sign) { log "flag: left space pad"; }
- case (flag_sign_always) { log "flag: sign always"; }
- case (flag_alternate) { log "flag: alternate"; }
- }
- }
- alt (c.width) {
- case (count_is(?i)) {
- log "width: count is " + std::int::to_str(i, 10u);
- }
- case (count_is_param(?i)) {
- log "width: count is param " + std::int::to_str(i, 10u);
- }
- case (count_is_next_param) { log "width: count is next param"; }
- case (count_implied) { log "width: count is implied"; }
- }
- alt (c.precision) {
- case (count_is(?i)) {
- log "prec: count is " + std::int::to_str(i, 10u);
- }
- case (count_is_param(?i)) {
- log "prec: count is param " + std::int::to_str(i, 10u);
- }
- case (count_is_next_param) { log "prec: count is next param"; }
- case (count_implied) { log "prec: count is implied"; }
- }
- alt (c.ty) {
- case (ty_bool) { log "type: bool"; }
- case (ty_str) { log "type: str"; }
- case (ty_char) { log "type: char"; }
- case (ty_int(?s)) {
- alt (s) {
- case (signed) { log "type: signed"; }
- case (unsigned) { log "type: unsigned"; }
- }
- }
- case (ty_bits) { log "type: bits"; }
- case (ty_hex(?cs)) {
- alt (cs) {
- case (case_upper) { log "type: uhex"; }
- case (case_lower) { log "type: lhex"; }
- }
- }
- case (ty_octal) { log "type: octal"; }
- }
- }
- auto fmt_sp = args.(0).span;
- auto n = 0u;
- auto tmp_expr = make_new_str(cx, sp, "");
- auto nargs = ivec::len[@ast::expr](args);
- for (piece pc in pieces) {
- alt (pc) {
- case (piece_string(?s)) {
- auto s_expr = make_new_str(cx, fmt_sp, s);
- tmp_expr = make_add_expr(cx, fmt_sp, tmp_expr, s_expr);
- }
- case (piece_conv(?conv)) {
- n += 1u;
- if (n >= nargs) {
+ for f: flag in cnv.flags {
+ alt f {
+ flag_left_justify. { }
+ flag_sign_always. {
+ if !is_signed_type(cnv) {
cx.span_fatal(sp,
- "not enough arguments to #fmt " +
- "for the given format string");
+ "+ flag only valid in " +
+ "signed #fmt conversion");
}
- log "Building conversion:";
- log_conv(conv);
- auto arg_expr = args.(n);
- auto c_expr = make_new_conv(cx, fmt_sp, conv, arg_expr);
- tmp_expr = make_add_expr(cx, fmt_sp, tmp_expr, c_expr);
+ }
+ flag_space_for_sign. {
+ if !is_signed_type(cnv) {
+ cx.span_fatal(sp,
+ "space flag only valid in " +
+ "signed #fmt conversions");
+ }
+ }
+ flag_left_zero_pad. { }
+ _ { cx.span_unimpl(sp, unsupported); }
}
}
+ alt cnv.width {
+ count_implied. { }
+ count_is(_) { }
+ _ { cx.span_unimpl(sp, unsupported); }
+ }
+ alt cnv.precision {
+ count_implied. { }
+ count_is(_) { }
+ _ { cx.span_unimpl(sp, unsupported); }
+ }
+ alt cnv.ty {
+ ty_str. { ret make_conv_call(cx, arg.span, "str", cnv, arg); }
+ ty_int(sign) {
+ alt sign {
+ signed. { ret make_conv_call(cx, arg.span, "int", cnv, arg); }
+ unsigned. {
+ ret make_conv_call(cx, arg.span, "uint", cnv, arg);
+ }
+ }
+ }
+ ty_bool. { ret make_conv_call(cx, arg.span, "bool", cnv, arg); }
+ ty_char. { ret make_conv_call(cx, arg.span, "char", cnv, arg); }
+ ty_hex(_) { ret make_conv_call(cx, arg.span, "uint", cnv, arg); }
+ ty_bits. { ret make_conv_call(cx, arg.span, "uint", cnv, arg); }
+ ty_octal. { ret make_conv_call(cx, arg.span, "uint", cnv, arg); }
+ _ { cx.span_unimpl(sp, unsupported); }
+ }
}
- auto expected_nargs = n + 1u; // n conversions + the fmt string
+ fn log_conv(c: conv) {
+ alt c.param {
+ some(p) { log "param: " + std::int::to_str(p, 10u); }
+ _ { log "param: none"; }
+ }
+ for f: flag in c.flags {
+ alt f {
+ flag_left_justify. { log "flag: left justify"; }
+ flag_left_zero_pad. { log "flag: left zero pad"; }
+ flag_space_for_sign. { log "flag: left space pad"; }
+ flag_sign_always. { log "flag: sign always"; }
+ flag_alternate. { log "flag: alternate"; }
+ }
+ }
+ alt c.width {
+ count_is(i) { log "width: count is " + std::int::to_str(i, 10u); }
+ count_is_param(i) {
+ log "width: count is param " + std::int::to_str(i, 10u);
+ }
+ count_is_next_param. { log "width: count is next param"; }
+ count_implied. { log "width: count is implied"; }
+ }
+ alt c.precision {
+ count_is(i) { log "prec: count is " + std::int::to_str(i, 10u); }
+ count_is_param(i) {
+ log "prec: count is param " + std::int::to_str(i, 10u);
+ }
+ count_is_next_param. { log "prec: count is next param"; }
+ count_implied. { log "prec: count is implied"; }
+ }
+ alt c.ty {
+ ty_bool. { log "type: bool"; }
+ ty_str. { log "type: str"; }
+ ty_char. { log "type: char"; }
+ ty_int(s) {
+ alt s {
+ signed. { log "type: signed"; }
+ unsigned. { log "type: unsigned"; }
+ }
+ }
+ ty_bits. { log "type: bits"; }
+ ty_hex(cs) {
+ alt cs {
+ case_upper. { log "type: uhex"; }
+ case_lower. { log "type: lhex"; }
+ }
+ }
+ ty_octal. { log "type: octal"; }
+ }
+ }
+ let fmt_sp = args.(0).span;
+ let n = 0u;
+ let tmp_expr = make_new_str(cx, sp, "");
+ let nargs = ivec::len[@ast::expr](args);
+ for pc: piece in pieces {
+ alt pc {
+ piece_string(s) {
+ let s_expr = make_new_str(cx, fmt_sp, s);
+ tmp_expr = make_add_expr(cx, fmt_sp, tmp_expr, s_expr);
+ }
+ piece_conv(conv) {
+ n += 1u;
+ if n >= nargs {
+ cx.span_fatal(sp,
+ "not enough arguments to #fmt " +
+ "for the given format string");
+ }
+ log "Building conversion:";
+ log_conv(conv);
+ let arg_expr = args.(n);
+ let c_expr = make_new_conv(cx, fmt_sp, conv, arg_expr);
+ tmp_expr = make_add_expr(cx, fmt_sp, tmp_expr, c_expr);
+ }
+ }
+ }
+ let expected_nargs = n + 1u; // n conversions + the fmt string
- if (expected_nargs < nargs) {
+ if expected_nargs < nargs {
cx.span_fatal(sp,
- #fmt("too many arguments to #fmt. found %u, expected %u",
- nargs, expected_nargs));
+ #fmt("too many arguments to #fmt. found %u, expected %u",
+ nargs, expected_nargs));
}
ret tmp_expr;
}
diff --git a/src/comp/syntax/ext/simplext.rs b/src/comp/syntax/ext/simplext.rs
index d6f7a7c..729e8e5 100644
--- a/src/comp/syntax/ext/simplext.rs
+++ b/src/comp/syntax/ext/simplext.rs
@@ -34,22 +34,18 @@
export add_new_extension;
-fn path_to_ident(&path pth) -> option::t[ident] {
- if (ivec::len(pth.node.idents) == 1u
- && ivec::len(pth.node.types) == 0u) {
+fn path_to_ident(pth: &path) -> option::t[ident] {
+ if ivec::len(pth.node.idents) == 1u && ivec::len(pth.node.types) == 0u {
ret some(pth.node.idents.(0u));
}
ret none;
}
//an ivec of binders might be a little big.
-type clause = rec((binders)[] params, @expr body);
+type clause = {params: binders[], body: @expr};
/* logically, an arb_depth should contain only one kind of matchable */
-tag arb_depth[T] {
- leaf(T);
- seq(vec[arb_depth[T]], span);
-}
+tag arb_depth[T] { leaf(T); seq(vec[arb_depth[T]], span); }
tag matchable {
@@ -62,31 +58,29 @@
}
/* for when given an incompatible bit of AST */
-fn match_error(&ext_ctxt cx, &matchable m, &str expected) -> ! {
- alt(m) {
- case (match_expr(?x)) {
- cx.span_fatal(x.span, "this argument is an expr, expected "
- + expected);
+fn match_error(cx: &ext_ctxt, m: &matchable, expected: &str) -> ! {
+ alt m {
+ match_expr(x) {
+ cx.span_fatal(x.span,
+ "this argument is an expr, expected " + expected);
}
- case (match_path(?x)) {
- cx.span_fatal(x.span, "this argument is a path, expected "
- + expected);
+ match_path(x) {
+ cx.span_fatal(x.span,
+ "this argument is a path, expected " + expected);
}
- case (match_ident(?x)) {
- cx.span_fatal(x.span, "this argument is an ident, expected "
- + expected);
+ match_ident(x) {
+ cx.span_fatal(x.span,
+ "this argument is an ident, expected " + expected);
}
- case (match_ty(?x)) {
- cx.span_fatal(x.span, "this argument is a type, expected "
- + expected);
+ match_ty(x) {
+ cx.span_fatal(x.span,
+ "this argument is a type, expected " + expected);
}
- case (match_block(?x)) {
- cx.span_fatal(x.span, "this argument is a block, expected "
- + expected);
+ match_block(x) {
+ cx.span_fatal(x.span,
+ "this argument is a block, expected " + expected);
}
- case (match_exact) {
- cx.bug("what is a match_exact doing in a bindings?");
- }
+ match_exact. { cx.bug("what is a match_exact doing in a bindings?"); }
}
}
@@ -97,88 +91,82 @@
// we'll want to return something indicating amount of progress and location
// of failure instead of `none`.
type match_result = option::t[arb_depth[matchable]];
-type selector = fn(&matchable) -> match_result;
+type selector = fn(&matchable) -> match_result ;
-fn elts_to_ell(&ext_ctxt cx, &(@expr)[] elts) -> option::t[@expr] {
- let uint idx = 0u;
- for (@expr elt in elts) {
- alt (elt.node) {
- case (expr_mac(?m)) {
- alt (m.node) {
- case (ast::mac_ellipsis) {
- if (idx != 1u || ivec::len(elts) != 2u) {
+fn elts_to_ell(cx: &ext_ctxt, elts: &(@expr)[]) -> option::t[@expr] {
+ let idx: uint = 0u;
+ for elt: @expr in elts {
+ alt elt.node {
+ expr_mac(m) {
+ alt m.node {
+ ast::mac_ellipsis. {
+ if idx != 1u || ivec::len(elts) != 2u {
cx.span_fatal(m.span,
- "Ellpisis may only appear"
- +" after exactly 1 item.");
+ "Ellpisis may only appear" +
+ " after exactly 1 item.");
}
ret some(elts.(0));
}
}
}
- case (_) { }
+ _ { }
}
idx += 1u;
}
ret none;
}
-fn option_flatten_map[T,U](&fn(&T)->option::t[U] f, &vec[T] v)
- -> option::t[vec[U]] {
- auto res = vec::alloc[U](vec::len(v));
- for (T elem in v) {
- alt (f(elem)) {
- case (none) { ret none; }
- case (some(?fv)) { res += [fv]; }
- }
+fn option_flatten_map[T, U](f: &fn(&T) -> option::t[U] , v: &vec[T]) ->
+ option::t[vec[U]] {
+ let res = vec::alloc[U](vec::len(v));
+ for elem: T in v {
+ alt f(elem) { none. { ret none; } some(fv) { res += [fv]; } }
}
ret some(res);
}
-fn a_d_map(&arb_depth[matchable] ad, &selector f)
- -> match_result {
- alt (ad) {
- case (leaf(?x)) { ret f(x); }
- case (seq(?ads,?span)) {
- alt (option_flatten_map(bind a_d_map(_, f), ads)) {
- case (none) { ret none; }
- case (some(?ts)) { ret some(seq(ts,span)); }
+fn a_d_map(ad: &arb_depth[matchable], f: &selector) -> match_result {
+ alt ad {
+ leaf(x) { ret f(x); }
+ seq(ads, span) {
+ alt option_flatten_map(bind a_d_map(_, f), ads) {
+ none. { ret none; }
+ some(ts) { ret some(seq(ts, span)); }
}
}
}
}
-fn compose_sels(selector s1, selector s2) -> selector {
- fn scomp(selector s1, selector s2, &matchable m) ->
- match_result {
- ret alt (s1(m)) {
- case (none) { none }
- case (some(?matches)) { a_d_map(matches, s2) }
- }
+fn compose_sels(s1: selector, s2: selector) -> selector {
+ fn scomp(s1: selector, s2: selector, m: &matchable) -> match_result {
+ ret alt s1(m) {
+ none. { none }
+ some(matches) { a_d_map(matches, s2) }
+ }
}
ret bind scomp(s1, s2, _);
}
-type binders = rec(hashmap[ident,selector] real_binders,
- mutable (selector)[] literal_ast_matchers);
+type binders =
+ {real_binders: hashmap[ident, selector],
+ mutable literal_ast_matchers: selector[]};
type bindings = hashmap[ident, arb_depth[matchable]];
-fn acumm_bindings(&ext_ctxt cx, &bindings b_dest, &bindings b_src) {
-}
+fn acumm_bindings(cx: &ext_ctxt, b_dest: &bindings, b_src: &bindings) { }
/* these three functions are the big moving parts */
/* create the selectors needed to bind and verify the pattern */
-fn pattern_to_selectors(&ext_ctxt cx, @expr e) -> binders {
- let binders res = rec(real_binders=new_str_hash[selector](),
- mutable literal_ast_matchers=~[]);
+fn pattern_to_selectors(cx: &ext_ctxt, e: @expr) -> binders {
+ let res: binders =
+ {real_binders: new_str_hash[selector](),
+ mutable literal_ast_matchers: ~[]};
//this oughta return binders instead, but macro args are a sequence of
//expressions, rather than a single expression
- fn trivial_selector(&matchable m) -> match_result {
- ret some(leaf(m));
- }
+ fn trivial_selector(m: &matchable) -> match_result { ret some(leaf(m)); }
p_t_s_rec(cx, match_expr(e), trivial_selector, res);
ret res;
}
@@ -189,146 +177,140 @@
bindings. Most of the work is done in p_t_s, which generates the
selectors. */
-fn use_selectors_to_bind(&binders b, @expr e) -> option::t[bindings] {
- auto res = new_str_hash[arb_depth[matchable]]();
- let bool never_mind = false;
- for each(@rec(ident key, selector val) pair
- in b.real_binders.items()) {
- alt (pair.val(match_expr(e))) {
- case (none) { never_mind = true; }
- case (some(?mtc)) { res.insert(pair.key, mtc); }
+fn use_selectors_to_bind(b: &binders, e: @expr) -> option::t[bindings] {
+ let res = new_str_hash[arb_depth[matchable]]();
+ let never_mind: bool = false;
+ for each pair: @{key: ident, val: selector} in b.real_binders.items() {
+ alt pair.val(match_expr(e)) {
+ none. { never_mind = true; }
+ some(mtc) { res.insert(pair.key, mtc); }
}
}
- if (never_mind) { ret none; } //HACK: `ret` doesn't work in `for each`
- for (selector sel in b.literal_ast_matchers) {
- alt (sel(match_expr(e))) {
- case (none) { ret none; }
- case (_) { }
- }
+ if never_mind {
+ ret none; //HACK: `ret` doesn't work in `for each`
+ }
+ for sel: selector in b.literal_ast_matchers {
+ alt sel(match_expr(e)) { none. { ret none; } _ { } }
}
ret some(res);
}
/* use the bindings on the body to generate the expanded code */
-fn transcribe(&ext_ctxt cx, &bindings b, @expr body) -> @expr {
- let @mutable vec[uint] idx_path = @mutable [];
- auto afp = default_ast_fold();
- auto f_pre =
- rec(fold_ident = bind transcribe_ident(cx, b, idx_path, _, _),
- fold_path = bind transcribe_path(cx, b, idx_path, _, _),
- fold_expr = bind transcribe_expr(cx, b, idx_path, _, _,
- afp.fold_expr),
- fold_ty = bind transcribe_type(cx, b, idx_path, _, _,
- afp.fold_ty),
- fold_block = bind transcribe_block(cx, b, idx_path, _, _,
- afp.fold_block),
- map_exprs = bind transcribe_exprs(cx, b, idx_path, _, _)
- with *afp);
- auto f = make_fold(f_pre);
- auto result = f.fold_expr(body);
- dummy_out(f); //temporary: kill circular reference
+fn transcribe(cx: &ext_ctxt, b: &bindings, body: @expr) -> @expr {
+ let idx_path: @mutable vec[uint] = @mutable [];
+ let afp = default_ast_fold();
+ let f_pre =
+ {fold_ident: bind transcribe_ident(cx, b, idx_path, _, _),
+ fold_path: bind transcribe_path(cx, b, idx_path, _, _),
+ fold_expr:
+ bind transcribe_expr(cx, b, idx_path, _, _, afp.fold_expr),
+ fold_ty: bind transcribe_type(cx, b, idx_path, _, _, afp.fold_ty),
+ fold_block:
+ bind transcribe_block(cx, b, idx_path, _, _, afp.fold_block),
+ map_exprs: bind transcribe_exprs(cx, b, idx_path, _, _) with *afp};
+ let f = make_fold(f_pre);
+ let result = f.fold_expr(body);
+ dummy_out(f); //temporary: kill circular reference
ret result;
}
/* helper: descend into a matcher */
-fn follow(&arb_depth[matchable] m, @mutable vec[uint] idx_path)
- -> arb_depth[matchable] {
- let arb_depth[matchable] res = m;
- for (uint idx in *idx_path) {
- alt(res) {
- case (leaf(_)) { ret res; /* end of the line */ }
- case (seq(?new_ms,_)) { res = new_ms.(idx); }
+fn follow(m: &arb_depth[matchable], idx_path: @mutable vec[uint]) ->
+ arb_depth[matchable] {
+ let res: arb_depth[matchable] = m;
+ for idx: uint in *idx_path {
+ alt res {
+ leaf(_) { ret res;/* end of the line */ }
+ seq(new_ms, _) { res = new_ms.(idx); }
}
}
ret res;
}
-fn follow_for_trans(&ext_ctxt cx, &option::t[arb_depth[matchable]] mmaybe,
- @mutable vec[uint] idx_path) -> option::t[matchable] {
- alt(mmaybe) {
- case (none) { ret none }
- case (some(?m)) {
- ret alt(follow(m, idx_path)) {
- case (seq(_,?sp)) {
- cx.span_fatal(sp, "syntax matched under ... but not "
- + "used that way.")
- }
- case (leaf(?m)) {
- ret some(m)
- }
- }
+fn follow_for_trans(cx: &ext_ctxt, mmaybe: &option::t[arb_depth[matchable]],
+ idx_path: @mutable vec[uint]) -> option::t[matchable] {
+ alt mmaybe {
+ none. { ret none }
+ some(m) {
+ ret alt follow(m, idx_path) {
+ seq(_, sp) {
+ cx.span_fatal(sp,
+ "syntax matched under ... but not " +
+ "used that way.")
+ }
+ leaf(m) { ret some(m) }
+ }
}
}
}
/* helper for transcribe_exprs: what vars from `b` occur in `e`? */
-iter free_vars(&bindings b, @expr e) -> ident {
- let hashmap[ident,()] idents = new_str_hash[()]();
- fn mark_ident(&ident i, ast_fold fld, &bindings b,
- &hashmap[ident,()] idents) -> ident {
- if(b.contains_key(i)) { idents.insert(i,()); }
+iter free_vars(b: &bindings, e: @expr) -> ident {
+ let idents: hashmap[ident, ()] = new_str_hash[()]();
+ fn mark_ident(i: &ident, fld: ast_fold, b: &bindings,
+ idents: &hashmap[ident, ()]) -> ident {
+ if b.contains_key(i) { idents.insert(i, ()); }
ret i;
}
// using fold is a hack: we want visit, but it doesn't hit idents ) :
// solve this with macros
- auto f_pre = rec(fold_ident=bind mark_ident(_, _, b, idents)
- with *default_ast_fold());
- auto f = make_fold(f_pre);
+ let f_pre =
+ {fold_ident: bind mark_ident(_, _, b, idents)
+ with *default_ast_fold()};
+ let f = make_fold(f_pre);
f.fold_expr(e); // ignore result
dummy_out(f);
- for each(ident id in idents.keys()) { put id; }
+ for each id: ident in idents.keys() { put id; }
}
/* handle sequences (anywhere in the AST) of exprs, either real or ...ed */
-fn transcribe_exprs(&ext_ctxt cx, &bindings b, @mutable vec[uint] idx_path,
- fn(&@expr)->@expr recur, (@expr)[] exprs) -> (@expr)[] {
- alt (elts_to_ell(cx, exprs)) {
- case (some(?repeat_me)) {
- let option::t[rec(uint rep_count, ident name)] repeat = none;
+fn transcribe_exprs(cx: &ext_ctxt, b: &bindings, idx_path: @mutable vec[uint],
+ recur: fn(&@expr) -> @expr , exprs: (@expr)[]) ->
+ (@expr)[] {
+ alt elts_to_ell(cx, exprs) {
+ some(repeat_me) {
+ let repeat: option::t[{rep_count: uint, name: ident}] = none;
/* we need to walk over all the free vars in lockstep, except for
the leaves, which are just duplicated */
- for each (ident fv in free_vars(b, repeat_me)) {
- auto cur_pos = follow(b.get(fv), idx_path);
- alt (cur_pos) {
- case (leaf(_)) { }
- case (seq(?ms,_)) {
- alt (repeat) {
- case (none) {
- repeat = some
- (rec(rep_count=vec::len(ms), name=fv));
+ for each fv: ident in free_vars(b, repeat_me) {
+ let cur_pos = follow(b.get(fv), idx_path);
+ alt cur_pos {
+ leaf(_) { }
+ seq(ms, _) {
+ alt repeat {
+ none. {
+ repeat = some({rep_count: vec::len(ms), name: fv});
}
- case (some({rep_count: ?old_len,
- name: ?old_name})) {
- auto len = vec::len(ms);
- if (old_len != len) {
- cx.span_fatal
- (repeat_me.span,
- #fmt("'%s' occurs %u times, but ",
- fv, len)+
- #fmt("'%s' occurs %u times",
- old_name, old_len));
+ some({rep_count: old_len, name: old_name}) {
+ let len = vec::len(ms);
+ if old_len != len {
+ cx.span_fatal(repeat_me.span,
+ #fmt("'%s' occurs %u times, but ", fv,
+ len) +
+ #fmt("'%s' occurs %u times",
+ old_name, old_len));
}
}
}
}
}
}
- auto res = ~[];
- alt (repeat) {
- case (none) {
+ let res = ~[];
+ alt repeat {
+ none. {
cx.span_fatal(repeat_me.span,
- "'...' surrounds an expression without any"
- + " repeating syntax variables");
+ "'...' surrounds an expression without any" +
+ " repeating syntax variables");
}
- case (some({rep_count: ?rc, _})) {
+ some({rep_count: rc, _}) {
/* Whew, we now know how how many times to repeat */
- let uint idx = 0u;
- while (idx < rc) {
+ let idx: uint = 0u;
+ while idx < rc {
vec::push(*idx_path, idx);
res += ~[recur(repeat_me)]; // whew!
vec::pop(*idx_path);
@@ -338,139 +320,141 @@
}
ret res;
}
- case (none) { ret ivec::map(recur, exprs); }
+ none. { ret ivec::map(recur, exprs); }
}
}
// substitute, in a position that's required to be an ident
-fn transcribe_ident(&ext_ctxt cx, &bindings b, @mutable vec[uint] idx_path,
- &ident i, ast_fold fld) -> ident {
- ret alt (follow_for_trans(cx, b.find(i), idx_path)) {
- case (some(match_ident(?a_id))) { a_id.node }
- case (some(?m)) { match_error(cx, m, "an identifier") }
- case (none) { i }
- }
-}
-
-
-fn transcribe_path(&ext_ctxt cx, &bindings b, @mutable vec[uint] idx_path,
- &path_ p, ast_fold fld) -> path_ {
- // Don't substitute into qualified names.
- if (ivec::len(p.types) > 0u || ivec::len(p.idents) != 1u) { ret p; }
- ret alt (follow_for_trans(cx, b.find(p.idents.(0)), idx_path)) {
- case (some(match_ident(?id))) {
- rec(global=false, idents=~[id.node], types=~[])
- }
- case (some(match_path(?a_pth))) { a_pth.node }
- case (some(?m)) { match_error(cx, m, "a path") }
- case (none) { p }
- }
-}
-
-
-fn transcribe_expr(&ext_ctxt cx, &bindings b, @mutable vec[uint] idx_path,
- &ast::expr_ e, ast_fold fld,
- fn(&ast::expr_, ast_fold) -> ast::expr_ orig)
- -> ast::expr_ {
- ret alt(e) {
- case (expr_path(?p)){
- // Don't substitute into qualified names.
- if (ivec::len(p.node.types) > 0u ||
- ivec::len(p.node.idents) != 1u) { e }
- alt (follow_for_trans(cx, b.find(p.node.idents.(0)), idx_path)) {
- case (some(match_ident(?id))) {
- expr_path(respan(id.span,
- rec(global=false,
- idents=~[id.node],types=~[])))
- }
- case (some(match_path(?a_pth))) { expr_path(a_pth) }
- case (some(match_expr(?a_exp))) { a_exp.node }
- case (some(?m)) { match_error(cx, m, "an expression")}
- case (none) { orig(e,fld) }
+fn transcribe_ident(cx: &ext_ctxt, b: &bindings, idx_path: @mutable vec[uint],
+ i: &ident, fld: ast_fold) -> ident {
+ ret alt follow_for_trans(cx, b.find(i), idx_path) {
+ some(match_ident(a_id)) { a_id.node }
+ some(m) { match_error(cx, m, "an identifier") }
+ none. { i }
}
- }
- case (_) { orig(e,fld) }
- }
}
-fn transcribe_type(&ext_ctxt cx, &bindings b, @mutable vec[uint] idx_path,
- &ast::ty_ t, ast_fold fld,
- fn(&ast::ty_, ast_fold) -> ast::ty_ orig) -> ast::ty_ {
- ret alt(t) {
- case (ast::ty_path(?pth,_)) {
- alt (path_to_ident(pth)) {
- case (some(?id)) {
- alt (follow_for_trans(cx, b.find(id), idx_path)) {
- case (some(match_ty(?ty))) { ty.node }
- case (some(?m)) { match_error(cx, m, "a type") }
- case (none) { orig(t, fld) }
+
+fn transcribe_path(cx: &ext_ctxt, b: &bindings, idx_path: @mutable vec[uint],
+ p: &path_, fld: ast_fold) -> path_ {
+ // Don't substitute into qualified names.
+ if ivec::len(p.types) > 0u || ivec::len(p.idents) != 1u { ret p; }
+ ret alt follow_for_trans(cx, b.find(p.idents.(0)), idx_path) {
+ some(match_ident(id)) {
+ {global: false, idents: ~[id.node], types: ~[]}
+ }
+ some(match_path(a_pth)) { a_pth.node }
+ some(m) { match_error(cx, m, "a path") }
+ none. { p }
+ }
+}
+
+
+fn transcribe_expr(cx: &ext_ctxt, b: &bindings, idx_path: @mutable vec[uint],
+ e: &ast::expr_, fld: ast_fold,
+ orig: fn(&ast::expr_, ast_fold) -> ast::expr_ ) ->
+ ast::expr_ {
+ ret alt e {
+ expr_path(p) {
+ // Don't substitute into qualified names.
+ if ivec::len(p.node.types) > 0u || ivec::len(p.node.idents) != 1u
+ {
+ e
+ }
+ alt follow_for_trans(cx, b.find(p.node.idents.(0)), idx_path) {
+ some(match_ident(id)) {
+ expr_path(respan(id.span,
+ {global: false,
+ idents: ~[id.node],
+ types: ~[]}))
+ }
+ some(match_path(a_pth)) { expr_path(a_pth) }
+ some(match_expr(a_exp)) { a_exp.node }
+ some(m) { match_error(cx, m, "an expression") }
+ none. { orig(e, fld) }
}
}
- case (none) { orig(t, fld) }
+ _ { orig(e, fld) }
}
- }
- case (_) { orig(t, fld) }
- }
+}
+
+fn transcribe_type(cx: &ext_ctxt, b: &bindings, idx_path: @mutable vec[uint],
+ t: &ast::ty_, fld: ast_fold,
+ orig: fn(&ast::ty_, ast_fold) -> ast::ty_ ) -> ast::ty_ {
+ ret alt t {
+ ast::ty_path(pth, _) {
+ alt path_to_ident(pth) {
+ some(id) {
+ alt follow_for_trans(cx, b.find(id), idx_path) {
+ some(match_ty(ty)) { ty.node }
+ some(m) { match_error(cx, m, "a type") }
+ none. { orig(t, fld) }
+ }
+ }
+ none. { orig(t, fld) }
+ }
+ }
+ _ { orig(t, fld) }
+ }
}
/* for parsing reasons, syntax variables bound to blocks must be used like
`{v}` */
-fn transcribe_block(&ext_ctxt cx, &bindings b, @mutable vec[uint] idx_path,
- &blk_ blk, ast_fold fld,
- fn(&blk_, ast_fold) -> blk_ orig) -> blk_ {
- ret alt (block_to_ident(blk)) {
- case (some(?id)) {
- alt (follow_for_trans(cx, b.find(id), idx_path)) {
- case (some(match_block(?new_blk))) { new_blk.node }
- // possibly allow promotion of ident/path/expr to blocks?
- case (some(?m)) { match_error(cx, m, "a block")}
- case (none) { orig(blk, fld) }
+fn transcribe_block(cx: &ext_ctxt, b: &bindings, idx_path: @mutable vec[uint],
+ blk: &blk_, fld: ast_fold,
+ orig: fn(&blk_, ast_fold) -> blk_ ) -> blk_ {
+ ret alt block_to_ident(blk) {
+ some(id) {
+ alt follow_for_trans(cx, b.find(id), idx_path) {
+ some(match_block(new_blk)) { new_blk.node }
+
+ // possibly allow promotion of ident/path/expr to blocks?
+ some(m) {
+ match_error(cx, m, "a block")
+ }
+ none. { orig(blk, fld) }
+ }
+ }
+ none. { orig(blk, fld) }
}
- }
- case (none) { orig(blk, fld) }
- }
}
/* traverse the pattern, building instructions on how to bind the actual
argument. ps accumulates instructions on navigating the tree.*/
-fn p_t_s_rec(&ext_ctxt cx, &matchable m, &selector s, &binders b) {
+fn p_t_s_rec(cx: &ext_ctxt, m: &matchable, s: &selector, b: &binders) {
+
//it might be possible to traverse only exprs, not matchables
- alt (m) {
- case (match_expr(?e)) {
- alt (e.node) {
- case (expr_path(?p_pth)) {
- p_t_s_r_path(cx,p_pth, s, b);
- }
- case (expr_vec(?p_elts, _, _)) {
- alt (elts_to_ell(cx, p_elts)) {
- case (some(?repeat_me)) {
- p_t_s_r_ellipses(cx, repeat_me, s, b);
- }
- case (none) {
- p_t_s_r_actual_vector(cx, p_elts, s, b);
- }
+ alt m {
+ match_expr(e) {
+ alt e.node {
+ expr_path(p_pth) { p_t_s_r_path(cx, p_pth, s, b); }
+ expr_vec(p_elts, _, _) {
+ alt elts_to_ell(cx, p_elts) {
+ some(repeat_me) { p_t_s_r_ellipses(cx, repeat_me, s, b); }
+ none. { p_t_s_r_actual_vector(cx, p_elts, s, b); }
}
}
+
/* TODO: handle embedded types and blocks, at least */
- case (expr_mac(?mac)) {
+ expr_mac(mac) {
p_t_s_r_mac(cx, mac, s, b);
}
- case (_) {
- fn select(&ext_ctxt cx, &matchable m, @expr pat)
- -> match_result {
- ret alt(m) {
- case (match_expr(?e)) {
- if (e==pat) { some(leaf(match_exact)) } else { none }
- }
- case (_) { cx.bug("broken traversal in p_t_s_r"); fail }
- }
+ _ {
+ fn select(cx: &ext_ctxt, m: &matchable, pat: @expr) ->
+ match_result {
+ ret alt m {
+ match_expr(e) {
+ if e == pat { some(leaf(match_exact)) } else { none }
+ }
+ _ { cx.bug("broken traversal in p_t_s_r"); fail }
+ }
}
- b.literal_ast_matchers += ~[bind select(cx,_,e)];
+ b.literal_ast_matchers += ~[bind select(cx, _, e)];
}
}
}
@@ -479,111 +463,103 @@
/* make a match more precise */
-fn specialize_match(&matchable m) -> matchable {
- ret alt (m) {
- case (match_expr(?e)) {
- alt (e.node) {
- case (expr_path(?pth)) {
- alt (path_to_ident(pth)) {
- case (some(?id)) { match_ident(respan(pth.span,id)) }
- case (none) { match_path(pth) }
+fn specialize_match(m: &matchable) -> matchable {
+ ret alt m {
+ match_expr(e) {
+ alt e.node {
+ expr_path(pth) {
+ alt path_to_ident(pth) {
+ some(id) { match_ident(respan(pth.span, id)) }
+ none. { match_path(pth) }
+ }
+ }
+ _ { m }
}
}
- case (_) { m }
+ _ { m }
}
- }
- case (_) { m }
- }
}
/* pattern_to_selectors helper functions */
-fn p_t_s_r_path(&ext_ctxt cx, &path p, &selector s, &binders b) {
- alt (path_to_ident(p)) {
- case (some(?p_id)) {
- fn select(&ext_ctxt cx, &matchable m) -> match_result {
- ret alt (m) {
- case (match_expr(?e)) { some(leaf(specialize_match(m))) }
- case (_) { cx.bug("broken traversal in p_t_s_r"); fail }
- }
+fn p_t_s_r_path(cx: &ext_ctxt, p: &path, s: &selector, b: &binders) {
+ alt path_to_ident(p) {
+ some(p_id) {
+ fn select(cx: &ext_ctxt, m: &matchable) -> match_result {
+ ret alt m {
+ match_expr(e) { some(leaf(specialize_match(m))) }
+ _ { cx.bug("broken traversal in p_t_s_r"); fail }
+ }
}
- if (b.real_binders.contains_key(p_id)) {
+ if b.real_binders.contains_key(p_id) {
cx.span_fatal(p.span, "duplicate binding identifier");
}
- b.real_binders.insert(p_id, compose_sels(s, bind select(cx,_)));
+ b.real_binders.insert(p_id, compose_sels(s, bind select(cx, _)));
}
- case (none) { }
+ none. { }
}
}
-fn block_to_ident(&blk_ blk) -> option::t[ident] {
- if(ivec::len(blk.stmts) != 0u) { ret none; }
- ret alt (blk.expr) {
- case (some(?expr)) {
- alt (expr.node) {
- case (expr_path(?pth)) { path_to_ident(pth) }
- case (_) { none }
- }
- }
- case(none) { none }
- }
-}
-
-fn p_t_s_r_mac(&ext_ctxt cx, &ast::mac mac, &selector s, &binders b) {
- fn select_pt_1(&ext_ctxt cx, &matchable m, fn(&ast::mac) ->
- match_result fn_m) -> match_result {
- ret alt(m) {
- case (match_expr(?e)) {
- alt(e.node) {
- case (expr_mac(?mac)) { fn_m(mac) }
- case (_) { none }
- }
+fn block_to_ident(blk: &blk_) -> option::t[ident] {
+ if ivec::len(blk.stmts) != 0u { ret none; }
+ ret alt blk.expr {
+ some(expr) {
+ alt expr.node { expr_path(pth) { path_to_ident(pth) } _ { none } }
}
- case (_) { cx.bug("broken traversal in p_t_s_r"); fail }
+ none. { none }
}
+}
+
+fn p_t_s_r_mac(cx: &ext_ctxt, mac: &ast::mac, s: &selector, b: &binders) {
+ fn select_pt_1(cx: &ext_ctxt, m: &matchable,
+ fn_m: fn(&ast::mac) -> match_result ) -> match_result {
+ ret alt m {
+ match_expr(e) {
+ alt e.node { expr_mac(mac) { fn_m(mac) } _ { none } }
+ }
+ _ { cx.bug("broken traversal in p_t_s_r"); fail }
+ }
}
- fn no_des(&ext_ctxt cx, &span sp, &str syn) -> ! {
- cx.span_fatal(sp, "destructuring "+syn+" is not yet supported");
+ fn no_des(cx: &ext_ctxt, sp: &span, syn: &str) -> ! {
+ cx.span_fatal(sp, "destructuring " + syn + " is not yet supported");
}
- alt (mac.node) {
- case (ast::mac_ellipsis) { cx.span_fatal(mac.span, "misused `...`"); }
- case (ast::mac_invoc(_,_, _)) { no_des(cx, mac.span, "macro calls"); }
- case (ast::mac_embed_type(?ty)) {
- alt (ty.node) {
- case ast::ty_path(?pth, _) {
- alt (path_to_ident(pth)) {
- case (some(?id)) {
+ alt mac.node {
+ ast::mac_ellipsis. { cx.span_fatal(mac.span, "misused `...`"); }
+ ast::mac_invoc(_, _, _) { no_des(cx, mac.span, "macro calls"); }
+ ast::mac_embed_type(ty) {
+ alt ty.node {
+ ast::ty_path(pth, _) {
+ alt path_to_ident(pth) {
+ some(id) {
/* look for an embedded type */
- fn select_pt_2(&ast::mac m) -> match_result {
- ret alt (m.node) {
- case (ast::mac_embed_type(?t)) {
- some(leaf(match_ty(t)))
- }
- case (_) { none }
- }
+ fn select_pt_2(m: &ast::mac) -> match_result {
+ ret alt m.node {
+ ast::mac_embed_type(t) { some(leaf(match_ty(t))) }
+ _ { none }
+ }
}
b.real_binders.insert(id,
bind select_pt_1(cx, _, select_pt_2));
}
- case (none) { no_des(cx, pth.span, "under `#<>`"); }
+ none. { no_des(cx, pth.span, "under `#<>`"); }
}
}
- case (_) { no_des(cx, ty.span, "under `#<>`"); }
+ _ { no_des(cx, ty.span, "under `#<>`"); }
}
}
- case (ast::mac_embed_block(?blk)) {
- alt (block_to_ident(blk.node)) {
- case (some(?id)) {
- fn select_pt_2(&ast::mac m) -> match_result {
- ret alt (m.node) {
- case (ast::mac_embed_block(?blk)) {
- some(leaf(match_block(blk)))
- }
- case (_) { none }
- }
+ ast::mac_embed_block(blk) {
+ alt block_to_ident(blk.node) {
+ some(id) {
+ fn select_pt_2(m: &ast::mac) -> match_result {
+ ret alt m.node {
+ ast::mac_embed_block(blk) {
+ some(leaf(match_block(blk)))
+ }
+ _ { none }
+ }
}
b.real_binders.insert(id, bind select_pt_1(cx, _, select_pt_2));
}
- case (none) { no_des(cx, blk.span, "under `#{}`"); }
+ none. { no_des(cx, blk.span, "under `#{}`"); }
}
}
}
@@ -591,68 +567,72 @@
/* TODO: move this to vec.rs */
-fn ivec_to_vec[T](&(T)[] v) -> vec[T] {
- let vec[T] rs = vec::alloc[T](ivec::len(v));
- for (T ve in v) { rs += [ve]; }
+fn ivec_to_vec[T](v: &T[]) -> vec[T] {
+ let rs: vec[T] = vec::alloc[T](ivec::len(v));
+ for ve: T in v { rs += [ve]; }
ret rs;
}
-fn p_t_s_r_ellipses(&ext_ctxt cx, @expr repeat_me, &selector s, &binders b) {
- fn select(&ext_ctxt cx, @expr repeat_me, &matchable m) -> match_result {
- ret alt (m) {
- case (match_expr(?e)) {
- alt (e.node) {
- case (expr_vec(?arg_elts, _, _)) {
- auto elts = ivec::map(leaf, ivec::map(match_expr,
- arg_elts));
- // using repeat_me.span is a little wacky, but the
- // error we want to report is one in the macro def
- some(seq(ivec_to_vec(elts), repeat_me.span))
+fn p_t_s_r_ellipses(cx: &ext_ctxt, repeat_me: @expr, s: &selector,
+ b: &binders) {
+ fn select(cx: &ext_ctxt, repeat_me: @expr, m: &matchable) ->
+ match_result {
+ ret alt m {
+ match_expr(e) {
+ alt e.node {
+ expr_vec(arg_elts, _, _) {
+ let elts =
+ ivec::map(leaf, ivec::map(match_expr, arg_elts));
+
+ // using repeat_me.span is a little wacky, but the
+ // error we want to report is one in the macro def
+ some(seq(ivec_to_vec(elts), repeat_me.span))
+ }
+ _ { none }
+ }
}
- case (_) { none }
+ _ { cx.bug("broken traversal in p_t_s_r"); fail }
}
- }
- case (_) { cx.bug("broken traversal in p_t_s_r"); fail }
- }
}
p_t_s_rec(cx, match_expr(repeat_me),
compose_sels(s, bind select(cx, repeat_me, _)), b);
}
-fn p_t_s_r_actual_vector(&ext_ctxt cx, (@expr)[] elts, &selector s,
- &binders b) {
- fn len_select(&ext_ctxt cx, &matchable m, uint len) -> match_result {
- ret alt (m) {
- case (match_expr(?e)) {
- alt (e.node) {
- case (expr_vec(?arg_elts, _, _)) {
- if (ivec::len(arg_elts) == len) { some(leaf(match_exact)) }
- else { none }
+fn p_t_s_r_actual_vector(cx: &ext_ctxt, elts: (@expr)[], s: &selector,
+ b: &binders) {
+ fn len_select(cx: &ext_ctxt, m: &matchable, len: uint) -> match_result {
+ ret alt m {
+ match_expr(e) {
+ alt e.node {
+ expr_vec(arg_elts, _, _) {
+ if ivec::len(arg_elts) == len {
+ some(leaf(match_exact))
+ } else { none }
+ }
+ _ { none }
+ }
}
- case (_) { none }
+ _ { none }
}
- }
- case (_) { none }
- }
}
b.literal_ast_matchers +=
~[compose_sels(s, bind len_select(cx, _, ivec::len(elts)))];
- let uint idx = 0u;
- while (idx < ivec::len(elts)) {
- fn select(&ext_ctxt cx, &matchable m, uint idx) -> match_result {
- ret alt (m) {
- case (match_expr(?e)) {
- alt (e.node) {
- case (expr_vec(?arg_elts, _, _)) {
- some(leaf(match_expr(arg_elts.(idx))))
+ let idx: uint = 0u;
+ while idx < ivec::len(elts) {
+ fn select(cx: &ext_ctxt, m: &matchable, idx: uint) -> match_result {
+ ret alt m {
+ match_expr(e) {
+ alt e.node {
+ expr_vec(arg_elts, _, _) {
+ some(leaf(match_expr(arg_elts.(idx))))
+ }
+ _ { none }
+ }
}
- case (_) { none }
+ _ { cx.bug("broken traversal in p_t_s_r"); fail }
}
- }
- case (_) { cx.bug("broken traversal in p_t_s_r"); fail}
- }
}
p_t_s_rec(cx, match_expr(elts.(idx)),
compose_sels(s, bind select(cx, _, idx)), b);
@@ -660,90 +640,93 @@
}
}
-fn add_new_extension(&ext_ctxt cx, span sp, &(@expr)[] args,
- option::t[str] body) -> base::macro_def {
- let option::t[str] macro_name = none;
- let (clause)[] clauses = ~[];
- for (@expr arg in args) {
- alt(arg.node) {
- case(expr_vec(?elts, ?mut, ?seq_kind)) {
- if (ivec::len(elts) != 2u) {
+fn add_new_extension(cx: &ext_ctxt, sp: span, args: &(@expr)[],
+ body: option::t[str]) -> base::macro_def {
+ let macro_name: option::t[str] = none;
+ let clauses: clause[] = ~[];
+ for arg: @expr in args {
+ alt arg.node {
+ expr_vec(elts, mut, seq_kind) {
+ if ivec::len(elts) != 2u {
cx.span_fatal((*arg).span,
"extension clause must consist of [" +
- "macro invocation, expansion body]");
+ "macro invocation, expansion body]");
}
- alt(elts.(0u).node) {
- case(expr_mac(?mac)) {
- alt (mac.node) {
- case (mac_invoc(?pth, ?invoc_args, ?body)) {
- alt (path_to_ident(pth)) {
- case (some(?id)) { macro_name=some(id); }
- case (none) {
- cx.span_fatal(pth.span, "macro name "
- + "must not be a path");
+
+ alt elts.(0u).node {
+ expr_mac(mac) {
+ alt mac.node {
+ mac_invoc(pth, invoc_args, body) {
+ alt path_to_ident(pth) {
+ some(id) { macro_name = some(id); }
+ none. {
+ cx.span_fatal(pth.span,
+ "macro name " + "must not be a path");
}
}
- auto bdrses = ~[];
- for(@expr arg in invoc_args) {
- bdrses +=
- ~[pattern_to_selectors(cx, arg)];
+ let bdrses = ~[];
+ for arg: @expr in invoc_args {
+ bdrses += ~[pattern_to_selectors(cx, arg)];
}
- clauses +=
- ~[rec(params=bdrses, body=elts.(1u))];
+ clauses += ~[{params: bdrses, body: elts.(1u)}];
// FIXME: check duplicates (or just simplify
// the macro arg situation)
}
}
}
- case(_) {
- cx.span_fatal(elts.(0u).span, "extension clause must"
- + " start with a macro invocation.");
+ _ {
+ cx.span_fatal(elts.(0u).span,
+ "extension clause must" +
+ " start with a macro invocation.");
}
}
}
- case(_) {
- cx.span_fatal((*arg).span, "extension must be [clause, "
- + " ...]");
+ _ {
+ cx.span_fatal((*arg).span,
+ "extension must be [clause, " + " ...]");
}
}
}
- auto ext = bind generic_extension(_,_,_,_,clauses);
+ let ext = bind generic_extension(_, _, _, _, clauses);
- ret rec(ident=alt (macro_name) {
- case (some(?id)) { id }
- case (none) {
- cx.span_fatal(sp, "macro definition must have "
- + "at least one clause")
- }
- }, ext=normal(ext));
+ ret {ident:
+ alt macro_name {
+ some(id) { id }
+ none. {
+ cx.span_fatal(sp,
+ "macro definition must have " +
+ "at least one clause")
+ }
+ },
+ ext: normal(ext)};
- fn generic_extension(&ext_ctxt cx, span sp, &(@expr)[] args,
- option::t[str] body, (clause)[] clauses)
- -> @expr {
+ fn generic_extension(cx: &ext_ctxt, sp: span, args: &(@expr)[],
+ body: option::t[str], clauses: clause[]) -> @expr {
- for (clause c in clauses) {
- if (ivec::len(args) != ivec::len(c.params)) { cont; }
- let uint i = 0u;
- let bindings bdgs = new_str_hash[arb_depth[matchable]]();
- let bool abort = false;
- while (i < ivec::len(args)) {
- alt (use_selectors_to_bind(c.params.(i), args.(i))) {
- case (some(?new_bindings)) {
+ for c: clause in clauses {
+ if ivec::len(args) != ivec::len(c.params) { cont; }
+ let i: uint = 0u;
+ let bdgs: bindings = new_str_hash[arb_depth[matchable]]();
+ let abort: bool = false;
+ while i < ivec::len(args) {
+ alt use_selectors_to_bind(c.params.(i), args.(i)) {
+ some(new_bindings) {
+
/* ick; I wish macros just took one expr */
- for each (@rec(ident key, arb_depth[matchable] val) it
- in new_bindings.items()) {
+ for each it: @{key: ident, val: arb_depth[matchable]} in
+ new_bindings.items() {
bdgs.insert(it.key, it.val);
}
}
- case (none) { abort = true; }
+ none. { abort = true; }
}
i += 1u;
}
- if (abort) { cont; }
+ if abort { cont; }
ret transcribe(cx, bdgs, c.body);
}
cx.span_fatal(sp, "no clauses match macro invocation");
diff --git a/src/comp/syntax/fold.rs b/src/comp/syntax/fold.rs
index d3290c7..4bb9545 100644
--- a/src/comp/syntax/fold.rs
+++ b/src/comp/syntax/fold.rs
@@ -19,705 +19,675 @@
// We may eventually want to be able to fold over type parameters, too
type ast_fold_precursor =
- rec(fn (&crate_ c, ast_fold) -> crate_ fold_crate,
- fn (&crate_directive_ cd, ast_fold) -> crate_directive_
- fold_crate_directive,
- fn (&view_item_ i, ast_fold) -> view_item_ fold_view_item,
- fn (&@native_item i, ast_fold) -> @native_item fold_native_item,
- fn (&@item i, ast_fold) -> @item fold_item,
- //unlike the others, item_ is non-trivial
- fn (&item_ i, ast_fold) -> item_ fold_item_underscore,
- fn (&method_ m, ast_fold) -> method_ fold_method,
- fn (&blk_ b, ast_fold) -> blk_ fold_block,
- fn (&stmt_ s, ast_fold) -> stmt_ fold_stmt,
- fn (&arm a, ast_fold) -> arm fold_arm,
- fn (&pat_ p, ast_fold) -> pat_ fold_pat,
- fn (&decl_ d, ast_fold) -> decl_ fold_decl,
- fn (&expr_ e, ast_fold) -> expr_ fold_expr,
- fn (&ty_ t, ast_fold) -> ty_ fold_ty,
- fn (&ast::constr_ c, ast_fold) -> constr_ fold_constr,
- fn (&_fn f, ast_fold) -> _fn fold_fn,
- fn (&_mod m, ast_fold) -> _mod fold_mod,
- fn (&native_mod, ast_fold) -> native_mod fold_native_mod,
- fn (&variant_, ast_fold) -> variant_ fold_variant,
- fn (&ident, ast_fold) -> ident fold_ident,
- fn (&path_, ast_fold) -> path_ fold_path,
- fn (&local_, ast_fold) -> local_ fold_local,
- fn (fn(&@expr)->@expr, (@expr)[] es) -> (@expr)[] map_exprs
- );
+ //unlike the others, item_ is non-trivial
+ {fold_crate: fn(&crate_, ast_fold) -> crate_ ,
+ fold_crate_directive:
+ fn(&crate_directive_, ast_fold) -> crate_directive_ ,
+ fold_view_item: fn(&view_item_, ast_fold) -> view_item_ ,
+ fold_native_item: fn(&@native_item, ast_fold) -> @native_item ,
+ fold_item: fn(&@item, ast_fold) -> @item ,
+ fold_item_underscore: fn(&item_, ast_fold) -> item_ ,
+ fold_method: fn(&method_, ast_fold) -> method_ ,
+ fold_block: fn(&blk_, ast_fold) -> blk_ ,
+ fold_stmt: fn(&stmt_, ast_fold) -> stmt_ ,
+ fold_arm: fn(&arm, ast_fold) -> arm ,
+ fold_pat: fn(&pat_, ast_fold) -> pat_ ,
+ fold_decl: fn(&decl_, ast_fold) -> decl_ ,
+ fold_expr: fn(&expr_, ast_fold) -> expr_ ,
+ fold_ty: fn(&ty_, ast_fold) -> ty_ ,
+ fold_constr: fn(&ast::constr_, ast_fold) -> constr_ ,
+ fold_fn: fn(&_fn, ast_fold) -> _fn ,
+ fold_mod: fn(&_mod, ast_fold) -> _mod ,
+ fold_native_mod: fn(&native_mod, ast_fold) -> native_mod ,
+ fold_variant: fn(&variant_, ast_fold) -> variant_ ,
+ fold_ident: fn(&ident, ast_fold) -> ident ,
+ fold_path: fn(&path_, ast_fold) -> path_ ,
+ fold_local: fn(&local_, ast_fold) -> local_ ,
+ map_exprs: fn(fn(&@expr) -> @expr , (@expr)[]) -> (@expr)[] };
type a_f =
- rec(fn (&crate c) -> crate fold_crate,
- fn (&@crate_directive cd) -> @crate_directive fold_crate_directive,
- fn (&@view_item i) -> @view_item fold_view_item,
- fn (&@native_item i) -> @native_item fold_native_item,
- fn (&@item i) -> @item fold_item,
- fn (&item_ i) -> item_ fold_item_underscore,
- fn (&@method m) -> @method fold_method,
- fn (&blk b) -> blk fold_block,
- fn (&@stmt s) -> @stmt fold_stmt,
- fn (&arm a) -> arm fold_arm,
- fn (&@pat p) -> @pat fold_pat,
- fn (&@decl d) -> @decl fold_decl,
- fn (&@expr e) -> @expr fold_expr,
- fn (&@ty t) -> @ty fold_ty,
- fn (&@constr c) -> @constr fold_constr,
- fn (&_fn f) -> _fn fold_fn,
- fn (&_mod m) -> _mod fold_mod,
- fn (&native_mod) -> native_mod fold_native_mod,
- fn (&variant) -> variant fold_variant,
- fn (&ident) -> ident fold_ident,
- fn (&path) -> path fold_path,
- fn (&@local) -> @local fold_local,
- fn (fn(&@expr)->@expr, (@expr)[] es) -> (@expr)[] map_exprs
- );
+ {fold_crate: fn(&crate) -> crate ,
+ fold_crate_directive: fn(&@crate_directive) -> @crate_directive ,
+ fold_view_item: fn(&@view_item) -> @view_item ,
+ fold_native_item: fn(&@native_item) -> @native_item ,
+ fold_item: fn(&@item) -> @item ,
+ fold_item_underscore: fn(&item_) -> item_ ,
+ fold_method: fn(&@method) -> @method ,
+ fold_block: fn(&blk) -> blk ,
+ fold_stmt: fn(&@stmt) -> @stmt ,
+ fold_arm: fn(&arm) -> arm ,
+ fold_pat: fn(&@pat) -> @pat ,
+ fold_decl: fn(&@decl) -> @decl ,
+ fold_expr: fn(&@expr) -> @expr ,
+ fold_ty: fn(&@ty) -> @ty ,
+ fold_constr: fn(&@constr) -> @constr ,
+ fold_fn: fn(&_fn) -> _fn ,
+ fold_mod: fn(&_mod) -> _mod ,
+ fold_native_mod: fn(&native_mod) -> native_mod ,
+ fold_variant: fn(&variant) -> variant ,
+ fold_ident: fn(&ident) -> ident ,
+ fold_path: fn(&path) -> path ,
+ fold_local: fn(&@local) -> @local ,
+ map_exprs: fn(fn(&@expr) -> @expr , (@expr)[]) -> (@expr)[] };
//fn nf_dummy[T](&T node) -> T { fail; }
-fn nf_crate_dummy(&crate c) -> crate { fail; }
-fn nf_crate_directive_dummy(&@crate_directive c)
- -> @crate_directive { fail; }
-fn nf_view_item_dummy(&@view_item v) -> @view_item { fail; }
-fn nf_native_item_dummy(&@native_item n) -> @native_item { fail; }
-fn nf_item_dummy(&@item i) -> @item { fail; }
-fn nf_item_underscore_dummy(&item_ i) -> item_ { fail; }
-fn nf_method_dummy(&@method m) -> @method { fail; }
-fn nf_blk_dummy(&blk b) -> blk { fail; }
-fn nf_stmt_dummy(&@stmt s) -> @stmt { fail; }
-fn nf_arm_dummy(&arm a) -> arm { fail; }
-fn nf_pat_dummy(&@pat p) -> @pat { fail; }
-fn nf_decl_dummy(&@decl d) -> @decl { fail; }
-fn nf_expr_dummy(&@expr e) -> @expr { fail; }
-fn nf_ty_dummy(&@ty t) -> @ty { fail; }
-fn nf_constr_dummy(&@constr c) -> @constr { fail; }
-fn nf_fn_dummy(&_fn f) -> _fn { fail; }
-fn nf_mod_dummy(&_mod m) -> _mod { fail; }
-fn nf_native_mod_dummy(&native_mod n) -> native_mod { fail; }
-fn nf_variant_dummy(&variant v) -> variant { fail; }
-fn nf_ident_dummy(&ident i) -> ident { fail; }
-fn nf_path_dummy(&path p) -> path { fail; }
-fn nf_obj_field_dummy(&obj_field o) -> obj_field { fail; }
-fn nf_local_dummy(&@local o) -> @local { fail; }
+fn nf_crate_dummy(c: &crate) -> crate { fail; }
+fn nf_crate_directive_dummy(c: &@crate_directive) -> @crate_directive {
+ fail;
+}
+fn nf_view_item_dummy(v: &@view_item) -> @view_item { fail; }
+fn nf_native_item_dummy(n: &@native_item) -> @native_item { fail; }
+fn nf_item_dummy(i: &@item) -> @item { fail; }
+fn nf_item_underscore_dummy(i: &item_) -> item_ { fail; }
+fn nf_method_dummy(m: &@method) -> @method { fail; }
+fn nf_blk_dummy(b: &blk) -> blk { fail; }
+fn nf_stmt_dummy(s: &@stmt) -> @stmt { fail; }
+fn nf_arm_dummy(a: &arm) -> arm { fail; }
+fn nf_pat_dummy(p: &@pat) -> @pat { fail; }
+fn nf_decl_dummy(d: &@decl) -> @decl { fail; }
+fn nf_expr_dummy(e: &@expr) -> @expr { fail; }
+fn nf_ty_dummy(t: &@ty) -> @ty { fail; }
+fn nf_constr_dummy(c: &@constr) -> @constr { fail; }
+fn nf_fn_dummy(f: &_fn) -> _fn { fail; }
+fn nf_mod_dummy(m: &_mod) -> _mod { fail; }
+fn nf_native_mod_dummy(n: &native_mod) -> native_mod { fail; }
+fn nf_variant_dummy(v: &variant) -> variant { fail; }
+fn nf_ident_dummy(i: &ident) -> ident { fail; }
+fn nf_path_dummy(p: &path) -> path { fail; }
+fn nf_obj_field_dummy(o: &obj_field) -> obj_field { fail; }
+fn nf_local_dummy(o: &@local) -> @local { fail; }
/* some little folds that probably aren't useful to have in ast_fold itself*/
//used in noop_fold_item and noop_fold_crate and noop_fold_crate_directive
-fn fold_meta_item_(&@meta_item mi, ast_fold fld) -> @meta_item {
- ret @rec(node=
- alt (mi.node) {
- case (meta_word(?id)) { meta_word(fld.fold_ident(id)) }
- case (meta_list(?id, ?mis)) {
- auto fold_meta_item = bind fold_meta_item_(_,fld);
- meta_list(id, ivec::map(fold_meta_item, mis))
- }
- case (meta_name_value(?id,?s)) {
- meta_name_value(fld.fold_ident(id),s)
- }
- },
- span=mi.span);
+fn fold_meta_item_(mi: &@meta_item, fld: ast_fold) -> @meta_item {
+ ret @{node:
+ alt mi.node {
+ meta_word(id) { meta_word(fld.fold_ident(id)) }
+ meta_list(id, mis) {
+ let fold_meta_item = bind fold_meta_item_(_, fld);
+ meta_list(id, ivec::map(fold_meta_item, mis))
+ }
+ meta_name_value(id, s) {
+ meta_name_value(fld.fold_ident(id), s)
+ }
+ },
+ span: mi.span};
}
//used in noop_fold_item and noop_fold_crate
-fn fold_attribute_(&attribute at, fn(&@meta_item) -> @meta_item fmi)
- -> attribute {
- ret rec(node=rec(style=at.node.style,
- value=*fmi(@at.node.value)),
- span=at.span);
+fn fold_attribute_(at: &attribute, fmi: fn(&@meta_item) -> @meta_item ) ->
+ attribute {
+ ret {node: {style: at.node.style, value: *fmi(@at.node.value)},
+ span: at.span};
}
//used in noop_fold_native_item and noop_fold_fn
-fn fold_arg_(&arg a, ast_fold fld) -> arg {
- ret rec(mode=a.mode, ty=fld.fold_ty(a.ty),
- ident=fld.fold_ident(a.ident), id=a.id);
+fn fold_arg_(a: &arg, fld: ast_fold) -> arg {
+ ret {mode: a.mode,
+ ty: fld.fold_ty(a.ty),
+ ident: fld.fold_ident(a.ident),
+ id: a.id};
}
//used in noop_fold_expr, and possibly elsewhere in the future
-fn fold_mac_(&mac m, ast_fold fld) -> mac {
- ret rec(node=
- alt(m.node) {
- case (mac_invoc(?pth,?args,?body)) {
- mac_invoc(fld.fold_path(pth),
- fld.map_exprs(fld.fold_expr, args), body)
- }
- case (mac_embed_type(?ty)) {
- mac_embed_type(fld.fold_ty(ty))
- }
- case (mac_embed_block(?blk)) {
- mac_embed_block(fld.fold_block(blk))
- }
- case (mac_ellipsis) { mac_ellipsis }
- },
- span=m.span);
+fn fold_mac_(m: &mac, fld: ast_fold) -> mac {
+ ret {node:
+ alt m.node {
+ mac_invoc(pth, args, body) {
+ mac_invoc(fld.fold_path(pth),
+ fld.map_exprs(fld.fold_expr, args), body)
+ }
+ mac_embed_type(ty) { mac_embed_type(fld.fold_ty(ty)) }
+ mac_embed_block(blk) { mac_embed_block(fld.fold_block(blk)) }
+ mac_ellipsis. { mac_ellipsis }
+ },
+ span: m.span};
}
-fn noop_fold_crate(&crate_ c, ast_fold fld) -> crate_ {
- auto fold_meta_item = bind fold_meta_item_(_,fld);
- auto fold_attribute = bind fold_attribute_(_,fold_meta_item);
+fn noop_fold_crate(c: &crate_, fld: ast_fold) -> crate_ {
+ let fold_meta_item = bind fold_meta_item_(_, fld);
+ let fold_attribute = bind fold_attribute_(_, fold_meta_item);
- ret rec(directives=ivec::map(fld.fold_crate_directive, c.directives),
- module=fld.fold_mod(c.module),
- attrs=ivec::map(fold_attribute, c.attrs),
- config=ivec::map(fold_meta_item, c.config));
+ ret {directives: ivec::map(fld.fold_crate_directive, c.directives),
+ module: fld.fold_mod(c.module),
+ attrs: ivec::map(fold_attribute, c.attrs),
+ config: ivec::map(fold_meta_item, c.config)};
}
-fn noop_fold_crate_directive(&crate_directive_ cd, ast_fold fld)
- -> crate_directive_ {
- ret alt(cd) {
- case(cdir_src_mod(?id,?fname,?attrs)) {
+fn noop_fold_crate_directive(cd: &crate_directive_, fld: ast_fold) ->
+ crate_directive_ {
+ ret alt cd {
+ cdir_src_mod(id, fname, attrs) {
cdir_src_mod(fld.fold_ident(id), fname, attrs)
- }
- case(cdir_dir_mod(?id,?fname,?cds,?attrs)) {
- cdir_dir_mod(fld.fold_ident(id),fname,
+ }
+ cdir_dir_mod(id, fname, cds, attrs) {
+ cdir_dir_mod(fld.fold_ident(id), fname,
ivec::map(fld.fold_crate_directive, cds), attrs)
- }
- case(cdir_view_item(?vi)) {
- cdir_view_item(fld.fold_view_item(vi))
- }
- case(cdir_syntax(_)) { cd }
- case(cdir_auth(_,_)) { cd }
- }
+ }
+ cdir_view_item(vi) { cdir_view_item(fld.fold_view_item(vi)) }
+ cdir_syntax(_) { cd }
+ cdir_auth(_, _) { cd }
+ }
}
-fn noop_fold_view_item(&view_item_ vi, ast_fold fld) -> view_item_ {
+fn noop_fold_view_item(vi: &view_item_, fld: ast_fold) -> view_item_ {
ret vi;
}
-fn noop_fold_native_item(&@native_item ni, ast_fold fld) -> @native_item {
- auto fold_arg = bind fold_arg_(_, fld);
- auto fold_meta_item = bind fold_meta_item_(_,fld);
- auto fold_attribute = bind fold_attribute_(_,fold_meta_item);
+fn noop_fold_native_item(ni: &@native_item, fld: ast_fold) -> @native_item {
+ let fold_arg = bind fold_arg_(_, fld);
+ let fold_meta_item = bind fold_meta_item_(_, fld);
+ let fold_attribute = bind fold_attribute_(_, fold_meta_item);
- ret @rec(ident=fld.fold_ident(ni.ident),
- attrs=ivec::map(fold_attribute, ni.attrs),
- node=alt (ni.node) {
- case (native_item_ty) { native_item_ty }
- case (native_item_fn(?st, ?fdec, ?typms)) {
- native_item_fn(st,
- rec(inputs=ivec::map(fold_arg,
- fdec.inputs),
- output=fld.fold_ty(fdec.output),
- purity=fdec.purity, cf=fdec.cf,
- constraints=ivec::map(fld.fold_constr,
- fdec.constraints)),
- typms)
- }
- },
- id=ni.id,
- span=ni.span);
+ ret @{ident: fld.fold_ident(ni.ident),
+ attrs: ivec::map(fold_attribute, ni.attrs),
+ node:
+ alt ni.node {
+ native_item_ty. { native_item_ty }
+ native_item_fn(st, fdec, typms) {
+ native_item_fn(st,
+ {inputs: ivec::map(fold_arg, fdec.inputs),
+ output: fld.fold_ty(fdec.output),
+ purity: fdec.purity,
+ cf: fdec.cf,
+ constraints:
+ ivec::map(fld.fold_constr,
+ fdec.constraints)}, typms)
+ }
+ },
+ id: ni.id,
+ span: ni.span};
}
-fn noop_fold_item(&@item i, ast_fold fld) -> @item {
- auto fold_meta_item = bind fold_meta_item_(_,fld);
- auto fold_attribute = bind fold_attribute_(_,fold_meta_item);
+fn noop_fold_item(i: &@item, fld: ast_fold) -> @item {
+ let fold_meta_item = bind fold_meta_item_(_, fld);
+ let fold_attribute = bind fold_attribute_(_, fold_meta_item);
- ret @rec(ident=fld.fold_ident(i.ident),
- attrs=ivec::map(fold_attribute,i.attrs),
- id=i.id, node=fld.fold_item_underscore(i.node),
- span=i.span);
+ ret @{ident: fld.fold_ident(i.ident),
+ attrs: ivec::map(fold_attribute, i.attrs),
+ id: i.id,
+ node: fld.fold_item_underscore(i.node),
+ span: i.span};
}
-fn noop_fold_item_underscore(&item_ i, ast_fold fld) -> item_ {
- fn fold_obj_field_(&obj_field of, ast_fold fld) -> obj_field {
- ret rec(mut=of.mut, ty=fld.fold_ty(of.ty),
- ident=fld.fold_ident(of.ident), id=of.id);
+fn noop_fold_item_underscore(i: &item_, fld: ast_fold) -> item_ {
+ fn fold_obj_field_(of: &obj_field, fld: ast_fold) -> obj_field {
+ ret {mut: of.mut,
+ ty: fld.fold_ty(of.ty),
+ ident: fld.fold_ident(of.ident),
+ id: of.id};
}
- auto fold_obj_field = bind fold_obj_field_(_,fld);
+ let fold_obj_field = bind fold_obj_field_(_, fld);
- ret alt(i) {
- case (item_const(?t, ?e)) {
- item_const(fld.fold_ty(t), fld.fold_expr(e))
- }
- case (item_fn(?f, ?typms)) {
- item_fn(fld.fold_fn(f), typms)
- }
- case (item_mod(?m)) { item_mod(fld.fold_mod(m)) }
- case (item_native_mod(?nm)) {
- item_native_mod(fld.fold_native_mod(nm))
- }
- case (item_ty(?t, ?typms)) {
- item_ty(fld.fold_ty(t), typms)
- }
- case (item_tag(?variants, ?typms)) {
+ ret alt i {
+ item_const(t, e) { item_const(fld.fold_ty(t), fld.fold_expr(e)) }
+ item_fn(f, typms) { item_fn(fld.fold_fn(f), typms) }
+ item_mod(m) { item_mod(fld.fold_mod(m)) }
+ item_native_mod(nm) { item_native_mod(fld.fold_native_mod(nm)) }
+ item_ty(t, typms) { item_ty(fld.fold_ty(t), typms) }
+ item_tag(variants, typms) {
item_tag(ivec::map(fld.fold_variant, variants), typms)
- }
- case (item_obj(?o, ?typms, ?d)) {
- item_obj(rec(fields=ivec::map(fold_obj_field,o.fields),
- methods=ivec::map(fld.fold_method,o.methods),
- dtor=option::map(fld.fold_method,o.dtor)),
- typms, d)
- }
- case (item_res(?dtor, ?did, ?typms, ?cid)) {
+ }
+ item_obj(o, typms, d) {
+ item_obj({fields: ivec::map(fold_obj_field, o.fields),
+ methods: ivec::map(fld.fold_method, o.methods),
+ dtor: option::map(fld.fold_method, o.dtor)}, typms, d)
+ }
+ item_res(dtor, did, typms, cid) {
item_res(fld.fold_fn(dtor), did, typms, cid)
- }
- };
+ }
+ };
}
-fn noop_fold_method(&method_ m, ast_fold fld) -> method_ {
- ret rec(ident=fld.fold_ident(m.ident),
- meth=fld.fold_fn(m.meth), id=m.id);
+fn noop_fold_method(m: &method_, fld: ast_fold) -> method_ {
+ ret {ident: fld.fold_ident(m.ident), meth: fld.fold_fn(m.meth), id: m.id};
}
-fn noop_fold_block(&blk_ b, ast_fold fld) -> blk_ {
- ret rec(stmts=ivec::map(fld.fold_stmt, b.stmts),
- expr=option::map(fld.fold_expr, b.expr), id=b.id);
+fn noop_fold_block(b: &blk_, fld: ast_fold) -> blk_ {
+ ret {stmts: ivec::map(fld.fold_stmt, b.stmts),
+ expr: option::map(fld.fold_expr, b.expr),
+ id: b.id};
}
-fn noop_fold_stmt(&stmt_ s, ast_fold fld) -> stmt_ {
- ret alt(s) {
- case (stmt_decl(?d, ?nid)) { stmt_decl(fld.fold_decl(d), nid) }
- case (stmt_expr(?e, ?nid)) { stmt_expr(fld.fold_expr(e), nid) }
- case (stmt_crate_directive(?cd)) {
- stmt_crate_directive(fld.fold_crate_directive(cd))
- }
- };
+fn noop_fold_stmt(s: &stmt_, fld: ast_fold) -> stmt_ {
+ ret alt s {
+ stmt_decl(d, nid) { stmt_decl(fld.fold_decl(d), nid) }
+ stmt_expr(e, nid) { stmt_expr(fld.fold_expr(e), nid) }
+ stmt_crate_directive(cd) {
+ stmt_crate_directive(fld.fold_crate_directive(cd))
+ }
+ };
}
-fn noop_fold_arm(&arm a, ast_fold fld) -> arm {
- ret rec(pats=ivec::map(fld.fold_pat, a.pats),
- block=fld.fold_block(a.block));
+fn noop_fold_arm(a: &arm, fld: ast_fold) -> arm {
+ ret {pats: ivec::map(fld.fold_pat, a.pats),
+ block: fld.fold_block(a.block)};
}
-fn noop_fold_pat(&pat_ p, ast_fold fld) -> pat_ {
- ret alt (p) {
- case (pat_wild) { p }
- case (pat_bind(?ident)) { pat_bind(fld.fold_ident(ident))}
- case (pat_lit(_)) { p }
- case (pat_tag(?pth, ?pats)) {
+fn noop_fold_pat(p: &pat_, fld: ast_fold) -> pat_ {
+ ret alt p {
+ pat_wild. { p }
+ pat_bind(ident) { pat_bind(fld.fold_ident(ident)) }
+ pat_lit(_) { p }
+ pat_tag(pth, pats) {
pat_tag(fld.fold_path(pth), ivec::map(fld.fold_pat, pats))
- }
- case (pat_rec(?fields, ?etc)) {
- auto fs = ~[];
- for (ast::field_pat f in fields) {
- fs += ~[rec(ident=f.ident, pat=fld.fold_pat(f.pat))];
+ }
+ pat_rec(fields, etc) {
+ let fs = ~[];
+ for f: ast::field_pat in fields {
+ fs += ~[{ident: f.ident, pat: fld.fold_pat(f.pat)}];
}
pat_rec(fs, etc)
- }
- case (pat_box(?inner)) { pat_box(fld.fold_pat(inner)) }
- };
+ }
+ pat_box(inner) { pat_box(fld.fold_pat(inner)) }
+ };
}
-fn noop_fold_decl(&decl_ d, ast_fold fld) -> decl_ {
- ret alt (d) {
- case (decl_local(?ls)) {
- decl_local(ivec::map(fld.fold_local, ls))
+fn noop_fold_decl(d: &decl_, fld: ast_fold) -> decl_ {
+ ret alt d {
+ decl_local(ls) { decl_local(ivec::map(fld.fold_local, ls)) }
+ decl_item(it) { decl_item(fld.fold_item(it)) }
}
- case (decl_item(?it)) { decl_item(fld.fold_item(it)) }
- }
}
-fn noop_fold_expr(&expr_ e, ast_fold fld) -> expr_ {
- fn fold_field_(&field field, ast_fold fld) -> field {
- ret rec(node=rec(mut=field.node.mut,
- ident=fld.fold_ident(field.node.ident),
- expr=fld.fold_expr(field.node.expr)),
- span=field.span);
+fn noop_fold_expr(e: &expr_, fld: ast_fold) -> expr_ {
+ fn fold_field_(field: &field, fld: ast_fold) -> field {
+ ret {node:
+ {mut: field.node.mut,
+ ident: fld.fold_ident(field.node.ident),
+ expr: fld.fold_expr(field.node.expr)},
+ span: field.span};
}
- auto fold_field = bind fold_field_(_,fld);
- fn fold_anon_obj_(&anon_obj ao, ast_fold fld) -> anon_obj {
- fn fold_anon_obj_field_(&anon_obj_field aof, ast_fold fld)
- -> anon_obj_field {
- ret rec(mut=aof.mut, ty=fld.fold_ty(aof.ty),
- expr=fld.fold_expr(aof.expr),
- ident=fld.fold_ident(aof.ident), id=aof.id);
+ let fold_field = bind fold_field_(_, fld);
+ fn fold_anon_obj_(ao: &anon_obj, fld: ast_fold) -> anon_obj {
+ fn fold_anon_obj_field_(aof: &anon_obj_field, fld: ast_fold) ->
+ anon_obj_field {
+ ret {mut: aof.mut,
+ ty: fld.fold_ty(aof.ty),
+ expr: fld.fold_expr(aof.expr),
+ ident: fld.fold_ident(aof.ident),
+ id: aof.id};
}
- auto fold_anon_obj_field = bind fold_anon_obj_field_(_,fld);
+ let fold_anon_obj_field = bind fold_anon_obj_field_(_, fld);
- ret rec(fields=alt(ao.fields) {
- case (option::none[anon_obj_field[]]) { ao.fields }
- case (option::some[anon_obj_field[]](?v)) {
- option::some[anon_obj_field[]]
- (ivec::map(fold_anon_obj_field, v))
- }},
- methods=ivec::map(fld.fold_method, ao.methods),
- with_obj=option::map(fld.fold_expr, ao.with_obj))
+
+ ret {fields:
+ alt ao.fields {
+ option::none[anon_obj_field[]]. { ao.fields }
+ option::some[anon_obj_field[]](v) {
+ option::some[anon_obj_field[]](ivec::map(fold_anon_obj_field,
+ v))
+ }
+ },
+ methods: ivec::map(fld.fold_method, ao.methods),
+ with_obj: option::map(fld.fold_expr, ao.with_obj)}
}
- auto fold_anon_obj = bind fold_anon_obj_(_,fld);
+ let fold_anon_obj = bind fold_anon_obj_(_, fld);
- auto fold_mac = bind fold_mac_(_,fld);
+ let fold_mac = bind fold_mac_(_, fld);
- ret alt (e) {
- case (expr_vec(?exprs, ?mut, ?seq_kind)) {
+
+ ret alt e {
+ expr_vec(exprs, mut, seq_kind) {
expr_vec(fld.map_exprs(fld.fold_expr, exprs), mut, seq_kind)
- }
- case (expr_rec(?fields, ?maybe_expr)) {
+ }
+ expr_rec(fields, maybe_expr) {
expr_rec(ivec::map(fold_field, fields),
option::map(fld.fold_expr, maybe_expr))
- }
- case (expr_call(?f, ?args)) {
+ }
+ expr_call(f, args) {
expr_call(fld.fold_expr(f), fld.map_exprs(fld.fold_expr, args))
- }
- case (expr_self_method(?id)) {
- expr_self_method(fld.fold_ident(id))
- }
- case (expr_bind(?f, ?args)) {
- auto opt_map_se = bind option::map(fld.fold_expr,_);
+ }
+ expr_self_method(id) { expr_self_method(fld.fold_ident(id)) }
+ expr_bind(f, args) {
+ let opt_map_se = bind option::map(fld.fold_expr, _);
expr_bind(fld.fold_expr(f), ivec::map(opt_map_se, args))
- }
- case (expr_spawn(?spawn_dom, ?name, ?f, ?args)) {
+ }
+ expr_spawn(spawn_dom, name, f, args) {
expr_spawn(spawn_dom, name, fld.fold_expr(f),
fld.map_exprs(fld.fold_expr, args))
- }
- case (expr_binary(?binop, ?lhs, ?rhs)) {
+ }
+ expr_binary(binop, lhs, rhs) {
expr_binary(binop, fld.fold_expr(lhs), fld.fold_expr(rhs))
- }
- case (expr_unary(?binop, ?ohs)) {
- expr_unary(binop, fld.fold_expr(ohs))
- }
- case (expr_lit(_)) { e }
- case (expr_cast(?expr, ?ty)) {
- expr_cast(fld.fold_expr(expr), ty)
- }
- case (expr_if(?cond, ?tr, ?fl)) {
+ }
+ expr_unary(binop, ohs) { expr_unary(binop, fld.fold_expr(ohs)) }
+ expr_lit(_) { e }
+ expr_cast(expr, ty) { expr_cast(fld.fold_expr(expr), ty) }
+ expr_if(cond, tr, fl) {
expr_if(fld.fold_expr(cond), fld.fold_block(tr),
option::map(fld.fold_expr, fl))
- }
- case (expr_ternary(?cond, ?tr, ?fl)) {
- expr_ternary(fld.fold_expr(cond),
- fld.fold_expr(tr),
+ }
+ expr_ternary(cond, tr, fl) {
+ expr_ternary(fld.fold_expr(cond), fld.fold_expr(tr),
fld.fold_expr(fl))
- }
- case (expr_while(?cond, ?body)) {
+ }
+ expr_while(cond, body) {
expr_while(fld.fold_expr(cond), fld.fold_block(body))
- }
- case (expr_for(?decl, ?expr, ?blk)) {
+ }
+ expr_for(decl, expr, blk) {
expr_for(fld.fold_local(decl), fld.fold_expr(expr),
fld.fold_block(blk))
- }
- case (expr_for_each(?decl, ?expr, ?blk)) {
+ }
+ expr_for_each(decl, expr, blk) {
expr_for_each(fld.fold_local(decl), fld.fold_expr(expr),
fld.fold_block(blk))
- }
- case (expr_do_while(?blk, ?expr)) {
+ }
+ expr_do_while(blk, expr) {
expr_do_while(fld.fold_block(blk), fld.fold_expr(expr))
- }
- case (expr_alt(?expr, ?arms)) {
+ }
+ expr_alt(expr, arms) {
expr_alt(fld.fold_expr(expr), ivec::map(fld.fold_arm, arms))
- }
- case (expr_fn(?f)) {
- expr_fn(fld.fold_fn(f))
- }
- case (expr_block(?blk)) {
- expr_block(fld.fold_block(blk))
- }
- case (expr_move(?el, ?er)) {
+ }
+ expr_fn(f) { expr_fn(fld.fold_fn(f)) }
+ expr_block(blk) { expr_block(fld.fold_block(blk)) }
+ expr_move(el, er) {
expr_move(fld.fold_expr(el), fld.fold_expr(er))
- }
- case (expr_assign(?el, ?er)) {
+ }
+ expr_assign(el, er) {
expr_assign(fld.fold_expr(el), fld.fold_expr(er))
- }
- case (expr_swap(?el, ?er)) {
+ }
+ expr_swap(el, er) {
expr_swap(fld.fold_expr(el), fld.fold_expr(er))
- }
- case (expr_assign_op(?op, ?el, ?er)) {
+ }
+ expr_assign_op(op, el, er) {
expr_assign_op(op, fld.fold_expr(el), fld.fold_expr(er))
- }
- case (expr_send(?el, ?er)) {
+ }
+ expr_send(el, er) {
expr_send(fld.fold_expr(el), fld.fold_expr(er))
- }
- case (expr_recv(?el, ?er)) {
+ }
+ expr_recv(el, er) {
expr_recv(fld.fold_expr(el), fld.fold_expr(er))
- }
- case (expr_field(?el, ?id)) {
+ }
+ expr_field(el, id) {
expr_field(fld.fold_expr(el), fld.fold_ident(id))
- }
- case (expr_index(?el, ?er)) {
+ }
+ expr_index(el, er) {
expr_index(fld.fold_expr(el), fld.fold_expr(er))
- }
- case (expr_path(?pth)) {
- expr_path(fld.fold_path(pth))
- }
- case (expr_fail(?e)) { expr_fail(option::map(fld.fold_expr, e)) }
- case (expr_break()) { e }
- case (expr_cont()) { e }
- case (expr_ret(?e)) {
- expr_ret(option::map(fld.fold_expr, e))
- }
- case (expr_put(?e)) {
- expr_put(option::map(fld.fold_expr, e))
- }
- case (expr_be(?e)) { expr_be(fld.fold_expr(e)) }
- case (expr_log(?lv, ?e)) { expr_log(lv, fld.fold_expr(e)) }
- case (expr_assert(?e)) { expr_assert(fld.fold_expr(e)) }
- case (expr_check(?m, ?e)) { expr_check(m, fld.fold_expr(e)) }
- case (expr_if_check(?cond, ?tr, ?fl)) {
+ }
+ expr_path(pth) { expr_path(fld.fold_path(pth)) }
+ expr_fail(e) { expr_fail(option::map(fld.fold_expr, e)) }
+ expr_break. { e }
+ expr_cont. { e }
+ expr_ret(e) { expr_ret(option::map(fld.fold_expr, e)) }
+ expr_put(e) { expr_put(option::map(fld.fold_expr, e)) }
+ expr_be(e) { expr_be(fld.fold_expr(e)) }
+ expr_log(lv, e) { expr_log(lv, fld.fold_expr(e)) }
+ expr_assert(e) { expr_assert(fld.fold_expr(e)) }
+ expr_check(m, e) { expr_check(m, fld.fold_expr(e)) }
+ expr_if_check(cond, tr, fl) {
expr_if_check(fld.fold_expr(cond), fld.fold_block(tr),
option::map(fld.fold_expr, fl))
- }
- case (expr_port(?ot)) {
- expr_port(alt(ot) {
- case (option::some(?t)) { option::some(fld.fold_ty(t)) }
- case (option::none) { option::none }
- })
- }
- case (expr_chan(?e)) { expr_chan(fld.fold_expr(e)) }
- case (expr_anon_obj(?ao)) {
- expr_anon_obj(fold_anon_obj(ao))
- }
- case (expr_mac(?mac)) {
- expr_mac(fold_mac(mac))
+ }
+ expr_port(ot) {
+ expr_port(alt ot {
+ option::some(t) { option::some(fld.fold_ty(t)) }
+ option::none. { option::none }
+ })
+ }
+ expr_chan(e) { expr_chan(fld.fold_expr(e)) }
+ expr_anon_obj(ao) { expr_anon_obj(fold_anon_obj(ao)) }
+ expr_mac(mac) { expr_mac(fold_mac(mac)) }
}
- }
}
-fn noop_fold_ty(&ty_ t, ast_fold fld) -> ty_ {
+fn noop_fold_ty(t: &ty_, fld: ast_fold) -> ty_ {
//drop in ty::fold_ty here if necessary
ret t;
}
-fn noop_fold_constr(&constr_ c, ast_fold fld) -> constr_ {
- rec(path=fld.fold_path(c.path), args=c.args, id=c.id)
+fn noop_fold_constr(c: &constr_, fld: ast_fold) -> constr_ {
+ {path: fld.fold_path(c.path), args: c.args, id: c.id}
}
// functions just don't get spans, for some reason
-fn noop_fold_fn(&_fn f, ast_fold fld) -> _fn {
- auto fold_arg = bind fold_arg_(_, fld);
+fn noop_fold_fn(f: &_fn, fld: ast_fold) -> _fn {
+ let fold_arg = bind fold_arg_(_, fld);
- ret rec(decl= rec(inputs=ivec::map(fold_arg, f.decl.inputs),
- output=fld.fold_ty(f.decl.output),
- purity=f.decl.purity,
- cf=f.decl.cf,
- constraints=ivec::map(fld.fold_constr,
- f.decl.constraints)),
- proto = f.proto,
- body = fld.fold_block(f.body));
+ ret {decl:
+ {inputs: ivec::map(fold_arg, f.decl.inputs),
+ output: fld.fold_ty(f.decl.output),
+ purity: f.decl.purity,
+ cf: f.decl.cf,
+ constraints: ivec::map(fld.fold_constr, f.decl.constraints)},
+ proto: f.proto,
+ body: fld.fold_block(f.body)};
}
// ...nor do modules
-fn noop_fold_mod(&_mod m, ast_fold fld) -> _mod {
- ret rec(view_items=ivec::map(fld.fold_view_item, m.view_items),
- items=ivec::map(fld.fold_item, m.items));
+fn noop_fold_mod(m: &_mod, fld: ast_fold) -> _mod {
+ ret {view_items: ivec::map(fld.fold_view_item, m.view_items),
+ items: ivec::map(fld.fold_item, m.items)};
}
-fn noop_fold_native_mod(&native_mod nm, ast_fold fld) -> native_mod {
- ret rec(native_name=nm.native_name,
- abi=nm.abi,
- view_items=ivec::map(fld.fold_view_item, nm.view_items),
- items=ivec::map(fld.fold_native_item, nm.items))
+fn noop_fold_native_mod(nm: &native_mod, fld: ast_fold) -> native_mod {
+ ret {native_name: nm.native_name,
+ abi: nm.abi,
+ view_items: ivec::map(fld.fold_view_item, nm.view_items),
+ items: ivec::map(fld.fold_native_item, nm.items)}
}
-fn noop_fold_variant(&variant_ v, ast_fold fld) -> variant_ {
- fn fold_variant_arg_(&variant_arg va, ast_fold fld) -> variant_arg {
- ret rec(ty=fld.fold_ty(va.ty), id=va.id);
+fn noop_fold_variant(v: &variant_, fld: ast_fold) -> variant_ {
+ fn fold_variant_arg_(va: &variant_arg, fld: ast_fold) -> variant_arg {
+ ret {ty: fld.fold_ty(va.ty), id: va.id};
}
- auto fold_variant_arg = bind fold_variant_arg_(_,fld);
- ret rec(name=v.name,
- args=ivec::map(fold_variant_arg, v.args),
- id=v.id);
+ let fold_variant_arg = bind fold_variant_arg_(_, fld);
+ ret {name: v.name, args: ivec::map(fold_variant_arg, v.args), id: v.id};
}
-fn noop_fold_ident(&ident i, ast_fold fld) -> ident {
- ret i;
+fn noop_fold_ident(i: &ident, fld: ast_fold) -> ident { ret i; }
+
+fn noop_fold_path(p: &path_, fld: ast_fold) -> path_ {
+ ret {global: p.global,
+ idents: ivec::map(fld.fold_ident, p.idents),
+ types: ivec::map(fld.fold_ty, p.types)};
}
-fn noop_fold_path(&path_ p, ast_fold fld) -> path_ {
- ret rec(global=p.global,
- idents=ivec::map(fld.fold_ident, p.idents),
- types=ivec::map(fld.fold_ty, p.types));
-}
-
-fn noop_fold_local(&local_ l, ast_fold fld) -> local_ {
- ret rec(ty=option::map(fld.fold_ty,l.ty),
- infer=l.infer,
- ident=fld.fold_ident(l.ident),
- init=alt (l.init) {
- case (option::none[initializer]) { l.init }
- case (option::some[initializer](?init)) {
- option::some[initializer]
- (rec(op=init.op,
- expr=fld.fold_expr(init.expr)))
- }
- },
- id=l.id);
+fn noop_fold_local(l: &local_, fld: ast_fold) -> local_ {
+ ret {ty: option::map(fld.fold_ty, l.ty),
+ infer: l.infer,
+ ident: fld.fold_ident(l.ident),
+ init:
+ alt l.init {
+ option::none[initializer]. { l.init }
+ option::some[initializer](init) {
+ option::some[initializer]({op: init.op,
+ expr: fld.fold_expr(init.expr)})
+ }
+ },
+ id: l.id};
}
/* temporarily eta-expand because of a compiler bug with using `fn[T]` as a
value */
-fn noop_map_exprs(fn(&@expr)->@expr f, (@expr)[] es) -> (@expr)[] {
- ret ivec::map(f,es);
+fn noop_map_exprs(f: fn(&@expr) -> @expr , es: (@expr)[]) -> (@expr)[] {
+ ret ivec::map(f, es);
}
fn default_ast_fold() -> @ast_fold_precursor {
- ret @rec(fold_crate = noop_fold_crate,
- fold_crate_directive = noop_fold_crate_directive,
- fold_view_item = noop_fold_view_item,
- fold_native_item = noop_fold_native_item,
- fold_item = noop_fold_item,
- fold_item_underscore = noop_fold_item_underscore,
- fold_method = noop_fold_method,
- fold_block = noop_fold_block,
- fold_stmt = noop_fold_stmt,
- fold_arm = noop_fold_arm,
- fold_pat = noop_fold_pat,
- fold_decl = noop_fold_decl,
- fold_expr = noop_fold_expr,
- fold_ty = noop_fold_ty,
- fold_constr = noop_fold_constr,
- fold_fn = noop_fold_fn,
- fold_mod = noop_fold_mod,
- fold_native_mod = noop_fold_native_mod,
- fold_variant = noop_fold_variant,
- fold_ident = noop_fold_ident,
- fold_path = noop_fold_path,
- fold_local = noop_fold_local,
- map_exprs = noop_map_exprs);
+ ret @{fold_crate: noop_fold_crate,
+ fold_crate_directive: noop_fold_crate_directive,
+ fold_view_item: noop_fold_view_item,
+ fold_native_item: noop_fold_native_item,
+ fold_item: noop_fold_item,
+ fold_item_underscore: noop_fold_item_underscore,
+ fold_method: noop_fold_method,
+ fold_block: noop_fold_block,
+ fold_stmt: noop_fold_stmt,
+ fold_arm: noop_fold_arm,
+ fold_pat: noop_fold_pat,
+ fold_decl: noop_fold_decl,
+ fold_expr: noop_fold_expr,
+ fold_ty: noop_fold_ty,
+ fold_constr: noop_fold_constr,
+ fold_fn: noop_fold_fn,
+ fold_mod: noop_fold_mod,
+ fold_native_mod: noop_fold_native_mod,
+ fold_variant: noop_fold_variant,
+ fold_ident: noop_fold_ident,
+ fold_path: noop_fold_path,
+ fold_local: noop_fold_local,
+ map_exprs: noop_map_exprs};
}
-fn dummy_out(ast_fold a) {
- *a = rec(fold_crate = nf_crate_dummy,
- fold_crate_directive = nf_crate_directive_dummy,
- fold_view_item = nf_view_item_dummy,
- fold_native_item = nf_native_item_dummy,
- fold_item = nf_item_dummy,
- fold_item_underscore = nf_item_underscore_dummy,
- fold_method = nf_method_dummy,
- fold_block = nf_blk_dummy,
- fold_stmt = nf_stmt_dummy,
- fold_arm = nf_arm_dummy,
- fold_pat = nf_pat_dummy,
- fold_decl = nf_decl_dummy,
- fold_expr = nf_expr_dummy,
- fold_ty = nf_ty_dummy,
- fold_constr = nf_constr_dummy,
- fold_fn = nf_fn_dummy,
- fold_mod = nf_mod_dummy,
- fold_native_mod = nf_native_mod_dummy,
- fold_variant = nf_variant_dummy,
- fold_ident = nf_ident_dummy,
- fold_path = nf_path_dummy,
- fold_local = nf_local_dummy,
- map_exprs = noop_map_exprs);
+fn dummy_out(a: ast_fold) {
+ *a =
+ {fold_crate: nf_crate_dummy,
+ fold_crate_directive: nf_crate_directive_dummy,
+ fold_view_item: nf_view_item_dummy,
+ fold_native_item: nf_native_item_dummy,
+ fold_item: nf_item_dummy,
+ fold_item_underscore: nf_item_underscore_dummy,
+ fold_method: nf_method_dummy,
+ fold_block: nf_blk_dummy,
+ fold_stmt: nf_stmt_dummy,
+ fold_arm: nf_arm_dummy,
+ fold_pat: nf_pat_dummy,
+ fold_decl: nf_decl_dummy,
+ fold_expr: nf_expr_dummy,
+ fold_ty: nf_ty_dummy,
+ fold_constr: nf_constr_dummy,
+ fold_fn: nf_fn_dummy,
+ fold_mod: nf_mod_dummy,
+ fold_native_mod: nf_native_mod_dummy,
+ fold_variant: nf_variant_dummy,
+ fold_ident: nf_ident_dummy,
+ fold_path: nf_path_dummy,
+ fold_local: nf_local_dummy,
+ map_exprs: noop_map_exprs};
}
-fn make_fold(&ast_fold_precursor afp) -> ast_fold {
- let ast_fold result =
- @mutable rec(fold_crate = nf_crate_dummy,
- fold_crate_directive = nf_crate_directive_dummy,
- fold_view_item = nf_view_item_dummy,
- fold_native_item = nf_native_item_dummy,
- fold_item = nf_item_dummy,
- fold_item_underscore = nf_item_underscore_dummy,
- fold_method = nf_method_dummy,
- fold_block = nf_blk_dummy,
- fold_stmt = nf_stmt_dummy,
- fold_arm = nf_arm_dummy,
- fold_pat = nf_pat_dummy,
- fold_decl = nf_decl_dummy,
- fold_expr = nf_expr_dummy,
- fold_ty = nf_ty_dummy,
- fold_constr = nf_constr_dummy,
- fold_fn = nf_fn_dummy,
- fold_mod = nf_mod_dummy,
- fold_native_mod = nf_native_mod_dummy,
- fold_variant = nf_variant_dummy,
- fold_ident = nf_ident_dummy,
- fold_path = nf_path_dummy,
- fold_local = nf_local_dummy,
- map_exprs = noop_map_exprs);
+fn make_fold(afp: &ast_fold_precursor) -> ast_fold {
+ let result: ast_fold =
+ @mutable {fold_crate: nf_crate_dummy,
+ fold_crate_directive: nf_crate_directive_dummy,
+ fold_view_item: nf_view_item_dummy,
+ fold_native_item: nf_native_item_dummy,
+ fold_item: nf_item_dummy,
+ fold_item_underscore: nf_item_underscore_dummy,
+ fold_method: nf_method_dummy,
+ fold_block: nf_blk_dummy,
+ fold_stmt: nf_stmt_dummy,
+ fold_arm: nf_arm_dummy,
+ fold_pat: nf_pat_dummy,
+ fold_decl: nf_decl_dummy,
+ fold_expr: nf_expr_dummy,
+ fold_ty: nf_ty_dummy,
+ fold_constr: nf_constr_dummy,
+ fold_fn: nf_fn_dummy,
+ fold_mod: nf_mod_dummy,
+ fold_native_mod: nf_native_mod_dummy,
+ fold_variant: nf_variant_dummy,
+ fold_ident: nf_ident_dummy,
+ fold_path: nf_path_dummy,
+ fold_local: nf_local_dummy,
+ map_exprs: noop_map_exprs};
/* naturally, a macro to write these would be nice */
- fn f_crate(&ast_fold_precursor afp, ast_fold f, &crate c) -> crate {
- ret rec(node=afp.fold_crate(c.node, f),
- span=c.span);
+ fn f_crate(afp: &ast_fold_precursor, f: ast_fold, c: &crate) -> crate {
+ ret {node: afp.fold_crate(c.node, f), span: c.span};
}
- fn f_crate_directive(&ast_fold_precursor afp, ast_fold f,
- &@crate_directive c) -> @crate_directive {
- ret @rec(node=afp.fold_crate_directive(c.node, f),
- span=c.span);
+ fn f_crate_directive(afp: &ast_fold_precursor, f: ast_fold,
+ c: &@crate_directive) -> @crate_directive {
+ ret @{node: afp.fold_crate_directive(c.node, f), span: c.span};
}
- fn f_view_item(&ast_fold_precursor afp, ast_fold f, &@view_item x)
- -> @view_item {
- ret @rec(node=afp.fold_view_item(x.node, f), span=x.span);
+ fn f_view_item(afp: &ast_fold_precursor, f: ast_fold, x: &@view_item) ->
+ @view_item {
+ ret @{node: afp.fold_view_item(x.node, f), span: x.span};
}
- fn f_native_item(&ast_fold_precursor afp, ast_fold f, &@native_item x)
- -> @native_item {
+ fn f_native_item(afp: &ast_fold_precursor, f: ast_fold, x: &@native_item)
+ -> @native_item {
ret afp.fold_native_item(x, f);
}
- fn f_item(&ast_fold_precursor afp, ast_fold f, &@item i) -> @item {
+ fn f_item(afp: &ast_fold_precursor, f: ast_fold, i: &@item) -> @item {
ret afp.fold_item(i, f);
}
- fn f_item_underscore(&ast_fold_precursor afp, ast_fold f, &item_ i) ->
- item_ {
+ fn f_item_underscore(afp: &ast_fold_precursor, f: ast_fold, i: &item_) ->
+ item_ {
ret afp.fold_item_underscore(i, f);
}
- fn f_method(&ast_fold_precursor afp, ast_fold f, &@method x) -> @method {
- ret @rec(node=afp.fold_method(x.node, f), span=x.span);
+ fn f_method(afp: &ast_fold_precursor, f: ast_fold, x: &@method) ->
+ @method {
+ ret @{node: afp.fold_method(x.node, f), span: x.span};
}
- fn f_block(&ast_fold_precursor afp, ast_fold f, &blk x) -> blk {
- ret rec(node=afp.fold_block(x.node, f), span=x.span);
+ fn f_block(afp: &ast_fold_precursor, f: ast_fold, x: &blk) -> blk {
+ ret {node: afp.fold_block(x.node, f), span: x.span};
}
- fn f_stmt(&ast_fold_precursor afp, ast_fold f, &@stmt x) -> @stmt {
- ret @rec(node=afp.fold_stmt(x.node, f), span=x.span);
+ fn f_stmt(afp: &ast_fold_precursor, f: ast_fold, x: &@stmt) -> @stmt {
+ ret @{node: afp.fold_stmt(x.node, f), span: x.span};
}
- fn f_arm(&ast_fold_precursor afp, ast_fold f, &arm x) -> arm {
+ fn f_arm(afp: &ast_fold_precursor, f: ast_fold, x: &arm) -> arm {
ret afp.fold_arm(x, f);
}
- fn f_pat(&ast_fold_precursor afp, ast_fold f, &@pat x) -> @pat {
- ret @rec(id=x.id, node=afp.fold_pat(x.node, f), span=x.span);
+ fn f_pat(afp: &ast_fold_precursor, f: ast_fold, x: &@pat) -> @pat {
+ ret @{id: x.id, node: afp.fold_pat(x.node, f), span: x.span};
}
- fn f_decl(&ast_fold_precursor afp, ast_fold f, &@decl x) -> @decl {
- ret @rec(node=afp.fold_decl(x.node, f), span=x.span);
+ fn f_decl(afp: &ast_fold_precursor, f: ast_fold, x: &@decl) -> @decl {
+ ret @{node: afp.fold_decl(x.node, f), span: x.span};
}
- fn f_expr(&ast_fold_precursor afp, ast_fold f, &@expr x) -> @expr {
- ret @rec(id=x.id, node=afp.fold_expr(x.node, f), span=x.span);
+ fn f_expr(afp: &ast_fold_precursor, f: ast_fold, x: &@expr) -> @expr {
+ ret @{id: x.id, node: afp.fold_expr(x.node, f), span: x.span};
}
- fn f_ty(&ast_fold_precursor afp, ast_fold f, &@ty x) -> @ty {
- ret @rec(node=afp.fold_ty(x.node, f), span=x.span);
+ fn f_ty(afp: &ast_fold_precursor, f: ast_fold, x: &@ty) -> @ty {
+ ret @{node: afp.fold_ty(x.node, f), span: x.span};
}
- fn f_constr(&ast_fold_precursor afp, ast_fold f, &@ast::constr x)
- -> @ast::constr {
- ret @rec(node=afp.fold_constr(x.node, f), span=x.span);
+ fn f_constr(afp: &ast_fold_precursor, f: ast_fold, x: &@ast::constr) ->
+ @ast::constr {
+ ret @{node: afp.fold_constr(x.node, f), span: x.span};
}
- fn f_fn(&ast_fold_precursor afp, ast_fold f, &_fn x) -> _fn {
+ fn f_fn(afp: &ast_fold_precursor, f: ast_fold, x: &_fn) -> _fn {
ret afp.fold_fn(x, f);
}
- fn f_mod(&ast_fold_precursor afp, ast_fold f, &_mod x) -> _mod {
+ fn f_mod(afp: &ast_fold_precursor, f: ast_fold, x: &_mod) -> _mod {
ret afp.fold_mod(x, f);
}
- fn f_native_mod(&ast_fold_precursor afp, ast_fold f, &native_mod x) ->
- native_mod {
+ fn f_native_mod(afp: &ast_fold_precursor, f: ast_fold, x: &native_mod) ->
+ native_mod {
ret afp.fold_native_mod(x, f);
}
- fn f_variant(&ast_fold_precursor afp, ast_fold f, &variant x)
- -> variant {
- ret rec(node=afp.fold_variant(x.node, f), span=x.span);
+ fn f_variant(afp: &ast_fold_precursor, f: ast_fold, x: &variant) ->
+ variant {
+ ret {node: afp.fold_variant(x.node, f), span: x.span};
}
- fn f_ident(&ast_fold_precursor afp, ast_fold f, &ident x) -> ident {
+ fn f_ident(afp: &ast_fold_precursor, f: ast_fold, x: &ident) -> ident {
ret afp.fold_ident(x, f);
}
- fn f_path(&ast_fold_precursor afp, ast_fold f, &path x) -> path {
- ret rec(node=afp.fold_path(x.node, f), span=x.span);
+ fn f_path(afp: &ast_fold_precursor, f: ast_fold, x: &path) -> path {
+ ret {node: afp.fold_path(x.node, f), span: x.span};
}
- fn f_local(&ast_fold_precursor afp, ast_fold f, &@local x) -> @local {
- ret @rec(node=afp.fold_local(x.node, f), span=x.span);
+ fn f_local(afp: &ast_fold_precursor, f: ast_fold, x: &@local) -> @local {
+ ret @{node: afp.fold_local(x.node, f), span: x.span};
}
- *result = rec(fold_crate = bind f_crate(afp,result,_),
- fold_crate_directive = bind f_crate_directive(afp,result,_),
- fold_view_item = bind f_view_item(afp,result,_),
- fold_native_item = bind f_native_item(afp,result,_),
- fold_item = bind f_item(afp,result,_),
- fold_item_underscore = bind f_item_underscore(afp,result,_),
- fold_method = bind f_method(afp,result,_),
- fold_block = bind f_block(afp,result,_),
- fold_stmt = bind f_stmt(afp,result,_),
- fold_arm = bind f_arm(afp, result, _),
- fold_pat = bind f_pat(afp,result,_),
- fold_decl = bind f_decl(afp,result,_),
- fold_expr = bind f_expr(afp,result,_),
- fold_ty = bind f_ty(afp,result,_),
- fold_constr = bind f_constr(afp,result,_),
- fold_fn = bind f_fn(afp,result,_),
- fold_mod = bind f_mod(afp,result,_),
- fold_native_mod = bind f_native_mod(afp,result,_),
- fold_variant = bind f_variant(afp,result,_),
- fold_ident = bind f_ident(afp,result,_),
- fold_path = bind f_path(afp,result,_),
- fold_local = bind f_local(afp,result,_),
- map_exprs = afp.map_exprs);
+ *result =
+ {fold_crate: bind f_crate(afp, result, _),
+ fold_crate_directive: bind f_crate_directive(afp, result, _),
+ fold_view_item: bind f_view_item(afp, result, _),
+ fold_native_item: bind f_native_item(afp, result, _),
+ fold_item: bind f_item(afp, result, _),
+ fold_item_underscore: bind f_item_underscore(afp, result, _),
+ fold_method: bind f_method(afp, result, _),
+ fold_block: bind f_block(afp, result, _),
+ fold_stmt: bind f_stmt(afp, result, _),
+ fold_arm: bind f_arm(afp, result, _),
+ fold_pat: bind f_pat(afp, result, _),
+ fold_decl: bind f_decl(afp, result, _),
+ fold_expr: bind f_expr(afp, result, _),
+ fold_ty: bind f_ty(afp, result, _),
+ fold_constr: bind f_constr(afp, result, _),
+ fold_fn: bind f_fn(afp, result, _),
+ fold_mod: bind f_mod(afp, result, _),
+ fold_native_mod: bind f_native_mod(afp, result, _),
+ fold_variant: bind f_variant(afp, result, _),
+ fold_ident: bind f_ident(afp, result, _),
+ fold_path: bind f_path(afp, result, _),
+ fold_local: bind f_local(afp, result, _),
+ map_exprs: afp.map_exprs};
ret result;
}
diff --git a/src/comp/syntax/parse/eval.rs b/src/comp/syntax/parse/eval.rs
index 6f551b9..08a6040 100644
--- a/src/comp/syntax/parse/eval.rs
+++ b/src/comp/syntax/parse/eval.rs
@@ -16,82 +16,79 @@
tag eval_mode { mode_depend; mode_parse; }
type ctx =
- @rec(parser p,
- eval_mode mode,
- mutable str[] deps,
- parser::parse_sess sess,
- mutable uint chpos,
- mutable uint byte_pos,
- ast::crate_cfg cfg);
+ @{p: parser,
+ mode: eval_mode,
+ mutable deps: str[],
+ sess: parser::parse_sess,
+ mutable chpos: uint,
+ mutable byte_pos: uint,
+ cfg: ast::crate_cfg};
-fn eval_crate_directives(ctx cx, &(@ast::crate_directive)[] cdirs,
- str prefix, &mutable (@ast::view_item)[] view_items,
- &mutable (@ast::item)[] items) {
- for (@ast::crate_directive sub_cdir in cdirs) {
+fn eval_crate_directives(cx: ctx, cdirs: &(@ast::crate_directive)[],
+ prefix: str,
+ view_items: &mutable (@ast::view_item)[],
+ items: &mutable (@ast::item)[]) {
+ for sub_cdir: @ast::crate_directive in cdirs {
eval_crate_directive(cx, sub_cdir, prefix, view_items, items);
}
}
-fn eval_crate_directives_to_mod(ctx cx, &(@ast::crate_directive)[] cdirs,
- str prefix) -> ast::_mod {
- let (@ast::view_item)[] view_items = ~[];
- let (@ast::item)[] items = ~[];
+fn eval_crate_directives_to_mod(cx: ctx, cdirs: &(@ast::crate_directive)[],
+ prefix: str) -> ast::_mod {
+ let view_items: (@ast::view_item)[] = ~[];
+ let items: (@ast::item)[] = ~[];
eval_crate_directives(cx, cdirs, prefix, view_items, items);
- ret rec(view_items=view_items, items=items);
+ ret {view_items: view_items, items: items};
}
-fn eval_crate_directive(ctx cx, @ast::crate_directive cdir, str prefix,
- &mutable (@ast::view_item)[] view_items,
- &mutable (@ast::item)[] items) {
- alt (cdir.node) {
- case (ast::cdir_src_mod(?id, ?file_opt, ?attrs)) {
- auto file_path = id + ".rs";
- alt (file_opt) {
- case (some(?f)) { file_path = f; }
- case (none) { }
- }
- auto full_path = if (std::fs::path_is_absolute(file_path)) {
+fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: str,
+ view_items: &mutable (@ast::view_item)[],
+ items: &mutable (@ast::item)[]) {
+ alt cdir.node {
+ ast::cdir_src_mod(id, file_opt, attrs) {
+ let file_path = id + ".rs";
+ alt file_opt { some(f) { file_path = f; } none. { } }
+ let full_path =
+ if std::fs::path_is_absolute(file_path) {
file_path
- } else {
- prefix + std::fs::path_sep() + file_path
- };
- if (cx.mode == mode_depend) { cx.deps += ~[full_path]; ret; }
- auto p0 =
- new_parser_from_file(cx.sess, cx.cfg, full_path, cx.chpos,
- cx.byte_pos);
- auto inner_attrs = parse_inner_attrs_and_next(p0);
- auto mod_attrs = attrs + inner_attrs.inner;
- auto first_item_outer_attrs = inner_attrs.next;
- auto m0 = parse_mod_items(p0, token::EOF, first_item_outer_attrs);
+ } else { prefix + std::fs::path_sep() + file_path };
+ if cx.mode == mode_depend { cx.deps += ~[full_path]; ret; }
+ let p0 =
+ new_parser_from_file(cx.sess, cx.cfg, full_path, cx.chpos,
+ cx.byte_pos);
+ let inner_attrs = parse_inner_attrs_and_next(p0);
+ let mod_attrs = attrs + inner_attrs.inner;
+ let first_item_outer_attrs = inner_attrs.next;
+ let m0 = parse_mod_items(p0, token::EOF, first_item_outer_attrs);
- auto i = syntax::parse::parser::mk_item
- (p0, cdir.span.lo, cdir.span.hi, id, ast::item_mod(m0),
- mod_attrs);
- // Thread defids, chpos and byte_pos through the parsers
- cx.chpos = p0.get_chpos();
- cx.byte_pos = p0.get_byte_pos();
- items += ~[i];
- }
- case (ast::cdir_dir_mod(?id, ?dir_opt, ?cdirs, ?attrs)) {
- auto path = id;
- alt (dir_opt) { case (some(?d)) { path = d; } case (none) { } }
- auto full_path = if (std::fs::path_is_absolute(path)) {
+ let i =
+ syntax::parse::parser::mk_item(p0, cdir.span.lo, cdir.span.hi, id,
+ ast::item_mod(m0), mod_attrs);
+ // Thread defids, chpos and byte_pos through the parsers
+ cx.chpos = p0.get_chpos();
+ cx.byte_pos = p0.get_byte_pos();
+ items += ~[i];
+ }
+ ast::cdir_dir_mod(id, dir_opt, cdirs, attrs) {
+ let path = id;
+ alt dir_opt { some(d) { path = d; } none. { } }
+ let full_path =
+ if std::fs::path_is_absolute(path) {
path
- } else {
- prefix + std::fs::path_sep() + path
- };
- auto m0 = eval_crate_directives_to_mod(cx, cdirs, full_path);
- auto i = @rec(ident=id,
- attrs=attrs,
- id=cx.sess.next_id,
- node=ast::item_mod(m0),
- span=cdir.span);
- cx.sess.next_id += 1;
- items += ~[i];
- }
- case (ast::cdir_view_item(?vi)) { view_items += ~[vi]; }
- case (ast::cdir_syntax(?pth)) { }
- case (ast::cdir_auth(?pth, ?eff)) { }
+ } else { prefix + std::fs::path_sep() + path };
+ let m0 = eval_crate_directives_to_mod(cx, cdirs, full_path);
+ let i =
+ @{ident: id,
+ attrs: attrs,
+ id: cx.sess.next_id,
+ node: ast::item_mod(m0),
+ span: cdir.span};
+ cx.sess.next_id += 1;
+ items += ~[i];
+ }
+ ast::cdir_view_item(vi) { view_items += ~[vi]; }
+ ast::cdir_syntax(pth) { }
+ ast::cdir_auth(pth, eff) { }
}
}
//
diff --git a/src/comp/syntax/parse/lexer.rs b/src/comp/syntax/parse/lexer.rs
index d011fdc..8163f8d 100644
--- a/src/comp/syntax/parse/lexer.rs
+++ b/src/comp/syntax/parse/lexer.rs
@@ -28,20 +28,20 @@
fn err(str) ;
};
-fn new_reader(&codemap::codemap cm, str src, codemap::filemap filemap,
- @interner::interner[str] itr) -> reader {
- obj reader(codemap::codemap cm,
- str src,
- uint len,
- mutable uint col,
- mutable uint pos,
- mutable char ch,
- mutable uint chpos,
- mutable str[] strs,
- codemap::filemap fm,
- @interner::interner[str] itr) {
+fn new_reader(cm: &codemap::codemap, src: str, filemap: codemap::filemap,
+ itr: @interner::interner[str]) -> reader {
+ obj reader(cm: codemap::codemap,
+ src: str,
+ len: uint,
+ mutable col: uint,
+ mutable pos: uint,
+ mutable ch: char,
+ mutable chpos: uint,
+ mutable strs: str[],
+ fm: codemap::filemap,
+ itr: @interner::interner[str]) {
fn is_eof() -> bool { ret ch == -1 as char; }
- fn get_str_from(uint start) -> str {
+ fn get_str_from(start: uint) -> str {
// I'm pretty skeptical about this subtraction. What if there's a
// multi-byte character before the mark?
ret str::slice(src, start - 1u, pos - 1u);
@@ -50,26 +50,26 @@
fn get_byte_pos() -> uint { ret pos; }
fn curr() -> char { ret ch; }
fn next() -> char {
- if (pos < len) {
+ if pos < len {
ret str::char_at(src, pos);
} else { ret -1 as char; }
}
fn init() {
- if (pos < len) {
- auto next = str::char_range_at(src, pos);
+ if pos < len {
+ let next = str::char_range_at(src, pos);
pos = next.next;
ch = next.ch;
}
}
fn bump() {
- if (pos < len) {
+ if pos < len {
col += 1u;
chpos += 1u;
- if (ch == '\n') {
+ if ch == '\n' {
codemap::next_line(fm, chpos, pos + fm.start_pos.byte);
col = 0u;
}
- auto next = str::char_range_at(src, pos);
+ let next = str::char_range_at(src, pos);
pos = next.next;
ch = next.ch;
} else { ch = -1 as char; }
@@ -77,86 +77,82 @@
fn get_interner() -> @interner::interner[str] { ret itr; }
fn get_col() -> uint { ret col; }
fn get_filemap() -> codemap::filemap { ret fm; }
- fn err(str m) {
- codemap::emit_error(some(rec(lo=chpos, hi=chpos)), m, cm);
+ fn err(m: str) {
+ codemap::emit_error(some({lo: chpos, hi: chpos}), m, cm);
}
}
- let str[] strs = ~[];
- auto rd =
+ let strs: str[] = ~[];
+ let rd =
reader(cm, src, str::byte_len(src), 0u, 0u, -1 as char,
filemap.start_pos.ch, strs, filemap, itr);
rd.init();
ret rd;
}
-fn dec_digit_val(char c) -> int { ret (c as int) - ('0' as int); }
+fn dec_digit_val(c: char) -> int { ret (c as int) - ('0' as int); }
-fn hex_digit_val(char c) -> int {
- if (in_range(c, '0', '9')) { ret (c as int) - ('0' as int); }
- if (in_range(c, 'a', 'f')) { ret (c as int) - ('a' as int) + 10; }
- if (in_range(c, 'A', 'F')) { ret (c as int) - ('A' as int) + 10; }
+fn hex_digit_val(c: char) -> int {
+ if in_range(c, '0', '9') { ret (c as int) - ('0' as int); }
+ if in_range(c, 'a', 'f') { ret (c as int) - ('a' as int) + 10; }
+ if in_range(c, 'A', 'F') { ret (c as int) - ('A' as int) + 10; }
fail;
}
-fn bin_digit_value(char c) -> int { if (c == '0') { ret 0; } ret 1; }
+fn bin_digit_value(c: char) -> int { if c == '0' { ret 0; } ret 1; }
-fn is_whitespace(char c) -> bool {
+fn is_whitespace(c: char) -> bool {
ret c == ' ' || c == '\t' || c == '\r' || c == '\n';
}
-fn may_begin_ident(char c) -> bool { ret is_alpha(c) || c == '_'; }
+fn may_begin_ident(c: char) -> bool { ret is_alpha(c) || c == '_'; }
-fn in_range(char c, char lo, char hi) -> bool { ret lo <= c && c <= hi; }
+fn in_range(c: char, lo: char, hi: char) -> bool { ret lo <= c && c <= hi; }
-fn is_alpha(char c) -> bool {
+fn is_alpha(c: char) -> bool {
ret in_range(c, 'a', 'z') || in_range(c, 'A', 'Z');
}
-fn is_dec_digit(char c) -> bool { ret in_range(c, '0', '9'); }
+fn is_dec_digit(c: char) -> bool { ret in_range(c, '0', '9'); }
-fn is_alnum(char c) -> bool { ret is_alpha(c) || is_dec_digit(c); }
+fn is_alnum(c: char) -> bool { ret is_alpha(c) || is_dec_digit(c); }
-fn is_hex_digit(char c) -> bool {
+fn is_hex_digit(c: char) -> bool {
ret in_range(c, '0', '9') || in_range(c, 'a', 'f') ||
in_range(c, 'A', 'F');
}
-fn is_bin_digit(char c) -> bool { ret c == '0' || c == '1'; }
+fn is_bin_digit(c: char) -> bool { ret c == '0' || c == '1'; }
-fn consume_whitespace_and_comments(&reader rdr) {
- while (is_whitespace(rdr.curr())) { rdr.bump(); }
+fn consume_whitespace_and_comments(rdr: &reader) {
+ while is_whitespace(rdr.curr()) { rdr.bump(); }
be consume_any_line_comment(rdr);
}
-fn consume_any_line_comment(&reader rdr) {
- if (rdr.curr() == '/') {
- alt (rdr.next()) {
- case ('/') {
- while (rdr.curr() != '\n' && !rdr.is_eof()) { rdr.bump(); }
- // Restart whitespace munch.
+fn consume_any_line_comment(rdr: &reader) {
+ if rdr.curr() == '/' {
+ alt rdr.next() {
+ '/' {
+ while rdr.curr() != '\n' && !rdr.is_eof() { rdr.bump(); }
+ // Restart whitespace munch.
- be consume_whitespace_and_comments(rdr);
- }
- case ('*') {
- rdr.bump();
- rdr.bump();
- be consume_block_comment(rdr);
- }
- case (_) { ret; }
+ be consume_whitespace_and_comments(rdr);
+ }
+ '*' { rdr.bump(); rdr.bump(); be consume_block_comment(rdr); }
+ _ { ret; }
}
}
}
-fn consume_block_comment(&reader rdr) {
- let int level = 1;
- while (level > 0) {
- if (rdr.is_eof()) { rdr.err("unterminated block comment"); fail; }
- if (rdr.curr() == '/' && rdr.next() == '*') {
+fn consume_block_comment(rdr: &reader) {
+ let level: int = 1;
+ while level > 0 {
+ if rdr.is_eof() { rdr.err("unterminated block comment"); fail; }
+ if rdr.curr() == '/' && rdr.next() == '*' {
rdr.bump();
rdr.bump();
level += 1;
} else {
- if (rdr.curr() == '*' && rdr.next() == '/') {
+ if rdr.curr() == '*' && rdr.next() == '/' {
rdr.bump();
rdr.bump();
level -= 1;
@@ -168,55 +164,55 @@
be consume_whitespace_and_comments(rdr);
}
-fn digits_to_string(str s) -> int {
- let int accum_int = 0;
- for (u8 c in s) {
+fn digits_to_string(s: str) -> int {
+ let accum_int: int = 0;
+ for c: u8 in s {
accum_int *= 10;
accum_int += dec_digit_val(c as char);
}
ret accum_int;
}
-fn scan_exponent(&reader rdr) -> option::t[str] {
- auto c = rdr.curr();
- auto rslt = "";
- if (c == 'e' || c == 'E') {
+fn scan_exponent(rdr: &reader) -> option::t[str] {
+ let c = rdr.curr();
+ let rslt = "";
+ if c == 'e' || c == 'E' {
rslt += str::from_bytes([c as u8]);
rdr.bump();
c = rdr.curr();
- if (c == '-' || c == '+') {
+ if c == '-' || c == '+' {
rslt += str::from_bytes([c as u8]);
rdr.bump();
}
- auto exponent = scan_dec_digits(rdr);
- if (str::byte_len(exponent) > 0u) {
+ let exponent = scan_dec_digits(rdr);
+ if str::byte_len(exponent) > 0u {
ret some(rslt + exponent);
} else { rdr.err("scan_exponent: bad fp literal"); fail; }
} else { ret none[str]; }
}
-fn scan_dec_digits(&reader rdr) -> str {
- auto c = rdr.curr();
- let str rslt = "";
- while (is_dec_digit(c) || c == '_') {
- if (c != '_') { rslt += str::from_bytes([c as u8]); }
+fn scan_dec_digits(rdr: &reader) -> str {
+ let c = rdr.curr();
+ let rslt: str = "";
+ while is_dec_digit(c) || c == '_' {
+ if c != '_' { rslt += str::from_bytes([c as u8]); }
rdr.bump();
c = rdr.curr();
}
ret rslt;
}
-fn scan_number(char c, &reader rdr) -> token::token {
- auto accum_int = 0;
- let str dec_str = "";
- let bool is_dec_integer = false;
- auto n = rdr.next();
- if (c == '0' && n == 'x') {
+fn scan_number(c: char, rdr: &reader) -> token::token {
+ let accum_int = 0;
+ let dec_str: str = "";
+ let is_dec_integer: bool = false;
+ let n = rdr.next();
+ if c == '0' && n == 'x' {
rdr.bump();
rdr.bump();
c = rdr.curr();
- while (is_hex_digit(c) || c == '_') {
- if (c != '_') { accum_int *= 16; accum_int += hex_digit_val(c); }
+ while is_hex_digit(c) || c == '_' {
+ if c != '_' { accum_int *= 16; accum_int += hex_digit_val(c); }
rdr.bump();
c = rdr.curr();
}
@@ -224,48 +220,48 @@
rdr.bump();
rdr.bump();
c = rdr.curr();
- while (is_bin_digit(c) || c == '_') {
- if (c != '_') { accum_int *= 2; accum_int += bin_digit_value(c); }
+ while is_bin_digit(c) || c == '_' {
+ if c != '_' { accum_int *= 2; accum_int += bin_digit_value(c); }
rdr.bump();
c = rdr.curr();
}
} else { dec_str = scan_dec_digits(rdr); is_dec_integer = true; }
- if (is_dec_integer) { accum_int = digits_to_string(dec_str); }
+ if is_dec_integer { accum_int = digits_to_string(dec_str); }
c = rdr.curr();
n = rdr.next();
- if (c == 'u' || c == 'i') {
- let bool signed = c == 'i';
+ if c == 'u' || c == 'i' {
+ let signed: bool = c == 'i';
rdr.bump();
c = rdr.curr();
- if (c == '8') {
+ if c == '8' {
rdr.bump();
- if (signed) {
+ if signed {
ret token::LIT_MACH_INT(ast::ty_i8, accum_int);
} else { ret token::LIT_MACH_INT(ast::ty_u8, accum_int); }
}
n = rdr.next();
- if (c == '1' && n == '6') {
+ if c == '1' && n == '6' {
rdr.bump();
rdr.bump();
- if (signed) {
+ if signed {
ret token::LIT_MACH_INT(ast::ty_i16, accum_int);
} else { ret token::LIT_MACH_INT(ast::ty_u16, accum_int); }
}
- if (c == '3' && n == '2') {
+ if c == '3' && n == '2' {
rdr.bump();
rdr.bump();
- if (signed) {
+ if signed {
ret token::LIT_MACH_INT(ast::ty_i32, accum_int);
} else { ret token::LIT_MACH_INT(ast::ty_u32, accum_int); }
}
- if (c == '6' && n == '4') {
+ if c == '6' && n == '4' {
rdr.bump();
rdr.bump();
- if (signed) {
+ if signed {
ret token::LIT_MACH_INT(ast::ty_i64, accum_int);
} else { ret token::LIT_MACH_INT(ast::ty_u64, accum_int); }
}
- if (signed) {
+ if signed {
ret token::LIT_INT(accum_int);
} else {
// FIXME: should cast in the target bit-width.
@@ -274,24 +270,21 @@
}
}
c = rdr.curr();
- if (c == '.') {
+ if c == '.' {
// Parse a floating-point number.
rdr.bump();
- auto dec_part = scan_dec_digits(rdr);
- auto float_str = dec_str + "." + dec_part;
+ let dec_part = scan_dec_digits(rdr);
+ let float_str = dec_str + "." + dec_part;
c = rdr.curr();
- auto exponent_str = scan_exponent(rdr);
- alt (exponent_str) {
- case (some(?s)) { float_str += s; }
- case (none) { }
- }
+ let exponent_str = scan_exponent(rdr);
+ alt exponent_str { some(s) { float_str += s; } none. { } }
c = rdr.curr();
- if (c == 'f') {
+ if c == 'f' {
rdr.bump();
c = rdr.curr();
n = rdr.next();
- if (c == '3' && n == '2') {
+ if c == '3' && n == '2' {
rdr.bump();
rdr.bump();
ret token::LIT_MACH_FLOAT(ast::ty_f32,
@@ -312,22 +305,22 @@
float_str));
}
}
- auto maybe_exponent = scan_exponent(rdr);
- alt (maybe_exponent) {
- case (some(?s)) {
- ret token::LIT_FLOAT(interner::intern[str](*rdr.get_interner(),
- dec_str + s));
- }
- case (none) { ret token::LIT_INT(accum_int); }
+ let maybe_exponent = scan_exponent(rdr);
+ alt maybe_exponent {
+ some(s) {
+ ret token::LIT_FLOAT(interner::intern[str](*rdr.get_interner(),
+ dec_str + s));
+ }
+ none. { ret token::LIT_INT(accum_int); }
}
}
-fn scan_numeric_escape(&reader rdr, uint n_hex_digits) -> char {
- auto accum_int = 0;
- while (n_hex_digits != 0u) {
- auto n = rdr.curr();
+fn scan_numeric_escape(rdr: &reader, n_hex_digits: uint) -> char {
+ let accum_int = 0;
+ while n_hex_digits != 0u {
+ let n = rdr.curr();
rdr.bump();
- if (!is_hex_digit(n)) {
+ if !is_hex_digit(n) {
rdr.err(#fmt("illegal numeric character escape: %d", n as int));
fail;
}
@@ -338,235 +331,215 @@
ret accum_int as char;
}
-fn next_token(&reader rdr) -> rec(token::token tok, uint chpos, uint bpos) {
+fn next_token(rdr: &reader) -> {tok: token::token, chpos: uint, bpos: uint} {
consume_whitespace_and_comments(rdr);
- auto start_chpos = rdr.get_chpos();
- auto start_bpos = rdr.get_byte_pos();
- auto tok = if rdr.is_eof() { token::EOF }
- else { next_token_inner(rdr) };
- ret rec(tok=tok, chpos=start_chpos, bpos=start_bpos);
+ let start_chpos = rdr.get_chpos();
+ let start_bpos = rdr.get_byte_pos();
+ let tok = if rdr.is_eof() { token::EOF } else { next_token_inner(rdr) };
+ ret {tok: tok, chpos: start_chpos, bpos: start_bpos};
}
-fn next_token_inner(&reader rdr) -> token::token {
- auto accum_str = "";
- auto c = rdr.curr();
- if (is_alpha(c) || c == '_') {
- while (is_alnum(c) || c == '_') {
+fn next_token_inner(rdr: &reader) -> token::token {
+ let accum_str = "";
+ let c = rdr.curr();
+ if is_alpha(c) || c == '_' {
+ while is_alnum(c) || c == '_' {
str::push_char(accum_str, c);
rdr.bump();
c = rdr.curr();
}
- if (str::eq(accum_str, "_")) { ret token::UNDERSCORE; }
- auto is_mod_name = c == ':' && rdr.next() == ':';
+ if str::eq(accum_str, "_") { ret token::UNDERSCORE; }
+ let is_mod_name = c == ':' && rdr.next() == ':';
ret token::IDENT(interner::intern[str](*rdr.get_interner(),
accum_str), is_mod_name);
}
- if (is_dec_digit(c)) { ret scan_number(c, rdr); }
- fn binop(&reader rdr, token::binop op) -> token::token {
+ if is_dec_digit(c) { ret scan_number(c, rdr); }
+ fn binop(rdr: &reader, op: token::binop) -> token::token {
rdr.bump();
- if (rdr.curr() == '=') {
+ if rdr.curr() == '=' {
rdr.bump();
ret token::BINOPEQ(op);
} else { ret token::BINOP(op); }
}
- alt (c) {
- // One-byte tokens.
- case ('?') { rdr.bump(); ret token::QUES; }
- case (';') { rdr.bump(); ret token::SEMI; }
- case (',') { rdr.bump(); ret token::COMMA; }
- case ('.') {
- rdr.bump();
- if (rdr.curr() == '.' && rdr.next() == '.') {
- rdr.bump();
- rdr.bump();
- ret token::ELLIPSIS;
- }
- ret token::DOT;
- }
- case ('(') { rdr.bump(); ret token::LPAREN; }
- case (')') { rdr.bump(); ret token::RPAREN; }
- case ('{') { rdr.bump(); ret token::LBRACE; }
- case ('}') { rdr.bump(); ret token::RBRACE; }
- case ('[') { rdr.bump(); ret token::LBRACKET; }
- case (']') { rdr.bump(); ret token::RBRACKET; }
- case ('@') { rdr.bump(); ret token::AT; }
- case ('#') {
- rdr.bump();
- if (rdr.curr() == '<') {
- rdr.bump();
- ret token::POUND_LT;
- }
- if (rdr.curr() == '{') {
- rdr.bump();
- ret token::POUND_LBRACE;
- }
- ret token::POUND;
- }
- case ('~') { rdr.bump(); ret token::TILDE; }
- case (':') {
- rdr.bump();
- if (rdr.curr() == ':') {
- rdr.bump();
- ret token::MOD_SEP;
- } else { ret token::COLON; }
- }
- // Multi-byte tokens.
- case ('=') {
- rdr.bump();
- if (rdr.curr() == '=') {
- rdr.bump();
- ret token::EQEQ;
- } else { ret token::EQ; }
- }
- case ('!') {
- rdr.bump();
- if (rdr.curr() == '=') {
- rdr.bump();
- ret token::NE;
- } else { ret token::NOT; }
- }
- case ('<') {
- rdr.bump();
- alt (rdr.curr()) {
- case ('=') { rdr.bump(); ret token::LE; }
- case ('<') { ret binop(rdr, token::LSL); }
- case ('|') { rdr.bump(); ret token::SEND; }
- case ('-') {
- rdr.bump();
- alt (rdr.curr()) {
- case ('>') { rdr.bump(); ret token::DARROW; }
- case (_) { ret token::LARROW; }
- }
- }
- case (_) { ret token::LT; }
- }
- }
- case ('>') {
- rdr.bump();
- alt (rdr.curr()) {
- case ('=') { rdr.bump(); ret token::GE; }
- case ('>') {
- if (rdr.next() == '>') {
- rdr.bump();
- ret binop(rdr, token::ASR);
- } else { ret binop(rdr, token::LSR); }
- }
- case (_) { ret token::GT; }
- }
- }
- case ('\'') {
- rdr.bump();
- auto c2 = rdr.curr();
- rdr.bump();
- if (c2 == '\\') {
- auto escaped = rdr.curr();
- rdr.bump();
- alt (escaped) {
- case ('n') { c2 = '\n'; }
- case ('r') { c2 = '\r'; }
- case ('t') { c2 = '\t'; }
- case ('\\') { c2 = '\\'; }
- case ('\'') { c2 = '\''; }
- case ('x') { c2 = scan_numeric_escape(rdr, 2u); }
- case ('u') { c2 = scan_numeric_escape(rdr, 4u); }
- case ('U') { c2 = scan_numeric_escape(rdr, 8u); }
- case (?c2) {
- rdr.err(#fmt("unknown character escape: %d",
- c2 as int));
- fail;
- }
- }
- }
- if (rdr.curr() != '\'') {
- rdr.err("unterminated character constant");
- fail;
- }
- rdr.bump(); // advance curr past token
+ alt c {
- ret token::LIT_CHAR(c2);
- }
- case ('"') {
+ // One-byte tokens.
+ '?' {
+ rdr.bump();
+ ret token::QUES;
+ }
+ ';' { rdr.bump(); ret token::SEMI; }
+ ',' { rdr.bump(); ret token::COMMA; }
+ '.' {
+ rdr.bump();
+ if rdr.curr() == '.' && rdr.next() == '.' {
rdr.bump();
- while (rdr.curr() != '"') {
- auto ch = rdr.curr();
- rdr.bump();
- alt (ch) {
- case ('\\') {
- auto escaped = rdr.curr();
- rdr.bump();
- alt (escaped) {
- case ('n') {
- str::push_byte(accum_str, '\n' as u8);
- }
- case ('r') {
- str::push_byte(accum_str, '\r' as u8);
- }
- case ('t') {
- str::push_byte(accum_str, '\t' as u8);
- }
- case ('\\') {
- str::push_byte(accum_str, '\\' as u8);
- }
- case ('"') {
- str::push_byte(accum_str, '"' as u8);
- }
- case ('\n') { consume_whitespace(rdr); }
- case ('x') {
- str::push_char(accum_str,
- scan_numeric_escape(rdr, 2u));
- }
- case ('u') {
- str::push_char(accum_str,
- scan_numeric_escape(rdr, 4u));
- }
- case ('U') {
- str::push_char(accum_str,
- scan_numeric_escape(rdr, 8u));
- }
- case (?c2) {
- rdr.err(#fmt("unknown string escape: %d",
- c2 as int));
- fail;
- }
- }
- }
- case (_) { str::push_char(accum_str, ch); }
- }
+ rdr.bump();
+ ret token::ELLIPSIS;
+ }
+ ret token::DOT;
+ }
+ '(' { rdr.bump(); ret token::LPAREN; }
+ ')' { rdr.bump(); ret token::RPAREN; }
+ '{' { rdr.bump(); ret token::LBRACE; }
+ '}' { rdr.bump(); ret token::RBRACE; }
+ '[' { rdr.bump(); ret token::LBRACKET; }
+ ']' { rdr.bump(); ret token::RBRACKET; }
+ '@' { rdr.bump(); ret token::AT; }
+ '#' {
+ rdr.bump();
+ if rdr.curr() == '<' { rdr.bump(); ret token::POUND_LT; }
+ if rdr.curr() == '{' { rdr.bump(); ret token::POUND_LBRACE; }
+ ret token::POUND;
+ }
+ '~' { rdr.bump(); ret token::TILDE; }
+ ':' {
+ rdr.bump();
+ if rdr.curr() == ':' {
+ rdr.bump();
+ ret token::MOD_SEP;
+ } else { ret token::COLON; }
+ }
+
+ // Multi-byte tokens.
+ '=' {
+ rdr.bump();
+ if rdr.curr() == '=' {
+ rdr.bump();
+ ret token::EQEQ;
+ } else { ret token::EQ; }
+ }
+ '!' {
+ rdr.bump();
+ if rdr.curr() == '=' {
+ rdr.bump();
+ ret token::NE;
+ } else { ret token::NOT; }
+ }
+ '<' {
+ rdr.bump();
+ alt rdr.curr() {
+ '=' { rdr.bump(); ret token::LE; }
+ '<' { ret binop(rdr, token::LSL); }
+ '|' { rdr.bump(); ret token::SEND; }
+ '-' {
+ rdr.bump();
+ alt rdr.curr() {
+ '>' { rdr.bump(); ret token::DARROW; }
+ _ { ret token::LARROW; }
}
+ }
+ _ { ret token::LT; }
+ }
+ }
+ '>' {
+ rdr.bump();
+ alt rdr.curr() {
+ '=' { rdr.bump(); ret token::GE; }
+ '>' {
+ if rdr.next() == '>' {
+ rdr.bump();
+ ret binop(rdr, token::ASR);
+ } else { ret binop(rdr, token::LSR); }
+ }
+ _ { ret token::GT; }
+ }
+ }
+ '\'' {
+ rdr.bump();
+ let c2 = rdr.curr();
+ rdr.bump();
+ if c2 == '\\' {
+ let escaped = rdr.curr();
rdr.bump();
- ret token::LIT_STR(interner::intern[str](*rdr.get_interner(),
- accum_str));
- }
- case ('-') {
- if (rdr.next() == '>') {
- rdr.bump();
- rdr.bump();
- ret token::RARROW;
- } else { ret binop(rdr, token::MINUS); }
- }
- case ('&') {
- if (rdr.next() == '&') {
- rdr.bump();
- rdr.bump();
- ret token::ANDAND;
- } else { ret binop(rdr, token::AND); }
- }
- case ('|') {
- alt (rdr.next()) {
- case ('|') { rdr.bump(); rdr.bump(); ret token::OROR; }
- case ('>') { rdr.bump(); rdr.bump(); ret token::RECV; }
- case (_) { ret binop(rdr, token::OR); }
+ alt escaped {
+ 'n' { c2 = '\n'; }
+ 'r' { c2 = '\r'; }
+ 't' { c2 = '\t'; }
+ '\\' { c2 = '\\'; }
+ '\'' { c2 = '\''; }
+ 'x' { c2 = scan_numeric_escape(rdr, 2u); }
+ 'u' { c2 = scan_numeric_escape(rdr, 4u); }
+ 'U' { c2 = scan_numeric_escape(rdr, 8u); }
+ c2 {
+ rdr.err(#fmt("unknown character escape: %d", c2 as int));
+ fail;
+ }
}
}
- case ('+') { ret binop(rdr, token::PLUS); }
- case ('*') { ret binop(rdr, token::STAR); }
- case ('/') { ret binop(rdr, token::SLASH); }
- case ('^') { ret binop(rdr, token::CARET); }
- case ('%') { ret binop(rdr, token::PERCENT); }
- case (?c) {
- rdr.err(#fmt("unkown start of token: %d", c as int));
+ if rdr.curr() != '\'' {
+ rdr.err("unterminated character constant");
fail;
}
+ rdr.bump(); // advance curr past token
+
+ ret token::LIT_CHAR(c2);
+ }
+ '"' {
+ rdr.bump();
+ while rdr.curr() != '"' {
+ let ch = rdr.curr();
+ rdr.bump();
+ alt ch {
+ '\\' {
+ let escaped = rdr.curr();
+ rdr.bump();
+ alt escaped {
+ 'n' { str::push_byte(accum_str, '\n' as u8); }
+ 'r' { str::push_byte(accum_str, '\r' as u8); }
+ 't' { str::push_byte(accum_str, '\t' as u8); }
+ '\\' { str::push_byte(accum_str, '\\' as u8); }
+ '"' { str::push_byte(accum_str, '"' as u8); }
+ '\n' { consume_whitespace(rdr); }
+ 'x' {
+ str::push_char(accum_str, scan_numeric_escape(rdr, 2u));
+ }
+ 'u' {
+ str::push_char(accum_str, scan_numeric_escape(rdr, 4u));
+ }
+ 'U' {
+ str::push_char(accum_str, scan_numeric_escape(rdr, 8u));
+ }
+ c2 {
+ rdr.err(#fmt("unknown string escape: %d", c2 as int));
+ fail;
+ }
+ }
+ }
+ _ { str::push_char(accum_str, ch); }
+ }
+ }
+ rdr.bump();
+ ret token::LIT_STR(interner::intern[str](*rdr.get_interner(),
+ accum_str));
+ }
+ '-' {
+ if rdr.next() == '>' {
+ rdr.bump();
+ rdr.bump();
+ ret token::RARROW;
+ } else { ret binop(rdr, token::MINUS); }
+ }
+ '&' {
+ if rdr.next() == '&' {
+ rdr.bump();
+ rdr.bump();
+ ret token::ANDAND;
+ } else { ret binop(rdr, token::AND); }
+ }
+ '|' {
+ alt rdr.next() {
+ '|' { rdr.bump(); rdr.bump(); ret token::OROR; }
+ '>' { rdr.bump(); rdr.bump(); ret token::RECV; }
+ _ { ret binop(rdr, token::OR); }
+ }
+ }
+ '+' { ret binop(rdr, token::PLUS); }
+ '*' { ret binop(rdr, token::STAR); }
+ '/' { ret binop(rdr, token::SLASH); }
+ '^' { ret binop(rdr, token::CARET); }
+ '%' { ret binop(rdr, token::PERCENT); }
+ c { rdr.err(#fmt("unkown start of token: %d", c as int)); fail; }
}
fail;
}
@@ -574,55 +547,57 @@
tag cmnt_style {
isolated; // No code on either side of each line of the comment
+
+
trailing; // Code exists to the left of the comment
+
+
mixed; // Code before /* foo */ and after the comment
+
+
blank_line; // Just a manual blank linke "\n\n", for layout
}
-type cmnt = rec(cmnt_style style, str[] lines, uint pos);
+type cmnt = {style: cmnt_style, lines: str[], pos: uint};
-fn read_to_eol(&reader rdr) -> str {
- auto val = "";
- while (rdr.curr() != '\n' && !rdr.is_eof()) {
+fn read_to_eol(rdr: &reader) -> str {
+ let val = "";
+ while rdr.curr() != '\n' && !rdr.is_eof() {
str::push_char(val, rdr.curr());
rdr.bump();
}
- if rdr.curr() == '\n' {
- rdr.bump();
- }
+ if rdr.curr() == '\n' { rdr.bump(); }
ret val;
}
-fn read_one_line_comment(&reader rdr) -> str {
- auto val = read_to_eol(rdr);
+fn read_one_line_comment(rdr: &reader) -> str {
+ let val = read_to_eol(rdr);
assert (val.(0) == '/' as u8 && val.(1) == '/' as u8);
ret val;
}
-fn consume_whitespace(&reader rdr) {
- while (is_whitespace(rdr.curr()) && !rdr.is_eof()) { rdr.bump(); }
+fn consume_whitespace(rdr: &reader) {
+ while is_whitespace(rdr.curr()) && !rdr.is_eof() { rdr.bump(); }
}
-fn consume_non_eol_whitespace(&reader rdr) {
- while (is_whitespace(rdr.curr()) && rdr.curr() != '\n' && !rdr.is_eof()) {
+fn consume_non_eol_whitespace(rdr: &reader) {
+ while is_whitespace(rdr.curr()) && rdr.curr() != '\n' && !rdr.is_eof() {
rdr.bump();
}
}
-fn push_blank_line_comment(&reader rdr,
- &mutable cmnt[] comments) {
+fn push_blank_line_comment(rdr: &reader, comments: &mutable cmnt[]) {
log ">>> blank-line comment";
- let str[] v = ~[];
- comments += ~[rec(style=blank_line, lines=v,
- pos=rdr.get_chpos())];
+ let v: str[] = ~[];
+ comments += ~[{style: blank_line, lines: v, pos: rdr.get_chpos()}];
}
-fn consume_whitespace_counting_blank_lines(&reader rdr,
- &mutable cmnt[] comments) {
- while (is_whitespace(rdr.curr()) && !rdr.is_eof()) {
+fn consume_whitespace_counting_blank_lines(rdr: &reader,
+ comments: &mutable cmnt[]) {
+ while is_whitespace(rdr.curr()) && !rdr.is_eof() {
if rdr.get_col() == 0u && rdr.curr() == '\n' {
push_blank_line_comment(rdr, comments);
}
@@ -630,36 +605,36 @@
}
}
-fn read_line_comments(&reader rdr, bool code_to_the_left) -> cmnt {
+fn read_line_comments(rdr: &reader, code_to_the_left: bool) -> cmnt {
log ">>> line comments";
- auto p = rdr.get_chpos();
- let str[] lines = ~[];
- while (rdr.curr() == '/' && rdr.next() == '/') {
- auto line = read_one_line_comment(rdr);
+ let p = rdr.get_chpos();
+ let lines: str[] = ~[];
+ while rdr.curr() == '/' && rdr.next() == '/' {
+ let line = read_one_line_comment(rdr);
log line;
lines += ~[line];
consume_non_eol_whitespace(rdr);
}
log "<<< line comments";
- ret rec(style=if (code_to_the_left) { trailing } else { isolated },
- lines=lines,
- pos=p);
+ ret {style: if code_to_the_left { trailing } else { isolated },
+ lines: lines,
+ pos: p};
}
-fn all_whitespace(&str s, uint begin, uint end) -> bool {
- let uint i = begin;
- while (i != end) {
- if (!is_whitespace(s.(i) as char)) { ret false; }
+fn all_whitespace(s: &str, begin: uint, end: uint) -> bool {
+ let i: uint = begin;
+ while i != end {
+ if !is_whitespace(s.(i) as char) { ret false; }
i += 1u;
}
ret true;
}
-fn trim_whitespace_prefix_and_push_line(&mutable str[] lines, &str s,
- uint col) {
- auto s1;
- if (all_whitespace(s, 0u, col)) {
- if (col < str::byte_len(s)) {
+fn trim_whitespace_prefix_and_push_line(lines: &mutable str[], s: &str,
+ col: uint) {
+ let s1;
+ if all_whitespace(s, 0u, col) {
+ if col < str::byte_len(s) {
s1 = str::slice(s, col, str::byte_len(s));
} else { s1 = ""; }
} else { s1 = s; }
@@ -667,31 +642,31 @@
lines += ~[s1];
}
-fn read_block_comment(&reader rdr, bool code_to_the_left) -> cmnt {
+fn read_block_comment(rdr: &reader, code_to_the_left: bool) -> cmnt {
log ">>> block comment";
- auto p = rdr.get_chpos();
- let str[] lines = ~[];
- let uint col = rdr.get_col();
+ let p = rdr.get_chpos();
+ let lines: str[] = ~[];
+ let col: uint = rdr.get_col();
rdr.bump();
rdr.bump();
- auto curr_line = "/*";
- let int level = 1;
- while (level > 0) {
+ let curr_line = "/*";
+ let level: int = 1;
+ while level > 0 {
log #fmt("=== block comment level %d", level);
- if (rdr.is_eof()) { rdr.err("unterminated block comment"); fail; }
- if (rdr.curr() == '\n') {
+ if rdr.is_eof() { rdr.err("unterminated block comment"); fail; }
+ if rdr.curr() == '\n' {
trim_whitespace_prefix_and_push_line(lines, curr_line, col);
curr_line = "";
rdr.bump();
} else {
str::push_char(curr_line, rdr.curr());
- if (rdr.curr() == '/' && rdr.next() == '*') {
+ if rdr.curr() == '/' && rdr.next() == '*' {
rdr.bump();
rdr.bump();
curr_line += "*";
level += 1;
} else {
- if (rdr.curr() == '*' && rdr.next() == '/') {
+ if rdr.curr() == '*' && rdr.next() == '/' {
rdr.bump();
rdr.bump();
curr_line += "/";
@@ -700,27 +675,27 @@
}
}
}
- if (str::byte_len(curr_line) != 0u) {
+ if str::byte_len(curr_line) != 0u {
trim_whitespace_prefix_and_push_line(lines, curr_line, col);
}
- auto style = if (code_to_the_left) { trailing } else { isolated };
+ let style = if code_to_the_left { trailing } else { isolated };
consume_non_eol_whitespace(rdr);
- if (!rdr.is_eof() && rdr.curr() != '\n' && ivec::len(lines) == 1u) {
+ if !rdr.is_eof() && rdr.curr() != '\n' && ivec::len(lines) == 1u {
style = mixed;
}
log "<<< block comment";
- ret rec(style=style, lines=lines, pos=p);
+ ret {style: style, lines: lines, pos: p};
}
-fn peeking_at_comment(&reader rdr) -> bool {
+fn peeking_at_comment(rdr: &reader) -> bool {
ret rdr.curr() == '/' && rdr.next() == '/' ||
rdr.curr() == '/' && rdr.next() == '*';
}
-fn consume_comment(&reader rdr, bool code_to_the_left,
- &mutable cmnt[] comments) {
+fn consume_comment(rdr: &reader, code_to_the_left: bool,
+ comments: &mutable cmnt[]) {
log ">>> consume comment";
- if (rdr.curr() == '/' && rdr.next() == '/') {
+ if rdr.curr() == '/' && rdr.next() == '/' {
comments += ~[read_line_comments(rdr, code_to_the_left)];
} else if (rdr.curr() == '/' && rdr.next() == '*') {
comments += ~[read_block_comment(rdr, code_to_the_left)];
@@ -728,53 +703,53 @@
log "<<< consume comment";
}
-fn is_lit(&token::token t) -> bool {
- ret alt (t) {
- case (token::LIT_INT(_)) { true }
- case (token::LIT_UINT(_)) { true }
- case (token::LIT_MACH_INT(_, _)) { true }
- case (token::LIT_FLOAT(_)) { true }
- case (token::LIT_MACH_FLOAT(_, _)) { true }
- case (token::LIT_STR(_)) { true }
- case (token::LIT_CHAR(_)) { true }
- case (token::LIT_BOOL(_)) { true }
- case (_) { false }
+fn is_lit(t: &token::token) -> bool {
+ ret alt t {
+ token::LIT_INT(_) { true }
+ token::LIT_UINT(_) { true }
+ token::LIT_MACH_INT(_, _) { true }
+ token::LIT_FLOAT(_) { true }
+ token::LIT_MACH_FLOAT(_, _) { true }
+ token::LIT_STR(_) { true }
+ token::LIT_CHAR(_) { true }
+ token::LIT_BOOL(_) { true }
+ _ { false }
}
}
-type lit = rec(str lit, uint pos);
+type lit = {lit: str, pos: uint};
-fn gather_comments_and_literals(&codemap::codemap cm, str path,
- ioivec::reader srdr)
- -> rec(cmnt[] cmnts, lit[] lits) {
- auto src = str::unsafe_from_bytes_ivec(srdr.read_whole_stream());
- auto itr = @interner::mk[str](str::hash, str::eq);
- auto rdr = new_reader(cm, src, codemap::new_filemap(path, 0u, 0u), itr);
- let cmnt[] comments = ~[];
- let lit[] literals = ~[];
- let bool first_read = true;
- while (!rdr.is_eof()) {
- while (true) {
- auto code_to_the_left = !first_read;
+fn gather_comments_and_literals(cm: &codemap::codemap, path: str,
+ srdr: ioivec::reader) ->
+ {cmnts: cmnt[], lits: lit[]} {
+ let src = str::unsafe_from_bytes_ivec(srdr.read_whole_stream());
+ let itr = @interner::mk[str](str::hash, str::eq);
+ let rdr = new_reader(cm, src, codemap::new_filemap(path, 0u, 0u), itr);
+ let comments: cmnt[] = ~[];
+ let literals: lit[] = ~[];
+ let first_read: bool = true;
+ while !rdr.is_eof() {
+ while true {
+ let code_to_the_left = !first_read;
consume_non_eol_whitespace(rdr);
- if (rdr.curr() == '\n') {
+ if rdr.curr() == '\n' {
code_to_the_left = false;
consume_whitespace_counting_blank_lines(rdr, comments);
}
- while (peeking_at_comment(rdr)) {
+ while peeking_at_comment(rdr) {
consume_comment(rdr, code_to_the_left, comments);
consume_whitespace_counting_blank_lines(rdr, comments);
}
break;
}
- auto tok = next_token(rdr);
- if (is_lit(tok.tok)) {
- literals += ~[rec(lit=rdr.get_str_from(tok.bpos), pos=tok.chpos)];
+ let tok = next_token(rdr);
+ if is_lit(tok.tok) {
+ literals += ~[{lit: rdr.get_str_from(tok.bpos), pos: tok.chpos}];
}
log "tok: " + token::to_str(rdr, tok.tok);
first_read = false;
}
- ret rec(cmnts=comments, lits=literals);
+ ret {cmnts: comments, lits: literals};
}
//
// Local Variables:
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs
index e0ca20a..c93f8ce 100644
--- a/src/comp/syntax/parse/parser.rs
+++ b/src/comp/syntax/parse/parser.rs
@@ -10,7 +10,7 @@
import std::either::right;
import std::map::hashmap;
import token::can_begin_expr;
-import ex=ext::base;
+import ex = ext::base;
import codemap::span;
import std::map::new_str_hash;
import util::interner;
@@ -23,98 +23,97 @@
tag ty_or_bang { a_ty(@ast::ty); a_bang; }
-type parse_sess = @rec(codemap::codemap cm,
- mutable node_id next_id);
+type parse_sess = @{cm: codemap::codemap, mutable next_id: node_id};
-fn next_node_id(&parse_sess sess) -> node_id {
- auto rv = sess.next_id;
+fn next_node_id(sess: &parse_sess) -> node_id {
+ let rv = sess.next_id;
sess.next_id += 1;
ret rv;
}
type parser =
obj {
- fn peek() -> token::token;
- fn bump();
- fn look_ahead(uint) -> token::token;
- fn fatal(str) -> !;
- fn warn(str);
- fn restrict(restriction);
- fn get_restriction() -> restriction;
- fn get_file_type() -> file_type;
- fn get_cfg() -> ast::crate_cfg;
- fn get_span() -> span;
- fn get_lo_pos() -> uint;
- fn get_hi_pos() -> uint;
- fn get_last_lo_pos() -> uint;
- fn get_last_hi_pos() -> uint;
- fn get_prec_table() -> @op_spec[];
- fn get_str(token::str_num) -> str;
- fn get_reader() -> lexer::reader;
- fn get_filemap() -> codemap::filemap;
- fn get_bad_expr_words() -> hashmap[str, ()];
- fn get_chpos() -> uint;
- fn get_byte_pos() -> uint;
- fn get_id() -> node_id;
- fn get_sess() -> parse_sess;
+ fn peek() -> token::token ;
+ fn bump() ;
+ fn look_ahead(uint) -> token::token ;
+ fn fatal(str) -> ! ;
+ fn warn(str) ;
+ fn restrict(restriction) ;
+ fn get_restriction() -> restriction ;
+ fn get_file_type() -> file_type ;
+ fn get_cfg() -> ast::crate_cfg ;
+ fn get_span() -> span ;
+ fn get_lo_pos() -> uint ;
+ fn get_hi_pos() -> uint ;
+ fn get_last_lo_pos() -> uint ;
+ fn get_last_hi_pos() -> uint ;
+ fn get_prec_table() -> @op_spec[] ;
+ fn get_str(token::str_num) -> str ;
+ fn get_reader() -> lexer::reader ;
+ fn get_filemap() -> codemap::filemap ;
+ fn get_bad_expr_words() -> hashmap[str, ()] ;
+ fn get_chpos() -> uint ;
+ fn get_byte_pos() -> uint ;
+ fn get_id() -> node_id ;
+ fn get_sess() -> parse_sess ;
};
-fn new_parser_from_file(parse_sess sess, ast::crate_cfg cfg,
- str path, uint chpos, uint byte_pos) -> parser {
- auto ftype = SOURCE_FILE;
- if (str::ends_with(path, ".rc")) { ftype = CRATE_FILE; }
- auto srdr = ioivec::file_reader(path);
- auto src = str::unsafe_from_bytes_ivec(srdr.read_whole_stream());
- auto filemap = codemap::new_filemap(path, chpos, byte_pos);
+fn new_parser_from_file(sess: parse_sess, cfg: ast::crate_cfg, path: str,
+ chpos: uint, byte_pos: uint) -> parser {
+ let ftype = SOURCE_FILE;
+ if str::ends_with(path, ".rc") { ftype = CRATE_FILE; }
+ let srdr = ioivec::file_reader(path);
+ let src = str::unsafe_from_bytes_ivec(srdr.read_whole_stream());
+ let filemap = codemap::new_filemap(path, chpos, byte_pos);
sess.cm.files += ~[filemap];
- auto itr = @interner::mk(str::hash, str::eq);
- auto rdr = lexer::new_reader(sess.cm, src, filemap, itr);
+ let itr = @interner::mk(str::hash, str::eq);
+ let rdr = lexer::new_reader(sess.cm, src, filemap, itr);
ret new_parser(sess, cfg, rdr, ftype);
}
-fn new_parser(parse_sess sess, ast::crate_cfg cfg, lexer::reader rdr,
- file_type ftype) -> parser {
- obj stdio_parser(parse_sess sess,
- ast::crate_cfg cfg,
- file_type ftype,
- mutable token::token tok,
- mutable span tok_span,
- mutable span last_tok_span,
- mutable rec(token::token tok, span span)[] buffer,
- mutable restriction restr,
- lexer::reader rdr,
- @op_spec[] precs,
- hashmap[str, ()] bad_words) {
+fn new_parser(sess: parse_sess, cfg: ast::crate_cfg, rdr: lexer::reader,
+ ftype: file_type) -> parser {
+ obj stdio_parser(sess: parse_sess,
+ cfg: ast::crate_cfg,
+ ftype: file_type,
+ mutable tok: token::token,
+ mutable tok_span: span,
+ mutable last_tok_span: span,
+ mutable buffer: {tok: token::token, span: span}[],
+ mutable restr: restriction,
+ rdr: lexer::reader,
+ precs: @op_spec[],
+ bad_words: hashmap[str, ()]) {
fn peek() -> token::token { ret tok; }
fn bump() {
last_tok_span = tok_span;
if ivec::len(buffer) == 0u {
- auto next = lexer::next_token(rdr);
+ let next = lexer::next_token(rdr);
tok = next.tok;
- tok_span = rec(lo=next.chpos, hi=rdr.get_chpos());
+ tok_span = {lo: next.chpos, hi: rdr.get_chpos()};
} else {
- auto next = ivec::pop(buffer);
+ let next = ivec::pop(buffer);
tok = next.tok;
tok_span = next.span;
}
}
- fn look_ahead(uint distance) -> token::token {
+ fn look_ahead(distance: uint) -> token::token {
while ivec::len(buffer) < distance {
- auto next = lexer::next_token(rdr);
- auto sp = rec(lo=next.chpos, hi=rdr.get_chpos());
- buffer = ~[rec(tok=next.tok, span=sp)] + buffer;
+ let next = lexer::next_token(rdr);
+ let sp = {lo: next.chpos, hi: rdr.get_chpos()};
+ buffer = ~[{tok: next.tok, span: sp}] + buffer;
}
- ret buffer.(distance-1u).tok;
+ ret buffer.(distance - 1u).tok;
}
- fn fatal(str m) -> ! {
+ fn fatal(m: str) -> ! {
codemap::emit_error(some(self.get_span()), m, sess.cm);
fail;
}
- fn warn(str m) {
+ fn warn(m: str) {
codemap::emit_warning(some(self.get_span()), m, sess.cm);
}
- fn restrict(restriction r) { restr = r; }
+ fn restrict(r: restriction) { restr = r; }
fn get_restriction() -> restriction { ret restr; }
fn get_span() -> span { ret tok_span; }
fn get_lo_pos() -> uint { ret tok_span.lo; }
@@ -124,7 +123,7 @@
fn get_file_type() -> file_type { ret ftype; }
fn get_cfg() -> ast::crate_cfg { ret cfg; }
fn get_prec_table() -> @op_spec[] { ret precs; }
- fn get_str(token::str_num i) -> str {
+ fn get_str(i: token::str_num) -> str {
ret interner::get(*rdr.get_interner(), i);
}
fn get_reader() -> lexer::reader { ret rdr; }
@@ -136,18 +135,17 @@
fn get_sess() -> parse_sess { ret sess; }
}
- auto tok0 = lexer::next_token(rdr);
- auto span0 = rec(lo=tok0.chpos, hi=rdr.get_chpos());
- ret stdio_parser(sess, cfg, ftype, tok0.tok,
- span0, span0, ~[], UNRESTRICTED, rdr,
- prec_table(), bad_expr_word_table());
+ let tok0 = lexer::next_token(rdr);
+ let span0 = {lo: tok0.chpos, hi: rdr.get_chpos()};
+ ret stdio_parser(sess, cfg, ftype, tok0.tok, span0, span0, ~[],
+ UNRESTRICTED, rdr, prec_table(), bad_expr_word_table());
}
// These are the words that shouldn't be allowed as value identifiers,
// because, if used at the start of a line, they will cause the line to be
// interpreted as a specific kind of statement, which would be confusing.
fn bad_expr_word_table() -> hashmap[str, ()] {
- auto words = new_str_hash();
+ let words = new_str_hash();
words.insert("mod", ());
words.insert("if", ());
words.insert("else", ());
@@ -188,17 +186,17 @@
ret words;
}
-fn unexpected(&parser p, token::token t) -> ! {
- let str s = "unexpected token: ";
+fn unexpected(p: &parser, t: token::token) -> ! {
+ let s: str = "unexpected token: ";
s += token::to_str(p.get_reader(), t);
p.fatal(s);
}
-fn expect(&parser p, token::token t) {
- if (p.peek() == t) {
+fn expect(p: &parser, t: token::token) {
+ if p.peek() == t {
p.bump();
} else {
- let str s = "expecting ";
+ let s: str = "expecting ";
s += token::to_str(p.get_reader(), t);
s += ", found ";
s += token::to_str(p.get_reader(), p.peek());
@@ -206,105 +204,105 @@
}
}
-fn spanned[T](uint lo, uint hi, &T node) -> spanned[T] {
- ret rec(node=node, span=rec(lo=lo, hi=hi));
+fn spanned[T](lo: uint, hi: uint, node: &T) -> spanned[T] {
+ ret {node: node, span: {lo: lo, hi: hi}};
}
-fn parse_ident(&parser p) -> ast::ident {
- alt (p.peek()) {
- case (token::IDENT(?i, _)) { p.bump(); ret p.get_str(i); }
- case (_) { p.fatal("expecting ident"); fail; }
+fn parse_ident(p: &parser) -> ast::ident {
+ alt p.peek() {
+ token::IDENT(i, _) { p.bump(); ret p.get_str(i); }
+ _ { p.fatal("expecting ident"); fail; }
}
}
-fn parse_value_ident(&parser p) -> ast::ident {
+fn parse_value_ident(p: &parser) -> ast::ident {
check_bad_word(p);
ret parse_ident(p);
}
-fn eat(&parser p, &token::token tok) -> bool {
- ret if p.peek() == tok { p.bump(); true }
- else { false };
+fn eat(p: &parser, tok: &token::token) -> bool {
+ ret if p.peek() == tok { p.bump(); true } else { false };
}
-fn is_word(&parser p, &str word) -> bool {
- ret alt (p.peek()) {
- case (token::IDENT(?sid, false)) { str::eq(word, p.get_str(sid)) }
- case (_) { false }
+fn is_word(p: &parser, word: &str) -> bool {
+ ret alt p.peek() {
+ token::IDENT(sid, false) { str::eq(word, p.get_str(sid)) }
+ _ { false }
};
}
-fn eat_word(&parser p, &str word) -> bool {
- alt (p.peek()) {
- case (token::IDENT(?sid, false)) {
- if (str::eq(word, p.get_str(sid))) {
- p.bump();
- ret true;
- } else { ret false; }
- }
- case (_) { ret false; }
+fn eat_word(p: &parser, word: &str) -> bool {
+ alt p.peek() {
+ token::IDENT(sid, false) {
+ if str::eq(word, p.get_str(sid)) {
+ p.bump();
+ ret true;
+ } else { ret false; }
+ }
+ _ { ret false; }
}
}
-fn expect_word(&parser p, &str word) {
- if (!eat_word(p, word)) {
+fn expect_word(p: &parser, word: &str) {
+ if !eat_word(p, word) {
p.fatal("expecting " + word + ", found " +
- token::to_str(p.get_reader(), p.peek()));
+ token::to_str(p.get_reader(), p.peek()));
}
}
-fn check_bad_word(&parser p) {
- alt (p.peek()) {
- case (token::IDENT(?sid, false)) {
- auto w = p.get_str(sid);
- if (p.get_bad_expr_words().contains_key(w)) {
- p.fatal("found " + w + " in expression position");
- }
+fn check_bad_word(p: &parser) {
+ alt p.peek() {
+ token::IDENT(sid, false) {
+ let w = p.get_str(sid);
+ if p.get_bad_expr_words().contains_key(w) {
+ p.fatal("found " + w + " in expression position");
}
- case (_) { }
+ }
+ _ { }
}
}
-fn parse_ty_fn(ast::proto proto, &parser p, uint lo) -> ast::ty_ {
- fn parse_fn_input_ty(&parser p) -> ast::ty_arg {
- auto lo = p.get_lo_pos();
+fn parse_ty_fn(proto: ast::proto, p: &parser, lo: uint) -> ast::ty_ {
+ fn parse_fn_input_ty(p: &parser) -> ast::ty_arg {
+ let lo = p.get_lo_pos();
// Ignore arg name, if present
if is_plain_ident(p) && p.look_ahead(1u) == token::COLON {
- p.bump(); p.bump();
+ p.bump();
+ p.bump();
}
- auto mode = ast::val;
- if (p.peek() == token::BINOP(token::AND)) {
+ let mode = ast::val;
+ if p.peek() == token::BINOP(token::AND) {
p.bump();
mode = ast::alias(eat_word(p, "mutable"));
}
- auto t = parse_ty(p);
- ret spanned(lo, t.span.hi, rec(mode=mode, ty=t));
+ let t = parse_ty(p);
+ ret spanned(lo, t.span.hi, {mode: mode, ty: t});
}
- auto lo = p.get_lo_pos();
- auto inputs =
+ let lo = p.get_lo_pos();
+ let inputs =
parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA),
- parse_fn_input_ty, p);
+ parse_fn_input_ty, p);
// FIXME: there's no syntax for this right now anyway
// auto constrs = parse_constrs(~[], p);
- let (@ast::constr)[] constrs = ~[];
- let @ast::ty output;
- auto cf = ast::return;
- if (p.peek() == token::RARROW) {
+ let constrs: (@ast::constr)[] = ~[];
+ let output: @ast::ty;
+ let cf = ast::return;
+ if p.peek() == token::RARROW {
p.bump();
- auto tmp = parse_ty_or_bang(p);
- alt (tmp) {
- case (a_ty(?t)) { output = t; }
- case (a_bang) {
- output = @spanned(lo, inputs.span.hi, ast::ty_bot);
- cf = ast::noreturn;
- }
+ let tmp = parse_ty_or_bang(p);
+ alt tmp {
+ a_ty(t) { output = t; }
+ a_bang. {
+ output = @spanned(lo, inputs.span.hi, ast::ty_bot);
+ cf = ast::noreturn;
+ }
}
} else { output = @spanned(lo, inputs.span.hi, ast::ty_nil); }
ret ast::ty_fn(proto, inputs.node, output, cf, constrs);
}
-fn parse_proto(&parser p) -> ast::proto {
- if (eat_word(p, "iter")) {
+fn parse_proto(p: &parser) -> ast::proto {
+ if eat_word(p, "iter") {
ret ast::proto_iter;
} else if (eat_word(p, "fn")) {
ret ast::proto_fn;
@@ -315,183 +313,178 @@
} else { unexpected(p, p.peek()); }
}
-fn parse_ty_obj(&parser p, &mutable uint hi) -> ast::ty_ {
- fn parse_method_sig(&parser p) -> ast::ty_method {
- auto flo = p.get_lo_pos();
- let ast::proto proto = parse_proto(p);
- auto ident = parse_value_ident(p);
- auto f = parse_ty_fn(proto, p, flo);
+fn parse_ty_obj(p: &parser, hi: &mutable uint) -> ast::ty_ {
+ fn parse_method_sig(p: &parser) -> ast::ty_method {
+ let flo = p.get_lo_pos();
+ let proto: ast::proto = parse_proto(p);
+ let ident = parse_value_ident(p);
+ let f = parse_ty_fn(proto, p, flo);
expect(p, token::SEMI);
- alt (f) {
- case (ast::ty_fn(?proto, ?inputs, ?output, ?cf, ?constrs)) {
- ret spanned(flo, output.span.hi,
- rec(proto=proto,
- ident=ident,
- inputs=inputs,
- output=output,
- cf=cf,
- constrs=constrs));
- }
+ alt f {
+ ast::ty_fn(proto, inputs, output, cf, constrs) {
+ ret spanned(flo, output.span.hi,
+ {proto: proto,
+ ident: ident,
+ inputs: inputs,
+ output: output,
+ cf: cf,
+ constrs: constrs});
+ }
}
fail;
}
- auto meths = parse_seq(token::LBRACE, token::RBRACE, none,
- parse_method_sig, p);
+ let meths =
+ parse_seq(token::LBRACE, token::RBRACE, none, parse_method_sig, p);
hi = meths.span.hi;
ret ast::ty_obj(meths.node);
}
-fn parse_mt(&parser p) -> ast::mt {
- auto mut = parse_mutability(p);
- auto t = parse_ty(p);
- ret rec(ty=t, mut=mut);
+fn parse_mt(p: &parser) -> ast::mt {
+ let mut = parse_mutability(p);
+ let t = parse_ty(p);
+ ret {ty: t, mut: mut};
}
-fn parse_ty_field(&parser p) -> ast::ty_field {
- auto lo = p.get_lo_pos();
- auto mut = parse_mutability(p);
- auto id = parse_ident(p);
+fn parse_ty_field(p: &parser) -> ast::ty_field {
+ let lo = p.get_lo_pos();
+ let mut = parse_mutability(p);
+ let id = parse_ident(p);
expect(p, token::COLON);
- auto ty = parse_ty(p);
- ret spanned(lo, ty.span.hi, rec(ident=id, mt=rec(ty=ty, mut=mut)));
+ let ty = parse_ty(p);
+ ret spanned(lo, ty.span.hi, {ident: id, mt: {ty: ty, mut: mut}});
}
// if i is the jth ident in args, return j
// otherwise, fail
-fn ident_index(&parser p, &ast::arg[] args, &ast::ident i) -> uint {
- auto j = 0u;
- for (ast::arg a in args) { if (a.ident == i) { ret j; } j += 1u; }
+fn ident_index(p: &parser, args: &ast::arg[], i: &ast::ident) -> uint {
+ let j = 0u;
+ for a: ast::arg in args { if a.ident == i { ret j; } j += 1u; }
p.fatal("Unbound variable " + i + " in constraint arg");
}
-fn parse_type_constr_arg(&parser p) -> @ast::ty_constr_arg {
- auto sp = p.get_span();
- auto carg = ast::carg_base;
+fn parse_type_constr_arg(p: &parser) -> @ast::ty_constr_arg {
+ let sp = p.get_span();
+ let carg = ast::carg_base;
expect(p, token::BINOP(token::STAR));
- if (p.peek() == token::DOT) {
+ if p.peek() == token::DOT {
// "*..." notation for record fields
p.bump();
- let ast::path pth = parse_path(p);
+ let pth: ast::path = parse_path(p);
carg = ast::carg_ident(pth);
}
// No literals yet, I guess?
- ret @rec(node=carg, span=sp);
+ ret @{node: carg, span: sp};
}
-fn parse_constr_arg(&ast::arg[] args, &parser p) -> @ast::constr_arg {
- auto sp = p.get_span();
- auto carg = ast::carg_base;
- if (p.peek() == token::BINOP(token::STAR)) {
+fn parse_constr_arg(args: &ast::arg[], p: &parser) -> @ast::constr_arg {
+ let sp = p.get_span();
+ let carg = ast::carg_base;
+ if p.peek() == token::BINOP(token::STAR) {
p.bump();
} else {
- let ast::ident i = parse_value_ident(p);
+ let i: ast::ident = parse_value_ident(p);
carg = ast::carg_ident(ident_index(p, args, i));
}
- ret @rec(node=carg, span=sp);
+ ret @{node: carg, span: sp};
}
-fn parse_ty_constr(&ast::arg[] fn_args, &parser p) -> @ast::constr {
- auto lo = p.get_lo_pos();
- auto path = parse_path(p);
- auto pf = bind parse_constr_arg(fn_args, _);
- let rec((@ast::constr_arg)[] node, span span) args =
- parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA), pf,
- p);
+fn parse_ty_constr(fn_args: &ast::arg[], p: &parser) -> @ast::constr {
+ let lo = p.get_lo_pos();
+ let path = parse_path(p);
+ let pf = bind parse_constr_arg(fn_args, _);
+ let args: {node: (@ast::constr_arg)[], span: span} =
+ parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA), pf, p);
ret @spanned(lo, args.span.hi,
- rec(path=path, args=args.node, id=p.get_id()));
+ {path: path, args: args.node, id: p.get_id()});
}
-fn parse_constr_in_type(&parser p) -> @ast::ty_constr {
- auto lo = p.get_lo_pos();
- auto path = parse_path(p);
- let (@ast::ty_constr_arg)[] args =
- (parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA),
- parse_type_constr_arg, p)).node;
- auto hi = p.get_lo_pos();
- let ast::ty_constr_ tc = rec(path=path, args=args, id=p.get_id());
+fn parse_constr_in_type(p: &parser) -> @ast::ty_constr {
+ let lo = p.get_lo_pos();
+ let path = parse_path(p);
+ let args: (@ast::ty_constr_arg)[] =
+ parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA),
+ parse_type_constr_arg, p).node;
+ let hi = p.get_lo_pos();
+ let tc: ast::ty_constr_ = {path: path, args: args, id: p.get_id()};
ret @spanned(lo, hi, tc);
}
-fn parse_constrs[T](fn(&parser p) ->
- (@ast::constr_general[T]) pser, &parser p)
- -> (@ast::constr_general[T])[] {
- let (@ast::constr_general[T])[] constrs = ~[];
- while (true) {
- auto constr = pser(p);
+fn parse_constrs[T](pser: fn(&parser) -> @ast::constr_general[T] , p: &parser)
+ -> (@ast::constr_general[T])[] {
+ let constrs: (@ast::constr_general[T])[] = ~[];
+ while true {
+ let constr = pser(p);
constrs += ~[constr];
- if (p.peek() == token::COMMA) { p.bump(); } else { break; }
+ if p.peek() == token::COMMA { p.bump(); } else { break; }
}
constrs
}
-fn parse_type_constraints(&parser p) -> (@ast::ty_constr)[] {
+fn parse_type_constraints(p: &parser) -> (@ast::ty_constr)[] {
ret parse_constrs(parse_constr_in_type, p);
}
-fn parse_ty_postfix(ast::ty_ orig_t, &parser p) -> @ast::ty {
- auto lo = p.get_lo_pos();
- if (p.peek() == token::LBRACKET) {
+fn parse_ty_postfix(orig_t: ast::ty_, p: &parser) -> @ast::ty {
+ let lo = p.get_lo_pos();
+ if p.peek() == token::LBRACKET {
p.bump();
- auto mut;
- if (eat_word(p, "mutable")) {
- if (p.peek() == token::QUES) {
+ let mut;
+ if eat_word(p, "mutable") {
+ if p.peek() == token::QUES {
p.bump();
mut = ast::maybe_mut;
- } else {
- mut = ast::mut;
- }
- } else {
- mut = ast::imm;
- }
+ } else { mut = ast::mut; }
+ } else { mut = ast::imm; }
- if (mut == ast::imm && p.peek() != token::RBRACKET) {
+ if mut == ast::imm && p.peek() != token::RBRACKET {
// This is explicit type parameter instantiation.
- auto seq = parse_seq_to_end(token::RBRACKET,
- some(token::COMMA), parse_ty, p);
+ let seq =
+ parse_seq_to_end(token::RBRACKET, some(token::COMMA),
+ parse_ty, p);
- alt (orig_t) {
- case (ast::ty_path(?pth, ?ann)) {
- auto hi = p.get_hi_pos();
- ret @spanned(lo, hi,
- ast::ty_path(spanned(lo, hi,
- rec(global=pth.node.global,
- idents=pth.node.idents,
- types=seq)),
- ann));
- }
- case (_) {
- p.fatal("type parameter instantiation only allowed for " +
- "paths");
- }
+
+ alt orig_t {
+ ast::ty_path(pth, ann) {
+ let hi = p.get_hi_pos();
+ ret @spanned(lo, hi,
+ ast::ty_path(spanned(lo, hi,
+ {global: pth.node.global,
+ idents: pth.node.idents,
+ types: seq}), ann));
+ }
+ _ {
+ p.fatal("type parameter instantiation only allowed for " +
+ "paths");
+ }
}
}
expect(p, token::RBRACKET);
- auto hi = p.get_hi_pos();
+ let hi = p.get_hi_pos();
// FIXME: spans are probably wrong
- auto t = ast::ty_ivec(rec(ty=@spanned(lo, hi, orig_t), mut=mut));
+ let t = ast::ty_ivec({ty: @spanned(lo, hi, orig_t), mut: mut});
ret parse_ty_postfix(t, p);
}
ret @spanned(lo, p.get_lo_pos(), orig_t);
}
-fn parse_ty_or_bang(&parser p) -> ty_or_bang {
- alt (p.peek()) {
- case (token::NOT) { p.bump(); ret a_bang; }
- case (_) { ret a_ty(parse_ty(p)); }
+fn parse_ty_or_bang(p: &parser) -> ty_or_bang {
+ alt p.peek() {
+ token::NOT. { p.bump(); ret a_bang; }
+ _ { ret a_ty(parse_ty(p)); }
}
}
-fn parse_ty(&parser p) -> @ast::ty {
- auto lo = p.get_lo_pos();
- auto hi = lo;
- let ast::ty_ t;
+fn parse_ty(p: &parser) -> @ast::ty {
+ let lo = p.get_lo_pos();
+ let hi = lo;
+ let t: ast::ty_;
// FIXME: do something with this
parse_layer(p);
- if (eat_word(p, "bool")) {
+ if eat_word(p, "bool") {
t = ast::ty_bool;
} else if (eat_word(p, "int")) {
t = ast::ty_int;
@@ -529,36 +522,34 @@
t = ast::ty_machine(ast::ty_f64);
} else if (p.peek() == token::LPAREN) {
p.bump();
- alt (p.peek()) {
- case (token::RPAREN) {
- hi = p.get_hi_pos();
- p.bump();
- t = ast::ty_nil;
- }
- case (_) {
- t = parse_ty(p).node;
- hi = p.get_hi_pos();
- expect(p, token::RPAREN);
- }
+ alt p.peek() {
+ token::RPAREN. { hi = p.get_hi_pos(); p.bump(); t = ast::ty_nil; }
+ _ {
+ t = parse_ty(p).node;
+ hi = p.get_hi_pos();
+ expect(p, token::RPAREN);
+ }
}
} else if (p.peek() == token::AT) {
p.bump();
- auto mt = parse_mt(p);
+ let mt = parse_mt(p);
hi = mt.ty.span.hi;
t = ast::ty_box(mt);
} else if (p.peek() == token::BINOP(token::STAR)) {
p.bump();
- auto mt = parse_mt(p);
+ let mt = parse_mt(p);
hi = mt.ty.span.hi;
t = ast::ty_ptr(mt);
} else if (p.peek() == token::LBRACE) {
- auto elems = parse_seq(token::LBRACE, token::RBRACE,
- some(token::COMMA), parse_ty_field, p);
+ let elems =
+ parse_seq(token::LBRACE, token::RBRACE, some(token::COMMA),
+ parse_ty_field, p);
hi = elems.span.hi;
t = ast::ty_rec(elems.node);
- if (p.peek() == token::COLON) {
+ if p.peek() == token::COLON {
p.bump();
- t = ast::ty_constr(@spanned(lo, hi, t),
+ t =
+ ast::ty_constr(@spanned(lo, hi, t),
parse_type_constraints(p));
}
} else if (eat_word(p, "vec")) {
@@ -567,17 +558,17 @@
hi = p.get_hi_pos();
expect(p, token::RBRACKET);
} else if (eat_word(p, "fn")) {
- auto flo = p.get_last_lo_pos();
+ let flo = p.get_last_lo_pos();
t = parse_ty_fn(ast::proto_fn, p, flo);
- alt (t) { case (ast::ty_fn(_, _, ?out, _, _)) { hi = out.span.hi; } }
+ alt t { ast::ty_fn(_, _, out, _, _) { hi = out.span.hi; } }
} else if (eat_word(p, "block")) {
- auto flo = p.get_last_lo_pos();
+ let flo = p.get_last_lo_pos();
t = parse_ty_fn(ast::proto_block, p, flo);
- alt (t) { case (ast::ty_fn(_, _, ?out, _, _)) { hi = out.span.hi; } }
+ alt t { ast::ty_fn(_, _, out, _, _) { hi = out.span.hi; } }
} else if (eat_word(p, "iter")) {
- auto flo = p.get_last_lo_pos();
+ let flo = p.get_last_lo_pos();
t = parse_ty_fn(ast::proto_iter, p, flo);
- alt (t) { case (ast::ty_fn(_, _, ?out, _, _)) { hi = out.span.hi; } }
+ alt t { ast::ty_fn(_, _, out, _, _) { hi = out.span.hi; } }
} else if (eat_word(p, "obj")) {
t = parse_ty_obj(p, hi);
} else if (eat_word(p, "port")) {
@@ -592,45 +583,43 @@
expect(p, token::RBRACKET);
} else if (eat_word(p, "mutable")) {
p.warn("ignoring deprecated 'mutable' type constructor");
- auto typ = parse_ty(p);
+ let typ = parse_ty(p);
t = typ.node;
hi = typ.span.hi;
} else if (p.peek() == token::MOD_SEP || is_ident(p.peek())) {
- auto path = parse_path(p);
+ let path = parse_path(p);
t = ast::ty_path(path, p.get_id());
hi = path.span.hi;
} else { p.fatal("expecting type"); t = ast::ty_nil; fail; }
ret parse_ty_postfix(t, p);
}
-fn parse_arg(&parser p) -> ast::arg {
- let ast::mode m = ast::val;
- let ast::ident i = parse_value_ident(p);
+fn parse_arg(p: &parser) -> ast::arg {
+ let m: ast::mode = ast::val;
+ let i: ast::ident = parse_value_ident(p);
expect(p, token::COLON);
if eat(p, token::BINOP(token::AND)) {
m = ast::alias(eat_word(p, "mutable"));
}
- let @ast::ty t = parse_ty(p);
- ret rec(mode=m, ty=t, ident=i, id=p.get_id());
+ let t: @ast::ty = parse_ty(p);
+ ret {mode: m, ty: t, ident: i, id: p.get_id()};
}
-fn parse_seq_to_end[T](token::token ket, option::t[token::token] sep,
- fn(&parser)->T f, &parser p) -> T[] {
- auto val = parse_seq_to_before_end(ket, sep, f, p);
+fn parse_seq_to_end[T](ket: token::token, sep: option::t[token::token],
+ f: fn(&parser) -> T , p: &parser) -> T[] {
+ let val = parse_seq_to_before_end(ket, sep, f, p);
p.bump();
ret val;
}
-fn parse_seq_to_before_end[T](token::token ket, option::t[token::token] sep,
- fn(&parser)->T f, &parser p) -> T[] {
- let bool first = true;
- let T[] v = ~[];
- while (p.peek() != ket) {
- alt (sep) {
- case (some(?t)) {
- if (first) { first = false; } else { expect(p, t); }
- }
- case (_) { }
+fn parse_seq_to_before_end[T](ket: token::token, sep: option::t[token::token],
+ f: fn(&parser) -> T , p: &parser) -> T[] {
+ let first: bool = true;
+ let v: T[] = ~[];
+ while p.peek() != ket {
+ alt sep {
+ some(t) { if first { first = false; } else { expect(p, t); } }
+ _ { }
}
v += ~[f(p)];
}
@@ -638,170 +627,167 @@
}
-fn parse_seq[T](token::token bra, token::token ket,
- option::t[token::token] sep,
- fn(&parser)->T f, &parser p) -> spanned[T[]] {
- auto lo = p.get_lo_pos();
+fn parse_seq[T](bra: token::token, ket: token::token,
+ sep: option::t[token::token], f: fn(&parser) -> T ,
+ p: &parser) -> spanned[T[]] {
+ let lo = p.get_lo_pos();
expect(p, bra);
- auto result = parse_seq_to_before_end[T](ket, sep, f, p);
- auto hi = p.get_hi_pos();
+ let result = parse_seq_to_before_end[T](ket, sep, f, p);
+ let hi = p.get_hi_pos();
p.bump();
ret spanned(lo, hi, result);
}
-fn parse_lit(&parser p) -> ast::lit {
- auto sp = p.get_span();
- let ast::lit_ lit = ast::lit_nil;
- if (eat_word(p, "true")) {
+fn parse_lit(p: &parser) -> ast::lit {
+ let sp = p.get_span();
+ let lit: ast::lit_ = ast::lit_nil;
+ if eat_word(p, "true") {
lit = ast::lit_bool(true);
} else if (eat_word(p, "false")) {
lit = ast::lit_bool(false);
} else {
- alt (p.peek()) {
- case (token::LIT_INT(?i)) { p.bump(); lit = ast::lit_int(i); }
- case (token::LIT_UINT(?u)) { p.bump(); lit = ast::lit_uint(u); }
- case (token::LIT_FLOAT(?s)) {
- p.bump();
- lit = ast::lit_float(p.get_str(s));
- }
- case (token::LIT_MACH_INT(?tm, ?i)) {
- p.bump();
- lit = ast::lit_mach_int(tm, i);
- }
- case (token::LIT_MACH_FLOAT(?tm, ?s)) {
- p.bump();
- lit = ast::lit_mach_float(tm, p.get_str(s));
- }
- case (token::LIT_CHAR(?c)) { p.bump(); lit = ast::lit_char(c); }
- case (token::LIT_STR(?s)) {
- p.bump();
- lit = ast::lit_str(p.get_str(s), ast::sk_rc);
- }
- case (token::LPAREN) {
- p.bump();
- expect(p, token::RPAREN);
- lit = ast::lit_nil;
- }
- case (?t) { unexpected(p, t); }
+ alt p.peek() {
+ token::LIT_INT(i) { p.bump(); lit = ast::lit_int(i); }
+ token::LIT_UINT(u) { p.bump(); lit = ast::lit_uint(u); }
+ token::LIT_FLOAT(s) {
+ p.bump();
+ lit = ast::lit_float(p.get_str(s));
+ }
+ token::LIT_MACH_INT(tm, i) {
+ p.bump();
+ lit = ast::lit_mach_int(tm, i);
+ }
+ token::LIT_MACH_FLOAT(tm, s) {
+ p.bump();
+ lit = ast::lit_mach_float(tm, p.get_str(s));
+ }
+ token::LIT_CHAR(c) { p.bump(); lit = ast::lit_char(c); }
+ token::LIT_STR(s) {
+ p.bump();
+ lit = ast::lit_str(p.get_str(s), ast::sk_rc);
+ }
+ token::LPAREN. {
+ p.bump();
+ expect(p, token::RPAREN);
+ lit = ast::lit_nil;
+ }
+ t { unexpected(p, t); }
}
}
- ret rec(node=lit, span=sp);
+ ret {node: lit, span: sp};
}
-fn is_ident(token::token t) -> bool {
- alt (t) { case (token::IDENT(_, _)) { ret true; } case (_) { } }
+fn is_ident(t: token::token) -> bool {
+ alt t { token::IDENT(_, _) { ret true; } _ { } }
ret false;
}
-fn is_plain_ident(&parser p) -> bool {
+fn is_plain_ident(p: &parser) -> bool {
ret alt p.peek() { token::IDENT(_, false) { true } _ { false } };
}
-fn parse_path(&parser p) -> ast::path {
- auto lo = p.get_lo_pos();
- auto hi = lo;
+fn parse_path(p: &parser) -> ast::path {
+ let lo = p.get_lo_pos();
+ let hi = lo;
- auto global;
- if (p.peek() == token::MOD_SEP) {
- global = true; p.bump();
- } else {
- global = false;
- }
+ let global;
+ if p.peek() == token::MOD_SEP {
+ global = true;
+ p.bump();
+ } else { global = false; }
- let ast::ident[] ids = ~[];
- while (true) {
- alt (p.peek()) {
- case (token::IDENT(?i, _)) {
- hi = p.get_hi_pos();
- ids += ~[p.get_str(i)];
- hi = p.get_hi_pos();
- p.bump();
- if (p.peek() == token::MOD_SEP) { p.bump(); } else { break; }
- }
- case (_) { break; }
+ let ids: ast::ident[] = ~[];
+ while true {
+ alt p.peek() {
+ token::IDENT(i, _) {
+ hi = p.get_hi_pos();
+ ids += ~[p.get_str(i)];
+ hi = p.get_hi_pos();
+ p.bump();
+ if p.peek() == token::MOD_SEP { p.bump(); } else { break; }
+ }
+ _ { break; }
}
}
- ret spanned(lo, hi, rec(global=global, idents=ids, types=~[]));
+ ret spanned(lo, hi, {global: global, idents: ids, types: ~[]});
}
-fn parse_path_and_ty_param_substs(&parser p) -> ast::path {
- auto lo = p.get_lo_pos();
- auto path = parse_path(p);
- if (p.peek() == token::LBRACKET) {
- auto seq = parse_seq(token::LBRACKET, token::RBRACKET,
- some(token::COMMA), parse_ty, p);
- auto hi = seq.span.hi;
- path = spanned(lo, hi, rec(global=path.node.global,
- idents=path.node.idents,
- types=seq.node));
+fn parse_path_and_ty_param_substs(p: &parser) -> ast::path {
+ let lo = p.get_lo_pos();
+ let path = parse_path(p);
+ if p.peek() == token::LBRACKET {
+ let seq =
+ parse_seq(token::LBRACKET, token::RBRACKET, some(token::COMMA),
+ parse_ty, p);
+ let hi = seq.span.hi;
+ path =
+ spanned(lo, hi,
+ {global: path.node.global,
+ idents: path.node.idents,
+ types: seq.node});
}
ret path;
}
-fn parse_mutability(&parser p) -> ast::mutability {
- if (eat_word(p, "mutable")) {
- if (p.peek() == token::QUES) { p.bump(); ret ast::maybe_mut; }
+fn parse_mutability(p: &parser) -> ast::mutability {
+ if eat_word(p, "mutable") {
+ if p.peek() == token::QUES { p.bump(); ret ast::maybe_mut; }
ret ast::mut;
}
ret ast::imm;
}
-fn parse_field(&parser p, &token::token sep) -> ast::field {
- auto lo = p.get_lo_pos();
- auto m = parse_mutability(p);
- auto i = parse_ident(p);
+fn parse_field(p: &parser, sep: &token::token) -> ast::field {
+ let lo = p.get_lo_pos();
+ let m = parse_mutability(p);
+ let i = parse_ident(p);
expect(p, sep);
- auto e = parse_expr(p);
- ret spanned(lo, e.span.hi, rec(mut=m, ident=i, expr=e));
+ let e = parse_expr(p);
+ ret spanned(lo, e.span.hi, {mut: m, ident: i, expr: e});
}
-fn mk_expr(&parser p, uint lo, uint hi, &ast::expr_ node) -> @ast::expr {
- ret @rec(id=p.get_id(),
- node=node,
- span=rec(lo=lo, hi=hi));
+fn mk_expr(p: &parser, lo: uint, hi: uint, node: &ast::expr_) -> @ast::expr {
+ ret @{id: p.get_id(), node: node, span: {lo: lo, hi: hi}};
}
-fn mk_mac_expr(&parser p, uint lo, uint hi, &ast::mac_ m) -> @ast::expr {
- ret @rec(id=p.get_id(),
- node=ast::expr_mac(rec(node=m, span=rec(lo=lo, hi=hi))),
- span=rec(lo=lo, hi=hi));
+fn mk_mac_expr(p: &parser, lo: uint, hi: uint, m: &ast::mac_) -> @ast::expr {
+ ret @{id: p.get_id(),
+ node: ast::expr_mac({node: m, span: {lo: lo, hi: hi}}),
+ span: {lo: lo, hi: hi}};
}
-fn parse_bottom_expr(&parser p) -> @ast::expr {
- auto lo = p.get_lo_pos();
- auto hi = p.get_hi_pos();
+fn parse_bottom_expr(p: &parser) -> @ast::expr {
+ let lo = p.get_lo_pos();
+ let hi = p.get_hi_pos();
// FIXME: can only remove this sort of thing when both typestate and
// alt-exhaustive-match checking are co-operating.
- auto lit = @spanned(lo, hi, ast::lit_nil);
- let ast::expr_ ex = ast::expr_lit(lit);
- if (p.peek() == token::LPAREN) {
+ let lit = @spanned(lo, hi, ast::lit_nil);
+ let ex: ast::expr_ = ast::expr_lit(lit);
+ if p.peek() == token::LPAREN {
p.bump();
- alt (p.peek()) {
- case (token::RPAREN) {
- hi = p.get_hi_pos();
- p.bump();
- auto lit = @spanned(lo, hi, ast::lit_nil);
- ret mk_expr(p, lo, hi, ast::expr_lit(lit));
- }
- case (_) {/* fall through */ }
+ alt p.peek() {
+ token::RPAREN. {
+ hi = p.get_hi_pos();
+ p.bump();
+ let lit = @spanned(lo, hi, ast::lit_nil);
+ ret mk_expr(p, lo, hi, ast::expr_lit(lit));
+ }
+ _ {/* fall through */ }
}
- auto e = parse_expr(p);
+ let e = parse_expr(p);
hi = p.get_hi_pos();
expect(p, token::RPAREN);
ret mk_expr(p, lo, hi, e.node);
} else if (p.peek() == token::LBRACE) {
p.bump();
- if (is_word(p, "mutable") ||
- is_plain_ident(p) && p.look_ahead(1u) == token::COLON) {
- auto fields = ~[parse_field(p, token::COLON)];
- auto base = none;
+ if is_word(p, "mutable") ||
+ is_plain_ident(p) && p.look_ahead(1u) == token::COLON {
+ let fields = ~[parse_field(p, token::COLON)];
+ let base = none;
while p.peek() != token::RBRACE {
- if eat_word(p, "with") {
- base = some(parse_expr(p));
- break;
- }
+ if eat_word(p, "with") { base = some(parse_expr(p)); break; }
expect(p, token::COMMA);
fields += ~[parse_field(p, token::COLON)];
}
@@ -809,7 +795,7 @@
expect(p, token::RBRACE);
ex = ast::expr_rec(fields, base);
} else {
- auto blk = parse_block_tail(p, lo);
+ let blk = parse_block_tail(p, lo);
ret mk_expr(p, blk.span.lo, blk.span.hi, ast::expr_block(blk));
}
} else if (eat_word(p, "if")) {
@@ -832,64 +818,63 @@
ret parse_fn_expr(p, ast::proto_closure);
} else if (p.peek() == token::LBRACKET) {
p.bump();
- auto mut = parse_mutability(p);
- auto es = parse_seq_to_end(token::RBRACKET, some(token::COMMA),
- parse_expr, p);
+ let mut = parse_mutability(p);
+ let es =
+ parse_seq_to_end(token::RBRACKET, some(token::COMMA), parse_expr,
+ p);
ex = ast::expr_vec(es, mut, ast::sk_rc);
} else if (p.peek() == token::POUND_LT) {
p.bump();
- auto ty = parse_ty(p);
+ let ty = parse_ty(p);
expect(p, token::GT);
+
/* hack: early return to take advantage of specialized function */
ret mk_mac_expr(p, lo, p.get_hi_pos(), ast::mac_embed_type(ty))
} else if (p.peek() == token::POUND_LBRACE) {
p.bump();
- auto blk = ast::mac_embed_block(parse_block_tail(p, lo));
+ let blk = ast::mac_embed_block(parse_block_tail(p, lo));
ret mk_mac_expr(p, lo, p.get_hi_pos(), blk);
} else if (p.peek() == token::ELLIPSIS) {
p.bump();
ret mk_mac_expr(p, lo, p.get_hi_pos(), ast::mac_ellipsis)
} else if (p.peek() == token::TILDE) {
p.bump();
- alt (p.peek()) {
- case (token::LBRACKET) { // unique array (temporary)
- p.bump();
- auto mut = parse_mutability(p);
- auto es = parse_seq_to_end
- (token::RBRACKET, some(token::COMMA), parse_expr, p);
- ex = ast::expr_vec(es, mut, ast::sk_unique);
- }
- case (token::LIT_STR(?s)) {
- p.bump();
- auto lit =
- @rec(node=ast::lit_str(p.get_str(s), ast::sk_unique),
- span=p.get_span());
- ex = ast::expr_lit(lit);
- }
- case (_) {
- p.fatal("unimplemented: unique pointer creation");
- }
+ alt p.peek() {
+ token::LBRACKET. { // unique array (temporary)
+ p.bump();
+ let mut = parse_mutability(p);
+ let es =
+ parse_seq_to_end(token::RBRACKET, some(token::COMMA),
+ parse_expr, p);
+ ex = ast::expr_vec(es, mut, ast::sk_unique);
+ }
+ token::LIT_STR(s) {
+ p.bump();
+ let lit =
+ @{node: ast::lit_str(p.get_str(s), ast::sk_unique),
+ span: p.get_span()};
+ ex = ast::expr_lit(lit);
+ }
+ _ { p.fatal("unimplemented: unique pointer creation"); }
}
} else if (eat_word(p, "obj")) {
// Anonymous object
// Only make people type () if they're actually adding new fields
- let option::t[ast::anon_obj_field[]] fields = none;
- if (p.peek() == token::LPAREN) {
+ let fields: option::t[ast::anon_obj_field[]] = none;
+ if p.peek() == token::LPAREN {
p.bump();
fields =
some(parse_seq_to_end(token::RPAREN, some(token::COMMA),
- parse_anon_obj_field, p));
+ parse_anon_obj_field, p));
}
- let (@ast::method)[] meths = ~[];
- let option::t[@ast::expr] with_obj = none;
+ let meths: (@ast::method)[] = ~[];
+ let with_obj: option::t[@ast::expr] = none;
expect(p, token::LBRACE);
- while (p.peek() != token::RBRACE) {
- if (eat_word(p, "with")) {
+ while p.peek() != token::RBRACE {
+ if eat_word(p, "with") {
with_obj = some(parse_expr(p));
- } else {
- meths += ~[parse_method(p)];
- }
+ } else { meths += ~[parse_method(p)]; }
}
hi = p.get_hi_pos();
expect(p, token::RBRACE);
@@ -899,44 +884,42 @@
// We don't need to pull ".node" out of fields because it's not a
// "spanned".
- let ast::anon_obj ob =
- rec(fields=fields, methods=meths, with_obj=with_obj);
+ let ob: ast::anon_obj =
+ {fields: fields, methods: meths, with_obj: with_obj};
ex = ast::expr_anon_obj(ob);
} else if (eat_word(p, "bind")) {
- auto e = parse_expr_res(p, RESTRICT_NO_CALL_EXPRS);
- fn parse_expr_opt(&parser p) -> option::t[@ast::expr] {
- alt (p.peek()) {
- case (token::UNDERSCORE) { p.bump(); ret none; }
- case (_) { ret some(parse_expr(p)); }
+ let e = parse_expr_res(p, RESTRICT_NO_CALL_EXPRS);
+ fn parse_expr_opt(p: &parser) -> option::t[@ast::expr] {
+ alt p.peek() {
+ token::UNDERSCORE. { p.bump(); ret none; }
+ _ { ret some(parse_expr(p)); }
}
}
- auto es = parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA),
- parse_expr_opt, p);
+ let es =
+ parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA),
+ parse_expr_opt, p);
hi = es.span.hi;
ex = ast::expr_bind(e, es.node);
} else if (p.peek() == token::POUND) {
- auto ex_ext = parse_syntax_ext(p);
+ let ex_ext = parse_syntax_ext(p);
hi = ex_ext.span.hi;
ex = ex_ext.node;
} else if (eat_word(p, "fail")) {
- if (can_begin_expr(p.peek())) {
- auto e = parse_expr(p);
+ if can_begin_expr(p.peek()) {
+ let e = parse_expr(p);
hi = e.span.hi;
ex = ast::expr_fail(some(e));
- }
- else {
- ex = ast::expr_fail(none);
- }
+ } else { ex = ast::expr_fail(none); }
} else if (eat_word(p, "log")) {
- auto e = parse_expr(p);
+ let e = parse_expr(p);
ex = ast::expr_log(1, e);
hi = e.span.hi;
} else if (eat_word(p, "log_err")) {
- auto e = parse_expr(p);
+ let e = parse_expr(p);
ex = ast::expr_log(0, e);
hi = e.span.hi;
} else if (eat_word(p, "assert")) {
- auto e = parse_expr(p);
+ let e = parse_expr(p);
ex = ast::expr_assert(e);
hi = e.span.hi;
} else if (eat_word(p, "check")) {
@@ -944,7 +927,7 @@
arguments that are all either slot variables or literals.
but the typechecker enforces that. */
- auto e = parse_expr(p);
+ let e = parse_expr(p);
hi = e.span.hi;
ex = ast::expr_check(ast::checked, e);
} else if (eat_word(p, "claim")) {
@@ -952,18 +935,15 @@
is enabled (a command-line flag), then the parser turns
claims into check */
- auto e = parse_expr(p);
+ let e = parse_expr(p);
hi = e.span.hi;
ex = ast::expr_check(ast::unchecked, e);
} else if (eat_word(p, "ret")) {
- if (can_begin_expr(p.peek())) {
- auto e = parse_expr(p);
+ if can_begin_expr(p.peek()) {
+ let e = parse_expr(p);
hi = e.span.hi;
ex = ast::expr_ret(some(e));
- }
- else {
- ex = ast::expr_ret(none);
- }
+ } else { ex = ast::expr_ret(none); }
} else if (eat_word(p, "break")) {
ex = ast::expr_break;
hi = p.get_hi_pos();
@@ -971,25 +951,26 @@
ex = ast::expr_cont;
hi = p.get_hi_pos();
} else if (eat_word(p, "put")) {
- alt (p.peek()) {
- case (token::SEMI) { ex = ast::expr_put(none); }
- case (_) {
- auto e = parse_expr(p);
- hi = e.span.hi;
- ex = ast::expr_put(some(e));
- }
+ alt p.peek() {
+ token::SEMI. { ex = ast::expr_put(none); }
+ _ {
+ let e = parse_expr(p);
+ hi = e.span.hi;
+ ex = ast::expr_put(some(e));
+ }
}
} else if (eat_word(p, "be")) {
- auto e = parse_expr(p);
+ let e = parse_expr(p);
+
// FIXME: Is this the right place for this check?
- if (/*check*/ast::is_call_expr(e)) {
+ if /*check*/ast::is_call_expr(e) {
hi = e.span.hi;
ex = ast::expr_be(e);
} else { p.fatal("Non-call expression in tail call"); }
} else if (eat_word(p, "port")) {
- auto ty = none;
- if(token::LBRACKET == p.peek()) {
+ let ty = none;
+ if token::LBRACKET == p.peek() {
expect(p, token::LBRACKET);
ty = some(parse_ty(p));
expect(p, token::RBRACKET);
@@ -1000,7 +981,7 @@
ex = ast::expr_port(ty);
} else if (eat_word(p, "chan")) {
expect(p, token::LPAREN);
- auto e = parse_expr(p);
+ let e = parse_expr(p);
hi = e.span.hi;
expect(p, token::RPAREN);
ex = ast::expr_chan(e);
@@ -1009,536 +990,528 @@
expect(p, token::DOT);
// The rest is a call expression.
- let @ast::expr f = parse_self_method(p);
- auto es = parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA),
- parse_expr, p);
+ let f: @ast::expr = parse_self_method(p);
+ let es =
+ parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA),
+ parse_expr, p);
hi = es.span.hi;
ex = ast::expr_call(f, es.node);
} else if (p.peek() == token::MOD_SEP ||
- (is_ident(p.peek()) && !is_word(p, "true") &&
- !is_word(p, "false"))) {
+ is_ident(p.peek()) && !is_word(p, "true") &&
+ !is_word(p, "false")) {
check_bad_word(p);
- auto pth = parse_path_and_ty_param_substs(p);
+ let pth = parse_path_and_ty_param_substs(p);
hi = pth.span.hi;
ex = ast::expr_path(pth);
} else {
- auto lit = parse_lit(p);
+ let lit = parse_lit(p);
hi = lit.span.hi;
ex = ast::expr_lit(@lit);
}
ret mk_expr(p, lo, hi, ex);
}
-fn parse_syntax_ext(&parser p) -> @ast::expr {
- auto lo = p.get_lo_pos();
+fn parse_syntax_ext(p: &parser) -> @ast::expr {
+ let lo = p.get_lo_pos();
expect(p, token::POUND);
ret parse_syntax_ext_naked(p, lo);
}
-fn parse_syntax_ext_naked(&parser p, uint lo) -> @ast::expr {
- auto pth = parse_path(p);
- if (ivec::len(pth.node.idents) == 0u) {
+fn parse_syntax_ext_naked(p: &parser, lo: uint) -> @ast::expr {
+ let pth = parse_path(p);
+ if ivec::len(pth.node.idents) == 0u {
p.fatal("expected a syntax expander name");
}
- auto es = parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA),
- parse_expr, p);
- auto hi = es.span.hi;
+ let es =
+ parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA),
+ parse_expr, p);
+ let hi = es.span.hi;
ret mk_mac_expr(p, lo, hi, ast::mac_invoc(pth, es.node, none));
}
-fn parse_self_method(&parser p) -> @ast::expr {
- auto sp = p.get_span();
- let ast::ident f_name = parse_ident(p);
+fn parse_self_method(p: &parser) -> @ast::expr {
+ let sp = p.get_span();
+ let f_name: ast::ident = parse_ident(p);
ret mk_expr(p, sp.lo, sp.hi, ast::expr_self_method(f_name));
}
-fn parse_dot_or_call_expr(&parser p) -> @ast::expr {
+fn parse_dot_or_call_expr(p: &parser) -> @ast::expr {
ret parse_dot_or_call_expr_with(p, parse_bottom_expr(p));
}
-fn parse_dot_or_call_expr_with(&parser p, @ast::expr e) -> @ast::expr {
- auto lo = e.span.lo;
- auto hi = e.span.hi;
- while (true) {
- alt (p.peek()) {
- case (token::LPAREN) {
- if (p.get_restriction() == RESTRICT_NO_CALL_EXPRS) {
- ret e;
- } else {
- // Call expr.
+fn parse_dot_or_call_expr_with(p: &parser, e: @ast::expr) -> @ast::expr {
+ let lo = e.span.lo;
+ let hi = e.span.hi;
+ while true {
+ alt p.peek() {
+ token::LPAREN. {
+ if p.get_restriction() == RESTRICT_NO_CALL_EXPRS {
+ ret e;
+ } else {
+ // Call expr.
- auto es = parse_seq(token::LPAREN, token::RPAREN,
- some(token::COMMA), parse_expr, p);
- hi = es.span.hi;
- e = mk_expr(p, lo, hi, ast::expr_call(e, es.node));
- }
+ let es =
+ parse_seq(token::LPAREN, token::RPAREN,
+ some(token::COMMA), parse_expr, p);
+ hi = es.span.hi;
+ e = mk_expr(p, lo, hi, ast::expr_call(e, es.node));
}
- case (token::DOT) {
+ }
+ token::DOT. {
+ p.bump();
+ alt p.peek() {
+ token::IDENT(i, _) {
+ hi = p.get_hi_pos();
p.bump();
- alt (p.peek()) {
- case (token::IDENT(?i, _)) {
- hi = p.get_hi_pos();
- p.bump();
- e = mk_expr(p, lo, hi,
- ast::expr_field(e, p.get_str(i)));
- }
- case (token::LPAREN) {
- p.bump();
- auto ix = parse_expr(p);
- hi = ix.span.hi;
- expect(p, token::RPAREN);
- e = mk_expr(p, lo, hi, ast::expr_index(e, ix));
- }
- case (?t) { unexpected(p, t); }
- }
+ e = mk_expr(p, lo, hi, ast::expr_field(e, p.get_str(i)));
+ }
+ token::LPAREN. {
+ p.bump();
+ let ix = parse_expr(p);
+ hi = ix.span.hi;
+ expect(p, token::RPAREN);
+ e = mk_expr(p, lo, hi, ast::expr_index(e, ix));
+ }
+ t { unexpected(p, t); }
}
- case (_) { ret e; }
+ }
+ _ { ret e; }
}
}
ret e;
}
-fn parse_prefix_expr(&parser p) -> @ast::expr {
- if (eat_word(p, "mutable")) {
+fn parse_prefix_expr(p: &parser) -> @ast::expr {
+ if eat_word(p, "mutable") {
p.warn("ignoring deprecated 'mutable' prefix operator");
}
- auto lo = p.get_lo_pos();
- auto hi = p.get_hi_pos();
+ let lo = p.get_lo_pos();
+ let hi = p.get_hi_pos();
// FIXME: can only remove this sort of thing when both typestate and
// alt-exhaustive-match checking are co-operating.
- auto lit = @spanned(lo, lo, ast::lit_nil);
- let ast::expr_ ex = ast::expr_lit(lit);
- alt (p.peek()) {
- case (token::NOT) {
+ let lit = @spanned(lo, lo, ast::lit_nil);
+ let ex: ast::expr_ = ast::expr_lit(lit);
+ alt p.peek() {
+ token::NOT. {
+ p.bump();
+ let e = parse_prefix_expr(p);
+ hi = e.span.hi;
+ ex = ast::expr_unary(ast::not, e);
+ }
+ token::BINOP(b) {
+ alt b {
+ token::MINUS. {
p.bump();
- auto e = parse_prefix_expr(p);
+ let e = parse_prefix_expr(p);
hi = e.span.hi;
- ex = ast::expr_unary(ast::not, e);
- }
- case (token::BINOP(?b)) {
- alt (b) {
- case (token::MINUS) {
- p.bump();
- auto e = parse_prefix_expr(p);
- hi = e.span.hi;
- ex = ast::expr_unary(ast::neg, e);
- }
- case (token::STAR) {
- p.bump();
- auto e = parse_prefix_expr(p);
- hi = e.span.hi;
- ex = ast::expr_unary(ast::deref, e);
- }
- case (_) { ret parse_dot_or_call_expr(p); }
- }
- }
- case (token::AT) {
+ ex = ast::expr_unary(ast::neg, e);
+ }
+ token::STAR. {
p.bump();
- auto m = parse_mutability(p);
- auto e = parse_prefix_expr(p);
+ let e = parse_prefix_expr(p);
hi = e.span.hi;
- ex = ast::expr_unary(ast::box(m), e);
+ ex = ast::expr_unary(ast::deref, e);
+ }
+ _ { ret parse_dot_or_call_expr(p); }
}
- case (_) { ret parse_dot_or_call_expr(p); }
+ }
+ token::AT. {
+ p.bump();
+ let m = parse_mutability(p);
+ let e = parse_prefix_expr(p);
+ hi = e.span.hi;
+ ex = ast::expr_unary(ast::box(m), e);
+ }
+ _ { ret parse_dot_or_call_expr(p); }
}
ret mk_expr(p, lo, hi, ex);
}
-fn parse_ternary(&parser p) -> @ast::expr {
- auto cond_expr = parse_binops(p);
- if (p.peek() == token::QUES) {
+fn parse_ternary(p: &parser) -> @ast::expr {
+ let cond_expr = parse_binops(p);
+ if p.peek() == token::QUES {
p.bump();
- auto then_expr = parse_expr(p);
+ let then_expr = parse_expr(p);
expect(p, token::COLON);
- auto else_expr = parse_expr(p);
+ let else_expr = parse_expr(p);
ret mk_expr(p, cond_expr.span.lo, else_expr.span.hi,
ast::expr_ternary(cond_expr, then_expr, else_expr));
- } else {
- ret cond_expr;
- }
+ } else { ret cond_expr; }
}
-type op_spec = rec(token::token tok, ast::binop op, int prec);
+type op_spec = {tok: token::token, op: ast::binop, prec: int};
// FIXME make this a const, don't store it in parser state
fn prec_table() -> @op_spec[] {
- ret @~[rec(tok=token::BINOP(token::STAR), op=ast::mul, prec=11),
- rec(tok=token::BINOP(token::SLASH), op=ast::div, prec=11),
- rec(tok=token::BINOP(token::PERCENT), op=ast::rem, prec=11),
- rec(tok=token::BINOP(token::PLUS), op=ast::add, prec=10),
- rec(tok=token::BINOP(token::MINUS), op=ast::sub, prec=10),
- rec(tok=token::BINOP(token::LSL), op=ast::lsl, prec=9),
- rec(tok=token::BINOP(token::LSR), op=ast::lsr, prec=9),
- rec(tok=token::BINOP(token::ASR), op=ast::asr, prec=9),
- rec(tok=token::BINOP(token::AND), op=ast::bitand, prec=8),
- rec(tok=token::BINOP(token::CARET), op=ast::bitxor, prec=6),
- rec(tok=token::BINOP(token::OR), op=ast::bitor, prec=6),
+ ret @~[{tok: token::BINOP(token::STAR), op: ast::mul, prec: 11},
+ {tok: token::BINOP(token::SLASH), op: ast::div, prec: 11},
+ {tok: token::BINOP(token::PERCENT), op: ast::rem, prec: 11},
+ {tok: token::BINOP(token::PLUS), op: ast::add, prec: 10},
+ {tok: token::BINOP(token::MINUS), op: ast::sub, prec: 10},
+ {tok: token::BINOP(token::LSL), op: ast::lsl, prec: 9},
+ {tok: token::BINOP(token::LSR), op: ast::lsr, prec: 9},
+ {tok: token::BINOP(token::ASR), op: ast::asr, prec: 9},
+ {tok: token::BINOP(token::AND), op: ast::bitand, prec: 8},
+ {tok: token::BINOP(token::CARET), op: ast::bitxor, prec: 6},
+ {tok: token::BINOP(token::OR), op: ast::bitor, prec: 6},
// 'as' sits between here with 5
- rec(tok=token::LT, op=ast::lt, prec=4),
- rec(tok=token::LE, op=ast::le, prec=4),
- rec(tok=token::GE, op=ast::ge, prec=4),
- rec(tok=token::GT, op=ast::gt, prec=4),
- rec(tok=token::EQEQ, op=ast::eq, prec=3),
- rec(tok=token::NE, op=ast::ne, prec=3),
- rec(tok=token::ANDAND, op=ast::and, prec=2),
- rec(tok=token::OROR, op=ast::or, prec=1)];
+ {tok: token::LT, op: ast::lt, prec: 4},
+ {tok: token::LE, op: ast::le, prec: 4},
+ {tok: token::GE, op: ast::ge, prec: 4},
+ {tok: token::GT, op: ast::gt, prec: 4},
+ {tok: token::EQEQ, op: ast::eq, prec: 3},
+ {tok: token::NE, op: ast::ne, prec: 3},
+ {tok: token::ANDAND, op: ast::and, prec: 2},
+ {tok: token::OROR, op: ast::or, prec: 1}];
}
-fn parse_binops(&parser p) -> @ast::expr {
+fn parse_binops(p: &parser) -> @ast::expr {
ret parse_more_binops(p, parse_prefix_expr(p), 0);
}
-const int unop_prec = 100;
+const unop_prec: int = 100;
-const int as_prec = 5;
-const int ternary_prec = 0;
+const as_prec: int = 5;
+const ternary_prec: int = 0;
-fn parse_more_binops(&parser p, @ast::expr lhs, int min_prec) -> @ast::expr {
- auto peeked = p.peek();
- for (op_spec cur in *p.get_prec_table()) {
- if (cur.prec > min_prec && cur.tok == peeked) {
+fn parse_more_binops(p: &parser, lhs: @ast::expr, min_prec: int) ->
+ @ast::expr {
+ let peeked = p.peek();
+ for cur: op_spec in *p.get_prec_table() {
+ if cur.prec > min_prec && cur.tok == peeked {
p.bump();
- auto rhs = parse_more_binops(p, parse_prefix_expr(p), cur.prec);
- auto bin = mk_expr(p, lhs.span.lo, rhs.span.hi,
- ast::expr_binary(cur.op, lhs, rhs));
+ let rhs = parse_more_binops(p, parse_prefix_expr(p), cur.prec);
+ let bin =
+ mk_expr(p, lhs.span.lo, rhs.span.hi,
+ ast::expr_binary(cur.op, lhs, rhs));
ret parse_more_binops(p, bin, min_prec);
}
}
- if (as_prec > min_prec && eat_word(p, "as")) {
- auto rhs = parse_ty(p);
- auto _as = mk_expr(p, lhs.span.lo, rhs.span.hi,
- ast::expr_cast(lhs, rhs));
+ if as_prec > min_prec && eat_word(p, "as") {
+ let rhs = parse_ty(p);
+ let _as =
+ mk_expr(p, lhs.span.lo, rhs.span.hi, ast::expr_cast(lhs, rhs));
ret parse_more_binops(p, _as, min_prec);
}
ret lhs;
}
-fn parse_assign_expr(&parser p) -> @ast::expr {
- auto lo = p.get_lo_pos();
- auto lhs = parse_ternary(p);
- alt (p.peek()) {
- case (token::EQ) {
- p.bump();
- auto rhs = parse_expr(p);
- ret mk_expr(p, lo, rhs.span.hi, ast::expr_assign(lhs, rhs));
+fn parse_assign_expr(p: &parser) -> @ast::expr {
+ let lo = p.get_lo_pos();
+ let lhs = parse_ternary(p);
+ alt p.peek() {
+ token::EQ. {
+ p.bump();
+ let rhs = parse_expr(p);
+ ret mk_expr(p, lo, rhs.span.hi, ast::expr_assign(lhs, rhs));
+ }
+ token::BINOPEQ(op) {
+ p.bump();
+ let rhs = parse_expr(p);
+ let aop = ast::add;
+ alt op {
+ token::PLUS. { aop = ast::add; }
+ token::MINUS. { aop = ast::sub; }
+ token::STAR. { aop = ast::mul; }
+ token::SLASH. { aop = ast::div; }
+ token::PERCENT. { aop = ast::rem; }
+ token::CARET. { aop = ast::bitxor; }
+ token::AND. { aop = ast::bitand; }
+ token::OR. { aop = ast::bitor; }
+ token::LSL. { aop = ast::lsl; }
+ token::LSR. { aop = ast::lsr; }
+ token::ASR. { aop = ast::asr; }
}
- case (token::BINOPEQ(?op)) {
- p.bump();
- auto rhs = parse_expr(p);
- auto aop = ast::add;
- alt (op) {
- case (token::PLUS) { aop = ast::add; }
- case (token::MINUS) { aop = ast::sub; }
- case (token::STAR) { aop = ast::mul; }
- case (token::SLASH) { aop = ast::div; }
- case (token::PERCENT) { aop = ast::rem; }
- case (token::CARET) { aop = ast::bitxor; }
- case (token::AND) { aop = ast::bitand; }
- case (token::OR) { aop = ast::bitor; }
- case (token::LSL) { aop = ast::lsl; }
- case (token::LSR) { aop = ast::lsr; }
- case (token::ASR) { aop = ast::asr; }
- }
- ret mk_expr(p, lo, rhs.span.hi,
- ast::expr_assign_op(aop, lhs, rhs));
- }
- case (token::LARROW) {
- p.bump();
- auto rhs = parse_expr(p);
- ret mk_expr(p, lo, rhs.span.hi, ast::expr_move(lhs, rhs));
- }
- case (token::SEND) {
- p.bump();
- auto rhs = parse_expr(p);
- ret mk_expr(p, lo, rhs.span.hi, ast::expr_send(lhs, rhs));
- }
- case (token::RECV) {
- p.bump();
- auto rhs = parse_expr(p);
- ret mk_expr(p, lo, rhs.span.hi, ast::expr_recv(lhs, rhs));
- }
- case (token::DARROW) {
- p.bump();
- auto rhs = parse_expr(p);
- ret mk_expr(p, lo, rhs.span.hi, ast::expr_swap(lhs, rhs));
- }
- case (_) {/* fall through */ }
+ ret mk_expr(p, lo, rhs.span.hi, ast::expr_assign_op(aop, lhs, rhs));
+ }
+ token::LARROW. {
+ p.bump();
+ let rhs = parse_expr(p);
+ ret mk_expr(p, lo, rhs.span.hi, ast::expr_move(lhs, rhs));
+ }
+ token::SEND. {
+ p.bump();
+ let rhs = parse_expr(p);
+ ret mk_expr(p, lo, rhs.span.hi, ast::expr_send(lhs, rhs));
+ }
+ token::RECV. {
+ p.bump();
+ let rhs = parse_expr(p);
+ ret mk_expr(p, lo, rhs.span.hi, ast::expr_recv(lhs, rhs));
+ }
+ token::DARROW. {
+ p.bump();
+ let rhs = parse_expr(p);
+ ret mk_expr(p, lo, rhs.span.hi, ast::expr_swap(lhs, rhs));
+ }
+ _ {/* fall through */ }
}
ret lhs;
}
-fn parse_if_expr_1(&parser p) -> rec(@ast::expr cond,
- ast::blk then,
- option::t[@ast::expr] els,
- uint lo, uint hi) {
- auto lo = p.get_last_lo_pos();
- auto cond = parse_expr(p);
- auto thn = parse_block(p);
- let option::t[@ast::expr] els = none;
- auto hi = thn.span.hi;
- if (eat_word(p, "else")) {
- auto elexpr = parse_else_expr(p);
+fn parse_if_expr_1(p: &parser) ->
+ {cond: @ast::expr,
+ then: ast::blk,
+ els: option::t[@ast::expr],
+ lo: uint,
+ hi: uint} {
+ let lo = p.get_last_lo_pos();
+ let cond = parse_expr(p);
+ let thn = parse_block(p);
+ let els: option::t[@ast::expr] = none;
+ let hi = thn.span.hi;
+ if eat_word(p, "else") {
+ let elexpr = parse_else_expr(p);
els = some(elexpr);
hi = elexpr.span.hi;
}
- ret rec(cond=cond, then=thn, els=els, lo=lo, hi=hi);
+ ret {cond: cond, then: thn, els: els, lo: lo, hi: hi};
}
-fn parse_if_expr(&parser p) -> @ast::expr {
- if (eat_word(p, "check")) {
- auto q = parse_if_expr_1(p);
- ret mk_expr(p, q.lo, q.hi,
- ast::expr_if_check(q.cond, q.then, q.els));
- }
- else {
- auto q = parse_if_expr_1(p);
+fn parse_if_expr(p: &parser) -> @ast::expr {
+ if eat_word(p, "check") {
+ let q = parse_if_expr_1(p);
+ ret mk_expr(p, q.lo, q.hi, ast::expr_if_check(q.cond, q.then, q.els));
+ } else {
+ let q = parse_if_expr_1(p);
ret mk_expr(p, q.lo, q.hi, ast::expr_if(q.cond, q.then, q.els));
}
}
-fn parse_fn_expr(&parser p, ast::proto proto) -> @ast::expr {
- auto lo = p.get_last_lo_pos();
- auto decl = parse_fn_decl(p, ast::impure_fn);
- auto body = parse_block(p);
- auto _fn = rec(decl=decl, proto=proto, body=body);
+fn parse_fn_expr(p: &parser, proto: ast::proto) -> @ast::expr {
+ let lo = p.get_last_lo_pos();
+ let decl = parse_fn_decl(p, ast::impure_fn);
+ let body = parse_block(p);
+ let _fn = {decl: decl, proto: proto, body: body};
ret mk_expr(p, lo, body.span.hi, ast::expr_fn(_fn));
}
-fn parse_else_expr(&parser p) -> @ast::expr {
- if (eat_word(p, "if")) {
+fn parse_else_expr(p: &parser) -> @ast::expr {
+ if eat_word(p, "if") {
ret parse_if_expr(p);
} else {
- auto blk = parse_block(p);
+ let blk = parse_block(p);
ret mk_expr(p, blk.span.lo, blk.span.hi, ast::expr_block(blk));
}
}
-fn parse_for_expr(&parser p) -> @ast::expr {
- auto lo = p.get_last_lo_pos();
- auto is_each = eat_word(p, "each");
- auto decl = parse_local(p, false);
+fn parse_for_expr(p: &parser) -> @ast::expr {
+ let lo = p.get_last_lo_pos();
+ let is_each = eat_word(p, "each");
+ let decl = parse_local(p, false);
expect_word(p, "in");
- auto seq = parse_expr(p);
- auto body = parse_block(p);
- auto hi = body.span.hi;
+ let seq = parse_expr(p);
+ let body = parse_block(p);
+ let hi = body.span.hi;
if is_each {
ret mk_expr(p, lo, hi, ast::expr_for_each(decl, seq, body));
- } else {
- ret mk_expr(p, lo, hi, ast::expr_for(decl, seq, body));
- }
+ } else { ret mk_expr(p, lo, hi, ast::expr_for(decl, seq, body)); }
}
-fn parse_while_expr(&parser p) -> @ast::expr {
- auto lo = p.get_last_lo_pos();
- auto cond = parse_expr(p);
- auto body = parse_block(p);
- auto hi = body.span.hi;
+fn parse_while_expr(p: &parser) -> @ast::expr {
+ let lo = p.get_last_lo_pos();
+ let cond = parse_expr(p);
+ let body = parse_block(p);
+ let hi = body.span.hi;
ret mk_expr(p, lo, hi, ast::expr_while(cond, body));
}
-fn parse_do_while_expr(&parser p) -> @ast::expr {
- auto lo = p.get_last_lo_pos();
- auto body = parse_block(p);
+fn parse_do_while_expr(p: &parser) -> @ast::expr {
+ let lo = p.get_last_lo_pos();
+ let body = parse_block(p);
expect_word(p, "while");
- auto cond = parse_expr(p);
- auto hi = cond.span.hi;
+ let cond = parse_expr(p);
+ let hi = cond.span.hi;
ret mk_expr(p, lo, hi, ast::expr_do_while(body, cond));
}
-fn parse_alt_expr(&parser p) -> @ast::expr {
- auto lo = p.get_last_lo_pos();
- auto discriminant = parse_expr(p);
+fn parse_alt_expr(p: &parser) -> @ast::expr {
+ let lo = p.get_last_lo_pos();
+ let discriminant = parse_expr(p);
expect(p, token::LBRACE);
- let ast::arm[] arms = ~[];
- while (p.peek() != token::RBRACE) {
+ let arms: ast::arm[] = ~[];
+ while p.peek() != token::RBRACE {
// Optionally eat the case keyword.
// FIXME remove this (and the optional parens) once we've updated our
// code to not use the old syntax
eat_word(p, "case");
- auto parens = false;
- if (p.peek() == token::LPAREN) { parens = true; p.bump(); }
- auto pats = parse_pats(p);
- if (parens) { expect(p, token::RPAREN); }
- auto blk = parse_block(p);
- arms += ~[rec(pats=pats, block=blk)];
+ let parens = false;
+ if p.peek() == token::LPAREN { parens = true; p.bump(); }
+ let pats = parse_pats(p);
+ if parens { expect(p, token::RPAREN); }
+ let blk = parse_block(p);
+ arms += ~[{pats: pats, block: blk}];
}
- auto hi = p.get_hi_pos();
+ let hi = p.get_hi_pos();
p.bump();
ret mk_expr(p, lo, hi, ast::expr_alt(discriminant, arms));
}
-fn parse_spawn_expr(&parser p) -> @ast::expr {
- auto lo = p.get_last_lo_pos();
+fn parse_spawn_expr(p: &parser) -> @ast::expr {
+ let lo = p.get_last_lo_pos();
// FIXME: Parse domain and name
// FIXME: why no full expr?
- auto fn_expr = parse_bottom_expr(p);
- auto es = parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA),
- parse_expr, p);
- auto hi = es.span.hi;
- ret mk_expr(p, lo, hi, ast::expr_spawn
- (ast::dom_implicit, option::none, fn_expr, es.node));
+ let fn_expr = parse_bottom_expr(p);
+ let es =
+ parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA),
+ parse_expr, p);
+ let hi = es.span.hi;
+ ret mk_expr(p, lo, hi,
+ ast::expr_spawn(ast::dom_implicit, option::none, fn_expr,
+ es.node));
}
-fn parse_expr(&parser p) -> @ast::expr {
+fn parse_expr(p: &parser) -> @ast::expr {
ret parse_expr_res(p, UNRESTRICTED);
}
-fn parse_expr_res(&parser p, restriction r) -> @ast::expr {
- auto old = p.get_restriction();
+fn parse_expr_res(p: &parser, r: restriction) -> @ast::expr {
+ let old = p.get_restriction();
p.restrict(r);
- auto e = parse_assign_expr(p);
+ let e = parse_assign_expr(p);
p.restrict(old);
ret e;
}
-fn parse_initializer(&parser p) -> option::t[ast::initializer] {
- alt (p.peek()) {
- case (token::EQ) {
- p.bump();
- ret some(rec(op=ast::init_assign, expr=parse_expr(p)));
- }
- case (token::LARROW) {
- p.bump();
- ret some(rec(op=ast::init_move, expr=parse_expr(p)));
- }
- // Now that the the channel is the first argument to receive,
- // combining it with an initializer doesn't really make sense.
- // case (token::RECV) {
- // p.bump();
- // ret some(rec(op = ast::init_recv,
- // expr = parse_expr(p)));
- // }
- case (_) {
- ret none;
- }
+fn parse_initializer(p: &parser) -> option::t[ast::initializer] {
+ alt p.peek() {
+ token::EQ. {
+ p.bump();
+ ret some({op: ast::init_assign, expr: parse_expr(p)});
+ }
+ token::LARROW. {
+ p.bump();
+ ret some({op: ast::init_move, expr: parse_expr(p)});
+ }
+
+ // Now that the the channel is the first argument to receive,
+ // combining it with an initializer doesn't really make sense.
+ // case (token::RECV) {
+ // p.bump();
+ // ret some(rec(op = ast::init_recv,
+ // expr = parse_expr(p)));
+ // }
+ _ {
+ ret none;
+ }
}
}
-fn parse_pats(&parser p) -> (@ast::pat)[] {
- auto pats = ~[];
- while (true) {
+fn parse_pats(p: &parser) -> (@ast::pat)[] {
+ let pats = ~[];
+ while true {
pats += ~[parse_pat(p)];
- if (p.peek() == token::BINOP(token::OR)) {
- p.bump();
- } else {
- break;
- }
+ if p.peek() == token::BINOP(token::OR) { p.bump(); } else { break; }
}
ret pats;
}
-fn parse_pat(&parser p) -> @ast::pat {
- auto lo = p.get_lo_pos();
- auto hi = p.get_hi_pos();
- auto pat;
- alt (p.peek()) {
- case (token::UNDERSCORE) {
- p.bump();
- pat = ast::pat_wild;
- }
- case (token::AT) {
- p.bump();
- auto sub = parse_pat(p);
- pat = ast::pat_box(sub);
- hi = sub.span.hi;
- }
- case (token::LBRACE) {
- p.bump();
- auto fields = ~[];
- auto etc = false;
- auto first = true;
- while (p.peek() != token::RBRACE) {
- if (first) { first = false; }
- else { expect(p, token::COMMA); }
+fn parse_pat(p: &parser) -> @ast::pat {
+ let lo = p.get_lo_pos();
+ let hi = p.get_hi_pos();
+ let pat;
+ alt p.peek() {
+ token::UNDERSCORE. { p.bump(); pat = ast::pat_wild; }
+ token::AT. {
+ p.bump();
+ let sub = parse_pat(p);
+ pat = ast::pat_box(sub);
+ hi = sub.span.hi;
+ }
+ token::LBRACE. {
+ p.bump();
+ let fields = ~[];
+ let etc = false;
+ let first = true;
+ while p.peek() != token::RBRACE {
+ if first { first = false; } else { expect(p, token::COMMA); }
- if (p.peek() == token::UNDERSCORE) {
- p.bump();
- if (p.peek() != token::RBRACE) {
- p.fatal("expecting }, found " +
+ if p.peek() == token::UNDERSCORE {
+ p.bump();
+ if p.peek() != token::RBRACE {
+ p.fatal("expecting }, found " +
token::to_str(p.get_reader(), p.peek()));
- }
- etc = true;
- break;
}
-
- auto fieldname = parse_ident(p);
- auto subpat;
- if (p.peek() == token::COLON) {
- p.bump();
- subpat = parse_pat(p);
- } else {
- if (p.get_bad_expr_words().contains_key(fieldname)) {
- p.fatal("found " + fieldname +
- " in binding position");
- }
- subpat = @rec(id=p.get_id(),
- node=ast::pat_bind(fieldname),
- span=rec(lo=lo, hi=hi));
- }
- fields += ~[rec(ident=fieldname, pat=subpat)];
+ etc = true;
+ break;
}
- hi = p.get_hi_pos();
- p.bump();
- pat = ast::pat_rec(fields, etc);
+
+ let fieldname = parse_ident(p);
+ let subpat;
+ if p.peek() == token::COLON {
+ p.bump();
+ subpat = parse_pat(p);
+ } else {
+ if p.get_bad_expr_words().contains_key(fieldname) {
+ p.fatal("found " + fieldname + " in binding position");
+ }
+ subpat =
+ @{id: p.get_id(),
+ node: ast::pat_bind(fieldname),
+ span: {lo: lo, hi: hi}};
+ }
+ fields += ~[{ident: fieldname, pat: subpat}];
}
- case (?tok) {
- if (!is_ident(tok) || is_word(p, "true") || is_word(p, "false")) {
- auto lit = parse_lit(p);
- hi = lit.span.hi;
- pat = ast::pat_lit(@lit);
- } else if (is_plain_ident(p) &&
+ hi = p.get_hi_pos();
+ p.bump();
+ pat = ast::pat_rec(fields, etc);
+ }
+ tok {
+ if !is_ident(tok) || is_word(p, "true") || is_word(p, "false") {
+ let lit = parse_lit(p);
+ hi = lit.span.hi;
+ pat = ast::pat_lit(@lit);
+ } else if (is_plain_ident(p) &&
alt p.look_ahead(1u) {
- token::DOT | token::LPAREN | token::LBRACKET {
+ token::DOT. | token::LPAREN. | token::LBRACKET. {
false
}
_ { true }
}) {
- hi = p.get_hi_pos();
- pat = ast::pat_bind(parse_ident(p));
- } else {
- auto tag_path = parse_path_and_ty_param_substs(p);
- hi = tag_path.span.hi;
- let (@ast::pat)[] args;
- alt (p.peek()) {
- case (token::LPAREN) {
- auto a = parse_seq(token::LPAREN, token::RPAREN,
- some(token::COMMA), parse_pat, p);
- args = a.node;
- hi = a.span.hi;
- }
- case (token::DOT) {
- args = ~[];
- p.bump();
- }
- case (_) { expect(p, token::LPAREN); fail; }
- }
- pat = ast::pat_tag(tag_path, args);
+ hi = p.get_hi_pos();
+ pat = ast::pat_bind(parse_ident(p));
+ } else {
+ let tag_path = parse_path_and_ty_param_substs(p);
+ hi = tag_path.span.hi;
+ let args: (@ast::pat)[];
+ alt p.peek() {
+ token::LPAREN. {
+ let a =
+ parse_seq(token::LPAREN, token::RPAREN,
+ some(token::COMMA), parse_pat, p);
+ args = a.node;
+ hi = a.span.hi;
+ }
+ token::DOT. { args = ~[]; p.bump(); }
+ _ { expect(p, token::LPAREN); fail; }
}
+ pat = ast::pat_tag(tag_path, args);
}
+ }
}
- ret @rec(id=p.get_id(), node=pat, span=rec(lo=lo, hi=hi));
+ ret @{id: p.get_id(), node: pat, span: {lo: lo, hi: hi}};
}
-fn parse_local(&parser p, bool allow_init) -> @ast::local {
- auto lo = p.get_lo_pos();
- auto ident = parse_value_ident(p);
- auto ty = none;
- if eat(p, token::COLON) {
- ty = some(parse_ty(p));
- }
- auto init = if allow_init { parse_initializer(p) }
- else { none };
+fn parse_local(p: &parser, allow_init: bool) -> @ast::local {
+ let lo = p.get_lo_pos();
+ let ident = parse_value_ident(p);
+ let ty = none;
+ if eat(p, token::COLON) { ty = some(parse_ty(p)); }
+ let init = if allow_init { parse_initializer(p) } else { none };
ret @spanned(lo, p.get_last_hi_pos(),
- rec(ty=ty, infer=false, ident=ident,
- init=init, id=p.get_id()));
+ {ty: ty,
+ infer: false,
+ ident: ident,
+ init: init,
+ id: p.get_id()});
}
-fn parse_let(&parser p) -> @ast::decl {
- auto lo = p.get_lo_pos();
- auto locals = ~[parse_local(p, true)];
+fn parse_let(p: &parser) -> @ast::decl {
+ let lo = p.get_lo_pos();
+ let locals = ~[parse_local(p, true)];
while p.peek() == token::COMMA {
p.bump();
locals += ~[parse_local(p, true)];
@@ -1546,483 +1519,474 @@
ret @spanned(lo, p.get_last_hi_pos(), ast::decl_local(locals));
}
-fn parse_stmt(&parser p) -> @ast::stmt {
- if (p.get_file_type() == SOURCE_FILE) {
+fn parse_stmt(p: &parser) -> @ast::stmt {
+ if p.get_file_type() == SOURCE_FILE {
ret parse_source_stmt(p);
} else { ret parse_crate_stmt(p); }
}
-fn parse_crate_stmt(&parser p) -> @ast::stmt {
- auto cdir = parse_crate_directive(p, ~[]);
+fn parse_crate_stmt(p: &parser) -> @ast::stmt {
+ let cdir = parse_crate_directive(p, ~[]);
ret @spanned(cdir.span.lo, cdir.span.hi,
ast::stmt_crate_directive(@cdir));
}
-fn parse_source_stmt(&parser p) -> @ast::stmt {
- auto lo = p.get_lo_pos();
- if (eat_word(p, "let")) {
- auto decl = parse_let(p);
+fn parse_source_stmt(p: &parser) -> @ast::stmt {
+ let lo = p.get_lo_pos();
+ if eat_word(p, "let") {
+ let decl = parse_let(p);
ret @spanned(lo, decl.span.hi, ast::stmt_decl(decl, p.get_id()));
} else {
- auto item_attrs;
- alt (parse_outer_attrs_or_ext(p)) {
- case (none) {
- item_attrs = ~[];
- }
- case (some(left(?attrs))) {
- item_attrs = attrs;
- }
- case (some(right(?ext))) {
- ret @spanned(lo, ext.span.hi,
- ast::stmt_expr(ext, p.get_id()));
- }
+ let item_attrs;
+ alt parse_outer_attrs_or_ext(p) {
+ none. { item_attrs = ~[]; }
+ some(left(attrs)) { item_attrs = attrs; }
+ some(right(ext)) {
+ ret @spanned(lo, ext.span.hi, ast::stmt_expr(ext, p.get_id()));
+ }
}
- auto maybe_item = parse_item(p, item_attrs);
+ let maybe_item = parse_item(p, item_attrs);
// If we have attributes then we should have an item
- if (ivec::len(item_attrs) > 0u) {
- alt (maybe_item) {
- case (got_item(_)) { /* fallthrough */ }
- case (_) {
- ret p.fatal("expected item");
- }
+ if ivec::len(item_attrs) > 0u {
+ alt maybe_item {
+ got_item(_) {/* fallthrough */ }
+ _ { ret p.fatal("expected item"); }
}
}
- alt (maybe_item) {
- case (got_item(?i)) {
- auto hi = i.span.hi;
- auto decl = @spanned(lo, hi, ast::decl_item(i));
- ret @spanned(lo, hi, ast::stmt_decl(decl, p.get_id()));
- }
- case (fn_no_item) { // parse_item will have already skipped "fn"
- auto e = parse_fn_expr(p, ast::proto_fn);
- e = parse_dot_or_call_expr_with(p, e);
- ret @spanned(lo, e.span.hi, ast::stmt_expr(e, p.get_id()));
- }
- case (no_item) {
- // Remainder are line-expr stmts.
+ alt maybe_item {
+ got_item(i) {
+ let hi = i.span.hi;
+ let decl = @spanned(lo, hi, ast::decl_item(i));
+ ret @spanned(lo, hi, ast::stmt_decl(decl, p.get_id()));
+ }
+ fn_no_item. { // parse_item will have already skipped "fn"
- auto e = parse_expr(p);
- ret @spanned(lo, e.span.hi, ast::stmt_expr(e, p.get_id()));
- }
+ let e = parse_fn_expr(p, ast::proto_fn);
+ e = parse_dot_or_call_expr_with(p, e);
+ ret @spanned(lo, e.span.hi, ast::stmt_expr(e, p.get_id()));
+ }
+ no_item. {
+ // Remainder are line-expr stmts.
+
+ let e = parse_expr(p);
+ ret @spanned(lo, e.span.hi, ast::stmt_expr(e, p.get_id()));
+ }
}
}
p.fatal("expected statement");
fail;
}
-fn stmt_to_expr(@ast::stmt stmt) -> option::t[@ast::expr] {
- ret alt (stmt.node) {
- case (ast::stmt_expr(?e, _)) { some(e) }
- case (_) { none }
- };
+fn stmt_to_expr(stmt: @ast::stmt) -> option::t[@ast::expr] {
+ ret alt stmt.node { ast::stmt_expr(e, _) { some(e) } _ { none } };
}
-fn stmt_ends_with_semi(&ast::stmt stmt) -> bool {
- alt (stmt.node) {
- case (ast::stmt_decl(?d, _)) {
- ret alt (d.node) {
- case (ast::decl_local(_)) { true }
- case (ast::decl_item(_)) { false }
+fn stmt_ends_with_semi(stmt: &ast::stmt) -> bool {
+ alt stmt.node {
+ ast::stmt_decl(d, _) {
+ ret alt d.node {
+ ast::decl_local(_) { true }
+ ast::decl_item(_) { false }
}
- }
- case (ast::stmt_expr(?e, _)) {
- ret alt (e.node) {
- case (ast::expr_vec(_, _, _)) { true }
- case (ast::expr_rec(_, _)) { true }
- case (ast::expr_call(_, _)) { true }
- case (ast::expr_self_method(_)) { false }
- case (ast::expr_bind(_, _)) { true }
- case (ast::expr_spawn(_, _, _, _)) { true }
- case (ast::expr_binary(_, _, _)) { true }
- case (ast::expr_unary(_, _)) { true }
- case (ast::expr_lit(_)) { true }
- case (ast::expr_cast(_, _)) { true }
- case (ast::expr_if(_, _, _)) { false }
- case (ast::expr_ternary(_, _, _)) { true }
- case (ast::expr_for(_, _, _)) { false }
- case (ast::expr_for_each(_, _, _)) { false }
- case (ast::expr_while(_, _)) { false }
- case (ast::expr_do_while(_, _)) { false }
- case (ast::expr_alt(_, _)) { false }
- case (ast::expr_fn(_)) { false }
- case (ast::expr_block(_)) { false }
- case (ast::expr_move(_, _)) { true }
- case (ast::expr_assign(_, _)) { true }
- case (ast::expr_swap(_, _)) { true }
- case (ast::expr_assign_op(_, _, _)) { true }
- case (ast::expr_send(_, _)) { true }
- case (ast::expr_recv(_, _)) { true }
- case (ast::expr_field(_, _)) { true }
- case (ast::expr_index(_, _)) { true }
- case (ast::expr_path(_)) { true }
- case (ast::expr_mac(_)) { true }
- case (ast::expr_fail(_)) { true }
- case (ast::expr_break) { true }
- case (ast::expr_cont) { true }
- case (ast::expr_ret(_)) { true }
- case (ast::expr_put(_)) { true }
- case (ast::expr_be(_)) { true }
- case (ast::expr_log(_, _)) { true }
- case (ast::expr_check(_, _)) { true }
- case (ast::expr_if_check(_, _, _)) { false }
- case (ast::expr_port(_)) { true }
- case (ast::expr_chan(_)) { true }
- case (ast::expr_anon_obj(_)) { false }
- case (ast::expr_assert(_)) { true }
+ }
+ ast::stmt_expr(e, _) {
+ ret alt e.node {
+ ast::expr_vec(_, _, _) { true }
+ ast::expr_rec(_, _) { true }
+ ast::expr_call(_, _) { true }
+ ast::expr_self_method(_) { false }
+ ast::expr_bind(_, _) { true }
+ ast::expr_spawn(_, _, _, _) { true }
+ ast::expr_binary(_, _, _) { true }
+ ast::expr_unary(_, _) { true }
+ ast::expr_lit(_) { true }
+ ast::expr_cast(_, _) { true }
+ ast::expr_if(_, _, _) { false }
+ ast::expr_ternary(_, _, _) { true }
+ ast::expr_for(_, _, _) { false }
+ ast::expr_for_each(_, _, _) { false }
+ ast::expr_while(_, _) { false }
+ ast::expr_do_while(_, _) { false }
+ ast::expr_alt(_, _) { false }
+ ast::expr_fn(_) { false }
+ ast::expr_block(_) { false }
+ ast::expr_move(_, _) { true }
+ ast::expr_assign(_, _) { true }
+ ast::expr_swap(_, _) { true }
+ ast::expr_assign_op(_, _, _) { true }
+ ast::expr_send(_, _) { true }
+ ast::expr_recv(_, _) { true }
+ ast::expr_field(_, _) { true }
+ ast::expr_index(_, _) { true }
+ ast::expr_path(_) { true }
+ ast::expr_mac(_) { true }
+ ast::expr_fail(_) { true }
+ ast::expr_break. { true }
+ ast::expr_cont. { true }
+ ast::expr_ret(_) { true }
+ ast::expr_put(_) { true }
+ ast::expr_be(_) { true }
+ ast::expr_log(_, _) { true }
+ ast::expr_check(_, _) { true }
+ ast::expr_if_check(_, _, _) { false }
+ ast::expr_port(_) { true }
+ ast::expr_chan(_) { true }
+ ast::expr_anon_obj(_) { false }
+ ast::expr_assert(_) { true }
}
- }
- // We should not be calling this on a cdir.
- case (ast::stmt_crate_directive(?cdir)) {
- fail;
- }
+ }
+
+ // We should not be calling this on a cdir.
+ ast::stmt_crate_directive(cdir) {
+ fail;
+ }
}
}
-fn parse_block(&parser p) -> ast::blk {
- auto lo = p.get_lo_pos();
+fn parse_block(p: &parser) -> ast::blk {
+ let lo = p.get_lo_pos();
expect(p, token::LBRACE);
be parse_block_tail(p, lo);
}
// some blocks start with "#{"...
-fn parse_block_tail(&parser p, uint lo) -> ast::blk {
- let (@ast::stmt)[] stmts = ~[];
- let option::t[@ast::expr] expr = none;
- while (p.peek() != token::RBRACE) {
- alt (p.peek()) {
- case (token::SEMI) {
- p.bump(); // empty
- }
- case (_) {
- auto stmt = parse_stmt(p);
- alt (stmt_to_expr(stmt)) {
- case (some(?e)) {
- alt (p.peek()) {
- case (token::SEMI) { p.bump(); stmts += ~[stmt]; }
- case (token::RBRACE) { expr = some(e); }
- case (?t) {
- if (stmt_ends_with_semi(*stmt)) {
- p.fatal("expected ';' or '}' after " +
- "expression but found " +
- token::to_str(p.get_reader(),
- t));
- fail;
- }
- stmts += ~[stmt];
- }
- }
+fn parse_block_tail(p: &parser, lo: uint) -> ast::blk {
+ let stmts: (@ast::stmt)[] = ~[];
+ let expr: option::t[@ast::expr] = none;
+ while p.peek() != token::RBRACE {
+ alt p.peek() {
+ token::SEMI. {
+ p.bump(); // empty
+ }
+ _ {
+ let stmt = parse_stmt(p);
+ alt stmt_to_expr(stmt) {
+ some(e) {
+ alt p.peek() {
+ token::SEMI. { p.bump(); stmts += ~[stmt]; }
+ token::RBRACE. { expr = some(e); }
+ t {
+ if stmt_ends_with_semi(*stmt) {
+ p.fatal("expected ';' or '}' after " +
+ "expression but found " +
+ token::to_str(p.get_reader(), t));
+ fail;
}
- case (none) {
- // Not an expression statement.
- stmts += ~[stmt];
-
- if (p.get_file_type() == SOURCE_FILE
- && stmt_ends_with_semi(*stmt)) {
- expect(p, token::SEMI);
- }
- }
+ stmts += ~[stmt];
+ }
}
+ }
+ none. {
+ // Not an expression statement.
+ stmts += ~[stmt];
+
+
+ if p.get_file_type() == SOURCE_FILE &&
+ stmt_ends_with_semi(*stmt) {
+ expect(p, token::SEMI);
+ }
+ }
}
+ }
}
}
- auto hi = p.get_hi_pos();
+ let hi = p.get_hi_pos();
p.bump();
- auto bloc = rec(stmts=stmts, expr=expr, id=p.get_id());
+ let bloc = {stmts: stmts, expr: expr, id: p.get_id()};
ret spanned(lo, hi, bloc);
}
-fn parse_ty_param(&parser p) -> ast::ty_param { ret parse_ident(p); }
+fn parse_ty_param(p: &parser) -> ast::ty_param { ret parse_ident(p); }
-fn parse_ty_params(&parser p) -> ast::ty_param[] {
- let ast::ty_param[] ty_params = ~[];
- if (p.peek() == token::LBRACKET) {
- ty_params = parse_seq(token::LBRACKET, token::RBRACKET,
- some(token::COMMA), parse_ty_param, p).node;
+fn parse_ty_params(p: &parser) -> ast::ty_param[] {
+ let ty_params: ast::ty_param[] = ~[];
+ if p.peek() == token::LBRACKET {
+ ty_params =
+ parse_seq(token::LBRACKET, token::RBRACKET, some(token::COMMA),
+ parse_ty_param, p).node;
}
ret ty_params;
}
-fn parse_fn_decl(&parser p, ast::purity purity) -> ast::fn_decl {
- let ast::spanned[ast::arg[]] inputs =
- parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA),
- parse_arg, p);
- let ty_or_bang rslt;
+fn parse_fn_decl(p: &parser, purity: ast::purity) -> ast::fn_decl {
+ let inputs: ast::spanned[ast::arg[]] =
+ parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA), parse_arg,
+ p);
+ let rslt: ty_or_bang;
// Use the args list to translate each bound variable
// mentioned in a constraint to an arg index.
// Seems weird to do this in the parser, but I'm not sure how else to.
- auto constrs = ~[];
- if (p.peek() == token::COLON) {
+ let constrs = ~[];
+ if p.peek() == token::COLON {
p.bump();
- constrs = parse_constrs(bind parse_ty_constr(inputs.node,_), p);
+ constrs = parse_constrs(bind parse_ty_constr(inputs.node, _), p);
}
- if (p.peek() == token::RARROW) {
+ if p.peek() == token::RARROW {
p.bump();
rslt = parse_ty_or_bang(p);
} else {
rslt = a_ty(@spanned(inputs.span.lo, inputs.span.hi, ast::ty_nil));
}
- alt (rslt) {
- case (a_ty(?t)) {
- ret rec(inputs=inputs.node,
- output=t,
- purity=purity,
- cf=ast::return,
- constraints=constrs);
- }
- case (a_bang) {
- ret rec(inputs=inputs.node,
- output=@spanned(p.get_lo_pos(), p.get_hi_pos(),
- ast::ty_bot),
- purity=purity,
- cf=ast::noreturn,
- constraints=constrs);
- }
+ alt rslt {
+ a_ty(t) {
+ ret {inputs: inputs.node,
+ output: t,
+ purity: purity,
+ cf: ast::return,
+ constraints: constrs};
+ }
+ a_bang. {
+ ret {inputs: inputs.node,
+ output: @spanned(p.get_lo_pos(), p.get_hi_pos(), ast::ty_bot),
+ purity: purity,
+ cf: ast::noreturn,
+ constraints: constrs};
+ }
}
}
-fn parse_fn(&parser p, ast::proto proto, ast::purity purity) -> ast::_fn {
- auto decl = parse_fn_decl(p, purity);
- auto body = parse_block(p);
- ret rec(decl=decl, proto=proto, body=body);
+fn parse_fn(p: &parser, proto: ast::proto, purity: ast::purity) -> ast::_fn {
+ let decl = parse_fn_decl(p, purity);
+ let body = parse_block(p);
+ ret {decl: decl, proto: proto, body: body};
}
-fn parse_fn_header(&parser p) -> rec(ast::ident ident, ast::ty_param[] tps) {
- auto id = parse_value_ident(p);
- auto ty_params = parse_ty_params(p);
- ret rec(ident=id, tps=ty_params);
+fn parse_fn_header(p: &parser) -> {ident: ast::ident, tps: ast::ty_param[]} {
+ let id = parse_value_ident(p);
+ let ty_params = parse_ty_params(p);
+ ret {ident: id, tps: ty_params};
}
-fn mk_item(&parser p, uint lo, uint hi, &ast::ident ident, &ast::item_ node,
- &ast::attribute[] attrs) -> @ast::item {
- ret @rec(ident=ident,
- attrs=attrs,
- id=p.get_id(),
- node=node,
- span=rec(lo=lo, hi=hi));
+fn mk_item(p: &parser, lo: uint, hi: uint, ident: &ast::ident,
+ node: &ast::item_, attrs: &ast::attribute[]) -> @ast::item {
+ ret @{ident: ident,
+ attrs: attrs,
+ id: p.get_id(),
+ node: node,
+ span: {lo: lo, hi: hi}};
}
-fn parse_item_fn_or_iter(&parser p, ast::purity purity, ast::proto proto,
- &ast::attribute[] attrs) -> @ast::item {
- auto lo = p.get_last_lo_pos();
- auto t = parse_fn_header(p);
- auto f = parse_fn(p, proto, purity);
- ret mk_item(p, lo, f.body.span.hi, t.ident,
- ast::item_fn(f, t.tps), attrs);
+fn parse_item_fn_or_iter(p: &parser, purity: ast::purity, proto: ast::proto,
+ attrs: &ast::attribute[]) -> @ast::item {
+ let lo = p.get_last_lo_pos();
+ let t = parse_fn_header(p);
+ let f = parse_fn(p, proto, purity);
+ ret mk_item(p, lo, f.body.span.hi, t.ident, ast::item_fn(f, t.tps),
+ attrs);
}
-fn parse_obj_field(&parser p) -> ast::obj_field {
- auto mut = parse_mutability(p);
- auto ident = parse_value_ident(p);
+fn parse_obj_field(p: &parser) -> ast::obj_field {
+ let mut = parse_mutability(p);
+ let ident = parse_value_ident(p);
expect(p, token::COLON);
- auto ty = parse_ty(p);
- ret rec(mut=mut, ty=ty, ident=ident, id=p.get_id());
+ let ty = parse_ty(p);
+ ret {mut: mut, ty: ty, ident: ident, id: p.get_id()};
}
-fn parse_anon_obj_field(&parser p) -> ast::anon_obj_field {
- auto mut = parse_mutability(p);
- auto ident = parse_value_ident(p);
+fn parse_anon_obj_field(p: &parser) -> ast::anon_obj_field {
+ let mut = parse_mutability(p);
+ let ident = parse_value_ident(p);
expect(p, token::COLON);
- auto ty = parse_ty(p);
+ let ty = parse_ty(p);
expect(p, token::EQ);
- auto expr = parse_expr(p);
- ret rec(mut=mut, ty=ty, expr=expr, ident=ident, id=p.get_id());
+ let expr = parse_expr(p);
+ ret {mut: mut, ty: ty, expr: expr, ident: ident, id: p.get_id()};
}
-fn parse_method(&parser p) -> @ast::method {
- auto lo = p.get_lo_pos();
- auto proto = parse_proto(p);
- auto ident = parse_value_ident(p);
- auto f = parse_fn(p, proto, ast::impure_fn);
- auto meth = rec(ident=ident, meth=f, id=p.get_id());
+fn parse_method(p: &parser) -> @ast::method {
+ let lo = p.get_lo_pos();
+ let proto = parse_proto(p);
+ let ident = parse_value_ident(p);
+ let f = parse_fn(p, proto, ast::impure_fn);
+ let meth = {ident: ident, meth: f, id: p.get_id()};
ret @spanned(lo, f.body.span.hi, meth);
}
-fn parse_dtor(&parser p) -> @ast::method {
- auto lo = p.get_last_lo_pos();
- let ast::blk b = parse_block(p);
- let ast::arg[] inputs = ~[];
- let @ast::ty output = @spanned(lo, lo, ast::ty_nil);
- let ast::fn_decl d =
- rec(inputs=inputs,
- output=output,
- purity=ast::impure_fn,
- cf=ast::return,
+fn parse_dtor(p: &parser) -> @ast::method {
+ let lo = p.get_last_lo_pos();
+ let b: ast::blk = parse_block(p);
+ let inputs: ast::arg[] = ~[];
+ let output: @ast::ty = @spanned(lo, lo, ast::ty_nil);
+ let
- // I guess dtors can't have constraints?
- constraints=~[]);
- let ast::_fn f = rec(decl=d, proto=ast::proto_fn, body=b);
- let ast::method_ m =
- rec(ident="drop", meth=f, id=p.get_id());
+ // I guess dtors can't have constraints?
+ d: ast::fn_decl =
+ {inputs: inputs,
+ output: output,
+ purity: ast::impure_fn,
+ cf: ast::return,
+ constraints: ~[]};
+ let f: ast::_fn = {decl: d, proto: ast::proto_fn, body: b};
+ let m: ast::method_ = {ident: "drop", meth: f, id: p.get_id()};
ret @spanned(lo, f.body.span.hi, m);
}
-fn parse_item_obj(&parser p, ast::layer lyr, &ast::attribute[] attrs) ->
+fn parse_item_obj(p: &parser, lyr: ast::layer, attrs: &ast::attribute[]) ->
@ast::item {
- auto lo = p.get_last_lo_pos();
- auto ident = parse_value_ident(p);
- auto ty_params = parse_ty_params(p);
- let ast::spanned[ast::obj_field[]] fields =
+ let lo = p.get_last_lo_pos();
+ let ident = parse_value_ident(p);
+ let ty_params = parse_ty_params(p);
+ let fields: ast::spanned[ast::obj_field[]] =
parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA),
- parse_obj_field, p);
- let (@ast::method)[] meths = ~[];
- let option::t[@ast::method] dtor = none;
+ parse_obj_field, p);
+ let meths: (@ast::method)[] = ~[];
+ let dtor: option::t[@ast::method] = none;
expect(p, token::LBRACE);
- while (p.peek() != token::RBRACE) {
- if (eat_word(p, "drop")) {
+ while p.peek() != token::RBRACE {
+ if eat_word(p, "drop") {
dtor = some(parse_dtor(p));
} else { meths += ~[parse_method(p)]; }
}
- auto hi = p.get_hi_pos();
+ let hi = p.get_hi_pos();
expect(p, token::RBRACE);
- let ast::_obj ob = rec(fields=fields.node, methods=meths, dtor=dtor);
- ret mk_item(p, lo, hi, ident, ast::item_obj(ob, ty_params,
- p.get_id()), attrs);
+ let ob: ast::_obj = {fields: fields.node, methods: meths, dtor: dtor};
+ ret mk_item(p, lo, hi, ident, ast::item_obj(ob, ty_params, p.get_id()),
+ attrs);
}
-fn parse_item_res(&parser p, ast::layer lyr, &ast::attribute[] attrs) ->
+fn parse_item_res(p: &parser, lyr: ast::layer, attrs: &ast::attribute[]) ->
@ast::item {
- auto lo = p.get_last_lo_pos();
- auto ident = parse_value_ident(p);
- auto ty_params = parse_ty_params(p);
+ let lo = p.get_last_lo_pos();
+ let ident = parse_value_ident(p);
+ let ty_params = parse_ty_params(p);
expect(p, token::LPAREN);
- auto arg_ident = parse_value_ident(p);
+ let arg_ident = parse_value_ident(p);
expect(p, token::COLON);
- auto t = parse_ty(p);
+ let t = parse_ty(p);
expect(p, token::RPAREN);
- auto dtor = parse_block(p);
- auto decl = rec(inputs=~[rec(mode=ast::alias(false), ty=t,
- ident=arg_ident, id=p.get_id())],
- output=@spanned(lo, lo, ast::ty_nil),
- purity=ast::impure_fn,
- cf=ast::return,
- constraints=~[]);
- auto f = rec(decl=decl, proto=ast::proto_fn, body=dtor);
+ let dtor = parse_block(p);
+ let decl =
+ {inputs:
+ ~[{mode: ast::alias(false),
+ ty: t,
+ ident: arg_ident,
+ id: p.get_id()}],
+ output: @spanned(lo, lo, ast::ty_nil),
+ purity: ast::impure_fn,
+ cf: ast::return,
+ constraints: ~[]};
+ let f = {decl: decl, proto: ast::proto_fn, body: dtor};
ret mk_item(p, lo, dtor.span.hi, ident,
ast::item_res(f, p.get_id(), ty_params, p.get_id()), attrs);
}
-fn parse_mod_items(&parser p, token::token term,
- &ast::attribute[] first_item_attrs) -> ast::_mod {
- auto view_items = if (ivec::len(first_item_attrs) == 0u) {
- parse_view(p)
- } else {
+fn parse_mod_items(p: &parser, term: token::token,
+ first_item_attrs: &ast::attribute[]) -> ast::_mod {
+ let
// Shouldn't be any view items since we've already parsed an item attr
- ~[]
- };
- let (@ast::item)[] items = ~[];
- auto initial_attrs = first_item_attrs;
- while (p.peek() != term) {
- auto attrs = initial_attrs + parse_outer_attributes(p);
+ view_items =
+ if ivec::len(first_item_attrs) == 0u { parse_view(p) } else { ~[] };
+ let items: (@ast::item)[] = ~[];
+ let initial_attrs = first_item_attrs;
+ while p.peek() != term {
+ let attrs = initial_attrs + parse_outer_attributes(p);
initial_attrs = ~[];
- alt (parse_item(p, attrs)) {
- case (got_item(?i)) { items += ~[i]; }
- case (_) {
- p.fatal("expected item but found " +
- token::to_str(p.get_reader(), p.peek()));
- }
+ alt parse_item(p, attrs) {
+ got_item(i) { items += ~[i]; }
+ _ {
+ p.fatal("expected item but found " +
+ token::to_str(p.get_reader(), p.peek()));
+ }
}
}
- ret rec(view_items=view_items, items=items);
+ ret {view_items: view_items, items: items};
}
-fn parse_item_const(&parser p, &ast::attribute[] attrs) -> @ast::item {
- auto lo = p.get_last_lo_pos();
- auto id = parse_value_ident(p);
+fn parse_item_const(p: &parser, attrs: &ast::attribute[]) -> @ast::item {
+ let lo = p.get_last_lo_pos();
+ let id = parse_value_ident(p);
expect(p, token::COLON);
- auto ty = parse_ty(p);
+ let ty = parse_ty(p);
expect(p, token::EQ);
- auto e = parse_expr(p);
- auto hi = p.get_hi_pos();
+ let e = parse_expr(p);
+ let hi = p.get_hi_pos();
expect(p, token::SEMI);
ret mk_item(p, lo, hi, id, ast::item_const(ty, e), attrs);
}
-fn parse_item_mod(&parser p, &ast::attribute[] attrs) -> @ast::item {
- auto lo = p.get_last_lo_pos();
- auto id = parse_ident(p);
+fn parse_item_mod(p: &parser, attrs: &ast::attribute[]) -> @ast::item {
+ let lo = p.get_last_lo_pos();
+ let id = parse_ident(p);
expect(p, token::LBRACE);
- auto inner_attrs = parse_inner_attrs_and_next(p);
- auto first_item_outer_attrs = inner_attrs.next;
- auto m = parse_mod_items(p, token::RBRACE, first_item_outer_attrs);
- auto hi = p.get_hi_pos();
+ let inner_attrs = parse_inner_attrs_and_next(p);
+ let first_item_outer_attrs = inner_attrs.next;
+ let m = parse_mod_items(p, token::RBRACE, first_item_outer_attrs);
+ let hi = p.get_hi_pos();
expect(p, token::RBRACE);
ret mk_item(p, lo, hi, id, ast::item_mod(m), attrs + inner_attrs.inner);
}
-fn parse_item_native_type(&parser p, &ast::attribute[] attrs)
- -> @ast::native_item {
- auto t = parse_type_decl(p);
- auto hi = p.get_hi_pos();
+fn parse_item_native_type(p: &parser, attrs: &ast::attribute[]) ->
+ @ast::native_item {
+ let t = parse_type_decl(p);
+ let hi = p.get_hi_pos();
expect(p, token::SEMI);
- ret @rec(ident=t.ident,
- attrs=attrs,
- node=ast::native_item_ty,
- id=p.get_id(),
- span=rec(lo=t.lo, hi=hi));
+ ret @{ident: t.ident,
+ attrs: attrs,
+ node: ast::native_item_ty,
+ id: p.get_id(),
+ span: {lo: t.lo, hi: hi}};
}
-fn parse_item_native_fn(&parser p, &ast::attribute[] attrs)
- -> @ast::native_item {
- auto lo = p.get_last_lo_pos();
- auto t = parse_fn_header(p);
- auto decl = parse_fn_decl(p, ast::impure_fn);
- auto link_name = none;
- if (p.peek() == token::EQ) {
- p.bump();
- link_name = some(parse_str(p));
- }
- auto hi = p.get_hi_pos();
+fn parse_item_native_fn(p: &parser, attrs: &ast::attribute[]) ->
+ @ast::native_item {
+ let lo = p.get_last_lo_pos();
+ let t = parse_fn_header(p);
+ let decl = parse_fn_decl(p, ast::impure_fn);
+ let link_name = none;
+ if p.peek() == token::EQ { p.bump(); link_name = some(parse_str(p)); }
+ let hi = p.get_hi_pos();
expect(p, token::SEMI);
- ret @rec(ident=t.ident,
- attrs=attrs,
- node=ast::native_item_fn(link_name, decl, t.tps),
- id=p.get_id(),
- span=rec(lo=lo, hi=hi));
+ ret @{ident: t.ident,
+ attrs: attrs,
+ node: ast::native_item_fn(link_name, decl, t.tps),
+ id: p.get_id(),
+ span: {lo: lo, hi: hi}};
}
-fn parse_native_item(&parser p, &ast::attribute[] attrs)
- -> @ast::native_item {
+fn parse_native_item(p: &parser, attrs: &ast::attribute[]) ->
+ @ast::native_item {
parse_layer(p);
- if (eat_word(p, "type")) {
+ if eat_word(p, "type") {
ret parse_item_native_type(p, attrs);
} else if (eat_word(p, "fn")) {
ret parse_item_native_fn(p, attrs);
} else { unexpected(p, p.peek()); fail; }
}
-fn parse_native_mod_items(&parser p, &str native_name, ast::native_abi abi,
- &ast::attribute[] first_item_attrs)
- -> ast::native_mod {
- auto view_items = if (ivec::len(first_item_attrs) == 0u) {
- parse_native_view(p)
- } else {
+fn parse_native_mod_items(p: &parser, native_name: &str, abi: ast::native_abi,
+ first_item_attrs: &ast::attribute[]) ->
+ ast::native_mod {
+ let
// Shouldn't be any view items since we've already parsed an item attr
- ~[]
- };
- let (@ast::native_item)[] items = ~[];
- auto initial_attrs = first_item_attrs;
- while (p.peek() != token::RBRACE) {
- auto attrs = initial_attrs + parse_outer_attributes(p);
+ view_items =
+ if ivec::len(first_item_attrs) == 0u {
+ parse_native_view(p)
+ } else { ~[] };
+ let items: (@ast::native_item)[] = ~[];
+ let initial_attrs = first_item_attrs;
+ while p.peek() != token::RBRACE {
+ let attrs = initial_attrs + parse_outer_attributes(p);
initial_attrs = ~[];
items += ~[parse_native_item(p, attrs)];
}
- ret rec(native_name=native_name,
- abi=abi,
- view_items=view_items,
- items=items);
+ ret {native_name: native_name,
+ abi: abi,
+ view_items: view_items,
+ items: items};
}
-fn parse_item_native_mod(&parser p, &ast::attribute[] attrs) -> @ast::item {
- auto lo = p.get_last_lo_pos();
- auto abi = ast::native_abi_cdecl;
- if (!is_word(p, "mod")) {
- auto t = parse_str(p);
- if (str::eq(t, "cdecl")) {
+fn parse_item_native_mod(p: &parser, attrs: &ast::attribute[]) -> @ast::item {
+ let lo = p.get_last_lo_pos();
+ let abi = ast::native_abi_cdecl;
+ if !is_word(p, "mod") {
+ let t = parse_str(p);
+ if str::eq(t, "cdecl") {
} else if (str::eq(t, "rust")) {
abi = ast::native_abi_rust;
} else if (str::eq(t, "llvm")) {
@@ -2034,105 +1998,101 @@
} else { p.fatal("unsupported abi: " + t); fail; }
}
expect_word(p, "mod");
- auto id = parse_ident(p);
- auto native_name;
- if (p.peek() == token::EQ) {
+ let id = parse_ident(p);
+ let native_name;
+ if p.peek() == token::EQ {
expect(p, token::EQ);
native_name = parse_str(p);
- } else {
- native_name = id;
- }
+ } else { native_name = id; }
expect(p, token::LBRACE);
- auto more_attrs = parse_inner_attrs_and_next(p);
- auto inner_attrs = more_attrs.inner;
- auto first_item_outer_attrs = more_attrs.next;
- auto m = parse_native_mod_items(p, native_name, abi,
- first_item_outer_attrs);
- auto hi = p.get_hi_pos();
+ let more_attrs = parse_inner_attrs_and_next(p);
+ let inner_attrs = more_attrs.inner;
+ let first_item_outer_attrs = more_attrs.next;
+ let m =
+ parse_native_mod_items(p, native_name, abi, first_item_outer_attrs);
+ let hi = p.get_hi_pos();
expect(p, token::RBRACE);
ret mk_item(p, lo, hi, id, ast::item_native_mod(m), attrs + inner_attrs);
}
-fn parse_type_decl(&parser p) -> rec(uint lo, ast::ident ident) {
- auto lo = p.get_last_lo_pos();
- auto id = parse_ident(p);
- ret rec(lo=lo, ident=id);
+fn parse_type_decl(p: &parser) -> {lo: uint, ident: ast::ident} {
+ let lo = p.get_last_lo_pos();
+ let id = parse_ident(p);
+ ret {lo: lo, ident: id};
}
-fn parse_item_type(&parser p, &ast::attribute[] attrs) -> @ast::item {
- auto t = parse_type_decl(p);
- auto tps = parse_ty_params(p);
+fn parse_item_type(p: &parser, attrs: &ast::attribute[]) -> @ast::item {
+ let t = parse_type_decl(p);
+ let tps = parse_ty_params(p);
expect(p, token::EQ);
- auto ty = parse_ty(p);
- auto hi = p.get_hi_pos();
+ let ty = parse_ty(p);
+ let hi = p.get_hi_pos();
expect(p, token::SEMI);
ret mk_item(p, t.lo, hi, t.ident, ast::item_ty(ty, tps), attrs);
}
-fn parse_item_tag(&parser p, &ast::attribute[] attrs) -> @ast::item {
- auto lo = p.get_last_lo_pos();
- auto id = parse_ident(p);
- auto ty_params = parse_ty_params(p);
- let ast::variant[] variants = ~[];
+fn parse_item_tag(p: &parser, attrs: &ast::attribute[]) -> @ast::item {
+ let lo = p.get_last_lo_pos();
+ let id = parse_ident(p);
+ let ty_params = parse_ty_params(p);
+ let variants: ast::variant[] = ~[];
// Newtype syntax
- if (p.peek() == token::EQ) {
- if (p.get_bad_expr_words().contains_key(id)) {
+ if p.peek() == token::EQ {
+ if p.get_bad_expr_words().contains_key(id) {
p.fatal("found " + id + " in tag constructor position");
}
p.bump();
- auto ty = parse_ty(p);
+ let ty = parse_ty(p);
expect(p, token::SEMI);
- auto variant = spanned(ty.span.lo, ty.span.hi,
- rec(name=id,
- args=~[rec(ty=ty, id=p.get_id())],
- id=p.get_id()));
+ let variant =
+ spanned(ty.span.lo, ty.span.hi,
+ {name: id,
+ args: ~[{ty: ty, id: p.get_id()}],
+ id: p.get_id()});
ret mk_item(p, lo, ty.span.hi, id,
ast::item_tag(~[variant], ty_params), attrs);
}
expect(p, token::LBRACE);
- while (p.peek() != token::RBRACE) {
- auto tok = p.peek();
- alt (tok) {
- case (token::IDENT(?name, _)) {
- check_bad_word(p);
- auto vlo = p.get_lo_pos();
- p.bump();
- let ast::variant_arg[] args = ~[];
- auto vhi = p.get_hi_pos();
- alt (p.peek()) {
- case (token::LPAREN) {
- auto arg_tys =
- parse_seq(token::LPAREN, token::RPAREN,
- some(token::COMMA), parse_ty, p);
- for (@ast::ty ty in arg_tys.node) {
- args += ~[rec(ty=ty, id=p.get_id())];
- }
- vhi = arg_tys.span.hi;
- }
- case (_) {/* empty */ }
+ while p.peek() != token::RBRACE {
+ let tok = p.peek();
+ alt tok {
+ token::IDENT(name, _) {
+ check_bad_word(p);
+ let vlo = p.get_lo_pos();
+ p.bump();
+ let args: ast::variant_arg[] = ~[];
+ let vhi = p.get_hi_pos();
+ alt p.peek() {
+ token::LPAREN. {
+ let arg_tys =
+ parse_seq(token::LPAREN, token::RPAREN,
+ some(token::COMMA), parse_ty, p);
+ for ty: @ast::ty in arg_tys.node {
+ args += ~[{ty: ty, id: p.get_id()}];
}
- expect(p, token::SEMI);
- p.get_id();
- auto vr =
- rec(name=p.get_str(name),
- args=args,
- id=p.get_id());
- variants += ~[spanned(vlo, vhi, vr)];
+ vhi = arg_tys.span.hi;
+ }
+ _ {/* empty */ }
}
- case (token::RBRACE) {/* empty */ }
- case (_) {
- p.fatal("expected name of variant or '}' but found " +
- token::to_str(p.get_reader(), tok));
- }
+ expect(p, token::SEMI);
+ p.get_id();
+ let vr = {name: p.get_str(name), args: args, id: p.get_id()};
+ variants += ~[spanned(vlo, vhi, vr)];
+ }
+ token::RBRACE. {/* empty */ }
+ _ {
+ p.fatal("expected name of variant or '}' but found " +
+ token::to_str(p.get_reader(), tok));
+ }
}
}
- auto hi = p.get_hi_pos();
+ let hi = p.get_hi_pos();
p.bump();
ret mk_item(p, lo, hi, id, ast::item_tag(variants, ty_params), attrs);
}
-fn parse_layer(&parser p) -> ast::layer {
- if (eat_word(p, "state")) {
+fn parse_layer(p: &parser) -> ast::layer {
+ if eat_word(p, "state") {
ret ast::layer_state;
} else if (eat_word(p, "gc")) {
ret ast::layer_gc;
@@ -2140,8 +2100,8 @@
fail;
}
-fn parse_auth(&parser p) -> ast::_auth {
- if (eat_word(p, "unsafe")) {
+fn parse_auth(p: &parser) -> ast::_auth {
+ if eat_word(p, "unsafe") {
ret ast::auth_unsafe;
} else { unexpected(p, p.peek()); }
fail;
@@ -2149,13 +2109,13 @@
tag parsed_item { got_item(@ast::item); no_item; fn_no_item; }
-fn parse_item(&parser p, &ast::attribute[] attrs) -> parsed_item {
- if (eat_word(p, "const")) {
+fn parse_item(p: &parser, attrs: &ast::attribute[]) -> parsed_item {
+ if eat_word(p, "const") {
ret got_item(parse_item_const(p, attrs));
} else if (eat_word(p, "fn")) {
// This is an anonymous function
- if (p.peek() == token::LPAREN) { ret fn_no_item; }
+ if p.peek() == token::LPAREN { ret fn_no_item; }
ret got_item(parse_item_fn_or_iter(p, ast::impure_fn, ast::proto_fn,
attrs));
} else if (eat_word(p, "pred")) {
@@ -2169,8 +2129,8 @@
} else if (eat_word(p, "native")) {
ret got_item(parse_item_native_mod(p, attrs));
}
- auto lyr = parse_layer(p);
- if (eat_word(p, "type")) {
+ let lyr = parse_layer(p);
+ if eat_word(p, "type") {
ret got_item(parse_item_type(p, attrs));
} else if (eat_word(p, "tag")) {
ret got_item(parse_item_tag(p, attrs));
@@ -2185,45 +2145,41 @@
// extensions, which both begin with token.POUND
type attr_or_ext = option::t[either::t[ast::attribute[], @ast::expr]];
-fn parse_outer_attrs_or_ext(&parser p) -> attr_or_ext {
- if (p.peek() == token::POUND) {
- auto lo = p.get_lo_pos();
+fn parse_outer_attrs_or_ext(p: &parser) -> attr_or_ext {
+ if p.peek() == token::POUND {
+ let lo = p.get_lo_pos();
p.bump();
- if (p.peek() == token::LBRACKET) {
- auto first_attr = parse_attribute_naked(p, ast::attr_outer, lo);
+ if p.peek() == token::LBRACKET {
+ let first_attr = parse_attribute_naked(p, ast::attr_outer, lo);
ret some(left(~[first_attr] + parse_outer_attributes(p)));
- } else if (! (p.peek() == token::LT || p.peek() == token::LBRACKET)) {
+ } else if (!(p.peek() == token::LT || p.peek() == token::LBRACKET)) {
ret some(right(parse_syntax_ext_naked(p, lo)));
- } else {
- ret none;
- }
- } else {
- ret none;
- }
+ } else { ret none; }
+ } else { ret none; }
}
// Parse attributes that appear before an item
-fn parse_outer_attributes(&parser p) -> ast::attribute[] {
- let ast::attribute[] attrs = ~[];
- while (p.peek() == token::POUND) {
+fn parse_outer_attributes(p: &parser) -> ast::attribute[] {
+ let attrs: ast::attribute[] = ~[];
+ while p.peek() == token::POUND {
attrs += ~[parse_attribute(p, ast::attr_outer)];
}
ret attrs;
}
-fn parse_attribute(&parser p, ast::attr_style style) -> ast::attribute {
- auto lo = p.get_lo_pos();
+fn parse_attribute(p: &parser, style: ast::attr_style) -> ast::attribute {
+ let lo = p.get_lo_pos();
expect(p, token::POUND);
ret parse_attribute_naked(p, style, lo);
}
-fn parse_attribute_naked(&parser p, ast::attr_style style,
- uint lo) -> ast::attribute {
+fn parse_attribute_naked(p: &parser, style: ast::attr_style, lo: uint) ->
+ ast::attribute {
expect(p, token::LBRACKET);
- auto meta_item = parse_meta_item(p);
+ let meta_item = parse_meta_item(p);
expect(p, token::RBRACKET);
- auto hi = p.get_hi_pos();
- ret spanned(lo, hi, rec(style=style, value=*meta_item));
+ let hi = p.get_hi_pos();
+ ret spanned(lo, hi, {style: style, value: *meta_item});
}
// Parse attributes that appear after the opening of an item, each terminated
@@ -2232,219 +2188,213 @@
// next item (since we can't know whether the attribute is an inner attribute
// of the containing item or an outer attribute of the first contained item
// until we see the semi).
-fn parse_inner_attrs_and_next(&parser p) -> rec(ast::attribute[] inner,
- ast::attribute[] next) {
- let ast::attribute[] inner_attrs = ~[];
- let ast::attribute[] next_outer_attrs = ~[];
- while (p.peek() == token::POUND) {
- auto attr = parse_attribute(p, ast::attr_inner);
- if (p.peek() == token::SEMI) {
+fn parse_inner_attrs_and_next(p: &parser) ->
+ {inner: ast::attribute[], next: ast::attribute[]} {
+ let inner_attrs: ast::attribute[] = ~[];
+ let next_outer_attrs: ast::attribute[] = ~[];
+ while p.peek() == token::POUND {
+ let attr = parse_attribute(p, ast::attr_inner);
+ if p.peek() == token::SEMI {
p.bump();
inner_attrs += ~[attr];
} else {
// It's not really an inner attribute
- auto outer_attr = spanned(attr.span.lo,
- attr.span.hi,
- rec(style=ast::attr_outer,
- value=attr.node.value));
+ let outer_attr =
+ spanned(attr.span.lo, attr.span.hi,
+ {style: ast::attr_outer, value: attr.node.value});
next_outer_attrs += ~[outer_attr];
break;
}
}
- ret rec(inner=inner_attrs, next=next_outer_attrs);
+ ret {inner: inner_attrs, next: next_outer_attrs};
}
-fn parse_meta_item(&parser p) -> @ast::meta_item {
- auto lo = p.get_lo_pos();
- auto ident = parse_ident(p);
- alt (p.peek()) {
- case (token::EQ) {
- p.bump();
- auto lit = parse_lit(p);
- auto hi = p.get_hi_pos();
- ret @spanned(lo, hi, ast::meta_name_value(ident, lit));
- }
- case (token::LPAREN) {
- auto inner_items = parse_meta_seq(p);
- auto hi = p.get_hi_pos();
- ret @spanned(lo, hi, ast::meta_list(ident, inner_items));
- }
- case (_) {
- auto hi = p.get_hi_pos();
- ret @spanned(lo, hi, ast::meta_word(ident));
- }
+fn parse_meta_item(p: &parser) -> @ast::meta_item {
+ let lo = p.get_lo_pos();
+ let ident = parse_ident(p);
+ alt p.peek() {
+ token::EQ. {
+ p.bump();
+ let lit = parse_lit(p);
+ let hi = p.get_hi_pos();
+ ret @spanned(lo, hi, ast::meta_name_value(ident, lit));
+ }
+ token::LPAREN. {
+ let inner_items = parse_meta_seq(p);
+ let hi = p.get_hi_pos();
+ ret @spanned(lo, hi, ast::meta_list(ident, inner_items));
+ }
+ _ {
+ let hi = p.get_hi_pos();
+ ret @spanned(lo, hi, ast::meta_word(ident));
+ }
}
}
-fn parse_meta_seq(&parser p) -> (@ast::meta_item)[] {
+fn parse_meta_seq(p: &parser) -> (@ast::meta_item)[] {
ret parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA),
parse_meta_item, p).node;
}
-fn parse_optional_meta(&parser p) -> (@ast::meta_item)[] {
- alt (p.peek()) {
- case (token::LPAREN) { ret parse_meta_seq(p); }
- case (_) { ret ~[]; }
- }
+fn parse_optional_meta(p: &parser) -> (@ast::meta_item)[] {
+ alt p.peek() { token::LPAREN. { ret parse_meta_seq(p); } _ { ret ~[]; } }
}
-fn parse_use(&parser p) -> ast::view_item_ {
- auto ident = parse_ident(p);
- auto metadata = parse_optional_meta(p);
+fn parse_use(p: &parser) -> ast::view_item_ {
+ let ident = parse_ident(p);
+ let metadata = parse_optional_meta(p);
ret ast::view_item_use(ident, metadata, p.get_id());
}
-fn parse_rest_import_name(&parser p, ast::ident first,
- option::t[ast::ident] def_ident) ->
+fn parse_rest_import_name(p: &parser, first: ast::ident,
+ def_ident: option::t[ast::ident]) ->
ast::view_item_ {
- let ast::ident[] identifiers = ~[first];
- let bool glob = false;
- while (true) {
- alt (p.peek()) {
- case (token::SEMI) { break; }
- case (token::MOD_SEP) {
- if (glob) { p.fatal("cannot path into a glob"); }
- p.bump();
- }
- case (_) { p.fatal("expecting '::' or ';'"); }
+ let identifiers: ast::ident[] = ~[first];
+ let glob: bool = false;
+ while true {
+ alt p.peek() {
+ token::SEMI. { break; }
+ token::MOD_SEP. {
+ if glob { p.fatal("cannot path into a glob"); }
+ p.bump();
+ }
+ _ { p.fatal("expecting '::' or ';'"); }
}
- alt (p.peek()) {
- case (token::IDENT(_, _)) { identifiers += ~[parse_ident(p)]; }
- //the lexer can't tell the different kinds of stars apart ) :
- case (token::BINOP(token::STAR)) {
- glob = true;
- p.bump();
- }
- case (_) { p.fatal("expecting an identifier, or '*'"); }
+ alt p.peek() {
+ token::IDENT(_, _) { identifiers += ~[parse_ident(p)]; }
+
+ //the lexer can't tell the different kinds of stars apart ) :
+ token::BINOP(token::STAR.) {
+ glob = true;
+ p.bump();
+ }
+ _ { p.fatal("expecting an identifier, or '*'"); }
}
}
- alt (def_ident) {
- case (some(?i)) {
- if (glob) { p.fatal("globbed imports can't be renamed"); }
- ret ast::view_item_import(i, identifiers, p.get_id());
+ alt def_ident {
+ some(i) {
+ if glob { p.fatal("globbed imports can't be renamed"); }
+ ret ast::view_item_import(i, identifiers, p.get_id());
+ }
+ _ {
+ if glob {
+ ret ast::view_item_import_glob(identifiers, p.get_id());
+ } else {
+ let len = ivec::len(identifiers);
+ ret ast::view_item_import(identifiers.(len - 1u), identifiers,
+ p.get_id());
}
- case (_) {
- if (glob) {
- ret ast::view_item_import_glob(identifiers, p.get_id());
- } else {
- auto len = ivec::len(identifiers);
- ret ast::view_item_import(identifiers.(len - 1u), identifiers,
- p.get_id());
- }
- }
+ }
}
}
-fn parse_full_import_name(&parser p, ast::ident def_ident) ->
+fn parse_full_import_name(p: &parser, def_ident: ast::ident) ->
ast::view_item_ {
- alt (p.peek()) {
- case (token::IDENT(?i, _)) {
- p.bump();
- ret parse_rest_import_name(p, p.get_str(i), some(def_ident));
- }
- case (_) { p.fatal("expecting an identifier"); }
+ alt p.peek() {
+ token::IDENT(i, _) {
+ p.bump();
+ ret parse_rest_import_name(p, p.get_str(i), some(def_ident));
+ }
+ _ { p.fatal("expecting an identifier"); }
}
fail;
}
-fn parse_import(&parser p) -> ast::view_item_ {
- alt (p.peek()) {
- case (token::IDENT(?i, _)) {
+fn parse_import(p: &parser) -> ast::view_item_ {
+ alt p.peek() {
+ token::IDENT(i, _) {
+ p.bump();
+ alt p.peek() {
+ token::EQ. {
p.bump();
- alt (p.peek()) {
- case (token::EQ) {
- p.bump();
- ret parse_full_import_name(p, p.get_str(i));
- }
- case (_) {
- ret parse_rest_import_name(p, p.get_str(i), none);
- }
- }
+ ret parse_full_import_name(p, p.get_str(i));
+ }
+ _ { ret parse_rest_import_name(p, p.get_str(i), none); }
}
- case (_) { p.fatal("expecting an identifier"); }
+ }
+ _ { p.fatal("expecting an identifier"); }
}
fail;
}
-fn parse_export(&parser p) -> ast::view_item_ {
- auto id = parse_ident(p);
+fn parse_export(p: &parser) -> ast::view_item_ {
+ let id = parse_ident(p);
ret ast::view_item_export(id, p.get_id());
}
-fn parse_view_item(&parser p) -> @ast::view_item {
- auto lo = p.get_lo_pos();
- auto the_item = if (eat_word(p, "use")) { parse_use(p) }
- else if (eat_word(p, "import")) { parse_import(p) }
- else if (eat_word(p, "export")) { parse_export(p) }
- else { fail };
- auto hi = p.get_lo_pos();
+fn parse_view_item(p: &parser) -> @ast::view_item {
+ let lo = p.get_lo_pos();
+ let the_item =
+ if eat_word(p, "use") {
+ parse_use(p)
+ } else if (eat_word(p, "import")) {
+ parse_import(p)
+ } else if (eat_word(p, "export")) { parse_export(p) } else { fail };
+ let hi = p.get_lo_pos();
expect(p, token::SEMI);
ret @spanned(lo, hi, the_item);
}
-fn is_view_item(&parser p) -> bool {
- alt (p.peek()) {
- case (token::IDENT(?sid, false)) {
- auto st = p.get_str(sid);
- ret str::eq(st, "use") || str::eq(st, "import") ||
- str::eq(st, "export");
- }
- case (_) { ret false; }
+fn is_view_item(p: &parser) -> bool {
+ alt p.peek() {
+ token::IDENT(sid, false) {
+ let st = p.get_str(sid);
+ ret str::eq(st, "use") || str::eq(st, "import") ||
+ str::eq(st, "export");
+ }
+ _ { ret false; }
}
ret false;
}
-fn parse_view(&parser p) -> (@ast::view_item)[] {
- let (@ast::view_item)[] items = ~[];
- while (is_view_item(p)) { items += ~[parse_view_item(p)]; }
+fn parse_view(p: &parser) -> (@ast::view_item)[] {
+ let items: (@ast::view_item)[] = ~[];
+ while is_view_item(p) { items += ~[parse_view_item(p)]; }
ret items;
}
-fn parse_native_view(&parser p) -> (@ast::view_item)[] {
- let (@ast::view_item)[] items = ~[];
- while (is_view_item(p)) { items += ~[parse_view_item(p)]; }
+fn parse_native_view(p: &parser) -> (@ast::view_item)[] {
+ let items: (@ast::view_item)[] = ~[];
+ while is_view_item(p) { items += ~[parse_view_item(p)]; }
ret items;
}
-fn parse_crate_from_source_file(&str input, &ast::crate_cfg cfg,
- &parse_sess sess) -> @ast::crate {
- auto p = new_parser_from_file(sess, cfg, input, 0u, 0u);
+fn parse_crate_from_source_file(input: &str, cfg: &ast::crate_cfg,
+ sess: &parse_sess) -> @ast::crate {
+ let p = new_parser_from_file(sess, cfg, input, 0u, 0u);
ret parse_crate_mod(p, cfg, sess);
}
-fn parse_crate_from_source_str(&str name, &str source, &ast::crate_cfg cfg,
- &codemap::codemap cm) -> @ast::crate {
- auto sess = @rec(cm=cm, mutable next_id=0);
- auto ftype = SOURCE_FILE;
- auto filemap = codemap::new_filemap(name, 0u, 0u);
+fn parse_crate_from_source_str(name: &str, source: &str, cfg: &ast::crate_cfg,
+ cm: &codemap::codemap) -> @ast::crate {
+ let sess = @{cm: cm, mutable next_id: 0};
+ let ftype = SOURCE_FILE;
+ let filemap = codemap::new_filemap(name, 0u, 0u);
sess.cm.files += ~[filemap];
- auto itr = @interner::mk(str::hash, str::eq);
- auto rdr = lexer::new_reader(sess.cm, source, filemap, itr);
- auto p = new_parser(sess, cfg, rdr, ftype);
+ let itr = @interner::mk(str::hash, str::eq);
+ let rdr = lexer::new_reader(sess.cm, source, filemap, itr);
+ let p = new_parser(sess, cfg, rdr, ftype);
ret parse_crate_mod(p, cfg, sess);
}
// Parses a source module as a crate
-fn parse_crate_mod(&parser p, &ast::crate_cfg cfg, parse_sess sess)
- -> @ast::crate {
- auto lo = p.get_lo_pos();
- auto crate_attrs = parse_inner_attrs_and_next(p);
- auto first_item_outer_attrs = crate_attrs.next;
- auto m = parse_mod_items(p, token::EOF,
- first_item_outer_attrs);
- ret @spanned(lo, p.get_lo_pos(), rec(directives=~[],
- module=m,
- attrs=crate_attrs.inner,
- config=p.get_cfg()));
+fn parse_crate_mod(p: &parser, cfg: &ast::crate_cfg, sess: parse_sess) ->
+ @ast::crate {
+ let lo = p.get_lo_pos();
+ let crate_attrs = parse_inner_attrs_and_next(p);
+ let first_item_outer_attrs = crate_attrs.next;
+ let m = parse_mod_items(p, token::EOF, first_item_outer_attrs);
+ ret @spanned(lo, p.get_lo_pos(),
+ {directives: ~[],
+ module: m,
+ attrs: crate_attrs.inner,
+ config: p.get_cfg()});
}
-fn parse_str(&parser p) -> ast::ident {
- alt (p.peek()) {
- case (token::LIT_STR(?s)) {
- p.bump();
- ret p.get_str(s);
- }
- case (_) { fail; }
+fn parse_str(p: &parser) -> ast::ident {
+ alt p.peek() {
+ token::LIT_STR(s) { p.bump(); ret p.get_str(s); }
+ _ { fail; }
}
}
@@ -2453,109 +2403,105 @@
// Each crate file is a sequence of directives.
//
// Each directive imperatively extends its environment with 0 or more items.
-fn parse_crate_directive(&parser p, &ast::attribute[] first_outer_attr)
- -> ast::crate_directive {
+fn parse_crate_directive(p: &parser, first_outer_attr: &ast::attribute[]) ->
+ ast::crate_directive {
// Collect the next attributes
- auto outer_attrs = first_outer_attr + parse_outer_attributes(p);
+ let outer_attrs = first_outer_attr + parse_outer_attributes(p);
// In a crate file outer attributes are only going to apply to mods
- auto expect_mod = ivec::len(outer_attrs) > 0u;
+ let expect_mod = ivec::len(outer_attrs) > 0u;
- auto lo = p.get_lo_pos();
- if (expect_mod || is_word(p, "mod")) {
+ let lo = p.get_lo_pos();
+ if expect_mod || is_word(p, "mod") {
expect_word(p, "mod");
- auto id = parse_ident(p);
- auto file_opt =
- alt (p.peek()) {
- case (token::EQ) {
- p.bump();
- some(parse_str(p))
- }
- case (_) { none }
+ let id = parse_ident(p);
+ let file_opt =
+ alt p.peek() {
+ token::EQ. { p.bump(); some(parse_str(p)) }
+ _ { none }
};
- alt (p.peek()) {
- case (
- // mod x = "foo.rs";
- token::SEMI) {
- auto hi = p.get_hi_pos();
- p.bump();
- ret spanned(lo, hi, ast::cdir_src_mod(id, file_opt,
- outer_attrs));
- }
- case (
- // mod x = "foo_dir" { ...directives... }
- token::LBRACE) {
- p.bump();
- auto inner_attrs = parse_inner_attrs_and_next(p);
- auto mod_attrs = outer_attrs + inner_attrs.inner;
- auto next_outer_attr = inner_attrs.next;
- auto cdirs = parse_crate_directives(p, token::RBRACE,
- next_outer_attr);
- auto hi = p.get_hi_pos();
- expect(p, token::RBRACE);
- ret spanned(lo, hi, ast::cdir_dir_mod(id, file_opt, cdirs,
- mod_attrs));
- }
- case (?t) { unexpected(p, t); }
+ alt p.peek() {
+
+ // mod x = "foo.rs";
+ token::SEMI. {
+ let hi = p.get_hi_pos();
+ p.bump();
+ ret spanned(lo, hi, ast::cdir_src_mod(id, file_opt, outer_attrs));
+ }
+
+ // mod x = "foo_dir" { ...directives... }
+ token::LBRACE. {
+ p.bump();
+ let inner_attrs = parse_inner_attrs_and_next(p);
+ let mod_attrs = outer_attrs + inner_attrs.inner;
+ let next_outer_attr = inner_attrs.next;
+ let cdirs =
+ parse_crate_directives(p, token::RBRACE, next_outer_attr);
+ let hi = p.get_hi_pos();
+ expect(p, token::RBRACE);
+ ret spanned(lo, hi,
+ ast::cdir_dir_mod(id, file_opt, cdirs, mod_attrs));
+ }
+ t { unexpected(p, t); }
}
} else if (eat_word(p, "auth")) {
- auto n = parse_path(p);
+ let n = parse_path(p);
expect(p, token::EQ);
- auto a = parse_auth(p);
- auto hi = p.get_hi_pos();
+ let a = parse_auth(p);
+ let hi = p.get_hi_pos();
expect(p, token::SEMI);
ret spanned(lo, hi, ast::cdir_auth(n, a));
} else if (is_view_item(p)) {
- auto vi = parse_view_item(p);
+ let vi = parse_view_item(p);
ret spanned(lo, vi.span.hi, ast::cdir_view_item(vi));
- } else {
- ret p.fatal("expected crate directive");
- }
+ } else { ret p.fatal("expected crate directive"); }
}
-fn parse_crate_directives(&parser p, token::token term,
- &ast::attribute[] first_outer_attr)
- -> (@ast::crate_directive)[] {
+fn parse_crate_directives(p: &parser, term: token::token,
+ first_outer_attr: &ast::attribute[]) ->
+ (@ast::crate_directive)[] {
// This is pretty ugly. If we have an outer attribute then we can't accept
// seeing the terminator next, so if we do see it then fail the same way
// parse_crate_directive would
- if (ivec::len(first_outer_attr) > 0u && p.peek() == term) {
+ if ivec::len(first_outer_attr) > 0u && p.peek() == term {
expect_word(p, "mod");
}
- let (@ast::crate_directive)[] cdirs = ~[];
- while (p.peek() != term) {
- auto cdir = @parse_crate_directive(p, first_outer_attr);
+ let cdirs: (@ast::crate_directive)[] = ~[];
+ while p.peek() != term {
+ let cdir = @parse_crate_directive(p, first_outer_attr);
cdirs += ~[cdir];
}
ret cdirs;
}
-fn parse_crate_from_crate_file(&str input, &ast::crate_cfg cfg,
- &parse_sess sess) -> @ast::crate {
- auto p = new_parser_from_file(sess, cfg, input, 0u, 0u);
- auto lo = p.get_lo_pos();
- auto prefix = std::fs::dirname(p.get_filemap().name);
- auto leading_attrs = parse_inner_attrs_and_next(p);
- auto crate_attrs = leading_attrs.inner;
- auto first_cdir_attr = leading_attrs.next;
- auto cdirs = parse_crate_directives(p, token::EOF, first_cdir_attr);
- let str[] deps = ~[];
- auto cx = @rec(p=p,
- mode=eval::mode_parse,
- mutable deps=deps,
- sess=sess,
- mutable chpos=p.get_chpos(),
- mutable byte_pos=p.get_byte_pos(),
- cfg = p.get_cfg());
- auto m = eval::eval_crate_directives_to_mod(cx, cdirs, prefix);
- auto hi = p.get_hi_pos();
+fn parse_crate_from_crate_file(input: &str, cfg: &ast::crate_cfg,
+ sess: &parse_sess) -> @ast::crate {
+ let p = new_parser_from_file(sess, cfg, input, 0u, 0u);
+ let lo = p.get_lo_pos();
+ let prefix = std::fs::dirname(p.get_filemap().name);
+ let leading_attrs = parse_inner_attrs_and_next(p);
+ let crate_attrs = leading_attrs.inner;
+ let first_cdir_attr = leading_attrs.next;
+ let cdirs = parse_crate_directives(p, token::EOF, first_cdir_attr);
+ let deps: str[] = ~[];
+ let cx =
+ @{p: p,
+ mode: eval::mode_parse,
+ mutable deps: deps,
+ sess: sess,
+ mutable chpos: p.get_chpos(),
+ mutable byte_pos: p.get_byte_pos(),
+ cfg: p.get_cfg()};
+ let m = eval::eval_crate_directives_to_mod(cx, cdirs, prefix);
+ let hi = p.get_hi_pos();
expect(p, token::EOF);
- ret @spanned(lo, hi, rec(directives=cdirs,
- module=m,
- attrs=crate_attrs,
- config=p.get_cfg()));
+ ret @spanned(lo, hi,
+ {directives: cdirs,
+ module: m,
+ attrs: crate_attrs,
+ config: p.get_cfg()});
}
//
// Local Variables:
diff --git a/src/comp/syntax/parse/token.rs b/src/comp/syntax/parse/token.rs
index 44dadc1..35bd1f1 100644
--- a/src/comp/syntax/parse/token.rs
+++ b/src/comp/syntax/parse/token.rs
@@ -25,6 +25,7 @@
tag token {
+
/* Expression-operator symbols. */
EQ;
LT;
@@ -40,6 +41,7 @@
BINOP(binop);
BINOPEQ(binop);
+
/* Structural symbols */
AT;
DOT;
@@ -64,6 +66,7 @@
POUND_LBRACE;
POUND_LT;
+
/* Literals */
LIT_INT(int);
LIT_UINT(uint);
@@ -74,6 +77,7 @@
LIT_CHAR(char);
LIT_BOOL(bool);
+
/* Name components */
IDENT(str_num, bool);
IDX(int);
@@ -82,113 +86,122 @@
EOF;
}
-fn binop_to_str(binop o) -> str {
- alt (o) {
- case (PLUS) { ret "+"; }
- case (MINUS) { ret "-"; }
- case (STAR) { ret "*"; }
- case (SLASH) { ret "/"; }
- case (PERCENT) { ret "%"; }
- case (CARET) { ret "^"; }
- case (AND) { ret "&"; }
- case (OR) { ret "|"; }
- case (LSL) { ret "<<"; }
- case (LSR) { ret ">>"; }
- case (ASR) { ret ">>>"; }
+fn binop_to_str(o: binop) -> str {
+ alt o {
+ PLUS. { ret "+"; }
+ MINUS. { ret "-"; }
+ STAR. { ret "*"; }
+ SLASH. { ret "/"; }
+ PERCENT. { ret "%"; }
+ CARET. { ret "^"; }
+ AND. { ret "&"; }
+ OR. { ret "|"; }
+ LSL. { ret "<<"; }
+ LSR. { ret ">>"; }
+ ASR. { ret ">>>"; }
}
}
-fn to_str(lexer::reader r, token t) -> str {
- alt (t) {
- case (EQ) { ret "="; }
- case (LT) { ret "<"; }
- case (LE) { ret "<="; }
- case (EQEQ) { ret "=="; }
- case (NE) { ret "!="; }
- case (GE) { ret ">="; }
- case (GT) { ret ">"; }
- case (NOT) { ret "!"; }
- case (TILDE) { ret "~"; }
- case (OROR) { ret "||"; }
- case (ANDAND) { ret "&&"; }
- case (BINOP(?op)) { ret binop_to_str(op); }
- case (BINOPEQ(?op)) { ret binop_to_str(op) + "="; }
- /* Structural symbols */
- case (AT) { ret "@"; }
- case (DOT) { ret "."; }
- case (ELLIPSIS) { ret "..."; }
- case (COMMA) { ret ","; }
- case (SEMI) { ret ";"; }
- case (COLON) { ret ":"; }
- case (MOD_SEP) { ret "::"; }
- case (QUES) { ret "?"; }
- case (RARROW) { ret "->"; }
- case (SEND) { ret "<|"; }
- case (RECV) { ret "|>"; }
- case (LARROW) { ret "<-"; }
- case (DARROW) { ret "<->"; }
- case (LPAREN) { ret "("; }
- case (RPAREN) { ret ")"; }
- case (LBRACKET) { ret "["; }
- case (RBRACKET) { ret "]"; }
- case (LBRACE) { ret "{"; }
- case (RBRACE) { ret "}"; }
- case (POUND) { ret "#"; }
- case (POUND_LBRACE) { ret "#{"; }
- case (POUND_LT) { ret "#<"; }
- /* Literals */
- case (LIT_INT(?i)) { ret int::to_str(i, 10u); }
- case (LIT_UINT(?u)) { ret uint::to_str(u, 10u); }
- case (LIT_MACH_INT(?tm, ?i)) {
- ret int::to_str(i, 10u) + "_" + ty_mach_to_str(tm);
- }
- case (LIT_MACH_FLOAT(?tm, ?s)) {
- ret interner::get[str](*r.get_interner(), s) + "_" +
- ty_mach_to_str(tm);
- }
- case (LIT_FLOAT(?s)) { ret interner::get[str](*r.get_interner(), s); }
- case (LIT_STR(?s)) { // FIXME: escape.
- ret "\"" + interner::get[str](*r.get_interner(), s) + "\"";
- }
- case (LIT_CHAR(?c)) {
- // FIXME: escape.
- auto tmp = "'";
- str::push_char(tmp, c);
- str::push_byte(tmp, '\'' as u8);
- ret tmp;
- }
- case (LIT_BOOL(?b)) { if (b) { ret "true"; } else { ret "false"; } }
- /* Name components */
- case (IDENT(?s, _)) { ret interner::get[str](*r.get_interner(), s); }
- case (IDX(?i)) { ret "_" + int::to_str(i, 10u); }
- case (UNDERSCORE) { ret "_"; }
- case (BRACEQUOTE(_)) { ret "<bracequote>"; }
- case (EOF) { ret "<eof>"; }
+fn to_str(r: lexer::reader, t: token) -> str {
+ alt t {
+ EQ. { ret "="; }
+ LT. { ret "<"; }
+ LE. { ret "<="; }
+ EQEQ. { ret "=="; }
+ NE. { ret "!="; }
+ GE. { ret ">="; }
+ GT. { ret ">"; }
+ NOT. { ret "!"; }
+ TILDE. { ret "~"; }
+ OROR. { ret "||"; }
+ ANDAND. { ret "&&"; }
+ BINOP(op) { ret binop_to_str(op); }
+ BINOPEQ(op) { ret binop_to_str(op) + "="; }
+
+ /* Structural symbols */
+ AT. {
+ ret "@";
+ }
+ DOT. { ret "."; }
+ ELLIPSIS. { ret "..."; }
+ COMMA. { ret ","; }
+ SEMI. { ret ";"; }
+ COLON. { ret ":"; }
+ MOD_SEP. { ret "::"; }
+ QUES. { ret "?"; }
+ RARROW. { ret "->"; }
+ SEND. { ret "<|"; }
+ RECV. { ret "|>"; }
+ LARROW. { ret "<-"; }
+ DARROW. { ret "<->"; }
+ LPAREN. { ret "("; }
+ RPAREN. { ret ")"; }
+ LBRACKET. { ret "["; }
+ RBRACKET. { ret "]"; }
+ LBRACE. { ret "{"; }
+ RBRACE. { ret "}"; }
+ POUND. { ret "#"; }
+ POUND_LBRACE. { ret "#{"; }
+ POUND_LT. { ret "#<"; }
+
+ /* Literals */
+ LIT_INT(i) {
+ ret int::to_str(i, 10u);
+ }
+ LIT_UINT(u) { ret uint::to_str(u, 10u); }
+ LIT_MACH_INT(tm, i) {
+ ret int::to_str(i, 10u) + "_" + ty_mach_to_str(tm);
+ }
+ LIT_MACH_FLOAT(tm, s) {
+ ret interner::get[str](*r.get_interner(), s) + "_" +
+ ty_mach_to_str(tm);
+ }
+ LIT_FLOAT(s) { ret interner::get[str](*r.get_interner(), s); }
+ LIT_STR(s) { // FIXME: escape.
+ ret "\"" + interner::get[str](*r.get_interner(), s) + "\"";
+ }
+ LIT_CHAR(c) {
+ // FIXME: escape.
+ let tmp = "'";
+ str::push_char(tmp, c);
+ str::push_byte(tmp, '\'' as u8);
+ ret tmp;
+ }
+ LIT_BOOL(b) { if b { ret "true"; } else { ret "false"; } }
+
+ /* Name components */
+ IDENT(s, _) {
+ ret interner::get[str](*r.get_interner(), s);
+ }
+ IDX(i) { ret "_" + int::to_str(i, 10u); }
+ UNDERSCORE. { ret "_"; }
+ BRACEQUOTE(_) { ret "<bracequote>"; }
+ EOF. { ret "<eof>"; }
}
}
-pred can_begin_expr(token t) -> bool {
- alt (t) {
- case (LPAREN) { true }
- case (LBRACE) { true }
- case (LBRACKET) { true }
- case (IDENT(_,_)) { true }
- case (UNDERSCORE) { true }
- case (TILDE) { true }
- case (LIT_INT(_)) { true }
- case (LIT_UINT(_)) { true }
- case (LIT_MACH_INT(_,_)) { true }
- case (LIT_FLOAT(_)) { true }
- case (LIT_MACH_FLOAT(_,_)) { true }
- case (LIT_STR(_)) { true }
- case (LIT_CHAR(_)) { true }
- case (POUND) { true }
- case (AT) { true }
- case (NOT) { true }
- case (BINOP(MINUS)) { true }
- case (BINOP(STAR)) { true }
- case (_) { false }
+pred can_begin_expr(t: token) -> bool {
+ alt t {
+ LPAREN. { true }
+ LBRACE. { true }
+ LBRACKET. { true }
+ IDENT(_, _) { true }
+ UNDERSCORE. { true }
+ TILDE. { true }
+ LIT_INT(_) { true }
+ LIT_UINT(_) { true }
+ LIT_MACH_INT(_, _) { true }
+ LIT_FLOAT(_) { true }
+ LIT_MACH_FLOAT(_, _) { true }
+ LIT_STR(_) { true }
+ LIT_CHAR(_) { true }
+ POUND. { true }
+ AT. { true }
+ NOT. { true }
+ BINOP(MINUS.) { true }
+ BINOP(STAR.) { true }
+ _ { false }
}
}
// Local Variables:
diff --git a/src/comp/syntax/print/pp.rs b/src/comp/syntax/print/pp.rs
index 96875bf..b1f8478 100644
--- a/src/comp/syntax/print/pp.rs
+++ b/src/comp/syntax/print/pp.rs
@@ -58,32 +58,32 @@
*/
tag breaks { consistent; inconsistent; }
-type break_t = rec(int offset, int blank_space);
+type break_t = {offset: int, blank_space: int};
-type begin_t = rec(int offset, breaks breaks);
+type begin_t = {offset: int, breaks: breaks};
tag token { STRING(str, int); BREAK(break_t); BEGIN(begin_t); END; EOF; }
-fn tok_str(token t) -> str {
- alt (t) {
- case (STRING(?s, ?len)) { ret #fmt("STR(%s,%d)", s, len); }
- case (BREAK(_)) { ret "BREAK"; }
- case (BEGIN(_)) { ret "BEGIN"; }
- case (END) { ret "END"; }
- case (EOF) { ret "EOF"; }
+fn tok_str(t: token) -> str {
+ alt t {
+ STRING(s, len) { ret #fmt("STR(%s,%d)", s, len); }
+ BREAK(_) { ret "BREAK"; }
+ BEGIN(_) { ret "BEGIN"; }
+ END. { ret "END"; }
+ EOF. { ret "EOF"; }
}
}
-fn buf_str(&token[mutable] toks, &int[mutable] szs, uint left, uint right,
- uint lim) -> str {
- auto n = ivec::len(toks);
+fn buf_str(toks: &token[mutable ], szs: &int[mutable ], left: uint,
+ right: uint, lim: uint) -> str {
+ let n = ivec::len(toks);
assert (n == ivec::len(szs));
- auto i = left;
- auto L = lim;
- auto s = "[";
- while (i != right && L != 0u) {
+ let i = left;
+ let L = lim;
+ let s = "[";
+ while i != right && L != 0u {
L -= 1u;
- if (i != left) { s += ", "; }
+ if i != left { s += ", "; }
s += #fmt("%d=%s", szs.(i), tok_str(toks.(i)));
i += 1u;
i %= n;
@@ -94,30 +94,30 @@
tag print_stack_break { fits; broken(breaks); }
-type print_stack_elt = rec(int offset, print_stack_break pbreak);
+type print_stack_elt = {offset: int, pbreak: print_stack_break};
-const int size_infinity = 0xffff;
+const size_infinity: int = 0xffff;
-fn mk_printer(ioivec::writer out, uint linewidth) -> printer {
+fn mk_printer(out: ioivec::writer, linewidth: uint) -> printer {
// Yes 3, it makes the ring buffers big enough to never
// fall behind.
- let uint n = 3u * linewidth;
+ let n: uint = 3u * linewidth;
log #fmt("mk_printer %u", linewidth);
- let token[mutable] token = ivec::init_elt_mut(EOF, n);
- let int[mutable] size = ivec::init_elt_mut(0, n);
- let uint[mutable] scan_stack = ivec::init_elt_mut(0u, n);
- let print_stack_elt[] print_stack = ~[];
+ let token: token[mutable ] = ivec::init_elt_mut(EOF, n);
+ let size: int[mutable ] = ivec::init_elt_mut(0, n);
+ let scan_stack: uint[mutable ] = ivec::init_elt_mut(0u, n);
+ let print_stack: print_stack_elt[] = ~[];
ret printer(out, n, linewidth as int, // margin
- linewidth as int, // space
- 0u, // left
- 0u, // right
- token, size, 0, // left_total
- 0, // right_total
- scan_stack, true, // scan_stack_empty
- 0u, // top
- 0u, // bottom
- print_stack, 0);
+ linewidth as int, // space
+ 0u, // left
+ 0u, // right
+ token, size, 0, // left_total
+ 0, // right_total
+ scan_stack, true, // scan_stack_empty
+ 0u, // top
+ 0u, // bottom
+ print_stack, 0);
}
@@ -198,23 +198,24 @@
* the method called 'pretty_print', and the 'PRINT' process is the method
* called 'print'.
*/
-obj printer(ioivec::writer out,
- uint buf_len,
- mutable int margin, // width of lines we're constrained to
+obj printer(out: ioivec::writer,
+ buf_len: uint,
+ mutable margin: int, // width of lines we're constrained to
- mutable int space, // number of spaces left on line
+ mutable space: int, // number of spaces left on line
- mutable uint left, // index of left side of input stream
+ mutable left: uint, // index of left side of input stream
- mutable uint right, // index of right side of input stream
+ mutable right: uint, // index of right side of input stream
- mutable token[mutable] token,
- // ring-buffr stream goes through
- mutable int[mutable] size, // ring-buffer of calculated sizes
+ mutable token: token[mutable ],
- mutable int left_total, // running size of stream "...left"
+ // ring-buffr stream goes through
+ mutable size: int[mutable ], // ring-buffer of calculated sizes
- mutable int right_total, // running size of stream "...right"
+ mutable left_total: int, // running size of stream "...left"
+
+ mutable right_total: int, // running size of stream "...right"
// pseudo-stack, really a ring too. Holds the
// primary-ring-buffers index of the BEGIN that started the
@@ -222,118 +223,115 @@
// BEGIN (if there is any) on top of it. Stuff is flushed off the
// bottom as it becomes irrelevant due to the primary ring-buffer
// advancing.
- mutable uint[mutable] scan_stack,
- mutable bool scan_stack_empty, // top==bottom disambiguator
+ mutable scan_stack: uint[mutable ],
+ mutable scan_stack_empty: bool, // top==bottom disambiguator
- mutable uint top, // index of top of scan_stack
+ mutable top: uint, // index of top of scan_stack
- mutable uint bottom, // index of bottom of scan_stack
+ mutable bottom: uint, // index of bottom of scan_stack
// stack of blocks-in-progress being flushed by print
- mutable print_stack_elt[] print_stack,
+ mutable print_stack: print_stack_elt[],
+
// buffered indentation to avoid writing trailing whitespace
- mutable int pending_indentation) {
+ mutable pending_indentation: int) {
- fn last_token() -> token {
- ret token.(right);
- }
+ fn last_token() -> token { ret token.(right); }
// be very careful with this!
- fn replace_last_token(token t) {
- token.(right) = t;
- }
+ fn replace_last_token(t: token) { token.(right) = t; }
- fn pretty_print(token t) {
+ fn pretty_print(t: token) {
log #fmt("pp [%u,%u]", left, right);
- alt (t) {
- case (EOF) {
- if (!scan_stack_empty) {
- self.check_stack(0);
- self.advance_left(token.(left), size.(left));
- }
- self.indent(0);
- }
- case (BEGIN(?b)) {
- if (scan_stack_empty) {
- left_total = 1;
- right_total = 1;
- left = 0u;
- right = 0u;
- } else { self.advance_right(); }
- log #fmt("pp BEGIN/buffer [%u,%u]", left, right);
- token.(right) = t;
- size.(right) = -right_total;
- self.scan_push(right);
- }
- case (END) {
- if (scan_stack_empty) {
- log #fmt("pp END/print [%u,%u]", left, right);
- self.print(t, 0);
- } else {
- log #fmt("pp END/buffer [%u,%u]", left, right);
- self.advance_right();
- token.(right) = t;
- size.(right) = -1;
- self.scan_push(right);
- }
- }
- case (BREAK(?b)) {
- if (scan_stack_empty) {
- left_total = 1;
- right_total = 1;
- left = 0u;
- right = 0u;
- } else { self.advance_right(); }
- log #fmt("pp BREAK/buffer [%u,%u]", left, right);
+ alt t {
+ EOF. {
+ if !scan_stack_empty {
self.check_stack(0);
- self.scan_push(right);
+ self.advance_left(token.(left), size.(left));
+ }
+ self.indent(0);
+ }
+ BEGIN(b) {
+ if scan_stack_empty {
+ left_total = 1;
+ right_total = 1;
+ left = 0u;
+ right = 0u;
+ } else { self.advance_right(); }
+ log #fmt("pp BEGIN/buffer [%u,%u]", left, right);
+ token.(right) = t;
+ size.(right) = -right_total;
+ self.scan_push(right);
+ }
+ END. {
+ if scan_stack_empty {
+ log #fmt("pp END/print [%u,%u]", left, right);
+ self.print(t, 0);
+ } else {
+ log #fmt("pp END/buffer [%u,%u]", left, right);
+ self.advance_right();
token.(right) = t;
- size.(right) = -right_total;
- right_total += b.blank_space;
+ size.(right) = -1;
+ self.scan_push(right);
}
- case (STRING(?s, ?len)) {
- if (scan_stack_empty) {
- log #fmt("pp STRING/print [%u,%u]", left, right);
- self.print(t, len);
- } else {
- log #fmt("pp STRING/buffer [%u,%u]", left, right);
- self.advance_right();
- token.(right) = t;
- size.(right) = len;
- right_total += len;
- self.check_stream();
- }
+ }
+ BREAK(b) {
+ if scan_stack_empty {
+ left_total = 1;
+ right_total = 1;
+ left = 0u;
+ right = 0u;
+ } else { self.advance_right(); }
+ log #fmt("pp BREAK/buffer [%u,%u]", left, right);
+ self.check_stack(0);
+ self.scan_push(right);
+ token.(right) = t;
+ size.(right) = -right_total;
+ right_total += b.blank_space;
+ }
+ STRING(s, len) {
+ if scan_stack_empty {
+ log #fmt("pp STRING/print [%u,%u]", left, right);
+ self.print(t, len);
+ } else {
+ log #fmt("pp STRING/buffer [%u,%u]", left, right);
+ self.advance_right();
+ token.(right) = t;
+ size.(right) = len;
+ right_total += len;
+ self.check_stream();
}
+ }
}
}
fn check_stream() {
log #fmt("check_stream [%u, %u] with left_total=%d, right_total=%d",
left, right, left_total, right_total);
- if (right_total - left_total > space) {
+ if right_total - left_total > space {
log #fmt("scan window is %d, longer than space on line (%d)",
right_total - left_total, space);
- if (!scan_stack_empty) {
- if (left == scan_stack.(bottom)) {
+ if !scan_stack_empty {
+ if left == scan_stack.(bottom) {
log #fmt("setting %u to infinity and popping", left);
size.(self.scan_pop_bottom()) = size_infinity;
}
}
self.advance_left(token.(left), size.(left));
- if (left != right) { self.check_stream(); }
+ if left != right { self.check_stream(); }
}
}
- fn scan_push(uint x) {
+ fn scan_push(x: uint) {
log #fmt("scan_push %u", x);
- if (scan_stack_empty) {
+ if scan_stack_empty {
scan_stack_empty = false;
} else { top += 1u; top %= buf_len; assert (top != bottom); }
scan_stack.(top) = x;
}
fn scan_pop() -> uint {
assert (!scan_stack_empty);
- auto x = scan_stack.(top);
- if (top == bottom) {
+ let x = scan_stack.(top);
+ if top == bottom {
scan_stack_empty = true;
} else { top += buf_len - 1u; top %= buf_len; }
ret x;
@@ -344,8 +342,8 @@
}
fn scan_pop_bottom() -> uint {
assert (!scan_stack_empty);
- auto x = scan_stack.(bottom);
- if (top == bottom) {
+ let x = scan_stack.(bottom);
+ if top == bottom {
scan_stack_empty = true;
} else { bottom += 1u; bottom %= buf_len; }
ret x;
@@ -355,179 +353,172 @@
right %= buf_len;
assert (right != left);
}
- fn advance_left(token x, int L) {
+ fn advance_left(x: token, L: int) {
log #fmt("advnce_left [%u,%u], sizeof(%u)=%d", left, right, left, L);
- if (L >= 0) {
+ if L >= 0 {
self.print(x, L);
- alt (x) {
- case (BREAK(?b)) { left_total += b.blank_space; }
- case (STRING(_, ?len)) {
- assert (len == L);
- left_total += len;
- }
- case (_) { }
+ alt x {
+ BREAK(b) { left_total += b.blank_space; }
+ STRING(_, len) { assert (len == L); left_total += len; }
+ _ { }
}
- if (left != right) {
+ if left != right {
left += 1u;
left %= buf_len;
self.advance_left(token.(left), size.(left));
}
}
}
- fn check_stack(int k) {
- if (!scan_stack_empty) {
- auto x = self.scan_top();
- alt (token.(x)) {
- case (BEGIN(?b)) {
- if (k > 0) {
- size.(self.scan_pop()) = size.(x) + right_total;
- self.check_stack(k - 1);
- }
- }
- case (END) {
- // paper says + not =, but that makes no sense.
-
- size.(self.scan_pop()) = 1;
- self.check_stack(k + 1);
- }
- case (_) {
+ fn check_stack(k: int) {
+ if !scan_stack_empty {
+ let x = self.scan_top();
+ alt token.(x) {
+ BEGIN(b) {
+ if k > 0 {
size.(self.scan_pop()) = size.(x) + right_total;
- if (k > 0) { self.check_stack(k); }
+ self.check_stack(k - 1);
}
+ }
+ END. {
+ // paper says + not =, but that makes no sense.
+
+ size.(self.scan_pop()) = 1;
+ self.check_stack(k + 1);
+ }
+ _ {
+ size.(self.scan_pop()) = size.(x) + right_total;
+ if k > 0 { self.check_stack(k); }
+ }
}
}
}
- fn print_newline(int amount) {
+ fn print_newline(amount: int) {
log #fmt("NEWLINE %d", amount);
out.write_str("\n");
pending_indentation = 0;
self.indent(amount);
}
- fn indent(int amount) {
+ fn indent(amount: int) {
log #fmt("INDENT %d", amount);
pending_indentation += amount;
}
fn top() -> print_stack_elt {
- auto n = ivec::len(print_stack);
- let print_stack_elt top = rec(offset=0, pbreak=broken(inconsistent));
- if (n != 0u) { top = print_stack.(n - 1u); }
+ let n = ivec::len(print_stack);
+ let top: print_stack_elt = {offset: 0, pbreak: broken(inconsistent)};
+ if n != 0u { top = print_stack.(n - 1u); }
ret top;
}
- fn write_str(str s) {
- while (pending_indentation > 0) {
+ fn write_str(s: str) {
+ while pending_indentation > 0 {
out.write_str(" ");
pending_indentation -= 1;
}
out.write_str(s);
}
- fn print(token x, int L) {
+ fn print(x: token, L: int) {
log #fmt("print %s %d (remaining line space=%d)", tok_str(x), L,
space);
log buf_str(token, size, left, right, 6u);
- alt (x) {
- case (BEGIN(?b)) {
- if (L > space) {
- auto col = margin - space + b.offset;
- log #fmt("print BEGIN -> push broken block at col %d",
- col);
- print_stack += ~[rec(offset=col,
- pbreak=broken(b.breaks))];
+ alt x {
+ BEGIN(b) {
+ if L > space {
+ let col = margin - space + b.offset;
+ log #fmt("print BEGIN -> push broken block at col %d", col);
+ print_stack += ~[{offset: col, pbreak: broken(b.breaks)}];
+ } else {
+ log "print BEGIN -> push fitting block";
+ print_stack += ~[{offset: 0, pbreak: fits}];
+ }
+ }
+ END. {
+ log "print END -> pop END";
+ assert (ivec::len(print_stack) != 0u);
+ ivec::pop(print_stack);
+ }
+ BREAK(b) {
+ let top = self.top();
+ alt top.pbreak {
+ fits. {
+ log "print BREAK in fitting block";
+ space -= b.blank_space;
+ self.indent(b.blank_space);
+ }
+ broken(consistent.) {
+ log "print BREAK in consistent block";
+ self.print_newline(top.offset + b.offset);
+ space = margin - (top.offset + b.offset);
+ }
+ broken(inconsistent.) {
+ if L > space {
+ log "print BREAK w/ newline in inconsistent";
+ self.print_newline(top.offset + b.offset);
+ space = margin - (top.offset + b.offset);
} else {
- log "print BEGIN -> push fitting block";
- print_stack += ~[rec(offset=0, pbreak=fits)];
+ log "print BREAK w/o newline in inconsistent";
+ self.indent(b.blank_space);
+ space -= b.blank_space;
}
+ }
}
- case (END) {
- log "print END -> pop END";
- assert (ivec::len(print_stack) != 0u);
- ivec::pop(print_stack);
- }
- case (BREAK(?b)) {
- auto top = self.top();
- alt (top.pbreak) {
- case (fits) {
- log "print BREAK in fitting block";
- space -= b.blank_space;
- self.indent(b.blank_space);
- }
- case (broken(consistent)) {
- log "print BREAK in consistent block";
- self.print_newline(top.offset + b.offset);
- space = margin - (top.offset + b.offset);
- }
- case (broken(inconsistent)) {
- if (L > space) {
- log "print BREAK w/ newline in inconsistent";
- self.print_newline(top.offset + b.offset);
- space = margin - (top.offset + b.offset);
- } else {
- log "print BREAK w/o newline in inconsistent";
- self.indent(b.blank_space);
- space -= b.blank_space;
- }
- }
- }
- }
- case (STRING(?s, ?len)) {
- log "print STRING";
- assert (L == len);
- // assert L <= space;
+ }
+ STRING(s, len) {
+ log "print STRING";
+ assert (L == len);
+ // assert L <= space;
- space -= len;
- self.write_str(s);
- }
- case (EOF) {
- // EOF should never get here.
+ space -= len;
+ self.write_str(s);
+ }
+ EOF. {
+ // EOF should never get here.
- fail;
- }
+ fail;
+ }
}
}
}
// Convenience functions to talk to the printer.
-fn box(printer p, uint indent, breaks b) {
- p.pretty_print(BEGIN(rec(offset=indent as int, breaks=b)));
+fn box(p: printer, indent: uint, b: breaks) {
+ p.pretty_print(BEGIN({offset: indent as int, breaks: b}));
}
-fn ibox(printer p, uint indent) { box(p, indent, inconsistent); }
+fn ibox(p: printer, indent: uint) { box(p, indent, inconsistent); }
-fn cbox(printer p, uint indent) { box(p, indent, consistent); }
+fn cbox(p: printer, indent: uint) { box(p, indent, consistent); }
-fn break_offset(printer p, uint n, int off) {
- p.pretty_print(BREAK(rec(offset=off, blank_space=n as int)));
+fn break_offset(p: printer, n: uint, off: int) {
+ p.pretty_print(BREAK({offset: off, blank_space: n as int}));
}
-fn end(printer p) { p.pretty_print(END); }
+fn end(p: printer) { p.pretty_print(END); }
-fn eof(printer p) { p.pretty_print(EOF); }
+fn eof(p: printer) { p.pretty_print(EOF); }
-fn word(printer p, str wrd) {
+fn word(p: printer, wrd: str) {
p.pretty_print(STRING(wrd, str::char_len(wrd) as int));
}
-fn huge_word(printer p, str wrd) {
+fn huge_word(p: printer, wrd: str) {
p.pretty_print(STRING(wrd, size_infinity));
}
-fn zero_word(printer p, str wrd) { p.pretty_print(STRING(wrd, 0)); }
+fn zero_word(p: printer, wrd: str) { p.pretty_print(STRING(wrd, 0)); }
-fn spaces(printer p, uint n) { break_offset(p, n, 0); }
+fn spaces(p: printer, n: uint) { break_offset(p, n, 0); }
-fn zerobreak(printer p) { spaces(p, 0u); }
+fn zerobreak(p: printer) { spaces(p, 0u); }
-fn space(printer p) { spaces(p, 1u); }
+fn space(p: printer) { spaces(p, 1u); }
-fn hardbreak(printer p) { spaces(p, size_infinity as uint); }
+fn hardbreak(p: printer) { spaces(p, size_infinity as uint); }
-fn hardbreak_tok_offset(int off) -> token {
- ret BREAK(rec(offset=off, blank_space=size_infinity));
+fn hardbreak_tok_offset(off: int) -> token {
+ ret BREAK({offset: off, blank_space: size_infinity});
}
-fn hardbreak_tok() -> token {
- ret hardbreak_tok_offset(0);
-}
+fn hardbreak_tok() -> token { ret hardbreak_tok_offset(0); }
//
diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs
index 92a1283..fd48b10 100644
--- a/src/comp/syntax/print/pprust.rs
+++ b/src/comp/syntax/print/pprust.rs
@@ -31,93 +31,88 @@
node_expr(ps, @ast::expr);
node_pat(ps, @ast::pat);
}
-type pp_ann = rec(fn(&ann_node node) pre,
- fn(&ann_node node) post);
+type pp_ann = {pre: fn(&ann_node) , post: fn(&ann_node) };
fn no_ann() -> pp_ann {
- fn ignore(&ann_node node) {}
- ret rec(pre=ignore, post=ignore);
+ fn ignore(node: &ann_node) { }
+ ret {pre: ignore, post: ignore};
}
type ps =
- @rec(pp::printer s,
- option::t[codemap] cm,
- option::t[lexer::cmnt[]] comments,
- option::t[lexer::lit[]] literals,
- mutable uint cur_cmnt,
- mutable uint cur_lit,
- mutable pp::breaks[] boxes,
- pp_ann ann);
+ @{s: pp::printer,
+ cm: option::t[codemap],
+ comments: option::t[lexer::cmnt[]],
+ literals: option::t[lexer::lit[]],
+ mutable cur_cmnt: uint,
+ mutable cur_lit: uint,
+ mutable boxes: pp::breaks[],
+ ann: pp_ann};
-fn ibox(&ps s, uint u) {
- s.boxes += ~[pp::inconsistent];
- pp::ibox(s.s, u);
+fn ibox(s: &ps, u: uint) { s.boxes += ~[pp::inconsistent]; pp::ibox(s.s, u); }
+
+fn end(s: &ps) { ivec::pop(s.boxes); pp::end(s.s); }
+
+fn rust_printer(writer: ioivec::writer) -> ps {
+ let boxes: pp::breaks[] = ~[];
+ ret @{s: pp::mk_printer(writer, default_columns),
+ cm: none[codemap],
+ comments: none[lexer::cmnt[]],
+ literals: none[lexer::lit[]],
+ mutable cur_cmnt: 0u,
+ mutable cur_lit: 0u,
+ mutable boxes: boxes,
+ ann: no_ann()};
}
-fn end(&ps s) { ivec::pop(s.boxes); pp::end(s.s); }
+const indent_unit: uint = 4u;
+const alt_indent_unit: uint = 2u;
-fn rust_printer(ioivec::writer writer) -> ps {
- let pp::breaks[] boxes = ~[];
- ret @rec(s=pp::mk_printer(writer, default_columns),
- cm=none[codemap],
- comments=none[lexer::cmnt[]],
- literals=none[lexer::lit[]],
- mutable cur_cmnt=0u,
- mutable cur_lit=0u,
- mutable boxes=boxes,
- ann=no_ann());
-}
-
-const uint indent_unit = 4u;
-const uint alt_indent_unit = 2u;
-
-const uint default_columns = 78u;
+const default_columns: uint = 78u;
// Requires you to pass an input filename and reader so that
// it can scan the input text for comments and literals to
// copy forward.
-fn print_crate(&codemap cm, @ast::crate crate,
- str filename, ioivec::reader in,
- ioivec::writer out, &pp_ann ann) {
- let pp::breaks[] boxes = ~[];
- auto r = lexer::gather_comments_and_literals(cm, filename, in);
- auto s =
- @rec(s=pp::mk_printer(out, default_columns),
- cm=some(cm),
- comments=some(r.cmnts),
- literals=some(r.lits),
- mutable cur_cmnt=0u,
- mutable cur_lit=0u,
- mutable boxes=boxes,
- ann=ann);
+fn print_crate(cm: &codemap, crate: @ast::crate, filename: str,
+ in: ioivec::reader, out: ioivec::writer, ann: &pp_ann) {
+ let boxes: pp::breaks[] = ~[];
+ let r = lexer::gather_comments_and_literals(cm, filename, in);
+ let s =
+ @{s: pp::mk_printer(out, default_columns),
+ cm: some(cm),
+ comments: some(r.cmnts),
+ literals: some(r.lits),
+ mutable cur_cmnt: 0u,
+ mutable cur_lit: 0u,
+ mutable boxes: boxes,
+ ann: ann};
print_mod(s, crate.node.module, crate.node.attrs);
print_remaining_comments(s);
eof(s.s);
}
-fn ty_to_str(&ast::ty ty) -> str { be to_str(ty, print_type); }
+fn ty_to_str(ty: &ast::ty) -> str { be to_str(ty, print_type); }
-fn pat_to_str(&@ast::pat pat) -> str { be to_str(pat, print_pat); }
+fn pat_to_str(pat: &@ast::pat) -> str { be to_str(pat, print_pat); }
-fn expr_to_str(&@ast::expr e) -> str { be to_str(e, print_expr); }
+fn expr_to_str(e: &@ast::expr) -> str { be to_str(e, print_expr); }
-fn stmt_to_str(&ast::stmt s) -> str { be to_str(s, print_stmt); }
+fn stmt_to_str(s: &ast::stmt) -> str { be to_str(s, print_stmt); }
-fn item_to_str(&@ast::item i) -> str { be to_str(i, print_item); }
+fn item_to_str(i: &@ast::item) -> str { be to_str(i, print_item); }
-fn path_to_str(&ast::path p) -> str { be to_str(p, print_path); }
+fn path_to_str(p: &ast::path) -> str { be to_str(p, print_path); }
-fn fun_to_str(&ast::_fn f, str name, &ast::ty_param[] params) -> str {
- auto writer = ioivec::string_writer();
- auto s = rust_printer(writer.get_writer());
+fn fun_to_str(f: &ast::_fn, name: str, params: &ast::ty_param[]) -> str {
+ let writer = ioivec::string_writer();
+ let s = rust_printer(writer.get_writer());
print_fn(s, f.decl, f.proto, name, params);
eof(s.s);
ret writer.get_str();
}
-fn block_to_str(&ast::blk blk) -> str {
- auto writer = ioivec::string_writer();
- auto s = rust_printer(writer.get_writer());
+fn block_to_str(blk: &ast::blk) -> str {
+ let writer = ioivec::string_writer();
+ let s = rust_printer(writer.get_writer());
// containing cbox, will be closed by print-block at }
cbox(s, indent_unit);
@@ -129,35 +124,32 @@
ret writer.get_str();
}
-fn meta_item_to_str(&ast::meta_item mi) -> str {
+fn meta_item_to_str(mi: &ast::meta_item) -> str {
ret to_str(@mi, print_meta_item);
}
-fn attribute_to_str(&ast::attribute attr) -> str {
+fn attribute_to_str(attr: &ast::attribute) -> str {
be to_str(attr, print_attribute);
}
-fn cbox(&ps s, uint u) {
- s.boxes += ~[pp::consistent];
- pp::cbox(s.s, u);
-}
+fn cbox(s: &ps, u: uint) { s.boxes += ~[pp::consistent]; pp::cbox(s.s, u); }
-fn box(&ps s, uint u, pp::breaks b) {
+fn box(s: &ps, u: uint, b: pp::breaks) {
s.boxes += ~[b];
pp::box(s.s, u, b);
}
-fn nbsp(&ps s) { word(s.s, " "); }
+fn nbsp(s: &ps) { word(s.s, " "); }
-fn word_nbsp(&ps s, str w) { word(s.s, w); nbsp(s); }
+fn word_nbsp(s: &ps, w: str) { word(s.s, w); nbsp(s); }
-fn word_space(&ps s, str w) { word(s.s, w); space(s.s); }
+fn word_space(s: &ps, w: str) { word(s.s, w); space(s.s); }
-fn popen(&ps s) { word(s.s, "("); }
+fn popen(s: &ps) { word(s.s, "("); }
-fn pclose(&ps s) { word(s.s, ")"); }
+fn pclose(s: &ps) { word(s.s, ")"); }
-fn head(&ps s, str w) {
+fn head(s: &ps, w: str) {
// outer-box is consistent
cbox(s, indent_unit);
// head-box is inconsistent
@@ -166,35 +158,32 @@
word_nbsp(s, w);
}
-fn bopen(&ps s) {
+fn bopen(s: &ps) {
word(s.s, "{");
end(s); // close the head-box
}
-fn bclose_(&ps s, codemap::span span, uint indented) {
+fn bclose_(s: &ps, span: codemap::span, indented: uint) {
maybe_print_comment(s, span.hi);
break_offset_if_not_bol(s, 1u, -(indented as int));
word(s.s, "}");
end(s); // close the outer-box
}
-fn bclose(&ps s, codemap::span span) {
- bclose_(s, span, indent_unit);
+fn bclose(s: &ps, span: codemap::span) { bclose_(s, span, indent_unit); }
+
+fn is_bol(s: &ps) -> bool {
+ ret s.s.last_token() == pp::EOF ||
+ s.s.last_token() == pp::hardbreak_tok();
}
-fn is_bol(&ps s) -> bool {
- ret (s.s.last_token() == pp::EOF ||
- s.s.last_token() == pp::hardbreak_tok());
-}
-
-fn hardbreak_if_not_bol(&ps s) { if ! is_bol(s) { hardbreak(s.s); } }
-fn space_if_not_bol(&ps s) { if ! is_bol(s) { space(s.s); } }
-fn break_offset_if_not_bol(&ps s, uint n, int off) {
- if ! is_bol(s) {
+fn hardbreak_if_not_bol(s: &ps) { if !is_bol(s) { hardbreak(s.s); } }
+fn space_if_not_bol(s: &ps) { if !is_bol(s) { space(s.s); } }
+fn break_offset_if_not_bol(s: &ps, n: uint, off: int) {
+ if !is_bol(s) {
break_offset(s.s, n, off);
} else {
- if off != 0 &&
- s.s.last_token() == pp::hardbreak_tok() {
+ if off != 0 && s.s.last_token() == pp::hardbreak_tok() {
// We do something pretty sketchy here: tuck the nonzero
// offset-adjustment we were going to deposit along with the
// break into the previous hardbreak.
@@ -205,7 +194,7 @@
// Synthesizes a comment that was not textually present in the original source
// file.
-fn synth_comment(&ps s, str text) {
+fn synth_comment(s: &ps, text: str) {
word(s.s, "/*");
space(s.s);
word(s.s, text);
@@ -213,27 +202,27 @@
word(s.s, "*/");
}
-fn commasep[IN](&ps s, breaks b, &IN[] elts, fn(&ps, &IN) op) {
+fn commasep[IN](s: &ps, b: breaks, elts: &IN[], op: fn(&ps, &IN) ) {
box(s, 0u, b);
- auto first = true;
- for (IN elt in elts) {
- if (first) { first = false; } else { word_space(s, ","); }
+ let first = true;
+ for elt: IN in elts {
+ if first { first = false; } else { word_space(s, ","); }
op(s, elt);
}
end(s);
}
-fn commasep_cmnt[IN](&ps s, breaks b, &IN[] elts, fn(&ps, &IN) op,
- fn(&IN) -> codemap::span get_span) {
+fn commasep_cmnt[IN](s: &ps, b: breaks, elts: &IN[], op: fn(&ps, &IN) ,
+ get_span: fn(&IN) -> codemap::span ) {
box(s, 0u, b);
- auto len = ivec::len[IN](elts);
- auto i = 0u;
- for (IN elt in elts) {
+ let len = ivec::len[IN](elts);
+ let i = 0u;
+ for elt: IN in elts {
maybe_print_comment(s, get_span(elt).hi);
op(s, elt);
i += 1u;
- if (i < len) {
+ if i < len {
word(s.s, ",");
maybe_print_trailing_comment(s, get_span(elt),
some(get_span(elts.(i)).hi));
@@ -243,136 +232,125 @@
end(s);
}
-fn commasep_exprs(&ps s, breaks b, &(@ast::expr)[] exprs) {
- fn expr_span(&@ast::expr expr) -> codemap::span { ret expr.span; }
+fn commasep_exprs(s: &ps, b: breaks, exprs: &(@ast::expr)[]) {
+ fn expr_span(expr: &@ast::expr) -> codemap::span { ret expr.span; }
commasep_cmnt(s, b, exprs, print_expr, expr_span);
}
-fn print_mod(&ps s, &ast::_mod _mod, &ast::attribute[] attrs) {
+fn print_mod(s: &ps, _mod: &ast::_mod, attrs: &ast::attribute[]) {
print_inner_attributes(s, attrs);
- for (@ast::view_item vitem in _mod.view_items) {
+ for vitem: @ast::view_item in _mod.view_items {
print_view_item(s, vitem);
}
- for (@ast::item item in _mod.items) {
- print_item(s, item);
- }
+ for item: @ast::item in _mod.items { print_item(s, item); }
}
-fn print_native_mod(&ps s, &ast::native_mod nmod,
- &ast::attribute[] attrs) {
+fn print_native_mod(s: &ps, nmod: &ast::native_mod,
+ attrs: &ast::attribute[]) {
print_inner_attributes(s, attrs);
- for (@ast::view_item vitem in nmod.view_items) {
+ for vitem: @ast::view_item in nmod.view_items {
print_view_item(s, vitem);
}
- for (@ast::native_item item in nmod.items) {
- print_native_item(s, item);
- }
+ for item: @ast::native_item in nmod.items { print_native_item(s, item); }
}
-fn print_boxed_type(&ps s, &@ast::ty ty) { print_type(s, *ty); }
+fn print_boxed_type(s: &ps, ty: &@ast::ty) { print_type(s, *ty); }
-fn print_type(&ps s, &ast::ty ty) {
+fn print_type(s: &ps, ty: &ast::ty) {
maybe_print_comment(s, ty.span.lo);
ibox(s, 0u);
- alt (ty.node) {
- case (ast::ty_nil) { word(s.s, "()"); }
- case (ast::ty_bool) { word(s.s, "bool"); }
- case (ast::ty_bot) { word(s.s, "!"); }
- case (ast::ty_int) { word(s.s, "int"); }
- case (ast::ty_uint) { word(s.s, "uint"); }
- case (ast::ty_float) { word(s.s, "float"); }
- case (ast::ty_machine(?tm)) { word(s.s, ast::ty_mach_to_str(tm)); }
- case (ast::ty_char) { word(s.s, "char"); }
- case (ast::ty_str) { word(s.s, "str"); }
- case (ast::ty_istr) { word(s.s, "istr"); }
- case (ast::ty_box(?mt)) { word(s.s, "@"); print_mt(s, mt); }
- case (ast::ty_vec(?mt)) {
- word(s.s, "vec[");
- print_mt(s, mt);
- word(s.s, "]");
- }
- case (ast::ty_ivec(?mt)) {
- auto parens = alt mt.ty.node {
+ alt ty.node {
+ ast::ty_nil. { word(s.s, "()"); }
+ ast::ty_bool. { word(s.s, "bool"); }
+ ast::ty_bot. { word(s.s, "!"); }
+ ast::ty_int. { word(s.s, "int"); }
+ ast::ty_uint. { word(s.s, "uint"); }
+ ast::ty_float. { word(s.s, "float"); }
+ ast::ty_machine(tm) { word(s.s, ast::ty_mach_to_str(tm)); }
+ ast::ty_char. { word(s.s, "char"); }
+ ast::ty_str. { word(s.s, "str"); }
+ ast::ty_istr. { word(s.s, "istr"); }
+ ast::ty_box(mt) { word(s.s, "@"); print_mt(s, mt); }
+ ast::ty_vec(mt) { word(s.s, "vec["); print_mt(s, mt); word(s.s, "]"); }
+ ast::ty_ivec(mt) {
+ let parens =
+ alt mt.ty.node {
ast::ty_box(_) | ast::ty_vec(_) | ast::ty_ptr(_) |
- ast::ty_port(_) | ast::ty_chan(_) { true }
- ast::ty_path(?pt, _) { ivec::len(pt.node.types) > 0u }
+ ast::ty_port(_) | ast::ty_chan(_) {
+ true
+ }
+ ast::ty_path(pt, _) { ivec::len(pt.node.types) > 0u }
_ { false }
};
- if parens { popen(s); }
- print_type(s, *mt.ty);
- if parens { pclose(s); }
- word(s.s, "[");
- print_mutability(s, mt.mut);
- word(s.s, "]");
+ if parens { popen(s); }
+ print_type(s, *mt.ty);
+ if parens { pclose(s); }
+ word(s.s, "[");
+ print_mutability(s, mt.mut);
+ word(s.s, "]");
+ }
+ ast::ty_ptr(mt) { word(s.s, "*"); print_mt(s, mt); }
+ ast::ty_task. { word(s.s, "task"); }
+ ast::ty_port(t) {
+ word(s.s, "port[");
+ print_type(s, *t);
+ word(s.s, "]");
+ }
+ ast::ty_chan(t) {
+ word(s.s, "chan[");
+ print_type(s, *t);
+ word(s.s, "]");
+ }
+ ast::ty_rec(fields) {
+ word(s.s, "{");
+ fn print_field(s: &ps, f: &ast::ty_field) {
+ cbox(s, indent_unit);
+ print_mutability(s, f.node.mt.mut);
+ word(s.s, f.node.ident);
+ word_space(s, ":");
+ print_type(s, *f.node.mt.ty);
+ end(s);
}
- case (ast::ty_ptr(?mt)) {
- word(s.s, "*");
- print_mt(s, mt);
+ fn get_span(f: &ast::ty_field) -> codemap::span { ret f.span; }
+ commasep_cmnt(s, consistent, fields, print_field, get_span);
+ word(s.s, "}");
+ }
+ ast::ty_fn(proto, inputs, output, cf, constrs) {
+ print_ty_fn(s, proto, none[str], inputs, output, cf, constrs);
+ }
+ ast::ty_obj(methods) {
+ head(s, "obj");
+ bopen(s);
+ for m: ast::ty_method in methods {
+ hardbreak_if_not_bol(s);
+ cbox(s, indent_unit);
+ maybe_print_comment(s, m.span.lo);
+ print_ty_fn(s, m.node.proto, some(m.node.ident), m.node.inputs,
+ m.node.output, m.node.cf, m.node.constrs);
+ word(s.s, ";");
+ end(s);
}
- case (ast::ty_task) {
- word(s.s, "task");
- }
- case (ast::ty_port(?t)) {
- word(s.s, "port[");
- print_type(s, *t);
- word(s.s, "]");
- }
- case (ast::ty_chan(?t)) {
- word(s.s, "chan[");
- print_type(s, *t);
- word(s.s, "]");
- }
- case (ast::ty_rec(?fields)) {
- word(s.s, "{");
- fn print_field(&ps s, &ast::ty_field f) {
- cbox(s, indent_unit);
- print_mutability(s, f.node.mt.mut);
- word(s.s, f.node.ident);
- word_space(s, ":");
- print_type(s, *f.node.mt.ty);
- end(s);
- }
- fn get_span(&ast::ty_field f) -> codemap::span { ret f.span; }
- commasep_cmnt(s, consistent, fields, print_field, get_span);
- word(s.s, "}");
- }
- case (ast::ty_fn(?proto, ?inputs, ?output, ?cf, ?constrs)) {
- print_ty_fn(s, proto, none[str], inputs, output, cf, constrs);
- }
- case (ast::ty_obj(?methods)) {
- head(s, "obj");
- bopen(s);
- for (ast::ty_method m in methods) {
- hardbreak_if_not_bol(s);
- cbox(s, indent_unit);
- maybe_print_comment(s, m.span.lo);
- print_ty_fn(s, m.node.proto, some(m.node.ident),
- m.node.inputs, m.node.output, m.node.cf,
- m.node.constrs);
- word(s.s, ";");
- end(s);
- }
- bclose(s, ty.span);
- }
- case (ast::ty_path(?path, _)) { print_path(s, path); }
- case (ast::ty_type) { word(s.s, "type"); }
- case (ast::ty_constr(?t, ?cs)) {
- print_type(s, *t);
- space(s.s);
- word(s.s, ":");
- space(s.s);
- word(s.s, ast_ty_constrs_str(cs));
- }
+ bclose(s, ty.span);
+ }
+ ast::ty_path(path, _) { print_path(s, path); }
+ ast::ty_type. { word(s.s, "type"); }
+ ast::ty_constr(t, cs) {
+ print_type(s, *t);
+ space(s.s);
+ word(s.s, ":");
+ space(s.s);
+ word(s.s, ast_ty_constrs_str(cs));
+ }
}
end(s);
}
-fn print_native_item(&ps s, &@ast::native_item item) {
+fn print_native_item(s: &ps, item: &@ast::native_item) {
hardbreak_if_not_bol(s);
maybe_print_comment(s, item.span.lo);
print_outer_attributes(s, item.attrs);
- alt (item.node) {
- ast::native_item_ty {
+ alt item.node {
+ ast::native_item_ty. {
ibox(s, indent_unit);
ibox(s, 0u);
word_nbsp(s, "type");
@@ -383,16 +361,12 @@
}
- ast::native_item_fn(?lname, ?decl, ?typarams) {
- print_fn(s, decl, ast::proto_fn, item.ident,
- typarams);
- alt (lname) {
- none { }
- some(?ss) {
- space(s.s);
- word_space(s, "=");
- print_string(s, ss);
- }
+
+ ast::native_item_fn(lname, decl, typarams) {
+ print_fn(s, decl, ast::proto_fn, item.ident, typarams);
+ alt lname {
+ none. { }
+ some(ss) { space(s.s); word_space(s, "="); print_string(s, ss); }
}
end(s); // end head-ibox
word(s.s, ";");
@@ -401,193 +375,185 @@
}
}
-fn print_item(&ps s, &@ast::item item) {
+fn print_item(s: &ps, item: &@ast::item) {
hardbreak_if_not_bol(s);
maybe_print_comment(s, item.span.lo);
print_outer_attributes(s, item.attrs);
- auto ann_node = node_item(s, item);
+ let ann_node = node_item(s, item);
s.ann.pre(ann_node);
- alt (item.node) {
- case (ast::item_const(?ty, ?expr)) {
- head(s, "const");
- word_space(s, item.ident + ":");
- print_type(s, *ty);
- space(s.s);
- end(s); // end the head-ibox
+ alt item.node {
+ ast::item_const(ty, expr) {
+ head(s, "const");
+ word_space(s, item.ident + ":");
+ print_type(s, *ty);
+ space(s.s);
+ end(s); // end the head-ibox
+ word_space(s, "=");
+ print_expr(s, expr);
+ word(s.s, ";");
+ end(s); // end the outer cbox
+
+ }
+ ast::item_fn(_fn, typarams) {
+ print_fn(s, _fn.decl, _fn.proto, item.ident, typarams);
+ word(s.s, " ");
+ print_block(s, _fn.body);
+ }
+ ast::item_mod(_mod) {
+ head(s, "mod");
+ word_nbsp(s, item.ident);
+ bopen(s);
+ print_mod(s, _mod, item.attrs);
+ bclose(s, item.span);
+ }
+ ast::item_native_mod(nmod) {
+ head(s, "native");
+ alt nmod.abi {
+ ast::native_abi_llvm. { word_nbsp(s, "\"llvm\""); }
+ ast::native_abi_rust. { word_nbsp(s, "\"rust\""); }
+ ast::native_abi_cdecl. { word_nbsp(s, "\"cdecl\""); }
+ ast::native_abi_rust_intrinsic. {
+ word_nbsp(s, "\"rust-intrinsic\"");
+ }
+ ast::native_abi_x86stdcall. { word_nbsp(s, "\"x86stdcall\""); }
+ }
+ word_nbsp(s, "mod");
+ word_nbsp(s, item.ident);
+ if !str::eq(nmod.native_name, item.ident) {
word_space(s, "=");
- print_expr(s, expr);
- word(s.s, ";");
- end(s); // end the outer cbox
+ print_string(s, nmod.native_name);
+ nbsp(s);
+ }
+ bopen(s);
+ print_native_mod(s, nmod, item.attrs);
+ bclose(s, item.span);
+ }
+ ast::item_ty(ty, params) {
+ ibox(s, indent_unit);
+ ibox(s, 0u);
+ word_nbsp(s, "type");
+ word(s.s, item.ident);
+ print_type_params(s, params);
+ end(s); // end the inner ibox
- }
- case (ast::item_fn(?_fn, ?typarams)) {
- print_fn(s, _fn.decl, _fn.proto, item.ident, typarams);
- word(s.s, " ");
- print_block(s, _fn.body);
- }
- case (ast::item_mod(?_mod)) {
- head(s, "mod");
- word_nbsp(s, item.ident);
- bopen(s);
- print_mod(s, _mod, item.attrs);
- bclose(s, item.span);
- }
- case (ast::item_native_mod(?nmod)) {
- head(s, "native");
- alt (nmod.abi) {
- case (ast::native_abi_llvm) { word_nbsp(s, "\"llvm\""); }
- case (ast::native_abi_rust) { word_nbsp(s, "\"rust\""); }
- case (ast::native_abi_cdecl) { word_nbsp(s, "\"cdecl\""); }
- case (ast::native_abi_rust_intrinsic) {
- word_nbsp(s, "\"rust-intrinsic\"");
- }
- case (ast::native_abi_x86stdcall) {
- word_nbsp(s, "\"x86stdcall\"");
- }
- }
- word_nbsp(s, "mod");
- word_nbsp(s, item.ident);
- if !str::eq(nmod.native_name, item.ident) {
- word_space(s, "=");
- print_string(s, nmod.native_name);
- nbsp(s);
- }
- bopen(s);
- print_native_mod(s, nmod, item.attrs);
- bclose(s, item.span);
- }
- case (ast::item_ty(?ty, ?params)) {
- ibox(s, indent_unit);
- ibox(s, 0u);
- word_nbsp(s, "type");
- word(s.s, item.ident);
- print_type_params(s, params);
- end(s); // end the inner ibox
-
- space(s.s);
- word_space(s, "=");
- print_type(s, *ty);
- word(s.s, ";");
- end(s); // end the outer ibox
- }
- case (ast::item_tag(?variants, ?params)) {
- auto newtype = ivec::len(variants) == 1u &&
+ space(s.s);
+ word_space(s, "=");
+ print_type(s, *ty);
+ word(s.s, ";");
+ end(s); // end the outer ibox
+ }
+ ast::item_tag(variants, params) {
+ let newtype =
+ ivec::len(variants) == 1u &&
str::eq(item.ident, variants.(0).node.name) &&
ivec::len(variants.(0).node.args) == 1u;
- if (newtype) {
- ibox(s, indent_unit);
- word_space(s, "tag");
- } else {
- head(s, "tag");
- }
- word(s.s, item.ident);
- print_type_params(s, params);
- space(s.s);
- if (newtype) {
- word_space(s, "=");
- print_type(s, *variants.(0).node.args.(0).ty);
- word(s.s, ";");
- end(s);
- } else {
- bopen(s);
- for (ast::variant v in variants) {
- space(s.s);
- maybe_print_comment(s, v.span.lo);
- word(s.s, v.node.name);
- if (ivec::len(v.node.args) > 0u) {
- popen(s);
- fn print_variant_arg(&ps s, &ast::variant_arg arg) {
- print_type(s, *arg.ty);
- }
- commasep(s, consistent, v.node.args,
- print_variant_arg);
- pclose(s);
- }
- word(s.s, ";");
- maybe_print_trailing_comment(s, v.span, none[uint]);
- }
- bclose(s, item.span);
- }
- }
- case (ast::item_obj(?_obj, ?params, _)) {
- head(s, "obj");
- word(s.s, item.ident);
- print_type_params(s, params);
- popen(s);
- fn print_field(&ps s, &ast::obj_field field) {
- ibox(s, indent_unit);
- print_mutability(s, field.mut);
- word_space(s, field.ident + ":");
- print_type(s, *field.ty);
- end(s);
- }
- fn get_span(&ast::obj_field f) -> codemap::span { ret f.ty.span; }
- commasep_cmnt(s, consistent, _obj.fields, print_field,
- get_span);
- pclose(s);
- space(s.s);
+ if newtype {
+ ibox(s, indent_unit);
+ word_space(s, "tag");
+ } else { head(s, "tag"); }
+ word(s.s, item.ident);
+ print_type_params(s, params);
+ space(s.s);
+ if newtype {
+ word_space(s, "=");
+ print_type(s, *variants.(0).node.args.(0).ty);
+ word(s.s, ";");
+ end(s);
+ } else {
bopen(s);
- for (@ast::method meth in _obj.methods) {
- let ast::ty_param[] typarams = ~[];
- hardbreak_if_not_bol(s);
- maybe_print_comment(s, meth.span.lo);
- print_fn(s, meth.node.meth.decl, meth.node.meth.proto,
- meth.node.ident, typarams);
- word(s.s, " ");
- print_block(s, meth.node.meth.body);
- }
- alt (_obj.dtor) {
- case (some(?dtor)) {
- head(s, "drop");
- print_block(s, dtor.node.meth.body);
+ for v: ast::variant in variants {
+ space(s.s);
+ maybe_print_comment(s, v.span.lo);
+ word(s.s, v.node.name);
+ if ivec::len(v.node.args) > 0u {
+ popen(s);
+ fn print_variant_arg(s: &ps, arg: &ast::variant_arg) {
+ print_type(s, *arg.ty);
+ }
+ commasep(s, consistent, v.node.args, print_variant_arg);
+ pclose(s);
}
- case (_) { }
+ word(s.s, ";");
+ maybe_print_trailing_comment(s, v.span, none[uint]);
}
bclose(s, item.span);
}
- case (ast::item_res(?dt, ?dt_id, ?tps, ?ct_id)) {
- head(s, "resource");
- word(s.s, item.ident);
- print_type_params(s, tps);
- popen(s);
- word_space(s, dt.decl.inputs.(0).ident + ":");
- print_type(s, *dt.decl.inputs.(0).ty);
- pclose(s);
- space(s.s);
- print_block(s, dt.body);
+ }
+ ast::item_obj(_obj, params, _) {
+ head(s, "obj");
+ word(s.s, item.ident);
+ print_type_params(s, params);
+ popen(s);
+ fn print_field(s: &ps, field: &ast::obj_field) {
+ ibox(s, indent_unit);
+ print_mutability(s, field.mut);
+ word_space(s, field.ident + ":");
+ print_type(s, *field.ty);
+ end(s);
}
+ fn get_span(f: &ast::obj_field) -> codemap::span { ret f.ty.span; }
+ commasep_cmnt(s, consistent, _obj.fields, print_field, get_span);
+ pclose(s);
+ space(s.s);
+ bopen(s);
+ for meth: @ast::method in _obj.methods {
+ let typarams: ast::ty_param[] = ~[];
+ hardbreak_if_not_bol(s);
+ maybe_print_comment(s, meth.span.lo);
+ print_fn(s, meth.node.meth.decl, meth.node.meth.proto,
+ meth.node.ident, typarams);
+ word(s.s, " ");
+ print_block(s, meth.node.meth.body);
+ }
+ alt _obj.dtor {
+ some(dtor) { head(s, "drop"); print_block(s, dtor.node.meth.body); }
+ _ { }
+ }
+ bclose(s, item.span);
+ }
+ ast::item_res(dt, dt_id, tps, ct_id) {
+ head(s, "resource");
+ word(s.s, item.ident);
+ print_type_params(s, tps);
+ popen(s);
+ word_space(s, dt.decl.inputs.(0).ident + ":");
+ print_type(s, *dt.decl.inputs.(0).ty);
+ pclose(s);
+ space(s.s);
+ print_block(s, dt.body);
+ }
}
s.ann.post(ann_node);
}
-fn print_outer_attributes(&ps s, &ast::attribute[] attrs) {
- auto count = 0;
- for (ast::attribute attr in attrs) {
- alt (attr.node.style) {
- case (ast::attr_outer) { print_attribute(s, attr); count += 1; }
- case (_) {/* fallthrough */ }
+fn print_outer_attributes(s: &ps, attrs: &ast::attribute[]) {
+ let count = 0;
+ for attr: ast::attribute in attrs {
+ alt attr.node.style {
+ ast::attr_outer. { print_attribute(s, attr); count += 1; }
+ _ {/* fallthrough */ }
}
}
- if (count > 0) { hardbreak_if_not_bol(s); }
+ if count > 0 { hardbreak_if_not_bol(s); }
}
-fn print_inner_attributes(&ps s, &ast::attribute[] attrs) {
- auto count = 0;
- for (ast::attribute attr in attrs) {
- alt (attr.node.style) {
- case (ast::attr_inner) {
- print_attribute(s, attr);
- word(s.s, ";");
- count += 1;
- }
- case (_) { /* fallthrough */ }
+fn print_inner_attributes(s: &ps, attrs: &ast::attribute[]) {
+ let count = 0;
+ for attr: ast::attribute in attrs {
+ alt attr.node.style {
+ ast::attr_inner. {
+ print_attribute(s, attr);
+ word(s.s, ";");
+ count += 1;
+ }
+ _ {/* fallthrough */ }
}
}
- if (count > 0) { hardbreak_if_not_bol(s); }
+ if count > 0 { hardbreak_if_not_bol(s); }
}
-fn print_attribute(&ps s, &ast::attribute attr) {
+fn print_attribute(s: &ps, attr: &ast::attribute) {
hardbreak_if_not_bol(s);
maybe_print_comment(s, attr.span.lo);
word(s.s, "#[");
@@ -595,607 +561,561 @@
word(s.s, "]");
}
-fn print_stmt(&ps s, &ast::stmt st) {
+fn print_stmt(s: &ps, st: &ast::stmt) {
maybe_print_comment(s, st.span.lo);
- alt (st.node) {
- case (ast::stmt_decl(?decl, _)) { print_decl(s, decl); }
- case (ast::stmt_expr(?expr, _)) {
- space_if_not_bol(s);
- print_expr(s, expr);
- }
+ alt st.node {
+ ast::stmt_decl(decl, _) { print_decl(s, decl); }
+ ast::stmt_expr(expr, _) { space_if_not_bol(s); print_expr(s, expr); }
}
- if (parse::parser::stmt_ends_with_semi(st)) { word(s.s, ";"); }
+ if parse::parser::stmt_ends_with_semi(st) { word(s.s, ";"); }
maybe_print_trailing_comment(s, st.span, none[uint]);
}
-fn print_block(&ps s, &ast::blk blk) {
+fn print_block(s: &ps, blk: &ast::blk) {
print_possibly_embedded_block(s, blk, false, indent_unit);
}
-fn print_possibly_embedded_block(&ps s, &ast::blk blk, bool embedded,
- uint indented) {
+fn print_possibly_embedded_block(s: &ps, blk: &ast::blk, embedded: bool,
+ indented: uint) {
maybe_print_comment(s, blk.span.lo);
- auto ann_node = node_block(s, blk);
+ let ann_node = node_block(s, blk);
s.ann.pre(ann_node);
- if (embedded) {
- word(s.s, "#{"); end(s);
- } else {
- bopen(s);
- }
- for (@ast::stmt st in blk.node.stmts) { print_stmt(s, *st) }
- alt (blk.node.expr) {
- case (some(?expr)) {
- space_if_not_bol(s);
- print_expr(s, expr);
- maybe_print_trailing_comment(s, expr.span, some(blk.span.hi));
- }
- case (_) { }
+ if embedded { word(s.s, "#{"); end(s); } else { bopen(s); }
+ for st: @ast::stmt in blk.node.stmts { print_stmt(s, *st) }
+ alt blk.node.expr {
+ some(expr) {
+ space_if_not_bol(s);
+ print_expr(s, expr);
+ maybe_print_trailing_comment(s, expr.span, some(blk.span.hi));
+ }
+ _ { }
}
bclose_(s, blk.span, indented);
s.ann.post(ann_node);
}
-fn print_if(&ps s, &@ast::expr test, &ast::blk blk,
- &option::t[@ast::expr] elseopt, bool chk) {
+fn print_if(s: &ps, test: &@ast::expr, blk: &ast::blk,
+ elseopt: &option::t[@ast::expr], chk: bool) {
head(s, "if");
- if (chk) {
- word_nbsp(s, "check");
- }
+ if chk { word_nbsp(s, "check"); }
print_expr(s, test);
space(s.s);
print_block(s, blk);
- fn do_else(&ps s, option::t[@ast::expr] els) {
- alt (els) {
- case (some(?_else)) {
- alt (_else.node) {
- // "another else-if"
- case (ast::expr_if(?i, ?t, ?e)) {
- cbox(s, indent_unit - 1u);
- ibox(s, 0u);
- word(s.s, " else if ");
- popen(s);
- print_expr(s, i);
- pclose(s);
- space(s.s);
- print_block(s, t);
- do_else(s, e);
- }
- // "final else"
- case (ast::expr_block(?b)) {
- cbox(s, indent_unit - 1u);
- ibox(s, 0u);
- word(s.s, " else ");
- print_block(s, b);
- }
- }
+ fn do_else(s: &ps, els: option::t[@ast::expr]) {
+ alt els {
+ some(_else) {
+ alt _else.node {
+
+ // "another else-if"
+ ast::expr_if(i, t, e) {
+ cbox(s, indent_unit - 1u);
+ ibox(s, 0u);
+ word(s.s, " else if ");
+ popen(s);
+ print_expr(s, i);
+ pclose(s);
+ space(s.s);
+ print_block(s, t);
+ do_else(s, e);
+ }
+
+ // "final else"
+ ast::expr_block(b) {
+ cbox(s, indent_unit - 1u);
+ ibox(s, 0u);
+ word(s.s, " else ");
+ print_block(s, b);
+ }
}
- case (_) {/* fall through */ }
+ }
+ _ {/* fall through */ }
}
}
do_else(s, elseopt);
}
-fn print_mac(&ps s, &ast::mac m) {
- alt (m.node) {
- case (ast::mac_invoc(?path, ?args, ?body)) {
- word(s.s, "#");
- print_path(s, path);
- if (ivec::len(args) > 0u) {
- popen(s);
- commasep_exprs(s, inconsistent, args);
- pclose(s);
- }
- // FIXME: extension 'body'
-
- }
- case (ast::mac_embed_type(?ty)) {
- word(s.s, "#<");
- print_type(s, *ty);
- word(s.s, ">");
- }
- case (ast::mac_embed_block(?blk)) {
- print_possibly_embedded_block(s, blk, true, indent_unit);
- }
- case (ast::mac_ellipsis) {
- word(s.s, "...");
- }
- }
-}
-
-fn print_expr(&ps s, &@ast::expr expr) {
- maybe_print_comment(s, expr.span.lo);
- ibox(s, indent_unit);
- auto ann_node = node_expr(s, expr);
- s.ann.pre(ann_node);
- alt (expr.node) {
- case (ast::expr_vec(?exprs, ?mut, ?kind)) {
- ibox(s, indent_unit);
- alt (kind) {
- case (ast::sk_rc) { word(s.s, "["); }
- case (ast::sk_unique) { word(s.s, "~["); }
- }
- if (mut == ast::mut) { word_nbsp(s, "mutable"); }
- commasep_exprs(s, inconsistent, exprs);
- word(s.s, "]");
- end(s);
- }
- case (ast::expr_rec(?fields, ?wth)) {
- fn print_field(&ps s, &ast::field field) {
- ibox(s, indent_unit);
- if (field.node.mut == ast::mut) { word_nbsp(s, "mutable"); }
- word(s.s, field.node.ident);
- word_space(s, ":");
- print_expr(s, field.node.expr);
- end(s);
- }
- fn get_span(&ast::field field) -> codemap::span {
- ret field.span;
- }
- word(s.s, "{");
- commasep_cmnt(s, consistent, fields, print_field, get_span);
- alt (wth) {
- case (some(?expr)) {
- if (ivec::len(fields) > 0u) { space(s.s); }
- ibox(s, indent_unit);
- word_space(s, "with");
- print_expr(s, expr);
- end(s);
- }
- case (_) { }
- }
- word(s.s, "}");
- }
- case (ast::expr_call(?func, ?args)) {
- print_expr_parens_if_unary(s, func);
+fn print_mac(s: &ps, m: &ast::mac) {
+ alt m.node {
+ ast::mac_invoc(path, args, body) {
+ word(s.s, "#");
+ print_path(s, path);
+ if ivec::len(args) > 0u {
popen(s);
commasep_exprs(s, inconsistent, args);
pclose(s);
}
- case (ast::expr_self_method(?ident)) {
- word(s.s, "self.");
- print_ident(s, ident);
+ // FIXME: extension 'body'
+
+ }
+ ast::mac_embed_type(ty) {
+ word(s.s, "#<");
+ print_type(s, *ty);
+ word(s.s, ">");
+ }
+ ast::mac_embed_block(blk) {
+ print_possibly_embedded_block(s, blk, true, indent_unit);
+ }
+ ast::mac_ellipsis. { word(s.s, "..."); }
+ }
+}
+
+fn print_expr(s: &ps, expr: &@ast::expr) {
+ maybe_print_comment(s, expr.span.lo);
+ ibox(s, indent_unit);
+ let ann_node = node_expr(s, expr);
+ s.ann.pre(ann_node);
+ alt expr.node {
+ ast::expr_vec(exprs, mut, kind) {
+ ibox(s, indent_unit);
+ alt kind {
+ ast::sk_rc. { word(s.s, "["); }
+ ast::sk_unique. { word(s.s, "~["); }
}
- case (ast::expr_bind(?func, ?args)) {
- fn print_opt(&ps s, &option::t[@ast::expr] expr) {
- alt (expr) {
- case (some(?expr)) { print_expr(s, expr); }
- case (_) { word(s.s, "_"); }
- }
- }
- word_nbsp(s, "bind");
- print_expr(s, func);
- popen(s);
- commasep(s, inconsistent, args, print_opt);
- pclose(s);
- }
- case (ast::expr_spawn(_, _, ?e, ?es)) {
- word_nbsp(s, "spawn");
- print_expr(s, e);
- popen(s);
- commasep_exprs(s, inconsistent, es);
- pclose(s);
- }
- case (ast::expr_binary(?op, ?lhs, ?rhs)) {
- auto prec = operator_prec(op);
- print_maybe_parens(s, lhs, prec);
- space(s.s);
- word_space(s, ast::binop_to_str(op));
- print_maybe_parens(s, rhs, prec + 1);
- }
- case (ast::expr_unary(?op, ?expr)) {
- word(s.s, ast::unop_to_str(op));
- print_maybe_parens(s, expr, parse::parser::unop_prec);
- }
- case (ast::expr_lit(?lit)) { print_literal(s, lit); }
- case (ast::expr_cast(?expr, ?ty)) {
- print_maybe_parens(s, expr, parse::parser::as_prec);
- space(s.s);
- word_space(s, "as");
- print_type(s, *ty);
- }
- case (ast::expr_if(?test, ?blk, ?elseopt)) {
- print_if(s, test, blk, elseopt, false);
- }
- case (ast::expr_if_check(?test, ?blk, ?elseopt)) {
- print_if(s, test, blk, elseopt, true);
- }
- case (ast::expr_ternary(?test, ?then, ?els)) {
- print_expr(s, test);
- space(s.s);
- word_space(s, "?");
- print_expr(s, then);
- space(s.s);
+ if mut == ast::mut { word_nbsp(s, "mutable"); }
+ commasep_exprs(s, inconsistent, exprs);
+ word(s.s, "]");
+ end(s);
+ }
+ ast::expr_rec(fields, wth) {
+ fn print_field(s: &ps, field: &ast::field) {
+ ibox(s, indent_unit);
+ if field.node.mut == ast::mut { word_nbsp(s, "mutable"); }
+ word(s.s, field.node.ident);
word_space(s, ":");
- print_expr(s, els);
+ print_expr(s, field.node.expr);
+ end(s);
}
- case (ast::expr_while(?test, ?blk)) {
- head(s, "while");
- print_expr(s, test);
- space(s.s);
- print_block(s, blk);
- }
- case (ast::expr_for(?decl, ?expr, ?blk)) {
- head(s, "for");
- print_for_decl(s, decl);
- space(s.s);
- word_space(s, "in");
+ fn get_span(field: &ast::field) -> codemap::span { ret field.span; }
+ word(s.s, "{");
+ commasep_cmnt(s, consistent, fields, print_field, get_span);
+ alt wth {
+ some(expr) {
+ if ivec::len(fields) > 0u { space(s.s); }
+ ibox(s, indent_unit);
+ word_space(s, "with");
print_expr(s, expr);
- space(s.s);
- print_block(s, blk);
+ end(s);
+ }
+ _ { }
}
- case (ast::expr_for_each(?decl, ?expr, ?blk)) {
- head(s, "for each");
- print_for_decl(s, decl);
- space(s.s);
- word_space(s, "in");
- print_expr(s, expr);
- space(s.s);
- print_block(s, blk);
+ word(s.s, "}");
+ }
+ ast::expr_call(func, args) {
+ print_expr_parens_if_unary(s, func);
+ popen(s);
+ commasep_exprs(s, inconsistent, args);
+ pclose(s);
+ }
+ ast::expr_self_method(ident) {
+ word(s.s, "self.");
+ print_ident(s, ident);
+ }
+ ast::expr_bind(func, args) {
+ fn print_opt(s: &ps, expr: &option::t[@ast::expr]) {
+ alt expr {
+ some(expr) { print_expr(s, expr); }
+ _ { word(s.s, "_"); }
+ }
}
- case (ast::expr_do_while(?blk, ?expr)) {
- head(s, "do");
+ word_nbsp(s, "bind");
+ print_expr(s, func);
+ popen(s);
+ commasep(s, inconsistent, args, print_opt);
+ pclose(s);
+ }
+ ast::expr_spawn(_, _, e, es) {
+ word_nbsp(s, "spawn");
+ print_expr(s, e);
+ popen(s);
+ commasep_exprs(s, inconsistent, es);
+ pclose(s);
+ }
+ ast::expr_binary(op, lhs, rhs) {
+ let prec = operator_prec(op);
+ print_maybe_parens(s, lhs, prec);
+ space(s.s);
+ word_space(s, ast::binop_to_str(op));
+ print_maybe_parens(s, rhs, prec + 1);
+ }
+ ast::expr_unary(op, expr) {
+ word(s.s, ast::unop_to_str(op));
+ print_maybe_parens(s, expr, parse::parser::unop_prec);
+ }
+ ast::expr_lit(lit) { print_literal(s, lit); }
+ ast::expr_cast(expr, ty) {
+ print_maybe_parens(s, expr, parse::parser::as_prec);
+ space(s.s);
+ word_space(s, "as");
+ print_type(s, *ty);
+ }
+ ast::expr_if(test, blk, elseopt) {
+ print_if(s, test, blk, elseopt, false);
+ }
+ ast::expr_if_check(test, blk, elseopt) {
+ print_if(s, test, blk, elseopt, true);
+ }
+ ast::expr_ternary(test, then, els) {
+ print_expr(s, test);
+ space(s.s);
+ word_space(s, "?");
+ print_expr(s, then);
+ space(s.s);
+ word_space(s, ":");
+ print_expr(s, els);
+ }
+ ast::expr_while(test, blk) {
+ head(s, "while");
+ print_expr(s, test);
+ space(s.s);
+ print_block(s, blk);
+ }
+ ast::expr_for(decl, expr, blk) {
+ head(s, "for");
+ print_for_decl(s, decl);
+ space(s.s);
+ word_space(s, "in");
+ print_expr(s, expr);
+ space(s.s);
+ print_block(s, blk);
+ }
+ ast::expr_for_each(decl, expr, blk) {
+ head(s, "for each");
+ print_for_decl(s, decl);
+ space(s.s);
+ word_space(s, "in");
+ print_expr(s, expr);
+ space(s.s);
+ print_block(s, blk);
+ }
+ ast::expr_do_while(blk, expr) {
+ head(s, "do");
+ space(s.s);
+ print_block(s, blk);
+ space(s.s);
+ word_space(s, "while");
+ print_expr(s, expr);
+ }
+ ast::expr_alt(expr, arms) {
+ cbox(s, alt_indent_unit);
+ ibox(s, 4u);
+ word_nbsp(s, "alt");
+ print_expr(s, expr);
+ space(s.s);
+ bopen(s);
+ for arm: ast::arm in arms {
space(s.s);
- print_block(s, blk);
- space(s.s);
- word_space(s, "while");
- print_expr(s, expr);
- }
- case (ast::expr_alt(?expr, ?arms)) {
cbox(s, alt_indent_unit);
- ibox(s, 4u);
- word_nbsp(s, "alt");
- print_expr(s, expr);
- space(s.s);
- bopen(s);
- for (ast::arm arm in arms) {
- space(s.s);
- cbox(s, alt_indent_unit);
- ibox(s, 0u);
- auto first = true;
- for (@ast::pat p in arm.pats) {
- if (first) { first = false; }
- else { space(s.s); word_space(s, "|"); }
- print_pat(s, p);
- }
- space(s.s);
- print_possibly_embedded_block(s, arm.block, false,
- alt_indent_unit);
- }
- bclose_(s, expr.span, alt_indent_unit);
- }
- case (ast::expr_fn(?f)) {
- head(s, proto_to_str(f.proto));
- print_fn_args_and_ret(s, f.decl);
- space(s.s);
- print_block(s, f.body);
- }
- case (ast::expr_block(?blk)) {
- // containing cbox, will be closed by print-block at }
- cbox(s, indent_unit);
- // head-box, will be closed by print-block after {
ibox(s, 0u);
- print_block(s, blk);
- }
- case (ast::expr_move(?lhs, ?rhs)) {
- print_expr(s, lhs);
+ let first = true;
+ for p: @ast::pat in arm.pats {
+ if first {
+ first = false;
+ } else { space(s.s); word_space(s, "|"); }
+ print_pat(s, p);
+ }
space(s.s);
- word_space(s, "<-");
- print_expr(s, rhs);
+ print_possibly_embedded_block(s, arm.block, false,
+ alt_indent_unit);
}
- case (ast::expr_assign(?lhs, ?rhs)) {
- print_expr(s, lhs);
+ bclose_(s, expr.span, alt_indent_unit);
+ }
+ ast::expr_fn(f) {
+ head(s, proto_to_str(f.proto));
+ print_fn_args_and_ret(s, f.decl);
+ space(s.s);
+ print_block(s, f.body);
+ }
+ ast::expr_block(blk) {
+ // containing cbox, will be closed by print-block at }
+ cbox(s, indent_unit);
+ // head-box, will be closed by print-block after {
+ ibox(s, 0u);
+ print_block(s, blk);
+ }
+ ast::expr_move(lhs, rhs) {
+ print_expr(s, lhs);
+ space(s.s);
+ word_space(s, "<-");
+ print_expr(s, rhs);
+ }
+ ast::expr_assign(lhs, rhs) {
+ print_expr(s, lhs);
+ space(s.s);
+ word_space(s, "=");
+ print_expr(s, rhs);
+ }
+ ast::expr_swap(lhs, rhs) {
+ print_expr(s, lhs);
+ space(s.s);
+ word_space(s, "<->");
+ print_expr(s, rhs);
+ }
+ ast::expr_assign_op(op, lhs, rhs) {
+ print_expr(s, lhs);
+ space(s.s);
+ word(s.s, ast::binop_to_str(op));
+ word_space(s, "=");
+ print_expr(s, rhs);
+ }
+ ast::expr_send(lhs, rhs) {
+ print_expr(s, lhs);
+ space(s.s);
+ word_space(s, "<|");
+ print_expr(s, rhs);
+ }
+ ast::expr_recv(lhs, rhs) {
+ print_expr(s, lhs);
+ space(s.s);
+ word_space(s, "|>");
+ print_expr(s, rhs);
+ }
+ ast::expr_field(expr, id) {
+ print_expr_parens_if_unary(s, expr);
+ word(s.s, ".");
+ word(s.s, id);
+ }
+ ast::expr_index(expr, index) {
+ print_expr_parens_if_unary(s, expr);
+ word(s.s, ".");
+ popen(s);
+ print_expr(s, index);
+ pclose(s);
+ }
+ ast::expr_path(path) { print_path(s, path); }
+ ast::expr_fail(maybe_fail_val) {
+ word(s.s, "fail");
+ alt maybe_fail_val {
+ some(expr) { word(s.s, " "); print_expr(s, expr); }
+ _ { }
+ }
+ }
+ ast::expr_break. { word(s.s, "break"); }
+ ast::expr_cont. { word(s.s, "cont"); }
+ ast::expr_ret(result) {
+ word(s.s, "ret");
+ alt result {
+ some(expr) { word(s.s, " "); print_expr(s, expr); }
+ _ { }
+ }
+ }
+ ast::expr_put(result) {
+ word(s.s, "put");
+ alt result {
+ some(expr) { word(s.s, " "); print_expr(s, expr); }
+ _ { }
+ }
+ }
+ ast::expr_be(result) { word_nbsp(s, "be"); print_expr(s, result); }
+ ast::expr_log(lvl, expr) {
+ alt lvl { 1 { word_nbsp(s, "log"); } 0 { word_nbsp(s, "log_err"); } }
+ print_expr(s, expr);
+ }
+ ast::expr_check(m, expr) {
+ alt m {
+ ast::unchecked. { word_nbsp(s, "claim"); }
+ ast::checked. { word_nbsp(s, "check"); }
+ }
+ popen(s);
+ print_expr(s, expr);
+ pclose(s);
+ }
+ ast::expr_assert(expr) {
+ word_nbsp(s, "assert");
+ popen(s);
+ print_expr(s, expr);
+ pclose(s);
+ }
+ ast::expr_mac(m) { print_mac(s, m); }
+ ast::expr_port(ot) {
+ word(s.s, "port");
+ alt ot {
+ some(t) { word(s.s, "["); print_type(s, *t); word(s.s, "]"); }
+ none. { }
+ }
+ popen(s);
+ pclose(s);
+ }
+ ast::expr_chan(expr) {
+ word(s.s, "chan");
+ popen(s);
+ print_expr(s, expr);
+ pclose(s);
+ }
+ ast::expr_anon_obj(anon_obj) {
+ head(s, "obj");
+
+ // Fields
+ popen(s);
+ fn print_field(s: &ps, field: &ast::anon_obj_field) {
+ ibox(s, indent_unit);
+ print_mutability(s, field.mut);
+ word_space(s, field.ident + ":");
+ print_type(s, *field.ty);
space(s.s);
word_space(s, "=");
- print_expr(s, rhs);
+ print_expr(s, field.expr);
+ end(s);
}
- case (ast::expr_swap(?lhs, ?rhs)) {
- print_expr(s, lhs);
- space(s.s);
- word_space(s, "<->");
- print_expr(s, rhs);
+ fn get_span(f: &ast::anon_obj_field) -> codemap::span {
+ ret f.ty.span;
}
- case (ast::expr_assign_op(?op, ?lhs, ?rhs)) {
- print_expr(s, lhs);
- space(s.s);
- word(s.s, ast::binop_to_str(op));
- word_space(s, "=");
- print_expr(s, rhs);
+ alt anon_obj.fields {
+ none. { }
+ some(fields) {
+ commasep_cmnt(s, consistent, fields, print_field, get_span);
+ }
}
- case (ast::expr_send(?lhs, ?rhs)) {
- print_expr(s, lhs);
- space(s.s);
- word_space(s, "<|");
- print_expr(s, rhs);
- }
- case (ast::expr_recv(?lhs, ?rhs)) {
- print_expr(s, lhs);
- space(s.s);
- word_space(s, "|>");
- print_expr(s, rhs);
- }
- case (ast::expr_field(?expr, ?id)) {
- print_expr_parens_if_unary(s, expr);
- word(s.s, ".");
- word(s.s, id);
- }
- case (ast::expr_index(?expr, ?index)) {
- print_expr_parens_if_unary(s, expr);
- word(s.s, ".");
- popen(s);
- print_expr(s, index);
- pclose(s);
- }
- case (ast::expr_path(?path)) { print_path(s, path); }
- case (ast::expr_fail(?maybe_fail_val)) {
- word(s.s, "fail");
- alt (maybe_fail_val) {
- case (some(?expr)) { word(s.s, " "); print_expr(s, expr); }
- case (_) { }
- }
- }
- case (ast::expr_break) { word(s.s, "break"); }
- case (ast::expr_cont) { word(s.s, "cont"); }
- case (ast::expr_ret(?result)) {
- word(s.s, "ret");
- alt (result) {
- case (some(?expr)) { word(s.s, " "); print_expr(s, expr); }
- case (_) { }
- }
- }
- case (ast::expr_put(?result)) {
- word(s.s, "put");
- alt (result) {
- case (some(?expr)) { word(s.s, " "); print_expr(s, expr); }
- case (_) { }
- }
- }
- case (ast::expr_be(?result)) {
- word_nbsp(s, "be");
- print_expr(s, result);
- }
- case (ast::expr_log(?lvl, ?expr)) {
- alt (lvl) {
- case (1) { word_nbsp(s, "log"); }
- case (0) { word_nbsp(s, "log_err"); }
- }
- print_expr(s, expr);
- }
- case (ast::expr_check(?m, ?expr)) {
- alt (m) {
- case (ast::unchecked) {
- word_nbsp(s, "claim");
- }
- case (ast::checked) {
- word_nbsp(s, "check");
- }
- }
- popen(s);
- print_expr(s, expr);
- pclose(s);
- }
- case (ast::expr_assert(?expr)) {
- word_nbsp(s, "assert");
- popen(s);
- print_expr(s, expr);
- pclose(s);
- }
- case (ast::expr_mac(?m)) {
- print_mac(s, m);
- }
- case (ast::expr_port(?ot)) {
- word(s.s, "port");
- alt(ot) {
- case(some(?t)) {
- word(s.s, "[");
- print_type(s, *t);
- word(s.s, "]");
- }
- case(none) {}
- }
- popen(s); pclose(s);
- }
- case (ast::expr_chan(?expr)) {
- word(s.s, "chan");
- popen(s);
- print_expr(s, expr);
- pclose(s);
- }
- case (ast::expr_anon_obj(?anon_obj)) {
- head(s, "obj");
+ pclose(s);
+ space(s.s);
+ bopen(s);
- // Fields
- popen(s);
- fn print_field(&ps s, &ast::anon_obj_field field) {
- ibox(s, indent_unit);
- print_mutability(s, field.mut);
- word_space(s, field.ident + ":");
- print_type(s, *field.ty);
- space(s.s);
- word_space(s, "=");
- print_expr(s, field.expr);
- end(s);
- }
- fn get_span(&ast::anon_obj_field f) -> codemap::span {
- ret f.ty.span;
- }
- alt (anon_obj.fields) {
- case (none) { }
- case (some(?fields)) {
- commasep_cmnt(s, consistent, fields, print_field,
- get_span);
- }
- }
- pclose(s);
- space(s.s);
- bopen(s);
-
- // Methods
- for (@ast::method meth in anon_obj.methods) {
- let ast::ty_param[] typarams = ~[];
- hardbreak_if_not_bol(s);
- maybe_print_comment(s, meth.span.lo);
- print_fn(s, meth.node.meth.decl, meth.node.meth.proto,
- meth.node.ident, typarams);
- word(s.s, " ");
- print_block(s, meth.node.meth.body);
- }
- space(s.s);
-
- // With object
- alt (anon_obj.with_obj) {
- case (none) { }
- case (some(?e)) {
- word_space(s, "with");
- print_expr(s, e);
- }
- }
- bclose(s, expr.span);
+ // Methods
+ for meth: @ast::method in anon_obj.methods {
+ let typarams: ast::ty_param[] = ~[];
+ hardbreak_if_not_bol(s);
+ maybe_print_comment(s, meth.span.lo);
+ print_fn(s, meth.node.meth.decl, meth.node.meth.proto,
+ meth.node.ident, typarams);
+ word(s.s, " ");
+ print_block(s, meth.node.meth.body);
}
+ space(s.s);
+
+ // With object
+ alt anon_obj.with_obj {
+ none. { }
+ some(e) { word_space(s, "with"); print_expr(s, e); }
+ }
+ bclose(s, expr.span);
+ }
}
s.ann.post(ann_node);
end(s);
}
-fn print_expr_parens_if_unary(&ps s, &@ast::expr ex) {
- auto parens = alt ex.node {
- ast::expr_unary(_, _) { true }
- _ { false }
- };
+fn print_expr_parens_if_unary(s: &ps, ex: &@ast::expr) {
+ let parens = alt ex.node { ast::expr_unary(_, _) { true } _ { false } };
if parens { popen(s); }
print_expr(s, ex);
if parens { pclose(s); }
}
-fn print_decl(&ps s, &@ast::decl decl) {
+fn print_decl(s: &ps, decl: &@ast::decl) {
maybe_print_comment(s, decl.span.lo);
- alt (decl.node) {
- case (ast::decl_local(?locs)) {
- space_if_not_bol(s);
- ibox(s, indent_unit);
- word_nbsp(s, "let");
- fn print_local(&ps s, &@ast::local loc) {
- alt loc.node.ty {
- some(?ty) {
- ibox(s, indent_unit);
- word_space(s, loc.node.ident + ":");
- print_type(s, *ty);
- end(s);
- }
- _ {
- word(s.s, loc.node.ident);
- }
- }
- alt loc.node.init {
- some(?init) {
- nbsp(s);
- alt init.op {
- ast::init_assign { word_space(s, "="); }
- ast::init_move { word_space(s, "<-"); }
- ast::init_recv { word_space(s, "|>"); }
- }
- print_expr(s, init.expr);
- }
- _ { }
- }
+ alt decl.node {
+ ast::decl_local(locs) {
+ space_if_not_bol(s);
+ ibox(s, indent_unit);
+ word_nbsp(s, "let");
+ fn print_local(s: &ps, loc: &@ast::local) {
+ alt loc.node.ty {
+ some(ty) {
+ ibox(s, indent_unit);
+ word_space(s, loc.node.ident + ":");
+ print_type(s, *ty);
+ end(s);
+ }
+ _ { word(s.s, loc.node.ident); }
}
- fn local_span(&@ast::local loc) -> codemap::span { ret loc.span; }
- commasep_cmnt(s, consistent, locs, print_local, local_span);
- end(s);
+ alt loc.node.init {
+ some(init) {
+ nbsp(s);
+ alt init.op {
+ ast::init_assign. { word_space(s, "="); }
+ ast::init_move. { word_space(s, "<-"); }
+ ast::init_recv. { word_space(s, "|>"); }
+ }
+ print_expr(s, init.expr);
+ }
+ _ { }
+ }
}
- case (ast::decl_item(?item)) { print_item(s, item); }
+ fn local_span(loc: &@ast::local) -> codemap::span { ret loc.span; }
+ commasep_cmnt(s, consistent, locs, print_local, local_span);
+ end(s);
+ }
+ ast::decl_item(item) { print_item(s, item); }
}
}
-fn print_ident(&ps s, &ast::ident ident) { word(s.s, ident); }
+fn print_ident(s: &ps, ident: &ast::ident) { word(s.s, ident); }
-fn print_for_decl(&ps s, @ast::local loc) {
+fn print_for_decl(s: &ps, loc: @ast::local) {
word(s.s, loc.node.ident);
- alt (loc.node.ty) {
- some (?t) {
- word_space(s, ":");
- print_type(s, *t);
- }
- none {}
+ alt loc.node.ty {
+ some(t) { word_space(s, ":"); print_type(s, *t); }
+ none. { }
}
space(s.s);
}
-fn print_path(&ps s, &ast::path path) {
+fn print_path(s: &ps, path: &ast::path) {
maybe_print_comment(s, path.span.lo);
if path.node.global { word(s.s, "::"); }
- auto first = true;
- for (str id in path.node.idents) {
- if (first) { first = false; } else { word(s.s, "::"); }
+ let first = true;
+ for id: str in path.node.idents {
+ if first { first = false; } else { word(s.s, "::"); }
word(s.s, id);
}
- if (ivec::len(path.node.types) > 0u) {
+ if ivec::len(path.node.types) > 0u {
word(s.s, "[");
commasep(s, inconsistent, path.node.types, print_boxed_type);
word(s.s, "]");
}
}
-fn print_pat(&ps s, &@ast::pat pat) {
+fn print_pat(s: &ps, pat: &@ast::pat) {
maybe_print_comment(s, pat.span.lo);
- auto ann_node = node_pat(s, pat);
+ let ann_node = node_pat(s, pat);
s.ann.pre(ann_node);
- alt (pat.node) {
- case (ast::pat_wild) { word(s.s, "_"); }
- case (ast::pat_bind(?id)) { word(s.s, id); }
- case (ast::pat_lit(?lit)) { print_literal(s, lit); }
- case (ast::pat_tag(?path, ?args)) {
- print_path(s, path);
- if (ivec::len(args) > 0u) {
- popen(s);
- commasep(s, inconsistent, args, print_pat);
- pclose(s);
- } else {
- word(s.s, ".");
- }
+ alt pat.node {
+ ast::pat_wild. { word(s.s, "_"); }
+ ast::pat_bind(id) { word(s.s, id); }
+ ast::pat_lit(lit) { print_literal(s, lit); }
+ ast::pat_tag(path, args) {
+ print_path(s, path);
+ if ivec::len(args) > 0u {
+ popen(s);
+ commasep(s, inconsistent, args, print_pat);
+ pclose(s);
+ } else { word(s.s, "."); }
+ }
+ ast::pat_rec(fields, etc) {
+ word(s.s, "{");
+ fn print_field(s: &ps, f: &ast::field_pat) {
+ cbox(s, indent_unit);
+ word(s.s, f.ident);
+ word_space(s, ":");
+ print_pat(s, f.pat);
+ end(s);
}
- case (ast::pat_rec(?fields, ?etc)) {
- word(s.s, "{");
- fn print_field(&ps s, &ast::field_pat f) {
- cbox(s, indent_unit);
- word(s.s, f.ident);
- word_space(s, ":");
- print_pat(s, f.pat);
- end(s);
- }
- fn get_span(&ast::field_pat f) -> codemap::span {
- ret f.pat.span;
- }
- commasep_cmnt(s, consistent, fields, print_field, get_span);
- if (etc) {
- if (ivec::len(fields) != 0u) { word_space(s, ","); }
- word(s.s, "_");
- }
- word(s.s, "}");
+ fn get_span(f: &ast::field_pat) -> codemap::span { ret f.pat.span; }
+ commasep_cmnt(s, consistent, fields, print_field, get_span);
+ if etc {
+ if ivec::len(fields) != 0u { word_space(s, ","); }
+ word(s.s, "_");
}
- case (ast::pat_box(?inner)) {
- word(s.s, "@");
- print_pat(s, inner);
- }
+ word(s.s, "}");
+ }
+ ast::pat_box(inner) { word(s.s, "@"); print_pat(s, inner); }
}
s.ann.post(ann_node);
}
-fn print_fn(&ps s, ast::fn_decl decl, ast::proto proto, str name,
- &ast::ty_param[] typarams) {
- alt (decl.purity) {
- case (ast::impure_fn) {
- head(s, proto_to_str(proto));
- }
- case (_) { head(s, "pred"); }
+fn print_fn(s: &ps, decl: ast::fn_decl, proto: ast::proto, name: str,
+ typarams: &ast::ty_param[]) {
+ alt decl.purity {
+ ast::impure_fn. { head(s, proto_to_str(proto)); }
+ _ { head(s, "pred"); }
}
word(s.s, name);
print_type_params(s, typarams);
print_fn_args_and_ret(s, decl);
}
-fn print_fn_args_and_ret(&ps s, &ast::fn_decl decl) {
+fn print_fn_args_and_ret(s: &ps, decl: &ast::fn_decl) {
popen(s);
- fn print_arg(&ps s, &ast::arg x) {
+ fn print_arg(s: &ps, x: &ast::arg) {
ibox(s, indent_unit);
word_space(s, x.ident + ":");
print_alias(s, x.mode);
@@ -1205,89 +1125,84 @@
commasep(s, inconsistent, decl.inputs, print_arg);
pclose(s);
maybe_print_comment(s, decl.output.span.lo);
- if (decl.output.node != ast::ty_nil) {
+ if decl.output.node != ast::ty_nil {
space_if_not_bol(s);
word_space(s, "->");
print_type(s, *decl.output);
}
}
-fn print_alias(&ps s, ast::mode m) {
- alt (m) {
- case (ast::alias(true)) { word_space(s, "&mutable"); }
- case (ast::alias(false)) { word(s.s, "&"); }
- case (ast::val) { }
+fn print_alias(s: &ps, m: ast::mode) {
+ alt m {
+ ast::alias(true) { word_space(s, "&mutable"); }
+ ast::alias(false) { word(s.s, "&"); }
+ ast::val. { }
}
}
-fn print_type_params(&ps s, &ast::ty_param[] params) {
- if (ivec::len(params) > 0u) {
+fn print_type_params(s: &ps, params: &ast::ty_param[]) {
+ if ivec::len(params) > 0u {
word(s.s, "[");
- fn printParam(&ps s, &ast::ty_param param) { word(s.s, param); }
+ fn printParam(s: &ps, param: &ast::ty_param) { word(s.s, param); }
commasep(s, inconsistent, params, printParam);
word(s.s, "]");
}
}
-fn print_meta_item(&ps s, &@ast::meta_item item) {
+fn print_meta_item(s: &ps, item: &@ast::meta_item) {
ibox(s, indent_unit);
- alt (item.node) {
- case (ast::meta_word(?name)) {
- word(s.s, name);
- }
- case (ast::meta_name_value(?name, ?value)) {
- word_space(s, name);
- word_space(s, "=");
- print_literal(s, @value);
- }
- case (ast::meta_list(?name, ?items)) {
- word(s.s, name);
- popen(s);
- commasep(s, consistent, items, print_meta_item);
- pclose(s);
- }
+ alt item.node {
+ ast::meta_word(name) { word(s.s, name); }
+ ast::meta_name_value(name, value) {
+ word_space(s, name);
+ word_space(s, "=");
+ print_literal(s, @value);
+ }
+ ast::meta_list(name, items) {
+ word(s.s, name);
+ popen(s);
+ commasep(s, consistent, items, print_meta_item);
+ pclose(s);
+ }
}
end(s);
}
-fn print_view_item(&ps s, &@ast::view_item item) {
+fn print_view_item(s: &ps, item: &@ast::view_item) {
hardbreak_if_not_bol(s);
maybe_print_comment(s, item.span.lo);
- alt (item.node) {
- case (ast::view_item_use(?id, ?mta, _)) {
- head(s, "use");
- word(s.s, id);
- if (ivec::len(mta) > 0u) {
- popen(s);
- commasep(s, consistent, mta, print_meta_item);
- pclose(s);
- }
+ alt item.node {
+ ast::view_item_use(id, mta, _) {
+ head(s, "use");
+ word(s.s, id);
+ if ivec::len(mta) > 0u {
+ popen(s);
+ commasep(s, consistent, mta, print_meta_item);
+ pclose(s);
}
- case (ast::view_item_import(?id, ?ids, _)) {
- head(s, "import");
- if (!str::eq(id, ids.(ivec::len(ids) - 1u))) {
- word_space(s, id);
- word_space(s, "=");
- }
- auto first = true;
- for (str elt in ids) {
- if (first) { first = false; } else { word(s.s, "::"); }
- word(s.s, elt);
- }
+ }
+ ast::view_item_import(id, ids, _) {
+ head(s, "import");
+ if !str::eq(id, ids.(ivec::len(ids) - 1u)) {
+ word_space(s, id);
+ word_space(s, "=");
}
- case (ast::view_item_import_glob(?ids, _)) {
- head(s, "import");
- auto first = true;
- for (str elt in ids) {
- if (first) { first = false; } else { word(s.s, "::"); }
- word(s.s, elt);
- }
- word(s.s, "::*");
+ let first = true;
+ for elt: str in ids {
+ if first { first = false; } else { word(s.s, "::"); }
+ word(s.s, elt);
}
- case (ast::view_item_export(?id, _)) {
- head(s, "export");
- word(s.s, id);
+ }
+ ast::view_item_import_glob(ids, _) {
+ head(s, "import");
+ let first = true;
+ for elt: str in ids {
+ if first { first = false; } else { word(s.s, "::"); }
+ word(s.s, elt);
}
+ word(s.s, "::*");
+ }
+ ast::view_item_export(id, _) { head(s, "export"); word(s.s, id); }
}
word(s.s, ";");
end(s); // end inner head-block
@@ -1299,70 +1214,65 @@
// FIXME: The fact that this builds up the table anew for every call is
// not good. Eventually, table should be a const.
-fn operator_prec(ast::binop op) -> int {
- for (parse::parser::op_spec spec in *parse::parser::prec_table()) {
- if (spec.op == op) { ret spec.prec; }
+fn operator_prec(op: ast::binop) -> int {
+ for spec: parse::parser::op_spec in *parse::parser::prec_table() {
+ if spec.op == op { ret spec.prec; }
}
fail;
}
-fn print_maybe_parens(&ps s, &@ast::expr expr, int outer_prec) {
- auto add_them;
- alt (expr.node) {
- case (ast::expr_binary(?op, _, _)) {
- add_them = operator_prec(op) < outer_prec;
- }
- case (ast::expr_cast(_, _)) {
- add_them = parse::parser::as_prec < outer_prec;
- }
- case (ast::expr_ternary(_, _, _)) {
- add_them = parse::parser::ternary_prec < outer_prec;
- }
- case (_) { add_them = false; }
+fn print_maybe_parens(s: &ps, expr: &@ast::expr, outer_prec: int) {
+ let add_them;
+ alt expr.node {
+ ast::expr_binary(op, _, _) {
+ add_them = operator_prec(op) < outer_prec;
+ }
+ ast::expr_cast(_, _) { add_them = parse::parser::as_prec < outer_prec; }
+ ast::expr_ternary(_, _, _) {
+ add_them = parse::parser::ternary_prec < outer_prec;
+ }
+ _ { add_them = false; }
}
- if (add_them) { popen(s); }
+ if add_them { popen(s); }
print_expr(s, expr);
- if (add_them) { pclose(s); }
+ if add_them { pclose(s); }
}
-fn print_mutability(&ps s, &ast::mutability mut) {
- alt (mut) {
- case (ast::mut) { word_nbsp(s, "mutable"); }
- case (ast::maybe_mut) { word_nbsp(s, "mutable?"); }
- case (ast::imm) {/* nothing */ }
+fn print_mutability(s: &ps, mut: &ast::mutability) {
+ alt mut {
+ ast::mut. { word_nbsp(s, "mutable"); }
+ ast::maybe_mut. { word_nbsp(s, "mutable?"); }
+ ast::imm. {/* nothing */ }
}
}
-fn print_mt(&ps s, &ast::mt mt) {
+fn print_mt(s: &ps, mt: &ast::mt) {
print_mutability(s, mt.mut);
print_type(s, *mt.ty);
}
-fn print_ty_fn(&ps s, &ast::proto proto, &option::t[str] id,
- &ast::ty_arg[] inputs, &@ast::ty output,
- &ast::controlflow cf, &(@ast::constr)[] constrs) {
+fn print_ty_fn(s: &ps, proto: &ast::proto, id: &option::t[str],
+ inputs: &ast::ty_arg[], output: &@ast::ty,
+ cf: &ast::controlflow, constrs: &(@ast::constr)[]) {
ibox(s, indent_unit);
word(s.s, proto_to_str(proto));
- alt (id) {
- case (some(?id)) { word(s.s, " "); word(s.s, id); }
- case (_) { }
- }
+ alt id { some(id) { word(s.s, " "); word(s.s, id); } _ { } }
zerobreak(s.s);
popen(s);
- fn print_arg(&ps s, &ast::ty_arg input) {
+ fn print_arg(s: &ps, input: &ast::ty_arg) {
print_alias(s, input.node.mode);
print_type(s, *input.node.ty);
}
commasep(s, inconsistent, inputs, print_arg);
pclose(s);
maybe_print_comment(s, output.span.lo);
- if (output.node != ast::ty_nil) {
+ if output.node != ast::ty_nil {
space_if_not_bol(s);
ibox(s, indent_unit);
word_space(s, "->");
- alt (cf) {
- case (ast::return) { print_type(s, *output); }
- case (ast::noreturn) { word_nbsp(s, "!"); }
+ alt cf {
+ ast::return. { print_type(s, *output); }
+ ast::noreturn. { word_nbsp(s, "!"); }
}
end(s);
}
@@ -1370,254 +1280,246 @@
end(s);
}
-fn maybe_print_trailing_comment(&ps s, codemap::span span,
- option::t[uint] next_pos) {
- auto cm;
- alt (s.cm) { case (some(?ccm)) { cm = ccm; } case (_) { ret; } }
- alt (next_comment(s)) {
- case (some(?cmnt)) {
- if (cmnt.style != lexer::trailing) { ret; }
- auto span_line = codemap::lookup_char_pos(cm, span.hi);
- auto comment_line = codemap::lookup_char_pos(cm, cmnt.pos);
- auto next = cmnt.pos + 1u;
- alt (next_pos) { case (none) { } case (some(?p)) { next = p; } }
- if (span.hi < cmnt.pos && cmnt.pos < next &&
- span_line.line == comment_line.line) {
- print_comment(s, cmnt);
- s.cur_cmnt += 1u;
- }
+fn maybe_print_trailing_comment(s: &ps, span: codemap::span,
+ next_pos: option::t[uint]) {
+ let cm;
+ alt s.cm { some(ccm) { cm = ccm; } _ { ret; } }
+ alt next_comment(s) {
+ some(cmnt) {
+ if cmnt.style != lexer::trailing { ret; }
+ let span_line = codemap::lookup_char_pos(cm, span.hi);
+ let comment_line = codemap::lookup_char_pos(cm, cmnt.pos);
+ let next = cmnt.pos + 1u;
+ alt next_pos { none. { } some(p) { next = p; } }
+ if span.hi < cmnt.pos && cmnt.pos < next &&
+ span_line.line == comment_line.line {
+ print_comment(s, cmnt);
+ s.cur_cmnt += 1u;
}
- case (_) { }
+ }
+ _ { }
}
}
-fn print_remaining_comments(&ps s) {
- while (true) {
- alt (next_comment(s)) {
- case (some(?cmnt)) { print_comment(s, cmnt); s.cur_cmnt += 1u; }
- case (_) { break; }
+fn print_remaining_comments(s: &ps) {
+ while true {
+ alt next_comment(s) {
+ some(cmnt) { print_comment(s, cmnt); s.cur_cmnt += 1u; }
+ _ { break; }
}
}
}
-fn in_cbox(&ps s) -> bool {
- auto len = ivec::len(s.boxes);
- if (len == 0u) { ret false; }
+fn in_cbox(s: &ps) -> bool {
+ let len = ivec::len(s.boxes);
+ if len == 0u { ret false; }
ret s.boxes.(len - 1u) == pp::consistent;
}
-fn print_literal(&ps s, &@ast::lit lit) {
+fn print_literal(s: &ps, lit: &@ast::lit) {
maybe_print_comment(s, lit.span.lo);
- alt (next_lit(s)) {
- case (some(?lt)) {
- if (lt.pos == lit.span.lo) {
- word(s.s, lt.lit);
- s.cur_lit += 1u;
- ret;
- }
- }
- case (_) { }
+ alt next_lit(s) {
+ some(lt) {
+ if lt.pos == lit.span.lo { word(s.s, lt.lit); s.cur_lit += 1u; ret; }
+ }
+ _ { }
}
- alt (lit.node) {
- case (ast::lit_str(?st, ?kind)) {
- if (kind == ast::sk_unique) { word(s.s, "~"); }
- print_string(s, st);
- }
- case (ast::lit_char(?ch)) {
- word(s.s,
- "'" + escape_str(str::from_bytes([ch as u8]), '\'') + "'");
- }
- case (ast::lit_int(?val)) { word(s.s, int::str(val)); }
- case (ast::lit_uint(?val)) { word(s.s, uint::str(val) + "u"); }
- case (ast::lit_float(?fstr)) { word(s.s, fstr); }
- case (ast::lit_mach_int(?mach, ?val)) {
- word(s.s, int::str(val as int));
- word(s.s, ast::ty_mach_to_str(mach));
- }
- case (ast::lit_mach_float(?mach, ?val)) {
- // val is already a str
- word(s.s, val);
- word(s.s, ast::ty_mach_to_str(mach));
- }
- case (ast::lit_nil) { word(s.s, "()"); }
- case (ast::lit_bool(?val)) {
- if (val) { word(s.s, "true"); } else { word(s.s, "false"); }
+ alt lit.node {
+ ast::lit_str(st, kind) {
+ if kind == ast::sk_unique { word(s.s, "~"); }
+ print_string(s, st);
+ }
+ ast::lit_char(ch) {
+ word(s.s, "'" + escape_str(str::from_bytes([ch as u8]), '\'') + "'");
+ }
+ ast::lit_int(val) { word(s.s, int::str(val)); }
+ ast::lit_uint(val) { word(s.s, uint::str(val) + "u"); }
+ ast::lit_float(fstr) { word(s.s, fstr); }
+ ast::lit_mach_int(mach, val) {
+ word(s.s, int::str(val as int));
+ word(s.s, ast::ty_mach_to_str(mach));
+ }
+ ast::lit_mach_float(mach, val) {
+ // val is already a str
+ word(s.s, val);
+ word(s.s, ast::ty_mach_to_str(mach));
+ }
+ ast::lit_nil. { word(s.s, "()"); }
+ ast::lit_bool(val) {
+ if val { word(s.s, "true"); } else { word(s.s, "false"); }
+ }
+ }
+}
+
+fn lit_to_str(l: &@ast::lit) -> str { be to_str(l, print_literal); }
+
+fn next_lit(s: &ps) -> option::t[lexer::lit] {
+ alt s.literals {
+ some(lits) {
+ if s.cur_lit < ivec::len(lits) {
+ ret some(lits.(s.cur_lit));
+ } else { ret none[lexer::lit]; }
+ }
+ _ { ret none[lexer::lit]; }
+ }
+}
+
+fn maybe_print_comment(s: &ps, pos: uint) {
+ while true {
+ alt next_comment(s) {
+ some(cmnt) {
+ if cmnt.pos < pos {
+ print_comment(s, cmnt);
+ s.cur_cmnt += 1u;
+ } else { break; }
+ }
+ _ { break; }
}
}
}
-fn lit_to_str(&@ast::lit l) -> str { be to_str(l, print_literal); }
-
-fn next_lit(&ps s) -> option::t[lexer::lit] {
- alt (s.literals) {
- case (some(?lits)) {
- if (s.cur_lit < ivec::len(lits)) {
- ret some(lits.(s.cur_lit));
- } else { ret none[lexer::lit]; }
- }
- case (_) { ret none[lexer::lit]; }
- }
-}
-
-fn maybe_print_comment(&ps s, uint pos) {
- while (true) {
- alt (next_comment(s)) {
- case (some(?cmnt)) {
- if (cmnt.pos < pos) {
- print_comment(s, cmnt);
- s.cur_cmnt += 1u;
- } else { break; }
- }
- case (_) { break; }
- }
- }
-}
-
-fn print_comment(&ps s, lexer::cmnt cmnt) {
- alt (cmnt.style) {
- case (lexer::mixed) {
- assert (ivec::len(cmnt.lines) == 1u);
- zerobreak(s.s);
+fn print_comment(s: &ps, cmnt: lexer::cmnt) {
+ alt cmnt.style {
+ lexer::mixed. {
+ assert (ivec::len(cmnt.lines) == 1u);
+ zerobreak(s.s);
+ word(s.s, cmnt.lines.(0));
+ zerobreak(s.s);
+ }
+ lexer::isolated. {
+ pprust::hardbreak_if_not_bol(s);
+ for line: str in cmnt.lines { word(s.s, line); hardbreak(s.s); }
+ }
+ lexer::trailing. {
+ word(s.s, " ");
+ if ivec::len(cmnt.lines) == 1u {
word(s.s, cmnt.lines.(0));
- zerobreak(s.s);
- }
- case (lexer::isolated) {
- pprust::hardbreak_if_not_bol(s);
- for (str line in cmnt.lines) { word(s.s, line); hardbreak(s.s); }
- }
- case (lexer::trailing) {
- word(s.s, " ");
- if (ivec::len(cmnt.lines) == 1u) {
- word(s.s, cmnt.lines.(0));
- hardbreak(s.s);
- } else {
- ibox(s, 0u);
- for (str line in cmnt.lines) {
- word(s.s, line);
- hardbreak(s.s);
- }
- end(s);
- }
- }
- case (lexer::blank_line) {
- // We need to do at least one, possibly two hardbreaks.
- pprust::hardbreak_if_not_bol(s);
hardbreak(s.s);
+ } else {
+ ibox(s, 0u);
+ for line: str in cmnt.lines { word(s.s, line); hardbreak(s.s); }
+ end(s);
}
+ }
+ lexer::blank_line. {
+ // We need to do at least one, possibly two hardbreaks.
+ pprust::hardbreak_if_not_bol(s);
+ hardbreak(s.s);
+ }
}
}
-fn print_string(&ps s, &str st) {
+fn print_string(s: &ps, st: &str) {
word(s.s, "\"");
word(s.s, escape_str(st, '"'));
word(s.s, "\"");
}
-fn escape_str(str st, char to_escape) -> str {
- let str out = "";
- auto len = str::byte_len(st);
- auto i = 0u;
- while (i < len) {
- alt (st.(i) as char) {
- case ('\n') { out += "\\n"; }
- case ('\t') { out += "\\t"; }
- case ('\r') { out += "\\r"; }
- case ('\\') { out += "\\\\"; }
- case (?cur) {
- if (cur == to_escape) { out += "\\"; }
- // FIXME some (or all?) non-ascii things should be escaped
+fn escape_str(st: str, to_escape: char) -> str {
+ let out: str = "";
+ let len = str::byte_len(st);
+ let i = 0u;
+ while i < len {
+ alt st.(i) as char {
+ '\n' { out += "\\n"; }
+ '\t' { out += "\\t"; }
+ '\r' { out += "\\r"; }
+ '\\' { out += "\\\\"; }
+ cur {
+ if cur == to_escape { out += "\\"; }
+ // FIXME some (or all?) non-ascii things should be escaped
- str::push_char(out, cur);
- }
+ str::push_char(out, cur);
+ }
}
i += 1u;
}
ret out;
}
-fn to_str[T](&T t, fn(&ps, &T) f) -> str {
- auto writer = ioivec::string_writer();
- auto s = rust_printer(writer.get_writer());
+fn to_str[T](t: &T, f: fn(&ps, &T) ) -> str {
+ let writer = ioivec::string_writer();
+ let s = rust_printer(writer.get_writer());
f(s, t);
eof(s.s);
ret writer.get_str();
}
-fn next_comment(&ps s) -> option::t[lexer::cmnt] {
- alt (s.comments) {
- case (some(?cmnts)) {
- if (s.cur_cmnt < ivec::len(cmnts)) {
- ret some(cmnts.(s.cur_cmnt));
- } else { ret none[lexer::cmnt]; }
- }
- case (_) { ret none[lexer::cmnt]; }
+fn next_comment(s: &ps) -> option::t[lexer::cmnt] {
+ alt s.comments {
+ some(cmnts) {
+ if s.cur_cmnt < ivec::len(cmnts) {
+ ret some(cmnts.(s.cur_cmnt));
+ } else { ret none[lexer::cmnt]; }
+ }
+ _ { ret none[lexer::cmnt]; }
}
}
// Removing the aliases from the type of f in the next two functions
// triggers memory corruption, but I haven't isolated the bug yet. FIXME
-fn constr_args_to_str[T](&fn(&T) -> str f,
- &(@ast::sp_constr_arg[T])[] args) -> str {
- auto comma = false;
- auto s = "(";
- for (@ast::sp_constr_arg[T] a in args) {
- if (comma) { s += ", "; } else { comma = true; }
+fn constr_args_to_str[T](f: &fn(&T) -> str ,
+ args: &(@ast::sp_constr_arg[T])[]) -> str {
+ let comma = false;
+ let s = "(";
+ for a: @ast::sp_constr_arg[T] in args {
+ if comma { s += ", "; } else { comma = true; }
s += constr_arg_to_str[T](f, a.node);
}
s += ")";
ret s;
}
-fn constr_arg_to_str[T](&fn(&T) -> str f, &ast::constr_arg_general_[T] c) ->
- str {
- alt (c) {
- case (ast::carg_base) { ret "*"; }
- case (ast::carg_ident(?i)) { ret f(i); }
- case (ast::carg_lit(?l)) { ret lit_to_str(l); }
+fn constr_arg_to_str[T](f: &fn(&T) -> str , c: &ast::constr_arg_general_[T])
+ -> str {
+ alt c {
+ ast::carg_base. { ret "*"; }
+ ast::carg_ident(i) { ret f(i); }
+ ast::carg_lit(l) { ret lit_to_str(l); }
}
}
// needed b/c constr_args_to_str needs
// something that takes an alias
// (argh)
-fn uint_to_str(&uint i) -> str { ret uint::str(i); }
+fn uint_to_str(i: &uint) -> str { ret uint::str(i); }
-fn ast_constr_to_str(&@ast::constr c) -> str {
+fn ast_constr_to_str(c: &@ast::constr) -> str {
ret path_to_str(c.node.path) +
- constr_args_to_str(uint_to_str, c.node.args);
+ constr_args_to_str(uint_to_str, c.node.args);
}
// FIXME: fix repeated code
-fn ast_constrs_str(&(@ast::constr)[] constrs) -> str {
- auto s = "";
- auto colon = true;
- for (@ast::constr c in constrs) {
- if (colon) { s += " : "; colon = false; } else { s += ", "; }
+fn ast_constrs_str(constrs: &(@ast::constr)[]) -> str {
+ let s = "";
+ let colon = true;
+ for c: @ast::constr in constrs {
+ if colon { s += " : "; colon = false; } else { s += ", "; }
s += ast_constr_to_str(c);
}
ret s;
}
-fn proto_to_str(&ast::proto p) -> str {
- ret alt (p) {
- ast::proto_fn { "fn" }
- ast::proto_iter { "iter" }
- ast::proto_block { "block" }
- ast::proto_closure { "lambda" }
- };
+fn proto_to_str(p: &ast::proto) -> str {
+ ret alt p {
+ ast::proto_fn. { "fn" }
+ ast::proto_iter. { "iter" }
+ ast::proto_block. { "block" }
+ ast::proto_closure. { "lambda" }
+ };
}
-fn ty_constr_to_str(&@ast::ty_constr c) -> str {
+fn ty_constr_to_str(c: &@ast::ty_constr) -> str {
ret path_to_str(c.node.path) +
- constr_args_to_str[ast::path](path_to_str, c.node.args);
+ constr_args_to_str[ast::path](path_to_str, c.node.args);
}
-fn ast_ty_constrs_str(&(@ast::ty_constr)[] constrs) -> str {
- auto s = "";
- auto colon = true;
- for (@ast::ty_constr c in constrs) {
- if (colon) { s += " : "; colon = false; } else { s += ", "; }
+fn ast_ty_constrs_str(constrs: &(@ast::ty_constr)[]) -> str {
+ let s = "";
+ let colon = true;
+ for c: @ast::ty_constr in constrs {
+ if colon { s += " : "; colon = false; } else { s += ", "; }
s += ty_constr_to_str(c);
}
ret s;
diff --git a/src/comp/syntax/util/interner.rs b/src/comp/syntax/util/interner.rs
index 9717e30..ec48435 100644
--- a/src/comp/syntax/util/interner.rs
+++ b/src/comp/syntax/util/interner.rs
@@ -11,25 +11,25 @@
import std::option::some;
type interner[T] =
- rec(hashmap[T, uint] map,
- mutable T[] vect,
- hashfn[T] hasher,
- eqfn[T] eqer);
+ {map: hashmap[T, uint],
+ mutable vect: T[],
+ hasher: hashfn[T],
+ eqer: eqfn[T]};
-fn mk[T](hashfn[T] hasher, eqfn[T] eqer) -> interner[T] {
- auto m = map::mk_hashmap[T, uint](hasher, eqer);
- ret rec(map=m, mutable vect=~[], hasher=hasher, eqer=eqer);
+fn mk[T](hasher: hashfn[T], eqer: eqfn[T]) -> interner[T] {
+ let m = map::mk_hashmap[T, uint](hasher, eqer);
+ ret {map: m, mutable vect: ~[], hasher: hasher, eqer: eqer};
}
-fn intern[T](&interner[T] itr, &T val) -> uint {
- alt (itr.map.find(val)) {
- case (some(?idx)) { ret idx; }
- case (none) {
- auto new_idx = ivec::len[T](itr.vect);
- itr.map.insert(val, new_idx);
- itr.vect += ~[val];
- ret new_idx;
- }
+fn intern[T](itr: &interner[T], val: &T) -> uint {
+ alt itr.map.find(val) {
+ some(idx) { ret idx; }
+ none. {
+ let new_idx = ivec::len[T](itr.vect);
+ itr.map.insert(val, new_idx);
+ itr.vect += ~[val];
+ ret new_idx;
+ }
}
}
-fn get[T](&interner[T] itr, uint idx) -> T { ret itr.vect.(idx); }
+fn get[T](itr: &interner[T], idx: uint) -> T { ret itr.vect.(idx); }
diff --git a/src/comp/syntax/visit.rs b/src/comp/syntax/visit.rs
index b18134a..7a88b98 100644
--- a/src/comp/syntax/visit.rs
+++ b/src/comp/syntax/visit.rs
@@ -17,398 +17,335 @@
tag vt[E] { mk_vt(visitor[E]); }
type visitor[E] =
- @rec(fn(&_mod, &span, &E, &vt[E]) visit_mod,
- fn(&@view_item, &E, &vt[E]) visit_view_item,
- fn(&@native_item, &E, &vt[E]) visit_native_item,
- fn(&@item, &E, &vt[E]) visit_item,
- fn(&@local, &E, &vt[E]) visit_local,
- fn(&ast::blk, &E, &vt[E]) visit_block,
- fn(&@stmt, &E, &vt[E]) visit_stmt,
- fn(&arm, &E, &vt[E]) visit_arm,
- fn(&@pat, &E, &vt[E]) visit_pat,
- fn(&@decl, &E, &vt[E]) visit_decl,
- fn(&@expr, &E, &vt[E]) visit_expr,
- fn(&@ty, &E, &vt[E]) visit_ty,
- // takes the components so that one function can be
- // generic over constr and ty_constr
- fn(&path, &span, node_id, &E, &vt[E]) visit_constr,
- fn(&_fn, &ty_param[], &span, &fn_ident, node_id, &E, &vt[E])
- visit_fn);
+ // takes the components so that one function can be
+ // generic over constr and ty_constr
+ @{visit_mod: fn(&_mod, &span, &E, &vt[E]) ,
+ visit_view_item: fn(&@view_item, &E, &vt[E]) ,
+ visit_native_item: fn(&@native_item, &E, &vt[E]) ,
+ visit_item: fn(&@item, &E, &vt[E]) ,
+ visit_local: fn(&@local, &E, &vt[E]) ,
+ visit_block: fn(&ast::blk, &E, &vt[E]) ,
+ visit_stmt: fn(&@stmt, &E, &vt[E]) ,
+ visit_arm: fn(&arm, &E, &vt[E]) ,
+ visit_pat: fn(&@pat, &E, &vt[E]) ,
+ visit_decl: fn(&@decl, &E, &vt[E]) ,
+ visit_expr: fn(&@expr, &E, &vt[E]) ,
+ visit_ty: fn(&@ty, &E, &vt[E]) ,
+ visit_constr: fn(&path, &span, node_id, &E, &vt[E]) ,
+ visit_fn:
+ fn(&_fn, &ty_param[], &span, &fn_ident, node_id, &E, &vt[E]) };
fn default_visitor[E]() -> visitor[E] {
- ret @rec(visit_mod=bind visit_mod[E](_, _, _, _),
- visit_view_item=bind visit_view_item[E](_, _, _),
- visit_native_item=bind visit_native_item[E](_, _, _),
- visit_item=bind visit_item[E](_, _, _),
- visit_local=bind visit_local[E](_, _, _),
- visit_block=bind visit_block[E](_, _, _),
- visit_stmt=bind visit_stmt[E](_, _, _),
- visit_arm=bind visit_arm[E](_, _, _),
- visit_pat=bind visit_pat[E](_, _, _),
- visit_decl=bind visit_decl[E](_, _, _),
- visit_expr=bind visit_expr[E](_, _, _),
- visit_ty=bind visit_ty[E](_, _, _),
- visit_constr=bind visit_constr[E](_, _, _, _, _),
- visit_fn=bind visit_fn[E](_, _, _, _, _, _, _));
+ ret @{visit_mod: bind visit_mod[E](_, _, _, _),
+ visit_view_item: bind visit_view_item[E](_, _, _),
+ visit_native_item: bind visit_native_item[E](_, _, _),
+ visit_item: bind visit_item[E](_, _, _),
+ visit_local: bind visit_local[E](_, _, _),
+ visit_block: bind visit_block[E](_, _, _),
+ visit_stmt: bind visit_stmt[E](_, _, _),
+ visit_arm: bind visit_arm[E](_, _, _),
+ visit_pat: bind visit_pat[E](_, _, _),
+ visit_decl: bind visit_decl[E](_, _, _),
+ visit_expr: bind visit_expr[E](_, _, _),
+ visit_ty: bind visit_ty[E](_, _, _),
+ visit_constr: bind visit_constr[E](_, _, _, _, _),
+ visit_fn: bind visit_fn[E](_, _, _, _, _, _, _)};
}
-fn visit_crate[E](&crate c, &E e, &vt[E] v) {
+fn visit_crate[E](c: &crate, e: &E, v: &vt[E]) {
v.visit_mod(c.node.module, c.span, e, v);
}
-fn visit_crate_directive[E](&@crate_directive cd, &E e, &vt[E] v) {
- alt (cd.node) {
- case (cdir_src_mod(_, _, _)) { }
- case (cdir_dir_mod(_, _, ?cdirs, _)) {
- for (@crate_directive cdir in cdirs) {
- visit_crate_directive(cdir, e, v);
- }
+fn visit_crate_directive[E](cd: &@crate_directive, e: &E, v: &vt[E]) {
+ alt cd.node {
+ cdir_src_mod(_, _, _) { }
+ cdir_dir_mod(_, _, cdirs, _) {
+ for cdir: @crate_directive in cdirs {
+ visit_crate_directive(cdir, e, v);
}
- case (cdir_view_item(?vi)) { v.visit_view_item(vi, e, v); }
- case (cdir_syntax(_)) { }
- case (cdir_auth(_, _)) { }
+ }
+ cdir_view_item(vi) { v.visit_view_item(vi, e, v); }
+ cdir_syntax(_) { }
+ cdir_auth(_, _) { }
}
}
-fn visit_mod[E](&_mod m, &span sp, &E e, &vt[E] v) {
- for (@view_item vi in m.view_items) { v.visit_view_item(vi, e, v); }
- for (@item i in m.items) { v.visit_item(i, e, v); }
+fn visit_mod[E](m: &_mod, sp: &span, e: &E, v: &vt[E]) {
+ for vi: @view_item in m.view_items { v.visit_view_item(vi, e, v); }
+ for i: @item in m.items { v.visit_item(i, e, v); }
}
-fn visit_view_item[E](&@view_item vi, &E e, &vt[E] v) { }
+fn visit_view_item[E](vi: &@view_item, e: &E, v: &vt[E]) { }
-fn visit_local[E](&@local loc, &E e, &vt[E] v) {
- alt (loc.node.ty) {
- case (none) { }
- case (some(?t)) { v.visit_ty(t, e, v); }
- }
- alt (loc.node.init) {
- case (none) { }
- case (some(?i)) { v.visit_expr(i.expr, e, v); }
+fn visit_local[E](loc: &@local, e: &E, v: &vt[E]) {
+ alt loc.node.ty { none. { } some(t) { v.visit_ty(t, e, v); } }
+ alt loc.node.init { none. { } some(i) { v.visit_expr(i.expr, e, v); } }
+}
+
+fn visit_item[E](i: &@item, e: &E, v: &vt[E]) {
+ alt i.node {
+ item_const(t, ex) { v.visit_ty(t, e, v); v.visit_expr(ex, e, v); }
+ item_fn(f, tp) { v.visit_fn(f, tp, i.span, some(i.ident), i.id, e, v); }
+ item_mod(m) { v.visit_mod(m, i.span, e, v); }
+ item_native_mod(nm) {
+ for vi: @view_item in nm.view_items { v.visit_view_item(vi, e, v); }
+ for ni: @native_item in nm.items { v.visit_native_item(ni, e, v); }
+ }
+ item_ty(t, _) { v.visit_ty(t, e, v); }
+ item_res(f, dtor_id, tps, _) {
+ v.visit_fn(f, tps, i.span, some(i.ident), dtor_id, e, v);
+ }
+ item_tag(variants, _) {
+ for vr: variant in variants {
+ for va: variant_arg in vr.node.args { v.visit_ty(va.ty, e, v); }
+ }
+ }
+ item_obj(ob, _, _) {
+ for f: obj_field in ob.fields { v.visit_ty(f.ty, e, v); }
+ for m: @method in ob.methods {
+ v.visit_fn(m.node.meth, ~[], m.span, some(m.node.ident),
+ m.node.id, e, v);
+ }
+ alt ob.dtor {
+ none. { }
+ some(m) {
+ v.visit_fn(m.node.meth, ~[], m.span, some(m.node.ident),
+ m.node.id, e, v);
+ }
+ }
+ }
}
}
-fn visit_item[E](&@item i, &E e, &vt[E] v) {
- alt (i.node) {
- case (item_const(?t, ?ex)) {
- v.visit_ty(t, e, v);
- v.visit_expr(ex, e, v);
+fn visit_ty[E](t: &@ty, e: &E, v: &vt[E]) {
+ alt t.node {
+ ty_nil. {/* no-op */ }
+ ty_bot. {/* no-op */ }
+ ty_bool. {/* no-op */ }
+ ty_int. {/* no-op */ }
+ ty_float. {/* no-op */ }
+ ty_uint. {/* no-op */ }
+ ty_machine(_) {/* no-op */ }
+ ty_char. {/* no-op */ }
+ ty_str. {/* no-op */ }
+ ty_istr. {/* no-op */ }
+ ty_box(mt) { v.visit_ty(mt.ty, e, v); }
+ ty_vec(mt) { v.visit_ty(mt.ty, e, v); }
+ ty_ivec(mt) { v.visit_ty(mt.ty, e, v); }
+ ty_ptr(mt) { v.visit_ty(mt.ty, e, v); }
+ ty_port(t) { v.visit_ty(t, e, v); }
+ ty_chan(t) { v.visit_ty(t, e, v); }
+ ty_task. {/* no-op */ }
+ ty_rec(flds) {
+ for f: ty_field in flds { v.visit_ty(f.node.mt.ty, e, v); }
+ }
+ ty_fn(_, args, out, _, constrs) {
+ for a: ty_arg in args { v.visit_ty(a.node.ty, e, v); }
+ for c: @constr in constrs {
+ v.visit_constr(c.node.path, c.span, c.node.id, e, v);
}
- case (item_fn(?f, ?tp)) {
- v.visit_fn(f, tp, i.span, some(i.ident), i.id, e, v);
+ v.visit_ty(out, e, v);
+ }
+ ty_obj(tmeths) {
+ for m: ty_method in tmeths {
+ for a: ty_arg in m.node.inputs { v.visit_ty(a.node.ty, e, v); }
+ v.visit_ty(m.node.output, e, v);
}
- case (item_mod(?m)) { v.visit_mod(m, i.span, e, v); }
- case (item_native_mod(?nm)) {
- for (@view_item vi in nm.view_items) {
- v.visit_view_item(vi, e, v);
- }
- for (@native_item ni in nm.items) {
- v.visit_native_item(ni, e, v);
- }
+ }
+ ty_path(p, _) { for tp: @ty in p.node.types { v.visit_ty(tp, e, v); } }
+ ty_type. {/* no-op */ }
+ ty_constr(t, cs) {
+ v.visit_ty(t, e, v);
+ for tc: @spanned[constr_general_[path, node_id]] in cs {
+ v.visit_constr(tc.node.path, tc.span, tc.node.id, e, v);
}
- case (item_ty(?t, _)) { v.visit_ty(t, e, v); }
- case (item_res(?f, ?dtor_id, ?tps, _)) {
- v.visit_fn(f, tps, i.span, some(i.ident), dtor_id, e, v);
- }
- case (item_tag(?variants, _)) {
- for (variant vr in variants) {
- for (variant_arg va in vr.node.args) {
- v.visit_ty(va.ty, e, v);
- }
- }
- }
- case (item_obj(?ob, _, _)) {
- for (obj_field f in ob.fields) { v.visit_ty(f.ty, e, v); }
- for (@method m in ob.methods) {
- v.visit_fn(m.node.meth, ~[], m.span, some(m.node.ident),
- m.node.id, e, v);
- }
- alt (ob.dtor) {
- case (none) { }
- case (some(?m)) {
- v.visit_fn(m.node.meth, ~[], m.span, some(m.node.ident),
- m.node.id, e, v);
- }
- }
- }
+ }
}
}
-fn visit_ty[E](&@ty t, &E e, &vt[E] v) {
- alt (t.node) {
- case (ty_nil) { /* no-op */ }
- case (ty_bot) { /* no-op */ }
- case (ty_bool) { /* no-op */ }
- case (ty_int) { /* no-op */ }
- case (ty_float) { /* no-op */ }
- case (ty_uint) { /* no-op */ }
- case (ty_machine(_)) { /* no-op */ }
- case (ty_char) { /* no-op */ }
- case (ty_str) { /* no-op */ }
- case (ty_istr) { /* no-op */ }
- case (ty_box(?mt)) { v.visit_ty(mt.ty, e, v); }
- case (ty_vec(?mt)) { v.visit_ty(mt.ty, e, v); }
- case (ty_ivec(?mt)) { v.visit_ty(mt.ty, e, v); }
- case (ty_ptr(?mt)) { v.visit_ty(mt.ty, e, v); }
- case (ty_port(?t)) { v.visit_ty(t, e, v); }
- case (ty_chan(?t)) { v.visit_ty(t, e, v); }
- case (ty_task) { /* no-op */ }
- case (ty_rec(?flds)) {
- for (ty_field f in flds) { v.visit_ty(f.node.mt.ty, e, v); }
- }
- case (ty_fn(_, ?args, ?out, _, ?constrs)) {
- for (ty_arg a in args) { v.visit_ty(a.node.ty, e, v); }
- for (@constr c in constrs) { v.visit_constr(c.node.path,
- c.span, c.node.id, e, v); }
- v.visit_ty(out, e, v);
- }
- case (ty_obj(?tmeths)) {
- for (ty_method m in tmeths) {
- for (ty_arg a in m.node.inputs) {
- v.visit_ty(a.node.ty, e, v);
- }
- v.visit_ty(m.node.output, e, v);
- }
- }
- case (ty_path(?p, _)) {
- for (@ty tp in p.node.types) { v.visit_ty(tp, e, v); }
- }
- case (ty_type) { /* no-op */ }
- case (ty_constr(?t, ?cs)) {
- v.visit_ty(t, e, v);
- for (@spanned[constr_general_[path, node_id]] tc in cs) {
- v.visit_constr(tc.node.path, tc.span, tc.node.id, e, v);
- }
- }
- }
+fn visit_ty_opt[E](ot: &option::t[@ty], e: &E, v: &vt[E]) {
+ alt ot { none. { } some(t) { v.visit_ty(t, e, v); } }
}
-fn visit_ty_opt[E](&option::t[@ty] ot, &E e, &vt[E] v) {
- alt (ot) {
- case (none) {}
- case (some(?t)) { v.visit_ty(t, e, v); }
- }
-}
-
-fn visit_constr[E](&path operator, &span sp, node_id id, &E e, &vt[E] v) {
+fn visit_constr[E](operator: &path, sp: &span, id: node_id, e: &E,
+ v: &vt[E]) {
// default
}
-fn visit_pat[E](&@pat p, &E e, &vt[E] v) {
- alt (p.node) {
- case (pat_tag(?path, ?children)) {
- for (@ty tp in path.node.types) { v.visit_ty(tp, e, v); }
- for (@pat child in children) { v.visit_pat(child, e, v); }
- }
- case (pat_rec(?fields, _)) {
- for (field_pat f in fields) { v.visit_pat(f.pat, e, v); }
- }
- case (pat_box(?inner)) { v.visit_pat(inner, e, v); }
- case (_) { }
+fn visit_pat[E](p: &@pat, e: &E, v: &vt[E]) {
+ alt p.node {
+ pat_tag(path, children) {
+ for tp: @ty in path.node.types { v.visit_ty(tp, e, v); }
+ for child: @pat in children { v.visit_pat(child, e, v); }
+ }
+ pat_rec(fields, _) {
+ for f: field_pat in fields { v.visit_pat(f.pat, e, v); }
+ }
+ pat_box(inner) { v.visit_pat(inner, e, v); }
+ _ { }
}
}
-fn visit_native_item[E](&@native_item ni, &E e, &vt[E] v) {
- alt (ni.node) {
- case (native_item_fn(_, ?fd, _)) { visit_fn_decl(fd, e, v); }
- case (native_item_ty) { }
+fn visit_native_item[E](ni: &@native_item, e: &E, v: &vt[E]) {
+ alt ni.node {
+ native_item_fn(_, fd, _) { visit_fn_decl(fd, e, v); }
+ native_item_ty. { }
}
}
-fn visit_fn_decl[E](&fn_decl fd, &E e, &vt[E] v) {
- for (arg a in fd.inputs) { v.visit_ty(a.ty, e, v); }
- for (@constr c in fd.constraints) {
+fn visit_fn_decl[E](fd: &fn_decl, e: &E, v: &vt[E]) {
+ for a: arg in fd.inputs { v.visit_ty(a.ty, e, v); }
+ for c: @constr in fd.constraints {
v.visit_constr(c.node.path, c.span, c.node.id, e, v);
}
v.visit_ty(fd.output, e, v);
}
-fn visit_fn[E](&_fn f, &ty_param[] tp, &span sp, &fn_ident i,
- node_id id, &E e, &vt[E] v) {
+fn visit_fn[E](f: &_fn, tp: &ty_param[], sp: &span, i: &fn_ident, id: node_id,
+ e: &E, v: &vt[E]) {
visit_fn_decl(f.decl, e, v);
v.visit_block(f.body, e, v);
}
-fn visit_block[E](&ast::blk b, &E e, &vt[E] v) {
- for (@stmt s in b.node.stmts) { v.visit_stmt(s, e, v); }
+fn visit_block[E](b: &ast::blk, e: &E, v: &vt[E]) {
+ for s: @stmt in b.node.stmts { v.visit_stmt(s, e, v); }
visit_expr_opt(b.node.expr, e, v);
}
-fn visit_stmt[E](&@stmt s, &E e, &vt[E] v) {
- alt (s.node) {
- case (stmt_decl(?d, _)) { v.visit_decl(d, e, v); }
- case (stmt_expr(?ex, _)) { v.visit_expr(ex, e, v); }
- case (stmt_crate_directive(?cd)) { visit_crate_directive(cd, e, v); }
+fn visit_stmt[E](s: &@stmt, e: &E, v: &vt[E]) {
+ alt s.node {
+ stmt_decl(d, _) { v.visit_decl(d, e, v); }
+ stmt_expr(ex, _) { v.visit_expr(ex, e, v); }
+ stmt_crate_directive(cd) { visit_crate_directive(cd, e, v); }
}
}
-fn visit_decl[E](&@decl d, &E e, &vt[E] v) {
- alt (d.node) {
- case (decl_local(?locs)) {
- for (@ast::local loc in locs) { v.visit_local(loc, e, v); }
- }
- case (decl_item(?it)) { v.visit_item(it, e, v); }
+fn visit_decl[E](d: &@decl, e: &E, v: &vt[E]) {
+ alt d.node {
+ decl_local(locs) {
+ for loc: @ast::local in locs { v.visit_local(loc, e, v); }
+ }
+ decl_item(it) { v.visit_item(it, e, v); }
}
}
-fn visit_expr_opt[E](option::t[@expr] eo, &E e, &vt[E] v) {
- alt (eo) {
- case (none) { }
- case (some(?ex)) { v.visit_expr(ex, e, v); }
+fn visit_expr_opt[E](eo: option::t[@expr], e: &E, v: &vt[E]) {
+ alt eo { none. { } some(ex) { v.visit_expr(ex, e, v); } }
+}
+
+fn visit_exprs[E](exprs: &(@expr)[], e: &E, v: &vt[E]) {
+ for ex: @expr in exprs { v.visit_expr(ex, e, v); }
+}
+
+fn visit_mac[E](m: mac, e: &E, v: &vt[E]) {
+ alt m.node {
+ ast::mac_invoc(pth, args, body) { visit_exprs(args, e, v); }
+ ast::mac_embed_type(ty) { v.visit_ty(ty, e, v); }
+ ast::mac_embed_block(blk) { v.visit_block(blk, e, v); }
+ ast::mac_ellipsis. { }
}
}
-fn visit_exprs[E](&(@expr)[] exprs, &E e, &vt[E] v) {
- for (@expr ex in exprs) { v.visit_expr(ex, e, v); }
-}
-
-fn visit_mac[E](mac m, &E e, &vt[E] v) {
- alt(m.node) {
- case (ast::mac_invoc(?pth, ?args, ?body)) { visit_exprs(args, e, v); }
- case (ast::mac_embed_type(?ty)) { v.visit_ty(ty, e, v); }
- case (ast::mac_embed_block(?blk)) { v.visit_block(blk, e, v); }
- case (ast::mac_ellipsis) { }
- }
-}
-
-fn visit_expr[E](&@expr ex, &E e, &vt[E] v) {
- alt (ex.node) {
- case (expr_vec(?es, _, _)) { visit_exprs(es, e, v); }
- case (expr_rec(?flds, ?base)) {
- for (field f in flds) { v.visit_expr(f.node.expr, e, v); }
- visit_expr_opt(base, e, v);
- }
- case (expr_call(?callee, ?args)) {
- v.visit_expr(callee, e, v);
- visit_exprs(args, e, v);
- }
- case (expr_self_method(_)) { }
- case (expr_bind(?callee, ?args)) {
- v.visit_expr(callee, e, v);
- for (option::t[@expr] eo in args) { visit_expr_opt(eo, e, v); }
- }
- case (expr_spawn(_, _, ?callee, ?args)) {
- v.visit_expr(callee, e, v);
- visit_exprs(args, e, v);
- }
- case (expr_binary(_, ?a, ?b)) {
- v.visit_expr(a, e, v);
- v.visit_expr(b, e, v);
- }
- case (expr_unary(_, ?a)) { v.visit_expr(a, e, v); }
- case (expr_lit(_)) { }
- case (expr_cast(?x, ?t)) {
- v.visit_expr(x, e, v);
- v.visit_ty(t, e, v);
- }
- case (expr_if(?x, ?b, ?eo)) {
- v.visit_expr(x, e, v);
- v.visit_block(b, e, v);
- visit_expr_opt(eo, e, v);
- }
- case (expr_if_check(?x, ?b, ?eo)) {
- v.visit_expr(x, e, v);
- v.visit_block(b, e, v);
- visit_expr_opt(eo, e, v);
- }
- case (expr_ternary(?c, ?t, ?el)) {
- v.visit_expr(c, e, v);
- v.visit_expr(t, e, v);
- v.visit_expr(el, e, v);
- }
- case (expr_while(?x, ?b)) {
- v.visit_expr(x, e, v);
- v.visit_block(b, e, v);
- }
- expr_for(?dcl, ?x, ?b) | expr_for_each(?dcl, ?x, ?b) {
- v.visit_local(dcl, e, v);
- v.visit_expr(x, e, v);
- v.visit_block(b, e, v);
- }
- case (expr_do_while(?b, ?x)) {
- v.visit_block(b, e, v);
- v.visit_expr(x, e, v);
- }
- case (expr_alt(?x, ?arms)) {
- v.visit_expr(x, e, v);
- for (arm a in arms) { v.visit_arm(a, e, v); }
- }
- case (expr_fn(?f)) {
- v.visit_fn(f, ~[], ex.span, none, ex.id, e, v);
- }
- case (expr_block(?b)) { v.visit_block(b, e, v); }
- case (expr_assign(?a, ?b)) {
- v.visit_expr(b, e, v);
- v.visit_expr(a, e, v);
- }
- case (expr_move(?a, ?b)) {
- v.visit_expr(b, e, v);
- v.visit_expr(a, e, v);
- }
- case (expr_swap(?a, ?b)) {
- v.visit_expr(a, e, v);
- v.visit_expr(b, e, v);
- }
- case (expr_assign_op(_, ?a, ?b)) {
- v.visit_expr(b, e, v);
- v.visit_expr(a, e, v);
- }
- case (expr_send(?a, ?b)) {
- v.visit_expr(a, e, v);
- v.visit_expr(b, e, v);
- }
- case (expr_recv(?a, ?b)) {
- v.visit_expr(a, e, v);
- v.visit_expr(b, e, v);
- }
- case (expr_field(?x, _)) { v.visit_expr(x, e, v); }
- case (expr_index(?a, ?b)) {
- v.visit_expr(a, e, v);
- v.visit_expr(b, e, v);
- }
- case (expr_path(?p)) {
- for (@ty tp in p.node.types) { v.visit_ty(tp, e, v); }
- }
- case (expr_fail(?eo)) {
- visit_expr_opt(eo, e, v);
- }
- case (expr_break) { }
- case (expr_cont) { }
- case (expr_ret(?eo)) { visit_expr_opt(eo, e, v); }
- case (expr_put(?eo)) { visit_expr_opt(eo, e, v); }
- case (expr_be(?x)) { v.visit_expr(x, e, v); }
- case (expr_log(_, ?x)) { v.visit_expr(x, e, v); }
- case (expr_check(_, ?x)) { v.visit_expr(x, e, v); }
- case (expr_assert(?x)) { v.visit_expr(x, e, v); }
- case (expr_port(?t)) { visit_ty_opt(t, e, v); }
- case (expr_chan(?x)) { v.visit_expr(x, e, v); }
- case (expr_anon_obj(?anon_obj)) {
- alt (anon_obj.fields) {
- case (none) { }
- case (some(?fields)) {
- for (anon_obj_field f in fields) {
- v.visit_ty(f.ty, e, v);
- v.visit_expr(f.expr, e, v);
- }
- }
+fn visit_expr[E](ex: &@expr, e: &E, v: &vt[E]) {
+ alt ex.node {
+ expr_vec(es, _, _) { visit_exprs(es, e, v); }
+ expr_rec(flds, base) {
+ for f: field in flds { v.visit_expr(f.node.expr, e, v); }
+ visit_expr_opt(base, e, v);
+ }
+ expr_call(callee, args) {
+ v.visit_expr(callee, e, v);
+ visit_exprs(args, e, v);
+ }
+ expr_self_method(_) { }
+ expr_bind(callee, args) {
+ v.visit_expr(callee, e, v);
+ for eo: option::t[@expr] in args { visit_expr_opt(eo, e, v); }
+ }
+ expr_spawn(_, _, callee, args) {
+ v.visit_expr(callee, e, v);
+ visit_exprs(args, e, v);
+ }
+ expr_binary(_, a, b) { v.visit_expr(a, e, v); v.visit_expr(b, e, v); }
+ expr_unary(_, a) { v.visit_expr(a, e, v); }
+ expr_lit(_) { }
+ expr_cast(x, t) { v.visit_expr(x, e, v); v.visit_ty(t, e, v); }
+ expr_if(x, b, eo) {
+ v.visit_expr(x, e, v);
+ v.visit_block(b, e, v);
+ visit_expr_opt(eo, e, v);
+ }
+ expr_if_check(x, b, eo) {
+ v.visit_expr(x, e, v);
+ v.visit_block(b, e, v);
+ visit_expr_opt(eo, e, v);
+ }
+ expr_ternary(c, t, el) {
+ v.visit_expr(c, e, v);
+ v.visit_expr(t, e, v);
+ v.visit_expr(el, e, v);
+ }
+ expr_while(x, b) { v.visit_expr(x, e, v); v.visit_block(b, e, v); }
+ expr_for(dcl, x, b) | expr_for_each(dcl, x, b) {
+ v.visit_local(dcl, e, v);
+ v.visit_expr(x, e, v);
+ v.visit_block(b, e, v);
+ }
+ expr_do_while(b, x) { v.visit_block(b, e, v); v.visit_expr(x, e, v); }
+ expr_alt(x, arms) {
+ v.visit_expr(x, e, v);
+ for a: arm in arms { v.visit_arm(a, e, v); }
+ }
+ expr_fn(f) { v.visit_fn(f, ~[], ex.span, none, ex.id, e, v); }
+ expr_block(b) { v.visit_block(b, e, v); }
+ expr_assign(a, b) { v.visit_expr(b, e, v); v.visit_expr(a, e, v); }
+ expr_move(a, b) { v.visit_expr(b, e, v); v.visit_expr(a, e, v); }
+ expr_swap(a, b) { v.visit_expr(a, e, v); v.visit_expr(b, e, v); }
+ expr_assign_op(_, a, b) {
+ v.visit_expr(b, e, v);
+ v.visit_expr(a, e, v);
+ }
+ expr_send(a, b) { v.visit_expr(a, e, v); v.visit_expr(b, e, v); }
+ expr_recv(a, b) { v.visit_expr(a, e, v); v.visit_expr(b, e, v); }
+ expr_field(x, _) { v.visit_expr(x, e, v); }
+ expr_index(a, b) { v.visit_expr(a, e, v); v.visit_expr(b, e, v); }
+ expr_path(p) { for tp: @ty in p.node.types { v.visit_ty(tp, e, v); } }
+ expr_fail(eo) { visit_expr_opt(eo, e, v); }
+ expr_break. { }
+ expr_cont. { }
+ expr_ret(eo) { visit_expr_opt(eo, e, v); }
+ expr_put(eo) { visit_expr_opt(eo, e, v); }
+ expr_be(x) { v.visit_expr(x, e, v); }
+ expr_log(_, x) { v.visit_expr(x, e, v); }
+ expr_check(_, x) { v.visit_expr(x, e, v); }
+ expr_assert(x) { v.visit_expr(x, e, v); }
+ expr_port(t) { visit_ty_opt(t, e, v); }
+ expr_chan(x) { v.visit_expr(x, e, v); }
+ expr_anon_obj(anon_obj) {
+ alt anon_obj.fields {
+ none. { }
+ some(fields) {
+ for f: anon_obj_field in fields {
+ v.visit_ty(f.ty, e, v);
+ v.visit_expr(f.expr, e, v);
}
- alt (anon_obj.with_obj) {
- case (none) { }
- case (some(?ex)) { v.visit_expr(ex, e, v); }
- }
- for (@method m in anon_obj.methods) {
- v.visit_fn(m.node.meth, ~[], m.span, some(m.node.ident),
- m.node.id, e, v);
- }
+ }
}
- case (expr_mac(?mac)) {
- visit_mac(mac, e, v);
+ alt anon_obj.with_obj {
+ none. { }
+ some(ex) { v.visit_expr(ex, e, v); }
}
+ for m: @method in anon_obj.methods {
+ v.visit_fn(m.node.meth, ~[], m.span, some(m.node.ident),
+ m.node.id, e, v);
+ }
+ }
+ expr_mac(mac) { visit_mac(mac, e, v); }
}
}
-fn visit_arm[E](&arm a, &E e, &vt[E] v) {
- for (@pat p in a.pats) { v.visit_pat(p, e, v); }
+fn visit_arm[E](a: &arm, e: &E, v: &vt[E]) {
+ for p: @pat in a.pats { v.visit_pat(p, e, v); }
v.visit_block(a.block, e, v);
}
@@ -416,103 +353,119 @@
// calls the given functions on the nodes.
type simple_visitor =
- @rec(fn(&_mod, &span) visit_mod,
- fn(&@view_item) visit_view_item,
- fn(&@native_item) visit_native_item,
- fn(&@item) visit_item,
- fn(&@local) visit_local,
- fn(&ast::blk) visit_block,
- fn(&@stmt) visit_stmt,
- fn(&arm) visit_arm,
- fn(&@pat) visit_pat,
- fn(&@decl) visit_decl,
- fn(&@expr) visit_expr,
- fn(&@ty) visit_ty,
- // takes the components so that one function can be
- // generic over constr and ty_constr
- fn(&path, &span, node_id) visit_constr,
- fn(&_fn, &ty_param[], &span, &fn_ident, node_id) visit_fn);
+ // takes the components so that one function can be
+ // generic over constr and ty_constr
+ @{visit_mod: fn(&_mod, &span) ,
+ visit_view_item: fn(&@view_item) ,
+ visit_native_item: fn(&@native_item) ,
+ visit_item: fn(&@item) ,
+ visit_local: fn(&@local) ,
+ visit_block: fn(&ast::blk) ,
+ visit_stmt: fn(&@stmt) ,
+ visit_arm: fn(&arm) ,
+ visit_pat: fn(&@pat) ,
+ visit_decl: fn(&@decl) ,
+ visit_expr: fn(&@expr) ,
+ visit_ty: fn(&@ty) ,
+ visit_constr: fn(&path, &span, node_id) ,
+ visit_fn: fn(&_fn, &ty_param[], &span, &fn_ident, node_id) };
fn default_simple_visitor() -> simple_visitor {
- ret @rec(visit_mod=fn(&_mod m, &span sp) {},
- visit_view_item=fn(&@view_item vi) {},
- visit_native_item=fn(&@native_item ni) {},
- visit_item=fn(&@item i) {},
- visit_local=fn(&@local l) {},
- visit_block=fn(&ast::blk b) {},
- visit_stmt=fn(&@stmt s) {},
- visit_arm=fn(&arm a) {},
- visit_pat=fn(&@pat p) {},
- visit_decl=fn(&@decl d) {},
- visit_expr=fn(&@expr e) {},
- visit_ty=fn(&@ty t) {},
- visit_constr=fn(&path p, &span sp, node_id id) {},
- visit_fn=fn(&_fn f, &ty_param[] tps, &span sp,
- &fn_ident ident, node_id id) {});
+ ret @{visit_mod: fn (m: &_mod, sp: &span) { },
+ visit_view_item: fn (vi: &@view_item) { },
+ visit_native_item: fn (ni: &@native_item) { },
+ visit_item: fn (i: &@item) { },
+ visit_local: fn (l: &@local) { },
+ visit_block: fn (b: &ast::blk) { },
+ visit_stmt: fn (s: &@stmt) { },
+ visit_arm: fn (a: &arm) { },
+ visit_pat: fn (p: &@pat) { },
+ visit_decl: fn (d: &@decl) { },
+ visit_expr: fn (e: &@expr) { },
+ visit_ty: fn (t: &@ty) { },
+ visit_constr: fn (p: &path, sp: &span, id: node_id) { },
+ visit_fn:
+ fn (f: &_fn, tps: &ty_param[], sp: &span, ident: &fn_ident,
+ id: node_id) {
+ }};
}
-fn mk_simple_visitor(&simple_visitor v) -> vt[()] {
- fn v_mod(fn(&_mod, &span) f, &_mod m, &span sp, &() e, &vt[()] v) {
- f(m, sp); visit_mod(m, sp, e, v);
+fn mk_simple_visitor(v: &simple_visitor) -> vt[()] {
+ fn v_mod(f: fn(&_mod, &span) , m: &_mod, sp: &span, e: &(), v: &vt[()]) {
+ f(m, sp);
+ visit_mod(m, sp, e, v);
}
- fn v_view_item(fn(&@view_item) f, &@view_item vi, &() e, &vt[()] v) {
- f(vi); visit_view_item(vi, e, v);
+ fn v_view_item(f: fn(&@view_item) , vi: &@view_item, e: &(), v: &vt[()]) {
+ f(vi);
+ visit_view_item(vi, e, v);
}
- fn v_native_item(fn(&@native_item) f, &@native_item ni, &() e, &vt[()] v){
- f(ni); visit_native_item(ni, e, v);
+ fn v_native_item(f: fn(&@native_item) , ni: &@native_item, e: &(),
+ v: &vt[()]) {
+ f(ni);
+ visit_native_item(ni, e, v);
}
- fn v_item(fn(&@item) f, &@item i, &() e, &vt[()] v) {
- f(i); visit_item(i, e, v);
+ fn v_item(f: fn(&@item) , i: &@item, e: &(), v: &vt[()]) {
+ f(i);
+ visit_item(i, e, v);
}
- fn v_local(fn(&@local) f, &@local l, &() e, &vt[()] v) {
- f(l); visit_local(l, e, v);
+ fn v_local(f: fn(&@local) , l: &@local, e: &(), v: &vt[()]) {
+ f(l);
+ visit_local(l, e, v);
}
- fn v_block(fn(&ast::blk) f, &ast::blk bl, &() e, &vt[()] v) {
- f(bl); visit_block(bl, e, v);
+ fn v_block(f: fn(&ast::blk) , bl: &ast::blk, e: &(), v: &vt[()]) {
+ f(bl);
+ visit_block(bl, e, v);
}
- fn v_stmt(fn(&@stmt) f, &@stmt st, &() e, &vt[()] v) {
- f(st); visit_stmt(st, e, v);
+ fn v_stmt(f: fn(&@stmt) , st: &@stmt, e: &(), v: &vt[()]) {
+ f(st);
+ visit_stmt(st, e, v);
}
- fn v_arm(fn(&arm) f, &arm a, &() e, &vt[()] v) {
- f(a); visit_arm(a, e, v);
+ fn v_arm(f: fn(&arm) , a: &arm, e: &(), v: &vt[()]) {
+ f(a);
+ visit_arm(a, e, v);
}
- fn v_pat(fn(&@pat) f, &@pat p, &() e, &vt[()] v) {
- f(p); visit_pat(p, e, v);
+ fn v_pat(f: fn(&@pat) , p: &@pat, e: &(), v: &vt[()]) {
+ f(p);
+ visit_pat(p, e, v);
}
- fn v_decl(fn(&@decl) f, &@decl d, &() e, &vt[()] v) {
- f(d); visit_decl(d, e, v);
+ fn v_decl(f: fn(&@decl) , d: &@decl, e: &(), v: &vt[()]) {
+ f(d);
+ visit_decl(d, e, v);
}
- fn v_expr(fn(&@expr) f, &@expr ex, &() e, &vt[()] v) {
- f(ex); visit_expr(ex, e, v);
+ fn v_expr(f: fn(&@expr) , ex: &@expr, e: &(), v: &vt[()]) {
+ f(ex);
+ visit_expr(ex, e, v);
}
- fn v_ty(fn(&@ty) f, &@ty ty, &() e, &vt[()] v) {
- f(ty); visit_ty(ty, e, v);
+ fn v_ty(f: fn(&@ty) , ty: &@ty, e: &(), v: &vt[()]) {
+ f(ty);
+ visit_ty(ty, e, v);
}
- fn v_constr(fn(&path, &span, node_id) f,
- &path pt, &span sp, node_id id, &() e, &vt[()] v) {
- f(pt, sp, id); visit_constr(pt, sp, id, e, v);
+ fn v_constr(f: fn(&path, &span, node_id) , pt: &path, sp: &span,
+ id: node_id, e: &(), v: &vt[()]) {
+ f(pt, sp, id);
+ visit_constr(pt, sp, id, e, v);
}
- fn v_fn(fn(&_fn, &ty_param[], &span, &fn_ident, node_id) f,
- &_fn ff, &ty_param[] tps, &span sp, &fn_ident ident, node_id id,
- &() e, &vt[()] v) {
- f(ff, tps, sp, ident, id); visit_fn(ff, tps, sp, ident, id, e, v);
+ fn v_fn(f: fn(&_fn, &ty_param[], &span, &fn_ident, node_id) , ff: &_fn,
+ tps: &ty_param[], sp: &span, ident: &fn_ident, id: node_id,
+ e: &(), v: &vt[()]) {
+ f(ff, tps, sp, ident, id);
+ visit_fn(ff, tps, sp, ident, id, e, v);
}
- ret mk_vt(@rec(visit_mod=bind v_mod(v.visit_mod, _, _, _, _),
- visit_view_item=
- bind v_view_item(v.visit_view_item, _, _, _),
- visit_native_item=
- bind v_native_item(v.visit_native_item, _, _, _),
- visit_item=bind v_item(v.visit_item, _, _, _),
- visit_local=bind v_local(v.visit_local, _, _, _),
- visit_block=bind v_block(v.visit_block, _, _, _),
- visit_stmt=bind v_stmt(v.visit_stmt, _, _, _),
- visit_arm=bind v_arm(v.visit_arm, _, _, _),
- visit_pat=bind v_pat(v.visit_pat, _, _, _),
- visit_decl=bind v_decl(v.visit_decl, _, _, _),
- visit_expr=bind v_expr(v.visit_expr, _, _, _),
- visit_ty=bind v_ty(v.visit_ty, _, _, _),
- visit_constr=bind v_constr(v.visit_constr, _, _, _, _, _),
- visit_fn=bind v_fn(v.visit_fn, _, _, _, _, _, _, _)));
+ ret mk_vt(@{visit_mod: bind v_mod(v.visit_mod, _, _, _, _),
+ visit_view_item: bind v_view_item(v.visit_view_item, _, _, _),
+ visit_native_item:
+ bind v_native_item(v.visit_native_item, _, _, _),
+ visit_item: bind v_item(v.visit_item, _, _, _),
+ visit_local: bind v_local(v.visit_local, _, _, _),
+ visit_block: bind v_block(v.visit_block, _, _, _),
+ visit_stmt: bind v_stmt(v.visit_stmt, _, _, _),
+ visit_arm: bind v_arm(v.visit_arm, _, _, _),
+ visit_pat: bind v_pat(v.visit_pat, _, _, _),
+ visit_decl: bind v_decl(v.visit_decl, _, _, _),
+ visit_expr: bind v_expr(v.visit_expr, _, _, _),
+ visit_ty: bind v_ty(v.visit_ty, _, _, _),
+ visit_constr: bind v_constr(v.visit_constr, _, _, _, _, _),
+ visit_fn: bind v_fn(v.visit_fn, _, _, _, _, _, _, _)});
}
// Local Variables:
diff --git a/src/comp/syntax/walk.rs b/src/comp/syntax/walk.rs
index d439a2e..528032a 100644
--- a/src/comp/syntax/walk.rs
+++ b/src/comp/syntax/walk.rs
@@ -8,412 +8,379 @@
import codemap::span;
type ast_visitor =
- rec(fn() -> bool keep_going,
- fn() -> bool want_crate_directives,
- fn(&ast::crate) visit_crate_pre,
- fn(&ast::crate) visit_crate_post,
- fn(&@ast::crate_directive) visit_crate_directive_pre,
- fn(&@ast::crate_directive) visit_crate_directive_post,
- fn(&@ast::view_item) visit_view_item_pre,
- fn(&@ast::view_item) visit_view_item_post,
- fn(&@ast::native_item) visit_native_item_pre,
- fn(&@ast::native_item) visit_native_item_post,
- fn(&@ast::item) visit_item_pre,
- fn(&@ast::item) visit_item_post,
- fn(&@ast::method) visit_method_pre,
- fn(&@ast::method) visit_method_post,
- fn(&ast::blk) visit_block_pre,
- fn(&ast::blk) visit_block_post,
- fn(&@ast::stmt) visit_stmt_pre,
- fn(&@ast::stmt) visit_stmt_post,
- fn(&ast::arm) visit_arm_pre,
- fn(&ast::arm) visit_arm_post,
- fn(&@ast::pat) visit_pat_pre,
- fn(&@ast::pat) visit_pat_post,
- fn(&@ast::decl) visit_decl_pre,
- fn(&@ast::decl) visit_decl_post,
- fn(&@ast::local) visit_local_pre,
- fn(&@ast::local) visit_local_post,
- fn(&@ast::expr) visit_expr_pre,
- fn(&@ast::expr) visit_expr_post,
- fn(&@ast::ty) visit_ty_pre,
- fn(&@ast::ty) visit_ty_post,
- fn(&@ast::constr) visit_constr,
- fn(&ast::_fn, &ast::ty_param[], &span, &ast::fn_ident,
- ast::node_id) visit_fn_pre,
- fn(&ast::_fn, &ast::ty_param[], &span, &ast::fn_ident,
- ast::node_id) visit_fn_post);
+ {keep_going: fn() -> bool ,
+ want_crate_directives: fn() -> bool ,
+ visit_crate_pre: fn(&ast::crate) ,
+ visit_crate_post: fn(&ast::crate) ,
+ visit_crate_directive_pre: fn(&@ast::crate_directive) ,
+ visit_crate_directive_post: fn(&@ast::crate_directive) ,
+ visit_view_item_pre: fn(&@ast::view_item) ,
+ visit_view_item_post: fn(&@ast::view_item) ,
+ visit_native_item_pre: fn(&@ast::native_item) ,
+ visit_native_item_post: fn(&@ast::native_item) ,
+ visit_item_pre: fn(&@ast::item) ,
+ visit_item_post: fn(&@ast::item) ,
+ visit_method_pre: fn(&@ast::method) ,
+ visit_method_post: fn(&@ast::method) ,
+ visit_block_pre: fn(&ast::blk) ,
+ visit_block_post: fn(&ast::blk) ,
+ visit_stmt_pre: fn(&@ast::stmt) ,
+ visit_stmt_post: fn(&@ast::stmt) ,
+ visit_arm_pre: fn(&ast::arm) ,
+ visit_arm_post: fn(&ast::arm) ,
+ visit_pat_pre: fn(&@ast::pat) ,
+ visit_pat_post: fn(&@ast::pat) ,
+ visit_decl_pre: fn(&@ast::decl) ,
+ visit_decl_post: fn(&@ast::decl) ,
+ visit_local_pre: fn(&@ast::local) ,
+ visit_local_post: fn(&@ast::local) ,
+ visit_expr_pre: fn(&@ast::expr) ,
+ visit_expr_post: fn(&@ast::expr) ,
+ visit_ty_pre: fn(&@ast::ty) ,
+ visit_ty_post: fn(&@ast::ty) ,
+ visit_constr: fn(&@ast::constr) ,
+ visit_fn_pre:
+ fn(&ast::_fn, &ast::ty_param[], &span, &ast::fn_ident, ast::node_id)
+ ,
+ visit_fn_post:
+ fn(&ast::_fn, &ast::ty_param[], &span, &ast::fn_ident, ast::node_id)
+ };
-fn walk_crate(&ast_visitor v, &ast::crate c) {
- if (!v.keep_going()) { ret; }
+fn walk_crate(v: &ast_visitor, c: &ast::crate) {
+ if !v.keep_going() { ret; }
v.visit_crate_pre(c);
walk_mod(v, c.node.module);
v.visit_crate_post(c);
}
-fn walk_crate_directive(&ast_visitor v, @ast::crate_directive cd) {
- if (!v.keep_going()) { ret; }
- if (!v.want_crate_directives()) { ret; }
+fn walk_crate_directive(v: &ast_visitor, cd: @ast::crate_directive) {
+ if !v.keep_going() { ret; }
+ if !v.want_crate_directives() { ret; }
v.visit_crate_directive_pre(cd);
- alt (cd.node) {
- case (ast::cdir_src_mod(_, _, _)) { }
- case (ast::cdir_dir_mod(_, _, ?cdirs, _)) {
- for (@ast::crate_directive cdir in cdirs) {
- walk_crate_directive(v, cdir);
- }
+ alt cd.node {
+ ast::cdir_src_mod(_, _, _) { }
+ ast::cdir_dir_mod(_, _, cdirs, _) {
+ for cdir: @ast::crate_directive in cdirs {
+ walk_crate_directive(v, cdir);
}
- case (ast::cdir_view_item(?vi)) { walk_view_item(v, vi); }
- case (ast::cdir_syntax(_)) { }
- case (ast::cdir_auth(_, _)) { }
+ }
+ ast::cdir_view_item(vi) { walk_view_item(v, vi); }
+ ast::cdir_syntax(_) { }
+ ast::cdir_auth(_, _) { }
}
v.visit_crate_directive_post(cd);
}
-fn walk_mod(&ast_visitor v, &ast::_mod m) {
- if (!v.keep_going()) { ret; }
- for (@ast::view_item vi in m.view_items) { walk_view_item(v, vi); }
- for (@ast::item i in m.items) { walk_item(v, i); }
+fn walk_mod(v: &ast_visitor, m: &ast::_mod) {
+ if !v.keep_going() { ret; }
+ for vi: @ast::view_item in m.view_items { walk_view_item(v, vi); }
+ for i: @ast::item in m.items { walk_item(v, i); }
}
-fn walk_view_item(&ast_visitor v, @ast::view_item vi) {
- if (!v.keep_going()) { ret; }
+fn walk_view_item(v: &ast_visitor, vi: @ast::view_item) {
+ if !v.keep_going() { ret; }
v.visit_view_item_pre(vi);
v.visit_view_item_post(vi);
}
-fn walk_local(&ast_visitor v, @ast::local loc) {
+fn walk_local(v: &ast_visitor, loc: @ast::local) {
v.visit_local_pre(loc);
- alt (loc.node.ty) { case (none) { } case (some(?t)) { walk_ty(v, t); } }
- alt (loc.node.init) {
- case (none) { }
- case (some(?i)) { walk_expr(v, i.expr); }
- }
+ alt loc.node.ty { none. { } some(t) { walk_ty(v, t); } }
+ alt loc.node.init { none. { } some(i) { walk_expr(v, i.expr); } }
v.visit_local_post(loc);
}
-fn walk_item(&ast_visitor v, @ast::item i) {
- if (!v.keep_going()) { ret; }
+fn walk_item(v: &ast_visitor, i: @ast::item) {
+ if !v.keep_going() { ret; }
v.visit_item_pre(i);
- alt (i.node) {
- case (ast::item_const(?t, ?e)) { walk_ty(v, t); walk_expr(v, e); }
- case (ast::item_fn(?f, ?tps)) {
- walk_fn(v, f, tps, i.span, some(i.ident), i.id);
+ alt i.node {
+ ast::item_const(t, e) { walk_ty(v, t); walk_expr(v, e); }
+ ast::item_fn(f, tps) {
+ walk_fn(v, f, tps, i.span, some(i.ident), i.id);
+ }
+ ast::item_mod(m) { walk_mod(v, m); }
+ ast::item_native_mod(nm) { walk_native_mod(v, nm); }
+ ast::item_ty(t, _) { walk_ty(v, t); }
+ ast::item_res(f, dtor_id, tps, _) {
+ walk_fn(v, f, tps, i.span, some(i.ident), dtor_id);
+ }
+ ast::item_tag(variants, _) {
+ for vr: ast::variant in variants {
+ for va: ast::variant_arg in vr.node.args { walk_ty(v, va.ty); }
}
- case (ast::item_mod(?m)) { walk_mod(v, m); }
- case (ast::item_native_mod(?nm)) { walk_native_mod(v, nm); }
- case (ast::item_ty(?t, _)) { walk_ty(v, t); }
- case (ast::item_res(?f, ?dtor_id, ?tps, _)) {
- walk_fn(v, f, tps, i.span, some(i.ident), dtor_id);
+ }
+ ast::item_obj(ob, _, _) {
+ for f: ast::obj_field in ob.fields { walk_ty(v, f.ty); }
+ for m: @ast::method in ob.methods {
+ v.visit_method_pre(m);
+ // Methods don't have ty params?
+ walk_fn(v, m.node.meth, ~[], m.span, some(m.node.ident),
+ m.node.id);
+ v.visit_method_post(m);
}
- case (ast::item_tag(?variants, _)) {
- for (ast::variant vr in variants) {
- for (ast::variant_arg va in vr.node.args) {
- walk_ty(v, va.ty);
- }
- }
+ alt ob.dtor {
+ none. { }
+ some(m) {
+ walk_fn(v, m.node.meth, ~[], m.span, some(m.node.ident),
+ m.node.id);
+ }
}
- case (ast::item_obj(?ob, _, _)) {
- for (ast::obj_field f in ob.fields) { walk_ty(v, f.ty); }
- for (@ast::method m in ob.methods) {
- v.visit_method_pre(m);
- // Methods don't have ty params?
- walk_fn(v, m.node.meth, ~[], m.span,
- some(m.node.ident), m.node.id);
- v.visit_method_post(m);
- }
- alt (ob.dtor) {
- case (none) { }
- case (some(?m)) {
- walk_fn(v, m.node.meth, ~[], m.span,
- some(m.node.ident), m.node.id);
- }
- }
- }
+ }
}
v.visit_item_post(i);
}
-fn walk_ty(&ast_visitor v, @ast::ty t) {
- if (!v.keep_going()) { ret; }
+fn walk_ty(v: &ast_visitor, t: @ast::ty) {
+ if !v.keep_going() { ret; }
v.visit_ty_pre(t);
- alt (t.node) {
- case (ast::ty_nil) { }
- case (ast::ty_bot) { }
- case (ast::ty_bool) { }
- case (ast::ty_int) { }
- case (ast::ty_uint) { }
- case (ast::ty_float) { }
- case (ast::ty_machine(_)) { }
- case (ast::ty_char) { }
- case (ast::ty_str) { }
- case (ast::ty_istr) { }
- case (ast::ty_box(?mt)) { walk_ty(v, mt.ty); }
- case (ast::ty_vec(?mt)) { walk_ty(v, mt.ty); }
- case (ast::ty_ivec(?mt)) { walk_ty(v, mt.ty); }
- case (ast::ty_ptr(?mt)) { walk_ty(v, mt.ty); }
- case (ast::ty_task) { }
- case (ast::ty_port(?t)) { walk_ty(v, t); }
- case (ast::ty_chan(?t)) { walk_ty(v, t); }
- case (ast::ty_rec(?flds)) {
- for (ast::ty_field f in flds) { walk_ty(v, f.node.mt.ty); }
+ alt t.node {
+ ast::ty_nil. { }
+ ast::ty_bot. { }
+ ast::ty_bool. { }
+ ast::ty_int. { }
+ ast::ty_uint. { }
+ ast::ty_float. { }
+ ast::ty_machine(_) { }
+ ast::ty_char. { }
+ ast::ty_str. { }
+ ast::ty_istr. { }
+ ast::ty_box(mt) { walk_ty(v, mt.ty); }
+ ast::ty_vec(mt) { walk_ty(v, mt.ty); }
+ ast::ty_ivec(mt) { walk_ty(v, mt.ty); }
+ ast::ty_ptr(mt) { walk_ty(v, mt.ty); }
+ ast::ty_task. { }
+ ast::ty_port(t) { walk_ty(v, t); }
+ ast::ty_chan(t) { walk_ty(v, t); }
+ ast::ty_rec(flds) {
+ for f: ast::ty_field in flds { walk_ty(v, f.node.mt.ty); }
+ }
+ ast::ty_fn(_, args, out, _, constrs) {
+ for a: ast::ty_arg in args { walk_ty(v, a.node.ty); }
+ for c: @ast::constr in constrs { v.visit_constr(c); }
+ walk_ty(v, out);
+ }
+ ast::ty_obj(tmeths) {
+ for m: ast::ty_method in tmeths {
+ for a: ast::ty_arg in m.node.inputs { walk_ty(v, a.node.ty); }
+ walk_ty(v, m.node.output);
}
- case (ast::ty_fn(_, ?args, ?out, _, ?constrs)) {
- for (ast::ty_arg a in args) { walk_ty(v, a.node.ty); }
- for (@ast::constr c in constrs) { v.visit_constr(c); }
- walk_ty(v, out);
- }
- case (ast::ty_obj(?tmeths)) {
- for (ast::ty_method m in tmeths) {
- for (ast::ty_arg a in m.node.inputs) {
- walk_ty(v, a.node.ty);
- }
- walk_ty(v, m.node.output);
- }
- }
- case (ast::ty_path(?p, _)) {
- for (@ast::ty tp in p.node.types) { walk_ty(v, tp); }
- }
- case (ast::ty_type) { }
- case (ast::ty_constr(?t, _)) { walk_ty(v, t); }
+ }
+ ast::ty_path(p, _) {
+ for tp: @ast::ty in p.node.types { walk_ty(v, tp); }
+ }
+ ast::ty_type. { }
+ ast::ty_constr(t, _) { walk_ty(v, t); }
}
v.visit_ty_post(t);
}
-fn walk_pat(&ast_visitor v, &@ast::pat p) {
+fn walk_pat(v: &ast_visitor, p: &@ast::pat) {
v.visit_pat_pre(p);
- alt (p.node) {
- case (ast::pat_tag(?path, ?children)) {
- for (@ast::ty tp in path.node.types) { walk_ty(v, tp); }
- for (@ast::pat child in children) { walk_pat(v, child); }
- }
- case (ast::pat_rec(?fields, _)) {
- for (ast::field_pat f in fields) { walk_pat(v, f.pat); }
- }
- case (ast::pat_box(?inner)) { walk_pat(v, inner); }
- case (_) { }
+ alt p.node {
+ ast::pat_tag(path, children) {
+ for tp: @ast::ty in path.node.types { walk_ty(v, tp); }
+ for child: @ast::pat in children { walk_pat(v, child); }
+ }
+ ast::pat_rec(fields, _) {
+ for f: ast::field_pat in fields { walk_pat(v, f.pat); }
+ }
+ ast::pat_box(inner) { walk_pat(v, inner); }
+ _ { }
}
v.visit_pat_post(p);
}
-fn walk_native_mod(&ast_visitor v, &ast::native_mod nm) {
- if (!v.keep_going()) { ret; }
- for (@ast::view_item vi in nm.view_items) { walk_view_item(v, vi); }
- for (@ast::native_item ni in nm.items) { walk_native_item(v, ni); }
+fn walk_native_mod(v: &ast_visitor, nm: &ast::native_mod) {
+ if !v.keep_going() { ret; }
+ for vi: @ast::view_item in nm.view_items { walk_view_item(v, vi); }
+ for ni: @ast::native_item in nm.items { walk_native_item(v, ni); }
}
-fn walk_native_item(&ast_visitor v, @ast::native_item ni) {
- if (!v.keep_going()) { ret; }
+fn walk_native_item(v: &ast_visitor, ni: @ast::native_item) {
+ if !v.keep_going() { ret; }
v.visit_native_item_pre(ni);
- alt (ni.node) {
- case (ast::native_item_fn(_, ?fd, _)) {
- walk_fn_decl(v, fd);
- }
- case (ast::native_item_ty) { }
+ alt ni.node {
+ ast::native_item_fn(_, fd, _) { walk_fn_decl(v, fd); }
+ ast::native_item_ty. { }
}
v.visit_native_item_post(ni);
}
-fn walk_fn_decl(&ast_visitor v, &ast::fn_decl fd) {
- for (ast::arg a in fd.inputs) { walk_ty(v, a.ty); }
- for (@ast::constr c in fd.constraints) { v.visit_constr(c); }
+fn walk_fn_decl(v: &ast_visitor, fd: &ast::fn_decl) {
+ for a: ast::arg in fd.inputs { walk_ty(v, a.ty); }
+ for c: @ast::constr in fd.constraints { v.visit_constr(c); }
walk_ty(v, fd.output);
}
-fn walk_fn(&ast_visitor v, &ast::_fn f, &ast::ty_param[] tps,
- &span sp, &ast::fn_ident i, ast::node_id d) {
- if (!v.keep_going()) { ret; }
+fn walk_fn(v: &ast_visitor, f: &ast::_fn, tps: &ast::ty_param[], sp: &span,
+ i: &ast::fn_ident, d: ast::node_id) {
+ if !v.keep_going() { ret; }
v.visit_fn_pre(f, tps, sp, i, d);
walk_fn_decl(v, f.decl);
walk_block(v, f.body);
v.visit_fn_post(f, tps, sp, i, d);
}
-fn walk_block(&ast_visitor v, &ast::blk b) {
- if (!v.keep_going()) { ret; }
+fn walk_block(v: &ast_visitor, b: &ast::blk) {
+ if !v.keep_going() { ret; }
v.visit_block_pre(b);
- for (@ast::stmt s in b.node.stmts) { walk_stmt(v, s); }
+ for s: @ast::stmt in b.node.stmts { walk_stmt(v, s); }
walk_expr_opt(v, b.node.expr);
v.visit_block_post(b);
}
-fn walk_stmt(&ast_visitor v, @ast::stmt s) {
- if (!v.keep_going()) { ret; }
+fn walk_stmt(v: &ast_visitor, s: @ast::stmt) {
+ if !v.keep_going() { ret; }
v.visit_stmt_pre(s);
- alt (s.node) {
- case (ast::stmt_decl(?d, _)) { walk_decl(v, d); }
- case (ast::stmt_expr(?e, _)) { walk_expr(v, e); }
- case (ast::stmt_crate_directive(?cdir)) {
- walk_crate_directive(v, cdir);
- }
+ alt s.node {
+ ast::stmt_decl(d, _) { walk_decl(v, d); }
+ ast::stmt_expr(e, _) { walk_expr(v, e); }
+ ast::stmt_crate_directive(cdir) { walk_crate_directive(v, cdir); }
}
v.visit_stmt_post(s);
}
-fn walk_decl(&ast_visitor v, @ast::decl d) {
- if (!v.keep_going()) { ret; }
+fn walk_decl(v: &ast_visitor, d: @ast::decl) {
+ if !v.keep_going() { ret; }
v.visit_decl_pre(d);
- alt (d.node) {
- case (ast::decl_local(?locs)) {
- for (@ast::local loc in locs) { walk_local(v, loc); }
- }
- case (ast::decl_item(?it)) { walk_item(v, it); }
+ alt d.node {
+ ast::decl_local(locs) {
+ for loc: @ast::local in locs { walk_local(v, loc); }
+ }
+ ast::decl_item(it) { walk_item(v, it); }
}
v.visit_decl_post(d);
}
-fn walk_expr_opt(&ast_visitor v, option::t[@ast::expr] eo) {
- alt (eo) { case (none) { } case (some(?e)) { walk_expr(v, e); } }
+fn walk_expr_opt(v: &ast_visitor, eo: option::t[@ast::expr]) {
+ alt eo { none. { } some(e) { walk_expr(v, e); } }
}
-fn walk_exprs(&ast_visitor v, &(@ast::expr)[] exprs) {
- for (@ast::expr e in exprs) { walk_expr(v, e); }
+fn walk_exprs(v: &ast_visitor, exprs: &(@ast::expr)[]) {
+ for e: @ast::expr in exprs { walk_expr(v, e); }
}
-fn walk_mac(&ast_visitor v, ast::mac mac) {
- alt(mac.node) {
- case (ast::mac_invoc(?pth, ?args, ?body)) { walk_exprs(v, args); }
- case (ast::mac_embed_type(?ty)) { walk_ty(v, ty); }
- case (ast::mac_embed_block(?blk)) { walk_block(v, blk); }
- case (ast::mac_ellipsis) { }
+fn walk_mac(v: &ast_visitor, mac: ast::mac) {
+ alt mac.node {
+ ast::mac_invoc(pth, args, body) { walk_exprs(v, args); }
+ ast::mac_embed_type(ty) { walk_ty(v, ty); }
+ ast::mac_embed_block(blk) { walk_block(v, blk); }
+ ast::mac_ellipsis. { }
}
}
-fn walk_expr(&ast_visitor v, @ast::expr e) {
- if (!v.keep_going()) { ret; }
+fn walk_expr(v: &ast_visitor, e: @ast::expr) {
+ if !v.keep_going() { ret; }
v.visit_expr_pre(e);
- alt (e.node) {
- case (ast::expr_vec(?es, _, _)) { walk_exprs(v, es); }
- case (ast::expr_rec(?flds, ?base)) {
- for (ast::field f in flds) { walk_expr(v, f.node.expr); }
- walk_expr_opt(v, base);
+ alt e.node {
+ ast::expr_vec(es, _, _) { walk_exprs(v, es); }
+ ast::expr_rec(flds, base) {
+ for f: ast::field in flds { walk_expr(v, f.node.expr); }
+ walk_expr_opt(v, base);
+ }
+ ast::expr_call(callee, args) {
+ walk_expr(v, callee);
+ walk_exprs(v, args);
+ }
+ ast::expr_self_method(_) { }
+ ast::expr_bind(callee, args) {
+ walk_expr(v, callee);
+ for eo: option::t[@ast::expr] in args { walk_expr_opt(v, eo); }
+ }
+ ast::expr_spawn(_, _, callee, args) {
+ walk_expr(v, callee);
+ walk_exprs(v, args);
+ }
+ ast::expr_binary(_, a, b) { walk_expr(v, a); walk_expr(v, b); }
+ ast::expr_unary(_, a) { walk_expr(v, a); }
+ ast::expr_lit(_) { }
+ ast::expr_cast(x, t) { walk_expr(v, x); walk_ty(v, t); }
+ ast::expr_if(x, b, eo) {
+ walk_expr(v, x);
+ walk_block(v, b);
+ walk_expr_opt(v, eo);
+ }
+ ast::expr_if_check(x, b, eo) {
+ walk_expr(v, x);
+ walk_block(v, b);
+ walk_expr_opt(v, eo);
+ }
+ ast::expr_ternary(c, t, e) {
+ walk_expr(v, c);
+ walk_expr(v, t);
+ walk_expr(v, e);
+ }
+ ast::expr_while(x, b) { walk_expr(v, x); walk_block(v, b); }
+ ast::expr_for(dcl, x, b) {
+ walk_local(v, dcl);
+ walk_expr(v, x);
+ walk_block(v, b);
+ }
+ ast::expr_for_each(dcl, x, b) {
+ walk_local(v, dcl);
+ walk_expr(v, x);
+ walk_block(v, b);
+ }
+ ast::expr_do_while(b, x) { walk_block(v, b); walk_expr(v, x); }
+ ast::expr_alt(x, arms) {
+ walk_expr(v, x);
+ for a: ast::arm in arms {
+ for p: @ast::pat in a.pats { walk_pat(v, p); }
+ v.visit_arm_pre(a);
+ walk_block(v, a.block);
+ v.visit_arm_post(a);
}
- case (ast::expr_call(?callee, ?args)) {
- walk_expr(v, callee);
- walk_exprs(v, args);
- }
- case (ast::expr_self_method(_)) { }
- case (ast::expr_bind(?callee, ?args)) {
- walk_expr(v, callee);
- for (option::t[@ast::expr] eo in args) { walk_expr_opt(v, eo); }
- }
- case (ast::expr_spawn(_, _, ?callee, ?args)) {
- walk_expr(v, callee);
- walk_exprs(v, args);
- }
- case (ast::expr_binary(_, ?a, ?b)) {
- walk_expr(v, a);
- walk_expr(v, b);
- }
- case (ast::expr_unary(_, ?a)) { walk_expr(v, a); }
- case (ast::expr_lit(_)) { }
- case (ast::expr_cast(?x, ?t)) { walk_expr(v, x); walk_ty(v, t); }
- case (ast::expr_if(?x, ?b, ?eo)) {
- walk_expr(v, x);
- walk_block(v, b);
- walk_expr_opt(v, eo);
- }
- case (ast::expr_if_check(?x, ?b, ?eo)) {
- walk_expr(v, x);
- walk_block(v, b);
- walk_expr_opt(v, eo);
- }
- case (ast::expr_ternary(?c, ?t, ?e)) {
- walk_expr(v, c);
- walk_expr(v, t);
- walk_expr(v, e);
- }
- case (ast::expr_while(?x, ?b)) {
- walk_expr(v, x);
- walk_block(v, b);
- }
- case (ast::expr_for(?dcl, ?x, ?b)) {
- walk_local(v, dcl);
- walk_expr(v, x);
- walk_block(v, b);
- }
- case (ast::expr_for_each(?dcl, ?x, ?b)) {
- walk_local(v, dcl);
- walk_expr(v, x);
- walk_block(v, b);
- }
- case (ast::expr_do_while(?b, ?x)) {
- walk_block(v, b);
- walk_expr(v, x);
- }
- case (ast::expr_alt(?x, ?arms)) {
- walk_expr(v, x);
- for (ast::arm a in arms) {
- for (@ast::pat p in a.pats) { walk_pat(v, p); }
- v.visit_arm_pre(a);
- walk_block(v, a.block);
- v.visit_arm_post(a);
- }
- }
- case (ast::expr_fn(?f)) {
- walk_fn(v, f, ~[], e.span, none, e.id);
- }
- case (ast::expr_block(?b)) { walk_block(v, b); }
- case (ast::expr_assign(?a, ?b)) {
- walk_expr(v, a);
- walk_expr(v, b);
- }
- case (ast::expr_move(?a, ?b)) { walk_expr(v, a); walk_expr(v, b); }
- case (ast::expr_swap(?a, ?b)) { walk_expr(v, a); walk_expr(v, b); }
- case (ast::expr_assign_op(_, ?a, ?b)) {
- walk_expr(v, a);
- walk_expr(v, b);
- }
- case (ast::expr_send(?a, ?b)) { walk_expr(v, a); walk_expr(v, b); }
- case (ast::expr_recv(?a, ?b)) { walk_expr(v, a); walk_expr(v, b); }
- case (ast::expr_field(?x, _)) { walk_expr(v, x); }
- case (ast::expr_index(?a, ?b)) {
- walk_expr(v, a);
- walk_expr(v, b);
- }
- case (ast::expr_path(?p)) {
- for (@ast::ty tp in p.node.types) { walk_ty(v, tp); }
- }
- case (ast::expr_fail(?eo)) { walk_expr_opt(v, eo); }
- case (ast::expr_break) { }
- case (ast::expr_cont) { }
- case (ast::expr_ret(?eo)) { walk_expr_opt(v, eo); }
- case (ast::expr_put(?eo)) { walk_expr_opt(v, eo); }
- case (ast::expr_be(?x)) { walk_expr(v, x); }
- case (ast::expr_log(_, ?x)) { walk_expr(v, x); }
- case (ast::expr_check(_, ?x)) { walk_expr(v, x); }
- case (ast::expr_assert(?x)) { walk_expr(v, x); }
- case (ast::expr_port(_)) { }
- case (ast::expr_chan(?x)) { walk_expr(v, x); }
- case (ast::expr_anon_obj(?anon_obj)) {
- // Fields
+ }
+ ast::expr_fn(f) { walk_fn(v, f, ~[], e.span, none, e.id); }
+ ast::expr_block(b) { walk_block(v, b); }
+ ast::expr_assign(a, b) { walk_expr(v, a); walk_expr(v, b); }
+ ast::expr_move(a, b) { walk_expr(v, a); walk_expr(v, b); }
+ ast::expr_swap(a, b) { walk_expr(v, a); walk_expr(v, b); }
+ ast::expr_assign_op(_, a, b) { walk_expr(v, a); walk_expr(v, b); }
+ ast::expr_send(a, b) { walk_expr(v, a); walk_expr(v, b); }
+ ast::expr_recv(a, b) { walk_expr(v, a); walk_expr(v, b); }
+ ast::expr_field(x, _) { walk_expr(v, x); }
+ ast::expr_index(a, b) { walk_expr(v, a); walk_expr(v, b); }
+ ast::expr_path(p) {
+ for tp: @ast::ty in p.node.types { walk_ty(v, tp); }
+ }
+ ast::expr_fail(eo) { walk_expr_opt(v, eo); }
+ ast::expr_break. { }
+ ast::expr_cont. { }
+ ast::expr_ret(eo) { walk_expr_opt(v, eo); }
+ ast::expr_put(eo) { walk_expr_opt(v, eo); }
+ ast::expr_be(x) { walk_expr(v, x); }
+ ast::expr_log(_, x) { walk_expr(v, x); }
+ ast::expr_check(_, x) { walk_expr(v, x); }
+ ast::expr_assert(x) { walk_expr(v, x); }
+ ast::expr_port(_) { }
+ ast::expr_chan(x) { walk_expr(v, x); }
+ ast::expr_anon_obj(anon_obj) {
+ // Fields
- alt (anon_obj.fields) {
- case (none) { }
- case (some(?fields)) {
- for (ast::anon_obj_field f in fields) {
- walk_ty(v, f.ty);
- walk_expr(v, f.expr);
- }
- }
+ alt anon_obj.fields {
+ none. { }
+ some(fields) {
+ for f: ast::anon_obj_field in fields {
+ walk_ty(v, f.ty);
+ walk_expr(v, f.expr);
}
- // with_obj
-
- alt (anon_obj.with_obj) {
- case (none) { }
- case (some(?e)) { walk_expr(v, e); }
- }
-
- // Methods
- for (@ast::method m in anon_obj.methods) {
- v.visit_method_pre(m);
- walk_fn(v, m.node.meth, ~[], m.span, some(m.node.ident),
- m.node.id);
- v.visit_method_post(m);
- }
+ }
}
- case (ast::expr_mac(?mac)) {
- walk_mac(v, mac);
+ // with_obj
+
+ alt anon_obj.with_obj { none. { } some(e) { walk_expr(v, e); } }
+
+
+ // Methods
+ for m: @ast::method in anon_obj.methods {
+ v.visit_method_pre(m);
+ walk_fn(v, m.node.meth, ~[], m.span, some(m.node.ident),
+ m.node.id);
+ v.visit_method_post(m);
}
+ }
+ ast::expr_mac(mac) { walk_mac(v, mac); }
}
v.visit_expr_post(e);
}
@@ -422,73 +389,74 @@
fn def_want_crate_directives() -> bool { ret false; }
-fn def_visit_crate(&ast::crate c) { }
+fn def_visit_crate(c: &ast::crate) { }
-fn def_visit_crate_directive(&@ast::crate_directive c) { }
+fn def_visit_crate_directive(c: &@ast::crate_directive) { }
-fn def_visit_view_item(&@ast::view_item vi) { }
+fn def_visit_view_item(vi: &@ast::view_item) { }
-fn def_visit_native_item(&@ast::native_item ni) { }
+fn def_visit_native_item(ni: &@ast::native_item) { }
-fn def_visit_item(&@ast::item i) { }
+fn def_visit_item(i: &@ast::item) { }
-fn def_visit_method(&@ast::method m) { }
+fn def_visit_method(m: &@ast::method) { }
-fn def_visit_block(&ast::blk b) { }
+fn def_visit_block(b: &ast::blk) { }
-fn def_visit_stmt(&@ast::stmt s) { }
+fn def_visit_stmt(s: &@ast::stmt) { }
-fn def_visit_arm(&ast::arm a) { }
+fn def_visit_arm(a: &ast::arm) { }
-fn def_visit_pat(&@ast::pat p) { }
+fn def_visit_pat(p: &@ast::pat) { }
-fn def_visit_decl(&@ast::decl d) { }
+fn def_visit_decl(d: &@ast::decl) { }
-fn def_visit_local(&@ast::local l) { }
+fn def_visit_local(l: &@ast::local) { }
-fn def_visit_expr(&@ast::expr e) { }
+fn def_visit_expr(e: &@ast::expr) { }
-fn def_visit_ty(&@ast::ty t) { }
+fn def_visit_ty(t: &@ast::ty) { }
-fn def_visit_constr(&@ast::constr c) { }
+fn def_visit_constr(c: &@ast::constr) { }
-fn def_visit_fn(&ast::_fn f, &ast::ty_param[] tps,
- &span sp, &ast::fn_ident i, ast::node_id d) { }
+fn def_visit_fn(f: &ast::_fn, tps: &ast::ty_param[], sp: &span,
+ i: &ast::fn_ident, d: ast::node_id) {
+}
fn default_visitor() -> ast_visitor {
- ret rec(keep_going=def_keep_going,
- want_crate_directives=def_want_crate_directives,
- visit_crate_pre=def_visit_crate,
- visit_crate_post=def_visit_crate,
- visit_crate_directive_pre=def_visit_crate_directive,
- visit_crate_directive_post=def_visit_crate_directive,
- visit_view_item_pre=def_visit_view_item,
- visit_view_item_post=def_visit_view_item,
- visit_native_item_pre=def_visit_native_item,
- visit_native_item_post=def_visit_native_item,
- visit_item_pre=def_visit_item,
- visit_item_post=def_visit_item,
- visit_method_pre=def_visit_method,
- visit_method_post=def_visit_method,
- visit_block_pre=def_visit_block,
- visit_block_post=def_visit_block,
- visit_stmt_pre=def_visit_stmt,
- visit_stmt_post=def_visit_stmt,
- visit_arm_pre=def_visit_arm,
- visit_arm_post=def_visit_arm,
- visit_pat_pre=def_visit_pat,
- visit_pat_post=def_visit_pat,
- visit_decl_pre=def_visit_decl,
- visit_decl_post=def_visit_decl,
- visit_local_pre=def_visit_local,
- visit_local_post=def_visit_local,
- visit_expr_pre=def_visit_expr,
- visit_expr_post=def_visit_expr,
- visit_ty_pre=def_visit_ty,
- visit_ty_post=def_visit_ty,
- visit_constr=def_visit_constr,
- visit_fn_pre=def_visit_fn,
- visit_fn_post=def_visit_fn);
+ ret {keep_going: def_keep_going,
+ want_crate_directives: def_want_crate_directives,
+ visit_crate_pre: def_visit_crate,
+ visit_crate_post: def_visit_crate,
+ visit_crate_directive_pre: def_visit_crate_directive,
+ visit_crate_directive_post: def_visit_crate_directive,
+ visit_view_item_pre: def_visit_view_item,
+ visit_view_item_post: def_visit_view_item,
+ visit_native_item_pre: def_visit_native_item,
+ visit_native_item_post: def_visit_native_item,
+ visit_item_pre: def_visit_item,
+ visit_item_post: def_visit_item,
+ visit_method_pre: def_visit_method,
+ visit_method_post: def_visit_method,
+ visit_block_pre: def_visit_block,
+ visit_block_post: def_visit_block,
+ visit_stmt_pre: def_visit_stmt,
+ visit_stmt_post: def_visit_stmt,
+ visit_arm_pre: def_visit_arm,
+ visit_arm_post: def_visit_arm,
+ visit_pat_pre: def_visit_pat,
+ visit_pat_post: def_visit_pat,
+ visit_decl_pre: def_visit_decl,
+ visit_decl_post: def_visit_decl,
+ visit_local_pre: def_visit_local,
+ visit_local_post: def_visit_local,
+ visit_expr_pre: def_visit_expr,
+ visit_expr_post: def_visit_expr,
+ visit_ty_pre: def_visit_ty,
+ visit_ty_post: def_visit_ty,
+ visit_constr: def_visit_constr,
+ visit_fn_pre: def_visit_fn,
+ visit_fn_post: def_visit_fn};
}
//
// Local Variables:
diff --git a/src/comp/util/common.rs b/src/comp/util/common.rs
index a6cd472..91ab266 100644
--- a/src/comp/util/common.rs
+++ b/src/comp/util/common.rs
@@ -30,164 +30,137 @@
type flag = hashmap[str, ()];
-fn def_eq(&ast::def_id a, &ast::def_id b) -> bool {
+fn def_eq(a: &ast::def_id, b: &ast::def_id) -> bool {
ret a.crate == b.crate && a.node == b.node;
}
-fn hash_def(&ast::def_id d) -> uint {
- auto h = 5381u;
+fn hash_def(d: &ast::def_id) -> uint {
+ let h = 5381u;
h = (h << 5u) + h ^ (d.crate as uint);
h = (h << 5u) + h ^ (d.node as uint);
ret h;
}
fn new_def_hash[V]() -> std::map::hashmap[ast::def_id, V] {
- let std::map::hashfn[ast::def_id] hasher = hash_def;
- let std::map::eqfn[ast::def_id] eqer = def_eq;
+ let hasher: std::map::hashfn[ast::def_id] = hash_def;
+ let eqer: std::map::eqfn[ast::def_id] = def_eq;
ret std::map::mk_hashmap[ast::def_id, V](hasher, eqer);
}
-fn elt_expr(&ast::elt e) -> @ast::expr { ret e.expr; }
+fn elt_expr(e: &ast::elt) -> @ast::expr { ret e.expr; }
-fn elt_exprs(&ast::elt[] elts) -> (@ast::expr)[] {
- auto es = ~[];
- for (ast::elt e in elts) { es += ~[e.expr]; }
+fn elt_exprs(elts: &ast::elt[]) -> (@ast::expr)[] {
+ let es = ~[];
+ for e: ast::elt in elts { es += ~[e.expr]; }
ret es;
}
-fn field_expr(&ast::field f) -> @ast::expr { ret f.node.expr; }
+fn field_expr(f: &ast::field) -> @ast::expr { ret f.node.expr; }
-fn field_exprs(&ast::field[] fields) -> (@ast::expr)[] {
- auto es = ~[];
- for (ast::field f in fields) { es += ~[f.node.expr]; }
+fn field_exprs(fields: &ast::field[]) -> (@ast::expr)[] {
+ let es = ~[];
+ for f: ast::field in fields { es += ~[f.node.expr]; }
ret es;
}
-fn log_expr(&ast::expr e) { log print::pprust::expr_to_str(@e); }
+fn log_expr(e: &ast::expr) { log print::pprust::expr_to_str(@e); }
-fn log_expr_err(&ast::expr e) { log_err print::pprust::expr_to_str(@e); }
+fn log_expr_err(e: &ast::expr) { log_err print::pprust::expr_to_str(@e); }
-fn log_ty_err(&ty t) { log_err print::pprust::ty_to_str(t); }
+fn log_ty_err(t: &ty) { log_err print::pprust::ty_to_str(t); }
-fn log_pat_err(&@pat p) { log_err print::pprust::pat_to_str(p); }
+fn log_pat_err(p: &@pat) { log_err print::pprust::pat_to_str(p); }
-fn log_block(&ast::blk b) { log print::pprust::block_to_str(b); }
+fn log_block(b: &ast::blk) { log print::pprust::block_to_str(b); }
-fn log_block_err(&ast::blk b) { log_err print::pprust::block_to_str(b); }
+fn log_block_err(b: &ast::blk) { log_err print::pprust::block_to_str(b); }
-fn log_item_err(&@ast::item i) { log_err print::pprust::item_to_str(i); }
+fn log_item_err(i: &@ast::item) { log_err print::pprust::item_to_str(i); }
-fn log_fn(&ast::_fn f, str name, &ast::ty_param[] params) {
+fn log_fn(f: &ast::_fn, name: str, params: &ast::ty_param[]) {
log print::pprust::fun_to_str(f, name, params);
}
-fn log_fn_err(&ast::_fn f, str name, &ast::ty_param[] params) {
+fn log_fn_err(f: &ast::_fn, name: str, params: &ast::ty_param[]) {
log_err print::pprust::fun_to_str(f, name, params);
}
-fn log_stmt(&ast::stmt st) { log print::pprust::stmt_to_str(st); }
+fn log_stmt(st: &ast::stmt) { log print::pprust::stmt_to_str(st); }
-fn log_stmt_err(&ast::stmt st) { log_err print::pprust::stmt_to_str(st); }
+fn log_stmt_err(st: &ast::stmt) { log_err print::pprust::stmt_to_str(st); }
-fn has_nonlocal_exits(&ast::blk b) -> bool {
- auto has_exits = @mutable false;
- fn visit_expr(@mutable bool flag, &@ast::expr e) {
- alt (e.node) {
- case (ast::expr_break) { *flag = true; }
- case (ast::expr_cont) { *flag = true; }
- case (_) { }
+fn has_nonlocal_exits(b: &ast::blk) -> bool {
+ let has_exits = @mutable false;
+ fn visit_expr(flag: @mutable bool, e: &@ast::expr) {
+ alt e.node {
+ ast::expr_break. { *flag = true; }
+ ast::expr_cont. { *flag = true; }
+ _ { }
}
}
- auto v = visit::mk_simple_visitor
- (@rec(visit_expr=bind visit_expr(has_exits, _)
- with *visit::default_simple_visitor()));
+ let v =
+ visit::mk_simple_visitor(@{visit_expr: bind visit_expr(has_exits, _)
+ with *visit::default_simple_visitor()});
visit::visit_block(b, (), v);
ret *has_exits;
}
-fn local_rhs_span(&@ast::local l, &span def) -> span {
- alt (l.node.init) {
- case (some(?i)) { ret i.expr.span; }
- case (_) { ret def; }
+fn local_rhs_span(l: &@ast::local, def: &span) -> span {
+ alt l.node.init { some(i) { ret i.expr.span; } _ { ret def; } }
+}
+
+fn lit_eq(l: &@ast::lit, m: &@ast::lit) -> bool {
+ alt l.node {
+ ast::lit_str(s, kind_s) {
+ alt m.node {
+ ast::lit_str(t, kind_t) { ret s == t && kind_s == kind_t; }
+ _ { ret false; }
+ }
+ }
+ ast::lit_char(c) {
+ alt m.node { ast::lit_char(d) { ret c == d; } _ { ret false; } }
+ }
+ ast::lit_int(i) {
+ alt m.node { ast::lit_int(j) { ret i == j; } _ { ret false; } }
+ }
+ ast::lit_uint(i) {
+ alt m.node { ast::lit_uint(j) { ret i == j; } _ { ret false; } }
+ }
+ ast::lit_mach_int(_, i) {
+ alt m.node {
+ ast::lit_mach_int(_, j) { ret i == j; }
+ _ { ret false; }
+ }
+ }
+ ast::lit_float(s) {
+ alt m.node { ast::lit_float(t) { ret s == t; } _ { ret false; } }
+ }
+ ast::lit_mach_float(_, s) {
+ alt m.node {
+ ast::lit_mach_float(_, t) { ret s == t; }
+ _ { ret false; }
+ }
+ }
+ ast::lit_nil. {
+ alt m.node { ast::lit_nil. { ret true; } _ { ret false; } }
+ }
+ ast::lit_bool(b) {
+ alt m.node { ast::lit_bool(c) { ret b == c; } _ { ret false; } }
+ }
}
}
-fn lit_eq(&@ast::lit l, &@ast::lit m) -> bool {
- alt (l.node) {
- case (ast::lit_str(?s, ?kind_s)) {
- alt (m.node) {
- case (ast::lit_str(?t, ?kind_t)) {
- ret s == t && kind_s == kind_t;
- }
- case (_) { ret false; }
- }
- }
- case (ast::lit_char(?c)) {
- alt (m.node) {
- case (ast::lit_char(?d)) { ret c == d; }
- case (_) { ret false; }
- }
- }
- case (ast::lit_int(?i)) {
- alt (m.node) {
- case (ast::lit_int(?j)) { ret i == j; }
- case (_) { ret false; }
- }
- }
- case (ast::lit_uint(?i)) {
- alt (m.node) {
- case (ast::lit_uint(?j)) { ret i == j; }
- case (_) { ret false; }
- }
- }
- case (ast::lit_mach_int(_, ?i)) {
- alt (m.node) {
- case (ast::lit_mach_int(_, ?j)) { ret i == j; }
- case (_) { ret false; }
- }
- }
- case (ast::lit_float(?s)) {
- alt (m.node) {
- case (ast::lit_float(?t)) { ret s == t; }
- case (_) { ret false; }
- }
- }
- case (ast::lit_mach_float(_, ?s)) {
- alt (m.node) {
- case (ast::lit_mach_float(_, ?t)) { ret s == t; }
- case (_) { ret false; }
- }
- }
- case (ast::lit_nil) {
- alt (m.node) {
- case (ast::lit_nil) { ret true; }
- case (_) { ret false; }
- }
- }
- case (ast::lit_bool(?b)) {
- alt (m.node) {
- case (ast::lit_bool(?c)) { ret b == c; }
- case (_) { ret false; }
- }
- }
+tag call_kind { kind_call; kind_spawn; kind_bind; }
+
+fn call_kind_str(c: call_kind) -> str {
+ alt c {
+ kind_call. { "Call" }
+ kind_spawn. { "Spawn" }
+ kind_bind. { "Bind" }
}
}
-tag call_kind {
- kind_call;
- kind_spawn;
- kind_bind;
-}
-
-fn call_kind_str(call_kind c) -> str {
- alt (c) {
- case (kind_call) { "Call" }
- case (kind_spawn) { "Spawn" }
- case (kind_bind) { "Bind" }
- }
-}
-
-fn is_main_name(&str[] path) -> bool {
+fn is_main_name(path: &str[]) -> bool {
str::eq(option::get(std::ivec::last(path)), "main")
}
//
diff --git a/src/comp/util/ppaux.rs b/src/comp/util/ppaux.rs
index 3cef5fe..946ec11 100644
--- a/src/comp/util/ppaux.rs
+++ b/src/comp/util/ppaux.rs
@@ -19,155 +19,150 @@
import ast::ty_mach_to_str;
import syntax::ast;
-fn mode_str(&ty::mode m) -> str {
- alt (m) {
- case (mo_val) { "" }
- case (mo_alias(false)) { "&" }
- case (mo_alias(true)) { "&mutable " }
+fn mode_str(m: &ty::mode) -> str {
+ alt m {
+ mo_val. { "" }
+ mo_alias(false) { "&" }
+ mo_alias(true) { "&mutable " }
}
}
-fn mode_str_1(&ty::mode m) -> str {
- alt (m) {
- case (mo_val) { "val" }
- case (_) { mode_str(m) }
- }
+fn mode_str_1(m: &ty::mode) -> str {
+ alt m { mo_val. { "val" } _ { mode_str(m) } }
}
-fn fn_ident_to_string(ast::node_id id, &ast::fn_ident i) -> str {
- ret alt (i) {
- case (none) { "anon" + int::str(id) }
- case (some(?s)) { s }
- };
+fn fn_ident_to_string(id: ast::node_id, i: &ast::fn_ident) -> str {
+ ret alt i { none. { "anon" + int::str(id) } some(s) { s } };
}
-fn ty_to_str(&ctxt cx, &t typ) -> str {
- fn fn_input_to_str(&ctxt cx, &rec(middle::ty::mode mode, t ty) input) ->
+fn ty_to_str(cx: &ctxt, typ: &t) -> str {
+ fn fn_input_to_str(cx: &ctxt, input: &{mode: middle::ty::mode, ty: t}) ->
str {
- auto s = mode_str(input.mode);
+ let s = mode_str(input.mode);
ret s + ty_to_str(cx, input.ty);
}
- fn fn_to_str(&ctxt cx, ast::proto proto, option::t[ast::ident] ident,
- &arg[] inputs, t output, ast::controlflow cf,
- &(@constr)[] constrs) -> str {
- auto s = proto_to_str(proto);
- alt (ident) { case (some(?i)) { s += " "; s += i; } case (_) { } }
+ fn fn_to_str(cx: &ctxt, proto: ast::proto, ident: option::t[ast::ident],
+ inputs: &arg[], output: t, cf: ast::controlflow,
+ constrs: &(@constr)[]) -> str {
+ let s = proto_to_str(proto);
+ alt ident { some(i) { s += " "; s += i; } _ { } }
s += "(";
- auto strs = [];
- for (arg a in inputs) { strs += [fn_input_to_str(cx, a)]; }
+ let strs = [];
+ for a: arg in inputs { strs += [fn_input_to_str(cx, a)]; }
s += str::connect(strs, ", ");
s += ")";
- if (struct(cx, output) != ty_nil) {
- alt (cf) {
- case (ast::noreturn) { s += " -> !"; }
- case (ast::return) { s += " -> " + ty_to_str(cx, output); }
+ if struct(cx, output) != ty_nil {
+ alt cf {
+ ast::noreturn. { s += " -> !"; }
+ ast::return. { s += " -> " + ty_to_str(cx, output); }
}
}
s += constrs_str(constrs);
ret s;
}
- fn method_to_str(&ctxt cx, &method m) -> str {
+ fn method_to_str(cx: &ctxt, m: &method) -> str {
ret fn_to_str(cx, m.proto, some[ast::ident](m.ident), m.inputs,
m.output, m.cf, m.constrs) + ";";
}
- fn field_to_str(&ctxt cx, &field f) -> str {
+ fn field_to_str(cx: &ctxt, f: &field) -> str {
ret mt_to_str(cx, f.mt) + " " + f.ident;
}
- fn mt_to_str(&ctxt cx, &mt m) -> str {
- auto mstr;
- alt (m.mut) {
- case (ast::mut) { mstr = "mutable "; }
- case (ast::imm) { mstr = ""; }
- case (ast::maybe_mut) { mstr = "mutable? "; }
+ fn mt_to_str(cx: &ctxt, m: &mt) -> str {
+ let mstr;
+ alt m.mut {
+ ast::mut. { mstr = "mutable "; }
+ ast::imm. { mstr = ""; }
+ ast::maybe_mut. { mstr = "mutable? "; }
}
ret mstr + ty_to_str(cx, m.ty);
}
- alt (cname(cx, typ)) { case (some(?cs)) { ret cs; } case (_) { } }
- auto s = "";
- alt (struct(cx, typ)) {
- case (ty_native(_)) { s += "native"; }
- case (ty_nil) { s += "()"; }
- case (ty_bot) { s += "_|_"; }
- case (ty_bool) { s += "bool"; }
- case (ty_int) { s += "int"; }
- case (ty_float) { s += "float"; }
- case (ty_uint) { s += "uint"; }
- case (ty_machine(?tm)) { s += ty_mach_to_str(tm); }
- case (ty_char) { s += "char"; }
- case (ty_str) { s += "str"; }
- case (ty_istr) { s += "istr"; }
- case (ty_box(?tm)) { s += "@" + mt_to_str(cx, tm); }
- case (ty_vec(?tm)) { s += "vec[" + mt_to_str(cx, tm) + "]"; }
- case (ty_ivec(?tm)) { s += "ivec[" + mt_to_str(cx, tm) + "]"; }
- case (ty_port(?t)) { s += "port[" + ty_to_str(cx, t) + "]"; }
- case (ty_chan(?t)) { s += "chan[" + ty_to_str(cx, t) + "]"; }
- case (ty_type) { s += "type"; }
- case (ty_task) { s += "task"; }
- case (ty_rec(?elems)) {
- let str[] strs = ~[];
- for (field fld in elems) { strs += ~[field_to_str(cx, fld)]; }
- s += "rec(" + str::connect_ivec(strs, ",") + ")";
- }
- case (ty_tag(?id, ?tps)) {
- // The user should never see this if the cname is set properly!
+ alt cname(cx, typ) { some(cs) { ret cs; } _ { } }
+ let s = "";
+ alt struct(cx, typ) {
+ ty_native(_) { s += "native"; }
+ ty_nil. { s += "()"; }
+ ty_bot. { s += "_|_"; }
+ ty_bool. { s += "bool"; }
+ ty_int. { s += "int"; }
+ ty_float. { s += "float"; }
+ ty_uint. { s += "uint"; }
+ ty_machine(tm) { s += ty_mach_to_str(tm); }
+ ty_char. { s += "char"; }
+ ty_str. { s += "str"; }
+ ty_istr. { s += "istr"; }
+ ty_box(tm) { s += "@" + mt_to_str(cx, tm); }
+ ty_vec(tm) { s += "vec[" + mt_to_str(cx, tm) + "]"; }
+ ty_ivec(tm) { s += "ivec[" + mt_to_str(cx, tm) + "]"; }
+ ty_port(t) { s += "port[" + ty_to_str(cx, t) + "]"; }
+ ty_chan(t) { s += "chan[" + ty_to_str(cx, t) + "]"; }
+ ty_type. { s += "type"; }
+ ty_task. { s += "task"; }
+ ty_rec(elems) {
+ let strs: str[] = ~[];
+ for fld: field in elems { strs += ~[field_to_str(cx, fld)]; }
+ s += "rec(" + str::connect_ivec(strs, ",") + ")";
+ }
+ ty_tag(id, tps) {
+ // The user should never see this if the cname is set properly!
- s += "<tag#" + int::str(id.crate) + ":" + int::str(id.node) + ">";
- if (ivec::len[t](tps) > 0u) {
- let str[] strs = ~[];
- for (t typ in tps) { strs += ~[ty_to_str(cx, typ)]; }
- s += "[" + str::connect_ivec(strs, ",") + "]";
- }
+ s += "<tag#" + int::str(id.crate) + ":" + int::str(id.node) + ">";
+ if ivec::len[t](tps) > 0u {
+ let strs: str[] = ~[];
+ for typ: t in tps { strs += ~[ty_to_str(cx, typ)]; }
+ s += "[" + str::connect_ivec(strs, ",") + "]";
}
- case (ty_fn(?proto, ?inputs, ?output, ?cf, ?constrs)) {
- s += fn_to_str(cx, proto, none, inputs, output, cf, constrs);
- }
- case (ty_native_fn(_, ?inputs, ?output)) {
- s += fn_to_str(cx, ast::proto_fn, none, inputs, output,
- ast::return, ~[]);
- }
- case (ty_obj(?meths)) {
- auto strs = ~[];
- for (method m in meths) { strs += ~[method_to_str(cx, m)]; }
- s += "obj {\n\t" + str::connect_ivec(strs, "\n\t") + "\n}";
- }
- case (ty_res(?id, _, _)) {
- s += "<resource#" + int::str(id.node) + ":" +
- int::str(id.crate) + ">";
- }
- case (ty_var(?v)) { s += "<T" + int::str(v) + ">"; }
- case (ty_param(?id)) {
- s += "'" + str::unsafe_from_bytes([('a' as u8) + (id as u8)]);
- }
- case (_) { s += ty_to_short_str(cx, typ); }
+ }
+ ty_fn(proto, inputs, output, cf, constrs) {
+ s += fn_to_str(cx, proto, none, inputs, output, cf, constrs);
+ }
+ ty_native_fn(_, inputs, output) {
+ s +=
+ fn_to_str(cx, ast::proto_fn, none, inputs, output, ast::return,
+ ~[]);
+ }
+ ty_obj(meths) {
+ let strs = ~[];
+ for m: method in meths { strs += ~[method_to_str(cx, m)]; }
+ s += "obj {\n\t" + str::connect_ivec(strs, "\n\t") + "\n}";
+ }
+ ty_res(id, _, _) {
+ s +=
+ "<resource#" + int::str(id.node) + ":" + int::str(id.crate) + ">";
+ }
+ ty_var(v) { s += "<T" + int::str(v) + ">"; }
+ ty_param(id) {
+ s += "'" + str::unsafe_from_bytes([('a' as u8) + (id as u8)]);
+ }
+ _ { s += ty_to_short_str(cx, typ); }
}
ret s;
}
-fn ty_to_short_str(&ctxt cx, t typ) -> str {
- auto s = encoder::encoded_ty(cx, typ);
- if (str::byte_len(s) >= 32u) { s = str::substr(s, 0u, 32u); }
+fn ty_to_short_str(cx: &ctxt, typ: t) -> str {
+ let s = encoder::encoded_ty(cx, typ);
+ if str::byte_len(s) >= 32u { s = str::substr(s, 0u, 32u); }
ret s;
}
-fn constr_to_str(&@constr c) -> str {
+fn constr_to_str(c: &@constr) -> str {
ret path_to_str(c.node.path) +
- pprust::constr_args_to_str(pprust::uint_to_str, c.node.args);
+ pprust::constr_args_to_str(pprust::uint_to_str, c.node.args);
}
-fn constrs_str(&(@constr)[] constrs) -> str {
- auto s = "";
- auto colon = true;
- for (@constr c in constrs) {
- if (colon) { s += " : "; colon = false; } else { s += ", "; }
+fn constrs_str(constrs: &(@constr)[]) -> str {
+ let s = "";
+ let colon = true;
+ for c: @constr in constrs {
+ if colon { s += " : "; colon = false; } else { s += ", "; }
s += constr_to_str(c);
}
ret s;
}
-fn ty_constr_to_str[Q](&@ast::spanned[ast::constr_general_[ast::path,Q]]
- c) -> str {
+fn ty_constr_to_str[Q](c: &@ast::spanned[ast::constr_general_[ast::path, Q]])
+ -> str {
ret path_to_str(c.node.path) +
- constr_args_to_str[ast::path](path_to_str, c.node.args);
+ constr_args_to_str[ast::path](path_to_str, c.node.args);
}
// Local Variables:
diff --git a/src/fuzzer/ast_match.rs b/src/fuzzer/ast_match.rs
index 001172a..fd9a553 100644
--- a/src/fuzzer/ast_match.rs
+++ b/src/fuzzer/ast_match.rs
@@ -1,32 +1,27 @@
use std;
import std::ivec;
-fn ivec_equal[T](&T[] v, &T[] u, fn (&T, &T) -> bool element_equality_test) -> bool {
- auto Lv = ivec::len(v);
- if (Lv != ivec::len(u)) {
- ret false;
- }
- auto i = 0u;
- while (i < Lv) {
- if (!element_equality_test(v.(i), u.(i))) {
- ret false;
- }
+fn ivec_equal[T](v: &T[], u: &T[], element_equality_test: fn(&T, &T) -> bool )
+ -> bool {
+ let Lv = ivec::len(v);
+ if Lv != ivec::len(u) { ret false; }
+ let i = 0u;
+ while i < Lv {
+ if !element_equality_test(v.(i), u.(i)) { ret false; }
i += 1u;
}
ret true;
}
-fn builtin_equal[T](&T a, &T b) -> bool {
- ret a == b;
-}
+fn builtin_equal[T](a: &T, b: &T) -> bool { ret a == b; }
fn main() {
- assert builtin_equal(5, 5);
- assert !builtin_equal(5, 4);
- assert !ivec_equal(~[5, 5], ~[5], builtin_equal);
- assert !ivec_equal(~[5, 5], ~[5, 4], builtin_equal);
- assert !ivec_equal(~[5, 5], ~[4, 5], builtin_equal);
- assert ivec_equal(~[5, 5], ~[5, 5], builtin_equal);
+ assert (builtin_equal(5, 5));
+ assert (!builtin_equal(5, 4));
+ assert (!ivec_equal(~[5, 5], ~[5], builtin_equal));
+ assert (!ivec_equal(~[5, 5], ~[5, 4], builtin_equal));
+ assert (!ivec_equal(~[5, 5], ~[4, 5], builtin_equal));
+ assert (ivec_equal(~[5, 5], ~[5, 5], builtin_equal));
log_err "Pass";
-}
+}
\ No newline at end of file
diff --git a/src/fuzzer/fuzzer.rs b/src/fuzzer/fuzzer.rs
index 390da30..5a7fa15 100644
--- a/src/fuzzer/fuzzer.rs
+++ b/src/fuzzer/fuzzer.rs
@@ -45,111 +45,132 @@
import rustc::lib::llvm;
*/
-fn read_whole_file(&str filename) -> str {
+fn read_whole_file(filename: &str) -> str {
str::unsafe_from_bytes_ivec(ioivec::file_reader(filename).read_whole_stream())
}
-fn write_file(&str filename, &str content) {
- ioivec::file_writer(filename, ~[ioivec::create,
- ioivec::truncate]).write_str(content);
+fn write_file(filename: &str, content: &str) {
+ ioivec::file_writer(filename,
+ ~[ioivec::create,
+ ioivec::truncate]).write_str(content);
}
-fn file_contains(&str filename, &str needle) -> bool {
- auto contents = read_whole_file(filename);
+fn file_contains(filename: &str, needle: &str) -> bool {
+ let contents = read_whole_file(filename);
ret str::find(contents, needle) != -1;
}
-fn contains(&str haystack, &str needle) -> bool { str::find(haystack, needle) != -1 }
+fn contains(haystack: &str, needle: &str) -> bool {
+ str::find(haystack, needle) != -1
+}
-fn find_rust_files(&mutable str[] files, str path) {
- if (str::ends_with(path, ".rs")) {
- if (file_contains(path, "xfail-stage1")) {
+fn find_rust_files(files: &mutable str[], path: str) {
+ if str::ends_with(path, ".rs") {
+ if file_contains(path, "xfail-stage1") {
//log_err "Skipping " + path + " because it is marked as xfail-stage1";
- } else {
- files += ~[path];
- }
- } else if (fs::file_is_dir(path) && str::find(path, "compile-fail") == -1) {
- for (str p in fs::list_dir(path)) {
- find_rust_files(files, p);
- }
+ } else { files += ~[path]; }
+ } else if (fs::file_is_dir(path) && str::find(path, "compile-fail") == -1)
+ {
+ for p: str in fs::list_dir(path) { find_rust_files(files, p); }
}
}
-fn safe_to_steal(ast::expr_ e) -> bool {
- alt (e) {
- // pretty-printer precedence issues -- https://github.com/graydon/rust/issues/670
- case (ast::expr_unary(_, _)) { false }
- case (ast::expr_lit(?lit)) {
- alt(lit.node) {
- case(ast::lit_str(_, _)) { true }
- case(ast::lit_char(_)) { true }
- case(ast::lit_int(_)) { false }
- case(ast::lit_uint(_)) { false }
- case(ast::lit_mach_int(_, _)) { false }
- case(ast::lit_float(_)) { false }
- case(ast::lit_mach_float(_, _)) { false }
- case(ast::lit_nil) { true }
- case(ast::lit_bool(_)) { true }
- }
+fn safe_to_steal(e: ast::expr_) -> bool {
+ alt e {
+
+ // pretty-printer precedence issues -- https://github.com/graydon/rust/issues/670
+ ast::expr_unary(_, _) {
+ false
+ }
+ ast::expr_lit(lit) {
+ alt lit.node {
+ ast::lit_str(_, _) { true }
+ ast::lit_char(_) { true }
+ ast::lit_int(_) { false }
+ ast::lit_uint(_) { false }
+ ast::lit_mach_int(_, _) { false }
+ ast::lit_float(_) { false }
+ ast::lit_mach_float(_, _) { false }
+ ast::lit_nil. { true }
+ ast::lit_bool(_) { true }
}
- case (ast::expr_cast(_, _)) { false }
- case (ast::expr_send(_, _)) { false }
- case (ast::expr_recv(_, _)) { false }
- case (ast::expr_assert(_)) { false }
- case (ast::expr_binary(_, _, _)) { false }
- case (ast::expr_assign(_, _)) { false }
- case (ast::expr_assign_op(_, _, _)) { false }
+ }
+ ast::expr_cast(_, _) { false }
+ ast::expr_send(_, _) { false }
+ ast::expr_recv(_, _) { false }
+ ast::expr_assert(_) { false }
+ ast::expr_binary(_, _, _) { false }
+ ast::expr_assign(_, _) { false }
+ ast::expr_assign_op(_, _, _) { false }
- // https://github.com/graydon/rust/issues/676
- case (ast::expr_ret(option::none)) { false }
- case (ast::expr_put(option::none)) { false }
- case (_) { true }
+ // https://github.com/graydon/rust/issues/676
+ ast::expr_ret(option::none.) {
+ false
+ }
+ ast::expr_put(option::none.) { false }
+
+
+ _ {
+ true
+ }
}
}
-fn steal_exprs(&ast::crate crate) -> ast::expr[] {
- let @mutable ast::expr[] exprs = @mutable ~[];
+fn steal_exprs(crate: &ast::crate) -> ast::expr[] {
+ let exprs: @mutable ast::expr[] = @mutable ~[];
// "Stash" is not type-parameterized because of the need for safe_to_steal
- fn stash_expr(@mutable ast::expr[] es, &@ast::expr e) { if (safe_to_steal(e.node)) { *es += ~[*e]; } else { /* now my indices are wrong :( */ } }
- auto v = rec(visit_expr_pre = bind stash_expr(exprs, _) with walk::default_visitor());
+ fn stash_expr(es: @mutable ast::expr[], e: &@ast::expr) {
+ if safe_to_steal(e.node) {
+ *es += ~[*e];
+ } else {/* now my indices are wrong :( */ }
+ }
+ let v =
+ {visit_expr_pre: bind stash_expr(exprs, _)
+ with walk::default_visitor()};
walk::walk_crate(v, crate);
*exprs
}
// https://github.com/graydon/rust/issues/652
-fn safe_to_replace(ast::expr_ e) -> bool {
- alt (e) {
- case (ast::expr_if(_, _, _)) { false }
- case (ast::expr_block(_)) { false }
- case (_) { true }
+fn safe_to_replace(e: ast::expr_) -> bool {
+ alt e {
+ ast::expr_if(_, _, _) { false }
+ ast::expr_block(_) { false }
+ _ { true }
}
}
// Replace the |i|th expr (in fold order) of |crate| with |newexpr|.
-fn replace_expr_in_crate(&ast::crate crate, uint i, ast::expr_ newexpr) -> ast::crate {
- let @mutable uint j = @mutable 0u;
- fn fold_expr_rep(@mutable uint j_, uint i_, &ast::expr_ newexpr_, &ast::expr_ original, fold::ast_fold fld) -> ast::expr_ {
- *j_ += 1u;
- if (i_ + 1u == *j_ && safe_to_replace(original)) {
- newexpr_
- } else {
- fold::noop_fold_expr(original, fld)
- }
+fn replace_expr_in_crate(crate: &ast::crate, i: uint, newexpr: ast::expr_) ->
+ ast::crate {
+ let j: @mutable uint = @mutable 0u;
+ fn fold_expr_rep(j_: @mutable uint, i_: uint, newexpr_: &ast::expr_,
+ original: &ast::expr_, fld: fold::ast_fold) ->
+ ast::expr_ {
+ *j_ += 1u;
+ if i_ + 1u == *j_ && safe_to_replace(original) {
+ newexpr_
+ } else { fold::noop_fold_expr(original, fld) }
}
- auto afp = rec(fold_expr = bind fold_expr_rep(j, i, newexpr, _, _) with *fold::default_ast_fold());
- auto af = fold::make_fold(afp);
- let @ast::crate crate2 = @af.fold_crate(crate);
+ let afp =
+ {fold_expr: bind fold_expr_rep(j, i, newexpr, _, _)
+ with *fold::default_ast_fold()};
+ let af = fold::make_fold(afp);
+ let crate2: @ast::crate = @af.fold_crate(crate);
fold::dummy_out(af); // work around a leak (https://github.com/graydon/rust/issues/651)
*crate2
}
-iter under(uint n) -> uint { let uint i = 0u; while (i < n) { put i; i += 1u; } }
+iter under(n: uint) -> uint {
+ let i: uint = 0u;
+ while i < n { put i; i += 1u; }
+}
fn devnull() -> ioivec::writer { std::ioivec::string_writer().get_writer() }
-fn as_str(fn (ioivec::writer) f) -> str {
- auto w = std::ioivec::string_writer();
+fn as_str(f: fn(ioivec::writer) ) -> str {
+ let w = std::ioivec::string_writer();
f(w.get_writer());
ret w.get_str();
}
@@ -171,106 +192,98 @@
}
*/
-fn parse_and_print(&str code) -> str {
- auto filename = "";
- auto codemap = codemap::new_codemap();
- auto crate = parser::parse_crate_from_source_str(filename, code, ~[], codemap);
+fn parse_and_print(code: &str) -> str {
+ let filename = "";
+ let codemap = codemap::new_codemap();
+ let crate =
+ parser::parse_crate_from_source_str(filename, code, ~[], codemap);
ret as_str(bind pprust::print_crate(codemap, crate, filename,
- ioivec::string_reader(code),
- _, pprust::no_ann()));
+ ioivec::string_reader(code), _,
+ pprust::no_ann()));
}
-fn content_is_confusing(&str code) -> bool {
- auto confusing_patterns = [
- "#macro", // https://github.com/graydon/rust/issues/671
- "][]", // https://github.com/graydon/rust/issues/669
- "][mutable]", // https://github.com/graydon/rust/issues/669
- "][mutable ]", // https://github.com/graydon/rust/issues/669
- "self", // crazy rules enforced by parser rather than typechecker?
- "spawn", // more precedence issues
- "bind" // more precedence issues?
- ];
+fn content_is_confusing(code: &str) -> bool {
+ let // https://github.com/graydon/rust/issues/671
+ // https://github.com/graydon/rust/issues/669
+ // https://github.com/graydon/rust/issues/669
+ // https://github.com/graydon/rust/issues/669
+ // crazy rules enforced by parser rather than typechecker?
+ // more precedence issues
+ // more precedence issues?
+ confusing_patterns =
+ ["#macro", "][]", "][mutable]", "][mutable ]", "self", "spawn",
+ "bind"];
- for (str p in confusing_patterns) {
- if contains(code, p) {
- ret true;
- }
- }
+ for p: str in confusing_patterns { if contains(code, p) { ret true; } }
ret false;
}
-fn file_is_confusing(&str filename) -> bool {
- auto confusing_files = [
+fn file_is_confusing(filename: &str) -> bool {
+ let
- "block-expr-precedence.rs", // https://github.com/graydon/rust/issues/674
+ // https://github.com/graydon/rust/issues/674
- "nil-pattern.rs", // something to do with () as a lone pattern
+ // something to do with () as a lone pattern
- "syntax-extension-fmt.rs" // an issue where -2147483648 gains an
- // extra negative sign each time through,
- // which i can't reproduce using "rustc
- // --pretty normal"???
- ];
+ // an issue where -2147483648 gains an
+ // extra negative sign each time through,
+ // which i can't reproduce using "rustc
+ // --pretty normal"???
+ confusing_files =
+ ["block-expr-precedence.rs", "nil-pattern.rs",
+ "syntax-extension-fmt.rs"];
- for (str f in confusing_files) {
- if contains(filename, f) {
- ret true;
- }
- }
+ for f: str in confusing_files { if contains(filename, f) { ret true; } }
ret false;
}
-fn check_roundtrip_convergence(&str code) {
+fn check_roundtrip_convergence(code: &str) {
- auto i = 0;
- auto new = code;
- auto old = code;
+ let i = 0;
+ let new = code;
+ let old = code;
- while (i < 10) {
+ while i < 10 {
old = new;
new = parse_and_print(old);
- if content_is_confusing(new) {
- ret;
- }
+ if content_is_confusing(new) { ret; }
i += 1;
log #fmt("cycle %d", i);
}
+
if old != new {
write_file("round-trip-a.rs", old);
write_file("round-trip-b.rs", new);
- std::run::run_program("kdiff3", ["round-trip-a.rs", "round-trip-b.rs"]);
+ std::run::run_program("kdiff3",
+ ["round-trip-a.rs", "round-trip-b.rs"]);
fail "Mismatch";
}
}
-
-fn check_convergence(&str[] files) {
-
+fn check_convergence(files: &str[]) {
log_err #fmt("pp convergence tests: %u files", ivec::len(files));
- for (str file in files) {
+ for file: str in files {
log_err #fmt("pp converge: %s", file);
- if ! file_is_confusing(file) {
- auto s = read_whole_file(file);
- if ! content_is_confusing(s) {
- check_roundtrip_convergence(s);
- }
+ if !file_is_confusing(file) {
+ let s = read_whole_file(file);
+ if !content_is_confusing(s) { check_roundtrip_convergence(s); }
}
//pprust::print_crate(cm, crate, file, devnull(), pprust::no_ann());
// Currently hits https://github.com/graydon/rust/issues/675
//pp_variants(*crate, cm, file);
}
- }
+}
-fn main(vec[str] args) {
- if (vec::len(args) != 2u) {
+fn main(args: vec[str]) {
+ if vec::len(args) != 2u {
log_err #fmt("usage: %s <testdir>", args.(0));
ret;
}
- auto files = ~[];
- auto root = args.(1);
+ let files = ~[];
+ let root = args.(1);
find_rust_files(files, root);
check_convergence(files);
diff --git a/src/fuzzer/ivec_fuzz.rs b/src/fuzzer/ivec_fuzz.rs
index 4d52e73..3f959f6 100644
--- a/src/fuzzer/ivec_fuzz.rs
+++ b/src/fuzzer/ivec_fuzz.rs
@@ -28,71 +28,87 @@
//fn vec_reverse(&T[] v) -> T[] { ... }
-fn vec_omit [T] (&T[] v, uint i) -> T[] { slice(v, 0u, i) + slice(v, i+1u, len(v)) }
-fn vec_dup [T] (&T[] v, uint i) -> T[] { slice(v, 0u, i) + ~[v.(i)] + slice(v, i, len(v)) }
-fn vec_swadj [T] (&T[] v, uint i) -> T[] { slice(v, 0u, i) + ~[v.(i+1u), v.(i)] + slice(v, i+2u, len(v)) }
-fn vec_prefix [T] (&T[] v, uint i) -> T[] { slice(v, 0u, i) }
-fn vec_suffix [T] (&T[] v, uint i) -> T[] { slice(v, i, len(v)) }
+fn vec_omit[T](v: &T[], i: uint) -> T[] {
+ slice(v, 0u, i) + slice(v, i + 1u, len(v))
+}
+fn vec_dup[T](v: &T[], i: uint) -> T[] {
+ slice(v, 0u, i) + ~[v.(i)] + slice(v, i, len(v))
+}
+fn vec_swadj[T](v: &T[], i: uint) -> T[] {
+ slice(v, 0u, i) + ~[v.(i + 1u), v.(i)] + slice(v, i + 2u, len(v))
+}
+fn vec_prefix[T](v: &T[], i: uint) -> T[] { slice(v, 0u, i) }
+fn vec_suffix[T](v: &T[], i: uint) -> T[] { slice(v, i, len(v)) }
-fn vec_poke [T] (&T[] v, uint i, &T x) -> T[] { slice(v, 0u, i) + ~[x] + slice(v, i+1u, len(v)) }
-fn vec_insert [T] (&T[] v, uint i, &T x) -> T[] { slice(v, 0u, i) + ~[x] + slice(v, i, len(v)) }
+fn vec_poke[T](v: &T[], i: uint, x: &T) -> T[] {
+ slice(v, 0u, i) + ~[x] + slice(v, i + 1u, len(v))
+}
+fn vec_insert[T](v: &T[], i: uint, x: &T) -> T[] {
+ slice(v, 0u, i) + ~[x] + slice(v, i, len(v))
+}
// Iterates over 0...length, skipping the specified number on each side.
-iter ix(uint skip_low, uint skip_high, uint length) -> uint { let uint i = skip_low; while (i + skip_high <= length) { put i; i += 1u; } }
+iter ix(skip_low: uint, skip_high: uint, length: uint) -> uint {
+ let i: uint = skip_low;
+ while i + skip_high <= length { put i; i += 1u; }
+}
// Returns a bunch of modified versions of v, some of which introduce new elements (borrowed from xs).
-fn vec_edits[T](&T[] v, &T[] xs) -> T[][] {
- let T[][] edits = ~[];
- let uint Lv = len(v);
+fn vec_edits[T](v: &T[], xs: &T[]) -> T[][] {
+ let edits: T[][] = ~[];
+ let Lv: uint = len(v);
- if (Lv != 1u) { edits += ~[~[]]; } // When Lv == 1u, this is redundant with omit
- //if (Lv >= 3u) { edits += ~[vec_reverse(v)]; }
+ if Lv != 1u {
+ edits +=
+ ~[~[]]; // When Lv == 1u, this is redundant with omit
+ //if (Lv >= 3u) { edits += ~[vec_reverse(v)]; }
- for each (uint i in ix(0u, 1u, Lv)) { edits += ~[vec_omit (v, i)]; }
- for each (uint i in ix(0u, 1u, Lv)) { edits += ~[vec_dup (v, i)]; }
- for each (uint i in ix(0u, 2u, Lv)) { edits += ~[vec_swadj (v, i)]; }
- for each (uint i in ix(1u, 2u, Lv)) { edits += ~[vec_prefix(v, i)]; }
- for each (uint i in ix(2u, 1u, Lv)) { edits += ~[vec_suffix(v, i)]; }
-
- for each (uint j in ix(0u, 1u, len(xs))) {
- for each (uint i in ix(0u, 1u, Lv)) { edits += ~[vec_poke (v, i, xs.(j))]; }
- for each (uint i in ix(0u, 0u, Lv)) { edits += ~[vec_insert(v, i, xs.(j))]; }
}
+ for each i: uint in ix(0u, 1u, Lv) { edits += ~[vec_omit(v, i)]; }
+ for each i: uint in ix(0u, 1u, Lv) { edits += ~[vec_dup(v, i)]; }
+ for each i: uint in ix(0u, 2u, Lv) { edits += ~[vec_swadj(v, i)]; }
+ for each i: uint in ix(1u, 2u, Lv) { edits += ~[vec_prefix(v, i)]; }
+ for each i: uint in ix(2u, 1u, Lv) { edits += ~[vec_suffix(v, i)]; }
+
+ for each j: uint in ix(0u, 1u, len(xs)) {
+ for each i: uint in ix(0u, 1u, Lv) {
+ edits += ~[vec_poke(v, i, xs.(j))];
+ }
+ for each i: uint in ix(0u, 0u, Lv) {
+ edits += ~[vec_insert(v, i, xs.(j))];
+ }
+ }
+
+
edits
}
// Would be nice if this were built in: https://github.com/graydon/rust/issues/424
-fn vec_to_str(&int[] v) -> str {
- auto i = 0u;
- auto s = "[";
- while (i < len(v)) {
+fn vec_to_str(v: &int[]) -> str {
+ let i = 0u;
+ let s = "[";
+ while i < len(v) {
s += int::str(v.(i));
- if (i + 1u < len(v)) {
- s += ", "
- }
+ if i + 1u < len(v) { s += ", " }
i += 1u;
}
ret s + "]";
}
-fn show_edits(&int[] a, &int[] xs) {
+fn show_edits(a: &int[], xs: &int[]) {
log_err "=== Edits of " + vec_to_str(a) + " ===";
- auto b = vec_edits(a, xs);
- for each (uint i in ix(0u, 1u, len(b))) {
- log_err vec_to_str(b.(i));
- }
+ let b = vec_edits(a, xs);
+ for each i: uint in ix(0u, 1u, len(b)) { log_err vec_to_str(b.(i)); }
}
fn demo_edits() {
- auto xs = ~[7, 8];
+ let xs = ~[7, 8];
show_edits(~[], xs);
show_edits(~[1], xs);
- show_edits(~[1,2], xs);
- show_edits(~[1,2,3], xs);
- show_edits(~[1,2,3,4], xs);
+ show_edits(~[1, 2], xs);
+ show_edits(~[1, 2, 3], xs);
+ show_edits(~[1, 2, 3, 4], xs);
}
-fn main() {
- demo_edits();
-}
+fn main() { demo_edits(); }
\ No newline at end of file
diff --git a/src/lib/bitv.rs b/src/lib/bitv.rs
index 536d637..8201264 100644
--- a/src/lib/bitv.rs
+++ b/src/lib/bitv.rs
@@ -24,168 +24,168 @@
// an optimizing version of this module that produces a different obj
// for the case where nbits <= 32.
-type t = @rec(uint[mutable] storage, uint nbits);
+type t = @{storage: uint[mutable ], nbits: uint};
// FIXME: this should be a constant once they work
fn uint_bits() -> uint { ret 32u + (1u << 32u >> 27u); }
-fn create(uint nbits, bool init) -> t {
- auto elt = if (init) { !0u } else { 0u };
- auto storage = ivec::init_elt_mut[uint](elt, nbits / uint_bits() + 1u);
- ret @rec(storage=storage, nbits=nbits);
+fn create(nbits: uint, init: bool) -> t {
+ let elt = if init { !0u } else { 0u };
+ let storage = ivec::init_elt_mut[uint](elt, nbits / uint_bits() + 1u);
+ ret @{storage: storage, nbits: nbits};
}
-fn process(&fn(uint, uint) -> uint op, &t v0, &t v1) -> bool {
- auto len = ivec::len(v1.storage);
+fn process(op: &fn(uint, uint) -> uint , v0: &t, v1: &t) -> bool {
+ let len = ivec::len(v1.storage);
assert (ivec::len(v0.storage) == len);
assert (v0.nbits == v1.nbits);
- auto changed = false;
- for each (uint i in uint::range(0u, len)) {
- auto w0 = v0.storage.(i);
- auto w1 = v1.storage.(i);
- auto w = op(w0, w1);
- if (w0 != w) { changed = true; v0.storage.(i) = w; }
+ let changed = false;
+ for each i: uint in uint::range(0u, len) {
+ let w0 = v0.storage.(i);
+ let w1 = v1.storage.(i);
+ let w = op(w0, w1);
+ if w0 != w { changed = true; v0.storage.(i) = w; }
}
ret changed;
}
-fn lor(uint w0, uint w1) -> uint { ret w0 | w1; }
+fn lor(w0: uint, w1: uint) -> uint { ret w0 | w1; }
-fn union(&t v0, &t v1) -> bool { auto sub = lor; ret process(sub, v0, v1); }
+fn union(v0: &t, v1: &t) -> bool { let sub = lor; ret process(sub, v0, v1); }
-fn land(uint w0, uint w1) -> uint { ret w0 & w1; }
+fn land(w0: uint, w1: uint) -> uint { ret w0 & w1; }
-fn intersect(&t v0, &t v1) -> bool {
- auto sub = land;
+fn intersect(v0: &t, v1: &t) -> bool {
+ let sub = land;
ret process(sub, v0, v1);
}
-fn right(uint w0, uint w1) -> uint { ret w1; }
+fn right(w0: uint, w1: uint) -> uint { ret w1; }
-fn copy(&t v0, t v1) -> bool { auto sub = right; ret process(sub, v0, v1); }
+fn copy(v0: &t, v1: t) -> bool { let sub = right; ret process(sub, v0, v1); }
-fn clone(t v) -> t {
- auto storage = ivec::init_elt_mut[uint](0u, v.nbits / uint_bits() + 1u);
- auto len = ivec::len(v.storage);
- for each (uint i in uint::range(0u, len)) { storage.(i) = v.storage.(i); }
- ret @rec(storage=storage, nbits=v.nbits);
+fn clone(v: t) -> t {
+ let storage = ivec::init_elt_mut[uint](0u, v.nbits / uint_bits() + 1u);
+ let len = ivec::len(v.storage);
+ for each i: uint in uint::range(0u, len) { storage.(i) = v.storage.(i); }
+ ret @{storage: storage, nbits: v.nbits};
}
-fn get(&t v, uint i) -> bool {
+fn get(v: &t, i: uint) -> bool {
assert (i < v.nbits);
- auto bits = uint_bits();
- auto w = i / bits;
- auto b = i % bits;
- auto x = 1u & v.storage.(w) >> b;
+ let bits = uint_bits();
+ let w = i / bits;
+ let b = i % bits;
+ let x = 1u & v.storage.(w) >> b;
ret x == 1u;
}
-fn equal(&t v0, &t v1) -> bool {
+fn equal(v0: &t, v1: &t) -> bool {
// FIXME: when we can break or return from inside an iterator loop,
// we can eliminate this painful while-loop
- auto len = ivec::len(v1.storage);
- auto i = 0u;
- while (i < len) {
- if (v0.storage.(i) != v1.storage.(i)) { ret false; }
+ let len = ivec::len(v1.storage);
+ let i = 0u;
+ while i < len {
+ if v0.storage.(i) != v1.storage.(i) { ret false; }
i = i + 1u;
}
ret true;
}
-fn clear(&t v) {
- for each (uint i in uint::range(0u, ivec::len(v.storage))) {
+fn clear(v: &t) {
+ for each i: uint in uint::range(0u, ivec::len(v.storage)) {
v.storage.(i) = 0u;
}
}
-fn set_all(&t v) {
- for each (uint i in uint::range(0u, v.nbits)) { set(v, i, true); }
+fn set_all(v: &t) {
+ for each i: uint in uint::range(0u, v.nbits) { set(v, i, true); }
}
-fn invert(&t v) {
- for each (uint i in uint::range(0u, ivec::len(v.storage))) {
+fn invert(v: &t) {
+ for each i: uint in uint::range(0u, ivec::len(v.storage)) {
v.storage.(i) = !v.storage.(i);
}
}
/* v0 = v0 - v1 */
-fn difference(&t v0, &t v1) -> bool {
+fn difference(v0: &t, v1: &t) -> bool {
invert(v1);
- auto b = intersect(v0, v1);
+ let b = intersect(v0, v1);
invert(v1);
ret b;
}
-fn set(&t v, uint i, bool x) {
+fn set(v: &t, i: uint, x: bool) {
assert (i < v.nbits);
- auto bits = uint_bits();
- auto w = i / bits;
- auto b = i % bits;
- auto flag = 1u << b;
+ let bits = uint_bits();
+ let w = i / bits;
+ let b = i % bits;
+ let flag = 1u << b;
v.storage.(w) =
- if (x) { v.storage.(w) | flag } else { v.storage.(w) & !flag };
+ if x { v.storage.(w) | flag } else { v.storage.(w) & !flag };
}
/* true if all bits are 1 */
-fn is_true(&t v) -> bool {
- for (uint i in to_ivec(v)) { if (i != 1u) { ret false; } }
+fn is_true(v: &t) -> bool {
+ for i: uint in to_ivec(v) { if i != 1u { ret false; } }
ret true;
}
/* true if all bits are non-1 */
-fn is_false(&t v) -> bool {
- for (uint i in to_ivec(v)) { if (i == 1u) { ret false; } }
+fn is_false(v: &t) -> bool {
+ for i: uint in to_ivec(v) { if i == 1u { ret false; } }
ret true;
}
-fn init_to_vec(t v, uint i) -> uint { ret if (get(v, i)) { 1u } else { 0u }; }
+fn init_to_vec(v: t, i: uint) -> uint { ret if get(v, i) { 1u } else { 0u }; }
-fn to_vec(&t v) -> vec[uint] {
- auto sub = bind init_to_vec(v, _);
+fn to_vec(v: &t) -> vec[uint] {
+ let sub = bind init_to_vec(v, _);
ret vec::init_fn[uint](sub, v.nbits);
}
-fn to_ivec(&t v) -> uint[] {
- auto sub = bind init_to_vec(v, _);
+fn to_ivec(v: &t) -> uint[] {
+ let sub = bind init_to_vec(v, _);
ret ivec::init_fn[uint](sub, v.nbits);
}
-fn to_str(&t v) -> str {
- auto rs = "";
- for (uint i in bitv::to_vec(v)) {
- if (i == 1u) { rs += "1"; } else { rs += "0"; }
+fn to_str(v: &t) -> str {
+ let rs = "";
+ for i: uint in bitv::to_vec(v) {
+ if i == 1u { rs += "1"; } else { rs += "0"; }
}
ret rs;
}
// FIXME: can we just use structural equality on to_vec?
-fn eq_vec(&t v0, &vec[uint] v1) -> bool {
+fn eq_vec(v0: &t, v1: &vec[uint]) -> bool {
assert (v0.nbits == vec::len[uint](v1));
- auto len = v0.nbits;
- auto i = 0u;
- while (i < len) {
- auto w0 = get(v0, i);
- auto w1 = v1.(i);
- if (!w0 && w1 != 0u || w0 && w1 == 0u) { ret false; }
+ let len = v0.nbits;
+ let i = 0u;
+ while i < len {
+ let w0 = get(v0, i);
+ let w1 = v1.(i);
+ if !w0 && w1 != 0u || w0 && w1 == 0u { ret false; }
i = i + 1u;
}
ret true;
}
-fn eq_ivec(&t v0, &uint[] v1) -> bool {
+fn eq_ivec(v0: &t, v1: &uint[]) -> bool {
assert (v0.nbits == ivec::len[uint](v1));
- auto len = v0.nbits;
- auto i = 0u;
- while (i < len) {
- auto w0 = get(v0, i);
- auto w1 = v1.(i);
- if (!w0 && w1 != 0u || w0 && w1 == 0u) { ret false; }
+ let len = v0.nbits;
+ let i = 0u;
+ while i < len {
+ let w0 = get(v0, i);
+ let w1 = v1.(i);
+ if !w0 && w1 != 0u || w0 && w1 == 0u { ret false; }
i = i + 1u;
}
ret true;
diff --git a/src/lib/box.rs b/src/lib/box.rs
index fb99485..c0c1e74 100644
--- a/src/lib/box.rs
+++ b/src/lib/box.rs
@@ -1,8 +1,8 @@
export ptr_eq;
-fn ptr_eq[T](&@T a, &@T b) -> bool {
- let uint a_ptr = unsafe::reinterpret_cast(a);
- let uint b_ptr = unsafe::reinterpret_cast(b);
+fn ptr_eq[T](a: &@T, b: &@T) -> bool {
+ let a_ptr: uint = unsafe::reinterpret_cast(a);
+ let b_ptr: uint = unsafe::reinterpret_cast(b);
ret a_ptr == b_ptr;
-}
+}
\ No newline at end of file
diff --git a/src/lib/dbg.rs b/src/lib/dbg.rs
index 0296ce4..39e6460 100644
--- a/src/lib/dbg.rs
+++ b/src/lib/dbg.rs
@@ -9,28 +9,28 @@
*/
// FIXME: handle 64-bit case.
-const uint const_refcount = 0x7bad_face_u;
+const const_refcount: uint = 0x7bad_face_u;
native "rust" mod rustrt {
fn debug_tydesc[T]();
- fn debug_opaque[T](&T x);
- fn debug_box[T](@T x);
- fn debug_tag[T](&T x);
- fn debug_obj[T](&T x, uint nmethods, uint nbytes);
- fn debug_fn[T](&T x);
- fn debug_ptrcast[T, U](@T x) -> @U;
- fn debug_trap(str msg);
+ fn debug_opaque[T](x: &T);
+ fn debug_box[T](x: @T);
+ fn debug_tag[T](x: &T);
+ fn debug_obj[T](x: &T, nmethods: uint, nbytes: uint);
+ fn debug_fn[T](x: &T);
+ fn debug_ptrcast[T, U](x: @T) -> @U;
+ fn debug_trap(msg: str);
}
-fn debug_vec[T](vec[T] v) { vec::print_debug_info[T](v); }
+fn debug_vec[T](v: vec[T]) { vec::print_debug_info[T](v); }
fn debug_tydesc[T]() { rustrt::debug_tydesc[T](); }
-fn debug_opaque[T](&T x) { rustrt::debug_opaque[T](x); }
+fn debug_opaque[T](x: &T) { rustrt::debug_opaque[T](x); }
-fn debug_box[T](@T x) { rustrt::debug_box[T](x); }
+fn debug_box[T](x: @T) { rustrt::debug_box[T](x); }
-fn debug_tag[T](&T x) { rustrt::debug_tag[T](x); }
+fn debug_tag[T](x: &T) { rustrt::debug_tag[T](x); }
/**
@@ -42,15 +42,15 @@
* this to at least be 4u, since an implicit captured tydesc pointer sits in
* the front of any obj's data tuple.x
*/
-fn debug_obj[T](&T x, uint nmethods, uint nbytes) {
+fn debug_obj[T](x: &T, nmethods: uint, nbytes: uint) {
rustrt::debug_obj[T](x, nmethods, nbytes);
}
-fn debug_fn[T](&T x) { rustrt::debug_fn[T](x); }
+fn debug_fn[T](x: &T) { rustrt::debug_fn[T](x); }
-fn ptr_cast[T, U](@T x) -> @U { ret rustrt::debug_ptrcast[T, U](x); }
+fn ptr_cast[T, U](x: @T) -> @U { ret rustrt::debug_ptrcast[T, U](x); }
-fn trap(str s) { rustrt::debug_trap(s); }
+fn trap(s: str) { rustrt::debug_trap(s); }
// Local Variables:
// mode: rust;
// fill-column: 78;
diff --git a/src/lib/deque.rs b/src/lib/deque.rs
index 102c066..00ccde1f 100644
--- a/src/lib/deque.rs
+++ b/src/lib/deque.rs
@@ -19,47 +19,43 @@
fn create[T]() -> t[T] {
type cell[T] = option::t[T];
- let uint initial_capacity = 32u; // 2^5
+ let initial_capacity: uint = 32u; // 2^5
/**
* Grow is only called on full elts, so nelts is also len(elts), unlike
* elsewhere.
*/
- fn grow[T](uint nelts, uint lo, &(cell[T])[mutable] elts)
- -> (cell[T])[mutable] {
- assert (nelts == ivec::len(elts));
- auto rv = ~[mutable];
- auto i = 0u;
- auto nalloc = uint::next_power_of_two(nelts + 1u);
- while (i < nalloc) {
- if (i < nelts) {
+ fn grow[T](nelts: uint, lo: uint, elts: &(cell[T])[mutable ]) ->
+ (cell[T])[mutable ] {
+ assert (nelts == ivec::len(elts));
+ let rv = ~[mutable ];
+
+ let i = 0u;
+ let nalloc = uint::next_power_of_two(nelts + 1u);
+ while i < nalloc {
+ if i < nelts {
rv += ~[mutable elts.((lo + i) % nelts)];
- } else {
- rv += ~[mutable option::none];
- }
+ } else { rv += ~[mutable option::none]; }
i += 1u;
}
ret rv;
}
- fn get[T](&(cell[T])[mutable] elts, uint i) -> T {
- ret alt (elts.(i)) {
- case (option::some(?t)) { t }
- case (_) { fail }
- };
+ fn get[T](elts: &(cell[T])[mutable ], i: uint) -> T {
+ ret alt elts.(i) { option::some(t) { t } _ { fail } };
}
- obj deque[T](mutable uint nelts,
- mutable uint lo,
- mutable uint hi,
- mutable (cell[T])[mutable] elts) {
+ obj deque[T](mutable nelts: uint,
+ mutable lo: uint,
+ mutable hi: uint,
+ mutable elts: (cell[T])[mutable ]) {
fn size() -> uint { ret nelts; }
- fn add_front(&T t) {
- let uint oldlo = lo;
- if (lo == 0u) {
+ fn add_front(t: &T) {
+ let oldlo: uint = lo;
+ if lo == 0u {
lo = ivec::len[cell[T]](elts) - 1u;
} else { lo -= 1u; }
- if (lo == hi) {
+ if lo == hi {
elts = grow[T](nelts, oldlo, elts);
lo = ivec::len[cell[T]](elts) - 1u;
hi = nelts;
@@ -67,8 +63,8 @@
elts.(lo) = option::some[T](t);
nelts += 1u;
}
- fn add_back(&T t) {
- if (lo == hi && nelts != 0u) {
+ fn add_back(t: &T) {
+ if lo == hi && nelts != 0u {
elts = grow[T](nelts, lo, elts);
lo = 0u;
hi = nelts;
@@ -83,31 +79,29 @@
* that we don't keep anyone's refcount up unexpectedly.
*/
fn pop_front() -> T {
- let T t = get[T](elts, lo);
+ let t: T = get[T](elts, lo);
elts.(lo) = option::none[T];
lo = (lo + 1u) % ivec::len[cell[T]](elts);
nelts -= 1u;
ret t;
}
fn pop_back() -> T {
- if (hi == 0u) {
+ if hi == 0u {
hi = ivec::len[cell[T]](elts) - 1u;
- } else {
- hi -= 1u;
- }
- let T t = get[T](elts, hi);
+ } else { hi -= 1u; }
+ let t: T = get[T](elts, hi);
elts.(hi) = option::none[T];
nelts -= 1u;
ret t;
}
fn peek_front() -> T { ret get[T](elts, lo); }
fn peek_back() -> T { ret get[T](elts, hi - 1u); }
- fn get(int i) -> T {
- let uint idx = (lo + (i as uint)) % ivec::len[cell[T]](elts);
+ fn get(i: int) -> T {
+ let idx: uint = (lo + (i as uint)) % ivec::len[cell[T]](elts);
ret get[T](elts, idx);
}
}
- let (cell[T])[mutable] v =
+ let v: (cell[T])[mutable ] =
ivec::init_elt_mut(option::none, initial_capacity);
ret deque[T](0u, 0u, 0u, v);
}
diff --git a/src/lib/ebml.rs b/src/lib/ebml.rs
index c61d2a2..3b921a8 100644
--- a/src/lib/ebml.rs
+++ b/src/lib/ebml.rs
@@ -6,104 +6,104 @@
import option::none;
import option::some;
-type ebml_tag = rec(uint id, uint size);
+type ebml_tag = {id: uint, size: uint};
-type ebml_state = rec(ebml_tag ebml_tag, uint tag_pos, uint data_pos);
+type ebml_state = {ebml_tag: ebml_tag, tag_pos: uint, data_pos: uint};
// TODO: When we have module renaming, make "reader" and "writer" separate
// modules within this file.
// ebml reading
-type doc = rec(vec[u8] data, uint start, uint end);
+type doc = {data: vec[u8], start: uint, end: uint};
-fn vint_at(vec[u8] data, uint start) -> rec(uint val, uint next) {
- auto a = data.(start);
- if (a & 0x80u8 != 0u8) {
- ret rec(val=a & 0x7fu8 as uint, next=start + 1u);
- }
- if (a & 0x40u8 != 0u8) {
- ret rec(val=(a & 0x3fu8 as uint) << 8u | (data.(start + 1u) as uint),
- next=start + 2u);
+fn vint_at(data: vec[u8], start: uint) -> {val: uint, next: uint} {
+ let a = data.(start);
+ if a & 0x80u8 != 0u8 { ret {val: a & 0x7fu8 as uint, next: start + 1u}; }
+ if a & 0x40u8 != 0u8 {
+ ret {val: (a & 0x3fu8 as uint) << 8u | (data.(start + 1u) as uint),
+ next: start + 2u};
} else if (a & 0x20u8 != 0u8) {
- ret rec(val=(a & 0x1fu8 as uint) << 16u |
- (data.(start + 1u) as uint) << 8u |
- (data.(start + 2u) as uint),
- next=start + 3u);
+ ret {val:
+ (a & 0x1fu8 as uint) << 16u |
+ (data.(start + 1u) as uint) << 8u |
+ (data.(start + 2u) as uint),
+ next: start + 3u};
} else if (a & 0x10u8 != 0u8) {
- ret rec(val=(a & 0x0fu8 as uint) << 24u |
- (data.(start + 1u) as uint) << 16u |
- (data.(start + 2u) as uint) << 8u |
- (data.(start + 3u) as uint),
- next=start + 4u);
+ ret {val:
+ (a & 0x0fu8 as uint) << 24u |
+ (data.(start + 1u) as uint) << 16u |
+ (data.(start + 2u) as uint) << 8u |
+ (data.(start + 3u) as uint),
+ next: start + 4u};
} else { log_err "vint too big"; fail; }
}
-fn new_doc(vec[u8] data) -> doc {
- ret rec(data=data, start=0u, end=vec::len[u8](data));
+fn new_doc(data: vec[u8]) -> doc {
+ ret {data: data, start: 0u, end: vec::len[u8](data)};
}
-fn doc_at(vec[u8] data, uint start) -> doc {
- auto elt_tag = vint_at(data, start);
- auto elt_size = vint_at(data, elt_tag.next);
- auto end = elt_size.next + elt_size.val;
- ret rec(data=data, start=elt_size.next, end=end);
+fn doc_at(data: vec[u8], start: uint) -> doc {
+ let elt_tag = vint_at(data, start);
+ let elt_size = vint_at(data, elt_tag.next);
+ let end = elt_size.next + elt_size.val;
+ ret {data: data, start: elt_size.next, end: end};
}
-fn maybe_get_doc(doc d, uint tg) -> option::t[doc] {
- auto pos = d.start;
- while (pos < d.end) {
- auto elt_tag = vint_at(d.data, pos);
- auto elt_size = vint_at(d.data, elt_tag.next);
+fn maybe_get_doc(d: doc, tg: uint) -> option::t[doc] {
+ let pos = d.start;
+ while pos < d.end {
+ let elt_tag = vint_at(d.data, pos);
+ let elt_size = vint_at(d.data, elt_tag.next);
pos = elt_size.next + elt_size.val;
- if (elt_tag.val == tg) {
- ret some[doc](rec(data=d.data, start=elt_size.next, end=pos));
+ if elt_tag.val == tg {
+ ret some[doc]({data: d.data, start: elt_size.next, end: pos});
}
}
ret none[doc];
}
-fn get_doc(doc d, uint tg) -> doc {
- alt (maybe_get_doc(d, tg)) {
- case (some(?d)) { ret d; }
- case (none) {
- log_err "failed to find block with tag " + uint::to_str(tg, 10u);
- fail;
+fn get_doc(d: doc, tg: uint) -> doc {
+ alt maybe_get_doc(d, tg) {
+ some(d) { ret d; }
+ none. {
+ log_err "failed to find block with tag " + uint::to_str(tg, 10u);
+ fail;
+ }
+ }
+}
+
+iter docs(d: doc) -> {tag: uint, doc: doc} {
+ let pos = d.start;
+ while pos < d.end {
+ let elt_tag = vint_at(d.data, pos);
+ let elt_size = vint_at(d.data, elt_tag.next);
+ pos = elt_size.next + elt_size.val;
+ put {tag: elt_tag.val,
+ doc: {data: d.data, start: elt_size.next, end: pos}};
+ }
+}
+
+iter tagged_docs(d: doc, tg: uint) -> doc {
+ let pos = d.start;
+ while pos < d.end {
+ let elt_tag = vint_at(d.data, pos);
+ let elt_size = vint_at(d.data, elt_tag.next);
+ pos = elt_size.next + elt_size.val;
+ if elt_tag.val == tg {
+ put {data: d.data, start: elt_size.next, end: pos};
}
}
}
-iter docs(doc d) -> rec(uint tag, doc doc) {
- auto pos = d.start;
- while (pos < d.end) {
- auto elt_tag = vint_at(d.data, pos);
- auto elt_size = vint_at(d.data, elt_tag.next);
- pos = elt_size.next + elt_size.val;
- put rec(tag=elt_tag.val,
- doc=rec(data=d.data, start=elt_size.next, end=pos));
- }
-}
+fn doc_data(d: doc) -> vec[u8] { ret vec::slice[u8](d.data, d.start, d.end); }
-iter tagged_docs(doc d, uint tg) -> doc {
- auto pos = d.start;
- while (pos < d.end) {
- auto elt_tag = vint_at(d.data, pos);
- auto elt_size = vint_at(d.data, elt_tag.next);
- pos = elt_size.next + elt_size.val;
- if (elt_tag.val == tg) {
- put rec(data=d.data, start=elt_size.next, end=pos);
- }
- }
-}
-
-fn doc_data(doc d) -> vec[u8] { ret vec::slice[u8](d.data, d.start, d.end); }
-
-fn be_uint_from_bytes(vec[u8] data, uint start, uint size) -> uint {
- auto sz = size;
+fn be_uint_from_bytes(data: vec[u8], start: uint, size: uint) -> uint {
+ let sz = size;
assert (sz <= 4u);
- auto val = 0u;
- auto pos = start;
- while (sz > 0u) {
+ let val = 0u;
+ let pos = start;
+ while sz > 0u {
sz -= 1u;
val += (data.(pos) as uint) << sz * 8u;
pos += 1u;
@@ -111,64 +111,64 @@
ret val;
}
-fn doc_as_uint(doc d) -> uint {
+fn doc_as_uint(d: doc) -> uint {
ret be_uint_from_bytes(d.data, d.start, d.end - d.start);
}
// ebml writing
-type writer = rec(io::buf_writer writer, mutable vec[uint] size_positions);
+type writer = {writer: io::buf_writer, mutable size_positions: vec[uint]};
-fn write_sized_vint(&io::buf_writer w, uint n, uint size) {
- let vec[u8] buf;
- alt (size) {
- case (1u) { buf = [0x80u8 | (n as u8)]; }
- case (2u) { buf = [0x40u8 | (n >> 8u as u8), n & 0xffu as u8]; }
- case (3u) {
- buf =
- [0x20u8 | (n >> 16u as u8), n >> 8u & 0xffu as u8,
- n & 0xffu as u8];
- }
- case (4u) {
- buf =
- [0x10u8 | (n >> 24u as u8), n >> 16u & 0xffu as u8,
- n >> 8u & 0xffu as u8, n & 0xffu as u8];
- }
- case (_) { log_err "vint to write too big"; fail; }
+fn write_sized_vint(w: &io::buf_writer, n: uint, size: uint) {
+ let buf: vec[u8];
+ alt size {
+ 1u { buf = [0x80u8 | (n as u8)]; }
+ 2u { buf = [0x40u8 | (n >> 8u as u8), n & 0xffu as u8]; }
+ 3u {
+ buf =
+ [0x20u8 | (n >> 16u as u8), n >> 8u & 0xffu as u8,
+ n & 0xffu as u8];
+ }
+ 4u {
+ buf =
+ [0x10u8 | (n >> 24u as u8), n >> 16u & 0xffu as u8,
+ n >> 8u & 0xffu as u8, n & 0xffu as u8];
+ }
+ _ { log_err "vint to write too big"; fail; }
}
w.write(buf);
}
-fn write_vint(&io::buf_writer w, uint n) {
- if (n < 0x7fu) { write_sized_vint(w, n, 1u); ret; }
- if (n < 0x4000u) { write_sized_vint(w, n, 2u); ret; }
- if (n < 0x200000u) { write_sized_vint(w, n, 3u); ret; }
- if (n < 0x10000000u) { write_sized_vint(w, n, 4u); ret; }
+fn write_vint(w: &io::buf_writer, n: uint) {
+ if n < 0x7fu { write_sized_vint(w, n, 1u); ret; }
+ if n < 0x4000u { write_sized_vint(w, n, 2u); ret; }
+ if n < 0x200000u { write_sized_vint(w, n, 3u); ret; }
+ if n < 0x10000000u { write_sized_vint(w, n, 4u); ret; }
log_err "vint to write too big";
fail;
}
-fn create_writer(&io::buf_writer w) -> writer {
- let vec[uint] size_positions = [];
- ret rec(writer=w, mutable size_positions=size_positions);
+fn create_writer(w: &io::buf_writer) -> writer {
+ let size_positions: vec[uint] = [];
+ ret {writer: w, mutable size_positions: size_positions};
}
// TODO: Provide a function to write the standard ebml header.
-fn start_tag(&writer w, uint tag_id) {
+fn start_tag(w: &writer, tag_id: uint) {
// Write the tag ID:
write_vint(w.writer, tag_id);
// Write a placeholder four-byte size.
w.size_positions += [w.writer.tell()];
- let vec[u8] zeroes = [0u8, 0u8, 0u8, 0u8];
+ let zeroes: vec[u8] = [0u8, 0u8, 0u8, 0u8];
w.writer.write(zeroes);
}
-fn end_tag(&writer w) {
- auto last_size_pos = vec::pop[uint](w.size_positions);
- auto cur_pos = w.writer.tell();
+fn end_tag(w: &writer) {
+ let last_size_pos = vec::pop[uint](w.size_positions);
+ let cur_pos = w.writer.tell();
w.writer.seek(last_size_pos as int, io::seek_set);
write_sized_vint(w.writer, cur_pos - last_size_pos - 4u, 4u);
w.writer.seek(cur_pos as int, io::seek_set);
diff --git a/src/lib/ebmlivec.rs b/src/lib/ebmlivec.rs
index 92b33bd..41e5bf0 100644
--- a/src/lib/ebmlivec.rs
+++ b/src/lib/ebmlivec.rs
@@ -6,104 +6,104 @@
import option::none;
import option::some;
-type ebml_tag = rec(uint id, uint size);
+type ebml_tag = {id: uint, size: uint};
-type ebml_state = rec(ebml_tag ebml_tag, uint tag_pos, uint data_pos);
+type ebml_state = {ebml_tag: ebml_tag, tag_pos: uint, data_pos: uint};
// TODO: When we have module renaming, make "reader" and "writer" separate
// modules within this file.
// ebml reading
-type doc = rec(@u8[] data, uint start, uint end);
+type doc = {data: @u8[], start: uint, end: uint};
-fn vint_at(&u8[] data, uint start) -> rec(uint val, uint next) {
- auto a = data.(start);
- if (a & 0x80u8 != 0u8) {
- ret rec(val=a & 0x7fu8 as uint, next=start + 1u);
- }
- if (a & 0x40u8 != 0u8) {
- ret rec(val=(a & 0x3fu8 as uint) << 8u | (data.(start + 1u) as uint),
- next=start + 2u);
+fn vint_at(data: &u8[], start: uint) -> {val: uint, next: uint} {
+ let a = data.(start);
+ if a & 0x80u8 != 0u8 { ret {val: a & 0x7fu8 as uint, next: start + 1u}; }
+ if a & 0x40u8 != 0u8 {
+ ret {val: (a & 0x3fu8 as uint) << 8u | (data.(start + 1u) as uint),
+ next: start + 2u};
} else if (a & 0x20u8 != 0u8) {
- ret rec(val=(a & 0x1fu8 as uint) << 16u |
- (data.(start + 1u) as uint) << 8u |
- (data.(start + 2u) as uint),
- next=start + 3u);
+ ret {val:
+ (a & 0x1fu8 as uint) << 16u |
+ (data.(start + 1u) as uint) << 8u |
+ (data.(start + 2u) as uint),
+ next: start + 3u};
} else if (a & 0x10u8 != 0u8) {
- ret rec(val=(a & 0x0fu8 as uint) << 24u |
- (data.(start + 1u) as uint) << 16u |
- (data.(start + 2u) as uint) << 8u |
- (data.(start + 3u) as uint),
- next=start + 4u);
+ ret {val:
+ (a & 0x0fu8 as uint) << 24u |
+ (data.(start + 1u) as uint) << 16u |
+ (data.(start + 2u) as uint) << 8u |
+ (data.(start + 3u) as uint),
+ next: start + 4u};
} else { log_err "vint too big"; fail; }
}
-fn new_doc(&@u8[] data) -> doc {
- ret rec(data=data, start=0u, end=ivec::len[u8](*data));
+fn new_doc(data: &@u8[]) -> doc {
+ ret {data: data, start: 0u, end: ivec::len[u8](*data)};
}
-fn doc_at(&@u8[] data, uint start) -> doc {
- auto elt_tag = vint_at(*data, start);
- auto elt_size = vint_at(*data, elt_tag.next);
- auto end = elt_size.next + elt_size.val;
- ret rec(data=data, start=elt_size.next, end=end);
+fn doc_at(data: &@u8[], start: uint) -> doc {
+ let elt_tag = vint_at(*data, start);
+ let elt_size = vint_at(*data, elt_tag.next);
+ let end = elt_size.next + elt_size.val;
+ ret {data: data, start: elt_size.next, end: end};
}
-fn maybe_get_doc(doc d, uint tg) -> option::t[doc] {
- auto pos = d.start;
- while (pos < d.end) {
- auto elt_tag = vint_at(*d.data, pos);
- auto elt_size = vint_at(*d.data, elt_tag.next);
+fn maybe_get_doc(d: doc, tg: uint) -> option::t[doc] {
+ let pos = d.start;
+ while pos < d.end {
+ let elt_tag = vint_at(*d.data, pos);
+ let elt_size = vint_at(*d.data, elt_tag.next);
pos = elt_size.next + elt_size.val;
- if (elt_tag.val == tg) {
- ret some[doc](rec(data=d.data, start=elt_size.next, end=pos));
+ if elt_tag.val == tg {
+ ret some[doc]({data: d.data, start: elt_size.next, end: pos});
}
}
ret none[doc];
}
-fn get_doc(doc d, uint tg) -> doc {
- alt (maybe_get_doc(d, tg)) {
- case (some(?d)) { ret d; }
- case (none) {
- log_err "failed to find block with tag " + uint::to_str(tg, 10u);
- fail;
+fn get_doc(d: doc, tg: uint) -> doc {
+ alt maybe_get_doc(d, tg) {
+ some(d) { ret d; }
+ none. {
+ log_err "failed to find block with tag " + uint::to_str(tg, 10u);
+ fail;
+ }
+ }
+}
+
+iter docs(d: doc) -> {tag: uint, doc: doc} {
+ let pos = d.start;
+ while pos < d.end {
+ let elt_tag = vint_at(*d.data, pos);
+ let elt_size = vint_at(*d.data, elt_tag.next);
+ pos = elt_size.next + elt_size.val;
+ put {tag: elt_tag.val,
+ doc: {data: d.data, start: elt_size.next, end: pos}};
+ }
+}
+
+iter tagged_docs(d: doc, tg: uint) -> doc {
+ let pos = d.start;
+ while pos < d.end {
+ let elt_tag = vint_at(*d.data, pos);
+ let elt_size = vint_at(*d.data, elt_tag.next);
+ pos = elt_size.next + elt_size.val;
+ if elt_tag.val == tg {
+ put {data: d.data, start: elt_size.next, end: pos};
}
}
}
-iter docs(doc d) -> rec(uint tag, doc doc) {
- auto pos = d.start;
- while (pos < d.end) {
- auto elt_tag = vint_at(*d.data, pos);
- auto elt_size = vint_at(*d.data, elt_tag.next);
- pos = elt_size.next + elt_size.val;
- put rec(tag=elt_tag.val,
- doc=rec(data=d.data, start=elt_size.next, end=pos));
- }
-}
+fn doc_data(d: doc) -> u8[] { ret ivec::slice[u8](*d.data, d.start, d.end); }
-iter tagged_docs(doc d, uint tg) -> doc {
- auto pos = d.start;
- while (pos < d.end) {
- auto elt_tag = vint_at(*d.data, pos);
- auto elt_size = vint_at(*d.data, elt_tag.next);
- pos = elt_size.next + elt_size.val;
- if (elt_tag.val == tg) {
- put rec(data=d.data, start=elt_size.next, end=pos);
- }
- }
-}
-
-fn doc_data(doc d) -> u8[] { ret ivec::slice[u8](*d.data, d.start, d.end); }
-
-fn be_uint_from_bytes(&@u8[] data, uint start, uint size) -> uint {
- auto sz = size;
+fn be_uint_from_bytes(data: &@u8[], start: uint, size: uint) -> uint {
+ let sz = size;
assert (sz <= 4u);
- auto val = 0u;
- auto pos = start;
- while (sz > 0u) {
+ let val = 0u;
+ let pos = start;
+ while sz > 0u {
sz -= 1u;
val += (data.(pos) as uint) << sz * 8u;
pos += 1u;
@@ -111,64 +111,64 @@
ret val;
}
-fn doc_as_uint(doc d) -> uint {
+fn doc_as_uint(d: doc) -> uint {
ret be_uint_from_bytes(d.data, d.start, d.end - d.start);
}
// ebml writing
-type writer = rec(ioivec::buf_writer writer, mutable uint[] size_positions);
+type writer = {writer: ioivec::buf_writer, mutable size_positions: uint[]};
-fn write_sized_vint(&ioivec::buf_writer w, uint n, uint size) {
- let u8[] buf;
- alt (size) {
- case (1u) { buf = ~[0x80u8 | (n as u8)]; }
- case (2u) { buf = ~[0x40u8 | (n >> 8u as u8), n & 0xffu as u8]; }
- case (3u) {
- buf =
- ~[0x20u8 | (n >> 16u as u8), n >> 8u & 0xffu as u8,
- n & 0xffu as u8];
- }
- case (4u) {
- buf =
- ~[0x10u8 | (n >> 24u as u8), n >> 16u & 0xffu as u8,
- n >> 8u & 0xffu as u8, n & 0xffu as u8];
- }
- case (_) { log_err "vint to write too big"; fail; }
+fn write_sized_vint(w: &ioivec::buf_writer, n: uint, size: uint) {
+ let buf: u8[];
+ alt size {
+ 1u { buf = ~[0x80u8 | (n as u8)]; }
+ 2u { buf = ~[0x40u8 | (n >> 8u as u8), n & 0xffu as u8]; }
+ 3u {
+ buf =
+ ~[0x20u8 | (n >> 16u as u8), n >> 8u & 0xffu as u8,
+ n & 0xffu as u8];
+ }
+ 4u {
+ buf =
+ ~[0x10u8 | (n >> 24u as u8), n >> 16u & 0xffu as u8,
+ n >> 8u & 0xffu as u8, n & 0xffu as u8];
+ }
+ _ { log_err "vint to write too big"; fail; }
}
w.write(buf);
}
-fn write_vint(&ioivec::buf_writer w, uint n) {
- if (n < 0x7fu) { write_sized_vint(w, n, 1u); ret; }
- if (n < 0x4000u) { write_sized_vint(w, n, 2u); ret; }
- if (n < 0x200000u) { write_sized_vint(w, n, 3u); ret; }
- if (n < 0x10000000u) { write_sized_vint(w, n, 4u); ret; }
+fn write_vint(w: &ioivec::buf_writer, n: uint) {
+ if n < 0x7fu { write_sized_vint(w, n, 1u); ret; }
+ if n < 0x4000u { write_sized_vint(w, n, 2u); ret; }
+ if n < 0x200000u { write_sized_vint(w, n, 3u); ret; }
+ if n < 0x10000000u { write_sized_vint(w, n, 4u); ret; }
log_err "vint to write too big";
fail;
}
-fn create_writer(&ioivec::buf_writer w) -> writer {
- let uint[] size_positions = ~[];
- ret rec(writer=w, mutable size_positions=size_positions);
+fn create_writer(w: &ioivec::buf_writer) -> writer {
+ let size_positions: uint[] = ~[];
+ ret {writer: w, mutable size_positions: size_positions};
}
// TODO: Provide a function to write the standard ebml header.
-fn start_tag(&writer w, uint tag_id) {
+fn start_tag(w: &writer, tag_id: uint) {
// Write the tag ID:
write_vint(w.writer, tag_id);
// Write a placeholder four-byte size.
w.size_positions += ~[w.writer.tell()];
- let u8[] zeroes = ~[0u8, 0u8, 0u8, 0u8];
+ let zeroes: u8[] = ~[0u8, 0u8, 0u8, 0u8];
w.writer.write(zeroes);
}
-fn end_tag(&writer w) {
- auto last_size_pos = ivec::pop[uint](w.size_positions);
- auto cur_pos = w.writer.tell();
+fn end_tag(w: &writer) {
+ let last_size_pos = ivec::pop[uint](w.size_positions);
+ let cur_pos = w.writer.tell();
w.writer.seek(last_size_pos as int, ioivec::seek_set);
write_sized_vint(w.writer, cur_pos - last_size_pos - 4u, 4u);
w.writer.seek(cur_pos as int, ioivec::seek_set);
diff --git a/src/lib/either.rs b/src/lib/either.rs
index c62a8e7..a410acd 100644
--- a/src/lib/either.rs
+++ b/src/lib/either.rs
@@ -8,47 +8,34 @@
type operator[T, U] = fn(&T) -> U ;
fn either[T, U,
- V](&operator[T, V] f_left, &operator[U, V] f_right, &t[T, U] value)
- -> V {
- alt (value) {
- case (left(?l)) { f_left(l) }
- case (right(?r)) { f_right(r) }
- }
+ V](f_left: &operator[T, V], f_right: &operator[U, V],
+ value: &t[T, U]) -> V {
+ alt value { left(l) { f_left(l) } right(r) { f_right(r) } }
}
-fn lefts[T, U](&(t[T, U])[] eithers) -> T[] {
- let T[] result = ~[];
- for (t[T, U] elt in eithers) {
- alt (elt) {
- case (left(?l)) { result += ~[l] }
- case (_) {/* fallthrough */ }
- }
+fn lefts[T, U](eithers: &(t[T, U])[]) -> T[] {
+ let result: T[] = ~[];
+ for elt: t[T, U] in eithers {
+ alt elt { left(l) { result += ~[l] } _ {/* fallthrough */ } }
}
ret result;
}
-fn rights[T, U](&(t[T, U])[] eithers) -> U[] {
- let U[] result = ~[];
- for (t[T, U] elt in eithers) {
- alt (elt) {
- case (right(?r)) { result += ~[r] }
- case (_) {/* fallthrough */ }
- }
+fn rights[T, U](eithers: &(t[T, U])[]) -> U[] {
+ let result: U[] = ~[];
+ for elt: t[T, U] in eithers {
+ alt elt { right(r) { result += ~[r] } _ {/* fallthrough */ } }
}
ret result;
}
-fn partition[T, U](&(t[T, U])[] eithers)
- -> rec(T[] lefts, U[] rights) {
- let T[] lefts = ~[];
- let U[] rights = ~[];
- for (t[T, U] elt in eithers) {
- alt (elt) {
- case (left(?l)) { lefts += ~[l] }
- case (right(?r)) { rights += ~[r] }
- }
+fn partition[T, U](eithers: &(t[T, U])[]) -> {lefts: T[], rights: U[]} {
+ let lefts: T[] = ~[];
+ let rights: U[] = ~[];
+ for elt: t[T, U] in eithers {
+ alt elt { left(l) { lefts += ~[l] } right(r) { rights += ~[r] } }
}
- ret rec(lefts=lefts, rights=rights);
+ ret {lefts: lefts, rights: rights};
}
//
// Local Variables:
diff --git a/src/lib/extfmt.rs b/src/lib/extfmt.rs
index ca1d826..00302ea 100644
--- a/src/lib/extfmt.rs
+++ b/src/lib/extfmt.rs
@@ -60,42 +60,42 @@
// A formatted conversion from an expression to a string
type conv =
- rec(option::t[int] param,
- vec[flag] flags,
- count width,
- count precision,
- ty ty);
+ {param: option::t[int],
+ flags: vec[flag],
+ width: count,
+ precision: count,
+ ty: ty};
// A fragment of the output sequence
tag piece { piece_string(str); piece_conv(conv); }
type error_fn = fn(str) -> ! ;
- fn parse_fmt_string(str s, error_fn error) -> vec[piece] {
- let vec[piece] pieces = [];
- auto lim = str::byte_len(s);
- auto buf = "";
- fn flush_buf(str buf, &mutable vec[piece] pieces) -> str {
- if (str::byte_len(buf) > 0u) {
- auto piece = piece_string(buf);
+ fn parse_fmt_string(s: str, error: error_fn) -> vec[piece] {
+ let pieces: vec[piece] = [];
+ let lim = str::byte_len(s);
+ let buf = "";
+ fn flush_buf(buf: str, pieces: &mutable vec[piece]) -> str {
+ if str::byte_len(buf) > 0u {
+ let piece = piece_string(buf);
pieces += [piece];
}
ret "";
}
- auto i = 0u;
- while (i < lim) {
- auto curr = str::substr(s, i, 1u);
- if (str::eq(curr, "%")) {
+ let i = 0u;
+ while i < lim {
+ let curr = str::substr(s, i, 1u);
+ if str::eq(curr, "%") {
i += 1u;
- if (i >= lim) {
+ if i >= lim {
error("unterminated conversion at end of string");
}
- auto curr2 = str::substr(s, i, 1u);
- if (str::eq(curr2, "%")) {
+ let curr2 = str::substr(s, i, 1u);
+ if str::eq(curr2, "%") {
i += 1u;
} else {
buf = flush_buf(buf, pieces);
- auto rs = parse_conversion(s, i, lim, error);
+ let rs = parse_conversion(s, i, lim, error);
pieces += [rs.piece];
i = rs.next;
}
@@ -104,67 +104,66 @@
buf = flush_buf(buf, pieces);
ret pieces;
}
- fn peek_num(str s, uint i, uint lim)
- -> option::t[rec(uint num, uint next)] {
- if (i >= lim) { ret none; }
- auto c = s.(i);
- if (!('0' as u8 <= c && c <= '9' as u8)) {
- ret option::none;
- }
- auto n = c - ('0' as u8) as uint;
- ret alt (peek_num(s, i + 1u, lim)) {
- case (none) { some(rec(num=n, next=i + 1u)) }
- case (some(?next)) {
- auto m = next.num;
- auto j = next.next;
- some(rec(num=n * 10u + m, next=j))
- }
+ fn peek_num(s: str, i: uint, lim: uint) ->
+ option::t[{num: uint, next: uint}] {
+ if i >= lim { ret none; }
+ let c = s.(i);
+ if !('0' as u8 <= c && c <= '9' as u8) { ret option::none; }
+ let n = c - ('0' as u8) as uint;
+ ret alt peek_num(s, i + 1u, lim) {
+ none. { some({num: n, next: i + 1u}) }
+ some(next) {
+ let m = next.num;
+ let j = next.next;
+ some({num: n * 10u + m, next: j})
+ }
};
}
- fn parse_conversion(str s, uint i, uint lim, error_fn error)
- -> rec(piece piece, uint next) {
- auto parm = parse_parameter(s, i, lim);
- auto flags = parse_flags(s, parm.next, lim);
- auto width = parse_count(s, flags.next, lim);
- auto prec = parse_precision(s, width.next, lim);
- auto ty = parse_type(s, prec.next, lim, error);
- ret rec(piece=piece_conv(rec(param=parm.param,
- flags=flags.flags,
- width=width.count,
- precision=prec.count,
- ty=ty.ty)),
- next=ty.next);
+ fn parse_conversion(s: str, i: uint, lim: uint, error: error_fn) ->
+ {piece: piece, next: uint} {
+ let parm = parse_parameter(s, i, lim);
+ let flags = parse_flags(s, parm.next, lim);
+ let width = parse_count(s, flags.next, lim);
+ let prec = parse_precision(s, width.next, lim);
+ let ty = parse_type(s, prec.next, lim, error);
+ ret {piece:
+ piece_conv({param: parm.param,
+ flags: flags.flags,
+ width: width.count,
+ precision: prec.count,
+ ty: ty.ty}),
+ next: ty.next};
}
- fn parse_parameter(str s, uint i, uint lim)
- -> rec(option::t[int] param, uint next) {
- if (i >= lim) { ret rec(param=none, next=i); }
- auto num = peek_num(s, i, lim);
- ret alt (num) {
- case (none) { rec(param=none, next=i) }
- case (some(?t)) {
- auto n = t.num;
- auto j = t.next;
- if (j < lim && s.(j) == '$' as u8) {
- rec(param=some(n as int), next=j + 1u)
- } else { rec(param=none, next=i) }
- }
+ fn parse_parameter(s: str, i: uint, lim: uint) ->
+ {param: option::t[int], next: uint} {
+ if i >= lim { ret {param: none, next: i}; }
+ let num = peek_num(s, i, lim);
+ ret alt num {
+ none. { {param: none, next: i} }
+ some(t) {
+ let n = t.num;
+ let j = t.next;
+ if j < lim && s.(j) == '$' as u8 {
+ {param: some(n as int), next: j + 1u}
+ } else { {param: none, next: i} }
+ }
};
}
- fn parse_flags(str s, uint i, uint lim)
- -> rec(vec[flag] flags, uint next) {
- let vec[flag] noflags = [];
- if (i >= lim) { ret rec(flags=noflags, next=i); }
- fn more_(flag f, str s, uint i, uint lim)
- -> rec(vec[flag] flags, uint next) {
- auto next = parse_flags(s, i + 1u, lim);
- auto rest = next.flags;
- auto j = next.next;
- let vec[flag] curr = [f];
- ret rec(flags=curr + rest, next=j);
+ fn parse_flags(s: str, i: uint, lim: uint) ->
+ {flags: vec[flag], next: uint} {
+ let noflags: vec[flag] = [];
+ if i >= lim { ret {flags: noflags, next: i}; }
+ fn more_(f: flag, s: str, i: uint, lim: uint) ->
+ {flags: vec[flag], next: uint} {
+ let next = parse_flags(s, i + 1u, lim);
+ let rest = next.flags;
+ let j = next.next;
+ let curr: vec[flag] = [f];
+ ret {flags: curr + rest, next: j};
}
- auto more = bind more_(_, s, i, lim);
- auto f = s.(i);
- ret if (f == '-' as u8) {
+ let more = bind more_(_, s, i, lim);
+ let f = s.(i);
+ ret if f == '-' as u8 {
more(flag_left_justify)
} else if (f == '0' as u8) {
more(flag_left_zero_pad)
@@ -174,59 +173,60 @@
more(flag_sign_always)
} else if (f == '#' as u8) {
more(flag_alternate)
- } else { rec(flags=noflags, next=i) };
+ } else { {flags: noflags, next: i} };
}
- fn parse_count(str s, uint i, uint lim)
- -> rec(count count, uint next) {
- ret if (i >= lim) {
- rec(count=count_implied, next=i)
+ fn parse_count(s: str, i: uint, lim: uint) -> {count: count, next: uint} {
+ ret if i >= lim {
+ {count: count_implied, next: i}
} else if (s.(i) == '*' as u8) {
- auto param = parse_parameter(s, i + 1u, lim);
- auto j = param.next;
- alt (param.param) {
- case (none) { rec(count=count_is_next_param, next=j) }
- case (some(?n)) { rec(count=count_is_param(n), next=j) }
+ let param = parse_parameter(s, i + 1u, lim);
+ let j = param.next;
+ alt param.param {
+ none. { {count: count_is_next_param, next: j} }
+ some(n) { {count: count_is_param(n), next: j} }
}
} else {
- auto num = peek_num(s, i, lim);
- alt (num) {
- case (none) { rec(count=count_implied, next=i) }
- case (some(?num)) { rec(count=count_is(num.num as int),
- next=num.next) }
+ let num = peek_num(s, i, lim);
+ alt num {
+ none. { {count: count_implied, next: i} }
+ some(num) {
+ {count: count_is(num.num as int), next: num.next}
+ }
}
};
}
- fn parse_precision(str s, uint i, uint lim)
- -> rec(count count, uint next) {
- ret if (i >= lim) {
- rec(count=count_implied, next=i)
+ fn parse_precision(s: str, i: uint, lim: uint) ->
+ {count: count, next: uint} {
+ ret if i >= lim {
+ {count: count_implied, next: i}
} else if (s.(i) == '.' as u8) {
- auto count = parse_count(s, i + 1u, lim);
+ let count = parse_count(s, i + 1u, lim);
+
// If there were no digits specified, i.e. the precision
// was ".", then the precision is 0
- alt (count.count) {
- case (count_implied) { rec(count=count_is(0),
- next=count.next) }
- case (_) { count }
+ alt count.count {
+ count_implied. { {count: count_is(0), next: count.next} }
+ _ { count }
}
- } else { rec(count=count_implied, next=i) };
+ } else { {count: count_implied, next: i} };
}
- fn parse_type(str s, uint i, uint lim, error_fn error)
- -> rec(ty ty, uint next) {
- if (i >= lim) { error("missing type in conversion"); }
- auto tstr = str::substr(s, i, 1u);
- auto t =
- if (str::eq(tstr, "b")) {
+ fn parse_type(s: str, i: uint, lim: uint, error: error_fn) ->
+ {ty: ty, next: uint} {
+ if i >= lim { error("missing type in conversion"); }
+ let tstr = str::substr(s, i, 1u);
+ let
+
+ // TODO: Do we really want two signed types here?
+ // How important is it to be printf compatible?
+ t =
+ if str::eq(tstr, "b") {
ty_bool
} else if (str::eq(tstr, "s")) {
ty_str
} else if (str::eq(tstr, "c")) {
ty_char
} else if (str::eq(tstr, "d") || str::eq(tstr, "i")) {
-
- // TODO: Do we really want two signed types here?
- // How important is it to be printf compatible?
ty_int(signed)
} else if (str::eq(tstr, "u")) {
ty_int(unsigned)
@@ -239,7 +239,7 @@
} else if (str::eq(tstr, "o")) {
ty_octal
} else { error("unknown type in conversion: " + tstr) };
- ret rec(ty=t, next=i + 1u);
+ ret {ty: t, next: i + 1u};
}
}
@@ -256,6 +256,7 @@
flag_sign_always;
flag_alternate;
+
// FIXME: This is a hack to avoid creating 0-length vec exprs,
// which have some difficulty typechecking currently. See
// comments in front::extfmt::make_flags
@@ -266,14 +267,14 @@
// FIXME: May not want to use a vector here for flags;
// instead just use a bool per flag
- type conv = rec(vec[flag] flags, count width, count precision, ty ty);
+ type conv = {flags: vec[flag], width: count, precision: count, ty: ty};
- fn conv_int(&conv cv, int i) -> str {
- auto radix = 10u;
- auto prec = get_int_precision(cv);
- auto s = int_to_str_prec(i, radix, prec);
- if (0 <= i) {
- if (have_flag(cv.flags, flag_sign_always)) {
+ fn conv_int(cv: &conv, i: int) -> str {
+ let radix = 10u;
+ let prec = get_int_precision(cv);
+ let s = int_to_str_prec(i, radix, prec);
+ if 0 <= i {
+ if have_flag(cv.flags, flag_sign_always) {
s = "+" + s;
} else if (have_flag(cv.flags, flag_space_for_sign)) {
s = " " + s;
@@ -281,52 +282,51 @@
}
ret pad(cv, s, pad_signed);
}
- fn conv_uint(&conv cv, uint u) -> str {
- auto prec = get_int_precision(cv);
- auto rs =
- alt (cv.ty) {
- case (ty_default) { uint_to_str_prec(u, 10u, prec) }
- case (ty_hex_lower) { uint_to_str_prec(u, 16u, prec) }
- case (ty_hex_upper) {
- str::to_upper(uint_to_str_prec(u, 16u, prec))
- }
- case (ty_bits) { uint_to_str_prec(u, 2u, prec) }
- case (ty_octal) { uint_to_str_prec(u, 8u, prec) }
+ fn conv_uint(cv: &conv, u: uint) -> str {
+ let prec = get_int_precision(cv);
+ let rs =
+ alt cv.ty {
+ ty_default. { uint_to_str_prec(u, 10u, prec) }
+ ty_hex_lower. { uint_to_str_prec(u, 16u, prec) }
+ ty_hex_upper. { str::to_upper(uint_to_str_prec(u, 16u, prec)) }
+ ty_bits. { uint_to_str_prec(u, 2u, prec) }
+ ty_octal. { uint_to_str_prec(u, 8u, prec) }
};
ret pad(cv, rs, pad_unsigned);
}
- fn conv_bool(&conv cv, bool b) -> str {
- auto s = if (b) { "true" } else { "false" };
+ fn conv_bool(cv: &conv, b: bool) -> str {
+ let s = if b { "true" } else { "false" };
// run the boolean conversion through the string conversion logic,
// giving it the same rules for precision, etc.
ret conv_str(cv, s);
}
- fn conv_char(&conv cv, char c) -> str {
+ fn conv_char(cv: &conv, c: char) -> str {
ret pad(cv, str::from_char(c), pad_nozero);
}
- fn conv_str(&conv cv, str s) -> str {
- auto unpadded =
- alt (cv.precision) {
- case (count_implied) { s }
- case (count_is(?max)) {
+ fn conv_str(cv: &conv, s: str) -> str {
+ let
- // For strings, precision is the maximum characters
- // displayed
- if (max as uint < str::char_len(s)) {
+ // For strings, precision is the maximum characters
+ // displayed
- // FIXME: substr works on bytes, not chars!
- str::substr(s, 0u, max as uint)
- } else { s }
- }
+ // FIXME: substr works on bytes, not chars!
+ unpadded =
+ alt cv.precision {
+ count_implied. { s }
+ count_is(max) {
+ if max as uint < str::char_len(s) {
+ str::substr(s, 0u, max as uint)
+ } else { s }
+ }
};
ret pad(cv, unpadded, pad_nozero);
}
// Convert an int to string with minimum number of digits. If precision is
// 0 and num is 0 then the result is the empty string.
- fn int_to_str_prec(int num, uint radix, uint prec) -> str {
- ret if (num < 0) {
+ fn int_to_str_prec(num: int, radix: uint, prec: uint) -> str {
+ ret if num < 0 {
"-" + uint_to_str_prec(-num as uint, radix, prec)
} else { uint_to_str_prec(num as uint, radix, prec) };
}
@@ -334,92 +334,89 @@
// Convert a uint to string with a minimum number of digits. If precision
// is 0 and num is 0 then the result is the empty string. Could move this
// to uint: but it doesn't seem all that useful.
- fn uint_to_str_prec(uint num, uint radix, uint prec) -> str {
- ret if (prec == 0u && num == 0u) {
+ fn uint_to_str_prec(num: uint, radix: uint, prec: uint) -> str {
+ ret if prec == 0u && num == 0u {
""
} else {
- auto s = uint::to_str(num, radix);
- auto len = str::char_len(s);
- if (len < prec) {
- auto diff = prec - len;
- auto pad = str_init_elt('0', diff);
+ let s = uint::to_str(num, radix);
+ let len = str::char_len(s);
+ if len < prec {
+ let diff = prec - len;
+ let pad = str_init_elt('0', diff);
pad + s
} else { s }
};
}
- fn get_int_precision(&conv cv) -> uint {
- ret alt (cv.precision) {
- case (count_is(?c)) { c as uint }
- case (count_implied) { 1u }
+ fn get_int_precision(cv: &conv) -> uint {
+ ret alt cv.precision {
+ count_is(c) { c as uint }
+ count_implied. { 1u }
};
}
// FIXME: This might be useful in str: but needs to be utf8 safe first
- fn str_init_elt(char c, uint n_elts) -> str {
- auto svec = vec::init_elt[u8](c as u8, n_elts);
+ fn str_init_elt(c: char, n_elts: uint) -> str {
+ let svec = vec::init_elt[u8](c as u8, n_elts);
ret str::from_bytes(svec);
}
tag pad_mode { pad_signed; pad_unsigned; pad_nozero; }
- fn pad(&conv cv, str s, pad_mode mode) -> str {
- auto uwidth;
- alt (cv.width) {
- case (count_implied) { ret s; }
- case (count_is(?width)) {
- // FIXME: Maybe width should be uint
+ fn pad(cv: &conv, s: str, mode: pad_mode) -> str {
+ let uwidth;
+ alt cv.width {
+ count_implied. { ret s; }
+ count_is(width) {
+ // FIXME: Maybe width should be uint
- uwidth = width as uint;
- }
+ uwidth = width as uint;
+ }
}
- auto strlen = str::char_len(s);
- if (uwidth <= strlen) { ret s; }
- auto padchar = ' ';
- auto diff = uwidth - strlen;
- if (have_flag(cv.flags, flag_left_justify)) {
- auto padstr = str_init_elt(padchar, diff);
+ let strlen = str::char_len(s);
+ if uwidth <= strlen { ret s; }
+ let padchar = ' ';
+ let diff = uwidth - strlen;
+ if have_flag(cv.flags, flag_left_justify) {
+ let padstr = str_init_elt(padchar, diff);
ret s + padstr;
}
- auto might_zero_pad = false;
- auto signed = false;
- alt (mode) {
- case (pad_nozero) {
- // fallthrough
+ let might_zero_pad = false;
+ let signed = false;
+ alt mode {
+ pad_nozero. {
+ // fallthrough
- }
- case (pad_signed) { might_zero_pad = true; signed = true; }
- case (pad_unsigned) { might_zero_pad = true; }
+ }
+ pad_signed. { might_zero_pad = true; signed = true; }
+ pad_unsigned. { might_zero_pad = true; }
}
- fn have_precision(&conv cv) -> bool {
- ret alt (cv.precision) {
- case (count_implied) { false }
- case (_) { true }
- };
+ fn have_precision(cv: &conv) -> bool {
+ ret alt cv.precision { count_implied. { false } _ { true } };
}
- auto zero_padding = false;
- if (might_zero_pad && have_flag(cv.flags, flag_left_zero_pad) &&
- !have_precision(cv)) {
+ let zero_padding = false;
+ if might_zero_pad && have_flag(cv.flags, flag_left_zero_pad) &&
+ !have_precision(cv) {
padchar = '0';
zero_padding = true;
}
- auto padstr = str_init_elt(padchar, diff);
+ let padstr = str_init_elt(padchar, diff);
// This is completely heinous. If we have a signed value then
// potentially rip apart the intermediate result and insert some
// zeros. It may make sense to convert zero padding to a precision
// instead.
- if (signed && zero_padding && str::byte_len(s) > 0u) {
- auto head = s.(0);
- if (head == '+' as u8 || head == '-' as u8 || head == ' ' as u8) {
- auto headstr = str::unsafe_from_bytes([head]);
- auto bytelen = str::byte_len(s);
- auto numpart = str::substr(s, 1u, bytelen - 1u);
+ if signed && zero_padding && str::byte_len(s) > 0u {
+ let head = s.(0);
+ if head == '+' as u8 || head == '-' as u8 || head == ' ' as u8 {
+ let headstr = str::unsafe_from_bytes([head]);
+ let bytelen = str::byte_len(s);
+ let numpart = str::substr(s, 1u, bytelen - 1u);
ret headstr + padstr + numpart;
}
}
ret padstr + s;
}
- fn have_flag(vec[flag] flags, flag f) -> bool {
- for (flag candidate in flags) { if (candidate == f) { ret true; } }
+ fn have_flag(flags: vec[flag], f: flag) -> bool {
+ for candidate: flag in flags { if candidate == f { ret true; } }
ret false;
}
}
diff --git a/src/lib/fs.rs b/src/lib/fs.rs
index 6370ece..7a4467f 100644
--- a/src/lib/fs.rs
+++ b/src/lib/fs.rs
@@ -4,74 +4,64 @@
import str;
native "rust" mod rustrt {
- fn rust_file_is_dir(str path) -> int;
+ fn rust_file_is_dir(path: str) -> int;
}
fn path_sep() -> str { ret str::from_char(os_fs::path_sep); }
type path = str;
-fn dirname(path p) -> path {
- let int i = str::rindex(p, os_fs::path_sep as u8);
- if (i == -1) {
+fn dirname(p: path) -> path {
+ let i: int = str::rindex(p, os_fs::path_sep as u8);
+ if i == -1 {
i = str::rindex(p, os_fs::alt_path_sep as u8);
- if (i == -1) { ret "."; }
+ if i == -1 { ret "."; }
}
ret str::substr(p, 0u, i as uint);
}
-fn basename(path p) -> path {
- let int i = str::rindex(p, os_fs::path_sep as u8);
- if (i == -1) {
+fn basename(p: path) -> path {
+ let i: int = str::rindex(p, os_fs::path_sep as u8);
+ if i == -1 {
i = str::rindex(p, os_fs::alt_path_sep as u8);
- if (i == -1) { ret p; }
+ if i == -1 { ret p; }
}
- auto len = str::byte_len(p);
- if (i + 1 as uint >= len) { ret p; }
+ let len = str::byte_len(p);
+ if i + 1 as uint >= len { ret p; }
ret str::slice(p, i + 1 as uint, len);
}
// FIXME: Need some typestate to avoid bounds check when len(pre) == 0
-fn connect(path pre, path post) -> path {
- auto len = str::byte_len(pre);
- ret if (pre.(len - 1u) == os_fs::path_sep as u8) {
+fn connect(pre: path, post: path) -> path {
+ let len = str::byte_len(pre);
+ ret if pre.(len - 1u) == os_fs::path_sep as u8 {
+
// Trailing '/'?
pre + post
} else { pre + path_sep() + post };
}
-fn file_is_dir(path p) -> bool { ret rustrt::rust_file_is_dir(p) != 0; }
+fn file_is_dir(p: path) -> bool { ret rustrt::rust_file_is_dir(p) != 0; }
-fn list_dir(path p) -> str[] {
- auto pl = str::byte_len(p);
- if (pl == 0u || p.(pl - 1u) as char != os_fs::path_sep) {
- p += path_sep();
- }
- let str[] full_paths = ~[];
- for (str filename in os_fs::list_dir(p)) {
- if (!str::eq(filename, ".")) {
- if (!str::eq(filename, "..")) {
- full_paths += ~[p + filename];
- }
+fn list_dir(p: path) -> str[] {
+ let pl = str::byte_len(p);
+ if pl == 0u || p.(pl - 1u) as char != os_fs::path_sep { p += path_sep(); }
+ let full_paths: str[] = ~[];
+ for filename: str in os_fs::list_dir(p) {
+ if !str::eq(filename, ".") {
+ if !str::eq(filename, "..") { full_paths += ~[p + filename]; }
}
}
ret full_paths;
}
-fn path_is_absolute(path p) -> bool {
- ret os_fs::path_is_absolute(p);
-}
+fn path_is_absolute(p: path) -> bool { ret os_fs::path_is_absolute(p); }
// FIXME: under Windows, we should prepend the current drive letter to paths
// that start with a slash.
-fn make_absolute(path p) -> path {
- if(path_is_absolute(p)) {
- ret p;
- }
- else {
- ret connect(getcwd(), p);
- }
+fn make_absolute(p: path) -> path {
+ if path_is_absolute(p) { ret p; } else { ret connect(getcwd(), p); }
}
// Local Variables:
diff --git a/src/lib/generic_os.rs b/src/lib/generic_os.rs
index 404ada3..bd78f02 100644
--- a/src/lib/generic_os.rs
+++ b/src/lib/generic_os.rs
@@ -3,44 +3,42 @@
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
-fn getenv(str n) -> option::t[str] {
- auto s = os::libc::getenv(str::buf(n));
- ret if (s as int == 0) {
+fn getenv(n: str) -> option::t[str] {
+ let s = os::libc::getenv(str::buf(n));
+ ret if s as int == 0 {
option::none[str]
} else { option::some[str](str::str_from_cstr(s)) };
}
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
-fn setenv(str n, str v) {
- auto nbuf = str::buf(n);
- auto vbuf = str::buf(v);
+fn setenv(n: str, v: str) {
+ let nbuf = str::buf(n);
+ let vbuf = str::buf(v);
os::libc::setenv(nbuf, vbuf, 1);
}
#[cfg(target_os = "win32")]
-fn getenv(str n) -> option::t[str]{
- auto nbuf = str::buf(n);
- auto nsize = 256u;
- while (true) {
- auto vstr = str::alloc(nsize - 1u);
- auto vbuf = str::buf(vstr);
- auto res = os::kernel32::GetEnvironmentVariableA(nbuf, vbuf, nsize);
- if (res == 0u) {
+fn getenv(n: str) -> option::t[str] {
+ let nbuf = str::buf(n);
+ let nsize = 256u;
+ while true {
+ let vstr = str::alloc(nsize - 1u);
+ let vbuf = str::buf(vstr);
+ let res = os::kernel32::GetEnvironmentVariableA(nbuf, vbuf, nsize);
+ if res == 0u {
ret option::none;
} else if (res < nsize) {
ret option::some(str::str_from_cstr(vbuf));
- } else {
- nsize = res;
- }
+ } else { nsize = res; }
}
fail;
}
#[cfg(target_os = "win32")]
-fn setenv(str n, str v) {
- auto nbuf = str::buf(n);
- auto vbuf = str::buf(v);
+fn setenv(n: str, v: str) {
+ let nbuf = str::buf(n);
+ let vbuf = str::buf(v);
os::kernel32::SetEnvironmentVariableA(nbuf, vbuf);
}
diff --git a/src/lib/getopts.rs b/src/lib/getopts.rs
index f5e29a3..67297e9 100644
--- a/src/lib/getopts.rs
+++ b/src/lib/getopts.rs
@@ -36,56 +36,50 @@
tag occur { req; optional; multi; }
-type opt = rec(name name, hasarg hasarg, occur occur);
+type opt = {name: name, hasarg: hasarg, occur: occur};
-fn mkname(str nm) -> name {
- ret if (str::char_len(nm) == 1u) {
+fn mkname(nm: str) -> name {
+ ret if str::char_len(nm) == 1u {
short(str::char_at(nm, 0u))
} else { long(nm) };
}
-fn reqopt(str name) -> opt {
- ret rec(name=mkname(name), hasarg=yes, occur=req);
+fn reqopt(name: str) -> opt {
+ ret {name: mkname(name), hasarg: yes, occur: req};
}
-fn optopt(str name) -> opt {
- ret rec(name=mkname(name), hasarg=yes, occur=optional);
+fn optopt(name: str) -> opt {
+ ret {name: mkname(name), hasarg: yes, occur: optional};
}
-fn optflag(str name) -> opt {
- ret rec(name=mkname(name), hasarg=no, occur=optional);
+fn optflag(name: str) -> opt {
+ ret {name: mkname(name), hasarg: no, occur: optional};
}
-fn optflagopt(str name) -> opt {
- ret rec(name=mkname(name), hasarg=maybe, occur=optional);
+fn optflagopt(name: str) -> opt {
+ ret {name: mkname(name), hasarg: maybe, occur: optional};
}
-fn optmulti(str name) -> opt {
- ret rec(name=mkname(name), hasarg=yes, occur=multi);
+fn optmulti(name: str) -> opt {
+ ret {name: mkname(name), hasarg: yes, occur: multi};
}
tag optval { val(str); given; }
-type match = rec(opt[] opts, (optval[])[mutable] vals, vec[str] free);
+type match = {opts: opt[], vals: optval[][mutable ], free: vec[str]};
-fn is_arg(str arg) -> bool {
+fn is_arg(arg: str) -> bool {
ret str::byte_len(arg) > 1u && arg.(0) == '-' as u8;
}
-fn name_str(name nm) -> str {
- ret alt (nm) {
- case (short(?ch)) { str::from_char(ch) }
- case (long(?s)) { s }
- };
+fn name_str(nm: name) -> str {
+ ret alt nm { short(ch) { str::from_char(ch) } long(s) { s } };
}
-fn find_opt(&opt[] opts, name nm) -> option::t[uint] {
- auto i = 0u;
- auto l = ivec::len[opt](opts);
- while (i < l) {
- if (opts.(i).name == nm) { ret some[uint](i); }
- i += 1u;
- }
+fn find_opt(opts: &opt[], nm: name) -> option::t[uint] {
+ let i = 0u;
+ let l = ivec::len[opt](opts);
+ while i < l { if opts.(i).name == nm { ret some[uint](i); } i += 1u; }
ret none[uint];
}
@@ -97,62 +91,54 @@
unexpected_argument(str);
}
-fn fail_str(fail_ f) -> str {
- ret alt (f) {
- case (argument_missing(?nm)) {
- "Argument to option '" + nm + "' missing."
- }
- case (unrecognized_option(?nm)) {
- "Unrecognized option: '" + nm + "'."
- }
- case (option_missing(?nm)) {
- "Required option '" + nm + "' missing."
- }
- case (option_duplicated(?nm)) {
- "Option '" + nm + "' given more than once."
- }
- case (unexpected_argument(?nm)) {
- "Option " + nm + " does not take an argument."
- }
+fn fail_str(f: fail_) -> str {
+ ret alt f {
+ argument_missing(nm) { "Argument to option '" + nm + "' missing." }
+ unrecognized_option(nm) { "Unrecognized option: '" + nm + "'." }
+ option_missing(nm) { "Required option '" + nm + "' missing." }
+ option_duplicated(nm) {
+ "Option '" + nm + "' given more than once."
+ }
+ unexpected_argument(nm) {
+ "Option " + nm + " does not take an argument."
+ }
};
}
tag result { success(match); failure(fail_); }
-fn getopts(vec[str] args, vec[opt] opts) -> result {
+fn getopts(args: vec[str], opts: vec[opt]) -> result {
// FIXME: Remove this vec->ivec conversion.
- auto args_ivec = ~[]; auto opts_ivec = ~[];
- for (str arg in args) { args_ivec += ~[arg]; }
- for (opt o in opts) { opts_ivec += ~[o]; }
+ let args_ivec = ~[];
+ let opts_ivec = ~[];
+ for arg: str in args { args_ivec += ~[arg]; }
+ for o: opt in opts { opts_ivec += ~[o]; }
ret getopts_ivec(args_ivec, opts_ivec);
}
-fn getopts_ivec(&str[] args, &opt[] opts) -> result {
- auto n_opts = ivec::len[opt](opts);
- fn f(uint x) -> optval[] { ret ~[]; }
- auto vals = ivec::init_fn_mut[optval[]](f, n_opts);
- let vec[str] free = [];
- auto l = ivec::len[str](args);
- auto i = 0u;
- while (i < l) {
- auto cur = args.(i);
- auto curlen = str::byte_len(cur);
- if (!is_arg(cur)) {
+fn getopts_ivec(args: &str[], opts: &opt[]) -> result {
+ let n_opts = ivec::len[opt](opts);
+ fn f(x: uint) -> optval[] { ret ~[]; }
+ let vals = ivec::init_fn_mut[optval[]](f, n_opts);
+ let free: vec[str] = [];
+ let l = ivec::len[str](args);
+ let i = 0u;
+ while i < l {
+ let cur = args.(i);
+ let curlen = str::byte_len(cur);
+ if !is_arg(cur) {
free += [cur];
} else if (str::eq(cur, "--")) {
- auto j = i + 1u;
- while (j < l) {
- free += [args.(j)];
- j += 1u;
- }
+ let j = i + 1u;
+ while j < l { free += [args.(j)]; j += 1u; }
break;
} else {
- auto names;
- auto i_arg = option::none[str];
- if (cur.(1) == '-' as u8) {
- auto tail = str::slice(cur, 2u, curlen);
- auto eq = str::index(tail, '=' as u8);
- if (eq == -1) {
+ let names;
+ let i_arg = option::none[str];
+ if cur.(1) == '-' as u8 {
+ let tail = str::slice(cur, 2u, curlen);
+ let eq = str::index(tail, '=' as u8);
+ if eq == -1 {
names = ~[long(tail)];
} else {
names = ~[long(str::slice(tail, 0u, eq as uint))];
@@ -161,129 +147,115 @@
curlen - 2u));
}
} else {
- auto j = 1u;
+ let j = 1u;
names = ~[];
- while (j < curlen) {
- auto range = str::char_range_at(cur, j);
+ while j < curlen {
+ let range = str::char_range_at(cur, j);
names += ~[short(range.ch)];
j = range.next;
}
}
- auto name_pos = 0u;
- for (name nm in names) {
+ let name_pos = 0u;
+ for nm: name in names {
name_pos += 1u;
- auto optid;
- alt (find_opt(opts, nm)) {
- case (some(?id)) { optid = id; }
- case (none) {
- ret failure(unrecognized_option(name_str(nm)));
- }
+ let optid;
+ alt find_opt(opts, nm) {
+ some(id) { optid = id; }
+ none. { ret failure(unrecognized_option(name_str(nm))); }
}
- alt (opts.(optid).hasarg) {
- case (no) {
- if (!option::is_none[str](i_arg)) {
- ret failure(unexpected_argument(name_str(nm)));
- }
+ alt opts.(optid).hasarg {
+ no. {
+ if !option::is_none[str](i_arg) {
+ ret failure(unexpected_argument(name_str(nm)));
+ }
+ vals.(optid) += ~[given];
+ }
+ maybe. {
+ if !option::is_none[str](i_arg) {
+ vals.(optid) += ~[val(option::get(i_arg))];
+ } else if (name_pos < ivec::len[name](names) ||
+ i + 1u == l || is_arg(args.(i + 1u))) {
vals.(optid) += ~[given];
- }
- case (maybe) {
- if (!option::is_none[str](i_arg)) {
- vals.(optid) += ~[val(option::get(i_arg))];
- } else if (name_pos < ivec::len[name](names) ||
- i + 1u == l || is_arg(args.(i + 1u))) {
- vals.(optid) += ~[given];
- } else {
- i += 1u;
- vals.(optid) += ~[val(args.(i))];
- }
- }
- case (yes) {
- if (!option::is_none[str](i_arg)) {
- vals.(optid) += ~[val(option::get[str](i_arg))];
- } else if (i + 1u == l) {
- ret failure(argument_missing(name_str(nm)));
- } else {
- i += 1u;
- vals.(optid) += ~[val(args.(i))];
- }
- }
+ } else { i += 1u; vals.(optid) += ~[val(args.(i))]; }
+ }
+ yes. {
+ if !option::is_none[str](i_arg) {
+ vals.(optid) += ~[val(option::get[str](i_arg))];
+ } else if (i + 1u == l) {
+ ret failure(argument_missing(name_str(nm)));
+ } else { i += 1u; vals.(optid) += ~[val(args.(i))]; }
+ }
}
}
}
i += 1u;
}
i = 0u;
- while (i < n_opts) {
- auto n = ivec::len[optval](vals.(i));
- auto occ = opts.(i).occur;
- if (occ == req) {
- if (n == 0u) {
+ while i < n_opts {
+ let n = ivec::len[optval](vals.(i));
+ let occ = opts.(i).occur;
+ if occ == req {
+ if n == 0u {
ret failure(option_missing(name_str(opts.(i).name)));
}
}
- if (occ != multi) {
- if (n > 1u) {
+ if occ != multi {
+ if n > 1u {
ret failure(option_duplicated(name_str(opts.(i).name)));
}
}
i += 1u;
}
- ret success(rec(opts=opts, vals=vals, free=free));
+ ret success({opts: opts, vals: vals, free: free});
}
-fn opt_vals(match m, str nm) -> optval[] {
- ret alt (find_opt(m.opts, mkname(nm))) {
- case (some(?id)) { m.vals.(id) }
- case (none) { log_err "No option '" + nm + "' defined."; fail }
+fn opt_vals(m: match, nm: str) -> optval[] {
+ ret alt find_opt(m.opts, mkname(nm)) {
+ some(id) { m.vals.(id) }
+ none. { log_err "No option '" + nm + "' defined."; fail }
};
}
-fn opt_val(match m, str nm) -> optval { ret opt_vals(m, nm).(0); }
+fn opt_val(m: match, nm: str) -> optval { ret opt_vals(m, nm).(0); }
-fn opt_present(match m, str nm) -> bool {
+fn opt_present(m: match, nm: str) -> bool {
ret ivec::len[optval](opt_vals(m, nm)) > 0u;
}
-fn opt_str(match m, str nm) -> str {
- ret alt (opt_val(m, nm)) { case (val(?s)) { s } case (_) { fail } };
+fn opt_str(m: match, nm: str) -> str {
+ ret alt opt_val(m, nm) { val(s) { s } _ { fail } };
}
-fn opt_strs(match m, str nm) -> vec[str] {
- let vec[str] acc = [];
- for (optval v in opt_vals(m, nm)) {
- alt (v) { case (val(?s)) { acc += [s]; } case (_) { } }
+fn opt_strs(m: match, nm: str) -> vec[str] {
+ let acc: vec[str] = [];
+ for v: optval in opt_vals(m, nm) {
+ alt v { val(s) { acc += [s]; } _ { } }
}
ret acc;
}
-fn opt_strs_ivec(match m, str nm) -> str[] {
- let str[] acc = ~[];
- for (optval v in opt_vals(m, nm)) {
- alt (v) { case (val(?s)) { acc += ~[s]; } case (_) { } }
+fn opt_strs_ivec(m: match, nm: str) -> str[] {
+ let acc: str[] = ~[];
+ for v: optval in opt_vals(m, nm) {
+ alt v { val(s) { acc += ~[s]; } _ { } }
}
ret acc;
}
-fn opt_maybe_str(match m, str nm) -> option::t[str] {
- auto vals = opt_vals(m, nm);
- if (ivec::len[optval](vals) == 0u) { ret none[str]; }
- ret alt (vals.(0)) {
- case (val(?s)) { some[str](s) }
- case (_) { none[str] }
- };
+fn opt_maybe_str(m: match, nm: str) -> option::t[str] {
+ let vals = opt_vals(m, nm);
+ if ivec::len[optval](vals) == 0u { ret none[str]; }
+ ret alt vals.(0) { val(s) { some[str](s) } _ { none[str] } };
}
/// Returns none if the option was not present, `def` if the option was
/// present but no argument was provided, and the argument if the option was
/// present and an argument was provided.
-fn opt_default(match m, str nm, str def) -> option::t[str] {
- auto vals = opt_vals(m, nm);
- if (ivec::len[optval](vals) == 0u) { ret none[str]; }
- ret alt (vals.(0)) {
- case (val(?s)) { some[str](s) }
- case (_) { some[str](def) }
- }
+fn opt_default(m: match, nm: str, def: str) -> option::t[str] {
+ let vals = opt_vals(m, nm);
+ if ivec::len[optval](vals) == 0u { ret none[str]; }
+ ret alt vals.(0) { val(s) { some[str](s) } _ { some[str](def) } }
}
// Local Variables:
// mode: rust;
diff --git a/src/lib/int.rs b/src/lib/int.rs
index af2403c..52a1cb1 100644
--- a/src/lib/int.rs
+++ b/src/lib/int.rs
@@ -1,63 +1,63 @@
-fn add(int x, int y) -> int { ret x + y; }
+fn add(x: int, y: int) -> int { ret x + y; }
-fn sub(int x, int y) -> int { ret x - y; }
+fn sub(x: int, y: int) -> int { ret x - y; }
-fn mul(int x, int y) -> int { ret x * y; }
+fn mul(x: int, y: int) -> int { ret x * y; }
-fn div(int x, int y) -> int { ret x / y; }
+fn div(x: int, y: int) -> int { ret x / y; }
-fn rem(int x, int y) -> int { ret x % y; }
+fn rem(x: int, y: int) -> int { ret x % y; }
-fn lt(int x, int y) -> bool { ret x < y; }
+fn lt(x: int, y: int) -> bool { ret x < y; }
-fn le(int x, int y) -> bool { ret x <= y; }
+fn le(x: int, y: int) -> bool { ret x <= y; }
-fn eq(int x, int y) -> bool { ret x == y; }
+fn eq(x: int, y: int) -> bool { ret x == y; }
-fn ne(int x, int y) -> bool { ret x != y; }
+fn ne(x: int, y: int) -> bool { ret x != y; }
-fn ge(int x, int y) -> bool { ret x >= y; }
+fn ge(x: int, y: int) -> bool { ret x >= y; }
-fn gt(int x, int y) -> bool { ret x > y; }
+fn gt(x: int, y: int) -> bool { ret x > y; }
-fn positive(int x) -> bool { ret x > 0; }
+fn positive(x: int) -> bool { ret x > 0; }
-fn negative(int x) -> bool { ret x < 0; }
+fn negative(x: int) -> bool { ret x < 0; }
-fn nonpositive(int x) -> bool { ret x <= 0; }
+fn nonpositive(x: int) -> bool { ret x <= 0; }
-fn nonnegative(int x) -> bool { ret x >= 0; }
+fn nonnegative(x: int) -> bool { ret x >= 0; }
// FIXME: Make sure this works with negative integers.
-fn hash(&int x) -> uint { ret x as uint; }
+fn hash(x: &int) -> uint { ret x as uint; }
-fn eq_alias(&int x, &int y) -> bool { ret x == y; }
+fn eq_alias(x: &int, y: &int) -> bool { ret x == y; }
-iter range(int lo, int hi) -> int {
- let int lo_ = lo;
- while (lo_ < hi) { put lo_; lo_ += 1; }
+iter range(lo: int, hi: int) -> int {
+ let lo_: int = lo;
+ while lo_ < hi { put lo_; lo_ += 1; }
}
-fn to_str(int n, uint radix) -> str {
+fn to_str(n: int, radix: uint) -> str {
assert (0u < radix && radix <= 16u);
- ret if (n < 0) {
+ ret if n < 0 {
"-" + uint::to_str(-n as uint, radix)
} else { uint::to_str(n as uint, radix) };
}
-fn str(int i) -> str { ret to_str(i, 10u); }
+fn str(i: int) -> str { ret to_str(i, 10u); }
-fn pow(int base, uint exponent) -> int {
- ret if (exponent == 0u) {
+fn pow(base: int, exponent: uint) -> int {
+ ret if exponent == 0u {
1
} else if (base == 0) {
0
} else {
- auto accum = base;
- auto count = exponent;
- while (count > 1u) { accum *= base; count -= 1u; }
+ let accum = base;
+ let count = exponent;
+ while count > 1u { accum *= base; count -= 1u; }
accum
};
}
diff --git a/src/lib/io.rs b/src/lib/io.rs
index c2c2389..acbbd49 100644
--- a/src/lib/io.rs
+++ b/src/lib/io.rs
@@ -15,25 +15,27 @@
// The raw underlying reader class. All readers must implement this.
type buf_reader =
+
+ // FIXME: Seekable really should be orthogonal. We will need
+ // inheritance.
obj {
fn read(uint) -> vec[u8] ;
fn read_byte() -> int ;
fn unread_byte(int) ;
fn eof() -> bool ;
-
- // FIXME: Seekable really should be orthogonal. We will need
- // inheritance.
- fn seek(int, seek_style) ;
+ fn seek(int, seek_style) ;
fn tell() -> uint ;
};
// Convenience methods for reading.
type reader =
- obj {
- // FIXME: This should inherit from buf_reader.
- fn get_buf_reader() -> buf_reader ;
+ // FIXME: This should inherit from buf_reader.
+ // FIXME: eventually u64
+
+ obj {
+ fn get_buf_reader() -> buf_reader ;
fn read_byte() -> int ;
fn unread_byte(int) ;
fn read_bytes(uint) -> vec[u8] ;
@@ -46,57 +48,52 @@
fn read_be_uint(uint) -> uint ;
fn read_whole_stream() -> vec[u8] ;
fn seek(int, seek_style) ;
- fn tell() -> uint ; // FIXME: eventually u64
-
+ fn tell() -> uint ;
};
-fn convert_whence(seek_style whence) -> int {
- ret alt (whence) {
- case (seek_set) { 0 }
- case (seek_cur) { 1 }
- case (seek_end) { 2 }
- };
+fn convert_whence(whence: seek_style) -> int {
+ ret alt whence { seek_set. { 0 } seek_cur. { 1 } seek_end. { 2 } };
}
-obj FILE_buf_reader(os::libc::FILE f, bool must_close) {
- fn read(uint len) -> vec[u8] {
- auto buf = vec::alloc[u8](len);
- auto read = os::libc::fread(vec::buf[u8](buf), 1u, len, f);
+obj FILE_buf_reader(f: os::libc::FILE, must_close: bool) {
+ fn read(len: uint) -> vec[u8] {
+ let buf = vec::alloc[u8](len);
+ let read = os::libc::fread(vec::buf[u8](buf), 1u, len, f);
vec::len_set[u8](buf, read);
ret buf;
}
fn read_byte() -> int { ret os::libc::fgetc(f); }
- fn unread_byte(int byte) { os::libc::ungetc(byte, f); }
+ fn unread_byte(byte: int) { os::libc::ungetc(byte, f); }
fn eof() -> bool { ret os::libc::feof(f) != 0; }
- fn seek(int offset, seek_style whence) {
+ fn seek(offset: int, whence: seek_style) {
assert (os::libc::fseek(f, offset, convert_whence(whence)) == 0);
}
fn tell() -> uint {
ret os::libc::ftell(f) as uint;
- }drop { if (must_close) { os::libc::fclose(f); } }
+ }drop { if must_close { os::libc::fclose(f); } }
}
// FIXME: Convert this into pseudomethods on buf_reader.
-obj new_reader(buf_reader rdr) {
+obj new_reader(rdr: buf_reader) {
fn get_buf_reader() -> buf_reader { ret rdr; }
fn read_byte() -> int { ret rdr.read_byte(); }
- fn unread_byte(int byte) { ret rdr.unread_byte(byte); }
- fn read_bytes(uint len) -> vec[u8] { ret rdr.read(len); }
+ fn unread_byte(byte: int) { ret rdr.unread_byte(byte); }
+ fn read_bytes(len: uint) -> vec[u8] { ret rdr.read(len); }
fn read_char() -> char {
- auto c0 = rdr.read_byte();
- if (c0 == -1) {
+ let c0 = rdr.read_byte();
+ if c0 == -1 {
ret -1 as char; // FIXME will this stay valid?
}
- auto b0 = c0 as u8;
- auto w = str::utf8_char_width(b0);
+ let b0 = c0 as u8;
+ let w = str::utf8_char_width(b0);
assert (w > 0u);
- if (w == 1u) { ret b0 as char; }
- auto val = 0u;
- while (w > 1u) {
+ if w == 1u { ret b0 as char; }
+ let val = 0u;
+ while w > 1u {
w -= 1u;
- auto next = rdr.read_byte();
+ let next = rdr.read_byte();
assert (next > -1);
assert (next & 192 == 128);
val <<= 6u;
@@ -109,24 +106,24 @@
}
fn eof() -> bool { ret rdr.eof(); }
fn read_line() -> str {
- let vec[u8] buf = [];
+ let buf: vec[u8] = [];
// No break yet in rustc
- auto go_on = true;
- while (go_on) {
- auto ch = rdr.read_byte();
- if (ch == -1 || ch == 10) {
+ let go_on = true;
+ while go_on {
+ let ch = rdr.read_byte();
+ if ch == -1 || ch == 10 {
go_on = false;
} else { vec::push[u8](buf, ch as u8); }
}
ret str::unsafe_from_bytes(buf);
}
fn read_c_str() -> str {
- let vec[u8] buf = [];
- auto go_on = true;
- while (go_on) {
- auto ch = rdr.read_byte();
- if (ch < 1) {
+ let buf: vec[u8] = [];
+ let go_on = true;
+ while go_on {
+ let ch = rdr.read_byte();
+ if ch < 1 {
go_on = false;
} else { vec::push[u8](buf, ch as u8); }
}
@@ -134,20 +131,20 @@
}
// FIXME deal with eof?
- fn read_le_uint(uint size) -> uint {
- auto val = 0u;
- auto pos = 0u;
- while (size > 0u) {
+ fn read_le_uint(size: uint) -> uint {
+ let val = 0u;
+ let pos = 0u;
+ while size > 0u {
val += (rdr.read_byte() as uint) << pos;
pos += 8u;
size -= 1u;
}
ret val;
}
- fn read_le_int(uint size) -> int {
- auto val = 0u;
- auto pos = 0u;
- while (size > 0u) {
+ fn read_le_int(size: uint) -> int {
+ let val = 0u;
+ let pos = 0u;
+ while size > 0u {
val += (rdr.read_byte() as uint) << pos;
pos += 8u;
size -= 1u;
@@ -156,21 +153,21 @@
}
// FIXME deal with eof?
- fn read_be_uint(uint sz) -> uint {
- auto val = 0u;
+ fn read_be_uint(sz: uint) -> uint {
+ let val = 0u;
- while (sz > 0u) {
+ while sz > 0u {
sz -= 1u;
val += (rdr.read_byte() as uint) << sz * 8u;
}
ret val;
}
fn read_whole_stream() -> vec[u8] {
- let vec[u8] buf = [];
- while (!rdr.eof()) { buf += rdr.read(2048u); }
+ let buf: vec[u8] = [];
+ while !rdr.eof() { buf += rdr.read(2048u); }
ret buf;
}
- fn seek(int offset, seek_style whence) { ret rdr.seek(offset, whence); }
+ fn seek(offset: int, whence: seek_style) { ret rdr.seek(offset, whence); }
fn tell() -> uint { ret rdr.tell(); }
}
@@ -178,49 +175,49 @@
ret new_reader(FILE_buf_reader(rustrt::rust_get_stdin(), false));
}
-fn file_reader(str path) -> reader {
- auto f = os::libc::fopen(str::buf(path), str::buf("r"));
- if (f as uint == 0u) { log_err "error opening " + path; fail; }
+fn file_reader(path: str) -> reader {
+ let f = os::libc::fopen(str::buf(path), str::buf("r"));
+ if f as uint == 0u { log_err "error opening " + path; fail; }
ret new_reader(FILE_buf_reader(f, true));
}
// FIXME: Remove me once objects are exported.
-fn new_reader_(buf_reader bufr) -> reader { ret new_reader(bufr); }
+fn new_reader_(bufr: buf_reader) -> reader { ret new_reader(bufr); }
// Byte buffer readers
// TODO: mutable? u8, but this fails with rustboot.
-type byte_buf = @rec(vec[u8] buf, mutable uint pos);
+type byte_buf = @{buf: vec[u8], mutable pos: uint};
-obj byte_buf_reader(byte_buf bbuf) {
- fn read(uint len) -> vec[u8] {
- auto rest = vec::len[u8](bbuf.buf) - bbuf.pos;
- auto to_read = len;
- if (rest < to_read) { to_read = rest; }
- auto range = vec::slice[u8](bbuf.buf, bbuf.pos, bbuf.pos + to_read);
+obj byte_buf_reader(bbuf: byte_buf) {
+ fn read(len: uint) -> vec[u8] {
+ let rest = vec::len[u8](bbuf.buf) - bbuf.pos;
+ let to_read = len;
+ if rest < to_read { to_read = rest; }
+ let range = vec::slice[u8](bbuf.buf, bbuf.pos, bbuf.pos + to_read);
bbuf.pos += to_read;
ret range;
}
fn read_byte() -> int {
- if (bbuf.pos == vec::len[u8](bbuf.buf)) { ret -1; }
- auto b = bbuf.buf.(bbuf.pos);
+ if bbuf.pos == vec::len[u8](bbuf.buf) { ret -1; }
+ let b = bbuf.buf.(bbuf.pos);
bbuf.pos += 1u;
ret b as int;
}
- fn unread_byte(int byte) { log_err "TODO: unread_byte"; fail; }
+ fn unread_byte(byte: int) { log_err "TODO: unread_byte"; fail; }
fn eof() -> bool { ret bbuf.pos == vec::len[u8](bbuf.buf); }
- fn seek(int offset, seek_style whence) {
- auto pos = bbuf.pos;
- auto len = vec::len[u8](bbuf.buf);
+ fn seek(offset: int, whence: seek_style) {
+ let pos = bbuf.pos;
+ let len = vec::len[u8](bbuf.buf);
bbuf.pos = seek_in_buf(offset, pos, len, whence);
}
fn tell() -> uint { ret bbuf.pos; }
}
-fn new_byte_buf_reader(vec[u8] buf) -> byte_buf_reader {
- ret byte_buf_reader(@rec(buf=buf, mutable pos=0u));
+fn new_byte_buf_reader(buf: vec[u8]) -> byte_buf_reader {
+ ret byte_buf_reader(@{buf: buf, mutable pos: 0u});
}
@@ -228,40 +225,41 @@
tag fileflag { append; create; truncate; none; }
type buf_writer =
+
+ // FIXME: Seekable really should be orthogonal. We will need
+ // inheritance.
+ // FIXME: eventually u64
+
obj {
fn write(vec[u8]) ;
-
- // FIXME: Seekable really should be orthogonal. We will need
- // inheritance.
- fn seek(int, seek_style) ;
- fn tell() -> uint ; // FIXME: eventually u64
-
+ fn seek(int, seek_style) ;
+ fn tell() -> uint ;
};
-obj FILE_writer(os::libc::FILE f, bool must_close) {
- fn write(vec[u8] v) {
- auto len = vec::len[u8](v);
- auto vbuf = vec::buf[u8](v);
- auto nout = os::libc::fwrite(vbuf, len, 1u, f);
- if (nout < 1u) { log_err "error dumping buffer"; }
+obj FILE_writer(f: os::libc::FILE, must_close: bool) {
+ fn write(v: vec[u8]) {
+ let len = vec::len[u8](v);
+ let vbuf = vec::buf[u8](v);
+ let nout = os::libc::fwrite(vbuf, len, 1u, f);
+ if nout < 1u { log_err "error dumping buffer"; }
}
- fn seek(int offset, seek_style whence) {
+ fn seek(offset: int, whence: seek_style) {
assert (os::libc::fseek(f, offset, convert_whence(whence)) == 0);
}
fn tell() -> uint {
ret os::libc::ftell(f) as uint;
- }drop { if (must_close) { os::libc::fclose(f); } }
+ }drop { if must_close { os::libc::fclose(f); } }
}
-obj fd_buf_writer(int fd, bool must_close) {
- fn write(vec[u8] v) {
- auto len = vec::len[u8](v);
- auto count = 0u;
- auto vbuf;
- while (count < len) {
+obj fd_buf_writer(fd: int, must_close: bool) {
+ fn write(v: vec[u8]) {
+ let len = vec::len[u8](v);
+ let count = 0u;
+ let vbuf;
+ while count < len {
vbuf = vec::buf_off[u8](v, count);
- auto nout = os::libc::write(fd, vbuf, len);
- if (nout < 0) {
+ let nout = os::libc::write(fd, vbuf, len);
+ if nout < 0 {
log_err "error dumping buffer";
log_err sys::rustrt::last_os_error();
fail;
@@ -269,32 +267,32 @@
count += nout as uint;
}
}
- fn seek(int offset, seek_style whence) {
+ fn seek(offset: int, whence: seek_style) {
log_err "need 64-bit native calls for seek, sorry";
fail;
}
fn tell() -> uint {
log_err "need 64-bit native calls for tell, sorry";
fail;
- }drop { if (must_close) { os::libc::close(fd); } }
+ }drop { if must_close { os::libc::close(fd); } }
}
-fn file_buf_writer(str path, vec[fileflag] flags) -> buf_writer {
- let int fflags =
+fn file_buf_writer(path: str, flags: vec[fileflag]) -> buf_writer {
+ let fflags: int =
os::libc_constants::O_WRONLY() | os::libc_constants::O_BINARY();
- for (fileflag f in flags) {
- alt (f) {
- case (append) { fflags |= os::libc_constants::O_APPEND(); }
- case (create) { fflags |= os::libc_constants::O_CREAT(); }
- case (truncate) { fflags |= os::libc_constants::O_TRUNC(); }
- case (none) { }
+ for f: fileflag in flags {
+ alt f {
+ append. { fflags |= os::libc_constants::O_APPEND(); }
+ create. { fflags |= os::libc_constants::O_CREAT(); }
+ truncate. { fflags |= os::libc_constants::O_TRUNC(); }
+ none. { }
}
}
- auto fd =
+ let fd =
os::libc::open(str::buf(path), fflags,
os::libc_constants::S_IRUSR() |
os::libc_constants::S_IWUSR());
- if (fd < 0) {
+ if fd < 0 {
log_err "error opening file for writing";
log_err sys::rustrt::last_os_error();
fail;
@@ -303,12 +301,12 @@
}
type writer =
+
+ // write_str will continue to do utf-8 output only. an alternative
+ // function will be provided for general encoded string output
obj {
fn get_buf_writer() -> buf_writer ;
-
- // write_str will continue to do utf-8 output only. an alternative
- // function will be provided for general encoded string output
- fn write_str(str) ;
+ fn write_str(str) ;
fn write_line(str) ;
fn write_char(char) ;
fn write_int(int) ;
@@ -319,58 +317,58 @@
fn write_be_uint(uint, uint) ;
};
-fn uint_to_le_bytes(uint n, uint size) -> vec[u8] {
- let vec[u8] bytes = [];
- while (size > 0u) { bytes += [n & 255u as u8]; n >>= 8u; size -= 1u; }
+fn uint_to_le_bytes(n: uint, size: uint) -> vec[u8] {
+ let bytes: vec[u8] = [];
+ while size > 0u { bytes += [n & 255u as u8]; n >>= 8u; size -= 1u; }
ret bytes;
}
-fn uint_to_be_bytes(uint n, uint size) -> vec[u8] {
- let vec[u8] bytes = [];
- auto i = size - 1u as int;
- while (i >= 0) { bytes += [n >> (i * 8 as uint) & 255u as u8]; i -= 1; }
+fn uint_to_be_bytes(n: uint, size: uint) -> vec[u8] {
+ let bytes: vec[u8] = [];
+ let i = size - 1u as int;
+ while i >= 0 { bytes += [n >> (i * 8 as uint) & 255u as u8]; i -= 1; }
ret bytes;
}
-obj new_writer(buf_writer out) {
+obj new_writer(out: buf_writer) {
fn get_buf_writer() -> buf_writer { ret out; }
- fn write_str(str s) { out.write(str::bytes(s)); }
- fn write_line(str s) {
+ fn write_str(s: str) { out.write(str::bytes(s)); }
+ fn write_line(s: str) {
out.write(str::bytes(s));
out.write(str::bytes("\n"));
}
- fn write_char(char ch) {
+ fn write_char(ch: char) {
// FIXME needlessly consy
out.write(str::bytes(str::from_char(ch)));
}
- fn write_int(int n) { out.write(str::bytes(int::to_str(n, 10u))); }
- fn write_uint(uint n) { out.write(str::bytes(uint::to_str(n, 10u))); }
- fn write_bytes(vec[u8] bytes) { out.write(bytes); }
- fn write_le_uint(uint n, uint size) {
+ fn write_int(n: int) { out.write(str::bytes(int::to_str(n, 10u))); }
+ fn write_uint(n: uint) { out.write(str::bytes(uint::to_str(n, 10u))); }
+ fn write_bytes(bytes: vec[u8]) { out.write(bytes); }
+ fn write_le_uint(n: uint, size: uint) {
out.write(uint_to_le_bytes(n, size));
}
- fn write_le_int(int n, uint size) {
+ fn write_le_int(n: int, size: uint) {
out.write(uint_to_le_bytes(n as uint, size));
}
- fn write_be_uint(uint n, uint size) {
+ fn write_be_uint(n: uint, size: uint) {
out.write(uint_to_be_bytes(n, size));
}
}
// FIXME: Remove me once objects are exported.
-fn new_writer_(buf_writer out) -> writer { ret new_writer(out); }
+fn new_writer_(out: buf_writer) -> writer { ret new_writer(out); }
-fn file_writer(str path, vec[fileflag] flags) -> writer {
+fn file_writer(path: str, flags: vec[fileflag]) -> writer {
ret new_writer(file_buf_writer(path, flags));
}
// FIXME: fileflags
-fn buffered_file_buf_writer(str path) -> buf_writer {
- auto f = os::libc::fopen(str::buf(path), str::buf("w"));
- if (f as uint == 0u) { log_err "error opening " + path; fail; }
+fn buffered_file_buf_writer(path: str) -> buf_writer {
+ let f = os::libc::fopen(str::buf(path), str::buf("w"));
+ if f as uint == 0u { log_err "error opening " + path; fail; }
ret FILE_writer(f, true);
}
@@ -384,37 +382,37 @@
fn get_str() -> str ;
};
-type mutable_byte_buf = @rec(mutable vec[mutable u8] buf, mutable uint pos);
+type mutable_byte_buf = @{mutable buf: vec[mutable u8], mutable pos: uint};
-obj byte_buf_writer(mutable_byte_buf buf) {
- fn write(vec[u8] v) {
+obj byte_buf_writer(buf: mutable_byte_buf) {
+ fn write(v: vec[u8]) {
// Fast path.
- if (buf.pos == vec::len(buf.buf)) {
+ if buf.pos == vec::len(buf.buf) {
// FIXME: Fix our type system. There's no reason you shouldn't be
// able to add a mutable vector to an immutable one.
- auto mv = vec::rustrt::unsafe_vec_to_mut[u8](v);
+ let mv = vec::rustrt::unsafe_vec_to_mut[u8](v);
buf.buf += mv;
buf.pos += vec::len[u8](v);
ret;
}
// FIXME: Optimize: These should be unique pointers.
- auto vlen = vec::len[u8](v);
- auto vpos = 0u;
- while (vpos < vlen) {
- auto b = v.(vpos);
- if (buf.pos == vec::len(buf.buf)) {
+ let vlen = vec::len[u8](v);
+ let vpos = 0u;
+ while vpos < vlen {
+ let b = v.(vpos);
+ if buf.pos == vec::len(buf.buf) {
buf.buf += [mutable b];
} else { buf.buf.(buf.pos) = b; }
buf.pos += 1u;
vpos += 1u;
}
}
- fn seek(int offset, seek_style whence) {
- auto pos = buf.pos;
- auto len = vec::len(buf.buf);
+ fn seek(offset: int, whence: seek_style) {
+ let pos = buf.pos;
+ let len = vec::len(buf.buf);
buf.pos = seek_in_buf(offset, pos, len, whence);
}
fn tell() -> uint { ret buf.pos; }
@@ -423,10 +421,10 @@
fn string_writer() -> str_writer {
// FIXME: yikes, this is bad. Needs fixing of mutable syntax.
- let vec[mutable u8] b = [mutable 0u8];
+ let b: vec[mutable u8] = [mutable 0u8];
vec::pop(b);
- let mutable_byte_buf buf = @rec(mutable buf=b, mutable pos=0u);
- obj str_writer_wrap(writer wr, mutable_byte_buf buf) {
+ let buf: mutable_byte_buf = @{mutable buf: b, mutable pos: 0u};
+ obj str_writer_wrap(wr: writer, buf: mutable_byte_buf) {
fn get_writer() -> writer { ret wr; }
fn get_str() -> str { ret str::unsafe_from_bytes(buf.buf); }
}
@@ -435,15 +433,16 @@
// Utility functions
-fn seek_in_buf(int offset, uint pos, uint len, seek_style whence) -> uint {
- auto bpos = pos as int;
- auto blen = len as int;
- alt (whence) {
- case (seek_set) { bpos = offset; }
- case (seek_cur) { bpos += offset; }
- case (seek_end) { bpos = blen + offset; }
+fn seek_in_buf(offset: int, pos: uint, len: uint, whence: seek_style) ->
+ uint {
+ let bpos = pos as int;
+ let blen = len as int;
+ alt whence {
+ seek_set. { bpos = offset; }
+ seek_cur. { bpos += offset; }
+ seek_end. { bpos = blen + offset; }
}
- if (bpos < 0) { bpos = 0; } else if (bpos > blen) { bpos = blen; }
+ if bpos < 0 { bpos = 0; } else if (bpos > blen) { bpos = blen; }
ret bpos as uint;
}
//
diff --git a/src/lib/ioivec.rs b/src/lib/ioivec.rs
index ce1b1ee..548a405 100644
--- a/src/lib/ioivec.rs
+++ b/src/lib/ioivec.rs
@@ -15,25 +15,27 @@
// The raw underlying reader class. All readers must implement this.
type buf_reader =
+
+ // FIXME: Seekable really should be orthogonal. We will need
+ // inheritance.
obj {
fn read(uint) -> u8[] ;
fn read_byte() -> int ;
fn unread_byte(int) ;
fn eof() -> bool ;
-
- // FIXME: Seekable really should be orthogonal. We will need
- // inheritance.
- fn seek(int, seek_style) ;
+ fn seek(int, seek_style) ;
fn tell() -> uint ;
};
// Convenience methods for reading.
type reader =
- obj {
- // FIXME: This should inherit from buf_reader.
- fn get_buf_reader() -> buf_reader ;
+ // FIXME: This should inherit from buf_reader.
+ // FIXME: eventually u64
+
+ obj {
+ fn get_buf_reader() -> buf_reader ;
fn read_byte() -> int ;
fn unread_byte(int) ;
fn read_bytes(uint) -> u8[] ;
@@ -46,58 +48,53 @@
fn read_be_uint(uint) -> uint ;
fn read_whole_stream() -> u8[] ;
fn seek(int, seek_style) ;
- fn tell() -> uint ; // FIXME: eventually u64
-
+ fn tell() -> uint ;
};
-fn convert_whence(seek_style whence) -> int {
- ret alt (whence) {
- case (seek_set) { 0 }
- case (seek_cur) { 1 }
- case (seek_end) { 2 }
- };
+fn convert_whence(whence: seek_style) -> int {
+ ret alt whence { seek_set. { 0 } seek_cur. { 1 } seek_end. { 2 } };
}
-obj FILE_buf_reader(os::libc::FILE f, bool must_close) {
- fn read(uint len) -> u8[] {
- auto buf = ~[];
+obj FILE_buf_reader(f: os::libc::FILE, must_close: bool) {
+ fn read(len: uint) -> u8[] {
+ let buf = ~[];
ivec::reserve[u8](buf, len);
- auto read = os::libc_ivec::fread(ivec::to_ptr[u8](buf), 1u, len, f);
+ let read = os::libc_ivec::fread(ivec::to_ptr[u8](buf), 1u, len, f);
ivec::unsafe::set_len[u8](buf, read);
ret buf;
}
fn read_byte() -> int { ret os::libc::fgetc(f); }
- fn unread_byte(int byte) { os::libc::ungetc(byte, f); }
+ fn unread_byte(byte: int) { os::libc::ungetc(byte, f); }
fn eof() -> bool { ret os::libc::feof(f) != 0; }
- fn seek(int offset, seek_style whence) {
+ fn seek(offset: int, whence: seek_style) {
assert (os::libc::fseek(f, offset, convert_whence(whence)) == 0);
}
fn tell() -> uint {
ret os::libc::ftell(f) as uint;
- }drop { if (must_close) { os::libc::fclose(f); } }
+ }drop { if must_close { os::libc::fclose(f); } }
}
// FIXME: Convert this into pseudomethods on buf_reader.
-obj new_reader(buf_reader rdr) {
+obj new_reader(rdr: buf_reader) {
fn get_buf_reader() -> buf_reader { ret rdr; }
fn read_byte() -> int { ret rdr.read_byte(); }
- fn unread_byte(int byte) { ret rdr.unread_byte(byte); }
- fn read_bytes(uint len) -> u8[] { ret rdr.read(len); }
+ fn unread_byte(byte: int) { ret rdr.unread_byte(byte); }
+ fn read_bytes(len: uint) -> u8[] { ret rdr.read(len); }
fn read_char() -> char {
- auto c0 = rdr.read_byte();
- if (c0 == -1) {
+ let c0 = rdr.read_byte();
+ if c0 == -1 {
ret -1 as char; // FIXME will this stay valid?
}
- auto b0 = c0 as u8;
- auto w = str::utf8_char_width(b0);
+ let b0 = c0 as u8;
+ let w = str::utf8_char_width(b0);
assert (w > 0u);
- if (w == 1u) { ret b0 as char; }
- auto val = 0u;
- while (w > 1u) {
+ if w == 1u { ret b0 as char; }
+ let val = 0u;
+ while w > 1u {
w -= 1u;
- auto next = rdr.read_byte();
+ let next = rdr.read_byte();
assert (next > -1);
assert (next & 192 == 128);
val <<= 6u;
@@ -110,45 +107,43 @@
}
fn eof() -> bool { ret rdr.eof(); }
fn read_line() -> str {
- let u8[] buf = ~[];
+ let buf: u8[] = ~[];
// No break yet in rustc
- auto go_on = true;
- while (go_on) {
- auto ch = rdr.read_byte();
- if (ch == -1 || ch == 10) {
+ let go_on = true;
+ while go_on {
+ let ch = rdr.read_byte();
+ if ch == -1 || ch == 10 {
go_on = false;
} else { buf += ~[ch as u8]; }
}
ret str::unsafe_from_bytes_ivec(buf);
}
fn read_c_str() -> str {
- let u8[] buf = ~[];
- auto go_on = true;
- while (go_on) {
- auto ch = rdr.read_byte();
- if (ch < 1) {
- go_on = false;
- } else { buf += ~[ch as u8]; }
+ let buf: u8[] = ~[];
+ let go_on = true;
+ while go_on {
+ let ch = rdr.read_byte();
+ if ch < 1 { go_on = false; } else { buf += ~[ch as u8]; }
}
ret str::unsafe_from_bytes_ivec(buf);
}
// FIXME deal with eof?
- fn read_le_uint(uint size) -> uint {
- auto val = 0u;
- auto pos = 0u;
- while (size > 0u) {
+ fn read_le_uint(size: uint) -> uint {
+ let val = 0u;
+ let pos = 0u;
+ while size > 0u {
val += (rdr.read_byte() as uint) << pos;
pos += 8u;
size -= 1u;
}
ret val;
}
- fn read_le_int(uint size) -> int {
- auto val = 0u;
- auto pos = 0u;
- while (size > 0u) {
+ fn read_le_int(size: uint) -> int {
+ let val = 0u;
+ let pos = 0u;
+ while size > 0u {
val += (rdr.read_byte() as uint) << pos;
pos += 8u;
size -= 1u;
@@ -157,21 +152,21 @@
}
// FIXME deal with eof?
- fn read_be_uint(uint sz) -> uint {
- auto val = 0u;
+ fn read_be_uint(sz: uint) -> uint {
+ let val = 0u;
- while (sz > 0u) {
+ while sz > 0u {
sz -= 1u;
val += (rdr.read_byte() as uint) << sz * 8u;
}
ret val;
}
fn read_whole_stream() -> u8[] {
- let u8[] buf = ~[];
- while (!rdr.eof()) { buf += rdr.read(2048u); }
+ let buf: u8[] = ~[];
+ while !rdr.eof() { buf += rdr.read(2048u); }
ret buf;
}
- fn seek(int offset, seek_style whence) { ret rdr.seek(offset, whence); }
+ fn seek(offset: int, whence: seek_style) { ret rdr.seek(offset, whence); }
fn tell() -> uint { ret rdr.tell(); }
}
@@ -179,52 +174,52 @@
ret new_reader(FILE_buf_reader(rustrt::rust_get_stdin(), false));
}
-fn file_reader(str path) -> reader {
- auto f = os::libc::fopen(str::buf(path), str::buf("r"));
- if (f as uint == 0u) { log_err "error opening " + path; fail; }
+fn file_reader(path: str) -> reader {
+ let f = os::libc::fopen(str::buf(path), str::buf("r"));
+ if f as uint == 0u { log_err "error opening " + path; fail; }
ret new_reader(FILE_buf_reader(f, true));
}
// FIXME: Remove me once objects are exported.
-fn new_reader_(buf_reader bufr) -> reader { ret new_reader(bufr); }
+fn new_reader_(bufr: buf_reader) -> reader { ret new_reader(bufr); }
// Byte buffer readers
// TODO: mutable? u8, but this fails with rustboot.
-type byte_buf = @rec(u8[] buf, mutable uint pos);
+type byte_buf = @{buf: u8[], mutable pos: uint};
-obj byte_buf_reader(byte_buf bbuf) {
- fn read(uint len) -> u8[] {
- auto rest = ivec::len[u8](bbuf.buf) - bbuf.pos;
- auto to_read = len;
- if (rest < to_read) { to_read = rest; }
- auto range = ivec::slice[u8](bbuf.buf, bbuf.pos, bbuf.pos + to_read);
+obj byte_buf_reader(bbuf: byte_buf) {
+ fn read(len: uint) -> u8[] {
+ let rest = ivec::len[u8](bbuf.buf) - bbuf.pos;
+ let to_read = len;
+ if rest < to_read { to_read = rest; }
+ let range = ivec::slice[u8](bbuf.buf, bbuf.pos, bbuf.pos + to_read);
bbuf.pos += to_read;
ret range;
}
fn read_byte() -> int {
- if (bbuf.pos == ivec::len[u8](bbuf.buf)) { ret -1; }
- auto b = bbuf.buf.(bbuf.pos);
+ if bbuf.pos == ivec::len[u8](bbuf.buf) { ret -1; }
+ let b = bbuf.buf.(bbuf.pos);
bbuf.pos += 1u;
ret b as int;
}
- fn unread_byte(int byte) { log_err "TODO: unread_byte"; fail; }
+ fn unread_byte(byte: int) { log_err "TODO: unread_byte"; fail; }
fn eof() -> bool { ret bbuf.pos == ivec::len[u8](bbuf.buf); }
- fn seek(int offset, seek_style whence) {
- auto pos = bbuf.pos;
- auto len = ivec::len[u8](bbuf.buf);
+ fn seek(offset: int, whence: seek_style) {
+ let pos = bbuf.pos;
+ let len = ivec::len[u8](bbuf.buf);
bbuf.pos = seek_in_buf(offset, pos, len, whence);
}
fn tell() -> uint { ret bbuf.pos; }
}
-fn new_byte_buf_reader(&u8[] buf) -> buf_reader {
- ret byte_buf_reader(@rec(buf=buf, mutable pos=0u));
+fn new_byte_buf_reader(buf: &u8[]) -> buf_reader {
+ ret byte_buf_reader(@{buf: buf, mutable pos: 0u});
}
-fn string_reader(&str s) -> reader {
+fn string_reader(s: &str) -> reader {
ret new_reader(new_byte_buf_reader(str::bytes_ivec(s)));
}
@@ -233,40 +228,41 @@
tag fileflag { append; create; truncate; none; }
type buf_writer =
+
+ // FIXME: Seekable really should be orthogonal. We will need
+ // inheritance.
+ // FIXME: eventually u64
+
obj {
fn write(&u8[]) ;
-
- // FIXME: Seekable really should be orthogonal. We will need
- // inheritance.
- fn seek(int, seek_style) ;
- fn tell() -> uint ; // FIXME: eventually u64
-
+ fn seek(int, seek_style) ;
+ fn tell() -> uint ;
};
-obj FILE_writer(os::libc::FILE f, bool must_close) {
- fn write(&u8[] v) {
- auto len = ivec::len[u8](v);
- auto vbuf = ivec::to_ptr[u8](v);
- auto nout = os::libc_ivec::fwrite(vbuf, len, 1u, f);
- if (nout < 1u) { log_err "error dumping buffer"; }
+obj FILE_writer(f: os::libc::FILE, must_close: bool) {
+ fn write(v: &u8[]) {
+ let len = ivec::len[u8](v);
+ let vbuf = ivec::to_ptr[u8](v);
+ let nout = os::libc_ivec::fwrite(vbuf, len, 1u, f);
+ if nout < 1u { log_err "error dumping buffer"; }
}
- fn seek(int offset, seek_style whence) {
+ fn seek(offset: int, whence: seek_style) {
assert (os::libc::fseek(f, offset, convert_whence(whence)) == 0);
}
fn tell() -> uint {
ret os::libc::ftell(f) as uint;
- }drop { if (must_close) { os::libc::fclose(f); } }
+ }drop { if must_close { os::libc::fclose(f); } }
}
-obj fd_buf_writer(int fd, bool must_close) {
- fn write(&u8[] v) {
- auto len = ivec::len[u8](v);
- auto count = 0u;
- auto vbuf;
- while (count < len) {
+obj fd_buf_writer(fd: int, must_close: bool) {
+ fn write(v: &u8[]) {
+ let len = ivec::len[u8](v);
+ let count = 0u;
+ let vbuf;
+ while count < len {
vbuf = ptr::offset(ivec::to_ptr[u8](v), count);
- auto nout = os::libc_ivec::write(fd, vbuf, len);
- if (nout < 0) {
+ let nout = os::libc_ivec::write(fd, vbuf, len);
+ if nout < 0 {
log_err "error dumping buffer";
log_err sys::rustrt::last_os_error();
fail;
@@ -274,32 +270,32 @@
count += nout as uint;
}
}
- fn seek(int offset, seek_style whence) {
+ fn seek(offset: int, whence: seek_style) {
log_err "need 64-bit native calls for seek, sorry";
fail;
}
fn tell() -> uint {
log_err "need 64-bit native calls for tell, sorry";
fail;
- }drop { if (must_close) { os::libc::close(fd); } }
+ }drop { if must_close { os::libc::close(fd); } }
}
-fn file_buf_writer(str path, &fileflag[] flags) -> buf_writer {
- let int fflags =
+fn file_buf_writer(path: str, flags: &fileflag[]) -> buf_writer {
+ let fflags: int =
os::libc_constants::O_WRONLY() | os::libc_constants::O_BINARY();
- for (fileflag f in flags) {
- alt (f) {
- case (append) { fflags |= os::libc_constants::O_APPEND(); }
- case (create) { fflags |= os::libc_constants::O_CREAT(); }
- case (truncate) { fflags |= os::libc_constants::O_TRUNC(); }
- case (none) { }
+ for f: fileflag in flags {
+ alt f {
+ append. { fflags |= os::libc_constants::O_APPEND(); }
+ create. { fflags |= os::libc_constants::O_CREAT(); }
+ truncate. { fflags |= os::libc_constants::O_TRUNC(); }
+ none. { }
}
}
- auto fd =
+ let fd =
os::libc::open(str::buf(path), fflags,
os::libc_constants::S_IRUSR() |
os::libc_constants::S_IWUSR());
- if (fd < 0) {
+ if fd < 0 {
log_err "error opening file for writing";
log_err sys::rustrt::last_os_error();
fail;
@@ -308,12 +304,12 @@
}
type writer =
+
+ // write_str will continue to do utf-8 output only. an alternative
+ // function will be provided for general encoded string output
obj {
fn get_buf_writer() -> buf_writer ;
-
- // write_str will continue to do utf-8 output only. an alternative
- // function will be provided for general encoded string output
- fn write_str(str) ;
+ fn write_str(str) ;
fn write_line(str) ;
fn write_char(char) ;
fn write_int(int) ;
@@ -324,60 +320,60 @@
fn write_be_uint(uint, uint) ;
};
-fn uint_to_le_bytes(uint n, uint size) -> u8[] {
- let u8[] bytes = ~[];
- while (size > 0u) { bytes += ~[n & 255u as u8]; n >>= 8u; size -= 1u; }
+fn uint_to_le_bytes(n: uint, size: uint) -> u8[] {
+ let bytes: u8[] = ~[];
+ while size > 0u { bytes += ~[n & 255u as u8]; n >>= 8u; size -= 1u; }
ret bytes;
}
-fn uint_to_be_bytes(uint n, uint size) -> u8[] {
- let u8[] bytes = ~[];
- auto i = size - 1u as int;
- while (i >= 0) { bytes += ~[n >> (i * 8 as uint) & 255u as u8]; i -= 1; }
+fn uint_to_be_bytes(n: uint, size: uint) -> u8[] {
+ let bytes: u8[] = ~[];
+ let i = size - 1u as int;
+ while i >= 0 { bytes += ~[n >> (i * 8 as uint) & 255u as u8]; i -= 1; }
ret bytes;
}
-obj new_writer(buf_writer out) {
+obj new_writer(out: buf_writer) {
fn get_buf_writer() -> buf_writer { ret out; }
- fn write_str(str s) { out.write(str::bytes_ivec(s)); }
- fn write_line(str s) {
+ fn write_str(s: str) { out.write(str::bytes_ivec(s)); }
+ fn write_line(s: str) {
out.write(str::bytes_ivec(s));
out.write(str::bytes_ivec("\n"));
}
- fn write_char(char ch) {
+ fn write_char(ch: char) {
// FIXME needlessly consy
out.write(str::bytes_ivec(str::from_char(ch)));
}
- fn write_int(int n) { out.write(str::bytes_ivec(int::to_str(n, 10u))); }
- fn write_uint(uint n) {
+ fn write_int(n: int) { out.write(str::bytes_ivec(int::to_str(n, 10u))); }
+ fn write_uint(n: uint) {
out.write(str::bytes_ivec(uint::to_str(n, 10u)));
}
- fn write_bytes(&u8[] bytes) { out.write(bytes); }
- fn write_le_uint(uint n, uint size) {
+ fn write_bytes(bytes: &u8[]) { out.write(bytes); }
+ fn write_le_uint(n: uint, size: uint) {
out.write(uint_to_le_bytes(n, size));
}
- fn write_le_int(int n, uint size) {
+ fn write_le_int(n: int, size: uint) {
out.write(uint_to_le_bytes(n as uint, size));
}
- fn write_be_uint(uint n, uint size) {
+ fn write_be_uint(n: uint, size: uint) {
out.write(uint_to_be_bytes(n, size));
}
}
// FIXME: Remove me once objects are exported.
-fn new_writer_(buf_writer out) -> writer { ret new_writer(out); }
+fn new_writer_(out: buf_writer) -> writer { ret new_writer(out); }
-fn file_writer(str path, &fileflag[] flags) -> writer {
+fn file_writer(path: str, flags: &fileflag[]) -> writer {
ret new_writer(file_buf_writer(path, flags));
}
// FIXME: fileflags
-fn buffered_file_buf_writer(str path) -> buf_writer {
- auto f = os::libc::fopen(str::buf(path), str::buf("w"));
- if (f as uint == 0u) { log_err "error opening " + path; fail; }
+fn buffered_file_buf_writer(path: str) -> buf_writer {
+ let f = os::libc::fopen(str::buf(path), str::buf("w"));
+ if f as uint == 0u { log_err "error opening " + path; fail; }
ret FILE_writer(f, true);
}
@@ -391,33 +387,33 @@
fn get_str() -> str ;
};
-type mutable_byte_buf = @rec(mutable u8[mutable] buf, mutable uint pos);
+type mutable_byte_buf = @{mutable buf: u8[mutable ], mutable pos: uint};
-obj byte_buf_writer(mutable_byte_buf buf) {
- fn write(&u8[] v) {
+obj byte_buf_writer(buf: mutable_byte_buf) {
+ fn write(v: &u8[]) {
// Fast path.
- if (buf.pos == ivec::len(buf.buf)) {
- for (u8 b in v) { buf.buf += ~[mutable b]; }
+ if buf.pos == ivec::len(buf.buf) {
+ for b: u8 in v { buf.buf += ~[mutable b]; }
buf.pos += ivec::len[u8](v);
ret;
}
// FIXME: Optimize: These should be unique pointers.
- auto vlen = ivec::len[u8](v);
- auto vpos = 0u;
- while (vpos < vlen) {
- auto b = v.(vpos);
- if (buf.pos == ivec::len(buf.buf)) {
+ let vlen = ivec::len[u8](v);
+ let vpos = 0u;
+ while vpos < vlen {
+ let b = v.(vpos);
+ if buf.pos == ivec::len(buf.buf) {
buf.buf += ~[mutable b];
} else { buf.buf.(buf.pos) = b; }
buf.pos += 1u;
vpos += 1u;
}
}
- fn seek(int offset, seek_style whence) {
- auto pos = buf.pos;
- auto len = ivec::len(buf.buf);
+ fn seek(offset: int, whence: seek_style) {
+ let pos = buf.pos;
+ let len = ivec::len(buf.buf);
buf.pos = seek_in_buf(offset, pos, len, whence);
}
fn tell() -> uint { ret buf.pos; }
@@ -426,10 +422,10 @@
fn string_writer() -> str_writer {
// FIXME: yikes, this is bad. Needs fixing of mutable syntax.
- let u8[mutable] b = ~[mutable 0u8];
+ let b: u8[mutable ] = ~[mutable 0u8];
ivec::pop(b);
- let mutable_byte_buf buf = @rec(mutable buf=b, mutable pos=0u);
- obj str_writer_wrap(writer wr, mutable_byte_buf buf) {
+ let buf: mutable_byte_buf = @{mutable buf: b, mutable pos: 0u};
+ obj str_writer_wrap(wr: writer, buf: mutable_byte_buf) {
fn get_writer() -> writer { ret wr; }
fn get_str() -> str { ret str::unsafe_from_bytes_ivec(buf.buf); }
}
@@ -438,15 +434,16 @@
// Utility functions
-fn seek_in_buf(int offset, uint pos, uint len, seek_style whence) -> uint {
- auto bpos = pos as int;
- auto blen = len as int;
- alt (whence) {
- case (seek_set) { bpos = offset; }
- case (seek_cur) { bpos += offset; }
- case (seek_end) { bpos = blen + offset; }
+fn seek_in_buf(offset: int, pos: uint, len: uint, whence: seek_style) ->
+ uint {
+ let bpos = pos as int;
+ let blen = len as int;
+ alt whence {
+ seek_set. { bpos = offset; }
+ seek_cur. { bpos += offset; }
+ seek_end. { bpos = blen + offset; }
}
- if (bpos < 0) { bpos = 0; } else if (bpos > blen) { bpos = blen; }
+ if bpos < 0 { bpos = 0; } else if (bpos > blen) { bpos = blen; }
ret bpos as uint;
}
//
diff --git a/src/lib/ivec.rs b/src/lib/ivec.rs
index 78869c5..71dc9cf 100644
--- a/src/lib/ivec.rs
+++ b/src/lib/ivec.rs
@@ -5,139 +5,121 @@
import uint::next_power_of_two;
import ptr::addr_of;
-type operator2[T,U,V] = fn(&T, &U) -> V;
+type operator2[T, U, V] = fn(&T, &U) -> V ;
native "rust-intrinsic" mod rusti {
- fn ivec_len[T](&T[] v) -> uint;
+ fn ivec_len[T](v: &T[]) -> uint;
}
native "rust" mod rustrt {
- fn ivec_reserve_shared[T](&mutable T[mutable?] v, uint n);
- fn ivec_on_heap[T](&T[] v) -> uint;
- fn ivec_to_ptr[T](&T[] v) -> *T;
- fn ivec_copy_from_buf_shared[T](&mutable T[mutable?] v,
- *T ptr, uint count);
+ fn ivec_reserve_shared[T](v: &mutable T[mutable? ], n: uint);
+ fn ivec_on_heap[T](v: &T[]) -> uint;
+ fn ivec_to_ptr[T](v: &T[]) -> *T;
+ fn ivec_copy_from_buf_shared[T](v: &mutable T[mutable? ], ptr: *T,
+ count: uint);
}
/// Reserves space for `n` elements in the given vector.
-fn reserve[T](&mutable T[mutable?] v, uint n) {
+fn reserve[T](v: &mutable T[mutable? ], n: uint) {
rustrt::ivec_reserve_shared(v, n);
}
-fn on_heap[T](&T[] v) -> bool {
- ret rustrt::ivec_on_heap(v) != 0u;
-}
+fn on_heap[T](v: &T[]) -> bool { ret rustrt::ivec_on_heap(v) != 0u; }
-fn to_ptr[T](&T[] v) -> *T {
- ret rustrt::ivec_to_ptr(v);
-}
+fn to_ptr[T](v: &T[]) -> *T { ret rustrt::ivec_to_ptr(v); }
-fn len[T](&T[mutable?] v) -> uint {
- ret rusti::ivec_len(v);
-}
+fn len[T](v: &T[mutable? ]) -> uint { ret rusti::ivec_len(v); }
-type init_op[T] = fn(uint) -> T;
+type init_op[T] = fn(uint) -> T ;
-fn init_fn[T](&init_op[T] op, uint n_elts) -> T[] {
- auto v = ~[];
+fn init_fn[T](op: &init_op[T], n_elts: uint) -> T[] {
+ let v = ~[];
reserve(v, n_elts);
- let uint i = 0u;
- while (i < n_elts) { v += ~[op(i)]; i += 1u; }
+ let i: uint = 0u;
+ while i < n_elts { v += ~[op(i)]; i += 1u; }
ret v;
}
// TODO: Remove me once we have slots.
-fn init_fn_mut[T](&init_op[T] op, uint n_elts) -> T[mutable] {
- auto v = ~[mutable];
+fn init_fn_mut[T](op: &init_op[T], n_elts: uint) -> T[mutable ] {
+ let v = ~[mutable ];
reserve(v, n_elts);
- let uint i = 0u;
- while (i < n_elts) { v += ~[mutable op(i)]; i += 1u; }
+ let i: uint = 0u;
+ while i < n_elts { v += ~[mutable op(i)]; i += 1u; }
ret v;
}
-fn init_elt[T](&T t, uint n_elts) -> T[] {
- auto v = ~[];
+fn init_elt[T](t: &T, n_elts: uint) -> T[] {
+ let v = ~[];
reserve(v, n_elts);
- let uint i = 0u;
- while (i < n_elts) { v += ~[t]; i += 1u; }
+ let i: uint = 0u;
+ while i < n_elts { v += ~[t]; i += 1u; }
ret v;
}
// TODO: Remove me once we have slots.
-fn init_elt_mut[T](&T t, uint n_elts) -> T[mutable] {
- auto v = ~[mutable];
+fn init_elt_mut[T](t: &T, n_elts: uint) -> T[mutable ] {
+ let v = ~[mutable ];
reserve(v, n_elts);
- let uint i = 0u;
- while (i < n_elts) { v += ~[mutable t]; i += 1u; }
+ let i: uint = 0u;
+ while i < n_elts { v += ~[mutable t]; i += 1u; }
ret v;
}
-fn to_mut[T](&T[] v) -> T[mutable] {
- auto vres = ~[mutable];
- for (T t in v) {
- vres += ~[mutable t];
- }
+fn to_mut[T](v: &T[]) -> T[mutable ] {
+ let vres = ~[mutable ];
+ for t: T in v { vres += ~[mutable t]; }
ret vres;
}
-fn from_mut[T](&T[mutable] v) -> T[] {
- auto vres = ~[];
- for (T t in v) {
- vres += ~[t];
- }
+fn from_mut[T](v: &T[mutable ]) -> T[] {
+ let vres = ~[];
+ for t: T in v { vres += ~[t]; }
ret vres;
}
// Predicates
-pred is_empty[T](&T[mutable?] v) -> bool {
+pred is_empty[T](v: &T[mutable? ]) -> bool {
// FIXME: This would be easier if we could just call len
- for (T t in v) {
- ret false;
- }
+ for t: T in v { ret false; }
ret true;
}
-pred is_not_empty[T](&T[mutable?] v) -> bool {
- ret !is_empty(v);
-}
+pred is_not_empty[T](v: &T[mutable? ]) -> bool { ret !is_empty(v); }
// Accessors
/// Returns the first element of a vector
-fn head[T](&T[mutable?] v) : is_not_empty(v) -> T {
- ret v.(0);
-}
+fn head[T](v: &T[mutable? ]) -> T { ret v.(0); }
/// Returns all but the first element of a vector
-fn tail[T](&T[mutable?] v) : is_not_empty(v) -> T[mutable?] {
- ret slice(v, 1u, len(v));
-}
+fn tail[T](v: &T[mutable? ]) -> T[mutable? ] { ret slice(v, 1u, len(v)); }
/// Returns the last element of `v`.
-fn last[T](&T[mutable?] v) -> option::t[T] {
- if (len(v) == 0u) { ret none; }
+fn last[T](v: &T[mutable? ]) -> option::t[T] {
+ if len(v) == 0u { ret none; }
ret some(v.(len(v) - 1u));
}
/// Returns a copy of the elements from [`start`..`end`) from `v`.
-fn slice[T](&T[mutable?] v, uint start, uint end) -> T[] {
+fn slice[T](v: &T[mutable? ], start: uint, end: uint) -> T[] {
assert (start <= end);
assert (end <= len(v));
- auto result = ~[];
+ let result = ~[];
reserve(result, end - start);
- auto i = start;
- while (i < end) { result += ~[v.(i)]; i += 1u; }
+ let i = start;
+ while i < end { result += ~[v.(i)]; i += 1u; }
ret result;
}
// TODO: Remove me once we have slots.
-fn slice_mut[T](&T[mutable?] v, uint start, uint end) -> T[mutable] {
+fn slice_mut[T](v: &T[mutable? ], start: uint, end: uint) -> T[mutable ] {
assert (start <= end);
assert (end <= len(v));
- auto result = ~[mutable];
+ let result = ~[mutable ];
reserve(result, end - start);
- auto i = start;
- while (i < end) { result += ~[mutable v.(i)]; i += 1u; }
+ let i = start;
+ while i < end { result += ~[mutable v.(i)]; i += 1u; }
ret result;
}
@@ -145,11 +127,11 @@
// Mutators
// TODO: Write this, unsafely, in a way that's not O(n).
-fn pop[T](&mutable T[mutable?] v) -> T {
- auto ln = len(v);
+fn pop[T](v: &mutable T[mutable? ]) -> T {
+ let ln = len(v);
assert (ln > 0u);
ln -= 1u;
- auto e = v.(ln);
+ let e = v.(ln);
v = slice(v, 0u, ln);
ret e;
}
@@ -160,153 +142,145 @@
// Appending
/// Expands the given vector in-place by appending `n` copies of `initval`.
-fn grow[T](&mutable T[] v, uint n, &T initval) {
+fn grow[T](v: &mutable T[], n: uint, initval: &T) {
reserve(v, next_power_of_two(len(v) + n));
- let uint i = 0u;
- while (i < n) {
- v += ~[initval];
- i += 1u;
- }
+ let i: uint = 0u;
+ while i < n { v += ~[initval]; i += 1u; }
}
// TODO: Remove me once we have slots.
-fn grow_mut[T](&mutable T[mutable] v, uint n, &T initval) {
+fn grow_mut[T](v: &mutable T[mutable ], n: uint, initval: &T) {
reserve(v, next_power_of_two(len(v) + n));
- let uint i = 0u;
- while (i < n) {
- v += ~[mutable initval];
- i += 1u;
- }
+ let i: uint = 0u;
+ while i < n { v += ~[mutable initval]; i += 1u; }
}
/// Calls `f` `n` times and appends the results of these calls to the given
/// vector.
-fn grow_fn[T](&mutable T[] v, uint n, fn(uint)->T init_fn) {
+fn grow_fn[T](v: &mutable T[], n: uint, init_fn: fn(uint) -> T ) {
reserve(v, next_power_of_two(len(v) + n));
- let uint i = 0u;
- while (i < n) {
- v += ~[init_fn(i)];
- i += 1u;
- }
+ let i: uint = 0u;
+ while i < n { v += ~[init_fn(i)]; i += 1u; }
}
/// Sets the element at position `index` to `val`. If `index` is past the end
/// of the vector, expands the vector by replicating `initval` to fill the
/// intervening space.
-fn grow_set[T](&mutable T[mutable] v, uint index, &T initval, &T val) {
- if (index >= len(v)) { grow_mut(v, index - len(v) + 1u, initval); }
+fn grow_set[T](v: &mutable T[mutable ], index: uint, initval: &T, val: &T) {
+ if index >= len(v) { grow_mut(v, index - len(v) + 1u, initval); }
v.(index) = val;
}
// Functional utilities
-fn map[T,U](fn(&T)->U f, &T[mutable?] v) -> U[] {
- auto result = ~[];
+fn map[T, U](f: fn(&T) -> U , v: &T[mutable? ]) -> U[] {
+ let result = ~[];
reserve(result, len(v));
- for (T elem in v) {
- auto elem2 = elem; // satisfies alias checker
+ for elem: T in v {
+ let elem2 = elem; // satisfies alias checker
result += ~[f(elem2)];
}
ret result;
}
-fn filter_map[T,U](fn(&T)->option::t[U] f, &T[mutable?] v) -> U[] {
- auto result = ~[];
- for (T elem in v) {
- auto elem2 = elem; // satisfies alias checker
- alt (f(elem2)) {
- case (none) { /* no-op */ }
- case (some(?result_elem)) { result += ~[result_elem]; }
+fn filter_map[T, U](f: fn(&T) -> option::t[U] , v: &T[mutable? ]) -> U[] {
+ let result = ~[];
+ for elem: T in v {
+ let elem2 = elem; // satisfies alias checker
+ alt f(elem2) {
+ none. {/* no-op */ }
+ some(result_elem) { result += ~[result_elem]; }
}
}
ret result;
}
-fn foldl[T,U](fn(&U,&T)->U p, &U z, &T[mutable?] v) -> U {
- auto sz = len(v);
- if (sz == 0u) { ret z; }
- auto first = v.(0);
- auto rest = slice(v, 1u, sz);
- ret p(foldl[T,U](p, z, rest), first);
+fn foldl[T, U](p: fn(&U, &T) -> U , z: &U, v: &T[mutable? ]) -> U {
+ let sz = len(v);
+ if sz == 0u { ret z; }
+ let first = v.(0);
+ let rest = slice(v, 1u, sz);
+ ret p(foldl[T, U](p, z, rest), first);
}
-fn any[T](fn(&T)->bool f, &T[] v) -> bool {
- for (T elem in v) { if (f(elem)) { ret true; } }
+fn any[T](f: fn(&T) -> bool , v: &T[]) -> bool {
+ for elem: T in v { if f(elem) { ret true; } }
ret false;
}
-fn all[T](fn(&T)->bool f, &T[] v) -> bool {
- for (T elem in v) { if (!f(elem)) { ret false; } }
+fn all[T](f: fn(&T) -> bool , v: &T[]) -> bool {
+ for elem: T in v { if !f(elem) { ret false; } }
ret true;
}
-fn member[T](&T x, &T[] v) -> bool {
- for (T elt in v) { if (x == elt) { ret true; } }
+fn member[T](x: &T, v: &T[]) -> bool {
+ for elt: T in v { if x == elt { ret true; } }
ret false;
}
-fn count[T](&T x, &T[mutable?] v) -> uint {
- auto cnt = 0u;
- for (T elt in v) { if (x == elt) { cnt += 1u; } }
+fn count[T](x: &T, v: &T[mutable? ]) -> uint {
+ let cnt = 0u;
+ for elt: T in v { if x == elt { cnt += 1u; } }
ret cnt;
}
-fn find[T](fn(&T) -> bool f, &T[] v) -> option::t[T] {
- for (T elt in v) { if (f(elt)) { ret some[T](elt); } }
+fn find[T](f: fn(&T) -> bool , v: &T[]) -> option::t[T] {
+ for elt: T in v { if f(elt) { ret some[T](elt); } }
ret none[T];
}
-fn unzip[T, U](&rec(T _0, U _1)[] v) -> rec(T[] _0, U[] _1) {
- auto sz = len(v);
- if (sz == 0u) {
- ret rec(_0=~[], _1=~[]);
+fn unzip[T, U](v: &{_0: T, _1: U}[]) -> {_0: T[], _1: U[]} {
+ let sz = len(v);
+ if sz == 0u {
+ ret {_0: ~[], _1: ~[]};
} else {
- auto rest = slice(v, 1u, sz);
- auto tl = unzip(rest);
- auto a = ~[v.(0)._0];
- auto b = ~[v.(0)._1];
- ret rec(_0=a + tl._0, _1=b + tl._1);
+ let rest = slice(v, 1u, sz);
+ let tl = unzip(rest);
+ let a = ~[v.(0)._0];
+ let b = ~[v.(0)._1];
+ ret {_0: a + tl._0, _1: b + tl._1};
}
}
// FIXME make the lengths being equal a constraint
-fn zip[T, U](&T[] v, &U[] u) -> rec(T _0, U _1)[] {
- auto sz = len(v);
+fn zip[T, U](v: &T[], u: &U[]) -> {_0: T, _1: U}[] {
+ let sz = len(v);
assert (sz == len(u));
- if (sz == 0u) {
+ if sz == 0u {
ret ~[];
} else {
- auto rest = zip(slice(v, 1u, sz), slice(u, 1u, sz));
- ret ~[rec(_0=v.(0), _1=u.(0))] + rest;
+ let rest = zip(slice(v, 1u, sz), slice(u, 1u, sz));
+ ret ~[{_0: v.(0), _1: u.(0)}] + rest;
}
}
mod unsafe {
- type ivec_repr = rec(mutable uint fill,
- mutable uint alloc,
- *mutable ivec_heap_part heap_part);
- type ivec_heap_part = rec(mutable uint fill);
+ type ivec_repr =
+ {mutable fill: uint,
+ mutable alloc: uint,
+ heap_part: *mutable ivec_heap_part};
+ type ivec_heap_part = {mutable fill: uint};
- fn copy_from_buf[T](&mutable T[] v, *T ptr, uint count) {
+ fn copy_from_buf[T](v: &mutable T[], ptr: *T, count: uint) {
ret rustrt::ivec_copy_from_buf_shared(v, ptr, count);
}
- fn from_buf[T](*T ptr, uint bytes) -> T[] {
- auto v = ~[];
+ fn from_buf[T](ptr: *T, bytes: uint) -> T[] {
+ let v = ~[];
copy_from_buf(v, ptr, bytes);
ret v;
}
- fn set_len[T](&mutable T[] v, uint new_len) {
- auto new_fill = new_len * sys::size_of[T]();
- let *mutable ivec_repr stack_part =
+ fn set_len[T](v: &mutable T[], new_len: uint) {
+ let new_fill = new_len * sys::size_of[T]();
+ let stack_part: *mutable ivec_repr =
::unsafe::reinterpret_cast(addr_of(v));
- if ((*stack_part).fill == 0u) {
- (*(*stack_part).heap_part).fill = new_fill; // On heap.
+ if (*stack_part).fill == 0u {
+ (*(*stack_part).heap_part).fill = new_fill; // On heap.
} else {
- (*stack_part).fill = new_fill; // On stack.
+ (*stack_part).fill = new_fill; // On stack.
}
}
}
diff --git a/src/lib/linux_os.rs b/src/lib/linux_os.rs
index 3313923..f6dc6b1 100644
--- a/src/lib/linux_os.rs
+++ b/src/lib/linux_os.rs
@@ -6,38 +6,38 @@
// FIXME Somehow merge stuff duplicated here and macosx_os.rs. Made difficult
// by https://github.com/graydon/rust/issues#issue/268
native "cdecl" mod libc = "" {
- fn open(sbuf s, int flags, uint mode) -> int;
- fn read(int fd, vbuf buf, uint count) -> int;
- fn write(int fd, vbuf buf, uint count) -> int;
- fn close(int fd) -> int;
+ fn open(s: sbuf, flags: int, mode: uint) -> int;
+ fn read(fd: int, buf: vbuf, count: uint) -> int;
+ fn write(fd: int, buf: vbuf, count: uint) -> int;
+ fn close(fd: int) -> int;
type FILE;
- fn fopen(sbuf path, sbuf mode) -> FILE;
- fn fdopen(int fd, sbuf mode) -> FILE;
- fn fclose(FILE f);
- fn fgetc(FILE f) -> int;
- fn ungetc(int c, FILE f);
- fn feof(FILE f) -> int;
- fn fread(vbuf buf, uint size, uint n, FILE f) -> uint;
- fn fwrite(vbuf buf, uint size, uint n, FILE f) -> uint;
- fn fseek(FILE f, int offset, int whence) -> int;
- fn ftell(FILE f) -> int;
+ fn fopen(path: sbuf, mode: sbuf) -> FILE;
+ fn fdopen(fd: int, mode: sbuf) -> FILE;
+ fn fclose(f: FILE);
+ fn fgetc(f: FILE) -> int;
+ fn ungetc(c: int, f: FILE);
+ fn feof(f: FILE) -> int;
+ fn fread(buf: vbuf, size: uint, n: uint, f: FILE) -> uint;
+ fn fwrite(buf: vbuf, size: uint, n: uint, f: FILE) -> uint;
+ fn fseek(f: FILE, offset: int, whence: int) -> int;
+ fn ftell(f: FILE) -> int;
type dir;
- fn opendir(sbuf d) -> dir;
- fn closedir(dir d) -> int;
+ fn opendir(d: sbuf) -> dir;
+ fn closedir(d: dir) -> int;
type dirent;
- fn readdir(dir d) -> dirent;
- fn getenv(sbuf n) -> sbuf;
- fn setenv(sbuf n, sbuf v, int overwrite) -> int;
- fn unsetenv(sbuf n) -> int;
- fn pipe(*mutable int buf) -> int;
- fn waitpid(int pid, &mutable int status, int options) -> int;
+ fn readdir(d: dir) -> dirent;
+ fn getenv(n: sbuf) -> sbuf;
+ fn setenv(n: sbuf, v: sbuf, overwrite: int) -> int;
+ fn unsetenv(n: sbuf) -> int;
+ fn pipe(buf: *mutable int) -> int;
+ fn waitpid(pid: int, status: &mutable int, options: int) -> int;
}
native "cdecl" mod libc_ivec = "" {
- fn read(int fd, *u8 buf, uint count) -> int;
- fn write(int fd, *u8 buf, uint count) -> int;
- fn fread(*u8 buf, uint size, uint n, libc::FILE f) -> uint;
- fn fwrite(*u8 buf, uint size, uint n, libc::FILE f) -> uint;
+ fn read(fd: int, buf: *u8, count: uint) -> int;
+ fn write(fd: int, buf: *u8, count: uint) -> int;
+ fn fread(buf: *u8, size: uint, n: uint, f: libc::FILE) -> uint;
+ fn fwrite(buf: *u8, size: uint, n: uint, f: libc::FILE) -> uint;
}
mod libc_constants {
@@ -64,18 +64,18 @@
fn target_os() -> str { ret "linux"; }
-fn dylib_filename(str base) -> str { ret "lib" + base + ".so"; }
+fn dylib_filename(base: str) -> str { ret "lib" + base + ".so"; }
-fn pipe() -> rec(int in, int out) {
- auto fds = rec(mutable in=0, mutable out=0);
+fn pipe() -> {in: int, out: int} {
+ let fds = {mutable in: 0, mutable out: 0};
assert (os::libc::pipe(ptr::addr_of(fds.in)) == 0);
- ret rec(in=fds.in, out=fds.out);
+ ret {in: fds.in, out: fds.out};
}
-fn fd_FILE(int fd) -> libc::FILE { ret libc::fdopen(fd, str::buf("r")); }
+fn fd_FILE(fd: int) -> libc::FILE { ret libc::fdopen(fd, str::buf("r")); }
-fn waitpid(int pid) -> int {
- auto status = 0;
+fn waitpid(pid: int) -> int {
+ let status = 0;
assert (os::libc::waitpid(pid, status, 0) != -1);
ret status;
}
diff --git a/src/lib/list.rs b/src/lib/list.rs
index 281f208..ce10fcc 100644
--- a/src/lib/list.rs
+++ b/src/lib/list.rs
@@ -8,76 +8,69 @@
// our recursion rules do not permit that.
tag list[T] { cons(T, @list[T]); nil; }
-fn from_vec[T](vec[T] v) -> list[T] {
- auto l = nil[T];
+fn from_vec[T](v: vec[T]) -> list[T] {
+ let l = nil[T];
// FIXME: This would be faster and more space efficient if it looped over
// a reverse vector iterator. Unfortunately generic iterators seem not to
// work yet.
- for (T item in vec::reversed(v)) { l = cons[T](item, @l); }
+ for item: T in vec::reversed(v) { l = cons[T](item, @l); }
ret l;
}
-fn foldl[T, U](&list[T] ls_, &U u, fn(&T, &U) -> U f) -> U {
- let U accum = u;
- auto ls = ls_;
- while (true) {
- alt (ls) {
- case (cons(?hd, ?tl)) { accum = f(hd, accum); ls = *tl; }
- case (nil) { break; }
+fn foldl[T, U](ls_: &list[T], u: &U, f: fn(&T, &U) -> U ) -> U {
+ let accum: U = u;
+ let ls = ls_;
+ while true {
+ alt ls {
+ cons(hd, tl) { accum = f(hd, accum); ls = *tl; }
+ nil. { break; }
}
}
ret accum;
}
-fn find[T, U](&list[T] ls_, fn(&T) -> option::t[U] f) -> option::t[U] {
- auto ls = ls_;
- while (true) {
- alt (ls) {
- case (cons(?hd, ?tl)) {
- alt (f(hd)) {
- case (none) { ls = *tl; }
- case (some(?rs)) { ret some(rs); }
- }
- }
- case (nil) { break; }
+fn find[T, U](ls_: &list[T], f: fn(&T) -> option::t[U] ) -> option::t[U] {
+ let ls = ls_;
+ while true {
+ alt ls {
+ cons(hd, tl) {
+ alt f(hd) { none. { ls = *tl; } some(rs) { ret some(rs); } }
+ }
+ nil. { break; }
}
}
ret none;
}
-fn has[T](&list[T] ls_, &T elt) -> bool {
- auto ls = ls_;
- while (true) {
- alt (ls) {
- case (cons(?hd, ?tl)) {
- if (elt == hd) { ret true; } else { ls = *tl; }
- }
- case (nil) { ret false; }
+fn has[T](ls_: &list[T], elt: &T) -> bool {
+ let ls = ls_;
+ while true {
+ alt ls {
+ cons(hd, tl) { if elt == hd { ret true; } else { ls = *tl; } }
+ nil. { ret false; }
}
}
ret false; // Typestate checker doesn't understand infinite loops
}
-fn length[T](&list[T] ls) -> uint {
- fn count[T](&T t, &uint u) -> uint { ret u + 1u; }
+fn length[T](ls: &list[T]) -> uint {
+ fn count[T](t: &T, u: &uint) -> uint { ret u + 1u; }
ret foldl[T, uint](ls, 0u, bind count[T](_, _));
}
-fn cdr[T](&list[T] ls) -> list[T] {
- alt (ls) { case (cons(_, ?tl)) { ret *tl; } }
-}
+fn cdr[T](ls: &list[T]) -> list[T] { alt ls { cons(_, tl) { ret *tl; } } }
-fn car[T](&list[T] ls) -> T { alt (ls) { case (cons(?hd, _)) { ret hd; } } }
+fn car[T](ls: &list[T]) -> T { alt ls { cons(hd, _) { ret hd; } } }
-fn append[T](&list[T] l, &list[T] m) -> list[T] {
- alt (l) {
- case (nil) { ret m; }
- case (cons(?x, ?xs)) {
- let list[T] rest = append[T](*xs, m);
- ret cons[T](x, @rest);
- }
+fn append[T](l: &list[T], m: &list[T]) -> list[T] {
+ alt l {
+ nil. { ret m; }
+ cons(x, xs) {
+ let rest: list[T] = append[T](*xs, m);
+ ret cons[T](x, @rest);
+ }
}
}
// Local Variables:
diff --git a/src/lib/macos_os.rs b/src/lib/macos_os.rs
index f1cf8d6..13e7022 100644
--- a/src/lib/macos_os.rs
+++ b/src/lib/macos_os.rs
@@ -3,38 +3,38 @@
import vec::vbuf;
native "cdecl" mod libc = "" {
- fn open(sbuf s, int flags, uint mode) -> int;
- fn read(int fd, vbuf buf, uint count) -> int;
- fn write(int fd, vbuf buf, uint count) -> int;
- fn close(int fd) -> int;
+ fn open(s: sbuf, flags: int, mode: uint) -> int;
+ fn read(fd: int, buf: vbuf, count: uint) -> int;
+ fn write(fd: int, buf: vbuf, count: uint) -> int;
+ fn close(fd: int) -> int;
type FILE;
- fn fopen(sbuf path, sbuf mode) -> FILE;
- fn fdopen(int fd, sbuf mode) -> FILE;
- fn fclose(FILE f);
- fn fgetc(FILE f) -> int;
- fn ungetc(int c, FILE f);
- fn feof(FILE f) -> int;
- fn fread(vbuf buf, uint size, uint n, FILE f) -> uint;
- fn fwrite(vbuf buf, uint size, uint n, FILE f) -> uint;
- fn fseek(FILE f, int offset, int whence) -> int;
- fn ftell(FILE f) -> int;
+ fn fopen(path: sbuf, mode: sbuf) -> FILE;
+ fn fdopen(fd: int, mode: sbuf) -> FILE;
+ fn fclose(f: FILE);
+ fn fgetc(f: FILE) -> int;
+ fn ungetc(c: int, f: FILE);
+ fn feof(f: FILE) -> int;
+ fn fread(buf: vbuf, size: uint, n: uint, f: FILE) -> uint;
+ fn fwrite(buf: vbuf, size: uint, n: uint, f: FILE) -> uint;
+ fn fseek(f: FILE, offset: int, whence: int) -> int;
+ fn ftell(f: FILE) -> int;
type dir;
- fn opendir(sbuf d) -> dir;
- fn closedir(dir d) -> int;
+ fn opendir(d: sbuf) -> dir;
+ fn closedir(d: dir) -> int;
type dirent;
- fn readdir(dir d) -> dirent;
- fn getenv(sbuf n) -> sbuf;
- fn setenv(sbuf n, sbuf v, int overwrite) -> int;
- fn unsetenv(sbuf n) -> int;
- fn pipe(*mutable int buf) -> int;
- fn waitpid(int pid, &mutable int status, int options) -> int;
+ fn readdir(d: dir) -> dirent;
+ fn getenv(n: sbuf) -> sbuf;
+ fn setenv(n: sbuf, v: sbuf, overwrite: int) -> int;
+ fn unsetenv(n: sbuf) -> int;
+ fn pipe(buf: *mutable int) -> int;
+ fn waitpid(pid: int, status: &mutable int, options: int) -> int;
}
native "cdecl" mod libc_ivec = "" {
- fn read(int fd, *u8 buf, uint count) -> int;
- fn write(int fd, *u8 buf, uint count) -> int;
- fn fread(*u8 buf, uint size, uint n, libc::FILE f) -> uint;
- fn fwrite(*u8 buf, uint size, uint n, libc::FILE f) -> uint;
+ fn read(fd: int, buf: *u8, count: uint) -> int;
+ fn write(fd: int, buf: *u8, count: uint) -> int;
+ fn fread(buf: *u8, size: uint, n: uint, f: libc::FILE) -> uint;
+ fn fwrite(buf: *u8, size: uint, n: uint, f: libc::FILE) -> uint;
}
mod libc_constants {
@@ -61,18 +61,18 @@
fn target_os() -> str { ret "macos"; }
-fn dylib_filename(str base) -> str { ret "lib" + base + ".dylib"; }
+fn dylib_filename(base: str) -> str { ret "lib" + base + ".dylib"; }
-fn pipe() -> rec(int in, int out) {
- auto fds = rec(mutable in=0, mutable out=0);
+fn pipe() -> {in: int, out: int} {
+ let fds = {mutable in: 0, mutable out: 0};
assert (os::libc::pipe(ptr::addr_of(fds.in)) == 0);
- ret rec(in=fds.in, out=fds.out);
+ ret {in: fds.in, out: fds.out};
}
-fn fd_FILE(int fd) -> libc::FILE { ret libc::fdopen(fd, str::buf("r")); }
+fn fd_FILE(fd: int) -> libc::FILE { ret libc::fdopen(fd, str::buf("r")); }
-fn waitpid(int pid) -> int {
- auto status = 0;
+fn waitpid(pid: int) -> int {
+ let status = 0;
assert (os::libc::waitpid(pid, status, 0) != -1);
ret status;
}
diff --git a/src/lib/map.rs b/src/lib/map.rs
index 195f180..a5a894f 100644
--- a/src/lib/map.rs
+++ b/src/lib/map.rs
@@ -14,21 +14,19 @@
fn find(&K) -> option::t[V] ;
fn remove(&K) -> option::t[V] ;
fn rehash() ;
- iter items() -> @rec(K key, V val);
+ iter items() -> @{key: K, val: V} ;
iter keys() -> K ;
};
type hashset[K] = hashmap[K, ()];
-fn set_add[K](hashset[K] set, &K key) -> bool {
- ret set.insert(key, ());
-}
+fn set_add[K](set: hashset[K], key: &K) -> bool { ret set.insert(key, ()); }
-fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
- let uint initial_capacity = 32u; // 2^5
+fn mk_hashmap[K, V](hasher: &hashfn[K], eqer: &eqfn[K]) -> hashmap[K, V] {
+ let initial_capacity: uint = 32u; // 2^5
- let util::rational load_factor = rec(num=3, den=4);
+ let load_factor: util::rational = {num: 3, den: 4};
tag bucket[K, V] { nil; deleted; some(K, V); }
- fn make_buckets[K, V](uint nbkts) -> (bucket[K, V])[mutable] {
+ fn make_buckets[K, V](nbkts: uint) -> (bucket[K, V])[mutable ] {
ret ivec::init_elt_mut[bucket[K, V]](nil[K, V], nbkts);
}
// Derive two hash functions from the one given by taking the upper
@@ -45,9 +43,9 @@
// is always a power of 2), so that all buckets are probed for a
// fixed key.
- fn hashl(uint n, uint nbkts) -> uint { ret (n >>> 16u) * 2u + 1u; }
- fn hashr(uint n, uint nbkts) -> uint { ret 0x0000_ffff_u & n; }
- fn hash(uint h, uint nbkts, uint i) -> uint {
+ fn hashl(n: uint, nbkts: uint) -> uint { ret (n >>> 16u) * 2u + 1u; }
+ fn hashr(n: uint, nbkts: uint) -> uint { ret 0x0000_ffff_u & n; }
+ fn hash(h: uint, nbkts: uint, i: uint) -> uint {
ret (hashl(h, nbkts) * i + hashr(h, nbkts)) % nbkts;
}
/**
@@ -56,153 +54,146 @@
*/
fn insert_common[K,
- V](&hashfn[K] hasher, &eqfn[K] eqer,
- &(bucket[K, V])[mutable] bkts, uint nbkts, &K key,
- &V val) -> bool {
- let uint i = 0u;
- let uint h = hasher(key);
- while (i < nbkts) {
- let uint j = hash(h, nbkts, i);
- alt (bkts.(j)) {
- case (some(?k, _)) {
- // Copy key to please alias analysis.
+ V](hasher: &hashfn[K], eqer: &eqfn[K],
+ bkts: &(bucket[K, V])[mutable ], nbkts: uint, key: &K,
+ val: &V) -> bool {
+ let i: uint = 0u;
+ let h: uint = hasher(key);
+ while i < nbkts {
+ let j: uint = hash(h, nbkts, i);
+ alt bkts.(j) {
+ some(k, _) {
+ // Copy key to please alias analysis.
- auto k_ = k;
- if (eqer(key, k_)) {
- bkts.(j) = some[K, V](k_, val);
- ret false;
- }
- i += 1u;
+ let k_ = k;
+ if eqer(key, k_) {
+ bkts.(j) = some[K, V](k_, val);
+ ret false;
}
- case (_) { bkts.(j) = some[K, V](key, val); ret true; }
+ i += 1u;
+ }
+ _ { bkts.(j) = some[K, V](key, val); ret true; }
}
}
fail; // full table
}
fn find_common[K,
- V](&hashfn[K] hasher, &eqfn[K] eqer,
- &(bucket[K, V])[mutable] bkts, uint nbkts, &K key) ->
- option::t[V] {
- let uint i = 0u;
- let uint h = hasher(key);
- while (i < nbkts) {
- let uint j = hash(h, nbkts, i);
- alt (bkts.(j)) {
- case (some(?k, ?v)) {
- // Copy to please alias analysis.
+ V](hasher: &hashfn[K], eqer: &eqfn[K],
+ bkts: &(bucket[K, V])[mutable ], nbkts: uint, key: &K)
+ -> option::t[V] {
+ let i: uint = 0u;
+ let h: uint = hasher(key);
+ while i < nbkts {
+ let j: uint = hash(h, nbkts, i);
+ alt bkts.(j) {
+ some(k, v) {
+ // Copy to please alias analysis.
- auto k_ = k;
- auto v_ = v;
- if (eqer(key, k_)) { ret option::some[V](v_); }
- }
- case (nil) { ret option::none[V]; }
- case (deleted[K, V]) { }
+ let k_ = k;
+ let v_ = v;
+ if eqer(key, k_) { ret option::some[V](v_); }
+ }
+ nil. { ret option::none[V]; }
+ deleted[K, V]. { }
}
i += 1u;
}
ret option::none[V];
}
fn rehash[K,
- V](&hashfn[K] hasher, &eqfn[K] eqer,
- &(bucket[K, V])[mutable] oldbkts, uint noldbkts,
- &(bucket[K, V])[mutable] newbkts, uint nnewbkts) {
- for (bucket[K, V] b in oldbkts) {
- alt (b) {
- case (some(?k_, ?v_)) {
- auto k = k_;
- auto v = v_;
- insert_common[K,
- V](hasher, eqer, newbkts, nnewbkts, k, v);
- }
- case (_) { }
+ V](hasher: &hashfn[K], eqer: &eqfn[K],
+ oldbkts: &(bucket[K, V])[mutable ], noldbkts: uint,
+ newbkts: &(bucket[K, V])[mutable ], nnewbkts: uint) {
+ for b: bucket[K, V] in oldbkts {
+ alt b {
+ some(k_, v_) {
+ let k = k_;
+ let v = v_;
+ insert_common[K, V](hasher, eqer, newbkts, nnewbkts, k, v);
+ }
+ _ { }
}
}
}
obj hashmap[K,
- V](hashfn[K] hasher,
- eqfn[K] eqer,
- mutable (bucket[K, V])[mutable] bkts,
- mutable uint nbkts,
- mutable uint nelts,
- util::rational lf) {
+ V](hasher: hashfn[K],
+ eqer: eqfn[K],
+ mutable bkts: (bucket[K, V])[mutable ],
+ mutable nbkts: uint,
+ mutable nelts: uint,
+ lf: util::rational) {
fn size() -> uint { ret nelts; }
- fn insert(&K key, &V val) -> bool {
- let util::rational load =
- rec(num=nelts + 1u as int, den=nbkts as int);
- if (!util::rational_leq(load, lf)) {
- let uint nnewbkts = uint::next_power_of_two(nbkts + 1u);
- auto newbkts = make_buckets[K, V](nnewbkts);
+ fn insert(key: &K, val: &V) -> bool {
+ let load: util::rational =
+ {num: nelts + 1u as int, den: nbkts as int};
+ if !util::rational_leq(load, lf) {
+ let nnewbkts: uint = uint::next_power_of_two(nbkts + 1u);
+ let newbkts = make_buckets[K, V](nnewbkts);
rehash[K, V](hasher, eqer, bkts, nbkts, newbkts, nnewbkts);
bkts = newbkts;
nbkts = nnewbkts;
}
- if (insert_common[K, V](hasher, eqer, bkts, nbkts, key, val)) {
+ if insert_common[K, V](hasher, eqer, bkts, nbkts, key, val) {
nelts += 1u;
ret true;
}
ret false;
}
- fn contains_key(&K key) -> bool {
- ret alt (find_common[K, V](hasher, eqer, bkts, nbkts, key)) {
- case (option::some(_)) { true }
- case (_) { false }
+ fn contains_key(key: &K) -> bool {
+ ret alt find_common[K, V](hasher, eqer, bkts, nbkts, key) {
+ option::some(_) { true }
+ _ { false }
};
}
- fn get(&K key) -> V {
- ret alt (find_common[K, V](hasher, eqer, bkts, nbkts, key)) {
- case (option::some(?val)) { val }
- case (_) { fail }
+ fn get(key: &K) -> V {
+ ret alt find_common[K, V](hasher, eqer, bkts, nbkts, key) {
+ option::some(val) { val }
+ _ { fail }
};
}
- fn find(&K key) -> option::t[V] {
+ fn find(key: &K) -> option::t[V] {
be find_common[K, V](hasher, eqer, bkts, nbkts, key);
}
- fn remove(&K key) -> option::t[V] {
- let uint i = 0u;
- let uint h = hasher(key);
- while (i < nbkts) {
- let uint j = hash(h, nbkts, i);
- alt (bkts.(j)) {
- case (some(?k, ?v)) {
- auto k_ = k;
- auto vo = option::some(v);
- if (eqer(key, k_)) {
- bkts.(j) = deleted[K, V];
- nelts -= 1u;
- ret vo;
- }
+ fn remove(key: &K) -> option::t[V] {
+ let i: uint = 0u;
+ let h: uint = hasher(key);
+ while i < nbkts {
+ let j: uint = hash(h, nbkts, i);
+ alt bkts.(j) {
+ some(k, v) {
+ let k_ = k;
+ let vo = option::some(v);
+ if eqer(key, k_) {
+ bkts.(j) = deleted[K, V];
+ nelts -= 1u;
+ ret vo;
}
- case (deleted) { }
- case (nil) { ret option::none[V]; }
+ }
+ deleted. { }
+ nil. { ret option::none[V]; }
}
i += 1u;
}
ret option::none[V];
}
fn rehash() {
- auto newbkts = make_buckets[K, V](nbkts);
+ let newbkts = make_buckets[K, V](nbkts);
rehash[K, V](hasher, eqer, bkts, nbkts, newbkts, nbkts);
bkts = newbkts;
}
- iter items() -> @rec(K key, V val) {
- for (bucket[K, V] b in bkts) {
- alt (b) {
- case (some(?k, ?v)) { put @rec(key=k, val=v); }
- case (_) { }
- }
+ iter items() -> @{key: K, val: V} {
+ for b: bucket[K, V] in bkts {
+ alt b { some(k, v) { put @{key: k, val: v}; } _ { } }
}
}
iter keys() -> K {
- for (bucket[K, V] b in bkts) {
- alt (b) {
- case (some(?k, _)) { put k; }
- case (_) { }
- }
+ for b: bucket[K, V] in bkts {
+ alt b { some(k, _) { put k; } _ { } }
}
}
}
- auto bkts = make_buckets[K, V](initial_capacity);
+ let bkts = make_buckets[K, V](initial_capacity);
ret hashmap[K, V](hasher, eqer, bkts, initial_capacity, 0u, load_factor);
}
@@ -213,14 +204,14 @@
}
fn new_int_hash[V]() -> hashmap[int, V] {
- fn hash_int(&int x) -> uint { ret x as uint; }
- fn eq_int(&int a, &int b) -> bool { ret a == b; }
+ fn hash_int(x: &int) -> uint { ret x as uint; }
+ fn eq_int(a: &int, b: &int) -> bool { ret a == b; }
ret mk_hashmap[int, V](hash_int, eq_int);
}
fn new_uint_hash[V]() -> hashmap[uint, V] {
- fn hash_uint(&uint x) -> uint { ret x; }
- fn eq_uint(&uint a, &uint b) -> bool { ret a == b; }
+ fn hash_uint(x: &uint) -> uint { ret x; }
+ fn eq_uint(a: &uint, b: &uint) -> bool { ret a == b; }
ret mk_hashmap[uint, V](hash_uint, eq_uint);
}
diff --git a/src/lib/option.rs b/src/lib/option.rs
index 30066f4..d08fcfd 100644
--- a/src/lib/option.rs
+++ b/src/lib/option.rs
@@ -6,38 +6,31 @@
type operator[T, U] = fn(&T) -> U ;
-fn get[T](&t[T] opt) -> T {
- ret alt (opt) { case (some(?x)) { x } case (none) { fail } };
+fn get[T](opt: &t[T]) -> T { ret alt opt { some(x) { x } none. { fail } }; }
+
+fn map[T, U](f: &operator[T, U], opt: &t[T]) -> t[U] {
+ ret alt opt { some(x) { some[U](f(x)) } none. { none[U] } };
}
-fn map[T, U](&operator[T, U] f, &t[T] opt) -> t[U] {
- ret alt (opt) {
- case (some(?x)) { some[U](f(x)) }
- case (none) { none[U] }
- };
+fn is_none[T](opt: &t[T]) -> bool {
+ ret alt opt { none. { true } some(_) { false } };
}
-fn is_none[T](&t[T] opt) -> bool {
- ret alt (opt) { case (none) { true } case (some(_)) { false } };
-}
+fn is_some[T](opt: &t[T]) -> bool { ret !is_none(opt); }
-fn is_some[T](&t[T] opt) -> bool {
- ret !is_none(opt);
-}
-
-fn from_maybe[T](&T def, &t[T] opt) -> T {
- auto f = bind util::id[T](_);
+fn from_maybe[T](def: &T, opt: &t[T]) -> T {
+ let f = bind util::id[T](_);
ret maybe[T, T](def, f, opt);
}
-fn maybe[T, U](&U def, fn(&T) -> U f, &t[T] opt) -> U {
- ret alt (opt) { case (none) { def } case (some(?t)) { f(t) } };
+fn maybe[T, U](def: &U, f: fn(&T) -> U , opt: &t[T]) -> U {
+ ret alt opt { none. { def } some(t) { f(t) } };
}
// Can be defined in terms of the above when/if we have const bind.
-fn may[T](fn(&T) f, &t[T] opt) {
- alt (opt) { case (none) {/* nothing */ } case (some(?t)) { f(t); } }
+fn may[T](f: fn(&T) , opt: &t[T]) {
+ alt opt { none. {/* nothing */ } some(t) { f(t); } }
}
// Local Variables:
// mode: rust;
diff --git a/src/lib/posix_fs.rs b/src/lib/posix_fs.rs
index 417c6f7..8ae7e36 100644
--- a/src/lib/posix_fs.rs
+++ b/src/lib/posix_fs.rs
@@ -1,11 +1,11 @@
native "rust" mod rustrt {
- fn rust_list_files(str path) -> vec[str];
- fn rust_list_files_ivec(str path) -> @str[];
- fn rust_dirent_filename(os::libc::dirent ent) -> str;
+ fn rust_list_files(path: str) -> vec[str];
+ fn rust_list_files_ivec(path: str) -> @str[];
+ fn rust_dirent_filename(ent: os::libc::dirent) -> str;
}
-fn list_dir(str path) -> str[] {
+fn list_dir(path: str) -> str[] {
ret *rustrt::rust_list_files_ivec(path);
// TODO ensure this is always closed
@@ -33,13 +33,11 @@
}
-fn path_is_absolute(str p) -> bool {
- ret str::char_at(p, 0u) == '/';
-}
+fn path_is_absolute(p: str) -> bool { ret str::char_at(p, 0u) == '/'; }
-const char path_sep = '/';
+const path_sep: char = '/';
-const char alt_path_sep = '/';
+const alt_path_sep: char = '/';
// Local Variables:
// mode: rust;
diff --git a/src/lib/ptr.rs b/src/lib/ptr.rs
index b230a61..fc336f4 100644
--- a/src/lib/ptr.rs
+++ b/src/lib/ptr.rs
@@ -1,10 +1,12 @@
// Unsafe pointer utility functions.
native "rust-intrinsic" mod rusti {
- fn addr_of[T](&mutable T val) -> *mutable T;
- fn ptr_offset[T](*T ptr, uint count) -> *T;
+ fn addr_of[T](val: &mutable T) -> *mutable T;
+ fn ptr_offset[T](ptr: *T, count: uint) -> *T;
}
-fn addr_of[T](&mutable T val) -> *mutable T { ret rusti::addr_of(val); }
-fn offset[T](*T ptr, uint count) -> *T { ret rusti::ptr_offset(ptr, count); }
+fn addr_of[T](val: &mutable T) -> *mutable T { ret rusti::addr_of(val); }
+fn offset[T](ptr: *T, count: uint) -> *T {
+ ret rusti::ptr_offset(ptr, count);
+}
diff --git a/src/lib/rand.rs b/src/lib/rand.rs
index 4a1b032..a6cb1cb 100644
--- a/src/lib/rand.rs
+++ b/src/lib/rand.rs
@@ -7,8 +7,8 @@
native "rust" mod rustrt {
type rctx;
fn rand_new() -> rctx;
- fn rand_next(rctx c) -> u32;
- fn rand_free(rctx c);
+ fn rand_next(c: rctx) -> u32;
+ fn rand_free(c: rctx);
}
type rng =
@@ -17,7 +17,7 @@
};
fn mk_rng() -> rng {
- obj rt_rng(rustrt::rctx c) {
+ obj rt_rng(c: rustrt::rctx) {
fn next() -> u32 {
ret rustrt::rand_next(c);
}drop { rustrt::rand_free(c); }
diff --git a/src/lib/run_program.rs b/src/lib/run_program.rs
index 31f0de9..0955020 100644
--- a/src/lib/run_program.rs
+++ b/src/lib/run_program.rs
@@ -9,27 +9,27 @@
export spawn_process;
native "rust" mod rustrt {
- fn rust_run_program(vbuf argv, int in_fd, int out_fd, int err_fd) -> int;
+ fn rust_run_program(argv: vbuf, in_fd: int, out_fd: int, err_fd: int) ->
+ int;
}
-fn arg_vec(str prog, vec[str] args) -> vec[sbuf] {
- auto argptrs = [str::buf(prog)];
- for (str arg in args) { vec::push[sbuf](argptrs, str::buf(arg)); }
+fn arg_vec(prog: str, args: vec[str]) -> vec[sbuf] {
+ let argptrs = [str::buf(prog)];
+ for arg: str in args { vec::push[sbuf](argptrs, str::buf(arg)); }
vec::push[sbuf](argptrs, 0 as sbuf);
ret argptrs;
}
-fn spawn_process(str prog, vec[str] args,
- int in_fd, int out_fd, int err_fd) -> int {
+fn spawn_process(prog: str, args: vec[str], in_fd: int, out_fd: int,
+ err_fd: int) -> int {
// Note: we have to hold on to this vector reference while we hold a
// pointer to its buffer
- auto argv = arg_vec(prog, args);
- auto pid = rustrt::rust_run_program(vec::buf(argv),
- in_fd, out_fd, err_fd);
+ let argv = arg_vec(prog, args);
+ let pid = rustrt::rust_run_program(vec::buf(argv), in_fd, out_fd, err_fd);
ret pid;
}
-fn run_program(str prog, vec[str] args) -> int {
+fn run_program(prog: str, args: vec[str]) -> int {
ret os::waitpid(spawn_process(prog, args, 0, 0, 0));
}
@@ -42,18 +42,18 @@
fn finish() -> int ;
};
-fn start_program(str prog, vec[str] args) -> @program {
- auto pipe_input = os::pipe();
- auto pipe_output = os::pipe();
- auto pid = spawn_process(prog, args, pipe_input.in, pipe_output.out, 0);
+fn start_program(prog: str, args: vec[str]) -> @program {
+ let pipe_input = os::pipe();
+ let pipe_output = os::pipe();
+ let pid = spawn_process(prog, args, pipe_input.in, pipe_output.out, 0);
- if (pid == -1) { fail; }
+ if pid == -1 { fail; }
os::libc::close(pipe_input.in);
os::libc::close(pipe_output.out);
- obj new_program(int pid,
- mutable int in_fd,
- os::libc::FILE out_file,
- mutable bool finished) {
+ obj new_program(pid: int,
+ mutable in_fd: int,
+ out_file: os::libc::FILE,
+ mutable finished: bool) {
fn get_id() -> int { ret pid; }
fn input() -> io::writer {
ret io::new_writer(io::fd_buf_writer(in_fd, false));
@@ -62,38 +62,36 @@
ret io::new_reader(io::FILE_buf_reader(out_file, false));
}
fn close_input() {
- auto invalid_fd = -1;
- if (in_fd != invalid_fd) {
+ let invalid_fd = -1;
+ if in_fd != invalid_fd {
os::libc::close(in_fd);
in_fd = invalid_fd;
}
}
fn finish() -> int {
- if (finished) { ret 0; }
+ if finished { ret 0; }
finished = true;
self.close_input();
ret os::waitpid(pid);
}drop {
- self.close_input();
- if (!finished) {
- os::waitpid(pid);
- }
+ self.close_input();
+ if !finished { os::waitpid(pid); }
os::libc::fclose(out_file);
}
}
ret @new_program(pid, pipe_input.out, os::fd_FILE(pipe_output.in), false);
}
-fn program_output(str prog, vec[str] args) -> rec(int status, str out) {
- auto pr = start_program(prog, args);
+fn program_output(prog: str, args: vec[str]) -> {status: int, out: str} {
+ let pr = start_program(prog, args);
pr.close_input();
- auto out = pr.output();
- auto buf = "";
- while (!out.eof()) {
- auto bytes = out.read_bytes(4096u);
+ let out = pr.output();
+ let buf = "";
+ while !out.eof() {
+ let bytes = out.read_bytes(4096u);
buf += str::unsafe_from_bytes(bytes);
}
- ret rec(status=pr.finish(), out=buf);
+ ret {status: pr.finish(), out: buf};
}
// Local Variables:
// mode: rust
diff --git a/src/lib/sha1.rs b/src/lib/sha1.rs
index 9ff775c..cd633b2 100644
--- a/src/lib/sha1.rs
+++ b/src/lib/sha1.rs
@@ -9,91 +9,91 @@
export mk_sha1;
type sha1 =
+
+ // Provide message input as bytes
+
+
+ // Provide message input as string
+
+ // Read the digest as a vector of 20 bytes. After
+ // calling this no further input may provided
+ // until reset is called
+
+
+ // Same as above, just a hex-string version.
+
+ // Reset the sha1 state for reuse. This is called
+ // automatically during construction
obj {
-
- // Provide message input as bytes
- fn input(&vec[u8]) ;
-
- fn input_ivec(&u8[]);
-
- // Provide message input as string
- fn input_str(&str) ;
-
- // Read the digest as a vector of 20 bytes. After
- // calling this no further input may provided
- // until reset is called
- fn result() -> vec[u8] ;
-
- fn result_ivec() -> u8[];
-
- // Same as above, just a hex-string version.
- fn result_str() -> str ;
-
- // Reset the sha1 state for reuse. This is called
- // automatically during construction
- fn reset() ;
+ fn input(&vec[u8]) ;
+ fn input_ivec(&u8[]) ;
+ fn input_str(&str) ;
+ fn result() -> vec[u8] ;
+ fn result_ivec() -> u8[] ;
+ fn result_str() -> str ;
+ fn reset() ;
};
// Some unexported constants
-const uint digest_buf_len = 5u;
+const digest_buf_len: uint = 5u;
-const uint msg_block_len = 64u;
+const msg_block_len: uint = 64u;
-const uint work_buf_len = 80u;
+const work_buf_len: uint = 80u;
-const u32 k0 = 0x5A827999u32;
+const k0: u32 = 0x5A827999u32;
-const u32 k1 = 0x6ED9EBA1u32;
+const k1: u32 = 0x6ED9EBA1u32;
-const u32 k2 = 0x8F1BBCDCu32;
+const k2: u32 = 0x8F1BBCDCu32;
-const u32 k3 = 0xCA62C1D6u32;
+const k3: u32 = 0xCA62C1D6u32;
// Builds a sha1 object
fn mk_sha1() -> sha1 {
type sha1state =
- rec(u32[mutable] h,
- mutable u32 len_low,
- mutable u32 len_high,
- u8[mutable] msg_block,
- mutable uint msg_block_idx,
- mutable bool computed,
- u32[mutable] work_buf);
+ {h: u32[mutable ],
+ mutable len_low: u32,
+ mutable len_high: u32,
+ msg_block: u8[mutable ],
+ mutable msg_block_idx: uint,
+ mutable computed: bool,
+ work_buf: u32[mutable ]};
- fn add_input(&sha1state st, &u8[] msg) {
+ fn add_input(st: &sha1state, msg: &u8[]) {
// FIXME: Should be typestate precondition
assert (!st.computed);
- for (u8 element in msg) {
+ for element: u8 in msg {
st.msg_block.(st.msg_block_idx) = element;
st.msg_block_idx += 1u;
st.len_low += 8u32;
- if (st.len_low == 0u32) {
+ if st.len_low == 0u32 {
st.len_high += 1u32;
- if (st.len_high == 0u32) {
+ if st.len_high == 0u32 {
// FIXME: Need better failure mode
fail;
}
}
- if (st.msg_block_idx == msg_block_len) { process_msg_block(st); }
+ if st.msg_block_idx == msg_block_len { process_msg_block(st); }
}
}
- fn process_msg_block(&sha1state st) {
+ fn process_msg_block(st: &sha1state) {
// FIXME: Make precondition
assert (ivec::len(st.h) == digest_buf_len);
assert (ivec::len(st.work_buf) == work_buf_len);
- let int t; // Loop counter
+ let t: int; // Loop counter
- auto w = st.work_buf;
+ let w = st.work_buf;
// Initialize the first 16 words of the vector w
t = 0;
- while (t < 16) {
- auto tmp;
+ while t < 16 {
+ let tmp;
tmp = (st.msg_block.(t * 4) as u32) << 24u32;
tmp = tmp | (st.msg_block.(t * 4 + 1) as u32) << 16u32;
tmp = tmp | (st.msg_block.(t * 4 + 2) as u32) << 8u32;
@@ -103,19 +103,19 @@
}
// Initialize the rest of vector w
- while (t < 80) {
- auto val = w.(t - 3) ^ w.(t - 8) ^ w.(t - 14) ^ w.(t - 16);
+ while t < 80 {
+ let val = w.(t - 3) ^ w.(t - 8) ^ w.(t - 14) ^ w.(t - 16);
w.(t) = circular_shift(1u32, val);
t += 1;
}
- auto a = st.h.(0);
- auto b = st.h.(1);
- auto c = st.h.(2);
- auto d = st.h.(3);
- auto e = st.h.(4);
- let u32 temp;
+ let a = st.h.(0);
+ let b = st.h.(1);
+ let c = st.h.(2);
+ let d = st.h.(3);
+ let e = st.h.(4);
+ let temp: u32;
t = 0;
- while (t < 20) {
+ while t < 20 {
temp =
circular_shift(5u32, a) + (b & c | !b & d) + e + w.(t) + k0;
e = d;
@@ -125,7 +125,7 @@
a = temp;
t += 1;
}
- while (t < 40) {
+ while t < 40 {
temp = circular_shift(5u32, a) + (b ^ c ^ d) + e + w.(t) + k1;
e = d;
d = c;
@@ -134,7 +134,7 @@
a = temp;
t += 1;
}
- while (t < 60) {
+ while t < 60 {
temp =
circular_shift(5u32, a) + (b & c | b & d | c & d) + e + w.(t)
+ k2;
@@ -145,7 +145,7 @@
a = temp;
t += 1;
}
- while (t < 80) {
+ while t < 80 {
temp = circular_shift(5u32, a) + (b ^ c ^ d) + e + w.(t) + k3;
e = d;
d = c;
@@ -161,17 +161,17 @@
st.h.(4) = st.h.(4) + e;
st.msg_block_idx = 0u;
}
- fn circular_shift(u32 bits, u32 word) -> u32 {
+ fn circular_shift(bits: u32, word: u32) -> u32 {
ret word << bits | word >> 32u32 - bits;
}
- fn mk_result(&sha1state st) -> u8[] {
- if (!st.computed) { pad_msg(st); st.computed = true; }
- let u8[] rs = ~[];
- for (u32 hpart in st.h) {
- auto a = hpart >> 24u32 & 0xFFu32 as u8;
- auto b = hpart >> 16u32 & 0xFFu32 as u8;
- auto c = hpart >> 8u32 & 0xFFu32 as u8;
- auto d = hpart & 0xFFu32 as u8;
+ fn mk_result(st: &sha1state) -> u8[] {
+ if !st.computed { pad_msg(st); st.computed = true; }
+ let rs: u8[] = ~[];
+ for hpart: u32 in st.h {
+ let a = hpart >> 24u32 & 0xFFu32 as u8;
+ let b = hpart >> 16u32 & 0xFFu32 as u8;
+ let c = hpart >> 8u32 & 0xFFu32 as u8;
+ let d = hpart & 0xFFu32 as u8;
rs += ~[a, b, c, d];
}
ret rs;
@@ -186,7 +186,7 @@
* can be assumed that the message digest has been computed.
*/
- fn pad_msg(&sha1state st) {
+ fn pad_msg(st: &sha1state) {
// FIXME: Should be a precondition
assert (ivec::len(st.msg_block) == msg_block_len);
@@ -196,10 +196,10 @@
* block, process it, and then continue padding into a second block.
*/
- if (st.msg_block_idx > 55u) {
+ if st.msg_block_idx > 55u {
st.msg_block.(st.msg_block_idx) = 0x80u8;
st.msg_block_idx += 1u;
- while (st.msg_block_idx < msg_block_len) {
+ while st.msg_block_idx < msg_block_len {
st.msg_block.(st.msg_block_idx) = 0u8;
st.msg_block_idx += 1u;
}
@@ -208,7 +208,7 @@
st.msg_block.(st.msg_block_idx) = 0x80u8;
st.msg_block_idx += 1u;
}
- while (st.msg_block_idx < 56u) {
+ while st.msg_block_idx < 56u {
st.msg_block.(st.msg_block_idx) = 0u8;
st.msg_block_idx += 1u;
}
@@ -224,7 +224,7 @@
st.msg_block.(63) = st.len_low & 0xFFu32 as u8;
process_msg_block(st);
}
- obj sha1(sha1state st) {
+ obj sha1(st: sha1state) {
fn reset() {
// FIXME: Should be typestate precondition
@@ -239,36 +239,36 @@
st.h.(4) = 0xC3D2E1F0u32;
st.computed = false;
}
- fn input(&vec[u8] msg) {
- auto m = ~[];
- for (u8 b in msg) { m += ~[b]; }
+ fn input(msg: &vec[u8]) {
+ let m = ~[];
+ for b: u8 in msg { m += ~[b]; }
add_input(st, m);
}
- fn input_ivec(&u8[] msg) { add_input(st, msg); }
- fn input_str(&str msg) { add_input(st, str::bytes_ivec(msg)); }
+ fn input_ivec(msg: &u8[]) { add_input(st, msg); }
+ fn input_str(msg: &str) { add_input(st, str::bytes_ivec(msg)); }
fn result() -> vec[u8] {
- auto rivec = mk_result(st);
- auto rvec = [];
- for (u8 b in rivec) { rvec += [b]; }
+ let rivec = mk_result(st);
+ let rvec = [];
+ for b: u8 in rivec { rvec += [b]; }
ret rvec;
}
fn result_ivec() -> u8[] { ret mk_result(st); }
fn result_str() -> str {
- auto r = mk_result(st);
- auto s = "";
- for (u8 b in r) { s += uint::to_str(b as uint, 16u); }
+ let r = mk_result(st);
+ let s = "";
+ for b: u8 in r { s += uint::to_str(b as uint, 16u); }
ret s;
}
}
- auto st =
- rec(h=ivec::init_elt_mut[u32](0u32, digest_buf_len),
- mutable len_low=0u32,
- mutable len_high=0u32,
- msg_block=ivec::init_elt_mut[u8](0u8, msg_block_len),
- mutable msg_block_idx=0u,
- mutable computed=false,
- work_buf=ivec::init_elt_mut[u32](0u32, work_buf_len));
- auto sh = sha1(st);
+ let st =
+ {h: ivec::init_elt_mut[u32](0u32, digest_buf_len),
+ mutable len_low: 0u32,
+ mutable len_high: 0u32,
+ msg_block: ivec::init_elt_mut[u8](0u8, msg_block_len),
+ mutable msg_block_idx: 0u,
+ mutable computed: false,
+ work_buf: ivec::init_elt_mut[u32](0u32, work_buf_len)};
+ let sh = sha1(st);
sh.reset();
ret sh;
}
diff --git a/src/lib/smallintmap.rs b/src/lib/smallintmap.rs
index b8cd89d..0c11e69 100644
--- a/src/lib/smallintmap.rs
+++ b/src/lib/smallintmap.rs
@@ -7,39 +7,38 @@
// FIXME: Should not be @; there's a bug somewhere in rustc that requires this
// to be.
-type smallintmap[T] = @rec(mutable (option::t[T])[mutable] v);
+type smallintmap[T] = @{mutable v: (option::t[T])[mutable ]};
fn mk[T]() -> smallintmap[T] {
- let (option::t[T])[mutable] v = ~[mutable];
- ret @rec(mutable v=v);
+ let v: (option::t[T])[mutable ] = ~[mutable ];
+ ret @{mutable v: v};
}
-fn insert[T](&smallintmap[T] m, uint key, &T val) {
+fn insert[T](m: &smallintmap[T], key: uint, val: &T) {
ivec::grow_set[option::t[T]](m.v, key, none[T], some[T](val));
}
-fn find[T](&smallintmap[T] m, uint key) -> option::t[T] {
- if (key < ivec::len[option::t[T]](m.v)) { ret m.v.(key); }
+fn find[T](m: &smallintmap[T], key: uint) -> option::t[T] {
+ if key < ivec::len[option::t[T]](m.v) { ret m.v.(key); }
ret none[T];
}
-fn get[T](&smallintmap[T] m, uint key) -> T {
- alt (find[T](m, key)) {
- case (none[T]) {
- log_err "smallintmap::get(): key not present";
- fail;
- }
- case (some[T](?v)) { ret v; }
+fn get[T](m: &smallintmap[T], key: uint) -> T {
+ alt find[T](m, key) {
+ none[T]. { log_err "smallintmap::get(): key not present"; fail; }
+ some[T](v) { ret v; }
}
}
-fn contains_key[T](&smallintmap[T] m, uint key) -> bool {
+fn contains_key[T](m: &smallintmap[T], key: uint) -> bool {
ret !option::is_none(find[T](m, key));
}
-fn truncate[T](&smallintmap[T] m, uint len) {
+fn truncate[T](m: &smallintmap[T], len: uint) {
m.v = ivec::slice_mut[option::t[T]](m.v, 0u, len);
}
-fn max_key[T](&smallintmap[T] m) -> uint { ret ivec::len[option::t[T]](m.v); }
+fn max_key[T](m: &smallintmap[T]) -> uint {
+ ret ivec::len[option::t[T]](m.v);
+}
diff --git a/src/lib/sort.rs b/src/lib/sort.rs
index b14c0cf..65aaf8f 100644
--- a/src/lib/sort.rs
+++ b/src/lib/sort.rs
@@ -11,15 +11,15 @@
type lteq[T] = fn(&T, &T) -> bool ;
-fn merge_sort[T](lteq[T] le, vec[T] v) -> vec[T] {
- fn merge[T](lteq[T] le, vec[T] a, vec[T] b) -> vec[T] {
- let vec[T] rs = [];
- let uint a_len = len[T](a);
- let uint a_ix = 0u;
- let uint b_len = len[T](b);
- let uint b_ix = 0u;
- while (a_ix < a_len && b_ix < b_len) {
- if (le(a.(a_ix), b.(b_ix))) {
+fn merge_sort[T](le: lteq[T], v: vec[T]) -> vec[T] {
+ fn merge[T](le: lteq[T], a: vec[T], b: vec[T]) -> vec[T] {
+ let rs: vec[T] = [];
+ let a_len: uint = len[T](a);
+ let a_ix: uint = 0u;
+ let b_len: uint = len[T](b);
+ let b_ix: uint = 0u;
+ while a_ix < a_len && b_ix < b_len {
+ if le(a.(a_ix), b.(b_ix)) {
rs += [a.(a_ix)];
a_ix += 1u;
} else { rs += [b.(b_ix)]; b_ix += 1u; }
@@ -28,28 +28,28 @@
rs += slice[T](b, b_ix, b_len);
ret rs;
}
- let uint v_len = len[T](v);
- if (v_len <= 1u) { ret v; }
- let uint mid = v_len / 2u;
- let vec[T] a = slice[T](v, 0u, mid);
- let vec[T] b = slice[T](v, mid, v_len);
+ let v_len: uint = len[T](v);
+ if v_len <= 1u { ret v; }
+ let mid: uint = v_len / 2u;
+ let a: vec[T] = slice[T](v, 0u, mid);
+ let b: vec[T] = slice[T](v, mid, v_len);
ret merge[T](le, merge_sort[T](le, a), merge_sort[T](le, b));
}
-fn swap[T](vec[mutable T] arr, uint x, uint y) {
- auto a = arr.(x);
+fn swap[T](arr: vec[mutable T], x: uint, y: uint) {
+ let a = arr.(x);
arr.(x) = arr.(y);
arr.(y) = a;
}
-fn part[T](lteq[T] compare_func, vec[mutable T] arr, uint left, uint right,
- uint pivot) -> uint {
- auto pivot_value = arr.(pivot);
+fn part[T](compare_func: lteq[T], arr: vec[mutable T], left: uint,
+ right: uint, pivot: uint) -> uint {
+ let pivot_value = arr.(pivot);
swap[T](arr, pivot, right);
- let uint storage_index = left;
- let uint i = left;
- while (i < right) {
- if (compare_func({ arr.(i) }, pivot_value)) {
+ let storage_index: uint = left;
+ let i: uint = left;
+ while i < right {
+ if compare_func({ arr.(i) }, pivot_value) {
swap[T](arr, i, storage_index);
storage_index += 1u;
}
@@ -59,11 +59,12 @@
ret storage_index;
}
-fn qsort[T](lteq[T] compare_func, vec[mutable T] arr, uint left, uint right) {
- if (right > left) {
- auto pivot = (left + right) / 2u;
- auto new_pivot = part[T](compare_func, arr, left, right, pivot);
- if (new_pivot != 0u) {
+fn qsort[T](compare_func: lteq[T], arr: vec[mutable T], left: uint,
+ right: uint) {
+ if right > left {
+ let pivot = (left + right) / 2u;
+ let new_pivot = part[T](compare_func, arr, left, right, pivot);
+ if new_pivot != 0u {
// Need to do this check before recursing due to overflow
qsort[T](compare_func, arr, left, new_pivot - 1u);
}
@@ -71,8 +72,8 @@
}
}
-fn quick_sort[T](lteq[T] compare_func, vec[mutable T] arr) {
- if (len[T](arr) == 0u) { ret; }
+fn quick_sort[T](compare_func: lteq[T], arr: vec[mutable T]) {
+ if len[T](arr) == 0u { ret; }
qsort[T](compare_func, arr, 0u, len[T](arr) - 1u);
}
@@ -81,29 +82,29 @@
// http://www.cs.princeton.edu/~rs/talks/QuicksortIsOptimal.pdf
// According to these slides this is the algorithm of choice for
// 'randomly ordered keys, abstract compare' & 'small number of key values'
-fn qsort3[T](lteq[T] compare_func_lt, lteq[T] compare_func_eq,
- vec[mutable T] arr, int left, int right) {
- if (right <= left) { ret; }
- let T v = arr.(right);
- let int i = left - 1;
- let int j = right;
- let int p = i;
- let int q = j;
- while (true) {
+fn qsort3[T](compare_func_lt: lteq[T], compare_func_eq: lteq[T],
+ arr: vec[mutable T], left: int, right: int) {
+ if right <= left { ret; }
+ let v: T = arr.(right);
+ let i: int = left - 1;
+ let j: int = right;
+ let p: int = i;
+ let q: int = j;
+ while true {
i += 1;
- while (compare_func_lt({ arr.(i) }, v)) { i += 1; }
+ while compare_func_lt({ arr.(i) }, v) { i += 1; }
j -= 1;
- while (compare_func_lt(v, { arr.(j) })) {
- if (j == left) { break; }
+ while compare_func_lt(v, { arr.(j) }) {
+ if j == left { break; }
j -= 1;
}
- if (i >= j) { break; }
+ if i >= j { break; }
swap[T](arr, i as uint, j as uint);
- if (compare_func_eq({ arr.(i) }, v)) {
+ if compare_func_eq({ arr.(i) }, v) {
p += 1;
swap[T](arr, p as uint, i as uint);
}
- if (compare_func_eq(v, { arr.(j) })) {
+ if compare_func_eq(v, { arr.(j) }) {
q -= 1;
swap[T](arr, j as uint, q as uint);
}
@@ -111,27 +112,27 @@
swap[T](arr, i as uint, right as uint);
j = i - 1;
i += 1;
- let int k = left;
- while (k < p) {
+ let k: int = left;
+ while k < p {
swap[T](arr, k as uint, j as uint);
k += 1;
j -= 1;
- if (k == vec::len[T](arr) as int) { break; }
+ if k == vec::len[T](arr) as int { break; }
}
k = right - 1;
- while (k > q) {
+ while k > q {
swap[T](arr, i as uint, k as uint);
k -= 1;
i += 1;
- if (k == 0) { break; }
+ if k == 0 { break; }
}
qsort3[T](compare_func_lt, compare_func_eq, arr, left, j);
qsort3[T](compare_func_lt, compare_func_eq, arr, i, right);
}
-fn quick_sort3[T](lteq[T] compare_func_lt, lteq[T] compare_func_eq,
- vec[mutable T] arr) {
- if (vec::len[T](arr) == 0u) { ret; }
+fn quick_sort3[T](compare_func_lt: lteq[T], compare_func_eq: lteq[T],
+ arr: vec[mutable T]) {
+ if vec::len[T](arr) == 0u { ret; }
qsort3[T](compare_func_lt, compare_func_eq, arr, 0,
(vec::len[T](arr) as int) - 1);
}
@@ -141,17 +142,17 @@
export quick_sort;
export quick_sort3;
- type lteq[T] = fn(&T, &T) -> bool;
+ type lteq[T] = fn(&T, &T) -> bool ;
- fn merge_sort[T](lteq[T] le, &T[] v) -> T[] {
- fn merge[T](lteq[T] le, &T[] a, &T[] b) -> T[] {
- let T[] rs = ~[];
- let uint a_len = ilen[T](a);
- let uint a_ix = 0u;
- let uint b_len = ilen[T](b);
- let uint b_ix = 0u;
- while (a_ix < a_len && b_ix < b_len) {
- if (le(a.(a_ix), b.(b_ix))) {
+ fn merge_sort[T](le: lteq[T], v: &T[]) -> T[] {
+ fn merge[T](le: lteq[T], a: &T[], b: &T[]) -> T[] {
+ let rs: T[] = ~[];
+ let a_len: uint = ilen[T](a);
+ let a_ix: uint = 0u;
+ let b_len: uint = ilen[T](b);
+ let b_ix: uint = 0u;
+ while a_ix < a_len && b_ix < b_len {
+ if le(a.(a_ix), b.(b_ix)) {
rs += ~[a.(a_ix)];
a_ix += 1u;
} else { rs += ~[b.(b_ix)]; b_ix += 1u; }
@@ -160,28 +161,28 @@
rs += islice[T](b, b_ix, b_len);
ret rs;
}
- let uint v_len = ilen[T](v);
- if (v_len <= 1u) { ret v; }
- let uint mid = v_len / 2u;
- let T[] a = islice[T](v, 0u, mid);
- let T[] b = islice[T](v, mid, v_len);
+ let v_len: uint = ilen[T](v);
+ if v_len <= 1u { ret v; }
+ let mid: uint = v_len / 2u;
+ let a: T[] = islice[T](v, 0u, mid);
+ let b: T[] = islice[T](v, mid, v_len);
ret merge[T](le, merge_sort[T](le, a), merge_sort[T](le, b));
}
- fn swap[T](&T[mutable] arr, uint x, uint y) {
- auto a = arr.(x);
+ fn swap[T](arr: &T[mutable ], x: uint, y: uint) {
+ let a = arr.(x);
arr.(x) = arr.(y);
arr.(y) = a;
}
- fn part[T](lteq[T] compare_func, &T[mutable] arr, uint left, uint right,
- uint pivot) -> uint {
- auto pivot_value = arr.(pivot);
+ fn part[T](compare_func: lteq[T], arr: &T[mutable ], left: uint,
+ right: uint, pivot: uint) -> uint {
+ let pivot_value = arr.(pivot);
swap[T](arr, pivot, right);
- let uint storage_index = left;
- let uint i = left;
- while (i < right) {
- if (compare_func({ arr.(i) }, pivot_value)) {
+ let storage_index: uint = left;
+ let i: uint = left;
+ while i < right {
+ if compare_func({ arr.(i) }, pivot_value) {
swap[T](arr, i, storage_index);
storage_index += 1u;
}
@@ -191,12 +192,12 @@
ret storage_index;
}
- fn qsort[T](lteq[T] compare_func, &T[mutable] arr, uint left,
- uint right) {
- if (right > left) {
- auto pivot = (left + right) / 2u;
- auto new_pivot = part[T](compare_func, arr, left, right, pivot);
- if (new_pivot != 0u) {
+ fn qsort[T](compare_func: lteq[T], arr: &T[mutable ], left: uint,
+ right: uint) {
+ if right > left {
+ let pivot = (left + right) / 2u;
+ let new_pivot = part[T](compare_func, arr, left, right, pivot);
+ if new_pivot != 0u {
// Need to do this check before recursing due to overflow
qsort[T](compare_func, arr, left, new_pivot - 1u);
}
@@ -204,8 +205,8 @@
}
}
- fn quick_sort[T](lteq[T] compare_func, &T[mutable] arr) {
- if (ilen[T](arr) == 0u) { ret; }
+ fn quick_sort[T](compare_func: lteq[T], arr: &T[mutable ]) {
+ if ilen[T](arr) == 0u { ret; }
qsort[T](compare_func, arr, 0u, ilen[T](arr) - 1u);
}
@@ -215,29 +216,29 @@
// According to these slides this is the algorithm of choice for
// 'randomly ordered keys, abstract compare' & 'small number of key
// values'
- fn qsort3[T](lteq[T] compare_func_lt, lteq[T] compare_func_eq,
- &T[mutable] arr, int left, int right) {
- if (right <= left) { ret; }
- let T v = arr.(right);
- let int i = left - 1;
- let int j = right;
- let int p = i;
- let int q = j;
- while (true) {
+ fn qsort3[T](compare_func_lt: lteq[T], compare_func_eq: lteq[T],
+ arr: &T[mutable ], left: int, right: int) {
+ if right <= left { ret; }
+ let v: T = arr.(right);
+ let i: int = left - 1;
+ let j: int = right;
+ let p: int = i;
+ let q: int = j;
+ while true {
i += 1;
- while (compare_func_lt({ arr.(i) }, v)) { i += 1; }
+ while compare_func_lt({ arr.(i) }, v) { i += 1; }
j -= 1;
- while (compare_func_lt(v, { arr.(j) })) {
- if (j == left) { break; }
+ while compare_func_lt(v, { arr.(j) }) {
+ if j == left { break; }
j -= 1;
}
- if (i >= j) { break; }
+ if i >= j { break; }
swap[T](arr, i as uint, j as uint);
- if (compare_func_eq({ arr.(i) }, v)) {
+ if compare_func_eq({ arr.(i) }, v) {
p += 1;
swap[T](arr, p as uint, i as uint);
}
- if (compare_func_eq(v, { arr.(j) })) {
+ if compare_func_eq(v, { arr.(j) }) {
q -= 1;
swap[T](arr, j as uint, q as uint);
}
@@ -245,27 +246,27 @@
swap[T](arr, i as uint, right as uint);
j = i - 1;
i += 1;
- let int k = left;
- while (k < p) {
+ let k: int = left;
+ while k < p {
swap[T](arr, k as uint, j as uint);
k += 1;
j -= 1;
- if (k == ilen[T](arr) as int) { break; }
+ if k == ilen[T](arr) as int { break; }
}
k = right - 1;
- while (k > q) {
+ while k > q {
swap[T](arr, i as uint, k as uint);
k -= 1;
i += 1;
- if (k == 0) { break; }
+ if k == 0 { break; }
}
qsort3[T](compare_func_lt, compare_func_eq, arr, left, j);
qsort3[T](compare_func_lt, compare_func_eq, arr, i, right);
}
- fn quick_sort3[T](lteq[T] compare_func_lt, lteq[T] compare_func_eq,
- &T[mutable] arr) {
- if (ilen[T](arr) == 0u) { ret; }
+ fn quick_sort3[T](compare_func_lt: lteq[T], compare_func_eq: lteq[T],
+ arr: &T[mutable ]) {
+ if ilen[T](arr) == 0u { ret; }
qsort3[T](compare_func_lt, compare_func_eq, arr, 0,
(ilen[T](arr) as int) - 1);
}
diff --git a/src/lib/str.rs b/src/lib/str.rs
index 265f623..ca0a81a 100644
--- a/src/lib/str.rs
+++ b/src/lib/str.rs
@@ -56,91 +56,91 @@
native "rust" mod rustrt {
type sbuf;
- fn str_buf(str s) -> sbuf;
- fn str_vec(str s) -> vec[u8];
- fn str_byte_len(str s) -> uint;
- fn str_alloc(uint n_bytes) -> str;
- fn str_from_ivec(&u8[mutable?] b) -> str;
- fn str_from_vec(vec[mutable? u8] b) -> str;
- fn str_from_cstr(sbuf cstr) -> str;
- fn str_from_buf(sbuf buf, uint len) -> str;
- fn str_push_byte(str s, uint byte) -> str;
- fn str_slice(str s, uint begin, uint end) -> str;
- fn refcount[T](str s) -> uint;
+ fn str_buf(s: str) -> sbuf;
+ fn str_vec(s: str) -> vec[u8];
+ fn str_byte_len(s: str) -> uint;
+ fn str_alloc(n_bytes: uint) -> str;
+ fn str_from_ivec(b: &u8[mutable? ]) -> str;
+ fn str_from_vec(b: vec[mutable? u8]) -> str;
+ fn str_from_cstr(cstr: sbuf) -> str;
+ fn str_from_buf(buf: sbuf, len: uint) -> str;
+ fn str_push_byte(s: str, byte: uint) -> str;
+ fn str_slice(s: str, begin: uint, end: uint) -> str;
+ fn refcount[T](s: str) -> uint;
}
-fn eq(&str a, &str b) -> bool {
- let uint i = byte_len(a);
- if (byte_len(b) != i) { ret false; }
- while (i > 0u) {
+fn eq(a: &str, b: &str) -> bool {
+ let i: uint = byte_len(a);
+ if byte_len(b) != i { ret false; }
+ while i > 0u {
i -= 1u;
- auto cha = a.(i);
- auto chb = b.(i);
- if (cha != chb) { ret false; }
+ let cha = a.(i);
+ let chb = b.(i);
+ if cha != chb { ret false; }
}
ret true;
}
-fn lteq(&str a, &str b) -> bool {
- let uint i = byte_len(a);
- let uint j = byte_len(b);
- let uint n = i;
- if (j < n) { n = j; }
- let uint x = 0u;
- while (x < n) {
- auto cha = a.(x);
- auto chb = b.(x);
- if (cha < chb) { ret true; } else if (cha > chb) { ret false; }
+fn lteq(a: &str, b: &str) -> bool {
+ let i: uint = byte_len(a);
+ let j: uint = byte_len(b);
+ let n: uint = i;
+ if j < n { n = j; }
+ let x: uint = 0u;
+ while x < n {
+ let cha = a.(x);
+ let chb = b.(x);
+ if cha < chb { ret true; } else if (cha > chb) { ret false; }
x += 1u;
}
ret i <= j;
}
-fn hash(&str s) -> uint {
+fn hash(s: &str) -> uint {
// djb hash.
// FIXME: replace with murmur.
- let uint u = 5381u;
- for (u8 c in s) { u *= 33u; u += c as uint; }
+ let u: uint = 5381u;
+ for c: u8 in s { u *= 33u; u += c as uint; }
ret u;
}
// UTF-8 tags and ranges
-const u8 tag_cont_u8 = 128u8;
+const tag_cont_u8: u8 = 128u8;
-const uint tag_cont = 128u;
+const tag_cont: uint = 128u;
-const uint max_one_b = 128u;
+const max_one_b: uint = 128u;
-const uint tag_two_b = 192u;
+const tag_two_b: uint = 192u;
-const uint max_two_b = 2048u;
+const max_two_b: uint = 2048u;
-const uint tag_three_b = 224u;
+const tag_three_b: uint = 224u;
-const uint max_three_b = 65536u;
+const max_three_b: uint = 65536u;
-const uint tag_four_b = 240u;
+const tag_four_b: uint = 240u;
-const uint max_four_b = 2097152u;
+const max_four_b: uint = 2097152u;
-const uint tag_five_b = 248u;
+const tag_five_b: uint = 248u;
-const uint max_five_b = 67108864u;
+const max_five_b: uint = 67108864u;
-const uint tag_six_b = 252u;
+const tag_six_b: uint = 252u;
-fn is_utf8(vec[u8] v) -> bool {
- auto i = 0u;
- auto total = vec::len[u8](v);
- while (i < total) {
- auto chsize = utf8_char_width(v.(i));
- if (chsize == 0u) { ret false; }
- if (i + chsize > total) { ret false; }
+fn is_utf8(v: vec[u8]) -> bool {
+ let i = 0u;
+ let total = vec::len[u8](v);
+ while i < total {
+ let chsize = utf8_char_width(v.(i));
+ if chsize == 0u { ret false; }
+ if i + chsize > total { ret false; }
i += 1u;
- while (chsize > 1u) {
- if (v.(i) & 192u8 != tag_cont_u8) { ret false; }
+ while chsize > 1u {
+ if v.(i) & 192u8 != tag_cont_u8 { ret false; }
i += 1u;
chsize -= 1u;
}
@@ -148,65 +148,60 @@
ret true;
}
-fn is_ascii(str s) -> bool {
- let uint i = byte_len(s);
- while (i > 0u) { i -= 1u; if (s.(i) & 128u8 != 0u8) { ret false; } }
+fn is_ascii(s: str) -> bool {
+ let i: uint = byte_len(s);
+ while i > 0u { i -= 1u; if s.(i) & 128u8 != 0u8 { ret false; } }
ret true;
}
-fn alloc(uint n_bytes) -> str { ret rustrt::str_alloc(n_bytes); }
+fn alloc(n_bytes: uint) -> str { ret rustrt::str_alloc(n_bytes); }
/// Returns true if the string has length 0
-pred is_empty(str s) -> bool {
- for (u8 c in s) {
- ret false;
- }
- ret true;
-}
+pred is_empty(s: str) -> bool { for c: u8 in s { ret false; } ret true; }
/// Returns true if the string has length greater than 0
-pred is_not_empty(str s) -> bool { !is_empty(s) }
+pred is_not_empty(s: str) -> bool { !is_empty(s) }
// Returns the number of bytes (a.k.a. UTF-8 code units) in s.
// Contrast with a function that would return the number of code
// points (char's), combining character sequences, words, etc. See
// http://icu-project.org/apiref/icu4c/classBreakIterator.html for a
// way to implement those.
-fn byte_len(str s) -> uint { ret rustrt::str_byte_len(s); }
+fn byte_len(s: str) -> uint { ret rustrt::str_byte_len(s); }
-fn buf(str s) -> sbuf { ret rustrt::str_buf(s); }
+fn buf(s: str) -> sbuf { ret rustrt::str_buf(s); }
-fn bytes(str s) -> vec[u8] { ret rustrt::str_vec(s); }
+fn bytes(s: str) -> vec[u8] { ret rustrt::str_vec(s); }
-fn bytes_ivec(str s) -> u8[] {
- auto sbuffer = buf(s);
- auto ptr = unsafe::reinterpret_cast(sbuffer);
+fn bytes_ivec(s: str) -> u8[] {
+ let sbuffer = buf(s);
+ let ptr = unsafe::reinterpret_cast(sbuffer);
ret ivec::unsafe::from_buf(ptr, byte_len(s));
}
-fn from_bytes(vec[u8] v) -> str { ret rustrt::str_from_vec(v); }
+fn from_bytes(v: vec[u8]) -> str { ret rustrt::str_from_vec(v); }
// FIXME temp thing
-fn unsafe_from_bytes(vec[mutable? u8] v) -> str {
+fn unsafe_from_bytes(v: vec[mutable? u8]) -> str {
ret rustrt::str_from_vec(v);
}
-fn unsafe_from_bytes_ivec(&u8[mutable?] v) -> str {
+fn unsafe_from_bytes_ivec(v: &u8[mutable? ]) -> str {
ret rustrt::str_from_ivec(v);
}
-fn unsafe_from_byte(u8 u) -> str { ret rustrt::str_from_vec([u]); }
+fn unsafe_from_byte(u: u8) -> str { ret rustrt::str_from_vec([u]); }
-fn str_from_cstr(sbuf cstr) -> str { ret rustrt::str_from_cstr(cstr); }
+fn str_from_cstr(cstr: sbuf) -> str { ret rustrt::str_from_cstr(cstr); }
-fn str_from_buf(sbuf buf, uint len) -> str {
+fn str_from_buf(buf: sbuf, len: uint) -> str {
ret rustrt::str_from_buf(buf, len);
}
-fn push_utf8_bytes(&mutable str s, char ch) {
- auto code = ch as uint;
- if (code < max_one_b) {
+fn push_utf8_bytes(s: &mutable str, ch: char) {
+ let code = ch as uint;
+ if code < max_one_b {
s = rustrt::str_push_byte(s, code);
} else if (code < max_two_b) {
s = rustrt::str_push_byte(s, code >> 6u & 31u | tag_two_b);
@@ -236,42 +231,42 @@
}
}
-fn from_char(char ch) -> str {
- auto buf = "";
+fn from_char(ch: char) -> str {
+ let buf = "";
push_utf8_bytes(buf, ch);
ret buf;
}
-fn from_chars(vec[char] chs) -> str {
- auto buf = "";
- for (char ch in chs) { push_utf8_bytes(buf, ch); }
+fn from_chars(chs: vec[char]) -> str {
+ let buf = "";
+ for ch: char in chs { push_utf8_bytes(buf, ch); }
ret buf;
}
-fn utf8_char_width(u8 b) -> uint {
- let uint byte = b as uint;
- if (byte < 128u) { ret 1u; }
- if (byte < 192u) {
+fn utf8_char_width(b: u8) -> uint {
+ let byte: uint = b as uint;
+ if byte < 128u { ret 1u; }
+ if byte < 192u {
ret 0u; // Not a valid start byte
}
- if (byte < 224u) { ret 2u; }
- if (byte < 240u) { ret 3u; }
- if (byte < 248u) { ret 4u; }
- if (byte < 252u) { ret 5u; }
+ if byte < 224u { ret 2u; }
+ if byte < 240u { ret 3u; }
+ if byte < 248u { ret 4u; }
+ if byte < 252u { ret 5u; }
ret 6u;
}
-fn char_range_at(str s, uint i) -> rec(char ch, uint next) {
- auto b0 = s.(i);
- auto w = utf8_char_width(b0);
+fn char_range_at(s: str, i: uint) -> {ch: char, next: uint} {
+ let b0 = s.(i);
+ let w = utf8_char_width(b0);
assert (w != 0u);
- if (w == 1u) { ret rec(ch=b0 as char, next=i + 1u); }
- auto val = 0u;
- auto end = i + w;
+ if w == 1u { ret {ch: b0 as char, next: i + 1u}; }
+ let val = 0u;
+ let end = i + w;
i += 1u;
- while (i < end) {
- auto byte = s.(i);
+ while i < end {
+ let byte = s.(i);
assert (byte & 192u8 == tag_cont_u8);
val <<= 6u;
val += byte & 63u8 as uint;
@@ -282,17 +277,17 @@
// a second (as uint) to get it to the right position.
val += (b0 << (w + 1u as u8) as uint) << (w - 1u) * 6u - w - 1u;
- ret rec(ch=val as char, next=i);
+ ret {ch: val as char, next: i};
}
-fn char_at(str s, uint i) -> char { ret char_range_at(s, i).ch; }
+fn char_at(s: str, i: uint) -> char { ret char_range_at(s, i).ch; }
-fn char_len(str s) -> uint {
- auto i = 0u;
- auto len = 0u;
- auto total = byte_len(s);
- while (i < total) {
- auto chsize = utf8_char_width(s.(i));
+fn char_len(s: str) -> uint {
+ let i = 0u;
+ let len = 0u;
+ let total = byte_len(s);
+ while i < total {
+ let chsize = utf8_char_width(s.(i));
assert (chsize > 0u);
len += 1u;
i += chsize;
@@ -301,91 +296,85 @@
ret len;
}
-fn to_chars(str s) -> vec[char] {
- let vec[char] buf = [];
- auto i = 0u;
- auto len = byte_len(s);
- while (i < len) {
- auto cur = char_range_at(s, i);
+fn to_chars(s: str) -> vec[char] {
+ let buf: vec[char] = [];
+ let i = 0u;
+ let len = byte_len(s);
+ while i < len {
+ let cur = char_range_at(s, i);
vec::push[char](buf, cur.ch);
i = cur.next;
}
ret buf;
}
-fn push_char(&mutable str s, char ch) { s += from_char(ch); }
+fn push_char(s: &mutable str, ch: char) { s += from_char(ch); }
-fn pop_char(&mutable str s) -> char {
- auto end = byte_len(s);
- while (end > 0u && s.(end - 1u) & 192u8 == tag_cont_u8) { end -= 1u; }
+fn pop_char(s: &mutable str) -> char {
+ let end = byte_len(s);
+ while end > 0u && s.(end - 1u) & 192u8 == tag_cont_u8 { end -= 1u; }
assert (end > 0u);
- auto ch = char_at(s, end - 1u);
+ let ch = char_at(s, end - 1u);
s = substr(s, 0u, end - 1u);
ret ch;
}
-fn shift_char(&mutable str s) -> char {
- auto r = char_range_at(s, 0u);
+fn shift_char(s: &mutable str) -> char {
+ let r = char_range_at(s, 0u);
s = substr(s, r.next, byte_len(s) - r.next);
ret r.ch;
}
-fn unshift_char(&mutable str s, char ch) {
- s = from_char(ch) + s;
-}
+fn unshift_char(s: &mutable str, ch: char) { s = from_char(ch) + s; }
-fn refcount(str s) -> uint {
- auto r = rustrt::refcount[u8](s);
- if (r == dbg::const_refcount) {
- ret r;
- } else {
- ret r - 1u;
- }
+fn refcount(s: str) -> uint {
+ let r = rustrt::refcount[u8](s);
+ if r == dbg::const_refcount { ret r; } else { ret r - 1u; }
}
// Standard bits from the world of string libraries.
-fn index(str s, u8 c) -> int {
- let int i = 0;
- for (u8 k in s) { if (k == c) { ret i; } i += 1; }
+fn index(s: str, c: u8) -> int {
+ let i: int = 0;
+ for k: u8 in s { if k == c { ret i; } i += 1; }
ret -1;
}
-fn rindex(str s, u8 c) -> int {
- let int n = str::byte_len(s) as int;
- while (n >= 0) { if (s.(n) == c) { ret n; } n -= 1; }
+fn rindex(s: str, c: u8) -> int {
+ let n: int = str::byte_len(s) as int;
+ while n >= 0 { if s.(n) == c { ret n; } n -= 1; }
ret n;
}
-fn find(str haystack, str needle) -> int {
- let int haystack_len = byte_len(haystack) as int;
- let int needle_len = byte_len(needle) as int;
- if (needle_len == 0) { ret 0; }
- fn match_at(&str haystack, &str needle, int i) -> bool {
- let int j = i;
- for (u8 c in needle) { if (haystack.(j) != c) { ret false; } j += 1; }
+fn find(haystack: str, needle: str) -> int {
+ let haystack_len: int = byte_len(haystack) as int;
+ let needle_len: int = byte_len(needle) as int;
+ if needle_len == 0 { ret 0; }
+ fn match_at(haystack: &str, needle: &str, i: int) -> bool {
+ let j: int = i;
+ for c: u8 in needle { if haystack.(j) != c { ret false; } j += 1; }
ret true;
}
- let int i = 0;
- while (i <= haystack_len - needle_len) {
- if (match_at(haystack, needle, i)) { ret i; }
+ let i: int = 0;
+ while i <= haystack_len - needle_len {
+ if match_at(haystack, needle, i) { ret i; }
i += 1;
}
ret -1;
}
-fn starts_with(str haystack, str needle) -> bool {
- let uint haystack_len = byte_len(haystack);
- let uint needle_len = byte_len(needle);
- if (needle_len == 0u) { ret true; }
- if (needle_len > haystack_len) { ret false; }
+fn starts_with(haystack: str, needle: str) -> bool {
+ let haystack_len: uint = byte_len(haystack);
+ let needle_len: uint = byte_len(needle);
+ if needle_len == 0u { ret true; }
+ if needle_len > haystack_len { ret false; }
ret eq(substr(haystack, 0u, needle_len), needle);
}
-fn ends_with(str haystack, str needle) -> bool {
- let uint haystack_len = byte_len(haystack);
- let uint needle_len = byte_len(needle);
- ret if (needle_len == 0u) {
+fn ends_with(haystack: str, needle: str) -> bool {
+ let haystack_len: uint = byte_len(haystack);
+ let needle_len: uint = byte_len(needle);
+ ret if needle_len == 0u {
true
} else if (needle_len > haystack_len) {
false
@@ -395,11 +384,11 @@
};
}
-fn substr(str s, uint begin, uint len) -> str {
+fn substr(s: str, begin: uint, len: uint) -> str {
ret slice(s, begin, begin + len);
}
-fn slice(str s, uint begin, uint end) -> str {
+fn slice(s: str, begin: uint, end: uint) -> str {
// FIXME: Typestate precondition
assert (begin <= end);
@@ -407,90 +396,92 @@
ret rustrt::str_slice(s, begin, end);
}
-fn safe_slice(str s, uint begin, uint end) : le(begin, end) -> str {
- assert (end <= str::byte_len(s)); // would need some magic to
- // make this a precondition
+fn safe_slice(s: str, begin: uint, end: uint) -> str {
+ assert (end <=
+ str::byte_len(s)); // would need some magic to
+ // make this a precondition
+
ret rustrt::str_slice(s, begin, end);
}
-fn shift_byte(&mutable str s) -> u8 {
- auto len = byte_len(s);
+fn shift_byte(s: &mutable str) -> u8 {
+ let len = byte_len(s);
assert (len > 0u);
- auto b = s.(0);
+ let b = s.(0);
s = substr(s, 1u, len - 1u);
ret b;
}
-fn pop_byte(&mutable str s) -> u8 {
- auto len = byte_len(s);
+fn pop_byte(s: &mutable str) -> u8 {
+ let len = byte_len(s);
assert (len > 0u);
- auto b = s.(len - 1u);
+ let b = s.(len - 1u);
s = substr(s, 0u, len - 1u);
ret b;
}
-fn push_byte(&mutable str s, u8 b) {
+fn push_byte(s: &mutable str, b: u8) {
s = rustrt::str_push_byte(s, b as uint);
}
-fn unshift_byte(&mutable str s, u8 b) {
- auto rs = alloc(byte_len(s) + 1u);
+fn unshift_byte(s: &mutable str, b: u8) {
+ let rs = alloc(byte_len(s) + 1u);
rs += unsafe_from_byte(b);
rs += s;
s = rs;
}
-fn split(str s, u8 sep) -> vec[str] {
- let vec[str] v = [];
- let str accum = "";
- let bool ends_with_sep = false;
- for (u8 c in s) {
- if (c == sep) {
+fn split(s: str, sep: u8) -> vec[str] {
+ let v: vec[str] = [];
+ let accum: str = "";
+ let ends_with_sep: bool = false;
+ for c: u8 in s {
+ if c == sep {
v += [accum];
accum = "";
ends_with_sep = true;
} else { accum += unsafe_from_byte(c); ends_with_sep = false; }
}
- if (str::byte_len(accum) != 0u || ends_with_sep) { v += [accum]; }
+ if str::byte_len(accum) != 0u || ends_with_sep { v += [accum]; }
ret v;
}
-fn split_ivec(str s, u8 sep) -> str[] {
- let str[] v = ~[];
- let str accum = "";
- let bool ends_with_sep = false;
- for (u8 c in s) {
- if (c == sep) {
+fn split_ivec(s: str, sep: u8) -> str[] {
+ let v: str[] = ~[];
+ let accum: str = "";
+ let ends_with_sep: bool = false;
+ for c: u8 in s {
+ if c == sep {
v += ~[accum];
accum = "";
ends_with_sep = true;
} else { accum += unsafe_from_byte(c); ends_with_sep = false; }
}
- if (str::byte_len(accum) != 0u || ends_with_sep) { v += ~[accum]; }
+ if str::byte_len(accum) != 0u || ends_with_sep { v += ~[accum]; }
ret v;
}
-fn concat(vec[str] v) -> str {
- let str s = "";
- for (str ss in v) { s += ss; }
+fn concat(v: vec[str]) -> str {
+ let s: str = "";
+ for ss: str in v { s += ss; }
ret s;
}
-fn connect(vec[str] v, str sep) -> str {
- let str s = "";
- let bool first = true;
- for (str ss in v) {
- if (first) { first = false; } else { s += sep; }
+fn connect(v: vec[str], sep: str) -> str {
+ let s: str = "";
+ let first: bool = true;
+ for ss: str in v {
+ if first { first = false; } else { s += sep; }
s += ss;
}
ret s;
}
-fn connect_ivec(&str[] v, str sep) -> str {
- let str s = "";
- let bool first = true;
- for (str ss in v) {
- if (first) { first = false; } else { s += sep; }
+fn connect_ivec(v: &str[], sep: str) -> str {
+ let s: str = "";
+ let first: bool = true;
+ for ss: str in v {
+ if first { first = false; } else { s += sep; }
s += ss;
}
ret s;
@@ -498,14 +489,14 @@
// FIXME: This only handles ASCII
-fn to_upper(str s) -> str {
- auto outstr = "";
- auto ascii_a = 'a' as u8;
- auto ascii_z = 'z' as u8;
- auto diff = 32u8;
- for (u8 byte in s) {
- auto next;
- if (ascii_a <= byte && byte <= ascii_z) {
+fn to_upper(s: str) -> str {
+ let outstr = "";
+ let ascii_a = 'a' as u8;
+ let ascii_z = 'z' as u8;
+ let diff = 32u8;
+ for byte: u8 in s {
+ let next;
+ if ascii_a <= byte && byte <= ascii_z {
next = byte - diff;
} else { next = byte; }
push_byte(outstr, next);
@@ -514,17 +505,16 @@
}
// FIXME: This is super-inefficient
-fn replace(str s, str from, str to) : is_not_empty(from) -> str {
+fn replace(s: str, from: str, to: str) -> str {
// FIXME (694): Shouldn't have to check this
- check is_not_empty(from);
- if (byte_len(s) == 0u) {
+ check (is_not_empty(from));
+ if byte_len(s) == 0u {
ret "";
} else if (starts_with(s, from)) {
- ret to + replace(slice(s, byte_len(from), byte_len(s)),
- from, to);
+ ret to + replace(slice(s, byte_len(from), byte_len(s)), from, to);
} else {
- ret unsafe_from_byte(s.(0))
- + replace(slice(s, 1u, byte_len(s)), from, to);
+ ret unsafe_from_byte(s.(0)) +
+ replace(slice(s, 1u, byte_len(s)), from, to);
}
}
diff --git a/src/lib/sys.rs b/src/lib/sys.rs
index f40da7e..79f3f0e 100644
--- a/src/lib/sys.rs
+++ b/src/lib/sys.rs
@@ -6,13 +6,13 @@
native "rust" mod rustrt {
- // Explicitly re-export native stuff we want to be made
- // available outside this crate. Otherwise it's
- // visible-in-crate, but not re-exported.
- fn last_os_error() -> str;
+ // Explicitly re-export native stuff we want to be made
+ // available outside this crate. Otherwise it's
+ // visible-in-crate, but not re-exported.
+ fn last_os_error() -> str;
fn size_of[T]() -> uint;
fn align_of[T]() -> uint;
- fn refcount[T](@T t) -> uint;
+ fn refcount[T](t: @T) -> uint;
fn do_gc();
fn unsupervise();
}
diff --git a/src/lib/task.rs b/src/lib/task.rs
index e3ddad7..3c3350f 100644
--- a/src/lib/task.rs
+++ b/src/lib/task.rs
@@ -1,11 +1,11 @@
native "rust" mod rustrt {
- fn task_sleep(uint time_in_us);
+ fn task_sleep(time_in_us: uint);
fn task_yield();
- fn task_join(task t) -> int;
+ fn task_join(t: task) -> int;
fn unsupervise();
fn pin_task();
fn unpin_task();
- fn clone_chan(*rust_chan c) -> *rust_chan;
+ fn clone_chan(c: *rust_chan) -> *rust_chan;
type rust_chan;
}
@@ -15,53 +15,33 @@
*
* arg: time_in_us maximum number of microseconds to yield control for
*/
-fn sleep(uint time_in_us) {
- ret rustrt::task_sleep(time_in_us);
+fn sleep(time_in_us: uint) { ret rustrt::task_sleep(time_in_us); }
+
+fn yield() { ret rustrt::task_yield(); }
+
+tag task_result { tr_success; tr_failure; }
+
+fn join(t: task) -> task_result {
+ alt rustrt::task_join(t) { 0 { tr_success } _ { tr_failure } }
}
-fn yield() {
- ret rustrt::task_yield();
-}
+fn unsupervise() { ret rustrt::unsupervise(); }
-tag task_result {
- tr_success;
- tr_failure;
-}
+fn pin() { rustrt::pin_task(); }
-fn join(task t) -> task_result {
- alt (rustrt::task_join(t)) {
- 0 { tr_success }
- _ { tr_failure }
- }
-}
+fn unpin() { rustrt::unpin_task(); }
-fn unsupervise() {
- ret rustrt::unsupervise();
-}
-
-fn pin() {
- rustrt::pin_task();
-}
-
-fn unpin() {
- rustrt::unpin_task();
-}
-
-fn clone_chan[T](chan[T] c) -> chan[T] {
- auto cloned = rustrt::clone_chan(unsafe::reinterpret_cast(c));
+fn clone_chan[T](c: chan[T]) -> chan[T] {
+ let cloned = rustrt::clone_chan(unsafe::reinterpret_cast(c));
ret unsafe::reinterpret_cast(cloned);
}
-fn send[T](chan[T] c, &T v) {
- c <| v;
-}
+fn send[T](c: chan[T], v: &T) { c <| v; }
-fn recv[T](port[T] p) -> T {
- auto v; p |> v; v
-}
+fn recv[T](p: port[T]) -> T { let v; p |> v; v }
// Spawn a task and immediately return a channel for communicating to it
-fn worker[T](fn(port[T]) f) -> rec(task task, chan[T] chan) {
+fn worker[T](f: fn(port[T]) ) -> {task: task, chan: chan[T]} {
// FIXME: This is frighteningly unsafe and only works for
// a few cases
@@ -70,76 +50,76 @@
// FIXME: This terrible hackery is because worktask can't currently
// have type params
type wordsz1 = int;
- type wordsz2 = rec(int a, int b);
- type wordsz3 = rec(int a, int b, int c);
- type wordsz4 = rec(int a, int b, int c, int d);
- type wordsz5 = rec(int a, int b, int c, int d, int e);
+ type wordsz2 = {a: int, b: int};
+ type wordsz3 = {a: int, b: int, c: int};
+ type wordsz4 = {a: int, b: int, c: int, d: int};
+ type wordsz5 = {a: int, b: int, c: int, d: int, e: int};
type opaquechan_1wordsz = chan[chan[wordsz1]];
type opaquechan_2wordsz = chan[chan[wordsz2]];
type opaquechan_3wordsz = chan[chan[wordsz3]];
type opaquechan_4wordsz = chan[chan[wordsz4]];
type opaquechan_5wordsz = chan[chan[wordsz5]];
- fn worktask1(opaquechan_1wordsz setupch, opaque fptr) {
- let *fn(port[wordsz1]) f = unsafe::reinterpret_cast(fptr);
- auto p = port[wordsz1]();
+ fn worktask1(setupch: opaquechan_1wordsz, fptr: opaque) {
+ let f: *fn(port[wordsz1]) = unsafe::reinterpret_cast(fptr);
+ let p = port[wordsz1]();
setupch <| chan(p);
(*f)(p);
}
- fn worktask2(opaquechan_2wordsz setupch, opaque fptr) {
- let *fn(port[wordsz2]) f = unsafe::reinterpret_cast(fptr);
- auto p = port[wordsz2]();
+ fn worktask2(setupch: opaquechan_2wordsz, fptr: opaque) {
+ let f: *fn(port[wordsz2]) = unsafe::reinterpret_cast(fptr);
+ let p = port[wordsz2]();
setupch <| chan(p);
(*f)(p);
}
- fn worktask3(opaquechan_3wordsz setupch, opaque fptr) {
- let *fn(port[wordsz3]) f = unsafe::reinterpret_cast(fptr);
- auto p = port[wordsz3]();
+ fn worktask3(setupch: opaquechan_3wordsz, fptr: opaque) {
+ let f: *fn(port[wordsz3]) = unsafe::reinterpret_cast(fptr);
+ let p = port[wordsz3]();
setupch <| chan(p);
(*f)(p);
}
- fn worktask4(opaquechan_4wordsz setupch, opaque fptr) {
- let *fn(port[wordsz4]) f = unsafe::reinterpret_cast(fptr);
- auto p = port[wordsz4]();
+ fn worktask4(setupch: opaquechan_4wordsz, fptr: opaque) {
+ let f: *fn(port[wordsz4]) = unsafe::reinterpret_cast(fptr);
+ let p = port[wordsz4]();
setupch <| chan(p);
(*f)(p);
}
- fn worktask5(opaquechan_5wordsz setupch, opaque fptr) {
- let *fn(port[wordsz5]) f = unsafe::reinterpret_cast(fptr);
- auto p = port[wordsz5]();
+ fn worktask5(setupch: opaquechan_5wordsz, fptr: opaque) {
+ let f: *fn(port[wordsz5]) = unsafe::reinterpret_cast(fptr);
+ let p = port[wordsz5]();
setupch <| chan(p);
(*f)(p);
}
- auto p = port[chan[T]]();
- auto setupch = chan(p);
- auto fptr = unsafe::reinterpret_cast(ptr::addr_of(f));
+ let p = port[chan[T]]();
+ let setupch = chan(p);
+ let fptr = unsafe::reinterpret_cast(ptr::addr_of(f));
- auto Tsz = sys::size_of[T]();
- auto t = if Tsz == sys::size_of[wordsz1]() {
- auto setupchptr = unsafe::reinterpret_cast(setupch);
- spawn worktask1(setupchptr, fptr)
- } else if Tsz == sys::size_of[wordsz2]() {
- auto setupchptr = unsafe::reinterpret_cast(setupch);
- spawn worktask2(setupchptr, fptr)
- } else if Tsz == sys::size_of[wordsz3]() {
- auto setupchptr = unsafe::reinterpret_cast(setupch);
- spawn worktask3(setupchptr, fptr)
- } else if Tsz == sys::size_of[wordsz4]() {
- auto setupchptr = unsafe::reinterpret_cast(setupch);
- spawn worktask4(setupchptr, fptr)
- } else if Tsz == sys::size_of[wordsz5]() {
- auto setupchptr = unsafe::reinterpret_cast(setupch);
- spawn worktask5(setupchptr, fptr)
- } else {
- fail #fmt("unhandled type size %u in task::worker", Tsz)
- };
- auto ch; p |> ch;
- ret rec(task = t, chan = ch);
+ let Tsz = sys::size_of[T]();
+ let t =
+ if Tsz == sys::size_of[wordsz1]() {
+ let setupchptr = unsafe::reinterpret_cast(setupch);
+ spawn worktask1(setupchptr, fptr)
+ } else if (Tsz == sys::size_of[wordsz2]()) {
+ let setupchptr = unsafe::reinterpret_cast(setupch);
+ spawn worktask2(setupchptr, fptr)
+ } else if (Tsz == sys::size_of[wordsz3]()) {
+ let setupchptr = unsafe::reinterpret_cast(setupch);
+ spawn worktask3(setupchptr, fptr)
+ } else if (Tsz == sys::size_of[wordsz4]()) {
+ let setupchptr = unsafe::reinterpret_cast(setupch);
+ spawn worktask4(setupchptr, fptr)
+ } else if (Tsz == sys::size_of[wordsz5]()) {
+ let setupchptr = unsafe::reinterpret_cast(setupch);
+ spawn worktask5(setupchptr, fptr)
+ } else { fail #fmt("unhandled type size %u in task::worker", Tsz) };
+ let ch;
+ p |> ch;
+ ret {task: t, chan: ch};
}
// Local Variables:
diff --git a/src/lib/term.rs b/src/lib/term.rs
index a4e723b..6576982 100644
--- a/src/lib/term.rs
+++ b/src/lib/term.rs
@@ -4,69 +4,69 @@
// Simple ANSI color library.
//
// TODO: Windows support.
-const u8 color_black = 0u8;
+const color_black: u8 = 0u8;
-const u8 color_red = 1u8;
+const color_red: u8 = 1u8;
-const u8 color_green = 2u8;
+const color_green: u8 = 2u8;
-const u8 color_yellow = 3u8;
+const color_yellow: u8 = 3u8;
-const u8 color_blue = 4u8;
+const color_blue: u8 = 4u8;
-const u8 color_magenta = 5u8;
+const color_magenta: u8 = 5u8;
-const u8 color_cyan = 6u8;
+const color_cyan: u8 = 6u8;
-const u8 color_light_gray = 7u8;
+const color_light_gray: u8 = 7u8;
-const u8 color_light_grey = 7u8;
+const color_light_grey: u8 = 7u8;
-const u8 color_dark_gray = 8u8;
+const color_dark_gray: u8 = 8u8;
-const u8 color_dark_grey = 8u8;
+const color_dark_grey: u8 = 8u8;
-const u8 color_bright_red = 9u8;
+const color_bright_red: u8 = 9u8;
-const u8 color_bright_green = 10u8;
+const color_bright_green: u8 = 10u8;
-const u8 color_bright_yellow = 11u8;
+const color_bright_yellow: u8 = 11u8;
-const u8 color_bright_blue = 12u8;
+const color_bright_blue: u8 = 12u8;
-const u8 color_bright_magenta = 13u8;
+const color_bright_magenta: u8 = 13u8;
-const u8 color_bright_cyan = 14u8;
+const color_bright_cyan: u8 = 14u8;
-const u8 color_bright_white = 15u8;
+const color_bright_white: u8 = 15u8;
-fn esc(io::buf_writer writer) { writer.write([0x1bu8, '[' as u8]); }
+fn esc(writer: io::buf_writer) { writer.write([0x1bu8, '[' as u8]); }
-fn reset(io::buf_writer writer) {
+fn reset(writer: io::buf_writer) {
esc(writer);
writer.write(['0' as u8, 'm' as u8]);
}
fn color_supported() -> bool {
- auto supported_terms = ["xterm-color", "xterm", "screen-bce"];
- ret alt (generic_os::getenv("TERM")) {
- case (option::some(?env)) { vec::member(env, supported_terms) }
- case (option::none) { false }
+ let supported_terms = ["xterm-color", "xterm", "screen-bce"];
+ ret alt generic_os::getenv("TERM") {
+ option::some(env) { vec::member(env, supported_terms) }
+ option::none. { false }
};
}
-fn set_color(io::buf_writer writer, u8 first_char, u8 color) {
+fn set_color(writer: io::buf_writer, first_char: u8, color: u8) {
assert (color < 16u8);
esc(writer);
- if (color >= 8u8) { writer.write(['1' as u8, ';' as u8]); color -= 8u8; }
+ if color >= 8u8 { writer.write(['1' as u8, ';' as u8]); color -= 8u8; }
writer.write([first_char, ('0' as u8) + color, 'm' as u8]);
}
-fn fg(io::buf_writer writer, u8 color) {
+fn fg(writer: io::buf_writer, color: u8) {
ret set_color(writer, '3' as u8, color);
}
-fn bg(io::buf_writer writer, u8 color) {
+fn bg(writer: io::buf_writer, color: u8) {
ret set_color(writer, '4' as u8, color);
}
// export fg;
diff --git a/src/lib/termivec.rs b/src/lib/termivec.rs
index c487fcc..29477ec 100644
--- a/src/lib/termivec.rs
+++ b/src/lib/termivec.rs
@@ -4,74 +4,74 @@
// Simple ANSI color library.
//
// TODO: Windows support.
-const u8 color_black = 0u8;
+const color_black: u8 = 0u8;
-const u8 color_red = 1u8;
+const color_red: u8 = 1u8;
-const u8 color_green = 2u8;
+const color_green: u8 = 2u8;
-const u8 color_yellow = 3u8;
+const color_yellow: u8 = 3u8;
-const u8 color_blue = 4u8;
+const color_blue: u8 = 4u8;
-const u8 color_magenta = 5u8;
+const color_magenta: u8 = 5u8;
-const u8 color_cyan = 6u8;
+const color_cyan: u8 = 6u8;
-const u8 color_light_gray = 7u8;
+const color_light_gray: u8 = 7u8;
-const u8 color_light_grey = 7u8;
+const color_light_grey: u8 = 7u8;
-const u8 color_dark_gray = 8u8;
+const color_dark_gray: u8 = 8u8;
-const u8 color_dark_grey = 8u8;
+const color_dark_grey: u8 = 8u8;
-const u8 color_bright_red = 9u8;
+const color_bright_red: u8 = 9u8;
-const u8 color_bright_green = 10u8;
+const color_bright_green: u8 = 10u8;
-const u8 color_bright_yellow = 11u8;
+const color_bright_yellow: u8 = 11u8;
-const u8 color_bright_blue = 12u8;
+const color_bright_blue: u8 = 12u8;
-const u8 color_bright_magenta = 13u8;
+const color_bright_magenta: u8 = 13u8;
-const u8 color_bright_cyan = 14u8;
+const color_bright_cyan: u8 = 14u8;
-const u8 color_bright_white = 15u8;
+const color_bright_white: u8 = 15u8;
-fn esc(ioivec::buf_writer writer) { writer.write(~[0x1bu8, '[' as u8]); }
+fn esc(writer: ioivec::buf_writer) { writer.write(~[0x1bu8, '[' as u8]); }
-fn reset(ioivec::buf_writer writer) {
+fn reset(writer: ioivec::buf_writer) {
esc(writer);
writer.write(~['0' as u8, 'm' as u8]);
}
fn color_supported() -> bool {
- auto supported_terms = ~["xterm-color", "xterm", "screen-bce"];
- ret alt (generic_os::getenv("TERM")) {
- case (option::some(?env)) {
- for (str term in supported_terms) {
- if (str::eq(term, env)) { ret true; }
+ let supported_terms = ~["xterm-color", "xterm", "screen-bce"];
+ ret alt generic_os::getenv("TERM") {
+ option::some(env) {
+ for term: str in supported_terms {
+ if str::eq(term, env) { ret true; }
}
false
}
- case (option::none) { false }
+ option::none. { false }
};
}
-fn set_color(ioivec::buf_writer writer, u8 first_char, u8 color) {
+fn set_color(writer: ioivec::buf_writer, first_char: u8, color: u8) {
assert (color < 16u8);
esc(writer);
- if (color >= 8u8) { writer.write(~['1' as u8, ';' as u8]); color -= 8u8; }
+ if color >= 8u8 { writer.write(~['1' as u8, ';' as u8]); color -= 8u8; }
writer.write(~[first_char, ('0' as u8) + color, 'm' as u8]);
}
-fn fg(ioivec::buf_writer writer, u8 color) {
+fn fg(writer: ioivec::buf_writer, color: u8) {
ret set_color(writer, '3' as u8, color);
}
-fn bg(ioivec::buf_writer writer, u8 color) {
+fn bg(writer: ioivec::buf_writer, color: u8) {
ret set_color(writer, '4' as u8, color);
}
// export fg;
diff --git a/src/lib/test.rs b/src/lib/test.rs
index bfbbdee..801d7cf 100644
--- a/src/lib/test.rs
+++ b/src/lib/test.rs
@@ -4,7 +4,7 @@
// while providing a base that other test frameworks may build off of.
import sort = sort::ivector;
-import getenv = generic_os::getenv;
+import generic_os::getenv;
export test_name;
export test_fn;
@@ -33,184 +33,165 @@
// the test succeeds; if the function fails then the test fails. We
// may need to come up with a more clever definition of test in order
// to support isolation of tests into tasks.
-type test_fn = fn();
+type test_fn = fn() ;
// The definition of a single test. A test runner will run a list of
// these.
-type test_desc = rec(test_name name,
- test_fn fn,
- bool ignore);
+type test_desc = {name: test_name, fn: test_fn, ignore: bool};
// The default console test runner. It accepts the command line
// arguments and a vector of test_descs (generated at compile time).
-fn test_main(&vec[str] args, &test_desc[] tests) {
- auto ivec_args = {
- auto iargs = ~[];
- for (str arg in args) {
- iargs += ~[arg]
- }
- iargs
- };
- check ivec::is_not_empty(ivec_args);
- auto opts = alt (parse_opts(ivec_args)) {
- either::left(?o) { o }
- either::right(?m) { fail m }
- };
- if (!run_tests_console(opts, tests)) {
- fail "Some tests failed";
- }
+fn test_main(args: &vec[str], tests: &test_desc[]) {
+ let ivec_args =
+ { let iargs = ~[]; for arg: str in args { iargs += ~[arg] } iargs };
+ check (ivec::is_not_empty(ivec_args));
+ let opts =
+ alt parse_opts(ivec_args) {
+ either::left(o) { o }
+ either::right(m) { fail m }
+ };
+ if !run_tests_console(opts, tests) { fail "Some tests failed"; }
}
-type test_opts = rec(option::t[str] filter,
- bool run_ignored);
+type test_opts = {filter: option::t[str], run_ignored: bool};
type opt_res = either::t[test_opts, str];
// Parses command line arguments into test options
-fn parse_opts(&str[] args) : ivec::is_not_empty(args) -> opt_res {
+fn parse_opts(args: &str[]) -> opt_res {
// FIXME (#649): Shouldn't have to check here
- check ivec::is_not_empty(args);
- auto args_ = ivec::tail(args);
- auto opts = ~[getopts::optflag("ignored")];
- auto match = alt (getopts::getopts_ivec(args_, opts)) {
- getopts::success(?m) { m }
- getopts::failure(?f) { ret either::right(getopts::fail_str(f)) }
- };
+ check (ivec::is_not_empty(args));
+ let args_ = ivec::tail(args);
+ let opts = ~[getopts::optflag("ignored")];
+ let match =
+ alt getopts::getopts_ivec(args_, opts) {
+ getopts::success(m) { m }
+ getopts::failure(f) { ret either::right(getopts::fail_str(f)) }
+ };
- auto filter = if (vec::len(match.free) > 0u) {
- option::some(match.free.(0))
- } else {
- option::none
- };
+ let filter =
+ if vec::len(match.free) > 0u {
+ option::some(match.free.(0))
+ } else { option::none };
- auto run_ignored = getopts::opt_present(match, "ignored");
+ let run_ignored = getopts::opt_present(match, "ignored");
- auto test_opts = rec(filter = filter,
- run_ignored = run_ignored);
+ let test_opts = {filter: filter, run_ignored: run_ignored};
ret either::left(test_opts);
}
-tag test_result {
- tr_ok;
- tr_failed;
- tr_ignored;
-}
+tag test_result { tr_ok; tr_failed; tr_ignored; }
// To get isolation and concurrency tests have to be run in their own tasks.
// In cases where test functions and closures it is not ok to just dump them
// into a task and run them, so this transformation gives the caller a chance
// to create the test task.
-type test_to_task = fn(&fn()) -> task;
+type test_to_task = fn(&fn() ) -> task ;
// A simple console test runner
-fn run_tests_console(&test_opts opts,
- &test_desc[] tests) -> bool {
+fn run_tests_console(opts: &test_opts, tests: &test_desc[]) -> bool {
run_tests_console_(opts, tests, default_test_to_task)
}
-fn run_tests_console_(&test_opts opts,
- &test_desc[] tests,
- &test_to_task to_task) -> bool {
+fn run_tests_console_(opts: &test_opts, tests: &test_desc[],
+ to_task: &test_to_task) -> bool {
- auto filtered_tests = filter_tests(opts, tests);
+ let filtered_tests = filter_tests(opts, tests);
- auto out = io::stdout();
+ let out = io::stdout();
- auto total = ivec::len(filtered_tests);
+ let total = ivec::len(filtered_tests);
out.write_line(#fmt("running %u tests", total));
- auto futures = ~[];
+ let futures = ~[];
- auto passed = 0u;
- auto failed = 0u;
- auto ignored = 0u;
+ let passed = 0u;
+ let failed = 0u;
+ let ignored = 0u;
- auto failures = ~[];
+ let failures = ~[];
// It's tempting to just spawn all the tests at once but that doesn't
// provide a great user experience because you might sit waiting for the
// result of a particular test for an unusually long amount of time.
- auto concurrency = get_concurrency();
+ let concurrency = get_concurrency();
log #fmt("using %u test tasks", concurrency);
- auto run_idx = 0u;
- auto wait_idx = 0u;
+ let run_idx = 0u;
+ let wait_idx = 0u;
- while (wait_idx < total) {
- while (ivec::len(futures) < concurrency
- && run_idx < total) {
+ while wait_idx < total {
+ while ivec::len(futures) < concurrency && run_idx < total {
futures += ~[run_test(filtered_tests.(run_idx), to_task)];
run_idx += 1u;
}
- auto future = futures.(0);
+ let future = futures.(0);
out.write_str(#fmt("running %s ... ", future.test.name));
- auto result = future.wait();
- alt (result) {
- tr_ok {
- passed += 1u;
- write_ok(out, concurrency);
- out.write_line("");
- }
- tr_failed {
- failed += 1u;
- write_failed(out, concurrency);
- out.write_line("");
- failures += ~[future.test];
- }
- tr_ignored {
- ignored += 1u;
- write_ignored(out, concurrency);
- out.write_line("");
- }
+ let result = future.wait();
+ alt result {
+ tr_ok. {
+ passed += 1u;
+ write_ok(out, concurrency);
+ out.write_line("");
+ }
+ tr_failed. {
+ failed += 1u;
+ write_failed(out, concurrency);
+ out.write_line("");
+ failures += ~[future.test];
+ }
+ tr_ignored. {
+ ignored += 1u;
+ write_ignored(out, concurrency);
+ out.write_line("");
+ }
}
futures = ivec::slice(futures, 1u, ivec::len(futures));
wait_idx += 1u;
}
- assert passed + failed + ignored == total;
- auto success = failed == 0u;
+ assert (passed + failed + ignored == total);
+ let success = failed == 0u;
- if (!success) {
+ if !success {
out.write_line("\nfailures:");
- for (test_desc test in failures) {
+ for test: test_desc in failures {
out.write_line(#fmt(" %s", test.name));
}
}
out.write_str(#fmt("\nresult: "));
- if (success) {
+ if success {
write_ok(out, concurrency);
- } else {
- write_failed(out, concurrency);
- }
- out.write_str(#fmt(". %u passed; %u failed; %u ignored\n\n",
- passed, failed, ignored));
+ } else { write_failed(out, concurrency); }
+ out.write_str(#fmt(". %u passed; %u failed; %u ignored\n\n", passed,
+ failed, ignored));
ret success;
- fn write_ok(&io::writer out, uint concurrency) {
+ fn write_ok(out: &io::writer, concurrency: uint) {
write_pretty(out, "ok", term::color_green, concurrency);
- }
+ }
- fn write_failed(&io::writer out, uint concurrency) {
+ fn write_failed(out: &io::writer, concurrency: uint) {
write_pretty(out, "FAILED", term::color_red, concurrency);
}
- fn write_ignored(&io::writer out, uint concurrency) {
+ fn write_ignored(out: &io::writer, concurrency: uint) {
write_pretty(out, "ignored", term::color_yellow, concurrency);
}
- fn write_pretty(&io::writer out, &str word, u8 color,
- uint concurrency) {
+ fn write_pretty(out: &io::writer, word: &str, color: u8,
+ concurrency: uint) {
// In the presence of concurrency, outputing control characters
// can cause some crazy artifacting
- if (concurrency == 1u && term::color_supported()) {
+ if concurrency == 1u && term::color_supported() {
term::fg(out.get_buf_writer(), color);
}
out.write_str(word);
- if (concurrency == 1u && term::color_supported()) {
+ if concurrency == 1u && term::color_supported() {
term::reset(out.get_buf_writer());
}
}
@@ -218,90 +199,94 @@
fn get_concurrency() -> uint {
alt getenv("RUST_THREADS") {
- option::some(?t) {
- auto threads = uint::parse_buf(str::bytes(t), 10u);
+ option::some(t) {
+ let threads = uint::parse_buf(str::bytes(t), 10u);
threads > 0u ? threads : 1u
}
- option::none {
- 1u
- }
+ option::none. { 1u }
}
}
-fn filter_tests(&test_opts opts, &test_desc[] tests) -> test_desc[] {
- auto filtered = tests;
+fn filter_tests(opts: &test_opts, tests: &test_desc[]) -> test_desc[] {
+ let filtered = tests;
// Remove tests that don't match the test filter
- filtered = if (option::is_none(opts.filter)) {
- filtered
- } else {
- auto filter_str = alt opts.filter { option::some(?f) { f }
- option::none { "" } };
+ filtered =
+ if option::is_none(opts.filter) {
+ filtered
+ } else {
+ let filter_str =
+ alt opts.filter {
+ option::some(f) { f }
+ option::none. { "" }
+ };
- auto filter = bind fn(&test_desc test,
- str filter_str) -> option::t[test_desc] {
- if (str::find(test.name, filter_str) >= 0) {
- ret option::some(test);
- } else {
- ret option::none;
- }
- } (_, filter_str);
+ let filter =
+ bind fn (test: &test_desc, filter_str: str) ->
+ option::t[test_desc] {
+ if str::find(test.name, filter_str) >= 0 {
+ ret option::some(test);
+ } else { ret option::none; }
+ }(_, filter_str);
- ivec::filter_map(filter, filtered)
- };
- // Maybe pull out the ignored test and unignore them
- filtered = if (!opts.run_ignored) {
- filtered
- } else {
- auto filter = fn(&test_desc test) -> option::t[test_desc] {
- if (test.ignore) {
- ret option::some(rec(name = test.name,
- fn = test.fn,
- ignore = false));
- } else {
- ret option::none;
- }
+ ivec::filter_map(filter, filtered)
};
- ivec::filter_map(filter, filtered)
- };
+ // Maybe pull out the ignored test and unignore them
+ filtered =
+ if !opts.run_ignored {
+ filtered
+ } else {
+ let filter =
+ fn (test: &test_desc) -> option::t[test_desc] {
+ if test.ignore {
+ ret option::some({name: test.name,
+ fn: test.fn,
+ ignore: false});
+ } else { ret option::none; }
+ };
+
+
+ ivec::filter_map(filter, filtered)
+ };
// Sort the tests alphabetically
- filtered = {
- fn lteq(&test_desc t1, &test_desc t2) -> bool {
- str::lteq(t1.name, t2.name)
- }
- sort::merge_sort(lteq, filtered)
- };
+ filtered =
+ {
+ fn lteq(t1: &test_desc, t2: &test_desc) -> bool {
+ str::lteq(t1.name, t2.name)
+ }
+ sort::merge_sort(lteq, filtered)
+ };
ret filtered;
}
-type test_future = rec(test_desc test,
- @fn() fnref,
- fn() -> test_result wait);
+type test_future =
+ {test: test_desc, fnref: @fn() , wait: fn() -> test_result };
-fn run_test(&test_desc test, &test_to_task to_task) -> test_future {
+fn run_test(test: &test_desc, to_task: &test_to_task) -> test_future {
// FIXME: Because of the unsafe way we're passing the test function
// to the test task, we need to make sure we keep a reference to that
// function around for longer than the lifetime of the task. To that end
// we keep the function boxed in the test future.
- auto fnref = @test.fn;
- if (!test.ignore) {
- auto test_task = to_task(*fnref);
- ret rec(test = test,
- fnref = fnref,
- wait = bind fn(&task test_task) -> test_result {
- alt (task::join(test_task)) {
- task::tr_success { tr_ok }
- task::tr_failure { tr_failed }
- }
- } (test_task));
+ let fnref = @test.fn;
+ if !test.ignore {
+ let test_task = to_task(*fnref);
+ ret {test: test,
+ fnref: fnref,
+ wait:
+ bind fn (test_task: &task) -> test_result {
+ alt task::join(test_task) {
+ task::tr_success. { tr_ok }
+ task::tr_failure. { tr_failed }
+ }
+ }(test_task)};
} else {
- ret rec(test = test,
- fnref = fnref,
- wait = fn() -> test_result { tr_ignored });
+ ret {test: test,
+ fnref: fnref,
+ wait: fn () -> test_result { tr_ignored }};
}
}
@@ -313,8 +298,8 @@
// But, at least currently, functions can't be used as spawn arguments so
// we've got to treat our test functions as unsafe pointers. This function
// only works with functions that don't contain closures.
-fn default_test_to_task(&fn() f) -> task {
- fn run_task(*mutable fn() fptr) {
+fn default_test_to_task(f: &fn() ) -> task {
+ fn run_task(fptr: *mutable fn() ) {
// If this task fails we don't want that failure to propagate to the
// test runner or else we couldn't keep running tests
task::unsupervise();
@@ -325,10 +310,11 @@
// the test runner can continue.
rustrt::hack_allow_leaks();
+
// Run the test
(*fptr)()
}
- auto fptr = ptr::addr_of(f);
+ let fptr = ptr::addr_of(f);
ret spawn run_task(fptr);
}
diff --git a/src/lib/time.rs b/src/lib/time.rs
index d2c61b7..cf8ddfc 100644
--- a/src/lib/time.rs
+++ b/src/lib/time.rs
@@ -1,25 +1,21 @@
native "rust" mod rustrt {
- fn get_time(&mutable u32 sec, &mutable u32 usec);
- fn nano_time(&mutable u64 ns);
+ fn get_time(sec: &mutable u32, usec: &mutable u32);
+ fn nano_time(ns: &mutable u64);
}
-type timeval = rec(u32 sec, u32 usec);
+type timeval = {sec: u32, usec: u32};
fn get_time() -> timeval {
- auto sec = 0u32;
- auto usec = 0u32;
+ let sec = 0u32;
+ let usec = 0u32;
rustrt::get_time(sec, usec);
- ret rec(sec=sec, usec=usec);
+ ret {sec: sec, usec: usec};
}
-fn precise_time_ns() -> u64 {
- auto ns = 0u64;
- rustrt::nano_time(ns);
- ret ns;
-}
+fn precise_time_ns() -> u64 { let ns = 0u64; rustrt::nano_time(ns); ret ns; }
fn precise_time_s() -> float {
ret (precise_time_ns() as float) / 1000000000.;
-}
+}
\ No newline at end of file
diff --git a/src/lib/u64.rs b/src/lib/u64.rs
index 32e5dd3..12197ad 100644
--- a/src/lib/u64.rs
+++ b/src/lib/u64.rs
@@ -1,39 +1,36 @@
-fn to_str(u64 n, uint radix) -> str {
- assert(0u < radix && radix <= 16u);
+fn to_str(n: u64, radix: uint) -> str {
+ assert (0u < radix && radix <= 16u);
- auto r64 = radix as u64;
+ let r64 = radix as u64;
- fn digit(u64 n) -> str {
- ret alt (n) {
- case (0u64) { "0" }
- case (1u64) { "1" }
- case (2u64) { "2" }
- case (3u64) { "3" }
- case (4u64) { "4" }
- case (5u64) { "5" }
- case (6u64) { "6" }
- case (7u64) { "7" }
- case (8u64) { "8" }
- case (9u64) { "9" }
- case (10u64) { "a" }
- case (11u64) { "b" }
- case (12u64) { "c" }
- case (13u64) { "d" }
- case (14u64) { "e" }
- case (15u64) { "f" }
- case (_) { fail }
- };
+ fn digit(n: u64) -> str {
+ ret alt n {
+ 0u64 { "0" }
+ 1u64 { "1" }
+ 2u64 { "2" }
+ 3u64 { "3" }
+ 4u64 { "4" }
+ 5u64 { "5" }
+ 6u64 { "6" }
+ 7u64 { "7" }
+ 8u64 { "8" }
+ 9u64 { "9" }
+ 10u64 { "a" }
+ 11u64 { "b" }
+ 12u64 { "c" }
+ 13u64 { "d" }
+ 14u64 { "e" }
+ 15u64 { "f" }
+ _ { fail }
+ };
}
if n == 0u64 { ret "0"; }
- auto s = "";
+ let s = "";
- while(n > 0u64) {
- s = digit(n % r64) + s;
- n /= r64;
- }
+ while n > 0u64 { s = digit(n % r64) + s; n /= r64; }
ret s;
}
-fn str(u64 n) -> str { ret to_str(n, 10u); }
+fn str(n: u64) -> str { ret to_str(n, 10u); }
\ No newline at end of file
diff --git a/src/lib/u8.rs b/src/lib/u8.rs
index cec6e1d..8a04308 100644
--- a/src/lib/u8.rs
+++ b/src/lib/u8.rs
@@ -1,28 +1,28 @@
-fn add(u8 x, u8 y) -> u8 { ret x + y; }
+fn add(x: u8, y: u8) -> u8 { ret x + y; }
-fn sub(u8 x, u8 y) -> u8 { ret x - y; }
+fn sub(x: u8, y: u8) -> u8 { ret x - y; }
-fn mul(u8 x, u8 y) -> u8 { ret x * y; }
+fn mul(x: u8, y: u8) -> u8 { ret x * y; }
-fn div(u8 x, u8 y) -> u8 { ret x / y; }
+fn div(x: u8, y: u8) -> u8 { ret x / y; }
-fn rem(u8 x, u8 y) -> u8 { ret x % y; }
+fn rem(x: u8, y: u8) -> u8 { ret x % y; }
-fn lt(u8 x, u8 y) -> bool { ret x < y; }
+fn lt(x: u8, y: u8) -> bool { ret x < y; }
-fn le(u8 x, u8 y) -> bool { ret x <= y; }
+fn le(x: u8, y: u8) -> bool { ret x <= y; }
-fn eq(u8 x, u8 y) -> bool { ret x == y; }
+fn eq(x: u8, y: u8) -> bool { ret x == y; }
-fn ne(u8 x, u8 y) -> bool { ret x != y; }
+fn ne(x: u8, y: u8) -> bool { ret x != y; }
-fn ge(u8 x, u8 y) -> bool { ret x >= y; }
+fn ge(x: u8, y: u8) -> bool { ret x >= y; }
-fn gt(u8 x, u8 y) -> bool { ret x > y; }
+fn gt(x: u8, y: u8) -> bool { ret x > y; }
-iter range(u8 lo, u8 hi) -> u8 { while (lo < hi) { put lo; lo += 1u8; } }
+iter range(lo: u8, hi: u8) -> u8 { while lo < hi { put lo; lo += 1u8; } }
// Local Variables:
// mode: rust;
// fill-column: 78;
diff --git a/src/lib/ufind.rs b/src/lib/ufind.rs
index 5dc0a10..dd2da25 100644
--- a/src/lib/ufind.rs
+++ b/src/lib/ufind.rs
@@ -8,14 +8,12 @@
// than the node itself.
type node = option::t[uint];
-type ufind = rec(mutable vec[mutable node] nodes);
+type ufind = {mutable nodes: vec[mutable node]};
-fn make() -> ufind {
- ret rec(mutable nodes=[mutable]);
-}
+fn make() -> ufind { ret {mutable nodes: [mutable ]}; }
-fn make_set(&ufind ufnd) -> uint {
- auto idx = vec::len(ufnd.nodes);
+fn make_set(ufnd: &ufind) -> uint {
+ let idx = vec::len(ufnd.nodes);
ufnd.nodes += [mutable none[uint]];
ret idx;
}
@@ -23,32 +21,32 @@
/// Creates sets as necessary to ensure that least `n` sets are present in the
/// data structure.
-fn grow(&ufind ufnd, uint n) {
- while (set_count(ufnd) < n) { make_set(ufnd); }
+fn grow(ufnd: &ufind, n: uint) {
+ while set_count(ufnd) < n { make_set(ufnd); }
}
-fn find(&ufind ufnd, uint n) -> uint {
- alt (ufnd.nodes.(n)) {
- case (none) { ret n; }
- case (some(?m)) { auto m_ = m; be find(ufnd, m_); }
+fn find(ufnd: &ufind, n: uint) -> uint {
+ alt ufnd.nodes.(n) {
+ none. { ret n; }
+ some(m) { let m_ = m; be find(ufnd, m_); }
}
}
-fn union(&ufind ufnd, uint m, uint n) {
- auto m_root = find(ufnd, m);
- auto n_root = find(ufnd, n);
- if (m_root < n_root) {
+fn union(ufnd: &ufind, m: uint, n: uint) {
+ let m_root = find(ufnd, m);
+ let n_root = find(ufnd, n);
+ if m_root < n_root {
ufnd.nodes.(n_root) = some[uint](m_root);
} else if (m_root > n_root) { ufnd.nodes.(m_root) = some[uint](n_root); }
}
-fn set_count(&ufind ufnd) -> uint { ret vec::len[node](ufnd.nodes); }
+fn set_count(ufnd: &ufind) -> uint { ret vec::len[node](ufnd.nodes); }
// Removes all sets with IDs greater than or equal to the given value.
-fn prune(&ufind ufnd, uint n) {
+fn prune(ufnd: &ufind, n: uint) {
// TODO: Use "slice" once we get rid of "mutable?"
- auto len = vec::len[node](ufnd.nodes);
- while (len != n) { vec::pop[node](ufnd.nodes); len -= 1u; }
-}
+ let len = vec::len[node](ufnd.nodes);
+ while len != n { vec::pop[node](ufnd.nodes); len -= 1u; }
+}
\ No newline at end of file
diff --git a/src/lib/ufindivec.rs b/src/lib/ufindivec.rs
index 9759820..37e44b8 100644
--- a/src/lib/ufindivec.rs
+++ b/src/lib/ufindivec.rs
@@ -8,14 +8,12 @@
// than the node itself.
type node = option::t[uint];
-type ufind = rec(mutable node[mutable] nodes);
+type ufind = {mutable nodes: node[mutable ]};
-fn make() -> ufind {
- ret rec(mutable nodes=~[mutable]);
-}
+fn make() -> ufind { ret {mutable nodes: ~[mutable ]}; }
-fn make_set(&ufind ufnd) -> uint {
- auto idx = ivec::len(ufnd.nodes);
+fn make_set(ufnd: &ufind) -> uint {
+ let idx = ivec::len(ufnd.nodes);
ufnd.nodes += ~[mutable none[uint]];
ret idx;
}
@@ -23,32 +21,32 @@
/// Creates sets as necessary to ensure that least `n` sets are present in the
/// data structure.
-fn grow(&ufind ufnd, uint n) {
- while (set_count(ufnd) < n) { make_set(ufnd); }
+fn grow(ufnd: &ufind, n: uint) {
+ while set_count(ufnd) < n { make_set(ufnd); }
}
-fn find(&ufind ufnd, uint n) -> uint {
- alt (ufnd.nodes.(n)) {
- case (none) { ret n; }
- case (some(?m)) { auto m_ = m; be find(ufnd, m_); }
+fn find(ufnd: &ufind, n: uint) -> uint {
+ alt ufnd.nodes.(n) {
+ none. { ret n; }
+ some(m) { let m_ = m; be find(ufnd, m_); }
}
}
-fn union(&ufind ufnd, uint m, uint n) {
- auto m_root = find(ufnd, m);
- auto n_root = find(ufnd, n);
- if (m_root < n_root) {
+fn union(ufnd: &ufind, m: uint, n: uint) {
+ let m_root = find(ufnd, m);
+ let n_root = find(ufnd, n);
+ if m_root < n_root {
ufnd.nodes.(n_root) = some[uint](m_root);
} else if (m_root > n_root) { ufnd.nodes.(m_root) = some[uint](n_root); }
}
-fn set_count(&ufind ufnd) -> uint { ret ivec::len[node](ufnd.nodes); }
+fn set_count(ufnd: &ufind) -> uint { ret ivec::len[node](ufnd.nodes); }
// Removes all sets with IDs greater than or equal to the given value.
-fn prune(&ufind ufnd, uint n) {
+fn prune(ufnd: &ufind, n: uint) {
// TODO: Use "slice" once we get rid of "mutable?"
- auto len = ivec::len[node](ufnd.nodes);
- while (len != n) { ivec::pop[node](ufnd.nodes); len -= 1u; }
-}
+ let len = ivec::len[node](ufnd.nodes);
+ while len != n { ivec::pop[node](ufnd.nodes); len -= 1u; }
+}
\ No newline at end of file
diff --git a/src/lib/uint.rs b/src/lib/uint.rs
index 2b3c287..248ac49 100644
--- a/src/lib/uint.rs
+++ b/src/lib/uint.rs
@@ -1,100 +1,97 @@
-fn add(uint x, uint y) -> uint { ret x + y; }
+fn add(x: uint, y: uint) -> uint { ret x + y; }
-fn sub(uint x, uint y) -> uint { ret x - y; }
+fn sub(x: uint, y: uint) -> uint { ret x - y; }
-fn mul(uint x, uint y) -> uint { ret x * y; }
+fn mul(x: uint, y: uint) -> uint { ret x * y; }
-fn div(uint x, uint y) -> uint { ret x / y; }
+fn div(x: uint, y: uint) -> uint { ret x / y; }
-fn rem(uint x, uint y) -> uint { ret x % y; }
+fn rem(x: uint, y: uint) -> uint { ret x % y; }
-pred lt(uint x, uint y) -> bool { ret x < y; }
+pred lt(x: uint, y: uint) -> bool { ret x < y; }
-pred le(uint x, uint y) -> bool { ret x <= y; }
+pred le(x: uint, y: uint) -> bool { ret x <= y; }
-pred eq(uint x, uint y) -> bool { ret x == y; }
+pred eq(x: uint, y: uint) -> bool { ret x == y; }
-pred ne(uint x, uint y) -> bool { ret x != y; }
+pred ne(x: uint, y: uint) -> bool { ret x != y; }
-pred ge(uint x, uint y) -> bool { ret x >= y; }
+pred ge(x: uint, y: uint) -> bool { ret x >= y; }
-pred gt(uint x, uint y) -> bool { ret x > y; }
+pred gt(x: uint, y: uint) -> bool { ret x > y; }
-fn max(uint x, uint y) -> uint { if (x > y) { ret x; } ret y; }
+fn max(x: uint, y: uint) -> uint { if x > y { ret x; } ret y; }
-fn min(uint x, uint y) -> uint { if (x > y) { ret y; } ret x; }
+fn min(x: uint, y: uint) -> uint { if x > y { ret y; } ret x; }
-iter range(uint lo, uint hi) -> uint {
- auto lo_ = lo;
- while (lo_ < hi) { put lo_; lo_ += 1u; }
+iter range(lo: uint, hi: uint) -> uint {
+ let lo_ = lo;
+ while lo_ < hi { put lo_; lo_ += 1u; }
}
-fn next_power_of_two(uint n) -> uint {
+fn next_power_of_two(n: uint) -> uint {
// FIXME change |* uint(4)| below to |* uint(8) / uint(2)| and watch the
// world explode.
- let uint halfbits = sys::rustrt::size_of[uint]() * 4u;
- let uint tmp = n - 1u;
- let uint shift = 1u;
- while (shift <= halfbits) { tmp |= tmp >> shift; shift <<= 1u; }
+ let halfbits: uint = sys::rustrt::size_of[uint]() * 4u;
+ let tmp: uint = n - 1u;
+ let shift: uint = 1u;
+ while shift <= halfbits { tmp |= tmp >> shift; shift <<= 1u; }
ret tmp + 1u;
}
-fn parse_buf(vec[u8] buf, uint radix) -> uint {
- if (vec::len[u8](buf) == 0u) {
- log_err "parse_buf(): buf is empty";
- fail;
- }
- auto i = vec::len[u8](buf) - 1u;
- auto power = 1u;
- auto n = 0u;
- while (true) {
+fn parse_buf(buf: vec[u8], radix: uint) -> uint {
+ if vec::len[u8](buf) == 0u { log_err "parse_buf(): buf is empty"; fail; }
+ let i = vec::len[u8](buf) - 1u;
+ let power = 1u;
+ let n = 0u;
+ while true {
n += (buf.(i) - ('0' as u8) as uint) * power;
power *= radix;
- if (i == 0u) { ret n; }
+ if i == 0u { ret n; }
i -= 1u;
}
fail;
}
-fn to_str(uint num, uint radix) -> str {
- auto n = num;
+fn to_str(num: uint, radix: uint) -> str {
+ let n = num;
assert (0u < radix && radix <= 16u);
- fn digit(uint n) -> char {
- ret alt (n) {
- case (0u) { '0' }
- case (1u) { '1' }
- case (2u) { '2' }
- case (3u) { '3' }
- case (4u) { '4' }
- case (5u) { '5' }
- case (6u) { '6' }
- case (7u) { '7' }
- case (8u) { '8' }
- case (9u) { '9' }
- case (10u) { 'a' }
- case (11u) { 'b' }
- case (12u) { 'c' }
- case (13u) { 'd' }
- case (14u) { 'e' }
- case (15u) { 'f' }
- case (_) { fail }
+ fn digit(n: uint) -> char {
+ ret alt n {
+ 0u { '0' }
+ 1u { '1' }
+ 2u { '2' }
+ 3u { '3' }
+ 4u { '4' }
+ 5u { '5' }
+ 6u { '6' }
+ 7u { '7' }
+ 8u { '8' }
+ 9u { '9' }
+ 10u { 'a' }
+ 11u { 'b' }
+ 12u { 'c' }
+ 13u { 'd' }
+ 14u { 'e' }
+ 15u { 'f' }
+ _ { fail }
};
}
- if (n == 0u) { ret "0"; }
- let str s = "";
- while (n != 0u) {
+ if n == 0u { ret "0"; }
+ let s: str = "";
+ while n != 0u {
s += str::unsafe_from_byte(digit(n % radix) as u8);
n /= radix;
}
- let str s1 = "";
- let uint len = str::byte_len(s);
- while (len != 0u) { len -= 1u; s1 += str::unsafe_from_byte(s.(len)); }
+ let s1: str = "";
+ let len: uint = str::byte_len(s);
+ while len != 0u { len -= 1u; s1 += str::unsafe_from_byte(s.(len)); }
ret s1;
}
-fn str(uint i) -> str { ret to_str(i, 10u); }
+fn str(i: uint) -> str { ret to_str(i, 10u); }
// Local Variables:
// mode: rust;
diff --git a/src/lib/unsafe.rs b/src/lib/unsafe.rs
index 11068b8..663bee5 100644
--- a/src/lib/unsafe.rs
+++ b/src/lib/unsafe.rs
@@ -1,9 +1,9 @@
// Unsafe operations.
native "rust-intrinsic" mod rusti {
- fn cast[T,U](&T src) -> U;
+ fn cast[T, U](src: &T) -> U;
}
// Casts the value at `src` to U. The two types must have the same length.
-fn reinterpret_cast[T,U](&T src) -> U { ret rusti::cast(src); }
+fn reinterpret_cast[T, U](src: &T) -> U { ret rusti::cast(src); }
diff --git a/src/lib/util.rs b/src/lib/util.rs
index 03832aa..672090e 100644
--- a/src/lib/util.rs
+++ b/src/lib/util.rs
@@ -1,21 +1,21 @@
-fn id[T](&T x) -> T { ret x; }
+fn id[T](x: &T) -> T { ret x; }
/* FIXME (issue #141): See test/run-pass/constrained-type.rs. Uncomment
* the constraint once fixed. */
-type rational = rec(int num, int den);
+type rational = {num: int, den: int};
// : int::positive(*.den);
-fn rational_leq(&rational x, &rational y) -> bool {
+fn rational_leq(x: &rational, y: &rational) -> bool {
// NB: Uses the fact that rationals have positive denominators WLOG:
ret x.num * y.den <= y.num * x.den;
}
-fn orb(&bool a, &bool b) -> bool { ret a || b; }
+fn orb(a: &bool, b: &bool) -> bool { ret a || b; }
// Local Variables:
// mode: rust;
// fill-column: 78;
diff --git a/src/lib/vec.rs b/src/lib/vec.rs
index 432098f..d7b1e77 100644
--- a/src/lib/vec.rs
+++ b/src/lib/vec.rs
@@ -11,46 +11,42 @@
native "rust" mod rustrt {
type vbuf;
- fn vec_buf[T](vec[T] v, uint offset) -> vbuf;
- fn vec_len[T](vec[T] v) -> uint;
+ fn vec_buf[T](v: vec[T], offset: uint) -> vbuf;
+ fn vec_len[T](v: vec[T]) -> uint;
- /**
- * Sometimes we modify the vec internal data via vec_buf and need to
- * update the vec's fill length accordingly.
- */
- fn vec_len_set[T](vec[T] v, uint n);
+ /**
+ * Sometimes we modify the vec internal data via vec_buf and need to
+ * update the vec's fill length accordingly.
+ */
+ fn vec_len_set[T](v: vec[T], n: uint);
- /**
- * The T in vec_alloc[T, U] is the type of the vec to allocate. The
- * U is the type of an element in the vec. So to allocate a vec[U] we
- * want to invoke this as vec_alloc[vec[U], U].
- */
- fn vec_alloc[T, U](uint n_elts) -> vec[U];
- fn vec_alloc_mut[T, U](uint n_elts) -> vec[mutable U];
- fn refcount[T](vec[T] v) -> uint;
- fn vec_print_debug_info[T](vec[T] v);
- fn vec_from_vbuf[T](vbuf v, uint n_elts) -> vec[T];
- fn unsafe_vec_to_mut[T](vec[T] v) -> vec[mutable T];
+ /**
+ * The T in vec_alloc[T, U] is the type of the vec to allocate. The
+ * U is the type of an element in the vec. So to allocate a vec[U] we
+ * want to invoke this as vec_alloc[vec[U], U].
+ */
+ fn vec_alloc[T, U](n_elts: uint) -> vec[U];
+ fn vec_alloc_mut[T, U](n_elts: uint) -> vec[mutable U];
+ fn refcount[T](v: vec[T]) -> uint;
+ fn vec_print_debug_info[T](v: vec[T]);
+ fn vec_from_vbuf[T](v: vbuf, n_elts: uint) -> vec[T];
+ fn unsafe_vec_to_mut[T](v: vec[T]) -> vec[mutable T];
}
-fn alloc[T](uint n_elts) -> vec[T] {
+fn alloc[T](n_elts: uint) -> vec[T] {
ret rustrt::vec_alloc[vec[T], T](n_elts);
}
-fn alloc_mut[T](uint n_elts) -> vec[mutable T] {
+fn alloc_mut[T](n_elts: uint) -> vec[mutable T] {
ret rustrt::vec_alloc_mut[vec[mutable T], T](n_elts);
}
-fn refcount[T](array[T] v) -> uint {
- auto r = rustrt::refcount[T](v);
- if (r == dbg::const_refcount) {
- ret r;
- } else {
- ret r - 1u;
- }
+fn refcount[T](v: array[T]) -> uint {
+ let r = rustrt::refcount[T](v);
+ if r == dbg::const_refcount { ret r; } else { ret r - 1u; }
}
-fn vec_from_vbuf[T](vbuf v, uint n_elts) -> vec[T] {
+fn vec_from_vbuf[T](v: vbuf, n_elts: uint) -> vec[T] {
ret rustrt::vec_from_vbuf[T](v, n_elts);
}
@@ -64,23 +60,23 @@
type init_op[T] = fn(uint) -> T ;
-fn init_fn[T](&init_op[T] op, uint n_elts) -> vec[T] {
- let vec[T] v = alloc[T](n_elts);
- let uint i = 0u;
- while (i < n_elts) { v += [op(i)]; i += 1u; }
+fn init_fn[T](op: &init_op[T], n_elts: uint) -> vec[T] {
+ let v: vec[T] = alloc[T](n_elts);
+ let i: uint = 0u;
+ while i < n_elts { v += [op(i)]; i += 1u; }
ret v;
}
-fn init_fn_mut[T](&init_op[T] op, uint n_elts) -> vec[mutable T] {
- let vec[mutable T] v = alloc_mut[T](n_elts);
- let uint i = 0u;
- while (i < n_elts) { v += [mutable op(i)]; i += 1u; }
+fn init_fn_mut[T](op: &init_op[T], n_elts: uint) -> vec[mutable T] {
+ let v: vec[mutable T] = alloc_mut[T](n_elts);
+ let i: uint = 0u;
+ while i < n_elts { v += [mutable op(i)]; i += 1u; }
ret v;
}
// init_elt: creates and returns a vector of length n_elts, filled with
// that many copies of element t.
-fn init_elt[T](&T t, uint n_elts) -> vec[T] {
+fn init_elt[T](t: &T, n_elts: uint) -> vec[T] {
/**
* FIXME (issue #81): should be:
*
@@ -89,273 +85,261 @@
* ret init_fn[T](inner, n_elts);
*/
- let vec[T] v = alloc[T](n_elts);
- let uint i = n_elts;
- while (i > 0u) { i -= 1u; v += [t]; }
+ let v: vec[T] = alloc[T](n_elts);
+ let i: uint = n_elts;
+ while i > 0u { i -= 1u; v += [t]; }
ret v;
}
-fn init_elt_mut[T](&T t, uint n_elts) -> vec[mutable T] {
- let vec[mutable T] v = alloc_mut[T](n_elts);
- let uint i = n_elts;
- while (i > 0u) { i -= 1u; v += [mutable t]; }
+fn init_elt_mut[T](t: &T, n_elts: uint) -> vec[mutable T] {
+ let v: vec[mutable T] = alloc_mut[T](n_elts);
+ let i: uint = n_elts;
+ while i > 0u { i -= 1u; v += [mutable t]; }
ret v;
}
-fn buf[T](array[T] v) -> vbuf { ret rustrt::vec_buf[T](v, 0u); }
+fn buf[T](v: array[T]) -> vbuf { ret rustrt::vec_buf[T](v, 0u); }
-fn len[T](array[T] v) -> uint { ret rustrt::vec_len[T](v); }
+fn len[T](v: array[T]) -> uint { ret rustrt::vec_len[T](v); }
-fn len_set[T](array[T] v, uint n) { rustrt::vec_len_set[T](v, n); }
+fn len_set[T](v: array[T], n: uint) { rustrt::vec_len_set[T](v, n); }
-fn buf_off[T](array[T] v, uint offset) -> vbuf {
+fn buf_off[T](v: array[T], offset: uint) -> vbuf {
assert (offset < len[T](v));
ret rustrt::vec_buf[T](v, offset);
}
-fn print_debug_info[T](array[T] v) { rustrt::vec_print_debug_info[T](v); }
+fn print_debug_info[T](v: array[T]) { rustrt::vec_print_debug_info[T](v); }
// FIXME: typestate precondition (list is non-empty)
// Returns the last element of v.
-fn last[T](array[T] v) -> option::t[T] {
- auto l = len[T](v);
- if (l == 0u) { ret none[T]; }
+fn last[T](v: array[T]) -> option::t[T] {
+ let l = len[T](v);
+ if l == 0u { ret none[T]; }
ret some[T](v.(l - 1u));
}
// Returns elements from [start..end) from v.
-fn slice[T](array[T] v, uint start, uint end) -> vec[T] {
+fn slice[T](v: array[T], start: uint, end: uint) -> vec[T] {
assert (start <= end);
assert (end <= len[T](v));
- auto result = alloc[T](end - start);
- let uint i = start;
- while (i < end) { result += [v.(i)]; i += 1u; }
+ let result = alloc[T](end - start);
+ let i: uint = start;
+ while i < end { result += [v.(i)]; i += 1u; }
ret result;
}
// FIXME: Should go away eventually.
-fn slice_mut[T](array[T] v, uint start, uint end) -> vec[mutable T] {
+fn slice_mut[T](v: array[T], start: uint, end: uint) -> vec[mutable T] {
assert (start <= end);
assert (end <= len[T](v));
- auto result = alloc_mut[T](end - start);
- let uint i = start;
- while (i < end) { result += [mutable v.(i)]; i += 1u; }
+ let result = alloc_mut[T](end - start);
+ let i: uint = start;
+ while i < end { result += [mutable v.(i)]; i += 1u; }
ret result;
}
-fn shift[T](&mutable array[T] v) -> T {
- auto ln = len[T](v);
+fn shift[T](v: &mutable array[T]) -> T {
+ let ln = len[T](v);
assert (ln > 0u);
- auto e = v.(0);
+ let e = v.(0);
v = slice[T](v, 1u, ln);
ret e;
}
-fn pop[T](&mutable array[T] v) -> T {
- auto ln = len[T](v);
+fn pop[T](v: &mutable array[T]) -> T {
+ let ln = len[T](v);
assert (ln > 0u);
ln -= 1u;
- auto e = v.(ln);
+ let e = v.(ln);
v = slice[T](v, 0u, ln);
ret e;
}
-fn top[T](&array[T] v) -> T {
- auto ln = len[T](v);
+fn top[T](v: &array[T]) -> T {
+ let ln = len[T](v);
assert (ln > 0u);
ret v.(ln - 1u);
}
-fn push[T](&mutable array[T] v, &T t) { v += [t]; }
+fn push[T](v: &mutable array[T], t: &T) { v += [t]; }
-fn unshift[T](&mutable array[T] v, &T t) {
- auto rs = alloc[T](len[T](v) + 1u);
+fn unshift[T](v: &mutable array[T], t: &T) {
+ let rs = alloc[T](len[T](v) + 1u);
rs += [t];
rs += v;
v = rs;
}
-fn grow[T](&mutable array[T] v, uint n, &T initval) {
- let uint i = n;
- while (i > 0u) { i -= 1u; v += [initval]; }
+fn grow[T](v: &mutable array[T], n: uint, initval: &T) {
+ let i: uint = n;
+ while i > 0u { i -= 1u; v += [initval]; }
}
-fn grow_set[T](&mutable vec[mutable T] v, uint index, &T initval, &T val) {
- auto length = vec::len(v);
- if (index >= length) { grow(v, index - length + 1u, initval); }
+fn grow_set[T](v: &mutable vec[mutable T], index: uint, initval: &T,
+ val: &T) {
+ let length = vec::len(v);
+ if index >= length { grow(v, index - length + 1u, initval); }
v.(index) = val;
}
-fn grow_init_fn[T](&mutable array[T] v, uint n, fn() -> T init_fn) {
- let uint i = n;
- while (i > 0u) { i -= 1u; v += [init_fn()]; }
+fn grow_init_fn[T](v: &mutable array[T], n: uint, init_fn: fn() -> T ) {
+ let i: uint = n;
+ while i > 0u { i -= 1u; v += [init_fn()]; }
}
-fn grow_init_fn_set[T](&array[T] v, uint index, fn() -> T init_fn, &T val) {
- auto length = vec::len(v);
- if (index >= length) { grow_init_fn(v, index - length + 1u, init_fn); }
+fn grow_init_fn_set[T](v: &array[T], index: uint, init_fn: fn() -> T ,
+ val: &T) {
+ let length = vec::len(v);
+ if index >= length { grow_init_fn(v, index - length + 1u, init_fn); }
v.(index) = val;
}
-fn map[T, U](&fn(&T) -> U f, &vec[T] v) -> vec[U] {
- let vec[U] rs = alloc[U](len[T](v));
- for (T ve in v) { rs += [f(ve)]; }
+fn map[T, U](f: &fn(&T) -> U , v: &vec[T]) -> vec[U] {
+ let rs: vec[U] = alloc[U](len[T](v));
+ for ve: T in v { rs += [f(ve)]; }
ret rs;
}
-fn filter_map[T, U](&fn(&T) -> option::t[U] f, &vec[T] v) -> vec[U] {
- let vec[U] rs = [];
- for (T ve in v) {
- alt (f(ve)) { case (some(?elt)) { rs += [elt]; } case (none) { } }
- }
+fn filter_map[T, U](f: &fn(&T) -> option::t[U] , v: &vec[T]) -> vec[U] {
+ let rs: vec[U] = [];
+ for ve: T in v { alt f(ve) { some(elt) { rs += [elt]; } none. { } } }
ret rs;
}
-fn map2[T, U, V](&operator2[T, U, V] f, &vec[T] v0, &vec[U] v1) -> vec[V] {
- auto v0_len = len[T](v0);
- if (v0_len != len[U](v1)) { fail; }
- let vec[V] u = alloc[V](v0_len);
- auto i = 0u;
- while (i < v0_len) { u += [f({ v0.(i) }, { v1.(i) })]; i += 1u; }
+fn map2[T, U, V](f: &operator2[T, U, V], v0: &vec[T], v1: &vec[U]) -> vec[V] {
+ let v0_len = len[T](v0);
+ if v0_len != len[U](v1) { fail; }
+ let u: vec[V] = alloc[V](v0_len);
+ let i = 0u;
+ while i < v0_len { u += [f({ v0.(i) }, { v1.(i) })]; i += 1u; }
ret u;
}
-fn find[T](fn(&T) -> bool f, &vec[T] v) -> option::t[T] {
- for (T elt in v) { if (f(elt)) { ret some[T](elt); } }
+fn find[T](f: fn(&T) -> bool , v: &vec[T]) -> option::t[T] {
+ for elt: T in v { if f(elt) { ret some[T](elt); } }
ret none[T];
}
-fn position[T](&T x, &array[T] v) -> option::t[uint] {
- let uint i = 0u;
- while (i < len(v)) {
- if (x == v.(i)) { ret some[uint](i); }
- i += 1u;
- }
+fn position[T](x: &T, v: &array[T]) -> option::t[uint] {
+ let i: uint = 0u;
+ while i < len(v) { if x == v.(i) { ret some[uint](i); } i += 1u; }
ret none[uint];
}
-fn position_pred[T](fn (&T) -> bool f, &vec[T] v) -> option::t[uint] {
- let uint i = 0u;
- while (i < len(v)) {
- if (f(v.(i))) { ret some[uint](i); }
- i += 1u;
- }
+fn position_pred[T](f: fn(&T) -> bool , v: &vec[T]) -> option::t[uint] {
+ let i: uint = 0u;
+ while i < len(v) { if f(v.(i)) { ret some[uint](i); } i += 1u; }
ret none[uint];
}
-fn member[T](&T x, &array[T] v) -> bool {
- for (T elt in v) { if (x == elt) { ret true; } }
+fn member[T](x: &T, v: &array[T]) -> bool {
+ for elt: T in v { if x == elt { ret true; } }
ret false;
}
-fn count[T](&T x, &array[T] v) -> uint {
- auto cnt = 0u;
- for (T elt in v) { if (x == elt) { cnt += 1u; } }
+fn count[T](x: &T, v: &array[T]) -> uint {
+ let cnt = 0u;
+ for elt: T in v { if x == elt { cnt += 1u; } }
ret cnt;
}
-fn foldl[T, U](fn(&U, &T) -> U p, &U z, &vec[T] v) -> U {
- auto sz = len[T](v);
- if (sz == 0u) {
+fn foldl[T, U](p: fn(&U, &T) -> U , z: &U, v: &vec[T]) -> U {
+ let sz = len[T](v);
+ if sz == 0u {
ret z;
} else {
- auto rest = slice[T](v, 1u, sz);
+ let rest = slice[T](v, 1u, sz);
ret p(foldl[T, U](p, z, rest), v.(0));
}
}
-fn unzip[T, U](&vec[rec(T _0, U _1)] v) -> rec(vec[T] _0, vec[U] _1) {
- auto sz = len(v);
- if (sz == 0u) {
- ret rec(_0=alloc[T](0u), _1=alloc[U](0u));
+fn unzip[T, U](v: &vec[{_0: T, _1: U}]) -> {_0: vec[T], _1: vec[U]} {
+ let sz = len(v);
+ if sz == 0u {
+ ret {_0: alloc[T](0u), _1: alloc[U](0u)};
} else {
- auto rest = slice(v, 1u, sz);
- auto tl = unzip[T, U](rest);
- auto a = [v.(0)._0];
- auto b = [v.(0)._1];
- ret rec(_0=a + tl._0, _1=b + tl._1);
+ let rest = slice(v, 1u, sz);
+ let tl = unzip[T, U](rest);
+ let a = [v.(0)._0];
+ let b = [v.(0)._1];
+ ret {_0: a + tl._0, _1: b + tl._1};
}
}
// FIXME make the lengths being equal a constraint
-fn zip[T, U](&vec[T] v, &vec[U] u) -> vec[rec(T _0, U _1)] {
- auto sz = len(v);
+fn zip[T, U](v: &vec[T], u: &vec[U]) -> vec[{_0: T, _1: U}] {
+ let sz = len(v);
assert (sz == len(u));
- if (sz == 0u) {
+ if sz == 0u {
ret alloc(0u);
} else {
- auto rest = zip(slice(v, 1u, sz), slice(u, 1u, sz));
- vec::push(rest, rec(_0=v.(0), _1=u.(0)));
+ let rest = zip(slice(v, 1u, sz), slice(u, 1u, sz));
+ vec::push(rest, {_0: v.(0), _1: u.(0)});
ret rest;
}
}
-fn or(&vec[bool] v) -> bool {
- auto f = orb;
+fn or(v: &vec[bool]) -> bool {
+ let f = orb;
ret vec::foldl[bool, bool](f, false, v);
}
-fn any[T](&fn(&T) -> bool f, &vec[T] v) -> bool {
- for (T t in v) {
- if (f(t)) { ret true; }
- }
+fn any[T](f: &fn(&T) -> bool , v: &vec[T]) -> bool {
+ for t: T in v { if f(t) { ret true; } }
ret false;
}
-fn all[T](&fn(&T) -> bool f, &vec[T] v) -> bool {
- for (T t in v) {
- if (!f(t)) { ret false; }
- }
+fn all[T](f: &fn(&T) -> bool , v: &vec[T]) -> bool {
+ for t: T in v { if !f(t) { ret false; } }
ret true;
}
-fn clone[T](&vec[T] v) -> vec[T] { ret slice[T](v, 0u, len[T](v)); }
+fn clone[T](v: &vec[T]) -> vec[T] { ret slice[T](v, 0u, len[T](v)); }
-fn plus_option[T](&mutable vec[T] v, &option::t[T] o) {
- alt (o) { case (none) { } case (some(?x)) { v += [x]; } }
+fn plus_option[T](v: &mutable vec[T], o: &option::t[T]) {
+ alt o { none. { } some(x) { v += [x]; } }
}
-fn cat_options[T](&vec[option::t[T]] v) -> vec[T] {
- let vec[T] rs = [];
- for (option::t[T] o in v) {
- alt (o) { case (none) { } case (some(?t)) { rs += [t]; } }
- }
+fn cat_options[T](v: &vec[option::t[T]]) -> vec[T] {
+ let rs: vec[T] = [];
+ for o: option::t[T] in v { alt o { none. { } some(t) { rs += [t]; } } }
ret rs;
}
// TODO: Remove in favor of built-in "freeze" operation when it's implemented.
-fn freeze[T](vec[mutable T] v) -> vec[T] {
- let vec[T] result = [];
- for (T elem in v) { result += [elem]; }
+fn freeze[T](v: vec[mutable T]) -> vec[T] {
+ let result: vec[T] = [];
+ for elem: T in v { result += [elem]; }
ret result;
}
// Swaps two elements in a vector
-fn swap[T](&vec[mutable T] v, uint a, uint b) {
- let T t = v.(a);
+fn swap[T](v: &vec[mutable T], a: uint, b: uint) {
+ let t: T = v.(a);
v.(a) = v.(b);
v.(b) = t;
}
// In place vector reversal
-fn reverse[T](&vec[mutable T] v) {
- let uint i = 0u;
- auto ln = len[T](v);
- while (i < ln / 2u) { swap(v, i, ln - i - 1u); i += 1u; }
+fn reverse[T](v: &vec[mutable T]) {
+ let i: uint = 0u;
+ let ln = len[T](v);
+ while i < ln / 2u { swap(v, i, ln - i - 1u); i += 1u; }
}
// Functional vector reversal. Returns a reversed copy of v.
-fn reversed[T](vec[T] v) -> vec[T] {
- let vec[T] rs = [];
- auto i = len[T](v);
- if (i == 0u) { ret rs; } else { i -= 1u; }
- while (i != 0u) { push[T](rs, v.(i)); i -= 1u; }
+fn reversed[T](v: vec[T]) -> vec[T] {
+ let rs: vec[T] = [];
+ let i = len[T](v);
+ if i == 0u { ret rs; } else { i -= 1u; }
+ while i != 0u { push[T](rs, v.(i)); i -= 1u; }
push[T](rs, v.(0));
ret rs;
}
@@ -363,7 +347,7 @@
/// Truncates the vector to length `new_len`.
/// FIXME: This relies on a typechecker bug (covariance vs. invariance).
-fn truncate[T](&mutable vec[mutable? T] v, uint new_len) {
+fn truncate[T](v: &mutable vec[mutable? T], new_len: uint) {
v = slice[T](v, 0u, new_len);
}
// Local Variables:
diff --git a/src/lib/win32_fs.rs b/src/lib/win32_fs.rs
index 5e96e2b..ae3d683 100644
--- a/src/lib/win32_fs.rs
+++ b/src/lib/win32_fs.rs
@@ -1,18 +1,18 @@
native "rust" mod rustrt {
- fn rust_list_files(str path) -> vec[str];
- fn rust_list_files_ivec(str path) -> @str[];
- fn rust_file_is_dir(str path) -> int;
+ fn rust_list_files(path: str) -> vec[str];
+ fn rust_list_files_ivec(path: str) -> @str[];
+ fn rust_file_is_dir(path: str) -> int;
}
-fn list_dir(str path) -> str[] {
+fn list_dir(path: str) -> str[] {
ret *rustrt::rust_list_files_ivec(path + "*");
}
-fn path_is_absolute(str p) -> bool {
- ret str::char_at(p, 0u) == '/'
- || (str::char_at(p, 1u) == ':' && str::char_at(p, 2u) == '\\');
+fn path_is_absolute(p: str) -> bool {
+ ret str::char_at(p, 0u) == '/' ||
+ str::char_at(p, 1u) == ':' && str::char_at(p, 2u) == '\\';
}
/* FIXME: win32 path handling actually accepts '/' or '\' and has subtly
@@ -21,9 +21,9 @@
* joining pathnames needs a bit more abstraction on win32. Possibly a vec or
* tag type.
*/
-const char path_sep = '/';
+const path_sep: char = '/';
-const char alt_path_sep = '\\';
+const alt_path_sep: char = '\\';
// Local Variables:
// mode: rust;
// fill-column: 78;
diff --git a/src/lib/win32_os.rs b/src/lib/win32_os.rs
index 15d950b..65ee769 100644
--- a/src/lib/win32_os.rs
+++ b/src/lib/win32_os.rs
@@ -3,41 +3,41 @@
import vec::vbuf;
native "cdecl" mod libc = "" {
- fn open(sbuf s, int flags, uint mode) -> int = "_open";
- fn read(int fd, vbuf buf, uint count) -> int = "_read";
- fn write(int fd, vbuf buf, uint count) -> int = "_write";
- fn close(int fd) -> int = "_close";
+ fn open(s: sbuf, flags: int, mode: uint) -> int = "_open";
+ fn read(fd: int, buf: vbuf, count: uint) -> int = "_read";
+ fn write(fd: int, buf: vbuf, count: uint) -> int = "_write";
+ fn close(fd: int) -> int = "_close";
type FILE;
- fn fopen(sbuf path, sbuf mode) -> FILE;
- fn _fdopen(int fd, sbuf mode) -> FILE;
- fn fclose(FILE f);
- fn fgetc(FILE f) -> int;
- fn ungetc(int c, FILE f);
- fn feof(FILE f) -> int;
- fn fread(vbuf buf, uint size, uint n, FILE f) -> uint;
- fn fwrite(vbuf buf, uint size, uint n, FILE f) -> uint;
- fn fseek(FILE f, int offset, int whence) -> int;
- fn ftell(FILE f) -> int;
- fn _pipe(*mutable int fds, uint size, int mode) -> int;
+ fn fopen(path: sbuf, mode: sbuf) -> FILE;
+ fn _fdopen(fd: int, mode: sbuf) -> FILE;
+ fn fclose(f: FILE);
+ fn fgetc(f: FILE) -> int;
+ fn ungetc(c: int, f: FILE);
+ fn feof(f: FILE) -> int;
+ fn fread(buf: vbuf, size: uint, n: uint, f: FILE) -> uint;
+ fn fwrite(buf: vbuf, size: uint, n: uint, f: FILE) -> uint;
+ fn fseek(f: FILE, offset: int, whence: int) -> int;
+ fn ftell(f: FILE) -> int;
+ fn _pipe(fds: *mutable int, size: uint, mode: int) -> int;
}
native "cdecl" mod libc_ivec = "" {
- fn read(int fd, *u8 buf, uint count) -> int;
- fn write(int fd, *u8 buf, uint count) -> int;
- fn fread(*u8 buf, uint size, uint n, libc::FILE f) -> uint;
- fn fwrite(*u8 buf, uint size, uint n, libc::FILE f) -> uint;
+ fn read(fd: int, buf: *u8, count: uint) -> int;
+ fn write(fd: int, buf: *u8, count: uint) -> int;
+ fn fread(buf: *u8, size: uint, n: uint, f: libc::FILE) -> uint;
+ fn fwrite(buf: *u8, size: uint, n: uint, f: libc::FILE) -> uint;
}
mod libc_constants {
fn O_RDONLY() -> int { ret 0; }
fn O_WRONLY() -> int { ret 1; }
fn O_RDWR() -> int { ret 2; }
- fn O_APPEND() -> int { ret 0x0008; }
- fn O_CREAT() -> int { ret 0x0100; }
- fn O_EXCL() -> int { ret 0x0400; }
- fn O_TRUNC() -> int { ret 0x0200; }
- fn O_TEXT() -> int { ret 0x4000; }
- fn O_BINARY() -> int { ret 0x8000; }
+ fn O_APPEND() -> int { ret 8; }
+ fn O_CREAT() -> int { ret 256; }
+ fn O_EXCL() -> int { ret 1024; }
+ fn O_TRUNC() -> int { ret 512; }
+ fn O_TEXT() -> int { ret 16384; }
+ fn O_BINARY() -> int { ret 32768; }
fn S_IRUSR() -> uint {
ret 256u; // really _S_IREAD in win32
@@ -49,31 +49,31 @@
}
native "x86stdcall" mod kernel32 {
- fn GetEnvironmentVariableA(sbuf n, sbuf v, uint nsize) -> uint;
- fn SetEnvironmentVariableA(sbuf n, sbuf v) -> int;
+ fn GetEnvironmentVariableA(n: sbuf, v: sbuf, nsize: uint) -> uint;
+ fn SetEnvironmentVariableA(n: sbuf, v: sbuf) -> int;
}
fn exec_suffix() -> str { ret ".exe"; }
fn target_os() -> str { ret "win32"; }
-fn dylib_filename(str base) -> str { ret base + ".dll"; }
+fn dylib_filename(base: str) -> str { ret base + ".dll"; }
-fn pipe() -> rec(int in, int out) {
- auto fds = rec(mutable in=0, mutable out=0);
+fn pipe() -> {in: int, out: int} {
+ let fds = {mutable in: 0, mutable out: 0};
assert (os::libc::_pipe(ptr::addr_of(fds.in), 1024u,
libc_constants::O_BINARY()) == 0);
- ret rec(in=fds.in, out=fds.out);
+ ret {in: fds.in, out: fds.out};
}
-fn fd_FILE(int fd) -> libc::FILE { ret libc::_fdopen(fd, str::buf("r")); }
+fn fd_FILE(fd: int) -> libc::FILE { ret libc::_fdopen(fd, str::buf("r")); }
native "rust" mod rustrt {
- fn rust_process_wait(int handle) -> int;
+ fn rust_process_wait(handle: int) -> int;
fn rust_getcwd() -> str;
}
-fn waitpid(int pid) -> int { ret rustrt::rust_process_wait(pid); }
+fn waitpid(pid: int) -> int { ret rustrt::rust_process_wait(pid); }
fn getcwd() -> str { ret rustrt::rust_getcwd(); }
diff --git a/src/test/bench/99bob-iter.rs b/src/test/bench/99bob-iter.rs
index b077aac..3807c89 100644
--- a/src/test/bench/99bob-iter.rs
+++ b/src/test/bench/99bob-iter.rs
@@ -22,19 +22,17 @@
ret "Go to the store and buy some more, # of beer on the wall.";
}
-fn sub(str t, int n) -> str {
- let str b = "";
- let uint i = 0u;
- let str ns;
- alt (n) {
- case (0) { ns = "no more bottles"; }
- case (1) { ns = "1 bottle"; }
- case (_) { ns = int::to_str(n, 10u) + " bottles"; }
+fn sub(t: str, n: int) -> str {
+ let b: str = "";
+ let i: uint = 0u;
+ let ns: str;
+ alt n {
+ 0 { ns = "no more bottles"; }
+ 1 { ns = "1 bottle"; }
+ _ { ns = int::to_str(n, 10u) + " bottles"; }
}
- while (i < str::byte_len(t)) {
- if (t.(i) == '#' as u8) {
- b += ns;
- } else { str::push_byte(b, t.(i)); }
+ while i < str::byte_len(t) {
+ if t.(i) == '#' as u8 { b += ns; } else { str::push_byte(b, t.(i)); }
i += 1u;
}
ret b;
@@ -42,10 +40,10 @@
/* Using an interator */
-iter ninetynine() -> int { let int n = 100; while (n > 1) { n -= 1; put n; } }
+iter ninetynine() -> int { let n: int = 100; while n > 1 { n -= 1; put n; } }
fn main() {
- for each (int n in ninetynine()) {
+ for each n: int in ninetynine() {
log sub(b1(), n);
log sub(b2(), n - 1);
log "";
diff --git a/src/test/bench/99bob-pattern.rs b/src/test/bench/99bob-pattern.rs
index d4790d3..4bbea0c 100644
--- a/src/test/bench/99bob-pattern.rs
+++ b/src/test/bench/99bob-pattern.rs
@@ -10,53 +10,50 @@
tag bottle { none; dual; single; multiple(int); }
-fn show(bottle b) {
- alt (b) {
- case (none) {
- log "No more bottles of beer on the wall, " +
- "no more bottles of beer,";
- log "Go to the store and buy some more, " +
- "99 bottles of beer on the wall.";
- }
- case (single) {
- log "1 bottle of beer on the wall, 1 bottle of beer,";
- log "Take one down and pass it around, " +
- "no more bottles of beer on the wall.";
- }
- case (dual) {
- log "2 bottles of beer on the wall, 2 bottles of beer,";
- log "Take one down and pass it around, " +
- "1 bottle of beer on the wall.";
- }
- case (multiple(?n)) {
- let str nb = int::to_str(n, 10u);
- let str mb = int::to_str(n - 1, 10u);
- log nb + " bottles of beer on the wall, " + nb +
- " bottles of beer,";
- log "Take one down and pass it around, " + mb +
- " bottles of beer on the wall.";
- }
+fn show(b: bottle) {
+ alt b {
+ none. {
+ log "No more bottles of beer on the wall, " +
+ "no more bottles of beer,";
+ log "Go to the store and buy some more, " +
+ "99 bottles of beer on the wall.";
+ }
+ single. {
+ log "1 bottle of beer on the wall, 1 bottle of beer,";
+ log "Take one down and pass it around, " +
+ "no more bottles of beer on the wall.";
+ }
+ dual. {
+ log "2 bottles of beer on the wall, 2 bottles of beer,";
+ log "Take one down and pass it around, " +
+ "1 bottle of beer on the wall.";
+ }
+ multiple(n) {
+ let nb: str = int::to_str(n, 10u);
+ let mb: str = int::to_str(n - 1, 10u);
+ log nb + " bottles of beer on the wall, " + nb + " bottles of beer,";
+ log "Take one down and pass it around, " + mb +
+ " bottles of beer on the wall.";
+ }
}
}
-fn next(bottle b) -> bottle {
- alt (b) {
- case (none) { ret none; }
- case (single) { ret none; }
- case (dual) { ret single; }
- case (multiple(3)) { ret dual; }
- case (multiple(?n)) { ret multiple(n - 1); }
+fn next(b: bottle) -> bottle {
+ alt b {
+ none. { ret none; }
+ single. { ret none; }
+ dual. { ret single; }
+ multiple(3) { ret dual; }
+ multiple(n) { ret multiple(n - 1); }
}
}
// Won't need this when tags can be compared with ==
-fn more(bottle b) -> bool {
- alt (b) { case (none) { ret false; } case (_) { ret true; } }
-}
+fn more(b: bottle) -> bool { alt b { none. { ret false; } _ { ret true; } } }
fn main() {
- let bottle b = multiple(99);
- let bool running = true;
- while (running) { show(b); log ""; running = more(b); b = next(b); }
+ let b: bottle = multiple(99);
+ let running: bool = true;
+ while running { show(b); log ""; running = more(b); b = next(b); }
}
\ No newline at end of file
diff --git a/src/test/bench/99bob-simple.rs b/src/test/bench/99bob-simple.rs
index 3135030..205ab67 100644
--- a/src/test/bench/99bob-simple.rs
+++ b/src/test/bench/99bob-simple.rs
@@ -22,19 +22,17 @@
ret "Go to the store and buy some more, # of beer on the wall.";
}
-fn sub(str t, int n) -> str {
- let str b = "";
- let uint i = 0u;
- let str ns;
- alt (n) {
- case (0) { ns = "no more bottles"; }
- case (1) { ns = "1 bottle"; }
- case (_) { ns = int::to_str(n, 10u) + " bottles"; }
+fn sub(t: str, n: int) -> str {
+ let b: str = "";
+ let i: uint = 0u;
+ let ns: str;
+ alt n {
+ 0 { ns = "no more bottles"; }
+ 1 { ns = "1 bottle"; }
+ _ { ns = int::to_str(n, 10u) + " bottles"; }
}
- while (i < str::byte_len(t)) {
- if (t.(i) == '#' as u8) {
- b += ns;
- } else { str::push_byte(b, t.(i)); }
+ while i < str::byte_len(t) {
+ if t.(i) == '#' as u8 { b += ns; } else { str::push_byte(b, t.(i)); }
i += 1u;
}
ret b;
@@ -43,8 +41,8 @@
/* Straightforward counter */
fn main() {
- let int n = 99;
- while (n > 0) { log sub(b1(), n); log sub(b2(), n - 1); log ""; n -= 1; }
+ let n: int = 99;
+ while n > 0 { log sub(b1(), n); log sub(b2(), n - 1); log ""; n -= 1; }
log b7();
log sub(b8(), 99);
}
\ No newline at end of file
diff --git a/src/test/bench/99bob-tail.rs b/src/test/bench/99bob-tail.rs
index d1612e2..c68d77f 100644
--- a/src/test/bench/99bob-tail.rs
+++ b/src/test/bench/99bob-tail.rs
@@ -7,14 +7,14 @@
import std::str;
fn main() {
- fn multiple(int n) {
- let str nb = int::to_str(n, 10u);
- let str mb = int::to_str(n - 1, 10u);
+ fn multiple(n: int) {
+ let nb: str = int::to_str(n, 10u);
+ let mb: str = int::to_str(n - 1, 10u);
log nb + " bottles of beer on the wall, " + nb + " bottles of beer,";
log "Take one down and pass it around, " + mb +
" bottles of beer on the wall.";
log "";
- if (n > 3) { be multiple(n - 1); } else { be dual(); }
+ if n > 3 { be multiple(n - 1); } else { be dual(); }
}
fn dual() {
log "2 bottles of beer on the wall, 2 bottles of beer,";
@@ -32,7 +32,7 @@
fn none() {
log "No more bottles of beer on the wall, no more bottles of beer,";
log "Go to the store and buy some more, " +
- "99 bottles of beer on the wall.";
+ "99 bottles of beer on the wall.";
log "";
}
multiple(99);
diff --git a/src/test/bench/shootout-ackermann.rs b/src/test/bench/shootout-ackermann.rs
index 868cee4..91e524d 100644
--- a/src/test/bench/shootout-ackermann.rs
+++ b/src/test/bench/shootout-ackermann.rs
@@ -2,11 +2,11 @@
// -*- rust -*-
-fn ack(int m, int n) -> int {
- if (m == 0) {
+fn ack(m: int, n: int) -> int {
+ if m == 0 {
ret n + 1;
} else {
- if (n == 0) {
+ if n == 0 {
ret ack(m - 1, 1);
} else { ret ack(m - 1, ack(m, n - 1)); }
}
diff --git a/src/test/bench/shootout-binarytrees.rs b/src/test/bench/shootout-binarytrees.rs
index ebbcc69..d7b5f52 100644
--- a/src/test/bench/shootout-binarytrees.rs
+++ b/src/test/bench/shootout-binarytrees.rs
@@ -4,41 +4,41 @@
tag tree { nil; node(@tree, @tree, int); }
-fn item_check(@tree t) -> int {
- alt (*t) {
- case (nil) { ret 0; }
- case (node(?left, ?right, ?item)) {
- ret item + item_check(left) - item_check(right);
- }
+fn item_check(t: @tree) -> int {
+ alt *t {
+ nil. { ret 0; }
+ node(left, right, item) {
+ ret item + item_check(left) - item_check(right);
+ }
}
}
-fn bottom_up_tree(int item, int depth) -> @tree {
- if (depth > 0) {
+fn bottom_up_tree(item: int, depth: int) -> @tree {
+ if depth > 0 {
ret @node(bottom_up_tree(2 * item - 1, depth - 1),
bottom_up_tree(2 * item, depth - 1), item);
} else { ret @nil; }
}
fn main() {
- auto n = 8;
- auto min_depth = 4;
- auto max_depth;
- if (min_depth + 2 > n) {
+ let n = 8;
+ let min_depth = 4;
+ let max_depth;
+ if min_depth + 2 > n {
max_depth = min_depth + 2;
} else { max_depth = n; }
- auto stretch_depth = max_depth + 1;
- auto stretch_tree = bottom_up_tree(0, stretch_depth);
+ let stretch_depth = max_depth + 1;
+ let stretch_tree = bottom_up_tree(0, stretch_depth);
log #fmt("stretch tree of depth %d\t check: %d", stretch_depth,
item_check(stretch_tree));
- auto long_lived_tree = bottom_up_tree(0, max_depth);
- auto depth = min_depth;
- while (depth <= max_depth) {
- auto iterations = int::pow(2, max_depth - depth + min_depth as uint);
- auto chk = 0;
- auto i = 1;
- while (i <= iterations) {
- auto temp_tree = bottom_up_tree(i, depth);
+ let long_lived_tree = bottom_up_tree(0, max_depth);
+ let depth = min_depth;
+ while depth <= max_depth {
+ let iterations = int::pow(2, max_depth - depth + min_depth as uint);
+ let chk = 0;
+ let i = 1;
+ while i <= iterations {
+ let temp_tree = bottom_up_tree(i, depth);
chk += item_check(temp_tree);
temp_tree = bottom_up_tree(-i, depth);
chk += item_check(temp_tree);
diff --git a/src/test/bench/shootout-fannkuchredux.rs b/src/test/bench/shootout-fannkuchredux.rs
index 02208a4..6e1f12f 100644
--- a/src/test/bench/shootout-fannkuchredux.rs
+++ b/src/test/bench/shootout-fannkuchredux.rs
@@ -5,33 +5,33 @@
import std::int;
import std::vec;
-fn fannkuch(int n) -> int {
- fn perm1init(uint i) -> int { ret i as int; }
- auto perm1init_ = perm1init; // Rustboot workaround
+fn fannkuch(n: int) -> int {
+ fn perm1init(i: uint) -> int { ret i as int; }
+ let perm1init_ = perm1init; // Rustboot workaround
- auto perm = vec::init_elt_mut(0, n as uint);
- auto perm1 = vec::init_fn_mut(perm1init_, n as uint);
- auto count = vec::init_elt_mut(0, n as uint);
- auto f = 0;
- auto i = 0;
- auto k = 0;
- auto r = 0;
- auto flips = 0;
- auto nperm = 0;
- auto checksum = 0;
+ let perm = vec::init_elt_mut(0, n as uint);
+ let perm1 = vec::init_fn_mut(perm1init_, n as uint);
+ let count = vec::init_elt_mut(0, n as uint);
+ let f = 0;
+ let i = 0;
+ let k = 0;
+ let r = 0;
+ let flips = 0;
+ let nperm = 0;
+ let checksum = 0;
r = n;
- while (r > 0) {
+ while r > 0 {
i = 0;
- while (r != 1) { count.(r - 1) = r; r -= 1; }
- while (i < n) { perm.(i) = perm1.(i); i += 1; }
+ while r != 1 { count.(r - 1) = r; r -= 1; }
+ while i < n { perm.(i) = perm1.(i); i += 1; }
// Count flips and update max and checksum
f = 0;
k = perm.(0);
- while (k != 0) {
+ while k != 0 {
i = 0;
- while (2 * i < k) {
- auto t = perm.(i);
+ while 2 * i < k {
+ let t = perm.(i);
perm.(i) = perm.(k - i);
perm.(k - i) = t;
i += 1;
@@ -39,26 +39,26 @@
k = perm.(0);
f += 1;
}
- if (f > flips) { flips = f; }
- if (nperm & 0x1 == 0) { checksum += f; } else { checksum -= f; }
+ if f > flips { flips = f; }
+ if nperm & 0x1 == 0 { checksum += f; } else { checksum -= f; }
// Use incremental change to generate another permutation
- auto go = true;
- while (go) {
- if (r == n) { log checksum; ret flips; }
- auto p0 = perm1.(0);
+ let go = true;
+ while go {
+ if r == n { log checksum; ret flips; }
+ let p0 = perm1.(0);
i = 0;
- while (i < r) { auto j = i + 1; perm1.(i) = perm1.(j); i = j; }
+ while i < r { let j = i + 1; perm1.(i) = perm1.(j); i = j; }
perm1.(r) = p0;
count.(r) -= 1;
- if (count.(r) > 0) { go = false; } else { r += 1; }
+ if count.(r) > 0 { go = false; } else { r += 1; }
}
nperm += 1;
}
ret flips;
}
-fn main(vec[str] args) {
- auto n = 7;
+fn main(args: vec[str]) {
+ let n = 7;
log #fmt("Pfannkuchen(%d) = %d", n, fannkuch(n));
}
\ No newline at end of file
diff --git a/src/test/bench/shootout-fasta.rs b/src/test/bench/shootout-fasta.rs
index 6d8cec5..4e38aba 100644
--- a/src/test/bench/shootout-fasta.rs
+++ b/src/test/bench/shootout-fasta.rs
@@ -13,29 +13,29 @@
fn LINE_LENGTH() -> uint { ret 60u; }
-obj myrandom(mutable u32 last) {
- fn next(u32 mx) -> u32 {
+obj myrandom(mutable last: u32) {
+ fn next(mx: u32) -> u32 {
last = (last * 3877u32 + 29573u32) % 139968u32;
- auto ans = mx * last / 139968u32;
+ let ans = mx * last / 139968u32;
ret ans;
}
}
-type aminoacids = rec(char ch, u32 prob);
+type aminoacids = {ch: char, prob: u32};
-fn make_cumulative(vec[aminoacids] aa) -> vec[aminoacids] {
- let u32 cp = 0u32;
- let vec[aminoacids] ans = [];
- for (aminoacids a in aa) { cp += a.prob; ans += [rec(ch=a.ch, prob=cp)]; }
+fn make_cumulative(aa: vec[aminoacids]) -> vec[aminoacids] {
+ let cp: u32 = 0u32;
+ let ans: vec[aminoacids] = [];
+ for a: aminoacids in aa { cp += a.prob; ans += [{ch: a.ch, prob: cp}]; }
ret ans;
}
-fn select_random(u32 r, vec[aminoacids] genelist) -> char {
- if (r < genelist.(0).prob) { ret genelist.(0).ch; }
- fn bisect(vec[aminoacids] v, uint lo, uint hi, u32 target) -> char {
- if (hi > lo + 1u) {
- let uint mid = lo + (hi - lo) / 2u;
- if (target < v.(mid).prob) {
+fn select_random(r: u32, genelist: vec[aminoacids]) -> char {
+ if r < genelist.(0).prob { ret genelist.(0).ch; }
+ fn bisect(v: vec[aminoacids], lo: uint, hi: uint, target: u32) -> char {
+ if hi > lo + 1u {
+ let mid: uint = lo + (hi - lo) / 2u;
+ if target < v.(mid).prob {
be bisect(v, lo, mid, target);
} else { be bisect(v, mid, hi, target); }
} else { ret v.(hi).ch; }
@@ -43,41 +43,41 @@
ret bisect(genelist, 0u, vec::len[aminoacids](genelist) - 1u, r);
}
-fn make_random_fasta(str id, str desc, vec[aminoacids] genelist, int n) {
+fn make_random_fasta(id: str, desc: str, genelist: vec[aminoacids], n: int) {
log ">" + id + " " + desc;
- auto rng = myrandom(std::rand::mk_rng().next());
- let str op = "";
- for each (uint i in uint::range(0u, n as uint)) {
+ let rng = myrandom(std::rand::mk_rng().next());
+ let op: str = "";
+ for each i: uint in uint::range(0u, n as uint) {
str::push_byte(op, select_random(rng.next(100u32), genelist) as u8);
- if (str::byte_len(op) >= LINE_LENGTH()) { log op; op = ""; }
+ if str::byte_len(op) >= LINE_LENGTH() { log op; op = ""; }
}
- if (str::byte_len(op) > 0u) { log op; }
+ if str::byte_len(op) > 0u { log op; }
}
-fn make_repeat_fasta(str id, str desc, str s, int n) {
+fn make_repeat_fasta(id: str, desc: str, s: str, n: int) {
log ">" + id + " " + desc;
- let str op = "";
- let uint sl = str::byte_len(s);
- for each (uint i in uint::range(0u, n as uint)) {
+ let op: str = "";
+ let sl: uint = str::byte_len(s);
+ for each i: uint in uint::range(0u, n as uint) {
str::push_byte(op, s.(i % sl));
- if (str::byte_len(op) >= LINE_LENGTH()) { log op; op = ""; }
+ if str::byte_len(op) >= LINE_LENGTH() { log op; op = ""; }
}
- if (str::byte_len(op) > 0u) { log op; }
+ if str::byte_len(op) > 0u { log op; }
}
-fn acid(char ch, u32 prob) -> aminoacids { ret rec(ch=ch, prob=prob); }
+fn acid(ch: char, prob: u32) -> aminoacids { ret {ch: ch, prob: prob}; }
-fn main(vec[str] args) {
- let vec[aminoacids] iub =
+fn main(args: vec[str]) {
+ let iub: vec[aminoacids] =
make_cumulative([acid('a', 27u32), acid('c', 12u32), acid('g', 12u32),
acid('t', 27u32), acid('B', 2u32), acid('D', 2u32),
acid('H', 2u32), acid('K', 2u32), acid('M', 2u32),
acid('N', 2u32), acid('R', 2u32), acid('S', 2u32),
acid('V', 2u32), acid('W', 2u32), acid('Y', 2u32)]);
- let vec[aminoacids] homosapiens =
+ let homosapiens: vec[aminoacids] =
make_cumulative([acid('a', 30u32), acid('c', 20u32), acid('g', 20u32),
acid('t', 30u32)]);
- let str alu =
+ let alu: str =
"GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" +
"GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" +
"CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT" +
@@ -85,7 +85,7 @@
"GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG" +
"AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC" +
"AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA";
- let int n = 512;
+ let n: int = 512;
make_repeat_fasta("ONE", "Homo sapiens alu", alu, n * 2);
make_random_fasta("TWO", "IUB ambiguity codes", iub, n * 3);
make_random_fasta("THREE", "Homo sapiens frequency", homosapiens, n * 5);
diff --git a/src/test/bench/shootout-fibo.rs b/src/test/bench/shootout-fibo.rs
index 1230358..37590c0 100644
--- a/src/test/bench/shootout-fibo.rs
+++ b/src/test/bench/shootout-fibo.rs
@@ -2,13 +2,14 @@
// -*- rust -*-
-fn fib(int n) -> int {
+fn fib(n: int) -> int {
+
// Several of the posted 'benchmark' versions of this compute the
// wrong Fibonacci numbers, of course.
- if (n == 0) {
+ if n == 0 {
ret 0;
- } else { if (n <= 2) { ret 1; } else { ret fib(n - 1) + fib(n - 2); } }
+ } else { if n <= 2 { ret 1; } else { ret fib(n - 1) + fib(n - 2); } }
}
fn main() {
diff --git a/src/test/bench/shootout-nbody.rs b/src/test/bench/shootout-nbody.rs
index 540be7c..4168df1 100644
--- a/src/test/bench/shootout-nbody.rs
+++ b/src/test/bench/shootout-nbody.rs
@@ -2,32 +2,29 @@
// http://shootout.alioth.debian.org/u32/benchmark.php?test=nbody&lang=java
native "llvm" mod llvm {
- fn sqrt(float n) -> float = "sqrt.f64";
+ fn sqrt(n: float) -> float = "sqrt.f64";
}
fn main() {
- let vec[int] inputs = [
- 50000,
- 500000
- //
- // Leave these commented out to
- // finish in a reasonable time
- // during 'make check' under valgrind
- // 5000000
- // 50000000
- ];
+ let
+ //
+ // Leave these commented out to
+ // finish in a reasonable time
+ // during 'make check' under valgrind
+ // 5000000
+ // 50000000
+ inputs: vec[int] =
+ [50000, 500000];
- let vec[Body::props] bodies = NBodySystem::MakeNBodySystem();
+ let bodies: vec[Body::props] = NBodySystem::MakeNBodySystem();
- for (int n in inputs) {
+
+ for n: int in inputs {
log NBodySystem::energy(bodies);
- let int i = 0;
- while (i < n) {
- NBodySystem::advance(bodies, 0.01);
- i += 1;
- }
+ let i: int = 0;
+ while i < n { NBodySystem::advance(bodies, 0.01); i += 1; }
log NBodySystem::energy(bodies);
}
}
@@ -38,20 +35,18 @@
mod NBodySystem {
fn MakeNBodySystem() -> vec[Body::props] {
- let vec[Body::props] bodies = [
+ let
// these each return a Body::props
- Body::sun(),
- Body::jupiter(),
- Body::saturn(),
- Body::uranus(),
- Body::neptune()];
+ bodies: vec[Body::props] =
+ [Body::sun(), Body::jupiter(), Body::saturn(), Body::uranus(),
+ Body::neptune()];
- let float px = 0.0;
- let float py = 0.0;
- let float pz = 0.0;
+ let px: float = 0.0;
+ let py: float = 0.0;
+ let pz: float = 0.0;
- let int i = 0;
- while (i < 5) {
+ let i: int = 0;
+ while i < 5 {
px += bodies.(i).vx * bodies.(i).mass;
py += bodies.(i).vy * bodies.(i).mass;
pz += bodies.(i).vz * bodies.(i).mass;
@@ -65,35 +60,29 @@
ret bodies;
}
- fn advance(vec[Body::props] bodies, float dt) -> () {
+ fn advance(bodies: vec[Body::props], dt: float) {
- let int i = 0;
- while (i < 5) {
- let int j = i+1;
- while (j < 5) {
- advance_one(bodies.(i), bodies.(j), dt);
- j += 1;
- }
+ let i: int = 0;
+ while i < 5 {
+ let j: int = i + 1;
+ while j < 5 { advance_one(bodies.(i), bodies.(j), dt); j += 1; }
i += 1;
}
i = 0;
- while (i < 5) {
- move(bodies.(i), dt);
- i += 1;
- }
+ while i < 5 { move(bodies.(i), dt); i += 1; }
}
- fn advance_one(&Body::props bi, &Body::props bj, float dt) {
- let float dx = bi.x - bj.x;
- let float dy = bi.y - bj.y;
- let float dz = bi.z - bj.z;
+ fn advance_one(bi: &Body::props, bj: &Body::props, dt: float) {
+ let dx: float = bi.x - bj.x;
+ let dy: float = bi.y - bj.y;
+ let dz: float = bi.z - bj.z;
- let float dSquared = dx * dx + dy * dy + dz * dz;
+ let dSquared: float = dx * dx + dy * dy + dz * dz;
- let float distance = llvm::sqrt(dSquared);
- let float mag = dt / (dSquared * distance);
+ let distance: float = llvm::sqrt(dSquared);
+ let mag: float = dt / (dSquared * distance);
bi.vx -= dx * bj.mass * mag;
bi.vy -= dy * bj.mass * mag;
@@ -104,34 +93,35 @@
bj.vz += dz * bi.mass * mag;
}
- fn move(&Body::props b, float dt) {
+ fn move(b: &Body::props, dt: float) {
b.x += dt * b.vx;
b.y += dt * b.vy;
b.z += dt * b.vz;
}
- fn energy(vec[Body::props] bodies) -> float {
- let float dx;
- let float dy;
- let float dz;
- let float distance;
- let float e = 0.0;
+ fn energy(bodies: vec[Body::props]) -> float {
+ let dx: float;
+ let dy: float;
+ let dz: float;
+ let distance: float;
+ let e: float = 0.0;
- let int i = 0;
- while (i < 5) {
- e += 0.5 * bodies.(i).mass *
- ( bodies.(i).vx * bodies.(i).vx
- + bodies.(i).vy * bodies.(i).vy
- + bodies.(i).vz * bodies.(i).vz );
+ let i: int = 0;
+ while i < 5 {
+ e +=
+ 0.5 * bodies.(i).mass *
+ (bodies.(i).vx * bodies.(i).vx +
+ bodies.(i).vy * bodies.(i).vy +
+ bodies.(i).vz * bodies.(i).vz);
- let int j = i+1;
- while (j < 5) {
+ let j: int = i + 1;
+ while j < 5 {
dx = bodies.(i).x - bodies.(j).x;
dy = bodies.(i).y - bodies.(j).y;
dz = bodies.(i).z - bodies.(j).z;
- distance = llvm::sqrt(dx*dx + dy*dy + dz*dz);
- e -= (bodies.(i).mass * bodies.(j).mass) / distance;
+ distance = llvm::sqrt(dx * dx + dy * dy + dz * dz);
+ e -= bodies.(i).mass * bodies.(j).mass / distance;
j += 1;
}
@@ -145,85 +135,74 @@
mod Body {
- const float PI = 3.141592653589793;
- const float SOLAR_MASS = 39.478417604357432; // was 4 * PI * PI originally
- const float DAYS_PER_YEAR = 365.24;
+ const PI: float = 3.141592653589793;
+ const SOLAR_MASS: float = 39.478417604357432;
+ // was 4 * PI * PI originally
+ const DAYS_PER_YEAR: float = 365.24;
- type props = rec(mutable float x,
- mutable float y,
- mutable float z,
- mutable float vx,
- mutable float vy,
- mutable float vz,
- float mass);
+ type props =
+ {mutable x: float,
+ mutable y: float,
+ mutable z: float,
+ mutable vx: float,
+ mutable vy: float,
+ mutable vz: float,
+ mass: float};
fn jupiter() -> Body::props {
- ret rec(
- mutable x = 4.84143144246472090e+00,
- mutable y = -1.16032004402742839e+00,
- mutable z = -1.03622044471123109e-01,
- mutable vx = 1.66007664274403694e-03 * DAYS_PER_YEAR,
- mutable vy = 7.69901118419740425e-03 * DAYS_PER_YEAR,
- mutable vz = -6.90460016972063023e-05 * DAYS_PER_YEAR,
- mass = 9.54791938424326609e-04 * SOLAR_MASS
- );
+ ret {mutable x: 4.84143144246472090e+00,
+ mutable y: -1.16032004402742839e+00,
+ mutable z: -1.03622044471123109e-01,
+ mutable vx: 1.66007664274403694e-03 * DAYS_PER_YEAR,
+ mutable vy: 7.69901118419740425e-03 * DAYS_PER_YEAR,
+ mutable vz: -6.90460016972063023e-05 * DAYS_PER_YEAR,
+ mass: 9.54791938424326609e-04 * SOLAR_MASS};
}
fn saturn() -> Body::props {
- ret rec(
- mutable x = 8.34336671824457987e+00,
- mutable y = 4.12479856412430479e+00,
- mutable z = -4.03523417114321381e-01,
- mutable vx = -2.76742510726862411e-03 * DAYS_PER_YEAR,
- mutable vy = 4.99852801234917238e-03 * DAYS_PER_YEAR,
- mutable vz = 2.30417297573763929e-05 * DAYS_PER_YEAR,
- mass = 2.85885980666130812e-04 * SOLAR_MASS
- );
- }
+ ret {mutable x: 8.34336671824457987e+00,
+ mutable y: 4.12479856412430479e+00,
+ mutable z: -4.03523417114321381e-01,
+ mutable vx: -2.76742510726862411e-03 * DAYS_PER_YEAR,
+ mutable vy: 4.99852801234917238e-03 * DAYS_PER_YEAR,
+ mutable vz: 2.30417297573763929e-05 * DAYS_PER_YEAR,
+ mass: 2.85885980666130812e-04 * SOLAR_MASS};
+ }
fn uranus() -> Body::props {
- ret rec(
- mutable x = 1.28943695621391310e+01,
- mutable y = -1.51111514016986312e+01,
- mutable z = -2.23307578892655734e-01,
- mutable vx = 2.96460137564761618e-03 * DAYS_PER_YEAR,
- mutable vy = 2.37847173959480950e-03 * DAYS_PER_YEAR,
- mutable vz = -2.96589568540237556e-05 * DAYS_PER_YEAR,
- mass = 4.36624404335156298e-05 * SOLAR_MASS
- );
+ ret {mutable x: 1.28943695621391310e+01,
+ mutable y: -1.51111514016986312e+01,
+ mutable z: -2.23307578892655734e-01,
+ mutable vx: 2.96460137564761618e-03 * DAYS_PER_YEAR,
+ mutable vy: 2.37847173959480950e-03 * DAYS_PER_YEAR,
+ mutable vz: -2.96589568540237556e-05 * DAYS_PER_YEAR,
+ mass: 4.36624404335156298e-05 * SOLAR_MASS};
}
fn neptune() -> Body::props {
- ret rec(
- mutable x = 1.53796971148509165e+01,
- mutable y = -2.59193146099879641e+01,
- mutable z = 1.79258772950371181e-01,
- mutable vx = 2.68067772490389322e-03 * DAYS_PER_YEAR,
- mutable vy = 1.62824170038242295e-03 * DAYS_PER_YEAR,
- mutable vz = -9.51592254519715870e-05 * DAYS_PER_YEAR,
- mass = 5.15138902046611451e-05 * SOLAR_MASS
- );
- }
+ ret {mutable x: 1.53796971148509165e+01,
+ mutable y: -2.59193146099879641e+01,
+ mutable z: 1.79258772950371181e-01,
+ mutable vx: 2.68067772490389322e-03 * DAYS_PER_YEAR,
+ mutable vy: 1.62824170038242295e-03 * DAYS_PER_YEAR,
+ mutable vz: -9.51592254519715870e-05 * DAYS_PER_YEAR,
+ mass: 5.15138902046611451e-05 * SOLAR_MASS};
+ }
- fn sun() -> Body::props {
- ret rec(
- mutable x = 0.0,
- mutable y = 0.0,
- mutable z = 0.0,
- mutable vx = 0.0,
- mutable vy = 0.0,
- mutable vz = 0.0,
- mass = SOLAR_MASS
- );
- }
+ fn sun() -> Body::props {
+ ret {mutable x: 0.0,
+ mutable y: 0.0,
+ mutable z: 0.0,
+ mutable vx: 0.0,
+ mutable vy: 0.0,
+ mutable vz: 0.0,
+ mass: SOLAR_MASS};
+ }
- fn offsetMomentum(&Body::props props,
- float px,
- float py,
- float pz) -> () {
- props.vx = -px / SOLAR_MASS;
- props.vy = -py / SOLAR_MASS;
- props.vz = -pz / SOLAR_MASS;
- }
+ fn offsetMomentum(props: &Body::props, px: float, py: float, pz: float) {
+ props.vx = -px / SOLAR_MASS;
+ props.vy = -py / SOLAR_MASS;
+ props.vz = -pz / SOLAR_MASS;
+ }
-}
+}
\ No newline at end of file
diff --git a/src/test/bench/shootout-pfib.rs b/src/test/bench/shootout-pfib.rs
index 09dcf6e..bd32061 100644
--- a/src/test/bench/shootout-pfib.rs
+++ b/src/test/bench/shootout-pfib.rs
@@ -21,98 +21,87 @@
import std::task;
import std::u64;
-fn recv[T](&port[T] p) -> T {
- let T x;
- p |> x;
- ret x;
-}
+fn recv[T](p: &port[T]) -> T { let x: T; p |> x; ret x; }
-fn fib(int n) -> int {
- fn pfib(chan[int] c, int n) {
- if (n == 0) {
+fn fib(n: int) -> int {
+ fn pfib(c: chan[int], n: int) {
+ if n == 0 {
c <| 0;
- }
- else if (n <= 2) {
+ } else if (n <= 2) {
c <| 1;
- }
- else {
- auto p = port();
+ } else {
+ let p = port();
- auto t1 = spawn pfib(chan(p), n - 1);
- auto t2 = spawn pfib(chan(p), n - 2);
+ let t1 = spawn pfib(chan(p), n - 1);
+ let t2 = spawn pfib(chan(p), n - 2);
c <| recv(p) + recv(p);
}
}
- auto p = port();
- auto t = spawn pfib(chan(p), n);
+ let p = port();
+ let t = spawn pfib(chan(p), n);
ret recv(p);
}
-type config = rec(bool stress);
+type config = {stress: bool};
-fn parse_opts(vec[str] argv) -> config {
- auto opts = [getopts::optflag("stress")];
+fn parse_opts(argv: vec[str]) -> config {
+ let opts = [getopts::optflag("stress")];
- auto opt_args = vec::slice(argv, 1u, vec::len(argv));
+ let opt_args = vec::slice(argv, 1u, vec::len(argv));
- alt(getopts::getopts(opt_args, opts)) {
- case(getopts::success(?m)) {
- ret rec(stress = getopts::opt_present(m, "stress"))
- }
- case(getopts::failure(_)) {
- fail;
- }
+
+ alt getopts::getopts(opt_args, opts) {
+ getopts::success(m) { ret {stress: getopts::opt_present(m, "stress")} }
+ getopts::failure(_) { fail; }
}
}
-fn stress_task(int id) {
- auto i = 0;
- while(true) {
- auto n = 15;
- assert(fib(n) == fib(n));
+fn stress_task(id: int) {
+ let i = 0;
+ while true {
+ let n = 15;
+ assert (fib(n) == fib(n));
i += 1;
log_err #fmt("%d: Completed %d iterations", id, i);
}
}
-fn stress(int num_tasks) {
- auto tasks = [];
- for each(int i in range(0, num_tasks)) {
+fn stress(num_tasks: int) {
+ let tasks = [];
+ for each i: int in range(0, num_tasks) {
tasks += [spawn stress_task(i)];
}
- for each(int i in range(0, num_tasks)) {
- task::join(tasks.(i));
- }
+ for each i: int in range(0, num_tasks) { task::join(tasks.(i)); }
}
-fn main(vec[str] argv) {
- if(vec::len(argv) == 1u) {
+fn main(argv: vec[str]) {
+ if vec::len(argv) == 1u {
assert (fib(8) == 21);
log fib(8);
- }
- else {
+ } else {
// Interactive mode! Wooo!!!!
- auto opts = parse_opts(argv);
+ let opts = parse_opts(argv);
- if(opts.stress) {
+
+ if opts.stress {
stress(2);
- }
- else {
- auto max = uint::parse_buf(str::bytes(argv.(1)), 10u) as int;
+ } else {
+ let max = uint::parse_buf(str::bytes(argv.(1)), 10u) as int;
- auto num_trials = 10;
+ let num_trials = 10;
- auto out = io::stdout();
+ let out = io::stdout();
- for each(int n in range(1, max + 1)) {
- for each(int i in range(0, num_trials)) {
- auto start = time::precise_time_ns();
- auto fibn = fib(n);
- auto stop = time::precise_time_ns();
- auto elapsed = stop - start;
+ for each n: int in range(1, max + 1) {
+ for each i: int in range(0, num_trials) {
+ let start = time::precise_time_ns();
+ let fibn = fib(n);
+ let stop = time::precise_time_ns();
+
+ let elapsed = stop - start;
out.write_line(#fmt("%d\t%d\t%s", n, fibn,
u64::str(elapsed)));
@@ -120,4 +109,4 @@
}
}
}
-}
+}
\ No newline at end of file
diff --git a/src/test/bench/task-perf-word-count.rs b/src/test/bench/task-perf-word-count.rs
index 1131c59..6827ea5 100644
--- a/src/test/bench/task-perf-word-count.rs
+++ b/src/test/bench/task-perf-word-count.rs
@@ -28,34 +28,29 @@
import std::task;
import clone = std::task::clone_chan;
-fn map(str filename, map_reduce::putter emit) {
+fn map(filename: str, emit: map_reduce::putter) {
// log_err "mapping " + filename;
- auto f = io::file_reader(filename);
+ let f = io::file_reader(filename);
- while(true) {
- alt(read_word(f)) {
- case (some(?w)) {
- emit(w, 1);
- }
- case (none) {
- break;
- }
- }
+
+ while true {
+ alt read_word(f) { some(w) { emit(w, 1); } none. { break; } }
}
// log_err "done mapping " + filename;
}
-fn reduce(str word, map_reduce::getter get) {
+fn reduce(word: str, get: map_reduce::getter) {
// log_err "reducing " + word;
- auto count = 0;
+ let count = 0;
- while(true) {
- alt(get()) {
- some(_) {
- // log_err "received word " + word;
- count += 1;
- }
- none { break }
+
+ while true {
+ alt get() {
+ some(_) {
+ // log_err "received word " + word;
+ count += 1;
+ }
+ none. { break }
}
}
@@ -72,31 +67,25 @@
export reducer;
export map_reduce;
- type putter = fn(str, int) -> ();
+ type putter = fn(str, int) ;
- type mapper = fn(str, putter);
+ type mapper = fn(str, putter) ;
- type getter = fn() -> option[int];
+ type getter = fn() -> option[int] ;
- type reducer = fn(str, getter);
+ type reducer = fn(str, getter) ;
tag ctrl_proto {
find_reducer(u8[], chan[chan[reduce_proto]]);
mapper_done;
}
- tag reduce_proto {
- emit_val(int);
- done;
- ref;
- release;
- }
+ tag reduce_proto { emit_val(int); done; ref; release; }
- fn start_mappers(chan[ctrl_proto] ctrl,
- vec[str] inputs) -> task[] {
- auto tasks = ~[];
+ fn start_mappers(ctrl: chan[ctrl_proto], inputs: vec[str]) -> task[] {
+ let tasks = ~[];
// log_err "starting mappers";
- for(str i in inputs) {
+ for i: str in inputs {
// log_err "starting mapper for " + i;
tasks += ~[spawn map_task(ctrl, i)];
}
@@ -104,38 +93,37 @@
ret tasks;
}
- fn map_task(chan[ctrl_proto] ctrl,
- str input) {
+ fn map_task(ctrl: chan[ctrl_proto], input: str) {
// log_err "map_task " + input;
- auto intermediates = map::new_str_hash();
+ let intermediates = map::new_str_hash();
- fn emit(&map::hashmap[str, chan[reduce_proto]] im,
- chan[ctrl_proto] ctrl,
- str key, int val) {
+ fn emit(im: &map::hashmap[str, chan[reduce_proto]],
+ ctrl: chan[ctrl_proto], key: str, val: int) {
// log_err "emitting " + key;
- auto c;
- alt(im.find(key)) {
- some(?_c) {
- // log_err "reusing saved channel for " + key;
- c = _c
- }
- none {
- // log_err "fetching new channel for " + key;
- auto p = port[chan[reduce_proto]]();
- auto keyi = str::bytes_ivec(key);
- ctrl <| find_reducer(keyi, chan(p));
- p |> c;
- im.insert(key, clone(c));
- c <| ref;
- }
+ let c;
+ alt im.find(key) {
+ some(_c) {
+
+ // log_err "reusing saved channel for " + key;
+ c = _c
+ }
+ none. {
+ // log_err "fetching new channel for " + key;
+ let p = port[chan[reduce_proto]]();
+ let keyi = str::bytes_ivec(key);
+ ctrl <| find_reducer(keyi, chan(p));
+ p |> c;
+ im.insert(key, clone(c));
+ c <| ref;
+ }
}
c <| emit_val(val);
}
map(input, bind emit(intermediates, ctrl, _, _));
- for each(@rec(str key, chan[reduce_proto] val) kv
- in intermediates.items()) {
+ for each kv: @{key: str, val: chan[reduce_proto]} in
+ intermediates.items() {
// log_err "sending done to reducer for " + kv._0;
kv.val <| release;
}
@@ -145,36 +133,33 @@
// log_err "~map_task " + input;
}
- fn reduce_task(str key, chan[chan[reduce_proto]] out) {
+ fn reduce_task(key: str, out: chan[chan[reduce_proto]]) {
// log_err "reduce_task " + key;
- auto p = port();
+ let p = port();
out <| chan(p);
- auto ref_count = 0;
- auto is_done = false;
+ let ref_count = 0;
+ let is_done = false;
- fn get(&port[reduce_proto] p, &mutable int ref_count,
- &mutable bool is_done) -> option[int] {
- while (!is_done || ref_count > 0) {
- auto m;
+ fn get(p: &port[reduce_proto], ref_count: &mutable int,
+ is_done: &mutable bool) -> option[int] {
+ while !is_done || ref_count > 0 {
+ let m;
p |> m;
- alt(m) {
- emit_val(?v) {
- // log_err #fmt("received %d", v);
- ret some(v);
- }
- done {
- // log_err "all done";
- is_done = true;
- }
- ref {
- ref_count += 1;
- }
- release {
- ref_count -= 1;
- }
+
+ alt m {
+ emit_val(v) {
+ // log_err #fmt("received %d", v);
+ ret some(v);
+ }
+ done. {
+ // log_err "all done";
+ is_done = true;
+ }
+ ref. { ref_count += 1; }
+ release. { ref_count -= 1; }
}
}
ret none;
@@ -184,185 +169,177 @@
// log_err "~reduce_task " + key;
}
- fn map_reduce (vec[str] inputs) {
- auto ctrl = port[ctrl_proto]();
+ fn map_reduce(inputs: vec[str]) {
+ let ctrl = port[ctrl_proto]();
// This task becomes the master control task. It spawns others
// to do the rest.
- let map::hashmap[str, chan[reduce_proto]] reducers;
+ let reducers: map::hashmap[str, chan[reduce_proto]];
reducers = map::new_str_hash();
- auto tasks = start_mappers(chan(ctrl), inputs);
+ let tasks = start_mappers(chan(ctrl), inputs);
- auto num_mappers = vec::len(inputs) as int;
+ let num_mappers = vec::len(inputs) as int;
- while(num_mappers > 0) {
- auto m;
+ while num_mappers > 0 {
+ let m;
ctrl |> m;
- alt(m) {
- mapper_done {
- // log_err "received mapper terminated.";
- num_mappers -= 1;
+
+ alt m {
+ mapper_done. {
+ // log_err "received mapper terminated.";
+ num_mappers -= 1;
+ }
+ find_reducer(ki, cc) {
+ let c;
+ let k = str::unsafe_from_bytes_ivec(ki);
+ // log_err "finding reducer for " + k;
+ alt reducers.find(k) {
+ some(_c) {
+ // log_err "reusing existing reducer for " + k;
+ c = _c;
+ }
+ none. {
+ // log_err "creating new reducer for " + k;
+ let p = port();
+ tasks += ~[spawn reduce_task(k, chan(p))];
+ p |> c;
+ reducers.insert(k, c);
+ }
}
- find_reducer(?ki, ?cc) {
- auto c;
- auto k = str::unsafe_from_bytes_ivec(ki);
- // log_err "finding reducer for " + k;
- alt(reducers.find(k)) {
- some(?_c) {
- // log_err "reusing existing reducer for " + k;
- c = _c;
- }
- none {
- // log_err "creating new reducer for " + k;
- auto p = port();
- tasks += ~[spawn reduce_task(k, chan(p))];
- p |> c;
- reducers.insert(k, c);
- }
- }
- cc <| clone(c);
- }
+ cc <| clone(c);
+ }
}
}
- for each(@rec(str key, chan[reduce_proto] val) kv
- in reducers.items()) {
+ for each kv: @{key: str, val: chan[reduce_proto]} in reducers.items()
+ {
// log_err "sending done to reducer for " + kv._0;
kv.val <| done;
}
+
// log_err #fmt("joining %u tasks", ivec::len(tasks));
- for (task t in tasks) {
- task::join(t);
- }
+ for t: task in tasks { task::join(t); }
// log_err "control task done.";
}
}
-fn main(vec[str] argv) {
- if(vec::len(argv) < 2u) {
- auto out = io::stdout();
+fn main(argv: vec[str]) {
+ if vec::len(argv) < 2u {
+ let out = io::stdout();
out.write_line(#fmt("Usage: %s <filename> ...", argv.(0)));
fail;
}
- auto start = time::precise_time_ns();
+ let start = time::precise_time_ns();
map_reduce::map_reduce(vec::slice(argv, 1u, vec::len(argv)));
- auto stop = time::precise_time_ns();
+ let stop = time::precise_time_ns();
- auto elapsed = stop - start;
+ let elapsed = stop - start;
elapsed /= 1000000u64;
log_err "MapReduce completed in " + u64::str(elapsed) + "ms";
}
-fn read_word(io::reader r) -> option[str] {
- auto w = "";
+fn read_word(r: io::reader) -> option[str] {
+ let w = "";
- while(!r.eof()) {
- auto c = r.read_char();
+ while !r.eof() {
+ let c = r.read_char();
- if(is_word_char(c)) {
+
+ if is_word_char(c) {
w += str::from_char(c);
- }
- else {
- if(w != "") {
- ret some(w);
- }
- }
+ } else { if w != "" { ret some(w); } }
}
ret none;
}
-fn is_digit(char c) -> bool {
- alt(c) {
- case ('0') { true }
- case ('1') { true }
- case ('2') { true }
- case ('3') { true }
- case ('4') { true }
- case ('5') { true }
- case ('6') { true }
- case ('7') { true }
- case ('8') { true }
- case ('9') { true }
- case (_) { false }
+fn is_digit(c: char) -> bool {
+ alt c {
+ '0' { true }
+ '1' { true }
+ '2' { true }
+ '3' { true }
+ '4' { true }
+ '5' { true }
+ '6' { true }
+ '7' { true }
+ '8' { true }
+ '9' { true }
+ _ { false }
}
}
-fn is_alpha_lower (char c) -> bool {
- alt(c) {
- case ('a') { true }
- case ('b') { true }
- case ('c') { true }
- case ('d') { true }
- case ('e') { true }
- case ('f') { true }
- case ('g') { true }
- case ('h') { true }
- case ('i') { true }
- case ('j') { true }
- case ('k') { true }
- case ('l') { true }
- case ('m') { true }
- case ('n') { true }
- case ('o') { true }
- case ('p') { true }
- case ('q') { true }
- case ('r') { true }
- case ('s') { true }
- case ('t') { true }
- case ('u') { true }
- case ('v') { true }
- case ('w') { true }
- case ('x') { true }
- case ('y') { true }
- case ('z') { true }
- case (_) { false }
+fn is_alpha_lower(c: char) -> bool {
+ alt c {
+ 'a' { true }
+ 'b' { true }
+ 'c' { true }
+ 'd' { true }
+ 'e' { true }
+ 'f' { true }
+ 'g' { true }
+ 'h' { true }
+ 'i' { true }
+ 'j' { true }
+ 'k' { true }
+ 'l' { true }
+ 'm' { true }
+ 'n' { true }
+ 'o' { true }
+ 'p' { true }
+ 'q' { true }
+ 'r' { true }
+ 's' { true }
+ 't' { true }
+ 'u' { true }
+ 'v' { true }
+ 'w' { true }
+ 'x' { true }
+ 'y' { true }
+ 'z' { true }
+ _ { false }
}
}
-fn is_alpha_upper (char c) -> bool {
- alt(c) {
- case ('A') { true }
- case ('B') { true }
- case ('C') { true }
- case ('D') { true }
- case ('E') { true }
- case ('F') { true }
- case ('G') { true }
- case ('H') { true }
- case ('I') { true }
- case ('J') { true }
- case ('K') { true }
- case ('L') { true }
- case ('M') { true }
- case ('N') { true }
- case ('O') { true }
- case ('P') { true }
- case ('Q') { true }
- case ('R') { true }
- case ('S') { true }
- case ('T') { true }
- case ('U') { true }
- case ('V') { true }
- case ('W') { true }
- case ('X') { true }
- case ('Y') { true }
- case ('Z') { true }
- case (_) { false }
+fn is_alpha_upper(c: char) -> bool {
+ alt c {
+ 'A' { true }
+ 'B' { true }
+ 'C' { true }
+ 'D' { true }
+ 'E' { true }
+ 'F' { true }
+ 'G' { true }
+ 'H' { true }
+ 'I' { true }
+ 'J' { true }
+ 'K' { true }
+ 'L' { true }
+ 'M' { true }
+ 'N' { true }
+ 'O' { true }
+ 'P' { true }
+ 'Q' { true }
+ 'R' { true }
+ 'S' { true }
+ 'T' { true }
+ 'U' { true }
+ 'V' { true }
+ 'W' { true }
+ 'X' { true }
+ 'Y' { true }
+ 'Z' { true }
+ _ { false }
}
}
-fn is_alpha(char c) -> bool {
- is_alpha_upper(c) || is_alpha_lower(c)
-}
+fn is_alpha(c: char) -> bool { is_alpha_upper(c) || is_alpha_lower(c) }
-fn is_word_char(char c) -> bool {
- is_alpha(c) || is_digit(c) || c == '_'
-}
\ No newline at end of file
+fn is_word_char(c: char) -> bool { is_alpha(c) || is_digit(c) || c == '_' }
\ No newline at end of file
diff --git a/src/test/compile-fail/alias-mismatch.rs b/src/test/compile-fail/alias-mismatch.rs
index b280351..b22d6c8 100644
--- a/src/test/compile-fail/alias-mismatch.rs
+++ b/src/test/compile-fail/alias-mismatch.rs
@@ -3,7 +3,7 @@
import std::vec::map;
fn main() {
- fn f(uint i) -> bool { true }
+ fn f(i: uint) -> bool { true }
- auto a = map(f, [5u]);
+ let a = map(f, [5u]);
}
\ No newline at end of file
diff --git a/src/test/compile-fail/aliasness-mismatch.rs b/src/test/compile-fail/aliasness-mismatch.rs
index b4f156c..a376508 100644
--- a/src/test/compile-fail/aliasness-mismatch.rs
+++ b/src/test/compile-fail/aliasness-mismatch.rs
@@ -1,13 +1,8 @@
// -*- rust -*-
// error-pattern: mismatched types
-fn f(&int x) { log_err x; }
-fn h(int x) { log_err x; }
-fn main() {
- let fn(int x) g = f;
- g(10);
- g = h;
- g(10);
-}
+fn f(x: &int) { log_err x; }
+fn h(x: int) { log_err x; }
+fn main() { let g: fn(int) = f; g(10); g = h; g(10); }
diff --git a/src/test/compile-fail/alt-tag-nullary.rs b/src/test/compile-fail/alt-tag-nullary.rs
index f55f67e..3951a51 100644
--- a/src/test/compile-fail/alt-tag-nullary.rs
+++ b/src/test/compile-fail/alt-tag-nullary.rs
@@ -3,10 +3,5 @@
tag a { A; }
tag b { B; }
-fn main() {
- let a x = A;
- alt (x) {
- case (B) {}
- }
-}
+fn main() { let x: a = A; alt x { B. { } } }
diff --git a/src/test/compile-fail/alt-tag-unary.rs b/src/test/compile-fail/alt-tag-unary.rs
index f200489..5e0fccf 100644
--- a/src/test/compile-fail/alt-tag-unary.rs
+++ b/src/test/compile-fail/alt-tag-unary.rs
@@ -3,10 +3,5 @@
tag a { A(int); }
tag b { B(int); }
-fn main() {
- let a x = A(0);
- alt (x) {
- case (B(?y)) {}
- }
-}
+fn main() { let x: a = A(0); alt x { B(y) { } } }
diff --git a/src/test/compile-fail/and-init.rs b/src/test/compile-fail/and-init.rs
index 7fa9c54..a23fc99 100644
--- a/src/test/compile-fail/and-init.rs
+++ b/src/test/compile-fail/and-init.rs
@@ -2,8 +2,8 @@
// error-pattern: Unsatisfied precondition constraint (for example, init(i
fn main() {
- let int i;
+ let i: int;
- log (false && {i = 5; true});
- log i;
+ log false && { i = 5; true };
+ log i;
}
\ No newline at end of file
diff --git a/src/test/compile-fail/anon-obj-overloading-wrong-type.rs b/src/test/compile-fail/anon-obj-overloading-wrong-type.rs
index d06193f..604c456 100644
--- a/src/test/compile-fail/anon-obj-overloading-wrong-type.rs
+++ b/src/test/compile-fail/anon-obj-overloading-wrong-type.rs
@@ -7,24 +7,20 @@
fn main() {
obj a() {
- fn foo() -> int {
- ret 2;
- }
- fn bar() -> int {
- ret self.foo();
- }
+ fn foo() -> int { ret 2; }
+ fn bar() -> int { ret self.foo(); }
}
- auto my_a = a();
+ let my_a = a();
// This compiles and shouldn't. You should only be able to
// overload a method with one of the same type. Issue #703.
- auto my_b = obj() {
- fn foo() -> str {
- ret "hello";
- }
- with my_a
- };
+ let my_b =
+ obj () {
+ fn foo() -> str { ret "hello"; }
+ with
+ my_a
+ };
log_err my_b.foo();
-}
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/arg-count-mismatch.rs b/src/test/compile-fail/arg-count-mismatch.rs
index 1033353..89be058 100644
--- a/src/test/compile-fail/arg-count-mismatch.rs
+++ b/src/test/compile-fail/arg-count-mismatch.rs
@@ -1,9 +1,5 @@
// error-pattern: parameters were supplied
-fn f(int x) {
-}
+fn f(x: int) { }
-fn main() {
- let () i;
- i = f();
-}
+fn main() { let i: (); i = f(); }
\ No newline at end of file
diff --git a/src/test/compile-fail/arg-type-mismatch.rs b/src/test/compile-fail/arg-type-mismatch.rs
index 3a61992..3fe2e95 100644
--- a/src/test/compile-fail/arg-type-mismatch.rs
+++ b/src/test/compile-fail/arg-type-mismatch.rs
@@ -1,10 +1,6 @@
// error-pattern: mismatched types
-fn f(int x) {
-}
+fn f(x: int) { }
-fn main() {
- let () i;
- i = f(());
-}
\ No newline at end of file
+fn main() { let i: (); i = f(()); }
\ No newline at end of file
diff --git a/src/test/compile-fail/assign-alias.rs b/src/test/compile-fail/assign-alias.rs
index 5b10892..66041f0 100644
--- a/src/test/compile-fail/assign-alias.rs
+++ b/src/test/compile-fail/assign-alias.rs
@@ -1,9 +1,5 @@
// error-pattern:assigning to immutable alias
-fn f(&int i) {
- i += 2;
-}
+fn f(i: &int) { i += 2; }
-fn main() {
- f(1);
-}
\ No newline at end of file
+fn main() { f(1); }
\ No newline at end of file
diff --git a/src/test/compile-fail/attr-bad-meta.rs b/src/test/compile-fail/attr-bad-meta.rs
index 85714af..400d420 100644
--- a/src/test/compile-fail/attr-bad-meta.rs
+++ b/src/test/compile-fail/attr-bad-meta.rs
@@ -1,6 +1,6 @@
-// xfail-stage0
-// error-pattern:expecting ]
-
-// asterisk is bogus
-#[attr*]
-mod m { }
\ No newline at end of file
+./src/test/compile-fail/attr-bad-meta.rs:5:6:5:7: [1;31merror:[0m expecting ], found *
+./src/test/compile-fail/attr-bad-meta.rs:5 #[attr*]
+ ^
+rt: ---
+rt: f00e:main:main: upcall fail 'explicit failure', src/comp/syntax/parse/parser.rs:112
+rt: f00e:main: domain main @0xa6bf04c root task failed
diff --git a/src/test/compile-fail/attr-before-stmt.rs b/src/test/compile-fail/attr-before-stmt.rs
index 27dae8c..184d8b0 100644
--- a/src/test/compile-fail/attr-before-stmt.rs
+++ b/src/test/compile-fail/attr-before-stmt.rs
@@ -1,10 +1,6 @@
-// xfail-stage0
-// error-pattern:expected item
-
-fn f() {
- #[foo = "bar"]
- auto x = 10;
-}
-
-fn main() {
-}
+./src/test/compile-fail/attr-before-stmt.rs:6:2:6:6: [1;31merror:[0m expected item
+./src/test/compile-fail/attr-before-stmt.rs:6 auto x = 10;
+ ^~~~
+rt: ---
+rt: 0bb1:main:main: upcall fail 'explicit failure', src/comp/syntax/parse/parser.rs:112
+rt: 0bb1:main: domain main @0x8ef904c root task failed
diff --git a/src/test/compile-fail/attr-before-view-item.rs b/src/test/compile-fail/attr-before-view-item.rs
index 56e2ab7..e0e8b66 100644
--- a/src/test/compile-fail/attr-before-view-item.rs
+++ b/src/test/compile-fail/attr-before-view-item.rs
@@ -1,8 +1,6 @@
-// xfail-stage0
-// error-pattern:expected item
-
-#[foo = "bar"]
-use std;
-
-fn main() {
-}
+./src/test/compile-fail/attr-before-view-item.rs:5:0:5:3: [1;31merror:[0m expected item but found use
+./src/test/compile-fail/attr-before-view-item.rs:5 use std;
+ ^~~
+rt: ---
+rt: 0bb1:main:main: upcall fail 'explicit failure', src/comp/syntax/parse/parser.rs:112
+rt: 0bb1:main: domain main @0xa78604c root task failed
diff --git a/src/test/compile-fail/attr-before-view-item2.rs b/src/test/compile-fail/attr-before-view-item2.rs
index ad4071a..7c34948 100644
--- a/src/test/compile-fail/attr-before-view-item2.rs
+++ b/src/test/compile-fail/attr-before-view-item2.rs
@@ -1,10 +1,6 @@
-// xfail-stage0
-// error-pattern:expected item
-
-mod m {
- #[foo = "bar"]
- use std;
-}
-
-fn main() {
-}
+./src/test/compile-fail/attr-before-view-item2.rs:6:2:6:5: [1;31merror:[0m expected item but found use
+./src/test/compile-fail/attr-before-view-item2.rs:6 use std;
+ ^~~
+rt: ---
+rt: 0bb1:main:main: upcall fail 'explicit failure', src/comp/syntax/parse/parser.rs:112
+rt: 0bb1:main: domain main @0xa1fd04c root task failed
diff --git a/src/test/compile-fail/attr-dangling-in-fn.rs b/src/test/compile-fail/attr-dangling-in-fn.rs
index c31b325..4886d5d 100644
--- a/src/test/compile-fail/attr-dangling-in-fn.rs
+++ b/src/test/compile-fail/attr-dangling-in-fn.rs
@@ -1,9 +1,6 @@
-// xfail-stage0
-// error-pattern:expected item
-
-fn f() {
- #[foo = "bar"]
-}
-
-fn main() {
-}
+./src/test/compile-fail/attr-dangling-in-fn.rs:6:0:6:1: [1;31merror:[0m expected item
+./src/test/compile-fail/attr-dangling-in-fn.rs:6 }
+ ^
+rt: ---
+rt: f00e:main:main: upcall fail 'explicit failure', src/comp/syntax/parse/parser.rs:112
+rt: f00e:main: domain main @0x9fb104c root task failed
diff --git a/src/test/compile-fail/attr-dangling-in-mod.rs b/src/test/compile-fail/attr-dangling-in-mod.rs
index bd07240..7684dc8 100644
--- a/src/test/compile-fail/attr-dangling-in-mod.rs
+++ b/src/test/compile-fail/attr-dangling-in-mod.rs
@@ -1,7 +1,6 @@
-// xfail-stage0
-// error-pattern:expected item
-
-fn main() {
-}
-
-#[foo = "bar"]
+./src/test/compile-fail/attr-dangling-in-mod.rs:7:14:7:14: [1;31merror:[0m expected item but found <eof>
+./src/test/compile-fail/attr-dangling-in-mod.rs:7 #[foo = "bar"]
+ ^
+rt: ---
+rt: 0bb1:main:main: upcall fail 'explicit failure', src/comp/syntax/parse/parser.rs:112
+rt: 0bb1:main: domain main @0xa2d504c root task failed
diff --git a/src/test/compile-fail/auto-deref-bind.rs b/src/test/compile-fail/auto-deref-bind.rs
index 51f76be..9d9b0613 100644
--- a/src/test/compile-fail/auto-deref-bind.rs
+++ b/src/test/compile-fail/auto-deref-bind.rs
@@ -1,7 +1,4 @@
// error-pattern: mismatched types
-fn add1(int i) -> int { ret i+1; }
-fn main() {
- auto f = @add1;
- auto g = bind f(5);
-}
+fn add1(i: int) -> int { ret i + 1; }
+fn main() { let f = @add1; let g = bind f(5); }
\ No newline at end of file
diff --git a/src/test/compile-fail/bad-alt.rs b/src/test/compile-fail/bad-alt.rs
index 0762953..0d2632a 100644
--- a/src/test/compile-fail/bad-alt.rs
+++ b/src/test/compile-fail/bad-alt.rs
@@ -1,6 +1,6 @@
-// error-pattern: expecting
-
-fn main() {
- let int x = 5;
- alt x;
-}
+./src/test/compile-fail/bad-alt.rs:5:7:5:8: [1;31merror:[0m expecting {, found ;
+./src/test/compile-fail/bad-alt.rs:5 alt x;
+ ^
+rt: ---
+rt: 0bb1:main:main: upcall fail 'explicit failure', src/comp/syntax/parse/parser.rs:112
+rt: 0bb1:main: domain main @0x9e0f04c root task failed
diff --git a/src/test/compile-fail/bad-bang-ann-2.rs b/src/test/compile-fail/bad-bang-ann-2.rs
index b3264ab..15ba26b 100644
--- a/src/test/compile-fail/bad-bang-ann-2.rs
+++ b/src/test/compile-fail/bad-bang-ann-2.rs
@@ -2,10 +2,6 @@
// Tests that a function with a ! annotation always actually fails
// error-pattern: some control paths may return
-fn bad_bang(uint i) -> ! {
- log 3;
-}
+fn bad_bang(i: uint) -> ! { log 3; }
-fn main() {
- bad_bang(5u);
-}
\ No newline at end of file
+fn main() { bad_bang(5u); }
\ No newline at end of file
diff --git a/src/test/compile-fail/bad-bang-ann-3.rs b/src/test/compile-fail/bad-bang-ann-3.rs
index b070132..7077a2e 100644
--- a/src/test/compile-fail/bad-bang-ann-3.rs
+++ b/src/test/compile-fail/bad-bang-ann-3.rs
@@ -2,10 +2,6 @@
// Tests that a function with a ! annotation always actually fails
// error-pattern: some control paths may return
-fn bad_bang(uint i) -> ! {
- ret 7u;
-}
+fn bad_bang(i: uint) -> ! { ret 7u; }
-fn main() {
- bad_bang(5u);
-}
\ No newline at end of file
+fn main() { bad_bang(5u); }
\ No newline at end of file
diff --git a/src/test/compile-fail/bad-bang-ann.rs b/src/test/compile-fail/bad-bang-ann.rs
index 77c6a41..20aed48 100644
--- a/src/test/compile-fail/bad-bang-ann.rs
+++ b/src/test/compile-fail/bad-bang-ann.rs
@@ -2,14 +2,6 @@
// Tests that a function with a ! annotation always actually fails
// error-pattern: may return to the caller
-fn bad_bang(uint i) -> ! {
- if (i < 0u) {
- }
- else {
- fail;
- }
-}
+fn bad_bang(i: uint) -> ! { if i < 0u { } else { fail; } }
-fn main() {
- bad_bang(5u);
-}
\ No newline at end of file
+fn main() { bad_bang(5u); }
\ No newline at end of file
diff --git a/src/test/compile-fail/bad-env-capture.rs b/src/test/compile-fail/bad-env-capture.rs
index 013bb56..2848d18 100644
--- a/src/test/compile-fail/bad-env-capture.rs
+++ b/src/test/compile-fail/bad-env-capture.rs
@@ -1,10 +1,6 @@
// error-pattern: attempted dynamic environment-capture
fn foo() {
- let int x;
- fn bar() {
- log x;
- }
+ let x: int;
+ fn bar() { log x; }
}
-fn main() {
- foo();
-}
\ No newline at end of file
+fn main() { foo(); }
\ No newline at end of file
diff --git a/src/test/compile-fail/bad-env-capture2.rs b/src/test/compile-fail/bad-env-capture2.rs
index eded6ea..47e9a4e 100644
--- a/src/test/compile-fail/bad-env-capture2.rs
+++ b/src/test/compile-fail/bad-env-capture2.rs
@@ -1,9 +1,5 @@
// error-pattern: attempted dynamic environment-capture
-fn foo(int x) {
- fn bar() {
- log x;
- }
+fn foo(x: int) {
+ fn bar() { log x; }
}
-fn main() {
- foo(2);
-}
\ No newline at end of file
+fn main() { foo(2); }
\ No newline at end of file
diff --git a/src/test/compile-fail/bad-env-capture3.rs b/src/test/compile-fail/bad-env-capture3.rs
index 418decf..43d9a15 100644
--- a/src/test/compile-fail/bad-env-capture3.rs
+++ b/src/test/compile-fail/bad-env-capture3.rs
@@ -1,12 +1,8 @@
// error-pattern: attempted dynamic environment-capture
-obj foo(int x) {
+obj foo(x: int) {
fn mth() {
- fn bar() {
- log x;
- }
+ fn bar() { log x; }
}
}
-fn main() {
- foo(2);
-}
+fn main() { foo(2); }
\ No newline at end of file
diff --git a/src/test/compile-fail/bad-expr-path.rs b/src/test/compile-fail/bad-expr-path.rs
index 56c09f4..93aa3db 100644
--- a/src/test/compile-fail/bad-expr-path.rs
+++ b/src/test/compile-fail/bad-expr-path.rs
@@ -1,8 +1,5 @@
// error-pattern: unresolved name: a
-mod m1 {
-}
+mod m1 { }
-fn main(vec[str] args) {
- log m1::a;
-}
+fn main(args: vec[str]) { log m1::a; }
\ No newline at end of file
diff --git a/src/test/compile-fail/bad-expr-path2.rs b/src/test/compile-fail/bad-expr-path2.rs
index e8123f2..1498bae 100644
--- a/src/test/compile-fail/bad-expr-path2.rs
+++ b/src/test/compile-fail/bad-expr-path2.rs
@@ -1,10 +1,7 @@
// error-pattern: unresolved name: a
mod m1 {
- mod a {
- }
+ mod a { }
}
-fn main(vec[str] args) {
- log m1::a;
-}
+fn main(args: vec[str]) { log m1::a; }
\ No newline at end of file
diff --git a/src/test/compile-fail/bad-main.rs b/src/test/compile-fail/bad-main.rs
index 5808cdd..fd9c3bc 100644
--- a/src/test/compile-fail/bad-main.rs
+++ b/src/test/compile-fail/bad-main.rs
@@ -4,5 +4,4 @@
// xfail-stage3
// error-pattern: bad type signature
-fn main(int x) {
-}
+fn main(x: int) { }
\ No newline at end of file
diff --git a/src/test/compile-fail/bad-module.rs b/src/test/compile-fail/bad-module.rs
index 111d118..bfb7969 100644
--- a/src/test/compile-fail/bad-module.rs
+++ b/src/test/compile-fail/bad-module.rs
@@ -1,6 +1,4 @@
// error-pattern: unresolved import: vec
import vec;
-fn main() {
- auto foo = vec::len([]);
-}
\ No newline at end of file
+fn main() { let foo = vec::len([]); }
\ No newline at end of file
diff --git a/src/test/compile-fail/bad-name.rs b/src/test/compile-fail/bad-name.rs
index a53b828..b16a806 100644
--- a/src/test/compile-fail/bad-name.rs
+++ b/src/test/compile-fail/bad-name.rs
@@ -1,5 +1,6 @@
-// error-pattern: expecting
-
-fn main() {
- let x.y[int].z foo;
-}
+./src/test/compile-fail/bad-name.rs:4:7:4:8: [1;31merror:[0m expecting ident
+./src/test/compile-fail/bad-name.rs:4 let x.y[int].z foo;
+ ^
+rt: ---
+rt: f00e:main:main: upcall fail 'explicit failure', src/comp/syntax/parse/parser.rs:112
+rt: f00e:main: domain main @0x8d6004c root task failed
diff --git a/src/test/compile-fail/bad-record-pat-2.rs b/src/test/compile-fail/bad-record-pat-2.rs
index 037658f..125b608 100644
--- a/src/test/compile-fail/bad-record-pat-2.rs
+++ b/src/test/compile-fail/bad-record-pat-2.rs
@@ -1,7 +1,3 @@
// error-pattern:did not expect a record with a field q
-fn main() {
- alt rec(x=1, y=2) {
- {x, q} {}
- }
-}
+fn main() { alt {x: 1, y: 2} { {x: x, q: q} { } } }
\ No newline at end of file
diff --git a/src/test/compile-fail/bad-record-pat.rs b/src/test/compile-fail/bad-record-pat.rs
index 9813267..e8bb242 100644
--- a/src/test/compile-fail/bad-record-pat.rs
+++ b/src/test/compile-fail/bad-record-pat.rs
@@ -1,7 +1,3 @@
// error-pattern:expected a record with 2 fields, found one with 1
-fn main() {
- alt rec(x=1, y=2) {
- {x} {}
- }
-}
+fn main() { alt {x: 1, y: 2} { {x: x} { } } }
\ No newline at end of file
diff --git a/src/test/compile-fail/bad-recv.rs b/src/test/compile-fail/bad-recv.rs
index 1532eed..d97d358 100644
--- a/src/test/compile-fail/bad-recv.rs
+++ b/src/test/compile-fail/bad-recv.rs
@@ -1,5 +1,3 @@
// error-pattern: mismatched types
-fn main() {
- 10 |> 10;
-}
\ No newline at end of file
+fn main() { 10 |> 10; }
\ No newline at end of file
diff --git a/src/test/compile-fail/bad-send.rs b/src/test/compile-fail/bad-send.rs
index e699b4e..deb7a74 100644
--- a/src/test/compile-fail/bad-send.rs
+++ b/src/test/compile-fail/bad-send.rs
@@ -1,5 +1,3 @@
// error-pattern: mismatched types
-fn main() {
- 10 <| 10;
-}
\ No newline at end of file
+fn main() { 10 <| 10; }
\ No newline at end of file
diff --git a/src/test/compile-fail/bad-type-env-capture.rs b/src/test/compile-fail/bad-type-env-capture.rs
index 940edb6..1d56259 100644
--- a/src/test/compile-fail/bad-type-env-capture.rs
+++ b/src/test/compile-fail/bad-type-env-capture.rs
@@ -3,5 +3,7 @@
// xfail-stage2
// xfail-stage3
// error-pattern: attempted dynamic environment-capture
-fn foo[T]() { obj bar(T b) {} }
-fn main() {}
\ No newline at end of file
+fn foo[T]() {
+ obj bar(b: T) { }
+}
+fn main() { }
\ No newline at end of file
diff --git a/src/test/compile-fail/bind-alias.rs b/src/test/compile-fail/bind-alias.rs
index 815e23a..8d53004 100644
--- a/src/test/compile-fail/bind-alias.rs
+++ b/src/test/compile-fail/bind-alias.rs
@@ -4,8 +4,6 @@
// xfail-stage3
// error-pattern: binding alias slot
-fn f(&int x) {}
+fn f(x: &int) { }
-fn main() {
- bind f(10);
-}
+fn main() { bind f(10); }
\ No newline at end of file
diff --git a/src/test/compile-fail/bind-parameterized-args.rs b/src/test/compile-fail/bind-parameterized-args.rs
index 970dbb9..2b22cad 100644
--- a/src/test/compile-fail/bind-parameterized-args.rs
+++ b/src/test/compile-fail/bind-parameterized-args.rs
@@ -1,10 +1,9 @@
// xfail-stage0
// error-pattern:Bind arguments with types containing parameters must be
fn main() {
- fn echo[T](int c, vec[T] x) {
- }
+ fn echo[T](c: int, x: vec[T]) { }
- let fn(vec[int]) -> () y = bind echo(42, _);
+ let y: fn(vec[int]) = bind echo(42, _);
- y([1]);
-}
+ y([1]);
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/binop-add-tup-assign.rs b/src/test/compile-fail/binop-add-tup-assign.rs
index 1d0595c..fbd2274 100644
--- a/src/test/compile-fail/binop-add-tup-assign.rs
+++ b/src/test/compile-fail/binop-add-tup-assign.rs
@@ -1,7 +1,4 @@
// xfail-stage0
// error-pattern:+ cannot be applied to type `rec(bool x)`
-fn main() {
- auto x = rec(x=true);
- x += rec(x=false);
-}
\ No newline at end of file
+fn main() { let x = {x: true}; x += {x: false}; }
\ No newline at end of file
diff --git a/src/test/compile-fail/binop-add-tup.rs b/src/test/compile-fail/binop-add-tup.rs
index 668a3d7..313ec76 100644
--- a/src/test/compile-fail/binop-add-tup.rs
+++ b/src/test/compile-fail/binop-add-tup.rs
@@ -1,6 +1,4 @@
// xfail-stage0
// error-pattern:+ cannot be applied to type `rec(bool x)`
-fn main() {
- auto x = rec(x=true) + rec(x=false);
-}
\ No newline at end of file
+fn main() { let x = {x: true} + {x: false}; }
\ No newline at end of file
diff --git a/src/test/compile-fail/binop-bitxor-str.rs b/src/test/compile-fail/binop-bitxor-str.rs
index b22b35c..e7f0561 100644
--- a/src/test/compile-fail/binop-bitxor-str.rs
+++ b/src/test/compile-fail/binop-bitxor-str.rs
@@ -1,6 +1,4 @@
// xfail-stage0
// error-pattern:^ cannot be applied to type `str`
-fn main() {
- auto x = "a" ^ "b";
-}
\ No newline at end of file
+fn main() { let x = "a" ^ "b"; }
\ No newline at end of file
diff --git a/src/test/compile-fail/binop-logic-float.rs b/src/test/compile-fail/binop-logic-float.rs
index 55448c8..4a1edf5 100644
--- a/src/test/compile-fail/binop-logic-float.rs
+++ b/src/test/compile-fail/binop-logic-float.rs
@@ -1,6 +1,4 @@
// xfail-stage0
// error-pattern:|| cannot be applied to type `f32`
-fn main() {
- auto x = 1.0_f32 || 2.0_f32;
-}
\ No newline at end of file
+fn main() { let x = 1.0_f32 || 2.0_f32; }
\ No newline at end of file
diff --git a/src/test/compile-fail/binop-logic-int.rs b/src/test/compile-fail/binop-logic-int.rs
index e777c2e..4ac9091 100644
--- a/src/test/compile-fail/binop-logic-int.rs
+++ b/src/test/compile-fail/binop-logic-int.rs
@@ -1,6 +1,4 @@
// xfail-stage0
// error-pattern:&& cannot be applied to type `int`
-fn main() {
- auto x = 1 && 2;
-}
\ No newline at end of file
+fn main() { let x = 1 && 2; }
\ No newline at end of file
diff --git a/src/test/compile-fail/binop-mul-bool.rs b/src/test/compile-fail/binop-mul-bool.rs
index 6ab4542..dcf7a06 100644
--- a/src/test/compile-fail/binop-mul-bool.rs
+++ b/src/test/compile-fail/binop-mul-bool.rs
@@ -1,6 +1,4 @@
// xfail-stage0
// error-pattern:* cannot be applied to type `bool`
-fn main() {
- auto x = true * false;
-}
\ No newline at end of file
+fn main() { let x = true * false; }
\ No newline at end of file
diff --git a/src/test/compile-fail/binop-shift-port.rs b/src/test/compile-fail/binop-shift-port.rs
index e4a6f31..047014a 100644
--- a/src/test/compile-fail/binop-shift-port.rs
+++ b/src/test/compile-fail/binop-shift-port.rs
@@ -2,7 +2,7 @@
// error-pattern:>> cannot be applied to type `port[int]`
fn main() {
- let port[int] p1 = port();
- let port[int] p2 = port();
- auto x = p1 >> p2;
+ let p1: port[int] = port();
+ let p2: port[int] = port();
+ let x = p1 >> p2;
}
\ No newline at end of file
diff --git a/src/test/compile-fail/binop-sub-obj.rs b/src/test/compile-fail/binop-sub-obj.rs
index 3b68b08..e86aa06 100644
--- a/src/test/compile-fail/binop-sub-obj.rs
+++ b/src/test/compile-fail/binop-sub-obj.rs
@@ -1,6 +1,4 @@
// xfail-stage0
// error-pattern:- cannot be applied to type `obj
-fn main() {
- auto x = obj(){} - obj(){};
-}
\ No newline at end of file
+fn main() { let x = obj () { } - obj () { }; }
\ No newline at end of file
diff --git a/src/test/compile-fail/binop-typeck.rs b/src/test/compile-fail/binop-typeck.rs
index 5d48300..376bca6 100644
--- a/src/test/compile-fail/binop-typeck.rs
+++ b/src/test/compile-fail/binop-typeck.rs
@@ -2,8 +2,4 @@
// error-pattern:mismatched types
// issue #500
-fn main() {
- auto x = true;
- auto y = 1;
- auto z = x + y;
-}
+fn main() { let x = true; let y = 1; let z = x + y; }
\ No newline at end of file
diff --git a/src/test/compile-fail/block-coerce-no.rs b/src/test/compile-fail/block-coerce-no.rs
index 1833126..9afcd2b 100644
--- a/src/test/compile-fail/block-coerce-no.rs
+++ b/src/test/compile-fail/block-coerce-no.rs
@@ -4,17 +4,11 @@
// Make sure that fn-to-block coercion isn't incorrectly lifted over
// other tycons.
-fn coerce(&block() b) -> fn() {
- fn lol(&fn(&block()) -> fn() f, &block() g) -> fn() {
- ret f(g);
- }
- fn fn_id (&fn() f) -> fn() { ret f }
+fn coerce(b: &block() ) -> fn() {
+ fn lol(f: &fn(&block() ) -> fn() , g: &block() ) -> fn() { ret f(g); }
+ fn fn_id(f: &fn() ) -> fn() { ret f }
ret lol(fn_id, b);
}
-fn main() {
- auto i = 8;
- auto f = coerce(block() { log_err i; } );
- f();
-}
+fn main() { let i = 8; let f = coerce(block () { log_err i; }); f(); }
\ No newline at end of file
diff --git a/src/test/compile-fail/block-copy.rs b/src/test/compile-fail/block-copy.rs
index d8df0a9..b6dc009 100644
--- a/src/test/compile-fail/block-copy.rs
+++ b/src/test/compile-fail/block-copy.rs
@@ -1,9 +1,5 @@
// error-pattern: non-copyable
// xfail-stage0
-fn lol(&block() f) -> block() { ret f; }
-fn main() {
- auto i = 8;
- auto f = lol(block() { log_err i; } );
- f();
-}
+fn lol(f: &block() ) -> block() { ret f; }
+fn main() { let i = 8; let f = lol(block () { log_err i; }); f(); }
\ No newline at end of file
diff --git a/src/test/compile-fail/block-uninit.rs b/src/test/compile-fail/block-uninit.rs
index ff86906..e5c877f 100644
--- a/src/test/compile-fail/block-uninit.rs
+++ b/src/test/compile-fail/block-uninit.rs
@@ -1,8 +1,5 @@
// error-pattern: Unsatisfied precondition constraint
// xfail-stage0
-fn force(&block() f) { f(); }
-fn main() {
- let int x;
- force(block() { log_err x; });
-}
+fn force(f: &block() ) { f(); }
+fn main() { let x: int; force(block () { log_err x; }); }
\ No newline at end of file
diff --git a/src/test/compile-fail/bogus-tag.rs b/src/test/compile-fail/bogus-tag.rs
index 9e5564d..e590a6b 100644
--- a/src/test/compile-fail/bogus-tag.rs
+++ b/src/test/compile-fail/bogus-tag.rs
@@ -2,20 +2,10 @@
// error-pattern: unresolved
-tag color {
- rgb(int, int, int);
- rgba(int, int, int, int);
-}
+tag color { rgb(int, int, int); rgba(int, int, int, int); }
-fn main() -> () {
- let color red = rgb(255, 0, 0);
- alt (red) {
- case (rgb(?r, ?g, ?b)) {
- log "rgb";
- }
- case (hsl(?h, ?s, ?l)) {
- log "hsl";
- }
- }
+fn main() {
+ let red: color = rgb(255, 0, 0);
+ alt red { rgb(r, g, b) { log "rgb"; } hsl(h, s, l) { log "hsl"; } }
}
diff --git a/src/test/compile-fail/break-outside-loop.rs b/src/test/compile-fail/break-outside-loop.rs
index bc40a50..6d9c0e9 100644
--- a/src/test/compile-fail/break-outside-loop.rs
+++ b/src/test/compile-fail/break-outside-loop.rs
@@ -1,8 +1,8 @@
// xfail-stage0
// error-pattern:Break outside a loop
fn main() {
- auto pth = break;
+ let pth = break;
- let rec(str t) rs = rec(t=pth);
+ let rs: {t: str} = {t: pth};
}
\ No newline at end of file
diff --git a/src/test/compile-fail/break-uninit.rs b/src/test/compile-fail/break-uninit.rs
index eaad421..d1c7a90 100644
--- a/src/test/compile-fail/break-uninit.rs
+++ b/src/test/compile-fail/break-uninit.rs
@@ -1,20 +1,14 @@
// error-pattern:Unsatisfied precondition
fn foo() -> int {
- let int x;
- let int i;
+ let x: int;
+ let i: int;
- do {
- i = 0;
- break;
- x = 0;
- } while (x != 0);
+ do { i = 0; break; x = 0; } while x != 0
- log(x);
+ log x;
- ret 17;
+ ret 17;
}
-fn main() {
- log(foo());
-}
+fn main() { log foo(); }
\ No newline at end of file
diff --git a/src/test/compile-fail/break-uninit2.rs b/src/test/compile-fail/break-uninit2.rs
index 5b19b06..9fb89c5 100644
--- a/src/test/compile-fail/break-uninit2.rs
+++ b/src/test/compile-fail/break-uninit2.rs
@@ -1,20 +1,14 @@
// error-pattern:Unsatisfied precondition
fn foo() -> int {
- let int x;
- let int i;
+ let x: int;
+ let i: int;
- do {
- i = 0;
- break;
- x = 0;
- } while (1 != 2);
+ do { i = 0; break; x = 0; } while 1 != 2
- log(x);
+ log x;
- ret 17;
+ ret 17;
}
-fn main() {
- log(foo());
-}
+fn main() { log foo(); }
\ No newline at end of file
diff --git a/src/test/compile-fail/capture1.rs b/src/test/compile-fail/capture1.rs
index fb1d82f..2423293 100644
--- a/src/test/compile-fail/capture1.rs
+++ b/src/test/compile-fail/capture1.rs
@@ -4,9 +4,7 @@
fn main() {
- fn foo() -> int {
- ret bar;
- }
+ fn foo() -> int { ret bar; }
- let int bar = 5;
-}
+ let bar: int = 5;
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/capture2.rs b/src/test/compile-fail/capture2.rs
index 1b088c6..918939b 100644
--- a/src/test/compile-fail/capture2.rs
+++ b/src/test/compile-fail/capture2.rs
@@ -2,17 +2,13 @@
// error-pattern: attempted dynamic environment-capture
-fn f(bool x) {
+fn f(x: bool) { }
+
+obj foobar(x: bool)
+ {drop {
+ let y = x;
+ fn test() { f(y); }
+ }
}
-state obj foobar(bool x) {
- drop {
- auto y = x;
- fn test() {
- f(y);
- }
- }
-}
-
-fn main() {
-}
+fn main() { }
\ No newline at end of file
diff --git a/src/test/compile-fail/chan-parameterized-args.rs b/src/test/compile-fail/chan-parameterized-args.rs
index 78c9a74..93c0b6a 100644
--- a/src/test/compile-fail/chan-parameterized-args.rs
+++ b/src/test/compile-fail/chan-parameterized-args.rs
@@ -1,18 +1,18 @@
// xfail-stage0
// error-pattern:Spawn arguments with types containing parameters must be
fn main() {
-// Similar to bind-parameterized-args
- fn echo[T](chan[T] c, chan[chan[T]] oc) {
- let port[T] p = port();
+ // Similar to bind-parameterized-args
+ fn echo[T](c: chan[T], oc: chan[chan[T]]) {
+ let p: port[T] = port();
oc <| chan(p);
- auto x;
+ let x;
p |> x;
c <| x;
}
- auto p = port[int]();
- auto p2 = port[chan[int]]();
+ let p = port[int]();
+ let p2 = port[chan[int]]();
spawn echo(chan(p), chan(p2));
}
\ No newline at end of file
diff --git a/src/test/compile-fail/constrained-type-missing-check.rs b/src/test/compile-fail/constrained-type-missing-check.rs
index e52e9ca..afc3f85 100644
--- a/src/test/compile-fail/constrained-type-missing-check.rs
+++ b/src/test/compile-fail/constrained-type-missing-check.rs
@@ -5,22 +5,19 @@
// xfail-stage3
// error-pattern:Unsatisfied precondition
-tag list {
- cons(int,@list);
- nil();
-}
+tag list { cons(int, @list); nil; }
-type bubu = rec(int x, int y);
+type bubu = {x: int, y: int};
-pred less_than(int x, int y) -> bool { ret x < y; }
+pred less_than(x: int, y: int) -> bool { ret x < y; }
-type ordered_range = rec(int low, int high) : less_than(*.low, *.high);
+type ordered_range = {low: int, high: int} : : less_than(low, high);
fn main() {
-// Should fail to compile, b/c we're not doing the check
-// explicitly that a < b
- let int a = 1;
- let int b = 2;
- let ordered_range c = rec(low=a, high=b);
- log c.low;
-}
+ // Should fail to compile, b/c we're not doing the check
+ // explicitly that a < b
+ let a: int = 1;
+ let b: int = 2;
+ let c: ordered_range = {low: a, high: b};
+ log c.low;
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/constructor-as-cast.rs b/src/test/compile-fail/constructor-as-cast.rs
index ccc58f1..2bee783 100644
--- a/src/test/compile-fail/constructor-as-cast.rs
+++ b/src/test/compile-fail/constructor-as-cast.rs
@@ -1,13 +1,10 @@
// error-pattern: unresolved name: base
type base =
- obj {
- fn foo();
- };
+ obj {
+ fn foo() ;
+ };
obj derived() {
- fn foo() {}
- fn bar() {}
+ fn foo() { }
+ fn bar() { }
}
-fn main() {
- let derived d = derived();
- let base b = base(d);
-}
+fn main() { let d: derived = derived(); let b: base = base(d); }
\ No newline at end of file
diff --git a/src/test/compile-fail/copy-a-resource.rs b/src/test/compile-fail/copy-a-resource.rs
index c22a154..aabacdd 100644
--- a/src/test/compile-fail/copy-a-resource.rs
+++ b/src/test/compile-fail/copy-a-resource.rs
@@ -1,8 +1,5 @@
// error-pattern:Copying a non-copyable type
-resource foo(int i) {}
+resource foo(i: int) { }
-fn main() {
- auto x <- foo(10);
- auto y = x;
-}
+fn main() { let x <- foo(10); let y = x; }
\ No newline at end of file
diff --git a/src/test/compile-fail/cross-crate-glob-collision.rs b/src/test/compile-fail/cross-crate-glob-collision.rs
index f29d553..3ebc480 100644
--- a/src/test/compile-fail/cross-crate-glob-collision.rs
+++ b/src/test/compile-fail/cross-crate-glob-collision.rs
@@ -8,7 +8,7 @@
import alternate_supplier::*;
mod alternate_supplier {
- fn swap() {}
+ fn swap() { }
}
-fn main() { swap() }
+fn main() { swap() }
\ No newline at end of file
diff --git a/src/test/compile-fail/dead-code-be.rs b/src/test/compile-fail/dead-code-be.rs
index 4730879..7d2168b 100644
--- a/src/test/compile-fail/dead-code-be.rs
+++ b/src/test/compile-fail/dead-code-be.rs
@@ -6,12 +6,7 @@
// error-pattern: dead
-fn f(str caller) {
- log caller;
-}
+fn f(caller: str) { log caller; }
-fn main() {
- be f("main");
- log "Paul is dead";
-}
+fn main() { be f("main"); log "Paul is dead"; }
diff --git a/src/test/compile-fail/dead-code-ret.rs b/src/test/compile-fail/dead-code-ret.rs
index 887d618..ee3a2af 100644
--- a/src/test/compile-fail/dead-code-ret.rs
+++ b/src/test/compile-fail/dead-code-ret.rs
@@ -6,12 +6,7 @@
// error-pattern: dead
-fn f(str caller) {
- log caller;
-}
+fn f(caller: str) { log caller; }
-fn main() {
- ret f("main");
- log "Paul is dead";
-}
+fn main() { ret f("main"); log "Paul is dead"; }
diff --git a/src/test/compile-fail/direct-obj-fn-call.rs b/src/test/compile-fail/direct-obj-fn-call.rs
index 3003716..557b6af 100644
--- a/src/test/compile-fail/direct-obj-fn-call.rs
+++ b/src/test/compile-fail/direct-obj-fn-call.rs
@@ -1,11 +1,7 @@
// error-pattern: attempted field access
obj x() {
- fn hello() {
- log "hello";
- }
+ fn hello() { log "hello"; }
}
-fn main() {
- x.hello();
-}
\ No newline at end of file
+fn main() { x.hello(); }
\ No newline at end of file
diff --git a/src/test/compile-fail/do-while-constraints.rs b/src/test/compile-fail/do-while-constraints.rs
index fe93499..b560d00 100644
--- a/src/test/compile-fail/do-while-constraints.rs
+++ b/src/test/compile-fail/do-while-constraints.rs
@@ -2,16 +2,10 @@
// error-pattern: Unsatisfied precondition constraint (for example, init(y
fn main() {
- let int y = 42;
- let int x;
- do {
- log y;
- do {
- do {
- do {
- x <- y;
- } while (true);
- } while (true);
- } while (true);
- } while (true);
+ let y: int = 42;
+ let x: int;
+ do {
+ log y;
+ do { do { do { x <- y; } while true } while true } while true
+ } while true
}
\ No newline at end of file
diff --git a/src/test/compile-fail/do-while-pred-constraints.rs b/src/test/compile-fail/do-while-pred-constraints.rs
index 119b263..b91e2aa 100644
--- a/src/test/compile-fail/do-while-pred-constraints.rs
+++ b/src/test/compile-fail/do-while-pred-constraints.rs
@@ -1,26 +1,16 @@
// xfail-stage0
// error-pattern: Unsatisfied precondition constraint (for example, even(y
-fn print_even(int y) : even(y) {
- log y;
-}
+fn print_even(y: int) { log y; }
-pred even(int y) -> bool {
- true
-}
+pred even(y: int) -> bool { true }
fn main() {
- let int y = 42;
- check even(y);
- do {
- print_even(y);
- do {
- do {
- do {
- y += 1;
- } while (true);
- } while (true);
- } while (true);
- } while (true);
+ let y: int = 42;
+ check (even(y));
+ do {
+ print_even(y);
+ do { do { do { y += 1; } while true } while true } while true
+ } while true
}
\ No newline at end of file
diff --git a/src/test/compile-fail/does-nothing.rs b/src/test/compile-fail/does-nothing.rs
index ef7115d..09671b7 100644
--- a/src/test/compile-fail/does-nothing.rs
+++ b/src/test/compile-fail/does-nothing.rs
@@ -1,7 +1,3 @@
// error-pattern: unresolved name: this_does_nothing_what_the
-fn main() {
- log "doing";
- this_does_nothing_what_the;
- log "boing";
-}
+fn main() { log "doing"; this_does_nothing_what_the; log "boing"; }
diff --git a/src/test/compile-fail/dup-link-name.rs b/src/test/compile-fail/dup-link-name.rs
index 7ef6314..90143e1 100644
--- a/src/test/compile-fail/dup-link-name.rs
+++ b/src/test/compile-fail/dup-link-name.rs
@@ -1,7 +1,6 @@
// xfail-stage0
// error-pattern:duplicate meta item `name`
-#[link(name = "test",
- name)];
+#[link(name = "test", name)];
-fn main() {}
\ No newline at end of file
+fn main() { }
\ No newline at end of file
diff --git a/src/test/compile-fail/duplicate-name.rs b/src/test/compile-fail/duplicate-name.rs
index c7650aa..294d782 100644
--- a/src/test/compile-fail/duplicate-name.rs
+++ b/src/test/compile-fail/duplicate-name.rs
@@ -1,6 +1,3 @@
// error-pattern: duplicate value name: x
-fn main() {
- auto x = 10;
- let int x = 20;
-}
+fn main() { let x = 10; let x: int = 20; }
\ No newline at end of file
diff --git a/src/test/compile-fail/export-fully-qualified.rs b/src/test/compile-fail/export-fully-qualified.rs
index 8592511..7413777 100644
--- a/src/test/compile-fail/export-fully-qualified.rs
+++ b/src/test/compile-fail/export-fully-qualified.rs
@@ -6,15 +6,11 @@
mod foo {
- export bar;
+ export bar;
- fn bar() {
- foo::baz();
- }
+ fn bar() { foo::baz(); }
- fn baz() {
- }
+ fn baz() { }
}
-fn main() {
-}
\ No newline at end of file
+fn main() { }
\ No newline at end of file
diff --git a/src/test/compile-fail/export-import.rs b/src/test/compile-fail/export-import.rs
index dce1fb0..2608f52 100644
--- a/src/test/compile-fail/export-import.rs
+++ b/src/test/compile-fail/export-import.rs
@@ -3,16 +3,12 @@
import m::unexported;
mod m {
- export exported;
+ export exported;
- fn exported() {
- }
+ fn exported() { }
- fn unexported() {
- }
+ fn unexported() { }
}
-fn main() {
- unexported();
-}
+fn main() { unexported(); }
\ No newline at end of file
diff --git a/src/test/compile-fail/export-no-tag-variants.rs b/src/test/compile-fail/export-no-tag-variants.rs
index c86cf4d..a824212 100644
--- a/src/test/compile-fail/export-no-tag-variants.rs
+++ b/src/test/compile-fail/export-no-tag-variants.rs
@@ -4,13 +4,9 @@
// simple sort of ADT.
mod foo {
- export t;
+ export t;
- tag t {
- t1;
- }
+ tag t { t1; }
}
-fn main() {
- auto x = foo::t1;
-}
+fn main() { let x = foo::t1; }
\ No newline at end of file
diff --git a/src/test/compile-fail/export-tag-variant.rs b/src/test/compile-fail/export-tag-variant.rs
index 1a856e8..a31ae56 100644
--- a/src/test/compile-fail/export-tag-variant.rs
+++ b/src/test/compile-fail/export-tag-variant.rs
@@ -1,16 +1,11 @@
// error-pattern: unresolved name
mod foo {
- export x;
+ export x;
- fn x() {
- }
+ fn x() { }
- tag y {
- y1;
- }
+ tag y { y1; }
}
-fn main() {
- auto z = foo::y1;
-}
+fn main() { let z = foo::y1; }
\ No newline at end of file
diff --git a/src/test/compile-fail/export.rs b/src/test/compile-fail/export.rs
index 2961589..5796783 100644
--- a/src/test/compile-fail/export.rs
+++ b/src/test/compile-fail/export.rs
@@ -1,14 +1,8 @@
// error-pattern: unresolved name
mod foo {
- export x;
- fn x(int y) {
- log y;
- }
- fn z(int y) {
- log y;
- }
+ export x;
+ fn x(y: int) { log y; }
+ fn z(y: int) { log y; }
}
-fn main() {
- foo::z(10);
-}
+fn main() { foo::z(10); }
\ No newline at end of file
diff --git a/src/test/compile-fail/export2.rs b/src/test/compile-fail/export2.rs
index c0a44af..47b8001 100644
--- a/src/test/compile-fail/export2.rs
+++ b/src/test/compile-fail/export2.rs
@@ -1,24 +1,17 @@
// error-pattern: unresolved name
mod foo {
- export x;
+ export x;
- fn x() {
- bar::x();
- }
+ fn x() { bar::x(); }
}
mod bar {
- export y;
+ export y;
- fn x() {
- log "x";
- }
+ fn x() { log "x"; }
- fn y() {
- }
+ fn y() { }
}
-fn main() {
- foo::x();
-}
+fn main() { foo::x(); }
\ No newline at end of file
diff --git a/src/test/compile-fail/ext-after-attrib.rs b/src/test/compile-fail/ext-after-attrib.rs
index 446fb83..530e912 100644
--- a/src/test/compile-fail/ext-after-attrib.rs
+++ b/src/test/compile-fail/ext-after-attrib.rs
@@ -1,8 +1,6 @@
-// xfail-stage0
-// error-pattern:expecting [, found fmt
-
-// Don't know how to deal with a syntax extension appearing after an
-// item attribute. Probably could use a better error message.
-#[foo = "bar"]
-#fmt("baz")
-fn main() { }
\ No newline at end of file
+./src/test/compile-fail/ext-after-attrib.rs:7:1:7:4: [1;31merror:[0m expecting [, found fmt
+./src/test/compile-fail/ext-after-attrib.rs:7 #fmt("baz")
+ ^~~
+rt: ---
+rt: f00e:main:main: upcall fail 'explicit failure', src/comp/syntax/parse/parser.rs:112
+rt: f00e:main: domain main @0xa47a04c root task failed
diff --git a/src/test/compile-fail/ext-noname.rs b/src/test/compile-fail/ext-noname.rs
index 82395c7..0846633 100644
--- a/src/test/compile-fail/ext-noname.rs
+++ b/src/test/compile-fail/ext-noname.rs
@@ -1,5 +1,6 @@
-// error-pattern:expected a syntax expander name
-
-fn main() {
- #();
-}
\ No newline at end of file
+./src/test/compile-fail/ext-noname.rs:4:3:4:4: [1;31merror:[0m expected a syntax expander name
+./src/test/compile-fail/ext-noname.rs:4 #();
+ ^
+rt: ---
+rt: 0bb1:main:main: upcall fail 'explicit failure', src/comp/syntax/parse/parser.rs:112
+rt: 0bb1:main: domain main @0x91a204c root task failed
diff --git a/src/test/compile-fail/ext-nonexistent.rs b/src/test/compile-fail/ext-nonexistent.rs
index 9a7591a..b86928e 100644
--- a/src/test/compile-fail/ext-nonexistent.rs
+++ b/src/test/compile-fail/ext-nonexistent.rs
@@ -1,4 +1,2 @@
// error-pattern:unknown syntax expander
-fn main() {
- #iamnotanextensionthatexists("");
-}
+fn main() { #iamnotanextensionthatexists(""); }
\ No newline at end of file
diff --git a/src/test/compile-fail/extend-non-object.rs b/src/test/compile-fail/extend-non-object.rs
index 3d232db..4a957f5 100644
--- a/src/test/compile-fail/extend-non-object.rs
+++ b/src/test/compile-fail/extend-non-object.rs
@@ -2,12 +2,12 @@
use std;
fn main() {
- auto x = 3;
+ let x = 3;
- auto anon_obj = obj {
- fn foo() -> int {
- ret 3;
- }
- with x
- };
-}
+ let anon_obj =
+ obj () {
+ fn foo() -> int { ret 3; }
+ with
+ x
+ };
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/extenv-no-args.rs b/src/test/compile-fail/extenv-no-args.rs
index 2503a63..d923078 100644
--- a/src/test/compile-fail/extenv-no-args.rs
+++ b/src/test/compile-fail/extenv-no-args.rs
@@ -1,5 +1,3 @@
// error-pattern:malformed #env call
-fn main() {
- #env();
-}
+fn main() { #env; }
\ No newline at end of file
diff --git a/src/test/compile-fail/extenv-not-string-literal.rs b/src/test/compile-fail/extenv-not-string-literal.rs
index 7c082b4..8ab4953 100644
--- a/src/test/compile-fail/extenv-not-string-literal.rs
+++ b/src/test/compile-fail/extenv-not-string-literal.rs
@@ -1,5 +1,3 @@
// error-pattern:requires a string
-fn main() {
- #env(10);
-}
+fn main() { #env(10); }
\ No newline at end of file
diff --git a/src/test/compile-fail/extenv-too-many-args.rs b/src/test/compile-fail/extenv-too-many-args.rs
index e71d0ec..65200e5 100644
--- a/src/test/compile-fail/extenv-too-many-args.rs
+++ b/src/test/compile-fail/extenv-too-many-args.rs
@@ -1,5 +1,3 @@
// error-pattern:malformed #env call
-fn main() {
- #env("one", "two");
-}
+fn main() { #env("one", "two"); }
\ No newline at end of file
diff --git a/src/test/compile-fail/extfmt-missing-type.rs b/src/test/compile-fail/extfmt-missing-type.rs
index 8f82e33..23deb75 100644
--- a/src/test/compile-fail/extfmt-missing-type.rs
+++ b/src/test/compile-fail/extfmt-missing-type.rs
@@ -1,5 +1,3 @@
// error-pattern:missing type
-fn main() {
- #fmt("%+");
-}
+fn main() { #fmt("%+"); }
\ No newline at end of file
diff --git a/src/test/compile-fail/extfmt-no-args.rs b/src/test/compile-fail/extfmt-no-args.rs
index b3bdf23..d6e146a 100644
--- a/src/test/compile-fail/extfmt-no-args.rs
+++ b/src/test/compile-fail/extfmt-no-args.rs
@@ -1,5 +1,3 @@
// error-pattern:format string
-fn main() {
- #fmt();
-}
+fn main() { #fmt; }
\ No newline at end of file
diff --git a/src/test/compile-fail/extfmt-non-literal.rs b/src/test/compile-fail/extfmt-non-literal.rs
index 4b85498..10020ab 100644
--- a/src/test/compile-fail/extfmt-non-literal.rs
+++ b/src/test/compile-fail/extfmt-non-literal.rs
@@ -2,8 +2,8 @@
// error-pattern: literal
fn main() {
- // #fmt's first argument must be a literal. Hopefully this
- // restriction can be eased eventually to just require a
- // compile-time constant.
- auto x = #fmt("a" + "b");
-}
+ // #fmt's first argument must be a literal. Hopefully this
+ // restriction can be eased eventually to just require a
+ // compile-time constant.
+ let x = #fmt("a" + "b");
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/extfmt-non-literal2.rs b/src/test/compile-fail/extfmt-non-literal2.rs
index 2182639..8172708 100644
--- a/src/test/compile-fail/extfmt-non-literal2.rs
+++ b/src/test/compile-fail/extfmt-non-literal2.rs
@@ -2,8 +2,8 @@
// error-pattern: literal
fn main() {
- // #fmt's first argument must be a literal. Hopefully this
- // restriction can be eased eventually to just require a
- // compile-time constant.
- auto x = #fmt(20);
-}
+ // #fmt's first argument must be a literal. Hopefully this
+ // restriction can be eased eventually to just require a
+ // compile-time constant.
+ let x = #fmt(20);
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/extfmt-not-enough-args.rs b/src/test/compile-fail/extfmt-not-enough-args.rs
index 80aad7b..335a441 100644
--- a/src/test/compile-fail/extfmt-not-enough-args.rs
+++ b/src/test/compile-fail/extfmt-not-enough-args.rs
@@ -3,6 +3,4 @@
use std;
-fn main() {
- auto s = #fmt("%s%s%s", "test", "test");
-}
+fn main() { let s = #fmt("%s%s%s", "test", "test"); }
\ No newline at end of file
diff --git a/src/test/compile-fail/extfmt-too-many-args.rs b/src/test/compile-fail/extfmt-too-many-args.rs
index c95217d..3b956fa 100644
--- a/src/test/compile-fail/extfmt-too-many-args.rs
+++ b/src/test/compile-fail/extfmt-too-many-args.rs
@@ -3,6 +3,4 @@
use std;
-fn main() {
- auto s = #fmt("%s", "test", "test");
-}
+fn main() { let s = #fmt("%s", "test", "test"); }
\ No newline at end of file
diff --git a/src/test/compile-fail/extfmt-unknown-type.rs b/src/test/compile-fail/extfmt-unknown-type.rs
index 08d5da0..8c272a1 100644
--- a/src/test/compile-fail/extfmt-unknown-type.rs
+++ b/src/test/compile-fail/extfmt-unknown-type.rs
@@ -1,5 +1,3 @@
// error-pattern:unknown type
-fn main() {
- #fmt("%w");
-}
+fn main() { #fmt("%w"); }
\ No newline at end of file
diff --git a/src/test/compile-fail/extfmt-unsigned-plus.rs b/src/test/compile-fail/extfmt-unsigned-plus.rs
index a74f4db..ad35d4e 100644
--- a/src/test/compile-fail/extfmt-unsigned-plus.rs
+++ b/src/test/compile-fail/extfmt-unsigned-plus.rs
@@ -2,6 +2,6 @@
// error-pattern:only valid in signed #fmt conversion
fn main() {
- // Can't use a sign on unsigned conversions
- #fmt("%+u", 10u);
-}
+ // Can't use a sign on unsigned conversions
+ #fmt("%+u", 10u);
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/extfmt-unsigned-space.rs b/src/test/compile-fail/extfmt-unsigned-space.rs
index bd1b6c9..898c429 100644
--- a/src/test/compile-fail/extfmt-unsigned-space.rs
+++ b/src/test/compile-fail/extfmt-unsigned-space.rs
@@ -2,6 +2,6 @@
// error-pattern:only valid in signed #fmt conversion
fn main() {
- // Can't use a space on unsigned conversions
- #fmt("% u", 10u);
-}
+ // Can't use a space on unsigned conversions
+ #fmt("% u", 10u);
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/extfmt-unterminated-conv.rs b/src/test/compile-fail/extfmt-unterminated-conv.rs
index 8c75c75..44a321f 100644
--- a/src/test/compile-fail/extfmt-unterminated-conv.rs
+++ b/src/test/compile-fail/extfmt-unterminated-conv.rs
@@ -1,5 +1,3 @@
// error-pattern:unterminated conversion
-fn main() {
- #fmt("%");
-}
+fn main() { #fmt("%"); }
\ No newline at end of file
diff --git a/src/test/compile-fail/fail-expr.rs b/src/test/compile-fail/fail-expr.rs
index dbc5afa..13d91ce 100644
--- a/src/test/compile-fail/fail-expr.rs
+++ b/src/test/compile-fail/fail-expr.rs
@@ -1,5 +1,3 @@
// error-pattern:mismatched types
-fn main() {
- fail 5;
-}
\ No newline at end of file
+fn main() { fail 5; }
\ No newline at end of file
diff --git a/src/test/compile-fail/fail-simple.rs b/src/test/compile-fail/fail-simple.rs
index 768cc1e..50c59d1 100644
--- a/src/test/compile-fail/fail-simple.rs
+++ b/src/test/compile-fail/fail-simple.rs
@@ -1,6 +1,6 @@
-// -*- rust -*-
-
-// error-pattern:unexpected token
-fn main() {
- fail @ ;
-}
+./src/test/compile-fail/fail-simple.rs:5:9:5:10: [1;31merror:[0m unexpected token: ;
+./src/test/compile-fail/fail-simple.rs:5 fail @ ;
+ ^
+rt: ---
+rt: f00e:main:main: upcall fail 'explicit failure', src/comp/syntax/parse/parser.rs:112
+rt: f00e:main: domain main @0x994f04c root task failed
diff --git a/src/test/compile-fail/fail-type-err.rs b/src/test/compile-fail/fail-type-err.rs
index 681e10f..952043e 100644
--- a/src/test/compile-fail/fail-type-err.rs
+++ b/src/test/compile-fail/fail-type-err.rs
@@ -1,5 +1,3 @@
// error-pattern:expected str but found vec
// xfail-stage0
-fn main() {
- fail [];
-}
+fn main() { fail []; }
\ No newline at end of file
diff --git a/src/test/compile-fail/fn-bad-block-type.rs b/src/test/compile-fail/fn-bad-block-type.rs
index ed6a735..44ef885 100644
--- a/src/test/compile-fail/fn-bad-block-type.rs
+++ b/src/test/compile-fail/fn-bad-block-type.rs
@@ -1,9 +1,6 @@
// xfail-stage0
// error-pattern:mismatched types
-fn f() -> int {
- true
-}
+fn f() -> int { true }
-fn main() {
-}
\ No newline at end of file
+fn main() { }
\ No newline at end of file
diff --git a/src/test/compile-fail/fn-compare-mismatch.rs b/src/test/compile-fail/fn-compare-mismatch.rs
index 4b83455..ba40cd5 100644
--- a/src/test/compile-fail/fn-compare-mismatch.rs
+++ b/src/test/compile-fail/fn-compare-mismatch.rs
@@ -2,7 +2,7 @@
// error-pattern:expected fn() but found fn(int)
fn main() {
- fn f() {}
- fn g(int i) {}
- auto x = f == g;
+ fn f() { }
+ fn g(i: int) { }
+ let x = f == g;
}
\ No newline at end of file
diff --git a/src/test/compile-fail/fn-constraint.rs b/src/test/compile-fail/fn-constraint.rs
index 85f3c8c..0be8d79 100644
--- a/src/test/compile-fail/fn-constraint.rs
+++ b/src/test/compile-fail/fn-constraint.rs
@@ -3,7 +3,7 @@
import std::str::*;
fn main() {
- let uint a = 4u;
- let uint b = 1u;
- log_err (safe_slice("kitties", a, b));
+ let a: uint = 4u;
+ let b: uint = 1u;
+ log_err safe_slice("kitties", a, b);
}
\ No newline at end of file
diff --git a/src/test/compile-fail/fn-expr-type-state.rs b/src/test/compile-fail/fn-expr-type-state.rs
index ac9489a..cecb7bf 100644
--- a/src/test/compile-fail/fn-expr-type-state.rs
+++ b/src/test/compile-fail/fn-expr-type-state.rs
@@ -3,9 +3,6 @@
fn main() {
// Typestate should work even in a lambda. we should reject this program.
- auto f = fn () -> int {
- let int i;
- ret i;
- };
+ let f = fn () -> int { let i: int; ret i; };
log_err f();
-}
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/fn-expr-typestate-2.rs b/src/test/compile-fail/fn-expr-typestate-2.rs
index f30e2a0..baa0e08 100644
--- a/src/test/compile-fail/fn-expr-typestate-2.rs
+++ b/src/test/compile-fail/fn-expr-typestate-2.rs
@@ -1,10 +1,4 @@
// error-pattern:Unsatisfied precondition
// xfail-stage0
-fn main() {
- auto j = (fn () -> int {
- let int i;
- ret i;
- })();
- log_err j;
-}
+fn main() { let j = fn () -> int { let i: int; ret i; }(); log_err j; }
\ No newline at end of file
diff --git a/src/test/compile-fail/for-loop-decl.rs b/src/test/compile-fail/for-loop-decl.rs
index c95893d..5b7fa90 100644
--- a/src/test/compile-fail/for-loop-decl.rs
+++ b/src/test/compile-fail/for-loop-decl.rs
@@ -3,22 +3,17 @@
import std::map::hashmap;
import std::bitv;
-type fn_info = rec(hashmap[uint, var_info] vars);
-type var_info = rec(uint a, uint b);
+type fn_info = {vars: hashmap[uint, var_info]};
+type var_info = {a: uint, b: uint};
-fn bitv_to_str(fn_info enclosing, bitv::t v) -> str {
- auto s = "";
+fn bitv_to_str(enclosing: fn_info, v: bitv::t) -> str {
+ let s = "";
- // error is that the value type in the hash map is var_info, not a box
- for each (@rec(uint key, @uint val) p
- in enclosing.vars.items()) {
- if (bitv::get(v, *p.val)) {
- s += "foo";
+ // error is that the value type in the hash map is var_info, not a box
+ for each p: @{key: uint, val: @uint} in enclosing.vars.items() {
+ if bitv::get(v, *p.val) { s += "foo"; }
}
- }
- ret s;
+ ret s;
}
-fn main() {
- log "OK";
-}
\ No newline at end of file
+fn main() { log "OK"; }
\ No newline at end of file
diff --git a/src/test/compile-fail/forgot-ret.rs b/src/test/compile-fail/forgot-ret.rs
index 3be3d0b..1cdc55f 100644
--- a/src/test/compile-fail/forgot-ret.rs
+++ b/src/test/compile-fail/forgot-ret.rs
@@ -1,16 +1,8 @@
// -*- rust -*-
// error-pattern: not all control paths return
-fn god_exists(int a) -> bool {
- be god_exists(a);
-}
+fn god_exists(a: int) -> bool { be god_exists(a); }
-fn f(int a) -> int {
- if (god_exists(a)) {
- ret 5;
- }
-}
+fn f(a: int) -> int { if god_exists(a) { ret 5; } }
-fn main() {
- f(12);
-}
+fn main() { f(12); }
\ No newline at end of file
diff --git a/src/test/compile-fail/fru-extra-field.rs b/src/test/compile-fail/fru-extra-field.rs
index 601aca2..6957da3 100644
--- a/src/test/compile-fail/fru-extra-field.rs
+++ b/src/test/compile-fail/fru-extra-field.rs
@@ -2,10 +2,10 @@
// error-pattern: record
-type point = rec(int x, int y);
+type point = {x: int, y: int};
fn main() {
- let point origin = rec(x=0, y=0);
+ let origin: point = {x: 0, y: 0};
- let point origin3d = rec(z=0 with origin);
-}
+ let origin3d: point = {z: 0 with origin};
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/fru-typestate.rs b/src/test/compile-fail/fru-typestate.rs
index 86c68e5..ce5102c 100644
--- a/src/test/compile-fail/fru-typestate.rs
+++ b/src/test/compile-fail/fru-typestate.rs
@@ -2,11 +2,11 @@
// error-pattern: precondition
-type point = rec(int x, int y);
+type point = {x: int, y: int};
fn main() {
- let point origin;
+ let origin: point;
- let point right = rec(x=10 with origin);
- origin = rec(x=0, y=0);
-}
+ let right: point = {x: 10 with origin};
+ origin = {x: 0, y: 0};
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/if-branch-types.rs b/src/test/compile-fail/if-branch-types.rs
index 3434040..345d250 100644
--- a/src/test/compile-fail/if-branch-types.rs
+++ b/src/test/compile-fail/if-branch-types.rs
@@ -1,9 +1,3 @@
// error-pattern:mismatched types
-fn main() {
- auto x = if (true) {
- 10
- } else {
- 10u
- };
-}
+fn main() { let x = if true { 10 } else { 10u }; }
\ No newline at end of file
diff --git a/src/test/compile-fail/if-check-precond-fail.rs b/src/test/compile-fail/if-check-precond-fail.rs
index 54aa1fe..0d19037 100644
--- a/src/test/compile-fail/if-check-precond-fail.rs
+++ b/src/test/compile-fail/if-check-precond-fail.rs
@@ -1,30 +1,13 @@
// xfail-stage0
// error-pattern:Unsatisfied precondition constraint
-pred even(uint x) -> bool {
- if (x < 2u) {
- ret false;
- }
- else if (x == 2u) {
- ret true;
- }
- else {
- ret even(x - 2u);
- }
+pred even(x: uint) -> bool {
+ if x < 2u {
+ ret false;
+ } else if (x == 2u) { ret true; } else { ret even(x - 2u); }
}
-fn print_even(uint x) : even(x) {
- log x;
-}
+fn print_even(x: uint) { log x; }
-fn foo(uint x) -> () {
- if check(even(x)) {
- fail;
- }
- else {
- print_even(x);
- }
-}
+fn foo(x: uint) { if check even(x) { fail; } else { print_even(x); } }
-fn main() {
- foo(3u);
-}
+fn main() { foo(3u); }
\ No newline at end of file
diff --git a/src/test/compile-fail/if-typeck.rs b/src/test/compile-fail/if-typeck.rs
index 2fbe384..a67b282 100644
--- a/src/test/compile-fail/if-typeck.rs
+++ b/src/test/compile-fail/if-typeck.rs
@@ -2,10 +2,10 @@
// error-pattern:mismatched types
// issue #513
-fn f() {}
+fn f() { }
fn main() {
- // f is not a bool
- if (f) {
- }
+
+ // f is not a bool
+ if f { }
}
\ No newline at end of file
diff --git a/src/test/compile-fail/import-glob-0.rs b/src/test/compile-fail/import-glob-0.rs
index 63bc0b5..8d74000 100644
--- a/src/test/compile-fail/import-glob-0.rs
+++ b/src/test/compile-fail/import-glob-0.rs
@@ -3,28 +3,20 @@
import module_of_many_things::*;
mod module_of_many_things {
- export f1;
- export f2;
- export f4;
+ export f1;
+ export f2;
+ export f4;
- fn f1() {
- log "f1";
- }
- fn f2() {
- log "f2";
- }
- fn f3() {
- log "f3";
- }
- fn f4() {
- log "f4";
- }
+ fn f1() { log "f1"; }
+ fn f2() { log "f2"; }
+ fn f3() { log "f3"; }
+ fn f4() { log "f4"; }
}
fn main() {
- f1();
- f2();
- f999(); // 'export' currently doesn't work?
- f4();
+ f1();
+ f2();
+ f999(); // 'export' currently doesn't work?
+ f4();
}
\ No newline at end of file
diff --git a/src/test/compile-fail/import-glob-circular.rs b/src/test/compile-fail/import-glob-circular.rs
index 3fbe240..1a937d6 100644
--- a/src/test/compile-fail/import-glob-circular.rs
+++ b/src/test/compile-fail/import-glob-circular.rs
@@ -1,35 +1,25 @@
// error-pattern: unresolved name
mod circ1 {
- import circ1::*;
- export f1;
- export f2;
- export common;
- fn f1() {
- log "f1";
- }
- fn common() -> uint {
- ret 0u;
- }
+ import circ1::*;
+ export f1;
+ export f2;
+ export common;
+ fn f1() { log "f1"; }
+ fn common() -> uint { ret 0u; }
}
mod circ2 {
- import circ2::*;
- export f1;
- export f2;
- export common;
- fn f2() {
- log "f2";
- }
- fn common() -> uint {
- ret 1u;
- }
+ import circ2::*;
+ export f1;
+ export f2;
+ export common;
+ fn f2() { log "f2"; }
+ fn common() -> uint { ret 1u; }
}
mod test {
- import circ1::*;
+ import circ1::*;
- fn test() {
- f1066();
- }
+ fn test() { f1066(); }
}
\ No newline at end of file
diff --git a/src/test/compile-fail/import-glob-export.rs b/src/test/compile-fail/import-glob-export.rs
index 561d791..57f154e 100644
--- a/src/test/compile-fail/import-glob-export.rs
+++ b/src/test/compile-fail/import-glob-export.rs
@@ -4,11 +4,9 @@
import m1::*;
mod m1 {
- export f1;
- fn f1() {}
- fn f2() {}
+ export f1;
+ fn f1() { }
+ fn f2() { }
}
-fn main () {
- f2();
-}
\ No newline at end of file
+fn main() { f2(); }
\ No newline at end of file
diff --git a/src/test/compile-fail/import-glob-multiple.rs b/src/test/compile-fail/import-glob-multiple.rs
index 5e4a422..1abe786 100644
--- a/src/test/compile-fail/import-glob-multiple.rs
+++ b/src/test/compile-fail/import-glob-multiple.rs
@@ -4,31 +4,17 @@
import mod2::*;
mod mod1 {
- fn f1() {
- log "f1";
- }
- fn common1() {
- log "common"
- }
- fn common2() {
- log "common"
- }
+ fn f1() { log "f1"; }
+ fn common1() { log "common" }
+ fn common2() { log "common" }
}
mod mod2 {
- fn f2() {
- log "f1";
- }
- fn common1() {
- log "common"
- }
- fn common2() {
- log "common"
- }
+ fn f2() { log "f1"; }
+ fn common1() { log "common" }
+ fn common2() { log "common" }
}
-fn main() {
- common2();
-}
\ No newline at end of file
+fn main() { common2(); }
\ No newline at end of file
diff --git a/src/test/compile-fail/import-loop-2.rs b/src/test/compile-fail/import-loop-2.rs
index 7667c39..a219508 100644
--- a/src/test/compile-fail/import-loop-2.rs
+++ b/src/test/compile-fail/import-loop-2.rs
@@ -1,15 +1,13 @@
// error-pattern:cyclic import
mod a {
- import b::x;
- export x;
+ import b::x;
+ export x;
}
mod b {
- import a::x;
- export x;
+ import a::x;
+ export x;
- fn main() {
- auto y = x;
- }
-}
+ fn main() { let y = x; }
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/import-loop.rs b/src/test/compile-fail/import-loop.rs
index c5d13ce..6e79082 100644
--- a/src/test/compile-fail/import-loop.rs
+++ b/src/test/compile-fail/import-loop.rs
@@ -7,5 +7,4 @@
export x;
}
-fn main() {
-}
+fn main() { }
\ No newline at end of file
diff --git a/src/test/compile-fail/import.rs b/src/test/compile-fail/import.rs
index 66c706c..6667c9a 100644
--- a/src/test/compile-fail/import.rs
+++ b/src/test/compile-fail/import.rs
@@ -2,10 +2,6 @@
import zed::bar;
import zed::baz;
mod zed {
- fn bar() {
- log "bar";
- }
+ fn bar() { log "bar"; }
}
-fn main(vec[str] args) {
- bar();
-}
+fn main(args: vec[str]) { bar(); }
\ No newline at end of file
diff --git a/src/test/compile-fail/import2.rs b/src/test/compile-fail/import2.rs
index f587d3f..6029aad 100644
--- a/src/test/compile-fail/import2.rs
+++ b/src/test/compile-fail/import2.rs
@@ -1,12 +1,7 @@
// error-pattern: unresolved modulename
import baz::zed::bar;
-mod baz {
-}
+mod baz { }
mod zed {
- fn bar() {
- log "bar3";
- }
+ fn bar() { log "bar3"; }
}
-fn main(vec[str] args) {
- bar();
-}
+fn main(args: vec[str]) { bar(); }
\ No newline at end of file
diff --git a/src/test/compile-fail/import3.rs b/src/test/compile-fail/import3.rs
index bdad687..b4e76af 100644
--- a/src/test/compile-fail/import3.rs
+++ b/src/test/compile-fail/import3.rs
@@ -1,6 +1,4 @@
// error-pattern: unresolved modulename
import main::bar;
-fn main(vec[str] args) {
- log "foo";
-}
+fn main(args: vec[str]) { log "foo"; }
\ No newline at end of file
diff --git a/src/test/compile-fail/import4.rs b/src/test/compile-fail/import4.rs
index 347d115..bde87e0 100644
--- a/src/test/compile-fail/import4.rs
+++ b/src/test/compile-fail/import4.rs
@@ -3,6 +3,4 @@
import zed::bar;
import bar::zed;
-fn main(vec[str] args) {
- log "loop";
-}
+fn main(args: vec[str]) { log "loop"; }
\ No newline at end of file
diff --git a/src/test/compile-fail/import5.rs b/src/test/compile-fail/import5.rs
index 3e926fd..4910bb5 100644
--- a/src/test/compile-fail/import5.rs
+++ b/src/test/compile-fail/import5.rs
@@ -1,15 +1,15 @@
// error-pattern:unresolved import: foo
mod m1 {
- fn foo() { log "foo"; }
+ fn foo() { log "foo"; }
}
mod m2 {
- import m1::foo;
+ import m1::foo;
}
mod m3 {
- import m2::foo;
+ import m2::foo;
}
-fn main () {}
\ No newline at end of file
+fn main() { }
\ No newline at end of file
diff --git a/src/test/compile-fail/impure-pred.rs b/src/test/compile-fail/impure-pred.rs
index e163d34..cf775f8 100644
--- a/src/test/compile-fail/impure-pred.rs
+++ b/src/test/compile-fail/impure-pred.rs
@@ -1,15 +1,12 @@
// -*- rust -*-
// error-pattern: Pure function calls function not known to be pure
-fn g() -> () {}
+fn g() { }
-pred f(int q) -> bool {
- g();
- ret true;
-}
+pred f(q: int) -> bool { g(); ret true; }
fn main() {
- auto x = 0;
+ let x = 0;
- check f(x);
-}
+ check (f(x));
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/infinite-tag-type-recursion.rs b/src/test/compile-fail/infinite-tag-type-recursion.rs
index 6bce29b..856bd7f 100644
--- a/src/test/compile-fail/infinite-tag-type-recursion.rs
+++ b/src/test/compile-fail/infinite-tag-type-recursion.rs
@@ -6,11 +6,6 @@
// error-pattern: tag of infinite size
-tag mlist {
- cons(int, mlist);
- nil;
-}
+tag mlist { cons(int, mlist); nil; }
-fn main() {
- auto a = cons(10, cons(11, nil));
-}
+fn main() { let a = cons(10, cons(11, nil)); }
\ No newline at end of file
diff --git a/src/test/compile-fail/infinite-vec-type-recursion.rs b/src/test/compile-fail/infinite-vec-type-recursion.rs
index 418fdb3..006a084 100644
--- a/src/test/compile-fail/infinite-vec-type-recursion.rs
+++ b/src/test/compile-fail/infinite-vec-type-recursion.rs
@@ -4,6 +4,4 @@
type x = vec[x];
-fn main() {
- let x b = [];
-}
+fn main() { let b: x = []; }
\ No newline at end of file
diff --git a/src/test/compile-fail/item-name-overload.rs b/src/test/compile-fail/item-name-overload.rs
index d3c3779..fe8da20 100644
--- a/src/test/compile-fail/item-name-overload.rs
+++ b/src/test/compile-fail/item-name-overload.rs
@@ -3,8 +3,8 @@
// error-pattern: Dynamically sized arguments must be passed by alias
mod foo {
- fn bar[T](T f) -> int { ret 17; }
- type bar[U, T] = rec(int a, U b, T c);
+ fn bar[T](f: T) -> int { ret 17; }
+ type bar[U, T] = {a: int, b: U, c: T};
}
-fn main() {}
+fn main() { }
\ No newline at end of file
diff --git a/src/test/compile-fail/macro-2.rs b/src/test/compile-fail/macro-2.rs
index 45926bfe..a2ff7ef 100644
--- a/src/test/compile-fail/macro-2.rs
+++ b/src/test/compile-fail/macro-2.rs
@@ -1,7 +1,11 @@
// xfail-stage0
//error-pattern:is an expr, expected an identifier
fn main() {
- #macro([#mylambda(x, body), {fn f(int x) -> int {ret body}; f}]);
+ #macro([#mylambda(x, body),
+ {
+ fn f(x: int) -> int { ret body }
+ f
+ }]);
- assert(#mylambda(y*1, y*2)(8) == 16);
+ assert (#mylambda(y * 1, y * 2)(8) == 16);
}
\ No newline at end of file
diff --git a/src/test/compile-fail/macro.rs b/src/test/compile-fail/macro.rs
index 5beb996..2118e5c 100644
--- a/src/test/compile-fail/macro.rs
+++ b/src/test/compile-fail/macro.rs
@@ -2,7 +2,8 @@
//error-pattern:no clauses match
fn main() {
- #macro([#trivial(), 1*2*4*2*1]);
+ #macro([#trivial, 1 * 2 * 4 * 2 * 1]);
- assert(#trivial(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16) == 16);
-}
+ assert (#trivial(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) ==
+ 16);
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/main-wrong-type-2.rs b/src/test/compile-fail/main-wrong-type-2.rs
index 50bf187..5386b78 100644
--- a/src/test/compile-fail/main-wrong-type-2.rs
+++ b/src/test/compile-fail/main-wrong-type-2.rs
@@ -1,4 +1,3 @@
// xfail-stage0
// error-pattern:Wrong type in main function: found fn() -> char
-fn main() -> char {
-}
+fn main() -> char { }
\ No newline at end of file
diff --git a/src/test/compile-fail/main-wrong-type.rs b/src/test/compile-fail/main-wrong-type.rs
index 4998867..58b3b26 100644
--- a/src/test/compile-fail/main-wrong-type.rs
+++ b/src/test/compile-fail/main-wrong-type.rs
@@ -1,4 +1,3 @@
// xfail-stage0
// error-pattern:Wrong type in main function: found fn(rec(int x
-fn main(rec(int x, int y) foo) {
-}
+fn main(foo: {x: int, y: int}) { }
\ No newline at end of file
diff --git a/src/test/compile-fail/missing-main.rs b/src/test/compile-fail/missing-main.rs
index 6eed365..4a91992 100644
--- a/src/test/compile-fail/missing-main.rs
+++ b/src/test/compile-fail/missing-main.rs
@@ -1,4 +1,3 @@
// xfail-stage0
// error-pattern:Main function not found
-fn mian() {
-}
+fn mian() { }
\ No newline at end of file
diff --git a/src/test/compile-fail/missing-return.rs b/src/test/compile-fail/missing-return.rs
index 34fb410..1050220 100644
--- a/src/test/compile-fail/missing-return.rs
+++ b/src/test/compile-fail/missing-return.rs
@@ -1,9 +1,6 @@
// error-pattern: return
-fn f() -> int {
-}
+fn f() -> int { }
-fn main() {
- f();
-}
+fn main() { f(); }
diff --git a/src/test/compile-fail/missing-return2.rs b/src/test/compile-fail/missing-return2.rs
index 2788f4c..af1612b 100644
--- a/src/test/compile-fail/missing-return2.rs
+++ b/src/test/compile-fail/missing-return2.rs
@@ -1,13 +1,10 @@
// error-pattern: return
fn f() -> int {
- // Make sure typestate doesn't interpret this alt expression
- // as the function result
- alt (true) {
- case (true) {
- }
- }
+
+ // Make sure typestate doesn't interpret this alt expression
+ // as the function result
+ alt true { true { } }
}
-fn main() {
-}
+fn main() { }
\ No newline at end of file
diff --git a/src/test/compile-fail/multiline-comment-line-tracking.rs b/src/test/compile-fail/multiline-comment-line-tracking.rs
index a345425..220a5e5 100644
--- a/src/test/compile-fail/multiline-comment-line-tracking.rs
+++ b/src/test/compile-fail/multiline-comment-line-tracking.rs
@@ -1,10 +1,6 @@
-// -*- rust -*-
-// error-pattern:9:2
-
-/* 1
- * 2
- * 3
- */
-fn main() {
- %; // parse error on line 9, but is reported on line 6 instead.
-}
+./src/test/compile-fail/multiline-comment-line-tracking.rs:9:2:9:3: [1;31merror:[0m unexpected token: %
+./src/test/compile-fail/multiline-comment-line-tracking.rs:9 %; // parse error on line 9, but is reported on line 6 instead.
+ ^
+rt: ---
+rt: f00e:main:main: upcall fail 'explicit failure', src/comp/syntax/parse/parser.rs:112
+rt: f00e:main: domain main @0x969e04c root task failed
diff --git a/src/test/compile-fail/native-type-mismatch.rs b/src/test/compile-fail/native-type-mismatch.rs
index 720b6f1..daa2c9f 100644
--- a/src/test/compile-fail/native-type-mismatch.rs
+++ b/src/test/compile-fail/native-type-mismatch.rs
@@ -2,6 +2,6 @@
use std;
fn main() {
- let std::os::libc::FILE f = std::io::rustrt::rust_get_stdin();
+ let f: std::os::libc::FILE = std::io::rustrt::rust_get_stdin();
std::os::libc::fopen(f, f);
-}
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/nested-ty-params.rs b/src/test/compile-fail/nested-ty-params.rs
index bbb246e..d321f6f 100644
--- a/src/test/compile-fail/nested-ty-params.rs
+++ b/src/test/compile-fail/nested-ty-params.rs
@@ -1,8 +1,6 @@
// xfail-stage0
// error-pattern:Attempt to use a type argument out of scope
-fn hd[U](&vec[U] v) -> U {
- fn hd1(&vec[U] w) -> U {
- ret w.(0);
- }
- ret hd1(v);
-}
+fn hd[U](v: &vec[U]) -> U {
+ fn hd1(w: &vec[U]) -> U { ret w.(0); }
+ ret hd1(v);
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/no-constraint-prop.rs b/src/test/compile-fail/no-constraint-prop.rs
index 0ba3d01..6d65be9 100644
--- a/src/test/compile-fail/no-constraint-prop.rs
+++ b/src/test/compile-fail/no-constraint-prop.rs
@@ -5,17 +5,17 @@
import std::uint::*;
fn main() {
- let uint a = 1u;
- let uint b = 4u;
- let uint c = 5u;
- // make sure that the constraint le(b, a) exists...
- check le(b, a);
- // ...invalidate it...
- b += 1u;
- check le(c, a);
- // ...and check that it doesn't get set in the poststate of
- // the next statement, since it's not true in the
- // prestate.
- auto d <- a;
- log (safe_slice("kitties", b, d));
+ let a: uint = 1u;
+ let b: uint = 4u;
+ let c: uint = 5u;
+ // make sure that the constraint le(b, a) exists...
+ check (le(b, a));
+ // ...invalidate it...
+ b += 1u;
+ check (le(c, a));
+ // ...and check that it doesn't get set in the poststate of
+ // the next statement, since it's not true in the
+ // prestate.
+ let d <- a;
+ log safe_slice("kitties", b, d);
}
\ No newline at end of file
diff --git a/src/test/compile-fail/no-self-dispatch.rs b/src/test/compile-fail/no-self-dispatch.rs
index 4e96f12..b23092b 100644
--- a/src/test/compile-fail/no-self-dispatch.rs
+++ b/src/test/compile-fail/no-self-dispatch.rs
@@ -1,11 +1,6 @@
// error-pattern: unresolved name
obj oT() {
- fn get() -> int {
- ret 3;
- }
- fn foo() {
- auto c = get();
- }
+ fn get() -> int { ret 3; }
+ fn foo() { let c = get(); }
}
-fn main() {
-}
+fn main() { }
\ No newline at end of file
diff --git a/src/test/compile-fail/not-a-pred-2.rs b/src/test/compile-fail/not-a-pred-2.rs
index 99a3616..63aad9b 100644
--- a/src/test/compile-fail/not-a-pred-2.rs
+++ b/src/test/compile-fail/not-a-pred-2.rs
@@ -3,6 +3,8 @@
// error-pattern: non-predicate
fn main() {
- check (1 == 2); // should fail to typecheck, as (a == b)
- // is not a manifest call
-}
+ check (1 ==
+ 2); // should fail to typecheck, as (a == b)
+ // is not a manifest call
+
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/not-a-pred-3.rs b/src/test/compile-fail/not-a-pred-3.rs
index d2145ca..6852429 100644
--- a/src/test/compile-fail/not-a-pred-3.rs
+++ b/src/test/compile-fail/not-a-pred-3.rs
@@ -2,13 +2,11 @@
// error-pattern: expected the constraint name
-obj f () {
- fn g (int q) -> bool {
- ret true;
- }
+obj f() {
+ fn g(q: int) -> bool { ret true; }
}
fn main() {
- auto z = f ();
- check (z.g)(42); // should fail to typecheck, as z.g isn't an explicit name
-}
+ let z = f();
+ check (z.g(42)); // should fail to typecheck, as z.g isn't an explicit name
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/not-a-pred-check.rs b/src/test/compile-fail/not-a-pred-check.rs
index 40f4d3b..20a0b5a 100644
--- a/src/test/compile-fail/not-a-pred-check.rs
+++ b/src/test/compile-fail/not-a-pred-check.rs
@@ -1,10 +1,10 @@
// -*- rust -*-
// error-pattern: non-predicate
-fn f(int q) -> bool { ret true; }
+fn f(q: int) -> bool { ret true; }
fn main() {
- auto x = 0;
+ let x = 0;
- check f(x);
-}
+ check (f(x));
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/not-a-pred.rs b/src/test/compile-fail/not-a-pred.rs
index ae8068d..a3421c6 100644
--- a/src/test/compile-fail/not-a-pred.rs
+++ b/src/test/compile-fail/not-a-pred.rs
@@ -2,15 +2,8 @@
// xfail-stage0
// error-pattern: Non-predicate in constraint: lt
-fn f(int a, int b) : lt(a,b) {
-}
+fn f(a: int, b: int) { }
-obj lt(int a, int b) {
-}
+obj lt(a: int, b: int) { }
-fn main() {
- let int a = 10;
- let int b = 23;
- check lt(a,b);
- f(a,b);
-}
+fn main() { let a: int = 10; let b: int = 23; check (lt(a, b)); f(a, b); }
\ No newline at end of file
diff --git a/src/test/compile-fail/not-pred-args.rs b/src/test/compile-fail/not-pred-args.rs
index daf781f..81a0cb0 100644
--- a/src/test/compile-fail/not-pred-args.rs
+++ b/src/test/compile-fail/not-pred-args.rs
@@ -2,9 +2,9 @@
// error-pattern: Constraint args must be
-pred f(int q) -> bool { ret true; }
+pred f(q: int) -> bool { ret true; }
fn main() {
-// should fail to typecheck, as pred args must be slot variables or literals
- check f(42 * 17);
-}
+ // should fail to typecheck, as pred args must be slot variables or literals
+ check (f(42 * 17));
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/or-init.rs b/src/test/compile-fail/or-init.rs
index aec1b49..3aac5cb 100644
--- a/src/test/compile-fail/or-init.rs
+++ b/src/test/compile-fail/or-init.rs
@@ -2,8 +2,8 @@
// error-pattern: Unsatisfied precondition constraint (for example, init(i
fn main() {
- let int i;
+ let i: int;
- log (false || {i = 5; true});
- log i;
+ log false || { i = 5; true };
+ log i;
}
\ No newline at end of file
diff --git a/src/test/compile-fail/or-patter-mismatch.rs b/src/test/compile-fail/or-patter-mismatch.rs
index b926e8d0a..d7525d7 100644
--- a/src/test/compile-fail/or-patter-mismatch.rs
+++ b/src/test/compile-fail/or-patter-mismatch.rs
@@ -1,12 +1,5 @@
// error-pattern: mismatched types
-tag blah {
- a(int, int, uint);
- b(int, int);
-}
+tag blah { a(int, int, uint); b(int, int); }
-fn main() {
- alt a(1, 1, 2u) {
- a(_, ?x, ?y) | b(?x, ?y) { }
- }
-}
+fn main() { alt a(1, 1, 2u) { a(_, x, y) | b(x, y) { } } }
\ No newline at end of file
diff --git a/src/test/compile-fail/output-type-mismatch.rs b/src/test/compile-fail/output-type-mismatch.rs
index c979f06..38ee7b5 100644
--- a/src/test/compile-fail/output-type-mismatch.rs
+++ b/src/test/compile-fail/output-type-mismatch.rs
@@ -1,9 +1,5 @@
// error-pattern: mismatched types
-fn f() {
-}
+fn f() { }
-fn main() {
- let int i;
- i = f();
-}
+fn main() { let i: int; i = f(); }
\ No newline at end of file
diff --git a/src/test/compile-fail/pattern-tyvar-2.rs b/src/test/compile-fail/pattern-tyvar-2.rs
index e7abfc1..27d7b50 100644
--- a/src/test/compile-fail/pattern-tyvar-2.rs
+++ b/src/test/compile-fail/pattern-tyvar-2.rs
@@ -6,21 +6,8 @@
// error-pattern: mismatched types
-tag bar {
- t1((), option::t[vec[int]]);
- t2;
-}
+tag bar { t1((), option::t[vec[int]]); t2; }
-fn foo(bar t) -> int {
- alt (t) {
- case (t1(_, some(?x))) {
- ret (x * 3);
- }
- case (_) {
- fail;
- }
- }
-}
+fn foo(t: bar) -> int { alt t { t1(_, some(x)) { ret x * 3; } _ { fail; } } }
-fn main() {
-}
\ No newline at end of file
+fn main() { }
\ No newline at end of file
diff --git a/src/test/compile-fail/pattern-tyvar.rs b/src/test/compile-fail/pattern-tyvar.rs
index cb94ee5..01da4d3 100644
--- a/src/test/compile-fail/pattern-tyvar.rs
+++ b/src/test/compile-fail/pattern-tyvar.rs
@@ -5,21 +5,8 @@
// error-pattern: mismatched types
-tag bar {
- t1((), option::t[vec[int]]);
- t2;
-}
+tag bar { t1((), option::t[vec[int]]); t2; }
-fn foo(bar t) {
- alt (t) {
- case (t1(_, some[int](?x))) {
- log x;
- }
- case (_) {
- fail;
- }
- }
-}
+fn foo(t: bar) { alt t { t1(_, some[int](x)) { log x; } _ { fail; } } }
-fn main() {
-}
\ No newline at end of file
+fn main() { }
\ No newline at end of file
diff --git a/src/test/compile-fail/pred-assign.rs b/src/test/compile-fail/pred-assign.rs
index 784164a..c70ee8e 100644
--- a/src/test/compile-fail/pred-assign.rs
+++ b/src/test/compile-fail/pred-assign.rs
@@ -3,18 +3,15 @@
// error-pattern: Unsatisfied precondition constraint (for example, lt(a, b)
-fn f(int a, int b) : lt(a,b) {
-}
+fn f(a: int, b: int) { }
-pred lt(int a, int b) -> bool {
- ret a < b;
-}
+pred lt(a: int, b: int) -> bool { ret a < b; }
fn main() {
- let int a = 10;
- let int b = 23;
- let int c = 77;
- check lt(a,b);
- a = 24;
- f(a,b);
-}
+ let a: int = 10;
+ let b: int = 23;
+ let c: int = 77;
+ check (lt(a, b));
+ a = 24;
+ f(a, b);
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/pred-not-bool.rs b/src/test/compile-fail/pred-not-bool.rs
index e4892f2..024ff52 100644
--- a/src/test/compile-fail/pred-not-bool.rs
+++ b/src/test/compile-fail/pred-not-bool.rs
@@ -5,9 +5,6 @@
// this checks that a pred with a non-bool return
// type is rejected, even if the pred is never used
-pred bad(int a) -> int {
- ret 37;
-}
+pred bad(a: int) -> int { ret 37; }
-fn main() {
-}
+fn main() { }
\ No newline at end of file
diff --git a/src/test/compile-fail/pred-on-wrong-slots.rs b/src/test/compile-fail/pred-on-wrong-slots.rs
index 50ae76b..adf0f02 100644
--- a/src/test/compile-fail/pred-on-wrong-slots.rs
+++ b/src/test/compile-fail/pred-on-wrong-slots.rs
@@ -3,19 +3,16 @@
// error-pattern: lt(a, c)
-fn f(int a, int b) : lt(a,b) {
-}
+fn f(a: int, b: int) { }
-pred lt(int a, int b) -> bool {
- ret a < b;
-}
+pred lt(a: int, b: int) -> bool { ret a < b; }
fn main() {
- let int a = 10;
- let int b = 23;
- let int c = 77;
- check lt(a,b);
- check lt(b,c);
- f(a,b);
- f(a,c);
-}
+ let a: int = 10;
+ let b: int = 23;
+ let c: int = 77;
+ check (lt(a, b));
+ check (lt(b, c));
+ f(a, b);
+ f(a, c);
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/pred-swap.rs b/src/test/compile-fail/pred-swap.rs
index 9d21ba7..4d3881c 100644
--- a/src/test/compile-fail/pred-swap.rs
+++ b/src/test/compile-fail/pred-swap.rs
@@ -3,18 +3,15 @@
// error-pattern: Unsatisfied precondition constraint (for example, lt(a, b)
-fn f(int a, int b) : lt(a,b) {
-}
+fn f(a: int, b: int) { }
-pred lt(int a, int b) -> bool {
- ret a < b;
-}
+pred lt(a: int, b: int) -> bool { ret a < b; }
fn main() {
- let int a = 10;
- let int b = 23;
- let int c = 77;
- check lt(a,b);
- b <-> a;
- f(a,b);
-}
+ let a: int = 10;
+ let b: int = 23;
+ let c: int = 77;
+ check (lt(a, b));
+ b <-> a;
+ f(a, b);
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/put-in-fn.rs b/src/test/compile-fail/put-in-fn.rs
index b00d398..c5e56de 100644
--- a/src/test/compile-fail/put-in-fn.rs
+++ b/src/test/compile-fail/put-in-fn.rs
@@ -4,9 +4,6 @@
// xfail-stage3
// error-pattern: iterator function
-fn f() -> int {
- put 10;
-}
+fn f() -> int { put 10; }
-fn main() {
-}
+fn main() { }
\ No newline at end of file
diff --git a/src/test/compile-fail/rec-extend.rs b/src/test/compile-fail/rec-extend.rs
index 936c76b..6103943 100644
--- a/src/test/compile-fail/rec-extend.rs
+++ b/src/test/compile-fail/rec-extend.rs
@@ -3,7 +3,7 @@
fn main() {
- auto a = rec(foo = 0);
+ let a = {foo: 0};
- auto b = rec(foo = true with a);
-}
+ let b = {foo: true with a};
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/rec-missing-fields.rs b/src/test/compile-fail/rec-missing-fields.rs
index 5b7dd4d..50bf16c 100644
--- a/src/test/compile-fail/rec-missing-fields.rs
+++ b/src/test/compile-fail/rec-missing-fields.rs
@@ -4,9 +4,6 @@
// Issue #51.
-type point = rec(int x, int y);
+type point = {x: int, y: int};
-fn main() {
- let point p = rec(x=10);
- log p.y;
-}
+fn main() { let p: point = {x: 10}; log p.y; }
\ No newline at end of file
diff --git a/src/test/compile-fail/ret-non-nil.rs b/src/test/compile-fail/ret-non-nil.rs
index 9d1435f..7c483ed 100644
--- a/src/test/compile-fail/ret-non-nil.rs
+++ b/src/test/compile-fail/ret-non-nil.rs
@@ -1,14 +1,7 @@
// error-pattern: ret; in function returning non-nil
-fn f() {
- ret;
-}
+fn f() { ret; }
-fn g() -> int {
- ret;
-}
+fn g() -> int { ret; }
-fn main() {
- f();
- g();
-}
+fn main() { f(); g(); }
\ No newline at end of file
diff --git a/src/test/compile-fail/return-uninit.rs b/src/test/compile-fail/return-uninit.rs
index 3711716..34b7a6b 100644
--- a/src/test/compile-fail/return-uninit.rs
+++ b/src/test/compile-fail/return-uninit.rs
@@ -1,10 +1,5 @@
// error-pattern: precondition constraint
-fn f() -> int {
- let int x;
- ret x;
-}
+fn f() -> int { let x: int; ret x; }
-fn main() {
- f();
-}
\ No newline at end of file
+fn main() { f(); }
\ No newline at end of file
diff --git a/src/test/compile-fail/self-call-non-obj.rs b/src/test/compile-fail/self-call-non-obj.rs
index 816c8ad..4d238f5 100644
--- a/src/test/compile-fail/self-call-non-obj.rs
+++ b/src/test/compile-fail/self-call-non-obj.rs
@@ -5,10 +5,8 @@
// Fix for issue #707.
fn main() {
- fn foo() -> int {
- ret 3();
- }
+ fn foo() -> int { ret 3(); }
self.foo();
-}
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/self-missing-method.rs b/src/test/compile-fail/self-missing-method.rs
index c415c28..32aee6f 100644
--- a/src/test/compile-fail/self-missing-method.rs
+++ b/src/test/compile-fail/self-missing-method.rs
@@ -1,12 +1,6 @@
-// error-pattern:expecting ., found (
-fn main() {
-
- obj foo() {
- fn m() {
- self();
- }
- }
-
- auto a = foo;
- a.m();
-}
+./src/test/compile-fail/self-missing-method.rs:6:14:6:15: [1;31merror:[0m expecting ., found (
+./src/test/compile-fail/self-missing-method.rs:6 self();
+ ^
+rt: ---
+rt: 0bb1:main:main: upcall fail 'explicit failure', src/comp/syntax/parse/parser.rs:112
+rt: 0bb1:main: domain main @0x8f5904c root task failed
diff --git a/src/test/compile-fail/shadow.rs b/src/test/compile-fail/shadow.rs
index 046c9f2..24bbf4f 100644
--- a/src/test/compile-fail/shadow.rs
+++ b/src/test/compile-fail/shadow.rs
@@ -1,25 +1,15 @@
// -*- rust -*-
// error-pattern:src/test/compile-fail/shadow.rs
-fn foo(vec[int] c) {
- let int a = 5;
- let vec[int] b = [];
+fn foo(c: vec[int]) {
+ let a: int = 5;
+ let b: vec[int] = [];
- alt (none[int]) {
- case (some[int](_)) {
- for (int i in c) {
- log a;
- auto a = 17;
- b += [a];
- }
+
+ alt none[int] {
+ some[int](_) { for i: int in c { log a; let a = 17; b += [a]; } }
}
- }
}
-tag t[T] {
- none;
- some(T);
-}
+tag t[T] { none; some(T); }
-fn main() {
- foo([]);
-}
+fn main() { foo([]); }
\ No newline at end of file
diff --git a/src/test/compile-fail/slot-as-pred.rs b/src/test/compile-fail/slot-as-pred.rs
index fa105bf..ae50c6b 100644
--- a/src/test/compile-fail/slot-as-pred.rs
+++ b/src/test/compile-fail/slot-as-pred.rs
@@ -2,13 +2,12 @@
// xfail-stage0
// error-pattern: unresolved name: lt
-fn f(int a, int b) : lt(a,b) {
-}
+fn f(a: int, b: int) { }
fn main() {
- let int lt;
- let int a = 10;
- let int b = 23;
- check lt(a,b);
- f(a,b);
-}
+ let lt: int;
+ let a: int = 10;
+ let b: int = 23;
+ check (lt(a, b));
+ f(a, b);
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/spawn-non-nil-fn.rs b/src/test/compile-fail/spawn-non-nil-fn.rs
index bd7d7d9..33d2b31 100644
--- a/src/test/compile-fail/spawn-non-nil-fn.rs
+++ b/src/test/compile-fail/spawn-non-nil-fn.rs
@@ -1,10 +1,6 @@
// xfail-stage0
// error-pattern: mismatched types
-fn f(int x) -> int {
- ret x;
-}
+fn f(x: int) -> int { ret x; }
-fn main() {
- spawn f(10);
-}
+fn main() { spawn f(10); }
\ No newline at end of file
diff --git a/src/test/compile-fail/swap-no-lval.rs b/src/test/compile-fail/swap-no-lval.rs
index db20cb3..a45f524 100644
--- a/src/test/compile-fail/swap-no-lval.rs
+++ b/src/test/compile-fail/swap-no-lval.rs
@@ -1,5 +1,3 @@
// error-pattern: assignment to non-lvalue
-fn main() {
- 5 <-> 3;
-}
+fn main() { 5 <-> 3; }
\ No newline at end of file
diff --git a/src/test/compile-fail/swap-uninit.rs b/src/test/compile-fail/swap-uninit.rs
index 18ca56b..e06d539 100644
--- a/src/test/compile-fail/swap-uninit.rs
+++ b/src/test/compile-fail/swap-uninit.rs
@@ -1,7 +1,3 @@
// error-pattern:Unsatisfied precondition
-fn main() {
- auto x = 3;
- auto y;
- x <-> y;
-}
+fn main() { let x = 3; let y; x <-> y; }
\ No newline at end of file
diff --git a/src/test/compile-fail/tag-type-args.rs b/src/test/compile-fail/tag-type-args.rs
index 4e890df..eb9dc23 100644
--- a/src/test/compile-fail/tag-type-args.rs
+++ b/src/test/compile-fail/tag-type-args.rs
@@ -1,13 +1,8 @@
// xfail-stage0
// error-pattern: Wrong number of type arguments
-tag quux[T] {
-}
+tag quux[T] { }
-fn foo(quux c) -> () {
- assert false;
-}
+fn foo(c: quux) { assert (false); }
-fn main() {
- fail;
-}
\ No newline at end of file
+fn main() { fail; }
\ No newline at end of file
diff --git a/src/test/compile-fail/tail-non-call.rs b/src/test/compile-fail/tail-non-call.rs
index 00a451f..632ea71 100644
--- a/src/test/compile-fail/tail-non-call.rs
+++ b/src/test/compile-fail/tail-non-call.rs
@@ -1,10 +1,6 @@
-// error-pattern: Non-call expression in tail call
-
-fn f() -> int {
- auto x = 1;
- be x;
-}
-
-fn main() {
- auto y = f();
-}
+./src/test/compile-fail/tail-non-call.rs:5:6:5:7: [1;31merror:[0m Non-call expression in tail call
+./src/test/compile-fail/tail-non-call.rs:5 be x;
+ ^
+rt: ---
+rt: f00e:main:main: upcall fail 'explicit failure', src/comp/syntax/parse/parser.rs:112
+rt: f00e:main: domain main @0x9d9404c root task failed
diff --git a/src/test/compile-fail/tail-typeck.rs b/src/test/compile-fail/tail-typeck.rs
index 64beedb..7dd315b 100644
--- a/src/test/compile-fail/tail-typeck.rs
+++ b/src/test/compile-fail/tail-typeck.rs
@@ -1,13 +1,7 @@
// error-pattern: mismatched types
-fn f() -> int {
- be g();
-}
+fn f() -> int { be g(); }
-fn g() -> uint {
- ret 0u;
-}
+fn g() -> uint { ret 0u; }
-fn main() {
- auto y = f();
-}
+fn main() { let y = f(); }
\ No newline at end of file
diff --git a/src/test/compile-fail/type-arg-out-of-scope.rs b/src/test/compile-fail/type-arg-out-of-scope.rs
index 46f3655..01b8e92 100644
--- a/src/test/compile-fail/type-arg-out-of-scope.rs
+++ b/src/test/compile-fail/type-arg-out-of-scope.rs
@@ -1,6 +1,6 @@
// xfail-stage0
// error-pattern:Attempt to use a type argument out of scope
-fn foo[T] (&T x) {
- fn bar(fn (&T) -> T f) { };
+fn foo[T](x: &T) {
+ fn bar(f: fn(&T) -> T ) { }
}
-fn main() { foo(1); }
+fn main() { foo(1); }
\ No newline at end of file
diff --git a/src/test/compile-fail/type-mismatch-multiple.rs b/src/test/compile-fail/type-mismatch-multiple.rs
index 10f7fc0..9a7a4b5 100644
--- a/src/test/compile-fail/type-mismatch-multiple.rs
+++ b/src/test/compile-fail/type-mismatch-multiple.rs
@@ -2,7 +2,4 @@
// error-pattern:mismatched types: expected bool
// error-pattern:mismatched types: expected int
-fn main() {
- let bool a = 1;
- let int b = true;
-}
\ No newline at end of file
+fn main() { let a: bool = 1; let b: int = true; }
\ No newline at end of file
diff --git a/src/test/compile-fail/type-mismatch.rs b/src/test/compile-fail/type-mismatch.rs
index 1ab8a13..059c4cd 100644
--- a/src/test/compile-fail/type-mismatch.rs
+++ b/src/test/compile-fail/type-mismatch.rs
@@ -2,8 +2,4 @@
// error-pattern:expected bool but found int
// issue #516
-fn main() {
- auto x = true;
- auto y = 1;
- auto z = x + y;
-}
\ No newline at end of file
+fn main() { let x = true; let y = 1; let z = x + y; }
\ No newline at end of file
diff --git a/src/test/compile-fail/type-recursive.rs b/src/test/compile-fail/type-recursive.rs
index 030947a..b71f47d 100644
--- a/src/test/compile-fail/type-recursive.rs
+++ b/src/test/compile-fail/type-recursive.rs
@@ -1,5 +1,5 @@
// xfail-stage0
// error-pattern:illegal recursive type
-type t1 = rec(int foo, t1 foolish);
+type t1 = {foo: int, foolish: t1};
-fn main() {}
+fn main() { }
\ No newline at end of file
diff --git a/src/test/compile-fail/type-shadow.rs b/src/test/compile-fail/type-shadow.rs
index 8f8aff9..52022cf 100644
--- a/src/test/compile-fail/type-shadow.rs
+++ b/src/test/compile-fail/type-shadow.rs
@@ -3,10 +3,10 @@
// error-pattern: mismatched types
fn main() {
- type X = int;
- type Y = X;
- if (true) {
- type X = str;
- let Y y = "hello";
- }
-}
+ type X = int;
+ type Y = X;
+ if true {
+ type X = str;
+ let y: Y = "hello";
+ }
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/unbalanced-comment.rs b/src/test/compile-fail/unbalanced-comment.rs
index c9d3e0c..55d4bfb 100644
--- a/src/test/compile-fail/unbalanced-comment.rs
+++ b/src/test/compile-fail/unbalanced-comment.rs
@@ -1,11 +1,6 @@
-// -*- rust -*-
-
-// error-pattern: unterminated block comment
-
-/*
- * This is an un-balanced /* multi-line comment.
- */
-
-fn main() {
- log "hello, world.";
-}
+./src/test/compile-fail/unbalanced-comment.rs:11:1:11:1: [1;31merror:[0m unterminated block comment
+./src/test/compile-fail/unbalanced-comment.rs:11 }
+ ^
+rt: ---
+rt: f00e:main:main: upcall fail 'explicit failure', src/comp/syntax/parse/lexer.rs:153
+rt: f00e:main: domain main @0x96ef04c root task failed
diff --git a/src/test/compile-fail/uninit-after-item.rs b/src/test/compile-fail/uninit-after-item.rs
index c6402e6..905cef4 100644
--- a/src/test/compile-fail/uninit-after-item.rs
+++ b/src/test/compile-fail/uninit-after-item.rs
@@ -1,8 +1,8 @@
// error-pattern:Unsatisfied precondition constraint (for example, init(bar
// xfail-stage0
fn main() {
- auto bar;
- fn baz(int x) { }
+ let bar;
+ fn baz(x: int) { }
bind baz(bar);
}
diff --git a/src/test/compile-fail/unreachable-arm.rs b/src/test/compile-fail/unreachable-arm.rs
index cfff479..eaf5d75 100644
--- a/src/test/compile-fail/unreachable-arm.rs
+++ b/src/test/compile-fail/unreachable-arm.rs
@@ -2,9 +2,4 @@
tag foo { a(@foo, int); b(uint); }
-fn main() {
- alt b(1u) {
- b(_) | a(@_, 1) {}
- a(_, 1) {}
- }
-}
+fn main() { alt b(1u) { b(_) | a(@_, 1) { } a(_, 1) { } } }
\ No newline at end of file
diff --git a/src/test/compile-fail/unsafe-alias-2.rs b/src/test/compile-fail/unsafe-alias-2.rs
index 4a9551a..3917dd3 100644
--- a/src/test/compile-fail/unsafe-alias-2.rs
+++ b/src/test/compile-fail/unsafe-alias-2.rs
@@ -1,15 +1,8 @@
// error-pattern:invalidate alias x
-fn whoknows(@mutable int x) {
- *x = 10;
-}
+fn whoknows(x: @mutable int) { *x = 10; }
fn main() {
- auto box = @mutable 1;
- alt (*box) {
- case (?x) {
- whoknows(box);
- log_err x;
- }
- }
-}
+ let box = @mutable 1;
+ alt *box { x { whoknows(box); log_err x; } }
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/unsafe-alias.rs b/src/test/compile-fail/unsafe-alias.rs
index a81b490..46fb135 100644
--- a/src/test/compile-fail/unsafe-alias.rs
+++ b/src/test/compile-fail/unsafe-alias.rs
@@ -1,14 +1,7 @@
// error-pattern:may alias with argument
-fn foo(&int x, fn() f) {
- log x;
-}
+fn foo(x: &int, f: fn() ) { log x; }
-fn whoknows(@mutable int x) {
- *x = 10;
-}
+fn whoknows(x: @mutable int) { *x = 10; }
-fn main() {
- auto box = @mutable 1;
- foo(*box, bind whoknows(box));
-}
+fn main() { let box = @mutable 1; foo(*box, bind whoknows(box)); }
\ No newline at end of file
diff --git a/src/test/compile-fail/unsafe-alt.rs b/src/test/compile-fail/unsafe-alt.rs
index 4144e37..2e0605fa 100644
--- a/src/test/compile-fail/unsafe-alt.rs
+++ b/src/test/compile-fail/unsafe-alt.rs
@@ -1,17 +1,8 @@
// error-pattern:invalidate alias i
-tag foo {
- left(int);
- right(bool);
-}
+tag foo { left(int); right(bool); }
fn main() {
- auto x = left(10);
- alt (x) {
- case (left(?i)) {
- x = right(false);
- log i;
- }
- case (_) {}
- }
-}
+ let x = left(10);
+ alt x { left(i) { x = right(false); log i; } _ { } }
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/unsafe-for.rs b/src/test/compile-fail/unsafe-for.rs
index bc05017..62fd755 100644
--- a/src/test/compile-fail/unsafe-for.rs
+++ b/src/test/compile-fail/unsafe-for.rs
@@ -1,9 +1,6 @@
// error-pattern:invalidate alias x
fn main() {
- let vec[mutable int] v = [mutable 1, 2, 3];
- for (int x in v) {
- v.(0) = 10;
- log x;
- }
-}
+ let v: vec[mutable int] = [mutable 1, 2, 3];
+ for x: int in v { v.(0) = 10; log x; }
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/unsafe-mutable-alias.rs b/src/test/compile-fail/unsafe-mutable-alias.rs
index b696805..24accc3 100644
--- a/src/test/compile-fail/unsafe-mutable-alias.rs
+++ b/src/test/compile-fail/unsafe-mutable-alias.rs
@@ -1,12 +1,6 @@
// xfail-stage0
// error-pattern:mutable alias to a variable that roots another alias
-fn f(&int a, &mutable int b) -> int {
- b += 1;
- ret a + b;
-}
+fn f(a: &int, b: &mutable int) -> int { b += 1; ret a + b; }
-fn main() {
- auto i = 4;
- log f(i, i);
-}
+fn main() { let i = 4; log f(i, i); }
\ No newline at end of file
diff --git a/src/test/compile-fail/use-after-move.rs b/src/test/compile-fail/use-after-move.rs
index 6c26279..ff20307 100644
--- a/src/test/compile-fail/use-after-move.rs
+++ b/src/test/compile-fail/use-after-move.rs
@@ -1,6 +1,2 @@
// error-pattern: Unsatisfied precondition constraint (for example, init(x
-fn main() {
- auto x = @5;
- auto y <- x;
- log *x;
-}
\ No newline at end of file
+fn main() { let x = @5; let y <- x; log *x; }
\ No newline at end of file
diff --git a/src/test/compile-fail/use-meta-dup.rs b/src/test/compile-fail/use-meta-dup.rs
index fc13c1e..a9e8df4 100644
--- a/src/test/compile-fail/use-meta-dup.rs
+++ b/src/test/compile-fail/use-meta-dup.rs
@@ -1,7 +1,6 @@
// xfail-stage0
// error-pattern:duplicate meta item `name`
-use std(name = "std",
- name = "nonstd");
+use std(name = "std", name = "nonstd");
-fn main(){}
+fn main() { }
\ No newline at end of file
diff --git a/src/test/compile-fail/use-meta-mismatch.rs b/src/test/compile-fail/use-meta-mismatch.rs
index fc01f5e..a2adca8 100644
--- a/src/test/compile-fail/use-meta-mismatch.rs
+++ b/src/test/compile-fail/use-meta-mismatch.rs
@@ -1,5 +1,5 @@
// error-pattern:can't find crate for 'std'
-use std (complex(meta(item)));
+use std(complex(meta(item)));
-fn main() {}
\ No newline at end of file
+fn main() { }
\ No newline at end of file
diff --git a/src/test/compile-fail/use-uninit-2.rs b/src/test/compile-fail/use-uninit-2.rs
index 79cebe2..d46c340 100644
--- a/src/test/compile-fail/use-uninit-2.rs
+++ b/src/test/compile-fail/use-uninit-2.rs
@@ -1,13 +1,5 @@
// error-pattern:Unsatisfied precondition
-fn foo(int x) {
- log x;
-}
+fn foo(x: int) { log x; }
-fn main() {
- let int x;
- if (1 > 2) {
- x = 10;
- }
- foo(x);
-}
\ No newline at end of file
+fn main() { let x: int; if 1 > 2 { x = 10; } foo(x); }
\ No newline at end of file
diff --git a/src/test/compile-fail/use-uninit-3.rs b/src/test/compile-fail/use-uninit-3.rs
index e654545..cf680f0 100644
--- a/src/test/compile-fail/use-uninit-3.rs
+++ b/src/test/compile-fail/use-uninit-3.rs
@@ -1,15 +1,5 @@
// error-pattern:Unsatisfied precondition
-fn foo(int x) {
- log x;
-}
+fn foo(x: int) { log x; }
-fn main() {
- let int x;
- if (1 > 2) {
- log "whoops";
- } else {
- x = 10;
- }
- foo(x);
-}
\ No newline at end of file
+fn main() { let x: int; if 1 > 2 { log "whoops"; } else { x = 10; } foo(x); }
\ No newline at end of file
diff --git a/src/test/compile-fail/use-uninit-dtor.rs b/src/test/compile-fail/use-uninit-dtor.rs
index fed90df..c3c824d 100644
--- a/src/test/compile-fail/use-uninit-dtor.rs
+++ b/src/test/compile-fail/use-uninit-dtor.rs
@@ -1,11 +1,6 @@
// error-pattern:Unsatisfied precondition
fn main() {
- state obj foo(int x) {
- drop {
- let int baz;
- log(baz);
- }
- }
- fail;
-}
+ obj foo(x: int) {drop { let baz: int; log baz; } }
+ fail;
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/use-uninit.rs b/src/test/compile-fail/use-uninit.rs
index 03dafdc..b787947 100644
--- a/src/test/compile-fail/use-uninit.rs
+++ b/src/test/compile-fail/use-uninit.rs
@@ -1,10 +1,5 @@
// error-pattern:Unsatisfied precondition
-fn foo(int x) {
- log x;
-}
+fn foo(x: int) { log x; }
-fn main() {
- let int x;
- foo(x);
-}
\ No newline at end of file
+fn main() { let x: int; foo(x); }
\ No newline at end of file
diff --git a/src/test/compile-fail/vec-field.rs b/src/test/compile-fail/vec-field.rs
index 8c3f0c3..76464a3 100644
--- a/src/test/compile-fail/vec-field.rs
+++ b/src/test/compile-fail/vec-field.rs
@@ -3,8 +3,8 @@
// issue #367
fn f() {
- auto v = [1];
- log v.some_field_name; //type error
+ let v = [1];
+ log v.some_field_name; //type error
}
-fn main() {}
\ No newline at end of file
+fn main() { }
\ No newline at end of file
diff --git a/src/test/compile-fail/vector-no-ann.rs b/src/test/compile-fail/vector-no-ann.rs
index cc61922..087fa20 100644
--- a/src/test/compile-fail/vector-no-ann.rs
+++ b/src/test/compile-fail/vector-no-ann.rs
@@ -1,4 +1,2 @@
// error-pattern:cannot determine a type
-fn main() -> () {
- auto foo = [];
-}
+fn main() { let foo = []; }
\ No newline at end of file
diff --git a/src/test/compile-fail/while-bypass.rs b/src/test/compile-fail/while-bypass.rs
index 1de89e9..7fa5ccb 100644
--- a/src/test/compile-fail/while-bypass.rs
+++ b/src/test/compile-fail/while-bypass.rs
@@ -1,13 +1,5 @@
// error-pattern: precondition constraint
-fn f() -> int {
- let int x;
- while(true) {
- x = 10;
- }
- ret x;
-}
+fn f() -> int { let x: int; while true { x = 10; } ret x; }
-fn main() {
- f();
-}
+fn main() { f(); }
\ No newline at end of file
diff --git a/src/test/compile-fail/while-expr.rs b/src/test/compile-fail/while-expr.rs
index 9077c18..8da769a 100644
--- a/src/test/compile-fail/while-expr.rs
+++ b/src/test/compile-fail/while-expr.rs
@@ -1,7 +1,3 @@
// error-pattern: precondition constraint
-fn main() {
- let bool x;
- while(x) {
- }
-}
+fn main() { let x: bool; while x { } }
\ No newline at end of file
diff --git a/src/test/compile-fail/while-loop-constraints.rs b/src/test/compile-fail/while-loop-constraints.rs
index 4c97aae..9cada6f 100644
--- a/src/test/compile-fail/while-loop-constraints.rs
+++ b/src/test/compile-fail/while-loop-constraints.rs
@@ -2,16 +2,7 @@
// error-pattern: Unsatisfied precondition constraint (for example, init(y
fn main() {
- let int y = 42;
- let int x;
- while (true) {
- log y;
- while (true) {
- while (true) {
- while (true) {
- x <- y;
- }
- }
- }
- }
+ let y: int = 42;
+ let x: int;
+ while true { log y; while true { while true { while true { x <- y; } } } }
}
\ No newline at end of file
diff --git a/src/test/compile-fail/while-loop-pred-constraints.rs b/src/test/compile-fail/while-loop-pred-constraints.rs
index 3908004..0defbe2 100644
--- a/src/test/compile-fail/while-loop-pred-constraints.rs
+++ b/src/test/compile-fail/while-loop-pred-constraints.rs
@@ -1,27 +1,17 @@
// xfail-stage0
// error-pattern: Unsatisfied precondition constraint (for example, even(y
-fn print_even(int y) : even(y) {
- log y;
-}
+fn print_even(y: int) { log y; }
-pred even(int y) -> bool {
- true
-}
+pred even(y: int) -> bool { true }
fn main() {
- let int y = 42;
- let int x = 1;
- check even(y);
- while (true) {
- print_even(y);
- while (true) {
- while (true) {
- while (true) {
- y += x;
+ let y: int = 42;
+ let x: int = 1;
+ check (even(y));
+ while true {
+ print_even(y);
+ while true { while true { while true { y += x; } } }
}
- }
- }
- }
}
\ No newline at end of file
diff --git a/src/test/compile-fail/while-type-error.rs b/src/test/compile-fail/while-type-error.rs
index 07d7867..3ee7dae 100644
--- a/src/test/compile-fail/while-type-error.rs
+++ b/src/test/compile-fail/while-type-error.rs
@@ -1,7 +1,4 @@
// error-pattern: mismatched types
-fn main() {
- while (main) {
- }
-}
+fn main() { while main { } }
diff --git a/src/test/compile-fail/writing-through-read-alias.rs b/src/test/compile-fail/writing-through-read-alias.rs
index 79bb37d..5e78a77 100644
--- a/src/test/compile-fail/writing-through-read-alias.rs
+++ b/src/test/compile-fail/writing-through-read-alias.rs
@@ -3,13 +3,8 @@
// error-pattern:assignment to immutable field
-type point = rec(int x, int y, int z);
+type point = {x: int, y: int, z: int};
-fn f(&point p) {
- p.x = 13;
-}
+fn f(p: &point) { p.x = 13; }
-fn main() {
- let point x = rec(x=10, y=11, z=12);
- f(x);
-}
+fn main() { let x: point = {x: 10, y: 11, z: 12}; f(x); }
\ No newline at end of file
diff --git a/src/test/compile-fail/writing-through-uninit-vec.rs b/src/test/compile-fail/writing-through-uninit-vec.rs
index 55edbf8..e71cf16 100644
--- a/src/test/compile-fail/writing-through-uninit-vec.rs
+++ b/src/test/compile-fail/writing-through-uninit-vec.rs
@@ -1,10 +1,5 @@
// error-pattern: Unsatisfied precondition constraint
-fn test() {
- let vec[int] w;
- w.(5) = 0;
-}
+fn test() { let w: vec[int]; w.(5) = 0; }
-fn main() {
- test();
-}
\ No newline at end of file
+fn main() { test(); }
\ No newline at end of file
diff --git a/src/test/compile-fail/writing-to-immutable-obj.rs b/src/test/compile-fail/writing-to-immutable-obj.rs
index 0fa7443..cf164e4 100644
--- a/src/test/compile-fail/writing-to-immutable-obj.rs
+++ b/src/test/compile-fail/writing-to-immutable-obj.rs
@@ -1,9 +1,6 @@
// xfail-stage0
// error-pattern:assigning to immutable obj field
-obj objy(int x) {
- fn foo() -> () {
- x = 5;
- }
+obj objy(x: int) {
+ fn foo() { x = 5; }
}
-fn main() {
-}
+fn main() { }
\ No newline at end of file
diff --git a/src/test/compile-fail/writing-to-immutable-rec.rs b/src/test/compile-fail/writing-to-immutable-rec.rs
index c98d4b5..c40c693 100644
--- a/src/test/compile-fail/writing-to-immutable-rec.rs
+++ b/src/test/compile-fail/writing-to-immutable-rec.rs
@@ -1,5 +1,2 @@
// error-pattern: assignment to immutable field
-fn main() {
- let rec(int x) r = rec(x=1);
- r.x = 6;
-}
+fn main() { let r: {x: int} = {x: 1}; r.x = 6; }
\ No newline at end of file
diff --git a/src/test/compile-fail/writing-to-immutable-vec.rs b/src/test/compile-fail/writing-to-immutable-vec.rs
index 7f574ce..0415547 100644
--- a/src/test/compile-fail/writing-to-immutable-vec.rs
+++ b/src/test/compile-fail/writing-to-immutable-vec.rs
@@ -1,6 +1,3 @@
// xfail-stage0
// error-pattern:assignment to immutable vec content
-fn main() {
- let vec[int] v = [1, 2, 3];
- v.(1) = 4;
-}
+fn main() { let v: vec[int] = [1, 2, 3]; v.(1) = 4; }
\ No newline at end of file
diff --git a/src/test/compile-fail/wrong-ret-type.rs b/src/test/compile-fail/wrong-ret-type.rs
index f00a734..b443508 100644
--- a/src/test/compile-fail/wrong-ret-type.rs
+++ b/src/test/compile-fail/wrong-ret-type.rs
@@ -1,7 +1,3 @@
// error-pattern: mismatched types
-fn mk_int() -> uint {
- let int i = 3;
- ret i;
-}
-fn main() {
-}
+fn mk_int() -> uint { let i: int = 3; ret i; }
+fn main() { }
\ No newline at end of file
diff --git a/src/test/compiletest/compiletest.rs b/src/test/compiletest/compiletest.rs
index cd349c3..0e1cc7f 100644
--- a/src/test/compiletest/compiletest.rs
+++ b/src/test/compiletest/compiletest.rs
@@ -12,100 +12,89 @@
import std::run;
import std::task;
-tag mode {
- mode_compile_fail;
- mode_run_fail;
- mode_run_pass;
-}
+tag mode { mode_compile_fail; mode_run_fail; mode_run_pass; }
-type config = rec(// The library paths required for running the compiler
- str compile_lib_path,
- // The library paths required for running compiled programs
- str run_lib_path,
- // The rustc executable
- str rustc_path,
- // The directory containing the tests to run
- str src_base,
- // The directory where programs should be built
- str build_base,
- // The name of the stage being built (stage1, etc)
- str stage_id,
- // The test mode, compile-fail, run-fail, run-pass
- mode mode,
- // Run ignored tests
- bool run_ignored,
- // Only run tests that match this filter
- option::t[str] filter,
- // A command line to prefix program execution with,
- // for running under valgrind
- option::t[str] runtool,
- // Flags to pass to the compiler
- option::t[str] rustcflags,
- // Explain what's going on
- bool verbose);
+type config = // The library paths required for running the compiler
+ // The library paths required for running compiled programs
+ // The rustc executable
+ // The directory containing the tests to run
+ // The directory where programs should be built
+ // The name of the stage being built (stage1, etc)
+ // The test mode, compile-fail, run-fail, run-pass
+ // Run ignored tests
+ // Only run tests that match this filter
+ // A command line to prefix program execution with,
+ // for running under valgrind
+ // Flags to pass to the compiler
+ // Explain what's going on
+ {compile_lib_path: str,
+ run_lib_path: str,
+ rustc_path: str,
+ src_base: str,
+ build_base: str,
+ stage_id: str,
+ mode: mode,
+ run_ignored: bool,
+ filter: option::t[str],
+ runtool: option::t[str],
+ rustcflags: option::t[str],
+ verbose: bool};
-fn main(vec[str] args) {
+fn main(args: vec[str]) {
- auto ivec_args = {
- auto ivec_args = ~[];
- for (str arg in args) {
- ivec_args += ~[arg];
- }
- ivec_args
- };
+ let ivec_args =
+ {
+ let ivec_args = ~[];
+ for arg: str in args { ivec_args += ~[arg]; }
+ ivec_args
+ };
- auto config = parse_config(ivec_args);
+ let config = parse_config(ivec_args);
log_config(config);
run_tests(config);
}
-fn parse_config(&str[] args) -> config {
- auto opts = ~[getopts::reqopt("compile-lib-path"),
- getopts::reqopt("run-lib-path"),
- getopts::reqopt("rustc-path"),
- getopts::reqopt("src-base"),
- getopts::reqopt("build-base"),
- getopts::reqopt("stage-id"),
- getopts::reqopt("mode"),
- getopts::optflag("ignored"),
- getopts::optopt("runtool"),
- getopts::optopt("rustcflags"),
- getopts::optflag("verbose")];
+fn parse_config(args: &str[]) -> config {
+ let opts =
+ ~[getopts::reqopt("compile-lib-path"),
+ getopts::reqopt("run-lib-path"), getopts::reqopt("rustc-path"),
+ getopts::reqopt("src-base"), getopts::reqopt("build-base"),
+ getopts::reqopt("stage-id"), getopts::reqopt("mode"),
+ getopts::optflag("ignored"), getopts::optopt("runtool"),
+ getopts::optopt("rustcflags"), getopts::optflag("verbose")];
- check ivec::is_not_empty(args);
- auto args_ = ivec::tail(args);
- auto match = alt (getopts::getopts_ivec(args_, opts)) {
- getopts::success(?m) { m }
- getopts::failure(?f) {
- fail getopts::fail_str(f)
- }
- };
+ check (ivec::is_not_empty(args));
+ let args_ = ivec::tail(args);
+ let match =
+ alt getopts::getopts_ivec(args_, opts) {
+ getopts::success(m) { m }
+ getopts::failure(f) { fail getopts::fail_str(f) }
+ };
- ret rec(compile_lib_path = getopts::opt_str(match, "compile-lib-path"),
- run_lib_path = getopts::opt_str(match, "run-lib-path"),
- rustc_path = getopts::opt_str(match, "rustc-path"),
- src_base = getopts::opt_str(match, "src-base"),
- build_base = getopts::opt_str(match, "build-base"),
- stage_id = getopts::opt_str(match, "stage-id"),
- mode = str_mode(getopts::opt_str(match, "mode")),
- run_ignored = getopts::opt_present(match, "ignored"),
- filter = if vec::len(match.free) > 0u {
- option::some(match.free.(0))
- } else {
- option::none
- },
- runtool = getopts::opt_maybe_str(match, "runtool"),
- rustcflags = getopts::opt_maybe_str(match, "rustcflags"),
- verbose = getopts::opt_present(match, "verbose"));
+ ret {compile_lib_path: getopts::opt_str(match, "compile-lib-path"),
+ run_lib_path: getopts::opt_str(match, "run-lib-path"),
+ rustc_path: getopts::opt_str(match, "rustc-path"),
+ src_base: getopts::opt_str(match, "src-base"),
+ build_base: getopts::opt_str(match, "build-base"),
+ stage_id: getopts::opt_str(match, "stage-id"),
+ mode: str_mode(getopts::opt_str(match, "mode")),
+ run_ignored: getopts::opt_present(match, "ignored"),
+ filter:
+ if vec::len(match.free) > 0u {
+ option::some(match.free.(0))
+ } else { option::none },
+ runtool: getopts::opt_maybe_str(match, "runtool"),
+ rustcflags: getopts::opt_maybe_str(match, "rustcflags"),
+ verbose: getopts::opt_present(match, "verbose")};
}
-fn log_config(&config config) {
- auto c = config;
+fn log_config(config: &config) {
+ let c = config;
logv(c, #fmt("configuration:"));
logv(c, #fmt("compile_lib_path: %s", config.compile_lib_path));
logv(c, #fmt("run_lib_path: %s", config.run_lib_path));
logv(c, #fmt("rustc_path: %s", config.rustc_path));
- logv(c, #fmt("src_base: %s", config.src_base));;
+ logv(c, #fmt("src_base: %s", config.src_base));
logv(c, #fmt("build_base: %s", config.build_base));
logv(c, #fmt("stage_id: %s", config.stage_id));
logv(c, #fmt("mode: %s", mode_str(config.mode)));
@@ -117,22 +106,15 @@
logv(c, #fmt("\n"));
}
-fn opt_str(option::t[str] maybestr) -> str {
- alt maybestr {
- option::some(?s) { s }
- option::none { "(none)" }
- }
+fn opt_str(maybestr: option::t[str]) -> str {
+ alt maybestr { option::some(s) { s } option::none. { "(none)" } }
}
-fn str_opt(str maybestr) -> option::t[str] {
- if maybestr != "(none)" {
- option::some(maybestr)
- } else {
- option::none
- }
+fn str_opt(maybestr: str) -> option::t[str] {
+ if maybestr != "(none)" { option::some(maybestr) } else { option::none }
}
-fn str_mode(str s) -> mode {
+fn str_mode(s: str) -> mode {
alt s {
"compile-fail" { mode_compile_fail }
"run-fail" { mode_run_fail }
@@ -141,84 +123,76 @@
}
}
-fn mode_str(mode mode) -> str {
- alt (mode) {
- mode_compile_fail { "compile-fail" }
- mode_run_fail { "run-fail" }
- mode_run_pass { "run-pass" }
+fn mode_str(mode: mode) -> str {
+ alt mode {
+ mode_compile_fail. { "compile-fail" }
+ mode_run_fail. { "run-fail" }
+ mode_run_pass. { "run-pass" }
}
}
-type cx = rec(config config,
- procsrv::handle procsrv);
+type cx = {config: config, procsrv: procsrv::handle};
-fn run_tests(&config config) {
- auto opts = test_opts(config);
- auto cx = rec(config = config,
- procsrv = procsrv::mk());
- auto tests = make_tests(cx);
+fn run_tests(config: &config) {
+ let opts = test_opts(config);
+ let cx = {config: config, procsrv: procsrv::mk()};
+ let tests = make_tests(cx);
test::run_tests_console_(opts, tests.tests, tests.to_task);
procsrv::close(cx.procsrv);
}
-fn test_opts(&config config) -> test::test_opts {
- rec(filter = config.filter,
- run_ignored = config.run_ignored)
+fn test_opts(config: &config) -> test::test_opts {
+ {filter: config.filter, run_ignored: config.run_ignored}
}
-type tests_and_conv_fn = rec(test::test_desc[] tests,
- fn(&fn()) -> task to_task);
+type tests_and_conv_fn =
+ {tests: test::test_desc[], to_task: fn(&fn() ) -> task };
-fn make_tests(&cx cx) -> tests_and_conv_fn {
+fn make_tests(cx: &cx) -> tests_and_conv_fn {
log #fmt("making tests from %s", cx.config.src_base);
- auto configport = port[str]();
- auto tests = ~[];
- for (str file in fs::list_dir(cx.config.src_base)) {
+ let configport = port[str]();
+ let tests = ~[];
+ for file: str in fs::list_dir(cx.config.src_base) {
log #fmt("inspecting file %s", file);
- if (is_test(file)) {
- tests += ~[make_test(cx, file, configport)];
- }
+ if is_test(file) { tests += ~[make_test(cx, file, configport)]; }
}
- ret rec(tests = tests,
- to_task = bind closure_to_task(cx, configport, _));
+ ret {tests: tests, to_task: bind closure_to_task(cx, configport, _)};
}
-fn is_test(&str testfile) -> bool {
- auto name = fs::basename(testfile);
- (str::ends_with(name, ".rs") || str::ends_with(name, ".rc"))
- && !(str::starts_with(name, ".")
- || str::starts_with(name, "#")
- || str::starts_with(name, "~"))
+fn is_test(testfile: &str) -> bool {
+ let name = fs::basename(testfile);
+ (str::ends_with(name, ".rs") || str::ends_with(name, ".rc")) &&
+ !(str::starts_with(name, ".") || str::starts_with(name, "#") ||
+ str::starts_with(name, "~"))
}
-fn make_test(&cx cx, &str testfile,
- &port[str] configport) -> test::test_desc {
- rec(name = testfile,
- fn = make_test_closure(testfile, chan(configport)),
- ignore = is_test_ignored(cx.config, testfile))
+fn make_test(cx: &cx, testfile: &str, configport: &port[str]) ->
+ test::test_desc {
+ {name: testfile,
+ fn: make_test_closure(testfile, chan(configport)),
+ ignore: is_test_ignored(cx.config, testfile)}
}
-fn is_test_ignored(&config config, &str testfile) -> bool {
- auto found = false;
- for each (str ln in iter_header(testfile)) {
+fn is_test_ignored(config: &config, testfile: &str) -> bool {
+ let found = false;
+ for each ln: str in iter_header(testfile) {
// FIXME: Can't return or break from iterator
found = found || parse_name_directive(ln, "xfail-" + config.stage_id);
}
ret found;
}
-iter iter_header(&str testfile) -> str {
- auto rdr = io::file_reader(testfile);
+iter iter_header(testfile: &str) -> str {
+ let rdr = io::file_reader(testfile);
while !rdr.eof() {
- auto ln = rdr.read_line();
+ let ln = rdr.read_line();
+
// Assume that any directives will be found before the
// first module or function. This doesn't seem to be an optimization
// with a warm page cache. Maybe with a cold one.
if str::starts_with(ln, "fn") || str::starts_with(ln, "mod") {
break;
- } else {
- put ln;
- }
+ } else { put ln; }
}
}
@@ -241,12 +215,11 @@
Really convoluted. Need to think up of a better definition for tests.
*/
-fn make_test_closure(&str testfile,
- chan[str] configchan) -> test::test_fn {
+fn make_test_closure(testfile: &str, configchan: chan[str]) -> test::test_fn {
bind send_config(testfile, configchan)
}
-fn send_config(str testfile, chan[str] configchan) {
+fn send_config(testfile: str, configchan: chan[str]) {
task::send(configchan, testfile);
}
@@ -259,172 +232,142 @@
break up the config record and pass everything individually to the spawned
function. */
-fn closure_to_task(cx cx, port[str] configport, &fn() testfn) -> task{
+fn closure_to_task(cx: cx, configport: port[str], testfn: &fn() ) -> task {
testfn();
- auto testfile = task::recv(configport);
+ let testfile = task::recv(configport);
ret spawn run_test_task(cx.config.compile_lib_path,
- cx.config.run_lib_path,
- cx.config.rustc_path,
- cx.config.src_base,
- cx.config.build_base,
- cx.config.stage_id,
- mode_str(cx.config.mode),
- cx.config.run_ignored,
- opt_str(cx.config.filter),
+ cx.config.run_lib_path, cx.config.rustc_path,
+ cx.config.src_base, cx.config.build_base,
+ cx.config.stage_id, mode_str(cx.config.mode),
+ cx.config.run_ignored, opt_str(cx.config.filter),
opt_str(cx.config.runtool),
- opt_str(cx.config.rustcflags),
- cx.config.verbose,
- procsrv::clone(cx.procsrv).chan,
- testfile);
+ opt_str(cx.config.rustcflags), cx.config.verbose,
+ procsrv::clone(cx.procsrv).chan, testfile);
}
-fn run_test_task(str compile_lib_path,
- str run_lib_path,
- str rustc_path,
- str src_base,
- str build_base,
- str stage_id,
- str mode,
- bool run_ignored,
- str opt_filter,
- str opt_runtool,
- str opt_rustcflags,
- bool verbose,
- procsrv::reqchan procsrv_chan,
- str testfile) {
+fn run_test_task(compile_lib_path: str, run_lib_path: str, rustc_path: str,
+ src_base: str, build_base: str, stage_id: str, mode: str,
+ run_ignored: bool, opt_filter: str, opt_runtool: str,
+ opt_rustcflags: str, verbose: bool,
+ procsrv_chan: procsrv::reqchan, testfile: str) {
- auto config = rec(compile_lib_path = compile_lib_path,
- run_lib_path = run_lib_path,
- rustc_path = rustc_path,
- src_base = src_base,
- build_base = build_base,
- stage_id = stage_id,
- mode = str_mode(mode),
- run_ignored = run_ignored,
- filter = str_opt(opt_filter),
- runtool = str_opt(opt_runtool),
- rustcflags = str_opt(opt_rustcflags),
- verbose = verbose);
+ let config =
+ {compile_lib_path: compile_lib_path,
+ run_lib_path: run_lib_path,
+ rustc_path: rustc_path,
+ src_base: src_base,
+ build_base: build_base,
+ stage_id: stage_id,
+ mode: str_mode(mode),
+ run_ignored: run_ignored,
+ filter: str_opt(opt_filter),
+ runtool: str_opt(opt_runtool),
+ rustcflags: str_opt(opt_rustcflags),
+ verbose: verbose};
- auto procsrv = procsrv::from_chan(procsrv_chan);
+ let procsrv = procsrv::from_chan(procsrv_chan);
- auto cx = rec(config = config,
- procsrv = procsrv);
+ let cx = {config: config, procsrv: procsrv};
log #fmt("running %s", testfile);
task::unsupervise();
- auto props = load_props(testfile);
- alt (cx.config.mode) {
- mode_compile_fail {
- run_cfail_test(cx, props, testfile);
- }
- mode_run_fail {
- run_rfail_test(cx, props, testfile);
- }
- mode_run_pass {
- run_rpass_test(cx, props, testfile);
- }
+ let props = load_props(testfile);
+ alt cx.config.mode {
+ mode_compile_fail. { run_cfail_test(cx, props, testfile); }
+ mode_run_fail. { run_rfail_test(cx, props, testfile); }
+ mode_run_pass. { run_rpass_test(cx, props, testfile); }
}
}
-type test_props = rec(str[] error_patterns,
- option::t[str] compile_flags);
+type test_props = {error_patterns: str[], compile_flags: option::t[str]};
// Load any test directives embedded in the file
-fn load_props(&str testfile) -> test_props {
- auto error_patterns = ~[];
- auto compile_flags = option::none;
- for each (str ln in iter_header(testfile)) {
+fn load_props(testfile: &str) -> test_props {
+ let error_patterns = ~[];
+ let compile_flags = option::none;
+ for each ln: str in iter_header(testfile) {
alt parse_error_pattern(ln) {
- option::some(?ep) { error_patterns += ~[ep]; }
- option::none { }
+ option::some(ep) { error_patterns += ~[ep]; }
+ option::none. { }
}
+
if option::is_none(compile_flags) {
compile_flags = parse_compile_flags(ln);
}
}
- ret rec(error_patterns = error_patterns,
- compile_flags = compile_flags);
+ ret {error_patterns: error_patterns, compile_flags: compile_flags};
}
-fn parse_error_pattern(&str line) -> option::t[str] {
+fn parse_error_pattern(line: &str) -> option::t[str] {
parse_name_value_directive(line, "error-pattern")
}
-fn parse_compile_flags(&str line) -> option::t[str] {
+fn parse_compile_flags(line: &str) -> option::t[str] {
parse_name_value_directive(line, "compile-flags")
}
-fn parse_name_directive(&str line, &str directive) -> bool {
+fn parse_name_directive(line: &str, directive: &str) -> bool {
str::find(line, directive) >= 0
}
-fn parse_name_value_directive(&str line, &str directive) -> option::t[str] {
- auto keycolon = directive + ":";
+fn parse_name_value_directive(line: &str, directive: &str) -> option::t[str] {
+ let keycolon = directive + ":";
if str::find(line, keycolon) >= 0 {
- auto colon = str::find(line, keycolon) as uint;
- auto value = str::slice(line,
- colon + str::byte_len(keycolon),
- str::byte_len(line));
+ let colon = str::find(line, keycolon) as uint;
+ let value =
+ str::slice(line, colon + str::byte_len(keycolon),
+ str::byte_len(line));
log #fmt("%s: %s", directive, value);
option::some(value)
- } else {
- option::none
- }
+ } else { option::none }
}
-fn run_cfail_test(&cx cx, &test_props props, &str testfile) {
- auto procres = compile_test(cx, props, testfile);
+fn run_cfail_test(cx: &cx, props: &test_props, testfile: &str) {
+ let procres = compile_test(cx, props, testfile);
- if (procres.status == 0) {
+ if procres.status == 0 {
fatal_procres("compile-fail test compiled successfully!", procres);
}
check_error_patterns(props, testfile, procres);
}
-fn run_rfail_test(&cx cx, &test_props props, &str testfile) {
- auto procres = compile_test(cx, props, testfile);
+fn run_rfail_test(cx: &cx, props: &test_props, testfile: &str) {
+ let procres = compile_test(cx, props, testfile);
- if (procres.status != 0) {
- fatal_procres("compilation failed!", procres);
- }
+ if procres.status != 0 { fatal_procres("compilation failed!", procres); }
procres = exec_compiled_test(cx, testfile);
- if (procres.status == 0) {
- fatal_procres("run-fail test didn't produce an error!",
- procres);
+ if procres.status == 0 {
+ fatal_procres("run-fail test didn't produce an error!", procres);
}
check_error_patterns(props, testfile, procres);
}
-fn run_rpass_test(&cx cx, &test_props props, &str testfile) {
- auto procres = compile_test(cx, props, testfile);
+fn run_rpass_test(cx: &cx, props: &test_props, testfile: &str) {
+ let procres = compile_test(cx, props, testfile);
- if (procres.status != 0) {
- fatal_procres("compilation failed!", procres);
- }
+ if procres.status != 0 { fatal_procres("compilation failed!", procres); }
procres = exec_compiled_test(cx, testfile);
- if (procres.status != 0) {
- fatal_procres("test run failed!", procres);
- }
+
+ if procres.status != 0 { fatal_procres("test run failed!", procres); }
}
-fn check_error_patterns(&test_props props, &str testfile,
- &procres procres) {
+fn check_error_patterns(props: &test_props, testfile: &str,
+ procres: &procres) {
if ivec::is_empty(props.error_patterns) {
fatal("no error pattern specified in " + testfile);
}
- auto next_err_idx = 0u;
- auto next_err_pat = props.error_patterns.(next_err_idx);
- for (str line in str::split(procres.out, '\n' as u8)) {
- if (str::find(line, next_err_pat) > 0) {
+ let next_err_idx = 0u;
+ let next_err_pat = props.error_patterns.(next_err_idx);
+ for line: str in str::split(procres.out, '\n' as u8) {
+ if str::find(line, next_err_pat) > 0 {
log #fmt("found error pattern %s", next_err_pat);
next_err_idx += 1u;
if next_err_idx == ivec::len(props.error_patterns) {
@@ -435,108 +378,95 @@
}
}
- auto missing_patterns = ivec::slice(props.error_patterns,
- next_err_idx,
- ivec::len(props.error_patterns));
- if (ivec::len(missing_patterns) == 1u) {
+ let missing_patterns =
+ ivec::slice(props.error_patterns, next_err_idx,
+ ivec::len(props.error_patterns));
+ if ivec::len(missing_patterns) == 1u {
fatal_procres(#fmt("error pattern '%s' not found!",
- missing_patterns.(0)),
- procres);
+ missing_patterns.(0)), procres);
} else {
- for (str pattern in missing_patterns) {
+ for pattern: str in missing_patterns {
error(#fmt("error pattern '%s' not found!", pattern));
}
fatal_procres("multiple error patterns not found", procres);
}
}
-type procargs = rec(str prog, vec[str] args);
+type procargs = {prog: str, args: vec[str]};
-type procres = rec(int status, str out, str cmdline);
+type procres = {status: int, out: str, cmdline: str};
-fn compile_test(&cx cx, &test_props props,
- &str testfile) -> procres {
- compose_and_run(cx,
- testfile,
- bind make_compile_args(_, props, _),
+fn compile_test(cx: &cx, props: &test_props, testfile: &str) -> procres {
+ compose_and_run(cx, testfile, bind make_compile_args(_, props, _),
cx.config.compile_lib_path)
}
-fn exec_compiled_test(&cx cx, &str testfile) -> procres {
- compose_and_run(cx,
- testfile,
- make_run_args,
- cx.config.run_lib_path)
+fn exec_compiled_test(cx: &cx, testfile: &str) -> procres {
+ compose_and_run(cx, testfile, make_run_args, cx.config.run_lib_path)
}
-fn compose_and_run(&cx cx, &str testfile,
- fn(&config, &str) -> procargs make_args,
- &str lib_path) -> procres {
- auto procargs = make_args(cx.config, testfile);
- ret program_output(cx, testfile, lib_path,
- procargs.prog, procargs.args);
+fn compose_and_run(cx: &cx, testfile: &str,
+ make_args: fn(&config, &str) -> procargs , lib_path: &str)
+ -> procres {
+ let procargs = make_args(cx.config, testfile);
+ ret program_output(cx, testfile, lib_path, procargs.prog, procargs.args);
}
-fn make_compile_args(&config config, &test_props props,
- &str testfile) -> procargs {
- auto prog = config.rustc_path;
- auto args = [testfile,
- "-o", make_exe_name(config, testfile)];
+fn make_compile_args(config: &config, props: &test_props, testfile: &str) ->
+ procargs {
+ let prog = config.rustc_path;
+ let args = [testfile, "-o", make_exe_name(config, testfile)];
args += split_maybe_args(config.rustcflags);
args += split_maybe_args(props.compile_flags);
- ret rec(prog = prog,
- args = args);
+ ret {prog: prog, args: args};
}
-fn make_run_args(&config config, &str testfile) -> procargs {
+fn make_run_args(config: &config, testfile: &str) -> procargs {
// If we've got another tool to run under (valgrind),
// then split apart its command
- auto args = split_maybe_args(config.runtool)
- + [make_exe_name(config, testfile)];
- ret rec(prog = args.(0),
- args = vec::slice(args, 1u, vec::len(args)));
+ let args =
+ split_maybe_args(config.runtool) + [make_exe_name(config, testfile)];
+ ret {prog: args.(0), args: vec::slice(args, 1u, vec::len(args))};
}
-fn split_maybe_args(&option::t[str] argstr) -> vec[str] {
- alt (argstr) {
- option::some(?s) { str::split(s, ' ' as u8) }
- option::none { [] }
+fn split_maybe_args(argstr: &option::t[str]) -> vec[str] {
+ alt argstr {
+ option::some(s) { str::split(s, ' ' as u8) }
+ option::none. { [] }
}
}
-fn program_output(&cx cx, &str testfile,
- &str lib_path, &str prog, &vec[str] args) -> procres {
- auto cmdline = {
- auto cmdline = make_cmdline(lib_path, prog, args);
- logv(cx.config, #fmt("running %s", cmdline));
- cmdline
- };
- auto res = procsrv::run(cx.procsrv, lib_path, prog, args);
+fn program_output(cx: &cx, testfile: &str, lib_path: &str, prog: &str,
+ args: &vec[str]) -> procres {
+ let cmdline =
+ {
+ let cmdline = make_cmdline(lib_path, prog, args);
+ logv(cx.config, #fmt("running %s", cmdline));
+ cmdline
+ };
+ let res = procsrv::run(cx.procsrv, lib_path, prog, args);
dump_output(cx.config, testfile, res.out);
- ret rec(status = res.status,
- out = res.out,
- cmdline = cmdline);
+ ret {status: res.status, out: res.out, cmdline: cmdline};
}
-fn make_cmdline(&str libpath, &str prog, &vec[str] args) -> str {
- #fmt("%s %s %s",
- lib_path_cmd_prefix(libpath),
- prog,
+fn make_cmdline(libpath: &str, prog: &str, args: &vec[str]) -> str {
+ #fmt("%s %s %s", lib_path_cmd_prefix(libpath), prog,
str::connect(args, " "))
}
// Build the LD_LIBRARY_PATH variable as it would be seen on the command line
// for diagnostic purposes
-fn lib_path_cmd_prefix(&str path) -> str {
+fn lib_path_cmd_prefix(path: &str) -> str {
#fmt("%s=\"%s\"", lib_path_env_var(), make_new_path(path))
}
-fn make_new_path(&str path) -> str {
+fn make_new_path(path: &str) -> str {
+
// Windows just uses PATH as the library search path, so we have to
// maintain the current value while adding our own
alt getenv(lib_path_env_var()) {
- option::some(?curr) { #fmt("%s:%s", path, curr) }
- option::none { path }
+ option::some(curr) { #fmt("%s:%s", path, curr) }
+ option::none. { path }
}
}
@@ -549,58 +479,55 @@
#[cfg(target_os = "win32")]
fn lib_path_env_var() -> str { "PATH" }
-fn make_exe_name(&config config, &str testfile) -> str {
+fn make_exe_name(config: &config, testfile: &str) -> str {
output_base_name(config, testfile) + os::exec_suffix()
}
-fn output_base_name(&config config, &str testfile) -> str {
- auto base = config.build_base;
- auto filename = {
- auto parts = str::split(fs::basename(testfile), '.' as u8);
- parts = vec::slice(parts, 0u, vec::len(parts) - 1u);
- str::connect(parts, ".")
- };
+fn output_base_name(config: &config, testfile: &str) -> str {
+ let base = config.build_base;
+ let filename =
+ {
+ let parts = str::split(fs::basename(testfile), '.' as u8);
+ parts = vec::slice(parts, 0u, vec::len(parts) - 1u);
+ str::connect(parts, ".")
+ };
#fmt("%s%s.%s", base, filename, config.stage_id)
}
#[cfg(target_os = "win32")]
#[cfg(target_os = "linux")]
-fn dump_output(&config config, &str testfile, &str out) {
- auto outfile = make_out_name(config, testfile);
- auto writer = io::file_writer(outfile, [io::create, io::truncate]);
+fn dump_output(config: &config, testfile: &str, out: &str) {
+ let outfile = make_out_name(config, testfile);
+ let writer = io::file_writer(outfile, [io::create, io::truncate]);
writer.write_str(out);
maybe_dump_to_stdout(config, out);
}
// FIXME (726): Can't use file_writer on mac
#[cfg(target_os = "macos")]
-fn dump_output(&config config, &str testfile, &str out) {
+fn dump_output(config: &config, testfile: &str, out: &str) {
maybe_dump_to_stdout(config, out);
}
-fn maybe_dump_to_stdout(&config config, &str out) {
- if (config.verbose) {
+fn maybe_dump_to_stdout(config: &config, out: &str) {
+ if config.verbose {
io::stdout().write_line("------------------------------------------");
io::stdout().write_line(out);
io::stdout().write_line("------------------------------------------");
}
}
-fn make_out_name(&config config, &str testfile) -> str {
+fn make_out_name(config: &config, testfile: &str) -> str {
output_base_name(config, testfile) + ".out"
}
-fn error(&str err) {
- io::stdout().write_line(#fmt("\nerror: %s", err));
-}
+fn error(err: &str) { io::stdout().write_line(#fmt("\nerror: %s", err)); }
-fn fatal(&str err) -> ! {
- error(err);
- fail;
-}
+fn fatal(err: &str) -> ! { error(err); fail; }
-fn fatal_procres(&str err, procres procres) -> ! {
- auto msg = #fmt("\n\
+fn fatal_procres(err: &str, procres: procres) -> ! {
+ let msg =
+ #fmt("\n\
error: %s\n\
command: %s\n\
output:\n\
@@ -608,16 +535,14 @@
%s\n\
------------------------------------------\n\
\n",
- err, procres.cmdline, procres.out);
+ err, procres.cmdline, procres.out);
io::stdout().write_str(msg);
fail;
}
-fn logv(&config config, &str s) {
+fn logv(config: &config, s: &str) {
log s;
- if (config.verbose) {
- io::stdout().write_line(s);
- }
+ if config.verbose { io::stdout().write_line(s); }
}
@@ -638,87 +563,76 @@
type reqchan = chan[request];
- type handle = rec(option::t[task] task,
- reqchan chan);
+ type handle = {task: option::t[task], chan: reqchan};
- tag request {
- exec(str, str, vec[str], chan[response]);
- stop;
- }
+ tag request { exec(str, str, vec[str], chan[response]); stop; }
- type response = rec(int pid, int outfd);
+ type response = {pid: int, outfd: int};
fn mk() -> handle {
- auto res = task::worker(worker);
- ret rec(task = option::some(res.task),
- chan = res.chan);
+ let res = task::worker(worker);
+ ret {task: option::some(res.task), chan: res.chan};
}
- fn from_chan(&reqchan ch) -> handle {
- rec(task = option::none,
- chan = ch)
- }
+ fn from_chan(ch: &reqchan) -> handle { {task: option::none, chan: ch} }
- fn clone(&handle handle) -> handle {
+ fn clone(handle: &handle) -> handle {
+
// Sharing tasks across tasks appears to be (yet another) recipe for
// disaster, so our handle clones will not get the task pointer.
- rec(task = option::none,
- chan = task::clone_chan(handle.chan))
+ {task: option::none, chan: task::clone_chan(handle.chan)}
}
- fn close(&handle handle) {
+ fn close(handle: &handle) {
task::send(handle.chan, stop);
task::join(option::get(handle.task));
}
- fn run(&handle handle, &str lib_path,
- &str prog, &vec[str] args) -> rec(int status, str out) {
- auto p = port[response]();
- auto ch = chan(p);
- task::send(handle.chan,
- exec(lib_path, prog, args, ch));
+ fn run(handle: &handle, lib_path: &str, prog: &str, args: &vec[str]) ->
+ {status: int, out: str} {
+ let p = port[response]();
+ let ch = chan(p);
+ task::send(handle.chan, exec(lib_path, prog, args, ch));
- auto resp = task::recv(p);
+ let resp = task::recv(p);
// Copied from run::program_output
- auto outfile = os::fd_FILE(resp.outfd);
- auto reader = io::new_reader(io::FILE_buf_reader(outfile, false));
- auto buf = "";
- while (!reader.eof()) {
- auto bytes = reader.read_bytes(4096u);
+ let outfile = os::fd_FILE(resp.outfd);
+ let reader = io::new_reader(io::FILE_buf_reader(outfile, false));
+ let buf = "";
+ while !reader.eof() {
+ let bytes = reader.read_bytes(4096u);
buf += str::unsafe_from_bytes(bytes);
}
os::libc::fclose(outfile);
- ret rec(status = os::waitpid(resp.pid), out = buf);
+ ret {status: os::waitpid(resp.pid), out: buf};
}
- fn worker(port[request] p) {
- while (true) {
+ fn worker(p: port[request]) {
+ while true {
alt task::recv(p) {
- exec(?lib_path, ?prog, ?args, ?respchan) {
+ exec(lib_path, prog, args, respchan) {
// This is copied from run::start_program
- auto pipe_in = os::pipe();
- auto pipe_out = os::pipe();
- auto spawnproc = bind run::spawn_process(
- prog, args, pipe_in.in, pipe_out.out, 0);
- auto pid = with_lib_path(lib_path, spawnproc);
- if (pid == -1) { fail; }
+ let pipe_in = os::pipe();
+ let pipe_out = os::pipe();
+ let spawnproc =
+ bind run::spawn_process(prog, args, pipe_in.in,
+ pipe_out.out, 0);
+ let pid = with_lib_path(lib_path, spawnproc);
+ if pid == -1 { fail; }
os::libc::close(pipe_in.in);
os::libc::close(pipe_in.out);
os::libc::close(pipe_out.out);
- task::send(respchan, rec(pid = pid,
- outfd = pipe_out.in));
+ task::send(respchan, {pid: pid, outfd: pipe_out.in});
}
- stop {
- ret;
- }
+ stop. { ret; }
}
}
}
- fn with_lib_path[T](&str path, fn() -> T f) -> T {
- auto maybe_oldpath = getenv(lib_path_env_var());
+ fn with_lib_path[T](path: &str, f: fn() -> T ) -> T {
+ let maybe_oldpath = getenv(lib_path_env_var());
append_lib_path(path);
- auto res = f();
+ let res = f();
if option::is_some(maybe_oldpath) {
export_lib_path(option::get(maybe_oldpath));
} else {
@@ -728,13 +642,9 @@
ret res;
}
- fn append_lib_path(&str path) {
- export_lib_path(make_new_path(path));
- }
+ fn append_lib_path(path: &str) { export_lib_path(make_new_path(path)); }
- fn export_lib_path(&str path) {
- setenv(lib_path_env_var(), path);
- }
+ fn export_lib_path(path: &str) { setenv(lib_path_env_var(), path); }
}
// Local Variables:
diff --git a/src/test/run-fail/alt-bot-fail.rs b/src/test/run-fail/alt-bot-fail.rs
index 39b2a36..087f6db 100644
--- a/src/test/run-fail/alt-bot-fail.rs
+++ b/src/test/run-fail/alt-bot-fail.rs
@@ -4,13 +4,9 @@
use std;
import std::option::*;
-fn foo(str s) { }
+fn foo(s: str) { }
fn main() {
- auto i =
- alt (some[int](3)) {
- case (none[int]) { fail }
- case (some[int](_)) { fail }
- };
+ let i = alt some[int](3) { none[int]. { fail } some[int](_) { fail } };
foo(i);
}
\ No newline at end of file
diff --git a/src/test/run-fail/args-fail.rs b/src/test/run-fail/args-fail.rs
index 07f47e0..d57938b 100644
--- a/src/test/run-fail/args-fail.rs
+++ b/src/test/run-fail/args-fail.rs
@@ -1,9 +1,5 @@
// xfail-stage0
// error-pattern:meep
-fn f(int a, int b, @int c) {
- fail "moop";
-}
+fn f(a: int, b: int, c: @int) { fail "moop"; }
-fn main() {
- f(1, fail "meep", @42);
-}
\ No newline at end of file
+fn main() { f(1, fail "meep", @42); }
\ No newline at end of file
diff --git a/src/test/run-fail/explicit-fail-msg.rs b/src/test/run-fail/explicit-fail-msg.rs
index 7932602..a200bcd 100644
--- a/src/test/run-fail/explicit-fail-msg.rs
+++ b/src/test/run-fail/explicit-fail-msg.rs
@@ -1,10 +1,4 @@
// error-pattern:wooooo
-fn main() {
- auto a = 1;
- if (1 == 1) {
- a = 2;
- }
- fail "woooo" + "o";
-}
\ No newline at end of file
+fn main() { let a = 1; if 1 == 1 { a = 2; } fail "woooo" + "o"; }
\ No newline at end of file
diff --git a/src/test/run-fail/expr-alt-fail-fn.rs b/src/test/run-fail/expr-alt-fail-fn.rs
index f3bd1a5..e975464 100644
--- a/src/test/run-fail/expr-alt-fail-fn.rs
+++ b/src/test/run-fail/expr-alt-fail-fn.rs
@@ -4,9 +4,6 @@
// error-pattern:explicit failure
fn f() -> ! { fail }
-fn g() -> int {
- auto x = alt (true) { case (true) { f() } case (false) { 10 } };
- ret x;
-}
+fn g() -> int { let x = alt true { true { f() } false { 10 } }; ret x; }
fn main() { g(); }
\ No newline at end of file
diff --git a/src/test/run-fail/expr-alt-fail.rs b/src/test/run-fail/expr-alt-fail.rs
index 1b653d8..5015489 100644
--- a/src/test/run-fail/expr-alt-fail.rs
+++ b/src/test/run-fail/expr-alt-fail.rs
@@ -2,4 +2,4 @@
// error-pattern:explicit failure
-fn main() { auto x = alt (true) { case (false) { 0 } case (true) { fail } }; }
\ No newline at end of file
+fn main() { let x = alt true { false { 0 } true { fail } }; }
\ No newline at end of file
diff --git a/src/test/run-fail/expr-if-fail-fn.rs b/src/test/run-fail/expr-if-fail-fn.rs
index 2e4d0cb..6b7b6d64 100644
--- a/src/test/run-fail/expr-if-fail-fn.rs
+++ b/src/test/run-fail/expr-if-fail-fn.rs
@@ -4,6 +4,6 @@
// error-pattern:explicit failure
fn f() -> ! { fail }
-fn g() -> int { auto x = if (true) { f() } else { 10 }; ret x; }
+fn g() -> int { let x = if true { f() } else { 10 }; ret x; }
fn main() { g(); }
\ No newline at end of file
diff --git a/src/test/run-fail/expr-if-fail.rs b/src/test/run-fail/expr-if-fail.rs
index a12b755..a738bfc 100644
--- a/src/test/run-fail/expr-if-fail.rs
+++ b/src/test/run-fail/expr-if-fail.rs
@@ -2,4 +2,4 @@
// error-pattern:explicit failure
-fn main() { auto x = if (false) { 0 } else if (true) { fail } else { 10 }; }
\ No newline at end of file
+fn main() { let x = if false { 0 } else if (true) { fail } else { 10 }; }
\ No newline at end of file
diff --git a/src/test/run-fail/fail-arg.rs b/src/test/run-fail/fail-arg.rs
index 22027f7..e82d729 100644
--- a/src/test/run-fail/fail-arg.rs
+++ b/src/test/run-fail/fail-arg.rs
@@ -1,9 +1,5 @@
// xfail-stage0
// error-pattern:woe
-fn f(int a) {
- log a;
-}
+fn f(a: int) { log a; }
-fn main() {
- f(fail "woe");
-}
+fn main() { f(fail "woe"); }
\ No newline at end of file
diff --git a/src/test/run-fail/fail-main.rs b/src/test/run-fail/fail-main.rs
index c4ec90b..d627640 100644
--- a/src/test/run-fail/fail-main.rs
+++ b/src/test/run-fail/fail-main.rs
@@ -2,6 +2,4 @@
// error-pattern:moop
use std;
import std::uint;
-fn main() {
- fail "moop";
-}
+fn main() { fail "moop"; }
\ No newline at end of file
diff --git a/src/test/run-fail/fmt-fail.rs b/src/test/run-fail/fmt-fail.rs
index 2b8a39f..029946e 100644
--- a/src/test/run-fail/fmt-fail.rs
+++ b/src/test/run-fail/fmt-fail.rs
@@ -3,7 +3,4 @@
use std;
import std::str;
-fn main() {
- let str str_var = "meh";
- fail #fmt("%s", str_var);
-}
\ No newline at end of file
+fn main() { let str_var: str = "meh"; fail #fmt("%s", str_var); }
\ No newline at end of file
diff --git a/src/test/run-fail/fn-constraint-claim.rs b/src/test/run-fail/fn-constraint-claim.rs
index 2608f15..ecf1ca5 100644
--- a/src/test/run-fail/fn-constraint-claim.rs
+++ b/src/test/run-fail/fn-constraint-claim.rs
@@ -5,13 +5,6 @@
import std::str::*;
import std::uint::*;
-fn nop(uint a, uint b) : le(a, b) {
- fail "quux";
-}
+fn nop(a: uint, b: uint) { fail "quux"; }
-fn main() {
- let uint a = 5u;
- let uint b = 4u;
- claim le(a, b);
- nop(a, b);
-}
\ No newline at end of file
+fn main() { let a: uint = 5u; let b: uint = 4u; claim (le(a, b)); nop(a, b); }
\ No newline at end of file
diff --git a/src/test/run-fail/fn-constraint.rs b/src/test/run-fail/fn-constraint.rs
index 3f79334..65bcc41 100644
--- a/src/test/run-fail/fn-constraint.rs
+++ b/src/test/run-fail/fn-constraint.rs
@@ -4,8 +4,8 @@
import std::uint::le;
fn main() {
- let uint a = 4u;
- let uint b = 1u;
- check le(a, b);
- log_err (safe_slice("kitties", a, b));
+ let a: uint = 4u;
+ let b: uint = 1u;
+ check (le(a, b));
+ log_err safe_slice("kitties", a, b);
}
\ No newline at end of file
diff --git a/src/test/run-fail/for-each-loop-fail.rs b/src/test/run-fail/for-each-loop-fail.rs
index 382fe3e..126e1cc 100644
--- a/src/test/run-fail/for-each-loop-fail.rs
+++ b/src/test/run-fail/for-each-loop-fail.rs
@@ -2,8 +2,4 @@
// error-pattern:moop
use std;
import std::uint;
-fn main() {
- for each (uint i in uint::range(0u, 10u)) {
- fail "moop";
- }
-}
+fn main() { for each i: uint in uint::range(0u, 10u) { fail "moop"; } }
\ No newline at end of file
diff --git a/src/test/run-fail/if-check-fail.rs b/src/test/run-fail/if-check-fail.rs
index 2c77bc8..7a1aa25 100644
--- a/src/test/run-fail/if-check-fail.rs
+++ b/src/test/run-fail/if-check-fail.rs
@@ -1,26 +1,11 @@
// xfail-stage0
// error-pattern:Number is odd
-pred even(uint x) -> bool {
- if (x < 2u) {
- ret false;
- }
- else if (x == 2u) {
- ret true;
- }
- else {
- ret even(x - 2u);
- }
+pred even(x: uint) -> bool {
+ if x < 2u {
+ ret false;
+ } else if (x == 2u) { ret true; } else { ret even(x - 2u); }
}
-fn foo(uint x) -> () {
- if check(even(x)) {
- log x;
- }
- else {
- fail "Number is odd";
- }
-}
+fn foo(x: uint) { if check even(x) { log x; } else { fail "Number is odd"; } }
-fn main() {
- foo(3u);
-}
+fn main() { foo(3u); }
\ No newline at end of file
diff --git a/src/test/run-fail/linked-failure.rs b/src/test/run-fail/linked-failure.rs
index f2f880e..bdf561c 100644
--- a/src/test/run-fail/linked-failure.rs
+++ b/src/test/run-fail/linked-failure.rs
@@ -2,13 +2,6 @@
// error-pattern:1 == 2
-fn child() {
- assert (1 == 2);
-}
+fn child() { assert (1 == 2); }
-fn main() {
- let port[int] p = port();
- spawn child();
- let int x;
- p |> x;
-}
+fn main() { let p: port[int] = port(); spawn child(); let x: int; p |> x; }
\ No newline at end of file
diff --git a/src/test/run-fail/non-exhaustive-match.rs b/src/test/run-fail/non-exhaustive-match.rs
index a1a70db..e62d069 100644
--- a/src/test/run-fail/non-exhaustive-match.rs
+++ b/src/test/run-fail/non-exhaustive-match.rs
@@ -6,4 +6,4 @@
// error-pattern:non-exhaustive match failure
tag t { a; b; }
-fn main() { auto x = a; alt (x) { case (b) { } } }
\ No newline at end of file
+fn main() { let x = a; alt x { b. { } } }
\ No newline at end of file
diff --git a/src/test/run-fail/port-type.rs b/src/test/run-fail/port-type.rs
index 6f962a7..b5cd359 100644
--- a/src/test/run-fail/port-type.rs
+++ b/src/test/run-fail/port-type.rs
@@ -1,16 +1,14 @@
// xfail-stage0
// error-pattern:meep
-fn echo[T](chan[T] c, chan[chan[T]] oc) {
- // Tests that the type argument in port gets
- // visited
- auto p = port[T]();
- oc <| chan(p);
+fn echo[T](c: chan[T], oc: chan[chan[T]]) {
+ // Tests that the type argument in port gets
+ // visited
+ let p = port[T]();
+ oc <| chan(p);
- auto x;
- p |> x;
- c <| x;
+ let x;
+ p |> x;
+ c <| x;
}
-fn main() {
- fail "meep";
-}
\ No newline at end of file
+fn main() { fail "meep"; }
\ No newline at end of file
diff --git a/src/test/run-fail/pred.rs b/src/test/run-fail/pred.rs
index ac63209..e67529c 100644
--- a/src/test/run-fail/pred.rs
+++ b/src/test/run-fail/pred.rs
@@ -4,8 +4,8 @@
// -*- rust -*-
// xfail-stage0
// error-pattern:Predicate lt(b, a) failed
-fn f(int a, int b) { }
+fn f(a: int, b: int) { }
-pred lt(int a, int b) -> bool { ret a < b; }
+pred lt(a: int, b: int) -> bool { ret a < b; }
-fn main() { let int a = 10; let int b = 23; check (lt(b, a)); f(b, a); }
\ No newline at end of file
+fn main() { let a: int = 10; let b: int = 23; check (lt(b, a)); f(b, a); }
\ No newline at end of file
diff --git a/src/test/run-fail/rhs-type.rs b/src/test/run-fail/rhs-type.rs
index 9947ec7..fc76711 100644
--- a/src/test/run-fail/rhs-type.rs
+++ b/src/test/run-fail/rhs-type.rs
@@ -5,4 +5,4 @@
// as a _|_-typed thing, not a str-typed thing
// xfail-stage0
// error-pattern:bye
-fn main() { auto pth = fail"bye"; let rec(str t) rs = rec(t=pth); }
\ No newline at end of file
+fn main() { let pth = fail "bye"; let rs: {t: str} = {t: pth}; }
\ No newline at end of file
diff --git a/src/test/run-fail/str-overrun.rs b/src/test/run-fail/str-overrun.rs
index 96d0f21..1ac862f 100644
--- a/src/test/run-fail/str-overrun.rs
+++ b/src/test/run-fail/str-overrun.rs
@@ -5,8 +5,8 @@
// error-pattern:bounds check
fn main() {
- let str s = "hello";
- let int x = 0;
+ let s: str = "hello";
+ let x: int = 0;
assert (s.(x) == 0x68 as u8);
// NB: at the moment a string always has a trailing NULL,
// so the largest index value on the string above is 5, not
diff --git a/src/test/run-fail/task-comm-14.rs b/src/test/run-fail/task-comm-14.rs
index c1e6b73..c46d8b1 100644
--- a/src/test/run-fail/task-comm-14.rs
+++ b/src/test/run-fail/task-comm-14.rs
@@ -1,33 +1,6 @@
-// xfail-stage0
-// xfail-stage1
-// xfail-stage2
-// xfail-stage3
-io fn main() {
- let port[int] po = port();
-
- // Spawn 10 tasks each sending us back one int.
- let int i = 10;
- while (i > 0) {
- log i;
- spawn "child" child(i, chan(po));
- i = i - 1;
- }
-
- // Spawned tasks are likely killed before they get a chance to send
- // anything back, so we deadlock here.
-
- i = 10;
- let int value = 0;
- while (i > 0) {
- log i;
- po |> value;
- i = i - 1;
- }
-
- log "main thread exiting";
-}
-
-io fn child(int x, chan[int] ch) {
- log x;
- ch <| x;
-}
+./src/test/run-fail/task-comm-14.rs:5:0:5:2: [1;31merror:[0m expected item but found io
+./src/test/run-fail/task-comm-14.rs:5 io fn main() {
+ ^~
+rt: ---
+rt: 0bb1:main:main: upcall fail 'explicit failure', src/comp/syntax/parse/parser.rs:112
+rt: 0bb1:main: domain main @0x919b04c root task failed
diff --git a/src/test/run-fail/trivial-message2.rs b/src/test/run-fail/trivial-message2.rs
index 5d1f54a..8d3681b 100644
--- a/src/test/run-fail/trivial-message2.rs
+++ b/src/test/run-fail/trivial-message2.rs
@@ -10,9 +10,9 @@
This program should hang on the po |> r line.
*/
fn main() {
- let port[int] po = port();
- let chan[int] ch = chan(po);
- auto r;
+ let po: port[int] = port();
+ let ch: chan[int] = chan(po);
+ let r;
po |> r;
ch <| 42;
log_err r;
diff --git a/src/test/run-fail/vec-overrun.rs b/src/test/run-fail/vec-overrun.rs
index f0318de..f0ec8f2 100644
--- a/src/test/run-fail/vec-overrun.rs
+++ b/src/test/run-fail/vec-overrun.rs
@@ -5,8 +5,8 @@
// error-pattern:bounds check
fn main() {
- let vec[int] v = [10];
- let int x = 0;
+ let v: vec[int] = [10];
+ let x: int = 0;
assert (v.(x) == 10);
// Bounds-check failure.
diff --git a/src/test/run-fail/vec-underrun.rs b/src/test/run-fail/vec-underrun.rs
index b645ea1..5bc224b 100644
--- a/src/test/run-fail/vec-underrun.rs
+++ b/src/test/run-fail/vec-underrun.rs
@@ -5,8 +5,8 @@
// error-pattern:bounds check
fn main() {
- let vec[int] v = [10, 20];
- let int x = 0;
+ let v: vec[int] = [10, 20];
+ let x: int = 0;
assert (v.(x) == 10);
// Bounds-check failure.
diff --git a/src/test/run-pass/acyclic-unwind.rs b/src/test/run-pass/acyclic-unwind.rs
index c2f718f..66f430c 100644
--- a/src/test/run-pass/acyclic-unwind.rs
+++ b/src/test/run-pass/acyclic-unwind.rs
@@ -4,35 +4,36 @@
// xfail-stage3
// -*- rust -*-
-fn f(chan[int] c) {
- type t = rec(int _0, int _1, int _2);
+fn f(c: chan[int]) {
+ type t = {_0: int, _1: int, _2: int};
- // Allocate a box.
- let @t x = @rec(_0=1, _1=2, _2=3);
+ // Allocate a box.
+ let x: @t = @{_0: 1, _1: 2, _2: 3};
- // Signal parent that we've allocated a box.
- c <| 1;
-
- while (true) {
- // spin waiting for the parent to kill us.
- log "child waiting to die...";
-
- // while waiting to die, the messages we are
- // sending to the channel are never received
- // by the parent, therefore this test cases drops
- // messages on the floor
+ // Signal parent that we've allocated a box.
c <| 1;
- }
+
+
+ while true {
+ // spin waiting for the parent to kill us.
+ log "child waiting to die...";
+
+ // while waiting to die, the messages we are
+ // sending to the channel are never received
+ // by the parent, therefore this test cases drops
+ // messages on the floor
+ c <| 1;
+ }
}
fn main() {
- let port[int] p = port();
- spawn f(chan(p));
- let int i;
+ let p: port[int] = port();
+ spawn f(chan(p));
+ let i: int;
- // synchronize on event from child.
- p |> i;
+ // synchronize on event from child.
+ p |> i;
- log "parent exiting, killing child";
-}
+ log "parent exiting, killing child";
+}
\ No newline at end of file
diff --git a/src/test/run-pass/alias-uninit-value.rs b/src/test/run-pass/alias-uninit-value.rs
index 4d96545..564217b 100644
--- a/src/test/run-pass/alias-uninit-value.rs
+++ b/src/test/run-pass/alias-uninit-value.rs
@@ -7,10 +7,10 @@
tag sty { ty_nil; }
-type raw_t = rec(sty struct, option::t[str] cname, uint hash);
+type raw_t = {struct: sty, cname: option::t[str], hash: uint};
-fn mk_raw_ty(sty st, &option::t[str] cname) -> raw_t {
- ret rec(struct=st, cname=cname, hash=0u);
+fn mk_raw_ty(st: sty, cname: &option::t[str]) -> raw_t {
+ ret {struct: st, cname: cname, hash: 0u};
}
fn main() { mk_raw_ty(ty_nil, none[str]); }
\ No newline at end of file
diff --git a/src/test/run-pass/alloca-from-derived-tydesc.rs b/src/test/run-pass/alloca-from-derived-tydesc.rs
index 9b37f36..cf9a9b6 100644
--- a/src/test/run-pass/alloca-from-derived-tydesc.rs
+++ b/src/test/run-pass/alloca-from-derived-tydesc.rs
@@ -1,17 +1,9 @@
// xfail-stage0
-tag option[T] {
- some(T);
- none;
-}
+tag option[T] { some(T); none; }
-type r[T] = rec(mutable (option[T])[] v);
+type r[T] = {mutable v: (option[T])[]};
-fn f[T]() -> T[] {
- ret ~[];
-}
+fn f[T]() -> T[] { ret ~[]; }
-fn main() {
- let r[int] r = rec(mutable v=~[]);
- r.v = f();
-}
+fn main() { let r: r[int] = {mutable v: ~[]}; r.v = f(); }
\ No newline at end of file
diff --git a/src/test/run-pass/alt-bot.rs b/src/test/run-pass/alt-bot.rs
index f656cf6..101a391 100644
--- a/src/test/run-pass/alt-bot.rs
+++ b/src/test/run-pass/alt-bot.rs
@@ -5,10 +5,6 @@
import std::option::*;
fn main() {
- let int i =
- alt (some[int](3)) {
- case (none[int]) { fail }
- case (some[int](_)) { 5 }
- };
+ let i: int = alt some[int](3) { none[int]. { fail } some[int](_) { 5 } };
log i;
}
\ No newline at end of file
diff --git a/src/test/run-pass/alt-join.rs b/src/test/run-pass/alt-join.rs
index 9639467..3aeb70e 100644
--- a/src/test/run-pass/alt-join.rs
+++ b/src/test/run-pass/alt-join.rs
@@ -5,17 +5,14 @@
import std::option::none;
import std::option::some;
-fn foo[T](&option::t[T] y) {
- let int x;
- let vec[int] rs = [];
+fn foo[T](y: &option::t[T]) {
+ let x: int;
+ let rs: vec[int] = [];
/* tests that x doesn't get put in the precondition for the
entire if expression */
- if (true) {
- } else {
- alt (y) { case (none[T]) { x = 17; } case (_) { x = 42; } }
- rs += [x];
- }
+ if true {
+ } else { alt y { none[T]. { x = 17; } _ { x = 42; } } rs += [x]; }
ret;
}
diff --git a/src/test/run-pass/alt-path.rs b/src/test/run-pass/alt-path.rs
index f6d4b0f..9f37cd2 100644
--- a/src/test/run-pass/alt-path.rs
+++ b/src/test/run-pass/alt-path.rs
@@ -4,6 +4,6 @@
tag foo { foo1; foo2; }
}
-fn bar(m1::foo x) { alt (x) { case (m1::foo1) { } } }
+fn bar(x: m1::foo) { alt x { m1::foo1. { } } }
fn main() { }
\ No newline at end of file
diff --git a/src/test/run-pass/alt-pattern-drop.rs b/src/test/run-pass/alt-pattern-drop.rs
index e5d008b..af0c615 100644
--- a/src/test/run-pass/alt-pattern-drop.rs
+++ b/src/test/run-pass/alt-pattern-drop.rs
@@ -7,26 +7,26 @@
// FIXME: import std::dbg.const_refcount. Currently
// cross-crate const references don't work.
-const uint const_refcount = 0x7bad_face_u;
+const const_refcount: uint = 0x7bad_face_u;
tag t { make_t(str); clam; }
-fn foo(str s) {
- let t x = make_t(s); // ref up
+fn foo(s: str) {
+ let x: t = make_t(s); // ref up
- alt (x) {
- case (make_t(?y)) {
- log y; // ref up then down
+ alt x {
+ make_t(y) {
+ log y; // ref up then down
- }
- case (_) { log "?"; fail; }
+ }
+ _ { log "?"; fail; }
}
log str::refcount(s);
assert (str::refcount(s) == const_refcount);
}
fn main() {
- let str s = "hi"; // ref up
+ let s: str = "hi"; // ref up
foo(s); // ref up then down
diff --git a/src/test/run-pass/alt-pattern-lit.rs b/src/test/run-pass/alt-pattern-lit.rs
index 8ec621c..3dc7bae 100644
--- a/src/test/run-pass/alt-pattern-lit.rs
+++ b/src/test/run-pass/alt-pattern-lit.rs
@@ -1,10 +1,7 @@
-fn altlit(int f) -> int {
- alt (f) {
- case (10) { log "case 10"; ret 20; }
- case (11) { log "case 11"; ret 22; }
- }
+fn altlit(f: int) -> int {
+ alt f { 10 { log "case 10"; ret 20; } 11 { log "case 11"; ret 22; } }
}
fn main() { assert (altlit(10) == 20); assert (altlit(11) == 22); }
\ No newline at end of file
diff --git a/src/test/run-pass/alt-pattern-no-type-params.rs b/src/test/run-pass/alt-pattern-no-type-params.rs
index 50fc85a..434f78d 100644
--- a/src/test/run-pass/alt-pattern-no-type-params.rs
+++ b/src/test/run-pass/alt-pattern-no-type-params.rs
@@ -4,11 +4,8 @@
// xfail-stage0
tag maybe[T] { nothing; just(T); }
-fn foo(maybe[int] x) {
- alt (x) {
- case (nothing) { log_err "A"; }
- case (just(?a)) { log_err "B"; }
- }
+fn foo(x: maybe[int]) {
+ alt x { nothing. { log_err "A"; } just(a) { log_err "B"; } }
}
fn main() { }
\ No newline at end of file
diff --git a/src/test/run-pass/alt-pattern-simple.rs b/src/test/run-pass/alt-pattern-simple.rs
index c524c03..1d02eb6 100644
--- a/src/test/run-pass/alt-pattern-simple.rs
+++ b/src/test/run-pass/alt-pattern-simple.rs
@@ -1,5 +1,5 @@
-fn altsimple(int f) { alt (f) { case (?x) { } } }
+fn altsimple(f: int) { alt f { x { } } }
fn main() { }
\ No newline at end of file
diff --git a/src/test/run-pass/alt-phi.rs b/src/test/run-pass/alt-phi.rs
index 1fd7988..07a4fe5 100644
--- a/src/test/run-pass/alt-phi.rs
+++ b/src/test/run-pass/alt-phi.rs
@@ -5,10 +5,10 @@
iter foo() -> int { put 10; }
fn main() {
- auto x = true;
- alt (a) {
- case (a) { x = true; for each (int i in foo()) { } }
- case (b) { x = false; }
- case (c) { x = false; }
+ let x = true;
+ alt a {
+ a. { x = true; for each i: int in foo() { } }
+ b. { x = false; }
+ c. { x = false; }
}
}
\ No newline at end of file
diff --git a/src/test/run-pass/alt-str.rs b/src/test/run-pass/alt-str.rs
index 591c06e..8fd15eb 100644
--- a/src/test/run-pass/alt-str.rs
+++ b/src/test/run-pass/alt-str.rs
@@ -1,21 +1,15 @@
// Issue #53
fn main() {
- alt ("test") {
- case ("not-test") { fail; }
- case ("test") { }
- case (_) { fail; }
- }
+ alt "test" { "not-test" { fail; } "test" { } _ { fail; } }
- tag t {
- tag1(str);
- tag2;
- }
+ tag t { tag1(str); tag2; }
- alt (tag1("test")) {
- case (tag2) { fail; }
- case (tag1("not-test")) { fail; }
- case (tag1("test")) { }
- case (_) { fail; }
- }
+
+ alt tag1("test") {
+ tag2. { fail; }
+ tag1("not-test") { fail; }
+ tag1("test") { }
+ _ { fail; }
+ }
}
\ No newline at end of file
diff --git a/src/test/run-pass/alt-tag.rs b/src/test/run-pass/alt-tag.rs
index 6e586a3..3bdc4b3 100644
--- a/src/test/run-pass/alt-tag.rs
+++ b/src/test/run-pass/alt-tag.rs
@@ -8,20 +8,20 @@
hsl(int, int, int);
}
-fn process(color c) -> int {
- let int x;
- alt (c) {
- case (rgb(?r, _, _)) { log "rgb"; log r; x = r; }
- case (rgba(_, _, _, ?a)) { log "rgba"; log a; x = a; }
- case (hsl(_, ?s, _)) { log "hsl"; log s; x = s; }
+fn process(c: color) -> int {
+ let x: int;
+ alt c {
+ rgb(r, _, _) { log "rgb"; log r; x = r; }
+ rgba(_, _, _, a) { log "rgba"; log a; x = a; }
+ hsl(_, s, _) { log "hsl"; log s; x = s; }
}
ret x;
}
fn main() {
- let color gray = rgb(127, 127, 127);
- let color clear = rgba(50, 150, 250, 0);
- let color red = hsl(0, 255, 255);
+ let gray: color = rgb(127, 127, 127);
+ let clear: color = rgba(50, 150, 250, 0);
+ let red: color = hsl(0, 255, 255);
assert (process(gray) == 127);
assert (process(clear) == 0);
assert (process(red) == 255);
diff --git a/src/test/run-pass/alt-type-simple.rs b/src/test/run-pass/alt-type-simple.rs
index bee450e..f30a758 100644
--- a/src/test/run-pass/alt-type-simple.rs
+++ b/src/test/run-pass/alt-type-simple.rs
@@ -1,15 +1,6 @@
-// xfail-stage0
-// xfail-stage1
-// xfail-stage2
-// xfail-stage3
-fn altsimple(any x) {
- alt type (f) {
- case (int i) { print("int"); }
- case (str s) { print("str"); }
- }
-}
-
-fn main() {
- altsimple(5);
- altsimple("asdfasdfsDF");
-}
+./src/test/run-pass/alt-type-simple.rs:6:6:6:10: [1;31merror:[0m found type in expression position
+./src/test/run-pass/alt-type-simple.rs:6 alt type (f) {
+ ^~~~
+rt: ---
+rt: f00e:main:main: upcall fail 'explicit failure', src/comp/syntax/parse/parser.rs:112
+rt: f00e:main: domain main @0x9b0204c root task failed
diff --git a/src/test/run-pass/anon-obj-backwarding.rs b/src/test/run-pass/anon-obj-backwarding.rs
index a1f6043..788be33 100644
--- a/src/test/run-pass/anon-obj-backwarding.rs
+++ b/src/test/run-pass/anon-obj-backwarding.rs
@@ -7,28 +7,20 @@
fn main() {
obj inner() {
- fn a() -> int {
- ret 2;
- }
- fn m() -> uint {
- ret 3u;
- }
- fn z() -> uint {
- ret self.m();
- }
+ fn a() -> int { ret 2; }
+ fn m() -> uint { ret 3u; }
+ fn z() -> uint { ret self.m(); }
}
- auto my_inner = inner();
+ let my_inner = inner();
- auto my_outer = obj() {
- fn b() -> uint {
- ret 5u;
- }
- fn n() -> str {
- ret "world!";
- }
- with my_inner
- };
+ let my_outer =
+ obj () {
+ fn b() -> uint { ret 5u; }
+ fn n() -> str { ret "world!"; }
+ with
+ my_inner
+ };
log_err my_inner.z();
assert (my_inner.z() == 3u);
diff --git a/src/test/run-pass/anon-obj-degenerate.rs b/src/test/run-pass/anon-obj-degenerate.rs
index 402bdae..d4870fc 100644
--- a/src/test/run-pass/anon-obj-degenerate.rs
+++ b/src/test/run-pass/anon-obj-degenerate.rs
@@ -3,22 +3,18 @@
fn main() {
obj a() {
- fn foo() -> int {
- ret 2;
- }
- fn bar() -> int {
- ret self.foo();
- }
+ fn foo() -> int { ret 2; }
+ fn bar() -> int { ret self.foo(); }
}
- auto my_a = a();
+ let my_a = a();
// Degenerate anonymous object: one that doesn't add any new
// methods or fields.
- auto my_d = obj() { with my_a };
+ let my_d = obj () { with my_a };
assert (my_d.foo() == 2);
assert (my_d.bar() == 2);
-}
+}
\ No newline at end of file
diff --git a/src/test/run-pass/anon-obj-overriding-reduced.rs b/src/test/run-pass/anon-obj-overriding-reduced.rs
index 0c1de4b..df1b700 100644
--- a/src/test/run-pass/anon-obj-overriding-reduced.rs
+++ b/src/test/run-pass/anon-obj-overriding-reduced.rs
@@ -2,19 +2,17 @@
fn main() {
obj a() {
- fn foo() -> int {
- ret 2;
- }
+ fn foo() -> int { ret 2; }
}
- auto my_a = a();
+ let my_a = a();
- auto my_b = obj() {
- fn foo() -> int {
- ret 3;
- }
- with my_a
- };
+ let my_b =
+ obj () {
+ fn foo() -> int { ret 3; }
+ with
+ my_a
+ };
assert (my_b.foo() == 3);
-}
+}
\ No newline at end of file
diff --git a/src/test/run-pass/anon-obj-overriding.rs b/src/test/run-pass/anon-obj-overriding.rs
index 223b384..9c8afbf 100644
--- a/src/test/run-pass/anon-obj-overriding.rs
+++ b/src/test/run-pass/anon-obj-overriding.rs
@@ -3,42 +3,39 @@
fn main() {
obj a() {
- fn foo() -> int {
- ret 2;
- }
- fn bar() -> int {
- ret self.foo();
- }
+ fn foo() -> int { ret 2; }
+ fn bar() -> int { ret self.foo(); }
}
- auto my_a = a();
+ let my_a = a();
// An anonymous object that overloads the 'foo' method.
- auto my_b = obj() {
- fn foo() -> int {
- ret 3;
- }
+ let
- with my_a
- };
+ my_b =
+ obj () {
+ fn foo() -> int { ret 3; }
+ with
+ my_a
+ };
assert (my_b.foo() == 3);
assert (my_b.bar() == 3);
- auto my_c = obj() {
- fn baz(int x, int y) -> int {
- ret x + y + self.foo();
- }
- with my_b
- };
+ let my_c =
+ obj () {
+ fn baz(x: int, y: int) -> int { ret x + y + self.foo(); }
+ with
+ my_b
+ };
- auto my_d = obj() {
- fn baz(int x, int y) -> int {
- ret x + y + self.foo();
- }
- with my_a
- };
+ let my_d =
+ obj () {
+ fn baz(x: int, y: int) -> int { ret x + y + self.foo(); }
+ with
+ my_a
+ };
assert (my_c.baz(1, 2) == 6);
assert (my_d.baz(1, 2) == 5);
-}
+}
\ No newline at end of file
diff --git a/src/test/run-pass/anon-obj-with-self-call-2.rs b/src/test/run-pass/anon-obj-with-self-call-2.rs
index 0b73e6d..69153ac 100644
--- a/src/test/run-pass/anon-obj-with-self-call-2.rs
+++ b/src/test/run-pass/anon-obj-with-self-call-2.rs
@@ -1,18 +1,16 @@
// Reduced test case for issue #540.
fn main() {
obj a() {
- fn foo() -> int {
- ret 2;
- }
+ fn foo() -> int { ret 2; }
}
- auto my_a = a();
- auto my_b = obj {
- fn baz() -> int {
- ret self.foo();
- }
- with my_a
- };
+ let my_a = a();
+ let my_b =
+ obj () {
+ fn baz() -> int { ret self.foo(); }
+ with
+ my_a
+ };
assert (my_b.baz() == 2);
-}
+}
\ No newline at end of file
diff --git a/src/test/run-pass/anon-obj-with-self-call.rs b/src/test/run-pass/anon-obj-with-self-call.rs
index 9690a4b..2944bc0 100644
--- a/src/test/run-pass/anon-obj-with-self-call.rs
+++ b/src/test/run-pass/anon-obj-with-self-call.rs
@@ -3,35 +3,29 @@
fn main() {
obj a() {
- fn foo() -> int {
- ret 2;
- }
- fn bar() -> int {
- ret self.foo();
- }
+ fn foo() -> int { ret 2; }
+ fn bar() -> int { ret self.foo(); }
}
- auto my_a = a();
+ let my_a = a();
- auto my_b = obj {
- fn baz() -> int {
- ret self.foo();
- }
- with my_a
- };
+ let my_b =
+ obj () {
+ fn baz() -> int { ret self.foo(); }
+ with
+ my_a
+ };
assert (my_b.baz() == 2);
- auto my_c = obj {
- fn foo() -> int {
- ret 3;
- }
- fn baz() -> int {
- ret self.foo();
- }
- with my_a
- };
+ let my_c =
+ obj () {
+ fn foo() -> int { ret 3; }
+ fn baz() -> int { ret self.foo(); }
+ with
+ my_a
+ };
assert (my_c.baz() == 3);
assert (my_c.bar() == 3);
-}
+}
\ No newline at end of file
diff --git a/src/test/run-pass/anon-objs-with-fields.rs b/src/test/run-pass/anon-objs-with-fields.rs
index 653294e..bf7344d 100644
--- a/src/test/run-pass/anon-objs-with-fields.rs
+++ b/src/test/run-pass/anon-objs-with-fields.rs
@@ -7,27 +7,23 @@
fn main() {
obj a() {
- fn foo() -> int {
- ret 2;
- }
- fn bar() -> int {
- ret self.foo();
- }
+ fn foo() -> int { ret 2; }
+ fn bar() -> int { ret self.foo(); }
}
- auto my_a = a();
+ let my_a = a();
// Extending an object with a new field. Adding support for this
// is issue #538.
// Right now, this fails with "unresolved name: quux".
- auto my_c = obj(int quux = 3) {
- fn baz() -> int {
- ret quux + 4;
- }
- with my_a
- };
+ let my_c =
+ obj (quux: int = 3) {
+ fn baz() -> int { ret quux + 4; }
+ with
+ my_a
+ };
assert (my_c.baz() == 7);
-}
+}
\ No newline at end of file
diff --git a/src/test/run-pass/argv.rs b/src/test/run-pass/argv.rs
index c94106a..7aefc0d 100644
--- a/src/test/run-pass/argv.rs
+++ b/src/test/run-pass/argv.rs
@@ -1,7 +1,7 @@
-fn main(vec[str] args) {
- let vec[str] vs = ["hi", "there", "this", "is", "a", "vec"];
- let vec[vec[str]] vvs = [args, vs];
- for (vec[str] vs in vvs) { for (str s in vs) { log s; } }
+fn main(args: vec[str]) {
+ let vs: vec[str] = ["hi", "there", "this", "is", "a", "vec"];
+ let vvs: vec[vec[str]] = [args, vs];
+ for vs: vec[str] in vvs { for s: str in vs { log s; } }
}
\ No newline at end of file
diff --git a/src/test/run-pass/arith-0.rs b/src/test/run-pass/arith-0.rs
index 5d68b04..6ad7979 100644
--- a/src/test/run-pass/arith-0.rs
+++ b/src/test/run-pass/arith-0.rs
@@ -1,3 +1,3 @@
-fn main() { let int a = 10; log a; assert (a * (a - 1) == 90); }
\ No newline at end of file
+fn main() { let a: int = 10; log a; assert (a * (a - 1) == 90); }
\ No newline at end of file
diff --git a/src/test/run-pass/arith-1.rs b/src/test/run-pass/arith-1.rs
index ec1c6ad..0f907de 100644
--- a/src/test/run-pass/arith-1.rs
+++ b/src/test/run-pass/arith-1.rs
@@ -1,7 +1,7 @@
fn main() {
- let int i32_a = 10;
+ let i32_a: int = 10;
assert (i32_a == 10);
assert (i32_a - 10 == 0);
assert (i32_a / 10 == 1);
@@ -13,7 +13,7 @@
assert (i32_a * i32_a * i32_a * i32_a == 10000);
assert (i32_a * i32_a / i32_a * i32_a == 100);
assert (i32_a * (i32_a - 1) << 2 + i32_a == 368640);
- let int i32_b = 0x10101010;
+ let i32_b: int = 0x10101010;
assert (i32_b + 1 - 1 == i32_b);
assert (i32_b << 1 == i32_b << 1);
assert (i32_b >> 1 == i32_b >> 1);
diff --git a/src/test/run-pass/arith-2.rs b/src/test/run-pass/arith-2.rs
index bbb7c7e..bb0f674 100644
--- a/src/test/run-pass/arith-2.rs
+++ b/src/test/run-pass/arith-2.rs
@@ -1,7 +1,7 @@
fn main() {
- let int i32_c = 0x10101010;
+ let i32_c: int = 0x10101010;
assert (i32_c + i32_c * 2 / 3 * 2 + (i32_c - 7 % 3) ==
i32_c + i32_c * 2 / 3 * 2 + (i32_c - 7 % 3));
}
\ No newline at end of file
diff --git a/src/test/run-pass/assign-assign.rs b/src/test/run-pass/assign-assign.rs
index d367593..2bd1a79 100644
--- a/src/test/run-pass/assign-assign.rs
+++ b/src/test/run-pass/assign-assign.rs
@@ -5,20 +5,20 @@
// Issue 483 - Assignment expressions result in nil
fn test_assign() {
- let int x;
- let () y = x = 10;
+ let x: int;
+ let y: () = x = 10;
assert (x == 10);
- auto z = x = 11;
+ let z = x = 11;
assert (x == 11);
z = x = 12;
assert (x == 12);
}
fn test_assign_op() {
- let int x = 0;
- let () y = x += 10;
+ let x: int = 0;
+ let y: () = x += 10;
assert (x == 10);
- auto z = x += 11;
+ let z = x += 11;
assert (x == 21);
z = x += 12;
assert (x == 33);
diff --git a/src/test/run-pass/auto-deref-fn.rs b/src/test/run-pass/auto-deref-fn.rs
index 8637c7d..59788ce 100644
--- a/src/test/run-pass/auto-deref-fn.rs
+++ b/src/test/run-pass/auto-deref-fn.rs
@@ -1,12 +1,12 @@
// xfail-stage0
-fn add1(int i) -> int { ret i+1; }
+fn add1(i: int) -> int { ret i + 1; }
fn main() {
- auto f = @add1;
- auto g = @f;
- auto h = @@@add1;
- assert(f(5) == 6);
- assert(g(8) == 9);
- assert(h(0x1badd00d) == 0x1badd00e);
- assert((@add1)(42) == 43);
-}
+ let f = @add1;
+ let g = @f;
+ let h = @@@add1;
+ assert (f(5) == 6);
+ assert (g(8) == 9);
+ assert (h(0x1badd00d) == 0x1badd00e);
+ assert ((@add1)(42) == 43);
+}
\ No newline at end of file
diff --git a/src/test/run-pass/auto-instantiate.rs b/src/test/run-pass/auto-instantiate.rs
index edc0ca3..e82aaa2 100644
--- a/src/test/run-pass/auto-instantiate.rs
+++ b/src/test/run-pass/auto-instantiate.rs
@@ -2,6 +2,6 @@
// -*- rust -*-
-fn f[T, U](&T x, &U y) -> rec(T a, U b) { ret rec(a=x, b=y); }
+fn f[T, U](x: &T, y: &U) -> {a: T, b: U} { ret {a: x, b: y}; }
-fn main() { log f(rec(x=3, y=4, z=5), 4).a.x; log f(5, 6).a; }
\ No newline at end of file
+fn main() { log f({x: 3, y: 4, z: 5}, 4).a.x; log f(5, 6).a; }
\ No newline at end of file
diff --git a/src/test/run-pass/auto-loop.rs b/src/test/run-pass/auto-loop.rs
index cc9275a..238c166 100644
--- a/src/test/run-pass/auto-loop.rs
+++ b/src/test/run-pass/auto-loop.rs
@@ -1,7 +1,5 @@
fn main() {
- auto sum = 0;
- for (auto x in ~[1, 2, 3, 4, 5]) {
- sum += x;
- }
- assert sum == 15;
-}
+ let sum = 0;
+ for x in ~[1, 2, 3, 4, 5] { sum += x; }
+ assert (sum == 15);
+}
\ No newline at end of file
diff --git a/src/test/run-pass/autobind.rs b/src/test/run-pass/autobind.rs
index 98cda76..935fbef 100644
--- a/src/test/run-pass/autobind.rs
+++ b/src/test/run-pass/autobind.rs
@@ -1,13 +1,9 @@
-fn f[T](&T[] x) -> T {
- ret x.(0);
-}
+fn f[T](x: &T[]) -> T { ret x.(0); }
-fn g(fn(&int[]) -> int act) -> int {
- ret act(~[1, 2, 3]);
-}
+fn g(act: fn(&int[]) -> int ) -> int { ret act(~[1, 2, 3]); }
fn main() {
- assert g(f) == 1;
- let fn(&str[]) -> str f1 = f;
- assert f1(~["x", "y", "z"]) == "x";
-}
+ assert (g(f) == 1);
+ let f1: fn(&str[]) -> str = f;
+ assert (f1(~["x", "y", "z"]) == "x");
+}
\ No newline at end of file
diff --git a/src/test/run-pass/autoderef-full-lval.rs b/src/test/run-pass/autoderef-full-lval.rs
index 1743466..01e2981 100644
--- a/src/test/run-pass/autoderef-full-lval.rs
+++ b/src/test/run-pass/autoderef-full-lval.rs
@@ -2,19 +2,19 @@
// -*- rust -*-
-type clam = rec(@int x, @int y);
+type clam = {x: @int, y: @int};
-type fish = rec(@int a);
+type fish = {a: @int};
fn main() {
- let clam a = rec(x=@1, y=@2);
- let clam b = rec(x=@10, y=@20);
- let int z = a.x + b.y;
+ let a: clam = {x: @1, y: @2};
+ let b: clam = {x: @10, y: @20};
+ let z: int = a.x + b.y;
log z;
assert (z == 21);
- let fish forty = rec(a=@40);
- let fish two = rec(a=@2);
- let int answer = forty.a + two.a;
+ let forty: fish = {a: @40};
+ let two: fish = {a: @2};
+ let answer: int = forty.a + two.a;
log answer;
assert (answer == 42);
}
\ No newline at end of file
diff --git a/src/test/run-pass/autoderef-objfn.rs b/src/test/run-pass/autoderef-objfn.rs
index 39218ff..cf7bb39 100644
--- a/src/test/run-pass/autoderef-objfn.rs
+++ b/src/test/run-pass/autoderef-objfn.rs
@@ -6,6 +6,6 @@
fn chowder() { log "in clam chowder"; }
}
-fn foo(@clam c) { c.chowder(); }
+fn foo(c: @clam) { c.chowder(); }
-fn main() { let clam c = clam(); foo(@c); }
\ No newline at end of file
+fn main() { let c: clam = clam(); foo(@c); }
\ No newline at end of file
diff --git a/src/test/run-pass/basic-1.rs b/src/test/run-pass/basic-1.rs
index f1425ed..8ee0245 100644
--- a/src/test/run-pass/basic-1.rs
+++ b/src/test/run-pass/basic-1.rs
@@ -1,26 +1,24 @@
// xfail-stage0
// -*- rust -*-
-fn a(chan[int] c) {
- c <| 10;
-}
+fn a(c: chan[int]) { c <| 10; }
fn main() {
- let port[int] p = port();
+ let p: port[int] = port();
spawn a(chan(p));
spawn b(chan(p));
- let int n = 0;
+ let n: int = 0;
p |> n;
p |> n;
-// log "Finished.";
+ // log "Finished.";
}
-fn b(chan[int] c) {
-// log "task b0";
-// log "task b1";
-// log "task b2";
-// log "task b3";
-// log "task b4";
-// log "task b5";
+fn b(c: chan[int]) {
+ // log "task b0";
+ // log "task b1";
+ // log "task b2";
+ // log "task b3";
+ // log "task b4";
+ // log "task b5";
c <| 10;
}
\ No newline at end of file
diff --git a/src/test/run-pass/basic-2.rs b/src/test/run-pass/basic-2.rs
index 44fb0a5..2c54c59 100644
--- a/src/test/run-pass/basic-2.rs
+++ b/src/test/run-pass/basic-2.rs
@@ -1,27 +1,23 @@
// xfail-stage0
// -*- rust -*-
-fn a(chan[int] c) {
- log "task a0";
- log "task a1";
- c <| 10;
-}
+fn a(c: chan[int]) { log "task a0"; log "task a1"; c <| 10; }
fn main() {
- let port[int] p = port();
+ let p: port[int] = port();
spawn a(chan(p));
spawn b(chan(p));
- let int n = 0;
+ let n: int = 0;
p |> n;
p |> n;
log "Finished.";
}
-fn b(chan[int] c) {
+fn b(c: chan[int]) {
log "task b0";
log "task b1";
log "task b2";
log "task b2";
log "task b3";
c <| 10;
-}
+}
\ No newline at end of file
diff --git a/src/test/run-pass/basic.rs b/src/test/run-pass/basic.rs
index c4100d8..927e763 100644
--- a/src/test/run-pass/basic.rs
+++ b/src/test/run-pass/basic.rs
@@ -1,36 +1,29 @@
// xfail-stage0
// -*- rust -*-
-fn a(chan[int] c) {
- if (true) {
- log "task a";
- log "task a";
- log "task a";
- log "task a";
- log "task a";
- }
- c <| 10;
+fn a(c: chan[int]) {
+ if true {
+ log "task a";
+ log "task a";
+ log "task a";
+ log "task a";
+ log "task a";
+ }
+ c <| 10;
}
-fn k(int x) -> int {
- ret 15;
-}
+fn k(x: int) -> int { ret 15; }
-fn g(int x, str y) -> int {
- log x;
- log y;
- let int z = k(1);
- ret z;
-}
+fn g(x: int, y: str) -> int { log x; log y; let z: int = k(1); ret z; }
fn main() {
- let int n = 2 + 3 * 7;
- let str s = "hello there";
- let port[int] p = port();
+ let n: int = 2 + 3 * 7;
+ let s: str = "hello there";
+ let p: port[int] = port();
spawn a(chan(p));
spawn b(chan(p));
- let int x = 10;
- x = g(n,s);
+ let x: int = 10;
+ x = g(n, s);
log x;
p |> n;
p |> n;
@@ -38,14 +31,14 @@
log "children finished, root finishing";
}
-fn b(chan[int] c) {
- if (true) {
- log "task b";
- log "task b";
- log "task b";
- log "task b";
- log "task b";
- log "task b";
- }
- c <| 10;
-}
+fn b(c: chan[int]) {
+ if true {
+ log "task b";
+ log "task b";
+ log "task b";
+ log "task b";
+ log "task b";
+ log "task b";
+ }
+ c <| 10;
+}
\ No newline at end of file
diff --git a/src/test/run-pass/bind-exterior.rs b/src/test/run-pass/bind-exterior.rs
index edf4b91..3785076 100644
--- a/src/test/run-pass/bind-exterior.rs
+++ b/src/test/run-pass/bind-exterior.rs
@@ -1,5 +1,5 @@
-fn foo(@int a, @int b) -> int { ret a + b; }
+fn foo(a: @int, b: @int) -> int { ret a + b; }
-fn main() { auto f1 = bind foo(@10, @12); assert (f1() == 22); }
\ No newline at end of file
+fn main() { let f1 = bind foo(@10, @12); assert (f1() == 22); }
\ No newline at end of file
diff --git a/src/test/run-pass/bind-interior.rs b/src/test/run-pass/bind-interior.rs
index d14d52c..ab3ce3b 100644
--- a/src/test/run-pass/bind-interior.rs
+++ b/src/test/run-pass/bind-interior.rs
@@ -2,10 +2,10 @@
// -*- rust -*-
-fn f(int n) -> int { ret n; }
+fn f(n: int) -> int { ret n; }
fn main() {
- let fn() -> int g = bind f(10);
- let int i = g();
+ let g: fn() -> int = bind f(10);
+ let i: int = g();
assert (i == 10);
}
\ No newline at end of file
diff --git a/src/test/run-pass/bind-obj-ctor.rs b/src/test/run-pass/bind-obj-ctor.rs
index c9f730b..6be4df9 100644
--- a/src/test/run-pass/bind-obj-ctor.rs
+++ b/src/test/run-pass/bind-obj-ctor.rs
@@ -3,14 +3,14 @@
fn main() {
// Testcase for issue #59.
- obj simple(int x, int y) {
+ obj simple(x: int, y: int) {
fn sum() -> int { ret x + y; }
}
- auto obj0 = simple(1, 2);
- auto ctor0 = bind simple(1, _);
- auto ctor1 = bind simple(_, 2);
- auto obj1 = ctor0(2);
- auto obj2 = ctor1(1);
+ let obj0 = simple(1, 2);
+ let ctor0 = bind simple(1, _);
+ let ctor1 = bind simple(_, 2);
+ let obj1 = ctor0(2);
+ let obj2 = ctor1(1);
assert (obj0.sum() == 3);
assert (obj1.sum() == 3);
assert (obj2.sum() == 3);
diff --git a/src/test/run-pass/bind-thunk.rs b/src/test/run-pass/bind-thunk.rs
index 378f9f8..e70fa6f 100644
--- a/src/test/run-pass/bind-thunk.rs
+++ b/src/test/run-pass/bind-thunk.rs
@@ -5,7 +5,7 @@
fn f() -> int { ret 42; }
fn main() {
- let fn() -> int g = bind f();
- let int i = g();
+ let g: fn() -> int = bind f();
+ let i: int = g();
assert (i == 42);
}
\ No newline at end of file
diff --git a/src/test/run-pass/bind-trivial.rs b/src/test/run-pass/bind-trivial.rs
index 1d5b72c..35ed5d7 100644
--- a/src/test/run-pass/bind-trivial.rs
+++ b/src/test/run-pass/bind-trivial.rs
@@ -2,10 +2,10 @@
// -*- rust -*-
-fn f(int n) -> int { ret n; }
+fn f(n: int) -> int { ret n; }
fn main() {
- let fn(int) -> int g = bind f(_);
- let int i = g(42);
+ let g: fn(int) -> int = bind f(_);
+ let i: int = g(42);
assert (i == 42);
}
\ No newline at end of file
diff --git a/src/test/run-pass/binops.rs b/src/test/run-pass/binops.rs
index 00d13c8..801da9c 100644
--- a/src/test/run-pass/binops.rs
+++ b/src/test/run-pass/binops.rs
@@ -3,160 +3,160 @@
// Binop corner cases
fn test_nil() {
- assert () == ();
- assert !(() != ());
- assert !(() < ());
- assert () <= ();
- assert !(() > ());
- assert () >= ();
+ assert (() == ());
+ assert (!(() != ()));
+ assert (!(() < ()));
+ assert (() <= ());
+ assert (!(() > ()));
+ assert (() >= ());
}
fn test_bool() {
- assert !(true < false);
- assert !(true <= false);
- assert (true > false);
- assert (true >= false);
+ assert (!(true < false));
+ assert (!(true <= false));
+ assert (true > false);
+ assert (true >= false);
- assert (false < true);
- assert (false <= true);
- assert !(false > true);
- assert !(false >= true);
+ assert (false < true);
+ assert (false <= true);
+ assert (!(false > true));
+ assert (!(false >= true));
- // Bools support bitwise binops
- assert (false & false == false);
- assert (true & false == false);
- assert (true & true == true);
- assert (false | false == false);
- assert (true | false == true);
- assert (true | true == true);
- assert (false ^ false == false);
- assert (true ^ false == true);
- assert (true ^ true == false);
+ // Bools support bitwise binops
+ assert (false & false == false);
+ assert (true & false == false);
+ assert (true & true == true);
+ assert (false | false == false);
+ assert (true | false == true);
+ assert (true | true == true);
+ assert (false ^ false == false);
+ assert (true ^ false == true);
+ assert (true ^ true == false);
}
fn test_char() {
- auto ch10 = 10 as char;
- auto ch4 = 4 as char;
- auto ch2 = 2 as char;
- assert ch10 + ch4 == 14 as char;
- assert ch10 - ch4 == 6 as char;
- assert ch10 * ch4 == 40 as char;
- assert ch10 / ch4 == ch2;
- assert ch10 % ch4 == ch2;
- assert ch10 >> ch2 == ch2;
- assert ch10 >>> ch2 == ch2;
- assert ch10 << ch4 == 160 as char;
- assert ch10 | ch4 == 14 as char;
- assert ch10 & ch2 == ch2;
- assert ch10 ^ ch2 == 8 as char;
+ let ch10 = 10 as char;
+ let ch4 = 4 as char;
+ let ch2 = 2 as char;
+ assert (ch10 + ch4 == 14 as char);
+ assert (ch10 - ch4 == 6 as char);
+ assert (ch10 * ch4 == 40 as char);
+ assert (ch10 / ch4 == ch2);
+ assert (ch10 % ch4 == ch2);
+ assert (ch10 >> ch2 == ch2);
+ assert (ch10 >>> ch2 == ch2);
+ assert (ch10 << ch4 == 160 as char);
+ assert (ch10 | ch4 == 14 as char);
+ assert (ch10 & ch2 == ch2);
+ assert (ch10 ^ ch2 == 8 as char);
}
fn test_box() {
- assert @10 == 10;
- assert 0xFF & @0xF0 == 0xF0;
- assert rec(a=1, b=3) < @rec(a=1, b=4);
- assert @rec(a = 'x') != @rec(a = 'y');
+ assert (@10 == 10);
+ assert (0xFF & @0xF0 == 0xF0);
+ assert ({a: 1, b: 3} < @{a: 1, b: 4});
+ assert (@{a: 'x'} != @{a: 'y'});
}
fn test_port() {
- let port[int] p1 = port();
- let port[int] p2 = port();
+ let p1: port[int] = port();
+ let p2: port[int] = port();
- // FIXME (#577) comparison of ports
- // assert (p1 != p2);
- // assert !(p1 < p2);
- // etc
+ // FIXME (#577) comparison of ports
+ // assert (p1 != p2);
+ // assert !(p1 < p2);
+ // etc
}
fn test_chan() {
- let port[int] p = port();
- auto ch1 = chan(p);
- auto ch2 = chan(p);
+ let p: port[int] = port();
+ let ch1 = chan(p);
+ let ch2 = chan(p);
- // FIXME (#577) comparison of channels
- // assert (ch1 != ch2);
- // etc
+ // FIXME (#577) comparison of channels
+ // assert (ch1 != ch2);
+ // etc
}
fn test_ptr() {
- // FIXME: Don't know what binops apply to pointers. Don't know how
- // to make or use pointers
+ // FIXME: Don't know what binops apply to pointers. Don't know how
+ // to make or use pointers
}
fn test_task() {
- fn f() {}
- auto t1 = spawn f();
- auto t2 = spawn f();
- // FIXME (#577) comparison of tasks
- //assert t1 != t2;
+ fn f() { }
+ let t1 = spawn f();
+ let t2 = spawn f();
+ // FIXME (#577) comparison of tasks
+ //assert t1 != t2;
}
fn test_fn() {
- fn f() {}
- fn g() {}
- fn h(int i) {}
- auto f1 = f;
- auto f2 = f;
- auto g1 = g;
- auto h1 = h;
- auto h2 = h;
- assert (f1 == f2);
- assert (f1 == f);
+ fn f() { }
+ fn g() { }
+ fn h(i: int) { }
+ let f1 = f;
+ let f2 = f;
+ let g1 = g;
+ let h1 = h;
+ let h2 = h;
+ assert (f1 == f2);
+ assert (f1 == f);
- assert (f1 == g1);
- assert (h1 == h2);
- assert !(f1 != f2);
- assert !(h1 < h2);
- assert (h1 <= h2);
- assert !(h1 > h2);
- assert (h1 >= h2);
+ assert (f1 == g1);
+ assert (h1 == h2);
+ assert (!(f1 != f2));
+ assert (!(h1 < h2));
+ assert (h1 <= h2);
+ assert (!(h1 > h2));
+ assert (h1 >= h2);
}
native "rust" mod native_mod = "" {
- fn str_byte_len(str s) -> vec[u8];
- fn str_alloc(uint n_bytes) -> str;
+ fn str_byte_len(s: str) -> vec[u8];
+ fn str_alloc(n_bytes: uint) -> str;
}
// FIXME: comparison of native fns
fn test_native_fn() {
- /*assert (native_mod::str_byte_len == native_mod::str_byte_len);
- assert (native_mod::str_byte_len != native_mod::str_alloc);*/
+ /*assert (native_mod::str_byte_len == native_mod::str_byte_len);
+ assert (native_mod::str_byte_len != native_mod::str_alloc);*/
}
fn test_obj() {
- auto o1 = obj() { };
- auto o2 = obj() { };
+ let o1 = obj () { };
+ let o2 = obj () { };
- assert (o1 == o2);
- assert !(o1 != o2);
- assert !(o1 < o2);
- assert (o1 <= o2);
- assert !(o1 > o2);
- assert (o1 >= o2);
+ assert (o1 == o2);
+ assert (!(o1 != o2));
+ assert (!(o1 < o2));
+ assert (o1 <= o2);
+ assert (!(o1 > o2));
+ assert (o1 >= o2);
- obj constr1(int i) { };
- obj constr2(int i) { };
+ obj constr1(i: int) { }
+ obj constr2(i: int) { }
- auto o5 = constr1(10);
- auto o6 = constr1(10);
- auto o7 = constr1(11);
- auto o8 = constr2(11);
+ let o5 = constr1(10);
+ let o6 = constr1(10);
+ let o7 = constr1(11);
+ let o8 = constr2(11);
- assert (o5 == o6);
- assert (o6 == o7);
- assert (o7 == o8);
+ assert (o5 == o6);
+ assert (o6 == o7);
+ assert (o7 == o8);
}
fn main() {
- test_nil();
- test_bool();
- test_char();
- test_box();
- test_port();
- test_chan();
- test_ptr();
- test_task();
- test_fn();
- test_native_fn();
- test_obj();
-}
+ test_nil();
+ test_bool();
+ test_char();
+ test_box();
+ test_port();
+ test_chan();
+ test_ptr();
+ test_task();
+ test_fn();
+ test_native_fn();
+ test_obj();
+}
\ No newline at end of file
diff --git a/src/test/run-pass/bitwise.rs b/src/test/run-pass/bitwise.rs
index e9a7416..0d41cb0 100644
--- a/src/test/run-pass/bitwise.rs
+++ b/src/test/run-pass/bitwise.rs
@@ -3,8 +3,8 @@
// -*- rust -*-
fn main() {
- let int a = 1;
- let int b = 2;
+ let a: int = 1;
+ let b: int = 2;
a ^= b;
b ^= a;
a = a ^ b;
diff --git a/src/test/run-pass/block-fn-coerce.rs b/src/test/run-pass/block-fn-coerce.rs
index f728fbb..ac6be75 100644
--- a/src/test/run-pass/block-fn-coerce.rs
+++ b/src/test/run-pass/block-fn-coerce.rs
@@ -1,9 +1,9 @@
// xfail-stage0
-fn force(&block() -> int f) -> int { ret f(); }
+fn force(f: &block() -> int ) -> int { ret f(); }
fn main() {
- auto f = fn() -> int { ret 7 };
- assert(force(f) == 7);
- auto g = bind force(f);
- assert(g() == 7);
-}
+ let f = fn () -> int { ret 7 };
+ assert (force(f) == 7);
+ let g = bind force(f);
+ assert (g() == 7);
+}
\ No newline at end of file
diff --git a/src/test/run-pass/block-iter-1.rs b/src/test/run-pass/block-iter-1.rs
index 6d887b2..85bd167 100644
--- a/src/test/run-pass/block-iter-1.rs
+++ b/src/test/run-pass/block-iter-1.rs
@@ -1,22 +1,16 @@
// xfail-stage0
-fn iter_vec[T](&vec[T] v, &block (&T) f) {
- for (T x in v) {
- f(x);
- }
-}
+fn iter_vec[T](v: &vec[T], f: &block(&T) ) { for x: T in v { f(x); } }
fn main() {
- auto v = [1,2,3,4,5,6,7];
- auto odds = 0;
+ let v = [1, 2, 3, 4, 5, 6, 7];
+ let odds = 0;
iter_vec(v,
- block (&int i) {
+ block (i: &int) {
log_err i;
- if (i % 2 == 1) {
- odds += 1;
- }
+ if i % 2 == 1 { odds += 1; }
log_err odds;
});
log_err odds;
- assert(odds == 4);
-}
+ assert (odds == 4);
+}
\ No newline at end of file
diff --git a/src/test/run-pass/block-iter-2.rs b/src/test/run-pass/block-iter-2.rs
index 1bc1997..4e0bc3e 100644
--- a/src/test/run-pass/block-iter-2.rs
+++ b/src/test/run-pass/block-iter-2.rs
@@ -1,22 +1,15 @@
// xfail-stage0
-fn iter_vec[T](&vec[T] v, &block (&T) f) {
- for (T x in v) {
- f(x);
- }
-}
+fn iter_vec[T](v: &vec[T], f: &block(&T) ) { for x: T in v { f(x); } }
fn main() {
- auto v = [1,2,3,4,5];
- auto sum = 0;
- iter_vec(v, block (&int i)
- {
- iter_vec(v, block (&int j)
- {
- log_err i*j;
- sum += i*j;
- });
- });
+ let v = [1, 2, 3, 4, 5];
+ let sum = 0;
+ iter_vec(v,
+ block (i: &int) {
+ iter_vec(v,
+ block (j: &int) { log_err i * j; sum += i * j; });
+ });
log_err sum;
- assert(sum == 225);
-}
+ assert (sum == 225);
+}
\ No newline at end of file
diff --git a/src/test/run-pass/bool-not.rs b/src/test/run-pass/bool-not.rs
index a18ffcf..9d609d4 100644
--- a/src/test/run-pass/bool-not.rs
+++ b/src/test/run-pass/bool-not.rs
@@ -3,6 +3,6 @@
// -*- rust -*-
fn main() {
- if (!false) { assert (true); } else { assert (false); }
- if (!true) { assert (false); } else { assert (true); }
+ if !false { assert (true); } else { assert (false); }
+ if !true { assert (false); } else { assert (true); }
}
\ No newline at end of file
diff --git a/src/test/run-pass/box-inside-if.rs b/src/test/run-pass/box-inside-if.rs
index 9d05403..e9e6be8 100644
--- a/src/test/run-pass/box-inside-if.rs
+++ b/src/test/run-pass/box-inside-if.rs
@@ -4,14 +4,14 @@
use std;
import std::vec;
-fn some_vec(int x) -> vec[int] { ret []; }
+fn some_vec(x: int) -> vec[int] { ret []; }
-fn is_odd(int n) -> bool { ret true; }
+fn is_odd(n: int) -> bool { ret true; }
-fn length_is_even(vec[int] vs) -> bool { ret true; }
+fn length_is_even(vs: vec[int]) -> bool { ret true; }
-fn foo(int acc, int n) {
- if (is_odd(n) && length_is_even(some_vec(1))) { log_err "bloop"; }
+fn foo(acc: int, n: int) {
+ if is_odd(n) && length_is_even(some_vec(1)) { log_err "bloop"; }
}
fn main() { foo(67, 5); }
\ No newline at end of file
diff --git a/src/test/run-pass/box-inside-if2.rs b/src/test/run-pass/box-inside-if2.rs
index f987e07..8ed2f44 100644
--- a/src/test/run-pass/box-inside-if2.rs
+++ b/src/test/run-pass/box-inside-if2.rs
@@ -4,14 +4,14 @@
use std;
import std::vec;
-fn some_vec(int x) -> vec[int] { ret []; }
+fn some_vec(x: int) -> vec[int] { ret []; }
-fn is_odd(int n) -> bool { ret true; }
+fn is_odd(n: int) -> bool { ret true; }
-fn length_is_even(vec[int] vs) -> bool { ret true; }
+fn length_is_even(vs: vec[int]) -> bool { ret true; }
-fn foo(int acc, int n) {
- if (is_odd(n) || length_is_even(some_vec(1))) { log_err "bloop"; }
+fn foo(acc: int, n: int) {
+ if is_odd(n) || length_is_even(some_vec(1)) { log_err "bloop"; }
}
fn main() { foo(67, 5); }
\ No newline at end of file
diff --git a/src/test/run-pass/box-pattern.rs b/src/test/run-pass/box-pattern.rs
index ad5e631..7c5e050 100644
--- a/src/test/run-pass/box-pattern.rs
+++ b/src/test/run-pass/box-pattern.rs
@@ -1,14 +1,11 @@
// xfail-stage0
-type foo = rec(int a, uint b);
-tag bar {
- u(@foo);
- w(int);
-}
+type foo = {a: int, b: uint};
+tag bar { u(@foo); w(int); }
fn main() {
- assert alt (u(@rec(a=10, b=40u))) {
- u(@{a, b}) { a + (b as int) }
- _ { 66 }
- } == 50;
-}
+ assert (alt u(@{a: 10, b: 40u}) {
+ u(@{a: a, b: b}) { a + (b as int) }
+ _ { 66 }
+ } == 50);
+}
\ No newline at end of file
diff --git a/src/test/run-pass/box-unbox.rs b/src/test/run-pass/box-unbox.rs
index a354f90..751d69c 100644
--- a/src/test/run-pass/box-unbox.rs
+++ b/src/test/run-pass/box-unbox.rs
@@ -1,12 +1,12 @@
-type box[T] = rec(@T c);
+type box[T] = {c: @T};
-fn unbox[T](&box[T] b) -> T { ret *b.c; }
+fn unbox[T](b: &box[T]) -> T { ret *b.c; }
fn main() {
- let int foo = 17;
- let box[int] bfoo = rec(c=@foo);
+ let foo: int = 17;
+ let bfoo: box[int] = {c: @foo};
log "see what's in our box";
assert (unbox[int](bfoo) == foo);
}
\ No newline at end of file
diff --git a/src/test/run-pass/box.rs b/src/test/run-pass/box.rs
index 3fc7d74..c9ef392 100644
--- a/src/test/run-pass/box.rs
+++ b/src/test/run-pass/box.rs
@@ -1,3 +1,3 @@
-fn main() { let @int x = @10; assert (*x == 10); }
\ No newline at end of file
+fn main() { let x: @int = @10; assert (*x == 10); }
\ No newline at end of file
diff --git a/src/test/run-pass/break-value.rs b/src/test/run-pass/break-value.rs
index b53cf5e..3e4a452 100644
--- a/src/test/run-pass/break-value.rs
+++ b/src/test/run-pass/break-value.rs
@@ -2,6 +2,6 @@
// xfail-stage0
-fn int_id(int x) -> int { ret x; }
+fn int_id(x: int) -> int { ret x; }
-fn main() { while (true) { int_id(break); } }
\ No newline at end of file
+fn main() { while true { int_id(break); } }
\ No newline at end of file
diff --git a/src/test/run-pass/break.rs b/src/test/run-pass/break.rs
index 29a03b1..a7f01b7 100644
--- a/src/test/run-pass/break.rs
+++ b/src/test/run-pass/break.rs
@@ -1,22 +1,21 @@
fn main() {
- auto i = 0;
- while (i < 20) { i += 1; if (i == 10) { break; } }
+ let i = 0;
+ while i < 20 { i += 1; if i == 10 { break; } }
assert (i == 10);
- do { i += 1; if (i == 20) { break; } } while (i < 30)
+ do { i += 1; if i == 20 { break; } } while i < 30
assert (i == 20);
- for (int x in [1, 2, 3, 4, 5, 6]) {
- if (x == 3) { break; }
+ for x: int in [1, 2, 3, 4, 5, 6] {
+ if x == 3 { break; }
assert (x <= 3);
}
i = 0;
- while (i < 10) { i += 1; if (i % 2 == 0) { cont; } assert (i % 2 != 0); }
+ while i < 10 { i += 1; if i % 2 == 0 { cont; } assert (i % 2 != 0); }
i = 0;
- do { i += 1; if (i % 2 == 0) { cont; } assert (i % 2 != 0); } while
- (i < 10)
- for (int x in [1, 2, 3, 4, 5, 6]) {
- if (x % 2 == 0) { cont; }
+ do { i += 1; if i % 2 == 0 { cont; } assert (i % 2 != 0); } while i < 10
+ for x: int in [1, 2, 3, 4, 5, 6] {
+ if x % 2 == 0 { cont; }
assert (x % 2 != 0);
}
}
\ No newline at end of file
diff --git a/src/test/run-pass/call-autoderef-tag.rs b/src/test/run-pass/call-autoderef-tag.rs
index 3826b9a..d185ed0 100644
--- a/src/test/run-pass/call-autoderef-tag.rs
+++ b/src/test/run-pass/call-autoderef-tag.rs
@@ -1,11 +1,11 @@
// xfail-stage0
-tag int_fn { f(fn(int) -> int); }
-tag int_box_fn { fb(@fn(int) -> int); }
-fn add1(int i) -> int { ret i+1; }
+tag int_fn { f(fn(int) -> int ); }
+tag int_box_fn { fb(@fn(int) -> int ); }
+fn add1(i: int) -> int { ret i + 1; }
fn main() {
- auto g = f(add1);
- assert(g(4) == 5);
- assert((f(add1))(5) == 6);
- assert((@(f(add1)))(5) == 6);
- assert((fb(@add1))(7) == 8);
-}
+ let g = f(add1);
+ assert (g(4) == 5);
+ assert (f(add1)(5) == 6);
+ assert ((@f(add1))(5) == 6);
+ assert (fb(@add1)(7) == 8);
+}
\ No newline at end of file
diff --git a/src/test/run-pass/cast.rs b/src/test/run-pass/cast.rs
index 276fa42..38a4ca7 100644
--- a/src/test/run-pass/cast.rs
+++ b/src/test/run-pass/cast.rs
@@ -3,9 +3,9 @@
// -*- rust -*-
fn main() {
- let int i = 'Q' as int;
+ let i: int = 'Q' as int;
assert (i == 0x51);
- let u32 u = i as u32;
+ let u: u32 = i as u32;
assert (u == 0x51 as u32);
assert (u == 'Q' as u32);
assert (i as u8 == 'Q' as u8);
diff --git a/src/test/run-pass/char.rs b/src/test/run-pass/char.rs
index d27e89c..8383a3d 100644
--- a/src/test/run-pass/char.rs
+++ b/src/test/run-pass/char.rs
@@ -1,8 +1,8 @@
fn main() {
- let char c = 'x';
- let char d = 'x';
+ let c: char = 'x';
+ let d: char = 'x';
assert (c == 'x');
assert ('x' == c);
assert (c == c);
diff --git a/src/test/run-pass/child-outlives-parent.rs b/src/test/run-pass/child-outlives-parent.rs
index 4bf03ea..44a4194 100644
--- a/src/test/run-pass/child-outlives-parent.rs
+++ b/src/test/run-pass/child-outlives-parent.rs
@@ -1,5 +1,5 @@
// xfail-stage0
// Reported as issue #126, child leaks the string.
-fn child2(str s) { }
+fn child2(s: str) { }
-fn main() { auto x = spawn child2("hi"); }
+fn main() { let x = spawn child2("hi"); }
\ No newline at end of file
diff --git a/src/test/run-pass/claim-nonterm.rs b/src/test/run-pass/claim-nonterm.rs
index 17dd6ec..311da33 100644
--- a/src/test/run-pass/claim-nonterm.rs
+++ b/src/test/run-pass/claim-nonterm.rs
@@ -5,11 +5,6 @@
import std::str::*;
import std::uint::*;
-pred fails(uint a) -> bool {
- fail;
-}
+pred fails(a: uint) -> bool { fail; }
-fn main() {
- let uint b = 4u;
- claim fails(b);
-}
\ No newline at end of file
+fn main() { let b: uint = 4u; claim (fails(b)); }
\ No newline at end of file
diff --git a/src/test/run-pass/clone-with-exterior.rs b/src/test/run-pass/clone-with-exterior.rs
index 01ffc09..27d3848 100644
--- a/src/test/run-pass/clone-with-exterior.rs
+++ b/src/test/run-pass/clone-with-exterior.rs
@@ -1,14 +1,6 @@
-// xfail-stage0
-// xfail-stage1
-// xfail-stage2
-// xfail-stage3
-fn f(@rec(int a, int b) x) {
- assert (x.a == 10);
- assert (x.b == 12);
-}
-
-fn main() {
- let @rec(int a, int b) z = rec(a=10, b=12);
- let task p = spawn thread f(z);
- join p;
-}
\ No newline at end of file
+./src/test/run-pass/clone-with-exterior.rs:12:28:12:29: [1;31merror:[0m expecting (, found f
+./src/test/run-pass/clone-with-exterior.rs:12 let task p = spawn thread f(z);
+ ^
+rt: ---
+rt: f00e:main:main: upcall fail 'explicit failure', src/comp/syntax/parse/parser.rs:112
+rt: f00e:main: domain main @0x8f2504c root task failed
diff --git a/src/test/run-pass/comm.rs b/src/test/run-pass/comm.rs
index 1e2dd5a..5f13a58 100644
--- a/src/test/run-pass/comm.rs
+++ b/src/test/run-pass/comm.rs
@@ -2,17 +2,13 @@
// -*- rust -*-
fn main() {
- let port[int] p = port();
- let task t = spawn child(chan(p));
- let int y;
- p |> y;
- log_err "received";
- log_err y;
- assert (y == 10);
+ let p: port[int] = port();
+ let t: task = spawn child(chan(p));
+ let y: int;
+ p |> y;
+ log_err "received";
+ log_err y;
+ assert (y == 10);
}
-fn child(chan[int] c) {
- log_err "sending";
- c <| 10;
- log_err "value sent"
-}
+fn child(c: chan[int]) { log_err "sending"; c <| 10; log_err "value sent" }
\ No newline at end of file
diff --git a/src/test/run-pass/command-line-args.rs b/src/test/run-pass/command-line-args.rs
index 9a2ebce..af42cbd 100644
--- a/src/test/run-pass/command-line-args.rs
+++ b/src/test/run-pass/command-line-args.rs
@@ -1,3 +1,3 @@
-fn main(vec[str] args) { log args.(0); }
\ No newline at end of file
+fn main(args: vec[str]) { log args.(0); }
\ No newline at end of file
diff --git a/src/test/run-pass/complex.rs b/src/test/run-pass/complex.rs
index 2f4f09b..cc5d8d3 100644
--- a/src/test/run-pass/complex.rs
+++ b/src/test/run-pass/complex.rs
@@ -6,23 +6,23 @@
fn nothing() { }
-fn putstr(str s) { }
+fn putstr(s: str) { }
-fn putint(int i) {
- let int i = 33;
- while (i < 36) { putstr("hi"); i = i + 1; }
+fn putint(i: int) {
+ let i: int = 33;
+ while i < 36 { putstr("hi"); i = i + 1; }
}
-fn zerg(int i) -> int { ret i; }
+fn zerg(i: int) -> int { ret i; }
-fn foo(int x) -> int {
- let t y = x + 2;
+fn foo(x: int) -> int {
+ let y: t = x + 2;
putstr("hello");
- while (y < 10) { putint(y); if (y * 3 == 4) { y = y + 2; nothing(); } }
- let t z;
+ while y < 10 { putint(y); if y * 3 == 4 { y = y + 2; nothing(); } }
+ let z: t;
z = 0x55;
foo(z);
ret 0;
}
-fn main() { let int x = 2 + 2; log x; log "hello, world"; log 10; }
\ No newline at end of file
+fn main() { let x: int = 2 + 2; log x; log "hello, world"; log 10; }
\ No newline at end of file
diff --git a/src/test/run-pass/conditional-compile.rs b/src/test/run-pass/conditional-compile.rs
index 2dbf922..34ebd11 100644
--- a/src/test/run-pass/conditional-compile.rs
+++ b/src/test/run-pass/conditional-compile.rs
@@ -1,19 +1,18 @@
// xfail-stage0
#[cfg(bogus)]
-const bool b = false;
+const b: bool = false;
-const bool b = true;
+const b: bool = true;
#[cfg(bogus)]
native "rust" mod rustrt {
- // This symbol doesn't exist and would be a link error if this
- // module was translated
- fn bogus();
+ // This symbol doesn't exist and would be a link error if this
+ // module was translated
+ fn bogus();
}
-native "rust" mod rustrt {
-}
+native "rust" mod rustrt { }
#[cfg(bogus)]
type t = int;
@@ -21,42 +20,37 @@
type t = bool;
#[cfg(bogus)]
-tag tg {
- foo;
-}
+tag tg { foo; }
-tag tg {
- bar;
-}
+tag tg { bar; }
#[cfg(bogus)]
obj o() {
- fn f() { ret bogus; }
+ fn f() { ret bogus; }
}
-obj o() {
-}
+obj o() { }
#[cfg(bogus)]
-resource r(int i) {}
+resource r(i: int) { }
-resource r(int i) {}
+resource r(i: int) { }
#[cfg(bogus)]
mod m {
- // This needs to parse but would fail in typeck. Since it's not in
- // the current config it should not be typechecked.
- fn bogus() { ret 0; }
+ // This needs to parse but would fail in typeck. Since it's not in
+ // the current config it should not be typechecked.
+ fn bogus() { ret 0; }
}
mod m {
- // Submodules have slightly different code paths than the top-level
- // module, so let's make sure this jazz works here as well
- #[cfg(bogus)]
- fn f() {}
+ // Submodules have slightly different code paths than the top-level
+ // module, so let's make sure this jazz works here as well
+ #[cfg(bogus)]
+ fn f() { }
- fn f() {}
+ fn f() { }
}
// Since the bogus configuration isn't defined main will just be
@@ -65,31 +59,31 @@
fn main() { fail }
fn main() {
- // Exercise some of the configured items in ways that wouldn't be possible
- // if they had the bogus definition
- assert b;
- let t x = true;
- let tg y = bar;
+ // Exercise some of the configured items in ways that wouldn't be possible
+ // if they had the bogus definition
+ assert (b);
+ let x: t = true;
+ let y: tg = bar;
- test_in_fn_ctxt();
+ test_in_fn_ctxt();
}
fn test_in_fn_ctxt() {
- #[cfg(bogus)]
- fn f() { fail }
- fn f() {}
- f();
+ #[cfg(bogus)]
+ fn f() { fail }
+ fn f() { }
+ f();
- #[cfg(bogus)]
- const int i = 0;
- const int i = 1;
- assert i == 1;
+ #[cfg(bogus)]
+ const i: int = 0;
+ const i: int = 1;
+ assert (i == 1);
}
mod test_native_items {
- native "rust" mod rustrt {
- #[cfg(bogus)]
- fn str_vec(str s) -> vec[u8];
- fn str_vec(str s) -> vec[u8];
- }
+ native "rust" mod rustrt {
+ #[cfg(bogus)]
+ fn str_vec(s: str) -> vec[u8];
+ fn str_vec(s: str) -> vec[u8];
+ }
}
\ No newline at end of file
diff --git a/src/test/run-pass/const.rs b/src/test/run-pass/const.rs
index 659c47c..d181c49 100644
--- a/src/test/run-pass/const.rs
+++ b/src/test/run-pass/const.rs
@@ -1,5 +1,5 @@
-const int i = 10;
+const i: int = 10;
fn main() { log i; }
\ No newline at end of file
diff --git a/src/test/run-pass/constrained-type.rs b/src/test/run-pass/constrained-type.rs
index d3003e8..4383116 100644
--- a/src/test/run-pass/constrained-type.rs
+++ b/src/test/run-pass/constrained-type.rs
@@ -1,16 +1,12 @@
// xfail-stage0
// -*- rust -*-
-tag list {
- cons(int,@list);
- nil();
-}
+tag list { cons(int, @list); nil; }
-type bubu = rec(int x, int y);
+type bubu = {x: int, y: int};
-pred less_than(int x, int y) -> bool { ret x < y; }
+pred less_than(x: int, y: int) -> bool { ret x < y; }
-type ordered_range = rec(int low, int high) : less_than(*.low, *.high);
+type ordered_range = {low: int, high: int} : : less_than(low, high);
-fn main() {
-}
+fn main() { }
\ No newline at end of file
diff --git a/src/test/run-pass/constraint-prop-expr-move.rs b/src/test/run-pass/constraint-prop-expr-move.rs
index 646e500..616c180 100644
--- a/src/test/run-pass/constraint-prop-expr-move.rs
+++ b/src/test/run-pass/constraint-prop-expr-move.rs
@@ -4,10 +4,10 @@
import std::uint::*;
fn main() {
- let uint a = 1u;
- let uint b = 4u;
- let uint c = 17u;
- check le(a, b);
- c <- a;
- log (safe_slice("kitties", c, b));
+ let a: uint = 1u;
+ let b: uint = 4u;
+ let c: uint = 17u;
+ check (le(a, b));
+ c <- a;
+ log safe_slice("kitties", c, b);
}
\ No newline at end of file
diff --git a/src/test/run-pass/constraint-prop-move.rs b/src/test/run-pass/constraint-prop-move.rs
index 9f3a901..e939e12 100644
--- a/src/test/run-pass/constraint-prop-move.rs
+++ b/src/test/run-pass/constraint-prop-move.rs
@@ -4,9 +4,9 @@
import std::uint::*;
fn main() {
- let uint a = 1u;
- let uint b = 4u;
- check le(a, b);
- auto c <- a;
- log (safe_slice("kitties", c, b));
+ let a: uint = 1u;
+ let b: uint = 4u;
+ check (le(a, b));
+ let c <- a;
+ log safe_slice("kitties", c, b);
}
\ No newline at end of file
diff --git a/src/test/run-pass/constraint-prop-swap.rs b/src/test/run-pass/constraint-prop-swap.rs
index 324d0a0..89a76f5 100644
--- a/src/test/run-pass/constraint-prop-swap.rs
+++ b/src/test/run-pass/constraint-prop-swap.rs
@@ -4,9 +4,9 @@
import std::uint::*;
fn main() {
- let uint a = 4u;
- let uint b = 1u;
- check le(b, a);
- b <-> a;
- log (safe_slice("kitties", a, b));
+ let a: uint = 4u;
+ let b: uint = 1u;
+ check (le(b, a));
+ b <-> a;
+ log safe_slice("kitties", a, b);
}
\ No newline at end of file
diff --git a/src/test/run-pass/constraint-prop.rs b/src/test/run-pass/constraint-prop.rs
index 69221ed..d63f48a 100644
--- a/src/test/run-pass/constraint-prop.rs
+++ b/src/test/run-pass/constraint-prop.rs
@@ -4,9 +4,9 @@
import std::uint::*;
fn main() {
- let uint a = 1u;
- let uint b = 4u;
- check le(a, b);
- auto c = b;
- log (safe_slice("kitties", a, c));
+ let a: uint = 1u;
+ let b: uint = 4u;
+ check (le(a, b));
+ let c = b;
+ log safe_slice("kitties", a, c);
}
\ No newline at end of file
diff --git a/src/test/run-pass/crate-attributes-src/foo.rs b/src/test/run-pass/crate-attributes-src/foo.rs
index 5ab36df..7decb51 100644
--- a/src/test/run-pass/crate-attributes-src/foo.rs
+++ b/src/test/run-pass/crate-attributes-src/foo.rs
@@ -5,4 +5,4 @@
// Attributes of the following function
#[attr1 = "val"]
#[attr2 = "val"]
-fn main() { }
+fn main() { }
\ No newline at end of file
diff --git a/src/test/run-pass/dead-code-one-arm-if.rs b/src/test/run-pass/dead-code-one-arm-if.rs
index 3192328..456d8bf 100644
--- a/src/test/run-pass/dead-code-one-arm-if.rs
+++ b/src/test/run-pass/dead-code-one-arm-if.rs
@@ -2,4 +2,4 @@
// -*- rust -*-
-fn main() { if (1 == 1) { ret; } log "Paul is dead"; }
\ No newline at end of file
+fn main() { if 1 == 1 { ret; } log "Paul is dead"; }
\ No newline at end of file
diff --git a/src/test/run-pass/decl-with-recv.rs b/src/test/run-pass/decl-with-recv.rs
index 6bd175d..6f24675 100644
--- a/src/test/run-pass/decl-with-recv.rs
+++ b/src/test/run-pass/decl-with-recv.rs
@@ -3,14 +3,14 @@
// -*- rust -*-
fn main() {
- let port[int] po = port();
- let chan[int] ch = chan(po);
+ let po: port[int] = port();
+ let ch: chan[int] = chan(po);
ch <| 10;
- let int i;
+ let i: int;
po |> i;
assert (i == 10);
ch <| 11;
- auto j;
+ let j;
po |> j;
assert (j == 11);
}
\ No newline at end of file
diff --git a/src/test/run-pass/deep.rs b/src/test/run-pass/deep.rs
index db5fe4b..c229ff9 100644
--- a/src/test/run-pass/deep.rs
+++ b/src/test/run-pass/deep.rs
@@ -2,8 +2,8 @@
// -*- rust -*-
-fn f(int x) -> int {
- if (x == 1) { ret 1; } else { let int y = 1 + f(x - 1); ret y; }
+fn f(x: int) -> int {
+ if x == 1 { ret 1; } else { let y: int = 1 + f(x - 1); ret y; }
}
fn main() { assert (f(5000) == 5000); }
\ No newline at end of file
diff --git a/src/test/run-pass/deref-lval.rs b/src/test/run-pass/deref-lval.rs
index f293c21..ba5149a 100644
--- a/src/test/run-pass/deref-lval.rs
+++ b/src/test/run-pass/deref-lval.rs
@@ -1,3 +1,3 @@
-fn main() { auto x = @mutable 5; *x = 1000; log *x; }
\ No newline at end of file
+fn main() { let x = @mutable 5; *x = 1000; log *x; }
\ No newline at end of file
diff --git a/src/test/run-pass/deref.rs b/src/test/run-pass/deref.rs
index 2836e52..71dcfeb 100644
--- a/src/test/run-pass/deref.rs
+++ b/src/test/run-pass/deref.rs
@@ -1,3 +1,3 @@
-fn main() { let @int x = @10; let int y = *x; }
\ No newline at end of file
+fn main() { let x: @int = @10; let y: int = *x; }
\ No newline at end of file
diff --git a/src/test/run-pass/destructor-ordering.rs b/src/test/run-pass/destructor-ordering.rs
index ae504a7..aadde39 100644
--- a/src/test/run-pass/destructor-ordering.rs
+++ b/src/test/run-pass/destructor-ordering.rs
@@ -1,123 +1,6 @@
-// xfail-stage0
-// xfail-stage1
-// xfail-stage2
-// xfail-stage3
-// This test checks that destructors run in the right order. Because
-// stateful objects can't have destructors, we have the destructors
-// record their expected order into a channel when they execute (so
-// the object becomes 'io' rather than 'state'). Then each test case
-// asserts that the channel produces values in ascending order.
-//
-// FIXME: Write an int->str function and concatenate the whole failure
-// message into a single log statement (or, even better, a print).
-//
-// FIXME: check_order should take only 1 line in a test, not 2+a block
-// block. Since destructor-having objects can't refer to mutable state
-// (like the port), we'd need a with-like construct to do the same for
-// stateful objects within a scope.
-//
-// FIXME #21: Each test should execute in its own task, so it can fail
-// independently, writing its error message to a channel that the
-// parent task aggregates.
-
-type order_info = rec(int order, str msg);
-
-io fn check_order(port[order_info] expected_p) {
- chan(expected_p) <| rec(order=-1, msg="");
- let mutable int actual = 0;
- // FIXME #121: Workaround for while(true) bug.
- auto expected; expected_p |> expected;
- auto done = -1; // FIXME: Workaround for typechecking bug.
- while(expected.order != done) {
- if (expected.order != actual) {
- log expected.order;
- log " != ";
- log actual;
- log expected.msg;
- fail;
- }
- actual += 1;
- expected_p |> expected;
- }
-}
-
-
-obj dorder(chan[order_info] expected, int order, str message) {
- drop {
- expected <| rec(order=order, msg=message);
- }
-}
-
-io fn test_simple() {
- let port[order_info] tracker_p = port();
- auto tracker = chan(tracker_p);
- dorder(tracker, 1, "Reverse decl order");
- dorder(tracker, 0, "Reverse decl order");
- check_order(tracker_p);
-}
-
-io fn test_block() {
- let port[order_info] tracker_p = port();
- auto tracker = chan(tracker_p);
- {
- dorder(tracker, 2, "Before block");
- {
- dorder(tracker, 0, "Inside block");
- }
- dorder(tracker, 1, "After block");
- }
- check_order(tracker_p);
-}
-
-io fn test_decl_v_init() {
- let port[order_info] tracker_p = port();
- auto tracker = chan(tracker_p);
- {
- auto var1;
- auto var2;
- var2 = dorder(tracker, 0, "decl, not init");
- var1 = dorder(tracker, 1, "decl, not init");
- }
- check_order(tracker_p);
-}
-
-io fn test_overwritten_obj() {
- let port[order_info] tracker_p = port();
- auto tracker = chan(tracker_p);
- {
- auto var1 = dorder(tracker, 0, "overwritten object destroyed first");
- auto var2 = dorder(tracker, 2, "destroyed at end of scope");
- var1 = dorder(tracker, 3, "overwriter deleted in rev decl order");
- {
- dorder(tracker, 1, "overwritten object destroyed before end of scope");
- }
- }
- check_order(tracker_p);
-}
-
-// Used to embed dorder objects into an expression. Note that the
-// parameters don't get destroyed.
-fn combine_dorders(dorder d1, dorder d2) -> int {
- ret 1;
-}
-io fn test_expression_destroyed_right_to_left() {
- let port[order_info] tracker_p = port();
- auto tracker = chan(tracker_p);
- {
- combine_dorders(dorder(tracker, 4, ""), dorder(tracker, 3, ""))
- / combine_dorders(dorder(tracker, 2, ""), dorder(tracker, 1, ""));
- {
- dorder(tracker, 0,
- "expression objects live to end of block, not statement");
- }
- }
- check_order(tracker_p);
-}
-
-io fn main() {
- test_simple();
- test_block();
- test_decl_v_init();
- test_overwritten_obj();
- test_expression_destroyed_right_to_left();
-}
+./src/test/run-pass/destructor-ordering.rs:25:0:25:2: [1;31merror:[0m expected item but found io
+./src/test/run-pass/destructor-ordering.rs:25 io fn check_order(port[order_info] expected_p) {
+ ^~
+rt: ---
+rt: 17b9:main:main: upcall fail 'explicit failure', src/comp/syntax/parse/parser.rs:112
+rt: 17b9:main: domain main @0x96d304c root task failed
diff --git a/src/test/run-pass/div-mod.rs b/src/test/run-pass/div-mod.rs
index 3fc875d..38a5bab 100644
--- a/src/test/run-pass/div-mod.rs
+++ b/src/test/run-pass/div-mod.rs
@@ -3,8 +3,8 @@
// -*- rust -*-
fn main() {
- let int x = 15;
- let int y = 5;
+ let x: int = 15;
+ let y: int = 5;
assert (x / 5 == 3);
assert (x / 4 == 3);
assert (x / 3 == 5);
diff --git a/src/test/run-pass/double-unbox.rs b/src/test/run-pass/double-unbox.rs
index 19f3ed3..32ecfa6 100644
--- a/src/test/run-pass/double-unbox.rs
+++ b/src/test/run-pass/double-unbox.rs
@@ -1,8 +1,6 @@
-type quux = rec(int bar);
+type quux = {bar: int};
-fn g(&int i) { }
-fn f(@@quux foo) {
- g(foo.bar);
-}
+fn g(i: &int) { }
+fn f(foo: @@quux) { g(foo.bar); }
-fn main() {}
+fn main() { }
\ No newline at end of file
diff --git a/src/test/run-pass/drop-bind-thunk-args.rs b/src/test/run-pass/drop-bind-thunk-args.rs
index b28b4e3..d5eddb7 100644
--- a/src/test/run-pass/drop-bind-thunk-args.rs
+++ b/src/test/run-pass/drop-bind-thunk-args.rs
@@ -1,5 +1,5 @@
-fn f(@int x) { }
+fn f(x: @int) { }
-fn main() { auto x = @10; auto ff = bind f(_); ff(x); ff(x); }
\ No newline at end of file
+fn main() { let x = @10; let ff = bind f(_); ff(x); ff(x); }
\ No newline at end of file
diff --git a/src/test/run-pass/drop-on-empty-block-exit.rs b/src/test/run-pass/drop-on-empty-block-exit.rs
index 5096aee..2a4f093 100644
--- a/src/test/run-pass/drop-on-empty-block-exit.rs
+++ b/src/test/run-pass/drop-on-empty-block-exit.rs
@@ -2,4 +2,4 @@
tag t { foo(@int); }
-fn main() { auto tt = foo(@10); alt (tt) { case (foo(?z)) { } } }
\ No newline at end of file
+fn main() { let tt = foo(@10); alt tt { foo(z) { } } }
\ No newline at end of file
diff --git a/src/test/run-pass/drop-on-ret.rs b/src/test/run-pass/drop-on-ret.rs
index 705654a..f1da1a3 100644
--- a/src/test/run-pass/drop-on-ret.rs
+++ b/src/test/run-pass/drop-on-ret.rs
@@ -2,6 +2,6 @@
// -*- rust -*-
-fn f() -> int { if (true) { let str s = "should not leak"; ret 1; } ret 0; }
+fn f() -> int { if true { let s: str = "should not leak"; ret 1; } ret 0; }
fn main() { f(); }
\ No newline at end of file
diff --git a/src/test/run-pass/drop-parametric-closure-with-bound-box.rs b/src/test/run-pass/drop-parametric-closure-with-bound-box.rs
index 0085b51..06bb931 100644
--- a/src/test/run-pass/drop-parametric-closure-with-bound-box.rs
+++ b/src/test/run-pass/drop-parametric-closure-with-bound-box.rs
@@ -1,5 +1,5 @@
-fn f[T](@int i, &T t) { }
+fn f[T](i: @int, t: &T) { }
-fn main() { auto x = bind f[char](@0xdeafbeef, _); }
\ No newline at end of file
+fn main() { let x = bind f[char](@0xdeafbeef, _); }
\ No newline at end of file
diff --git a/src/test/run-pass/else-if.rs b/src/test/run-pass/else-if.rs
index 3d8c9fb..cf13a53 100644
--- a/src/test/run-pass/else-if.rs
+++ b/src/test/run-pass/else-if.rs
@@ -1,20 +1,20 @@
fn main() {
- if (1 == 2) {
+ if 1 == 2 {
assert (false);
} else if (2 == 3) {
assert (false);
} else if (3 == 4) { assert (false); } else { assert (true); }
- if (1 == 2) { assert (false); } else if (2 == 2) { assert (true); }
- if (1 == 2) {
+ if 1 == 2 { assert (false); } else if (2 == 2) { assert (true); }
+ if 1 == 2 {
assert (false);
} else if (2 == 2) {
- if (1 == 1) {
+ if 1 == 1 {
assert (true);
- } else { if (2 == 1) { assert (false); } else { assert (false); } }
+ } else { if 2 == 1 { assert (false); } else { assert (false); } }
}
- if (1 == 2) {
+ if 1 == 2 {
assert (false);
- } else { if (1 == 2) { assert (false); } else { assert (true); } }
+ } else { if 1 == 2 { assert (false); } else { assert (true); } }
}
\ No newline at end of file
diff --git a/src/test/run-pass/empty-mutable-vec.rs b/src/test/run-pass/empty-mutable-vec.rs
index eaa2de30..f79ab0a 100644
--- a/src/test/run-pass/empty-mutable-vec.rs
+++ b/src/test/run-pass/empty-mutable-vec.rs
@@ -1,3 +1,3 @@
-fn main() { let vec[mutable int] v = [mutable ]; }
\ No newline at end of file
+fn main() { let v: vec[mutable int] = [mutable ]; }
\ No newline at end of file
diff --git a/src/test/run-pass/export-abstract-tag.rs b/src/test/run-pass/export-abstract-tag.rs
index 7e48863..7ef167c 100644
--- a/src/test/run-pass/export-abstract-tag.rs
+++ b/src/test/run-pass/export-abstract-tag.rs
@@ -2,18 +2,12 @@
// sort of ADT.
mod foo {
- export t;
- export f;
+ export t;
+ export f;
- tag t {
- t1;
- }
+ tag t { t1; }
- fn f() -> t {
- ret t1;
- }
+ fn f() -> t { ret t1; }
}
-fn main() {
- let foo::t v = foo::f();
-}
+fn main() { let v: foo::t = foo::f(); }
\ No newline at end of file
diff --git a/src/test/run-pass/export-non-interference2.rs b/src/test/run-pass/export-non-interference2.rs
index 533df52..b9ffd8e 100644
--- a/src/test/run-pass/export-non-interference2.rs
+++ b/src/test/run-pass/export-non-interference2.rs
@@ -1,18 +1,12 @@
mod foo {
- export bar;
+ export bar;
- mod bar {
- fn y() {
- x();
+ mod bar {
+ fn y() { x(); }
}
- }
- fn x() {
- log "x";
- }
+ fn x() { log "x"; }
}
-fn main() {
- foo::bar::y();
-}
+fn main() { foo::bar::y(); }
\ No newline at end of file
diff --git a/src/test/run-pass/export-non-interference3.rs b/src/test/run-pass/export-non-interference3.rs
index 7b936b63..bfb7345 100644
--- a/src/test/run-pass/export-non-interference3.rs
+++ b/src/test/run-pass/export-non-interference3.rs
@@ -1,19 +1,13 @@
mod foo {
- export x;
+ export x;
- fn x() {
- bar::x();
- }
+ fn x() { bar::x(); }
}
mod bar {
- export x;
+ export x;
- fn x() {
- log "x";
- }
+ fn x() { log "x"; }
}
-fn main() {
- foo::x();
-}
+fn main() { foo::x(); }
\ No newline at end of file
diff --git a/src/test/run-pass/export-tag-variant.rs b/src/test/run-pass/export-tag-variant.rs
index 309261a..f7599d0 100644
--- a/src/test/run-pass/export-tag-variant.rs
+++ b/src/test/run-pass/export-tag-variant.rs
@@ -1,12 +1,8 @@
// Export the tag variants, without the tag
mod foo {
- export t1;
- tag t {
- t1;
- }
+ export t1;
+ tag t { t1; }
}
-fn main() {
- auto v = foo::t1;
-}
+fn main() { let v = foo::t1; }
\ No newline at end of file
diff --git a/src/test/run-pass/export-unexported-dep.rs b/src/test/run-pass/export-unexported-dep.rs
index dcb88af..8f1d54e 100644
--- a/src/test/run-pass/export-unexported-dep.rs
+++ b/src/test/run-pass/export-unexported-dep.rs
@@ -2,23 +2,15 @@
// that are not exported, allowing for a sort of poor-man's ADT
mod foo {
- export f;
- export g;
+ export f;
+ export g;
- // not exported
- tag t {
- t1;
- }
+ // not exported
+ tag t { t1; }
- fn f() -> t {
- ret t1;
- }
+ fn f() -> t { ret t1; }
- fn g(t v) {
- assert v == t1;
- }
+ fn g(v: t) { assert (v == t1); }
}
-fn main() {
- foo::g(foo::f());
-}
\ No newline at end of file
+fn main() { foo::g(foo::f()); }
\ No newline at end of file
diff --git a/src/test/run-pass/expr-alt-box.rs b/src/test/run-pass/expr-alt-box.rs
index 52868f4..a397874 100644
--- a/src/test/run-pass/expr-alt-box.rs
+++ b/src/test/run-pass/expr-alt-box.rs
@@ -4,13 +4,10 @@
// -*- rust -*-
// Tests for alt as expressions resulting in boxed types
-fn test_box() {
- auto res = alt (true) { case (true) { @100 } };
- assert (*res == 100);
-}
+fn test_box() { let res = alt true { true { @100 } }; assert (*res == 100); }
fn test_str() {
- auto res = alt (true) { case (true) { "happy" } };
+ let res = alt true { true { "happy" } };
assert (res == "happy");
}
diff --git a/src/test/run-pass/expr-alt-fail-all.rs b/src/test/run-pass/expr-alt-fail-all.rs
index d17105b..55f4e69 100644
--- a/src/test/run-pass/expr-alt-fail-all.rs
+++ b/src/test/run-pass/expr-alt-fail-all.rs
@@ -4,11 +4,9 @@
// When all branches of an alt expression result in fail, the entire
// alt expression results in fail.
fn main() {
- auto x =
- alt (true) {
- case (true) { 10 }
- case (false) {
- alt (true) { case (true) { fail } case (false) { fail } }
- }
+ let x =
+ alt true {
+ true { 10 }
+ false { alt true { true { fail } false { fail } } }
};
}
\ No newline at end of file
diff --git a/src/test/run-pass/expr-alt-fail.rs b/src/test/run-pass/expr-alt-fail.rs
index a956ac2..bc79663 100644
--- a/src/test/run-pass/expr-alt-fail.rs
+++ b/src/test/run-pass/expr-alt-fail.rs
@@ -3,12 +3,12 @@
// xfail-stage0
fn test_simple() {
- auto r = alt (true) { case (true) { true } case (false) { fail } };
+ let r = alt true { true { true } false { fail } };
assert (r == true);
}
fn test_box() {
- auto r = alt (true) { case (true) { [10] } case (false) { fail } };
+ let r = alt true { true { [10] } false { fail } };
assert (r.(0) == 10);
}
diff --git a/src/test/run-pass/expr-alt-generic-box1.rs b/src/test/run-pass/expr-alt-generic-box1.rs
index ea9403d..e4d560d 100644
--- a/src/test/run-pass/expr-alt-generic-box1.rs
+++ b/src/test/run-pass/expr-alt-generic-box1.rs
@@ -4,14 +4,14 @@
// -*- rust -*-
type compare[T] = fn(@T, @T) -> bool ;
-fn test_generic[T](@T expected, &compare[T] eq) {
- let @T actual = alt (true) { case (true) { expected } };
+fn test_generic[T](expected: @T, eq: &compare[T]) {
+ let actual: @T = alt true { true { expected } };
assert (eq(expected, actual));
}
fn test_box() {
- fn compare_box(@bool b1, @bool b2) -> bool { ret *b1 == *b2; }
- auto eq = bind compare_box(_, _);
+ fn compare_box(b1: @bool, b2: @bool) -> bool { ret *b1 == *b2; }
+ let eq = bind compare_box(_, _);
test_generic[bool](@true, eq);
}
diff --git a/src/test/run-pass/expr-alt-generic-box2.rs b/src/test/run-pass/expr-alt-generic-box2.rs
index 022ea63..3d905f8 100644
--- a/src/test/run-pass/expr-alt-generic-box2.rs
+++ b/src/test/run-pass/expr-alt-generic-box2.rs
@@ -4,14 +4,14 @@
// -*- rust -*-
type compare[T] = fn(&T, &T) -> bool ;
-fn test_generic[T](&T expected, &compare[T] eq) {
- let T actual = alt (true) { case (true) { expected } };
+fn test_generic[T](expected: &T, eq: &compare[T]) {
+ let actual: T = alt true { true { expected } };
assert (eq(expected, actual));
}
fn test_vec() {
- fn compare_vec(&vec[int] v1, &vec[int] v2) -> bool { ret v1 == v2; }
- auto eq = bind compare_vec(_, _);
+ fn compare_vec(v1: &vec[int], v2: &vec[int]) -> bool { ret v1 == v2; }
+ let eq = bind compare_vec(_, _);
test_generic[vec[int]]([1, 2, 3], eq);
}
diff --git a/src/test/run-pass/expr-alt-generic.rs b/src/test/run-pass/expr-alt-generic.rs
index 6c34337..33979e9 100644
--- a/src/test/run-pass/expr-alt-generic.rs
+++ b/src/test/run-pass/expr-alt-generic.rs
@@ -4,23 +4,23 @@
// -*- rust -*-
type compare[T] = fn(&T, &T) -> bool ;
-fn test_generic[T](&T expected, &compare[T] eq) {
- let T actual = alt (true) { case (true) { expected } };
+fn test_generic[T](expected: &T, eq: &compare[T]) {
+ let actual: T = alt true { true { expected } };
assert (eq(expected, actual));
}
fn test_bool() {
- fn compare_bool(&bool b1, &bool b2) -> bool { ret b1 == b2; }
- auto eq = bind compare_bool(_, _);
+ fn compare_bool(b1: &bool, b2: &bool) -> bool { ret b1 == b2; }
+ let eq = bind compare_bool(_, _);
test_generic[bool](true, eq);
}
fn test_rec() {
- type t = rec(int a, int b);
+ type t = {a: int, b: int};
- fn compare_rec(&t t1, &t t2) -> bool { ret t1 == t2; }
- auto eq = bind compare_rec(_, _);
- test_generic[t](rec(a=1, b=2), eq);
+ fn compare_rec(t1: &t, t2: &t) -> bool { ret t1 == t2; }
+ let eq = bind compare_rec(_, _);
+ test_generic[t]({a: 1, b: 2}, eq);
}
fn main() { test_bool(); test_rec(); }
\ No newline at end of file
diff --git a/src/test/run-pass/expr-alt-struct.rs b/src/test/run-pass/expr-alt-struct.rs
index ae318c5..51ef9e0 100644
--- a/src/test/run-pass/expr-alt-struct.rs
+++ b/src/test/run-pass/expr-alt-struct.rs
@@ -5,13 +5,13 @@
// Tests for alt as expressions resulting in structural types
fn test_rec() {
- auto rs = alt (true) { case (true) { rec(i=100) } };
- assert (rs == rec(i=100));
+ let rs = alt true { true { {i: 100} } };
+ assert (rs == {i: 100});
}
fn test_tag() {
tag mood { happy; sad; }
- auto rs = alt (true) { case (true) { happy } case (false) { sad } };
+ let rs = alt true { true { happy } false { sad } };
assert (rs == happy);
}
diff --git a/src/test/run-pass/expr-alt.rs b/src/test/run-pass/expr-alt.rs
index a401e2d..8d4ddd2 100644
--- a/src/test/run-pass/expr-alt.rs
+++ b/src/test/run-pass/expr-alt.rs
@@ -5,35 +5,33 @@
// Tests for using alt as an expression
fn test_basic() {
- let bool rs = alt (true) { case (true) { true } case (false) { false } };
+ let rs: bool = alt true { true { true } false { false } };
assert (rs);
- rs = alt (false) { case (true) { false } case (false) { true } };
+ rs = alt false { true { false } false { true } };
assert (rs);
}
fn test_inferrence() {
- auto rs = alt (true) { case (true) { true } case (false) { false } };
+ let rs = alt true { true { true } false { false } };
assert (rs);
}
fn test_alt_as_alt_head() {
// Yeah, this is kind of confusing ...
- auto rs =
- alt (alt (false) { case (true) { true } case (false) { false } }) {
- case (true) { false }
- case (false) { true }
+ let rs =
+ alt alt false { true { true } false { false } } {
+ true { false }
+ false { true }
};
assert (rs);
}
fn test_alt_as_block_result() {
- auto rs =
- alt (false) {
- case (true) { false }
- case (false) {
- alt (true) { case (true) { true } case (false) { false } }
- }
+ let rs =
+ alt false {
+ true { false }
+ false { alt true { true { true } false { false } } }
};
assert (rs);
}
diff --git a/src/test/run-pass/expr-block-box.rs b/src/test/run-pass/expr-block-box.rs
index 6d886a7..6297119 100644
--- a/src/test/run-pass/expr-block-box.rs
+++ b/src/test/run-pass/expr-block-box.rs
@@ -2,4 +2,4 @@
// -*- rust -*-
-fn main() { auto x = { @100 }; assert (*x == 100); }
\ No newline at end of file
+fn main() { let x = { @100 }; assert (*x == 100); }
\ No newline at end of file
diff --git a/src/test/run-pass/expr-block-fn.rs b/src/test/run-pass/expr-block-fn.rs
index d2682da..dc8690f 100644
--- a/src/test/run-pass/expr-block-fn.rs
+++ b/src/test/run-pass/expr-block-fn.rs
@@ -4,7 +4,7 @@
type t = fn() -> int ;
fn ten() -> int { ret 10; }
- let t rs = { ten };
+ let rs: t = { ten };
assert (rs() == 10);
}
diff --git a/src/test/run-pass/expr-block-generic-box1.rs b/src/test/run-pass/expr-block-generic-box1.rs
index a3f75eb..715043c 100644
--- a/src/test/run-pass/expr-block-generic-box1.rs
+++ b/src/test/run-pass/expr-block-generic-box1.rs
@@ -4,18 +4,18 @@
// -*- rust -*-
type compare[T] = fn(@T, @T) -> bool ;
-fn test_generic[T](@T expected, &compare[T] eq) {
- let @T actual = { expected };
+fn test_generic[T](expected: @T, eq: &compare[T]) {
+ let actual: @T = { expected };
assert (eq(expected, actual));
}
fn test_box() {
- fn compare_box(@bool b1, @bool b2) -> bool {
+ fn compare_box(b1: @bool, b2: @bool) -> bool {
log *b1;
log *b2;
ret *b1 == *b2;
}
- auto eq = bind compare_box(_, _);
+ let eq = bind compare_box(_, _);
test_generic[bool](@true, eq);
}
diff --git a/src/test/run-pass/expr-block-generic-box2.rs b/src/test/run-pass/expr-block-generic-box2.rs
index 8081911..3a6b580 100644
--- a/src/test/run-pass/expr-block-generic-box2.rs
+++ b/src/test/run-pass/expr-block-generic-box2.rs
@@ -4,14 +4,14 @@
// -*- rust -*-
type compare[T] = fn(&T, &T) -> bool ;
-fn test_generic[T](&T expected, &compare[T] eq) {
- let T actual = { expected };
+fn test_generic[T](expected: &T, eq: &compare[T]) {
+ let actual: T = { expected };
assert (eq(expected, actual));
}
fn test_vec() {
- fn compare_vec(&vec[int] v1, &vec[int] v2) -> bool { ret v1 == v2; }
- auto eq = bind compare_vec(_, _);
+ fn compare_vec(v1: &vec[int], v2: &vec[int]) -> bool { ret v1 == v2; }
+ let eq = bind compare_vec(_, _);
test_generic[vec[int]]([1, 2], eq);
}
diff --git a/src/test/run-pass/expr-block-generic.rs b/src/test/run-pass/expr-block-generic.rs
index 108db2b..97f9287 100644
--- a/src/test/run-pass/expr-block-generic.rs
+++ b/src/test/run-pass/expr-block-generic.rs
@@ -6,23 +6,23 @@
// Tests for standalone blocks as expressions with dynamic type sizes
type compare[T] = fn(&T, &T) -> bool ;
-fn test_generic[T](&T expected, &compare[T] eq) {
- let T actual = { expected };
+fn test_generic[T](expected: &T, eq: &compare[T]) {
+ let actual: T = { expected };
assert (eq(expected, actual));
}
fn test_bool() {
- fn compare_bool(&bool b1, &bool b2) -> bool { ret b1 == b2; }
- auto eq = bind compare_bool(_, _);
+ fn compare_bool(b1: &bool, b2: &bool) -> bool { ret b1 == b2; }
+ let eq = bind compare_bool(_, _);
test_generic[bool](true, eq);
}
fn test_rec() {
- type t = rec(int a, int b);
+ type t = {a: int, b: int};
- fn compare_rec(&t t1, &t t2) -> bool { ret t1 == t2; }
- auto eq = bind compare_rec(_, _);
- test_generic[t](rec(a=1, b=2), eq);
+ fn compare_rec(t1: &t, t2: &t) -> bool { ret t1 == t2; }
+ let eq = bind compare_rec(_, _);
+ test_generic[t]({a: 1, b: 2}, eq);
}
fn main() { test_bool(); test_rec(); }
\ No newline at end of file
diff --git a/src/test/run-pass/expr-block-ref.rs b/src/test/run-pass/expr-block-ref.rs
index 20c3d8e..a6bce4e 100644
--- a/src/test/run-pass/expr-block-ref.rs
+++ b/src/test/run-pass/expr-block-ref.rs
@@ -4,4 +4,4 @@
// xfail-stage0
// Regression test for issue #388
-fn main() { auto x = { { [10] } }; }
\ No newline at end of file
+fn main() { let x = { { [10] } }; }
\ No newline at end of file
diff --git a/src/test/run-pass/expr-block-slot.rs b/src/test/run-pass/expr-block-slot.rs
index 1cc531d..9bf9c88 100644
--- a/src/test/run-pass/expr-block-slot.rs
+++ b/src/test/run-pass/expr-block-slot.rs
@@ -5,8 +5,8 @@
// Regression test for issue #377
fn main() {
- auto a = { auto b = rec(a=3); b };
+ let a = { let b = {a: 3}; b };
assert (a.a == 3);
- auto c = { auto d = rec(v=3); d };
+ let c = { let d = {v: 3}; d };
assert (c.v == 3);
}
\ No newline at end of file
diff --git a/src/test/run-pass/expr-block.rs b/src/test/run-pass/expr-block.rs
index b11a125..d0fb65c 100644
--- a/src/test/run-pass/expr-block.rs
+++ b/src/test/run-pass/expr-block.rs
@@ -4,12 +4,12 @@
// -*- rust -*-
// Tests for standalone blocks as expressions
-fn test_basic() { let bool rs = { true }; assert (rs); }
+fn test_basic() { let rs: bool = { true }; assert (rs); }
-fn test_rec() { auto rs = { rec(v1=10, v2=20) }; assert (rs.v2 == 20); }
+fn test_rec() { let rs = { {v1: 10, v2: 20} }; assert (rs.v2 == 20); }
fn test_filled_with_stuff() {
- auto rs = { auto a = 0; while (a < 10) { a += 1; } a };
+ let rs = { let a = 0; while a < 10 { a += 1; } a };
assert (rs == 10);
}
diff --git a/src/test/run-pass/expr-elseif-ref.rs b/src/test/run-pass/expr-elseif-ref.rs
index 80018c4..5ae99aa 100644
--- a/src/test/run-pass/expr-elseif-ref.rs
+++ b/src/test/run-pass/expr-elseif-ref.rs
@@ -6,7 +6,7 @@
// Make sure we drop the refs of the temporaries needed to return the
// values from the else if branch
fn main() {
- let vec[uint] y = [10u];
- auto x = if (false) { y } else if (true) { y } else { y };
+ let y: vec[uint] = [10u];
+ let x = if false { y } else if (true) { y } else { y };
assert (y.(0) == 10u);
}
\ No newline at end of file
diff --git a/src/test/run-pass/expr-elseif-ref2.rs b/src/test/run-pass/expr-elseif-ref2.rs
index 4215312..50408ac 100644
--- a/src/test/run-pass/expr-elseif-ref2.rs
+++ b/src/test/run-pass/expr-elseif-ref2.rs
@@ -5,5 +5,5 @@
// Regression test for issue #388
fn main() {
- auto x = if (false) { [0u] } else if (true) { [10u] } else { [0u] };
+ let x = if false { [0u] } else if (true) { [10u] } else { [0u] };
}
\ No newline at end of file
diff --git a/src/test/run-pass/expr-empty-ret.rs b/src/test/run-pass/expr-empty-ret.rs
index 86d2efd..6b6c9be 100644
--- a/src/test/run-pass/expr-empty-ret.rs
+++ b/src/test/run-pass/expr-empty-ret.rs
@@ -1,11 +1,6 @@
// xfail-stage0
// Issue #521
-fn f() {
- auto x = alt (true) {
- case (true) { 10 }
- case (false) { ret }
- };
-}
+fn f() { let x = alt true { true { 10 } false { ret } }; }
-fn main() { }
+fn main() { }
\ No newline at end of file
diff --git a/src/test/run-pass/expr-fn.rs b/src/test/run-pass/expr-fn.rs
index 9187e53..4b8ce9b 100644
--- a/src/test/run-pass/expr-fn.rs
+++ b/src/test/run-pass/expr-fn.rs
@@ -13,17 +13,17 @@
}
fn test_generic() {
- fn f[T](&T t) -> T { t }
+ fn f[T](t: &T) -> T { t }
assert (f(10) == 10);
}
fn test_alt() {
- fn f() -> int { alt (true) { case (false) { 10 } case (true) { 20 } } }
+ fn f() -> int { alt true { false { 10 } true { 20 } } }
assert (f() == 20);
}
fn test_if() {
- fn f() -> int { if (true) { 10 } else { 20 } }
+ fn f() -> int { if true { 10 } else { 20 } }
assert (f() == 10);
}
@@ -43,7 +43,7 @@
// From issue #372
fn test_372() {
- fn f() -> int { auto x = { 3 }; x }
+ fn f() -> int { let x = { 3 }; x }
assert (f() == 3);
}
diff --git a/src/test/run-pass/expr-if-box.rs b/src/test/run-pass/expr-if-box.rs
index fd63eb9..32881d2 100644
--- a/src/test/run-pass/expr-if-box.rs
+++ b/src/test/run-pass/expr-if-box.rs
@@ -5,12 +5,12 @@
// Tests for if as expressions returning boxed types
fn test_box() {
- auto rs = if (true) { @100 } else { @101 };
+ let rs = if true { @100 } else { @101 };
assert (*rs == 100);
}
fn test_str() {
- auto rs = if (true) { "happy" } else { "sad" };
+ let rs = if true { "happy" } else { "sad" };
assert (rs == "happy");
}
diff --git a/src/test/run-pass/expr-if-fail-all.rs b/src/test/run-pass/expr-if-fail-all.rs
index 3d11fd0..2f7e0f2 100644
--- a/src/test/run-pass/expr-if-fail-all.rs
+++ b/src/test/run-pass/expr-if-fail-all.rs
@@ -5,6 +5,4 @@
// When all branches of an if expression result in fail, the entire if
// expression results in fail.
-fn main() {
- auto x = if (true) { 10 } else { if (true) { fail } else { fail } };
-}
\ No newline at end of file
+fn main() { let x = if true { 10 } else { if true { fail } else { fail } }; }
\ No newline at end of file
diff --git a/src/test/run-pass/expr-if-fail.rs b/src/test/run-pass/expr-if-fail.rs
index 0ab671a..1589f79 100644
--- a/src/test/run-pass/expr-if-fail.rs
+++ b/src/test/run-pass/expr-if-fail.rs
@@ -2,18 +2,15 @@
// xfail-stage0
-fn test_if_fail() {
- auto x = if (false) { fail } else { 10 };
- assert (x == 10);
-}
+fn test_if_fail() { let x = if false { fail } else { 10 }; assert (x == 10); }
fn test_else_fail() {
- auto x = if (true) { 10 } else { fail };
+ let x = if true { 10 } else { fail };
assert (x == 10);
}
fn test_elseif_fail() {
- auto x = if (false) { 0 } else if (false) { fail } else { 10 };
+ let x = if false { 0 } else if (false) { fail } else { 10 };
assert (x == 10);
}
diff --git a/src/test/run-pass/expr-if-generic-box1.rs b/src/test/run-pass/expr-if-generic-box1.rs
index 0f0e4fe..3d13018 100644
--- a/src/test/run-pass/expr-if-generic-box1.rs
+++ b/src/test/run-pass/expr-if-generic-box1.rs
@@ -4,14 +4,14 @@
// -*- rust -*-
type compare[T] = fn(@T, @T) -> bool ;
-fn test_generic[T](@T expected, @T not_expected, &compare[T] eq) {
- let @T actual = if (true) { expected } else { not_expected };
+fn test_generic[T](expected: @T, not_expected: @T, eq: &compare[T]) {
+ let actual: @T = if true { expected } else { not_expected };
assert (eq(expected, actual));
}
fn test_box() {
- fn compare_box(@bool b1, @bool b2) -> bool { ret *b1 == *b2; }
- auto eq = bind compare_box(_, _);
+ fn compare_box(b1: @bool, b2: @bool) -> bool { ret *b1 == *b2; }
+ let eq = bind compare_box(_, _);
test_generic[bool](@true, @false, eq);
}
diff --git a/src/test/run-pass/expr-if-generic-box2.rs b/src/test/run-pass/expr-if-generic-box2.rs
index 4ee2784..d06e7e0 100644
--- a/src/test/run-pass/expr-if-generic-box2.rs
+++ b/src/test/run-pass/expr-if-generic-box2.rs
@@ -4,14 +4,14 @@
// -*- rust -*-
type compare[T] = fn(&T, &T) -> bool ;
-fn test_generic[T](&T expected, &T not_expected, &compare[T] eq) {
- let T actual = if (true) { expected } else { not_expected };
+fn test_generic[T](expected: &T, not_expected: &T, eq: &compare[T]) {
+ let actual: T = if true { expected } else { not_expected };
assert (eq(expected, actual));
}
fn test_vec() {
- fn compare_vec(&vec[int] v1, &vec[int] v2) -> bool { ret v1 == v2; }
- auto eq = bind compare_vec(_, _);
+ fn compare_vec(v1: &vec[int], v2: &vec[int]) -> bool { ret v1 == v2; }
+ let eq = bind compare_vec(_, _);
test_generic[vec[int]]([1, 2], [2, 3], eq);
}
diff --git a/src/test/run-pass/expr-if-generic.rs b/src/test/run-pass/expr-if-generic.rs
index 72c2475..4994c07 100644
--- a/src/test/run-pass/expr-if-generic.rs
+++ b/src/test/run-pass/expr-if-generic.rs
@@ -6,23 +6,23 @@
// Tests for if as expressions with dynamic type sizes
type compare[T] = fn(&T, &T) -> bool ;
-fn test_generic[T](&T expected, &T not_expected, &compare[T] eq) {
- let T actual = if (true) { expected } else { not_expected };
+fn test_generic[T](expected: &T, not_expected: &T, eq: &compare[T]) {
+ let actual: T = if true { expected } else { not_expected };
assert (eq(expected, actual));
}
fn test_bool() {
- fn compare_bool(&bool b1, &bool b2) -> bool { ret b1 == b2; }
- auto eq = bind compare_bool(_, _);
+ fn compare_bool(b1: &bool, b2: &bool) -> bool { ret b1 == b2; }
+ let eq = bind compare_bool(_, _);
test_generic[bool](true, false, eq);
}
fn test_rec() {
- type t = rec(int a, int b);
+ type t = {a: int, b: int};
- fn compare_rec(&t t1, &t t2) -> bool { ret t1 == t2; }
- auto eq = bind compare_rec(_, _);
- test_generic[t](rec(a=1, b=2), rec(a=2, b=3), eq);
+ fn compare_rec(t1: &t, t2: &t) -> bool { ret t1 == t2; }
+ let eq = bind compare_rec(_, _);
+ test_generic[t]({a: 1, b: 2}, {a: 2, b: 3}, eq);
}
fn main() { test_bool(); test_rec(); }
\ No newline at end of file
diff --git a/src/test/run-pass/expr-if-struct.rs b/src/test/run-pass/expr-if-struct.rs
index 824f72f..481fbf3 100644
--- a/src/test/run-pass/expr-if-struct.rs
+++ b/src/test/run-pass/expr-if-struct.rs
@@ -5,13 +5,13 @@
// Tests for if as expressions returning structural types
fn test_rec() {
- auto rs = if (true) { rec(i=100) } else { rec(i=101) };
- assert (rs == rec(i=100));
+ let rs = if true { {i: 100} } else { {i: 101} };
+ assert (rs == {i: 100});
}
fn test_tag() {
tag mood { happy; sad; }
- auto rs = if (true) { happy } else { sad };
+ let rs = if true { happy } else { sad };
assert (rs == happy);
}
diff --git a/src/test/run-pass/expr-if.rs b/src/test/run-pass/expr-if.rs
index e406902..74c2a53 100644
--- a/src/test/run-pass/expr-if.rs
+++ b/src/test/run-pass/expr-if.rs
@@ -4,50 +4,42 @@
// -*- rust -*-
// Tests for if as expressions
-fn test_if() {
- let bool rs = if (true) { true } else { false };
- assert (rs);
-}
+fn test_if() { let rs: bool = if true { true } else { false }; assert (rs); }
fn test_else() {
- let bool rs = if (false) { false } else { true };
+ let rs: bool = if false { false } else { true };
assert (rs);
}
fn test_elseif1() {
- let bool rs = if (true) { true } else if (true) { false } else { false };
+ let rs: bool = if true { true } else if (true) { false } else { false };
assert (rs);
}
fn test_elseif2() {
- let bool rs =
- if (false) { false } else if (true) { true } else { false };
+ let rs: bool = if false { false } else if (true) { true } else { false };
assert (rs);
}
fn test_elseif3() {
- let bool rs =
- if (false) { false } else if (false) { false } else { true };
+ let rs: bool = if false { false } else if (false) { false } else { true };
assert (rs);
}
fn test_inferrence() {
- auto rs = if (true) { true } else { false };
+ let rs = if true { true } else { false };
assert (rs);
}
fn test_if_as_if_condition() {
- auto rs1 =
- if (if (false) { false } else { true }) { true } else { false };
+ let rs1 = if if false { false } else { true } { true } else { false };
assert (rs1);
- auto rs2 =
- if (if (true) { false } else { true }) { false } else { true };
+ let rs2 = if if true { false } else { true } { false } else { true };
assert (rs2);
}
fn test_if_as_block_result() {
- auto rs =
- if (true) { if (false) { false } else { true } } else { false };
+ let rs = if true { if false { false } else { true } } else { false };
assert (rs);
}
diff --git a/src/test/run-pass/exterior.rs b/src/test/run-pass/exterior.rs
index 8f65d7a..ae34d05 100644
--- a/src/test/run-pass/exterior.rs
+++ b/src/test/run-pass/exterior.rs
@@ -2,13 +2,13 @@
// -*- rust -*-
-type point = rec(int x, int y, mutable int z);
+type point = {x: int, y: int, mutable z: int};
-fn f(@point p) { assert (p.z == 12); p.z = 13; assert (p.z == 13); }
+fn f(p: @point) { assert (p.z == 12); p.z = 13; assert (p.z == 13); }
fn main() {
- let point a = rec(x=10, y=11, mutable z=12);
- let @point b = @a;
+ let a: point = {x: 10, y: 11, mutable z: 12};
+ let b: @point = @a;
assert (b.z == 12);
f(b);
assert (a.z == 12);
diff --git a/src/test/run-pass/fact.rs b/src/test/run-pass/fact.rs
index 9fb719a..f47c2e9 100644
--- a/src/test/run-pass/fact.rs
+++ b/src/test/run-pass/fact.rs
@@ -2,18 +2,18 @@
// -*- rust -*-
-fn f(int x) -> int {
+fn f(x: int) -> int {
// log "in f:";
log x;
- if (x == 1) {
+ if x == 1 {
// log "bottoming out";
ret 1;
} else {
// log "recurring";
- let int y = x * f(x - 1);
+ let y: int = x * f(x - 1);
// log "returned";
log y;
diff --git a/src/test/run-pass/fixed-point-bind-box.rs b/src/test/run-pass/fixed-point-bind-box.rs
index d53e465..e1f5609 100644
--- a/src/test/run-pass/fixed-point-bind-box.rs
+++ b/src/test/run-pass/fixed-point-bind-box.rs
@@ -1,20 +1,20 @@
// xfail-stage0
-fn fix_help[A,B](@fn (@fn (&A) -> B, &A) -> B f, &A x) -> B {
+fn fix_help[A, B](f: @fn(@fn(&A) -> B , &A) -> B , x: &A) -> B {
ret f(@bind fix_help(f, _), x);
}
-fn fix[A,B](@fn (@fn (&A) -> B, &A) -> B f) -> (@fn(&A) -> B) {
+fn fix[A, B](f: @fn(@fn(&A) -> B , &A) -> B ) -> @fn(&A) -> B {
ret @bind fix_help(f, _);
}
-fn fact_(@fn (&int) -> int f, &int n) -> int {
+fn fact_(f: @fn(&int) -> int , n: &int) -> int {
// fun fact 0 = 1
- ret if (n == 0) { 1 } else { n*f(n-1) };
+ ret if n == 0 { 1 } else { n * f(n - 1) };
}
fn main() {
- auto fact = fix(@fact_);
- assert(fact(5) == 120);
- assert(fact(2) == 2);
-}
+ let fact = fix(@fact_);
+ assert (fact(5) == 120);
+ assert (fact(2) == 2);
+}
\ No newline at end of file
diff --git a/src/test/run-pass/float-signature.rs b/src/test/run-pass/float-signature.rs
index a547a24..f2e7229 100644
--- a/src/test/run-pass/float-signature.rs
+++ b/src/test/run-pass/float-signature.rs
@@ -1,8 +1,8 @@
fn main() {
- fn foo(float n) -> float { ret n + 0.12345; }
- let float n = 0.1;
- let float m = foo(n);
+ fn foo(n: float) -> float { ret n + 0.12345; }
+ let n: float = 0.1;
+ let m: float = foo(n);
log m;
}
\ No newline at end of file
diff --git a/src/test/run-pass/float.rs b/src/test/run-pass/float.rs
index 177293f..b9014c9 100644
--- a/src/test/run-pass/float.rs
+++ b/src/test/run-pass/float.rs
@@ -1,10 +1,10 @@
fn main() {
- auto pi = 3.1415927;
+ let pi = 3.1415927;
log -pi * (pi + 2.0 / pi) - pi * 5.0;
- if (pi == 5.0 || pi < 10.0 || pi <= 2.0 || pi != 22.0 / 7.0 || pi >= 10.0
- || pi > 1.0) {
+ if pi == 5.0 || pi < 10.0 || pi <= 2.0 || pi != 22.0 / 7.0 || pi >= 10.0
+ || pi > 1.0 {
log "yes";
}
}
\ No newline at end of file
diff --git a/src/test/run-pass/float2.rs b/src/test/run-pass/float2.rs
index 8e892c7..1eed1e3 100644
--- a/src/test/run-pass/float2.rs
+++ b/src/test/run-pass/float2.rs
@@ -1,17 +1,17 @@
fn main() {
- auto a = 1.5e6;
- auto b = 1.5E6;
- auto c = 1e6;
- auto d = 1E6;
- auto e = 3.0f32;
- auto f = 5.9f64;
- auto g = 1.e6f32;
- auto h = 1.0e7f64;
- auto i = 1.0E7f64;
- auto j = 3.1e+9;
- auto k = 3.2e-10;
+ let a = 1.5e6;
+ let b = 1.5E6;
+ let c = 1e6;
+ let d = 1E6;
+ let e = 3.0f32;
+ let f = 5.9f64;
+ let g = 1.e6f32;
+ let h = 1.0e7f64;
+ let i = 1.0E7f64;
+ let j = 3.1e+9;
+ let k = 3.2e-10;
assert (a == b);
assert (c < b);
assert (c == d);
diff --git a/src/test/run-pass/floatlits.rs b/src/test/run-pass/floatlits.rs
index d14a85e..13039f2 100644
--- a/src/test/run-pass/floatlits.rs
+++ b/src/test/run-pass/floatlits.rs
@@ -1,10 +1,10 @@
fn main() {
- auto f = 4.999999999999;
+ let f = 4.999999999999;
assert (f > 4.90);
assert (f < 5.0);
- auto g = 4.90000000001e-10;
+ let g = 4.90000000001e-10;
assert (g > 5e-11);
assert (g < 5e-9);
}
\ No newline at end of file
diff --git a/src/test/run-pass/fn-constraint.rs b/src/test/run-pass/fn-constraint.rs
index a14cb3a..2f7b81e 100644
--- a/src/test/run-pass/fn-constraint.rs
+++ b/src/test/run-pass/fn-constraint.rs
@@ -3,8 +3,8 @@
import std::uint::*;
fn main() {
- let uint a = 1u;
- let uint b = 4u;
- check le(a, b);
- log (safe_slice("kitties", a, b));
+ let a: uint = 1u;
+ let b: uint = 4u;
+ check (le(a, b));
+ log safe_slice("kitties", a, b);
}
\ No newline at end of file
diff --git a/src/test/run-pass/fn-expr.rs b/src/test/run-pass/fn-expr.rs
index 263ef7f..728c435 100644
--- a/src/test/run-pass/fn-expr.rs
+++ b/src/test/run-pass/fn-expr.rs
@@ -2,4 +2,4 @@
// xfail-stage0
-fn main() { auto x = fn (int a) -> int { ret a + 1; }; assert (x(4) == 5); }
\ No newline at end of file
+fn main() { let x = fn (a: int) -> int { ret a + 1; }; assert (x(4) == 5); }
\ No newline at end of file
diff --git a/src/test/run-pass/fn-lval.rs b/src/test/run-pass/fn-lval.rs
index 05a676b..faa12c8 100644
--- a/src/test/run-pass/fn-lval.rs
+++ b/src/test/run-pass/fn-lval.rs
@@ -2,8 +2,8 @@
// -*- rust -*-
-fn foo(fn(int) -> int f) { }
+fn foo(f: fn(int) -> int ) { }
-fn id(int x) -> int { ret x; }
+fn id(x: int) -> int { ret x; }
fn main() { foo(id); }
\ No newline at end of file
diff --git a/src/test/run-pass/fn-type-infer.rs b/src/test/run-pass/fn-type-infer.rs
index 1c0fbbe..f0522cc 100644
--- a/src/test/run-pass/fn-type-infer.rs
+++ b/src/test/run-pass/fn-type-infer.rs
@@ -2,5 +2,5 @@
fn main() {
// We should be able to type infer inside of lambdas.
- auto f = fn () { auto i = 10; };
-}
+ let f = fn () { let i = 10; };
+}
\ No newline at end of file
diff --git a/src/test/run-pass/for-loop-fail.rs b/src/test/run-pass/for-loop-fail.rs
index 84dcc30..d3b6098 100644
--- a/src/test/run-pass/for-loop-fail.rs
+++ b/src/test/run-pass/for-loop-fail.rs
@@ -1,7 +1,2 @@
// xfail-stage0
-fn main() {
- let vec[int] x = [];
- for (int i in x) {
- fail "moop";
- }
-}
+fn main() { let x: vec[int] = []; for i: int in x { fail "moop"; } }
\ No newline at end of file
diff --git a/src/test/run-pass/foreach-box-drop.rs b/src/test/run-pass/foreach-box-drop.rs
index 39ac962..3c025a0 100644
--- a/src/test/run-pass/foreach-box-drop.rs
+++ b/src/test/run-pass/foreach-box-drop.rs
@@ -1,9 +1,9 @@
-obj ob[K](K k) {
- iter foo() -> @rec(K a) { put @rec(a=k); }
+obj ob[K](k: K) {
+ iter foo() -> @{a: K} { put @{a: k}; }
}
-fn x(&ob[str] o) { for each (@rec(str a) i in o.foo()) { } }
+fn x(o: &ob[str]) { for each i: @{a: str} in o.foo() { } }
-fn main() { auto o = ob[str]("hi" + "there"); x(o); }
\ No newline at end of file
+fn main() { let o = ob[str]("hi" + "there"); x(o); }
\ No newline at end of file
diff --git a/src/test/run-pass/foreach-nested-2.rs b/src/test/run-pass/foreach-nested-2.rs
index 14489a4..030bf33 100644
--- a/src/test/run-pass/foreach-nested-2.rs
+++ b/src/test/run-pass/foreach-nested-2.rs
@@ -4,18 +4,18 @@
// -*- rust -*-
iter two() -> int { put 0; put 1; }
-iter range(int start, int stop) -> int {
- let int i = start;
- while (i < stop) { put i; i += 1; }
+iter range(start: int, stop: int) -> int {
+ let i: int = start;
+ while i < stop { put i; i += 1; }
}
fn main() {
- let vec[mutable int] a = [mutable -1, -1, -1, -1, -1, -1, -1, -1];
- let int p = 0;
- for each (int i in two()) {
- for each (int j in range(0, 2)) {
- let int tmp = 10 * i + j;
- for each (int k in range(0, 2)) { a.(p) = 10 * tmp + k; p += 1; }
+ let a: vec[mutable int] = [mutable -1, -1, -1, -1, -1, -1, -1, -1];
+ let p: int = 0;
+ for each i: int in two() {
+ for each j: int in range(0, 2) {
+ let tmp: int = 10 * i + j;
+ for each k: int in range(0, 2) { a.(p) = 10 * tmp + k; p += 1; }
}
}
assert (a.(0) == 0);
diff --git a/src/test/run-pass/foreach-nested.rs b/src/test/run-pass/foreach-nested.rs
index f2def14..0d84f35 100644
--- a/src/test/run-pass/foreach-nested.rs
+++ b/src/test/run-pass/foreach-nested.rs
@@ -5,10 +5,10 @@
iter two() -> int { put 0; put 1; }
fn main() {
- let vec[mutable int] a = [mutable -1, -1, -1, -1];
- let int p = 0;
- for each (int i in two()) {
- for each (int j in two()) { a.(p) = 10 * i + j; p += 1; }
+ let a: vec[mutable int] = [mutable -1, -1, -1, -1];
+ let p: int = 0;
+ for each i: int in two() {
+ for each j: int in two() { a.(p) = 10 * i + j; p += 1; }
}
assert (a.(0) == 0);
assert (a.(1) == 1);
diff --git a/src/test/run-pass/foreach-put-structured.rs b/src/test/run-pass/foreach-put-structured.rs
index eae0f61..2384a38 100644
--- a/src/test/run-pass/foreach-put-structured.rs
+++ b/src/test/run-pass/foreach-put-structured.rs
@@ -1,15 +1,15 @@
-iter pairs() -> rec(int _0, int _1) {
- let int i = 0;
- let int j = 0;
- while (i < 10) { put rec(_0=i, _1=j); i += 1; j += i; }
+iter pairs() -> {_0: int, _1: int} {
+ let i: int = 0;
+ let j: int = 0;
+ while i < 10 { put {_0: i, _1: j}; i += 1; j += i; }
}
fn main() {
- let int i = 10;
- let int j = 0;
- for each (rec(int _0, int _1) p in pairs()) {
+ let i: int = 10;
+ let j: int = 0;
+ for each p: {_0: int, _1: int} in pairs() {
log p._0;
log p._1;
assert (p._0 + 10 == i);
diff --git a/src/test/run-pass/foreach-simple-outer-slot.rs b/src/test/run-pass/foreach-simple-outer-slot.rs
index 270c658..e2a01d2 100644
--- a/src/test/run-pass/foreach-simple-outer-slot.rs
+++ b/src/test/run-pass/foreach-simple-outer-slot.rs
@@ -3,14 +3,14 @@
// -*- rust -*-
fn main() {
- let int sum = 0;
- for each (int i in first_ten()) { log "main"; log i; sum = sum + i; }
+ let sum: int = 0;
+ for each i: int in first_ten() { log "main"; log i; sum = sum + i; }
log "sum";
log sum;
assert (sum == 45);
}
iter first_ten() -> int {
- let int i = 0;
- while (i < 10) { log "first_ten"; put i; i = i + 1; }
+ let i: int = 0;
+ while i < 10 { log "first_ten"; put i; i = i + 1; }
}
\ No newline at end of file
diff --git a/src/test/run-pass/foreach-simple.rs b/src/test/run-pass/foreach-simple.rs
index e718aa6..94ae11b 100644
--- a/src/test/run-pass/foreach-simple.rs
+++ b/src/test/run-pass/foreach-simple.rs
@@ -2,9 +2,9 @@
// -*- rust -*-
-fn main() { for each (int i in first_ten()) { log "main"; } }
+fn main() { for each i: int in first_ten() { log "main"; } }
iter first_ten() -> int {
- let int i = 90;
- while (i < 100) { log "first_ten"; log i; put i; i = i + 1; }
+ let i: int = 90;
+ while i < 100 { log "first_ten"; log i; put i; i = i + 1; }
}
\ No newline at end of file
diff --git a/src/test/run-pass/fun-call-variants.rs b/src/test/run-pass/fun-call-variants.rs
index fdf6da1..a15a964 100644
--- a/src/test/run-pass/fun-call-variants.rs
+++ b/src/test/run-pass/fun-call-variants.rs
@@ -2,18 +2,20 @@
// -*- rust -*-
-fn ho(fn(int) -> int f) -> int { let int n = f(3); ret n; }
+fn ho(f: fn(int) -> int ) -> int { let n: int = f(3); ret n; }
-fn direct(int x) -> int { ret x + 1; }
+fn direct(x: int) -> int { ret x + 1; }
fn main() {
- let int a =
+ let a: int =
direct(3); // direct
//let int b = ho(direct); // indirect unbound
- let int c =
+
+ let c: int =
ho(bind direct(_)); // indirect bound
//assert (a == b);
//assert (b == c);
+
}
\ No newline at end of file
diff --git a/src/test/run-pass/fun-indirect-call.rs b/src/test/run-pass/fun-indirect-call.rs
index 107eb69..7bbfd7b 100644
--- a/src/test/run-pass/fun-indirect-call.rs
+++ b/src/test/run-pass/fun-indirect-call.rs
@@ -4,4 +4,4 @@
// -*- rust -*-
fn f() -> int { ret 42; }
-fn main() { let fn() -> int g = f; let int i = g(); assert (i == 42); }
\ No newline at end of file
+fn main() { let g: fn() -> int = f; let i: int = g(); assert (i == 42); }
\ No newline at end of file
diff --git a/src/test/run-pass/generic-alias-box.rs b/src/test/run-pass/generic-alias-box.rs
index 179edf8..e920774 100644
--- a/src/test/run-pass/generic-alias-box.rs
+++ b/src/test/run-pass/generic-alias-box.rs
@@ -1,10 +1,10 @@
-fn id[T](&T t) -> T { ret t; }
+fn id[T](t: &T) -> T { ret t; }
fn main() {
- auto expected = @100;
- auto actual = id[@int](expected);
+ let expected = @100;
+ let actual = id[@int](expected);
log *actual;
assert (*expected == *actual);
}
\ No newline at end of file
diff --git a/src/test/run-pass/generic-bind-2.rs b/src/test/run-pass/generic-bind-2.rs
index c5337e9..b4699cb 100644
--- a/src/test/run-pass/generic-bind-2.rs
+++ b/src/test/run-pass/generic-bind-2.rs
@@ -1,10 +1,10 @@
-fn id[T](&T t) -> T { ret t; }
+fn id[T](t: &T) -> T { ret t; }
fn main() {
- auto t = rec(a=1, b=2, c=3, d=4, e=5, f=6, g=7);
+ let t = {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7};
assert (t.f == 6);
- auto f0 = bind id(t);
+ let f0 = bind id(t);
assert (f0().f == 6);
}
\ No newline at end of file
diff --git a/src/test/run-pass/generic-bind.rs b/src/test/run-pass/generic-bind.rs
index e807788..2f8669d 100644
--- a/src/test/run-pass/generic-bind.rs
+++ b/src/test/run-pass/generic-bind.rs
@@ -1,11 +1,17 @@
-fn id[T](&T t) -> T { ret t; }
+fn id[T](t: &T) -> T { ret t; }
fn main() {
- auto t = rec(_0=1, _1=2, _2=3, _3=4, _4=5, _5=6, _6=7);
+ let t = {_0: 1, _1: 2, _2: 3, _3: 4, _4: 5, _5: 6, _6: 7};
assert (t._5 == 6);
- auto f1 = bind id[rec(int _0, int _1, int _2, int _3, int _4,
- int _5, int _6)](_);
+ let f1 =
+ bind id[{_0: int,
+ _1: int,
+ _2: int,
+ _3: int,
+ _4: int,
+ _5: int,
+ _6: int}](_);
assert (f1(t)._5 == 6);
}
\ No newline at end of file
diff --git a/src/test/run-pass/generic-box.rs b/src/test/run-pass/generic-box.rs
index 9020c61..d06b9cc 100644
--- a/src/test/run-pass/generic-box.rs
+++ b/src/test/run-pass/generic-box.rs
@@ -1,8 +1,8 @@
-fn box[T](&rec(T x, T y, T z) x) -> @rec(T x, T y, T z) { ret @x; }
+fn box[T](x: &{x: T, y: T, z: T}) -> @{x: T, y: T, z: T} { ret @x; }
fn main() {
- let @rec(int x, int y, int z) x = box[int](rec(x=1, y=2, z=3));
+ let x: @{x: int, y: int, z: int} = box[int]({x: 1, y: 2, z: 3});
assert (x.y == 2);
}
\ No newline at end of file
diff --git a/src/test/run-pass/generic-derived-type.rs b/src/test/run-pass/generic-derived-type.rs
index 2ff8a1a..cdb30e3 100644
--- a/src/test/run-pass/generic-derived-type.rs
+++ b/src/test/run-pass/generic-derived-type.rs
@@ -1,16 +1,16 @@
-fn g[X](&X x) -> X { ret x; }
+fn g[X](x: &X) -> X { ret x; }
-fn f[T](&T t) -> rec(T a, T b) {
- type pair = rec(T a, T b);
+fn f[T](t: &T) -> {a: T, b: T} {
+ type pair = {a: T, b: T};
- let pair x = rec(a=t, b=t);
+ let x: pair = {a: t, b: t};
ret g[pair](x);
}
fn main() {
- auto b = f[int](10);
+ let b = f[int](10);
log b.a;
log b.b;
assert (b.a == 10);
diff --git a/src/test/run-pass/generic-drop-glue.rs b/src/test/run-pass/generic-drop-glue.rs
index 1415448..4a244dc 100644
--- a/src/test/run-pass/generic-drop-glue.rs
+++ b/src/test/run-pass/generic-drop-glue.rs
@@ -1,5 +1,5 @@
-fn f[T](&T t) { let T t1 = t; }
+fn f[T](t: &T) { let t1: T = t; }
-fn main() { auto x = rec(x=@10, y=@12); f(x); }
\ No newline at end of file
+fn main() { let x = {x: @10, y: @12}; f(x); }
\ No newline at end of file
diff --git a/src/test/run-pass/generic-exterior-box.rs b/src/test/run-pass/generic-exterior-box.rs
index 979dc71..8efac57 100644
--- a/src/test/run-pass/generic-exterior-box.rs
+++ b/src/test/run-pass/generic-exterior-box.rs
@@ -1,11 +1,11 @@
-type recbox[T] = rec(@T x);
+type recbox[T] = {x: @T};
-fn reclift[T](&T t) -> recbox[T] { ret rec(x=@t); }
+fn reclift[T](t: &T) -> recbox[T] { ret {x: @t}; }
fn main() {
- let int foo = 17;
- let recbox[int] rbfoo = reclift[int](foo);
+ let foo: int = 17;
+ let rbfoo: recbox[int] = reclift[int](foo);
assert (rbfoo.x == foo);
}
\ No newline at end of file
diff --git a/src/test/run-pass/generic-fn-box.rs b/src/test/run-pass/generic-fn-box.rs
index 47200fd..1a3420c 100644
--- a/src/test/run-pass/generic-fn-box.rs
+++ b/src/test/run-pass/generic-fn-box.rs
@@ -1,5 +1,5 @@
-fn f[T](@T x) -> @T { ret x; }
+fn f[T](x: @T) -> @T { ret x; }
-fn main() { auto x = f(@3); log *x; }
\ No newline at end of file
+fn main() { let x = f(@3); log *x; }
\ No newline at end of file
diff --git a/src/test/run-pass/generic-fn-infer.rs b/src/test/run-pass/generic-fn-infer.rs
index 1e00481..8f50d3f 100644
--- a/src/test/run-pass/generic-fn-infer.rs
+++ b/src/test/run-pass/generic-fn-infer.rs
@@ -4,6 +4,6 @@
// -*- rust -*-
// Issue #45: infer type parameters in function applications
-fn id[T](&T x) -> T { ret x; }
+fn id[T](x: &T) -> T { ret x; }
-fn main() { let int x = 42; let int y = id(x); assert (x == y); }
\ No newline at end of file
+fn main() { let x: int = 42; let y: int = id(x); assert (x == y); }
\ No newline at end of file
diff --git a/src/test/run-pass/generic-fn.rs b/src/test/run-pass/generic-fn.rs
index 8a35d43..016969d 100644
--- a/src/test/run-pass/generic-fn.rs
+++ b/src/test/run-pass/generic-fn.rs
@@ -2,17 +2,17 @@
// -*- rust -*-
-fn id[T](&T x) -> T { ret x; }
+fn id[T](x: &T) -> T { ret x; }
-type triple = rec(int x, int y, int z);
+type triple = {x: int, y: int, z: int};
fn main() {
- auto x = 62;
- auto y = 63;
- auto a = 'a';
- auto b = 'b';
- let triple p = rec(x=65, y=66, z=67);
- let triple q = rec(x=68, y=69, z=70);
+ let x = 62;
+ let y = 63;
+ let a = 'a';
+ let b = 'b';
+ let p: triple = {x: 65, y: 66, z: 67};
+ let q: triple = {x: 68, y: 69, z: 70};
y = id[int](x);
log y;
assert (x == y);
diff --git a/src/test/run-pass/generic-iter-frame.rs b/src/test/run-pass/generic-iter-frame.rs
index 1b04cb0..36b7aa5 100644
--- a/src/test/run-pass/generic-iter-frame.rs
+++ b/src/test/run-pass/generic-iter-frame.rs
@@ -4,6 +4,6 @@
// Contrived example? No. It showed up in rustc's resolve pass.
iter i() { put (); }
-fn foo[T](&T t) { let int x = 10; for each (() j in i()) { log x; } }
+fn foo[T](t: &T) { let x: int = 10; for each j: () in i() { log x; } }
fn main() { foo(0xdeadbeef_u); }
\ No newline at end of file
diff --git a/src/test/run-pass/generic-ivec-leak.rs b/src/test/run-pass/generic-ivec-leak.rs
index 4bf776c..ea084f9 100644
--- a/src/test/run-pass/generic-ivec-leak.rs
+++ b/src/test/run-pass/generic-ivec-leak.rs
@@ -1,10 +1,6 @@
// xfail-stage0
-tag wrapper[T] {
- wrapped(T);
-}
+tag wrapper[T] { wrapped(T); }
-fn main() {
- auto w = wrapped(~[ 1, 2, 3, 4, 5 ]);
-}
+fn main() { let w = wrapped(~[1, 2, 3, 4, 5]); }
diff --git a/src/test/run-pass/generic-ivec.rs b/src/test/run-pass/generic-ivec.rs
index 2afc69d..dcfd33c 100644
--- a/src/test/run-pass/generic-ivec.rs
+++ b/src/test/run-pass/generic-ivec.rs
@@ -1,7 +1,5 @@
// xfail-stage0
-fn f[T](@T v) {}
-fn main() {
- f(@~[ 1, 2, 3, 4, 5 ]);
-}
+fn f[T](v: @T) { }
+fn main() { f(@~[1, 2, 3, 4, 5]); }
diff --git a/src/test/run-pass/generic-obj-with-derived-type.rs b/src/test/run-pass/generic-obj-with-derived-type.rs
index 08dffe7..54432be 100644
--- a/src/test/run-pass/generic-obj-with-derived-type.rs
+++ b/src/test/run-pass/generic-obj-with-derived-type.rs
@@ -1,15 +1,13 @@
-obj handle[T](T data) {
+obj handle[T](data: T) {
fn get() -> T { ret data; }
}
fn main() {
- type rgb = rec(u8 x, u8 y, u8 z);
+ type rgb = {x: u8, y: u8, z: u8};
- let handle[rgb] h = handle[rgb](rec(x=1 as u8,
- y=2 as u8,
- z=3 as u8));
+ let h: handle[rgb] = handle[rgb]({x: 1 as u8, y: 2 as u8, z: 3 as u8});
log "constructed object";
log h.get().x;
log h.get().y;
diff --git a/src/test/run-pass/generic-obj.rs b/src/test/run-pass/generic-obj.rs
index 7e7692d..76283f4 100644
--- a/src/test/run-pass/generic-obj.rs
+++ b/src/test/run-pass/generic-obj.rs
@@ -1,17 +1,17 @@
-obj buf[T](rec(T _0, T _1, T _2) data) {
- fn get(int i) -> T {
- if (i == 0) {
+obj buf[T](data: {_0: T, _1: T, _2: T}) {
+ fn get(i: int) -> T {
+ if i == 0 {
ret data._0;
- } else { if (i == 1) { ret data._1; } else { ret data._2; } }
+ } else { if i == 1 { ret data._1; } else { ret data._2; } }
}
- fn take(&T t) { }
- fn take2(&T t) { }
+ fn take(t: &T) { }
+ fn take2(t: &T) { }
}
fn main() {
- let buf[int] b = buf[int](rec(_0=1, _1=2, _2=3));
+ let b: buf[int] = buf[int]({_0: 1, _1: 2, _2: 3});
log "constructed object";
log b.get(0);
log b.get(1);
diff --git a/src/test/run-pass/generic-recursive-tag.rs b/src/test/run-pass/generic-recursive-tag.rs
index fd007f5..4e50be9 100644
--- a/src/test/run-pass/generic-recursive-tag.rs
+++ b/src/test/run-pass/generic-recursive-tag.rs
@@ -3,6 +3,6 @@
tag list[T] { cons(@T, @list[T]); nil; }
fn main() {
- let list[int] a =
+ let a: list[int] =
cons[int](@10, @cons[int](@12, @cons[int](@13, @nil[int])));
}
\ No newline at end of file
diff --git a/src/test/run-pass/generic-tag-alt.rs b/src/test/run-pass/generic-tag-alt.rs
index 84c72a7..f55cfca 100644
--- a/src/test/run-pass/generic-tag-alt.rs
+++ b/src/test/run-pass/generic-tag-alt.rs
@@ -2,9 +2,9 @@
tag foo[T] { arm(T); }
-fn altfoo[T](&foo[T] f) {
- auto hit = false;
- alt (f) { case (arm[T](?x)) { log "in arm"; hit = true; } }
+fn altfoo[T](f: &foo[T]) {
+ let hit = false;
+ alt f { arm[T](x) { log "in arm"; hit = true; } }
assert (hit);
}
diff --git a/src/test/run-pass/generic-tag-corruption.rs b/src/test/run-pass/generic-tag-corruption.rs
index 9d335f5..e5f8006 100644
--- a/src/test/run-pass/generic-tag-corruption.rs
+++ b/src/test/run-pass/generic-tag-corruption.rs
@@ -4,4 +4,4 @@
// This causes memory corruption in stage0.
tag thing[K] { some(K); }
-fn main() { auto x = some("hi"); }
\ No newline at end of file
+fn main() { let x = some("hi"); }
\ No newline at end of file
diff --git a/src/test/run-pass/generic-tag-local.rs b/src/test/run-pass/generic-tag-local.rs
index 7b4ff49..ae10ba7 100644
--- a/src/test/run-pass/generic-tag-local.rs
+++ b/src/test/run-pass/generic-tag-local.rs
@@ -2,4 +2,4 @@
tag clam[T] { a(T); }
-fn main() { auto c = a(3); }
\ No newline at end of file
+fn main() { let c = a(3); }
\ No newline at end of file
diff --git a/src/test/run-pass/generic-tag-values.rs b/src/test/run-pass/generic-tag-values.rs
index f40091f..035c34e 100644
--- a/src/test/run-pass/generic-tag-values.rs
+++ b/src/test/run-pass/generic-tag-values.rs
@@ -5,15 +5,10 @@
tag noption[T] { some(T); }
fn main() {
- let noption[int] nop = some[int](5);
- alt (nop) { case (some[int](?n)) { log n; assert (n == 5); } }
- let noption[rec(int x, int y)] nop2 = some(rec(x=17, y=42));
- alt (nop2) {
- case (some(?t)) {
- log t.x;
- log t.y;
- assert (t.x == 17);
- assert (t.y == 42);
- }
+ let nop: noption[int] = some[int](5);
+ alt nop { some[int](n) { log n; assert (n == 5); } }
+ let nop2: noption[{x: int, y: int}] = some({x: 17, y: 42});
+ alt nop2 {
+ some(t) { log t.x; log t.y; assert (t.x == 17); assert (t.y == 42); }
}
}
\ No newline at end of file
diff --git a/src/test/run-pass/generic-tag.rs b/src/test/run-pass/generic-tag.rs
index ee00e94..babc087 100644
--- a/src/test/run-pass/generic-tag.rs
+++ b/src/test/run-pass/generic-tag.rs
@@ -2,4 +2,4 @@
tag option[T] { some(@T); none; }
-fn main() { let option[int] a = some[int](@10); a = none[int]; }
\ No newline at end of file
+fn main() { let a: option[int] = some[int](@10); a = none[int]; }
\ No newline at end of file
diff --git a/src/test/run-pass/generic-temporary.rs b/src/test/run-pass/generic-temporary.rs
index b8a7b38..4fec91d 100644
--- a/src/test/run-pass/generic-temporary.rs
+++ b/src/test/run-pass/generic-temporary.rs
@@ -2,12 +2,12 @@
fn mk() -> int { ret 1; }
-fn chk(&int a) { log a; assert (a == 1); }
+fn chk(a: &int) { log a; assert (a == 1); }
-fn apply[T](fn() -> T produce, fn(&T) consume) { consume(produce()); }
+fn apply[T](produce: fn() -> T , consume: fn(&T) ) { consume(produce()); }
fn main() {
- let fn() -> int produce = mk;
- let fn(&int) consume = chk;
+ let produce: fn() -> int = mk;
+ let consume: fn(&int) = chk;
apply[int](produce, consume);
}
\ No newline at end of file
diff --git a/src/test/run-pass/generic-type-synonym.rs b/src/test/run-pass/generic-type-synonym.rs
index c83e936..b7b720f 100644
--- a/src/test/run-pass/generic-type-synonym.rs
+++ b/src/test/run-pass/generic-type-synonym.rs
@@ -1,9 +1,9 @@
-type foo[T] = rec(T a);
+type foo[T] = {a: T};
type bar[T] = foo[T];
-fn takebar[T](&bar[T] b) { }
+fn takebar[T](b: &bar[T]) { }
fn main() { }
\ No newline at end of file
diff --git a/src/test/run-pass/generic-type.rs b/src/test/run-pass/generic-type.rs
index cdf2ee1..b480b43 100644
--- a/src/test/run-pass/generic-type.rs
+++ b/src/test/run-pass/generic-type.rs
@@ -1,9 +1,9 @@
-type pair[T] = rec(T x, T y);
+type pair[T] = {x: T, y: T};
fn main() {
- let pair[int] x = rec(x=10, y=12);
+ let x: pair[int] = {x: 10, y: 12};
assert (x.x == 10);
assert (x.y == 12);
}
\ No newline at end of file
diff --git a/src/test/run-pass/global-scope.rs b/src/test/run-pass/global-scope.rs
index 6765efe..0c91c49 100644
--- a/src/test/run-pass/global-scope.rs
+++ b/src/test/run-pass/global-scope.rs
@@ -5,10 +5,7 @@
mod foo {
fn f() -> int { ret 2; }
- fn g() {
- assert (f() == 2);
- assert (::f() == 1);
- }
+ fn g() { assert (f() == 2); assert (::f() == 1); }
}
fn main() { ret foo::g(); }
diff --git a/src/test/run-pass/hashmap-memory.rs b/src/test/run-pass/hashmap-memory.rs
index 3414dc0..6470f4d 100644
--- a/src/test/run-pass/hashmap-memory.rs
+++ b/src/test/run-pass/hashmap-memory.rs
@@ -14,53 +14,41 @@
import std::vec;
import std::map;
-fn map(str filename, map_reduce::putter emit) {
- emit(filename, "1");
-}
+fn map(filename: str, emit: map_reduce::putter) { emit(filename, "1"); }
mod map_reduce {
export putter;
export mapper;
export map_reduce;
- type putter = fn(str, str) -> ();
+ type putter = fn(str, str) ;
- type mapper = fn(str, putter);
+ type mapper = fn(str, putter) ;
- tag ctrl_proto {
- find_reducer(str, chan[int]);
- mapper_done;
+ tag ctrl_proto { find_reducer(str, chan[int]); mapper_done; }
+
+ fn start_mappers(ctrl: chan[ctrl_proto], inputs: vec[str]) {
+ for i: str in inputs { spawn map_task(ctrl, i); }
}
- fn start_mappers(chan[ctrl_proto] ctrl,
- vec[str] inputs) {
- for(str i in inputs) {
- spawn map_task(ctrl, i);
- }
- }
+ fn map_task(ctrl: chan[ctrl_proto], input: str) {
- fn map_task(chan[ctrl_proto] ctrl,
- str input) {
+ let intermediates = map::new_str_hash();
- auto intermediates = map::new_str_hash();
-
- fn emit(&map::hashmap[str, int] im,
- chan[ctrl_proto] ctrl,
- str key, str val) {
- auto c;
- alt(im.find(key)) {
- case(some(?_c)) {
- c = _c
- }
- case(none) {
- auto p = port();
- log_err "sending find_reducer";
- ctrl <| find_reducer(key, chan(p));
- log_err "receiving";
- p |> c;
- log_err c;
- im.insert(key, c);
- }
+ fn emit(im: &map::hashmap[str, int], ctrl: chan[ctrl_proto], key: str,
+ val: str) {
+ let c;
+ alt im.find(key) {
+ some(_c) { c = _c }
+ none. {
+ let p = port();
+ log_err "sending find_reducer";
+ ctrl <| find_reducer(key, chan(p));
+ log_err "receiving";
+ p |> c;
+ log_err c;
+ im.insert(key, c);
+ }
}
}
@@ -68,36 +56,33 @@
ctrl <| mapper_done;
}
- fn map_reduce (vec[str] inputs) {
- auto ctrl = port[ctrl_proto]();
+ fn map_reduce(inputs: vec[str]) {
+ let ctrl = port[ctrl_proto]();
// This task becomes the master control task. It spawns others
// to do the rest.
- let map::hashmap[str, int] reducers;
+ let reducers: map::hashmap[str, int];
reducers = map::new_str_hash();
start_mappers(chan(ctrl), inputs);
- auto num_mappers = vec::len(inputs) as int;
+ let num_mappers = vec::len(inputs) as int;
- while(num_mappers > 0) {
- auto m;
+
+ while num_mappers > 0 {
+ let m;
ctrl |> m;
- alt(m) {
- case(mapper_done) { num_mappers -= 1; }
- case(find_reducer(?k, ?cc)) {
- auto c;
- alt(reducers.find(k)) {
- case(some(?_c)) { c = _c; }
- case(none) {
- c = 0;
- }
- }
- cc <| c;
- }
+
+ alt m {
+ mapper_done. { num_mappers -= 1; }
+ find_reducer(k, cc) {
+ let c;
+ alt reducers.find(k) { some(_c) { c = _c; } none. { c = 0; } }
+ cc <| c;
+ }
}
}
}
@@ -105,4 +90,4 @@
fn main() {
map_reduce::map_reduce(["../src/test/run-pass/hashmap-memory.rs"]);
-}
+}
\ No newline at end of file
diff --git a/src/test/run-pass/i32-sub.rs b/src/test/run-pass/i32-sub.rs
index 3bb40f9..a83e95a 100644
--- a/src/test/run-pass/i32-sub.rs
+++ b/src/test/run-pass/i32-sub.rs
@@ -2,4 +2,4 @@
// -*- rust -*-
-fn main() { let i32 x = -400_i32; x = 0_i32 - x; assert (x == 400_i32); }
\ No newline at end of file
+fn main() { let x: i32 = -400_i32; x = 0_i32 - x; assert (x == 400_i32); }
\ No newline at end of file
diff --git a/src/test/run-pass/i8-incr.rs b/src/test/run-pass/i8-incr.rs
index b890a3e..f825d54 100644
--- a/src/test/run-pass/i8-incr.rs
+++ b/src/test/run-pass/i8-incr.rs
@@ -3,8 +3,8 @@
// -*- rust -*-
fn main() {
- let i8 x = -12i8;
- let i8 y = -12i8;
+ let x: i8 = -12i8;
+ let y: i8 = -12i8;
x = x + 1i8;
x = x - 1i8;
assert (x == y);
diff --git a/src/test/run-pass/if-bot.rs b/src/test/run-pass/if-bot.rs
index 5ff8f80..8ef6bab 100644
--- a/src/test/run-pass/if-bot.rs
+++ b/src/test/run-pass/if-bot.rs
@@ -1,3 +1,3 @@
-fn main() { let int i = if (false) { fail } else { 5 }; log i; }
\ No newline at end of file
+fn main() { let i: int = if false { fail } else { 5 }; log i; }
\ No newline at end of file
diff --git a/src/test/run-pass/if-check-precond.rs b/src/test/run-pass/if-check-precond.rs
index 1c61f40..32d9b0e 100644
--- a/src/test/run-pass/if-check-precond.rs
+++ b/src/test/run-pass/if-check-precond.rs
@@ -1,29 +1,12 @@
// xfail-stage0
-pred even(uint x) -> bool {
- if (x < 2u) {
- ret false;
- }
- else if (x == 2u) {
- ret true;
- }
- else {
- ret even(x - 2u);
- }
+pred even(x: uint) -> bool {
+ if x < 2u {
+ ret false;
+ } else if (x == 2u) { ret true; } else { ret even(x - 2u); }
}
-fn print_even(uint x) : even(x) {
- log x;
-}
+fn print_even(x: uint) { log x; }
-fn foo(uint x) -> () {
- if check(even(x)) {
- print_even(x);
- }
- else {
- fail;
- }
-}
+fn foo(x: uint) { if check even(x) { print_even(x); } else { fail; } }
-fn main() {
- foo(2u);
-}
+fn main() { foo(2u); }
\ No newline at end of file
diff --git a/src/test/run-pass/if-check.rs b/src/test/run-pass/if-check.rs
index 6c6c2ac..4840de1 100644
--- a/src/test/run-pass/if-check.rs
+++ b/src/test/run-pass/if-check.rs
@@ -1,25 +1,10 @@
// xfail-stage0
-pred even(uint x) -> bool {
- if (x < 2u) {
- ret false;
- }
- else if (x == 2u) {
- ret true;
- }
- else {
- ret even(x - 2u);
- }
+pred even(x: uint) -> bool {
+ if x < 2u {
+ ret false;
+ } else if (x == 2u) { ret true; } else { ret even(x - 2u); }
}
-fn foo(uint x) -> () {
- if check(even(x)) {
- log x;
- }
- else {
- fail;
- }
-}
+fn foo(x: uint) { if check even(x) { log x; } else { fail; } }
-fn main() {
- foo(2u);
-}
+fn main() { foo(2u); }
\ No newline at end of file
diff --git a/src/test/run-pass/if-ret.rs b/src/test/run-pass/if-ret.rs
index 7d0d165..81cb300 100644
--- a/src/test/run-pass/if-ret.rs
+++ b/src/test/run-pass/if-ret.rs
@@ -1,6 +1,4 @@
// xfail-stage0
-fn foo() {
- if (ret) { }
-}
+fn foo() { if ret { } }
-fn main() { foo(); }
+fn main() { foo(); }
\ No newline at end of file
diff --git a/src/test/run-pass/import-glob-0.rs b/src/test/run-pass/import-glob-0.rs
index 33ca7ca..e5e9ab9 100644
--- a/src/test/run-pass/import-glob-0.rs
+++ b/src/test/run-pass/import-glob-0.rs
@@ -2,47 +2,29 @@
import dug::too::greedily::and::too::deep::*;
mod module_of_many_things {
- export f1;
- export f2;
- export f4;
- fn f1() {
- log "f1";
- }
- fn f2() {
- log "f2";
- }
- fn f3() {
- log "f3";
- }
- fn f4() {
- log "f4";
- }
+ export f1;
+ export f2;
+ export f4;
+ fn f1() { log "f1"; }
+ fn f2() { log "f2"; }
+ fn f3() { log "f3"; }
+ fn f4() { log "f4"; }
}
mod dug {
- mod too {
- mod greedily {
- mod and {
- mod too {
- mod deep {
- fn nameless_fear() {
- log "Boo!";
+ mod too {
+ mod greedily {
+ mod and {
+ mod too {
+ mod deep {
+ fn nameless_fear() { log "Boo!"; }
+ fn also_redstone() { log "Whatever."; }
+ }
+ }
}
- fn also_redstone() {
- log "Whatever.";
- }
- }
}
- }
}
- }
}
-fn main() {
- f1();
- f2();
- f4();
- nameless_fear();
- also_redstone();
-}
\ No newline at end of file
+fn main() { f1(); f2(); f4(); nameless_fear(); also_redstone(); }
\ No newline at end of file
diff --git a/src/test/run-pass/import-glob-1.rs b/src/test/run-pass/import-glob-1.rs
index 62a6ed3..64c5a47 100644
--- a/src/test/run-pass/import-glob-1.rs
+++ b/src/test/run-pass/import-glob-1.rs
@@ -1,29 +1,40 @@
import a1::b1::word_traveler;
-mod a1 { //
- mod b1 { //
- import a2::b1::*; // <-\
- export word_traveler; // |
- } // |
- mod b2 { // |
- import a2::b2::*; // <-\ -\ |
- export word_traveler; // | | |
- } // | | |
-} // | | |
- // | | |
-mod a2 { // | | |
- native mod b1 = "" { // | | |
- import a1::b2::*; // | <-/ -/
- export word_traveler; // |
- } // |
- mod b2 { // |
- fn word_traveler() { // |
- log "ahoy!"; // -/
- } //
- } //
-} //
+mod a1 {
+ //
+ mod b1 {
+ //
+ import a2::b1::*;
+ // <-\
+ export word_traveler; // |
+ }
+ // |
+ mod b2 {
+ // |
+ import a2::b2::*;
+ // <-\ -\ |
+ export word_traveler; // | | |
+ } // | | |
+}
+ // | | |
+ // | | |
+ mod a2 {
+ // | | |
+ native "cdecl" mod b1 = "" {
+ // | | |
+ import a1::b2::*;
+ // | <-/ -/
+ export word_traveler; // |
+ }
+ // |
+ mod b2 {
+ // |
+ fn word_traveler() { // |
+ log "ahoy!"; // -/
+ } //
+ } //
+ }
+ //
-fn main() {
- word_traveler();
-}
\ No newline at end of file
+fn main() { word_traveler(); }
\ No newline at end of file
diff --git a/src/test/run-pass/import-glob-circular.rs b/src/test/run-pass/import-glob-circular.rs
index 66e19a1..bc97c79 100644
--- a/src/test/run-pass/import-glob-circular.rs
+++ b/src/test/run-pass/import-glob-circular.rs
@@ -2,60 +2,49 @@
import test2::*;
mod circ1 {
- import circ1::*;
- export f1;
- export f2;
- export common;
- fn f1() -> uint {
- ret 1u
- }
- fn common() -> uint {
- ret 1u;
- }
+ import circ1::*;
+ export f1;
+ export f2;
+ export common;
+ fn f1() -> uint { ret 1u }
+ fn common() -> uint { ret 1u; }
}
mod circ2 {
- import circ2::*;
- export f1;
- export f2;
- export common;
- fn f2() -> uint {
- ret 2u;
- }
- fn common() -> uint {
- ret 2u;
- }
+ import circ2::*;
+ export f1;
+ export f2;
+ export common;
+ fn f2() -> uint { ret 2u; }
+ fn common() -> uint { ret 2u; }
}
mod test1 {
- import circ1::*;
- fn test1() {
- assert(f1() == 1u);
- //make sure that cached lookups work...
- assert(f1() == 1u);
- //assert(f2() == 2u); //TODO: renable when 'reexport' is implemented
- //assert(f2() == 2u);
- assert(common() == 1u);
- assert(common() == 1u);
- }
+ import circ1::*;
+ fn test1() {
+ assert (f1() == 1u);
+ //make sure that cached lookups work...
+ assert (f1() == 1u);
+ //assert(f2() == 2u); //TODO: renable when 'reexport' is implemented
+ //assert(f2() == 2u);
+ assert (common() == 1u);
+ assert (common() == 1u);
+ }
}
mod test2 {
- import circ2::*;
- fn test2() {
- //assert(f1() == 1u); //TODO: renable when 'reexport' is implemented
- ////make sure that cached lookups work...
- //assert(f1() == 1u);
- assert(f2() == 2u);
- assert(f2() == 2u);
- assert(common() == 2u);
- assert(common() == 2u);
- }
+ import circ2::*;
+ fn test2() {
+ //assert(f1() == 1u); //TODO: renable when 'reexport' is implemented
+ ////make sure that cached lookups work...
+ //assert(f1() == 1u);
+ assert (f2() == 2u);
+ assert (f2() == 2u);
+ assert (common() == 2u);
+ assert (common() == 2u);
+ }
}
-fn main() {
- test1();
- test2();
-}
\ No newline at end of file
+fn main() { test1(); test2(); }
\ No newline at end of file
diff --git a/src/test/run-pass/import-glob-crate.rs b/src/test/run-pass/import-glob-crate.rs
index 8c852f4..8307b7d 100644
--- a/src/test/run-pass/import-glob-crate.rs
+++ b/src/test/run-pass/import-glob-crate.rs
@@ -3,7 +3,7 @@
import std::vec::*;
fn main() {
- auto v = empty[int]();
- v += [4,2];
- assert(reversed(v) == [2,4]);
+ let v = empty[int]();
+ v += [4, 2];
+ assert (reversed(v) == [2, 4]);
}
\ No newline at end of file
diff --git a/src/test/run-pass/import.rs b/src/test/run-pass/import.rs
index f434bcf0..31622c1 100644
--- a/src/test/run-pass/import.rs
+++ b/src/test/run-pass/import.rs
@@ -1,16 +1,11 @@
mod foo {
- fn x(int y) {
- log y;
- }
+ fn x(y: int) { log y; }
}
mod bar {
- import foo::x;
- import z = foo::x;
- fn thing() {
- x(10);
- z(10);
- }
+ import foo::x;
+ import z = foo::x;
+ fn thing() { x(10); z(10); }
}
fn main() { bar::thing(); }
\ No newline at end of file
diff --git a/src/test/run-pass/import4.rs b/src/test/run-pass/import4.rs
index 16c5b4d..c9ada05 100644
--- a/src/test/run-pass/import4.rs
+++ b/src/test/run-pass/import4.rs
@@ -5,4 +5,4 @@
fn bar() { log "bar"; }
}
-fn main(vec[str] args) { auto zed = 42; bar(); }
\ No newline at end of file
+fn main(args: vec[str]) { let zed = 42; bar(); }
\ No newline at end of file
diff --git a/src/test/run-pass/import5.rs b/src/test/run-pass/import5.rs
index b629520..6fdd690 100644
--- a/src/test/run-pass/import5.rs
+++ b/src/test/run-pass/import5.rs
@@ -1,14 +1,10 @@
import foo::bar;
mod foo {
- import zed::bar;
- export bar;
- mod zed {
- fn bar() {
- log "foo";
+ import zed::bar;
+ export bar;
+ mod zed {
+ fn bar() { log "foo"; }
}
- }
}
-fn main(vec[str] args) {
- bar();
-}
+fn main(args: vec[str]) { bar(); }
\ No newline at end of file
diff --git a/src/test/run-pass/import6.rs b/src/test/run-pass/import6.rs
index 5c56b69..bc57537 100644
--- a/src/test/run-pass/import6.rs
+++ b/src/test/run-pass/import6.rs
@@ -1,16 +1,12 @@
import bar::baz;
import foo::zed;
mod foo {
- mod zed {
- fn baz() {
- log "baz";
+ mod zed {
+ fn baz() { log "baz"; }
}
- }
}
mod bar {
- import zed::baz;
- export baz;
+ import zed::baz;
+ export baz;
}
-fn main() {
- baz();
-}
+fn main() { baz(); }
\ No newline at end of file
diff --git a/src/test/run-pass/import7.rs b/src/test/run-pass/import7.rs
index 3970ff5..26a3f68 100644
--- a/src/test/run-pass/import7.rs
+++ b/src/test/run-pass/import7.rs
@@ -1,20 +1,15 @@
import bar::baz;
import foo::zed;
mod foo {
- mod zed {
- fn baz() {
- log "baz";
+ mod zed {
+ fn baz() { log "baz"; }
}
- }
}
mod bar {
- import zed::baz;
- export baz;
- mod foo {
- mod zed {
+ import zed::baz;
+ export baz;
+ mod foo {
+ mod zed { }
}
- }
}
-fn main(vec[str] args) {
- baz();
-}
+fn main(args: vec[str]) { baz(); }
\ No newline at end of file
diff --git a/src/test/run-pass/import8.rs b/src/test/run-pass/import8.rs
index 2588485..ed55934 100644
--- a/src/test/run-pass/import8.rs
+++ b/src/test/run-pass/import8.rs
@@ -3,7 +3,7 @@
import z = foo::x;
mod foo {
- fn x(int y) { log y; }
+ fn x(y: int) { log y; }
}
fn main() { x(10); z(10); }
\ No newline at end of file
diff --git a/src/test/run-pass/infer-fn-tail-expr.rs b/src/test/run-pass/infer-fn-tail-expr.rs
index 342cfef..216516d 100644
--- a/src/test/run-pass/infer-fn-tail-expr.rs
+++ b/src/test/run-pass/infer-fn-tail-expr.rs
@@ -1,9 +1,6 @@
// xfail-stage0
// issue #680
-fn f() -> int[] {
- ~[]
-}
+fn f() -> int[] { ~[] }
-fn main() {
-}
\ No newline at end of file
+fn main() { }
\ No newline at end of file
diff --git a/src/test/run-pass/infinite-loops.rs b/src/test/run-pass/infinite-loops.rs
index be9fed9..8fc53f0 100644
--- a/src/test/run-pass/infinite-loops.rs
+++ b/src/test/run-pass/infinite-loops.rs
@@ -11,19 +11,14 @@
use std;
import std::task::join;
-fn loop(int n) {
- let task t1;
- let task t2;
+fn loop(n: int) {
+ let t1: task;
+ let t2: task;
- if(n > 0) {
- t1 = spawn loop(n - 1);
- t2 = spawn loop(n - 1);
- }
+ if n > 0 { t1 = spawn loop(n - 1); t2 = spawn loop(n - 1); }
- while(true) {}
+
+ while true { }
}
-fn main() {
- let task t = spawn loop(5);
- join(t);
-}
+fn main() { let t: task = spawn loop(5); join(t); }
\ No newline at end of file
diff --git a/src/test/run-pass/int.rs b/src/test/run-pass/int.rs
index 491c8ad..2d2422d 100644
--- a/src/test/run-pass/int.rs
+++ b/src/test/run-pass/int.rs
@@ -2,4 +2,4 @@
// -*- rust -*-
-fn main() { let int x = 10; }
\ No newline at end of file
+fn main() { let x: int = 10; }
\ No newline at end of file
diff --git a/src/test/run-pass/integral-indexing.rs b/src/test/run-pass/integral-indexing.rs
index 2413187..83ae0ec 100644
--- a/src/test/run-pass/integral-indexing.rs
+++ b/src/test/run-pass/integral-indexing.rs
@@ -3,8 +3,8 @@
// This is a testcase for issue #94.
fn main() {
- let vec[int] v = [0, 1, 2, 3, 4, 5];
- let str s = "abcdef";
+ let v: vec[int] = [0, 1, 2, 3, 4, 5];
+ let s: str = "abcdef";
assert (v.(3u) == 3);
assert (v.(3u8) == 3);
assert (v.(3i8) == 3);
diff --git a/src/test/run-pass/interior-vec.rs b/src/test/run-pass/interior-vec.rs
index 7788b7a..4799a04 100644
--- a/src/test/run-pass/interior-vec.rs
+++ b/src/test/run-pass/interior-vec.rs
@@ -3,29 +3,29 @@
import rusti::ivec_len;
native "rust-intrinsic" mod rusti {
- fn ivec_len[T](&T[] v) -> uint;
+ fn ivec_len[T](v: &T[]) -> uint;
}
fn main() {
- let int[] v = ~[];
- assert (ivec_len(v) == 0u); // zero-length
- auto x = ~[ 1, 2 ];
- assert (ivec_len(x) == 2u); // on stack
- auto y = ~[ 1, 2, 3, 4, 5 ];
- assert (ivec_len(y) == 5u); // on heap
+ let v: int[] = ~[];
+ assert (ivec_len(v) == 0u); // zero-length
+ let x = ~[1, 2];
+ assert (ivec_len(x) == 2u); // on stack
+ let y = ~[1, 2, 3, 4, 5];
+ assert (ivec_len(y) == 5u); // on heap
v += ~[];
- assert (ivec_len(v) == 0u); // zero-length append
- x += ~[ 3 ];
- assert (ivec_len(x) == 3u); // on-stack append
- y += ~[ 6, 7, 8, 9 ];
- assert (ivec_len(y) == 9u); // on-heap append
+ assert (ivec_len(v) == 0u); // zero-length append
+ x += ~[3];
+ assert (ivec_len(x) == 3u); // on-stack append
+ y += ~[6, 7, 8, 9];
+ assert (ivec_len(y) == 9u); // on-heap append
- auto vv = v + v;
- assert (ivec_len(vv) == 0u); // zero-length add
- auto xx = x + ~[ 4 ];
- assert (ivec_len(xx) == 4u); // on-stack add
- auto yy = y + ~[ 10, 11 ];
- assert (ivec_len(yy) == 11u); // on-heap add
+ let vv = v + v;
+ assert (ivec_len(vv) == 0u); // zero-length add
+ let xx = x + ~[4];
+ assert (ivec_len(xx) == 4u); // on-stack add
+ let yy = y + ~[10, 11];
+ assert (ivec_len(yy) == 11u); // on-heap add
}
diff --git a/src/test/run-pass/issue-333.rs b/src/test/run-pass/issue-333.rs
index f7be7c4..8df73a3 100644
--- a/src/test/run-pass/issue-333.rs
+++ b/src/test/run-pass/issue-333.rs
@@ -1,12 +1,5 @@
-fn quux[T](&T x) -> T{
- auto f = id[T];
- ret f(x);
-}
+fn quux[T](x: &T) -> T { let f = id[T]; ret f(x); }
-fn id[T](&T x) -> T {
- ret x;
-}
+fn id[T](x: &T) -> T { ret x; }
-fn main() {
- assert quux(10) == 10;
-}
\ No newline at end of file
+fn main() { assert (quux(10) == 10); }
\ No newline at end of file
diff --git a/src/test/run-pass/issue-506.rs b/src/test/run-pass/issue-506.rs
index 1461162..43bbfa3 100644
--- a/src/test/run-pass/issue-506.rs
+++ b/src/test/run-pass/issue-506.rs
@@ -5,10 +5,8 @@
// xfail-stage0
native "rust" mod rustrt {
- fn task_yield();
+ fn task_yield();
}
-fn main() {
- spawn rustrt::task_yield();
-}
+fn main() { spawn rustrt::task_yield(); }
diff --git a/src/test/run-pass/issue-507.rs b/src/test/run-pass/issue-507.rs
index 3d81c85..53585f3 100644
--- a/src/test/run-pass/issue-507.rs
+++ b/src/test/run-pass/issue-507.rs
@@ -9,26 +9,24 @@
import std::task::join;
-fn grandchild(chan[int] c) {
- c <| 42;
-}
+fn grandchild(c: chan[int]) { c <| 42; }
-fn child(chan[int] c) {
- auto _grandchild = spawn grandchild(c);
- join(_grandchild);
+fn child(c: chan[int]) {
+ let _grandchild = spawn grandchild(c);
+ join(_grandchild);
}
fn main() {
- let port[int] p = port();
+ let p: port[int] = port();
- auto _child = spawn child(chan(p));
+ let _child = spawn child(chan(p));
- let int x;
- p |> x;
+ let x: int;
+ p |> x;
- log x;
+ log x;
- assert(x == 42);
+ assert (x == 42);
- join(_child);
-}
+ join(_child);
+}
\ No newline at end of file
diff --git a/src/test/run-pass/issue-687.rs b/src/test/run-pass/issue-687.rs
index aee3495..1a0e938 100644
--- a/src/test/run-pass/issue-687.rs
+++ b/src/test/run-pass/issue-687.rs
@@ -3,26 +3,23 @@
use std;
import std::ivec;
-tag msg {
- closed;
- received(u8[]);
-}
+tag msg { closed; received(u8[]); }
-fn producer(chan[u8[]] c) {
+fn producer(c: chan[u8[]]) {
c <| ~[1u8, 2u8, 3u8, 4u8];
- let u8[] empty = ~[];
+ let empty: u8[] = ~[];
c <| empty;
}
-fn packager(chan[chan[u8[]]] cb, chan[msg] msg) {
- let port[u8[]] p = port();
+fn packager(cb: chan[chan[u8[]]], msg: chan[msg]) {
+ let p: port[u8[]] = port();
cb <| chan(p);
- while (true) {
+ while true {
log "waiting for bytes";
- let u8[] data;
+ let data: u8[];
p |> data;
log "got bytes";
- if (ivec::len[u8](data) == 0u) {
+ if ivec::len[u8](data) == 0u {
log "got empty bytes, quitting";
break;
}
@@ -37,26 +34,24 @@
}
fn main() {
- let port[msg] p = port();
- let port[chan[u8[]]] recv_reader = port();
- auto pack = spawn packager(chan(recv_reader), chan(p));
+ let p: port[msg] = port();
+ let recv_reader: port[chan[u8[]]] = port();
+ let pack = spawn packager(chan(recv_reader), chan(p));
- let chan[u8[]] source_chan;
+ let source_chan: chan[u8[]];
recv_reader |> source_chan;
- let task prod = spawn producer(source_chan);
+ let prod: task = spawn producer(source_chan);
- while (true) {
- let msg msg;
+
+ while true {
+ let msg: msg;
p |> msg;
- alt (msg) {
- case (closed) {
- log "Got close message";
- break;
- }
- case (received(?data)) {
- log "Got data. Length is:";
- log ivec::len[u8](data);
- }
+ alt msg {
+ closed. { log "Got close message"; break; }
+ received(data) {
+ log "Got data. Length is:";
+ log ivec::len[u8](data);
+ }
}
}
-}
+}
\ No newline at end of file
diff --git a/src/test/run-pass/issue-718.rs b/src/test/run-pass/issue-718.rs
index f914de6..577a76f2 100644
--- a/src/test/run-pass/issue-718.rs
+++ b/src/test/run-pass/issue-718.rs
@@ -6,22 +6,16 @@
fn main() {
obj a() {
- fn foo() -> int {
- ret 2;
- }
+ fn foo() -> int { ret 2; }
}
- auto my_a = a();
+ let my_a = a();
- auto my_b = obj() {
- with my_a
- };
+ let my_b = obj () { with my_a };
assert (my_b.foo() == 2);
- auto my_c = obj() {
- with my_b
- };
+ let my_c = obj () { with my_b };
assert (my_c.foo() == 2);
}
diff --git a/src/test/run-pass/item-attributes.rs b/src/test/run-pass/item-attributes.rs
index be43623..8f8770c 100644
--- a/src/test/run-pass/item-attributes.rs
+++ b/src/test/run-pass/item-attributes.rs
@@ -17,20 +17,18 @@
// These are are attributes of the following mod
#[attr1 = "val"]
#[attr2 = "val"]
-mod test_first_item_in_file_mod {
-}
+mod test_first_item_in_file_mod { }
mod test_single_attr_outer {
#[attr = "val"]
- const int x = 10;
+ const x: int = 10;
#[attr = "val"]
- fn f() {}
+ fn f() { }
#[attr = "val"]
- mod mod1 {
- }
+ mod mod1 { }
#[attr = "val"]
native "rust" mod rustrt { }
@@ -47,16 +45,15 @@
#[attr1 = "val"]
#[attr2 = "val"]
- const int x = 10;
+ const x: int = 10;
#[attr1 = "val"]
#[attr2 = "val"]
- fn f() {}
+ fn f() { }
#[attr1 = "val"]
#[attr2 = "val"]
- mod mod1 {
- }
+ mod mod1 { }
#[attr1 = "val"]
#[attr2 = "val"]
@@ -77,16 +74,16 @@
fn f() {
#[attr = "val"]
- const int x = 10;
+ const x: int = 10;
#[attr = "val"]
- fn f() {}
+ fn f() { }
/* FIXME: Issue #493
#[attr = "val"]
mod mod1 {
}
-
+
#[attr = "val"]
native "rust" mod rustrt {
}
@@ -107,18 +104,18 @@
#[attr1 = "val"]
#[attr2 = "val"]
- const int x = 10;
+ const x: int = 10;
#[attr1 = "val"]
#[attr2 = "val"]
- fn f() {}
+ fn f() { }
/* FIXME: Issue #493
#[attr1 = "val"]
#[attr2 = "val"]
mod mod1 {
}
-
+
#[attr1 = "val"]
#[attr2 = "val"]
native "rust" mod rustrt {
@@ -151,8 +148,7 @@
#[attr = "val"];
// This is an attribute of fn f
#[attr = "val"]
- fn f() {
- }
+ fn f() { }
}
}
@@ -164,8 +160,7 @@
// This is an attribute of fn f
#[attr1 = "val"]
#[attr2 = "val"]
- fn f() {
- }
+ fn f() { }
}
}
@@ -176,8 +171,7 @@
fn f() {
#fmt("test%s", "s");
#[attr = "val"]
- fn g() {
- }
+ fn g() { }
}
}
@@ -185,11 +179,8 @@
#[attr]
#[attr(word)]
#[attr(attr(word))]
- #[attr(key1 = "val",
- key2 = "val",
- attr)]
- fn f() {
- }
+ #[attr(key1 = "val", key2 = "val", attr)]
+ fn f() { }
}
mod test_native_items {
@@ -200,7 +191,7 @@
type vbuf;
#[attr]
- fn vec_len[T](vec[T] v) -> uint;
+ fn vec_len[T](v: vec[T]) -> uint;
}
}
@@ -215,11 +206,10 @@
// FIXME (#622): Can't parse a nil literal here
//#[nil = ()];
#[bool = true];
- mod m {}
+ mod m { }
}
-fn main() {
-}
+fn main() { }
//
// Local Variables:
diff --git a/src/test/run-pass/iter-range.rs b/src/test/run-pass/iter-range.rs
index e1c97af..8b22a43 100644
--- a/src/test/run-pass/iter-range.rs
+++ b/src/test/run-pass/iter-range.rs
@@ -1,13 +1,13 @@
-iter range(int a, int b) -> int {
+iter range(a: int, b: int) -> int {
assert (a < b);
- let int i = a;
- while (i < b) { put i; i += 1; }
+ let i: int = a;
+ while i < b { put i; i += 1; }
}
fn main() {
- let int sum = 0;
- for each (int x in range(0, 100)) { sum += x; }
+ let sum: int = 0;
+ for each x: int in range(0, 100) { sum += x; }
log sum;
}
\ No newline at end of file
diff --git a/src/test/run-pass/iter-ret.rs b/src/test/run-pass/iter-ret.rs
index 5df91d2..ff68fc6 100644
--- a/src/test/run-pass/iter-ret.rs
+++ b/src/test/run-pass/iter-ret.rs
@@ -2,6 +2,6 @@
iter x() -> int { }
-fn f() -> bool { for each (int i in x()) { ret true; } ret false; }
+fn f() -> bool { for each i: int in x() { ret true; } ret false; }
-fn main(vec[str] args) { f(); }
\ No newline at end of file
+fn main(args: vec[str]) { f(); }
\ No newline at end of file
diff --git a/src/test/run-pass/ivec-add.rs b/src/test/run-pass/ivec-add.rs
index ad22c6c..09e58c4 100644
--- a/src/test/run-pass/ivec-add.rs
+++ b/src/test/run-pass/ivec-add.rs
@@ -1,11 +1,11 @@
// xfail-stage0
-fn double[T](&T a) -> T[] { ret ~[a] + ~[a]; }
+fn double[T](a: &T) -> T[] { ret ~[a] + ~[a]; }
-fn double_int(int a) -> int[] { ret ~[a] + ~[a]; }
+fn double_int(a: int) -> int[] { ret ~[a] + ~[a]; }
fn main() {
- auto d = double(1);
+ let d = double(1);
assert (d.(0) == 1);
assert (d.(1) == 1);
diff --git a/src/test/run-pass/ivec-pass-by-value.rs b/src/test/run-pass/ivec-pass-by-value.rs
index 0badde5..49caca9 100644
--- a/src/test/run-pass/ivec-pass-by-value.rs
+++ b/src/test/run-pass/ivec-pass-by-value.rs
@@ -1,5 +1,5 @@
// xfail-stage0
-fn f(int[] a) {}
-fn main() { f(~[ 1, 2, 3, 4, 5 ]); }
+fn f(a: int[]) { }
+fn main() { f(~[1, 2, 3, 4, 5]); }
diff --git a/src/test/run-pass/join.rs b/src/test/run-pass/join.rs
index 7830214..ee8ec4e 100644
--- a/src/test/run-pass/join.rs
+++ b/src/test/run-pass/join.rs
@@ -6,13 +6,11 @@
import std::task::*;
fn main() {
- auto other = spawn child();
- log_err "1";
- yield();
- join(other);
- log_err "3";
+ let other = spawn child();
+ log_err "1";
+ yield();
+ join(other);
+ log_err "3";
}
-fn child() {
- log_err "2";
-}
+fn child() { log_err "2"; }
\ No newline at end of file
diff --git a/src/test/run-pass/large-records.rs b/src/test/run-pass/large-records.rs
index fb38efd..004e3a8 100644
--- a/src/test/run-pass/large-records.rs
+++ b/src/test/run-pass/large-records.rs
@@ -3,19 +3,31 @@
// -*- rust -*-
fn f() {
- let rec(int a,
- int b,
- int c,
- int d,
- int e,
- int f,
- int g,
- int h,
- int i,
- int j,
- int k,
- int l) foo =
- rec(a=0, b=0, c=0, d=0, e=0, f=0, g=0, h=0, i=0, j=0, k=0, l=0);
+ let foo:
+ {a: int,
+ b: int,
+ c: int,
+ d: int,
+ e: int,
+ f: int,
+ g: int,
+ h: int,
+ i: int,
+ j: int,
+ k: int,
+ l: int} =
+ {a: 0,
+ b: 0,
+ c: 0,
+ d: 0,
+ e: 0,
+ f: 0,
+ g: 0,
+ h: 0,
+ i: 0,
+ j: 0,
+ k: 0,
+ l: 0};
}
fn main() { f(); }
\ No newline at end of file
diff --git a/src/test/run-pass/lazy-and-or.rs b/src/test/run-pass/lazy-and-or.rs
index 613f7fd..348ce5d 100644
--- a/src/test/run-pass/lazy-and-or.rs
+++ b/src/test/run-pass/lazy-and-or.rs
@@ -1,12 +1,12 @@
-fn incr(&mutable int x) -> bool { x += 1; assert (false); ret false; }
+fn incr(x: &mutable int) -> bool { x += 1; assert (false); ret false; }
fn main() {
- auto x = 1 == 2 || 3 == 3;
+ let x = 1 == 2 || 3 == 3;
assert (x);
- let int y = 10;
+ let y: int = 10;
log x || incr(y);
assert (y == 10);
- if (true && x) { assert (true); } else { assert (false); }
+ if true && x { assert (true); } else { assert (false); }
}
\ No newline at end of file
diff --git a/src/test/run-pass/lazy-init.rs b/src/test/run-pass/lazy-init.rs
index 3b65277..d36ad1b 100644
--- a/src/test/run-pass/lazy-init.rs
+++ b/src/test/run-pass/lazy-init.rs
@@ -1,5 +1,5 @@
-fn foo(int x) { log x; }
+fn foo(x: int) { log x; }
-fn main() { let int x; if (1 > 2) { x = 12; } else { x = 10; } foo(x); }
\ No newline at end of file
+fn main() { let x: int; if 1 > 2 { x = 12; } else { x = 10; } foo(x); }
\ No newline at end of file
diff --git a/src/test/run-pass/lazychan.rs b/src/test/run-pass/lazychan.rs
index 96a00a6..3b98692 100644
--- a/src/test/run-pass/lazychan.rs
+++ b/src/test/run-pass/lazychan.rs
@@ -2,23 +2,21 @@
// -*- rust -*-
fn main() {
- let port[int] p = port();
- auto c = chan(p);
- let int y;
+ let p: port[int] = port();
+ let c = chan(p);
+ let y: int;
- spawn child(c);
- p |> y;
- log "received 1";
- log y;
- assert (y == 10);
+ spawn child(c);
+ p |> y;
+ log "received 1";
+ log y;
+ assert (y == 10);
- spawn child(c);
- p |> y;
- log "received 2";
- log y;
- assert (y == 10);
+ spawn child(c);
+ p |> y;
+ log "received 2";
+ log y;
+ assert (y == 10);
}
-fn child(chan[int] c) {
- c <| 10;
-}
+fn child(c: chan[int]) { c <| 10; }
\ No newline at end of file
diff --git a/src/test/run-pass/leak-box-as-tydesc.rs b/src/test/run-pass/leak-box-as-tydesc.rs
index c791718..d71aa10 100644
--- a/src/test/run-pass/leak-box-as-tydesc.rs
+++ b/src/test/run-pass/leak-box-as-tydesc.rs
@@ -1,5 +1,5 @@
-fn leaky[T](&T t) { }
+fn leaky[T](t: &T) { }
-fn main() { auto x = @10; leaky[@int](x); }
\ No newline at end of file
+fn main() { let x = @10; leaky[@int](x); }
\ No newline at end of file
diff --git a/src/test/run-pass/leak-tag-copy.rs b/src/test/run-pass/leak-tag-copy.rs
index 3b4f202..48b1117 100644
--- a/src/test/run-pass/leak-tag-copy.rs
+++ b/src/test/run-pass/leak-tag-copy.rs
@@ -2,4 +2,4 @@
tag t { a; b(@int); }
-fn main() { auto x = b(@10); x = a; }
\ No newline at end of file
+fn main() { let x = b(@10); x = a; }
\ No newline at end of file
diff --git a/src/test/run-pass/linear-for-loop.rs b/src/test/run-pass/linear-for-loop.rs
index 89b7aeb..379693a 100644
--- a/src/test/run-pass/linear-for-loop.rs
+++ b/src/test/run-pass/linear-for-loop.rs
@@ -1,19 +1,19 @@
fn main() {
- auto x = [1, 2, 3];
- auto y = 0;
- for (int i in x) { log i; y += i; }
+ let x = [1, 2, 3];
+ let y = 0;
+ for i: int in x { log i; y += i; }
log y;
assert (y == 6);
- auto s = "hello there";
- let int i = 0;
- for (u8 c in s) {
- if (i == 0) { assert (c == 'h' as u8); }
- if (i == 1) { assert (c == 'e' as u8); }
- if (i == 2) { assert (c == 'l' as u8); }
- if (i == 3) { assert (c == 'l' as u8); }
- if (i == 4) { assert (c == 'o' as u8); }
+ let s = "hello there";
+ let i: int = 0;
+ for c: u8 in s {
+ if i == 0 { assert (c == 'h' as u8); }
+ if i == 1 { assert (c == 'e' as u8); }
+ if i == 2 { assert (c == 'l' as u8); }
+ if i == 3 { assert (c == 'l' as u8); }
+ if i == 4 { assert (c == 'o' as u8); }
// ...
i += 1;
diff --git a/src/test/run-pass/log-err-phi.rs b/src/test/run-pass/log-err-phi.rs
index aa511bc..0623dae 100644
--- a/src/test/run-pass/log-err-phi.rs
+++ b/src/test/run-pass/log-err-phi.rs
@@ -1,3 +1,3 @@
-fn main() { if (false) { log_err "foo" + "bar"; } }
\ No newline at end of file
+fn main() { if false { log_err "foo" + "bar"; } }
\ No newline at end of file
diff --git a/src/test/run-pass/long-while.rs b/src/test/run-pass/long-while.rs
index 57e8492..59cbd10 100644
--- a/src/test/run-pass/long-while.rs
+++ b/src/test/run-pass/long-while.rs
@@ -1,3 +1,3 @@
-fn main() { let int i = 0; while (i < 1000000) { i += 1; auto x = 3; } }
\ No newline at end of file
+fn main() { let i: int = 0; while i < 1000000 { i += 1; let x = 3; } }
\ No newline at end of file
diff --git a/src/test/run-pass/loop-scope.rs b/src/test/run-pass/loop-scope.rs
index 0a7c155..1c61a85 100644
--- a/src/test/run-pass/loop-scope.rs
+++ b/src/test/run-pass/loop-scope.rs
@@ -1,6 +1,6 @@
fn main() {
- auto x = ~[10, 20, 30];
- auto sum = 0;
- for (auto x in x) { sum += x; }
- assert sum == 60;
-}
+ let x = ~[10, 20, 30];
+ let sum = 0;
+ for x in x { sum += x; }
+ assert (sum == 60);
+}
\ No newline at end of file
diff --git a/src/test/run-pass/macro-2.rs b/src/test/run-pass/macro-2.rs
index debf327..13cc026 100644
--- a/src/test/run-pass/macro-2.rs
+++ b/src/test/run-pass/macro-2.rs
@@ -1,7 +1,11 @@
// xfail-stage0
fn main() {
- #macro([#mylambda(x,body), {fn f(int x) -> int { ret body }; f}]);
+ #macro([#mylambda(x, body),
+ {
+ fn f(x: int) -> int { ret body }
+ f
+ }]);
- assert(#mylambda(y,y*2)(8) == 16);
+ assert (#mylambda(y, y * 2)(8) == 16);
}
\ No newline at end of file
diff --git a/src/test/run-pass/macro-3.rs b/src/test/run-pass/macro-3.rs
index c14d894..25098f3 100644
--- a/src/test/run-pass/macro-3.rs
+++ b/src/test/run-pass/macro-3.rs
@@ -1,7 +1,7 @@
// xfail-stage0
fn main() {
- #macro([#trivial(), 1*2*4*2*1]);
+ #macro([#trivial, 1 * 2 * 4 * 2 * 1]);
- assert(#trivial() == 16);
-}
+ assert (#trivial == 16);
+}
\ No newline at end of file
diff --git a/src/test/run-pass/macro-by-example-1.rs b/src/test/run-pass/macro-by-example-1.rs
index d557ce5..ef12704 100644
--- a/src/test/run-pass/macro-by-example-1.rs
+++ b/src/test/run-pass/macro-by-example-1.rs
@@ -1,9 +1,7 @@
fn main() {
- #macro([#apply(f,[x,...]), f(x, ...)]);
+ #macro([#apply(f, [x, ...]), f(x, ...)]);
- fn add(int a, int b) -> int {
- ret a+b;
- }
+ fn add(a: int, b: int) -> int { ret a + b; }
- assert(#apply(add, [1, 15]) == 16);
+ assert (#apply(add, [1, 15]) == 16);
}
\ No newline at end of file
diff --git a/src/test/run-pass/macro-by-example-2.rs b/src/test/run-pass/macro-by-example-2.rs
index 4c459fab..036bd77 100644
--- a/src/test/run-pass/macro-by-example-2.rs
+++ b/src/test/run-pass/macro-by-example-2.rs
@@ -3,26 +3,32 @@
[#zip_or_unzip([[xx, yy], ...]), [[xx, ...], [yy, ...]]]);
- assert(#zip_or_unzip([[1,2,3,4],[5,6,7,8]]) == [[1,5],[2,6],[3,7],[4,8]]);
- assert(#zip_or_unzip([[1,5],[2,6],[3,7],[4,8]]) == [[1,2,3,4],[5,6,7,8]]);
+ assert (#zip_or_unzip([[1, 2, 3, 4], [5, 6, 7, 8]]) ==
+ [[1, 5], [2, 6], [3, 7], [4, 8]]);
+ assert (#zip_or_unzip([[1, 5], [2, 6], [3, 7], [4, 8]]) ==
+ [[1, 2, 3, 4], [5, 6, 7, 8]]);
#macro([#nested([[[x, ...], ...], [[y, ...], ...]]),
[[[x, y], ...], ...]]);
- assert(#nested([[[1,2,3,4,5], [7,8,9,10,11,12]],
- [[-1,-2,-3,-4,-5], [-7,-8,-9,-10,-11,-12]]])
- ==
- [[[1, -1], [2, -2], [3, -3], [4, -4], [5, -5]],
- [[7, -7], [8, -8], [9, -9], [10, -10], [11, -11], [12, -12]]]);
+ assert (#nested([[[1, 2, 3, 4, 5], [7, 8, 9, 10, 11, 12]],
+ [[-1, -2, -3, -4, -5], [-7, -8, -9, -10, -11, -12]]]) ==
+ [[[1, -1], [2, -2], [3, -3], [4, -4], [5, -5]],
+ [[7, -7], [8, -8], [9, -9], [10, -10], [11, -11],
+ [12, -12]]]);
#macro([#dup([y, [x, ...]]), [[y, x], ...]]);
- assert(#dup([1,[1,2,3,4]]) == [[1,1], [1,2], [1,3], [1,4]]);
+ assert (#dup([1, [1, 2, 3, 4]]) == [[1, 1], [1, 2], [1, 3], [1, 4]]);
#macro([#lambda(x, #<t>, body, #<s>),
- {fn result(t x) -> s { ret body }; result}]);
+ {
+ fn result(x: t) -> s { ret body }
+ result
+ }]);
- assert(#lambda(i, #<uint>, i+4u, #<uint>)(12u) == 16u)
+
+ assert (#lambda(i, #<uint>, i + 4u, #<uint>)(12u) == 16u)
}
\ No newline at end of file
diff --git a/src/test/run-pass/macro.rs b/src/test/run-pass/macro.rs
index 869e940..688723b 100644
--- a/src/test/run-pass/macro.rs
+++ b/src/test/run-pass/macro.rs
@@ -1,6 +1,3 @@
// xfail-stage0
-fn main() {
- #macro([#m1(a), a*4]);
- assert (#m1(2) == 8);
-}
\ No newline at end of file
+fn main() { #macro([#m1(a), a * 4]); assert (#m1(2) == 8); }
\ No newline at end of file
diff --git a/src/test/run-pass/many.rs b/src/test/run-pass/many.rs
index 6affa16..9213799 100644
--- a/src/test/run-pass/many.rs
+++ b/src/test/run-pass/many.rs
@@ -1,25 +1,6 @@
-// xfail-stage0
-// xfail-stage1
-// xfail-stage2
-// xfail-stage3
-// -*- rust -*-
-
-fn sub(chan[int] parent, int id) {
- if (id == 0) {
- parent <| 0;
- } else {
- let port[int] p = port();
- auto child = spawn sub(chan(p), id-1);
- let int y; p |> y;
- parent <| y + 1;
- }
-}
-
-fn main() {
- let port[int] p = port();
- auto child = spawn sub(chan(p), 500);
- let int p |> y;
- log "transmission complete";
- log y;
- assert (y == 500);
-}
+./src/test/run-pass/many.rs:21:12:21:14: [1;31merror:[0m expecting ;, found |>
+./src/test/run-pass/many.rs:21 let int p |> y;
+ ^~
+rt: ---
+rt: f00e:main:main: upcall fail 'explicit failure', src/comp/syntax/parse/parser.rs:112
+rt: f00e:main: domain main @0x8da604c root task failed
diff --git a/src/test/run-pass/maybe-mutable.rs b/src/test/run-pass/maybe-mutable.rs
index 2299421..c6a907e 100644
--- a/src/test/run-pass/maybe-mutable.rs
+++ b/src/test/run-pass/maybe-mutable.rs
@@ -2,15 +2,15 @@
// -*- rust -*-
-fn len(vec[mutable? int] v) -> uint {
- auto i = 0u;
- for (int x in v) { i += 1u; }
+fn len(v: vec[mutable? int]) -> uint {
+ let i = 0u;
+ for x: int in v { i += 1u; }
ret i;
}
fn main() {
- auto v0 = [1, 2, 3, 4, 5];
+ let v0 = [1, 2, 3, 4, 5];
log len(v0);
- auto v1 = [mutable 1, 2, 3, 4, 5];
+ let v1 = [mutable 1, 2, 3, 4, 5];
log len(v1);
}
\ No newline at end of file
diff --git a/src/test/run-pass/mlist-cycle.rs b/src/test/run-pass/mlist-cycle.rs
index d4161f8..5a6aa21 100644
--- a/src/test/run-pass/mlist-cycle.rs
+++ b/src/test/run-pass/mlist-cycle.rs
@@ -7,14 +7,14 @@
// -*- rust -*-
use std;
-type cell = rec(mutable @list c);
+type cell = {mutable c: @list};
tag list { link(@cell); nil; }
fn main() {
- let @cell first = @rec(mutable c=@nil());
- let @cell second = @rec(mutable c=@link(first));
+ let first: @cell = @{mutable c: @nil()};
+ let second: @cell = @{mutable c: @link(first)};
first._0 = @link(second);
std::sys.rustrt.gc();
- let @cell third = @rec(mutable c=@nil());
+ let third: @cell = @{mutable c: @nil()};
}
\ No newline at end of file
diff --git a/src/test/run-pass/mod-view-items.rs b/src/test/run-pass/mod-view-items.rs
index b5041f1..852a124 100644
--- a/src/test/run-pass/mod-view-items.rs
+++ b/src/test/run-pass/mod-view-items.rs
@@ -5,11 +5,9 @@
// begin failing.
mod m {
- use std;
- import std::vec;
- fn f() -> vec[int] { vec::empty[int]() }
+ use std;
+ import std::vec;
+ fn f() -> vec[int] { vec::empty[int]() }
}
-fn main() {
- auto x = m::f();
-}
\ No newline at end of file
+fn main() { let x = m::f(); }
\ No newline at end of file
diff --git a/src/test/run-pass/move-1.rs b/src/test/run-pass/move-1.rs
index cdd93f1..d0dcc0b 100644
--- a/src/test/run-pass/move-1.rs
+++ b/src/test/run-pass/move-1.rs
@@ -1,18 +1,14 @@
-fn test(bool x, @rec(int x, int y, int z) foo) -> int {
- auto bar = foo;
- let @rec(int x,int y, int z) y;
- if (x) {
- y <- bar;
- } else {
- y = @rec(x=4, y=5, z=6);
- }
+fn test(x: bool, foo: @{x: int, y: int, z: int}) -> int {
+ let bar = foo;
+ let y: @{x: int, y: int, z: int};
+ if x { y <- bar; } else { y = @{x: 4, y: 5, z: 6}; }
ret y.y;
}
fn main() {
- auto x = @rec(x=1, y=2, z=3);
+ let x = @{x: 1, y: 2, z: 3};
assert (test(true, x) == 2);
assert (test(true, x) == 2);
assert (test(true, x) == 2);
assert (test(false, x) == 5);
-}
+}
\ No newline at end of file
diff --git a/src/test/run-pass/move-2.rs b/src/test/run-pass/move-2.rs
index 9534781..0f36f5f 100644
--- a/src/test/run-pass/move-2.rs
+++ b/src/test/run-pass/move-2.rs
@@ -1,7 +1,3 @@
-fn main() {
- auto x = @rec(x=1, y=2, z=3);
- auto y <- x;
- assert (y.y == 2);
-}
\ No newline at end of file
+fn main() { let x = @{x: 1, y: 2, z: 3}; let y <- x; assert (y.y == 2); }
\ No newline at end of file
diff --git a/src/test/run-pass/move-3.rs b/src/test/run-pass/move-3.rs
index 0e2cf48..97d1bd7 100644
--- a/src/test/run-pass/move-3.rs
+++ b/src/test/run-pass/move-3.rs
@@ -1,21 +1,17 @@
use std;
import std::uint;
-fn test(bool x, @rec(int x, int y, int z) foo) -> int {
- auto bar = foo;
- let @rec(int x, int y, int z) y;
- if (x) {
- y <- bar;
- } else {
- y = @rec(x=4, y=5, z=6);
- }
+fn test(x: bool, foo: @{x: int, y: int, z: int}) -> int {
+ let bar = foo;
+ let y: @{x: int, y: int, z: int};
+ if x { y <- bar; } else { y = @{x: 4, y: 5, z: 6}; }
ret y.y;
}
fn main() {
- auto x = @rec(x=1, y=2, z=3);
- for each (uint i in uint::range(0u, 10000u)) {
+ let x = @{x: 1, y: 2, z: 3};
+ for each i: uint in uint::range(0u, 10000u) {
assert (test(true, x) == 2);
}
assert (test(false, x) == 5);
-}
+}
\ No newline at end of file
diff --git a/src/test/run-pass/move-4.rs b/src/test/run-pass/move-4.rs
index fe3dcd2..6fc6c6b 100644
--- a/src/test/run-pass/move-4.rs
+++ b/src/test/run-pass/move-4.rs
@@ -2,15 +2,11 @@
use std;
import std::uint;
-fn test(@rec(int a, int b, int c) foo) -> @rec(int a, int b, int c) {
- auto bar <- foo;
- auto baz <- bar;
- auto quux <- baz;
+fn test(foo: @{a: int, b: int, c: int}) -> @{a: int, b: int, c: int} {
+ let bar <- foo;
+ let baz <- bar;
+ let quux <- baz;
ret quux;
}
-fn main() {
- auto x = @rec(a=1, b=2, c=3);
- auto y = test(x);
- assert (y.c == 3);
-}
\ No newline at end of file
+fn main() { let x = @{a: 1, b: 2, c: 3}; let y = test(x); assert (y.c == 3); }
\ No newline at end of file
diff --git a/src/test/run-pass/move-scalar.rs b/src/test/run-pass/move-scalar.rs
index bc96c7a..2a2c805 100644
--- a/src/test/run-pass/move-scalar.rs
+++ b/src/test/run-pass/move-scalar.rs
@@ -1,7 +1,7 @@
fn main() {
- let int y = 42;
- let int x;
- x <- y;
- assert (x == 42);
+ let y: int = 42;
+ let x: int;
+ x <- y;
+ assert (x == 42);
}
\ No newline at end of file
diff --git a/src/test/run-pass/mutable-alias-vec.rs b/src/test/run-pass/mutable-alias-vec.rs
index 4ca2637..38ecc1f 100644
--- a/src/test/run-pass/mutable-alias-vec.rs
+++ b/src/test/run-pass/mutable-alias-vec.rs
@@ -3,14 +3,14 @@
// -*- rust -*-
use std;
-fn grow(&mutable vec[int] v) { v += [1]; }
+fn grow(v: &mutable vec[int]) { v += [1]; }
fn main() {
- let vec[int] v = [];
+ let v: vec[int] = [];
grow(v);
grow(v);
grow(v);
- auto len = std::vec::len[int](v);
+ let len = std::vec::len[int](v);
log len;
assert (len == 3 as uint);
}
\ No newline at end of file
diff --git a/src/test/run-pass/mutable-vec-drop.rs b/src/test/run-pass/mutable-vec-drop.rs
index ade3ae6..d25ef7c 100644
--- a/src/test/run-pass/mutable-vec-drop.rs
+++ b/src/test/run-pass/mutable-vec-drop.rs
@@ -1,6 +1,6 @@
fn main() {
// This just tests whether the vec leaks its members.
- let vec[mutable @rec(int a, int b)] pvec =
- [mutable @rec(a=1, b=2), @rec(a=3, b=4), @rec(a=5, b=6)];
+ let pvec: vec[mutable @{a: int, b: int}] =
+ [mutable @{a: 1, b: 2}, @{a: 3, b: 4}, @{a: 5, b: 6}];
}
\ No newline at end of file
diff --git a/src/test/run-pass/native-mod-src/inner.rs b/src/test/run-pass/native-mod-src/inner.rs
index e3d514e..0842fcb 100644
--- a/src/test/run-pass/native-mod-src/inner.rs
+++ b/src/test/run-pass/native-mod-src/inner.rs
@@ -3,10 +3,10 @@
// -*- rust -*-
fn main() {
- auto f = "Makefile";
- auto s = rustrt.str_buf(f);
- auto buf = libc.malloc(1024);
- auto fd = libc.open(s, 0, 0);
+ let f = "Makefile";
+ let s = rustrt.str_buf(f);
+ let buf = libc.malloc(1024);
+ let fd = libc.open(s, 0, 0);
libc.read(fd, buf, 1024);
libc.write(1, buf, 1024);
libc.close(fd);
diff --git a/src/test/run-pass/native2.rs b/src/test/run-pass/native2.rs
index d034404..e0916da 100644
--- a/src/test/run-pass/native2.rs
+++ b/src/test/run-pass/native2.rs
@@ -2,7 +2,7 @@
native "rust" mod rustrt {
type vbuf;
- fn vec_buf[T](vec[T] v, uint offset) -> vbuf;
+ fn vec_buf[T](v: vec[T], offset: uint) -> vbuf;
}
native "rust" mod bar = "" { }
@@ -10,9 +10,9 @@
native "cdecl" mod zed = "" { }
native "cdecl" mod libc = "" {
- fn write(int fd, rustrt::vbuf buf, uint count) -> int;
+ fn write(fd: int, buf: rustrt::vbuf, count: uint) -> int;
}
native "cdecl" mod baz = "" { }
-fn main(vec[str] args) { }
\ No newline at end of file
+fn main(args: vec[str]) { }
\ No newline at end of file
diff --git a/src/test/run-pass/nested-alts.rs b/src/test/run-pass/nested-alts.rs
index 3e63ca0..5d7b3d7 100644
--- a/src/test/run-pass/nested-alts.rs
+++ b/src/test/run-pass/nested-alts.rs
@@ -5,16 +5,13 @@
fn baz() -> ! { fail; }
fn foo() {
- alt (some[int](5)) {
- case (some[int](?x)) {
- auto bar;
- alt (none[int]) {
- case (none[int]) { bar = 5; }
- case (_) { baz(); }
- }
- log bar;
- }
- case (none[int]) { log "hello"; }
+ alt some[int](5) {
+ some[int](x) {
+ let bar;
+ alt none[int] { none[int]. { bar = 5; } _ { baz(); } }
+ log bar;
+ }
+ none[int]. { log "hello"; }
}
}
diff --git a/src/test/run-pass/nested-obj-self.rs b/src/test/run-pass/nested-obj-self.rs
index 54b628c..3ed72d8 100644
--- a/src/test/run-pass/nested-obj-self.rs
+++ b/src/test/run-pass/nested-obj-self.rs
@@ -5,24 +5,24 @@
fn m1() -> str { ret "foo.m1"; }
fn m2() -> str { ret self.m1(); }
fn m3() -> str {
- let str s1 = self.m2();
+ let s1: str = self.m2();
assert (s1 == "foo.m1");
obj bar() {
fn m1() -> str { ret "bar.m1"; }
fn m2() -> str { ret self.m1(); }
}
- auto b = bar();
- let str s3 = b.m2();
- let str s4 = self.m2();
+ let b = bar();
+ let s3: str = b.m2();
+ let s4: str = self.m2();
assert (s4 == "foo.m1");
ret s3;
}
}
- auto a = foo();
- let str s1 = a.m1();
+ let a = foo();
+ let s1: str = a.m1();
assert (s1 == "foo.m1");
- let str s2 = a.m2();
+ let s2: str = a.m2();
assert (s2 == "foo.m1");
- let str s3 = a.m3();
+ let s3: str = a.m3();
assert (s3 == "bar.m1");
}
\ No newline at end of file
diff --git a/src/test/run-pass/nested-pattern.rs b/src/test/run-pass/nested-pattern.rs
index 3bf982b..dba2d6a 100644
--- a/src/test/run-pass/nested-pattern.rs
+++ b/src/test/run-pass/nested-pattern.rs
@@ -8,13 +8,10 @@
tag t { foo(int, uint); bar(int, option::t[int]); }
-fn nested(t o) {
- alt (o) {
- case (bar(?i, some[int](_))) {
- log_err "wrong pattern matched";
- fail;
- }
- case (_) { log_err "succeeded"; }
+fn nested(o: t) {
+ alt o {
+ bar(i, some[int](_)) { log_err "wrong pattern matched"; fail; }
+ _ { log_err "succeeded"; }
}
}
diff --git a/src/test/run-pass/newtype-polymorphic.rs b/src/test/run-pass/newtype-polymorphic.rs
index efbcb51..f612812 100644
--- a/src/test/run-pass/newtype-polymorphic.rs
+++ b/src/test/run-pass/newtype-polymorphic.rs
@@ -1,16 +1,12 @@
tag myvec[X] = vec[X];
-fn myvec_deref[X](&myvec[X] mv) -> vec[X] {
- ret *mv;
-}
+fn myvec_deref[X](mv: &myvec[X]) -> vec[X] { ret *mv; }
-fn myvec_elt[X](&myvec[X] mv) -> X {
- ret mv.(0);
-}
+fn myvec_elt[X](mv: &myvec[X]) -> X { ret mv.(0); }
fn main() {
- auto mv = myvec([1, 2, 3]);
- assert(myvec_deref(mv).(1) == 2);
- assert(myvec_elt(mv) == 1);
- assert(mv.(2) == 3);
-}
+ let mv = myvec([1, 2, 3]);
+ assert (myvec_deref(mv).(1) == 2);
+ assert (myvec_elt(mv) == 1);
+ assert (mv.(2) == 3);
+}
\ No newline at end of file
diff --git a/src/test/run-pass/newtype.rs b/src/test/run-pass/newtype.rs
index 7f8cb3b..b0e67f4 100644
--- a/src/test/run-pass/newtype.rs
+++ b/src/test/run-pass/newtype.rs
@@ -1,10 +1,8 @@
-tag mytype = rec(fn (&mytype i) -> int compute, int val);
+tag mytype = {compute: fn(&mytype) -> int , val: int};
-fn compute(&mytype i) -> int {
- ret i.val + 20;
-}
+fn compute(i: &mytype) -> int { ret i.val + 20; }
fn main() {
- auto myval = mytype(rec(compute=compute, val=30));
- assert(myval.compute(myval) == 50);
-}
+ let myval = mytype({compute: compute, val: 30});
+ assert (myval.compute(myval) == 50);
+}
\ No newline at end of file
diff --git a/src/test/run-pass/nil-pattern.rs b/src/test/run-pass/nil-pattern.rs
index 63f0787..92ede8d 100644
--- a/src/test/run-pass/nil-pattern.rs
+++ b/src/test/run-pass/nil-pattern.rs
@@ -1,8 +1,2 @@
// xfail-stage0
-fn main() {
- auto x = ();
- alt (x) {
- case (()) {
- }
- }
-}
+fn main() { let x = (); alt x { () { } } }
\ No newline at end of file
diff --git a/src/test/run-pass/obj-as.rs b/src/test/run-pass/obj-as.rs
index ba329e6..2c5f0ac 100644
--- a/src/test/run-pass/obj-as.rs
+++ b/src/test/run-pass/obj-as.rs
@@ -17,10 +17,10 @@
};
fn main() {
- let big b = big();
+ let b: big = big();
assert (b.one() == 1);
assert (b.two() == 2);
assert (b.three() == 3);
- let small s = b as small;
+ let s: small = b as small;
assert (s.one() == 1);
}
\ No newline at end of file
diff --git a/src/test/run-pass/obj-drop.rs b/src/test/run-pass/obj-drop.rs
index 90a5035..b807fe3 100644
--- a/src/test/run-pass/obj-drop.rs
+++ b/src/test/run-pass/obj-drop.rs
@@ -1,8 +1,8 @@
fn main() {
- obj handle(@int i) { }
+ obj handle(i: @int) { }
// This just tests whether the obj leaks its box state members.
- auto ob = handle(@0xf00f00);
+ let ob = handle(@0xf00f00);
}
\ No newline at end of file
diff --git a/src/test/run-pass/obj-dtor-2.rs b/src/test/run-pass/obj-dtor-2.rs
index 4797fcc..ed018c2 100644
--- a/src/test/run-pass/obj-dtor-2.rs
+++ b/src/test/run-pass/obj-dtor-2.rs
@@ -1,9 +1,9 @@
-obj foo(@mutable int x) {drop { log "running dtor"; *x = *x + 1; } }
+obj foo(x: @mutable int) {drop { log "running dtor"; *x = *x + 1; } }
fn main() {
- auto mbox = @mutable 10;
- { auto x = foo(mbox); }
+ let mbox = @mutable 10;
+ { let x = foo(mbox); }
assert (*mbox == 11);
}
\ No newline at end of file
diff --git a/src/test/run-pass/obj-dtor.rs b/src/test/run-pass/obj-dtor.rs
index 4e7241e..416e399 100644
--- a/src/test/run-pass/obj-dtor.rs
+++ b/src/test/run-pass/obj-dtor.rs
@@ -5,13 +5,13 @@
// xfail-stage1
// xfail-stage2
// xfail-stage3
-obj worker(chan[int] c) {drop { log "in dtor"; c <| 10; } }
+obj worker(c: chan[int]) {drop { log "in dtor"; c <| 10; } }
-fn do_work(chan[int] c) {
+fn do_work(c: chan[int]) {
log "in child task";
- { let worker w = worker(c); log "constructed worker"; }
+ { let w: worker = worker(c); log "constructed worker"; }
log "destructed worker";
- while (true) {
+ while true {
// Deadlock-condition not handled properly yet, need to avoid
// exiting the child early.
@@ -21,10 +21,10 @@
}
fn main() {
- let port[int] p = port();
+ let p: port[int] = port();
log "spawning worker";
- auto w = spawn do_work(chan(p));
- let int i;
+ let w = spawn do_work(chan(p));
+ let i: int;
log "parent waiting for shutdown";
p |> i;
log "received int";
diff --git a/src/test/run-pass/obj-recursion.rs b/src/test/run-pass/obj-recursion.rs
index 4c8f8d5..7110683 100644
--- a/src/test/run-pass/obj-recursion.rs
+++ b/src/test/run-pass/obj-recursion.rs
@@ -5,15 +5,15 @@
fn add() ;
};
-obj leaf_adder(int x) {
+obj leaf_adder(x: int) {
fn add() { log "leaf"; log x; }
}
-obj delegate_adder(adder a) {
+obj delegate_adder(a: adder) {
fn add() { a.add(); }
}
fn main() {
- auto x = delegate_adder(delegate_adder(delegate_adder(leaf_adder(10))));
+ let x = delegate_adder(delegate_adder(delegate_adder(leaf_adder(10))));
x.add();
}
\ No newline at end of file
diff --git a/src/test/run-pass/obj-self-2.rs b/src/test/run-pass/obj-self-2.rs
index b1bbbaa..8b0dd4b 100644
--- a/src/test/run-pass/obj-self-2.rs
+++ b/src/test/run-pass/obj-self-2.rs
@@ -2,11 +2,11 @@
fn main() {
obj foo() {
- fn m1(int i) { i += 1; log "hi!"; }
- fn m2(int i) { i += 1; self.m1(i); }
+ fn m1(i: int) { i += 1; log "hi!"; }
+ fn m2(i: int) { i += 1; self.m1(i); }
}
- auto a = foo();
- let int i = 0;
+ let a = foo();
+ let i: int = 0;
a.m1(i);
a.m2(i);
}
\ No newline at end of file
diff --git a/src/test/run-pass/obj-self-3.rs b/src/test/run-pass/obj-self-3.rs
index b8cb1b2..fcee2e1 100644
--- a/src/test/run-pass/obj-self-3.rs
+++ b/src/test/run-pass/obj-self-3.rs
@@ -2,12 +2,12 @@
fn main() {
obj foo() {
- fn m1(int i) -> int { i += 1; ret i; }
- fn m2(int i) -> int { ret self.m1(i); }
- fn m3(int i) -> int { i += 1; ret self.m1(i); }
+ fn m1(i: int) -> int { i += 1; ret i; }
+ fn m2(i: int) -> int { ret self.m1(i); }
+ fn m3(i: int) -> int { i += 1; ret self.m1(i); }
}
- auto a = foo();
- let int i = 0;
+ let a = foo();
+ let i: int = 0;
i = a.m1(i);
assert (i == 1);
i = a.m2(i);
diff --git a/src/test/run-pass/obj-self-4.rs b/src/test/run-pass/obj-self-4.rs
index c57f9e5..ca9c768 100644
--- a/src/test/run-pass/obj-self-4.rs
+++ b/src/test/run-pass/obj-self-4.rs
@@ -3,8 +3,8 @@
// xfail-boot
fn main() {
- obj foo(mutable int i) {
- fn inc_by(int incr) -> int { i += incr; ret i; }
+ obj foo(mutable i: int) {
+ fn inc_by(incr: int) -> int { i += incr; ret i; }
fn inc_by_5() -> int { ret self.inc_by(5); }
// A test case showing that issue #324 is resolved. (It used to
@@ -15,8 +15,8 @@
// }
fn get() -> int { ret i; }
}
- let int rs;
- auto o = foo(5);
+ let rs: int;
+ let o = foo(5);
rs = o.get();
assert (rs == 5);
rs = o.inc_by(3);
diff --git a/src/test/run-pass/obj-self.rs b/src/test/run-pass/obj-self.rs
index edbaa87..6e293fc 100644
--- a/src/test/run-pass/obj-self.rs
+++ b/src/test/run-pass/obj-self.rs
@@ -5,7 +5,7 @@
fn m1() { log "hi!"; }
fn m2() { self.m1(); }
}
- auto a = foo();
+ let a = foo();
a.m1();
a.m2();
}
\ No newline at end of file
diff --git a/src/test/run-pass/obj-with-vec.rs b/src/test/run-pass/obj-with-vec.rs
index c185bff..c20dd37 100644
--- a/src/test/run-pass/obj-with-vec.rs
+++ b/src/test/run-pass/obj-with-vec.rs
@@ -1,10 +1,10 @@
fn main() {
- obj buf(vec[u8] data) {
- fn get(int i) -> u8 { ret data.(i); }
+ obj buf(data: vec[u8]) {
+ fn get(i: int) -> u8 { ret data.(i); }
}
- auto b = buf([1 as u8, 2 as u8, 3 as u8]);
+ let b = buf([1 as u8, 2 as u8, 3 as u8]);
log b.get(1);
assert (b.get(1) == 2 as u8);
}
\ No newline at end of file
diff --git a/src/test/run-pass/opeq.rs b/src/test/run-pass/opeq.rs
index a2b860e..0357654 100644
--- a/src/test/run-pass/opeq.rs
+++ b/src/test/run-pass/opeq.rs
@@ -3,7 +3,7 @@
// -*- rust -*-
fn main() {
- let int x = 1;
+ let x: int = 1;
x *= 2;
log x;
assert (x == 2);
diff --git a/src/test/run-pass/or-pattern.rs b/src/test/run-pass/or-pattern.rs
index 55f346f..498a677 100644
--- a/src/test/run-pass/or-pattern.rs
+++ b/src/test/run-pass/or-pattern.rs
@@ -1,18 +1,11 @@
-tag blah {
- a(int, int, uint);
- b(int, int);
- c;
-}
+tag blah { a(int, int, uint); b(int, int); c; }
-fn or_alt(&blah q) -> int {
- alt q {
- a(?x, ?y, _) | b(?x, ?y) { ret x + y;}
- c { ret 0; }
- }
+fn or_alt(q: &blah) -> int {
+ alt q { a(x, y, _) | b(x, y) { ret x + y; } c. { ret 0; } }
}
fn main() {
- assert or_alt(c) == 0;
- assert or_alt(a(10, 100, 0u)) == 110;
- assert or_alt(b(20, 200)) == 220;
-}
+ assert (or_alt(c) == 0);
+ assert (or_alt(a(10, 100, 0u)) == 110);
+ assert (or_alt(b(20, 200)) == 220);
+}
\ No newline at end of file
diff --git a/src/test/run-pass/output-slot-variants.rs b/src/test/run-pass/output-slot-variants.rs
index 9e162a1..fe318ec 100644
--- a/src/test/run-pass/output-slot-variants.rs
+++ b/src/test/run-pass/output-slot-variants.rs
@@ -4,21 +4,21 @@
fn ret_ext_i() -> @int { ret @10; }
-fn ret_int_rec() -> rec(int a, int b) { ret rec(a=10, b=10); }
+fn ret_int_rec() -> {a: int, b: int} { ret {a: 10, b: 10}; }
-fn ret_ext_rec() -> @rec(int a, int b) { ret @rec(a=10, b=10); }
+fn ret_ext_rec() -> @{a: int, b: int} { ret @{a: 10, b: 10}; }
-fn ret_ext_mem() -> rec(@int a, @int b) { ret rec(a=@10, b=@10); }
+fn ret_ext_mem() -> {a: @int, b: @int} { ret {a: @10, b: @10}; }
-fn ret_ext_ext_mem() -> @rec(@int a, @int b) { ret @rec(a=@10, b=@10); }
+fn ret_ext_ext_mem() -> @{a: @int, b: @int} { ret @{a: @10, b: @10}; }
fn main() {
- let int int_i;
- let @int ext_i;
- let rec(int a, int b) int_rec;
- let @rec(int a, int b) ext_rec;
- let rec(@int a, @int b) ext_mem;
- let @rec(@int a, @int b) ext_ext_mem;
+ let int_i: int;
+ let ext_i: @int;
+ let int_rec: {a: int, b: int};
+ let ext_rec: @{a: int, b: int};
+ let ext_mem: {a: @int, b: @int};
+ let ext_ext_mem: @{a: @int, b: @int};
int_i = ret_int_i(); // initializing
int_i = ret_int_i(); // non-initializing
diff --git a/src/test/run-pass/over-constrained-vregs.rs b/src/test/run-pass/over-constrained-vregs.rs
index 9f8ea50..2984098 100644
--- a/src/test/run-pass/over-constrained-vregs.rs
+++ b/src/test/run-pass/over-constrained-vregs.rs
@@ -2,4 +2,4 @@
// Regression test for issue #152.
-fn main() { let uint b = 1u; while (b <= 32u) { 0u << b; b <<= 1u; log b; } }
\ No newline at end of file
+fn main() { let b: uint = 1u; while b <= 32u { 0u << b; b <<= 1u; log b; } }
\ No newline at end of file
diff --git a/src/test/run-pass/paren-free.rs b/src/test/run-pass/paren-free.rs
index b155338..cde723b 100644
--- a/src/test/run-pass/paren-free.rs
+++ b/src/test/run-pass/paren-free.rs
@@ -1,11 +1,5 @@
fn main() {
- auto x = true;
- if x {
- auto i = 10;
- while i > 0 { i -= 1; }
- }
- alt x {
- true { log "right"; }
- false { log "wrong"; }
- }
+ let x = true;
+ if x { let i = 10; while i > 0 { i -= 1; } }
+ alt x { true { log "right"; } false { log "wrong"; } }
}
\ No newline at end of file
diff --git a/src/test/run-pass/path.rs b/src/test/run-pass/path.rs
index 0d57bed..9c5319a 100644
--- a/src/test/run-pass/path.rs
+++ b/src/test/run-pass/path.rs
@@ -1,7 +1,7 @@
mod foo {
- fn bar(uint offset) { }
+ fn bar(offset: uint) { }
}
-fn main(vec[str] args) { foo::bar(0u); }
\ No newline at end of file
+fn main(args: vec[str]) { foo::bar(0u); }
\ No newline at end of file
diff --git a/src/test/run-pass/pattern-bound-var-in-for-each.rs b/src/test/run-pass/pattern-bound-var-in-for-each.rs
index 8bc4370..504aea1 100644
--- a/src/test/run-pass/pattern-bound-var-in-for-each.rs
+++ b/src/test/run-pass/pattern-bound-var-in-for-each.rs
@@ -6,19 +6,18 @@
import std::option::*;
import std::uint;
-fn foo(uint src) {
+fn foo(src: uint) {
- alt (some(src)) {
- case (some(?src_id)) {
- for each (uint i in uint::range(0u, 10u)) {
- auto yyy = src_id;
+
+ alt some(src) {
+ some(src_id) {
+ for each i: uint in uint::range(0u, 10u) {
+ let yyy = src_id;
assert (yyy == 0u);
- }
}
- case (_) {}
+ }
+ _ { }
}
}
-fn main() {
- foo(0u);
-}
+fn main() { foo(0u); }
\ No newline at end of file
diff --git a/src/test/run-pass/pred-check.rs b/src/test/run-pass/pred-check.rs
index 6a57c40..6d071c8 100644
--- a/src/test/run-pass/pred-check.rs
+++ b/src/test/run-pass/pred-check.rs
@@ -3,6 +3,6 @@
// -*- rust -*-
// xfail-stage0
-pred f(int q) -> bool { ret true; }
+pred f(q: int) -> bool { ret true; }
-fn main() { auto x = 0; check (f(x)); }
\ No newline at end of file
+fn main() { let x = 0; check (f(x)); }
\ No newline at end of file
diff --git a/src/test/run-pass/pred.rs b/src/test/run-pass/pred.rs
index 7322f14..e0873ac 100644
--- a/src/test/run-pass/pred.rs
+++ b/src/test/run-pass/pred.rs
@@ -3,14 +3,14 @@
// xfail-stage0
// -*- rust -*-
-fn f(int a, int b) { }
+fn f(a: int, b: int) { }
-pred lt(int a, int b) -> bool { ret a < b; }
+pred lt(a: int, b: int) -> bool { ret a < b; }
fn main() {
- let int a = 10;
- let int b = 23;
- let int c = 77;
+ let a: int = 10;
+ let b: int = 23;
+ let c: int = 77;
check (lt(a, b));
check (lt(a, c));
f(a, b);
diff --git a/src/test/run-pass/preempt.rs b/src/test/run-pass/preempt.rs
index e3f4325..1e3aa10 100644
--- a/src/test/run-pass/preempt.rs
+++ b/src/test/run-pass/preempt.rs
@@ -4,27 +4,22 @@
// xfail-stage3
// This checks that preemption works.
-fn starve_main(chan[int] alive) {
- log "signalling main";
- alive <| 1;
- log "starving main";
- let int i = 0;
- while (true) {
- i += 1;
- }
+fn starve_main(alive: chan[int]) {
+ log "signalling main";
+ alive <| 1;
+ log "starving main";
+ let i: int = 0;
+ while true { i += 1; }
}
fn main() {
- let port[int] alive = port();
- log "main started";
- let task s = spawn starve_main(chan(alive));
- let int i;
- log "main waiting for alive signal";
- alive |> i;
- log "main got alive signal";
- while (i < 50) {
- log "main iterated";
- i += 1;
- }
- log "main completed";
+ let alive: port[int] = port();
+ log "main started";
+ let s: task = spawn starve_main(chan(alive));
+ let i: int;
+ log "main waiting for alive signal";
+ alive |> i;
+ log "main got alive signal";
+ while i < 50 { log "main iterated"; i += 1; }
+ log "main completed";
}
\ No newline at end of file
diff --git a/src/test/run-pass/readalias.rs b/src/test/run-pass/readalias.rs
index 379fd3e..451aa29 100644
--- a/src/test/run-pass/readalias.rs
+++ b/src/test/run-pass/readalias.rs
@@ -2,8 +2,8 @@
// -*- rust -*-
-type point = rec(int x, int y, int z);
+type point = {x: int, y: int, z: int};
-fn f(&point p) { assert (p.z == 12); }
+fn f(p: &point) { assert (p.z == 12); }
-fn main() { let point x = rec(x=10, y=11, z=12); f(x); }
\ No newline at end of file
+fn main() { let x: point = {x: 10, y: 11, z: 12}; f(x); }
\ No newline at end of file
diff --git a/src/test/run-pass/rec-auto.rs b/src/test/run-pass/rec-auto.rs
index e08f537..4162beb 100644
--- a/src/test/run-pass/rec-auto.rs
+++ b/src/test/run-pass/rec-auto.rs
@@ -4,4 +4,4 @@
// -*- rust -*-
// Issue #50.
-fn main() { auto x = rec(foo="hello", bar="world"); log x.foo; log x.bar; }
\ No newline at end of file
+fn main() { let x = {foo: "hello", bar: "world"}; log x.foo; log x.bar; }
\ No newline at end of file
diff --git a/src/test/run-pass/rec-extend.rs b/src/test/run-pass/rec-extend.rs
index 0d32785..6b30710 100644
--- a/src/test/run-pass/rec-extend.rs
+++ b/src/test/run-pass/rec-extend.rs
@@ -2,12 +2,12 @@
// -*- rust -*-
-type point = rec(int x, int y);
+type point = {x: int, y: int};
fn main() {
- let point origin = rec(x=0, y=0);
- let point right = rec(x=origin.x + 10 with origin);
- let point up = rec(y=origin.y + 10 with origin);
+ let origin: point = {x: 0, y: 0};
+ let right: point = {x: origin.x + 10 with origin};
+ let up: point = {y: origin.y + 10 with origin};
assert (origin.x == 0);
assert (origin.y == 0);
assert (right.x == 10);
diff --git a/src/test/run-pass/rec.rs b/src/test/run-pass/rec.rs
index 736121e..b7a3f3a 100644
--- a/src/test/run-pass/rec.rs
+++ b/src/test/run-pass/rec.rs
@@ -2,9 +2,9 @@
// -*- rust -*-
-type rect = rec(int x, int y, int w, int h);
+type rect = {x: int, y: int, w: int, h: int};
-fn f(rect r, int x, int y, int w, int h) {
+fn f(r: rect, x: int, y: int, w: int, h: int) {
assert (r.x == x);
assert (r.y == y);
assert (r.w == w);
@@ -12,13 +12,13 @@
}
fn main() {
- let rect r = rec(x=10, y=20, w=100, h=200);
+ let r: rect = {x: 10, y: 20, w: 100, h: 200};
assert (r.x == 10);
assert (r.y == 20);
assert (r.w == 100);
assert (r.h == 200);
- let rect r2 = r;
- let int x = r2.x;
+ let r2: rect = r;
+ let x: int = r2.x;
assert (x == 10);
f(r, 10, 20, 100, 200);
f(r2, 10, 20, 100, 200);
diff --git a/src/test/run-pass/record-pat.rs b/src/test/run-pass/record-pat.rs
index 5d72d98..6d08c91 100644
--- a/src/test/run-pass/record-pat.rs
+++ b/src/test/run-pass/record-pat.rs
@@ -1,17 +1,17 @@
// xfail-stage0
tag t1 { a(int); b(uint); }
-type t2 = rec(t1 x, int y);
+type t2 = {x: t1, y: int};
tag t3 { c(t2, uint); }
-fn m(&t3 in) -> int {
+fn m(in: &t3) -> int {
alt in {
- c({x: a(?m), _}, _) { ret m; }
- c({x: b(?m), y}, ?z) { ret (m + z) as int + y; }
+ c({x: a(m), _}, _) { ret m; }
+ c({x: b(m), y: y}, z) { ret (m + z as int) + y; }
}
}
fn main() {
- assert m(c(rec(x=a(10), y=5), 4u)) == 10;
- assert m(c(rec(x=b(10u), y=5), 4u)) == 19;
-}
+ assert (m(c({x: a(10), y: 5}, 4u)) == 10);
+ assert (m(c({x: b(10u), y: 5}, 4u)) == 19);
+}
\ No newline at end of file
diff --git a/src/test/run-pass/resource-destruct.rs b/src/test/run-pass/resource-destruct.rs
index 3732a80..8d6d858 100644
--- a/src/test/run-pass/resource-destruct.rs
+++ b/src/test/run-pass/resource-destruct.rs
@@ -1,16 +1,9 @@
-resource shrinky_pointer(@mutable int i) {
- *i -= 1;
-}
+resource shrinky_pointer(i: @mutable int) { *i -= 1; }
-fn look_at(&shrinky_pointer pt) -> int {
- ret **pt;
-}
+fn look_at(pt: &shrinky_pointer) -> int { ret **pt; }
fn main() {
- auto my_total = @mutable 10;
- {
- auto pt <- shrinky_pointer(my_total);
- assert (look_at(pt) == 10);
- }
+ let my_total = @mutable 10;
+ { let pt <- shrinky_pointer(my_total); assert (look_at(pt) == 10); }
assert (*my_total == 9);
-}
+}
\ No newline at end of file
diff --git a/src/test/run-pass/resource-generic.rs b/src/test/run-pass/resource-generic.rs
index 7be26e8..eebe23e 100644
--- a/src/test/run-pass/resource-generic.rs
+++ b/src/test/run-pass/resource-generic.rs
@@ -1,13 +1,9 @@
-resource finish[T](rec(T val, fn(&T) fin) arg) {
- arg.fin(arg.val);
-}
+resource finish[T](arg: {val: T, fin: fn(&T) }) { arg.fin(arg.val); }
fn main() {
- auto box = @mutable 10;
- fn dec_box(&@mutable int i) { *i -= 1; }
+ let box = @mutable 10;
+ fn dec_box(i: &@mutable int) { *i -= 1; }
- {
- auto i <- finish(rec(val=box, fin=dec_box));
- }
- assert(*box == 9);
-}
+ { let i <- finish({val: box, fin: dec_box}); }
+ assert (*box == 9);
+}
\ No newline at end of file
diff --git a/src/test/run-pass/ret-bang.rs b/src/test/run-pass/ret-bang.rs
index c00e936..e668ff9 100644
--- a/src/test/run-pass/ret-bang.rs
+++ b/src/test/run-pass/ret-bang.rs
@@ -2,10 +2,10 @@
// -*- rust -*-
-fn my_err(str s) -> ! { log_err s; fail; }
+fn my_err(s: str) -> ! { log_err s; fail; }
-fn okay(uint i) -> int {
- if (i == 3u) { my_err("I don't like three"); } else { ret 42; }
+fn okay(i: uint) -> int {
+ if i == 3u { my_err("I don't like three"); } else { ret 42; }
}
fn main() { okay(4u); }
\ No newline at end of file
diff --git a/src/test/run-pass/return-nil.rs b/src/test/run-pass/return-nil.rs
index 8e02e09..6e7b9d8 100644
--- a/src/test/run-pass/return-nil.rs
+++ b/src/test/run-pass/return-nil.rs
@@ -1,5 +1,5 @@
-fn f() { let () x = (); ret x; }
+fn f() { let x: () = (); ret x; }
-fn main() { auto x = f(); }
\ No newline at end of file
+fn main() { let x = f(); }
\ No newline at end of file
diff --git a/src/test/run-pass/rt-circular-buffer.rs b/src/test/run-pass/rt-circular-buffer.rs
index bf9899f..f4ee721 100644
--- a/src/test/run-pass/rt-circular-buffer.rs
+++ b/src/test/run-pass/rt-circular-buffer.rs
@@ -11,7 +11,7 @@
// A 12-byte unit to send over the channel
-type record = rec(u32 val1, u32 val2, u32 val3);
+type record = {val1: u32, val2: u32, val3: u32};
// Assuming that the default buffer size needs to hold 8 units,
@@ -19,9 +19,9 @@
// power of two so needs to be rounded up. Don't trigger any
// assertions.
fn test_init() {
- let port[record] myport = port();
- auto mychan = chan(myport);
- let record val = rec(val1=0u32, val2=0u32, val3=0u32);
+ let myport: port[record] = port();
+ let mychan = chan(myport);
+ let val: record = {val1: 0u32, val2: 0u32, val3: 0u32};
mychan <| val;
}
@@ -29,39 +29,39 @@
// Dump lots of items into the channel so it has to grow.
// Don't trigger any assertions.
fn test_grow() {
- let port[record] myport = port();
- auto mychan = chan(myport);
- let record val = rec(val1=0u32, val2=0u32, val3=0u32);
- for each (uint i in uint::range(0u, 100u)) { mychan <| val; }
+ let myport: port[record] = port();
+ let mychan = chan(myport);
+ let val: record = {val1: 0u32, val2: 0u32, val3: 0u32};
+ for each i: uint in uint::range(0u, 100u) { mychan <| val; }
}
// Don't allow the buffer to shrink below it's original size
fn test_shrink1() {
- let port[i8] myport = port();
- auto mychan = chan(myport);
+ let myport: port[i8] = port();
+ let mychan = chan(myport);
mychan <| 0i8;
- auto x;
+ let x;
myport |> x;
}
fn test_shrink2() {
- let port[record] myport = port();
- auto mychan = chan(myport);
- let record val = rec(val1=0u32, val2=0u32, val3=0u32);
- for each (uint i in uint::range(0u, 100u)) { mychan <| val; }
- for each (uint i in uint::range(0u, 100u)) { auto x; myport |> x; }
+ let myport: port[record] = port();
+ let mychan = chan(myport);
+ let val: record = {val1: 0u32, val2: 0u32, val3: 0u32};
+ for each i: uint in uint::range(0u, 100u) { mychan <| val; }
+ for each i: uint in uint::range(0u, 100u) { let x; myport |> x; }
}
// Test rotating the buffer when the unit size is not a power of two
fn test_rotate() {
- let port[record] myport = port();
- auto mychan = chan(myport);
- for each (uint i in uint::range(0u, 100u)) {
- auto val = rec(val1=i as u32, val2=i as u32, val3=i as u32);
+ let myport: port[record] = port();
+ let mychan = chan(myport);
+ for each i: uint in uint::range(0u, 100u) {
+ let val = {val1: i as u32, val2: i as u32, val3: i as u32};
mychan <| val;
- auto x;
+ let x;
myport |> x;
assert (x.val1 == i as u32);
assert (x.val2 == i as u32);
@@ -73,15 +73,16 @@
// Test rotating and growing the buffer when
// the unit size is not a power of two
fn test_rotate_grow() {
- let port[record] myport = port();
- auto mychan = chan(myport);
- for each (uint j in uint::range(0u, 10u)) {
- for each (uint i in uint::range(0u, 10u)) {
- let record val = rec(val1=i as u32, val2=i as u32, val3=i as u32);
+ let myport: port[record] = port();
+ let mychan = chan(myport);
+ for each j: uint in uint::range(0u, 10u) {
+ for each i: uint in uint::range(0u, 10u) {
+ let val: record =
+ {val1: i as u32, val2: i as u32, val3: i as u32};
mychan <| val;
}
- for each (uint i in uint::range(0u, 10u)) {
- auto x;
+ for each i: uint in uint::range(0u, 10u) {
+ let x;
myport |> x;
assert (x.val1 == i as u32);
assert (x.val2 == i as u32);
diff --git a/src/test/run-pass/self-shadowing-import.rs b/src/test/run-pass/self-shadowing-import.rs
index 04548c8..c9b70d3 100644
--- a/src/test/run-pass/self-shadowing-import.rs
+++ b/src/test/run-pass/self-shadowing-import.rs
@@ -8,9 +8,7 @@
mod c {
import a::b::a;
- fn bar() { assert a::foo() == 1; }
+ fn bar() { assert (a::foo() == 1); }
}
-fn main() {
- c::bar();
-}
+fn main() { c::bar(); }
\ No newline at end of file
diff --git a/src/test/run-pass/send-type-inference.rs b/src/test/run-pass/send-type-inference.rs
index bd5b4af..87481ef 100644
--- a/src/test/run-pass/send-type-inference.rs
+++ b/src/test/run-pass/send-type-inference.rs
@@ -1,10 +1,9 @@
// xfail-stage0
// tests that ctrl's type gets inferred properly
-type command[K, V] = rec(K key, V val);
+type command[K, V] = {key: K, val: V};
-fn cache_server[K, V] (chan[chan[command[K,V]]] c) {
- auto ctrl = port();
+fn cache_server[K, V](c: chan[chan[command[K, V]]]) {
+ let ctrl = port();
c <| chan(ctrl);
}
-fn main() {
-}
\ No newline at end of file
+fn main() { }
\ No newline at end of file
diff --git a/src/test/run-pass/simple-alt-generic-tag.rs b/src/test/run-pass/simple-alt-generic-tag.rs
index 24c26e1..8399f27 100644
--- a/src/test/run-pass/simple-alt-generic-tag.rs
+++ b/src/test/run-pass/simple-alt-generic-tag.rs
@@ -2,7 +2,4 @@
tag opt[T] { none; }
-fn main() {
- auto x = none[int];
- alt (x) { case (none[int]) { log "hello world"; } }
-}
\ No newline at end of file
+fn main() { let x = none[int]; alt x { none[int]. { log "hello world"; } } }
\ No newline at end of file
diff --git a/src/test/run-pass/simple-anon-objs.rs b/src/test/run-pass/simple-anon-objs.rs
index dd07433..8525ea8 100644
--- a/src/test/run-pass/simple-anon-objs.rs
+++ b/src/test/run-pass/simple-anon-objs.rs
@@ -4,26 +4,26 @@
obj normal() {
fn foo() -> int { ret 2; }
}
- auto my_normal_obj = normal();
+ let my_normal_obj = normal();
// Extending an object with a new method
- auto my_anon_obj = obj {
- fn bar() -> int {
- ret 3;
- }
- with my_normal_obj
- };
+ let my_anon_obj =
+ obj () {
+ fn bar() -> int { ret 3; }
+ with
+ my_normal_obj
+ };
assert (my_normal_obj.foo() == 2);
assert (my_anon_obj.bar() == 3);
- auto another_anon_obj = obj {
- fn baz() -> int {
- ret 4;
- }
- with my_anon_obj
- };
+ let another_anon_obj =
+ obj () {
+ fn baz() -> int { ret 4; }
+ with
+ my_anon_obj
+ };
assert (another_anon_obj.baz() == 4);
-}
+}
\ No newline at end of file
diff --git a/src/test/run-pass/simple-generic-alt.rs b/src/test/run-pass/simple-generic-alt.rs
index 1132adf..30256c1 100644
--- a/src/test/run-pass/simple-generic-alt.rs
+++ b/src/test/run-pass/simple-generic-alt.rs
@@ -2,4 +2,4 @@
tag clam[T] { a(T); }
-fn main() { auto c = a(2); alt (c) { case (a[int](_)) { } } }
\ No newline at end of file
+fn main() { let c = a(2); alt c { a[int](_) { } } }
\ No newline at end of file
diff --git a/src/test/run-pass/simple-infer.rs b/src/test/run-pass/simple-infer.rs
index cc84182..6cf8df9 100644
--- a/src/test/run-pass/simple-infer.rs
+++ b/src/test/run-pass/simple-infer.rs
@@ -1,3 +1,3 @@
-fn main() { auto n; n = 1; log n; }
\ No newline at end of file
+fn main() { let n; n = 1; log n; }
\ No newline at end of file
diff --git a/src/test/run-pass/simple-obj.rs b/src/test/run-pass/simple-obj.rs
index 9e3e92d..1133cdc 100644
--- a/src/test/run-pass/simple-obj.rs
+++ b/src/test/run-pass/simple-obj.rs
@@ -6,4 +6,4 @@
fn hello() { log "hello, object world"; }
}
-fn main() { auto mx = x(); mx.hello(); }
\ No newline at end of file
+fn main() { let mx = x(); mx.hello(); }
\ No newline at end of file
diff --git a/src/test/run-pass/simple-qsort.rs b/src/test/run-pass/simple-qsort.rs
index 25425e6..98b0211 100644
--- a/src/test/run-pass/simple-qsort.rs
+++ b/src/test/run-pass/simple-qsort.rs
@@ -6,20 +6,18 @@
import std::sort;
fn test_qsort() {
- auto names = ~[mutable 2, 1, 3];
+ let names = ~[mutable 2, 1, 3];
- auto expected = ~[1, 2, 3];
+ let expected = ~[1, 2, 3];
- fn lteq(&int a, &int b) -> bool { int::le(a, b) }
+ fn lteq(a: &int, b: &int) -> bool { int::le(a, b) }
sort::ivector::quick_sort(lteq, names);
- auto pairs = ivec::zip(expected, ivec::from_mut(names));
- for (rec(int _0, int _1) p in pairs) {
+ let pairs = ivec::zip(expected, ivec::from_mut(names));
+ for p: {_0: int, _1: int} in pairs {
log_err #fmt("%d %d", p._0, p._1);
- assert p._0 == p._1;
+ assert (p._0 == p._1);
}
}
-fn main() {
- test_qsort();
-}
+fn main() { test_qsort(); }
\ No newline at end of file
diff --git a/src/test/run-pass/size-and-align.rs b/src/test/run-pass/size-and-align.rs
index ebbd618..b911bc3 100644
--- a/src/test/run-pass/size-and-align.rs
+++ b/src/test/run-pass/size-and-align.rs
@@ -4,14 +4,14 @@
// -*- rust -*-
tag clam[T] { a(T, int); b; }
-fn uhoh[T](vec[clam[T]] v) {
- alt (v.(1)) {
- case (a[T](?t, ?u)) { log "incorrect"; log u; fail; }
- case (b[T]) { log "correct"; }
+fn uhoh[T](v: vec[clam[T]]) {
+ alt v.(1) {
+ a[T](t, u) { log "incorrect"; log u; fail; }
+ b[T]. { log "correct"; }
}
}
fn main() {
- let vec[clam[int]] v = [b[int], b[int], a[int](42, 17)];
+ let v: vec[clam[int]] = [b[int], b[int], a[int](42, 17)];
uhoh[int](v);
}
\ No newline at end of file
diff --git a/src/test/run-pass/spawn-fn.rs b/src/test/run-pass/spawn-fn.rs
index 288d5af..72876be 100644
--- a/src/test/run-pass/spawn-fn.rs
+++ b/src/test/run-pass/spawn-fn.rs
@@ -4,19 +4,12 @@
// xfail-stage3
// -*- rust -*-
-fn x(str s, int n) {
- log s;
- log n;
-}
+fn x(s: str, n: int) { log s; log n; }
fn main() {
- spawn x("hello from first spawned fn", 65);
- spawn x("hello from second spawned fn", 66);
- spawn x("hello from third spawned fn", 67);
- let int i = 30;
- while (i > 0) {
- i = i - 1;
- log "parent sleeping";
- yield;
- }
-}
+ spawn x("hello from first spawned fn", 65);
+ spawn x("hello from second spawned fn", 66);
+ spawn x("hello from third spawned fn", 67);
+ let i: int = 30;
+ while i > 0 { i = i - 1; log "parent sleeping"; yield; }
+}
\ No newline at end of file
diff --git a/src/test/run-pass/spawn-module-qualified.rs b/src/test/run-pass/spawn-module-qualified.rs
index 24711da..5c7106b 100644
--- a/src/test/run-pass/spawn-module-qualified.rs
+++ b/src/test/run-pass/spawn-module-qualified.rs
@@ -1,13 +1,6 @@
-// xfail-stage0
-// xfail-stage1
-// xfail-stage2
-// xfail-stage3
-fn main() {
- auto x = spawn m::child(10);
- join x;
-}
-mod m {
- fn child(int i) {
- log i;
- }
-}
+./src/test/run-pass/spawn-module-qualified.rs:7:7:7:8: [1;31merror:[0m expected ';' or '}' after expression but found x
+./src/test/run-pass/spawn-module-qualified.rs:7 join x;
+ ^
+rt: ---
+rt: 0bb1:main:main: upcall fail 'explicit failure', src/comp/syntax/parse/parser.rs:112
+rt: 0bb1:main: domain main @0xa98404c root task failed
diff --git a/src/test/run-pass/spawn-types.rs b/src/test/run-pass/spawn-types.rs
index 4bbeb3c..a7ab4c0 100644
--- a/src/test/run-pass/spawn-types.rs
+++ b/src/test/run-pass/spawn-types.rs
@@ -12,11 +12,6 @@
type ctx = chan[int];
-fn iotask(ctx cx, str ip) {
- assert(str::eq(ip, "localhost"));
-}
+fn iotask(cx: ctx, ip: str) { assert (str::eq(ip, "localhost")); }
-fn main() {
- let port[int] p = port();
- spawn iotask(chan(p), "localhost");
-}
+fn main() { let p: port[int] = port(); spawn iotask(chan(p), "localhost"); }
\ No newline at end of file
diff --git a/src/test/run-pass/spawn.rs b/src/test/run-pass/spawn.rs
index e627949..cb236e7 100644
--- a/src/test/run-pass/spawn.rs
+++ b/src/test/run-pass/spawn.rs
@@ -3,15 +3,9 @@
use std;
-fn main() {
- auto t = spawn child(10);
- std::task::join(t);
-}
+fn main() { let t = spawn child(10); std::task::join(t); }
-fn child(int i) {
- log_err i;
- assert(i == 10);
-}
+fn child(i: int) { log_err i; assert (i == 10); }
// Local Variables:
// mode: rust;
diff --git a/src/test/run-pass/spawn2.rs b/src/test/run-pass/spawn2.rs
index 9485210..e2f8f96 100644
--- a/src/test/run-pass/spawn2.rs
+++ b/src/test/run-pass/spawn2.rs
@@ -1,38 +1,28 @@
// xfail-stage0
// -*- rust -*-
-fn main() {
- spawn child(10, 20, 30, 40, 50, 60, 70, 80, 90);
-}
+fn main() { spawn child(10, 20, 30, 40, 50, 60, 70, 80, 90); }
-fn child(int i1,
- int i2,
- int i3,
- int i4,
- int i5,
- int i6,
- int i7,
- int i8,
- int i9)
-{
- log_err i1;
- log_err i2;
- log_err i3;
- log_err i4;
- log_err i5;
- log_err i6;
- log_err i7;
- log_err i8;
- log_err i9;
- assert(i1 == 10);
- assert(i2 == 20);
- assert(i3 == 30);
- assert(i4 == 40);
- assert(i5 == 50);
- assert(i6 == 60);
- assert(i7 == 70);
- assert(i8 == 80);
- assert(i9 == 90);
+fn child(i1: int, i2: int, i3: int, i4: int, i5: int, i6: int, i7: int,
+ i8: int, i9: int) {
+ log_err i1;
+ log_err i2;
+ log_err i3;
+ log_err i4;
+ log_err i5;
+ log_err i6;
+ log_err i7;
+ log_err i8;
+ log_err i9;
+ assert (i1 == 10);
+ assert (i2 == 20);
+ assert (i3 == 30);
+ assert (i4 == 40);
+ assert (i5 == 50);
+ assert (i6 == 60);
+ assert (i7 == 70);
+ assert (i8 == 80);
+ assert (i9 == 90);
}
// Local Variables:
diff --git a/src/test/run-pass/stateful-obj.rs b/src/test/run-pass/stateful-obj.rs
index 992a535..7e3fa56 100644
--- a/src/test/run-pass/stateful-obj.rs
+++ b/src/test/run-pass/stateful-obj.rs
@@ -2,14 +2,14 @@
// -*- rust -*-
-obj counter(mutable int x) {
+obj counter(mutable x: int) {
fn hello() -> int { ret 12345; }
fn incr() { x = x + 1; }
fn get() -> int { ret x; }
}
fn main() {
- auto y = counter(0);
+ let y = counter(0);
assert (y.hello() == 12345);
log y.get();
y.incr();
diff --git a/src/test/run-pass/str-append.rs b/src/test/run-pass/str-append.rs
index f13fa97..a27f729 100644
--- a/src/test/run-pass/str-append.rs
+++ b/src/test/run-pass/str-append.rs
@@ -5,7 +5,7 @@
import std::str;
fn test1() {
- let str s = "hello";
+ let s: str = "hello";
s += "world";
log s;
assert (s.(9) == 'd' as u8);
@@ -14,9 +14,9 @@
fn test2() {
// This tests for issue #163
- let str ff = "abc";
- let str a = ff + "ABC" + ff;
- let str b = "ABC" + ff + "ABC";
+ let ff: str = "abc";
+ let a: str = ff + "ABC" + ff;
+ let b: str = "ABC" + ff + "ABC";
log a;
log b;
assert (str::eq(a, "abcABCabc"));
diff --git a/src/test/run-pass/str-concat.rs b/src/test/run-pass/str-concat.rs
index a16a57d..57c0525 100644
--- a/src/test/run-pass/str-concat.rs
+++ b/src/test/run-pass/str-concat.rs
@@ -3,9 +3,9 @@
// -*- rust -*-
fn main() {
- let str a = "hello";
- let str b = "world";
- let str s = a + b;
+ let a: str = "hello";
+ let b: str = "world";
+ let s: str = a + b;
log s;
assert (s.(9) == 'd' as u8);
}
\ No newline at end of file
diff --git a/src/test/run-pass/str-growth.rs b/src/test/run-pass/str-growth.rs
index 1ad847a..35d29fe 100644
--- a/src/test/run-pass/str-growth.rs
+++ b/src/test/run-pass/str-growth.rs
@@ -1,7 +1,7 @@
fn main() {
- auto s = "a";
+ let s = "a";
s += "b";
assert (s.(0) == 'a' as u8);
assert (s.(1) == 'b' as u8);
diff --git a/src/test/run-pass/str-idx.rs b/src/test/run-pass/str-idx.rs
index 89ef320..40366ed 100644
--- a/src/test/run-pass/str-idx.rs
+++ b/src/test/run-pass/str-idx.rs
@@ -1,8 +1,8 @@
fn main() {
- auto s = "hello";
- let u8 c = s.(4);
+ let s = "hello";
+ let c: u8 = s.(4);
log c;
assert (c == 0x6f as u8);
}
\ No newline at end of file
diff --git a/src/test/run-pass/str-multiline.rs b/src/test/run-pass/str-multiline.rs
index 1120148..45d6ad6 100644
--- a/src/test/run-pass/str-multiline.rs
+++ b/src/test/run-pass/str-multiline.rs
@@ -5,9 +5,9 @@
import std::str;
fn main() {
- let str a = "this \
+ let a: str = "this \
is a test";
- let str b =
+ let b: str =
"this \
is \
another \
diff --git a/src/test/run-pass/string-self-append.rs b/src/test/run-pass/string-self-append.rs
index 532b3af..842c00b 100644
--- a/src/test/run-pass/string-self-append.rs
+++ b/src/test/run-pass/string-self-append.rs
@@ -3,17 +3,16 @@
use std;
import std::str;
-fn main()
-{
+fn main() {
// Make sure we properly handle repeated self-appends.
- let str a = "A";
- auto i = 20;
- auto expected_len = 1u;
- while (i > 0) {
+ let a: str = "A";
+ let i = 20;
+ let expected_len = 1u;
+ while i > 0 {
log_err str::byte_len(a);
assert (str::byte_len(a) == expected_len);
a += a;
i -= 1;
expected_len *= 2u;
}
-}
+}
\ No newline at end of file
diff --git a/src/test/run-pass/structured-compare.rs b/src/test/run-pass/structured-compare.rs
index 36b7f3d..e2d95a5 100644
--- a/src/test/run-pass/structured-compare.rs
+++ b/src/test/run-pass/structured-compare.rs
@@ -3,16 +3,16 @@
tag foo { large; small; }
fn main() {
- auto a = rec(x=1, y=2, z=3);
- auto b = rec(x=1, y=2, z=3);
+ let a = {x: 1, y: 2, z: 3};
+ let b = {x: 1, y: 2, z: 3};
assert (a == b);
- assert (a != rec(x=1, y=2, z=4));
- assert (a < rec(x=1, y=2, z=4));
- assert (a <= rec(x=1, y=2, z=4));
- assert (rec(x=1, y=2, z=4) > a);
- assert (rec(x=1, y=2, z=4) >= a);
- auto x = large;
- auto y = small;
+ assert (a != {x: 1, y: 2, z: 4});
+ assert (a < {x: 1, y: 2, z: 4});
+ assert (a <= {x: 1, y: 2, z: 4});
+ assert ({x: 1, y: 2, z: 4} > a);
+ assert ({x: 1, y: 2, z: 4} >= a);
+ let x = large;
+ let y = small;
assert (x != y);
assert (x == large);
assert (x != small);
diff --git a/src/test/run-pass/swap-1.rs b/src/test/run-pass/swap-1.rs
index a4ce5bf..62b557e 100644
--- a/src/test/run-pass/swap-1.rs
+++ b/src/test/run-pass/swap-1.rs
@@ -1,7 +1 @@
-fn main() {
- auto x = 3;
- auto y = 7;
- x <-> y;
- assert (x == 7);
- assert (y == 3);
-}
+fn main() { let x = 3; let y = 7; x <-> y; assert (x == 7); assert (y == 3); }
\ No newline at end of file
diff --git a/src/test/run-pass/swap-2.rs b/src/test/run-pass/swap-2.rs
index 6c33030..826c3e2 100644
--- a/src/test/run-pass/swap-2.rs
+++ b/src/test/run-pass/swap-2.rs
@@ -1,14 +1,12 @@
-fn swap[T](&vec[mutable T] v, int i, int j) {
- v.(i) <-> v.(j);
-}
+fn swap[T](v: &vec[mutable T], i: int, j: int) { v.(i) <-> v.(j); }
fn main() {
- let vec[mutable int] a = [mutable 0,1,2,3,4,5,6];
+ let a: vec[mutable int] = [mutable 0, 1, 2, 3, 4, 5, 6];
swap(a, 2, 4);
- assert(a.(2) == 4);
- assert(a.(4) == 2);
- auto n = 42;
+ assert (a.(2) == 4);
+ assert (a.(4) == 2);
+ let n = 42;
n <-> a.(0);
- assert(a.(0) == 42);
- assert(n == 0);
-}
+ assert (a.(0) == 42);
+ assert (n == 0);
+}
\ No newline at end of file
diff --git a/src/test/run-pass/syntax-extension-fmt.rs b/src/test/run-pass/syntax-extension-fmt.rs
index e09792c..44119c8 100644
--- a/src/test/run-pass/syntax-extension-fmt.rs
+++ b/src/test/run-pass/syntax-extension-fmt.rs
@@ -2,7 +2,7 @@
use std;
import std::str;
-fn test(str actual, str expected) {
+fn test(actual: str, expected: str) {
log actual;
log expected;
assert (str::eq(actual, expected));
@@ -183,7 +183,7 @@
test(#fmt("%-05c", 'A'), "A ");
test(#fmt("%-05b", true), "true ");
}
-fn part6(){
+fn part6() {
// Precision overrides 0-padding
test(#fmt("%06.5d", 0), " 00000");
@@ -215,4 +215,4 @@
test(#fmt("%- 05d", -1), "-1 ");
test(#fmt("%-+05d", 1), "+1 ");
test(#fmt("%-+05d", -1), "-1 ");
-}
+}
\ No newline at end of file
diff --git a/src/test/run-pass/syntax-extension-shell.rs b/src/test/run-pass/syntax-extension-shell.rs
index 59ef847..d495f7e 100644
--- a/src/test/run-pass/syntax-extension-shell.rs
+++ b/src/test/run-pass/syntax-extension-shell.rs
@@ -1,8 +1,6 @@
-// xfail-stage0
-// xfail-stage1
-// xfail-stage2
-// xfail-stage3
-fn main() {
- auto s = #shell { uname -a };
- log s;
-}
+./src/test/run-pass/syntax-extension-shell.rs:6:18:6:19: [1;31merror:[0m expecting (, found {
+./src/test/run-pass/syntax-extension-shell.rs:6 auto s = #shell { uname -a };
+ ^
+rt: ---
+rt: f00e:main:main: upcall fail 'explicit failure', src/comp/syntax/parse/parser.rs:112
+rt: f00e:main: domain main @0x910c04c root task failed
diff --git a/src/test/run-pass/tag-and-generic-obj.rs b/src/test/run-pass/tag-and-generic-obj.rs
index f87294d..d13c115 100644
--- a/src/test/run-pass/tag-and-generic-obj.rs
+++ b/src/test/run-pass/tag-and-generic-obj.rs
@@ -3,7 +3,7 @@
tag colour { red; green; }
obj foo[T]() {
- fn meth(&T x) { }
+ fn meth(x: &T) { }
}
fn main() { foo[colour]().meth(red); }
\ No newline at end of file
diff --git a/src/test/run-pass/tag-in-block.rs b/src/test/run-pass/tag-in-block.rs
index 8d51395..4268940 100644
--- a/src/test/run-pass/tag-in-block.rs
+++ b/src/test/run-pass/tag-in-block.rs
@@ -1,9 +1,9 @@
fn foo() {
- fn zed(bar z) { }
+ fn zed(z: bar) { }
tag bar { nil; }
fn baz() { zed(nil); }
}
-fn main(vec[str] args) { }
\ No newline at end of file
+fn main(args: vec[str]) { }
\ No newline at end of file
diff --git a/src/test/run-pass/tag.rs b/src/test/run-pass/tag.rs
index 00fd4ce..1ea4702 100644
--- a/src/test/run-pass/tag.rs
+++ b/src/test/run-pass/tag.rs
@@ -5,8 +5,8 @@
tag colour { red(int, int); green; }
fn f() {
- auto x = red(1, 2);
- auto y = green;
+ let x = red(1, 2);
+ let y = green;
// FIXME: needs structural equality test working.
// assert (x != y);
diff --git a/src/test/run-pass/tail-call-arg-leak.rs b/src/test/run-pass/tail-call-arg-leak.rs
index 0c342de..f771e9e 100644
--- a/src/test/run-pass/tail-call-arg-leak.rs
+++ b/src/test/run-pass/tail-call-arg-leak.rs
@@ -2,6 +2,6 @@
// use of tail calls causes arg slot leaks, issue #160.
-fn inner(str dummy, bool b) { if (b) { be inner(dummy, false); } }
+fn inner(dummy: str, b: bool) { if b { be inner(dummy, false); } }
fn main() { inner("hi", true); }
\ No newline at end of file
diff --git a/src/test/run-pass/tail-cps.rs b/src/test/run-pass/tail-cps.rs
index 37fb22a..81efa8f 100644
--- a/src/test/run-pass/tail-cps.rs
+++ b/src/test/run-pass/tail-cps.rs
@@ -2,18 +2,18 @@
// -*- rust -*-
-fn checktrue(bool rs) -> bool { assert (rs); ret true; }
+fn checktrue(rs: bool) -> bool { assert (rs); ret true; }
-fn main() { auto k = checktrue; evenk(42, k); oddk(45, k); }
+fn main() { let k = checktrue; evenk(42, k); oddk(45, k); }
-fn evenk(int n, fn(bool) -> bool k) -> bool {
+fn evenk(n: int, k: fn(bool) -> bool ) -> bool {
log "evenk";
log n;
- if (n == 0) { be k(true); } else { be oddk(n - 1, k); }
+ if n == 0 { be k(true); } else { be oddk(n - 1, k); }
}
-fn oddk(int n, fn(bool) -> bool k) -> bool {
+fn oddk(n: int, k: fn(bool) -> bool ) -> bool {
log "oddk";
log n;
- if (n == 0) { be k(false); } else { be evenk(n - 1, k); }
+ if n == 0 { be k(false); } else { be evenk(n - 1, k); }
}
\ No newline at end of file
diff --git a/src/test/run-pass/tail-direct.rs b/src/test/run-pass/tail-direct.rs
index 3e2cf97..f0b50b0 100644
--- a/src/test/run-pass/tail-direct.rs
+++ b/src/test/run-pass/tail-direct.rs
@@ -4,6 +4,6 @@
// -*- rust -*-
fn main() { assert (even(42)); assert (odd(45)); }
-fn even(int n) -> bool { if (n == 0) { ret true; } else { be odd(n - 1); } }
+fn even(n: int) -> bool { if n == 0 { ret true; } else { be odd(n - 1); } }
-fn odd(int n) -> bool { if (n == 0) { ret false; } else { be even(n - 1); } }
\ No newline at end of file
+fn odd(n: int) -> bool { if n == 0 { ret false; } else { be even(n - 1); } }
\ No newline at end of file
diff --git a/src/test/run-pass/task-comm-0.rs b/src/test/run-pass/task-comm-0.rs
index 33365bf..c93b1cb4 100644
--- a/src/test/run-pass/task-comm-0.rs
+++ b/src/test/run-pass/task-comm-0.rs
@@ -1,20 +1,15 @@
// xfail-stage0
-fn main() -> () {
- test05();
-}
+fn main() { test05(); }
-fn test05_start(chan[int] ch) {
- ch <| 10;
- ch <| 20;
- ch <| 30;
-}
+fn test05_start(ch: chan[int]) { ch <| 10; ch <| 20; ch <| 30; }
fn test05() {
- let port[int] po = port();
- let chan[int] ch = chan(po);
+ let po: port[int] = port();
+ let ch: chan[int] = chan(po);
spawn test05_start(chan(po));
- let int value; po |> value;
+ let value: int;
+ po |> value;
po |> value;
po |> value;
assert (value == 30);
-}
+}
\ No newline at end of file
diff --git a/src/test/run-pass/task-comm-1.rs b/src/test/run-pass/task-comm-1.rs
index 764919f..194ab3f 100644
--- a/src/test/run-pass/task-comm-1.rs
+++ b/src/test/run-pass/task-comm-1.rs
@@ -4,16 +4,8 @@
import std::task::join;
-fn main() -> () {
- test00();
-}
+fn main() { test00(); }
-fn start() {
- log "Started / Finished task.";
-}
+fn start() { log "Started / Finished task."; }
-fn test00() {
- let task t = spawn start();
- join(t);
- log "Completing.";
-}
\ No newline at end of file
+fn test00() { let t: task = spawn start(); join(t); log "Completing."; }
\ No newline at end of file
diff --git a/src/test/run-pass/task-comm-10.rs b/src/test/run-pass/task-comm-10.rs
index 56585ad..ad096c4 100644
--- a/src/test/run-pass/task-comm-10.rs
+++ b/src/test/run-pass/task-comm-10.rs
@@ -3,8 +3,8 @@
use std;
import std::task;
-fn start(chan[chan[str]] c) {
- let port[str] p;
+fn start(c: chan[chan[str]]) {
+ let p: port[str];
p = port();
c <| chan(p);
@@ -13,20 +13,20 @@
p |> b;
log_err b;
- auto a;
- auto b;
+ let a;
+ let b;
}
fn main() {
- let port[chan[str]] p;
- auto child;
+ let p: port[chan[str]];
+ let child;
p = port();
child = spawn start(chan(p));
- auto c;
+ let c;
p |> c;
c <| "A";
c <| "B";
task::yield();
-}
+}
\ No newline at end of file
diff --git a/src/test/run-pass/task-comm-11.rs b/src/test/run-pass/task-comm-11.rs
index 9a240dc..c93a4c3 100644
--- a/src/test/run-pass/task-comm-11.rs
+++ b/src/test/run-pass/task-comm-11.rs
@@ -1,13 +1,11 @@
// xfail-stage0
// xfail-stage3
-fn start(chan[chan[str]] c) {
- let port[str] p = port();
- c <| chan(p);
-}
+fn start(c: chan[chan[str]]) { let p: port[str] = port(); c <| chan(p); }
fn main() {
- let port[chan[str]] p = port();
- auto child = spawn start(chan(p));
- auto c; p |> c;
-}
+ let p: port[chan[str]] = port();
+ let child = spawn start(chan(p));
+ let c;
+ p |> c;
+}
\ No newline at end of file
diff --git a/src/test/run-pass/task-comm-12.rs b/src/test/run-pass/task-comm-12.rs
index 54d54f3..97fa86e 100644
--- a/src/test/run-pass/task-comm-12.rs
+++ b/src/test/run-pass/task-comm-12.rs
@@ -3,17 +3,13 @@
use std;
import std::task;
-fn main() -> () {
- test00();
-}
+fn main() { test00(); }
-fn start(int task_number) {
- log "Started / Finished task.";
-}
+fn start(task_number: int) { log "Started / Finished task."; }
fn test00() {
- let int i = 0;
- let task t = spawn start(i);
+ let i: int = 0;
+ let t: task = spawn start(i);
// Sleep long enough for the task to finish.
task::sleep(10000u);
diff --git a/src/test/run-pass/task-comm-13.rs b/src/test/run-pass/task-comm-13.rs
index 62bbf5e..48b0e48 100644
--- a/src/test/run-pass/task-comm-13.rs
+++ b/src/test/run-pass/task-comm-13.rs
@@ -3,18 +3,15 @@
use std;
import std::task;
-fn start(chan[int] c, int start, int number_of_messages) {
- let int i = 0;
- while (i < number_of_messages) {
- c <| start + i;
- i += 1;
- }
+fn start(c: chan[int], start: int, number_of_messages: int) {
+ let i: int = 0;
+ while i < number_of_messages { c <| start + i; i += 1; }
}
-fn main() -> () {
+fn main() {
log "Check that we don't deadlock.";
- let port[int] p = port();
- let task a = spawn start(chan(p), 0, 10);
+ let p: port[int] = port();
+ let a: task = spawn start(chan(p), 0, 10);
task::join(a);
log "Joined task";
}
\ No newline at end of file
diff --git a/src/test/run-pass/task-comm-15.rs b/src/test/run-pass/task-comm-15.rs
index 118bac2..f211ade 100644
--- a/src/test/run-pass/task-comm-15.rs
+++ b/src/test/run-pass/task-comm-15.rs
@@ -3,21 +3,20 @@
// xfail-stage3
// This test fails when run with multiple threads
-fn start(chan[int] c, int n) {
- let int i = n;
+fn start(c: chan[int], n: int) {
+ let i: int = n;
- while(i > 0) {
- c <| 0;
- i = i - 1;
- }
+
+ while i > 0 { c <| 0; i = i - 1; }
}
fn main() {
- let port[int] p = port();
+ let p: port[int] = port();
// Spawn a task that sends us back messages. The parent task
// is likely to terminate before the child completes, so from
// the child's point of view the receiver may die. We should
// drop messages on the floor in this case, and not crash!
- auto child = spawn start(chan(p), 10);
- auto c; p |> c;
-}
+ let child = spawn start(chan(p), 10);
+ let c;
+ p |> c;
+}
\ No newline at end of file
diff --git a/src/test/run-pass/task-comm-16.rs b/src/test/run-pass/task-comm-16.rs
index dfd6815..6ca323fa 100644
--- a/src/test/run-pass/task-comm-16.rs
+++ b/src/test/run-pass/task-comm-16.rs
@@ -2,13 +2,13 @@
// Tests of ports and channels on various types
fn test_rec() {
- type r = rec(int val0, u8 val1, char val2);
+ type r = {val0: int, val1: u8, val2: char};
- let port[r] po = port();
- let chan[r] ch = chan(po);
- let r r0 = rec(val0=0, val1=1u8, val2='2');
+ let po: port[r] = port();
+ let ch: chan[r] = chan(po);
+ let r0: r = {val0: 0, val1: 1u8, val2: '2'};
ch <| r0;
- let r r1;
+ let r1: r;
po |> r1;
assert (r1.val0 == 0);
assert (r1.val1 == 1u8);
@@ -16,11 +16,11 @@
}
fn test_vec() {
- let port[int[]] po = port();
- let chan[int[]] ch = chan(po);
- let int[] v0 = ~[0, 1, 2];
+ let po: port[int[]] = port();
+ let ch: chan[int[]] = chan(po);
+ let v0: int[] = ~[0, 1, 2];
ch <| v0;
- let int[] v1;
+ let v1: int[];
po |> v1;
assert (v1.(0) == 0);
assert (v1.(1) == 1);
@@ -28,11 +28,11 @@
}
fn test_str() {
- let port[str] po = port();
- let chan[str] ch = chan(po);
- let str s0 = "test";
+ let po: port[str] = port();
+ let ch: chan[str] = chan(po);
+ let s0: str = "test";
ch <| s0;
- let str s1;
+ let s1: str;
po |> s1;
assert (s1.(0) as u8 == 't' as u8);
assert (s1.(1) as u8 == 'e' as u8);
@@ -42,12 +42,12 @@
fn test_tag() {
tag t { tag1; tag2(int); tag3(int, u8, char); }
- let port[t] po = port();
- let chan[t] ch = chan(po);
+ let po: port[t] = port();
+ let ch: chan[t] = chan(po);
ch <| tag1;
ch <| tag2(10);
ch <| tag3(10, 11u8, 'A');
- let t t1;
+ let t1: t;
po |> t1;
assert (t1 == tag1);
po |> t1;
@@ -57,25 +57,19 @@
}
fn test_chan() {
- let port[chan[int]] po = port();
- let chan[chan[int]] ch = chan(po);
- let port[int] po0 = port();
- let chan[int] ch0 = chan(po0);
+ let po: port[chan[int]] = port();
+ let ch: chan[chan[int]] = chan(po);
+ let po0: port[int] = port();
+ let ch0: chan[int] = chan(po0);
ch <| ch0;
- let chan[int] ch1;
+ let ch1: chan[int];
po |> ch1;
// Does the transmitted channel still work?
ch1 <| 10;
- let int i;
+ let i: int;
po0 |> i;
assert (i == 10);
}
-fn main() {
- test_rec();
- test_vec();
- test_str();
- test_tag();
- test_chan();
-}
\ No newline at end of file
+fn main() { test_rec(); test_vec(); test_str(); test_tag(); test_chan(); }
\ No newline at end of file
diff --git a/src/test/run-pass/task-comm-2.rs b/src/test/run-pass/task-comm-2.rs
index 51ba905..3760978 100644
--- a/src/test/run-pass/task-comm-2.rs
+++ b/src/test/run-pass/task-comm-2.rs
@@ -4,33 +4,23 @@
import std::task;
-fn main() -> () {
- log "===== SPAWNING and JOINING THREAD TASKS =====";
- test00();
-}
+fn main() { log "===== SPAWNING and JOINING THREAD TASKS ====="; test00(); }
-fn start(int task_number) {
+fn start(task_number: int) {
log "Started task.";
- let int i = 0;
- while (i < 10000) {
- i = i + 1;
- }
+ let i: int = 0;
+ while i < 10000 { i = i + 1; }
log "Finished task.";
}
fn test00() {
- let int number_of_tasks = 8;
+ let number_of_tasks: int = 8;
- let int i = 0;
- let vec[task] tasks = [];
- while (i < number_of_tasks) {
- i = i + 1;
- tasks += [spawn start(i)];
- }
+ let i: int = 0;
+ let tasks: vec[task] = [];
+ while i < number_of_tasks { i = i + 1; tasks += [spawn start(i)]; }
- for (task t in tasks) {
- task::join(t);
- }
+ for t: task in tasks { task::join(t); }
log "Joined all task.";
}
\ No newline at end of file
diff --git a/src/test/run-pass/task-comm-3.rs b/src/test/run-pass/task-comm-3.rs
index 8b95df1..491ac2c 100644
--- a/src/test/run-pass/task-comm-3.rs
+++ b/src/test/run-pass/task-comm-3.rs
@@ -3,58 +3,50 @@
use std;
import std::task;
-fn main() -> () {
- log "===== WITHOUT THREADS =====";
- test00();
-}
+fn main() { log "===== WITHOUT THREADS ====="; test00(); }
-fn test00_start(chan[int] ch, int message, int count) {
+fn test00_start(ch: chan[int], message: int, count: int) {
log "Starting test00_start";
- let int i = 0;
- while (i < count) {
- log "Sending Message";
- ch <| message;
- i = i + 1;
- }
+ let i: int = 0;
+ while i < count { log "Sending Message"; ch <| message; i = i + 1; }
log "Ending test00_start";
}
fn test00() {
- let int number_of_tasks = 16;
- let int number_of_messages = 4;
+ let number_of_tasks: int = 16;
+ let number_of_messages: int = 4;
log "Creating tasks";
- let port[int] po = port();
- let chan[int] ch = chan(po);
+ let po: port[int] = port();
+ let ch: chan[int] = chan(po);
- let int i = 0;
+ let i: int = 0;
// Create and spawn tasks...
- let vec[task] tasks = [];
- while (i < number_of_tasks) {
+ let tasks: vec[task] = [];
+ while i < number_of_tasks {
tasks += [spawn test00_start(ch, i, number_of_messages)];
i = i + 1;
}
// Read from spawned tasks...
- let int sum = 0;
- for (task t in tasks) {
+ let sum: int = 0;
+ for t: task in tasks {
i = 0;
- while (i < number_of_messages) {
- let int value; po |> value;
+ while i < number_of_messages {
+ let value: int;
+ po |> value;
sum += value;
i = i + 1;
}
}
// Join spawned tasks...
- for (task t in tasks) {
- task::join(t);
- }
+ for t: task in tasks { task::join(t); }
log "Completed: Final number is: ";
// assert (sum == (((number_of_tasks * (number_of_tasks - 1)) / 2) *
// number_of_messages));
assert (sum == 480);
-}
+}
\ No newline at end of file
diff --git a/src/test/run-pass/task-comm-4.rs b/src/test/run-pass/task-comm-4.rs
index b26bd63..1b002a6 100644
--- a/src/test/run-pass/task-comm-4.rs
+++ b/src/test/run-pass/task-comm-4.rs
@@ -3,10 +3,10 @@
fn main() { test00(); }
fn test00() {
- let int r = 0;
- let int sum = 0;
- let port[int] p = port();
- let chan[int] c = chan(p);
+ let r: int = 0;
+ let sum: int = 0;
+ let p: port[int] = port();
+ let c: chan[int] = chan(p);
c <| 1;
c <| 2;
c <| 3;
diff --git a/src/test/run-pass/task-comm-5.rs b/src/test/run-pass/task-comm-5.rs
index 8e19b77..d156203 100644
--- a/src/test/run-pass/task-comm-5.rs
+++ b/src/test/run-pass/task-comm-5.rs
@@ -3,14 +3,14 @@
fn main() { test00(); }
fn test00() {
- let int r = 0;
- let int sum = 0;
- let port[int] p = port();
- let chan[int] c = chan(p);
- let int number_of_messages = 1000;
- let int i = 0;
- while (i < number_of_messages) { c <| i; i += 1; }
+ let r: int = 0;
+ let sum: int = 0;
+ let p: port[int] = port();
+ let c: chan[int] = chan(p);
+ let number_of_messages: int = 1000;
+ let i: int = 0;
+ while i < number_of_messages { c <| i; i += 1; }
i = 0;
- while (i < number_of_messages) { p |> r; sum += r; i += 1; }
+ while i < number_of_messages { p |> r; sum += r; i += 1; }
assert (sum == number_of_messages * (number_of_messages - 1) / 2);
}
\ No newline at end of file
diff --git a/src/test/run-pass/task-comm-6.rs b/src/test/run-pass/task-comm-6.rs
index 8f61a20..c273d87 100644
--- a/src/test/run-pass/task-comm-6.rs
+++ b/src/test/run-pass/task-comm-6.rs
@@ -3,16 +3,16 @@
fn main() { test00(); }
fn test00() {
- let int r = 0;
- let int sum = 0;
- let port[int] p = port();
- let chan[int] c0 = chan(p);
- let chan[int] c1 = chan(p);
- let chan[int] c2 = chan(p);
- let chan[int] c3 = chan(p);
- let int number_of_messages = 1000;
- let int i = 0;
- while (i < number_of_messages) {
+ let r: int = 0;
+ let sum: int = 0;
+ let p: port[int] = port();
+ let c0: chan[int] = chan(p);
+ let c1: chan[int] = chan(p);
+ let c2: chan[int] = chan(p);
+ let c3: chan[int] = chan(p);
+ let number_of_messages: int = 1000;
+ let i: int = 0;
+ while i < number_of_messages {
c0 <| i;
c1 <| i;
c2 <| i;
@@ -20,7 +20,7 @@
i += 1;
}
i = 0;
- while (i < number_of_messages) {
+ while i < number_of_messages {
p |> r;
sum += r;
p |> r;
diff --git a/src/test/run-pass/task-comm-7.rs b/src/test/run-pass/task-comm-7.rs
index 6f23ffe..defcc77 100644
--- a/src/test/run-pass/task-comm-7.rs
+++ b/src/test/run-pass/task-comm-7.rs
@@ -3,39 +3,42 @@
use std;
import std::task;
-fn main() -> () {
- test00();
-}
+fn main() { test00(); }
-fn test00_start(chan[int] c, int start, int number_of_messages) {
- let int i = 0;
- while (i < number_of_messages) {
- c <| start + i;
- i += 1;
- }
+fn test00_start(c: chan[int], start: int, number_of_messages: int) {
+ let i: int = 0;
+ while i < number_of_messages { c <| start + i; i += 1; }
}
fn test00() {
- let int r = 0;
- let int sum = 0;
- let port[int] p = port();
- let int number_of_messages = 10;
+ let r: int = 0;
+ let sum: int = 0;
+ let p: port[int] = port();
+ let number_of_messages: int = 10;
- let task t0 = spawn test00_start(chan(p),
- number_of_messages * 0, number_of_messages);
- let task t1 = spawn test00_start(chan(p),
- number_of_messages * 1, number_of_messages);
- let task t2 = spawn test00_start(chan(p),
- number_of_messages * 2, number_of_messages);
- let task t3 = spawn test00_start(chan(p),
- number_of_messages * 3, number_of_messages);
+ let t0: task =
+ spawn test00_start(chan(p), number_of_messages * 0,
+ number_of_messages);
+ let t1: task =
+ spawn test00_start(chan(p), number_of_messages * 1,
+ number_of_messages);
+ let t2: task =
+ spawn test00_start(chan(p), number_of_messages * 2,
+ number_of_messages);
+ let t3: task =
+ spawn test00_start(chan(p), number_of_messages * 3,
+ number_of_messages);
- let int i = 0;
- while (i < number_of_messages) {
- p |> r; sum += r;
- p |> r; sum += r;
- p |> r; sum += r;
- p |> r; sum += r;
+ let i: int = 0;
+ while i < number_of_messages {
+ p |> r;
+ sum += r;
+ p |> r;
+ sum += r;
+ p |> r;
+ sum += r;
+ p |> r;
+ sum += r;
i += 1;
}
@@ -44,6 +47,5 @@
task::join(t2);
task::join(t3);
- assert (sum == (((number_of_messages * 4) *
- ((number_of_messages * 4) - 1)) / 2));
+ assert (sum == number_of_messages * 4 * (number_of_messages * 4 - 1) / 2);
}
\ No newline at end of file
diff --git a/src/test/run-pass/task-comm-8.rs b/src/test/run-pass/task-comm-8.rs
index 6f23ffe..defcc77 100644
--- a/src/test/run-pass/task-comm-8.rs
+++ b/src/test/run-pass/task-comm-8.rs
@@ -3,39 +3,42 @@
use std;
import std::task;
-fn main() -> () {
- test00();
-}
+fn main() { test00(); }
-fn test00_start(chan[int] c, int start, int number_of_messages) {
- let int i = 0;
- while (i < number_of_messages) {
- c <| start + i;
- i += 1;
- }
+fn test00_start(c: chan[int], start: int, number_of_messages: int) {
+ let i: int = 0;
+ while i < number_of_messages { c <| start + i; i += 1; }
}
fn test00() {
- let int r = 0;
- let int sum = 0;
- let port[int] p = port();
- let int number_of_messages = 10;
+ let r: int = 0;
+ let sum: int = 0;
+ let p: port[int] = port();
+ let number_of_messages: int = 10;
- let task t0 = spawn test00_start(chan(p),
- number_of_messages * 0, number_of_messages);
- let task t1 = spawn test00_start(chan(p),
- number_of_messages * 1, number_of_messages);
- let task t2 = spawn test00_start(chan(p),
- number_of_messages * 2, number_of_messages);
- let task t3 = spawn test00_start(chan(p),
- number_of_messages * 3, number_of_messages);
+ let t0: task =
+ spawn test00_start(chan(p), number_of_messages * 0,
+ number_of_messages);
+ let t1: task =
+ spawn test00_start(chan(p), number_of_messages * 1,
+ number_of_messages);
+ let t2: task =
+ spawn test00_start(chan(p), number_of_messages * 2,
+ number_of_messages);
+ let t3: task =
+ spawn test00_start(chan(p), number_of_messages * 3,
+ number_of_messages);
- let int i = 0;
- while (i < number_of_messages) {
- p |> r; sum += r;
- p |> r; sum += r;
- p |> r; sum += r;
- p |> r; sum += r;
+ let i: int = 0;
+ while i < number_of_messages {
+ p |> r;
+ sum += r;
+ p |> r;
+ sum += r;
+ p |> r;
+ sum += r;
+ p |> r;
+ sum += r;
i += 1;
}
@@ -44,6 +47,5 @@
task::join(t2);
task::join(t3);
- assert (sum == (((number_of_messages * 4) *
- ((number_of_messages * 4) - 1)) / 2));
+ assert (sum == number_of_messages * 4 * (number_of_messages * 4 - 1) / 2);
}
\ No newline at end of file
diff --git a/src/test/run-pass/task-comm-9.rs b/src/test/run-pass/task-comm-9.rs
index cb2479b..19654ae 100644
--- a/src/test/run-pass/task-comm-9.rs
+++ b/src/test/run-pass/task-comm-9.rs
@@ -3,34 +3,25 @@
use std;
import std::task;
-fn main() -> () {
- test00();
-}
+fn main() { test00(); }
-fn test00_start(chan[int] c, int number_of_messages) {
- let int i = 0;
- while (i < number_of_messages) {
- c <| i;
- i += 1;
- }
+fn test00_start(c: chan[int], number_of_messages: int) {
+ let i: int = 0;
+ while i < number_of_messages { c <| i; i += 1; }
}
fn test00() {
- let int r = 0;
- let int sum = 0;
- let port[int] p = port();
- let int number_of_messages = 10;
+ let r: int = 0;
+ let sum: int = 0;
+ let p: port[int] = port();
+ let number_of_messages: int = 10;
- let task t0 = spawn
- test00_start(chan(p), number_of_messages);
+ let t0: task = spawn test00_start(chan(p), number_of_messages);
- let int i = 0;
- while (i < number_of_messages) {
- p |> r; sum += r; log (r);
- i += 1;
- }
+ let i: int = 0;
+ while i < number_of_messages { p |> r; sum += r; log r; i += 1; }
task::join(t0);
- assert (sum == (number_of_messages * (number_of_messages - 1)) / 2);
+ assert (sum == number_of_messages * (number_of_messages - 1) / 2);
}
\ No newline at end of file
diff --git a/src/test/run-pass/task-comm-chan-nil.rs b/src/test/run-pass/task-comm-chan-nil.rs
index 157ddfd..2cdd2c5 100644
--- a/src/test/run-pass/task-comm-chan-nil.rs
+++ b/src/test/run-pass/task-comm-chan-nil.rs
@@ -7,10 +7,10 @@
// any size, but rustc currently can because they do have size. Whether
// or not this is desirable I don't know, but here's a regression test.
fn main() {
- let port[()] po = port();
- let chan[()] ch = chan(po);
+ let po: port[()] = port();
+ let ch: chan[()] = chan(po);
ch <| ();
- let () n;
+ let n: ();
po |> n;
assert (n == ());
}
\ No newline at end of file
diff --git a/src/test/run-pass/task-comm.rs b/src/test/run-pass/task-comm.rs
index 26087f9..6b69bbb 100644
--- a/src/test/run-pass/task-comm.rs
+++ b/src/test/run-pass/task-comm.rs
@@ -4,7 +4,7 @@
import std::task;
-fn main() -> () {
+fn main() {
test00();
// test01();
test02();
@@ -14,104 +14,95 @@
test06();
}
-fn test00_start(chan[int] ch, int message, int count) {
+fn test00_start(ch: chan[int], message: int, count: int) {
log "Starting test00_start";
- let int i = 0;
- while (i < count) {
- log "Sending Message";
- ch <| message;
- i = i + 1;
- }
+ let i: int = 0;
+ while i < count { log "Sending Message"; ch <| message; i = i + 1; }
log "Ending test00_start";
}
fn test00() {
- let int number_of_tasks = 1;
- let int number_of_messages = 4;
+ let number_of_tasks: int = 1;
+ let number_of_messages: int = 4;
log "Creating tasks";
- let port[int] po = port();
- let chan[int] ch = chan(po);
+ let po: port[int] = port();
+ let ch: chan[int] = chan(po);
- let int i = 0;
+ let i: int = 0;
- let vec[task] tasks = [];
- while (i < number_of_tasks) {
+ let tasks: vec[task] = [];
+ while i < number_of_tasks {
i = i + 1;
tasks += [spawn test00_start(ch, i, number_of_messages)];
}
- let int sum = 0;
- for (task t in tasks) {
+ let sum: int = 0;
+ for t: task in tasks {
i = 0;
- while (i < number_of_messages) {
- let int value; po |> value;
+ while i < number_of_messages {
+ let value: int;
+ po |> value;
sum += value;
i = i + 1;
}
}
- for (task t in tasks) {
- task::join(t);
- }
+ for t: task in tasks { task::join(t); }
log "Completed: Final number is: ";
- assert (sum == number_of_messages *
- (number_of_tasks * number_of_tasks + number_of_tasks) / 2);
+ assert (sum ==
+ number_of_messages *
+ (number_of_tasks * number_of_tasks + number_of_tasks) /
+ 2);
}
fn test01() {
- let port[int] p = port();
+ let p: port[int] = port();
log "Reading from a port that is never written to.";
- let int value; p |> value;
+ let value: int;
+ p |> value;
log value;
}
fn test02() {
- let port[int] p = port();
- let chan[int] c = chan(p);
+ let p: port[int] = port();
+ let c: chan[int] = chan(p);
log "Writing to a local task channel.";
c <| 42;
log "Reading from a local task port.";
- let int value; p |> value;
+ let value: int;
+ p |> value;
log value;
}
-obj vector(mutable int x, int y) {
- fn length() -> int {
- x = x + 2;
- ret x + y;
- }
+obj vector(mutable x: int, y: int) {
+ fn length() -> int { x = x + 2; ret x + y; }
}
fn test03() {
log "Creating object ...";
- let vector v = vector(1, 2);
+ let v: vector = vector(1, 2);
log "created object ...";
- let vector t = v;
+ let t: vector = v;
log v.length();
}
fn test04_start() {
log "Started task";
- let int i = 1024 * 1024 * 64;
- while (i > 0) {
- i = i - 1;
- }
+ let i: int = 1024 * 1024 * 64;
+ while i > 0 { i = i - 1; }
log "Finished task";
}
fn test04() {
log "Spawning lots of tasks.";
- let int i = 4;
- while (i > 0) {
- i = i - 1;
- spawn test04_start();
- }
+ let i: int = 4;
+ while i > 0 { i = i - 1; spawn test04_start(); }
log "Finishing up.";
}
-fn test05_start(chan[int] ch) {
+fn test05_start(ch: chan[int]) {
ch <| 10;
ch <| 20;
ch <| 30;
@@ -120,39 +111,34 @@
}
fn test05() {
- let port[int] po = port();
- let chan[int] ch = chan(po);
+ let po: port[int] = port();
+ let ch: chan[int] = chan(po);
spawn test05_start(ch);
- let int value; po |> value;
+ let value: int;
+ po |> value;
po |> value;
po |> value;
log value;
}
-fn test06_start(int task_number) {
+fn test06_start(task_number: int) {
log "Started task.";
- let int i = 0;
- while (i < 100000000) {
- i = i + 1;
- }
+ let i: int = 0;
+ while i < 100000000 { i = i + 1; }
log "Finished task.";
}
fn test06() {
- let int number_of_tasks = 4;
+ let number_of_tasks: int = 4;
log "Creating tasks";
- let int i = 0;
+ let i: int = 0;
- let vec[task] tasks = [];
- while (i < number_of_tasks) {
- i = i + 1;
- tasks += [spawn test06_start(i)];
- }
+ let tasks: vec[task] = [];
+ while i < number_of_tasks { i = i + 1; tasks += [spawn test06_start(i)]; }
- for (task t in tasks) {
- task::join(t);
- }
+
+ for t: task in tasks { task::join(t); }
}
diff --git a/src/test/run-pass/task-compare.rs b/src/test/run-pass/task-compare.rs
index 15708f4..ad05546 100644
--- a/src/test/run-pass/task-compare.rs
+++ b/src/test/run-pass/task-compare.rs
@@ -10,36 +10,39 @@
use std;
import std::task::join;
-fn child() {}
+fn child() { }
fn main() {
// tasks
- auto t1; auto t2;
+ let t1;
+ let t2;
t1 = spawn child();
t2 = spawn child();
- assert(t1 == t1);
- assert(t1 != t2);
+ assert (t1 == t1);
+ assert (t1 != t2);
// ports
- auto p1; auto p2;
+ let p1;
+ let p2;
p1 = port[int]();
p2 = port[int]();
- assert(p1 == p1);
- assert(p1 != p2);
+ assert (p1 == p1);
+ assert (p1 != p2);
// channels
- auto c1; auto c2;
+ let c1;
+ let c2;
c1 = chan(p1);
c2 = chan(p2);
- assert(c1 == c1);
- assert(c1 != c2);
+ assert (c1 == c1);
+ assert (c1 != c2);
join(t1);
join(t2);
-}
+}
\ No newline at end of file
diff --git a/src/test/run-pass/task-killjoin.rs b/src/test/run-pass/task-killjoin.rs
index bad47e2..e12526a 100644
--- a/src/test/run-pass/task-killjoin.rs
+++ b/src/test/run-pass/task-killjoin.rs
@@ -1,41 +1,6 @@
-// xfail-stage0
-// xfail-stage1
-// xfail-stage2
-// xfail-stage3
-
-// Create a task that is supervised by another task,
-// join the supervised task from the supervising task,
-// then fail the supervised task. The supervised task
-// will kill the supervising task, waking it up. The
-// supervising task no longer needs to be wakened when
-// the supervised task exits.
-
-fn supervised() {
- // Yield to make sure the supervisor joins before we
- // fail. This is currently not needed because the supervisor
- // runs first, but I can imagine that changing.
- yield;
- fail;
-}
-
-fn supervisor() {
- let task t = spawn "supervised" supervised();
- join t;
-}
-
-fn main() {
- // Start the test in another domain so that
- // the process doesn't return a failure status as a result
- // of the main task being killed.
- let task dom2 = spawn thread "supervisor" supervisor();
- join dom2;
-}
-
-// Local Variables:
-// mode: rust;
-// fill-column: 78;
-// indent-tabs-mode: nil
-// c-basic-offset: 4
-// buffer-file-coding-system: utf-8-unix
-// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
+./src/test/run-pass/task-killjoin.rs:22:36:22:46: [1;31merror:[0m expecting (, found supervised
+./src/test/run-pass/task-killjoin.rs:22 let task t = spawn "supervised" supervised();
+ ^~~~~~~~~~
+rt: ---
+rt: f00e:main:main: upcall fail 'explicit failure', src/comp/syntax/parse/parser.rs:112
+rt: f00e:main: domain main @0xa7b604c root task failed
diff --git a/src/test/run-pass/task-life-0.rs b/src/test/run-pass/task-life-0.rs
index a73773b..d0d1e07 100644
--- a/src/test/run-pass/task-life-0.rs
+++ b/src/test/run-pass/task-life-0.rs
@@ -1,8 +1,6 @@
// xfail-stage0
-fn main() -> () {
- spawn child("Hello");
-}
+fn main() { spawn child("Hello"); }
-fn child(str s) {
+fn child(s: str) {
-}
+}
\ No newline at end of file
diff --git a/src/test/run-pass/task-pin.rs b/src/test/run-pass/task-pin.rs
index d2c4e14..d29548b 100644
--- a/src/test/run-pass/task-pin.rs
+++ b/src/test/run-pass/task-pin.rs
@@ -9,7 +9,4 @@
import std::task;
-fn main() {
- task::pin();
- task::unpin();
-}
\ No newline at end of file
+fn main() { task::pin(); task::unpin(); }
\ No newline at end of file
diff --git a/src/test/run-pass/ternary.rs b/src/test/run-pass/ternary.rs
index 364b422..ff68840 100644
--- a/src/test/run-pass/ternary.rs
+++ b/src/test/run-pass/ternary.rs
@@ -1,52 +1,45 @@
// xfail-stage0
-fn test_simple() {
- auto x = true ? 10 : 11;
- assert (x == 10);
-}
+fn test_simple() { let x = true ? 10 : 11; assert (x == 10); }
fn test_precedence() {
- auto x;
+ let x;
- x = true || true ? 10 : 11;
- assert (x == 10);
+ x = true || true ? 10 : 11;
+ assert (x == 10);
- x = true == false ? 10 : 11;
- assert (x == 11);
+ x = true == false ? 10 : 11;
+ assert (x == 11);
- x = true ? false ? 10 : 11 : 12;
- assert (x == 11);
+ x = true ? false ? 10 : 11 : 12;
+ assert (x == 11);
- auto y = true ? 0xF0 : 0x0 | 0x0F;
- assert (y == 0xF0);
+ let y = true ? 0xF0 : 0x0 | 0x0F;
+ assert (y == 0xF0);
- y = true ? 0xF0 | 0x0F : 0x0;
- assert (y == 0xFF);
+ y = true ? 0xF0 | 0x0F : 0x0;
+ assert (y == 0xFF);
}
fn test_associativity() {
- // Ternary is right-associative
- auto x = false ? 10 : false ? 11 : 12;
- assert (x == 12);
+ // Ternary is right-associative
+ let x = false ? 10 : false ? 11 : 12;
+ assert (x == 12);
}
fn test_lval() {
- let @mutable int box1 = @mutable 10;
- let @mutable int box2 = @mutable 10;
- *(true ? box1 : box2) = 100;
- assert (*box1 == 100);
+ let box1: @mutable int = @mutable 10;
+ let box2: @mutable int = @mutable 10;
+ *(true ? box1 : box2) = 100;
+ assert (*box1 == 100);
}
-fn test_as_stmt() {
- auto s;
- true ? s = 10 : s = 12;
- assert (s == 10);
-}
+fn test_as_stmt() { let s; true ? s = 10 : s = 12; assert (s == 10); }
fn main() {
- test_simple();
- test_precedence();
- test_associativity();
- test_lval();
- test_as_stmt();
+ test_simple();
+ test_precedence();
+ test_associativity();
+ test_lval();
+ test_as_stmt();
}
\ No newline at end of file
diff --git a/src/test/run-pass/test-runner-hides-main.rs b/src/test/run-pass/test-runner-hides-main.rs
index 2b48e45..2edf36d 100644
--- a/src/test/run-pass/test-runner-hides-main.rs
+++ b/src/test/run-pass/test-runner-hides-main.rs
@@ -5,6 +5,4 @@
// Building as a test runner means that a synthetic main will be run,
// not ours
-fn main() {
- fail;
-}
\ No newline at end of file
+fn main() { fail; }
\ No newline at end of file
diff --git a/src/test/run-pass/threads.rs b/src/test/run-pass/threads.rs
index 885b0e8..82ba2de 100644
--- a/src/test/run-pass/threads.rs
+++ b/src/test/run-pass/threads.rs
@@ -1,20 +1,6 @@
-// xfail-stage0
-// xfail-stage1
-// xfail-stage2
-// xfail-stage3
-
-// -*- rust -*-
-
-fn main() {
- let int i = 10;
- while (i > 0) {
- spawn thread "child" child(i);
- i = i - 1;
- }
- log "main thread exiting";
-}
-
-fn child(int x) {
- log x;
-}
-
+./src/test/run-pass/threads.rs:11:17:11:24: [1;31merror:[0m expecting (, found "child"
+./src/test/run-pass/threads.rs:11 spawn thread "child" child(i);
+ ^~~~~~~
+rt: ---
+rt: f00e:main:main: upcall fail 'explicit failure', src/comp/syntax/parse/parser.rs:112
+rt: f00e:main: domain main @0x999804c root task failed
diff --git a/src/test/run-pass/trivial-message.rs b/src/test/run-pass/trivial-message.rs
index eb21f7a..e5f25d6 100644
--- a/src/test/run-pass/trivial-message.rs
+++ b/src/test/run-pass/trivial-message.rs
@@ -6,10 +6,10 @@
message.
*/
fn main() {
- let port[int] po = port();
- let chan[int] ch = chan(po);
+ let po: port[int] = port();
+ let ch: chan[int] = chan(po);
ch <| 42;
- auto r;
+ let r;
po |> r;
log_err r;
}
\ No newline at end of file
diff --git a/src/test/run-pass/type-in-nested-module.rs b/src/test/run-pass/type-in-nested-module.rs
index 230a222..2c91b35 100644
--- a/src/test/run-pass/type-in-nested-module.rs
+++ b/src/test/run-pass/type-in-nested-module.rs
@@ -4,7 +4,7 @@
mod b {
type t = int;
- fn foo() { let t x = 10; }
+ fn foo() { let x: t = 10; }
}
}
diff --git a/src/test/run-pass/type-namespace.rs b/src/test/run-pass/type-namespace.rs
index 8649509..25262c9 100644
--- a/src/test/run-pass/type-namespace.rs
+++ b/src/test/run-pass/type-namespace.rs
@@ -2,8 +2,8 @@
// xfail-stage0
-type a = rec(int a);
+type a = {a: int};
-fn a(a a) -> int { ret a.a; }
+fn a(a: a) -> int { ret a.a; }
-fn main() { let a x = rec(a=1); assert (a(x) == 1); }
\ No newline at end of file
+fn main() { let x: a = {a: 1}; assert (a(x) == 1); }
\ No newline at end of file
diff --git a/src/test/run-pass/type-param.rs b/src/test/run-pass/type-param.rs
index 9315e23..404adc1 100644
--- a/src/test/run-pass/type-param.rs
+++ b/src/test/run-pass/type-param.rs
@@ -2,4 +2,4 @@
type lteq[T] = fn(&T) -> bool ;
-fn main(vec[str] args) { }
\ No newline at end of file
+fn main(args: vec[str]) { }
\ No newline at end of file
diff --git a/src/test/run-pass/type-params-in-for-each.rs b/src/test/run-pass/type-params-in-for-each.rs
index ee9ba17..caee2a1 100644
--- a/src/test/run-pass/type-params-in-for-each.rs
+++ b/src/test/run-pass/type-params-in-for-each.rs
@@ -1,12 +1,12 @@
-iter range(uint lo, uint hi) -> uint {
- auto lo_ = lo;
- while (lo_ < hi) { put lo_; lo_ += 1u; }
+iter range(lo: uint, hi: uint) -> uint {
+ let lo_ = lo;
+ while lo_ < hi { put lo_; lo_ += 1u; }
}
-fn create_index[T](vec[rec(T a, uint b)] index, fn(&T) -> uint hash_fn) {
- for each (uint i in range(0u, 256u)) { let vec[T] bucket = []; }
+fn create_index[T](index: vec[{a: T, b: uint}], hash_fn: fn(&T) -> uint ) {
+ for each i: uint in range(0u, 256u) { let bucket: vec[T] = []; }
}
fn main() { }
\ No newline at end of file
diff --git a/src/test/run-pass/type-ptr.rs b/src/test/run-pass/type-ptr.rs
index 3743fb1..b5cdb00 100644
--- a/src/test/run-pass/type-ptr.rs
+++ b/src/test/run-pass/type-ptr.rs
@@ -1,12 +1,5 @@
-fn f(*int a) -> *int {
- ret a;
-}
+fn f(a: *int) -> *int { ret a; }
-fn g(*int a) -> *int {
- auto b = f(a);
- ret b;
-}
+fn g(a: *int) -> *int { let b = f(a); ret b; }
-fn main(vec[str] args) {
- ret;
-}
+fn main(args: vec[str]) { ret; }
\ No newline at end of file
diff --git a/src/test/run-pass/type-sizes.rs b/src/test/run-pass/type-sizes.rs
index ab57657..8798142 100644
--- a/src/test/run-pass/type-sizes.rs
+++ b/src/test/run-pass/type-sizes.rs
@@ -13,14 +13,14 @@
assert (size_of[char]() == 4 as uint);
assert (size_of[i8]() == 1 as uint);
assert (size_of[i32]() == 4 as uint);
- assert (size_of[rec(u8 a, i8 b)]() == 2 as uint);
- assert (size_of[rec(u8 a, i8 b, u8 c)]() == 3 as uint);
+ assert (size_of[{a: u8, b: i8}]() == 2 as uint);
+ assert (size_of[{a: u8, b: i8, c: u8}]() == 3 as uint);
// Alignment causes padding before the char and the u32.
- assert (size_of[rec(u8 a, i8 b, rec(char u, u8 v) c, u32 d)]()
- == 16 as uint);
+ assert (size_of[{a: u8, b: i8, c: {u: char, v: u8}, d: u32}]() ==
+ 16 as uint);
assert (size_of[int]() == size_of[uint]());
- assert (size_of[rec(int a, () b)]() == size_of[int]());
- assert (size_of[rec(int a, () b, () c)]() == size_of[int]());
- assert (size_of[int]() == size_of[rec(int x)]());
+ assert (size_of[{a: int, b: ()}]() == size_of[int]());
+ assert (size_of[{a: int, b: (), c: ()}]() == size_of[int]());
+ assert (size_of[int]() == size_of[{x: int}]());
}
\ No newline at end of file
diff --git a/src/test/run-pass/typestate-cfg-nesting.rs b/src/test/run-pass/typestate-cfg-nesting.rs
index 0e6c1c7..5270292 100644
--- a/src/test/run-pass/typestate-cfg-nesting.rs
+++ b/src/test/run-pass/typestate-cfg-nesting.rs
@@ -1,13 +1,9 @@
-fn f() {
- auto x = 10;
- auto y = 11;
- if (true) { alt (x) { case (_) { y = x; } } } else { }
-}
+fn f() { let x = 10; let y = 11; if true { alt x { _ { y = x; } } } else { } }
fn main() {
- auto x = 10;
- auto y = 11;
- if (true) { while (false) { y = x; } } else { }
+ let x = 10;
+ let y = 11;
+ if true { while false { y = x; } } else { }
}
\ No newline at end of file
diff --git a/src/test/run-pass/typestate-transitive.rs b/src/test/run-pass/typestate-transitive.rs
index 86dacb2..acc9f0c 100644
--- a/src/test/run-pass/typestate-transitive.rs
+++ b/src/test/run-pass/typestate-transitive.rs
@@ -1,8 +1,7 @@
-pred p(int i) -> bool { true }
+pred p(i: int) -> bool { true }
-fn f(int i) : p(i) -> int { i }
+fn f(i: int) -> int { i }
-fn g(int i) : p(i) -> int { f(i) }
+fn g(i: int) -> int { f(i) }
-fn main() {
-}
+fn main() { }
\ No newline at end of file
diff --git a/src/test/run-pass/u32-decr.rs b/src/test/run-pass/u32-decr.rs
index 6951b6a..ba7af14 100644
--- a/src/test/run-pass/u32-decr.rs
+++ b/src/test/run-pass/u32-decr.rs
@@ -3,7 +3,7 @@
// -*- rust -*-
fn main() {
- let u32 word = 200000u32;
+ let word: u32 = 200000u32;
word = word - 1u32;
assert (word == 199999u32);
}
\ No newline at end of file
diff --git a/src/test/run-pass/u8-incr-decr.rs b/src/test/run-pass/u8-incr-decr.rs
index a23b22e..8562a87 100644
--- a/src/test/run-pass/u8-incr-decr.rs
+++ b/src/test/run-pass/u8-incr-decr.rs
@@ -6,9 +6,9 @@
// These constants were chosen because they aren't used anywhere
// in the rest of the generated code so they're easily grep-able.
fn main() {
- let u8 x = 19u8; // 0x13
+ let x: u8 = 19u8; // 0x13
- let u8 y = 35u8; // 0x23
+ let y: u8 = 35u8; // 0x23
x = x + 7u8; // 0x7
diff --git a/src/test/run-pass/u8-incr.rs b/src/test/run-pass/u8-incr.rs
index f2e0217..c1f0ee3 100644
--- a/src/test/run-pass/u8-incr.rs
+++ b/src/test/run-pass/u8-incr.rs
@@ -3,8 +3,8 @@
// -*- rust -*-
fn main() {
- let u8 x = 12u8;
- let u8 y = 12u8;
+ let x: u8 = 12u8;
+ let y: u8 = 12u8;
x = x + 1u8;
x = x - 1u8;
assert (x == y);
diff --git a/src/test/run-pass/uint.rs b/src/test/run-pass/uint.rs
index b567bf4..8e5795e 100644
--- a/src/test/run-pass/uint.rs
+++ b/src/test/run-pass/uint.rs
@@ -2,4 +2,4 @@
// -*- rust -*-
-fn main() { let uint x = 10 as uint; }
\ No newline at end of file
+fn main() { let x: uint = 10 as uint; }
\ No newline at end of file
diff --git a/src/test/run-pass/unit.rs b/src/test/run-pass/unit.rs
index 8d427b6b..6b944d5 100644
--- a/src/test/run-pass/unit.rs
+++ b/src/test/run-pass/unit.rs
@@ -2,6 +2,6 @@
// -*- rust -*-
-fn f(() u) { ret u; }
+fn f(u: ()) { ret u; }
-fn main() { let () u1 = (); let () u2 = f(u1); u2 = (); ret (); }
\ No newline at end of file
+fn main() { let u1: () = (); let u2: () = f(u1); u2 = (); ret (); }
\ No newline at end of file
diff --git a/src/test/run-pass/use-uninit-alt.rs b/src/test/run-pass/use-uninit-alt.rs
index 56a75a8..70917c9 100644
--- a/src/test/run-pass/use-uninit-alt.rs
+++ b/src/test/run-pass/use-uninit-alt.rs
@@ -1,8 +1,8 @@
-fn foo[T](&myoption[T] o) -> int {
- let int x = 5;
- alt (o) { case (none[T]) { } case (some[T](?t)) { x += 1; } }
+fn foo[T](o: &myoption[T]) -> int {
+ let x: int = 5;
+ alt o { none[T]. { } some[T](t) { x += 1; } }
ret x;
}
diff --git a/src/test/run-pass/use-uninit-alt2.rs b/src/test/run-pass/use-uninit-alt2.rs
index ea30367..4eb1890 100644
--- a/src/test/run-pass/use-uninit-alt2.rs
+++ b/src/test/run-pass/use-uninit-alt2.rs
@@ -1,8 +1,8 @@
-fn foo[T](&myoption[T] o) -> int {
- let int x;
- alt (o) { case (none[T]) { fail; } case (some[T](?t)) { x = 5; } }
+fn foo[T](o: &myoption[T]) -> int {
+ let x: int;
+ alt o { none[T]. { fail; } some[T](t) { x = 5; } }
ret x;
}
diff --git a/src/test/run-pass/user.rs b/src/test/run-pass/user.rs
index 02d184e..1af1995 100644
--- a/src/test/run-pass/user.rs
+++ b/src/test/run-pass/user.rs
@@ -1,18 +1,6 @@
-// xfail-stage0
-// xfail-stage1
-// xfail-stage2
-// xfail-stage3
-// -*- rust -*-
-
-use std (name = "std",
- url = "http://rust-lang.org/src/std",
- uuid = _, ver = _);
-
-fn main() {
- auto s = std::str.alloc(10 as uint);
- s += "hello ";
- log s;
- s += "there";
- log s;
- auto z = std::vec.alloc[int](10 as uint);
-}
+./src/test/run-pass/user.rs:9:16:9:17: [1;31merror:[0m unexpected token: _
+./src/test/run-pass/user.rs:9 uuid = _, ver = _);
+ ^
+rt: ---
+rt: f00e:main:main: upcall fail 'explicit failure', src/comp/syntax/parse/parser.rs:112
+rt: f00e:main: domain main @0x907604c root task failed
diff --git a/src/test/run-pass/utf8.rs b/src/test/run-pass/utf8.rs
index 64c192d..d02a7fa 100644
--- a/src/test/run-pass/utf8.rs
+++ b/src/test/run-pass/utf8.rs
@@ -1,50 +1,50 @@
// xfail-stage0
fn main() {
- let char yen = '¥'; // 0xa5
- let char c_cedilla = 'ç'; // 0xe7
- let char thorn = 'þ'; // 0xfe
- let char y_diaeresis = 'ÿ'; // 0xff
- let char pi = 'Π'; // 0x3a0
+ let yen: char = '¥'; // 0xa5
+ let c_cedilla: char = 'ç'; // 0xe7
+ let thorn: char = 'þ'; // 0xfe
+ let y_diaeresis: char = 'ÿ'; // 0xff
+ let pi: char = 'Π'; // 0x3a0
- assert ((yen as int) == 0xa5);
- assert ((c_cedilla as int) == 0xe7);
- assert ((thorn as int) == 0xfe);
- assert ((y_diaeresis as int) == 0xff);
- assert ((pi as int) == 0x3a0);
+ assert (yen as int == 0xa5);
+ assert (c_cedilla as int == 0xe7);
+ assert (thorn as int == 0xfe);
+ assert (y_diaeresis as int == 0xff);
+ assert (pi as int == 0x3a0);
- assert ((pi as int) == ('\u03a0' as int));
- assert (('\x0a' as int) == ('\n' as int));
+ assert (pi as int == '\u03a0' as int);
+ assert ('\x0a' as int == '\n' as int);
- let str bhutan = "འབྲུག་ཡུལ།";
- let str japan = "日本";
- let str uzbekistan = "Ўзбекистон";
- let str austria = "Österreich";
+ let bhutan: str = "འབྲུག་ཡུལ།";
+ let japan: str = "日本";
+ let uzbekistan: str = "Ўзбекистон";
+ let austria: str = "Österreich";
- let str bhutan_e =
- "\u0f60\u0f56\u0fb2\u0f74\u0f42\u0f0b\u0f61\u0f74\u0f63\u0f0d";
- let str japan_e = "\u65e5\u672c";
- let str uzbekistan_e =
- "\u040e\u0437\u0431\u0435\u043a\u0438\u0441\u0442\u043e\u043d";
- let str austria_e = "\u00d6sterreich";
+ let bhutan_e: str =
+ "\u0f60\u0f56\u0fb2\u0f74\u0f42\u0f0b\u0f61\u0f74\u0f63\u0f0d";
+ let japan_e: str = "\u65e5\u672c";
+ let uzbekistan_e: str =
+ "\u040e\u0437\u0431\u0435\u043a\u0438\u0441\u0442\u043e\u043d";
+ let austria_e: str = "\u00d6sterreich";
- let char oo = 'Ö';
- assert ((oo as int) == 0xd6);
+ let oo: char = 'Ö';
+ assert (oo as int == 0xd6);
- fn check_str_eq(str a, str b) {
- let int i = 0;
- for (u8 ab in a) {
- log i;
- log ab;
- let u8 bb = b.(i);
- log bb;
- assert (ab == bb);
- i += 1;
+ fn check_str_eq(a: str, b: str) {
+ let i: int = 0;
+ for ab: u8 in a {
+ log i;
+ log ab;
+ let bb: u8 = b.(i);
+ log bb;
+ assert (ab == bb);
+ i += 1;
+ }
}
- }
- check_str_eq(bhutan, bhutan_e);
- check_str_eq(japan, japan_e);
- check_str_eq(uzbekistan, uzbekistan_e);
- check_str_eq(austria, austria_e);
-}
+ check_str_eq(bhutan, bhutan_e);
+ check_str_eq(japan, japan_e);
+ check_str_eq(uzbekistan, uzbekistan_e);
+ check_str_eq(austria, austria_e);
+}
\ No newline at end of file
diff --git a/src/test/run-pass/utf8_chars.rs b/src/test/run-pass/utf8_chars.rs
index f7c4098..6c9a696 100644
--- a/src/test/run-pass/utf8_chars.rs
+++ b/src/test/run-pass/utf8_chars.rs
@@ -6,29 +6,29 @@
import std::io;
fn main() {
- // Chars of 1, 2, 3, and 4 bytes
- let vec[char] chs = ['e', 'é', '€', 0x10000 as char];
- let str s = str::from_chars(chs);
+ // Chars of 1, 2, 3, and 4 bytes
+ let chs: vec[char] = ['e', 'é', '€', 0x10000 as char];
+ let s: str = str::from_chars(chs);
- assert (str::byte_len(s) == 10u);
- assert (str::char_len(s) == 4u);
- assert (vec::len[char](str::to_chars(s)) == 4u);
- assert (str::eq(str::from_chars(str::to_chars(s)), s));
- assert (str::char_at(s, 0u) == 'e');
- assert (str::char_at(s, 1u) == 'é');
+ assert (str::byte_len(s) == 10u);
+ assert (str::char_len(s) == 4u);
+ assert (vec::len[char](str::to_chars(s)) == 4u);
+ assert (str::eq(str::from_chars(str::to_chars(s)), s));
+ assert (str::char_at(s, 0u) == 'e');
+ assert (str::char_at(s, 1u) == 'é');
- assert (str::is_utf8(str::bytes(s)));
- assert (!str::is_utf8([0x80_u8]));
- assert (!str::is_utf8([0xc0_u8]));
- assert (!str::is_utf8([0xc0_u8, 0x10_u8]));
+ assert (str::is_utf8(str::bytes(s)));
+ assert (!str::is_utf8([0x80_u8]));
+ assert (!str::is_utf8([0xc0_u8]));
+ assert (!str::is_utf8([0xc0_u8, 0x10_u8]));
- auto stack = "a×c€";
- assert (str::pop_char(stack) == '€');
- assert (str::pop_char(stack) == 'c');
- str::push_char(stack, 'u');
- assert (str::eq(stack, "a×u"));
- assert (str::shift_char(stack) == 'a');
- assert (str::shift_char(stack) == '×');
- str::unshift_char(stack, 'ß');
- assert (str::eq(stack, "ßu"));
-}
+ let stack = "a×c€";
+ assert (str::pop_char(stack) == '€');
+ assert (str::pop_char(stack) == 'c');
+ str::push_char(stack, 'u');
+ assert (str::eq(stack, "a×u"));
+ assert (str::shift_char(stack) == 'a');
+ assert (str::shift_char(stack) == '×');
+ str::unshift_char(stack, 'ß');
+ assert (str::eq(stack, "ßu"));
+}
\ No newline at end of file
diff --git a/src/test/run-pass/vec-alloc-append.rs b/src/test/run-pass/vec-alloc-append.rs
index f41436e..472fe21 100644
--- a/src/test/run-pass/vec-alloc-append.rs
+++ b/src/test/run-pass/vec-alloc-append.rs
@@ -3,8 +3,8 @@
// This is a test for issue #109.
use std;
-fn slice[T](vec[T] e) {
- let vec[T] result = std::vec::alloc[T](1 as uint);
+fn slice[T](e: vec[T]) {
+ let result: vec[T] = std::vec::alloc[T](1 as uint);
log "alloced";
result += e;
log "appended";
diff --git a/src/test/run-pass/vec-append.rs b/src/test/run-pass/vec-append.rs
index 7df688d..6753580 100644
--- a/src/test/run-pass/vec-append.rs
+++ b/src/test/run-pass/vec-append.rs
@@ -8,10 +8,10 @@
// FIXME: import std::dbg::const_refcount. Currently
// cross-crate const references don't work.
-const uint const_refcount = 0x7bad_face_u;
+const const_refcount: uint = 0x7bad_face_u;
fn fast_growth() {
- let vec[int] v = [1, 2, 3, 4, 5];
+ let v: vec[int] = [1, 2, 3, 4, 5];
v += [6, 7, 8, 9, 0];
log v.(9);
assert (v.(0) == 1);
@@ -20,21 +20,21 @@
}
fn slow_growth() {
- let vec[int] v = [];
- let vec[int] u = v;
+ let v: vec[int] = [];
+ let u: vec[int] = v;
v += [17];
log v.(0);
assert (v.(0) == 17);
}
-fn slow_growth2_helper(str s) { // ref up: s
+fn slow_growth2_helper(s: str) { // ref up: s
- obj acc(mutable vec[str] v) {
- fn add(&str s) { v += [s]; }
+ obj acc(mutable v: vec[str]) {
+ fn add(s: &str) { v += [s]; }
}
- let str ss = s; // ref up: s
+ let ss: str = s; // ref up: s
- let str mumble = "mrghrm"; // ref up: mumble
+ let mumble: str = "mrghrm"; // ref up: mumble
{
/**
@@ -47,10 +47,10 @@
* mumble, the existing str in the originally- shared vec.
*/
- let vec[str] v = [mumble]; // ref up: v, mumble
+ let v: vec[str] = [mumble]; // ref up: v, mumble
log vec::refcount[str](v);
- let acc a = acc(v); // ref up: a, v
+ let a: acc = acc(v); // ref up: a, v
log vec::refcount[str](v);
assert (vec::refcount[str](v) == 2u);
@@ -76,9 +76,9 @@
log ss;
}
- // ref down
+// ref down
fn slow_growth2() {
- let str s = "hi"; // ref up: s
+ let s: str = "hi"; // ref up: s
slow_growth2_helper(s);
log str::refcount(s);
diff --git a/src/test/run-pass/vec-concat.rs b/src/test/run-pass/vec-concat.rs
index 396e06e..e544bec 100644
--- a/src/test/run-pass/vec-concat.rs
+++ b/src/test/run-pass/vec-concat.rs
@@ -3,9 +3,9 @@
// -*- rust -*-
fn main() {
- let vec[int] a = [1, 2, 3, 4, 5];
- let vec[int] b = [6, 7, 8, 9, 0];
- let vec[int] v = a + b;
+ let a: vec[int] = [1, 2, 3, 4, 5];
+ let b: vec[int] = [6, 7, 8, 9, 0];
+ let v: vec[int] = a + b;
log v.(9);
assert (v.(0) == 1);
assert (v.(7) == 8);
diff --git a/src/test/run-pass/vec-drop.rs b/src/test/run-pass/vec-drop.rs
index e410b08..ed24d9c 100644
--- a/src/test/run-pass/vec-drop.rs
+++ b/src/test/run-pass/vec-drop.rs
@@ -3,7 +3,6 @@
fn main() {
// This just tests whether the vec leaks its members.
- let vec[@rec(int x, int y)] pvec = [@rec(x=1, y=2),
- @rec(x=3, y=4),
- @rec(x=5, y=6)];
+ let pvec: vec[@{x: int, y: int}] =
+ [@{x: 1, y: 2}, @{x: 3, y: 4}, @{x: 5, y: 6}];
}
\ No newline at end of file
diff --git a/src/test/run-pass/vec-growth.rs b/src/test/run-pass/vec-growth.rs
index 92b75a7..987163a 100644
--- a/src/test/run-pass/vec-growth.rs
+++ b/src/test/run-pass/vec-growth.rs
@@ -1,7 +1,7 @@
fn main() {
- auto v = [1];
+ let v = [1];
v += [2];
v += [3];
v += [4];
diff --git a/src/test/run-pass/vec-ivec-deadlock.rs b/src/test/run-pass/vec-ivec-deadlock.rs
index fe09525..eb9c558 100644
--- a/src/test/run-pass/vec-ivec-deadlock.rs
+++ b/src/test/run-pass/vec-ivec-deadlock.rs
@@ -1,7 +1,3 @@
// xfail-stage0
-fn main() {
- auto a = ~[ 1, 2, 3, 4, 5 ];
- auto b = [ a, a ];
- b += b;
-}
+fn main() { let a = ~[1, 2, 3, 4, 5]; let b = [a, a]; b += b; }
\ No newline at end of file
diff --git a/src/test/run-pass/vec-late-init.rs b/src/test/run-pass/vec-late-init.rs
index 4e5bba5..029e2c1 100644
--- a/src/test/run-pass/vec-late-init.rs
+++ b/src/test/run-pass/vec-late-init.rs
@@ -1,7 +1,7 @@
fn main() {
- let vec[int] later;
- if (true) { later = [1]; } else { later = [2]; }
+ let later: vec[int];
+ if true { later = [1]; } else { later = [2]; }
log later.(0);
}
\ No newline at end of file
diff --git a/src/test/run-pass/vec-push.rs b/src/test/run-pass/vec-push.rs
index e512b5a..6dcbe35 100644
--- a/src/test/run-pass/vec-push.rs
+++ b/src/test/run-pass/vec-push.rs
@@ -1,5 +1,5 @@
-fn push[T](&mutable vec[mutable? T] v, &T t) { v += [t]; }
+fn push[T](v: &mutable vec[mutable? T], t: &T) { v += [t]; }
-fn main() { auto v = [1, 2, 3]; push(v, 1); }
\ No newline at end of file
+fn main() { let v = [1, 2, 3]; push(v, 1); }
\ No newline at end of file
diff --git a/src/test/run-pass/vec-ref-count.rs b/src/test/run-pass/vec-ref-count.rs
index a43043b..9452f7f 100644
--- a/src/test/run-pass/vec-ref-count.rs
+++ b/src/test/run-pass/vec-ref-count.rs
@@ -3,7 +3,7 @@
import std::vec;
fn main() {
- auto v = [1, 2, 3];
+ let v = [1, 2, 3];
log_err vec::refcount[int](v);
log_err vec::refcount[int](v);
log_err vec::refcount[int](v);
diff --git a/src/test/run-pass/vec-reverse.rs b/src/test/run-pass/vec-reverse.rs
index fd13d74..64d75b6 100644
--- a/src/test/run-pass/vec-reverse.rs
+++ b/src/test/run-pass/vec-reverse.rs
@@ -3,20 +3,20 @@
import std::vec;
fn main() {
- let vec[mutable int] v = [mutable 10, 20];
+ let v: vec[mutable int] = [mutable 10, 20];
assert (v.(0) == 10);
assert (v.(1) == 20);
vec::reverse(v);
assert (v.(0) == 20);
assert (v.(1) == 10);
- auto v2 = vec::reversed[int]([10, 20]);
+ let v2 = vec::reversed[int]([10, 20]);
assert (v2.(0) == 20);
assert (v2.(1) == 10);
v.(0) = 30;
assert (v2.(0) == 20);
// Make sure they work with 0-length vectors too.
- auto v4 = vec::reversed[int]([]);
- let vec[mutable int] v3 = vec::empty_mut();
+ let v4 = vec::reversed[int]([]);
+ let v3: vec[mutable int] = vec::empty_mut();
vec::reverse[int](v3);
}
\ No newline at end of file
diff --git a/src/test/run-pass/vec-self-append.rs b/src/test/run-pass/vec-self-append.rs
index 7cafdf9..dd37f8a 100644
--- a/src/test/run-pass/vec-self-append.rs
+++ b/src/test/run-pass/vec-self-append.rs
@@ -3,17 +3,16 @@
use std;
import std::vec;
-fn main()
-{
+fn main() {
// Make sure we properly handle repeated self-appends.
- let vec[int] a = [0];
- auto i = 20;
- auto expected_len = 1u;
- while (i > 0) {
+ let a: vec[int] = [0];
+ let i = 20;
+ let expected_len = 1u;
+ while i > 0 {
log_err vec::len(a);
assert (vec::len(a) == expected_len);
a += a;
i -= 1;
expected_len *= 2u;
}
-}
+}
\ No newline at end of file
diff --git a/src/test/run-pass/vec-slice.rs b/src/test/run-pass/vec-slice.rs
index 9434eed..5c572a0 100644
--- a/src/test/run-pass/vec-slice.rs
+++ b/src/test/run-pass/vec-slice.rs
@@ -1,10 +1,6 @@
-// xfail-stage0
-// xfail-stage1
-// xfail-stage2
-// xfail-stage3
-fn main() {
- let vec[int] v = [1,2,3,4,5];
- auto v2 = v.(1,2);
- assert (v2.(0) == 2);
- assert (v2.(1) == 3);
-}
\ No newline at end of file
+./src/test/run-pass/vec-slice.rs:7:16:7:17: [1;31merror:[0m expecting ), found ,
+./src/test/run-pass/vec-slice.rs:7 auto v2 = v.(1,2);
+ ^
+rt: ---
+rt: f00e:main:main: upcall fail 'explicit failure', src/comp/syntax/parse/parser.rs:112
+rt: f00e:main: domain main @0xa73404c root task failed
diff --git a/src/test/run-pass/vec.rs b/src/test/run-pass/vec.rs
index 9bc69bc..f4ad4e4 100644
--- a/src/test/run-pass/vec.rs
+++ b/src/test/run-pass/vec.rs
@@ -3,10 +3,10 @@
// -*- rust -*-
fn main() {
- let vec[int] v = [10, 20];
+ let v: vec[int] = [10, 20];
assert (v.(0) == 10);
assert (v.(1) == 20);
- let int x = 0;
+ let x: int = 0;
assert (v.(x) == 10);
assert (v.(x + 1) == 20);
x = x + 1;
diff --git a/src/test/run-pass/vector-no-ann-2.rs b/src/test/run-pass/vector-no-ann-2.rs
index fc09f88..ecdb443 100644
--- a/src/test/run-pass/vector-no-ann-2.rs
+++ b/src/test/run-pass/vector-no-ann-2.rs
@@ -2,4 +2,4 @@
// xfail-stage0
-fn main() { let @vec[uint] quux = @[]; }
\ No newline at end of file
+fn main() { let quux: @vec[uint] = @[]; }
\ No newline at end of file
diff --git a/src/test/run-pass/while-and-do-while.rs b/src/test/run-pass/while-and-do-while.rs
index 8c02c97..3287791 100644
--- a/src/test/run-pass/while-and-do-while.rs
+++ b/src/test/run-pass/while-and-do-while.rs
@@ -1,8 +1,8 @@
fn main() {
- let int x = 10;
- let int y = 0;
- while (y < x) { log y; log "hello"; y = y + 1; }
- do { log "goodbye"; x = x - 1; log x; } while (x > 0)
+ let x: int = 10;
+ let y: int = 0;
+ while y < x { log y; log "hello"; y = y + 1; }
+ do { log "goodbye"; x = x - 1; log x; } while x > 0
}
\ No newline at end of file
diff --git a/src/test/run-pass/while-flow-graph.rs b/src/test/run-pass/while-flow-graph.rs
index 51c2a94..bf18406 100644
--- a/src/test/run-pass/while-flow-graph.rs
+++ b/src/test/run-pass/while-flow-graph.rs
@@ -1,3 +1,3 @@
-fn main() { let int x = 10; while (x == 10 && x == 11) { auto y = 0xf00; } }
\ No newline at end of file
+fn main() { let x: int = 10; while x == 10 && x == 11 { let y = 0xf00; } }
\ No newline at end of file
diff --git a/src/test/run-pass/while-loop-constraints-2.rs b/src/test/run-pass/while-loop-constraints-2.rs
index d39fa1a..e90189d 100644
--- a/src/test/run-pass/while-loop-constraints-2.rs
+++ b/src/test/run-pass/while-loop-constraints-2.rs
@@ -1,16 +1,9 @@
// xfail-stage0
fn main() {
- let int y = 42;
- let int z = 42;
- let int x;
- while (z < 50) {
- z += 1;
- while (false) {
- x <- y;
- y = z;
- }
- log y;
- }
- assert (y == 42 && z == 50);
+ let y: int = 42;
+ let z: int = 42;
+ let x: int;
+ while z < 50 { z += 1; while false { x <- y; y = z; } log y; }
+ assert (y == 42 && z == 50);
}
\ No newline at end of file
diff --git a/src/test/run-pass/while-prelude-drop.rs b/src/test/run-pass/while-prelude-drop.rs
index 4301179..59db1c6 100644
--- a/src/test/run-pass/while-prelude-drop.rs
+++ b/src/test/run-pass/while-prelude-drop.rs
@@ -2,9 +2,9 @@
tag t { a; b(str); }
-fn make(int i) -> t {
- if (i > 10) { ret a; }
- auto s = "hello";
+fn make(i: int) -> t {
+ if i > 10 { ret a; }
+ let s = "hello";
// Ensure s is non-const.
s += "there";
@@ -12,8 +12,9 @@
}
fn main() {
- auto i = 0;
+ let i = 0;
+
// The auto slot for the result of make(i) should not leak.
- while (make(i) != a) { i += 1; }
+ while make(i) != a { i += 1; }
}
\ No newline at end of file
diff --git a/src/test/run-pass/while-with-break.rs b/src/test/run-pass/while-with-break.rs
index a906d50..b9fb06c 100644
--- a/src/test/run-pass/while-with-break.rs
+++ b/src/test/run-pass/while-with-break.rs
@@ -3,12 +3,12 @@
// -*- rust -*-
fn main() {
- let int i = 90;
- while (i < 100) {
+ let i: int = 90;
+ while i < 100 {
log i;
i = i + 1;
- if (i == 95) {
- let vec[int] v =
+ if i == 95 {
+ let v: vec[int] =
[1, 2, 3, 4, 5]; // we check that it is freed by break
log "breaking";
diff --git a/src/test/run-pass/writealias.rs b/src/test/run-pass/writealias.rs
index 1cccb3d..0f77947 100644
--- a/src/test/run-pass/writealias.rs
+++ b/src/test/run-pass/writealias.rs
@@ -2,12 +2,12 @@
// -*- rust -*-
-type point = rec(int x, int y, mutable int z);
+type point = {x: int, y: int, mutable z: int};
-fn f(&mutable point p) { p.z = 13; }
+fn f(p: &mutable point) { p.z = 13; }
fn main() {
- let point x = rec(x=10, y=11, mutable z=12);
+ let x: point = {x: 10, y: 11, mutable z: 12};
f(x);
assert (x.z == 13);
}
\ No newline at end of file
diff --git a/src/test/run-pass/x86stdcall.rs b/src/test/run-pass/x86stdcall.rs
index e7af50e..0351383 100644
--- a/src/test/run-pass/x86stdcall.rs
+++ b/src/test/run-pass/x86stdcall.rs
@@ -2,19 +2,18 @@
#[cfg(target_os = "win32")]
native "x86stdcall" mod kernel32 {
- fn SetLastError(uint err);
- fn GetLastError() -> uint;
+ fn SetLastError(err: uint);
+ fn GetLastError() -> uint;
}
#[cfg(target_os = "win32")]
fn main() {
- auto expected = 10u;
- kernel32::SetLastError(expected);
- auto actual = kernel32::GetLastError();
- assert expected == actual;
+ let expected = 10u;
+ kernel32::SetLastError(expected);
+ let actual = kernel32::GetLastError();
+ assert (expected == actual);
}
#[cfg(target_os = "macos")]
#[cfg(target_os = "linux")]
-fn main() {
-}
\ No newline at end of file
+fn main() { }
\ No newline at end of file
diff --git a/src/test/run-pass/yield.rs b/src/test/run-pass/yield.rs
index d0577da..02bc629 100644
--- a/src/test/run-pass/yield.rs
+++ b/src/test/run-pass/yield.rs
@@ -6,7 +6,7 @@
import std::task::*;
fn main() {
- auto other = spawn child();
+ let other = spawn child();
log_err "1";
yield();
log_err "2";
diff --git a/src/test/run-pass/yield1.rs b/src/test/run-pass/yield1.rs
index 1683d9d..c430810 100644
--- a/src/test/run-pass/yield1.rs
+++ b/src/test/run-pass/yield1.rs
@@ -5,6 +5,6 @@
use std;
import std::task::*;
-fn main() { auto other = spawn child(); log_err "1"; yield(); join(other); }
+fn main() { let other = spawn child(); log_err "1"; yield(); join(other); }
fn child() { log_err "2"; }
\ No newline at end of file
diff --git a/src/test/run-pass/yield2.rs b/src/test/run-pass/yield2.rs
index 575b91c..d19a1e7 100644
--- a/src/test/run-pass/yield2.rs
+++ b/src/test/run-pass/yield2.rs
@@ -5,6 +5,6 @@
use std;
fn main() {
- let int i = 0;
- while (i < 100) { i = i + 1; log_err i; std::task::yield(); }
+ let i: int = 0;
+ while i < 100 { i = i + 1; log_err i; std::task::yield(); }
}
\ No newline at end of file
diff --git a/src/test/stdtest/bitv.rs b/src/test/stdtest/bitv.rs
index a550136..2cf8a79 100644
--- a/src/test/stdtest/bitv.rs
+++ b/src/test/stdtest/bitv.rs
@@ -5,8 +5,8 @@
#[test]
fn test_0_elements() {
- auto act;
- auto exp;
+ let act;
+ let exp;
act = bitv::create(0u, false);
exp = vec::init_elt[uint](0u, 0u);
// FIXME: why can't I write vec[uint]()?
@@ -16,7 +16,7 @@
#[test]
fn test_1_element() {
- auto act;
+ let act;
act = bitv::create(1u, false);
assert (bitv::eq_vec(act, [0u]));
act = bitv::create(1u, true);
@@ -25,7 +25,7 @@
#[test]
fn test_10_elements() {
- auto act;
+ let act;
// all 0
act = bitv::create(10u, false);
@@ -64,7 +64,7 @@
#[test]
fn test_31_elements() {
- auto act;
+ let act;
// all 0
act = bitv::create(31u, false);
@@ -137,7 +137,7 @@
#[test]
fn test_32_elements() {
- auto act;
+ let act;
// all 0
act = bitv::create(32u, false);
@@ -212,7 +212,7 @@
#[test]
fn test_33_elements() {
- auto act;
+ let act;
// all 0
act = bitv::create(33u, false);
diff --git a/src/test/stdtest/box.rs b/src/test/stdtest/box.rs
index 6b2d199..6212ec6 100644
--- a/src/test/stdtest/box.rs
+++ b/src/test/stdtest/box.rs
@@ -4,8 +4,8 @@
#[test]
fn test() {
- auto x = @3;
- auto y = @3;
+ let x = @3;
+ let y = @3;
assert (box::ptr_eq[int](x, x));
assert (box::ptr_eq[int](y, y));
assert (!box::ptr_eq[int](x, y));
diff --git a/src/test/stdtest/deque.rs b/src/test/stdtest/deque.rs
index 0a66ab3..d43d4b7 100644
--- a/src/test/stdtest/deque.rs
+++ b/src/test/stdtest/deque.rs
@@ -6,7 +6,7 @@
#[test]
fn test_simple() {
- let deque::t[int] d = deque::create[int]();
+ let d: deque::t[int] = deque::create[int]();
assert (d.size() == 0u);
d.add_front(17);
d.add_front(42);
@@ -18,7 +18,7 @@
assert (d.peek_front() == 42);
log d.peek_back();
assert (d.peek_back() == 137);
- let int i = d.pop_front();
+ let i: int = d.pop_front();
log i;
assert (i == 42);
i = d.pop_back();
@@ -49,8 +49,8 @@
assert (d.get(3) == 4);
}
-fn test_boxes(@int a, @int b, @int c, @int d) {
- let deque::t[@int] deq = deque::create[@int]();
+fn test_boxes(a: @int, b: @int, c: @int, d: @int) {
+ let deq: deque::t[@int] = deque::create[@int]();
assert (deq.size() == 0u);
deq.add_front(a);
deq.add_front(b);
@@ -81,8 +81,8 @@
type eqfn[T] = fn(&T, &T) -> bool ;
-fn test_parameterized[T](eqfn[T] e, &T a, &T b, &T c, &T d) {
- let deque::t[T] deq = deque::create[T]();
+fn test_parameterized[T](e: eqfn[T], a: &T, b: &T, c: &T, d: &T) {
+ let deq: deque::t[T] = deque::create[T]();
assert (deq.size() == 0u);
deq.add_front(a);
deq.add_front(b);
@@ -115,80 +115,70 @@
tag taggypar[T] { onepar(int); twopar(int, int); threepar(int, int, int); }
-type reccy = rec(int x, int y, taggy t);
+type reccy = {x: int, y: int, t: taggy};
#[test]
fn test() {
- fn inteq(&int a, &int b) -> bool { ret a == b; }
- fn intboxeq(&@int a, &@int b) -> bool { ret a == b; }
- fn taggyeq(&taggy a, &taggy b) -> bool {
- alt (a) {
- case (one(?a1)) {
- alt (b) {
- case (one(?b1)) { ret a1 == b1; }
- case (_) { ret false; }
- }
+ fn inteq(a: &int, b: &int) -> bool { ret a == b; }
+ fn intboxeq(a: &@int, b: &@int) -> bool { ret a == b; }
+ fn taggyeq(a: &taggy, b: &taggy) -> bool {
+ alt a {
+ one(a1) { alt b { one(b1) { ret a1 == b1; } _ { ret false; } } }
+ two(a1, a2) {
+ alt b {
+ two(b1, b2) { ret a1 == b1 && a2 == b2; }
+ _ { ret false; }
}
- case (two(?a1, ?a2)) {
- alt (b) {
- case (two(?b1, ?b2)) { ret a1 == b1 && a2 == b2; }
- case (_) { ret false; }
- }
+ }
+ three(a1, a2, a3) {
+ alt b {
+ three(b1, b2, b3) { ret a1 == b1 && a2 == b2 && a3 == b3; }
+ _ { ret false; }
}
- case (three(?a1, ?a2, ?a3)) {
- alt (b) {
- case (three(?b1, ?b2, ?b3)) {
- ret a1 == b1 && a2 == b2 && a3 == b3;
- }
- case (_) { ret false; }
- }
- }
+ }
}
}
- fn taggypareq[T](&taggypar[T] a, &taggypar[T] b) -> bool {
- alt (a) {
- case (onepar[T](?a1)) {
- alt (b) {
- case (onepar[T](?b1)) { ret a1 == b1; }
- case (_) { ret false; }
- }
+ fn taggypareq[T](a: &taggypar[T], b: &taggypar[T]) -> bool {
+ alt a {
+ onepar[T](a1) {
+ alt b { onepar[T](b1) { ret a1 == b1; } _ { ret false; } }
+ }
+ twopar[T](a1, a2) {
+ alt b {
+ twopar[T](b1, b2) { ret a1 == b1 && a2 == b2; }
+ _ { ret false; }
}
- case (twopar[T](?a1, ?a2)) {
- alt (b) {
- case (twopar[T](?b1, ?b2)) { ret a1 == b1 && a2 == b2; }
- case (_) { ret false; }
- }
+ }
+ threepar[T](a1, a2, a3) {
+ alt b {
+ threepar[T](b1, b2, b3) {
+ ret a1 == b1 && a2 == b2 && a3 == b3;
+ }
+ _ { ret false; }
}
- case (threepar[T](?a1, ?a2, ?a3)) {
- alt (b) {
- case (threepar[T](?b1, ?b2, ?b3)) {
- ret a1 == b1 && a2 == b2 && a3 == b3;
- }
- case (_) { ret false; }
- }
- }
+ }
}
}
- fn reccyeq(&reccy a, &reccy b) -> bool {
+ fn reccyeq(a: &reccy, b: &reccy) -> bool {
ret a.x == b.x && a.y == b.y && taggyeq(a.t, b.t);
}
log "*** test boxes";
test_boxes(@5, @72, @64, @175);
log "*** end test boxes";
log "test parameterized: int";
- let eqfn[int] eq1 = inteq;
+ let eq1: eqfn[int] = inteq;
test_parameterized[int](eq1, 5, 72, 64, 175);
log "*** test parameterized: @int";
- let eqfn[@int] eq2 = intboxeq;
+ let eq2: eqfn[@int] = intboxeq;
test_parameterized[@int](eq2, @5, @72, @64, @175);
log "*** end test parameterized @int";
log "test parameterized: taggy";
- let eqfn[taggy] eq3 = taggyeq;
+ let eq3: eqfn[taggy] = taggyeq;
test_parameterized[taggy](eq3, one(1), two(1, 2), three(1, 2, 3),
two(17, 42));
/*
* FIXME: Segfault. Also appears to be caused only after upcall_grow_task
-
+
log "*** test parameterized: taggypar[int]";
let eqfn[taggypar[int]] eq4 = taggypareq[int];
test_parameterized[taggypar[int]](eq4,
@@ -197,15 +187,15 @@
threepar[int](1, 2, 3),
twopar[int](17, 42));
log "*** end test parameterized: taggypar[int]";
-
+
*/
log "*** test parameterized: reccy";
- let reccy reccy1 = rec(x=1, y=2, t=one(1));
- let reccy reccy2 = rec(x=345, y=2, t=two(1, 2));
- let reccy reccy3 = rec(x=1, y=777, t=three(1, 2, 3));
- let reccy reccy4 = rec(x=19, y=252, t=two(17, 42));
- let eqfn[reccy] eq5 = reccyeq;
+ let reccy1: reccy = {x: 1, y: 2, t: one(1)};
+ let reccy2: reccy = {x: 345, y: 2, t: two(1, 2)};
+ let reccy3: reccy = {x: 1, y: 777, t: three(1, 2, 3)};
+ let reccy4: reccy = {x: 19, y: 252, t: two(17, 42)};
+ let eq5: eqfn[reccy] = reccyeq;
test_parameterized[reccy](eq5, reccy1, reccy2, reccy3, reccy4);
log "*** end test parameterized: reccy";
log "*** done";
diff --git a/src/test/stdtest/either.rs b/src/test/stdtest/either.rs
index 3096bd1..97ed9ef1 100644
--- a/src/test/stdtest/either.rs
+++ b/src/test/stdtest/either.rs
@@ -4,109 +4,93 @@
#[test]
fn test_either_left() {
- auto val = left(10);
- fn f_left(&int x) -> bool { x == 10 }
- fn f_right(&uint x) -> bool { false }
- assert (either(f_left, f_right, val));
+ let val = left(10);
+ fn f_left(x: &int) -> bool { x == 10 }
+ fn f_right(x: &uint) -> bool { false }
+ assert (either(f_left, f_right, val));
}
#[test]
fn test_either_right() {
- auto val = right(10u);
- fn f_left(&int x) -> bool { false }
- fn f_right(&uint x) -> bool { x == 10u }
- assert (either(f_left, f_right, val));
+ let val = right(10u);
+ fn f_left(x: &int) -> bool { false }
+ fn f_right(x: &uint) -> bool { x == 10u }
+ assert (either(f_left, f_right, val));
}
#[test]
fn test_lefts() {
- auto input = ~[left(10),
- right(11),
- left(12),
- right(13),
- left(14)];
- auto result = lefts(input);
- assert (result == ~[10, 12, 14]);
+ let input = ~[left(10), right(11), left(12), right(13), left(14)];
+ let result = lefts(input);
+ assert (result == ~[10, 12, 14]);
}
#[test]
fn test_lefts_none() {
- let (t[int, int])[] input = ~[right(10),
- right(10)];
- auto result = lefts(input);
- assert (len(result) == 0u);
+ let input: (t[int, int])[] = ~[right(10), right(10)];
+ let result = lefts(input);
+ assert (len(result) == 0u);
}
#[test]
fn test_lefts_empty() {
- let (t[int, int])[] input = ~[];
- auto result = lefts(input);
- assert (len(result) == 0u);
+ let input: (t[int, int])[] = ~[];
+ let result = lefts(input);
+ assert (len(result) == 0u);
}
#[test]
fn test_rights() {
- auto input = ~[left(10),
- right(11),
- left(12),
- right(13),
- left(14)];
- auto result = rights(input);
- assert (result == ~[11, 13]);
+ let input = ~[left(10), right(11), left(12), right(13), left(14)];
+ let result = rights(input);
+ assert (result == ~[11, 13]);
}
#[test]
fn test_rights_none() {
- let (t[int, int])[] input = ~[left(10),
- left(10)];
- auto result = rights(input);
- assert (len(result) == 0u);
+ let input: (t[int, int])[] = ~[left(10), left(10)];
+ let result = rights(input);
+ assert (len(result) == 0u);
}
#[test]
fn test_rights_empty() {
- let (t[int, int])[] input = ~[];
- auto result = rights(input);
+ let input: (t[int, int])[] = ~[];
+ let result = rights(input);
assert (len(result) == 0u);
}
#[test]
fn test_partition() {
- auto input = ~[left(10),
- right(11),
- left(12),
- right(13),
- left(14)];
- auto result = partition(input);
- assert (result.lefts.(0) == 10);
- assert (result.lefts.(1) == 12);
- assert (result.lefts.(2) == 14);
- assert (result.rights.(0) == 11);
- assert (result.rights.(1) == 13);
+ let input = ~[left(10), right(11), left(12), right(13), left(14)];
+ let result = partition(input);
+ assert (result.lefts.(0) == 10);
+ assert (result.lefts.(1) == 12);
+ assert (result.lefts.(2) == 14);
+ assert (result.rights.(0) == 11);
+ assert (result.rights.(1) == 13);
}
#[test]
fn test_partition_no_lefts() {
- let (t[int, int])[] input = ~[right(10),
- right(11)];
- auto result = partition(input);
- assert (len(result.lefts) == 0u);
- assert (len(result.rights) == 2u);
+ let input: (t[int, int])[] = ~[right(10), right(11)];
+ let result = partition(input);
+ assert (len(result.lefts) == 0u);
+ assert (len(result.rights) == 2u);
}
#[test]
fn test_partition_no_rights() {
- let (t[int, int])[] input = ~[left(10),
- left(11)];
- auto result = partition(input);
- assert (len(result.lefts) == 2u);
- assert (len(result.rights) == 0u);
+ let input: (t[int, int])[] = ~[left(10), left(11)];
+ let result = partition(input);
+ assert (len(result.lefts) == 2u);
+ assert (len(result.rights) == 0u);
}
#[test]
fn test_partition_empty() {
- let (t[int, int])[] input = ~[];
- auto result = partition(input);
- assert (len(result.lefts) == 0u);
- assert (len(result.rights) == 0u);
-}
+ let input: (t[int, int])[] = ~[];
+ let result = partition(input);
+ assert (len(result.lefts) == 0u);
+ assert (len(result.rights) == 0u);
+}
\ No newline at end of file
diff --git a/src/test/stdtest/fs.rs b/src/test/stdtest/fs.rs
index 76321fb..7c33b37 100644
--- a/src/test/stdtest/fs.rs
+++ b/src/test/stdtest/fs.rs
@@ -4,7 +4,7 @@
#[test]
fn test_connect() {
- auto slash = fs::path_sep();
+ let slash = fs::path_sep();
log_err fs::connect("a", "b");
assert (fs::connect("a", "b") == "a" + slash + "b");
assert (fs::connect("a" + slash, "b") == "a" + slash + "b");
@@ -12,7 +12,5 @@
// Issue #712
#[test]
-fn test_list_dir_no_invalid_memory_access() {
- fs::list_dir(".");
-}
+fn test_list_dir_no_invalid_memory_access() { fs::list_dir("."); }
diff --git a/src/test/stdtest/getopts.rs b/src/test/stdtest/getopts.rs
index 233e3a5..7515c43 100644
--- a/src/test/stdtest/getopts.rs
+++ b/src/test/stdtest/getopts.rs
@@ -12,18 +12,14 @@
unexpected_argument;
}
-fn check_fail_type(opt::fail_ f, fail_type ft) {
- alt (f) {
- case (opt::argument_missing(_)) { assert (ft == argument_missing); }
- case (opt::unrecognized_option(_)) {
- assert (ft == unrecognized_option);
- }
- case (opt::option_missing(_)) { assert (ft == option_missing); }
- case (opt::option_duplicated(_)) { assert (ft == option_duplicated); }
- case (opt::unexpected_argument(_)) {
- assert (ft == unexpected_argument);
- }
- case (_) { fail; }
+fn check_fail_type(f: opt::fail_, ft: fail_type) {
+ alt f {
+ opt::argument_missing(_) { assert (ft == argument_missing); }
+ opt::unrecognized_option(_) { assert (ft == unrecognized_option); }
+ opt::option_missing(_) { assert (ft == option_missing); }
+ opt::option_duplicated(_) { assert (ft == option_duplicated); }
+ opt::unexpected_argument(_) { assert (ft == unexpected_argument); }
+ _ { fail; }
}
}
@@ -31,95 +27,95 @@
// Tests for reqopt
#[test]
fn test_reqopt_long() {
- auto args = ["--test=20"];
- auto opts = [opt::reqopt("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) {
- assert (opt::opt_present(m, "test"));
- assert (opt::opt_str(m, "test") == "20");
- }
- case (_) { fail; }
+ let args = ["--test=20"];
+ let opts = [opt::reqopt("test")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::success(m) {
+ assert (opt::opt_present(m, "test"));
+ assert (opt::opt_str(m, "test") == "20");
+ }
+ _ { fail; }
}
}
#[test]
fn test_reqopt_long_missing() {
- auto args = ["blah"];
- auto opts = [opt::reqopt("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, option_missing); }
- case (_) { fail; }
+ let args = ["blah"];
+ let opts = [opt::reqopt("test")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::failure(f) { check_fail_type(f, option_missing); }
+ _ { fail; }
}
}
#[test]
fn test_reqopt_long_no_arg() {
- auto args = ["--test"];
- auto opts = [opt::reqopt("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, argument_missing); }
- case (_) { fail; }
+ let args = ["--test"];
+ let opts = [opt::reqopt("test")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::failure(f) { check_fail_type(f, argument_missing); }
+ _ { fail; }
}
}
#[test]
fn test_reqopt_long_multi() {
- auto args = ["--test=20", "--test=30"];
- auto opts = [opt::reqopt("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, option_duplicated); }
- case (_) { fail; }
+ let args = ["--test=20", "--test=30"];
+ let opts = [opt::reqopt("test")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::failure(f) { check_fail_type(f, option_duplicated); }
+ _ { fail; }
}
}
#[test]
fn test_reqopt_short() {
- auto args = ["-t", "20"];
- auto opts = [opt::reqopt("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) {
- assert (opt::opt_present(m, "t"));
- assert (opt::opt_str(m, "t") == "20");
- }
- case (_) { fail; }
+ let args = ["-t", "20"];
+ let opts = [opt::reqopt("t")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::success(m) {
+ assert (opt::opt_present(m, "t"));
+ assert (opt::opt_str(m, "t") == "20");
+ }
+ _ { fail; }
}
}
#[test]
fn test_reqopt_short_missing() {
- auto args = ["blah"];
- auto opts = [opt::reqopt("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, option_missing); }
- case (_) { fail; }
+ let args = ["blah"];
+ let opts = [opt::reqopt("t")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::failure(f) { check_fail_type(f, option_missing); }
+ _ { fail; }
}
}
#[test]
fn test_reqopt_short_no_arg() {
- auto args = ["-t"];
- auto opts = [opt::reqopt("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, argument_missing); }
- case (_) { fail; }
+ let args = ["-t"];
+ let opts = [opt::reqopt("t")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::failure(f) { check_fail_type(f, argument_missing); }
+ _ { fail; }
}
}
#[test]
fn test_reqopt_short_multi() {
- auto args = ["-t", "20", "-t", "30"];
- auto opts = [opt::reqopt("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, option_duplicated); }
- case (_) { fail; }
+ let args = ["-t", "20", "-t", "30"];
+ let opts = [opt::reqopt("t")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::failure(f) { check_fail_type(f, option_duplicated); }
+ _ { fail; }
}
}
@@ -127,95 +123,95 @@
// Tests for optopt
#[test]
fn test_optopt_long() {
- auto args = ["--test=20"];
- auto opts = [opt::optopt("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) {
- assert (opt::opt_present(m, "test"));
- assert (opt::opt_str(m, "test") == "20");
- }
- case (_) { fail; }
+ let args = ["--test=20"];
+ let opts = [opt::optopt("test")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::success(m) {
+ assert (opt::opt_present(m, "test"));
+ assert (opt::opt_str(m, "test") == "20");
+ }
+ _ { fail; }
}
}
#[test]
fn test_optopt_long_missing() {
- auto args = ["blah"];
- auto opts = [opt::optopt("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) { assert (!opt::opt_present(m, "test")); }
- case (_) { fail; }
+ let args = ["blah"];
+ let opts = [opt::optopt("test")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::success(m) { assert (!opt::opt_present(m, "test")); }
+ _ { fail; }
}
}
#[test]
fn test_optopt_long_no_arg() {
- auto args = ["--test"];
- auto opts = [opt::optopt("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, argument_missing); }
- case (_) { fail; }
+ let args = ["--test"];
+ let opts = [opt::optopt("test")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::failure(f) { check_fail_type(f, argument_missing); }
+ _ { fail; }
}
}
#[test]
fn test_optopt_long_multi() {
- auto args = ["--test=20", "--test=30"];
- auto opts = [opt::optopt("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, option_duplicated); }
- case (_) { fail; }
+ let args = ["--test=20", "--test=30"];
+ let opts = [opt::optopt("test")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::failure(f) { check_fail_type(f, option_duplicated); }
+ _ { fail; }
}
}
#[test]
fn test_optopt_short() {
- auto args = ["-t", "20"];
- auto opts = [opt::optopt("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) {
- assert (opt::opt_present(m, "t"));
- assert (opt::opt_str(m, "t") == "20");
- }
- case (_) { fail; }
+ let args = ["-t", "20"];
+ let opts = [opt::optopt("t")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::success(m) {
+ assert (opt::opt_present(m, "t"));
+ assert (opt::opt_str(m, "t") == "20");
+ }
+ _ { fail; }
}
}
#[test]
fn test_optopt_short_missing() {
- auto args = ["blah"];
- auto opts = [opt::optopt("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) { assert (!opt::opt_present(m, "t")); }
- case (_) { fail; }
+ let args = ["blah"];
+ let opts = [opt::optopt("t")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::success(m) { assert (!opt::opt_present(m, "t")); }
+ _ { fail; }
}
}
#[test]
fn test_optopt_short_no_arg() {
- auto args = ["-t"];
- auto opts = [opt::optopt("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, argument_missing); }
- case (_) { fail; }
+ let args = ["-t"];
+ let opts = [opt::optopt("t")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::failure(f) { check_fail_type(f, argument_missing); }
+ _ { fail; }
}
}
#[test]
fn test_optopt_short_multi() {
- auto args = ["-t", "20", "-t", "30"];
- auto opts = [opt::optopt("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, option_duplicated); }
- case (_) { fail; }
+ let args = ["-t", "20", "-t", "30"];
+ let opts = [opt::optopt("t")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::failure(f) { check_fail_type(f, option_duplicated); }
+ _ { fail; }
}
}
@@ -223,96 +219,96 @@
// Tests for optflag
#[test]
fn test_optflag_long() {
- auto args = ["--test"];
- auto opts = [opt::optflag("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) { assert (opt::opt_present(m, "test")); }
- case (_) { fail; }
+ let args = ["--test"];
+ let opts = [opt::optflag("test")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::success(m) { assert (opt::opt_present(m, "test")); }
+ _ { fail; }
}
}
#[test]
fn test_optflag_long_missing() {
- auto args = ["blah"];
- auto opts = [opt::optflag("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) { assert (!opt::opt_present(m, "test")); }
- case (_) { fail; }
+ let args = ["blah"];
+ let opts = [opt::optflag("test")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::success(m) { assert (!opt::opt_present(m, "test")); }
+ _ { fail; }
}
}
#[test]
fn test_optflag_long_arg() {
- auto args = ["--test=20"];
- auto opts = [opt::optflag("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) {
- log_err opt::fail_str(f);
- check_fail_type(f, unexpected_argument);
- }
- case (_) { fail; }
+ let args = ["--test=20"];
+ let opts = [opt::optflag("test")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::failure(f) {
+ log_err opt::fail_str(f);
+ check_fail_type(f, unexpected_argument);
+ }
+ _ { fail; }
}
}
#[test]
fn test_optflag_long_multi() {
- auto args = ["--test", "--test"];
- auto opts = [opt::optflag("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, option_duplicated); }
- case (_) { fail; }
+ let args = ["--test", "--test"];
+ let opts = [opt::optflag("test")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::failure(f) { check_fail_type(f, option_duplicated); }
+ _ { fail; }
}
}
#[test]
fn test_optflag_short() {
- auto args = ["-t"];
- auto opts = [opt::optflag("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) { assert (opt::opt_present(m, "t")); }
- case (_) { fail; }
+ let args = ["-t"];
+ let opts = [opt::optflag("t")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::success(m) { assert (opt::opt_present(m, "t")); }
+ _ { fail; }
}
}
#[test]
fn test_optflag_short_missing() {
- auto args = ["blah"];
- auto opts = [opt::optflag("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) { assert (!opt::opt_present(m, "t")); }
- case (_) { fail; }
+ let args = ["blah"];
+ let opts = [opt::optflag("t")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::success(m) { assert (!opt::opt_present(m, "t")); }
+ _ { fail; }
}
}
#[test]
fn test_optflag_short_arg() {
- auto args = ["-t", "20"];
- auto opts = [opt::optflag("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) {
- // The next variable after the flag is just a free argument
+ let args = ["-t", "20"];
+ let opts = [opt::optflag("t")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::success(m) {
+ // The next variable after the flag is just a free argument
- assert (m.free.(0) == "20");
- }
- case (_) { fail; }
+ assert (m.free.(0) == "20");
+ }
+ _ { fail; }
}
}
#[test]
fn test_optflag_short_multi() {
- auto args = ["-t", "-t"];
- auto opts = [opt::optflag("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, option_duplicated); }
- case (_) { fail; }
+ let args = ["-t", "-t"];
+ let opts = [opt::optflag("t")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::failure(f) { check_fail_type(f, option_duplicated); }
+ _ { fail; }
}
}
@@ -320,153 +316,153 @@
// Tests for optmulti
#[test]
fn test_optmulti_long() {
- auto args = ["--test=20"];
- auto opts = [opt::optmulti("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) {
- assert (opt::opt_present(m, "test"));
- assert (opt::opt_str(m, "test") == "20");
- }
- case (_) { fail; }
+ let args = ["--test=20"];
+ let opts = [opt::optmulti("test")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::success(m) {
+ assert (opt::opt_present(m, "test"));
+ assert (opt::opt_str(m, "test") == "20");
+ }
+ _ { fail; }
}
}
#[test]
fn test_optmulti_long_missing() {
- auto args = ["blah"];
- auto opts = [opt::optmulti("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) { assert (!opt::opt_present(m, "test")); }
- case (_) { fail; }
+ let args = ["blah"];
+ let opts = [opt::optmulti("test")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::success(m) { assert (!opt::opt_present(m, "test")); }
+ _ { fail; }
}
}
#[test]
fn test_optmulti_long_no_arg() {
- auto args = ["--test"];
- auto opts = [opt::optmulti("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, argument_missing); }
- case (_) { fail; }
+ let args = ["--test"];
+ let opts = [opt::optmulti("test")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::failure(f) { check_fail_type(f, argument_missing); }
+ _ { fail; }
}
}
#[test]
fn test_optmulti_long_multi() {
- auto args = ["--test=20", "--test=30"];
- auto opts = [opt::optmulti("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) {
- assert (opt::opt_present(m, "test"));
- assert (opt::opt_str(m, "test") == "20");
- assert (opt::opt_strs(m, "test").(0) == "20");
- assert (opt::opt_strs(m, "test").(1) == "30");
- }
- case (_) { fail; }
+ let args = ["--test=20", "--test=30"];
+ let opts = [opt::optmulti("test")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::success(m) {
+ assert (opt::opt_present(m, "test"));
+ assert (opt::opt_str(m, "test") == "20");
+ assert (opt::opt_strs(m, "test").(0) == "20");
+ assert (opt::opt_strs(m, "test").(1) == "30");
+ }
+ _ { fail; }
}
}
#[test]
fn test_optmulti_short() {
- auto args = ["-t", "20"];
- auto opts = [opt::optmulti("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) {
- assert (opt::opt_present(m, "t"));
- assert (opt::opt_str(m, "t") == "20");
- }
- case (_) { fail; }
+ let args = ["-t", "20"];
+ let opts = [opt::optmulti("t")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::success(m) {
+ assert (opt::opt_present(m, "t"));
+ assert (opt::opt_str(m, "t") == "20");
+ }
+ _ { fail; }
}
}
#[test]
fn test_optmulti_short_missing() {
- auto args = ["blah"];
- auto opts = [opt::optmulti("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) { assert (!opt::opt_present(m, "t")); }
- case (_) { fail; }
+ let args = ["blah"];
+ let opts = [opt::optmulti("t")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::success(m) { assert (!opt::opt_present(m, "t")); }
+ _ { fail; }
}
}
#[test]
fn test_optmulti_short_no_arg() {
- auto args = ["-t"];
- auto opts = [opt::optmulti("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, argument_missing); }
- case (_) { fail; }
+ let args = ["-t"];
+ let opts = [opt::optmulti("t")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::failure(f) { check_fail_type(f, argument_missing); }
+ _ { fail; }
}
}
#[test]
fn test_optmulti_short_multi() {
- auto args = ["-t", "20", "-t", "30"];
- auto opts = [opt::optmulti("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) {
- assert (opt::opt_present(m, "t"));
- assert (opt::opt_str(m, "t") == "20");
- assert (opt::opt_strs(m, "t").(0) == "20");
- assert (opt::opt_strs(m, "t").(1) == "30");
- }
- case (_) { fail; }
+ let args = ["-t", "20", "-t", "30"];
+ let opts = [opt::optmulti("t")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::success(m) {
+ assert (opt::opt_present(m, "t"));
+ assert (opt::opt_str(m, "t") == "20");
+ assert (opt::opt_strs(m, "t").(0) == "20");
+ assert (opt::opt_strs(m, "t").(1) == "30");
+ }
+ _ { fail; }
}
}
#[test]
fn test_unrecognized_option_long() {
- auto args = ["--untest"];
- auto opts = [opt::optmulti("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, unrecognized_option); }
- case (_) { fail; }
+ let args = ["--untest"];
+ let opts = [opt::optmulti("t")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::failure(f) { check_fail_type(f, unrecognized_option); }
+ _ { fail; }
}
}
#[test]
fn test_unrecognized_option_short() {
- auto args = ["-t"];
- auto opts = [opt::optmulti("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, unrecognized_option); }
- case (_) { fail; }
+ let args = ["-t"];
+ let opts = [opt::optmulti("test")];
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::failure(f) { check_fail_type(f, unrecognized_option); }
+ _ { fail; }
}
}
#[test]
fn test_combined() {
- auto args =
+ let args =
["prog", "free1", "-s", "20", "free2", "--flag", "--long=30", "-f",
"-m", "40", "-m", "50"];
- auto opts =
+ let opts =
[opt::optopt("s"), opt::optflag("flag"), opt::reqopt("long"),
opt::optflag("f"), opt::optmulti("m"), opt::optopt("notpresent")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) {
- assert (m.free.(0) == "prog");
- assert (m.free.(1) == "free1");
- assert (opt::opt_str(m, "s") == "20");
- assert (m.free.(2) == "free2");
- assert (opt::opt_present(m, "flag"));
- assert (opt::opt_str(m, "long") == "30");
- assert (opt::opt_present(m, "f"));
- assert (opt::opt_strs(m, "m").(0) == "40");
- assert (opt::opt_strs(m, "m").(1) == "50");
- assert (!opt::opt_present(m, "notpresent"));
- }
- case (_) { fail; }
+ let rs = opt::getopts(args, opts);
+ alt rs {
+ opt::success(m) {
+ assert (m.free.(0) == "prog");
+ assert (m.free.(1) == "free1");
+ assert (opt::opt_str(m, "s") == "20");
+ assert (m.free.(2) == "free2");
+ assert (opt::opt_present(m, "flag"));
+ assert (opt::opt_str(m, "long") == "30");
+ assert (opt::opt_present(m, "f"));
+ assert (opt::opt_strs(m, "m").(0) == "40");
+ assert (opt::opt_strs(m, "m").(1) == "50");
+ assert (!opt::opt_present(m, "notpresent"));
+ }
+ _ { fail; }
}
}
diff --git a/src/test/stdtest/int.rs b/src/test/stdtest/int.rs
index 61d3448..936b1fa 100644
--- a/src/test/stdtest/int.rs
+++ b/src/test/stdtest/int.rs
@@ -22,4 +22,4 @@
assert (int::pow(-3, 2u) == 9);
assert (int::pow(-3, 3u) == -27);
assert (int::pow(4, 9u) == 262144);
-}
+}
\ No newline at end of file
diff --git a/src/test/stdtest/io.rs b/src/test/stdtest/io.rs
index 460d68b..08330c6 100644
--- a/src/test/stdtest/io.rs
+++ b/src/test/stdtest/io.rs
@@ -7,17 +7,17 @@
#[cfg(target_os = "win32")]
#[test]
fn test_simple() {
- let str tmpfile = "test/run-pass/lib-io-test-simple.tmp";
+ let tmpfile: str = "test/run-pass/lib-io-test-simple.tmp";
log tmpfile;
- let str frood = "A hoopy frood who really knows where his towel is.";
+ let frood: str = "A hoopy frood who really knows where his towel is.";
log frood;
{
- let io::writer out = io::file_writer(tmpfile, [io::create,
- io::truncate]);
+ let out: io::writer =
+ io::file_writer(tmpfile, [io::create, io::truncate]);
out.write_str(frood);
}
- let io::reader inp = io::file_reader(tmpfile);
- let str frood2 = inp.read_c_str();
+ let inp: io::reader = io::file_reader(tmpfile);
+ let frood2: str = inp.read_c_str();
log frood2;
assert (str::eq(frood, frood2));
}
@@ -26,5 +26,5 @@
#[cfg(target_os = "macos")]
#[test]
#[ignore]
-fn test_simple() {}
+fn test_simple() { }
diff --git a/src/test/stdtest/ivec.rs b/src/test/stdtest/ivec.rs
index 95e1271..ab486b4 100644
--- a/src/test/stdtest/ivec.rs
+++ b/src/test/stdtest/ivec.rs
@@ -5,21 +5,21 @@
import std::option::none;
import std::option::some;
-fn square(uint n) -> uint { ret n * n; }
+fn square(n: uint) -> uint { ret n * n; }
-fn square_alias(&uint n) -> uint { ret n * n; }
+fn square_alias(n: &uint) -> uint { ret n * n; }
-pred is_three(&uint n) -> bool { ret n == 3u; }
+pred is_three(n: &uint) -> bool { ret n == 3u; }
-fn square_if_odd(&uint n) -> option::t[uint] {
- ret if (n % 2u == 1u) { some(n * n) } else { none };
+fn square_if_odd(n: &uint) -> option::t[uint] {
+ ret if n % 2u == 1u { some(n * n) } else { none };
}
-fn add(&uint x, &uint y) -> uint { ret x + y; }
+fn add(x: &uint, y: &uint) -> uint { ret x + y; }
#[test]
fn test_reserve_and_on_heap() {
- let int[] v = ~[ 1, 2 ];
+ let v: int[] = ~[1, 2];
assert (!ivec::on_heap(v));
ivec::reserve(v, 8u);
assert (ivec::on_heap(v));
@@ -28,9 +28,9 @@
#[test]
fn test_unsafe_ptrs() {
// Test on-stack copy-from-buf.
- auto a = ~[ 1, 2, 3 ];
- auto ptr = ivec::to_ptr(a);
- auto b = ~[];
+ let a = ~[1, 2, 3];
+ let ptr = ivec::to_ptr(a);
+ let b = ~[];
ivec::unsafe::copy_from_buf(b, ptr, 3u);
assert (ivec::len(b) == 3u);
assert (b.(0) == 1);
@@ -38,9 +38,9 @@
assert (b.(2) == 3);
// Test on-heap copy-from-buf.
- auto c = ~[ 1, 2, 3, 4, 5 ];
+ let c = ~[1, 2, 3, 4, 5];
ptr = ivec::to_ptr(c);
- auto d = ~[];
+ let d = ~[];
ivec::unsafe::copy_from_buf(d, ptr, 5u);
assert (ivec::len(d) == 5u);
assert (d.(0) == 1);
@@ -53,7 +53,7 @@
#[test]
fn test_init_fn() {
// Test on-stack init_fn.
- auto v = ivec::init_fn(square, 3u);
+ let v = ivec::init_fn(square, 3u);
assert (ivec::len(v) == 3u);
assert (v.(0) == 0u);
assert (v.(1) == 1u);
@@ -72,7 +72,7 @@
#[test]
fn test_init_elt() {
// Test on-stack init_elt.
- auto v = ivec::init_elt(10u, 2u);
+ let v = ivec::init_elt(10u, 2u);
assert (ivec::len(v) == 2u);
assert (v.(0) == 10u);
assert (v.(1) == 10u);
@@ -89,61 +89,61 @@
#[test]
fn test_is_empty() {
- assert ivec::is_empty[int](~[]);
- assert !ivec::is_empty(~[0]);
+ assert (ivec::is_empty[int](~[]));
+ assert (!ivec::is_empty(~[0]));
}
#[test]
fn test_is_not_empty() {
- assert ivec::is_not_empty(~[0]);
- assert !ivec::is_not_empty[int](~[]);
+ assert (ivec::is_not_empty(~[0]));
+ assert (!ivec::is_not_empty[int](~[]));
}
#[test]
fn test_head() {
- auto a = ~[11, 12];
- check ivec::is_not_empty(a);
- assert ivec::head(a) == 11;
+ let a = ~[11, 12];
+ check (ivec::is_not_empty(a));
+ assert (ivec::head(a) == 11);
}
#[test]
fn test_tail() {
- auto a = ~[11];
- check ivec::is_not_empty(a);
- assert ivec::tail(a) == ~[];
+ let a = ~[11];
+ check (ivec::is_not_empty(a));
+ assert (ivec::tail(a) == ~[]);
a = ~[11, 12];
- check ivec::is_not_empty(a);
- assert ivec::tail(a) == ~[12];
+ check (ivec::is_not_empty(a));
+ assert (ivec::tail(a) == ~[12]);
}
#[test]
fn test_last() {
- auto n = ivec::last(~[]);
+ let n = ivec::last(~[]);
assert (n == none);
- n = ivec::last(~[ 1, 2, 3 ]);
+ n = ivec::last(~[1, 2, 3]);
assert (n == some(3));
- n = ivec::last(~[ 1, 2, 3, 4, 5 ]);
+ n = ivec::last(~[1, 2, 3, 4, 5]);
assert (n == some(5));
}
#[test]
fn test_slice() {
// Test on-stack -> on-stack slice.
- auto v = ivec::slice(~[ 1, 2, 3 ], 1u, 3u);
+ let v = ivec::slice(~[1, 2, 3], 1u, 3u);
assert (ivec::len(v) == 2u);
assert (v.(0) == 2);
assert (v.(1) == 3);
// Test on-heap -> on-stack slice.
- v = ivec::slice(~[ 1, 2, 3, 4, 5 ], 0u, 3u);
+ v = ivec::slice(~[1, 2, 3, 4, 5], 0u, 3u);
assert (ivec::len(v) == 3u);
assert (v.(0) == 1);
assert (v.(1) == 2);
assert (v.(2) == 3);
// Test on-heap -> on-heap slice.
- v = ivec::slice(~[ 1, 2, 3, 4, 5, 6 ], 1u, 6u);
+ v = ivec::slice(~[1, 2, 3, 4, 5, 6], 1u, 6u);
assert (ivec::len(v) == 5u);
assert (v.(0) == 2);
assert (v.(1) == 3);
@@ -155,15 +155,15 @@
#[test]
fn test_pop() {
// Test on-stack pop.
- auto v = ~[ 1, 2, 3 ];
- auto e = ivec::pop(v);
+ let v = ~[1, 2, 3];
+ let e = ivec::pop(v);
assert (ivec::len(v) == 2u);
assert (v.(0) == 1);
assert (v.(1) == 2);
assert (e == 3);
// Test on-heap pop.
- v = ~[ 1, 2, 3, 4, 5 ];
+ v = ~[1, 2, 3, 4, 5];
e = ivec::pop(v);
assert (ivec::len(v) == 4u);
assert (v.(0) == 1);
@@ -176,7 +176,7 @@
#[test]
fn test_grow() {
// Test on-stack grow().
- auto v = ~[];
+ let v = ~[];
ivec::grow(v, 2u, 1);
assert (ivec::len(v) == 2u);
assert (v.(0) == 1);
@@ -194,7 +194,7 @@
#[test]
fn test_grow_fn() {
- auto v = ~[];
+ let v = ~[];
ivec::grow_fn(v, 3u, square);
assert (ivec::len(v) == 3u);
assert (v.(0) == 0u);
@@ -204,7 +204,7 @@
#[test]
fn test_grow_set() {
- auto v = ~[ mutable 1, 2, 3 ];
+ let v = ~[mutable 1, 2, 3];
ivec::grow_set(v, 4u, 4, 5);
assert (ivec::len(v) == 5u);
assert (v.(0) == 1);
@@ -217,15 +217,15 @@
#[test]
fn test_map() {
// Test on-stack map.
- auto v = ~[ 1u, 2u, 3u ];
- auto w = ivec::map(square_alias, v);
+ let v = ~[1u, 2u, 3u];
+ let w = ivec::map(square_alias, v);
assert (ivec::len(w) == 3u);
assert (w.(0) == 1u);
assert (w.(1) == 4u);
assert (w.(2) == 9u);
// Test on-heap map.
- v = ~[ 1u, 2u, 3u, 4u, 5u ];
+ v = ~[1u, 2u, 3u, 4u, 5u];
w = ivec::map(square_alias, v);
assert (ivec::len(w) == 5u);
assert (w.(0) == 1u);
@@ -238,14 +238,14 @@
#[test]
fn test_filter_map() {
// Test on-stack filter-map.
- auto v = ~[ 1u, 2u, 3u ];
- auto w = ivec::filter_map(square_if_odd, v);
+ let v = ~[1u, 2u, 3u];
+ let w = ivec::filter_map(square_if_odd, v);
assert (ivec::len(w) == 2u);
assert (w.(0) == 1u);
assert (w.(1) == 9u);
// Test on-heap filter-map.
- v = ~[ 1u, 2u, 3u, 4u, 5u ];
+ v = ~[1u, 2u, 3u, 4u, 5u];
w = ivec::filter_map(square_if_odd, v);
assert (ivec::len(w) == 3u);
assert (w.(0) == 1u);
@@ -256,44 +256,44 @@
#[test]
fn test_foldl() {
// Test on-stack fold.
- auto v = ~[ 1u, 2u, 3u ];
- auto sum = ivec::foldl(add, 0u, v);
+ let v = ~[1u, 2u, 3u];
+ let sum = ivec::foldl(add, 0u, v);
assert (sum == 6u);
// Test on-heap fold.
- v = ~[ 1u, 2u, 3u, 4u, 5u ];
+ v = ~[1u, 2u, 3u, 4u, 5u];
sum = ivec::foldl(add, 0u, v);
assert (sum == 15u);
}
#[test]
fn test_any_and_all() {
- assert (ivec::any(is_three, ~[ 1u, 2u, 3u ]));
- assert (!ivec::any(is_three, ~[ 0u, 1u, 2u ]));
- assert (ivec::any(is_three, ~[ 1u, 2u, 3u, 4u, 5u ]));
- assert (!ivec::any(is_three, ~[ 1u, 2u, 4u, 5u, 6u ]));
+ assert (ivec::any(is_three, ~[1u, 2u, 3u]));
+ assert (!ivec::any(is_three, ~[0u, 1u, 2u]));
+ assert (ivec::any(is_three, ~[1u, 2u, 3u, 4u, 5u]));
+ assert (!ivec::any(is_three, ~[1u, 2u, 4u, 5u, 6u]));
- assert (ivec::all(is_three, ~[ 3u, 3u, 3u ]));
- assert (!ivec::all(is_three, ~[ 3u, 3u, 2u ]));
- assert (ivec::all(is_three, ~[ 3u, 3u, 3u, 3u, 3u ]));
- assert (!ivec::all(is_three, ~[ 3u, 3u, 0u, 1u, 2u ]));
+ assert (ivec::all(is_three, ~[3u, 3u, 3u]));
+ assert (!ivec::all(is_three, ~[3u, 3u, 2u]));
+ assert (ivec::all(is_three, ~[3u, 3u, 3u, 3u, 3u]));
+ assert (!ivec::all(is_three, ~[3u, 3u, 0u, 1u, 2u]));
}
#[test]
fn test_zip_unzip() {
- auto v1 = ~[1, 2, 3];
- auto v2 = ~[4, 5, 6];
- auto z1 = ivec::zip(v1, v2);
+ let v1 = ~[1, 2, 3];
+ let v2 = ~[4, 5, 6];
+ let z1 = ivec::zip(v1, v2);
- assert rec(_0=1, _1=4) == z1.(0);
- assert rec(_0=2, _1=5) == z1.(1);
- assert rec(_0=3, _1=6) == z1.(2);
+ assert ({_0: 1, _1: 4} == z1.(0));
+ assert ({_0: 2, _1: 5} == z1.(1));
+ assert ({_0: 3, _1: 6} == z1.(2));
- auto u1 = ivec::unzip(z1);
+ let u1 = ivec::unzip(z1);
- assert rec(_0=1, _1=4) == rec(_0=u1._0.(0), _1=u1._1.(0));
- assert rec(_0=2, _1=5) == rec(_0=u1._0.(1), _1=u1._1.(1));
- assert rec(_0=3, _1=6) == rec(_0=u1._0.(2), _1=u1._1.(2));
+ assert ({_0: 1, _1: 4} == {_0: u1._0.(0), _1: u1._1.(0)});
+ assert ({_0: 2, _1: 5} == {_0: u1._0.(1), _1: u1._1.(1)});
+ assert ({_0: 3, _1: 6} == {_0: u1._0.(2), _1: u1._1.(2)});
}
// Local Variables:
diff --git a/src/test/stdtest/list.rs b/src/test/stdtest/list.rs
index 3d93701..f96fc7c 100644
--- a/src/test/stdtest/list.rs
+++ b/src/test/stdtest/list.rs
@@ -8,7 +8,7 @@
#[test]
fn test_from_vec() {
- auto l = from_vec([0, 1, 2]);
+ let l = from_vec([0, 1, 2]);
assert (car(l) == 0);
assert (car(cdr(l)) == 1);
assert (car(cdr(cdr(l))) == 2);
@@ -16,34 +16,34 @@
#[test]
fn test_foldl() {
- auto l = from_vec([0, 1, 2, 3, 4]);
- fn add(&int a, &uint b) -> uint { ret (a as uint) + b; }
- auto rs = list::foldl(l, 0u, add);
+ let l = from_vec([0, 1, 2, 3, 4]);
+ fn add(a: &int, b: &uint) -> uint { ret (a as uint) + b; }
+ let rs = list::foldl(l, 0u, add);
assert (rs == 10u);
}
#[test]
fn test_find_success() {
- auto l = from_vec([0, 1, 2]);
- fn match(&int i) -> option::t[int] {
- ret if (i == 2) { option::some(i) } else { option::none[int] };
+ let l = from_vec([0, 1, 2]);
+ fn match(i: &int) -> option::t[int] {
+ ret if i == 2 { option::some(i) } else { option::none[int] };
}
- auto rs = list::find(l, match);
+ let rs = list::find(l, match);
assert (rs == option::some(2));
}
#[test]
fn test_find_fail() {
- auto l = from_vec([0, 1, 2]);
- fn match(&int i) -> option::t[int] { ret option::none[int]; }
- auto rs = list::find(l, match);
+ let l = from_vec([0, 1, 2]);
+ fn match(i: &int) -> option::t[int] { ret option::none[int]; }
+ let rs = list::find(l, match);
assert (rs == option::none[int]);
}
#[test]
fn test_has() {
- auto l = from_vec([5, 8, 6]);
- auto empty = list::nil[int];
+ let l = from_vec([5, 8, 6]);
+ let empty = list::nil[int];
assert (list::has(l, 5));
assert (!list::has(l, 7));
assert (list::has(l, 8));
@@ -52,7 +52,7 @@
#[test]
fn test_length() {
- auto l = from_vec([0, 1, 2]);
+ let l = from_vec([0, 1, 2]);
assert (list::length(l) == 3u);
}
diff --git a/src/test/stdtest/map.rs b/src/test/stdtest/map.rs
index da6d063..44edb3f 100644
--- a/src/test/stdtest/map.rs
+++ b/src/test/stdtest/map.rs
@@ -10,19 +10,19 @@
#[test]
fn test_simple() {
log "*** starting test_simple";
- fn eq_uint(&uint x, &uint y) -> bool { ret x == y; }
- fn hash_uint(&uint u) -> uint {
+ fn eq_uint(x: &uint, y: &uint) -> bool { ret x == y; }
+ fn hash_uint(u: &uint) -> uint {
// FIXME: can't use std::util::id since we'd be capturing a type
// param, and presently we can't close items over type params.
ret u;
}
- let map::hashfn[uint] hasher_uint = hash_uint;
- let map::eqfn[uint] eqer_uint = eq_uint;
- let map::hashfn[str] hasher_str = str::hash;
- let map::eqfn[str] eqer_str = str::eq;
+ let hasher_uint: map::hashfn[uint] = hash_uint;
+ let eqer_uint: map::eqfn[uint] = eq_uint;
+ let hasher_str: map::hashfn[str] = str::hash;
+ let eqer_str: map::eqfn[str] = str::eq;
log "uint -> uint";
- let map::hashmap[uint, uint] hm_uu =
+ let hm_uu: map::hashmap[uint, uint] =
map::mk_hashmap[uint, uint](hasher_uint, eqer_uint);
assert (hm_uu.insert(10u, 12u));
assert (hm_uu.insert(11u, 13u));
@@ -34,11 +34,11 @@
assert (hm_uu.get(12u) == 14u);
assert (!hm_uu.insert(12u, 12u));
assert (hm_uu.get(12u) == 12u);
- let str ten = "ten";
- let str eleven = "eleven";
- let str twelve = "twelve";
+ let ten: str = "ten";
+ let eleven: str = "eleven";
+ let twelve: str = "twelve";
log "str -> uint";
- let map::hashmap[str, uint] hm_su =
+ let hm_su: map::hashmap[str, uint] =
map::mk_hashmap[str, uint](hasher_str, eqer_str);
assert (hm_su.insert("ten", 12u));
assert (hm_su.insert(eleven, 13u));
@@ -52,7 +52,7 @@
assert (!hm_su.insert("twelve", 12u));
assert (hm_su.get("twelve") == 12u);
log "uint -> str";
- let map::hashmap[uint, str] hm_us =
+ let hm_us: map::hashmap[uint, str] =
map::mk_hashmap[uint, str](hasher_uint, eqer_uint);
assert (hm_us.insert(10u, "twelve"));
assert (hm_us.insert(11u, "thirteen"));
@@ -65,7 +65,7 @@
assert (!hm_us.insert(12u, "twelve"));
assert (str::eq(hm_us.get(12u), "twelve"));
log "str -> str";
- let map::hashmap[str, str] hm_ss =
+ let hm_ss: map::hashmap[str, str] =
map::mk_hashmap[str, str](hasher_str, eqer_str);
assert (hm_ss.insert(ten, "twelve"));
assert (hm_ss.insert(eleven, "thirteen"));
@@ -87,21 +87,21 @@
#[test]
fn test_growth() {
log "*** starting test_growth";
- let uint num_to_insert = 64u;
- fn eq_uint(&uint x, &uint y) -> bool { ret x == y; }
- fn hash_uint(&uint u) -> uint {
+ let num_to_insert: uint = 64u;
+ fn eq_uint(x: &uint, y: &uint) -> bool { ret x == y; }
+ fn hash_uint(u: &uint) -> uint {
// FIXME: can't use std::util::id since we'd be capturing a type
// param, and presently we can't close items over type params.
ret u;
}
log "uint -> uint";
- let map::hashfn[uint] hasher_uint = hash_uint;
- let map::eqfn[uint] eqer_uint = eq_uint;
- let map::hashmap[uint, uint] hm_uu =
+ let hasher_uint: map::hashfn[uint] = hash_uint;
+ let eqer_uint: map::eqfn[uint] = eq_uint;
+ let hm_uu: map::hashmap[uint, uint] =
map::mk_hashmap[uint, uint](hasher_uint, eqer_uint);
- let uint i = 0u;
- while (i < num_to_insert) {
+ let i: uint = 0u;
+ while i < num_to_insert {
assert (hm_uu.insert(i, i * i));
log "inserting " + uint::to_str(i, 10u) + " -> " +
uint::to_str(i * i, 10u);
@@ -109,7 +109,7 @@
}
log "-----";
i = 0u;
- while (i < num_to_insert) {
+ while i < num_to_insert {
log "get(" + uint::to_str(i, 10u) + ") = " +
uint::to_str(hm_uu.get(i), 10u);
assert (hm_uu.get(i) == i * i);
@@ -120,19 +120,19 @@
log "-----";
hm_uu.rehash();
i = 0u;
- while (i < num_to_insert) {
+ while i < num_to_insert {
log "get(" + uint::to_str(i, 10u) + ") = " +
uint::to_str(hm_uu.get(i), 10u);
assert (hm_uu.get(i) == i * i);
i += 1u;
}
log "str -> str";
- let map::hashfn[str] hasher_str = str::hash;
- let map::eqfn[str] eqer_str = str::eq;
- let map::hashmap[str, str] hm_ss =
+ let hasher_str: map::hashfn[str] = str::hash;
+ let eqer_str: map::eqfn[str] = str::eq;
+ let hm_ss: map::hashmap[str, str] =
map::mk_hashmap[str, str](hasher_str, eqer_str);
i = 0u;
- while (i < num_to_insert) {
+ while i < num_to_insert {
assert (hm_ss.insert(uint::to_str(i, 2u), uint::to_str(i * i, 2u)));
log "inserting \"" + uint::to_str(i, 2u) + "\" -> \"" +
uint::to_str(i * i, 2u) + "\"";
@@ -140,7 +140,7 @@
}
log "-----";
i = 0u;
- while (i < num_to_insert) {
+ while i < num_to_insert {
log "get(\"" + uint::to_str(i, 2u) + "\") = \"" +
hm_ss.get(uint::to_str(i, 2u)) + "\"";
assert (str::eq(hm_ss.get(uint::to_str(i, 2u)),
@@ -154,7 +154,7 @@
log "-----";
hm_ss.rehash();
i = 0u;
- while (i < num_to_insert) {
+ while i < num_to_insert {
log "get(\"" + uint::to_str(i, 2u) + "\") = \"" +
hm_ss.get(uint::to_str(i, 2u)) + "\"";
assert (str::eq(hm_ss.get(uint::to_str(i, 2u)),
@@ -167,9 +167,9 @@
#[test]
fn test_removal() {
log "*** starting test_removal";
- let uint num_to_insert = 64u;
- fn eq(&uint x, &uint y) -> bool { ret x == y; }
- fn hash(&uint u) -> uint {
+ let num_to_insert: uint = 64u;
+ fn eq(x: &uint, y: &uint) -> bool { ret x == y; }
+ fn hash(u: &uint) -> uint {
// This hash function intentionally causes collisions between
// consecutive integer pairs.
@@ -178,12 +178,12 @@
assert (hash(0u) == hash(1u));
assert (hash(2u) == hash(3u));
assert (hash(0u) != hash(2u));
- let map::hashfn[uint] hasher = hash;
- let map::eqfn[uint] eqer = eq;
- let map::hashmap[uint, uint] hm =
+ let hasher: map::hashfn[uint] = hash;
+ let eqer: map::eqfn[uint] = eq;
+ let hm: map::hashmap[uint, uint] =
map::mk_hashmap[uint, uint](hasher, eqer);
- let uint i = 0u;
- while (i < num_to_insert) {
+ let i: uint = 0u;
+ while i < num_to_insert {
assert (hm.insert(i, i * i));
log "inserting " + uint::to_str(i, 10u) + " -> " +
uint::to_str(i * i, 10u);
@@ -193,11 +193,11 @@
log "-----";
log "removing evens";
i = 0u;
- while (i < num_to_insert) {
+ while i < num_to_insert {
/**
* FIXME (issue #150): we want to check the removed value as in the
* following:
-
+
let util.option[uint] v = hm.remove(i);
alt (v) {
case (util.some[uint](u)) {
@@ -205,7 +205,7 @@
}
case (util.none[uint]()) { fail; }
}
-
+
* but we util.option is a tag type so util.some and util.none are
* off limits until we parse the dwarf for tag types.
*/
@@ -216,7 +216,7 @@
assert (hm.size() == num_to_insert / 2u);
log "-----";
i = 1u;
- while (i < num_to_insert) {
+ while i < num_to_insert {
log "get(" + uint::to_str(i, 10u) + ") = " +
uint::to_str(hm.get(i), 10u);
assert (hm.get(i) == i * i);
@@ -227,7 +227,7 @@
hm.rehash();
log "-----";
i = 1u;
- while (i < num_to_insert) {
+ while i < num_to_insert {
log "get(" + uint::to_str(i, 10u) + ") = " +
uint::to_str(hm.get(i), 10u);
assert (hm.get(i) == i * i);
@@ -235,7 +235,7 @@
}
log "-----";
i = 0u;
- while (i < num_to_insert) {
+ while i < num_to_insert {
assert (hm.insert(i, i * i));
log "inserting " + uint::to_str(i, 10u) + " -> " +
uint::to_str(i * i, 10u);
@@ -244,7 +244,7 @@
assert (hm.size() == num_to_insert);
log "-----";
i = 0u;
- while (i < num_to_insert) {
+ while i < num_to_insert {
log "get(" + uint::to_str(i, 10u) + ") = " +
uint::to_str(hm.get(i), 10u);
assert (hm.get(i) == i * i);
@@ -256,7 +256,7 @@
log "-----";
assert (hm.size() == num_to_insert);
i = 0u;
- while (i < num_to_insert) {
+ while i < num_to_insert {
log "get(" + uint::to_str(i, 10u) + ") = " +
uint::to_str(hm.get(i), 10u);
assert (hm.get(i) == i * i);
@@ -267,8 +267,8 @@
#[test]
fn test_contains_key() {
- auto key = "k";
- auto map = map::mk_hashmap[str, str](str::hash, str::eq);
+ let key = "k";
+ let map = map::mk_hashmap[str, str](str::hash, str::eq);
assert (!map.contains_key(key));
map.insert(key, "val");
assert (map.contains_key(key));
@@ -276,9 +276,9 @@
#[test]
fn test_find() {
- auto key = "k";
- auto map = map::mk_hashmap[str, str](str::hash, str::eq);
+ let key = "k";
+ let map = map::mk_hashmap[str, str](str::hash, str::eq);
assert (std::option::is_none(map.find(key)));
map.insert(key, "val");
assert (std::option::get(map.find(key)) == "val");
-}
+}
\ No newline at end of file
diff --git a/src/test/stdtest/option.rs b/src/test/stdtest/option.rs
index a22effc..6426c96 100644
--- a/src/test/stdtest/option.rs
+++ b/src/test/stdtest/option.rs
@@ -2,4 +2,4 @@
use std;
#[test]
-fn test() { auto x = std::option::some[int](10); }
\ No newline at end of file
+fn test() { let x = std::option::some[int](10); }
\ No newline at end of file
diff --git a/src/test/stdtest/os.rs b/src/test/stdtest/os.rs
index 8fcfd35..49ebb21 100644
--- a/src/test/stdtest/os.rs
+++ b/src/test/stdtest/os.rs
@@ -7,28 +7,25 @@
// NB: Each test of setenv needs to use different variable names or the
// tests will not be threadsafe
setenv("NAME1", "VALUE");
- assert getenv("NAME1") == option::some("VALUE");
+ assert (getenv("NAME1") == option::some("VALUE"));
}
#[test]
fn test_setenv_overwrite() {
setenv("NAME2", "1");
setenv("NAME2", "2");
- assert getenv("NAME2") == option::some("2");
+ assert (getenv("NAME2") == option::some("2"));
}
// Windows GetEnvironmentVariable requires some extra work to make sure
// the buffer the variable is copied into is the right size
#[test]
fn test_getenv_big() {
- auto s = "";
- auto i = 0;
- while (i < 100) {
- s += "aaaaaaaaaa";
- i += 1;
- }
+ let s = "";
+ let i = 0;
+ while i < 100 { s += "aaaaaaaaaa"; i += 1; }
setenv("NAME3", s);
- assert getenv("NAME3") == option::some(s);
+ assert (getenv("NAME3") == option::some(s));
}
// Local Variables:
diff --git a/src/test/stdtest/path.rs b/src/test/stdtest/path.rs
index 81fd742..5f7c34c 100644
--- a/src/test/stdtest/path.rs
+++ b/src/test/stdtest/path.rs
@@ -8,10 +8,10 @@
#[test]
fn test() {
- assert(!fs::path_is_absolute("test-path"));
+ assert (!fs::path_is_absolute("test-path"));
- log "Current working directory: " + os::getcwd();
+ log "Current working directory: " + os::getcwd();
- log fs::make_absolute("test-path");
- log fs::make_absolute("/usr/bin");
+ log fs::make_absolute("test-path");
+ log fs::make_absolute("/usr/bin");
}
\ No newline at end of file
diff --git a/src/test/stdtest/ptr.rs b/src/test/stdtest/ptr.rs
index bf9633e..269febf 100644
--- a/src/test/stdtest/ptr.rs
+++ b/src/test/stdtest/ptr.rs
@@ -2,19 +2,19 @@
import std::ptr;
import std::unsafe;
-type pair = rec(mutable int fst, mutable int snd);
+type pair = {mutable fst: int, mutable snd: int};
#[test]
fn test() {
- auto p = rec(mutable fst=10, mutable snd=20);
- let *mutable pair pptr = ptr::addr_of(p);
- let *mutable int iptr = unsafe::reinterpret_cast(pptr);
+ let p = {mutable fst: 10, mutable snd: 20};
+ let pptr: *mutable pair = ptr::addr_of(p);
+ let iptr: *mutable int = unsafe::reinterpret_cast(pptr);
assert (*iptr == 10);
*iptr = 30;
assert (*iptr == 30);
assert (p.fst == 30);
- *pptr = rec(mutable fst=50, mutable snd=60);
+ *pptr = {mutable fst: 50, mutable snd: 60};
assert (*iptr == 50);
assert (p.fst == 50);
assert (p.snd == 60);
diff --git a/src/test/stdtest/qsort.rs b/src/test/stdtest/qsort.rs
index c05daec..c8f19e3 100644
--- a/src/test/stdtest/qsort.rs
+++ b/src/test/stdtest/qsort.rs
@@ -5,36 +5,36 @@
import std::ivec;
import std::int;
-fn check_sort(vec[mutable int] v1, vec[mutable int] v2) {
- auto len = std::vec::len[int](v1);
- fn ltequal(&int a, &int b) -> bool { ret a <= b; }
- auto f = ltequal;
+fn check_sort(v1: vec[mutable int], v2: vec[mutable int]) {
+ let len = std::vec::len[int](v1);
+ fn ltequal(a: &int, b: &int) -> bool { ret a <= b; }
+ let f = ltequal;
std::sort::quick_sort[int](f, v1);
- auto i = 0u;
- while (i < len) { log v2.(i); assert (v2.(i) == v1.(i)); i += 1u; }
+ let i = 0u;
+ while i < len { log v2.(i); assert (v2.(i) == v1.(i)); i += 1u; }
}
#[test]
fn test() {
{
- auto v1 = [mutable 3, 7, 4, 5, 2, 9, 5, 8];
- auto v2 = [mutable 2, 3, 4, 5, 5, 7, 8, 9];
+ let v1 = [mutable 3, 7, 4, 5, 2, 9, 5, 8];
+ let v2 = [mutable 2, 3, 4, 5, 5, 7, 8, 9];
check_sort(v1, v2);
}
{
- auto v1 = [mutable 1, 1, 1];
- auto v2 = [mutable 1, 1, 1];
+ let v1 = [mutable 1, 1, 1];
+ let v2 = [mutable 1, 1, 1];
check_sort(v1, v2);
}
{
- let vec[mutable int] v1 = [mutable ];
- let vec[mutable int] v2 = [mutable ];
+ let v1: vec[mutable int] = [mutable ];
+ let v2: vec[mutable int] = [mutable ];
check_sort(v1, v2);
}
- { auto v1 = [mutable 9]; auto v2 = [mutable 9]; check_sort(v1, v2); }
+ { let v1 = [mutable 9]; let v2 = [mutable 9]; check_sort(v1, v2); }
{
- auto v1 = [mutable 9, 3, 3, 3, 9];
- auto v2 = [mutable 3, 3, 3, 9, 9];
+ let v1 = [mutable 9, 3, 3, 3, 9];
+ let v2 = [mutable 3, 3, 3, 9, 9];
check_sort(v1, v2);
}
}
@@ -42,17 +42,17 @@
// Regression test for #705
#[test]
fn test_simple() {
- auto names = ~[mutable 2, 1, 3];
+ let names = ~[mutable 2, 1, 3];
- auto expected = ~[1, 2, 3];
+ let expected = ~[1, 2, 3];
- fn lteq(&int a, &int b) -> bool { int::le(a, b) }
+ fn lteq(a: &int, b: &int) -> bool { int::le(a, b) }
sort::ivector::quick_sort(lteq, names);
- auto pairs = ivec::zip(expected, ivec::from_mut(names));
- for (rec(int _0, int _1) p in pairs) {
+ let pairs = ivec::zip(expected, ivec::from_mut(names));
+ for p: {_0: int, _1: int} in pairs {
log #fmt("%d %d", p._0, p._1);
- assert p._0 == p._1;
+ assert (p._0 == p._1);
}
}
diff --git a/src/test/stdtest/qsort3.rs b/src/test/stdtest/qsort3.rs
index 58abf1b..79e4c42 100644
--- a/src/test/stdtest/qsort3.rs
+++ b/src/test/stdtest/qsort3.rs
@@ -1,38 +1,38 @@
use std;
-fn check_sort(vec[mutable int] v1, vec[mutable int] v2) {
- auto len = std::vec::len[int](v1);
- fn lt(&int a, &int b) -> bool { ret a < b; }
- fn equal(&int a, &int b) -> bool { ret a == b; }
- auto f1 = lt;
- auto f2 = equal;
+fn check_sort(v1: vec[mutable int], v2: vec[mutable int]) {
+ let len = std::vec::len[int](v1);
+ fn lt(a: &int, b: &int) -> bool { ret a < b; }
+ fn equal(a: &int, b: &int) -> bool { ret a == b; }
+ let f1 = lt;
+ let f2 = equal;
std::sort::quick_sort3[int](f1, f2, v1);
- auto i = 0u;
- while (i < len) { log v2.(i); assert (v2.(i) == v1.(i)); i += 1u; }
+ let i = 0u;
+ while i < len { log v2.(i); assert (v2.(i) == v1.(i)); i += 1u; }
}
#[test]
fn test() {
{
- auto v1 = [mutable 3, 7, 4, 5, 2, 9, 5, 8];
- auto v2 = [mutable 2, 3, 4, 5, 5, 7, 8, 9];
+ let v1 = [mutable 3, 7, 4, 5, 2, 9, 5, 8];
+ let v2 = [mutable 2, 3, 4, 5, 5, 7, 8, 9];
check_sort(v1, v2);
}
{
- auto v1 = [mutable 1, 1, 1];
- auto v2 = [mutable 1, 1, 1];
+ let v1 = [mutable 1, 1, 1];
+ let v2 = [mutable 1, 1, 1];
check_sort(v1, v2);
}
{
- let vec[mutable int] v1 = [mutable ];
- let vec[mutable int] v2 = [mutable ];
+ let v1: vec[mutable int] = [mutable ];
+ let v2: vec[mutable int] = [mutable ];
check_sort(v1, v2);
}
- { auto v1 = [mutable 9]; auto v2 = [mutable 9]; check_sort(v1, v2); }
+ { let v1 = [mutable 9]; let v2 = [mutable 9]; check_sort(v1, v2); }
{
- auto v1 = [mutable 9, 3, 3, 3, 9];
- auto v2 = [mutable 3, 3, 3, 9, 9];
+ let v1 = [mutable 9, 3, 3, 3, 9];
+ let v2 = [mutable 3, 3, 3, 9, 9];
check_sort(v1, v2);
}
}
diff --git a/src/test/stdtest/rand.rs b/src/test/stdtest/rand.rs
index 8d7b26d..bf39460 100644
--- a/src/test/stdtest/rand.rs
+++ b/src/test/stdtest/rand.rs
@@ -6,11 +6,11 @@
#[test]
fn test() {
- let rand::rng r1 = rand::mk_rng();
+ let r1: rand::rng = rand::mk_rng();
log r1.next();
log r1.next();
{
- auto r2 = rand::mk_rng();
+ let r2 = rand::mk_rng();
log r1.next();
log r2.next();
log r1.next();
diff --git a/src/test/stdtest/run.rs b/src/test/stdtest/run.rs
index c86182d..8ba4c6a 100644
--- a/src/test/stdtest/run.rs
+++ b/src/test/stdtest/run.rs
@@ -6,13 +6,13 @@
#[cfg(target_os = "macos")]
#[test]
fn test_leaks() {
- run::run_program("echo", []);
- run::start_program("echo", []);
- run::program_output("echo", []);
+ run::run_program("echo", []);
+ run::start_program("echo", []);
+ run::program_output("echo", []);
}
// FIXME
#[cfg(target_os = "win32")]
#[test]
#[ignore]
-fn test_leaks() {}
+fn test_leaks() { }
\ No newline at end of file
diff --git a/src/test/stdtest/sha1.rs b/src/test/stdtest/sha1.rs
index 0384445..a514d34 100644
--- a/src/test/stdtest/sha1.rs
+++ b/src/test/stdtest/sha1.rs
@@ -9,73 +9,79 @@
#[test]
fn test() {
- type test = rec(str input, vec[u8] output);
+ type test = {input: str, output: vec[u8]};
fn a_million_letter_a() -> str {
- auto i = 0;
- auto rs = "";
- while (i < 100000) { rs += "aaaaaaaaaa"; i += 1; }
+ let i = 0;
+ let rs = "";
+ while i < 100000 { rs += "aaaaaaaaaa"; i += 1; }
ret rs;
}
// Test messages from FIPS 180-1
- let vec[test] fips_180_1_tests =
- [rec(input="abc",
- output=[0xA9u8, 0x99u8, 0x3Eu8, 0x36u8, 0x47u8, 0x06u8, 0x81u8,
- 0x6Au8, 0xBAu8, 0x3Eu8, 0x25u8, 0x71u8, 0x78u8, 0x50u8,
- 0xC2u8, 0x6Cu8, 0x9Cu8, 0xD0u8, 0xD8u8, 0x9Du8]),
- rec(input="abcdbcdecdefdefgefghfghighij" +
- "hijkijkljklmklmnlmnomnopnopq",
- output=[0x84u8, 0x98u8, 0x3Eu8, 0x44u8, 0x1Cu8, 0x3Bu8, 0xD2u8,
- 0x6Eu8, 0xBAu8, 0xAEu8, 0x4Au8, 0xA1u8, 0xF9u8, 0x51u8,
- 0x29u8, 0xE5u8, 0xE5u8, 0x46u8, 0x70u8, 0xF1u8]),
- rec(input=a_million_letter_a(),
- output=[0x34u8, 0xAAu8, 0x97u8, 0x3Cu8, 0xD4u8, 0xC4u8, 0xDAu8,
- 0xA4u8, 0xF6u8, 0x1Eu8, 0xEBu8, 0x2Bu8, 0xDBu8, 0xADu8,
- 0x27u8, 0x31u8, 0x65u8, 0x34u8, 0x01u8, 0x6Fu8])];
+ let fips_180_1_tests: vec[test] =
+ [{input: "abc",
+ output:
+ [0xA9u8, 0x99u8, 0x3Eu8, 0x36u8, 0x47u8, 0x06u8, 0x81u8, 0x6Au8,
+ 0xBAu8, 0x3Eu8, 0x25u8, 0x71u8, 0x78u8, 0x50u8, 0xC2u8, 0x6Cu8,
+ 0x9Cu8, 0xD0u8, 0xD8u8, 0x9Du8]},
+ {input:
+ "abcdbcdecdefdefgefghfghighij" + "hijkijkljklmklmnlmnomnopnopq",
+ output:
+ [0x84u8, 0x98u8, 0x3Eu8, 0x44u8, 0x1Cu8, 0x3Bu8, 0xD2u8, 0x6Eu8,
+ 0xBAu8, 0xAEu8, 0x4Au8, 0xA1u8, 0xF9u8, 0x51u8, 0x29u8, 0xE5u8,
+ 0xE5u8, 0x46u8, 0x70u8, 0xF1u8]},
+ {input: a_million_letter_a(),
+ output:
+ [0x34u8, 0xAAu8, 0x97u8, 0x3Cu8, 0xD4u8, 0xC4u8, 0xDAu8, 0xA4u8,
+ 0xF6u8, 0x1Eu8, 0xEBu8, 0x2Bu8, 0xDBu8, 0xADu8, 0x27u8, 0x31u8,
+ 0x65u8, 0x34u8, 0x01u8, 0x6Fu8]}];
// Examples from wikipedia
- let vec[test] wikipedia_tests =
- [rec(input="The quick brown fox jumps over the lazy dog",
- output=[0x2fu8, 0xd4u8, 0xe1u8, 0xc6u8, 0x7au8, 0x2du8, 0x28u8,
- 0xfcu8, 0xedu8, 0x84u8, 0x9eu8, 0xe1u8, 0xbbu8, 0x76u8,
- 0xe7u8, 0x39u8, 0x1bu8, 0x93u8, 0xebu8, 0x12u8]),
- rec(input="The quick brown fox jumps over the lazy cog",
- output=[0xdeu8, 0x9fu8, 0x2cu8, 0x7fu8, 0xd2u8, 0x5eu8, 0x1bu8,
- 0x3au8, 0xfau8, 0xd3u8, 0xe8u8, 0x5au8, 0x0bu8, 0xd1u8,
- 0x7du8, 0x9bu8, 0x10u8, 0x0du8, 0xb4u8, 0xb3u8])];
- auto tests = fips_180_1_tests + wikipedia_tests;
- fn check_vec_eq(vec[u8] v0, vec[u8] v1) {
+ let wikipedia_tests: vec[test] =
+ [{input: "The quick brown fox jumps over the lazy dog",
+ output:
+ [0x2fu8, 0xd4u8, 0xe1u8, 0xc6u8, 0x7au8, 0x2du8, 0x28u8, 0xfcu8,
+ 0xedu8, 0x84u8, 0x9eu8, 0xe1u8, 0xbbu8, 0x76u8, 0xe7u8, 0x39u8,
+ 0x1bu8, 0x93u8, 0xebu8, 0x12u8]},
+ {input: "The quick brown fox jumps over the lazy cog",
+ output:
+ [0xdeu8, 0x9fu8, 0x2cu8, 0x7fu8, 0xd2u8, 0x5eu8, 0x1bu8, 0x3au8,
+ 0xfau8, 0xd3u8, 0xe8u8, 0x5au8, 0x0bu8, 0xd1u8, 0x7du8, 0x9bu8,
+ 0x10u8, 0x0du8, 0xb4u8, 0xb3u8]}];
+ let tests = fips_180_1_tests + wikipedia_tests;
+ fn check_vec_eq(v0: vec[u8], v1: vec[u8]) {
assert (vec::len[u8](v0) == vec::len[u8](v1));
- auto len = vec::len[u8](v0);
- auto i = 0u;
- while (i < len) {
- auto a = v0.(i);
- auto b = v1.(i);
+ let len = vec::len[u8](v0);
+ let i = 0u;
+ while i < len {
+ let a = v0.(i);
+ let b = v1.(i);
assert (a == b);
i += 1u;
}
}
// Test that it works when accepting the message all at once
- auto sh = sha1::mk_sha1();
- for (test t in tests) {
+ let sh = sha1::mk_sha1();
+ for t: test in tests {
sh.input_str(t.input);
- auto out = sh.result();
+ let out = sh.result();
check_vec_eq(t.output, out);
sh.reset();
}
+
// Test that it works when accepting the message in pieces
- for (test t in tests) {
- auto len = str::byte_len(t.input);
- auto left = len;
- while (left > 0u) {
- auto take = (left + 1u) / 2u;
+ for t: test in tests {
+ let len = str::byte_len(t.input);
+ let left = len;
+ while left > 0u {
+ let take = (left + 1u) / 2u;
sh.input_str(str::substr(t.input, len - left, take));
left = left - take;
}
- auto out = sh.result();
+ let out = sh.result();
check_vec_eq(t.output, out);
sh.reset();
}
diff --git a/src/test/stdtest/sort.rs b/src/test/stdtest/sort.rs
index aae6792..e2ce3f0 100644
--- a/src/test/stdtest/sort.rs
+++ b/src/test/stdtest/sort.rs
@@ -1,28 +1,28 @@
use std;
-fn check_sort(vec[int] v1, vec[int] v2) {
- auto len = std::vec::len[int](v1);
- fn lteq(&int a, &int b) -> bool { ret a <= b; }
- auto f = lteq;
- auto v3 = std::sort::merge_sort[int](f, v1);
- auto i = 0u;
- while (i < len) { log v3.(i); assert (v3.(i) == v2.(i)); i += 1u; }
+fn check_sort(v1: vec[int], v2: vec[int]) {
+ let len = std::vec::len[int](v1);
+ fn lteq(a: &int, b: &int) -> bool { ret a <= b; }
+ let f = lteq;
+ let v3 = std::sort::merge_sort[int](f, v1);
+ let i = 0u;
+ while i < len { log v3.(i); assert (v3.(i) == v2.(i)); i += 1u; }
}
#[test]
fn test() {
{
- auto v1 = [3, 7, 4, 5, 2, 9, 5, 8];
- auto v2 = [2, 3, 4, 5, 5, 7, 8, 9];
+ let v1 = [3, 7, 4, 5, 2, 9, 5, 8];
+ let v2 = [2, 3, 4, 5, 5, 7, 8, 9];
check_sort(v1, v2);
}
- { auto v1 = [1, 1, 1]; auto v2 = [1, 1, 1]; check_sort(v1, v2); }
- { let vec[int] v1 = []; let vec[int] v2 = []; check_sort(v1, v2); }
- { auto v1 = [9]; auto v2 = [9]; check_sort(v1, v2); }
+ { let v1 = [1, 1, 1]; let v2 = [1, 1, 1]; check_sort(v1, v2); }
+ { let v1: vec[int] = []; let v2: vec[int] = []; check_sort(v1, v2); }
+ { let v1 = [9]; let v2 = [9]; check_sort(v1, v2); }
{
- auto v1 = [9, 3, 3, 3, 9];
- auto v2 = [3, 3, 3, 9, 9];
+ let v1 = [9, 3, 3, 3, 9];
+ let v2 = [3, 3, 3, 9, 9];
check_sort(v1, v2);
}
}
\ No newline at end of file
diff --git a/src/test/stdtest/sort_ivec.rs b/src/test/stdtest/sort_ivec.rs
index dcc90a8..14654a8 100644
--- a/src/test/stdtest/sort_ivec.rs
+++ b/src/test/stdtest/sort_ivec.rs
@@ -1,28 +1,28 @@
use std;
-fn check_sort(&int[] v1, &int[] v2) {
- auto len = std::ivec::len[int](v1);
- fn lteq(&int a, &int b) -> bool { ret a <= b; }
- auto f = lteq;
- auto v3 = std::sort::ivector::merge_sort[int](f, v1);
- auto i = 0u;
- while (i < len) { log v3.(i); assert (v3.(i) == v2.(i)); i += 1u; }
+fn check_sort(v1: &int[], v2: &int[]) {
+ let len = std::ivec::len[int](v1);
+ fn lteq(a: &int, b: &int) -> bool { ret a <= b; }
+ let f = lteq;
+ let v3 = std::sort::ivector::merge_sort[int](f, v1);
+ let i = 0u;
+ while i < len { log v3.(i); assert (v3.(i) == v2.(i)); i += 1u; }
}
#[test]
fn test() {
{
- auto v1 = ~[3, 7, 4, 5, 2, 9, 5, 8];
- auto v2 = ~[2, 3, 4, 5, 5, 7, 8, 9];
+ let v1 = ~[3, 7, 4, 5, 2, 9, 5, 8];
+ let v2 = ~[2, 3, 4, 5, 5, 7, 8, 9];
check_sort(v1, v2);
}
- { auto v1 = ~[1, 1, 1]; auto v2 = ~[1, 1, 1]; check_sort(v1, v2); }
- { let int[] v1 = ~[]; let int[] v2 = ~[]; check_sort(v1, v2); }
- { auto v1 = ~[9]; auto v2 = ~[9]; check_sort(v1, v2); }
+ { let v1 = ~[1, 1, 1]; let v2 = ~[1, 1, 1]; check_sort(v1, v2); }
+ { let v1: int[] = ~[]; let v2: int[] = ~[]; check_sort(v1, v2); }
+ { let v1 = ~[9]; let v2 = ~[9]; check_sort(v1, v2); }
{
- auto v1 = ~[9, 3, 3, 3, 9];
- auto v2 = ~[3, 3, 3, 9, 9];
+ let v1 = ~[9, 3, 3, 3, 9];
+ let v2 = ~[3, 3, 3, 9, 9];
check_sort(v1, v2);
}
-}
+}
\ No newline at end of file
diff --git a/src/test/stdtest/str.rs b/src/test/stdtest/str.rs
index 063a0d9..f2b6a6b 100644
--- a/src/test/stdtest/str.rs
+++ b/src/test/stdtest/str.rs
@@ -24,12 +24,12 @@
#[test]
fn test_split() {
- fn t(&str s, char c, int i, &str k) {
+ fn t(s: &str, c: char, i: int, k: &str) {
log "splitting: " + s;
log i;
- auto v = str::split(s, c as u8);
+ let v = str::split(s, c as u8);
log "split to: ";
- for (str z in v) { log z; }
+ for z: str in v { log z; }
log "comparing: " + v.(i) + " vs. " + k;
assert (str::eq(v.(i), k));
}
@@ -44,8 +44,8 @@
#[test]
fn test_find() {
- fn t(&str haystack, &str needle, int i) {
- let int j = str::find(haystack, needle);
+ fn t(haystack: &str, needle: &str, i: int) {
+ let j: int = str::find(haystack, needle);
log "searched for " + needle;
log j;
assert (i == j);
@@ -59,7 +59,7 @@
#[test]
fn test_substr() {
- fn t(&str a, &str b, int start) {
+ fn t(a: &str, b: &str, start: int) {
assert (str::eq(str::substr(a, start as uint, str::byte_len(b)), b));
}
t("hello", "llo", 2);
@@ -69,20 +69,20 @@
#[test]
fn test_concat() {
- fn t(&vec[str] v, &str s) { assert (str::eq(str::concat(v), s)); }
+ fn t(v: &vec[str], s: &str) { assert (str::eq(str::concat(v), s)); }
t(["you", "know", "I'm", "no", "good"], "youknowI'mnogood");
- let vec[str] v = [];
+ let v: vec[str] = [];
t(v, "");
t(["hi"], "hi");
}
#[test]
fn test_connect() {
- fn t(&vec[str] v, &str sep, &str s) {
+ fn t(v: &vec[str], sep: &str, s: &str) {
assert (str::eq(str::connect(v, sep), s));
}
t(["you", "know", "I'm", "no", "good"], " ", "you know I'm no good");
- let vec[str] v = [];
+ let v: vec[str] = [];
t(v, " ", "");
t(["hi"], " ", "hi");
}
@@ -92,10 +92,10 @@
// to_upper doesn't understand unicode yet,
// but we need to at least preserve it
- auto unicode = "\u65e5\u672c";
- auto input = "abcDEF" + unicode + "xyz:.;";
- auto expected = "ABCDEF" + unicode + "XYZ:.;";
- auto actual = str::to_upper(input);
+ let unicode = "\u65e5\u672c";
+ let input = "abcDEF" + unicode + "xyz:.;";
+ let expected = "ABCDEF" + unicode + "XYZ:.;";
+ let actual = str::to_upper(input);
assert (str::eq(expected, actual));
}
@@ -105,15 +105,15 @@
assert (str::eq("bc", str::slice("abc", 1u, 3u)));
assert (str::eq("", str::slice("abc", 1u, 1u)));
fn a_million_letter_a() -> str {
- auto i = 0;
- auto rs = "";
- while (i < 100000) { rs += "aaaaaaaaaa"; i += 1; }
+ let i = 0;
+ let rs = "";
+ while i < 100000 { rs += "aaaaaaaaaa"; i += 1; }
ret rs;
}
fn half_a_million_letter_a() -> str {
- auto i = 0;
- auto rs = "";
- while (i < 100000) { rs += "aaaaa"; i += 1; }
+ let i = 0;
+ let rs = "";
+ while i < 100000 { rs += "aaaaa"; i += 1; }
ret rs;
}
assert (str::eq(half_a_million_letter_a(),
@@ -131,28 +131,27 @@
#[test]
fn test_is_empty() {
- assert str::is_empty("");
- assert !str::is_empty("a");
+ assert (str::is_empty(""));
+ assert (!str::is_empty("a"));
}
#[test]
fn test_is_not_empty() {
- assert str::is_not_empty("a");
- assert !str::is_not_empty("");
+ assert (str::is_not_empty("a"));
+ assert (!str::is_not_empty(""));
}
#[test]
fn test_replace() {
- auto a = "a";
- check str::is_not_empty(a);
- assert str::replace("", a, "b") == "";
- assert str::replace("a", a, "b") == "b";
- assert str::replace("ab", a, "b") == "bb";
- auto test = "test";
- check str::is_not_empty(test);
- assert str::replace(" test test ", test, "toast")
- == " toast toast ";
- assert str::replace(" test test ", test, "") == " ";
+ let a = "a";
+ check (str::is_not_empty(a));
+ assert (str::replace("", a, "b") == "");
+ assert (str::replace("a", a, "b") == "b");
+ assert (str::replace("ab", a, "b") == "bb");
+ let test = "test";
+ check (str::is_not_empty(test));
+ assert (str::replace(" test test ", test, "toast") == " toast toast ");
+ assert (str::replace(" test test ", test, "") == " ");
}
diff --git a/src/test/stdtest/str_buf.rs b/src/test/stdtest/str_buf.rs
index 0bc0052..6b013ed 100644
--- a/src/test/stdtest/str_buf.rs
+++ b/src/test/stdtest/str_buf.rs
@@ -6,10 +6,10 @@
#[test]
fn test() {
- auto s = "hello";
- auto sb = str::buf(s);
- auto s_cstr = str::str_from_cstr(sb);
+ let s = "hello";
+ let sb = str::buf(s);
+ let s_cstr = str::str_from_cstr(sb);
assert (str::eq(s_cstr, s));
- auto s_buf = str::str_from_buf(sb, 5u);
+ let s_buf = str::str_from_buf(sb, 5u);
assert (str::eq(s_buf, s));
}
\ No newline at end of file
diff --git a/src/test/stdtest/task.rs b/src/test/stdtest/task.rs
index 62ed8b9..1324326 100644
--- a/src/test/stdtest/task.rs
+++ b/src/test/stdtest/task.rs
@@ -7,59 +7,53 @@
#[test]
fn test_unsupervise() {
- fn f() {
- task::unsupervise();
- fail;
- }
+ fn f() { task::unsupervise(); fail; }
spawn f();
}
#[test]
fn test_join() {
- fn winner() {
- }
+ fn winner() { }
- auto wintask = spawn winner();
+ let wintask = spawn winner();
- assert task::join(wintask) == task::tr_success;
+ assert (task::join(wintask) == task::tr_success);
- fn failer() {
- task::unsupervise();
- fail;
- }
+ fn failer() { task::unsupervise(); fail; }
- auto failtask = spawn failer();
+ let failtask = spawn failer();
- assert task::join(failtask) == task::tr_failure;
+ assert (task::join(failtask) == task::tr_failure);
}
#[test]
fn test_send_recv() {
- auto p = port[int]();
- auto c = chan(p);
+ let p = port[int]();
+ let c = chan(p);
task::send(c, 10);
- assert task::recv(p) == 10;
+ assert (task::recv(p) == 10);
}
#[test]
fn test_worker() {
- task::worker(fn(port[int] p) {
- auto x; p |> x;
- assert x == 10;
- }).chan <| 10;
+ task::worker(fn (p: port[int]) { let x; p |> x; assert (x == 10); }).chan
+ <| 10;
- task::worker(fn(port[rec(int x, int y)] p) {
- auto x; p |> x;
- assert x.y == 20;
- }).chan <| rec(x = 10, y = 20);
+ task::worker(fn (p: port[{x: int, y: int}]) {
+ let x;
+ p |> x;
+ assert (x.y == 20);
+ }).chan <| {x: 10, y: 20};
- task::worker(fn(port[rec(int x, int y, int z)] p) {
- auto x; p |> x;
- assert x.z == 30;
- }).chan <| rec(x = 10, y = 20, z = 30);
+ task::worker(fn (p: port[{x: int, y: int, z: int}]) {
+ let x;
+ p |> x;
+ assert (x.z == 30);
+ }).chan <| {x: 10, y: 20, z: 30};
- task::worker(fn(port[rec(int a, int b, int c, int d)] p) {
- auto x; p |> x;
- assert x.d == 40;
- }).chan <| rec(a = 10, b = 20, c = 30, d = 40);
-}
+ task::worker(fn (p: port[{a: int, b: int, c: int, d: int}]) {
+ let x;
+ p |> x;
+ assert (x.d == 40);
+ }).chan <| {a: 10, b: 20, c: 30, d: 40};
+}
\ No newline at end of file
diff --git a/src/test/stdtest/test.rs b/src/test/stdtest/test.rs
index 65c1a04..fd6f883 100644
--- a/src/test/stdtest/test.rs
+++ b/src/test/stdtest/test.rs
@@ -6,44 +6,38 @@
#[test]
fn do_not_run_ignored_tests() {
- auto ran = @mutable false;
- auto f = bind fn(@mutable bool ran) {
- *ran = true;
- } (ran);
+ let ran = @mutable false;
+ let f = bind fn (ran: @mutable bool) { *ran = true; }(ran);
- auto desc = rec(name = "whatever",
- fn = f,
- ignore = true);
+ let desc = {name: "whatever", fn: f, ignore: true};
test::run_test(desc, test::default_test_to_task);
- assert ran == false;
+ assert (ran == false);
}
#[test]
fn ignored_tests_result_in_ignored() {
fn f() { }
- auto desc = rec(name = "whatever",
- fn = f,
- ignore = true);
- auto res = test::run_test(desc, test::default_test_to_task).wait();
- assert res == test::tr_ignored;
+ let desc = {name: "whatever", fn: f, ignore: true};
+ let res = test::run_test(desc, test::default_test_to_task).wait();
+ assert (res == test::tr_ignored);
}
#[test]
fn first_free_arg_should_be_a_filter() {
- auto args = ~["progname", "filter"];
- check ivec::is_not_empty(args);
- auto opts = alt test::parse_opts(args) { either::left(?o) { o } };
- assert str::eq("filter", option::get(opts.filter));
+ let args = ~["progname", "filter"];
+ check (ivec::is_not_empty(args));
+ let opts = alt test::parse_opts(args) { either::left(o) { o } };
+ assert (str::eq("filter", option::get(opts.filter)));
}
#[test]
fn parse_ignored_flag() {
- auto args = ~["progname", "filter", "--ignored"];
- check ivec::is_not_empty(args);
- auto opts = alt test::parse_opts(args) { either::left(?o) { o } };
- assert opts.run_ignored;
+ let args = ~["progname", "filter", "--ignored"];
+ check (ivec::is_not_empty(args));
+ let opts = alt test::parse_opts(args) { either::left(o) { o } };
+ assert (opts.run_ignored);
}
#[test]
@@ -51,62 +45,52 @@
// When we run ignored tests the test filter should filter out all the
// unignored tests and flip the ignore flag on the rest to false
- auto opts = rec(filter = option::none,
- run_ignored = true);
- auto tests = ~[rec(name = "1",
- fn = fn() {},
- ignore = true),
- rec(name = "2",
- fn = fn() {},
- ignore = false)];
- auto filtered = test::filter_tests(opts, tests);
+ let opts = {filter: option::none, run_ignored: true};
+ let tests =
+ ~[{name: "1", fn: fn () { }, ignore: true},
+ {name: "2", fn: fn () { }, ignore: false}];
+ let filtered = test::filter_tests(opts, tests);
- assert ivec::len(filtered) == 1u;
- assert filtered.(0).name == "1";
- assert filtered.(0).ignore == false;
+ assert (ivec::len(filtered) == 1u);
+ assert (filtered.(0).name == "1");
+ assert (filtered.(0).ignore == false);
}
#[test]
fn sort_tests() {
- auto opts = rec(filter = option::none,
- run_ignored = false);
+ let opts = {filter: option::none, run_ignored: false};
- auto names = ~["sha1::test",
- "int::test_to_str",
- "int::test_pow",
- "test::do_not_run_ignored_tests",
- "test::ignored_tests_result_in_ignored",
- "test::first_free_arg_should_be_a_filter",
- "test::parse_ignored_flag",
- "test::filter_for_ignored_option",
- "test::sort_tests"];
- auto tests = {
- auto testfn = fn() {};
- auto tests = ~[];
- for (str name in names) {
- auto test = rec(name = name,
- fn = testfn,
- ignore = false);
- tests += ~[test];
- }
- tests
- };
- auto filtered = test::filter_tests(opts, tests);
+ let names =
+ ~["sha1::test", "int::test_to_str", "int::test_pow",
+ "test::do_not_run_ignored_tests",
+ "test::ignored_tests_result_in_ignored",
+ "test::first_free_arg_should_be_a_filter",
+ "test::parse_ignored_flag", "test::filter_for_ignored_option",
+ "test::sort_tests"];
+ let tests =
+ {
+ let testfn = fn () { };
+ let tests = ~[];
+ for name: str in names {
+ let test = {name: name, fn: testfn, ignore: false};
+ tests += ~[test];
+ }
+ tests
+ };
+ let filtered = test::filter_tests(opts, tests);
- auto expected = ~["int::test_pow",
- "int::test_to_str",
- "sha1::test",
- "test::do_not_run_ignored_tests",
- "test::filter_for_ignored_option",
- "test::first_free_arg_should_be_a_filter",
- "test::ignored_tests_result_in_ignored",
- "test::parse_ignored_flag",
- "test::sort_tests"];
+ let expected =
+ ~["int::test_pow", "int::test_to_str", "sha1::test",
+ "test::do_not_run_ignored_tests", "test::filter_for_ignored_option",
+ "test::first_free_arg_should_be_a_filter",
+ "test::ignored_tests_result_in_ignored", "test::parse_ignored_flag",
+ "test::sort_tests"];
- auto pairs = ivec::zip(expected, filtered);
+ let pairs = ivec::zip(expected, filtered);
- for (rec(str _0, test::test_desc _1) p in pairs) {
- assert p._0 == p._1.name;
+
+ for p: {_0: str, _1: test::test_desc} in pairs {
+ assert (p._0 == p._1.name);
}
}
diff --git a/src/test/stdtest/vec.rs b/src/test/stdtest/vec.rs
index 5e140a7..af34647 100644
--- a/src/test/stdtest/vec.rs
+++ b/src/test/stdtest/vec.rs
@@ -6,19 +6,19 @@
#[test]
fn test_init_elt() {
- let vec[uint] v = init_elt[uint](5u, 3u);
+ let v: vec[uint] = init_elt[uint](5u, 3u);
assert (len[uint](v) == 3u);
assert (v.(0) == 5u);
assert (v.(1) == 5u);
assert (v.(2) == 5u);
}
-fn id(uint x) -> uint { ret x; }
+fn id(x: uint) -> uint { ret x; }
#[test]
fn test_init_fn() {
- let fn(uint) -> uint op = id;
- let vec[uint] v = init_fn[uint](op, 5u);
+ let op: fn(uint) -> uint = id;
+ let v: vec[uint] = init_fn[uint](op, 5u);
assert (len[uint](v) == 5u);
assert (v.(0) == 0u);
assert (v.(1) == 1u);
@@ -29,8 +29,8 @@
#[test]
fn test_slice() {
- let vec[int] v = [1, 2, 3, 4, 5];
- auto v2 = slice[int](v, 2u, 4u);
+ let v: vec[int] = [1, 2, 3, 4, 5];
+ let v2 = slice[int](v, 2u, 4u);
assert (len[int](v2) == 2u);
assert (v2.(0) == 3);
assert (v2.(1) == 4);
@@ -38,40 +38,39 @@
#[test]
fn test_map() {
- fn square(&int x) -> int { ret x * x; }
- let option::operator[int, int] op = square;
- let vec[int] v = [1, 2, 3, 4, 5];
- let vec[int] s = map[int, int](op, v);
- let int i = 0;
- while (i < 5) { assert (v.(i) * v.(i) == s.(i)); i += 1; }
+ fn square(x: &int) -> int { ret x * x; }
+ let op: option::operator[int, int] = square;
+ let v: vec[int] = [1, 2, 3, 4, 5];
+ let s: vec[int] = map[int, int](op, v);
+ let i: int = 0;
+ while i < 5 { assert (v.(i) * v.(i) == s.(i)); i += 1; }
}
#[test]
fn test_map2() {
- fn times(&int x, &int y) -> int { ret x * y; }
- auto f = times;
- auto v0 = [1, 2, 3, 4, 5];
- auto v1 = [5, 4, 3, 2, 1];
- auto u = map2[int, int, int](f, v0, v1);
- auto i = 0;
- while (i < 5) { assert (v0.(i) * v1.(i) == u.(i)); i += 1; }
+ fn times(x: &int, y: &int) -> int { ret x * y; }
+ let f = times;
+ let v0 = [1, 2, 3, 4, 5];
+ let v1 = [5, 4, 3, 2, 1];
+ let u = map2[int, int, int](f, v0, v1);
+ let i = 0;
+ while i < 5 { assert (v0.(i) * v1.(i) == u.(i)); i += 1; }
}
#[test]
fn test_filter_map() {
- fn halve(&int i) -> option::t[int] {
- if (i % 2 == 0) {
+ fn halve(i: &int) -> option::t[int] {
+ if i % 2 == 0 {
ret option::some[int](i / 2);
} else { ret option::none[int]; }
}
- fn halve_for_sure(&int i) -> int { ret i / 2; }
- let vec[int] all_even = [0, 2, 8, 6];
- let vec[int] all_odd1 = [1, 7, 3];
- let vec[int] all_odd2 = [];
- let vec[int] mix = [9, 2, 6, 7, 1, 0, 0, 3];
- let vec[int] mix_dest = [1, 3, 0, 0];
- assert (filter_map(halve, all_even) ==
- map(halve_for_sure, all_even));
+ fn halve_for_sure(i: &int) -> int { ret i / 2; }
+ let all_even: vec[int] = [0, 2, 8, 6];
+ let all_odd1: vec[int] = [1, 7, 3];
+ let all_odd2: vec[int] = [];
+ let mix: vec[int] = [9, 2, 6, 7, 1, 0, 0, 3];
+ let mix_dest: vec[int] = [1, 3, 0, 0];
+ assert (filter_map(halve, all_even) == map(halve_for_sure, all_even));
assert (filter_map(halve, all_odd1) == empty[int]());
assert (filter_map(halve, all_odd2) == empty[int]());
assert (filter_map(halve, mix) == mix_dest);
@@ -79,22 +78,18 @@
#[test]
fn test_position() {
- let vec[int] v1 = [1, 2, 3, 3, 2, 5];
- assert (position(1, v1) == option::some[uint](0u));
- assert (position(2, v1) == option::some[uint](1u));
- assert (position(5, v1) == option::some[uint](5u));
- assert (position(4, v1) == option::none[uint]);
+ let v1: vec[int] = [1, 2, 3, 3, 2, 5];
+ assert (position(1, v1) == option::some[uint](0u));
+ assert (position(2, v1) == option::some[uint](1u));
+ assert (position(5, v1) == option::some[uint](5u));
+ assert (position(4, v1) == option::none[uint]);
}
#[test]
fn test_position_pred() {
- fn less_than_three(&int i) -> bool {
- ret i <3;
- }
- fn is_eighteen(&int i) -> bool {
- ret i == 18;
- }
- let vec[int] v1 = [5, 4, 3, 2, 1];
- assert (position_pred(less_than_three, v1) == option::some[uint](3u));
- assert (position_pred(is_eighteen, v1) == option::none[uint]);
-}
+ fn less_than_three(i: &int) -> bool { ret i < 3; }
+ fn is_eighteen(i: &int) -> bool { ret i == 18; }
+ let v1: vec[int] = [5, 4, 3, 2, 1];
+ assert (position_pred(less_than_three, v1) == option::some[uint](3u));
+ assert (position_pred(is_eighteen, v1) == option::none[uint]);
+}
\ No newline at end of file
diff --git a/src/test/stdtest/vec_str_conversions.rs b/src/test/stdtest/vec_str_conversions.rs
index dddbb5b..554fd69 100644
--- a/src/test/stdtest/vec_str_conversions.rs
+++ b/src/test/stdtest/vec_str_conversions.rs
@@ -7,7 +7,7 @@
#[test]
fn test_simple() {
- let str s1 = "All mimsy were the borogoves";
+ let s1: str = "All mimsy were the borogoves";
/*
* FIXME from_bytes(vec[u8] v) has constraint is_utf(v), which is
* unimplemented and thereby just fails. This doesn't stop us from
@@ -15,15 +15,15 @@
* working, but we should implement is_utf8 before that happens.
*/
- let vec[u8] v = str::bytes(s1);
- let str s2 = str::from_bytes(v);
- let uint i = 0u;
- let uint n1 = str::byte_len(s1);
- let uint n2 = vec::len[u8](v);
+ let v: vec[u8] = str::bytes(s1);
+ let s2: str = str::from_bytes(v);
+ let i: uint = 0u;
+ let n1: uint = str::byte_len(s1);
+ let n2: uint = vec::len[u8](v);
assert (n1 == n2);
- while (i < n1) {
- let u8 a = s1.(i);
- let u8 b = s2.(i);
+ while i < n1 {
+ let a: u8 = s1.(i);
+ let b: u8 = s2.(i);
log a;
log b;
assert (a == b);
@@ -31,4 +31,4 @@
}
log "refcnt is";
log str::refcount(s1);
-}
+}
\ No newline at end of file