auto merge of #9296 : alexcrichton/rust/snapshots, r=cmr

huzzah!
This commit is contained in:
bors 2013-09-18 11:46:37 -07:00
commit d2b0b11aeb
32 changed files with 32 additions and 1663 deletions

View File

@ -137,16 +137,6 @@ fn list_dir_sorted(path: &Path) -> ~[Path] {
/**
* A compiled Unix shell style pattern.
*/
#[cfg(stage0)]
#[deriving(Clone, Eq, TotalEq, Ord, TotalOrd, IterBytes)]
pub struct Pattern {
priv tokens: ~[PatternToken]
}
/**
* A compiled Unix shell style pattern.
*/
#[cfg(not(stage0))]
#[deriving(Clone, Eq, TotalEq, Ord, TotalOrd, IterBytes, Default)]
pub struct Pattern {
priv tokens: ~[PatternToken]
@ -465,39 +455,10 @@ fn is_sep(c: char) -> bool {
}
}
/**
* Configuration options to modify the behaviour of `Pattern::matches_with(..)`
*/
#[cfg(stage0)]
#[deriving(Clone, Eq, TotalEq, Ord, TotalOrd, IterBytes)]
pub struct MatchOptions {
/**
* Whether or not patterns should be matched in a case-sensitive manner. This
* currently only considers upper/lower case relationships between ASCII characters,
* but in future this might be extended to work with Unicode.
*/
case_sensitive: bool,
/**
* If this is true then path-component separator characters (e.g. `/` on Posix)
* must be matched by a literal `/`, rather than by `*` or `?` or `[...]`
*/
require_literal_separator: bool,
/**
* If this is true then paths that contain components that start with a `.` will
* not match unless the `.` appears literally in the pattern: `*`, `?` or `[...]`
* will not match. This is useful because such files are conventionally considered
* hidden on Unix systems and it might be desirable to skip them when listing files.
*/
require_literal_leading_dot: bool
}
/**
* Configuration options to modify the behaviour of `Pattern::matches_with(..)`
*/
#[cfg(not(stage0))]
#[deriving(Clone, Eq, TotalEq, Ord, TotalOrd, IterBytes, Default)]
pub struct MatchOptions {

View File

@ -13,25 +13,6 @@ use std::libc::{c_char, c_int};
use std::{local_data, str, rt};
use std::unstable::finally::Finally;
#[cfg(stage0)]
pub mod rustrt {
use std::libc::{c_char, c_int};
extern {
fn linenoise(prompt: *c_char) -> *c_char;
fn linenoiseHistoryAdd(line: *c_char) -> c_int;
fn linenoiseHistorySetMaxLen(len: c_int) -> c_int;
fn linenoiseHistorySave(file: *c_char) -> c_int;
fn linenoiseHistoryLoad(file: *c_char) -> c_int;
fn linenoiseSetCompletionCallback(callback: *u8);
fn linenoiseAddCompletion(completions: *(), line: *c_char);
fn rust_take_linenoise_lock();
fn rust_drop_linenoise_lock();
}
}
#[cfg(not(stage0))]
pub mod rustrt {
use std::libc::{c_char, c_int};
@ -109,7 +90,7 @@ pub fn read(prompt: &str) -> Option<~str> {
pub type CompletionCb = @fn(~str, @fn(~str));
static complete_key: local_data::Key<CompletionCb> = &local_data::Key;
local_data_key!(complete_key: CompletionCb)
/// Bind to the main completion callback in the current task.
///

View File

@ -190,7 +190,7 @@ pub mod jit {
// The stage1 compiler won't work, but that doesn't really matter. TLS
// changed only very recently to allow storage of owned values.
static engine_key: local_data::Key<~Engine> = &local_data::Key;
local_data_key!(engine_key: ~Engine)
fn set_engine(engine: ~Engine) {
local_data::set(engine_key, engine)

View File

@ -293,50 +293,6 @@ fn mk_std(cx: &TestCtxt) -> ast::view_item {
}
}
#[cfg(stage0)]
fn mk_test_module(cx: &TestCtxt) -> @ast::item {
// Link to extra
let view_items = ~[mk_std(cx)];
// A constant vector of test descriptors.
let tests = mk_tests(cx);
// The synthesized main function which will call the console test runner
// with our list of tests
let ext_cx = cx.ext_cx;
let mainfn = (quote_item!(
pub fn main() {
#[main];
extra::test::test_main_static(::std::os::args(), TESTS);
}
)).unwrap();
let testmod = ast::_mod {
view_items: view_items,
items: ~[mainfn, tests],
};
let item_ = ast::item_mod(testmod);
// This attribute tells resolve to let us call unexported functions
let resolve_unexported_attr =
attr::mk_attr(attr::mk_word_item(@"!resolve_unexported"));
let item = ast::item {
ident: cx.sess.ident_of("__test"),
attrs: ~[resolve_unexported_attr],
id: ast::DUMMY_NODE_ID,
node: item_,
vis: ast::public,
span: dummy_sp(),
};
debug!("Synthetic test module:\n%s\n",
pprust::item_to_str(@item.clone(), cx.sess.intr()));
return @item;
}
#[cfg(not(stage0))]
fn mk_test_module(cx: &TestCtxt) -> @ast::item {
// Link to extra
@ -407,21 +363,6 @@ fn path_node_global(ids: ~[ast::Ident]) -> ast::Path {
}
}
#[cfg(stage0)]
fn mk_tests(cx: &TestCtxt) -> @ast::item {
let ext_cx = cx.ext_cx;
// The vector of test_descs for this crate
let test_descs = mk_test_descs(cx);
(quote_item!(
pub static TESTS : &'static [self::extra::test::TestDescAndFn] =
$test_descs
;
)).unwrap()
}
#[cfg(not(stage0))]
fn mk_tests(cx: &TestCtxt) -> @ast::item {
// The vector of test_descs for this crate
let test_descs = mk_test_descs(cx);
@ -461,63 +402,6 @@ fn mk_test_descs(cx: &TestCtxt) -> @ast::Expr {
}
}
#[cfg(stage0)]
fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> @ast::Expr {
let span = test.span;
let path = test.path.clone();
let ext_cx = cx.ext_cx;
debug!("encoding %s", ast_util::path_name_i(path));
let name_lit: ast::lit =
nospan(ast::lit_str(ast_util::path_name_i(path).to_managed()));
let name_expr = @ast::Expr {
id: ast::DUMMY_NODE_ID,
node: ast::ExprLit(@name_lit),
span: span
};
let fn_path = path_node_global(path);
let fn_expr = @ast::Expr {
id: ast::DUMMY_NODE_ID,
node: ast::ExprPath(fn_path),
span: span,
};
let t_expr = if test.bench {
quote_expr!( self::extra::test::StaticBenchFn($fn_expr) )
} else {
quote_expr!( self::extra::test::StaticTestFn($fn_expr) )
};
let ignore_expr = if test.ignore {
quote_expr!( true )
} else {
quote_expr!( false )
};
let fail_expr = if test.should_fail {
quote_expr!( true )
} else {
quote_expr!( false )
};
let e = quote_expr!(
self::extra::test::TestDescAndFn {
desc: self::extra::test::TestDesc {
name: self::extra::test::StaticTestName($name_expr),
ignore: $ignore_expr,
should_fail: $fail_expr
},
testfn: $t_expr,
}
);
e
}
#[cfg(not(stage0))]
fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> @ast::Expr {
let span = test.span;
let path = test.path.clone();

View File

@ -92,7 +92,7 @@ use syntax::visit::Visitor;
pub use middle::trans::context::task_llcx;
static task_local_insn_key: local_data::Key<@~[&'static str]> = &local_data::Key;
local_data_key!(task_local_insn_key: @~[&'static str])
pub fn with_insn_ctxt(blk: &fn(&[&'static str])) {
let opt = local_data::get(task_local_insn_key, |k| k.map_move(|k| *k));

View File

@ -287,7 +287,7 @@ impl Drop for CrateContext {
}
}
static task_local_llcx_key: local_data::Key<@ContextRef> = &local_data::Key;
local_data_key!(task_local_llcx_key: @ContextRef)
pub fn task_llcx() -> ContextRef {
let opt = local_data::get(task_local_llcx_key, |k| k.map_move(|k| *k));

View File

@ -60,7 +60,7 @@ struct LocalVariable {
}
type LocalCache = @mut HashMap<~str, @~[u8]>;
static tls_key: local_data::Key<LocalCache> = &local_data::Key;
local_data_key!(tls_key: LocalCache)
impl Program {
pub fn new() -> Program {

View File

@ -30,9 +30,7 @@ pub enum NullByteResolution {
condition! {
// This should be &[u8] but there's a lifetime issue (#5370).
// NOTE: this super::NullByteResolution should be NullByteResolution
// Change this next time the snapshot is updated.
pub null_byte: (~[u8]) -> super::NullByteResolution;
pub null_byte: (~[u8]) -> NullByteResolution;
}
/// The representation of a C String.

View File

@ -37,17 +37,6 @@ pub fn console_off() {
rt::logging::console_off();
}
#[cfg(not(test), stage0)]
#[lang="log_type"]
#[allow(missing_doc)]
pub fn log_type<T>(_level: u32, object: &T) {
use sys;
// XXX: Bad allocation
let msg = sys::log_str(object);
newsched_log_str(msg);
}
fn newsched_log_str(msg: ~str) {
use rt::task::Task;
use rt::local::Local;

View File

@ -148,18 +148,6 @@ pub mod win32 {
}
}
#[cfg(stage0)]
mod macro_hack {
#[macro_escape];
macro_rules! externfn(
(fn $name:ident ()) => (
extern {
fn $name();
}
)
)
}
/*
Accessing environment variables is not generally threadsafe.
Serialize access through a global lock.

View File

@ -16,31 +16,13 @@ use clone::Clone;
use cmp::Equiv;
use iter::{range, Iterator};
use option::{Option, Some, None};
#[cfg(stage0)]
use sys;
use unstable::intrinsics;
use util::swap;
#[cfg(not(test))] use cmp::{Eq, Ord};
/// Calculate the offset from a pointer. The count *must* be in bounds or
/// otherwise the loads of this address are undefined.
#[inline]
#[cfg(stage0)]
pub unsafe fn offset<T>(ptr: *T, count: int) -> *T {
(ptr as uint + (count as uint) * sys::size_of::<T>()) as *T
}
/// Calculate the offset from a mut pointer
#[inline]
#[cfg(stage0)]
pub unsafe fn mut_offset<T>(ptr: *mut T, count: int) -> *mut T {
(ptr as uint + (count as uint) * sys::size_of::<T>()) as *mut T
}
/// Calculate the offset from a pointer
#[inline]
#[cfg(not(stage0))]
pub unsafe fn offset<T>(ptr: *T, count: int) -> *T {
intrinsics::offset(ptr, count)
}
@ -48,7 +30,6 @@ pub unsafe fn offset<T>(ptr: *T, count: int) -> *T {
/// Calculate the offset from a mut pointer. The count *must* be in bounds or
/// otherwise the loads of this address are undefined.
#[inline]
#[cfg(not(stage0))]
pub unsafe fn mut_offset<T>(ptr: *mut T, count: int) -> *mut T {
intrinsics::offset(ptr as *T, count) as *mut T
}
@ -383,17 +364,7 @@ impl<T> RawPtr<T> for *mut T {
}
// Equality for pointers
#[cfg(stage0, not(test))]
impl<T> Eq for *T {
#[inline]
fn eq(&self, other: &*T) -> bool {
(*self as uint) == (*other as uint)
}
#[inline]
fn ne(&self, other: &*T) -> bool { !self.eq(other) }
}
#[cfg(not(stage0), not(test))]
#[cfg(not(test))]
impl<T> Eq for *T {
#[inline]
fn eq(&self, other: &*T) -> bool {
@ -403,17 +374,7 @@ impl<T> Eq for *T {
fn ne(&self, other: &*T) -> bool { !self.eq(other) }
}
#[cfg(stage0, not(test))]
impl<T> Eq for *mut T {
#[inline]
fn eq(&self, other: &*mut T) -> bool {
(*self as uint) == (*other as uint)
}
#[inline]
fn ne(&self, other: &*mut T) -> bool { !self.eq(other) }
}
#[cfg(not(stage0), not(test))]
#[cfg(not(test))]
impl<T> Eq for *mut T {
#[inline]
fn eq(&self, other: &*mut T) -> bool {
@ -480,27 +441,7 @@ mod externfnpointers {
}
// Comparison for pointers
#[cfg(stage0, not(test))]
impl<T> Ord for *T {
#[inline]
fn lt(&self, other: &*T) -> bool {
(*self as uint) < (*other as uint)
}
#[inline]
fn le(&self, other: &*T) -> bool {
(*self as uint) <= (*other as uint)
}
#[inline]
fn ge(&self, other: &*T) -> bool {
(*self as uint) >= (*other as uint)
}
#[inline]
fn gt(&self, other: &*T) -> bool {
(*self as uint) > (*other as uint)
}
}
#[cfg(not(stage0), not(test))]
#[cfg(not(test))]
impl<T> Ord for *T {
#[inline]
fn lt(&self, other: &*T) -> bool {
@ -520,27 +461,7 @@ impl<T> Ord for *T {
}
}
#[cfg(stage0, not(test))]
impl<T> Ord for *mut T {
#[inline]
fn lt(&self, other: &*mut T) -> bool {
(*self as uint) < (*other as uint)
}
#[inline]
fn le(&self, other: &*mut T) -> bool {
(*self as uint) <= (*other as uint)
}
#[inline]
fn ge(&self, other: &*mut T) -> bool {
(*self as uint) >= (*other as uint)
}
#[inline]
fn gt(&self, other: &*mut T) -> bool {
(*self as uint) > (*other as uint)
}
}
#[cfg(not(stage0), not(test))]
#[cfg(not(test))]
impl<T> Ord for *mut T {
#[inline]
fn lt(&self, other: &*mut T) -> bool {

View File

@ -915,7 +915,7 @@ pub fn seed() -> ~[u8] {
}
// used to make space in TLS for a random number generator
static tls_rng_state: local_data::Key<@@mut IsaacRng> = &local_data::Key;
local_data_key!(tls_rng_state: @@mut IsaacRng)
/**
* Gives back a lazily initialized task-local random number generator,

View File

@ -1,493 +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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
/*!
Runtime type reflection
*/
#[allow(missing_doc)];
use unstable::intrinsics::{Opaque, TyDesc, TyVisitor};
use libc::c_void;
use sys;
use unstable::raw;
/**
* Trait for visitor that wishes to reflect on data. To use this, create a
* struct that encapsulates the set of pointers you wish to walk through a
* data structure, and implement both `MovePtr` for it as well as `TyVisitor`;
* then build a MovePtrAdaptor wrapped around your struct.
*/
pub trait MovePtr {
fn move_ptr(&self, adjustment: &fn(*c_void) -> *c_void);
fn push_ptr(&self);
fn pop_ptr(&self);
}
/// Helper function for alignment calculation.
#[inline]
pub fn align(size: uint, align: uint) -> uint {
((size + align) - 1u) & !(align - 1u)
}
/// Adaptor to wrap around visitors implementing MovePtr.
pub struct MovePtrAdaptor<V> {
inner: V
}
pub fn MovePtrAdaptor<V:TyVisitor + MovePtr>(v: V) -> MovePtrAdaptor<V> {
MovePtrAdaptor { inner: v }
}
impl<V:TyVisitor + MovePtr> MovePtrAdaptor<V> {
#[inline]
pub fn bump(&self, sz: uint) {
do self.inner.move_ptr() |p| {
((p as uint) + sz) as *c_void
};
}
#[inline]
pub fn align(&self, a: uint) {
do self.inner.move_ptr() |p| {
align(p as uint, a) as *c_void
};
}
#[inline]
pub fn align_to<T>(&self) {
self.align(sys::min_align_of::<T>());
}
#[inline]
pub fn bump_past<T>(&self) {
self.bump(sys::size_of::<T>());
}
}
/// Abstract type-directed pointer-movement using the MovePtr trait
impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
fn visit_bot(&self) -> bool {
self.align_to::<()>();
if ! self.inner.visit_bot() { return false; }
self.bump_past::<()>();
true
}
fn visit_nil(&self) -> bool {
self.align_to::<()>();
if ! self.inner.visit_nil() { return false; }
self.bump_past::<()>();
true
}
fn visit_bool(&self) -> bool {
self.align_to::<bool>();
if ! self.inner.visit_bool() { return false; }
self.bump_past::<bool>();
true
}
fn visit_int(&self) -> bool {
self.align_to::<int>();
if ! self.inner.visit_int() { return false; }
self.bump_past::<int>();
true
}
fn visit_i8(&self) -> bool {
self.align_to::<i8>();
if ! self.inner.visit_i8() { return false; }
self.bump_past::<i8>();
true
}
fn visit_i16(&self) -> bool {
self.align_to::<i16>();
if ! self.inner.visit_i16() { return false; }
self.bump_past::<i16>();
true
}
fn visit_i32(&self) -> bool {
self.align_to::<i32>();
if ! self.inner.visit_i32() { return false; }
self.bump_past::<i32>();
true
}
fn visit_i64(&self) -> bool {
self.align_to::<i64>();
if ! self.inner.visit_i64() { return false; }
self.bump_past::<i64>();
true
}
fn visit_uint(&self) -> bool {
self.align_to::<uint>();
if ! self.inner.visit_uint() { return false; }
self.bump_past::<uint>();
true
}
fn visit_u8(&self) -> bool {
self.align_to::<u8>();
if ! self.inner.visit_u8() { return false; }
self.bump_past::<u8>();
true
}
fn visit_u16(&self) -> bool {
self.align_to::<u16>();
if ! self.inner.visit_u16() { return false; }
self.bump_past::<u16>();
true
}
fn visit_u32(&self) -> bool {
self.align_to::<u32>();
if ! self.inner.visit_u32() { return false; }
self.bump_past::<u32>();
true
}
fn visit_u64(&self) -> bool {
self.align_to::<u64>();
if ! self.inner.visit_u64() { return false; }
self.bump_past::<u64>();
true
}
fn visit_float(&self) -> bool {
self.align_to::<float>();
if ! self.inner.visit_float() { return false; }
self.bump_past::<float>();
true
}
fn visit_f32(&self) -> bool {
self.align_to::<f32>();
if ! self.inner.visit_f32() { return false; }
self.bump_past::<f32>();
true
}
fn visit_f64(&self) -> bool {
self.align_to::<f64>();
if ! self.inner.visit_f64() { return false; }
self.bump_past::<f64>();
true
}
fn visit_char(&self) -> bool {
self.align_to::<char>();
if ! self.inner.visit_char() { return false; }
self.bump_past::<char>();
true
}
fn visit_estr_box(&self) -> bool {
self.align_to::<@str>();
if ! self.inner.visit_estr_box() { return false; }
self.bump_past::<@str>();
true
}
fn visit_estr_uniq(&self) -> bool {
self.align_to::<~str>();
if ! self.inner.visit_estr_uniq() { return false; }
self.bump_past::<~str>();
true
}
fn visit_estr_slice(&self) -> bool {
self.align_to::<&'static str>();
if ! self.inner.visit_estr_slice() { return false; }
self.bump_past::<&'static str>();
true
}
fn visit_estr_fixed(&self, n: uint,
sz: uint,
align: uint) -> bool {
self.align(align);
if ! self.inner.visit_estr_fixed(n, sz, align) { return false; }
self.bump(sz);
true
}
fn visit_box(&self, mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<@u8>();
if ! self.inner.visit_box(mtbl, inner) { return false; }
self.bump_past::<@u8>();
true
}
fn visit_uniq(&self, mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<~u8>();
if ! self.inner.visit_uniq(mtbl, inner) { return false; }
self.bump_past::<~u8>();
true
}
fn visit_uniq_managed(&self, mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<~u8>();
if ! self.inner.visit_uniq_managed(mtbl, inner) { return false; }
self.bump_past::<~u8>();
true
}
fn visit_ptr(&self, mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<*u8>();
if ! self.inner.visit_ptr(mtbl, inner) { return false; }
self.bump_past::<*u8>();
true
}
fn visit_rptr(&self, mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<&'static u8>();
if ! self.inner.visit_rptr(mtbl, inner) { return false; }
self.bump_past::<&'static u8>();
true
}
fn visit_unboxed_vec(&self, mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<raw::Vec<()>>();
if ! self.inner.visit_vec(mtbl, inner) { return false; }
true
}
fn visit_vec(&self, mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<~[u8]>();
if ! self.inner.visit_vec(mtbl, inner) { return false; }
self.bump_past::<~[u8]>();
true
}
fn visit_evec_box(&self, mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<@[u8]>();
if ! self.inner.visit_evec_box(mtbl, inner) { return false; }
self.bump_past::<@[u8]>();
true
}
fn visit_evec_uniq(&self, mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<~[u8]>();
if ! self.inner.visit_evec_uniq(mtbl, inner) { return false; }
self.bump_past::<~[u8]>();
true
}
fn visit_evec_uniq_managed(&self, mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<~[@u8]>();
if ! self.inner.visit_evec_uniq_managed(mtbl, inner) { return false; }
self.bump_past::<~[@u8]>();
true
}
fn visit_evec_slice(&self, mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<&'static [u8]>();
if ! self.inner.visit_evec_slice(mtbl, inner) { return false; }
self.bump_past::<&'static [u8]>();
true
}
fn visit_evec_fixed(&self, n: uint, sz: uint, align: uint,
mtbl: uint, inner: *TyDesc) -> bool {
self.align(align);
if ! self.inner.visit_evec_fixed(n, sz, align, mtbl, inner) {
return false;
}
self.bump(sz);
true
}
fn visit_enter_rec(&self, n_fields: uint, sz: uint, align: uint) -> bool {
self.align(align);
if ! self.inner.visit_enter_rec(n_fields, sz, align) { return false; }
true
}
fn visit_rec_field(&self, i: uint, name: &str,
mtbl: uint, inner: *TyDesc) -> bool {
unsafe { self.align((*inner).align); }
if ! self.inner.visit_rec_field(i, name, mtbl, inner) {
return false;
}
unsafe { self.bump((*inner).size); }
true
}
fn visit_leave_rec(&self, n_fields: uint, sz: uint, align: uint) -> bool {
if ! self.inner.visit_leave_rec(n_fields, sz, align) { return false; }
true
}
fn visit_enter_class(&self, n_fields: uint, sz: uint, align: uint)
-> bool {
self.align(align);
if ! self.inner.visit_enter_class(n_fields, sz, align) {
return false;
}
true
}
fn visit_class_field(&self, i: uint, name: &str,
mtbl: uint, inner: *TyDesc) -> bool {
unsafe { self.align((*inner).align); }
if ! self.inner.visit_class_field(i, name, mtbl, inner) {
return false;
}
unsafe { self.bump((*inner).size); }
true
}
fn visit_leave_class(&self, n_fields: uint, sz: uint, align: uint)
-> bool {
if ! self.inner.visit_leave_class(n_fields, sz, align) {
return false;
}
true
}
fn visit_enter_tup(&self, n_fields: uint, sz: uint, align: uint) -> bool {
self.align(align);
if ! self.inner.visit_enter_tup(n_fields, sz, align) { return false; }
true
}
fn visit_tup_field(&self, i: uint, inner: *TyDesc) -> bool {
unsafe { self.align((*inner).align); }
if ! self.inner.visit_tup_field(i, inner) { return false; }
unsafe { self.bump((*inner).size); }
true
}
fn visit_leave_tup(&self, n_fields: uint, sz: uint, align: uint) -> bool {
if ! self.inner.visit_leave_tup(n_fields, sz, align) { return false; }
true
}
fn visit_enter_fn(&self, purity: uint, proto: uint,
n_inputs: uint, retstyle: uint) -> bool {
if ! self.inner.visit_enter_fn(purity, proto, n_inputs, retstyle) {
return false
}
true
}
fn visit_fn_input(&self, i: uint, mode: uint, inner: *TyDesc) -> bool {
if ! self.inner.visit_fn_input(i, mode, inner) { return false; }
true
}
fn visit_fn_output(&self, retstyle: uint, inner: *TyDesc) -> bool {
if ! self.inner.visit_fn_output(retstyle, inner) { return false; }
true
}
fn visit_leave_fn(&self, purity: uint, proto: uint,
n_inputs: uint, retstyle: uint) -> bool {
if ! self.inner.visit_leave_fn(purity, proto, n_inputs, retstyle) {
return false;
}
true
}
fn visit_enter_enum(&self, n_variants: uint,
get_disr: extern unsafe fn(ptr: *Opaque) -> int,
sz: uint, align: uint)
-> bool {
self.align(align);
if ! self.inner.visit_enter_enum(n_variants, get_disr, sz, align) {
return false;
}
true
}
fn visit_enter_enum_variant(&self, variant: uint,
disr_val: int,
n_fields: uint,
name: &str) -> bool {
if ! self.inner.visit_enter_enum_variant(variant, disr_val,
n_fields, name) {
return false;
}
true
}
fn visit_enum_variant_field(&self, i: uint, offset: uint, inner: *TyDesc) -> bool {
self.inner.push_ptr();
self.bump(offset);
if ! self.inner.visit_enum_variant_field(i, offset, inner) { return false; }
self.inner.pop_ptr();
true
}
fn visit_leave_enum_variant(&self, variant: uint,
disr_val: int,
n_fields: uint,
name: &str) -> bool {
if ! self.inner.visit_leave_enum_variant(variant, disr_val,
n_fields, name) {
return false;
}
true
}
fn visit_leave_enum(&self, n_variants: uint,
get_disr: extern unsafe fn(ptr: *Opaque) -> int,
sz: uint, align: uint) -> bool {
if ! self.inner.visit_leave_enum(n_variants, get_disr, sz, align) {
return false;
}
self.bump(sz);
true
}
fn visit_trait(&self) -> bool {
self.align_to::<@TyVisitor>();
if ! self.inner.visit_trait() { return false; }
self.bump_past::<@TyVisitor>();
true
}
fn visit_param(&self, i: uint) -> bool {
if ! self.inner.visit_param(i) { return false; }
true
}
fn visit_self(&self) -> bool {
self.align_to::<&'static u8>();
if ! self.inner.visit_self() { return false; }
self.align_to::<&'static u8>();
true
}
fn visit_type(&self) -> bool {
if ! self.inner.visit_type() { return false; }
true
}
fn visit_opaque_box(&self) -> bool {
self.align_to::<@u8>();
if ! self.inner.visit_opaque_box() { return false; }
self.bump_past::<@u8>();
true
}
fn visit_closure_ptr(&self, ck: uint) -> bool {
self.align_to::<@fn()>();
if ! self.inner.visit_closure_ptr(ck) { return false; }
self.bump_past::<@fn()>();
true
}
}

View File

@ -1,626 +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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
/*!
More runtime type reflection
*/
#[allow(missing_doc)];
use cast::transmute;
use char;
use container::Container;
use io::{Writer, WriterUtil};
use iter::Iterator;
use libc::c_void;
use option::{Some, None};
use ptr;
use reflect;
use reflect::{MovePtr, align};
use str::StrSlice;
use to_str::ToStr;
use vec::OwnedVector;
use unstable::intrinsics::{Opaque, TyDesc, TyVisitor, get_tydesc, visit_tydesc};
use unstable::raw;
#[cfg(test)] use io;
/// Helpers
trait EscapedCharWriter {
fn write_escaped_char(&self, ch: char);
}
impl EscapedCharWriter for @Writer {
fn write_escaped_char(&self, ch: char) {
match ch {
'\t' => self.write_str("\\t"),
'\r' => self.write_str("\\r"),
'\n' => self.write_str("\\n"),
'\\' => self.write_str("\\\\"),
'\'' => self.write_str("\\'"),
'"' => self.write_str("\\\""),
'\x20'..'\x7e' => self.write_char(ch),
_ => {
do char::escape_unicode(ch) |c| {
self.write_char(c);
}
}
}
}
}
/// Representations
trait Repr {
fn write_repr(&self, writer: @Writer);
}
impl Repr for () {
fn write_repr(&self, writer: @Writer) { writer.write_str("()"); }
}
impl Repr for bool {
fn write_repr(&self, writer: @Writer) {
writer.write_str(if *self { "true" } else { "false" })
}
}
macro_rules! int_repr(($ty:ident) => (impl Repr for $ty {
fn write_repr(&self, writer: @Writer) {
do ::$ty::to_str_bytes(*self, 10u) |bits| {
writer.write(bits);
}
}
}))
int_repr!(int)
int_repr!(i8)
int_repr!(i16)
int_repr!(i32)
int_repr!(i64)
int_repr!(uint)
int_repr!(u8)
int_repr!(u16)
int_repr!(u32)
int_repr!(u64)
macro_rules! num_repr(($ty:ident) => (impl Repr for $ty {
fn write_repr(&self, writer: @Writer) {
let s = self.to_str();
writer.write(s.as_bytes());
}
}))
num_repr!(float)
num_repr!(f32)
num_repr!(f64)
// New implementation using reflect::MovePtr
enum VariantState {
SearchingFor(int),
Matched,
AlreadyFound
}
pub struct ReprVisitor {
ptr: @mut *c_void,
ptr_stk: @mut ~[*c_void],
var_stk: @mut ~[VariantState],
writer: @Writer
}
pub fn ReprVisitor(ptr: *c_void, writer: @Writer) -> ReprVisitor {
ReprVisitor {
ptr: @mut ptr,
ptr_stk: @mut ~[],
var_stk: @mut ~[],
writer: writer,
}
}
impl MovePtr for ReprVisitor {
#[inline]
fn move_ptr(&self, adjustment: &fn(*c_void) -> *c_void) {
*self.ptr = adjustment(*self.ptr);
}
fn push_ptr(&self) {
self.ptr_stk.push(*self.ptr);
}
fn pop_ptr(&self) {
*self.ptr = self.ptr_stk.pop();
}
}
impl ReprVisitor {
// Various helpers for the TyVisitor impl
#[inline]
pub fn get<T>(&self, f: &fn(&T)) -> bool {
unsafe {
f(transmute::<*c_void,&T>(*self.ptr));
}
true
}
#[inline]
pub fn visit_inner(&self, inner: *TyDesc) -> bool {
self.visit_ptr_inner(*self.ptr, inner)
}
#[inline]
pub fn visit_ptr_inner(&self, ptr: *c_void, inner: *TyDesc) -> bool {
unsafe {
let u = ReprVisitor(ptr, self.writer);
let v = reflect::MovePtrAdaptor(u);
visit_tydesc(inner, @v as @TyVisitor);
true
}
}
#[inline]
pub fn write<T:Repr>(&self) -> bool {
do self.get |v:&T| {
v.write_repr(self.writer);
}
}
pub fn write_escaped_slice(&self, slice: &str) {
self.writer.write_char('"');
for ch in slice.iter() {
self.writer.write_escaped_char(ch);
}
self.writer.write_char('"');
}
pub fn write_mut_qualifier(&self, mtbl: uint) {
if mtbl == 0 {
self.writer.write_str("mut ");
} else if mtbl == 1 {
// skip, this is ast::m_imm
} else {
assert_eq!(mtbl, 2);
self.writer.write_str("const ");
}
}
pub fn write_vec_range(&self,
_mtbl: uint,
ptr: *(),
len: uint,
inner: *TyDesc)
-> bool {
let mut p = ptr as *u8;
let (sz, al) = unsafe { ((*inner).size, (*inner).align) };
self.writer.write_char('[');
let mut first = true;
let mut left = len;
// unit structs have 0 size, and don't loop forever.
let dec = if sz == 0 {1} else {sz};
while left > 0 {
if first {
first = false;
} else {
self.writer.write_str(", ");
}
self.visit_ptr_inner(p as *c_void, inner);
unsafe {
p = align(ptr::offset(p, sz as int) as uint, al) as *u8;
}
left -= dec;
}
self.writer.write_char(']');
true
}
pub fn write_unboxed_vec_repr(&self,
mtbl: uint,
v: &raw::Vec<()>,
inner: *TyDesc)
-> bool {
self.write_vec_range(mtbl, ptr::to_unsafe_ptr(&v.data),
v.fill, inner)
}
}
impl TyVisitor for ReprVisitor {
fn visit_bot(&self) -> bool {
self.writer.write_str("!");
true
}
fn visit_nil(&self) -> bool { self.write::<()>() }
fn visit_bool(&self) -> bool { self.write::<bool>() }
fn visit_int(&self) -> bool { self.write::<int>() }
fn visit_i8(&self) -> bool { self.write::<i8>() }
fn visit_i16(&self) -> bool { self.write::<i16>() }
fn visit_i32(&self) -> bool { self.write::<i32>() }
fn visit_i64(&self) -> bool { self.write::<i64>() }
fn visit_uint(&self) -> bool { self.write::<uint>() }
fn visit_u8(&self) -> bool { self.write::<u8>() }
fn visit_u16(&self) -> bool { self.write::<u16>() }
fn visit_u32(&self) -> bool { self.write::<u32>() }
fn visit_u64(&self) -> bool { self.write::<u64>() }
fn visit_float(&self) -> bool { self.write::<float>() }
fn visit_f32(&self) -> bool { self.write::<f32>() }
fn visit_f64(&self) -> bool { self.write::<f64>() }
fn visit_char(&self) -> bool {
do self.get::<char> |&ch| {
self.writer.write_char('\'');
self.writer.write_escaped_char(ch);
self.writer.write_char('\'');
}
}
fn visit_estr_box(&self) -> bool {
do self.get::<@str> |s| {
self.writer.write_char('@');
self.write_escaped_slice(*s);
}
}
fn visit_estr_uniq(&self) -> bool {
do self.get::<~str> |s| {
self.writer.write_char('~');
self.write_escaped_slice(*s);
}
}
fn visit_estr_slice(&self) -> bool {
do self.get::<&str> |s| {
self.write_escaped_slice(*s);
}
}
// Type no longer exists, vestigial function.
fn visit_estr_fixed(&self, _n: uint, _sz: uint,
_align: uint) -> bool { fail!(); }
fn visit_box(&self, mtbl: uint, inner: *TyDesc) -> bool {
self.writer.write_char('@');
self.write_mut_qualifier(mtbl);
do self.get::<&raw::Box<()>> |b| {
let p = ptr::to_unsafe_ptr(&b.data) as *c_void;
self.visit_ptr_inner(p, inner);
}
}
fn visit_uniq(&self, _mtbl: uint, inner: *TyDesc) -> bool {
self.writer.write_char('~');
do self.get::<*c_void> |b| {
self.visit_ptr_inner(*b, inner);
}
}
fn visit_uniq_managed(&self, _mtbl: uint, inner: *TyDesc) -> bool {
self.writer.write_char('~');
do self.get::<&raw::Box<()>> |b| {
let p = ptr::to_unsafe_ptr(&b.data) as *c_void;
self.visit_ptr_inner(p, inner);
}
}
fn visit_ptr(&self, _mtbl: uint, _inner: *TyDesc) -> bool {
do self.get::<*c_void> |p| {
self.writer.write_str(fmt!("(0x%x as *())",
*p as uint));
}
}
fn visit_rptr(&self, mtbl: uint, inner: *TyDesc) -> bool {
self.writer.write_char('&');
self.write_mut_qualifier(mtbl);
do self.get::<*c_void> |p| {
self.visit_ptr_inner(*p, inner);
}
}
// Type no longer exists, vestigial function.
fn visit_vec(&self, _mtbl: uint, _inner: *TyDesc) -> bool { fail!(); }
fn visit_unboxed_vec(&self, mtbl: uint, inner: *TyDesc) -> bool {
do self.get::<raw::Vec<()>> |b| {
self.write_unboxed_vec_repr(mtbl, b, inner);
}
}
fn visit_evec_box(&self, mtbl: uint, inner: *TyDesc) -> bool {
do self.get::<&raw::Box<raw::Vec<()>>> |b| {
self.writer.write_char('@');
self.write_mut_qualifier(mtbl);
self.write_unboxed_vec_repr(mtbl, &b.data, inner);
}
}
fn visit_evec_uniq(&self, mtbl: uint, inner: *TyDesc) -> bool {
do self.get::<&raw::Vec<()>> |b| {
self.writer.write_char('~');
self.write_unboxed_vec_repr(mtbl, *b, inner);
}
}
fn visit_evec_uniq_managed(&self, mtbl: uint, inner: *TyDesc) -> bool {
do self.get::<&raw::Box<raw::Vec<()>>> |b| {
self.writer.write_char('~');
self.write_unboxed_vec_repr(mtbl, &b.data, inner);
}
}
fn visit_evec_slice(&self, mtbl: uint, inner: *TyDesc) -> bool {
do self.get::<raw::Slice<()>> |s| {
self.writer.write_char('&');
self.write_vec_range(mtbl, s.data, s.len, inner);
}
}
fn visit_evec_fixed(&self, _n: uint, sz: uint, _align: uint,
mtbl: uint, inner: *TyDesc) -> bool {
do self.get::<()> |b| {
self.write_vec_range(mtbl, ptr::to_unsafe_ptr(b), sz, inner);
}
}
fn visit_enter_rec(&self, _n_fields: uint,
_sz: uint, _align: uint) -> bool {
self.writer.write_char('{');
true
}
fn visit_rec_field(&self, i: uint, name: &str,
mtbl: uint, inner: *TyDesc) -> bool {
if i != 0 {
self.writer.write_str(", ");
}
self.write_mut_qualifier(mtbl);
self.writer.write_str(name);
self.writer.write_str(": ");
self.visit_inner(inner);
true
}
fn visit_leave_rec(&self, _n_fields: uint,
_sz: uint, _align: uint) -> bool {
self.writer.write_char('}');
true
}
fn visit_enter_class(&self, _n_fields: uint,
_sz: uint, _align: uint) -> bool {
self.writer.write_char('{');
true
}
fn visit_class_field(&self, i: uint, name: &str,
mtbl: uint, inner: *TyDesc) -> bool {
if i != 0 {
self.writer.write_str(", ");
}
self.write_mut_qualifier(mtbl);
self.writer.write_str(name);
self.writer.write_str(": ");
self.visit_inner(inner);
true
}
fn visit_leave_class(&self, _n_fields: uint,
_sz: uint, _align: uint) -> bool {
self.writer.write_char('}');
true
}
fn visit_enter_tup(&self, _n_fields: uint,
_sz: uint, _align: uint) -> bool {
self.writer.write_char('(');
true
}
fn visit_tup_field(&self, i: uint, inner: *TyDesc) -> bool {
if i != 0 {
self.writer.write_str(", ");
}
self.visit_inner(inner);
true
}
fn visit_leave_tup(&self, _n_fields: uint,
_sz: uint, _align: uint) -> bool {
if _n_fields == 1 {
self.writer.write_char(',');
}
self.writer.write_char(')');
true
}
fn visit_enter_enum(&self,
_n_variants: uint,
get_disr: extern unsafe fn(ptr: *Opaque) -> int,
_sz: uint,
_align: uint) -> bool {
let var_stk: &mut ~[VariantState] = self.var_stk;
let disr = unsafe {
get_disr(transmute(*self.ptr))
};
var_stk.push(SearchingFor(disr));
true
}
fn visit_enter_enum_variant(&self, _variant: uint,
disr_val: int,
n_fields: uint,
name: &str) -> bool {
let mut write = false;
match self.var_stk.pop() {
SearchingFor(sought) => {
if disr_val == sought {
self.var_stk.push(Matched);
write = true;
} else {
self.var_stk.push(SearchingFor(sought));
}
}
Matched | AlreadyFound => {
self.var_stk.push(AlreadyFound);
}
}
if write {
self.writer.write_str(name);
if n_fields > 0 {
self.writer.write_char('(');
}
}
true
}
fn visit_enum_variant_field(&self,
i: uint,
_offset: uint,
inner: *TyDesc)
-> bool {
match self.var_stk[self.var_stk.len() - 1] {
Matched => {
if i != 0 {
self.writer.write_str(", ");
}
if ! self.visit_inner(inner) {
return false;
}
}
_ => ()
}
true
}
fn visit_leave_enum_variant(&self, _variant: uint,
_disr_val: int,
n_fields: uint,
_name: &str) -> bool {
match self.var_stk[self.var_stk.len() - 1] {
Matched => {
if n_fields > 0 {
self.writer.write_char(')');
}
}
_ => ()
}
true
}
fn visit_leave_enum(&self,
_n_variants: uint,
_get_disr: extern unsafe fn(ptr: *Opaque) -> int,
_sz: uint,
_align: uint)
-> bool {
let var_stk: &mut ~[VariantState] = self.var_stk;
match var_stk.pop() {
SearchingFor(*) => fail!("enum value matched no variant"),
_ => true
}
}
fn visit_enter_fn(&self, _purity: uint, _proto: uint,
_n_inputs: uint, _retstyle: uint) -> bool { true }
fn visit_fn_input(&self, _i: uint, _mode: uint, _inner: *TyDesc) -> bool {
true
}
fn visit_fn_output(&self, _retstyle: uint, _inner: *TyDesc) -> bool {
true
}
fn visit_leave_fn(&self, _purity: uint, _proto: uint,
_n_inputs: uint, _retstyle: uint) -> bool { true }
fn visit_trait(&self) -> bool { true }
fn visit_param(&self, _i: uint) -> bool { true }
fn visit_self(&self) -> bool { true }
fn visit_type(&self) -> bool { true }
fn visit_opaque_box(&self) -> bool {
self.writer.write_char('@');
do self.get::<&raw::Box<()>> |b| {
let p = ptr::to_unsafe_ptr(&b.data) as *c_void;
self.visit_ptr_inner(p, b.type_desc);
}
}
fn visit_closure_ptr(&self, _ck: uint) -> bool { true }
}
pub fn write_repr<T>(writer: @Writer, object: &T) {
unsafe {
let ptr = ptr::to_unsafe_ptr(object) as *c_void;
let tydesc = get_tydesc::<T>();
let u = ReprVisitor(ptr, writer);
let v = reflect::MovePtrAdaptor(u);
visit_tydesc(tydesc, @v as @TyVisitor)
}
}
#[cfg(test)]
struct P {a: int, b: float}
#[test]
fn test_repr() {
fn exact_test<T>(t: &T, e:&str) {
let s : &str = io::with_str_writer(|w| write_repr(w, t));
if s != e {
error!("expected '%s', got '%s'",
e, s);
}
assert_eq!(s, e);
}
exact_test(&10, "10");
exact_test(&true, "true");
exact_test(&false, "false");
exact_test(&1.234, "1.234");
exact_test(&(&"hello"), "\"hello\"");
exact_test(&(@"hello"), "@\"hello\"");
exact_test(&(~"he\u10f3llo"), "~\"he\\u10f3llo\"");
exact_test(&(@10), "@10");
exact_test(&(@mut 10), "@10"); // FIXME: #4210: incorrect
exact_test(&((@mut 10, 2)), "(@mut 10, 2)");
exact_test(&(~10), "~10");
exact_test(&(&10), "&10");
let mut x = 10;
exact_test(&(&mut x), "&mut 10");
exact_test(&(@mut [1, 2]), "@mut [1, 2]");
exact_test(&(1,), "(1,)");
exact_test(&(@[1,2,3,4,5,6,7,8]),
"@[1, 2, 3, 4, 5, 6, 7, 8]");
exact_test(&(@[1u8,2u8,3u8,4u8]),
"@[1, 2, 3, 4]");
exact_test(&(@["hi", "there"]),
"@[\"hi\", \"there\"]");
exact_test(&(~["hi", "there"]),
"~[\"hi\", \"there\"]");
exact_test(&(&["hi", "there"]),
"&[\"hi\", \"there\"]");
exact_test(&(P{a:10, b:1.234}),
"{a: 10, b: 1.234}");
exact_test(&(@P{a:10, b:1.234}),
"@{a: 10, b: 1.234}");
exact_test(&(~P{a:10, b:1.234}),
"~{a: 10, b: 1.234}");
exact_test(&(10_u8, ~"hello"),
"(10, ~\"hello\")");
exact_test(&(10_u16, ~"hello"),
"(10, ~\"hello\")");
exact_test(&(10_u32, ~"hello"),
"(10, ~\"hello\")");
exact_test(&(10_u64, ~"hello"),
"(10, ~\"hello\")");
struct Foo;
exact_test(&(~[Foo, Foo, Foo]), "~[{}, {}, {}]");
}

View File

@ -117,18 +117,6 @@ mod imp {
}
}
#[cfg(stage0)]
mod macro_hack {
#[macro_escape];
macro_rules! externfn(
(fn $name:ident () $(-> $ret_ty:ty),*) => (
extern {
fn $name() $(-> $ret_ty),*;
}
)
)
}
externfn!(fn rust_take_global_args_lock())
externfn!(fn rust_drop_global_args_lock())
externfn!(fn rust_get_global_args_ptr() -> *mut Option<~~[~str]>)

View File

@ -126,7 +126,7 @@ impl<R: Reader> Decorator<R> for BufferedReader<R> {
/// Wraps a Writer and buffers output to it
///
/// NOTE: `BufferedWriter` will NOT flush its buffer when dropped.
/// Note that `BufferedWriter` will NOT flush its buffer when dropped.
pub struct BufferedWriter<W> {
priv inner: W,
priv buf: ~[u8],
@ -204,7 +204,7 @@ impl<W: Reader> Reader for InternalBufferedWriter<W> {
/// Wraps a Stream and buffers input and output to and from it
///
/// NOTE: `BufferedStream` will NOT flush its output buffer when dropped.
/// Note that `BufferedStream` will NOT flush its output buffer when dropped.
// FIXME #9155 this should be a newtype struct
pub struct BufferedStream<S> {
priv inner: BufferedReader<InternalBufferedWriter<S>>

View File

@ -388,17 +388,13 @@ impl ToStr for IoErrorKind {
// XXX: Can't put doc comments on macros
// Raised by `I/O` operations on error.
condition! {
// NOTE: this super::IoError should be IoError
// Change this next time the snapshot is updated.
pub io_error: super::IoError -> ();
pub io_error: IoError -> ();
}
// XXX: Can't put doc comments on macros
// Raised by `read` on error
condition! {
// NOTE: this super::IoError should be IoError
// Change this next time the snapshot it updated.
pub read_error: super::IoError -> ();
pub read_error: IoError -> ();
}
/// Helper for wrapper calls where you want to

View File

@ -198,18 +198,6 @@ pub fn start_on_main_thread(argc: int, argv: **u8, crate_map: *u8, main: ~fn())
return exit_code;
}
#[cfg(stage0)]
mod macro_hack {
#[macro_escape];
macro_rules! externfn(
(fn $name:ident ($($arg_name:ident : $arg_ty:ty),*) $(-> $ret_ty:ty),*) => (
extern {
fn $name($($arg_name : $arg_ty),*) $(-> $ret_ty),*;
}
)
)
}
/// One-time runtime initialization.
///
/// Initializes global state, including frobbing

View File

@ -444,17 +444,10 @@ impl Unwinder {
}
extern {
#[cfg(not(stage0))]
#[rust_stack]
fn rust_try(f: extern "C" fn(*c_void, *c_void),
code: *c_void,
data: *c_void) -> uintptr_t;
#[cfg(stage0)]
#[rust_stack]
fn rust_try(f: *u8,
code: *c_void,
data: *c_void) -> uintptr_t;
}
}
@ -490,10 +483,10 @@ mod test {
fn tls() {
use local_data;
do run_in_newsched_task() {
static key: local_data::Key<@~str> = &local_data::Key;
local_data_key!(key: @~str)
local_data::set(key, @~"data");
assert!(*local_data::get(key, |k| k.map_move(|k| *k)).unwrap() == ~"data");
static key2: local_data::Key<@~str> = &local_data::Key;
local_data_key!(key2: @~str)
local_data::set(key2, @~"data");
assert!(*local_data::get(key2, |k| k.map_move(|k| *k)).unwrap() == ~"data");
}

View File

@ -31,7 +31,6 @@
use c_str::ToCStr;
use libc::{size_t, c_int, c_uint, c_void, c_char, uintptr_t};
#[cfg(not(stage0))]
use libc::ssize_t;
use libc::{malloc, free};
use libc;
@ -149,73 +148,33 @@ impl uv_stat_t {
}
}
#[cfg(stage0)]
pub type uv_idle_cb = *u8;
#[cfg(stage0)]
pub type uv_alloc_cb = *u8;
#[cfg(stage0)]
pub type uv_read_cb = *u8;
#[cfg(stage0)]
pub type uv_udp_send_cb = *u8;
#[cfg(stage0)]
pub type uv_udp_recv_cb = *u8;
#[cfg(stage0)]
pub type uv_close_cb = *u8;
#[cfg(stage0)]
pub type uv_walk_cb = *u8;
#[cfg(stage0)]
pub type uv_async_cb = *u8;
#[cfg(stage0)]
pub type uv_connect_cb = *u8;
#[cfg(stage0)]
pub type uv_connection_cb = *u8;
#[cfg(stage0)]
pub type uv_timer_cb = *u8;
#[cfg(stage0)]
pub type uv_write_cb = *u8;
#[cfg(stage0)]
pub type uv_getaddrinfo_cb = *u8;
#[cfg(not(stage0))]
pub type uv_idle_cb = extern "C" fn(handle: *uv_idle_t,
status: c_int);
#[cfg(not(stage0))]
pub type uv_alloc_cb = extern "C" fn(stream: *uv_stream_t,
suggested_size: size_t) -> uv_buf_t;
#[cfg(not(stage0))]
pub type uv_read_cb = extern "C" fn(stream: *uv_stream_t,
nread: ssize_t,
buf: uv_buf_t);
#[cfg(not(stage0))]
pub type uv_udp_send_cb = extern "C" fn(req: *uv_udp_send_t,
status: c_int);
#[cfg(not(stage0))]
pub type uv_udp_recv_cb = extern "C" fn(handle: *uv_udp_t,
nread: ssize_t,
buf: uv_buf_t,
addr: *sockaddr,
flags: c_uint);
#[cfg(not(stage0))]
pub type uv_close_cb = extern "C" fn(handle: *uv_handle_t);
#[cfg(not(stage0))]
pub type uv_walk_cb = extern "C" fn(handle: *uv_handle_t,
arg: *c_void);
#[cfg(not(stage0))]
pub type uv_async_cb = extern "C" fn(handle: *uv_async_t,
status: c_int);
#[cfg(not(stage0))]
pub type uv_connect_cb = extern "C" fn(handle: *uv_connect_t,
status: c_int);
#[cfg(not(stage0))]
pub type uv_connection_cb = extern "C" fn(handle: *uv_connection_t,
status: c_int);
#[cfg(not(stage0))]
pub type uv_timer_cb = extern "C" fn(handle: *uv_timer_t,
status: c_int);
#[cfg(not(stage0))]
pub type uv_write_cb = extern "C" fn(handle: *uv_write_t,
status: c_int);
#[cfg(not(stage0))]
pub type uv_getaddrinfo_cb = extern "C" fn(req: *uv_getaddrinfo_t,
status: c_int,
res: *addrinfo);

View File

@ -736,8 +736,6 @@ fn with_envp<T>(env: Option<~[(~str, ~str)]>, cb: &fn(*c_void) -> T) -> T {
let mut tmps = vec::with_capacity(env.len());
for pair in env.iter() {
// Use of match here is just to workaround limitations
// in the stage0 irrefutable pattern impl.
let kv = fmt!("%s=%s", pair.first(), pair.second());
tmps.push(kv.to_c_str());
}

View File

@ -179,14 +179,8 @@ pub mod run;
pub mod sys;
pub mod cast;
pub mod fmt;
#[cfg(stage0)] #[path = "repr_stage0.rs"]
pub mod repr;
#[cfg(not(stage0))]
pub mod repr;
pub mod cleanup;
#[cfg(stage0)] #[path = "reflect_stage0.rs"]
pub mod reflect;
#[cfg(not(stage0))]
pub mod reflect;
pub mod condition;
pub mod logging;

View File

@ -14,8 +14,6 @@
use c_str::ToCStr;
use cast;
#[cfg(stage0)]
use io;
use libc;
use libc::{c_char, size_t};
use repr;
@ -92,7 +90,6 @@ pub fn refcount<T>(t: @T) -> uint {
}
}
#[cfg(not(stage0))]
pub fn log_str<T>(t: &T) -> ~str {
use rt::io;
use rt::io::Decorator;
@ -101,12 +98,6 @@ pub fn log_str<T>(t: &T) -> ~str {
repr::write_repr(&mut result as &mut io::Writer, t);
str::from_utf8_owned(result.inner())
}
#[cfg(stage0)]
pub fn log_str<T>(t: &T) -> ~str {
do io::with_str_writer |w| {
repr::write_repr(w, t)
}
}
/// Trait for initiating task failure.
pub trait FailWithCause {

View File

@ -76,103 +76,7 @@ pub struct TyDesc {
pub enum Opaque { }
#[lang="ty_visitor"]
#[cfg(not(test), stage0)]
pub trait TyVisitor {
fn visit_bot(&self) -> bool;
fn visit_nil(&self) -> bool;
fn visit_bool(&self) -> bool;
fn visit_int(&self) -> bool;
fn visit_i8(&self) -> bool;
fn visit_i16(&self) -> bool;
fn visit_i32(&self) -> bool;
fn visit_i64(&self) -> bool;
fn visit_uint(&self) -> bool;
fn visit_u8(&self) -> bool;
fn visit_u16(&self) -> bool;
fn visit_u32(&self) -> bool;
fn visit_u64(&self) -> bool;
fn visit_float(&self) -> bool;
fn visit_f32(&self) -> bool;
fn visit_f64(&self) -> bool;
fn visit_char(&self) -> bool;
fn visit_estr_box(&self) -> bool;
fn visit_estr_uniq(&self) -> bool;
fn visit_estr_slice(&self) -> bool;
fn visit_estr_fixed(&self, n: uint, sz: uint, align: uint) -> bool;
fn visit_box(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_uniq(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_uniq_managed(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_ptr(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_rptr(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_vec(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_unboxed_vec(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_evec_box(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_evec_uniq(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_evec_uniq_managed(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_evec_slice(&self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_evec_fixed(&self, n: uint, sz: uint, align: uint,
mtbl: uint, inner: *TyDesc) -> bool;
fn visit_enter_rec(&self, n_fields: uint,
sz: uint, align: uint) -> bool;
fn visit_rec_field(&self, i: uint, name: &str,
mtbl: uint, inner: *TyDesc) -> bool;
fn visit_leave_rec(&self, n_fields: uint,
sz: uint, align: uint) -> bool;
fn visit_enter_class(&self, n_fields: uint,
sz: uint, align: uint) -> bool;
fn visit_class_field(&self, i: uint, name: &str,
mtbl: uint, inner: *TyDesc) -> bool;
fn visit_leave_class(&self, n_fields: uint,
sz: uint, align: uint) -> bool;
fn visit_enter_tup(&self, n_fields: uint,
sz: uint, align: uint) -> bool;
fn visit_tup_field(&self, i: uint, inner: *TyDesc) -> bool;
fn visit_leave_tup(&self, n_fields: uint,
sz: uint, align: uint) -> bool;
fn visit_enter_enum(&self, n_variants: uint,
get_disr: extern unsafe fn(ptr: *Opaque) -> int,
sz: uint, align: uint) -> bool;
fn visit_enter_enum_variant(&self, variant: uint,
disr_val: int,
n_fields: uint,
name: &str) -> bool;
fn visit_enum_variant_field(&self, i: uint, offset: uint, inner: *TyDesc) -> bool;
fn visit_leave_enum_variant(&self, variant: uint,
disr_val: int,
n_fields: uint,
name: &str) -> bool;
fn visit_leave_enum(&self, n_variants: uint,
get_disr: extern unsafe fn(ptr: *Opaque) -> int,
sz: uint, align: uint) -> bool;
fn visit_enter_fn(&self, purity: uint, proto: uint,
n_inputs: uint, retstyle: uint) -> bool;
fn visit_fn_input(&self, i: uint, mode: uint, inner: *TyDesc) -> bool;
fn visit_fn_output(&self, retstyle: uint, inner: *TyDesc) -> bool;
fn visit_leave_fn(&self, purity: uint, proto: uint,
n_inputs: uint, retstyle: uint) -> bool;
fn visit_trait(&self) -> bool;
fn visit_param(&self, i: uint) -> bool;
fn visit_self(&self) -> bool;
fn visit_type(&self) -> bool;
fn visit_opaque_box(&self) -> bool;
fn visit_closure_ptr(&self, ck: uint) -> bool;
}
#[lang="ty_visitor"]
#[cfg(not(test), not(stage0))]
#[cfg(not(test))]
pub trait TyVisitor {
fn visit_bot(&mut self) -> bool;
fn visit_nil(&mut self) -> bool;
@ -424,9 +328,6 @@ extern "rust-intrinsic" {
/// Returns `true` if a type is managed (will be allocated on the local heap)
pub fn contains_managed<T>() -> bool;
#[cfg(stage0)]
pub fn visit_tydesc(td: *TyDesc, tv: &TyVisitor);
#[cfg(not(stage0))]
pub fn visit_tydesc(td: *TyDesc, tv: &mut TyVisitor);
pub fn frame_address(f: &once fn(*u8));

View File

@ -411,23 +411,6 @@ impl<T:Send> Exclusive<T> {
}
}
#[cfg(stage0)]
mod macro_hack {
#[macro_escape];
macro_rules! externfn(
(fn $name:ident () $(-> $ret_ty:ty),*) => (
extern {
fn $name() $(-> $ret_ty),*;
}
);
(fn $name:ident ($($arg_name:ident : $arg_ty:ty),*) $(-> $ret_ty:ty),*) => (
extern {
fn $name($($arg_name : $arg_ty),*) $(-> $ret_ty),*;
}
)
)
}
externfn!(fn rust_create_little_lock() -> rust_little_lock)
externfn!(fn rust_destroy_little_lock(lock: rust_little_lock))
externfn!(fn rust_lock_little_lock(lock: rust_little_lock))

View File

@ -804,7 +804,7 @@ pub fn new_sctable_internal() -> SCTable {
// fetch the SCTable from TLS, create one if it doesn't yet exist.
pub fn get_sctable() -> @mut SCTable {
static sctable_key: local_data::Key<@@mut SCTable> = &local_data::Key;
local_data_key!(sctable_key: @@mut SCTable)
match local_data::get(sctable_key, |k| k.map_move(|k| *k)) {
None => {
let new_table = @@mut new_sctable_internal();
@ -841,7 +841,7 @@ pub type ResolveTable = HashMap<(Name,SyntaxContext),Name>;
// okay, I admit, putting this in TLS is not so nice:
// fetch the SCTable from TLS, create one if it doesn't yet exist.
pub fn get_resolve_table() -> @mut ResolveTable {
static resolve_table_key: local_data::Key<@@mut ResolveTable> = &local_data::Key;
local_data_key!(resolve_table_key: @@mut ResolveTable)
match local_data::get(resolve_table_key, |k| k.map(|&k| *k)) {
None => {
let new_table = @@mut HashMap::new();

View File

@ -187,7 +187,7 @@ fn diagnosticcolor(lvl: level) -> term::color::Color {
}
fn print_maybe_styled(msg: &str, color: term::attr::Attr) {
static tls_terminal: local_data::Key<@Option<term::Terminal>> = &local_data::Key;
local_data_key!(tls_terminal: @Option<term::Terminal>)
let stderr = io::stderr();

View File

@ -644,25 +644,11 @@ impl AstBuilder for @ExtCtxt {
self.expr(span, ast::ExprFnBlock(fn_decl, blk))
}
#[cfg(stage0)]
fn lambda0(&self, _span: Span, blk: ast::Block) -> @ast::Expr {
let ext_cx = *self;
let blk_e = self.expr(blk.span, ast::ExprBlock(blk.clone()));
quote_expr!(|| $blk_e )
}
#[cfg(not(stage0))]
fn lambda0(&self, _span: Span, blk: ast::Block) -> @ast::Expr {
let blk_e = self.expr(blk.span, ast::ExprBlock(blk.clone()));
quote_expr!(*self, || $blk_e )
}
#[cfg(stage0)]
fn lambda1(&self, _span: Span, blk: ast::Block, ident: ast::Ident) -> @ast::Expr {
let ext_cx = *self;
let blk_e = self.expr(blk.span, ast::ExprBlock(blk.clone()));
quote_expr!(|$ident| $blk_e )
}
#[cfg(not(stage0))]
fn lambda1(&self, _span: Span, blk: ast::Block, ident: ast::Ident) -> @ast::Expr {
let blk_e = self.expr(blk.span, ast::ExprBlock(blk.clone()));
quote_expr!(*self, |$ident| $blk_e )

View File

@ -22,18 +22,6 @@ use ext::build::AstBuilder;
use std::os;
#[cfg(stage0)]
pub fn expand_option_env(ext_cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
-> base::MacResult {
let var = get_single_str_from_tts(ext_cx, sp, tts, "option_env!");
let e = match os::getenv(var) {
None => quote_expr!(::std::option::None::<&'static str>),
Some(s) => quote_expr!(::std::option::Some($s))
};
MRExpr(e)
}
#[cfg(not(stage0))]
pub fn expand_option_env(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
-> base::MacResult {
let var = get_single_str_from_tts(cx, sp, tts, "option_env!");

View File

@ -863,9 +863,7 @@ pub fn std_macros() -> @str {
use super::*;
static key: ::std::local_data::Key<
@::std::condition::Handler<$input, $out>> =
&::std::local_data::Key;
local_data_key!(key: @::std::condition::Handler<$input, $out>)
pub static cond :
::std::condition::Condition<$input,$out> =
@ -884,9 +882,7 @@ pub fn std_macros() -> @str {
use super::*;
static key: ::std::local_data::Key<
@::std::condition::Handler<$input, $out>> =
&::std::local_data::Key;
local_data_key!(key: @::std::condition::Handler<$input, $out>)
pub static cond :
::std::condition::Condition<$input,$out> =
@ -975,8 +971,6 @@ pub fn std_macros() -> @str {
($($arg:tt)*) => (::std::io::println(format!($($arg)*)))
)
// NOTE: use this after a snapshot lands to abstract the details
// of the TLS interface.
macro_rules! local_data_key (
($name:ident: $ty:ty) => (
static $name: ::std::local_data::Key<$ty> = &::std::local_data::Key;

View File

@ -490,8 +490,7 @@ fn mk_fresh_ident_interner() -> @ident_interner {
// if an interner exists in TLS, return it. Otherwise, prepare a
// fresh one.
pub fn get_ident_interner() -> @ident_interner {
static key: local_data::Key<@@::parse::token::ident_interner> =
&local_data::Key;
local_data_key!(key: @@::parse::token::ident_interner)
match local_data::get(key, |k| k.map_move(|k| *k)) {
Some(interner) => *interner,
None => {

View File

@ -1,3 +1,11 @@
S 2013-09-17 cbd1eef
freebsd-x86_64 9166867a8859076343cb3e57da918b5c0eea720b
linux-i386 38347b579312ff30c36d257a1161660eb0ae8422
linux-x86_64 0c169bba5d6729d0c0f096d61d9274fb082b4b34
macos-i386 1eb229510dd12b91800674566b8dad401a3f80d3
macos-x86_64 1c5d8e29b9671af93963e1b5fa9fcca081124a39
winnt-i386 56baa04a1f02235ebc5a75be05aa65fdc822a4e6
S 2013-08-14 e7b5729
freebsd-x86_64 9de0b5583a5c4413f9e77df7071498385e936dd2
linux-i386 29119a9072f74c639c2bad998edc40e582da540e