diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-10-03 19:16:27 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-10-04 15:07:49 -0700 |
| commit | edc317b8212fe1c29b5e7e2e4e260b9a4d72b447 (patch) | |
| tree | 3bdc8d5103affca408a0ff2bc2325f4869ecb375 /src/rustc | |
| parent | e3f458e6390d66b9634e7dce4aa7e91c091aebc6 (diff) | |
| download | rust-edc317b8212fe1c29b5e7e2e4e260b9a4d72b447.tar.gz rust-edc317b8212fe1c29b5e7e2e4e260b9a4d72b447.zip | |
Remove arg vectors from main functions. Stop supporting them.
Diffstat (limited to 'src/rustc')
| -rw-r--r-- | src/rustc/driver/rustc.rs | 3 | ||||
| -rw-r--r-- | src/rustc/front/test.rs | 40 | ||||
| -rw-r--r-- | src/rustc/middle/trans/base.rs | 20 | ||||
| -rw-r--r-- | src/rustc/middle/typeck.rs | 6 |
4 files changed, 21 insertions, 48 deletions
diff --git a/src/rustc/driver/rustc.rs b/src/rustc/driver/rustc.rs index c6b93fc0603..5fc48e2b6a2 100644 --- a/src/rustc/driver/rustc.rs +++ b/src/rustc/driver/rustc.rs @@ -277,7 +277,8 @@ fn monitor(+f: fn~(diagnostic::emitter)) { } } -fn main(args: ~[~str]) { +fn main() { + let args = os::args(); do monitor |demitter| { run_compiler(args, demitter); } diff --git a/src/rustc/front/test.rs b/src/rustc/front/test.rs index 952d7b9ab79..1a6cc6dd895 100644 --- a/src/rustc/front/test.rs +++ b/src/rustc/front/test.rs @@ -415,34 +415,12 @@ fn mk_test_wrapper(cx: test_ctxt, } fn mk_main(cx: test_ctxt) -> @ast::item { - let str_pt = path_node(~[cx.sess.ident_of(~"str")]); - let str_ty_inner = @{id: cx.sess.next_node_id(), - node: ast::ty_path(str_pt, cx.sess.next_node_id()), - span: dummy_sp()}; - let str_ty = @{id: cx.sess.next_node_id(), - node: ast::ty_uniq({ty: str_ty_inner, mutbl: ast::m_imm}), - span: dummy_sp()}; - let args_mt = {ty: str_ty, mutbl: ast::m_imm}; - let args_ty_inner = @{id: cx.sess.next_node_id(), - node: ast::ty_vec(args_mt), - span: dummy_sp()}; - let args_ty = {id: cx.sess.next_node_id(), - node: ast::ty_uniq({ty: args_ty_inner, mutbl: ast::m_imm}), - span: dummy_sp()}; - - - let args_arg: ast::arg = - {mode: ast::expl(ast::by_val), - ty: @args_ty, - ident: cx.sess.ident_of(~"args"), - id: cx.sess.next_node_id()}; - let ret_ty = {id: cx.sess.next_node_id(), node: ast::ty_nil, span: dummy_sp()}; let decl: ast::fn_decl = - {inputs: ~[args_arg], + {inputs: ~[], output: @ret_ty, cf: ast::return_val}; @@ -465,9 +443,11 @@ fn mk_main(cx: test_ctxt) -> @ast::item { } fn mk_test_main_call(cx: test_ctxt) -> @ast::expr { - - // Get the args passed to main so we can pass the to test_main - let args_path = path_node(~[cx.sess.ident_of(~"args")]); + // Call os::args to generate the vector of test_descs + let args_path = path_node(~[ + cx.sess.ident_of(~"os"), + cx.sess.ident_of(~"args") + ]); let args_path_expr_: ast::expr_ = ast::expr_path(args_path); @@ -475,6 +455,12 @@ fn mk_test_main_call(cx: test_ctxt) -> @ast::expr { {id: cx.sess.next_node_id(), callee_id: cx.sess.next_node_id(), node: args_path_expr_, span: dummy_sp()}; + let args_call_expr_ = ast::expr_call(@args_path_expr, ~[], false); + + let args_call_expr: ast::expr = + {id: cx.sess.next_node_id(), callee_id: cx.sess.next_node_id(), + node: args_call_expr_, span: dummy_sp()}; + // Call __test::test to generate the vector of test_descs let test_path = path_node(~[cx.sess.ident_of(~"tests")]); @@ -503,7 +489,7 @@ fn mk_test_main_call(cx: test_ctxt) -> @ast::expr { let test_main_call_expr_: ast::expr_ = ast::expr_call(@test_main_path_expr, - ~[@args_path_expr, @test_call_expr], false); + ~[@args_call_expr, @test_call_expr], false); let test_main_call_expr: ast::expr = {id: cx.sess.next_node_id(), callee_id: cx.sess.next_node_id(), diff --git a/src/rustc/middle/trans/base.rs b/src/rustc/middle/trans/base.rs index 0631d7b1ea4..ce596586ddc 100644 --- a/src/rustc/middle/trans/base.rs +++ b/src/rustc/middle/trans/base.rs @@ -1953,32 +1953,23 @@ fn register_fn_fuller(ccx: @crate_ctxt, sp: span, path: path, ast_map::path_to_str(path, ccx.sess.parse_sess.interner)); let is_main = is_main_name(path) && !ccx.sess.building_library; - if is_main { create_main_wrapper(ccx, sp, llfn, node_type); } + if is_main { create_main_wrapper(ccx, sp, llfn); } llfn } // Create a _rust_main(args: ~[str]) function which will be called from the // runtime rust_start function -fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef, - main_node_type: ty::t) { +fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef) { if ccx.main_fn != None::<ValueRef> { ccx.sess.span_fatal(sp, ~"multiple 'main' functions"); } - let main_takes_argv = - // invariant! - match ty::get(main_node_type).sty { - ty::ty_fn(ref fn_ty) => fn_ty.sig.inputs.len() != 0u, - _ => ccx.sess.span_fatal(sp, ~"main has a non-function type") - }; - - let llfn = create_main(ccx, main_llfn, main_takes_argv); + let llfn = create_main(ccx, main_llfn); ccx.main_fn = Some(llfn); create_entry_fn(ccx, llfn); - fn create_main(ccx: @crate_ctxt, main_llfn: ValueRef, - takes_argv: bool) -> ValueRef { + fn create_main(ccx: @crate_ctxt, main_llfn: ValueRef) -> ValueRef { let unit_ty = ty::mk_estr(ccx.tcx, ty::vstore_uniq); let vecarg_ty: ty::arg = {mode: ast::expl(ast::by_val), @@ -1998,9 +1989,6 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef, let lloutputarg = llvm::LLVMGetParam(llfdecl, 0 as c_uint); let llenvarg = llvm::LLVMGetParam(llfdecl, 1 as c_uint); let mut args = ~[lloutputarg, llenvarg]; - if takes_argv { - args.push(llvm::LLVMGetParam(llfdecl, 2 as c_uint)); - } Call(bcx, main_llfn, args); build_return(bcx); diff --git a/src/rustc/middle/typeck.rs b/src/rustc/middle/typeck.rs index e0b2ca5ae64..3a9471139f9 100644 --- a/src/rustc/middle/typeck.rs +++ b/src/rustc/middle/typeck.rs @@ -301,14 +301,12 @@ fn check_main_fn_ty(ccx: @crate_ctxt, } let mut ok = ty::type_is_nil(fn_ty.sig.output); let num_args = vec::len(fn_ty.sig.inputs); - ok &= num_args == 0u || num_args == 1u && - arg_is_argv_ty(tcx, fn_ty.sig.inputs[0]); + ok &= num_args == 0u; if !ok { tcx.sess.span_err( main_span, fmt!("Wrong type in main function: found `%s`, \ - expected `extern fn(++v: ~[~str]) -> ()` \ - or `extern fn() -> ()`", + expected `fn() -> ()`", ty_to_str(tcx, main_t))); } } |
