auto merge of #6240 : brson/rust/snapshots, r=brson
This commit is contained in:
commit
d74ac9ea03
@ -10,9 +10,7 @@
|
||||
|
||||
//! Unsafe casting functions
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
use sys;
|
||||
#[cfg(not(stage0))]
|
||||
use unstable;
|
||||
|
||||
pub mod rusti {
|
||||
@ -21,35 +19,11 @@ pub mod rusti {
|
||||
pub extern "rust-intrinsic" {
|
||||
fn forget<T>(+x: T);
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn reinterpret_cast<T, U>(&&e: T) -> U;
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn transmute<T,U>(e: T) -> U;
|
||||
}
|
||||
}
|
||||
|
||||
/// Casts the value at `src` to U. The two types must have the same length.
|
||||
#[inline(always)]
|
||||
#[cfg(stage0)]
|
||||
pub unsafe fn reinterpret_cast<T, U>(src: &T) -> U {
|
||||
rusti::reinterpret_cast(*src)
|
||||
}
|
||||
|
||||
/// Unsafely copies and casts the value at `src` to U, even if the value is
|
||||
/// noncopyable. The two types must have the same length.
|
||||
#[inline(always)]
|
||||
#[cfg(stage0)]
|
||||
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
|
||||
rusti::reinterpret_cast(*src)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
|
||||
let mut dest: U = unstable::intrinsics::init();
|
||||
{
|
||||
@ -90,17 +64,6 @@ pub unsafe fn bump_box_refcount<T>(t: @T) { forget(t); }
|
||||
* assert!(transmute("L") == ~[76u8, 0u8]);
|
||||
*/
|
||||
#[inline(always)]
|
||||
#[cfg(stage0)]
|
||||
pub unsafe fn transmute<L, G>(thing: L) -> G {
|
||||
let newthing: G = reinterpret_cast(&thing);
|
||||
forget(thing);
|
||||
newthing
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
pub unsafe fn transmute<L, G>(thing: L) -> G {
|
||||
rusti::transmute(thing)
|
||||
}
|
||||
@ -161,15 +124,6 @@ mod tests {
|
||||
use cast::{bump_box_refcount, transmute};
|
||||
|
||||
#[test]
|
||||
#[cfg(stage0)]
|
||||
fn test_reinterpret_cast() {
|
||||
assert!(1u == unsafe { ::cast::reinterpret_cast(&1) });
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn test_transmute_copy() {
|
||||
assert!(1u == unsafe { ::cast::transmute_copy(&1) });
|
||||
}
|
||||
|
@ -25,42 +25,6 @@ pub trait Mutable: Container {
|
||||
fn clear(&mut self);
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
pub trait Map<K, V>: Mutable {
|
||||
/// Return true if the map contains a value for the specified key
|
||||
fn contains_key(&self, key: &K) -> bool;
|
||||
|
||||
// Visits all keys and values
|
||||
fn each(&self, f: &fn(&K, &V) -> bool);
|
||||
|
||||
/// Visit all keys
|
||||
fn each_key(&self, f: &fn(&K) -> bool);
|
||||
|
||||
/// Visit all values
|
||||
fn each_value(&self, f: &fn(&V) -> bool);
|
||||
|
||||
/// Iterate over the map and mutate the contained values
|
||||
fn mutate_values(&mut self, f: &fn(&K, &mut V) -> bool);
|
||||
|
||||
/// Return a reference to the value corresponding to the key
|
||||
fn find(&self, key: &K) -> Option<&'self V>;
|
||||
|
||||
/// Return a mutable reference to the value corresponding to the key
|
||||
fn find_mut(&mut self, key: &K) -> Option<&'self mut V>;
|
||||
|
||||
/// Insert a key-value pair into the map. An existing value for a
|
||||
/// key is replaced by the new value. Return true if the key did
|
||||
/// not already exist in the map.
|
||||
fn insert(&mut self, key: K, value: V) -> bool;
|
||||
|
||||
/// Remove a key-value pair from the map. Return true if the key
|
||||
/// was present in the map, otherwise false.
|
||||
fn remove(&mut self, key: &K) -> bool;
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
pub trait Map<K, V>: Mutable {
|
||||
/// Return true if the map contains a value for the specified key
|
||||
fn contains_key(&self, key: &K) -> bool;
|
||||
|
@ -74,9 +74,6 @@ they contained the following prologue:
|
||||
|
||||
pub use kinds::{Const, Copy, Owned, Durable};
|
||||
pub use ops::{Drop};
|
||||
#[cfg(stage0)]
|
||||
pub use ops::{Add, Sub, Mul, Div, Modulo, Neg, Not};
|
||||
#[cfg(not(stage0))]
|
||||
pub use ops::{Add, Sub, Mul, Div, Rem, Neg, Not};
|
||||
pub use ops::{BitAnd, BitOr, BitXor};
|
||||
pub use ops::{Shl, Shr, Index};
|
||||
|
@ -184,18 +184,6 @@ priv impl<K:Hash + Eq,V> HashMap<K, V> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[inline(always)]
|
||||
fn value_for_bucket(&self, idx: uint) -> &'self V {
|
||||
match self.buckets[idx] {
|
||||
Some(ref bkt) => &bkt.value,
|
||||
None => fail!(~"HashMap::find: internal logic error"),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
#[inline(always)]
|
||||
fn value_for_bucket<'a>(&'a self, idx: uint) -> &'a V {
|
||||
match self.buckets[idx] {
|
||||
@ -204,18 +192,6 @@ priv impl<K:Hash + Eq,V> HashMap<K, V> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[inline(always)]
|
||||
fn mut_value_for_bucket(&mut self, idx: uint) -> &'self mut V {
|
||||
match self.buckets[idx] {
|
||||
Some(ref mut bkt) => &mut bkt.value,
|
||||
None => unreachable()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
#[inline(always)]
|
||||
fn mut_value_for_bucket<'a>(&'a mut self, idx: uint) -> &'a mut V {
|
||||
match self.buckets[idx] {
|
||||
@ -329,21 +305,6 @@ impl<K:Hash + Eq,V> Map<K, V> for HashMap<K, V> {
|
||||
}
|
||||
|
||||
/// Visit all key-value pairs
|
||||
#[cfg(stage0)]
|
||||
fn each(&self, blk: &fn(&'self K, &'self V) -> bool) {
|
||||
for uint::range(0, self.buckets.len()) |i| {
|
||||
for self.buckets[i].each |bucket| {
|
||||
if !blk(&bucket.key, &bucket.value) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Visit all key-value pairs
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn each<'a>(&'a self, blk: &fn(&'a K, &'a V) -> bool) {
|
||||
for uint::range(0, self.buckets.len()) |i| {
|
||||
for self.buckets[i].each |bucket| {
|
||||
@ -360,15 +321,6 @@ impl<K:Hash + Eq,V> Map<K, V> for HashMap<K, V> {
|
||||
}
|
||||
|
||||
/// Visit all values
|
||||
#[cfg(stage0)]
|
||||
fn each_value(&self, blk: &fn(v: &V) -> bool) {
|
||||
self.each(|_, v| blk(v))
|
||||
}
|
||||
|
||||
/// Visit all values
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn each_value<'a>(&'a self, blk: &fn(v: &'a V) -> bool) {
|
||||
self.each(|_, v| blk(v))
|
||||
}
|
||||
@ -386,18 +338,6 @@ impl<K:Hash + Eq,V> Map<K, V> for HashMap<K, V> {
|
||||
}
|
||||
|
||||
/// Return a reference to the value corresponding to the key
|
||||
#[cfg(stage0)]
|
||||
fn find(&self, k: &K) -> Option<&'self V> {
|
||||
match self.bucket_for_key(k) {
|
||||
FoundEntry(idx) => Some(self.value_for_bucket(idx)),
|
||||
TableFull | FoundHole(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Return a reference to the value corresponding to the key
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn find<'a>(&'a self, k: &K) -> Option<&'a V> {
|
||||
match self.bucket_for_key(k) {
|
||||
FoundEntry(idx) => Some(self.value_for_bucket(idx)),
|
||||
@ -406,21 +346,6 @@ impl<K:Hash + Eq,V> Map<K, V> for HashMap<K, V> {
|
||||
}
|
||||
|
||||
/// Return a mutable reference to the value corresponding to the key
|
||||
#[cfg(stage0)]
|
||||
fn find_mut(&mut self, k: &K) -> Option<&'self mut V> {
|
||||
let idx = match self.bucket_for_key(k) {
|
||||
FoundEntry(idx) => idx,
|
||||
TableFull | FoundHole(_) => return None
|
||||
};
|
||||
unsafe { // FIXME(#4903)---requires flow-sensitive borrow checker
|
||||
Some(::cast::transmute_mut_region(self.mut_value_for_bucket(idx)))
|
||||
}
|
||||
}
|
||||
|
||||
/// Return a mutable reference to the value corresponding to the key
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn find_mut<'a>(&'a mut self, k: &K) -> Option<&'a mut V> {
|
||||
let idx = match self.bucket_for_key(k) {
|
||||
FoundEntry(idx) => idx,
|
||||
@ -503,40 +428,6 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {
|
||||
|
||||
/// Return the value corresponding to the key in the map, or insert
|
||||
/// and return the value if it doesn't exist.
|
||||
#[cfg(stage0)]
|
||||
fn find_or_insert(&mut self, k: K, v: V) -> &'self V {
|
||||
if self.size >= self.resize_at {
|
||||
// n.b.: We could also do this after searching, so
|
||||
// that we do not resize if this call to insert is
|
||||
// simply going to update a key in place. My sense
|
||||
// though is that it's worse to have to search through
|
||||
// buckets to find the right spot twice than to just
|
||||
// resize in this corner case.
|
||||
self.expand();
|
||||
}
|
||||
|
||||
let hash = k.hash_keyed(self.k0, self.k1) as uint;
|
||||
let idx = match self.bucket_for_key_with_hash(hash, &k) {
|
||||
TableFull => fail!(~"Internal logic error"),
|
||||
FoundEntry(idx) => idx,
|
||||
FoundHole(idx) => {
|
||||
self.buckets[idx] = Some(Bucket{hash: hash, key: k,
|
||||
value: v});
|
||||
self.size += 1;
|
||||
idx
|
||||
},
|
||||
};
|
||||
|
||||
unsafe { // FIXME(#4903)---requires flow-sensitive borrow checker
|
||||
::cast::transmute_region(self.value_for_bucket(idx))
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the value corresponding to the key in the map, or insert
|
||||
/// and return the value if it doesn't exist.
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn find_or_insert<'a>(&'a mut self, k: K, v: V) -> &'a V {
|
||||
if self.size >= self.resize_at {
|
||||
// n.b.: We could also do this after searching, so
|
||||
@ -567,41 +458,6 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {
|
||||
|
||||
/// Return the value corresponding to the key in the map, or create,
|
||||
/// insert, and return a new value if it doesn't exist.
|
||||
#[cfg(stage0)]
|
||||
fn find_or_insert_with(&mut self, k: K, f: &fn(&K) -> V) -> &'self V {
|
||||
if self.size >= self.resize_at {
|
||||
// n.b.: We could also do this after searching, so
|
||||
// that we do not resize if this call to insert is
|
||||
// simply going to update a key in place. My sense
|
||||
// though is that it's worse to have to search through
|
||||
// buckets to find the right spot twice than to just
|
||||
// resize in this corner case.
|
||||
self.expand();
|
||||
}
|
||||
|
||||
let hash = k.hash_keyed(self.k0, self.k1) as uint;
|
||||
let idx = match self.bucket_for_key_with_hash(hash, &k) {
|
||||
TableFull => fail!(~"Internal logic error"),
|
||||
FoundEntry(idx) => idx,
|
||||
FoundHole(idx) => {
|
||||
let v = f(&k);
|
||||
self.buckets[idx] = Some(Bucket{hash: hash, key: k,
|
||||
value: v});
|
||||
self.size += 1;
|
||||
idx
|
||||
},
|
||||
};
|
||||
|
||||
unsafe { // FIXME(#4903)---requires flow-sensitive borrow checker
|
||||
::cast::transmute_region(self.value_for_bucket(idx))
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the value corresponding to the key in the map, or create,
|
||||
/// insert, and return a new value if it doesn't exist.
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn find_or_insert_with<'a>(&'a mut self, k: K, f: &fn(&K) -> V) -> &'a V {
|
||||
if self.size >= self.resize_at {
|
||||
// n.b.: We could also do this after searching, so
|
||||
@ -647,17 +503,6 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn get(&self, k: &K) -> &'self V {
|
||||
match self.find(k) {
|
||||
Some(v) => v,
|
||||
None => fail!(fmt!("No entry found for key: %?", k)),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn get<'a>(&'a self, k: &K) -> &'a V {
|
||||
match self.find(k) {
|
||||
Some(v) => v,
|
||||
@ -676,19 +521,6 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {
|
||||
|
||||
/// Return the value corresponding to the key in the map, using
|
||||
/// equivalence
|
||||
#[cfg(stage0)]
|
||||
fn find_equiv<Q:Hash + Equiv<K>>(&self, k: &Q) -> Option<&'self V> {
|
||||
match self.bucket_for_key_equiv(k) {
|
||||
FoundEntry(idx) => Some(self.value_for_bucket(idx)),
|
||||
TableFull | FoundHole(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the value corresponding to the key in the map, using
|
||||
/// equivalence
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn find_equiv<'a, Q:Hash + Equiv<K>>(&'a self, k: &Q) -> Option<&'a V> {
|
||||
match self.bucket_for_key_equiv(k) {
|
||||
FoundEntry(idx) => Some(self.value_for_bucket(idx)),
|
||||
|
@ -284,12 +284,7 @@ impl Div<f32,f32> for f32 {
|
||||
fn div(&self, other: &f32) -> f32 { *self / *other }
|
||||
}
|
||||
|
||||
#[cfg(stage0,notest)]
|
||||
impl Modulo<f32,f32> for f32 {
|
||||
#[inline(always)]
|
||||
fn modulo(&self, other: &f32) -> f32 { *self % *other }
|
||||
}
|
||||
#[cfg(not(stage0),notest)]
|
||||
#[cfg(notest)]
|
||||
impl Rem<f32,f32> for f32 {
|
||||
#[inline(always)]
|
||||
fn rem(&self, other: &f32) -> f32 { *self % *other }
|
||||
|
@ -299,11 +299,7 @@ impl Mul<f64,f64> for f64 {
|
||||
impl Div<f64,f64> for f64 {
|
||||
fn div(&self, other: &f64) -> f64 { *self / *other }
|
||||
}
|
||||
#[cfg(stage0,notest)]
|
||||
impl Modulo<f64,f64> for f64 {
|
||||
fn modulo(&self, other: &f64) -> f64 { *self % *other }
|
||||
}
|
||||
#[cfg(not(stage0),notest)]
|
||||
#[cfg(notest)]
|
||||
impl Rem<f64,f64> for f64 {
|
||||
#[inline(always)]
|
||||
fn rem(&self, other: &f64) -> f64 { *self % *other }
|
||||
|
@ -697,12 +697,7 @@ impl Div<float,float> for float {
|
||||
fn div(&self, other: &float) -> float { *self / *other }
|
||||
}
|
||||
|
||||
#[cfg(stage0,notest)]
|
||||
impl Modulo<float,float> for float {
|
||||
#[inline(always)]
|
||||
fn modulo(&self, other: &float) -> float { *self % *other }
|
||||
}
|
||||
#[cfg(not(stage0),notest)]
|
||||
#[cfg(notest)]
|
||||
impl Rem<float,float> for float {
|
||||
#[inline(always)]
|
||||
fn rem(&self, other: &float) -> float { *self % *other }
|
||||
|
@ -224,12 +224,7 @@ impl Div<T,T> for T {
|
||||
fn div(&self, other: &T) -> T { *self / *other }
|
||||
}
|
||||
|
||||
#[cfg(stage0,notest)]
|
||||
impl Modulo<T,T> for T {
|
||||
#[inline(always)]
|
||||
fn modulo(&self, other: &T) -> T { *self % *other }
|
||||
}
|
||||
#[cfg(not(stage0),notest)]
|
||||
#[cfg(notest)]
|
||||
impl Rem<T,T> for T {
|
||||
///
|
||||
/// Returns the integer remainder after division, satisfying:
|
||||
|
@ -10,11 +10,6 @@
|
||||
|
||||
//! An interface for numeric types
|
||||
use cmp::{Eq, Ord};
|
||||
#[cfg(stage0)]
|
||||
use ops::{Add, Sub, Mul, Div, Neg};
|
||||
#[cfg(stage0)]
|
||||
use Rem = ops::Modulo;
|
||||
#[cfg(not(stage0))]
|
||||
use ops::{Add, Sub, Mul, Div, Rem, Neg};
|
||||
use ops::{Not, BitAnd, BitOr, BitXor, Shl, Shr};
|
||||
use option::Option;
|
||||
@ -391,23 +386,7 @@ pub fn pow_with_uint<T:NumCast+One+Zero+Copy+Div<T,T>+Mul<T,T>>(
|
||||
}
|
||||
|
||||
/// Helper function for testing numeric operations
|
||||
#[cfg(stage0,test)]
|
||||
pub fn test_num<T:Num + NumCast>(ten: T, two: T) {
|
||||
assert_eq!(ten.add(&two), cast(12));
|
||||
assert_eq!(ten.sub(&two), cast(8));
|
||||
assert_eq!(ten.mul(&two), cast(20));
|
||||
assert_eq!(ten.div(&two), cast(5));
|
||||
assert_eq!(ten.modulo(&two), cast(0));
|
||||
|
||||
assert_eq!(ten.add(&two), ten + two);
|
||||
assert_eq!(ten.sub(&two), ten - two);
|
||||
assert_eq!(ten.mul(&two), ten * two);
|
||||
assert_eq!(ten.div(&two), ten / two);
|
||||
assert_eq!(ten.modulo(&two), ten % two);
|
||||
}
|
||||
#[cfg(stage1,test)]
|
||||
#[cfg(stage2,test)]
|
||||
#[cfg(stage3,test)]
|
||||
#[cfg(test)]
|
||||
pub fn test_num<T:Num + NumCast>(ten: T, two: T) {
|
||||
assert_eq!(ten.add(&two), cast(12));
|
||||
assert_eq!(ten.sub(&two), cast(8));
|
||||
|
@ -9,13 +9,6 @@
|
||||
// except according to those terms.
|
||||
|
||||
use core::cmp::{Ord, Eq};
|
||||
#[cfg(stage0)]
|
||||
use ops::{Add, Sub, Mul, Div, Neg};
|
||||
#[cfg(stage0)]
|
||||
use Rem = ops::Modulo;
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
use ops::{Add, Sub, Mul, Div, Rem, Neg};
|
||||
use option::{None, Option, Some};
|
||||
use char;
|
||||
|
@ -171,12 +171,7 @@ impl Div<T,T> for T {
|
||||
fn div(&self, other: &T) -> T { *self / *other }
|
||||
}
|
||||
|
||||
#[cfg(stage0,notest)]
|
||||
impl Modulo<T,T> for T {
|
||||
#[inline(always)]
|
||||
fn modulo(&self, other: &T) -> T { *self % *other }
|
||||
}
|
||||
#[cfg(not(stage0),notest)]
|
||||
#[cfg(notest)]
|
||||
impl Rem<T,T> for T {
|
||||
#[inline(always)]
|
||||
fn rem(&self, other: &T) -> T { *self % *other }
|
||||
|
@ -35,13 +35,7 @@ pub trait Div<RHS,Result> {
|
||||
fn div(&self, rhs: &RHS) -> Result;
|
||||
}
|
||||
|
||||
#[lang="modulo"]
|
||||
#[cfg(stage0)]
|
||||
pub trait Modulo<RHS,Result> {
|
||||
fn modulo(&self, rhs: &RHS) -> Result;
|
||||
}
|
||||
#[lang="rem"]
|
||||
#[cfg(not(stage0))]
|
||||
pub trait Rem<RHS,Result> {
|
||||
fn rem(&self, rhs: &RHS) -> Result;
|
||||
}
|
||||
|
@ -100,16 +100,6 @@ impl<T: Copy + Add<T,T>> Add<Option<T>, Option<T>> for Option<T> {
|
||||
|
||||
impl<T> BaseIter<T> for Option<T> {
|
||||
/// Performs an operation on the contained value by reference
|
||||
#[cfg(stage0)]
|
||||
#[inline(always)]
|
||||
fn each(&self, f: &fn(x: &'self T) -> bool) {
|
||||
match *self { None => (), Some(ref t) => { f(t); } }
|
||||
}
|
||||
|
||||
/// Performs an operation on the contained value by reference
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
#[inline(always)]
|
||||
fn each<'a>(&'a self, f: &fn(x: &'a T) -> bool) {
|
||||
match *self { None => (), Some(ref t) => { f(t); } }
|
||||
@ -122,15 +112,6 @@ impl<T> BaseIter<T> for Option<T> {
|
||||
}
|
||||
|
||||
impl<T> MutableIter<T> for Option<T> {
|
||||
#[cfg(stage0)]
|
||||
#[inline(always)]
|
||||
fn each_mut(&mut self, f: &fn(&'self mut T) -> bool) {
|
||||
match *self { None => (), Some(ref mut t) => { f(t); } }
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
#[inline(always)]
|
||||
fn each_mut<'a>(&'a mut self, f: &fn(&'a mut T) -> bool) {
|
||||
match *self { None => (), Some(ref mut t) => { f(t); } }
|
||||
@ -200,35 +181,12 @@ pub impl<T> Option<T> {
|
||||
* Update an optional value by optionally running its content by reference
|
||||
* through a function that returns an option.
|
||||
*/
|
||||
#[cfg(stage0)]
|
||||
#[inline(always)]
|
||||
fn chain_ref<U>(&self, f: &fn(x: &'self T) -> Option<U>) -> Option<U> {
|
||||
match *self { Some(ref x) => f(x), None => None }
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an optional value by optionally running its content by reference
|
||||
* through a function that returns an option.
|
||||
*/
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
#[inline(always)]
|
||||
fn chain_ref<'a, U>(&'a self, f: &fn(x: &'a T) -> Option<U>) -> Option<U> {
|
||||
match *self { Some(ref x) => f(x), None => None }
|
||||
}
|
||||
|
||||
/// Maps a `some` value from one type to another by reference
|
||||
#[cfg(stage0)]
|
||||
#[inline(always)]
|
||||
fn map<U>(&self, f: &fn(&'self T) -> U) -> Option<U> {
|
||||
match *self { Some(ref x) => Some(f(x)), None => None }
|
||||
}
|
||||
|
||||
/// Maps a `some` value from one type to another by reference
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
#[inline(always)]
|
||||
fn map<'a, U>(&self, f: &fn(&'a T) -> U) -> Option<U> {
|
||||
match *self { Some(ref x) => Some(f(x)), None => None }
|
||||
@ -242,16 +200,6 @@ pub impl<T> Option<T> {
|
||||
}
|
||||
|
||||
/// Applies a function to the contained value or returns a default
|
||||
#[cfg(stage0)]
|
||||
#[inline(always)]
|
||||
fn map_default<U>(&self, def: U, f: &fn(&'self T) -> U) -> U {
|
||||
match *self { None => def, Some(ref t) => f(t) }
|
||||
}
|
||||
|
||||
/// Applies a function to the contained value or returns a default
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
#[inline(always)]
|
||||
fn map_default<'a, U>(&'a self, def: U, f: &fn(&'a T) -> U) -> U {
|
||||
match *self { None => def, Some(ref t) => f(t) }
|
||||
@ -295,32 +243,6 @@ pub impl<T> Option<T> {
|
||||
case explicitly.
|
||||
*/
|
||||
#[inline(always)]
|
||||
#[cfg(stage0)]
|
||||
fn get_ref(&self) -> &'self T {
|
||||
match *self {
|
||||
Some(ref x) => x,
|
||||
None => fail!(~"option::get_ref none")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Gets an immutable reference to the value inside an option.
|
||||
|
||||
# Failure
|
||||
|
||||
Fails if the value equals `None`
|
||||
|
||||
# Safety note
|
||||
|
||||
In general, because this function may fail, its use is discouraged
|
||||
(calling `get` on `None` is akin to dereferencing a null pointer).
|
||||
Instead, prefer to use pattern matching and handle the `None`
|
||||
case explicitly.
|
||||
*/
|
||||
#[inline(always)]
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn get_ref<'a>(&'a self) -> &'a T {
|
||||
match *self {
|
||||
Some(ref x) => x,
|
||||
@ -343,32 +265,6 @@ pub impl<T> Option<T> {
|
||||
case explicitly.
|
||||
*/
|
||||
#[inline(always)]
|
||||
#[cfg(stage0)]
|
||||
fn get_mut_ref(&mut self) -> &'self mut T {
|
||||
match *self {
|
||||
Some(ref mut x) => x,
|
||||
None => fail!(~"option::get_mut_ref none")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Gets a mutable reference to the value inside an option.
|
||||
|
||||
# Failure
|
||||
|
||||
Fails if the value equals `None`
|
||||
|
||||
# Safety note
|
||||
|
||||
In general, because this function may fail, its use is discouraged
|
||||
(calling `get` on `None` is akin to dereferencing a null pointer).
|
||||
Instead, prefer to use pattern matching and handle the `None`
|
||||
case explicitly.
|
||||
*/
|
||||
#[inline(always)]
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn get_mut_ref<'a>(&'a mut self) -> &'a mut T {
|
||||
match *self {
|
||||
Some(ref mut x) => x,
|
||||
|
@ -14,9 +14,6 @@
|
||||
|
||||
pub use either::{Either, Left, Right};
|
||||
pub use kinds::{Const, Copy, Owned, Durable};
|
||||
#[cfg(stage0)]
|
||||
pub use ops::{Add, Sub, Mul, Div, Modulo, Neg, Not};
|
||||
#[cfg(not(stage0))]
|
||||
pub use ops::{Add, Sub, Mul, Div, Rem, Neg, Not};
|
||||
pub use ops::{BitAnd, BitOr, BitXor};
|
||||
pub use ops::{Drop};
|
||||
|
@ -15,7 +15,7 @@ Runtime type reflection
|
||||
*/
|
||||
|
||||
use intrinsic::{TyDesc, TyVisitor};
|
||||
#[cfg(not(stage0))] use intrinsic::Opaque;
|
||||
use intrinsic::Opaque;
|
||||
use libc::c_void;
|
||||
use sys;
|
||||
use vec;
|
||||
@ -394,17 +394,6 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn visit_enter_enum(&self, n_variants: uint, sz: uint, align: uint)
|
||||
-> bool {
|
||||
self.align(align);
|
||||
if ! self.inner.visit_enter_enum(n_variants, sz, align) {
|
||||
return false;
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
fn visit_enter_enum(&self, n_variants: uint,
|
||||
get_disr: extern unsafe fn(ptr: *Opaque) -> int,
|
||||
sz: uint, align: uint)
|
||||
@ -428,15 +417,6 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn visit_enum_variant_field(&self, i: uint, inner: *TyDesc) -> bool {
|
||||
unsafe { self.align((*inner).align); }
|
||||
if ! self.inner.visit_enum_variant_field(i, inner) { return false; }
|
||||
unsafe { self.bump((*inner).size); }
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
fn visit_enum_variant_field(&self, i: uint, offset: uint, inner: *TyDesc) -> bool {
|
||||
self.inner.push_ptr();
|
||||
self.bump(offset);
|
||||
@ -457,17 +437,6 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn visit_leave_enum(&self, n_variants: uint, sz: uint, align: uint)
|
||||
-> bool {
|
||||
if ! self.inner.visit_leave_enum(n_variants, sz, align) {
|
||||
return false;
|
||||
}
|
||||
self.bump(sz);
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
fn visit_leave_enum(&self, n_variants: uint,
|
||||
get_disr: extern unsafe fn(ptr: *Opaque) -> int,
|
||||
sz: uint, align: uint) -> bool {
|
||||
|
@ -18,12 +18,11 @@ use cast::transmute;
|
||||
use char;
|
||||
use intrinsic;
|
||||
use intrinsic::{TyDesc, TyVisitor, visit_tydesc};
|
||||
#[cfg(not(stage0))] use intrinsic::Opaque;
|
||||
use intrinsic::Opaque;
|
||||
use io::{Writer, WriterUtil};
|
||||
use libc::c_void;
|
||||
use managed;
|
||||
use ptr;
|
||||
#[cfg(stage0)] use sys;
|
||||
use reflect;
|
||||
use reflect::{MovePtr, align};
|
||||
use to_str::ToStr;
|
||||
@ -138,14 +137,6 @@ impl Repr for char {
|
||||
|
||||
// New implementation using reflect::MovePtr
|
||||
|
||||
#[cfg(stage0)]
|
||||
enum VariantState {
|
||||
Degenerate,
|
||||
TagMatch,
|
||||
TagMismatch,
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
enum VariantState {
|
||||
SearchingFor(int),
|
||||
Matched,
|
||||
@ -190,18 +181,6 @@ pub impl ReprVisitor {
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(stage0)] #[inline(always)]
|
||||
fn bump(&self, sz: uint) {
|
||||
do self.move_ptr() |p| {
|
||||
((p as uint) + sz) as *c_void
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(stage0)] #[inline(always)]
|
||||
fn bump_past<T>(&self) {
|
||||
self.bump(sys::size_of::<T>());
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn visit_inner(&self, inner: *TyDesc) -> bool {
|
||||
self.visit_ptr_inner(self.ptr, inner)
|
||||
@ -467,18 +446,6 @@ impl TyVisitor for ReprVisitor {
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn visit_enter_enum(&self, n_variants: uint,
|
||||
_sz: uint, _align: uint) -> bool {
|
||||
if n_variants == 1 {
|
||||
self.var_stk.push(Degenerate)
|
||||
} else {
|
||||
self.var_stk.push(TagMatch)
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
fn visit_enter_enum(&self, _n_variants: uint,
|
||||
get_disr: extern unsafe fn(ptr: *Opaque) -> int,
|
||||
_sz: uint, _align: uint) -> bool {
|
||||
@ -487,40 +454,6 @@ impl TyVisitor for ReprVisitor {
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
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() {
|
||||
Degenerate => {
|
||||
write = true;
|
||||
self.var_stk.push(Degenerate);
|
||||
}
|
||||
TagMatch | TagMismatch => {
|
||||
do self.get::<int>() |t| {
|
||||
if disr_val == *t {
|
||||
write = true;
|
||||
self.var_stk.push(TagMatch);
|
||||
} else {
|
||||
self.var_stk.push(TagMismatch);
|
||||
}
|
||||
};
|
||||
self.bump_past::<int>();
|
||||
}
|
||||
}
|
||||
|
||||
if write {
|
||||
self.writer.write_str(name);
|
||||
if n_fields > 0 {
|
||||
self.writer.write_char('(');
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
fn visit_enter_enum_variant(&self, _variant: uint,
|
||||
disr_val: int,
|
||||
n_fields: uint,
|
||||
@ -549,23 +482,6 @@ impl TyVisitor for ReprVisitor {
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn visit_enum_variant_field(&self, i: uint, inner: *TyDesc) -> bool {
|
||||
match self.var_stk[vec::uniq_len(&const self.var_stk) - 1] {
|
||||
Degenerate | TagMatch => {
|
||||
if i != 0 {
|
||||
self.writer.write_str(", ");
|
||||
}
|
||||
if ! self.visit_inner(inner) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
TagMismatch => ()
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
fn visit_enum_variant_field(&self, i: uint, _offset: uint, inner: *TyDesc) -> bool {
|
||||
match self.var_stk[vec::uniq_len(&const self.var_stk) - 1] {
|
||||
Matched => {
|
||||
@ -581,23 +497,6 @@ impl TyVisitor for ReprVisitor {
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn visit_leave_enum_variant(&self, _variant: uint,
|
||||
_disr_val: int,
|
||||
n_fields: uint,
|
||||
_name: &str) -> bool {
|
||||
match self.var_stk[vec::uniq_len(&const self.var_stk) - 1] {
|
||||
Degenerate | TagMatch => {
|
||||
if n_fields > 0 {
|
||||
self.writer.write_char(')');
|
||||
}
|
||||
}
|
||||
TagMismatch => ()
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
fn visit_leave_enum_variant(&self, _variant: uint,
|
||||
_disr_val: int,
|
||||
n_fields: uint,
|
||||
@ -613,14 +512,6 @@ impl TyVisitor for ReprVisitor {
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn visit_leave_enum(&self, _n_variants: uint,
|
||||
_sz: uint, _align: uint) -> bool {
|
||||
self.var_stk.pop();
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
fn visit_leave_enum(&self, _n_variants: uint,
|
||||
_get_disr: extern unsafe fn(ptr: *Opaque) -> int,
|
||||
_sz: uint, _align: uint) -> bool {
|
||||
|
@ -226,13 +226,6 @@ pub fn map_err<T:Copy,E,F:Copy>(res: &Result<T, E>, op: &fn(&E) -> F)
|
||||
}
|
||||
|
||||
pub impl<T, E> Result<T, E> {
|
||||
#[cfg(stage0)]
|
||||
#[inline(always)]
|
||||
fn get_ref(&self) -> &'self T { get_ref(self) }
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
#[inline(always)]
|
||||
fn get_ref<'a>(&'a self) -> &'a T { get_ref(self) }
|
||||
|
||||
|
@ -275,7 +275,6 @@ pub mod net {
|
||||
}
|
||||
|
||||
/// Readers and Writers for memory buffers and strings.
|
||||
#[cfg(not(stage0))] // XXX Using unsnapshotted features
|
||||
pub mod mem;
|
||||
|
||||
/// Non-blocking access to stdin, stdout, stderr
|
||||
@ -286,11 +285,9 @@ pub mod stdio;
|
||||
mod option;
|
||||
|
||||
/// Basic stream compression. XXX: Belongs with other flate code
|
||||
#[cfg(not(stage0))] // XXX Using unsnapshotted features
|
||||
pub mod flate;
|
||||
|
||||
/// Interop between byte streams and pipes. Not sure where it belongs
|
||||
#[cfg(not(stage0))] // XXX "
|
||||
pub mod comm_adapters;
|
||||
|
||||
/// Extension traits
|
||||
|
@ -37,27 +37,6 @@ mod local_heap;
|
||||
#[cfg(test)]
|
||||
pub mod test;
|
||||
|
||||
#[cfg(stage0)]
|
||||
pub fn start(main: *u8, _argc: int, _argv: *c_char, _crate_map: *u8) -> int {
|
||||
use self::sched::{Scheduler, Task};
|
||||
use self::uvio::UvEventLoop;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
pub fn start(main: *u8, _argc: int, _argv: **c_char, _crate_map: *u8) -> int {
|
||||
use self::sched::{Scheduler, Task};
|
||||
use self::uvio::UvEventLoop;
|
||||
|
@ -24,11 +24,6 @@ pub trait EventLoop {
|
||||
fn run(&mut self);
|
||||
fn callback(&mut self, ~fn());
|
||||
/// The asynchronous I/O services. Not all event loops may provide one
|
||||
#[cfg(stage0)]
|
||||
fn io(&mut self) -> Option<&'self mut IoFactoryObject>;
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn io<'a>(&'a mut self) -> Option<&'a mut IoFactoryObject>;
|
||||
}
|
||||
|
||||
|
@ -68,14 +68,6 @@ impl EventLoop for UvEventLoop {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn io(&mut self) -> Option<&'self mut IoFactoryObject> {
|
||||
Some(&mut self.uvio)
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn io<'a>(&'a mut self) -> Option<&'a mut IoFactoryObject> {
|
||||
Some(&mut self.uvio)
|
||||
}
|
||||
@ -98,14 +90,6 @@ fn test_callback_run_once() {
|
||||
pub struct UvIoFactory(Loop);
|
||||
|
||||
pub impl UvIoFactory {
|
||||
#[cfg(stage0)]
|
||||
fn uv_loop(&mut self) -> &'self mut Loop {
|
||||
match self { &UvIoFactory(ref mut ptr) => ptr }
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn uv_loop<'a>(&'a mut self) -> &'a mut Loop {
|
||||
match self { &UvIoFactory(ref mut ptr) => ptr }
|
||||
}
|
||||
|
@ -93,9 +93,6 @@ pub mod rustrt {
|
||||
pub mod rusti {
|
||||
#[abi = "rust-intrinsic"]
|
||||
pub extern "rust-intrinsic" {
|
||||
#[cfg(stage0)]
|
||||
pub fn frame_address(f: &once fn(x: *u8));
|
||||
#[cfg(not(stage0))]
|
||||
pub fn frame_address(+f: &once fn(x: *u8));
|
||||
}
|
||||
}
|
||||
|
@ -200,21 +200,6 @@ impl FailWithCause for &'static str {
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: remove function after snapshot
|
||||
#[cfg(stage0)]
|
||||
pub fn begin_unwind(msg: ~str, file: ~str, line: uint) -> ! {
|
||||
|
||||
do str::as_buf(msg) |msg_buf, _msg_len| {
|
||||
do str::as_buf(file) |file_buf, _file_len| {
|
||||
unsafe {
|
||||
let msg_buf = cast::transmute(msg_buf);
|
||||
let file_buf = cast::transmute(file_buf);
|
||||
begin_unwind_(msg_buf, file_buf, line as libc::size_t)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME #4427: Temporary until rt::rt_fail_ goes away
|
||||
pub fn begin_unwind_(msg: *c_char, file: *c_char, line: size_t) -> ! {
|
||||
use rt::{context, OldTaskContext};
|
||||
@ -242,13 +227,6 @@ pub fn begin_unwind_(msg: *c_char, file: *c_char, line: size_t) -> ! {
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: remove function after snapshot
|
||||
#[cfg(stage0)]
|
||||
pub fn fail_assert(msg: &str, file: &str, line: uint) -> ! {
|
||||
let (msg, file) = (msg.to_owned(), file.to_owned());
|
||||
begin_unwind(~"assertion failed: " + msg, file, line)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use cast;
|
||||
|
@ -56,16 +56,6 @@ impl<T> Map<uint, T> for TrieMap<T> {
|
||||
|
||||
/// Visit all key-value pairs in order
|
||||
#[inline(always)]
|
||||
#[cfg(stage0)]
|
||||
fn each(&self, f: &fn(&uint, &'self T) -> bool) {
|
||||
self.root.each(f);
|
||||
}
|
||||
|
||||
/// Visit all key-value pairs in order
|
||||
#[inline(always)]
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn each<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) {
|
||||
self.root.each(f);
|
||||
}
|
||||
@ -78,16 +68,6 @@ impl<T> Map<uint, T> for TrieMap<T> {
|
||||
|
||||
/// Visit all values in order
|
||||
#[inline(always)]
|
||||
#[cfg(stage0)]
|
||||
fn each_value(&self, f: &fn(&T) -> bool) {
|
||||
self.each(|_, v| f(v))
|
||||
}
|
||||
|
||||
/// Visit all values in order
|
||||
#[inline(always)]
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn each_value<'a>(&'a self, f: &fn(&'a T) -> bool) {
|
||||
self.each(|_, v| f(v))
|
||||
}
|
||||
@ -99,31 +79,6 @@ impl<T> Map<uint, T> for TrieMap<T> {
|
||||
}
|
||||
|
||||
/// Return a reference to the value corresponding to the key
|
||||
#[cfg(stage0)]
|
||||
#[inline(hint)]
|
||||
fn find(&self, key: &uint) -> Option<&'self T> {
|
||||
let mut node: &'self TrieNode<T> = &self.root;
|
||||
let mut idx = 0;
|
||||
loop {
|
||||
match node.children[chunk(*key, idx)] {
|
||||
Internal(ref x) => node = &**x,
|
||||
External(stored, ref value) => {
|
||||
if stored == *key {
|
||||
return Some(value)
|
||||
} else {
|
||||
return None
|
||||
}
|
||||
}
|
||||
Nothing => return None
|
||||
}
|
||||
idx += 1;
|
||||
}
|
||||
}
|
||||
|
||||
/// Return a reference to the value corresponding to the key
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
#[inline(hint)]
|
||||
fn find<'a>(&'a self, key: &uint) -> Option<&'a T> {
|
||||
let mut node: &'a TrieNode<T> = &self.root;
|
||||
@ -145,16 +100,6 @@ impl<T> Map<uint, T> for TrieMap<T> {
|
||||
}
|
||||
|
||||
/// Return a mutable reference to the value corresponding to the key
|
||||
#[cfg(stage0)]
|
||||
#[inline(always)]
|
||||
fn find_mut(&mut self, key: &uint) -> Option<&'self mut T> {
|
||||
find_mut(&mut self.root.children[chunk(*key, 0)], *key, 1)
|
||||
}
|
||||
|
||||
/// Return a mutable reference to the value corresponding to the key
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
#[inline(always)]
|
||||
fn find_mut<'a>(&'a mut self, key: &uint) -> Option<&'a mut T> {
|
||||
find_mut(&mut self.root.children[chunk(*key, 0)], *key, 1)
|
||||
@ -193,16 +138,6 @@ pub impl<T> TrieMap<T> {
|
||||
|
||||
/// Visit all key-value pairs in reverse order
|
||||
#[inline(always)]
|
||||
#[cfg(stage0)]
|
||||
fn each_reverse(&self, f: &fn(&uint, &'self T) -> bool) {
|
||||
self.root.each_reverse(f);
|
||||
}
|
||||
|
||||
/// Visit all key-value pairs in reverse order
|
||||
#[inline(always)]
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn each_reverse<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) {
|
||||
self.root.each_reverse(f);
|
||||
}
|
||||
@ -298,21 +233,6 @@ impl<T> TrieNode<T> {
|
||||
}
|
||||
|
||||
impl<T> TrieNode<T> {
|
||||
#[cfg(stage0)]
|
||||
fn each(&self, f: &fn(&uint, &'self T) -> bool) -> bool {
|
||||
for uint::range(0, self.children.len()) |idx| {
|
||||
match self.children[idx] {
|
||||
Internal(ref x) => if !x.each(f) { return false },
|
||||
External(k, ref v) => if !f(&k, v) { return false },
|
||||
Nothing => ()
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn each<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool {
|
||||
for uint::range(0, self.children.len()) |idx| {
|
||||
match self.children[idx] {
|
||||
@ -324,21 +244,6 @@ impl<T> TrieNode<T> {
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn each_reverse(&self, f: &fn(&uint, &'self T) -> bool) -> bool {
|
||||
for uint::range_rev(self.children.len(), 0) |idx| {
|
||||
match self.children[idx - 1] {
|
||||
Internal(ref x) => if !x.each_reverse(f) { return false },
|
||||
External(k, ref v) => if !f(&k, v) { return false },
|
||||
Nothing => ()
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn each_reverse<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool {
|
||||
for uint::range_rev(self.children.len(), 0) |idx| {
|
||||
match self.children[idx - 1] {
|
||||
|
@ -56,39 +56,11 @@ impl<T:Clone,U:Clone> Clone for (T, U) {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
pub trait ImmutableTuple<T, U> {
|
||||
fn first_ref(&self) -> &'self T;
|
||||
fn second_ref(&self) -> &'self U;
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<T, U> ImmutableTuple<T, U> for (T, U) {
|
||||
#[inline(always)]
|
||||
fn first_ref(&self) -> &'self T {
|
||||
match *self {
|
||||
(ref t, _) => t,
|
||||
}
|
||||
}
|
||||
#[inline(always)]
|
||||
fn second_ref(&self) -> &'self U {
|
||||
match *self {
|
||||
(_, ref u) => u,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
pub trait ImmutableTuple<T, U> {
|
||||
fn first_ref<'a>(&'a self) -> &'a T;
|
||||
fn second_ref<'a>(&'a self) -> &'a U;
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
impl<T, U> ImmutableTuple<T, U> for (T, U) {
|
||||
#[inline(always)]
|
||||
fn first_ref<'a>(&'a self) -> &'a T {
|
||||
|
@ -46,10 +46,6 @@ pub extern "rust-intrinsic" {
|
||||
|
||||
pub fn forget<T>(_: T) -> ();
|
||||
|
||||
// XXX: intrinsic uses legacy modes
|
||||
#[cfg(stage0)]
|
||||
fn reinterpret_cast<T,U>(&&src: T) -> U;
|
||||
|
||||
pub fn needs_drop<T>() -> bool;
|
||||
|
||||
// XXX: intrinsic uses legacy modes and has reference to TyDesc
|
||||
|
@ -17,9 +17,7 @@ use str;
|
||||
use sys;
|
||||
use unstable::exchange_alloc;
|
||||
use cast::transmute;
|
||||
#[cfg(not(stage0))]
|
||||
use rt::{context, OldTaskContext};
|
||||
#[cfg(not(stage0))]
|
||||
use rt::local_services::borrow_local_services;
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
@ -91,14 +89,6 @@ pub unsafe fn exchange_free(ptr: *c_char) {
|
||||
}
|
||||
|
||||
#[lang="malloc"]
|
||||
#[inline(always)]
|
||||
#[cfg(stage0)] // For some reason this isn't working on windows in stage0
|
||||
pub unsafe fn local_malloc(td: *c_char, size: uintptr_t) -> *c_char {
|
||||
return rustrt::rust_upcall_malloc_noswitch(td, size);
|
||||
}
|
||||
|
||||
#[lang="malloc"]
|
||||
#[cfg(not(stage0))]
|
||||
pub unsafe fn local_malloc(td: *c_char, size: uintptr_t) -> *c_char {
|
||||
match context() {
|
||||
OldTaskContext => {
|
||||
@ -118,17 +108,6 @@ pub unsafe fn local_malloc(td: *c_char, size: uintptr_t) -> *c_char {
|
||||
// inside a landing pad may corrupt the state of the exception handler. If a
|
||||
// problem occurs, call exit instead.
|
||||
#[lang="free"]
|
||||
#[inline(always)]
|
||||
#[cfg(stage0)]
|
||||
pub unsafe fn local_free(ptr: *c_char) {
|
||||
rustrt::rust_upcall_free_noswitch(ptr);
|
||||
}
|
||||
|
||||
// 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"]
|
||||
#[cfg(not(stage0))]
|
||||
pub unsafe fn local_free(ptr: *c_char) {
|
||||
match context() {
|
||||
OldTaskContext => {
|
||||
@ -176,32 +155,6 @@ pub unsafe fn strdup_uniq(ptr: *c_uchar, len: uint) -> ~str {
|
||||
}
|
||||
|
||||
#[lang="start"]
|
||||
#[cfg(stage0)]
|
||||
pub fn start(main: *u8, argc: int, argv: *c_char,
|
||||
crate_map: *u8) -> int {
|
||||
use libc::getenv;
|
||||
use rt::start;
|
||||
|
||||
unsafe {
|
||||
let use_old_rt = do str::as_c_str("RUST_NEWRT") |s| {
|
||||
getenv(s).is_null()
|
||||
};
|
||||
if use_old_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;
|
||||
}
|
||||
}
|
||||
|
||||
#[lang="start"]
|
||||
#[cfg(not(stage0))]
|
||||
pub fn start(main: *u8, argc: int, argv: **c_char,
|
||||
crate_map: *u8) -> int {
|
||||
use libc::getenv;
|
||||
|
@ -19,9 +19,6 @@ use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
|
||||
use clone::Clone;
|
||||
use old_iter::BaseIter;
|
||||
use old_iter;
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
use iterator::Iterator;
|
||||
use kinds::Copy;
|
||||
use libc;
|
||||
@ -1566,16 +1563,6 @@ pub fn each_permutation<T:Copy>(v: &[T], put: &fn(ts: &[T]) -> bool) {
|
||||
}
|
||||
}
|
||||
|
||||
// see doc below
|
||||
#[cfg(stage0)] // XXX: lifetimes!
|
||||
pub fn windowed<T>(n: uint, v: &[T], it: &fn(&[T]) -> bool) {
|
||||
assert!(1u <= n);
|
||||
if n > v.len() { return; }
|
||||
for uint::range(0, v.len() - n + 1) |i| {
|
||||
if !it(v.slice(i, i+n)) { return }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate over all contiguous windows of length `n` of the vector `v`.
|
||||
*
|
||||
@ -1590,9 +1577,6 @@ pub fn windowed<T>(n: uint, v: &[T], it: &fn(&[T]) -> bool) {
|
||||
* ~~~
|
||||
*
|
||||
*/
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
pub fn windowed<'r, T>(n: uint, v: &'r [T], it: &fn(&'r [T]) -> bool) {
|
||||
assert!(1u <= n);
|
||||
if n > v.len() { return; }
|
||||
@ -1854,150 +1838,6 @@ impl<'self,T:Copy> CopyableVector<T> for &'self const [T] {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
pub trait ImmutableVector<T> {
|
||||
fn slice(&self, start: uint, end: uint) -> &'self [T];
|
||||
fn head(&self) -> &'self T;
|
||||
fn head_opt(&self) -> Option<&'self T>;
|
||||
fn tail(&self) -> &'self [T];
|
||||
fn tailn(&self, n: uint) -> &'self [T];
|
||||
fn init(&self) -> &'self [T];
|
||||
fn initn(&self, n: uint) -> &'self [T];
|
||||
fn last(&self) -> &'self T;
|
||||
fn last_opt(&self) -> Option<&'self T>;
|
||||
fn each_reverse(&self, blk: &fn(&T) -> bool);
|
||||
fn eachi_reverse(&self, blk: &fn(uint, &T) -> bool);
|
||||
fn foldr<U: Copy>(&self, z: U, p: &fn(t: &T, u: U) -> U) -> U;
|
||||
fn map<U>(&self, f: &fn(t: &T) -> U) -> ~[U];
|
||||
fn mapi<U>(&self, f: &fn(uint, t: &T) -> U) -> ~[U];
|
||||
fn map_r<U>(&self, f: &fn(x: &T) -> U) -> ~[U];
|
||||
fn alli(&self, f: &fn(uint, t: &T) -> bool) -> bool;
|
||||
fn flat_map<U>(&self, f: &fn(t: &T) -> ~[U]) -> ~[U];
|
||||
fn filter_mapped<U:Copy>(&self, f: &fn(t: &T) -> Option<U>) -> ~[U];
|
||||
unsafe fn unsafe_ref(&self, index: uint) -> *T;
|
||||
}
|
||||
|
||||
/// Extension methods for vectors
|
||||
#[cfg(stage0)]
|
||||
impl<'self,T> ImmutableVector<T> for &'self [T] {
|
||||
/// Return a slice that points into another slice.
|
||||
#[inline]
|
||||
fn slice(&self, start: uint, end: uint) -> &'self [T] {
|
||||
slice(*self, start, end)
|
||||
}
|
||||
|
||||
/// Returns the first element of a vector, failing if the vector is empty.
|
||||
#[inline]
|
||||
fn head(&self) -> &'self T { head(*self) }
|
||||
|
||||
/// Returns the first element of a vector
|
||||
#[inline]
|
||||
fn head_opt(&self) -> Option<&'self T> { head_opt(*self) }
|
||||
|
||||
/// Returns all but the first element of a vector
|
||||
#[inline]
|
||||
fn tail(&self) -> &'self [T] { tail(*self) }
|
||||
|
||||
/// Returns all but the first `n' elements of a vector
|
||||
#[inline]
|
||||
fn tailn(&self, n: uint) -> &'self [T] { tailn(*self, n) }
|
||||
|
||||
/// Returns all but the last elemnt of a vector
|
||||
#[inline]
|
||||
fn init(&self) -> &'self [T] { init(*self) }
|
||||
|
||||
/// Returns all but the last `n' elemnts of a vector
|
||||
#[inline]
|
||||
fn initn(&self, n: uint) -> &'self [T] { initn(*self, n) }
|
||||
|
||||
/// Returns the last element of a `v`, failing if the vector is empty.
|
||||
#[inline]
|
||||
fn last(&self) -> &'self T { last(*self) }
|
||||
|
||||
/// Returns the last element of a `v`, failing if the vector is empty.
|
||||
#[inline]
|
||||
fn last_opt(&self) -> Option<&'self T> { last_opt(*self) }
|
||||
|
||||
/// Iterates over a vector's elements in reverse.
|
||||
#[inline]
|
||||
fn each_reverse(&self, blk: &fn(&T) -> bool) {
|
||||
each_reverse(*self, blk)
|
||||
}
|
||||
|
||||
/// Iterates over a vector's elements and indices in reverse.
|
||||
#[inline]
|
||||
fn eachi_reverse(&self, blk: &fn(uint, &T) -> bool) {
|
||||
eachi_reverse(*self, blk)
|
||||
}
|
||||
|
||||
/// Reduce a vector from right to left
|
||||
#[inline]
|
||||
fn foldr<U:Copy>(&self, z: U, p: &fn(t: &T, u: U) -> U) -> U {
|
||||
foldr(*self, z, p)
|
||||
}
|
||||
|
||||
/// Apply a function to each element of a vector and return the results
|
||||
#[inline]
|
||||
fn map<U>(&self, f: &fn(t: &T) -> U) -> ~[U] { map(*self, f) }
|
||||
|
||||
/**
|
||||
* Apply a function to the index and value of each element in the vector
|
||||
* and return the results
|
||||
*/
|
||||
fn mapi<U>(&self, f: &fn(uint, t: &T) -> U) -> ~[U] {
|
||||
mapi(*self, f)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn map_r<U>(&self, f: &fn(x: &T) -> U) -> ~[U] {
|
||||
let mut r = ~[];
|
||||
let mut i = 0;
|
||||
while i < self.len() {
|
||||
r.push(f(&self[i]));
|
||||
i += 1;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the function returns true for all elements.
|
||||
*
|
||||
* If the vector is empty, true is returned.
|
||||
*/
|
||||
fn alli(&self, f: &fn(uint, t: &T) -> bool) -> bool {
|
||||
alli(*self, f)
|
||||
}
|
||||
/**
|
||||
* Apply a function to each element of a vector and return a concatenation
|
||||
* of each result vector
|
||||
*/
|
||||
#[inline]
|
||||
fn flat_map<U>(&self, f: &fn(t: &T) -> ~[U]) -> ~[U] {
|
||||
flat_map(*self, f)
|
||||
}
|
||||
/**
|
||||
* Apply a function to each element of a vector and return the results
|
||||
*
|
||||
* If function `f` returns `none` then that element is excluded from
|
||||
* the resulting vector.
|
||||
*/
|
||||
#[inline]
|
||||
fn filter_mapped<U:Copy>(&self, f: &fn(t: &T) -> Option<U>) -> ~[U] {
|
||||
filter_mapped(*self, f)
|
||||
}
|
||||
|
||||
/// Returns a pointer to the element at the given index, without doing
|
||||
/// bounds checking.
|
||||
#[inline(always)]
|
||||
unsafe fn unsafe_ref(&self, index: uint) -> *T {
|
||||
let (ptr, _): (*T, uint) = transmute(*self);
|
||||
ptr.offset(index)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
pub trait ImmutableVector<'self, T> {
|
||||
fn slice(&self, start: uint, end: uint) -> &'self [T];
|
||||
fn iter(self) -> VecIterator<'self, T>;
|
||||
@ -2022,9 +1862,6 @@ pub trait ImmutableVector<'self, T> {
|
||||
}
|
||||
|
||||
/// Extension methods for vectors
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
|
||||
/// Return a slice that points into another slice.
|
||||
#[inline]
|
||||
@ -2634,17 +2471,6 @@ pub mod bytes {
|
||||
// ___________________________________________________________________________
|
||||
// ITERATION TRAIT METHODS
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<'self,A> old_iter::BaseIter<A> for &'self [A] {
|
||||
#[inline(always)]
|
||||
fn each(&self, blk: &fn(v: &'self A) -> bool) { each(*self, blk) }
|
||||
#[inline(always)]
|
||||
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
impl<'self,A> old_iter::BaseIter<A> for &'self [A] {
|
||||
#[inline(always)]
|
||||
fn each<'a>(&'a self, blk: &fn(v: &'a A) -> bool) { each(*self, blk) }
|
||||
@ -2653,18 +2479,6 @@ impl<'self,A> old_iter::BaseIter<A> for &'self [A] {
|
||||
}
|
||||
|
||||
// FIXME(#4148): This should be redundant
|
||||
#[cfg(stage0)]
|
||||
impl<A> old_iter::BaseIter<A> for ~[A] {
|
||||
#[inline(always)]
|
||||
fn each(&self, blk: &fn(v: &'self A) -> bool) { each(*self, blk) }
|
||||
#[inline(always)]
|
||||
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
|
||||
}
|
||||
|
||||
// FIXME(#4148): This should be redundant
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
impl<A> old_iter::BaseIter<A> for ~[A] {
|
||||
#[inline(always)]
|
||||
fn each<'a>(&'a self, blk: &fn(v: &'a A) -> bool) { each(*self, blk) }
|
||||
@ -2673,18 +2487,6 @@ impl<A> old_iter::BaseIter<A> for ~[A] {
|
||||
}
|
||||
|
||||
// FIXME(#4148): This should be redundant
|
||||
#[cfg(stage0)]
|
||||
impl<A> old_iter::BaseIter<A> for @[A] {
|
||||
#[inline(always)]
|
||||
fn each(&self, blk: &fn(v: &'self A) -> bool) { each(*self, blk) }
|
||||
#[inline(always)]
|
||||
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
|
||||
}
|
||||
|
||||
// FIXME(#4148): This should be redundant
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
impl<A> old_iter::BaseIter<A> for @[A] {
|
||||
#[inline(always)]
|
||||
fn each<'a>(&'a self, blk: &fn(v: &'a A) -> bool) { each(*self, blk) }
|
||||
@ -2692,17 +2494,6 @@ impl<A> old_iter::BaseIter<A> for @[A] {
|
||||
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<'self,A> old_iter::MutableIter<A> for &'self mut [A] {
|
||||
#[inline(always)]
|
||||
fn each_mut(&mut self, blk: &fn(v: &'self mut A) -> bool) {
|
||||
each_mut(*self, blk)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
impl<'self,A> old_iter::MutableIter<A> for &'self mut [A] {
|
||||
#[inline(always)]
|
||||
fn each_mut<'a>(&'a mut self, blk: &fn(v: &'a mut A) -> bool) {
|
||||
@ -2711,17 +2502,6 @@ impl<'self,A> old_iter::MutableIter<A> for &'self mut [A] {
|
||||
}
|
||||
|
||||
// FIXME(#4148): This should be redundant
|
||||
#[cfg(stage0)]
|
||||
impl<A> old_iter::MutableIter<A> for ~[A] {
|
||||
#[inline(always)]
|
||||
fn each_mut(&mut self, blk: &fn(v: &'self mut A) -> bool) {
|
||||
each_mut(*self, blk)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
impl<A> old_iter::MutableIter<A> for ~[A] {
|
||||
#[inline(always)]
|
||||
fn each_mut<'a>(&'a mut self, blk: &fn(v: &'a mut A) -> bool) {
|
||||
@ -2927,18 +2707,12 @@ impl<A:Clone> Clone for ~[A] {
|
||||
}
|
||||
|
||||
// could be implemented with &[T] with .slice(), but this avoids bounds checks
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
pub struct VecIterator<'self, T> {
|
||||
priv ptr: *T,
|
||||
priv end: *T,
|
||||
priv lifetime: &'self T // FIXME: #5922
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
impl<'self, T> Iterator<&'self T> for VecIterator<'self, T> {
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<&'self T> {
|
||||
|
@ -272,14 +272,6 @@ fn item_ty_param_defs(item: ebml::Doc, tcx: ty::ctxt, cdata: cmd,
|
||||
@bounds
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn item_ty_region_param(item: ebml::Doc) -> Option<ty::region_variance> {
|
||||
reader::maybe_get_doc(item, tag_region_param).map(|doc| {
|
||||
Decodable::decode(&reader::Decoder(*doc))
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
fn item_ty_region_param(item: ebml::Doc) -> Option<ty::region_variance> {
|
||||
reader::maybe_get_doc(item, tag_region_param).map(|doc| {
|
||||
let mut decoder = reader::Decoder(*doc);
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -203,21 +203,6 @@ pub impl Arena {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(stage0)]
|
||||
priv fn alloc_pod<T>(&mut self, op: &fn() -> T) -> &'self T {
|
||||
unsafe {
|
||||
let tydesc = sys::get_type_desc::<T>();
|
||||
let ptr = self.alloc_pod_inner((*tydesc).size, (*tydesc).align);
|
||||
let ptr: *mut T = transmute(ptr);
|
||||
rusti::move_val_init(&mut (*ptr), op());
|
||||
return transmute(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
priv fn alloc_pod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
|
||||
unsafe {
|
||||
let tydesc = sys::get_type_desc::<T>();
|
||||
@ -265,31 +250,6 @@ pub impl Arena {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(stage0)]
|
||||
priv fn alloc_nonpod<T>(&mut self, op: &fn() -> T) -> &'self T {
|
||||
unsafe {
|
||||
let tydesc = sys::get_type_desc::<T>();
|
||||
let (ty_ptr, ptr) =
|
||||
self.alloc_nonpod_inner((*tydesc).size, (*tydesc).align);
|
||||
let ty_ptr: *mut uint = transmute(ty_ptr);
|
||||
let ptr: *mut T = transmute(ptr);
|
||||
// Write in our tydesc along with a bit indicating that it
|
||||
// has *not* been initialized yet.
|
||||
*ty_ptr = transmute(tydesc);
|
||||
// Actually initialize it
|
||||
rusti::move_val_init(&mut(*ptr), op());
|
||||
// Now that we are done, update the tydesc to indicate that
|
||||
// the object is there.
|
||||
*ty_ptr = bitpack_tydesc_ptr(tydesc, true);
|
||||
|
||||
return transmute(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
priv fn alloc_nonpod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
|
||||
unsafe {
|
||||
let tydesc = sys::get_type_desc::<T>();
|
||||
@ -312,25 +272,6 @@ pub impl Arena {
|
||||
|
||||
// The external interface
|
||||
#[inline(always)]
|
||||
#[cfg(stage0)]
|
||||
fn alloc<T>(&mut self, op: &fn() -> T) -> &'self T {
|
||||
unsafe {
|
||||
// XXX: Borrow check
|
||||
let this = transmute_mut_region(self);
|
||||
if !rusti::needs_drop::<T>() {
|
||||
return this.alloc_pod(op);
|
||||
}
|
||||
// XXX: Borrow check
|
||||
let this = transmute_mut_region(self);
|
||||
this.alloc_nonpod(op)
|
||||
}
|
||||
}
|
||||
|
||||
// The external interface
|
||||
#[inline(always)]
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn alloc<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
|
||||
unsafe {
|
||||
// XXX: Borrow check
|
||||
|
@ -37,128 +37,6 @@ impl<T> Mutable for Deque<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
pub impl<T> Deque<T> {
|
||||
/// Create an empty Deque
|
||||
fn new() -> Deque<T> {
|
||||
Deque{nelts: 0, lo: 0, hi: 0,
|
||||
elts: vec::from_fn(initial_capacity, |_| None)}
|
||||
}
|
||||
|
||||
/// Return a reference to the first element in the deque
|
||||
///
|
||||
/// Fails if the deque is empty
|
||||
#[cfg(stage0)]
|
||||
fn peek_front(&self) -> &'self T { get(self.elts, self.lo) }
|
||||
|
||||
/// Return a reference to the first element in the deque
|
||||
///
|
||||
/// Fails if the deque is empty
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn peek_front<'a>(&'a self) -> &'a T { get(self.elts, self.lo) }
|
||||
|
||||
/// Return a reference to the last element in the deque
|
||||
///
|
||||
/// Fails if the deque is empty
|
||||
#[cfg(stage0)]
|
||||
fn peek_back(&self) -> &'self T { get(self.elts, self.hi - 1u) }
|
||||
|
||||
/// Return a reference to the last element in the deque
|
||||
///
|
||||
/// Fails if the deque is empty
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn peek_back<'a>(&'a self) -> &'a T { get(self.elts, self.hi - 1u) }
|
||||
|
||||
/// Retrieve an element in the deque by index
|
||||
///
|
||||
/// Fails if there is no element with the given index
|
||||
#[cfg(stage0)]
|
||||
fn get(&self, i: int) -> &'self T {
|
||||
let idx = (self.lo + (i as uint)) % self.elts.len();
|
||||
get(self.elts, idx)
|
||||
}
|
||||
|
||||
/// Retrieve an element in the deque by index
|
||||
///
|
||||
/// Fails if there is no element with the given index
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn get<'a>(&'a self, i: int) -> &'a T {
|
||||
let idx = (self.lo + (i as uint)) % self.elts.len();
|
||||
get(self.elts, idx)
|
||||
}
|
||||
|
||||
/// Iterate over the elements in the deque
|
||||
fn each(&self, f: &fn(&T) -> bool) {
|
||||
self.eachi(|_i, e| f(e))
|
||||
}
|
||||
|
||||
/// Iterate over the elements in the deque by index
|
||||
fn eachi(&self, f: &fn(uint, &T) -> bool) {
|
||||
for uint::range(0, self.nelts) |i| {
|
||||
if !f(i, self.get(i as int)) { return; }
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove and return the first element in the deque
|
||||
///
|
||||
/// Fails if the deque is empty
|
||||
fn pop_front(&mut self) -> T {
|
||||
let result = self.elts[self.lo].swap_unwrap();
|
||||
self.lo = (self.lo + 1u) % self.elts.len();
|
||||
self.nelts -= 1u;
|
||||
result
|
||||
}
|
||||
|
||||
/// Remove and return the last element in the deque
|
||||
///
|
||||
/// Fails if the deque is empty
|
||||
fn pop_back(&mut self) -> T {
|
||||
if self.hi == 0u {
|
||||
self.hi = self.elts.len() - 1u;
|
||||
} else { self.hi -= 1u; }
|
||||
let result = self.elts[self.hi].swap_unwrap();
|
||||
self.elts[self.hi] = None;
|
||||
self.nelts -= 1u;
|
||||
result
|
||||
}
|
||||
|
||||
/// Prepend an element to the deque
|
||||
fn add_front(&mut self, t: T) {
|
||||
let oldlo = self.lo;
|
||||
if self.lo == 0u {
|
||||
self.lo = self.elts.len() - 1u;
|
||||
} else { self.lo -= 1u; }
|
||||
if self.lo == self.hi {
|
||||
self.elts = grow(self.nelts, oldlo, self.elts);
|
||||
self.lo = self.elts.len() - 1u;
|
||||
self.hi = self.nelts;
|
||||
}
|
||||
self.elts[self.lo] = Some(t);
|
||||
self.nelts += 1u;
|
||||
}
|
||||
|
||||
/// Append an element to the deque
|
||||
fn add_back(&mut self, t: T) {
|
||||
if self.lo == self.hi && self.nelts != 0u {
|
||||
self.elts = grow(self.nelts, self.lo, self.elts);
|
||||
self.lo = 0u;
|
||||
self.hi = self.nelts;
|
||||
}
|
||||
self.elts[self.hi] = Some(t);
|
||||
self.hi = (self.hi + 1u) % self.elts.len();
|
||||
self.nelts += 1u;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
pub impl<T> Deque<T> {
|
||||
/// Create an empty Deque
|
||||
fn new() -> Deque<T> {
|
||||
|
@ -263,13 +263,6 @@ pub mod reader {
|
||||
pub fn doc_as_i32(d: Doc) -> i32 { doc_as_u32(d) as i32 }
|
||||
pub fn doc_as_i64(d: Doc) -> i64 { doc_as_u64(d) as i64 }
|
||||
|
||||
#[cfg(stage0)]
|
||||
pub struct Decoder {
|
||||
priv mut parent: Doc,
|
||||
priv mut pos: uint,
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
pub struct Decoder {
|
||||
priv parent: Doc,
|
||||
priv pos: uint,
|
||||
@ -283,25 +276,6 @@ pub mod reader {
|
||||
}
|
||||
|
||||
priv impl Decoder {
|
||||
#[cfg(stage0)]
|
||||
fn _check_label(&self, lbl: &str) {
|
||||
if self.pos < self.parent.end {
|
||||
let TaggedDoc { tag: r_tag, doc: r_doc } =
|
||||
doc_at(self.parent.data, self.pos);
|
||||
|
||||
if r_tag == (EsLabel as uint) {
|
||||
self.pos = r_doc.end;
|
||||
let str = doc_as_str(r_doc);
|
||||
if lbl != str {
|
||||
fail!(fmt!("Expected label %s but found %s",
|
||||
lbl,
|
||||
str));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
fn _check_label(&mut self, lbl: &str) {
|
||||
if self.pos < self.parent.end {
|
||||
let TaggedDoc { tag: r_tag, doc: r_doc } =
|
||||
@ -319,30 +293,6 @@ pub mod reader {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn next_doc(&self, exp_tag: EbmlEncoderTag) -> Doc {
|
||||
debug!(". next_doc(exp_tag=%?)", exp_tag);
|
||||
if self.pos >= self.parent.end {
|
||||
fail!(~"no more documents in current node!");
|
||||
}
|
||||
let TaggedDoc { tag: r_tag, doc: r_doc } =
|
||||
doc_at(self.parent.data, self.pos);
|
||||
debug!("self.parent=%?-%? self.pos=%? r_tag=%? r_doc=%?-%?",
|
||||
copy self.parent.start, copy self.parent.end,
|
||||
copy self.pos, r_tag, r_doc.start, r_doc.end);
|
||||
if r_tag != (exp_tag as uint) {
|
||||
fail!(fmt!("expected EBML doc with tag %? but found tag %?",
|
||||
exp_tag, r_tag));
|
||||
}
|
||||
if r_doc.end > self.parent.end {
|
||||
fail!(fmt!("invalid EBML, child extends to 0x%x, \
|
||||
parent to 0x%x", r_doc.end, self.parent.end));
|
||||
}
|
||||
self.pos = r_doc.end;
|
||||
r_doc
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
fn next_doc(&mut self, exp_tag: EbmlEncoderTag) -> Doc {
|
||||
debug!(". next_doc(exp_tag=%?)", exp_tag);
|
||||
if self.pos >= self.parent.end {
|
||||
@ -365,19 +315,6 @@ pub mod reader {
|
||||
r_doc
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn push_doc<T>(&self, d: Doc, f: &fn() -> T) -> T {
|
||||
let old_parent = self.parent;
|
||||
let old_pos = self.pos;
|
||||
self.parent = d;
|
||||
self.pos = d.start;
|
||||
let r = f();
|
||||
self.parent = old_parent;
|
||||
self.pos = old_pos;
|
||||
r
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
fn push_doc<T>(&mut self, d: Doc, f: &fn() -> T) -> T {
|
||||
let old_parent = self.parent;
|
||||
let old_pos = self.pos;
|
||||
@ -389,14 +326,6 @@ pub mod reader {
|
||||
r
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn _next_uint(&self, exp_tag: EbmlEncoderTag) -> uint {
|
||||
let r = doc_as_u32(self.next_doc(exp_tag));
|
||||
debug!("_next_uint exp_tag=%? result=%?", exp_tag, r);
|
||||
r as uint
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
fn _next_uint(&mut self, exp_tag: EbmlEncoderTag) -> uint {
|
||||
let r = doc_as_u32(self.next_doc(exp_tag));
|
||||
debug!("_next_uint exp_tag=%? result=%?", exp_tag, r);
|
||||
@ -405,14 +334,6 @@ pub mod reader {
|
||||
}
|
||||
|
||||
pub impl Decoder {
|
||||
#[cfg(stage0)]
|
||||
fn read_opaque<R>(&self, op: &fn(Doc) -> R) -> R {
|
||||
do self.push_doc(self.next_doc(EsOpaque)) {
|
||||
op(copy self.parent)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
fn read_opaque<R>(&mut self, op: &fn(&mut Decoder, Doc) -> R) -> R {
|
||||
let doc = self.next_doc(EsOpaque);
|
||||
|
||||
@ -428,188 +349,6 @@ pub mod reader {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl serialize::Decoder for Decoder {
|
||||
fn read_nil(&self) -> () { () }
|
||||
|
||||
fn read_u64(&self) -> u64 { doc_as_u64(self.next_doc(EsU64)) }
|
||||
fn read_u32(&self) -> u32 { doc_as_u32(self.next_doc(EsU32)) }
|
||||
fn read_u16(&self) -> u16 { doc_as_u16(self.next_doc(EsU16)) }
|
||||
fn read_u8 (&self) -> u8 { doc_as_u8 (self.next_doc(EsU8 )) }
|
||||
fn read_uint(&self) -> uint {
|
||||
let v = doc_as_u64(self.next_doc(EsUint));
|
||||
if v > (::core::uint::max_value as u64) {
|
||||
fail!(fmt!("uint %? too large for this architecture", v));
|
||||
}
|
||||
v as uint
|
||||
}
|
||||
|
||||
fn read_i64(&self) -> i64 {
|
||||
doc_as_u64(self.next_doc(EsI64)) as i64
|
||||
}
|
||||
fn read_i32(&self) -> i32 {
|
||||
doc_as_u32(self.next_doc(EsI32)) as i32
|
||||
}
|
||||
fn read_i16(&self) -> i16 {
|
||||
doc_as_u16(self.next_doc(EsI16)) as i16
|
||||
}
|
||||
fn read_i8 (&self) -> i8 {
|
||||
doc_as_u8(self.next_doc(EsI8 )) as i8
|
||||
}
|
||||
fn read_int(&self) -> int {
|
||||
let v = doc_as_u64(self.next_doc(EsInt)) as i64;
|
||||
if v > (int::max_value as i64) || v < (int::min_value as i64) {
|
||||
fail!(fmt!("int %? out of range for this architecture", v));
|
||||
}
|
||||
v as int
|
||||
}
|
||||
|
||||
fn read_bool(&self) -> bool {
|
||||
doc_as_u8(self.next_doc(EsBool)) as bool
|
||||
}
|
||||
|
||||
fn read_f64(&self) -> f64 { fail!(~"read_f64()"); }
|
||||
fn read_f32(&self) -> f32 { fail!(~"read_f32()"); }
|
||||
fn read_float(&self) -> float { fail!(~"read_float()"); }
|
||||
fn read_char(&self) -> char { fail!(~"read_char()"); }
|
||||
fn read_str(&self) -> ~str { doc_as_str(self.next_doc(EsStr)) }
|
||||
|
||||
// Compound types:
|
||||
fn read_enum<T>(&self, name: &str, f: &fn() -> T) -> T {
|
||||
debug!("read_enum(%s)", name);
|
||||
self._check_label(name);
|
||||
self.push_doc(self.next_doc(EsEnum), f)
|
||||
}
|
||||
|
||||
fn read_enum_variant<T>(&self,
|
||||
_: &[&str],
|
||||
f: &fn(uint) -> T)
|
||||
-> T {
|
||||
debug!("read_enum_variant()");
|
||||
let idx = self._next_uint(EsEnumVid);
|
||||
debug!(" idx=%u", idx);
|
||||
do self.push_doc(self.next_doc(EsEnumBody)) {
|
||||
f(idx)
|
||||
}
|
||||
}
|
||||
|
||||
fn read_enum_variant_arg<T>(&self,
|
||||
idx: uint,
|
||||
f: &fn() -> T) -> T {
|
||||
debug!("read_enum_variant_arg(idx=%u)", idx);
|
||||
f()
|
||||
}
|
||||
|
||||
fn read_enum_struct_variant<T>(&self,
|
||||
_: &[&str],
|
||||
f: &fn(uint) -> T)
|
||||
-> T {
|
||||
debug!("read_enum_struct_variant()");
|
||||
let idx = self._next_uint(EsEnumVid);
|
||||
debug!(" idx=%u", idx);
|
||||
do self.push_doc(self.next_doc(EsEnumBody)) {
|
||||
f(idx)
|
||||
}
|
||||
}
|
||||
|
||||
fn read_enum_struct_variant_field<T>(&self,
|
||||
name: &str,
|
||||
idx: uint,
|
||||
f: &fn() -> T)
|
||||
-> T {
|
||||
debug!("read_enum_struct_variant_arg(name=%?, idx=%u)", name, idx);
|
||||
f()
|
||||
}
|
||||
|
||||
fn read_struct<T>(&self,
|
||||
name: &str,
|
||||
_: uint,
|
||||
f: &fn() -> T)
|
||||
-> T {
|
||||
debug!("read_struct(name=%s)", name);
|
||||
f()
|
||||
}
|
||||
|
||||
fn read_field<T>(&self,
|
||||
name: &str,
|
||||
idx: uint,
|
||||
f: &fn() -> T)
|
||||
-> T {
|
||||
debug!("read_field(name=%?, idx=%u)", name, idx);
|
||||
self._check_label(name);
|
||||
f()
|
||||
}
|
||||
|
||||
fn read_tuple<T>(&self, f: &fn(uint) -> T) -> T {
|
||||
debug!("read_tuple()");
|
||||
self.read_seq(f)
|
||||
}
|
||||
|
||||
fn read_tuple_arg<T>(&self, idx: uint, f: &fn() -> T) -> T {
|
||||
debug!("read_tuple_arg(idx=%u)", idx);
|
||||
self.read_seq_elt(idx, f)
|
||||
}
|
||||
|
||||
fn read_tuple_struct<T>(&self,
|
||||
name: &str,
|
||||
f: &fn(uint) -> T)
|
||||
-> T {
|
||||
debug!("read_tuple_struct(name=%?)", name);
|
||||
self.read_tuple(f)
|
||||
}
|
||||
|
||||
fn read_tuple_struct_arg<T>(&self,
|
||||
idx: uint,
|
||||
f: &fn() -> T)
|
||||
-> T {
|
||||
debug!("read_tuple_struct_arg(idx=%u)", idx);
|
||||
self.read_tuple_arg(idx, f)
|
||||
}
|
||||
|
||||
fn read_option<T>(&self, f: &fn(bool) -> T) -> T {
|
||||
debug!("read_option()");
|
||||
do self.read_enum("Option") || {
|
||||
do self.read_enum_variant(["None", "Some"]) |idx| {
|
||||
match idx {
|
||||
0 => f(false),
|
||||
1 => f(true),
|
||||
_ => fail!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn read_seq<T>(&self, f: &fn(uint) -> T) -> T {
|
||||
debug!("read_seq()");
|
||||
do self.push_doc(self.next_doc(EsVec)) {
|
||||
let len = self._next_uint(EsVecLen);
|
||||
debug!(" len=%u", len);
|
||||
f(len)
|
||||
}
|
||||
}
|
||||
|
||||
fn read_seq_elt<T>(&self, idx: uint, f: &fn() -> T) -> T {
|
||||
debug!("read_seq_elt(idx=%u)", idx);
|
||||
self.push_doc(self.next_doc(EsVecElt), f)
|
||||
}
|
||||
|
||||
fn read_map<T>(&self, _f: &fn(uint) -> T) -> T {
|
||||
debug!("read_map()");
|
||||
fail!(~"read_map is unimplemented");
|
||||
}
|
||||
|
||||
fn read_map_elt_key<T>(&self, idx: uint, _f: &fn() -> T) -> T {
|
||||
debug!("read_map_elt_key(idx=%u)", idx);
|
||||
fail!(~"read_map_elt_val is unimplemented");
|
||||
}
|
||||
|
||||
fn read_map_elt_val<T>(&self, idx: uint, _f: &fn() -> T) -> T {
|
||||
debug!("read_map_elt_val(idx=%u)", idx);
|
||||
fail!(~"read_map_elt_val is unimplemented");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl serialize::Decoder for Decoder {
|
||||
fn read_nil(&mut self) -> () { () }
|
||||
|
||||
@ -891,104 +630,6 @@ pub mod writer {
|
||||
}
|
||||
|
||||
// FIXME (#2741): Provide a function to write the standard ebml header.
|
||||
#[cfg(stage0)]
|
||||
pub impl Encoder {
|
||||
fn start_tag(&self, tag_id: uint) {
|
||||
debug!("Start tag %u", tag_id);
|
||||
|
||||
// Write the enum ID:
|
||||
write_vuint(self.writer, tag_id);
|
||||
|
||||
// Write a placeholder four-byte size.
|
||||
self.size_positions.push(self.writer.tell());
|
||||
let zeroes: &[u8] = &[0u8, 0u8, 0u8, 0u8];
|
||||
self.writer.write(zeroes);
|
||||
}
|
||||
|
||||
fn end_tag(&self) {
|
||||
let last_size_pos = self.size_positions.pop();
|
||||
let cur_pos = self.writer.tell();
|
||||
self.writer.seek(last_size_pos as int, io::SeekSet);
|
||||
let size = (cur_pos - last_size_pos - 4u);
|
||||
write_sized_vuint(self.writer, size, 4u);
|
||||
self.writer.seek(cur_pos as int, io::SeekSet);
|
||||
|
||||
debug!("End tag (size = %u)", size);
|
||||
}
|
||||
|
||||
fn wr_tag(&self, tag_id: uint, blk: &fn()) {
|
||||
self.start_tag(tag_id);
|
||||
blk();
|
||||
self.end_tag();
|
||||
}
|
||||
|
||||
fn wr_tagged_bytes(&self, tag_id: uint, b: &[u8]) {
|
||||
write_vuint(self.writer, tag_id);
|
||||
write_vuint(self.writer, vec::len(b));
|
||||
self.writer.write(b);
|
||||
}
|
||||
|
||||
fn wr_tagged_u64(&self, tag_id: uint, v: u64) {
|
||||
do io::u64_to_be_bytes(v, 8u) |v| {
|
||||
self.wr_tagged_bytes(tag_id, v);
|
||||
}
|
||||
}
|
||||
|
||||
fn wr_tagged_u32(&self, tag_id: uint, v: u32) {
|
||||
do io::u64_to_be_bytes(v as u64, 4u) |v| {
|
||||
self.wr_tagged_bytes(tag_id, v);
|
||||
}
|
||||
}
|
||||
|
||||
fn wr_tagged_u16(&self, tag_id: uint, v: u16) {
|
||||
do io::u64_to_be_bytes(v as u64, 2u) |v| {
|
||||
self.wr_tagged_bytes(tag_id, v);
|
||||
}
|
||||
}
|
||||
|
||||
fn wr_tagged_u8(&self, tag_id: uint, v: u8) {
|
||||
self.wr_tagged_bytes(tag_id, &[v]);
|
||||
}
|
||||
|
||||
fn wr_tagged_i64(&self, tag_id: uint, v: i64) {
|
||||
do io::u64_to_be_bytes(v as u64, 8u) |v| {
|
||||
self.wr_tagged_bytes(tag_id, v);
|
||||
}
|
||||
}
|
||||
|
||||
fn wr_tagged_i32(&self, tag_id: uint, v: i32) {
|
||||
do io::u64_to_be_bytes(v as u64, 4u) |v| {
|
||||
self.wr_tagged_bytes(tag_id, v);
|
||||
}
|
||||
}
|
||||
|
||||
fn wr_tagged_i16(&self, tag_id: uint, v: i16) {
|
||||
do io::u64_to_be_bytes(v as u64, 2u) |v| {
|
||||
self.wr_tagged_bytes(tag_id, v);
|
||||
}
|
||||
}
|
||||
|
||||
fn wr_tagged_i8(&self, tag_id: uint, v: i8) {
|
||||
self.wr_tagged_bytes(tag_id, &[v as u8]);
|
||||
}
|
||||
|
||||
fn wr_tagged_str(&self, tag_id: uint, v: &str) {
|
||||
str::byte_slice(v, |b| self.wr_tagged_bytes(tag_id, b));
|
||||
}
|
||||
|
||||
fn wr_bytes(&self, b: &[u8]) {
|
||||
debug!("Write %u bytes", vec::len(b));
|
||||
self.writer.write(b);
|
||||
}
|
||||
|
||||
fn wr_str(&self, s: &str) {
|
||||
debug!("Write str: %?", s);
|
||||
self.writer.write(str::to_bytes(s));
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME (#2741): Provide a function to write the standard ebml header.
|
||||
#[cfg(not(stage0))]
|
||||
pub impl Encoder {
|
||||
fn start_tag(&mut self, tag_id: uint) {
|
||||
debug!("Start tag %u", tag_id);
|
||||
@ -1091,26 +732,6 @@ pub mod writer {
|
||||
// Totally lame approach.
|
||||
static debug: bool = true;
|
||||
|
||||
#[cfg(stage0)]
|
||||
priv impl Encoder {
|
||||
// used internally to emit things like the vector length and so on
|
||||
fn _emit_tagged_uint(&self, t: EbmlEncoderTag, v: uint) {
|
||||
assert!(v <= 0xFFFF_FFFF_u);
|
||||
self.wr_tagged_u32(t as uint, v as u32);
|
||||
}
|
||||
|
||||
fn _emit_label(&self, label: &str) {
|
||||
// There are various strings that we have access to, such as
|
||||
// the name of a record field, which do not actually appear in
|
||||
// the encoded EBML (normally). This is just for
|
||||
// efficiency. When debugging, though, we can emit such
|
||||
// labels and then they will be checked by decoder to
|
||||
// try and check failures more quickly.
|
||||
if debug { self.wr_tagged_str(EsLabel as uint, label) }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
priv impl Encoder {
|
||||
// used internally to emit things like the vector length and so on
|
||||
fn _emit_tagged_uint(&mut self, t: EbmlEncoderTag, v: uint) {
|
||||
@ -1129,16 +750,6 @@ pub mod writer {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
pub impl Encoder {
|
||||
fn emit_opaque(&self, f: &fn()) {
|
||||
do self.wr_tag(EsOpaque as uint) {
|
||||
f()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
pub impl Encoder {
|
||||
fn emit_opaque(&mut self, f: &fn(&mut Encoder)) {
|
||||
self.start_tag(EsOpaque as uint);
|
||||
@ -1147,156 +758,6 @@ pub mod writer {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl ::serialize::Encoder for Encoder {
|
||||
fn emit_nil(&self) {}
|
||||
|
||||
fn emit_uint(&self, v: uint) {
|
||||
self.wr_tagged_u64(EsUint as uint, v as u64);
|
||||
}
|
||||
fn emit_u64(&self, v: u64) {
|
||||
self.wr_tagged_u64(EsU64 as uint, v);
|
||||
}
|
||||
fn emit_u32(&self, v: u32) {
|
||||
self.wr_tagged_u32(EsU32 as uint, v);
|
||||
}
|
||||
fn emit_u16(&self, v: u16) {
|
||||
self.wr_tagged_u16(EsU16 as uint, v);
|
||||
}
|
||||
fn emit_u8(&self, v: u8) {
|
||||
self.wr_tagged_u8(EsU8 as uint, v);
|
||||
}
|
||||
|
||||
fn emit_int(&self, v: int) {
|
||||
self.wr_tagged_i64(EsInt as uint, v as i64);
|
||||
}
|
||||
fn emit_i64(&self, v: i64) {
|
||||
self.wr_tagged_i64(EsI64 as uint, v);
|
||||
}
|
||||
fn emit_i32(&self, v: i32) {
|
||||
self.wr_tagged_i32(EsI32 as uint, v);
|
||||
}
|
||||
fn emit_i16(&self, v: i16) {
|
||||
self.wr_tagged_i16(EsI16 as uint, v);
|
||||
}
|
||||
fn emit_i8(&self, v: i8) {
|
||||
self.wr_tagged_i8(EsI8 as uint, v);
|
||||
}
|
||||
|
||||
fn emit_bool(&self, v: bool) {
|
||||
self.wr_tagged_u8(EsBool as uint, v as u8)
|
||||
}
|
||||
|
||||
// FIXME (#2742): implement these
|
||||
fn emit_f64(&self, _v: f64) {
|
||||
fail!(~"Unimplemented: serializing an f64");
|
||||
}
|
||||
fn emit_f32(&self, _v: f32) {
|
||||
fail!(~"Unimplemented: serializing an f32");
|
||||
}
|
||||
fn emit_float(&self, _v: float) {
|
||||
fail!(~"Unimplemented: serializing a float");
|
||||
}
|
||||
|
||||
fn emit_char(&self, _v: char) {
|
||||
fail!(~"Unimplemented: serializing a char");
|
||||
}
|
||||
|
||||
fn emit_str(&self, v: &str) {
|
||||
self.wr_tagged_str(EsStr as uint, v)
|
||||
}
|
||||
|
||||
fn emit_enum(&self, name: &str, f: &fn()) {
|
||||
self._emit_label(name);
|
||||
self.wr_tag(EsEnum as uint, f)
|
||||
}
|
||||
|
||||
fn emit_enum_variant(&self,
|
||||
_: &str,
|
||||
v_id: uint,
|
||||
_: uint,
|
||||
f: &fn()) {
|
||||
self._emit_tagged_uint(EsEnumVid, v_id);
|
||||
self.wr_tag(EsEnumBody as uint, f)
|
||||
}
|
||||
|
||||
fn emit_enum_variant_arg(&self, _: uint, f: &fn()) {
|
||||
f()
|
||||
}
|
||||
|
||||
fn emit_enum_struct_variant(&self,
|
||||
v_name: &str,
|
||||
v_id: uint,
|
||||
cnt: uint,
|
||||
f: &fn()) {
|
||||
self.emit_enum_variant(v_name, v_id, cnt, f)
|
||||
}
|
||||
|
||||
fn emit_enum_struct_variant_field(&self,
|
||||
_: &str,
|
||||
idx: uint,
|
||||
f: &fn()) {
|
||||
self.emit_enum_variant_arg(idx, f)
|
||||
}
|
||||
|
||||
fn emit_struct(&self, _: &str, _len: uint, f: &fn()) {
|
||||
f()
|
||||
}
|
||||
|
||||
fn emit_field(&self, name: &str, _idx: uint, f: &fn()) {
|
||||
self._emit_label(name);
|
||||
f()
|
||||
}
|
||||
|
||||
fn emit_tuple(&self, len: uint, f: &fn()) {
|
||||
self.emit_seq(len, f)
|
||||
}
|
||||
fn emit_tuple_arg(&self, idx: uint, f: &fn()) {
|
||||
self.emit_seq_elt(idx, f)
|
||||
}
|
||||
|
||||
fn emit_tuple_struct(&self, _name: &str, len: uint, f: &fn()) {
|
||||
self.emit_seq(len, f)
|
||||
}
|
||||
fn emit_tuple_struct_arg(&self, idx: uint, f: &fn()) {
|
||||
self.emit_seq_elt(idx, f)
|
||||
}
|
||||
|
||||
fn emit_option(&self, f: &fn()) {
|
||||
self.emit_enum("Option", f);
|
||||
}
|
||||
fn emit_option_none(&self) {
|
||||
self.emit_enum_variant("None", 0, 0, || ())
|
||||
}
|
||||
fn emit_option_some(&self, f: &fn()) {
|
||||
self.emit_enum_variant("Some", 1, 1, f)
|
||||
}
|
||||
|
||||
fn emit_seq(&self, len: uint, f: &fn()) {
|
||||
do self.wr_tag(EsVec as uint) {
|
||||
self._emit_tagged_uint(EsVecLen, len);
|
||||
f()
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_seq_elt(&self, _idx: uint, f: &fn()) {
|
||||
self.wr_tag(EsVecElt as uint, f)
|
||||
}
|
||||
|
||||
fn emit_map(&self, _len: uint, _f: &fn()) {
|
||||
fail!(~"emit_map is unimplemented");
|
||||
}
|
||||
|
||||
fn emit_map_elt_key(&self, _idx: uint, _f: &fn()) {
|
||||
fail!(~"emit_map_elt_key is unimplemented");
|
||||
}
|
||||
|
||||
fn emit_map_elt_val(&self, _idx: uint, _f: &fn()) {
|
||||
fail!(~"emit_map_elt_val is unimplemented");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl ::serialize::Encoder for Encoder {
|
||||
fn emit_nil(&mut self) {}
|
||||
|
||||
|
@ -438,19 +438,6 @@ pub mod flatteners {
|
||||
SerializingFlattener
|
||||
*/
|
||||
|
||||
#[cfg(stage0)]
|
||||
pub fn deserialize_buffer<D: Decoder + FromReader,
|
||||
T: Decodable<D>>(
|
||||
buf: &[u8])
|
||||
-> T {
|
||||
let buf = vec::from_slice(buf);
|
||||
let buf_reader = @BufReader::new(buf);
|
||||
let reader = buf_reader as @Reader;
|
||||
let deser: D = FromReader::from_reader(reader);
|
||||
Decodable::decode(&deser)
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
pub fn deserialize_buffer<D: Decoder + FromReader,
|
||||
T: Decodable<D>>(
|
||||
buf: &[u8])
|
||||
@ -462,18 +449,6 @@ pub mod flatteners {
|
||||
Decodable::decode(&mut deser)
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
pub fn serialize_value<D: Encoder + FromWriter,
|
||||
T: Encodable<D>>(
|
||||
val: &T)
|
||||
-> ~[u8] {
|
||||
do io::with_bytes_writer |writer| {
|
||||
let ser = FromWriter::from_writer(writer);
|
||||
val.encode(&ser);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
pub fn serialize_value<D: Encoder + FromWriter,
|
||||
T: Encodable<D>>(
|
||||
val: &T)
|
||||
|
@ -54,35 +54,6 @@ pub impl<A:Copy> Future<A> {
|
||||
}
|
||||
|
||||
pub impl<A> Future<A> {
|
||||
#[cfg(stage0)]
|
||||
fn get_ref(&self) -> &'self A {
|
||||
/*!
|
||||
* Executes the future's closure and then returns a borrowed
|
||||
* pointer to the result. The borrowed pointer lasts as long as
|
||||
* the future.
|
||||
*/
|
||||
unsafe {
|
||||
match self.state {
|
||||
Forced(ref mut v) => { return cast::transmute(v); }
|
||||
Evaluating => fail!(~"Recursive forcing of future!"),
|
||||
Pending(_) => {}
|
||||
}
|
||||
|
||||
let mut state = Evaluating;
|
||||
self.state <-> state;
|
||||
match state {
|
||||
Forced(_) | Evaluating => fail!(~"Logic error."),
|
||||
Pending(f) => {
|
||||
self.state = Forced(f());
|
||||
self.get_ref()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn get_ref<'a>(&'a self) -> &'a A {
|
||||
/*!
|
||||
* Executes the future's closure and then returns a borrowed
|
||||
|
@ -77,150 +77,6 @@ pub fn Encoder(wr: @io::Writer) -> Encoder {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl serialize::Encoder for Encoder {
|
||||
fn emit_nil(&self) { self.wr.write_str("null") }
|
||||
|
||||
fn emit_uint(&self, v: uint) { self.emit_float(v as float); }
|
||||
fn emit_u64(&self, v: u64) { self.emit_float(v as float); }
|
||||
fn emit_u32(&self, v: u32) { self.emit_float(v as float); }
|
||||
fn emit_u16(&self, v: u16) { self.emit_float(v as float); }
|
||||
fn emit_u8(&self, v: u8) { self.emit_float(v as float); }
|
||||
|
||||
fn emit_int(&self, v: int) { self.emit_float(v as float); }
|
||||
fn emit_i64(&self, v: i64) { self.emit_float(v as float); }
|
||||
fn emit_i32(&self, v: i32) { self.emit_float(v as float); }
|
||||
fn emit_i16(&self, v: i16) { self.emit_float(v as float); }
|
||||
fn emit_i8(&self, v: i8) { self.emit_float(v as float); }
|
||||
|
||||
fn emit_bool(&self, v: bool) {
|
||||
if v {
|
||||
self.wr.write_str("true");
|
||||
} else {
|
||||
self.wr.write_str("false");
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_f64(&self, v: f64) { self.emit_float(v as float); }
|
||||
fn emit_f32(&self, v: f32) { self.emit_float(v as float); }
|
||||
fn emit_float(&self, v: float) {
|
||||
self.wr.write_str(float::to_str_digits(v, 6u));
|
||||
}
|
||||
|
||||
fn emit_char(&self, v: char) { self.emit_str(str::from_char(v)) }
|
||||
fn emit_str(&self, v: &str) { self.wr.write_str(escape_str(v)) }
|
||||
|
||||
fn emit_enum(&self, _name: &str, f: &fn()) { f() }
|
||||
|
||||
fn emit_enum_variant(&self,
|
||||
name: &str,
|
||||
_id: uint,
|
||||
cnt: uint,
|
||||
f: &fn()) {
|
||||
// enums are encoded as strings or vectors:
|
||||
// Bunny => "Bunny"
|
||||
// Kangaroo(34,"William") => ["Kangaroo",[34,"William"]]
|
||||
|
||||
if cnt == 0 {
|
||||
self.wr.write_str(escape_str(name));
|
||||
} else {
|
||||
self.wr.write_char('[');
|
||||
self.wr.write_str(escape_str(name));
|
||||
self.wr.write_char(',');
|
||||
f();
|
||||
self.wr.write_char(']');
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_enum_variant_arg(&self, idx: uint, f: &fn()) {
|
||||
if idx != 0 {self.wr.write_char(',');}
|
||||
f();
|
||||
}
|
||||
|
||||
fn emit_enum_struct_variant(&self,
|
||||
name: &str,
|
||||
id: uint,
|
||||
cnt: uint,
|
||||
f: &fn()) {
|
||||
self.emit_enum_variant(name, id, cnt, f)
|
||||
}
|
||||
|
||||
fn emit_enum_struct_variant_field(&self,
|
||||
_: &str,
|
||||
idx: uint,
|
||||
f: &fn()) {
|
||||
self.emit_enum_variant_arg(idx, f)
|
||||
}
|
||||
|
||||
fn emit_struct(&self, _: &str, _: uint, f: &fn()) {
|
||||
self.wr.write_char('{');
|
||||
f();
|
||||
self.wr.write_char('}');
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn emit_field(&self, name: &str, idx: uint, f: &fn()) {
|
||||
if idx != 0 { self.wr.write_char(','); }
|
||||
self.wr.write_str(escape_str(name));
|
||||
self.wr.write_char(':');
|
||||
f();
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn emit_struct_field(&self, name: &str, idx: uint, f: &fn()) {
|
||||
if idx != 0 { self.wr.write_char(','); }
|
||||
self.wr.write_str(escape_str(name));
|
||||
self.wr.write_char(':');
|
||||
f();
|
||||
}
|
||||
|
||||
fn emit_tuple(&self, len: uint, f: &fn()) { self.emit_seq(len, f) }
|
||||
fn emit_tuple_arg(&self, idx: uint, f: &fn()) {
|
||||
self.emit_seq_elt(idx, f)
|
||||
}
|
||||
|
||||
fn emit_tuple_struct(&self, _name: &str, len: uint, f: &fn()) {
|
||||
self.emit_seq(len, f)
|
||||
}
|
||||
fn emit_tuple_struct_arg(&self, idx: uint, f: &fn()) {
|
||||
self.emit_seq_elt(idx, f)
|
||||
}
|
||||
|
||||
fn emit_option(&self, f: &fn()) { f(); }
|
||||
fn emit_option_none(&self) { self.emit_nil(); }
|
||||
fn emit_option_some(&self, f: &fn()) { f(); }
|
||||
|
||||
fn emit_seq(&self, _len: uint, f: &fn()) {
|
||||
self.wr.write_char('[');
|
||||
f();
|
||||
self.wr.write_char(']');
|
||||
}
|
||||
|
||||
fn emit_seq_elt(&self, idx: uint, f: &fn()) {
|
||||
if idx != 0 { self.wr.write_char(','); }
|
||||
f()
|
||||
}
|
||||
|
||||
fn emit_map(&self, _len: uint, f: &fn()) {
|
||||
self.wr.write_char('{');
|
||||
f();
|
||||
self.wr.write_char('}');
|
||||
}
|
||||
|
||||
fn emit_map_elt_key(&self, idx: uint, f: &fn()) {
|
||||
if idx != 0 { self.wr.write_char(','); }
|
||||
f()
|
||||
}
|
||||
|
||||
fn emit_map_elt_val(&self, _idx: uint, f: &fn()) {
|
||||
self.wr.write_char(':');
|
||||
f()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl serialize::Encoder for Encoder {
|
||||
fn emit_nil(&mut self) { self.wr.write_str("null") }
|
||||
|
||||
@ -376,202 +232,6 @@ pub fn PrettyEncoder(wr: @io::Writer) -> PrettyEncoder {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl serialize::Encoder for PrettyEncoder {
|
||||
fn emit_nil(&self) { self.wr.write_str("null") }
|
||||
|
||||
fn emit_uint(&self, v: uint) { self.emit_float(v as float); }
|
||||
fn emit_u64(&self, v: u64) { self.emit_float(v as float); }
|
||||
fn emit_u32(&self, v: u32) { self.emit_float(v as float); }
|
||||
fn emit_u16(&self, v: u16) { self.emit_float(v as float); }
|
||||
fn emit_u8(&self, v: u8) { self.emit_float(v as float); }
|
||||
|
||||
fn emit_int(&self, v: int) { self.emit_float(v as float); }
|
||||
fn emit_i64(&self, v: i64) { self.emit_float(v as float); }
|
||||
fn emit_i32(&self, v: i32) { self.emit_float(v as float); }
|
||||
fn emit_i16(&self, v: i16) { self.emit_float(v as float); }
|
||||
fn emit_i8(&self, v: i8) { self.emit_float(v as float); }
|
||||
|
||||
fn emit_bool(&self, v: bool) {
|
||||
if v {
|
||||
self.wr.write_str("true");
|
||||
} else {
|
||||
self.wr.write_str("false");
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_f64(&self, v: f64) { self.emit_float(v as float); }
|
||||
fn emit_f32(&self, v: f32) { self.emit_float(v as float); }
|
||||
fn emit_float(&self, v: float) {
|
||||
self.wr.write_str(float::to_str_digits(v, 6u));
|
||||
}
|
||||
|
||||
fn emit_char(&self, v: char) { self.emit_str(str::from_char(v)) }
|
||||
fn emit_str(&self, v: &str) { self.wr.write_str(escape_str(v)); }
|
||||
|
||||
fn emit_enum(&self, _name: &str, f: &fn()) { f() }
|
||||
|
||||
fn emit_enum_variant(&self,
|
||||
name: &str,
|
||||
_: uint,
|
||||
cnt: uint,
|
||||
f: &fn()) {
|
||||
if cnt == 0 {
|
||||
self.wr.write_str(escape_str(name));
|
||||
} else {
|
||||
self.wr.write_char('[');
|
||||
self.indent += 2;
|
||||
self.wr.write_char('\n');
|
||||
self.wr.write_str(spaces(self.indent));
|
||||
self.wr.write_str(escape_str(name));
|
||||
self.wr.write_str(",\n");
|
||||
f();
|
||||
self.wr.write_char('\n');
|
||||
self.indent -= 2;
|
||||
self.wr.write_str(spaces(self.indent));
|
||||
self.wr.write_char(']');
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_enum_variant_arg(&self, idx: uint, f: &fn()) {
|
||||
if idx != 0 {
|
||||
self.wr.write_str(",\n");
|
||||
}
|
||||
self.wr.write_str(spaces(self.indent));
|
||||
f()
|
||||
}
|
||||
|
||||
fn emit_enum_struct_variant(&self,
|
||||
name: &str,
|
||||
id: uint,
|
||||
cnt: uint,
|
||||
f: &fn()) {
|
||||
self.emit_enum_variant(name, id, cnt, f)
|
||||
}
|
||||
|
||||
fn emit_enum_struct_variant_field(&self,
|
||||
_: &str,
|
||||
idx: uint,
|
||||
f: &fn()) {
|
||||
self.emit_enum_variant_arg(idx, f)
|
||||
}
|
||||
|
||||
|
||||
fn emit_struct(&self, _name: &str, len: uint, f: &fn()) {
|
||||
if len == 0 {
|
||||
self.wr.write_str("{}");
|
||||
} else {
|
||||
self.wr.write_char('{');
|
||||
self.indent += 2;
|
||||
f();
|
||||
self.wr.write_char('\n');
|
||||
self.indent -= 2;
|
||||
self.wr.write_str(spaces(self.indent));
|
||||
self.wr.write_char('}');
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn emit_field(&self, name: &str, idx: uint, f: &fn()) {
|
||||
if idx == 0 {
|
||||
self.wr.write_char('\n');
|
||||
} else {
|
||||
self.wr.write_str(",\n");
|
||||
}
|
||||
self.wr.write_str(spaces(self.indent));
|
||||
self.wr.write_str(escape_str(name));
|
||||
self.wr.write_str(": ");
|
||||
f();
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn emit_struct_field(&self, name: &str, idx: uint, f: &fn()) {
|
||||
if idx == 0 {
|
||||
self.wr.write_char('\n');
|
||||
} else {
|
||||
self.wr.write_str(",\n");
|
||||
}
|
||||
self.wr.write_str(spaces(self.indent));
|
||||
self.wr.write_str(escape_str(name));
|
||||
self.wr.write_str(": ");
|
||||
f();
|
||||
}
|
||||
|
||||
fn emit_tuple(&self, len: uint, f: &fn()) {
|
||||
self.emit_seq(len, f)
|
||||
}
|
||||
fn emit_tuple_arg(&self, idx: uint, f: &fn()) {
|
||||
self.emit_seq_elt(idx, f)
|
||||
}
|
||||
|
||||
fn emit_tuple_struct(&self, _name: &str, len: uint, f: &fn()) {
|
||||
self.emit_seq(len, f)
|
||||
}
|
||||
fn emit_tuple_struct_arg(&self, idx: uint, f: &fn()) {
|
||||
self.emit_seq_elt(idx, f)
|
||||
}
|
||||
|
||||
fn emit_option(&self, f: &fn()) { f(); }
|
||||
fn emit_option_none(&self) { self.emit_nil(); }
|
||||
fn emit_option_some(&self, f: &fn()) { f(); }
|
||||
|
||||
fn emit_seq(&self, len: uint, f: &fn()) {
|
||||
if len == 0 {
|
||||
self.wr.write_str("[]");
|
||||
} else {
|
||||
self.wr.write_char('[');
|
||||
self.indent += 2;
|
||||
f();
|
||||
self.wr.write_char('\n');
|
||||
self.indent -= 2;
|
||||
self.wr.write_str(spaces(self.indent));
|
||||
self.wr.write_char(']');
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_seq_elt(&self, idx: uint, f: &fn()) {
|
||||
if idx == 0 {
|
||||
self.wr.write_char('\n');
|
||||
} else {
|
||||
self.wr.write_str(",\n");
|
||||
}
|
||||
self.wr.write_str(spaces(self.indent));
|
||||
f()
|
||||
}
|
||||
|
||||
fn emit_map(&self, len: uint, f: &fn()) {
|
||||
if len == 0 {
|
||||
self.wr.write_str("{}");
|
||||
} else {
|
||||
self.wr.write_char('{');
|
||||
self.indent += 2;
|
||||
f();
|
||||
self.wr.write_char('\n');
|
||||
self.indent -= 2;
|
||||
self.wr.write_str(spaces(self.indent));
|
||||
self.wr.write_char('}');
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_map_elt_key(&self, idx: uint, f: &fn()) {
|
||||
if idx == 0 {
|
||||
self.wr.write_char('\n');
|
||||
} else {
|
||||
self.wr.write_str(",\n");
|
||||
}
|
||||
self.wr.write_str(spaces(self.indent));
|
||||
f();
|
||||
}
|
||||
|
||||
fn emit_map_elt_val(&self, _idx: uint, f: &fn()) {
|
||||
self.wr.write_str(": ");
|
||||
f();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl serialize::Encoder for PrettyEncoder {
|
||||
fn emit_nil(&mut self) { self.wr.write_str("null") }
|
||||
|
||||
@ -765,21 +425,6 @@ impl serialize::Encoder for PrettyEncoder {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<E: serialize::Encoder> serialize::Encodable<E> for Json {
|
||||
fn encode(&self, e: &E) {
|
||||
match *self {
|
||||
Number(v) => v.encode(e),
|
||||
String(ref v) => v.encode(e),
|
||||
Boolean(v) => v.encode(e),
|
||||
List(ref v) => v.encode(e),
|
||||
Object(ref v) => v.encode(e),
|
||||
Null => e.emit_nil(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl<E: serialize::Encoder> serialize::Encodable<E> for Json {
|
||||
fn encode(&self, e: &mut E) {
|
||||
match *self {
|
||||
@ -794,14 +439,6 @@ impl<E: serialize::Encoder> serialize::Encodable<E> for Json {
|
||||
}
|
||||
|
||||
/// Encodes a json value into a io::writer
|
||||
#[cfg(stage0)]
|
||||
pub fn to_writer(wr: @io::Writer, json: &Json) {
|
||||
let encoder = Encoder(wr);
|
||||
json.encode(&encoder)
|
||||
}
|
||||
|
||||
/// Encodes a json value into a io::writer
|
||||
#[cfg(not(stage0))]
|
||||
pub fn to_writer(wr: @io::Writer, json: &Json) {
|
||||
let mut encoder = Encoder(wr);
|
||||
json.encode(&mut encoder)
|
||||
@ -813,14 +450,6 @@ pub fn to_str(json: &Json) -> ~str {
|
||||
}
|
||||
|
||||
/// Encodes a json value into a io::writer
|
||||
#[cfg(stage0)]
|
||||
pub fn to_pretty_writer(wr: @io::Writer, json: &Json) {
|
||||
let encoder = PrettyEncoder(wr);
|
||||
json.encode(&encoder)
|
||||
}
|
||||
|
||||
/// Encodes a json value into a io::writer
|
||||
#[cfg(not(stage0))]
|
||||
pub fn to_pretty_writer(wr: @io::Writer, json: &Json) {
|
||||
let mut encoder = PrettyEncoder(wr);
|
||||
json.encode(&mut encoder)
|
||||
@ -1219,243 +848,6 @@ pub fn Decoder(json: Json) -> Decoder {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl serialize::Decoder for Decoder {
|
||||
fn read_nil(&self) -> () {
|
||||
debug!("read_nil");
|
||||
match self.stack.pop() {
|
||||
Null => (),
|
||||
value => fail!(fmt!("not a null: %?", value))
|
||||
}
|
||||
}
|
||||
|
||||
fn read_u64(&self) -> u64 { self.read_float() as u64 }
|
||||
fn read_u32(&self) -> u32 { self.read_float() as u32 }
|
||||
fn read_u16(&self) -> u16 { self.read_float() as u16 }
|
||||
fn read_u8 (&self) -> u8 { self.read_float() as u8 }
|
||||
fn read_uint(&self) -> uint { self.read_float() as uint }
|
||||
|
||||
fn read_i64(&self) -> i64 { self.read_float() as i64 }
|
||||
fn read_i32(&self) -> i32 { self.read_float() as i32 }
|
||||
fn read_i16(&self) -> i16 { self.read_float() as i16 }
|
||||
fn read_i8 (&self) -> i8 { self.read_float() as i8 }
|
||||
fn read_int(&self) -> int { self.read_float() as int }
|
||||
|
||||
fn read_bool(&self) -> bool {
|
||||
debug!("read_bool");
|
||||
match self.stack.pop() {
|
||||
Boolean(b) => b,
|
||||
value => fail!(fmt!("not a boolean: %?", value))
|
||||
}
|
||||
}
|
||||
|
||||
fn read_f64(&self) -> f64 { self.read_float() as f64 }
|
||||
fn read_f32(&self) -> f32 { self.read_float() as f32 }
|
||||
fn read_float(&self) -> float {
|
||||
debug!("read_float");
|
||||
match self.stack.pop() {
|
||||
Number(f) => f,
|
||||
value => fail!(fmt!("not a number: %?", value))
|
||||
}
|
||||
}
|
||||
|
||||
fn read_char(&self) -> char {
|
||||
let mut v = ~[];
|
||||
for str::each_char(self.read_str()) |c| { v.push(c) }
|
||||
if v.len() != 1 { fail!(~"string must have one character") }
|
||||
v[0]
|
||||
}
|
||||
|
||||
fn read_str(&self) -> ~str {
|
||||
debug!("read_str");
|
||||
match self.stack.pop() {
|
||||
String(s) => s,
|
||||
json => fail!(fmt!("not a string: %?", json))
|
||||
}
|
||||
}
|
||||
|
||||
fn read_enum<T>(&self, name: &str, f: &fn() -> T) -> T {
|
||||
debug!("read_enum(%s)", name);
|
||||
f()
|
||||
}
|
||||
|
||||
fn read_enum_variant<T>(&self,
|
||||
names: &[&str],
|
||||
f: &fn(uint) -> T)
|
||||
-> T {
|
||||
debug!("read_enum_variant(names=%?)", names);
|
||||
let name = match self.stack.pop() {
|
||||
String(s) => s,
|
||||
List(list) => {
|
||||
do vec::consume_reverse(list) |_i, v| {
|
||||
self.stack.push(v);
|
||||
}
|
||||
match self.stack.pop() {
|
||||
String(s) => s,
|
||||
value => fail!(fmt!("invalid variant name: %?", value)),
|
||||
}
|
||||
}
|
||||
ref json => fail!(fmt!("invalid variant: %?", *json)),
|
||||
};
|
||||
let idx = match vec::position(names, |n| str::eq_slice(*n, name)) {
|
||||
Some(idx) => idx,
|
||||
None => fail!(fmt!("Unknown variant name: %?", name)),
|
||||
};
|
||||
f(idx)
|
||||
}
|
||||
|
||||
fn read_enum_variant_arg<T>(&self, idx: uint, f: &fn() -> T) -> T {
|
||||
debug!("read_enum_variant_arg(idx=%u)", idx);
|
||||
f()
|
||||
}
|
||||
|
||||
fn read_enum_struct_variant<T>(&self,
|
||||
names: &[&str],
|
||||
f: &fn(uint) -> T)
|
||||
-> T {
|
||||
debug!("read_enum_struct_variant(names=%?)", names);
|
||||
self.read_enum_variant(names, f)
|
||||
}
|
||||
|
||||
|
||||
fn read_enum_struct_variant_field<T>(&self,
|
||||
name: &str,
|
||||
idx: uint,
|
||||
f: &fn() -> T)
|
||||
-> T {
|
||||
debug!("read_enum_struct_variant_field(name=%?, idx=%u)", name, idx);
|
||||
self.read_enum_variant_arg(idx, f)
|
||||
}
|
||||
|
||||
fn read_struct<T>(&self, name: &str, len: uint, f: &fn() -> T) -> T {
|
||||
debug!("read_struct(name=%s, len=%u)", name, len);
|
||||
let value = f();
|
||||
self.stack.pop();
|
||||
value
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn read_field<T>(&self, name: &str, idx: uint, f: &fn() -> T) -> T {
|
||||
debug!("read_field(name=%?, idx=%u)", name, idx);
|
||||
match self.stack.pop() {
|
||||
Object(obj) => {
|
||||
let mut obj = obj;
|
||||
let value = match obj.pop(&name.to_owned()) {
|
||||
None => fail!(fmt!("no such field: %s", name)),
|
||||
Some(json) => {
|
||||
self.stack.push(json);
|
||||
f()
|
||||
}
|
||||
};
|
||||
self.stack.push(Object(obj));
|
||||
value
|
||||
}
|
||||
value => fail!(fmt!("not an object: %?", value))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn read_struct_field<T>(&self,
|
||||
name: &str,
|
||||
idx: uint,
|
||||
f: &fn() -> T)
|
||||
-> T {
|
||||
debug!("read_struct_field(name=%?, idx=%u)", name, idx);
|
||||
match self.stack.pop() {
|
||||
Object(obj) => {
|
||||
let mut obj = obj;
|
||||
let value = match obj.pop(&name.to_owned()) {
|
||||
None => fail!(fmt!("no such field: %s", name)),
|
||||
Some(json) => {
|
||||
self.stack.push(json);
|
||||
f()
|
||||
}
|
||||
};
|
||||
self.stack.push(Object(obj));
|
||||
value
|
||||
}
|
||||
value => fail!(fmt!("not an object: %?", value))
|
||||
}
|
||||
}
|
||||
|
||||
fn read_tuple<T>(&self, f: &fn(uint) -> T) -> T {
|
||||
debug!("read_tuple()");
|
||||
self.read_seq(f)
|
||||
}
|
||||
|
||||
fn read_tuple_arg<T>(&self, idx: uint, f: &fn() -> T) -> T {
|
||||
debug!("read_tuple_arg(idx=%u)", idx);
|
||||
self.read_seq_elt(idx, f)
|
||||
}
|
||||
|
||||
fn read_tuple_struct<T>(&self, name: &str, f: &fn(uint) -> T) -> T {
|
||||
debug!("read_tuple_struct(name=%?)", name);
|
||||
self.read_tuple(f)
|
||||
}
|
||||
|
||||
fn read_tuple_struct_arg<T>(&self, idx: uint, f: &fn() -> T) -> T {
|
||||
debug!("read_tuple_struct_arg(idx=%u)", idx);
|
||||
self.read_tuple_arg(idx, f)
|
||||
}
|
||||
|
||||
fn read_option<T>(&self, f: &fn(bool) -> T) -> T {
|
||||
match self.stack.pop() {
|
||||
Null => f(false),
|
||||
value => { self.stack.push(value); f(true) }
|
||||
}
|
||||
}
|
||||
|
||||
fn read_seq<T>(&self, f: &fn(uint) -> T) -> T {
|
||||
debug!("read_seq()");
|
||||
let len = match self.stack.pop() {
|
||||
List(list) => {
|
||||
let len = list.len();
|
||||
do vec::consume_reverse(list) |_i, v| {
|
||||
self.stack.push(v);
|
||||
}
|
||||
len
|
||||
}
|
||||
_ => fail!(~"not a list"),
|
||||
};
|
||||
f(len)
|
||||
}
|
||||
|
||||
fn read_seq_elt<T>(&self, idx: uint, f: &fn() -> T) -> T {
|
||||
debug!("read_seq_elt(idx=%u)", idx);
|
||||
f()
|
||||
}
|
||||
|
||||
fn read_map<T>(&self, f: &fn(uint) -> T) -> T {
|
||||
debug!("read_map()");
|
||||
let len = match self.stack.pop() {
|
||||
Object(obj) => {
|
||||
let mut obj = obj;
|
||||
let len = obj.len();
|
||||
do obj.consume |key, value| {
|
||||
self.stack.push(value);
|
||||
self.stack.push(String(key));
|
||||
}
|
||||
len
|
||||
}
|
||||
json => fail!(fmt!("not an object: %?", json)),
|
||||
};
|
||||
f(len)
|
||||
}
|
||||
|
||||
fn read_map_elt_key<T>(&self, idx: uint, f: &fn() -> T) -> T {
|
||||
debug!("read_map_elt_key(idx=%u)", idx);
|
||||
f()
|
||||
}
|
||||
|
||||
fn read_map_elt_val<T>(&self, idx: uint, f: &fn() -> T) -> T {
|
||||
debug!("read_map_elt_val(idx=%u)", idx);
|
||||
f()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl serialize::Decoder for Decoder {
|
||||
fn read_nil(&mut self) -> () {
|
||||
debug!("read_nil");
|
||||
@ -1577,29 +969,6 @@ impl serialize::Decoder for Decoder {
|
||||
value
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn read_field<T>(&mut self, name: &str, idx: uint, f: &fn() -> T) -> T {
|
||||
debug!("read_field(name=%?, idx=%u)", name, idx);
|
||||
match self.stack.pop() {
|
||||
Object(obj) => {
|
||||
let mut obj = obj;
|
||||
let value = match obj.pop(&name.to_owned()) {
|
||||
None => fail!(fmt!("no such field: %s", name)),
|
||||
Some(json) => {
|
||||
self.stack.push(json);
|
||||
f()
|
||||
}
|
||||
};
|
||||
self.stack.push(Object(obj));
|
||||
value
|
||||
}
|
||||
value => fail!(fmt!("not an object: %?", value))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn read_struct_field<T>(&mut self,
|
||||
name: &str,
|
||||
idx: uint,
|
||||
|
@ -45,25 +45,9 @@ impl<T:Ord> Mutable for PriorityQueue<T> {
|
||||
|
||||
pub impl <T:Ord> PriorityQueue<T> {
|
||||
/// Returns the greatest item in the queue - fails if empty
|
||||
#[cfg(stage0)]
|
||||
fn top(&self) -> &'self T { &self.data[0] }
|
||||
|
||||
/// Returns the greatest item in the queue - fails if empty
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn top<'a>(&'a self) -> &'a T { &self.data[0] }
|
||||
|
||||
/// Returns the greatest item in the queue - None if empty
|
||||
#[cfg(stage0)]
|
||||
fn maybe_top(&self) -> Option<&'self T> {
|
||||
if self.is_empty() { None } else { Some(self.top()) }
|
||||
}
|
||||
|
||||
/// Returns the greatest item in the queue - None if empty
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn maybe_top<'a>(&'a self) -> Option<&'a T> {
|
||||
if self.is_empty() { None } else { Some(self.top()) }
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -50,20 +50,6 @@ impl<V> Map<uint, V> for SmallIntMap<V> {
|
||||
}
|
||||
|
||||
/// Visit all key-value pairs in order
|
||||
#[cfg(stage0)]
|
||||
fn each(&self, it: &fn(&uint, &'self V) -> bool) {
|
||||
for uint::range(0, self.v.len()) |i| {
|
||||
match self.v[i] {
|
||||
Some(ref elt) => if !it(&i, elt) { break },
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Visit all key-value pairs in order
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn each<'a>(&'a self, it: &fn(&uint, &'a V) -> bool) {
|
||||
for uint::range(0, self.v.len()) |i| {
|
||||
match self.v[i] {
|
||||
@ -79,15 +65,6 @@ impl<V> Map<uint, V> for SmallIntMap<V> {
|
||||
}
|
||||
|
||||
/// Visit all values in order
|
||||
#[cfg(stage0)]
|
||||
fn each_value(&self, blk: &fn(value: &V) -> bool) {
|
||||
self.each(|_, v| blk(v))
|
||||
}
|
||||
|
||||
/// Visit all values in order
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn each_value<'a>(&'a self, blk: &fn(value: &'a V) -> bool) {
|
||||
self.each(|_, v| blk(v))
|
||||
}
|
||||
@ -103,22 +80,6 @@ impl<V> Map<uint, V> for SmallIntMap<V> {
|
||||
}
|
||||
|
||||
/// Return a reference to the value corresponding to the key
|
||||
#[cfg(stage0)]
|
||||
fn find(&self, key: &uint) -> Option<&'self V> {
|
||||
if *key < self.v.len() {
|
||||
match self.v[*key] {
|
||||
Some(ref value) => Some(value),
|
||||
None => None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Return a reference to the value corresponding to the key
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn find<'a>(&'a self, key: &uint) -> Option<&'a V> {
|
||||
if *key < self.v.len() {
|
||||
match self.v[*key] {
|
||||
@ -131,22 +92,6 @@ impl<V> Map<uint, V> for SmallIntMap<V> {
|
||||
}
|
||||
|
||||
/// Return a mutable reference to the value corresponding to the key
|
||||
#[cfg(stage0)]
|
||||
fn find_mut(&mut self, key: &uint) -> Option<&'self mut V> {
|
||||
if *key < self.v.len() {
|
||||
match self.v[*key] {
|
||||
Some(ref mut value) => Some(value),
|
||||
None => None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Return a mutable reference to the value corresponding to the key
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn find_mut<'a>(&'a mut self, key: &uint) -> Option<&'a mut V> {
|
||||
if *key < self.v.len() {
|
||||
match self.v[*key] {
|
||||
@ -188,20 +133,6 @@ pub impl<V> SmallIntMap<V> {
|
||||
fn new() -> SmallIntMap<V> { SmallIntMap{v: ~[]} }
|
||||
|
||||
/// Visit all key-value pairs in reverse order
|
||||
#[cfg(stage0)]
|
||||
fn each_reverse(&self, it: &fn(uint, &'self V) -> bool) {
|
||||
for uint::range_rev(self.v.len(), 0) |i| {
|
||||
match self.v[i - 1] {
|
||||
Some(ref elt) => if !it(i - 1, elt) { break },
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Visit all key-value pairs in reverse order
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn each_reverse<'a>(&'a self, it: &fn(uint, &'a V) -> bool) {
|
||||
for uint::range_rev(self.v.len(), 0) |i| {
|
||||
match self.v[i - 1] {
|
||||
@ -211,14 +142,6 @@ pub impl<V> SmallIntMap<V> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn get(&self, key: &uint) -> &'self V {
|
||||
self.find(key).expect("key not present")
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn get<'a>(&'a self, key: &uint) -> &'a V {
|
||||
self.find(key).expect("key not present")
|
||||
}
|
||||
|
@ -71,7 +71,6 @@ pub mod rope;
|
||||
pub mod smallintmap;
|
||||
pub mod sort;
|
||||
pub mod dlist;
|
||||
#[cfg(not(stage0))]
|
||||
pub mod treemap;
|
||||
|
||||
// And ... other stuff
|
||||
@ -91,13 +90,10 @@ pub mod cmp;
|
||||
pub mod base64;
|
||||
pub mod rl;
|
||||
pub mod workcache;
|
||||
#[cfg(not(stage0))]
|
||||
#[path="num/bigint.rs"]
|
||||
pub mod bigint;
|
||||
#[cfg(not(stage0))]
|
||||
#[path="num/rational.rs"]
|
||||
pub mod rational;
|
||||
#[cfg(not(stage0))]
|
||||
#[path="num/complex.rs"]
|
||||
pub mod complex;
|
||||
pub mod stats;
|
||||
|
@ -138,19 +138,6 @@ impl WorkMap {
|
||||
fn new() -> WorkMap { WorkMap(HashMap::new()) }
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<S:Encoder> Encodable<S> for WorkMap {
|
||||
fn encode(&self, s: &S) {
|
||||
let mut d = ~[];
|
||||
for self.each |k, v| {
|
||||
d.push((copy *k, copy *v))
|
||||
}
|
||||
sort::tim_sort(d);
|
||||
d.encode(s)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl<S:Encoder> Encodable<S> for WorkMap {
|
||||
fn encode(&self, s: &mut S) {
|
||||
let mut d = ~[];
|
||||
@ -162,19 +149,6 @@ impl<S:Encoder> Encodable<S> for WorkMap {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<D:Decoder> Decodable<D> for WorkMap {
|
||||
fn decode(d: &D) -> WorkMap {
|
||||
let v : ~[(WorkKey,~str)] = Decodable::decode(d);
|
||||
let mut w = WorkMap::new();
|
||||
for v.each |&(k, v)| {
|
||||
w.insert(copy k, copy v);
|
||||
}
|
||||
w
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl<D:Decoder> Decodable<D> for WorkMap {
|
||||
fn decode(d: &mut D) -> WorkMap {
|
||||
let v : ~[(WorkKey,~str)] = Decodable::decode(d);
|
||||
@ -253,14 +227,6 @@ struct Work<T> {
|
||||
res: Option<Either<T,PortOne<(Exec,T)>>>
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn json_encode<T:Encodable<json::Encoder>>(t: &T) -> ~str {
|
||||
do io::with_str_writer |wr| {
|
||||
t.encode(&json::Encoder(wr));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
fn json_encode<T:Encodable<json::Encoder>>(t: &T) -> ~str {
|
||||
do io::with_str_writer |wr| {
|
||||
let mut encoder = json::Encoder(wr);
|
||||
@ -269,17 +235,6 @@ fn json_encode<T:Encodable<json::Encoder>>(t: &T) -> ~str {
|
||||
}
|
||||
|
||||
// FIXME(#5121)
|
||||
#[cfg(stage0)]
|
||||
fn json_decode<T:Decodable<json::Decoder>>(s: &str) -> T {
|
||||
do io::with_str_reader(s) |rdr| {
|
||||
let j = result::unwrap(json::from_reader(rdr));
|
||||
let decoder = json::Decoder(j);
|
||||
Decodable::decode(&decoder)
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME(#5121)
|
||||
#[cfg(not(stage0))]
|
||||
fn json_decode<T:Decodable<json::Decoder>>(s: &str) -> T {
|
||||
do io::with_str_reader(s) |rdr| {
|
||||
let j = result::unwrap(json::from_reader(rdr));
|
||||
|
@ -70,22 +70,6 @@ pub type Name = uint;
|
||||
// with a macro expansion
|
||||
pub type Mrk = uint;
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<S:Encoder> Encodable<S> for ident {
|
||||
fn encode(&self, s: &S) {
|
||||
unsafe {
|
||||
let intr =
|
||||
match task::local_data::local_data_get(interner_key!()) {
|
||||
None => fail!(~"encode: TLS interner not set up"),
|
||||
Some(intr) => intr
|
||||
};
|
||||
|
||||
s.emit_str(*(*intr).get(*self));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl<S:Encoder> Encodable<S> for ident {
|
||||
fn encode(&self, s: &mut S) {
|
||||
unsafe {
|
||||
@ -100,21 +84,6 @@ impl<S:Encoder> Encodable<S> for ident {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<D:Decoder> Decodable<D> for ident {
|
||||
fn decode(d: &D) -> ident {
|
||||
let intr = match unsafe {
|
||||
task::local_data::local_data_get(interner_key!())
|
||||
} {
|
||||
None => fail!(~"decode: TLS interner not set up"),
|
||||
Some(intr) => intr
|
||||
};
|
||||
|
||||
(*intr).intern(@d.read_str())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl<D:Decoder> Decodable<D> for ident {
|
||||
fn decode(d: &mut D) -> ident {
|
||||
let intr = match unsafe {
|
||||
|
@ -125,13 +125,6 @@ impl cmp::Eq for span {
|
||||
fn ne(&self, other: &span) -> bool { !(*self).eq(other) }
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<S:Encoder> Encodable<S> for span {
|
||||
/* Note #1972 -- spans are encoded but not decoded */
|
||||
fn encode(&self, _s: &S) { _s.emit_nil() }
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl<S:Encoder> Encodable<S> for span {
|
||||
/* Note #1972 -- spans are encoded but not decoded */
|
||||
fn encode(&self, s: &mut S) {
|
||||
@ -139,14 +132,6 @@ impl<S:Encoder> Encodable<S> for span {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<D:Decoder> Decodable<D> for span {
|
||||
fn decode(_d: &D) -> span {
|
||||
dummy_sp()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl<D:Decoder> Decodable<D> for span {
|
||||
fn decode(_d: &mut D) -> span {
|
||||
dummy_sp()
|
||||
|
@ -451,17 +451,6 @@ impl <K: Eq + Hash + IterBytes ,V: Copy> MapChain<K,V>{
|
||||
|
||||
// ugh: can't get this to compile with mut because of the
|
||||
// lack of flow sensitivity.
|
||||
#[cfg(stage0)]
|
||||
fn get_map(&self) -> &'self HashMap<K,@V> {
|
||||
match *self {
|
||||
BaseMapChain (~ref map) => map,
|
||||
ConsMapChain (~ref map,_) => map
|
||||
}
|
||||
}
|
||||
|
||||
// ugh: can't get this to compile with mut because of the
|
||||
// lack of flow sensitivity.
|
||||
#[cfg(not(stage0))]
|
||||
fn get_map<'a>(&'a self) -> &'a HashMap<K,@V> {
|
||||
match *self {
|
||||
BaseMapChain (~ref map) => map,
|
||||
|
@ -61,15 +61,6 @@ impl<T> OptVec<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn get(&self, i: uint) -> &'self T {
|
||||
match *self {
|
||||
Empty => fail!(fmt!("Invalid index %u", i)),
|
||||
Vec(ref v) => &v[i]
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
fn get<'a>(&'a self, i: uint) -> &'a T {
|
||||
match *self {
|
||||
Empty => fail!(fmt!("Invalid index %u", i)),
|
||||
|
@ -1,3 +1,11 @@
|
||||
S 2013-05-03 213f7b2
|
||||
macos-i386 0bf8b88ea01cc4cdd81ac4db1d301ea9b3371f13
|
||||
macos-x86_64 2da3990639ab5a9c9d51b3478c437cb459de84e3
|
||||
linux-i386 094500e587bfac27d7be752b635c242e07774c0d
|
||||
linux-x86_64 75733a5a58f53aa783253c8cfd56923b78676705
|
||||
winnt-i386 bd07c935a917c0796d4dc803d973b864d4794ade
|
||||
freebsd-x86_64 b95d648d9bfeacdd04cc5213bdc803b0fd94add7
|
||||
|
||||
S 2013-03-28 f7a2371
|
||||
macos-i386 2e05a33716fc4982db53946c3b0dccf0194826fe
|
||||
macos-x86_64 fbd3feec8dd17a6b6c8df114e6e9b4cd17cc6172
|
||||
|
Loading…
x
Reference in New Issue
Block a user