Downcase std modules again, move to :: for module dereferencing

This should be a snapshot transition.
This commit is contained in:
Marijn Haverbeke 2011-05-12 17:24:54 +02:00
parent b1d3364487
commit 3816e57fd2
168 changed files with 7643 additions and 7608 deletions

View file

@ -1,16 +1,16 @@
import driver.session;
import lib.llvm.llvm;
import middle.trans;
import std.Str;
import std.FS;
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 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;
@ -19,32 +19,32 @@ tag output_type {
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;
}
@ -64,29 +64,29 @@ mod Write {
// 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.
@ -99,13 +99,13 @@ mod Write {
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));
}
}
}
@ -118,13 +118,13 @@ mod Write {
// 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
@ -135,7 +135,7 @@ mod Write {
}
if (opts.verify) {
llvm.LLVMAddVerifierPass(pm.llpm);
llvm::LLVMAddVerifierPass(pm.llpm);
}
// TODO: Write .s if -c was specified and -save-temps was on.
@ -157,32 +157,32 @@ mod Write {
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();
}
}
}

View file

@ -2,7 +2,7 @@
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;
@ -97,7 +97,7 @@ fn native_glue_name(int n, native_glue_type ngt) -> str {
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 {

View file

@ -1,27 +1,27 @@
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,
@ -66,13 +66,13 @@ fn declare_upcalls(type_names tn, ModuleRef llmod) -> @upcalls {
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();

View file

@ -1,9 +1,9 @@
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;
@ -55,35 +55,35 @@ fn restore_callee_saves() -> vec[str] {
}
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)");
}
@ -157,7 +157,7 @@ fn rust_activate_glue() -> vec[str] {
* 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)")
/*
@ -209,13 +209,13 @@ fn rust_yield_glue() -> vec[str] {
+ 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; }
}
/*
@ -241,7 +241,7 @@ fn native_glue(int n_args, abi.native_glue_type ngt) -> vec[str] {
}
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, _);
@ -259,7 +259,7 @@ fn native_glue(int n_args, abi.native_glue_type ngt) -> vec[str] {
+ 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",
@ -278,21 +278,21 @@ fn decl_glue(int align, str prefix, str name, vec[str] insns) -> str {
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 "";
@ -306,51 +306,51 @@ fn get_module_asm() -> str {
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";

View file

@ -1,69 +1,68 @@
// -*- 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 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::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 std::getopts;
import std::getopts::optopt;
import std::getopts::optmulti;
import std::getopts::optflag;
import std::getopts::opt_present;
import back.Link.output_type;
import back::Link::output_type;
fn default_environment(session.session sess,
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;
@ -72,73 +71,74 @@ fn parse_input(session.session sess,
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
@ -164,46 +164,46 @@ options:
--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"),
@ -214,14 +214,14 @@ fn main(vec[str] args) {
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")) {
@ -239,16 +239,16 @@ fn main(vec[str] args) {
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");
@ -259,7 +259,7 @@ fn main(vec[str] args) {
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) {
@ -267,7 +267,7 @@ fn main(vec[str] args) {
case (some[str](?s)) { sysroot = s; }
}
let @session.options sopts =
let @session::options sopts =
@rec(shared = shared,
optimize = optimize,
debuginfo = debuginfo,
@ -280,21 +280,21 @@ fn main(vec[str] args) {
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;
}
@ -309,19 +309,19 @@ fn main(vec[str] args) {
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)) {

View file

@ -1,11 +1,11 @@
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;
@ -33,37 +33,38 @@ type options = rec(bool shared,
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;
@ -73,7 +74,7 @@ state obj session(ast.crate_num cnum,
ret opts;
}
fn get_targ_crate_num() -> ast.crate_num {
fn get_targ_crate_num() -> ast::crate_num {
ret cnum;
}
@ -88,10 +89,10 @@ state obj session(ast.crate_num 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;
}
@ -129,12 +130,12 @@ state obj session(ast.crate_num cnum,
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);
}
}

View file

@ -1,13 +1,13 @@
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;
@ -25,9 +25,9 @@ type ty_param = ident;
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 {
@ -96,8 +96,8 @@ tag crate_directive_ {
// 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);
@ -111,7 +111,7 @@ type meta_item_ = rec(ident name, str value);
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_];
@ -234,10 +234,10 @@ tag init_op {
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);
@ -261,16 +261,16 @@ type expr = spanned[expr_];
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);
@ -284,12 +284,12 @@ tag expr_ {
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 */
@ -328,7 +328,7 @@ tag ty_ {
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);
@ -365,14 +365,13 @@ type _fn = rec(fn_decl decl,
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);
@ -395,7 +394,7 @@ type variant = spanned[variant_];
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);
}
@ -428,16 +427,16 @@ fn item_ident(@item it) -> 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;

View file

@ -1,4 +1,4 @@
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
@ -24,18 +24,18 @@ fn new_filemap(str filename, uint start_pos) -> filemap {
}
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; }

View file

@ -1,56 +1,56 @@
// -*- 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 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 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);
@ -62,105 +62,105 @@ fn next(@pstate st) -> u8 {
}
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,
@ -169,19 +169,19 @@ fn parse_ty(@pstate st, str_def sd) -> ty.t {
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);
@ -197,20 +197,20 @@ fn parse_ty(@pstate st, str_def sd) -> ty.t {
}
}
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);
@ -245,13 +245,13 @@ fn parse_hex(@pstate st) -> uint {
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)));
@ -263,9 +263,9 @@ fn parse_ty_fn(@pstate st, str_def sd) -> tup(vec[ty.arg], ty.t) {
// 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;
}
@ -274,30 +274,31 @@ fn parse_def_id(vec[u8] buf) -> ast.def_id {
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 (_) {}
@ -308,127 +309,127 @@ fn lookup_hash(&EBML.doc d, fn(vec[u8]) -> bool eq_fn, uint hash)
// 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;
}
@ -441,10 +442,10 @@ fn load_crate(session.session sess,
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;
@ -455,23 +456,24 @@ fn fold_view_item_use(&env e, &span sp, &ast.ident ident,
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);
}
@ -497,15 +499,15 @@ fn kind_has_type_params(u8 kind_ch) -> bool {
// 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];
}
}
@ -516,31 +518,31 @@ fn lookup_def(session.session sess, int cnum, vec[ast.ident] path)
// 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);
@ -558,29 +560,29 @@ fn get_type(session.session sess, ty.ctxt tcx, ast.def_id def)
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);
}
}
@ -594,46 +596,46 @@ fn get_tag_variants(session.session sess, ty.ctxt tcx, ast.def_id def)
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));

View file

@ -1,20 +1,20 @@
import std.Vec;
import std.Str;
import std.Option;
import std.Option.some;
import std.Option.none;
import std.Map.hashmap;
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 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.
@ -33,7 +33,7 @@ type env = vec[tup(ident, val)];
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);
@ -90,9 +90,9 @@ fn val_as_str(val v) -> str {
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;
}
}
@ -100,11 +100,11 @@ fn lookup(session.session sess, env e, span sp, ident i) -> val {
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");
}
@ -112,24 +112,24 @@ fn eval_lit(ctx cx, span sp, @ast.lit lit) -> val {
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));
}
@ -141,11 +141,11 @@ fn eval_expr(ctx cx, env e, @ast.expr x) -> val {
}
}
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));
}
@ -155,53 +155,53 @@ fn eval_expr(ctx cx, env e, @ast.expr x) -> val {
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));
}
@ -217,7 +217,7 @@ fn eval_expr(ctx cx, env e, @ast.expr x) -> val {
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);
}
@ -225,7 +225,7 @@ fn val_eq(session.session sess, span sp, val av, val bv) -> bool {
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");
@ -234,12 +234,12 @@ fn val_eq(session.session sess, span sp, val av, val bv) -> bool {
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);
}
@ -247,10 +247,10 @@ fn eval_crate_directives(ctx cx,
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);
@ -261,14 +261,14 @@ fn eval_crate_directives_to_mod(ctx cx, env e,
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);
}
@ -282,13 +282,13 @@ fn eval_crate_directive_block(ctx cx,
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'");
@ -300,7 +300,7 @@ fn eval_crate_directive_expr(ctx cx,
}
alt (elopt) {
case (some[@ast.expr](?els)) {
case (some[@ast::expr](?els)) {
ret eval_crate_directive_expr(cx, e, els, prefix,
view_items, items);
}
@ -310,18 +310,18 @@ fn eval_crate_directive_expr(ctx cx,
}
}
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);
@ -335,7 +335,7 @@ fn eval_crate_directive_expr(ctx cx,
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);
}
@ -348,25 +348,25 @@ fn eval_crate_directive_expr(ctx cx,
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) {
@ -376,7 +376,7 @@ fn eval_crate_directive(ctx cx,
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);
@ -386,18 +386,18 @@ fn eval_crate_directive(ctx cx,
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) {
@ -407,23 +407,23 @@ fn eval_crate_directive(ctx cx,
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)) {}
}
}

View file

@ -4,47 +4,47 @@
* 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;
}
}
@ -54,14 +54,15 @@ fn expr_to_str(parser.parser p,
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);
}

View file

@ -1,56 +1,56 @@
/*
* 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 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::_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 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;
@ -62,16 +62,16 @@ fn expand_syntax_ext(parser p,
// 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;
}
}
@ -86,75 +86,75 @@ fn expr_to_str(@ast.expr expr) -> str {
// 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;
@ -166,18 +166,18 @@ fn pieces_to_expr(parser p, vec[piece] pieces, vec[@ast.expr] args)
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) {
@ -203,14 +203,14 @@ fn pieces_to_expr(parser p, vec[piece] pieces, vec[@ast.expr] args)
// 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");
@ -228,7 +228,7 @@ fn pieces_to_expr(parser p, vec[piece] pieces, vec[@ast.expr] args)
}
}
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)) {
@ -256,11 +256,11 @@ fn pieces_to_expr(parser p, vec[piece] pieces, vec[@ast.expr] args)
}
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),
@ -279,8 +279,8 @@ fn pieces_to_expr(parser p, vec[piece] pieces, vec[@ast.expr] args)
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);
@ -288,9 +288,9 @@ fn pieces_to_expr(parser p, vec[piece] pieces, vec[@ast.expr] args)
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)) {
@ -312,7 +312,7 @@ fn pieces_to_expr(parser p, vec[piece] pieces, vec[@ast.expr] args)
auto unsupported = "conversion not supported in #fmt string";
alt (cnv.param) {
case (Option.none[int]) {
case (option::none[int]) {
}
case (_) {
log_err unsupported;
@ -407,7 +407,7 @@ fn pieces_to_expr(parser p, vec[piece] pieces, vec[@ast.expr] args)
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";
@ -434,10 +434,10 @@ fn pieces_to_expr(parser p, vec[piece] pieces, vec[@ast.expr] args)
}
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";
@ -448,10 +448,10 @@ fn pieces_to_expr(parser p, vec[piece] pieces, vec[@ast.expr] args)
}
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";
@ -507,7 +507,7 @@ fn pieces_to_expr(parser p, vec[piece] pieces, vec[@ast.expr] args)
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;
}
@ -526,7 +526,7 @@ fn pieces_to_expr(parser p, vec[piece] pieces, vec[@ast.expr] args)
// TODO: Remove this debug logging
// log "dumping expanded ast:";
// log pretty.print_expr(tmp_expr);
// log pretty::print_expr(tmp_expr);
ret tmp_expr;
}

View file

@ -1,15 +1,15 @@
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;
@ -19,17 +19,17 @@ state type reader = state obj {
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,
@ -39,9 +39,9 @@ fn new_reader(session sess, IO.reader rdr,
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;
@ -56,13 +56,13 @@ fn new_reader(session sess, IO.reader rdr,
}
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;
}
@ -72,9 +72,9 @@ fn new_reader(session sess, IO.reader rdr,
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 {
@ -82,16 +82,16 @@ fn new_reader(session sess, IO.reader rdr,
}
}
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);
}
@ -99,7 +99,7 @@ fn new_reader(session sess, IO.reader rdr,
ret reserved;
}
fn get_filemap() -> codemap.filemap {
fn get_filemap() -> codemap::filemap {
ret fm;
}
@ -107,9 +107,9 @@ fn new_reader(session sess, IO.reader rdr,
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(),
@ -118,115 +118,115 @@ fn new_reader(session sess, IO.reader rdr,
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'
@ -362,20 +362,20 @@ fn digits_to_string(str s) -> int {
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 {
@ -395,7 +395,7 @@ fn scan_dec_digits(reader rdr) -> str {
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();
@ -404,7 +404,7 @@ fn scan_dec_digits(reader rdr) -> str {
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;
@ -453,9 +453,9 @@ fn scan_number(char c, reader rdr) -> token.token {
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);
}
}
@ -464,18 +464,18 @@ fn scan_number(char c, reader rdr) -> token.token {
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);
}
}
@ -483,17 +483,17 @@ fn scan_number(char c, reader rdr) -> token.token {
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();
@ -520,29 +520,29 @@ fn scan_number(char c, reader rdr) -> token.token {
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);
}
}
}
@ -583,25 +583,25 @@ fn scan_numeric_escape(reader rdr) -> char {
}
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();
@ -615,46 +615,46 @@ fn next_token(reader rdr) -> token.token {
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;
};
}
@ -663,9 +663,9 @@ fn next_token(reader rdr) -> token.token {
rdr.bump();
if (rdr.curr() == '=') {
rdr.bump();
ret token.EQEQ;
ret token::EQEQ;
} else {
ret token.EQ;
ret token::EQ;
}
}
@ -673,9 +673,9 @@ fn next_token(reader rdr) -> token.token {
rdr.bump();
if (rdr.curr() == '=') {
rdr.bump();
ret token.NE;
ret token::NE;
} else {
ret token.NOT;
ret token::NOT;
}
}
@ -684,21 +684,21 @@ fn next_token(reader rdr) -> token.token {
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;
}
}
}
@ -708,20 +708,20 @@ fn next_token(reader rdr) -> token.token {
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;
}
}
}
@ -756,7 +756,7 @@ fn next_token(reader rdr) -> token.token {
}
rdr.bump(); // advance curr to closing '
rdr.bump(); // advance curr past token
ret token.LIT_CHAR(c2);
ret token::LIT_CHAR(c2);
}
case ('"') {
@ -767,37 +767,37 @@ fn next_token(reader rdr) -> token.token {
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));
}
@ -809,22 +809,22 @@ fn next_token(reader rdr) -> token.token {
}
}
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);
}
}
@ -832,9 +832,9 @@ fn next_token(reader rdr) -> token.token {
if (rdr.next() == '&') {
rdr.bump();
rdr.bump();
ret token.ANDAND;
ret token::ANDAND;
} else {
ret binop(rdr, token.AND);
ret binop(rdr, token::AND);
}
}
@ -842,30 +842,30 @@ fn next_token(reader rdr) -> token.token {
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) {
@ -899,7 +899,7 @@ fn read_line_comment(reader rdr) -> cmnt {
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),
@ -916,7 +916,7 @@ fn read_block_comment(reader rdr) -> cmnt {
auto level = 1;
while (true) {
if (rdr.curr() == '\n') {
Vec.push[str](lines, val);
_vec::push[str](lines, val);
val = "";
consume_whitespace(rdr);
} else {
@ -924,13 +924,13 @@ fn read_block_comment(reader rdr) -> cmnt {
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()) {
@ -944,16 +944,16 @@ fn read_block_comment(reader rdr) -> cmnt {
}
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);

File diff suppressed because it is too large Load diff

View file

@ -1,9 +1,9 @@
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;
@ -191,7 +191,7 @@ fn binop_to_str(binop o) -> str {
}
}
fn to_str(lexer.reader r, token t) -> str {
fn to_str(lexer::reader r, token t) -> str {
alt (t) {
case (EQ) { ret "="; }
@ -299,10 +299,10 @@ fn to_str(lexer.reader r, token t) -> str {
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)) {
@ -317,8 +317,8 @@ fn to_str(lexer.reader r, token t) -> str {
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;
}
@ -332,7 +332,7 @@ fn to_str(lexer.reader r, token t) -> str {
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 */

View file

@ -1,29 +1,29 @@
import std.Vec;
import std.Str;
import std.Str.rustrt.sbuf;
import std.Vec.rustrt.vbuf;
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 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;
@ -717,7 +717,7 @@ native mod llvm = llvm_lib {
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;
@ -835,7 +835,7 @@ native mod llvm = llvm_lib {
/** 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. */
@ -868,7 +868,7 @@ native mod llvm = llvm_lib {
/** 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;
@ -895,46 +895,46 @@ obj builder(BuilderRef B, @mutable bool terminated) {
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,
@ -943,352 +943,352 @@ obj builder(BuilderRef B, @mutable bool terminated) {
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(""));
}
@ -1296,131 +1296,133 @@ obj builder(BuilderRef B, @mutable bool terminated) {
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));
@ -1447,7 +1449,7 @@ state obj type_names(std.Map.hashmap[TypeRef, str] type_names,
}
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;
@ -1457,9 +1459,9 @@ fn mk_type_names() -> type_names {
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);
}
@ -1478,7 +1480,7 @@ fn type_to_str_inner(type_names names,
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 {
@ -1497,7 +1499,7 @@ fn type_to_str_inner(type_names names,
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"; }
@ -1509,16 +1511,17 @@ fn type_to_str_inner(type_names names,
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);
@ -1527,10 +1530,10 @@ fn type_to_str_inner(type_names names,
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;
@ -1543,12 +1546,12 @@ fn type_to_str_inner(type_names names,
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"; }
@ -1564,52 +1567,52 @@ fn type_to_str_inner(type_names names,
/* 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));
}

View file

@ -1,73 +1,73 @@
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) {
@ -79,12 +79,12 @@ fn walk_expr(@env e, &@ast.expr x) {
}
}
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 (_) { }
@ -95,18 +95,18 @@ fn walk_block(@env e, &ast.block b) {
}
}
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:

File diff suppressed because it is too large Load diff

View file

@ -1,23 +1,23 @@
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 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 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 lib::llvm::llvm;
import lib::llvm::llvm::ValueRef;
import lib::llvm::False;
const uint tag_paths = 0x01u;
const uint tag_items = 0x02u;
@ -55,14 +55,14 @@ type ty_abbrev = rec(uint pos, uint len, str s);
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
);
@ -73,22 +73,22 @@ mod Encode {
}
}
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);
}
@ -103,7 +103,7 @@ mod Encode {
}
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 {
@ -121,8 +121,8 @@ mod Encode {
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);
}
@ -133,127 +133,127 @@ mod Encode {
}
}
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(']');
@ -263,338 +263,338 @@ mod Encode {
}
// 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;
}
@ -610,7 +610,7 @@ fn hash_def_num(&int def_num) -> uint {
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;
@ -619,7 +619,7 @@ fn hash_path(&str s) -> uint {
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);
}
@ -632,69 +632,69 @@ fn create_index[T](&vec[tup(T, uint)] index, fn(&T) -> uint hash_fn)
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.
@ -703,17 +703,17 @@ fn encode_metadata(&@trans.crate_ctxt cx, &@ast.crate crate)
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()));
}
//

View file

@ -1,26 +1,25 @@
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,
@ -34,53 +33,53 @@ import std.Vec;
// 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);
@ -94,8 +93,8 @@ tag namespace {
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](),
@ -111,47 +110,47 @@ fn resolve_crate(session sess, @ast.crate crate)
// 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 (_) {}
@ -160,7 +159,7 @@ fn map_crate(&@env e, &ast.crate c) {
}
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);
@ -171,7 +170,7 @@ fn resolve_imports(&env e) {
}
// 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,_,_,_,_),
@ -182,41 +181,41 @@ fn resolve_names(&@env e, &ast.crate c) -> @ast.crate {
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);
@ -232,16 +231,16 @@ fn lookup_import(&env e, def_id defid, namespace ns) -> Option.t[def] {
}
}
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) {
@ -270,7 +269,7 @@ fn resolve_import(&env e, &@ast.view_item it, &list[scope] sc) {
}
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");
}
@ -278,40 +277,40 @@ fn resolve_import(&env e, &@ast.view_item it, &list[scope] sc) {
}
}
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; }
}
}
@ -329,7 +328,7 @@ fn unresolved(&env e, &span sp, ident id, str kind) {
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) {
@ -341,7 +340,7 @@ fn lookup_path_strict(&env e, &list[scope] sc, &span sp, vec[ident] 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;
@ -361,34 +360,34 @@ fn lookup_in_scope_strict(&env e, list[scope] sc, &span sp, ident id,
}
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);
}
@ -399,7 +398,7 @@ fn lookup_in_scope(&env e, list[scope] sc, ident id, namespace ns)
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);
}
}
@ -408,9 +407,9 @@ fn lookup_in_scope(&env e, list[scope] sc, ident id, namespace 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));
}
}
}
@ -445,27 +444,27 @@ fn lookup_in_scope(&env e, list[scope] sc, ident id, namespace ns)
}
}
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; }
}
@ -475,12 +474,12 @@ fn lookup_in_pat(ident id, &ast.pat pat) -> Option.t[def] {
}
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];
@ -489,12 +488,12 @@ fn lookup_in_fn(ident id, &ast.fn_decl decl,
}
}
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];
@ -503,36 +502,36 @@ fn lookup_in_obj(ident id, &ast._obj ob, &vec[ast.ty_param] ty_params,
}
}
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; }
}
@ -547,29 +546,29 @@ fn lookup_in_block(ident id, &ast.block_ b, namespace ns)
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 (_) { }
}
@ -590,11 +589,11 @@ fn lookup_in_mod_strict(&env e, def m, &span sp, ident id,
}
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);
@ -603,40 +602,41 @@ fn lookup_in_mod(&env e, def m, ident id, namespace ns, dir dr)
}
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);
}
@ -645,10 +645,10 @@ fn lookup_in_regular_mod(&env e, def_id defid, ident id, namespace ns, dir dr)
}
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];
}
@ -659,26 +659,26 @@ fn lookup_in_regular_mod(&env e, def_id defid, ident id, namespace ns, dir dr)
}
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));
}
}
}
@ -690,48 +690,48 @@ fn lookup_in_native_mod(&env e, def_id defid, ident id, namespace ns)
// 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));
}
}
@ -740,24 +740,24 @@ fn index_mod(&ast._mod md) -> mod_index {
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));
}
}
@ -771,31 +771,31 @@ fn index_nmod(&ast.native_mod md) -> nmod_index {
// 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;
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,120 +1,120 @@
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);
}
}
@ -124,282 +124,282 @@ fn walk_item(&ast_visitor v, @ast.item i) {
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);
}
}
@ -408,16 +408,16 @@ fn walk_expr(&ast_visitor v, @ast.expr e) {
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 {

View file

@ -1,6 +1,6 @@
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;}
@ -19,7 +19,7 @@ type context = rec(contexttype tp, uint indent);
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,
@ -30,7 +30,7 @@ type ps = @rec(mutable vec[context] context,
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();
@ -57,12 +57,12 @@ fn write_spaces(ps p, uint i) {
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) {
@ -89,7 +89,7 @@ fn buffer_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);
@ -97,14 +97,14 @@ fn buffer_token(ps p, token tok) {
}
}
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);
}
}
@ -123,7 +123,7 @@ fn check_potential_brk(ps p) {
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) {
@ -154,10 +154,10 @@ fn start_scan(ps p, token tok, scantype tp) {
}
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);
@ -190,7 +190,7 @@ fn do_token(ps p, token tok) {
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);
@ -202,7 +202,7 @@ fn do_token(ps p, token tok) {
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) {
@ -247,8 +247,8 @@ fn token_size(token tok) -> uint {
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;}
}

File diff suppressed because it is too large Load diff

View file

@ -55,11 +55,11 @@ mod util {
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) {

View file

@ -1,23 +1,23 @@
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 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 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::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);
@ -56,150 +56,150 @@ fn ty_mach_to_str(ty_mach tm) -> str {
}
}
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 */ }
@ -207,40 +207,40 @@ fn stmt_to_str(&ast.stmt st) -> str {
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 */
}
}
@ -248,29 +248,29 @@ fn decl_lhs(@ast.decl d) -> ast.def_id {
}
}
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);
}

View file

@ -1,21 +1,21 @@
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" */
@ -29,7 +29,7 @@ type pre_and_post_state = rec(prestate prestate, poststate poststate);
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 {
@ -45,7 +45,7 @@ fn empty_poststate(uint num_vars) -> poststate {
}
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 {
@ -72,15 +72,15 @@ fn get_post(&pre_and_post p) -> postcond {
}
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 {
@ -91,62 +91,62 @@ 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;
}
@ -164,16 +164,16 @@ fn pp_clone(&pre_and_post p) -> pre_and_post {
}
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);
}
//

View file

@ -1,9 +0,0 @@
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));
}
}

View file

@ -29,9 +29,9 @@ fn to_str(int n, uint radix) -> str
{
assert (0u < radix && radix <= 16u);
if (n < 0) {
ret "-" + UInt.to_str((-n) as uint, radix);
ret "-" + _uint::to_str((-n) as uint, radix);
} else {
ret UInt.to_str(n as uint, radix);
ret _uint::to_str(n as uint, radix);
}
}

View file

@ -1,6 +1,6 @@
import rustrt.sbuf;
import rustrt::sbuf;
import Vec.rustrt.vbuf;
import _vec::rustrt::vbuf;
native "rust" mod rustrt {
type sbuf;
@ -84,7 +84,7 @@ const uint tag_six_b = 0xfc_u;
fn is_utf8(vec[u8] v) -> bool {
auto i = 0u;
auto total = Vec.len[u8](v);
auto total = _vec::len[u8](v);
while (i < total) {
auto chsize = utf8_char_width(v.(i));
if (chsize == 0u) {ret false;}
@ -111,7 +111,7 @@ fn is_ascii(str s) -> bool {
}
fn alloc(uint n_bytes) -> str {
ret rustrt.str_alloc(n_bytes);
ret rustrt::str_alloc(n_bytes);
}
// Returns the number of bytes (a.k.a. UTF-8 code units) in s.
@ -120,67 +120,67 @@ fn alloc(uint n_bytes) -> str {
// 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);
ret rustrt::str_byte_len(s);
}
fn buf(str s) -> sbuf {
ret rustrt.str_buf(s);
ret rustrt::str_buf(s);
}
fn bytes(str s) -> vec[u8] {
ret rustrt.str_vec(s);
ret rustrt::str_vec(s);
}
fn from_bytes(vec[u8] v) : is_utf8(v) -> str {
ret rustrt.str_from_vec(v);
ret rustrt::str_from_vec(v);
}
// FIXME temp thing
fn unsafe_from_bytes(vec[mutable? u8] v) -> str {
ret rustrt.str_from_vec(v);
ret rustrt::str_from_vec(v);
}
fn unsafe_from_byte(u8 u) -> str {
ret rustrt.str_from_vec(vec(u));
ret rustrt::str_from_vec(vec(u));
}
fn str_from_cstr(sbuf cstr) -> str {
ret rustrt.str_from_cstr(cstr);
ret rustrt::str_from_cstr(cstr);
}
fn str_from_buf(sbuf buf, uint len) -> str {
ret rustrt.str_from_buf(buf, len);
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);
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);
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);
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);
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);
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);
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);
}
}
@ -253,7 +253,7 @@ fn to_chars(str s) -> vec[char] {
auto len = byte_len(s);
while (i < len) {
auto cur = char_range_at(s, i);
Vec.push[char](buf, cur._0);
_vec::push[char](buf, cur._0);
i = cur._1;
}
ret buf;
@ -287,8 +287,8 @@ fn unshift_char(&mutable str s, char ch) {
}
fn refcount(str s) -> uint {
auto r = rustrt.refcount[u8](s);
if (r == Dbg.const_refcount) {
auto r = rustrt::refcount[u8](s);
if (r == dbg::const_refcount) {
ret r;
} else {
// -1 because calling this function incremented the refcount.
@ -311,7 +311,7 @@ fn index(str s, u8 c) -> int {
}
fn rindex(str s, u8 c) -> int {
let int n = Str.byte_len(s) as int;
let int n = _str::byte_len(s) as int;
while (n >= 0) {
if (s.(n) == c) {
ret n;
@ -387,8 +387,8 @@ fn substr(str s, uint begin, uint len) -> str {
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);
assert (end <= _str::byte_len(s));
ret rustrt::str_slice(s, begin, end);
}
fn shift_byte(&mutable str s) -> u8 {
@ -408,7 +408,7 @@ fn pop_byte(&mutable str s) -> u8 {
}
fn push_byte(&mutable str s, u8 b) {
s = rustrt.str_push_byte(s, b as uint);
s = rustrt::str_push_byte(s, b as uint);
}
fn unshift_byte(&mutable str s, u8 b) {
@ -432,7 +432,7 @@ fn split(str s, u8 sep) -> vec[str] {
ends_with_sep = false;
}
}
if (Str.byte_len(accum) != 0u ||
if (_str::byte_len(accum) != 0u ||
ends_with_sep) {
v += vec(accum);
}

View file

@ -8,7 +8,7 @@ native "rust" mod rustrt {
* 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);
ret rustrt::task_sleep(time_in_us);
}
// Local Variables:

View file

@ -23,7 +23,7 @@ iter range(uint lo, uint hi) -> uint {
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 halfbits = sys::rustrt::size_of[uint]() * 4u;
let uint tmp = n - 1u;
let uint shift = 1u;
while (shift <= halfbits) {
@ -34,12 +34,12 @@ fn next_power_of_two(uint n) -> uint {
}
fn parse_buf(vec[u8] buf, uint radix) -> uint {
if (Vec.len[u8](buf) == 0u) {
if (_vec::len[u8](buf) == 0u) {
log_err "parse_buf(): buf is empty";
fail;
}
auto i = Vec.len[u8](buf) - 1u;
auto i = _vec::len[u8](buf) - 1u;
auto power = 1u;
auto n = 0u;
while (true) {
@ -83,15 +83,15 @@ fn to_str(uint num, uint radix) -> str
let str s = "";
while (n != 0u) {
s += Str.unsafe_from_byte(digit(n % radix) as u8);
s += _str::unsafe_from_byte(digit(n % radix) as u8);
n /= radix;
}
let str s1 = "";
let uint len = Str.byte_len(s);
let uint len = _str::byte_len(s);
while (len != 0u) {
len -= 1u;
s1 += Str.unsafe_from_byte(s.(len));
s1 += _str::unsafe_from_byte(s.(len));
}
ret s1;

View file

@ -1,8 +1,8 @@
import Option.none;
import Option.some;
import Util.orb;
import option::none;
import option::some;
import util::orb;
type vbuf = rustrt.vbuf;
type vbuf = rustrt::vbuf;
type operator2[T,U,V] = fn(&T, &U) -> V;
@ -38,16 +38,16 @@ native "rust" mod rustrt {
}
fn alloc[T](uint n_elts) -> vec[T] {
ret rustrt.vec_alloc[vec[T], T](n_elts);
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);
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) {
auto r = rustrt::refcount[T](v);
if (r == dbg::const_refcount) {
ret r;
} else {
// -1 because calling this function incremented the refcount.
@ -56,7 +56,7 @@ fn refcount[T](array[T] v) -> uint {
}
fn vec_from_vbuf[T](vbuf v, uint n_elts) -> vec[T] {
ret rustrt.vec_from_vbuf[T](v, n_elts);
ret rustrt::vec_from_vbuf[T](v, n_elts);
}
// FIXME: Remove me; this is a botch to get around rustboot's bad typechecker.
@ -119,28 +119,28 @@ fn init_elt_mut[T](&T t, uint n_elts) -> vec[mutable T] {
}
fn buf[T](array[T] v) -> vbuf {
ret rustrt.vec_buf[T](v, 0u);
ret rustrt::vec_buf[T](v, 0u);
}
fn len[T](array[T] v) -> uint {
ret rustrt.vec_len[T](v);
ret rustrt::vec_len[T](v);
}
fn len_set[T](array[T] v, uint n) {
rustrt.vec_len_set[T](v, 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);
ret rustrt::vec_buf[T](v, offset);
}
fn print_debug_info[T](array[T] v) {
rustrt.vec_print_debug_info[T](v);
rustrt::vec_print_debug_info[T](v);
}
// Returns the last element of v.
fn last[T](array[T] v) -> Option.t[T] {
fn last[T](array[T] v) -> option::t[T] {
auto l = len[T](v);
if (l == 0u) {
ret none[T];
@ -199,14 +199,14 @@ fn grow[T](&array[T] v, uint n, &T initval) {
}
fn grow_set[T](&vec[mutable T] v, uint index, &T initval, &T val) {
auto length = Vec.len(v);
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] {
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));
@ -230,7 +230,7 @@ fn map2[T,U,V](&operator2[T,U,V] f, &array[T] v0, &array[U] v1) -> vec[V] {
ret u;
}
fn find[T](fn (&T) -> bool f, &array[T] v) -> Option.t[T] {
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);
@ -270,24 +270,24 @@ fn unzip[T, U](&vec[tup(T, U)] v) -> tup(vec[T], vec[U]) {
fn or(&vec[bool] v) -> bool {
auto f = orb;
ret Vec.foldl[bool, bool](f, false, v);
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) -> () {
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] {
fn cat_options[T](&vec[option::t[T]] v) -> vec[T] {
let vec[T] res = vec();
for (Option.t[T] o in v) {
for (option::t[T] o in v) {
alt (o) {
case (none[T]) { }
case (some[T](?t)) {

View file

@ -21,19 +21,19 @@ fn create(uint nbits, bool init) -> t {
elt = 0u;
}
auto storage = Vec.init_elt_mut[uint](elt, nbits / uint_bits() + 1u);
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);
auto len = _vec::len(v1.storage);
assert (Vec.len(v0.storage) == len);
assert (_vec::len(v0.storage) == len);
assert (v0.nbits == v1.nbits);
auto changed = false;
for each (uint i in UInt.range(0u, len)) {
for each (uint i in _uint::range(0u, len)) {
auto w0 = v0.storage.(i);
auto w1 = v1.storage.(i);
@ -75,9 +75,9 @@ fn copy(&t v0, t v1) -> bool {
}
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)) {
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);
@ -97,7 +97,7 @@ fn get(&t v, uint i) -> bool {
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 len = _vec::len(v1.storage);
auto i = 0u;
while (i < len) {
if (v0.storage.(i) != v1.storage.(i)) {
@ -109,13 +109,13 @@ fn equal(&t v0, &t v1) -> bool {
}
fn clear(&t v) {
for each (uint i in UInt.range(0u, Vec.len(v.storage))) {
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))) {
for each (uint i in _uint::range(0u, _vec::len(v.storage))) {
v.storage.(i) = ~v.storage.(i);
}
}
@ -176,13 +176,13 @@ fn init_to_vec(t v, uint i) -> uint {
fn to_vec(&t v) -> vec[uint] {
auto sub = bind init_to_vec(v, _);
ret Vec.init_fn[uint](sub, v.nbits);
ret _vec::init_fn[uint](sub, v.nbits);
}
fn to_str(&t v) -> str {
auto res = "";
for (uint i in BitV.to_vec(v)) {
for (uint i in bitv::to_vec(v)) {
if (i == 1u) {
res += "1";
}
@ -196,7 +196,7 @@ fn to_str(&t v) -> str {
// 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));
assert (v0.nbits == _vec::len[uint](v1));
auto len = v0.nbits;
auto i = 0u;
while (i < len) {

View file

@ -4,5 +4,5 @@ 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; }
fn ptr_eq[T](@T a, @T b) -> bool { ret rustrt::rust_ptr_eq[T](a, b) != 0; }

View file

@ -20,23 +20,23 @@ native "rust" mod rustrt {
}
fn debug_vec[T](vec[T] v) {
Vec.print_debug_info[T](v);
_vec::print_debug_info[T](v);
}
fn debug_tydesc[T]() {
rustrt.debug_tydesc[T]();
rustrt::debug_tydesc[T]();
}
fn debug_opaque[T](&T x) {
rustrt.debug_opaque[T](x);
rustrt::debug_opaque[T](x);
}
fn debug_box[T](@T x) {
rustrt.debug_box[T](x);
rustrt::debug_box[T](x);
}
fn debug_tag[T](&T x) {
rustrt.debug_tag[T](x);
rustrt::debug_tag[T](x);
}
/**
@ -49,19 +49,19 @@ fn debug_tag[T](&T x) {
* 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);
rustrt::debug_obj[T](x, nmethods, nbytes);
}
fn debug_fn[T](&T x) {
rustrt.debug_fn[T](x);
rustrt::debug_fn[T](x);
}
fn ptr_cast[T, U](@T x) -> @U {
ret rustrt.debug_ptrcast[T, U](x);
ret rustrt::debug_ptrcast[T, U](x);
}
fn trap(str s) {
rustrt.debug_trap(s);
rustrt::debug_trap(s);
}
// Local Variables:

View file

@ -19,7 +19,7 @@ type t[T] = obj {
fn create[T]() -> t[T] {
type cell[T] = Option.t[T];
type cell[T] = option::t[T];
let uint initial_capacity = 32u; // 2^5
@ -28,25 +28,25 @@ fn create[T]() -> t[T] {
* elsewhere.
*/
fn grow[T](uint nelts, uint lo, vec[cell[T]] elts) -> vec[cell[T]] {
assert (nelts == Vec.len[cell[T]](elts));
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];
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);
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 (option::some[T](?t)) { ret t; }
case (_) { fail; }
}
fail; // FIXME: remove me when exhaustiveness checking works
@ -63,18 +63,18 @@ fn create[T]() -> t[T] {
let uint oldlo = lo;
if (lo == 0u) {
lo = Vec.len[cell[T]](elts) - 1u;
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;
lo = _vec::len[cell[T]](elts) - 1u;
hi = nelts;
}
elts.(lo) = Option.some[T](t);
elts.(lo) = option::some[T](t);
nelts += 1u;
}
@ -85,8 +85,8 @@ fn create[T]() -> t[T] {
hi = nelts;
}
elts.(hi) = Option.some[T](t);
hi = (hi + 1u) % Vec.len[cell[T]](elts);
elts.(hi) = option::some[T](t);
hi = (hi + 1u) % _vec::len[cell[T]](elts);
nelts += 1u;
}
@ -96,21 +96,21 @@ fn create[T]() -> t[T] {
*/
fn pop_front() -> T {
let T t = get[T](elts, lo);
elts.(lo) = Option.none[T];
lo = (lo + 1u) % Vec.len[cell[T]](elts);
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;
hi = _vec::len[cell[T]](elts) - 1u;
} else {
hi -= 1u;
}
let T t = get[T](elts, hi);
elts.(hi) = Option.none[T];
elts.(hi) = option::none[T];
nelts -= 1u;
ret t;
}
@ -124,12 +124,12 @@ fn create[T]() -> t[T] {
}
fn get(int i) -> T {
let uint idx = (lo + (i as uint)) % Vec.len[cell[T]](elts);
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],
let vec[cell[T]] v = _vec::init_elt[cell[T]](option::none[T],
initial_capacity);
ret deque[T](0u, 0u, 0u, v);

View file

@ -1,9 +1,9 @@
// Simple Extensible Binary Markup Language (EBML) reader and writer on a
// 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;
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);
@ -11,7 +11,7 @@ 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
// ebml reading
type doc = rec(vec[u8] data,
uint start,
@ -38,7 +38,7 @@ fn vint_at(vec[u8] data, uint start) -> tup(uint, uint) {
}
fn new_doc(vec[u8] data) -> doc {
ret rec(data=data, start=0u, end=Vec.len[u8](data));
ret rec(data=data, start=0u, end=_vec::len[u8](data));
}
fn doc_at(vec[u8] data, uint start) -> doc {
@ -48,7 +48,7 @@ fn doc_at(vec[u8] data, uint start) -> doc {
ret rec(data=data, start=elt_size._1, end=end);
}
fn maybe_get_doc(doc d, uint tg) -> Option.t[doc] {
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);
@ -65,7 +65,7 @@ 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);
log_err "failed to find block with tag " + _uint::to_str(tg, 10u);
fail;
}
}
@ -94,7 +94,7 @@ iter tagged_docs(doc d, uint tg) -> doc {
}
fn doc_data(doc d) -> vec[u8] {
ret Vec.slice[u8](d.data, d.start, d.end);
ret _vec::slice[u8](d.data, d.start, d.end);
}
fn be_uint_from_bytes(vec[u8] data, uint start, uint size) -> uint {
@ -114,11 +114,11 @@ fn doc_as_uint(doc d) -> uint {
ret be_uint_from_bytes(d.data, d.start, d.end - d.start);
}
// EBML writing
// ebml writing
type writer = rec(IO.buf_writer writer, mutable vec[uint] size_positions);
type writer = rec(io::buf_writer writer, mutable vec[uint] size_positions);
fn write_sized_vint(&IO.buf_writer w, uint n, uint size) {
fn write_sized_vint(&io::buf_writer w, uint n, uint size) {
let vec[u8] buf;
alt (size) {
case (1u) {
@ -148,7 +148,7 @@ fn write_sized_vint(&IO.buf_writer w, uint n, uint size) {
w.write(buf);
}
fn write_vint(&IO.buf_writer w, uint n) {
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; }
@ -157,15 +157,15 @@ fn write_vint(&IO.buf_writer w, uint n) {
fail;
}
fn create_writer(&IO.buf_writer w) -> writer {
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.
// TODO: Provide a function to write the standard ebml header.
fn start_tag(&writer w, uint tag_id) {
// Write the tag ID.
// Write the tag ID:
write_vint(w.writer, tag_id);
// Write a placeholder four-byte size.
@ -175,11 +175,11 @@ fn start_tag(&writer w, uint tag_id) {
}
fn end_tag(&writer w) {
auto last_size_pos = Vec.pop[uint](w.size_positions);
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);
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);
w.writer.seek(cur_pos as int, io::seek_set);
}
// TODO: optionally perform "relaxations" on end_tag to more efficiently

View file

@ -13,8 +13,8 @@
* combinations at the moment.
*/
import Option.none;
import Option.some;
import option::none;
import option::some;
/*
* We have a CT (compile-time) module that parses format strings into a
@ -66,7 +66,7 @@ mod CT {
}
// A formatted conversion from an expression to a string
type conv = rec(Option.t[int] param,
type conv = rec(option::t[int] param,
vec[flag] flags,
count width,
count precision,
@ -80,11 +80,11 @@ mod CT {
fn parse_fmt_string(str s) -> vec[piece] {
let vec[piece] pieces = vec();
auto lim = Str.byte_len(s);
auto lim = _str::byte_len(s);
auto buf = "";
fn flush_buf(str buf, &vec[piece] pieces) -> str {
if (Str.byte_len(buf) > 0u) {
if (_str::byte_len(buf) > 0u) {
auto piece = piece_string(buf);
pieces += vec(piece);
}
@ -93,15 +93,15 @@ mod CT {
auto i = 0u;
while (i < lim) {
auto curr = Str.substr(s, i, 1u);
if (Str.eq(curr, "%")) {
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, "%")) {
auto curr2 = _str::substr(s, i, 1u);
if (_str::eq(curr2, "%")) {
i += 1u;
} else {
buf = flush_buf(buf, pieces);
@ -118,14 +118,14 @@ mod CT {
ret pieces;
}
fn peek_num(str s, uint i, uint lim) -> Option.t[tup(uint, uint)] {
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)];
ret option::none[tup(uint, uint)];
}
auto n = (c - ('0' as u8)) as uint;
@ -156,7 +156,7 @@ mod CT {
ty._1);
}
fn parse_parameter(str s, uint i, uint lim) -> tup(Option.t[int], uint) {
fn parse_parameter(str s, uint i, uint lim) -> tup(option::t[int], uint) {
if (i >= lim) {
ret tup(none[int], i);
}
@ -270,27 +270,27 @@ mod CT {
}
auto t;
auto tstr = Str.substr(s, i, 1u);
if (Str.eq(tstr, "b")) {
auto tstr = _str::substr(s, i, 1u);
if (_str::eq(tstr, "b")) {
t = ty_bool;
} else if (Str.eq(tstr, "s")) {
} else if (_str::eq(tstr, "s")) {
t = ty_str;
} else if (Str.eq(tstr, "c")) {
} else if (_str::eq(tstr, "c")) {
t = ty_char;
} else if (Str.eq(tstr, "d")
|| Str.eq(tstr, "i")) {
} 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")) {
} else if (_str::eq(tstr, "u")) {
t = ty_int(unsigned);
} else if (Str.eq(tstr, "x")) {
} else if (_str::eq(tstr, "x")) {
t = ty_hex(case_lower);
} else if (Str.eq(tstr, "X")) {
} else if (_str::eq(tstr, "X")) {
t = ty_hex(case_upper);
} else if (Str.eq(tstr, "t")) {
} else if (_str::eq(tstr, "t")) {
t = ty_bits;
} else if (Str.eq(tstr, "o")) {
} else if (_str::eq(tstr, "o")) {
t = ty_octal;
} else {
log_err "unknown type in conversion";
@ -315,7 +315,7 @@ mod RT {
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
// comments in front::extfmt::make_flags
flag_none;
}
@ -364,7 +364,7 @@ mod RT {
res = uint_to_str_prec(u, 16u, prec);
}
case (ty_hex_upper) {
res = Str.to_upper(uint_to_str_prec(u, 16u, prec));
res = _str::to_upper(uint_to_str_prec(u, 16u, prec));
}
case (ty_bits) {
res = uint_to_str_prec(u, 2u, prec);
@ -383,13 +383,13 @@ mod RT {
} else {
s = "false";
}
// Run the boolean conversion through the string conversion logic,
// 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);
ret pad(cv, _str::from_char(c), pad_nozero);
}
fn conv_str(&conv cv, str s) -> str {
@ -399,9 +399,9 @@ mod RT {
}
case (count_is(?max)) {
// For strings, precision is the maximum characters displayed
if (max as uint < Str.char_len(s)) {
if (max as uint < _str::char_len(s)) {
// FIXME: substr works on bytes, not chars!
unpadded = Str.substr(s, 0u, max as uint);
unpadded = _str::substr(s, 0u, max as uint);
}
}
}
@ -420,15 +420,15 @@ mod RT {
// 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.
// 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);
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);
@ -450,12 +450,12 @@ mod RT {
}
}
// FIXME: This might be useful in Str. but needs to be utf8 safe first
// 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);
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);
ret _str::unsafe_from_bytes(svec);
}
tag pad_mode {
@ -476,7 +476,7 @@ mod RT {
}
}
auto strlen = Str.char_len(s);
auto strlen = _str::char_len(s);
if (uwidth <= strlen) {
ret s;
}
@ -532,16 +532,16 @@ mod RT {
// instead.
if (signed
&& zero_padding
&& Str.byte_len(s) > 0u) {
&& _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);
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;
}
}

View file

@ -3,43 +3,43 @@ native "rust" mod rustrt {
}
fn path_sep() -> str {
ret Str.from_char(OS_FS.path_sep);
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);
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);
i = _str::rindex(p, os_fs::alt_path_sep as u8);
if (i == -1) {
ret p;
}
}
ret Str.substr(p, 0u, i as uint);
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 '/'?
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;
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) {
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);
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;

9
src/lib/generic_os.rs Normal file
View file

@ -0,0 +1,9 @@
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));
}
}

View file

@ -7,8 +7,8 @@
* argument values out of the match object.
*/
import Option.some;
import Option.none;
import option::some;
import option::none;
tag name { long(str); short(char); }
tag hasarg { yes; no; maybe; }
@ -17,7 +17,7 @@ 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)); }
if (_str::char_len(nm) == 1u) { ret short(_str::char_at(nm, 0u)); }
else { ret long(nm); }
}
fn reqopt(str name) -> opt {
@ -41,11 +41,11 @@ tag optval {
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;
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 (short(?ch)) {ret _str::from_char(ch);}
case (long(?s)) {ret s;}
}
}
@ -55,16 +55,16 @@ fn name_eq(name a, name b) -> bool {
alt (a) {
case (long(?a)) {
alt (b) {
case (long(?b)) { ret Str.eq(a, 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] {
fn find_opt(vec[opt] opts, name nm) -> option::t[uint] {
auto i = 0u;
auto l = Vec.len[opt](opts);
auto l = _vec::len[opt](opts);
while (i < l) {
if (name_eq(opts.(i).name, nm)) { ret some[uint](i); }
i += 1u;
@ -91,7 +91,7 @@ fn fail_str(fail_ f) -> str {
ret "Required option '" + nm + "' missing.";
}
case (option_duplicated(?nm)) {
ret "Option '" + nm + "' given more than once.";
ret "option '" + nm + "' given more than once.";
}
}
}
@ -102,41 +102,41 @@ tag result {
}
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 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);
auto vals = _vec::init_fn_mut[vec[optval]](f, n_opts);
let vec[str] free = vec();
auto l = Vec.len[str](args);
auto l = _vec::len[str](args);
auto i = 0u;
while (i < l) {
auto cur = args.(i);
auto curlen = Str.byte_len(cur);
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);
_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];
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);
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));
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));
auto range = _str::char_range_at(cur, j);
_vec::push[name](names, short(range._0));
j = range._1;
}
}
@ -152,29 +152,29 @@ fn getopts(vec[str] args, vec[opt] opts) -> result {
}
alt (opts.(optid).hasarg) {
case (no) {
Vec.push[optval](vals.(optid), given);
_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) ||
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);
_vec::push[optval](vals.(optid), given);
} else {
i += 1u;
Vec.push[optval](vals.(optid), val(args.(i)));
_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)));
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)));
_vec::push[optval](vals.(optid), val(args.(i)));
}
}
}
@ -185,7 +185,7 @@ fn getopts(vec[str] args, vec[opt] opts) -> result {
i = 0u;
while (i < n_opts) {
auto n = Vec.len[optval](vals.(i));
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)));
@ -212,7 +212,7 @@ 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;
ret _vec::len[optval](opt_vals(m, nm)) > 0u;
}
fn opt_str(match m, str nm) -> str {
alt (opt_val(m, nm)) {
@ -224,15 +224,15 @@ 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 (val(?s)) { _vec::push[str](acc, s); }
case (_) {}
}
}
ret acc;
}
fn opt_maybe_str(match m, str nm) -> Option.t[str] {
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]; }
if (_vec::len[optval](vals) == 0u) { ret none[str]; }
alt (vals.(0)) {
case (val(?s)) { ret some[str](s); }
case (_) { ret none[str]; }

View file

@ -1,8 +1,8 @@
import OS.libc;
import os::libc;
native "rust" mod rustrt {
fn rust_get_stdin() -> OS.libc.FILE;
fn rust_get_stdout() -> OS.libc.FILE;
fn rust_get_stdin() -> os::libc::FILE;
fn rust_get_stdout() -> os::libc::FILE;
}
// Reading
@ -55,30 +55,30 @@ fn convert_whence(seek_style whence) -> int {
}
}
state obj FILE_buf_reader(OS.libc.FILE f, bool must_close) {
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);
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);
ret os::libc::fgetc(f);
}
fn unread_byte(int byte) {
OS.libc.ungetc(byte, f);
os::libc::ungetc(byte, f);
}
fn eof() -> bool {
ret OS.libc.feof(f) != 0;
ret os::libc::feof(f) != 0;
}
fn seek(int offset, seek_style whence) {
assert (OS.libc.fseek(f, offset, convert_whence(whence)) == 0);
assert (os::libc::fseek(f, offset, convert_whence(whence)) == 0);
}
fn tell() -> uint {
ret OS.libc.ftell(f) as uint;
ret os::libc::ftell(f) as uint;
}
drop {
if (must_close) { OS.libc.fclose(f); }
if (must_close) { os::libc::fclose(f); }
}
}
@ -100,7 +100,7 @@ state obj new_reader(buf_reader rdr) {
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);
auto w = _str::utf8_char_width(b0);
assert (w > 0u);
if (w == 1u) {ret b0 as char;}
auto val = 0u;
@ -112,7 +112,7 @@ state obj new_reader(buf_reader rdr) {
val <<= 6u;
val += (next & 0x3f) as uint;
}
// See Str.char_at
// See _str::char_at
val += ((b0 << ((w + 1u) as u8)) as uint) << ((w - 1u) * 6u - w - 1u);
ret val as char;
}
@ -126,9 +126,9 @@ state obj new_reader(buf_reader rdr) {
while (go_on) {
auto ch = rdr.read_byte();
if (ch == -1 || ch == 10) {go_on = false;}
else {Vec.push[u8](buf, ch as u8);}
else {_vec::push[u8](buf, ch as u8);}
}
ret Str.unsafe_from_bytes(buf);
ret _str::unsafe_from_bytes(buf);
}
fn read_c_str() -> str {
let vec[u8] buf = vec();
@ -136,9 +136,9 @@ state obj new_reader(buf_reader rdr) {
while (go_on) {
auto ch = rdr.read_byte();
if (ch < 1) {go_on = false;}
else {Vec.push[u8](buf, ch as u8);}
else {_vec::push[u8](buf, ch as u8);}
}
ret Str.unsafe_from_bytes(buf);
ret _str::unsafe_from_bytes(buf);
}
// FIXME deal with eof?
fn read_le_uint(uint size) -> uint {
@ -164,7 +164,7 @@ state obj new_reader(buf_reader rdr) {
// FIXME deal with eof?
fn read_be_uint(uint size) -> uint {
auto val = 0u;
auto sz = size; // FIXME: trans.ml bug workaround
auto sz = size; // FIXME: trans::ml bug workaround
while (sz > 0u) {
sz -= 1u;
val += (rdr.read_byte() as uint) << (sz * 8u);
@ -187,11 +187,11 @@ state obj new_reader(buf_reader rdr) {
}
fn stdin() -> reader {
ret new_reader(FILE_buf_reader(rustrt.rust_get_stdin(), false));
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"));
auto f = os::libc::fopen(_str::buf(path), _str::buf("r"));
if (f as uint == 0u) {
log_err "error opening " + path;
fail;
@ -212,17 +212,17 @@ 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 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);
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;}
if (bbuf.pos == _vec::len[u8](bbuf.buf)) {ret -1;}
auto b = bbuf.buf.(bbuf.pos);
bbuf.pos += 1u;
ret b as int;
@ -234,12 +234,12 @@ state obj byte_buf_reader(byte_buf bbuf) {
}
fn eof() -> bool {
ret bbuf.pos == Vec.len[u8](bbuf.buf);
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);
auto len = _vec::len[u8](bbuf.buf);
bbuf.pos = seek_in_buf(offset, pos, len, whence);
}
@ -268,40 +268,40 @@ type buf_writer = state obj {
fn tell() -> uint; // FIXME: eventually u64
};
state obj FILE_writer(OS.libc.FILE f, bool must_close) {
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);
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);
assert (os::libc::fseek(f, offset, convert_whence(whence)) == 0);
}
fn tell() -> uint {
ret OS.libc.ftell(f) as uint;
ret os::libc::ftell(f) as uint;
}
drop {
if (must_close) {OS.libc.fclose(f);}
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 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);
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();
log_err sys::rustrt::last_os_error();
fail;
}
count += nout as uint;
@ -319,32 +319,32 @@ state obj fd_buf_writer(int fd, bool must_close) {
}
drop {
if (must_close) {OS.libc.close(fd);}
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();
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 (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),
auto fd = os::libc::open(_str::buf(path),
fflags,
OS.libc_constants.S_IRUSR() |
OS.libc_constants.S_IWUSR());
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();
log_err sys::rustrt::last_os_error();
fail;
}
ret fd_buf_writer(fd, true);
@ -390,17 +390,17 @@ state obj new_writer(buf_writer out) {
ret out;
}
fn write_str(str s) {
out.write(Str.bytes(s));
out.write(_str::bytes(s));
}
fn write_char(char ch) {
// FIXME needlessly consy
out.write(Str.bytes(Str.from_char(ch)));
out.write(_str::bytes(_str::from_char(ch)));
}
fn write_int(int n) {
out.write(Str.bytes(Int.to_str(n, 10u)));
out.write(_str::bytes(_int::to_str(n, 10u)));
}
fn write_uint(uint n) {
out.write(Str.bytes(UInt.to_str(n, 10u)));
out.write(_str::bytes(_uint::to_str(n, 10u)));
}
fn write_bytes(vec[u8] bytes) {
out.write(bytes);
@ -427,7 +427,7 @@ fn file_writer(str path, vec[fileflag] flags) -> writer {
// FIXME: fileflags
fn buffered_file_buf_writer(str path) -> buf_writer {
auto f = OS.libc.fopen(Str.buf(path), Str.buf("w"));
auto f = os::libc::fopen(_str::buf(path), _str::buf("w"));
if (f as uint == 0u) {
log_err "error opening " + path;
fail;
@ -451,21 +451,21 @@ 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)) {
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);
auto mv = _vec::rustrt::unsafe_vec_to_mut[u8](v);
buf.buf += mv;
buf.pos += Vec.len[u8](v);
buf.pos += _vec::len[u8](v);
ret;
}
// FIXME: Optimize. These should be unique pointers.
auto vlen = Vec.len[u8](v);
// 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)) {
if (buf.pos == _vec::len(buf.buf)) {
buf.buf += vec(mutable b);
} else {
buf.buf.(buf.pos) = b;
@ -477,7 +477,7 @@ state obj byte_buf_writer(mutable_byte_buf buf) {
fn seek(int offset, seek_style whence) {
auto pos = buf.pos;
auto len = Vec.len(buf.buf);
auto len = _vec::len(buf.buf);
buf.pos = seek_in_buf(offset, pos, len, whence);
}
@ -487,12 +487,12 @@ state obj byte_buf_writer(mutable_byte_buf buf) {
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);
_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);}
fn get_str() -> str {ret _str::unsafe_from_bytes(buf.buf);}
}
ret str_writer_wrap(new_writer(byte_buf_writer(buf)), buf);
}

View file

@ -1,10 +1,10 @@
import Str.sbuf;
import Vec.vbuf;
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" {
native mod libc = "libc::so.6" {
fn open(sbuf s, int flags, uint mode) -> int;
fn read(int fd, vbuf buf, uint count) -> int;
@ -66,17 +66,17 @@ fn dylib_filename(str base) -> str {
fn pipe() -> tup(int, int) {
let vec[mutable int] fds = vec(mutable 0, 0);
assert (OS.libc.pipe(Vec.buf(fds)) == 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 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);
assert (os::libc::waitpid(pid, _vec::buf(status), 0) != -1);
ret status.(0);
}

View file

@ -1,5 +1,5 @@
import Option.some;
import Option.none;
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
@ -27,7 +27,7 @@ fn foldl[T,U](&list[T] ls, &U u, fn(&T t, &U u) -> U f) -> U {
}
fn find[T,U](&list[T] ls,
(fn(&T) -> Option.t[U]) f) -> Option.t[U] {
(fn(&T) -> option::t[U]) f) -> option::t[U] {
alt(ls) {
case (cons[T](?hd, ?tl)) {
alt (f(hd)) {

View file

@ -1,7 +1,7 @@
import Str.sbuf;
import Vec.vbuf;
import _str::sbuf;
import _vec::vbuf;
native mod libc = "libc.dylib" {
native mod libc = "libc::dylib" {
fn open(sbuf s, int flags, uint mode) -> int;
fn read(int fd, vbuf buf, uint count) -> int;
@ -63,17 +63,17 @@ fn dylib_filename(str base) -> str {
fn pipe() -> tup(int, int) {
let vec[mutable int] fds = vec(mutable 0, 0);
assert (OS.libc.pipe(Vec.buf(fds)) == 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 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);
assert (os::libc::waitpid(pid, _vec::buf(status), 0) != -1);
ret status.(0);
}

View file

@ -11,8 +11,8 @@ state type hashmap[K, V] = state obj {
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 find(&K key) -> option::t[V];
fn remove(&K key) -> option::t[V];
fn rehash();
iter items() -> @tup(K,V);
};
@ -20,7 +20,7 @@ state type hashmap[K, V] = state obj {
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);
let util::rational load_factor = rec(num=3, den=4);
tag bucket[K, V] {
nil;
@ -29,7 +29,7 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[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);
ret _vec::init_elt_mut[bucket[K, V]](nil[K, V], nbkts);
}
// Derive two hash functions from the one given by taking the upper
@ -96,7 +96,7 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
vec[mutable bucket[K, V]] bkts,
uint nbkts,
&K key)
-> Option.t[V]
-> option::t[V]
{
let uint i = 0u;
let uint h = hasher(key);
@ -105,17 +105,17 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
alt (bkts.(j)) {
case (some[K, V](?k, ?v)) {
if (eqer(key, k)) {
ret Option.some[V](v);
ret option::some[V](v);
}
}
case (nil[K, V]) {
ret Option.none[V];
ret option::none[V];
}
case (deleted[K, V]) { }
}
i += 1u;
}
ret Option.none[V];
ret option::none[V];
}
@ -140,15 +140,15 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
mutable vec[mutable bucket[K, V]] bkts,
mutable uint nbkts,
mutable uint nelts,
Util.rational lf)
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,
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);
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,
@ -167,7 +167,7 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
fn contains_key(&K key) -> bool {
alt (find_common[K, V](hasher, eqer, bkts, nbkts, key)) {
case (Option.some[V](_)) { ret true; }
case (option::some[V](_)) { ret true; }
case (_) { ret false; }
}
fail; // FIXME: remove me when exhaustiveness checking works
@ -175,19 +175,19 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
fn get(&K key) -> V {
alt (find_common[K, V](hasher, eqer, bkts, nbkts, key)) {
case (Option.some[V](?val)) { ret val; }
case (option::some[V](?val)) { ret val; }
case (_) { fail; }
}
fail; // FIXME: remove me when exhaustiveness checking works
}
fn find(&K key) -> Option.t[V] {
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] {
fn remove(&K key) -> option::t[V] {
let uint i = 0u;
let uint h = hasher(key);
while (i < nbkts) {
@ -197,17 +197,17 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
if (eqer(key, k)) {
bkts.(j) = deleted[K, V];
nelts -= 1u;
ret Option.some[V](v);
ret option::some[V](v);
}
}
case (deleted[K, V]) { }
case (nil[K, V]) {
ret Option.none[V];
ret option::none[V];
}
}
i += 1u;
}
ret Option.none[V];
ret option::none[V];
}
fn rehash() {

View file

@ -1,4 +1,4 @@
// lib/Option.rs
// lib/option::rs
tag t[T] {
none;
@ -39,7 +39,7 @@ fn is_none[T](&t[T] opt) -> bool {
}
fn from_maybe[T](&T def, &t[T] opt) -> T {
auto f = bind Util.id[T](_);
auto f = bind util::id[T](_);
ret maybe[T, T](def, f, opt);
}

View file

@ -1,21 +1,21 @@
native "rust" mod rustrt {
fn rust_dirent_filename(OS.libc.dirent ent) -> str;
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));
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);
auto ent = os::libc::readdir(dir);
if (ent as int == 0) {
OS.libc.closedir(dir);
os::libc::closedir(dir);
ret result;
}
Vec.push[str](result, rustrt.rust_dirent_filename(ent));
_vec::push[str](result, rustrt::rust_dirent_filename(ent));
}
OS.libc.closedir(dir);
os::libc::closedir(dir);
ret result;
}

View file

@ -12,16 +12,16 @@ native "rust" mod rustrt {
type rng = obj { fn next() -> u32; };
fn mk_rng() -> rng {
obj rt_rng(rustrt.rctx c) {
obj rt_rng(rustrt::rctx c) {
fn next() -> u32 {
ret rustrt.rand_next(c);
ret rustrt::rand_next(c);
}
drop {
rustrt.rand_free(c);
rustrt::rand_free(c);
}
}
ret rt_rng(rustrt.rand_new());
ret rt_rng(rustrt::rand_new());
}
// Local Variables:

View file

@ -1,74 +1,74 @@
import Str.sbuf;
import Vec.vbuf;
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));
auto argptrs = vec(_str::buf(prog));
for (str arg in args) {
Vec.push[sbuf](argptrs, Str.buf(arg));
_vec::push[sbuf](argptrs, _str::buf(arg));
}
Vec.push[sbuf](argptrs, 0 as sbuf);
_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)),
auto pid = rustrt::rust_run_program(_vec::buf[sbuf](argvec(prog, args)),
0, 0, 0);
ret OS.waitpid(pid);
ret os::waitpid(pid);
}
type program =
state obj {
fn get_id() -> int;
fn input() -> IO.writer;
fn output() -> IO.reader;
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)),
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);
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,
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 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 output() -> io::reader {
ret io::new_reader(io::FILE_buf_reader(out_file, false));
}
fn close_input() {
OS.libc.close(in_fd);
os::libc::close(in_fd);
}
fn finish() -> int {
if (finished) {ret 0;}
finished = true;
OS.libc.close(in_fd);
ret OS.waitpid(pid);
os::libc::close(in_fd);
ret os::waitpid(pid);
}
drop {
if (!finished) {
OS.libc.close(in_fd);
OS.waitpid(pid);
os::libc::close(in_fd);
os::waitpid(pid);
}
OS.libc.fclose(out_file);
os::libc::fclose(out_file);
}
}
ret @new_program(pid, pipe_input._1,
OS.fd_FILE(pipe_output._0),
os::fd_FILE(pipe_output._0),
false);
}
@ -80,7 +80,7 @@ fn program_output(str prog, vec[str] args)
auto buf = "";
while (!out.eof()) {
auto bytes = out.read_bytes(4096u);
buf += Str.unsafe_from_bytes(bytes);
buf += _str::unsafe_from_bytes(bytes);
}
ret rec(status=pr.finish(), out=buf);
}

View file

@ -74,8 +74,8 @@ fn mk_sha1() -> sha1 {
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);
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;
@ -196,7 +196,7 @@ fn mk_sha1() -> sha1 {
*/
fn pad_msg(&sha1state st) {
// FIXME: Should be a precondition
assert (Vec.len(st.msg_block) == msg_block_len);
assert (_vec::len(st.msg_block) == msg_block_len);
/*
* Check to see if the current message block is too small to hold
@ -240,7 +240,7 @@ fn mk_sha1() -> sha1 {
fn reset() {
// FIXME: Should be typestate precondition
assert (Vec.len(st.h) == digest_buf_len);
assert (_vec::len(st.h) == digest_buf_len);
st.len_low = 0u32;
st.len_high = 0u32;
@ -260,7 +260,7 @@ fn mk_sha1() -> sha1 {
}
fn input_str(&str msg) {
add_input(st, Str.bytes(msg));
add_input(st, _str::bytes(msg));
}
fn result() -> vec[u8] {
@ -271,19 +271,19 @@ fn mk_sha1() -> sha1 {
auto r = mk_result(st);
auto s = "";
for (u8 b in r) {
s += UInt.to_str(b as uint, 16u);
s += _uint::to_str(b as uint, 16u);
}
ret s;
}
}
auto st = rec(h = Vec.init_elt_mut[u32](0u32, digest_buf_len),
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),
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));
work_buf = _vec::init_elt_mut[u32](0u32, work_buf_len));
auto sh = sha1(st);
sh.reset();
ret sh;

View file

@ -1,5 +1,5 @@
import Vec.len;
import Vec.slice;
import _vec::len;
import _vec::slice;
type lteq[T] = fn(&T a, &T b) -> bool;

View file

@ -6,76 +6,76 @@ meta (name = "std",
// 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;

View file

@ -21,20 +21,20 @@ const u8 color_bright_magenta = 13u8;
const u8 color_bright_cyan = 14u8;
const u8 color_bright_white = 15u8;
fn esc(IO.buf_writer writer) {
fn esc(io::buf_writer writer) {
writer.write(vec(0x1bu8, '[' as u8));
}
fn reset(IO.buf_writer writer) {
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");
ret generic_os::getenv("TERM") == option::some[str]("xterm-color");
}
fn set_color(IO.buf_writer writer, u8 first_char, u8 color) {
fn set_color(io::buf_writer writer, u8 first_char, u8 color) {
assert (color < 16u8);
esc(writer);
@ -45,11 +45,11 @@ fn set_color(IO.buf_writer writer, u8 first_char, u8 color) {
writer.write(vec(first_char, ('0' as u8) + color, 'm' as u8));
}
fn fg(IO.buf_writer writer, u8 color) {
fn fg(io::buf_writer writer, u8 color) {
ret set_color(writer, '3' as u8, color);
}
fn bg(IO.buf_writer writer, u8 color) {
fn bg(io::buf_writer writer, u8 color) {
ret set_color(writer, '4' as u8, color);
}

View file

@ -6,7 +6,7 @@ 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);
rustrt::get_time(res.sec, res.usec);
ret res;
}

View file

@ -1,19 +1,19 @@
import Option.none;
import Option.some;
import option::none;
import option::some;
// A very naive implementation of union-find with unsigned integer nodes.
type node = Option.t[uint];
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
_vec::pop(v); // FIXME: botch
ret rec(mutable nodes=v);
}
fn make_set(&ufind ufnd) -> uint {
auto idx = Vec.len(ufnd.nodes);
auto idx = _vec::len(ufnd.nodes);
ufnd.nodes += vec(mutable none[uint]);
ret idx;
}

View file

@ -4,10 +4,10 @@ fn id[T](&T x) -> T {
/* 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);
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.
// NB: Uses the fact that rationals have positive denominators WLOG:
ret x.num * y.den <= y.num * x.den;
}

View file

@ -4,7 +4,7 @@ native "rust" mod rustrt {
}
fn list_dir(str path) -> vec[str] {
ret rustrt.rust_list_files(path+"*");
ret rustrt::rust_list_files(path+"*");
}
/* FIXME: win32 path handling actually accepts '/' or '\' and has subtly

View file

@ -1,5 +1,5 @@
import Str.sbuf;
import Vec.vbuf;
import _str::sbuf;
import _vec::vbuf;
native mod libc = "msvcrt.dll" {
fn open(sbuf s, int flags, uint mode) -> int = "_open";
@ -53,13 +53,13 @@ fn dylib_filename(str base) -> str {
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);
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"));
fn fd_FILE(int fd) -> libc::FILE {
ret libc::_fdopen(fd, _str::buf("r"));
}
native "rust" mod rustrt {
@ -67,7 +67,7 @@ native "rust" mod rustrt {
}
fn waitpid(int pid) -> int {
ret rustrt.rust_process_wait(pid);
ret rustrt::rust_process_wait(pid);
}
// Local Variables:

View file

@ -1,10 +1,10 @@
/* -*- 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.";
@ -32,15 +32,15 @@ case (1) {
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;
}

View file

@ -1,10 +1,10 @@
/* -*- 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);}
@ -25,8 +25,8 @@ fn show(bottle b) {
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.";

View file

@ -1,10 +1,10 @@
/* -*- 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.";
@ -31,15 +31,15 @@ case (1) {
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;
}

View file

@ -1,15 +1,15 @@
/* -*- 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.";

View file

@ -1,6 +1,6 @@
use std;
import std.Int;
import std::_int;
tag tree {
nil;
@ -49,7 +49,7 @@ fn main() {
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;

View file

@ -2,8 +2,8 @@
use std;
import std.Int;
import std.Vec;
import std::_int;
import std::_vec;
fn fannkuch(int n) -> int {
@ -12,9 +12,9 @@ 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;

View file

@ -7,10 +7,10 @@
* 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;
@ -54,21 +54,21 @@ fn select_random(u32 r, vec[aminoacids] genelist) -> char {
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);
}
}
@ -76,16 +76,16 @@ fn make_random_fasta(str id, str desc, vec[aminoacids] genelist, int n) {
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);
}
}

View file

@ -19,33 +19,33 @@ fn main() {
// 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;
@ -61,12 +61,12 @@ mod NBodySystem {
}
// 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) {
@ -86,14 +86,14 @@ mod NBodySystem {
}
}
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;
@ -105,13 +105,13 @@ mod NBodySystem {
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;
@ -131,7 +131,7 @@ mod NBodySystem {
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;
@ -158,7 +158,7 @@ mod Body {
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,
@ -170,7 +170,7 @@ mod Body {
);
}
fn saturn() -> Body.props {
fn saturn() -> Body::props {
ret rec(
mutable x = 8.34336671824457987e+00,
mutable y = 4.12479856412430479e+00,
@ -182,7 +182,7 @@ mod Body {
);
}
fn uranus() -> Body.props {
fn uranus() -> Body::props {
ret rec(
mutable x = 1.28943695621391310e+01,
mutable y = -1.51111514016986312e+01,
@ -194,7 +194,7 @@ mod Body {
);
}
fn neptune() -> Body.props {
fn neptune() -> Body::props {
ret rec(
mutable x = 1.53796971148509165e+01,
mutable y = -2.59193146099879641e+01,
@ -206,7 +206,7 @@ mod Body {
);
}
fn sun() -> Body.props {
fn sun() -> Body::props {
ret rec(
mutable x = 0.0,
mutable y = 0.0,
@ -218,7 +218,7 @@ mod Body {
);
}
fn offsetMomentum(&Body.props props,
fn offsetMomentum(&Body::props props,
float px,
float py,
float pz) -> () {

View file

@ -5,5 +5,5 @@ mod m1 {
}
fn main(vec[str] args) {
log m1.a;
log m1::a;
}

View file

@ -1,4 +1,4 @@
// error-pattern: can't refer to a module as a first-class value
// error-pattern: is a module, not a
mod m1 {
mod a {
@ -6,5 +6,5 @@ mod m1 {
}
fn main(vec[str] args) {
log m1.a;
log m1::a;
}

View file

@ -1,5 +1,5 @@
// xfail-boot
// error-pattern:Unsatisfied precondition
// error-pattern::Unsatisfied precondition
fn foo() -> int {
let int x;

View file

@ -1,5 +1,5 @@
// xfail-boot
// error-pattern:Unsatisfied precondition
// error-pattern::Unsatisfied precondition
fn foo() -> int {
let int x;

View file

@ -17,5 +17,5 @@ mod foo {
}
fn main() {
foo.z(10);
foo::z(10);
}

View file

@ -10,7 +10,7 @@ mod foo {
export bar;
fn bar() {
foo.baz();
foo::baz();
}
fn baz() {

View file

@ -2,7 +2,7 @@
// xfail-stage0
// error-pattern: unresolved import
import m.unexported;
import m::unexported;
mod m {
export exported;

View file

@ -13,5 +13,5 @@ mod foo {
}
fn main() {
auto x = foo.t1;
auto x = foo::t1;
}

View file

@ -13,5 +13,5 @@ mod foo {
}
fn main() {
auto z = foo.y1;
auto z = foo::y1;
}

View file

@ -11,5 +11,5 @@ mod foo {
}
fn main() {
foo.z(10);
foo::z(10);
}

View file

@ -5,7 +5,7 @@ mod foo {
export x;
fn x() {
bar.x();
bar::x();
}
}
@ -21,5 +21,5 @@ mod bar {
}
fn main() {
foo.x();
foo::x();
}

View file

@ -1,11 +1,11 @@
// 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;

View file

@ -1,4 +1,4 @@
// error-pattern:cyclic import
// error-pattern::cyclic import
import x;

View file

@ -1,8 +1,8 @@
// 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";

View file

@ -1,6 +1,6 @@
// xfail-boot
// error-pattern: unresolved name
import baz.zed.bar;
import baz::zed::bar;
mod baz {
}
mod zed {

View file

@ -1,6 +1,6 @@
// xfail-boot
// error-pattern: main is not a module or crate
import main.bar;
import main::bar;
fn main(vec[str] args) {
log "foo";

View file

@ -1,8 +1,8 @@
// 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";

View file

@ -1,5 +1,5 @@
// -*- rust -*-
// error-pattern:9:2
// error-pattern::9:2
/* 1
* 2

View file

@ -1,4 +1,4 @@
// error-pattern:reserved keyword
// error-pattern::reserved keyword
fn main() {
let int dec = 0;

View file

@ -1,4 +1,4 @@
// error-pattern:reserved keyword
// error-pattern::reserved keyword
fn main() {
let int f128 = 0;

View file

@ -1,4 +1,4 @@
// error-pattern:reserved keyword
// error-pattern::reserved keyword
fn main() {
let int f16 = 0;

View file

@ -1,4 +1,4 @@
// error-pattern:reserved keyword
// error-pattern::reserved keyword
fn main() {
let int f80 = 0;

View file

@ -1,4 +1,4 @@
// error-pattern:reserved keyword
// error-pattern::reserved keyword
fn main() {
let int m128 = 0;

View file

@ -1,4 +1,4 @@
// error-pattern:reserved keyword
// error-pattern::reserved keyword
fn main() {
let int m32 = 0;

View file

@ -1,4 +1,4 @@
// error-pattern:reserved keyword
// error-pattern::reserved keyword
fn main() {
let int m64 = 0;

View file

@ -1,5 +1,5 @@
// xfail-boot
// error-pattern:expecting ., found (
// error-pattern::expecting ., found (
fn main() {
obj foo() {

View file

@ -1,4 +1,4 @@
// error-pattern:Unsatisfied precondition
// error-pattern::Unsatisfied precondition
fn foo(int x) {
log x;

Some files were not shown because too many files have changed in this diff Show more