Merge branch 'master' of github.com:graydon/rust
This commit is contained in:
commit
28f9af6074
@ -108,6 +108,30 @@ fn time<T>(do_it: bool, what: str, thunk: fn@() -> T) -> T {
|
|||||||
ret rv;
|
ret rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn inject_libcore_reference(sess: session::session,
|
||||||
|
crate: @ast::crate) -> @ast::crate {
|
||||||
|
|
||||||
|
fn spanned<copy T>(x: T) -> @ast::spanned<T> {
|
||||||
|
ret @{node: x,
|
||||||
|
span: {lo: 0u, hi: 0u,
|
||||||
|
expanded_from: codemap::os_none}};
|
||||||
|
}
|
||||||
|
|
||||||
|
let n1 = sess.next_node_id();
|
||||||
|
let n2 = sess.next_node_id();
|
||||||
|
|
||||||
|
let vi1 = spanned(ast::view_item_use("core", [], n1));
|
||||||
|
let vi2 = spanned(ast::view_item_import_glob(@["core"], n2));
|
||||||
|
|
||||||
|
let cd1 = spanned(ast::cdir_view_item(vi1));
|
||||||
|
let cd2 = spanned(ast::cdir_view_item(vi2));
|
||||||
|
|
||||||
|
let cdirs = [cd1, cd2] + crate.node.directives;
|
||||||
|
|
||||||
|
ret @{node: {directives: cdirs with crate.node} with *crate }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
|
fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
|
||||||
output: str) {
|
output: str) {
|
||||||
let time_passes = sess.get_opts().time_passes;
|
let time_passes = sess.get_opts().time_passes;
|
||||||
@ -126,6 +150,10 @@ fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
|
|||||||
time(time_passes, "expansion",
|
time(time_passes, "expansion",
|
||||||
bind syntax::ext::expand::expand_crate(sess, crate));
|
bind syntax::ext::expand::expand_crate(sess, crate));
|
||||||
|
|
||||||
|
if sess.get_opts().libcore {
|
||||||
|
crate = inject_libcore_reference(sess, crate);
|
||||||
|
}
|
||||||
|
|
||||||
let ast_map =
|
let ast_map =
|
||||||
time(time_passes, "ast indexing",
|
time(time_passes, "ast indexing",
|
||||||
bind middle::ast_map::map_crate(*crate));
|
bind middle::ast_map::map_crate(*crate));
|
||||||
@ -257,6 +285,7 @@ options:
|
|||||||
-o <filename> write output to <filename>
|
-o <filename> write output to <filename>
|
||||||
--lib compile a library crate
|
--lib compile a library crate
|
||||||
--static use or produce static libraries
|
--static use or produce static libraries
|
||||||
|
--no-core omit the 'core' library (used and imported by default)
|
||||||
--pretty [type] pretty-print the input instead of compiling
|
--pretty [type] pretty-print the input instead of compiling
|
||||||
--ls list the symbols defined by a crate file
|
--ls list the symbols defined by a crate file
|
||||||
-L <path> add a directory to the library search path
|
-L <path> add a directory to the library search path
|
||||||
@ -362,6 +391,7 @@ fn build_session_options(match: getopts::match)
|
|||||||
} else if opt_present(match, "emit-llvm") {
|
} else if opt_present(match, "emit-llvm") {
|
||||||
link::output_type_bitcode
|
link::output_type_bitcode
|
||||||
} else { link::output_type_exe };
|
} else { link::output_type_exe };
|
||||||
|
let libcore = !opt_present(match, "no-core");
|
||||||
let verify = !opt_present(match, "no-verify");
|
let verify = !opt_present(match, "no-verify");
|
||||||
let save_temps = opt_present(match, "save-temps");
|
let save_temps = opt_present(match, "save-temps");
|
||||||
let debuginfo = opt_present(match, "g");
|
let debuginfo = opt_present(match, "g");
|
||||||
@ -409,6 +439,7 @@ fn build_session_options(match: getopts::match)
|
|||||||
let sopts: @session::options =
|
let sopts: @session::options =
|
||||||
@{library: library,
|
@{library: library,
|
||||||
static: static,
|
static: static,
|
||||||
|
libcore: libcore,
|
||||||
optimize: opt_level,
|
optimize: opt_level,
|
||||||
debuginfo: debuginfo,
|
debuginfo: debuginfo,
|
||||||
verify: verify,
|
verify: verify,
|
||||||
@ -465,6 +496,7 @@ fn opts() -> [getopts::opt] {
|
|||||||
optflag("time-passes"), optflag("time-llvm-passes"),
|
optflag("time-passes"), optflag("time-llvm-passes"),
|
||||||
optflag("no-verify"),
|
optflag("no-verify"),
|
||||||
optmulti("cfg"), optflag("test"),
|
optmulti("cfg"), optflag("test"),
|
||||||
|
optflag("no-core"),
|
||||||
optflag("lib"), optflag("static"), optflag("gc"),
|
optflag("lib"), optflag("static"), optflag("gc"),
|
||||||
optflag("stack-growth"),
|
optflag("stack-growth"),
|
||||||
optflag("no-asm-comments"),
|
optflag("no-asm-comments"),
|
||||||
|
@ -26,6 +26,7 @@ type options =
|
|||||||
// with additional crate configurations during the compile process
|
// with additional crate configurations during the compile process
|
||||||
{library: bool,
|
{library: bool,
|
||||||
static: bool,
|
static: bool,
|
||||||
|
libcore: bool,
|
||||||
optimize: uint,
|
optimize: uint,
|
||||||
debuginfo: bool,
|
debuginfo: bool,
|
||||||
verify: bool,
|
verify: bool,
|
||||||
|
@ -19,7 +19,6 @@ type test = {span: span, path: [ast::ident], ignore: bool, should_fail: bool};
|
|||||||
type test_ctxt =
|
type test_ctxt =
|
||||||
@{sess: session::session,
|
@{sess: session::session,
|
||||||
crate: @ast::crate,
|
crate: @ast::crate,
|
||||||
next_node_id: node_id_gen,
|
|
||||||
mutable path: [ast::ident],
|
mutable path: [ast::ident],
|
||||||
mutable testfns: [test]};
|
mutable testfns: [test]};
|
||||||
|
|
||||||
@ -28,22 +27,9 @@ type test_ctxt =
|
|||||||
fn modify_for_testing(sess: session::session,
|
fn modify_for_testing(sess: session::session,
|
||||||
crate: @ast::crate) -> @ast::crate {
|
crate: @ast::crate) -> @ast::crate {
|
||||||
|
|
||||||
// FIXME: This hackasaurus assumes that 200000 is a safe number to start
|
|
||||||
// generating node_ids at (which is totally not the case). pauls is going
|
|
||||||
// to land a patch that puts parse_sess into session, which will give us
|
|
||||||
// access to the real next node_id.
|
|
||||||
let next_node_id = @mutable 200000;
|
|
||||||
let next_node_id_fn =
|
|
||||||
bind fn (next_node_id: @mutable ast::node_id) -> ast::node_id {
|
|
||||||
let this_node_id = *next_node_id;
|
|
||||||
*next_node_id += 1;
|
|
||||||
ret this_node_id;
|
|
||||||
}(next_node_id);
|
|
||||||
|
|
||||||
let cx: test_ctxt =
|
let cx: test_ctxt =
|
||||||
@{sess: sess,
|
@{sess: sess,
|
||||||
crate: crate,
|
crate: crate,
|
||||||
next_node_id: next_node_id_fn,
|
|
||||||
mutable path: [],
|
mutable path: [],
|
||||||
mutable testfns: []};
|
mutable testfns: []};
|
||||||
|
|
||||||
@ -187,7 +173,7 @@ fn mk_test_module(cx: test_ctxt) -> @ast::item {
|
|||||||
let item: ast::item =
|
let item: ast::item =
|
||||||
{ident: "__test",
|
{ident: "__test",
|
||||||
attrs: [],
|
attrs: [],
|
||||||
id: cx.next_node_id(),
|
id: cx.sess.next_node_id(),
|
||||||
node: item_,
|
node: item_,
|
||||||
span: dummy_sp()};
|
span: dummy_sp()};
|
||||||
|
|
||||||
@ -216,7 +202,7 @@ fn mk_tests(cx: test_ctxt) -> @ast::item {
|
|||||||
let test_descs = mk_test_desc_vec(cx);
|
let test_descs = mk_test_desc_vec(cx);
|
||||||
|
|
||||||
let body_: ast::blk_ =
|
let body_: ast::blk_ =
|
||||||
default_block([], option::some(test_descs), cx.next_node_id());
|
default_block([], option::some(test_descs), cx.sess.next_node_id());
|
||||||
let body = nospan(body_);
|
let body = nospan(body_);
|
||||||
|
|
||||||
let fn_ = {decl: decl, proto: proto, body: body};
|
let fn_ = {decl: decl, proto: proto, body: body};
|
||||||
@ -225,7 +211,7 @@ fn mk_tests(cx: test_ctxt) -> @ast::item {
|
|||||||
let item: ast::item =
|
let item: ast::item =
|
||||||
{ident: "tests",
|
{ident: "tests",
|
||||||
attrs: [],
|
attrs: [],
|
||||||
id: cx.next_node_id(),
|
id: cx.sess.next_node_id(),
|
||||||
node: item_,
|
node: item_,
|
||||||
span: dummy_sp()};
|
span: dummy_sp()};
|
||||||
ret @item;
|
ret @item;
|
||||||
@ -240,7 +226,7 @@ fn mk_test_desc_vec_ty(cx: test_ctxt) -> @ast::ty {
|
|||||||
idents: ["std", "test", "default_test_fn"],
|
idents: ["std", "test", "default_test_fn"],
|
||||||
types: []
|
types: []
|
||||||
}),
|
}),
|
||||||
cx.next_node_id()));
|
cx.sess.next_node_id()));
|
||||||
|
|
||||||
let test_desc_ty_path =
|
let test_desc_ty_path =
|
||||||
@nospan({global: false,
|
@nospan({global: false,
|
||||||
@ -248,7 +234,7 @@ fn mk_test_desc_vec_ty(cx: test_ctxt) -> @ast::ty {
|
|||||||
types: [@test_fn_ty]});
|
types: [@test_fn_ty]});
|
||||||
|
|
||||||
let test_desc_ty: ast::ty =
|
let test_desc_ty: ast::ty =
|
||||||
nospan(ast::ty_path(test_desc_ty_path, cx.next_node_id()));
|
nospan(ast::ty_path(test_desc_ty_path, cx.sess.next_node_id()));
|
||||||
|
|
||||||
let vec_mt: ast::mt = {ty: @test_desc_ty, mut: ast::imm};
|
let vec_mt: ast::mt = {ty: @test_desc_ty, mut: ast::imm};
|
||||||
|
|
||||||
@ -263,7 +249,7 @@ fn mk_test_desc_vec(cx: test_ctxt) -> @ast::expr {
|
|||||||
descs += [mk_test_desc_rec(cx, test_)];
|
descs += [mk_test_desc_rec(cx, test_)];
|
||||||
}
|
}
|
||||||
|
|
||||||
ret @{id: cx.next_node_id(),
|
ret @{id: cx.sess.next_node_id(),
|
||||||
node: ast::expr_vec(descs, ast::imm),
|
node: ast::expr_vec(descs, ast::imm),
|
||||||
span: dummy_sp()};
|
span: dummy_sp()};
|
||||||
}
|
}
|
||||||
@ -277,7 +263,7 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
|
|||||||
let name_lit: ast::lit =
|
let name_lit: ast::lit =
|
||||||
nospan(ast::lit_str(ast_util::path_name_i(path)));
|
nospan(ast::lit_str(ast_util::path_name_i(path)));
|
||||||
let name_expr: ast::expr =
|
let name_expr: ast::expr =
|
||||||
{id: cx.next_node_id(),
|
{id: cx.sess.next_node_id(),
|
||||||
node: ast::expr_lit(@name_lit),
|
node: ast::expr_lit(@name_lit),
|
||||||
span: span};
|
span: span};
|
||||||
|
|
||||||
@ -287,7 +273,7 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
|
|||||||
let fn_path = @nospan({global: false, idents: path, types: []});
|
let fn_path = @nospan({global: false, idents: path, types: []});
|
||||||
|
|
||||||
let fn_expr: ast::expr =
|
let fn_expr: ast::expr =
|
||||||
{id: cx.next_node_id(),
|
{id: cx.sess.next_node_id(),
|
||||||
node: ast::expr_path(fn_path),
|
node: ast::expr_path(fn_path),
|
||||||
span: span};
|
span: span};
|
||||||
|
|
||||||
@ -299,7 +285,7 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
|
|||||||
let ignore_lit: ast::lit = nospan(ast::lit_bool(test.ignore));
|
let ignore_lit: ast::lit = nospan(ast::lit_bool(test.ignore));
|
||||||
|
|
||||||
let ignore_expr: ast::expr =
|
let ignore_expr: ast::expr =
|
||||||
{id: cx.next_node_id(),
|
{id: cx.sess.next_node_id(),
|
||||||
node: ast::expr_lit(@ignore_lit),
|
node: ast::expr_lit(@ignore_lit),
|
||||||
span: span};
|
span: span};
|
||||||
|
|
||||||
@ -309,7 +295,7 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
|
|||||||
let fail_lit: ast::lit = nospan(ast::lit_bool(test.should_fail));
|
let fail_lit: ast::lit = nospan(ast::lit_bool(test.should_fail));
|
||||||
|
|
||||||
let fail_expr: ast::expr =
|
let fail_expr: ast::expr =
|
||||||
{id: cx.next_node_id(),
|
{id: cx.sess.next_node_id(),
|
||||||
node: ast::expr_lit(@fail_lit),
|
node: ast::expr_lit(@fail_lit),
|
||||||
span: span};
|
span: span};
|
||||||
|
|
||||||
@ -320,7 +306,7 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
|
|||||||
ast::expr_rec([name_field, fn_field, ignore_field, fail_field],
|
ast::expr_rec([name_field, fn_field, ignore_field, fail_field],
|
||||||
option::none);
|
option::none);
|
||||||
let desc_rec: ast::expr =
|
let desc_rec: ast::expr =
|
||||||
{id: cx.next_node_id(), node: desc_rec_, span: span};
|
{id: cx.sess.next_node_id(), node: desc_rec_, span: span};
|
||||||
ret @desc_rec;
|
ret @desc_rec;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -330,13 +316,13 @@ fn mk_test_wrapper(cx: test_ctxt,
|
|||||||
fn_path_expr: ast::expr,
|
fn_path_expr: ast::expr,
|
||||||
span: span) -> @ast::expr {
|
span: span) -> @ast::expr {
|
||||||
let call_expr: ast::expr = {
|
let call_expr: ast::expr = {
|
||||||
id: cx.next_node_id(),
|
id: cx.sess.next_node_id(),
|
||||||
node: ast::expr_call(@fn_path_expr, [], false),
|
node: ast::expr_call(@fn_path_expr, [], false),
|
||||||
span: span
|
span: span
|
||||||
};
|
};
|
||||||
|
|
||||||
let call_stmt: ast::stmt = nospan(
|
let call_stmt: ast::stmt = nospan(
|
||||||
ast::stmt_expr(@call_expr, cx.next_node_id()));
|
ast::stmt_expr(@call_expr, cx.sess.next_node_id()));
|
||||||
|
|
||||||
let wrapper_decl: ast::fn_decl = {
|
let wrapper_decl: ast::fn_decl = {
|
||||||
inputs: [],
|
inputs: [],
|
||||||
@ -351,7 +337,7 @@ fn mk_test_wrapper(cx: test_ctxt,
|
|||||||
view_items: [],
|
view_items: [],
|
||||||
stmts: [@call_stmt],
|
stmts: [@call_stmt],
|
||||||
expr: option::none,
|
expr: option::none,
|
||||||
id: cx.next_node_id(),
|
id: cx.sess.next_node_id(),
|
||||||
rules: ast::default_blk
|
rules: ast::default_blk
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -362,7 +348,7 @@ fn mk_test_wrapper(cx: test_ctxt,
|
|||||||
};
|
};
|
||||||
|
|
||||||
let wrapper_expr: ast::expr = {
|
let wrapper_expr: ast::expr = {
|
||||||
id: cx.next_node_id(),
|
id: cx.sess.next_node_id(),
|
||||||
node: ast::expr_fn(wrapper_fn),
|
node: ast::expr_fn(wrapper_fn),
|
||||||
span: span
|
span: span
|
||||||
};
|
};
|
||||||
@ -379,7 +365,7 @@ fn mk_main(cx: test_ctxt) -> @ast::item {
|
|||||||
{mode: ast::by_val,
|
{mode: ast::by_val,
|
||||||
ty: @args_ty,
|
ty: @args_ty,
|
||||||
ident: "args",
|
ident: "args",
|
||||||
id: cx.next_node_id()};
|
id: cx.sess.next_node_id()};
|
||||||
|
|
||||||
let ret_ty = nospan(ast::ty_nil);
|
let ret_ty = nospan(ast::ty_nil);
|
||||||
|
|
||||||
@ -396,7 +382,7 @@ fn mk_main(cx: test_ctxt) -> @ast::item {
|
|||||||
|
|
||||||
let body_: ast::blk_ =
|
let body_: ast::blk_ =
|
||||||
default_block([], option::some(test_main_call_expr),
|
default_block([], option::some(test_main_call_expr),
|
||||||
cx.next_node_id());
|
cx.sess.next_node_id());
|
||||||
let body = {node: body_, span: dummy_sp()};
|
let body = {node: body_, span: dummy_sp()};
|
||||||
|
|
||||||
let fn_ = {decl: decl, proto: proto, body: body};
|
let fn_ = {decl: decl, proto: proto, body: body};
|
||||||
@ -405,7 +391,7 @@ fn mk_main(cx: test_ctxt) -> @ast::item {
|
|||||||
let item: ast::item =
|
let item: ast::item =
|
||||||
{ident: "main",
|
{ident: "main",
|
||||||
attrs: [],
|
attrs: [],
|
||||||
id: cx.next_node_id(),
|
id: cx.sess.next_node_id(),
|
||||||
node: item_,
|
node: item_,
|
||||||
span: dummy_sp()};
|
span: dummy_sp()};
|
||||||
ret @item;
|
ret @item;
|
||||||
@ -420,7 +406,7 @@ fn mk_test_main_call(cx: test_ctxt) -> @ast::expr {
|
|||||||
let args_path_expr_: ast::expr_ = ast::expr_path(args_path);
|
let args_path_expr_: ast::expr_ = ast::expr_path(args_path);
|
||||||
|
|
||||||
let args_path_expr: ast::expr =
|
let args_path_expr: ast::expr =
|
||||||
{id: cx.next_node_id(), node: args_path_expr_, span: dummy_sp()};
|
{id: cx.sess.next_node_id(), node: args_path_expr_, span: dummy_sp()};
|
||||||
|
|
||||||
// Call __test::test to generate the vector of test_descs
|
// Call __test::test to generate the vector of test_descs
|
||||||
let test_path =
|
let test_path =
|
||||||
@ -429,12 +415,12 @@ fn mk_test_main_call(cx: test_ctxt) -> @ast::expr {
|
|||||||
let test_path_expr_: ast::expr_ = ast::expr_path(test_path);
|
let test_path_expr_: ast::expr_ = ast::expr_path(test_path);
|
||||||
|
|
||||||
let test_path_expr: ast::expr =
|
let test_path_expr: ast::expr =
|
||||||
{id: cx.next_node_id(), node: test_path_expr_, span: dummy_sp()};
|
{id: cx.sess.next_node_id(), node: test_path_expr_, span: dummy_sp()};
|
||||||
|
|
||||||
let test_call_expr_ = ast::expr_call(@test_path_expr, [], false);
|
let test_call_expr_ = ast::expr_call(@test_path_expr, [], false);
|
||||||
|
|
||||||
let test_call_expr: ast::expr =
|
let test_call_expr: ast::expr =
|
||||||
{id: cx.next_node_id(), node: test_call_expr_, span: dummy_sp()};
|
{id: cx.sess.next_node_id(), node: test_call_expr_, span: dummy_sp()};
|
||||||
|
|
||||||
// Call std::test::test_main
|
// Call std::test::test_main
|
||||||
let test_main_path =
|
let test_main_path =
|
||||||
@ -445,14 +431,16 @@ fn mk_test_main_call(cx: test_ctxt) -> @ast::expr {
|
|||||||
let test_main_path_expr_: ast::expr_ = ast::expr_path(test_main_path);
|
let test_main_path_expr_: ast::expr_ = ast::expr_path(test_main_path);
|
||||||
|
|
||||||
let test_main_path_expr: ast::expr =
|
let test_main_path_expr: ast::expr =
|
||||||
{id: cx.next_node_id(), node: test_main_path_expr_, span: dummy_sp()};
|
{id: cx.sess.next_node_id(), node: test_main_path_expr_,
|
||||||
|
span: dummy_sp()};
|
||||||
|
|
||||||
let test_main_call_expr_: ast::expr_ =
|
let test_main_call_expr_: ast::expr_ =
|
||||||
ast::expr_call(@test_main_path_expr,
|
ast::expr_call(@test_main_path_expr,
|
||||||
[@args_path_expr, @test_call_expr], false);
|
[@args_path_expr, @test_call_expr], false);
|
||||||
|
|
||||||
let test_main_call_expr: ast::expr =
|
let test_main_call_expr: ast::expr =
|
||||||
{id: cx.next_node_id(), node: test_main_call_expr_, span: dummy_sp()};
|
{id: cx.sess.next_node_id(), node: test_main_call_expr_,
|
||||||
|
span: dummy_sp()};
|
||||||
|
|
||||||
ret @test_main_call_expr;
|
ret @test_main_call_expr;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user