From 9639ca5aa88c59cedc7bbe4bd31ec7dabe8a62ec Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 1 Mar 2013 17:27:14 -0800 Subject: core: Move core::rt to core::unstable::lang --- src/libcore/cleanup.rs | 2 +- src/libcore/core.rc | 2 - src/libcore/rt.rs | 139 ------------------------------------ src/libcore/task/local_data_priv.rs | 6 +- src/libcore/unstable.rs | 3 + src/libcore/unstable/lang.rs | 136 +++++++++++++++++++++++++++++++++++ 6 files changed, 141 insertions(+), 147 deletions(-) delete mode 100644 src/libcore/rt.rs create mode 100644 src/libcore/unstable/lang.rs (limited to 'src/libcore') diff --git a/src/libcore/cleanup.rs b/src/libcore/cleanup.rs index 6912d6d995b..393a71562ad 100644 --- a/src/libcore/cleanup.rs +++ b/src/libcore/cleanup.rs @@ -154,7 +154,7 @@ fn debug_mem() -> bool { #[cfg(notest)] #[lang="annihilate"] pub unsafe fn annihilate() { - use rt::local_free; + use unstable::lang::local_free; use io::WriterUtil; use io; use libc; diff --git a/src/libcore/core.rc b/src/libcore/core.rc index 525887f8cb3..c8d2da28255 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -225,8 +225,6 @@ pub const debug : u32 = 4_u32; /* Unsupported interfaces */ -// The runtime interface used by the compiler -#[cfg(notest)] pub mod rt; // Private APIs pub mod unstable; // NOTE: Remove after snapshot diff --git a/src/libcore/rt.rs b/src/libcore/rt.rs deleted file mode 100644 index a4f90e37683..00000000000 --- a/src/libcore/rt.rs +++ /dev/null @@ -1,139 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Runtime calls emitted by the compiler. - -use cast::transmute; -use libc::{c_char, c_uchar, c_void, size_t, uintptr_t, c_int}; -use managed::raw::BoxRepr; -use str; -use sys; -use unstable::exchange_alloc; -use cast::transmute; - -use gc::{cleanup_stack_for_failure, gc, Word}; - -#[allow(non_camel_case_types)] -pub type rust_task = c_void; - -#[cfg(target_word_size = "32")] -pub const FROZEN_BIT: uint = 0x80000000; -#[cfg(target_word_size = "64")] -pub const FROZEN_BIT: uint = 0x8000000000000000; - -pub extern mod rustrt { - #[rust_stack] - unsafe fn rust_upcall_malloc(td: *c_char, size: uintptr_t) -> *c_char; - - #[rust_stack] - unsafe fn rust_upcall_free(ptr: *c_char); -} - -#[lang="fail_"] -pub fn fail_(expr: *c_char, file: *c_char, line: size_t) -> ! { - sys::begin_unwind_(expr, file, line); -} - -#[lang="fail_bounds_check"] -pub unsafe fn fail_bounds_check(file: *c_char, line: size_t, - index: size_t, len: size_t) { - let msg = fmt!("index out of bounds: the len is %d but the index is %d", - len as int, index as int); - do str::as_buf(msg) |p, _len| { - fail_(p as *c_char, file, line); - } -} - -pub unsafe fn fail_borrowed() { - let msg = "borrowed"; - do str::as_buf(msg) |msg_p, _| { - do str::as_buf("???") |file_p, _| { - fail_(msg_p as *c_char, file_p as *c_char, 0); - } - } -} - -// FIXME #4942: Make these signatures agree with exchange_alloc's signatures -#[lang="exchange_malloc"] -pub unsafe fn exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char { - transmute(exchange_alloc::malloc(transmute(td), transmute(size))) -} - -// NB: Calls to free CANNOT be allowed to fail, as throwing an exception from -// inside a landing pad may corrupt the state of the exception handler. If a -// problem occurs, call exit instead. -#[lang="exchange_free"] -pub unsafe fn exchange_free(ptr: *c_char) { - exchange_alloc::free(transmute(ptr)) -} - -#[lang="malloc"] -pub unsafe fn local_malloc(td: *c_char, size: uintptr_t) -> *c_char { - return rustrt::rust_upcall_malloc(td, size); -} - -// NB: Calls to free CANNOT be allowed to fail, as throwing an exception from -// inside a landing pad may corrupt the state of the exception handler. If a -// problem occurs, call exit instead. -#[lang="free"] -pub unsafe fn local_free(ptr: *c_char) { - rustrt::rust_upcall_free(ptr); -} - -#[lang="borrow_as_imm"] -#[inline(always)] -pub unsafe fn borrow_as_imm(a: *u8) { - let a: *mut BoxRepr = transmute(a); - (*a).header.ref_count |= FROZEN_BIT; -} - -#[lang="return_to_mut"] -#[inline(always)] -pub unsafe fn return_to_mut(a: *u8) { - let a: *mut BoxRepr = transmute(a); - (*a).header.ref_count &= !FROZEN_BIT; -} - -#[lang="check_not_borrowed"] -#[inline(always)] -pub unsafe fn check_not_borrowed(a: *u8) { - let a: *mut BoxRepr = transmute(a); - if ((*a).header.ref_count & FROZEN_BIT) != 0 { - fail_borrowed(); - } -} - -#[lang="strdup_uniq"] -pub unsafe fn strdup_uniq(ptr: *c_uchar, len: uint) -> ~str { - str::raw::from_buf_len(ptr, len) -} - -#[lang="start"] -pub fn start(main: *u8, argc: int, argv: *c_char, - crate_map: *u8) -> int { - - 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: -// mode: rust; -// fill-column: 78; -// indent-tabs-mode: nil -// c-basic-offset: 4 -// buffer-file-coding-system: utf-8-unix -// End: diff --git a/src/libcore/task/local_data_priv.rs b/src/libcore/task/local_data_priv.rs index df5a5af74ca..fc152765322 100644 --- a/src/libcore/task/local_data_priv.rs +++ b/src/libcore/task/local_data_priv.rs @@ -19,11 +19,7 @@ use prelude::*; use task::rt; use task::local_data::LocalDataKey; -#[cfg(notest)] -use rt::rust_task; -#[cfg(test)] -#[allow(non_camel_case_types)] -type rust_task = libc::c_void; +use super::rt::rust_task; pub trait LocalData { } impl LocalData for @T { } diff --git a/src/libcore/unstable.rs b/src/libcore/unstable.rs index b7b4b563425..8c0c029a90f 100644 --- a/src/libcore/unstable.rs +++ b/src/libcore/unstable.rs @@ -36,6 +36,9 @@ pub mod exchange_alloc; pub mod intrinsics; #[path = "unstable/extfmt.rs"] pub mod extfmt; +#[path = "unstable/lang.rs"] +#[cfg(notest)] +pub mod lang; extern mod rustrt { pub unsafe fn rust_create_little_lock() -> rust_little_lock; diff --git a/src/libcore/unstable/lang.rs b/src/libcore/unstable/lang.rs new file mode 100644 index 00000000000..e74052995e6 --- /dev/null +++ b/src/libcore/unstable/lang.rs @@ -0,0 +1,136 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Runtime calls emitted by the compiler. + +use cast::transmute; +use libc::{c_char, c_uchar, c_void, size_t, uintptr_t, c_int}; +use managed::raw::BoxRepr; +use str; +use sys; +use unstable::exchange_alloc; +use cast::transmute; + +use gc::{cleanup_stack_for_failure, gc, Word}; + +#[cfg(target_word_size = "32")] +pub const FROZEN_BIT: uint = 0x80000000; +#[cfg(target_word_size = "64")] +pub const FROZEN_BIT: uint = 0x8000000000000000; + +pub extern mod rustrt { + #[rust_stack] + unsafe fn rust_upcall_malloc(td: *c_char, size: uintptr_t) -> *c_char; + + #[rust_stack] + unsafe fn rust_upcall_free(ptr: *c_char); +} + +#[lang="fail_"] +pub fn fail_(expr: *c_char, file: *c_char, line: size_t) -> ! { + sys::begin_unwind_(expr, file, line); +} + +#[lang="fail_bounds_check"] +pub unsafe fn fail_bounds_check(file: *c_char, line: size_t, + index: size_t, len: size_t) { + let msg = fmt!("index out of bounds: the len is %d but the index is %d", + len as int, index as int); + do str::as_buf(msg) |p, _len| { + fail_(p as *c_char, file, line); + } +} + +pub unsafe fn fail_borrowed() { + let msg = "borrowed"; + do str::as_buf(msg) |msg_p, _| { + do str::as_buf("???") |file_p, _| { + fail_(msg_p as *c_char, file_p as *c_char, 0); + } + } +} + +// FIXME #4942: Make these signatures agree with exchange_alloc's signatures +#[lang="exchange_malloc"] +pub unsafe fn exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char { + transmute(exchange_alloc::malloc(transmute(td), transmute(size))) +} + +// NB: Calls to free CANNOT be allowed to fail, as throwing an exception from +// inside a landing pad may corrupt the state of the exception handler. If a +// problem occurs, call exit instead. +#[lang="exchange_free"] +pub unsafe fn exchange_free(ptr: *c_char) { + exchange_alloc::free(transmute(ptr)) +} + +#[lang="malloc"] +pub unsafe fn local_malloc(td: *c_char, size: uintptr_t) -> *c_char { + return rustrt::rust_upcall_malloc(td, size); +} + +// NB: Calls to free CANNOT be allowed to fail, as throwing an exception from +// inside a landing pad may corrupt the state of the exception handler. If a +// problem occurs, call exit instead. +#[lang="free"] +pub unsafe fn local_free(ptr: *c_char) { + rustrt::rust_upcall_free(ptr); +} + +#[lang="borrow_as_imm"] +#[inline(always)] +pub unsafe fn borrow_as_imm(a: *u8) { + let a: *mut BoxRepr = transmute(a); + (*a).header.ref_count |= FROZEN_BIT; +} + +#[lang="return_to_mut"] +#[inline(always)] +pub unsafe fn return_to_mut(a: *u8) { + let a: *mut BoxRepr = transmute(a); + (*a).header.ref_count &= !FROZEN_BIT; +} + +#[lang="check_not_borrowed"] +#[inline(always)] +pub unsafe fn check_not_borrowed(a: *u8) { + let a: *mut BoxRepr = transmute(a); + if ((*a).header.ref_count & FROZEN_BIT) != 0 { + fail_borrowed(); + } +} + +#[lang="strdup_uniq"] +pub unsafe fn strdup_uniq(ptr: *c_uchar, len: uint) -> ~str { + str::raw::from_buf_len(ptr, len) +} + +#[lang="start"] +pub fn start(main: *u8, argc: int, argv: *c_char, + crate_map: *u8) -> int { + + 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: +// mode: rust; +// fill-column: 78; +// indent-tabs-mode: nil +// c-basic-offset: 4 +// buffer-file-coding-system: utf-8-unix +// End: -- cgit 1.4.1-3-g733a5