about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/compiletest/common.rs3
-rw-r--r--src/compiletest/compiletest.rc5
-rw-r--r--src/compiletest/runtest.rs10
-rw-r--r--src/libcore/rt/mod.rs31
-rw-r--r--src/libcore/unstable/lang.rs19
-rw-r--r--src/rt/rust.cpp15
-rw-r--r--src/rt/rust_builtin.cpp31
-rw-r--r--src/rt/rustrt.def.in3
8 files changed, 95 insertions, 22 deletions
diff --git a/src/compiletest/common.rs b/src/compiletest/common.rs
index b7c4e26c4b1..36691380e17 100644
--- a/src/compiletest/common.rs
+++ b/src/compiletest/common.rs
@@ -63,6 +63,9 @@ pub struct config {
     // Run tests using the JIT
     jit: bool,
 
+    // Run tests using the new runtime
+    newrt: bool,
+
     // Explain what's going on
     verbose: bool
 
diff --git a/src/compiletest/compiletest.rc b/src/compiletest/compiletest.rc
index 7d53b29e040..0c1f328ad09 100644
--- a/src/compiletest/compiletest.rc
+++ b/src/compiletest/compiletest.rc
@@ -61,7 +61,8 @@ pub fn parse_config(args: ~[~str]) -> config {
           getopts::optopt(~"runtool"), getopts::optopt(~"rustcflags"),
           getopts::optflag(~"verbose"),
           getopts::optopt(~"logfile"),
-          getopts::optflag(~"jit")];
+          getopts::optflag(~"jit"),
+          getopts::optflag(~"newrt")];
 
     fail_unless!(!args.is_empty());
     let args_ = vec::tail(args);
@@ -95,6 +96,7 @@ pub fn parse_config(args: ~[~str]) -> config {
         runtool: getopts::opt_maybe_str(matches, ~"runtool"),
         rustcflags: getopts::opt_maybe_str(matches, ~"rustcflags"),
         jit: getopts::opt_present(matches, ~"jit"),
+        newrt: getopts::opt_present(matches, ~"newrt"),
         verbose: getopts::opt_present(matches, ~"verbose")
     }
 }
@@ -114,6 +116,7 @@ pub fn log_config(config: config) {
     logv(c, fmt!("runtool: %s", opt_str(config.runtool)));
     logv(c, fmt!("rustcflags: %s", opt_str(config.rustcflags)));
     logv(c, fmt!("jit: %b", config.jit));
+    logv(c, fmt!("newrt: %b", config.newrt));
     logv(c, fmt!("verbose: %b", config.verbose));
     logv(c, fmt!("\n"));
 }
diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs
index 03f3fa9fcf6..736aa4eebf0 100644
--- a/src/compiletest/runtest.rs
+++ b/src/compiletest/runtest.rs
@@ -483,9 +483,17 @@ fn compile_test_(config: config, props: TestProps,
 
 fn exec_compiled_test(config: config, props: TestProps,
                       testfile: &Path) -> ProcRes {
+
+    // If testing the new runtime then set the RUST_NEWRT env var
+    let env = if config.newrt {
+        props.exec_env + ~[(~"RUST_NEWRT", ~"1")]
+    } else {
+        props.exec_env
+    };
+
     compose_and_run(config, testfile,
                     make_run_args(config, props, testfile),
-                    props.exec_env,
+                    env,
                     config.run_lib_path, None)
 }
 
diff --git a/src/libcore/rt/mod.rs b/src/libcore/rt/mod.rs
index 1e919af4d14..f900747c996 100644
--- a/src/libcore/rt/mod.rs
+++ b/src/libcore/rt/mod.rs
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+use libc::c_char;
 
 // Some basic logging
 macro_rules! rtdebug_ (
@@ -44,3 +45,33 @@ mod stack;
 mod context;
 mod thread;
 pub mod env;
+
+pub fn initialize() {
+    unsafe { rust_initialize_global_state(); }
+    extern {
+        fn rust_initialize_global_state();
+    }
+}
+
+pub fn start(main: *u8, _argc: int, _argv: *c_char, _crate_map: *u8) -> int {
+    use self::sched::{Scheduler, Task};
+    use self::uvio::UvEventLoop;
+
+    // XXX: Would rather do this lazily in Scheduler
+    initialize();
+
+    let loop_ = ~UvEventLoop::new();
+    let mut sched = ~Scheduler::new(loop_);
+    let main_task = ~do Task::new(&mut sched.stack_pool) {
+        // XXX: Can't call a C function pointer from Rust yet
+        unsafe { rust_call_nullary_fn(main) };
+    };
+    sched.task_queue.push_back(main_task);
+    sched.run();
+    return 0;
+
+    extern {
+        fn rust_call_nullary_fn(f: *u8);
+    }
+}
+
diff --git a/src/libcore/unstable/lang.rs b/src/libcore/unstable/lang.rs
index db0b1cc33cd..855c6b250ec 100644
--- a/src/libcore/unstable/lang.rs
+++ b/src/libcore/unstable/lang.rs
@@ -120,16 +120,25 @@ pub unsafe fn strdup_uniq(ptr: *c_uchar, len: uint) -> ~str {
 #[lang="start"]
 pub fn start(main: *u8, argc: int, argv: *c_char,
              crate_map: *u8) -> int {
+    use libc::getenv;
+    use rt::start;
+
+    unsafe {
+        let use_new_rt = do str::as_c_str("RUST_NEWRT") |s| {
+            getenv(s).is_null()
+        };
+        if use_new_rt {
+            return rust_start(main as *c_void, argc as c_int, argv,
+                              crate_map as *c_void) as int;
+        } else {
+            return start(main, argc, argv, crate_map);
+        }
+    }
 
     extern {
         fn rust_start(main: *c_void, argc: c_int, argv: *c_char,
                       crate_map: *c_void) -> c_int;
     }
-
-    unsafe {
-        return rust_start(main as *c_void, argc as c_int, argv,
-                          crate_map as *c_void) as int;
-    }
 }
 
 // Local Variables:
diff --git a/src/rt/rust.cpp b/src/rt/rust.cpp
index d9ef6a52dbe..803da32cbc8 100644
--- a/src/rt/rust.cpp
+++ b/src/rt/rust.cpp
@@ -21,17 +21,6 @@
 
 void* global_crate_map = NULL;
 
-#ifndef _WIN32
-pthread_key_t sched_key;
-#else
-DWORD sched_key;
-#endif
-
-extern "C" void*
-rust_get_sched_tls_key() {
-    return &sched_key;
-}
-
 /**
    The runtime entrypoint. The (C ABI) main function generated by rustc calls
    `rust_start`, providing the address of the Rust ABI main function, the
@@ -41,10 +30,6 @@ rust_get_sched_tls_key() {
 extern "C" CDECL int
 rust_start(uintptr_t main_fn, int argc, char **argv, void* crate_map) {
 
-#ifndef _WIN32
-    pthread_key_create(&sched_key, NULL);
-#endif
-
     // Load runtime configuration options from the environment.
     // FIXME #1497: Should provide a way to get these from the command
     // line as well.
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp
index a2053c115bb..9349db17d56 100644
--- a/src/rt/rust_builtin.cpp
+++ b/src/rt/rust_builtin.cpp
@@ -882,6 +882,37 @@ rust_get_rt_env() {
     return task->kernel->env;
 }
 
+typedef void *(*nullary_fn)();
+
+extern "C" CDECL void
+rust_call_nullary_fn(nullary_fn f) {
+    f();
+}
+
+
+#ifndef _WIN32
+pthread_key_t sched_key;
+#else
+DWORD sched_key;
+#endif
+
+extern "C" void*
+rust_get_sched_tls_key() {
+    return &sched_key;
+}
+
+extern "C" CDECL void
+rust_initialize_global_state() {
+
+#ifndef _WIN32
+    assert(!pthread_key_create(&sched_key, NULL));
+#else
+    sched_key = TlsAlloc();
+    assert(sched_key != TLS_OUT_OF_INDEXES);
+#endif
+
+}
+
 //
 // Local Variables:
 // mode: C++
diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in
index 4fde952ba95..59fd8991622 100644
--- a/src/rt/rustrt.def.in
+++ b/src/rt/rustrt.def.in
@@ -210,4 +210,7 @@ rust_uv_ip4_addrp
 rust_uv_ip6_addrp
 rust_uv_free_ip4_addr
 rust_uv_free_ip6_addr
+rust_call_nullary_fn
+rust_initialize_global_state
+