This should be a snapshot transition.
-import driver.session;
-import lib.llvm.llvm;
-import middle.trans;
-import std.Str;
-import std.FS;
-
-import lib.llvm.llvm.ModuleRef;
-import lib.llvm.llvm.ValueRef;
-import lib.llvm.mk_pass_manager;
-import lib.llvm.mk_target_data;
-import lib.llvm.mk_type_names;
-import lib.llvm.False;
-import lib.llvm.True;
+import driver::session;
+import lib::llvm::llvm;
+import middle::trans;
+import std::_str;
+import std::fs;
+
+import lib::llvm::llvm::ModuleRef;
+import lib::llvm::llvm::ValueRef;
+import lib::llvm::mk_pass_manager;
+import lib::llvm::mk_target_data;
+import lib::llvm::mk_type_names;
+import lib::llvm::False;
+import lib::llvm::True;
tag output_type {
output_type_none;
output_type_object;
}
-fn llvm_err(session.session sess, str msg) {
- auto buf = llvm.LLVMRustGetLastError();
+fn llvm_err(session::session sess, str msg) {
+ auto buf = llvm::LLVMRustGetLastError();
if ((buf as uint) == 0u) {
sess.err(msg);
} else {
- sess.err(msg + ": " + Str.str_from_cstr(buf));
+ sess.err(msg + ": " + _str::str_from_cstr(buf));
}
fail;
}
-fn link_intrinsics(session.session sess, ModuleRef llmod) {
- auto path = FS.connect(sess.get_opts().sysroot, "intrinsics.bc");
+fn link_intrinsics(session::session sess, ModuleRef llmod) {
+ auto path = fs::connect(sess.get_opts().sysroot, "intrinsics.bc");
auto membuf =
- llvm.LLVMRustCreateMemoryBufferWithContentsOfFile(Str.buf(path));
+ llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(_str::buf(path));
if ((membuf as uint) == 0u) {
llvm_err(sess, "installation problem: couldn't open intrinstics.bc");
fail;
}
- auto llintrinsicsmod = llvm.LLVMRustParseBitcode(membuf);
+ auto llintrinsicsmod = llvm::LLVMRustParseBitcode(membuf);
if ((llintrinsicsmod as uint) == 0u) {
llvm_err(sess, "installation problem: couldn't parse intrinstics.bc");
fail;
}
- if (llvm.LLVMLinkModules(llmod, llintrinsicsmod) == False) {
+ if (llvm::LLVMLinkModules(llmod, llintrinsicsmod) == False) {
llvm_err(sess, "couldn't link the module with the intrinsics");
fail;
}
// 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 dot_pos = _str::index(output_path, '.' as u8);
auto stem;
if (dot_pos < 0) {
stem = output_path;
} else {
- stem = Str.substr(output_path, 0u, dot_pos as uint);
+ stem = _str::substr(output_path, 0u, dot_pos as uint);
}
ret stem + "." + extension;
}
- fn run_passes(session.session sess, ModuleRef llmod, str output) {
+ fn run_passes(session::session sess, ModuleRef llmod, str output) {
auto opts = sess.get_opts();
if (opts.time_llvm_passes) {
- llvm.LLVMRustEnableTimePasses();
+ llvm::LLVMRustEnableTimePasses();
}
link_intrinsics(sess, llmod);
auto pm = mk_pass_manager();
- auto td = mk_target_data(x86.get_data_layout());
- llvm.LLVMAddTargetData(td.lltd, pm.llpm);
+ auto 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.
if (opts.optimize) {
auto filename = mk_intermediate_name(output,
"no-opt.bc");
- llvm.LLVMWriteBitcodeToFile(llmod,
- Str.buf(filename));
+ llvm::LLVMWriteBitcodeToFile(llmod,
+ _str::buf(filename));
}
}
case (_) {
auto filename = mk_intermediate_name(output, "bc");
- llvm.LLVMWriteBitcodeToFile(llmod, Str.buf(filename));
+ llvm::LLVMWriteBitcodeToFile(llmod, _str::buf(filename));
}
}
}
// tool?
if (opts.optimize) {
auto fpm = mk_pass_manager();
- llvm.LLVMAddTargetData(td.lltd, fpm.llpm);
- llvm.LLVMAddStandardFunctionPasses(fpm.llpm, 2u);
- llvm.LLVMRunPassManager(fpm.llpm, llmod);
+ llvm::LLVMAddTargetData(td.lltd, fpm.llpm);
+ llvm::LLVMAddStandardFunctionPasses(fpm.llpm, 2u);
+ llvm::LLVMRunPassManager(fpm.llpm, llmod);
// TODO: On -O3, use 275 instead of 225 for the inlining
// threshold.
- llvm.LLVMAddStandardModulePasses(pm.llpm,
+ llvm::LLVMAddStandardModulePasses(pm.llpm,
2u, // optimization level
False, // optimize for size
True, // unit-at-a-time
}
if (opts.verify) {
- llvm.LLVMAddVerifierPass(pm.llpm);
+ llvm::LLVMAddVerifierPass(pm.llpm);
}
// TODO: Write .s if -c was specified and -save-temps was on.
case (_) {
auto filename = mk_intermediate_name(output,
"opt.bc");
- llvm.LLVMRunPassManager(pm.llpm, llmod);
- llvm.LLVMWriteBitcodeToFile(llmod,
- Str.buf(filename));
+ llvm::LLVMRunPassManager(pm.llpm, llmod);
+ llvm::LLVMWriteBitcodeToFile(llmod,
+ _str::buf(filename));
pm = mk_pass_manager();
}
}
}
- llvm.LLVMRustWriteOutputFile(pm.llpm, llmod,
- Str.buf(x86.get_target_triple()),
- Str.buf(output),
+ llvm::LLVMRustWriteOutputFile(pm.llpm, llmod,
+ _str::buf(x86::get_target_triple()),
+ _str::buf(output),
FileType);
- llvm.LLVMDisposeModule(llmod);
+ llvm::LLVMDisposeModule(llmod);
if (opts.time_llvm_passes) {
- llvm.LLVMRustPrintPassTimings();
+ llvm::LLVMRustPrintPassTimings();
}
ret;
}
- llvm.LLVMRunPassManager(pm.llpm, llmod);
+ llvm::LLVMRunPassManager(pm.llpm, llmod);
- llvm.LLVMWriteBitcodeToFile(llmod, Str.buf(output));
- llvm.LLVMDisposeModule(llmod);
+ llvm::LLVMWriteBitcodeToFile(llmod, _str::buf(output));
+ llvm::LLVMDisposeModule(llmod);
if (opts.time_llvm_passes) {
- llvm.LLVMRustPrintPassTimings();
+ llvm::LLVMRustPrintPassTimings();
}
}
}
const int rc_base_field_refcnt = 0;
-// FIXME: import from std.dbg when imported consts work.
+// FIXME: import from std::dbg when imported consts work.
const uint const_refcount = 0x7bad_face_u;
const int task_field_refcnt = 0;
case (ngt_pure_rust) { prefix = "rust_native_pure_rust_"; }
case (ngt_cdecl) { prefix = "rust_native_cdecl_"; }
}
- ret prefix + util.common.istr(n);
+ ret prefix + util::common::istr(n);
}
fn activate_glue_name() -> str {
-import middle.trans;
+import middle::trans;
-import trans.decl_cdecl_fn;
-import trans.type_names;
-import trans.ModuleRef;
-import trans.TypeRef;
-import trans.ValueRef;
+import trans::decl_cdecl_fn;
+import trans::type_names;
+import trans::ModuleRef;
+import trans::TypeRef;
+import trans::ValueRef;
-import trans.T_crate;
-import trans.T_f32;
-import trans.T_f64;
-import trans.T_fn;
-import trans.T_i8;
-import trans.T_i32;
-import trans.T_int;
-import trans.T_opaque_chan_ptr;
-import trans.T_opaque_port_ptr;
-import trans.T_opaque_vec_ptr;
-import trans.T_ptr;
-import trans.T_size_t;
-import trans.T_str;
-import trans.T_taskptr;
-import trans.T_tydesc;
-import trans.T_void;
+import trans::T_crate;
+import trans::T_f32;
+import trans::T_f64;
+import trans::T_fn;
+import trans::T_i8;
+import trans::T_i32;
+import trans::T_int;
+import trans::T_opaque_chan_ptr;
+import trans::T_opaque_port_ptr;
+import trans::T_opaque_vec_ptr;
+import trans::T_ptr;
+import trans::T_size_t;
+import trans::T_str;
+import trans::T_taskptr;
+import trans::T_tydesc;
+import trans::T_void;
type upcalls = rec(
ValueRef grow_task,
let vec[TypeRef] arg_tys = vec(T_taskptr(tn));
for (TypeRef t in tys) { arg_tys += vec(t); }
auto fn_ty = T_fn(arg_tys, rv);
- ret trans.decl_cdecl_fn(llmod, "upcall_" + name, fn_ty);
+ ret trans::decl_cdecl_fn(llmod, "upcall_" + name, fn_ty);
}
auto dv = bind decl(tn, llmod, _, _, T_void());
auto d = bind decl(tn, llmod, _, _, _);
- // FIXME: Sigh... remove this when I fix the typechecker pushdown.
+ // FIXME: Sigh:.. remove this when I fix the typechecker pushdown.
// --pcwalton
let vec[TypeRef] empty_vec = vec();
-import lib.llvm.llvm;
-import lib.llvm.llvm.ModuleRef;
-import std.Str;
-import std.Vec;
-import std.OS.target_os;
-import util.common.istr;
+import lib::llvm::llvm;
+import lib::llvm::llvm::ModuleRef;
+import std::_str;
+import std::_vec;
+import std::os::target_os;
+import util::common::istr;
const int wordsz = 4;
}
fn load_esp_from_rust_sp_first_arg() -> vec[str] {
- ret vec("movl " + wstr(abi.task_field_rust_sp) + "(%ecx), %esp");
+ ret vec("movl " + wstr(abi::task_field_rust_sp) + "(%ecx), %esp");
}
fn load_esp_from_runtime_sp_first_arg() -> vec[str] {
- ret vec("movl " + wstr(abi.task_field_runtime_sp) + "(%ecx), %esp");
+ ret vec("movl " + wstr(abi::task_field_runtime_sp) + "(%ecx), %esp");
}
fn store_esp_to_rust_sp_first_arg() -> vec[str] {
- ret vec("movl %esp, " + wstr(abi.task_field_rust_sp) + "(%ecx)");
+ ret vec("movl %esp, " + wstr(abi::task_field_rust_sp) + "(%ecx)");
}
fn store_esp_to_runtime_sp_first_arg() -> vec[str] {
- ret vec("movl %esp, " + wstr(abi.task_field_runtime_sp) + "(%ecx)");
+ ret vec("movl %esp, " + wstr(abi::task_field_runtime_sp) + "(%ecx)");
}
fn load_esp_from_rust_sp_second_arg() -> vec[str] {
- ret vec("movl " + wstr(abi.task_field_rust_sp) + "(%edx), %esp");
+ ret vec("movl " + wstr(abi::task_field_rust_sp) + "(%edx), %esp");
}
fn load_esp_from_runtime_sp_second_arg() -> vec[str] {
- ret vec("movl " + wstr(abi.task_field_runtime_sp) + "(%edx), %esp");
+ ret vec("movl " + wstr(abi::task_field_runtime_sp) + "(%edx), %esp");
}
fn store_esp_to_rust_sp_second_arg() -> vec[str] {
- ret vec("movl %esp, " + wstr(abi.task_field_rust_sp) + "(%edx)");
+ ret vec("movl %esp, " + wstr(abi::task_field_rust_sp) + "(%edx)");
}
fn store_esp_to_runtime_sp_second_arg() -> vec[str] {
- ret vec("movl %esp, " + wstr(abi.task_field_runtime_sp) + "(%edx)");
+ ret vec("movl %esp, " + wstr(abi::task_field_runtime_sp) + "(%edx)");
}
* will be a no-op. Esp won't move, and the task's stack won't
* grow.
*/
- + vec("addl $20, " + wstr(abi.task_field_rust_sp) + "(%ecx)")
+ + vec("addl $20, " + wstr(abi::task_field_rust_sp) + "(%ecx)")
/*
+ vec("ret");
}
-fn native_glue(int n_args, abi.native_glue_type ngt) -> vec[str] {
+fn native_glue(int n_args, abi::native_glue_type ngt) -> vec[str] {
let bool pass_task;
alt (ngt) {
- case (abi.ngt_rust) { pass_task = true; }
- case (abi.ngt_pure_rust) { pass_task = true; }
- case (abi.ngt_cdecl) { pass_task = false; }
+ case (abi::ngt_rust) { pass_task = true; }
+ case (abi::ngt_pure_rust) { pass_task = true; }
+ case (abi::ngt_cdecl) { pass_task = false; }
}
/*
}
auto m = vec("movl " + src_off + "(%ebp),%eax",
"movl %eax," + dst_off + "(%esp)");
- ret Str.connect(m, "\n\t");
+ ret _str::connect(m, "\n\t");
}
auto carg = bind copy_arg(pass_task, _);
+ vec("subl $" + wstr(n_args) + ", %esp # esp -= args",
"andl $~0xf, %esp # align esp down")
- + Vec.init_fn[str](carg, (n_args) as uint)
+ + _vec::init_fn[str](carg, (n_args) as uint)
+ vec("movl %edx, %edi # save task from edx to edi",
"call *%ecx # call *%ecx",
ret "\t.globl " + sym + "\n" +
"\t.balign " + istr(align) + "\n" +
sym + ":\n" +
- "\t" + Str.connect(insns, "\n\t");
+ "\t" + _str::connect(insns, "\n\t");
}
-fn decl_native_glue(int align, str prefix, abi.native_glue_type ngt, uint n)
+fn decl_native_glue(int align, str prefix, abi::native_glue_type ngt, uint n)
-> str {
let int i = n as int;
ret decl_glue(align, prefix,
- abi.native_glue_name(i, ngt),
+ abi::native_glue_name(i, ngt),
native_glue(i, ngt));
}
fn get_symbol_prefix() -> str {
- if (Str.eq(target_os(), "macos") ||
- Str.eq(target_os(), "win32")) {
+ if (_str::eq(target_os(), "macos") ||
+ _str::eq(target_os(), "win32")) {
ret "_";
} else {
ret "";
auto glues =
vec(decl_glue(align, prefix,
- abi.activate_glue_name(),
+ abi::activate_glue_name(),
rust_activate_glue()),
decl_glue(align, prefix,
- abi.yield_glue_name(),
+ abi::yield_glue_name(),
rust_yield_glue()))
- + Vec.init_fn[str](bind decl_native_glue(align, prefix,
- abi.ngt_rust, _), (abi.n_native_glues + 1) as uint)
- + Vec.init_fn[str](bind decl_native_glue(align, prefix,
- abi.ngt_pure_rust, _), (abi.n_native_glues + 1) as uint)
- + Vec.init_fn[str](bind decl_native_glue(align, prefix,
- abi.ngt_cdecl, _), (abi.n_native_glues + 1) as uint);
+ + _vec::init_fn[str](bind decl_native_glue(align, prefix,
+ abi::ngt_rust, _), (abi::n_native_glues + 1) as uint)
+ + _vec::init_fn[str](bind decl_native_glue(align, prefix,
+ abi::ngt_pure_rust, _), (abi::n_native_glues + 1) as uint)
+ + _vec::init_fn[str](bind decl_native_glue(align, prefix,
+ abi::ngt_cdecl, _), (abi::n_native_glues + 1) as uint);
- ret Str.connect(glues, "\n\n");
+ ret _str::connect(glues, "\n\n");
}
fn get_meta_sect_name() -> str {
- if (Str.eq(target_os(), "macos")) {
+ if (_str::eq(target_os(), "macos")) {
ret "__DATA,__note.rustc";
}
- if (Str.eq(target_os(), "win32")) {
+ 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")) {
+ if (_str::eq(target_os(), "macos")) {
ret "i686-apple-darwin";
}
- if (Str.eq(target_os(), "win32")) {
+ if (_str::eq(target_os(), "win32")) {
ret "i686-pc-mingw32";
}
ret "i686-unknown-linux-gnu";
// -*- rust -*-
-import front.creader;
-import front.parser;
-import front.token;
-import front.eval;
-import front.ast;
-import middle.trans;
-import middle.resolve;
-import middle.capture;
-import middle.ty;
-import middle.typeck;
-import middle.typestate_check;
-import back.Link;
-import lib.llvm;
-import util.common;
-
-import std.FS;
-import std.Map.mk_hashmap;
-import std.Option;
-import std.Option.some;
-import std.Option.none;
-import std.Str;
-import std.Vec;
-import std.IO;
-import std.Time;
-
-import std.GetOpts;
-import std.GetOpts.optopt;
-import std.GetOpts.optmulti;
-import std.GetOpts.optflag;
-import std.GetOpts.opt_present;
-
-import back.Link.output_type;
-
-fn default_environment(session.session sess,
+import front::creader;
+import front::parser;
+import front::token;
+import front::eval;
+import front::ast;
+import middle::trans;
+import middle::resolve;
+import middle::capture;
+import middle::ty;
+import middle::typeck;
+import middle::typestate_check;
+import back::Link;
+import lib::llvm;
+import util::common;
+
+import std::fs;
+import std::map::mk_hashmap;
+import std::option;
+import std::option::some;
+import std::option::none;
+import std::_str;
+import std::_vec;
+import std::io;
+
+import std::getopts;
+import std::getopts::optopt;
+import std::getopts::optmulti;
+import std::getopts::optflag;
+import std::getopts::opt_present;
+
+import back::Link::output_type;
+
+fn default_environment(session::session sess,
str argv0,
- str input) -> eval.env {
+ str input) -> eval::env {
- auto libc = "libc.so";
+ auto libc = "libc::so";
alt (sess.get_targ_cfg().os) {
- case (session.os_win32) { libc = "msvcrt.dll"; }
- case (session.os_macos) { libc = "libc.dylib"; }
- case (session.os_linux) { libc = "libc.so.6"; }
+ case (session::os_win32) { libc = "msvcrt.dll"; }
+ case (session::os_macos) { libc = "libc::dylib"; }
+ case (session::os_linux) { libc = "libc::so.6"; }
}
ret
vec(
// Target bindings.
- tup("target_os", eval.val_str(std.OS.target_os())),
- tup("target_arch", eval.val_str("x86")),
- tup("target_libc", eval.val_str(libc)),
+ tup("target_os", eval::val_str(std::os::target_os())),
+ tup("target_arch", eval::val_str("x86")),
+ tup("target_libc", eval::val_str(libc)),
// Build bindings.
- tup("build_compiler", eval.val_str(argv0)),
- tup("build_input", eval.val_str(input))
+ tup("build_compiler", eval::val_str(argv0)),
+ tup("build_input", eval::val_str(input))
);
}
-fn parse_input(session.session sess,
- parser.parser p,
- str input) -> @ast.crate {
- if (Str.ends_with(input, ".rc")) {
- ret parser.parse_crate_from_crate_file(p);
- } else if (Str.ends_with(input, ".rs")) {
- ret parser.parse_crate_from_source_file(p);
+fn parse_input(session::session sess,
+ parser::parser p,
+ str input) -> @ast::crate {
+ if (_str::ends_with(input, ".rc")) {
+ ret parser::parse_crate_from_crate_file(p);
+ } else if (_str::ends_with(input, ".rs")) {
+ ret parser::parse_crate_from_source_file(p);
}
sess.err("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 = Time.get_time();
+ auto start = std::time::get_time();
auto rv = thunk();
- auto end = Time.get_time();
+ auto 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,
- eval.env env,
+fn compile_input(session::session sess,
+ eval::env env,
str input, str output) {
auto time_passes = sess.get_opts().time_passes;
- auto def = tup(ast.local_crate, 0);
- auto p = parser.new_parser(sess, env, def, input, 0u, 0u);
+ auto def = tup(ast::local_crate, 0);
+ auto p = parser::new_parser(sess, env, def, input, 0u, 0u);
auto crate = time(time_passes, "parsing",
bind parse_input(sess, p, input));
- if (sess.get_opts().output_type == Link.output_type_none) {ret;}
+ if (sess.get_opts().output_type == Link::output_type_none) {ret;}
crate = time(time_passes, "external crate reading",
- bind creader.read_crates(sess, crate));
+ bind creader::read_crates(sess, crate));
auto res = time(time_passes, "resolution",
- bind resolve.resolve_crate(sess, crate));
+ bind resolve::resolve_crate(sess, crate));
crate = res._0;
auto def_map = res._1;
time[()](time_passes, "capture checking",
- bind capture.check_for_captures(sess, crate, def_map));
+ bind capture::check_for_captures(sess, crate, def_map));
- auto ty_cx = ty.mk_ctxt(sess, def_map);
+ auto ty_cx = ty::mk_ctxt(sess, def_map);
auto typeck_result =
- time[typeck.typecheck_result](time_passes, "typechecking",
- bind typeck.check_crate(ty_cx, crate));
+ time[typeck::typecheck_result](time_passes, "typechecking",
+ bind typeck::check_crate(ty_cx, crate));
crate = typeck_result._0;
auto type_cache = typeck_result._1;
if (sess.get_opts().run_typestate) {
crate = time(time_passes, "typestate checking",
- bind typestate_check.check_crate(crate, def_map));
+ bind typestate_check::check_crate(crate, def_map));
}
- auto llmod = time[llvm.ModuleRef](time_passes, "translation",
- bind trans.trans_crate(sess, crate, ty_cx, type_cache, output));
+ auto llmod = time[llvm::ModuleRef](time_passes, "translation",
+ bind trans::trans_crate(sess, crate, ty_cx, type_cache, output));
time[()](time_passes, "LLVM passes",
- bind Link.Write.run_passes(sess, llmod, output));
+ bind Link::Write::run_passes(sess, llmod, output));
}
-fn pretty_print_input(session.session sess,
- eval.env env,
+fn pretty_print_input(session::session sess,
+ eval::env env,
str input) {
- auto def = tup(ast.local_crate, 0);
- auto p = front.parser.new_parser(sess, env, def, input, 0u, 0u);
- auto crate = front.parser.parse_crate_from_source_file(p);
- pretty.pprust.print_file(sess, crate.node.module, input, std.IO.stdout());
+ auto def = tup(ast::local_crate, 0);
+ auto p = front::parser::new_parser(sess, env, def, input, 0u, 0u);
+ auto crate = front::parser::parse_crate_from_source_file(p);
+ pretty::pprust::print_file(sess, crate.node.module, input,
+ std::io::stdout());
}
fn version(str argv0) {
auto vers = "unknown version";
auto env_vers = #env("CFG_VERSION");
- if (Str.byte_len(env_vers) != 0u) {
+ if (_str::byte_len(env_vers) != 0u) {
vers = env_vers;
}
- IO.stdout().write_str(#fmt("%s %s\n", argv0, vers));
+ io::stdout().write_str(#fmt("%s %s\n", argv0, vers));
}
fn usage(str argv0) {
- IO.stdout().write_str(#fmt("usage: %s [options] <input>\n", argv0) + "
+ io::stdout().write_str(#fmt("usage: %s [options] <input>\n", argv0) + "
options:
-h --help display this message
--no-typestate don't run the typestate pass (unsafe!)\n\n");
}
-fn get_os(str triple) -> session.os {
- if (Str.find(triple, "win32") > 0 ||
- Str.find(triple, "mingw32") > 0 ) {
- ret session.os_win32;
- } else if (Str.find(triple, "darwin") > 0) { ret session.os_macos; }
- else if (Str.find(triple, "linux") > 0) { ret session.os_linux; }
+fn get_os(str triple) -> session::os {
+ if (_str::find(triple, "win32") > 0 ||
+ _str::find(triple, "mingw32") > 0 ) {
+ ret session::os_win32;
+ } else if (_str::find(triple, "darwin") > 0) { ret session::os_macos; }
+ else if (_str::find(triple, "linux") > 0) { ret session::os_linux; }
}
-fn get_arch(str triple) -> session.arch {
- 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 ) {
- ret session.arch_x86;
- } else if (Str.find(triple, "x86_64") > 0) {
- ret session.arch_x64;
- } else if (Str.find(triple, "arm") > 0 ||
- Str.find(triple, "xscale") > 0 ) {
- ret session.arch_arm;
+fn get_arch(str triple) -> session::arch {
+ 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 ) {
+ ret session::arch_x86;
+ } else if (_str::find(triple, "x86_64") > 0) {
+ ret session::arch_x64;
+ } else if (_str::find(triple, "arm") > 0 ||
+ _str::find(triple, "xscale") > 0 ) {
+ ret session::arch_arm;
}
}
fn get_default_sysroot(str binary) -> str {
- auto dirname = FS.dirname(binary);
- if (Str.eq(dirname, binary)) { ret "."; }
+ auto dirname = fs::dirname(binary);
+ if (_str::eq(dirname, binary)) { ret "."; }
ret dirname;
}
fn main(vec[str] args) {
let str triple =
- std.Str.rustrt.str_from_cstr(llvm.llvm.LLVMRustGetHostTriple());
+ std::_str::rustrt::str_from_cstr(llvm::llvm::LLVMRustGetHostTriple());
- let @session.config target_cfg =
+ let @session::config target_cfg =
@rec(os = get_os(triple),
arch = get_arch(triple),
- int_type = common.ty_i32,
- uint_type = common.ty_u32,
- float_type = common.ty_f64);
+ int_type = common::ty_i32,
+ uint_type = common::ty_u32,
+ float_type = common::ty_f64);
auto opts = vec(optflag("h"), optflag("help"),
optflag("v"), optflag("version"),
optflag("save-temps"), optopt("sysroot"),
optflag("time-passes"), optflag("time-llvm-passes"),
optflag("no-typestate"), optflag("noverify"));
- auto binary = Vec.shift[str](args);
+ auto binary = _vec::shift[str](args);
auto match;
- alt (GetOpts.getopts(args, opts)) {
- case (GetOpts.failure(?f)) {
- log_err #fmt("error: %s", GetOpts.fail_str(f));
+ alt (getopts::getopts(args, opts)) {
+ case (getopts::failure(?f)) {
+ log_err #fmt("error: %s", getopts::fail_str(f));
fail;
}
- case (GetOpts.success(?m)) { match = m; }
+ case (getopts::success(?m)) { match = m; }
}
if (opt_present(match, "h") ||
opt_present(match, "help")) {
auto ls = opt_present(match, "ls");
auto glue = opt_present(match, "glue");
auto shared = opt_present(match, "shared");
- auto output_file = GetOpts.opt_maybe_str(match, "o");
- auto library_search_paths = GetOpts.opt_strs(match, "L");
+ auto output_file = getopts::opt_maybe_str(match, "o");
+ auto library_search_paths = getopts::opt_strs(match, "L");
- auto output_type = Link.output_type_bitcode;
+ auto output_type = Link::output_type_bitcode;
if (opt_present(match, "parse-only")) {
- output_type = Link.output_type_none;
+ output_type = Link::output_type_none;
} else if (opt_present(match, "S")) {
- output_type = Link.output_type_assembly;
+ output_type = Link::output_type_assembly;
} else if (opt_present(match, "c")) {
- output_type = Link.output_type_object;
+ output_type = Link::output_type_object;
}
auto verify = !opt_present(match, "noverify");
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");
+ auto sysroot_opt = getopts::opt_maybe_str(match, "sysroot");
auto sysroot;
alt (sysroot_opt) {
case (some[str](?s)) { sysroot = s; }
}
- let @session.options sopts =
+ let @session::options sopts =
@rec(shared = shared,
optimize = optimize,
debuginfo = debuginfo,
library_search_paths = library_search_paths,
sysroot = sysroot);
- auto crate_cache = common.new_int_hash[session.crate_metadata]();
+ auto crate_cache = common::new_int_hash[session::crate_metadata]();
auto target_crate_num = 0;
- let vec[@ast.meta_item] md = vec();
+ let vec[@ast::meta_item] md = vec();
auto sess =
- session.session(target_crate_num, target_cfg, sopts,
- crate_cache, md, front.codemap.new_codemap());
+ session::session(target_crate_num, target_cfg, sopts,
+ crate_cache, md, front::codemap::new_codemap());
- auto n_inputs = Vec.len[str](match.free);
+ auto n_inputs = _vec::len[str](match.free);
if (glue) {
if (n_inputs > 0u) {
sess.err("No input files allowed with --glue.");
}
- auto out = Option.from_maybe[str]("glue.bc", output_file);
- middle.trans.make_common_glue(sess, out);
+ auto out = option::from_maybe[str]("glue.bc", output_file);
+ middle::trans::make_common_glue(sess, out);
ret;
}
if (pretty) {
pretty_print_input(sess, env, ifile);
} else if (ls) {
- front.creader.list_file_metadata(ifile, std.IO.stdout());
+ front::creader::list_file_metadata(ifile, std::io::stdout());
} else {
alt (output_file) {
case (none[str]) {
- let vec[str] parts = Str.split(ifile, '.' as u8);
- Vec.pop[str](parts);
+ let vec[str] parts = _str::split(ifile, '.' as u8);
+ _vec::pop[str](parts);
alt (output_type) {
- case (Link.output_type_none) { parts += vec("pp"); }
- case (Link.output_type_bitcode) { parts += vec("bc"); }
- case (Link.output_type_assembly) { parts += vec("s"); }
- case (Link.output_type_object) { parts += vec("o"); }
+ case (Link::output_type_none) { parts += vec("pp"); }
+ case (Link::output_type_bitcode) { parts += vec("bc"); }
+ case (Link::output_type_assembly) { parts += vec("s"); }
+ case (Link::output_type_object) { parts += vec("o"); }
}
- auto ofile = Str.connect(parts, ".");
+ auto ofile = _str::connect(parts, ".");
compile_input(sess, env, ifile, ofile);
}
case (some[str](?ofile)) {
-import front.ast;
-import front.codemap;
-import util.common.span;
-import util.common.ty_mach;
-import std.UInt;
-import std.Term;
-import std.IO;
-import std.Map;
+import front::ast;
+import front::codemap;
+import util::common::span;
+import util::common::ty_mach;
+import std::_uint;
+import std::term;
+import std::io;
+import std::map;
tag os {
os_win32;
bool save_temps,
bool time_passes,
bool time_llvm_passes,
- back.Link.output_type output_type,
+ back::Link::output_type output_type,
vec[str] library_search_paths,
str sysroot);
type crate_metadata = rec(str name,
vec[u8] data);
-fn emit_diagnostic(span sp, str msg, str kind, u8 color, codemap.codemap cm) {
- auto lo = codemap.lookup_pos(cm, sp.lo);
- auto hi = codemap.lookup_pos(cm, sp.hi);
- IO.stdout().write_str(#fmt("%s:%u:%u:%u:%u: ", lo.filename, lo.line,
+fn emit_diagnostic(span sp, str msg, str kind, u8 color,
+ codemap::codemap cm) {
+ auto lo = codemap::lookup_pos(cm, sp.lo);
+ auto hi = codemap::lookup_pos(cm, sp.hi);
+ io::stdout().write_str(#fmt("%s:%u:%u:%u:%u: ", lo.filename, lo.line,
lo.col, hi.line, hi.col));
- if (Term.color_supported()) {
- Term.fg(IO.stdout().get_buf_writer(), color);
+ if (term::color_supported()) {
+ term::fg(io::stdout().get_buf_writer(), color);
}
- IO.stdout().write_str(#fmt("%s:", kind));
+ io::stdout().write_str(#fmt("%s:", kind));
- if (Term.color_supported()) {
- Term.reset(IO.stdout().get_buf_writer());
+ if (term::color_supported()) {
+ term::reset(io::stdout().get_buf_writer());
}
- IO.stdout().write_str(#fmt(" %s\n", msg));
+ io::stdout().write_str(#fmt(" %s\n", msg));
}
-state obj session(ast.crate_num cnum,
+state obj session(ast::crate_num cnum,
@config targ_cfg, @options opts,
- Map.hashmap[int, crate_metadata] crates,
- mutable vec[@ast.meta_item] metadata,
- codemap.codemap cm) {
+ map::hashmap[int, crate_metadata] crates,
+ mutable vec[@ast::meta_item] metadata,
+ codemap::codemap cm) {
fn get_targ_cfg() -> @config {
ret targ_cfg;
ret opts;
}
- fn get_targ_crate_num() -> ast.crate_num {
+ fn get_targ_crate_num() -> ast::crate_num {
ret cnum;
}
fail;
}
- fn add_metadata(vec[@ast.meta_item] data) {
+ fn add_metadata(vec[@ast::meta_item] data) {
metadata = metadata + data;
}
- fn get_metadata() -> vec[@ast.meta_item] {
+ fn get_metadata() -> vec[@ast::meta_item] {
ret metadata;
}
ret crates.contains_key(num);
}
- fn get_codemap() -> codemap.codemap {
+ fn get_codemap() -> codemap::codemap {
ret cm;
}
- fn lookup_pos(uint pos) -> codemap.loc {
- ret codemap.lookup_pos(cm, pos);
+ fn lookup_pos(uint pos) -> codemap::loc {
+ ret codemap::lookup_pos(cm, pos);
}
}
-import std.Map.hashmap;
-import std.Option;
-import std.Str;
-import std.Vec;
-import util.common.span;
-import util.common.spanned;
-import util.common.ty_mach;
-import util.common.filename;
-import util.typestate_ann.ts_ann;
+import std::map::hashmap;
+import std::option;
+import std::_str;
+import std::_vec;
+import util::common::span;
+import util::common::spanned;
+import util::common::ty_mach;
+import util::common::filename;
+import util::typestate_ann::ts_ann;
type ident = str;
tag ann {
ann_none(uint);
ann_type(uint,
- middle.ty.t,
- Option.t[vec[middle.ty.t]], /* ty param substs */
- Option.t[@ts_ann]); /* pre- and postcondition for typestate */
+ middle::ty::t,
+ option::t[vec[middle::ty::t]], /* ty param substs */
+ option::t[@ts_ann]); /* pre- and postcondition for typestate */
}
fn ann_tag(&ann a) -> uint {
// and redirected to the use of const stmt_decls inside
// crate directive blocks.
cdir_let(ident, @expr, vec[@crate_directive]);
- cdir_src_mod(ident, Option.t[filename]);
- cdir_dir_mod(ident, Option.t[filename], vec[@crate_directive]);
+ cdir_src_mod(ident, option::t[filename]);
+ cdir_dir_mod(ident, option::t[filename], vec[@crate_directive]);
cdir_view_item(@view_item);
cdir_meta(vec[@meta_item]);
cdir_syntax(path);
type block = spanned[block_];
type block_ = rec(vec[@stmt] stmts,
- Option.t[@expr] expr,
+ option::t[@expr] expr,
ann a); /* ann is only meaningful for the ts_ann field */
type pat = spanned[pat_];
type initializer = rec(init_op op,
@expr expr);
-type local = rec(Option.t[@ty] ty,
+type local = rec(option::t[@ty] ty,
bool infer,
ident ident,
- Option.t[initializer] init,
+ option::t[initializer] init,
def_id id,
ann ann);
tag expr_ {
expr_vec(vec[@expr], mutability, ann);
expr_tup(vec[elt], ann);
- expr_rec(vec[field], Option.t[@expr], ann);
+ expr_rec(vec[field], option::t[@expr], ann);
expr_call(@expr, vec[@expr], ann);
expr_self_method(ident, ann);
- expr_bind(@expr, vec[Option.t[@expr]], ann);
- expr_spawn(spawn_dom, Option.t[str], @expr, vec[@expr], ann);
+ expr_bind(@expr, vec[option::t[@expr]], ann);
+ expr_spawn(spawn_dom, option::t[str], @expr, vec[@expr], ann);
expr_binary(binop, @expr, @expr, ann);
expr_unary(unop, @expr, ann);
expr_lit(@lit, ann);
expr_cast(@expr, @ty, ann);
- expr_if(@expr, block, Option.t[@expr], ann);
+ expr_if(@expr, block, option::t[@expr], ann);
expr_while(@expr, block, ann);
expr_for(@decl, @expr, block, ann);
expr_for_each(@decl, @expr, block, ann);
expr_field(@expr, ident, ann);
expr_index(@expr, @expr, ann);
expr_path(path, ann);
- expr_ext(path, vec[@expr], Option.t[str], @expr, ann);
+ expr_ext(path, vec[@expr], option::t[str], @expr, ann);
expr_fail(ann);
expr_break(ann);
expr_cont(ann);
- expr_ret(Option.t[@expr], ann);
- expr_put(Option.t[@expr], ann);
+ expr_ret(option::t[@expr], ann);
+ expr_put(option::t[@expr], ann);
expr_be(@expr, ann);
expr_log(int, @expr, ann);
/* just an assert, no significance to typestate */
ty_int;
ty_uint;
ty_float;
- ty_machine(util.common.ty_mach);
+ ty_machine(util::common::ty_mach);
ty_char;
ty_str;
ty_box(mt);
proto proto,
block body);
-
type method_ = rec(ident ident, _fn meth, def_id id, ann ann);
type method = spanned[method_];
type obj_field = rec(@ty ty, ident ident, def_id id, ann ann);
type _obj = rec(vec[obj_field] fields,
vec[@method] methods,
- Option.t[@method] dtor);
+ option::t[@method] dtor);
type _mod = rec(vec[@view_item] view_items,
vec[@item] items);
type view_item = spanned[view_item_];
tag view_item_ {
- view_item_use(ident, vec[@meta_item], def_id, Option.t[int]);
+ view_item_use(ident, vec[@meta_item], def_id, option::t[int]);
view_item_import(ident, vec[ident], def_id);
view_item_export(ident);
}
type native_item = spanned[native_item_];
tag native_item_ {
native_item_ty(ident, def_id);
- native_item_fn(ident, Option.t[str],
+ native_item_fn(ident, option::t[str],
fn_decl, vec[ty_param], def_id, ann);
}
fn is_exported(ident i, _mod m) -> bool {
auto count = 0;
- for (@ast.view_item vi in m.view_items) {
+ for (@ast::view_item vi in m.view_items) {
alt (vi.node) {
- case (ast.view_item_export(?id)) {
- if (Str.eq(i, id)) {
+ case (ast::view_item_export(?id)) {
+ if (_str::eq(i, id)) {
ret true;
}
count += 1;
-import std.Vec;
+import std::_vec;
/* 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
}
fn next_line(filemap file, uint pos) {
- Vec.push[uint](file.lines, pos);
+ _vec::push[uint](file.lines, pos);
}
fn lookup_pos(codemap map, uint pos) -> loc {
- auto a = 0u; auto b = Vec.len[filemap](map.files);
+ auto a = 0u; auto b = _vec::len[filemap](map.files);
while (b - a > 1u) {
auto m = (a + b) / 2u;
if (map.files.(m).start_pos > pos) { b = m; }
else { a = m; }
}
auto f = map.files.(a);
- a = 0u; b = Vec.len[uint](f.lines);
+ a = 0u; b = _vec::len[uint](f.lines);
while (b - a > 1u) {
auto m = (a + b) / 2u;
if (f.lines.(m) > pos) { b = m; }
// -*- rust -*-
-import driver.session;
-import front.ast;
-import lib.llvm.False;
-import lib.llvm.llvm;
-import lib.llvm.mk_object_file;
-import lib.llvm.mk_section_iter;
-import middle.fold;
-import middle.metadata;
-import middle.trans;
-import middle.ty;
-import back.x86;
-import util.common;
-import util.common.span;
-
-import std.Str;
-import std.UInt;
-import std.Vec;
-import std.EBML;
-import std.FS;
-import std.IO;
-import std.Option;
-import std.Option.none;
-import std.Option.some;
-import std.OS;
-import std.Map.hashmap;
+import driver::session;
+import front::ast;
+import lib::llvm::False;
+import lib::llvm::llvm;
+import lib::llvm::mk_object_file;
+import lib::llvm::mk_section_iter;
+import middle::fold;
+import middle::metadata;
+import middle::trans;
+import middle::ty;
+import back::x86;
+import util::common;
+import util::common::span;
+
+import std::_str;
+import std::_uint;
+import std::_vec;
+import std::ebml;
+import std::fs;
+import std::io;
+import std::option;
+import std::option::none;
+import std::option::some;
+import std::os;
+import std::map::hashmap;
// TODO: map to a real type here.
type env = @rec(
- session.session sess,
+ session::session sess,
@hashmap[str, int] crate_cache,
vec[str] library_search_paths,
mutable int next_crate_num
);
tag resolve_result {
- rr_ok(ast.def_id);
- rr_not_found(ast.ident);
+ rr_ok(ast::def_id);
+ rr_not_found(ast::ident);
}
// Type decoding
-// Compact string representation for ty.t values. API ty_str & parse_from_str.
+// Compact string representation for ty::t values. API ty_str & parse_from_str
// (The second has to be authed pure.) Extra parameters are for converting
// to/from def_ids in the data buffer. Whatever format you choose should not
// contain pipe characters.
-// Callback to translate defs to strs or back.
-type str_def = fn(str) -> ast.def_id;
+// Callback to translate defs to strs or back:
+type str_def = fn(str) -> ast::def_id;
type pstate = rec(vec[u8] data, int crate,
- mutable uint pos, uint len, ty.ctxt tcx);
+ mutable uint pos, uint len, ty::ctxt tcx);
fn peek(@pstate st) -> u8 {
ret st.data.(st.pos);
}
fn parse_ty_data(vec[u8] data, int crate_num, uint pos, uint len,
- str_def sd, ty.ctxt tcx) -> ty.t {
+ 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);
ret result;
}
-fn parse_ty(@pstate st, str_def sd) -> ty.t {
+fn parse_ty(@pstate st, str_def sd) -> ty::t {
alt (next(st) as char) {
- case ('n') { ret ty.mk_nil(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 ('n') { ret ty::mk_nil(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, common.ty_u8); }
- case ('w') { ret ty.mk_mach(st.tcx, common.ty_u16); }
- case ('l') { ret ty.mk_mach(st.tcx, common.ty_u32); }
- case ('d') { ret ty.mk_mach(st.tcx, common.ty_u64); }
- case ('B') { ret ty.mk_mach(st.tcx, common.ty_i8); }
- case ('W') { ret ty.mk_mach(st.tcx, common.ty_i16); }
- case ('L') { ret ty.mk_mach(st.tcx, common.ty_i32); }
- case ('D') { ret ty.mk_mach(st.tcx, common.ty_i64); }
- case ('f') { ret ty.mk_mach(st.tcx, common.ty_f32); }
- case ('F') { ret ty.mk_mach(st.tcx, common.ty_f64); }
+ case ('b') { ret ty::mk_mach(st.tcx, common::ty_u8); }
+ case ('w') { ret ty::mk_mach(st.tcx, common::ty_u16); }
+ case ('l') { ret ty::mk_mach(st.tcx, common::ty_u32); }
+ case ('d') { ret ty::mk_mach(st.tcx, common::ty_u64); }
+ case ('B') { ret ty::mk_mach(st.tcx, common::ty_i8); }
+ case ('W') { ret ty::mk_mach(st.tcx, common::ty_i16); }
+ case ('L') { ret ty::mk_mach(st.tcx, common::ty_i32); }
+ case ('D') { ret ty::mk_mach(st.tcx, common::ty_i64); }
+ case ('f') { ret ty::mk_mach(st.tcx, common::ty_f32); }
+ case ('F') { ret ty::mk_mach(st.tcx, common::ty_f64); }
}
}
- case ('c') { ret ty.mk_char(st.tcx); }
- case ('s') { ret ty.mk_str(st.tcx); }
+ case ('c') { ret ty::mk_char(st.tcx); }
+ case ('s') { ret ty::mk_str(st.tcx); }
case ('t') {
assert (next(st) as char == '[');
auto def = parse_def(st, sd);
- let vec[ty.t] params = vec();
+ let vec[ty::t] params = vec();
while (peek(st) as char != ']') {
params += vec(parse_ty(st, sd));
}
st.pos = st.pos + 1u;
- ret ty.mk_tag(st.tcx, def, params);
+ 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 ('V') { ret ty.mk_vec(st.tcx, parse_mt(st, sd)); }
- 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 ('p') { ret ty::mk_param(st.tcx, parse_int(st) as uint); }
+ case ('@') { ret ty::mk_box(st.tcx, parse_mt(st, sd)); }
+ case ('V') { ret ty::mk_vec(st.tcx, parse_mt(st, sd)); }
+ 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 ('T') {
assert (next(st) as char == '[');
- let vec[ty.mt] params = vec();
+ let vec[ty::mt] params = vec();
while (peek(st) as char != ']') {
params += vec(parse_mt(st, sd));
}
st.pos = st.pos + 1u;
- ret ty.mk_tup(st.tcx, params);
+ ret ty::mk_tup(st.tcx, params);
}
case ('R') {
assert (next(st) as char == '[');
- let vec[ty.field] fields = vec();
+ let vec[ty::field] fields = vec();
while (peek(st) as char != ']') {
auto name = "";
while (peek(st) as char != '=') {
- name += Str.unsafe_from_byte(next(st));
+ name += _str::unsafe_from_byte(next(st));
}
st.pos = st.pos + 1u;
fields += vec(rec(ident=name, mt=parse_mt(st, sd)));
}
st.pos = st.pos + 1u;
- ret ty.mk_rec(st.tcx, fields);
+ ret ty::mk_rec(st.tcx, fields);
}
case ('F') {
auto func = parse_ty_fn(st, sd);
- ret ty.mk_fn(st.tcx, ast.proto_fn, func._0, func._1);
+ ret ty::mk_fn(st.tcx, ast::proto_fn, func._0, func._1);
}
case ('W') {
auto func = parse_ty_fn(st, sd);
- ret ty.mk_fn(st.tcx, ast.proto_iter, func._0, func._1);
+ ret ty::mk_fn(st.tcx, ast::proto_iter, func._0, func._1);
}
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 ('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; }
}
auto func = parse_ty_fn(st, sd);
- ret ty.mk_native_fn(st.tcx,abi,func._0,func._1);
+ ret ty::mk_native_fn(st.tcx,abi,func._0,func._1);
}
case ('O') {
assert (next(st) as char == '[');
- let vec[ty.method] methods = vec();
+ let vec[ty::method] methods = vec();
while (peek(st) as char != ']') {
auto proto;
alt (next(st) as char) {
- case ('W') {proto = ast.proto_iter;}
- case ('F') {proto = ast.proto_fn;}
+ 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));
+ name += _str::unsafe_from_byte(next(st));
}
auto func = parse_ty_fn(st, sd);
methods += vec(rec(proto=proto,
output=func._1));
}
st.pos += 1u;
- ret ty.mk_obj(st.tcx, methods);
+ ret ty::mk_obj(st.tcx, methods);
}
- case ('X') { ret ty.mk_var(st.tcx, parse_int(st)); }
- case ('E') { ret ty.mk_native(st.tcx); }
- case ('Y') { ret ty.mk_type(st.tcx); }
+ case ('X') { ret ty::mk_var(st.tcx, parse_int(st)); }
+ case ('E') { ret ty::mk_native(st.tcx); }
+ 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(tup(st.crate,pos,len))) {
- case (some[ty.t](?tt)) { ret tt; }
- case (none[ty.t]) {
+ case (some[ty::t](?tt)) { ret tt; }
+ case (none[ty::t]) {
auto ps = @rec(pos=pos, len=len with *st);
auto tt = parse_ty(ps, sd);
st.tcx.rcache.insert(tup(st.crate,pos,len), tt);
}
}
-fn parse_mt(@pstate st, str_def sd) -> ty.mt {
+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;}
+ case ('m') {next(st); mut = ast::mut;}
+ case ('?') {next(st); mut = ast::maybe_mut;}
+ case (_) {mut=ast::imm;}
}
ret rec(ty=parse_ty(st, sd), mut=mut);
}
-fn parse_def(@pstate st, str_def sd) -> ast.def_id {
+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));
+ def += _str::unsafe_from_byte(next(st));
}
st.pos = st.pos + 1u;
ret sd(def);
ret n;
}
-fn parse_ty_fn(@pstate st, str_def sd) -> tup(vec[ty.arg], ty.t) {
+fn parse_ty_fn(@pstate st, str_def sd) -> tup(vec[ty::arg], ty::t) {
assert (next(st) as char == '[');
- let vec[ty.arg] inputs = vec();
+ let vec[ty::arg] inputs = vec();
while (peek(st) as char != ']') {
- auto mode = ty.mo_val;
+ auto mode = ty::mo_val;
if (peek(st) as char == '&') {
- mode = ty.mo_alias;
+ mode = ty::mo_alias;
st.pos = st.pos + 1u;
}
inputs += vec(rec(mode=mode, ty=parse_ty(st, sd)));
// Rust metadata parsing
-fn parse_def_id(vec[u8] buf) -> ast.def_id {
+fn parse_def_id(vec[u8] buf) -> ast::def_id {
auto colon_idx = 0u;
- auto len = Vec.len[u8](buf);
+ auto len = _vec::len[u8](buf);
while (colon_idx < len && buf.(colon_idx) != (':' as u8)) {
colon_idx += 1u;
}
fail;
}
- auto crate_part = Vec.slice[u8](buf, 0u, colon_idx);
- auto def_part = Vec.slice[u8](buf, colon_idx + 1u, len);
- auto crate_num = UInt.parse_buf(crate_part, 10u) as int;
- auto def_num = UInt.parse_buf(def_part, 10u) as int;
+ auto crate_part = _vec::slice[u8](buf, 0u, colon_idx);
+ auto def_part = _vec::slice[u8](buf, colon_idx + 1u, len);
+ auto crate_num = _uint::parse_buf(crate_part, 10u) as int;
+ auto def_num = _uint::parse_buf(def_part, 10u) as int;
ret tup(crate_num, def_num);
}
-fn lookup_hash(&EBML.doc d, fn(vec[u8]) -> bool eq_fn, uint hash)
- -> Option.t[EBML.doc] {
- auto index = EBML.get_doc(d, metadata.tag_index);
- auto table = EBML.get_doc(index, metadata.tag_index_table);
+fn lookup_hash(&ebml::doc d, fn(vec[u8]) -> bool eq_fn, uint hash)
+ -> option::t[ebml::doc] {
+ auto index = ebml::get_doc(d, metadata::tag_index);
+ auto table = ebml::get_doc(index, metadata::tag_index_table);
auto hash_pos = table.start + (hash % 256u) * 4u;
- auto pos = EBML.be_uint_from_bytes(d.data, hash_pos, 4u);
- auto bucket = EBML.doc_at(d.data, pos);
+ auto pos = ebml::be_uint_from_bytes(d.data, hash_pos, 4u);
+ auto bucket = ebml::doc_at(d.data, pos);
// Awkward logic because we can't ret from foreach yet
- auto result = Option.none[EBML.doc];
- auto belt = metadata.tag_index_buckets_bucket_elt;
- for each (EBML.doc elt in EBML.tagged_docs(bucket, belt)) {
+ auto result = option::none[ebml::doc];
+ auto belt = metadata::tag_index_buckets_bucket_elt;
+ for each (ebml::doc elt in ebml::tagged_docs(bucket, belt)) {
alt (result) {
- case (Option.none[EBML.doc]) {
- auto pos = EBML.be_uint_from_bytes(elt.data, elt.start, 4u);
- if (eq_fn(Vec.slice[u8](elt.data, elt.start+4u, elt.end))) {
- result = Option.some[EBML.doc](EBML.doc_at(d.data, pos));
+ case (option::none[ebml::doc]) {
+ auto pos = ebml::be_uint_from_bytes(elt.data, elt.start, 4u);
+ if (eq_fn(_vec::slice[u8](elt.data, elt.start+4u, elt.end))) {
+ result = option::some[ebml::doc]
+ (ebml::doc_at(d.data, pos));
}
}
case (_) {}
// Given a path and serialized crate metadata, returns the ID of the
// definition the path refers to.
-fn resolve_path(vec[ast.ident] path, vec[u8] data) -> resolve_result {
+fn resolve_path(vec[ast::ident] path, vec[u8] data) -> resolve_result {
fn eq_item(vec[u8] data, str s) -> bool {
- ret Str.eq(Str.unsafe_from_bytes(data), s);
+ ret _str::eq(_str::unsafe_from_bytes(data), s);
}
- auto s = Str.connect(path, "::");
- auto md = EBML.new_doc(data);
- auto paths = EBML.get_doc(md, metadata.tag_paths);
+ auto s = _str::connect(path, "::");
+ auto md = ebml::new_doc(data);
+ auto paths = ebml::get_doc(md, metadata::tag_paths);
auto eqer = bind eq_item(_, s);
- alt (lookup_hash(paths, eqer, metadata.hash_path(s))) {
- case (Option.some[EBML.doc](?d)) {
- auto did_doc = EBML.get_doc(d, metadata.tag_def_id);
- ret rr_ok(parse_def_id(EBML.doc_data(did_doc)));
+ alt (lookup_hash(paths, eqer, metadata::hash_path(s))) {
+ case (option::some[ebml::doc](?d)) {
+ auto did_doc = ebml::get_doc(d, metadata::tag_def_id);
+ ret rr_ok(parse_def_id(ebml::doc_data(did_doc)));
}
- case (Option.none[EBML.doc]) {
+ case (option::none[ebml::doc]) {
ret rr_not_found(s);
}
}
}
-fn maybe_find_item(int item_id, &EBML.doc items) -> Option.t[EBML.doc] {
+fn maybe_find_item(int item_id, &ebml::doc items) -> option::t[ebml::doc] {
fn eq_item(vec[u8] bytes, int item_id) -> bool {
- ret EBML.be_uint_from_bytes(bytes, 0u, 4u) as int == item_id;
+ ret ebml::be_uint_from_bytes(bytes, 0u, 4u) as int == item_id;
}
auto eqer = bind eq_item(_, item_id);
- ret lookup_hash(items, eqer, metadata.hash_def_num(item_id));
+ ret lookup_hash(items, eqer, metadata::hash_def_num(item_id));
}
-fn find_item(int item_id, &EBML.doc items) -> EBML.doc {
+fn find_item(int item_id, &ebml::doc items) -> ebml::doc {
alt (maybe_find_item(item_id, items)) {
- case (Option.some[EBML.doc](?d)) {ret d;}
+ case (option::some[ebml::doc](?d)) {ret d;}
}
}
-// Looks up an item in the given metadata and returns an EBML doc pointing
+// Looks up an item in the given metadata and returns an ebml doc pointing
// to the item data.
-fn lookup_item(int item_id, vec[u8] data) -> EBML.doc {
- auto items = EBML.get_doc(EBML.new_doc(data), metadata.tag_items);
+fn lookup_item(int item_id, vec[u8] data) -> ebml::doc {
+ auto items = ebml::get_doc(ebml::new_doc(data), metadata::tag_items);
ret find_item(item_id, items);
}
-fn item_kind(&EBML.doc item) -> u8 {
- auto kind = EBML.get_doc(item, metadata.tag_items_data_item_kind);
- ret EBML.doc_as_uint(kind) as u8;
+fn item_kind(&ebml::doc item) -> u8 {
+ auto kind = ebml::get_doc(item, metadata::tag_items_data_item_kind);
+ ret ebml::doc_as_uint(kind) as u8;
}
-fn item_symbol(&EBML.doc item) -> str {
- auto sym = EBML.get_doc(item, metadata.tag_items_data_item_symbol);
- ret Str.unsafe_from_bytes(EBML.doc_data(sym));
+fn item_symbol(&ebml::doc item) -> str {
+ auto sym = ebml::get_doc(item, metadata::tag_items_data_item_symbol);
+ ret _str::unsafe_from_bytes(ebml::doc_data(sym));
}
-fn variant_tag_id(&EBML.doc d) -> ast.def_id {
- auto tagdoc = EBML.get_doc(d, metadata.tag_items_data_item_tag_id);
- ret parse_def_id(EBML.doc_data(tagdoc));
+fn variant_tag_id(&ebml::doc d) -> ast::def_id {
+ auto tagdoc = ebml::get_doc(d, metadata::tag_items_data_item_tag_id);
+ ret parse_def_id(ebml::doc_data(tagdoc));
}
-fn item_type(&EBML.doc item, int this_cnum, ty.ctxt tcx) -> ty.t {
- fn parse_external_def_id(int this_cnum, str s) -> ast.def_id {
+fn item_type(&ebml::doc item, int this_cnum, ty::ctxt tcx) -> ty::t {
+ fn parse_external_def_id(int this_cnum, str s) -> ast::def_id {
// FIXME: This is completely wrong when linking against a crate
// that, in turn, links against another crate. We need a mapping
// from crate ID to crate "meta" attributes as part of the crate
- // metadata.
- auto buf = Str.bytes(s);
+ // metadata:
+ auto buf = _str::bytes(s);
auto external_def_id = parse_def_id(buf);
ret tup(this_cnum, external_def_id._1);
}
- auto tp = EBML.get_doc(item, metadata.tag_items_data_item_type);
- auto s = Str.unsafe_from_bytes(EBML.doc_data(tp));
+ auto tp = ebml::get_doc(item, metadata::tag_items_data_item_type);
+ auto s = _str::unsafe_from_bytes(ebml::doc_data(tp));
ret parse_ty_data(item.data, this_cnum, tp.start, tp.end - tp.start,
bind parse_external_def_id(this_cnum, _), tcx);
}
-fn item_ty_param_count(&EBML.doc item, int this_cnum) -> uint {
+fn item_ty_param_count(&ebml::doc item, int this_cnum) -> uint {
let uint ty_param_count = 0u;
- auto tp = metadata.tag_items_data_item_ty_param_count;
- for each (EBML.doc p in EBML.tagged_docs(item, tp)) {
- ty_param_count = EBML.vint_at(EBML.doc_data(p), 0u)._0;
+ auto tp = metadata::tag_items_data_item_ty_param_count;
+ for each (ebml::doc p in ebml::tagged_docs(item, tp)) {
+ ty_param_count = ebml::vint_at(ebml::doc_data(p), 0u)._0;
}
ret ty_param_count;
}
-fn tag_variant_ids(&EBML.doc item, int this_cnum) -> vec[ast.def_id] {
- let vec[ast.def_id] ids = vec();
- auto v = metadata.tag_items_data_item_variant;
- for each (EBML.doc p in EBML.tagged_docs(item, v)) {
- auto ext = parse_def_id(EBML.doc_data(p));
- Vec.push[ast.def_id](ids, tup(this_cnum, ext._1));
+fn tag_variant_ids(&ebml::doc item, int this_cnum) -> vec[ast::def_id] {
+ let vec[ast::def_id] ids = vec();
+ auto v = metadata::tag_items_data_item_variant;
+ for each (ebml::doc p in ebml::tagged_docs(item, v)) {
+ auto ext = parse_def_id(ebml::doc_data(p));
+ _vec::push[ast::def_id](ids, tup(this_cnum, ext._1));
}
ret ids;
}
-fn get_metadata_section(str filename) -> Option.t[vec[u8]] {
- auto mb = llvm.LLVMRustCreateMemoryBufferWithContentsOfFile
- (Str.buf(filename));
- if (mb as int == 0) {ret Option.none[vec[u8]];}
+fn get_metadata_section(str filename) -> option::t[vec[u8]] {
+ auto mb = llvm::LLVMRustCreateMemoryBufferWithContentsOfFile
+ (_str::buf(filename));
+ if (mb as int == 0) {ret option::none[vec[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);
- auto cvbuf = cbuf as Vec.vbuf;
- ret Option.some[vec[u8]](Vec.vec_from_vbuf[u8](cvbuf, csz));
+ 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);
+ auto cvbuf = cbuf as _vec::vbuf;
+ ret option::some[vec[u8]](_vec::vec_from_vbuf[u8](cvbuf, csz));
}
- llvm.LLVMMoveToNextSection(si.llsi);
+ llvm::LLVMMoveToNextSection(si.llsi);
}
- ret Option.none[vec[u8]];
+ ret option::none[vec[u8]];
}
-fn load_crate(session.session sess,
+fn load_crate(session::session sess,
int cnum,
- ast.ident ident,
+ ast::ident ident,
vec[str] library_search_paths) {
- auto filename = parser.default_native_name(sess, ident);
+ auto filename = parser::default_native_name(sess, ident);
for (str library_search_path in library_search_paths) {
- auto path = FS.connect(library_search_path, filename);
+ auto path = fs::connect(library_search_path, filename);
alt (get_metadata_section(path)) {
- case (Option.some[vec[u8]](?cvec)) {
+ case (option::some[vec[u8]](?cvec)) {
sess.set_external_crate(cnum, rec(name=ident, data=cvec));
ret;
}
fail;
}
-fn fold_view_item_use(&env e, &span sp, &ast.ident ident,
- &vec[@ast.meta_item] meta_items,
- &ast.def_id id, &Option.t[int] cnum_opt)
- -> @ast.view_item {
+fn fold_view_item_use(&env e, &span sp, &ast::ident ident,
+ &vec[@ast::meta_item] meta_items,
+ &ast::def_id id, &option::t[int] cnum_opt)
+ -> @ast::view_item {
auto cnum;
if (!e.crate_cache.contains_key(ident)) {
cnum = e.next_crate_num;
cnum = e.crate_cache.get(ident);
}
- auto viu = ast.view_item_use(ident, meta_items, id, some[int](cnum));
- ret @fold.respan[ast.view_item_](sp, viu);
+ auto viu = ast::view_item_use(ident, meta_items, id, some[int](cnum));
+ ret @fold::respan[ast::view_item_](sp, viu);
}
// Reads external crates referenced by "use" directives.
-fn read_crates(session.session sess,
- @ast.crate crate) -> @ast.crate {
+fn read_crates(session::session sess,
+ @ast::crate crate) -> @ast::crate {
auto e = @rec(
sess=sess,
- crate_cache=@common.new_str_hash[int](),
+ crate_cache=@common::new_str_hash[int](),
library_search_paths=sess.get_opts().library_search_paths,
mutable next_crate_num=1
);
auto f = fold_view_item_use;
- auto fld = @rec(fold_view_item_use=f with *fold.new_identity_fold[env]());
- ret fold.fold_crate[env](e, fld, crate);
+ auto fld = @rec(fold_view_item_use=f
+ with *fold::new_identity_fold[env]());
+ ret fold::fold_crate[env](e, fld, crate);
}
// Crate metadata queries
-fn lookup_def(session.session sess, int cnum, vec[ast.ident] path)
- -> Option.t[ast.def] {
+fn lookup_def(session::session sess, int cnum, vec[ast::ident] path)
+ -> option::t[ast::def] {
auto data = sess.get_external_crate(cnum).data;
auto did;
alt (resolve_path(path, data)) {
case (rr_ok(?di)) { did = di; }
case (rr_not_found(?name)) {
- ret none[ast.def];
+ ret none[ast::def];
}
}
// FIXME: It'd be great if we had u8 char literals.
auto def;
- if (kind_ch == ('c' as u8)) { def = ast.def_const(did); }
- else if (kind_ch == ('f' as u8)) { def = ast.def_fn(did); }
- else if (kind_ch == ('F' as u8)) { def = ast.def_native_fn(did); }
- else if (kind_ch == ('y' as u8)) { def = ast.def_ty(did); }
- else if (kind_ch == ('o' as u8)) { def = ast.def_obj(did); }
- else if (kind_ch == ('T' as u8)) { def = ast.def_native_ty(did); }
+ if (kind_ch == ('c' as u8)) { def = ast::def_const(did); }
+ else if (kind_ch == ('f' as u8)) { def = ast::def_fn(did); }
+ else if (kind_ch == ('F' as u8)) { def = ast::def_native_fn(did); }
+ else if (kind_ch == ('y' as u8)) { def = ast::def_ty(did); }
+ else if (kind_ch == ('o' as u8)) { def = ast::def_obj(did); }
+ else if (kind_ch == ('T' as u8)) { def = ast::def_native_ty(did); }
else if (kind_ch == ('t' as u8)) {
// We treat references to tags as references to types.
- def = ast.def_ty(did);
- } else if (kind_ch == ('m' as u8)) { def = ast.def_mod(did); }
- else if (kind_ch == ('n' as u8)) { def = ast.def_native_mod(did); }
+ def = ast::def_ty(did);
+ } else if (kind_ch == ('m' as u8)) { def = ast::def_mod(did); }
+ else if (kind_ch == ('n' as u8)) { def = ast::def_native_mod(did); }
else if (kind_ch == ('v' as u8)) {
auto tid = variant_tag_id(item);
tid = tup(cnum, tid._1);
- def = ast.def_variant(tid, did);
+ def = ast::def_variant(tid, did);
} else {
log_err #fmt("lookup_def(): unknown kind char: %d", kind_ch as int);
fail;
}
- ret some[ast.def](def);
+ ret some[ast::def](def);
}
-fn get_type(session.session sess, ty.ctxt tcx, ast.def_id def)
- -> ty.ty_param_count_and_ty {
+fn get_type(session::session sess, ty::ctxt tcx, ast::def_id def)
+ -> ty::ty_param_count_and_ty {
auto external_crate_id = def._0;
auto data = sess.get_external_crate(external_crate_id).data;
auto item = lookup_item(def._1, data);
ret tup(tp_count, t);
}
-fn get_symbol(session.session sess, ast.def_id def) -> str {
+fn get_symbol(session::session sess, ast::def_id def) -> str {
auto external_crate_id = def._0;
auto data = sess.get_external_crate(external_crate_id).data;
auto item = lookup_item(def._1, data);
ret item_symbol(item);
}
-fn get_tag_variants(session.session sess, ty.ctxt tcx, ast.def_id def)
- -> vec[trans.variant_info] {
+fn get_tag_variants(session::session sess, ty::ctxt tcx, ast::def_id def)
+ -> vec[trans::variant_info] {
auto external_crate_id = def._0;
auto data = sess.get_external_crate(external_crate_id).data;
- auto items = EBML.get_doc(EBML.new_doc(data), metadata.tag_items);
+ auto items = ebml::get_doc(ebml::new_doc(data), metadata::tag_items);
auto item = find_item(def._1, items);
- let vec[trans.variant_info] infos = vec();
+ let vec[trans::variant_info] infos = vec();
auto variant_ids = tag_variant_ids(item, external_crate_id);
- for (ast.def_id did in variant_ids) {
+ for (ast::def_id did in variant_ids) {
auto item = find_item(did._1, items);
auto ctor_ty = item_type(item, external_crate_id, tcx);
- let vec[ty.t] arg_tys = vec();
- alt (ty.struct(tcx, ctor_ty)) {
- case (ty.ty_fn(_, ?args, _)) {
- for (ty.arg a in args) {
+ let vec[ty::t] arg_tys = vec();
+ alt (ty::struct(tcx, ctor_ty)) {
+ case (ty::ty_fn(_, ?args, _)) {
+ for (ty::arg a in args) {
arg_tys += vec(a.ty);
}
}
ret infos;
}
-fn list_file_metadata(str path, IO.writer out) {
+fn list_file_metadata(str path, io::writer out) {
alt (get_metadata_section(path)) {
- case (Option.some[vec[u8]](?bytes)) {
+ case (option::some[vec[u8]](?bytes)) {
list_crate_metadata(bytes, out);
}
- case (Option.none[vec[u8]]) {
+ case (option::none[vec[u8]]) {
out.write_str("Could not find metadata in " + path + ".\n");
}
}
}
-fn read_path(&EBML.doc d) -> tup(str, uint) {
- auto desc = EBML.doc_data(d);
- auto pos = EBML.be_uint_from_bytes(desc, 0u, 4u);
- auto pathbytes = Vec.slice[u8](desc, 4u, Vec.len[u8](desc));
- auto path = Str.unsafe_from_bytes(pathbytes);
+fn read_path(&ebml::doc d) -> tup(str, uint) {
+ auto desc = ebml::doc_data(d);
+ auto pos = ebml::be_uint_from_bytes(desc, 0u, 4u);
+ auto pathbytes = _vec::slice[u8](desc, 4u, _vec::len[u8](desc));
+ auto path = _str::unsafe_from_bytes(pathbytes);
ret tup(path, pos);
}
-fn list_crate_metadata(vec[u8] bytes, IO.writer out) {
- auto md = EBML.new_doc(bytes);
- auto paths = EBML.get_doc(md, metadata.tag_paths);
- auto items = EBML.get_doc(md, metadata.tag_items);
- auto index = EBML.get_doc(paths, metadata.tag_index);
- auto bs = EBML.get_doc(index, metadata.tag_index_buckets);
- for each (EBML.doc bucket in
- EBML.tagged_docs(bs, metadata.tag_index_buckets_bucket)) {
- auto et = metadata.tag_index_buckets_bucket_elt;
- for each (EBML.doc elt in EBML.tagged_docs(bucket, et)) {
+fn list_crate_metadata(vec[u8] bytes, io::writer out) {
+ auto md = ebml::new_doc(bytes);
+ auto paths = ebml::get_doc(md, metadata::tag_paths);
+ auto items = ebml::get_doc(md, metadata::tag_items);
+ auto index = ebml::get_doc(paths, metadata::tag_index);
+ auto bs = ebml::get_doc(index, metadata::tag_index_buckets);
+ for each (ebml::doc bucket in
+ ebml::tagged_docs(bs, metadata::tag_index_buckets_bucket)) {
+ auto et = metadata::tag_index_buckets_bucket_elt;
+ for each (ebml::doc elt in ebml::tagged_docs(bucket, et)) {
auto data = read_path(elt);
- auto def = EBML.doc_at(bytes, data._1);
- auto did_doc = EBML.get_doc(def, metadata.tag_def_id);
- auto did = parse_def_id(EBML.doc_data(did_doc));
+ auto def = ebml::doc_at(bytes, data._1);
+ auto did_doc = ebml::get_doc(def, metadata::tag_def_id);
+ auto did = parse_def_id(ebml::doc_data(did_doc));
out.write_str(#fmt("%s (%s)\n", data._0,
describe_def(items, did)));
}
}
}
-fn describe_def(&EBML.doc items, ast.def_id id) -> str {
+fn describe_def(&ebml::doc items, ast::def_id id) -> str {
if (id._0 != 0) {ret "external";}
auto item = find_item(id._1, items);
ret item_kind_to_str(item_kind(item));
-import std.Vec;
-import std.Str;
-import std.Option;
-import std.Option.some;
-import std.Option.none;
-import std.Map.hashmap;
-
-import driver.session;
-import ast.ident;
-import front.parser.parser;
-import front.parser.spanned;
-import front.parser.new_parser;
-import front.parser.parse_mod_items;
-import util.common;
-import util.common.filename;
-import util.common.span;
-import util.common.new_str_hash;
+import std::_vec;
+import std::_str;
+import std::option;
+import std::option::some;
+import std::option::none;
+import std::map::hashmap;
+
+import driver::session;
+import ast::ident;
+import front::parser::parser;
+import front::parser::spanned;
+import front::parser::new_parser;
+import front::parser::parse_mod_items;
+import util::common;
+import util::common::filename;
+import util::common::span;
+import util::common::new_str_hash;
// Simple dynamic-typed value type for eval_expr.
type ctx = @rec(parser p,
eval_mode mode,
mutable vec[str] deps,
- session.session sess,
+ session::session sess,
mutable uint chpos,
mutable uint next_ann);
fail;
}
-fn lookup(session.session sess, env e, span sp, ident i) -> val {
+fn lookup(session::session sess, env e, span sp, ident i) -> val {
for (tup(ident, val) pair in e) {
- if (Str.eq(i, pair._0)) {
+ if (_str::eq(i, pair._0)) {
ret pair._1;
}
}
fail;
}
-fn eval_lit(ctx cx, span sp, @ast.lit lit) -> val {
+fn eval_lit(ctx cx, span sp, @ast::lit lit) -> val {
alt (lit.node) {
- case (ast.lit_bool(?b)) { ret val_bool(b); }
- case (ast.lit_int(?i)) { ret val_int(i); }
- case (ast.lit_str(?s)) { ret val_str(s); }
+ case (ast::lit_bool(?b)) { ret val_bool(b); }
+ case (ast::lit_int(?i)) { ret val_int(i); }
+ case (ast::lit_str(?s)) { ret val_str(s); }
case (_) {
cx.sess.span_err(sp, "evaluating unsupported literal");
}
fail;
}
-fn eval_expr(ctx cx, env e, @ast.expr x) -> val {
+fn eval_expr(ctx cx, env e, @ast::expr x) -> val {
alt (x.node) {
- case (ast.expr_path(?pth, _)) {
- if (Vec.len[ident](pth.node.idents) == 1u &&
- Vec.len[@ast.ty](pth.node.types) == 0u) {
+ case (ast::expr_path(?pth, _)) {
+ if (_vec::len[ident](pth.node.idents) == 1u &&
+ _vec::len[@ast::ty](pth.node.types) == 0u) {
ret lookup(cx.sess, e, x.span, pth.node.idents.(0));
}
cx.sess.span_err(x.span, "evaluating structured path-name");
}
- case (ast.expr_lit(?lit, _)) {
+ case (ast::expr_lit(?lit, _)) {
ret eval_lit(cx, x.span, lit);
}
- case (ast.expr_unary(?op, ?a, _)) {
+ case (ast::expr_unary(?op, ?a, _)) {
auto av = eval_expr(cx, e, a);
alt (op) {
- case (ast.not) {
+ case (ast::not) {
if (val_is_bool(av)) {
ret val_bool(!val_as_bool(av));
}
}
}
- case (ast.expr_binary(?op, ?a, ?b, _)) {
+ case (ast::expr_binary(?op, ?a, ?b, _)) {
auto av = eval_expr(cx, e, a);
auto bv = eval_expr(cx, e, b);
alt (op) {
- case (ast.add) {
+ case (ast::add) {
if (val_is_int(av) && val_is_int(bv)) {
ret val_int(val_as_int(av) + val_as_int(bv));
}
cx.sess.span_err(x.span, "bad types in '+' expression");
}
- case (ast.sub) {
+ case (ast::sub) {
if (val_is_int(av) && val_is_int(bv)) {
ret val_int(val_as_int(av) - val_as_int(bv));
}
cx.sess.span_err(x.span, "bad types in '-' expression");
}
- case (ast.mul) {
+ case (ast::mul) {
if (val_is_int(av) && val_is_int(bv)) {
ret val_int(val_as_int(av) * val_as_int(bv));
}
cx.sess.span_err(x.span, "bad types in '*' expression");
}
- case (ast.div) {
+ case (ast::div) {
if (val_is_int(av) && val_is_int(bv)) {
ret val_int(val_as_int(av) / val_as_int(bv));
}
cx.sess.span_err(x.span, "bad types in '/' expression");
}
- case (ast.rem) {
+ case (ast::rem) {
if (val_is_int(av) && val_is_int(bv)) {
ret val_int(val_as_int(av) % val_as_int(bv));
}
cx.sess.span_err(x.span, "bad types in '%' expression");
}
- case (ast.and) {
+ case (ast::and) {
if (val_is_bool(av) && val_is_bool(bv)) {
ret val_bool(val_as_bool(av) && val_as_bool(bv));
}
cx.sess.span_err(x.span, "bad types in '&&' expression");
}
- case (ast.or) {
+ case (ast::or) {
if (val_is_bool(av) && val_is_bool(bv)) {
ret val_bool(val_as_bool(av) || val_as_bool(bv));
}
cx.sess.span_err(x.span, "bad types in '||' expression");
}
- case (ast.eq) {
+ case (ast::eq) {
ret val_bool(val_eq(cx.sess, x.span, av, bv));
}
- case (ast.ne) {
+ case (ast::ne) {
ret val_bool(! val_eq(cx.sess, x.span, av, bv));
}
fail;
}
-fn val_eq(session.session sess, span sp, val av, val bv) -> bool {
+fn val_eq(session::session sess, span sp, val av, val bv) -> bool {
if (val_is_bool(av) && val_is_bool(bv)) {
ret val_as_bool(av) == val_as_bool(bv);
}
ret val_as_int(av) == val_as_int(bv);
}
if (val_is_str(av) && val_is_str(bv)) {
- ret Str.eq(val_as_str(av),
+ ret _str::eq(val_as_str(av),
val_as_str(bv));
}
sess.span_err(sp, "bad types in comparison");
fn eval_crate_directives(ctx cx,
env e,
- vec[@ast.crate_directive] cdirs,
+ vec[@ast::crate_directive] cdirs,
str prefix,
- &mutable vec[@ast.view_item] view_items,
- &mutable vec[@ast.item] items) {
+ &mutable vec[@ast::view_item] view_items,
+ &mutable vec[@ast::item] items) {
- for (@ast.crate_directive sub_cdir in cdirs) {
+ for (@ast::crate_directive sub_cdir in cdirs) {
eval_crate_directive(cx, e, sub_cdir, prefix,
view_items, items);
}
fn eval_crate_directives_to_mod(ctx cx, env e,
- vec[@ast.crate_directive] cdirs,
- str prefix) -> ast._mod {
- let vec[@ast.view_item] view_items = vec();
- let vec[@ast.item] items = vec();
+ vec[@ast::crate_directive] cdirs,
+ str prefix) -> ast::_mod {
+ let vec[@ast::view_item] view_items = vec();
+ let vec[@ast::item] items = vec();
eval_crate_directives(cx, e, cdirs, prefix,
view_items, items);
fn eval_crate_directive_block(ctx cx,
env e,
- &ast.block blk,
+ &ast::block blk,
str prefix,
- &mutable vec[@ast.view_item] view_items,
- &mutable vec[@ast.item] items) {
+ &mutable vec[@ast::view_item] view_items,
+ &mutable vec[@ast::item] items) {
- for (@ast.stmt s in blk.node.stmts) {
+ for (@ast::stmt s in blk.node.stmts) {
alt (s.node) {
- case (ast.stmt_crate_directive(?cdir)) {
+ case (ast::stmt_crate_directive(?cdir)) {
eval_crate_directive(cx, e, cdir, prefix,
view_items, items);
}
fn eval_crate_directive_expr(ctx cx,
env e,
- @ast.expr x,
+ @ast::expr x,
str prefix,
- &mutable vec[@ast.view_item] view_items,
- &mutable vec[@ast.item] items) {
+ &mutable vec[@ast::view_item] view_items,
+ &mutable vec[@ast::item] items) {
alt (x.node) {
- case (ast.expr_if(?cond, ?thn, ?elopt, _)) {
+ case (ast::expr_if(?cond, ?thn, ?elopt, _)) {
auto cv = eval_expr(cx, e, cond);
if (!val_is_bool(cv)) {
cx.sess.span_err(x.span, "bad cond type in 'if'");
}
alt (elopt) {
- case (some[@ast.expr](?els)) {
+ case (some[@ast::expr](?els)) {
ret eval_crate_directive_expr(cx, e, els, prefix,
view_items, items);
}
}
}
- case (ast.expr_alt(?v, ?arms, _)) {
+ case (ast::expr_alt(?v, ?arms, _)) {
auto vv = eval_expr(cx, e, v);
- for (ast.arm arm in arms) {
+ for (ast::arm arm in arms) {
alt (arm.pat.node) {
- case (ast.pat_lit(?lit, _)) {
+ case (ast::pat_lit(?lit, _)) {
auto pv = eval_lit(cx, arm.pat.span, lit);
if (val_eq(cx.sess, arm.pat.span, vv, pv)) {
ret eval_crate_directive_block
(cx, e, arm.block, prefix, view_items, items);
}
}
- case (ast.pat_wild(_)) {
+ case (ast::pat_wild(_)) {
ret eval_crate_directive_block
(cx, e, arm.block, prefix,
view_items, items);
cx.sess.span_err(x.span, "no cases matched in 'alt'");
}
- case (ast.expr_block(?block, _)) {
+ case (ast::expr_block(?block, _)) {
ret eval_crate_directive_block(cx, e, block, prefix,
view_items, items);
}
fn eval_crate_directive(ctx cx,
env e,
- @ast.crate_directive cdir,
+ @ast::crate_directive cdir,
str prefix,
- &mutable vec[@ast.view_item] view_items,
- &mutable vec[@ast.item] items) {
+ &mutable vec[@ast::view_item] view_items,
+ &mutable vec[@ast::item] items) {
alt (cdir.node) {
- case (ast.cdir_let(?id, ?x, ?cdirs)) {
+ case (ast::cdir_let(?id, ?x, ?cdirs)) {
auto v = eval_expr(cx, e, x);
auto e0 = vec(tup(id, v)) + e;
eval_crate_directives(cx, e0, cdirs, prefix,
view_items, items);
}
- case (ast.cdir_expr(?x)) {
+ case (ast::cdir_expr(?x)) {
eval_crate_directive_expr(cx, e, x, prefix,
view_items, items);
}
- case (ast.cdir_src_mod(?id, ?file_opt)) {
+ case (ast::cdir_src_mod(?id, ?file_opt)) {
auto file_path = id + ".rs";
alt (file_opt) {
case (none[filename]) {}
}
- auto full_path = prefix + std.FS.path_sep() + file_path;
+ auto full_path = prefix + std::fs::path_sep() + file_path;
if (cx.mode == mode_depend) {
cx.deps += vec(full_path);
auto start_id = cx.p.next_def_id();
auto p0 = new_parser(cx.sess, e, start_id, full_path, cx.chpos,
cx.next_ann);
- auto m0 = parse_mod_items(p0, token.EOF);
+ auto m0 = parse_mod_items(p0, token::EOF);
auto next_id = p0.next_def_id();
// Thread defids and chpos through the parsers
cx.p.set_def(next_id._1);
cx.chpos = p0.get_chpos();
cx.next_ann = p0.next_ann_num();
- auto im = ast.item_mod(id, m0, next_id);
+ auto im = ast::item_mod(id, m0, next_id);
auto i = @spanned(cdir.span.lo, cdir.span.hi, im);
- Vec.push[@ast.item](items, i);
+ _vec::push[@ast::item](items, i);
}
- case (ast.cdir_dir_mod(?id, ?dir_opt, ?cdirs)) {
+ case (ast::cdir_dir_mod(?id, ?dir_opt, ?cdirs)) {
auto path = id;
alt (dir_opt) {
case (none[filename]) {}
}
- auto full_path = prefix + std.FS.path_sep() + path;
+ auto full_path = prefix + std::fs::path_sep() + path;
auto m0 = eval_crate_directives_to_mod(cx, e, cdirs, full_path);
- auto im = ast.item_mod(id, m0, cx.p.next_def_id());
+ auto im = ast::item_mod(id, m0, cx.p.next_def_id());
auto i = @spanned(cdir.span.lo, cdir.span.hi, im);
- Vec.push[@ast.item](items, i);
+ _vec::push[@ast::item](items, i);
}
- case (ast.cdir_view_item(?vi)) {
- Vec.push[@ast.view_item](view_items, vi);
+ case (ast::cdir_view_item(?vi)) {
+ _vec::push[@ast::view_item](view_items, vi);
}
- case (ast.cdir_meta(?mi)) {
+ case (ast::cdir_meta(?mi)) {
cx.sess.add_metadata(mi);
}
- case (ast.cdir_syntax(?pth)) {}
- case (ast.cdir_auth(?pth, ?eff)) {}
+ case (ast::cdir_syntax(?pth)) {}
+ case (ast::cdir_auth(?pth, ?eff)) {}
}
}
* interface.
*/
-import util.common;
+import util::common;
-import std.Str;
-import std.Vec;
-import std.Option;
-import std.GenericOS;
+import std::_str;
+import std::_vec;
+import std::option;
+import std::generic_os;
export expand_syntax_ext;
// FIXME: Need to thread parser through here to handle errors correctly
-fn expand_syntax_ext(parser.parser p,
- common.span sp,
- vec[@ast.expr] args,
- Option.t[str] body) -> @ast.expr {
+fn expand_syntax_ext(parser::parser p,
+ common::span sp,
+ vec[@ast::expr] args,
+ option::t[str] body) -> @ast::expr {
- if (Vec.len[@ast.expr](args) != 1u) {
+ if (_vec::len[@ast::expr](args) != 1u) {
p.err("malformed #env call");
}
// FIXME: if this was more thorough it would manufacture an
- // Option.t[str] rather than just an maybe-empty string.
+ // option::t[str] rather than just an maybe-empty string.
auto var = expr_to_str(p, args.(0));
- alt (GenericOS.getenv(var)) {
- case (Option.none[str]) {
+ alt (generic_os::getenv(var)) {
+ case (option::none[str]) {
ret make_new_str(p, sp, "");
}
- case (Option.some[str](?s)) {
+ case (option::some[str](?s)) {
ret make_new_str(p, sp, s);
}
}
}
-// FIXME: duplicate code copied from extfmt.
+// FIXME: duplicate code copied from extfmt:
-fn expr_to_str(parser.parser p,
- @ast.expr expr) -> str {
+fn expr_to_str(parser::parser p,
+ @ast::expr expr) -> str {
alt (expr.node) {
- case (ast.expr_lit(?l, _)) {
+ case (ast::expr_lit(?l, _)) {
alt (l.node) {
- case (ast.lit_str(?s)) {
+ case (ast::lit_str(?s)) {
ret s;
}
}
fail;
}
-fn make_new_lit(parser.parser p, common.span sp, ast.lit_ lit) -> @ast.expr {
+fn make_new_lit(parser::parser p, common::span sp, ast::lit_ lit)
+ -> @ast::expr {
auto sp_lit = @rec(node=lit, span=sp);
- auto expr = ast.expr_lit(sp_lit, p.get_ann());
+ auto expr = ast::expr_lit(sp_lit, p.get_ann());
ret @rec(node=expr, span=sp);
}
-fn make_new_str(parser.parser p, common.span sp, str s) -> @ast.expr {
- auto lit = ast.lit_str(s);
+fn make_new_str(parser::parser p, common::span sp, str s) -> @ast::expr {
+ auto lit = ast::lit_str(s);
ret make_new_lit(p, sp, lit);
}
/*
* The compiler code necessary to support the #fmt extension. Eventually this
- * should all get sucked into either the standard library ExtFmt module or the
+ * should all get sucked into either the standard library extfmt module or the
* compiler syntax extension plugin interface.
*/
-import front.parser.parser;
-import util.common;
-
-import std.Str;
-import std.Vec;
-import std.Option;
-import std.Option.none;
-import std.Option.some;
-
-import std.ExtFmt.CT.signedness;
-import std.ExtFmt.CT.signed;
-import std.ExtFmt.CT.unsigned;
-import std.ExtFmt.CT.caseness;
-import std.ExtFmt.CT.case_upper;
-import std.ExtFmt.CT.case_lower;
-import std.ExtFmt.CT.ty;
-import std.ExtFmt.CT.ty_bool;
-import std.ExtFmt.CT.ty_str;
-import std.ExtFmt.CT.ty_char;
-import std.ExtFmt.CT.ty_int;
-import std.ExtFmt.CT.ty_bits;
-import std.ExtFmt.CT.ty_hex;
-import std.ExtFmt.CT.ty_octal;
-import std.ExtFmt.CT.flag;
-import std.ExtFmt.CT.flag_left_justify;
-import std.ExtFmt.CT.flag_left_zero_pad;
-import std.ExtFmt.CT.flag_space_for_sign;
-import std.ExtFmt.CT.flag_sign_always;
-import std.ExtFmt.CT.flag_alternate;
-import std.ExtFmt.CT.count;
-import std.ExtFmt.CT.count_is;
-import std.ExtFmt.CT.count_is_param;
-import std.ExtFmt.CT.count_is_next_param;
-import std.ExtFmt.CT.count_implied;
-import std.ExtFmt.CT.conv;
-import std.ExtFmt.CT.piece;
-import std.ExtFmt.CT.piece_string;
-import std.ExtFmt.CT.piece_conv;
-import std.ExtFmt.CT.parse_fmt_string;
+import front::parser::parser;
+import util::common;
+
+import std::_str;
+import std::_vec;
+import std::option;
+import std::option::none;
+import std::option::some;
+
+import std::extfmt::CT::signedness;
+import std::extfmt::CT::signed;
+import std::extfmt::CT::unsigned;
+import std::extfmt::CT::caseness;
+import std::extfmt::CT::case_upper;
+import std::extfmt::CT::case_lower;
+import std::extfmt::CT::ty;
+import std::extfmt::CT::ty_bool;
+import std::extfmt::CT::ty_str;
+import std::extfmt::CT::ty_char;
+import std::extfmt::CT::ty_int;
+import std::extfmt::CT::ty_bits;
+import std::extfmt::CT::ty_hex;
+import std::extfmt::CT::ty_octal;
+import std::extfmt::CT::flag;
+import std::extfmt::CT::flag_left_justify;
+import std::extfmt::CT::flag_left_zero_pad;
+import std::extfmt::CT::flag_space_for_sign;
+import std::extfmt::CT::flag_sign_always;
+import std::extfmt::CT::flag_alternate;
+import std::extfmt::CT::count;
+import std::extfmt::CT::count_is;
+import std::extfmt::CT::count_is_param;
+import std::extfmt::CT::count_is_next_param;
+import std::extfmt::CT::count_implied;
+import std::extfmt::CT::conv;
+import std::extfmt::CT::piece;
+import std::extfmt::CT::piece_string;
+import std::extfmt::CT::piece_conv;
+import std::extfmt::CT::parse_fmt_string;
export expand_syntax_ext;
fn expand_syntax_ext(parser p,
- vec[@ast.expr] args,
- Option.t[str] body) -> @ast.expr {
+ vec[@ast::expr] args,
+ option::t[str] body) -> @ast::expr {
- if (Vec.len[@ast.expr](args) == 0u) {
+ if (_vec::len[@ast::expr](args) == 0u) {
// FIXME: Handle error correctly.
log_err "malformed #fmt call";
fail;
// log fmt;
auto pieces = parse_fmt_string(fmt);
- auto args_len = Vec.len[@ast.expr](args);
- auto fmt_args = Vec.slice[@ast.expr](args, 1u, args_len - 1u);
+ auto args_len = _vec::len[@ast::expr](args);
+ auto fmt_args = _vec::slice[@ast::expr](args, 1u, args_len - 1u);
ret pieces_to_expr(p, pieces, args);
}
-fn expr_to_str(@ast.expr expr) -> str {
+fn expr_to_str(@ast::expr expr) -> str {
alt (expr.node) {
- case (ast.expr_lit(?l, _)) {
+ case (ast::expr_lit(?l, _)) {
alt (l.node) {
- case (ast.lit_str(?s)) {
+ case (ast::lit_str(?s)) {
ret s;
}
}
// be factored out in common with other code that builds expressions.
// FIXME: Probably should be using the parser's span functions
// FIXME: Cleanup the naming of these functions
-fn pieces_to_expr(parser p, vec[piece] pieces, vec[@ast.expr] args)
- -> @ast.expr {
+fn pieces_to_expr(parser p, vec[piece] pieces, vec[@ast::expr] args)
+ -> @ast::expr {
- fn make_new_lit(parser p, common.span sp, ast.lit_ lit) -> @ast.expr {
+ fn make_new_lit(parser p, common::span sp, ast::lit_ lit) -> @ast::expr {
auto sp_lit = @rec(node=lit, span=sp);
- auto expr = ast.expr_lit(sp_lit, p.get_ann());
+ auto expr = ast::expr_lit(sp_lit, p.get_ann());
ret @rec(node=expr, span=sp);
}
- fn make_new_str(parser p, common.span sp, str s) -> @ast.expr {
- auto lit = ast.lit_str(s);
+ fn make_new_str(parser p, common::span sp, str s) -> @ast::expr {
+ auto lit = ast::lit_str(s);
ret make_new_lit(p, sp, lit);
}
- fn make_new_int(parser p, common.span sp, int i) -> @ast.expr {
- auto lit = ast.lit_int(i);
+ fn make_new_int(parser p, common::span sp, int i) -> @ast::expr {
+ auto lit = ast::lit_int(i);
ret make_new_lit(p, sp, lit);
}
- fn make_new_uint(parser p, common.span sp, uint u) -> @ast.expr {
- auto lit = ast.lit_uint(u);
+ fn make_new_uint(parser p, common::span sp, uint u) -> @ast::expr {
+ auto lit = ast::lit_uint(u);
ret make_new_lit(p, sp, lit);
}
- fn make_add_expr(parser p, common.span sp,
- @ast.expr lhs, @ast.expr rhs) -> @ast.expr {
- auto binexpr = ast.expr_binary(ast.add, lhs, rhs, p.get_ann());
+ fn make_add_expr(parser p, common::span sp,
+ @ast::expr lhs, @ast::expr rhs) -> @ast::expr {
+ auto binexpr = ast::expr_binary(ast::add, lhs, rhs, p.get_ann());
ret @rec(node=binexpr, span=sp);
}
- fn make_path_expr(parser p, common.span sp, vec[ast.ident] idents)
- -> @ast.expr {
- let vec[@ast.ty] types = vec();
+ fn make_path_expr(parser p, common::span sp, vec[ast::ident] idents)
+ -> @ast::expr {
+ let vec[@ast::ty] types = vec();
auto path = rec(idents=idents, types=types);
auto sp_path = rec(node=path, span=sp);
- auto pathexpr = ast.expr_path(sp_path, p.get_ann());
+ auto pathexpr = ast::expr_path(sp_path, p.get_ann());
auto sp_pathexpr = @rec(node=pathexpr, span=sp);
ret sp_pathexpr;
}
- fn make_vec_expr(parser p, common.span sp, vec[@ast.expr] exprs)
- -> @ast.expr {
- auto vecexpr = ast.expr_vec(exprs, ast.imm, p.get_ann());
+ fn make_vec_expr(parser p, common::span sp, vec[@ast::expr] exprs)
+ -> @ast::expr {
+ auto vecexpr = ast::expr_vec(exprs, ast::imm, p.get_ann());
auto sp_vecexpr = @rec(node=vecexpr, span=sp);
ret sp_vecexpr;
}
- fn make_call(parser p, common.span sp, vec[ast.ident] fn_path,
- vec[@ast.expr] args) -> @ast.expr {
+ fn make_call(parser p, common::span sp, vec[ast::ident] fn_path,
+ vec[@ast::expr] args) -> @ast::expr {
auto pathexpr = make_path_expr(p, sp, fn_path);
- auto callexpr = ast.expr_call(pathexpr, args, p.get_ann());
+ auto callexpr = ast::expr_call(pathexpr, args, p.get_ann());
auto sp_callexpr = @rec(node=callexpr, span=sp);
ret sp_callexpr;
}
- fn make_rec_expr(parser p, common.span sp,
- vec[tup(ast.ident, @ast.expr)] fields) -> @ast.expr {
- let vec[ast.field] astfields = vec();
- for (tup(ast.ident, @ast.expr) field in fields) {
+ fn make_rec_expr(parser p, common::span sp,
+ vec[tup(ast::ident, @ast::expr)] fields) -> @ast::expr {
+ let vec[ast::field] astfields = vec();
+ for (tup(ast::ident, @ast::expr) field in fields) {
auto ident = field._0;
auto val = field._1;
- auto astfield = rec(mut = ast.imm,
+ auto astfield = rec(mut = ast::imm,
ident = ident,
expr = val);
astfields += vec(astfield);
}
- auto recexpr = ast.expr_rec(astfields,
- Option.none[@ast.expr],
+ auto recexpr = ast::expr_rec(astfields,
+ option::none[@ast::expr],
p.get_ann());
auto sp_recexpr = @rec(node=recexpr, span=sp);
ret sp_recexpr;
ret vec("std", "extfmt", "RT", ident);
}
- fn make_rt_path_expr(parser p, common.span sp, str ident) -> @ast.expr {
+ fn make_rt_path_expr(parser p, common::span sp, str ident) -> @ast::expr {
auto path = make_path_vec(ident);
ret make_path_expr(p, 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(parser p, common.span sp, &conv cnv) -> @ast.expr {
+ // 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(parser p, common::span sp, &conv cnv) -> @ast::expr {
- fn make_flags(parser p, common.span sp, vec[flag] flags)
- -> @ast.expr {
- let vec[@ast.expr] flagexprs = vec();
+ fn make_flags(parser p, common::span sp, vec[flag] flags)
+ -> @ast::expr {
+ let vec[@ast::expr] flagexprs = vec();
for (flag f in flags) {
auto fstr;
alt (f) {
// FIXME: 0-length vectors can't have their type inferred
// through the rec that these flags are a member of, so
// this is a hack placeholder flag
- if (Vec.len[@ast.expr](flagexprs) == 0u) {
+ if (_vec::len[@ast::expr](flagexprs) == 0u) {
flagexprs += vec(make_rt_path_expr(p, sp, "flag_none"));
}
ret make_vec_expr(p, sp, flagexprs);
}
- fn make_count(parser p, common.span sp, &count cnt) -> @ast.expr {
+ fn make_count(parser p, common::span sp, &count cnt) -> @ast::expr {
alt (cnt) {
case (count_implied) {
ret make_rt_path_expr(p, sp, "count_implied");
}
}
- fn make_ty(parser p, common.span sp, &ty t) -> @ast.expr {
+ fn make_ty(parser p, common::span sp, &ty t) -> @ast::expr {
auto rt_type;
alt (t) {
case (ty_hex(?c)) {
}
fn make_conv_rec(parser p,
- common.span sp,
- @ast.expr flags_expr,
- @ast.expr width_expr,
- @ast.expr precision_expr,
- @ast.expr ty_expr) -> @ast.expr {
+ common::span sp,
+ @ast::expr flags_expr,
+ @ast::expr width_expr,
+ @ast::expr precision_expr,
+ @ast::expr ty_expr) -> @ast::expr {
ret make_rec_expr(p, sp, vec(tup("flags", flags_expr),
tup("width", width_expr),
tup("precision", precision_expr),
rt_conv_ty);
}
- fn make_conv_call(parser p, common.span sp, str conv_type,
- &conv cnv, @ast.expr arg) -> @ast.expr {
+ fn make_conv_call(parser p, common::span sp, str conv_type,
+ &conv cnv, @ast::expr arg) -> @ast::expr {
auto fname = "conv_" + conv_type;
auto path = make_path_vec(fname);
auto cnv_expr = make_rt_conv_expr(p, sp, cnv);
ret make_call(p, arg.span, path, args);
}
- fn make_new_conv(parser p, conv cnv, @ast.expr arg) -> @ast.expr {
+ fn make_new_conv(parser p, conv cnv, @ast::expr arg) -> @ast::expr {
- // FIXME: Extract all this validation into ExtFmt.CT
+ // FIXME: Extract all this validation into extfmt::CT
fn is_signed_type(conv cnv) -> bool {
alt (cnv.ty) {
case (ty_int(?s)) {
auto unsupported = "conversion not supported in #fmt string";
alt (cnv.param) {
- case (Option.none[int]) {
+ case (option::none[int]) {
}
case (_) {
log_err unsupported;
fn log_conv(conv c) {
alt (c.param) {
case (some[int](?p)) {
- log "param: " + std.Int.to_str(p, 10u);
+ log "param: " + std::_int::to_str(p, 10u);
}
case (_) {
log "param: none";
}
alt (c.width) {
case (count_is(?i)) {
- log "width: count is " + std.Int.to_str(i, 10u);
+ 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);
+ log "width: count is param " + std::_int::to_str(i, 10u);
}
case (count_is_next_param) {
log "width: count is next param";
}
alt (c.precision) {
case (count_is(?i)) {
- log "prec: count is " + std.Int.to_str(i, 10u);
+ 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);
+ log "prec: count is param " + std::_int::to_str(i, 10u);
}
case (count_is_next_param) {
log "prec: count is next param";
tmp_expr = make_add_expr(p, sp, tmp_expr, s_expr);
}
case (piece_conv(?conv)) {
- if (n >= Vec.len[@ast.expr](args)) {
+ if (n >= _vec::len[@ast::expr](args)) {
log_err "too many conversions in #fmt string";
fail;
}
// TODO: Remove this debug logging
// log "dumping expanded ast:";
- // log pretty.print_expr(tmp_expr);
+ // log pretty::print_expr(tmp_expr);
ret tmp_expr;
}
-import std.IO;
-import std.Str;
-import std.Vec;
-import std.Int;
-import std.Map;
-import std.Map.hashmap;
-import std.Option;
-import std.Option.some;
-import std.Option.none;
-import driver.session.session;
-import util.common;
-import util.common.new_str_hash;
+import std::io;
+import std::_str;
+import std::_vec;
+import std::_int;
+import std::map;
+import std::map::hashmap;
+import std::option;
+import std::option::some;
+import std::option::none;
+import driver::session::session;
+import util::common;
+import util::common::new_str_hash;
state type reader = state obj {
fn is_eof() -> bool;
fn bump();
fn mark();
fn get_mark_chpos() -> uint;
- fn add_str(str) -> token.str_num;
- fn get_str(token.str_num) -> str;
+ fn add_str(str) -> token::str_num;
+ fn get_str(token::str_num) -> str;
fn get_chpos() -> uint;
- fn get_keywords() -> hashmap[str,token.token];
+ fn get_keywords() -> hashmap[str,token::token];
fn get_reserved() -> hashmap[str,()];
- fn get_filemap() -> codemap.filemap;
+ fn get_filemap() -> codemap::filemap;
fn err(str m);
};
-fn new_reader(session sess, IO.reader rdr,
- codemap.filemap filemap) -> reader {
+fn new_reader(session sess, io::reader rdr,
+ codemap::filemap filemap) -> reader {
state obj reader(session sess,
str file,
mutable uint mark_chpos,
mutable uint chpos,
mutable vec[str] strs,
- hashmap[str,token.token] keywords,
+ hashmap[str,token::token] keywords,
hashmap[str,()] reserved,
- codemap.filemap fm) {
+ codemap::filemap fm) {
fn is_eof() -> bool {
ret ch == -1 as char;
}
fn next() -> char {
- if (pos < len) {ret Str.char_at(file, pos);}
+ if (pos < len) {ret _str::char_at(file, pos);}
else {ret -1 as char;}
}
fn init() {
if (pos < len) {
- auto next = Str.char_range_at(file, pos);
+ auto next = _str::char_range_at(file, pos);
pos = next._1;
ch = next._0;
}
if (pos < len) {
chpos += 1u;
if (ch == '\n') {
- codemap.next_line(fm, chpos);
+ codemap::next_line(fm, chpos);
}
- auto next = Str.char_range_at(file, pos);
+ auto next = _str::char_range_at(file, pos);
pos = next._1;
ch = next._0;
} else {
}
}
- fn get_keywords() -> hashmap[str,token.token] {
+ fn get_keywords() -> hashmap[str,token::token] {
ret keywords;
}
- fn add_str(str s) -> token.str_num {
+ fn add_str(str s) -> token::str_num {
strs += vec(s);
- ret Vec.len[str](strs) - 1u;
+ ret _vec::len[str](strs) - 1u;
}
- fn get_str(token.str_num i) -> str {
+ fn get_str(token::str_num i) -> str {
ret strs.(i);
}
ret reserved;
}
- fn get_filemap() -> codemap.filemap {
+ fn get_filemap() -> codemap::filemap {
ret fm;
}
sess.span_err(rec(lo=chpos, hi=chpos), m);
}
}
- auto file = Str.unsafe_from_bytes(rdr.read_whole_stream());
+ auto file = _str::unsafe_from_bytes(rdr.read_whole_stream());
let vec[str] strs = vec();
- auto rd = reader(sess, file, Str.byte_len(file), 0u, -1 as char,
+ auto rd = reader(sess, file, _str::byte_len(file), 0u, -1 as char,
filemap.start_pos, filemap.start_pos,
strs, keyword_table(),
reserved_word_table(),
ret rd;
}
-fn keyword_table() -> std.Map.hashmap[str, token.token] {
- auto keywords = new_str_hash[token.token]();
+fn keyword_table() -> std::map::hashmap[str, token::token] {
+ auto keywords = new_str_hash[token::token]();
- keywords.insert("mod", token.MOD);
- keywords.insert("use", token.USE);
- keywords.insert("meta", token.META);
- keywords.insert("auth", token.AUTH);
+ keywords.insert("mod", token::MOD);
+ keywords.insert("use", token::USE);
+ keywords.insert("meta", token::META);
+ keywords.insert("auth", token::AUTH);
- keywords.insert("syntax", token.SYNTAX);
+ keywords.insert("syntax", token::SYNTAX);
- keywords.insert("if", token.IF);
- keywords.insert("else", token.ELSE);
- keywords.insert("while", token.WHILE);
- keywords.insert("do", token.DO);
- keywords.insert("alt", token.ALT);
- keywords.insert("case", token.CASE);
+ keywords.insert("if", token::IF);
+ keywords.insert("else", token::ELSE);
+ keywords.insert("while", token::WHILE);
+ keywords.insert("do", token::DO);
+ keywords.insert("alt", token::ALT);
+ keywords.insert("case", token::CASE);
- keywords.insert("for", token.FOR);
- keywords.insert("each", token.EACH);
- keywords.insert("break", token.BREAK);
- keywords.insert("cont", token.CONT);
- keywords.insert("put", token.PUT);
- keywords.insert("ret", token.RET);
- keywords.insert("be", token.BE);
+ keywords.insert("for", token::FOR);
+ keywords.insert("each", token::EACH);
+ keywords.insert("break", token::BREAK);
+ keywords.insert("cont", token::CONT);
+ keywords.insert("put", token::PUT);
+ keywords.insert("ret", token::RET);
+ keywords.insert("be", token::BE);
- keywords.insert("fail", token.FAIL);
- keywords.insert("drop", token.DROP);
+ keywords.insert("fail", token::FAIL);
+ keywords.insert("drop", token::DROP);
- keywords.insert("type", token.TYPE);
- keywords.insert("check", token.CHECK);
- keywords.insert("assert", token.ASSERT);
- keywords.insert("claim", token.CLAIM);
- keywords.insert("prove", token.PROVE);
+ keywords.insert("type", token::TYPE);
+ keywords.insert("check", token::CHECK);
+ keywords.insert("assert", token::ASSERT);
+ keywords.insert("claim", token::CLAIM);
+ keywords.insert("prove", token::PROVE);
- keywords.insert("state", token.STATE);
- keywords.insert("gc", token.GC);
+ keywords.insert("state", token::STATE);
+ keywords.insert("gc", token::GC);
- keywords.insert("unsafe", token.UNSAFE);
+ keywords.insert("unsafe", token::UNSAFE);
- keywords.insert("native", token.NATIVE);
- keywords.insert("mutable", token.MUTABLE);
- keywords.insert("auto", token.AUTO);
+ keywords.insert("native", token::NATIVE);
+ keywords.insert("mutable", token::MUTABLE);
+ keywords.insert("auto", token::AUTO);
- keywords.insert("fn", token.FN);
- keywords.insert("pred", token.PRED);
- keywords.insert("iter", token.ITER);
+ keywords.insert("fn", token::FN);
+ keywords.insert("pred", token::PRED);
+ keywords.insert("iter", token::ITER);
- keywords.insert("import", token.IMPORT);
- keywords.insert("export", token.EXPORT);
+ keywords.insert("import", token::IMPORT);
+ keywords.insert("export", token::EXPORT);
- keywords.insert("let", token.LET);
- keywords.insert("const", token.CONST);
+ keywords.insert("let", token::LET);
+ keywords.insert("const", token::CONST);
- keywords.insert("log", token.LOG);
- keywords.insert("log_err", token.LOG_ERR);
- keywords.insert("spawn", token.SPAWN);
- keywords.insert("thread", token.THREAD);
- keywords.insert("yield", token.YIELD);
- keywords.insert("join", token.JOIN);
+ keywords.insert("log", token::LOG);
+ keywords.insert("log_err", token::LOG_ERR);
+ keywords.insert("spawn", token::SPAWN);
+ keywords.insert("thread", token::THREAD);
+ keywords.insert("yield", token::YIELD);
+ keywords.insert("join", token::JOIN);
- keywords.insert("bool", token.BOOL);
+ keywords.insert("bool", token::BOOL);
- keywords.insert("int", token.INT);
- keywords.insert("uint", token.UINT);
- keywords.insert("float", token.FLOAT);
+ keywords.insert("int", token::INT);
+ keywords.insert("uint", token::UINT);
+ keywords.insert("float", token::FLOAT);
- keywords.insert("char", token.CHAR);
- keywords.insert("str", token.STR);
+ keywords.insert("char", token::CHAR);
+ keywords.insert("str", token::STR);
- keywords.insert("rec", token.REC);
- keywords.insert("tup", token.TUP);
- keywords.insert("tag", token.TAG);
- keywords.insert("vec", token.VEC);
- keywords.insert("any", token.ANY);
+ keywords.insert("rec", token::REC);
+ keywords.insert("tup", token::TUP);
+ keywords.insert("tag", token::TAG);
+ keywords.insert("vec", token::VEC);
+ keywords.insert("any", token::ANY);
- keywords.insert("obj", token.OBJ);
- keywords.insert("self", token.SELF);
+ keywords.insert("obj", token::OBJ);
+ keywords.insert("self", token::SELF);
- keywords.insert("port", token.PORT);
- keywords.insert("chan", token.CHAN);
+ keywords.insert("port", token::PORT);
+ keywords.insert("chan", token::CHAN);
- keywords.insert("task", token.TASK);
+ keywords.insert("task", token::TASK);
- keywords.insert("true", token.LIT_BOOL(true));
- keywords.insert("false", token.LIT_BOOL(false));
+ keywords.insert("true", token::LIT_BOOL(true));
+ keywords.insert("false", token::LIT_BOOL(false));
- keywords.insert("in", token.IN);
+ keywords.insert("in", token::IN);
- keywords.insert("as", token.AS);
- keywords.insert("with", token.WITH);
+ keywords.insert("as", token::AS);
+ keywords.insert("with", token::WITH);
- keywords.insert("bind", token.BIND);
+ keywords.insert("bind", token::BIND);
- keywords.insert("u8", token.MACH(common.ty_u8));
- keywords.insert("u16", token.MACH(common.ty_u16));
- keywords.insert("u32", token.MACH(common.ty_u32));
- keywords.insert("u64", token.MACH(common.ty_u64));
- keywords.insert("i8", token.MACH(common.ty_i8));
- keywords.insert("i16", token.MACH(common.ty_i16));
- keywords.insert("i32", token.MACH(common.ty_i32));
- keywords.insert("i64", token.MACH(common.ty_i64));
- keywords.insert("f32", token.MACH(common.ty_f32));
- keywords.insert("f64", token.MACH(common.ty_f64));
+ keywords.insert("u8", token::MACH(common::ty_u8));
+ keywords.insert("u16", token::MACH(common::ty_u16));
+ keywords.insert("u32", token::MACH(common::ty_u32));
+ keywords.insert("u64", token::MACH(common::ty_u64));
+ keywords.insert("i8", token::MACH(common::ty_i8));
+ keywords.insert("i16", token::MACH(common::ty_i16));
+ keywords.insert("i32", token::MACH(common::ty_i32));
+ keywords.insert("i64", token::MACH(common::ty_i64));
+ keywords.insert("f32", token::MACH(common::ty_f32));
+ keywords.insert("f64", token::MACH(common::ty_f64));
ret keywords;
}
-fn reserved_word_table() -> std.Map.hashmap[str, ()] {
+fn reserved_word_table() -> std::map::hashmap[str, ()] {
auto reserved = new_str_hash[()]();
reserved.insert("f16", ()); // IEEE 754-2008 'binary16' interchange fmt
reserved.insert("f80", ()); // IEEE 754-1985 'extended'
ret accum_int;
}
-fn scan_exponent(reader rdr) -> Option.t[str] {
+fn scan_exponent(reader rdr) -> option::t[str] {
auto c = rdr.curr();
auto res = "";
if (c == 'e' || c == 'E') {
- res += Str.from_bytes(vec(c as u8));
+ res += _str::from_bytes(vec(c as u8));
rdr.bump();
c = rdr.curr();
if (c == '-' || c == '+') {
- res += Str.from_bytes(vec(c as u8));
+ res += _str::from_bytes(vec(c as u8));
rdr.bump();
}
auto exponent = scan_dec_digits(rdr);
- if (Str.byte_len(exponent) > 0u) {
+ if (_str::byte_len(exponent) > 0u) {
ret(some(res + exponent));
}
else {
while (is_dec_digit (c) || c == '_') {
if (c != '_') {
- res += Str.from_bytes(vec(c as u8));
+ res += _str::from_bytes(vec(c as u8));
}
rdr.bump();
c = rdr.curr();
ret res;
}
-fn scan_number(char c, reader rdr) -> token.token {
+fn scan_number(char c, reader rdr) -> token::token {
auto accum_int = 0;
let str dec_str = "";
let bool is_dec_integer = false;
if (c == '8') {
rdr.bump();
if (signed) {
- ret token.LIT_MACH_INT(common.ty_i8, accum_int);
+ ret token::LIT_MACH_INT(common::ty_i8, accum_int);
} else {
- ret token.LIT_MACH_INT(common.ty_u8, accum_int);
+ ret token::LIT_MACH_INT(common::ty_u8, accum_int);
}
}
rdr.bump();
rdr.bump();
if (signed) {
- ret token.LIT_MACH_INT(common.ty_i16, accum_int);
+ ret token::LIT_MACH_INT(common::ty_i16, accum_int);
} else {
- ret token.LIT_MACH_INT(common.ty_u16, accum_int);
+ ret token::LIT_MACH_INT(common::ty_u16, accum_int);
}
}
if (c == '3' && n == '2') {
rdr.bump();
rdr.bump();
if (signed) {
- ret token.LIT_MACH_INT(common.ty_i32, accum_int);
+ ret token::LIT_MACH_INT(common::ty_i32, accum_int);
} else {
- ret token.LIT_MACH_INT(common.ty_u32, accum_int);
+ ret token::LIT_MACH_INT(common::ty_u32, accum_int);
}
}
rdr.bump();
rdr.bump();
if (signed) {
- ret token.LIT_MACH_INT(common.ty_i64, accum_int);
+ ret token::LIT_MACH_INT(common::ty_i64, accum_int);
} else {
- ret token.LIT_MACH_INT(common.ty_u64, accum_int);
+ ret token::LIT_MACH_INT(common::ty_u64, accum_int);
}
}
if (signed) {
- ret token.LIT_INT(accum_int);
+ ret token::LIT_INT(accum_int);
} else {
// FIXME: should cast in the target bit-width.
- ret token.LIT_UINT(accum_int as uint);
+ ret token::LIT_UINT(accum_int as uint);
}
}
c = rdr.curr();
n = rdr.next();
if (c == '3' && n == '2') {
rdr.bump(); rdr.bump();
- ret token.LIT_MACH_FLOAT(util.common.ty_f32,
+ ret token::LIT_MACH_FLOAT(util::common::ty_f32,
rdr.add_str(float_str));
}
else if (c == '6' && n == '4') {
rdr.bump(); rdr.bump();
- ret token.LIT_MACH_FLOAT(util.common.ty_f64,
+ ret token::LIT_MACH_FLOAT(util::common::ty_f64,
rdr.add_str(float_str));
/* FIXME: if this is out of range for either a 32-bit or
64-bit float, it won't be noticed till the back-end */
}
}
else {
- ret token.LIT_FLOAT(rdr.add_str(float_str));
+ ret token::LIT_FLOAT(rdr.add_str(float_str));
}
}
auto maybe_exponent = scan_exponent(rdr);
alt(maybe_exponent) {
case(some[str](?s)) {
- ret token.LIT_FLOAT(rdr.add_str(dec_str + s));
+ ret token::LIT_FLOAT(rdr.add_str(dec_str + s));
}
case(none[str]) {
- ret token.LIT_INT(accum_int);
+ ret token::LIT_INT(accum_int);
}
}
}
}
-fn next_token(reader rdr) -> token.token {
+fn next_token(reader rdr) -> token::token {
auto accum_str = "";
consume_any_whitespace(rdr);
- if (rdr.is_eof()) { ret token.EOF; }
+ if (rdr.is_eof()) { ret token::EOF; }
rdr.mark();
auto c = rdr.curr();
if (is_alpha(c) || c == '_') {
while (is_alnum(c) || c == '_') {
- Str.push_char(accum_str, c);
+ _str::push_char(accum_str, c);
rdr.bump();
c = rdr.curr();
}
- if (Str.eq(accum_str, "_")) {
- ret token.UNDERSCORE;
+ if (_str::eq(accum_str, "_")) {
+ ret token::UNDERSCORE;
}
auto kwds = rdr.get_keywords();
fail;
}
- ret token.IDENT(rdr.add_str(accum_str));
+ ret token::IDENT(rdr.add_str(accum_str));
}
if (is_dec_digit(c)) {
ret scan_number(c, rdr);
}
- fn binop(reader rdr, token.binop op) -> token.token {
+ fn binop(reader rdr, token::binop op) -> token::token {
rdr.bump();
if (rdr.curr() == '=') {
rdr.bump();
- ret token.BINOPEQ(op);
+ ret token::BINOPEQ(op);
} else {
- ret token.BINOP(op);
+ 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(); 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(); ret token.POUND; }
- case ('~') { rdr.bump(); ret token.TILDE; }
+ case ('?') { rdr.bump(); ret token::QUES; }
+ case (';') { rdr.bump(); ret token::SEMI; }
+ case (',') { rdr.bump(); ret token::COMMA; }
+ case ('.') { rdr.bump(); 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(); ret token::POUND; }
+ case ('~') { rdr.bump(); ret token::TILDE; }
case (':') {
rdr.bump();
if (rdr.curr() == ':') {
rdr.bump();
- ret token.MOD_SEP;
+ ret token::MOD_SEP;
}
else {
- ret token.COLON;
+ ret token::COLON;
};
}
rdr.bump();
if (rdr.curr() == '=') {
rdr.bump();
- ret token.EQEQ;
+ ret token::EQEQ;
} else {
- ret token.EQ;
+ ret token::EQ;
}
}
rdr.bump();
if (rdr.curr() == '=') {
rdr.bump();
- ret token.NE;
+ ret token::NE;
} else {
- ret token.NOT;
+ ret token::NOT;
}
}
alt (rdr.curr()) {
case ('=') {
rdr.bump();
- ret token.LE;
+ ret token::LE;
}
case ('<') {
- ret binop(rdr, token.LSL);
+ ret binop(rdr, token::LSL);
}
case ('-') {
rdr.bump();
- ret token.LARROW;
+ ret token::LARROW;
}
case ('|') {
rdr.bump();
- ret token.SEND;
+ ret token::SEND;
}
case (_) {
- ret token.LT;
+ ret token::LT;
}
}
}
alt (rdr.curr()) {
case ('=') {
rdr.bump();
- ret token.GE;
+ ret token::GE;
}
case ('>') {
if (rdr.next() == '>') {
rdr.bump();
- ret binop(rdr, token.ASR);
+ ret binop(rdr, token::ASR);
} else {
- ret binop(rdr, token.LSR);
+ ret binop(rdr, token::LSR);
}
}
case (_) {
- ret token.GT;
+ ret token::GT;
}
}
}
}
rdr.bump(); // advance curr to closing '
rdr.bump(); // advance curr past token
- ret token.LIT_CHAR(c2);
+ ret token::LIT_CHAR(c2);
}
case ('"') {
alt (rdr.next()) {
case ('n') {
rdr.bump();
- Str.push_byte(accum_str, '\n' as u8);
+ _str::push_byte(accum_str, '\n' as u8);
}
case ('r') {
rdr.bump();
- Str.push_byte(accum_str, '\r' as u8);
+ _str::push_byte(accum_str, '\r' as u8);
}
case ('t') {
rdr.bump();
- Str.push_byte(accum_str, '\t' as u8);
+ _str::push_byte(accum_str, '\t' as u8);
}
case ('\\') {
rdr.bump();
- Str.push_byte(accum_str, '\\' as u8);
+ _str::push_byte(accum_str, '\\' as u8);
}
case ('"') {
rdr.bump();
- Str.push_byte(accum_str, '"' as u8);
+ _str::push_byte(accum_str, '"' as u8);
}
case ('x') {
- Str.push_char(accum_str,
+ _str::push_char(accum_str,
scan_numeric_escape(rdr));
}
case ('u') {
- Str.push_char(accum_str,
+ _str::push_char(accum_str,
scan_numeric_escape(rdr));
}
case ('U') {
- Str.push_char(accum_str,
+ _str::push_char(accum_str,
scan_numeric_escape(rdr));
}
}
}
case (_) {
- Str.push_char(accum_str, rdr.curr());
+ _str::push_char(accum_str, rdr.curr());
}
}
rdr.bump();
}
rdr.bump();
- ret token.LIT_STR(rdr.add_str(accum_str));
+ ret token::LIT_STR(rdr.add_str(accum_str));
}
case ('-') {
if (rdr.next() == '>') {
rdr.bump();
rdr.bump();
- ret token.RARROW;
+ ret token::RARROW;
} else {
- ret binop(rdr, token.MINUS);
+ ret binop(rdr, token::MINUS);
}
}
if (rdr.next() == '&') {
rdr.bump();
rdr.bump();
- ret token.ANDAND;
+ ret token::ANDAND;
} else {
- ret binop(rdr, token.AND);
+ ret binop(rdr, token::AND);
}
}
if (rdr.next() == '|') {
rdr.bump();
rdr.bump();
- ret token.OROR;
+ ret token::OROR;
} else {
- ret binop(rdr, token.OR);
+ ret binop(rdr, token::OR);
}
}
case ('+') {
- ret binop(rdr, token.PLUS);
+ ret binop(rdr, token::PLUS);
}
case ('*') {
- ret binop(rdr, token.STAR);
+ ret binop(rdr, token::STAR);
}
case ('/') {
- ret binop(rdr, token.SLASH);
+ ret binop(rdr, token::SLASH);
}
case ('^') {
- ret binop(rdr, token.CARET);
+ ret binop(rdr, token::CARET);
}
case ('%') {
- ret binop(rdr, token.PERCENT);
+ ret binop(rdr, token::PERCENT);
}
case (?c) {
while (rdr.curr() == ' ') {rdr.bump();}
auto val = "";
while (rdr.curr() != '\n' && !rdr.is_eof()) {
- Str.push_char(val, rdr.curr());
+ _str::push_char(val, rdr.curr());
rdr.bump();
}
ret rec(val=cmnt_line(val),
auto level = 1;
while (true) {
if (rdr.curr() == '\n') {
- Vec.push[str](lines, val);
+ _vec::push[str](lines, val);
val = "";
consume_whitespace(rdr);
} else {
level -= 1;
if (level == 0) {
rdr.bump(); rdr.bump();
- Vec.push[str](lines, val);
+ _vec::push[str](lines, val);
break;
}
} else if (rdr.curr() == '/' && rdr.next() == '*') {
level += 1;
}
- Str.push_char(val, rdr.curr());
+ _str::push_char(val, rdr.curr());
rdr.bump();
}
if (rdr.is_eof()) {
}
fn gather_comments(session sess, str path) -> vec[cmnt] {
- auto srdr = IO.file_reader(path);
- auto rdr = new_reader(sess, srdr, codemap.new_filemap(path, 0u));
+ auto srdr = io::file_reader(path);
+ auto rdr = new_reader(sess, srdr, codemap::new_filemap(path, 0u));
let vec[cmnt] comments = vec();
while (!rdr.is_eof()) {
while (true) {
consume_whitespace(rdr);
if (rdr.curr() == '/' && rdr.next() == '/') {
- Vec.push[cmnt](comments, read_line_comment(rdr));
+ _vec::push[cmnt](comments, read_line_comment(rdr));
} else if (rdr.curr() == '/' && rdr.next() == '*') {
- Vec.push[cmnt](comments, read_block_comment(rdr));
+ _vec::push[cmnt](comments, read_block_comment(rdr));
} else { break; }
}
next_token(rdr);
-import std.IO;
-import std.Vec;
-import std.Str;
-import std.Option;
-import std.Option.some;
-import std.Option.none;
-import std.Map.hashmap;
-
-import driver.session;
-import util.common;
-import util.common.filename;
-import util.common.span;
-import util.common.new_str_hash;
+import std::io;
+import std::_vec;
+import std::_str;
+import std::option;
+import std::option::some;
+import std::option::none;
+import std::map::hashmap;
+
+import driver::session;
+import util::common;
+import util::common::filename;
+import util::common::span;
+import util::common::new_str_hash;
tag restriction {
UNRESTRICTED;
state type parser =
state obj {
- fn peek() -> token.token;
+ fn peek() -> token::token;
fn bump();
fn err(str s);
fn restrict(restriction r);
fn get_restriction() -> restriction;
fn get_file_type() -> file_type;
- fn get_env() -> eval.env;
- fn get_session() -> session.session;
- fn get_span() -> common.span;
+ fn get_env() -> eval::env;
+ fn get_session() -> session::session;
+ fn get_span() -> common::span;
fn get_lo_pos() -> uint;
fn get_hi_pos() -> uint;
- fn next_def_id() -> ast.def_id;
- fn set_def(ast.def_num);
+ fn next_def_id() -> ast::def_id;
+ fn set_def(ast::def_num);
fn get_prec_table() -> vec[op_spec];
- fn get_str(token.str_num) -> str;
- fn get_reader() -> lexer.reader;
- fn get_filemap() -> codemap.filemap;
+ fn get_str(token::str_num) -> str;
+ fn get_reader() -> lexer::reader;
+ fn get_filemap() -> codemap::filemap;
fn get_chpos() -> uint;
- fn get_ann() -> ast.ann;
+ fn get_ann() -> ast::ann;
fn next_ann_num() -> uint;
};
-fn new_parser(session.session sess,
- eval.env env,
- ast.def_id initial_def,
+fn new_parser(session::session sess,
+ eval::env env,
+ ast::def_id initial_def,
str path, uint pos, uint next_ann) -> parser {
- state obj stdio_parser(session.session sess,
- eval.env env,
+ state obj stdio_parser(session::session sess,
+ eval::env env,
file_type ftype,
- mutable token.token tok,
+ mutable token::token tok,
mutable uint lo,
mutable uint hi,
- mutable ast.def_num def,
+ mutable ast::def_num def,
mutable restriction res,
- ast.crate_num crate,
- lexer.reader rdr,
+ ast::crate_num crate,
+ lexer::reader rdr,
vec[op_spec] precs,
mutable uint next_ann_var)
{
- fn peek() -> token.token {
+ fn peek() -> token::token {
ret tok;
}
fn bump() {
// log rdr.get_filename()
- // + ":" + common.istr(lo.line as int);
- tok = lexer.next_token(rdr);
+ // + ":" + common::istr(lo.line as int);
+ tok = lexer::next_token(rdr);
lo = rdr.get_mark_chpos();
hi = rdr.get_chpos();
}
ret res;
}
- fn get_session() -> session.session {
+ fn get_session() -> session::session {
ret sess;
}
- fn get_span() -> common.span { ret rec(lo=lo, hi=hi); }
+ fn get_span() -> common::span { ret rec(lo=lo, hi=hi); }
fn get_lo_pos() -> uint { ret lo; }
fn get_hi_pos() -> uint { ret hi; }
- fn next_def_id() -> ast.def_id {
+ fn next_def_id() -> ast::def_id {
def += 1;
ret tup(crate, def);
}
- fn set_def(ast.def_num d) {
+ fn set_def(ast::def_num d) {
def = d;
}
ret ftype;
}
- fn get_env() -> eval.env {
+ fn get_env() -> eval::env {
ret env;
}
ret precs;
}
- fn get_str(token.str_num i) -> str {
+ fn get_str(token::str_num i) -> str {
ret rdr.get_str(i);
}
- fn get_reader() -> lexer.reader {
+ fn get_reader() -> lexer::reader {
ret rdr;
}
- fn get_filemap() -> codemap.filemap {
+ fn get_filemap() -> codemap::filemap {
ret rdr.get_filemap();
}
fn get_chpos() -> uint {ret rdr.get_chpos();}
- fn get_ann() -> ast.ann {
- auto rv = ast.ann_none(next_ann_var);
+ fn get_ann() -> ast::ann {
+ auto rv = ast::ann_none(next_ann_var);
next_ann_var += 1u;
ret rv;
}
}
}
auto ftype = SOURCE_FILE;
- if (Str.ends_with(path, ".rc")) {
+ if (_str::ends_with(path, ".rc")) {
ftype = CRATE_FILE;
}
- auto srdr = IO.file_reader(path);
- auto filemap = codemap.new_filemap(path, pos);
- Vec.push[codemap.filemap](sess.get_codemap().files, filemap);
- auto rdr = lexer.new_reader(sess, srdr, filemap);
- // Make sure npos points at first actual token.
- lexer.consume_any_whitespace(rdr);
+ auto srdr = io::file_reader(path);
+ auto filemap = codemap::new_filemap(path, pos);
+ _vec::push[codemap::filemap](sess.get_codemap().files, filemap);
+ auto rdr = lexer::new_reader(sess, srdr, filemap);
+ // Make sure npos points at first actual token:
+ lexer::consume_any_whitespace(rdr);
auto npos = rdr.get_chpos();
- ret stdio_parser(sess, env, ftype, lexer.next_token(rdr),
+ ret stdio_parser(sess, env, ftype, lexer::next_token(rdr),
npos, npos, initial_def._1, UNRESTRICTED, initial_def._0,
rdr, prec_table(), next_ann);
}
-fn unexpected(parser p, token.token t) {
+fn unexpected(parser p, token::token t) {
let str s = "unexpected token: ";
- s += token.to_str(p.get_reader(), t);
+ s += token::to_str(p.get_reader(), t);
p.err(s);
}
-fn expect(parser p, token.token t) {
+fn expect(parser p, token::token t) {
if (p.peek() == t) {
p.bump();
} else {
let str s = "expecting ";
- s += token.to_str(p.get_reader(), t);
+ s += token::to_str(p.get_reader(), t);
s += ", found ";
- s += token.to_str(p.get_reader(), p.peek());
+ s += token::to_str(p.get_reader(), p.peek());
p.err(s);
}
}
-fn spanned[T](uint lo, uint hi, &T node) -> ast.spanned[T] {
+fn spanned[T](uint lo, uint hi, &T node) -> ast::spanned[T] {
ret rec(node=node, span=rec(lo=lo, hi=hi));
}
-fn parse_ident(parser p) -> ast.ident {
+fn parse_ident(parser p) -> ast::ident {
alt (p.peek()) {
- case (token.IDENT(?i)) { p.bump(); ret p.get_str(i); }
+ case (token::IDENT(?i)) { p.bump(); ret p.get_str(i); }
case (_) {
p.err("expecting ident");
fail;
* lexical sytnax-extension or something similar. For now we just imitate
* rustboot.
*/
-fn parse_str_lit_or_env_ident(parser p) -> ast.ident {
+fn parse_str_lit_or_env_ident(parser p) -> ast::ident {
alt (p.peek()) {
- case (token.LIT_STR(?s)) { p.bump(); ret p.get_str(s); }
- case (token.IDENT(?i)) {
- auto v = eval.lookup(p.get_session(), p.get_env(),
+ case (token::LIT_STR(?s)) { p.bump(); ret p.get_str(s); }
+ case (token::IDENT(?i)) {
+ auto v = eval::lookup(p.get_session(), p.get_env(),
p.get_span(), p.get_str(i));
- if (!eval.val_is_str(v)) {
+ if (!eval::val_is_str(v)) {
p.err("expecting string-valued variable");
}
p.bump();
- ret eval.val_as_str(v);
+ ret eval::val_as_str(v);
}
case (_) {
p.err("expecting string literal");
}
-fn parse_ty_fn(ast.proto proto, parser p, uint lo)
- -> ast.ty_ {
- fn parse_fn_input_ty(parser p) -> rec(ast.mode mode, @ast.ty ty) {
+fn parse_ty_fn(ast::proto proto, parser p, uint lo)
+ -> ast::ty_ {
+ fn parse_fn_input_ty(parser p) -> rec(ast::mode mode, @ast::ty ty) {
auto mode;
- if (p.peek() == token.BINOP(token.AND)) {
+ if (p.peek() == token::BINOP(token::AND)) {
p.bump();
- mode = ast.alias;
+ mode = ast::alias;
- if (p.peek() == token.MUTABLE) {
+ if (p.peek() == token::MUTABLE) {
p.bump();
// TODO: handle mutable alias args
}
} else {
- mode = ast.val;
+ mode = ast::val;
}
auto t = parse_ty(p);
alt (p.peek()) {
- case (token.IDENT(_)) { p.bump(); /* ignore the param name */ }
+ case (token::IDENT(_)) { p.bump(); /* ignore the param name */ }
case (_) { /* no param name present */ }
}
auto lo = p.get_lo_pos();
auto f = parse_fn_input_ty; // FIXME: trans_const_lval bug
- auto inputs = parse_seq[rec(ast.mode mode, @ast.ty ty)](token.LPAREN,
- token.RPAREN, some(token.COMMA), f, p);
+ auto inputs = parse_seq[rec(ast::mode mode, @ast::ty ty)](token::LPAREN,
+ token::RPAREN, some(token::COMMA), f, p);
// FIXME: dropping constrs on the floor at the moment.
// pick them up when they're used by typestate pass.
parse_constrs(p);
- let @ast.ty output;
- if (p.peek() == token.RARROW) {
+ let @ast::ty output;
+ if (p.peek() == token::RARROW) {
p.bump();
output = parse_ty(p);
} else {
- output = @spanned(lo, inputs.span.hi, ast.ty_nil);
+ output = @spanned(lo, inputs.span.hi, ast::ty_nil);
}
- ret ast.ty_fn(proto, inputs.node, output);
+ ret ast::ty_fn(proto, inputs.node, output);
}
-fn parse_proto(parser p) -> ast.proto {
+fn parse_proto(parser p) -> ast::proto {
alt (p.peek()) {
- case (token.ITER) { p.bump(); ret ast.proto_iter; }
- case (token.FN) { p.bump(); ret ast.proto_fn; }
- case (token.PRED) { p.bump(); ret ast.proto_fn; }
+ case (token::ITER) { p.bump(); ret ast::proto_iter; }
+ case (token::FN) { p.bump(); ret ast::proto_fn; }
+ case (token::PRED) { p.bump(); ret ast::proto_fn; }
case (?t) { unexpected(p, t); }
}
fail;
}
-fn parse_ty_obj(parser p, &mutable uint hi) -> ast.ty_ {
- expect(p, token.OBJ);
- fn parse_method_sig(parser p) -> ast.ty_method {
+fn parse_ty_obj(parser p, &mutable uint hi) -> ast::ty_ {
+ expect(p, token::OBJ);
+ fn parse_method_sig(parser p) -> ast::ty_method {
auto flo = p.get_lo_pos();
- let ast.proto proto = parse_proto(p);
+ let ast::proto proto = parse_proto(p);
auto ident = parse_ident(p);
auto f = parse_ty_fn(proto, p, flo);
- expect(p, token.SEMI);
+ expect(p, token::SEMI);
alt (f) {
- case (ast.ty_fn(?proto, ?inputs, ?output)) {
+ case (ast::ty_fn(?proto, ?inputs, ?output)) {
ret rec(proto=proto, ident=ident,
inputs=inputs, output=output);
}
}
auto f = parse_method_sig;
auto meths =
- parse_seq[ast.ty_method](token.LBRACE,
- token.RBRACE,
- none[token.token],
+ parse_seq[ast::ty_method](token::LBRACE,
+ token::RBRACE,
+ none[token::token],
f, p);
hi = meths.span.hi;
- ret ast.ty_obj(meths.node);
+ ret ast::ty_obj(meths.node);
}
-fn parse_mt(parser p) -> ast.mt {
+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_ty_field(parser p) -> ast.ty_field {
+fn parse_ty_field(parser p) -> ast::ty_field {
auto mt = parse_mt(p);
auto id = parse_ident(p);
ret rec(ident=id, mt=mt);
}
-fn parse_constr_arg(parser p) -> @ast.constr_arg {
+fn parse_constr_arg(parser p) -> @ast::constr_arg {
auto sp = p.get_span();
- auto carg = ast.carg_base;
- if (p.peek() == token.BINOP(token.STAR)) {
+ auto carg = ast::carg_base;
+ if (p.peek() == token::BINOP(token::STAR)) {
p.bump();
} else {
- carg = ast.carg_ident(parse_ident(p));
+ carg = ast::carg_ident(parse_ident(p));
}
ret @rec(node=carg, span=sp);
}
-fn parse_ty_constr(parser p) -> @ast.constr {
+fn parse_ty_constr(parser p) -> @ast::constr {
auto lo = p.get_lo_pos();
auto path = parse_path(p);
auto pf = parse_constr_arg;
- auto args = parse_seq[@ast.constr_arg](token.LPAREN,
- token.RPAREN,
- some(token.COMMA), pf, p);
+ auto args = parse_seq[@ast::constr_arg](token::LPAREN,
+ token::RPAREN,
+ some(token::COMMA), pf, p);
ret @spanned(lo, args.span.hi, rec(path=path, args=args.node));
}
-fn parse_constrs(parser p) -> common.spanned[vec[@ast.constr]] {
+fn parse_constrs(parser p) -> common::spanned[vec[@ast::constr]] {
auto lo = p.get_lo_pos();
auto hi = p.get_hi_pos();
- let vec[@ast.constr] constrs = vec();
- if (p.peek() == token.COLON) {
+ let vec[@ast::constr] constrs = vec();
+ if (p.peek() == token::COLON) {
p.bump();
while (true) {
auto constr = parse_ty_constr(p);
hi = constr.span.hi;
- Vec.push[@ast.constr](constrs, constr);
- if (p.peek() == token.COMMA) {
+ _vec::push[@ast::constr](constrs, constr);
+ if (p.peek() == token::COMMA) {
p.bump();
} else {
break;
ret spanned(lo, hi, constrs);
}
-fn parse_ty_constrs(@ast.ty t, parser p) -> @ast.ty {
- if (p.peek() == token.COLON) {
+fn parse_ty_constrs(@ast::ty t, parser p) -> @ast::ty {
+ if (p.peek() == token::COLON) {
auto constrs = parse_constrs(p);
ret @spanned(t.span.lo, constrs.span.hi,
- ast.ty_constr(t, constrs.node));
+ ast::ty_constr(t, constrs.node));
}
ret t;
}
-fn parse_ty(parser p) -> @ast.ty {
+fn parse_ty(parser p) -> @ast::ty {
auto lo = p.get_lo_pos();
auto hi = lo;
- let ast.ty_ t;
+ let ast::ty_ t;
// FIXME: do something with this
- let ast.layer lyr = parse_layer(p);
+ let ast::layer lyr = parse_layer(p);
alt (p.peek()) {
- case (token.BOOL) { p.bump(); t = ast.ty_bool; }
- case (token.INT) { p.bump(); t = ast.ty_int; }
- case (token.UINT) { p.bump(); t = ast.ty_uint; }
- case (token.FLOAT) { p.bump(); t = ast.ty_float; }
- case (token.STR) { p.bump(); t = ast.ty_str; }
- case (token.CHAR) { p.bump(); t = ast.ty_char; }
- case (token.MACH(?tm)) { p.bump(); t = ast.ty_machine(tm); }
-
- case (token.LPAREN) {
+ case (token::BOOL) { p.bump(); t = ast::ty_bool; }
+ case (token::INT) { p.bump(); t = ast::ty_int; }
+ case (token::UINT) { p.bump(); t = ast::ty_uint; }
+ case (token::FLOAT) { p.bump(); t = ast::ty_float; }
+ case (token::STR) { p.bump(); t = ast::ty_str; }
+ case (token::CHAR) { p.bump(); t = ast::ty_char; }
+ case (token::MACH(?tm)) { p.bump(); t = ast::ty_machine(tm); }
+
+ case (token::LPAREN) {
p.bump();
alt (p.peek()) {
- case (token.RPAREN) {
+ case (token::RPAREN) {
hi = p.get_hi_pos();
p.bump();
- t = ast.ty_nil;
+ t = ast::ty_nil;
}
case (_) {
t = parse_ty(p).node;
hi = p.get_hi_pos();
- expect(p, token.RPAREN);
+ expect(p, token::RPAREN);
}
}
}
- case (token.AT) {
+ case (token::AT) {
p.bump();
auto mt = parse_mt(p);
hi = mt.ty.span.hi;
- t = ast.ty_box(mt);
+ t = ast::ty_box(mt);
}
- case (token.VEC) {
+ case (token::VEC) {
p.bump();
- expect(p, token.LBRACKET);
- t = ast.ty_vec(parse_mt(p));
+ expect(p, token::LBRACKET);
+ t = ast::ty_vec(parse_mt(p));
hi = p.get_hi_pos();
- expect(p, token.RBRACKET);
+ expect(p, token::RBRACKET);
}
- case (token.TUP) {
+ case (token::TUP) {
p.bump();
auto f = parse_mt; // FIXME: trans_const_lval bug
- auto elems = parse_seq[ast.mt] (token.LPAREN,
- token.RPAREN,
- some(token.COMMA), f, p);
+ auto elems = parse_seq[ast::mt] (token::LPAREN,
+ token::RPAREN,
+ some(token::COMMA), f, p);
hi = elems.span.hi;
- t = ast.ty_tup(elems.node);
+ t = ast::ty_tup(elems.node);
}
- case (token.REC) {
+ case (token::REC) {
p.bump();
auto f = parse_ty_field; // FIXME: trans_const_lval bug
auto elems =
- parse_seq[ast.ty_field](token.LPAREN,
- token.RPAREN,
- some(token.COMMA),
+ parse_seq[ast::ty_field](token::LPAREN,
+ token::RPAREN,
+ some(token::COMMA),
f, p);
hi = elems.span.hi;
- t = ast.ty_rec(elems.node);
+ t = ast::ty_rec(elems.node);
}
- case (token.FN) {
+ case (token::FN) {
auto flo = p.get_lo_pos();
p.bump();
- t = parse_ty_fn(ast.proto_fn, p, flo);
+ t = parse_ty_fn(ast::proto_fn, p, flo);
alt (t) {
- case (ast.ty_fn(_, _, ?out)) {
+ case (ast::ty_fn(_, _, ?out)) {
hi = out.span.hi;
}
}
}
- case (token.ITER) {
+ case (token::ITER) {
auto flo = p.get_lo_pos();
p.bump();
- t = parse_ty_fn(ast.proto_iter, p, flo);
+ t = parse_ty_fn(ast::proto_iter, p, flo);
alt (t) {
- case (ast.ty_fn(_, _, ?out)) {
+ case (ast::ty_fn(_, _, ?out)) {
hi = out.span.hi;
}
}
}
- case (token.OBJ) {
+ case (token::OBJ) {
t = parse_ty_obj(p, hi);
}
- case (token.PORT) {
+ case (token::PORT) {
p.bump();
- expect(p, token.LBRACKET);
- t = ast.ty_port(parse_ty(p));
+ expect(p, token::LBRACKET);
+ t = ast::ty_port(parse_ty(p));
hi = p.get_hi_pos();
- expect(p, token.RBRACKET);
+ expect(p, token::RBRACKET);
}
- case (token.CHAN) {
+ case (token::CHAN) {
p.bump();
- expect(p, token.LBRACKET);
- t = ast.ty_chan(parse_ty(p));
+ expect(p, token::LBRACKET);
+ t = ast::ty_chan(parse_ty(p));
hi = p.get_hi_pos();
- expect(p, token.RBRACKET);
+ expect(p, token::RBRACKET);
}
- case (token.IDENT(_)) {
+ case (token::IDENT(_)) {
auto path = parse_path(p);
- t = ast.ty_path(path, p.get_ann());
+ t = ast::ty_path(path, p.get_ann());
hi = path.span.hi;
}
- case (token.MUTABLE) {
+ case (token::MUTABLE) {
p.bump();
p.get_session().span_warn(p.get_span(),
"ignoring deprecated 'mutable' type constructor");
case (_) {
p.err("expecting type");
- t = ast.ty_nil;
+ t = ast::ty_nil;
fail;
}
}
ret parse_ty_constrs(@spanned(lo, hi, t), p);
}
-fn parse_arg(parser p) -> ast.arg {
- let ast.mode m = ast.val;
- if (p.peek() == token.BINOP(token.AND)) {
- m = ast.alias;
+fn parse_arg(parser p) -> ast::arg {
+ let ast::mode m = ast::val;
+ if (p.peek() == token::BINOP(token::AND)) {
+ m = ast::alias;
p.bump();
- if (p.peek() == token.MUTABLE) {
+ if (p.peek() == token::MUTABLE) {
// TODO: handle mutable alias args
p.bump();
}
}
- let @ast.ty t = parse_ty(p);
- let ast.ident i = parse_ident(p);
+ let @ast::ty t = parse_ty(p);
+ let ast::ident i = parse_ident(p);
ret rec(mode=m, ty=t, ident=i, id=p.next_def_id());
}
-fn parse_seq_to_end[T](token.token ket,
- Option.t[token.token] sep,
+fn parse_seq_to_end[T](token::token ket,
+ option::t[token::token] sep,
(fn(parser) -> T) f,
uint hi,
parser p) -> vec[T] {
let vec[T] v = vec();
while (p.peek() != ket) {
alt(sep) {
- case (some[token.token](?t)) {
+ case (some[token::token](?t)) {
if (first) {
first = false;
} else {
ret v;
}
-fn parse_seq[T](token.token bra,
- token.token ket,
- Option.t[token.token] sep,
+fn parse_seq[T](token::token bra,
+ token::token ket,
+ option::t[token::token] sep,
(fn(parser) -> T) f,
- parser p) -> util.common.spanned[vec[T]] {
+ parser p) -> util::common::spanned[vec[T]] {
auto lo = p.get_lo_pos();
auto hi = p.get_hi_pos();
expect(p, bra);
ret spanned(lo, hi, result);
}
-fn parse_lit(parser p) -> ast.lit {
+fn parse_lit(parser p) -> ast::lit {
auto sp = p.get_span();
- let ast.lit_ lit = ast.lit_nil;
+ let ast::lit_ lit = ast::lit_nil;
alt (p.peek()) {
- case (token.LIT_INT(?i)) {
+ case (token::LIT_INT(?i)) {
p.bump();
- lit = ast.lit_int(i);
+ lit = ast::lit_int(i);
}
- case (token.LIT_UINT(?u)) {
+ case (token::LIT_UINT(?u)) {
p.bump();
- lit = ast.lit_uint(u);
+ lit = ast::lit_uint(u);
}
- case (token.LIT_FLOAT(?s)) {
+ case (token::LIT_FLOAT(?s)) {
p.bump();
- lit = ast.lit_float(p.get_str(s));
+ lit = ast::lit_float(p.get_str(s));
}
- case (token.LIT_MACH_INT(?tm, ?i)) {
+ case (token::LIT_MACH_INT(?tm, ?i)) {
p.bump();
- lit = ast.lit_mach_int(tm, i);
+ lit = ast::lit_mach_int(tm, i);
}
- case (token.LIT_MACH_FLOAT(?tm, ?s)) {
+ case (token::LIT_MACH_FLOAT(?tm, ?s)) {
p.bump();
- lit = ast.lit_mach_float(tm, p.get_str(s));
+ lit = ast::lit_mach_float(tm, p.get_str(s));
}
- case (token.LIT_CHAR(?c)) {
+ case (token::LIT_CHAR(?c)) {
p.bump();
- lit = ast.lit_char(c);
+ lit = ast::lit_char(c);
}
- case (token.LIT_BOOL(?b)) {
+ case (token::LIT_BOOL(?b)) {
p.bump();
- lit = ast.lit_bool(b);
+ lit = ast::lit_bool(b);
}
- case (token.LIT_STR(?s)) {
+ case (token::LIT_STR(?s)) {
p.bump();
- lit = ast.lit_str(p.get_str(s));
+ lit = ast::lit_str(p.get_str(s));
}
case (?t) {
unexpected(p, t);
ret rec(node=lit, span=sp);
}
-fn is_ident(token.token t) -> bool {
+fn is_ident(token::token t) -> bool {
alt (t) {
- case (token.IDENT(_)) { ret true; }
+ case (token::IDENT(_)) { ret true; }
case (_) {}
}
ret false;
}
fn parse_ty_args(parser p, uint hi) ->
- util.common.spanned[vec[@ast.ty]] {
+ util::common::spanned[vec[@ast::ty]] {
- if (p.peek() == token.LBRACKET) {
+ if (p.peek() == token::LBRACKET) {
auto pf = parse_ty;
- ret parse_seq[@ast.ty](token.LBRACKET,
- token.RBRACKET,
- some(token.COMMA),
+ ret parse_seq[@ast::ty](token::LBRACKET,
+ token::RBRACKET,
+ some(token::COMMA),
pf, p);
}
- let vec[@ast.ty] v = vec();
+ let vec[@ast::ty] v = vec();
auto pos = p.get_lo_pos();
ret spanned(hi, hi, v);
}
-fn parse_path(parser p) -> ast.path {
+fn parse_path(parser p) -> ast::path {
auto lo = p.get_lo_pos();
auto hi = lo;
- let vec[ast.ident] ids = vec();
+ let vec[ast::ident] ids = vec();
while (true) {
alt (p.peek()) {
- case (token.IDENT(?i)) {
+ case (token::IDENT(?i)) {
hi = p.get_hi_pos();
ids += vec(p.get_str(i));
p.bump();
- if (p.peek() == token.MOD_SEP) {
+ if (p.peek() == token::MOD_SEP) {
p.bump();
} else { break; }
}
ret spanned(lo, tys.span.hi, rec(idents=ids, types=tys.node));
}
-fn parse_mutability(parser p) -> ast.mutability {
- if (p.peek() == token.MUTABLE) {
+fn parse_mutability(parser p) -> ast::mutability {
+ if (p.peek() == token::MUTABLE) {
p.bump();
- if (p.peek() == token.QUES) {
+ if (p.peek() == token::QUES) {
p.bump();
- ret ast.maybe_mut;
+ ret ast::maybe_mut;
}
- ret ast.mut;
+ ret ast::mut;
}
- ret ast.imm;
+ ret ast::imm;
}
-fn parse_field(parser p) -> ast.field {
+fn parse_field(parser p) -> ast::field {
auto m = parse_mutability(p);
auto i = parse_ident(p);
- expect(p, token.EQ);
+ expect(p, token::EQ);
auto e = parse_expr(p);
ret rec(mut=m, ident=i, expr=e);
}
-fn parse_bottom_expr(parser p) -> @ast.expr {
+fn parse_bottom_expr(parser p) -> @ast::expr {
auto lo = p.get_lo_pos();
auto 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, p.get_ann());
+ auto lit = @spanned(lo, hi, ast::lit_nil);
+ let ast::expr_ ex = ast::expr_lit(lit, p.get_ann());
alt (p.peek()) {
- case (token.IDENT(_)) {
+ case (token::IDENT(_)) {
auto pth = parse_path(p);
hi = pth.span.hi;
- ex = ast.expr_path(pth, p.get_ann());
+ ex = ast::expr_path(pth, p.get_ann());
}
- case (token.LPAREN) {
+ case (token::LPAREN) {
p.bump();
alt (p.peek()) {
- case (token.RPAREN) {
+ case (token::RPAREN) {
hi = p.get_hi_pos();
p.bump();
- auto lit = @spanned(lo, hi, ast.lit_nil);
+ auto lit = @spanned(lo, hi, ast::lit_nil);
ret @spanned(lo, hi,
- ast.expr_lit(lit, p.get_ann()));
+ ast::expr_lit(lit, p.get_ann()));
}
case (_) { /* fall through */ }
}
auto e = parse_expr(p);
hi = p.get_hi_pos();
- expect(p, token.RPAREN);
+ expect(p, token::RPAREN);
ret @spanned(lo, hi, e.node);
}
- case (token.TUP) {
+ case (token::TUP) {
p.bump();
- fn parse_elt(parser p) -> ast.elt {
+ fn parse_elt(parser p) -> ast::elt {
auto m = parse_mutability(p);
auto e = parse_expr(p);
ret rec(mut=m, expr=e);
}
auto pf = parse_elt;
auto es =
- parse_seq[ast.elt](token.LPAREN,
- token.RPAREN,
- some(token.COMMA),
+ parse_seq[ast::elt](token::LPAREN,
+ token::RPAREN,
+ some(token::COMMA),
pf, p);
hi = es.span.hi;
- ex = ast.expr_tup(es.node, p.get_ann());
+ ex = ast::expr_tup(es.node, p.get_ann());
}
- case (token.VEC) {
+ case (token::VEC) {
p.bump();
auto pf = parse_expr;
- expect(p, token.LPAREN);
+ expect(p, token::LPAREN);
auto mut = parse_mutability(p);
- auto es = parse_seq_to_end[@ast.expr](token.RPAREN,
- some(token.COMMA),
+ auto es = parse_seq_to_end[@ast::expr](token::RPAREN,
+ some(token::COMMA),
pf, hi, p);
- ex = ast.expr_vec(es, mut, p.get_ann());
+ ex = ast::expr_vec(es, mut, p.get_ann());
}
- case (token.REC) {
+ case (token::REC) {
p.bump();
- expect(p, token.LPAREN);
+ expect(p, token::LPAREN);
auto fields = vec(parse_field(p));
auto more = true;
- auto base = none[@ast.expr];
+ auto base = none[@ast::expr];
while (more) {
alt (p.peek()) {
- case (token.RPAREN) {
+ case (token::RPAREN) {
hi = p.get_hi_pos();
p.bump();
more = false;
}
- case (token.WITH) {
+ case (token::WITH) {
p.bump();
- base = some[@ast.expr](parse_expr(p));
+ base = some[@ast::expr](parse_expr(p));
hi = p.get_hi_pos();
- expect(p, token.RPAREN);
+ expect(p, token::RPAREN);
more = false;
}
- case (token.COMMA) {
+ case (token::COMMA) {
p.bump();
fields += vec(parse_field(p));
}
}
- ex = ast.expr_rec(fields, base, p.get_ann());
+ ex = ast::expr_rec(fields, base, p.get_ann());
}
- case (token.BIND) {
+ case (token::BIND) {
p.bump();
auto e = parse_expr_res(p, RESTRICT_NO_CALL_EXPRS);
- fn parse_expr_opt(parser p) -> Option.t[@ast.expr] {
+ fn parse_expr_opt(parser p) -> option::t[@ast::expr] {
alt (p.peek()) {
- case (token.UNDERSCORE) {
+ case (token::UNDERSCORE) {
p.bump();
- ret none[@ast.expr];
+ ret none[@ast::expr];
}
case (_) {
- ret some[@ast.expr](parse_expr(p));
+ ret some[@ast::expr](parse_expr(p));
}
}
}
auto pf = parse_expr_opt;
- auto es = parse_seq[Option.t[@ast.expr]](token.LPAREN,
- token.RPAREN,
- some(token.COMMA),
+ auto es = parse_seq[option::t[@ast::expr]](token::LPAREN,
+ token::RPAREN,
+ some(token::COMMA),
pf, p);
hi = es.span.hi;
- ex = ast.expr_bind(e, es.node, p.get_ann());
+ ex = ast::expr_bind(e, es.node, p.get_ann());
}
- case (token.POUND) {
+ case (token::POUND) {
p.bump();
auto pth = parse_path(p);
auto pf = parse_expr;
- auto es = parse_seq[@ast.expr](token.LPAREN,
- token.RPAREN,
- some(token.COMMA),
+ auto es = parse_seq[@ast::expr](token::LPAREN,
+ token::RPAREN,
+ some(token::COMMA),
pf, p);
hi = es.span.hi;
ex = expand_syntax_ext(p, es.span, pth, es.node,
none[str]);
}
- case (token.FAIL) {
+ case (token::FAIL) {
p.bump();
- ex = ast.expr_fail(p.get_ann());
+ ex = ast::expr_fail(p.get_ann());
}
- case (token.LOG) {
+ case (token::LOG) {
p.bump();
auto e = parse_expr(p);
auto hi = e.span.hi;
- ex = ast.expr_log(1, e, p.get_ann());
+ ex = ast::expr_log(1, e, p.get_ann());
}
- case (token.LOG_ERR) {
+ case (token::LOG_ERR) {
p.bump();
auto e = parse_expr(p);
auto hi = e.span.hi;
- ex = ast.expr_log(0, e, p.get_ann());
+ ex = ast::expr_log(0, e, p.get_ann());
}
- case (token.ASSERT) {
+ case (token::ASSERT) {
p.bump();
auto e = parse_expr(p);
auto hi = e.span.hi;
- ex = ast.expr_assert(e, p.get_ann());
+ ex = ast::expr_assert(e, p.get_ann());
}
- case (token.CHECK) {
+ case (token::CHECK) {
p.bump();
/* Should be a predicate (pure boolean function) applied to
arguments that are all either slot variables or literals.
but the typechecker enforces that. */
auto e = parse_expr(p);
auto hi = e.span.hi;
- ex = ast.expr_check(e, p.get_ann());
+ ex = ast::expr_check(e, p.get_ann());
}
- case (token.RET) {
+ case (token::RET) {
p.bump();
alt (p.peek()) {
- case (token.SEMI) {
- ex = ast.expr_ret(none[@ast.expr], p.get_ann());
+ case (token::SEMI) {
+ ex = ast::expr_ret(none[@ast::expr], p.get_ann());
}
case (_) {
auto e = parse_expr(p);
hi = e.span.hi;
- ex = ast.expr_ret(some[@ast.expr](e), p.get_ann());
+ ex = ast::expr_ret(some[@ast::expr](e), p.get_ann());
}
}
}
- case (token.BREAK) {
+ case (token::BREAK) {
p.bump();
- ex = ast.expr_break(p.get_ann());
+ ex = ast::expr_break(p.get_ann());
}
- case (token.CONT) {
+ case (token::CONT) {
p.bump();
- ex = ast.expr_cont(p.get_ann());
+ ex = ast::expr_cont(p.get_ann());
}
- case (token.PUT) {
+ case (token::PUT) {
p.bump();
alt (p.peek()) {
- case (token.SEMI) {
- ex = ast.expr_put(none[@ast.expr], p.get_ann());
+ case (token::SEMI) {
+ ex = ast::expr_put(none[@ast::expr], p.get_ann());
}
case (_) {
auto e = parse_expr(p);
hi = e.span.hi;
- ex = ast.expr_put(some[@ast.expr](e), p.get_ann());
+ ex = ast::expr_put(some[@ast::expr](e), p.get_ann());
}
}
}
- case (token.BE) {
+ case (token::BE) {
p.bump();
auto 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, p.get_ann());
+ ex = ast::expr_be(e, p.get_ann());
}
else {
p.err("Non-call expression in tail call");
}
}
- case (token.PORT) {
+ case (token::PORT) {
p.bump();
- expect(p, token.LPAREN);
- expect(p, token.RPAREN);
+ expect(p, token::LPAREN);
+ expect(p, token::RPAREN);
hi = p.get_hi_pos();
- ex = ast.expr_port(p.get_ann());
+ ex = ast::expr_port(p.get_ann());
}
- case (token.CHAN) {
+ case (token::CHAN) {
p.bump();
- expect(p, token.LPAREN);
+ expect(p, token::LPAREN);
auto e = parse_expr(p);
hi = e.span.hi;
- expect(p, token.RPAREN);
- ex = ast.expr_chan(e, p.get_ann());
+ expect(p, token::RPAREN);
+ ex = ast::expr_chan(e, p.get_ann());
}
- case (token.SELF) {
+ case (token::SELF) {
log "parsing a self-call...";
p.bump();
- expect(p, token.DOT);
+ expect(p, token::DOT);
// The rest is a call expression.
- let @ast.expr f = parse_self_method(p);
+ let @ast::expr f = parse_self_method(p);
auto pf = parse_expr;
- auto es = parse_seq[@ast.expr](token.LPAREN,
- token.RPAREN,
- some(token.COMMA),
+ auto es = parse_seq[@ast::expr](token::LPAREN,
+ token::RPAREN,
+ some(token::COMMA),
pf, p);
hi = es.span.hi;
- ex = ast.expr_call(f, es.node, p.get_ann());
+ ex = ast::expr_call(f, es.node, p.get_ann());
}
case (_) {
auto lit = parse_lit(p);
hi = lit.span.hi;
- ex = ast.expr_lit(@lit, p.get_ann());
+ ex = ast::expr_lit(@lit, p.get_ann());
}
}
* rust crates. At the moment we have neither.
*/
-fn expand_syntax_ext(parser p, ast.span sp,
- &ast.path path, vec[@ast.expr] args,
- Option.t[str] body) -> ast.expr_ {
+fn expand_syntax_ext(parser p, ast::span sp,
+ &ast::path path, vec[@ast::expr] args,
+ option::t[str] body) -> ast::expr_ {
- assert (Vec.len[ast.ident](path.node.idents) > 0u);
+ assert (_vec::len[ast::ident](path.node.idents) > 0u);
auto extname = path.node.idents.(0);
- if (Str.eq(extname, "fmt")) {
- auto expanded = extfmt.expand_syntax_ext(p, args, body);
- auto newexpr = ast.expr_ext(path, args, body,
+ if (_str::eq(extname, "fmt")) {
+ auto expanded = extfmt::expand_syntax_ext(p, args, body);
+ auto newexpr = ast::expr_ext(path, args, body,
expanded,
p.get_ann());
ret newexpr;
- } else if (Str.eq(extname, "env")) {
- auto expanded = extenv.expand_syntax_ext(p, sp, args, body);
- auto newexpr = ast.expr_ext(path, args, body,
+ } else if (_str::eq(extname, "env")) {
+ auto expanded = extenv::expand_syntax_ext(p, sp, args, body);
+ auto newexpr = ast::expr_ext(path, args, body,
expanded,
p.get_ann());
}
}
-fn parse_self_method(parser p) -> @ast.expr {
+fn parse_self_method(parser p) -> @ast::expr {
auto sp = p.get_span();
- let ast.ident f_name = parse_ident(p);
+ let ast::ident f_name = parse_ident(p);
auto hi = p.get_span();
- ret @rec(node=ast.expr_self_method(f_name, p.get_ann()), span=sp);
+ ret @rec(node=ast::expr_self_method(f_name, p.get_ann()), span=sp);
}
-fn parse_dot_or_call_expr(parser p) -> @ast.expr {
+fn parse_dot_or_call_expr(parser p) -> @ast::expr {
auto lo = p.get_lo_pos();
auto e = parse_bottom_expr(p);
auto hi = e.span.hi;
while (true) {
alt (p.peek()) {
- case (token.LPAREN) {
+ case (token::LPAREN) {
if (p.get_restriction() == RESTRICT_NO_CALL_EXPRS) {
ret e;
} else {
// Call expr.
auto pf = parse_expr;
- auto es = parse_seq[@ast.expr](token.LPAREN,
- token.RPAREN,
- some(token.COMMA),
+ auto es = parse_seq[@ast::expr](token::LPAREN,
+ token::RPAREN,
+ some(token::COMMA),
pf, p);
hi = es.span.hi;
- auto e_ = ast.expr_call(e, es.node, p.get_ann());
+ auto e_ = ast::expr_call(e, es.node, p.get_ann());
e = @spanned(lo, hi, e_);
}
}
- case (token.DOT) {
+ case (token::DOT) {
p.bump();
alt (p.peek()) {
- case (token.IDENT(?i)) {
+ case (token::IDENT(?i)) {
hi = p.get_hi_pos();
p.bump();
- auto e_ = ast.expr_field(e, p.get_str(i),
+ auto e_ = ast::expr_field(e, p.get_str(i),
p.get_ann());
e = @spanned(lo, hi, e_);
}
- case (token.LPAREN) {
+ case (token::LPAREN) {
p.bump();
auto ix = parse_expr(p);
hi = ix.span.hi;
- expect(p, token.RPAREN);
- auto e_ = ast.expr_index(e, ix, p.get_ann());
+ expect(p, token::RPAREN);
+ auto e_ = ast::expr_index(e, ix, p.get_ann());
e = @spanned(lo, hi, e_);
}
ret e;
}
-fn parse_prefix_expr(parser p) -> @ast.expr {
+fn parse_prefix_expr(parser p) -> @ast::expr {
- if (p.peek() == token.MUTABLE) {
+ if (p.peek() == token::MUTABLE) {
p.bump();
p.get_session().span_warn(p.get_span(),
"ignoring deprecated 'mutable' prefix operator");
// 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, p.get_ann());
+ auto lit = @spanned(lo, lo, ast::lit_nil);
+ let ast::expr_ ex = ast::expr_lit(lit, p.get_ann());
alt (p.peek()) {
- case (token.NOT) {
+ case (token::NOT) {
p.bump();
auto e = parse_prefix_expr(p);
hi = e.span.hi;
- ex = ast.expr_unary(ast.not, e, p.get_ann());
+ ex = ast::expr_unary(ast::not, e, p.get_ann());
}
- case (token.TILDE) {
+ case (token::TILDE) {
p.bump();
auto e = parse_prefix_expr(p);
hi = e.span.hi;
- ex = ast.expr_unary(ast.bitnot, e, p.get_ann());
+ ex = ast::expr_unary(ast::bitnot, e, p.get_ann());
}
- case (token.BINOP(?b)) {
+ case (token::BINOP(?b)) {
alt (b) {
- case (token.MINUS) {
+ case (token::MINUS) {
p.bump();
auto e = parse_prefix_expr(p);
hi = e.span.hi;
- ex = ast.expr_unary(ast.neg, e, p.get_ann());
+ ex = ast::expr_unary(ast::neg, e, p.get_ann());
}
- case (token.STAR) {
+ case (token::STAR) {
p.bump();
auto e = parse_prefix_expr(p);
hi = e.span.hi;
- ex = ast.expr_unary(ast.deref, e, p.get_ann());
+ ex = ast::expr_unary(ast::deref, e, p.get_ann());
}
case (_) {
}
}
- case (token.AT) {
+ case (token::AT) {
p.bump();
auto m = parse_mutability(p);
auto e = parse_prefix_expr(p);
hi = e.span.hi;
- ex = ast.expr_unary(ast.box(m), e, p.get_ann());
+ ex = ast::expr_unary(ast::box(m), e, p.get_ann());
}
case (_) {
ret @spanned(lo, hi, ex);
}
-type op_spec = rec(token.token tok, ast.binop op, int prec);
+type op_spec = rec(token::token tok, ast::binop op, int prec);
// FIXME make this a const, don't store it in parser state
fn prec_table() -> vec[op_spec] {
- ret vec(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),
- // ast.mul is a bogus placeholder here, AS is special
+ ret vec(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),
+ // ast::mul is a bogus placeholder here, AS is special
// cased in parse_more_binops
- rec(tok=token.AS, op=ast.mul, prec=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));
-}
-
-fn parse_binops(parser p) -> @ast.expr {
+ rec(tok=token::AS, op=ast::mul, prec=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));
+}
+
+fn parse_binops(parser p) -> @ast::expr {
ret parse_more_binops(p, parse_prefix_expr(p), 0);
}
-fn parse_more_binops(parser p, @ast.expr lhs, int min_prec)
- -> @ast.expr {
+fn parse_more_binops(parser p, @ast::expr lhs, int min_prec)
+ -> @ast::expr {
// Magic nonsense to work around rustboot bug
- fn op_eq(token.token a, token.token b) -> bool {
+ fn op_eq(token::token a, token::token b) -> bool {
if (a == b) {ret true;}
else {ret false;}
}
if (cur.prec > min_prec && op_eq(cur.tok, peeked)) {
p.bump();
alt (cur.tok) {
- case (token.AS) {
+ case (token::AS) {
auto rhs = parse_ty(p);
- auto _as = ast.expr_cast(lhs, rhs, p.get_ann());
+ auto _as = ast::expr_cast(lhs, rhs, p.get_ann());
auto span = @spanned(lhs.span.lo, rhs.span.hi, _as);
ret parse_more_binops(p, span, min_prec);
}
case (_) {
auto rhs = parse_more_binops(p, parse_prefix_expr(p),
cur.prec);
- auto bin = ast.expr_binary(cur.op, lhs, rhs,
+ auto bin = ast::expr_binary(cur.op, lhs, rhs,
p.get_ann());
auto span = @spanned(lhs.span.lo, rhs.span.hi, bin);
ret parse_more_binops(p, span, min_prec);
ret lhs;
}
-fn parse_assign_expr(parser p) -> @ast.expr {
+fn parse_assign_expr(parser p) -> @ast::expr {
auto lo = p.get_lo_pos();
auto lhs = parse_binops(p);
alt (p.peek()) {
- case (token.EQ) {
+ case (token::EQ) {
p.bump();
auto rhs = parse_expr(p);
ret @spanned(lo, rhs.span.hi,
- ast.expr_assign(lhs, rhs, p.get_ann()));
+ ast::expr_assign(lhs, rhs, p.get_ann()));
}
- case (token.BINOPEQ(?op)) {
+ case (token::BINOPEQ(?op)) {
p.bump();
auto rhs = parse_expr(p);
- auto aop = ast.add;
+ 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; }
+ 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 @spanned(lo, rhs.span.hi,
- ast.expr_assign_op(aop, lhs, rhs, p.get_ann()));
+ ast::expr_assign_op(aop, lhs, rhs, p.get_ann()));
}
- case (token.SEND) {
+ case (token::SEND) {
p.bump();
auto rhs = parse_expr(p);
ret @spanned(lo, rhs.span.hi,
- ast.expr_send(lhs, rhs, p.get_ann()));
+ ast::expr_send(lhs, rhs, p.get_ann()));
}
- case (token.LARROW) {
+ case (token::LARROW) {
p.bump();
auto rhs = parse_expr(p);
ret @spanned(lo, rhs.span.hi,
- ast.expr_recv(lhs, rhs, p.get_ann()));
+ ast::expr_recv(lhs, rhs, p.get_ann()));
}
case (_) { /* fall through */ }
}
ret lhs;
}
-fn parse_if_expr(parser p) -> @ast.expr {
+fn parse_if_expr(parser p) -> @ast::expr {
auto lo = p.get_lo_pos();
- expect(p, token.IF);
- expect(p, token.LPAREN);
+ expect(p, token::IF);
+ expect(p, token::LPAREN);
auto cond = parse_expr(p);
- expect(p, token.RPAREN);
+ expect(p, token::RPAREN);
auto thn = parse_block(p);
- let Option.t[@ast.expr] els = none[@ast.expr];
+ let option::t[@ast::expr] els = none[@ast::expr];
auto hi = thn.span.hi;
alt (p.peek()) {
- case (token.ELSE) {
+ case (token::ELSE) {
auto elexpr = parse_else_expr(p);
els = some(elexpr);
hi = elexpr.span.hi;
case (_) { /* fall through */ }
}
- ret @spanned(lo, hi, ast.expr_if(cond, thn, els, p.get_ann()));
+ ret @spanned(lo, hi, ast::expr_if(cond, thn, els, p.get_ann()));
}
-fn parse_else_expr(parser p) -> @ast.expr {
- expect(p, token.ELSE);
+fn parse_else_expr(parser p) -> @ast::expr {
+ expect(p, token::ELSE);
alt (p.peek()) {
- case (token.IF) {
+ case (token::IF) {
ret parse_if_expr(p);
}
case (_) {
auto blk = parse_block(p);
ret @spanned(blk.span.lo, blk.span.hi,
- ast.expr_block(blk, p.get_ann()));
+ ast::expr_block(blk, p.get_ann()));
}
}
}
-fn parse_head_local(parser p) -> @ast.decl {
+fn parse_head_local(parser p) -> @ast::decl {
auto lo = p.get_lo_pos();
- let @ast.local local;
- if (p.peek() == token.AUTO) {
+ let @ast::local local;
+ if (p.peek() == token::AUTO) {
local = parse_auto_local(p);
} else {
local = parse_typed_local(p);
}
- ret @spanned(lo, p.get_hi_pos(), ast.decl_local(local));
+ ret @spanned(lo, p.get_hi_pos(), ast::decl_local(local));
}
-fn parse_for_expr(parser p) -> @ast.expr {
+fn parse_for_expr(parser p) -> @ast::expr {
auto lo = p.get_lo_pos();
auto is_each = false;
- expect(p, token.FOR);
- if (p.peek() == token.EACH) {
+ expect(p, token::FOR);
+ if (p.peek() == token::EACH) {
is_each = true;
p.bump();
}
- expect (p, token.LPAREN);
+ expect (p, token::LPAREN);
auto decl = parse_head_local(p);
- expect(p, token.IN);
+ expect(p, token::IN);
auto seq = parse_expr(p);
- expect(p, token.RPAREN);
+ expect(p, token::RPAREN);
auto body = parse_block(p);
auto hi = body.span.hi;
if (is_each) {
- ret @spanned(lo, hi, ast.expr_for_each(decl, seq, body,
+ ret @spanned(lo, hi, ast::expr_for_each(decl, seq, body,
p.get_ann()));
} else {
- ret @spanned(lo, hi, ast.expr_for(decl, seq, body,
+ ret @spanned(lo, hi, ast::expr_for(decl, seq, body,
p.get_ann()));
}
}
-fn parse_while_expr(parser p) -> @ast.expr {
+fn parse_while_expr(parser p) -> @ast::expr {
auto lo = p.get_lo_pos();
- expect(p, token.WHILE);
- expect (p, token.LPAREN);
+ expect(p, token::WHILE);
+ expect (p, token::LPAREN);
auto cond = parse_expr(p);
- expect(p, token.RPAREN);
+ expect(p, token::RPAREN);
auto body = parse_block(p);
auto hi = body.span.hi;
- ret @spanned(lo, hi, ast.expr_while(cond, body, p.get_ann()));
+ ret @spanned(lo, hi, ast::expr_while(cond, body, p.get_ann()));
}
-fn parse_do_while_expr(parser p) -> @ast.expr {
+fn parse_do_while_expr(parser p) -> @ast::expr {
auto lo = p.get_lo_pos();
- expect(p, token.DO);
+ expect(p, token::DO);
auto body = parse_block(p);
- expect(p, token.WHILE);
- expect (p, token.LPAREN);
+ expect(p, token::WHILE);
+ expect (p, token::LPAREN);
auto cond = parse_expr(p);
- expect(p, token.RPAREN);
+ expect(p, token::RPAREN);
auto hi = cond.span.hi;
- ret @spanned(lo, hi, ast.expr_do_while(body, cond, p.get_ann()));
+ ret @spanned(lo, hi, ast::expr_do_while(body, cond, p.get_ann()));
}
-fn parse_alt_expr(parser p) -> @ast.expr {
+fn parse_alt_expr(parser p) -> @ast::expr {
auto lo = p.get_lo_pos();
- expect(p, token.ALT);
- expect(p, token.LPAREN);
+ expect(p, token::ALT);
+ expect(p, token::LPAREN);
auto discriminant = parse_expr(p);
- expect(p, token.RPAREN);
- expect(p, token.LBRACE);
+ expect(p, token::RPAREN);
+ expect(p, token::LBRACE);
- let vec[ast.arm] arms = vec();
- while (p.peek() != token.RBRACE) {
+ let vec[ast::arm] arms = vec();
+ while (p.peek() != token::RBRACE) {
alt (p.peek()) {
- case (token.CASE) {
+ case (token::CASE) {
p.bump();
- expect(p, token.LPAREN);
+ expect(p, token::LPAREN);
auto pat = parse_pat(p);
- expect(p, token.RPAREN);
+ expect(p, token::RPAREN);
auto block = parse_block(p);
arms += vec(rec(pat=pat, block=block));
}
// meaning, and only exists due to the cexp/pexp split
// in rustboot, which we're not maintaining.
- case (token.ELSE) {
+ case (token::ELSE) {
p.bump();
auto hi = p.get_hi_pos();
- auto pat = @spanned(lo, hi, ast.pat_wild(p.get_ann()));
+ auto pat = @spanned(lo, hi, ast::pat_wild(p.get_ann()));
auto block = parse_block(p);
arms += vec(rec(pat=pat, block=block));
}
- case (token.RBRACE) { /* empty */ }
+ case (token::RBRACE) { /* empty */ }
case (?tok) {
p.err("expected 'case' or '}' when parsing 'alt' statement " +
- "but found " + token.to_str(p.get_reader(), tok));
+ "but found " + token::to_str(p.get_reader(), tok));
}
}
}
auto hi = p.get_hi_pos();
p.bump();
- auto expr = ast.expr_alt(discriminant, arms, p.get_ann());
+ auto expr = ast::expr_alt(discriminant, arms, p.get_ann());
ret @spanned(lo, hi, expr);
}
-fn parse_spawn_expr(parser p) -> @ast.expr {
+fn parse_spawn_expr(parser p) -> @ast::expr {
auto lo = p.get_lo_pos();
- expect(p, token.SPAWN);
+ expect(p, token::SPAWN);
// FIXME: Parse domain and name
// FIXME: why no full expr?
auto fn_expr = parse_bottom_expr(p);
auto pf = parse_expr;
- auto es = parse_seq[@ast.expr](token.LPAREN,
- token.RPAREN,
- some(token.COMMA),
+ auto es = parse_seq[@ast::expr](token::LPAREN,
+ token::RPAREN,
+ some(token::COMMA),
pf, p);
auto hi = es.span.hi;
- auto spawn_expr = ast.expr_spawn(ast.dom_implicit,
- Option.none[str],
+ auto spawn_expr = ast::expr_spawn(ast::dom_implicit,
+ option::none[str],
fn_expr,
es.node,
p.get_ann());
ret @spanned(lo, hi, spawn_expr);
}
-fn parse_expr(parser p) -> @ast.expr {
+fn parse_expr(parser p) -> @ast::expr {
ret parse_expr_res(p, UNRESTRICTED);
}
-fn parse_expr_res(parser p, restriction r) -> @ast.expr {
+fn parse_expr_res(parser p, restriction r) -> @ast::expr {
auto old = p.get_restriction();
p.restrict(r);
auto e = parse_expr_inner(p);
ret e;
}
-fn parse_expr_inner(parser p) -> @ast.expr {
+fn parse_expr_inner(parser p) -> @ast::expr {
alt (p.peek()) {
- case (token.LBRACE) {
+ case (token::LBRACE) {
auto blk = parse_block(p);
ret @spanned(blk.span.lo, blk.span.hi,
- ast.expr_block(blk, p.get_ann()));
+ ast::expr_block(blk, p.get_ann()));
}
- case (token.IF) {
+ case (token::IF) {
ret parse_if_expr(p);
}
- case (token.FOR) {
+ case (token::FOR) {
ret parse_for_expr(p);
}
- case (token.WHILE) {
+ case (token::WHILE) {
ret parse_while_expr(p);
}
- case (token.DO) {
+ case (token::DO) {
ret parse_do_while_expr(p);
}
- case (token.ALT) {
+ case (token::ALT) {
ret parse_alt_expr(p);
}
- case (token.SPAWN) {
+ case (token::SPAWN) {
ret parse_spawn_expr(p);
}
case (_) {
}
}
-fn parse_initializer(parser p) -> Option.t[ast.initializer] {
+fn parse_initializer(parser p) -> option::t[ast::initializer] {
alt (p.peek()) {
- case (token.EQ) {
+ case (token::EQ) {
p.bump();
- ret some(rec(op = ast.init_assign,
+ ret some(rec(op = ast::init_assign,
expr = parse_expr(p)));
}
- case (token.LARROW) {
+ case (token::LARROW) {
p.bump();
- ret some(rec(op = ast.init_recv,
+ ret some(rec(op = ast::init_recv,
expr = parse_expr(p)));
}
case (_) {
- ret none[ast.initializer];
+ ret none[ast::initializer];
}
}
}
-fn parse_pat(parser p) -> @ast.pat {
+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) {
+ case (token::UNDERSCORE) {
p.bump();
- pat = ast.pat_wild(p.get_ann());
+ pat = ast::pat_wild(p.get_ann());
}
- case (token.QUES) {
+ case (token::QUES) {
p.bump();
alt (p.peek()) {
- case (token.IDENT(?id)) {
+ case (token::IDENT(?id)) {
hi = p.get_hi_pos();
p.bump();
- pat = ast.pat_bind(p.get_str(id), p.next_def_id(),
+ pat = ast::pat_bind(p.get_str(id), p.next_def_id(),
p.get_ann());
}
case (?tok) {
p.err("expected identifier after '?' in pattern but " +
- "found " + token.to_str(p.get_reader(), tok));
+ "found " + token::to_str(p.get_reader(), tok));
fail;
}
}
}
- case (token.IDENT(_)) {
+ case (token::IDENT(_)) {
auto tag_path = parse_path(p);
hi = tag_path.span.hi;
- let vec[@ast.pat] args;
+ let vec[@ast::pat] args;
alt (p.peek()) {
- case (token.LPAREN) {
+ case (token::LPAREN) {
auto f = parse_pat;
- auto a = parse_seq[@ast.pat](token.LPAREN, token.RPAREN,
- some(token.COMMA), f, p);
+ auto a = parse_seq[@ast::pat](token::LPAREN,
+ token::RPAREN,
+ some(token::COMMA), f, p);
args = a.node;
hi = a.span.hi;
}
case (_) { args = vec(); }
}
- pat = ast.pat_tag(tag_path, args, p.get_ann());
+ pat = ast::pat_tag(tag_path, args, p.get_ann());
}
case (_) {
auto lit = parse_lit(p);
hi = lit.span.hi;
- pat = ast.pat_lit(@lit, p.get_ann());
+ pat = ast::pat_lit(@lit, p.get_ann());
}
}
ret @spanned(lo, hi, pat);
}
-fn parse_local_full(&Option.t[@ast.ty] tyopt,
- parser p) -> @ast.local {
+fn parse_local_full(&option::t[@ast::ty] tyopt,
+ parser p) -> @ast::local {
auto ident = parse_ident(p);
auto init = parse_initializer(p);
ret @rec(ty = tyopt,
ann = p.get_ann());
}
-fn parse_typed_local(parser p) -> @ast.local {
+fn parse_typed_local(parser p) -> @ast::local {
auto ty = parse_ty(p);
ret parse_local_full(some(ty), p);
}
-fn parse_auto_local(parser p) -> @ast.local {
- ret parse_local_full(none[@ast.ty], p);
+fn parse_auto_local(parser p) -> @ast::local {
+ ret parse_local_full(none[@ast::ty], p);
}
-fn parse_let(parser p) -> @ast.decl {
+fn parse_let(parser p) -> @ast::decl {
auto lo = p.get_lo_pos();
- expect(p, token.LET);
+ expect(p, token::LET);
auto local = parse_typed_local(p);
- ret @spanned(lo, p.get_hi_pos(), ast.decl_local(local));
+ ret @spanned(lo, p.get_hi_pos(), ast::decl_local(local));
}
-fn parse_auto(parser p) -> @ast.decl {
+fn parse_auto(parser p) -> @ast::decl {
auto lo = p.get_lo_pos();
- expect(p, token.AUTO);
+ expect(p, token::AUTO);
auto local = parse_auto_local(p);
- ret @spanned(lo, p.get_hi_pos(), ast.decl_local(local));
+ ret @spanned(lo, p.get_hi_pos(), ast::decl_local(local));
}
-fn parse_stmt(parser p) -> @ast.stmt {
+fn parse_stmt(parser p) -> @ast::stmt {
if (p.get_file_type() == SOURCE_FILE) {
ret parse_source_stmt(p);
} else {
}
}
-fn parse_crate_stmt(parser p) -> @ast.stmt {
+fn parse_crate_stmt(parser p) -> @ast::stmt {
auto cdir = parse_crate_directive(p);
ret @spanned(cdir.span.lo, cdir.span.hi,
- ast.stmt_crate_directive(@cdir));
+ ast::stmt_crate_directive(@cdir));
}
-fn parse_source_stmt(parser p) -> @ast.stmt {
+fn parse_source_stmt(parser p) -> @ast::stmt {
auto lo = p.get_lo_pos();
alt (p.peek()) {
- case (token.LET) {
+ case (token::LET) {
auto decl = parse_let(p);
auto hi = p.get_span();
ret @spanned
- (lo, decl.span.hi, ast.stmt_decl(decl, p.get_ann()));
+ (lo, decl.span.hi, ast::stmt_decl(decl, p.get_ann()));
}
- case (token.AUTO) {
+ case (token::AUTO) {
auto decl = parse_auto(p);
auto hi = p.get_span();
- ret @spanned(lo, decl.span.hi, ast.stmt_decl(decl, p.get_ann()));
+ ret @spanned(lo, decl.span.hi, ast::stmt_decl(decl, p.get_ann()));
}
case (_) {
// Might be a local item decl.
auto i = parse_item(p);
auto hi = i.span.hi;
- auto decl = @spanned(lo, hi, ast.decl_item(i));
- ret @spanned(lo, hi, ast.stmt_decl(decl, p.get_ann()));
+ auto decl = @spanned(lo, hi, ast::decl_item(i));
+ ret @spanned(lo, hi, ast::stmt_decl(decl, p.get_ann()));
} else {
// Remainder are line-expr stmts.
auto e = parse_expr(p);
auto hi = p.get_span();
- ret @spanned(lo, e.span.hi, ast.stmt_expr(e, p.get_ann()));
+ ret @spanned(lo, e.span.hi, ast::stmt_expr(e, p.get_ann()));
}
}
}
fail;
}
-fn stmt_to_expr(@ast.stmt stmt) -> Option.t[@ast.expr] {
+fn stmt_to_expr(@ast::stmt stmt) -> option::t[@ast::expr] {
alt (stmt.node) {
- case (ast.stmt_expr(?e,_)) { ret some[@ast.expr](e); }
+ case (ast::stmt_expr(?e,_)) { ret some[@ast::expr](e); }
case (_) { /* fall through */ }
}
- ret none[@ast.expr];
+ ret none[@ast::expr];
}
-fn stmt_ends_with_semi(@ast.stmt stmt) -> bool {
+fn stmt_ends_with_semi(@ast::stmt stmt) -> bool {
alt (stmt.node) {
- case (ast.stmt_decl(?d,_)) {
+ case (ast::stmt_decl(?d,_)) {
alt (d.node) {
- case (ast.decl_local(_)) { ret true; }
- case (ast.decl_item(_)) { ret false; }
+ case (ast::decl_local(_)) { ret true; }
+ case (ast::decl_item(_)) { ret false; }
}
}
- case (ast.stmt_expr(?e,_)) {
+ case (ast::stmt_expr(?e,_)) {
alt (e.node) {
- case (ast.expr_vec(_,_,_)) { ret true; }
- case (ast.expr_tup(_,_)) { ret true; }
- case (ast.expr_rec(_,_,_)) { ret true; }
- case (ast.expr_call(_,_,_)) { ret true; }
- case (ast.expr_self_method(_,_)){ ret false; }
- case (ast.expr_binary(_,_,_,_)) { ret true; }
- case (ast.expr_unary(_,_,_)) { ret true; }
- case (ast.expr_lit(_,_)) { ret true; }
- case (ast.expr_cast(_,_,_)) { ret true; }
- case (ast.expr_if(_,_,_,_)) { ret false; }
- case (ast.expr_for(_,_,_,_)) { ret false; }
- case (ast.expr_for_each(_,_,_,_))
+ case (ast::expr_vec(_,_,_)) { ret true; }
+ case (ast::expr_tup(_,_)) { ret true; }
+ case (ast::expr_rec(_,_,_)) { ret true; }
+ case (ast::expr_call(_,_,_)) { ret true; }
+ case (ast::expr_self_method(_,_)){ ret false; }
+ case (ast::expr_binary(_,_,_,_)) { ret true; }
+ case (ast::expr_unary(_,_,_)) { ret true; }
+ case (ast::expr_lit(_,_)) { ret true; }
+ case (ast::expr_cast(_,_,_)) { ret true; }
+ case (ast::expr_if(_,_,_,_)) { ret false; }
+ case (ast::expr_for(_,_,_,_)) { ret false; }
+ case (ast::expr_for_each(_,_,_,_))
{ ret false; }
- case (ast.expr_while(_,_,_)) { ret false; }
- case (ast.expr_do_while(_,_,_)) { ret false; }
- case (ast.expr_alt(_,_,_)) { ret false; }
- case (ast.expr_block(_,_)) { ret false; }
- case (ast.expr_assign(_,_,_)) { ret true; }
- case (ast.expr_assign_op(_,_,_,_))
+ case (ast::expr_while(_,_,_)) { ret false; }
+ case (ast::expr_do_while(_,_,_)) { ret false; }
+ case (ast::expr_alt(_,_,_)) { ret false; }
+ case (ast::expr_block(_,_)) { ret false; }
+ case (ast::expr_assign(_,_,_)) { ret true; }
+ case (ast::expr_assign_op(_,_,_,_))
{ ret true; }
- case (ast.expr_send(_,_,_)) { ret true; }
- case (ast.expr_recv(_,_,_)) { ret true; }
- case (ast.expr_field(_,_,_)) { ret true; }
- case (ast.expr_index(_,_,_)) { ret true; }
- case (ast.expr_path(_,_)) { ret true; }
- case (ast.expr_fail(_)) { ret true; }
- case (ast.expr_break(_)) { ret true; }
- case (ast.expr_cont(_)) { ret true; }
- case (ast.expr_ret(_,_)) { ret true; }
- case (ast.expr_put(_,_)) { ret true; }
- case (ast.expr_be(_,_)) { ret true; }
- case (ast.expr_log(_,_,_)) { ret true; }
- case (ast.expr_check(_,_)) { ret true; }
- case (ast.expr_assert(_,_)) { ret true; }
+ case (ast::expr_send(_,_,_)) { ret true; }
+ case (ast::expr_recv(_,_,_)) { ret true; }
+ case (ast::expr_field(_,_,_)) { ret true; }
+ case (ast::expr_index(_,_,_)) { ret true; }
+ case (ast::expr_path(_,_)) { ret true; }
+ case (ast::expr_fail(_)) { ret true; }
+ case (ast::expr_break(_)) { ret true; }
+ case (ast::expr_cont(_)) { ret true; }
+ case (ast::expr_ret(_,_)) { ret true; }
+ case (ast::expr_put(_,_)) { ret true; }
+ case (ast::expr_be(_,_)) { ret true; }
+ case (ast::expr_log(_,_,_)) { ret true; }
+ case (ast::expr_check(_,_)) { ret true; }
+ case (ast::expr_assert(_,_)) { ret true; }
}
}
// We should not be calling this on a cdir.
- case (ast.stmt_crate_directive(?cdir)) { fail; }
+ case (ast::stmt_crate_directive(?cdir)) { fail; }
}
}
-fn parse_block(parser p) -> ast.block {
+fn parse_block(parser p) -> ast::block {
auto lo = p.get_lo_pos();
- let vec[@ast.stmt] stmts = vec();
- let Option.t[@ast.expr] expr = none[@ast.expr];
+ let vec[@ast::stmt] stmts = vec();
+ let option::t[@ast::expr] expr = none[@ast::expr];
- expect(p, token.LBRACE);
- while (p.peek() != token.RBRACE) {
+ expect(p, token::LBRACE);
+ while (p.peek() != token::RBRACE) {
alt (p.peek()) {
- case (token.RBRACE) {
+ case (token::RBRACE) {
// empty; fall through to next iteration
}
- case (token.SEMI) {
+ case (token::SEMI) {
p.bump();
// empty
}
case (_) {
auto stmt = parse_stmt(p);
alt (stmt_to_expr(stmt)) {
- case (some[@ast.expr](?e)) {
+ case (some[@ast::expr](?e)) {
alt (p.peek()) {
- case (token.SEMI) {
+ case (token::SEMI) {
p.bump();
stmts += vec(stmt);
}
- case (token.RBRACE) { expr = some(e); }
+ case (token::RBRACE) { expr = some(e); }
case (?t) {
if (stmt_ends_with_semi(stmt)) {
p.err("expected ';' or '}' after " +
"expression but found " +
- token.to_str(p.get_reader(), t));
+ token::to_str(p.get_reader(), t));
fail;
}
stmts += vec(stmt);
}
}
}
- case (none[@ast.expr]) {
+ case (none[@ast::expr]) {
// Not an expression statement.
stmts += vec(stmt);
// FIXME: crazy differentiation between conditions
// means we cannot use && here. I know, right?
if (p.get_file_type() == SOURCE_FILE) {
if (stmt_ends_with_semi(stmt)) {
- expect(p, token.SEMI);
+ expect(p, token::SEMI);
}
}
}
p.bump();
auto bloc = rec(stmts=stmts, expr=expr, a=p.get_ann());
- ret spanned[ast.block_](lo, hi, bloc);
+ ret spanned[ast::block_](lo, hi, bloc);
}
-fn parse_ty_param(parser p) -> ast.ty_param {
+fn parse_ty_param(parser p) -> ast::ty_param {
ret parse_ident(p);
}
-fn parse_ty_params(parser p) -> vec[ast.ty_param] {
- let vec[ast.ty_param] ty_params = vec();
- if (p.peek() == token.LBRACKET) {
+fn parse_ty_params(parser p) -> vec[ast::ty_param] {
+ let vec[ast::ty_param] ty_params = vec();
+ if (p.peek() == token::LBRACKET) {
auto f = parse_ty_param; // FIXME: pass as lval directly
- ty_params = parse_seq[ast.ty_param](token.LBRACKET, token.RBRACKET,
- some(token.COMMA), f, p).node;
+ ty_params = parse_seq[ast::ty_param](token::LBRACKET, token::RBRACKET,
+ some(token::COMMA), f, p).node;
}
ret ty_params;
}
-fn parse_fn_decl(parser p, ast.purity purity) -> ast.fn_decl {
+fn parse_fn_decl(parser p, ast::purity purity) -> ast::fn_decl {
auto pf = parse_arg;
- let util.common.spanned[vec[ast.arg]] inputs =
+ let util::common::spanned[vec[ast::arg]] inputs =
// FIXME: passing parse_arg as an lval doesn't work at the
// moment.
- parse_seq[ast.arg]
- (token.LPAREN,
- token.RPAREN,
- some(token.COMMA),
+ parse_seq[ast::arg]
+ (token::LPAREN,
+ token::RPAREN,
+ some(token::COMMA),
pf, p);
- let @ast.ty output;
+ let @ast::ty output;
// FIXME: dropping constrs on the floor at the moment.
// pick them up when they're used by typestate pass.
parse_constrs(p);
- if (p.peek() == token.RARROW) {
+ if (p.peek() == token::RARROW) {
p.bump();
output = parse_ty(p);
} else {
- output = @spanned(inputs.span.lo, inputs.span.hi, ast.ty_nil);
+ output = @spanned(inputs.span.lo, inputs.span.hi, ast::ty_nil);
}
// FIXME
ret rec(inputs=inputs.node, output=output, purity=purity);
}
-fn parse_fn(parser p, ast.proto proto, ast.purity purity) -> ast._fn {
+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,
}
fn parse_fn_header(parser p)
- -> tup(ast.ident, vec[ast.ty_param]) {
+ -> tup(ast::ident, vec[ast::ty_param]) {
auto id = parse_ident(p);
auto ty_params = parse_ty_params(p);
ret tup(id, ty_params);
}
-fn parse_item_fn_or_iter(parser p, ast.purity purity) -> @ast.item {
+fn parse_item_fn_or_iter(parser p, ast::purity purity) -> @ast::item {
auto lo = p.get_lo_pos();
auto proto = parse_proto(p);
auto t = parse_fn_header(p);
auto f = parse_fn(p, proto, purity);
- auto item = ast.item_fn(t._0, f, t._1,
+ auto item = ast::item_fn(t._0, f, t._1,
p.next_def_id(), p.get_ann());
ret @spanned(lo, f.body.span.hi, item);
}
-fn parse_obj_field(parser p) -> ast.obj_field {
+fn parse_obj_field(parser p) -> ast::obj_field {
auto mut = parse_mutability(p); // TODO: store this, use it in typeck
auto ty = parse_ty(p);
auto ident = parse_ident(p);
ret rec(ty=ty, ident=ident, id=p.next_def_id(), ann=p.get_ann());
}
-fn parse_method(parser p) -> @ast.method {
+fn parse_method(parser p) -> @ast::method {
auto lo = p.get_lo_pos();
auto proto = parse_proto(p);
auto ident = parse_ident(p);
- auto f = parse_fn(p, proto, ast.impure_fn);
+ auto f = parse_fn(p, proto, ast::impure_fn);
auto meth = rec(ident=ident, meth=f,
id=p.next_def_id(), ann=p.get_ann());
ret @spanned(lo, f.body.span.hi, meth);
}
-fn parse_dtor(parser p) -> @ast.method {
+fn parse_dtor(parser p) -> @ast::method {
auto lo = p.get_lo_pos();
- expect(p, token.DROP);
- let ast.block b = parse_block(p);
- let vec[ast.arg] inputs = vec();
- let @ast.ty output = @spanned(lo, lo, ast.ty_nil);
- let ast.fn_decl d = rec(inputs=inputs,
+ expect(p, token::DROP);
+ let ast::block b = parse_block(p);
+ let vec[ast::arg] inputs = vec();
+ let @ast::ty output = @spanned(lo, lo, ast::ty_nil);
+ let ast::fn_decl d = rec(inputs=inputs,
output=output,
- purity=ast.impure_fn);
- let ast._fn f = rec(decl = d,
- proto = ast.proto_fn,
+ purity=ast::impure_fn);
+ let ast::_fn f = rec(decl = d,
+ proto = ast::proto_fn,
body = b);
- let ast.method_ m = rec(ident="drop",
+ let ast::method_ m = rec(ident="drop",
meth=f,
id=p.next_def_id(),
ann=p.get_ann());
ret @spanned(lo, f.body.span.hi, m);
}
-fn parse_item_obj(parser p, ast.layer lyr) -> @ast.item {
+fn parse_item_obj(parser p, ast::layer lyr) -> @ast::item {
auto lo = p.get_lo_pos();
- expect(p, token.OBJ);
+ expect(p, token::OBJ);
auto ident = parse_ident(p);
auto ty_params = parse_ty_params(p);
auto pf = parse_obj_field;
- let util.common.spanned[vec[ast.obj_field]] fields =
- parse_seq[ast.obj_field]
- (token.LPAREN,
- token.RPAREN,
- some(token.COMMA),
+ let util::common::spanned[vec[ast::obj_field]] fields =
+ parse_seq[ast::obj_field]
+ (token::LPAREN,
+ token::RPAREN,
+ some(token::COMMA),
pf, p);
- let vec[@ast.method] meths = vec();
- let Option.t[@ast.method] dtor = none[@ast.method];
+ let vec[@ast::method] meths = vec();
+ let option::t[@ast::method] dtor = none[@ast::method];
- expect(p, token.LBRACE);
- while (p.peek() != token.RBRACE) {
+ expect(p, token::LBRACE);
+ while (p.peek() != token::RBRACE) {
alt (p.peek()) {
- case (token.DROP) {
- dtor = some[@ast.method](parse_dtor(p));
+ case (token::DROP) {
+ dtor = some[@ast::method](parse_dtor(p));
}
case (_) {
- Vec.push[@ast.method](meths,
+ _vec::push[@ast::method](meths,
parse_method(p));
}
}
}
auto hi = p.get_hi_pos();
- expect(p, token.RBRACE);
+ expect(p, token::RBRACE);
- let ast._obj ob = rec(fields=fields.node,
+ let ast::_obj ob = rec(fields=fields.node,
methods=meths,
dtor=dtor);
auto odid = rec(ty=p.next_def_id(), ctor=p.next_def_id());
- auto item = ast.item_obj(ident, ob, ty_params, odid, p.get_ann());
+ auto item = ast::item_obj(ident, ob, ty_params, odid, p.get_ann());
ret @spanned(lo, hi, item);
}
-fn parse_mod_items(parser p, token.token term) -> ast._mod {
+fn parse_mod_items(parser p, token::token term) -> ast::_mod {
auto view_items = parse_view(p);
- let vec[@ast.item] items = vec();
+ let vec[@ast::item] items = vec();
while (p.peek() != term) {
items += vec(parse_item(p));
}
ret rec(view_items=view_items, items=items);
}
-fn parse_item_const(parser p) -> @ast.item {
+fn parse_item_const(parser p) -> @ast::item {
auto lo = p.get_lo_pos();
- expect(p, token.CONST);
+ expect(p, token::CONST);
auto ty = parse_ty(p);
auto id = parse_ident(p);
- expect(p, token.EQ);
+ expect(p, token::EQ);
auto e = parse_expr(p);
auto hi = p.get_hi_pos();
- expect(p, token.SEMI);
- auto item = ast.item_const(id, ty, e, p.next_def_id(), p.get_ann());
+ expect(p, token::SEMI);
+ auto item = ast::item_const(id, ty, e, p.next_def_id(), p.get_ann());
ret @spanned(lo, hi, item);
}
-fn parse_item_mod(parser p) -> @ast.item {
+fn parse_item_mod(parser p) -> @ast::item {
auto lo = p.get_lo_pos();
- expect(p, token.MOD);
+ expect(p, token::MOD);
auto id = parse_ident(p);
- expect(p, token.LBRACE);
- auto m = parse_mod_items(p, token.RBRACE);
+ expect(p, token::LBRACE);
+ auto m = parse_mod_items(p, token::RBRACE);
auto hi = p.get_hi_pos();
- expect(p, token.RBRACE);
- auto item = ast.item_mod(id, m, p.next_def_id());
+ expect(p, token::RBRACE);
+ auto item = ast::item_mod(id, m, p.next_def_id());
ret @spanned(lo, hi, item);
}
-fn parse_item_native_type(parser p) -> @ast.native_item {
+fn parse_item_native_type(parser p) -> @ast::native_item {
auto t = parse_type_decl(p);
auto hi = p.get_hi_pos();
- expect(p, token.SEMI);
- auto item = ast.native_item_ty(t._1, p.next_def_id());
+ expect(p, token::SEMI);
+ auto item = ast::native_item_ty(t._1, p.next_def_id());
ret @spanned(t._0, hi, item);
}
-fn parse_item_native_fn(parser p) -> @ast.native_item {
+fn parse_item_native_fn(parser p) -> @ast::native_item {
auto lo = p.get_lo_pos();
- expect(p, token.FN);
+ expect(p, token::FN);
auto t = parse_fn_header(p);
- auto decl = parse_fn_decl(p, ast.impure_fn);
+ auto decl = parse_fn_decl(p, ast::impure_fn);
auto link_name = none[str];
- if (p.peek() == token.EQ) {
+ if (p.peek() == token::EQ) {
p.bump();
link_name = some[str](parse_str_lit_or_env_ident(p));
}
auto hi = p.get_hi_pos();
- expect(p, token.SEMI);
- auto item = ast.native_item_fn(t._0, link_name, decl,
+ expect(p, token::SEMI);
+ auto item = ast::native_item_fn(t._0, link_name, decl,
t._1, p.next_def_id(),
p.get_ann());
ret @spanned(lo, hi, item);
}
-fn parse_native_item(parser p) -> @ast.native_item {
- let ast.layer lyr = parse_layer(p);
+fn parse_native_item(parser p) -> @ast::native_item {
+ let ast::layer lyr = parse_layer(p);
alt (p.peek()) {
- case (token.TYPE) {
+ case (token::TYPE) {
ret parse_item_native_type(p);
}
- case (token.FN) {
+ case (token::FN) {
ret parse_item_native_fn(p);
}
case (?t) {
fn parse_native_mod_items(parser p,
str native_name,
- ast.native_abi abi) -> ast.native_mod {
- let vec[@ast.native_item] items = vec();
+ ast::native_abi abi) -> ast::native_mod {
+ let vec[@ast::native_item] items = vec();
auto view_items = parse_native_view(p);
- while (p.peek() != token.RBRACE) {
+ while (p.peek() != token::RBRACE) {
items += vec(parse_native_item(p));
}
ret rec(native_name=native_name, abi=abi,
items=items);
}
-fn default_native_name(session.session sess, str id) -> str {
+fn default_native_name(session::session sess, str id) -> str {
alt (sess.get_targ_cfg().os) {
- case (session.os_win32) {
+ case (session::os_win32) {
ret id + ".dll";
}
- case (session.os_macos) {
+ case (session::os_macos) {
ret "lib" + id + ".dylib";
}
- case (session.os_linux) {
+ case (session::os_linux) {
ret "lib" + id + ".so";
}
}
}
-fn parse_item_native_mod(parser p) -> @ast.item {
+fn parse_item_native_mod(parser p) -> @ast::item {
auto lo = p.get_lo_pos();
- expect(p, token.NATIVE);
- auto abi = ast.native_abi_cdecl;
- if (p.peek() != token.MOD) {
+ expect(p, token::NATIVE);
+ auto abi = ast::native_abi_cdecl;
+ if (p.peek() != token::MOD) {
auto t = parse_str_lit_or_env_ident(p);
- if (Str.eq(t, "cdecl")) {
- } else if (Str.eq(t, "rust")) {
- abi = ast.native_abi_rust;
- } else if (Str.eq(t, "llvm")) {
- abi = ast.native_abi_llvm;
- } else if (Str.eq(t, "rust-intrinsic")) {
- abi = ast.native_abi_rust_intrinsic;
+ if (_str::eq(t, "cdecl")) {
+ } else if (_str::eq(t, "rust")) {
+ abi = ast::native_abi_rust;
+ } else if (_str::eq(t, "llvm")) {
+ abi = ast::native_abi_llvm;
+ } else if (_str::eq(t, "rust-intrinsic")) {
+ abi = ast::native_abi_rust_intrinsic;
} else {
p.err("unsupported abi: " + t);
fail;
}
}
- expect(p, token.MOD);
+ expect(p, token::MOD);
auto id = parse_ident(p);
auto native_name;
- if (p.peek() == token.EQ) {
- expect(p, token.EQ);
+ if (p.peek() == token::EQ) {
+ expect(p, token::EQ);
native_name = parse_str_lit_or_env_ident(p);
} else {
native_name = default_native_name(p.get_session(), id);
}
- expect(p, token.LBRACE);
+ expect(p, token::LBRACE);
auto m = parse_native_mod_items(p, native_name, abi);
auto hi = p.get_hi_pos();
- expect(p, token.RBRACE);
- auto item = ast.item_native_mod(id, m, p.next_def_id());
+ expect(p, token::RBRACE);
+ auto item = ast::item_native_mod(id, m, p.next_def_id());
ret @spanned(lo, hi, item);
}
-fn parse_type_decl(parser p) -> tup(uint, ast.ident) {
+fn parse_type_decl(parser p) -> tup(uint, ast::ident) {
auto lo = p.get_lo_pos();
- expect(p, token.TYPE);
+ expect(p, token::TYPE);
auto id = parse_ident(p);
ret tup(lo, id);
}
-fn parse_item_type(parser p) -> @ast.item {
+fn parse_item_type(parser p) -> @ast::item {
auto t = parse_type_decl(p);
auto tps = parse_ty_params(p);
- expect(p, token.EQ);
+ expect(p, token::EQ);
auto ty = parse_ty(p);
auto hi = p.get_hi_pos();
- expect(p, token.SEMI);
- auto item = ast.item_ty(t._1, ty, tps, p.next_def_id(), p.get_ann());
+ expect(p, token::SEMI);
+ auto item = ast::item_ty(t._1, ty, tps, p.next_def_id(), p.get_ann());
ret @spanned(t._0, hi, item);
}
-fn parse_item_tag(parser p) -> @ast.item {
+fn parse_item_tag(parser p) -> @ast::item {
auto lo = p.get_lo_pos();
- expect(p, token.TAG);
+ expect(p, token::TAG);
auto id = parse_ident(p);
auto ty_params = parse_ty_params(p);
- let vec[ast.variant] variants = vec();
- expect(p, token.LBRACE);
- while (p.peek() != token.RBRACE) {
+ let vec[ast::variant] variants = vec();
+ expect(p, token::LBRACE);
+ while (p.peek() != token::RBRACE) {
auto tok = p.peek();
alt (tok) {
- case (token.IDENT(?name)) {
+ case (token::IDENT(?name)) {
auto vlo = p.get_lo_pos();
p.bump();
- let vec[ast.variant_arg] args = vec();
+ let vec[ast::variant_arg] args = vec();
alt (p.peek()) {
- case (token.LPAREN) {
+ case (token::LPAREN) {
auto f = parse_ty;
- auto arg_tys = parse_seq[@ast.ty](token.LPAREN,
- token.RPAREN,
- some(token.COMMA),
+ auto arg_tys = parse_seq[@ast::ty](token::LPAREN,
+ token::RPAREN,
+ some(token::COMMA),
f, p);
- for (@ast.ty ty in arg_tys.node) {
+ for (@ast::ty ty in arg_tys.node) {
args += vec(rec(ty=ty, id=p.next_def_id()));
}
}
}
auto vhi = p.get_hi_pos();
- expect(p, token.SEMI);
+ expect(p, token::SEMI);
auto id = p.next_def_id();
auto vr = rec(name=p.get_str(name), args=args,
id=id, ann=p.get_ann());
- variants += vec(spanned[ast.variant_](vlo, vhi, vr));
+ variants += vec(spanned[ast::variant_](vlo, vhi, vr));
}
- case (token.RBRACE) { /* empty */ }
+ case (token::RBRACE) { /* empty */ }
case (_) {
p.err("expected name of variant or '}' but found " +
- token.to_str(p.get_reader(), tok));
+ token::to_str(p.get_reader(), tok));
}
}
}
auto hi = p.get_hi_pos();
p.bump();
- auto item = ast.item_tag(id, variants, ty_params, p.next_def_id(),
+ auto item = ast::item_tag(id, variants, ty_params, p.next_def_id(),
p.get_ann());
ret @spanned(lo, hi, item);
}
-fn parse_layer(parser p) -> ast.layer {
+fn parse_layer(parser p) -> ast::layer {
alt (p.peek()) {
- case (token.STATE) {
+ case (token::STATE) {
p.bump();
- ret ast.layer_state;
+ ret ast::layer_state;
}
- case (token.GC) {
+ case (token::GC) {
p.bump();
- ret ast.layer_gc;
+ ret ast::layer_gc;
}
case (_) {
- ret ast.layer_value;
+ ret ast::layer_value;
}
}
fail;
}
-fn parse_auth(parser p) -> ast._auth {
+fn parse_auth(parser p) -> ast::_auth {
alt (p.peek()) {
- case (token.UNSAFE) {
+ case (token::UNSAFE) {
p.bump();
- ret ast.auth_unsafe;
+ ret ast::auth_unsafe;
}
case (?t) {
unexpected(p, t);
fn peeking_at_item(parser p) -> bool {
alt (p.peek()) {
- case (token.STATE) { ret true; }
- case (token.GC) { ret true; }
- case (token.CONST) { ret true; }
- case (token.FN) { ret true; }
- case (token.PRED) { ret true; }
- case (token.ITER) { ret true; }
- case (token.MOD) { ret true; }
- case (token.TYPE) { ret true; }
- case (token.TAG) { ret true; }
- case (token.OBJ) { ret true; }
+ case (token::STATE) { ret true; }
+ case (token::GC) { ret true; }
+ case (token::CONST) { ret true; }
+ case (token::FN) { ret true; }
+ case (token::PRED) { ret true; }
+ case (token::ITER) { ret true; }
+ case (token::MOD) { ret true; }
+ case (token::TYPE) { ret true; }
+ case (token::TAG) { ret true; }
+ case (token::OBJ) { ret true; }
case (_) { ret false; }
}
ret false;
}
-fn parse_item(parser p) -> @ast.item {
- let ast.layer lyr = parse_layer(p);
+fn parse_item(parser p) -> @ast::item {
+ let ast::layer lyr = parse_layer(p);
alt (p.peek()) {
- case (token.CONST) {
- assert (lyr == ast.layer_value);
+ case (token::CONST) {
+ assert (lyr == ast::layer_value);
ret parse_item_const(p);
}
- case (token.FN) {
- assert (lyr == ast.layer_value);
- ret parse_item_fn_or_iter(p, ast.impure_fn);
+ case (token::FN) {
+ assert (lyr == ast::layer_value);
+ ret parse_item_fn_or_iter(p, ast::impure_fn);
}
- case (token.PRED) {
- assert (lyr == ast.layer_value);
- ret parse_item_fn_or_iter(p, ast.pure_fn);
+ case (token::PRED) {
+ assert (lyr == ast::layer_value);
+ ret parse_item_fn_or_iter(p, ast::pure_fn);
}
- case (token.ITER) {
- assert (lyr == ast.layer_value);
- ret parse_item_fn_or_iter(p, ast.impure_fn);
+ case (token::ITER) {
+ assert (lyr == ast::layer_value);
+ ret parse_item_fn_or_iter(p, ast::impure_fn);
}
- case (token.MOD) {
- assert (lyr == ast.layer_value);
+ case (token::MOD) {
+ assert (lyr == ast::layer_value);
ret parse_item_mod(p);
}
- case (token.NATIVE) {
- assert (lyr == ast.layer_value);
+ case (token::NATIVE) {
+ assert (lyr == ast::layer_value);
ret parse_item_native_mod(p);
}
- case (token.TYPE) {
+ case (token::TYPE) {
ret parse_item_type(p);
}
- case (token.TAG) {
+ case (token::TAG) {
ret parse_item_tag(p);
}
- case (token.OBJ) {
+ case (token::OBJ) {
ret parse_item_obj(p, lyr);
}
case (?t) {
p.err("expected item but found " +
- token.to_str(p.get_reader(), t));
+ token::to_str(p.get_reader(), t));
}
}
fail;
}
-fn parse_meta_item(parser p) -> @ast.meta_item {
+fn parse_meta_item(parser p) -> @ast::meta_item {
auto lo = p.get_lo_pos();
auto ident = parse_ident(p);
- expect(p, token.EQ);
+ expect(p, token::EQ);
alt (p.peek()) {
- case (token.LIT_STR(?s)) {
+ case (token::LIT_STR(?s)) {
auto hi = p.get_hi_pos();
p.bump();
ret @spanned(lo, hi, rec(name = ident,
fail;
}
-fn parse_meta(parser p) -> vec[@ast.meta_item] {
+fn parse_meta(parser p) -> vec[@ast::meta_item] {
auto pf = parse_meta_item;
- ret parse_seq[@ast.meta_item](token.LPAREN, token.RPAREN,
- some(token.COMMA), pf, p).node;
+ ret parse_seq[@ast::meta_item](token::LPAREN, token::RPAREN,
+ some(token::COMMA), pf, p).node;
}
-fn parse_optional_meta(parser p) -> vec[@ast.meta_item] {
+fn parse_optional_meta(parser p) -> vec[@ast::meta_item] {
alt (p.peek()) {
- case (token.LPAREN) {
+ case (token::LPAREN) {
ret parse_meta(p);
}
case (_) {
- let vec[@ast.meta_item] v = vec();
+ let vec[@ast::meta_item] v = vec();
ret v;
}
}
}
-fn parse_use(parser p) -> @ast.view_item {
+fn parse_use(parser p) -> @ast::view_item {
auto lo = p.get_lo_pos();
- expect(p, token.USE);
+ expect(p, token::USE);
auto ident = parse_ident(p);
auto metadata = parse_optional_meta(p);
auto hi = p.get_hi_pos();
- expect(p, token.SEMI);
- auto use_decl = ast.view_item_use(ident, metadata, p.next_def_id(),
+ expect(p, token::SEMI);
+ auto use_decl = ast::view_item_use(ident, metadata, p.next_def_id(),
none[int]);
ret @spanned(lo, hi, use_decl);
}
-fn parse_rest_import_name(parser p, ast.ident first,
- Option.t[ast.ident] def_ident)
- -> @ast.view_item {
+fn parse_rest_import_name(parser p, ast::ident first,
+ option::t[ast::ident] def_ident)
+ -> @ast::view_item {
auto lo = p.get_lo_pos();
- let vec[ast.ident] identifiers = vec(first);
- while (p.peek() != token.SEMI) {
- expect(p, token.MOD_SEP);
+ let vec[ast::ident] identifiers = vec(first);
+ while (p.peek() != token::SEMI) {
+ expect(p, token::MOD_SEP);
auto i = parse_ident(p);
identifiers += vec(i);
}
p.bump();
auto defined_id;
alt (def_ident) {
- case(some[ast.ident](?i)) {
+ case(some[ast::ident](?i)) {
defined_id = i;
}
case (_) {
- auto len = Vec.len[ast.ident](identifiers);
+ auto len = _vec::len[ast::ident](identifiers);
defined_id = identifiers.(len - 1u);
}
}
- auto import_decl = ast.view_item_import(defined_id, identifiers,
+ auto import_decl = ast::view_item_import(defined_id, identifiers,
p.next_def_id());
ret @spanned(lo, hi, import_decl);
}
-fn parse_full_import_name(parser p, ast.ident def_ident)
- -> @ast.view_item {
+fn parse_full_import_name(parser p, ast::ident def_ident)
+ -> @ast::view_item {
alt (p.peek()) {
- case (token.IDENT(?i)) {
+ case (token::IDENT(?i)) {
p.bump();
ret parse_rest_import_name(p, p.get_str(i), some(def_ident));
}
fail;
}
-fn parse_import(parser p) -> @ast.view_item {
- expect(p, token.IMPORT);
+fn parse_import(parser p) -> @ast::view_item {
+ expect(p, token::IMPORT);
alt (p.peek()) {
- case (token.IDENT(?i)) {
+ case (token::IDENT(?i)) {
p.bump();
alt (p.peek()) {
- case (token.EQ) {
+ 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[ast.ident]);
+ none[ast::ident]);
}
}
}
fail;
}
-fn parse_export(parser p) -> @ast.view_item {
+fn parse_export(parser p) -> @ast::view_item {
auto lo = p.get_lo_pos();
- expect(p, token.EXPORT);
+ expect(p, token::EXPORT);
auto id = parse_ident(p);
auto hi = p.get_hi_pos();
- expect(p, token.SEMI);
- ret @spanned(lo, hi, ast.view_item_export(id));
+ expect(p, token::SEMI);
+ ret @spanned(lo, hi, ast::view_item_export(id));
}
-fn parse_view_item(parser p) -> @ast.view_item {
+fn parse_view_item(parser p) -> @ast::view_item {
alt (p.peek()) {
- case (token.USE) {
+ case (token::USE) {
ret parse_use(p);
}
- case (token.IMPORT) {
+ case (token::IMPORT) {
ret parse_import(p);
}
- case (token.EXPORT) {
+ case (token::EXPORT) {
ret parse_export(p);
}
}
}
-fn is_view_item(token.token t) -> bool {
+fn is_view_item(token::token t) -> bool {
alt (t) {
- case (token.USE) { ret true; }
- case (token.IMPORT) { ret true; }
- case (token.EXPORT) { ret true; }
+ case (token::USE) { ret true; }
+ case (token::IMPORT) { ret true; }
+ case (token::EXPORT) { ret true; }
case (_) {}
}
ret false;
}
-fn parse_view(parser p) -> vec[@ast.view_item] {
- let vec[@ast.view_item] items = vec();
+fn parse_view(parser p) -> vec[@ast::view_item] {
+ let vec[@ast::view_item] items = vec();
while (is_view_item(p.peek())) {
items += vec(parse_view_item(p));
}
ret items;
}
-fn parse_native_view(parser p) -> vec[@ast.view_item] {
- let vec[@ast.view_item] items = vec();
+fn parse_native_view(parser p) -> vec[@ast::view_item] {
+ let vec[@ast::view_item] items = vec();
while (is_view_item(p.peek())) {
items += vec(parse_view_item(p));
}
}
-fn parse_crate_from_source_file(parser p) -> @ast.crate {
+fn parse_crate_from_source_file(parser p) -> @ast::crate {
auto lo = p.get_lo_pos();
- auto m = parse_mod_items(p, token.EOF);
- let vec[@ast.crate_directive] cdirs = vec();
+ auto m = parse_mod_items(p, token::EOF);
+ let vec[@ast::crate_directive] cdirs = vec();
ret @spanned(lo, p.get_lo_pos(), rec(directives=cdirs,
module=m));
}
//
// Each directive imperatively extends its environment with 0 or more items.
-fn parse_crate_directive(parser p) -> ast.crate_directive
+fn parse_crate_directive(parser p) -> ast::crate_directive
{
auto lo = p.get_lo_pos();
alt (p.peek()) {
- case (token.AUTH) {
+ case (token::AUTH) {
p.bump();
auto n = parse_path(p);
- expect(p, token.EQ);
+ expect(p, token::EQ);
auto a = parse_auth(p);
auto hi = p.get_hi_pos();
- expect(p, token.SEMI);
- ret spanned(lo, hi, ast.cdir_auth(n, a));
+ expect(p, token::SEMI);
+ ret spanned(lo, hi, ast::cdir_auth(n, a));
}
- case (token.META) {
+ case (token::META) {
p.bump();
auto mis = parse_meta(p);
auto hi = p.get_hi_pos();
- expect(p, token.SEMI);
- ret spanned(lo, hi, ast.cdir_meta(mis));
+ expect(p, token::SEMI);
+ ret spanned(lo, hi, ast::cdir_meta(mis));
}
- case (token.MOD) {
+ case (token::MOD) {
p.bump();
auto id = parse_ident(p);
auto file_opt = none[filename];
alt (p.peek()) {
- case (token.EQ) {
+ case (token::EQ) {
p.bump();
// FIXME: turn this into parse+eval expr
file_opt = some[filename](parse_str_lit_or_env_ident(p));
// mod x = "foo.rs";
- case (token.SEMI) {
+ case (token::SEMI) {
auto hi = p.get_hi_pos();
p.bump();
- ret spanned(lo, hi, ast.cdir_src_mod(id, file_opt));
+ ret spanned(lo, hi, ast::cdir_src_mod(id, file_opt));
}
// mod x = "foo_dir" { ...directives... }
- case (token.LBRACE) {
+ case (token::LBRACE) {
p.bump();
- auto cdirs = parse_crate_directives(p, token.RBRACE);
+ auto cdirs = parse_crate_directives(p, token::RBRACE);
auto hi = p.get_hi_pos();
- expect(p, token.RBRACE);
+ expect(p, token::RBRACE);
ret spanned(lo, hi,
- ast.cdir_dir_mod(id, file_opt, cdirs));
+ ast::cdir_dir_mod(id, file_opt, cdirs));
}
case (?t) {
}
}
- case (token.LET) {
+ case (token::LET) {
p.bump();
- expect(p, token.LPAREN);
+ expect(p, token::LPAREN);
auto id = parse_ident(p);
- expect(p, token.EQ);
+ expect(p, token::EQ);
auto x = parse_expr(p);
- expect(p, token.RPAREN);
- expect(p, token.LBRACE);
- auto v = parse_crate_directives(p, token.RBRACE);
+ expect(p, token::RPAREN);
+ expect(p, token::LBRACE);
+ auto v = parse_crate_directives(p, token::RBRACE);
auto hi = p.get_hi_pos();
- expect(p, token.RBRACE);
- ret spanned(lo, hi, ast.cdir_let(id, x, v));
+ expect(p, token::RBRACE);
+ ret spanned(lo, hi, ast::cdir_let(id, x, v));
}
- case (token.USE) {
+ case (token::USE) {
auto vi = parse_view_item(p);
- ret spanned(lo, vi.span.hi, ast.cdir_view_item(vi));
+ ret spanned(lo, vi.span.hi, ast::cdir_view_item(vi));
}
- case (token.IMPORT) {
+ case (token::IMPORT) {
auto vi = parse_view_item(p);
- ret spanned(lo, vi.span.hi, ast.cdir_view_item(vi));
+ ret spanned(lo, vi.span.hi, ast::cdir_view_item(vi));
}
- case (token.EXPORT) {
+ case (token::EXPORT) {
auto vi = parse_view_item(p);
- ret spanned(lo, vi.span.hi, ast.cdir_view_item(vi));
+ ret spanned(lo, vi.span.hi, ast::cdir_view_item(vi));
}
case (_) {
auto x = parse_expr(p);
- ret spanned(lo, x.span.hi, ast.cdir_expr(x));
+ ret spanned(lo, x.span.hi, ast::cdir_expr(x));
}
}
fail;
}
-fn parse_crate_directives(parser p, token.token term)
- -> vec[@ast.crate_directive] {
+fn parse_crate_directives(parser p, token::token term)
+ -> vec[@ast::crate_directive] {
- let vec[@ast.crate_directive] cdirs = vec();
+ let vec[@ast::crate_directive] cdirs = vec();
while (p.peek() != term) {
auto cdir = @parse_crate_directive(p);
- Vec.push[@ast.crate_directive](cdirs, cdir);
+ _vec::push[@ast::crate_directive](cdirs, cdir);
}
ret cdirs;
}
-fn parse_crate_from_crate_file(parser p) -> @ast.crate {
+fn parse_crate_from_crate_file(parser p) -> @ast::crate {
auto lo = p.get_lo_pos();
- auto prefix = std.FS.dirname(p.get_filemap().name);
- auto cdirs = parse_crate_directives(p, token.EOF);
+ auto prefix = std::fs::dirname(p.get_filemap().name);
+ auto cdirs = parse_crate_directives(p, token::EOF);
let vec[str] deps = vec();
auto cx = @rec(p=p,
- mode=eval.mode_parse,
+ mode=eval::mode_parse,
mutable deps = deps,
sess=p.get_session(),
mutable chpos=p.get_chpos(),
mutable next_ann=p.next_ann_num());
- auto m = eval.eval_crate_directives_to_mod(cx, p.get_env(),
+ auto m = eval::eval_crate_directives_to_mod(cx, p.get_env(),
cdirs, prefix);
auto hi = p.get_hi_pos();
- expect(p, token.EOF);
+ expect(p, token::EOF);
ret @spanned(lo, hi, rec(directives=cdirs,
module=m));
}
-import util.common.ty_mach;
-import util.common.ty_mach_to_str;
-import util.common.new_str_hash;
-import std.Int;
-import std.UInt;
-import std.Str;
+import util::common::ty_mach;
+import util::common::ty_mach_to_str;
+import util::common::new_str_hash;
+import std::_int;
+import std::_uint;
+import std::_str;
type str_num = uint;
}
}
-fn to_str(lexer.reader r, token t) -> str {
+fn to_str(lexer::reader r, token t) -> str {
alt (t) {
case (EQ) { ret "="; }
case (JOIN) { ret "join"; }
/* Literals */
- case (LIT_INT(?i)) { ret Int.to_str(i, 10u); }
- case (LIT_UINT(?u)) { ret UInt.to_str(u, 10u); }
+ 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)
+ ret _int::to_str(i, 10u)
+ "_" + ty_mach_to_str(tm);
}
case (LIT_MACH_FLOAT(?tm, ?s)) {
case (LIT_CHAR(?c)) {
// FIXME: escape.
auto tmp = "'";
- Str.push_char(tmp, c);
- Str.push_byte(tmp, '\'' as u8);
+ _str::push_char(tmp, c);
+ _str::push_byte(tmp, '\'' as u8);
ret tmp;
}
si += r.get_str(s);
ret si;
}
- case (IDX(?i)) { ret "_" + Int.to_str(i, 10u); }
+ case (IDX(?i)) { ret "_" + _int::to_str(i, 10u); }
case (UNDERSCORE) { ret "_"; }
/* Reserved type names */
-import std.Vec;
-import std.Str;
-import std.Str.rustrt.sbuf;
-import std.Vec.rustrt.vbuf;
-
-import llvm.ModuleRef;
-import llvm.ContextRef;
-import llvm.TypeRef;
-import llvm.TypeHandleRef;
-import llvm.ValueRef;
-import llvm.BasicBlockRef;
-import llvm.BuilderRef;
-import llvm.ModuleProviderRef;
-import llvm.MemoryBufferRef;
-import llvm.PassManagerRef;
-import llvm.UseRef;
-import llvm.TargetDataRef;
-import llvm.Linkage;
-import llvm.Attribute;
-import llvm.Visibility;
-import llvm.CallConv;
-import llvm.IntPredicate;
-import llvm.RealPredicate;
-import llvm.Opcode;
-import llvm.ObjectFileRef;
-import llvm.SectionIteratorRef;
+import std::_vec;
+import std::_str;
+import std::_str::rustrt::sbuf;
+import std::_vec::rustrt::vbuf;
+
+import llvm::ModuleRef;
+import llvm::ContextRef;
+import llvm::TypeRef;
+import llvm::TypeHandleRef;
+import llvm::ValueRef;
+import llvm::BasicBlockRef;
+import llvm::BuilderRef;
+import llvm::ModuleProviderRef;
+import llvm::MemoryBufferRef;
+import llvm::PassManagerRef;
+import llvm::UseRef;
+import llvm::TargetDataRef;
+import llvm::Linkage;
+import llvm::Attribute;
+import llvm::Visibility;
+import llvm::CallConv;
+import llvm::IntPredicate;
+import llvm::RealPredicate;
+import llvm::Opcode;
+import llvm::ObjectFileRef;
+import llvm::SectionIteratorRef;
type ULongLong = u64;
type LongLong = i64;
fn LLVMBuildSelect(BuilderRef B, ValueRef If,
ValueRef Then, ValueRef Else,
sbuf Name) -> ValueRef;
- fn LLVMBuildVAArg(BuilderRef B, ValueRef List, TypeRef Ty,
+ fn LLVMBuildVAArg(BuilderRef B, ValueRef list, TypeRef Ty,
sbuf Name) -> ValueRef;
fn LLVMBuildExtractElement(BuilderRef B, ValueRef VecVal,
ValueRef Index, sbuf Name) -> ValueRef;
/** Destroys a section iterator. */
fn LLVMDisposeSectionIterator(SectionIteratorRef SI);
/** Returns true if the section iterator is at the end of the section
- List. */
+ list: */
fn LLVMIsSectionIteratorAtEnd(ObjectFileRef ObjectFile,
SectionIteratorRef SI) -> Bool;
/** Moves the section iterator to point to the next section. */
/** Parses the bitcode in the given memory buffer. */
fn LLVMRustParseBitcode(MemoryBufferRef MemBuf) -> ModuleRef;
- /** FiXME: Hacky adaptor for lack of ULongLong in FFI. */
+ /** FiXME: Hacky adaptor for lack of ULongLong in FFI: */
fn LLVMRustConstSmallInt(TypeRef IntTy, uint N,
Bool SignExtend) -> ValueRef;
fn RetVoid() -> ValueRef {
assert (!*terminated);
*terminated = true;
- ret llvm.LLVMBuildRetVoid(B);
+ ret llvm::LLVMBuildRetVoid(B);
}
fn Ret(ValueRef V) -> ValueRef {
assert (!*terminated);
*terminated = true;
- ret llvm.LLVMBuildRet(B, V);
+ ret llvm::LLVMBuildRet(B, V);
}
fn AggregateRet(vec[ValueRef] RetVals) -> ValueRef {
assert (!*terminated);
*terminated = true;
- ret llvm.LLVMBuildAggregateRet(B,
- Vec.buf[ValueRef](RetVals),
- Vec.len[ValueRef](RetVals));
+ ret llvm::LLVMBuildAggregateRet(B,
+ _vec::buf[ValueRef](RetVals),
+ _vec::len[ValueRef](RetVals));
}
fn Br(BasicBlockRef Dest) -> ValueRef {
assert (!*terminated);
*terminated = true;
- ret llvm.LLVMBuildBr(B, Dest);
+ ret llvm::LLVMBuildBr(B, Dest);
}
fn CondBr(ValueRef If, BasicBlockRef Then,
BasicBlockRef Else) -> ValueRef {
assert (!*terminated);
*terminated = true;
- ret llvm.LLVMBuildCondBr(B, If, Then, Else);
+ ret llvm::LLVMBuildCondBr(B, If, Then, Else);
}
fn Switch(ValueRef V, BasicBlockRef Else, uint NumCases) -> ValueRef {
assert (!*terminated);
*terminated = true;
- ret llvm.LLVMBuildSwitch(B, V, Else, NumCases);
+ ret llvm::LLVMBuildSwitch(B, V, Else, NumCases);
}
fn IndirectBr(ValueRef Addr, uint NumDests) -> ValueRef {
assert (!*terminated);
*terminated = true;
- ret llvm.LLVMBuildIndirectBr(B, Addr, NumDests);
+ ret llvm::LLVMBuildIndirectBr(B, Addr, NumDests);
}
fn Invoke(ValueRef Fn,
BasicBlockRef Catch) -> ValueRef {
assert (!*terminated);
*terminated = true;
- ret llvm.LLVMBuildInvoke(B, Fn,
- Vec.buf[ValueRef](Args),
- Vec.len[ValueRef](Args),
+ ret llvm::LLVMBuildInvoke(B, Fn,
+ _vec::buf[ValueRef](Args),
+ _vec::len[ValueRef](Args),
Then, Catch,
- Str.buf(""));
+ _str::buf(""));
}
fn Unwind() -> ValueRef {
assert (!*terminated);
*terminated = true;
- ret llvm.LLVMBuildUnwind(B);
+ ret llvm::LLVMBuildUnwind(B);
}
fn Unreachable() -> ValueRef {
assert (!*terminated);
*terminated = true;
- ret llvm.LLVMBuildUnreachable(B);
+ ret llvm::LLVMBuildUnreachable(B);
}
/* Arithmetic */
fn Add(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildAdd(B, LHS, RHS, Str.buf(""));
+ ret llvm::LLVMBuildAdd(B, LHS, RHS, _str::buf(""));
}
fn NSWAdd(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildNSWAdd(B, LHS, RHS, Str.buf(""));
+ ret llvm::LLVMBuildNSWAdd(B, LHS, RHS, _str::buf(""));
}
fn NUWAdd(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildNUWAdd(B, LHS, RHS, Str.buf(""));
+ ret llvm::LLVMBuildNUWAdd(B, LHS, RHS, _str::buf(""));
}
fn FAdd(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildFAdd(B, LHS, RHS, Str.buf(""));
+ ret llvm::LLVMBuildFAdd(B, LHS, RHS, _str::buf(""));
}
fn Sub(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildSub(B, LHS, RHS, Str.buf(""));
+ ret llvm::LLVMBuildSub(B, LHS, RHS, _str::buf(""));
}
fn NSWSub(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildNSWSub(B, LHS, RHS, Str.buf(""));
+ ret llvm::LLVMBuildNSWSub(B, LHS, RHS, _str::buf(""));
}
fn NUWSub(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildNUWSub(B, LHS, RHS, Str.buf(""));
+ ret llvm::LLVMBuildNUWSub(B, LHS, RHS, _str::buf(""));
}
fn FSub(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildFSub(B, LHS, RHS, Str.buf(""));
+ ret llvm::LLVMBuildFSub(B, LHS, RHS, _str::buf(""));
}
fn Mul(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildMul(B, LHS, RHS, Str.buf(""));
+ ret llvm::LLVMBuildMul(B, LHS, RHS, _str::buf(""));
}
fn NSWMul(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildNSWMul(B, LHS, RHS, Str.buf(""));
+ ret llvm::LLVMBuildNSWMul(B, LHS, RHS, _str::buf(""));
}
fn NUWMul(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildNUWMul(B, LHS, RHS, Str.buf(""));
+ ret llvm::LLVMBuildNUWMul(B, LHS, RHS, _str::buf(""));
}
fn FMul(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildFMul(B, LHS, RHS, Str.buf(""));
+ ret llvm::LLVMBuildFMul(B, LHS, RHS, _str::buf(""));
}
fn UDiv(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildUDiv(B, LHS, RHS, Str.buf(""));
+ ret llvm::LLVMBuildUDiv(B, LHS, RHS, _str::buf(""));
}
fn SDiv(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildSDiv(B, LHS, RHS, Str.buf(""));
+ ret llvm::LLVMBuildSDiv(B, LHS, RHS, _str::buf(""));
}
fn ExactSDiv(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildExactSDiv(B, LHS, RHS, Str.buf(""));
+ ret llvm::LLVMBuildExactSDiv(B, LHS, RHS, _str::buf(""));
}
fn FDiv(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildFDiv(B, LHS, RHS, Str.buf(""));
+ ret llvm::LLVMBuildFDiv(B, LHS, RHS, _str::buf(""));
}
fn URem(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildURem(B, LHS, RHS, Str.buf(""));
+ ret llvm::LLVMBuildURem(B, LHS, RHS, _str::buf(""));
}
fn SRem(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildSRem(B, LHS, RHS, Str.buf(""));
+ ret llvm::LLVMBuildSRem(B, LHS, RHS, _str::buf(""));
}
fn FRem(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildFRem(B, LHS, RHS, Str.buf(""));
+ ret llvm::LLVMBuildFRem(B, LHS, RHS, _str::buf(""));
}
fn Shl(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildShl(B, LHS, RHS, Str.buf(""));
+ ret llvm::LLVMBuildShl(B, LHS, RHS, _str::buf(""));
}
fn LShr(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildLShr(B, LHS, RHS, Str.buf(""));
+ ret llvm::LLVMBuildLShr(B, LHS, RHS, _str::buf(""));
}
fn AShr(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildAShr(B, LHS, RHS, Str.buf(""));
+ ret llvm::LLVMBuildAShr(B, LHS, RHS, _str::buf(""));
}
fn And(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildAnd(B, LHS, RHS, Str.buf(""));
+ ret llvm::LLVMBuildAnd(B, LHS, RHS, _str::buf(""));
}
fn Or(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildOr(B, LHS, RHS, Str.buf(""));
+ ret llvm::LLVMBuildOr(B, LHS, RHS, _str::buf(""));
}
fn Xor(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildXor(B, LHS, RHS, Str.buf(""));
+ ret llvm::LLVMBuildXor(B, LHS, RHS, _str::buf(""));
}
fn BinOp(Opcode Op, ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildBinOp(B, Op, LHS, RHS, Str.buf(""));
+ ret llvm::LLVMBuildBinOp(B, Op, LHS, RHS, _str::buf(""));
}
fn Neg(ValueRef V) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildNeg(B, V, Str.buf(""));
+ ret llvm::LLVMBuildNeg(B, V, _str::buf(""));
}
fn NSWNeg(ValueRef V) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildNSWNeg(B, V, Str.buf(""));
+ ret llvm::LLVMBuildNSWNeg(B, V, _str::buf(""));
}
fn NUWNeg(ValueRef V) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildNUWNeg(B, V, Str.buf(""));
+ ret llvm::LLVMBuildNUWNeg(B, V, _str::buf(""));
}
fn FNeg(ValueRef V) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildFNeg(B, V, Str.buf(""));
+ ret llvm::LLVMBuildFNeg(B, V, _str::buf(""));
}
fn Not(ValueRef V) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildNot(B, V, Str.buf(""));
+ ret llvm::LLVMBuildNot(B, V, _str::buf(""));
}
/* Memory */
fn Malloc(TypeRef Ty) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildMalloc(B, Ty, Str.buf(""));
+ ret llvm::LLVMBuildMalloc(B, Ty, _str::buf(""));
}
fn ArrayMalloc(TypeRef Ty, ValueRef Val) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildArrayMalloc(B, Ty, Val, Str.buf(""));
+ ret llvm::LLVMBuildArrayMalloc(B, Ty, Val, _str::buf(""));
}
fn Alloca(TypeRef Ty) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildAlloca(B, Ty, Str.buf(""));
+ ret llvm::LLVMBuildAlloca(B, Ty, _str::buf(""));
}
fn ArrayAlloca(TypeRef Ty, ValueRef Val) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildArrayAlloca(B, Ty, Val, Str.buf(""));
+ ret llvm::LLVMBuildArrayAlloca(B, Ty, Val, _str::buf(""));
}
fn Free(ValueRef PointerVal) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildFree(B, PointerVal);
+ ret llvm::LLVMBuildFree(B, PointerVal);
}
fn Load(ValueRef PointerVal) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildLoad(B, PointerVal, Str.buf(""));
+ ret llvm::LLVMBuildLoad(B, PointerVal, _str::buf(""));
}
fn Store(ValueRef Val, ValueRef Ptr) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildStore(B, Val, Ptr);
+ ret llvm::LLVMBuildStore(B, Val, Ptr);
}
fn GEP(ValueRef Pointer, vec[ValueRef] Indices) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildGEP(B, Pointer,
- Vec.buf[ValueRef](Indices),
- Vec.len[ValueRef](Indices),
- Str.buf(""));
+ ret llvm::LLVMBuildGEP(B, Pointer,
+ _vec::buf[ValueRef](Indices),
+ _vec::len[ValueRef](Indices),
+ _str::buf(""));
}
fn InBoundsGEP(ValueRef Pointer, vec[ValueRef] Indices) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildInBoundsGEP(B, Pointer,
- Vec.buf[ValueRef](Indices),
- Vec.len[ValueRef](Indices),
- Str.buf(""));
+ ret llvm::LLVMBuildInBoundsGEP(B, Pointer,
+ _vec::buf[ValueRef](Indices),
+ _vec::len[ValueRef](Indices),
+ _str::buf(""));
}
fn StructGEP(ValueRef Pointer, uint Idx) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildStructGEP(B, Pointer, Idx, Str.buf(""));
+ ret llvm::LLVMBuildStructGEP(B, Pointer, Idx, _str::buf(""));
}
fn GlobalString(sbuf _Str) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildGlobalString(B, _Str, Str.buf(""));
+ ret llvm::LLVMBuildGlobalString(B, _Str, _str::buf(""));
}
fn GlobalStringPtr(sbuf _Str) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildGlobalStringPtr(B, _Str, Str.buf(""));
+ ret llvm::LLVMBuildGlobalStringPtr(B, _Str, _str::buf(""));
}
/* Casts */
fn Trunc(ValueRef Val, TypeRef DestTy) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildTrunc(B, Val, DestTy, Str.buf(""));
+ ret llvm::LLVMBuildTrunc(B, Val, DestTy, _str::buf(""));
}
fn ZExt(ValueRef Val, TypeRef DestTy) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildZExt(B, Val, DestTy, Str.buf(""));
+ ret llvm::LLVMBuildZExt(B, Val, DestTy, _str::buf(""));
}
fn SExt(ValueRef Val, TypeRef DestTy) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildSExt(B, Val, DestTy, Str.buf(""));
+ ret llvm::LLVMBuildSExt(B, Val, DestTy, _str::buf(""));
}
fn FPToUI(ValueRef Val, TypeRef DestTy) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildFPToUI(B, Val, DestTy, Str.buf(""));
+ ret llvm::LLVMBuildFPToUI(B, Val, DestTy, _str::buf(""));
}
fn FPToSI(ValueRef Val, TypeRef DestTy) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildFPToSI(B, Val, DestTy, Str.buf(""));
+ ret llvm::LLVMBuildFPToSI(B, Val, DestTy, _str::buf(""));
}
fn UIToFP(ValueRef Val, TypeRef DestTy) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildUIToFP(B, Val, DestTy, Str.buf(""));
+ ret llvm::LLVMBuildUIToFP(B, Val, DestTy, _str::buf(""));
}
fn SIToFP(ValueRef Val, TypeRef DestTy) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildSIToFP(B, Val, DestTy, Str.buf(""));
+ ret llvm::LLVMBuildSIToFP(B, Val, DestTy, _str::buf(""));
}
fn FPTrunc(ValueRef Val, TypeRef DestTy) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildFPTrunc(B, Val, DestTy, Str.buf(""));
+ ret llvm::LLVMBuildFPTrunc(B, Val, DestTy, _str::buf(""));
}
fn FPExt(ValueRef Val, TypeRef DestTy) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildFPExt(B, Val, DestTy, Str.buf(""));
+ ret llvm::LLVMBuildFPExt(B, Val, DestTy, _str::buf(""));
}
fn PtrToInt(ValueRef Val, TypeRef DestTy) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildPtrToInt(B, Val, DestTy, Str.buf(""));
+ ret llvm::LLVMBuildPtrToInt(B, Val, DestTy, _str::buf(""));
}
fn IntToPtr(ValueRef Val, TypeRef DestTy) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildIntToPtr(B, Val, DestTy, Str.buf(""));
+ ret llvm::LLVMBuildIntToPtr(B, Val, DestTy, _str::buf(""));
}
fn BitCast(ValueRef Val, TypeRef DestTy) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildBitCast(B, Val, DestTy, Str.buf(""));
+ ret llvm::LLVMBuildBitCast(B, Val, DestTy, _str::buf(""));
}
fn ZExtOrBitCast(ValueRef Val, TypeRef DestTy) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildZExtOrBitCast(B, Val, DestTy, Str.buf(""));
+ ret llvm::LLVMBuildZExtOrBitCast(B, Val, DestTy, _str::buf(""));
}
fn SExtOrBitCast(ValueRef Val, TypeRef DestTy) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildSExtOrBitCast(B, Val, DestTy, Str.buf(""));
+ ret llvm::LLVMBuildSExtOrBitCast(B, Val, DestTy, _str::buf(""));
}
fn TruncOrBitCast(ValueRef Val, TypeRef DestTy) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildTruncOrBitCast(B, Val, DestTy, Str.buf(""));
+ ret llvm::LLVMBuildTruncOrBitCast(B, Val, DestTy, _str::buf(""));
}
fn Cast(Opcode Op, ValueRef Val, TypeRef DestTy, sbuf Name) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildCast(B, Op, Val, DestTy, Str.buf(""));
+ ret llvm::LLVMBuildCast(B, Op, Val, DestTy, _str::buf(""));
}
fn PointerCast(ValueRef Val, TypeRef DestTy) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildPointerCast(B, Val, DestTy, Str.buf(""));
+ ret llvm::LLVMBuildPointerCast(B, Val, DestTy, _str::buf(""));
}
fn IntCast(ValueRef Val, TypeRef DestTy) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildIntCast(B, Val, DestTy, Str.buf(""));
+ ret llvm::LLVMBuildIntCast(B, Val, DestTy, _str::buf(""));
}
fn FPCast(ValueRef Val, TypeRef DestTy) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildFPCast(B, Val, DestTy, Str.buf(""));
+ ret llvm::LLVMBuildFPCast(B, Val, DestTy, _str::buf(""));
}
/* Comparisons */
fn ICmp(uint Op, ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildICmp(B, Op, LHS, RHS, Str.buf(""));
+ ret llvm::LLVMBuildICmp(B, Op, LHS, RHS, _str::buf(""));
}
fn FCmp(uint Op, ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildFCmp(B, Op, LHS, RHS, Str.buf(""));
+ ret llvm::LLVMBuildFCmp(B, Op, LHS, RHS, _str::buf(""));
}
fn Phi(TypeRef Ty, vec[ValueRef] vals,
vec[BasicBlockRef] bbs) -> ValueRef {
assert (!*terminated);
- auto phi = llvm.LLVMBuildPhi(B, Ty, Str.buf(""));
- assert (Vec.len[ValueRef](vals) == Vec.len[BasicBlockRef](bbs));
- llvm.LLVMAddIncoming(phi,
- Vec.buf[ValueRef](vals),
- Vec.buf[BasicBlockRef](bbs),
- Vec.len[ValueRef](vals));
+ auto phi = llvm::LLVMBuildPhi(B, Ty, _str::buf(""));
+ assert (_vec::len[ValueRef](vals) == _vec::len[BasicBlockRef](bbs));
+ llvm::LLVMAddIncoming(phi,
+ _vec::buf[ValueRef](vals),
+ _vec::buf[BasicBlockRef](bbs),
+ _vec::len[ValueRef](vals));
ret phi;
}
fn AddIncomingToPhi(ValueRef phi,
vec[ValueRef] vals,
vec[BasicBlockRef] bbs) {
- assert (Vec.len[ValueRef](vals) == Vec.len[BasicBlockRef](bbs));
- llvm.LLVMAddIncoming(phi,
- Vec.buf[ValueRef](vals),
- Vec.buf[BasicBlockRef](bbs),
- Vec.len[ValueRef](vals));
+ assert (_vec::len[ValueRef](vals) == _vec::len[BasicBlockRef](bbs));
+ llvm::LLVMAddIncoming(phi,
+ _vec::buf[ValueRef](vals),
+ _vec::buf[BasicBlockRef](bbs),
+ _vec::len[ValueRef](vals));
}
fn Call(ValueRef Fn, vec[ValueRef] Args) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildCall(B, Fn,
- Vec.buf[ValueRef](Args),
- Vec.len[ValueRef](Args),
- Str.buf(""));
+ ret llvm::LLVMBuildCall(B, Fn,
+ _vec::buf[ValueRef](Args),
+ _vec::len[ValueRef](Args),
+ _str::buf(""));
}
fn FastCall(ValueRef Fn, vec[ValueRef] Args) -> ValueRef {
assert (!*terminated);
- auto v = llvm.LLVMBuildCall(B, Fn,
- Vec.buf[ValueRef](Args),
- Vec.len[ValueRef](Args),
- Str.buf(""));
- llvm.LLVMSetInstructionCallConv(v, LLVMFastCallConv);
+ auto v = llvm::LLVMBuildCall(B, Fn,
+ _vec::buf[ValueRef](Args),
+ _vec::len[ValueRef](Args),
+ _str::buf(""));
+ llvm::LLVMSetInstructionCallConv(v, LLVMFastCallConv);
ret v;
}
fn Select(ValueRef If, ValueRef Then, ValueRef Else) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildSelect(B, If, Then, Else, Str.buf(""));
+ ret llvm::LLVMBuildSelect(B, If, Then, Else, _str::buf(""));
}
- fn VAArg(ValueRef List, TypeRef Ty) -> ValueRef {
+ fn VAArg(ValueRef list, TypeRef Ty) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildVAArg(B, List, Ty, Str.buf(""));
+ ret llvm::LLVMBuildVAArg(B, list, Ty, _str::buf(""));
}
fn ExtractElement(ValueRef VecVal, ValueRef Index) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildExtractElement(B, VecVal, Index, Str.buf(""));
+ ret llvm::LLVMBuildExtractElement(B, VecVal, Index, _str::buf(""));
}
fn InsertElement(ValueRef VecVal, ValueRef EltVal,
ValueRef Index) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildInsertElement(B, VecVal, EltVal, Index,
- Str.buf(""));
+ ret llvm::LLVMBuildInsertElement(B, VecVal, EltVal, Index,
+ _str::buf(""));
}
fn ShuffleVector(ValueRef V1, ValueRef V2, ValueRef Mask) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildShuffleVector(B, V1, V2, Mask, Str.buf(""));
+ ret llvm::LLVMBuildShuffleVector(B, V1, V2, Mask, _str::buf(""));
}
fn ExtractValue(ValueRef AggVal, uint Index) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildExtractValue(B, AggVal, Index, Str.buf(""));
+ ret llvm::LLVMBuildExtractValue(B, AggVal, Index, _str::buf(""));
}
fn InsertValue(ValueRef AggVal, ValueRef EltVal,
uint Index) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildInsertValue(B, AggVal, EltVal, Index, Str.buf(""));
+ ret llvm::LLVMBuildInsertValue(B, AggVal, EltVal, Index,
+ _str::buf(""));
}
fn IsNull(ValueRef Val) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildIsNull(B, Val, Str.buf(""));
+ ret llvm::LLVMBuildIsNull(B, Val, _str::buf(""));
}
fn IsNotNull(ValueRef Val) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildIsNotNull(B, Val, Str.buf(""));
+ ret llvm::LLVMBuildIsNotNull(B, Val, _str::buf(""));
}
fn PtrDiff(ValueRef LHS, ValueRef RHS) -> ValueRef {
assert (!*terminated);
- ret llvm.LLVMBuildPtrDiff(B, LHS, RHS, Str.buf(""));
+ 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 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"));
assert (T as int != 0);
let vec[ValueRef] Args = vec();
- ret llvm.LLVMBuildCall(B, T,
- Vec.buf[ValueRef](Args),
- Vec.len[ValueRef](Args),
- Str.buf(""));
+ ret llvm::LLVMBuildCall(B, T,
+ _vec::buf[ValueRef](Args),
+ _vec::len[ValueRef](Args),
+ _str::buf(""));
}
drop {
- llvm.LLVMDisposeBuilder(B);
+ llvm::LLVMDisposeBuilder(B);
}
}
/* Memory-managed object interface to type handles. */
obj type_handle_dtor(TypeHandleRef TH) {
- drop { llvm.LLVMDisposeTypeHandle(TH); }
+ drop { llvm::LLVMDisposeTypeHandle(TH); }
}
type type_handle = rec(TypeHandleRef llth, type_handle_dtor dtor);
fn mk_type_handle() -> type_handle {
- auto th = llvm.LLVMCreateTypeHandle(llvm.LLVMOpaqueType());
+ auto th = llvm::LLVMCreateTypeHandle(llvm::LLVMOpaqueType());
ret rec(llth=th, dtor=type_handle_dtor(th));
}
-state obj type_names(std.Map.hashmap[TypeRef, str] type_names,
- std.Map.hashmap[str, TypeRef] named_types) {
+state obj type_names(std::map::hashmap[TypeRef, str] type_names,
+ std::map::hashmap[str, TypeRef] named_types) {
fn associate(str s, TypeRef t) {
assert (!named_types.contains_key(s));
}
fn mk_type_names() -> type_names {
- auto nt = util.common.new_str_hash[TypeRef]();
+ auto nt = util::common::new_str_hash[TypeRef]();
fn hash(&TypeRef t) -> uint {
ret t as uint;
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 std::map::hashfn[TypeRef] hasher = hash;
+ let std::map::eqfn[TypeRef] eqer = eq;
+ auto tn = std::map::mk_hashmap[TypeRef,str](hasher, eqer);
ret type_names(tn, nt);
}
auto outer = outer0 + vec(ty);
- let int kind = llvm.LLVMGetTypeKind(ty);
+ let int kind = llvm::LLVMGetTypeKind(ty);
fn tys_str(type_names names,
vec[TypeRef] outer, vec[TypeRef] tys) -> str {
alt (kind) {
- // FIXME: more enum-as-int constants determined from Core.h;
+ // FIXME: more enum-as-int constants determined from Core::h;
// horrible, horrible. Complete as needed.
case (0) { ret "Void"; }
case (6) { ret "Label"; }
case (7) {
- ret "i" + util.common.istr(llvm.LLVMGetIntTypeWidth(ty) as int);
+ ret "i" + util::common::istr(llvm::LLVMGetIntTypeWidth(ty)
+ as int);
}
case (8) {
auto s = "fn(";
- let TypeRef out_ty = llvm.LLVMGetReturnType(ty);
- let uint n_args = llvm.LLVMCountParamTypes(ty);
+ let TypeRef out_ty = llvm::LLVMGetReturnType(ty);
+ let uint n_args = llvm::LLVMCountParamTypes(ty);
let vec[TypeRef] args =
- Vec.init_elt[TypeRef](0 as TypeRef, n_args);
- llvm.LLVMGetParamTypes(ty, Vec.buf[TypeRef](args));
+ _vec::init_elt[TypeRef](0 as TypeRef, n_args);
+ llvm::LLVMGetParamTypes(ty, _vec::buf[TypeRef](args));
s += tys_str(names, outer, args);
s += ") -> ";
s += type_to_str_inner(names, outer, out_ty);
case (9) {
let str s = "{";
- let uint n_elts = llvm.LLVMCountStructElementTypes(ty);
+ let uint n_elts = llvm::LLVMCountStructElementTypes(ty);
let vec[TypeRef] elts =
- Vec.init_elt[TypeRef](0 as TypeRef, n_elts);
- llvm.LLVMGetStructElementTypes(ty, Vec.buf[TypeRef](elts));
+ _vec::init_elt[TypeRef](0 as TypeRef, n_elts);
+ llvm::LLVMGetStructElementTypes(ty, _vec::buf[TypeRef](elts));
s += tys_str(names, outer, elts);
s += "}";
ret s;
for (TypeRef tout in outer0) {
i += 1u;
if (tout as int == ty as int) {
- let uint n = Vec.len[TypeRef](outer0) - i;
- ret "*\\" + util.common.istr(n as int);
+ let uint n = _vec::len[TypeRef](outer0) - i;
+ ret "*\\" + util::common::istr(n as int);
}
}
ret "*" + type_to_str_inner(names, outer,
- llvm.LLVMGetElementType(ty));
+ llvm::LLVMGetElementType(ty));
}
case (12) { ret "Opaque"; }
/* Memory-managed interface to target data. */
obj target_data_dtor(TargetDataRef TD) {
- drop { llvm.LLVMDisposeTargetData(TD); }
+ drop { llvm::LLVMDisposeTargetData(TD); }
}
type target_data = rec(TargetDataRef lltd, target_data_dtor dtor);
fn mk_target_data(str string_rep) -> target_data {
- auto lltd = llvm.LLVMCreateTargetData(Str.buf(string_rep));
+ auto lltd = llvm::LLVMCreateTargetData(_str::buf(string_rep));
ret rec(lltd=lltd, dtor=target_data_dtor(lltd));
}
/* Memory-managed interface to pass managers. */
obj pass_manager_dtor(PassManagerRef PM) {
- drop { llvm.LLVMDisposePassManager(PM); }
+ drop { llvm::LLVMDisposePassManager(PM); }
}
type pass_manager = rec(PassManagerRef llpm, pass_manager_dtor dtor);
fn mk_pass_manager() -> pass_manager {
- auto llpm = llvm.LLVMCreatePassManager();
+ auto llpm = llvm::LLVMCreatePassManager();
ret rec(llpm=llpm, dtor=pass_manager_dtor(llpm));
}
/* Memory-managed interface to object files. */
obj object_file_dtor(ObjectFileRef ObjectFile) {
- drop { llvm.LLVMDisposeObjectFile(ObjectFile); }
+ drop { llvm::LLVMDisposeObjectFile(ObjectFile); }
}
type object_file = rec(ObjectFileRef llof, object_file_dtor dtor);
fn mk_object_file(MemoryBufferRef llmb) -> object_file {
- auto llof = llvm.LLVMCreateObjectFile(llmb);
+ auto llof = llvm::LLVMCreateObjectFile(llmb);
ret rec(llof=llof, dtor=object_file_dtor(llof));
}
/* Memory-managed interface to section iterators. */
obj section_iter_dtor(SectionIteratorRef SI) {
- drop { llvm.LLVMDisposeSectionIterator(SI); }
+ drop { llvm::LLVMDisposeSectionIterator(SI); }
}
type section_iter = rec(SectionIteratorRef llsi, section_iter_dtor dtor);
fn mk_section_iter(ObjectFileRef llof) -> section_iter {
- auto llsi = llvm.LLVMGetSections(llof);
+ auto llsi = llvm::LLVMGetSections(llof);
ret rec(llsi=llsi, dtor=section_iter_dtor(llsi));
}
-import driver.session;
-import front.ast;
-import std.Map.hashmap;
-import std.Option;
-import std.Option.some;
-import std.Option.none;
-import std.Int;
-import std.Vec;
-import util.common;
-import resolve.def_map;
+import driver::session;
+import front::ast;
+import std::map::hashmap;
+import std::option;
+import std::option::some;
+import std::option::none;
+import std::_int;
+import std::_vec;
+import util::common;
+import resolve::def_map;
-type fn_id_of_local = std.Map.hashmap[ast.def_id, ast.def_id];
-type env = rec(mutable vec[ast.def_id] current_context, // fn or obj
+type fn_id_of_local = std::map::hashmap[ast::def_id, ast::def_id];
+type env = rec(mutable vec[ast::def_id] current_context, // fn or obj
def_map def_map,
fn_id_of_local idmap,
- session.session sess);
+ session::session sess);
-fn current_context(&env e) -> ast.def_id {
- ret e.current_context.(Vec.len(e.current_context) - 1u);
+fn current_context(&env e) -> ast::def_id {
+ ret e.current_context.(_vec::len(e.current_context) - 1u);
}
-fn enter_item(@env e, &@ast.item i) {
+fn enter_item(@env e, &@ast::item i) {
alt (i.node) {
- case (ast.item_fn(?name, _, _, ?id, _)) {
- Vec.push(e.current_context, id);
+ case (ast::item_fn(?name, _, _, ?id, _)) {
+ _vec::push(e.current_context, id);
}
- case (ast.item_obj(?name, _, _, ?ids, _)) {
- Vec.push(e.current_context, ids.ty);
+ case (ast::item_obj(?name, _, _, ?ids, _)) {
+ _vec::push(e.current_context, ids.ty);
}
case (_) {}
}
}
-fn leave_item(@env e, &@ast.item i) {
+fn leave_item(@env e, &@ast::item i) {
alt (i.node) {
- case (ast.item_fn(?name, _, _, ?id, _)) {
- Vec.pop(e.current_context);
+ case (ast::item_fn(?name, _, _, ?id, _)) {
+ _vec::pop(e.current_context);
}
- case (ast.item_obj(_, _, _, ?ids, _)) {
- Vec.pop(e.current_context);
+ case (ast::item_obj(_, _, _, ?ids, _)) {
+ _vec::pop(e.current_context);
}
case (_) {}
}
}
-fn walk_expr(@env e, &@ast.expr x) {
+fn walk_expr(@env e, &@ast::expr x) {
alt (x.node) {
- case (ast.expr_for(?d, _, _, _)) {
+ case (ast::expr_for(?d, _, _, _)) {
alt (d.node) {
- case (ast.decl_local(?local)) {
+ case (ast::decl_local(?local)) {
e.idmap.insert(local.id, current_context(*e));
}
case (_) { }
}
}
- case (ast.expr_for_each(?d, _, _, _)) {
+ case (ast::expr_for_each(?d, _, _, _)) {
alt (d.node) {
- case (ast.decl_local(?local)) {
+ case (ast::decl_local(?local)) {
e.idmap.insert(local.id, current_context(*e));
}
case (_) { }
}
}
- case (ast.expr_path(?pt, ?ann)) {
+ case (ast::expr_path(?pt, ?ann)) {
auto local_id;
- alt (e.def_map.get(ast.ann_tag(ann))) {
- case (ast.def_local(?id)) { local_id = id; }
+ alt (e.def_map.get(ast::ann_tag(ann))) {
+ case (ast::def_local(?id)) { local_id = id; }
case (_) { ret; }
}
- auto df = ast.def_id_of_def(e.def_map.get(ast.ann_tag(ann)));
+ auto df = ast::def_id_of_def(e.def_map.get(ast::ann_tag(ann)));
auto def_context = e.idmap.get(df);
if (current_context(*e) != def_context) {
}
}
-fn walk_block(@env e, &ast.block b) {
- for (@ast.stmt st in b.node.stmts) {
+fn walk_block(@env e, &ast::block b) {
+ for (@ast::stmt st in b.node.stmts) {
alt (st.node) {
- case (ast.stmt_decl(?d,_)) {
+ case (ast::stmt_decl(?d,_)) {
alt (d.node) {
- case (ast.decl_local(?loc)) {
+ case (ast::decl_local(?loc)) {
e.idmap.insert(loc.id, current_context(*e));
}
case (_) { }
}
}
-fn check_for_captures(session.session sess, @ast.crate crate, def_map dm) {
- let vec[ast.def_id] curctx = vec();
+fn check_for_captures(session::session sess, @ast::crate crate, def_map dm) {
+ let vec[ast::def_id] curctx = vec();
auto env = @rec(mutable current_context = curctx,
def_map = dm,
- idmap = common.new_def_hash[ast.def_id](),
+ idmap = common::new_def_hash[ast::def_id](),
sess = sess);
auto visitor = rec(visit_item_pre = bind enter_item(env, _),
visit_item_post = bind leave_item(env, _),
visit_block_pre = bind walk_block(env, _),
visit_expr_pre = bind walk_expr(env, _)
- with walk.default_visitor());
- walk.walk_crate(visitor, *crate);
+ with walk::default_visitor());
+ walk::walk_crate(visitor, *crate);
}
// Local Variables:
-import std.Map.hashmap;
-import std.Option;
-import std.Option.some;
-import std.Option.none;
-
-import util.common.new_str_hash;
-import util.common.spanned;
-import util.common.span;
-import util.common.ty_mach;
-import util.typestate_ann.ts_ann;
-
-import front.ast;
-import front.ast.fn_decl;
-import front.ast.ident;
-import front.ast.path;
-import front.ast.mutability;
-import front.ast.ty;
-import front.ast.expr;
-import front.ast.stmt;
-import front.ast.block;
-import front.ast.item;
-import front.ast.view_item;
-import front.ast.meta_item;
-import front.ast.native_item;
-import front.ast.arg;
-import front.ast.pat;
-import front.ast.decl;
-import front.ast.arm;
-import front.ast.def;
-import front.ast.def_id;
-import front.ast.ann;
-import front.ast.mt;
-import front.ast.purity;
-
-import std.UInt;
-import std.Vec;
+import std::map::hashmap;
+import std::option;
+import std::option::some;
+import std::option::none;
+
+import util::common::new_str_hash;
+import util::common::spanned;
+import util::common::span;
+import util::common::ty_mach;
+import util::typestate_ann::ts_ann;
+
+import front::ast;
+import front::ast::fn_decl;
+import front::ast::ident;
+import front::ast::path;
+import front::ast::mutability;
+import front::ast::ty;
+import front::ast::expr;
+import front::ast::stmt;
+import front::ast::block;
+import front::ast::item;
+import front::ast::view_item;
+import front::ast::meta_item;
+import front::ast::native_item;
+import front::ast::arg;
+import front::ast::pat;
+import front::ast::decl;
+import front::ast::arm;
+import front::ast::def;
+import front::ast::def_id;
+import front::ast::ann;
+import front::ast::mt;
+import front::ast::purity;
+
+import std::_uint;
+import std::_vec;
type ast_fold[ENV] =
@rec
(
- // Path fold.
- (fn(&ENV e, &span sp, &ast.path_ p) -> path) fold_path,
+ // Path fold:
+ (fn(&ENV e, &span sp, &ast::path_ p) -> path) fold_path,
// Type folds.
(fn(&ENV e, &span sp) -> @ty) fold_ty_nil,
(fn(&ENV e, &span sp, &vec[mt] elts) -> @ty) fold_ty_tup,
(fn(&ENV e, &span sp,
- &vec[ast.ty_field] elts) -> @ty) fold_ty_rec,
+ &vec[ast::ty_field] elts) -> @ty) fold_ty_rec,
(fn(&ENV e, &span sp,
- &vec[ast.ty_method] meths) -> @ty) fold_ty_obj,
+ &vec[ast::ty_method] meths) -> @ty) fold_ty_obj,
(fn(&ENV e, &span sp,
- ast.proto proto,
- &vec[rec(ast.mode mode, @ty ty)] inputs,
+ ast::proto proto,
+ &vec[rec(ast::mode mode, @ty ty)] inputs,
&@ty output) -> @ty) fold_ty_fn,
- (fn(&ENV e, &span sp, &ast.path p,
+ (fn(&ENV e, &span sp, &ast::path p,
&ann a) -> @ty) fold_ty_path,
(fn(&ENV e, &span sp, &@ty t) -> @ty) fold_ty_chan,
// Expr folds.
(fn(&ENV e, &span sp,
- &vec[@expr] es, ast.mutability mut,
+ &vec[@expr] es, ast::mutability mut,
&ann a) -> @expr) fold_expr_vec,
(fn(&ENV e, &span sp,
- &vec[ast.elt] es, &ann a) -> @expr) fold_expr_tup,
+ &vec[ast::elt] es, &ann a) -> @expr) fold_expr_tup,
(fn(&ENV e, &span sp,
- &vec[ast.field] fields,
- &Option.t[@expr] base, &ann a) -> @expr) fold_expr_rec,
+ &vec[ast::field] fields,
+ &option::t[@expr] base, &ann a) -> @expr) fold_expr_rec,
(fn(&ENV e, &span sp,
&@expr f, &vec[@expr] args,
&ident id, &ann a) -> @expr) fold_expr_self_method,
(fn(&ENV e, &span sp,
- &@expr f, &vec[Option.t[@expr]] args,
+ &@expr f, &vec[option::t[@expr]] args,
&ann a) -> @expr) fold_expr_bind,
(fn(&ENV e, &span sp,
- ast.spawn_dom dom, &Option.t[str] name,
+ ast::spawn_dom dom, &option::t[str] name,
&@expr f, &vec[@expr] args,
&ann a) -> @expr) fold_expr_spawn,
(fn(&ENV e, &span sp,
- ast.binop,
+ ast::binop,
&@expr lhs, &@expr rhs,
&ann a) -> @expr) fold_expr_binary,
(fn(&ENV e, &span sp,
- ast.unop, &@expr e,
+ ast::unop, &@expr e,
&ann a) -> @expr) fold_expr_unary,
(fn(&ENV e, &span sp,
- &@ast.lit, &ann a) -> @expr) fold_expr_lit,
+ &@ast::lit, &ann a) -> @expr) fold_expr_lit,
(fn(&ENV e, &span sp,
- &@ast.expr e, &@ast.ty ty,
+ &@ast::expr e, &@ast::ty ty,
&ann a) -> @expr) fold_expr_cast,
(fn(&ENV e, &span sp,
&@expr cond, &block thn,
- &Option.t[@expr] els,
+ &option::t[@expr] els,
&ann a) -> @expr) fold_expr_if,
(fn(&ENV e, &span sp,
&ann a) -> @expr) fold_expr_assign,
(fn(&ENV e, &span sp,
- ast.binop,
+ ast::binop,
&@expr lhs, &@expr rhs,
&ann a) -> @expr) fold_expr_assign_op,
(fn(&ENV e, &span sp,
&path p, &vec[@expr] args,
- &Option.t[str] body,
+ &option::t[str] body,
&@expr expanded,
&ann a) -> @expr) fold_expr_ext,
(fn(&ENV e, &span sp, &ann a) -> @expr) fold_expr_cont,
(fn(&ENV e, &span sp,
- &Option.t[@expr] rv, &ann a) -> @expr) fold_expr_ret,
+ &option::t[@expr] rv, &ann a) -> @expr) fold_expr_ret,
(fn(&ENV e, &span sp,
- &Option.t[@expr] rv, &ann a) -> @expr) fold_expr_put,
+ &option::t[@expr] rv, &ann a) -> @expr) fold_expr_put,
(fn(&ENV e, &span sp,
&@expr e, &ann a) -> @expr) fold_expr_be,
// Decl folds.
(fn(&ENV e, &span sp,
- &@ast.local local) -> @decl) fold_decl_local,
+ &@ast::local local) -> @decl) fold_decl_local,
(fn(&ENV e, &span sp,
&@item item) -> @decl) fold_decl_item,
&ann a) -> @pat) fold_pat_wild,
(fn(&ENV e, &span sp,
- &@ast.lit lit, &ann a) -> @pat) fold_pat_lit,
+ &@ast::lit lit, &ann a) -> @pat) fold_pat_lit,
(fn(&ENV e, &span sp,
&ident i, &def_id did, &ann a) -> @pat) fold_pat_bind,
&def_id id, &ann a) -> @item) fold_item_const,
(fn(&ENV e, &span sp, &ident ident,
- &ast._fn f,
- &vec[ast.ty_param] ty_params,
+ &ast::_fn f,
+ &vec[ast::ty_param] ty_params,
&def_id id, &ann a) -> @item) fold_item_fn,
(fn(&ENV e, &span sp, &ident ident,
- &Option.t[str] link_name,
- &ast.fn_decl decl,
- &vec[ast.ty_param] ty_params,
+ &option::t[str] link_name,
+ &ast::fn_decl decl,
+ &vec[ast::ty_param] ty_params,
&def_id id, &ann a) -> @native_item) fold_native_item_fn,
(fn(&ENV e, &span sp, &ident ident,
- &ast._mod m, &def_id id) -> @item) fold_item_mod,
+ &ast::_mod m, &def_id id) -> @item) fold_item_mod,
(fn(&ENV e, &span sp, &ident ident,
- &ast.native_mod m, &def_id id) -> @item) fold_item_native_mod,
+ &ast::native_mod m, &def_id id) -> @item) fold_item_native_mod,
(fn(&ENV e, &span sp, &ident ident,
- &@ty t, &vec[ast.ty_param] ty_params,
+ &@ty t, &vec[ast::ty_param] ty_params,
&def_id id, &ann a) -> @item) fold_item_ty,
(fn(&ENV e, &span sp, &ident ident,
&def_id id) -> @native_item) fold_native_item_ty,
(fn(&ENV e, &span sp, &ident ident,
- &vec[ast.variant] variants,
- &vec[ast.ty_param] ty_params,
+ &vec[ast::variant] variants,
+ &vec[ast::ty_param] ty_params,
&def_id id, &ann a) -> @item) fold_item_tag,
(fn(&ENV e, &span sp, &ident ident,
- &ast._obj ob,
- &vec[ast.ty_param] ty_params,
- &ast.obj_def_ids odid, &ann a) -> @item) fold_item_obj,
+ &ast::_obj ob,
+ &vec[ast::ty_param] ty_params,
+ &ast::obj_def_ids odid, &ann a) -> @item) fold_item_obj,
// View Item folds.
(fn(&ENV e, &span sp, &ident ident,
&vec[@meta_item] meta_items,
&def_id id,
- &Option.t[int]) -> @view_item) fold_view_item_use,
+ &option::t[int]) -> @view_item) fold_view_item_use,
(fn(&ENV e, &span sp, &ident i,
&vec[ident] idents,
// Additional nodes.
(fn(&ENV e, &fn_decl decl,
- ast.proto proto,
- &block body) -> ast._fn) fold_fn,
+ ast::proto proto,
+ &block body) -> ast::_fn) fold_fn,
(fn(&ENV e,
&vec[arg] inputs,
&@ty output,
- &purity p) -> ast.fn_decl) fold_fn_decl,
+ &purity p) -> ast::fn_decl) fold_fn_decl,
- (fn(&ENV e, &ast._mod m) -> ast._mod) fold_mod,
+ (fn(&ENV e, &ast::_mod m) -> ast::_mod) fold_mod,
- (fn(&ENV e, &ast.native_mod m) -> ast.native_mod) fold_native_mod,
+ (fn(&ENV e, &ast::native_mod m) -> ast::native_mod) fold_native_mod,
(fn(&ENV e, &span sp,
- &vec[@ast.crate_directive] cdirs,
- &ast._mod m) -> @ast.crate) fold_crate,
+ &vec[@ast::crate_directive] cdirs,
+ &ast::_mod m) -> @ast::crate) fold_crate,
(fn(&ENV e,
- &vec[ast.obj_field] fields,
- &vec[@ast.method] methods,
- &Option.t[@ast.method] dtor)
- -> ast._obj) fold_obj,
+ &vec[ast::obj_field] fields,
+ &vec[@ast::method] methods,
+ &option::t[@ast::method] dtor)
+ -> ast::_obj) fold_obj,
// Env updates.
- (fn(&ENV e, &@ast.crate c) -> ENV) update_env_for_crate,
+ (fn(&ENV e, &@ast::crate c) -> ENV) update_env_for_crate,
(fn(&ENV e, &@item i) -> ENV) update_env_for_item,
(fn(&ENV e, &@native_item i) -> ENV) update_env_for_native_item,
(fn(&ENV e, &@view_item i) -> ENV) update_env_for_view_item,
//// Fold drivers.
fn fold_path[ENV](&ENV env, &ast_fold[ENV] fld, &path p) -> path {
- let vec[@ast.ty] tys_ = vec();
- for (@ast.ty t in p.node.types) {
- Vec.push[@ast.ty](tys_, fold_ty(env, fld, t));
+ let vec[@ast::ty] tys_ = vec();
+ for (@ast::ty t in p.node.types) {
+ _vec::push[@ast::ty](tys_, fold_ty(env, fld, t));
}
- let ast.path_ p_ = rec(idents=p.node.idents, types=tys_);
+ let ast::path_ p_ = rec(idents=p.node.idents, types=tys_);
ret fld.fold_path(env, p.span, p_);
}
}
alt (t.node) {
- case (ast.ty_nil) { ret fld.fold_ty_nil(env_, t.span); }
- case (ast.ty_bool) { ret fld.fold_ty_bool(env_, t.span); }
- case (ast.ty_int) { ret fld.fold_ty_int(env_, t.span); }
- case (ast.ty_uint) { ret fld.fold_ty_uint(env_, t.span); }
- case (ast.ty_float) { ret fld.fold_ty_float(env_, t.span); }
+ case (ast::ty_nil) { ret fld.fold_ty_nil(env_, t.span); }
+ case (ast::ty_bool) { ret fld.fold_ty_bool(env_, t.span); }
+ case (ast::ty_int) { ret fld.fold_ty_int(env_, t.span); }
+ case (ast::ty_uint) { ret fld.fold_ty_uint(env_, t.span); }
+ case (ast::ty_float) { ret fld.fold_ty_float(env_, t.span); }
- case (ast.ty_machine(?m)) {
+ case (ast::ty_machine(?m)) {
ret fld.fold_ty_machine(env_, t.span, m);
}
- case (ast.ty_char) { ret fld.fold_ty_char(env_, t.span); }
- case (ast.ty_str) { ret fld.fold_ty_str(env_, t.span); }
+ case (ast::ty_char) { ret fld.fold_ty_char(env_, t.span); }
+ case (ast::ty_str) { ret fld.fold_ty_str(env_, t.span); }
- case (ast.ty_box(?tm)) {
+ case (ast::ty_box(?tm)) {
auto ty_ = fold_ty(env, fld, tm.ty);
ret fld.fold_ty_box(env_, t.span, rec(ty=ty_, mut=tm.mut));
}
- case (ast.ty_vec(?tm)) {
+ case (ast::ty_vec(?tm)) {
auto ty_ = fold_ty(env, fld, tm.ty);
ret fld.fold_ty_vec(env_, t.span, rec(ty=ty_, mut=tm.mut));
}
- case (ast.ty_tup(?elts)) {
+ case (ast::ty_tup(?elts)) {
let vec[mt] elts_ = vec();
for (mt elt in elts) {
auto ty_ = fold_ty(env, fld, elt.ty);
- Vec.push[mt](elts_, rec(ty=ty_, mut=elt.mut));
+ _vec::push[mt](elts_, rec(ty=ty_, mut=elt.mut));
}
ret fld.fold_ty_tup(env_, t.span, elts_);
}
- case (ast.ty_rec(?flds)) {
- let vec[ast.ty_field] flds_ = vec();
- for (ast.ty_field f in flds) {
+ case (ast::ty_rec(?flds)) {
+ let vec[ast::ty_field] flds_ = vec();
+ for (ast::ty_field f in flds) {
auto ty_ = fold_ty(env, fld, f.mt.ty);
- Vec.push[ast.ty_field]
+ _vec::push[ast::ty_field]
(flds_, rec(mt=rec(ty=ty_, mut=f.mt.mut) with f));
}
ret fld.fold_ty_rec(env_, t.span, flds_);
}
- case (ast.ty_obj(?meths)) {
- let vec[ast.ty_method] meths_ = vec();
- for (ast.ty_method m in meths) {
+ case (ast::ty_obj(?meths)) {
+ let vec[ast::ty_method] meths_ = vec();
+ for (ast::ty_method m in meths) {
auto tfn = fold_ty_fn(env_, fld, t.span, m.proto,
m.inputs, m.output);
alt (tfn.node) {
- case (ast.ty_fn(?p, ?ins, ?out)) {
- Vec.push[ast.ty_method]
+ case (ast::ty_fn(?p, ?ins, ?out)) {
+ _vec::push[ast::ty_method]
(meths_, rec(proto=p, inputs=ins,
output=out with m));
}
ret fld.fold_ty_obj(env_, t.span, meths_);
}
- case (ast.ty_path(?pth, ?ann)) {
+ case (ast::ty_path(?pth, ?ann)) {
auto pth_ = fold_path(env, fld, pth);
ret fld.fold_ty_path(env_, t.span, pth_, ann);
}
- case (ast.ty_fn(?proto, ?inputs, ?output)) {
+ case (ast::ty_fn(?proto, ?inputs, ?output)) {
ret fold_ty_fn(env_, fld, t.span, proto, inputs, output);
}
- case (ast.ty_chan(?ty)) {
+ case (ast::ty_chan(?ty)) {
auto ty_ = fold_ty(env, fld, ty);
ret fld.fold_ty_chan(env_, t.span, ty_);
}
- case (ast.ty_port(?ty)) {
+ case (ast::ty_port(?ty)) {
auto ty_ = fold_ty(env, fld, ty);
ret fld.fold_ty_port(env_, t.span, ty_);
}
}
fn fold_ty_fn[ENV](&ENV env, &ast_fold[ENV] fld, &span sp,
- ast.proto proto,
- &vec[rec(ast.mode mode, @ty ty)] inputs,
+ ast::proto proto,
+ &vec[rec(ast::mode mode, @ty ty)] inputs,
&@ty output) -> @ty {
auto output_ = fold_ty(env, fld, output);
- let vec[rec(ast.mode mode, @ty ty)] inputs_ = vec();
- for (rec(ast.mode mode, @ty ty) input in inputs) {
+ let vec[rec(ast::mode mode, @ty ty)] inputs_ = vec();
+ for (rec(ast::mode mode, @ty ty) input in inputs) {
auto ty_ = fold_ty(env, fld, input.ty);
auto input_ = rec(ty=ty_ with input);
inputs_ += vec(input_);
}
alt (d.node) {
- case (ast.decl_local(?local)) {
- auto ty_ = none[@ast.ty];
- auto init_ = none[ast.initializer];
+ case (ast::decl_local(?local)) {
+ auto ty_ = none[@ast::ty];
+ auto init_ = none[ast::initializer];
alt (local.ty) {
- case (some[@ast.ty](?t)) {
- ty_ = some[@ast.ty](fold_ty(env, fld, t));
+ case (some[@ast::ty](?t)) {
+ ty_ = some[@ast::ty](fold_ty(env, fld, t));
}
case (_) { /* fall through */ }
}
alt (local.init) {
- case (some[ast.initializer](?init)) {
+ case (some[ast::initializer](?init)) {
auto e = fold_expr(env, fld, init.expr);
- init_ = some[ast.initializer](rec(expr = e with init));
+ init_ = some[ast::initializer](rec(expr = e with init));
}
case (_) { /* fall through */ }
}
auto ann_ = fld.fold_ann(env_, local.ann);
- let @ast.local local_ =
+ let @ast::local local_ =
@rec(ty=ty_, init=init_, ann=ann_ with *local);
ret fld.fold_decl_local(env_, d.span, local_);
}
- case (ast.decl_item(?item)) {
+ case (ast::decl_item(?item)) {
auto item_ = fold_item(env_, fld, item);
ret fld.fold_decl_item(env_, d.span, item_);
}
fail;
}
-fn fold_pat[ENV](&ENV env, &ast_fold[ENV] fld, &@ast.pat p) -> @ast.pat {
+fn fold_pat[ENV](&ENV env, &ast_fold[ENV] fld, &@ast::pat p) -> @ast::pat {
let ENV env_ = fld.update_env_for_pat(env, p);
if (!fld.keep_going(env_)) {
}
alt (p.node) {
- case (ast.pat_wild(?t)) { ret fld.fold_pat_wild(env_, p.span, t); }
- case (ast.pat_lit(?lt, ?t)) {
+ case (ast::pat_wild(?t)) { ret fld.fold_pat_wild(env_, p.span, t); }
+ case (ast::pat_lit(?lt, ?t)) {
ret fld.fold_pat_lit(env_, p.span, lt, t);
}
- case (ast.pat_bind(?id, ?did, ?t)) {
+ case (ast::pat_bind(?id, ?did, ?t)) {
ret fld.fold_pat_bind(env_, p.span, id, did, t);
}
- case (ast.pat_tag(?path, ?pats, ?t)) {
+ case (ast::pat_tag(?path, ?pats, ?t)) {
auto ppath = fold_path(env, fld, path);
- let vec[@ast.pat] ppats = vec();
- for (@ast.pat pat in pats) {
+ let vec[@ast::pat] ppats = vec();
+ for (@ast::pat pat in pats) {
ppats += vec(fold_pat(env_, fld, pat));
}
&vec[@expr] es) -> vec[@expr] {
let vec[@expr] exprs = vec();
for (@expr e in es) {
- Vec.push[@expr](exprs, fold_expr(env, fld, e));
+ _vec::push[@expr](exprs, fold_expr(env, fld, e));
}
ret exprs;
}
-fn fold_tup_elt[ENV](&ENV env, &ast_fold[ENV] fld, &ast.elt e) -> ast.elt {
+fn fold_tup_elt[ENV](&ENV env, &ast_fold[ENV] fld, &ast::elt e) -> ast::elt {
ret rec(expr=fold_expr(env, fld, e.expr) with e);
}
-fn fold_rec_field[ENV](&ENV env, &ast_fold[ENV] fld, &ast.field f)
- -> ast.field {
+fn fold_rec_field[ENV](&ENV env, &ast_fold[ENV] fld, &ast::field f)
+ -> ast::field {
ret rec(expr=fold_expr(env, fld, f.expr) with f);
}
}
alt (e.node) {
- case (ast.expr_vec(?es, ?mut, ?t)) {
+ case (ast::expr_vec(?es, ?mut, ?t)) {
auto ees = fold_exprs(env_, fld, es);
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_vec(env_, e.span, ees, mut, t2);
}
- case (ast.expr_tup(?es, ?t)) {
- let vec[ast.elt] elts = vec();
- for (ast.elt e in es) {
+ case (ast::expr_tup(?es, ?t)) {
+ let vec[ast::elt] elts = vec();
+ for (ast::elt e in es) {
elts += vec(fold_tup_elt[ENV](env, fld, e));
}
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_tup(env_, e.span, elts, t2);
}
- case (ast.expr_rec(?fs, ?base, ?t)) {
- let vec[ast.field] fields = vec();
- let Option.t[@expr] b = none[@expr];
- for (ast.field f in fs) {
+ case (ast::expr_rec(?fs, ?base, ?t)) {
+ let vec[ast::field] fields = vec();
+ let option::t[@expr] b = none[@expr];
+ for (ast::field f in fs) {
fields += vec(fold_rec_field(env, fld, f));
}
alt (base) {
- case (none[@ast.expr]) { }
- case (some[@ast.expr](?eb)) {
+ case (none[@ast::expr]) { }
+ case (some[@ast::expr](?eb)) {
b = some[@expr](fold_expr(env_, fld, eb));
}
}
ret fld.fold_expr_rec(env_, e.span, fields, b, t2);
}
- case (ast.expr_call(?f, ?args, ?t)) {
+ case (ast::expr_call(?f, ?args, ?t)) {
auto ff = fold_expr(env_, fld, f);
auto aargs = fold_exprs(env_, fld, args);
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_call(env_, e.span, ff, aargs, t2);
}
- case (ast.expr_self_method(?ident, ?t)) {
+ case (ast::expr_self_method(?ident, ?t)) {
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_self_method(env_, e.span, ident, t2);
}
- case (ast.expr_bind(?f, ?args_opt, ?t)) {
+ case (ast::expr_bind(?f, ?args_opt, ?t)) {
auto ff = fold_expr(env_, fld, f);
- let vec[Option.t[@ast.expr]] aargs_opt = vec();
- for (Option.t[@ast.expr] t_opt in args_opt) {
+ let vec[option::t[@ast::expr]] aargs_opt = vec();
+ for (option::t[@ast::expr] t_opt in args_opt) {
alt (t_opt) {
- case (none[@ast.expr]) {
- aargs_opt += vec(none[@ast.expr]);
+ case (none[@ast::expr]) {
+ aargs_opt += vec(none[@ast::expr]);
}
- case (some[@ast.expr](?e)) {
+ case (some[@ast::expr](?e)) {
aargs_opt += vec(some(fold_expr(env_, fld, e)));
}
- case (none[@ast.expr]) { /* empty */ }
+ case (none[@ast::expr]) { /* empty */ }
}
}
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_bind(env_, e.span, ff, aargs_opt, t2);
}
- case (ast.expr_spawn(?dom, ?name, ?f, ?args, ?t)) {
+ case (ast::expr_spawn(?dom, ?name, ?f, ?args, ?t)) {
auto ff = fold_expr(env_, fld, f);
auto aargs = fold_exprs(env_, fld, args);
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_spawn(env_, e.span, dom, name, ff, aargs, t2);
}
- case (ast.expr_binary(?op, ?a, ?b, ?t)) {
+ case (ast::expr_binary(?op, ?a, ?b, ?t)) {
auto aa = fold_expr(env_, fld, a);
auto bb = fold_expr(env_, fld, b);
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_binary(env_, e.span, op, aa, bb, t2);
}
- case (ast.expr_unary(?op, ?a, ?t)) {
+ case (ast::expr_unary(?op, ?a, ?t)) {
auto aa = fold_expr(env_, fld, a);
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_unary(env_, e.span, op, aa, t2);
}
- case (ast.expr_lit(?lit, ?t)) {
+ case (ast::expr_lit(?lit, ?t)) {
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_lit(env_, e.span, lit, t2);
}
- case (ast.expr_cast(?e, ?t, ?at)) {
+ case (ast::expr_cast(?e, ?t, ?at)) {
auto ee = fold_expr(env_, fld, e);
auto tt = fold_ty(env, fld, t);
auto at2 = fld.fold_ann(env_, at);
ret fld.fold_expr_cast(env_, e.span, ee, tt, at2);
}
- case (ast.expr_if(?cnd, ?thn, ?els, ?t)) {
+ case (ast::expr_if(?cnd, ?thn, ?els, ?t)) {
auto ccnd = fold_expr(env_, fld, cnd);
auto tthn = fold_block(env_, fld, thn);
auto eels = none[@expr];
ret fld.fold_expr_if(env_, e.span, ccnd, tthn, eels, t2);
}
- case (ast.expr_for(?decl, ?seq, ?body, ?t)) {
+ case (ast::expr_for(?decl, ?seq, ?body, ?t)) {
auto ddecl = fold_decl(env_, fld, decl);
auto sseq = fold_expr(env_, fld, seq);
auto bbody = fold_block(env_, fld, body);
ret fld.fold_expr_for(env_, e.span, ddecl, sseq, bbody, t2);
}
- case (ast.expr_for_each(?decl, ?seq, ?body, ?t)) {
+ case (ast::expr_for_each(?decl, ?seq, ?body, ?t)) {
auto ddecl = fold_decl(env_, fld, decl);
auto sseq = fold_expr(env_, fld, seq);
auto bbody = fold_block(env_, fld, body);
ret fld.fold_expr_for_each(env_, e.span, ddecl, sseq, bbody, t2);
}
- case (ast.expr_while(?cnd, ?body, ?t)) {
+ case (ast::expr_while(?cnd, ?body, ?t)) {
auto ccnd = fold_expr(env_, fld, cnd);
auto bbody = fold_block(env_, fld, body);
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_while(env_, e.span, ccnd, bbody, t2);
}
- case (ast.expr_do_while(?body, ?cnd, ?t)) {
+ case (ast::expr_do_while(?body, ?cnd, ?t)) {
auto bbody = fold_block(env_, fld, body);
auto ccnd = fold_expr(env_, fld, cnd);
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_do_while(env_, e.span, bbody, ccnd, t2);
}
- case (ast.expr_alt(?expr, ?arms, ?t)) {
+ case (ast::expr_alt(?expr, ?arms, ?t)) {
auto eexpr = fold_expr(env_, fld, expr);
- let vec[ast.arm] aarms = vec();
- for (ast.arm a in arms) {
+ let vec[ast::arm] aarms = vec();
+ for (ast::arm a in arms) {
aarms += vec(fold_arm(env_, fld, a));
}
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_alt(env_, e.span, eexpr, aarms, t2);
}
- case (ast.expr_block(?b, ?t)) {
+ case (ast::expr_block(?b, ?t)) {
auto bb = fold_block(env_, fld, b);
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_block(env_, e.span, bb, t2);
}
- case (ast.expr_assign(?lhs, ?rhs, ?t)) {
+ case (ast::expr_assign(?lhs, ?rhs, ?t)) {
auto llhs = fold_expr(env_, fld, lhs);
auto rrhs = fold_expr(env_, fld, rhs);
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_assign(env_, e.span, llhs, rrhs, t2);
}
- case (ast.expr_assign_op(?op, ?lhs, ?rhs, ?t)) {
+ case (ast::expr_assign_op(?op, ?lhs, ?rhs, ?t)) {
auto llhs = fold_expr(env_, fld, lhs);
auto rrhs = fold_expr(env_, fld, rhs);
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_assign_op(env_, e.span, op, llhs, rrhs, t2);
}
- case (ast.expr_send(?lhs, ?rhs, ?t)) {
+ case (ast::expr_send(?lhs, ?rhs, ?t)) {
auto llhs = fold_expr(env_, fld, lhs);
auto rrhs = fold_expr(env_, fld, rhs);
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_send(env_, e.span, llhs, rrhs, t2);
}
- case (ast.expr_recv(?lhs, ?rhs, ?t)) {
+ case (ast::expr_recv(?lhs, ?rhs, ?t)) {
auto llhs = fold_expr(env_, fld, lhs);
auto rrhs = fold_expr(env_, fld, rhs);
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_recv(env_, e.span, llhs, rrhs, t2);
}
- case (ast.expr_field(?e, ?i, ?t)) {
+ case (ast::expr_field(?e, ?i, ?t)) {
auto ee = fold_expr(env_, fld, e);
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_field(env_, e.span, ee, i, t2);
}
- case (ast.expr_index(?e, ?ix, ?t)) {
+ case (ast::expr_index(?e, ?ix, ?t)) {
auto ee = fold_expr(env_, fld, e);
auto iix = fold_expr(env_, fld, ix);
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_index(env_, e.span, ee, iix, t2);
}
- case (ast.expr_path(?p, ?t)) {
+ case (ast::expr_path(?p, ?t)) {
auto p_ = fold_path(env_, fld, p);
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_path(env_, e.span, p_, t2);
}
- case (ast.expr_ext(?p, ?args, ?body, ?expanded, ?t)) {
+ case (ast::expr_ext(?p, ?args, ?body, ?expanded, ?t)) {
// Only fold the expanded expression, not the
// expressions involved in syntax extension
auto exp = fold_expr(env_, fld, expanded);
exp, t2);
}
- case (ast.expr_fail(?t)) {
+ case (ast::expr_fail(?t)) {
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_fail(env_, e.span, t2);
}
- case (ast.expr_break(?t)) {
+ case (ast::expr_break(?t)) {
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_break(env_, e.span, t2);
}
- case (ast.expr_cont(?t)) {
+ case (ast::expr_cont(?t)) {
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_cont(env_, e.span, t2);
}
- case (ast.expr_ret(?oe, ?t)) {
+ case (ast::expr_ret(?oe, ?t)) {
auto oee = none[@expr];
alt (oe) {
case (some[@expr](?x)) {
ret fld.fold_expr_ret(env_, e.span, oee, t2);
}
- case (ast.expr_put(?oe, ?t)) {
+ case (ast::expr_put(?oe, ?t)) {
auto oee = none[@expr];
alt (oe) {
case (some[@expr](?x)) {
ret fld.fold_expr_put(env_, e.span, oee, t2);
}
- case (ast.expr_be(?x, ?t)) {
+ case (ast::expr_be(?x, ?t)) {
auto ee = fold_expr(env_, fld, x);
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_be(env_, e.span, ee, t2);
}
- case (ast.expr_log(?l, ?x, ?t)) {
+ case (ast::expr_log(?l, ?x, ?t)) {
auto ee = fold_expr(env_, fld, x);
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_log(env_, e.span, l, ee, t2);
}
- case (ast.expr_check(?x, ?t)) {
+ case (ast::expr_check(?x, ?t)) {
auto ee = fold_expr(env_, fld, x);
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_check(env_, e.span, ee, t2);
}
- case (ast.expr_assert(?x, ?t)) {
+ case (ast::expr_assert(?x, ?t)) {
auto ee = fold_expr(env_, fld, x);
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_assert(env_, e.span, ee, t2);
}
- case (ast.expr_port(?t)) {
+ case (ast::expr_port(?t)) {
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_port(env_, e.span, t2);
}
- case (ast.expr_chan(?x, ?t)) {
+ case (ast::expr_chan(?x, ?t)) {
auto ee = fold_expr(env_, fld, x);
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_chan(env_, e.span, ee, t2);
}
alt (s.node) {
- case (ast.stmt_decl(?d, ?a)) {
+ case (ast::stmt_decl(?d, ?a)) {
auto dd = fold_decl(env_, fld, d);
auto aa = fld.fold_ann(env_, a);
ret fld.fold_stmt_decl(env_, s.span, dd, aa);
}
- case (ast.stmt_expr(?e, ?a)) {
+ case (ast::stmt_expr(?e, ?a)) {
auto ee = fold_expr(env_, fld, e);
auto aa = fld.fold_ann(env_, a);
ret fld.fold_stmt_expr(env_, s.span, ee, aa);
ret blk;
}
- let vec[@ast.stmt] stmts = vec();
- for (@ast.stmt s in blk.node.stmts) {
+ let vec[@ast::stmt] stmts = vec();
+ for (@ast::stmt s in blk.node.stmts) {
auto new_stmt = fold_stmt[ENV](env_, fld, s);
- Vec.push[@ast.stmt](stmts, new_stmt);
+ _vec::push[@ast::stmt](stmts, new_stmt);
}
- auto expr = none[@ast.expr];
+ auto expr = none[@ast::expr];
alt (blk.node.expr) {
- case (some[@ast.expr](?e)) {
- expr = some[@ast.expr](fold_expr[ENV](env_, fld, e));
+ case (some[@ast::expr](?e)) {
+ expr = some[@ast::expr](fold_expr[ENV](env_, fld, e));
}
- case (none[@ast.expr]) {
+ case (none[@ast::expr]) {
// empty
}
}
}
fn fold_fn_decl[ENV](&ENV env, &ast_fold[ENV] fld,
- &ast.fn_decl decl) -> ast.fn_decl {
- let vec[ast.arg] inputs = vec();
- for (ast.arg a in decl.inputs) {
+ &ast::fn_decl decl) -> ast::fn_decl {
+ let vec[ast::arg] inputs = vec();
+ for (ast::arg a in decl.inputs) {
inputs += vec(fold_arg(env, fld, a));
}
auto output = fold_ty[ENV](env, fld, decl.output);
ret fld.fold_fn_decl(env, inputs, output, decl.purity);
}
-fn fold_fn[ENV](&ENV env, &ast_fold[ENV] fld, &ast._fn f) -> ast._fn {
+fn fold_fn[ENV](&ENV env, &ast_fold[ENV] fld, &ast::_fn f) -> ast::_fn {
auto decl = fold_fn_decl(env, fld, f.decl);
auto body = fold_block[ENV](env, fld, f.body);
fn fold_obj_field[ENV](&ENV env, &ast_fold[ENV] fld,
- &ast.obj_field f) -> ast.obj_field {
+ &ast::obj_field f) -> ast::obj_field {
auto ty = fold_ty(env, fld, f.ty);
ret rec(ty=ty with f);
}
fn fold_method[ENV](&ENV env, &ast_fold[ENV] fld,
- &@ast.method m) -> @ast.method {
+ &@ast::method m) -> @ast::method {
auto meth = fold_fn(env, fld, m.node.meth);
ret @rec(node=rec(meth=meth with m.node) with *m);
}
-fn fold_obj[ENV](&ENV env, &ast_fold[ENV] fld, &ast._obj ob) -> ast._obj {
+fn fold_obj[ENV](&ENV env, &ast_fold[ENV] fld, &ast::_obj ob) -> ast::_obj {
- let vec[ast.obj_field] fields = vec();
- let vec[@ast.method] meths = vec();
- for (ast.obj_field f in ob.fields) {
+ let vec[ast::obj_field] fields = vec();
+ let vec[@ast::method] meths = vec();
+ for (ast::obj_field f in ob.fields) {
fields += vec(fold_obj_field(env, fld, f));
}
- let Option.t[@ast.method] dtor = none[@ast.method];
+ let option::t[@ast::method] dtor = none[@ast::method];
alt (ob.dtor) {
- case (none[@ast.method]) { }
- case (some[@ast.method](?m)) {
- dtor = some[@ast.method](fold_method[ENV](env, fld, m));
+ case (none[@ast::method]) { }
+ case (some[@ast::method](?m)) {
+ dtor = some[@ast::method](fold_method[ENV](env, fld, m));
}
}
- let vec[ast.ty_param] tp = vec();
- for (@ast.method m in ob.methods) {
- // Fake-up an ast.item for this method.
+ let vec[ast::ty_param] tp = vec();
+ for (@ast::method m in ob.methods) {
+ // Fake-up an ast::item for this method.
// FIXME: this is kinda awful. Maybe we should reformulate
// the way we store methods in the AST?
- let @ast.item i = @rec(node=ast.item_fn(m.node.ident,
+ let @ast::item i = @rec(node=ast::item_fn(m.node.ident,
m.node.meth,
tp,
m.node.id,
m.node.ann),
span=m.span);
let ENV _env = fld.update_env_for_item(env, i);
- Vec.push[@ast.method](meths, fold_method(_env, fld, m));
+ _vec::push[@ast::method](meths, fold_method(_env, fld, m));
}
ret fld.fold_obj(env, fields, meths, dtor);
}
}
alt (vi.node) {
- case (ast.view_item_use(?ident, ?meta_items, ?def_id, ?cnum)) {
+ case (ast::view_item_use(?ident, ?meta_items, ?def_id, ?cnum)) {
ret fld.fold_view_item_use(env_, vi.span, ident, meta_items,
def_id, cnum);
}
- case (ast.view_item_import(?def_ident, ?idents, ?def_id)) {
+ case (ast::view_item_import(?def_ident, ?idents, ?def_id)) {
ret fld.fold_view_item_import(env_, vi.span, def_ident, idents,
def_id);
}
- case (ast.view_item_export(?def_ident)) {
+ case (ast::view_item_export(?def_ident)) {
ret fld.fold_view_item_export(env_, vi.span, def_ident);
}
}
alt (i.node) {
- case (ast.item_const(?ident, ?t, ?e, ?id, ?ann)) {
- let @ast.ty t_ = fold_ty[ENV](env_, fld, t);
- let @ast.expr e_ = fold_expr(env_, fld, e);
+ case (ast::item_const(?ident, ?t, ?e, ?id, ?ann)) {
+ let @ast::ty t_ = fold_ty[ENV](env_, fld, t);
+ let @ast::expr e_ = fold_expr(env_, fld, e);
ret fld.fold_item_const(env_, i.span, ident, t_, e_, id, ann);
}
- case (ast.item_fn(?ident, ?ff, ?tps, ?id, ?ann)) {
- let ast._fn ff_ = fold_fn[ENV](env_, fld, ff);
+ case (ast::item_fn(?ident, ?ff, ?tps, ?id, ?ann)) {
+ let ast::_fn ff_ = fold_fn[ENV](env_, fld, ff);
ret fld.fold_item_fn(env_, i.span, ident, ff_, tps, id, ann);
}
- case (ast.item_mod(?ident, ?mm, ?id)) {
- let ast._mod mm_ = fold_mod[ENV](env_, fld, mm);
+ case (ast::item_mod(?ident, ?mm, ?id)) {
+ let ast::_mod mm_ = fold_mod[ENV](env_, fld, mm);
ret fld.fold_item_mod(env_, i.span, ident, mm_, id);
}
- case (ast.item_native_mod(?ident, ?mm, ?id)) {
- let ast.native_mod mm_ = fold_native_mod[ENV](env_, fld, mm);
+ case (ast::item_native_mod(?ident, ?mm, ?id)) {
+ let ast::native_mod mm_ = fold_native_mod[ENV](env_, fld, mm);
ret fld.fold_item_native_mod(env_, i.span, ident, mm_, id);
}
- case (ast.item_ty(?ident, ?ty, ?params, ?id, ?ann)) {
- let @ast.ty ty_ = fold_ty[ENV](env_, fld, ty);
+ case (ast::item_ty(?ident, ?ty, ?params, ?id, ?ann)) {
+ let @ast::ty ty_ = fold_ty[ENV](env_, fld, ty);
ret fld.fold_item_ty(env_, i.span, ident, ty_, params, id, ann);
}
- case (ast.item_tag(?ident, ?variants, ?ty_params, ?id, ?ann)) {
- let vec[ast.variant] new_variants = vec();
- for (ast.variant v in variants) {
- let vec[ast.variant_arg] new_args = vec();
- for (ast.variant_arg va in v.node.args) {
+ case (ast::item_tag(?ident, ?variants, ?ty_params, ?id, ?ann)) {
+ let vec[ast::variant] new_variants = vec();
+ for (ast::variant v in variants) {
+ let vec[ast::variant_arg] new_args = vec();
+ for (ast::variant_arg va in v.node.args) {
auto new_ty = fold_ty[ENV](env_, fld, va.ty);
new_args += vec(rec(ty=new_ty, id=va.id));
}
auto new_v = rec(name=v.node.name, args=new_args,
id=v.node.id, ann=v.node.ann);
- new_variants += vec(respan[ast.variant_](v.span, new_v));
+ new_variants += vec(respan[ast::variant_](v.span, new_v));
}
ret fld.fold_item_tag(env_, i.span, ident, new_variants,
ty_params, id, ann);
}
- case (ast.item_obj(?ident, ?ob, ?tps, ?odid, ?ann)) {
- let ast._obj ob_ = fold_obj[ENV](env_, fld, ob);
+ case (ast::item_obj(?ident, ?ob, ?tps, ?odid, ?ann)) {
+ let ast::_obj ob_ = fold_obj[ENV](env_, fld, ob);
ret fld.fold_item_obj(env_, i.span, ident, ob_, tps, odid, ann);
}
fail;
}
-fn fold_mod[ENV](&ENV e, &ast_fold[ENV] fld, &ast._mod m) -> ast._mod {
+fn fold_mod[ENV](&ENV e, &ast_fold[ENV] fld, &ast::_mod m) -> ast::_mod {
let vec[@view_item] view_items = vec();
let vec[@item] items = vec();
for (@view_item vi in m.view_items) {
auto new_vi = fold_view_item[ENV](e, fld, vi);
- Vec.push[@view_item](view_items, new_vi);
+ _vec::push[@view_item](view_items, new_vi);
}
for (@item i in m.items) {
auto new_item = fold_item[ENV](e, fld, i);
- Vec.push[@item](items, new_item);
+ _vec::push[@item](items, new_item);
}
ret fld.fold_mod(e, rec(view_items=view_items, items=items));
ret i;
}
alt (i.node) {
- case (ast.native_item_ty(?ident, ?id)) {
+ case (ast::native_item_ty(?ident, ?id)) {
ret fld.fold_native_item_ty(env_, i.span, ident, id);
}
- case (ast.native_item_fn(?ident, ?lname, ?fn_decl,
+ case (ast::native_item_fn(?ident, ?lname, ?fn_decl,
?ty_params, ?id, ?ann)) {
auto d = fold_fn_decl[ENV](env_, fld, fn_decl);
ret fld.fold_native_item_fn(env_, i.span, ident, lname, d,
}
fn fold_native_mod[ENV](&ENV e, &ast_fold[ENV] fld,
- &ast.native_mod m) -> ast.native_mod {
+ &ast::native_mod m) -> ast::native_mod {
let vec[@view_item] view_items = vec();
let vec[@native_item] items = vec();
for (@view_item vi in m.view_items) {
auto new_vi = fold_view_item[ENV](e, fld, vi);
- Vec.push[@view_item](view_items, new_vi);
+ _vec::push[@view_item](view_items, new_vi);
}
for (@native_item i in m.items) {
auto new_item = fold_native_item[ENV](e, fld, i);
- Vec.push[@native_item](items, new_item);
+ _vec::push[@native_item](items, new_item);
}
ret fld.fold_native_mod(e, rec(native_name=m.native_name,
}
fn fold_crate[ENV](&ENV env, &ast_fold[ENV] fld,
- &@ast.crate c) -> @ast.crate {
+ &@ast::crate c) -> @ast::crate {
// FIXME: possibly fold the directives so you process any expressions
- // within them? Not clear. After front/eval.rs, nothing else should look
+ // within them? Not clear. After front/eval::rs, nothing else should look
// at crate directives.
let ENV env_ = fld.update_env_for_crate(env, c);
- let ast._mod m = fold_mod[ENV](env_, fld, c.node.module);
+ let ast::_mod m = fold_mod[ENV](env_, fld, c.node.module);
ret fld.fold_crate(env_, c.span, c.node.directives, m);
}
// Path identity.
-fn identity_fold_path[ENV](&ENV env, &span sp, &ast.path_ p) -> path {
+fn identity_fold_path[ENV](&ENV env, &span sp, &ast::path_ p) -> path {
ret respan(sp, p);
}
// Type identities.
fn identity_fold_ty_nil[ENV](&ENV env, &span sp) -> @ty {
- ret @respan(sp, ast.ty_nil);
+ ret @respan(sp, ast::ty_nil);
}
fn identity_fold_ty_bool[ENV](&ENV env, &span sp) -> @ty {
- ret @respan(sp, ast.ty_bool);
+ ret @respan(sp, ast::ty_bool);
}
fn identity_fold_ty_int[ENV](&ENV env, &span sp) -> @ty {
- ret @respan(sp, ast.ty_int);
+ ret @respan(sp, ast::ty_int);
}
fn identity_fold_ty_uint[ENV](&ENV env, &span sp) -> @ty {
- ret @respan(sp, ast.ty_uint);
+ ret @respan(sp, ast::ty_uint);
}
fn identity_fold_ty_float[ENV](&ENV env, &span sp) -> @ty {
- ret @respan(sp, ast.ty_float);
+ ret @respan(sp, ast::ty_float);
}
fn identity_fold_ty_machine[ENV](&ENV env, &span sp,
ty_mach tm) -> @ty {
- ret @respan(sp, ast.ty_machine(tm));
+ ret @respan(sp, ast::ty_machine(tm));
}
fn identity_fold_ty_char[ENV](&ENV env, &span sp) -> @ty {
- ret @respan(sp, ast.ty_char);
+ ret @respan(sp, ast::ty_char);
}
fn identity_fold_ty_str[ENV](&ENV env, &span sp) -> @ty {
- ret @respan(sp, ast.ty_str);
+ ret @respan(sp, ast::ty_str);
}
fn identity_fold_ty_box[ENV](&ENV env, &span sp, &mt tm) -> @ty {
- ret @respan(sp, ast.ty_box(tm));
+ ret @respan(sp, ast::ty_box(tm));
}
fn identity_fold_ty_vec[ENV](&ENV env, &span sp, &mt tm) -> @ty {
- ret @respan(sp, ast.ty_vec(tm));
+ ret @respan(sp, ast::ty_vec(tm));
}
fn identity_fold_ty_tup[ENV](&ENV env, &span sp,
&vec[mt] elts) -> @ty {
- ret @respan(sp, ast.ty_tup(elts));
+ ret @respan(sp, ast::ty_tup(elts));
}
fn identity_fold_ty_rec[ENV](&ENV env, &span sp,
- &vec[ast.ty_field] elts) -> @ty {
- ret @respan(sp, ast.ty_rec(elts));
+ &vec[ast::ty_field] elts) -> @ty {
+ ret @respan(sp, ast::ty_rec(elts));
}
fn identity_fold_ty_obj[ENV](&ENV env, &span sp,
- &vec[ast.ty_method] meths) -> @ty {
- ret @respan(sp, ast.ty_obj(meths));
+ &vec[ast::ty_method] meths) -> @ty {
+ ret @respan(sp, ast::ty_obj(meths));
}
fn identity_fold_ty_fn[ENV](&ENV env, &span sp,
- ast.proto proto,
- &vec[rec(ast.mode mode, @ty ty)] inputs,
+ ast::proto proto,
+ &vec[rec(ast::mode mode, @ty ty)] inputs,
&@ty output) -> @ty {
- ret @respan(sp, ast.ty_fn(proto, inputs, output));
+ ret @respan(sp, ast::ty_fn(proto, inputs, output));
}
-fn identity_fold_ty_path[ENV](&ENV env, &span sp, &ast.path p,
+fn identity_fold_ty_path[ENV](&ENV env, &span sp, &ast::path p,
&ann a) -> @ty {
- ret @respan(sp, ast.ty_path(p, a));
+ ret @respan(sp, ast::ty_path(p, a));
}
fn identity_fold_ty_chan[ENV](&ENV env, &span sp, &@ty t) -> @ty {
- ret @respan(sp, ast.ty_chan(t));
+ ret @respan(sp, ast::ty_chan(t));
}
fn identity_fold_ty_port[ENV](&ENV env, &span sp, &@ty t) -> @ty {
- ret @respan(sp, ast.ty_port(t));
+ ret @respan(sp, ast::ty_port(t));
}
// Expr identities.
fn identity_fold_expr_vec[ENV](&ENV env, &span sp, &vec[@expr] es,
- ast.mutability mut, &ann a) -> @expr {
- ret @respan(sp, ast.expr_vec(es, mut, a));
+ ast::mutability mut, &ann a) -> @expr {
+ ret @respan(sp, ast::expr_vec(es, mut, a));
}
fn identity_fold_expr_tup[ENV](&ENV env, &span sp,
- &vec[ast.elt] es, &ann a) -> @expr {
- ret @respan(sp, ast.expr_tup(es, a));
+ &vec[ast::elt] es, &ann a) -> @expr {
+ ret @respan(sp, ast::expr_tup(es, a));
}
fn identity_fold_expr_rec[ENV](&ENV env, &span sp,
- &vec[ast.field] fields,
- &Option.t[@expr] base, &ann a) -> @expr {
- ret @respan(sp, ast.expr_rec(fields, base, a));
+ &vec[ast::field] fields,
+ &option::t[@expr] base, &ann a) -> @expr {
+ ret @respan(sp, ast::expr_rec(fields, base, a));
}
fn identity_fold_expr_call[ENV](&ENV env, &span sp, &@expr f,
&vec[@expr] args, &ann a) -> @expr {
- ret @respan(sp, ast.expr_call(f, args, a));
+ ret @respan(sp, ast::expr_call(f, args, a));
}
fn identity_fold_expr_self_method[ENV](&ENV env, &span sp, &ident id,
&ann a) -> @expr {
- ret @respan(sp, ast.expr_self_method(id, a));
+ ret @respan(sp, ast::expr_self_method(id, a));
}
fn identity_fold_expr_bind[ENV](&ENV env, &span sp, &@expr f,
- &vec[Option.t[@expr]] args_opt, &ann a)
+ &vec[option::t[@expr]] args_opt, &ann a)
-> @expr {
- ret @respan(sp, ast.expr_bind(f, args_opt, a));
+ ret @respan(sp, ast::expr_bind(f, args_opt, a));
}
fn identity_fold_expr_spawn[ENV](&ENV env, &span sp,
- ast.spawn_dom dom, &Option.t[str] name,
+ ast::spawn_dom dom, &option::t[str] name,
&@expr f, &vec[@expr] args,
&ann a) -> @expr {
- ret @respan(sp, ast.expr_spawn(dom, name, f, args, a));
+ ret @respan(sp, ast::expr_spawn(dom, name, f, args, a));
}
-fn identity_fold_expr_binary[ENV](&ENV env, &span sp, ast.binop b,
+fn identity_fold_expr_binary[ENV](&ENV env, &span sp, ast::binop b,
&@expr lhs, &@expr rhs,
&ann a) -> @expr {
- ret @respan(sp, ast.expr_binary(b, lhs, rhs, a));
+ ret @respan(sp, ast::expr_binary(b, lhs, rhs, a));
}
fn identity_fold_expr_unary[ENV](&ENV env, &span sp,
- ast.unop u, &@expr e, &ann a)
+ ast::unop u, &@expr e, &ann a)
-> @expr {
- ret @respan(sp, ast.expr_unary(u, e, a));
+ ret @respan(sp, ast::expr_unary(u, e, a));
}
-fn identity_fold_expr_lit[ENV](&ENV env, &span sp, &@ast.lit lit,
+fn identity_fold_expr_lit[ENV](&ENV env, &span sp, &@ast::lit lit,
&ann a) -> @expr {
- ret @respan(sp, ast.expr_lit(lit, a));
+ ret @respan(sp, ast::expr_lit(lit, a));
}
-fn identity_fold_expr_cast[ENV](&ENV env, &span sp, &@ast.expr e,
- &@ast.ty t, &ann a) -> @expr {
- ret @respan(sp, ast.expr_cast(e, t, a));
+fn identity_fold_expr_cast[ENV](&ENV env, &span sp, &@ast::expr e,
+ &@ast::ty t, &ann a) -> @expr {
+ ret @respan(sp, ast::expr_cast(e, t, a));
}
fn identity_fold_expr_if[ENV](&ENV env, &span sp,
&@expr cond, &block thn,
- &Option.t[@expr] els, &ann a) -> @expr {
- ret @respan(sp, ast.expr_if(cond, thn, els, a));
+ &option::t[@expr] els, &ann a) -> @expr {
+ ret @respan(sp, ast::expr_if(cond, thn, els, a));
}
fn identity_fold_expr_for[ENV](&ENV env, &span sp,
&@decl d, &@expr seq,
&block body, &ann a) -> @expr {
- ret @respan(sp, ast.expr_for(d, seq, body, a));
+ ret @respan(sp, ast::expr_for(d, seq, body, a));
}
fn identity_fold_expr_for_each[ENV](&ENV env, &span sp,
&@decl d, &@expr seq,
&block body, &ann a) -> @expr {
- ret @respan(sp, ast.expr_for_each(d, seq, body, a));
+ ret @respan(sp, ast::expr_for_each(d, seq, body, a));
}
fn identity_fold_expr_while[ENV](&ENV env, &span sp,
&@expr cond, &block body, &ann a) -> @expr {
- ret @respan(sp, ast.expr_while(cond, body, a));
+ ret @respan(sp, ast::expr_while(cond, body, a));
}
fn identity_fold_expr_do_while[ENV](&ENV env, &span sp,
&block body, &@expr cond,
&ann a) -> @expr {
- ret @respan(sp, ast.expr_do_while(body, cond, a));
+ ret @respan(sp, ast::expr_do_while(body, cond, a));
}
fn identity_fold_expr_alt[ENV](&ENV env, &span sp,
&@expr e, &vec[arm] arms,
&ann a) -> @expr {
- ret @respan(sp, ast.expr_alt(e, arms, a));
+ ret @respan(sp, ast::expr_alt(e, arms, a));
}
fn identity_fold_expr_block[ENV](&ENV env, &span sp, &block blk,
&ann a) -> @expr {
- ret @respan(sp, ast.expr_block(blk, a));
+ ret @respan(sp, ast::expr_block(blk, a));
}
fn identity_fold_expr_assign[ENV](&ENV env, &span sp,
&@expr lhs, &@expr rhs, &ann a)
-> @expr {
- ret @respan(sp, ast.expr_assign(lhs, rhs, a));
+ ret @respan(sp, ast::expr_assign(lhs, rhs, a));
}
-fn identity_fold_expr_assign_op[ENV](&ENV env, &span sp, ast.binop op,
+fn identity_fold_expr_assign_op[ENV](&ENV env, &span sp, ast::binop op,
&@expr lhs, &@expr rhs, &ann a)
-> @expr {
- ret @respan(sp, ast.expr_assign_op(op, lhs, rhs, a));
+ ret @respan(sp, ast::expr_assign_op(op, lhs, rhs, a));
}
fn identity_fold_expr_send[ENV](&ENV e, &span sp,
&@expr lhs, &@expr rhs, &ann a) -> @expr {
- ret @respan(sp, ast.expr_send(lhs, rhs, a));
+ ret @respan(sp, ast::expr_send(lhs, rhs, a));
}
fn identity_fold_expr_recv[ENV](&ENV e, &span sp,
&@expr lhs, &@expr rhs, &ann a) -> @expr {
- ret @respan(sp, ast.expr_recv(lhs, rhs, a));
+ ret @respan(sp, ast::expr_recv(lhs, rhs, a));
}
fn identity_fold_expr_field[ENV](&ENV env, &span sp,
&@expr e, &ident i, &ann a) -> @expr {
- ret @respan(sp, ast.expr_field(e, i, a));
+ ret @respan(sp, ast::expr_field(e, i, a));
}
fn identity_fold_expr_index[ENV](&ENV env, &span sp,
&@expr e, &@expr ix, &ann a) -> @expr {
- ret @respan(sp, ast.expr_index(e, ix, a));
+ ret @respan(sp, ast::expr_index(e, ix, a));
}
fn identity_fold_expr_path[ENV](&ENV env, &span sp,
&path p, &ann a) -> @expr {
- ret @respan(sp, ast.expr_path(p, a));
+ ret @respan(sp, ast::expr_path(p, a));
}
fn identity_fold_expr_ext[ENV](&ENV env, &span sp,
&path p, &vec[@expr] args,
- &Option.t[str] body,
+ &option::t[str] body,
&@expr expanded,
&ann a) -> @expr {
- ret @respan(sp, ast.expr_ext(p, args, body, expanded, a));
+ ret @respan(sp, ast::expr_ext(p, args, body, expanded, a));
}
fn identity_fold_expr_fail[ENV](&ENV env, &span sp, &ann a) -> @expr {
- ret @respan(sp, ast.expr_fail(a));
+ ret @respan(sp, ast::expr_fail(a));
}
fn identity_fold_expr_break[ENV](&ENV env, &span sp, &ann a) -> @expr {
- ret @respan(sp, ast.expr_break(a));
+ ret @respan(sp, ast::expr_break(a));
}
fn identity_fold_expr_cont[ENV](&ENV env, &span sp, &ann a) -> @expr {
- ret @respan(sp, ast.expr_cont(a));
+ ret @respan(sp, ast::expr_cont(a));
}
fn identity_fold_expr_ret[ENV](&ENV env, &span sp,
- &Option.t[@expr] rv, &ann a) -> @expr {
- ret @respan(sp, ast.expr_ret(rv, a));
+ &option::t[@expr] rv, &ann a) -> @expr {
+ ret @respan(sp, ast::expr_ret(rv, a));
}
fn identity_fold_expr_put[ENV](&ENV env, &span sp,
- &Option.t[@expr] rv, &ann a) -> @expr {
- ret @respan(sp, ast.expr_put(rv, a));
+ &option::t[@expr] rv, &ann a) -> @expr {
+ ret @respan(sp, ast::expr_put(rv, a));
}
fn identity_fold_expr_be[ENV](&ENV env, &span sp,
&@expr x, &ann a) -> @expr {
- ret @respan(sp, ast.expr_be(x, a));
+ ret @respan(sp, ast::expr_be(x, a));
}
fn identity_fold_expr_log[ENV](&ENV e, &span sp, int lvl, &@expr x,
&ann a) -> @expr {
- ret @respan(sp, ast.expr_log(lvl, x, a));
+ ret @respan(sp, ast::expr_log(lvl, x, a));
}
fn identity_fold_expr_check[ENV](&ENV e, &span sp, &@expr x, &ann a)
-> @expr {
- ret @respan(sp, ast.expr_check(x, a));
+ ret @respan(sp, ast::expr_check(x, a));
}
fn identity_fold_expr_assert[ENV](&ENV e, &span sp, &@expr x, &ann a)
-> @expr {
- ret @respan(sp, ast.expr_assert(x, a));
+ ret @respan(sp, ast::expr_assert(x, a));
}
fn identity_fold_expr_port[ENV](&ENV e, &span sp, &ann a) -> @expr {
- ret @respan(sp, ast.expr_port(a));
+ ret @respan(sp, ast::expr_port(a));
}
fn identity_fold_expr_chan[ENV](&ENV e, &span sp, &@expr x,
&ann a) -> @expr {
- ret @respan(sp, ast.expr_chan(x, a));
+ ret @respan(sp, ast::expr_chan(x, a));
}
// Decl identities.
fn identity_fold_decl_local[ENV](&ENV e, &span sp,
- &@ast.local local) -> @decl {
- ret @respan(sp, ast.decl_local(local));
+ &@ast::local local) -> @decl {
+ ret @respan(sp, ast::decl_local(local));
}
fn identity_fold_decl_item[ENV](&ENV e, &span sp, &@item i) -> @decl {
- ret @respan(sp, ast.decl_item(i));
+ ret @respan(sp, ast::decl_item(i));
}
// Pat identities.
fn identity_fold_pat_wild[ENV](&ENV e, &span sp, &ann a) -> @pat {
- ret @respan(sp, ast.pat_wild(a));
+ ret @respan(sp, ast::pat_wild(a));
}
fn identity_fold_pat_lit[ENV](&ENV e, &span sp,
- &@ast.lit lit, &ann a) -> @pat {
- ret @respan(sp, ast.pat_lit(lit, a));
+ &@ast::lit lit, &ann a) -> @pat {
+ ret @respan(sp, ast::pat_lit(lit, a));
}
fn identity_fold_pat_bind[ENV](&ENV e, &span sp, &ident i,
&def_id did, &ann a)
-> @pat {
- ret @respan(sp, ast.pat_bind(i, did, a));
+ ret @respan(sp, ast::pat_bind(i, did, a));
}
fn identity_fold_pat_tag[ENV](&ENV e, &span sp, &path p, &vec[@pat] args,
&ann a) -> @pat {
- ret @respan(sp, ast.pat_tag(p, args, a));
+ ret @respan(sp, ast::pat_tag(p, args, a));
}
fn identity_fold_stmt_decl[ENV](&ENV env, &span sp,
&@decl d, &ann a) -> @stmt {
- ret @respan(sp, ast.stmt_decl(d, a));
+ ret @respan(sp, ast::stmt_decl(d, a));
}
fn identity_fold_stmt_expr[ENV](&ENV e, &span sp,
&@expr x, &ann a) -> @stmt {
- ret @respan(sp, ast.stmt_expr(x, a));
+ ret @respan(sp, ast::stmt_expr(x, a));
}
fn identity_fold_item_const[ENV](&ENV e, &span sp, &ident i,
&@ty t, &@expr ex,
&def_id id, &ann a) -> @item {
- ret @respan(sp, ast.item_const(i, t, ex, id, a));
+ ret @respan(sp, ast::item_const(i, t, ex, id, a));
}
fn identity_fold_item_fn[ENV](&ENV e, &span sp, &ident i,
- &ast._fn f, &vec[ast.ty_param] ty_params,
+ &ast::_fn f, &vec[ast::ty_param] ty_params,
&def_id id, &ann a) -> @item {
- ret @respan(sp, ast.item_fn(i, f, ty_params, id, a));
+ ret @respan(sp, ast::item_fn(i, f, ty_params, id, a));
}
fn identity_fold_native_item_fn[ENV](&ENV e, &span sp, &ident i,
- &Option.t[str] link_name,
- &ast.fn_decl decl,
- &vec[ast.ty_param] ty_params,
+ &option::t[str] link_name,
+ &ast::fn_decl decl,
+ &vec[ast::ty_param] ty_params,
&def_id id, &ann a) -> @native_item {
- ret @respan(sp, ast.native_item_fn(i, link_name, decl, ty_params, id, a));
+ ret @respan(sp, ast::native_item_fn(i, link_name, decl, ty_params,
+ id, a));
}
fn identity_fold_item_mod[ENV](&ENV e, &span sp, &ident i,
- &ast._mod m, &def_id id) -> @item {
- ret @respan(sp, ast.item_mod(i, m, id));
+ &ast::_mod m, &def_id id) -> @item {
+ ret @respan(sp, ast::item_mod(i, m, id));
}
fn identity_fold_item_native_mod[ENV](&ENV e, &span sp, &ident i,
- &ast.native_mod m,
+ &ast::native_mod m,
&def_id id) -> @item {
- ret @respan(sp, ast.item_native_mod(i, m, id));
+ ret @respan(sp, ast::item_native_mod(i, m, id));
}
fn identity_fold_item_ty[ENV](&ENV e, &span sp, &ident i,
- &@ty t, &vec[ast.ty_param] ty_params,
+ &@ty t, &vec[ast::ty_param] ty_params,
&def_id id, &ann a) -> @item {
- ret @respan(sp, ast.item_ty(i, t, ty_params, id, a));
+ ret @respan(sp, ast::item_ty(i, t, ty_params, id, a));
}
fn identity_fold_native_item_ty[ENV](&ENV e, &span sp, &ident i,
&def_id id) -> @native_item {
- ret @respan(sp, ast.native_item_ty(i, id));
+ ret @respan(sp, ast::native_item_ty(i, id));
}
fn identity_fold_item_tag[ENV](&ENV e, &span sp, &ident i,
- &vec[ast.variant] variants,
- &vec[ast.ty_param] ty_params,
+ &vec[ast::variant] variants,
+ &vec[ast::ty_param] ty_params,
&def_id id, &ann a) -> @item {
- ret @respan(sp, ast.item_tag(i, variants, ty_params, id, a));
+ ret @respan(sp, ast::item_tag(i, variants, ty_params, id, a));
}
fn identity_fold_item_obj[ENV](&ENV e, &span sp, &ident i,
- &ast._obj ob, &vec[ast.ty_param] ty_params,
- &ast.obj_def_ids odid, &ann a) -> @item {
- ret @respan(sp, ast.item_obj(i, ob, ty_params, odid, a));
+ &ast::_obj ob, &vec[ast::ty_param] ty_params,
+ &ast::obj_def_ids odid, &ann a) -> @item {
+ ret @respan(sp, ast::item_obj(i, ob, ty_params, odid, a));
}
// View Item folds.
fn identity_fold_view_item_use[ENV](&ENV e, &span sp, &ident i,
&vec[@meta_item] meta_items,
- &def_id id, &Option.t[int] cnum)
+ &def_id id, &option::t[int] cnum)
-> @view_item {
- ret @respan(sp, ast.view_item_use(i, meta_items, id, cnum));
+ ret @respan(sp, ast::view_item_use(i, meta_items, id, cnum));
}
fn identity_fold_view_item_import[ENV](&ENV e, &span sp, &ident i,
&vec[ident] is, &def_id id)
-> @view_item {
- ret @respan(sp, ast.view_item_import(i, is, id));
+ ret @respan(sp, ast::view_item_import(i, is, id));
}
fn identity_fold_view_item_export[ENV](&ENV e, &span sp, &ident i)
-> @view_item {
- ret @respan(sp, ast.view_item_export(i));
+ ret @respan(sp, ast::view_item_export(i));
}
// Annotation folding.
// Additional identities.
-fn identity_fold_block[ENV](&ENV e, &span sp, &ast.block_ blk) -> block {
+fn identity_fold_block[ENV](&ENV e, &span sp, &ast::block_ blk) -> block {
ret respan(sp, blk);
}
fn identity_fold_fn_decl[ENV](&ENV e,
&vec[arg] inputs,
&@ty output,
- &purity p) -> ast.fn_decl {
+ &purity p) -> ast::fn_decl {
ret rec(inputs=inputs, output=output, purity=p);
}
fn identity_fold_fn[ENV](&ENV e,
&fn_decl decl,
- ast.proto proto,
- &block body) -> ast._fn {
+ ast::proto proto,
+ &block body) -> ast::_fn {
ret rec(decl=decl, proto=proto, body=body);
}
-fn identity_fold_mod[ENV](&ENV e, &ast._mod m) -> ast._mod {
+fn identity_fold_mod[ENV](&ENV e, &ast::_mod m) -> ast::_mod {
ret m;
}
fn identity_fold_native_mod[ENV](&ENV e,
- &ast.native_mod m) -> ast.native_mod {
+ &ast::native_mod m) -> ast::native_mod {
ret m;
}
fn identity_fold_crate[ENV](&ENV e, &span sp,
- &vec[@ast.crate_directive] cdirs,
- &ast._mod m) -> @ast.crate {
+ &vec[@ast::crate_directive] cdirs,
+ &ast::_mod m) -> @ast::crate {
ret @respan(sp, rec(directives=cdirs, module=m));
}
fn identity_fold_obj[ENV](&ENV e,
- &vec[ast.obj_field] fields,
- &vec[@ast.method] methods,
- &Option.t[@ast.method] dtor) -> ast._obj {
+ &vec[ast::obj_field] fields,
+ &vec[@ast::method] methods,
+ &option::t[@ast::method] dtor) -> ast::_obj {
ret rec(fields=fields, methods=methods, dtor=dtor);
}
// Env update identities.
-fn identity_update_env_for_crate[ENV](&ENV e, &@ast.crate c) -> ENV {
+fn identity_update_env_for_crate[ENV](&ENV e, &@ast::crate c) -> ENV {
ret e;
}
-import std.Str;
-import std.UInt;
-import std.Vec;
-import std.Map.hashmap;
-import std.EBML;
-import std.IO;
-import std.Option;
-import std.Option.some;
-import std.Option.none;
-
-import front.ast;
-import middle.fold;
-import middle.trans;
-import middle.ty;
-import back.x86;
-import util.common;
-
-import lib.llvm.llvm;
-import lib.llvm.llvm.ValueRef;
-import lib.llvm.False;
+import std::_str;
+import std::_uint;
+import std::_vec;
+import std::map::hashmap;
+import std::ebml;
+import std::io;
+import std::option;
+import std::option::some;
+import std::option::none;
+
+import front::ast;
+import middle::fold;
+import middle::trans;
+import middle::ty;
+import back::x86;
+import util::common;
+
+import lib::llvm::llvm;
+import lib::llvm::llvm::ValueRef;
+import lib::llvm::False;
const uint tag_paths = 0x01u;
const uint tag_items = 0x02u;
tag abbrev_ctxt {
ac_no_abbrevs;
- ac_use_abbrevs(hashmap[ty.t, ty_abbrev]);
+ ac_use_abbrevs(hashmap[ty::t, ty_abbrev]);
}
mod Encode {
type ctxt = rec(
- fn(&ast.def_id) -> str ds, // Def -> str Callback.
- ty.ctxt tcx, // The type context.
+ fn(&ast::def_id) -> str ds, // Def -> str Callback:
+ ty::ctxt tcx, // The type context.
abbrev_ctxt abbrevs
);
}
}
- fn ty_str(&@ctxt cx, &ty.t t) -> str {
+ fn ty_str(&@ctxt cx, &ty::t t) -> str {
assert (!cx_uses_abbrevs(cx));
- auto sw = IO.string_writer();
+ auto sw = io::string_writer();
enc_ty(sw.get_writer(), cx, t);
ret sw.get_str();
}
- fn enc_ty(&IO.writer w, &@ctxt cx, &ty.t t) {
+ fn enc_ty(&io::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[str](?s)) { result_str = s; }
case (none[str]) {
- auto sw = IO.string_writer();
- enc_sty(sw.get_writer(), cx, ty.struct(cx.tcx, t));
+ auto sw = io::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 (none[ty_abbrev]) {
auto pos = w.get_buf_writer().tell();
- auto ss = enc_sty(w, cx, ty.struct(cx.tcx, t));
+ auto ss = 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 {
if (abbrev_len < len) {
// I.e. it's actually an abbreviation.
auto s = ("#"
- + UInt.to_str(pos, 16u) + ":"
- + UInt.to_str(len, 16u) + "#");
+ + _uint::to_str(pos, 16u) + ":"
+ + _uint::to_str(len, 16u) + "#");
auto a = rec(pos=pos, len=len, s=s);
abbrevs.insert(t, a);
}
}
}
- fn enc_mt(&IO.writer w, &@ctxt cx, &ty.mt mt) {
+ fn enc_mt(&io::writer w, &@ctxt cx, &ty::mt mt) {
alt (mt.mut) {
- case (ast.imm) { }
- case (ast.mut) { w.write_char('m'); }
- case (ast.maybe_mut) { w.write_char('?'); }
+ case (ast::imm) { }
+ case (ast::mut) { w.write_char('m'); }
+ case (ast::maybe_mut) { w.write_char('?'); }
}
enc_ty(w, cx, mt.ty);
}
- fn enc_sty(&IO.writer w, &@ctxt cx, &ty.sty st) {
+ fn enc_sty(&io::writer w, &@ctxt cx, &ty::sty st) {
alt (st) {
- case (ty.ty_nil) { w.write_char('n'); }
- 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)) {
+ case (ty::ty_nil) { w.write_char('n'); }
+ 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 (common.ty_u8) { w.write_str("Mb"); }
- case (common.ty_u16) { w.write_str("Mw"); }
- case (common.ty_u32) { w.write_str("Ml"); }
- case (common.ty_u64) { w.write_str("Md"); }
- case (common.ty_i8) { w.write_str("MB"); }
- case (common.ty_i16) { w.write_str("MW"); }
- case (common.ty_i32) { w.write_str("ML"); }
- case (common.ty_i64) { w.write_str("MD"); }
- case (common.ty_f32) { w.write_str("Mf"); }
- case (common.ty_f64) { w.write_str("MF"); }
+ case (common::ty_u8) { w.write_str("Mb"); }
+ case (common::ty_u16) { w.write_str("Mw"); }
+ case (common::ty_u32) { w.write_str("Ml"); }
+ case (common::ty_u64) { w.write_str("Md"); }
+ case (common::ty_i8) { w.write_str("MB"); }
+ case (common::ty_i16) { w.write_str("MW"); }
+ case (common::ty_i32) { w.write_str("ML"); }
+ case (common::ty_i64) { w.write_str("MD"); }
+ case (common::ty_f32) { w.write_str("Mf"); }
+ case (common::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_tag(?def,?tys)) { // TODO restore def_id
+ case (ty::ty_char) {w.write_char('c');}
+ case (ty::ty_str) {w.write_char('s');}
+ case (ty::ty_tag(?def,?tys)) { // TODO restore def_id
w.write_str("t[");
w.write_str(cx.ds(def));
w.write_char('|');
- for (ty.t t in tys) {
+ for (ty::t t in tys) {
enc_ty(w, cx, t);
}
w.write_char(']');
}
- case (ty.ty_box(?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_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_tup(?mts)) {
+ case (ty::ty_box(?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_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_tup(?mts)) {
w.write_str("T[");
- for (ty.mt mt in mts) {
+ for (ty::mt mt in mts) {
enc_mt(w, cx, mt);
}
w.write_char(']');
}
- case (ty.ty_rec(?fields)) {
+ case (ty::ty_rec(?fields)) {
w.write_str("R[");
- for (ty.field field in fields) {
+ for (ty::field field in fields) {
w.write_str(field.ident);
w.write_char('=');
enc_mt(w, cx, field.mt);
}
w.write_char(']');
}
- case (ty.ty_fn(?proto,?args,?out)) {
+ case (ty::ty_fn(?proto,?args,?out)) {
enc_proto(w, proto);
enc_ty_fn(w, cx, args, out);
}
- case (ty.ty_native_fn(?abi,?args,?out)) {
+ case (ty::ty_native_fn(?abi,?args,?out)) {
w.write_char('N');
alt (abi) {
- case (ast.native_abi_rust) { w.write_char('r'); }
- case (ast.native_abi_rust_intrinsic) {
+ case (ast::native_abi_rust) { w.write_char('r'); }
+ case (ast::native_abi_rust_intrinsic) {
w.write_char('i');
}
- case (ast.native_abi_cdecl) { w.write_char('c'); }
- case (ast.native_abi_llvm) { w.write_char('l'); }
+ case (ast::native_abi_cdecl) { w.write_char('c'); }
+ case (ast::native_abi_llvm) { w.write_char('l'); }
}
enc_ty_fn(w, cx, args, out);
}
- case (ty.ty_obj(?methods)) {
+ case (ty::ty_obj(?methods)) {
w.write_str("O[");
- for (ty.method m in methods) {
+ 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);
}
w.write_char(']');
}
- case (ty.ty_var(?id)) {
+ case (ty::ty_var(?id)) {
w.write_char('X');
- w.write_str(common.istr(id));
+ w.write_str(common::istr(id));
}
- case (ty.ty_native) {w.write_char('E');}
- case (ty.ty_param(?id)) {
+ case (ty::ty_native) {w.write_char('E');}
+ case (ty::ty_param(?id)) {
w.write_char('p');
- w.write_str(common.uistr(id));
+ w.write_str(common::uistr(id));
}
- case (ty.ty_type) {w.write_char('Y');}
+ case (ty::ty_type) {w.write_char('Y');}
// These two don't appear in crate metadata, but are here because
// `hash_ty()` uses this function.
- case (ty.ty_bound_param(?id)) {
+ case (ty::ty_bound_param(?id)) {
w.write_char('o');
- w.write_str(common.uistr(id));
+ w.write_str(common::uistr(id));
}
- case (ty.ty_local(?def)) {
+ case (ty::ty_local(?def)) {
w.write_char('L');
w.write_str(cx.ds(def));
}
}
}
- fn enc_proto(&IO.writer w, ast.proto proto) {
+ fn enc_proto(&io::writer w, ast::proto proto) {
alt (proto) {
- case (ast.proto_iter) { w.write_char('W'); }
- case (ast.proto_fn) { w.write_char('F'); }
+ case (ast::proto_iter) { w.write_char('W'); }
+ case (ast::proto_fn) { w.write_char('F'); }
}
}
- fn enc_ty_fn(&IO.writer w, &@ctxt cx, &vec[ty.arg] args, &ty.t out) {
+ fn enc_ty_fn(&io::writer w, &@ctxt cx, &vec[ty::arg] args, &ty::t out) {
w.write_char('[');
- for (ty.arg arg in args) {
- if (arg.mode == ty.mo_alias) { w.write_char('&'); }
+ for (ty::arg arg in args) {
+ if (arg.mode == ty::mo_alias) { w.write_char('&'); }
enc_ty(w, cx, arg.ty);
}
w.write_char(']');
}
-// Returns a Plain Old LLVM String.
+// Returns a Plain Old LLVM String:
fn C_postr(&str s) -> ValueRef {
- ret llvm.LLVMConstString(Str.buf(s), Str.byte_len(s), False);
+ ret llvm::LLVMConstString(_str::buf(s), _str::byte_len(s), False);
}
// Path table encoding
-fn encode_name(&EBML.writer ebml_w, &str name) {
- EBML.start_tag(ebml_w, tag_paths_data_name);
- ebml_w.writer.write(Str.bytes(name));
- EBML.end_tag(ebml_w);
+fn encode_name(&ebml::writer ebml_w, &str name) {
+ ebml::start_tag(ebml_w, tag_paths_data_name);
+ ebml_w.writer.write(_str::bytes(name));
+ ebml::end_tag(ebml_w);
}
-fn encode_def_id(&EBML.writer ebml_w, &ast.def_id id) {
- EBML.start_tag(ebml_w, tag_def_id);
- ebml_w.writer.write(Str.bytes(def_to_str(id)));
- EBML.end_tag(ebml_w);
+fn encode_def_id(&ebml::writer ebml_w, &ast::def_id id) {
+ ebml::start_tag(ebml_w, tag_def_id);
+ ebml_w.writer.write(_str::bytes(def_to_str(id)));
+ ebml::end_tag(ebml_w);
}
-fn encode_tag_variant_paths(&EBML.writer ebml_w,
- &vec[ast.variant] variants,
+fn encode_tag_variant_paths(&ebml::writer ebml_w,
+ &vec[ast::variant] variants,
&vec[str] path,
&mutable vec[tup(str, uint)] index) {
- for (ast.variant variant in variants) {
+ for (ast::variant variant in variants) {
add_to_index(ebml_w, path, index, variant.node.name);
- EBML.start_tag(ebml_w, tag_paths_data_item);
+ ebml::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, variant.node.name);
encode_def_id(ebml_w, variant.node.id);
- EBML.end_tag(ebml_w);
+ ebml::end_tag(ebml_w);
}
}
-fn add_to_index(&EBML.writer ebml_w,
+fn add_to_index(&ebml::writer ebml_w,
&vec[str] path,
&mutable vec[tup(str, uint)] index,
&str name) {
auto full_path = path + vec(name);
- index += vec(tup(Str.connect(full_path, "::"), ebml_w.writer.tell()));
+ index += vec(tup(_str::connect(full_path, "::"), ebml_w.writer.tell()));
}
-fn encode_native_module_item_paths(&EBML.writer ebml_w,
- &ast.native_mod nmod,
+fn encode_native_module_item_paths(&ebml::writer ebml_w,
+ &ast::native_mod nmod,
&vec[str] path,
&mutable vec[tup(str, uint)] index) {
- for (@ast.native_item nitem in nmod.items) {
+ for (@ast::native_item nitem in nmod.items) {
alt (nitem.node) {
- case (ast.native_item_ty(?id, ?did)) {
+ case (ast::native_item_ty(?id, ?did)) {
add_to_index(ebml_w, path, index, id);
- EBML.start_tag(ebml_w, tag_paths_data_item);
+ ebml::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, id);
encode_def_id(ebml_w, did);
- EBML.end_tag(ebml_w);
+ ebml::end_tag(ebml_w);
}
- case (ast.native_item_fn(?id, _, _, _, ?did, _)) {
+ case (ast::native_item_fn(?id, _, _, _, ?did, _)) {
add_to_index(ebml_w, path, index, id);
- EBML.start_tag(ebml_w, tag_paths_data_item);
+ ebml::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, id);
encode_def_id(ebml_w, did);
- EBML.end_tag(ebml_w);
+ ebml::end_tag(ebml_w);
}
}
}
}
-fn encode_module_item_paths(&EBML.writer ebml_w,
- &ast._mod module,
+fn encode_module_item_paths(&ebml::writer ebml_w,
+ &ast::_mod module,
&vec[str] path,
&mutable vec[tup(str, uint)] index) {
// TODO: only encode exported items
- for (@ast.item it in module.items) {
+ for (@ast::item it in module.items) {
alt (it.node) {
- case (ast.item_const(?id, _, ?tps, ?did, ?ann)) {
+ case (ast::item_const(?id, _, ?tps, ?did, ?ann)) {
add_to_index(ebml_w, path, index, id);
- EBML.start_tag(ebml_w, tag_paths_data_item);
+ ebml::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, id);
encode_def_id(ebml_w, did);
- EBML.end_tag(ebml_w);
+ ebml::end_tag(ebml_w);
}
- case (ast.item_fn(?id, _, ?tps, ?did, ?ann)) {
+ case (ast::item_fn(?id, _, ?tps, ?did, ?ann)) {
add_to_index(ebml_w, path, index, id);
- EBML.start_tag(ebml_w, tag_paths_data_item);
+ ebml::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, id);
encode_def_id(ebml_w, did);
- EBML.end_tag(ebml_w);
+ ebml::end_tag(ebml_w);
}
- case (ast.item_mod(?id, ?_mod, ?did)) {
+ case (ast::item_mod(?id, ?_mod, ?did)) {
add_to_index(ebml_w, path, index, id);
- EBML.start_tag(ebml_w, tag_paths_data_mod);
+ ebml::start_tag(ebml_w, tag_paths_data_mod);
encode_name(ebml_w, id);
encode_def_id(ebml_w, did);
encode_module_item_paths(ebml_w, _mod, path + vec(id), index);
- EBML.end_tag(ebml_w);
+ ebml::end_tag(ebml_w);
}
- case (ast.item_native_mod(?id, ?nmod, ?did)) {
+ case (ast::item_native_mod(?id, ?nmod, ?did)) {
add_to_index(ebml_w, path, index, id);
- EBML.start_tag(ebml_w, tag_paths_data_mod);
+ ebml::start_tag(ebml_w, tag_paths_data_mod);
encode_name(ebml_w, id);
encode_def_id(ebml_w, did);
encode_native_module_item_paths(ebml_w, nmod, path + vec(id),
index);
- EBML.end_tag(ebml_w);
+ ebml::end_tag(ebml_w);
}
- case (ast.item_ty(?id, _, ?tps, ?did, ?ann)) {
+ case (ast::item_ty(?id, _, ?tps, ?did, ?ann)) {
add_to_index(ebml_w, path, index, id);
- EBML.start_tag(ebml_w, tag_paths_data_item);
+ ebml::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, id);
encode_def_id(ebml_w, did);
- EBML.end_tag(ebml_w);
+ ebml::end_tag(ebml_w);
}
- case (ast.item_tag(?id, ?variants, ?tps, ?did, _)) {
+ case (ast::item_tag(?id, ?variants, ?tps, ?did, _)) {
add_to_index(ebml_w, path, index, id);
- EBML.start_tag(ebml_w, tag_paths_data_item);
+ ebml::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, id);
encode_def_id(ebml_w, did);
- EBML.end_tag(ebml_w);
+ ebml::end_tag(ebml_w);
encode_tag_variant_paths(ebml_w, variants, path, index);
}
- case (ast.item_obj(?id, _, ?tps, ?odid, ?ann)) {
+ case (ast::item_obj(?id, _, ?tps, ?odid, ?ann)) {
add_to_index(ebml_w, path, index, id);
- EBML.start_tag(ebml_w, tag_paths_data_item);
+ ebml::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, id);
encode_def_id(ebml_w, odid.ctor);
encode_obj_type_id(ebml_w, odid.ty);
- EBML.end_tag(ebml_w);
+ ebml::end_tag(ebml_w);
}
}
}
}
-fn encode_item_paths(&EBML.writer ebml_w, &@ast.crate crate)
+fn encode_item_paths(&ebml::writer ebml_w, &@ast::crate crate)
-> vec[tup(str, uint)] {
let vec[tup(str, uint)] index = vec();
let vec[str] path = vec();
- EBML.start_tag(ebml_w, tag_paths);
+ ebml::start_tag(ebml_w, tag_paths);
encode_module_item_paths(ebml_w, crate.node.module, path, index);
- EBML.end_tag(ebml_w);
+ ebml::end_tag(ebml_w);
ret index;
}
// Item info table encoding
-fn encode_kind(&EBML.writer ebml_w, u8 c) {
- EBML.start_tag(ebml_w, tag_items_data_item_kind);
+fn encode_kind(&ebml::writer ebml_w, u8 c) {
+ ebml::start_tag(ebml_w, tag_items_data_item_kind);
ebml_w.writer.write(vec(c));
- EBML.end_tag(ebml_w);
+ ebml::end_tag(ebml_w);
}
-fn def_to_str(&ast.def_id did) -> str {
+fn def_to_str(&ast::def_id did) -> str {
ret #fmt("%d:%d", did._0, did._1);
}
-fn encode_type_param_count(&EBML.writer ebml_w, &vec[ast.ty_param] tps) {
- EBML.start_tag(ebml_w, tag_items_data_item_ty_param_count);
- EBML.write_vint(ebml_w.writer, Vec.len[ast.ty_param](tps));
- EBML.end_tag(ebml_w);
+fn encode_type_param_count(&ebml::writer ebml_w, &vec[ast::ty_param] tps) {
+ ebml::start_tag(ebml_w, tag_items_data_item_ty_param_count);
+ ebml::write_vint(ebml_w.writer, _vec::len[ast::ty_param](tps));
+ ebml::end_tag(ebml_w);
}
-fn encode_variant_id(&EBML.writer ebml_w, &ast.def_id vid) {
- EBML.start_tag(ebml_w, tag_items_data_item_variant);
- ebml_w.writer.write(Str.bytes(def_to_str(vid)));
- EBML.end_tag(ebml_w);
+fn encode_variant_id(&ebml::writer ebml_w, &ast::def_id vid) {
+ ebml::start_tag(ebml_w, tag_items_data_item_variant);
+ ebml_w.writer.write(_str::bytes(def_to_str(vid)));
+ ebml::end_tag(ebml_w);
}
-fn encode_type(&@trans.crate_ctxt cx, &EBML.writer ebml_w, &ty.t typ) {
- EBML.start_tag(ebml_w, tag_items_data_item_type);
+fn encode_type(&@trans::crate_ctxt cx, &ebml::writer ebml_w, &ty::t typ) {
+ ebml::start_tag(ebml_w, tag_items_data_item_type);
auto f = def_to_str;
auto ty_str_ctxt = @rec(ds=f, tcx=cx.tcx,
abbrevs=ac_use_abbrevs(cx.type_abbrevs));
- Encode.enc_ty(IO.new_writer_(ebml_w.writer), ty_str_ctxt, typ);
- EBML.end_tag(ebml_w);
+ Encode::enc_ty(io::new_writer_(ebml_w.writer), ty_str_ctxt, typ);
+ ebml::end_tag(ebml_w);
}
-fn encode_symbol(&@trans.crate_ctxt cx, &EBML.writer ebml_w,
- &ast.def_id did) {
- EBML.start_tag(ebml_w, tag_items_data_item_symbol);
- ebml_w.writer.write(Str.bytes(cx.item_symbols.get(did)));
- EBML.end_tag(ebml_w);
+fn encode_symbol(&@trans::crate_ctxt cx, &ebml::writer ebml_w,
+ &ast::def_id did) {
+ ebml::start_tag(ebml_w, tag_items_data_item_symbol);
+ ebml_w.writer.write(_str::bytes(cx.item_symbols.get(did)));
+ ebml::end_tag(ebml_w);
}
-fn encode_discriminant(&@trans.crate_ctxt cx, &EBML.writer ebml_w,
- &ast.def_id did) {
- EBML.start_tag(ebml_w, tag_items_data_item_symbol);
- ebml_w.writer.write(Str.bytes(cx.discrim_symbols.get(did)));
- EBML.end_tag(ebml_w);
+fn encode_discriminant(&@trans::crate_ctxt cx, &ebml::writer ebml_w,
+ &ast::def_id did) {
+ ebml::start_tag(ebml_w, tag_items_data_item_symbol);
+ ebml_w.writer.write(_str::bytes(cx.discrim_symbols.get(did)));
+ ebml::end_tag(ebml_w);
}
-fn encode_tag_id(&EBML.writer ebml_w, &ast.def_id id) {
- EBML.start_tag(ebml_w, tag_items_data_item_tag_id);
- ebml_w.writer.write(Str.bytes(def_to_str(id)));
- EBML.end_tag(ebml_w);
+fn encode_tag_id(&ebml::writer ebml_w, &ast::def_id id) {
+ ebml::start_tag(ebml_w, tag_items_data_item_tag_id);
+ ebml_w.writer.write(_str::bytes(def_to_str(id)));
+ ebml::end_tag(ebml_w);
}
-fn encode_obj_type_id(&EBML.writer ebml_w, &ast.def_id id) {
- EBML.start_tag(ebml_w, tag_items_data_item_obj_type_id);
- ebml_w.writer.write(Str.bytes(def_to_str(id)));
- EBML.end_tag(ebml_w);
+fn encode_obj_type_id(&ebml::writer ebml_w, &ast::def_id id) {
+ ebml::start_tag(ebml_w, tag_items_data_item_obj_type_id);
+ ebml_w.writer.write(_str::bytes(def_to_str(id)));
+ ebml::end_tag(ebml_w);
}
-fn encode_tag_variant_info(&@trans.crate_ctxt cx, &EBML.writer ebml_w,
- &ast.def_id did, &vec[ast.variant] variants,
+fn encode_tag_variant_info(&@trans::crate_ctxt cx, &ebml::writer ebml_w,
+ &ast::def_id did, &vec[ast::variant] variants,
&mutable vec[tup(int, uint)] index,
- &vec[ast.ty_param] ty_params) {
- for (ast.variant variant in variants) {
+ &vec[ast::ty_param] ty_params) {
+ for (ast::variant variant in variants) {
index += vec(tup(variant.node.id._1, ebml_w.writer.tell()));
- EBML.start_tag(ebml_w, tag_items_data_item);
+ ebml::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, variant.node.id);
encode_kind(ebml_w, 'v' as u8);
encode_tag_id(ebml_w, did);
- encode_type(cx, ebml_w, trans.node_ann_type(cx, variant.node.ann));
- if (Vec.len[ast.variant_arg](variant.node.args) > 0u) {
+ encode_type(cx, ebml_w, trans::node_ann_type(cx, variant.node.ann));
+ if (_vec::len[ast::variant_arg](variant.node.args) > 0u) {
encode_symbol(cx, ebml_w, variant.node.id);
}
encode_discriminant(cx, ebml_w, variant.node.id);
encode_type_param_count(ebml_w, ty_params);
- EBML.end_tag(ebml_w);
+ ebml::end_tag(ebml_w);
}
}
-fn encode_info_for_item(@trans.crate_ctxt cx, &EBML.writer ebml_w,
- @ast.item item, &mutable vec[tup(int, uint)] index) {
+fn encode_info_for_item(@trans::crate_ctxt cx, &ebml::writer ebml_w,
+ @ast::item item, &mutable vec[tup(int, uint)] index) {
alt (item.node) {
- case (ast.item_const(_, _, _, ?did, ?ann)) {
- EBML.start_tag(ebml_w, tag_items_data_item);
+ case (ast::item_const(_, _, _, ?did, ?ann)) {
+ ebml::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, did);
encode_kind(ebml_w, 'c' as u8);
- encode_type(cx, ebml_w, trans.node_ann_type(cx, ann));
+ encode_type(cx, ebml_w, trans::node_ann_type(cx, ann));
encode_symbol(cx, ebml_w, did);
- EBML.end_tag(ebml_w);
+ ebml::end_tag(ebml_w);
}
- case (ast.item_fn(_, _, ?tps, ?did, ?ann)) {
- EBML.start_tag(ebml_w, tag_items_data_item);
+ case (ast::item_fn(_, _, ?tps, ?did, ?ann)) {
+ ebml::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, did);
encode_kind(ebml_w, 'f' as u8);
encode_type_param_count(ebml_w, tps);
- encode_type(cx, ebml_w, trans.node_ann_type(cx, ann));
+ encode_type(cx, ebml_w, trans::node_ann_type(cx, ann));
encode_symbol(cx, ebml_w, did);
- EBML.end_tag(ebml_w);
+ ebml::end_tag(ebml_w);
}
- case (ast.item_mod(_, _, ?did)) {
- EBML.start_tag(ebml_w, tag_items_data_item);
+ case (ast::item_mod(_, _, ?did)) {
+ ebml::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, did);
encode_kind(ebml_w, 'm' as u8);
- EBML.end_tag(ebml_w);
+ ebml::end_tag(ebml_w);
}
- case (ast.item_native_mod(?id, _, ?did)) {
- EBML.start_tag(ebml_w, tag_items_data_item);
+ case (ast::item_native_mod(?id, _, ?did)) {
+ ebml::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, did);
encode_kind(ebml_w, 'n' as u8);
- EBML.end_tag(ebml_w);
+ ebml::end_tag(ebml_w);
}
- case (ast.item_ty(?id, _, ?tps, ?did, ?ann)) {
- EBML.start_tag(ebml_w, tag_items_data_item);
+ case (ast::item_ty(?id, _, ?tps, ?did, ?ann)) {
+ ebml::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, did);
encode_kind(ebml_w, 'y' as u8);
encode_type_param_count(ebml_w, tps);
- encode_type(cx, ebml_w, trans.node_ann_type(cx, ann));
- EBML.end_tag(ebml_w);
+ encode_type(cx, ebml_w, trans::node_ann_type(cx, ann));
+ ebml::end_tag(ebml_w);
}
- case (ast.item_tag(?id, ?variants, ?tps, ?did, ?ann)) {
- EBML.start_tag(ebml_w, tag_items_data_item);
+ case (ast::item_tag(?id, ?variants, ?tps, ?did, ?ann)) {
+ ebml::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, did);
encode_kind(ebml_w, 't' as u8);
encode_type_param_count(ebml_w, tps);
- encode_type(cx, ebml_w, trans.node_ann_type(cx, ann));
- for (ast.variant v in variants) {
+ encode_type(cx, ebml_w, trans::node_ann_type(cx, ann));
+ for (ast::variant v in variants) {
encode_variant_id(ebml_w, v.node.id);
}
- EBML.end_tag(ebml_w);
+ ebml::end_tag(ebml_w);
encode_tag_variant_info(cx, ebml_w, did, variants, index, tps);
}
- case (ast.item_obj(?id, _, ?tps, ?odid, ?ann)) {
- EBML.start_tag(ebml_w, tag_items_data_item);
+ case (ast::item_obj(?id, _, ?tps, ?odid, ?ann)) {
+ ebml::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, odid.ctor);
encode_kind(ebml_w, 'o' as u8);
encode_type_param_count(ebml_w, tps);
- auto fn_ty = trans.node_ann_type(cx, ann);
+ auto fn_ty = trans::node_ann_type(cx, ann);
encode_type(cx, ebml_w, fn_ty);
encode_symbol(cx, ebml_w, odid.ctor);
- EBML.end_tag(ebml_w);
+ ebml::end_tag(ebml_w);
- EBML.start_tag(ebml_w, tag_items_data_item);
+ ebml::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, odid.ty);
encode_kind(ebml_w, 'y' as u8);
encode_type_param_count(ebml_w, tps);
- encode_type(cx, ebml_w, ty.ty_fn_ret(cx.tcx, fn_ty));
- EBML.end_tag(ebml_w);
+ encode_type(cx, ebml_w, ty::ty_fn_ret(cx.tcx, fn_ty));
+ ebml::end_tag(ebml_w);
}
}
}
-fn encode_info_for_native_item(&@trans.crate_ctxt cx, &EBML.writer ebml_w,
- &@ast.native_item nitem) {
- EBML.start_tag(ebml_w, tag_items_data_item);
+fn encode_info_for_native_item(&@trans::crate_ctxt cx, &ebml::writer ebml_w,
+ &@ast::native_item nitem) {
+ ebml::start_tag(ebml_w, tag_items_data_item);
alt (nitem.node) {
- case (ast.native_item_ty(_, ?did)) {
+ case (ast::native_item_ty(_, ?did)) {
encode_def_id(ebml_w, did);
encode_kind(ebml_w, 'T' as u8);
- encode_type(cx, ebml_w, ty.mk_native(cx.tcx));
+ encode_type(cx, ebml_w, ty::mk_native(cx.tcx));
}
- case (ast.native_item_fn(_, _, _, ?tps, ?did, ?ann)) {
+ case (ast::native_item_fn(_, _, _, ?tps, ?did, ?ann)) {
encode_def_id(ebml_w, did);
encode_kind(ebml_w, 'F' as u8);
encode_type_param_count(ebml_w, tps);
- encode_type(cx, ebml_w, trans.node_ann_type(cx, ann));
+ encode_type(cx, ebml_w, trans::node_ann_type(cx, ann));
encode_symbol(cx, ebml_w, did);
}
}
- EBML.end_tag(ebml_w);
+ ebml::end_tag(ebml_w);
}
-fn encode_info_for_items(&@trans.crate_ctxt cx, &EBML.writer ebml_w)
+fn encode_info_for_items(&@trans::crate_ctxt cx, &ebml::writer ebml_w)
-> vec[tup(int, uint)] {
let vec[tup(int, uint)] index = vec();
- EBML.start_tag(ebml_w, tag_items_data);
- for each (@tup(ast.def_id, @ast.item) kvp in cx.items.items()) {
+ ebml::start_tag(ebml_w, tag_items_data);
+ for each (@tup(ast::def_id, @ast::item) kvp in cx.items.items()) {
index += vec(tup(kvp._0._1, ebml_w.writer.tell()));
encode_info_for_item(cx, ebml_w, kvp._1, index);
}
- for each (@tup(ast.def_id, @ast.native_item) kvp in
+ for each (@tup(ast::def_id, @ast::native_item) kvp in
cx.native_items.items()) {
index += vec(tup(kvp._0._1, ebml_w.writer.tell()));
encode_info_for_native_item(cx, ebml_w, kvp._1);
}
- EBML.end_tag(ebml_w);
+ ebml::end_tag(ebml_w);
ret index;
}
fn hash_path(&str s) -> uint {
auto h = 5381u;
- for (u8 ch in Str.bytes(s)) {
+ for (u8 ch in _str::bytes(s)) {
h = ((h << 5u) + h) ^ (ch as uint);
}
ret h;
fn create_index[T](&vec[tup(T, uint)] index, fn(&T) -> uint hash_fn)
-> vec[vec[tup(T, uint)]] {
let vec[vec[tup(T, uint)]] buckets = vec();
- for each (uint i in UInt.range(0u, 256u)) {
+ for each (uint i in _uint::range(0u, 256u)) {
let vec[tup(T, uint)] bucket = vec();
buckets += vec(bucket);
}
ret buckets;
}
-fn encode_index[T](&EBML.writer ebml_w, &vec[vec[tup(T, uint)]] buckets,
- fn(&IO.writer, &T) write_fn) {
- auto writer = IO.new_writer_(ebml_w.writer);
+fn encode_index[T](&ebml::writer ebml_w, &vec[vec[tup(T, uint)]] buckets,
+ fn(&io::writer, &T) write_fn) {
+ auto writer = io::new_writer_(ebml_w.writer);
- EBML.start_tag(ebml_w, tag_index);
+ ebml::start_tag(ebml_w, tag_index);
let vec[uint] bucket_locs = vec();
- EBML.start_tag(ebml_w, tag_index_buckets);
+ ebml::start_tag(ebml_w, tag_index_buckets);
for (vec[tup(T, uint)] bucket in buckets) {
bucket_locs += vec(ebml_w.writer.tell());
- EBML.start_tag(ebml_w, tag_index_buckets_bucket);
+ ebml::start_tag(ebml_w, tag_index_buckets_bucket);
for (tup(T, uint) elt in bucket) {
- EBML.start_tag(ebml_w, tag_index_buckets_bucket_elt);
+ ebml::start_tag(ebml_w, tag_index_buckets_bucket_elt);
writer.write_be_uint(elt._1, 4u);
write_fn(writer, elt._0);
- EBML.end_tag(ebml_w);
+ ebml::end_tag(ebml_w);
}
- EBML.end_tag(ebml_w);
+ ebml::end_tag(ebml_w);
}
- EBML.end_tag(ebml_w);
+ ebml::end_tag(ebml_w);
- EBML.start_tag(ebml_w, tag_index_table);
+ ebml::start_tag(ebml_w, tag_index_table);
for (uint pos in bucket_locs) {
writer.write_be_uint(pos, 4u);
}
- EBML.end_tag(ebml_w);
+ ebml::end_tag(ebml_w);
- EBML.end_tag(ebml_w);
+ ebml::end_tag(ebml_w);
}
-fn write_str(&IO.writer writer, &str s) {
+fn write_str(&io::writer writer, &str s) {
writer.write_str(s);
}
-fn write_int(&IO.writer writer, &int n) {
+fn write_int(&io::writer writer, &int n) {
writer.write_be_uint(n as uint, 4u);
}
-fn encode_metadata(&@trans.crate_ctxt cx, &@ast.crate crate)
+fn encode_metadata(&@trans::crate_ctxt cx, &@ast::crate crate)
-> ValueRef {
- auto string_w = IO.string_writer();
+ auto string_w = io::string_writer();
auto buf_w = string_w.get_writer().get_buf_writer();
- auto ebml_w = EBML.create_writer(buf_w);
+ auto ebml_w = ebml::create_writer(buf_w);
// Encode and index the paths.
- EBML.start_tag(ebml_w, tag_paths);
+ ebml::start_tag(ebml_w, tag_paths);
auto paths_index = encode_item_paths(ebml_w, crate);
auto str_writer = write_str;
auto path_hasher = hash_path;
auto paths_buckets = create_index[str](paths_index, path_hasher);
encode_index[str](ebml_w, paths_buckets, str_writer);
- EBML.end_tag(ebml_w);
+ ebml::end_tag(ebml_w);
// Encode and index the items.
- EBML.start_tag(ebml_w, tag_items);
+ ebml::start_tag(ebml_w, tag_items);
auto items_index = encode_info_for_items(cx, ebml_w);
auto int_writer = write_int;
auto item_hasher = hash_def_num;
auto items_buckets = create_index[int](items_index, item_hasher);
encode_index[int](ebml_w, items_buckets, int_writer);
- EBML.end_tag(ebml_w);
+ ebml::end_tag(ebml_w);
// Pad this, since something (LLVM, presumably) is cutting off the
// remaining % 4 bytes.
ret C_postr(string_w.get_str());
}
-fn write_metadata(&@trans.crate_ctxt cx, &@ast.crate crate) {
+fn write_metadata(&@trans::crate_ctxt cx, &@ast::crate crate) {
auto llmeta = C_postr("");
if (cx.sess.get_opts().shared) {
llmeta = encode_metadata(cx, crate);
}
- auto llconst = trans.C_struct(vec(llmeta));
- auto llglobal = llvm.LLVMAddGlobal(cx.llmod, trans.val_ty(llconst),
- Str.buf("rust_metadata"));
- llvm.LLVMSetInitializer(llglobal, llconst);
- llvm.LLVMSetSection(llglobal, Str.buf(x86.get_meta_sect_name()));
+ auto llconst = trans::C_struct(vec(llmeta));
+ auto llglobal = llvm::LLVMAddGlobal(cx.llmod, trans::val_ty(llconst),
+ _str::buf("rust_metadata"));
+ llvm::LLVMSetInitializer(llglobal, llconst);
+ llvm::LLVMSetSection(llglobal, _str::buf(x86::get_meta_sect_name()));
}
//
-import front.ast;
-import front.ast.ident;
-import front.ast.def;
-import front.ast.def_id;
-import front.ast.ann;
-import front.creader;
-import driver.session.session;
-import util.common.new_def_hash;
-import util.common.new_int_hash;
-import util.common.new_uint_hash;
-import util.common.new_str_hash;
-import util.common.span;
-import util.typestate_ann.ts_ann;
-import std.Map.hashmap;
-import std.List;
-import std.List.list;
-import std.List.nil;
-import std.List.cons;
-import std.Option;
-import std.Option.some;
-import std.Option.none;
-import std.Str;
-import std.Vec;
+import front::ast;
+import front::ast::ident;
+import front::ast::def;
+import front::ast::def_id;
+import front::ast::ann;
+import front::creader;
+import driver::session::session;
+import util::common::new_def_hash;
+import util::common::new_int_hash;
+import util::common::new_uint_hash;
+import util::common::new_str_hash;
+import util::common::span;
+import util::typestate_ann::ts_ann;
+import std::map::hashmap;
+import std::list::list;
+import std::list::nil;
+import std::list::cons;
+import std::option;
+import std::option::some;
+import std::option::none;
+import std::_str;
+import std::_vec;
// Resolving happens in two passes. The first pass collects defids of all
// (internal) imports and modules, so that they can be looked up when needed,
// isn't a const.)
tag scope {
- scope_crate(@ast.crate);
- scope_item(@ast.item);
- scope_native_item(@ast.native_item);
- scope_loop(@ast.decl); // there's only 1 decl per loop.
- scope_block(ast.block);
- scope_arm(ast.arm);
+ scope_crate(@ast::crate);
+ scope_item(@ast::item);
+ scope_native_item(@ast::native_item);
+ scope_loop(@ast::decl); // there's only 1 decl per loop.
+ scope_block(ast::block);
+ scope_arm(ast::arm);
}
tag import_state {
- todo(@ast.view_item, list[scope]);
+ todo(@ast::view_item, list[scope]);
resolving(span);
- resolved(Option.t[def] /* value */, Option.t[def] /* type */);
+ resolved(option::t[def] /* value */, option::t[def] /* type */);
}
type ext_hash = hashmap[tup(def_id,str),def];
fn new_ext_hash() -> ext_hash {
fn hash(&tup(def_id,str) v) -> uint {
- ret Str.hash(v._1) + util.common.hash_def(v._0);
+ ret _str::hash(v._1) + util::common::hash_def(v._0);
}
fn eq(&tup(def_id,str) v1, &tup(def_id,str) v2) -> bool {
- ret util.common.def_eq(v1._0, v2._0) &&
- Str.eq(v1._1, v2._1);
+ ret util::common::def_eq(v1._0, v2._0) &&
+ _str::eq(v1._1, v2._1);
}
- ret std.Map.mk_hashmap[tup(def_id,str),def](hash, eq);
+ ret std::map::mk_hashmap[tup(def_id,str),def](hash, eq);
}
tag mod_index_entry {
- mie_view_item(@ast.view_item);
- mie_item(@ast.item);
- mie_tag_variant(@ast.item /* tag item */, uint /* variant index */);
+ mie_view_item(@ast::view_item);
+ mie_item(@ast::item);
+ mie_tag_variant(@ast::item /* tag item */, uint /* variant index */);
}
type mod_index = hashmap[ident,mod_index_entry];
-type indexed_mod = rec(ast._mod m, mod_index index);
+type indexed_mod = rec(ast::_mod m, mod_index index);
tag native_mod_index_entry {
- nmie_view_item(@ast.view_item);
- nmie_item(@ast.native_item);
+ nmie_view_item(@ast::view_item);
+ nmie_item(@ast::native_item);
}
type nmod_index = hashmap[ident,native_mod_index_entry];
-type indexed_nmod = rec(ast.native_mod m, nmod_index index);
+type indexed_nmod = rec(ast::native_mod m, nmod_index index);
type def_map = hashmap[uint,def];
type env = rec(def_map def_map,
- hashmap[ast.def_num,import_state] imports,
- hashmap[ast.def_num,@indexed_mod] mod_map,
- hashmap[ast.def_num,@indexed_nmod] nmod_map,
+ hashmap[ast::def_num,import_state] imports,
+ hashmap[ast::def_num,@indexed_mod] mod_map,
+ hashmap[ast::def_num,@indexed_nmod] nmod_map,
hashmap[def_id,vec[ident]] ext_map,
ext_hash ext_cache,
session sess);
ns_type;
}
-fn resolve_crate(session sess, @ast.crate crate)
- -> tup(@ast.crate, def_map) {
+fn resolve_crate(session sess, @ast::crate crate)
+ -> tup(@ast::crate, def_map) {
auto e = @rec(def_map = new_uint_hash[def](),
imports = new_int_hash[import_state](),
mod_map = new_int_hash[@indexed_mod](),
// 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(&@env e, &ast::crate c) {
auto cell = @mutable nil[scope];
auto v = rec(visit_crate_pre = bind push_env_for_crate(cell, _),
visit_crate_post = bind pop_env_for_crate(cell, _),
visit_view_item_pre = bind visit_view_item(e, cell, _),
visit_item_pre = bind push_env_for_item_map_mod(e, cell, _),
visit_item_post = bind pop_env_for_item(cell, _)
- with walk.default_visitor());
+ with walk::default_visitor());
// Register the top-level mod
e.mod_map.insert(-1, @rec(m=c.node.module,
index=index_mod(c.node.module)));
- walk.walk_crate(v, c);
+ walk::walk_crate(v, c);
// Helpers for this pass.
- fn push_env_for_crate(@mutable list[scope] sc, &ast.crate c) {
+ fn push_env_for_crate(@mutable list[scope] sc, &ast::crate c) {
*sc = cons[scope](scope_crate(@c), @*sc);
}
- fn pop_env_for_crate(@mutable list[scope] sc, &ast.crate c) {
- *sc = List.cdr(*sc);
+ fn pop_env_for_crate(@mutable list[scope] sc, &ast::crate c) {
+ *sc = std::list::cdr(*sc);
}
fn push_env_for_item_map_mod(@env e, @mutable list[scope] sc,
- &@ast.item i) {
+ &@ast::item i) {
*sc = cons[scope](scope_item(i), @*sc);
alt (i.node) {
- case (ast.item_mod(_, ?md, ?defid)) {
+ case (ast::item_mod(_, ?md, ?defid)) {
auto index = index_mod(md);
e.mod_map.insert(defid._1, @rec(m=md, index=index));
}
- case (ast.item_native_mod(_, ?nmd, ?defid)) {
+ case (ast::item_native_mod(_, ?nmd, ?defid)) {
auto index = index_nmod(nmd);
e.nmod_map.insert(defid._1, @rec(m=nmd, index=index));
}
case (_) {}
}
}
- fn pop_env_for_item(@mutable list[scope] sc, &@ast.item i) {
- *sc = List.cdr(*sc);
+ fn pop_env_for_item(@mutable list[scope] sc, &@ast::item i) {
+ *sc = std::list::cdr(*sc);
}
- fn visit_view_item(@env e, @mutable list[scope] sc, &@ast.view_item i) {
+ fn visit_view_item(@env e, @mutable list[scope] sc, &@ast::view_item i) {
alt (i.node) {
- case (ast.view_item_import(_, ?ids, ?defid)) {
+ case (ast::view_item_import(_, ?ids, ?defid)) {
e.imports.insert(defid._1, todo(i, *sc));
}
case (_) {}
}
fn resolve_imports(&env e) {
- for each (@tup(ast.def_num, import_state) it in e.imports.items()) {
+ for each (@tup(ast::def_num, import_state) it in e.imports.items()) {
alt (it._1) {
case (todo(?item, ?sc)) {
resolve_import(e, item, sc);
}
// FIXME this should use walk (will need to add walk_arm)
-fn resolve_names(&@env e, &ast.crate c) -> @ast.crate {
+fn resolve_names(&@env e, &ast::crate c) -> @ast::crate {
auto fld = @rec(fold_pat_tag = bind fold_pat_tag(e,_,_,_,_,_),
fold_expr_path = bind fold_expr_path(e,_,_,_,_),
fold_ty_path = bind fold_ty_path(e,_,_,_,_),
update_env_for_block = bind update_env_for_block(_,_),
update_env_for_arm = bind update_env_for_arm(_,_),
update_env_for_expr = bind update_env_for_expr(_,_)
- with *fold.new_identity_fold[list[scope]]());
- ret fold.fold_crate(nil[scope], fld, @c);
+ with *fold::new_identity_fold[list[scope]]());
+ ret fold::fold_crate(nil[scope], fld, @c);
// Helpers for this pass
- fn update_env_for_crate(&list[scope] sc, &@ast.crate c) -> list[scope] {
+ fn update_env_for_crate(&list[scope] sc, &@ast::crate c) -> list[scope] {
ret cons[scope](scope_crate(c), @sc);
}
- fn update_env_for_item(&list[scope] sc, &@ast.item i) -> list[scope] {
+ fn update_env_for_item(&list[scope] sc, &@ast::item i) -> list[scope] {
ret cons[scope](scope_item(i), @sc);
}
- fn update_env_for_native_item(&list[scope] sc, &@ast.native_item i)
+ fn update_env_for_native_item(&list[scope] sc, &@ast::native_item i)
-> list[scope] {
ret cons[scope](scope_native_item(i), @sc);
}
- fn update_env_for_block(&list[scope] sc, &ast.block b) -> list[scope] {
+ fn update_env_for_block(&list[scope] sc, &ast::block b) -> list[scope] {
ret cons[scope](scope_block(b), @sc);
}
- fn update_env_for_expr(&list[scope] sc, &@ast.expr x) -> list[scope] {
+ fn update_env_for_expr(&list[scope] sc, &@ast::expr x) -> list[scope] {
alt (x.node) {
- case (ast.expr_for(?d, _, _, _)) {
+ case (ast::expr_for(?d, _, _, _)) {
ret cons[scope](scope_loop(d), @sc);
}
- case (ast.expr_for_each(?d, _, _, _)) {
+ case (ast::expr_for_each(?d, _, _, _)) {
ret cons[scope](scope_loop(d), @sc);
}
case (_) { ret sc; }
}
}
- fn update_env_for_arm(&list[scope] sc, &ast.arm p) -> list[scope] {
+ fn update_env_for_arm(&list[scope] sc, &ast::arm p) -> list[scope] {
ret cons[scope](scope_arm(p), @sc);
}
}
-fn lookup_import(&env e, def_id defid, namespace ns) -> Option.t[def] {
+fn lookup_import(&env e, def_id defid, namespace ns) -> option::t[def] {
alt (e.imports.get(defid._1)) {
case (todo(?item, ?sc)) {
resolve_import(e, item, sc);
}
}
-fn resolve_import(&env e, &@ast.view_item it, &list[scope] sc) {
+fn resolve_import(&env e, &@ast::view_item it, &list[scope] sc) {
auto defid; auto ids;
alt (it.node) {
- case (ast.view_item_import(_, ?_ids, ?_defid)) {
+ case (ast::view_item_import(_, ?_ids, ?_defid)) {
defid = _defid; ids = _ids;
}
}
e.imports.insert(defid._1, resolving(it.span));
- auto n_idents = Vec.len(ids);
+ auto n_idents = _vec::len(ids);
auto end_id = ids.(n_idents - 1u);
if (n_idents == 1u) {
}
fn register(&env e, def_id defid, &span sp, ident id,
- Option.t[def] val, Option.t[def] typ) {
+ option::t[def] val, option::t[def] typ) {
if (val == none[def] && typ == none[def]) {
unresolved(e, sp, id, "import");
}
}
}
-fn fold_expr_path(@env e, &list[scope] sc, &span sp, &ast.path p, &ann a)
- -> @ast.expr {
+fn fold_expr_path(@env e, &list[scope] sc, &span sp, &ast::path p, &ann a)
+ -> @ast::expr {
auto df = lookup_path_strict(*e, sc, sp, p.node.idents, ns_value);
- e.def_map.insert(ast.ann_tag(a), df);
- ret @fold.respan(sp, ast.expr_path(p, a));
+ e.def_map.insert(ast::ann_tag(a), df);
+ ret @fold::respan(sp, ast::expr_path(p, a));
}
-fn fold_pat_tag(@env e, &list[scope] sc, &span sp, &ast.path p,
- &vec[@ast.pat] args, &ann a) -> @ast.pat {
+fn fold_pat_tag(@env e, &list[scope] sc, &span sp, &ast::path p,
+ &vec[@ast::pat] args, &ann a) -> @ast::pat {
alt (lookup_path_strict(*e, sc, sp, p.node.idents, ns_value)) {
- case (ast.def_variant(?did, ?vid)) {
- e.def_map.insert(ast.ann_tag(a), ast.def_variant(did, vid));
- ret @fold.respan[ast.pat_](sp, ast.pat_tag(p, args, a));
+ case (ast::def_variant(?did, ?vid)) {
+ e.def_map.insert(ast::ann_tag(a), ast::def_variant(did, vid));
+ ret @fold::respan[ast::pat_](sp, ast::pat_tag(p, args, a));
}
case (_) {
e.sess.span_err(sp, "not a tag variant: " +
- Str.connect(p.node.idents, "::"));
+ _str::connect(p.node.idents, "::"));
fail;
}
}
}
-fn fold_ty_path(@env e, &list[scope] sc, &span sp, &ast.path p,
- &ast.ann a) -> @ast.ty {
+fn fold_ty_path(@env e, &list[scope] sc, &span sp, &ast::path p,
+ &ast::ann a) -> @ast::ty {
auto new_def = lookup_path_strict(*e, sc, sp, p.node.idents, ns_type);
- e.def_map.insert(ast.ann_tag(a), new_def);
- ret @fold.respan[ast.ty_](sp, ast.ty_path(p, a));
+ e.def_map.insert(ast::ann_tag(a), new_def);
+ ret @fold::respan[ast::ty_](sp, ast::ty_path(p, a));
}
fn is_module(def d) -> bool {
alt (d) {
- case (ast.def_mod(_)) { ret true; }
- case (ast.def_native_mod(_)) { ret true; }
+ case (ast::def_mod(_)) { ret true; }
+ case (ast::def_native_mod(_)) { ret true; }
case (_) { ret false; }
}
}
fn lookup_path_strict(&env e, &list[scope] sc, &span sp, vec[ident] idents,
namespace ns) -> def {
- auto n_idents = Vec.len(idents);
+ auto n_idents = _vec::len(idents);
auto dcur = lookup_in_scope_strict(e, sc, sp, idents.(0), ns);
auto i = 1u;
while (i < n_idents) {
i += 1u;
}
if (is_module(dcur)) {
- e.sess.span_err(sp, Str.connect(idents, "::") +
+ e.sess.span_err(sp, _str::connect(idents, "::") +
" is a module, not a " + ns_name(ns));
}
ret dcur;
}
fn lookup_in_scope(&env e, list[scope] sc, ident id, namespace ns)
- -> Option.t[def] {
+ -> option::t[def] {
fn in_scope(&env e, ident id, &scope s, namespace ns)
- -> Option.t[def] {
+ -> option::t[def] {
alt (s) {
case (scope_crate(?c)) {
- auto defid = tup(ast.local_crate, -1);
+ auto defid = tup(ast::local_crate, -1);
ret lookup_in_regular_mod(e, defid, id, ns, inside);
}
case (scope_item(?it)) {
alt (it.node) {
- case (ast.item_fn(_, ?f, ?ty_params, _, _)) {
+ case (ast::item_fn(_, ?f, ?ty_params, _, _)) {
ret lookup_in_fn(id, f.decl, ty_params, ns);
}
- case (ast.item_obj(_, ?ob, ?ty_params, _, _)) {
+ case (ast::item_obj(_, ?ob, ?ty_params, _, _)) {
ret lookup_in_obj(id, ob, ty_params, ns);
}
- case (ast.item_tag(_, _, ?ty_params, _, _)) {
+ case (ast::item_tag(_, _, ?ty_params, _, _)) {
if (ns == ns_type) {
ret lookup_in_ty_params(id, ty_params);
}
}
- case (ast.item_mod(_, _, ?defid)) {
+ case (ast::item_mod(_, _, ?defid)) {
ret lookup_in_regular_mod(e, defid, id, ns, inside);
}
- case (ast.item_native_mod(_, ?m, ?defid)) {
+ case (ast::item_native_mod(_, ?m, ?defid)) {
ret lookup_in_native_mod(e, defid, id, ns);
}
- case (ast.item_ty(_, _, ?ty_params, _, _)) {
+ case (ast::item_ty(_, _, ?ty_params, _, _)) {
if (ns == ns_type) {
ret lookup_in_ty_params(id, ty_params);
}
case (scope_native_item(?it)) {
alt (it.node) {
- case (ast.native_item_fn(_, _, ?decl, ?ty_params, _, _)) {
+ case (ast::native_item_fn(_, _, ?decl, ?ty_params, _, _)){
ret lookup_in_fn(id, decl, ty_params, ns);
}
}
case (scope_loop(?d)) {
if (ns == ns_value) {
alt (d.node) {
- case (ast.decl_local(?local)) {
- if (Str.eq(local.ident, id)) {
- ret some(ast.def_local(local.id));
+ case (ast::decl_local(?local)) {
+ if (_str::eq(local.ident, id)) {
+ ret some(ast::def_local(local.id));
}
}
}
}
}
-fn lookup_in_ty_params(ident id, &vec[ast.ty_param] ty_params)
- -> Option.t[def] {
+fn lookup_in_ty_params(ident id, &vec[ast::ty_param] ty_params)
+ -> option::t[def] {
auto i = 0u;
- for (ast.ty_param tp in ty_params) {
- if (Str.eq(tp, id)) {
- ret some(ast.def_ty_arg(i));
+ for (ast::ty_param tp in ty_params) {
+ if (_str::eq(tp, id)) {
+ ret some(ast::def_ty_arg(i));
}
i += 1u;
}
ret none[def];
}
-fn lookup_in_pat(ident id, &ast.pat pat) -> Option.t[def] {
+fn lookup_in_pat(ident id, &ast::pat pat) -> option::t[def] {
alt (pat.node) {
- case (ast.pat_bind(?name, ?defid, _)) {
- if (Str.eq(name, id)) { ret some(ast.def_binding(defid)); }
+ case (ast::pat_bind(?name, ?defid, _)) {
+ if (_str::eq(name, id)) { ret some(ast::def_binding(defid)); }
}
- case (ast.pat_wild(_)) {}
- case (ast.pat_lit(_, _)) {}
- case (ast.pat_tag(_, ?pats, _)) {
- for (@ast.pat p in pats) {
+ case (ast::pat_wild(_)) {}
+ case (ast::pat_lit(_, _)) {}
+ case (ast::pat_tag(_, ?pats, _)) {
+ for (@ast::pat p in pats) {
auto found = lookup_in_pat(id, *p);
if (found != none[def]) { ret found; }
}
}
-fn lookup_in_fn(ident id, &ast.fn_decl decl,
- &vec[ast.ty_param] ty_params, namespace ns) -> Option.t[def] {
+fn lookup_in_fn(ident id, &ast::fn_decl decl, &vec[ast::ty_param] ty_params,
+ namespace ns) -> option::t[def] {
if (ns == ns_value) {
- for (ast.arg a in decl.inputs) {
- if (Str.eq(a.ident, id)) {
- ret some(ast.def_arg(a.id));
+ for (ast::arg a in decl.inputs) {
+ if (_str::eq(a.ident, id)) {
+ ret some(ast::def_arg(a.id));
}
}
ret none[def];
}
}
-fn lookup_in_obj(ident id, &ast._obj ob, &vec[ast.ty_param] ty_params,
- namespace ns) -> Option.t[def] {
+fn lookup_in_obj(ident id, &ast::_obj ob, &vec[ast::ty_param] ty_params,
+ namespace ns) -> option::t[def] {
if (ns == ns_value) {
- for (ast.obj_field f in ob.fields) {
- if (Str.eq(f.ident, id)) {
- ret some(ast.def_obj_field(f.id));
+ for (ast::obj_field f in ob.fields) {
+ if (_str::eq(f.ident, id)) {
+ ret some(ast::def_obj_field(f.id));
}
}
ret none[def];
}
}
-fn lookup_in_block(ident id, &ast.block_ b, namespace ns)
- -> Option.t[def] {
- for (@ast.stmt st in b.stmts) {
+fn lookup_in_block(ident id, &ast::block_ b, namespace ns)
+ -> option::t[def] {
+ for (@ast::stmt st in b.stmts) {
alt (st.node) {
- case (ast.stmt_decl(?d,_)) {
+ case (ast::stmt_decl(?d,_)) {
alt (d.node) {
- case (ast.decl_local(?loc)) {
- if (ns == ns_value && Str.eq(id, loc.ident)) {
- ret some(ast.def_local(loc.id));
+ case (ast::decl_local(?loc)) {
+ if (ns == ns_value && _str::eq(id, loc.ident)) {
+ ret some(ast::def_local(loc.id));
}
}
- case (ast.decl_item(?it)) {
+ case (ast::decl_item(?it)) {
alt (it.node) {
- case (ast.item_tag(?name, ?variants, _,
+ case (ast::item_tag(?name, ?variants, _,
?defid, _)) {
if (ns == ns_type) {
- if (Str.eq(name, id)) {
- ret some(ast.def_ty(defid));
+ if (_str::eq(name, id)) {
+ ret some(ast::def_ty(defid));
}
} else {
- for (ast.variant v in variants) {
- if (Str.eq(v.node.name, id)) {
- ret some(ast.def_variant(
+ for (ast::variant v in variants) {
+ if (_str::eq(v.node.name, id)) {
+ ret some(ast::def_variant(
defid, v.node.id));
}
}
}
}
case (_) {
- if (Str.eq(ast.item_ident(it), id)) {
+ if (_str::eq(ast::item_ident(it), id)) {
auto found = found_def_item(it, ns);
if (found != none[def]) { ret found; }
}
ret none[def];
}
-fn found_def_item(@ast.item i, namespace ns) -> Option.t[def] {
+fn found_def_item(@ast::item i, namespace ns) -> option::t[def] {
alt (i.node) {
- case (ast.item_const(_, _, _, ?defid, _)) {
- if (ns == ns_value) { ret some(ast.def_const(defid)); }
+ case (ast::item_const(_, _, _, ?defid, _)) {
+ if (ns == ns_value) { ret some(ast::def_const(defid)); }
}
- case (ast.item_fn(_, _, _, ?defid, _)) {
- if (ns == ns_value) { ret some(ast.def_fn(defid)); }
+ case (ast::item_fn(_, _, _, ?defid, _)) {
+ if (ns == ns_value) { ret some(ast::def_fn(defid)); }
}
- case (ast.item_mod(_, _, ?defid)) {
- ret some(ast.def_mod(defid));
+ case (ast::item_mod(_, _, ?defid)) {
+ ret some(ast::def_mod(defid));
}
- case (ast.item_native_mod(_, _, ?defid)) {
- ret some(ast.def_native_mod(defid));
+ case (ast::item_native_mod(_, _, ?defid)) {
+ ret some(ast::def_native_mod(defid));
}
- case (ast.item_ty(_, _, _, ?defid, _)) {
- if (ns == ns_type) { ret some(ast.def_ty(defid)); }
+ case (ast::item_ty(_, _, _, ?defid, _)) {
+ if (ns == ns_type) { ret some(ast::def_ty(defid)); }
}
- case (ast.item_tag(_, _, _, ?defid, _)) {
- if (ns == ns_type) { ret some(ast.def_ty(defid)); }
+ case (ast::item_tag(_, _, _, ?defid, _)) {
+ if (ns == ns_type) { ret some(ast::def_ty(defid)); }
}
- case (ast.item_obj(_, _, _, ?odid, _)) {
- if (ns == ns_value) { ret some(ast.def_obj(odid.ctor)); }
- else { ret some(ast.def_obj(odid.ty)); }
+ case (ast::item_obj(_, _, _, ?odid, _)) {
+ if (ns == ns_value) { ret some(ast::def_obj(odid.ctor)); }
+ else { ret some(ast::def_obj(odid.ty)); }
}
case (_) { }
}
}
fn lookup_in_mod(&env e, def m, ident id, namespace ns, dir dr)
- -> Option.t[def] {
- auto defid = ast.def_id_of_def(m);
- if (defid._0 != ast.local_crate) { // Not in this crate
+ -> option::t[def] {
+ auto defid = ast::def_id_of_def(m);
+ if (defid._0 != ast::local_crate) { // Not in this crate
auto cached = e.ext_cache.find(tup(defid,id));
- if (cached != none[def] && check_def_by_ns(Option.get(cached), ns)) {
+ if (cached != none[def] && check_def_by_ns(option::get(cached), ns)) {
ret cached;
}
auto path = vec(id);
}
auto fnd = lookup_external(e, defid._0, path, ns);
if (fnd != none[def]) {
- e.ext_cache.insert(tup(defid,id), Option.get(fnd));
+ e.ext_cache.insert(tup(defid,id), option::get(fnd));
}
ret fnd;
}
alt (m) {
- case (ast.def_mod(?defid)) {
+ case (ast::def_mod(?defid)) {
ret lookup_in_regular_mod(e, defid, id, ns, dr);
}
- case (ast.def_native_mod(?defid)) {
+ case (ast::def_native_mod(?defid)) {
ret lookup_in_native_mod(e, defid, id, ns);
}
}
}
-fn found_view_item(&env e, @ast.view_item vi, namespace ns) -> Option.t[def] {
+fn found_view_item(&env e, @ast::view_item vi, namespace ns)
+ -> option::t[def] {
alt (vi.node) {
- case (ast.view_item_use(_, _, _, ?cnum)) {
- ret some(ast.def_mod(tup(Option.get(cnum), -1)));
+ case (ast::view_item_use(_, _, _, ?cnum)) {
+ ret some(ast::def_mod(tup(option::get(cnum), -1)));
}
- case (ast.view_item_import(_, _, ?defid)) {
+ case (ast::view_item_import(_, _, ?defid)) {
ret lookup_import(e, defid, ns);
}
}
}
fn lookup_in_regular_mod(&env e, def_id defid, ident id, namespace ns, dir dr)
- -> Option.t[def] {
+ -> option::t[def] {
auto info = e.mod_map.get(defid._1);
auto found = info.index.find(id);
if (found == none[mod_index_entry] ||
- (dr == outside && !ast.is_exported(id, info.m))) {
+ (dr == outside && !ast::is_exported(id, info.m))) {
ret none[def];
}
- alt (Option.get(found)) {
+ alt (option::get(found)) {
case (mie_view_item(?view_item)) {
ret found_view_item(e, view_item, ns);
}
}
case (mie_tag_variant(?item, ?variant_idx)) {
alt (item.node) {
- case (ast.item_tag(_, ?variants, _, ?tid, _)) {
+ case (ast::item_tag(_, ?variants, _, ?tid, _)) {
if (ns == ns_value) {
auto vid = variants.(variant_idx).node.id;
- ret some(ast.def_variant(tid, vid));
+ ret some(ast::def_variant(tid, vid));
} else {
ret none[def];
}
}
fn lookup_in_native_mod(&env e, def_id defid, ident id, namespace ns)
- -> Option.t[def] {
+ -> option::t[def] {
auto info = e.nmod_map.get(defid._1);
auto found = info.index.find(id);
if (found == none[native_mod_index_entry]) {
ret none[def];
}
- alt (Option.get(found)) {
+ alt (option::get(found)) {
case (nmie_view_item(?view_item)) {
ret found_view_item(e, view_item, ns);
}
case (nmie_item(?item)) {
alt (item.node) {
- case (ast.native_item_ty(_, ?id)) {
+ case (ast::native_item_ty(_, ?id)) {
if (ns == ns_type) {
- ret some(ast.def_native_ty(id));
+ ret some(ast::def_native_ty(id));
}
}
- case (ast.native_item_fn(_, _, _, _, ?id, _)) {
+ case (ast::native_item_fn(_, _, _, _, ?id, _)) {
if (ns == ns_value) {
- ret some(ast.def_native_fn(id));
+ ret some(ast::def_native_fn(id));
}
}
}
// Module indexing
-fn index_mod(&ast._mod md) -> mod_index {
+fn index_mod(&ast::_mod md) -> mod_index {
auto index = new_str_hash[mod_index_entry]();
- for (@ast.view_item it in md.view_items) {
+ for (@ast::view_item it in md.view_items) {
alt (it.node) {
- case(ast.view_item_use(?id, _, _, _)) {
+ case(ast::view_item_use(?id, _, _, _)) {
index.insert(id, mie_view_item(it));
}
- case(ast.view_item_import(?def_ident,_,_)) {
+ case(ast::view_item_import(?def_ident,_,_)) {
index.insert(def_ident, mie_view_item(it));
}
- case(ast.view_item_export(_)) {}
+ case(ast::view_item_export(_)) {}
}
}
- for (@ast.item it in md.items) {
+ for (@ast::item it in md.items) {
alt (it.node) {
- case (ast.item_const(?id, _, _, _, _)) {
+ case (ast::item_const(?id, _, _, _, _)) {
index.insert(id, mie_item(it));
}
- case (ast.item_fn(?id, _, _, _, _)) {
+ case (ast::item_fn(?id, _, _, _, _)) {
index.insert(id, mie_item(it));
}
- case (ast.item_mod(?id, _, _)) {
+ case (ast::item_mod(?id, _, _)) {
index.insert(id, mie_item(it));
}
- case (ast.item_native_mod(?id, _, _)) {
+ case (ast::item_native_mod(?id, _, _)) {
index.insert(id, mie_item(it));
}
- case (ast.item_ty(?id, _, _, _, _)) {
+ case (ast::item_ty(?id, _, _, _, _)) {
index.insert(id, mie_item(it));
}
- case (ast.item_tag(?id, ?variants, _, _, _)) {
+ case (ast::item_tag(?id, ?variants, _, _, _)) {
index.insert(id, mie_item(it));
let uint variant_idx = 0u;
- for (ast.variant v in variants) {
+ for (ast::variant v in variants) {
index.insert(v.node.name,
mie_tag_variant(it, variant_idx));
variant_idx += 1u;
}
}
- case (ast.item_obj(?id, _, _, _, _)) {
+ case (ast::item_obj(?id, _, _, _, _)) {
index.insert(id, mie_item(it));
}
}
ret index;
}
-fn index_nmod(&ast.native_mod md) -> nmod_index {
+fn index_nmod(&ast::native_mod md) -> nmod_index {
auto index = new_str_hash[native_mod_index_entry]();
- for (@ast.view_item it in md.view_items) {
+ for (@ast::view_item it in md.view_items) {
alt (it.node) {
- case(ast.view_item_import(?def_ident,_,_)) {
+ case(ast::view_item_import(?def_ident,_,_)) {
index.insert(def_ident, nmie_view_item(it));
}
- case(ast.view_item_export(_)) {}
+ case(ast::view_item_export(_)) {}
}
}
- for (@ast.native_item it in md.items) {
+ for (@ast::native_item it in md.items) {
alt (it.node) {
- case (ast.native_item_ty(?id, _)) {
+ case (ast::native_item_ty(?id, _)) {
index.insert(id, nmie_item(it));
}
- case (ast.native_item_fn(?id, _, _, _, _, _)) {
+ case (ast::native_item_fn(?id, _, _, _, _, _)) {
index.insert(id, nmie_item(it));
}
}
// FIXME creader should handle multiple namespaces
fn check_def_by_ns(def d, namespace ns) -> bool {
ret alt (d) {
- case (ast.def_fn(?id)) { ns == ns_value }
- case (ast.def_obj(?id)) { ns == ns_value }
- case (ast.def_obj_field(?id)) { ns == ns_value }
- case (ast.def_mod(?id)) { true }
- case (ast.def_native_mod(?id)) { true }
- case (ast.def_const(?id)) { ns == ns_value }
- case (ast.def_arg(?id)) { ns == ns_value }
- case (ast.def_local(?id)) { ns == ns_value }
- case (ast.def_upvar(?id)) { ns == ns_value }
- case (ast.def_variant(_, ?id)) { ns == ns_value }
- case (ast.def_ty(?id)) { ns == ns_type }
- case (ast.def_binding(?id)) { ns == ns_type }
- case (ast.def_use(?id)) { true }
- case (ast.def_native_ty(?id)) { ns == ns_type }
- case (ast.def_native_fn(?id)) { ns == ns_value }
+ case (ast::def_fn(?id)) { ns == ns_value }
+ case (ast::def_obj(?id)) { ns == ns_value }
+ case (ast::def_obj_field(?id)) { ns == ns_value }
+ case (ast::def_mod(?id)) { true }
+ case (ast::def_native_mod(?id)) { true }
+ case (ast::def_const(?id)) { ns == ns_value }
+ case (ast::def_arg(?id)) { ns == ns_value }
+ case (ast::def_local(?id)) { ns == ns_value }
+ case (ast::def_upvar(?id)) { ns == ns_value }
+ case (ast::def_variant(_, ?id)) { ns == ns_value }
+ case (ast::def_ty(?id)) { ns == ns_type }
+ case (ast::def_binding(?id)) { ns == ns_type }
+ case (ast::def_use(?id)) { true }
+ case (ast::def_native_ty(?id)) { ns == ns_type }
+ case (ast::def_native_fn(?id)) { ns == ns_value }
};
}
fn lookup_external(&env e, int cnum, vec[ident] ids, namespace ns)
- -> Option.t[def] {
- auto found = creader.lookup_def(e.sess, cnum, ids);
+ -> option::t[def] {
+ auto found = creader::lookup_def(e.sess, cnum, ids);
if (found != none[def]) {
- auto d = Option.get(found);
+ auto d = option::get(found);
if (!check_def_by_ns(d, ns)) { ret none[def]; }
- e.ext_map.insert(ast.def_id_of_def(d), ids);
+ e.ext_map.insert(ast::def_id_of_def(d), ids);
}
ret found;
}
-import std.Int;
-import std.Str;
-import std.UInt;
-import std.Vec;
-import std.Str.rustrt.sbuf;
-import std.Vec.rustrt.vbuf;
-import std.Map;
-import std.Map.hashmap;
-import std.Option;
-import std.Option.some;
-import std.Option.none;
-
-import front.ast;
-import front.creader;
-import driver.session;
-import middle.ty;
-import back.Link;
-import back.x86;
-import back.abi;
-import back.upcall;
-
-import middle.ty.pat_ty;
-
-import util.common;
-import util.common.istr;
-import util.common.new_def_hash;
-import util.common.new_str_hash;
-
-import lib.llvm.llvm;
-import lib.llvm.builder;
-import lib.llvm.target_data;
-import lib.llvm.type_handle;
-import lib.llvm.type_names;
-import lib.llvm.mk_target_data;
-import lib.llvm.mk_type_handle;
-import lib.llvm.mk_type_names;
-import lib.llvm.llvm.ModuleRef;
-import lib.llvm.llvm.ValueRef;
-import lib.llvm.llvm.TypeRef;
-import lib.llvm.llvm.TypeHandleRef;
-import lib.llvm.llvm.BuilderRef;
-import lib.llvm.llvm.BasicBlockRef;
-
-import lib.llvm.False;
-import lib.llvm.True;
-import lib.llvm.Bool;
+import std::_int;
+import std::_str;
+import std::_uint;
+import std::_vec;
+import std::_str::rustrt::sbuf;
+import std::_vec::rustrt::vbuf;
+import std::map;
+import std::map::hashmap;
+import std::option;
+import std::option::some;
+import std::option::none;
+
+import front::ast;
+import front::creader;
+import driver::session;
+import middle::ty;
+import back::Link;
+import back::x86;
+import back::abi;
+import back::upcall;
+
+import middle::ty::pat_ty;
+
+import util::common;
+import util::common::istr;
+import util::common::new_def_hash;
+import util::common::new_str_hash;
+
+import lib::llvm::llvm;
+import lib::llvm::builder;
+import lib::llvm::target_data;
+import lib::llvm::type_handle;
+import lib::llvm::type_names;
+import lib::llvm::mk_target_data;
+import lib::llvm::mk_type_handle;
+import lib::llvm::mk_type_names;
+import lib::llvm::llvm::ModuleRef;
+import lib::llvm::llvm::ValueRef;
+import lib::llvm::llvm::TypeRef;
+import lib::llvm::llvm::TypeHandleRef;
+import lib::llvm::llvm::BuilderRef;
+import lib::llvm::llvm::BasicBlockRef;
+
+import lib::llvm::False;
+import lib::llvm::True;
+import lib::llvm::Bool;
state obj namegen(mutable int i) {
fn next(str prefix) -> str {
*
* A "native" is a combination of an extern that references C code, plus a
* glue-code stub that "looks like" a rust function, emitted here, plus a
- * generic N-ary bit of asm glue (found over in back/x86.rs) that performs a
+ * generic N-ary bit of asm glue (found over in back/x86::rs) that performs a
* control transfer into C from rust. Natives may be normal C library code.
*
* An upcall is a native call generated by the compiler (not corresponding to
*
*/
-state type crate_ctxt = rec(session.session sess,
+state type crate_ctxt = rec(session::session sess,
ModuleRef llmod,
target_data td,
type_names tn,
ValueRef crate_ptr,
hashmap[str, ValueRef] externs,
hashmap[str, ValueRef] intrinsics,
- hashmap[ast.def_id, ValueRef] item_ids,
- hashmap[ast.def_id, @ast.item] items,
- hashmap[ast.def_id,
- @ast.native_item] native_items,
- ty.type_cache type_cache,
- hashmap[ast.def_id, str] item_symbols,
+ hashmap[ast::def_id, ValueRef] item_ids,
+ hashmap[ast::def_id, @ast::item] items,
+ hashmap[ast::def_id,
+ @ast::native_item] native_items,
+ ty::type_cache type_cache,
+ hashmap[ast::def_id, str] item_symbols,
// TODO: hashmap[tup(tag_id,subtys), @tag_info]
- hashmap[ty.t, uint] tag_sizes,
- hashmap[ast.def_id, ValueRef] discrims,
- hashmap[ast.def_id, str] discrim_symbols,
- hashmap[ast.def_id, ValueRef] fn_pairs,
- hashmap[ast.def_id, ValueRef] consts,
- hashmap[ast.def_id,()] obj_methods,
- hashmap[ty.t, @tydesc_info] tydescs,
+ hashmap[ty::t, uint] tag_sizes,
+ hashmap[ast::def_id, ValueRef] discrims,
+ hashmap[ast::def_id, str] discrim_symbols,
+ hashmap[ast::def_id, ValueRef] fn_pairs,
+ hashmap[ast::def_id, ValueRef] consts,
+ hashmap[ast::def_id,()] obj_methods,
+ hashmap[ty::t, @tydesc_info] tydescs,
hashmap[str, ValueRef] module_data,
- hashmap[ty.t, TypeRef] lltypes,
+ hashmap[ty::t, TypeRef] lltypes,
@glue_fns glues,
namegen names,
- std.SHA1.sha1 sha,
- hashmap[ty.t, str] type_sha1s,
- hashmap[ty.t, metadata.ty_abbrev] type_abbrevs,
- hashmap[ty.t, str] type_short_names,
- ty.ctxt tcx,
- @upcall.upcalls upcalls);
+ std::sha1::sha1 sha,
+ hashmap[ty::t, str] type_sha1s,
+ hashmap[ty::t, metadata::ty_abbrev] type_abbrevs,
+ hashmap[ty::t, str] type_short_names,
+ ty::ctxt tcx,
+ @upcall::upcalls upcalls);
type local_ctxt = rec(vec[str] path,
vec[str] module_path,
- vec[ast.ty_param] obj_typarams,
- vec[ast.obj_field] obj_fields,
+ vec[ast::ty_param] obj_typarams,
+ vec[ast::obj_field] obj_fields,
@crate_ctxt ccx);
-type self_vt = rec(ValueRef v, ty.t t);
+type self_vt = rec(ValueRef v, ty::t t);
state type fn_ctxt = rec(ValueRef llfn,
ValueRef lltaskptr,
mutable BasicBlockRef llallocas,
mutable BasicBlockRef llcopyargs,
mutable BasicBlockRef llderivedtydescs,
- mutable Option.t[self_vt] llself,
- mutable Option.t[ValueRef] lliterbody,
- hashmap[ast.def_id, ValueRef] llargs,
- hashmap[ast.def_id, ValueRef] llobjfields,
- hashmap[ast.def_id, ValueRef] lllocals,
- hashmap[ast.def_id, ValueRef] llupvars,
+ mutable option::t[self_vt] llself,
+ mutable option::t[ValueRef] lliterbody,
+ hashmap[ast::def_id, ValueRef] llargs,
+ hashmap[ast::def_id, ValueRef] llobjfields,
+ hashmap[ast::def_id, ValueRef] lllocals,
+ hashmap[ast::def_id, ValueRef] llupvars,
mutable vec[ValueRef] lltydescs,
- hashmap[ty.t, derived_tydesc_info] derived_tydescs,
+ hashmap[ty::t, derived_tydesc_info] derived_tydescs,
@local_ctxt lcx);
tag cleanup {
tag block_kind {
SCOPE_BLOCK;
- LOOP_SCOPE_BLOCK(Option.t[@block_ctxt], @block_ctxt);
+ LOOP_SCOPE_BLOCK(option::t[@block_ctxt], @block_ctxt);
NON_SCOPE_BLOCK;
}
mutable vec[cleanup] cleanups,
@fn_ctxt fcx);
-// FIXME: we should be able to use Option.t[@block_parent] here but
+// FIXME: we should be able to use option::t[@block_parent] here but
// the infinite-tag check in rustboot gets upset.
tag block_parent {
}
fn path_name(&vec[str] path) -> str {
- ret Str.connect(path, sep());
+ ret _str::connect(path, sep());
}
-fn get_type_sha1(&@crate_ctxt ccx, &ty.t t) -> str {
+fn get_type_sha1(&@crate_ctxt ccx, &ty::t t) -> str {
auto hash = "";
alt (ccx.type_sha1s.find(t)) {
case (some[str](?h)) { hash = h; }
case (none[str]) {
ccx.sha.reset();
- auto f = metadata.def_to_str;
+ auto f = metadata::def_to_str;
// NB: do *not* use abbrevs here as we want the symbol names
// to be independent of one another in the crate.
- auto cx = @rec(ds=f, tcx=ccx.tcx, abbrevs=metadata.ac_no_abbrevs);
+ auto cx = @rec(ds=f,
+ tcx=ccx.tcx,
+ abbrevs=metadata::ac_no_abbrevs);
- ccx.sha.input_str(metadata.Encode.ty_str(cx, t));
- hash = Str.substr(ccx.sha.result_str(), 0u, 16u);
+ ccx.sha.input_str(metadata::Encode::ty_str(cx, t));
+ hash = _str::substr(ccx.sha.result_str(), 0u, 16u);
ccx.type_sha1s.insert(t, hash);
}
}
ret hash;
}
-fn mangle_name_by_type(&@crate_ctxt ccx, &vec[str] path, &ty.t t) -> str {
+fn mangle_name_by_type(&@crate_ctxt ccx, &vec[str] path, &ty::t t) -> str {
auto hash = get_type_sha1(ccx, t);
ret sep() + "rust" + sep() + hash + sep() + path_name(path);
}
-fn mangle_name_by_type_only(&@crate_ctxt ccx, &ty.t t, &str name) -> str {
- auto f = metadata.def_to_str;
- auto cx = @rec(ds=f, tcx=ccx.tcx, abbrevs=metadata.ac_no_abbrevs);
- auto s = ty.ty_to_short_str(ccx.tcx, t);
+fn mangle_name_by_type_only(&@crate_ctxt ccx, &ty::t t, &str name) -> str {
+ auto f = metadata::def_to_str;
+ auto cx = @rec(ds=f, tcx=ccx.tcx, abbrevs=metadata::ac_no_abbrevs);
+ auto s = ty::ty_to_short_str(ccx.tcx, t);
auto hash = get_type_sha1(ccx, t);
ret sep() + "rust" + sep() + hash + sep() + name + "_" + s;
}
fn ty_str(type_names tn, TypeRef t) -> str {
- ret lib.llvm.type_to_str(tn, t);
+ ret lib::llvm::type_to_str(tn, t);
}
fn val_ty(ValueRef v) -> TypeRef {
- ret llvm.LLVMTypeOf(v);
+ ret llvm::LLVMTypeOf(v);
}
fn val_str(type_names tn, ValueRef v) -> str {
// zero). This makes the result incorrect for now -- things like a tuple
// of 10 nil values will have 10-bit size -- but it doesn't seem like we
// have any other options until it's fixed upstream.
- ret llvm.LLVMVoidType();
+ ret llvm::LLVMVoidType();
}
fn T_nil() -> TypeRef {
// NB: See above in T_void().
- ret llvm.LLVMInt1Type();
+ ret llvm::LLVMInt1Type();
}
fn T_i1() -> TypeRef {
- ret llvm.LLVMInt1Type();
+ ret llvm::LLVMInt1Type();
}
fn T_i8() -> TypeRef {
- ret llvm.LLVMInt8Type();
+ ret llvm::LLVMInt8Type();
}
fn T_i16() -> TypeRef {
- ret llvm.LLVMInt16Type();
+ ret llvm::LLVMInt16Type();
}
fn T_i32() -> TypeRef {
- ret llvm.LLVMInt32Type();
+ ret llvm::LLVMInt32Type();
}
fn T_i64() -> TypeRef {
- ret llvm.LLVMInt64Type();
+ ret llvm::LLVMInt64Type();
}
fn T_f32() -> TypeRef {
- ret llvm.LLVMFloatType();
+ ret llvm::LLVMFloatType();
}
fn T_f64() -> TypeRef {
- ret llvm.LLVMDoubleType();
+ ret llvm::LLVMDoubleType();
}
fn T_bool() -> TypeRef {
}
fn T_fn(vec[TypeRef] inputs, TypeRef output) -> TypeRef {
- ret llvm.LLVMFunctionType(output,
- Vec.buf[TypeRef](inputs),
- Vec.len[TypeRef](inputs),
+ ret llvm::LLVMFunctionType(output,
+ _vec::buf[TypeRef](inputs),
+ _vec::len[TypeRef](inputs),
False);
}
}
fn T_ptr(TypeRef t) -> TypeRef {
- ret llvm.LLVMPointerType(t, 0u);
+ ret llvm::LLVMPointerType(t, 0u);
}
fn T_struct(&vec[TypeRef] elts) -> TypeRef {
- ret llvm.LLVMStructType(Vec.buf[TypeRef](elts),
- Vec.len[TypeRef](elts),
+ ret llvm::LLVMStructType(_vec::buf[TypeRef](elts),
+ _vec::len[TypeRef](elts),
False);
}
fn T_opaque() -> TypeRef {
- ret llvm.LLVMOpaqueType();
+ ret llvm::LLVMOpaqueType();
}
fn T_task(&type_names tn) -> TypeRef {
fn T_tydesc_field(&type_names tn, int field) -> TypeRef {
// Bit of a kludge: pick the fn typeref out of the tydesc..
let vec[TypeRef] tydesc_elts =
- Vec.init_elt[TypeRef](T_nil(), abi.n_tydesc_fields as uint);
- llvm.LLVMGetStructElementTypes(T_tydesc(tn),
- Vec.buf[TypeRef](tydesc_elts));
- auto t = llvm.LLVMGetElementType(tydesc_elts.(field));
+ _vec::init_elt[TypeRef](T_nil(), abi::n_tydesc_fields as uint);
+ llvm::LLVMGetStructElementTypes(T_tydesc(tn),
+ _vec::buf[TypeRef](tydesc_elts));
+ auto t = llvm::LLVMGetElementType(tydesc_elts.(field));
ret t;
}
ret tn.get_type(s);
}
- auto t = T_tydesc_field(tn, abi.tydesc_field_drop_glue);
+ auto t = T_tydesc_field(tn, abi::tydesc_field_drop_glue);
tn.associate(s, t);
ret t;
}
fn T_dtor(&@crate_ctxt ccx, TypeRef llself_ty) -> TypeRef {
- ret type_of_fn_full(ccx, ast.proto_fn, some[TypeRef](llself_ty),
- Vec.empty[ty.arg](), ty.mk_nil(ccx.tcx), 0u);
+ ret type_of_fn_full(ccx, ast::proto_fn, some[TypeRef](llself_ty),
+ _vec::empty[ty::arg](), ty::mk_nil(ccx.tcx), 0u);
}
fn T_cmp_glue_fn(&type_names tn) -> TypeRef {
ret tn.get_type(s);
}
- auto t = T_tydesc_field(tn, abi.tydesc_field_cmp_glue);
+ auto t = T_tydesc_field(tn, abi::tydesc_field_cmp_glue);
tn.associate(s, t);
ret t;
}
}
auto th = mk_type_handle();
- auto abs_tydesc = llvm.LLVMResolveTypeHandle(th.llth);
+ auto abs_tydesc = llvm::LLVMResolveTypeHandle(th.llth);
auto tydescpp = T_ptr(T_ptr(abs_tydesc));
auto pvoid = T_ptr(T_i8());
auto glue_fn_ty = T_ptr(T_fn(vec(T_ptr(T_nil()),
glue_fn_ty, // is_stateful
cmp_glue_fn_ty)); // cmp_glue
- llvm.LLVMRefineType(abs_tydesc, tydesc);
- auto t = llvm.LLVMResolveTypeHandle(th.llth);
+ llvm::LLVMRefineType(abs_tydesc, tydesc);
+ auto t = llvm::LLVMResolveTypeHandle(th.llth);
tn.associate(s, t);
ret t;
}
fn T_array(TypeRef t, uint n) -> TypeRef {
assert (n != 0u);
- ret llvm.LLVMArrayType(t, n);
+ ret llvm::LLVMArrayType(t, n);
}
fn T_vec(TypeRef t) -> TypeRef {
uint n_ty_params) -> 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
+ // an LLVM typeref structure that has the same "shape" as the ty::t
// it constructs.
ret T_ptr(T_box(T_struct(vec(T_ptr(T_tydesc(tn)),
lltarget_ty,
}
fn T_tag(&type_names tn, uint size) -> TypeRef {
- auto s = "tag_" + UInt.to_str(size, 10u);
+ auto s = "tag_" + _uint::to_str(size, 10u);
if (tn.name_has_type(s)) {
ret tn.get_type(s);
}
}
fn T_captured_tydescs(&type_names tn, uint n) -> TypeRef {
- ret T_struct(Vec.init_elt[TypeRef](T_ptr(T_tydesc(tn)), n));
+ ret T_struct(_vec::init_elt[TypeRef](T_ptr(T_tydesc(tn)), n));
}
fn T_obj_ptr(&type_names tn, uint n_captured_tydescs) -> TypeRef {
// return value was always meaningless in that case anyhow). Beware!
//
// TODO: Enforce via a predicate.
-fn type_of(&@crate_ctxt cx, &ty.t t) -> TypeRef {
- if (ty.type_has_dynamic_size(cx.tcx, t)) {
+fn type_of(&@crate_ctxt cx, &ty::t t) -> TypeRef {
+ if (ty::type_has_dynamic_size(cx.tcx, t)) {
log_err "type_of() called on a type with dynamic size: " +
- ty.ty_to_str(cx.tcx, t);
+ ty::ty_to_str(cx.tcx, t);
fail;
}
}
fn type_of_explicit_args(&@crate_ctxt cx,
- &vec[ty.arg] inputs) -> vec[TypeRef] {
+ &vec[ty::arg] inputs) -> vec[TypeRef] {
let vec[TypeRef] atys = vec();
- for (ty.arg arg in inputs) {
- if (ty.type_has_dynamic_size(cx.tcx, arg.ty)) {
- assert (arg.mode == ty.mo_alias);
+ for (ty::arg arg in inputs) {
+ if (ty::type_has_dynamic_size(cx.tcx, arg.ty)) {
+ assert (arg.mode == ty::mo_alias);
atys += vec(T_typaram_ptr(cx.tn));
} else {
let TypeRef t;
alt (arg.mode) {
- case (ty.mo_alias) {
+ case (ty::mo_alias) {
t = T_ptr(type_of_inner(cx, arg.ty));
}
case (_) {
// - trans_args
fn type_of_fn_full(&@crate_ctxt cx,
- ast.proto proto,
- &Option.t[TypeRef] obj_self,
- &vec[ty.arg] inputs,
- &ty.t output,
+ ast::proto proto,
+ &option::t[TypeRef] obj_self,
+ &vec[ty::arg] inputs,
+ &ty::t output,
uint ty_param_count) -> TypeRef {
let vec[TypeRef] atys = vec();
// Arg 0: Output pointer.
- if (ty.type_has_dynamic_size(cx.tcx, output)) {
+ if (ty::type_has_dynamic_size(cx.tcx, output)) {
atys += vec(T_typaram_ptr(cx.tn));
} else {
atys += vec(T_ptr(type_of_inner(cx, output)));
}
- // Arg 1: Task pointer.
+ // Arg 1: task pointer.
atys += vec(T_taskptr(cx.tn));
// Arg 2: Env (closure-bindings / self-obj)
}
}
- 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 +=
vec(T_fn_pair(cx.tn,
- type_of_fn_full(cx, ast.proto_fn, none[TypeRef],
- vec(rec(mode=ty.mo_alias,
+ type_of_fn_full(cx, ast::proto_fn, none[TypeRef],
+ vec(rec(mode=ty::mo_alias,
ty=output)),
- ty.mk_nil(cx.tcx), 0u)));
+ ty::mk_nil(cx.tcx), 0u)));
}
// ... then explicit args.
atys += type_of_explicit_args(cx, inputs);
- ret T_fn(atys, llvm.LLVMVoidType());
+ ret T_fn(atys, llvm::LLVMVoidType());
}
fn type_of_fn(&@crate_ctxt cx,
- ast.proto proto,
- &vec[ty.arg] inputs,
- &ty.t output,
+ ast::proto proto,
+ &vec[ty::arg] inputs,
+ &ty::t output,
uint ty_param_count) -> TypeRef {
ret type_of_fn_full(cx, proto, none[TypeRef], inputs, output,
ty_param_count);
}
-fn type_of_native_fn(&@crate_ctxt cx, ast.native_abi abi,
- &vec[ty.arg] inputs,
- &ty.t output,
+fn type_of_native_fn(&@crate_ctxt cx, ast::native_abi abi,
+ &vec[ty::arg] inputs,
+ &ty::t output,
uint ty_param_count) -> TypeRef {
let vec[TypeRef] atys = vec();
- if (abi == ast.native_abi_rust) {
+ if (abi == ast::native_abi_rust) {
atys += vec(T_taskptr(cx.tn));
- auto t = ty.ty_native_fn(abi, inputs, output);
+ auto t = ty::ty_native_fn(abi, inputs, output);
auto i = 0u;
while (i < ty_param_count) {
atys += vec(T_ptr(T_tydesc(cx.tn)));
ret T_fn(atys, type_of_inner(cx, output));
}
-fn type_of_inner(&@crate_ctxt cx, &ty.t t) -> TypeRef {
+fn type_of_inner(&@crate_ctxt cx, &ty::t 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_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 (ty::struct(cx.tcx, t)) {
+ case (ty::ty_native) { llty = T_ptr(T_i8()); }
+ case (ty::ty_nil) { llty = T_nil(); }
+ 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 (common.ty_i8) { llty = T_i8(); }
- case (common.ty_u8) { llty = T_i8(); }
- case (common.ty_i16) { llty = T_i16(); }
- case (common.ty_u16) { llty = T_i16(); }
- case (common.ty_i32) { llty = T_i32(); }
- case (common.ty_u32) { llty = T_i32(); }
- case (common.ty_i64) { llty = T_i64(); }
- case (common.ty_u64) { llty = T_i64(); }
- case (common.ty_f32) { llty = T_f32(); }
- case (common.ty_f64) { llty = T_f64(); }
+ case (common::ty_i8) { llty = T_i8(); }
+ case (common::ty_u8) { llty = T_i8(); }
+ case (common::ty_i16) { llty = T_i16(); }
+ case (common::ty_u16) { llty = T_i16(); }
+ case (common::ty_i32) { llty = T_i32(); }
+ case (common::ty_u32) { llty = T_i32(); }
+ case (common::ty_i64) { llty = T_i64(); }
+ case (common::ty_u64) { llty = T_i64(); }
+ case (common::ty_f32) { llty = T_f32(); }
+ case (common::ty_f64) { llty = T_f64(); }
}
}
- case (ty.ty_char) { llty = T_char(); }
- case (ty.ty_str) { llty = T_ptr(T_str()); }
- case (ty.ty_tag(_, _)) {
- if (ty.type_has_dynamic_size(cx.tcx, t)) {
+ case (ty::ty_char) { llty = T_char(); }
+ case (ty::ty_str) { llty = T_ptr(T_str()); }
+ case (ty::ty_tag(_, _)) {
+ if (ty::type_has_dynamic_size(cx.tcx, t)) {
llty = T_opaque_tag(cx.tn);
} else {
auto size = static_size_of_tag(cx, t);
llty = T_tag(cx.tn, size);
}
}
- case (ty.ty_box(?mt)) {
+ case (ty::ty_box(?mt)) {
llty = T_ptr(T_box(type_of_inner(cx, mt.ty)));
}
- case (ty.ty_vec(?mt)) {
+ case (ty::ty_vec(?mt)) {
llty = T_ptr(T_vec(type_of_inner(cx, mt.ty)));
}
- case (ty.ty_port(?t)) {
+ case (ty::ty_port(?t)) {
llty = T_ptr(T_port(type_of_inner(cx, t)));
}
- case (ty.ty_chan(?t)) {
+ case (ty::ty_chan(?t)) {
llty = T_ptr(T_chan(type_of_inner(cx, t)));
}
- case (ty.ty_tup(?elts)) {
+ case (ty::ty_tup(?elts)) {
let vec[TypeRef] tys = vec();
- for (ty.mt elt in elts) {
+ for (ty::mt elt in elts) {
tys += vec(type_of_inner(cx, elt.ty));
}
llty = T_struct(tys);
}
- case (ty.ty_rec(?fields)) {
+ case (ty::ty_rec(?fields)) {
let vec[TypeRef] tys = vec();
- for (ty.field f in fields) {
+ for (ty::field f in fields) {
tys += vec(type_of_inner(cx, f.mt.ty));
}
llty = T_struct(tys);
}
- case (ty.ty_fn(?proto, ?args, ?out)) {
+ case (ty::ty_fn(?proto, ?args, ?out)) {
llty = T_fn_pair(cx.tn, type_of_fn(cx, proto, args, out, 0u));
}
- case (ty.ty_native_fn(?abi, ?args, ?out)) {
+ case (ty::ty_native_fn(?abi, ?args, ?out)) {
auto nft = native_fn_wrapper_type(cx, 0u, t);
llty = T_fn_pair(cx.tn, nft);
}
- case (ty.ty_obj(?meths)) {
+ case (ty::ty_obj(?meths)) {
auto th = mk_type_handle();
- auto self_ty = llvm.LLVMResolveTypeHandle(th.llth);
+ auto self_ty = llvm::LLVMResolveTypeHandle(th.llth);
let vec[TypeRef] mtys = vec(T_ptr(T_i8()));
- for (ty.method m in meths) {
+ for (ty::method m in meths) {
let TypeRef mty =
type_of_fn_full(cx, m.proto,
some[TypeRef](self_ty),
let TypeRef pair = T_struct(vec(T_ptr(vtbl),
T_opaque_obj_ptr(cx.tn)));
- auto abs_pair = llvm.LLVMResolveTypeHandle(th.llth);
- llvm.LLVMRefineType(abs_pair, pair);
- abs_pair = llvm.LLVMResolveTypeHandle(th.llth);
+ auto abs_pair = llvm::LLVMResolveTypeHandle(th.llth);
+ llvm::LLVMRefineType(abs_pair, pair);
+ abs_pair = llvm::LLVMResolveTypeHandle(th.llth);
llty = abs_pair;
}
- case (ty.ty_var(_)) {
- log_err "ty_var in trans.type_of";
+ case (ty::ty_var(_)) {
+ log_err "ty_var in trans::type_of";
fail;
}
- case (ty.ty_param(_)) {
+ case (ty::ty_param(_)) {
llty = T_i8();
}
- case (ty.ty_bound_param(_)) {
- log_err "ty_bound_param in trans.type_of";
+ case (ty::ty_bound_param(_)) {
+ log_err "ty_bound_param in trans::type_of";
fail;
}
- case (ty.ty_type) { llty = T_ptr(T_tydesc(cx.tn)); }
+ case (ty::ty_type) { llty = T_ptr(T_tydesc(cx.tn)); }
}
assert (llty as int != 0);
if (cx.sess.get_opts().save_temps) {
- llvm.LLVMAddTypeName(cx.llmod,
- Str.buf(ty.ty_to_short_str(cx.tcx, t)),
+ llvm::LLVMAddTypeName(cx.llmod,
+ _str::buf(ty::ty_to_short_str(cx.tcx, t)),
llty);
}
cx.lltypes.insert(t, llty);
ret llty;
}
-fn type_of_arg(@local_ctxt cx, &ty.arg arg) -> TypeRef {
- alt (ty.struct(cx.ccx.tcx, arg.ty)) {
- case (ty.ty_param(_)) {
- if (arg.mode == ty.mo_alias) {
+fn type_of_arg(@local_ctxt cx, &ty::arg arg) -> TypeRef {
+ alt (ty::struct(cx.ccx.tcx, arg.ty)) {
+ case (ty::ty_param(_)) {
+ if (arg.mode == ty::mo_alias) {
ret T_typaram_ptr(cx.ccx.tn);
}
}
}
auto typ;
- if (arg.mode == ty.mo_alias) {
+ if (arg.mode == ty::mo_alias) {
typ = T_ptr(type_of_inner(cx.ccx, arg.ty));
} else {
typ = type_of_inner(cx.ccx, arg.ty);
}
fn type_of_ty_param_count_and_ty(@local_ctxt lcx,
- &ty.ty_param_count_and_ty tpt) -> TypeRef {
- alt (ty.struct(lcx.ccx.tcx, tpt._1)) {
- case (ty.ty_fn(?proto, ?inputs, ?output)) {
+ &ty::ty_param_count_and_ty tpt) -> TypeRef {
+ alt (ty::struct(lcx.ccx.tcx, tpt._1)) {
+ case (ty::ty_fn(?proto, ?inputs, ?output)) {
auto llfnty = type_of_fn(lcx.ccx, proto, inputs, output, tpt._0);
ret T_fn_pair(lcx.ccx.tn, llfnty);
}
c != (' ' as u8) && c != ('\t' as u8) &&
c != (';' as u8)) {
auto v = vec(c);
- result += Str.from_bytes(v);
+ result += _str::from_bytes(v);
}
}
}
// LLVM constant constructors.
fn C_null(TypeRef t) -> ValueRef {
- ret llvm.LLVMConstNull(t);
+ ret llvm::LLVMConstNull(t);
}
fn C_integral(TypeRef t, uint u, Bool sign_extend) -> ValueRef {
- // FIXME. We can't use LLVM.ULongLong with our existing minimal native
+ // FIXME: We can't use LLVM::ULongLong with our existing minimal native
// API, which only knows word-sized args.
//
- // ret llvm.LLVMConstInt(T_int(), t as LLVM.ULongLong, False);
+ // ret llvm::LLVMConstInt(T_int(), t as LLVM::ULongLong, False);
//
- ret llvm.LLVMRustConstSmallInt(t, u, sign_extend);
+ ret llvm::LLVMRustConstSmallInt(t, u, sign_extend);
}
fn C_float(&str s) -> ValueRef {
- ret llvm.LLVMConstRealOfString(T_float(), Str.buf(s));
+ ret llvm::LLVMConstRealOfString(T_float(), _str::buf(s));
}
fn C_floating(&str s, TypeRef t) -> ValueRef {
- ret llvm.LLVMConstRealOfString(t, Str.buf(s));
+ ret llvm::LLVMConstRealOfString(t, _str::buf(s));
}
fn C_nil() -> ValueRef {
// 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 = llvm.LLVMAddGlobal(cx.llmod, val_ty(sc),
- Str.buf(cx.names.next("str")));
- llvm.LLVMSetInitializer(g, sc);
- llvm.LLVMSetGlobalConstant(g, True);
- llvm.LLVMSetLinkage(g, lib.llvm.LLVMInternalLinkage
- as llvm.Linkage);
+ auto sc = llvm::LLVMConstString(_str::buf(s), _str::byte_len(s), False);
+ auto g = llvm::LLVMAddGlobal(cx.llmod, val_ty(sc),
+ _str::buf(cx.names.next("str")));
+ llvm::LLVMSetInitializer(g, sc);
+ llvm::LLVMSetGlobalConstant(g, True);
+ llvm::LLVMSetLinkage(g, lib::llvm::LLVMInternalLinkage
+ as llvm::Linkage);
ret g;
}
// 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(vec(C_int(abi.const_refcount as int),
+ auto len = _str::byte_len(s);
+ auto box = C_struct(vec(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'
- llvm.LLVMConstString(Str.buf(s),
+ llvm::LLVMConstString(_str::buf(s),
len, False)));
- auto g = llvm.LLVMAddGlobal(cx.llmod, val_ty(box),
- Str.buf(cx.names.next("str")));
- llvm.LLVMSetInitializer(g, box);
- llvm.LLVMSetGlobalConstant(g, True);
- llvm.LLVMSetLinkage(g, lib.llvm.LLVMInternalLinkage
- as llvm.Linkage);
- ret llvm.LLVMConstPointerCast(g, T_ptr(T_str()));
+ auto g = llvm::LLVMAddGlobal(cx.llmod, val_ty(box),
+ _str::buf(cx.names.next("str")));
+ llvm::LLVMSetInitializer(g, box);
+ llvm::LLVMSetGlobalConstant(g, True);
+ llvm::LLVMSetLinkage(g, lib::llvm::LLVMInternalLinkage
+ as llvm::Linkage);
+ ret llvm::LLVMConstPointerCast(g, T_ptr(T_str()));
}
fn C_zero_byte_arr(uint size) -> ValueRef {
elts += vec(C_u8(0u));
i += 1u;
}
- ret llvm.LLVMConstArray(T_i8(), Vec.buf[ValueRef](elts),
- Vec.len[ValueRef](elts));
+ ret llvm::LLVMConstArray(T_i8(), _vec::buf[ValueRef](elts),
+ _vec::len[ValueRef](elts));
}
fn C_struct(&vec[ValueRef] elts) -> ValueRef {
- ret llvm.LLVMConstStruct(Vec.buf[ValueRef](elts),
- Vec.len[ValueRef](elts),
+ ret llvm::LLVMConstStruct(_vec::buf[ValueRef](elts),
+ _vec::len[ValueRef](elts),
False);
}
fn C_array(TypeRef ty, &vec[ValueRef] elts) -> ValueRef {
- ret llvm.LLVMConstArray(ty, Vec.buf[ValueRef](elts),
- Vec.len[ValueRef](elts));
+ ret llvm::LLVMConstArray(ty, _vec::buf[ValueRef](elts),
+ _vec::len[ValueRef](elts));
}
fn decl_fn(ModuleRef llmod, &str name, uint cc, TypeRef llty) -> ValueRef {
let ValueRef llfn =
- llvm.LLVMAddFunction(llmod, Str.buf(name), llty);
- llvm.LLVMSetFunctionCallConv(llfn, cc);
+ llvm::LLVMAddFunction(llmod, _str::buf(name), llty);
+ llvm::LLVMSetFunctionCallConv(llfn, cc);
ret llfn;
}
fn decl_cdecl_fn(ModuleRef llmod, &str name, TypeRef llty) -> ValueRef {
- ret decl_fn(llmod, name, lib.llvm.LLVMCCallConv, llty);
+ ret decl_fn(llmod, name, lib::llvm::LLVMCCallConv, llty);
}
fn decl_fastcall_fn(ModuleRef llmod, &str name, TypeRef llty) -> ValueRef {
- ret decl_fn(llmod, name, lib.llvm.LLVMFastCallConv, llty);
+ ret decl_fn(llmod, name, lib::llvm::LLVMFastCallConv, llty);
}
fn decl_internal_fastcall_fn(ModuleRef llmod,
&str name, TypeRef llty) -> ValueRef {
- auto llfn = decl_fn(llmod, name, lib.llvm.LLVMFastCallConv, llty);
- llvm.LLVMSetLinkage(llfn, lib.llvm.LLVMInternalLinkage as llvm.Linkage);
+ auto llfn = decl_fn(llmod, name, lib::llvm::LLVMFastCallConv, llty);
+ llvm::LLVMSetLinkage(llfn, lib::llvm::LLVMInternalLinkage
+ as llvm::Linkage);
ret llfn;
}
}
fn decl_native_glue(ModuleRef llmod, &type_names tn,
- abi.native_glue_type ngt, uint _n) -> ValueRef {
+ abi::native_glue_type ngt, uint _n) -> ValueRef {
let bool pass_task;
alt (ngt) {
- case (abi.ngt_rust) { pass_task = true; }
- case (abi.ngt_pure_rust) { pass_task = true; }
- case (abi.ngt_cdecl) { pass_task = false; }
+ case (abi::ngt_rust) { pass_task = true; }
+ case (abi::ngt_pure_rust) { pass_task = true; }
+ case (abi::ngt_cdecl) { pass_task = false; }
}
// It doesn't actually matter what type we come up with here, at the
// them to the indirect native-invocation glue. But eventually we'd like
// to call them directly, once we have a calling convention worked out.
let int n = _n as int;
- let str s = abi.native_glue_name(n, ngt);
+ let str s = abi::native_glue_name(n, ngt);
let vec[TypeRef] args = vec(T_int()); // callee
if (!pass_task) {
args += vec(T_int()); // taskptr, will not be passed
}
- args += Vec.init_elt[TypeRef](T_int(), n as uint);
+ args += _vec::init_elt[TypeRef](T_int(), n as uint);
ret decl_fastcall_fn(llmod, s, T_fn(args, T_int()));
}
if (externs.contains_key(name)) {
ret externs.get(name);
}
- auto c = llvm.LLVMAddGlobal(llmod, ty, Str.buf(name));
+ auto 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 = Vec.init_elt[TypeRef](T_int(), n_args as uint);
+ auto inputs = _vec::init_elt[TypeRef](T_int(), n_args as uint);
auto output = T_int();
auto t = T_fn(inputs, output);
- ret get_extern_fn(externs, llmod, name, lib.llvm.LLVMCCallConv, t);
+ 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, &vec[ValueRef] args) -> ValueRef {
- let int n = (Vec.len[ValueRef](args) as int);
+ let int n = (_vec::len[ValueRef](args) as int);
let ValueRef llnative = get_simple_extern_fn(externs, llmod, name, n);
- llnative = llvm.LLVMConstPointerCast(llnative, T_int());
+ llnative = llvm::LLVMConstPointerCast(llnative, T_int());
let ValueRef llglue;
if (pass_task) {
}
fn umax(&@block_ctxt cx, ValueRef a, ValueRef b) -> ValueRef {
- auto cond = cx.build.ICmp(lib.llvm.LLVMIntULT, a, b);
+ auto 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);
+ auto cond = cx.build.ICmp(lib::llvm::LLVMIntULT, a, b);
ret cx.build.Select(cond, a, b);
}
// Returns the real size of the given type for the current target.
fn llsize_of_real(&@crate_ctxt cx, TypeRef t) -> uint {
- ret llvm.LLVMStoreSizeOfType(cx.td.lltd, t);
+ ret llvm::LLVMStoreSizeOfType(cx.td.lltd, t);
}
fn llsize_of(TypeRef t) -> ValueRef {
- ret llvm.LLVMConstIntCast(lib.llvm.llvm.LLVMSizeOf(t), T_int(), False);
+ ret llvm::LLVMConstIntCast(lib::llvm::llvm::LLVMSizeOf(t),
+ T_int(), False);
}
fn llalign_of(TypeRef t) -> ValueRef {
- ret llvm.LLVMConstIntCast(lib.llvm.llvm.LLVMAlignOf(t), T_int(), False);
+ 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(cx.fcx.lcx.ccx.tcx, t)) {
+fn size_of(&@block_ctxt cx, &ty::t t) -> result {
+ if (!ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, t)) {
ret res(cx, llsize_of(type_of(cx.fcx.lcx.ccx, t)));
}
ret dynamic_size_of(cx, t);
}
-fn align_of(&@block_ctxt cx, &ty.t t) -> result {
- if (!ty.type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, t)) {
+fn align_of(&@block_ctxt cx, &ty::t t) -> result {
+ if (!ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, t)) {
ret res(cx, llalign_of(type_of(cx.fcx.lcx.ccx, t)));
}
ret dynamic_align_of(cx, t);
// 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));
+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 (_) { ret typ; }
}
}
auto f = bind simplifier(ccx, _);
- ret ty.fold_ty(ccx.tcx, f, typ);
+ ret ty::fold_ty(ccx.tcx, f, typ);
}
// Computes the size of the data part of a non-dynamically-sized tag.
-fn static_size_of_tag(&@crate_ctxt cx, &ty.t t) -> uint {
- if (ty.type_has_dynamic_size(cx.tcx, t)) {
+fn static_size_of_tag(&@crate_ctxt cx, &ty::t t) -> uint {
+ if (ty::type_has_dynamic_size(cx.tcx, t)) {
log_err "dynamically sized type passed to static_size_of_tag()";
fail;
}
}
auto tid;
- let vec[ty.t] subtys;
- alt (ty.struct(cx.tcx, t)) {
- case (ty.ty_tag(?tid_, ?subtys_)) {
+ let vec[ty::t] subtys;
+ alt (ty::struct(cx.tcx, t)) {
+ case (ty::ty_tag(?tid_, ?subtys_)) {
tid = tid_;
subtys = subtys_;
}
auto max_size = 0u;
auto variants = tag_variants(cx, tid);
for (variant_info variant in variants) {
- auto tup_ty = simplify_type(cx, ty.mk_imm_tup(cx.tcx, variant.args));
+ auto tup_ty = simplify_type(cx, ty::mk_imm_tup(cx.tcx, variant.args));
// Perform any type parameter substitutions.
- tup_ty = ty.bind_params_in_type(cx.tcx, tup_ty);
- tup_ty = ty.substitute_type_params(cx.tcx, subtys, tup_ty);
+ tup_ty = ty::bind_params_in_type(cx.tcx, tup_ty);
+ 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, tup_ty));
ret max_size;
}
-fn dynamic_size_of(&@block_ctxt cx, ty.t t) -> result {
- fn align_elements(&@block_ctxt cx, &vec[ty.t] elts) -> result {
+fn dynamic_size_of(&@block_ctxt cx, ty::t t) -> result {
+ fn align_elements(&@block_ctxt cx, &vec[ty::t] elts) -> result {
//
// C padding rules:
//
auto off = C_int(0);
auto max_align = C_int(1);
auto bcx = cx;
- for (ty.t e in elts) {
+ for (ty::t e in elts) {
auto elt_align = align_of(bcx, e);
bcx = elt_align.bcx;
auto elt_size = size_of(bcx, e);
ret res(bcx, off);
}
- alt (ty.struct(cx.fcx.lcx.ccx.tcx, t)) {
- case (ty.ty_param(?p)) {
- auto szptr = field_of_tydesc(cx, t, false, abi.tydesc_field_size);
+ alt (ty::struct(cx.fcx.lcx.ccx.tcx, t)) {
+ case (ty::ty_param(?p)) {
+ auto szptr = field_of_tydesc(cx, t, false,
+ abi::tydesc_field_size);
ret res(szptr.bcx, szptr.bcx.build.Load(szptr.val));
}
- case (ty.ty_tup(?elts)) {
- let vec[ty.t] tys = vec();
- for (ty.mt mt in elts) {
+ case (ty::ty_tup(?elts)) {
+ let vec[ty::t] tys = vec();
+ for (ty::mt mt in elts) {
tys += vec(mt.ty);
}
ret align_elements(cx, tys);
}
- case (ty.ty_rec(?flds)) {
- let vec[ty.t] tys = vec();
- for (ty.field f in flds) {
+ case (ty::ty_rec(?flds)) {
+ let vec[ty::t] tys = vec();
+ for (ty::field f in flds) {
tys += vec(f.mt.ty);
}
ret align_elements(cx, tys);
}
- case (ty.ty_tag(?tid, ?tps)) {
+ case (ty::ty_tag(?tid, ?tps)) {
auto bcx = cx;
// Compute max(variant sizes).
auto variants = tag_variants(bcx.fcx.lcx.ccx, tid);
for (variant_info variant in variants) {
// Perform type substitution on the raw argument types.
- let vec[ty.t] raw_tys = variant.args;
- let vec[ty.t] tys = vec();
- for (ty.t raw_ty in raw_tys) {
- auto t = ty.bind_params_in_type(cx.fcx.lcx.ccx.tcx,
+ let vec[ty::t] raw_tys = variant.args;
+ let vec[ty::t] tys = vec();
+ for (ty::t raw_ty in raw_tys) {
+ auto t = ty::bind_params_in_type(cx.fcx.lcx.ccx.tcx,
raw_ty);
- t = ty.substitute_type_params(cx.fcx.lcx.ccx.tcx, tps, t);
+ t = ty::substitute_type_params(cx.fcx.lcx.ccx.tcx, tps,
+ t);
tys += vec(t);
}
}
}
-fn dynamic_align_of(&@block_ctxt cx, &ty.t t) -> result {
- alt (ty.struct(cx.fcx.lcx.ccx.tcx, t)) {
- case (ty.ty_param(?p)) {
- auto aptr = field_of_tydesc(cx, t, false, abi.tydesc_field_align);
+fn dynamic_align_of(&@block_ctxt cx, &ty::t t) -> result {
+ alt (ty::struct(cx.fcx.lcx.ccx.tcx, t)) {
+ case (ty::ty_param(?p)) {
+ auto aptr = field_of_tydesc(cx, t, false,
+ abi::tydesc_field_align);
ret res(aptr.bcx, aptr.bcx.build.Load(aptr.val));
}
- case (ty.ty_tup(?elts)) {
+ case (ty::ty_tup(?elts)) {
auto a = C_int(1);
auto bcx = cx;
- for (ty.mt e in elts) {
+ for (ty::mt e in elts) {
auto align = align_of(bcx, e.ty);
bcx = align.bcx;
a = umax(bcx, a, align.val);
}
ret res(bcx, a);
}
- case (ty.ty_rec(?flds)) {
+ case (ty::ty_rec(?flds)) {
auto a = C_int(1);
auto bcx = cx;
- for (ty.field f in flds) {
+ for (ty::field f in flds) {
auto align = align_of(bcx, f.mt.ty);
bcx = align.bcx;
a = umax(bcx, a, align.val);
}
ret res(bcx, a);
}
- case (ty.ty_tag(_, _)) {
+ case (ty::ty_tag(_, _)) {
ret res(cx, C_int(1)); // FIXME: stub
}
}
// Replacement for the LLVM 'GEP' instruction when field-indexing into a
// tuple-like structure (tup, rec) with a static index. This one is driven off
-// ty.struct and knows what to do when it runs into a ty_param stuck in the
+// 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,
+fn GEP_tup_like(&@block_ctxt cx, &ty::t t,
ValueRef base, &vec[int] ixs) -> result {
- assert (ty.type_is_tup_like(cx.fcx.lcx.ccx.tcx, t));
+ assert (ty::type_is_tup_like(cx.fcx.lcx.ccx.tcx, t));
// It might be a static-known type. Handle this.
- if (! ty.type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, t)) {
+ if (! ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, t)) {
let vec[ValueRef] v = vec();
for (int i in ixs) {
v += vec(C_int(i));
// 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, &vec[int] ixs, uint n)
- -> rec(vec[ty.t] prefix, ty.t target) {
+ fn split_type(&@crate_ctxt ccx, &ty::t t, &vec[int] ixs, uint n)
+ -> rec(vec[ty::t] prefix, ty::t target) {
- let uint len = Vec.len[int](ixs);
+ let uint len = _vec::len[int](ixs);
- // We don't support 0-index or 1-index GEPs. The former is nonsense
+ // 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 (n < len);
let int ix = ixs.(n);
- let vec[ty.t] prefix = vec();
+ let vec[ty::t] prefix = vec();
let int i = 0;
while (i < ix) {
- Vec.push[ty.t](prefix,
- ty.get_element_type(ccx.tcx, t, i as uint));
+ _vec::push[ty::t](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);
+ auto selected = ty::get_element_type(ccx.tcx, t, i as uint);
if (n == len-1u) {
// We are at the innermost index.
// flattened the incoming structure.
auto s = split_type(cx.fcx.lcx.ccx, t, ixs, 0u);
- auto prefix_ty = ty.mk_imm_tup(cx.fcx.lcx.ccx.tcx, s.prefix);
+ auto prefix_ty = ty::mk_imm_tup(cx.fcx.lcx.ccx.tcx, s.prefix);
auto bcx = cx;
auto 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, vec(sz.val));
- if (ty.type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, s.target)) {
+ if (ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, s.target)) {
ret res(bcx, bumped);
}
// 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,
- &vec[ty.t] ty_substs,
+ &ast::def_id tag_id,
+ &ast::def_id variant_id,
+ &vec[ty::t] ty_substs,
int ix)
-> result {
auto variant = tag_variant_with_id(cx.fcx.lcx.ccx, 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(cx.fcx.lcx.ccx.tcx); // typestate infelicity
+ auto elem_ty = ty::mk_nil(cx.fcx.lcx.ccx.tcx); // typestate infelicity
auto i = 0;
- let vec[ty.t] true_arg_tys = vec();
- for (ty.t aty in arg_tys) {
- auto arg_ty = ty.bind_params_in_type(cx.fcx.lcx.ccx.tcx, aty);
- arg_ty = ty.substitute_type_params(cx.fcx.lcx.ccx.tcx, ty_substs,
+ let vec[ty::t] true_arg_tys = vec();
+ for (ty::t aty in arg_tys) {
+ auto arg_ty = ty::bind_params_in_type(cx.fcx.lcx.ccx.tcx, aty);
+ arg_ty = ty::substitute_type_params(cx.fcx.lcx.ccx.tcx, ty_substs,
arg_ty);
true_arg_tys += vec(arg_ty);
if (i == ix) {
i += 1;
}
- auto tup_ty = ty.mk_imm_tup(cx.fcx.lcx.ccx.tcx, true_arg_tys);
+ auto tup_ty = ty::mk_imm_tup(cx.fcx.lcx.ccx.tcx, 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(cx.fcx.lcx.ccx.tcx, tup_ty)) {
+ if (!ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, tup_ty)) {
auto llty = type_of(cx.fcx.lcx.ccx, tup_ty);
llunionptr = cx.build.TruncOrBitCast(llblobptr, T_ptr(llty));
} else {
// Cast the result to the appropriate type, if necessary.
auto val;
- if (!ty.type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, elem_ty)) {
+ if (!ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, elem_ty)) {
auto llelemty = type_of(rslt.bcx.fcx.lcx.ccx, elem_ty);
val = rslt.bcx.build.PointerCast(rslt.val, T_ptr(llelemty));
} else {
ret res(cx, cx.build.PointerCast(rval, llptr_ty));
}
-fn trans_malloc_boxed(&@block_ctxt cx, ty.t t) -> result {
+fn trans_malloc_boxed(&@block_ctxt cx, ty::t t) -> result {
// Synthesize a fake box type structurally so we have something
// to measure the size of.
- auto boxed_body = ty.mk_imm_tup(cx.fcx.lcx.ccx.tcx,
- vec(ty.mk_int(cx.fcx.lcx.ccx.tcx), t));
- auto box_ptr = ty.mk_imm_box(cx.fcx.lcx.ccx.tcx, t);
+ auto boxed_body = ty::mk_imm_tup(cx.fcx.lcx.ccx.tcx,
+ vec(ty::mk_int(cx.fcx.lcx.ccx.tcx), t));
+ auto box_ptr = ty::mk_imm_box(cx.fcx.lcx.ccx.tcx, t);
auto sz = size_of(cx, boxed_body);
auto llty = type_of(cx.fcx.lcx.ccx, box_ptr);
ret trans_raw_malloc(sz.bcx, llty, sz.val);
// 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(&@block_ctxt cx, &ty::t t, bool escapes, int field)
-> result {
auto tydesc = get_tydesc(cx, t, escapes);
ret res(tydesc.bcx,
// 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) ->
+fn linearize_ty_params(&@block_ctxt cx, &ty::t t) ->
tup(vec[uint], vec[ValueRef]) {
let vec[ValueRef] param_vals = vec();
let vec[uint] param_defs = vec();
mutable vec[ValueRef] vals,
mutable vec[uint] defs);
- fn linearizer(@rr r, ty.t t) {
- alt(ty.struct(r.cx.fcx.lcx.ccx.tcx, t)) {
- case (ty.ty_param(?pid)) {
+ fn linearizer(@rr r, ty::t t) {
+ alt(ty::struct(r.cx.fcx.lcx.ccx.tcx, t)) {
+ case (ty::ty_param(?pid)) {
let bool seen = false;
for (uint d in r.defs) {
if (d == pid) {
mutable defs = param_defs);
auto f = bind linearizer(x, _);
- ty.walk_ty(cx.fcx.lcx.ccx.tcx, f, t);
+ ty::walk_ty(cx.fcx.lcx.ccx.tcx, f, t);
ret tup(x.defs, x.vals);
}
fn trans_stack_local_derived_tydesc(&@block_ctxt cx, ValueRef llsz,
ValueRef llalign,
ValueRef llroottydesc,
- &Option.t[ValueRef] llparamtydescs)
+ &option::t[ValueRef] llparamtydescs)
-> ValueRef {
auto llmyroottydesc = alloca(cx, T_tydesc(cx.fcx.lcx.ccx.tn));
ret llmyroottydesc;
}
-fn mk_derived_tydesc(&@block_ctxt cx, &ty.t t, bool escapes) -> result {
+fn mk_derived_tydesc(&@block_ctxt cx, &ty::t t, bool escapes) -> result {
alt (cx.fcx.derived_tydescs.find(t)) {
case (some[derived_tydesc_info](?info)) {
// If the tydesc escapes in this context, the cached derived
auto bcx = new_raw_block_ctxt(cx.fcx, cx.fcx.llderivedtydescs);
- let uint n_params = ty.count_ty_params(bcx.fcx.lcx.ccx.tcx, t);
+ let uint n_params = ty::count_ty_params(bcx.fcx.lcx.ccx.tcx, t);
auto tys = linearize_ty_params(bcx, t);
- assert (n_params == Vec.len[uint](tys._0));
- assert (n_params == Vec.len[ValueRef](tys._1));
+ assert (n_params == _vec::len[uint](tys._0));
+ assert (n_params == _vec::len[ValueRef](tys._1));
auto root = get_static_tydesc(bcx, t, tys._0).tydesc;
ret res(cx, v);
}
-fn get_tydesc(&@block_ctxt cx, &ty.t t, bool escapes) -> result {
+fn get_tydesc(&@block_ctxt cx, &ty::t t, bool escapes) -> result {
// Is the supplied type a type param? If so, return the passed-in tydesc.
- alt (ty.type_param(cx.fcx.lcx.ccx.tcx, t)) {
+ alt (ty::type_param(cx.fcx.lcx.ccx.tcx, t)) {
case (some[uint](?id)) { ret res(cx, cx.fcx.lltydescs.(id)); }
case (none[uint]) { /* fall through */ }
}
// Does it contain a type param? If so, generate a derived tydesc.
- if (ty.type_contains_params(cx.fcx.lcx.ccx.tcx, t)) {
+ if (ty::type_contains_params(cx.fcx.lcx.ccx.tcx, t)) {
ret mk_derived_tydesc(cx, t, escapes);
}
}
fn get_static_tydesc(&@block_ctxt cx,
- &ty.t t, &vec[uint] ty_params) -> @tydesc_info {
+ &ty::t t, &vec[uint] ty_params) -> @tydesc_info {
alt (cx.fcx.lcx.ccx.tydescs.find(t)) {
case (some[@tydesc_info](?info)) {
ret info;
// in this file. Experiment with other approaches to this.
/*
- fn simplifier(ty.t typ) -> ty.t {
+ fn simplifier(ty::t typ) -> ty::t {
ret @rec(cname=none[str] with *typ);
}
auto f = simplifier;
- auto t_simplified = ty.fold_ty(cx.fcx.lcx.ccx.tcx, f, t);
+ auto t_simplified = ty::fold_ty(cx.fcx.lcx.ccx.tcx, f, t);
auto info = declare_tydesc(cx.fcx.lcx, t_simplified);
cx.fcx.lcx.ccx.tydescs.insert(t_simplified, info);
*/
// Generates the declaration for (but doesn't fill in) a type descriptor. This
// needs to be separate from make_tydesc() below, because sometimes type glue
// functions needs to refer to their own type descriptors.
-fn declare_tydesc(&@local_ctxt cx, &ty.t t) -> @tydesc_info {
+fn declare_tydesc(&@local_ctxt cx, &ty::t t) -> @tydesc_info {
auto take_glue = declare_generic_glue(cx, t, T_glue_fn(cx.ccx.tn),
"take");
auto drop_glue = declare_generic_glue(cx, t, T_glue_fn(cx.ccx.tn),
auto llsize;
auto llalign;
- if (!ty.type_has_dynamic_size(ccx.tcx, t)) {
+ if (!ty::type_has_dynamic_size(ccx.tcx, t)) {
auto llty = type_of(ccx, t);
llsize = llsize_of(llty);
llalign = llalign_of(llty);
name = mangle_name_by_seq(cx.ccx, cx.path, "tydesc");
}
- auto gvar = llvm.LLVMAddGlobal(ccx.llmod, T_tydesc(ccx.tn),
- Str.buf(name));
+ auto gvar = llvm::LLVMAddGlobal(ccx.llmod, T_tydesc(ccx.tn),
+ _str::buf(name));
auto tydesc = C_struct(vec(C_null(T_ptr(T_ptr(T_tydesc(ccx.tn)))),
llsize,
llalign,
C_null(glue_fn_ty), // is_stateful
cmp_glue)); // cmp_glue
- llvm.LLVMSetInitializer(gvar, tydesc);
- llvm.LLVMSetGlobalConstant(gvar, True);
- llvm.LLVMSetLinkage(gvar, lib.llvm.LLVMInternalLinkage
- as llvm.Linkage);
+ llvm::LLVMSetInitializer(gvar, tydesc);
+ llvm::LLVMSetGlobalConstant(gvar, True);
+ llvm::LLVMSetLinkage(gvar, lib::llvm::LLVMInternalLinkage
+ as llvm::Linkage);
auto info = @rec(
tydesc=gvar,
}
tag make_generic_glue_helper_fn {
- mgghf_single(fn(&@block_ctxt cx, ValueRef v, &ty.t t));
+ mgghf_single(fn(&@block_ctxt cx, ValueRef v, &ty::t t));
mgghf_cmp;
}
// declare_tydesc() above must have been called first.
-fn define_tydesc(&@local_ctxt cx, &ty.t t, &vec[uint] ty_params) {
+fn define_tydesc(&@local_ctxt cx, &ty::t t, &vec[uint] ty_params) {
auto info = cx.ccx.tydescs.get(t);
auto gvar = info.tydesc;
}
fn declare_generic_glue(&@local_ctxt cx,
- &ty.t t,
+ &ty::t t,
TypeRef llfnty,
&str name) -> ValueRef {
auto fn_nm;
}
fn make_generic_glue(&@local_ctxt cx,
- &ty.t t,
+ &ty::t t,
ValueRef llfn,
&make_generic_glue_helper_fn helper,
&vec[uint] ty_params) -> ValueRef {
// passed by value.
auto llty;
- if (ty.type_has_dynamic_size(cx.ccx.tcx, t)) {
+ if (ty::type_has_dynamic_size(cx.ccx.tcx, t)) {
llty = T_ptr(T_i8());
} else {
llty = T_ptr(type_of(cx.ccx, t));
}
- auto ty_param_count = Vec.len[uint](ty_params);
+ auto ty_param_count = _vec::len[uint](ty_params);
- auto lltyparams = llvm.LLVMGetParam(llfn, 3u);
+ auto lltyparams = llvm::LLVMGetParam(llfn, 3u);
auto copy_args_bcx = new_raw_block_ctxt(fcx, fcx.llcopyargs);
- auto lltydescs = Vec.empty_mut[ValueRef]();
+ auto lltydescs = _vec::empty_mut[ValueRef]();
auto p = 0u;
while (p < ty_param_count) {
auto llparam = copy_args_bcx.build.GEP(lltyparams,
vec(C_int(p as int)));
llparam = copy_args_bcx.build.Load(llparam);
- Vec.grow_set[ValueRef](lltydescs, ty_params.(p), 0 as ValueRef,
+ _vec::grow_set[ValueRef](lltydescs, ty_params.(p), 0 as ValueRef,
llparam);
p += 1u;
}
- fcx.lltydescs = Vec.freeze[ValueRef](lltydescs);
+ fcx.lltydescs = _vec::freeze[ValueRef](lltydescs);
auto bcx = new_top_block_ctxt(fcx);
auto lltop = bcx.llbb;
- auto llrawptr0 = llvm.LLVMGetParam(llfn, 4u);
+ auto llrawptr0 = llvm::LLVMGetParam(llfn, 4u);
auto llval0 = bcx.build.BitCast(llrawptr0, llty);
alt (helper) {
single_fn(bcx, llval0, t);
}
case (mgghf_cmp) {
- auto llrawptr1 = llvm.LLVMGetParam(llfn, 5u);
+ auto llrawptr1 = llvm::LLVMGetParam(llfn, 5u);
auto llval1 = bcx.build.BitCast(llrawptr1, llty);
- auto llcmpval = llvm.LLVMGetParam(llfn, 6u);
+ auto llcmpval = llvm::LLVMGetParam(llfn, 6u);
make_cmp_glue(bcx, llval0, llval1, t, llcmpval);
}
ret llfn;
}
-fn make_take_glue(&@block_ctxt cx, ValueRef v, &ty.t t) {
+fn make_take_glue(&@block_ctxt cx, ValueRef v, &ty::t t) {
// NB: v is an *alias* of type t here, not a direct value.
auto bcx;
- if (ty.type_is_boxed(cx.fcx.lcx.ccx.tcx, t)) {
+ if (ty::type_is_boxed(cx.fcx.lcx.ccx.tcx, t)) {
bcx = incr_refcnt_of_boxed(cx, cx.build.Load(v)).bcx;
- } else if (ty.type_is_structural(cx.fcx.lcx.ccx.tcx, t)) {
+ } else if (ty::type_is_structural(cx.fcx.lcx.ccx.tcx, t)) {
bcx = iter_structural_ty(cx, v, t,
bind take_ty(_, _, _)).bcx;
} else {
fn incr_refcnt_of_boxed(&@block_ctxt cx, ValueRef box_ptr) -> result {
auto rc_ptr = cx.build.GEP(box_ptr, vec(C_int(0),
- C_int(abi.box_rc_field_refcnt)));
+ 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 = cx.build.ICmp(lib.llvm.LLVMIntEQ,
- C_int(abi.const_refcount as int), rc);
+ auto 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);
rc = rc_adj_cx.build.Add(rc, C_int(1));
ret res(next_cx, C_nil());
}
-fn make_drop_glue(&@block_ctxt cx, ValueRef v0, &ty.t t) {
+fn make_drop_glue(&@block_ctxt cx, ValueRef v0, &ty::t t) {
// NB: v0 is an *alias* of type t here, not a direct value.
auto rslt;
- alt (ty.struct(cx.fcx.lcx.ccx.tcx, t)) {
- case (ty.ty_str) {
+ alt (ty::struct(cx.fcx.lcx.ccx.tcx, t)) {
+ case (ty::ty_str) {
auto v = cx.build.Load(v0);
rslt = decr_refcnt_and_if_zero
(cx, v, bind trans_non_gc_free(_, v),
T_int(), C_int(0));
}
- case (ty.ty_vec(_)) {
+ case (ty::ty_vec(_)) {
fn hit_zero(&@block_ctxt cx, ValueRef v,
- ty.t t) -> result {
+ ty::t t) -> result {
auto res = iter_sequence(cx, v, t,
bind drop_ty(_,_,_));
// FIXME: switch gc/non-gc on layer of the type.
T_int(), C_int(0));
}
- case (ty.ty_box(?body_mt)) {
+ case (ty::ty_box(?body_mt)) {
fn hit_zero(&@block_ctxt cx, ValueRef v,
- ty.t body_ty) -> result {
+ ty::t body_ty) -> result {
auto body = cx.build.GEP(v,
vec(C_int(0),
- C_int(abi.box_rc_field_body)));
+ C_int(abi::box_rc_field_body)));
auto body_val = load_if_immediate(cx, body, body_ty);
auto res = drop_ty(cx, body_val, body_ty);
T_int(), C_int(0));
}
- case (ty.ty_port(_)) {
+ case (ty::ty_port(_)) {
fn hit_zero(&@block_ctxt cx, ValueRef v) -> result {
cx.build.Call(cx.fcx.lcx.ccx.upcalls.del_port,
vec(cx.fcx.lltaskptr,
T_int(), C_int(0));
}
- case (ty.ty_chan(_)) {
+ case (ty::ty_chan(_)) {
fn hit_zero(&@block_ctxt cx, ValueRef v) -> result {
cx.build.Call(cx.fcx.lcx.ccx.upcalls.del_chan,
vec(cx.fcx.lltaskptr,
T_int(), C_int(0));
}
- case (ty.ty_obj(_)) {
+ case (ty::ty_obj(_)) {
fn hit_zero(&@block_ctxt cx, ValueRef b, ValueRef o) -> result {
auto body =
cx.build.GEP(b,
vec(C_int(0),
- C_int(abi.box_rc_field_body)));
+ C_int(abi::box_rc_field_body)));
auto tydescptr =
cx.build.GEP(body,
vec(C_int(0),
- C_int(abi.obj_body_elt_tydesc)));
+ C_int(abi::obj_body_elt_tydesc)));
auto tydesc = cx.build.Load(tydescptr);
auto cx_ = maybe_call_dtor(cx, o);
// Call through the obj's own fields-drop glue first.
call_tydesc_glue_full(cx_, body, tydesc,
- abi.tydesc_field_drop_glue);
+ abi::tydesc_field_drop_glue);
// Then free the body.
// FIXME: switch gc/non-gc on layer of the type.
auto box_cell =
cx.build.GEP(v0,
vec(C_int(0),
- C_int(abi.obj_field_box)));
+ C_int(abi::obj_field_box)));
auto boxptr = cx.build.Load(box_cell);
T_int(), C_int(0));
}
- case (ty.ty_fn(_,_,_)) {
+ case (ty::ty_fn(_,_,_)) {
fn hit_zero(&@block_ctxt cx, ValueRef v) -> result {
// Call through the closure's own fields-drop glue first.
auto body =
cx.build.GEP(v,
vec(C_int(0),
- C_int(abi.box_rc_field_body)));
+ C_int(abi::box_rc_field_body)));
auto bindings =
cx.build.GEP(body,
vec(C_int(0),
- C_int(abi.closure_elt_bindings)));
+ C_int(abi::closure_elt_bindings)));
auto tydescptr =
cx.build.GEP(body,
vec(C_int(0),
- C_int(abi.closure_elt_tydesc)));
+ C_int(abi::closure_elt_tydesc)));
call_tydesc_glue_full(cx, bindings, cx.build.Load(tydescptr),
- abi.tydesc_field_drop_glue);
+ abi::tydesc_field_drop_glue);
// Then free the body.
auto box_cell =
cx.build.GEP(v0,
vec(C_int(0),
- C_int(abi.fn_field_box)));
+ C_int(abi::fn_field_box)));
auto boxptr = cx.build.Load(box_cell);
}
case (_) {
- if (ty.type_is_structural(cx.fcx.lcx.ccx.tcx, t)) {
+ if (ty::type_is_structural(cx.fcx.lcx.ccx.tcx, t)) {
rslt = iter_structural_ty(cx, v0, t,
bind drop_ty(_, _, _));
- } else if (ty.type_is_scalar(cx.fcx.lcx.ccx.tcx, t) ||
- ty.type_is_native(cx.fcx.lcx.ccx.tcx, t) ||
- ty.type_is_nil(cx.fcx.lcx.ccx.tcx, t)) {
+ } else if (ty::type_is_scalar(cx.fcx.lcx.ccx.tcx, t) ||
+ ty::type_is_native(cx.fcx.lcx.ccx.tcx, t) ||
+ ty::type_is_nil(cx.fcx.lcx.ccx.tcx, t)) {
rslt = res(cx, C_nil());
} else {
rslt = res(cx, C_nil());
auto rc_ptr = load_rc_cx.build.GEP(box_ptr,
vec(C_int(0),
- C_int(abi.box_rc_field_refcnt)));
+ C_int(abi::box_rc_field_refcnt)));
auto rc = load_rc_cx.build.Load(rc_ptr);
auto const_test =
- load_rc_cx.build.ICmp(lib.llvm.LLVMIntEQ,
- C_int(abi.const_refcount as int), rc);
+ 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);
+ auto zero_test = rc_adj_cx.build.ICmp(lib::llvm::LLVMIntEQ, C_int(0), rc);
rc_adj_cx.build.CondBr(zero_test, inner_cx.llbb, next_cx.llbb);
auto inner_res = inner(inner_cx);
fn maybe_name_value(&@crate_ctxt cx, ValueRef v, &str s) {
if (cx.sess.get_opts().save_temps) {
- llvm.LLVMSetValueName(v, Str.buf(s));
+ llvm::LLVMSetValueName(v, _str::buf(s));
}
}
fn make_cmp_glue(&@block_ctxt cx,
ValueRef lhs0,
ValueRef rhs0,
- &ty.t t,
+ &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(cx.fcx.lcx.ccx.tcx, t)) {
+ if (ty::type_is_scalar(cx.fcx.lcx.ccx.tcx, t)) {
make_scalar_cmp_glue(cx, lhs, rhs, t, llop);
- } else if (ty.type_is_box(cx.fcx.lcx.ccx.tcx, t)) {
- lhs = cx.build.GEP(lhs, vec(C_int(0), C_int(abi.box_rc_field_body)));
- rhs = cx.build.GEP(rhs, vec(C_int(0), C_int(abi.box_rc_field_body)));
+ } else if (ty::type_is_box(cx.fcx.lcx.ccx.tcx, t)) {
+ lhs = cx.build.GEP(lhs, vec(C_int(0), C_int(abi::box_rc_field_body)));
+ rhs = cx.build.GEP(rhs, vec(C_int(0), C_int(abi::box_rc_field_body)));
auto rslt = call_cmp_glue(cx, lhs, rhs, t, llop);
rslt.bcx.build.Store(rslt.val, cx.fcx.llretptr);
rslt.bcx.build.RetVoid();
- } else if (ty.type_is_structural(cx.fcx.lcx.ccx.tcx, t)
- || ty.type_is_sequence(cx.fcx.lcx.ccx.tcx, t)) {
+ } else if (ty::type_is_structural(cx.fcx.lcx.ccx.tcx, t)
+ || ty::type_is_sequence(cx.fcx.lcx.ccx.tcx, t)) {
auto scx = new_sub_block_ctxt(cx, "structural compare start");
auto next = new_sub_block_ctxt(cx, "structural compare end");
* !=, < and >.
*
* We then move one element at a time through the structure checking
- * for pairwise element equality. If we have equality, our assumption
+ * for pairwise element equality: If we have equality, our assumption
* about overall sequence equality is not modified, so we have to move
* to the next element.
*
maybe_name_value(cx.fcx.lcx.ccx, flag, "flag");
auto r;
- if (ty.type_is_sequence(cx.fcx.lcx.ccx.tcx, t)) {
+ if (ty::type_is_sequence(cx.fcx.lcx.ccx.tcx, t)) {
// If we hit == all the way through the minimum-shared-length
// section, default to judging the relative sequence lengths.
} else {
// == and <= default to true if they find == all the way. <
// defaults to false if it finds == all the way.
- auto result_if_equal = scx.build.ICmp(lib.llvm.LLVMIntNE, llop,
- C_u8(abi.cmp_glue_op_lt));
+ auto 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 = res(scx, C_nil());
}
&@block_ctxt cx,
ValueRef av0,
ValueRef bv0,
- ty.t t) -> result {
+ ty::t t) -> result {
auto cnt_cx = new_sub_block_ctxt(cx, "continue_comparison");
auto stop_cx = new_sub_block_ctxt(cx, "stop_comparison");
// 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(last_cx.fcx.lcx.ccx.tcx, t)) {
+ if (!ty::type_has_dynamic_size(last_cx.fcx.lcx.ccx.tcx, t)) {
auto llelemty = T_ptr(type_of(last_cx.fcx.lcx.ccx, t));
av = cx.build.PointerCast(av, llelemty);
bv = cx.build.PointerCast(bv, llelemty);
// First 'eq' comparison: if so, continue to next elts.
auto eq_r = call_cmp_glue(cx, av, bv, t,
- C_u8(abi.cmp_glue_op_eq));
+ 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.
ret res(cnt_cx, C_nil());
}
- if (ty.type_is_structural(cx.fcx.lcx.ccx.tcx, t)) {
+ if (ty::type_is_structural(cx.fcx.lcx.ccx.tcx, t)) {
r = iter_structural_ty_full(r.bcx, lhs, rhs, t,
bind inner(next, false, flag, llop,
_, _, _, _));
auto min_len = umin(r.bcx, vec_fill(r.bcx, lhs),
vec_fill(r.bcx, rhs));
auto rhs_lim = r.bcx.build.GEP(rhs_p0, vec(min_len));
- auto elt_ty = ty.sequence_element_type(cx.fcx.lcx.ccx.tcx, t);
+ auto elt_ty = ty::sequence_element_type(cx.fcx.lcx.ccx.tcx, t);
r = size_of(r.bcx, elt_ty);
r = iter_sequence_raw(r.bcx, lhs_p0, rhs_p0, rhs_lim, r.val,
bind inner(next, true, flag, llop,
} else {
// FIXME: compare obj, fn by pointer?
- trans_fail(cx, none[common.span],
+ trans_fail(cx, none[common::span],
"attempt to compare values of type " +
- ty.ty_to_str(cx.fcx.lcx.ccx.tcx, t));
+ ty::ty_to_str(cx.fcx.lcx.ccx.tcx, t));
}
}
// 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) {
- if (ty.type_is_fp(cx.fcx.lcx.ccx.tcx, t)) {
+ &ty::t t, ValueRef llop) {
+ if (ty::type_is_fp(cx.fcx.lcx.ccx.tcx, t)) {
make_fp_cmp_glue(cx, lhs, rhs, t, llop);
ret;
}
- if (ty.type_is_integral(cx.fcx.lcx.ccx.tcx, t) ||
- ty.type_is_bool(cx.fcx.lcx.ccx.tcx, t)) {
+ if (ty::type_is_integral(cx.fcx.lcx.ccx.tcx, t) ||
+ ty::type_is_bool(cx.fcx.lcx.ccx.tcx, t)) {
make_integral_cmp_glue(cx, lhs, rhs, t, llop);
ret;
}
- if (ty.type_is_nil(cx.fcx.lcx.ccx.tcx, t)) {
+ if (ty::type_is_nil(cx.fcx.lcx.ccx.tcx, t)) {
cx.build.Store(C_bool(true), cx.fcx.llretptr);
cx.build.RetVoid();
ret;
}
- trans_fail(cx, none[common.span],
+ trans_fail(cx, none[common::span],
"attempt to compare values of type " +
- ty.ty_to_str(cx.fcx.lcx.ccx.tcx, t));
+ ty::ty_to_str(cx.fcx.lcx.ccx.tcx, t));
}
// A helper function to create floating point comparison glue.
fn make_fp_cmp_glue(&@block_ctxt cx, ValueRef lhs, ValueRef rhs,
- &ty.t fptype, ValueRef llop) {
+ &ty::t fptype, ValueRef llop) {
auto last_cx = new_sub_block_ctxt(cx, "last");
auto eq_cx = new_sub_block_ctxt(cx, "eq");
- auto eq_result = eq_cx.build.FCmp(lib.llvm.LLVMRealUEQ, lhs, rhs);
+ auto eq_result = eq_cx.build.FCmp(lib::llvm::LLVMRealUEQ, lhs, rhs);
eq_cx.build.Br(last_cx.llbb);
auto lt_cx = new_sub_block_ctxt(cx, "lt");
- auto lt_result = lt_cx.build.FCmp(lib.llvm.LLVMRealULT, lhs, rhs);
+ auto lt_result = lt_cx.build.FCmp(lib::llvm::LLVMRealULT, lhs, rhs);
lt_cx.build.Br(last_cx.llbb);
auto le_cx = new_sub_block_ctxt(cx, "le");
- auto le_result = le_cx.build.FCmp(lib.llvm.LLVMRealULE, lhs, rhs);
+ auto le_result = le_cx.build.FCmp(lib::llvm::LLVMRealULE, lhs, rhs);
le_cx.build.Br(last_cx.llbb);
auto unreach_cx = new_sub_block_ctxt(cx, "unreach");
unreach_cx.build.Unreachable();
auto 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);
+ 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 =
last_cx.build.Phi(T_i1(), vec(eq_result, lt_result, le_result),
bool signed, ValueRef llop) -> result {
auto lt_cmp; auto le_cmp;
if (signed) {
- lt_cmp = lib.llvm.LLVMIntSLT;
- le_cmp = lib.llvm.LLVMIntSLE;
+ lt_cmp = lib::llvm::LLVMIntSLT;
+ le_cmp = lib::llvm::LLVMIntSLE;
} else {
- lt_cmp = lib.llvm.LLVMIntULT;
- le_cmp = lib.llvm.LLVMIntULE;
+ lt_cmp = lib::llvm::LLVMIntULT;
+ le_cmp = lib::llvm::LLVMIntULE;
}
auto last_cx = new_sub_block_ctxt(cx, "last");
auto eq_cx = new_sub_block_ctxt(cx, "eq");
- auto eq_result = eq_cx.build.ICmp(lib.llvm.LLVMIntEQ, lhs, rhs);
+ auto eq_result = eq_cx.build.ICmp(lib::llvm::LLVMIntEQ, lhs, rhs);
eq_cx.build.Br(last_cx.llbb);
auto lt_cx = new_sub_block_ctxt(cx, "lt");
unreach_cx.build.Unreachable();
auto 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);
+ 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 =
last_cx.build.Phi(T_i1(), vec(eq_result, lt_result, le_result),
// A helper function to create integral comparison glue.
fn make_integral_cmp_glue(&@block_ctxt cx, ValueRef lhs, ValueRef rhs,
- &ty.t intype, ValueRef llop) {
+ &ty::t intype, ValueRef llop) {
auto r = compare_integral_values(cx, lhs, rhs,
- ty.type_is_signed(cx.fcx.lcx.ccx.tcx, intype), llop);
+ ty::type_is_signed(cx.fcx.lcx.ccx.tcx, intype), llop);
r.bcx.build.Store(r.val, r.bcx.fcx.llretptr);
r.bcx.build.RetVoid();
}
// Tag information
-type variant_info = rec(vec[ty.t] args, ty.t ctor_ty, ast.def_id id);
+type variant_info = rec(vec[ty::t] args, ty::t ctor_ty, ast::def_id id);
// Returns information about the variants in a tag.
-fn tag_variants(&@crate_ctxt cx, &ast.def_id id) -> vec[variant_info] {
+fn tag_variants(&@crate_ctxt cx, &ast::def_id id) -> vec[variant_info] {
if (cx.sess.get_targ_crate_num() != id._0) {
- ret creader.get_tag_variants(cx.sess, cx.tcx, id);
+ ret creader::get_tag_variants(cx.sess, cx.tcx, id);
}
assert (cx.items.contains_key(id));
alt (cx.items.get(id).node) {
- case (ast.item_tag(_, ?variants, _, _, _)) {
+ case (ast::item_tag(_, ?variants, _, _, _)) {
let vec[variant_info] result = vec();
- for (ast.variant variant in variants) {
+ for (ast::variant variant in variants) {
auto ctor_ty = node_ann_type(cx, variant.node.ann);
- let vec[ty.t] arg_tys = vec();
- if (Vec.len[ast.variant_arg](variant.node.args) > 0u) {
- for (ty.arg a in ty.ty_fn_args(cx.tcx, ctor_ty)) {
+ let vec[ty::t] arg_tys = vec();
+ if (_vec::len[ast::variant_arg](variant.node.args) > 0u) {
+ for (ty::arg a in ty::ty_fn_args(cx.tcx, ctor_ty)) {
arg_tys += vec(a.ty);
}
}
fail; // not reached
}
-// Returns information about the tag variant with the given ID.
+// Returns information about the tag variant with the given ID:
fn tag_variant_with_id(&@crate_ctxt cx,
- &ast.def_id tag_id,
- &ast.def_id variant_id) -> variant_info {
+ &ast::def_id tag_id,
+ &ast::def_id variant_id) -> variant_info {
auto variants = tag_variants(cx, tag_id);
auto i = 0u;
- while (i < Vec.len[variant_info](variants)) {
+ while (i < _vec::len[variant_info](variants)) {
auto variant = variants.(i);
- if (common.def_eq(variant.id, variant_id)) {
+ if (common::def_eq(variant.id, variant_id)) {
ret variant;
}
i += 1u;
type val_pair_fn = fn(&@block_ctxt cx, ValueRef dst, ValueRef src) -> result;
-type val_and_ty_fn = fn(&@block_ctxt cx, ValueRef v, ty.t t) -> result;
+type val_and_ty_fn = fn(&@block_ctxt cx, ValueRef v, ty::t t) -> result;
type val_pair_and_ty_fn =
- fn(&@block_ctxt cx, ValueRef av, ValueRef bv, ty.t t) -> result;
+ fn(&@block_ctxt cx, ValueRef av, ValueRef bv, ty::t t) -> result;
// Iterates through the elements of a structural type.
fn iter_structural_ty(&@block_ctxt cx,
ValueRef v,
- &ty.t t,
+ &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 {
+ ty::t t) -> result {
ret f(cx, av, t);
}
be iter_structural_ty_full(cx, v, v, t,
fn iter_structural_ty_full(&@block_ctxt cx,
ValueRef av,
ValueRef bv,
- &ty.t t,
+ &ty::t t,
&val_pair_and_ty_fn f)
-> result {
let result r = res(cx, C_nil());
&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(cx.fcx.lcx.ccx.tcx);
- auto tbox = ty.mk_imm_box(cx.fcx.lcx.ccx.tcx, tnil);
+ auto tnil = ty::mk_nil(cx.fcx.lcx.ccx.tcx);
+ auto tbox = ty::mk_imm_box(cx.fcx.lcx.ccx.tcx, tnil);
auto inner_cx = new_sub_block_ctxt(cx, "iter box");
auto next_cx = new_sub_block_ctxt(cx, "next");
ret res(next_cx, C_nil());
}
- alt (ty.struct(cx.fcx.lcx.ccx.tcx, t)) {
- case (ty.ty_tup(?args)) {
+ alt (ty::struct(cx.fcx.lcx.ccx.tcx, t)) {
+ case (ty::ty_tup(?args)) {
let int i = 0;
- for (ty.mt arg in args) {
+ for (ty::mt arg in args) {
r = GEP_tup_like(r.bcx, t, av, vec(0, i));
auto elt_a = r.val;
r = GEP_tup_like(r.bcx, t, bv, vec(0, i));
i += 1;
}
}
- case (ty.ty_rec(?fields)) {
+ case (ty::ty_rec(?fields)) {
let int i = 0;
- for (ty.field fld in fields) {
+ for (ty::field fld in fields) {
r = GEP_tup_like(r.bcx, t, av, vec(0, i));
auto llfld_a = r.val;
r = GEP_tup_like(r.bcx, t, bv, vec(0, i));
i += 1;
}
}
- case (ty.ty_tag(?tid, ?tps)) {
+ case (ty::ty_tag(?tid, ?tps)) {
auto variants = tag_variants(cx.fcx.lcx.ccx, tid);
- auto n_variants = Vec.len[variant_info](variants);
+ auto n_variants = _vec::len[variant_info](variants);
// Cast the tags to types we can GEP into.
auto lltagty = T_opaque_tag_ptr(cx.fcx.lcx.ccx.tn);
// comparison know not to proceed when the discriminants differ.
auto bcx = cx;
bcx = f(bcx, lldiscrim_a, lldiscrim_b,
- ty.mk_int(cx.fcx.lcx.ccx.tcx)).bcx;
+ ty::mk_int(cx.fcx.lcx.ccx.tcx)).bcx;
auto unr_cx = new_sub_block_ctxt(bcx, "tag-iter-unr");
unr_cx.build.Unreachable();
for (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);
+ _uint::to_str(i, 10u));
+ llvm::LLVMAddCase(llswitch, C_int(i as int), variant_cx.llbb);
- if (Vec.len[ty.t](variant.args) > 0u) {
+ if (_vec::len[ty::t](variant.args) > 0u) {
// N-ary variant.
auto fn_ty = variant.ctor_ty;
- alt (ty.struct(bcx.fcx.lcx.ccx.tcx, fn_ty)) {
- case (ty.ty_fn(_, ?args, _)) {
+ alt (ty::struct(bcx.fcx.lcx.ccx.tcx, fn_ty)) {
+ case (ty::ty_fn(_, ?args, _)) {
auto j = 0;
- for (ty.arg a in args) {
+ for (ty::arg a in args) {
auto v = vec(C_int(0), C_int(j as int));
auto rslt = GEP_tag(variant_cx, llunion_a_ptr,
auto llfldp_b = rslt.val;
variant_cx = rslt.bcx;
- auto ty_subst = ty.bind_params_in_type(
+ auto ty_subst = ty::bind_params_in_type(
cx.fcx.lcx.ccx.tcx, a.ty);
- ty_subst = ty.substitute_type_params(
+ ty_subst = ty::substitute_type_params(
cx.fcx.lcx.ccx.tcx, tps, ty_subst);
auto llfld_a =
ret res(next_cx, C_nil());
}
- case (ty.ty_fn(_,_,_)) {
+ case (ty::ty_fn(_,_,_)) {
auto box_cell_a =
cx.build.GEP(av,
vec(C_int(0),
- C_int(abi.fn_field_box)));
+ C_int(abi::fn_field_box)));
auto box_cell_b =
cx.build.GEP(bv,
vec(C_int(0),
- C_int(abi.fn_field_box)));
+ C_int(abi::fn_field_box)));
ret iter_boxpp(cx, box_cell_a, box_cell_b, f);
}
- case (ty.ty_obj(_)) {
+ case (ty::ty_obj(_)) {
auto box_cell_a =
cx.build.GEP(av,
vec(C_int(0),
- C_int(abi.obj_field_box)));
+ C_int(abi::obj_field_box)));
auto box_cell_b =
cx.build.GEP(bv,
vec(C_int(0),
- C_int(abi.obj_field_box)));
+ C_int(abi::obj_field_box)));
ret iter_boxpp(cx, box_cell_a, box_cell_b, f);
}
case (_) {
let ValueRef src_curr = cond_cx.build.Phi(T_int(),
vec(src_int), vec(bcx.llbb));
- auto end_test = cond_cx.build.ICmp(lib.llvm.LLVMIntULT,
+ auto 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);
fn iter_sequence_inner(&@block_ctxt cx,
ValueRef src, // elt*
ValueRef src_lim, // elt*
- &ty.t elt_ty,
+ &ty::t elt_ty,
&val_and_ty_fn f) -> result {
fn adaptor_fn(val_and_ty_fn f,
- ty.t elt_ty,
+ ty::t elt_ty,
&@block_ctxt cx,
ValueRef dst,
ValueRef src) -> result {
auto llptrty;
- if (!ty.type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, elt_ty)) {
+ if (!ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, elt_ty)) {
auto llty = type_of(cx.fcx.lcx.ccx, elt_ty);
llptrty = T_ptr(llty);
} else {
// Iterates through the elements of a vec or str.
fn iter_sequence(@block_ctxt cx,
ValueRef v,
- &ty.t t,
+ &ty::t t,
&val_and_ty_fn f) -> result {
fn iter_sequence_body(@block_ctxt cx,
ValueRef v,
- &ty.t elt_ty,
+ &ty::t elt_ty,
&val_and_ty_fn f,
bool trailing_null) -> result {
auto p0 = cx.build.GEP(v, vec(C_int(0),
- C_int(abi.vec_elt_data)));
+ C_int(abi::vec_elt_data)));
auto lenptr = cx.build.GEP(v, vec(C_int(0),
- C_int(abi.vec_elt_fill)));
+ C_int(abi::vec_elt_fill)));
auto llunit_ty;
- if (ty.type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, elt_ty)) {
+ if (ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, elt_ty)) {
llunit_ty = T_i8();
} else {
llunit_ty = type_of(cx.fcx.lcx.ccx, elt_ty);
ret iter_sequence_inner(bcx, p0, p1, elt_ty, f);
}
- alt (ty.struct(cx.fcx.lcx.ccx.tcx, t)) {
- case (ty.ty_vec(?elt)) {
+ alt (ty::struct(cx.fcx.lcx.ccx.tcx, t)) {
+ case (ty::ty_vec(?elt)) {
ret iter_sequence_body(cx, v, elt.ty, f, false);
}
- case (ty.ty_str) {
- auto et = ty.mk_mach(cx.fcx.lcx.ccx.tcx, common.ty_u8);
+ case (ty::ty_str) {
+ auto et = ty::mk_mach(cx.fcx.lcx.ccx.tcx, common::ty_u8);
ret iter_sequence_body(cx, v, et, f, true);
}
case (_) { fail; }
}
- cx.fcx.lcx.ccx.sess.bug("bad type in trans.iter_sequence");
+ cx.fcx.lcx.ccx.sess.bug("bad type in trans::iter_sequence");
fail;
}
auto llrawptr = cx.build.BitCast(v, T_ptr(T_i8()));
auto lltydescs = cx.build.GEP(tydesc,
vec(C_int(0),
- C_int(abi.tydesc_field_first_param)));
+ C_int(abi::tydesc_field_first_param)));
lltydescs = cx.build.Load(lltydescs);
auto llfnptr = cx.build.GEP(tydesc, vec(C_int(0), C_int(field)));
auto llfn = cx.build.Load(llfnptr);
}
fn call_tydesc_glue(&@block_ctxt cx, ValueRef v,
- &ty.t t, bool escapes, int field) -> result {
+ &ty::t t, bool escapes, int field) -> result {
auto td = get_tydesc(cx, t, escapes);
call_tydesc_glue_full(td.bcx,
spill_if_immediate(td.bcx, v, t),
}
fn maybe_call_dtor(&@block_ctxt cx, ValueRef v) -> @block_ctxt {
- auto vtbl = cx.build.GEP(v, vec(C_int(0), C_int(abi.obj_field_vtbl)));
+ auto vtbl = cx.build.GEP(v, vec(C_int(0), C_int(abi::obj_field_vtbl)));
vtbl = cx.build.Load(vtbl);
auto dtor_ptr = cx.build.GEP(vtbl, vec(C_int(0), C_int(0)));
dtor_ptr = cx.build.Load(dtor_ptr);
- auto self_t = llvm.LLVMGetElementType(val_ty(v));
+ auto self_t = llvm::LLVMGetElementType(val_ty(v));
dtor_ptr = cx.build.BitCast(dtor_ptr,
T_ptr(T_dtor(cx.fcx.lcx.ccx, self_t)));
auto dtor_cx = new_sub_block_ctxt(cx, "dtor");
auto after_cx = new_sub_block_ctxt(cx, "after_dtor");
- auto test = cx.build.ICmp(lib.llvm.LLVMIntNE, dtor_ptr,
+ auto 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);
fn call_cmp_glue(&@block_ctxt cx,
ValueRef lhs,
ValueRef rhs,
- &ty.t t,
+ &ty::t t,
ValueRef llop) -> result {
// We can't use call_tydesc_glue_full() and friends here because compare
// glue has a special signature.
auto r = get_tydesc(cx, t, false);
auto lltydescs =
r.bcx.build.GEP(r.val, vec(C_int(0),
- C_int(abi.tydesc_field_first_param)));
+ C_int(abi::tydesc_field_first_param)));
lltydescs = r.bcx.build.Load(lltydescs);
auto llfnptr =
r.bcx.build.GEP(r.val, vec(C_int(0),
- C_int(abi.tydesc_field_cmp_glue)));
+ C_int(abi::tydesc_field_cmp_glue)));
auto llfn = r.bcx.build.Load(llfnptr);
auto llcmpresultptr = r.bcx.build.Alloca(T_i1());
ret res(r.bcx, r.bcx.build.Load(llcmpresultptr));
}
-fn take_ty(&@block_ctxt cx, ValueRef v, ty.t t) -> result {
- if (!ty.type_is_scalar(cx.fcx.lcx.ccx.tcx, t)) {
- ret call_tydesc_glue(cx, v, t, false, abi.tydesc_field_take_glue);
+fn take_ty(&@block_ctxt cx, ValueRef v, ty::t t) -> result {
+ if (!ty::type_is_scalar(cx.fcx.lcx.ccx.tcx, t)) {
+ ret call_tydesc_glue(cx, v, t, false, abi::tydesc_field_take_glue);
}
ret res(cx, C_nil());
}
fn drop_slot(&@block_ctxt cx,
ValueRef slot,
- &ty.t t) -> result {
+ &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);
+ auto 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 {
+ ty::t t) -> result {
- if (!ty.type_is_scalar(cx.fcx.lcx.ccx.tcx, t)) {
- ret call_tydesc_glue(cx, v, t, false, abi.tydesc_field_drop_glue);
+ if (!ty::type_is_scalar(cx.fcx.lcx.ccx.tcx, t)) {
+ ret call_tydesc_glue(cx, v, t, false, abi::tydesc_field_drop_glue);
}
ret res(cx, C_nil());
}
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)
+ 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 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)
+ if (lib::llvm::llvm::LLVMIsConstant(align_bytes) == True)
{ cx.build.IntCast(align_bytes, T_i32()) }
else
{ cx.build.IntCast(C_int(0), T_i32()) };
fn memmove_ty(&@block_ctxt cx,
ValueRef dst,
ValueRef src,
- &ty.t t) -> result {
- if (ty.type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, t)) {
+ &ty::t t) -> result {
+ if (ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, t)) {
auto llsz = size_of(cx, t);
auto llalign = align_of(llsz.bcx, t);
ret call_memmove(llalign.bcx, dst, src, llsz.val, llalign.val);
copy_action action,
ValueRef dst,
ValueRef src,
- &ty.t t) -> result {
- if (ty.type_is_scalar(cx.fcx.lcx.ccx.tcx, t) ||
- ty.type_is_native(cx.fcx.lcx.ccx.tcx, t)) {
+ &ty::t t) -> result {
+ if (ty::type_is_scalar(cx.fcx.lcx.ccx.tcx, t) ||
+ ty::type_is_native(cx.fcx.lcx.ccx.tcx, t)) {
ret res(cx, cx.build.Store(src, dst));
- } else if (ty.type_is_nil(cx.fcx.lcx.ccx.tcx, t)) {
+ } else if (ty::type_is_nil(cx.fcx.lcx.ccx.tcx, t)) {
ret res(cx, C_nil());
- } else if (ty.type_is_boxed(cx.fcx.lcx.ccx.tcx, t)) {
+ } else if (ty::type_is_boxed(cx.fcx.lcx.ccx.tcx, t)) {
auto r = take_ty(cx, src, t);
if (action == DROP_EXISTING) {
r = drop_ty(r.bcx, r.bcx.build.Load(dst), t);
}
ret res(r.bcx, r.bcx.build.Store(src, dst));
- } else if (ty.type_is_structural(cx.fcx.lcx.ccx.tcx, t) ||
- ty.type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, t)) {
+ } else if (ty::type_is_structural(cx.fcx.lcx.ccx.tcx, t) ||
+ ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, t)) {
auto r = take_ty(cx, src, t);
if (action == DROP_EXISTING) {
r = drop_ty(r.bcx, dst, t);
ret memmove_ty(r.bcx, dst, src, t);
}
- cx.fcx.lcx.ccx.sess.bug("unexpected type in trans.copy_ty: " +
- ty.ty_to_str(cx.fcx.lcx.ccx.tcx, t));
+ cx.fcx.lcx.ccx.sess.bug("unexpected type in trans::copy_ty: " +
+ ty::ty_to_str(cx.fcx.lcx.ccx.tcx, t));
fail;
}
-fn trans_lit(&@crate_ctxt cx, &ast.lit lit, &ast.ann ann) -> ValueRef {
+fn trans_lit(&@crate_ctxt cx, &ast::lit lit, &ast::ann ann) -> ValueRef {
alt (lit.node) {
- case (ast.lit_int(?i)) {
+ case (ast::lit_int(?i)) {
ret C_int(i);
}
- case (ast.lit_uint(?u)) {
+ case (ast::lit_uint(?u)) {
ret C_int(u as int);
}
- case (ast.lit_mach_int(?tm, ?i)) {
+ 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.
auto t = T_int();
auto s = True;
alt (tm) {
- case (common.ty_u8) { t = T_i8(); s = False; }
- case (common.ty_u16) { t = T_i16(); s = False; }
- case (common.ty_u32) { t = T_i32(); s = False; }
- case (common.ty_u64) { t = T_i64(); s = False; }
-
- case (common.ty_i8) { t = T_i8(); }
- case (common.ty_i16) { t = T_i16(); }
- case (common.ty_i32) { t = T_i32(); }
- case (common.ty_i64) { t = T_i64(); }
+ case (common::ty_u8) { t = T_i8(); s = False; }
+ case (common::ty_u16) { t = T_i16(); s = False; }
+ case (common::ty_u32) { t = T_i32(); s = False; }
+ case (common::ty_u64) { t = T_i64(); s = False; }
+
+ case (common::ty_i8) { t = T_i8(); }
+ case (common::ty_i16) { t = T_i16(); }
+ case (common::ty_i32) { t = T_i32(); }
+ case (common::ty_i64) { t = T_i64(); }
}
ret C_integral(t, i as uint, s);
}
- case(ast.lit_float(?fs)) {
+ case(ast::lit_float(?fs)) {
ret C_float(fs);
}
- case(ast.lit_mach_float(?tm, ?s)) {
+ case(ast::lit_mach_float(?tm, ?s)) {
auto t = T_float();
alt(tm) {
- case(common.ty_f32) { t = T_f32(); }
- case(common.ty_f64) { t = T_f64(); }
+ case(common::ty_f32) { t = T_f32(); }
+ case(common::ty_f64) { t = T_f64(); }
}
ret C_floating(s, t);
}
- case (ast.lit_char(?c)) {
+ case (ast::lit_char(?c)) {
ret C_integral(T_char(), c as uint, False);
}
- case (ast.lit_bool(?b)) {
+ case (ast::lit_bool(?b)) {
ret C_bool(b);
}
- case (ast.lit_nil) {
+ case (ast::lit_nil) {
ret C_nil();
}
- case (ast.lit_str(?s)) {
+ case (ast::lit_str(?s)) {
ret C_str(cx, s);
}
}
}
-fn target_type(&@crate_ctxt cx, &ty.t t) -> ty.t {
- alt (ty.struct(cx.tcx, t)) {
- case (ty.ty_int) {
- auto struct_ty = ty.mk_mach(cx.tcx,
+fn target_type(&@crate_ctxt cx, &ty::t t) -> ty::t {
+ alt (ty::struct(cx.tcx, t)) {
+ case (ty::ty_int) {
+ auto struct_ty = ty::mk_mach(cx.tcx,
cx.sess.get_targ_cfg().int_type);
- ret ty.copy_cname(cx.tcx, struct_ty, t);
+ ret ty::copy_cname(cx.tcx, struct_ty, t);
}
- case (ty.ty_uint) {
- auto struct_ty = ty.mk_mach(cx.tcx,
+ case (ty::ty_uint) {
+ auto struct_ty = ty::mk_mach(cx.tcx,
cx.sess.get_targ_cfg().uint_type);
- ret ty.copy_cname(cx.tcx, struct_ty, t);
+ ret ty::copy_cname(cx.tcx, struct_ty, t);
}
case (_) { /* fall through */ }
}
// Converts an annotation to a type
-fn node_ann_type(&@crate_ctxt cx, &ast.ann a) -> ty.t {
- ret target_type(cx, ty.ann_to_monotype(cx.tcx, a));
+fn node_ann_type(&@crate_ctxt cx, &ast::ann a) -> ty::t {
+ ret target_type(cx, ty::ann_to_monotype(cx.tcx, a));
}
-fn node_ann_ty_params(&ast.ann a) -> vec[ty.t] {
+fn node_ann_ty_params(&ast::ann a) -> vec[ty::t] {
alt (a) {
- case (ast.ann_none(_)) {
+ case (ast::ann_none(_)) {
log_err "missing type annotation";
fail;
}
- case (ast.ann_type(_, _, ?tps_opt, _)) {
+ case (ast::ann_type(_, _, ?tps_opt, _)) {
alt (tps_opt) {
- case (none[vec[ty.t]]) {
+ case (none[vec[ty::t]]) {
log_err "type annotation has no ty params";
fail;
}
- case (some[vec[ty.t]](?tps)) { ret tps; }
+ case (some[vec[ty::t]](?tps)) { ret tps; }
}
}
}
}
-fn node_type(&@crate_ctxt cx, &ast.ann a) -> TypeRef {
+fn node_type(&@crate_ctxt cx, &ast::ann a) -> TypeRef {
ret type_of(cx, node_ann_type(cx, a));
}
-fn trans_unary(&@block_ctxt cx, ast.unop op,
- &@ast.expr e, &ast.ann a) -> result {
+fn trans_unary(&@block_ctxt cx, ast::unop op,
+ &@ast::expr e, &ast::ann a) -> result {
auto sub = trans_expr(cx, e);
- auto e_ty = ty.expr_ty(cx.fcx.lcx.ccx.tcx, e);
+ auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e);
alt (op) {
- case (ast.bitnot) {
+ case (ast::bitnot) {
sub = autoderef(sub.bcx, sub.val,
- ty.expr_ty(cx.fcx.lcx.ccx.tcx, e));
+ ty::expr_ty(cx.fcx.lcx.ccx.tcx, e));
ret res(sub.bcx, sub.bcx.build.Not(sub.val));
}
- case (ast.not) {
+ case (ast::not) {
sub = autoderef(sub.bcx, sub.val,
- ty.expr_ty(cx.fcx.lcx.ccx.tcx, e));
+ ty::expr_ty(cx.fcx.lcx.ccx.tcx, e));
ret res(sub.bcx, sub.bcx.build.Not(sub.val));
}
- case (ast.neg) {
+ case (ast::neg) {
sub = autoderef(sub.bcx, sub.val,
- ty.expr_ty(cx.fcx.lcx.ccx.tcx, e));
- if(ty.struct(cx.fcx.lcx.ccx.tcx, e_ty) == ty.ty_float) {
+ ty::expr_ty(cx.fcx.lcx.ccx.tcx, e));
+ if(ty::struct(cx.fcx.lcx.ccx.tcx, e_ty) == ty::ty_float) {
ret res(sub.bcx, sub.bcx.build.FNeg(sub.val));
}
else {
ret res(sub.bcx, sub.bcx.build.Neg(sub.val));
}
}
- case (ast.box(_)) {
- auto e_ty = ty.expr_ty(cx.fcx.lcx.ccx.tcx, e);
+ case (ast::box(_)) {
+ auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e);
auto e_val = sub.val;
auto box_ty = node_ann_type(sub.bcx.fcx.lcx.ccx, a);
sub = trans_malloc_boxed(sub.bcx, e_ty);
auto box = sub.val;
auto rc = sub.bcx.build.GEP(box,
vec(C_int(0),
- C_int(abi.box_rc_field_refcnt)));
+ C_int(abi::box_rc_field_refcnt)));
auto body = sub.bcx.build.GEP(box,
vec(C_int(0),
- C_int(abi.box_rc_field_body)));
+ 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(cx.fcx.lcx.ccx.tcx, e_ty)) {
+ if (!ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, e_ty)) {
auto llety = T_ptr(type_of(sub.bcx.fcx.lcx.ccx, e_ty));
body = sub.bcx.build.PointerCast(body, llety);
}
sub = copy_ty(sub.bcx, INIT, body, e_val, e_ty);
ret res(sub.bcx, box);
}
- case (ast.deref) {
+ case (ast::deref) {
log_err "deref expressions should have been translated using " +
"trans_lval(), not trans_unary()";
fail;
fail;
}
-fn trans_compare(&@block_ctxt cx0, ast.binop op, &ty.t t0,
+fn trans_compare(&@block_ctxt cx0, ast::binop op, &ty::t t0,
ValueRef lhs0, ValueRef rhs0) -> result {
// Autoderef both sides.
auto cx = cx0;
// 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); }
+ 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); }
}
auto rslt = call_cmp_glue(cx, lhs, rhs, t, llop);
// Invert the result if necessary.
// FIXME: Use or-patterns when we have them.
alt (op) {
- case (ast.eq) { ret res(rslt.bcx, rslt.val); }
- case (ast.lt) { ret res(rslt.bcx, rslt.val); }
- case (ast.le) { ret res(rslt.bcx, rslt.val); }
- case (ast.ne) { ret res(rslt.bcx, rslt.bcx.build.Not(rslt.val)); }
- case (ast.ge) { ret res(rslt.bcx, rslt.bcx.build.Not(rslt.val)); }
- case (ast.gt) { ret res(rslt.bcx, rslt.bcx.build.Not(rslt.val)); }
+ case (ast::eq) { ret res(rslt.bcx, rslt.val); }
+ case (ast::lt) { ret res(rslt.bcx, rslt.val); }
+ case (ast::le) { ret res(rslt.bcx, rslt.val); }
+ case (ast::ne) { ret res(rslt.bcx, rslt.bcx.build.Not(rslt.val)); }
+ case (ast::ge) { ret res(rslt.bcx, rslt.bcx.build.Not(rslt.val)); }
+ case (ast::gt) { ret res(rslt.bcx, rslt.bcx.build.Not(rslt.val)); }
}
}
-fn trans_vec_append(&@block_ctxt cx, &ty.t t,
+fn trans_vec_append(&@block_ctxt cx, &ty::t t,
ValueRef lhs, ValueRef rhs) -> result {
- auto elt_ty = ty.sequence_element_type(cx.fcx.lcx.ccx.tcx, t);
+ auto elt_ty = ty::sequence_element_type(cx.fcx.lcx.ccx.tcx, t);
auto skip_null = C_bool(false);
- alt (ty.struct(cx.fcx.lcx.ccx.tcx, t)) {
- case (ty.ty_str) { skip_null = C_bool(true); }
+ alt (ty::struct(cx.fcx.lcx.ccx.tcx, t)) {
+ case (ty::ty_str) { skip_null = C_bool(true); }
case (_) { }
}
dst, src, skip_null)));
}
-fn trans_vec_add(&@block_ctxt cx, &ty.t t,
+fn trans_vec_add(&@block_ctxt cx, &ty::t t,
ValueRef lhs, ValueRef rhs) -> result {
auto r = alloc_ty(cx, t);
auto tmp = r.val;
}
-fn trans_eager_binop(&@block_ctxt cx, ast.binop op, &ty.t intype,
+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(cx.fcx.lcx.ccx.tcx, intype)) {
- case (ty.ty_float) {
+ alt (ty::struct(cx.fcx.lcx.ccx.tcx, intype)) {
+ case (ty::ty_float) {
is_float = true;
}
case (_) {
}
alt (op) {
- case (ast.add) {
- if (ty.type_is_sequence(cx.fcx.lcx.ccx.tcx, intype)) {
+ case (ast::add) {
+ if (ty::type_is_sequence(cx.fcx.lcx.ccx.tcx, intype)) {
ret trans_vec_add(cx, intype, lhs, rhs);
}
if (is_float) {
ret res(cx, cx.build.Add(lhs, rhs));
}
}
- case (ast.sub) {
+ case (ast::sub) {
if (is_float) {
ret res(cx, cx.build.FSub(lhs, rhs));
}
}
}
- case (ast.mul) {
+ case (ast::mul) {
if (is_float) {
ret res(cx, cx.build.FMul(lhs, rhs));
}
}
}
- case (ast.div) {
+ case (ast::div) {
if (is_float) {
ret res(cx, cx.build.FDiv(lhs, rhs));
}
- if (ty.type_is_signed(cx.fcx.lcx.ccx.tcx, intype)) {
+ if (ty::type_is_signed(cx.fcx.lcx.ccx.tcx, intype)) {
ret res(cx, cx.build.SDiv(lhs, rhs));
} else {
ret res(cx, cx.build.UDiv(lhs, rhs));
}
}
- case (ast.rem) {
+ case (ast::rem) {
if (is_float) {
ret res(cx, cx.build.FRem(lhs, rhs));
}
- if (ty.type_is_signed(cx.fcx.lcx.ccx.tcx, intype)) {
+ if (ty::type_is_signed(cx.fcx.lcx.ccx.tcx, intype)) {
ret res(cx, cx.build.SRem(lhs, rhs));
} else {
ret res(cx, cx.build.URem(lhs, rhs));
}
}
- case (ast.bitor) { ret res(cx, cx.build.Or(lhs, rhs)); }
- case (ast.bitand) { ret res(cx, cx.build.And(lhs, rhs)); }
- case (ast.bitxor) { ret res(cx, cx.build.Xor(lhs, rhs)); }
- case (ast.lsl) { ret res(cx, cx.build.Shl(lhs, rhs)); }
- case (ast.lsr) { ret res(cx, cx.build.LShr(lhs, rhs)); }
- case (ast.asr) { ret res(cx, cx.build.AShr(lhs, rhs)); }
+ case (ast::bitor) { ret res(cx, cx.build.Or(lhs, rhs)); }
+ case (ast::bitand) { ret res(cx, cx.build.And(lhs, rhs)); }
+ case (ast::bitxor) { ret res(cx, cx.build.Xor(lhs, rhs)); }
+ case (ast::lsl) { ret res(cx, cx.build.Shl(lhs, rhs)); }
+ case (ast::lsr) { ret res(cx, cx.build.LShr(lhs, rhs)); }
+ case (ast::asr) { ret res(cx, cx.build.AShr(lhs, rhs)); }
case (_) {
ret trans_compare(cx, op, intype, lhs, rhs);
}
fail;
}
-fn autoderef(&@block_ctxt cx, ValueRef v, &ty.t t) -> result {
+fn autoderef(&@block_ctxt cx, ValueRef v, &ty::t t) -> result {
let ValueRef v1 = v;
- let ty.t t1 = t;
+ let ty::t t1 = t;
while (true) {
- alt (ty.struct(cx.fcx.lcx.ccx.tcx, t1)) {
- case (ty.ty_box(?mt)) {
+ alt (ty::struct(cx.fcx.lcx.ccx.tcx, t1)) {
+ case (ty::ty_box(?mt)) {
auto body = cx.build.GEP(v1,
vec(C_int(0),
- C_int(abi.box_rc_field_body)));
+ 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(cx.fcx.lcx.ccx.tcx, mt.ty)) {
+ if (!ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, mt.ty)) {
auto llty = type_of(cx.fcx.lcx.ccx, mt.ty);
v1 = cx.build.PointerCast(body, T_ptr(llty));
} else {
}
}
-fn autoderefed_ty(&@crate_ctxt ccx, &ty.t t) -> ty.t {
- let ty.t t1 = t;
+fn autoderefed_ty(&@crate_ctxt ccx, &ty::t t) -> ty::t {
+ let ty::t t1 = t;
while (true) {
- alt (ty.struct(ccx.tcx, t1)) {
- case (ty.ty_box(?mt)) {
+ alt (ty::struct(ccx.tcx, t1)) {
+ case (ty::ty_box(?mt)) {
t1 = mt.ty;
}
case (_) {
}
}
-fn trans_binary(&@block_ctxt cx, ast.binop op,
- &@ast.expr a, &@ast.expr b) -> result {
+fn trans_binary(&@block_ctxt cx, ast::binop op,
+ &@ast::expr a, &@ast::expr b) -> result {
// First couple cases are lazy:
alt (op) {
- case (ast.and) {
+ case (ast::and) {
// Lazy-eval and
auto lhs_res = trans_expr(cx, a);
lhs_res = autoderef(lhs_res.bcx, lhs_res.val,
- ty.expr_ty(cx.fcx.lcx.ccx.tcx, a));
+ ty::expr_ty(cx.fcx.lcx.ccx.tcx, a));
auto rhs_cx = new_scope_block_ctxt(cx, "rhs");
auto rhs_res = trans_expr(rhs_cx, b);
rhs_res = autoderef(rhs_res.bcx, rhs_res.val,
- ty.expr_ty(cx.fcx.lcx.ccx.tcx, b));
+ ty::expr_ty(cx.fcx.lcx.ccx.tcx, b));
auto lhs_false_cx = new_scope_block_ctxt(cx, "lhs false");
auto lhs_false_res = res(lhs_false_cx, C_bool(false));
vec(lhs_false_res, rhs_res));
}
- case (ast.or) {
+ case (ast::or) {
// Lazy-eval or
auto lhs_res = trans_expr(cx, a);
lhs_res = autoderef(lhs_res.bcx, lhs_res.val,
- ty.expr_ty(cx.fcx.lcx.ccx.tcx, a));
+ ty::expr_ty(cx.fcx.lcx.ccx.tcx, a));
auto rhs_cx = new_scope_block_ctxt(cx, "rhs");
auto rhs_res = trans_expr(rhs_cx, b);
rhs_res = autoderef(rhs_res.bcx, rhs_res.val,
- ty.expr_ty(cx.fcx.lcx.ccx.tcx, b));
+ ty::expr_ty(cx.fcx.lcx.ccx.tcx, b));
auto lhs_true_cx = new_scope_block_ctxt(cx, "lhs true");
auto lhs_true_res = res(lhs_true_cx, C_bool(true));
case (_) {
// Remaining cases are eager:
auto lhs = trans_expr(cx, a);
- auto lhty = ty.expr_ty(cx.fcx.lcx.ccx.tcx, a);
+ auto lhty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, a);
lhs = autoderef(lhs.bcx, lhs.val, lhty);
auto rhs = trans_expr(lhs.bcx, b);
- auto rhty = ty.expr_ty(cx.fcx.lcx.ccx.tcx, b);
+ auto rhty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, b);
rhs = autoderef(rhs.bcx, rhs.val, rhty);
ret trans_eager_binop(rhs.bcx, op,
autoderefed_ty(cx.fcx.lcx.ccx, lhty), lhs.val, rhs.val);
}
}
- alt (Vec.len[result](live)) {
+ alt (_vec::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.
- assert (Vec.len[result](ins) >= 1u);
+ assert (_vec::len[result](ins) >= 1u);
ret ins.(0);
}
ret res(join_cx, phi);
}
-fn trans_if(&@block_ctxt cx, &@ast.expr cond,
- &ast.block thn, &Option.t[@ast.expr] els) -> result {
+fn trans_if(&@block_ctxt cx, &@ast::expr cond,
+ &ast::block thn, &option::t[@ast::expr] els) -> result {
auto cond_res = trans_expr(cx, cond);
auto else_res;
auto expr_llty;
alt (els) {
- case (some[@ast.expr](?elexpr)) {
+ case (some[@ast::expr](?elexpr)) {
alt (elexpr.node) {
- case (ast.expr_if(_, _, _, _)) {
+ case (ast::expr_if(_, _, _, _)) {
else_res = trans_expr(else_cx, elexpr);
}
- case (ast.expr_block(?blk, _)) {
+ 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
// If we have an else expression, then the entire
// if expression can have a non-nil type.
// FIXME: This isn't quite right, particularly re: dynamic types
- auto expr_ty = ty.expr_ty(cx.fcx.lcx.ccx.tcx, elexpr);
- if (ty.type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, expr_ty)) {
+ auto expr_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, elexpr);
+ if (ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, expr_ty)) {
expr_llty = T_typaram_ptr(cx.fcx.lcx.ccx.tn);
} else {
expr_llty = type_of(else_res.bcx.fcx.lcx.ccx, expr_ty);
- if (ty.type_is_structural(cx.fcx.lcx.ccx.tcx, expr_ty)) {
+ if (ty::type_is_structural(cx.fcx.lcx.ccx.tcx, expr_ty)) {
expr_llty = T_ptr(expr_llty);
}
}
}
fn trans_for(&@block_ctxt cx,
- &@ast.decl decl,
- &@ast.expr seq,
- &ast.block body) -> result {
+ &@ast::decl decl,
+ &@ast::expr seq,
+ &ast::block body) -> result {
fn inner(&@block_ctxt cx,
- @ast.local local, ValueRef curr,
- ty.t t, ast.block body,
+ @ast::local local, ValueRef curr,
+ ty::t t, ast::block body,
@block_ctxt outer_next_cx) -> result {
auto next_cx = new_sub_block_ctxt(cx, "next");
auto scope_cx =
- new_loop_scope_block_ctxt(cx, Option.some[@block_ctxt](next_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);
}
- let @ast.local local;
+ let @ast::local local;
alt (decl.node) {
- case (ast.decl_local(?loc)) {
+ case (ast::decl_local(?loc)) {
local = loc;
}
}
auto next_cx = new_sub_block_ctxt(cx, "next");
- auto seq_ty = ty.expr_ty(cx.fcx.lcx.ccx.tcx, seq);
+ auto seq_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, seq);
auto seq_res = trans_expr(cx, seq);
auto it = iter_sequence(seq_res.bcx, seq_res.val, seq_ty,
bind inner(_, local, _, _, body, next_cx));
// Searches through a block for all references to locals or upvars in this
// frame and returns the list of definition IDs thus found.
-fn collect_upvars(&@block_ctxt cx, &ast.block bloc, &ast.def_id initial_decl)
- -> vec[ast.def_id] {
+fn collect_upvars(&@block_ctxt cx, &ast::block bloc,
+ &ast::def_id initial_decl) -> vec[ast::def_id] {
type env = @rec(
- mutable vec[ast.def_id] refs,
- hashmap[ast.def_id,()] decls,
- resolve.def_map def_map
+ mutable vec[ast::def_id] refs,
+ hashmap[ast::def_id,()] decls,
+ resolve::def_map def_map
);
- fn walk_expr(env e, &@ast.expr expr) {
+ fn walk_expr(env e, &@ast::expr expr) {
alt (expr.node) {
- case (ast.expr_path(?path, ?ann)) {
- alt (e.def_map.get(ast.ann_tag(ann))) {
- case (ast.def_arg(?did)) {
- Vec.push[ast.def_id](e.refs, did);
+ case (ast::expr_path(?path, ?ann)) {
+ alt (e.def_map.get(ast::ann_tag(ann))) {
+ case (ast::def_arg(?did)) {
+ _vec::push[ast::def_id](e.refs, did);
}
- case (ast.def_local(?did)) {
- Vec.push[ast.def_id](e.refs, did);
+ case (ast::def_local(?did)) {
+ _vec::push[ast::def_id](e.refs, did);
}
- case (ast.def_upvar(?did)) {
- Vec.push[ast.def_id](e.refs, did);
+ case (ast::def_upvar(?did)) {
+ _vec::push[ast::def_id](e.refs, did);
}
case (_) {}
}
}
}
- fn walk_decl(env e, &@ast.decl decl) {
+ fn walk_decl(env e, &@ast::decl decl) {
alt (decl.node) {
- case (ast.decl_local(?local)) {
+ case (ast::decl_local(?local)) {
e.decls.insert(local.id, ());
}
case (_) {}
}
}
- let vec[ast.def_id] refs = vec();
- let hashmap[ast.def_id,()] decls = new_def_hash[()]();
+ let vec[ast::def_id] refs = vec();
+ let hashmap[ast::def_id,()] decls = new_def_hash[()]();
decls.insert(initial_decl, ());
let env e = @rec(mutable refs=refs,
decls=decls,
auto visitor = @rec(visit_decl_pre = bind walk_decl(e, _),
visit_expr_pre = bind walk_expr(e, _)
- with walk.default_visitor());
- walk.walk_block(*visitor, bloc);
+ with walk::default_visitor());
+ walk::walk_block(*visitor, bloc);
// Calculate (refs - decls). This is the set of captured upvars.
- let vec[ast.def_id] result = vec();
- for (ast.def_id ref_id in e.refs) {
+ let vec[ast::def_id] result = vec();
+ for (ast::def_id ref_id in e.refs) {
if (!decls.contains_key(ref_id)) {
result += vec(ref_id);
}
}
fn trans_for_each(&@block_ctxt cx,
- &@ast.decl decl,
- &@ast.expr seq,
- &ast.block body) -> result {
+ &@ast::decl decl,
+ &@ast::expr seq,
+ &ast::block body) -> result {
/*
* The translation is a little .. complex here. Code like:
*
auto lcx = cx.fcx.lcx;
// FIXME: possibly support alias-mode here?
- auto decl_ty = ty.mk_nil(lcx.ccx.tcx);
+ auto decl_ty = ty::mk_nil(lcx.ccx.tcx);
auto decl_id;
alt (decl.node) {
- case (ast.decl_local(?local)) {
+ case (ast::decl_local(?local)) {
decl_ty = node_ann_type(lcx.ccx, local.ann);
decl_id = local.id;
}
}
auto upvars = collect_upvars(cx, body, decl_id);
- auto upvar_count = Vec.len[ast.def_id](upvars);
+ auto upvar_count = _vec::len[ast::def_id](upvars);
auto llbindingsptr;
if (upvar_count > 0u) {
// Gather up the upvars.
let vec[ValueRef] llbindings = vec();
let vec[TypeRef] llbindingtys = vec();
- for (ast.def_id did in upvars) {
+ for (ast::def_id did in upvars) {
auto llbinding;
alt (cx.fcx.lllocals.find(did)) {
case (none[ValueRef]) {
}
// Create an environment and populate it with the bindings.
- auto tydesc_count = Vec.len[ValueRef](cx.fcx.lltydescs);
+ auto tydesc_count = _vec::len[ValueRef](cx.fcx.lltydescs);
auto llenvptrty = T_closure_ptr(lcx.ccx.tn, T_ptr(T_nil()),
val_ty(llbindingsptr), tydesc_count);
- auto llenvptr = alloca(cx, llvm.LLVMGetElementType(llenvptrty));
+ auto llenvptr = alloca(cx, llvm::LLVMGetElementType(llenvptrty));
auto llbindingsptrptr = cx.build.GEP(llenvptr,
vec(C_int(0),
- C_int(abi.box_rc_field_body),
+ C_int(abi::box_rc_field_body),
C_int(2)));
cx.build.Store(llbindingsptr, llbindingsptrptr);
// to them.
auto lltydescsptr = cx.build.GEP(llenvptr,
vec(C_int(0),
- C_int(abi.box_rc_field_body),
- C_int(abi.closure_elt_ty_params)));
+ C_int(abi::box_rc_field_body),
+ C_int(abi::closure_elt_ty_params)));
auto i = 0u;
while (i < tydesc_count) {
auto lltydescptr = cx.build.GEP(lltydescsptr,
// and pass it in as a first class fn-arg to the iterator.
auto iter_body_llty =
- type_of_fn_full(lcx.ccx, ast.proto_fn,
+ type_of_fn_full(lcx.ccx, ast::proto_fn,
none[TypeRef],
- vec(rec(mode=ty.mo_alias, ty=decl_ty)),
- ty.mk_nil(lcx.ccx.tcx), 0u);
+ vec(rec(mode=ty::mo_alias, ty=decl_ty)),
+ ty::mk_nil(lcx.ccx.tcx), 0u);
let ValueRef lliterbody = decl_internal_fastcall_fn(lcx.ccx.llmod,
s, iter_body_llty);
auto llremotebindingsptrptr =
copy_args_bcx.build.GEP(llremoteenvptr,
vec(C_int(0),
- C_int(abi.box_rc_field_body),
- C_int(abi.closure_elt_bindings)));
+ C_int(abi::box_rc_field_body),
+ C_int(abi::closure_elt_bindings)));
auto llremotebindingsptr =
copy_args_bcx.build.Load(llremotebindingsptrptr);
auto llremotetydescsptr =
copy_args_bcx.build.GEP(llremoteenvptr,
vec(C_int(0),
- C_int(abi.box_rc_field_body),
- C_int(abi.closure_elt_ty_params)));
+ C_int(abi::box_rc_field_body),
+ C_int(abi::closure_elt_ty_params)));
i = 0u;
while (i < tydesc_count) {
}
// Add an upvar for the loop variable alias.
- fcx.llupvars.insert(decl_id, llvm.LLVMGetParam(fcx.llfn, 3u));
+ fcx.llupvars.insert(decl_id, llvm::LLVMGetParam(fcx.llfn, 3u));
auto bcx = new_top_block_ctxt(fcx);
auto lltop = bcx.llbb;
alt (seq.node) {
- case (ast.expr_call(?f, ?args, ?ann)) {
+ case (ast::expr_call(?f, ?args, ?ann)) {
auto pair = alloca(cx, T_fn_pair(lcx.ccx.tn,
iter_body_llty));
auto code_cell = cx.build.GEP(pair,
vec(C_int(0),
- C_int(abi.fn_field_code)));
+ C_int(abi::fn_field_code)));
cx.build.Store(lliterbody, code_cell);
auto env_cell = cx.build.GEP(pair, vec(C_int(0),
- C_int(abi.fn_field_box)));
+ C_int(abi::fn_field_box)));
auto llenvblobptr = cx.build.PointerCast(llenvptr,
T_opaque_closure_ptr(lcx.ccx.tn));
cx.build.Store(llenvblobptr, env_cell);
}
-fn trans_while(&@block_ctxt cx, &@ast.expr cond,
- &ast.block body) -> result {
+fn trans_while(&@block_ctxt cx, &@ast::expr cond,
+ &ast::block body) -> result {
auto cond_cx = new_scope_block_ctxt(cx, "while cond");
auto next_cx = new_sub_block_ctxt(cx, "next");
- auto body_cx = new_loop_scope_block_ctxt(cx, Option.none[@block_ctxt],
+ auto 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);
ret res(next_cx, C_nil());
}
-fn trans_do_while(&@block_ctxt cx, &ast.block body,
- &@ast.expr cond) -> result {
+fn trans_do_while(&@block_ctxt cx, &ast::block body,
+ &@ast::expr cond) -> result {
auto next_cx = new_sub_block_ctxt(cx, "next");
- auto body_cx = new_loop_scope_block_ctxt(cx, Option.none[@block_ctxt],
+ auto 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);
// Pattern matching translation
-fn trans_pat_match(&@block_ctxt cx, &@ast.pat pat, ValueRef llval,
+fn trans_pat_match(&@block_ctxt cx, &@ast::pat pat, ValueRef llval,
&@block_ctxt next_cx) -> result {
alt (pat.node) {
- case (ast.pat_wild(_)) { ret res(cx, llval); }
- case (ast.pat_bind(_, _, _)) { ret res(cx, llval); }
+ case (ast::pat_wild(_)) { ret res(cx, llval); }
+ case (ast::pat_bind(_, _, _)) { ret res(cx, llval); }
- case (ast.pat_lit(?lt, ?ann)) {
+ case (ast::pat_lit(?lt, ?ann)) {
auto lllit = trans_lit(cx.fcx.lcx.ccx, *lt, ann);
- auto lltype = ty.ann_to_type(ann);
- auto lleq = trans_compare(cx, ast.eq, lltype, llval, lllit);
+ auto lltype = ty::ann_to_type(ann);
+ auto lleq = trans_compare(cx, ast::eq, lltype, llval, lllit);
auto matched_cx = new_sub_block_ctxt(lleq.bcx, "matched_cx");
lleq.bcx.build.CondBr(lleq.val, matched_cx.llbb, next_cx.llbb);
ret res(matched_cx, llval);
}
- case (ast.pat_tag(?id, ?subpats, ?ann)) {
+ case (ast::pat_tag(?id, ?subpats, ?ann)) {
auto lltagptr = cx.build.PointerCast(llval,
T_opaque_tag_ptr(cx.fcx.lcx.ccx.tn));
vec(C_int(0), C_int(0)));
auto lldiscrim = cx.build.Load(lldiscrimptr);
- auto vdef = ast.variant_def_ids
- (cx.fcx.lcx.ccx.tcx.def_map.get(ast.ann_tag(ann)));
+ auto vdef = ast::variant_def_ids
+ (cx.fcx.lcx.ccx.tcx.def_map.get(ast::ann_tag(ann)));
auto variant_tag = 0;
auto variants = tag_variants(cx.fcx.lcx.ccx, vdef._0);
auto matched_cx = new_sub_block_ctxt(cx, "matched_cx");
- auto lleq = cx.build.ICmp(lib.llvm.LLVMIntEQ, lldiscrim,
+ auto lleq = cx.build.ICmp(lib::llvm::LLVMIntEQ, lldiscrim,
C_int(variant_tag));
cx.build.CondBr(lleq, matched_cx.llbb, next_cx.llbb);
auto ty_params = node_ann_ty_params(ann);
- if (Vec.len[@ast.pat](subpats) > 0u) {
+ if (_vec::len[@ast::pat](subpats) > 0u) {
auto llblobptr = matched_cx.build.GEP(lltagptr,
vec(C_int(0), C_int(1)));
auto i = 0;
- for (@ast.pat subpat in subpats) {
+ for (@ast::pat subpat in subpats) {
auto rslt = GEP_tag(matched_cx, llblobptr, vdef._0,
vdef._1, ty_params, i);
auto llsubvalptr = rslt.val;
fail;
}
-fn trans_pat_binding(&@block_ctxt cx, &@ast.pat pat,
+fn trans_pat_binding(&@block_ctxt cx, &@ast::pat pat,
ValueRef llval, bool bind_alias)
-> result {
alt (pat.node) {
- case (ast.pat_wild(_)) { ret res(cx, llval); }
- case (ast.pat_lit(_, _)) { ret res(cx, llval); }
- case (ast.pat_bind(?id, ?def_id, ?ann)) {
+ case (ast::pat_wild(_)) { ret res(cx, llval); }
+ case (ast::pat_lit(_, _)) { ret res(cx, llval); }
+ case (ast::pat_bind(?id, ?def_id, ?ann)) {
if (bind_alias) {
cx.fcx.lllocals.insert(def_id, llval);
ret res(cx, llval);
ret copy_ty(bcx, INIT, dst, llval, t);
}
}
- case (ast.pat_tag(_, ?subpats, ?ann)) {
- if (Vec.len[@ast.pat](subpats) == 0u) { ret res(cx, llval); }
+ case (ast::pat_tag(_, ?subpats, ?ann)) {
+ if (_vec::len[@ast::pat](subpats) == 0u) { ret res(cx, llval); }
// Get the appropriate variant for this tag.
- auto vdef = ast.variant_def_ids
- (cx.fcx.lcx.ccx.tcx.def_map.get(ast.ann_tag(ann)));
+ auto vdef = ast::variant_def_ids
+ (cx.fcx.lcx.ccx.tcx.def_map.get(ast::ann_tag(ann)));
auto lltagptr = cx.build.PointerCast(llval,
T_opaque_tag_ptr(cx.fcx.lcx.ccx.tn));
auto this_cx = cx;
auto i = 0;
- for (@ast.pat subpat in subpats) {
+ for (@ast::pat subpat in subpats) {
auto rslt = GEP_tag(this_cx, llblobptr, vdef._0, vdef._1,
ty_param_substs, i);
this_cx = rslt.bcx;
}
}
-fn trans_alt(&@block_ctxt cx, &@ast.expr expr,
- &vec[ast.arm] arms, &ast.ann ann) -> result {
+fn trans_alt(&@block_ctxt cx, &@ast::expr expr,
+ &vec[ast::arm] arms, &ast::ann ann) -> result {
auto expr_res = trans_expr(cx, expr);
auto this_cx = expr_res.bcx;
let vec[result] arm_results = vec();
- for (ast.arm arm in arms) {
+ for (ast::arm arm in arms) {
auto next_cx = new_sub_block_ctxt(expr_res.bcx, "next");
auto match_res = trans_pat_match(this_cx, arm.pat, expr_res.val,
next_cx);
}
auto default_cx = this_cx;
- auto default_res = trans_fail(default_cx, some[common.span](expr.span),
+ auto default_res = trans_fail(default_cx, some[common::span](expr.span),
"non-exhaustive match failure");
// FIXME: This isn't quite right, particularly re: dynamic types
- auto expr_ty = ty.ann_to_type(ann);
+ auto expr_ty = ty::ann_to_type(ann);
auto expr_llty;
- if (ty.type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, expr_ty)) {
+ if (ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, expr_ty)) {
expr_llty = T_typaram_ptr(cx.fcx.lcx.ccx.tn);
} else {
expr_llty = type_of(cx.fcx.lcx.ccx, expr_ty);
- if (ty.type_is_structural(cx.fcx.lcx.ccx.tcx, expr_ty)) {
+ if (ty::type_is_structural(cx.fcx.lcx.ccx.tcx, expr_ty)) {
expr_llty = T_ptr(expr_llty);
}
}
ret join_results(cx, expr_llty, arm_results);
}
-type generic_info = rec(ty.t item_type,
+type generic_info = rec(ty::t item_type,
vec[ValueRef] tydescs);
type lval_result = rec(result res,
bool is_mem,
- Option.t[generic_info] generic,
- Option.t[ValueRef] llobj,
- Option.t[ty.t] method_ty);
+ option::t[generic_info] generic,
+ option::t[ValueRef] llobj,
+ option::t[ty::t] method_ty);
fn lval_mem(&@block_ctxt cx, ValueRef val) -> lval_result {
ret rec(res=res(cx, val),
is_mem=true,
generic=none[generic_info],
llobj=none[ValueRef],
- method_ty=none[ty.t]);
+ method_ty=none[ty::t]);
}
fn lval_val(&@block_ctxt cx, ValueRef val) -> lval_result {
is_mem=false,
generic=none[generic_info],
llobj=none[ValueRef],
- method_ty=none[ty.t]);
+ method_ty=none[ty::t]);
}
-fn trans_external_path(&@block_ctxt cx, &ast.def_id did,
- &ty.ty_param_count_and_ty tpt) -> lval_result {
+fn trans_external_path(&@block_ctxt cx, &ast::def_id did,
+ &ty::ty_param_count_and_ty tpt) -> lval_result {
auto lcx = cx.fcx.lcx;
- auto name = creader.get_symbol(lcx.ccx.sess, did);
+ auto name = creader::get_symbol(lcx.ccx.sess, did);
auto v = get_extern_const(lcx.ccx.externs, lcx.ccx.llmod,
name, type_of_ty_param_count_and_ty(lcx, tpt));
ret lval_val(cx, v);
}
fn lval_generic_fn(&@block_ctxt cx,
- &ty.ty_param_count_and_ty tpt,
- &ast.def_id fn_id,
- &ast.ann ann)
+ &ty::ty_param_count_and_ty tpt,
+ &ast::def_id fn_id,
+ &ast::ann ann)
-> lval_result {
auto lv;
if (cx.fcx.lcx.ccx.sess.get_targ_crate_num() == fn_id._0) {
}
auto monoty;
- let vec[ty.t] tys;
+ let vec[ty::t] tys;
alt (ann) {
- case (ast.ann_none(_)) {
+ case (ast::ann_none(_)) {
cx.fcx.lcx.ccx.sess.bug("no type annotation for path!");
fail;
}
- case (ast.ann_type(_, ?monoty_, ?tps, _)) {
+ case (ast::ann_type(_, ?monoty_, ?tps, _)) {
monoty = monoty_;
- tys = Option.get[vec[ty.t]](tps);
+ tys = option::get[vec[ty::t]](tps);
}
}
- if (Vec.len[ty.t](tys) != 0u) {
+ if (_vec::len[ty::t](tys) != 0u) {
auto bcx = lv.res.bcx;
let vec[ValueRef] tydescs = vec();
- for (ty.t t in tys) {
+ for (ty::t t in tys) {
// TODO: Doesn't always escape.
auto td = get_tydesc(bcx, t, true);
bcx = td.bcx;
- Vec.push[ValueRef](tydescs, td.val);
+ _vec::push[ValueRef](tydescs, td.val);
}
auto gen = rec( item_type = tpt._1,
tydescs = tydescs );
ret lv;
}
-fn lookup_discriminant(&@local_ctxt lcx, &ast.def_id tid, &ast.def_id vid)
+fn lookup_discriminant(&@local_ctxt lcx, &ast::def_id tid, &ast::def_id vid)
-> ValueRef {
alt (lcx.ccx.discrims.find(vid)) {
case (none[ValueRef]) {
// It's an external discriminant that we haven't seen yet.
assert (lcx.ccx.sess.get_targ_crate_num() != vid._0);
- auto sym = creader.get_symbol(lcx.ccx.sess, 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);
+ auto sym = creader::get_symbol(lcx.ccx.sess, 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, gvar);
ret gvar;
}
}
}
-fn trans_path(&@block_ctxt cx, &ast.path p, &ast.ann ann) -> lval_result {
- alt (cx.fcx.lcx.ccx.tcx.def_map.get(ast.ann_tag(ann))) {
- case (ast.def_arg(?did)) {
+fn trans_path(&@block_ctxt cx, &ast::path p, &ast::ann ann) -> lval_result {
+ alt (cx.fcx.lcx.ccx.tcx.def_map.get(ast::ann_tag(ann))) {
+ case (ast::def_arg(?did)) {
alt (cx.fcx.llargs.find(did)) {
case (none[ValueRef]) {
assert (cx.fcx.llupvars.contains_key(did));
}
}
}
- case (ast.def_local(?did)) {
+ case (ast::def_local(?did)) {
alt (cx.fcx.lllocals.find(did)) {
case (none[ValueRef]) {
assert (cx.fcx.llupvars.contains_key(did));
}
}
}
- case (ast.def_binding(?did)) {
+ case (ast::def_binding(?did)) {
assert (cx.fcx.lllocals.contains_key(did));
ret lval_mem(cx, cx.fcx.lllocals.get(did));
}
- case (ast.def_obj_field(?did)) {
+ case (ast::def_obj_field(?did)) {
assert (cx.fcx.llobjfields.contains_key(did));
ret lval_mem(cx, cx.fcx.llobjfields.get(did));
}
- case (ast.def_fn(?did)) {
- auto tyt = ty.lookup_item_type(cx.fcx.lcx.ccx.sess,
+ case (ast::def_fn(?did)) {
+ auto tyt = ty::lookup_item_type(cx.fcx.lcx.ccx.sess,
cx.fcx.lcx.ccx.tcx,
cx.fcx.lcx.ccx.type_cache, did);
ret lval_generic_fn(cx, tyt, did, ann);
}
- case (ast.def_obj(?did)) {
- auto tyt = ty.lookup_item_type(cx.fcx.lcx.ccx.sess,
+ case (ast::def_obj(?did)) {
+ auto tyt = ty::lookup_item_type(cx.fcx.lcx.ccx.sess,
cx.fcx.lcx.ccx.tcx,
cx.fcx.lcx.ccx.type_cache, did);
ret lval_generic_fn(cx, tyt, did, ann);
}
- case (ast.def_variant(?tid, ?vid)) {
- auto v_tyt = ty.lookup_item_type(cx.fcx.lcx.ccx.sess,
+ case (ast::def_variant(?tid, ?vid)) {
+ auto v_tyt = ty::lookup_item_type(cx.fcx.lcx.ccx.sess,
cx.fcx.lcx.ccx.tcx,
cx.fcx.lcx.ccx.type_cache, vid);
- alt (ty.struct(cx.fcx.lcx.ccx.tcx, v_tyt._1)) {
- case (ty.ty_fn(_, _, _)) {
+ alt (ty::struct(cx.fcx.lcx.ccx.tcx, v_tyt._1)) {
+ case (ty::ty_fn(_, _, _)) {
// N-ary variant.
ret lval_generic_fn(cx, v_tyt, vid, ann);
}
auto lltagblob = alloc_result.val;
auto lltagty;
- if (ty.type_has_dynamic_size(cx.fcx.lcx.ccx.tcx,
+ if (ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx,
tag_ty)) {
lltagty = T_opaque_tag(cx.fcx.lcx.ccx.tn);
} else {
}
}
}
- case (ast.def_const(?did)) {
+ case (ast::def_const(?did)) {
// TODO: externals
assert (cx.fcx.lcx.ccx.consts.contains_key(did));
ret lval_mem(cx, cx.fcx.lcx.ccx.consts.get(did));
}
- case (ast.def_native_fn(?did)) {
- auto tyt = ty.lookup_item_type(cx.fcx.lcx.ccx.sess,
+ case (ast::def_native_fn(?did)) {
+ auto tyt = ty::lookup_item_type(cx.fcx.lcx.ccx.sess,
cx.fcx.lcx.ccx.tcx,
cx.fcx.lcx.ccx.type_cache, did);
ret lval_generic_fn(cx, tyt, did, ann);
}
}
-fn trans_field(&@block_ctxt cx, &ast.span sp, ValueRef v, &ty.t t0,
- &ast.ident field, &ast.ann ann) -> lval_result {
+fn trans_field(&@block_ctxt cx, &ast::span sp, ValueRef v, &ty::t t0,
+ &ast::ident field, &ast::ann ann) -> lval_result {
auto r = autoderef(cx, v, t0);
auto t = autoderefed_ty(cx.fcx.lcx.ccx, t0);
- alt (ty.struct(cx.fcx.lcx.ccx.tcx, t)) {
- case (ty.ty_tup(_)) {
- let uint ix = ty.field_num(cx.fcx.lcx.ccx.sess, sp, field);
+ alt (ty::struct(cx.fcx.lcx.ccx.tcx, t)) {
+ case (ty::ty_tup(_)) {
+ let uint ix = ty::field_num(cx.fcx.lcx.ccx.sess, sp, field);
auto v = GEP_tup_like(r.bcx, t, r.val, vec(0, ix as int));
ret lval_mem(v.bcx, v.val);
}
- case (ty.ty_rec(?fields)) {
- let uint ix = ty.field_idx(cx.fcx.lcx.ccx.sess, sp, field,
+ case (ty::ty_rec(?fields)) {
+ let uint ix = ty::field_idx(cx.fcx.lcx.ccx.sess, sp, field,
fields);
auto v = GEP_tup_like(r.bcx, t, r.val, vec(0, ix as int));
ret lval_mem(v.bcx, v.val);
}
- case (ty.ty_obj(?methods)) {
- let uint ix = ty.method_idx(cx.fcx.lcx.ccx.sess, sp, field,
+ case (ty::ty_obj(?methods)) {
+ let uint ix = ty::method_idx(cx.fcx.lcx.ccx.sess, sp, field,
methods);
auto vtbl = r.bcx.build.GEP(r.val,
vec(C_int(0),
- C_int(abi.obj_field_vtbl)));
+ C_int(abi::obj_field_vtbl)));
vtbl = r.bcx.build.Load(vtbl);
// +1 because slot #0 contains the destructor
auto v = r.bcx.build.GEP(vtbl, vec(C_int(0),
C_int((ix + 1u) as int)));
auto lvo = lval_mem(r.bcx, v);
- let ty.t fn_ty = ty.method_ty_to_fn_ty(cx.fcx.lcx.ccx.tcx,
+ let ty::t fn_ty = ty::method_ty_to_fn_ty(cx.fcx.lcx.ccx.tcx,
methods.(ix));
ret rec(llobj = some[ValueRef](r.val),
- method_ty = some[ty.t](fn_ty)
+ method_ty = some[ty::t](fn_ty)
with lvo);
}
case (_) {cx.fcx.lcx.ccx.sess.unimpl("field variant in trans_field");}
fail;
}
-fn trans_index(&@block_ctxt cx, &ast.span sp, &@ast.expr base,
- &@ast.expr idx, &ast.ann ann) -> lval_result {
+fn trans_index(&@block_ctxt cx, &ast::span sp, &@ast::expr base,
+ &@ast::expr idx, &ast::ann ann) -> lval_result {
auto lv = trans_expr(cx, base);
- lv = autoderef(lv.bcx, lv.val, ty.expr_ty(cx.fcx.lcx.ccx.tcx, base));
+ lv = autoderef(lv.bcx, lv.val, ty::expr_ty(cx.fcx.lcx.ccx.tcx, base));
auto ix = trans_expr(lv.bcx, idx);
auto v = lv.val;
auto bcx = ix.bcx;
auto scaled_ix = bcx.build.Mul(ix_val, unit_sz.val);
maybe_name_value(cx.fcx.lcx.ccx, scaled_ix, "scaled_ix");
- auto lim = bcx.build.GEP(v, vec(C_int(0), C_int(abi.vec_elt_fill)));
+ auto lim = bcx.build.GEP(v, vec(C_int(0), C_int(abi::vec_elt_fill)));
lim = bcx.build.Load(lim);
- auto bounds_check = bcx.build.ICmp(lib.llvm.LLVMIntULT,
+ auto bounds_check = bcx.build.ICmp(lib::llvm::LLVMIntULT,
scaled_ix, lim);
auto fail_cx = new_sub_block_ctxt(bcx, "fail");
bcx.build.CondBr(bounds_check, next_cx.llbb, fail_cx.llbb);
// fail: bad bounds check.
- auto fail_res = trans_fail(fail_cx, some[common.span](sp),
+ auto fail_res = trans_fail(fail_cx, some[common::span](sp),
"bounds check");
- auto body = next_cx.build.GEP(v, vec(C_int(0), C_int(abi.vec_elt_data)));
+ auto body = next_cx.build.GEP(v, vec(C_int(0), C_int(abi::vec_elt_data)));
auto elt;
- if (ty.type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, unit_ty)) {
+ if (ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, unit_ty)) {
body = next_cx.build.PointerCast(body, T_ptr(T_array(T_i8(), 1u)));
elt = next_cx.build.GEP(body, vec(C_int(0), scaled_ix));
} else {
// represented as an alloca or heap, hence needs a 'load' to be used as an
// immediate).
-fn trans_lval(&@block_ctxt cx, &@ast.expr e) -> lval_result {
+fn trans_lval(&@block_ctxt cx, &@ast::expr e) -> lval_result {
alt (e.node) {
- case (ast.expr_path(?p, ?ann)) {
+ case (ast::expr_path(?p, ?ann)) {
ret trans_path(cx, p, ann);
}
- case (ast.expr_field(?base, ?ident, ?ann)) {
+ case (ast::expr_field(?base, ?ident, ?ann)) {
auto r = trans_expr(cx, base);
- auto t = ty.expr_ty(cx.fcx.lcx.ccx.tcx, base);
+ auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx, base);
ret trans_field(r.bcx, e.span, r.val, t, ident, ann);
}
- case (ast.expr_index(?base, ?idx, ?ann)) {
+ case (ast::expr_index(?base, ?idx, ?ann)) {
ret trans_index(cx, e.span, base, idx, ann);
}
- case (ast.expr_unary(?unop, ?base, ?ann)) {
- assert (unop == ast.deref);
+ case (ast::expr_unary(?unop, ?base, ?ann)) {
+ assert (unop == ast::deref);
auto sub = trans_expr(cx, base);
auto val = sub.bcx.build.GEP(sub.val,
vec(C_int(0),
- C_int(abi.box_rc_field_body)));
+ C_int(abi::box_rc_field_body)));
ret lval_mem(sub.bcx, val);
}
- case (ast.expr_self_method(?ident, ?ann)) {
+ case (ast::expr_self_method(?ident, ?ann)) {
alt (cx.fcx.llself) {
case (some[self_vt](?s_vt)) {
auto r = s_vt.v;
fn int_cast(&@block_ctxt bcx, TypeRef lldsttype, TypeRef llsrctype,
ValueRef llsrc, bool signed) -> ValueRef {
- if (llvm.LLVMGetIntTypeWidth(lldsttype) >
- llvm.LLVMGetIntTypeWidth(llsrctype)) {
+ if (llvm::LLVMGetIntTypeWidth(lldsttype) >
+ llvm::LLVMGetIntTypeWidth(llsrctype)) {
if (signed) {
// Widening signed cast.
ret bcx.build.SExtOrBitCast(llsrc, lldsttype);
ret bcx.build.TruncOrBitCast(llsrc, lldsttype);
}
-fn trans_cast(&@block_ctxt cx, &@ast.expr e, &ast.ann ann) -> result {
+fn trans_cast(&@block_ctxt cx, &@ast::expr e, &ast::ann ann) -> result {
auto e_res = trans_expr(cx, e);
auto llsrctype = val_ty(e_res.val);
auto t = node_ann_type(cx.fcx.lcx.ccx, ann);
auto lldsttype = type_of(cx.fcx.lcx.ccx, t);
- if (!ty.type_is_fp(cx.fcx.lcx.ccx.tcx, t)) {
+ if (!ty::type_is_fp(cx.fcx.lcx.ccx.tcx, t)) {
// TODO: native-to-native casts
- if (ty.type_is_native(cx.fcx.lcx.ccx.tcx,
- ty.expr_ty(cx.fcx.lcx.ccx.tcx, e))) {
+ if (ty::type_is_native(cx.fcx.lcx.ccx.tcx,
+ ty::expr_ty(cx.fcx.lcx.ccx.tcx, e))) {
e_res.val = e_res.bcx.build.PtrToInt(e_res.val, lldsttype);
- } else if (ty.type_is_native(cx.fcx.lcx.ccx.tcx, t)) {
+ } else if (ty::type_is_native(cx.fcx.lcx.ccx.tcx, t)) {
e_res.val = e_res.bcx.build.IntToPtr(e_res.val, lldsttype);
} else {
e_res.val = int_cast(e_res.bcx, lldsttype, llsrctype, e_res.val,
- ty.type_is_signed(cx.fcx.lcx.ccx.tcx, t));
+ ty::type_is_signed(cx.fcx.lcx.ccx.tcx, t));
}
} else {
cx.fcx.lcx.ccx.sess.unimpl("fp cast");
}
fn trans_bind_thunk(&@local_ctxt cx,
- &ty.t incoming_fty,
- &ty.t outgoing_fty,
- &vec[Option.t[@ast.expr]] args,
- &ty.t closure_ty,
- &vec[ty.t] bound_tys,
+ &ty::t incoming_fty,
+ &ty::t outgoing_fty,
+ &vec[option::t[@ast::expr]] args,
+ &ty::t closure_ty,
+ &vec[ty::t] bound_tys,
uint ty_param_count) -> ValueRef {
// Construct a thunk-call with signature incoming_fty, and that copies
- // args forward into a call to outgoing_fty.
+ // args forward into a call to outgoing_fty:
let str s = mangle_name_by_seq(cx.ccx, cx.path, "thunk");
let TypeRef llthunk_ty = get_pair_fn_ty(type_of(cx.ccx, incoming_fty));
auto lltop = bcx.llbb;
auto llclosure_ptr_ty =
- type_of(cx.ccx, ty.mk_imm_box(cx.ccx.tcx, closure_ty));
+ type_of(cx.ccx, ty::mk_imm_box(cx.ccx.tcx, closure_ty));
auto llclosure = bcx.build.PointerCast(fcx.llenv, llclosure_ptr_ty);
auto lltarget = GEP_tup_like(bcx, closure_ty, llclosure,
vec(0,
- abi.box_rc_field_body,
- abi.closure_elt_target));
+ abi::box_rc_field_body,
+ abi::closure_elt_target));
bcx = lltarget.bcx;
auto lltargetclosure = bcx.build.GEP(lltarget.val,
vec(C_int(0),
- C_int(abi.fn_field_box)));
+ C_int(abi::fn_field_box)));
lltargetclosure = bcx.build.Load(lltargetclosure);
- auto outgoing_ret_ty = ty.ty_fn_ret(cx.ccx.tcx, outgoing_fty);
- auto outgoing_args = ty.ty_fn_args(cx.ccx.tcx, outgoing_fty);
+ auto outgoing_ret_ty = ty::ty_fn_ret(cx.ccx.tcx, outgoing_fty);
+ auto outgoing_args = ty::ty_fn_args(cx.ccx.tcx, outgoing_fty);
auto llretptr = fcx.llretptr;
- if (ty.type_has_dynamic_size(cx.ccx.tcx, outgoing_ret_ty)) {
+ if (ty::type_has_dynamic_size(cx.ccx.tcx, outgoing_ret_ty)) {
llretptr = bcx.build.PointerCast(llretptr, T_typaram_ptr(cx.ccx.tn));
}
auto lltyparam_ptr =
GEP_tup_like(bcx, closure_ty, llclosure,
vec(0,
- abi.box_rc_field_body,
- abi.closure_elt_ty_params,
+ abi::box_rc_field_body,
+ abi::closure_elt_ty_params,
(i as int)));
bcx = lltyparam_ptr.bcx;
auto td = bcx.build.Load(lltyparam_ptr.val);
let vec[TypeRef] llout_arg_tys =
type_of_explicit_args(cx.ccx, outgoing_args);
- for (Option.t[@ast.expr] arg in 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[@ast.expr](?e)) {
- auto e_ty = ty.expr_ty(cx.ccx.tcx, e);
+ case (some[@ast::expr](?e)) {
+ auto e_ty = ty::expr_ty(cx.ccx.tcx, e);
auto bound_arg =
GEP_tup_like(bcx, closure_ty, llclosure,
vec(0,
- abi.box_rc_field_body,
- abi.closure_elt_bindings,
+ 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 (out_arg.mode == ty::mo_val) {
if (type_is_immediate(cx.ccx, e_ty)) {
val = bcx.build.Load(val);
bcx = take_ty(bcx, val, e_ty).bcx;
bcx = take_ty(bcx, val, e_ty).bcx;
val = bcx.build.Load(val);
}
- } else if (ty.type_contains_params(cx.ccx.tcx,
+ } else if (ty::type_contains_params(cx.ccx.tcx,
out_arg.ty)) {
- assert (out_arg.mode == ty.mo_alias);
+ assert (out_arg.mode == ty::mo_alias);
val = bcx.build.PointerCast(val, llout_arg_ty);
}
}
// Arg will be provided when the thunk is invoked.
- case (none[@ast.expr]) {
- let ValueRef passed_arg = llvm.LLVMGetParam(llthunk, a);
+ case (none[@ast::expr]) {
+ 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_alias);
+ if (ty::type_contains_params(cx.ccx.tcx, out_arg.ty)) {
+ assert (out_arg.mode == ty::mo_alias);
passed_arg = bcx.build.PointerCast(passed_arg,
llout_arg_ty);
}
// FIXME: turn this call + ret into a tail call.
auto lltargetfn = bcx.build.GEP(lltarget.val,
vec(C_int(0),
- C_int(abi.fn_field_code)));
+ 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 = type_of_fn(bcx.fcx.lcx.ccx,
- ty.ty_fn_proto(bcx.fcx.lcx.ccx.tcx,
+ ty::ty_fn_proto(bcx.fcx.lcx.ccx.tcx,
outgoing_fty),
outgoing_args,
outgoing_ret_ty,
ret llthunk;
}
-fn trans_bind(&@block_ctxt cx, &@ast.expr f,
- &vec[Option.t[@ast.expr]] args,
- &ast.ann ann) -> result {
+fn trans_bind(&@block_ctxt cx, &@ast::expr f,
+ &vec[option::t[@ast::expr]] args,
+ &ast::ann ann) -> result {
auto f_res = trans_lval(cx, f);
if (f_res.is_mem) {
cx.fcx.lcx.ccx.sess.unimpl("re-binding existing function");
} else {
- let vec[@ast.expr] bound = vec();
+ let vec[@ast::expr] bound = vec();
- for (Option.t[@ast.expr] argopt in args) {
+ for (option::t[@ast::expr] argopt in args) {
alt (argopt) {
- case (none[@ast.expr]) {
+ case (none[@ast::expr]) {
}
- case (some[@ast.expr](?e)) {
- Vec.push[@ast.expr](bound, e);
+ case (some[@ast::expr](?e)) {
+ _vec::push[@ast::expr](bound, e);
}
}
}
// Figure out which tydescs we need to pass, if any.
- let ty.t outgoing_fty;
+ let ty::t outgoing_fty;
let vec[ValueRef] lltydescs;
alt (f_res.generic) {
case (none[generic_info]) {
- outgoing_fty = ty.expr_ty(cx.fcx.lcx.ccx.tcx, f);
+ outgoing_fty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, f);
lltydescs = vec();
}
case (some[generic_info](?ginfo)) {
lltydescs = ginfo.tydescs;
}
}
- auto ty_param_count = Vec.len[ValueRef](lltydescs);
+ auto ty_param_count = _vec::len[ValueRef](lltydescs);
- if (Vec.len[@ast.expr](bound) == 0u && ty_param_count == 0u) {
+ if (_vec::len[@ast::expr](bound) == 0u && ty_param_count == 0u) {
// Trivial 'binding': just return the static pair-ptr.
ret f_res.res;
} else {
auto pair_v = alloca(bcx, pair_t);
// Translate the bound expressions.
- let vec[ty.t] bound_tys = vec();
+ let vec[ty::t] bound_tys = vec();
let vec[ValueRef] bound_vals = vec();
auto i = 0u;
- for (@ast.expr e in bound) {
+ for (@ast::expr e in bound) {
auto arg = trans_expr(bcx, e);
bcx = arg.bcx;
- Vec.push[ValueRef](bound_vals, arg.val);
- Vec.push[ty.t](bound_tys,
- ty.expr_ty(cx.fcx.lcx.ccx.tcx, e));
+ _vec::push[ValueRef](bound_vals, arg.val);
+ _vec::push[ty::t](bound_tys,
+ ty::expr_ty(cx.fcx.lcx.ccx.tcx, e));
i += 1u;
}
// Synthesize a closure type.
- let ty.t bindings_ty = ty.mk_imm_tup(cx.fcx.lcx.ccx.tcx,
+ let ty::t bindings_ty = ty::mk_imm_tup(cx.fcx.lcx.ccx.tcx,
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
+ // a ty::t structure that has the same "shape" as the LLVM type
// it constructs.
- let ty.t tydesc_ty = ty.mk_type(cx.fcx.lcx.ccx.tcx);
+ let ty::t tydesc_ty = ty::mk_type(cx.fcx.lcx.ccx.tcx);
- let vec[ty.t] captured_tys =
- Vec.init_elt[ty.t](tydesc_ty, ty_param_count);
+ let vec[ty::t] captured_tys =
+ _vec::init_elt[ty::t](tydesc_ty, ty_param_count);
- let vec[ty.t] closure_tys =
+ let vec[ty::t] closure_tys =
vec(tydesc_ty,
outgoing_fty,
bindings_ty,
- ty.mk_imm_tup(cx.fcx.lcx.ccx.tcx, captured_tys));
+ ty::mk_imm_tup(cx.fcx.lcx.ccx.tcx, captured_tys));
- let ty.t closure_ty = ty.mk_imm_tup(cx.fcx.lcx.ccx.tcx,
+ let ty::t closure_ty = ty::mk_imm_tup(cx.fcx.lcx.ccx.tcx,
closure_tys);
auto r = trans_malloc_boxed(bcx, closure_ty);
bcx = r.bcx;
auto rc = bcx.build.GEP(box,
vec(C_int(0),
- C_int(abi.box_rc_field_refcnt)));
+ C_int(abi::box_rc_field_refcnt)));
auto closure =
bcx.build.GEP(box,
vec(C_int(0),
- C_int(abi.box_rc_field_body)));
+ C_int(abi::box_rc_field_body)));
bcx.build.Store(C_int(1), rc);
// Store bindings tydesc.
auto bound_tydesc =
bcx.build.GEP(closure,
vec(C_int(0),
- C_int(abi.closure_elt_tydesc)));
+ C_int(abi::closure_elt_tydesc)));
auto bindings_tydesc = get_tydesc(bcx, bindings_ty, true);
bcx = bindings_tydesc.bcx;
bcx.build.Store(bindings_tydesc.val, bound_tydesc);
// function has, which type_of() doesn't, as only we know which
// item the function refers to.
auto llfnty = type_of_fn(bcx.fcx.lcx.ccx,
- ty.ty_fn_proto(bcx.fcx.lcx.ccx.tcx, outgoing_fty),
- ty.ty_fn_args(bcx.fcx.lcx.ccx.tcx, outgoing_fty),
- ty.ty_fn_ret(bcx.fcx.lcx.ccx.tcx, outgoing_fty),
+ ty::ty_fn_proto(bcx.fcx.lcx.ccx.tcx, outgoing_fty),
+ ty::ty_fn_args(bcx.fcx.lcx.ccx.tcx, outgoing_fty),
+ ty::ty_fn_ret(bcx.fcx.lcx.ccx.tcx, outgoing_fty),
ty_param_count);
auto llclosurety = T_ptr(T_fn_pair(bcx.fcx.lcx.ccx.tn, llfnty));
auto bound_target =
bcx.build.GEP(closure,
vec(C_int(0),
- C_int(abi.closure_elt_target)));
+ C_int(abi::closure_elt_target)));
auto src = bcx.build.Load(f_res.res.val);
bound_target = bcx.build.PointerCast(bound_target, llclosurety);
bcx.build.Store(src, bound_target);
auto bindings =
bcx.build.GEP(closure,
vec(C_int(0),
- C_int(abi.closure_elt_bindings)));
+ C_int(abi::closure_elt_bindings)));
for (ValueRef v in bound_vals) {
auto bound = bcx.build.GEP(bindings,
vec(C_int(0), C_int(i as int)));
auto ty_params_slot =
bcx.build.GEP(closure,
vec(C_int(0),
- C_int(abi.closure_elt_ty_params)));
+ 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,
// Make thunk and store thunk-ptr in outer pair's code slot.
auto pair_code = bcx.build.GEP(pair_v,
vec(C_int(0),
- C_int(abi.fn_field_code)));
+ C_int(abi::fn_field_code)));
- let ty.t pair_ty = node_ann_type(cx.fcx.lcx.ccx, ann);
+ let ty::t pair_ty = node_ann_type(cx.fcx.lcx.ccx, ann);
let ValueRef llthunk =
trans_bind_thunk(cx.fcx.lcx, pair_ty, outgoing_fty,
// Store box ptr in outer pair's box slot.
auto pair_box = bcx.build.GEP(pair_v,
vec(C_int(0),
- C_int(abi.fn_field_box)));
+ C_int(abi::fn_field_box)));
bcx.build.Store
(bcx.build.PointerCast
(box,
}
fn trans_arg_expr(&@block_ctxt cx,
- &ty.arg arg,
+ &ty::arg arg,
TypeRef lldestty0,
- &@ast.expr e) -> result {
+ &@ast::expr e) -> result {
auto val;
auto bcx = cx;
- auto e_ty = ty.expr_ty(cx.fcx.lcx.ccx.tcx, e);
+ auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e);
- if (ty.type_is_structural(cx.fcx.lcx.ccx.tcx, e_ty)) {
+ if (ty::type_is_structural(cx.fcx.lcx.ccx.tcx, e_ty)) {
auto re = trans_expr(bcx, e);
val = re.val;
bcx = re.bcx;
- } else if (arg.mode == ty.mo_alias) {
+ } else if (arg.mode == ty::mo_alias) {
let lval_result lv;
- if (ty.is_lval(e)) {
+ if (ty::is_lval(e)) {
lv = trans_lval(bcx, e);
} else {
auto r = trans_expr(bcx, e);
bcx = re.bcx;
}
- if (arg.mode != ty.mo_alias) {
+ if (arg.mode != ty::mo_alias) {
bcx = take_ty(bcx, val, e_ty).bcx;
}
- if (ty.type_contains_params(cx.fcx.lcx.ccx.tcx, arg.ty)) {
+ if (ty::type_contains_params(cx.fcx.lcx.ccx.tcx, arg.ty)) {
auto lldestty = lldestty0;
- if (arg.mode == ty.mo_val) {
+ if (arg.mode == ty::mo_val) {
// FIXME: we'd prefer to use &&, but rustboot doesn't like it
- if (ty.type_is_structural(cx.fcx.lcx.ccx.tcx, e_ty)) {
+ if (ty::type_is_structural(cx.fcx.lcx.ccx.tcx, e_ty)) {
lldestty = T_ptr(lldestty);
}
}
val = bcx.build.PointerCast(val, lldestty);
}
- if (arg.mode == ty.mo_val) {
+ if (arg.mode == ty::mo_val) {
// FIXME: we'd prefer to use &&, but rustboot doesn't like it
- if (ty.type_is_structural(cx.fcx.lcx.ccx.tcx, e_ty)) {
+ if (ty::type_is_structural(cx.fcx.lcx.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);
fn trans_args(&@block_ctxt cx,
ValueRef llenv,
- &Option.t[ValueRef] llobj,
- &Option.t[generic_info] gen,
- &Option.t[ValueRef] lliterbody,
- &vec[@ast.expr] es,
- &ty.t fn_ty)
+ &option::t[ValueRef] llobj,
+ &option::t[generic_info] gen,
+ &option::t[ValueRef] lliterbody,
+ &vec[@ast::expr] es,
+ &ty::t fn_ty)
-> tup(@block_ctxt, vec[ValueRef], ValueRef) {
- let vec[ty.arg] args = ty.ty_fn_args(cx.fcx.lcx.ccx.tcx, fn_ty);
+ let vec[ty::arg] args = ty::ty_fn_args(cx.fcx.lcx.ccx.tcx, fn_ty);
let vec[ValueRef] llargs = vec();
let vec[ValueRef] lltydescs = vec();
let @block_ctxt bcx = cx;
// Arg 0: Output pointer.
- auto retty = ty.ty_fn_ret(cx.fcx.lcx.ccx.tcx, fn_ty);
+ auto retty = ty::ty_fn_ret(cx.fcx.lcx.ccx.tcx, fn_ty);
auto llretslot_res = alloc_ty(bcx, retty);
bcx = llretslot_res.bcx;
auto llretslot = llretslot_res.val;
alt (gen) {
case (some[generic_info](?g)) {
lltydescs = g.tydescs;
- args = ty.ty_fn_args(cx.fcx.lcx.ccx.tcx, g.item_type);
- retty = ty.ty_fn_ret(cx.fcx.lcx.ccx.tcx, g.item_type);
+ args = ty::ty_fn_args(cx.fcx.lcx.ccx.tcx, g.item_type);
+ retty = ty::ty_fn_ret(cx.fcx.lcx.ccx.tcx, g.item_type);
}
case (_) {
}
}
- if (ty.type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, retty)) {
+ if (ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, retty)) {
llargs += vec(bcx.build.PointerCast
(llretslot, T_typaram_ptr(cx.fcx.lcx.ccx.tn)));
- } else if (ty.type_contains_params(cx.fcx.lcx.ccx.tcx, retty)) {
+ } else if (ty::type_contains_params(cx.fcx.lcx.ccx.tcx, retty)) {
// It's possible that the callee has some generic-ness somewhere in
// its return value -- say a method signature within an obj or a fn
// type deep in a structure -- which the caller has a concrete view
}
- // Arg 1: Task pointer.
+ // Arg 1: task pointer.
llargs += vec(bcx.fcx.lltaskptr);
// Arg 2: Env (closure-bindings / self-obj)
auto arg_tys = type_of_explicit_args(cx.fcx.lcx.ccx, args);
auto i = 0u;
- for (@ast.expr e in es) {
+ for (@ast::expr e in es) {
auto r = trans_arg_expr(bcx, args.(i), arg_tys.(i), e);
bcx = r.bcx;
llargs += vec(r.val);
ret tup(bcx, llargs, llretslot);
}
-fn trans_call(&@block_ctxt cx, &@ast.expr f,
- &Option.t[ValueRef] lliterbody,
- &vec[@ast.expr] args,
- &ast.ann ann) -> result {
+fn trans_call(&@block_ctxt cx, &@ast::expr f,
+ &option::t[ValueRef] lliterbody,
+ &vec[@ast::expr] args,
+ &ast::ann ann) -> 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
auto bcx = f_res.res.bcx;
auto pair = faddr;
faddr = bcx.build.GEP(pair, vec(C_int(0),
- C_int(abi.fn_field_code)));
+ C_int(abi::fn_field_code)));
faddr = bcx.build.Load(faddr);
auto llclosure = bcx.build.GEP(pair,
vec(C_int(0),
- C_int(abi.fn_field_box)));
+ C_int(abi::fn_field_box)));
llenv = bcx.build.Load(llclosure);
}
}
- let ty.t fn_ty;
+ let ty::t fn_ty;
alt (f_res.method_ty) {
- case (some[ty.t](?meth)) {
+ case (some[ty::t](?meth)) {
// self-call
fn_ty = meth;
}
case (_) {
- fn_ty = ty.expr_ty(cx.fcx.lcx.ccx.tcx, f);
+ fn_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, f);
}
}
- auto ret_ty = ty.ann_to_type(ann);
+ auto ret_ty = ty::ann_to_type(ann);
auto args_res = trans_args(f_res.res.bcx,
llenv, f_res.llobj,
f_res.generic,
alt (lliterbody) {
case (none[ValueRef]) {
- if (!ty.type_is_nil(cx.fcx.lcx.ccx.tcx, ret_ty)) {
+ if (!ty::type_is_nil(cx.fcx.lcx.ccx.tcx, 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
ret res(bcx, retval);
}
-fn trans_tup(&@block_ctxt cx, &vec[ast.elt] elts,
- &ast.ann ann) -> result {
+fn trans_tup(&@block_ctxt cx, &vec[ast::elt] elts,
+ &ast::ann ann) -> result {
auto bcx = cx;
auto t = node_ann_type(bcx.fcx.lcx.ccx, ann);
auto tup_res = alloc_ty(bcx, t);
vec(clean(bind drop_ty(_, tup_val, t)));
let int i = 0;
- for (ast.elt e in elts) {
- auto e_ty = ty.expr_ty(cx.fcx.lcx.ccx.tcx, e.expr);
+ for (ast::elt e in elts) {
+ auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e.expr);
auto src_res = trans_expr(bcx, e.expr);
bcx = src_res.bcx;
auto dst_res = GEP_tup_like(bcx, t, tup_val, vec(0, i));
ret res(bcx, tup_val);
}
-fn trans_vec(&@block_ctxt cx, &vec[@ast.expr] args,
- &ast.ann ann) -> result {
+fn trans_vec(&@block_ctxt cx, &vec[@ast::expr] args,
+ &ast::ann ann) -> result {
auto t = node_ann_type(cx.fcx.lcx.ccx, ann);
auto unit_ty = t;
- alt (ty.struct(cx.fcx.lcx.ccx.tcx, t)) {
- case (ty.ty_vec(?mt)) {
+ alt (ty::struct(cx.fcx.lcx.ccx.tcx, t)) {
+ case (ty::ty_vec(?mt)) {
unit_ty = mt.ty;
}
case (_) {
auto bcx = cx;
auto unit_sz = size_of(bcx, unit_ty);
bcx = unit_sz.bcx;
- auto data_sz = bcx.build.Mul(C_int(Vec.len[@ast.expr](args) as int),
+ auto data_sz = bcx.build.Mul(C_int(_vec::len[@ast::expr](args) as int),
unit_sz.val);
// FIXME: pass tydesc properly.
vec(clean(bind drop_ty(_, vec_val, t)));
auto body = bcx.build.GEP(vec_val, vec(C_int(0),
- C_int(abi.vec_elt_data)));
+ C_int(abi::vec_elt_data)));
auto pseudo_tup_ty =
- ty.mk_imm_tup(cx.fcx.lcx.ccx.tcx,
- Vec.init_elt[ty.t](unit_ty,
- Vec.len[@ast.expr](args)));
+ ty::mk_imm_tup(cx.fcx.lcx.ccx.tcx,
+ _vec::init_elt[ty::t](unit_ty,
+ _vec::len[@ast::expr](args)));
let int i = 0;
- for (@ast.expr e in args) {
+ for (@ast::expr e in args) {
auto src_res = trans_expr(bcx, e);
bcx = src_res.bcx;
auto dst_res = GEP_tup_like(bcx, pseudo_tup_ty, body, vec(0, i));
// (5) "src_res" is derived from "unit_ty", which is not behind a box.
auto dst_val;
- if (!ty.type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, unit_ty)) {
+ if (!ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, unit_ty)) {
auto llunit_ty = type_of(cx.fcx.lcx.ccx, unit_ty);
dst_val = bcx.build.PointerCast(dst_res.val, T_ptr(llunit_ty));
} else {
i += 1;
}
auto fill = bcx.build.GEP(vec_val,
- vec(C_int(0), C_int(abi.vec_elt_fill)));
+ vec(C_int(0), C_int(abi::vec_elt_fill)));
bcx.build.Store(data_sz, fill);
ret res(bcx, vec_val);
}
-fn trans_rec(&@block_ctxt cx, &vec[ast.field] fields,
- &Option.t[@ast.expr] base, &ast.ann ann) -> result {
+fn trans_rec(&@block_ctxt cx, &vec[ast::field] fields,
+ &option::t[@ast::expr] base, &ast::ann ann) -> result {
auto bcx = cx;
auto t = node_ann_type(bcx.fcx.lcx.ccx, ann);
auto base_val = C_nil();
alt (base) {
- case (none[@ast.expr]) { }
- case (some[@ast.expr](?bexp)) {
+ case (none[@ast::expr]) { }
+ case (some[@ast::expr](?bexp)) {
auto base_res = trans_expr(bcx, bexp);
bcx = base_res.bcx;
base_val = base_res.val;
}
}
- let vec[ty.field] ty_fields = vec();
- alt (ty.struct(cx.fcx.lcx.ccx.tcx, t)) {
- case (ty.ty_rec(?flds)) { ty_fields = flds; }
+ let vec[ty::field] ty_fields = vec();
+ alt (ty::struct(cx.fcx.lcx.ccx.tcx, t)) {
+ case (ty::ty_rec(?flds)) { ty_fields = flds; }
}
- for (ty.field tf in ty_fields) {
+ for (ty::field tf in ty_fields) {
auto e_ty = tf.mt.ty;
auto dst_res = GEP_tup_like(bcx, t, rec_val, vec(0, i));
bcx = dst_res.bcx;
auto expr_provided = false;
auto src_res = res(bcx, C_nil());
- for (ast.field f in fields) {
- if (Str.eq(f.ident, tf.ident)) {
+ for (ast::field f in fields) {
+ if (_str::eq(f.ident, tf.ident)) {
expr_provided = true;
src_res = trans_expr(bcx, f.expr);
}
-fn trans_expr(&@block_ctxt cx, &@ast.expr e) -> result {
+fn trans_expr(&@block_ctxt cx, &@ast::expr e) -> result {
alt (e.node) {
- case (ast.expr_lit(?lit, ?ann)) {
+ case (ast::expr_lit(?lit, ?ann)) {
ret res(cx, trans_lit(cx.fcx.lcx.ccx, *lit, ann));
}
- case (ast.expr_unary(?op, ?x, ?ann)) {
- if (op != ast.deref) {
+ case (ast::expr_unary(?op, ?x, ?ann)) {
+ if (op != ast::deref) {
ret trans_unary(cx, op, x, ann);
}
}
- case (ast.expr_binary(?op, ?x, ?y, _)) {
+ case (ast::expr_binary(?op, ?x, ?y, _)) {
ret trans_binary(cx, op, x, y);
}
- case (ast.expr_if(?cond, ?thn, ?els, _)) {
+ case (ast::expr_if(?cond, ?thn, ?els, _)) {
ret trans_if(cx, cond, thn, els);
}
- case (ast.expr_for(?decl, ?seq, ?body, _)) {
+ case (ast::expr_for(?decl, ?seq, ?body, _)) {
ret trans_for(cx, decl, seq, body);
}
- case (ast.expr_for_each(?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, _)) {
+ case (ast::expr_while(?cond, ?body, _)) {
ret trans_while(cx, cond, body);
}
- case (ast.expr_do_while(?body, ?cond, _)) {
+ case (ast::expr_do_while(?body, ?cond, _)) {
ret trans_do_while(cx, body, cond);
}
- case (ast.expr_alt(?expr, ?arms, ?ann)) {
+ case (ast::expr_alt(?expr, ?arms, ?ann)) {
ret trans_alt(cx, expr, arms, ann);
}
- case (ast.expr_block(?blk, _)) {
+ 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 = trans_block(sub_cx, blk);
ret res(next_cx, sub.val);
}
- case (ast.expr_assign(?dst, ?src, ?ann)) {
+ case (ast::expr_assign(?dst, ?src, ?ann)) {
auto lhs_res = trans_lval(cx, dst);
assert (lhs_res.is_mem);
auto rhs_res = trans_expr(lhs_res.res.bcx, src);
lhs_res.res.val, rhs_res.val, t);
}
- case (ast.expr_assign_op(?op, ?dst, ?src, ?ann)) {
+ case (ast::expr_assign_op(?op, ?dst, ?src, ?ann)) {
auto t = node_ann_type(cx.fcx.lcx.ccx, ann);
auto lhs_res = trans_lval(cx, dst);
assert (lhs_res.is_mem);
auto rhs_res = trans_expr(lhs_res.res.bcx, src);
- if (ty.type_is_sequence(cx.fcx.lcx.ccx.tcx, t)) {
+ if (ty::type_is_sequence(cx.fcx.lcx.ccx.tcx, t)) {
alt (op) {
- case (ast.add) {
+ case (ast::add) {
ret trans_vec_append(rhs_res.bcx, t,
lhs_res.res.val,
rhs_res.val);
lhs_res.res.val, v.val, t);
}
- case (ast.expr_bind(?f, ?args, ?ann)) {
+ case (ast::expr_bind(?f, ?args, ?ann)) {
ret trans_bind(cx, f, args, ann);
}
- case (ast.expr_call(?f, ?args, ?ann)) {
+ case (ast::expr_call(?f, ?args, ?ann)) {
ret trans_call(cx, f, none[ValueRef], args, ann);
}
- case (ast.expr_cast(?e, _, ?ann)) {
+ case (ast::expr_cast(?e, _, ?ann)) {
ret trans_cast(cx, e, ann);
}
- case (ast.expr_vec(?args, _, ?ann)) {
+ case (ast::expr_vec(?args, _, ?ann)) {
ret trans_vec(cx, args, ann);
}
- case (ast.expr_tup(?args, ?ann)) {
+ case (ast::expr_tup(?args, ?ann)) {
ret trans_tup(cx, args, ann);
}
- case (ast.expr_rec(?args, ?base, ?ann)) {
+ case (ast::expr_rec(?args, ?base, ?ann)) {
ret trans_rec(cx, args, base, ann);
}
- case (ast.expr_ext(_, _, _, ?expanded, _)) {
+ case (ast::expr_ext(_, _, _, ?expanded, _)) {
ret trans_expr(cx, expanded);
}
- case (ast.expr_fail(_)) {
- ret trans_fail(cx, some[common.span](e.span), "explicit failure");
+ case (ast::expr_fail(_)) {
+ ret trans_fail(cx, some(e.span), "explicit failure");
}
- case (ast.expr_log(?lvl, ?a, _)) {
+ case (ast::expr_log(?lvl, ?a, _)) {
ret trans_log(lvl, cx, a);
}
- case (ast.expr_assert(?a, _)) {
+ case (ast::expr_assert(?a, _)) {
ret trans_check_expr(cx, a);
}
- case (ast.expr_check(?a, _)) {
+ case (ast::expr_check(?a, _)) {
ret trans_check_expr(cx, a);
}
- case (ast.expr_break(?a)) {
+ case (ast::expr_break(?a)) {
ret trans_break(cx);
}
- case (ast.expr_cont(?a)) {
+ case (ast::expr_cont(?a)) {
ret trans_cont(cx);
}
- case (ast.expr_ret(?e, _)) {
+ case (ast::expr_ret(?e, _)) {
ret trans_ret(cx, e);
}
- case (ast.expr_put(?e, _)) {
+ case (ast::expr_put(?e, _)) {
ret trans_put(cx, e);
}
- case (ast.expr_be(?e, _)) {
+ case (ast::expr_be(?e, _)) {
ret trans_be(cx, e);
}
- case (ast.expr_port(?ann)) {
+ case (ast::expr_port(?ann)) {
ret trans_port(cx, ann);
}
- case (ast.expr_chan(?e, ?ann)) {
+ case (ast::expr_chan(?e, ?ann)) {
ret trans_chan(cx, e, ann);
}
- case (ast.expr_send(?lhs, ?rhs, ?ann)) {
+ case (ast::expr_send(?lhs, ?rhs, ?ann)) {
ret trans_send(cx, lhs, rhs, ann);
}
- case (ast.expr_recv(?lhs, ?rhs, ?ann)) {
+ case (ast::expr_recv(?lhs, ?rhs, ?ann)) {
ret trans_recv(cx, lhs, rhs, ann);
}
// lval cases fall through to trans_lval and then
// possibly load the result (if it's non-structural).
- auto t = ty.expr_ty(cx.fcx.lcx.ccx.tcx, e);
+ auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e);
auto sub = trans_lval(cx, e);
ret res(sub.res.bcx, load_if_immediate(sub.res.bcx, sub.res.val, t));
}
// 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 {
- ret ty.type_is_scalar(ccx.tcx, t) ||
- ty.type_is_boxed(ccx.tcx, t) ||
- ty.type_is_native(ccx.tcx, t);
+fn type_is_immediate(&@crate_ctxt ccx, &ty::t 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 {
ret llptr;
}
-fn spill_if_immediate(&@block_ctxt cx, ValueRef v, &ty.t t) -> ValueRef {
+fn spill_if_immediate(&@block_ctxt cx, ValueRef v, &ty::t t) -> ValueRef {
if (type_is_immediate(cx.fcx.lcx.ccx, t)) {
ret do_spill(cx, v);
}
ret v;
}
-fn load_if_immediate(&@block_ctxt cx, ValueRef v, &ty.t t) -> ValueRef {
+fn load_if_immediate(&@block_ctxt cx, ValueRef v, &ty::t t) -> ValueRef {
if (type_is_immediate(cx.fcx.lcx.ccx, t)) {
ret cx.build.Load(v);
}
ret v;
}
-fn trans_log(int lvl, &@block_ctxt cx, &@ast.expr e) -> result {
+fn trans_log(int lvl, &@block_ctxt cx, &@ast::expr e) -> result {
auto lcx = cx.fcx.lcx;
- auto modname = Str.connect(lcx.module_path, "::");
+ auto modname = _str::connect(lcx.module_path, "::");
auto global;
if (lcx.ccx.module_data.contains_key(modname)) {
global = lcx.ccx.module_data.get(modname);
} else {
- global = llvm.LLVMAddGlobal(lcx.ccx.llmod, T_int(),
- Str.buf("_rust_mod_log_" + modname));
- llvm.LLVMSetGlobalConstant(global, False);
- llvm.LLVMSetInitializer(global, C_null(T_int()));
- llvm.LLVMSetLinkage(global, lib.llvm.LLVMInternalLinkage
- as llvm.Linkage);
+ global = llvm::LLVMAddGlobal(lcx.ccx.llmod, T_int(),
+ _str::buf("_rust_mod_log_" + modname));
+ llvm::LLVMSetGlobalConstant(global, False);
+ llvm::LLVMSetInitializer(global, C_null(T_int()));
+ llvm::LLVMSetLinkage(global, 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));
+ auto 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(cx.fcx.lcx.ccx.tcx, e);
+ auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e);
auto log_bcx = sub.bcx;
- if (ty.type_is_fp(cx.fcx.lcx.ccx.tcx, e_ty)) {
+ if (ty::type_is_fp(cx.fcx.lcx.ccx.tcx, e_ty)) {
let TypeRef tr;
let bool is32bit = false;
- alt (ty.struct(cx.fcx.lcx.ccx.tcx, e_ty)) {
- case (ty.ty_machine(util.common.ty_f32)) {
+ alt (ty::struct(cx.fcx.lcx.ccx.tcx, e_ty)) {
+ case (ty::ty_machine(util::common::ty_f32)) {
tr = T_f32();
is32bit = true;
}
- case (ty.ty_machine(util.common.ty_f64)) {
+ case (ty::ty_machine(util::common::ty_f64)) {
tr = T_f64();
}
case (_) {
vec(log_bcx.fcx.lltaskptr, C_int(lvl), tmp));
}
} else {
- alt (ty.struct(cx.fcx.lcx.ccx.tcx, e_ty)) {
- case (ty.ty_str) {
+ alt (ty::struct(cx.fcx.lcx.ccx.tcx, e_ty)) {
+ case (ty::ty_str) {
log_bcx.build.Call(log_bcx.fcx.lcx.ccx.upcalls.log_str,
vec(log_bcx.fcx.lltaskptr, C_int(lvl),
sub.val));
ret res(after_cx, C_nil());
}
-fn trans_check_expr(&@block_ctxt cx, &@ast.expr e) -> result {
+fn trans_check_expr(&@block_ctxt cx, &@ast::expr e) -> result {
auto cond_res = trans_expr(cx, e);
- auto expr_str = util.common.expr_to_str(e);
+ auto expr_str = util::common::expr_to_str(e);
auto fail_cx = new_sub_block_ctxt(cx, "fail");
- auto fail_res = trans_fail(fail_cx, some[common.span](e.span), expr_str);
+ auto fail_res = trans_fail(fail_cx, some[common::span](e.span), expr_str);
auto next_cx = new_sub_block_ctxt(cx, "next");
cond_res.bcx.build.CondBr(cond_res.val,
ret res(next_cx, C_nil());
}
-fn trans_fail(&@block_ctxt cx, &Option.t[common.span] sp_opt, &str fail_str)
+fn trans_fail(&@block_ctxt cx, &option::t[common::span] sp_opt, &str fail_str)
-> result {
auto V_fail_str = C_cstr(cx.fcx.lcx.ccx, fail_str);
auto V_filename; auto V_line;
alt (sp_opt) {
- case (some[common.span](?sp)) {
+ case (some[common::span](?sp)) {
auto loc = cx.fcx.lcx.ccx.sess.lookup_pos(sp.lo);
V_filename = C_cstr(cx.fcx.lcx.ccx, loc.filename);
V_line = loc.line as int;
}
- case (none[common.span]) {
+ case (none[common::span]) {
V_filename = C_cstr(cx.fcx.lcx.ccx, "<runtime>");
V_line = 0;
}
ret res(cx, C_nil());
}
-fn trans_put(&@block_ctxt cx, &Option.t[@ast.expr] e) -> result {
+fn trans_put(&@block_ctxt cx, &option::t[@ast::expr] e) -> result {
auto llcallee = C_nil();
auto llenv = C_nil();
cx.build.Store(lli, slot);
llcallee = cx.build.GEP(slot, vec(C_int(0),
- C_int(abi.fn_field_code)));
+ C_int(abi::fn_field_code)));
llcallee = cx.build.Load(llcallee);
llenv = cx.build.GEP(slot, vec(C_int(0),
- C_int(abi.fn_field_box)));
+ C_int(abi::fn_field_box)));
llenv = cx.build.Load(llenv);
}
}
auto dummy_retslot = alloca(bcx, T_nil());
let vec[ValueRef] llargs = vec(dummy_retslot, cx.fcx.lltaskptr, llenv);
alt (e) {
- case (none[@ast.expr]) { }
- case (some[@ast.expr](?x)) {
- auto e_ty = ty.expr_ty(cx.fcx.lcx.ccx.tcx, x);
- auto arg = rec(mode=ty.mo_alias, ty=e_ty);
+ case (none[@ast::expr]) { }
+ case (some[@ast::expr](?x)) {
+ auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, x);
+ auto arg = rec(mode=ty::mo_alias, ty=e_ty);
auto arg_tys = type_of_explicit_args(cx.fcx.lcx.ccx, vec(arg));
auto r = trans_arg_expr(bcx, arg, arg_tys.(0), x);
bcx = r.bcx;
bcx.build.Br(_break.llbb);
} else {
alt (_cont) {
- case (Option.some[@block_ctxt](?_cont)) {
+ case (option::some[@block_ctxt](?_cont)) {
bcx.build.Br(_cont.llbb);
}
case (_) {
}
-fn trans_ret(&@block_ctxt cx, &Option.t[@ast.expr] e) -> result {
+fn trans_ret(&@block_ctxt cx, &option::t[@ast::expr] e) -> result {
auto bcx = cx;
auto val = C_nil();
alt (e) {
- case (some[@ast.expr](?x)) {
- auto t = ty.expr_ty(cx.fcx.lcx.ccx.tcx, x);
+ case (some[@ast::expr](?x)) {
+ auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx, x);
auto r = trans_expr(cx, x);
bcx = r.bcx;
val = r.val;
bcx = copy_ty(bcx, INIT, cx.fcx.llretptr, val, t).bcx;
}
case (_) {
- auto t = llvm.LLVMGetElementType(val_ty(cx.fcx.llretptr));
- auto null = lib.llvm.llvm.LLVMConstNull(t);
+ auto t = llvm::LLVMGetElementType(val_ty(cx.fcx.llretptr));
+ auto null = lib::llvm::llvm::LLVMConstNull(t);
bcx.build.Store(null, cx.fcx.llretptr);
}
}
- // Run all cleanups and back out.
+ // run all cleanups and back out.
let bool more_cleanups = true;
auto cleanup_cx = cx;
while (more_cleanups) {
ret res(new_sub_block_ctxt(bcx, "ret.unreachable"), C_nil());
}
-fn trans_be(&@block_ctxt cx, &@ast.expr e) -> result {
+fn trans_be(&@block_ctxt cx, &@ast::expr e) -> result {
// FIXME: This should be a typestate precondition
- assert (ast.is_call_expr(e));
+ assert (ast::is_call_expr(e));
// FIXME: Turn this into a real tail call once
// calling convention issues are settled
ret trans_ret(cx, some(e));
}
-fn trans_port(&@block_ctxt cx, &ast.ann ann) -> result {
+fn trans_port(&@block_ctxt cx, &ast::ann ann) -> result {
auto t = node_ann_type(cx.fcx.lcx.ccx, ann);
auto unit_ty;
- alt (ty.struct(cx.fcx.lcx.ccx.tcx, t)) {
- case (ty.ty_port(?t)) {
+ alt (ty::struct(cx.fcx.lcx.ccx.tcx, t)) {
+ case (ty::ty_port(?t)) {
unit_ty = t;
}
case (_) {
ret res(bcx, port_val);
}
-fn trans_chan(&@block_ctxt cx, &@ast.expr e, &ast.ann ann) -> result {
+fn trans_chan(&@block_ctxt cx, &@ast::expr e, &ast::ann ann) -> result {
auto bcx = cx;
auto prt = trans_expr(bcx, e);
ret res(bcx, chan_val);
}
-fn trans_send(&@block_ctxt cx, &@ast.expr lhs, &@ast.expr rhs,
- &ast.ann ann) -> result {
+fn trans_send(&@block_ctxt cx, &@ast::expr lhs, &@ast::expr rhs,
+ &ast::ann ann) -> result {
auto bcx = cx;
auto chn = trans_expr(bcx, lhs);
auto chan_ty = node_ann_type(cx.fcx.lcx.ccx, ann);
auto unit_ty;
- alt (ty.struct(cx.fcx.lcx.ccx.tcx, chan_ty)) {
- case (ty.ty_chan(?t)) {
+ alt (ty::struct(cx.fcx.lcx.ccx.tcx, chan_ty)) {
+ case (ty::ty_chan(?t)) {
unit_ty = t;
}
case (_) {
ret res(bcx, chn.val);
}
-fn trans_recv(&@block_ctxt cx, &@ast.expr lhs, &@ast.expr rhs,
- &ast.ann ann) -> result {
+fn trans_recv(&@block_ctxt cx, &@ast::expr lhs, &@ast::expr rhs,
+ &ast::ann ann) -> result {
auto bcx = cx;
auto data = trans_lval(bcx, lhs);
ret recv_val(bcx, data.res.val, rhs, unit_ty, DROP_EXISTING);
}
-fn recv_val(&@block_ctxt cx, ValueRef lhs, &@ast.expr rhs,
- &ty.t unit_ty, copy_action action) -> result {
+fn recv_val(&@block_ctxt cx, ValueRef lhs, &@ast::expr rhs,
+ &ty::t unit_ty, copy_action action) -> result {
auto bcx = cx;
auto prt = trans_expr(bcx, rhs);
ret res(bcx, lhs);
}
-fn init_local(&@block_ctxt cx, &@ast.local local) -> result {
+fn init_local(&@block_ctxt cx, &@ast::local local) -> result {
// Make a note to drop this slot on the way out.
assert (cx.fcx.lllocals.contains_key(local.id));
vec(clean(bind drop_slot(_, llptr, ty)));
alt (local.init) {
- case (some[ast.initializer](?init)) {
+ case (some[ast::initializer](?init)) {
alt (init.op) {
- case (ast.init_assign) {
+ case (ast::init_assign) {
auto sub = trans_expr(bcx, init.expr);
bcx = copy_ty(sub.bcx, INIT, llptr, sub.val, ty).bcx;
}
- case (ast.init_recv) {
+ case (ast::init_recv) {
bcx = recv_val(bcx, llptr, init.expr, ty, INIT).bcx;
}
}
ret res(bcx, llptr);
}
-fn zero_alloca(&@block_ctxt cx, ValueRef llptr, ty.t t) -> result {
+fn zero_alloca(&@block_ctxt cx, ValueRef llptr, ty::t t) -> result {
auto bcx = cx;
- if (ty.type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, t)) {
+ if (ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, t)) {
auto llsz = size_of(bcx, t);
auto llalign = align_of(llsz.bcx, t);
bcx = call_bzero(llalign.bcx, llptr,
llsz.val, llalign.val).bcx;
} else {
auto llty = type_of(bcx.fcx.lcx.ccx, t);
- auto null = lib.llvm.llvm.LLVMConstNull(llty);
+ auto null = lib::llvm::llvm::LLVMConstNull(llty);
bcx.build.Store(null, llptr);
}
ret res(bcx, llptr);
}
-fn trans_stmt(&@block_ctxt cx, &ast.stmt s) -> result {
+fn trans_stmt(&@block_ctxt cx, &ast::stmt s) -> result {
auto bcx = cx;
alt (s.node) {
- case (ast.stmt_expr(?e,_)) {
+ case (ast::stmt_expr(?e,_)) {
bcx = trans_expr(cx, e).bcx;
}
- case (ast.stmt_decl(?d,_)) {
+ case (ast::stmt_decl(?d,_)) {
alt (d.node) {
- case (ast.decl_local(?local)) {
+ case (ast::decl_local(?local)) {
bcx = init_local(bcx, local).bcx;
}
- case (ast.decl_item(?i)) {
+ case (ast::decl_item(?i)) {
trans_item(cx.fcx.lcx, *i);
}
}
}
fn new_builder(BasicBlockRef llbb) -> builder {
- let BuilderRef llbuild = llvm.LLVMCreateBuilder();
- llvm.LLVMPositionBuilderAtEnd(llbuild, llbb);
+ let BuilderRef llbuild = llvm::LLVMCreateBuilder();
+ llvm::LLVMPositionBuilderAtEnd(llbuild, llbb);
ret builder(llbuild, @mutable false);
}
block_kind kind,
&str name) -> @block_ctxt {
let vec[cleanup] cleanups = vec();
- auto s = Str.buf("");
+ auto s = _str::buf("");
if (cx.lcx.ccx.sess.get_opts().save_temps) {
- s = Str.buf(cx.lcx.ccx.names.next(name));
+ s = _str::buf(cx.lcx.ccx.names.next(name));
}
- let BasicBlockRef llbb = llvm.LLVMAppendBasicBlock(cx.llfn, s);
+ let BasicBlockRef llbb = llvm::LLVMAppendBasicBlock(cx.llfn, s);
ret @rec(llbb=llbb,
build=new_builder(llbb),
parent=parent,
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,
+fn new_loop_scope_block_ctxt(&@block_ctxt bcx, &option::t[@block_ctxt] _cont,
&@block_ctxt _break, &str n) -> @block_ctxt {
ret new_block_ctxt(bcx.fcx, parent_some(bcx),
LOOP_SCOPE_BLOCK(_cont, _break), n);
auto bcx = cx;
if (cleanup_cx.kind == NON_SCOPE_BLOCK) {
- assert (Vec.len[cleanup](cleanup_cx.cleanups) == 0u);
+ assert (_vec::len[cleanup](cleanup_cx.cleanups) == 0u);
}
- auto i = Vec.len[cleanup](cleanup_cx.cleanups);
+ auto i = _vec::len[cleanup](cleanup_cx.cleanups);
while (i > 0u) {
i -= 1u;
auto c = cleanup_cx.cleanups.(i);
ret bcx;
}
-iter block_locals(&ast.block b) -> @ast.local {
+iter block_locals(&ast::block b) -> @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) {
+ for (@ast::stmt s in b.node.stmts) {
alt (s.node) {
- case (ast.stmt_decl(?d,_)) {
+ case (ast::stmt_decl(?d,_)) {
alt (d.node) {
- case (ast.decl_local(?local)) {
+ case (ast::decl_local(?local)) {
put local;
}
case (_) { /* fall through */ }
fcx=fcx);
}
-fn alloc_ty(&@block_ctxt cx, &ty.t t) -> result {
+fn alloc_ty(&@block_ctxt cx, &ty::t t) -> result {
auto val = C_int(0);
- if (ty.type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, t)) {
+ if (ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, t)) {
// NB: we have to run this particular 'size_of' in a
// block_ctxt built on the llallocas block for the fn,
ret res(cx, val);
}
-fn alloc_local(&@block_ctxt cx, &@ast.local local) -> result {
+fn alloc_local(&@block_ctxt cx, &@ast::local local) -> result {
auto t = node_ann_type(cx.fcx.lcx.ccx, local.ann);
auto r = alloc_ty(cx, t);
r.bcx.fcx.lllocals.insert(local.id, r.val);
ret r;
}
-fn trans_block(&@block_ctxt cx, &ast.block b) -> result {
+fn trans_block(&@block_ctxt cx, &ast::block b) -> result {
auto bcx = cx;
- for each (@ast.local local in block_locals(b)) {
+ for each (@ast::local local in block_locals(b)) {
bcx = alloc_local(bcx, local).bcx;
}
auto r = res(bcx, C_nil());
- for (@ast.stmt s in b.node.stmts) {
+ for (@ast::stmt s in b.node.stmts) {
r = trans_stmt(bcx, *s);
bcx = r.bcx;
// If we hit a terminator, control won't go any further so
}
alt (b.node.expr) {
- case (some[@ast.expr](?e)) {
+ case (some[@ast::expr](?e)) {
r = trans_expr(bcx, e);
bcx = r.bcx;
if (is_terminated(bcx)) {
ret r;
} else {
- auto r_ty = ty.expr_ty(cx.fcx.lcx.ccx.tcx, e);
- if (!ty.type_is_nil(cx.fcx.lcx.ccx.tcx, r_ty)) {
+ auto r_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e);
+ if (!ty::type_is_nil(cx.fcx.lcx.ccx.tcx, r_ty)) {
// The value resulting from the block gets copied into an
// alloca created in an outer scope and its refcount
// bumped so that it can escape this block. This means
fn drop_hoisted_ty(&@block_ctxt cx,
ValueRef alloca_val,
- ty.t t) -> result {
+ ty::t t) -> result {
auto reg_val = load_if_immediate(cx,
alloca_val, t);
ret drop_ty(cx, reg_val, t);
}
}
}
- case (none[@ast.expr]) {
+ case (none[@ast::expr]) {
r = res(bcx, C_nil());
}
}
fn new_local_ctxt(&@crate_ctxt ccx) -> @local_ctxt {
let vec[str] pth = vec();
- let vec[ast.ty_param] obj_typarams = vec();
- let vec[ast.obj_field] obj_fields = vec();
+ let vec[ast::ty_param] obj_typarams = vec();
+ let vec[ast::obj_field] obj_fields = vec();
ret @rec(path=pth,
module_path=vec(crate_name(ccx, "main")),
obj_typarams = obj_typarams,
// tydescs.
fn mk_standard_basic_blocks(ValueRef llfn) ->
tup(BasicBlockRef, BasicBlockRef, BasicBlockRef) {
- ret tup(llvm.LLVMAppendBasicBlock(llfn, Str.buf("allocas")),
- llvm.LLVMAppendBasicBlock(llfn, Str.buf("copy_args")),
- llvm.LLVMAppendBasicBlock(llfn, Str.buf("derived_tydescs")));
+ ret tup(llvm::LLVMAppendBasicBlock(llfn, _str::buf("allocas")),
+ llvm::LLVMAppendBasicBlock(llfn, _str::buf("copy_args")),
+ llvm::LLVMAppendBasicBlock(llfn, _str::buf("derived_tydescs")));
}
// NB: must keep 4 fns in sync:
fn new_fn_ctxt(@local_ctxt cx,
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 ValueRef llretptr = llvm::LLVMGetParam(llfndecl, 0u);
+ let ValueRef lltaskptr = llvm::LLVMGetParam(llfndecl, 1u);
+ let ValueRef llenv = llvm::LLVMGetParam(llfndecl, 2u);
- let hashmap[ast.def_id, ValueRef] llargs = new_def_hash[ValueRef]();
- let hashmap[ast.def_id, ValueRef] llobjfields = new_def_hash[ValueRef]();
- let hashmap[ast.def_id, ValueRef] lllocals = new_def_hash[ValueRef]();
- let hashmap[ast.def_id, ValueRef] llupvars = new_def_hash[ValueRef]();
+ let hashmap[ast::def_id, ValueRef] llargs = new_def_hash[ValueRef]();
+ let hashmap[ast::def_id, ValueRef] llobjfields = new_def_hash[ValueRef]();
+ let hashmap[ast::def_id, ValueRef] lllocals = new_def_hash[ValueRef]();
+ let hashmap[ast::def_id, ValueRef] llupvars = new_def_hash[ValueRef]();
auto derived_tydescs =
- Map.mk_hashmap[ty.t, derived_tydesc_info](ty.hash_ty, ty.eq_ty);
+ map::mk_hashmap[ty::t, derived_tydesc_info](ty::hash_ty, ty::eq_ty);
auto llbbs = mk_standard_basic_blocks(llfndecl);
llobjfields=llobjfields,
lllocals=lllocals,
llupvars=llupvars,
- mutable lltydescs=Vec.empty[ValueRef](),
+ mutable lltydescs=_vec::empty[ValueRef](),
derived_tydescs=derived_tydescs,
lcx=cx);
}
// - trans_args
fn create_llargs_for_fn_args(&@fn_ctxt cx,
- ast.proto proto,
- Option.t[tup(TypeRef, ty.t)] ty_self,
- ty.t ret_ty,
- &vec[ast.arg] args,
- &vec[ast.ty_param] ty_params) {
+ ast::proto proto,
+ option::t[tup(TypeRef, ty::t)] ty_self,
+ ty::t ret_ty,
+ &vec[ast::arg] args,
+ &vec[ast::ty_param] ty_params) {
auto arg_n = 3u;
alt (ty_self) {
- case (some[tup(TypeRef, ty.t)](?tt)) {
+ case (some[tup(TypeRef, ty::t)](?tt)) {
cx.llself = some[self_vt](rec(v = cx.llenv, t = tt._1));
}
- case (none[tup(TypeRef, ty.t)]) {
+ case (none[tup(TypeRef, ty::t)]) {
auto i = 0u;
- for (ast.ty_param tp in ty_params) {
- auto llarg = llvm.LLVMGetParam(cx.llfn, arg_n);
+ for (ast::ty_param tp in ty_params) {
+ auto llarg = llvm::LLVMGetParam(cx.llfn, arg_n);
assert (llarg as int != 0);
cx.lltydescs += vec(llarg);
arg_n += 1u;
}
}
- if (proto == ast.proto_iter) {
- auto llarg = llvm.LLVMGetParam(cx.llfn, arg_n);
+ if (proto == ast::proto_iter) {
+ auto llarg = llvm::LLVMGetParam(cx.llfn, arg_n);
assert (llarg as int != 0);
cx.lliterbody = some[ValueRef](llarg);
arg_n += 1u;
}
- for (ast.arg arg in args) {
- auto llarg = llvm.LLVMGetParam(cx.llfn, arg_n);
+ for (ast::arg arg in args) {
+ auto llarg = llvm::LLVMGetParam(cx.llfn, arg_n);
assert (llarg as int != 0);
cx.llargs.insert(arg.id, llarg);
arg_n += 1u;
// were passed and whatnot. Apparently mem2reg will mop up.
fn copy_any_self_to_alloca(@fn_ctxt fcx,
- Option.t[tup(TypeRef, ty.t)] ty_self) {
+ option::t[tup(TypeRef, ty::t)] ty_self) {
auto bcx = llallocas_block_ctxt(fcx);
alt (fcx.llself) {
case (some[self_vt](?s_vt)) {
alt (ty_self) {
- case (some[tup(TypeRef, ty.t)](?tt)) {
+ case (some[tup(TypeRef, ty::t)](?tt)) {
auto a = alloca(bcx, tt._0);
bcx.build.Store(s_vt.v, a);
fcx.llself = some[self_vt](rec(v = a, t = s_vt.t));
fn copy_args_to_allocas(@fn_ctxt fcx,
- vec[ast.arg] args,
- vec[ty.arg] arg_tys) {
+ vec[ast::arg] args,
+ vec[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.alias) {
+ for (ast::arg aarg in args) {
+ if (aarg.mode != ast::alias) {
auto arg_t = type_of_arg(bcx.fcx.lcx, arg_tys.(arg_n));
auto a = alloca(bcx, arg_t);
auto argval = bcx.fcx.llargs.get(aarg.id);
}
fn add_cleanups_for_args(&@block_ctxt bcx,
- vec[ast.arg] args,
- vec[ty.arg] arg_tys) {
+ vec[ast::arg] args,
+ vec[ty::arg] arg_tys) {
let uint arg_n = 0u;
- for (ast.arg aarg in args) {
- if (aarg.mode != ast.alias) {
+ for (ast::arg aarg in args) {
+ if (aarg.mode != ast::alias) {
auto argval = bcx.fcx.llargs.get(aarg.id);
find_scope_cx(bcx).cleanups +=
vec(clean(bind drop_slot(_, argval, arg_tys.(arg_n).ty)));
fn is_terminated(&@block_ctxt cx) -> bool {
- auto inst = llvm.LLVMGetLastInstruction(cx.llbb);
- ret llvm.LLVMIsATerminatorInst(inst) as int != 0;
+ auto inst = llvm::LLVMGetLastInstruction(cx.llbb);
+ ret llvm::LLVMIsATerminatorInst(inst) as int != 0;
}
-fn arg_tys_of_fn(&@crate_ctxt ccx, ast.ann ann) -> vec[ty.arg] {
- alt (ty.struct(ccx.tcx, ty.ann_to_type(ann))) {
- case (ty.ty_fn(_, ?arg_tys, _)) {
+fn arg_tys_of_fn(&@crate_ctxt ccx, ast::ann ann) -> vec[ty::arg] {
+ alt (ty::struct(ccx.tcx, ty::ann_to_type(ann))) {
+ case (ty::ty_fn(_, ?arg_tys, _)) {
ret arg_tys;
}
}
fail;
}
-fn ret_ty_of_fn_ty(&@crate_ctxt ccx, ty.t t) -> ty.t {
- alt (ty.struct(ccx.tcx, t)) {
- case (ty.ty_fn(_, _, ?ret_ty)) {
+fn ret_ty_of_fn_ty(&@crate_ctxt ccx, ty::t t) -> ty::t {
+ alt (ty::struct(ccx.tcx, t)) {
+ case (ty::ty_fn(_, _, ?ret_ty)) {
ret ret_ty;
}
}
}
-fn ret_ty_of_fn(&@crate_ctxt ccx, ast.ann ann) -> ty.t {
- ret ret_ty_of_fn_ty(ccx, ty.ann_to_type(ann));
+fn ret_ty_of_fn(&@crate_ctxt ccx, ast::ann ann) -> ty::t {
+ ret ret_ty_of_fn_ty(ccx, ty::ann_to_type(ann));
}
fn populate_fn_ctxt_from_llself(@fn_ctxt fcx, self_vt llself) {
auto bcx = llallocas_block_ctxt(fcx);
- let vec[ty.t] field_tys = vec();
+ let vec[ty::t] field_tys = vec();
- for (ast.obj_field f in bcx.fcx.lcx.obj_fields) {
+ for (ast::obj_field f in bcx.fcx.lcx.obj_fields) {
field_tys += vec(node_ann_type(bcx.fcx.lcx.ccx, f.ann));
}
// 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 fields_tup_ty = ty::mk_imm_tup(fcx.lcx.ccx.tcx, field_tys);
- auto n_typarams = Vec.len[ast.ty_param](bcx.fcx.lcx.obj_typarams);
+ auto n_typarams = _vec::len[ast::ty_param](bcx.fcx.lcx.obj_typarams);
let TypeRef llobj_box_ty = T_obj_ptr(bcx.fcx.lcx.ccx.tn, n_typarams);
auto box_cell =
bcx.build.GEP(llself.v,
vec(C_int(0),
- C_int(abi.obj_field_box)));
+ C_int(abi::obj_field_box)));
auto box_ptr = bcx.build.Load(box_cell);
auto obj_typarams = bcx.build.GEP(box_ptr,
vec(C_int(0),
- C_int(abi.box_rc_field_body),
- C_int(abi.obj_body_elt_typarams)));
+ C_int(abi::box_rc_field_body),
+ 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 obj_fields = bcx.build.Add(vp2i(bcx, obj_typarams),
- llsize_of(llvm.LLVMGetElementType(val_ty(obj_typarams))));
+ llsize_of(llvm::LLVMGetElementType(val_ty(obj_typarams))));
// 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)) {
+ if (!ty::type_has_dynamic_size(fcx.lcx.ccx.tcx, fields_tup_ty)) {
auto llfields_ty = type_of(fcx.lcx.ccx, fields_tup_ty);
obj_fields = vi2p(bcx, obj_fields, T_ptr(llfields_ty));
} else {
let int i = 0;
- for (ast.ty_param p in fcx.lcx.obj_typarams) {
+ for (ast::ty_param p in fcx.lcx.obj_typarams) {
let ValueRef lltyparam = bcx.build.GEP(obj_typarams,
vec(C_int(0),
C_int(i)));
}
i = 0;
- for (ast.obj_field f in fcx.lcx.obj_fields) {
+ for (ast::obj_field f in fcx.lcx.obj_fields) {
auto rslt = GEP_tup_like(bcx, fields_tup_ty, obj_fields, vec(0, i));
bcx = llallocas_block_ctxt(fcx);
auto llfield = rslt.val;
new_builder(fcx.llderivedtydescs).Br(lltop);
}
-fn trans_fn(@local_ctxt cx, &ast._fn f, ast.def_id fid,
- Option.t[tup(TypeRef, ty.t)] ty_self,
- &vec[ast.ty_param] ty_params, &ast.ann ann) {
+fn trans_fn(@local_ctxt cx, &ast::_fn f, ast::def_id fid,
+ option::t[tup(TypeRef, ty::t)] ty_self,
+ &vec[ast::ty_param] ty_params, &ast::ann ann) {
auto llfndecl = cx.ccx.item_ids.get(fid);
auto fcx = new_fn_ctxt(cx, llfndecl);
fn trans_vtbl(@local_ctxt cx,
TypeRef llself_ty,
- ty.t self_ty,
- &ast._obj ob,
- &vec[ast.ty_param] ty_params) -> ValueRef {
+ ty::t self_ty,
+ &ast::_obj ob,
+ &vec[ast::ty_param] ty_params) -> ValueRef {
auto dtor = C_null(T_ptr(T_i8()));
alt (ob.dtor) {
- case (some[@ast.method](?d)) {
+ case (some[@ast::method](?d)) {
auto dtor_1 = trans_dtor(cx, llself_ty, self_ty, ty_params, d);
- dtor = llvm.LLVMConstBitCast(dtor_1, val_ty(dtor));
+ dtor = llvm::LLVMConstBitCast(dtor_1, val_ty(dtor));
}
- case (none[@ast.method]) {}
+ case (none[@ast::method]) {}
}
let vec[ValueRef] methods = vec(dtor);
- fn meth_lteq(&@ast.method a, &@ast.method b) -> bool {
- ret Str.lteq(a.node.ident, b.node.ident);
+ fn meth_lteq(&@ast::method a, &@ast::method b) -> bool {
+ ret _str::lteq(a.node.ident, b.node.ident);
}
- auto meths = std.Sort.merge_sort[@ast.method](bind meth_lteq(_,_),
+ auto meths = std::sort::merge_sort[@ast::method](bind meth_lteq(_,_),
ob.methods);
- for (@ast.method m in meths) {
+ for (@ast::method m in meths) {
auto llfnty = T_nil();
- alt (ty.struct(cx.ccx.tcx, node_ann_type(cx.ccx, m.node.ann))) {
- case (ty.ty_fn(?proto, ?inputs, ?output)) {
+ alt (ty::struct(cx.ccx.tcx, node_ann_type(cx.ccx, m.node.ann))) {
+ case (ty::ty_fn(?proto, ?inputs, ?output)) {
llfnty = type_of_fn_full(cx.ccx, proto,
some[TypeRef](llself_ty),
inputs, output,
- Vec.len[ast.ty_param](ty_params));
+ _vec::len[ast::ty_param](ty_params));
}
}
cx.ccx.item_symbols.insert(m.node.id, s);
trans_fn(mcx, m.node.meth, m.node.id,
- some[tup(TypeRef, ty.t)](tup(llself_ty, self_ty)),
+ some[tup(TypeRef, ty::t)](tup(llself_ty, self_ty)),
ty_params, m.node.ann);
methods += vec(llfn);
}
auto vtbl = C_struct(methods);
auto vtbl_name = mangle_name_by_seq(cx.ccx, cx.path, "vtbl");
- auto gvar = llvm.LLVMAddGlobal(cx.ccx.llmod, val_ty(vtbl),
- Str.buf(vtbl_name));
- llvm.LLVMSetInitializer(gvar, vtbl);
- llvm.LLVMSetGlobalConstant(gvar, True);
- llvm.LLVMSetLinkage(gvar, lib.llvm.LLVMInternalLinkage
- as llvm.Linkage);
+ auto gvar = llvm::LLVMAddGlobal(cx.ccx.llmod, val_ty(vtbl),
+ _str::buf(vtbl_name));
+ llvm::LLVMSetInitializer(gvar, vtbl);
+ llvm::LLVMSetGlobalConstant(gvar, True);
+ llvm::LLVMSetLinkage(gvar, lib::llvm::LLVMInternalLinkage
+ as llvm::Linkage);
ret gvar;
}
fn trans_dtor(@local_ctxt cx,
TypeRef llself_ty,
- ty.t self_ty,
- &vec[ast.ty_param] ty_params,
- &@ast.method dtor) -> ValueRef {
+ ty::t self_ty,
+ &vec[ast::ty_param] ty_params,
+ &@ast::method dtor) -> ValueRef {
auto llfnty = T_dtor(cx.ccx, llself_ty);
let @local_ctxt dcx = extend_path(cx, "drop");
cx.ccx.item_symbols.insert(dtor.node.id, s);
trans_fn(dcx, dtor.node.meth, dtor.node.id,
- some[tup(TypeRef, ty.t)](tup(llself_ty, self_ty)),
+ some[tup(TypeRef, ty::t)](tup(llself_ty, self_ty)),
ty_params, dtor.node.ann);
ret llfn;
}
-fn trans_obj(@local_ctxt cx, &ast._obj ob, ast.def_id oid,
- &vec[ast.ty_param] ty_params, &ast.ann ann) {
+fn trans_obj(@local_ctxt cx, &ast::_obj ob, ast::def_id oid,
+ &vec[ast::ty_param] ty_params, &ast::ann ann) {
auto ccx = cx.ccx;
auto llctor_decl = ccx.item_ids.get(oid);
// Translate obj ctor args to function arguments.
- let vec[ast.arg] fn_args = vec();
- for (ast.obj_field f in ob.fields) {
- fn_args += vec(rec(mode=ast.alias, ty=f.ty, ident=f.ident, id=f.id));
+ let vec[ast::arg] fn_args = vec();
+ for (ast::obj_field f in ob.fields) {
+ fn_args += vec(rec(mode=ast::alias, ty=f.ty, ident=f.ident, id=f.id));
}
auto fcx = new_fn_ctxt(cx, llctor_decl);
- create_llargs_for_fn_args(fcx, ast.proto_fn,
- none[tup(TypeRef, ty.t)],
+ create_llargs_for_fn_args(fcx, ast::proto_fn,
+ none[tup(TypeRef, ty::t)],
ret_ty_of_fn(ccx, ann),
fn_args, ty_params);
- let vec[ty.arg] arg_tys = arg_tys_of_fn(ccx, ann);
+ let vec[ty::arg] arg_tys = arg_tys_of_fn(ccx, ann);
copy_args_to_allocas(fcx, fn_args, arg_tys);
auto bcx = new_top_block_ctxt(fcx);
auto vtbl = trans_vtbl(cx, llself_ty, self_ty, ob, ty_params);
auto pair_vtbl = bcx.build.GEP(pair,
vec(C_int(0),
- C_int(abi.obj_field_vtbl)));
+ C_int(abi::obj_field_vtbl)));
auto pair_box = bcx.build.GEP(pair,
vec(C_int(0),
- C_int(abi.obj_field_box)));
+ C_int(abi::obj_field_box)));
bcx.build.Store(vtbl, pair_vtbl);
let TypeRef llbox_ty = T_opaque_obj_ptr(ccx.tn);
// 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 (Vec.len[ast.ty_param](ty_params) == 0u &&
- Vec.len[ty.arg](arg_tys) == 0u) {
+ if (_vec::len[ast::ty_param](ty_params) == 0u &&
+ _vec::len[ty::arg](arg_tys) == 0u) {
// Store null into pair, if no args or typarams.
bcx.build.Store(C_null(llbox_ty), pair_box);
} else {
// Malloc a box for the body and copy args in.
- let vec[ty.t] obj_fields = vec();
- for (ty.arg a in arg_tys) {
- Vec.push[ty.t](obj_fields, a.ty);
+ let vec[ty::t] obj_fields = vec();
+ for (ty::arg a in arg_tys) {
+ _vec::push[ty::t](obj_fields, a.ty);
}
// Synthesize an obj body type.
- auto tydesc_ty = ty.mk_type(ccx.tcx);
- let vec[ty.t] tps = vec();
- for (ast.ty_param tp in ty_params) {
- Vec.push[ty.t](tps, tydesc_ty);
+ auto tydesc_ty = ty::mk_type(ccx.tcx);
+ let vec[ty::t] tps = vec();
+ for (ast::ty_param tp in ty_params) {
+ _vec::push[ty::t](tps, tydesc_ty);
}
- let ty.t typarams_ty = ty.mk_imm_tup(ccx.tcx, tps);
- let ty.t fields_ty = ty.mk_imm_tup(ccx.tcx, obj_fields);
- let ty.t body_ty = ty.mk_imm_tup(ccx.tcx,
+ let ty::t typarams_ty = ty::mk_imm_tup(ccx.tcx, tps);
+ let ty::t fields_ty = ty::mk_imm_tup(ccx.tcx, obj_fields);
+ let ty::t body_ty = ty::mk_imm_tup(ccx.tcx,
vec(tydesc_ty,
typarams_ty,
fields_ty));
- let ty.t boxed_body_ty = ty.mk_imm_box(ccx.tcx, body_ty);
+ let ty::t boxed_body_ty = ty::mk_imm_box(ccx.tcx, body_ty);
// Malloc a box for the body.
auto box = trans_malloc_boxed(bcx, body_ty);
bcx = box.bcx;
auto rc = GEP_tup_like(bcx, boxed_body_ty, box.val,
- vec(0, abi.box_rc_field_refcnt));
+ vec(0, abi::box_rc_field_refcnt));
bcx = rc.bcx;
auto body = GEP_tup_like(bcx, boxed_body_ty, box.val,
- vec(0, abi.box_rc_field_body));
+ vec(0, abi::box_rc_field_body));
bcx = body.bcx;
bcx.build.Store(C_int(1), rc.val);
// Store body tydesc.
auto body_tydesc =
GEP_tup_like(bcx, body_ty, body.val,
- vec(0, abi.obj_body_elt_tydesc));
+ vec(0, abi::obj_body_elt_tydesc));
bcx = body_tydesc.bcx;
auto body_td = get_tydesc(bcx, body_ty, true);
auto dtor = C_null(T_ptr(T_glue_fn(ccx.tn)));
alt (ob.dtor) {
- case (some[@ast.method](?d)) {
+ case (some[@ast::method](?d)) {
dtor = trans_dtor(cx, llself_ty, self_ty, ty_params, d);
}
- case (none[@ast.method]) {}
+ case (none[@ast::method]) {}
}
bcx = body_td.bcx;
// Copy typarams into captured typarams.
auto body_typarams =
GEP_tup_like(bcx, body_ty, body.val,
- vec(0, abi.obj_body_elt_typarams));
+ vec(0, abi::obj_body_elt_typarams));
bcx = body_typarams.bcx;
let int i = 0;
- for (ast.ty_param tp in ty_params) {
+ for (ast::ty_param tp in ty_params) {
auto typaram = bcx.fcx.lltydescs.(i);
auto capture = GEP_tup_like(bcx, typarams_ty, body_typarams.val,
vec(0, i));
// Copy args into body fields.
auto body_fields =
GEP_tup_like(bcx, body_ty, body.val,
- vec(0, abi.obj_body_elt_fields));
+ vec(0, abi::obj_body_elt_fields));
bcx = body_fields.bcx;
i = 0;
- for (ast.obj_field f in ob.fields) {
+ for (ast::obj_field f in ob.fields) {
auto arg = bcx.fcx.llargs.get(f.id);
arg = load_if_immediate(bcx, arg, arg_tys.(i).ty);
auto field = GEP_tup_like(bcx, fields_ty, body_fields.val,
finish_fn(fcx, lltop);
}
-fn trans_tag_variant(@local_ctxt cx, ast.def_id tag_id,
- &ast.variant variant, int index,
- &vec[ast.ty_param] ty_params) {
- if (Vec.len[ast.variant_arg](variant.node.args) == 0u) {
+fn trans_tag_variant(@local_ctxt cx, ast::def_id tag_id,
+ &ast::variant variant, int index,
+ &vec[ast::ty_param] ty_params) {
+ if (_vec::len[ast::variant_arg](variant.node.args) == 0u) {
ret; // nullary constructors are just constants
}
// Translate variant arguments to function arguments.
- let vec[ast.arg] fn_args = vec();
+ let vec[ast::arg] fn_args = vec();
auto i = 0u;
- for (ast.variant_arg varg in variant.node.args) {
- fn_args += vec(rec(mode=ast.alias,
+ for (ast::variant_arg varg in variant.node.args) {
+ fn_args += vec(rec(mode=ast::alias,
ty=varg.ty,
- ident="arg" + UInt.to_str(i, 10u),
+ ident="arg" + _uint::to_str(i, 10u),
id=varg.id));
}
auto fcx = new_fn_ctxt(cx, llfndecl);
- create_llargs_for_fn_args(fcx, ast.proto_fn,
- none[tup(TypeRef, ty.t)],
+ create_llargs_for_fn_args(fcx, ast::proto_fn,
+ none[tup(TypeRef, ty::t)],
ret_ty_of_fn(cx.ccx, variant.node.ann),
fn_args, ty_params);
- let vec[ty.t] ty_param_substs = vec();
+ let vec[ty::t] ty_param_substs = vec();
i = 0u;
- for (ast.ty_param tp in ty_params) {
- ty_param_substs += vec(ty.mk_param(cx.ccx.tcx, i));
+ for (ast::ty_param tp in ty_params) {
+ ty_param_substs += vec(ty::mk_param(cx.ccx.tcx, i));
i += 1u;
}
vec(C_int(0), C_int(1)));
i = 0u;
- for (ast.variant_arg va in variant.node.args) {
+ for (ast::variant_arg va in variant.node.args) {
auto rslt = GEP_tag(bcx, llblobptr, tag_id, variant.node.id,
ty_param_substs, i as int);
bcx = rslt.bcx;
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)) {
+ 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);
// 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 {
+fn trans_const_expr(&@crate_ctxt cx, @ast::expr e) -> ValueRef {
alt (e.node) {
- case (ast.expr_lit(?lit, ?ann)) {
+ case (ast::expr_lit(?lit, ?ann)) {
ret trans_lit(cx, *lit, ann);
}
case (_) {
}
}
-fn trans_const(&@crate_ctxt cx, @ast.expr e,
- &ast.def_id cid, &ast.ann ann) {
+fn trans_const(&@crate_ctxt cx, @ast::expr e,
+ &ast::def_id cid, &ast::ann ann) {
auto t = node_ann_type(cx, ann);
auto v = trans_const_expr(cx, e);
// The scalars come back as 1st class LLVM vals
// which we have to stick into global constants.
auto g = cx.consts.get(cid);
- llvm.LLVMSetInitializer(g, v);
- llvm.LLVMSetGlobalConstant(g, True);
+ llvm::LLVMSetInitializer(g, v);
+ llvm::LLVMSetGlobalConstant(g, True);
}
-fn trans_item(@local_ctxt cx, &ast.item item) {
+fn trans_item(@local_ctxt cx, &ast::item item) {
alt (item.node) {
- case (ast.item_fn(?name, ?f, ?tps, ?fid, ?ann)) {
+ case (ast::item_fn(?name, ?f, ?tps, ?fid, ?ann)) {
auto sub_cx = extend_path(cx, name);
- trans_fn(sub_cx, f, fid, none[tup(TypeRef, ty.t)], tps, ann);
+ trans_fn(sub_cx, f, fid, none[tup(TypeRef, ty::t)], tps, ann);
}
- case (ast.item_obj(?name, ?ob, ?tps, ?oid, ?ann)) {
+ case (ast::item_obj(?name, ?ob, ?tps, ?oid, ?ann)) {
auto sub_cx = @rec(obj_typarams=tps,
obj_fields=ob.fields with
*extend_path(cx, name));
trans_obj(sub_cx, ob, oid.ctor, tps, ann);
}
- case (ast.item_mod(?name, ?m, _)) {
+ case (ast::item_mod(?name, ?m, _)) {
auto sub_cx = @rec(path = cx.path + vec(name),
module_path = cx.module_path + vec(name)
with *cx);
trans_mod(sub_cx, m);
}
- case (ast.item_tag(?name, ?variants, ?tps, ?tag_id, _)) {
+ case (ast::item_tag(?name, ?variants, ?tps, ?tag_id, _)) {
auto sub_cx = extend_path(cx, name);
auto i = 0;
- for (ast.variant variant in variants) {
+ for (ast::variant variant in variants) {
trans_tag_variant(sub_cx, tag_id, variant, i, tps);
i += 1;
}
}
- case (ast.item_const(?name, _, ?expr, ?cid, ?ann)) {
+ case (ast::item_const(?name, _, ?expr, ?cid, ?ann)) {
trans_const(cx.ccx, expr, cid, ann);
}
case (_) { /* fall through */ }
}
}
-fn trans_mod(@local_ctxt cx, &ast._mod m) {
- for (@ast.item item in m.items) {
+fn trans_mod(@local_ctxt cx, &ast::_mod m) {
+ for (@ast::item item in m.items) {
trans_item(cx, *item);
}
}
fn get_pair_fn_ty(TypeRef llpairty) -> TypeRef {
// Bit of a kludge: pick the fn typeref out of the pair.
let vec[TypeRef] pair_tys = vec(T_nil(), T_nil());
- llvm.LLVMGetStructElementTypes(llpairty,
- Vec.buf[TypeRef](pair_tys));
- ret llvm.LLVMGetElementType(pair_tys.(0));
+ llvm::LLVMGetStructElementTypes(llpairty,
+ _vec::buf[TypeRef](pair_tys));
+ ret llvm::LLVMGetElementType(pair_tys.(0));
}
fn decl_fn_and_pair(&@crate_ctxt ccx,
vec[str] path,
str flav,
- vec[ast.ty_param] ty_params,
- &ast.ann ann,
- ast.def_id id) {
+ vec[ast::ty_param] ty_params,
+ &ast::ann ann,
+ ast::def_id id) {
auto llfty;
auto llpairty;
- alt (ty.struct(ccx.tcx, node_ann_type(ccx, ann))) {
- case (ty.ty_fn(?proto, ?inputs, ?output)) {
+ alt (ty::struct(ccx.tcx, node_ann_type(ccx, ann))) {
+ case (ty::ty_fn(?proto, ?inputs, ?output)) {
llfty = type_of_fn(ccx, proto, inputs, output,
- Vec.len[ast.ty_param](ty_params));
+ _vec::len[ast::ty_param](ty_params));
llpairty = T_fn_pair(ccx.tn, llfty);
}
case (_) {
}
fn register_fn_pair(&@crate_ctxt cx, str ps, TypeRef llpairty, ValueRef llfn,
- ast.def_id id) {
- let ValueRef gvar = llvm.LLVMAddGlobal(cx.llmod, llpairty,
- Str.buf(ps));
+ ast::def_id id) {
+ let ValueRef gvar = llvm::LLVMAddGlobal(cx.llmod, llpairty,
+ _str::buf(ps));
auto pair = C_struct(vec(llfn,
C_null(T_opaque_closure_ptr(cx.tn))));
- llvm.LLVMSetInitializer(gvar, pair);
- llvm.LLVMSetGlobalConstant(gvar, True);
- llvm.LLVMSetVisibility(gvar,
- lib.llvm.LLVMProtectedVisibility
- as llvm.Visibility);
+ llvm::LLVMSetInitializer(gvar, pair);
+ llvm::LLVMSetGlobalConstant(gvar, True);
+ llvm::LLVMSetVisibility(gvar,
+ lib::llvm::LLVMProtectedVisibility
+ as llvm::Visibility);
cx.item_ids.insert(id, llfn);
cx.item_symbols.insert(id, ps);
}
// Returns the number of type parameters that the given native function has.
-fn native_fn_ty_param_count(&@crate_ctxt cx, &ast.def_id id) -> uint {
+fn native_fn_ty_param_count(&@crate_ctxt cx, &ast::def_id id) -> uint {
auto count;
auto native_item = cx.native_items.get(id);
alt (native_item.node) {
- case (ast.native_item_ty(_,_)) {
+ case (ast::native_item_ty(_,_)) {
cx.sess.bug("decl_native_fn_and_pair(): native fn isn't " +
"actually a fn?!");
fail;
}
- case (ast.native_item_fn(_, _, _, ?tps, _, _)) {
- count = Vec.len[ast.ty_param](tps);
+ case (ast::native_item_fn(_, _, _, ?tps, _, _)) {
+ count = _vec::len[ast::ty_param](tps);
}
}
ret count;
}
-fn native_fn_wrapper_type(&@crate_ctxt cx, uint ty_param_count, ty.t x)
+fn native_fn_wrapper_type(&@crate_ctxt cx, 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, ast.proto_fn, args, out, ty_param_count);
+ alt (ty::struct(cx.tcx, x)) {
+ case (ty::ty_native_fn(?abi, ?args, ?out)) {
+ ret type_of_fn(cx, ast::proto_fn, args, out, ty_param_count);
}
}
fail;
fn decl_native_fn_and_pair(&@crate_ctxt ccx,
vec[str] path,
str name,
- &ast.ann ann,
- ast.def_id id) {
+ &ast::ann ann,
+ ast::def_id id) {
auto num_ty_param = native_fn_ty_param_count(ccx, id);
// Declare the wrapper.
auto item = ccx.native_items.get(id);
auto fn_type = node_ann_type(ccx, ann); // NB: has no type params
- auto abi = ty.ty_fn_abi(ccx.tcx, fn_type);
+ auto abi = ty::ty_fn_abi(ccx.tcx, fn_type);
auto llfnty = type_of_native_fn(ccx, abi,
- ty.ty_fn_args(ccx.tcx, fn_type),
- ty.ty_fn_ret(ccx.tcx, fn_type), num_ty_param);
+ ty::ty_fn_args(ccx.tcx, fn_type),
+ ty::ty_fn_ret(ccx.tcx, fn_type), num_ty_param);
// 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_is_nil = ty.type_is_nil(ccx.tcx, ty.ty_fn_ret(ccx.tcx, fn_type));
+ auto rty_is_nil = ty::type_is_nil(ccx.tcx, ty::ty_fn_ret(ccx.tcx,
+ fn_type));
auto pass_task;
auto cast_to_i32;
alt (abi) {
- case (ast.native_abi_rust) {
+ case (ast::native_abi_rust) {
pass_task = true;
cast_to_i32 = true;
}
- case (ast.native_abi_rust_intrinsic) {
+ case (ast::native_abi_rust_intrinsic) {
pass_task = true;
cast_to_i32 = false;
}
- case (ast.native_abi_cdecl) {
+ case (ast::native_abi_cdecl) {
pass_task = false;
cast_to_i32 = true;
}
- case (ast.native_abi_llvm) {
+ case (ast::native_abi_llvm) {
pass_task = false;
cast_to_i32 = false;
}
if (pass_task) { call_args += vec(lltaskptr); }
auto arg_n = 3u;
- for each (uint i in UInt.range(0u, num_ty_param)) {
- auto llarg = llvm.LLVMGetParam(fcx.llfn, arg_n);
+ for each (uint i in _uint::range(0u, num_ty_param)) {
+ auto llarg = llvm::LLVMGetParam(fcx.llfn, arg_n);
fcx.lltydescs += vec(llarg);
assert (llarg as int != 0);
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(cx.fcx.lcx.ccx.tcx, t)) {
+ ty::t t,
+ ty::mode mode) -> ValueRef {
+ if (mode == ty::mo_val) {
+ if (ty::type_is_integral(cx.fcx.lcx.ccx.tcx, t)) {
auto lldsttype = T_int();
auto llsrctype = type_of(cx.fcx.lcx.ccx, t);
- if (llvm.LLVMGetIntTypeWidth(lldsttype) >
- llvm.LLVMGetIntTypeWidth(llsrctype)) {
+ 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(cx.fcx.lcx.ccx.tcx, t)) {
+ if (ty::type_is_fp(cx.fcx.lcx.ccx.tcx, t)) {
ret cx.build.FPToSI(v, T_int());
}
}
fn trans_simple_native_abi(&@block_ctxt bcx,
str name,
&mutable vec[ValueRef] call_args,
- ty.t fn_type,
+ ty::t fn_type,
uint first_arg_n) -> tup(ValueRef, ValueRef) {
let vec[TypeRef] call_arg_tys = vec();
for (ValueRef arg in call_args) {
auto llnativefnty =
T_fn(call_arg_tys,
type_of(bcx.fcx.lcx.ccx,
- ty.ty_fn_ret(bcx.fcx.lcx.ccx.tcx, fn_type)));
+ ty::ty_fn_ret(bcx.fcx.lcx.ccx.tcx, fn_type)));
auto llnativefn = get_extern_fn(bcx.fcx.lcx.ccx.externs,
bcx.fcx.lcx.ccx.llmod,
name,
- lib.llvm.LLVMCCallConv,
+ lib::llvm::LLVMCCallConv,
llnativefnty);
auto r = bcx.build.Call(llnativefn, call_args);
ret tup(r, rptr);
}
- auto args = ty.ty_fn_args(ccx.tcx, fn_type);
+ auto args = ty::ty_fn_args(ccx.tcx, fn_type);
// Build up the list of arguments.
- let vec[tup(ValueRef, ty.t)] drop_args = vec();
+ let vec[tup(ValueRef, ty::t)] drop_args = vec();
auto i = arg_n;
- for (ty.arg arg in args) {
- auto llarg = llvm.LLVMGetParam(fcx.llfn, i);
+ for (ty::arg arg in args) {
+ auto llarg = llvm::LLVMGetParam(fcx.llfn, i);
assert (llarg as int != 0);
if (cast_to_i32) {
call_args += vec(llarg);
}
- if (arg.mode == ty.mo_val) {
+ if (arg.mode == ty::mo_val) {
drop_args += vec(tup(llarg, arg.ty));
}
auto r;
auto rptr;
alt (abi) {
- case (ast.native_abi_llvm) {
+ case (ast::native_abi_llvm) {
auto result = trans_simple_native_abi(bcx, name, call_args,
fn_type, arg_n);
r = result._0; rptr = result._1;
}
- case (ast.native_abi_rust_intrinsic) {
+ 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);
// the FIXME above.
if (!rty_is_nil) { bcx.build.Store(r, rptr); }
- for (tup(ValueRef, ty.t) d in drop_args) {
+ for (tup(ValueRef, ty::t) d in drop_args) {
bcx = drop_ty(bcx, d._0, d._1).bcx;
}
ret @rec(mutable path=path);
}
-fn enter_item(@walk_ctxt cx, &@ast.item item) {
+fn enter_item(@walk_ctxt cx, &@ast::item item) {
alt (item.node) {
- case (ast.item_fn(?name, _, _, _, _)) {
- Vec.push[str](cx.path, name);
+ case (ast::item_fn(?name, _, _, _, _)) {
+ _vec::push[str](cx.path, name);
}
- case (ast.item_obj(?name, _, _, _, _)) {
- Vec.push[str](cx.path, name);
+ case (ast::item_obj(?name, _, _, _, _)) {
+ _vec::push[str](cx.path, name);
}
- case (ast.item_mod(?name, _, _)) {
- Vec.push[str](cx.path, name);
+ case (ast::item_mod(?name, _, _)) {
+ _vec::push[str](cx.path, name);
}
case (_) { }
}
}
-fn leave_item(@walk_ctxt cx, &@ast.item item) {
+fn leave_item(@walk_ctxt cx, &@ast::item item) {
alt (item.node) {
- case (ast.item_fn(_, _, _, _, _)) {
- Vec.pop[str](cx.path);
+ case (ast::item_fn(_, _, _, _, _)) {
+ _vec::pop[str](cx.path);
}
- case (ast.item_obj(_, _, _, _, _)) {
- Vec.pop[str](cx.path);
+ case (ast::item_obj(_, _, _, _, _)) {
+ _vec::pop[str](cx.path);
}
- case (ast.item_mod(_, _, _)) {
- Vec.pop[str](cx.path);
+ case (ast::item_mod(_, _, _)) {
+ _vec::pop[str](cx.path);
}
case (_) { }
}
}
fn collect_native_item(&@crate_ctxt ccx, @walk_ctxt wcx,
- &@ast.native_item i) {
+ &@ast::native_item i) {
alt (i.node) {
- case (ast.native_item_fn(?name, _, _, _, ?fid, ?ann)) {
+ case (ast::native_item_fn(?name, _, _, _, ?fid, ?ann)) {
ccx.native_items.insert(fid, i);
if (!ccx.obj_methods.contains_key(fid)) {
decl_native_fn_and_pair(ccx, wcx.path, name, ann, fid);
}
}
- case (ast.native_item_ty(_, ?tid)) {
+ case (ast::native_item_ty(_, ?tid)) {
ccx.native_items.insert(tid, i);
}
}
}
-fn collect_item_1(&@crate_ctxt ccx, @walk_ctxt wcx, &@ast.item i) {
+fn collect_item_1(&@crate_ctxt ccx, @walk_ctxt wcx, &@ast::item i) {
enter_item(wcx, i);
alt (i.node) {
- case (ast.item_const(?name, _, _, ?cid, ?ann)) {
+ case (ast::item_const(?name, _, _, ?cid, ?ann)) {
auto typ = node_ann_type(ccx, ann);
- auto g = llvm.LLVMAddGlobal(ccx.llmod, type_of(ccx, typ),
- Str.buf(ccx.names.next(name)));
- llvm.LLVMSetLinkage(g, lib.llvm.LLVMInternalLinkage
- as llvm.Linkage);
+ auto g = llvm::LLVMAddGlobal(ccx.llmod, type_of(ccx, typ),
+ _str::buf(ccx.names.next(name)));
+ llvm::LLVMSetLinkage(g, lib::llvm::LLVMInternalLinkage
+ as llvm::Linkage);
ccx.items.insert(cid, i);
ccx.consts.insert(cid, g);
}
- case (ast.item_mod(?name, ?m, ?mid)) {
+ case (ast::item_mod(?name, ?m, ?mid)) {
ccx.items.insert(mid, i);
}
- case (ast.item_native_mod(_, _, ?mid)) {
+ case (ast::item_native_mod(_, _, ?mid)) {
ccx.items.insert(mid, i);
}
- case (ast.item_ty(_, _, _, ?did, _)) {
+ case (ast::item_ty(_, _, _, ?did, _)) {
ccx.items.insert(did, i);
}
- case (ast.item_tag(?name, ?variants, ?tps, ?tag_id, _)) {
+ case (ast::item_tag(?name, ?variants, ?tps, ?tag_id, _)) {
ccx.items.insert(tag_id, i);
}
case (_) {}
}
}
-fn collect_item_2(&@crate_ctxt ccx, @walk_ctxt wcx, &@ast.item i) {
+fn collect_item_2(&@crate_ctxt ccx, @walk_ctxt wcx, &@ast::item i) {
enter_item(wcx, i);
alt (i.node) {
- case (ast.item_fn(?name, ?f, ?tps, ?fid, ?ann)) {
+ case (ast::item_fn(?name, ?f, ?tps, ?fid, ?ann)) {
ccx.items.insert(fid, i);
if (!ccx.obj_methods.contains_key(fid)) {
decl_fn_and_pair(ccx, wcx.path, "fn", tps, ann, fid);
}
}
- case (ast.item_obj(?name, ?ob, ?tps, ?oid, ?ann)) {
+ case (ast::item_obj(?name, ?ob, ?tps, ?oid, ?ann)) {
ccx.items.insert(oid.ctor, i);
decl_fn_and_pair(ccx, wcx.path, "obj_ctor", tps, ann, oid.ctor);
- for (@ast.method m in ob.methods) {
+ for (@ast::method m in ob.methods) {
ccx.obj_methods.insert(m.node.id, ());
}
}
}
}
-fn collect_items(&@crate_ctxt ccx, @ast.crate crate) {
+fn collect_items(&@crate_ctxt ccx, @ast::crate crate) {
auto wcx = new_walk_ctxt();
- auto visitor0 = walk.default_visitor();
+ auto visitor0 = walk::default_visitor();
auto visitor1 = rec(visit_native_item_pre =
bind collect_native_item(ccx, wcx, _),
visit_item_pre = bind collect_item_1(ccx, wcx, _),
auto visitor2 = rec(visit_item_pre = bind collect_item_2(ccx, wcx, _),
visit_item_post = bind leave_item(wcx, _)
with visitor0);
- walk.walk_crate(visitor1, *crate);
- walk.walk_crate(visitor2, *crate);
+ walk::walk_crate(visitor1, *crate);
+ walk::walk_crate(visitor2, *crate);
}
-fn collect_tag_ctor(&@crate_ctxt ccx, @walk_ctxt wcx, &@ast.item i) {
+fn collect_tag_ctor(&@crate_ctxt ccx, @walk_ctxt wcx, &@ast::item i) {
enter_item(wcx, i);
alt (i.node) {
- case (ast.item_tag(_, ?variants, ?tps, _, _)) {
- for (ast.variant variant in variants) {
- if (Vec.len[ast.variant_arg](variant.node.args) != 0u) {
+ case (ast::item_tag(_, ?variants, ?tps, _, _)) {
+ for (ast::variant variant in variants) {
+ if (_vec::len[ast::variant_arg](variant.node.args) != 0u) {
decl_fn_and_pair(ccx, wcx.path + vec(variant.node.name),
"tag", tps, variant.node.ann,
variant.node.id);
}
}
-fn collect_tag_ctors(&@crate_ctxt ccx, @ast.crate crate) {
+fn collect_tag_ctors(&@crate_ctxt ccx, @ast::crate crate) {
auto wcx = new_walk_ctxt();
auto visitor = rec(visit_item_pre = bind collect_tag_ctor(ccx, wcx, _),
visit_item_post = bind leave_item(wcx, _)
- with walk.default_visitor());
- walk.walk_crate(visitor, *crate);
+ with walk::default_visitor());
+ walk::walk_crate(visitor, *crate);
}
// The constant translation pass.
-fn trans_constant(&@crate_ctxt ccx, @walk_ctxt wcx, &@ast.item it) {
+fn trans_constant(&@crate_ctxt ccx, @walk_ctxt wcx, &@ast::item it) {
enter_item(wcx, it);
alt (it.node) {
- case (ast.item_tag(?ident, ?variants, _, ?tag_id, _)) {
+ case (ast::item_tag(?ident, ?variants, _, ?tag_id, _)) {
auto i = 0u;
- auto n_variants = Vec.len[ast.variant](variants);
+ auto n_variants = _vec::len[ast::variant](variants);
while (i < n_variants) {
auto variant = variants.(i);
auto s = mangle_name_by_seq(ccx, wcx.path,
#fmt("_rust_tag_discrim_%s_%u",
ident, i));
- auto discrim_gvar = llvm.LLVMAddGlobal(ccx.llmod, T_int(),
- Str.buf(s));
+ auto discrim_gvar = llvm::LLVMAddGlobal(ccx.llmod, T_int(),
+ _str::buf(s));
- llvm.LLVMSetInitializer(discrim_gvar, discrim_val);
- llvm.LLVMSetGlobalConstant(discrim_gvar, True);
+ llvm::LLVMSetInitializer(discrim_gvar, discrim_val);
+ llvm::LLVMSetGlobalConstant(discrim_gvar, True);
ccx.discrims.insert(variant.node.id, discrim_gvar);
ccx.discrim_symbols.insert(variant.node.id, s);
}
}
- case (ast.item_const(?name, _, ?expr, ?cid, ?ann)) {
+ case (ast::item_const(?name, _, ?expr, ?cid, ?ann)) {
// FIXME: The whole expr-translation system needs cloning to deal
// with consts.
auto v = C_int(1);
}
}
-fn trans_constants(&@crate_ctxt ccx, @ast.crate crate) {
+fn trans_constants(&@crate_ctxt ccx, @ast::crate crate) {
auto wcx = new_walk_ctxt();
auto visitor = rec(visit_item_pre = bind trans_constant(ccx, wcx, _),
visit_item_post = bind leave_item(wcx, _)
- with walk.default_visitor());
- walk.walk_crate(visitor, *crate);
+ with walk::default_visitor());
+ walk::walk_crate(visitor, *crate);
}
}
fn p2i(ValueRef v) -> ValueRef {
- ret llvm.LLVMConstPtrToInt(v, T_int());
+ ret llvm::LLVMConstPtrToInt(v, T_int());
}
fn i2p(ValueRef v, TypeRef t) -> ValueRef {
- ret llvm.LLVMConstIntToPtr(v, t);
+ ret llvm::LLVMConstIntToPtr(v, t);
}
fn trans_exit_task_glue(@glue_fns glues,
auto llfn = glues.exit_task_glue;
- auto entrybb = llvm.LLVMAppendBasicBlock(llfn, Str.buf("entry"));
+ auto entrybb = llvm::LLVMAppendBasicBlock(llfn, _str::buf("entry"));
auto build = new_builder(entrybb);
- let ValueRef arg1 = llvm.LLVMGetParam(llfn, 0u);
- let ValueRef arg2 = llvm.LLVMGetParam(llfn, 1u);
- let ValueRef arg3 = llvm.LLVMGetParam(llfn, 2u);
- let ValueRef arg4 = llvm.LLVMGetParam(llfn, 3u);
- let ValueRef arg5 = llvm.LLVMGetParam(llfn, 4u);
+ let ValueRef arg1 = llvm::LLVMGetParam(llfn, 0u);
+ let ValueRef arg2 = llvm::LLVMGetParam(llfn, 1u);
+ let ValueRef arg3 = llvm::LLVMGetParam(llfn, 2u);
+ let ValueRef arg4 = llvm::LLVMGetParam(llfn, 3u);
+ let ValueRef arg5 = llvm::LLVMGetParam(llfn, 4u);
auto main_type = T_fn(vec(T_int(), T_int(), T_int(), T_int()), T_void());
}
fn create_typedefs(&@crate_ctxt cx) {
- llvm.LLVMAddTypeName(cx.llmod, Str.buf("crate"), T_crate(cx.tn));
- llvm.LLVMAddTypeName(cx.llmod, Str.buf("task"), T_task(cx.tn));
- llvm.LLVMAddTypeName(cx.llmod, Str.buf("tydesc"), T_tydesc(cx.tn));
+ llvm::LLVMAddTypeName(cx.llmod, _str::buf("crate"), T_crate(cx.tn));
+ llvm::LLVMAddTypeName(cx.llmod, _str::buf("task"), T_task(cx.tn));
+ llvm::LLVMAddTypeName(cx.llmod, _str::buf("tydesc"), T_tydesc(cx.tn));
}
fn create_crate_constant(ValueRef crate_ptr, @glue_fns glues) {
let ValueRef crate_addr = p2i(crate_ptr);
let ValueRef activate_glue_off =
- llvm.LLVMConstSub(p2i(glues.activate_glue), crate_addr);
+ llvm::LLVMConstSub(p2i(glues.activate_glue), crate_addr);
let ValueRef yield_glue_off =
- llvm.LLVMConstSub(p2i(glues.yield_glue), crate_addr);
+ llvm::LLVMConstSub(p2i(glues.yield_glue), crate_addr);
let ValueRef exit_task_glue_off =
- llvm.LLVMConstSub(p2i(glues.exit_task_glue), crate_addr);
+ llvm::LLVMConstSub(p2i(glues.exit_task_glue), crate_addr);
let ValueRef crate_val =
C_struct(vec(C_null(T_int()), // ptrdiff_t image_base_off
C_null(T_int()), // int n_rust_syms
C_null(T_int()), // int n_c_syms
C_null(T_int()), // int n_libs
- C_int(abi.abi_x86_rustc_fastcall) // uintptr_t abi_tag
+ C_int(abi::abi_x86_rustc_fastcall) // uintptr_t abi_tag
));
- llvm.LLVMSetInitializer(crate_ptr, crate_val);
+ llvm::LLVMSetInitializer(crate_ptr, crate_val);
}
fn find_main_fn(&@crate_ctxt cx) -> ValueRef {
auto e = sep() + "main";
let ValueRef v = C_nil();
let uint n = 0u;
- for each (@tup(ast.def_id, str) i in cx.item_symbols.items()) {
- if (Str.ends_with(i._1, e)) {
+ for each (@tup(ast::def_id, str) i in cx.item_symbols.items()) {
+ if (_str::ends_with(i._1, e)) {
n += 1u;
v = cx.item_ids.get(i._0);
}
auto T_rust_start_args = vec(T_int(), T_int(), T_int(), T_int(), T_int());
auto main_name;
- if (Str.eq(std.OS.target_os(), "win32")) {
+ if (_str::eq(std::os::target_os(), "win32")) {
main_name = "WinMain@16";
} else {
main_name = "main";
auto llrust_start = decl_cdecl_fn(cx.ccx.llmod, "rust_start",
T_fn(T_rust_start_args, T_int()));
- auto llargc = llvm.LLVMGetParam(llmain, 0u);
- auto llargv = llvm.LLVMGetParam(llmain, 1u);
+ auto llargc = llvm::LLVMGetParam(llmain, 0u);
+ auto llargv = llvm::LLVMGetParam(llmain, 1u);
auto llrust_main = find_main_fn(cx.ccx);
//
//
let BasicBlockRef llbb =
- llvm.LLVMAppendBasicBlock(llmain, Str.buf(""));
+ llvm::LLVMAppendBasicBlock(llmain, _str::buf(""));
auto b = new_builder(llbb);
auto start_args = vec(p2i(llrust_main), p2i(llcrate), llargc, llargv,
fn decl_no_op_type_glue(ModuleRef llmod, type_names tn) -> ValueRef {
auto ty = T_fn(vec(T_taskptr(tn), T_ptr(T_i8())), T_void());
- ret decl_fastcall_fn(llmod, abi.no_op_type_glue_name(), ty);
+ 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);
+ auto bb_name = _str::buf("_rust_no_op_type_glue_bb");
+ auto llbb = llvm::LLVMAppendBasicBlock(fun, bb_name);
new_builder(llbb).RetVoid();
}
T_opaque_vec_ptr(), T_bool()),
T_void());
- auto llfn = decl_fastcall_fn(llmod, abi.vec_append_glue_name(), ty);
+ auto llfn = decl_fastcall_fn(llmod, abi::vec_append_glue_name(), ty);
ret llfn;
}
fn vec_fill(&@block_ctxt bcx, ValueRef v) -> ValueRef {
ret bcx.build.Load(bcx.build.GEP(v, vec(C_int(0),
- C_int(abi.vec_elt_fill))));
+ C_int(abi::vec_elt_fill))));
}
fn put_vec_fill(&@block_ctxt bcx, ValueRef v, ValueRef fill) -> ValueRef {
ret bcx.build.Store(fill,
bcx.build.GEP(v,
vec(C_int(0),
- C_int(abi.vec_elt_fill))));
+ C_int(abi::vec_elt_fill))));
}
fn vec_fill_adjusted(&@block_ctxt bcx, ValueRef v,
ValueRef skipnull) -> ValueRef {
auto f = bcx.build.Load(bcx.build.GEP(v,
vec(C_int(0),
- C_int(abi.vec_elt_fill))));
+ C_int(abi::vec_elt_fill))));
ret bcx.build.Select(skipnull, bcx.build.Sub(f, C_int(1)), f);
}
fn vec_p0(&@block_ctxt bcx, ValueRef v) -> ValueRef {
auto p = bcx.build.GEP(v, vec(C_int(0),
- C_int(abi.vec_elt_data)));
+ C_int(abi::vec_elt_data)));
ret bcx.build.PointerCast(p, T_ptr(T_i8()));
}
auto llfn = cx.ccx.glues.vec_append_glue;
- let ValueRef lltaskptr = llvm.LLVMGetParam(llfn, 0u);
- let ValueRef llvec_tydesc = llvm.LLVMGetParam(llfn, 1u);
- let ValueRef llelt_tydesc = llvm.LLVMGetParam(llfn, 2u);
- let ValueRef lldst_vec_ptr = llvm.LLVMGetParam(llfn, 3u);
- let ValueRef llsrc_vec = llvm.LLVMGetParam(llfn, 4u);
- let ValueRef llskipnull = llvm.LLVMGetParam(llfn, 5u);
+ let ValueRef lltaskptr = llvm::LLVMGetParam(llfn, 0u);
+ let ValueRef llvec_tydesc = llvm::LLVMGetParam(llfn, 1u);
+ let ValueRef llelt_tydesc = llvm::LLVMGetParam(llfn, 2u);
+ let ValueRef lldst_vec_ptr = llvm::LLVMGetParam(llfn, 3u);
+ let ValueRef llsrc_vec = llvm::LLVMGetParam(llfn, 4u);
+ let ValueRef llskipnull = llvm::LLVMGetParam(llfn, 5u);
auto derived_tydescs =
- Map.mk_hashmap[ty.t, derived_tydesc_info](ty.hash_ty, ty.eq_ty);
+ map::mk_hashmap[ty::t, derived_tydesc_info](ty::hash_ty, ty::eq_ty);
auto llbbs = mk_standard_basic_blocks(llfn);
llobjfields=new_def_hash[ValueRef](),
lllocals=new_def_hash[ValueRef](),
llupvars=new_def_hash[ValueRef](),
- mutable lltydescs=Vec.empty[ValueRef](),
+ mutable lltydescs=_vec::empty[ValueRef](),
derived_tydescs=derived_tydescs,
lcx=cx);
auto elt_llsz =
cx.build.Load(cx.build.GEP(elt_tydesc,
vec(C_int(0),
- C_int(abi.tydesc_field_size))));
+ C_int(abi::tydesc_field_size))));
maybe_name_value(cx.fcx.lcx.ccx, elt_llsz, "elt_llsz");
auto elt_llalign =
cx.build.Load(cx.build.GEP(elt_tydesc,
vec(C_int(0),
- C_int(abi.tydesc_field_align))));
+ C_int(abi::tydesc_field_align))));
maybe_name_value(cx.fcx.lcx.ccx, elt_llsz, "elt_llalign");
ValueRef dst, ValueRef src) -> result {
call_tydesc_glue_full(cx, src,
elt_tydesc,
- abi.tydesc_field_take_glue);
+ abi::tydesc_field_take_glue);
ret res(cx, src);
}
fn make_glues(ModuleRef llmod, &type_names tn) -> @glue_fns {
- ret @rec(activate_glue = decl_glue(llmod, tn, abi.activate_glue_name()),
- yield_glue = decl_glue(llmod, tn, abi.yield_glue_name()),
- exit_task_glue = decl_cdecl_fn(llmod, abi.exit_task_glue_name(),
+ ret @rec(activate_glue = decl_glue(llmod, tn, abi::activate_glue_name()),
+ yield_glue = decl_glue(llmod, tn, abi::yield_glue_name()),
+ exit_task_glue = decl_cdecl_fn(llmod, abi::exit_task_glue_name(),
T_fn(vec(T_int(),
T_int(),
T_int(),
T_void())),
native_glues_rust =
- Vec.init_fn[ValueRef](bind decl_native_glue(llmod, tn,
- abi.ngt_rust, _), abi.n_native_glues + 1 as uint),
+ _vec::init_fn[ValueRef](bind decl_native_glue(llmod, tn,
+ abi::ngt_rust, _), abi::n_native_glues + 1 as uint),
native_glues_pure_rust =
- Vec.init_fn[ValueRef](bind decl_native_glue(llmod, tn,
- abi.ngt_pure_rust, _), abi.n_native_glues + 1 as uint),
+ _vec::init_fn[ValueRef](bind decl_native_glue(llmod, tn,
+ abi::ngt_pure_rust, _), abi::n_native_glues + 1 as uint),
native_glues_cdecl =
- Vec.init_fn[ValueRef](bind decl_native_glue(llmod, tn,
- abi.ngt_cdecl, _), abi.n_native_glues + 1 as uint),
+ _vec::init_fn[ValueRef](bind decl_native_glue(llmod, tn,
+ abi::ngt_cdecl, _), abi::n_native_glues + 1 as uint),
no_op_type_glue = decl_no_op_type_glue(llmod, tn),
vec_append_glue = make_vec_append_glue(llmod, tn));
}
-fn make_common_glue(&session.session sess, &str output) {
+fn make_common_glue(&session::session sess, &str output) {
// FIXME: part of this is repetitive and is probably a good idea
// to autogen it.
auto llmod =
- llvm.LLVMModuleCreateWithNameInContext(Str.buf("rust_out"),
- llvm.LLVMGetGlobalContext());
+ 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());
+ 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();
let ValueRef crate_ptr =
- llvm.LLVMAddGlobal(llmod, T_crate(tn), Str.buf("rust_crate"));
+ llvm::LLVMAddGlobal(llmod, T_crate(tn), _str::buf("rust_crate"));
auto intrinsics = declare_intrinsics(llmod);
- llvm.LLVMSetModuleInlineAsm(llmod, Str.buf(x86.get_module_asm()));
+ llvm::LLVMSetModuleInlineAsm(llmod, _str::buf(x86::get_module_asm()));
auto glues = make_glues(llmod, tn);
create_crate_constant(crate_ptr, glues);
- trans.trans_exit_task_glue(glues, new_str_hash[ValueRef](), tn,
+ trans::trans_exit_task_glue(glues, new_str_hash[ValueRef](), tn,
llmod);
- Link.Write.run_passes(sess, llmod, output);
+ Link::Write::run_passes(sess, llmod, output);
}
fn create_module_map(&@crate_ctxt ccx) -> ValueRef {
auto elttype = T_struct(vec(T_int(), T_int()));
auto maptype = T_array(elttype, ccx.module_data.size() + 1u);
- auto map = llvm.LLVMAddGlobal(ccx.llmod, maptype,
- Str.buf("_rust_mod_map"));
- llvm.LLVMSetLinkage(map, lib.llvm.LLVMInternalLinkage as llvm.Linkage);
+ auto map = llvm::LLVMAddGlobal(ccx.llmod, maptype,
+ _str::buf("_rust_mod_map"));
+ llvm::LLVMSetLinkage(map, lib::llvm::LLVMInternalLinkage
+ as llvm::Linkage);
let vec[ValueRef] elts = vec();
for each (@tup(str, ValueRef) item in ccx.module_data.items()) {
auto elt = C_struct(vec(p2i(C_cstr(ccx, item._0)), p2i(item._1)));
- Vec.push[ValueRef](elts, elt);
+ _vec::push[ValueRef](elts, elt);
}
auto term = C_struct(vec(C_int(0), C_int(0)));
- Vec.push[ValueRef](elts, term);
- llvm.LLVMSetInitializer(map, C_array(elttype, elts));
+ _vec::push[ValueRef](elts, term);
+ llvm::LLVMSetInitializer(map, C_array(elttype, elts));
ret map;
}
fn crate_name(&@crate_ctxt ccx, &str deflt) -> str {
- for (@ast.meta_item item in ccx.sess.get_metadata()) {
- if (Str.eq(item.node.name, "name")) {
+ for (@ast::meta_item item in ccx.sess.get_metadata()) {
+ if (_str::eq(item.node.name, "name")) {
ret item.node.value;
}
}
auto i = 1;
while (ccx.sess.has_external_crate(i)) {
auto name = ccx.sess.get_external_crate(i).name;
- auto cr = llvm.LLVMAddGlobal(ccx.llmod, T_int(),
- Str.buf("_rust_crate_map_" + name));
- Vec.push[ValueRef](subcrates, p2i(cr));
+ auto cr = llvm::LLVMAddGlobal(ccx.llmod, T_int(),
+ _str::buf("_rust_crate_map_" + name));
+ _vec::push[ValueRef](subcrates, p2i(cr));
i += 1;
}
- Vec.push[ValueRef](subcrates, C_int(0));
+ _vec::push[ValueRef](subcrates, C_int(0));
auto sym_name = "_rust_crate_map_" + crate_name(ccx, "__none__");
- auto arrtype = T_array(T_int(), Vec.len[ValueRef](subcrates));
+ auto arrtype = T_array(T_int(), _vec::len[ValueRef](subcrates));
auto maptype = T_struct(vec(T_int(), arrtype));
- auto map = llvm.LLVMAddGlobal(ccx.llmod, maptype, Str.buf(sym_name));
- llvm.LLVMSetLinkage(map, lib.llvm.LLVMExternalLinkage as llvm.Linkage);
- llvm.LLVMSetInitializer(map, C_struct(vec(p2i(create_module_map(ccx)),
+ auto map = llvm::LLVMAddGlobal(ccx.llmod, maptype, _str::buf(sym_name));
+ llvm::LLVMSetLinkage(map, lib::llvm::LLVMExternalLinkage
+ as llvm::Linkage);
+ llvm::LLVMSetInitializer(map, C_struct(vec(p2i(create_module_map(ccx)),
C_array(T_int(), subcrates))));
ret map;
}
-fn trans_crate(&session.session sess, &@ast.crate crate, &ty.ctxt tcx,
- &ty.type_cache type_cache, &str output)
+fn trans_crate(&session::session sess, &@ast::crate crate, &ty::ctxt tcx,
+ &ty::type_cache type_cache, &str output)
-> ModuleRef {
auto llmod =
- llvm.LLVMModuleCreateWithNameInContext(Str.buf("rust_out"),
- llvm.LLVMGetGlobalContext());
+ 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());
+ 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();
let ValueRef crate_ptr =
- llvm.LLVMAddGlobal(llmod, T_crate(tn), Str.buf("rust_crate"));
+ llvm::LLVMAddGlobal(llmod, T_crate(tn), _str::buf("rust_crate"));
auto intrinsics = declare_intrinsics(llmod);
auto glues = make_glues(llmod, tn);
- 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 abbrevs = Map.mk_hashmap[ty.t,metadata.ty_abbrev](hasher, eqer);
- auto short_names = Map.mk_hashmap[ty.t,str](hasher, eqer);
+ 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 abbrevs = map::mk_hashmap[ty::t,metadata::ty_abbrev](hasher, eqer);
+ auto short_names = map::mk_hashmap[ty::t,str](hasher, eqer);
auto ccx = @rec(sess = sess,
llmod = llmod,
externs = new_str_hash[ValueRef](),
intrinsics = intrinsics,
item_ids = new_def_hash[ValueRef](),
- items = new_def_hash[@ast.item](),
- native_items = new_def_hash[@ast.native_item](),
+ items = new_def_hash[@ast::item](),
+ native_items = new_def_hash[@ast::native_item](),
type_cache = type_cache,
item_symbols = new_def_hash[str](),
tag_sizes = tag_sizes,
lltypes = lltypes,
glues = glues,
names = namegen(0),
- sha = std.SHA1.mk_sha1(),
+ sha = std::sha1::mk_sha1(),
type_sha1s = sha1s,
type_abbrevs = abbrevs,
type_short_names = short_names,
tcx = tcx,
- upcalls = upcall.declare_upcalls(tn, llmod));
+ upcalls = upcall::declare_upcalls(tn, llmod));
auto cx = new_local_ctxt(ccx);
create_typedefs(ccx);
trans_main_fn(cx, crate_ptr, crate_map);
}
- // Translate the metadata.
- middle.metadata.write_metadata(cx.ccx, crate);
+ // Translate the metadata:
+ middle::metadata::write_metadata(cx.ccx, crate);
ret llmod;
}
-import std.Str;
-import std.UInt;
-import std.Vec;
-import std.Box;
-import std.UFind;
-import std.Map;
-import std.Map.hashmap;
-import std.Option;
-import std.Option.none;
-import std.Option.some;
-
-import driver.session;
-import front.ast;
-import front.ast.mutability;
-import front.creader;
-import middle.metadata;
-import util.common;
-
-import util.common.ty_u8;
-import util.common.ty_u16;
-import util.common.ty_u32;
-import util.common.ty_u64;
-
-import util.common.ty_i8;
-import util.common.ty_i16;
-import util.common.ty_i32;
-import util.common.ty_i64;
-
-import util.common.ty_f32;
-import util.common.ty_f64;
-
-import util.common.new_def_hash;
-import util.common.span;
-import util.typestate_ann.ts_ann;
+import std::_str;
+import std::_uint;
+import std::_vec;
+import std::box;
+import std::ufind;
+import std::map;
+import std::map::hashmap;
+import std::option;
+import std::option::none;
+import std::option::some;
+
+import driver::session;
+import front::ast;
+import front::ast::mutability;
+import front::creader;
+import middle::metadata;
+import util::common;
+
+import util::common::ty_u8;
+import util::common::ty_u16;
+import util::common::ty_u32;
+import util::common::ty_u64;
+
+import util::common::ty_i8;
+import util::common::ty_i16;
+import util::common::ty_i32;
+import util::common::ty_i64;
+
+import util::common::ty_f32;
+import util::common::ty_f64;
+
+import util::common::new_def_hash;
+import util::common::span;
+import util::typestate_ann::ts_ann;
// Data types
}
type arg = rec(mode mode, t ty);
-type field = rec(ast.ident ident, mt mt);
-type method = rec(ast.proto proto,
- ast.ident ident,
+type field = rec(ast::ident ident, mt mt);
+type method = rec(ast::proto proto,
+ ast::ident ident,
vec[arg] inputs,
t output);
-type mt = rec(t ty, ast.mutability mut);
+type mt = rec(t ty, ast::mutability mut);
// Contains information needed to resolve types and (in the future) look up
// the types of AST nodes.
-type creader_cache = hashmap[tup(int,uint,uint),ty.t];
+type creader_cache = hashmap[tup(int,uint,uint),ty::t];
type ctxt = rec(@type_store ts,
- session.session sess,
- resolve.def_map def_map,
+ session::session sess,
+ resolve::def_map def_map,
creader_cache rcache,
hashmap[t,str] short_names_cache);
-type ty_ctxt = ctxt; // Needed for disambiguation from Unify.ctxt.
+type ty_ctxt = ctxt; // Needed for disambiguation from Unify::ctxt.
// Convert from method type to function type. Pretty easy; we just drop
// 'ident'.
// TODO: It'd be really nice to be able to hide this definition from the
// outside world, to enforce the above invariants.
type raw_t = rec(sty struct,
- Option.t[str] cname,
+ option::t[str] cname,
uint hash,
bool has_params,
bool has_bound_params,
type t = uint;
// NB: If you change this, you'll probably want to change the corresponding
-// AST structure in front/ast.rs as well.
+// AST structure in front/ast::rs as well.
tag sty {
ty_nil;
ty_bool;
ty_int;
ty_float;
ty_uint;
- ty_machine(util.common.ty_mach);
+ ty_machine(util::common::ty_mach);
ty_char;
ty_str;
- ty_tag(ast.def_id, vec[t]);
+ ty_tag(ast::def_id, vec[t]);
ty_box(mt);
ty_vec(mt);
ty_port(t);
ty_task;
ty_tup(vec[mt]);
ty_rec(vec[field]);
- ty_fn(ast.proto, vec[arg], t);
- ty_native_fn(ast.native_abi, vec[arg], t);
+ ty_fn(ast::proto, vec[arg], t);
+ ty_native_fn(ast::native_abi, vec[arg], t);
ty_obj(vec[method]);
ty_var(int); // ephemeral type var
- ty_local(ast.def_id); // type of a local var
+ ty_local(ast::def_id); // type of a local var
ty_param(uint); // fn/tag type param
ty_bound_param(uint); // bound param, only paths
ty_type;
// Data structures used in type unification
type unify_handler = obj {
- fn resolve_local(ast.def_id id) -> Option.t[t];
- fn record_local(ast.def_id id, t ty); // TODO: -> Unify.result
- fn record_param(uint index, t binding) -> Unify.result;
+ fn resolve_local(ast::def_id id) -> option::t[t];
+ fn record_local(ast::def_id id, t ty); // TODO: -> Unify::result
+ fn record_param(uint index, t binding) -> Unify::result;
};
tag type_err {
terr_tuple_mutability;
terr_record_size(uint, uint);
terr_record_mutability;
- terr_record_fields(ast.ident,ast.ident);
+ terr_record_fields(ast::ident,ast::ident);
terr_meth_count;
- terr_obj_meths(ast.ident,ast.ident);
+ terr_obj_meths(ast::ident,ast::ident);
terr_arg_count;
}
type ty_param_count_and_ty = tup(uint, t);
-type type_cache = hashmap[ast.def_id,ty_param_count_and_ty];
+type type_cache = hashmap[ast::def_id,ty_param_count_and_ty];
const uint idx_nil = 0u;
const uint idx_bool = 1u;
fn mk_type_store() -> @type_store {
let vec[raw_t] others = vec();
let hashmap[raw_t,uint] ost =
- Map.mk_hashmap[raw_t,uint](hash_raw_ty, eq_raw_ty);
+ map::mk_hashmap[raw_t,uint](hash_raw_ty, eq_raw_ty);
auto ts = @rec(mutable others=others, other_structural=ost);
intern(ts, ty_native, none[str]);
intern(ts, ty_type, none[str]);
- assert Vec.len(ts.others) == idx_first_others;
+ assert _vec::len(ts.others) == idx_first_others;
ret ts;
}
}
auto h = hash_cache_entry;
auto e = eq_cache_entries;
- ret Map.mk_hashmap[tup(int,uint,uint),t](h, e);
+ ret map::mk_hashmap[tup(int,uint,uint),t](h, e);
}
-fn mk_ctxt(session.session s, resolve.def_map dm) -> ctxt {
+fn mk_ctxt(session::session s, resolve::def_map dm) -> ctxt {
ret rec(ts = mk_type_store(),
sess = s,
def_map = dm,
rcache = mk_rcache(),
short_names_cache =
- Map.mk_hashmap[ty.t,str](ty.hash_ty, ty.eq_ty));
+ map::mk_hashmap[ty::t,str](ty::hash_ty, ty::eq_ty));
}
// Type constructors
-fn mk_raw_ty(&@type_store ts, &sty st, &Option.t[str] cname) -> raw_t {
+fn mk_raw_ty(&@type_store ts, &sty st, &option::t[str] cname) -> raw_t {
auto h = hash_type_info(st, cname);
let bool has_params = false;
}
fn intern_raw_ty(&@type_store ts, &raw_t rt) {
- auto type_num = Vec.len[raw_t](ts.others);
+ auto type_num = _vec::len[raw_t](ts.others);
ts.others += vec(rt);
ts.other_structural.insert(rt, type_num);
}
-fn intern(&@type_store ts, &sty st, &Option.t[str] cname) {
+fn intern(&@type_store ts, &sty st, &option::t[str] cname) {
intern_raw_ty(ts, mk_raw_ty(ts, st, cname));
}
-fn gen_ty_full(&ctxt cx, &sty st, &Option.t[str] cname) -> t {
+fn gen_ty_full(&ctxt cx, &sty st, &option::t[str] cname) -> t {
auto raw_type = mk_raw_ty(cx.ts, st, cname);
// Is it interned?
ret typ;
}
case (none[t]) {
- // Nope. Insert it and return.
- auto type_num = Vec.len[raw_t](cx.ts.others);
+ // Nope: Insert it and return.
+ auto type_num = _vec::len[raw_t](cx.ts.others);
intern_raw_ty(cx.ts, raw_type);
// log_err "added: " + ty_to_str(tystore, raw_type);
ret type_num;
fn mk_float(&ctxt cx) -> t { ret idx_float; }
fn mk_uint(&ctxt cx) -> t { ret idx_uint; }
-fn mk_mach(&ctxt cx, &util.common.ty_mach tm) -> t {
+fn mk_mach(&ctxt cx, &util::common::ty_mach tm) -> t {
alt (tm) {
case (ty_u8) { ret idx_u8; }
case (ty_u16) { ret idx_u16; }
fn mk_char(&ctxt cx) -> t { ret idx_char; }
fn mk_str(&ctxt cx) -> t { ret idx_str; }
-fn mk_tag(&ctxt cx, &ast.def_id did, &vec[t] tys) -> t {
+fn mk_tag(&ctxt cx, &ast::def_id did, &vec[t] tys) -> t {
ret gen_ty(cx, ty_tag(did, tys));
}
}
fn mk_imm_box(&ctxt cx, &t ty) -> t {
- ret mk_box(cx, rec(ty=ty, mut=ast.imm));
+ ret mk_box(cx, rec(ty=ty, mut=ast::imm));
}
fn mk_vec(&ctxt cx, &mt tm) -> t { ret gen_ty(cx, ty_vec(tm)); }
fn mk_imm_tup(&ctxt cx, &vec[t] tys) -> t {
// TODO: map
- let vec[ty.mt] mts = vec();
+ let vec[ty::mt] mts = vec();
for (t typ in tys) {
- mts += vec(rec(ty=typ, mut=ast.imm));
+ mts += vec(rec(ty=typ, mut=ast::imm));
}
ret mk_tup(cx, mts);
}
fn mk_rec(&ctxt cx, &vec[field] fs) -> t { ret gen_ty(cx, ty_rec(fs)); }
-fn mk_fn(&ctxt cx, &ast.proto proto, &vec[arg] args, &t ty) -> t {
+fn mk_fn(&ctxt cx, &ast::proto proto, &vec[arg] args, &t ty) -> t {
ret gen_ty(cx, ty_fn(proto, args, ty));
}
-fn mk_native_fn(&ctxt cx, &ast.native_abi abi, &vec[arg] args, &t ty) -> t {
+fn mk_native_fn(&ctxt cx, &ast::native_abi abi, &vec[arg] args, &t ty) -> t {
ret gen_ty(cx, ty_native_fn(abi, args, ty));
}
ret gen_ty(cx, ty_var(v));
}
-fn mk_local(&ctxt cx, ast.def_id did) -> t {
+fn mk_local(&ctxt cx, ast::def_id did) -> t {
ret gen_ty(cx, ty_local(did));
}
fn struct(&ctxt cx, &t typ) -> sty { ret cx.ts.others.(typ).struct; }
// Returns the canonical name of the given type.
-fn cname(&ctxt cx, &t typ) -> Option.t[str] { ret cx.ts.others.(typ).cname; }
+fn cname(&ctxt cx, &t typ) -> option::t[str] { ret cx.ts.others.(typ).cname; }
// Stringification
-fn path_to_str(&ast.path pth) -> str {
- auto result = Str.connect(pth.node.idents, "::");
- if (Vec.len[@ast.ty](pth.node.types) > 0u) {
- auto f = pretty.pprust.ty_to_str;
+fn path_to_str(&ast::path pth) -> str {
+ auto result = _str::connect(pth.node.idents, "::");
+ if (_vec::len[@ast::ty](pth.node.types) > 0u) {
+ auto f = pretty::pprust::ty_to_str;
result += "[";
- result += Str.connect(Vec.map[@ast.ty,str](f, pth.node.types), ",");
+ result += _str::connect(_vec::map(f, pth.node.types), ",");
result += "]";
}
ret result;
}
fn fn_to_str(ctxt cx,
- ast.proto proto,
- Option.t[ast.ident] ident,
+ ast::proto proto,
+ option::t[ast::ident] ident,
vec[arg] inputs, t output) -> str {
auto f = bind fn_input_to_str(cx, _);
auto s;
alt (proto) {
- case (ast.proto_iter) {
+ case (ast::proto_iter) {
s = "iter";
}
- case (ast.proto_fn) {
+ case (ast::proto_fn) {
s = "fn";
}
}
alt (ident) {
- case (some[ast.ident](?i)) {
+ case (some[ast::ident](?i)) {
s += " ";
s += i;
}
}
s += "(";
- s += Str.connect(Vec.map[arg,str](f, inputs), ", ");
+ s += _str::connect(_vec::map[arg,str](f, inputs), ", ");
s += ")";
if (struct(cx, output) != ty_nil) {
}
fn method_to_str(ctxt cx, &method m) -> str {
- ret fn_to_str(cx, m.proto, some[ast.ident](m.ident),
+ ret fn_to_str(cx, m.proto, some[ast::ident](m.ident),
m.inputs, m.output) + ";";
}
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? "; }
+ case (ast::mut) { mstr = "mutable "; }
+ case (ast::imm) { mstr = ""; }
+ case (ast::maybe_mut) { mstr = "mutable? "; }
}
ret mstr + ty_to_str(cx, m.ty);
case (ty_int) { s += "int"; }
case (ty_float) { s += "float"; }
case (ty_uint) { s += "uint"; }
- case (ty_machine(?tm)) { s += common.ty_mach_to_str(tm); }
+ case (ty_machine(?tm)) { s += common::ty_mach_to_str(tm); }
case (ty_char) { s += "char"; }
case (ty_str) { s += "str"; }
case (ty_box(?tm)) { s += "@" + mt_to_str(cx, tm); }
case (ty_tup(?elems)) {
auto f = bind mt_to_str(cx, _);
- auto strs = Vec.map[mt,str](f, elems);
- s += "tup(" + Str.connect(strs, ",") + ")";
+ auto strs = _vec::map[mt,str](f, elems);
+ s += "tup(" + _str::connect(strs, ",") + ")";
}
case (ty_rec(?elems)) {
auto f = bind field_to_str(cx, _);
- auto strs = Vec.map[field,str](f, elems);
- s += "rec(" + Str.connect(strs, ",") + ")";
+ auto strs = _vec::map[field,str](f, elems);
+ s += "rec(" + _str::connect(strs, ",") + ")";
}
case (ty_tag(?id, ?tps)) {
// The user should never see this if the cname is set properly!
- s += "<tag#" + util.common.istr(id._0) + ":" +
- util.common.istr(id._1) + ">";
- if (Vec.len[t](tps) > 0u) {
+ s += "<tag#" + util::common::istr(id._0) + ":" +
+ util::common::istr(id._1) + ">";
+ if (_vec::len[t](tps) > 0u) {
auto f = bind ty_to_str(cx, _);
- auto strs = Vec.map[t,str](f, tps);
- s += "[" + Str.connect(strs, ",") + "]";
+ auto strs = _vec::map[t,str](f, tps);
+ s += "[" + _str::connect(strs, ",") + "]";
}
}
case (ty_fn(?proto, ?inputs, ?output)) {
- s += fn_to_str(cx, proto, none[ast.ident], inputs, output);
+ s += fn_to_str(cx, proto, none[ast::ident], inputs, output);
}
case (ty_native_fn(_, ?inputs, ?output)) {
- s += fn_to_str(cx, ast.proto_fn, none[ast.ident], inputs, output);
+ s += fn_to_str(cx, ast::proto_fn, none[ast::ident],
+ inputs, output);
}
case (ty_obj(?meths)) {
auto f = bind method_to_str(cx, _);
- auto m = Vec.map[method,str](f, meths);
- s += "obj {\n\t" + Str.connect(m, "\n\t") + "\n}";
+ auto m = _vec::map[method,str](f, meths);
+ s += "obj {\n\t" + _str::connect(m, "\n\t") + "\n}";
}
case (ty_var(?v)) {
- s += "<T" + util.common.istr(v) + ">";
+ s += "<T" + util::common::istr(v) + ">";
}
case (ty_local(?id)) {
- s += "<L" + util.common.istr(id._0) + ":" +
- util.common.istr(id._1) + ">";
+ s += "<L" + util::common::istr(id._0) + ":" +
+ util::common::istr(id._1) + ">";
}
case (ty_param(?id)) {
- s += "'" + Str.unsafe_from_bytes(vec(('a' as u8) + (id as u8)));
+ s += "'" + _str::unsafe_from_bytes(vec(('a' as u8) + (id as u8)));
}
case (ty_bound_param(?id)) {
- s += "''" + Str.unsafe_from_bytes(vec(('a' as u8) + (id as u8)));
+ s += "''" + _str::unsafe_from_bytes(vec(('a' as u8) +
+ (id as u8)));
}
}
fn ty_to_short_str(ctxt cx, t typ) -> str {
auto f = def_to_str;
- auto ecx = @rec(ds=f, tcx=cx, abbrevs=metadata.ac_no_abbrevs);
- auto s = metadata.Encode.ty_str(ecx, typ);
- if (Str.byte_len(s) >= 32u) { s = Str.substr(s, 0u, 32u); }
+ auto ecx = @rec(ds=f, tcx=cx, abbrevs=metadata::ac_no_abbrevs);
+ auto s = metadata::Encode::ty_str(ecx, typ);
+ if (_str::byte_len(s) >= 32u) { s = _str::substr(s, 0u, 32u); }
ret s;
}
fn sequence_element_type(&ctxt cx, &t ty) -> t {
alt (struct(cx, ty)) {
- case (ty_str) { ret mk_mach(cx, common.ty_u8); }
+ case (ty_str) { ret mk_mach(cx, common::ty_u8); }
case (ty_vec(?mt)) { ret mt.ty; }
}
fail;
alt (struct(cx, ty)) {
case (ty_tup(?mts)) {
auto i = 0u;
- while (i < Vec.len[mt](mts)) {
+ while (i < _vec::len[mt](mts)) {
if (type_has_dynamic_size(cx, mts.(i).ty)) { ret true; }
i += 1u;
}
}
case (ty_rec(?fields)) {
auto i = 0u;
- while (i < Vec.len[field](fields)) {
+ while (i < _vec::len[field](fields)) {
if (type_has_dynamic_size(cx, fields.(i).mt.ty)) {
ret true;
}
}
case (ty_tag(_, ?subtys)) {
auto i = 0u;
- while (i < Vec.len[t](subtys)) {
+ while (i < _vec::len[t](subtys)) {
if (type_has_dynamic_size(cx, subtys.(i))) { ret true; }
i += 1u;
}
case (ty_uint) { ret true; }
case (ty_machine(?m)) {
alt (m) {
- case (common.ty_i8) { ret true; }
- case (common.ty_i16) { ret true; }
- case (common.ty_i32) { ret true; }
- case (common.ty_i64) { ret true; }
-
- case (common.ty_u8) { ret true; }
- case (common.ty_u16) { ret true; }
- case (common.ty_u32) { ret true; }
- case (common.ty_u64) { ret true; }
+ case (common::ty_i8) { ret true; }
+ case (common::ty_i16) { ret true; }
+ case (common::ty_i32) { ret true; }
+ case (common::ty_i64) { ret true; }
+
+ case (common::ty_u8) { ret true; }
+ case (common::ty_u16) { ret true; }
+ case (common::ty_u32) { ret true; }
+ case (common::ty_u64) { ret true; }
case (_) { ret false; }
}
}
alt (struct(cx, ty)) {
case (ty_machine(?tm)) {
alt (tm) {
- case (common.ty_f32) { ret true; }
- case (common.ty_f64) { ret true; }
+ case (common::ty_f32) { ret true; }
+ case (common::ty_f64) { ret true; }
case (_) { ret false; }
}
}
case (ty_int) { ret true; }
case (ty_machine(?tm)) {
alt (tm) {
- case (common.ty_i8) { ret true; }
- case (common.ty_i16) { ret true; }
- case (common.ty_i32) { ret true; }
- case (common.ty_i64) { ret true; }
+ case (common::ty_i8) { ret true; }
+ case (common::ty_i16) { ret true; }
+ case (common::ty_i32) { ret true; }
+ case (common::ty_i64) { ret true; }
case (_) { ret false; }
}
}
fail;
}
-fn type_param(&ctxt cx, &t ty) -> Option.t[uint] {
+fn type_param(&ctxt cx, &t ty) -> option::t[uint] {
alt (struct(cx, ty)) {
case (ty_param(?id)) { ret some[uint](id); }
case (_) { /* fall through */ }
ret none[uint];
}
-fn def_to_str(&ast.def_id did) -> str {
+fn def_to_str(&ast::def_id did) -> str {
ret #fmt("%d:%d", did._0, did._1);
}
ret h;
}
- fn hash_def(uint id, ast.def_id did) -> uint {
+ fn hash_def(uint id, ast::def_id did) -> uint {
auto h = id;
h += h << 5u + (did._0 as uint);
h += h << 5u + (did._1 as uint);
case (ty_uint) { ret 4u; }
case (ty_machine(?tm)) {
alt (tm) {
- case (common.ty_i8) { ret 5u; }
- case (common.ty_i16) { ret 6u; }
- case (common.ty_i32) { ret 7u; }
- case (common.ty_i64) { ret 8u; }
+ case (common::ty_i8) { ret 5u; }
+ case (common::ty_i16) { ret 6u; }
+ case (common::ty_i32) { ret 7u; }
+ case (common::ty_i64) { ret 8u; }
- case (common.ty_u8) { ret 9u; }
- case (common.ty_u16) { ret 10u; }
- case (common.ty_u32) { ret 11u; }
- case (common.ty_u64) { ret 12u; }
+ case (common::ty_u8) { ret 9u; }
+ case (common::ty_u16) { ret 10u; }
+ case (common::ty_u32) { ret 11u; }
+ case (common::ty_u64) { ret 12u; }
- case (common.ty_f32) { ret 13u; }
- case (common.ty_f64) { ret 14u; }
+ case (common::ty_f32) { ret 13u; }
+ case (common::ty_f64) { ret 14u; }
}
}
case (ty_char) { ret 15u; }
case (ty_obj(?methods)) {
auto h = 27u;
for (method m in methods) {
- h += h << 5u + Str.hash(m.ident);
+ h += h << 5u + _str::hash(m.ident);
}
ret h;
}
}
}
-fn hash_type_info(&sty st, &Option.t[str] cname_opt) -> uint {
+fn hash_type_info(&sty st, &option::t[str] cname_opt) -> uint {
auto h = hash_type_structure(st);
alt (cname_opt) {
case (none[str]) { /* no-op */ }
- case (some[str](?s)) { h += h << 5u + Str.hash(s); }
+ case (some[str](?s)) { h += h << 5u + _str::hash(s); }
}
ret h;
}
&vec[arg] args_b, &t rty_b) -> bool {
if (!eq_ty(rty_a, rty_b)) { ret false; }
- auto len = Vec.len[arg](args_a);
- if (len != Vec.len[arg](args_b)) { ret false; }
+ auto len = _vec::len[arg](args_a);
+ if (len != _vec::len[arg](args_b)) { ret false; }
auto i = 0u;
while (i < len) {
ret true;
}
- fn equal_def(&ast.def_id did_a, &ast.def_id did_b) -> bool {
+ fn equal_def(&ast::def_id did_a, &ast::def_id did_b) -> bool {
ret did_a._0 == did_b._0 && did_a._1 == did_b._1;
}
case (ty_tag(?id_b, ?tys_b)) {
if (!equal_def(id_a, id_b)) { ret false; }
- auto len = Vec.len[t](tys_a);
- if (len != Vec.len[t](tys_b)) { ret false; }
+ auto len = _vec::len[t](tys_a);
+ if (len != _vec::len[t](tys_b)) { ret false; }
auto i = 0u;
while (i < len) {
if (!eq_ty(tys_a.(i), tys_b.(i))) { ret false; }
case (ty_tup(?mts_a)) {
alt (b) {
case (ty_tup(?mts_b)) {
- auto len = Vec.len[mt](mts_a);
- if (len != Vec.len[mt](mts_b)) { ret false; }
+ auto len = _vec::len[mt](mts_a);
+ if (len != _vec::len[mt](mts_b)) { ret false; }
auto i = 0u;
while (i < len) {
if (!equal_mt(mts_a.(i), mts_b.(i))) { ret false; }
case (ty_rec(?flds_a)) {
alt (b) {
case (ty_rec(?flds_b)) {
- auto len = Vec.len[field](flds_a);
- if (len != Vec.len[field](flds_b)) { ret false; }
+ auto len = _vec::len[field](flds_a);
+ if (len != _vec::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) ||
+ if (!_str::eq(fld_a.ident, fld_b.ident) ||
!equal_mt(fld_a.mt, fld_b.mt)) {
ret false;
}
case (ty_obj(?methods_a)) {
alt (b) {
case (ty_obj(?methods_b)) {
- auto len = Vec.len[method](methods_a);
- if (len != Vec.len[method](methods_b)) { ret false; }
+ auto len = _vec::len[method](methods_a);
+ if (len != _vec::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) ||
+ !_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 (some[str](?s_a)) {
alt (b.cname) {
case (some[str](?s_b)) {
- if (!Str.eq(s_a, s_b)) { ret false; }
+ if (!_str::eq(s_a, s_b)) { ret false; }
}
case (_) { ret false; }
}
fn eq_ty(&t a, &t b) -> bool { ret a == b; }
-fn ann_to_type(&ast.ann ann) -> t {
+fn ann_to_type(&ast::ann ann) -> t {
alt (ann) {
- case (ast.ann_none(_)) {
+ case (ast::ann_none(_)) {
log_err "ann_to_type() called on node with no type";
fail;
}
- case (ast.ann_type(_, ?ty, _, _)) {
+ case (ast::ann_type(_, ?ty, _, _)) {
ret ty;
}
}
}
-fn ann_to_type_params(&ast.ann ann) -> vec[t] {
+fn ann_to_type_params(&ast::ann ann) -> vec[t] {
alt (ann) {
- case (ast.ann_none(_)) {
+ case (ast::ann_none(_)) {
log_err "ann_to_type_params() called on node with no type params";
fail;
}
- case (ast.ann_type(_, _, ?tps, _)) {
+ case (ast::ann_type(_, _, ?tps, _)) {
alt (tps) {
case (none[vec[t]]) {
let vec[t] result = vec();
// Returns the type of an annotation, with type parameter substitutions
// performed if applicable.
-fn ann_to_monotype(ctxt cx, ast.ann a) -> t {
+fn ann_to_monotype(ctxt cx, ast::ann a) -> t {
// TODO: Refactor to use recursive pattern matching when we're more
// confident that it works.
alt (a) {
- case (ast.ann_none(_)) {
+ case (ast::ann_none(_)) {
log_err "ann_to_monotype() called on expression with no type!";
fail;
}
- case (ast.ann_type(_, ?typ, ?tps_opt, _)) {
+ case (ast::ann_type(_, ?typ, ?tps_opt, _)) {
alt (tps_opt) {
case (none[vec[t]]) { ret typ; }
case (some[vec[t]](?tps)) {
}
// Turns a type into an ann_type, using defaults for other fields.
-fn triv_ann(&ast.ann old, t typ) -> ast.ann {
- ret ast.ann_type(ast.ann_tag(old), typ, none[vec[t]], none[@ts_ann]);
+fn triv_ann(&ast::ann old, t typ) -> ast::ann {
+ ret ast::ann_type(ast::ann_tag(old), typ, none[vec[t]], none[@ts_ann]);
}
// Returns the number of distinct type parameters in the given type.
let @mutable vec[uint] param_indices = @mutable v;
auto f = bind counter(cx, param_indices, _);
walk_ty(cx, f, ty);
- ret Vec.len[uint](*param_indices);
+ ret _vec::len[uint](*param_indices);
}
fn type_contains_vars(&ctxt cx, &t typ) -> bool {
fn ty_fn_args(&ctxt cx, &t fty) -> vec[arg] {
alt (struct(cx, fty)) {
- case (ty.ty_fn(_, ?a, _)) { ret a; }
- case (ty.ty_native_fn(_, ?a, _)) { ret a; }
+ case (ty::ty_fn(_, ?a, _)) { ret a; }
+ case (ty::ty_native_fn(_, ?a, _)) { ret a; }
}
fail;
}
-fn ty_fn_proto(&ctxt cx, &t fty) -> ast.proto {
+fn ty_fn_proto(&ctxt cx, &t fty) -> ast::proto {
alt (struct(cx, fty)) {
- case (ty.ty_fn(?p, _, _)) { ret p; }
+ case (ty::ty_fn(?p, _, _)) { ret p; }
}
fail;
}
-fn ty_fn_abi(&ctxt cx, &t fty) -> ast.native_abi {
+fn ty_fn_abi(&ctxt cx, &t fty) -> ast::native_abi {
alt (struct(cx, fty)) {
- case (ty.ty_native_fn(?a, _, _)) { ret a; }
+ case (ty::ty_native_fn(?a, _, _)) { ret a; }
}
fail;
}
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; }
+ case (ty::ty_fn(_, _, ?r)) { ret r; }
+ case (ty::ty_native_fn(_, _, ?r)) { ret r; }
}
fail;
}
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 (ty::ty_fn(_, _, _)) { ret true; }
+ case (ty::ty_native_fn(_, _, _)) { ret true; }
case (_) { ret false; }
}
ret false;
// Given an item, returns the associated type as well as the number of type
// parameters it has.
-fn native_item_ty(&@ast.native_item it) -> ty_param_count_and_ty {
+fn native_item_ty(&@ast::native_item it) -> ty_param_count_and_ty {
auto ty_param_count;
auto result_ty;
alt (it.node) {
- case (ast.native_item_fn(_, _, _, ?tps, _, ?ann)) {
- ty_param_count = Vec.len[ast.ty_param](tps);
+ case (ast::native_item_fn(_, _, _, ?tps, _, ?ann)) {
+ ty_param_count = _vec::len[ast::ty_param](tps);
result_ty = ann_to_type(ann);
}
}
ret tup(ty_param_count, result_ty);
}
-fn item_ty(&@ast.item it) -> ty_param_count_and_ty {
+fn item_ty(&@ast::item it) -> ty_param_count_and_ty {
auto ty_param_count;
auto result_ty;
alt (it.node) {
- case (ast.item_const(_, _, _, _, ?ann)) {
+ case (ast::item_const(_, _, _, _, ?ann)) {
ty_param_count = 0u;
result_ty = ann_to_type(ann);
}
- case (ast.item_fn(_, _, ?tps, _, ?ann)) {
- ty_param_count = Vec.len[ast.ty_param](tps);
+ case (ast::item_fn(_, _, ?tps, _, ?ann)) {
+ ty_param_count = _vec::len[ast::ty_param](tps);
result_ty = ann_to_type(ann);
}
- case (ast.item_mod(_, _, _)) {
+ case (ast::item_mod(_, _, _)) {
fail; // modules are typeless
}
- case (ast.item_ty(_, _, ?tps, _, ?ann)) {
- ty_param_count = Vec.len[ast.ty_param](tps);
+ case (ast::item_ty(_, _, ?tps, _, ?ann)) {
+ ty_param_count = _vec::len[ast::ty_param](tps);
result_ty = ann_to_type(ann);
}
- case (ast.item_tag(_, _, ?tps, ?did, ?ann)) {
- ty_param_count = Vec.len[ast.ty_param](tps);
+ case (ast::item_tag(_, _, ?tps, ?did, ?ann)) {
+ ty_param_count = _vec::len[ast::ty_param](tps);
result_ty = ann_to_type(ann);
}
- case (ast.item_obj(_, _, ?tps, _, ?ann)) {
- ty_param_count = Vec.len[ast.ty_param](tps);
+ case (ast::item_obj(_, _, ?tps, _, ?ann)) {
+ ty_param_count = _vec::len[ast::ty_param](tps);
result_ty = ann_to_type(ann);
}
}
ret tup(ty_param_count, result_ty);
}
-fn stmt_ty(&ctxt cx, &@ast.stmt s) -> t {
+fn stmt_ty(&ctxt cx, &@ast::stmt s) -> t {
alt (s.node) {
- case (ast.stmt_expr(?e,_)) {
+ case (ast::stmt_expr(?e,_)) {
ret expr_ty(cx, e);
}
case (_) {
}
}
-fn block_ty(&ctxt cx, &ast.block b) -> t {
+fn block_ty(&ctxt cx, &ast::block b) -> t {
alt (b.node.expr) {
- case (some[@ast.expr](?e)) { ret expr_ty(cx, e); }
- case (none[@ast.expr]) { ret mk_nil(cx); }
+ case (some[@ast::expr](?e)) { ret expr_ty(cx, e); }
+ case (none[@ast::expr]) { ret mk_nil(cx); }
}
}
// 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(&ctxt cx, &@ast::pat pat) -> t {
alt (pat.node) {
- case (ast.pat_wild(?ann)) { ret ann_to_monotype(cx, ann); }
- case (ast.pat_lit(_, ?ann)) { ret ann_to_monotype(cx, ann); }
- case (ast.pat_bind(_, _, ?ann)) { ret ann_to_monotype(cx, ann); }
- case (ast.pat_tag(_, _, ?ann)) { ret ann_to_monotype(cx, ann); }
+ case (ast::pat_wild(?ann)) { ret ann_to_monotype(cx, ann); }
+ case (ast::pat_lit(_, ?ann)) { ret ann_to_monotype(cx, ann); }
+ case (ast::pat_bind(_, _, ?ann)) { ret ann_to_monotype(cx, ann); }
+ case (ast::pat_tag(_, _, ?ann)) { ret ann_to_monotype(cx, ann); }
}
fail; // not reached
}
-fn expr_ann(&@ast.expr e) -> ast.ann {
+fn expr_ann(&@ast::expr e) -> ast::ann {
alt(e.node) {
- case (ast.expr_vec(_,_,?a)) {
+ case (ast::expr_vec(_,_,?a)) {
ret a;
}
- case (ast.expr_tup(_,?a)) {
+ case (ast::expr_tup(_,?a)) {
ret a;
}
- case (ast.expr_rec(_,_,?a)) {
+ case (ast::expr_rec(_,_,?a)) {
ret a;
}
- case (ast.expr_call(_,_,?a)) {
+ case (ast::expr_call(_,_,?a)) {
ret a;
}
- case (ast.expr_bind(_,_,?a)) {
+ case (ast::expr_bind(_,_,?a)) {
ret a;
}
- case (ast.expr_binary(_,_,_,?a)) {
+ case (ast::expr_binary(_,_,_,?a)) {
ret a;
}
- case (ast.expr_unary(_,_,?a)) {
+ case (ast::expr_unary(_,_,?a)) {
ret a;
}
- case (ast.expr_lit(_,?a)) {
+ case (ast::expr_lit(_,?a)) {
ret a;
}
- case (ast.expr_cast(_,_,?a)) {
+ case (ast::expr_cast(_,_,?a)) {
ret a;
}
- case (ast.expr_if(_,_,_,?a)) {
+ case (ast::expr_if(_,_,_,?a)) {
ret a;
}
- case (ast.expr_while(_,_,?a)) {
+ case (ast::expr_while(_,_,?a)) {
ret a;
}
- case (ast.expr_for(_,_,_,?a)) {
+ case (ast::expr_for(_,_,_,?a)) {
ret a;
}
- case (ast.expr_for_each(_,_,_,?a)) {
+ case (ast::expr_for_each(_,_,_,?a)) {
ret a;
}
- case (ast.expr_do_while(_,_,?a)) {
+ case (ast::expr_do_while(_,_,?a)) {
ret a;
}
- case (ast.expr_alt(_,_,?a)) {
+ case (ast::expr_alt(_,_,?a)) {
ret a;
}
- case (ast.expr_block(_,?a)) {
+ case (ast::expr_block(_,?a)) {
ret a;
}
- case (ast.expr_assign(_,_,?a)) {
+ case (ast::expr_assign(_,_,?a)) {
ret a;
}
- case (ast.expr_assign_op(_,_,_,?a)) {
+ case (ast::expr_assign_op(_,_,_,?a)) {
ret a;
}
- case (ast.expr_send(_,_,?a)) {
+ case (ast::expr_send(_,_,?a)) {
ret a;
}
- case (ast.expr_recv(_,_,?a)) {
+ case (ast::expr_recv(_,_,?a)) {
ret a;
}
- case (ast.expr_field(_,_,?a)) {
+ case (ast::expr_field(_,_,?a)) {
ret a;
}
- case (ast.expr_index(_,_,?a)) {
+ case (ast::expr_index(_,_,?a)) {
ret a;
}
- case (ast.expr_path(_,?a)) {
+ case (ast::expr_path(_,?a)) {
ret a;
}
- case (ast.expr_ext(_,_,_,_,?a)) {
+ case (ast::expr_ext(_,_,_,_,?a)) {
ret a;
}
- case (ast.expr_fail(?a)) {
+ case (ast::expr_fail(?a)) {
ret a;
}
- case (ast.expr_ret(_,?a)) {
+ case (ast::expr_ret(_,?a)) {
ret a;
}
- case (ast.expr_put(_,?a)) {
+ case (ast::expr_put(_,?a)) {
ret a;
}
- case (ast.expr_be(_,?a)) {
+ case (ast::expr_be(_,?a)) {
ret a;
}
- case (ast.expr_log(_,_,?a)) {
+ case (ast::expr_log(_,_,?a)) {
ret a;
}
- case (ast.expr_assert(_,?a)) {
+ case (ast::expr_assert(_,?a)) {
ret a;
}
- case (ast.expr_check(_,?a)) {
+ case (ast::expr_check(_,?a)) {
ret a;
}
- case (ast.expr_port(?a)) {
+ case (ast::expr_port(?a)) {
ret a;
}
- case (ast.expr_chan(_,?a)) {
+ case (ast::expr_chan(_,?a)) {
ret a;
}
- case (ast.expr_break(?a)) {
+ case (ast::expr_break(?a)) {
ret a;
}
- case (ast.expr_cont(?a)) {
+ case (ast::expr_cont(?a)) {
ret a;
}
- case (ast.expr_self_method(_, ?a)) {
+ case (ast::expr_self_method(_, ?a)) {
ret a;
}
}
// 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(&ctxt cx, &@ast::expr expr) -> t {
ret ann_to_monotype(cx, expr_ann(expr));
}
-fn expr_ty_params_and_ty(&ctxt cx, &@ast.expr expr) -> tup(vec[t], t) {
+fn expr_ty_params_and_ty(&ctxt cx, &@ast::expr expr) -> tup(vec[t], t) {
auto a = expr_ann(expr);
ret tup(ann_to_type_params(a), ann_to_type(a));
}
-fn expr_has_ty_params(&@ast.expr expr) -> bool {
+fn expr_has_ty_params(&@ast::expr expr) -> bool {
// FIXME: Rewrite using complex patterns when they're trustworthy.
alt (expr_ann(expr)) {
- case (ast.ann_none(_)) { fail; }
- case (ast.ann_type(_, _, ?tps_opt, _)) {
- ret !Option.is_none[vec[t]](tps_opt);
+ case (ast::ann_none(_)) { fail; }
+ case (ast::ann_type(_, _, ?tps_opt, _)) {
+ ret !option::is_none[vec[t]](tps_opt);
}
}
}
// FIXME: At the moment this works only for call, bind, and path expressions.
-fn replace_expr_type(&@ast.expr expr,
- &tup(vec[t], t) new_tyt) -> @ast.expr {
+fn replace_expr_type(&@ast::expr expr,
+ &tup(vec[t], t) new_tyt) -> @ast::expr {
auto new_tps;
if (expr_has_ty_params(expr)) {
new_tps = some[vec[t]](new_tyt._0);
new_tps = none[vec[t]];
}
- fn mkann_fn(t tyt, Option.t[vec[t]] tps, &ast.ann old_ann) -> ast.ann {
- ret ast.ann_type(ast.ann_tag(old_ann), tyt, tps, none[@ts_ann]);
+ fn mkann_fn(t tyt, option::t[vec[t]] tps, &ast::ann old_ann) -> ast::ann {
+ ret ast::ann_type(ast::ann_tag(old_ann), tyt, tps, none[@ts_ann]);
}
auto mkann = bind mkann_fn(new_tyt._1, new_tps, _);
alt (expr.node) {
- case (ast.expr_call(?callee, ?args, ?a)) {
- ret @fold.respan(expr.span,
- ast.expr_call(callee, args, mkann(a)));
+ case (ast::expr_call(?callee, ?args, ?a)) {
+ ret @fold::respan(expr.span,
+ ast::expr_call(callee, args, mkann(a)));
}
- case (ast.expr_self_method(?ident, ?a)) {
- ret @fold.respan(expr.span,
- ast.expr_self_method(ident, mkann(a)));
+ case (ast::expr_self_method(?ident, ?a)) {
+ ret @fold::respan(expr.span,
+ ast::expr_self_method(ident, mkann(a)));
}
- case (ast.expr_bind(?callee, ?args, ?a)) {
- ret @fold.respan(expr.span,
- ast.expr_bind(callee, args, mkann(a)));
+ case (ast::expr_bind(?callee, ?args, ?a)) {
+ ret @fold::respan(expr.span,
+ ast::expr_bind(callee, args, mkann(a)));
}
- case (ast.expr_field(?e, ?i, ?a)) {
- ret @fold.respan(expr.span,
- ast.expr_field(e, i, mkann(a)));
+ case (ast::expr_field(?e, ?i, ?a)) {
+ ret @fold::respan(expr.span,
+ ast::expr_field(e, i, mkann(a)));
}
- case (ast.expr_path(?p, ?a)) {
- ret @fold.respan(expr.span,
- ast.expr_path(p, mkann(a)));
+ case (ast::expr_path(?p, ?a)) {
+ ret @fold::respan(expr.span,
+ ast::expr_path(p, mkann(a)));
}
case (_) {
log_err "unhandled expr type in replace_expr_type(): " +
- util.common.expr_to_str(expr);
+ util::common::expr_to_str(expr);
fail;
}
}
// Expression utilities
-fn field_num(&session.session sess, &span sp,
- &ast.ident id) -> uint {
+fn field_num(&session::session sess, &span sp,
+ &ast::ident id) -> uint {
let uint accum = 0u;
let uint i = 0u;
for (u8 c in id) {
accum += (c as uint) - ('0' as uint);
} else {
auto s = "";
- s += Str.unsafe_from_byte(c);
+ s += _str::unsafe_from_byte(c);
sess.span_err(sp,
"bad numeric field on tuple: "
+ " non-digit character: "
ret accum;
}
-fn field_idx(&session.session sess, &span sp,
- &ast.ident id, &vec[field] fields) -> uint {
+fn field_idx(&session::session sess, &span sp,
+ &ast::ident id, &vec[field] fields) -> uint {
let uint i = 0u;
for (field f in fields) {
- if (Str.eq(f.ident, id)) {
+ if (_str::eq(f.ident, id)) {
ret i;
}
i += 1u;
fail;
}
-fn method_idx(&session.session sess, &span sp,
- &ast.ident id, &vec[method] meths) -> uint {
+fn method_idx(&session::session sess, &span sp,
+ &ast::ident id, &vec[method] meths) -> uint {
let uint i = 0u;
for (method m in meths) {
- if (Str.eq(m.ident, id)) {
+ if (_str::eq(m.ident, id)) {
ret i;
}
i += 1u;
fn sort_methods(&vec[method] meths) -> vec[method] {
fn method_lteq(&method a, &method b) -> bool {
- ret Str.lteq(a.ident, b.ident);
+ ret _str::lteq(a.ident, b.ident);
}
- ret std.Sort.merge_sort[method](bind method_lteq(_,_), meths);
+ ret std::sort::merge_sort[method](bind method_lteq(_,_), meths);
}
-fn is_lval(&@ast.expr expr) -> bool {
+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 (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; }
}
}
ures_err(type_err, t, t);
}
- type ctxt = rec(UFind.ufind sets,
+ type ctxt = rec(ufind::ufind sets,
hashmap[int,uint] var_ids,
mutable vec[mutable vec[t]] types,
unify_handler handler,
}
// Unifies two mutability flags.
- fn unify_mut(ast.mutability expected, ast.mutability actual)
- -> Option.t[ast.mutability] {
+ fn unify_mut(ast::mutability expected, ast::mutability actual)
+ -> option::t[ast::mutability] {
if (expected == actual) {
- ret some[ast.mutability](expected);
+ ret some[ast::mutability](expected);
}
- if (expected == ast.maybe_mut) {
- ret some[ast.mutability](actual);
+ if (expected == ast::maybe_mut) {
+ ret some[ast::mutability](actual);
}
- if (actual == ast.maybe_mut) {
- ret some[ast.mutability](expected);
+ if (actual == ast::maybe_mut) {
+ ret some[ast::mutability](expected);
}
- ret none[ast.mutability];
+ ret none[ast::mutability];
}
tag fn_common_res {
&vec[arg] expected_inputs, &t expected_output,
&vec[arg] actual_inputs, &t actual_output)
-> fn_common_res {
- auto expected_len = Vec.len[arg](expected_inputs);
- auto actual_len = Vec.len[arg](actual_inputs);
+ auto expected_len = _vec::len[arg](expected_inputs);
+ auto actual_len = _vec::len[arg](actual_inputs);
if (expected_len != actual_len) {
ret fn_common_res_err(ures_err(terr_arg_count,
expected, actual));
}
fn unify_fn(&@ctxt cx,
- &ast.proto e_proto,
- &ast.proto a_proto,
+ &ast::proto e_proto,
+ &ast::proto a_proto,
&t expected,
&t actual,
&vec[arg] expected_inputs, &t expected_output,
}
fn unify_native_fn(&@ctxt cx,
- &ast.native_abi e_abi,
- &ast.native_abi a_abi,
+ &ast::native_abi e_abi,
+ &ast::native_abi a_abi,
&t expected,
&t actual,
&vec[arg] expected_inputs, &t expected_output,
&vec[method] actual_meths) -> result {
let vec[method] result_meths = vec();
let uint i = 0u;
- let uint expected_len = Vec.len[method](expected_meths);
- let uint actual_len = Vec.len[method](actual_meths);
+ let uint expected_len = _vec::len[method](expected_meths);
+ let uint actual_len = _vec::len[method](actual_meths);
if (expected_len != actual_len) {
ret ures_err(terr_meth_count, expected, actual);
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)) {
+ if (! _str::eq(e_meth.ident, a_meth.ident)) {
ret ures_err(terr_obj_meths(e_meth.ident, a_meth.ident),
expected, actual);
}
auto set_num;
alt (cx.var_ids.find(id)) {
case (none[uint]) {
- set_num = UFind.make_set(cx.sets);
+ set_num = ufind::make_set(cx.sets);
cx.var_ids.insert(id, set_num);
}
case (some[uint](?n)) { set_num = n; }
alt (struct(cx.tcx, actual)) {
// If the RHS is a variable type, then just do the appropriate
// binding.
- case (ty.ty_var(?actual_id)) {
+ case (ty::ty_var(?actual_id)) {
auto actual_n = get_or_create_set(cx, actual_id);
alt (struct(cx.tcx, expected)) {
- case (ty.ty_var(?expected_id)) {
+ case (ty::ty_var(?expected_id)) {
auto expected_n = get_or_create_set(cx, expected_id);
- UFind.union(cx.sets, expected_n, actual_n);
+ ufind::union(cx.sets, expected_n, actual_n);
}
case (_) {
// Just bind the type variable to the expected type.
- auto vlen = Vec.len[vec[t]](cx.types);
+ auto vlen = _vec::len[vec[t]](cx.types);
if (actual_n < vlen) {
cx.types.(actual_n) += vec(expected);
} else {
}
ret ures_ok(actual);
}
- case (ty.ty_local(?actual_id)) {
+ case (ty::ty_local(?actual_id)) {
auto result_ty;
alt (cx.handler.resolve_local(actual_id)) {
case (none[t]) { result_ty = expected; }
cx.handler.record_local(actual_id, result_ty);
ret ures_ok(result_ty);
}
- case (ty.ty_bound_param(?actual_id)) {
+ case (ty::ty_bound_param(?actual_id)) {
alt (struct(cx.tcx, expected)) {
- case (ty.ty_local(_)) {
+ case (ty::ty_local(_)) {
log_err "TODO: bound param unifying with local";
fail;
}
}
alt (struct(cx.tcx, expected)) {
- case (ty.ty_nil) { ret struct_cmp(cx, expected, 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_type) { ret struct_cmp(cx, expected, actual); }
- case (ty.ty_native) { ret struct_cmp(cx, expected, actual); }
- case (ty.ty_param(_)) { ret struct_cmp(cx, expected, actual); }
-
- case (ty.ty_tag(?expected_id, ?expected_tps)) {
+ case (ty::ty_nil) { ret struct_cmp(cx, expected, 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_type) { ret struct_cmp(cx, expected, actual); }
+ case (ty::ty_native) { ret struct_cmp(cx, expected, actual); }
+ 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)) {
+ case (ty::ty_tag(?actual_id, ?actual_tps)) {
if (expected_id._0 != actual_id._0 ||
expected_id._1 != actual_id._1) {
ret ures_err(terr_mismatch, expected, actual);
}
// TODO: factor this cruft out, see the TODO in the
- // ty.ty_tup case
+ // ty::ty_tup case
let vec[t] result_tps = vec();
auto i = 0u;
- auto expected_len = Vec.len[t](expected_tps);
+ auto expected_len = _vec::len[t](expected_tps);
while (i < expected_len) {
auto expected_tp = expected_tps.(i);
auto actual_tp = actual_tps.(i);
alt (result) {
case (ures_ok(?rty)) {
- Vec.push[t](result_tps, rty);
+ _vec::push[t](result_tps, rty);
}
case (_) {
ret result;
ret ures_err(terr_mismatch, expected, actual);
}
- case (ty.ty_box(?expected_mt)) {
+ case (ty::ty_box(?expected_mt)) {
alt (struct(cx.tcx, actual)) {
- case (ty.ty_box(?actual_mt)) {
+ case (ty::ty_box(?actual_mt)) {
auto mut;
alt (unify_mut(expected_mt.mut, actual_mt.mut)) {
- case (none[ast.mutability]) {
+ case (none[ast::mutability]) {
ret ures_err(terr_box_mutability, expected,
actual);
}
- case (some[ast.mutability](?m)) { mut = m; }
+ case (some[ast::mutability](?m)) { mut = m; }
}
auto result = unify_step(cx,
}
}
- case (ty.ty_vec(?expected_mt)) {
+ case (ty::ty_vec(?expected_mt)) {
alt (struct(cx.tcx, actual)) {
- case (ty.ty_vec(?actual_mt)) {
+ case (ty::ty_vec(?actual_mt)) {
auto mut;
alt (unify_mut(expected_mt.mut, actual_mt.mut)) {
- case (none[ast.mutability]) {
+ case (none[ast::mutability]) {
ret ures_err(terr_vec_mutability, expected,
actual);
}
- case (some[ast.mutability](?m)) { mut = m; }
+ case (some[ast::mutability](?m)) { mut = m; }
}
auto result = unify_step(cx,
}
}
- case (ty.ty_port(?expected_sub)) {
+ case (ty::ty_port(?expected_sub)) {
alt (struct(cx.tcx, actual)) {
- case (ty.ty_port(?actual_sub)) {
+ case (ty::ty_port(?actual_sub)) {
auto result = unify_step(cx,
expected_sub,
actual_sub);
}
}
- case (ty.ty_chan(?expected_sub)) {
+ case (ty::ty_chan(?expected_sub)) {
alt (struct(cx.tcx, actual)) {
- case (ty.ty_chan(?actual_sub)) {
+ case (ty::ty_chan(?actual_sub)) {
auto result = unify_step(cx,
expected_sub,
actual_sub);
}
}
- case (ty.ty_tup(?expected_elems)) {
+ case (ty::ty_tup(?expected_elems)) {
alt (struct(cx.tcx, actual)) {
- case (ty.ty_tup(?actual_elems)) {
- auto expected_len = Vec.len[ty.mt](expected_elems);
- auto actual_len = Vec.len[ty.mt](actual_elems);
+ case (ty::ty_tup(?actual_elems)) {
+ auto expected_len = _vec::len[ty::mt](expected_elems);
+ auto actual_len = _vec::len[ty::mt](actual_elems);
if (expected_len != actual_len) {
auto err = terr_tuple_size(expected_len,
actual_len);
// TODO: implement an iterator that can iterate over
// two arrays simultaneously.
- let vec[ty.mt] result_elems = vec();
+ let vec[ty::mt] result_elems = vec();
auto i = 0u;
while (i < expected_len) {
auto expected_elem = expected_elems.(i);
auto mut;
alt (unify_mut(expected_elem.mut,
actual_elem.mut)) {
- case (none[ast.mutability]) {
+ case (none[ast::mutability]) {
auto err = terr_tuple_mutability;
ret ures_err(err, expected, actual);
}
- case (some[ast.mutability](?m)) { mut = m; }
+ case (some[ast::mutability](?m)) { mut = m; }
}
auto result = unify_step(cx,
}
}
- case (ty.ty_rec(?expected_fields)) {
+ case (ty::ty_rec(?expected_fields)) {
alt (struct(cx.tcx, actual)) {
- case (ty.ty_rec(?actual_fields)) {
- auto expected_len = Vec.len[field](expected_fields);
- auto actual_len = Vec.len[field](actual_fields);
+ case (ty::ty_rec(?actual_fields)) {
+ auto expected_len = _vec::len[field](expected_fields);
+ auto actual_len = _vec::len[field](actual_fields);
if (expected_len != actual_len) {
auto err = terr_record_size(expected_len,
actual_len);
auto mut;
alt (unify_mut(expected_field.mt.mut,
actual_field.mt.mut)) {
- case (none[ast.mutability]) {
+ case (none[ast::mutability]) {
ret ures_err(terr_record_mutability,
expected, actual);
}
- case (some[ast.mutability](?m)) { mut = m; }
+ case (some[ast::mutability](?m)) { mut = m; }
}
- if (!Str.eq(expected_field.ident,
+ if (!_str::eq(expected_field.ident,
actual_field.ident)) {
auto err =
terr_record_fields(expected_field.ident,
alt (result) {
case (ures_ok(?rty)) {
auto mt = rec(ty=rty, mut=mut);
- Vec.push[field]
+ _vec::push[field]
(result_fields,
rec(mt=mt with expected_field));
}
}
}
- case (ty.ty_fn(?ep, ?expected_inputs, ?expected_output)) {
+ case (ty::ty_fn(?ep, ?expected_inputs, ?expected_output)) {
alt (struct(cx.tcx, actual)) {
- case (ty.ty_fn(?ap, ?actual_inputs, ?actual_output)) {
+ case (ty::ty_fn(?ap, ?actual_inputs, ?actual_output)) {
ret unify_fn(cx, ep, ap,
expected, actual,
expected_inputs, expected_output,
}
}
- case (ty.ty_native_fn(?e_abi, ?expected_inputs,
+ 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,
+ case (ty::ty_native_fn(?a_abi, ?actual_inputs,
?actual_output)) {
ret unify_native_fn(cx, e_abi, a_abi,
expected, actual,
}
}
- case (ty.ty_obj(?expected_meths)) {
+ case (ty::ty_obj(?expected_meths)) {
alt (struct(cx.tcx, actual)) {
- case (ty.ty_obj(?actual_meths)) {
+ case (ty::ty_obj(?actual_meths)) {
ret unify_obj(cx, expected, actual,
expected_meths, actual_meths);
}
}
}
- case (ty.ty_var(?expected_id)) {
+ case (ty::ty_var(?expected_id)) {
// Add a binding.
auto expected_n = get_or_create_set(cx, expected_id);
- auto vlen = Vec.len[vec[t]](cx.types);
+ auto vlen = _vec::len[vec[t]](cx.types);
if (expected_n < vlen) {
cx.types.(expected_n) += vec(actual);
} else {
ret ures_ok(expected);
}
- case (ty.ty_local(?expected_id)) {
+ case (ty::ty_local(?expected_id)) {
auto result_ty;
alt (cx.handler.resolve_local(expected_id)) {
case (none[t]) { result_ty = actual; }
ret ures_ok(result_ty);
}
- case (ty.ty_bound_param(?expected_id)) {
+ case (ty::ty_bound_param(?expected_id)) {
ret cx.handler.record_param(expected_id, actual);
}
}
case (ty_var(?id)) {
alt (cx.var_ids.find(id)) {
case (some[uint](?n)) {
- auto root = UFind.find(cx.sets, n);
+ auto root = ufind::find(cx.sets, n);
ret types.(root);
}
case (none[uint]) { ret typ; }
fn unify_sets(&@ctxt cx) -> vec[t] {
let vec[t] throwaway = vec();
let vec[mutable vec[t]] set_types = vec(mutable throwaway);
- Vec.pop[vec[t]](set_types); // FIXME: botch
+ _vec::pop[vec[t]](set_types); // FIXME: botch
- for (UFind.node node in cx.sets.nodes) {
+ for (ufind::node node in cx.sets.nodes) {
let vec[t] v = vec();
set_types += vec(mutable v);
}
auto i = 0u;
- while (i < Vec.len[vec[t]](set_types)) {
- auto root = UFind.find(cx.sets, i);
+ while (i < _vec::len[vec[t]](set_types)) {
+ auto root = ufind::find(cx.sets, i);
set_types.(root) += cx.types.(i);
i += 1u;
}
let vec[t] result = vec();
for (vec[t] types in set_types) {
- if (Vec.len[t](types) > 1u) {
+ if (_vec::len[t](types) > 1u) {
log_err "unification of > 1 types in a type set is " +
"unimplemented";
fail;
&ty_ctxt tcx) -> result {
let vec[t] throwaway = vec();
let vec[mutable vec[t]] types = vec(mutable throwaway);
- Vec.pop[vec[t]](types); // FIXME: botch
+ _vec::pop[vec[t]](types); // FIXME: botch
- auto cx = @rec(sets=UFind.make(),
- var_ids=common.new_int_hash[uint](),
+ auto cx = @rec(sets=ufind::make(),
+ var_ids=common::new_int_hash[uint](),
mutable types=types,
handler=handler,
tcx=tcx);
case (ures_ok(?typ)) {
// Fast path: if there are no local variables, don't perform
// substitutions.
- if (Vec.len(cx.sets.nodes) == 0u) {
+ if (_vec::len(cx.sets.nodes) == 0u) {
ret ures_ok(typ);
}
}
}
-fn type_err_to_str(&ty.type_err err) -> str {
+fn type_err_to_str(&ty::type_err err) -> str {
alt (err) {
case (terr_mismatch) {
ret "types differ";
ret "vectors differ in mutability";
}
case (terr_tuple_size(?e_sz, ?a_sz)) {
- ret "expected a tuple with " + UInt.to_str(e_sz, 10u) +
- " elements but found one with " + UInt.to_str(a_sz, 10u) +
+ ret "expected a tuple with " + _uint::to_str(e_sz, 10u) +
+ " elements but found one with " + _uint::to_str(a_sz, 10u) +
" elements";
}
case (terr_tuple_mutability) {
ret "tuple elements 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) +
+ 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) {
}
-fn def_has_ty_params(&ast.def def) -> bool {
+fn def_has_ty_params(&ast::def def) -> bool {
alt (def) {
- case (ast.def_fn(_)) { ret true; }
- case (ast.def_obj(_)) { 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; }
+ case (ast::def_fn(_)) { ret true; }
+ case (ast::def_obj(_)) { 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; }
}
}
// 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(session.session sess,
+fn lookup_item_type(session::session sess,
ctxt cx,
&type_cache cache,
- ast.def_id did) -> ty_param_count_and_ty {
+ ast::def_id did) -> ty_param_count_and_ty {
if (did._0 == sess.get_targ_crate_num()) {
// The item is in this crate. The caller should have added it to the
// type cache already; we simply return it.
alt (cache.find(did)) {
case (some[ty_param_count_and_ty](?tpt)) { ret tpt; }
case (none[ty_param_count_and_ty]) {
- auto tyt = creader.get_type(sess, cx, did);
+ auto tyt = creader::get_type(sess, cx, did);
cache.insert(did, tyt);
ret tyt;
}
-import front.ast;
-import front.ast.ann;
-import front.ast.ann_none;
-import front.ast.mutability;
-import front.creader;
-import middle.fold;
-import driver.session;
-import util.common;
-import util.common.span;
-import util.common.plain_ann;
-import util.common.new_def_hash;
-import util.common.log_expr_err;
-
-import middle.ty;
-import middle.ty.ann_to_type;
-import middle.ty.arg;
-import middle.ty.bind_params_in_type;
-import middle.ty.block_ty;
-import middle.ty.expr_ty;
-import middle.ty.field;
-import middle.ty.method;
-import middle.ty.mo_val;
-import middle.ty.mo_alias;
-import middle.ty.mo_either;
-import middle.ty.pat_ty;
-import middle.ty.path_to_str;
-import middle.ty.struct;
-import middle.ty.triv_ann;
-import middle.ty.ty_to_str;
-import middle.ty.type_is_integral;
-import middle.ty.type_is_scalar;
-import middle.ty.ty_param_count_and_ty;
-import middle.ty.ty_nil;
-import middle.ty.Unify.ures_ok;
-import middle.ty.Unify.ures_err;
-
-import std.Str;
-import std.UInt;
-import std.Vec;
-import std.Map;
-import std.Map.hashmap;
-import std.Option;
-import std.Option.none;
-import std.Option.some;
-import std.Option.from_maybe;
-
-import util.typestate_ann.ts_ann;
-
-type ty_table = hashmap[ast.def_id, ty.t];
+import front::ast;
+import front::ast::ann;
+import front::ast::ann_none;
+import front::ast::mutability;
+import front::creader;
+import middle::fold;
+import driver::session;
+import util::common;
+import util::common::span;
+import util::common::plain_ann;
+import util::common::new_def_hash;
+import util::common::log_expr_err;
+
+import middle::ty;
+import middle::ty::ann_to_type;
+import middle::ty::arg;
+import middle::ty::bind_params_in_type;
+import middle::ty::block_ty;
+import middle::ty::expr_ty;
+import middle::ty::field;
+import middle::ty::method;
+import middle::ty::mo_val;
+import middle::ty::mo_alias;
+import middle::ty::mo_either;
+import middle::ty::pat_ty;
+import middle::ty::path_to_str;
+import middle::ty::struct;
+import middle::ty::triv_ann;
+import middle::ty::ty_to_str;
+import middle::ty::type_is_integral;
+import middle::ty::type_is_scalar;
+import middle::ty::ty_param_count_and_ty;
+import middle::ty::ty_nil;
+import middle::ty::Unify::ures_ok;
+import middle::ty::Unify::ures_err;
+
+import std::_str;
+import std::_uint;
+import std::_vec;
+import std::map;
+import std::map::hashmap;
+import std::option;
+import std::option::none;
+import std::option::some;
+import std::option::from_maybe;
+
+import util::typestate_ann::ts_ann;
+
+type ty_table = hashmap[ast::def_id, ty::t];
tag any_item {
- any_item_rust(@ast.item);
- any_item_native(@ast.native_item, ast.native_abi);
+ any_item_rust(@ast::item);
+ any_item_native(@ast::native_item, ast::native_abi);
}
-type ty_item_table = hashmap[ast.def_id,any_item];
-type fn_purity_table = hashmap[ast.def_id, ast.purity];
+type ty_item_table = hashmap[ast::def_id,any_item];
+type fn_purity_table = hashmap[ast::def_id, ast::purity];
-type unify_cache_entry = tup(ty.t,ty.t,vec[mutable ty.t]);
-type unify_cache = hashmap[unify_cache_entry,ty.Unify.result];
+type unify_cache_entry = tup(ty::t,ty::t,vec[mutable ty::t]);
+type unify_cache = hashmap[unify_cache_entry,ty::Unify::result];
-type crate_ctxt = rec(session.session sess,
- ty.type_cache type_cache,
+type crate_ctxt = rec(session::session sess,
+ ty::type_cache type_cache,
@ty_item_table item_items,
- vec[ast.obj_field] obj_fields,
- Option.t[ast.def_id] this_obj,
+ vec[ast::obj_field] obj_fields,
+ option::t[ast::def_id] this_obj,
@fn_purity_table fn_purity_table,
mutable int next_var_id,
unify_cache unify_cache,
mutable uint cache_hits,
mutable uint cache_misses,
- ty.ctxt tcx);
+ ty::ctxt tcx);
-type fn_ctxt = rec(ty.t ret_ty,
- ast.purity purity,
+type fn_ctxt = rec(ty::t ret_ty,
+ ast::purity purity,
@ty_table locals,
@crate_ctxt ccx);
// 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;
// Substitutes the user's explicit types for the parameters in a path
// expression.
fn substitute_ty_params(&@crate_ctxt ccx,
- &ty.t typ,
+ &ty::t typ,
uint ty_param_count,
- &vec[ty.t] supplied,
- &span sp) -> ty.t {
- fn substituter(@crate_ctxt ccx, vec[ty.t] supplied, ty.t typ) -> ty.t {
+ &vec[ty::t] supplied,
+ &span sp) -> ty::t {
+ fn substituter(@crate_ctxt ccx, vec[ty::t] supplied, ty::t typ) -> ty::t {
alt (struct(ccx.tcx, typ)) {
- case (ty.ty_bound_param(?pid)) { ret supplied.(pid); }
+ case (ty::ty_bound_param(?pid)) { ret supplied.(pid); }
case (_) { ret typ; }
}
}
- auto supplied_len = Vec.len[ty.t](supplied);
+ auto supplied_len = _vec::len[ty::t](supplied);
if (ty_param_count != supplied_len) {
ccx.sess.span_err(sp, "expected " +
- UInt.to_str(ty_param_count, 10u) +
+ _uint::to_str(ty_param_count, 10u) +
" type parameter(s) but found " +
- UInt.to_str(supplied_len, 10u) + " parameter(s)");
+ _uint::to_str(supplied_len, 10u) + " parameter(s)");
fail;
}
- if (!ty.type_contains_bound_params(ccx.tcx, typ)) {
+ if (!ty::type_contains_bound_params(ccx.tcx, typ)) {
ret typ;
}
auto f = bind substituter(ccx, supplied, _);
- ret ty.fold_ty(ccx.tcx, f, typ);
+ ret ty::fold_ty(ccx.tcx, f, typ);
}
// Returns the type parameter count and the type for the given definition.
-fn ty_param_count_and_ty_for_def(&@fn_ctxt fcx, &ast.span sp, &ast.def defn)
+fn ty_param_count_and_ty_for_def(&@fn_ctxt fcx, &ast::span sp, &ast::def defn)
-> ty_param_count_and_ty {
alt (defn) {
- case (ast.def_arg(?id)) {
+ case (ast::def_arg(?id)) {
// assert (fcx.locals.contains_key(id));
ret tup(0u, fcx.locals.get(id));
}
- case (ast.def_local(?id)) {
+ case (ast::def_local(?id)) {
auto t;
alt (fcx.locals.find(id)) {
- case (some[ty.t](?t1)) { t = t1; }
- case (none[ty.t]) { t = ty.mk_local(fcx.ccx.tcx, id); }
+ case (some[ty::t](?t1)) { t = t1; }
+ case (none[ty::t]) { t = ty::mk_local(fcx.ccx.tcx, id); }
}
ret tup(0u, t);
}
- case (ast.def_obj_field(?id)) {
+ case (ast::def_obj_field(?id)) {
// assert (fcx.locals.contains_key(id));
ret tup(0u, fcx.locals.get(id));
}
- case (ast.def_fn(?id)) {
- ret ty.lookup_item_type(fcx.ccx.sess, fcx.ccx.tcx,
+ case (ast::def_fn(?id)) {
+ ret ty::lookup_item_type(fcx.ccx.sess, fcx.ccx.tcx,
fcx.ccx.type_cache, id);
}
- case (ast.def_native_fn(?id)) {
- ret ty.lookup_item_type(fcx.ccx.sess, fcx.ccx.tcx,
+ case (ast::def_native_fn(?id)) {
+ ret ty::lookup_item_type(fcx.ccx.sess, fcx.ccx.tcx,
fcx.ccx.type_cache, id);
}
- case (ast.def_const(?id)) {
- ret ty.lookup_item_type(fcx.ccx.sess, fcx.ccx.tcx,
+ case (ast::def_const(?id)) {
+ ret ty::lookup_item_type(fcx.ccx.sess, fcx.ccx.tcx,
fcx.ccx.type_cache, id);
}
- case (ast.def_variant(_, ?vid)) {
- ret ty.lookup_item_type(fcx.ccx.sess, fcx.ccx.tcx,
+ case (ast::def_variant(_, ?vid)) {
+ ret ty::lookup_item_type(fcx.ccx.sess, fcx.ccx.tcx,
fcx.ccx.type_cache, vid);
}
- case (ast.def_binding(?id)) {
+ case (ast::def_binding(?id)) {
// assert (fcx.locals.contains_key(id));
ret tup(0u, fcx.locals.get(id));
}
- case (ast.def_obj(?id)) {
- ret ty.lookup_item_type(fcx.ccx.sess, fcx.ccx.tcx,
+ case (ast::def_obj(?id)) {
+ ret ty::lookup_item_type(fcx.ccx.sess, fcx.ccx.tcx,
fcx.ccx.type_cache, id);
}
- case (ast.def_mod(_)) {
+ case (ast::def_mod(_)) {
// Hopefully part of a path.
// TODO: return a type that's more poisonous, perhaps?
- ret tup(0u, ty.mk_nil(fcx.ccx.tcx));
+ ret tup(0u, ty::mk_nil(fcx.ccx.tcx));
}
- case (ast.def_ty(_)) {
+ case (ast::def_ty(_)) {
fcx.ccx.sess.span_err(sp, "expected value but found type");
fail;
}
// 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, uint ann_tag) -> ast.ann {
+fn instantiate_path(&@fn_ctxt fcx, &ast::path pth, &ty_param_count_and_ty tpt,
+ &span sp, uint ann_tag) -> ast::ann {
auto ty_param_count = tpt._0;
auto t = bind_params_in_type(fcx.ccx.tcx, tpt._1);
auto ty_substs_opt;
- auto ty_substs_len = Vec.len[@ast.ty](pth.node.types);
+ auto ty_substs_len = _vec::len[@ast::ty](pth.node.types);
if (ty_substs_len > 0u) {
- let vec[ty.t] ty_substs = vec();
+ let vec[ty::t] ty_substs = vec();
auto i = 0u;
while (i < ty_substs_len) {
ty_substs += vec(ast_ty_to_ty_crate(fcx.ccx, pth.node.types.(i)));
i += 1u;
}
- ty_substs_opt = some[vec[ty.t]](ty_substs);
+ ty_substs_opt = some[vec[ty::t]](ty_substs);
if (ty_param_count == 0u) {
fcx.ccx.sess.span_err(sp, "this item does not take type " +
}
} else {
// We will acquire the type parameters through unification.
- let vec[ty.t] ty_substs = vec();
+ let vec[ty::t] ty_substs = vec();
auto i = 0u;
while (i < ty_param_count) {
ty_substs += vec(next_ty_var(fcx.ccx));
i += 1u;
}
- ty_substs_opt = some[vec[ty.t]](ty_substs);
+ ty_substs_opt = some[vec[ty::t]](ty_substs);
}
- ret ast.ann_type(ann_tag, t, ty_substs_opt, none[@ts_ann]);
+ ret ast::ann_type(ann_tag, t, ty_substs_opt, none[@ts_ann]);
}
-fn ast_mode_to_mode(ast.mode mode) -> ty.mode {
+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) { ty_mode = mo_alias; }
+ case (ast::val) { ty_mode = mo_val; }
+ case (ast::alias) { ty_mode = mo_alias; }
}
ret ty_mode;
}
// 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 {
- fn ast_arg_to_arg(&ty.ctxt tcx,
+// corresponding to a definition ID:
+fn ast_ty_to_ty(&ty::ctxt tcx, &ty_getter getter, &@ast::ty ast_ty) -> ty::t {
+ fn ast_arg_to_arg(&ty::ctxt tcx,
&ty_getter getter,
- &rec(ast.mode mode, @ast.ty ty) arg)
- -> rec(ty.mode mode, ty.t ty) {
+ &rec(ast::mode mode, @ast::ty ty) arg)
+ -> rec(ty::mode mode, ty::t ty) {
auto ty_mode = ast_mode_to_mode(arg.mode);
ret rec(mode=ty_mode, ty=ast_ty_to_ty(tcx, getter, arg.ty));
}
- fn ast_mt_to_mt(&ty.ctxt tcx,
+ fn ast_mt_to_mt(&ty::ctxt tcx,
&ty_getter getter,
- &ast.mt mt) -> ty.mt {
+ &ast::mt mt) -> ty::mt {
ret rec(ty=ast_ty_to_ty(tcx, getter, mt.ty), mut=mt.mut);
}
- fn instantiate(&ty.ctxt tcx,
+ fn instantiate(&ty::ctxt tcx,
&ty_getter getter,
- &ast.def_id id,
- &vec[@ast.ty] args) -> ty.t {
+ &ast::def_id id,
+ &vec[@ast::ty] args) -> ty::t {
// TODO: maybe record cname chains so we can do
// "foo = int" like OCaml?
auto params_opt_and_ty = getter(id);
// TODO: Make sure the number of supplied bindings matches the number
// of type parameters in the typedef. Emit a friendly error otherwise.
auto bound_ty = bind_params_in_type(tcx, params_opt_and_ty._1);
- let vec[ty.t] param_bindings = vec();
- for (@ast.ty ast_ty in args) {
+ let vec[ty::t] param_bindings = vec();
+ for (@ast::ty ast_ty in args) {
param_bindings += vec(ast_ty_to_ty(tcx, getter, ast_ty));
}
- ret ty.substitute_type_params(tcx, param_bindings, bound_ty);
+ ret ty::substitute_type_params(tcx, param_bindings, bound_ty);
}
- auto mut = ast.imm;
+ auto mut = ast::imm;
auto typ;
auto cname = none[str];
alt (ast_ty.node) {
- case (ast.ty_nil) { typ = ty.mk_nil(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_box(?mt)) {
- typ = ty.mk_box(tcx, ast_mt_to_mt(tcx, getter, mt));
+ case (ast::ty_nil) { typ = ty::mk_nil(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_box(?mt)) {
+ typ = ty::mk_box(tcx, ast_mt_to_mt(tcx, getter, mt));
}
- case (ast.ty_vec(?mt)) {
- typ = ty.mk_vec(tcx, ast_mt_to_mt(tcx, getter, mt));
+ case (ast::ty_vec(?mt)) {
+ typ = ty::mk_vec(tcx, ast_mt_to_mt(tcx, getter, mt));
}
- case (ast.ty_port(?t)) {
- typ = ty.mk_port(tcx, ast_ty_to_ty(tcx, getter, t));
+ 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_chan(?t)) {
+ typ = ty::mk_chan(tcx, ast_ty_to_ty(tcx, getter, t));
}
- case (ast.ty_tup(?fields)) {
- let vec[ty.mt] flds = vec();
- for (ast.mt field in fields) {
- Vec.push[ty.mt](flds, ast_mt_to_mt(tcx, getter, field));
+ case (ast::ty_tup(?fields)) {
+ let vec[ty::mt] flds = vec();
+ for (ast::mt field in fields) {
+ _vec::push[ty::mt](flds, ast_mt_to_mt(tcx, getter, field));
}
- typ = ty.mk_tup(tcx, flds);
+ typ = ty::mk_tup(tcx, flds);
}
- case (ast.ty_rec(?fields)) {
+ case (ast::ty_rec(?fields)) {
let vec[field] flds = vec();
- for (ast.ty_field f in fields) {
+ for (ast::ty_field f in fields) {
auto tm = ast_mt_to_mt(tcx, getter, f.mt);
- Vec.push[field](flds, rec(ident=f.ident, mt=tm));
+ _vec::push[field](flds, rec(ident=f.ident, mt=tm));
}
- typ = ty.mk_rec(tcx, flds);
+ typ = ty::mk_rec(tcx, flds);
}
- case (ast.ty_fn(?proto, ?inputs, ?output)) {
+ case (ast::ty_fn(?proto, ?inputs, ?output)) {
auto f = bind ast_arg_to_arg(tcx, getter, _);
- auto i = Vec.map[ast.ty_arg, arg](f, inputs);
+ auto i = _vec::map[ast::ty_arg, arg](f, inputs);
auto out_ty = ast_ty_to_ty(tcx, getter, output);
- typ = ty.mk_fn(tcx, proto, i, out_ty);
+ typ = ty::mk_fn(tcx, proto, i, out_ty);
}
- case (ast.ty_path(?path, ?ann)) {
- alt (tcx.def_map.get(ast.ann_tag(ann))) {
- case (ast.def_ty(?id)) {
+ case (ast::ty_path(?path, ?ann)) {
+ alt (tcx.def_map.get(ast::ann_tag(ann))) {
+ case (ast::def_ty(?id)) {
typ = instantiate(tcx, getter, id, path.node.types);
}
- case (ast.def_native_ty(?id)) { typ = getter(id)._1; }
- case (ast.def_obj(?id)) {
+ case (ast::def_native_ty(?id)) { typ = getter(id)._1; }
+ case (ast::def_obj(?id)) {
typ = instantiate(tcx, getter, id, path.node.types);
}
- case (ast.def_ty_arg(?id)) { typ = ty.mk_param(tcx, id); }
+ case (ast::def_ty_arg(?id)) { typ = ty::mk_param(tcx, id); }
case (_) {
tcx.sess.span_err(ast_ty.span,
"found type name used as a variable");
cname = some(path_to_str(path));
}
- case (ast.ty_obj(?meths)) {
- let vec[ty.method] tmeths = vec();
+ case (ast::ty_obj(?meths)) {
+ let vec[ty::method] tmeths = vec();
auto f = bind ast_arg_to_arg(tcx, getter, _);
- for (ast.ty_method m in meths) {
- auto ins = Vec.map[ast.ty_arg, arg](f, m.inputs);
+ for (ast::ty_method m in meths) {
+ auto ins = _vec::map[ast::ty_arg, arg](f, m.inputs);
auto out = ast_ty_to_ty(tcx, getter, m.output);
- Vec.push[ty.method](tmeths,
+ _vec::push[ty::method](tmeths,
rec(proto=m.proto,
ident=m.ident,
inputs=ins,
output=out));
}
- typ = ty.mk_obj(tcx, ty.sort_methods(tmeths));
+ typ = ty::mk_obj(tcx, ty::sort_methods(tmeths));
}
}
alt (cname) {
case (none[str]) { /* no-op */ }
case (some[str](?cname_str)) {
- typ = ty.rename(tcx, typ, cname_str);
+ typ = ty::rename(tcx, typ, cname_str);
}
}
ret typ;
// 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 {
- ret ty.lookup_item_type(ccx.sess, ccx.tcx, ccx.type_cache, id);
+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 {
+ ret ty::lookup_item_type(ccx.sess, ccx.tcx, ccx.type_cache, id);
}
auto f = bind getter(ccx, _);
ret ast_ty_to_ty(ccx.tcx, f, ast_ty);
// AST, along with a table mapping item IDs to their types.
mod Collect {
- type ctxt = rec(session.session sess,
+ type ctxt = rec(session::session sess,
@ty_item_table id_to_ty_item,
- ty.type_cache type_cache,
- ty.ctxt tcx);
- type env = rec(@ctxt cx, ast.native_abi abi);
+ ty::type_cache type_cache,
+ ty::ctxt tcx);
+ type env = rec(@ctxt cx, ast::native_abi abi);
fn ty_of_fn_decl(&@ctxt cx,
- &fn(&@ast.ty ast_ty) -> ty.t convert,
- &fn(&ast.arg a) -> arg ty_of_arg,
- &ast.fn_decl decl,
- ast.proto proto,
- &vec[ast.ty_param] ty_params,
- &ast.def_id def_id) -> ty.ty_param_count_and_ty {
- auto input_tys = Vec.map[ast.arg,arg](ty_of_arg, decl.inputs);
+ &fn(&@ast::ty ast_ty) -> ty::t convert,
+ &fn(&ast::arg a) -> arg ty_of_arg,
+ &ast::fn_decl decl,
+ ast::proto proto,
+ &vec[ast::ty_param] ty_params,
+ &ast::def_id def_id) -> ty::ty_param_count_and_ty {
+ auto input_tys = _vec::map[ast::arg,arg](ty_of_arg, decl.inputs);
auto output_ty = convert(decl.output);
- auto t_fn = ty.mk_fn(cx.tcx, proto, input_tys, output_ty);
- auto ty_param_count = Vec.len[ast.ty_param](ty_params);
+ auto t_fn = ty::mk_fn(cx.tcx, proto, input_tys, output_ty);
+ auto ty_param_count = _vec::len[ast::ty_param](ty_params);
auto tpt = tup(ty_param_count, t_fn);
cx.type_cache.insert(def_id, tpt);
ret tpt;
}
fn ty_of_native_fn_decl(&@ctxt cx,
- &fn(&@ast.ty ast_ty) -> ty.t convert,
- &fn(&ast.arg a) -> arg ty_of_arg,
- &ast.fn_decl decl,
- ast.native_abi abi,
- &vec[ast.ty_param] ty_params,
- &ast.def_id def_id) -> ty.ty_param_count_and_ty {
- auto input_tys = Vec.map[ast.arg,arg](ty_of_arg, decl.inputs);
+ &fn(&@ast::ty ast_ty) -> ty::t convert,
+ &fn(&ast::arg a) -> arg ty_of_arg,
+ &ast::fn_decl decl,
+ ast::native_abi abi,
+ &vec[ast::ty_param] ty_params,
+ &ast::def_id def_id) -> ty::ty_param_count_and_ty{
+ auto input_tys = _vec::map[ast::arg,arg](ty_of_arg, decl.inputs);
auto output_ty = convert(decl.output);
- auto t_fn = ty.mk_native_fn(cx.tcx, abi, input_tys, output_ty);
- auto ty_param_count = Vec.len[ast.ty_param](ty_params);
+ auto t_fn = ty::mk_native_fn(cx.tcx, abi, input_tys, output_ty);
+ auto ty_param_count = _vec::len[ast::ty_param](ty_params);
auto tpt = tup(ty_param_count, t_fn);
cx.type_cache.insert(def_id, tpt);
ret tpt;
}
- fn getter(@ctxt cx, &ast.def_id id) -> ty.ty_param_count_and_ty {
+ fn getter(@ctxt cx, &ast::def_id id) -> ty::ty_param_count_and_ty {
if (id._0 != cx.sess.get_targ_crate_num()) {
// This is a type we need to load in from the crate reader.
- ret creader.get_type(cx.sess, cx.tcx, id);
+ ret creader::get_type(cx.sess, cx.tcx, id);
}
// assert (cx.id_to_ty_item.contains_key(id));
ret tpt;
}
- fn ty_of_arg(@ctxt cx, &ast.arg a) -> arg {
+ fn ty_of_arg(@ctxt cx, &ast::arg a) -> arg {
auto ty_mode = ast_mode_to_mode(a.mode);
auto f = bind getter(cx, _);
ret rec(mode=ty_mode, ty=ast_ty_to_ty(cx.tcx, f, a.ty));
}
- fn ty_of_method(@ctxt cx, &@ast.method m) -> method {
+ fn ty_of_method(@ctxt cx, &@ast::method m) -> method {
auto get = bind getter(cx, _);
auto convert = bind ast_ty_to_ty(cx.tcx, get, _);
auto f = bind ty_of_arg(cx, _);
- auto inputs = Vec.map[ast.arg,arg](f, m.node.meth.decl.inputs);
+ auto inputs = _vec::map[ast::arg,arg](f, m.node.meth.decl.inputs);
auto output = convert(m.node.meth.decl.output);
ret rec(proto=m.node.meth.proto, ident=m.node.ident,
inputs=inputs, output=output);
}
fn ty_of_obj(@ctxt cx,
- &ast.ident id,
- &ast._obj obj_info,
- &vec[ast.ty_param] ty_params) -> ty.ty_param_count_and_ty {
+ &ast::ident id,
+ &ast::_obj obj_info,
+ &vec[ast::ty_param] ty_params) -> ty::ty_param_count_and_ty {
auto f = bind ty_of_method(cx, _);
- auto methods = Vec.map[@ast.method,method](f, obj_info.methods);
+ auto methods = _vec::map[@ast::method,method](f, obj_info.methods);
- auto t_obj = ty.mk_obj(cx.tcx, ty.sort_methods(methods));
- t_obj = ty.rename(cx.tcx, t_obj, id);
- auto ty_param_count = Vec.len[ast.ty_param](ty_params);
+ auto t_obj = ty::mk_obj(cx.tcx, ty::sort_methods(methods));
+ t_obj = ty::rename(cx.tcx, t_obj, id);
+ auto ty_param_count = _vec::len[ast::ty_param](ty_params);
ret tup(ty_param_count, t_obj);
}
fn ty_of_obj_ctor(@ctxt cx,
- &ast.ident id,
- &ast._obj obj_info,
- &ast.def_id obj_ty_id,
- &vec[ast.ty_param] ty_params)
- -> ty.ty_param_count_and_ty {
+ &ast::ident id,
+ &ast::_obj obj_info,
+ &ast::def_id obj_ty_id,
+ &vec[ast::ty_param] ty_params)
+ -> ty::ty_param_count_and_ty {
auto t_obj = ty_of_obj(cx, id, obj_info, ty_params);
let vec[arg] t_inputs = vec();
- for (ast.obj_field f in obj_info.fields) {
+ for (ast::obj_field f in obj_info.fields) {
auto g = bind getter(cx, _);
auto t_field = ast_ty_to_ty(cx.tcx, g, f.ty);
- Vec.push[arg](t_inputs, rec(mode=ty.mo_alias, ty=t_field));
+ _vec::push[arg](t_inputs, rec(mode=ty::mo_alias, ty=t_field));
}
cx.type_cache.insert(obj_ty_id, t_obj);
- auto t_fn = ty.mk_fn(cx.tcx, ast.proto_fn, t_inputs, t_obj._1);
+ auto t_fn = ty::mk_fn(cx.tcx, ast::proto_fn, t_inputs, t_obj._1);
ret tup(t_obj._0, t_fn);
}
- fn ty_of_item(&@ctxt cx, &@ast.item it) -> ty.ty_param_count_and_ty {
+ 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(?ident, ?t, _, ?def_id, _)) {
+ case (ast::item_const(?ident, ?t, _, ?def_id, _)) {
auto typ = convert(t);
auto tpt = tup(0u, typ);
cx.type_cache.insert(def_id, tpt);
ret tpt;
}
- case (ast.item_fn(?ident, ?fn_info, ?tps, ?def_id, _)) {
+ case (ast::item_fn(?ident, ?fn_info, ?tps, ?def_id, _)) {
auto f = bind ty_of_arg(cx, _);
ret ty_of_fn_decl(cx, convert, f, fn_info.decl, fn_info.proto,
tps, def_id);
}
- case (ast.item_obj(?ident, ?obj_info, ?tps, ?odid, _)) {
+ case (ast::item_obj(?ident, ?obj_info, ?tps, ?odid, _)) {
auto t_ctor = ty_of_obj_ctor(cx, ident, obj_info, odid.ty,
tps);
cx.type_cache.insert(odid.ctor, t_ctor);
ret cx.type_cache.get(odid.ty);
}
- case (ast.item_ty(?ident, ?t, ?tps, ?def_id, _)) {
+ case (ast::item_ty(?ident, ?t, ?tps, ?def_id, _)) {
alt (cx.type_cache.find(def_id)) {
- case (some[ty.ty_param_count_and_ty](?tpt)) {
+ case (some[ty::ty_param_count_and_ty](?tpt)) {
ret tpt;
}
- case (none[ty.ty_param_count_and_ty]) {}
+ case (none[ty::ty_param_count_and_ty]) {}
}
// 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 = Vec.len[ast.ty_param](tps);
+ auto ty_param_count = _vec::len[ast::ty_param](tps);
auto tpt = tup(ty_param_count, typ);
cx.type_cache.insert(def_id, tpt);
ret tpt;
}
- case (ast.item_tag(_, _, ?tps, ?def_id, _)) {
+ case (ast::item_tag(_, _, ?tps, ?def_id, _)) {
// Create a new generic polytype.
- let vec[ty.t] subtys = vec();
+ let vec[ty::t] subtys = vec();
auto i = 0u;
- for (ast.ty_param tp in tps) {
- subtys += vec(ty.mk_param(cx.tcx, i));
+ for (ast::ty_param tp in tps) {
+ subtys += vec(ty::mk_param(cx.tcx, i));
i += 1u;
}
- auto t = ty.mk_tag(cx.tcx, def_id, subtys);
+ auto t = ty::mk_tag(cx.tcx, def_id, subtys);
- auto ty_param_count = Vec.len[ast.ty_param](tps);
+ auto ty_param_count = _vec::len[ast::ty_param](tps);
auto tpt = tup(ty_param_count, t);
cx.type_cache.insert(def_id, tpt);
ret tpt;
}
- case (ast.item_mod(_, _, _)) { fail; }
- case (ast.item_native_mod(_, _, _)) { fail; }
+ case (ast::item_mod(_, _, _)) { fail; }
+ case (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 {
+ 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(?ident, ?lname, ?fn_decl,
+ case (ast::native_item_fn(?ident, ?lname, ?fn_decl,
?params, ?def_id, _)) {
auto get = bind getter(cx, _);
auto convert = bind ast_ty_to_ty(cx.tcx, get, _);
ret ty_of_native_fn_decl(cx, convert, f, fn_decl, abi, params,
def_id);
}
- case (ast.native_item_ty(_, ?def_id)) {
+ case (ast::native_item_ty(_, ?def_id)) {
alt (cx.type_cache.find(def_id)) {
- case (some[ty.ty_param_count_and_ty](?tpt)) {
+ case (some[ty::ty_param_count_and_ty](?tpt)) {
ret tpt;
}
- case (none[ty.ty_param_count_and_ty]) {}
+ case (none[ty::ty_param_count_and_ty]) {}
}
- auto t = ty.mk_native(cx.tcx);
+ auto t = ty::mk_native(cx.tcx);
auto tpt = tup(0u, t);
cx.type_cache.insert(def_id, tpt);
ret tpt;
}
}
- fn get_tag_variant_types(&@ctxt cx, &ast.def_id tag_id,
- &vec[ast.variant] variants,
- &vec[ast.ty_param] ty_params)
- -> vec[ast.variant] {
- let vec[ast.variant] result = vec();
+ fn get_tag_variant_types(&@ctxt cx, &ast::def_id tag_id,
+ &vec[ast::variant] variants,
+ &vec[ast::ty_param] ty_params)
+ -> vec[ast::variant] {
+ let vec[ast::variant] result = vec();
// Create a set of parameter types shared among all the variants.
- let vec[ty.t] ty_param_tys = vec();
+ let vec[ty::t] ty_param_tys = vec();
auto i = 0u;
- for (ast.ty_param tp in ty_params) {
- ty_param_tys += vec(ty.mk_param(cx.tcx, i));
+ for (ast::ty_param tp in ty_params) {
+ ty_param_tys += vec(ty::mk_param(cx.tcx, i));
i += 1u;
}
- auto ty_param_count = Vec.len[ast.ty_param](ty_params);
+ auto ty_param_count = _vec::len[ast::ty_param](ty_params);
- for (ast.variant variant in variants) {
+ for (ast::variant variant in variants) {
// Nullary tag constructors get turned into constants; n-ary tag
// constructors get turned into functions.
auto result_ty;
- if (Vec.len[ast.variant_arg](variant.node.args) == 0u) {
- result_ty = ty.mk_tag(cx.tcx, tag_id, ty_param_tys);
+ if (_vec::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 vec[arg] args = vec();
- for (ast.variant_arg va in variant.node.args) {
+ for (ast::variant_arg va in variant.node.args) {
auto arg_ty = ast_ty_to_ty(cx.tcx, f, va.ty);
- args += vec(rec(mode=ty.mo_alias, ty=arg_ty));
+ args += vec(rec(mode=ty::mo_alias, ty=arg_ty));
}
- auto tag_t = ty.mk_tag(cx.tcx, tag_id, ty_param_tys);
- result_ty = ty.mk_fn(cx.tcx, ast.proto_fn, args, tag_t);
+ auto tag_t = ty::mk_tag(cx.tcx, tag_id, ty_param_tys);
+ result_ty = ty::mk_fn(cx.tcx, ast::proto_fn, args, tag_t);
}
auto tpt = tup(ty_param_count, result_ty);
auto variant_t = rec(ann=triv_ann(variant.node.ann, result_ty)
with variant.node
);
- result += vec(fold.respan[ast.variant_](variant.span, variant_t));
+ result += vec(fold::respan(variant.span, variant_t));
}
ret result;
}
- fn collect(&@ty_item_table id_to_ty_item, &@ast.item i)
+ fn collect(&@ty_item_table id_to_ty_item, &@ast::item i)
-> @ty_item_table {
alt (i.node) {
- case (ast.item_ty(_, _, _, ?def_id, _)) {
+ case (ast::item_ty(_, _, _, ?def_id, _)) {
id_to_ty_item.insert(def_id, any_item_rust(i));
}
- case (ast.item_tag(_, _, _, ?def_id, _)) {
+ case (ast::item_tag(_, _, _, ?def_id, _)) {
id_to_ty_item.insert(def_id, any_item_rust(i));
}
- case (ast.item_obj(_, _, _, ?odid, _)) {
+ case (ast::item_obj(_, _, _, ?odid, _)) {
id_to_ty_item.insert(odid.ty, any_item_rust(i));
}
case (_) { /* empty */ }
ret id_to_ty_item;
}
- fn collect_native(&@ty_item_table id_to_ty_item, &@ast.native_item i)
+ fn collect_native(&@ty_item_table id_to_ty_item, &@ast::native_item i)
-> @ty_item_table {
alt (i.node) {
- case (ast.native_item_ty(_, ?def_id)) {
+ case (ast::native_item_ty(_, ?def_id)) {
// The abi of types is not used.
id_to_ty_item.insert(def_id,
any_item_native(i,
- ast.native_abi_cdecl));
+ ast::native_abi_cdecl));
}
case (_) {
}
ret id_to_ty_item;
}
- fn convert(&@env e, &@ast.item i) -> @env {
+ fn convert(&@env e, &@ast::item i) -> @env {
auto abi = e.abi;
alt (i.node) {
- case (ast.item_mod(_, _, _)) {
+ case (ast::item_mod(_, _, _)) {
// ignore item_mod, it has no type.
}
- case (ast.item_native_mod(_, ?native_mod, _)) {
+ case (ast::item_native_mod(_, ?native_mod, _)) {
// ignore item_native_mod, it has no type.
abi = native_mod.abi;
}
ret @rec(abi=abi with *e);
}
- fn convert_native(&@env e, &@ast.native_item i) -> @env {
+ fn convert_native(&@env e, &@ast::native_item i) -> @env {
ty_of_native_item(e.cx, i, e.abi);
ret e;
}
- fn fold_item_const(&@env e, &span sp, &ast.ident i,
- &@ast.ty t, &@ast.expr ex,
- &ast.def_id id, &ast.ann a) -> @ast.item {
+ fn fold_item_const(&@env e, &span sp, &ast::ident i,
+ &@ast::ty t, &@ast::expr ex,
+ &ast::def_id id, &ast::ann a) -> @ast::item {
// assert (e.cx.type_cache.contains_key(id));
auto typ = e.cx.type_cache.get(id)._1;
- auto item = ast.item_const(i, t, ex, id, triv_ann(a, typ));
- ret @fold.respan[ast.item_](sp, item);
+ auto item = ast::item_const(i, t, ex, id, triv_ann(a, typ));
+ ret @fold::respan[ast::item_](sp, item);
}
- fn fold_item_fn(&@env e, &span sp, &ast.ident i,
- &ast._fn f, &vec[ast.ty_param] ty_params,
- &ast.def_id id, &ast.ann a) -> @ast.item {
+ fn fold_item_fn(&@env e, &span sp, &ast::ident i,
+ &ast::_fn f, &vec[ast::ty_param] ty_params,
+ &ast::def_id id, &ast::ann a) -> @ast::item {
// assert (e.cx.type_cache.contains_key(id));
auto typ = e.cx.type_cache.get(id)._1;
- auto item = ast.item_fn(i, f, ty_params, id, triv_ann(a, typ));
- ret @fold.respan[ast.item_](sp, item);
+ auto item = ast::item_fn(i, f, ty_params, id, triv_ann(a, typ));
+ ret @fold::respan[ast::item_](sp, item);
}
- fn fold_native_item_fn(&@env e, &span sp, &ast.ident i, &Option.t[str] ln,
- &ast.fn_decl d, &vec[ast.ty_param] ty_params,
- &ast.def_id id, &ast.ann a) -> @ast.native_item {
+ fn fold_native_item_fn(&@env e, &span sp, &ast::ident i,
+ &option::t[str] ln,
+ &ast::fn_decl d, &vec[ast::ty_param] ty_params,
+ &ast::def_id id, &ast::ann a) -> @ast::native_item{
// assert (e.cx.type_cache.contains_key(id));
auto typ = e.cx.type_cache.get(id)._1;
- auto item = ast.native_item_fn(i, ln, d, ty_params, id,
+ auto item = ast::native_item_fn(i, ln, d, ty_params, id,
triv_ann(a, typ));
- ret @fold.respan[ast.native_item_](sp, item);
+ ret @fold::respan[ast::native_item_](sp, item);
}
- fn get_ctor_obj_methods(&@env e, &ty.t t) -> vec[method] {
+ fn get_ctor_obj_methods(&@env e, &ty::t t) -> vec[method] {
alt (struct(e.cx.tcx, t)) {
- case (ty.ty_fn(_,_,?tobj)) {
+ case (ty::ty_fn(_,_,?tobj)) {
alt (struct(e.cx.tcx, tobj)) {
- case (ty.ty_obj(?tm)) {
+ case (ty::ty_obj(?tm)) {
ret tm;
}
case (_) {
}
- fn fold_item_obj(&@env e, &span sp, &ast.ident i,
- &ast._obj ob, &vec[ast.ty_param] ty_params,
- &ast.obj_def_ids odid, &ast.ann a) -> @ast.item {
+ fn fold_item_obj(&@env e, &span sp, &ast::ident i,
+ &ast::_obj ob, &vec[ast::ty_param] ty_params,
+ &ast::obj_def_ids odid, &ast::ann a) -> @ast::item {
// assert (e.cx.type_cache.contains_key(odid.ctor));
auto t = e.cx.type_cache.get(odid.ctor)._1;
let vec[method] meth_tys = get_ctor_obj_methods(e, t);
- let vec[@ast.method] methods = vec();
- let vec[ast.obj_field] fields = vec();
+ let vec[@ast::method] methods = vec();
+ let vec[ast::obj_field] fields = vec();
- for (@ast.method meth in ob.methods) {
- let uint ix = ty.method_idx(e.cx.sess,
+ for (@ast::method meth in ob.methods) {
+ let uint ix = ty::method_idx(e.cx.sess,
sp, meth.node.ident,
meth_tys);
let method meth_ty = meth_tys.(ix);
- let ast.method_ m_;
- let @ast.method m;
- auto meth_tfn = ty.mk_fn(e.cx.tcx,
+ let ast::method_ m_;
+ let @ast::method m;
+ auto meth_tfn = ty::mk_fn(e.cx.tcx,
meth_ty.proto,
meth_ty.inputs,
meth_ty.output);
with meth.node
);
m = @rec(node=m_ with *meth);
- Vec.push[@ast.method](methods, m);
+ _vec::push[@ast::method](methods, m);
}
auto g = bind getter(e.cx, _);
- for (ast.obj_field fld in ob.fields) {
- let ty.t fty = ast_ty_to_ty(e.cx.tcx, g, fld.ty);
- let ast.obj_field f = rec(ann=triv_ann(fld.ann, fty)
+ for (ast::obj_field fld in ob.fields) {
+ let ty::t fty = ast_ty_to_ty(e.cx.tcx, g, fld.ty);
+ let ast::obj_field f = rec(ann=triv_ann(fld.ann, fty)
with fld
);
- Vec.push[ast.obj_field](fields, f);
+ _vec::push[ast::obj_field](fields, f);
}
- auto dtor = none[@ast.method];
+ auto dtor = none[@ast::method];
alt (ob.dtor) {
- case (some[@ast.method](?d)) {
+ case (some[@ast::method](?d)) {
let vec[arg] inputs = vec();
- let ty.t output = ty.mk_nil(e.cx.tcx);
- auto dtor_tfn = ty.mk_fn(e.cx.tcx, ast.proto_fn, inputs,
+ let ty::t output = ty::mk_nil(e.cx.tcx);
+ auto dtor_tfn = ty::mk_fn(e.cx.tcx, ast::proto_fn, inputs,
output);
auto d_ = rec(ann=triv_ann(d.node.ann, dtor_tfn) with d.node);
- dtor = some[@ast.method](@rec(node=d_ with *d));
+ dtor = some[@ast::method](@rec(node=d_ with *d));
}
- case (none[@ast.method]) { }
+ case (none[@ast::method]) { }
}
auto ob_ = rec(methods = methods,
fields = fields,
dtor = dtor
with ob);
- auto item = ast.item_obj(i, ob_, ty_params, odid, triv_ann(a, t));
- ret @fold.respan[ast.item_](sp, item);
+ auto item = ast::item_obj(i, ob_, ty_params, odid, triv_ann(a, t));
+ ret @fold::respan[ast::item_](sp, item);
}
- fn fold_item_ty(&@env e, &span sp, &ast.ident i,
- &@ast.ty t, &vec[ast.ty_param] ty_params,
- &ast.def_id id, &ast.ann a) -> @ast.item {
+ fn fold_item_ty(&@env e, &span sp, &ast::ident i,
+ &@ast::ty t, &vec[ast::ty_param] ty_params,
+ &ast::def_id id, &ast::ann a) -> @ast::item {
// assert (e.cx.type_cache.contains_key(id));
auto typ = e.cx.type_cache.get(id)._1;
- auto item = ast.item_ty(i, t, ty_params, id, triv_ann(a, typ));
- ret @fold.respan[ast.item_](sp, item);
+ auto item = ast::item_ty(i, t, ty_params, id, triv_ann(a, typ));
+ ret @fold::respan[ast::item_](sp, item);
}
- fn fold_item_tag(&@env e, &span sp, &ast.ident i,
- &vec[ast.variant] variants,
- &vec[ast.ty_param] ty_params,
- &ast.def_id id, &ast.ann a) -> @ast.item {
+ fn fold_item_tag(&@env e, &span sp, &ast::ident i,
+ &vec[ast::variant] variants,
+ &vec[ast::ty_param] ty_params,
+ &ast::def_id id, &ast::ann a) -> @ast::item {
auto variants_t = get_tag_variant_types(e.cx, id, variants,
ty_params);
auto typ = e.cx.type_cache.get(id)._1;
- auto item = ast.item_tag(i, variants_t, ty_params, id,
- ast.ann_type(ast.ann_tag(a), typ,
- none[vec[ty.t]],
+ auto item = ast::item_tag(i, variants_t, ty_params, id,
+ ast::ann_type(ast::ann_tag(a), typ,
+ none[vec[ty::t]],
none[@ts_ann]));
- ret @fold.respan[ast.item_](sp, item);
+ ret @fold::respan[ast::item_](sp, item);
}
- fn collect_item_types(&session.session sess, &ty.ctxt tcx,
- &@ast.crate crate)
- -> tup(@ast.crate, ty.type_cache, @ty_item_table) {
- // First pass: collect all type item IDs.
+ fn collect_item_types(&session::session sess, &ty::ctxt tcx,
+ &@ast::crate crate)
+ -> tup(@ast::crate, ty::type_cache, @ty_item_table) {
+ // First pass: collect all type item IDs:
auto module = crate.node.module;
- auto id_to_ty_item = @common.new_def_hash[any_item]();
+ auto id_to_ty_item = @common::new_def_hash[any_item]();
- auto fld_1 = fold.new_identity_fold[@ty_item_table]();
+ auto fld_1 = fold::new_identity_fold[@ty_item_table]();
fld_1 = @rec(update_env_for_item = bind collect(_, _),
update_env_for_native_item = bind collect_native(_, _)
with *fld_1);
- fold.fold_crate[@ty_item_table](id_to_ty_item, fld_1, crate);
+ fold::fold_crate[@ty_item_table](id_to_ty_item, fld_1, crate);
// Second pass: translate the types of all items.
- auto type_cache = common.new_def_hash[ty.ty_param_count_and_ty]();
+ auto type_cache = common::new_def_hash[ty::ty_param_count_and_ty]();
auto cx = @rec(sess=sess,
id_to_ty_item=id_to_ty_item,
type_cache=type_cache,
tcx=tcx);
- let @env e = @rec(cx=cx, abi=ast.native_abi_cdecl);
+ let @env e = @rec(cx=cx, abi=ast::native_abi_cdecl);
- auto fld_2 = fold.new_identity_fold[@env]();
+ auto fld_2 = fold::new_identity_fold[@env]();
fld_2 =
@rec(update_env_for_item = bind convert(_,_),
update_env_for_native_item = bind convert_native(_,_),
fold_item_ty = bind fold_item_ty(_,_,_,_,_,_,_),
fold_item_tag = bind fold_item_tag(_,_,_,_,_,_,_)
with *fld_2);
- auto crate_ = fold.fold_crate[@env](e, fld_2, crate);
+ auto crate_ = fold::fold_crate[@env](e, fld_2, crate);
ret tup(crate_, type_cache, id_to_ty_item);
}
}
// Type unification
mod Unify {
- fn simple(&@fn_ctxt fcx, &ty.t expected,
- &ty.t actual) -> ty.Unify.result {
+ fn simple(&@fn_ctxt fcx, &ty::t expected,
+ &ty::t actual) -> ty::Unify::result {
// FIXME: horrid botch
- let vec[mutable ty.t] param_substs =
- vec(mutable ty.mk_nil(fcx.ccx.tcx));
- Vec.pop(param_substs);
+ let vec[mutable ty::t] param_substs =
+ vec(mutable ty::mk_nil(fcx.ccx.tcx));
+ _vec::pop(param_substs);
ret with_params(fcx, expected, actual, param_substs);
}
- fn with_params(&@fn_ctxt fcx, &ty.t expected, &ty.t actual,
- &vec[mutable ty.t] param_substs) -> ty.Unify.result {
+ fn with_params(&@fn_ctxt fcx, &ty::t expected, &ty::t actual,
+ &vec[mutable ty::t] param_substs) -> ty::Unify::result {
auto cache_key = tup(expected, actual, param_substs);
alt (fcx.ccx.unify_cache.find(cache_key)) {
- case (some[ty.Unify.result](?r)) {
+ case (some[ty::Unify::result](?r)) {
fcx.ccx.cache_hits += 1u;
ret r;
}
- case (none[ty.Unify.result]) {
+ case (none[ty::Unify::result]) {
fcx.ccx.cache_misses += 1u;
}
}
- obj unify_handler(@fn_ctxt fcx, vec[mutable ty.t] param_substs) {
- fn resolve_local(ast.def_id id) -> Option.t[ty.t] {
+ obj unify_handler(@fn_ctxt fcx, vec[mutable ty::t] param_substs) {
+ fn resolve_local(ast::def_id id) -> option::t[ty::t] {
alt (fcx.locals.find(id)) {
- case (none[ty.t]) { ret none[ty.t]; }
- case (some[ty.t](?existing_type)) {
- if (ty.type_contains_vars(fcx.ccx.tcx,
+ case (none[ty::t]) { ret none[ty::t]; }
+ case (some[ty::t](?existing_type)) {
+ if (ty::type_contains_vars(fcx.ccx.tcx,
existing_type)) {
// Not fully resolved yet. The writeback phase
// will mop up.
- ret none[ty.t];
+ ret none[ty::t];
}
- ret some[ty.t](existing_type);
+ ret some[ty::t](existing_type);
}
}
}
- fn record_local(ast.def_id id, ty.t new_type) {
+ fn record_local(ast::def_id id, ty::t new_type) {
auto unified_type;
alt (fcx.locals.find(id)) {
- case (none[ty.t]) { unified_type = new_type; }
- case (some[ty.t](?old_type)) {
+ case (none[ty::t]) { unified_type = new_type; }
+ case (some[ty::t](?old_type)) {
alt (with_params(fcx, old_type, new_type,
param_substs)) {
case (ures_ok(?ut)) { unified_type = ut; }
}
// TODO: "freeze"
- let vec[ty.t] param_substs_1 = vec();
- for (ty.t subst in param_substs) {
+ let vec[ty::t] param_substs_1 = vec();
+ for (ty::t subst in param_substs) {
param_substs_1 += vec(subst);
}
unified_type =
- ty.substitute_type_params(fcx.ccx.tcx, param_substs_1,
+ ty::substitute_type_params(fcx.ccx.tcx, param_substs_1,
unified_type);
fcx.locals.insert(id, unified_type);
}
- fn record_param(uint index, ty.t binding) -> ty.Unify.result {
+ fn record_param(uint index, ty::t binding) -> ty::Unify::result {
// Unify with the appropriate type in the parameter
- // substitution List.
+ // substitution list:
auto old_subst = param_substs.(index);
auto result = with_params(fcx, old_subst, binding,
alt (result) {
case (ures_ok(?new_subst)) {
param_substs.(index) = new_subst;
- ret ures_ok(ty.mk_bound_param(fcx.ccx.tcx, index));
+ ret ures_ok(ty::mk_bound_param(fcx.ccx.tcx, index));
}
case (_) { ret result; }
}
auto handler = unify_handler(fcx, param_substs);
- auto result = ty.Unify.unify(expected, actual, handler, fcx.ccx.tcx);
+ auto result = ty::Unify::unify(expected, actual, handler,
+ fcx.ccx.tcx);
fcx.ccx.unify_cache.insert(cache_key, result);
ret result;
}
NO_AUTODEREF;
}
-fn strip_boxes(&ty.ctxt tcx, &ty.t t) -> ty.t {
+fn strip_boxes(&ty::ctxt tcx, &ty::t t) -> ty::t {
auto t1 = t;
while (true) {
alt (struct(tcx, t1)) {
- case (ty.ty_box(?inner)) { t1 = inner.ty; }
+ case (ty::ty_box(?inner)) { t1 = inner.ty; }
case (_) { ret t1; }
}
}
fail;
}
-fn add_boxes(&@crate_ctxt ccx, uint n, &ty.t t) -> ty.t {
+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);
+ t1 = ty::mk_imm_box(ccx.tcx, t1);
n -= 1u;
}
ret t1;
}
-fn count_boxes(&ty.ctxt tcx, &ty.t t) -> uint {
+fn count_boxes(&ty::ctxt tcx, &ty::t t) -> uint {
auto n = 0u;
auto t1 = t;
while (true) {
alt (struct(tcx, t1)) {
- case (ty.ty_box(?inner)) { n += 1u; t1 = inner.ty; }
+ case (ty::ty_box(?inner)) { n += 1u; t1 = inner.ty; }
case (_) { ret n; }
}
}
// Demands - procedures that require that two types unify and emit an error
// message if they don't.
-type ty_param_substs_and_ty = tup(vec[ty.t], ty.t);
+type ty_param_substs_and_ty = tup(vec[ty::t], ty::t);
mod Demand {
- fn simple(&@fn_ctxt fcx, &span sp, &ty.t expected, &ty.t actual) -> ty.t {
- let vec[ty.t] tps = vec();
+ fn simple(&@fn_ctxt fcx, &span sp, &ty::t expected, &ty::t actual)
+ -> ty::t {
+ let vec[ty::t] tps = vec();
ret full(fcx, sp, expected, actual, tps, NO_AUTODEREF)._1;
}
- fn autoderef(&@fn_ctxt fcx, &span sp, &ty.t expected, &ty.t actual,
- autoderef_kind adk) -> ty.t {
- let vec[ty.t] tps = vec();
+ fn autoderef(&@fn_ctxt fcx, &span sp, &ty::t expected, &ty::t actual,
+ autoderef_kind adk) -> ty::t {
+ let vec[ty::t] tps = vec();
ret full(fcx, sp, expected, actual, tps, adk)._1;
}
// 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,
- &vec[ty.t] ty_param_substs_0, autoderef_kind adk)
+ fn full(&@fn_ctxt fcx, &span sp, &ty::t expected, &ty::t actual,
+ &vec[ty::t] ty_param_substs_0, autoderef_kind adk)
-> ty_param_substs_and_ty {
auto expected_1 = expected;
implicit_boxes = count_boxes(fcx.ccx.tcx, actual);
}
- let vec[mutable ty.t] ty_param_substs =
- vec(mutable ty.mk_nil(fcx.ccx.tcx));
- Vec.pop(ty_param_substs); // FIXME: horrid botch
- for (ty.t ty_param_subst in ty_param_substs_0) {
+ let vec[mutable ty::t] ty_param_substs =
+ vec(mutable ty::mk_nil(fcx.ccx.tcx));
+ _vec::pop(ty_param_substs); // FIXME: horrid botch
+ for (ty::t ty_param_subst in ty_param_substs_0) {
ty_param_substs += vec(mutable ty_param_subst);
}
- alt (Unify.with_params(fcx, expected_1, actual_1, ty_param_substs)) {
+ alt (Unify::with_params(fcx, expected_1, actual_1, ty_param_substs)) {
case (ures_ok(?t)) {
// TODO: Use "freeze", when we have it.
- let vec[ty.t] result_ty_param_substs = vec();
- for (ty.t ty_param_subst in ty_param_substs) {
+ let vec[ty::t] result_ty_param_substs = vec();
+ for (ty::t ty_param_subst in ty_param_substs) {
result_ty_param_substs += vec(ty_param_subst);
}
fcx.ccx.sess.span_err(sp, "mismatched types: expected "
+ ty_to_str(fcx.ccx.tcx, expected) + " but found "
+ ty_to_str(fcx.ccx.tcx, actual) + " ("
- + ty.type_err_to_str(err) + ")");
+ + ty::type_err_to_str(err) + ")");
// TODO: In the future, try returning "expected", reporting
// the error, and continue.
// 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)) {
+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; }
}
}
// Returns the types of the arguments to a tag variant.
-fn variant_arg_types(&@crate_ctxt ccx, &span sp, &ast.def_id vid,
- &vec[ty.t] tag_ty_params) -> vec[ty.t] {
- auto ty_param_count = Vec.len[ty.t](tag_ty_params);
+fn variant_arg_types(&@crate_ctxt ccx, &span sp, &ast::def_id vid,
+ &vec[ty::t] tag_ty_params) -> vec[ty::t] {
+ auto ty_param_count = _vec::len[ty::t](tag_ty_params);
- let vec[ty.t] result = vec();
+ let vec[ty::t] result = vec();
- auto tpt = ty.lookup_item_type(ccx.sess, ccx.tcx, ccx.type_cache, vid);
+ auto tpt = ty::lookup_item_type(ccx.sess, ccx.tcx, ccx.type_cache, vid);
alt (struct(ccx.tcx, tpt._1)) {
- case (ty.ty_fn(_, ?ins, _)) {
+ case (ty::ty_fn(_, ?ins, _)) {
// N-ary variant.
- for (ty.arg arg in ins) {
+ for (ty::arg arg in ins) {
auto arg_ty = bind_params_in_type(ccx.tcx, arg.ty);
arg_ty = substitute_ty_params(ccx, arg_ty, ty_param_count,
tag_ty_params, sp);
//
// TODO: enforce this via a predicate.
- fn pushdown_pat(&@fn_ctxt fcx, &ty.t expected,
- &@ast.pat pat) -> @ast.pat {
+ fn pushdown_pat(&@fn_ctxt fcx, &ty::t expected,
+ &@ast::pat pat) -> @ast::pat {
auto p_1;
alt (pat.node) {
- case (ast.pat_wild(?ann)) {
- auto t = Demand.simple(fcx, pat.span, expected,
+ case (ast::pat_wild(?ann)) {
+ auto t = Demand::simple(fcx, pat.span, expected,
ann_to_type(ann));
- p_1 = ast.pat_wild(ast.ann_type(ast.ann_tag(ann), t,
- none[vec[ty.t]],
+ p_1 = ast::pat_wild(ast::ann_type(ast::ann_tag(ann), t,
+ none[vec[ty::t]],
none[@ts_ann]));
}
- case (ast.pat_lit(?lit, ?ann)) {
- auto t = Demand.simple(fcx, pat.span, expected,
+ case (ast::pat_lit(?lit, ?ann)) {
+ auto t = Demand::simple(fcx, pat.span, expected,
ann_to_type(ann));
- p_1 = ast.pat_lit(lit, ast.ann_type(ast.ann_tag(ann), t,
- none[vec[ty.t]],
+ p_1 = ast::pat_lit(lit, ast::ann_type(ast::ann_tag(ann), t,
+ none[vec[ty::t]],
none[@ts_ann]));
}
- case (ast.pat_bind(?id, ?did, ?ann)) {
- auto t = Demand.simple(fcx, pat.span, expected,
+ case (ast::pat_bind(?id, ?did, ?ann)) {
+ auto t = Demand::simple(fcx, pat.span, expected,
ann_to_type(ann));
fcx.locals.insert(did, t);
- p_1 = ast.pat_bind(id, did, ast.ann_type(ast.ann_tag(ann), t,
- none[vec[ty.t]],
- none[@ts_ann]));
+ p_1 = ast::pat_bind(id, did, ast::ann_type(ast::ann_tag(ann),
+ t,
+ none[vec[ty::t]],
+ none[@ts_ann]));
}
- case (ast.pat_tag(?id, ?subpats, ?ann)) {
+ case (ast::pat_tag(?id, ?subpats, ?ann)) {
// Take the variant's type parameters out of the expected
// type.
auto tag_tps;
alt (struct(fcx.ccx.tcx, expected)) {
- case (ty.ty_tag(_, ?tps)) { tag_tps = tps; }
+ case (ty::ty_tag(_, ?tps)) { tag_tps = tps; }
case (_) {
log_err "tag pattern type not actually a tag?!";
fail;
// Get the types of the arguments of the variant.
auto arg_tys;
- alt (fcx.ccx.tcx.def_map.get(ast.ann_tag(ann))) {
- case (ast.def_variant(_, ?vdefid)) {
+ alt (fcx.ccx.tcx.def_map.get(ast::ann_tag(ann))) {
+ case (ast::def_variant(_, ?vdefid)) {
arg_tys = variant_arg_types(fcx.ccx, pat.span, vdefid,
tag_tps);
}
}
- let vec[@ast.pat] subpats_1 = vec();
+ let vec[@ast::pat] subpats_1 = vec();
auto i = 0u;
- for (@ast.pat subpat in subpats) {
+ for (@ast::pat subpat in subpats) {
subpats_1 += vec(pushdown_pat(fcx, arg_tys.(i), subpat));
i += 1u;
}
// TODO: push down type from "expected".
- p_1 = ast.pat_tag(id, subpats_1, ann);
+ p_1 = ast::pat_tag(id, subpats_1, ann);
}
}
- ret @fold.respan[ast.pat_](pat.span, p_1);
+ ret @fold::respan[ast::pat_](pat.span, p_1);
}
// Push-down over typed expressions. Note that the expression that you
// TODO: enforce this via a predicate.
// TODO: This function is incomplete.
- fn pushdown_expr(&@fn_ctxt fcx, &ty.t expected, &@ast.expr e)
- -> @ast.expr {
+ fn pushdown_expr(&@fn_ctxt fcx, &ty::t expected, &@ast::expr e)
+ -> @ast::expr {
be pushdown_expr_full(fcx, expected, e, NO_AUTODEREF);
}
- fn pushdown_expr_full(&@fn_ctxt fcx, &ty.t expected, &@ast.expr e,
- autoderef_kind adk) -> @ast.expr {
+ fn pushdown_expr_full(&@fn_ctxt fcx, &ty::t expected, &@ast::expr e,
+ autoderef_kind adk) -> @ast::expr {
auto e_1;
alt (e.node) {
- case (ast.expr_vec(?es_0, ?mut, ?ann)) {
+ case (ast::expr_vec(?es_0, ?mut, ?ann)) {
// TODO: enforce mutability
- auto t = Demand.simple(fcx, e.span, expected,
+ auto t = Demand::simple(fcx, e.span, expected,
ann_to_type(ann));
- let vec[@ast.expr] es_1 = vec();
+ let vec[@ast::expr] es_1 = vec();
alt (struct(fcx.ccx.tcx, t)) {
- case (ty.ty_vec(?mt)) {
- for (@ast.expr e_0 in es_0) {
+ case (ty::ty_vec(?mt)) {
+ for (@ast::expr e_0 in es_0) {
es_1 += vec(pushdown_expr(fcx, mt.ty, e_0));
}
}
fail;
}
}
- e_1 = ast.expr_vec(es_1, mut, triv_ann(ann, t));
+ e_1 = ast::expr_vec(es_1, mut, triv_ann(ann, t));
}
- case (ast.expr_tup(?es_0, ?ann)) {
- auto t = Demand.simple(fcx, e.span, expected,
+ case (ast::expr_tup(?es_0, ?ann)) {
+ auto t = Demand::simple(fcx, e.span, expected,
ann_to_type(ann));
- let vec[ast.elt] elts_1 = vec();
+ let vec[ast::elt] elts_1 = vec();
alt (struct(fcx.ccx.tcx, t)) {
- case (ty.ty_tup(?mts)) {
+ case (ty::ty_tup(?mts)) {
auto i = 0u;
- for (ast.elt elt_0 in es_0) {
+ for (ast::elt elt_0 in es_0) {
auto e_1 = pushdown_expr(fcx, mts.(i).ty,
elt_0.expr);
elts_1 += vec(rec(mut=elt_0.mut, expr=e_1));
fail;
}
}
- e_1 = ast.expr_tup(elts_1, triv_ann(ann, t));
+ e_1 = ast::expr_tup(elts_1, triv_ann(ann, t));
}
- case (ast.expr_rec(?fields_0, ?base_0, ?ann)) {
+ case (ast::expr_rec(?fields_0, ?base_0, ?ann)) {
auto base_1 = base_0;
- auto t = Demand.simple(fcx, e.span, expected,
+ auto t = Demand::simple(fcx, e.span, expected,
ann_to_type(ann));
- let vec[ast.field] fields_1 = vec();
+ let vec[ast::field] fields_1 = vec();
alt (struct(fcx.ccx.tcx, t)) {
- case (ty.ty_rec(?field_mts)) {
+ case (ty::ty_rec(?field_mts)) {
alt (base_0) {
- case (none[@ast.expr]) {
+ case (none[@ast::expr]) {
auto i = 0u;
- for (ast.field field_0 in fields_0) {
- assert (Str.eq(field_0.ident,
+ for (ast::field field_0 in fields_0) {
+ assert (_str::eq(field_0.ident,
field_mts.(i).ident));
auto e_1 =
pushdown_expr(fcx,
i += 1u;
}
}
- case (some[@ast.expr](?bx)) {
+ case (some[@ast::expr](?bx)) {
- base_1 = some[@ast.expr](pushdown_expr(fcx, t,
- bx));
+ base_1 = some[@ast::expr]
+ (pushdown_expr(fcx, t, bx));
let vec[field] base_fields = vec();
- for (ast.field field_0 in fields_0) {
+ for (ast::field field_0 in fields_0) {
- for (ty.field ft in field_mts) {
- if (Str.eq(field_0.ident,
+ for (ty::field ft in field_mts) {
+ if (_str::eq(field_0.ident,
ft.ident)) {
auto e_1 =
pushdown_expr(fcx, ft.mt.ty,
fail;
}
}
- e_1 = ast.expr_rec(fields_1, base_1, triv_ann(ann, t));
+ e_1 = ast::expr_rec(fields_1, base_1, triv_ann(ann, t));
}
- case (ast.expr_bind(?sube, ?es, ?ann)) {
- auto t = Demand.simple(fcx, e.span, expected,
+ case (ast::expr_bind(?sube, ?es, ?ann)) {
+ auto t = Demand::simple(fcx, e.span, expected,
ann_to_type(ann));
- e_1 = ast.expr_bind(sube, es, triv_ann(ann, t));
+ e_1 = ast::expr_bind(sube, es, triv_ann(ann, t));
}
- case (ast.expr_call(?sube, ?es, ?ann)) {
- // NB: we call 'Demand.autoderef' and pass in adk only in
+ case (ast::expr_call(?sube, ?es, ?ann)) {
+ // NB: we call 'Demand::autoderef' and pass in adk only in
// cases where e is an expression that could *possibly*
// produce a box; things like expr_binary or expr_bind can't,
// so there's no need.
- auto t = Demand.autoderef(fcx, e.span, expected,
+ auto t = Demand::autoderef(fcx, e.span, expected,
ann_to_type(ann), adk);
- e_1 = ast.expr_call(sube, es, triv_ann(ann, t));
+ e_1 = ast::expr_call(sube, es, triv_ann(ann, t));
}
- case (ast.expr_self_method(?id, ?ann)) {
- auto t = Demand.simple(fcx, e.span, expected,
+ case (ast::expr_self_method(?id, ?ann)) {
+ auto t = Demand::simple(fcx, e.span, expected,
ann_to_type(ann));
- e_1 = ast.expr_self_method(id, triv_ann(ann, t));
+ e_1 = ast::expr_self_method(id, triv_ann(ann, t));
}
- case (ast.expr_binary(?bop, ?lhs, ?rhs, ?ann)) {
- auto t = Demand.simple(fcx, e.span, expected,
+ case (ast::expr_binary(?bop, ?lhs, ?rhs, ?ann)) {
+ auto t = Demand::simple(fcx, e.span, expected,
ann_to_type(ann));
- e_1 = ast.expr_binary(bop, lhs, rhs, triv_ann(ann, t));
+ e_1 = ast::expr_binary(bop, lhs, rhs, triv_ann(ann, t));
}
- case (ast.expr_unary(?uop, ?sube, ?ann)) {
+ case (ast::expr_unary(?uop, ?sube, ?ann)) {
// See note in expr_unary for why we're calling
- // Demand.autoderef.
- auto t = Demand.autoderef(fcx, e.span, expected,
+ // Demand::autoderef.
+ auto t = Demand::autoderef(fcx, e.span, expected,
ann_to_type(ann), adk);
- e_1 = ast.expr_unary(uop, sube, triv_ann(ann, t));
+ e_1 = ast::expr_unary(uop, sube, triv_ann(ann, t));
}
- case (ast.expr_lit(?lit, ?ann)) {
- auto t = Demand.simple(fcx, e.span, expected,
+ case (ast::expr_lit(?lit, ?ann)) {
+ auto t = Demand::simple(fcx, e.span, expected,
ann_to_type(ann));
- e_1 = ast.expr_lit(lit, triv_ann(ann, t));
+ e_1 = ast::expr_lit(lit, triv_ann(ann, t));
}
- case (ast.expr_cast(?sube, ?ast_ty, ?ann)) {
- auto t = Demand.simple(fcx, e.span, expected,
+ case (ast::expr_cast(?sube, ?ast_ty, ?ann)) {
+ auto t = Demand::simple(fcx, e.span, expected,
ann_to_type(ann));
- e_1 = ast.expr_cast(sube, ast_ty, triv_ann(ann, t));
+ e_1 = ast::expr_cast(sube, ast_ty, triv_ann(ann, t));
}
- case (ast.expr_if(?cond, ?then_0, ?else_0, ?ann)) {
- auto t = Demand.autoderef(fcx, e.span, expected,
+ case (ast::expr_if(?cond, ?then_0, ?else_0, ?ann)) {
+ auto t = Demand::autoderef(fcx, e.span, expected,
ann_to_type(ann), adk);
auto then_1 = pushdown_block(fcx, expected, then_0);
auto else_1;
alt (else_0) {
- case (none[@ast.expr]) { else_1 = none[@ast.expr]; }
- case (some[@ast.expr](?e_0)) {
+ case (none[@ast::expr]) { else_1 = none[@ast::expr]; }
+ case (some[@ast::expr](?e_0)) {
auto e_1 = pushdown_expr(fcx, expected, e_0);
- else_1 = some[@ast.expr](e_1);
+ else_1 = some[@ast::expr](e_1);
}
}
- e_1 = ast.expr_if(cond, then_1, else_1, triv_ann(ann, t));
+ e_1 = ast::expr_if(cond, then_1, else_1, triv_ann(ann, t));
}
- case (ast.expr_for(?decl, ?seq, ?bloc, ?ann)) {
- auto t = Demand.simple(fcx, e.span, expected,
+ case (ast::expr_for(?decl, ?seq, ?bloc, ?ann)) {
+ auto t = Demand::simple(fcx, e.span, expected,
ann_to_type(ann));
- e_1 = ast.expr_for(decl, seq, bloc, triv_ann(ann, t));
+ e_1 = ast::expr_for(decl, seq, bloc, triv_ann(ann, t));
}
- case (ast.expr_for_each(?decl, ?seq, ?bloc, ?ann)) {
- auto t = Demand.simple(fcx, e.span, expected,
+ case (ast::expr_for_each(?decl, ?seq, ?bloc, ?ann)) {
+ auto t = Demand::simple(fcx, e.span, expected,
ann_to_type(ann));
- e_1 = ast.expr_for_each(decl, seq, bloc, triv_ann(ann, t));
+ e_1 = ast::expr_for_each(decl, seq, bloc, triv_ann(ann, t));
}
- case (ast.expr_while(?cond, ?bloc, ?ann)) {
- auto t = Demand.simple(fcx, e.span, expected,
+ case (ast::expr_while(?cond, ?bloc, ?ann)) {
+ auto t = Demand::simple(fcx, e.span, expected,
ann_to_type(ann));
- e_1 = ast.expr_while(cond, bloc, triv_ann(ann, t));
+ e_1 = ast::expr_while(cond, bloc, triv_ann(ann, t));
}
- case (ast.expr_do_while(?bloc, ?cond, ?ann)) {
- auto t = Demand.simple(fcx, e.span, expected,
+ case (ast::expr_do_while(?bloc, ?cond, ?ann)) {
+ auto t = Demand::simple(fcx, e.span, expected,
ann_to_type(ann));
- e_1 = ast.expr_do_while(bloc, cond, triv_ann(ann, t));
+ e_1 = ast::expr_do_while(bloc, cond, triv_ann(ann, t));
}
- case (ast.expr_block(?bloc, ?ann)) {
- auto t = Demand.autoderef(fcx, e.span, expected,
+ case (ast::expr_block(?bloc, ?ann)) {
+ auto t = Demand::autoderef(fcx, e.span, expected,
ann_to_type(ann), adk);
- e_1 = ast.expr_block(bloc, triv_ann(ann, t));
+ e_1 = ast::expr_block(bloc, triv_ann(ann, t));
}
- case (ast.expr_assign(?lhs_0, ?rhs_0, ?ann)) {
- auto t = Demand.autoderef(fcx, e.span, expected,
+ case (ast::expr_assign(?lhs_0, ?rhs_0, ?ann)) {
+ auto t = Demand::autoderef(fcx, e.span, expected,
ann_to_type(ann), adk);
auto lhs_1 = pushdown_expr(fcx, expected, lhs_0);
auto rhs_1 = pushdown_expr(fcx, expected, rhs_0);
- e_1 = ast.expr_assign(lhs_1, rhs_1, triv_ann(ann, t));
+ e_1 = ast::expr_assign(lhs_1, rhs_1, triv_ann(ann, t));
}
- case (ast.expr_assign_op(?op, ?lhs_0, ?rhs_0, ?ann)) {
- auto t = Demand.autoderef(fcx, e.span, expected,
+ case (ast::expr_assign_op(?op, ?lhs_0, ?rhs_0, ?ann)) {
+ auto t = Demand::autoderef(fcx, e.span, expected,
ann_to_type(ann), adk);
auto lhs_1 = pushdown_expr(fcx, expected, lhs_0);
auto rhs_1 = pushdown_expr(fcx, expected, rhs_0);
- e_1 = ast.expr_assign_op(op, lhs_1, rhs_1, triv_ann(ann, t));
+ e_1 = ast::expr_assign_op(op, lhs_1, rhs_1, triv_ann(ann, t));
}
- case (ast.expr_field(?lhs, ?rhs, ?ann)) {
- auto t = Demand.autoderef(fcx, e.span, expected,
+ case (ast::expr_field(?lhs, ?rhs, ?ann)) {
+ auto t = Demand::autoderef(fcx, e.span, expected,
ann_to_type(ann), adk);
- e_1 = ast.expr_field(lhs, rhs, triv_ann(ann, t));
+ e_1 = ast::expr_field(lhs, rhs, triv_ann(ann, t));
}
- case (ast.expr_index(?base, ?index, ?ann)) {
- auto t = Demand.autoderef(fcx, e.span, expected,
+ case (ast::expr_index(?base, ?index, ?ann)) {
+ auto t = Demand::autoderef(fcx, e.span, expected,
ann_to_type(ann), adk);
- e_1 = ast.expr_index(base, index, triv_ann(ann, t));
+ e_1 = ast::expr_index(base, index, triv_ann(ann, t));
}
- case (ast.expr_path(?pth, ?ann)) {
- auto tp_substs_0 = ty.ann_to_type_params(ann);
+ case (ast::expr_path(?pth, ?ann)) {
+ auto tp_substs_0 = ty::ann_to_type_params(ann);
auto t_0 = ann_to_type(ann);
- auto result_0 = Demand.full(fcx, e.span, expected, t_0,
+ auto result_0 = Demand::full(fcx, e.span, expected, t_0,
tp_substs_0, adk);
auto t = result_0._1;
// provided by the programmer.
auto ty_params_opt;
alt (ann) {
- case (ast.ann_none(_)) {
+ case (ast::ann_none(_)) {
log_err "pushdown_expr(): no type annotation for " +
"path expr; did you pass it to check_expr()?";
fail;
}
- case (ast.ann_type(_, _, ?tps_opt, _)) {
+ case (ast::ann_type(_, _, ?tps_opt, _)) {
alt (tps_opt) {
- case (none[vec[ty.t]]) {
- ty_params_opt = none[vec[ty.t]];
+ case (none[vec[ty::t]]) {
+ ty_params_opt = none[vec[ty::t]];
}
- case (some[vec[ty.t]](?tps)) {
- ty_params_opt = some[vec[ty.t]](tps);
+ case (some[vec[ty::t]](?tps)) {
+ ty_params_opt = some[vec[ty::t]](tps);
}
}
}
}
- e_1 = ast.expr_path(pth,
- ast.ann_type(ast.ann_tag(ann), t,
+ e_1 = ast::expr_path(pth,
+ ast::ann_type(ast::ann_tag(ann), t,
ty_params_opt,
none[@ts_ann]));
}
- case (ast.expr_ext(?p, ?args, ?body, ?expanded, ?ann)) {
- auto t = Demand.autoderef(fcx, e.span, expected,
+ case (ast::expr_ext(?p, ?args, ?body, ?expanded, ?ann)) {
+ auto t = Demand::autoderef(fcx, e.span, expected,
ann_to_type(ann), adk);
- e_1 = ast.expr_ext(p, args, body, expanded, triv_ann(ann, t));
+ e_1 = ast::expr_ext(p, args, body, expanded,
+ triv_ann(ann, t));
}
/* FIXME: should this check the type annotations? */
- case (ast.expr_fail(_)) { e_1 = e.node; }
- case (ast.expr_log(_,_,_)) { e_1 = e.node; }
- case (ast.expr_break(_)) { e_1 = e.node; }
- case (ast.expr_cont(_)) { e_1 = e.node; }
- case (ast.expr_ret(_,_)) { e_1 = e.node; }
- case (ast.expr_put(_,_)) { e_1 = e.node; }
- case (ast.expr_be(_,_)) { e_1 = e.node; }
- case (ast.expr_check(_,_)) { e_1 = e.node; }
- case (ast.expr_assert(_,_)) { e_1 = e.node; }
-
- case (ast.expr_port(?ann)) {
- auto t = Demand.simple(fcx, e.span, expected,
+ case (ast::expr_fail(_)) { e_1 = e.node; }
+ case (ast::expr_log(_,_,_)) { e_1 = e.node; }
+ case (ast::expr_break(_)) { e_1 = e.node; }
+ case (ast::expr_cont(_)) { e_1 = e.node; }
+ case (ast::expr_ret(_,_)) { e_1 = e.node; }
+ case (ast::expr_put(_,_)) { e_1 = e.node; }
+ case (ast::expr_be(_,_)) { e_1 = e.node; }
+ case (ast::expr_check(_,_)) { e_1 = e.node; }
+ case (ast::expr_assert(_,_)) { e_1 = e.node; }
+
+ case (ast::expr_port(?ann)) {
+ auto t = Demand::simple(fcx, e.span, expected,
ann_to_type(ann));
- e_1 = ast.expr_port(triv_ann(ann, t));
+ e_1 = ast::expr_port(triv_ann(ann, t));
}
- case (ast.expr_chan(?es, ?ann)) {
- auto t = Demand.simple(fcx, e.span, expected,
+ case (ast::expr_chan(?es, ?ann)) {
+ auto t = Demand::simple(fcx, e.span, expected,
ann_to_type(ann));
- let @ast.expr es_1;
+ let @ast::expr es_1;
alt (struct(fcx.ccx.tcx, t)) {
- case (ty.ty_chan(?subty)) {
- auto pt = ty.mk_port(fcx.ccx.tcx, subty);
+ case (ty::ty_chan(?subty)) {
+ auto pt = ty::mk_port(fcx.ccx.tcx, subty);
es_1 = pushdown_expr(fcx, pt, es);
}
case (_) {
fail;
}
}
- e_1 = ast.expr_chan(es_1, triv_ann(ann, t));
+ e_1 = ast::expr_chan(es_1, triv_ann(ann, t));
}
- case (ast.expr_alt(?discrim, ?arms_0, ?ann)) {
+ case (ast::expr_alt(?discrim, ?arms_0, ?ann)) {
auto t = expected;
- let vec[ast.arm] arms_1 = vec();
- for (ast.arm arm_0 in arms_0) {
+ let vec[ast::arm] arms_1 = vec();
+ for (ast::arm arm_0 in arms_0) {
auto block_1 = pushdown_block(fcx, expected, arm_0.block);
- t = Demand.simple(fcx, e.span, t,
+ t = Demand::simple(fcx, e.span, t,
block_ty(fcx.ccx.tcx, block_1));
auto arm_1 = rec(pat=arm_0.pat, block=block_1);
arms_1 += vec(arm_1);
}
- e_1 = ast.expr_alt(discrim, arms_1, triv_ann(ann, t));
+ e_1 = ast::expr_alt(discrim, arms_1, triv_ann(ann, t));
}
- case (ast.expr_recv(?lval_0, ?expr_0, ?ann)) {
+ case (ast::expr_recv(?lval_0, ?expr_0, ?ann)) {
auto lval_1 = pushdown_expr(fcx, next_ty_var(fcx.ccx),
lval_0);
auto t = expr_ty(fcx.ccx.tcx, lval_1);
- auto expr_1 = pushdown_expr(fcx, ty.mk_port(fcx.ccx.tcx, t),
+ auto expr_1 = pushdown_expr(fcx, ty::mk_port(fcx.ccx.tcx, t),
expr_0);
- e_1 = ast.expr_recv(lval_1, expr_1, ann);
+ e_1 = ast::expr_recv(lval_1, expr_1, ann);
}
- case (ast.expr_send(?lval_0, ?expr_0, ?ann)) {
+ case (ast::expr_send(?lval_0, ?expr_0, ?ann)) {
auto expr_1 = pushdown_expr(fcx, next_ty_var(fcx.ccx),
expr_0);
auto t = expr_ty(fcx.ccx.tcx, expr_1);
- auto lval_1 = pushdown_expr(fcx, ty.mk_chan(fcx.ccx.tcx, t),
+ auto lval_1 = pushdown_expr(fcx, ty::mk_chan(fcx.ccx.tcx, t),
lval_0);
- e_1 = ast.expr_send(lval_1, expr_1, ann);
+ e_1 = ast::expr_send(lval_1, expr_1, ann);
}
case (_) {
fcx.ccx.sess.span_unimpl(e.span,
#fmt("type unification for expression variant: %s",
- util.common.expr_to_str(e)));
+ util::common::expr_to_str(e)));
fail;
}
}
- ret @fold.respan[ast.expr_](e.span, e_1);
+ ret @fold::respan[ast::expr_](e.span, e_1);
}
// Push-down over typed blocks.
- fn pushdown_block(&@fn_ctxt fcx, &ty.t expected, &ast.block bloc)
- -> ast.block {
+ fn pushdown_block(&@fn_ctxt fcx, &ty::t expected, &ast::block bloc)
+ -> ast::block {
alt (bloc.node.expr) {
- case (some[@ast.expr](?e_0)) {
+ case (some[@ast::expr](?e_0)) {
auto e_1 = pushdown_expr(fcx, expected, e_0);
auto block_ = rec(stmts=bloc.node.stmts,
- expr=some[@ast.expr](e_1),
+ expr=some[@ast::expr](e_1),
a=plain_ann(bloc.node.a, fcx.ccx.tcx));
- ret fold.respan[ast.block_](bloc.span, block_);
+ ret fold::respan[ast::block_](bloc.span, block_);
}
- case (none[@ast.expr]) {
- Demand.simple(fcx, bloc.span, expected,
- ty.mk_nil(fcx.ccx.tcx));
- ret fold.respan(bloc.span,
+ case (none[@ast::expr]) {
+ Demand::simple(fcx, bloc.span, expected,
+ ty::mk_nil(fcx.ccx.tcx));
+ ret fold::respan(bloc.span,
rec(a = plain_ann(bloc.node.a, fcx.ccx.tcx)
with bloc.node));
// Local variable resolution: the phase that finds all the types in the AST
// and replaces opaque "ty_local" types with the resolved local types.
-fn writeback_local(&Option.t[@fn_ctxt] env, &span sp, &@ast.local local)
- -> @ast.decl {
- auto fcx = Option.get[@fn_ctxt](env);
+fn writeback_local(&option::t[@fn_ctxt] env, &span sp, &@ast::local local)
+ -> @ast::decl {
+ auto fcx = option::get[@fn_ctxt](env);
auto local_ty;
alt (fcx.locals.find(local.id)) {
- case (none[ty.t]) {
+ case (none[ty::t]) {
fcx.ccx.sess.span_err(sp, "unable to determine type of local: "
+ local.ident);
fail;
}
- case (some[ty.t](?lt)) {
+ case (some[ty::t](?lt)) {
local_ty = lt;
}
}
auto local_wb = @rec(ann=triv_ann(local.ann, local_ty)
with *local
);
- ret @fold.respan[ast.decl_](sp, ast.decl_local(local_wb));
+ ret @fold::respan[ast::decl_](sp, ast::decl_local(local_wb));
}
-fn resolve_local_types_in_annotation(&Option.t[@fn_ctxt] env, &ast.ann ann)
- -> ast.ann {
- fn resolver(@fn_ctxt fcx, ty.t typ) -> ty.t {
+fn resolve_local_types_in_annotation(&option::t[@fn_ctxt] env, &ast::ann ann)
+ -> ast::ann {
+ fn resolver(@fn_ctxt fcx, ty::t typ) -> ty::t {
alt (struct(fcx.ccx.tcx, typ)) {
- case (ty.ty_local(?lid)) { ret fcx.locals.get(lid); }
+ case (ty::ty_local(?lid)) { ret fcx.locals.get(lid); }
case (_) { ret typ; }
}
}
- auto fcx = Option.get[@fn_ctxt](env);
+ auto fcx = option::get[@fn_ctxt](env);
alt (ann) {
- case (ast.ann_none(_)) {
+ case (ast::ann_none(_)) {
log "warning: no type for expression";
ret ann;
}
- case (ast.ann_type(?tg, ?typ, ?tps, ?ts_info)) {
+ case (ast::ann_type(?tg, ?typ, ?tps, ?ts_info)) {
auto tt = ann_to_type(ann);
- if (!ty.type_contains_locals(fcx.ccx.tcx, tt)) {
+ if (!ty::type_contains_locals(fcx.ccx.tcx, tt)) {
ret ann;
}
auto f = bind resolver(fcx, _);
- auto new_type = ty.fold_ty(fcx.ccx.tcx, f, ann_to_type(ann));
- ret ast.ann_type(tg, new_type, tps, ts_info);
+ auto new_type = ty::fold_ty(fcx.ccx.tcx, f, ann_to_type(ann));
+ ret ast::ann_type(tg, new_type, tps, ts_info);
}
}
}
-fn resolve_local_types_in_block(&@fn_ctxt fcx, &ast.block block)
- -> ast.block {
- fn update_env_for_item(&Option.t[@fn_ctxt] env, &@ast.item i)
- -> Option.t[@fn_ctxt] {
+fn resolve_local_types_in_block(&@fn_ctxt fcx, &ast::block block)
+ -> ast::block {
+ fn update_env_for_item(&option::t[@fn_ctxt] env, &@ast::item i)
+ -> option::t[@fn_ctxt] {
ret none[@fn_ctxt];
}
- fn keep_going(&Option.t[@fn_ctxt] env) -> bool {
- ret !Option.is_none[@fn_ctxt](env);
+ fn keep_going(&option::t[@fn_ctxt] env) -> bool {
+ ret !option::is_none[@fn_ctxt](env);
}
// FIXME: rustboot bug prevents us from using these functions directly
- auto fld = fold.new_identity_fold[Option.t[@fn_ctxt]]();
+ auto fld = fold::new_identity_fold[option::t[@fn_ctxt]]();
auto wbl = writeback_local;
auto rltia = bind resolve_local_types_in_annotation(_,_);
auto uefi = update_env_for_item;
update_env_for_item = uefi,
keep_going = kg
with *fld);
- ret fold.fold_block[Option.t[@fn_ctxt]](some[@fn_ctxt](fcx), fld, block);
+ ret fold::fold_block[option::t[@fn_ctxt]](some(fcx), fld, block);
}
// AST fragment checking
-fn check_lit(@crate_ctxt ccx, &@ast.lit lit) -> ty.t {
+fn check_lit(@crate_ctxt ccx, &@ast::lit lit) -> ty::t {
alt (lit.node) {
- case (ast.lit_str(_)) { ret ty.mk_str(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); }
+ case (ast::lit_str(_)) { ret ty::mk_str(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); }
}
fail; // not reached
}
-fn check_pat(&@fn_ctxt fcx, &@ast.pat pat) -> @ast.pat {
+fn check_pat(&@fn_ctxt fcx, &@ast::pat pat) -> @ast::pat {
auto new_pat;
alt (pat.node) {
- case (ast.pat_wild(?ann)) {
- new_pat = ast.pat_wild(triv_ann(ann, next_ty_var(fcx.ccx)));
+ case (ast::pat_wild(?ann)) {
+ new_pat = ast::pat_wild(triv_ann(ann, next_ty_var(fcx.ccx)));
}
- case (ast.pat_lit(?lt, ?ann)) {
- new_pat = ast.pat_lit(lt, triv_ann(ann, check_lit(fcx.ccx, lt)));
+ case (ast::pat_lit(?lt, ?ann)) {
+ new_pat = ast::pat_lit(lt, triv_ann(ann, check_lit(fcx.ccx, lt)));
}
- case (ast.pat_bind(?id, ?def_id, ?a)) {
+ case (ast::pat_bind(?id, ?def_id, ?a)) {
auto ann = triv_ann(a, next_ty_var(fcx.ccx));
- new_pat = ast.pat_bind(id, def_id, ann);
+ new_pat = ast::pat_bind(id, def_id, ann);
}
- case (ast.pat_tag(?p, ?subpats, ?old_ann)) {
- auto vdef = ast.variant_def_ids
- (fcx.ccx.tcx.def_map.get(ast.ann_tag(old_ann)));
- auto t = ty.lookup_item_type(fcx.ccx.sess, fcx.ccx.tcx,
+ case (ast::pat_tag(?p, ?subpats, ?old_ann)) {
+ auto vdef = ast::variant_def_ids
+ (fcx.ccx.tcx.def_map.get(ast::ann_tag(old_ann)));
+ auto t = ty::lookup_item_type(fcx.ccx.sess, fcx.ccx.tcx,
fcx.ccx.type_cache, vdef._1)._1;
- auto len = Vec.len[ast.ident](p.node.idents);
+ auto len = _vec::len[ast::ident](p.node.idents);
auto last_id = p.node.idents.(len - 1u);
- auto tpt = ty.lookup_item_type(fcx.ccx.sess, fcx.ccx.tcx,
+ auto tpt = ty::lookup_item_type(fcx.ccx.sess, fcx.ccx.tcx,
fcx.ccx.type_cache, vdef._0);
auto ann = instantiate_path(fcx, p, tpt, pat.span,
- ast.ann_tag(old_ann));
+ ast::ann_tag(old_ann));
alt (struct(fcx.ccx.tcx, t)) {
// N-ary variants have function types.
- case (ty.ty_fn(_, ?args, ?tag_ty)) {
- auto arg_len = Vec.len[arg](args);
- auto subpats_len = Vec.len[@ast.pat](subpats);
+ case (ty::ty_fn(_, ?args, ?tag_ty)) {
+ auto arg_len = _vec::len[arg](args);
+ auto subpats_len = _vec::len[@ast::pat](subpats);
if (arg_len != subpats_len) {
// TODO: pluralize properly
auto err_msg = "tag type " + last_id + " has " +
- UInt.to_str(subpats_len, 10u) +
+ _uint::to_str(subpats_len, 10u) +
" field(s), but this pattern has " +
- UInt.to_str(arg_len, 10u) +
+ _uint::to_str(arg_len, 10u) +
" field(s)";
fcx.ccx.sess.span_err(pat.span, err_msg);
fail; // TODO: recover
}
- let vec[@ast.pat] new_subpats = vec();
- for (@ast.pat subpat in subpats) {
+ let vec[@ast::pat] new_subpats = vec();
+ for (@ast::pat subpat in subpats) {
new_subpats += vec(check_pat(fcx, subpat));
}
- new_pat = ast.pat_tag(p, new_subpats, ann);
+ new_pat = ast::pat_tag(p, new_subpats, ann);
}
// Nullary variants have tag types.
- case (ty.ty_tag(?tid, _)) {
- auto subpats_len = Vec.len[@ast.pat](subpats);
+ case (ty::ty_tag(?tid, _)) {
+ auto subpats_len = _vec::len[@ast::pat](subpats);
if (subpats_len > 0u) {
// TODO: pluralize properly
auto err_msg = "tag type " + last_id +
" has no field(s)," +
" but this pattern has " +
- UInt.to_str(subpats_len, 10u) +
+ _uint::to_str(subpats_len, 10u) +
" field(s)";
fcx.ccx.sess.span_err(pat.span, err_msg);
fail; // TODO: recover
}
- new_pat = ast.pat_tag(p, subpats, ann);
+ new_pat = ast::pat_tag(p, subpats, ann);
}
}
}
}
- ret @fold.respan[ast.pat_](pat.span, new_pat);
+ ret @fold::respan[ast::pat_](pat.span, new_pat);
}
-fn require_impure(&session.session sess,
- &ast.purity f_purity, &span sp) -> () {
+fn require_impure(&session::session sess,
+ &ast::purity f_purity, &span sp) -> () {
alt (f_purity) {
- case (ast.impure_fn) {
+ case (ast::impure_fn) {
ret;
}
- case (ast.pure_fn) {
+ case (ast::pure_fn) {
sess.span_err(sp,
"Found impure expression in pure function decl");
}
}
}
-fn get_function_purity(@crate_ctxt ccx, &ast.def_id d_id) -> ast.purity {
- let Option.t[ast.purity] o = ccx.fn_purity_table.find(d_id);
- ret from_maybe[ast.purity](ast.impure_fn, o);
+fn get_function_purity(@crate_ctxt ccx, &ast::def_id d_id) -> ast::purity {
+ let option::t[ast::purity] o = ccx.fn_purity_table.find(d_id);
+ ret from_maybe[ast::purity](ast::impure_fn, o);
}
fn require_pure_call(@crate_ctxt ccx,
- &ast.purity caller_purity,
- &@ast.expr callee, &span sp) -> () {
+ &ast::purity caller_purity,
+ &@ast::expr callee, &span sp) -> () {
alt (caller_purity) {
- case (ast.impure_fn) {
+ case (ast::impure_fn) {
ret;
}
- case (ast.pure_fn) {
+ case (ast::pure_fn) {
alt (callee.node) {
- case (ast.expr_path(_, ?ann)) {
+ case (ast::expr_path(_, ?ann)) {
auto d_id;
- alt (ccx.tcx.def_map.get(ast.ann_tag(ann))) {
- case (ast.def_fn(?_d_id)) { d_id = _d_id; }
+ alt (ccx.tcx.def_map.get(ast::ann_tag(ann))) {
+ case (ast::def_fn(?_d_id)) { d_id = _d_id; }
}
alt (get_function_purity(ccx, d_id)) {
- case (ast.pure_fn) {
+ case (ast::pure_fn) {
ret;
}
case (_) {
}
}
-fn require_pure_function(@crate_ctxt ccx, &ast.def_id d_id, &span sp) -> () {
+fn require_pure_function(@crate_ctxt ccx, &ast::def_id d_id, &span sp) -> () {
alt (get_function_purity(ccx, d_id)) {
- case (ast.impure_fn) {
+ case (ast::impure_fn) {
ccx.sess.span_err(sp, "Found non-predicate in check expression");
}
case (_) { ret; }
}
}
-fn check_expr(&@fn_ctxt fcx, &@ast.expr expr) -> @ast.expr {
+fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) -> @ast::expr {
//fcx.ccx.sess.span_warn(expr.span, "typechecking expr " +
- // util.common.expr_to_str(expr));
+ // util::common::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, &@ast.expr f,
- &vec[Option.t[@ast.expr]] args)
- -> tup(@ast.expr, vec[Option.t[@ast.expr]]) {
+ fn check_call_or_bind(&@fn_ctxt fcx, &@ast::expr f,
+ &vec[option::t[@ast::expr]] args)
+ -> tup(@ast::expr, vec[option::t[@ast::expr]]) {
// Check the function.
auto f_0 = check_expr(fcx, f);
// Check the arguments and generate the argument signature.
- let vec[Option.t[@ast.expr]] args_0 = vec();
+ let vec[option::t[@ast::expr]] args_0 = vec();
let vec[arg] arg_tys_0 = vec();
- for (Option.t[@ast.expr] a_opt in args) {
+ for (option::t[@ast::expr] a_opt in args) {
alt (a_opt) {
- case (some[@ast.expr](?a)) {
+ case (some[@ast::expr](?a)) {
auto a_0 = check_expr(fcx, a);
- args_0 += vec(some[@ast.expr](a_0));
+ args_0 += vec(some[@ast::expr](a_0));
auto arg_ty = rec(mode=mo_either,
ty=expr_ty(fcx.ccx.tcx, a_0));
- Vec.push[arg](arg_tys_0, arg_ty);
+ _vec::push[arg](arg_tys_0, arg_ty);
}
- case (none[@ast.expr]) {
- args_0 += vec(none[@ast.expr]);
+ case (none[@ast::expr]) {
+ args_0 += vec(none[@ast::expr]);
auto typ = next_ty_var(fcx.ccx);
- Vec.push[arg](arg_tys_0, rec(mode=mo_either, ty=typ));
+ _vec::push[arg](arg_tys_0, rec(mode=mo_either, ty=typ));
}
}
}
auto rt_0 = next_ty_var(fcx.ccx);
auto t_0;
alt (struct(fcx.ccx.tcx, expr_ty(fcx.ccx.tcx, f_0))) {
- case (ty.ty_fn(?proto, _, _)) {
- t_0 = ty.mk_fn(fcx.ccx.tcx, proto, arg_tys_0, rt_0);
+ case (ty::ty_fn(?proto, _, _)) {
+ t_0 = ty::mk_fn(fcx.ccx.tcx, proto, arg_tys_0, rt_0);
}
- case (ty.ty_native_fn(?abi, _, _)) {
- t_0 = ty.mk_native_fn(fcx.ccx.tcx, abi, arg_tys_0, rt_0);
+ case (ty::ty_native_fn(?abi, _, _)) {
+ t_0 = ty::mk_native_fn(fcx.ccx.tcx, abi, arg_tys_0, rt_0);
}
case (_) {
log_err "check_call_or_bind(): fn expr doesn't have fn type";
}
// Unify the callee and arguments.
- auto tpt_0 = ty.expr_ty_params_and_ty(fcx.ccx.tcx, f_0);
- auto tpt_1 = Demand.full(fcx, f.span, tpt_0._1, t_0, tpt_0._0,
+ auto tpt_0 = ty::expr_ty_params_and_ty(fcx.ccx.tcx, f_0);
+ auto tpt_1 = Demand::full(fcx, f.span, tpt_0._1, t_0, tpt_0._0,
NO_AUTODEREF);
- auto f_1 = ty.replace_expr_type(f_0, tpt_1);
+ auto f_1 = ty::replace_expr_type(f_0, tpt_1);
ret tup(f_1, args_0);
}
// A generic function for checking assignment expressions
- fn check_assignment(&@fn_ctxt fcx, &@ast.expr lhs, &@ast.expr rhs,
- &ast.ann a)
- -> tup(@ast.expr, @ast.expr, ast.ann) {
+ fn check_assignment(&@fn_ctxt fcx, &@ast::expr lhs, &@ast::expr rhs,
+ &ast::ann a)
+ -> tup(@ast::expr, @ast::expr, ast::ann) {
auto lhs_0 = check_expr(fcx, lhs);
auto rhs_0 = check_expr(fcx, rhs);
auto lhs_t0 = expr_ty(fcx.ccx.tcx, lhs_0);
auto rhs_t0 = expr_ty(fcx.ccx.tcx, rhs_0);
- auto lhs_1 = Pushdown.pushdown_expr(fcx, rhs_t0, lhs_0);
- auto rhs_1 = Pushdown.pushdown_expr(fcx, expr_ty(fcx.ccx.tcx, lhs_1),
+ auto lhs_1 = Pushdown::pushdown_expr(fcx, rhs_t0, lhs_0);
+ auto rhs_1 = Pushdown::pushdown_expr(fcx, expr_ty(fcx.ccx.tcx, lhs_1),
rhs_0);
auto ann = triv_ann(a, expr_ty(fcx.ccx.tcx, rhs_1));
}
// A generic function for checking call expressions
- fn check_call(&@fn_ctxt fcx, &@ast.expr f, &vec[@ast.expr] args)
- -> tup(@ast.expr, vec[@ast.expr]) {
+ fn check_call(&@fn_ctxt fcx, &@ast::expr f, &vec[@ast::expr] args)
+ -> tup(@ast::expr, vec[@ast::expr]) {
- let vec[Option.t[@ast.expr]] args_opt_0 = vec();
- for (@ast.expr arg in args) {
- args_opt_0 += vec(some[@ast.expr](arg));
+ let vec[option::t[@ast::expr]] args_opt_0 = vec();
+ for (@ast::expr arg in args) {
+ args_opt_0 += vec(some[@ast::expr](arg));
}
// Call the generic checker.
auto result = check_call_or_bind(fcx, f, args_opt_0);
// Pull out the arguments.
- let vec[@ast.expr] args_1 = vec();
- for (Option.t[@ast.expr] arg in result._1) {
- args_1 += vec(Option.get[@ast.expr](arg));
+ let vec[@ast::expr] args_1 = vec();
+ for (option::t[@ast::expr] arg in result._1) {
+ args_1 += vec(option::get[@ast::expr](arg));
}
ret tup(result._0, args_1);
}
alt (expr.node) {
- case (ast.expr_lit(?lit, ?a)) {
+ case (ast::expr_lit(?lit, ?a)) {
auto typ = check_lit(fcx.ccx, lit);
auto ann = triv_ann(a, typ);
- ret @fold.respan[ast.expr_](expr.span, ast.expr_lit(lit, ann));
+ ret @fold::respan[ast::expr_](expr.span, ast::expr_lit(lit, ann));
}
- case (ast.expr_binary(?binop, ?lhs, ?rhs, ?a)) {
+ case (ast::expr_binary(?binop, ?lhs, ?rhs, ?a)) {
auto lhs_0 = check_expr(fcx, lhs);
auto rhs_0 = check_expr(fcx, rhs);
auto lhs_t0 = expr_ty(fcx.ccx.tcx, lhs_0);
auto rhs_t0 = expr_ty(fcx.ccx.tcx, rhs_0);
// FIXME: Binops have a bit more subtlety than this.
- auto lhs_1 = Pushdown.pushdown_expr_full(fcx, rhs_t0, lhs_0,
+ auto lhs_1 = Pushdown::pushdown_expr_full(fcx, rhs_t0, lhs_0,
AUTODEREF_OK);
auto rhs_1 =
- Pushdown.pushdown_expr_full(fcx,
+ Pushdown::pushdown_expr_full(fcx,
expr_ty(fcx.ccx.tcx, lhs_1),
rhs_0, AUTODEREF_OK);
auto t = strip_boxes(fcx.ccx.tcx, lhs_t0);
alt (binop) {
- case (ast.eq) { t = ty.mk_bool(fcx.ccx.tcx); }
- case (ast.lt) { t = ty.mk_bool(fcx.ccx.tcx); }
- case (ast.le) { t = ty.mk_bool(fcx.ccx.tcx); }
- case (ast.ne) { t = ty.mk_bool(fcx.ccx.tcx); }
- case (ast.ge) { t = ty.mk_bool(fcx.ccx.tcx); }
- case (ast.gt) { t = ty.mk_bool(fcx.ccx.tcx); }
+ case (ast::eq) { t = ty::mk_bool(fcx.ccx.tcx); }
+ case (ast::lt) { t = ty::mk_bool(fcx.ccx.tcx); }
+ case (ast::le) { t = ty::mk_bool(fcx.ccx.tcx); }
+ case (ast::ne) { t = ty::mk_bool(fcx.ccx.tcx); }
+ case (ast::ge) { t = ty::mk_bool(fcx.ccx.tcx); }
+ case (ast::gt) { t = ty::mk_bool(fcx.ccx.tcx); }
case (_) { /* fall through */ }
}
auto ann = triv_ann(a, t);
- ret @fold.respan[ast.expr_](expr.span,
- ast.expr_binary(binop, lhs_1, rhs_1,
+ ret @fold::respan[ast::expr_](expr.span,
+ ast::expr_binary(binop, lhs_1, rhs_1,
ann));
}
- case (ast.expr_unary(?unop, ?oper, ?a)) {
+ case (ast::expr_unary(?unop, ?oper, ?a)) {
auto oper_1 = check_expr(fcx, oper);
auto oper_t = expr_ty(fcx.ccx.tcx, oper_1);
alt (unop) {
- case (ast.box(?mut)) {
- oper_t = ty.mk_box(fcx.ccx.tcx,
+ case (ast::box(?mut)) {
+ oper_t = ty::mk_box(fcx.ccx.tcx,
rec(ty=oper_t, mut=mut));
}
- case (ast.deref) {
+ case (ast::deref) {
alt (struct(fcx.ccx.tcx, oper_t)) {
- case (ty.ty_box(?inner)) {
+ case (ty::ty_box(?inner)) {
oper_t = inner.ty;
}
case (_) {
}
auto ann = triv_ann(a, oper_t);
- ret @fold.respan[ast.expr_](expr.span,
- ast.expr_unary(unop, oper_1, ann));
+ ret @fold::respan[ast::expr_](expr.span,
+ ast::expr_unary(unop, oper_1, ann));
}
- case (ast.expr_path(?pth, ?old_ann)) {
- auto t = ty.mk_nil(fcx.ccx.tcx);
- auto defn = fcx.ccx.tcx.def_map.get(ast.ann_tag(old_ann));
+ case (ast::expr_path(?pth, ?old_ann)) {
+ auto t = ty::mk_nil(fcx.ccx.tcx);
+ auto defn = fcx.ccx.tcx.def_map.get(ast::ann_tag(old_ann));
auto tpt = ty_param_count_and_ty_for_def(fcx, expr.span, defn);
- if (ty.def_has_ty_params(defn)) {
+ if (ty::def_has_ty_params(defn)) {
auto ann = instantiate_path(fcx, pth, tpt, expr.span,
- ast.ann_tag(old_ann));
- ret @fold.respan[ast.expr_](expr.span,
- ast.expr_path(pth, ann));
+ ast::ann_tag(old_ann));
+ ret @fold::respan[ast::expr_](expr.span,
+ ast::expr_path(pth, ann));
}
// The definition doesn't take type parameters. If the programmer
// supplied some, that's an error.
- if (Vec.len[@ast.ty](pth.node.types) > 0u) {
+ if (_vec::len[@ast::ty](pth.node.types) > 0u) {
fcx.ccx.sess.span_err(expr.span, "this kind of value does " +
"not take type parameters");
fail;
}
- auto e = ast.expr_path(pth, triv_ann(old_ann, tpt._1));
- ret @fold.respan[ast.expr_](expr.span, e);
+ auto e = ast::expr_path(pth, triv_ann(old_ann, tpt._1));
+ ret @fold::respan[ast::expr_](expr.span, e);
}
- case (ast.expr_ext(?p, ?args, ?body, ?expanded, ?a)) {
+ case (ast::expr_ext(?p, ?args, ?body, ?expanded, ?a)) {
auto exp_ = check_expr(fcx, expanded);
auto t = expr_ty(fcx.ccx.tcx, exp_);
auto ann = triv_ann(a, t);
- ret @fold.respan[ast.expr_](expr.span,
- ast.expr_ext(p, args, body, exp_,
+ ret @fold::respan[ast::expr_](expr.span,
+ ast::expr_ext(p, args, body, exp_,
ann));
}
- case (ast.expr_fail(?a)) {
- ret @fold.respan[ast.expr_](expr.span,
- ast.expr_fail(plain_ann(a, fcx.ccx.tcx)));
+ case (ast::expr_fail(?a)) {
+ ret @fold::respan[ast::expr_](expr.span,
+ ast::expr_fail(plain_ann(a, fcx.ccx.tcx)));
}
- case (ast.expr_break(?a)) {
- ret @fold.respan[ast.expr_](expr.span,
- ast.expr_break(plain_ann(a, fcx.ccx.tcx)));
+ case (ast::expr_break(?a)) {
+ ret @fold::respan[ast::expr_](expr.span,
+ ast::expr_break(plain_ann(a, fcx.ccx.tcx)));
}
- case (ast.expr_cont(?a)) {
- ret @fold.respan[ast.expr_](expr.span,
- ast.expr_cont(plain_ann(a, fcx.ccx.tcx)));
+ case (ast::expr_cont(?a)) {
+ ret @fold::respan[ast::expr_](expr.span,
+ ast::expr_cont(plain_ann(a, fcx.ccx.tcx)));
}
- case (ast.expr_ret(?expr_opt, ?a)) {
+ case (ast::expr_ret(?expr_opt, ?a)) {
alt (expr_opt) {
- case (none[@ast.expr]) {
- auto nil = ty.mk_nil(fcx.ccx.tcx);
+ case (none[@ast::expr]) {
+ auto nil = ty::mk_nil(fcx.ccx.tcx);
if (!are_compatible(fcx, fcx.ret_ty, nil)) {
fcx.ccx.sess.err("ret; in function "
+ "returning non-nil");
}
- ret @fold.respan[ast.expr_]
+ ret @fold::respan[ast::expr_]
(expr.span,
- ast.expr_ret(none[@ast.expr],
+ ast::expr_ret(none[@ast::expr],
plain_ann(a, fcx.ccx.tcx)));
}
- case (some[@ast.expr](?e)) {
+ case (some[@ast::expr](?e)) {
auto expr_0 = check_expr(fcx, e);
- auto expr_1 = Pushdown.pushdown_expr(fcx, fcx.ret_ty,
+ auto expr_1 = Pushdown::pushdown_expr(fcx, fcx.ret_ty,
expr_0);
- ret @fold.respan[ast.expr_]
- (expr.span, ast.expr_ret(some(expr_1),
+ ret @fold::respan[ast::expr_]
+ (expr.span, ast::expr_ret(some(expr_1),
plain_ann(a, fcx.ccx.tcx)));
}
}
}
- case (ast.expr_put(?expr_opt, ?a)) {
+ case (ast::expr_put(?expr_opt, ?a)) {
require_impure(fcx.ccx.sess, fcx.purity, expr.span);
alt (expr_opt) {
- case (none[@ast.expr]) {
- auto nil = ty.mk_nil(fcx.ccx.tcx);
+ case (none[@ast::expr]) {
+ auto nil = ty::mk_nil(fcx.ccx.tcx);
if (!are_compatible(fcx, fcx.ret_ty, nil)) {
fcx.ccx.sess.err("put; in function "
+ "putting non-nil");
}
- ret @fold.respan[ast.expr_]
- (expr.span, ast.expr_put(none[@ast.expr],
+ ret @fold::respan[ast::expr_]
+ (expr.span, ast::expr_put(none[@ast::expr],
plain_ann(a, fcx.ccx.tcx)));
}
- case (some[@ast.expr](?e)) {
+ case (some[@ast::expr](?e)) {
auto expr_0 = check_expr(fcx, e);
- auto expr_1 = Pushdown.pushdown_expr(fcx, fcx.ret_ty,
+ auto expr_1 = Pushdown::pushdown_expr(fcx, fcx.ret_ty,
expr_0);
- ret @fold.respan[ast.expr_]
- (expr.span, ast.expr_put(some(expr_1),
+ ret @fold::respan[ast::expr_]
+ (expr.span, ast::expr_put(some(expr_1),
plain_ann(a, fcx.ccx.tcx)));
}
}
}
- case (ast.expr_be(?e, ?a)) {
+ case (ast::expr_be(?e, ?a)) {
/* FIXME: prove instead of check */
- assert (ast.is_call_expr(e));
+ assert (ast::is_call_expr(e));
auto expr_0 = check_expr(fcx, e);
- auto expr_1 = Pushdown.pushdown_expr(fcx, fcx.ret_ty, expr_0);
- ret @fold.respan(expr.span,
- ast.expr_be(expr_1, plain_ann(a, fcx.ccx.tcx)));
+ auto expr_1 = Pushdown::pushdown_expr(fcx, fcx.ret_ty, expr_0);
+ ret @fold::respan(expr.span,
+ ast::expr_be(expr_1, plain_ann(a, fcx.ccx.tcx)));
}
- case (ast.expr_log(?l, ?e, ?a)) {
+ case (ast::expr_log(?l, ?e, ?a)) {
auto expr_t = check_expr(fcx, e);
- ret @fold.respan[ast.expr_]
- (expr.span, ast.expr_log(l, expr_t,
+ ret @fold::respan[ast::expr_]
+ (expr.span, ast::expr_log(l, expr_t,
plain_ann(a, fcx.ccx.tcx)));
}
- case (ast.expr_check(?e, ?a)) {
+ case (ast::expr_check(?e, ?a)) {
auto expr_t = check_expr(fcx, e);
- Demand.simple(fcx, expr.span, ty.mk_bool(fcx.ccx.tcx),
+ Demand::simple(fcx, expr.span, ty::mk_bool(fcx.ccx.tcx),
expr_ty(fcx.ccx.tcx, expr_t));
/* e must be a call expr where all arguments are either
literals or slots */
alt (e.node) {
- case (ast.expr_call(?operator, ?operands, _)) {
+ case (ast::expr_call(?operator, ?operands, _)) {
alt (operator.node) {
- case (ast.expr_path(?oper_name, ?ann)) {
+ case (ast::expr_path(?oper_name, ?ann)) {
auto d_id;
- alt (fcx.ccx.tcx.def_map.get(ast.ann_tag(ann))) {
- case (ast.def_fn(?_d_id)) { d_id = _d_id; }
+ alt (fcx.ccx.tcx.def_map.get(ast::ann_tag(ann))) {
+ case (ast::def_fn(?_d_id)) { d_id = _d_id; }
}
- for (@ast.expr operand in operands) {
- if (! ast.is_constraint_arg(operand)) {
+ for (@ast::expr operand in operands) {
+ if (! ast::is_constraint_arg(operand)) {
fcx.ccx.sess.span_err(expr.span,
"Constraint args must be "
+ "slot variables or literals");
require_pure_function(fcx.ccx, d_id, expr.span);
- ret @fold.respan[ast.expr_]
- (expr.span, ast.expr_check(expr_t,
+ ret @fold::respan[ast::expr_]
+ (expr.span, ast::expr_check(expr_t,
plain_ann(a, fcx.ccx.tcx)));
}
case (_) {
}
}
- case (ast.expr_assert(?e, ?a)) {
+ case (ast::expr_assert(?e, ?a)) {
auto expr_t = check_expr(fcx, e);
- Demand.simple(fcx, expr.span, ty.mk_bool(fcx.ccx.tcx),
+ Demand::simple(fcx, expr.span, ty::mk_bool(fcx.ccx.tcx),
expr_ty(fcx.ccx.tcx, expr_t));
- ret @fold.respan[ast.expr_]
- (expr.span, ast.expr_assert(expr_t,
+ ret @fold::respan[ast::expr_]
+ (expr.span, ast::expr_assert(expr_t,
plain_ann(a, fcx.ccx.tcx)));
}
- case (ast.expr_assign(?lhs, ?rhs, ?a)) {
+ case (ast::expr_assign(?lhs, ?rhs, ?a)) {
require_impure(fcx.ccx.sess, fcx.purity, expr.span);
auto checked = check_assignment(fcx, lhs, rhs, a);
- auto newexpr = ast.expr_assign(checked._0,
+ auto newexpr = ast::expr_assign(checked._0,
checked._1,
checked._2);
- ret @fold.respan[ast.expr_](expr.span, newexpr);
+ ret @fold::respan[ast::expr_](expr.span, newexpr);
}
- case (ast.expr_assign_op(?op, ?lhs, ?rhs, ?a)) {
+ case (ast::expr_assign_op(?op, ?lhs, ?rhs, ?a)) {
require_impure(fcx.ccx.sess, fcx.purity, expr.span);
auto checked = check_assignment(fcx, lhs, rhs, a);
- auto newexpr = ast.expr_assign_op(op,
+ auto newexpr = ast::expr_assign_op(op,
checked._0,
checked._1,
checked._2);
- ret @fold.respan[ast.expr_](expr.span, newexpr);
+ ret @fold::respan[ast::expr_](expr.span, newexpr);
}
- case (ast.expr_send(?lhs, ?rhs, ?a)) {
+ case (ast::expr_send(?lhs, ?rhs, ?a)) {
require_impure(fcx.ccx.sess, fcx.purity, expr.span);
auto lhs_0 = check_expr(fcx, lhs);
auto rhs_0 = check_expr(fcx, rhs);
auto rhs_t = expr_ty(fcx.ccx.tcx, rhs_0);
- auto chan_t = ty.mk_chan(fcx.ccx.tcx, rhs_t);
- auto lhs_1 = Pushdown.pushdown_expr(fcx, chan_t, lhs_0);
+ auto chan_t = ty::mk_chan(fcx.ccx.tcx, rhs_t);
+ auto lhs_1 = Pushdown::pushdown_expr(fcx, chan_t, lhs_0);
auto item_t;
alt (struct(fcx.ccx.tcx, expr_ty(fcx.ccx.tcx, lhs_1))) {
- case (ty.ty_chan(?it)) {
+ case (ty::ty_chan(?it)) {
item_t = it;
}
case (_) {
fail;
}
}
- auto rhs_1 = Pushdown.pushdown_expr(fcx, item_t, rhs_0);
+ auto rhs_1 = Pushdown::pushdown_expr(fcx, item_t, rhs_0);
auto ann = triv_ann(a, chan_t);
- auto newexpr = ast.expr_send(lhs_1, rhs_1, ann);
- ret @fold.respan[ast.expr_](expr.span, newexpr);
+ auto newexpr = ast::expr_send(lhs_1, rhs_1, ann);
+ ret @fold::respan[ast::expr_](expr.span, newexpr);
}
- case (ast.expr_recv(?lhs, ?rhs, ?a)) {
+ case (ast::expr_recv(?lhs, ?rhs, ?a)) {
require_impure(fcx.ccx.sess, fcx.purity, expr.span);
auto lhs_0 = check_expr(fcx, lhs);
auto rhs_0 = check_expr(fcx, rhs);
auto lhs_t1 = expr_ty(fcx.ccx.tcx, lhs_0);
- auto port_t = ty.mk_port(fcx.ccx.tcx, lhs_t1);
- auto rhs_1 = Pushdown.pushdown_expr(fcx, port_t, rhs_0);
+ auto port_t = ty::mk_port(fcx.ccx.tcx, lhs_t1);
+ auto rhs_1 = Pushdown::pushdown_expr(fcx, port_t, rhs_0);
auto item_t;
alt (struct(fcx.ccx.tcx, expr_ty(fcx.ccx.tcx, rhs_0))) {
- case (ty.ty_port(?it)) {
+ case (ty::ty_port(?it)) {
item_t = it;
}
case (_) {
fail;
}
}
- auto lhs_1 = Pushdown.pushdown_expr(fcx, item_t, lhs_0);
+ auto lhs_1 = Pushdown::pushdown_expr(fcx, item_t, lhs_0);
auto ann = triv_ann(a, item_t);
- auto newexpr = ast.expr_recv(lhs_1, rhs_1, ann);
- ret @fold.respan[ast.expr_](expr.span, newexpr);
+ auto newexpr = ast::expr_recv(lhs_1, rhs_1, ann);
+ ret @fold::respan[ast::expr_](expr.span, newexpr);
}
- case (ast.expr_if(?cond, ?thn, ?elsopt, ?a)) {
+ case (ast::expr_if(?cond, ?thn, ?elsopt, ?a)) {
auto cond_0 = check_expr(fcx, cond);
- auto cond_1 = Pushdown.pushdown_expr(fcx, ty.mk_bool(fcx.ccx.tcx),
- cond_0);
+ auto cond_1 = Pushdown::pushdown_expr(fcx,
+ ty::mk_bool(fcx.ccx.tcx),
+ cond_0);
auto thn_0 = check_block(fcx, thn);
auto thn_t = block_ty(fcx.ccx.tcx, thn_0);
auto elsopt_1;
auto elsopt_t;
alt (elsopt) {
- case (some[@ast.expr](?els)) {
+ case (some[@ast::expr](?els)) {
auto els_0 = check_expr(fcx, els);
- auto els_1 = Pushdown.pushdown_expr(fcx, thn_t, els_0);
- elsopt_1 = some[@ast.expr](els_1);
+ auto els_1 = Pushdown::pushdown_expr(fcx, thn_t, els_0);
+ elsopt_1 = some[@ast::expr](els_1);
elsopt_t = expr_ty(fcx.ccx.tcx, els_1);
}
- case (none[@ast.expr]) {
- elsopt_1 = none[@ast.expr];
- elsopt_t = ty.mk_nil(fcx.ccx.tcx);
+ case (none[@ast::expr]) {
+ elsopt_1 = none[@ast::expr];
+ elsopt_t = ty::mk_nil(fcx.ccx.tcx);
}
}
- auto thn_1 = Pushdown.pushdown_block(fcx, elsopt_t, thn_0);
+ auto thn_1 = Pushdown::pushdown_block(fcx, elsopt_t, thn_0);
auto ann = triv_ann(a, elsopt_t);
- ret @fold.respan[ast.expr_](expr.span,
- ast.expr_if(cond_1, thn_1,
+ ret @fold::respan[ast::expr_](expr.span,
+ ast::expr_if(cond_1, thn_1,
elsopt_1, ann));
}
- case (ast.expr_for(?decl, ?seq, ?body, ?a)) {
+ case (ast::expr_for(?decl, ?seq, ?body, ?a)) {
auto decl_1 = check_decl_local(fcx, decl);
auto seq_1 = check_expr(fcx, seq);
auto body_1 = check_block(fcx, body);
// FIXME: enforce that the type of the decl is the element type
// of the seq.
- auto ann = triv_ann(a, ty.mk_nil(fcx.ccx.tcx));
- ret @fold.respan[ast.expr_](expr.span,
- ast.expr_for(decl_1, seq_1,
+ auto ann = triv_ann(a, ty::mk_nil(fcx.ccx.tcx));
+ ret @fold::respan[ast::expr_](expr.span,
+ ast::expr_for(decl_1, seq_1,
body_1, ann));
}
- case (ast.expr_for_each(?decl, ?seq, ?body, ?a)) {
+ case (ast::expr_for_each(?decl, ?seq, ?body, ?a)) {
auto decl_1 = check_decl_local(fcx, decl);
auto seq_1 = check_expr(fcx, seq);
auto body_1 = check_block(fcx, body);
- auto ann = triv_ann(a, ty.mk_nil(fcx.ccx.tcx));
- ret @fold.respan[ast.expr_](expr.span,
- ast.expr_for_each(decl_1, seq_1,
+ auto ann = triv_ann(a, ty::mk_nil(fcx.ccx.tcx));
+ ret @fold::respan[ast::expr_](expr.span,
+ ast::expr_for_each(decl_1, seq_1,
body_1, ann));
}
- case (ast.expr_while(?cond, ?body, ?a)) {
+ case (ast::expr_while(?cond, ?body, ?a)) {
auto cond_0 = check_expr(fcx, cond);
- auto cond_1 = Pushdown.pushdown_expr(fcx, ty.mk_bool(fcx.ccx.tcx),
- cond_0);
+ auto cond_1 = Pushdown::pushdown_expr(fcx,
+ ty::mk_bool(fcx.ccx.tcx),
+ cond_0);
auto body_1 = check_block(fcx, body);
- auto ann = triv_ann(a, ty.mk_nil(fcx.ccx.tcx));
- ret @fold.respan[ast.expr_](expr.span,
- ast.expr_while(cond_1, body_1, ann));
+ auto ann = triv_ann(a, ty::mk_nil(fcx.ccx.tcx));
+ ret @fold::respan[ast::expr_](expr.span,
+ ast::expr_while(cond_1, body_1, ann));
}
- case (ast.expr_do_while(?body, ?cond, ?a)) {
+ case (ast::expr_do_while(?body, ?cond, ?a)) {
auto cond_0 = check_expr(fcx, cond);
- auto cond_1 = Pushdown.pushdown_expr(fcx, ty.mk_bool(fcx.ccx.tcx),
- cond_0);
+ auto cond_1 = Pushdown::pushdown_expr(fcx,
+ ty::mk_bool(fcx.ccx.tcx),
+ cond_0);
auto body_1 = check_block(fcx, body);
auto ann = triv_ann(a, block_ty(fcx.ccx.tcx, body_1));
- ret @fold.respan[ast.expr_](expr.span,
- ast.expr_do_while(body_1, cond_1,
+ ret @fold::respan[ast::expr_](expr.span,
+ ast::expr_do_while(body_1, cond_1,
ann));
}
- case (ast.expr_alt(?expr, ?arms, ?a)) {
+ case (ast::expr_alt(?expr, ?arms, ?a)) {
auto expr_0 = check_expr(fcx, expr);
// Typecheck the patterns first, so that we get types for all the
// bindings.
auto pattern_ty = expr_ty(fcx.ccx.tcx, expr_0);
- let vec[@ast.pat] pats_0 = vec();
- for (ast.arm arm in arms) {
+ let vec[@ast::pat] pats_0 = vec();
+ for (ast::arm arm in arms) {
auto pat_0 = check_pat(fcx, arm.pat);
- pattern_ty = Demand.simple(fcx, pat_0.span, pattern_ty,
+ pattern_ty = Demand::simple(fcx, pat_0.span, pattern_ty,
pat_ty(fcx.ccx.tcx, pat_0));
pats_0 += vec(pat_0);
}
- let vec[@ast.pat] pats_1 = vec();
- for (@ast.pat pat_0 in pats_0) {
- pats_1 += vec(Pushdown.pushdown_pat(fcx, pattern_ty, pat_0));
+ let vec[@ast::pat] pats_1 = vec();
+ for (@ast::pat pat_0 in pats_0) {
+ pats_1 += vec(Pushdown::pushdown_pat(fcx, pattern_ty, pat_0));
}
// Now typecheck the blocks.
auto result_ty = next_ty_var(fcx.ccx);
- let vec[ast.block] blocks_0 = vec();
- for (ast.arm arm in arms) {
+ let vec[ast::block] blocks_0 = vec();
+ for (ast::arm arm in arms) {
auto block_0 = check_block(fcx, arm.block);
- result_ty = Demand.simple(fcx, block_0.span, result_ty,
+ result_ty = Demand::simple(fcx, block_0.span, result_ty,
block_ty(fcx.ccx.tcx, block_0));
blocks_0 += vec(block_0);
}
- let vec[ast.arm] arms_1 = vec();
+ let vec[ast::arm] arms_1 = vec();
auto i = 0u;
- for (ast.block block_0 in blocks_0) {
- auto block_1 = Pushdown.pushdown_block(fcx, result_ty,
+ for (ast::block block_0 in blocks_0) {
+ auto block_1 = Pushdown::pushdown_block(fcx, result_ty,
block_0);
auto pat_1 = pats_1.(i);
auto arm = arms.(i);
i += 1u;
}
- auto expr_1 = Pushdown.pushdown_expr(fcx, pattern_ty, expr_0);
+ auto expr_1 = Pushdown::pushdown_expr(fcx, pattern_ty, expr_0);
auto ann = triv_ann(a, result_ty);
- ret @fold.respan[ast.expr_](expr.span,
- ast.expr_alt(expr_1, arms_1, ann));
+ ret @fold::respan[ast::expr_](expr.span,
+ ast::expr_alt(expr_1, arms_1, ann));
}
- case (ast.expr_block(?b, ?a)) {
+ case (ast::expr_block(?b, ?a)) {
auto b_0 = check_block(fcx, b);
auto ann;
alt (b_0.node.expr) {
- case (some[@ast.expr](?expr)) {
+ case (some[@ast::expr](?expr)) {
ann = triv_ann(a, expr_ty(fcx.ccx.tcx, expr));
}
- case (none[@ast.expr]) {
- ann = triv_ann(a, ty.mk_nil(fcx.ccx.tcx));
+ case (none[@ast::expr]) {
+ ann = triv_ann(a, ty::mk_nil(fcx.ccx.tcx));
}
}
- ret @fold.respan[ast.expr_](expr.span, ast.expr_block(b_0, ann));
+ ret @fold::respan(expr.span, ast::expr_block(b_0, ann));
}
- case (ast.expr_bind(?f, ?args, ?a)) {
+ case (ast::expr_bind(?f, ?args, ?a)) {
// Call the generic checker.
auto result = check_call_or_bind(fcx, f, args);
// Pull the argument and return types out.
auto proto_1;
- let vec[ty.arg] arg_tys_1 = vec();
+ let vec[ty::arg] arg_tys_1 = vec();
auto rt_1;
alt (struct(fcx.ccx.tcx, expr_ty(fcx.ccx.tcx, result._0))) {
- case (ty.ty_fn(?proto, ?arg_tys, ?rt)) {
+ case (ty::ty_fn(?proto, ?arg_tys, ?rt)) {
proto_1 = proto;
rt_1 = rt;
// For each blank argument, add the type of that argument
// to the resulting function type.
auto i = 0u;
- while (i < Vec.len[Option.t[@ast.expr]](args)) {
+ while (i < _vec::len[option::t[@ast::expr]](args)) {
alt (args.(i)) {
- case (some[@ast.expr](_)) { /* no-op */ }
- case (none[@ast.expr]) {
+ case (some[@ast::expr](_)) { /* no-op */ }
+ case (none[@ast::expr]) {
arg_tys_1 += vec(arg_tys.(i));
}
}
}
}
- auto t_1 = ty.mk_fn(fcx.ccx.tcx, proto_1, arg_tys_1, rt_1);
+ auto t_1 = ty::mk_fn(fcx.ccx.tcx, proto_1, arg_tys_1, rt_1);
auto ann = triv_ann(a, t_1);
- ret @fold.respan[ast.expr_](expr.span,
- ast.expr_bind(result._0, result._1,
+ ret @fold::respan[ast::expr_](expr.span,
+ ast::expr_bind(result._0, result._1,
ann));
}
- case (ast.expr_call(?f, ?args, ?a)) {
+ case (ast::expr_call(?f, ?args, ?a)) {
/* 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
auto args_1 = result._1;
// Pull the return type out of the type of the function.
- auto rt_1 = ty.mk_nil(fcx.ccx.tcx); // FIXME: typestate botch
+ auto rt_1 = ty::mk_nil(fcx.ccx.tcx); // FIXME: typestate botch
alt (struct(fcx.ccx.tcx, expr_ty(fcx.ccx.tcx, f_1))) {
- case (ty.ty_fn(_,_,?rt)) { rt_1 = rt; }
- case (ty.ty_native_fn(_, _, ?rt)) { rt_1 = rt; }
+ 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;
}
auto ann = triv_ann(a, rt_1);
- ret @fold.respan[ast.expr_](expr.span,
- ast.expr_call(f_1, args_1, ann));
+ ret @fold::respan[ast::expr_](expr.span,
+ ast::expr_call(f_1, args_1, ann));
}
- case (ast.expr_self_method(?id, ?a)) {
- auto t = ty.mk_nil(fcx.ccx.tcx);
- let ty.t this_obj_ty;
+ case (ast::expr_self_method(?id, ?a)) {
+ auto t = ty::mk_nil(fcx.ccx.tcx);
+ let ty::t this_obj_ty;
// Grab the type of the current object
auto this_obj_id = fcx.ccx.this_obj;
alt (this_obj_id) {
- case (some[ast.def_id](?def_id)) {
- this_obj_ty = ty.lookup_item_type(fcx.ccx.sess,
+ case (some[ast::def_id](?def_id)) {
+ this_obj_ty = ty::lookup_item_type(fcx.ccx.sess,
fcx.ccx.tcx, fcx.ccx.type_cache, def_id)._1;
}
case (_) { fail; }
// Grab this method's type out of the current object type
- // this_obj_ty is an ty.t
+ // this_obj_ty is an ty::t
alt (struct(fcx.ccx.tcx, this_obj_ty)) {
- case (ty.ty_obj(?methods)) {
- for (ty.method method in methods) {
+ case (ty::ty_obj(?methods)) {
+ for (ty::method method in methods) {
if (method.ident == id) {
- t = ty.method_ty_to_fn_ty(fcx.ccx.tcx,
+ t = ty::method_ty_to_fn_ty(fcx.ccx.tcx,
method);
}
}
require_impure(fcx.ccx.sess, fcx.purity, expr.span);
- ret @fold.respan[ast.expr_](expr.span,
- ast.expr_self_method(id, ann));
+ ret @fold::respan[ast::expr_](expr.span,
+ ast::expr_self_method(id, ann));
}
- case (ast.expr_spawn(?dom, ?name, ?f, ?args, ?a)) {
+ case (ast::expr_spawn(?dom, ?name, ?f, ?args, ?a)) {
auto result = check_call(fcx, f, args);
auto f_1 = result._0;
auto args_1 = result._1;
// Check the return type
alt (struct(fcx.ccx.tcx, expr_ty(fcx.ccx.tcx, f_1))) {
- case (ty.ty_fn(_,_,?rt)) {
+ case (ty::ty_fn(_,_,?rt)) {
alt (struct(fcx.ccx.tcx, rt)) {
- case (ty.ty_nil) {
+ case (ty::ty_nil) {
// This is acceptable
}
case (_) {
// FIXME: Other typechecks needed
- auto ann = triv_ann(a, ty.mk_task(fcx.ccx.tcx));
- ret @fold.respan[ast.expr_](expr.span,
- ast.expr_spawn(dom, name,
+ auto ann = triv_ann(a, ty::mk_task(fcx.ccx.tcx));
+ ret @fold::respan[ast::expr_](expr.span,
+ ast::expr_spawn(dom, name,
f_1, args_1, ann));
}
- case (ast.expr_cast(?e, ?t, ?a)) {
+ case (ast::expr_cast(?e, ?t, ?a)) {
auto e_1 = 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.
}
auto ann = triv_ann(a, t_1);
- ret @fold.respan[ast.expr_](expr.span,
- ast.expr_cast(e_1, t, ann));
+ ret @fold::respan[ast::expr_](expr.span,
+ ast::expr_cast(e_1, t, ann));
}
- case (ast.expr_vec(?args, ?mut, ?a)) {
- let vec[@ast.expr] args_1 = vec();
+ case (ast::expr_vec(?args, ?mut, ?a)) {
+ let vec[@ast::expr] args_1 = vec();
- let ty.t t;
- if (Vec.len[@ast.expr](args) == 0u) {
+ let ty::t t;
+ if (_vec::len[@ast::expr](args) == 0u) {
t = next_ty_var(fcx.ccx);
} else {
auto expr_1 = check_expr(fcx, args.(0));
t = expr_ty(fcx.ccx.tcx, expr_1);
}
- for (@ast.expr e in args) {
+ for (@ast::expr e in args) {
auto expr_1 = check_expr(fcx, e);
auto expr_t = expr_ty(fcx.ccx.tcx, expr_1);
- Demand.simple(fcx, expr.span, t, expr_t);
- Vec.push[@ast.expr](args_1,expr_1);
+ Demand::simple(fcx, expr.span, t, expr_t);
+ _vec::push[@ast::expr](args_1,expr_1);
}
- auto ann = triv_ann(a, ty.mk_vec(fcx.ccx.tcx,
+ auto ann = triv_ann(a, ty::mk_vec(fcx.ccx.tcx,
rec(ty=t, mut=mut)));
- ret @fold.respan[ast.expr_](expr.span,
- ast.expr_vec(args_1, mut, ann));
+ ret @fold::respan[ast::expr_](expr.span,
+ ast::expr_vec(args_1, mut, ann));
}
- case (ast.expr_tup(?elts, ?a)) {
- let vec[ast.elt] elts_1 = vec();
- let vec[ty.mt] elts_mt = vec();
+ case (ast::expr_tup(?elts, ?a)) {
+ let vec[ast::elt] elts_1 = vec();
+ let vec[ty::mt] elts_mt = vec();
- for (ast.elt e in elts) {
+ for (ast::elt e in elts) {
auto expr_1 = check_expr(fcx, e.expr);
auto expr_t = expr_ty(fcx.ccx.tcx, expr_1);
- Vec.push[ast.elt](elts_1, rec(expr=expr_1 with e));
+ _vec::push[ast::elt](elts_1, rec(expr=expr_1 with e));
elts_mt += vec(rec(ty=expr_t, mut=e.mut));
}
- auto ann = triv_ann(a, ty.mk_tup(fcx.ccx.tcx, elts_mt));
- ret @fold.respan[ast.expr_](expr.span,
- ast.expr_tup(elts_1, ann));
+ auto ann = triv_ann(a, ty::mk_tup(fcx.ccx.tcx, elts_mt));
+ ret @fold::respan[ast::expr_](expr.span,
+ ast::expr_tup(elts_1, ann));
}
- case (ast.expr_rec(?fields, ?base, ?a)) {
+ case (ast::expr_rec(?fields, ?base, ?a)) {
auto base_1;
alt (base) {
- case (none[@ast.expr]) { base_1 = none[@ast.expr]; }
- case (some[@ast.expr](?b_0)) {
- base_1 = some[@ast.expr](check_expr(fcx, b_0));
+ case (none[@ast::expr]) { base_1 = none[@ast::expr]; }
+ case (some[@ast::expr](?b_0)) {
+ base_1 = some[@ast::expr](check_expr(fcx, b_0));
}
}
- let vec[ast.field] fields_1 = vec();
+ let vec[ast::field] fields_1 = vec();
let vec[field] fields_t = vec();
- for (ast.field f in fields) {
+ for (ast::field f in fields) {
auto expr_1 = check_expr(fcx, f.expr);
auto expr_t = expr_ty(fcx.ccx.tcx, expr_1);
- Vec.push[ast.field](fields_1, rec(expr=expr_1 with f));
+ _vec::push[ast::field](fields_1, rec(expr=expr_1 with f));
auto expr_mt = rec(ty=expr_t, mut=f.mut);
- Vec.push[field](fields_t, rec(ident=f.ident, mt=expr_mt));
+ _vec::push[field](fields_t, rec(ident=f.ident, mt=expr_mt));
}
auto ann;
alt (base) {
- case (none[@ast.expr]) {
- ann = triv_ann(a, ty.mk_rec(fcx.ccx.tcx, fields_t));
+ case (none[@ast::expr]) {
+ ann = triv_ann(a, ty::mk_rec(fcx.ccx.tcx, fields_t));
}
- case (some[@ast.expr](?bexpr)) {
+ case (some[@ast::expr](?bexpr)) {
auto bexpr_1 = check_expr(fcx, bexpr);
auto bexpr_t = expr_ty(fcx.ccx.tcx, bexpr_1);
let vec[field] base_fields = vec();
alt (struct(fcx.ccx.tcx, bexpr_t)) {
- case (ty.ty_rec(?flds)) {
+ case (ty::ty_rec(?flds)) {
base_fields = flds;
}
case (_) {
ann = triv_ann(a, bexpr_t);
- for (ty.field f in fields_t) {
+ for (ty::field f in fields_t) {
auto found = false;
- for (ty.field bf in base_fields) {
- if (Str.eq(f.ident, bf.ident)) {
- Demand.simple(fcx, expr.span, f.mt.ty,
+ for (ty::field bf in base_fields) {
+ if (_str::eq(f.ident, bf.ident)) {
+ Demand::simple(fcx, expr.span, f.mt.ty,
bf.mt.ty);
found = true;
}
}
}
- ret @fold.respan[ast.expr_](expr.span,
- ast.expr_rec(fields_1, base_1, ann));
+ ret @fold::respan[ast::expr_](expr.span,
+ ast::expr_rec(fields_1, base_1, ann));
}
- case (ast.expr_field(?base, ?field, ?a)) {
+ case (ast::expr_field(?base, ?field, ?a)) {
auto base_1 = check_expr(fcx, base);
auto base_t = strip_boxes(fcx.ccx.tcx,
expr_ty(fcx.ccx.tcx, base_1));
alt (struct(fcx.ccx.tcx, base_t)) {
- case (ty.ty_tup(?args)) {
- let uint ix = ty.field_num(fcx.ccx.sess,
+ case (ty::ty_tup(?args)) {
+ let uint ix = ty::field_num(fcx.ccx.sess,
expr.span, field);
- if (ix >= Vec.len[ty.mt](args)) {
+ if (ix >= _vec::len[ty::mt](args)) {
fcx.ccx.sess.span_err(expr.span,
"bad index on tuple");
}
auto ann = triv_ann(a, args.(ix).ty);
- ret @fold.respan[ast.expr_](expr.span,
- ast.expr_field(base_1,
+ ret @fold::respan[ast::expr_](expr.span,
+ ast::expr_field(base_1,
field,
ann));
}
- case (ty.ty_rec(?fields)) {
- let uint ix = ty.field_idx(fcx.ccx.sess,
+ case (ty::ty_rec(?fields)) {
+ let uint ix = ty::field_idx(fcx.ccx.sess,
expr.span, field, fields);
- if (ix >= Vec.len[typeck.field](fields)) {
+ if (ix >= _vec::len[typeck::field](fields)) {
fcx.ccx.sess.span_err(expr.span,
"bad index on record");
}
auto ann = triv_ann(a, fields.(ix).mt.ty);
- ret @fold.respan[ast.expr_](expr.span,
- ast.expr_field(base_1,
+ ret @fold::respan[ast::expr_](expr.span,
+ ast::expr_field(base_1,
field,
ann));
}
- case (ty.ty_obj(?methods)) {
- let uint ix = ty.method_idx(fcx.ccx.sess,
+ case (ty::ty_obj(?methods)) {
+ let uint ix = ty::method_idx(fcx.ccx.sess,
expr.span, field, methods);
- if (ix >= Vec.len[typeck.method](methods)) {
+ if (ix >= _vec::len[typeck::method](methods)) {
fcx.ccx.sess.span_err(expr.span,
"bad index on obj");
}
auto meth = methods.(ix);
- auto t = ty.mk_fn(fcx.ccx.tcx, meth.proto,
+ auto t = ty::mk_fn(fcx.ccx.tcx, meth.proto,
meth.inputs, meth.output);
auto ann = triv_ann(a, t);
- ret @fold.respan[ast.expr_](expr.span,
- ast.expr_field(base_1,
+ ret @fold::respan[ast::expr_](expr.span,
+ ast::expr_field(base_1,
field,
ann));
}
case (_) {
fcx.ccx.sess.span_unimpl(expr.span,
- "base type for expr_field in typeck.check_expr: " +
+ "base type for expr_field in typeck::check_expr: " +
ty_to_str(fcx.ccx.tcx, base_t));
}
}
}
- case (ast.expr_index(?base, ?idx, ?a)) {
+ case (ast::expr_index(?base, ?idx, ?a)) {
auto base_1 = check_expr(fcx, base);
auto base_t = strip_boxes(fcx.ccx.tcx,
expr_ty(fcx.ccx.tcx, base_1));
auto idx_1 = check_expr(fcx, idx);
auto idx_t = expr_ty(fcx.ccx.tcx, idx_1);
alt (struct(fcx.ccx.tcx, base_t)) {
- case (ty.ty_vec(?mt)) {
+ case (ty::ty_vec(?mt)) {
if (! type_is_integral(fcx.ccx.tcx, idx_t)) {
fcx.ccx.sess.span_err
(idx.span,
+ ty_to_str(fcx.ccx.tcx, idx_t));
}
auto ann = triv_ann(a, mt.ty);
- ret @fold.respan[ast.expr_](expr.span,
- ast.expr_index(base_1,
+ ret @fold::respan[ast::expr_](expr.span,
+ ast::expr_index(base_1,
idx_1,
ann));
}
- case (ty.ty_str) {
+ case (ty::ty_str) {
if (! type_is_integral(fcx.ccx.tcx, idx_t)) {
fcx.ccx.sess.span_err
(idx.span,
"non-integral type of str index: "
+ ty_to_str(fcx.ccx.tcx, idx_t));
}
- auto ann = triv_ann(a, ty.mk_mach(fcx.ccx.tcx,
- common.ty_u8));
- ret @fold.respan[ast.expr_](expr.span,
- ast.expr_index(base_1,
+ auto ann = triv_ann(a, ty::mk_mach(fcx.ccx.tcx,
+ common::ty_u8));
+ ret @fold::respan[ast::expr_](expr.span,
+ ast::expr_index(base_1,
idx_1,
ann));
}
}
}
- case (ast.expr_port(?a)) {
+ case (ast::expr_port(?a)) {
auto t = next_ty_var(fcx.ccx);
- auto pt = ty.mk_port(fcx.ccx.tcx, t);
+ auto pt = ty::mk_port(fcx.ccx.tcx, t);
auto ann = triv_ann(a, pt);
- ret @fold.respan[ast.expr_](expr.span, ast.expr_port(ann));
+ ret @fold::respan[ast::expr_](expr.span, ast::expr_port(ann));
}
- case (ast.expr_chan(?x, ?a)) {
+ case (ast::expr_chan(?x, ?a)) {
auto expr_1 = check_expr(fcx, x);
auto port_t = expr_ty(fcx.ccx.tcx, expr_1);
alt (struct(fcx.ccx.tcx, port_t)) {
- case (ty.ty_port(?subtype)) {
- auto ct = ty.mk_chan(fcx.ccx.tcx, subtype);
+ case (ty::ty_port(?subtype)) {
+ auto ct = ty::mk_chan(fcx.ccx.tcx, subtype);
auto ann = triv_ann(a, ct);
- ret @fold.respan[ast.expr_](expr.span,
- ast.expr_chan(expr_1, ann));
+ ret @fold::respan[ast::expr_](expr.span,
+ ast::expr_chan(expr_1, ann));
}
case (_) {
fcx.ccx.sess.span_err(expr.span,
}
case (_) {
- fcx.ccx.sess.unimpl("expr type in typeck.check_expr");
+ fcx.ccx.sess.unimpl("expr type in typeck::check_expr");
// TODO
ret expr;
}
}
}
-fn next_ty_var(&@crate_ctxt ccx) -> ty.t {
- auto t = ty.mk_var(ccx.tcx, ccx.next_var_id);
+fn next_ty_var(&@crate_ctxt ccx) -> ty::t {
+ auto t = ty::mk_var(ccx.tcx, ccx.next_var_id);
ccx.next_var_id += 1;
ret t;
}
-fn check_decl_local(&@fn_ctxt fcx, &@ast.decl decl) -> @ast.decl {
+fn check_decl_local(&@fn_ctxt fcx, &@ast::decl decl) -> @ast::decl {
alt (decl.node) {
- case (ast.decl_local(?local)) {
+ case (ast::decl_local(?local)) {
auto t;
- t = ty.mk_nil(fcx.ccx.tcx);
+ t = ty::mk_nil(fcx.ccx.tcx);
alt (local.ty) {
- case (none[@ast.ty]) {
+ case (none[@ast::ty]) {
// Auto slot. Do nothing for now.
}
- case (some[@ast.ty](?ast_ty)) {
+ case (some[@ast::ty](?ast_ty)) {
auto local_ty = ast_ty_to_ty_crate(fcx.ccx, ast_ty);
fcx.locals.insert(local.id, local_ty);
t = local_ty;
auto initopt = local.init;
alt (local.init) {
- case (some[ast.initializer](?init)) {
+ case (some[ast::initializer](?init)) {
auto expr_0 = check_expr(fcx, init.expr);
- auto lty = ty.mk_local(fcx.ccx.tcx, local.id);
+ auto lty = ty::mk_local(fcx.ccx.tcx, local.id);
auto expr_1;
alt (init.op) {
- case (ast.init_assign) {
- expr_1 = Pushdown.pushdown_expr(fcx, lty, expr_0);
+ case (ast::init_assign) {
+ expr_1 = Pushdown::pushdown_expr(fcx, lty,
+ expr_0);
}
- case (ast.init_recv) {
- auto port_ty = ty.mk_port(fcx.ccx.tcx, lty);
- expr_1 = Pushdown.pushdown_expr(fcx, port_ty,
+ case (ast::init_recv) {
+ auto port_ty = ty::mk_port(fcx.ccx.tcx, lty);
+ expr_1 = Pushdown::pushdown_expr(fcx, port_ty,
expr_0);
}
}
auto init_0 = rec(expr = expr_1 with init);
- initopt = some[ast.initializer](init_0);
+ initopt = some[ast::initializer](init_0);
}
case (_) { /* fall through */ }
}
auto local_1 = @rec(init = initopt, ann = a_res with *local);
- ret @rec(node=ast.decl_local(local_1)
+ ret @rec(node=ast::decl_local(local_1)
with *decl);
}
}
}
-fn check_stmt(&@fn_ctxt fcx, &@ast.stmt stmt) -> @ast.stmt {
+fn check_stmt(&@fn_ctxt fcx, &@ast::stmt stmt) -> @ast::stmt {
alt (stmt.node) {
- case (ast.stmt_decl(?decl,?a)) {
+ case (ast::stmt_decl(?decl,?a)) {
alt (decl.node) {
- case (ast.decl_local(_)) {
+ case (ast::decl_local(_)) {
auto decl_1 = check_decl_local(fcx, decl);
- ret @fold.respan[ast.stmt_](stmt.span,
- ast.stmt_decl(decl_1,
+ ret @fold::respan[ast::stmt_](stmt.span,
+ ast::stmt_decl(decl_1,
plain_ann(a, fcx.ccx.tcx)));
}
- case (ast.decl_item(_)) {
+ case (ast::decl_item(_)) {
// Ignore for now. We'll return later.
- ret @fold.respan[ast.stmt_](stmt.span,
- ast.stmt_decl(decl,
+ ret @fold::respan[ast::stmt_](stmt.span,
+ ast::stmt_decl(decl,
plain_ann(a, fcx.ccx.tcx)));
}
}
// ret stmt;
}
- case (ast.stmt_expr(?expr,?a)) {
+ case (ast::stmt_expr(?expr,?a)) {
auto expr_t = check_expr(fcx, expr);
- expr_t = Pushdown.pushdown_expr(fcx, expr_ty(fcx.ccx.tcx, expr_t),
- expr_t);
- ret @fold.respan(stmt.span,
- ast.stmt_expr(expr_t, plain_ann(a, fcx.ccx.tcx)));
+ expr_t = Pushdown::pushdown_expr(fcx,
+ expr_ty(fcx.ccx.tcx, expr_t),
+ expr_t);
+ ret @fold::respan(stmt.span,
+ ast::stmt_expr(expr_t,
+ plain_ann(a, fcx.ccx.tcx)));
}
}
fail;
}
-fn check_block(&@fn_ctxt fcx, &ast.block block) -> ast.block {
- let vec[@ast.stmt] stmts = vec();
- for (@ast.stmt s in block.node.stmts) {
- Vec.push[@ast.stmt](stmts, check_stmt(fcx, s));
+fn check_block(&@fn_ctxt fcx, &ast::block block) -> ast::block {
+ let vec[@ast::stmt] stmts = vec();
+ for (@ast::stmt s in block.node.stmts) {
+ _vec::push[@ast::stmt](stmts, check_stmt(fcx, s));
}
- auto expr = none[@ast.expr];
+ auto expr = none[@ast::expr];
alt (block.node.expr) {
- case (none[@ast.expr]) { /* empty */ }
- case (some[@ast.expr](?e)) {
+ case (none[@ast::expr]) { /* empty */ }
+ case (some[@ast::expr](?e)) {
auto expr_t = check_expr(fcx, e);
- expr_t = Pushdown.pushdown_expr(fcx,
+ expr_t = Pushdown::pushdown_expr(fcx,
expr_ty(fcx.ccx.tcx, expr_t),
expr_t);
- expr = some[@ast.expr](expr_t);
+ expr = some[@ast::expr](expr_t);
}
}
- ret fold.respan(block.span,
+ ret fold::respan(block.span,
rec(stmts=stmts, expr=expr,
a=plain_ann(block.node.a, fcx.ccx.tcx)));
}
-fn check_const(&@crate_ctxt ccx, &span sp, &ast.ident ident, &@ast.ty t,
- &@ast.expr e, &ast.def_id id, &ast.ann ann) -> @ast.item {
+fn check_const(&@crate_ctxt ccx, &span sp, &ast::ident ident, &@ast::ty t,
+ &@ast::expr e, &ast::def_id id, &ast::ann ann) -> @ast::item {
// FIXME: this is kinda a kludge; we manufacture a fake "function context"
// for checking the initializer expression.
auto rty = ann_to_type(ann);
let @fn_ctxt fcx = @rec(ret_ty = rty,
- purity = ast.pure_fn,
- locals = @common.new_def_hash[ty.t](),
+ purity = ast::pure_fn,
+ locals = @common::new_def_hash[ty::t](),
ccx = ccx);
auto e_ = check_expr(fcx, e);
// FIXME: necessary? Correct sequence?
- Pushdown.pushdown_expr(fcx, rty, e_);
- auto item = ast.item_const(ident, t, e_, id, ann);
- ret @fold.respan[ast.item_](sp, item);
+ Pushdown::pushdown_expr(fcx, rty, e_);
+ auto item = ast::item_const(ident, t, e_, id, ann);
+ ret @fold::respan[ast::item_](sp, item);
}
-fn check_fn(&@crate_ctxt ccx, &ast.fn_decl decl, ast.proto proto,
- &ast.block body) -> ast._fn {
- auto local_ty_table = @common.new_def_hash[ty.t]();
+fn check_fn(&@crate_ctxt ccx, &ast::fn_decl decl, ast::proto proto,
+ &ast::block body) -> ast::_fn {
+ auto local_ty_table = @common::new_def_hash[ty::t]();
// FIXME: duplicate work: the item annotation already has the arg types
- // and return type translated to typeck.ty values. We don't need do to it
+ // and return type translated to typeck::ty values. We don't need do to it
// again here, we can extract them.
- for (ast.obj_field f in ccx.obj_fields) {
- auto field_ty = ty.ann_to_type(f.ann);
+ for (ast::obj_field f in ccx.obj_fields) {
+ auto field_ty = ty::ann_to_type(f.ann);
local_ty_table.insert(f.id, field_ty);
}
// Store the type of each argument in the table.
- for (ast.arg arg in decl.inputs) {
+ for (ast::arg arg in decl.inputs) {
auto input_ty = ast_ty_to_ty_crate(ccx, arg.ty);
local_ty_table.insert(arg.id, input_ty);
}
// TODO: Make sure the type of the block agrees with the function type.
auto block_t = check_block(fcx, body);
alt (decl.purity) {
- case (ast.pure_fn) {
+ case (ast::pure_fn) {
// per the previous comment, 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)) {
+ if (!ty::type_is_bool(ccx.tcx, fcx.ret_ty)) {
ccx.sess.span_err(body.span, "Non-boolean return type in pred");
}
}
ret fn_t;
}
-fn check_item_fn(&@crate_ctxt ccx, &span sp, &ast.ident ident, &ast._fn f,
- &vec[ast.ty_param] ty_params, &ast.def_id id,
- &ast.ann ann) -> @ast.item {
+fn check_item_fn(&@crate_ctxt ccx, &span sp, &ast::ident ident, &ast::_fn f,
+ &vec[ast::ty_param] ty_params, &ast::def_id id,
+ &ast::ann ann) -> @ast::item {
// FIXME: duplicate work: the item annotation already has the arg types
- // and return type translated to typeck.ty values. We don't need do to it
+ // and return type translated to typeck::ty values. We don't need do to it
// again here, we can extract them.
let vec[arg] inputs = vec();
- for (ast.arg arg in f.decl.inputs) {
+ for (ast::arg arg in f.decl.inputs) {
auto input_ty = ast_ty_to_ty_crate(ccx, arg.ty);
inputs += vec(rec(mode=ast_mode_to_mode(arg.mode), ty=input_ty));
}
auto output_ty = ast_ty_to_ty_crate(ccx, f.decl.output);
- auto fn_ann = triv_ann(ann, ty.mk_fn(ccx.tcx, f.proto, inputs,
+ auto fn_ann = triv_ann(ann, ty::mk_fn(ccx.tcx, f.proto, inputs,
output_ty));
- auto item = ast.item_fn(ident, f, ty_params, id, fn_ann);
- ret @fold.respan[ast.item_](sp, item);
+ auto item = ast::item_fn(ident, f, ty_params, id, fn_ann);
+ ret @fold::respan[ast::item_](sp, item);
}
-fn update_obj_fields(&@crate_ctxt ccx, &@ast.item i) -> @crate_ctxt {
+fn update_obj_fields(&@crate_ctxt ccx, &@ast::item i) -> @crate_ctxt {
alt (i.node) {
- case (ast.item_obj(_, ?ob, _, ?obj_def_ids, _)) {
- let ast.def_id di = obj_def_ids.ty;
+ case (ast::item_obj(_, ?ob, _, ?obj_def_ids, _)) {
+ let ast::def_id di = obj_def_ids.ty;
ret @rec(obj_fields = ob.fields,
- this_obj = some[ast.def_id](di) with *ccx);
+ this_obj = some[ast::def_id](di) with *ccx);
}
case (_) {
}
// Utilities for the unification cache
fn hash_unify_cache_entry(&unify_cache_entry uce) -> uint {
- auto h = ty.hash_ty(uce._0);
- h += h << 5u + ty.hash_ty(uce._1);
+ auto h = ty::hash_ty(uce._0);
+ h += h << 5u + ty::hash_ty(uce._1);
auto i = 0u;
- auto tys_len = Vec.len(uce._2);
+ auto tys_len = _vec::len(uce._2);
while (i < tys_len) {
- h += h << 5u + ty.hash_ty(uce._2.(i));
+ h += h << 5u + ty::hash_ty(uce._2.(i));
i += 1u;
}
}
fn eq_unify_cache_entry(&unify_cache_entry a, &unify_cache_entry b) -> bool {
- if (!ty.eq_ty(a._0, b._0) || !ty.eq_ty(a._1, b._1)) { ret false; }
+ if (!ty::eq_ty(a._0, b._0) || !ty::eq_ty(a._1, b._1)) { ret false; }
auto i = 0u;
- auto tys_len = Vec.len(a._2);
- if (Vec.len(b._2) != tys_len) { ret false; }
+ auto tys_len = _vec::len(a._2);
+ if (_vec::len(b._2) != tys_len) { ret false; }
while (i < tys_len) {
- if (!ty.eq_ty(a._2.(i), b._2.(i))) { ret false; }
+ if (!ty::eq_ty(a._2.(i), b._2.(i))) { ret false; }
i += 1u;
}
ret true;
}
-fn mk_fn_purity_table(&@ast.crate crate) -> @fn_purity_table {
- auto res = @new_def_hash[ast.purity]();
+fn mk_fn_purity_table(&@ast::crate crate) -> @fn_purity_table {
+ auto res = @new_def_hash[ast::purity]();
- fn do_one(@fn_purity_table t, &@ast.item i) -> () {
+ fn do_one(@fn_purity_table t, &@ast::item i) -> () {
alt (i.node) {
- case (ast.item_fn(_, ?f, _, ?d_id, _)) {
+ case (ast::item_fn(_, ?f, _, ?d_id, _)) {
t.insert(d_id, f.decl.purity);
}
case (_) {}
}
auto do_one_fn = bind do_one(res,_);
- auto v = walk.default_visitor();
+ auto v = walk::default_visitor();
auto add_fn_entry_visitor = rec(visit_item_post=do_one_fn with v);
- walk.walk_crate(add_fn_entry_visitor, *crate);
+ walk::walk_crate(add_fn_entry_visitor, *crate);
ret res;
}
-type typecheck_result = tup(@ast.crate, ty.type_cache);
+type typecheck_result = tup(@ast::crate, ty::type_cache);
-fn check_crate(&ty.ctxt tcx, &@ast.crate crate) -> typecheck_result {
+fn check_crate(&ty::ctxt tcx, &@ast::crate crate) -> typecheck_result {
auto sess = tcx.sess;
- auto result = Collect.collect_item_types(sess, tcx, crate);
+ auto result = Collect::collect_item_types(sess, tcx, crate);
- let vec[ast.obj_field] fields = vec();
+ let vec[ast::obj_field] fields = vec();
auto hasher = hash_unify_cache_entry;
auto eqer = eq_unify_cache_entry;
auto unify_cache =
- Map.mk_hashmap[unify_cache_entry,ty.Unify.result](hasher, eqer);
+ map::mk_hashmap[unify_cache_entry,ty::Unify::result](hasher, eqer);
auto fpt =
mk_fn_purity_table(crate); // use a variation on Collect
type_cache=result._1,
item_items=result._2,
obj_fields=fields,
- this_obj=none[ast.def_id],
+ this_obj=none[ast::def_id],
fn_purity_table = fpt,
mutable next_var_id=0,
unify_cache=unify_cache,
mutable cache_misses=0u,
tcx=tcx);
- auto fld = fold.new_identity_fold[@crate_ctxt]();
+ auto fld = fold::new_identity_fold[@crate_ctxt]();
fld = @rec(update_env_for_item = bind update_obj_fields(_, _),
fold_fn = bind check_fn(_,_,_,_),
fold_item_fn = bind check_item_fn(_,_,_,_,_,_,_)
with *fld);
- auto crate_1 = fold.fold_crate[@crate_ctxt](ccx, fld, result._0);
+ auto crate_1 = fold::fold_crate[@crate_ctxt](ccx, fld, result._0);
log #fmt("cache hit rate: %u/%u", ccx.cache_hits,
ccx.cache_hits + ccx.cache_misses);
-import front.ast;
-import front.ast.ann;
-import front.ast.method;
-import front.ast.ty;
-import front.ast.mutability;
-import front.ast.item;
-import front.ast.block;
-import front.ast.block_;
-import front.ast.obj_field;
-import front.ast.decl;
-import front.ast.arm;
-import front.ast.stmt;
-import front.ast.stmt_;
-import front.ast.stmt_decl;
-import front.ast.stmt_expr;
-import front.ast.stmt_crate_directive;
-import front.ast.decl_local;
-import front.ast.decl_item;
-import front.ast.ident;
-import front.ast.def_id;
-import front.ast.ann;
-import front.ast.field;
-import front.ast.expr;
-import front.ast.expr_call;
-import front.ast.expr_vec;
-import front.ast.expr_tup;
-import front.ast.expr_path;
-import front.ast.expr_field;
-import front.ast.expr_index;
-import front.ast.expr_log;
-import front.ast.expr_block;
-import front.ast.expr_rec;
-import front.ast.expr_if;
-import front.ast.expr_binary;
-import front.ast.expr_unary;
-import front.ast.expr_assign;
-import front.ast.expr_assign_op;
-import front.ast.expr_while;
-import front.ast.expr_do_while;
-import front.ast.expr_alt;
-import front.ast.expr_lit;
-import front.ast.expr_ret;
-import front.ast.expr_self_method;
-import front.ast.expr_bind;
-import front.ast.expr_spawn;
-import front.ast.expr_ext;
-import front.ast.expr_fail;
-import front.ast.expr_break;
-import front.ast.expr_cont;
-import front.ast.expr_send;
-import front.ast.expr_recv;
-import front.ast.expr_put;
-import front.ast.expr_port;
-import front.ast.expr_chan;
-import front.ast.expr_be;
-import front.ast.expr_check;
-import front.ast.expr_assert;
-import front.ast.expr_cast;
-import front.ast.expr_for;
-import front.ast.expr_for_each;
-import front.ast.path;
-import front.ast.elt;
-import front.ast.crate_directive;
-import front.ast.fn_decl;
-import front.ast._obj;
-import front.ast.native_mod;
-import front.ast.variant;
-import front.ast.ty_param;
-import front.ast.ty;
-import front.ast.proto;
-import front.ast.pat;
-import front.ast.binop;
-import front.ast.unop;
-import front.ast.def;
-import front.ast.lit;
-import front.ast.init_op;
-import front.ast.initializer;
-import front.ast.local;
-import front.ast._fn;
-import front.ast.ann_none;
-import front.ast.ann_type;
-import front.ast._obj;
-import front.ast._mod;
-import front.ast.crate;
-import front.ast.item_fn;
-import front.ast.item_obj;
-import front.ast.def_local;
-
-import middle.fold;
-import middle.fold.respan;
-import driver.session;
-import util.common;
-import util.common.span;
-import util.common.spanned;
-import util.common.new_str_hash;
-import util.common.new_def_hash;
-import util.common.uistr;
-import util.common.elt_exprs;
-import util.common.field_exprs;
-import util.common.log_expr;
-import util.common.log_expr_err;
-import util.common.log_stmt;
-import util.common.log_block;
-import util.common.log_stmt_err;
-import util.common.log_fn_err;
-import util.common.log_fn;
-import util.common.log_block_err;
-import util.common.has_nonlocal_exits;
-import util.common.decl_lhs;
-import util.typestate_ann;
-import util.typestate_ann.ts_ann;
-import util.typestate_ann.empty_pre_post;
-import util.typestate_ann.empty_poststate;
-import util.typestate_ann.true_precond;
-import util.typestate_ann.true_postcond;
-import util.typestate_ann.false_postcond;
-import util.typestate_ann.postcond;
-import util.typestate_ann.precond;
-import util.typestate_ann.poststate;
-import util.typestate_ann.prestate;
-import util.typestate_ann.pre_and_post;
-import util.typestate_ann.get_pre;
-import util.typestate_ann.get_post;
-import util.typestate_ann.ann_precond;
-import util.typestate_ann.ann_prestate;
-import util.typestate_ann.set_precondition;
-import util.typestate_ann.set_postcondition;
-import util.typestate_ann.set_prestate;
-import util.typestate_ann.set_poststate;
-import util.typestate_ann.set_in_postcond;
-import util.typestate_ann.set_in_poststate;
-import util.typestate_ann.implies;
-import util.typestate_ann.pre_and_post_state;
-import util.typestate_ann.empty_states;
-import util.typestate_ann.empty_prestate;
-import util.typestate_ann.empty_ann;
-import util.typestate_ann.extend_prestate;
-import util.typestate_ann.extend_poststate;
-import util.typestate_ann.relax_prestate;
-import util.typestate_ann.intersect;
-import util.typestate_ann.pp_clone;
-import util.typestate_ann.clone;
-
-import middle.ty;
-import middle.ty.ann_to_type;
-import middle.ty.arg;
-import middle.ty.expr_ann;
-import middle.ty.ty_to_str;
-
-import pretty.pprust.print_block;
-import pretty.pprust.print_expr;
-import pretty.pprust.print_decl;
-import pretty.pp.mkstate;
-import std.IO.stdout;
-import std.IO.str_writer;
-import std.IO.string_writer;
-import std.Vec.map;
-import std.Vec;
-import std.Vec.len;
-import std.Vec.pop;
-import std.Vec.push;
-import std.Vec.slice;
-import std.Vec.unzip;
-import std.Vec.plus_option;
-import std.Vec.cat_options;
-import std.Option;
-import std.Option.t;
-import std.Option.some;
-import std.Option.none;
-import std.Option.from_maybe;
-import std.Option.maybe;
-import std.Option.is_none;
-import std.Option.get;
-import std.Map.hashmap;
-import std.List;
-import std.List.list;
-import std.List.cons;
-import std.List.nil;
-import std.List.foldl;
-import std.List.find;
-import std.UInt;
-import std.BitV;
-import std.Util.fst;
-import std.Util.snd;
-
-import util.typestate_ann;
-import util.typestate_ann.difference;
-import util.typestate_ann.union;
-import util.typestate_ann.pps_len;
-import util.typestate_ann.require_and_preserve;
-
-import resolve.def_map;
+import front::ast;
+import front::ast::ann;
+import front::ast::method;
+import front::ast::ty;
+import front::ast::mutability;
+import front::ast::item;
+import front::ast::block;
+import front::ast::block_;
+import front::ast::obj_field;
+import front::ast::decl;
+import front::ast::arm;
+import front::ast::stmt;
+import front::ast::stmt_;
+import front::ast::stmt_decl;
+import front::ast::stmt_expr;
+import front::ast::stmt_crate_directive;
+import front::ast::decl_local;
+import front::ast::decl_item;
+import front::ast::ident;
+import front::ast::def_id;
+import front::ast::ann;
+import front::ast::field;
+import front::ast::expr;
+import front::ast::expr_call;
+import front::ast::expr_vec;
+import front::ast::expr_tup;
+import front::ast::expr_path;
+import front::ast::expr_field;
+import front::ast::expr_index;
+import front::ast::expr_log;
+import front::ast::expr_block;
+import front::ast::expr_rec;
+import front::ast::expr_if;
+import front::ast::expr_binary;
+import front::ast::expr_unary;
+import front::ast::expr_assign;
+import front::ast::expr_assign_op;
+import front::ast::expr_while;
+import front::ast::expr_do_while;
+import front::ast::expr_alt;
+import front::ast::expr_lit;
+import front::ast::expr_ret;
+import front::ast::expr_self_method;
+import front::ast::expr_bind;
+import front::ast::expr_spawn;
+import front::ast::expr_ext;
+import front::ast::expr_fail;
+import front::ast::expr_break;
+import front::ast::expr_cont;
+import front::ast::expr_send;
+import front::ast::expr_recv;
+import front::ast::expr_put;
+import front::ast::expr_port;
+import front::ast::expr_chan;
+import front::ast::expr_be;
+import front::ast::expr_check;
+import front::ast::expr_assert;
+import front::ast::expr_cast;
+import front::ast::expr_for;
+import front::ast::expr_for_each;
+import front::ast::path;
+import front::ast::elt;
+import front::ast::crate_directive;
+import front::ast::fn_decl;
+import front::ast::_obj;
+import front::ast::native_mod;
+import front::ast::variant;
+import front::ast::ty_param;
+import front::ast::ty;
+import front::ast::proto;
+import front::ast::pat;
+import front::ast::binop;
+import front::ast::unop;
+import front::ast::def;
+import front::ast::lit;
+import front::ast::init_op;
+import front::ast::initializer;
+import front::ast::local;
+import front::ast::_fn;
+import front::ast::ann_none;
+import front::ast::ann_type;
+import front::ast::_obj;
+import front::ast::_mod;
+import front::ast::crate;
+import front::ast::item_fn;
+import front::ast::item_obj;
+import front::ast::def_local;
+
+import middle::fold;
+import middle::fold::respan;
+import driver::session;
+import util::common;
+import util::common::span;
+import util::common::spanned;
+import util::common::new_str_hash;
+import util::common::new_def_hash;
+import util::common::uistr;
+import util::common::elt_exprs;
+import util::common::field_exprs;
+import util::common::log_expr;
+import util::common::log_expr_err;
+import util::common::log_stmt;
+import util::common::log_block;
+import util::common::log_stmt_err;
+import util::common::log_fn_err;
+import util::common::log_fn;
+import util::common::log_block_err;
+import util::common::has_nonlocal_exits;
+import util::common::decl_lhs;
+import util::typestate_ann;
+import util::typestate_ann::ts_ann;
+import util::typestate_ann::empty_pre_post;
+import util::typestate_ann::empty_poststate;
+import util::typestate_ann::true_precond;
+import util::typestate_ann::true_postcond;
+import util::typestate_ann::false_postcond;
+import util::typestate_ann::postcond;
+import util::typestate_ann::precond;
+import util::typestate_ann::poststate;
+import util::typestate_ann::prestate;
+import util::typestate_ann::pre_and_post;
+import util::typestate_ann::get_pre;
+import util::typestate_ann::get_post;
+import util::typestate_ann::ann_precond;
+import util::typestate_ann::ann_prestate;
+import util::typestate_ann::set_precondition;
+import util::typestate_ann::set_postcondition;
+import util::typestate_ann::set_prestate;
+import util::typestate_ann::set_poststate;
+import util::typestate_ann::set_in_postcond;
+import util::typestate_ann::set_in_poststate;
+import util::typestate_ann::implies;
+import util::typestate_ann::pre_and_post_state;
+import util::typestate_ann::empty_states;
+import util::typestate_ann::empty_prestate;
+import util::typestate_ann::empty_ann;
+import util::typestate_ann::extend_prestate;
+import util::typestate_ann::extend_poststate;
+import util::typestate_ann::relax_prestate;
+import util::typestate_ann::intersect;
+import util::typestate_ann::pp_clone;
+import util::typestate_ann::clone;
+
+import middle::ty;
+import middle::ty::ann_to_type;
+import middle::ty::arg;
+import middle::ty::expr_ann;
+import middle::ty::ty_to_str;
+
+import pretty::pprust::print_block;
+import pretty::pprust::print_expr;
+import pretty::pprust::print_decl;
+import pretty::pp::mkstate;
+import std::io::stdout;
+import std::io::str_writer;
+import std::io::string_writer;
+import std::_vec::map;
+import std::_vec;
+import std::_vec::len;
+import std::_vec::pop;
+import std::_vec::push;
+import std::_vec::slice;
+import std::_vec::unzip;
+import std::_vec::plus_option;
+import std::_vec::cat_options;
+import std::option;
+import std::option::t;
+import std::option::some;
+import std::option::none;
+import std::option::from_maybe;
+import std::option::maybe;
+import std::option::is_none;
+import std::option::get;
+import std::map::hashmap;
+import std::list;
+import std::list::list;
+import std::list::cons;
+import std::list::nil;
+import std::list::foldl;
+import std::list::find;
+import std::_uint;
+import std::bitv;
+import std::util::fst;
+import std::util::snd;
+
+import util::typestate_ann;
+import util::typestate_ann::difference;
+import util::typestate_ann::union;
+import util::typestate_ann::pps_len;
+import util::typestate_ann::require_and_preserve;
+
+import resolve::def_map;
/**** debugging junk ****/
-fn bitv_to_str(fn_info enclosing, BitV.t v) -> str {
+fn bitv_to_str(fn_info enclosing, bitv::t v) -> str {
auto s = "";
for each (@tup(def_id, tup(uint, ident)) p in enclosing.items()) {
- if (BitV.get(v, p._1._0)) {
+ if (bitv::get(v, p._1._0)) {
s += " " + p._1._1 + " ";
}
}
ret s;
}
-fn log_bitv(fn_info enclosing, BitV.t v) {
+fn log_bitv(fn_info enclosing, bitv::t v) {
log(bitv_to_str(enclosing, v));
}
-fn log_bitv_err(fn_info enclosing, BitV.t v) {
+fn log_bitv_err(fn_info enclosing, bitv::t v) {
log_err(bitv_to_str(enclosing, v));
}
}
fn log_pp(&pre_and_post pp) -> () {
- auto p1 = BitV.to_vec(pp.precondition);
- auto p2 = BitV.to_vec(pp.postcondition);
+ auto p1 = bitv::to_vec(pp.precondition);
+ auto p2 = bitv::to_vec(pp.postcondition);
log("pre:");
log_cond(p1);
log("post:");
}
fn log_pp_err(&pre_and_post pp) -> () {
- auto p1 = BitV.to_vec(pp.precondition);
- auto p2 = BitV.to_vec(pp.postcondition);
+ auto p1 = bitv::to_vec(pp.precondition);
+ auto p2 = bitv::to_vec(pp.postcondition);
log_err("pre:");
log_cond_err(p1);
log_err("post:");
}
fn log_states(&pre_and_post_state pp) -> () {
- auto p1 = BitV.to_vec(pp.prestate);
- auto p2 = BitV.to_vec(pp.poststate);
+ auto p1 = bitv::to_vec(pp.prestate);
+ auto p2 = bitv::to_vec(pp.poststate);
log("prestate:");
log_cond(p1);
log("poststate:");
}
fn log_states_err(&pre_and_post_state pp) -> () {
- auto p1 = BitV.to_vec(pp.prestate);
- auto p2 = BitV.to_vec(pp.poststate);
+ auto p1 = bitv::to_vec(pp.prestate);
+ auto p2 = bitv::to_vec(pp.poststate);
log_err("prestate:");
log_cond_err(p1);
log_err("poststate:");
variable in a given function) to bit number
(also remembers the ident for error-logging purposes) */
type var_info = tup(uint, ident);
-type fn_info = std.Map.hashmap[def_id, var_info];
+type fn_info = std::map::hashmap[def_id, var_info];
/* mapping from function name to fn_info map */
-type fn_info_map = std.Map.hashmap[def_id, fn_info];
+type fn_info_map = std::map::hashmap[def_id, fn_info];
fn bit_num(def_id v, fn_info m) -> uint {
assert (m.contains_key(v));
ret m.size();
}
-fn collect_local(&@vec[tup(ident, def_id)] vars, &span sp, &@ast.local loc)
+fn collect_local(&@vec[tup(ident, def_id)] vars, &span sp, &@ast::local loc)
-> @decl {
log("collect_local: pushing " + loc.ident);
- Vec.push[tup(ident, def_id)](*vars, tup(loc.ident, loc.id));
+ _vec::push[tup(ident, def_id)](*vars, tup(loc.ident, loc.id));
ret @respan(sp, decl_local(loc));
}
fn find_locals(_fn f) -> @vec[tup(ident,def_id)] {
- auto res = @Vec.alloc[tup(ident,def_id)](0u);
+ auto res = @_vec::alloc[tup(ident,def_id)](0u);
- auto fld = fold.new_identity_fold[@vec[tup(ident, def_id)]]();
+ auto fld = fold::new_identity_fold[@vec[tup(ident, def_id)]]();
fld = @rec(fold_decl_local = bind collect_local(_,_,_) with *fld);
- auto ignore = fold.fold_fn[@vec[tup(ident, def_id)]](res, fld, f);
+ auto ignore = fold::fold_fn[@vec[tup(ident, def_id)]](res, fld, f);
ret res;
}
fn add_var(def_id v, ident nm, uint next, fn_info tbl) -> uint {
- log(nm + " |-> " + util.common.uistr(next));
+ log(nm + " |-> " + util::common::uistr(next));
tbl.insert(v, tup(next,nm));
ret (next + 1u);
}
fn mk_fn_info(_fn f) -> fn_info {
auto res = new_def_hash[var_info]();
let uint next = 0u;
- let vec[ast.arg] f_args = f.decl.inputs;
+ let vec[ast::arg] f_args = f.decl.inputs;
/* ignore args, which we know are initialized;
just collect locally declared vars */
let @vec[tup(ident,def_id)] locals = find_locals(f);
- log(uistr(Vec.len[tup(ident, def_id)](*locals)) + " locals");
+ log(uistr(_vec::len[tup(ident, def_id)](*locals)) + " locals");
for (tup(ident,def_id) p in *locals) {
next = add_var(p._1, p._0, next, res);
}
/* extends mk_fn_info to a function item, side-effecting the map fi from
function IDs to fn_info maps */
-fn mk_fn_info_item_fn(&fn_info_map fi, &span sp, &ident i, &ast._fn f,
- &vec[ast.ty_param] ty_params, &def_id id, &ann a) -> @item {
+fn mk_fn_info_item_fn(&fn_info_map fi, &span sp, &ident i, &ast::_fn f,
+ &vec[ast::ty_param] ty_params, &def_id id, &ann a) -> @item {
fi.insert(id, mk_fn_info(f));
log(i + " has " + uistr(num_locals(mk_fn_info(f))) + " local vars");
ret @respan(sp, item_fn(i, f, ty_params, id, a));
/* extends mk_fn_info to an obj item, side-effecting the map fi from
function IDs to fn_info maps */
-fn mk_fn_info_item_obj(&fn_info_map fi, &span sp, &ident i, &ast._obj o,
- &vec[ast.ty_param] ty_params,
- &ast.obj_def_ids odid, &ann a) -> @item {
- auto all_methods = Vec.clone[@method](o.methods);
+fn mk_fn_info_item_obj(&fn_info_map fi, &span sp, &ident i, &ast::_obj o,
+ &vec[ast::ty_param] ty_params,
+ &ast::obj_def_ids odid, &ann a) -> @item {
+ auto all_methods = _vec::clone[@method](o.methods);
plus_option[@method](all_methods, o.dtor);
for (@method m in all_methods) {
fi.insert(m.node.id, mk_fn_info(m.node.meth));
/* 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(@ast.crate c) -> fn_info_map {
+fn mk_f_to_fn_info(@ast::crate c) -> fn_info_map {
auto res = new_def_hash[fn_info]();
- auto fld = fold.new_identity_fold[fn_info_map]();
+ auto fld = fold::new_identity_fold[fn_info_map]();
fld = @rec(fold_item_fn = bind mk_fn_info_item_fn(_,_,_,_,_,_,_),
fold_item_obj = bind mk_fn_info_item_obj(_,_,_,_,_,_,_)
with *fld);
- fold.fold_crate[fn_info_map](res, fld, c);
+ fold::fold_crate[fn_info_map](res, fld, c);
ret res;
}
}
}
-fn ann_to_ts_ann_fail(ann a) -> Option.t[@ts_ann] {
+fn ann_to_ts_ann_fail(ann a) -> option::t[@ts_ann] {
alt (a) {
case (ann_none(_)) {
log("ann_to_ts_ann_fail: didn't expect ann_none here");
ret (ann_to_ts_ann_fail_more(a)).states.poststate;
}
-fn stmt_to_ann(&stmt s) -> Option.t[@ts_ann] {
+fn stmt_to_ann(&stmt s) -> option::t[@ts_ann] {
alt (s.node) {
case (stmt_decl(_,?a)) {
ret ann_to_ts_ann_fail(a);
/* works on either postconds or preconds
should probably rethink the whole type synonym situation */
fn union_postconds_go(&postcond first, &vec[postcond] rest) -> postcond {
- auto sz = Vec.len[postcond](rest);
+ auto sz = _vec::len[postcond](rest);
if (sz > 0u) {
auto other = rest.(0);
fn union_postconds(uint nv, &vec[postcond] pcs) -> postcond {
if (len[postcond](pcs) > 0u) {
- ret union_postconds_go(BitV.clone(pcs.(0)), pcs);
+ ret union_postconds_go(bitv::clone(pcs.(0)), pcs);
}
else {
ret empty_prestate(nv);
/* Gee, maybe we could use foldl or something */
fn intersect_postconds_go(&postcond first, &vec[postcond] rest) -> postcond {
- auto sz = Vec.len[postcond](rest);
+ auto sz = _vec::len[postcond](rest);
if (sz > 0u) {
auto other = rest.(0);
fn intersect_postconds(&vec[postcond] pcs) -> postcond {
assert (len[postcond](pcs) > 0u);
- ret intersect_postconds_go(BitV.clone(pcs.(0)), pcs);
+ ret intersect_postconds_go(bitv::clone(pcs.(0)), pcs);
}
/******* AST-traversing code ********/
find_pre_post_fn(dm, fm, fm.get(m.node.id), m.node.meth);
}
auto f = bind do_a_method(dm, fm, _);
- Vec.map[@method, ()](f, o.methods);
- Option.map[@method, ()](f, o.dtor);
+ _vec::map[@method, ()](f, o.methods);
+ option::map[@method, ()](f, o.dtor);
}
fn find_pre_post_state_obj(&def_map dm, &fn_info_map fm, _obj o) -> bool {
ret find_pre_post_state_fn(dm, fm, fm.get(m.node.id), m.node.meth);
}
auto f = bind do_a_method(dm, fm, _);
- auto flags = Vec.map[@method, bool](f, o.methods);
- auto changed = Vec.or(flags);
+ auto flags = _vec::map[@method, bool](f, o.methods);
+ auto changed = _vec::or(flags);
changed = changed || maybe[@method, bool](false, f, o.dtor);
ret changed;
}
fn find_pre_post_item(&def_map dm, &fn_info_map fm, &fn_info enclosing,
&item i) -> () {
alt (i.node) {
- case (ast.item_const(?id, ?t, ?e, ?di, ?a)) {
+ case (ast::item_const(?id, ?t, ?e, ?di, ?a)) {
find_pre_post_expr(dm, fm, enclosing, e);
}
- case (ast.item_fn(?id, ?f, ?ps, ?di, ?a)) {
+ case (ast::item_fn(?id, ?f, ?ps, ?di, ?a)) {
assert (fm.contains_key(di));
find_pre_post_fn(dm, fm, fm.get(di), f);
}
- case (ast.item_mod(?id, ?m, ?di)) {
+ case (ast::item_mod(?id, ?m, ?di)) {
find_pre_post_mod(m);
}
- case (ast.item_native_mod(?id, ?nm, ?di)) {
+ case (ast::item_native_mod(?id, ?nm, ?di)) {
find_pre_post_native_mod(nm);
}
- case (ast.item_ty(_,_,_,_,_)) {
+ case (ast::item_ty(_,_,_,_,_)) {
ret;
}
- case (ast.item_tag(_,_,_,_,_)) {
+ case (ast::item_tag(_,_,_,_,_)) {
ret;
}
- case (ast.item_obj(?id, ?o, ?ps, ?di, ?a)) {
+ case (ast::item_obj(?id, ?o, ?ps, ?di, ?a)) {
find_pre_post_obj(dm, fm, o);
}
}
}
auto f = bind do_one(dm, fm, enclosing, _);
- Vec.map[@expr, ()](f, args);
+ _vec::map[@expr, ()](f, args);
fn get_pp(&@expr e) -> pre_and_post {
ret expr_pp(e);
}
auto g = get_pp;
- auto pps = Vec.map[@expr, pre_and_post](g, args);
+ auto pps = _vec::map[@expr, pre_and_post](g, args);
auto h = get_post;
set_pre_and_post(a,
rec(precondition=seq_preconds(enclosing, pps),
postcondition=union_postconds
- (nv, (Vec.map[pre_and_post, postcond](h, pps)))));
+ (nv, (_vec::map[pre_and_post, postcond](h, pps)))));
}
fn find_pre_post_loop(&def_map dm, &fn_info_map fm, &fn_info enclosing,
alt (e.node) {
case (expr_call(?operator, ?operands, ?a)) {
- auto args = Vec.clone[@expr](operands);
- Vec.push[@expr](args, operator);
+ auto args = _vec::clone[@expr](operands);
+ _vec::push[@expr](args, operator);
find_pre_post_exprs(dm, fm, enclosing, args, a);
}
case (expr_spawn(_, _, ?operator, ?operands, ?a)) {
- auto args = Vec.clone[@expr](operands);
- Vec.push[@expr](args, operator);
+ auto args = _vec::clone[@expr](operands);
+ _vec::push[@expr](args, operator);
find_pre_post_exprs(dm, fm, enclosing, args, a);
}
case (expr_vec(?args, _, ?a)) {
case (expr_path(?p, ?a)) {
auto res = empty_pre_post(num_local_vars);
- alt (dm.get(ast.ann_tag(a))) {
+ alt (dm.get(ast::ann_tag(a))) {
case (def_local(?d_id)) {
auto i = bit_num(d_id, enclosing);
require_and_preserve(i, res);
}
case (expr_rec(?fields,?maybe_base,?a)) {
auto es = field_exprs(fields);
- Vec.plus_option[@expr](es, maybe_base);
+ _vec::plus_option[@expr](es, maybe_base);
find_pre_post_exprs(dm, fm, enclosing, es, a);
}
case (expr_assign(?lhs, ?rhs, ?a)) {
alt (lhs.node) {
case (expr_path(?p, ?a_lhs)) {
- alt (dm.get(ast.ann_tag(a_lhs))) {
+ alt (dm.get(ast::ann_tag(a_lhs))) {
case (def_local(?d_id)) {
find_pre_post_expr(dm, fm, enclosing, rhs);
set_pre_and_post(a, expr_pp(rhs));
case (expr_recv(?lhs, ?rhs, ?a)) {
alt (lhs.node) {
case (expr_path(?p, ?a_lhs)) {
- alt (dm.get(ast.ann_tag(a_lhs))) {
+ alt (dm.get(ast::ann_tag(a_lhs))) {
case (def_local(?d_id)) {
find_pre_post_expr(dm, fm, enclosing, rhs);
set_pre_and_post(a, expr_pp(rhs));
ret block_pp(an_alt.block);
}
auto f = bind do_an_alt(dm, fm, enclosing, _);
- auto alt_pps = Vec.map[arm, pre_and_post](f, alts);
+ auto alt_pps = _vec::map[arm, pre_and_post](f, alts);
fn combine_pp(pre_and_post antec,
fn_info enclosing, &pre_and_post pp,
&pre_and_post next) -> pre_and_post {
postcondition=false_postcond(num_local_vars));
auto g = bind combine_pp(antec_pp, enclosing, _, _);
- auto alts_overall_pp = Vec.foldl[pre_and_post, pre_and_post]
+ auto alts_overall_pp = _vec::foldl[pre_and_post, pre_and_post]
(g, e_pp, alt_pps);
set_pre_and_post(a, alts_overall_pp);
set_pre_and_post(a, expr_pp(p));
}
case(expr_bind(?operator, ?maybe_args, ?a)) {
- auto args = Vec.cat_options[@expr](maybe_args);
- Vec.push[@expr](args, operator); /* ??? order of eval? */
+ auto args = _vec::cat_options[@expr](maybe_args);
+ _vec::push[@expr](args, operator); /* ??? order of eval? */
find_pre_post_exprs(dm, fm, enclosing, args, a);
}
case (expr_break(?a)) {
}
fn find_pre_post_stmt(&def_map dm, fn_info_map fm, &fn_info enclosing,
- &ast.stmt s) -> () {
+ &ast::stmt s) -> () {
log("stmt =");
log_stmt(s);
auto num_local_vars = num_locals(enclosing);
alt(s.node) {
- case(ast.stmt_decl(?adecl, ?a)) {
+ case(ast::stmt_decl(?adecl, ?a)) {
alt(adecl.node) {
- case(ast.decl_local(?alocal)) {
+ case(ast::decl_local(?alocal)) {
alt(alocal.init) {
- case(some[ast.initializer](?an_init)) {
+ case(some[ast::initializer](?an_init)) {
find_pre_post_expr(dm, fm, enclosing, an_init.expr);
auto rhs_pp = expr_pp(an_init.expr);
set_pre_and_post(alocal.ann, rhs_pp);
log_err("pp = ");
log_pp(stmt_pp(s)); */
}
- case(none[ast.initializer]) {
+ case(none[ast::initializer]) {
auto pp = empty_pre_post(num_local_vars);
set_pre_and_post(alocal.ann, pp);
set_pre_and_post(a, pp);
}
auto do_one = bind do_one_(dm, fm, enclosing, _);
- Vec.map[@stmt, ()](do_one, b.node.stmts);
+ _vec::map[@stmt, ()](do_one, b.node.stmts);
fn do_inner_(def_map dm, fn_info_map fm, fn_info i, &@expr e) -> () {
find_pre_post_expr(dm, fm, i, e);
}
auto do_inner = bind do_inner_(dm, fm, enclosing, _);
- Option.map[@expr, ()](do_inner, b.node.expr);
+ option::map[@expr, ()](do_inner, b.node.expr);
let vec[pre_and_post] pps = vec();
ret stmt_pp(*s);
}
auto f = get_pp_stmt;
- pps += Vec.map[@stmt, pre_and_post](f, b.node.stmts);
+ pps += _vec::map[@stmt, pre_and_post](f, b.node.stmts);
fn get_pp_expr(&@expr e) -> pre_and_post {
ret expr_pp(e);
}
auto g = get_pp_expr;
plus_option[pre_and_post](pps,
- Option.map[@expr, pre_and_post](g, b.node.expr));
+ option::map[@expr, pre_and_post](g, b.node.expr));
auto block_precond = seq_preconds(enclosing, pps);
auto h = get_post;
- auto postconds = Vec.map[pre_and_post, postcond](h, pps);
+ auto postconds = _vec::map[pre_and_post, postcond](h, pps);
/* A block may be empty, so this next line ensures that the postconds
vector is non-empty. */
- Vec.push[postcond](postconds, block_precond);
+ _vec::push[postcond](postconds, block_precond);
auto block_postcond = empty_poststate(nv);
/* conservative approximation */
if (! has_nonlocal_exits(b)) {
find_pre_post_block(dm, fm, fi, f.body);
}
-fn check_item_fn(&def_map dm, &fn_info_map fm, &span sp, &ident i, &ast._fn f,
- &vec[ast.ty_param] ty_params,
+fn check_item_fn(&def_map dm, &fn_info_map fm, &span sp, &ident i,
+ &ast::_fn f, &vec[ast::ty_param] ty_params,
&def_id id, &ann a) -> @item {
log("check_item_fn:");
assert (fm.contains_key(id));
find_pre_post_fn(dm, fm, fm.get(id), f);
- ret @respan(sp, ast.item_fn(i, f, ty_params, id, a));
+ ret @respan(sp, ast::item_fn(i, f, ty_params, id, a));
}
fn find_pre_post_state_item(&def_map dm, &fn_info_map fm, &fn_info enclosing,
@item i) -> bool {
alt (i.node) {
- case (ast.item_const(?id, ?t, ?e, ?di, ?a)) {
+ case (ast::item_const(?id, ?t, ?e, ?di, ?a)) {
ret find_pre_post_state_expr(dm, fm, enclosing,
empty_prestate(num_locals(enclosing)), e);
}
- case (ast.item_fn(?id, ?f, ?ps, ?di, ?a)) {
+ case (ast::item_fn(?id, ?f, ?ps, ?di, ?a)) {
assert (fm.contains_key(di));
ret find_pre_post_state_fn(dm, fm, fm.get(di), f);
}
- case (ast.item_mod(?id, ?m, ?di)) {
+ case (ast::item_mod(?id, ?m, ?di)) {
ret find_pre_post_state_mod(m);
}
- case (ast.item_native_mod(?id, ?nm, ?di)) {
+ case (ast::item_native_mod(?id, ?nm, ?di)) {
ret find_pre_post_state_native_mod(nm);
}
- case (ast.item_ty(_,_,_,_,_)) {
+ case (ast::item_ty(_,_,_,_,_)) {
ret false;
}
- case (ast.item_tag(_,_,_,_,_)) {
+ case (ast::item_tag(_,_,_,_,_)) {
ret false;
}
- case (ast.item_obj(?id, ?o, ?ps, ?di, ?a)) {
+ case (ast::item_obj(?id, ?o, ?ps, ?di, ?a)) {
ret find_pre_post_state_obj(dm, fm, o);
}
}
alt (lhs.node) {
case (expr_path(_, ?a_lhs)) {
- alt (dm.get(ast.ann_tag(a_lhs))) {
+ alt (dm.get(ast::ann_tag(a_lhs))) {
case (def_local(?d_id)) {
// assignment to local var
changed = pure_exp(a_lhs, pres) || changed;
alt (lhs.node) {
case (expr_path(?p, ?a_lhs)) {
- alt (dm.get(ast.ann_tag(a_lhs))) {
+ alt (dm.get(ast::ann_tag(a_lhs))) {
case (def_local(?d_id)) {
// receive to local var
changed = pure_exp(a_lhs, pres) || changed;
|| changed;
auto e_post = expr_poststate(e);
auto a_post;
- if (Vec.len[arm](alts) > 0u) {
+ if (_vec::len[arm](alts) > 0u) {
a_post = false_postcond(num_local_vars);
for (arm an_alt in alts) {
changed = find_pre_post_state_block(dm, fm, enclosing, e_post,
log("*At beginning: stmt = ");
log_stmt(*s);
log("*prestate = ");
- log(BitV.to_str(stmt_ann.states.prestate));
+ log(bitv::to_str(stmt_ann.states.prestate));
log("*poststate =");
- log(BitV.to_str(stmt_ann.states.poststate));
+ log(bitv::to_str(stmt_ann.states.poststate));
log("*changed =");
log(changed);
alt (s.node) {
case (stmt_decl(?adecl, ?a)) {
alt (adecl.node) {
- case (ast.decl_local(?alocal)) {
+ case (ast::decl_local(?alocal)) {
alt (alocal.init) {
- case (some[ast.initializer](?an_init)) {
+ case (some[ast::initializer](?an_init)) {
changed = extend_prestate(stmt_ann.states.prestate, pres)
|| changed;
changed = find_pre_post_state_expr
log("Summary: stmt = ");
log_stmt(*s);
log("prestate = ");
- log(BitV.to_str(stmt_ann.states.prestate));
+ log(bitv::to_str(stmt_ann.states.prestate));
log_bitv(enclosing, stmt_ann.states.prestate);
log("poststate =");
log_bitv(enclosing, stmt_ann.states.poststate);
ret changed;
}
- case (none[ast.initializer]) {
+ case (none[ast::initializer]) {
changed = extend_prestate(stmt_ann.states.prestate, pres)
|| changed;
changed = extend_poststate(stmt_ann.states.poststate, pres)
}
}
}
- case (ast.decl_item(?an_item)) {
+ case (ast::decl_item(?an_item)) {
changed = extend_prestate(stmt_ann.states.prestate, pres)
|| changed;
changed = extend_poststate(stmt_ann.states.poststate, pres)
log("Summary: stmt = ");
log_stmt(*s);
log("prestate = ");
- log(BitV.to_str(stmt_ann.states.prestate));
+ log(bitv::to_str(stmt_ann.states.prestate));
log_bitv(enclosing, stmt_ann.states.prestate);
log("poststate =");
- log(BitV.to_str(stmt_ann.states.poststate));
+ log(bitv::to_str(stmt_ann.states.poststate));
log_bitv(enclosing, stmt_ann.states.poststate);
log("changed =");
log(changed);
}
fn find_pre_post_state_fn(&def_map dm, &fn_info_map f_info, &fn_info fi,
- &ast._fn f) -> bool {
+ &ast::_fn f) -> bool {
/* FIXME: where do we set args as being initialized?
What about for methods? */
auto num_local_vars = num_locals(fi);
}
}
-fn check_states_against_conditions(fn_info enclosing, &ast._fn f) -> () {
+fn check_states_against_conditions(fn_info enclosing, &ast::_fn f) -> () {
fn do_one_(fn_info i, &@stmt s) -> () {
check_states_stmt(i, *s);
}
auto do_one = bind do_one_(enclosing, _);
- Vec.map[@stmt, ()](do_one, f.body.node.stmts);
+ _vec::map[@stmt, ()](do_one, f.body.node.stmts);
fn do_inner_(fn_info i, &@expr e) -> () {
check_states_expr(i, e);
}
auto do_inner = bind do_inner_(enclosing, _);
- Option.map[@expr, ()](do_inner, f.body.node.expr);
+ option::map[@expr, ()](do_inner, f.body.node.expr);
}
fn check_fn_states(&def_map dm, &fn_info_map f_info_map, &fn_info f_info,
- &ast._fn f) -> () {
+ &ast::_fn f) -> () {
/* Compute the pre- and post-states for this function */
// (Fixpoint iteration)
while (find_pre_post_state_fn(dm, f_info_map, f_info, f)) {}
}
fn check_item_fn_state(def_map dm, &fn_info_map f_info_map, &span sp,
- &ident i, &ast._fn f, &vec[ast.ty_param] ty_params,
+ &ident i, &ast::_fn f, &vec[ast::ty_param] ty_params,
&def_id id, &ann a) -> @item {
/* Look up the var-to-bit-num map for this function */
check_fn_states(dm, f_info_map, f_info, f);
/* Rebuild the same function */
- ret @respan(sp, ast.item_fn(i, f, ty_params, id, a));
+ ret @respan(sp, ast::item_fn(i, f, ty_params, id, a));
}
fn check_method_states(&def_map dm, &fn_info_map f_info_map, @method m) {
fn check_obj_state(def_map dm, &fn_info_map f_info_map,
&vec[obj_field] fields, &vec[@method] methods,
- &Option.t[@method] dtor) -> ast._obj {
+ &option::t[@method] dtor) -> ast::_obj {
fn one(def_map dm, fn_info_map fm, &@method m) -> () {
ret check_method_states(dm, fm, m);
}
auto f = bind one(dm, f_info_map,_);
- Vec.map[@method, ()](f, methods);
- Option.map[@method, ()](f, dtor);
+ _vec::map[@method, ()](f, methods);
+ option::map[@method, ()](f, dtor);
ret rec(fields=fields, methods=methods, dtor=dtor);
}
fail;
}
case (ann_type(_, ?t,?ps,_)) {
- auto fld0 = fold.new_identity_fold[fn_info]();
+ auto fld0 = fold::new_identity_fold[fn_info]();
fld0 = @rec(fold_ann = bind init_ann(_,_) with *fld0);
- ret fold.fold_block[fn_info](fi, fld0, respan(sp, b));
+ ret fold::fold_block[fn_info](fi, fld0, respan(sp, b));
}
}
}
-fn item_fn_anns(&fn_info_map fm, &span sp, ident i, &ast._fn f,
- vec[ast.ty_param] ty_params, def_id id, ann a) -> @item {
+fn item_fn_anns(&fn_info_map fm, &span sp, ident i, &ast::_fn f,
+ vec[ast::ty_param] ty_params, def_id id, ann a) -> @item {
assert (fm.contains_key(id));
auto f_info = fm.get(id);
log(i + " has " + uistr(num_locals(f_info)) + " local vars");
- auto fld0 = fold.new_identity_fold[fn_info]();
+ auto fld0 = fold::new_identity_fold[fn_info]();
fld0 = @rec(fold_ann = bind init_ann(_,_)
with *fld0);
- ret fold.fold_item[fn_info]
+ ret fold::fold_item[fn_info]
(f_info, fld0, @respan(sp, item_fn(i, f, ty_params, id, a)));
}
/* This is painstakingly written as an explicit recursion b/c the
- standard ast.fold doesn't traverse in the correct order:
+ standard ast::fold doesn't traverse in the correct order:
consider
fn foo() {
fn bar() {
ret annotate_expr(fm, e);
}
auto f = bind one(fm,_);
- ret Vec.map[@expr, @expr](f, es);
+ ret _vec::map[@expr, @expr](f, es);
}
fn annotate_elts(&fn_info_map fm, &vec[elt] es) -> vec[elt] {
fn one(fn_info_map fm, &elt e) -> elt {
expr=annotate_expr(fm, e.expr));
}
auto f = bind one(fm,_);
- ret Vec.map[elt, elt](f, es);
+ ret _vec::map[elt, elt](f, es);
}
fn annotate_fields(&fn_info_map fm, &vec[field] fs) -> vec[field] {
fn one(fn_info_map fm, &field f) -> field {
expr=annotate_expr(fm, f.expr));
}
auto f = bind one(fm,_);
- ret Vec.map[field, field](f, fs);
+ ret _vec::map[field, field](f, fs);
}
-fn annotate_option_exp(&fn_info_map fm, &Option.t[@expr] o)
- -> Option.t[@expr] {
+fn annotate_option_exp(&fn_info_map fm, &option::t[@expr] o)
+ -> option::t[@expr] {
fn one(fn_info_map fm, &@expr e) -> @expr {
ret annotate_expr(fm, e);
}
auto f = bind one(fm,_);
- ret Option.map[@expr, @expr](f, o);
+ ret option::map[@expr, @expr](f, o);
}
-fn annotate_option_exprs(&fn_info_map fm, &vec[Option.t[@expr]] es)
- -> vec[Option.t[@expr]] {
- fn one(fn_info_map fm, &Option.t[@expr] o) -> Option.t[@expr] {
+fn annotate_option_exprs(&fn_info_map fm, &vec[option::t[@expr]] es)
+ -> vec[option::t[@expr]] {
+ fn one(fn_info_map fm, &option::t[@expr] o) -> option::t[@expr] {
ret annotate_option_exp(fm, o);
}
auto f = bind one(fm,_);
- ret Vec.map[Option.t[@expr], Option.t[@expr]](f, es);
+ ret _vec::map[option::t[@expr], option::t[@expr]](f, es);
}
fn annotate_decl(&fn_info_map fm, &@decl d) -> @decl {
auto d1 = d.node;
case (decl_local(?l)) {
alt(l.init) {
case (some[initializer](?init)) {
- let Option.t[initializer] an_i =
+ let option::t[initializer] an_i =
some[initializer]
(rec(expr=annotate_expr(fm, init.expr)
with init));
block=annotate_block(fm, a.block));
}
auto f = bind one(fm,_);
- ret Vec.map[arm, arm](f, alts);
+ ret _vec::map[arm, arm](f, alts);
}
fn annotate_expr(&fn_info_map fm, &@expr e) -> @expr {
for (@stmt s in b.node.stmts) {
auto new_s = annotate_stmt(fm, s);
- Vec.push[@stmt](new_stmts, new_s);
+ _vec::push[@stmt](new_stmts, new_s);
}
fn ann_e(fn_info_map fm, &@expr e) -> @expr {
ret annotate_expr(fm, e);
}
auto f = bind ann_e(fm,_);
- auto new_e = Option.map[@expr, @expr](f, b.node.expr);
+ auto new_e = option::map[@expr, @expr](f, b.node.expr);
ret respan(b.span,
rec(stmts=new_stmts, expr=new_e with b.node));
}
-fn annotate_fn(&fn_info_map fm, &ast._fn f) -> ast._fn {
+fn annotate_fn(&fn_info_map fm, &ast::_fn f) -> ast::_fn {
// subexps have *already* been annotated based on
// f's number-of-locals
ret rec(body=annotate_block(fm, f.body) with f);
}
-fn annotate_mod(&fn_info_map fm, &ast._mod m) -> ast._mod {
+fn annotate_mod(&fn_info_map fm, &ast::_mod m) -> ast::_mod {
let vec[@item] new_items = vec();
for (@item i in m.items) {
auto new_i = annotate_item(fm, i);
- Vec.push[@item](new_items, new_i);
+ _vec::push[@item](new_items, new_i);
}
ret rec(items=new_items with m);
}
fn annotate_method(&fn_info_map fm, &@method m) -> @method {
auto f_info = get_fn_info(fm, m.node.id);
- auto fld0 = fold.new_identity_fold[fn_info]();
+ auto fld0 = fold::new_identity_fold[fn_info]();
fld0 = @rec(fold_ann = bind init_ann(_,_)
with *fld0);
- auto outer = fold.fold_method[fn_info](f_info, fld0, m);
+ auto outer = fold::fold_method[fn_info](f_info, fld0, m);
auto new_fn = annotate_fn(fm, outer.node.meth);
ret @respan(m.span,
rec(meth=new_fn with m.node));
}
-fn annotate_obj(&fn_info_map fm, &ast._obj o) -> ast._obj {
+fn annotate_obj(&fn_info_map fm, &ast::_obj o) -> ast::_obj {
fn one(fn_info_map fm, &@method m) -> @method {
ret annotate_method(fm, m);
}
auto f = bind one(fm,_);
- auto new_methods = Vec.map[@method, @method](f, o.methods);
- auto new_dtor = Option.map[@method, @method](f, o.dtor);
+ auto new_methods = _vec::map[@method, @method](f, o.methods);
+ auto new_dtor = option::map[@method, @method](f, o.dtor);
ret rec(methods=new_methods, dtor=new_dtor with o);
}
// Only annotates the components of the item recursively.
-fn annotate_item_inner(&fn_info_map fm, &@ast.item item) -> @ast.item {
+fn annotate_item_inner(&fn_info_map fm, &@ast::item item) -> @ast::item {
alt (item.node) {
/* FIXME can't skip this case -- exprs contain blocks contain stmts,
which contain decls */
- case (ast.item_const(_,_,_,_,_)) {
+ case (ast::item_const(_,_,_,_,_)) {
// this has already been annotated by annotate_item
ret item;
}
- case (ast.item_fn(?ident, ?ff, ?tps, ?id, ?ann)) {
+ case (ast::item_fn(?ident, ?ff, ?tps, ?id, ?ann)) {
ret @respan(item.span,
- ast.item_fn(ident, annotate_fn(fm, ff), tps, id, ann));
+ ast::item_fn(ident, annotate_fn(fm, ff),
+ tps, id, ann));
}
- case (ast.item_mod(?ident, ?mm, ?id)) {
+ case (ast::item_mod(?ident, ?mm, ?id)) {
ret @respan(item.span,
- ast.item_mod(ident, annotate_mod(fm, mm), id));
+ ast::item_mod(ident, annotate_mod(fm, mm), id));
}
- case (ast.item_native_mod(?ident, ?mm, ?id)) {
+ case (ast::item_native_mod(?ident, ?mm, ?id)) {
ret item;
}
- case (ast.item_ty(_,_,_,_,_)) {
+ case (ast::item_ty(_,_,_,_,_)) {
ret item;
}
- case (ast.item_tag(_,_,_,_,_)) {
+ case (ast::item_tag(_,_,_,_,_)) {
ret item;
}
- case (ast.item_obj(?ident, ?ob, ?tps, ?odid, ?ann)) {
+ case (ast::item_obj(?ident, ?ob, ?tps, ?odid, ?ann)) {
ret @respan(item.span,
- ast.item_obj(ident, annotate_obj(fm, ob), tps, odid, ann));
+ ast::item_obj(ident, annotate_obj(fm, ob), tps, odid, ann));
}
}
}
-fn annotate_item(&fn_info_map fm, &@ast.item item) -> @ast.item {
+fn annotate_item(&fn_info_map fm, &@ast::item item) -> @ast::item {
// Using a fold, recursively set all anns in this item
// to be blank.
// *Then*, call annotate_item recursively to do the right
// thing for any nested items inside this one.
alt (item.node) {
- case (ast.item_const(_,_,_,_,_)) {
- auto fld0 = fold.new_identity_fold[()]();
+ case (ast::item_const(_,_,_,_,_)) {
+ auto fld0 = fold::new_identity_fold[()]();
fld0 = @rec(fold_ann = bind init_blank_ann(_,_)
with *fld0);
- ret fold.fold_item[()]((), fld0, item);
+ ret fold::fold_item[()]((), fld0, item);
}
- case (ast.item_fn(?i,?ff,?tps,?id,?ann)) {
+ case (ast::item_fn(?i,?ff,?tps,?id,?ann)) {
auto f_info = get_fn_info(fm, id);
- auto fld0 = fold.new_identity_fold[fn_info]();
+ auto fld0 = fold::new_identity_fold[fn_info]();
fld0 = @rec(fold_ann = bind init_ann(_,_)
with *fld0);
- auto outer = fold.fold_item[fn_info](f_info, fld0, item);
+ auto outer = fold::fold_item[fn_info](f_info, fld0, item);
// now recurse into any nested items
ret annotate_item_inner(fm, outer);
}
- case (ast.item_mod(?i, ?mm, ?id)) {
- auto fld0 = fold.new_identity_fold[()]();
+ case (ast::item_mod(?i, ?mm, ?id)) {
+ auto fld0 = fold::new_identity_fold[()]();
fld0 = @rec(fold_ann = bind init_blank_ann(_,_)
with *fld0);
- auto outer = fold.fold_item[()]((), fld0, item);
+ auto outer = fold::fold_item[()]((), fld0, item);
ret annotate_item_inner(fm, outer);
}
- case (ast.item_native_mod(?i, ?nm, ?id)) {
+ case (ast::item_native_mod(?i, ?nm, ?id)) {
ret item;
}
- case (ast.item_ty(_,_,_,_,_)) {
+ case (ast::item_ty(_,_,_,_,_)) {
ret item;
}
- case (ast.item_tag(_,_,_,_,_)) {
+ case (ast::item_tag(_,_,_,_,_)) {
ret item;
}
- case (ast.item_obj(?i,?ob,?tps,?odid,?ann)) {
- auto fld0 = fold.new_identity_fold[()]();
+ case (ast::item_obj(?i,?ob,?tps,?odid,?ann)) {
+ auto fld0 = fold::new_identity_fold[()]();
fld0 = @rec(fold_ann = bind init_blank_ann(_,_)
with *fld0);
- auto outer = fold.fold_item[()]((), fld0, item);
+ auto outer = fold::fold_item[()]((), fld0, item);
ret annotate_item_inner(fm, outer);
}
}
}
-fn annotate_module(&fn_info_map fm, &ast._mod module) -> ast._mod {
+fn annotate_module(&fn_info_map fm, &ast::_mod module) -> ast::_mod {
let vec[@item] new_items = vec();
for (@item i in module.items) {
auto new_item = annotate_item(fm, i);
- Vec.push[@item](new_items, new_item);
+ _vec::push[@item](new_items, new_item);
}
ret rec(items = new_items with module);
}
-fn annotate_crate(&fn_info_map fm, &@ast.crate crate) -> @ast.crate {
+fn annotate_crate(&fn_info_map fm, &@ast::crate crate) -> @ast::crate {
ret @respan(crate.span,
rec(module = annotate_module(fm, crate.node.module)
with crate.node));
}
-fn check_crate(@ast.crate crate, def_map dm) -> @ast.crate {
+fn check_crate(@ast::crate crate, def_map dm) -> @ast::crate {
/* Build the global map from function id to var-to-bit-num-map */
auto fm = mk_f_to_fn_info(crate);
auto with_anns = annotate_crate(fm, crate);
/* Compute the pre and postcondition for every subexpression */
- auto fld = fold.new_identity_fold[fn_info_map]();
+ auto fld = fold::new_identity_fold[fn_info_map]();
fld = @rec(fold_item_fn = bind check_item_fn(dm,_,_,_,_,_,_,_) with *fld);
- auto with_pre_postconditions = fold.fold_crate[fn_info_map]
+ auto with_pre_postconditions = fold::fold_crate[fn_info_map]
(fm, fld, with_anns);
- auto fld1 = fold.new_identity_fold[fn_info_map]();
+ auto fld1 = fold::new_identity_fold[fn_info_map]();
fld1 = @rec(fold_item_fn = bind check_item_fn_state(dm,_,_,_,_,_,_,_),
fold_obj = bind check_obj_state(dm,_,_,_,_)
with *fld1);
- ret fold.fold_crate[fn_info_map](fm, fld1,
+ ret fold::fold_crate[fn_info_map](fm, fld1,
with_pre_postconditions);
}
-import front.ast;
+import front::ast;
-import std.Option;
-import std.Option.some;
-import std.Option.none;
+import std::option;
+import std::option::some;
+import std::option::none;
type ast_visitor =
rec(fn () -> bool keep_going,
fn () -> bool want_crate_directives,
- fn (&ast.crate c) visit_crate_pre,
- fn (&ast.crate c) visit_crate_post,
- fn (&@ast.crate_directive cd) visit_crate_directive_pre,
- fn (&@ast.crate_directive cd) visit_crate_directive_post,
- fn (&@ast.view_item i) visit_view_item_pre,
- fn (&@ast.view_item i) visit_view_item_post,
- fn (&@ast.native_item i) visit_native_item_pre,
- fn (&@ast.native_item i) visit_native_item_post,
- fn (&@ast.item i) visit_item_pre,
- fn (&@ast.item i) visit_item_post,
- fn (&ast.block b) visit_block_pre,
- fn (&ast.block b) visit_block_post,
- fn (&@ast.stmt s) visit_stmt_pre,
- fn (&@ast.stmt s) visit_stmt_post,
- fn (&@ast.decl d) visit_decl_pre,
- fn (&@ast.decl d) visit_decl_post,
- fn (&@ast.expr e) visit_expr_pre,
- fn (&@ast.expr e) visit_expr_post,
- fn (&@ast.ty t) visit_ty_pre,
- fn (&@ast.ty t) visit_ty_post);
+ fn (&ast::crate c) visit_crate_pre,
+ fn (&ast::crate c) visit_crate_post,
+ fn (&@ast::crate_directive cd) visit_crate_directive_pre,
+ fn (&@ast::crate_directive cd) visit_crate_directive_post,
+ fn (&@ast::view_item i) visit_view_item_pre,
+ fn (&@ast::view_item i) visit_view_item_post,
+ fn (&@ast::native_item i) visit_native_item_pre,
+ fn (&@ast::native_item i) visit_native_item_post,
+ fn (&@ast::item i) visit_item_pre,
+ fn (&@ast::item i) visit_item_post,
+ fn (&ast::block b) visit_block_pre,
+ fn (&ast::block b) visit_block_post,
+ fn (&@ast::stmt s) visit_stmt_pre,
+ fn (&@ast::stmt s) visit_stmt_post,
+ fn (&@ast::decl d) visit_decl_pre,
+ fn (&@ast::decl d) visit_decl_post,
+ fn (&@ast::expr e) visit_expr_pre,
+ fn (&@ast::expr e) visit_expr_post,
+ fn (&@ast::ty t) visit_ty_pre,
+ fn (&@ast::ty t) visit_ty_post);
-fn walk_crate(&ast_visitor v, &ast.crate c) {
+fn walk_crate(&ast_visitor v, &ast::crate c) {
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) {
+fn walk_crate_directive(&ast_visitor v, @ast::crate_directive cd) {
if (!v.keep_going()) { ret; }
if (!v.want_crate_directives()) { ret; }
v.visit_crate_directive_pre(cd);
alt (cd.node) {
- case (ast.cdir_let(_, ?e, ?cdirs)) {
+ case (ast::cdir_let(_, ?e, ?cdirs)) {
walk_expr(v, e);
- for (@ast.crate_directive cdir in cdirs) {
+ for (@ast::crate_directive cdir in cdirs) {
walk_crate_directive(v, cdir);
}
}
- case (ast.cdir_src_mod(_, _)) {}
- case (ast.cdir_dir_mod(_, _, ?cdirs)) {
- for (@ast.crate_directive cdir in cdirs) {
+ case (ast::cdir_src_mod(_, _)) {}
+ case (ast::cdir_dir_mod(_, _, ?cdirs)) {
+ for (@ast::crate_directive cdir in cdirs) {
walk_crate_directive(v, cdir);
}
}
- case (ast.cdir_view_item(?vi)) {
+ case (ast::cdir_view_item(?vi)) {
walk_view_item(v, vi);
}
- case (ast.cdir_meta(_)) {}
- case (ast.cdir_syntax(_)) {}
- case (ast.cdir_auth(_, _)) {}
+ case (ast::cdir_meta(_)) {}
+ case (ast::cdir_syntax(_)) {}
+ case (ast::cdir_auth(_, _)) {}
}
v.visit_crate_directive_post(cd);
}
-fn walk_mod(&ast_visitor v, &ast._mod m) {
+fn walk_mod(&ast_visitor v, &ast::_mod m) {
if (!v.keep_going()) { ret; }
- for (@ast.view_item vi in m.view_items) {
+ for (@ast::view_item vi in m.view_items) {
walk_view_item(v, vi);
}
- for (@ast.item i in m.items) {
+ for (@ast::item i in m.items) {
walk_item(v, i);
}
}
-fn walk_view_item(&ast_visitor v, @ast.view_item vi) {
+fn walk_view_item(&ast_visitor v, @ast::view_item vi) {
if (!v.keep_going()) { ret; }
v.visit_view_item_pre(vi);
v.visit_view_item_post(vi);
}
-fn walk_item(&ast_visitor v, @ast.item i) {
+fn walk_item(&ast_visitor v, @ast::item i) {
if (!v.keep_going()) { ret; }
v.visit_item_pre(i);
alt (i.node) {
- case (ast.item_const(_, ?t, ?e, _, _)) {
+ case (ast::item_const(_, ?t, ?e, _, _)) {
walk_ty(v, t);
walk_expr(v, e);
}
- case (ast.item_fn(_, ?f, _, _, _)) {
+ case (ast::item_fn(_, ?f, _, _, _)) {
walk_fn(v, f);
}
- case (ast.item_mod(_, ?m, _)) {
+ case (ast::item_mod(_, ?m, _)) {
walk_mod(v, m);
}
- case (ast.item_native_mod(_, ?nm, _)) {
+ case (ast::item_native_mod(_, ?nm, _)) {
walk_native_mod(v, nm);
}
- case (ast.item_ty(_, ?t, _, _, _)) {
+ case (ast::item_ty(_, ?t, _, _, _)) {
walk_ty(v, t);
}
- case (ast.item_tag(_, ?variants, _, _, _)) {
- for (ast.variant vr in variants) {
- for (ast.variant_arg va in vr.node.args) {
+ 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);
}
}
}
- case (ast.item_obj(_, ?ob, _, _, _)) {
- for (ast.obj_field f in ob.fields) {
+ 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) {
+ for (@ast::method m in ob.methods) {
walk_fn(v, m.node.meth);
}
alt (ob.dtor) {
- case (none[@ast.method]) {}
- case (some[@ast.method](?m)) {
+ case (none[@ast::method]) {}
+ case (some[@ast::method](?m)) {
walk_fn(v, m.node.meth);
}
}
v.visit_item_post(i);
}
-fn walk_ty(&ast_visitor v, @ast.ty t) {
+fn walk_ty(&ast_visitor v, @ast::ty t) {
if (!v.keep_going()) { ret; }
v.visit_ty_pre(t);
alt (t.node) {
- case (ast.ty_nil) {}
- 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_box(?mt)) { walk_ty(v, mt.ty); }
- case (ast.ty_vec(?mt)) { walk_ty(v, mt.ty); }
- case (ast.ty_port(?t)) { walk_ty(v, t); }
- case (ast.ty_chan(?t)) { walk_ty(v, t); }
- case (ast.ty_tup(?mts)) {
- for (ast.mt mt in mts) {
+ case (ast::ty_nil) {}
+ 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_box(?mt)) { walk_ty(v, mt.ty); }
+ case (ast::ty_vec(?mt)) { walk_ty(v, mt.ty); }
+ case (ast::ty_port(?t)) { walk_ty(v, t); }
+ case (ast::ty_chan(?t)) { walk_ty(v, t); }
+ case (ast::ty_tup(?mts)) {
+ for (ast::mt mt in mts) {
walk_ty(v, mt.ty);
}
}
- case (ast.ty_rec(?flds)) {
- for (ast.ty_field f in flds) {
+ case (ast::ty_rec(?flds)) {
+ for (ast::ty_field f in flds) {
walk_ty(v, f.mt.ty);
}
}
- case (ast.ty_fn(_, ?args, ?out)) {
- for (ast.ty_arg a in args) {
+ case (ast::ty_fn(_, ?args, ?out)) {
+ for (ast::ty_arg a in args) {
walk_ty(v, a.ty);
}
walk_ty(v, out);
}
- case (ast.ty_obj(?tmeths)) {
- for (ast.ty_method m in tmeths) {
- for (ast.ty_arg a in m.inputs) {
+ case (ast::ty_obj(?tmeths)) {
+ for (ast::ty_method m in tmeths) {
+ for (ast::ty_arg a in m.inputs) {
walk_ty(v, a.ty);
}
walk_ty(v, m.output);
}
}
- case (ast.ty_path(_, _)) {}
- case (ast.ty_type) {}
- case (ast.ty_constr(?t, _)) { walk_ty(v, t); }
+ case (ast::ty_path(_, _)) {}
+ case (ast::ty_type) {}
+ case (ast::ty_constr(?t, _)) { walk_ty(v, t); }
}
v.visit_ty_post(t);
}
-fn walk_native_mod(&ast_visitor v, &ast.native_mod nm) {
+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) {
+ for (@ast::view_item vi in nm.view_items) {
walk_view_item(v, vi);
}
- for (@ast.native_item ni in nm.items) {
+ for (@ast::native_item ni in nm.items) {
walk_native_item(v, ni);
}
}
-fn walk_native_item(&ast_visitor v, @ast.native_item ni) {
+fn walk_native_item(&ast_visitor v, @ast::native_item ni) {
if (!v.keep_going()) { ret; }
v.visit_native_item_pre(ni);
alt (ni.node) {
- case (ast.native_item_fn(_, _, ?fd, _, _, _)) {
+ case (ast::native_item_fn(_, _, ?fd, _, _, _)) {
walk_fn_decl(v, fd);
}
- case (ast.native_item_ty(_, _)) {
+ case (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) {
+fn walk_fn_decl(&ast_visitor v, &ast::fn_decl fd) {
+ for (ast::arg a in fd.inputs) {
walk_ty(v, a.ty);
}
walk_ty(v, fd.output);
}
-fn walk_fn(&ast_visitor v, &ast._fn f) {
+fn walk_fn(&ast_visitor v, &ast::_fn f) {
if (!v.keep_going()) { ret; }
walk_fn_decl(v, f.decl);
walk_block(v, f.body);
}
-fn walk_block(&ast_visitor v, &ast.block b) {
+fn walk_block(&ast_visitor v, &ast::block b) {
if (!v.keep_going()) { ret; }
v.visit_block_pre(b);
- for (@ast.stmt s in b.node.stmts) {
+ for (@ast::stmt s 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) {
+fn walk_stmt(&ast_visitor v, @ast::stmt s) {
if (!v.keep_going()) { ret; }
v.visit_stmt_pre(s);
alt (s.node) {
- case (ast.stmt_decl(?d, _)) {
+ case (ast::stmt_decl(?d, _)) {
walk_decl(v, d);
}
- case (ast.stmt_expr(?e, _)) {
+ case (ast::stmt_expr(?e, _)) {
walk_expr(v, e);
}
- case (ast.stmt_crate_directive(?cdir)) {
+ case (ast::stmt_crate_directive(?cdir)) {
walk_crate_directive(v, cdir);
}
}
v.visit_stmt_post(s);
}
-fn walk_decl(&ast_visitor v, @ast.decl d) {
+fn walk_decl(&ast_visitor v, @ast::decl d) {
if (!v.keep_going()) { ret; }
v.visit_decl_pre(d);
alt (d.node) {
- case (ast.decl_local(?loc)) {
+ case (ast::decl_local(?loc)) {
alt (loc.ty) {
- case (none[@ast.ty]) {}
- case (some[@ast.ty](?t)) { walk_ty(v, t); }
+ case (none[@ast::ty]) {}
+ case (some[@ast::ty](?t)) { walk_ty(v, t); }
}
alt (loc.init) {
- case (none[ast.initializer]) {}
- case (some[ast.initializer](?i)) {
+ case (none[ast::initializer]) {}
+ case (some[ast::initializer](?i)) {
walk_expr(v, i.expr);
}
}
}
- case (ast.decl_item(?it)) {
+ case (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) {
+fn walk_expr_opt(&ast_visitor v, option::t[@ast::expr] eo) {
alt (eo) {
- case (none[@ast.expr]) {}
- case (some[@ast.expr](?e)) {
+ case (none[@ast::expr]) {}
+ case (some[@ast::expr](?e)) {
walk_expr(v, e);
}
}
}
-fn walk_exprs(&ast_visitor v, vec[@ast.expr] exprs) {
- for (@ast.expr e in exprs) {
+fn walk_exprs(&ast_visitor v, vec[@ast::expr] exprs) {
+ for (@ast::expr e in exprs) {
walk_expr(v, e);
}
}
-fn walk_expr(&ast_visitor v, @ast.expr e) {
+fn walk_expr(&ast_visitor v, @ast::expr e) {
if (!v.keep_going()) { ret; }
v.visit_expr_pre(e);
alt (e.node) {
- case (ast.expr_vec(?es, _, _)) {
+ case (ast::expr_vec(?es, _, _)) {
walk_exprs(v, es);
}
- case (ast.expr_tup(?elts, _)) {
- for (ast.elt e in elts) {
+ case (ast::expr_tup(?elts, _)) {
+ for (ast::elt e in elts) {
walk_expr(v, e.expr);
}
}
- case (ast.expr_rec(?flds, ?base, _)) {
- for (ast.field f in flds) {
+ case (ast::expr_rec(?flds, ?base, _)) {
+ for (ast::field f in flds) {
walk_expr(v, f.expr);
}
walk_expr_opt(v, base);
}
- case (ast.expr_call(?callee, ?args, _)) {
+ 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, _)) {
+ case (ast::expr_self_method(_, _)) { }
+ case (ast::expr_bind(?callee, ?args, _)) {
walk_expr(v, callee);
- for (Option.t[@ast.expr] eo in args) {
+ for (option::t[@ast::expr] eo in args) {
walk_expr_opt(v, eo);
}
}
- case (ast.expr_spawn(_, _, ?callee, ?args, _)) {
+ case (ast::expr_spawn(_, _, ?callee, ?args, _)) {
walk_expr(v, callee);
walk_exprs(v, args);
}
- case (ast.expr_binary(_, ?a, ?b, _)) {
+ case (ast::expr_binary(_, ?a, ?b, _)) {
walk_expr(v, a);
walk_expr(v, b);
}
- case (ast.expr_unary(_, ?a, _)) {
+ case (ast::expr_unary(_, ?a, _)) {
walk_expr(v, a);
}
- case (ast.expr_lit(_, _)) { }
- case (ast.expr_cast(?x, ?t, _)) {
+ 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, _)) {
+ case (ast::expr_if(?x, ?b, ?eo, _)) {
walk_expr(v, x);
walk_block(v, b);
walk_expr_opt(v, eo);
}
- case (ast.expr_while(?x, ?b, _)) {
+ case (ast::expr_while(?x, ?b, _)) {
walk_expr(v, x);
walk_block(v, b);
}
- case (ast.expr_for(?dcl, ?x, ?b, _)) {
+ case (ast::expr_for(?dcl, ?x, ?b, _)) {
walk_decl(v, dcl);
walk_expr(v, x);
walk_block(v, b);
}
- case (ast.expr_for_each(?dcl, ?x, ?b, _)) {
+ case (ast::expr_for_each(?dcl, ?x, ?b, _)) {
walk_decl(v, dcl);
walk_expr(v, x);
walk_block(v, b);
}
- case (ast.expr_do_while(?b, ?x, _)) {
+ case (ast::expr_do_while(?b, ?x, _)) {
walk_block(v, b);
walk_expr(v, x);
}
- case (ast.expr_alt(?x, ?arms, _)) {
+ case (ast::expr_alt(?x, ?arms, _)) {
walk_expr(v, x);
- for (ast.arm a in arms) {
+ for (ast::arm a in arms) {
walk_block(v, a.block);
}
}
- case (ast.expr_block(?b, _)) {
+ case (ast::expr_block(?b, _)) {
walk_block(v, b);
}
- case (ast.expr_assign(?a, ?b, _)) {
+ case (ast::expr_assign(?a, ?b, _)) {
walk_expr(v, a);
walk_expr(v, b);
}
- case (ast.expr_assign_op(_, ?a, ?b, _)) {
+ case (ast::expr_assign_op(_, ?a, ?b, _)) {
walk_expr(v, a);
walk_expr(v, b);
}
- case (ast.expr_send(?a, ?b, _)) {
+ case (ast::expr_send(?a, ?b, _)) {
walk_expr(v, a);
walk_expr(v, b);
}
- case (ast.expr_recv(?a, ?b, _)) {
+ case (ast::expr_recv(?a, ?b, _)) {
walk_expr(v, a);
walk_expr(v, b);
}
- case (ast.expr_field(?x, _, _)) {
+ case (ast::expr_field(?x, _, _)) {
walk_expr(v, x);
}
- case (ast.expr_index(?a, ?b, _)) {
+ case (ast::expr_index(?a, ?b, _)) {
walk_expr(v, a);
walk_expr(v, b);
}
- case (ast.expr_path(_, _)) { }
- case (ast.expr_ext(_, ?args, ?body, ?expansion, _)) {
+ case (ast::expr_path(_, _)) { }
+ case (ast::expr_ext(_, ?args, ?body, ?expansion, _)) {
// Only walk expansion, not args/body.
walk_expr(v, expansion);
}
- case (ast.expr_fail(_)) { }
- case (ast.expr_break(_)) { }
- case (ast.expr_cont(_)) { }
- case (ast.expr_ret(?eo, _)) {
+ case (ast::expr_fail(_)) { }
+ case (ast::expr_break(_)) { }
+ case (ast::expr_cont(_)) { }
+ case (ast::expr_ret(?eo, _)) {
walk_expr_opt(v, eo);
}
- case (ast.expr_put(?eo, _)) {
+ case (ast::expr_put(?eo, _)) {
walk_expr_opt(v, eo);
}
- case (ast.expr_be(?x, _)) {
+ case (ast::expr_be(?x, _)) {
walk_expr(v, x);
}
- case (ast.expr_log(_,?x, _)) {
+ case (ast::expr_log(_,?x, _)) {
walk_expr(v, x);
}
- case (ast.expr_check(?x, _)) {
+ case (ast::expr_check(?x, _)) {
walk_expr(v, x);
}
- case (ast.expr_assert(?x, _)) {
+ case (ast::expr_assert(?x, _)) {
walk_expr(v, x);
}
- case (ast.expr_port(_)) { }
- case (ast.expr_chan(?x, _)) {
+ case (ast::expr_port(_)) { }
+ case (ast::expr_chan(?x, _)) {
walk_expr(v, x);
}
}
fn def_keep_going() -> bool { ret true; }
fn def_want_crate_directives() -> bool { ret false; }
-fn def_visit_crate(&ast.crate c) { }
-fn def_visit_crate_directive(&@ast.crate_directive c) { }
-fn def_visit_view_item(&@ast.view_item vi) { }
-fn def_visit_native_item(&@ast.native_item ni) { }
-fn def_visit_item(&@ast.item i) { }
-fn def_visit_block(&ast.block b) { }
-fn def_visit_stmt(&@ast.stmt s) { }
-fn def_visit_decl(&@ast.decl d) { }
-fn def_visit_expr(&@ast.expr e) { }
-fn def_visit_ty(&@ast.ty t) { }
+fn def_visit_crate(&ast::crate c) { }
+fn def_visit_crate_directive(&@ast::crate_directive c) { }
+fn def_visit_view_item(&@ast::view_item vi) { }
+fn def_visit_native_item(&@ast::native_item ni) { }
+fn def_visit_item(&@ast::item i) { }
+fn def_visit_block(&ast::block b) { }
+fn def_visit_stmt(&@ast::stmt s) { }
+fn def_visit_decl(&@ast::decl d) { }
+fn def_visit_expr(&@ast::expr e) { }
+fn def_visit_ty(&@ast::ty t) { }
fn default_visitor() -> ast_visitor {
-import std.IO;
-import std.Vec;
-import std.Str;
+import std::io;
+import std::_vec;
+import std::_str;
tag boxtype {box_h; box_v; box_hv; box_align;}
tag contexttype {cx_h; cx_v;}
type ps = @rec(mutable vec[context] context,
uint width,
- IO.writer out,
+ io::writer out,
mutable uint col,
mutable uint spaces,
mutable vec[token] buffered,
mutable bool start_of_box,
mutable bool potential_brk);
-fn mkstate(IO.writer out, uint width) -> ps {
+fn mkstate(io::writer out, uint width) -> ps {
let vec[context] stack = vec(rec(tp=cx_v, indent=0u));
let vec[token] buff = vec();
let vec[boxtype] sd = vec();
fn push_context(ps p, contexttype tp, uint indent) {
before_print(p, false);
- Vec.push[context](p.context, rec(tp=tp, indent=indent));
+ _vec::push[context](p.context, rec(tp=tp, indent=indent));
p.start_of_box = true;
}
fn pop_context(ps p) {
- Vec.pop[context](p.context);
+ _vec::pop[context](p.context);
}
fn add_token(ps p, token tok) {
} else {
alt (tok) {
case (open(?tp,_)) {
- Vec.push[boxtype](p.scandepth, tp);
+ _vec::push[boxtype](p.scandepth, tp);
if (p.scanning == scan_h) {
if (tp == box_h) {
check_potential_brk(p);
}
}
case (close) {
- Vec.pop[boxtype](p.scandepth);
- if (Vec.len[boxtype](p.scandepth) == 0u) {
+ _vec::pop[boxtype](p.scandepth);
+ if (_vec::len[boxtype](p.scandepth) == 0u) {
finish_scan(p, true);
}
}
case (brk(_)) {
if (p.scanning == scan_h) {
- if (p.scandepth.(Vec.len[boxtype](p.scandepth)-1u) == box_v) {
+ if (p.scandepth.(_vec::len[boxtype](p.scandepth)-1u) == box_v) {
finish_scan(p, true);
}
}
fn finish_scan(ps p, bool fits) {
auto buf = p.buffered;
- auto front = Vec.shift[token](buf);
+ auto front = _vec::shift[token](buf);
auto chosen_tp = cx_h;
if (!fits) {chosen_tp = cx_v;}
alt (front) {
}
fn cur_context(ps p) -> context {
- ret p.context.(Vec.len[context](p.context)-1u);
+ ret p.context.(_vec::len[context](p.context)-1u);
}
fn base_indent(ps p) -> uint {
- auto i = Vec.len[context](p.context);
+ auto i = _vec::len[context](p.context);
while (i > 0u) {
i -= 1u;
auto cx = p.context.(i);
line_break(p);
}
case (word(?w)) {
- auto len = Str.char_len(w);
+ auto len = _str::char_len(w);
if (len + p.col + p.spaces > p.width && !start_of_box &&
!p.start_of_line) {
line_break(p);
case (cword(?w)) {
before_print(p, true);
p.out.write_str(w);
- p.col += Str.char_len(w);
+ p.col += _str::char_len(w);
}
case (open(?tp, ?indent)) {
if (tp == box_v) {
alt (tok) {
case (brk(?sz)) {ret sz;}
case (hardbrk) {ret 0xFFFFFFu;}
- case (word(?w)) {ret Str.char_len(w);}
- case (cword(?w)) {ret Str.char_len(w);}
+ case (word(?w)) {ret _str::char_len(w);}
+ case (cword(?w)) {ret _str::char_len(w);}
case (open(_, _)) {ret 0u;}
case (close) {ret 0u;}
}
-import std.Vec;
-import std.Str;
-import std.IO;
-import std.Option;
-import driver.session.session;
-import front.ast;
-import front.lexer;
-import util.common;
-import pp.end; import pp.wrd; import pp.space; import pp.line;
+import std::_vec;
+import std::_str;
+import std::io;
+import std::option;
+import driver::session::session;
+import front::ast;
+import front::lexer;
+import util::common;
+import pp::end; import pp::wrd; import pp::space; import pp::line;
const uint indent_unit = 4u;
const int as_prec = 5;
const uint default_columns = 78u;
-type ps = @rec(pp.ps s,
- Option.t[vec[lexer.cmnt]] comments,
+type ps = @rec(pp::ps s,
+ option::t[vec[lexer::cmnt]] comments,
mutable uint cur_cmnt);
-fn print_file(session sess, ast._mod _mod, str filename, IO.writer out) {
- auto cmnts = lexer.gather_comments(sess, filename);
- auto s = @rec(s=pp.mkstate(out, default_columns),
- comments=Option.some[vec[lexer.cmnt]](cmnts),
+fn print_file(session sess, ast::_mod _mod, str filename, io::writer out) {
+ auto cmnts = lexer::gather_comments(sess, filename);
+ auto s = @rec(s=pp::mkstate(out, default_columns),
+ comments=option::some[vec[lexer::cmnt]](cmnts),
mutable cur_cmnt=0u);
print_mod(s, _mod);
}
-fn ty_to_str(&@ast.ty ty) -> str {
- auto writer = IO.string_writer();
- auto s = @rec(s=pp.mkstate(writer.get_writer(), 0u),
- comments=Option.none[vec[lexer.cmnt]],
+fn ty_to_str(&@ast::ty ty) -> str {
+ auto writer = io::string_writer();
+ auto s = @rec(s=pp::mkstate(writer.get_writer(), 0u),
+ comments=option::none[vec[lexer::cmnt]],
mutable cur_cmnt=0u);
print_type(s, ty);
ret writer.get_str();
}
-fn block_to_str(&ast.block blk) -> str {
- auto writer = IO.string_writer();
- auto s = @rec(s=pp.mkstate(writer.get_writer(), 78u),
- comments=Option.none[vec[lexer.cmnt]],
+fn block_to_str(&ast::block blk) -> str {
+ auto writer = io::string_writer();
+ auto s = @rec(s=pp::mkstate(writer.get_writer(), 78u),
+ comments=option::none[vec[lexer::cmnt]],
mutable cur_cmnt=0u);
print_block(s, blk);
ret writer.get_str();
}
-fn pat_to_str(&@ast.pat p) -> str {
- auto writer = IO.string_writer();
- auto s = @rec(s=pp.mkstate(writer.get_writer(), 78u),
- comments=Option.none[vec[lexer.cmnt]],
+fn pat_to_str(&@ast::pat p) -> str {
+ auto writer = io::string_writer();
+ auto s = @rec(s=pp::mkstate(writer.get_writer(), 78u),
+ comments=option::none[vec[lexer::cmnt]],
mutable cur_cmnt=0u);
print_pat(s, p);
ret writer.get_str();
}
fn hbox(ps s) {
- pp.hbox(s.s, indent_unit);
+ pp::hbox(s.s, indent_unit);
}
fn wrd1(ps s, str word) {
wrd(s.s, word);
}
fn popen(ps s) {
wrd(s.s, "(");
- pp.abox(s.s);
+ pp::abox(s.s);
}
fn popen_h(ps s) {
wrd(s.s, "(");
- pp.hbox(s.s, 0u);
+ pp::hbox(s.s, 0u);
}
fn pclose(ps s) {
end(s.s);
}
fn bopen(ps s) {
wrd(s.s, "{");
- pp.vbox(s.s, indent_unit);
+ pp::vbox(s.s, indent_unit);
line(s.s);
}
fn bclose(ps s) {
end(s.s);
- pp.cwrd(s.s, "}");
+ pp::cwrd(s.s, "}");
}
-fn bclose_c(ps s, common.span span) {
+fn bclose_c(ps s, common::span span) {
maybe_print_comment(s, span.hi);
bclose(s);
}
}
}
fn commasep_cmnt[IN](ps s, vec[IN] elts, fn(ps, &IN) op,
- fn(&IN) -> common.span get_span) {
- auto len = Vec.len[IN](elts);
+ fn(&IN) -> common::span get_span) {
+ auto len = _vec::len[IN](elts);
auto i = 0u;
for (IN elt in elts) {
op(s, elt);
}
}
}
-fn commasep_exprs(ps s, vec[@ast.expr] exprs) {
- fn expr_span(&@ast.expr expr) -> common.span {ret expr.span;}
+fn commasep_exprs(ps s, vec[@ast::expr] exprs) {
+ fn expr_span(&@ast::expr expr) -> common::span {ret expr.span;}
auto f = print_expr;
auto gs = expr_span;
- commasep_cmnt[@ast.expr](s, exprs, f, gs);
+ commasep_cmnt[@ast::expr](s, exprs, f, gs);
}
-fn print_mod(ps s, ast._mod _mod) {
- for (@ast.view_item vitem in _mod.view_items) {print_view_item(s, vitem);}
+fn print_mod(ps s, ast::_mod _mod) {
+ for (@ast::view_item vitem in _mod.view_items) {
+ print_view_item(s, vitem);
+ }
line(s.s);
- for (@ast.item item in _mod.items) {print_item(s, item);}
+ for (@ast::item item in _mod.items) {print_item(s, item);}
print_remaining_comments(s);
}
-fn print_type(ps s, &@ast.ty ty) {
+fn print_type(ps s, &@ast::ty ty) {
maybe_print_comment(s, ty.span.lo);
hbox(s);
alt (ty.node) {
- case (ast.ty_nil) {wrd(s.s, "()");}
- case (ast.ty_bool) {wrd(s.s, "bool");}
- case (ast.ty_int) {wrd(s.s, "int");}
- case (ast.ty_uint) {wrd(s.s, "uint");}
- case (ast.ty_float) {wrd(s.s, "float");}
- case (ast.ty_machine(?tm)) {wrd(s.s, common.ty_mach_to_str(tm));}
- case (ast.ty_char) {wrd(s.s, "char");}
- case (ast.ty_str) {wrd(s.s, "str");}
- case (ast.ty_box(?mt)) {wrd(s.s, "@"); print_mt(s, mt);}
- case (ast.ty_vec(?mt)) {
+ case (ast::ty_nil) {wrd(s.s, "()");}
+ case (ast::ty_bool) {wrd(s.s, "bool");}
+ case (ast::ty_int) {wrd(s.s, "int");}
+ case (ast::ty_uint) {wrd(s.s, "uint");}
+ case (ast::ty_float) {wrd(s.s, "float");}
+ case (ast::ty_machine(?tm)) {wrd(s.s, common::ty_mach_to_str(tm));}
+ case (ast::ty_char) {wrd(s.s, "char");}
+ case (ast::ty_str) {wrd(s.s, "str");}
+ case (ast::ty_box(?mt)) {wrd(s.s, "@"); print_mt(s, mt);}
+ case (ast::ty_vec(?mt)) {
wrd(s.s, "vec["); print_mt(s, mt); wrd(s.s, "]");
}
- case (ast.ty_port(?t)) {
+ case (ast::ty_port(?t)) {
wrd(s.s, "port["); print_type(s, t); wrd(s.s, "]");
}
- case (ast.ty_chan(?t)) {
+ case (ast::ty_chan(?t)) {
wrd(s.s, "chan["); print_type(s, t); wrd(s.s, "]");
}
- case (ast.ty_type) {wrd(s.s, "type");}
- case (ast.ty_tup(?elts)) {
+ case (ast::ty_type) {wrd(s.s, "type");}
+ case (ast::ty_tup(?elts)) {
wrd(s.s, "tup");
popen(s);
auto f = print_mt;
- commasep[ast.mt](s, elts, f);
+ commasep[ast::mt](s, elts, f);
pclose(s);
}
- case (ast.ty_rec(?fields)) {
+ case (ast::ty_rec(?fields)) {
wrd(s.s, "rec");
popen(s);
- fn print_field(ps s, &ast.ty_field f) {
+ fn print_field(ps s, &ast::ty_field f) {
hbox(s);
print_mt(s, f.mt);
space(s.s);
wrd(s.s, f.ident);
end(s.s);
}
- fn get_span(&ast.ty_field f) -> common.span {
+ fn get_span(&ast::ty_field f) -> common::span {
// Try to reconstruct the span for this field
auto sp = f.mt.ty.span;
- auto hi = sp.hi + Str.char_len(f.ident) + 1u;
+ auto hi = sp.hi + _str::char_len(f.ident) + 1u;
ret rec(hi=hi with sp);
}
auto f = print_field;
auto gs = get_span;
- commasep_cmnt[ast.ty_field](s, fields, f, gs);
+ commasep_cmnt[ast::ty_field](s, fields, f, gs);
pclose(s);
}
- case (ast.ty_obj(?methods)) {
+ case (ast::ty_obj(?methods)) {
wrd1(s, "obj");
bopen(s);
- for (ast.ty_method m in methods) {
+ for (ast::ty_method m in methods) {
hbox(s);
- print_ty_fn(s, m.proto, Option.some[str](m.ident),
+ print_ty_fn(s, m.proto, option::some[str](m.ident),
m.inputs, m.output);
wrd(s.s, ";");
end(s.s);
}
bclose_c(s, ty.span);
}
- case (ast.ty_fn(?proto,?inputs,?output)) {
- print_ty_fn(s, proto, Option.none[str], inputs, output);
+ case (ast::ty_fn(?proto,?inputs,?output)) {
+ print_ty_fn(s, proto, option::none[str], inputs, output);
}
- case (ast.ty_path(?path,_)) {
+ case (ast::ty_path(?path,_)) {
print_path(s, path);
}
}
end(s.s);
}
-fn print_item(ps s, @ast.item item) {
+fn print_item(ps s, @ast::item item) {
maybe_print_comment(s, item.span.lo);
hbox(s);
alt (item.node) {
- case (ast.item_const(?id, ?ty, ?expr, _, _)) {
+ case (ast::item_const(?id, ?ty, ?expr, _, _)) {
wrd1(s, "const");
print_type(s, ty);
space(s.s);
print_expr(s, expr);
wrd(s.s, ";");
}
- case (ast.item_fn(?name,?_fn,?typarams,_,_)) {
+ case (ast::item_fn(?name,?_fn,?typarams,_,_)) {
print_fn(s, _fn.decl, name, typarams);
space(s.s);
print_block(s, _fn.body);
}
- case (ast.item_mod(?id,?_mod,_)) {
+ case (ast::item_mod(?id,?_mod,_)) {
wrd1(s, "mod");
wrd1(s, id);
bopen(s);
- for (@ast.item itm in _mod.items) {print_item(s, itm);}
+ for (@ast::item itm in _mod.items) {print_item(s, itm);}
bclose_c(s, item.span);
}
- case (ast.item_native_mod(?id,?nmod,_)) {
+ case (ast::item_native_mod(?id,?nmod,_)) {
wrd1(s, "native");
alt (nmod.abi) {
- case (ast.native_abi_rust) {wrd1(s, "\"rust\"");}
- case (ast.native_abi_cdecl) {wrd1(s, "\"cdecl\"");}
- case (ast.native_abi_rust_intrinsic) {
+ case (ast::native_abi_rust) {wrd1(s, "\"rust\"");}
+ case (ast::native_abi_cdecl) {wrd1(s, "\"cdecl\"");}
+ case (ast::native_abi_rust_intrinsic) {
wrd1(s, "\"rust-intrinstic\"");
}
}
wrd1(s, "mod");
wrd1(s, id);
bopen(s);
- for (@ast.native_item item in nmod.items) {
+ for (@ast::native_item item in nmod.items) {
hbox(s);
maybe_print_comment(s, item.span.lo);
alt (item.node) {
- case (ast.native_item_ty(?id,_)) {
+ case (ast::native_item_ty(?id,_)) {
wrd1(s, "type");
wrd(s.s, id);
}
- case (ast.native_item_fn(?id,?lname,?decl,
+ case (ast::native_item_fn(?id,?lname,?decl,
?typarams,_,_)) {
print_fn(s, decl, id, typarams);
alt (lname) {
- case (Option.none[str]) {}
- case (Option.some[str](?ss)) {
+ case (option::none[str]) {}
+ case (option::some[str](?ss)) {
print_string(s, ss);
}
}
}
bclose_c(s, item.span);
}
- case (ast.item_ty(?id,?ty,?params,_,_)) {
+ case (ast::item_ty(?id,?ty,?params,_,_)) {
wrd1(s, "type");
wrd(s.s, id);
print_type_params(s, params);
print_type(s, ty);
wrd(s.s, ";");
}
- case (ast.item_tag(?id,?variants,?params,_,_)) {
+ case (ast::item_tag(?id,?variants,?params,_,_)) {
wrd1(s, "tag");
wrd(s.s, id);
print_type_params(s, params);
space(s.s);
bopen(s);
- for (ast.variant v in variants) {
+ for (ast::variant v in variants) {
maybe_print_comment(s, v.span.lo);
wrd(s.s, v.node.name);
- if (Vec.len[ast.variant_arg](v.node.args) > 0u) {
+ if (_vec::len[ast::variant_arg](v.node.args) > 0u) {
popen(s);
- fn print_variant_arg(ps s, &ast.variant_arg arg) {
+ fn print_variant_arg(ps s, &ast::variant_arg arg) {
print_type(s, arg.ty);
}
auto f = print_variant_arg;
- commasep[ast.variant_arg](s, v.node.args, f);
+ commasep[ast::variant_arg](s, v.node.args, f);
pclose(s);
}
wrd(s.s, ";");
}
bclose_c(s, item.span);
}
- case (ast.item_obj(?id,?_obj,?params,_,_)) {
+ case (ast::item_obj(?id,?_obj,?params,_,_)) {
wrd1(s, "obj");
wrd(s.s, id);
print_type_params(s, params);
popen(s);
- fn print_field(ps s, &ast.obj_field field) {
+ fn print_field(ps s, &ast::obj_field field) {
hbox(s);
print_type(s, field.ty);
space(s.s);
wrd(s.s, field.ident);
end(s.s);
}
- fn get_span(&ast.obj_field f) -> common.span {ret f.ty.span;}
+ fn get_span(&ast::obj_field f) -> common::span {ret f.ty.span;}
auto f = print_field;
auto gs = get_span;
- commasep_cmnt[ast.obj_field](s, _obj.fields, f, gs);
+ commasep_cmnt[ast::obj_field](s, _obj.fields, f, gs);
pclose(s);
space(s.s);
bopen(s);
- for (@ast.method meth in _obj.methods) {
+ for (@ast::method meth in _obj.methods) {
hbox(s);
- let vec[ast.ty_param] typarams = vec();
+ let vec[ast::ty_param] typarams = vec();
maybe_print_comment(s, meth.span.lo);
print_fn(s, meth.node.meth.decl, meth.node.ident, typarams);
space(s.s);
line(s.s);
}
alt (_obj.dtor) {
- case (Option.some[@ast.method](?dtor)) {
+ case (option::some[@ast::method](?dtor)) {
hbox(s);
wrd1(s, "close");
print_block(s, dtor.node.meth.body);
line(s.s);
}
-fn print_block(ps s, ast.block blk) {
+fn print_block(ps s, ast::block blk) {
maybe_print_comment(s, blk.span.lo);
bopen(s);
- for (@ast.stmt st in blk.node.stmts) {
+ for (@ast::stmt st in blk.node.stmts) {
maybe_print_comment(s, st.span.lo);
alt (st.node) {
- case (ast.stmt_decl(?decl,_)) {print_decl(s, decl);}
- case (ast.stmt_expr(?expr,_)) {print_expr(s, expr);}
+ case (ast::stmt_decl(?decl,_)) {print_decl(s, decl);}
+ case (ast::stmt_expr(?expr,_)) {print_expr(s, expr);}
}
- if (front.parser.stmt_ends_with_semi(st)) {wrd(s.s, ";");}
+ if (front::parser::stmt_ends_with_semi(st)) {wrd(s.s, ";");}
if (!maybe_print_line_comment(s, st.span)) {line(s.s);}
}
alt (blk.node.expr) {
- case (Option.some[@ast.expr](?expr)) {
+ case (option::some[@ast::expr](?expr)) {
print_expr(s, expr);
if (!maybe_print_line_comment(s, expr.span)) {line(s.s);}
}
bclose_c(s, blk.span);
}
-fn print_literal(ps s, @ast.lit lit) {
+fn print_literal(ps s, @ast::lit lit) {
maybe_print_comment(s, lit.span.lo);
alt (lit.node) {
- case (ast.lit_str(?st)) {print_string(s, st);}
- case (ast.lit_char(?ch)) {
- wrd(s.s, "'" + escape_str(Str.from_bytes(vec(ch as u8)), '\'')
+ case (ast::lit_str(?st)) {print_string(s, st);}
+ case (ast::lit_char(?ch)) {
+ wrd(s.s, "'" + escape_str(_str::from_bytes(vec(ch as u8)), '\'')
+ "'");
}
- case (ast.lit_int(?val)) {
- wrd(s.s, common.istr(val));
+ case (ast::lit_int(?val)) {
+ wrd(s.s, common::istr(val));
}
- case (ast.lit_uint(?val)) { // FIXME clipping? uistr?
- wrd(s.s, common.istr(val as int) + "u");
+ case (ast::lit_uint(?val)) { // FIXME clipping? uistr?
+ wrd(s.s, common::istr(val as int) + "u");
}
- case (ast.lit_float(?fstr)) {
+ case (ast::lit_float(?fstr)) {
wrd(s.s, fstr);
}
- case (ast.lit_mach_int(?mach,?val)) {
- wrd(s.s, common.istr(val as int));
- wrd(s.s, common.ty_mach_to_str(mach));
+ case (ast::lit_mach_int(?mach,?val)) {
+ wrd(s.s, common::istr(val as int));
+ wrd(s.s, common::ty_mach_to_str(mach));
}
- case (ast.lit_mach_float(?mach,?val)) {
+ case (ast::lit_mach_float(?mach,?val)) {
// val is already a str
wrd(s.s, val);
- wrd(s.s, common.ty_mach_to_str(mach));
+ wrd(s.s, common::ty_mach_to_str(mach));
}
- case (ast.lit_nil) {wrd(s.s, "()");}
- case (ast.lit_bool(?val)) {
+ case (ast::lit_nil) {wrd(s.s, "()");}
+ case (ast::lit_bool(?val)) {
if (val) {wrd(s.s, "true");} else {wrd(s.s, "false");}
}
}
}
-fn print_expr(ps s, &@ast.expr expr) {
+fn print_expr(ps s, &@ast::expr expr) {
maybe_print_comment(s, expr.span.lo);
hbox(s);
alt (expr.node) {
- case (ast.expr_vec(?exprs,?mut,_)) {
- if (mut == ast.mut) {
+ case (ast::expr_vec(?exprs,?mut,_)) {
+ if (mut == ast::mut) {
wrd1(s, "mutable");
}
wrd(s.s, "vec");
commasep_exprs(s, exprs);
pclose(s);
}
- case (ast.expr_tup(?exprs,_)) {
- fn printElt(ps s, &ast.elt elt) {
+ case (ast::expr_tup(?exprs,_)) {
+ fn printElt(ps s, &ast::elt elt) {
hbox(s);
- if (elt.mut == ast.mut) {wrd1(s, "mutable");}
+ if (elt.mut == ast::mut) {wrd1(s, "mutable");}
print_expr(s, elt.expr);
end(s.s);
}
- fn get_span(&ast.elt elt) -> common.span {ret elt.expr.span;}
+ fn get_span(&ast::elt elt) -> common::span {ret elt.expr.span;}
wrd(s.s, "tup");
popen(s);
auto f = printElt;
auto gs = get_span;
- commasep_cmnt[ast.elt](s, exprs, f, gs);
+ commasep_cmnt[ast::elt](s, exprs, f, gs);
pclose(s);
}
- case (ast.expr_rec(?fields,?wth,_)) {
- fn print_field(ps s, &ast.field field) {
+ case (ast::expr_rec(?fields,?wth,_)) {
+ fn print_field(ps s, &ast::field field) {
hbox(s);
- if (field.mut == ast.mut) {wrd1(s, "mutable");}
+ if (field.mut == ast::mut) {wrd1(s, "mutable");}
wrd(s.s, field.ident);
wrd(s.s, "=");
print_expr(s, field.expr);
end(s.s);
}
- fn get_span(&ast.field field) -> common.span {
+ fn get_span(&ast::field field) -> common::span {
ret field.expr.span;
}
wrd(s.s, "rec");
popen(s);
auto f = print_field;
auto gs = get_span;
- commasep_cmnt[ast.field](s, fields, f, gs);
+ commasep_cmnt[ast::field](s, fields, f, gs);
alt (wth) {
- case (Option.some[@ast.expr](?expr)) {
- if (Vec.len[ast.field](fields) > 0u) {space(s.s);}
+ case (option::some[@ast::expr](?expr)) {
+ if (_vec::len[ast::field](fields) > 0u) {space(s.s);}
hbox(s);
wrd1(s, "with");
print_expr(s, expr);
}
pclose(s);
}
- case (ast.expr_call(?func,?args,_)) {
+ case (ast::expr_call(?func,?args,_)) {
print_expr(s, func);
popen(s);
commasep_exprs(s, args);
pclose(s);
}
- case (ast.expr_self_method(?ident,_)) {
+ case (ast::expr_self_method(?ident,_)) {
wrd(s.s, "self.");
print_ident(s, ident);
}
- case (ast.expr_bind(?func,?args,_)) {
- fn print_opt(ps s, &Option.t[@ast.expr] expr) {
+ case (ast::expr_bind(?func,?args,_)) {
+ fn print_opt(ps s, &option::t[@ast::expr] expr) {
alt (expr) {
- case (Option.some[@ast.expr](?expr)) {
+ case (option::some[@ast::expr](?expr)) {
print_expr(s, expr);
}
case (_) {wrd(s.s, "_");}
print_expr(s, func);
popen(s);
auto f = print_opt;
- commasep[Option.t[@ast.expr]](s, args, f);
+ commasep[option::t[@ast::expr]](s, args, f);
pclose(s);
}
- case (ast.expr_spawn(_,_,?e,?es,_)) {
+ case (ast::expr_spawn(_,_,?e,?es,_)) {
wrd1(s, "spawn");
print_expr(s, e);
popen(s);
commasep_exprs(s, es);
pclose(s);
}
- case (ast.expr_binary(?op,?lhs,?rhs,_)) {
+ case (ast::expr_binary(?op,?lhs,?rhs,_)) {
auto prec = operator_prec(op);
print_maybe_parens(s, lhs, prec);
space(s.s);
- wrd1(s, ast.binop_to_str(op));
+ wrd1(s, ast::binop_to_str(op));
print_maybe_parens(s, rhs, prec + 1);
}
- case (ast.expr_unary(?op,?expr,_)) {
- wrd(s.s, ast.unop_to_str(op));
+ case (ast::expr_unary(?op,?expr,_)) {
+ wrd(s.s, ast::unop_to_str(op));
print_expr(s, expr);
}
- case (ast.expr_lit(?lit,_)) {
+ case (ast::expr_lit(?lit,_)) {
print_literal(s, lit);
}
- case (ast.expr_cast(?expr,?ty,_)) {
+ case (ast::expr_cast(?expr,?ty,_)) {
print_maybe_parens(s, expr, as_prec);
space(s.s);
wrd1(s, "as");
print_type(s, ty);
}
- case (ast.expr_if(?test,?block,?elseopt,_)) {
+ case (ast::expr_if(?test,?block,?elseopt,_)) {
wrd1(s, "if");
popen_h(s);
print_expr(s, test);
space(s.s);
print_block(s, block);
alt (elseopt) {
- case (Option.some[@ast.expr](?_else)) {
+ case (option::some[@ast::expr](?_else)) {
space(s.s);
wrd1(s, "else");
print_expr(s, _else);
case (_) { /* fall through */ }
}
}
- case (ast.expr_while(?test,?block,_)) {
+ case (ast::expr_while(?test,?block,_)) {
wrd1(s, "while");
popen_h(s);
print_expr(s, test);
space(s.s);
print_block(s, block);
}
- case (ast.expr_for(?decl,?expr,?block,_)) {
+ case (ast::expr_for(?decl,?expr,?block,_)) {
wrd1(s, "for");
popen_h(s);
print_for_decl(s, decl);
space(s.s);
print_block(s, block);
}
- case (ast.expr_for_each(?decl,?expr,?block,_)) {
+ case (ast::expr_for_each(?decl,?expr,?block,_)) {
wrd1(s, "for each");
popen_h(s);
print_for_decl(s, decl);
space(s.s);
print_block(s, block);
}
- case (ast.expr_do_while(?block,?expr,_)) {
+ case (ast::expr_do_while(?block,?expr,_)) {
wrd1(s, "do");
space(s.s);
print_block(s, block);
print_expr(s, expr);
pclose(s);
}
- case (ast.expr_alt(?expr,?arms,_)) {
+ case (ast::expr_alt(?expr,?arms,_)) {
wrd1(s, "alt");
popen_h(s);
print_expr(s, expr);
pclose(s);
space(s.s);
bopen(s);
- for (ast.arm arm in arms) {
+ for (ast::arm arm in arms) {
hbox(s);
wrd1(s, "case");
popen_h(s);
}
bclose_c(s, expr.span);
}
- case (ast.expr_block(?block,_)) {
+ case (ast::expr_block(?block,_)) {
print_block(s, block);
}
- case (ast.expr_assign(?lhs,?rhs,_)) {
+ case (ast::expr_assign(?lhs,?rhs,_)) {
print_expr(s, lhs);
space(s.s);
wrd1(s, "=");
print_expr(s, rhs);
}
- case (ast.expr_assign_op(?op,?lhs,?rhs,_)) {
+ case (ast::expr_assign_op(?op,?lhs,?rhs,_)) {
print_expr(s, lhs);
space(s.s);
- wrd(s.s, ast.binop_to_str(op));
+ wrd(s.s, ast::binop_to_str(op));
wrd1(s, "=");
print_expr(s, rhs);
}
- case (ast.expr_send(?lhs, ?rhs, _)) {
+ case (ast::expr_send(?lhs, ?rhs, _)) {
print_expr(s, lhs);
space(s.s);
wrd1(s, "<|");
print_expr(s, rhs);
}
- case (ast.expr_recv(?lhs, ?rhs, _)) {
+ case (ast::expr_recv(?lhs, ?rhs, _)) {
print_expr(s, lhs);
space(s.s);
wrd1(s, "<-");
print_expr(s, rhs);
}
- case (ast.expr_field(?expr,?id,_)) {
+ case (ast::expr_field(?expr,?id,_)) {
print_expr(s, expr);
wrd(s.s, ".");
wrd(s.s, id);
}
- case (ast.expr_index(?expr,?index,_)) {
+ case (ast::expr_index(?expr,?index,_)) {
print_expr(s, expr);
wrd(s.s, ".");
popen_h(s);
print_expr(s, index);
pclose(s);
}
- case (ast.expr_path(?path,_)) {
+ case (ast::expr_path(?path,_)) {
print_path(s, path);
}
- case (ast.expr_fail(_)) {
+ case (ast::expr_fail(_)) {
wrd(s.s, "fail");
}
- case (ast.expr_break(_)) {
+ case (ast::expr_break(_)) {
wrd(s.s, "break");
}
- case (ast.expr_cont(_)) {
+ case (ast::expr_cont(_)) {
wrd(s.s, "cont");
}
- case (ast.expr_ret(?result,_)) {
+ case (ast::expr_ret(?result,_)) {
wrd(s.s, "ret");
alt (result) {
- case (Option.some[@ast.expr](?expr)) {
+ case (option::some[@ast::expr](?expr)) {
space(s.s);
print_expr(s, expr);
}
case (_) {}
}
}
- case (ast.expr_put(?result,_)) {
+ case (ast::expr_put(?result,_)) {
wrd(s.s, "put");
alt (result) {
- case (Option.some[@ast.expr](?expr)) {
+ case (option::some[@ast::expr](?expr)) {
space(s.s);
print_expr(s, expr);
}
case (_) {}
}
}
- case (ast.expr_be(?result,_)) {
+ case (ast::expr_be(?result,_)) {
wrd1(s, "be");
print_expr(s, result);
}
- case (ast.expr_log(?lvl,?expr,_)) {
+ case (ast::expr_log(?lvl,?expr,_)) {
alt (lvl) {
case (1) {wrd1(s, "log");}
case (0) {wrd1(s, "log_err");}
}
print_expr(s, expr);
}
- case (ast.expr_check(?expr,_)) {
+ case (ast::expr_check(?expr,_)) {
wrd1(s, "check");
popen_h(s);
print_expr(s, expr);
pclose(s);
}
- case (ast.expr_assert(?expr,_)) {
+ case (ast::expr_assert(?expr,_)) {
wrd1(s, "assert");
popen_h(s);
print_expr(s, expr);
pclose(s);
}
- case (ast.expr_ext(?path, ?args, ?body, _, _)) {
+ case (ast::expr_ext(?path, ?args, ?body, _, _)) {
wrd(s.s, "#");
print_path(s, path);
- if (Vec.len[@ast.expr](args) > 0u) {
+ if (_vec::len[@ast::expr](args) > 0u) {
popen(s);
commasep_exprs(s, args);
pclose(s);
}
// FIXME: extension 'body'
}
- case (ast.expr_port(_)) {
+ case (ast::expr_port(_)) {
wrd(s.s, "port");
popen_h(s);
pclose(s);
}
- case (ast.expr_chan(?expr, _)) {
+ case (ast::expr_chan(?expr, _)) {
wrd(s.s, "chan");
popen_h(s);
print_expr(s, expr);
end(s.s);
}
-fn print_decl(ps s, @ast.decl decl) {
+fn print_decl(ps s, @ast::decl decl) {
maybe_print_comment(s, decl.span.lo);
hbox(s);
alt (decl.node) {
- case (ast.decl_local(?loc)) {
+ case (ast::decl_local(?loc)) {
alt (loc.ty) {
- case (Option.some[@ast.ty](?ty)) {
+ case (option::some[@ast::ty](?ty)) {
wrd1(s, "let");
print_type(s, ty);
space(s.s);
}
wrd(s.s, loc.ident);
alt (loc.init) {
- case (Option.some[ast.initializer](?init)) {
+ case (option::some[ast::initializer](?init)) {
space(s.s);
alt (init.op) {
- case (ast.init_assign) {
+ case (ast::init_assign) {
wrd1(s, "=");
}
- case (ast.init_recv) {
+ case (ast::init_recv) {
wrd1(s, "<-");
}
}
case (_) {}
}
}
- case (ast.decl_item(?item)) {
+ case (ast::decl_item(?item)) {
print_item(s, item);
}
}
end(s.s);
}
-fn print_ident(ps s, ast.ident ident) {
+fn print_ident(ps s, ast::ident ident) {
wrd(s.s, ident);
}
-fn print_for_decl(ps s, @ast.decl decl) {
+fn print_for_decl(ps s, @ast::decl decl) {
alt (decl.node) {
- case (ast.decl_local(?loc)) {
- print_type(s, Option.get[@ast.ty](loc.ty));
+ case (ast::decl_local(?loc)) {
+ print_type(s, option::get[@ast::ty](loc.ty));
space(s.s);
wrd(s.s, loc.ident);
}
}
}
-fn print_path(ps s, ast.path path) {
+fn print_path(ps s, ast::path path) {
maybe_print_comment(s, path.span.lo);
auto first = true;
for (str id in path.node.idents) {
else {wrd(s.s, "::");}
wrd(s.s, id);
}
- if (Vec.len[@ast.ty](path.node.types) > 0u) {
+ if (_vec::len[@ast::ty](path.node.types) > 0u) {
wrd(s.s, "[");
auto f = print_type;
- commasep[@ast.ty](s, path.node.types, f);
+ commasep[@ast::ty](s, path.node.types, f);
wrd(s.s, "]");
}
}
-fn print_pat(ps s, &@ast.pat pat) {
+fn print_pat(ps s, &@ast::pat pat) {
maybe_print_comment(s, pat.span.lo);
alt (pat.node) {
- case (ast.pat_wild(_)) {wrd(s.s, "_");}
- case (ast.pat_bind(?id,_,_)) {wrd(s.s, "?" + id);}
- case (ast.pat_lit(?lit,_)) {print_literal(s, lit);}
- case (ast.pat_tag(?path,?args,_)) {
+ case (ast::pat_wild(_)) {wrd(s.s, "_");}
+ case (ast::pat_bind(?id,_,_)) {wrd(s.s, "?" + id);}
+ case (ast::pat_lit(?lit,_)) {print_literal(s, lit);}
+ case (ast::pat_tag(?path,?args,_)) {
print_path(s, path);
- if (Vec.len[@ast.pat](args) > 0u) {
+ if (_vec::len[@ast::pat](args) > 0u) {
popen_h(s);
auto f = print_pat;
- commasep[@ast.pat](s, args, f);
+ commasep[@ast::pat](s, args, f);
pclose(s);
}
}
}
}
-fn print_fn(ps s, ast.fn_decl decl, str name,
- vec[ast.ty_param] typarams) {
+fn print_fn(ps s, ast::fn_decl decl, str name,
+ vec[ast::ty_param] typarams) {
alt (decl.purity) {
- case (ast.impure_fn) {
+ case (ast::impure_fn) {
wrd1(s, "fn");
}
case (_) {
wrd(s.s, name);
print_type_params(s, typarams);
popen(s);
- fn print_arg(ps s, &ast.arg x) {
+ fn print_arg(ps s, &ast::arg x) {
hbox(s);
- if (x.mode == ast.alias) {wrd(s.s, "&");}
+ if (x.mode == ast::alias) {wrd(s.s, "&");}
print_type(s, x.ty);
space(s.s);
wrd(s.s, x.ident);
end(s.s);
}
auto f = print_arg;
- commasep[ast.arg](s, decl.inputs, f);
+ commasep[ast::arg](s, decl.inputs, f);
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(s.s);
hbox(s);
wrd1(s, "->");
}
}
-fn print_type_params(ps s, vec[ast.ty_param] params) {
- if (Vec.len[ast.ty_param](params) > 0u) {
+fn print_type_params(ps s, vec[ast::ty_param] params) {
+ if (_vec::len[ast::ty_param](params) > 0u) {
wrd(s.s, "[");
- fn printParam(ps s, &ast.ty_param param) {
+ fn printParam(ps s, &ast::ty_param param) {
wrd(s.s, param);
}
auto f = printParam;
- commasep[ast.ty_param](s, params, f);
+ commasep[ast::ty_param](s, params, f);
wrd(s.s, "]");
}
}
-fn print_view_item(ps s, @ast.view_item item) {
+fn print_view_item(ps s, @ast::view_item item) {
maybe_print_comment(s, item.span.lo);
hbox(s);
alt (item.node) {
- case (ast.view_item_use(?id,?mta,_,_)) {
+ case (ast::view_item_use(?id,?mta,_,_)) {
wrd1(s, "use");
wrd(s.s, id);
- if (Vec.len[@ast.meta_item](mta) > 0u) {
+ if (_vec::len[@ast::meta_item](mta) > 0u) {
popen(s);
- fn print_meta(ps s, &@ast.meta_item item) {
+ fn print_meta(ps s, &@ast::meta_item item) {
hbox(s);
wrd1(s, item.node.name);
wrd1(s, "=");
end(s.s);
}
auto f = print_meta;
- commasep[@ast.meta_item](s, mta, f);
+ commasep[@ast::meta_item](s, mta, f);
pclose(s);
}
}
- case (ast.view_item_import(?id,?ids,_)) {
+ case (ast::view_item_import(?id,?ids,_)) {
wrd1(s, "import");
- if (!Str.eq(id, ids.(Vec.len[str](ids)-1u))) {
+ if (!_str::eq(id, ids.(_vec::len[str](ids)-1u))) {
wrd1(s, id);
wrd1(s, "=");
}
wrd(s.s, elt);
}
}
- case (ast.view_item_export(?id)) {
+ case (ast::view_item_export(?id)) {
wrd1(s, "export");
wrd(s.s, id);
}
// 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 (front.parser.op_spec spec in front.parser.prec_table()) {
+fn operator_prec(ast::binop op) -> int {
+ for (front::parser::op_spec spec in front::parser::prec_table()) {
if (spec.op == op) {ret spec.prec;}
}
fail;
}
-fn print_maybe_parens(ps s, @ast.expr expr, int outer_prec) {
+fn print_maybe_parens(ps s, @ast::expr expr, int outer_prec) {
auto add_them;
alt (expr.node) {
- case (ast.expr_binary(?op,_,_,_)) {
+ case (ast::expr_binary(?op,_,_,_)) {
add_them = operator_prec(op) < outer_prec;
}
- case (ast.expr_cast(_,_,_)) {
+ case (ast::expr_cast(_,_,_)) {
add_them = as_prec < outer_prec;
}
case (_) {
fn escape_str(str st, char to_escape) -> str {
let str out = "";
- auto len = Str.byte_len(st);
+ auto len = _str::byte_len(st);
auto i = 0u;
while (i < len) {
alt (st.(i) as char) {
case ('\\') {out += "\\\\";}
case (?cur) {
if (cur == to_escape) {out += "\\";}
- Str.push_byte(out, cur as u8);
+ _str::push_byte(out, cur as u8);
}
}
i += 1u;
ret out;
}
-fn print_mt(ps s, &ast.mt mt) {
+fn print_mt(ps s, &ast::mt mt) {
alt (mt.mut) {
- case (ast.mut) { wrd1(s, "mutable"); }
- case (ast.maybe_mut) { wrd1(s, "mutable?"); }
- case (ast.imm) { /* nothing */ }
+ case (ast::mut) { wrd1(s, "mutable"); }
+ case (ast::maybe_mut) { wrd1(s, "mutable?"); }
+ case (ast::imm) { /* nothing */ }
}
print_type(s, mt.ty);
}
wrd(s.s, "\""); wrd(s.s, escape_str(st, '"')); wrd(s.s, "\"");
}
-fn print_ty_fn(ps s, ast.proto proto, Option.t[str] id,
- vec[ast.ty_arg] inputs, @ast.ty output) {
- if (proto == ast.proto_fn) {wrd(s.s, "fn");}
+fn print_ty_fn(ps s, ast::proto proto, option::t[str] id,
+ vec[ast::ty_arg] inputs, @ast::ty output) {
+ if (proto == ast::proto_fn) {wrd(s.s, "fn");}
else {wrd(s.s, "iter");}
alt (id) {
- case (Option.some[str](?id)) {space(s.s); wrd(s.s, id);}
+ case (option::some[str](?id)) {space(s.s); wrd(s.s, id);}
case (_) {}
}
popen_h(s);
- fn print_arg(ps s, &ast.ty_arg input) {
- if (input.mode == ast.alias) {wrd(s.s, "&");}
+ fn print_arg(ps s, &ast::ty_arg input) {
+ if (input.mode == ast::alias) {wrd(s.s, "&");}
print_type(s, input.ty);
}
auto f = print_arg;
- commasep[ast.ty_arg](s, inputs, f);
+ commasep[ast::ty_arg](s, inputs, f);
pclose(s);
maybe_print_comment(s, output.span.lo);
- if (output.node != ast.ty_nil) {
+ if (output.node != ast::ty_nil) {
space(s.s);
hbox(s);
wrd1(s, "->");
}
}
-fn next_comment(ps s) -> Option.t[lexer.cmnt] {
+fn next_comment(ps s) -> option::t[lexer::cmnt] {
alt (s.comments) {
- case (Option.some[vec[lexer.cmnt]](?cmnts)) {
- if (s.cur_cmnt < Vec.len[lexer.cmnt](cmnts)) {
- ret Option.some[lexer.cmnt](cmnts.(s.cur_cmnt));
- } else {ret Option.none[lexer.cmnt];}
+ case (option::some[vec[lexer::cmnt]](?cmnts)) {
+ if (s.cur_cmnt < _vec::len[lexer::cmnt](cmnts)) {
+ ret option::some[lexer::cmnt](cmnts.(s.cur_cmnt));
+ } else {ret option::none[lexer::cmnt];}
}
- case (_) {ret Option.none[lexer.cmnt];}
+ case (_) {ret option::none[lexer::cmnt];}
}
}
fn maybe_print_comment(ps s, uint pos) {
while (true) {
alt (next_comment(s)) {
- case (Option.some[lexer.cmnt](?cmnt)) {
+ case (option::some[lexer::cmnt](?cmnt)) {
if (cmnt.pos < pos) {
print_comment(s, cmnt.val);
if (cmnt.space_after) {line(s.s);}
}
}
-fn maybe_print_line_comment(ps s, common.span span) -> bool {
+fn maybe_print_line_comment(ps s, common::span span) -> bool {
alt (next_comment(s)) {
- case (Option.some[lexer.cmnt](?cmnt)) {
+ case (option::some[lexer::cmnt](?cmnt)) {
if (span.hi + 4u >= cmnt.pos) {
wrd(s.s, " ");
print_comment(s, cmnt.val);
fn print_remaining_comments(ps s) {
while (true) {
alt (next_comment(s)) {
- case (Option.some[lexer.cmnt](?cmnt)) {
+ case (option::some[lexer::cmnt](?cmnt)) {
print_comment(s, cmnt.val);
if (cmnt.space_after) {line(s.s);}
s.cur_cmnt += 1u;
}
}
-fn print_comment(ps s, lexer.cmnt_ cmnt) {
+fn print_comment(ps s, lexer::cmnt_ cmnt) {
alt (cmnt) {
- case (lexer.cmnt_line(?val)) {
+ case (lexer::cmnt_line(?val)) {
wrd(s.s, "// " + val);
- pp.hardbreak(s.s);
+ pp::hardbreak(s.s);
}
- case (lexer.cmnt_block(?lines)) {
- pp.abox(s.s);
+ case (lexer::cmnt_block(?lines)) {
+ pp::abox(s.s);
wrd(s.s, "/* ");
- pp.abox(s.s);
+ pp::abox(s.s);
auto first = true;
for (str ln in lines) {
if (first) {first = false;}
- else {pp.hardbreak(s.s);}
+ else {pp::hardbreak(s.s);}
wrd(s.s, ln);
}
end(s.s);
mod typestate_ann;
}
-auth front.creader.load_crate = unsafe;
-auth front.creader.get_metadata_section = unsafe;
-auth middle.metadata = unsafe;
-auth middle.trans = unsafe;
-auth lib.llvm = unsafe;
+auth front::creader::load_crate = unsafe;
+auth front::creader::get_metadata_section = unsafe;
+auth middle::metadata = unsafe;
+auth middle::trans = unsafe;
+auth lib::llvm = unsafe;
mod lib {
alt (target_os) {
-import std.Map;
-import std.Map.hashmap;
-import std.UInt;
-import std.Int;
-import std.Vec;
-import std.Option.none;
-import front.ast;
-import util.typestate_ann.ts_ann;
-
-import middle.fold;
-import middle.fold.respan;
-
-import std.IO.stdout;
-import std.IO.str_writer;
-import std.IO.string_writer;
-import pretty.pprust.print_block;
-import pretty.pprust.print_expr;
-import pretty.pprust.print_decl;
-import pretty.pprust.print_fn;
-import pretty.pp.mkstate;
+import std::map;
+import std::map::hashmap;
+import std::_uint;
+import std::_int;
+import std::_vec;
+import std::option::none;
+import front::ast;
+import util::typestate_ann::ts_ann;
+
+import middle::fold;
+import middle::fold::respan;
+
+import std::io::stdout;
+import std::io::str_writer;
+import std::io::string_writer;
+import pretty::pprust::print_block;
+import pretty::pprust::print_expr;
+import pretty::pprust::print_decl;
+import pretty::pprust::print_fn;
+import pretty::pp::mkstate;
type filename = str;
type span = rec(uint lo, uint hi);
}
}
-fn new_str_hash[V]() -> std.Map.hashmap[str,V] {
- let std.Map.hashfn[str] hasher = std.Str.hash;
- let std.Map.eqfn[str] eqer = std.Str.eq;
- ret std.Map.mk_hashmap[str,V](hasher, eqer);
+fn new_str_hash[V]() -> std::map::hashmap[str,V] {
+ let std::map::hashfn[str] hasher = std::_str::hash;
+ let std::map::eqfn[str] eqer = std::_str::eq;
+ ret std::map::mk_hashmap[str,V](hasher, eqer);
}
-fn def_eq(&ast.def_id a, &ast.def_id b) -> bool {
+fn def_eq(&ast::def_id a, &ast::def_id b) -> bool {
ret a._0 == b._0 && a._1 == b._1;
}
-fn hash_def(&ast.def_id d) -> uint {
+fn hash_def(&ast::def_id d) -> uint {
auto h = 5381u;
h = ((h << 5u) + h) ^ (d._0 as uint);
h = ((h << 5u) + h) ^ (d._1 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;
- ret std.Map.mk_hashmap[ast.def_id,V](hasher, eqer);
+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;
+ ret std::map::mk_hashmap[ast::def_id,V](hasher, eqer);
}
-fn new_int_hash[V]() -> std.Map.hashmap[int,V] {
+fn new_int_hash[V]() -> std::map::hashmap[int,V] {
fn hash_int(&int x) -> uint { ret x as uint; }
fn eq_int(&int a, &int b) -> bool { ret a == b; }
auto hasher = hash_int;
auto eqer = eq_int;
- ret std.Map.mk_hashmap[int,V](hasher, eqer);
+ ret std::map::mk_hashmap[int,V](hasher, eqer);
}
-fn new_uint_hash[V]() -> std.Map.hashmap[uint,V] {
+fn new_uint_hash[V]() -> std::map::hashmap[uint,V] {
fn hash_uint(&uint x) -> uint { ret x; }
fn eq_uint(&uint a, &uint b) -> bool { ret a == b; }
auto hasher = hash_uint;
auto eqer = eq_uint;
- ret std.Map.mk_hashmap[uint,V](hasher, eqer);
+ ret std::map::mk_hashmap[uint,V](hasher, eqer);
}
fn istr(int i) -> str {
- ret Int.to_str(i, 10u);
+ ret _int::to_str(i, 10u);
}
fn uistr(uint i) -> str {
- ret UInt.to_str(i, 10u);
+ ret _uint::to_str(i, 10u);
}
-fn elt_expr(&ast.elt e) -> @ast.expr { ret e.expr; }
+fn elt_expr(&ast::elt e) -> @ast::expr { ret e.expr; }
-fn elt_exprs(&vec[ast.elt] elts) -> vec[@ast.expr] {
+fn elt_exprs(&vec[ast::elt] elts) -> vec[@ast::expr] {
auto f = elt_expr;
- ret Vec.map[ast.elt, @ast.expr](f, elts);
+ ret _vec::map[ast::elt, @ast::expr](f, elts);
}
-fn field_expr(&ast.field f) -> @ast.expr { ret f.expr; }
+fn field_expr(&ast::field f) -> @ast::expr { ret f.expr; }
-fn field_exprs(vec[ast.field] fields) -> vec [@ast.expr] {
+fn field_exprs(vec[ast::field] fields) -> vec [@ast::expr] {
auto f = field_expr;
- ret Vec.map[ast.field, @ast.expr](f, fields);
+ ret _vec::map[ast::field, @ast::expr](f, fields);
}
-fn plain_ann(&ast.ann old, middle.ty.ctxt tcx) -> ast.ann {
- ret ast.ann_type(ast.ann_tag(old), middle.ty.mk_nil(tcx),
- none[vec[middle.ty.t]], none[@ts_ann]);
+fn plain_ann(&ast::ann old, middle::ty::ctxt tcx) -> ast::ann {
+ ret ast::ann_type(ast::ann_tag(old), middle::ty::mk_nil(tcx),
+ none[vec[middle::ty::t]], none[@ts_ann]);
}
-fn expr_to_str(&@ast.expr e) -> str {
+fn expr_to_str(&@ast::expr e) -> str {
let str_writer s = string_writer();
auto out_ = mkstate(s.get_writer(), 80u);
auto out = @rec(s=out_,
- comments=none[vec[front.lexer.cmnt]],
+ comments=none[vec[front::lexer::cmnt]],
mutable cur_cmnt=0u);
print_expr(out, e);
ret s.get_str();
}
-fn log_expr(&ast.expr e) -> () {
+fn log_expr(&ast::expr e) -> () {
log(expr_to_str(@e));
}
-fn log_expr_err(&ast.expr e) -> () {
+fn log_expr_err(&ast::expr e) -> () {
log_err(expr_to_str(@e));
}
-fn block_to_str(&ast.block b) -> str {
+fn block_to_str(&ast::block b) -> str {
let str_writer s = string_writer();
auto out_ = mkstate(s.get_writer(), 80u);
auto out = @rec(s=out_,
- comments=none[vec[front.lexer.cmnt]],
+ comments=none[vec[front::lexer::cmnt]],
mutable cur_cmnt=0u);
print_block(out, b);
ret s.get_str();
}
-fn log_block(&ast.block b) -> () {
+fn log_block(&ast::block b) -> () {
log(block_to_str(b));
}
-fn log_block_err(&ast.block b) -> () {
+fn log_block_err(&ast::block b) -> () {
log_err(block_to_str(b));
}
-fn log_ann(&ast.ann a) -> () {
+fn log_ann(&ast::ann a) -> () {
alt (a) {
- case (ast.ann_none(_)) {
+ case (ast::ann_none(_)) {
log("ann_none");
}
- case (ast.ann_type(_,_,_,_)) {
+ case (ast::ann_type(_,_,_,_)) {
log("ann_type");
}
}
}
-fn fun_to_str(&ast._fn f, str name, vec[ast.ty_param] params) -> str {
+fn fun_to_str(&ast::_fn f, str name, vec[ast::ty_param] params) -> str {
let str_writer s = string_writer();
auto out_ = mkstate(s.get_writer(), 80u);
auto out = @rec(s=out_,
- comments=none[vec[front.lexer.cmnt]],
+ comments=none[vec[front::lexer::cmnt]],
mutable cur_cmnt=0u);
print_fn(out, f.decl, name, params);
ret s.get_str();
}
-fn log_fn(&ast._fn f, str name, vec[ast.ty_param] params) -> () {
+fn log_fn(&ast::_fn f, str name, vec[ast::ty_param] params) -> () {
log(fun_to_str(f, name, params));
}
-fn log_fn_err(&ast._fn f, str name, vec[ast.ty_param] params) -> () {
+fn log_fn_err(&ast::_fn f, str name, vec[ast::ty_param] params) -> () {
log_err(fun_to_str(f, name, params));
}
-fn stmt_to_str(&ast.stmt st) -> str {
+fn stmt_to_str(&ast::stmt st) -> str {
let str_writer s = string_writer();
auto out_ = mkstate(s.get_writer(), 80u);
auto out = @rec(s=out_,
- comments=none[vec[front.lexer.cmnt]],
+ comments=none[vec[front::lexer::cmnt]],
mutable cur_cmnt=0u);
alt (st.node) {
- case (ast.stmt_decl(?decl,_)) {
+ case (ast::stmt_decl(?decl,_)) {
print_decl(out, decl);
}
- case (ast.stmt_expr(?ex,_)) {
+ case (ast::stmt_expr(?ex,_)) {
print_expr(out, ex);
}
case (_) { /* do nothing */ }
ret s.get_str();
}
-fn log_stmt(&ast.stmt st) -> () {
+fn log_stmt(&ast::stmt st) -> () {
log(stmt_to_str(st));
}
-fn log_stmt_err(&ast.stmt st) -> () {
+fn log_stmt_err(&ast::stmt st) -> () {
log_err(stmt_to_str(st));
}
-fn decl_lhs(@ast.decl d) -> ast.def_id {
+fn decl_lhs(@ast::decl d) -> ast::def_id {
alt (d.node) {
- case (ast.decl_local(?l)) {
+ case (ast::decl_local(?l)) {
ret l.id;
}
- case (ast.decl_item(?an_item)) {
+ case (ast::decl_item(?an_item)) {
alt (an_item.node) {
- case (ast.item_const(_,_,_,?d,_)) {
+ case (ast::item_const(_,_,_,?d,_)) {
ret d;
}
- case (ast.item_fn(_,_,_,?d,_)) {
+ case (ast::item_fn(_,_,_,?d,_)) {
ret d;
}
- case (ast.item_mod(_,_,?d)) {
+ case (ast::item_mod(_,_,?d)) {
ret d;
}
- case (ast.item_native_mod(_,_,?d)) {
+ case (ast::item_native_mod(_,_,?d)) {
ret d;
}
- case (ast.item_ty(_,_,_,?d,_)) {
+ case (ast::item_ty(_,_,_,?d,_)) {
ret d;
}
- case (ast.item_tag(_,_,_,?d,_)) {
+ case (ast::item_tag(_,_,_,?d,_)) {
ret d;
}
- case (ast.item_obj(_,_,_,?d,_)) {
+ case (ast::item_obj(_,_,_,?d,_)) {
ret d.ctor; /* This doesn't really make sense */
}
}
}
}
-fn has_nonlocal_exits(&ast.block b) -> bool {
+fn has_nonlocal_exits(&ast::block b) -> bool {
/* overkill, but just passing around a mutable bool doesn't seem
to work in rustboot */
auto has_exits = new_str_hash[()]();
- fn set_break(&flag f, &span sp, &ast.ann a) -> @ast.expr {
+ fn set_break(&flag f, &span sp, &ast::ann a) -> @ast::expr {
f.insert("foo", ());
- ret @respan(sp, ast.expr_break(a));
+ ret @respan(sp, ast::expr_break(a));
}
- fn set_cont(&flag f, &span sp, &ast.ann a) -> @ast.expr {
+ fn set_cont(&flag f, &span sp, &ast::ann a) -> @ast::expr {
f.insert("foo", ());
- ret @respan(sp, ast.expr_cont(a));
+ ret @respan(sp, ast::expr_cont(a));
}
fn check_b(&flag f) -> bool {
ret (f.size() == 0u);
}
- auto fld0 = fold.new_identity_fold[flag]();
+ auto fld0 = fold::new_identity_fold[flag]();
fld0 = @rec(fold_expr_break = bind set_break(_,_,_),
fold_expr_cont = bind set_cont(_,_,_),
keep_going = bind check_b(_) with *fld0);
- fold.fold_block[flag](has_exits, fld0, b);
+ fold::fold_block[flag](has_exits, fld0, b);
ret (has_exits.size() > 0u);
}
-import front.ast.ident;
-import std.Vec;
-import std.BitV;
+import front::ast::ident;
+import std::_vec;
+import std::bitv;
/*
This says: this expression requires the idents in <pre> to be initialized,
and given the precondition, it guarantees that the idents in <post> are
initialized.
*/
-type precond = BitV.t; /* 1 means "this variable must be initialized"
+type precond = bitv::t; /* 1 means "this variable must be initialized"
0 means "don't care about this variable" */
-type postcond = BitV.t; /* 1 means "this variable is initialized"
+type postcond = bitv::t; /* 1 means "this variable is initialized"
0 means "don't know about this variable */
-type prestate = BitV.t; /* 1 means "this variable is definitely initialized"
+type prestate = bitv::t; /* 1 means "this variable is definitely initialized"
0 means "don't know whether this variable is
initialized" */
-type poststate = BitV.t; /* 1 means "this variable is definitely initialized"
+type poststate = bitv::t; /* 1 means "this variable is definitely initialized"
0 means "don't know whether this variable is
initialized" */
type ts_ann = rec(pre_and_post conditions, pre_and_post_state states);
fn true_precond(uint num_vars) -> precond {
- be BitV.create(num_vars, false);
+ be bitv::create(num_vars, false);
}
fn true_postcond(uint num_vars) -> postcond {
}
fn false_postcond(uint num_vars) -> postcond {
- be BitV.create(num_vars, true);
+ be bitv::create(num_vars, true);
}
fn empty_pre_post(uint num_vars) -> pre_and_post {
}
fn difference(&precond p1, &precond p2) -> bool {
- be BitV.difference(p1, p2);
+ be bitv::difference(p1, p2);
}
fn union(&precond p1, &precond p2) -> bool {
- be BitV.union(p1, p2);
+ be bitv::union(p1, p2);
}
fn intersect(&precond p1, &precond p2) -> bool {
- be BitV.intersect(p1, p2);
+ be bitv::intersect(p1, p2);
}
fn pps_len(&pre_and_post p) -> uint {
fn require_and_preserve(uint i, &pre_and_post p) -> () {
// sets the ith bit in p's pre and post
- BitV.set(p.precondition, i, true);
- BitV.set(p.postcondition, i, true);
+ bitv::set(p.precondition, i, true);
+ bitv::set(p.postcondition, i, true);
}
fn set_in_postcond(uint i, &pre_and_post p) -> bool {
// sets the ith bit in p's post
- auto was_set = BitV.get(p.postcondition, i);
- BitV.set(p.postcondition, i, true);
+ auto was_set = bitv::get(p.postcondition, i);
+ bitv::set(p.postcondition, i, true);
ret !was_set;
}
fn set_in_poststate(uint i, &pre_and_post_state s) -> bool {
// sets the ith bit in p's post
- auto was_set = BitV.get(s.poststate, i);
- BitV.set(s.poststate, i, true);
+ auto was_set = bitv::get(s.poststate, i);
+ bitv::set(s.poststate, i, true);
ret !was_set;
}
// 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) -> () {
- BitV.copy(a.conditions.precondition, p);
+ bitv::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) -> () {
- BitV.copy(a.conditions.postcondition, p);
+ bitv::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 {
- ret BitV.copy(a.states.prestate, p);
+ ret bitv::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 {
- ret BitV.copy(a.states.poststate, p);
+ ret bitv::copy(a.states.poststate, p);
}
// Set all the bits in p that are set in new
fn extend_prestate(&prestate p, &poststate new) -> bool {
- ret BitV.union(p, new);
+ ret bitv::union(p, new);
}
// Set all the bits in p that are set in new
fn extend_poststate(&poststate p, &poststate new) -> bool {
- ret BitV.union(p, new);
+ ret bitv::union(p, new);
}
// Clears the given bit in p
fn relax_prestate(uint i, &prestate p) -> bool {
- auto was_set = BitV.get(p, i);
- BitV.set(p, i, false);
+ auto was_set = bitv::get(p, i);
+ bitv::set(p, i, false);
ret was_set;
}
}
fn clone(prestate p) -> prestate {
- ret BitV.clone(p);
+ ret bitv::clone(p);
}
// returns true if a implies b
// that is, returns true except if for some bits c and d,
// c = 1 and d = 0
-fn implies(BitV.t a, BitV.t b) -> bool {
- auto tmp = BitV.clone(b);
- BitV.difference(tmp, a);
- ret BitV.is_false(tmp);
+fn implies(bitv::t a, bitv::t b) -> bool {
+ auto tmp = bitv::clone(b);
+ bitv::difference(tmp, a);
+ ret bitv::is_false(tmp);
}
//
+++ /dev/null
-// FIXME: With recursive object types, we could implement binary methods like
-// union, intersection, and difference. At that point, we could write
-// an optimizing version of this module that produces a different obj
-// for the case where nbits <= 32.
-
-// FIXME: Almost all the functions in this module should be state fns, but the
-// effect system isn't currently working correctly.
-
-state type t = rec(vec[mutable uint] storage, uint nbits);
-
-// 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) {
- elt = ~0u;
- } else {
- elt = 0u;
- }
-
- auto storage = Vec.init_elt_mut[uint](elt, nbits / uint_bits() + 1u);
- ret rec(storage = storage, nbits = nbits);
-}
-
-fn process(&fn(uint, uint) -> uint op, &t v0, &t v1) -> bool {
- auto len = Vec.len(v1.storage);
-
- assert (Vec.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;
- }
- }
-
- ret changed;
-}
-
-fn lor(uint w0, uint w1) -> uint {
- ret w0 | w1;
-}
-
-fn union(&t v0, &t v1) -> bool {
- auto sub = lor;
- ret process(sub, v0, v1);
-}
-
-fn land(uint w0, uint w1) -> uint {
- ret w0 & w1;
-}
-
-fn intersect(&t v0, &t v1) -> bool {
- auto sub = land;
- ret process(sub, v0, v1);
-}
-
-fn right(uint w0, uint w1) -> uint {
- ret w1;
-}
-
-fn copy(&t v0, t v1) -> bool {
- auto sub = right;
- ret process(sub, v0, v1);
-}
-
-fn clone(t v) -> t {
- auto storage = Vec.init_elt_mut[uint](0u, v.nbits / uint_bits() + 1u);
- auto len = Vec.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 get(&t v, uint i) -> bool {
- assert (i < v.nbits);
-
- auto bits = uint_bits();
-
- auto w = i / bits;
- auto b = i % bits;
- auto x = 1u & (v.storage.(w) >> b);
- ret x == 1u;
-}
-
-fn equal(&t v0, &t v1) -> bool {
- // FIXME: when we can break or return from inside an iterator loop,
- // we can eliminate this painful while-loop
- auto len = Vec.len(v1.storage);
- auto 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, Vec.len(v.storage))) {
- v.storage.(i) = 0u;
- }
-}
-
-fn invert(&t v) {
- for each (uint i in UInt.range(0u, Vec.len(v.storage))) {
- v.storage.(i) = ~v.storage.(i);
- }
-}
-
-/* v0 = v0 - v1 */
-fn difference(&t v0, &t v1) -> bool {
- invert(v1);
- auto b = intersect(v0, v1);
- invert(v1);
- ret b;
-}
-
-fn set(&t v, uint i, bool x) {
- assert (i < v.nbits);
-
- auto bits = uint_bits();
-
- auto w = i / bits;
- auto b = i % bits;
- auto w0 = v.storage.(w);
- auto flag = 1u << b;
- if (x) {
- v.storage.(w) = v.storage.(w) | flag;
- } else {
- v.storage.(w) = v.storage.(w) & ~flag;
- }
-}
-
-/* true if all bits are 1 */
-fn is_true(&t v) -> bool {
- for (uint i in to_vec(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_vec(v)) {
- if (i == 1u) {
- ret false;
- }
- }
-
- ret true;
-}
-
-fn init_to_vec(t v, uint i) -> uint {
- if (get(v, i)) {
- ret 1u;
- } else {
- ret 0u;
- }
-}
-
-fn to_vec(&t v) -> vec[uint] {
- auto sub = bind init_to_vec(v, _);
- ret Vec.init_fn[uint](sub, v.nbits);
-}
-
-fn to_str(&t v) -> str {
- auto res = "";
-
- for (uint i in BitV.to_vec(v)) {
- if (i == 1u) {
- res += "1";
- }
- else {
- res += "0";
- }
- }
-
- ret res;
-}
-
-// FIXME: can we just use structural equality on to_vec?
-fn eq_vec(&t v0, &vec[uint] v1) -> 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;
- }
- i = i + 1u;
- }
- ret true;
-}
-
-//
-// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
-//
+++ /dev/null
-export rustrt;
-
-native "rust" mod rustrt {
- fn rust_ptr_eq[T](@T a, @T b) -> int;
-}
-
-fn ptr_eq[T](@T a, @T b) -> bool { ret rustrt.rust_ptr_eq[T](a, b) != 0; }
-
+++ /dev/null
-/**
- * Unsafe debugging functions for inspecting values.
- *
- * Your RUST_LOG environment variable must contain "stdlib" for any debug
- * logging.
- */
-
-// FIXME: handle 64-bit case.
-const uint const_refcount = 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_vec[T](vec[T] v) {
- 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_box[T](@T x) {
- rustrt.debug_box[T](x);
-}
-
-fn debug_tag[T](&T x) {
- rustrt.debug_tag[T](x);
-}
-
-/**
- * `nmethods` is the number of methods we expect the object to have. The
- * runtime will print this many words of the obj vtbl).
- *
- * `nbytes` is the number of bytes of body data we expect the object to have.
- * The runtime will print this many bytes of the obj body. You probably want
- * 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) {
- rustrt.debug_obj[T](x, nmethods, nbytes);
-}
-
-fn debug_fn[T](&T x) {
- rustrt.debug_fn[T](x);
-}
-
-fn ptr_cast[T, U](@T x) -> @U {
- ret rustrt.debug_ptrcast[T, U](x);
-}
-
-fn trap(str s) {
- rustrt.debug_trap(s);
-}
-
-// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
+++ /dev/null
-/**
- * A deque, for fun. Untested as of yet. Likely buggy.
- */
-
-type t[T] = obj {
- fn size() -> uint;
-
- fn add_front(&T t);
- fn add_back(&T t);
-
- fn pop_front() -> T;
- fn pop_back() -> T;
-
- fn peek_front() -> T;
- fn peek_back() -> T;
-
- fn get(int i) -> T;
-};
-
-fn create[T]() -> t[T] {
-
- type cell[T] = Option.t[T];
-
- let uint initial_capacity = 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, vec[cell[T]] elts) -> vec[cell[T]] {
- assert (nelts == Vec.len[cell[T]](elts));
-
- fn fill[T](uint i, uint nelts, uint lo,
- vec[cell[T]] old) -> cell[T] {
- if (i < nelts) {
- ret old.((lo + i) % nelts);
- } else {
- ret Option.none[T];
- }
- }
-
- let uint nalloc = UInt.next_power_of_two(nelts + 1u);
- let Vec.init_op[cell[T]] copy_op = bind fill[T](_, nelts, lo, elts);
- ret Vec.init_fn[cell[T]](copy_op, nalloc);
- }
-
- fn get[T](vec[cell[T]] elts, uint i) -> T {
- alt (elts.(i)) {
- case (Option.some[T](?t)) { ret t; }
- case (_) { fail; }
- }
- fail; // FIXME: remove me when exhaustiveness checking works
- }
-
- obj deque[T](mutable uint nelts,
- mutable uint lo,
- mutable uint hi,
- mutable vec[cell[T]] elts)
- {
- fn size() -> uint { ret nelts; }
-
- fn add_front(&T t) {
- let uint oldlo = lo;
-
- if (lo == 0u) {
- lo = Vec.len[cell[T]](elts) - 1u;
- } else {
- lo -= 1u;
- }
-
- if (lo == hi) {
- elts = grow[T](nelts, oldlo, elts);
- lo = Vec.len[cell[T]](elts) - 1u;
- hi = nelts;
- }
-
- elts.(lo) = Option.some[T](t);
- nelts += 1u;
- }
-
- fn add_back(&T t) {
- if (lo == hi && nelts != 0u) {
- elts = grow[T](nelts, lo, elts);
- lo = 0u;
- hi = nelts;
- }
-
- elts.(hi) = Option.some[T](t);
- hi = (hi + 1u) % Vec.len[cell[T]](elts);
- nelts += 1u;
- }
-
- /**
- * We actually release (turn to none()) the T we're popping so
- * that we don't keep anyone's refcount up unexpectedly.
- */
- fn pop_front() -> T {
- let T t = get[T](elts, lo);
- elts.(lo) = Option.none[T];
- lo = (lo + 1u) % Vec.len[cell[T]](elts);
- nelts -= 1u;
- ret t;
- }
-
- fn pop_back() -> T {
- if (hi == 0u) {
- hi = Vec.len[cell[T]](elts) - 1u;
- } 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)) % Vec.len[cell[T]](elts);
- ret get[T](elts, idx);
- }
-
- }
- let vec[cell[T]] v = Vec.init_elt[cell[T]](Option.none[T],
- initial_capacity);
-
- ret deque[T](0u, 0u, 0u, v);
-}
-
-// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
+++ /dev/null
-// Simple Extensible Binary Markup Language (EBML) reader and writer on a
-// cursor model. See the specification here:
-// http://www.matroska.org/technical/specs/rfc/index.html
-
-import Option.none;
-import Option.some;
-
-type ebml_tag = rec(uint id, uint size);
-type ebml_state = rec(ebml_tag ebml_tag, uint tag_pos, uint data_pos);
-
-// 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);
-
-fn vint_at(vec[u8] data, uint start) -> tup(uint, uint) {
- auto a = data.(start);
- if (a & 0x80u8 != 0u8) { ret tup((a & 0x7fu8) as uint, start + 1u); }
- if (a & 0x40u8 != 0u8) {
- ret tup((((a & 0x3fu8) as uint) << 8u) | (data.(start + 1u) as uint),
- start + 2u);
- } else if (a & 0x20u8 != 0u8) {
- ret tup((((a & 0x1fu8) as uint) << 16u) |
- ((data.(start + 1u) as uint) << 8u) |
- (data.(start + 2u) as uint), start + 3u);
- } else if (a & 0x10u8 != 0u8) {
- ret tup((((a & 0x0fu8) as uint) << 24u) |
- ((data.(start + 1u) as uint) << 16u) |
- ((data.(start + 2u) as uint) << 8u) |
- (data.(start + 3u) as uint), 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 doc_at(vec[u8] data, uint start) -> doc {
- auto elt_tag = vint_at(data, start);
- auto elt_size = vint_at(data, elt_tag._1);
- auto end = elt_size._1 + elt_size._0;
- ret rec(data=data, start=elt_size._1, 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._1);
- pos = elt_size._1 + elt_size._0;
- if (elt_tag._0 == tg) {
- ret some[doc](rec(data=d.data, start=elt_size._1, end=pos));
- }
- }
- ret none[doc];
-}
-
-fn get_doc(doc d, uint tg) -> doc {
- alt (maybe_get_doc(d, tg)) {
- case (some[doc](?d)) {ret d;}
- case (none[doc]) {
- log_err "failed to find block with tag " + UInt.to_str(tg, 10u);
- fail;
- }
- }
-}
-
-iter docs(doc d) -> tup(uint, 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._1);
- pos = elt_size._1 + elt_size._0;
- put tup(elt_tag._0, rec(data=d.data, start=elt_size._1, end=pos));
- }
-}
-
-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._1);
- pos = elt_size._1 + elt_size._0;
- if (elt_tag._0 == tg) {
- put rec(data=d.data, start=elt_size._1, 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;
- assert (sz <= 4u);
- auto val = 0u;
- auto pos = start;
- while (sz > 0u) {
- sz -= 1u;
- val += (data.(pos) as uint) << (sz * 8u);
- pos += 1u;
- }
- ret val;
-}
-
-fn doc_as_uint(doc d) -> 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);
-
-fn write_sized_vint(&IO.buf_writer w, uint n, uint size) {
- let vec[u8] buf;
- alt (size) {
- case (1u) {
- buf = vec(0x80u8 | (n as u8));
- }
- case (2u) {
- buf = vec(0x40u8 | ((n >> 8u) as u8),
- (n & 0xffu) as u8);
- }
- case (3u) {
- buf = vec(0x20u8 | ((n >> 16u) as u8),
- ((n >> 8u) & 0xffu) as u8,
- (n & 0xffu) as u8);
- }
- case (4u) {
- buf = vec(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;
- }
- }
-
- 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; }
- log_err "vint to write too big";
- fail;
-}
-
-fn create_writer(&IO.buf_writer w) -> writer {
- let vec[uint] size_positions = vec();
- ret rec(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) {
- // Write the tag ID.
- write_vint(w.writer, tag_id);
-
- // Write a placeholder four-byte size.
- w.size_positions += vec(w.writer.tell());
- let vec[u8] zeroes = vec(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();
- 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);
-}
-
-// TODO: optionally perform "relaxations" on end_tag to more efficiently
-// encode sizes; this is a fixed point iteration
+++ /dev/null
-/* The 'fmt' extension is modeled on the posix printf system.
- *
- * A posix conversion ostensibly looks like this:
- *
- * %[parameter][flags][width][.precision][length]type
- *
- * Given the different numeric type bestiary we have, we omit the 'length'
- * parameter and support slightly different conversions for 'type':
- *
- * %[parameter][flags][width][.precision]type
- *
- * we also only support translating-to-rust a tiny subset of the possible
- * combinations at the moment.
- */
-
-import Option.none;
-import Option.some;
-
-/*
- * We have a CT (compile-time) module that parses format strings into a
- * sequence of conversions. From those conversions AST fragments are built
- * that call into properly-typed functions in the RT (run-time) module. Each
- * of those run-time conversion functions accepts another conversion
- * description that specifies how to format its output.
- *
- * The building of the AST is currently done in a module inside the compiler,
- * but should migrate over here as the plugin interface is defined.
- */
-
-// Functions used by the fmt extension at compile time
-mod CT {
- tag signedness {
- signed;
- unsigned;
- }
-
- tag caseness {
- case_upper;
- case_lower;
- }
-
- tag ty {
- ty_bool;
- ty_str;
- ty_char;
- ty_int(signedness);
- ty_bits;
- ty_hex(caseness);
- ty_octal;
- // FIXME: More types
- }
-
- tag flag {
- flag_left_justify;
- flag_left_zero_pad;
- flag_space_for_sign;
- flag_sign_always;
- flag_alternate;
- }
-
- tag count {
- count_is(int);
- count_is_param(int);
- count_is_next_param;
- count_implied;
- }
-
- // 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);
-
- // A fragment of the output sequence
- tag piece {
- piece_string(str);
- piece_conv(conv);
- }
-
- fn parse_fmt_string(str s) -> vec[piece] {
- let vec[piece] pieces = vec();
- auto lim = Str.byte_len(s);
- auto buf = "";
-
- fn flush_buf(str buf, &vec[piece] pieces) -> str {
- if (Str.byte_len(buf) > 0u) {
- auto piece = piece_string(buf);
- pieces += vec(piece);
- }
- ret "";
- }
-
- auto i = 0u;
- while (i < lim) {
- auto curr = Str.substr(s, i, 1u);
- if (Str.eq(curr, "%")) {
- i += 1u;
- if (i >= lim) {
- log_err "unterminated conversion at end of string";
- fail;
- }
- auto curr2 = Str.substr(s, i, 1u);
- if (Str.eq(curr2, "%")) {
- i += 1u;
- } else {
- buf = flush_buf(buf, pieces);
- auto res = parse_conversion(s, i, lim);
- pieces += vec(res._0);
- i = res._1;
- }
- } else {
- buf += curr;
- i += 1u;
- }
- }
- buf = flush_buf(buf, pieces);
- ret pieces;
- }
-
- fn peek_num(str s, uint i, uint lim) -> Option.t[tup(uint, uint)] {
- if (i >= lim) {
- ret none[tup(uint, uint)];
- }
-
- auto c = s.(i);
- if (!('0' as u8 <= c && c <= '9' as u8)) {
- ret Option.none[tup(uint, uint)];
- }
-
- auto n = (c - ('0' as u8)) as uint;
- alt (peek_num(s, i + 1u, lim)) {
- case (none[tup(uint, uint)]) {
- ret some[tup(uint, uint)](tup(n, i + 1u));
- }
- case (some[tup(uint, uint)](?next)) {
- auto m = next._0;
- auto j = next._1;
- ret some[tup(uint, uint)](tup(n * 10u + m, j));
- }
- }
-
- }
-
- fn parse_conversion(str s, uint i, uint lim) -> tup(piece, uint) {
- auto parm = parse_parameter(s, i, lim);
- auto flags = parse_flags(s, parm._1, lim);
- auto width = parse_count(s, flags._1, lim);
- auto prec = parse_precision(s, width._1, lim);
- auto ty = parse_type(s, prec._1, lim);
- ret tup(piece_conv(rec(param = parm._0,
- flags = flags._0,
- width = width._0,
- precision = prec._0,
- ty = ty._0)),
- ty._1);
- }
-
- fn parse_parameter(str s, uint i, uint lim) -> tup(Option.t[int], uint) {
- if (i >= lim) {
- ret tup(none[int], i);
- }
-
- auto num = peek_num(s, i, lim);
- alt (num) {
- case (none[tup(uint, uint)]) {
- ret tup(none[int], i);
- }
- case (some[tup(uint, uint)](?t)) {
- auto n = t._0;
- auto j = t._1;
- if (j < lim && s.(j) == '$' as u8) {
- ret tup(some[int](n as int), j + 1u);
- }
- else {
- ret tup(none[int], i);
- }
- }
- }
- }
-
- fn parse_flags(str s, uint i, uint lim) -> tup(vec[flag], uint) {
- let vec[flag] noflags = vec();
-
- if (i >= lim) {
- ret tup(noflags, i);
- }
-
- fn more_(flag f, str s, uint i, uint lim) -> tup(vec[flag], uint) {
- auto next = parse_flags(s, i + 1u, lim);
- auto rest = next._0;
- auto j = next._1;
- let vec[flag] curr = vec(f);
- ret tup(curr + rest, j);
- }
-
- auto more = bind more_(_, s, i, lim);
-
- auto f = s.(i);
- if (f == ('-' as u8)) {
- ret more(flag_left_justify);
- } else if (f == ('0' as u8)) {
- ret more(flag_left_zero_pad);
- } else if (f == (' ' as u8)) {
- ret more(flag_space_for_sign);
- } else if (f == ('+' as u8)) {
- ret more(flag_sign_always);
- } else if (f == ('#' as u8)) {
- ret more(flag_alternate);
- } else {
- ret tup(noflags, i);
- }
- }
-
- fn parse_count(str s, uint i, uint lim) -> tup(count, uint) {
- if (i >= lim) {
- ret tup(count_implied, i);
- }
-
- if (s.(i) == ('*' as u8)) {
- auto param = parse_parameter(s, i + 1u, lim);
- auto j = param._1;
- alt (param._0) {
- case (none[int]) {
- ret tup(count_is_next_param, j);
- }
- case (some[int](?n)) {
- ret tup(count_is_param(n), j);
- }
- }
- } else {
- auto num = peek_num(s, i, lim);
- alt (num) {
- case (none[tup(uint, uint)]) {
- ret tup(count_implied, i);
- }
- case (some[tup(uint, uint)](?num)) {
- ret tup(count_is(num._0 as int), num._1);
- }
- }
- }
- }
-
- fn parse_precision(str s, uint i, uint lim) -> tup(count, uint) {
- if (i >= lim) {
- ret tup(count_implied, i);
- }
-
- if (s.(i) == '.' as u8) {
- auto 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._0) {
- case (count_implied) {
- ret tup(count_is(0), count._1);
- }
- case (_) {
- ret count;
- }
- }
- } else {
- ret tup(count_implied, i);
- }
- }
-
- fn parse_type(str s, uint i, uint lim) -> tup(ty, uint) {
- if (i >= lim) {
- log_err "missing type in conversion";
- fail;
- }
-
- auto t;
- auto tstr = Str.substr(s, i, 1u);
- if (Str.eq(tstr, "b")) {
- t = ty_bool;
- } else if (Str.eq(tstr, "s")) {
- t = ty_str;
- } else if (Str.eq(tstr, "c")) {
- t = 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?
- t = ty_int(signed);
- } else if (Str.eq(tstr, "u")) {
- t = ty_int(unsigned);
- } else if (Str.eq(tstr, "x")) {
- t = ty_hex(case_lower);
- } else if (Str.eq(tstr, "X")) {
- t = ty_hex(case_upper);
- } else if (Str.eq(tstr, "t")) {
- t = ty_bits;
- } else if (Str.eq(tstr, "o")) {
- t = ty_octal;
- } else {
- log_err "unknown type in conversion";
- fail;
- }
-
- ret tup(t, i + 1u);
- }
-}
-
-// Functions used by the fmt extension at runtime. For now there are a lot of
-// decisions made a runtime. If it proves worthwhile then some of these
-// conditions can be evaluated at compile-time. For now though it's cleaner to
-// implement it this way, I think.
-mod RT {
-
- tag flag {
- flag_left_justify;
- flag_left_zero_pad;
- flag_space_for_sign;
- 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
- flag_none;
- }
-
- tag count {
- count_is(int);
- count_implied;
- }
-
- tag ty {
- ty_default;
- ty_bits;
- ty_hex_upper;
- ty_hex_lower;
- ty_octal;
- }
-
- // 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);
-
- 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)) {
- s = "+" + s;
- } else if (have_flag(cv.flags, flag_space_for_sign)) {
- s = " " + s;
- }
- }
- ret pad(cv, s, pad_signed);
- }
-
- fn conv_uint(&conv cv, uint u) -> str {
- auto prec = get_int_precision(cv);
- auto res;
- alt (cv.ty) {
- case (ty_default) {
- res = uint_to_str_prec(u, 10u, prec);
- }
- case (ty_hex_lower) {
- res = uint_to_str_prec(u, 16u, prec);
- }
- case (ty_hex_upper) {
- res = Str.to_upper(uint_to_str_prec(u, 16u, prec));
- }
- case (ty_bits) {
- res = uint_to_str_prec(u, 2u, prec);
- }
- case (ty_octal) {
- res = uint_to_str_prec(u, 8u, prec);
- }
- }
- ret pad(cv, res, pad_unsigned);
- }
-
- fn conv_bool(&conv cv, bool b) -> str {
- auto s;
- if (b) {
- s = "true";
- } else {
- s = "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 {
- ret pad(cv, Str.from_char(c), pad_nozero);
- }
-
- fn conv_str(&conv cv, str s) -> str {
- auto unpadded = s;
- alt (cv.precision) {
- case (count_implied) {
- }
- case (count_is(?max)) {
- // For strings, precision is the maximum characters displayed
- if (max as uint < Str.char_len(s)) {
- // FIXME: substr works on bytes, not chars!
- unpadded = Str.substr(s, 0u, max as uint);
- }
- }
- }
- 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 {
- if (num < 0) {
- ret "-" + uint_to_str_prec((-num) as uint, radix, prec);
- } else {
- ret uint_to_str_prec(num as uint, radix, prec);
- }
- }
-
- // 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 {
- auto s;
-
- if (prec == 0u && num == 0u) {
- s = "";
- } else {
- 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);
- s = pad + s;
- }
- }
-
- ret s;
- }
-
- fn get_int_precision(&conv cv) -> uint {
- alt (cv.precision) {
- case (count_is(?c)) {
- ret c as uint;
- }
- case (count_implied) {
- ret 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);
- // FIXME: Using unsafe_from_bytes because rustboot
- // can't figure out the is_utf8 predicate on from_bytes?
- ret Str.unsafe_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
- 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);
- ret s + padstr;
- }
-
- auto might_zero_pad = false;
- auto signed = false;
-
- alt (mode) {
- case (pad_nozero) {
- // fallthrough
- }
- case (pad_signed) {
- might_zero_pad = true;
- signed = true;
- }
- case (pad_unsigned) {
- might_zero_pad = true;
- }
- }
-
- fn have_precision(&conv cv) -> bool {
- alt (cv.precision) {
- case (count_implied) {
- ret false;
- }
- case (_) {
- ret true;
- }
- }
- }
-
- auto 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);
-
- // 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(vec(head));
- auto bytelen = Str.byte_len(s);
- auto 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;
- }
- }
- ret false;
- }
-}
-
-// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
+++ /dev/null
-native "rust" mod rustrt {
- fn rust_file_is_dir(str path) -> 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) {
- i = Str.rindex(p, OS_FS.alt_path_sep as u8);
- if (i == -1) {
- ret p;
- }
- }
- ret Str.substr(p, 0u, i as uint);
-}
-
-fn connect(path pre, path post) -> path {
- auto len = Str.byte_len(pre);
- if (pre.(len - 1u) == (OS_FS.path_sep as u8)) { // Trailing '/'?
- ret pre + post;
- }
- ret pre + path_sep() + post;
-}
-
-fn file_is_dir(path p) -> bool {
- ret rustrt.rust_file_is_dir(p) != 0;
-}
-
-fn list_dir(path p) -> vec[str] {
- auto pl = Str.byte_len(p);
- if (pl == 0u || p.(pl - 1u) as char != OS_FS.path_sep) {
- p += path_sep();
- }
- let vec[str] full_paths = vec();
- for (str filename in OS_FS.list_dir(p)) {
- if (!Str.eq(filename, ".")) {if (!Str.eq(filename, "..")) {
- Vec.push[str](full_paths, p + filename);
- }}
- }
- ret full_paths;
-}
-
-
-// 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:
+++ /dev/null
-fn getenv(str n) -> Option.t[str] {
- auto s = OS.libc.getenv(Str.buf(n));
- if ((s as int) == 0) {
- ret Option.none[str];
- } else {
- ret Option.some[str](Str.str_from_cstr(s));
- }
-}
-
+++ /dev/null
-/* Simple getopt alternative. Construct a vector of options, either by using
- * reqopt, optopt, and optflag or by building them from components yourself,
- * and pass them to getopts, along with a vector of actual arguments (not
- * including argv[0]). You'll either get a failure code back, or a match.
- * You'll have to verify whether the amount of 'free' arguments in the match
- * is what you expect. Use opt_* accessors (bottom of the file) to get
- * argument values out of the match object.
- */
-
-import Option.some;
-import Option.none;
-
-tag name { long(str); short(char); }
-tag hasarg { yes; no; maybe; }
-tag occur { req; optional; multi; }
-
-type opt = rec(name name, hasarg hasarg, occur occur);
-
-fn mkname(str nm) -> name {
- if (Str.char_len(nm) == 1u) { ret short(Str.char_at(nm, 0u)); }
- else { ret long(nm); }
-}
-fn reqopt(str name) -> opt {
- ret rec(name=mkname(name), hasarg=yes, occur=req);
-}
-fn optopt(str name) -> opt {
- ret rec(name=mkname(name), hasarg=yes, occur=optional);
-}
-fn optflag(str name) -> opt {
- ret rec(name=mkname(name), hasarg=no, occur=optional);
-}
-fn optmulti(str name) -> opt {
- ret rec(name=mkname(name), hasarg=yes, occur=multi);
-}
-
-tag optval {
- val(str);
- given;
-}
-
-type match = rec(vec[opt] opts, vec[mutable vec[optval]] vals, vec[str] free);
-
-fn is_arg(str arg) -> bool {
- ret Str.byte_len(arg) > 1u && arg.(0) == '-' as u8;
-}
-fn name_str(name nm) -> str {
- alt (nm) {
- case (short(?ch)) {ret Str.from_char(ch);}
- case (long(?s)) {ret s;}
- }
-}
-
-// FIXME rustboot workaround
-fn name_eq(name a, name b) -> bool {
- alt (a) {
- case (long(?a)) {
- alt (b) {
- case (long(?b)) { ret Str.eq(a, b); }
- case (_) { ret false; }
- }
- }
- case (_) { if (a == b) { ret true; } else {ret false; } }
- }
-}
-fn find_opt(vec[opt] opts, name nm) -> Option.t[uint] {
- auto i = 0u;
- auto l = Vec.len[opt](opts);
- while (i < l) {
- if (name_eq(opts.(i).name, nm)) { ret some[uint](i); }
- i += 1u;
- }
- ret none[uint];
-}
-
-tag fail_ {
- argument_missing(str);
- unrecognized_option(str);
- option_missing(str);
- option_duplicated(str);
-}
-
-fn fail_str(fail_ f) -> str {
- alt (f) {
- case (argument_missing(?nm)) {
- ret "Argument to option '" + nm + "' missing.";
- }
- case (unrecognized_option(?nm)) {
- ret "Unrecognized option: '" + nm + "'.";
- }
- case (option_missing(?nm)) {
- ret "Required option '" + nm + "' missing.";
- }
- case (option_duplicated(?nm)) {
- ret "Option '" + nm + "' given more than once.";
- }
- }
-}
-
-tag result {
- success(match);
- failure(fail_);
-}
-
-fn getopts(vec[str] args, vec[opt] opts) -> result {
- auto n_opts = Vec.len[opt](opts);
- fn empty_(uint x) -> vec[optval]{ret Vec.empty[optval]();}
- auto f = empty_;
- auto vals = Vec.init_fn_mut[vec[optval]](f, n_opts);
- let vec[str] free = vec();
-
- auto l = Vec.len[str](args);
- auto i = 0u;
- while (i < l) {
- auto cur = args.(i);
- auto curlen = Str.byte_len(cur);
- if (!is_arg(cur)) {
- Vec.push[str](free, cur);
- } else if (Str.eq(cur, "--")) {
- free += Vec.slice[str](args, i + 1u, l);
- 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) {
- names = vec(long(tail));
- } else {
- names = vec(long(Str.slice(tail, 0u, eq as uint)));
- i_arg = Option.some[str]
- (Str.slice(tail, (eq as uint) + 1u, curlen - 2u));
- }
- } else {
- auto j = 1u;
- names = vec();
- while (j < curlen) {
- auto range = Str.char_range_at(cur, j);
- Vec.push[name](names, short(range._0));
- j = range._1;
- }
- }
- auto name_pos = 0u;
- for (name nm in names) {
- name_pos += 1u;
- auto optid;
- alt (find_opt(opts, nm)) {
- case (some[uint](?id)) {optid = id;}
- case (none[uint]) {
- ret failure(unrecognized_option(name_str(nm)));
- }
- }
- alt (opts.(optid).hasarg) {
- case (no) {
- Vec.push[optval](vals.(optid), given);
- }
- case (maybe) {
- if (!Option.is_none[str](i_arg)) {
- Vec.push[optval](vals.(optid),
- val(Option.get[str](i_arg)));
- } else if (name_pos < Vec.len[name](names) ||
- i + 1u == l || is_arg(args.(i + 1u))) {
- Vec.push[optval](vals.(optid), given);
- } else {
- i += 1u;
- Vec.push[optval](vals.(optid), val(args.(i)));
- }
- }
- case (yes) {
- if (!Option.is_none[str](i_arg)) {
- Vec.push[optval](vals.(optid),
- val(Option.get[str](i_arg)));
- } else if (i + 1u == l) {
- ret failure(argument_missing(name_str(nm)));
- } else {
- i += 1u;
- Vec.push[optval](vals.(optid), val(args.(i)));
- }
- }
- }
- }
- }
- i += 1u;
- }
-
- i = 0u;
- while (i < n_opts) {
- auto n = Vec.len[optval](vals.(i));
- auto 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) {
- ret failure(option_duplicated(name_str(opts.(i).name)));
- }}
- i += 1u;
- }
-
- ret success(rec(opts=opts, vals=vals, free=free));
-}
-
-fn opt_vals(match m, str nm) -> vec[optval] {
- alt (find_opt(m.opts, mkname(nm))) {
- case (some[uint](?id)) { ret m.vals.(id); }
- case (none[uint]) {
- log_err "No option '" + nm + "' defined.";
- fail;
- }
- }
-}
-fn opt_val(match m, str nm) -> optval {
- ret opt_vals(m, nm).(0);
-}
-fn opt_present(match m, str nm) -> bool {
- ret Vec.len[optval](opt_vals(m, nm)) > 0u;
-}
-fn opt_str(match m, str nm) -> str {
- alt (opt_val(m, nm)) {
- case (val(?s)) { ret s; }
- case (_) { fail; }
- }
-}
-fn opt_strs(match m, str nm) -> vec[str] {
- let vec[str] acc = vec();
- for (optval v in opt_vals(m, nm)) {
- alt (v) {
- case (val(?s)) { Vec.push[str](acc, s); }
- case (_) {}
- }
- }
- ret acc;
-}
-fn opt_maybe_str(match m, str nm) -> Option.t[str] {
- auto vals = opt_vals(m, nm);
- if (Vec.len[optval](vals) == 0u) { ret none[str]; }
- alt (vals.(0)) {
- case (val(?s)) { ret some[str](s); }
- case (_) { ret none[str]; }
- }
-}
-
-// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
+++ /dev/null
-import OS.libc;
-
-native "rust" mod rustrt {
- fn rust_get_stdin() -> OS.libc.FILE;
- fn rust_get_stdout() -> OS.libc.FILE;
-}
-
-// Reading
-
-// FIXME This is all buffered. We might need an unbuffered variant as well
-
-tag seek_style {seek_set; seek_end; seek_cur;}
-
-// The raw underlying reader class. All readers must implement this.
-type buf_reader =
- state obj {
- fn read(uint len) -> vec[u8];
- fn read_byte() -> int;
- fn unread_byte(int byte);
- fn eof() -> bool;
-
- // FIXME: Seekable really should be orthogonal. We will need
- // inheritance.
- fn seek(int offset, seek_style whence);
- fn tell() -> uint;
- };
-
-// Convenience methods for reading.
-type reader =
- state obj {
- // FIXME: This should inherit from buf_reader.
- fn get_buf_reader() -> buf_reader;
-
- fn read_byte() -> int;
- fn unread_byte(int byte);
- fn read_bytes(uint len) -> vec[u8];
- fn read_char() -> char;
- fn eof() -> bool;
- fn read_line() -> str;
- fn read_c_str() -> str;
- fn read_le_uint(uint size) -> uint;
- fn read_le_int(uint size) -> int;
- fn read_be_uint(uint size) -> uint;
- fn read_whole_stream() -> vec[u8];
-
- fn seek(int offset, seek_style whence);
- fn tell() -> uint; // FIXME: eventually u64
- };
-
-fn convert_whence(seek_style whence) -> int {
- alt (whence) {
- case (seek_set) {ret 0;}
- case (seek_cur) {ret 1;}
- case (seek_end) {ret 2;}
- }
-}
-
-state 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);
- 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 eof() -> bool {
- ret OS.libc.feof(f) != 0;
- }
- fn seek(int offset, seek_style whence) {
- 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); }
- }
-}
-
-// FIXME: Convert this into pseudomethods on buf_reader.
-state obj new_reader(buf_reader rdr) {
- 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 read_char() -> char {
- auto 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);
- assert (w > 0u);
- if (w == 1u) {ret b0 as char;}
- auto val = 0u;
- while (w > 1u) {
- w -= 1u;
- auto next = rdr.read_byte();
- assert (next > -1);
- assert (next & 0xc0 == 0x80);
- val <<= 6u;
- val += (next & 0x3f) as uint;
- }
- // See Str.char_at
- val += ((b0 << ((w + 1u) as u8)) as uint) << ((w - 1u) * 6u - w - 1u);
- ret val as char;
- }
- fn eof() -> bool {
- ret rdr.eof();
- }
- fn read_line() -> str {
- let vec[u8] buf = vec();
- // No break yet in rustc
- auto go_on = true;
- while (go_on) {
- auto 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 = vec();
- auto go_on = true;
- while (go_on) {
- auto ch = rdr.read_byte();
- if (ch < 1) {go_on = false;}
- else {Vec.push[u8](buf, ch as u8);}
- }
- ret Str.unsafe_from_bytes(buf);
- }
- // FIXME deal with eof?
- fn read_le_uint(uint size) -> uint {
- auto val = 0u;
- auto 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) {
- val += (rdr.read_byte() as uint) << pos;
- pos += 8u;
- size -= 1u;
- }
- ret val as int;
- }
- // FIXME deal with eof?
- fn read_be_uint(uint size) -> uint {
- auto val = 0u;
- auto sz = size; // FIXME: trans.ml bug workaround
- 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 = vec();
- while (!rdr.eof()) {
- buf += rdr.read(2048u);
- }
- ret buf;
- }
- fn seek(int offset, seek_style whence) {
- ret rdr.seek(offset, whence);
- }
- fn tell() -> uint {
- ret rdr.tell();
- }
-}
-
-fn stdin() -> reader {
- 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;
- }
- 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);
-}
-
-
-// Byte buffer readers
-
-// TODO: mutable? u8, but this fails with rustboot.
-type byte_buf = @rec(vec[u8] buf, mutable uint pos);
-
-state 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);
- 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);
- bbuf.pos += 1u;
- ret b as int;
- }
-
- fn unread_byte(int byte) {
- 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);
- 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));
-}
-
-
-// Writing
-
-tag fileflag {
- append;
- create;
- truncate;
- none;
-}
-
-type buf_writer = state obj {
- fn write(vec[u8] v);
-
- // FIXME: Seekable really should be orthogonal. We will need inheritance.
- fn seek(int offset, seek_style whence);
- fn tell() -> uint; // FIXME: eventually u64
-};
-
-state 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";
- }
- }
-
- fn seek(int offset, seek_style whence) {
- 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);}
- }
-}
-
-state 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) {
- vbuf = Vec.buf_off[u8](v, count);
- auto nout = OS.libc.write(fd, vbuf, len);
- if (nout < 0) {
- log_err "error dumping buffer";
- log_err Sys.rustrt.last_os_error();
- fail;
- }
- count += nout as uint;
- }
- }
-
- fn seek(int offset, seek_style whence) {
- 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);}
- }
-}
-
-fn file_buf_writer(str path, vec[fileflag] flags) -> buf_writer {
- let int fflags =
- 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) {}
- }
- }
-
- auto fd = OS.libc.open(Str.buf(path),
- fflags,
- OS.libc_constants.S_IRUSR() |
- OS.libc_constants.S_IWUSR());
-
- if (fd < 0) {
- log_err "error opening file for writing";
- log_err Sys.rustrt.last_os_error();
- fail;
- }
- ret fd_buf_writer(fd, true);
-}
-
-type writer =
- state 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 s);
- fn write_char(char ch);
- fn write_int(int n);
- fn write_uint(uint n);
- fn write_bytes(vec[u8] bytes);
- fn write_le_uint(uint n, uint size);
- fn write_le_int(int n, uint size);
- fn write_be_uint(uint n, uint size);
- };
-
-fn uint_to_le_bytes(uint n, uint size) -> vec[u8] {
- let vec[u8] bytes = vec();
- while (size > 0u) {
- bytes += vec((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 = vec();
- auto i = (size - 1u) as int;
- while (i >= 0) {
- bytes += vec(((n >> ((i * 8) as uint)) & 255u) as u8);
- i -= 1;
- }
- ret bytes;
-}
-
-state obj new_writer(buf_writer out) {
- fn get_buf_writer() -> buf_writer {
- ret out;
- }
- fn write_str(str s) {
- out.write(Str.bytes(s));
- }
- fn write_char(char ch) {
- // 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) {
- out.write(uint_to_le_bytes(n, size));
- }
- fn write_le_int(int n, uint size) {
- out.write(uint_to_le_bytes(n as uint, size));
- }
- fn write_be_uint(uint n, uint size) {
- 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 file_writer(str path, vec[fileflag] flags) -> 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;
- }
- ret FILE_writer(f, true);
-}
-
-// FIXME it would be great if this could be a const
-fn stdout() -> writer {
- ret new_writer(fd_buf_writer(1, false));
-}
-
-type str_writer =
- state obj {
- fn get_writer() -> writer;
- fn get_str() -> str;
- };
-
-type mutable_byte_buf = @rec(mutable vec[mutable u8] buf, mutable uint pos);
-
-state obj byte_buf_writer(mutable_byte_buf buf) {
- fn write(vec[u8] v) {
- // Fast path.
- 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);
- 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)) {
- buf.buf += vec(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);
- buf.pos = seek_in_buf(offset, pos, len, whence);
- }
-
- fn tell() -> uint { ret buf.pos; }
-}
-
-fn string_writer() -> str_writer {
- // FIXME: yikes, this is bad. Needs fixing of mutable syntax.
- let vec[mutable u8] b = vec(mutable 0u8);
- Vec.pop(b);
-
- let mutable_byte_buf buf = @rec(mutable buf = b, mutable pos = 0u);
- state obj str_writer_wrap(writer wr, mutable_byte_buf buf) {
- fn get_writer() -> writer {ret wr;}
- fn get_str() -> str {ret Str.unsafe_from_bytes(buf.buf);}
- }
- ret str_writer_wrap(new_writer(byte_buf_writer(buf)), buf);
-}
-
-
-// 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; }
- }
-
- if (bpos < 0) {
- bpos = 0;
- } else if (bpos > blen) {
- bpos = blen;
- }
-
- ret bpos as uint;
-}
-
-
-//
-// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
-//
+++ /dev/null
-
-fn add(int x, int y) -> int { ret x + y; }
-fn sub(int x, int y) -> int { ret x - y; }
-fn mul(int x, int y) -> int { ret x * y; }
-fn div(int x, int y) -> int { ret x / y; }
-fn rem(int x, int y) -> int { ret x % y; }
-
-fn lt(int x, int y) -> bool { ret x < y; }
-fn le(int x, int y) -> bool { ret x <= y; }
-fn eq(int x, int y) -> bool { ret x == y; }
-fn ne(int x, int y) -> bool { ret x != y; }
-fn ge(int x, int y) -> bool { ret x >= y; }
-fn gt(int x, int y) -> bool { ret x > y; }
-
-fn positive(int x) -> bool { ret x > 0; }
-fn negative(int x) -> bool { ret x < 0; }
-fn nonpositive(int x) -> bool { ret x <= 0; }
-fn nonnegative(int x) -> bool { ret x >= 0; }
-
-iter range(int lo, int hi) -> int {
- let int lo_ = lo;
- while (lo_ < hi) {
- put lo_;
- lo_ += 1;
- }
-}
-
-fn to_str(int n, uint radix) -> str
-{
- assert (0u < radix && radix <= 16u);
- if (n < 0) {
- ret "-" + UInt.to_str((-n) as uint, radix);
- } else {
- ret UInt.to_str(n as uint, radix);
- }
-}
-
-fn pow(int base, uint exponent) -> int {
-
- if (exponent == 0u) {
- ret 1;
- } else if (base == 0) {
- ret 0;
- } else {
- auto accum = base;
- auto count = exponent;
- while (count > 1u) {
- accum *= base;
- count -= 1u;
- }
- ret accum;
- }
-}
-
-// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
+++ /dev/null
-import Option.some;
-import Option.none;
-
-// FIXME: It would probably be more appealing to define this as
-// type list[T] = rec(T hd, option[@list[T]] tl), but at the moment
-// our recursion rules do not permit that.
-
-tag list[T] {
- cons(T, @list[T]);
- nil;
-}
-
-fn foldl[T,U](&list[T] ls, &U u, fn(&T t, &U u) -> U f) -> U {
- alt(ls) {
- case (cons[T](?hd, ?tl)) {
- auto u_ = f(hd, u);
- // FIXME: should use 'be' here, not 'ret'. But parametric
- // tail calls currently don't work.
- ret foldl[T,U](*tl, u_, f);
- }
- case (nil[T]) {
- ret u;
- }
- }
-
- fail; // TODO: remove me when exhaustiveness checking works
-}
-
-fn find[T,U](&list[T] ls,
- (fn(&T) -> Option.t[U]) f) -> Option.t[U] {
- alt(ls) {
- case (cons[T](?hd, ?tl)) {
- alt (f(hd)) {
- case (none[U]) {
- // FIXME: should use 'be' here, not 'ret'. But parametric tail
- // calls currently don't work.
- ret find[T,U](*tl, f);
- }
- case (some[U](?res)) {
- ret some[U](res);
- }
- }
- }
- case (nil[T]) {
- ret none[U];
- }
- }
-
- fail; // TODO: remove me when exhaustiveness checking works
-}
-
-fn length[T](&list[T] ls) -> uint {
- fn count[T](&T t, &uint u) -> 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[T](_, ?tl)) {ret *tl;}
- }
-}
-fn car[T](&list[T] ls) -> T {
- alt (ls) {
- case (cons[T](?hd, _)) {ret hd;}
- }
-}
-
-// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
+++ /dev/null
-/**
- * At the moment, this is a partial hashmap implementation, not yet fit for
- * use, but useful as a stress test for rustboot.
- */
-
-type hashfn[K] = fn(&K) -> uint;
-type eqfn[K] = fn(&K, &K) -> bool;
-
-state type hashmap[K, V] = state obj {
- fn size() -> uint;
- fn insert(&K key, &V val) -> bool;
- fn contains_key(&K key) -> bool;
- fn get(&K key) -> V;
- fn find(&K key) -> Option.t[V];
- fn remove(&K key) -> Option.t[V];
- fn rehash();
- iter items() -> @tup(K,V);
-};
-
-fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
-
- let uint initial_capacity = 32u; // 2^5
- let Util.rational load_factor = rec(num=3, den=4);
-
- tag bucket[K, V] {
- nil;
- deleted;
- some(K, V);
- }
-
- fn make_buckets[K, V](uint nbkts) -> vec[mutable bucket[K, V]] {
- ret Vec.init_elt_mut[bucket[K, V]](nil[K, V], nbkts);
- }
-
- // Derive two hash functions from the one given by taking the upper
- // half and lower half of the uint bits. Our bucket probing
- // sequence is then defined by
- //
- // hash(key, i) := hashl(key) * i + hashr(key) for i = 0, 1, 2, ...
- //
- // Tearing the hash function apart this way is kosher in practice
- // as, assuming 32-bit uints, the table would have to be at 2^32
- // buckets before the resulting pair of hash functions no longer
- // probes all buckets for a fixed key. Note that hashl is made to
- // output odd numbers (hence coprime to the number of nbkts, which
- // 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 {
- ret (hashl(h, nbkts) * i + hashr(h, nbkts)) % nbkts;
- }
-
- /**
- * We attempt to never call this with a full table. If we do, it
- * will fail.
- */
- fn insert_common[K, V](&hashfn[K] hasher,
- &eqfn[K] eqer,
- vec[mutable bucket[K, V]] 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, V](?k, _)) {
- if (eqer(key, k)) {
- bkts.(j) = some[K, V](k, val);
- ret false;
- }
- i += 1u;
- }
- case (_) {
- bkts.(j) = some[K, V](key, val);
- ret true;
- }
- }
- }
- fail; // full table
- }
-
- fn find_common[K, V](&hashfn[K] hasher,
- &eqfn[K] eqer,
- vec[mutable bucket[K, V]] 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](?k, ?v)) {
- if (eqer(key, k)) {
- ret Option.some[V](v);
- }
- }
- case (nil[K, V]) {
- ret Option.none[V];
- }
- case (deleted[K, V]) { }
- }
- i += 1u;
- }
- ret Option.none[V];
- }
-
-
- fn rehash[K, V](&hashfn[K] hasher,
- &eqfn[K] eqer,
- vec[mutable bucket[K, V]] oldbkts, uint noldbkts,
- vec[mutable bucket[K, V]] newbkts, uint nnewbkts)
- {
- for (bucket[K, V] b in oldbkts) {
- alt (b) {
- case (some[K, V](?k, ?v)) {
- insert_common[K, V](hasher, eqer, newbkts,
- nnewbkts, k, v);
- }
- case (_) { }
- }
- }
- }
-
- state obj hashmap[K, V](hashfn[K] hasher,
- eqfn[K] eqer,
- mutable vec[mutable bucket[K, V]] bkts,
- mutable uint nbkts,
- mutable uint nelts,
- Util.rational lf)
- {
- 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);
- let vec[mutable bucket[K, V]] 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)) {
- nelts += 1u;
- ret true;
- }
- ret false;
- }
-
- fn contains_key(&K key) -> bool {
- alt (find_common[K, V](hasher, eqer, bkts, nbkts, key)) {
- case (Option.some[V](_)) { ret true; }
- case (_) { ret false; }
- }
- fail; // FIXME: remove me when exhaustiveness checking works
- }
-
- fn get(&K key) -> V {
- alt (find_common[K, V](hasher, eqer, bkts, nbkts, key)) {
- case (Option.some[V](?val)) { ret val; }
- case (_) { fail; }
- }
- fail; // FIXME: remove me when exhaustiveness checking works
- }
-
- fn find(&K key) -> Option.t[V] {
- // FIXME: should be 'be' but parametric tail-calls don't
- // work at the moment.
- ret 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](?k, ?v)) {
- if (eqer(key, k)) {
- bkts.(j) = deleted[K, V];
- nelts -= 1u;
- ret Option.some[V](v);
- }
- }
- case (deleted[K, V]) { }
- case (nil[K, V]) {
- ret Option.none[V];
- }
- }
- i += 1u;
- }
- ret Option.none[V];
- }
-
- fn rehash() {
- let vec[mutable bucket[K, V]] newbkts =
- make_buckets[K, V](nbkts);
- rehash[K, V](hasher, eqer, bkts, nbkts, newbkts, nbkts);
- bkts = newbkts;
- }
-
- iter items() -> @tup(K,V) {
- for (bucket[K,V] b in bkts) {
- alt (b) {
- case(some[K,V](?k,?v)) {
- put @tup(k,v);
- }
- case (_) { }
- }
- }
- }
- }
-
- let vec[mutable bucket[K, V]] bkts =
- make_buckets[K, V](initial_capacity);
-
- ret hashmap[K, V](hasher, eqer, bkts, initial_capacity, 0u, load_factor);
-}
-
-
-// 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:
+++ /dev/null
-// lib/Option.rs
-
-tag t[T] {
- none;
- some(T);
-}
-
-type operator[T, U] = fn(&T) -> U;
-
-fn get[T](&t[T] opt) -> T {
- alt (opt) {
- case (some[T](?x)) {
- ret x;
- }
- case (none[T]) {
- fail;
- }
- }
- fail; // FIXME: remove me when exhaustiveness checking works
-}
-
-fn map[T, U](&operator[T, U] f, &t[T] opt) -> t[U] {
- alt (opt) {
- case (some[T](?x)) {
- ret some[U](f(x));
- }
- case (none[T]) {
- ret none[U];
- }
- }
- fail; // FIXME: remove me when exhaustiveness checking works
-}
-
-fn is_none[T](&t[T] opt) -> bool {
- alt (opt) {
- case (none[T]) { ret true; }
- case (some[T](_)) { ret false; }
- }
-}
-
-fn from_maybe[T](&T def, &t[T] opt) -> T {
- auto 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 {
- alt (opt) {
- case (none[T]) { ret def; }
- case (some[T](?t)) { ret f(t); }
- }
-}
-// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
-
+++ /dev/null
-/**
- * Bindings the runtime's random number generator (ISAAC).
- */
-
-native "rust" mod rustrt {
- type rctx;
- fn rand_new() -> rctx;
- fn rand_next(rctx c) -> u32;
- fn rand_free(rctx c);
-}
-
-type rng = obj { fn next() -> u32; };
-
-fn mk_rng() -> rng {
- obj rt_rng(rustrt.rctx c) {
- fn next() -> u32 {
- ret rustrt.rand_next(c);
- }
- drop {
- rustrt.rand_free(c);
- }
- }
-
- ret rt_rng(rustrt.rand_new());
-}
-
-// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
+++ /dev/null
-import Str.sbuf;
-import Vec.vbuf;
-
-native "rust" mod rustrt {
- fn rust_run_program(vbuf argv, int in_fd, int out_fd, int err_fd) -> int;
-}
-
-fn argvec(str prog, vec[str] args) -> vec[sbuf] {
- auto argptrs = vec(Str.buf(prog));
- for (str arg in args) {
- Vec.push[sbuf](argptrs, Str.buf(arg));
- }
- Vec.push[sbuf](argptrs, 0 as sbuf);
- ret argptrs;
-}
-
-fn run_program(str prog, vec[str] args) -> int {
- auto pid = rustrt.rust_run_program(Vec.buf[sbuf](argvec(prog, args)),
- 0, 0, 0);
- ret OS.waitpid(pid);
-}
-
-type program =
- state obj {
- fn get_id() -> int;
- fn input() -> IO.writer;
- fn output() -> IO.reader;
- fn close_input();
- fn finish() -> int;
- };
-
-fn start_program(str prog, vec[str] args) -> @program {
- auto pipe_input = OS.pipe();
- auto pipe_output = OS.pipe();
- auto pid = rustrt.rust_run_program
- (Vec.buf[sbuf](argvec(prog, args)),
- pipe_input._0, pipe_output._1, 0);
- if (pid == -1) {fail;}
- OS.libc.close(pipe_input._0);
- OS.libc.close(pipe_output._1);
-
- state obj new_program(int pid,
- int in_fd,
- OS.libc.FILE out_file,
- mutable bool finished) {
- fn get_id() -> int {ret pid;}
- fn input() -> IO.writer {
- ret IO.new_writer(IO.fd_buf_writer(in_fd, false));
- }
- fn output() -> IO.reader {
- ret IO.new_reader(IO.FILE_buf_reader(out_file, false));
- }
- fn close_input() {
- OS.libc.close(in_fd);
- }
- fn finish() -> int {
- if (finished) {ret 0;}
- finished = true;
- OS.libc.close(in_fd);
- ret OS.waitpid(pid);
- }
- drop {
- if (!finished) {
- OS.libc.close(in_fd);
- OS.waitpid(pid);
- }
- OS.libc.fclose(out_file);
- }
- }
- ret @new_program(pid, pipe_input._1,
- OS.fd_FILE(pipe_output._0),
- false);
-}
-
-fn program_output(str prog, vec[str] args)
- -> rec(int status, str out) {
- auto pr = start_program(prog, args);
- pr.close_input();
- auto out = pr.output();
- auto buf = "";
- while (!out.eof()) {
- auto bytes = out.read_bytes(4096u);
- buf += Str.unsafe_from_bytes(bytes);
- }
- ret rec(status=pr.finish(), out=buf);
-}
-
-
-// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
+++ /dev/null
-/*
- * A SHA-1 implementation derived from Paul E. Jones's reference
- * implementation, which is written for clarity, not speed. At some
- * point this will want to be rewritten.
- */
-
-export sha1;
-export mk_sha1;
-
-state type sha1 = state obj {
- // Provide message input as bytes
- fn input(&vec[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];
-
- // 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();
-};
-
-// Some unexported constants
-const uint digest_buf_len = 5;
-const uint msg_block_len = 64;
-const uint work_buf_len = 80;
-
-const u32 k0 = 0x5A827999u32;
-const u32 k1 = 0x6ED9EBA1u32;
-const u32 k2 = 0x8F1BBCDCu32;
-const u32 k3 = 0xCA62C1D6u32;
-
-// Builds a sha1 object
-fn mk_sha1() -> sha1 {
-
- state type sha1state = rec(vec[mutable u32] h,
- mutable u32 len_low,
- mutable u32 len_high,
- vec[mutable u8] msg_block,
- mutable uint msg_block_idx,
- mutable bool computed,
- vec[mutable u32] work_buf);
-
- fn add_input(&sha1state st, &vec[u8] msg) {
- // FIXME: Should be typestate precondition
- assert (!st.computed);
-
- for (u8 element in msg) {
- st.msg_block.(st.msg_block_idx) = element;
- st.msg_block_idx += 1u;
-
- st.len_low += 8u32;
- if (st.len_low == 0u32) {
- st.len_high += 1u32;
- if (st.len_high == 0u32) {
- // FIXME: Need better failure mode
- fail;
- }
- }
-
- if (st.msg_block_idx == msg_block_len) {
- process_msg_block(st);
- }
- }
- }
-
- fn process_msg_block(&sha1state st) {
-
- // FIXME: Make precondition
- assert (Vec.len(st.h) == digest_buf_len);
- assert (Vec.len(st.work_buf) == work_buf_len);
-
- let int t; // Loop counter
- auto w = st.work_buf;
-
- // Initialize the first 16 words of the vector w
- t = 0;
- while (t < 16) {
- auto 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);
- tmp = tmp | (st.msg_block.(t * 4 + 3) as u32);
- w.(t) = tmp;
- t += 1;
- }
-
- // Initialize the rest of vector w
- while (t < 80) {
- auto 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;
-
- t = 0;
- while (t < 20) {
- temp = circular_shift(5u32, a)
- + ((b & c) | ((~b) & d)) + e + w.(t) + k0;
- e = d;
- d = c;
- c = circular_shift(30u32, b);
- b = a;
- a = temp;
- t += 1;
- }
-
- while (t < 40) {
- temp = circular_shift(5u32, a)
- + (b ^ c ^ d) + e + w.(t) + k1;
- e = d;
- d = c;
- c = circular_shift(30u32, b);
- b = a;
- a = temp;
- t += 1;
- }
-
- while (t < 60) {
- temp = circular_shift(5u32, a)
- + ((b & c) | (b & d) | (c & d)) + e + w.(t) + k2;
- e = d;
- d = c;
- c = circular_shift(30u32, b);
- b = a;
- a = temp;
- t += 1;
- }
-
- while (t < 80) {
- temp = circular_shift(5u32, a)
- + (b ^ c ^ d) + e + w.(t) + k3;
- e = d;
- d = c;
- c = circular_shift(30u32, b);
- b = a;
- a = temp;
- t += 1;
- }
-
- st.h.(0) = st.h.(0) + a;
- st.h.(1) = st.h.(1) + b;
- st.h.(2) = st.h.(2) + c;
- st.h.(3) = st.h.(3) + d;
- st.h.(4) = st.h.(4) + e;
-
- st.msg_block_idx = 0u;
- }
-
- fn circular_shift(u32 bits, u32 word) -> u32 {
- // FIXME: This is a workaround for a rustboot
- // "unrecognized quads" codegen bug
- auto bits_hack = bits;
- ret (word << bits_hack) | (word >> (32u32 - bits));
- }
-
- fn mk_result(&sha1state st) -> vec[u8] {
- if (!st.computed) {
- pad_msg(st);
- st.computed = true;
- }
-
- let vec[u8] res = vec();
- 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);
- res += vec(a,b,c,d);
- }
- ret res;
- }
-
- /*
- * According to the standard, the message must be padded to an even
- * 512 bits. The first padding bit must be a '1'. The last 64 bits
- * represent the length of the original message. All bits in between
- * should be 0. This function will pad the message according to those
- * rules by filling the msg_block vector accordingly. It will also
- * call process_msg_block() appropriately. When it returns, it
- * can be assumed that the message digest has been computed.
- */
- fn pad_msg(&sha1state st) {
- // FIXME: Should be a precondition
- assert (Vec.len(st.msg_block) == msg_block_len);
-
- /*
- * Check to see if the current message block is too small to hold
- * the initial padding bits and length. If so, we will pad the
- * block, process it, and then continue padding into a second block.
- */
- 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) {
- st.msg_block.(st.msg_block_idx) = 0u8;
- st.msg_block_idx += 1u;
- }
-
- process_msg_block(st);
- } else {
- st.msg_block.(st.msg_block_idx) = 0x80u8;
- st.msg_block_idx += 1u;
- }
-
- while (st.msg_block_idx < 56u) {
- st.msg_block.(st.msg_block_idx) = 0u8;
- st.msg_block_idx += 1u;
- }
-
- // Store the message length as the last 8 octets
- st.msg_block.(56) = (st.len_high >> 24u32) & 0xFFu32 as u8;
- st.msg_block.(57) = (st.len_high >> 16u32) & 0xFFu32 as u8;
- st.msg_block.(58) = (st.len_high >> 8u32) & 0xFFu32 as u8;
- st.msg_block.(59) = st.len_high & 0xFFu32 as u8;
- st.msg_block.(60) = (st.len_low >> 24u32) & 0xFFu32 as u8;
- st.msg_block.(61) = (st.len_low >> 16u32) & 0xFFu32 as u8;
- st.msg_block.(62) = (st.len_low >> 8u32) & 0xFFu32 as u8;
- st.msg_block.(63) = st.len_low & 0xFFu32 as u8;
-
- process_msg_block(st);
- }
-
- state obj sha1(sha1state st) {
-
- fn reset() {
- // FIXME: Should be typestate precondition
- assert (Vec.len(st.h) == digest_buf_len);
-
- st.len_low = 0u32;
- st.len_high = 0u32;
- st.msg_block_idx = 0u;
-
- st.h.(0) = 0x67452301u32;
- st.h.(1) = 0xEFCDAB89u32;
- st.h.(2) = 0x98BADCFEu32;
- st.h.(3) = 0x10325476u32;
- st.h.(4) = 0xC3D2E1F0u32;
-
- st.computed = false;
- }
-
- fn input(&vec[u8] msg) {
- add_input(st, msg);
- }
-
- fn input_str(&str msg) {
- add_input(st, Str.bytes(msg));
- }
-
- fn result() -> vec[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);
- }
- ret s;
- }
- }
-
- auto st = rec(h = Vec.init_elt_mut[u32](0u32, digest_buf_len),
- mutable len_low = 0u32,
- mutable len_high = 0u32,
- msg_block = Vec.init_elt_mut[u8](0u8, msg_block_len),
- mutable msg_block_idx = 0u,
- mutable computed = false,
- work_buf = Vec.init_elt_mut[u32](0u32, work_buf_len));
- auto sh = sha1(st);
- sh.reset();
- ret sh;
-}
-
-// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
+++ /dev/null
-import Vec.len;
-import Vec.slice;
-
-type lteq[T] = fn(&T a, &T b) -> 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] res = vec();
- 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))) {
- res += vec(a.(a_ix));
- a_ix += 1u;
- } else {
- res += vec(b.(b_ix));
- b_ix += 1u;
- }
- }
- res += slice[T](a, a_ix, a_len);
- res += slice[T](b, b_ix, b_len);
- ret res;
- }
-
- 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);
- 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);
- 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 {
-
- fn compare[T](lteq[T] compare_func, vec[mutable T]arr,
- uint arr_idx, &T arr_value) -> bool {
-
- ret compare_func(arr.(arr_idx),arr_value);
- }
-
- auto pivot_value = arr.(pivot);
- swap[T](arr, pivot, right);
- let uint storage_index = left;
- let uint i = left;
- while (i<right) {
- if (compare[T](compare_func, arr, i, pivot_value)) {
- swap[T](arr, i, storage_index);
- storage_index += 1u;
- }
- i += 1u;
- }
- swap[T](arr, storage_index, right);
- 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) {
- ret;
- }
- qsort[T](compare_func, arr, left, new_pivot - 1u);
- qsort[T](compare_func, arr, new_pivot + 1u, right);
- }
-}
-
-fn quick_sort[T](lteq[T] compare_func, vec[mutable T] arr) {
-
- if (len[T](arr) == 0u) {
- ret;
- }
- qsort[T](compare_func, arr, 0u, (len[T](arr)) - 1u);
-}
-
-// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
+++ /dev/null
-import rustrt.sbuf;
-
-import Vec.rustrt.vbuf;
-
-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_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 eq(&str a, &str b) -> bool {
- let uint i = 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;
- }
- }
- 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;
- }
- x += 1u;
- }
-
- ret i <= j;
-}
-
-
-fn hash(&str s) -> uint {
- // djb hash.
- // FIXME: replace with murmur.
- let uint u = 5381u;
- for (u8 c in s) {
- u *= 33u;
- u += (c as uint);
- }
- ret u;
-}
-
-// UTF-8 tags and ranges
-const u8 tag_cont_u8 = 0x80_u8;
-const uint tag_cont = 0x80_u;
-const uint max_one_b = 0x80_u;
-const uint tag_two_b = 0xc0_u;
-const uint max_two_b = 0x800_u;
-const uint tag_three_b = 0xe0_u;
-const uint max_three_b = 0x10000_u;
-const uint tag_four_b = 0xf0_u;
-const uint max_four_b = 0x200000_u;
-const uint tag_five_b = 0xf8_u;
-const uint max_five_b = 0x4000000_u;
-const uint tag_six_b = 0xfc_u;
-
-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;}
- i += 1u;
- while (chsize > 1u) {
- if (v.(i) & 0xc0_u8 != tag_cont_u8) {ret false;}
- i += 1u;
- chsize -= 1u;
- }
- }
- ret true;
-}
-
-fn is_ascii(str s) -> bool {
- let uint i = byte_len(s);
- while (i > 0u) {
- i -= 1u;
- if ((s.(i) & 0x80_u8) != 0u8) {
- ret false;
- }
- }
- ret true;
-}
-
-fn alloc(uint n_bytes) -> str {
- ret rustrt.str_alloc(n_bytes);
-}
-
-// 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 buf(str s) -> sbuf {
- ret rustrt.str_buf(s);
-}
-
-fn bytes(str s) -> vec[u8] {
- ret rustrt.str_vec(s);
-}
-
-fn from_bytes(vec[u8] v) : is_utf8(v) -> str {
- ret rustrt.str_from_vec(v);
-}
-
-// FIXME temp thing
-fn unsafe_from_bytes(vec[mutable? u8] v) -> str {
- ret rustrt.str_from_vec(v);
-}
-
-fn unsafe_from_byte(u8 u) -> str {
- ret rustrt.str_from_vec(vec(u));
-}
-
-fn str_from_cstr(sbuf cstr) -> str {
- ret rustrt.str_from_cstr(cstr);
-}
-
-fn str_from_buf(sbuf buf, uint len) -> 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) {
- s = rustrt.str_push_byte(s, code);
- } else if (code < max_two_b) {
- s = rustrt.str_push_byte(s, ((code >> 6u) & 0x1f_u) | tag_two_b);
- s = rustrt.str_push_byte(s, (code & 0x3f_u) | tag_cont);
- } else if (code < max_three_b) {
- s = rustrt.str_push_byte(s, ((code >> 12u) & 0x0f_u) | tag_three_b);
- s = rustrt.str_push_byte(s, ((code >> 6u) & 0x3f_u) | tag_cont);
- s = rustrt.str_push_byte(s, (code & 0x3f_u) | tag_cont);
- } else if (code < max_four_b) {
- s = rustrt.str_push_byte(s, ((code >> 18u) & 0x07_u) | tag_four_b);
- s = rustrt.str_push_byte(s, ((code >> 12u) & 0x3f_u) | tag_cont);
- s = rustrt.str_push_byte(s, ((code >> 6u) & 0x3f_u) | tag_cont);
- s = rustrt.str_push_byte(s, (code & 0x3f_u) | tag_cont);
- } else if (code < max_five_b) {
- s = rustrt.str_push_byte(s, ((code >> 24u) & 0x03_u) | tag_five_b);
- s = rustrt.str_push_byte(s, ((code >> 18u) & 0x3f_u) | tag_cont);
- s = rustrt.str_push_byte(s, ((code >> 12u) & 0x3f_u) | tag_cont);
- s = rustrt.str_push_byte(s, ((code >> 6u) & 0x3f_u) | tag_cont);
- s = rustrt.str_push_byte(s, (code & 0x3f_u) | tag_cont);
- } else {
- s = rustrt.str_push_byte(s, ((code >> 30u) & 0x01_u) | tag_six_b);
- s = rustrt.str_push_byte(s, ((code >> 24u) & 0x3f_u) | tag_cont);
- s = rustrt.str_push_byte(s, ((code >> 18u) & 0x3f_u) | tag_cont);
- s = rustrt.str_push_byte(s, ((code >> 12u) & 0x3f_u) | tag_cont);
- s = rustrt.str_push_byte(s, ((code >> 6u) & 0x3f_u) | tag_cont);
- s = rustrt.str_push_byte(s, (code & 0x3f_u) | tag_cont);
- }
-}
-
-fn from_char(char ch) -> str {
- auto 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);}
- ret buf;
-}
-
-fn utf8_char_width(u8 b) -> uint {
- let uint byte = b as uint;
- if (byte < 0x80_u) {ret 1u;}
- if (byte < 0xc0_u) {ret 0u;} // Not a valid start byte
- if (byte < 0xe0_u) {ret 2u;}
- if (byte < 0xf0_u) {ret 3u;}
- if (byte < 0xf8_u) {ret 4u;}
- if (byte < 0xfc_u) {ret 5u;}
- ret 6u;
-}
-
-fn char_range_at(str s, uint i) -> tup(char, uint) {
- auto b0 = s.(i);
- auto w = utf8_char_width(b0);
- assert (w != 0u);
- if (w == 1u) {ret tup(b0 as char, i + 1u);}
- auto val = 0u;
- auto end = i + w;
- i += 1u;
- while (i < end) {
- auto byte = s.(i);
- assert (byte & 0xc0_u8 == tag_cont_u8);
- val <<= 6u;
- val += (byte & 0x3f_u8) as uint;
- i += 1u;
- }
- // Clunky way to get the right bits from the first byte. Uses two shifts,
- // the first to clip off the marker bits at the left of the byte, and then
- // 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 tup(val as char, i);
-}
-
-fn char_at(str s, uint i) -> char {
- ret char_range_at(s, i)._0;
-}
-
-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));
- assert (chsize > 0u);
- len += 1u;
- i += chsize;
- }
- assert (i == total);
- ret len;
-}
-
-fn to_chars(str s) -> vec[char] {
- let vec[char] buf = vec();
- auto i = 0u;
- auto len = byte_len(s);
- while (i < len) {
- auto cur = char_range_at(s, i);
- Vec.push[char](buf, cur._0);
- i = cur._1;
- }
- ret buf;
-}
-
-fn push_char(&mutable str s, char ch) {
- s += from_char(ch);
-}
-
-fn pop_char(&mutable str s) -> char {
- auto end = byte_len(s);
- while (end > 0u && s.(end - 1u) & 0xc0_u8 == tag_cont_u8) {end -= 1u;}
- assert (end > 0u);
- auto 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);
- s = substr(s, r._1, byte_len(s) - r._1);
- ret r._0;
-}
-
-fn unshift_char(&mutable str s, char ch) {
- // Workaround for rustboot order-of-evaluation issue -- if I put s
- // directly after the +, the string ends up containing (only) the
- // character, twice.
- auto x = s;
- s = from_char(ch) + x;
-}
-
-fn refcount(str s) -> uint {
- auto r = rustrt.refcount[u8](s);
- if (r == Dbg.const_refcount) {
- ret r;
- } else {
- // -1 because calling this function incremented the refcount.
- 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;
- }
- 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;
- }
- 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;
- }
- ret true;
- }
-
- let int i = 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;
- }
- 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);
- if (needle_len == 0u) {
- ret true;
- }
- if (needle_len > haystack_len) {
- ret false;
- }
- ret eq(substr(haystack,
- haystack_len - needle_len,
- needle_len),
- needle);
-}
-
-fn substr(str s, uint begin, uint len) -> str {
- ret slice(s, begin, begin + len);
-}
-
-fn slice(str s, uint begin, uint end) -> str {
- // FIXME: Typestate precondition
- assert (begin <= end);
- assert (end <= Str.byte_len(s));
- ret rustrt.str_slice(s, begin, end);
-}
-
-fn shift_byte(&mutable str s) -> u8 {
- auto len = byte_len(s);
- assert (len > 0u);
- auto b = s.(0);
- s = substr(s, 1u, len - 1u);
- ret b;
-}
-
-fn pop_byte(&mutable str s) -> u8 {
- auto len = byte_len(s);
- assert (len > 0u);
- auto b = s.(len - 1u);
- s = substr(s, 0u, len - 1u);
- ret b;
-}
-
-fn push_byte(&mutable str s, u8 b) {
- s = rustrt.str_push_byte(s, b as uint);
-}
-
-fn unshift_byte(&mutable str s, u8 b) {
- auto res = alloc(byte_len(s) + 1u);
- res += unsafe_from_byte(b);
- res += s;
- s = res;
-}
-
-fn split(str s, u8 sep) -> vec[str] {
- let vec[str] v = vec();
- let str accum = "";
- let bool ends_with_sep = false;
- for (u8 c in s) {
- if (c == sep) {
- v += vec(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 += vec(accum);
- }
- ret v;
-}
-
-fn concat(vec[str] v) -> str {
- let str s = "";
- for (str ss 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;
- }
- s += ss;
- }
- ret s;
-}
-
-// 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) {
- next = byte - diff;
- } else {
- next = byte;
- }
- push_byte(outstr, next);
- }
- ret outstr;
-}
-
-
-// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
+++ /dev/null
-export rustrt;
-
-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.
-
- export last_os_error;
- export size_of;
- export align_of;
- export refcount;
- export do_gc;
-
- fn last_os_error() -> str;
- fn size_of[T]() -> uint;
- fn align_of[T]() -> uint;
- fn refcount[T](@T t) -> uint;
- fn do_gc();
- fn unsupervise();
-}
-
-// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
+++ /dev/null
-native "rust" mod rustrt {
- fn task_sleep(uint time_in_us);
-}
-
-/**
- * Hints the scheduler to yield this task for a specified ammount of time.
- *
- * 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);
-}
-
-// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
+++ /dev/null
-// Simple ANSI color library.
-//
-// TODO: Windows support.
-
-const u8 color_black = 0u8;
-const u8 color_red = 1u8;
-const u8 color_green = 2u8;
-const u8 color_yellow = 3u8;
-const u8 color_blue = 4u8;
-const u8 color_magenta = 5u8;
-const u8 color_cyan = 6u8;
-const u8 color_light_gray = 7u8;
-const u8 color_light_grey = 7u8;
-const u8 color_dark_gray = 8u8;
-const u8 color_dark_grey = 8u8;
-const u8 color_bright_red = 9u8;
-const u8 color_bright_green = 10u8;
-const u8 color_bright_yellow = 11u8;
-const u8 color_bright_blue = 12u8;
-const u8 color_bright_magenta = 13u8;
-const u8 color_bright_cyan = 14u8;
-const u8 color_bright_white = 15u8;
-
-fn esc(IO.buf_writer writer) {
- writer.write(vec(0x1bu8, '[' as u8));
-}
-
-fn reset(IO.buf_writer writer) {
- esc(writer);
- writer.write(vec('0' as u8, 'm' as u8));
-}
-
-fn color_supported() -> bool {
- ret GenericOS.getenv("TERM") == Option.some[str]("xterm-color");
-}
-
-fn set_color(IO.buf_writer writer, u8 first_char, u8 color) {
- assert (color < 16u8);
-
- esc(writer);
- if (color >= 8u8) {
- writer.write(vec('1' as u8, ';' as u8));
- color -= 8u8;
- }
- writer.write(vec(first_char, ('0' as u8) + color, 'm' as u8));
-}
-
-fn fg(IO.buf_writer writer, u8 color) {
- ret set_color(writer, '3' as u8, color);
-}
-
-fn bg(IO.buf_writer writer, u8 color) {
- ret set_color(writer, '4' as u8, color);
-}
-
-// export fg;
-// export bg;
-
+++ /dev/null
-native "rust" mod rustrt {
- fn get_time(&mutable u32 sec, &mutable u32 usec);
-}
-
-type timeval = rec(u32 sec, u32 usec);
-
-fn get_time() -> timeval {
- let timeval res = rec(sec=0u32, usec=0u32);
- rustrt.get_time(res.sec, res.usec);
- ret res;
-}
-
+++ /dev/null
-fn add(u8 x, u8 y) -> u8 { ret x + y; }
-fn sub(u8 x, u8 y) -> u8 { ret x - y; }
-fn mul(u8 x, u8 y) -> u8 { ret x * y; }
-fn div(u8 x, u8 y) -> u8 { ret x / y; }
-fn rem(u8 x, u8 y) -> u8 { ret x % y; }
-
-fn lt(u8 x, u8 y) -> bool { ret x < y; }
-fn le(u8 x, u8 y) -> bool { ret x <= y; }
-fn eq(u8 x, u8 y) -> bool { ret x == y; }
-fn ne(u8 x, u8 y) -> bool { ret x != y; }
-fn ge(u8 x, u8 y) -> bool { ret x >= y; }
-fn gt(u8 x, u8 y) -> bool { ret x > y; }
-
-iter range(u8 lo, u8 hi) -> u8 {
- while (lo < hi) {
- put lo;
- lo += 1u8;
- }
-}
-
-// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
+++ /dev/null
-import Option.none;
-import Option.some;
-
-// A very naive implementation of union-find with unsigned integer nodes.
-
-type node = Option.t[uint];
-type ufind = rec(mutable vec[mutable node] nodes);
-
-fn make() -> ufind {
- let vec[mutable node] v = vec(mutable none[uint]);
- Vec.pop(v); // FIXME: botch
- ret rec(mutable nodes=v);
-}
-
-fn make_set(&ufind ufnd) -> uint {
- auto idx = Vec.len(ufnd.nodes);
- ufnd.nodes += vec(mutable none[uint]);
- ret idx;
-}
-
-fn find(&ufind ufnd, uint n) -> uint {
- alt (ufnd.nodes.(n)) {
- case (none[uint]) { ret n; }
- case (some[uint](?m)) {
- // TODO: "be"
- ret find(ufnd, m);
- }
- }
-}
-
-fn union(&ufind ufnd, uint m, uint n) {
- auto m_root = find(ufnd, m);
- auto n_root = find(ufnd, n);
- auto ptr = some[uint](n_root);
- ufnd.nodes.(m_root) = ptr;
-}
-
+++ /dev/null
-
-fn add(uint x, uint y) -> uint { ret x + y; }
-fn sub(uint x, uint y) -> uint { ret x - y; }
-fn mul(uint x, uint y) -> uint { ret x * y; }
-fn div(uint x, uint y) -> uint { ret x / y; }
-fn rem(uint x, uint y) -> uint { ret x % y; }
-
-fn lt(uint x, uint y) -> bool { ret x < y; }
-fn le(uint x, uint y) -> bool { ret x <= y; }
-fn eq(uint x, uint y) -> bool { ret x == y; }
-fn ne(uint x, uint y) -> bool { ret x != y; }
-fn ge(uint x, uint y) -> bool { ret x >= y; }
-fn gt(uint x, uint y) -> bool { ret x > y; }
-
-iter range(uint lo, uint hi) -> uint {
- auto lo_ = lo;
- while (lo_ < hi) {
- put lo_;
- lo_ += 1u;
- }
-}
-
-fn next_power_of_two(uint n) -> 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;
- }
- 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) {
- n += (((buf.(i)) - ('0' as u8)) as uint) * power;
- power *= radix;
- if (i == 0u) { ret n; }
- i -= 1u;
- }
-
- fail;
-}
-
-fn to_str(uint num, uint radix) -> str
-{
- auto n = num;
-
- assert (0u < radix && radix <= 16u);
- fn digit(uint n) -> char {
- alt (n) {
- case (0u) { ret '0'; }
- case (1u) { ret '1'; }
- case (2u) { ret '2'; }
- case (3u) { ret '3'; }
- case (4u) { ret '4'; }
- case (5u) { ret '5'; }
- case (6u) { ret '6'; }
- case (7u) { ret '7'; }
- case (8u) { ret '8'; }
- case (9u) { ret '9'; }
- case (10u) { ret 'a'; }
- case (11u) { ret 'b'; }
- case (12u) { ret 'c'; }
- case (13u) { ret 'd'; }
- case (14u) { ret 'e'; }
- case (15u) { ret 'f'; }
- }
- fail;
- }
-
- if (n == 0u) { ret "0"; }
-
- let str s = "";
- 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));
- }
- ret s1;
-
-}
-
-// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
+++ /dev/null
-fn id[T](&T x) -> 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); // : Int.positive(*.den);
-
-fn rational_leq(&rational x, &rational y) -> bool {
- // NB: Uses the fact that rationals have positive denominators WLOG.
- ret x.num * y.den <= y.num * x.den;
-}
-
-fn fst[T, U](&tup(T, U) x) -> T {
- ret x._0;
-}
-
-fn snd[T, U](&tup(T, U) x) -> U {
- ret x._1;
-}
-
-fn orb(&bool a, &bool b) -> bool {
- ret a || b;
-}
-
-// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
+++ /dev/null
-import Option.none;
-import Option.some;
-import Util.orb;
-
-type vbuf = rustrt.vbuf;
-
-type operator2[T,U,V] = fn(&T, &U) -> V;
-
-type array[T] = vec[mutable? T];
-
-native "rust" mod rustrt {
- type vbuf;
-
- fn vec_buf[T](vec[T] v, uint offset) -> vbuf;
-
- fn vec_len[T](vec[T] v) -> 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);
-
- /**
- * 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];
-}
-
-fn alloc[T](uint n_elts) -> vec[T] {
- ret rustrt.vec_alloc[vec[T], T](n_elts);
-}
-
-fn alloc_mut[T](uint n_elts) -> 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 {
- // -1 because calling this function incremented the refcount.
- ret r - 1u;
- }
-}
-
-fn vec_from_vbuf[T](vbuf v, uint n_elts) -> vec[T] {
- ret rustrt.vec_from_vbuf[T](v, n_elts);
-}
-
-// FIXME: Remove me; this is a botch to get around rustboot's bad typechecker.
-fn empty[T]() -> vec[T] {
- ret alloc[T](0u);
-}
-
-// FIXME: Remove me; this is a botch to get around rustboot's bad typechecker.
-fn empty_mut[T]() -> vec[mutable T] {
- ret alloc_mut[T](0u);
-}
-
-type init_op[T] = fn(uint i) -> 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 += vec(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 += vec(mutable op(i));
- i += 1u;
- }
- ret v;
-}
-
-fn init_elt[T](&T t, uint n_elts) -> vec[T] {
- /**
- * FIXME (issue #81): should be:
- *
- * fn elt_op[T](&T x, uint i) -> T { ret x; }
- * let init_op[T] inner = bind elt_op[T](t, _);
- * 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 += vec(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 += vec(mutable t);
- }
- ret v;
-}
-
-fn buf[T](array[T] v) -> vbuf {
- ret rustrt.vec_buf[T](v, 0u);
-}
-
-fn len[T](array[T] v) -> uint {
- ret rustrt.vec_len[T](v);
-}
-
-fn len_set[T](array[T] v, uint n) {
- rustrt.vec_len_set[T](v, n);
-}
-
-fn buf_off[T](array[T] v, uint offset) -> 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);
-}
-
-// 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];
- }
- 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] {
- assert (start <= end);
- assert (end <= len[T](v));
- auto result = alloc[T](end - start);
- let uint i = start;
- while (i < end) {
- result += vec(v.(i));
- i += 1u;
- }
- ret result;
-}
-
-fn shift[T](&mutable array[T] v) -> T {
- auto ln = len[T](v);
- assert (ln > 0u);
- auto e = v.(0);
- v = slice[T](v, 1u, ln);
- ret e;
-}
-
-fn pop[T](&mutable array[T] v) -> T {
- auto ln = len[T](v);
- assert (ln > 0u);
- ln -= 1u;
- auto e = v.(ln);
- v = slice[T](v, 0u, ln);
- ret e;
-}
-
-fn push[T](&mutable array[T] v, &T t) {
- v += vec(t);
-}
-
-fn unshift[T](&mutable array[T] v, &T t) {
- auto res = alloc[T](len[T](v) + 1u);
- res += vec(t);
- res += v;
- v = res;
-}
-
-fn grow[T](&array[T] v, uint n, &T initval) {
- let uint i = n;
- while (i > 0u) {
- i -= 1u;
- v += vec(initval);
- }
-}
-
-fn grow_set[T](&vec[mutable T] v, uint index, &T initval, &T val) {
- auto length = Vec.len(v);
- if (index >= length) {
- grow(v, index - length + 1u, initval);
- }
- v.(index) = val;
-}
-
-fn map[T, U](&Option.operator[T,U] f, &array[T] v) -> vec[U] {
- let vec[U] u = alloc[U](len[T](v));
- for (T ve in v) {
- u += vec(f(ve));
- }
- ret u;
-}
-
-fn map2[T,U,V](&operator2[T,U,V] f, &array[T] v0, &array[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 += vec(f(v0.(i), v1.(i)));
- i += 1u;
- }
-
- ret u;
-}
-
-fn find[T](fn (&T) -> bool f, &array[T] v) -> Option.t[T] {
- for (T elt in v) {
- if (f(elt)) {
- ret some[T](elt);
- }
- }
-
- ret none[T];
-}
-
-fn foldl[T, U](fn (&U, &T) -> U p, &U z, &vec[T] v) -> U {
- auto sz = len[T](v);
-
- if (sz == 0u) {
- ret z;
- }
- else {
- auto rest = slice[T](v, 1u, sz);
-
- ret (p(foldl[T,U](p, z, rest), v.(0)));
- }
-}
-
-fn unzip[T, U](&vec[tup(T, U)] v) -> tup(vec[T], vec[U]) {
- auto sz = len[tup(T, U)](v);
-
- if (sz == 0u) {
- ret tup(alloc[T](0u), alloc[U](0u));
- }
- else {
- auto rest = slice[tup(T, U)](v, 1u, sz);
- auto tl = unzip[T, U](rest);
- auto a = vec(v.(0)._0);
- auto b = vec(v.(0)._1);
- ret tup(a + tl._0, b + tl._1);
- }
-}
-
-fn or(&vec[bool] v) -> bool {
- auto f = orb;
- ret Vec.foldl[bool, bool](f, false, v);
-}
-
-fn clone[T](&vec[T] v) -> vec[T] {
- ret slice[T](v, 0u, len[T](v));
-}
-
-fn plus_option[T](&vec[T] v, &Option.t[T] o) -> () {
- alt (o) {
- case (none[T]) {}
- case (some[T](?x)) { v += vec(x); }
- }
-}
-
-fn cat_options[T](&vec[Option.t[T]] v) -> vec[T] {
- let vec[T] res = vec();
-
- for (Option.t[T] o in v) {
- alt (o) {
- case (none[T]) { }
- case (some[T](?t)) {
- res += vec(t);
- }
- }
- }
-
- ret res;
-}
-
-// 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 = vec();
- for (T elem in v) {
- result += vec(elem);
- }
- ret result;
-}
-
-// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
--- /dev/null
+
+fn add(int x, int y) -> int { ret x + y; }
+fn sub(int x, int y) -> int { ret x - y; }
+fn mul(int x, int y) -> int { ret x * y; }
+fn div(int x, int y) -> int { ret x / y; }
+fn rem(int x, int y) -> int { ret x % y; }
+
+fn lt(int x, int y) -> bool { ret x < y; }
+fn le(int x, int y) -> bool { ret x <= y; }
+fn eq(int x, int y) -> bool { ret x == y; }
+fn ne(int x, int y) -> bool { ret x != y; }
+fn ge(int x, int y) -> bool { ret x >= y; }
+fn gt(int x, int y) -> bool { ret x > y; }
+
+fn positive(int x) -> bool { ret x > 0; }
+fn negative(int x) -> bool { ret x < 0; }
+fn nonpositive(int x) -> bool { ret x <= 0; }
+fn nonnegative(int x) -> bool { ret x >= 0; }
+
+iter range(int lo, int hi) -> int {
+ let int lo_ = lo;
+ while (lo_ < hi) {
+ put lo_;
+ lo_ += 1;
+ }
+}
+
+fn to_str(int n, uint radix) -> str
+{
+ assert (0u < radix && radix <= 16u);
+ if (n < 0) {
+ ret "-" + _uint::to_str((-n) as uint, radix);
+ } else {
+ ret _uint::to_str(n as uint, radix);
+ }
+}
+
+fn pow(int base, uint exponent) -> int {
+
+ if (exponent == 0u) {
+ ret 1;
+ } else if (base == 0) {
+ ret 0;
+ } else {
+ auto accum = base;
+ auto count = exponent;
+ while (count > 1u) {
+ accum *= base;
+ count -= 1u;
+ }
+ ret accum;
+ }
+}
+
+// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
--- /dev/null
+import rustrt::sbuf;
+
+import _vec::rustrt::vbuf;
+
+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_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 eq(&str a, &str b) -> bool {
+ let uint i = 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;
+ }
+ }
+ 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;
+ }
+ x += 1u;
+ }
+
+ ret i <= j;
+}
+
+
+fn hash(&str s) -> uint {
+ // djb hash.
+ // FIXME: replace with murmur.
+ let uint u = 5381u;
+ for (u8 c in s) {
+ u *= 33u;
+ u += (c as uint);
+ }
+ ret u;
+}
+
+// UTF-8 tags and ranges
+const u8 tag_cont_u8 = 0x80_u8;
+const uint tag_cont = 0x80_u;
+const uint max_one_b = 0x80_u;
+const uint tag_two_b = 0xc0_u;
+const uint max_two_b = 0x800_u;
+const uint tag_three_b = 0xe0_u;
+const uint max_three_b = 0x10000_u;
+const uint tag_four_b = 0xf0_u;
+const uint max_four_b = 0x200000_u;
+const uint tag_five_b = 0xf8_u;
+const uint max_five_b = 0x4000000_u;
+const uint tag_six_b = 0xfc_u;
+
+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;}
+ i += 1u;
+ while (chsize > 1u) {
+ if (v.(i) & 0xc0_u8 != tag_cont_u8) {ret false;}
+ i += 1u;
+ chsize -= 1u;
+ }
+ }
+ ret true;
+}
+
+fn is_ascii(str s) -> bool {
+ let uint i = byte_len(s);
+ while (i > 0u) {
+ i -= 1u;
+ if ((s.(i) & 0x80_u8) != 0u8) {
+ ret false;
+ }
+ }
+ ret true;
+}
+
+fn alloc(uint n_bytes) -> str {
+ ret rustrt::str_alloc(n_bytes);
+}
+
+// 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 buf(str s) -> sbuf {
+ ret rustrt::str_buf(s);
+}
+
+fn bytes(str s) -> vec[u8] {
+ ret rustrt::str_vec(s);
+}
+
+fn from_bytes(vec[u8] v) : is_utf8(v) -> str {
+ ret rustrt::str_from_vec(v);
+}
+
+// FIXME temp thing
+fn unsafe_from_bytes(vec[mutable? u8] v) -> str {
+ ret rustrt::str_from_vec(v);
+}
+
+fn unsafe_from_byte(u8 u) -> str {
+ ret rustrt::str_from_vec(vec(u));
+}
+
+fn str_from_cstr(sbuf cstr) -> str {
+ ret rustrt::str_from_cstr(cstr);
+}
+
+fn str_from_buf(sbuf buf, uint len) -> 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) {
+ s = rustrt::str_push_byte(s, code);
+ } else if (code < max_two_b) {
+ s = rustrt::str_push_byte(s, ((code >> 6u) & 0x1f_u) | tag_two_b);
+ s = rustrt::str_push_byte(s, (code & 0x3f_u) | tag_cont);
+ } else if (code < max_three_b) {
+ s = rustrt::str_push_byte(s, ((code >> 12u) & 0x0f_u) | tag_three_b);
+ s = rustrt::str_push_byte(s, ((code >> 6u) & 0x3f_u) | tag_cont);
+ s = rustrt::str_push_byte(s, (code & 0x3f_u) | tag_cont);
+ } else if (code < max_four_b) {
+ s = rustrt::str_push_byte(s, ((code >> 18u) & 0x07_u) | tag_four_b);
+ s = rustrt::str_push_byte(s, ((code >> 12u) & 0x3f_u) | tag_cont);
+ s = rustrt::str_push_byte(s, ((code >> 6u) & 0x3f_u) | tag_cont);
+ s = rustrt::str_push_byte(s, (code & 0x3f_u) | tag_cont);
+ } else if (code < max_five_b) {
+ s = rustrt::str_push_byte(s, ((code >> 24u) & 0x03_u) | tag_five_b);
+ s = rustrt::str_push_byte(s, ((code >> 18u) & 0x3f_u) | tag_cont);
+ s = rustrt::str_push_byte(s, ((code >> 12u) & 0x3f_u) | tag_cont);
+ s = rustrt::str_push_byte(s, ((code >> 6u) & 0x3f_u) | tag_cont);
+ s = rustrt::str_push_byte(s, (code & 0x3f_u) | tag_cont);
+ } else {
+ s = rustrt::str_push_byte(s, ((code >> 30u) & 0x01_u) | tag_six_b);
+ s = rustrt::str_push_byte(s, ((code >> 24u) & 0x3f_u) | tag_cont);
+ s = rustrt::str_push_byte(s, ((code >> 18u) & 0x3f_u) | tag_cont);
+ s = rustrt::str_push_byte(s, ((code >> 12u) & 0x3f_u) | tag_cont);
+ s = rustrt::str_push_byte(s, ((code >> 6u) & 0x3f_u) | tag_cont);
+ s = rustrt::str_push_byte(s, (code & 0x3f_u) | tag_cont);
+ }
+}
+
+fn from_char(char ch) -> str {
+ auto 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);}
+ ret buf;
+}
+
+fn utf8_char_width(u8 b) -> uint {
+ let uint byte = b as uint;
+ if (byte < 0x80_u) {ret 1u;}
+ if (byte < 0xc0_u) {ret 0u;} // Not a valid start byte
+ if (byte < 0xe0_u) {ret 2u;}
+ if (byte < 0xf0_u) {ret 3u;}
+ if (byte < 0xf8_u) {ret 4u;}
+ if (byte < 0xfc_u) {ret 5u;}
+ ret 6u;
+}
+
+fn char_range_at(str s, uint i) -> tup(char, uint) {
+ auto b0 = s.(i);
+ auto w = utf8_char_width(b0);
+ assert (w != 0u);
+ if (w == 1u) {ret tup(b0 as char, i + 1u);}
+ auto val = 0u;
+ auto end = i + w;
+ i += 1u;
+ while (i < end) {
+ auto byte = s.(i);
+ assert (byte & 0xc0_u8 == tag_cont_u8);
+ val <<= 6u;
+ val += (byte & 0x3f_u8) as uint;
+ i += 1u;
+ }
+ // Clunky way to get the right bits from the first byte. Uses two shifts,
+ // the first to clip off the marker bits at the left of the byte, and then
+ // 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 tup(val as char, i);
+}
+
+fn char_at(str s, uint i) -> char {
+ ret char_range_at(s, i)._0;
+}
+
+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));
+ assert (chsize > 0u);
+ len += 1u;
+ i += chsize;
+ }
+ assert (i == total);
+ ret len;
+}
+
+fn to_chars(str s) -> vec[char] {
+ let vec[char] buf = vec();
+ auto i = 0u;
+ auto len = byte_len(s);
+ while (i < len) {
+ auto cur = char_range_at(s, i);
+ _vec::push[char](buf, cur._0);
+ i = cur._1;
+ }
+ ret buf;
+}
+
+fn push_char(&mutable str s, char ch) {
+ s += from_char(ch);
+}
+
+fn pop_char(&mutable str s) -> char {
+ auto end = byte_len(s);
+ while (end > 0u && s.(end - 1u) & 0xc0_u8 == tag_cont_u8) {end -= 1u;}
+ assert (end > 0u);
+ auto 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);
+ s = substr(s, r._1, byte_len(s) - r._1);
+ ret r._0;
+}
+
+fn unshift_char(&mutable str s, char ch) {
+ // Workaround for rustboot order-of-evaluation issue -- if I put s
+ // directly after the +, the string ends up containing (only) the
+ // character, twice.
+ auto x = s;
+ s = from_char(ch) + x;
+}
+
+fn refcount(str s) -> uint {
+ auto r = rustrt::refcount[u8](s);
+ if (r == dbg::const_refcount) {
+ ret r;
+ } else {
+ // -1 because calling this function incremented the refcount.
+ 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;
+ }
+ 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;
+ }
+ 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;
+ }
+ ret true;
+ }
+
+ let int i = 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;
+ }
+ 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);
+ if (needle_len == 0u) {
+ ret true;
+ }
+ if (needle_len > haystack_len) {
+ ret false;
+ }
+ ret eq(substr(haystack,
+ haystack_len - needle_len,
+ needle_len),
+ needle);
+}
+
+fn substr(str s, uint begin, uint len) -> str {
+ ret slice(s, begin, begin + len);
+}
+
+fn slice(str s, uint begin, uint end) -> str {
+ // FIXME: Typestate precondition
+ assert (begin <= end);
+ assert (end <= _str::byte_len(s));
+ ret rustrt::str_slice(s, begin, end);
+}
+
+fn shift_byte(&mutable str s) -> u8 {
+ auto len = byte_len(s);
+ assert (len > 0u);
+ auto b = s.(0);
+ s = substr(s, 1u, len - 1u);
+ ret b;
+}
+
+fn pop_byte(&mutable str s) -> u8 {
+ auto len = byte_len(s);
+ assert (len > 0u);
+ auto b = s.(len - 1u);
+ s = substr(s, 0u, len - 1u);
+ ret b;
+}
+
+fn push_byte(&mutable str s, u8 b) {
+ s = rustrt::str_push_byte(s, b as uint);
+}
+
+fn unshift_byte(&mutable str s, u8 b) {
+ auto res = alloc(byte_len(s) + 1u);
+ res += unsafe_from_byte(b);
+ res += s;
+ s = res;
+}
+
+fn split(str s, u8 sep) -> vec[str] {
+ let vec[str] v = vec();
+ let str accum = "";
+ let bool ends_with_sep = false;
+ for (u8 c in s) {
+ if (c == sep) {
+ v += vec(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 += vec(accum);
+ }
+ ret v;
+}
+
+fn concat(vec[str] v) -> str {
+ let str s = "";
+ for (str ss 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;
+ }
+ s += ss;
+ }
+ ret s;
+}
+
+// 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) {
+ next = byte - diff;
+ } else {
+ next = byte;
+ }
+ push_byte(outstr, next);
+ }
+ ret outstr;
+}
+
+
+// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
--- /dev/null
+native "rust" mod rustrt {
+ fn task_sleep(uint time_in_us);
+}
+
+/**
+ * Hints the scheduler to yield this task for a specified ammount of time.
+ *
+ * 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);
+}
+
+// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
--- /dev/null
+fn add(u8 x, u8 y) -> u8 { ret x + y; }
+fn sub(u8 x, u8 y) -> u8 { ret x - y; }
+fn mul(u8 x, u8 y) -> u8 { ret x * y; }
+fn div(u8 x, u8 y) -> u8 { ret x / y; }
+fn rem(u8 x, u8 y) -> u8 { ret x % y; }
+
+fn lt(u8 x, u8 y) -> bool { ret x < y; }
+fn le(u8 x, u8 y) -> bool { ret x <= y; }
+fn eq(u8 x, u8 y) -> bool { ret x == y; }
+fn ne(u8 x, u8 y) -> bool { ret x != y; }
+fn ge(u8 x, u8 y) -> bool { ret x >= y; }
+fn gt(u8 x, u8 y) -> bool { ret x > y; }
+
+iter range(u8 lo, u8 hi) -> u8 {
+ while (lo < hi) {
+ put lo;
+ lo += 1u8;
+ }
+}
+
+// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
--- /dev/null
+
+fn add(uint x, uint y) -> uint { ret x + y; }
+fn sub(uint x, uint y) -> uint { ret x - y; }
+fn mul(uint x, uint y) -> uint { ret x * y; }
+fn div(uint x, uint y) -> uint { ret x / y; }
+fn rem(uint x, uint y) -> uint { ret x % y; }
+
+fn lt(uint x, uint y) -> bool { ret x < y; }
+fn le(uint x, uint y) -> bool { ret x <= y; }
+fn eq(uint x, uint y) -> bool { ret x == y; }
+fn ne(uint x, uint y) -> bool { ret x != y; }
+fn ge(uint x, uint y) -> bool { ret x >= y; }
+fn gt(uint x, uint y) -> bool { ret x > y; }
+
+iter range(uint lo, uint hi) -> uint {
+ auto lo_ = lo;
+ while (lo_ < hi) {
+ put lo_;
+ lo_ += 1u;
+ }
+}
+
+fn next_power_of_two(uint n) -> 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;
+ }
+ 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) {
+ n += (((buf.(i)) - ('0' as u8)) as uint) * power;
+ power *= radix;
+ if (i == 0u) { ret n; }
+ i -= 1u;
+ }
+
+ fail;
+}
+
+fn to_str(uint num, uint radix) -> str
+{
+ auto n = num;
+
+ assert (0u < radix && radix <= 16u);
+ fn digit(uint n) -> char {
+ alt (n) {
+ case (0u) { ret '0'; }
+ case (1u) { ret '1'; }
+ case (2u) { ret '2'; }
+ case (3u) { ret '3'; }
+ case (4u) { ret '4'; }
+ case (5u) { ret '5'; }
+ case (6u) { ret '6'; }
+ case (7u) { ret '7'; }
+ case (8u) { ret '8'; }
+ case (9u) { ret '9'; }
+ case (10u) { ret 'a'; }
+ case (11u) { ret 'b'; }
+ case (12u) { ret 'c'; }
+ case (13u) { ret 'd'; }
+ case (14u) { ret 'e'; }
+ case (15u) { ret 'f'; }
+ }
+ fail;
+ }
+
+ if (n == 0u) { ret "0"; }
+
+ let str s = "";
+ 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));
+ }
+ ret s1;
+
+}
+
+// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
--- /dev/null
+import option::none;
+import option::some;
+import util::orb;
+
+type vbuf = rustrt::vbuf;
+
+type operator2[T,U,V] = fn(&T, &U) -> V;
+
+type array[T] = vec[mutable? T];
+
+native "rust" mod rustrt {
+ type vbuf;
+
+ fn vec_buf[T](vec[T] v, uint offset) -> vbuf;
+
+ fn vec_len[T](vec[T] v) -> 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);
+
+ /**
+ * 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];
+}
+
+fn alloc[T](uint n_elts) -> vec[T] {
+ ret rustrt::vec_alloc[vec[T], T](n_elts);
+}
+
+fn alloc_mut[T](uint n_elts) -> 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 {
+ // -1 because calling this function incremented the refcount.
+ ret r - 1u;
+ }
+}
+
+fn vec_from_vbuf[T](vbuf v, uint n_elts) -> vec[T] {
+ ret rustrt::vec_from_vbuf[T](v, n_elts);
+}
+
+// FIXME: Remove me; this is a botch to get around rustboot's bad typechecker.
+fn empty[T]() -> vec[T] {
+ ret alloc[T](0u);
+}
+
+// FIXME: Remove me; this is a botch to get around rustboot's bad typechecker.
+fn empty_mut[T]() -> vec[mutable T] {
+ ret alloc_mut[T](0u);
+}
+
+type init_op[T] = fn(uint i) -> 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 += vec(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 += vec(mutable op(i));
+ i += 1u;
+ }
+ ret v;
+}
+
+fn init_elt[T](&T t, uint n_elts) -> vec[T] {
+ /**
+ * FIXME (issue #81): should be:
+ *
+ * fn elt_op[T](&T x, uint i) -> T { ret x; }
+ * let init_op[T] inner = bind elt_op[T](t, _);
+ * 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 += vec(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 += vec(mutable t);
+ }
+ ret v;
+}
+
+fn buf[T](array[T] v) -> vbuf {
+ ret rustrt::vec_buf[T](v, 0u);
+}
+
+fn len[T](array[T] v) -> uint {
+ ret rustrt::vec_len[T](v);
+}
+
+fn len_set[T](array[T] v, uint n) {
+ rustrt::vec_len_set[T](v, n);
+}
+
+fn buf_off[T](array[T] v, uint offset) -> 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);
+}
+
+// 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];
+ }
+ 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] {
+ assert (start <= end);
+ assert (end <= len[T](v));
+ auto result = alloc[T](end - start);
+ let uint i = start;
+ while (i < end) {
+ result += vec(v.(i));
+ i += 1u;
+ }
+ ret result;
+}
+
+fn shift[T](&mutable array[T] v) -> T {
+ auto ln = len[T](v);
+ assert (ln > 0u);
+ auto e = v.(0);
+ v = slice[T](v, 1u, ln);
+ ret e;
+}
+
+fn pop[T](&mutable array[T] v) -> T {
+ auto ln = len[T](v);
+ assert (ln > 0u);
+ ln -= 1u;
+ auto e = v.(ln);
+ v = slice[T](v, 0u, ln);
+ ret e;
+}
+
+fn push[T](&mutable array[T] v, &T t) {
+ v += vec(t);
+}
+
+fn unshift[T](&mutable array[T] v, &T t) {
+ auto res = alloc[T](len[T](v) + 1u);
+ res += vec(t);
+ res += v;
+ v = res;
+}
+
+fn grow[T](&array[T] v, uint n, &T initval) {
+ let uint i = n;
+ while (i > 0u) {
+ i -= 1u;
+ v += vec(initval);
+ }
+}
+
+fn grow_set[T](&vec[mutable T] v, uint index, &T initval, &T val) {
+ auto length = _vec::len(v);
+ if (index >= length) {
+ grow(v, index - length + 1u, initval);
+ }
+ v.(index) = val;
+}
+
+fn map[T, U](&option::operator[T,U] f, &array[T] v) -> vec[U] {
+ let vec[U] u = alloc[U](len[T](v));
+ for (T ve in v) {
+ u += vec(f(ve));
+ }
+ ret u;
+}
+
+fn map2[T,U,V](&operator2[T,U,V] f, &array[T] v0, &array[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 += vec(f(v0.(i), v1.(i)));
+ i += 1u;
+ }
+
+ ret u;
+}
+
+fn find[T](fn (&T) -> bool f, &array[T] v) -> option::t[T] {
+ for (T elt in v) {
+ if (f(elt)) {
+ ret some[T](elt);
+ }
+ }
+
+ ret none[T];
+}
+
+fn foldl[T, U](fn (&U, &T) -> U p, &U z, &vec[T] v) -> U {
+ auto sz = len[T](v);
+
+ if (sz == 0u) {
+ ret z;
+ }
+ else {
+ auto rest = slice[T](v, 1u, sz);
+
+ ret (p(foldl[T,U](p, z, rest), v.(0)));
+ }
+}
+
+fn unzip[T, U](&vec[tup(T, U)] v) -> tup(vec[T], vec[U]) {
+ auto sz = len[tup(T, U)](v);
+
+ if (sz == 0u) {
+ ret tup(alloc[T](0u), alloc[U](0u));
+ }
+ else {
+ auto rest = slice[tup(T, U)](v, 1u, sz);
+ auto tl = unzip[T, U](rest);
+ auto a = vec(v.(0)._0);
+ auto b = vec(v.(0)._1);
+ ret tup(a + tl._0, b + tl._1);
+ }
+}
+
+fn or(&vec[bool] v) -> bool {
+ auto f = orb;
+ ret _vec::foldl[bool, bool](f, false, v);
+}
+
+fn clone[T](&vec[T] v) -> vec[T] {
+ ret slice[T](v, 0u, len[T](v));
+}
+
+fn plus_option[T](&vec[T] v, &option::t[T] o) -> () {
+ alt (o) {
+ case (none[T]) {}
+ case (some[T](?x)) { v += vec(x); }
+ }
+}
+
+fn cat_options[T](&vec[option::t[T]] v) -> vec[T] {
+ let vec[T] res = vec();
+
+ for (option::t[T] o in v) {
+ alt (o) {
+ case (none[T]) { }
+ case (some[T](?t)) {
+ res += vec(t);
+ }
+ }
+ }
+
+ ret res;
+}
+
+// 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 = vec();
+ for (T elem in v) {
+ result += vec(elem);
+ }
+ ret result;
+}
+
+// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
--- /dev/null
+// FIXME: With recursive object types, we could implement binary methods like
+// union, intersection, and difference. At that point, we could write
+// an optimizing version of this module that produces a different obj
+// for the case where nbits <= 32.
+
+// FIXME: Almost all the functions in this module should be state fns, but the
+// effect system isn't currently working correctly.
+
+state type t = rec(vec[mutable uint] storage, uint nbits);
+
+// 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) {
+ elt = ~0u;
+ } else {
+ elt = 0u;
+ }
+
+ auto storage = _vec::init_elt_mut[uint](elt, nbits / uint_bits() + 1u);
+ ret rec(storage = storage, nbits = nbits);
+}
+
+fn process(&fn(uint, uint) -> uint op, &t v0, &t v1) -> bool {
+ auto len = _vec::len(v1.storage);
+
+ assert (_vec::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;
+ }
+ }
+
+ ret changed;
+}
+
+fn lor(uint w0, uint w1) -> uint {
+ ret w0 | w1;
+}
+
+fn union(&t v0, &t v1) -> bool {
+ auto sub = lor;
+ ret process(sub, v0, v1);
+}
+
+fn land(uint w0, uint w1) -> uint {
+ ret w0 & w1;
+}
+
+fn intersect(&t v0, &t v1) -> bool {
+ auto sub = land;
+ ret process(sub, v0, v1);
+}
+
+fn right(uint w0, uint w1) -> uint {
+ ret w1;
+}
+
+fn copy(&t v0, t v1) -> bool {
+ auto sub = right;
+ ret process(sub, v0, v1);
+}
+
+fn clone(t v) -> t {
+ auto storage = _vec::init_elt_mut[uint](0u, v.nbits / uint_bits() + 1u);
+ auto len = _vec::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 get(&t v, uint i) -> bool {
+ assert (i < v.nbits);
+
+ auto bits = uint_bits();
+
+ auto w = i / bits;
+ auto b = i % bits;
+ auto x = 1u & (v.storage.(w) >> b);
+ ret x == 1u;
+}
+
+fn equal(&t v0, &t v1) -> bool {
+ // FIXME: when we can break or return from inside an iterator loop,
+ // we can eliminate this painful while-loop
+ auto len = _vec::len(v1.storage);
+ auto 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, _vec::len(v.storage))) {
+ v.storage.(i) = 0u;
+ }
+}
+
+fn invert(&t v) {
+ for each (uint i in _uint::range(0u, _vec::len(v.storage))) {
+ v.storage.(i) = ~v.storage.(i);
+ }
+}
+
+/* v0 = v0 - v1 */
+fn difference(&t v0, &t v1) -> bool {
+ invert(v1);
+ auto b = intersect(v0, v1);
+ invert(v1);
+ ret b;
+}
+
+fn set(&t v, uint i, bool x) {
+ assert (i < v.nbits);
+
+ auto bits = uint_bits();
+
+ auto w = i / bits;
+ auto b = i % bits;
+ auto w0 = v.storage.(w);
+ auto flag = 1u << b;
+ if (x) {
+ v.storage.(w) = v.storage.(w) | flag;
+ } else {
+ v.storage.(w) = v.storage.(w) & ~flag;
+ }
+}
+
+/* true if all bits are 1 */
+fn is_true(&t v) -> bool {
+ for (uint i in to_vec(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_vec(v)) {
+ if (i == 1u) {
+ ret false;
+ }
+ }
+
+ ret true;
+}
+
+fn init_to_vec(t v, uint i) -> uint {
+ if (get(v, i)) {
+ ret 1u;
+ } else {
+ ret 0u;
+ }
+}
+
+fn to_vec(&t v) -> vec[uint] {
+ auto sub = bind init_to_vec(v, _);
+ ret _vec::init_fn[uint](sub, v.nbits);
+}
+
+fn to_str(&t v) -> str {
+ auto res = "";
+
+ for (uint i in bitv::to_vec(v)) {
+ if (i == 1u) {
+ res += "1";
+ }
+ else {
+ res += "0";
+ }
+ }
+
+ ret res;
+}
+
+// FIXME: can we just use structural equality on to_vec?
+fn eq_vec(&t v0, &vec[uint] v1) -> 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;
+ }
+ i = i + 1u;
+ }
+ ret true;
+}
+
+//
+// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
+//
--- /dev/null
+export rustrt;
+
+native "rust" mod rustrt {
+ fn rust_ptr_eq[T](@T a, @T b) -> int;
+}
+
+fn ptr_eq[T](@T a, @T b) -> bool { ret rustrt::rust_ptr_eq[T](a, b) != 0; }
+
--- /dev/null
+/**
+ * Unsafe debugging functions for inspecting values.
+ *
+ * Your RUST_LOG environment variable must contain "stdlib" for any debug
+ * logging.
+ */
+
+// FIXME: handle 64-bit case.
+const uint const_refcount = 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_vec[T](vec[T] v) {
+ _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_box[T](@T x) {
+ rustrt::debug_box[T](x);
+}
+
+fn debug_tag[T](&T x) {
+ rustrt::debug_tag[T](x);
+}
+
+/**
+ * `nmethods` is the number of methods we expect the object to have. The
+ * runtime will print this many words of the obj vtbl).
+ *
+ * `nbytes` is the number of bytes of body data we expect the object to have.
+ * The runtime will print this many bytes of the obj body. You probably want
+ * 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) {
+ rustrt::debug_obj[T](x, nmethods, nbytes);
+}
+
+fn debug_fn[T](&T x) {
+ rustrt::debug_fn[T](x);
+}
+
+fn ptr_cast[T, U](@T x) -> @U {
+ ret rustrt::debug_ptrcast[T, U](x);
+}
+
+fn trap(str s) {
+ rustrt::debug_trap(s);
+}
+
+// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
--- /dev/null
+/**
+ * A deque, for fun. Untested as of yet. Likely buggy.
+ */
+
+type t[T] = obj {
+ fn size() -> uint;
+
+ fn add_front(&T t);
+ fn add_back(&T t);
+
+ fn pop_front() -> T;
+ fn pop_back() -> T;
+
+ fn peek_front() -> T;
+ fn peek_back() -> T;
+
+ fn get(int i) -> T;
+};
+
+fn create[T]() -> t[T] {
+
+ type cell[T] = option::t[T];
+
+ let uint initial_capacity = 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, vec[cell[T]] elts) -> vec[cell[T]] {
+ assert (nelts == _vec::len[cell[T]](elts));
+
+ fn fill[T](uint i, uint nelts, uint lo,
+ vec[cell[T]] old) -> cell[T] {
+ if (i < nelts) {
+ ret old.((lo + i) % nelts);
+ } else {
+ ret option::none[T];
+ }
+ }
+
+ let uint nalloc = _uint::next_power_of_two(nelts + 1u);
+ let _vec::init_op[cell[T]] copy_op = bind fill[T](_, nelts, lo, elts);
+ ret _vec::init_fn[cell[T]](copy_op, nalloc);
+ }
+
+ fn get[T](vec[cell[T]] elts, uint i) -> T {
+ alt (elts.(i)) {
+ case (option::some[T](?t)) { ret t; }
+ case (_) { fail; }
+ }
+ fail; // FIXME: remove me when exhaustiveness checking works
+ }
+
+ obj deque[T](mutable uint nelts,
+ mutable uint lo,
+ mutable uint hi,
+ mutable vec[cell[T]] elts)
+ {
+ fn size() -> uint { ret nelts; }
+
+ fn add_front(&T t) {
+ let uint oldlo = lo;
+
+ if (lo == 0u) {
+ lo = _vec::len[cell[T]](elts) - 1u;
+ } else {
+ lo -= 1u;
+ }
+
+ if (lo == hi) {
+ elts = grow[T](nelts, oldlo, elts);
+ lo = _vec::len[cell[T]](elts) - 1u;
+ hi = nelts;
+ }
+
+ elts.(lo) = option::some[T](t);
+ nelts += 1u;
+ }
+
+ fn add_back(&T t) {
+ if (lo == hi && nelts != 0u) {
+ elts = grow[T](nelts, lo, elts);
+ lo = 0u;
+ hi = nelts;
+ }
+
+ elts.(hi) = option::some[T](t);
+ hi = (hi + 1u) % _vec::len[cell[T]](elts);
+ nelts += 1u;
+ }
+
+ /**
+ * We actually release (turn to none()) the T we're popping so
+ * that we don't keep anyone's refcount up unexpectedly.
+ */
+ fn pop_front() -> T {
+ let T t = get[T](elts, lo);
+ elts.(lo) = option::none[T];
+ lo = (lo + 1u) % _vec::len[cell[T]](elts);
+ nelts -= 1u;
+ ret t;
+ }
+
+ fn pop_back() -> T {
+ if (hi == 0u) {
+ hi = _vec::len[cell[T]](elts) - 1u;
+ } 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)) % _vec::len[cell[T]](elts);
+ ret get[T](elts, idx);
+ }
+
+ }
+ let vec[cell[T]] v = _vec::init_elt[cell[T]](option::none[T],
+ initial_capacity);
+
+ ret deque[T](0u, 0u, 0u, v);
+}
+
+// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
--- /dev/null
+// Simple Extensible Binary Markup Language (ebml) reader and writer on a
+// cursor model. See the specification here:
+// http://www.matroska.org/technical/specs/rfc/index.html
+
+import option::none;
+import option::some;
+
+type ebml_tag = rec(uint id, uint size);
+type ebml_state = rec(ebml_tag ebml_tag, uint tag_pos, uint data_pos);
+
+// 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);
+
+fn vint_at(vec[u8] data, uint start) -> tup(uint, uint) {
+ auto a = data.(start);
+ if (a & 0x80u8 != 0u8) { ret tup((a & 0x7fu8) as uint, start + 1u); }
+ if (a & 0x40u8 != 0u8) {
+ ret tup((((a & 0x3fu8) as uint) << 8u) | (data.(start + 1u) as uint),
+ start + 2u);
+ } else if (a & 0x20u8 != 0u8) {
+ ret tup((((a & 0x1fu8) as uint) << 16u) |
+ ((data.(start + 1u) as uint) << 8u) |
+ (data.(start + 2u) as uint), start + 3u);
+ } else if (a & 0x10u8 != 0u8) {
+ ret tup((((a & 0x0fu8) as uint) << 24u) |
+ ((data.(start + 1u) as uint) << 16u) |
+ ((data.(start + 2u) as uint) << 8u) |
+ (data.(start + 3u) as uint), 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 doc_at(vec[u8] data, uint start) -> doc {
+ auto elt_tag = vint_at(data, start);
+ auto elt_size = vint_at(data, elt_tag._1);
+ auto end = elt_size._1 + elt_size._0;
+ ret rec(data=data, start=elt_size._1, 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._1);
+ pos = elt_size._1 + elt_size._0;
+ if (elt_tag._0 == tg) {
+ ret some[doc](rec(data=d.data, start=elt_size._1, end=pos));
+ }
+ }
+ ret none[doc];
+}
+
+fn get_doc(doc d, uint tg) -> doc {
+ alt (maybe_get_doc(d, tg)) {
+ case (some[doc](?d)) {ret d;}
+ case (none[doc]) {
+ log_err "failed to find block with tag " + _uint::to_str(tg, 10u);
+ fail;
+ }
+ }
+}
+
+iter docs(doc d) -> tup(uint, 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._1);
+ pos = elt_size._1 + elt_size._0;
+ put tup(elt_tag._0, rec(data=d.data, start=elt_size._1, end=pos));
+ }
+}
+
+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._1);
+ pos = elt_size._1 + elt_size._0;
+ if (elt_tag._0 == tg) {
+ put rec(data=d.data, start=elt_size._1, 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;
+ assert (sz <= 4u);
+ auto val = 0u;
+ auto pos = start;
+ while (sz > 0u) {
+ sz -= 1u;
+ val += (data.(pos) as uint) << (sz * 8u);
+ pos += 1u;
+ }
+ ret val;
+}
+
+fn doc_as_uint(doc d) -> 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);
+
+fn write_sized_vint(&io::buf_writer w, uint n, uint size) {
+ let vec[u8] buf;
+ alt (size) {
+ case (1u) {
+ buf = vec(0x80u8 | (n as u8));
+ }
+ case (2u) {
+ buf = vec(0x40u8 | ((n >> 8u) as u8),
+ (n & 0xffu) as u8);
+ }
+ case (3u) {
+ buf = vec(0x20u8 | ((n >> 16u) as u8),
+ ((n >> 8u) & 0xffu) as u8,
+ (n & 0xffu) as u8);
+ }
+ case (4u) {
+ buf = vec(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;
+ }
+ }
+
+ 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; }
+ log_err "vint to write too big";
+ fail;
+}
+
+fn create_writer(&io::buf_writer w) -> writer {
+ let vec[uint] size_positions = vec();
+ ret rec(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) {
+ // Write the tag ID:
+ write_vint(w.writer, tag_id);
+
+ // Write a placeholder four-byte size.
+ w.size_positions += vec(w.writer.tell());
+ let vec[u8] zeroes = vec(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();
+ 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);
+}
+
+// TODO: optionally perform "relaxations" on end_tag to more efficiently
+// encode sizes; this is a fixed point iteration
--- /dev/null
+/* The 'fmt' extension is modeled on the posix printf system.
+ *
+ * A posix conversion ostensibly looks like this:
+ *
+ * %[parameter][flags][width][.precision][length]type
+ *
+ * Given the different numeric type bestiary we have, we omit the 'length'
+ * parameter and support slightly different conversions for 'type':
+ *
+ * %[parameter][flags][width][.precision]type
+ *
+ * we also only support translating-to-rust a tiny subset of the possible
+ * combinations at the moment.
+ */
+
+import option::none;
+import option::some;
+
+/*
+ * We have a CT (compile-time) module that parses format strings into a
+ * sequence of conversions. From those conversions AST fragments are built
+ * that call into properly-typed functions in the RT (run-time) module. Each
+ * of those run-time conversion functions accepts another conversion
+ * description that specifies how to format its output.
+ *
+ * The building of the AST is currently done in a module inside the compiler,
+ * but should migrate over here as the plugin interface is defined.
+ */
+
+// Functions used by the fmt extension at compile time
+mod CT {
+ tag signedness {
+ signed;
+ unsigned;
+ }
+
+ tag caseness {
+ case_upper;
+ case_lower;
+ }
+
+ tag ty {
+ ty_bool;
+ ty_str;
+ ty_char;
+ ty_int(signedness);
+ ty_bits;
+ ty_hex(caseness);
+ ty_octal;
+ // FIXME: More types
+ }
+
+ tag flag {
+ flag_left_justify;
+ flag_left_zero_pad;
+ flag_space_for_sign;
+ flag_sign_always;
+ flag_alternate;
+ }
+
+ tag count {
+ count_is(int);
+ count_is_param(int);
+ count_is_next_param;
+ count_implied;
+ }
+
+ // 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);
+
+ // A fragment of the output sequence
+ tag piece {
+ piece_string(str);
+ piece_conv(conv);
+ }
+
+ fn parse_fmt_string(str s) -> vec[piece] {
+ let vec[piece] pieces = vec();
+ auto lim = _str::byte_len(s);
+ auto buf = "";
+
+ fn flush_buf(str buf, &vec[piece] pieces) -> str {
+ if (_str::byte_len(buf) > 0u) {
+ auto piece = piece_string(buf);
+ pieces += vec(piece);
+ }
+ ret "";
+ }
+
+ auto i = 0u;
+ while (i < lim) {
+ auto curr = _str::substr(s, i, 1u);
+ if (_str::eq(curr, "%")) {
+ i += 1u;
+ if (i >= lim) {
+ log_err "unterminated conversion at end of string";
+ fail;
+ }
+ auto curr2 = _str::substr(s, i, 1u);
+ if (_str::eq(curr2, "%")) {
+ i += 1u;
+ } else {
+ buf = flush_buf(buf, pieces);
+ auto res = parse_conversion(s, i, lim);
+ pieces += vec(res._0);
+ i = res._1;
+ }
+ } else {
+ buf += curr;
+ i += 1u;
+ }
+ }
+ buf = flush_buf(buf, pieces);
+ ret pieces;
+ }
+
+ fn peek_num(str s, uint i, uint lim) -> option::t[tup(uint, uint)] {
+ if (i >= lim) {
+ ret none[tup(uint, uint)];
+ }
+
+ auto c = s.(i);
+ if (!('0' as u8 <= c && c <= '9' as u8)) {
+ ret option::none[tup(uint, uint)];
+ }
+
+ auto n = (c - ('0' as u8)) as uint;
+ alt (peek_num(s, i + 1u, lim)) {
+ case (none[tup(uint, uint)]) {
+ ret some[tup(uint, uint)](tup(n, i + 1u));
+ }
+ case (some[tup(uint, uint)](?next)) {
+ auto m = next._0;
+ auto j = next._1;
+ ret some[tup(uint, uint)](tup(n * 10u + m, j));
+ }
+ }
+
+ }
+
+ fn parse_conversion(str s, uint i, uint lim) -> tup(piece, uint) {
+ auto parm = parse_parameter(s, i, lim);
+ auto flags = parse_flags(s, parm._1, lim);
+ auto width = parse_count(s, flags._1, lim);
+ auto prec = parse_precision(s, width._1, lim);
+ auto ty = parse_type(s, prec._1, lim);
+ ret tup(piece_conv(rec(param = parm._0,
+ flags = flags._0,
+ width = width._0,
+ precision = prec._0,
+ ty = ty._0)),
+ ty._1);
+ }
+
+ fn parse_parameter(str s, uint i, uint lim) -> tup(option::t[int], uint) {
+ if (i >= lim) {
+ ret tup(none[int], i);
+ }
+
+ auto num = peek_num(s, i, lim);
+ alt (num) {
+ case (none[tup(uint, uint)]) {
+ ret tup(none[int], i);
+ }
+ case (some[tup(uint, uint)](?t)) {
+ auto n = t._0;
+ auto j = t._1;
+ if (j < lim && s.(j) == '$' as u8) {
+ ret tup(some[int](n as int), j + 1u);
+ }
+ else {
+ ret tup(none[int], i);
+ }
+ }
+ }
+ }
+
+ fn parse_flags(str s, uint i, uint lim) -> tup(vec[flag], uint) {
+ let vec[flag] noflags = vec();
+
+ if (i >= lim) {
+ ret tup(noflags, i);
+ }
+
+ fn more_(flag f, str s, uint i, uint lim) -> tup(vec[flag], uint) {
+ auto next = parse_flags(s, i + 1u, lim);
+ auto rest = next._0;
+ auto j = next._1;
+ let vec[flag] curr = vec(f);
+ ret tup(curr + rest, j);
+ }
+
+ auto more = bind more_(_, s, i, lim);
+
+ auto f = s.(i);
+ if (f == ('-' as u8)) {
+ ret more(flag_left_justify);
+ } else if (f == ('0' as u8)) {
+ ret more(flag_left_zero_pad);
+ } else if (f == (' ' as u8)) {
+ ret more(flag_space_for_sign);
+ } else if (f == ('+' as u8)) {
+ ret more(flag_sign_always);
+ } else if (f == ('#' as u8)) {
+ ret more(flag_alternate);
+ } else {
+ ret tup(noflags, i);
+ }
+ }
+
+ fn parse_count(str s, uint i, uint lim) -> tup(count, uint) {
+ if (i >= lim) {
+ ret tup(count_implied, i);
+ }
+
+ if (s.(i) == ('*' as u8)) {
+ auto param = parse_parameter(s, i + 1u, lim);
+ auto j = param._1;
+ alt (param._0) {
+ case (none[int]) {
+ ret tup(count_is_next_param, j);
+ }
+ case (some[int](?n)) {
+ ret tup(count_is_param(n), j);
+ }
+ }
+ } else {
+ auto num = peek_num(s, i, lim);
+ alt (num) {
+ case (none[tup(uint, uint)]) {
+ ret tup(count_implied, i);
+ }
+ case (some[tup(uint, uint)](?num)) {
+ ret tup(count_is(num._0 as int), num._1);
+ }
+ }
+ }
+ }
+
+ fn parse_precision(str s, uint i, uint lim) -> tup(count, uint) {
+ if (i >= lim) {
+ ret tup(count_implied, i);
+ }
+
+ if (s.(i) == '.' as u8) {
+ auto 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._0) {
+ case (count_implied) {
+ ret tup(count_is(0), count._1);
+ }
+ case (_) {
+ ret count;
+ }
+ }
+ } else {
+ ret tup(count_implied, i);
+ }
+ }
+
+ fn parse_type(str s, uint i, uint lim) -> tup(ty, uint) {
+ if (i >= lim) {
+ log_err "missing type in conversion";
+ fail;
+ }
+
+ auto t;
+ auto tstr = _str::substr(s, i, 1u);
+ if (_str::eq(tstr, "b")) {
+ t = ty_bool;
+ } else if (_str::eq(tstr, "s")) {
+ t = ty_str;
+ } else if (_str::eq(tstr, "c")) {
+ t = 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?
+ t = ty_int(signed);
+ } else if (_str::eq(tstr, "u")) {
+ t = ty_int(unsigned);
+ } else if (_str::eq(tstr, "x")) {
+ t = ty_hex(case_lower);
+ } else if (_str::eq(tstr, "X")) {
+ t = ty_hex(case_upper);
+ } else if (_str::eq(tstr, "t")) {
+ t = ty_bits;
+ } else if (_str::eq(tstr, "o")) {
+ t = ty_octal;
+ } else {
+ log_err "unknown type in conversion";
+ fail;
+ }
+
+ ret tup(t, i + 1u);
+ }
+}
+
+// Functions used by the fmt extension at runtime. For now there are a lot of
+// decisions made a runtime. If it proves worthwhile then some of these
+// conditions can be evaluated at compile-time. For now though it's cleaner to
+// implement it this way, I think.
+mod RT {
+
+ tag flag {
+ flag_left_justify;
+ flag_left_zero_pad;
+ flag_space_for_sign;
+ 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
+ flag_none;
+ }
+
+ tag count {
+ count_is(int);
+ count_implied;
+ }
+
+ tag ty {
+ ty_default;
+ ty_bits;
+ ty_hex_upper;
+ ty_hex_lower;
+ ty_octal;
+ }
+
+ // 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);
+
+ 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)) {
+ s = "+" + s;
+ } else if (have_flag(cv.flags, flag_space_for_sign)) {
+ s = " " + s;
+ }
+ }
+ ret pad(cv, s, pad_signed);
+ }
+
+ fn conv_uint(&conv cv, uint u) -> str {
+ auto prec = get_int_precision(cv);
+ auto res;
+ alt (cv.ty) {
+ case (ty_default) {
+ res = uint_to_str_prec(u, 10u, prec);
+ }
+ case (ty_hex_lower) {
+ res = uint_to_str_prec(u, 16u, prec);
+ }
+ case (ty_hex_upper) {
+ res = _str::to_upper(uint_to_str_prec(u, 16u, prec));
+ }
+ case (ty_bits) {
+ res = uint_to_str_prec(u, 2u, prec);
+ }
+ case (ty_octal) {
+ res = uint_to_str_prec(u, 8u, prec);
+ }
+ }
+ ret pad(cv, res, pad_unsigned);
+ }
+
+ fn conv_bool(&conv cv, bool b) -> str {
+ auto s;
+ if (b) {
+ s = "true";
+ } else {
+ s = "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 {
+ ret pad(cv, _str::from_char(c), pad_nozero);
+ }
+
+ fn conv_str(&conv cv, str s) -> str {
+ auto unpadded = s;
+ alt (cv.precision) {
+ case (count_implied) {
+ }
+ case (count_is(?max)) {
+ // For strings, precision is the maximum characters displayed
+ if (max as uint < _str::char_len(s)) {
+ // FIXME: substr works on bytes, not chars!
+ unpadded = _str::substr(s, 0u, max as uint);
+ }
+ }
+ }
+ 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 {
+ if (num < 0) {
+ ret "-" + uint_to_str_prec((-num) as uint, radix, prec);
+ } else {
+ ret uint_to_str_prec(num as uint, radix, prec);
+ }
+ }
+
+ // 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 {
+ auto s;
+
+ if (prec == 0u && num == 0u) {
+ s = "";
+ } else {
+ 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);
+ s = pad + s;
+ }
+ }
+
+ ret s;
+ }
+
+ fn get_int_precision(&conv cv) -> uint {
+ alt (cv.precision) {
+ case (count_is(?c)) {
+ ret c as uint;
+ }
+ case (count_implied) {
+ ret 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);
+ // FIXME: Using unsafe_from_bytes because rustboot
+ // can't figure out the is_utf8 predicate on from_bytes?
+ ret _str::unsafe_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
+ 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);
+ ret s + padstr;
+ }
+
+ auto might_zero_pad = false;
+ auto signed = false;
+
+ alt (mode) {
+ case (pad_nozero) {
+ // fallthrough
+ }
+ case (pad_signed) {
+ might_zero_pad = true;
+ signed = true;
+ }
+ case (pad_unsigned) {
+ might_zero_pad = true;
+ }
+ }
+
+ fn have_precision(&conv cv) -> bool {
+ alt (cv.precision) {
+ case (count_implied) {
+ ret false;
+ }
+ case (_) {
+ ret true;
+ }
+ }
+ }
+
+ auto 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);
+
+ // 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(vec(head));
+ auto bytelen = _str::byte_len(s);
+ auto 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;
+ }
+ }
+ ret false;
+ }
+}
+
+// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
--- /dev/null
+native "rust" mod rustrt {
+ fn rust_file_is_dir(str path) -> 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) {
+ i = _str::rindex(p, os_fs::alt_path_sep as u8);
+ if (i == -1) {
+ ret p;
+ }
+ }
+ ret _str::substr(p, 0u, i as uint);
+}
+
+fn connect(path pre, path post) -> path {
+ auto len = _str::byte_len(pre);
+ if (pre.(len - 1u) == (os_fs::path_sep as u8)) { // Trailing '/'?
+ ret pre + post;
+ }
+ ret pre + path_sep() + post;
+}
+
+fn file_is_dir(path p) -> bool {
+ ret rustrt::rust_file_is_dir(p) != 0;
+}
+
+fn list_dir(path p) -> vec[str] {
+ auto pl = _str::byte_len(p);
+ if (pl == 0u || p.(pl - 1u) as char != os_fs::path_sep) {
+ p += path_sep();
+ }
+ let vec[str] full_paths = vec();
+ for (str filename in os_fs::list_dir(p)) {
+ if (!_str::eq(filename, ".")) {if (!_str::eq(filename, "..")) {
+ _vec::push[str](full_paths, p + filename);
+ }}
+ }
+ ret full_paths;
+}
+
+
+// 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:
--- /dev/null
+fn getenv(str n) -> option::t[str] {
+ auto s = os::libc::getenv(_str::buf(n));
+ if ((s as int) == 0) {
+ ret option::none[str];
+ } else {
+ ret option::some[str](_str::str_from_cstr(s));
+ }
+}
+
--- /dev/null
+/* Simple getopt alternative. Construct a vector of options, either by using
+ * reqopt, optopt, and optflag or by building them from components yourself,
+ * and pass them to getopts, along with a vector of actual arguments (not
+ * including argv[0]). You'll either get a failure code back, or a match.
+ * You'll have to verify whether the amount of 'free' arguments in the match
+ * is what you expect. Use opt_* accessors (bottom of the file) to get
+ * argument values out of the match object.
+ */
+
+import option::some;
+import option::none;
+
+tag name { long(str); short(char); }
+tag hasarg { yes; no; maybe; }
+tag occur { req; optional; multi; }
+
+type opt = rec(name name, hasarg hasarg, occur occur);
+
+fn mkname(str nm) -> name {
+ if (_str::char_len(nm) == 1u) { ret short(_str::char_at(nm, 0u)); }
+ else { ret long(nm); }
+}
+fn reqopt(str name) -> opt {
+ ret rec(name=mkname(name), hasarg=yes, occur=req);
+}
+fn optopt(str name) -> opt {
+ ret rec(name=mkname(name), hasarg=yes, occur=optional);
+}
+fn optflag(str name) -> opt {
+ ret rec(name=mkname(name), hasarg=no, occur=optional);
+}
+fn optmulti(str name) -> opt {
+ ret rec(name=mkname(name), hasarg=yes, occur=multi);
+}
+
+tag optval {
+ val(str);
+ given;
+}
+
+type match = rec(vec[opt] opts, vec[mutable vec[optval]] vals, vec[str] free);
+
+fn is_arg(str arg) -> bool {
+ ret _str::byte_len(arg) > 1u && arg.(0) == '-' as u8;
+}
+fn name_str(name nm) -> str {
+ alt (nm) {
+ case (short(?ch)) {ret _str::from_char(ch);}
+ case (long(?s)) {ret s;}
+ }
+}
+
+// FIXME rustboot workaround
+fn name_eq(name a, name b) -> bool {
+ alt (a) {
+ case (long(?a)) {
+ alt (b) {
+ case (long(?b)) { ret _str::eq(a, b); }
+ case (_) { ret false; }
+ }
+ }
+ case (_) { if (a == b) { ret true; } else {ret false; } }
+ }
+}
+fn find_opt(vec[opt] opts, name nm) -> option::t[uint] {
+ auto i = 0u;
+ auto l = _vec::len[opt](opts);
+ while (i < l) {
+ if (name_eq(opts.(i).name, nm)) { ret some[uint](i); }
+ i += 1u;
+ }
+ ret none[uint];
+}
+
+tag fail_ {
+ argument_missing(str);
+ unrecognized_option(str);
+ option_missing(str);
+ option_duplicated(str);
+}
+
+fn fail_str(fail_ f) -> str {
+ alt (f) {
+ case (argument_missing(?nm)) {
+ ret "Argument to option '" + nm + "' missing.";
+ }
+ case (unrecognized_option(?nm)) {
+ ret "Unrecognized option: '" + nm + "'.";
+ }
+ case (option_missing(?nm)) {
+ ret "Required option '" + nm + "' missing.";
+ }
+ case (option_duplicated(?nm)) {
+ ret "option '" + nm + "' given more than once.";
+ }
+ }
+}
+
+tag result {
+ success(match);
+ failure(fail_);
+}
+
+fn getopts(vec[str] args, vec[opt] opts) -> result {
+ auto n_opts = _vec::len[opt](opts);
+ fn empty_(uint x) -> vec[optval]{ret _vec::empty[optval]();}
+ auto f = empty_;
+ auto vals = _vec::init_fn_mut[vec[optval]](f, n_opts);
+ let vec[str] free = vec();
+
+ auto l = _vec::len[str](args);
+ auto i = 0u;
+ while (i < l) {
+ auto cur = args.(i);
+ auto curlen = _str::byte_len(cur);
+ if (!is_arg(cur)) {
+ _vec::push[str](free, cur);
+ } else if (_str::eq(cur, "--")) {
+ free += _vec::slice[str](args, i + 1u, l);
+ 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) {
+ names = vec(long(tail));
+ } else {
+ names = vec(long(_str::slice(tail, 0u, eq as uint)));
+ i_arg = option::some[str]
+ (_str::slice(tail, (eq as uint) + 1u, curlen - 2u));
+ }
+ } else {
+ auto j = 1u;
+ names = vec();
+ while (j < curlen) {
+ auto range = _str::char_range_at(cur, j);
+ _vec::push[name](names, short(range._0));
+ j = range._1;
+ }
+ }
+ auto name_pos = 0u;
+ for (name nm in names) {
+ name_pos += 1u;
+ auto optid;
+ alt (find_opt(opts, nm)) {
+ case (some[uint](?id)) {optid = id;}
+ case (none[uint]) {
+ ret failure(unrecognized_option(name_str(nm)));
+ }
+ }
+ alt (opts.(optid).hasarg) {
+ case (no) {
+ _vec::push[optval](vals.(optid), given);
+ }
+ case (maybe) {
+ if (!option::is_none[str](i_arg)) {
+ _vec::push[optval](vals.(optid),
+ val(option::get[str](i_arg)));
+ } else if (name_pos < _vec::len[name](names) ||
+ i + 1u == l || is_arg(args.(i + 1u))) {
+ _vec::push[optval](vals.(optid), given);
+ } else {
+ i += 1u;
+ _vec::push[optval](vals.(optid), val(args.(i)));
+ }
+ }
+ case (yes) {
+ if (!option::is_none[str](i_arg)) {
+ _vec::push[optval](vals.(optid),
+ val(option::get[str](i_arg)));
+ } else if (i + 1u == l) {
+ ret failure(argument_missing(name_str(nm)));
+ } else {
+ i += 1u;
+ _vec::push[optval](vals.(optid), val(args.(i)));
+ }
+ }
+ }
+ }
+ }
+ i += 1u;
+ }
+
+ i = 0u;
+ while (i < n_opts) {
+ auto n = _vec::len[optval](vals.(i));
+ auto 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) {
+ ret failure(option_duplicated(name_str(opts.(i).name)));
+ }}
+ i += 1u;
+ }
+
+ ret success(rec(opts=opts, vals=vals, free=free));
+}
+
+fn opt_vals(match m, str nm) -> vec[optval] {
+ alt (find_opt(m.opts, mkname(nm))) {
+ case (some[uint](?id)) { ret m.vals.(id); }
+ case (none[uint]) {
+ log_err "No option '" + nm + "' defined.";
+ fail;
+ }
+ }
+}
+fn opt_val(match m, str nm) -> optval {
+ ret opt_vals(m, nm).(0);
+}
+fn opt_present(match m, str nm) -> bool {
+ ret _vec::len[optval](opt_vals(m, nm)) > 0u;
+}
+fn opt_str(match m, str nm) -> str {
+ alt (opt_val(m, nm)) {
+ case (val(?s)) { ret s; }
+ case (_) { fail; }
+ }
+}
+fn opt_strs(match m, str nm) -> vec[str] {
+ let vec[str] acc = vec();
+ for (optval v in opt_vals(m, nm)) {
+ alt (v) {
+ case (val(?s)) { _vec::push[str](acc, s); }
+ case (_) {}
+ }
+ }
+ ret acc;
+}
+fn opt_maybe_str(match m, str nm) -> option::t[str] {
+ auto vals = opt_vals(m, nm);
+ if (_vec::len[optval](vals) == 0u) { ret none[str]; }
+ alt (vals.(0)) {
+ case (val(?s)) { ret some[str](s); }
+ case (_) { ret none[str]; }
+ }
+}
+
+// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
--- /dev/null
+import os::libc;
+
+native "rust" mod rustrt {
+ fn rust_get_stdin() -> os::libc::FILE;
+ fn rust_get_stdout() -> os::libc::FILE;
+}
+
+// Reading
+
+// FIXME This is all buffered. We might need an unbuffered variant as well
+
+tag seek_style {seek_set; seek_end; seek_cur;}
+
+// The raw underlying reader class. All readers must implement this.
+type buf_reader =
+ state obj {
+ fn read(uint len) -> vec[u8];
+ fn read_byte() -> int;
+ fn unread_byte(int byte);
+ fn eof() -> bool;
+
+ // FIXME: Seekable really should be orthogonal. We will need
+ // inheritance.
+ fn seek(int offset, seek_style whence);
+ fn tell() -> uint;
+ };
+
+// Convenience methods for reading.
+type reader =
+ state obj {
+ // FIXME: This should inherit from buf_reader.
+ fn get_buf_reader() -> buf_reader;
+
+ fn read_byte() -> int;
+ fn unread_byte(int byte);
+ fn read_bytes(uint len) -> vec[u8];
+ fn read_char() -> char;
+ fn eof() -> bool;
+ fn read_line() -> str;
+ fn read_c_str() -> str;
+ fn read_le_uint(uint size) -> uint;
+ fn read_le_int(uint size) -> int;
+ fn read_be_uint(uint size) -> uint;
+ fn read_whole_stream() -> vec[u8];
+
+ fn seek(int offset, seek_style whence);
+ fn tell() -> uint; // FIXME: eventually u64
+ };
+
+fn convert_whence(seek_style whence) -> int {
+ alt (whence) {
+ case (seek_set) {ret 0;}
+ case (seek_cur) {ret 1;}
+ case (seek_end) {ret 2;}
+ }
+}
+
+state 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);
+ _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 eof() -> bool {
+ ret os::libc::feof(f) != 0;
+ }
+ fn seek(int offset, seek_style whence) {
+ 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); }
+ }
+}
+
+// FIXME: Convert this into pseudomethods on buf_reader.
+state obj new_reader(buf_reader rdr) {
+ 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 read_char() -> char {
+ auto 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);
+ assert (w > 0u);
+ if (w == 1u) {ret b0 as char;}
+ auto val = 0u;
+ while (w > 1u) {
+ w -= 1u;
+ auto next = rdr.read_byte();
+ assert (next > -1);
+ assert (next & 0xc0 == 0x80);
+ val <<= 6u;
+ val += (next & 0x3f) as uint;
+ }
+ // See _str::char_at
+ val += ((b0 << ((w + 1u) as u8)) as uint) << ((w - 1u) * 6u - w - 1u);
+ ret val as char;
+ }
+ fn eof() -> bool {
+ ret rdr.eof();
+ }
+ fn read_line() -> str {
+ let vec[u8] buf = vec();
+ // No break yet in rustc
+ auto go_on = true;
+ while (go_on) {
+ auto 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 = vec();
+ auto go_on = true;
+ while (go_on) {
+ auto ch = rdr.read_byte();
+ if (ch < 1) {go_on = false;}
+ else {_vec::push[u8](buf, ch as u8);}
+ }
+ ret _str::unsafe_from_bytes(buf);
+ }
+ // FIXME deal with eof?
+ fn read_le_uint(uint size) -> uint {
+ auto val = 0u;
+ auto 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) {
+ val += (rdr.read_byte() as uint) << pos;
+ pos += 8u;
+ size -= 1u;
+ }
+ ret val as int;
+ }
+ // FIXME deal with eof?
+ fn read_be_uint(uint size) -> uint {
+ auto val = 0u;
+ auto sz = size; // FIXME: trans::ml bug workaround
+ 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 = vec();
+ while (!rdr.eof()) {
+ buf += rdr.read(2048u);
+ }
+ ret buf;
+ }
+ fn seek(int offset, seek_style whence) {
+ ret rdr.seek(offset, whence);
+ }
+ fn tell() -> uint {
+ ret rdr.tell();
+ }
+}
+
+fn stdin() -> reader {
+ 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;
+ }
+ 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);
+}
+
+
+// Byte buffer readers
+
+// TODO: mutable? u8, but this fails with rustboot.
+type byte_buf = @rec(vec[u8] buf, mutable uint pos);
+
+state 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);
+ 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);
+ bbuf.pos += 1u;
+ ret b as int;
+ }
+
+ fn unread_byte(int byte) {
+ 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);
+ 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));
+}
+
+
+// Writing
+
+tag fileflag {
+ append;
+ create;
+ truncate;
+ none;
+}
+
+type buf_writer = state obj {
+ fn write(vec[u8] v);
+
+ // FIXME: Seekable really should be orthogonal. We will need inheritance.
+ fn seek(int offset, seek_style whence);
+ fn tell() -> uint; // FIXME: eventually u64
+};
+
+state 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";
+ }
+ }
+
+ fn seek(int offset, seek_style whence) {
+ 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);}
+ }
+}
+
+state 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) {
+ vbuf = _vec::buf_off[u8](v, count);
+ auto nout = os::libc::write(fd, vbuf, len);
+ if (nout < 0) {
+ log_err "error dumping buffer";
+ log_err sys::rustrt::last_os_error();
+ fail;
+ }
+ count += nout as uint;
+ }
+ }
+
+ fn seek(int offset, seek_style whence) {
+ 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);}
+ }
+}
+
+fn file_buf_writer(str path, vec[fileflag] flags) -> buf_writer {
+ let int fflags =
+ 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) {}
+ }
+ }
+
+ auto fd = os::libc::open(_str::buf(path),
+ fflags,
+ os::libc_constants::S_IRUSR() |
+ os::libc_constants::S_IWUSR());
+
+ if (fd < 0) {
+ log_err "error opening file for writing";
+ log_err sys::rustrt::last_os_error();
+ fail;
+ }
+ ret fd_buf_writer(fd, true);
+}
+
+type writer =
+ state 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 s);
+ fn write_char(char ch);
+ fn write_int(int n);
+ fn write_uint(uint n);
+ fn write_bytes(vec[u8] bytes);
+ fn write_le_uint(uint n, uint size);
+ fn write_le_int(int n, uint size);
+ fn write_be_uint(uint n, uint size);
+ };
+
+fn uint_to_le_bytes(uint n, uint size) -> vec[u8] {
+ let vec[u8] bytes = vec();
+ while (size > 0u) {
+ bytes += vec((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 = vec();
+ auto i = (size - 1u) as int;
+ while (i >= 0) {
+ bytes += vec(((n >> ((i * 8) as uint)) & 255u) as u8);
+ i -= 1;
+ }
+ ret bytes;
+}
+
+state obj new_writer(buf_writer out) {
+ fn get_buf_writer() -> buf_writer {
+ ret out;
+ }
+ fn write_str(str s) {
+ out.write(_str::bytes(s));
+ }
+ fn write_char(char ch) {
+ // 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) {
+ out.write(uint_to_le_bytes(n, size));
+ }
+ fn write_le_int(int n, uint size) {
+ out.write(uint_to_le_bytes(n as uint, size));
+ }
+ fn write_be_uint(uint n, uint size) {
+ 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 file_writer(str path, vec[fileflag] flags) -> 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;
+ }
+ ret FILE_writer(f, true);
+}
+
+// FIXME it would be great if this could be a const
+fn stdout() -> writer {
+ ret new_writer(fd_buf_writer(1, false));
+}
+
+type str_writer =
+ state obj {
+ fn get_writer() -> writer;
+ fn get_str() -> str;
+ };
+
+type mutable_byte_buf = @rec(mutable vec[mutable u8] buf, mutable uint pos);
+
+state obj byte_buf_writer(mutable_byte_buf buf) {
+ fn write(vec[u8] v) {
+ // Fast path.
+ 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);
+ 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)) {
+ buf.buf += vec(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);
+ buf.pos = seek_in_buf(offset, pos, len, whence);
+ }
+
+ fn tell() -> uint { ret buf.pos; }
+}
+
+fn string_writer() -> str_writer {
+ // FIXME: yikes, this is bad. Needs fixing of mutable syntax.
+ let vec[mutable u8] b = vec(mutable 0u8);
+ _vec::pop(b);
+
+ let mutable_byte_buf buf = @rec(mutable buf = b, mutable pos = 0u);
+ state obj str_writer_wrap(writer wr, mutable_byte_buf buf) {
+ fn get_writer() -> writer {ret wr;}
+ fn get_str() -> str {ret _str::unsafe_from_bytes(buf.buf);}
+ }
+ ret str_writer_wrap(new_writer(byte_buf_writer(buf)), buf);
+}
+
+
+// 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; }
+ }
+
+ if (bpos < 0) {
+ bpos = 0;
+ } else if (bpos > blen) {
+ bpos = blen;
+ }
+
+ ret bpos as uint;
+}
+
+
+//
+// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
+//
+++ /dev/null
-import Str.sbuf;
-import Vec.vbuf;
-
-// FIXME Somehow merge stuff duplicated here and macosx_os.rs. Made difficult
-// by https://github.com/graydon/rust/issues#issue/268
-
-native mod libc = "libc.so.6" {
-
- 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;
-
- 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;
-
- type dir;
- fn opendir(sbuf d) -> dir;
- fn closedir(dir d) -> 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(vbuf buf) -> int;
- fn waitpid(int pid, vbuf status, int options) -> int;
-}
-
-mod libc_constants {
- fn O_RDONLY() -> int { ret 0x0000; }
- fn O_WRONLY() -> int { ret 0x0001; }
- fn O_RDWR() -> int { ret 0x0002; }
- fn O_APPEND() -> int { ret 0x0400; }
- fn O_CREAT() -> int { ret 0x0040; }
- fn O_EXCL() -> int { ret 0x0080; }
- fn O_TRUNC() -> int { ret 0x0200; }
- fn O_TEXT() -> int { ret 0x0000; } // nonexistent in linux libc
- fn O_BINARY() -> int { ret 0x0000; } // nonexistent in linux libc
-
- fn S_IRUSR() -> uint { ret 0x0100u; }
- fn S_IWUSR() -> uint { ret 0x0080u; }
-}
-
-fn exec_suffix() -> str {
- ret "";
-}
-
-fn target_os() -> str {
- ret "linux";
-}
-
-fn dylib_filename(str base) -> str {
- ret "lib" + base + ".so";
-}
-
-fn pipe() -> tup(int, int) {
- let vec[mutable int] fds = vec(mutable 0, 0);
- assert (OS.libc.pipe(Vec.buf(fds)) == 0);
- ret tup(fds.(0), fds.(1));
-}
-
-fn fd_FILE(int fd) -> libc.FILE {
- ret libc.fdopen(fd, Str.buf("r"));
-}
-
-fn waitpid(int pid) -> int {
- let vec[mutable int] status = vec(mutable 0);
- assert (OS.libc.waitpid(pid, Vec.buf(status), 0) != -1);
- ret status.(0);
-}
-
-// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
--- /dev/null
+import _str::sbuf;
+import _vec::vbuf;
+
+// FIXME Somehow merge stuff duplicated here and macosx_os.rs. Made difficult
+// by https://github.com/graydon/rust/issues#issue/268
+
+native mod libc = "libc::so.6" {
+
+ 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;
+
+ 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;
+
+ type dir;
+ fn opendir(sbuf d) -> dir;
+ fn closedir(dir d) -> 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(vbuf buf) -> int;
+ fn waitpid(int pid, vbuf status, int options) -> int;
+}
+
+mod libc_constants {
+ fn O_RDONLY() -> int { ret 0x0000; }
+ fn O_WRONLY() -> int { ret 0x0001; }
+ fn O_RDWR() -> int { ret 0x0002; }
+ fn O_APPEND() -> int { ret 0x0400; }
+ fn O_CREAT() -> int { ret 0x0040; }
+ fn O_EXCL() -> int { ret 0x0080; }
+ fn O_TRUNC() -> int { ret 0x0200; }
+ fn O_TEXT() -> int { ret 0x0000; } // nonexistent in linux libc
+ fn O_BINARY() -> int { ret 0x0000; } // nonexistent in linux libc
+
+ fn S_IRUSR() -> uint { ret 0x0100u; }
+ fn S_IWUSR() -> uint { ret 0x0080u; }
+}
+
+fn exec_suffix() -> str {
+ ret "";
+}
+
+fn target_os() -> str {
+ ret "linux";
+}
+
+fn dylib_filename(str base) -> str {
+ ret "lib" + base + ".so";
+}
+
+fn pipe() -> tup(int, int) {
+ let vec[mutable int] fds = vec(mutable 0, 0);
+ assert (os::libc::pipe(_vec::buf(fds)) == 0);
+ ret tup(fds.(0), fds.(1));
+}
+
+fn fd_FILE(int fd) -> libc::FILE {
+ ret libc::fdopen(fd, _str::buf("r"));
+}
+
+fn waitpid(int pid) -> int {
+ let vec[mutable int] status = vec(mutable 0);
+ assert (os::libc::waitpid(pid, _vec::buf(status), 0) != -1);
+ ret status.(0);
+}
+
+// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
--- /dev/null
+import option::some;
+import option::none;
+
+// FIXME: It would probably be more appealing to define this as
+// type list[T] = rec(T hd, option[@list[T]] tl), but at the moment
+// our recursion rules do not permit that.
+
+tag list[T] {
+ cons(T, @list[T]);
+ nil;
+}
+
+fn foldl[T,U](&list[T] ls, &U u, fn(&T t, &U u) -> U f) -> U {
+ alt(ls) {
+ case (cons[T](?hd, ?tl)) {
+ auto u_ = f(hd, u);
+ // FIXME: should use 'be' here, not 'ret'. But parametric
+ // tail calls currently don't work.
+ ret foldl[T,U](*tl, u_, f);
+ }
+ case (nil[T]) {
+ ret u;
+ }
+ }
+
+ fail; // TODO: remove me when exhaustiveness checking works
+}
+
+fn find[T,U](&list[T] ls,
+ (fn(&T) -> option::t[U]) f) -> option::t[U] {
+ alt(ls) {
+ case (cons[T](?hd, ?tl)) {
+ alt (f(hd)) {
+ case (none[U]) {
+ // FIXME: should use 'be' here, not 'ret'. But parametric tail
+ // calls currently don't work.
+ ret find[T,U](*tl, f);
+ }
+ case (some[U](?res)) {
+ ret some[U](res);
+ }
+ }
+ }
+ case (nil[T]) {
+ ret none[U];
+ }
+ }
+
+ fail; // TODO: remove me when exhaustiveness checking works
+}
+
+fn length[T](&list[T] ls) -> uint {
+ fn count[T](&T t, &uint u) -> 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[T](_, ?tl)) {ret *tl;}
+ }
+}
+fn car[T](&list[T] ls) -> T {
+ alt (ls) {
+ case (cons[T](?hd, _)) {ret hd;}
+ }
+}
+
+// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
+++ /dev/null
-import Str.sbuf;
-import Vec.vbuf;
-
-native mod libc = "libc.dylib" {
-
- 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;
-
- 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;
-
- type dir;
- fn opendir(sbuf d) -> dir;
- fn closedir(dir d) -> 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(vbuf buf) -> int;
- fn waitpid(int pid, vbuf status, int options) -> int;
-}
-
-mod libc_constants {
- fn O_RDONLY() -> int { ret 0x0000; }
- fn O_WRONLY() -> int { ret 0x0001; }
- fn O_RDWR() -> int { ret 0x0002; }
- fn O_APPEND() -> int { ret 0x0008; }
- fn O_CREAT() -> int { ret 0x0200; }
- fn O_EXCL() -> int { ret 0x0800; }
- fn O_TRUNC() -> int { ret 0x0400; }
- fn O_TEXT() -> int { ret 0x0000; } // nonexistent in darwin libc
- fn O_BINARY() -> int { ret 0x0000; } // nonexistent in darwin libc
-
- fn S_IRUSR() -> uint { ret 0x0400u; }
- fn S_IWUSR() -> uint { ret 0x0200u; }
-}
-
-fn exec_suffix() -> str {
- ret "";
-}
-
-fn target_os() -> str {
- ret "macos";
-}
-
-fn dylib_filename(str base) -> str {
- ret "lib" + base + ".dylib";
-}
-
-fn pipe() -> tup(int, int) {
- let vec[mutable int] fds = vec(mutable 0, 0);
- assert (OS.libc.pipe(Vec.buf(fds)) == 0);
- ret tup(fds.(0), fds.(1));
-}
-
-fn fd_FILE(int fd) -> libc.FILE {
- ret libc.fdopen(fd, Str.buf("r"));
-}
-
-fn waitpid(int pid) -> int {
- let vec[mutable int] status = vec(mutable 0);
- assert (OS.libc.waitpid(pid, Vec.buf(status), 0) != -1);
- ret status.(0);
-}
-
-// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
--- /dev/null
+import _str::sbuf;
+import _vec::vbuf;
+
+native mod libc = "libc::dylib" {
+
+ 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;
+
+ 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;
+
+ type dir;
+ fn opendir(sbuf d) -> dir;
+ fn closedir(dir d) -> 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(vbuf buf) -> int;
+ fn waitpid(int pid, vbuf status, int options) -> int;
+}
+
+mod libc_constants {
+ fn O_RDONLY() -> int { ret 0x0000; }
+ fn O_WRONLY() -> int { ret 0x0001; }
+ fn O_RDWR() -> int { ret 0x0002; }
+ fn O_APPEND() -> int { ret 0x0008; }
+ fn O_CREAT() -> int { ret 0x0200; }
+ fn O_EXCL() -> int { ret 0x0800; }
+ fn O_TRUNC() -> int { ret 0x0400; }
+ fn O_TEXT() -> int { ret 0x0000; } // nonexistent in darwin libc
+ fn O_BINARY() -> int { ret 0x0000; } // nonexistent in darwin libc
+
+ fn S_IRUSR() -> uint { ret 0x0400u; }
+ fn S_IWUSR() -> uint { ret 0x0200u; }
+}
+
+fn exec_suffix() -> str {
+ ret "";
+}
+
+fn target_os() -> str {
+ ret "macos";
+}
+
+fn dylib_filename(str base) -> str {
+ ret "lib" + base + ".dylib";
+}
+
+fn pipe() -> tup(int, int) {
+ let vec[mutable int] fds = vec(mutable 0, 0);
+ assert (os::libc::pipe(_vec::buf(fds)) == 0);
+ ret tup(fds.(0), fds.(1));
+}
+
+fn fd_FILE(int fd) -> libc::FILE {
+ ret libc::fdopen(fd, _str::buf("r"));
+}
+
+fn waitpid(int pid) -> int {
+ let vec[mutable int] status = vec(mutable 0);
+ assert (os::libc::waitpid(pid, _vec::buf(status), 0) != -1);
+ ret status.(0);
+}
+
+// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
--- /dev/null
+/**
+ * At the moment, this is a partial hashmap implementation, not yet fit for
+ * use, but useful as a stress test for rustboot.
+ */
+
+type hashfn[K] = fn(&K) -> uint;
+type eqfn[K] = fn(&K, &K) -> bool;
+
+state type hashmap[K, V] = state obj {
+ fn size() -> uint;
+ fn insert(&K key, &V val) -> bool;
+ fn contains_key(&K key) -> bool;
+ fn get(&K key) -> V;
+ fn find(&K key) -> option::t[V];
+ fn remove(&K key) -> option::t[V];
+ fn rehash();
+ iter items() -> @tup(K,V);
+};
+
+fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
+
+ let uint initial_capacity = 32u; // 2^5
+ let util::rational load_factor = rec(num=3, den=4);
+
+ tag bucket[K, V] {
+ nil;
+ deleted;
+ some(K, V);
+ }
+
+ fn make_buckets[K, V](uint nbkts) -> vec[mutable bucket[K, V]] {
+ ret _vec::init_elt_mut[bucket[K, V]](nil[K, V], nbkts);
+ }
+
+ // Derive two hash functions from the one given by taking the upper
+ // half and lower half of the uint bits. Our bucket probing
+ // sequence is then defined by
+ //
+ // hash(key, i) := hashl(key) * i + hashr(key) for i = 0, 1, 2, ...
+ //
+ // Tearing the hash function apart this way is kosher in practice
+ // as, assuming 32-bit uints, the table would have to be at 2^32
+ // buckets before the resulting pair of hash functions no longer
+ // probes all buckets for a fixed key. Note that hashl is made to
+ // output odd numbers (hence coprime to the number of nbkts, which
+ // 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 {
+ ret (hashl(h, nbkts) * i + hashr(h, nbkts)) % nbkts;
+ }
+
+ /**
+ * We attempt to never call this with a full table. If we do, it
+ * will fail.
+ */
+ fn insert_common[K, V](&hashfn[K] hasher,
+ &eqfn[K] eqer,
+ vec[mutable bucket[K, V]] 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, V](?k, _)) {
+ if (eqer(key, k)) {
+ bkts.(j) = some[K, V](k, val);
+ ret false;
+ }
+ i += 1u;
+ }
+ case (_) {
+ bkts.(j) = some[K, V](key, val);
+ ret true;
+ }
+ }
+ }
+ fail; // full table
+ }
+
+ fn find_common[K, V](&hashfn[K] hasher,
+ &eqfn[K] eqer,
+ vec[mutable bucket[K, V]] 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](?k, ?v)) {
+ if (eqer(key, k)) {
+ ret option::some[V](v);
+ }
+ }
+ case (nil[K, V]) {
+ ret option::none[V];
+ }
+ case (deleted[K, V]) { }
+ }
+ i += 1u;
+ }
+ ret option::none[V];
+ }
+
+
+ fn rehash[K, V](&hashfn[K] hasher,
+ &eqfn[K] eqer,
+ vec[mutable bucket[K, V]] oldbkts, uint noldbkts,
+ vec[mutable bucket[K, V]] newbkts, uint nnewbkts)
+ {
+ for (bucket[K, V] b in oldbkts) {
+ alt (b) {
+ case (some[K, V](?k, ?v)) {
+ insert_common[K, V](hasher, eqer, newbkts,
+ nnewbkts, k, v);
+ }
+ case (_) { }
+ }
+ }
+ }
+
+ state obj hashmap[K, V](hashfn[K] hasher,
+ eqfn[K] eqer,
+ mutable vec[mutable bucket[K, V]] bkts,
+ mutable uint nbkts,
+ mutable uint nelts,
+ util::rational lf)
+ {
+ 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);
+ let vec[mutable bucket[K, V]] 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)) {
+ nelts += 1u;
+ ret true;
+ }
+ ret false;
+ }
+
+ fn contains_key(&K key) -> bool {
+ alt (find_common[K, V](hasher, eqer, bkts, nbkts, key)) {
+ case (option::some[V](_)) { ret true; }
+ case (_) { ret false; }
+ }
+ fail; // FIXME: remove me when exhaustiveness checking works
+ }
+
+ fn get(&K key) -> V {
+ alt (find_common[K, V](hasher, eqer, bkts, nbkts, key)) {
+ case (option::some[V](?val)) { ret val; }
+ case (_) { fail; }
+ }
+ fail; // FIXME: remove me when exhaustiveness checking works
+ }
+
+ fn find(&K key) -> option::t[V] {
+ // FIXME: should be 'be' but parametric tail-calls don't
+ // work at the moment.
+ ret 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](?k, ?v)) {
+ if (eqer(key, k)) {
+ bkts.(j) = deleted[K, V];
+ nelts -= 1u;
+ ret option::some[V](v);
+ }
+ }
+ case (deleted[K, V]) { }
+ case (nil[K, V]) {
+ ret option::none[V];
+ }
+ }
+ i += 1u;
+ }
+ ret option::none[V];
+ }
+
+ fn rehash() {
+ let vec[mutable bucket[K, V]] newbkts =
+ make_buckets[K, V](nbkts);
+ rehash[K, V](hasher, eqer, bkts, nbkts, newbkts, nbkts);
+ bkts = newbkts;
+ }
+
+ iter items() -> @tup(K,V) {
+ for (bucket[K,V] b in bkts) {
+ alt (b) {
+ case(some[K,V](?k,?v)) {
+ put @tup(k,v);
+ }
+ case (_) { }
+ }
+ }
+ }
+ }
+
+ let vec[mutable bucket[K, V]] bkts =
+ make_buckets[K, V](initial_capacity);
+
+ ret hashmap[K, V](hasher, eqer, bkts, initial_capacity, 0u, load_factor);
+}
+
+
+// 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:
--- /dev/null
+// lib/option::rs
+
+tag t[T] {
+ none;
+ some(T);
+}
+
+type operator[T, U] = fn(&T) -> U;
+
+fn get[T](&t[T] opt) -> T {
+ alt (opt) {
+ case (some[T](?x)) {
+ ret x;
+ }
+ case (none[T]) {
+ fail;
+ }
+ }
+ fail; // FIXME: remove me when exhaustiveness checking works
+}
+
+fn map[T, U](&operator[T, U] f, &t[T] opt) -> t[U] {
+ alt (opt) {
+ case (some[T](?x)) {
+ ret some[U](f(x));
+ }
+ case (none[T]) {
+ ret none[U];
+ }
+ }
+ fail; // FIXME: remove me when exhaustiveness checking works
+}
+
+fn is_none[T](&t[T] opt) -> bool {
+ alt (opt) {
+ case (none[T]) { ret true; }
+ case (some[T](_)) { ret false; }
+ }
+}
+
+fn from_maybe[T](&T def, &t[T] opt) -> T {
+ auto 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 {
+ alt (opt) {
+ case (none[T]) { ret def; }
+ case (some[T](?t)) { ret f(t); }
+ }
+}
+// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
+
+++ /dev/null
-native "rust" mod rustrt {
- fn rust_dirent_filename(OS.libc.dirent ent) -> str;
-}
-
-fn list_dir(str path) -> vec[str] {
- // TODO ensure this is always closed
- auto dir = OS.libc.opendir(Str.buf(path));
- assert (dir as uint != 0u);
- let vec[str] result = vec();
- while (true) {
- auto ent = OS.libc.readdir(dir);
- if (ent as int == 0) {
- OS.libc.closedir(dir);
- ret result;
- }
- Vec.push[str](result, rustrt.rust_dirent_filename(ent));
- }
- OS.libc.closedir(dir);
- ret result;
-}
-
-const char path_sep = '/';
-const char alt_path_sep = '/';
-
-// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
--- /dev/null
+native "rust" mod rustrt {
+ fn rust_dirent_filename(os::libc::dirent ent) -> str;
+}
+
+fn list_dir(str path) -> vec[str] {
+ // TODO ensure this is always closed
+ auto dir = os::libc::opendir(_str::buf(path));
+ assert (dir as uint != 0u);
+ let vec[str] result = vec();
+ while (true) {
+ auto ent = os::libc::readdir(dir);
+ if (ent as int == 0) {
+ os::libc::closedir(dir);
+ ret result;
+ }
+ _vec::push[str](result, rustrt::rust_dirent_filename(ent));
+ }
+ os::libc::closedir(dir);
+ ret result;
+}
+
+const char path_sep = '/';
+const char alt_path_sep = '/';
+
+// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
--- /dev/null
+/**
+ * Bindings the runtime's random number generator (ISAAC).
+ */
+
+native "rust" mod rustrt {
+ type rctx;
+ fn rand_new() -> rctx;
+ fn rand_next(rctx c) -> u32;
+ fn rand_free(rctx c);
+}
+
+type rng = obj { fn next() -> u32; };
+
+fn mk_rng() -> rng {
+ obj rt_rng(rustrt::rctx c) {
+ fn next() -> u32 {
+ ret rustrt::rand_next(c);
+ }
+ drop {
+ rustrt::rand_free(c);
+ }
+ }
+
+ ret rt_rng(rustrt::rand_new());
+}
+
+// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
--- /dev/null
+import _str::sbuf;
+import _vec::vbuf;
+
+native "rust" mod rustrt {
+ fn rust_run_program(vbuf argv, int in_fd, int out_fd, int err_fd) -> int;
+}
+
+fn argvec(str prog, vec[str] args) -> vec[sbuf] {
+ auto argptrs = vec(_str::buf(prog));
+ for (str arg in args) {
+ _vec::push[sbuf](argptrs, _str::buf(arg));
+ }
+ _vec::push[sbuf](argptrs, 0 as sbuf);
+ ret argptrs;
+}
+
+fn run_program(str prog, vec[str] args) -> int {
+ auto pid = rustrt::rust_run_program(_vec::buf[sbuf](argvec(prog, args)),
+ 0, 0, 0);
+ ret os::waitpid(pid);
+}
+
+type program =
+ state obj {
+ fn get_id() -> int;
+ fn input() -> io::writer;
+ fn output() -> io::reader;
+ fn close_input();
+ fn finish() -> int;
+ };
+
+fn start_program(str prog, vec[str] args) -> @program {
+ auto pipe_input = os::pipe();
+ auto pipe_output = os::pipe();
+ auto pid = rustrt::rust_run_program
+ (_vec::buf[sbuf](argvec(prog, args)),
+ pipe_input._0, pipe_output._1, 0);
+ if (pid == -1) {fail;}
+ os::libc::close(pipe_input._0);
+ os::libc::close(pipe_output._1);
+
+ state obj new_program(int pid,
+ int in_fd,
+ os::libc::FILE out_file,
+ mutable bool finished) {
+ fn get_id() -> int {ret pid;}
+ fn input() -> io::writer {
+ ret io::new_writer(io::fd_buf_writer(in_fd, false));
+ }
+ fn output() -> io::reader {
+ ret io::new_reader(io::FILE_buf_reader(out_file, false));
+ }
+ fn close_input() {
+ os::libc::close(in_fd);
+ }
+ fn finish() -> int {
+ if (finished) {ret 0;}
+ finished = true;
+ os::libc::close(in_fd);
+ ret os::waitpid(pid);
+ }
+ drop {
+ if (!finished) {
+ os::libc::close(in_fd);
+ os::waitpid(pid);
+ }
+ os::libc::fclose(out_file);
+ }
+ }
+ ret @new_program(pid, pipe_input._1,
+ os::fd_FILE(pipe_output._0),
+ false);
+}
+
+fn program_output(str prog, vec[str] args)
+ -> rec(int status, str out) {
+ auto pr = start_program(prog, args);
+ pr.close_input();
+ auto out = pr.output();
+ auto buf = "";
+ while (!out.eof()) {
+ auto bytes = out.read_bytes(4096u);
+ buf += _str::unsafe_from_bytes(bytes);
+ }
+ ret rec(status=pr.finish(), out=buf);
+}
+
+
+// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
--- /dev/null
+/*
+ * A SHA-1 implementation derived from Paul E. Jones's reference
+ * implementation, which is written for clarity, not speed. At some
+ * point this will want to be rewritten.
+ */
+
+export sha1;
+export mk_sha1;
+
+state type sha1 = state obj {
+ // Provide message input as bytes
+ fn input(&vec[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];
+
+ // 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();
+};
+
+// Some unexported constants
+const uint digest_buf_len = 5;
+const uint msg_block_len = 64;
+const uint work_buf_len = 80;
+
+const u32 k0 = 0x5A827999u32;
+const u32 k1 = 0x6ED9EBA1u32;
+const u32 k2 = 0x8F1BBCDCu32;
+const u32 k3 = 0xCA62C1D6u32;
+
+// Builds a sha1 object
+fn mk_sha1() -> sha1 {
+
+ state type sha1state = rec(vec[mutable u32] h,
+ mutable u32 len_low,
+ mutable u32 len_high,
+ vec[mutable u8] msg_block,
+ mutable uint msg_block_idx,
+ mutable bool computed,
+ vec[mutable u32] work_buf);
+
+ fn add_input(&sha1state st, &vec[u8] msg) {
+ // FIXME: Should be typestate precondition
+ assert (!st.computed);
+
+ for (u8 element in msg) {
+ st.msg_block.(st.msg_block_idx) = element;
+ st.msg_block_idx += 1u;
+
+ st.len_low += 8u32;
+ if (st.len_low == 0u32) {
+ st.len_high += 1u32;
+ if (st.len_high == 0u32) {
+ // FIXME: Need better failure mode
+ fail;
+ }
+ }
+
+ if (st.msg_block_idx == msg_block_len) {
+ process_msg_block(st);
+ }
+ }
+ }
+
+ fn process_msg_block(&sha1state st) {
+
+ // FIXME: Make precondition
+ assert (_vec::len(st.h) == digest_buf_len);
+ assert (_vec::len(st.work_buf) == work_buf_len);
+
+ let int t; // Loop counter
+ auto w = st.work_buf;
+
+ // Initialize the first 16 words of the vector w
+ t = 0;
+ while (t < 16) {
+ auto 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);
+ tmp = tmp | (st.msg_block.(t * 4 + 3) as u32);
+ w.(t) = tmp;
+ t += 1;
+ }
+
+ // Initialize the rest of vector w
+ while (t < 80) {
+ auto 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;
+
+ t = 0;
+ while (t < 20) {
+ temp = circular_shift(5u32, a)
+ + ((b & c) | ((~b) & d)) + e + w.(t) + k0;
+ e = d;
+ d = c;
+ c = circular_shift(30u32, b);
+ b = a;
+ a = temp;
+ t += 1;
+ }
+
+ while (t < 40) {
+ temp = circular_shift(5u32, a)
+ + (b ^ c ^ d) + e + w.(t) + k1;
+ e = d;
+ d = c;
+ c = circular_shift(30u32, b);
+ b = a;
+ a = temp;
+ t += 1;
+ }
+
+ while (t < 60) {
+ temp = circular_shift(5u32, a)
+ + ((b & c) | (b & d) | (c & d)) + e + w.(t) + k2;
+ e = d;
+ d = c;
+ c = circular_shift(30u32, b);
+ b = a;
+ a = temp;
+ t += 1;
+ }
+
+ while (t < 80) {
+ temp = circular_shift(5u32, a)
+ + (b ^ c ^ d) + e + w.(t) + k3;
+ e = d;
+ d = c;
+ c = circular_shift(30u32, b);
+ b = a;
+ a = temp;
+ t += 1;
+ }
+
+ st.h.(0) = st.h.(0) + a;
+ st.h.(1) = st.h.(1) + b;
+ st.h.(2) = st.h.(2) + c;
+ st.h.(3) = st.h.(3) + d;
+ st.h.(4) = st.h.(4) + e;
+
+ st.msg_block_idx = 0u;
+ }
+
+ fn circular_shift(u32 bits, u32 word) -> u32 {
+ // FIXME: This is a workaround for a rustboot
+ // "unrecognized quads" codegen bug
+ auto bits_hack = bits;
+ ret (word << bits_hack) | (word >> (32u32 - bits));
+ }
+
+ fn mk_result(&sha1state st) -> vec[u8] {
+ if (!st.computed) {
+ pad_msg(st);
+ st.computed = true;
+ }
+
+ let vec[u8] res = vec();
+ 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);
+ res += vec(a,b,c,d);
+ }
+ ret res;
+ }
+
+ /*
+ * According to the standard, the message must be padded to an even
+ * 512 bits. The first padding bit must be a '1'. The last 64 bits
+ * represent the length of the original message. All bits in between
+ * should be 0. This function will pad the message according to those
+ * rules by filling the msg_block vector accordingly. It will also
+ * call process_msg_block() appropriately. When it returns, it
+ * can be assumed that the message digest has been computed.
+ */
+ fn pad_msg(&sha1state st) {
+ // FIXME: Should be a precondition
+ assert (_vec::len(st.msg_block) == msg_block_len);
+
+ /*
+ * Check to see if the current message block is too small to hold
+ * the initial padding bits and length. If so, we will pad the
+ * block, process it, and then continue padding into a second block.
+ */
+ 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) {
+ st.msg_block.(st.msg_block_idx) = 0u8;
+ st.msg_block_idx += 1u;
+ }
+
+ process_msg_block(st);
+ } else {
+ st.msg_block.(st.msg_block_idx) = 0x80u8;
+ st.msg_block_idx += 1u;
+ }
+
+ while (st.msg_block_idx < 56u) {
+ st.msg_block.(st.msg_block_idx) = 0u8;
+ st.msg_block_idx += 1u;
+ }
+
+ // Store the message length as the last 8 octets
+ st.msg_block.(56) = (st.len_high >> 24u32) & 0xFFu32 as u8;
+ st.msg_block.(57) = (st.len_high >> 16u32) & 0xFFu32 as u8;
+ st.msg_block.(58) = (st.len_high >> 8u32) & 0xFFu32 as u8;
+ st.msg_block.(59) = st.len_high & 0xFFu32 as u8;
+ st.msg_block.(60) = (st.len_low >> 24u32) & 0xFFu32 as u8;
+ st.msg_block.(61) = (st.len_low >> 16u32) & 0xFFu32 as u8;
+ st.msg_block.(62) = (st.len_low >> 8u32) & 0xFFu32 as u8;
+ st.msg_block.(63) = st.len_low & 0xFFu32 as u8;
+
+ process_msg_block(st);
+ }
+
+ state obj sha1(sha1state st) {
+
+ fn reset() {
+ // FIXME: Should be typestate precondition
+ assert (_vec::len(st.h) == digest_buf_len);
+
+ st.len_low = 0u32;
+ st.len_high = 0u32;
+ st.msg_block_idx = 0u;
+
+ st.h.(0) = 0x67452301u32;
+ st.h.(1) = 0xEFCDAB89u32;
+ st.h.(2) = 0x98BADCFEu32;
+ st.h.(3) = 0x10325476u32;
+ st.h.(4) = 0xC3D2E1F0u32;
+
+ st.computed = false;
+ }
+
+ fn input(&vec[u8] msg) {
+ add_input(st, msg);
+ }
+
+ fn input_str(&str msg) {
+ add_input(st, _str::bytes(msg));
+ }
+
+ fn result() -> vec[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);
+ }
+ ret s;
+ }
+ }
+
+ auto st = rec(h = _vec::init_elt_mut[u32](0u32, digest_buf_len),
+ mutable len_low = 0u32,
+ mutable len_high = 0u32,
+ msg_block = _vec::init_elt_mut[u8](0u8, msg_block_len),
+ mutable msg_block_idx = 0u,
+ mutable computed = false,
+ work_buf = _vec::init_elt_mut[u32](0u32, work_buf_len));
+ auto sh = sha1(st);
+ sh.reset();
+ ret sh;
+}
+
+// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
--- /dev/null
+import _vec::len;
+import _vec::slice;
+
+type lteq[T] = fn(&T a, &T b) -> 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] res = vec();
+ 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))) {
+ res += vec(a.(a_ix));
+ a_ix += 1u;
+ } else {
+ res += vec(b.(b_ix));
+ b_ix += 1u;
+ }
+ }
+ res += slice[T](a, a_ix, a_len);
+ res += slice[T](b, b_ix, b_len);
+ ret res;
+ }
+
+ 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);
+ 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);
+ 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 {
+
+ fn compare[T](lteq[T] compare_func, vec[mutable T]arr,
+ uint arr_idx, &T arr_value) -> bool {
+
+ ret compare_func(arr.(arr_idx),arr_value);
+ }
+
+ auto pivot_value = arr.(pivot);
+ swap[T](arr, pivot, right);
+ let uint storage_index = left;
+ let uint i = left;
+ while (i<right) {
+ if (compare[T](compare_func, arr, i, pivot_value)) {
+ swap[T](arr, i, storage_index);
+ storage_index += 1u;
+ }
+ i += 1u;
+ }
+ swap[T](arr, storage_index, right);
+ 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) {
+ ret;
+ }
+ qsort[T](compare_func, arr, left, new_pivot - 1u);
+ qsort[T](compare_func, arr, new_pivot + 1u, right);
+ }
+}
+
+fn quick_sort[T](lteq[T] compare_func, vec[mutable T] arr) {
+
+ if (len[T](arr) == 0u) {
+ ret;
+ }
+ qsort[T](compare_func, arr, 0u, (len[T](arr)) - 1u);
+}
+
+// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
// Built-in types support modules.
-mod Int;
-mod UInt;
-mod U8;
-mod Vec;
-mod Str;
+mod _int;
+mod _uint;
+mod _u8;
+mod _vec;
+mod _str;
-// General IO and system-services modules.
+// General io and system-services modules.
-mod IO;
-mod Sys;
-mod Task;
+mod io;
+mod sys;
+mod _task;
// Utility modules.
-mod Option;
-mod Util;
+mod option;
+mod util;
// Authorize various rule-bendings.
-auth IO = unsafe;
-auth FS = unsafe;
-auth OS_FS = unsafe;
-auth Run = unsafe;
-auth Str = unsafe;
-auth Vec = unsafe;
-auth Task = unsafe;
+auth io = unsafe;
+auth fs = unsafe;
+auth os_fs = unsafe;
+auth run = unsafe;
+auth _str = unsafe;
+auth _vec = unsafe;
+auth _task = unsafe;
-auth Dbg = unsafe;
+auth dbg = unsafe;
-auth UInt.next_power_of_two = unsafe;
-auth Map.mk_hashmap = unsafe;
-auth Rand.mk_rng = unsafe;
+auth _uint::next_power_of_two = unsafe;
+auth map::mk_hashmap = unsafe;
+auth rand::mk_rng = unsafe;
-// Target-OS module.
+// Target-os module.
-// TODO: Have each OS module re-export everything from GenericOS.
-mod GenericOS;
+// TODO: Have each os module re-export everything from genericos.
+mod generic_os;
alt (target_os) {
case ("win32") {
- mod OS = "win32_OS.rs";
- mod OS_FS = "win32_FS.rs";
+ mod os = "win32_os.rs";
+ mod os_fs = "win32_fs.rs";
} case ("macos") {
- mod OS = "macos_OS.rs";
- mod OS_FS = "posix_FS.rs";
+ mod os = "macos_os.rs";
+ mod os_fs = "posix_fs.rs";
} else {
- mod OS = "linux_OS.rs";
- mod OS_FS = "posix_FS.rs";
+ mod os = "linux_os.rs";
+ mod os_fs = "posix_fs.rs";
}
}
-mod Run = "Run_Program.rs";
-mod FS;
+mod run = "run_program.rs";
+mod fs;
// FIXME: parametric
-mod Map;
-mod Deque;
-mod List;
-mod Rand;
-mod Dbg;
-mod BitV;
-mod Sort;
-mod SHA1;
-mod EBML;
-mod UFind;
-mod ExtFmt;
-mod Box;
-mod GetOpts;
-mod Term;
-mod Time;
+mod map;
+mod deque;
+mod list;
+mod rand;
+mod dbg;
+mod bitv;
+mod sort;
+mod sha1;
+mod ebml;
+mod ufind;
+mod extfmt;
+mod box;
+mod getopts;
+mod term;
+mod time;
// Local Variables:
// mode: rust;
--- /dev/null
+export rustrt;
+
+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.
+
+ export last_os_error;
+ export size_of;
+ export align_of;
+ export refcount;
+ export do_gc;
+
+ fn last_os_error() -> str;
+ fn size_of[T]() -> uint;
+ fn align_of[T]() -> uint;
+ fn refcount[T](@T t) -> uint;
+ fn do_gc();
+ fn unsupervise();
+}
+
+// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
--- /dev/null
+// Simple ANSI color library.
+//
+// TODO: Windows support.
+
+const u8 color_black = 0u8;
+const u8 color_red = 1u8;
+const u8 color_green = 2u8;
+const u8 color_yellow = 3u8;
+const u8 color_blue = 4u8;
+const u8 color_magenta = 5u8;
+const u8 color_cyan = 6u8;
+const u8 color_light_gray = 7u8;
+const u8 color_light_grey = 7u8;
+const u8 color_dark_gray = 8u8;
+const u8 color_dark_grey = 8u8;
+const u8 color_bright_red = 9u8;
+const u8 color_bright_green = 10u8;
+const u8 color_bright_yellow = 11u8;
+const u8 color_bright_blue = 12u8;
+const u8 color_bright_magenta = 13u8;
+const u8 color_bright_cyan = 14u8;
+const u8 color_bright_white = 15u8;
+
+fn esc(io::buf_writer writer) {
+ writer.write(vec(0x1bu8, '[' as u8));
+}
+
+fn reset(io::buf_writer writer) {
+ esc(writer);
+ writer.write(vec('0' as u8, 'm' as u8));
+}
+
+fn color_supported() -> bool {
+ ret generic_os::getenv("TERM") == option::some[str]("xterm-color");
+}
+
+fn set_color(io::buf_writer writer, u8 first_char, u8 color) {
+ assert (color < 16u8);
+
+ esc(writer);
+ if (color >= 8u8) {
+ writer.write(vec('1' as u8, ';' as u8));
+ color -= 8u8;
+ }
+ writer.write(vec(first_char, ('0' as u8) + color, 'm' as u8));
+}
+
+fn fg(io::buf_writer writer, u8 color) {
+ ret set_color(writer, '3' as u8, color);
+}
+
+fn bg(io::buf_writer writer, u8 color) {
+ ret set_color(writer, '4' as u8, color);
+}
+
+// export fg;
+// export bg;
+
--- /dev/null
+native "rust" mod rustrt {
+ fn get_time(&mutable u32 sec, &mutable u32 usec);
+}
+
+type timeval = rec(u32 sec, u32 usec);
+
+fn get_time() -> timeval {
+ let timeval res = rec(sec=0u32, usec=0u32);
+ rustrt::get_time(res.sec, res.usec);
+ ret res;
+}
+
--- /dev/null
+import option::none;
+import option::some;
+
+// A very naive implementation of union-find with unsigned integer nodes.
+
+type node = option::t[uint];
+type ufind = rec(mutable vec[mutable node] nodes);
+
+fn make() -> ufind {
+ let vec[mutable node] v = vec(mutable none[uint]);
+ _vec::pop(v); // FIXME: botch
+ ret rec(mutable nodes=v);
+}
+
+fn make_set(&ufind ufnd) -> uint {
+ auto idx = _vec::len(ufnd.nodes);
+ ufnd.nodes += vec(mutable none[uint]);
+ ret idx;
+}
+
+fn find(&ufind ufnd, uint n) -> uint {
+ alt (ufnd.nodes.(n)) {
+ case (none[uint]) { ret n; }
+ case (some[uint](?m)) {
+ // TODO: "be"
+ ret find(ufnd, m);
+ }
+ }
+}
+
+fn union(&ufind ufnd, uint m, uint n) {
+ auto m_root = find(ufnd, m);
+ auto n_root = find(ufnd, n);
+ auto ptr = some[uint](n_root);
+ ufnd.nodes.(m_root) = ptr;
+}
+
--- /dev/null
+fn id[T](&T x) -> 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); // : _int::positive(*.den);
+
+fn rational_leq(&rational x, &rational y) -> bool {
+ // NB: Uses the fact that rationals have positive denominators WLOG:
+ ret x.num * y.den <= y.num * x.den;
+}
+
+fn fst[T, U](&tup(T, U) x) -> T {
+ ret x._0;
+}
+
+fn snd[T, U](&tup(T, U) x) -> U {
+ ret x._1;
+}
+
+fn orb(&bool a, &bool b) -> bool {
+ ret a || b;
+}
+
+// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
+++ /dev/null
-native "rust" mod rustrt {
- fn rust_list_files(str path) -> vec[str];
- fn rust_file_is_dir(str path) -> int;
-}
-
-fn list_dir(str path) -> vec[str] {
- ret rustrt.rust_list_files(path+"*");
-}
-
-/* FIXME: win32 path handling actually accepts '/' or '\' and has subtly
- * different semantics for each. Since we build on mingw, we are usually
- * dealing with /-separated paths. But the whole interface to splitting and
- * joining pathnames needs a bit more abstraction on win32. Possibly a vec or
- * tag type.
- */
-const char path_sep = '/';
-const char alt_path_sep = '\\';
-
-// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
+++ /dev/null
-import Str.sbuf;
-import Vec.vbuf;
-
-native mod libc = "msvcrt.dll" {
- 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";
-
- 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 getenv(sbuf n) -> sbuf;
-
- fn _pipe(vbuf fds, uint size, int mode) -> int;
-}
-
-mod libc_constants {
- fn O_RDONLY() -> int { ret 0x0000; }
- fn O_WRONLY() -> int { ret 0x0001; }
- fn O_RDWR() -> int { ret 0x0002; }
- fn O_APPEND() -> int { ret 0x0400; }
- fn O_CREAT() -> int { ret 0x0040; }
- fn O_EXCL() -> int { ret 0x0080; }
- fn O_TRUNC() -> int { ret 0x0200; }
- fn O_TEXT() -> int { ret 0x4000; }
- fn O_BINARY() -> int { ret 0x8000; }
-
- fn S_IRUSR() -> uint { ret 0x0100u; } // really _S_IREAD in win32
- fn S_IWUSR() -> uint { ret 0x0080u; } // really _S_IWRITE in win32
-}
-
-fn exec_suffix() -> str {
- ret ".exe";
-}
-
-fn target_os() -> str {
- ret "win32";
-}
-
-fn dylib_filename(str base) -> str {
- ret base + ".dll";
-}
-
-fn pipe() -> tup(int, int) {
- let vec[mutable int] fds = vec(mutable 0, 0);
- assert (OS.libc._pipe(Vec.buf(fds), 1024u,
- libc_constants.O_BINARY()) == 0);
- ret tup(fds.(0), fds.(1));
-}
-
-fn fd_FILE(int fd) -> libc.FILE {
- ret libc._fdopen(fd, Str.buf("r"));
-}
-
-native "rust" mod rustrt {
- fn rust_process_wait(int handle) -> int;
-}
-
-fn waitpid(int pid) -> int {
- ret rustrt.rust_process_wait(pid);
-}
-
-// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
--- /dev/null
+native "rust" mod rustrt {
+ fn rust_list_files(str path) -> vec[str];
+ fn rust_file_is_dir(str path) -> int;
+}
+
+fn list_dir(str path) -> vec[str] {
+ ret rustrt::rust_list_files(path+"*");
+}
+
+/* FIXME: win32 path handling actually accepts '/' or '\' and has subtly
+ * different semantics for each. Since we build on mingw, we are usually
+ * dealing with /-separated paths. But the whole interface to splitting and
+ * joining pathnames needs a bit more abstraction on win32. Possibly a vec or
+ * tag type.
+ */
+const char path_sep = '/';
+const char alt_path_sep = '\\';
+
+// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
--- /dev/null
+import _str::sbuf;
+import _vec::vbuf;
+
+native mod libc = "msvcrt.dll" {
+ 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";
+
+ 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 getenv(sbuf n) -> sbuf;
+
+ fn _pipe(vbuf fds, uint size, int mode) -> int;
+}
+
+mod libc_constants {
+ fn O_RDONLY() -> int { ret 0x0000; }
+ fn O_WRONLY() -> int { ret 0x0001; }
+ fn O_RDWR() -> int { ret 0x0002; }
+ fn O_APPEND() -> int { ret 0x0400; }
+ fn O_CREAT() -> int { ret 0x0040; }
+ fn O_EXCL() -> int { ret 0x0080; }
+ fn O_TRUNC() -> int { ret 0x0200; }
+ fn O_TEXT() -> int { ret 0x4000; }
+ fn O_BINARY() -> int { ret 0x8000; }
+
+ fn S_IRUSR() -> uint { ret 0x0100u; } // really _S_IREAD in win32
+ fn S_IWUSR() -> uint { ret 0x0080u; } // really _S_IWRITE in win32
+}
+
+fn exec_suffix() -> str {
+ ret ".exe";
+}
+
+fn target_os() -> str {
+ ret "win32";
+}
+
+fn dylib_filename(str base) -> str {
+ ret base + ".dll";
+}
+
+fn pipe() -> tup(int, int) {
+ let vec[mutable int] fds = vec(mutable 0, 0);
+ assert (os::libc::_pipe(_vec::buf(fds), 1024u,
+ libc_constants::O_BINARY()) == 0);
+ ret tup(fds.(0), fds.(1));
+}
+
+fn fd_FILE(int fd) -> libc::FILE {
+ ret libc::_fdopen(fd, _str::buf("r"));
+}
+
+native "rust" mod rustrt {
+ fn rust_process_wait(int handle) -> int;
+}
+
+fn waitpid(int pid) -> int {
+ ret rustrt::rust_process_wait(pid);
+}
+
+// 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 .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
-/* -*- mode:rust;indent-tabs-mode:nil -*-
+/* -*- mode::rust;indent-tabs-mode::nil -*-
* Implementation of 99 Bottles of Beer
* http://99-bottles-of-beer.net/
*/
use std;
-import std.Int;
-import std.Str;
+import std::_int;
+import std::_str;
fn b1() -> str {
ret "# of beer on the wall, # of beer.";
ns = "1 bottle";
}
case (_) {
- ns = Int.to_str(n, 10u) + " bottles";
+ ns = _int::to_str(n, 10u) + " bottles";
}
}
- while (i < Str.byte_len(t)) {
+ while (i < _str::byte_len(t)) {
if (t.(i) == ('#' as u8)) {
b += ns;
}
else {
- Str.push_byte(b, t.(i));
+ _str::push_byte(b, t.(i));
}
i += 1u;
}
-/* -*- mode:rust;indent-tabs-mode:nil -*-
+/* -*- mode::rust;indent-tabs-mode::nil -*-
* Implementation of 99 Bottles of Beer
* http://99-bottles-of-beer.net/
*/
use std;
-import std.Int;
-import std.Str;
+import std::_int;
+import std::_str;
tag bottle { none; dual; single; multiple(int);}
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);
+ 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.";
-/* -*- mode:rust;indent-tabs-mode:nil -*-
+/* -*- mode::rust;indent-tabs-mode::nil -*-
* Implementation of 99 Bottles of Beer
* http://99-bottles-of-beer.net/
*/
use std;
-import std.Int;
-import std.Str;
+import std::_int;
+import std::_str;
fn b1() -> str {
ret "# of beer on the wall, # of beer.";
ns = "1 bottle";
}
case (_) {
- ns = Int.to_str(n, 10u) + " bottles";
+ ns = _int::to_str(n, 10u) + " bottles";
}
}
- while (i < Str.byte_len(t)) {
+ while (i < _str::byte_len(t)) {
if (t.(i) == ('#' as u8)) {
b += ns;
}
else {
- Str.push_byte(b, t.(i));
+ _str::push_byte(b, t.(i));
}
i += 1u;
}
-/* -*- mode:rust;indent-tabs-mode:nil -*-
+/* -*- mode::rust;indent-tabs-mode::nil -*-
* Implementation of 99 Bottles of Beer
* http://99-bottles-of-beer.net/
*/
use std;
-import std.Int;
-import std.Str;
+import std::_int;
+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);
+ 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.";
use std;
-import std.Int;
+import std::_int;
tag tree {
nil;
auto depth = min_depth;
while (depth <= max_depth) {
- auto iterations = Int.pow(2, (max_depth - depth + min_depth) as uint);
+ auto iterations = _int::pow(2, (max_depth - depth + min_depth) as uint);
auto chk = 0;
auto i = 1;
use std;
-import std.Int;
-import std.Vec;
+import std::_int;
+import std::_vec;
fn fannkuch(int n) -> int {
}
auto perm1init_ = perm1init; // Rustboot workaround
- auto perm = Vec.init_elt(0, n as uint);
- auto perm1 = Vec.init_fn(perm1init_, n as uint);
- auto count = Vec.init_elt(0, n as uint);
+ auto perm = _vec::init_elt(0, n as uint);
+ auto perm1 = _vec::init_fn(perm1init_, n as uint);
+ auto count = _vec::init_elt(0, n as uint);
auto f = 0;
auto i = 0;
* http://shootout.alioth.debian.org/
*/
use std;
-import std.Vec;
-import std.Str;
-import std.UInt;
-import std.Int;
+import std::_vec;
+import std::_str;
+import std::_uint;
+import std::_int;
fn LINE_LENGTH() -> uint {
ret 60u;
ret v.(hi)._0;
}
}
- ret bisect(genelist, 0u, Vec.len[aminoacids](genelist) - 1u, r);
+ ret bisect(genelist, 0u, _vec::len[aminoacids](genelist) - 1u, r);
}
fn make_random_fasta(str id, str desc, vec[aminoacids] genelist, int n) {
log(">" + id + " " + desc);
- auto rng = myrandom(std.Rand.mk_rng().next());
+ auto rng = myrandom(std::rand::mk_rng().next());
let str op = "";
- for each (uint i 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()) {
+ for each (uint i 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) > 0u) {
+ if (_str::byte_len(op) > 0u) {
log(op);
}
}
fn make_repeat_fasta(str id, str desc, str s, int n) {
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 uint sl = _str::byte_len(s);
+ for each (uint i in _uint::range(0u, n as uint)) {
- Str.push_byte(op, s.(i % sl));
- if (Str.byte_len(op) >= LINE_LENGTH()) {
+ _str::push_byte(op, s.(i % sl));
+ if (_str::byte_len(op) >= LINE_LENGTH()) {
log(op);
op = "";
}
}
- if (Str.byte_len(op) > 0u) {
+ if (_str::byte_len(op) > 0u) {
log(op);
}
}
// 50000000
);
- let vec[Body.props] bodies = NBodySystem.MakeNBodySystem();
+ let vec[Body::props] bodies = NBodySystem::MakeNBodySystem();
for (int n in inputs) {
- log NBodySystem.energy(bodies);
+ log NBodySystem::energy(bodies);
let int i = 0;
while (i < n) {
- NBodySystem.advance(bodies, 0.01);
+ NBodySystem::advance(bodies, 0.01);
i += 1;
}
- log NBodySystem.energy(bodies);
+ log NBodySystem::energy(bodies);
}
}
-// Body.props is a record of floats, so
-// vec[Body.props] is a vector of records of floats
+// Body::props is a record of floats, so
+// vec[Body::props] is a vector of records of floats
mod NBodySystem {
- fn MakeNBodySystem() -> vec[Body.props] {
- let vec[Body.props] bodies = vec(
- // these each return a Body.props
- Body.sun(),
- Body.jupiter(),
- Body.saturn(),
- Body.uranus(),
- Body.neptune());
+ fn MakeNBodySystem() -> vec[Body::props] {
+ let vec[Body::props] bodies = vec(
+ // these each return a Body::props
+ Body::sun(),
+ Body::jupiter(),
+ Body::saturn(),
+ Body::uranus(),
+ Body::neptune());
let float px = 0.0;
let float py = 0.0;
}
// side-effecting
- Body.offsetMomentum(bodies.(0), px, py, pz);
+ Body::offsetMomentum(bodies.(0), px, py, pz);
ret bodies;
}
- fn advance(vec[Body.props] bodies, float dt) -> () {
+ fn advance(vec[Body::props] bodies, float dt) -> () {
let int i = 0;
while (i < 5) {
}
}
- fn advance_one(&Body.props bi, &Body.props bj, float dt) {
+ 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;
let float dSquared = dx * dx + dy * dy + dz * dz;
- let float distance = llvm.sqrt(dSquared);
+ let float distance = llvm::sqrt(dSquared);
let float mag = dt / (dSquared * distance);
bi.vx -= dx * bj.mass * mag;
bj.vz += dz * bi.mass * mag;
}
- fn move(&Body.props b, float dt) {
+ fn move(&Body::props b, float dt) {
b.x += dt * b.vx;
b.y += dt * b.vy;
b.z += dt * b.vz;
}
- fn energy(vec[Body.props] bodies) -> float {
+ fn energy(vec[Body::props] bodies) -> float {
let float dx;
let float dy;
let float dz;
dy = bodies.(i).y - bodies.(j).y;
dz = bodies.(i).z - bodies.(j).z;
- distance = llvm.sqrt(dx*dx + dy*dy + dz*dz);
+ distance = llvm::sqrt(dx*dx + dy*dy + dz*dz);
e -= (bodies.(i).mass * bodies.(j).mass) / distance;
j += 1;
mutable float vz,
float mass);
- fn jupiter() -> Body.props {
+ fn jupiter() -> Body::props {
ret rec(
mutable x = 4.84143144246472090e+00,
mutable y = -1.16032004402742839e+00,
);
}
- fn saturn() -> Body.props {
+ fn saturn() -> Body::props {
ret rec(
mutable x = 8.34336671824457987e+00,
mutable y = 4.12479856412430479e+00,
);
}
- fn uranus() -> Body.props {
+ fn uranus() -> Body::props {
ret rec(
mutable x = 1.28943695621391310e+01,
mutable y = -1.51111514016986312e+01,
);
}
- fn neptune() -> Body.props {
+ fn neptune() -> Body::props {
ret rec(
mutable x = 1.53796971148509165e+01,
mutable y = -2.59193146099879641e+01,
);
}
- fn sun() -> Body.props {
+ fn sun() -> Body::props {
ret rec(
mutable x = 0.0,
mutable y = 0.0,
);
}
- fn offsetMomentum(&Body.props props,
+ fn offsetMomentum(&Body::props props,
float px,
float py,
float pz) -> () {
}
fn main(vec[str] args) {
- log m1.a;
+ log m1::a;
}
-// error-pattern: can't refer to a module as a first-class value
+// error-pattern: is a module, not a
mod m1 {
mod a {
}
fn main(vec[str] args) {
- log m1.a;
+ log m1::a;
}
// xfail-boot
-// error-pattern:Unsatisfied precondition
+// error-pattern::Unsatisfied precondition
fn foo() -> int {
let int x;
// xfail-boot
-// error-pattern:Unsatisfied precondition
+// error-pattern::Unsatisfied precondition
fn foo() -> int {
let int x;
}
fn main() {
- foo.z(10);
+ foo::z(10);
}
export bar;
fn bar() {
- foo.baz();
+ foo::baz();
}
fn baz() {
// xfail-stage0
// error-pattern: unresolved import
-import m.unexported;
+import m::unexported;
mod m {
export exported;
}
fn main() {
- auto x = foo.t1;
+ auto x = foo::t1;
}
}
fn main() {
- auto z = foo.y1;
+ auto z = foo::y1;
}
}
fn main() {
- foo.z(10);
+ foo::z(10);
}
export x;
fn x() {
- bar.x();
+ bar::x();
}
}
}
fn main() {
- foo.x();
+ foo::x();
}
-// error-pattern:cyclic import
+// error-pattern::cyclic import
mod a {
- import b.x;
+ import b::x;
}
mod b {
- import a.x;
+ import a::x;
fn main() {
auto y = x;
-// error-pattern:cyclic import
+// error-pattern::cyclic import
import x;
// xfail-boot
// xfail-stage0
// error-pattern: unresolved import: baz
-import zed.bar;
-import zed.baz;
+import zed::bar;
+import zed::baz;
mod zed {
fn bar() {
log "bar";
// xfail-boot
// error-pattern: unresolved name
-import baz.zed.bar;
+import baz::zed::bar;
mod baz {
}
mod zed {
// xfail-boot
// error-pattern: main is not a module or crate
-import main.bar;
+import main::bar;
fn main(vec[str] args) {
log "foo";
// xfail-boot
// error-pattern: cyclic import
-import zed.bar;
-import bar.zed;
+import zed::bar;
+import bar::zed;
fn main(vec[str] args) {
log "loop";
// -*- rust -*-
-// error-pattern:9:2
+// error-pattern::9:2
/* 1
* 2
-// error-pattern:reserved keyword
+// error-pattern::reserved keyword
fn main() {
let int dec = 0;
-// error-pattern:reserved keyword
+// error-pattern::reserved keyword
fn main() {
let int f128 = 0;
-// error-pattern:reserved keyword
+// error-pattern::reserved keyword
fn main() {
let int f16 = 0;
-// error-pattern:reserved keyword
+// error-pattern::reserved keyword
fn main() {
let int f80 = 0;
-// error-pattern:reserved keyword
+// error-pattern::reserved keyword
fn main() {
let int m128 = 0;
-// error-pattern:reserved keyword
+// error-pattern::reserved keyword
fn main() {
let int m32 = 0;
-// error-pattern:reserved keyword
+// error-pattern::reserved keyword
fn main() {
let int m64 = 0;
// xfail-boot
-// error-pattern:expecting ., found (
+// error-pattern::expecting ., found (
fn main() {
obj foo() {
-// error-pattern:Unsatisfied precondition
+// error-pattern::Unsatisfied precondition
fn foo(int x) {
log x;
-// error-pattern:Unsatisfied precondition
+// error-pattern::Unsatisfied precondition
fn foo(int x) {
log x;
-// error-pattern:Unsatisfied precondition
+// error-pattern::Unsatisfied precondition
fn main() {
state obj foo(int x) {
-// error-pattern:Unsatisfied precondition
+// error-pattern::Unsatisfied precondition
fn foo(int x) {
log x;
// xfail-stage0
// xfail-stage1
// xfail-stage2
-// error-pattern:explicit
+// error-pattern::explicit
fn main() {
fail;
// xfail-stage0
// xfail-stage1
// xfail-stage2
-// error-pattern:1 == 2
+// error-pattern::1 == 2
fn main() {
assert (1 == 2);
// xfail-stage2
// -*- rust -*-
-// error-pattern:1 == 2
+// error-pattern::1 == 2
fn child() {
assert (1 == 2);
// xfail-stage2
// -*- rust -*-
-// error-pattern:non-exhaustive match failure
+// error-pattern::non-exhaustive match failure
tag t {
a;
// xfail-stage2
// -*- rust -*-
-// error-pattern:predicate check
+// error-pattern::predicate check
fn f(int a, int b) : lt(a,b) {
}
// xfail-stage2
// -*- rust -*-
-// error-pattern:bounds check
+// error-pattern::bounds check
fn main() {
let str s = "hello";
// xfail-stage2
// -*- rust -*-
-// error-pattern:bounds check
+// error-pattern::bounds check
fn main() {
let vec[int] v = vec(10);
// xfail-stage2
// -*- rust -*-
-// error-pattern:bounds check
+// error-pattern::bounds check
fn main() {
let vec[int] v = vec(10, 20);
use std;
-import std.Option;
-import std.Option.t;
-import std.Option.none;
-import std.Option.some;
+import std::option;
+import std::option::t;
+import std::option::none;
+import std::option::some;
-fn foo[T](&Option.t[T] y) {
+fn foo[T](&option::t[T] y) {
let int x;
let vec[int] res = vec();
foo2;
}
}
-fn bar(m1.foo x) {
+fn bar(m1::foo x) {
alt(x) {
- case (m1.foo1) {
+ case (m1::foo1) {
}
}
}
// -*- rust -*-
use std;
-import std.Str;
+import std::_str;
-// FIXME: import std.Dbg.const_refcount. Currently
+// FIXME: import std::dbg.const_refcount. Currently
// cross-crate const references don't work.
const uint const_refcount = 0x7bad_face_u;
case (_) { log "?"; fail; }
}
- log Str.refcount(s);
- assert (Str.refcount(s) == const_refcount);
+ log _str::refcount(s);
+ assert (_str::refcount(s) == const_refcount);
}
fn main() {
let str s = "hi"; // ref up
foo(s); // ref up then down
- log Str.refcount(s);
- assert (Str.refcount(s) == const_refcount);
+ log _str::refcount(s);
+ assert (_str::refcount(s) == const_refcount);
}
}
fn main() {
- let foo.t v = foo.f();
+ let foo::t v = foo::f();
}
}
fn main() {
- foo.bar.y();
+ foo::bar::y();
}
export x;
fn x() {
- bar.x();
+ bar::x();
}
}
}
fn main() {
- foo.x();
+ foo::x();
}
}
fn main() {
- auto v = foo.t1;
+ auto v = foo::t1;
}
}
fn main() {
- foo.g(foo.f());
+ foo::g(foo::f());
}
\ No newline at end of file
}
fn main() {
- foomod.foo[int]();
- foomod.foo[int]();
+ foomod::foo[int]();
+ foomod::foo[int]();
}
}
mod bar {
- import foo.x;
- import z = foo.x;
+ import foo::x;
+ import z = foo::x;
fn main() {
x(10);
z(10);
-import zed.bar;
+import zed::bar;
mod zed {
fn bar() {
log "bar";
-import zed.bar;
-import baz.zed;
+import zed::bar;
+import baz::zed;
mod baz {
mod zed {
fn bar() {
-import zed.bar;
+import zed::bar;
mod zed {
fn bar() {
log "bar";
-import foo.bar;
+import foo::bar;
mod foo {
- import zed.bar;
+ import zed::bar;
mod zed {
fn bar() {
log "foo";
-import bar.baz;
-import foo.zed;
+import bar::baz;
+import foo::zed;
mod foo {
mod zed {
fn baz() {
}
}
mod bar {
- import zed.baz;
+ import zed::baz;
}
fn main(vec[str] args) {
baz();
-import bar.baz;
-import foo.zed;
+import bar::baz;
+import foo::zed;
mod foo {
mod zed {
fn baz() {
}
}
mod bar {
- import zed.baz;
+ import zed::baz;
mod foo {
mod zed {
}
-import foo.x;
-import z = foo.x;
+import foo::x;
+import z = foo::x;
mod foo {
fn x(int y) {
}
}
fn hello() {
- inner2.hello();
+ inner2::hello();
}
}
fn main() {
- inner.hello();
- inner.inner2.hello();
+ inner::hello();
+ inner::inner2::hello();
}
use std;
-import std.Vec;
-import std.BitV;
+import std::_vec;
+import std::bitv;
fn test_0_elements() {
auto act;
auto exp;
- act = BitV.create(0u, false);
- exp = Vec.init_elt[uint](0u, 0u);
+ act = bitv::create(0u, false);
+ exp = _vec::init_elt[uint](0u, 0u);
// FIXME: why can't I write vec[uint]()?
- assert (BitV.eq_vec(act, exp));
+ assert (bitv::eq_vec(act, exp));
}
fn test_1_element() {
auto act;
- act = BitV.create(1u, false);
- assert (BitV.eq_vec(act, vec(0u)));
+ act = bitv::create(1u, false);
+ assert (bitv::eq_vec(act, vec(0u)));
- act = BitV.create(1u, true);
- assert (BitV.eq_vec(act, vec(1u)));
+ act = bitv::create(1u, true);
+ assert (bitv::eq_vec(act, vec(1u)));
}
fn test_10_elements() {
auto act;
// all 0
- act = BitV.create(10u, false);
- assert (BitV.eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u)));
+ act = bitv::create(10u, false);
+ assert (bitv::eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u)));
// all 1
- act = BitV.create(10u, true);
- assert (BitV.eq_vec(act, vec(1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u)));
+ act = bitv::create(10u, true);
+ assert (bitv::eq_vec(act, vec(1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u)));
// mixed
- act = BitV.create(10u, false);
- BitV.set(act, 0u, true);
- BitV.set(act, 1u, true);
- BitV.set(act, 2u, true);
- BitV.set(act, 3u, true);
- BitV.set(act, 4u, true);
- assert (BitV.eq_vec(act, vec(1u, 1u, 1u, 1u, 1u, 0u, 0u, 0u, 0u, 0u)));
+ act = bitv::create(10u, false);
+ bitv::set(act, 0u, true);
+ bitv::set(act, 1u, true);
+ bitv::set(act, 2u, true);
+ bitv::set(act, 3u, true);
+ bitv::set(act, 4u, true);
+ assert (bitv::eq_vec(act, vec(1u, 1u, 1u, 1u, 1u, 0u, 0u, 0u, 0u, 0u)));
// mixed
- act = BitV.create(10u, false);
- BitV.set(act, 5u, true);
- BitV.set(act, 6u, true);
- BitV.set(act, 7u, true);
- BitV.set(act, 8u, true);
- BitV.set(act, 9u, true);
- assert (BitV.eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 1u, 1u, 1u, 1u, 1u)));
+ act = bitv::create(10u, false);
+ bitv::set(act, 5u, true);
+ bitv::set(act, 6u, true);
+ bitv::set(act, 7u, true);
+ bitv::set(act, 8u, true);
+ bitv::set(act, 9u, true);
+ assert (bitv::eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 1u, 1u, 1u, 1u, 1u)));
// mixed
- act = BitV.create(10u, false);
- BitV.set(act, 0u, true);
- BitV.set(act, 3u, true);
- BitV.set(act, 6u, true);
- BitV.set(act, 9u, true);
- assert (BitV.eq_vec(act, vec(1u, 0u, 0u, 1u, 0u, 0u, 1u, 0u, 0u, 1u)));
+ act = bitv::create(10u, false);
+ bitv::set(act, 0u, true);
+ bitv::set(act, 3u, true);
+ bitv::set(act, 6u, true);
+ bitv::set(act, 9u, true);
+ assert (bitv::eq_vec(act, vec(1u, 0u, 0u, 1u, 0u, 0u, 1u, 0u, 0u, 1u)));
}
fn test_31_elements() {
auto act;
// all 0
- act = BitV.create(31u, false);
- assert (BitV.eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ act = bitv::create(31u, false);
+ assert (bitv::eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u)));
// all 1
- act = BitV.create(31u, true);
- assert (BitV.eq_vec(act, vec(1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
+ act = bitv::create(31u, true);
+ assert (bitv::eq_vec(act, vec(1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
1u, 1u, 1u, 1u, 1u, 1u, 1u)));
// mixed
- act = BitV.create(31u, false);
- BitV.set(act, 0u, true);
- BitV.set(act, 1u, true);
- BitV.set(act, 2u, true);
- BitV.set(act, 3u, true);
- BitV.set(act, 4u, true);
- BitV.set(act, 5u, true);
- BitV.set(act, 6u, true);
- BitV.set(act, 7u, true);
- assert (BitV.eq_vec(act, vec(1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
+ act = bitv::create(31u, false);
+ bitv::set(act, 0u, true);
+ bitv::set(act, 1u, true);
+ bitv::set(act, 2u, true);
+ bitv::set(act, 3u, true);
+ bitv::set(act, 4u, true);
+ bitv::set(act, 5u, true);
+ bitv::set(act, 6u, true);
+ bitv::set(act, 7u, true);
+ assert (bitv::eq_vec(act, vec(1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u)));
// mixed
- act = BitV.create(31u, false);
- BitV.set(act, 16u, true);
- BitV.set(act, 17u, true);
- BitV.set(act, 18u, true);
- BitV.set(act, 19u, true);
- BitV.set(act, 20u, true);
- BitV.set(act, 21u, true);
- BitV.set(act, 22u, true);
- BitV.set(act, 23u, true);
- assert (BitV.eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ act = bitv::create(31u, false);
+ bitv::set(act, 16u, true);
+ bitv::set(act, 17u, true);
+ bitv::set(act, 18u, true);
+ bitv::set(act, 19u, true);
+ bitv::set(act, 20u, true);
+ bitv::set(act, 21u, true);
+ bitv::set(act, 22u, true);
+ bitv::set(act, 23u, true);
+ assert (bitv::eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
0u, 0u, 0u, 0u, 0u, 0u, 0u)));
// mixed
- act = BitV.create(31u, false);
- BitV.set(act, 24u, true);
- BitV.set(act, 25u, true);
- BitV.set(act, 26u, true);
- BitV.set(act, 27u, true);
- BitV.set(act, 28u, true);
- BitV.set(act, 29u, true);
- BitV.set(act, 30u, true);
- assert (BitV.eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ act = bitv::create(31u, false);
+ bitv::set(act, 24u, true);
+ bitv::set(act, 25u, true);
+ bitv::set(act, 26u, true);
+ bitv::set(act, 27u, true);
+ bitv::set(act, 28u, true);
+ bitv::set(act, 29u, true);
+ bitv::set(act, 30u, true);
+ assert (bitv::eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
1u, 1u, 1u, 1u, 1u, 1u, 1u)));
// mixed
- act = BitV.create(31u, false);
- BitV.set(act, 3u, true);
- BitV.set(act, 17u, true);
- BitV.set(act, 30u, true);
- assert (BitV.eq_vec(act, vec(0u, 0u, 0u, 1u, 0u, 0u, 0u, 0u,
+ act = bitv::create(31u, false);
+ bitv::set(act, 3u, true);
+ bitv::set(act, 17u, true);
+ bitv::set(act, 30u, true);
+ assert (bitv::eq_vec(act, vec(0u, 0u, 0u, 1u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 1u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 1u)));
auto act;
// all 0
- act = BitV.create(32u, false);
- assert (BitV.eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ act = bitv::create(32u, false);
+ assert (bitv::eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u)));
// all 1
- act = BitV.create(32u, true);
- assert (BitV.eq_vec(act, vec(1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
+ act = bitv::create(32u, true);
+ assert (bitv::eq_vec(act, vec(1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u)));
// mixed
- act = BitV.create(32u, false);
- BitV.set(act, 0u, true);
- BitV.set(act, 1u, true);
- BitV.set(act, 2u, true);
- BitV.set(act, 3u, true);
- BitV.set(act, 4u, true);
- BitV.set(act, 5u, true);
- BitV.set(act, 6u, true);
- BitV.set(act, 7u, true);
- assert (BitV.eq_vec(act, vec(1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
+ act = bitv::create(32u, false);
+ bitv::set(act, 0u, true);
+ bitv::set(act, 1u, true);
+ bitv::set(act, 2u, true);
+ bitv::set(act, 3u, true);
+ bitv::set(act, 4u, true);
+ bitv::set(act, 5u, true);
+ bitv::set(act, 6u, true);
+ bitv::set(act, 7u, true);
+ assert (bitv::eq_vec(act, vec(1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u)));
// mixed
- act = BitV.create(32u, false);
- BitV.set(act, 16u, true);
- BitV.set(act, 17u, true);
- BitV.set(act, 18u, true);
- BitV.set(act, 19u, true);
- BitV.set(act, 20u, true);
- BitV.set(act, 21u, true);
- BitV.set(act, 22u, true);
- BitV.set(act, 23u, true);
- assert (BitV.eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ act = bitv::create(32u, false);
+ bitv::set(act, 16u, true);
+ bitv::set(act, 17u, true);
+ bitv::set(act, 18u, true);
+ bitv::set(act, 19u, true);
+ bitv::set(act, 20u, true);
+ bitv::set(act, 21u, true);
+ bitv::set(act, 22u, true);
+ bitv::set(act, 23u, true);
+ assert (bitv::eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u)));
// mixed
- act = BitV.create(32u, false);
- BitV.set(act, 24u, true);
- BitV.set(act, 25u, true);
- BitV.set(act, 26u, true);
- BitV.set(act, 27u, true);
- BitV.set(act, 28u, true);
- BitV.set(act, 29u, true);
- BitV.set(act, 30u, true);
- BitV.set(act, 31u, true);
- assert (BitV.eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ act = bitv::create(32u, false);
+ bitv::set(act, 24u, true);
+ bitv::set(act, 25u, true);
+ bitv::set(act, 26u, true);
+ bitv::set(act, 27u, true);
+ bitv::set(act, 28u, true);
+ bitv::set(act, 29u, true);
+ bitv::set(act, 30u, true);
+ bitv::set(act, 31u, true);
+ assert (bitv::eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u)));
// mixed
- act = BitV.create(32u, false);
- BitV.set(act, 3u, true);
- BitV.set(act, 17u, true);
- BitV.set(act, 30u, true);
- BitV.set(act, 31u, true);
- assert (BitV.eq_vec(act, vec(0u, 0u, 0u, 1u, 0u, 0u, 0u, 0u,
+ act = bitv::create(32u, false);
+ bitv::set(act, 3u, true);
+ bitv::set(act, 17u, true);
+ bitv::set(act, 30u, true);
+ bitv::set(act, 31u, true);
+ assert (bitv::eq_vec(act, vec(0u, 0u, 0u, 1u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 1u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 1u, 1u)));
auto act;
// all 0
- act = BitV.create(33u, false);
- assert (BitV.eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ act = bitv::create(33u, false);
+ assert (bitv::eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u)));
// all 1
- act = BitV.create(33u, true);
- assert (BitV.eq_vec(act, vec(1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
+ act = bitv::create(33u, true);
+ assert (bitv::eq_vec(act, vec(1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
1u)));
// mixed
- act = BitV.create(33u, false);
- BitV.set(act, 0u, true);
- BitV.set(act, 1u, true);
- BitV.set(act, 2u, true);
- BitV.set(act, 3u, true);
- BitV.set(act, 4u, true);
- BitV.set(act, 5u, true);
- BitV.set(act, 6u, true);
- BitV.set(act, 7u, true);
- assert (BitV.eq_vec(act, vec(1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
+ act = bitv::create(33u, false);
+ bitv::set(act, 0u, true);
+ bitv::set(act, 1u, true);
+ bitv::set(act, 2u, true);
+ bitv::set(act, 3u, true);
+ bitv::set(act, 4u, true);
+ bitv::set(act, 5u, true);
+ bitv::set(act, 6u, true);
+ bitv::set(act, 7u, true);
+ assert (bitv::eq_vec(act, vec(1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u)));
// mixed
- act = BitV.create(33u, false);
- BitV.set(act, 16u, true);
- BitV.set(act, 17u, true);
- BitV.set(act, 18u, true);
- BitV.set(act, 19u, true);
- BitV.set(act, 20u, true);
- BitV.set(act, 21u, true);
- BitV.set(act, 22u, true);
- BitV.set(act, 23u, true);
- assert (BitV.eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ act = bitv::create(33u, false);
+ bitv::set(act, 16u, true);
+ bitv::set(act, 17u, true);
+ bitv::set(act, 18u, true);
+ bitv::set(act, 19u, true);
+ bitv::set(act, 20u, true);
+ bitv::set(act, 21u, true);
+ bitv::set(act, 22u, true);
+ bitv::set(act, 23u, true);
+ assert (bitv::eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u)));
// mixed
- act = BitV.create(33u, false);
- BitV.set(act, 24u, true);
- BitV.set(act, 25u, true);
- BitV.set(act, 26u, true);
- BitV.set(act, 27u, true);
- BitV.set(act, 28u, true);
- BitV.set(act, 29u, true);
- BitV.set(act, 30u, true);
- BitV.set(act, 31u, true);
- assert (BitV.eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ act = bitv::create(33u, false);
+ bitv::set(act, 24u, true);
+ bitv::set(act, 25u, true);
+ bitv::set(act, 26u, true);
+ bitv::set(act, 27u, true);
+ bitv::set(act, 28u, true);
+ bitv::set(act, 29u, true);
+ bitv::set(act, 30u, true);
+ bitv::set(act, 31u, true);
+ assert (bitv::eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
0u)));
// mixed
- act = BitV.create(33u, false);
- BitV.set(act, 3u, true);
- BitV.set(act, 17u, true);
- BitV.set(act, 30u, true);
- BitV.set(act, 31u, true);
- BitV.set(act, 32u, true);
- assert (BitV.eq_vec(act, vec(0u, 0u, 0u, 1u, 0u, 0u, 0u, 0u,
+ act = bitv::create(33u, false);
+ bitv::set(act, 3u, true);
+ bitv::set(act, 17u, true);
+ bitv::set(act, 30u, true);
+ bitv::set(act, 31u, true);
+ bitv::set(act, 32u, true);
+ assert (bitv::eq_vec(act, vec(0u, 0u, 0u, 1u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 1u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 1u, 1u,
use std;
-import std.Box;
+import std::box;
fn main() {
auto x = @3;
auto y = @3;
- assert (Box.ptr_eq[int](x, x));
- assert (Box.ptr_eq[int](y, y));
- assert (!Box.ptr_eq[int](x, y));
- assert (!Box.ptr_eq[int](y, x));
+ assert (box::ptr_eq[int](x, x));
+ assert (box::ptr_eq[int](y, y));
+ assert (!box::ptr_eq[int](x, y));
+ assert (!box::ptr_eq[int](y, x));
}
// -*- rust -*-
use std;
-import std.Deque;
+import std::deque;
fn test_simple() {
- let Deque.t[int] d = Deque.create[int]();
+ let deque::t[int] d = deque::create[int]();
assert (d.size() == 0u);
d.add_front(17);
d.add_front(42);
}
fn test_boxes(@int a, @int b, @int c, @int d) {
- let Deque.t[@int] deq = Deque.create[@int]();
+ let deque::t[@int] deq = deque::create[@int]();
assert (deq.size() == 0u);
deq.add_front(a);
deq.add_front(b);
type eqfn[T] = fn(&T a, &T b) -> bool;
fn test_parameterized[T](eqfn[T] e, &T a, &T b, &T c, &T d) {
- let Deque.t[T] deq = Deque.create[T]();
+ let deque::t[T] deq = deque::create[T]();
assert (deq.size() == 0u);
deq.add_front(a);
deq.add_front(b);
use std;
-import std.Int;
-import std.Str.eq;
+import std::_int;
+import std::_str::eq;
fn test_to_str() {
- assert (eq(Int.to_str(0, 10u), "0"));
- assert (eq(Int.to_str(1, 10u), "1"));
- assert (eq(Int.to_str(-1, 10u), "-1"));
- assert (eq(Int.to_str(255, 16u), "ff"));
- assert (eq(Int.to_str(100, 10u), "100"));
+ assert (eq(_int::to_str(0, 10u), "0"));
+ assert (eq(_int::to_str(1, 10u), "1"));
+ assert (eq(_int::to_str(-1, 10u), "-1"));
+ assert (eq(_int::to_str(255, 16u), "ff"));
+ assert (eq(_int::to_str(100, 10u), "100"));
}
fn test_pow() {
- assert (Int.pow(0, 0u) == 1);
- assert (Int.pow(0, 1u) == 0);
- assert (Int.pow(0, 2u) == 0);
- assert (Int.pow(-1, 0u) == -1);
- assert (Int.pow(1, 0u) == 1);
- assert (Int.pow(-3, 2u) == 9);
- assert (Int.pow(-3, 3u) == -27);
- assert (Int.pow(4, 9u) == 262144);
+ assert (_int::pow(0, 0u) == 1);
+ assert (_int::pow(0, 1u) == 0);
+ assert (_int::pow(0, 2u) == 0);
+ assert (_int::pow(-1, 0u) == -1);
+ assert (_int::pow(1, 0u) == 1);
+ assert (_int::pow(-3, 2u) == 9);
+ assert (_int::pow(-3, 3u) == -27);
+ assert (_int::pow(4, 9u) == 262144);
}
fn main() {
// -*- rust -*-
use std;
-import std.IO;
-import std.Str;
+import std::io;
+import std::_str;
fn test_simple(str tmpfilebase) {
let str tmpfile = tmpfilebase + ".tmp";
log frood;
{
- let IO.writer out = IO.file_writer(tmpfile, vec(IO.create));
+ let io::writer out = io::file_writer(tmpfile, vec(io::create));
out.write_str(frood);
}
- let IO.reader inp = IO.file_reader(tmpfile);
+ let io::reader inp = io::file_reader(tmpfile);
let str frood2 = inp.read_c_str();
log frood2;
- assert (Str.eq(frood, frood2));
+ assert (_str::eq(frood, frood2));
}
fn main(vec[str] argv) {
// -*- rust -*-
use std;
-import std.Map;
-import std.Str;
-import std.UInt;
-import std.Util;
+import std::map;
+import std::_str;
+import std::_uint;
+import std::util;
fn test_simple() {
log "*** starting test_simple";
fn eq_uint(&uint x, &uint y) -> bool { ret x == y; }
fn hash_uint(&uint u) -> uint {
- // FIXME: can't use std.Util.id since we'd be capturing a type param,
+ // 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[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 map::hashfn[str] hasher_str = _str::hash;
+ let map::eqfn[str] eqer_str = _str::eq;
log "uint -> uint";
- let Map.hashmap[uint, uint] hm_uu = Map.mk_hashmap[uint, uint](hasher_uint,
- eqer_uint);
+ let map::hashmap[uint, uint] hm_uu =
+ map::mk_hashmap[uint, uint](hasher_uint, eqer_uint);
assert (hm_uu.insert(10u, 12u));
assert (hm_uu.insert(11u, 13u));
log "str -> uint";
- let Map.hashmap[str, uint] hm_su = Map.mk_hashmap[str, uint](hasher_str,
+ let map::hashmap[str, uint] hm_su = map::mk_hashmap[str, uint](hasher_str,
eqer_str);
assert (hm_su.insert("ten", 12u));
assert (hm_su.insert(eleven, 13u));
log "uint -> str";
- let Map.hashmap[uint, str] hm_us = Map.mk_hashmap[uint, str](hasher_uint,
+ let map::hashmap[uint, str] hm_us = map::mk_hashmap[uint, str](hasher_uint,
eqer_uint);
assert (hm_us.insert(10u, "twelve"));
assert (hm_us.insert(11u, "thirteen"));
assert (hm_us.insert(12u, "fourteen"));
- assert (Str.eq(hm_us.get(11u), "thirteen"));
- assert (Str.eq(hm_us.get(12u), "fourteen"));
- assert (Str.eq(hm_us.get(10u), "twelve"));
+ assert (_str::eq(hm_us.get(11u), "thirteen"));
+ assert (_str::eq(hm_us.get(12u), "fourteen"));
+ assert (_str::eq(hm_us.get(10u), "twelve"));
assert (!hm_us.insert(12u, "fourteen"));
- assert (Str.eq(hm_us.get(12u), "fourteen"));
+ assert (_str::eq(hm_us.get(12u), "fourteen"));
assert (!hm_us.insert(12u, "twelve"));
- assert (Str.eq(hm_us.get(12u), "twelve"));
+ assert (_str::eq(hm_us.get(12u), "twelve"));
log "str -> str";
- let Map.hashmap[str, str] hm_ss = Map.mk_hashmap[str, str](hasher_str,
+ let map::hashmap[str, str] hm_ss = map::mk_hashmap[str, str](hasher_str,
eqer_str);
assert (hm_ss.insert(ten, "twelve"));
assert (hm_ss.insert(eleven, "thirteen"));
assert (hm_ss.insert(twelve, "fourteen"));
- assert (Str.eq(hm_ss.get("eleven"), "thirteen"));
- assert (Str.eq(hm_ss.get("twelve"), "fourteen"));
- assert (Str.eq(hm_ss.get("ten"), "twelve"));
+ assert (_str::eq(hm_ss.get("eleven"), "thirteen"));
+ assert (_str::eq(hm_ss.get("twelve"), "fourteen"));
+ assert (_str::eq(hm_ss.get("ten"), "twelve"));
assert (!hm_ss.insert("twelve", "fourteen"));
- assert (Str.eq(hm_ss.get("twelve"), "fourteen"));
+ assert (_str::eq(hm_ss.get("twelve"), "fourteen"));
assert (!hm_ss.insert("twelve", "twelve"));
- assert (Str.eq(hm_ss.get("twelve"), "twelve"));
+ assert (_str::eq(hm_ss.get("twelve"), "twelve"));
log "*** finished test_simple";
}
fn eq_uint(&uint x, &uint y) -> bool { ret x == y; }
fn hash_uint(&uint u) -> uint {
- // FIXME: can't use std.Util.id since we'd be capturing a type param,
+ // 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 = Map.mk_hashmap[uint, uint](hasher_uint,
- eqer_uint);
+ let map::hashfn[uint] hasher_uint = hash_uint;
+ let map::eqfn[uint] eqer_uint = eq_uint;
+ let map::hashmap[uint, uint] hm_uu =
+ map::mk_hashmap[uint, uint](hasher_uint, eqer_uint);
let uint i = 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);
+ log "inserting " + _uint::to_str(i, 10u)
+ + " -> " + _uint::to_str(i * i, 10u);
i += 1u;
}
i = 0u;
while (i < num_to_insert) {
- log "get(" + UInt.to_str(i, 10u) + ") = "
- + UInt.to_str(hm_uu.get(i), 10u);
+ log "get(" + _uint::to_str(i, 10u) + ") = "
+ + _uint::to_str(hm_uu.get(i), 10u);
assert (hm_uu.get(i) == i * i);
i += 1u;
}
i = 0u;
while (i < num_to_insert) {
- log "get(" + UInt.to_str(i, 10u) + ") = "
- + UInt.to_str(hm_uu.get(i), 10u);
+ 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 = Map.mk_hashmap[str, str](hasher_str,
+ let map::hashfn[str] hasher_str = _str::hash;
+ let map::eqfn[str] eqer_str = _str::eq;
+ let map::hashmap[str, str] hm_ss = map::mk_hashmap[str, str](hasher_str,
eqer_str);
i = 0u;
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) + "\"";
+ 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) + "\"";
i += 1u;
}
i = 0u;
while (i < num_to_insert) {
log "get(\""
- + UInt.to_str(i, 2u)
+ + _uint::to_str(i, 2u)
+ "\") = \""
- + hm_ss.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)),
- UInt.to_str(i * i, 2u)));
+ assert (_str::eq(hm_ss.get(_uint::to_str(i, 2u)),
+ _uint::to_str(i * i, 2u)));
i += 1u;
}
- assert (hm_ss.insert(UInt.to_str(num_to_insert, 2u),
- UInt.to_str(17u, 2u)));
+ assert (hm_ss.insert(_uint::to_str(num_to_insert, 2u),
+ _uint::to_str(17u, 2u)));
- assert (Str.eq(hm_ss.get(UInt.to_str(num_to_insert, 2u)),
- UInt.to_str(17u, 2u)));
+ assert (_str::eq(hm_ss.get(_uint::to_str(num_to_insert, 2u)),
+ _uint::to_str(17u, 2u)));
log "-----";
i = 0u;
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)),
- UInt.to_str(i * i, 2u)));
+ 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)),
+ _uint::to_str(i * i, 2u)));
i += 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 = Map.mk_hashmap[uint, uint](hasher, eqer);
+ let map::hashfn[uint] hasher = hash;
+ let map::eqfn[uint] eqer = eq;
+ let map::hashmap[uint, uint] hm = map::mk_hashmap[uint, uint](hasher, eqer);
let uint i = 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);
+ log "inserting " + _uint::to_str(i, 10u)
+ + " -> " + _uint::to_str(i * i, 10u);
i += 1u;
}
i = 1u;
while (i < num_to_insert) {
- log "get(" + UInt.to_str(i, 10u) + ") = "
- + UInt.to_str(hm.get(i), 10u);
+ log "get(" + _uint::to_str(i, 10u) + ") = "
+ + _uint::to_str(hm.get(i), 10u);
assert (hm.get(i) == i * i);
i += 2u;
}
i = 1u;
while (i < num_to_insert) {
- log "get(" + UInt.to_str(i, 10u) + ") = "
- + UInt.to_str(hm.get(i), 10u);
+ log "get(" + _uint::to_str(i, 10u) + ") = "
+ + _uint::to_str(hm.get(i), 10u);
assert (hm.get(i) == i * i);
i += 2u;
}
i = 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);
+ log "inserting " + _uint::to_str(i, 10u)
+ + " -> " + _uint::to_str(i * i, 10u);
i += 2u;
}
i = 0u;
while (i < num_to_insert) {
- log "get(" + UInt.to_str(i, 10u) + ") = "
- + UInt.to_str(hm.get(i), 10u);
+ log "get(" + _uint::to_str(i, 10u) + ") = "
+ + _uint::to_str(hm.get(i), 10u);
assert (hm.get(i) == i * i);
i += 1u;
}
i = 0u;
while (i < num_to_insert) {
- log "get(" + UInt.to_str(i, 10u) + ") = "
- + UInt.to_str(hm.get(i), 10u);
+ log "get(" + _uint::to_str(i, 10u) + ") = "
+ + _uint::to_str(hm.get(i), 10u);
assert (hm.get(i) == i * i);
i += 1u;
}
use std;
fn main() {
- auto x = std.Option.some[int](10);
+ auto x = std::option::some[int](10);
}
use std;
fn check_sort(vec[mutable int] v1, vec[mutable int] v2) {
- auto len = std.Vec.len[int](v1);
+ auto len = std::_vec::len[int](v1);
fn ltequal(&int a, &int b) -> bool {
ret a <= b;
}
auto f = ltequal;
- std.Sort.quick_sort[int](f, v1);
+ std::sort::quick_sort[int](f, v1);
auto i = 0u;
while (i < len) {
log v2.(i);
// -*- rust -*-
use std;
-import std.Rand;
+import std::rand;
fn main() {
- let Rand.rng r1 = Rand.mk_rng();
+ let rand::rng r1 = rand::mk_rng();
log r1.next();
log r1.next();
{
- auto r2 = Rand.mk_rng();
+ auto r2 = rand::mk_rng();
log r1.next();
log r2.next();
log r1.next();
use std;
-import std.SHA1;
-import std.Vec;
-import std.Str;
+import std::sha1;
+import std::_vec;
+import std::_str;
fn main() {
auto tests = fips_180_1_tests + wikipedia_tests;
fn check_vec_eq(vec[u8] v0, vec[u8] v1) {
- assert (Vec.len[u8](v0) == Vec.len[u8](v1));
- auto len = Vec.len[u8](v0);
+ 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);
}
// Test that it works when accepting the message all at once
- auto sh = SHA1.mk_sha1();
+ auto sh = sha1::mk_sha1();
for (test t in tests) {
sh.input_str(t.input);
auto out = sh.result();
// Test that it works when accepting the message in pieces
for (test t in tests) {
- auto len = Str.byte_len(t.input);
+ auto len = _str::byte_len(t.input);
auto left = len;
while (left > 0u) {
auto take = (left + 1u) / 2u;
- sh.input_str(Str.substr(t.input, len - left, take));
+ sh.input_str(_str::substr(t.input, len - left, take));
left = left - take;
}
auto out = sh.result();
use std;
fn check_sort(vec[int] v1, vec[int] v2) {
- auto len = std.Vec.len[int](v1);
+ 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 v3 = std::sort::merge_sort[int](f, v1);
auto i = 0u;
while (i < len) {
log v3.(i);
// -*- rust -*-
use std;
-import std.Str;
+import std::_str;
fn main() {
auto s = "hello";
- auto sb = Str.rustrt.str_buf(s);
- auto s_cstr = Str.rustrt.str_from_cstr(sb);
- assert (Str.eq(s_cstr, s));
- auto s_buf = Str.rustrt.str_from_buf(sb, 5u);
- assert (Str.eq(s_buf, s));
+ auto sb = str.rustrt.str_buf(s);
+ auto s_cstr = str.rustrt.str_from_cstr(sb);
+ assert (str.eq(s_cstr, s));
+ auto s_buf = str.rustrt.str_from_buf(sb, 5u);
+ assert (str.eq(s_buf, s));
}
// xfail-stage0
use std;
-import std.Str;
+import std::_str;
fn test_bytes_len() {
- assert (Str.byte_len("") == 0u);
- assert (Str.byte_len("hello world") == 11u);
- assert (Str.byte_len("\x63") == 1u);
- assert (Str.byte_len("\xa2") == 2u);
- assert (Str.byte_len("\u03c0") == 2u);
- assert (Str.byte_len("\u2620") == 3u);
- assert (Str.byte_len("\U0001d11e") == 4u);
+ assert (_str::byte_len("") == 0u);
+ assert (_str::byte_len("hello world") == 11u);
+ assert (_str::byte_len("\x63") == 1u);
+ assert (_str::byte_len("\xa2") == 2u);
+ assert (_str::byte_len("\u03c0") == 2u);
+ assert (_str::byte_len("\u2620") == 3u);
+ assert (_str::byte_len("\U0001d11e") == 4u);
}
fn test_index_and_rindex() {
- assert (Str.index("hello", 'e' as u8) == 1);
- assert (Str.index("hello", 'o' as u8) == 4);
- assert (Str.index("hello", 'z' as u8) == -1);
- assert (Str.rindex("hello", 'l' as u8) == 3);
- assert (Str.rindex("hello", 'h' as u8) == 0);
- assert (Str.rindex("hello", 'z' as u8) == -1);
+ assert (_str::index("hello", 'e' as u8) == 1);
+ assert (_str::index("hello", 'o' as u8) == 4);
+ assert (_str::index("hello", 'z' as u8) == -1);
+ assert (_str::rindex("hello", 'l' as u8) == 3);
+ assert (_str::rindex("hello", 'h' as u8) == 0);
+ assert (_str::rindex("hello", 'z' as u8) == -1);
}
fn test_split() {
fn t(&str s, char c, int i, &str k) {
log "splitting: " + s;
log i;
- auto v = Str.split(s, c as u8);
+ auto v = _str::split(s, c as u8);
log "split to: ";
for (str z in v) {
log z;
}
log "comparing: " + v.(i) + " vs. " + k;
- assert (Str.eq(v.(i), k));
+ assert (_str::eq(v.(i), k));
}
t("abc.hello.there", '.', 0, "abc");
t("abc.hello.there", '.', 1, "hello");
fn test_find() {
fn t(&str haystack, &str needle, int i) {
- let int j = Str.find(haystack,needle);
+ let int j = _str::find(haystack,needle);
log "searched for " + needle;
log j;
assert (i == j);
fn test_substr() {
fn t(&str a, &str b, int start) {
- assert (Str.eq(Str.substr(a, start as uint,
- Str.byte_len(b)), b));
+ assert (_str::eq(_str::substr(a, start as uint,
+ _str::byte_len(b)), b));
}
t("hello", "llo", 2);
fn test_concat() {
fn t(&vec[str] v, &str s) {
- assert (Str.eq(Str.concat(v), s));
+ assert (_str::eq(_str::concat(v), s));
}
t(vec("you", "know", "I'm", "no", "good"), "youknowI'mnogood");
fn test_connect() {
fn t(&vec[str] v, &str sep, &str s) {
- assert (Str.eq(Str.connect(v, sep), s));
+ assert (_str::eq(_str::connect(v, sep), s));
}
t(vec("you", "know", "I'm", "no", "good"), " ", "you know I'm no good");
auto unicode = "\u65e5\u672c";
auto input = "abcDEF" + unicode + "xyz:.;";
auto expected = "ABCDEF" + unicode + "XYZ:.;";
- auto actual = Str.to_upper(input);
- assert (Str.eq(expected, actual));
+ auto actual = _str::to_upper(input);
+ assert (_str::eq(expected, actual));
}
fn test_slice() {
- assert (Str.eq("ab", Str.slice("abc", 0u, 2u)));
- assert (Str.eq("bc", Str.slice("abc", 1u, 3u)));
- assert (Str.eq("", Str.slice("abc", 1u, 1u)));
+ assert (_str::eq("ab", _str::slice("abc", 0u, 2u)));
+ 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;
ret res;
}
- assert (Str.eq(half_a_million_letter_a(),
- Str.slice(a_million_letter_a(),
+ assert (_str::eq(half_a_million_letter_a(),
+ _str::slice(a_million_letter_a(),
0u,
500000u)));
}
use std;
-import std.Task;
+import std::_task;
fn main() {
- Task.sleep(1000000u);
+ _task::sleep(1000000u);
}
\ No newline at end of file
// -*- rust -*-
use std;
-import std.UInt;
+import std::_uint;
fn main() {
- assert (UInt.next_power_of_two(0u) == 0u);
- assert (UInt.next_power_of_two(1u) == 1u);
- assert (UInt.next_power_of_two(2u) == 2u);
- assert (UInt.next_power_of_two(3u) == 4u);
- assert (UInt.next_power_of_two(4u) == 4u);
- assert (UInt.next_power_of_two(5u) == 8u);
- assert (UInt.next_power_of_two(6u) == 8u);
- assert (UInt.next_power_of_two(7u) == 8u);
- assert (UInt.next_power_of_two(8u) == 8u);
- assert (UInt.next_power_of_two(9u) == 16u);
- assert (UInt.next_power_of_two(10u) == 16u);
- assert (UInt.next_power_of_two(11u) == 16u);
- assert (UInt.next_power_of_two(12u) == 16u);
- assert (UInt.next_power_of_two(13u) == 16u);
- assert (UInt.next_power_of_two(14u) == 16u);
- assert (UInt.next_power_of_two(15u) == 16u);
- assert (UInt.next_power_of_two(16u) == 16u);
- assert (UInt.next_power_of_two(17u) == 32u);
- assert (UInt.next_power_of_two(18u) == 32u);
- assert (UInt.next_power_of_two(19u) == 32u);
- assert (UInt.next_power_of_two(20u) == 32u);
- assert (UInt.next_power_of_two(21u) == 32u);
- assert (UInt.next_power_of_two(22u) == 32u);
- assert (UInt.next_power_of_two(23u) == 32u);
- assert (UInt.next_power_of_two(24u) == 32u);
- assert (UInt.next_power_of_two(25u) == 32u);
- assert (UInt.next_power_of_two(26u) == 32u);
- assert (UInt.next_power_of_two(27u) == 32u);
- assert (UInt.next_power_of_two(28u) == 32u);
- assert (UInt.next_power_of_two(29u) == 32u);
- assert (UInt.next_power_of_two(30u) == 32u);
- assert (UInt.next_power_of_two(31u) == 32u);
- assert (UInt.next_power_of_two(32u) == 32u);
- assert (UInt.next_power_of_two(33u) == 64u);
- assert (UInt.next_power_of_two(34u) == 64u);
- assert (UInt.next_power_of_two(35u) == 64u);
- assert (UInt.next_power_of_two(36u) == 64u);
- assert (UInt.next_power_of_two(37u) == 64u);
- assert (UInt.next_power_of_two(38u) == 64u);
- assert (UInt.next_power_of_two(39u) == 64u);
+ assert (_uint::next_power_of_two(0u) == 0u);
+ assert (_uint::next_power_of_two(1u) == 1u);
+ assert (_uint::next_power_of_two(2u) == 2u);
+ assert (_uint::next_power_of_two(3u) == 4u);
+ assert (_uint::next_power_of_two(4u) == 4u);
+ assert (_uint::next_power_of_two(5u) == 8u);
+ assert (_uint::next_power_of_two(6u) == 8u);
+ assert (_uint::next_power_of_two(7u) == 8u);
+ assert (_uint::next_power_of_two(8u) == 8u);
+ assert (_uint::next_power_of_two(9u) == 16u);
+ assert (_uint::next_power_of_two(10u) == 16u);
+ assert (_uint::next_power_of_two(11u) == 16u);
+ assert (_uint::next_power_of_two(12u) == 16u);
+ assert (_uint::next_power_of_two(13u) == 16u);
+ assert (_uint::next_power_of_two(14u) == 16u);
+ assert (_uint::next_power_of_two(15u) == 16u);
+ assert (_uint::next_power_of_two(16u) == 16u);
+ assert (_uint::next_power_of_two(17u) == 32u);
+ assert (_uint::next_power_of_two(18u) == 32u);
+ assert (_uint::next_power_of_two(19u) == 32u);
+ assert (_uint::next_power_of_two(20u) == 32u);
+ assert (_uint::next_power_of_two(21u) == 32u);
+ assert (_uint::next_power_of_two(22u) == 32u);
+ assert (_uint::next_power_of_two(23u) == 32u);
+ assert (_uint::next_power_of_two(24u) == 32u);
+ assert (_uint::next_power_of_two(25u) == 32u);
+ assert (_uint::next_power_of_two(26u) == 32u);
+ assert (_uint::next_power_of_two(27u) == 32u);
+ assert (_uint::next_power_of_two(28u) == 32u);
+ assert (_uint::next_power_of_two(29u) == 32u);
+ assert (_uint::next_power_of_two(30u) == 32u);
+ assert (_uint::next_power_of_two(31u) == 32u);
+ assert (_uint::next_power_of_two(32u) == 32u);
+ assert (_uint::next_power_of_two(33u) == 64u);
+ assert (_uint::next_power_of_two(34u) == 64u);
+ assert (_uint::next_power_of_two(35u) == 64u);
+ assert (_uint::next_power_of_two(36u) == 64u);
+ assert (_uint::next_power_of_two(37u) == 64u);
+ assert (_uint::next_power_of_two(38u) == 64u);
+ assert (_uint::next_power_of_two(39u) == 64u);
}
// -*- rust -*-
use std;
-import std.Str;
-import std.Vec;
+import std::_str;
+import std::_vec;
fn test_simple() {
let str s1 = "All mimsy were the borogoves";
* 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 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 uint n1 = _str::byte_len(s1);
+ let uint n2 = _vec::len[u8](v);
assert (n1 == n2);
}
log "refcnt is";
- log Str.refcount(s1);
+ log _str::refcount(s1);
}
fn main() {
use std;
fn test_init_elt() {
- let vec[uint] v = std.Vec.init_elt[uint](5u, 3u);
- assert (std.Vec.len[uint](v) == 3u);
+ let vec[uint] v = std::_vec::init_elt[uint](5u, 3u);
+ assert (std::_vec::len[uint](v) == 3u);
assert (v.(0) == 5u);
assert (v.(1) == 5u);
assert (v.(2) == 5u);
}
fn test_init_fn() {
let fn(uint)->uint op = id;
- let vec[uint] v = std.Vec.init_fn[uint](op, 5u);
- assert (std.Vec.len[uint](v) == 5u);
+ let vec[uint] v = std::_vec::init_fn[uint](op, 5u);
+ assert (std::_vec::len[uint](v) == 5u);
assert (v.(0) == 0u);
assert (v.(1) == 1u);
assert (v.(2) == 2u);
fn test_slice() {
let vec[int] v = vec(1,2,3,4,5);
- auto v2 = std.Vec.slice[int](v, 2u, 4u);
- assert (std.Vec.len[int](v2) == 2u);
+ auto v2 = std::_vec::slice[int](v, 2u, 4u);
+ assert (std::_vec::len[int](v2) == 2u);
assert (v2.(0) == 3);
assert (v2.(1) == 4);
}
fn test_map() {
fn square(&int x) -> int { ret x * x; }
- let std.Option.operator[int, int] op = square;
+ let std::option::operator[int, int] op = square;
let vec[int] v = vec(1, 2, 3, 4, 5);
- let vec[int] s = std.Vec.map[int, int](op, v);
+ let vec[int] s = std::_vec::map[int, int](op, v);
let int i = 0;
while (i < 5) {
assert (v.(i) * v.(i) == s.(i));
auto f = times;
auto v0 = vec(1, 2, 3, 4, 5);
auto v1 = vec(5, 4, 3, 2, 1);
- auto u = std.Vec.map2[int,int,int](f, v0, v1);
+ auto u = std::_vec::map2[int,int,int](f, v0, v1);
auto i = 0;
while (i < 5) {
let @cell first = @tup(mutable @nil());
let @cell second = @tup(mutable @link(first));
first._0 = @link(second);
- std.Sys.rustrt.gc();
+ std::sys.rustrt.gc();
let @cell third = @tup(mutable @nil());
}
grow(v);
grow(v);
grow(v);
- auto len = std.Vec.len[int](v);
+ auto len = std::_vec::len[int](v);
log len;
assert (len == (3 as uint));
}
}
native mod libc = "libc.dylib" {
- fn write(int fd, rustrt.vbuf buf, uint count) -> int;
+ fn write(int fd, rustrt::vbuf buf, uint count) -> int;
}
native "cdecl" mod baz {
// a bug was causing this to complain about leaked memory on exit
use std;
-import std.Option;
-import std.Option.some;
-import std.Option.none;
+import std::option;
+import std::option::some;
+import std::option::none;
tag t {
foo(int, uint);
- bar(int, Option.t[int]);
+ bar(int, option::t[int]);
}
fn nested(t o) {
}
fn main(vec[str] args) {
- foo.bar(0u);
+ foo::bar(0u);
}
use std;
-import std.Option;
-import std.UInt;
-import std.Vec;
+import std::option;
+import std::_uint;
+import std::_vec;
// A 12-byte unit to send over the channel
type record = rec(u32 val1, u32 val2, u32 val3);
let record val = rec(val1=0u32, val2=0u32, val3=0u32);
- for each (uint i in UInt.range(0u, 100u)) {
+ for each (uint i in _uint::range(0u, 100u)) {
mychan <| val;
}
}
let record val = rec(val1=0u32, val2=0u32, val3=0u32);
- for each (uint i in UInt.range(0u, 100u)) {
+ for each (uint i in _uint::range(0u, 100u)) {
mychan <| val;
}
- for each (uint i in UInt.range(0u, 100u)) {
+ for each (uint i in _uint::range(0u, 100u)) {
auto x <- myport;
}
}
let port[record] myport = port();
auto mychan = chan(myport);
- for each (uint i in UInt.range(0u, 100u)) {
+ 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 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)) {
+ 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);
mychan <| val;
}
- for each (uint i in UInt.range(0u, 10u)) {
+ for each (uint i in _uint::range(0u, 10u)) {
auto x <- myport;
assert (x.val1 == i as u32);
assert (x.val2 == i as u32);
// xfail-stage1
// xfail-stage2
fn main() {
- auto x = spawn m.child(10);
+ auto x = spawn m::child(10);
join x;
}
mod m {
// -*- rust -*-
use std;
-import std.Str;
+import std::_str;
fn test1() {
let str s = "hello";
log a;
log b;
- assert (Str.eq(a, "abcABCabc"));
- assert (Str.eq(b, "ABCabcABC"));
+ assert (_str::eq(a, "abcABCabc"));
+ assert (_str::eq(b, "ABCabcABC"));
}
fn main() {
// xfail-boot
use std;
-import std.Str;
+import std::_str;
fn test(str actual, str expected) {
log actual;
log expected;
- assert (Str.eq(actual, expected));
+ assert (_str::eq(actual, expected));
}
fn main() {
}
fn start() {
- log "Started / Finished Task.";
+ log "Started / Finished task.";
}
fn test00() {
// xfail-stage1
// xfail-stage2
use std;
-import std.Task;
+import std::_task;
fn main() -> () {
test00();
}
fn start(int task_number) {
- log "Started / Finished Task.";
+ log "Started / Finished task.";
}
fn test00() {
let task t = spawn thread "child" start(i);
// Sleep long enough for the task to finish.
- Task.sleep(10000u);
+ _task::sleep(10000u);
// Try joining tasks that have already finished.
join t;
- log "Joined Task.";
+ log "Joined task.";
}
\ No newline at end of file
// xfail-stage1
// xfail-stage2
use std;
-import std.Task;
+import std::_task;
fn start(chan[int] c, int start, int number_of_messages) {
let int i = 0;
let port[int] p = port();
let task a = spawn thread "start" start(chan(p), 0, 10);
join a;
- log "Joined Task";
+ log "Joined task";
}
\ No newline at end of file
// xfail-stage1
// xfail-stage2
use std;
-import std.Task;
+import std::_task;
fn start(chan[int] c, int start, int number_of_messages) {
let int i = 0;
let port[int] p = port();
let task a = spawn "start" start(chan(p), 0, 10);
join a;
- log "Joined Task";
+ log "Joined task";
}
\ No newline at end of file
}
fn test04_start() {
- log "Started Task";
+ log "Started task";
let int i = 1024 * 1024 * 64;
while (i > 0) {
i = i - 1;
}
- log "Finished Task";
+ log "Finished task";
}
fn test04() {
// xfail-stage1
// xfail-stage2
-import size_of = std.Sys.rustrt.size_of;
+import size_of = std::sys.rustrt.size_of;
use std;
}
fn main() {
- foo.x();
- bar.y();
+ foo::x();
+ bar::y();
}
use bar(name = "std", ver = "0.0.1");
// FIXME: commented out since resolve doesn't know how to handle crates yet.
-// import std.Str;
-// import x = std.Str;
+// import std::str;
+// import x = std::str;
mod baz {
use std;
use zed(name = "std");
use bar(name = "std", ver = "0.0.1");
- // import std.Str;
- // import x = std.Str;
+ // import std::str;
+ // import x = std::str;
}
fn main() {
uuid = _, ver = _);
fn main() {
- auto s = std.Str.alloc(10 as uint);
+ 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);
+ auto z = std::vec.alloc[int](10 as uint);
}
// xfail-stage1
// xfail-stage2
use std;
-import std.Str;
-import std.Vec;
-import std.IO;
+import std::_str;
+import std::_vec;
+import std::io;
fn main() {
// Chars of 1, 2, 3, and 4 bytes
let vec[char] chs = vec('e', 'é', '€', 0x10000 as char);
- let str s = Str.from_chars(chs);
+ let str s = _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(vec(0x80_u8)));
- assert (!Str.is_utf8(vec(0xc0_u8)));
- assert (!Str.is_utf8(vec(0xc0_u8, 0x10_u8)));
+ assert (_str::is_utf8(_str::bytes(s)));
+ assert (!_str::is_utf8(vec(0x80_u8)));
+ assert (!_str::is_utf8(vec(0xc0_u8)));
+ assert (!_str::is_utf8(vec(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"));
+ 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"));
}
use std;
fn slice[T](vec[T] e) {
- let vec[T] result = std.Vec.alloc[T](1 as uint);
+ let vec[T] result = std::vec.alloc[T](1 as uint);
log "alloced";
result += e;
log "appended";
// -*- rust -*-
use std;
-import std.Str;
-import std.Vec;
+import std::_str;
+import std::_vec;
-// FIXME: import std.Dbg.const_refcount. Currently
+// FIXME: import std::dbg::const_refcount. Currently
// cross-crate const references don't work.
const uint const_refcount = 0x7bad_face_u;
let vec[str] v = vec(mumble); // ref up: v, mumble
let acc a = acc(v); // ref up: a, v
- log Vec.refcount[str](v);
- assert (Vec.refcount[str](v) == 2u);
+ log _vec::refcount[str](v);
+ assert (_vec::refcount[str](v) == 2u);
a.add(s); // ref up: mumble, s. ref down: v
- log Vec.refcount[str](v);
- log Str.refcount(s);
- log Str.refcount(mumble);
+ log _vec::refcount[str](v);
+ log _str::refcount(s);
+ log _str::refcount(mumble);
- assert (Vec.refcount[str](v) == 1u);
- assert (Str.refcount(s) == const_refcount);
- assert (Str.refcount(mumble) == const_refcount);
+ assert (_vec::refcount[str](v) == 1u);
+ assert (_str::refcount(s) == const_refcount);
+ assert (_str::refcount(mumble) == const_refcount);
log v.(0);
- log Vec.len[str](v);
- assert (Str.eq(v.(0), mumble));
- assert (Vec.len[str](v) == 1u);
+ log _vec::len[str](v);
+ assert (_str::eq(v.(0), mumble));
+ assert (_vec::len[str](v) == 1u);
} // ref down: a, mumble, s, v
- log Str.refcount(s);
- log Str.refcount(mumble);
+ log _str::refcount(s);
+ log _str::refcount(mumble);
- assert (Str.refcount(s) == const_refcount);
- assert (Str.refcount(mumble) == const_refcount);
+ assert (_str::refcount(s) == const_refcount);
+ assert (_str::refcount(mumble) == const_refcount);
log mumble;
log ss;
fn slow_growth2() {
let str s = "hi"; // ref up: s
slow_growth2_helper(s);
- log Str.refcount(s);
- assert (Str.refcount(s) == const_refcount);
+ log _str::refcount(s);
+ assert (_str::refcount(s) == const_refcount);
}
fn main() {
use std;
-import std.Vec;
+import std::_vec;
fn main() {
auto v = vec(1, 2, 3);
- log_err Vec.refcount[int](v);
- log_err Vec.refcount[int](v);
- log_err Vec.refcount[int](v);
- assert (Vec.refcount[int](v) == 1u || Vec.refcount[int](v) == 2u);
- assert (Vec.refcount[int](v) == 1u || Vec.refcount[int](v) == 2u);
+ log_err _vec::refcount[int](v);
+ log_err _vec::refcount[int](v);
+ log_err _vec::refcount[int](v);
+ assert (_vec::refcount[int](v) == 1u || _vec::refcount[int](v) == 2u);
+ assert (_vec::refcount[int](v) == 1u || _vec::refcount[int](v) == 2u);
}