diff options
| author | Brian Anderson <banderson@mozilla.com> | 2013-05-04 14:25:41 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2013-05-04 15:43:51 -0700 |
| commit | 8081e8debf63726865e869aaacbd040755285a51 (patch) | |
| tree | 9154d7c17af39c1e817bf27652d6a9d45b4009b5 /src/libstd | |
| parent | b872900a5b4adb53b7d74d45a3138083b22940d6 (diff) | |
| download | rust-8081e8debf63726865e869aaacbd040755285a51.tar.gz rust-8081e8debf63726865e869aaacbd040755285a51.zip | |
Register snapshots
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/arena.rs | 59 | ||||
| -rw-r--r-- | src/libstd/deque.rs | 122 | ||||
| -rw-r--r-- | src/libstd/ebml.rs | 539 | ||||
| -rw-r--r-- | src/libstd/flatpipes.rs | 25 | ||||
| -rw-r--r-- | src/libstd/future.rs | 29 | ||||
| -rw-r--r-- | src/libstd/json.rs | 631 | ||||
| -rw-r--r-- | src/libstd/priority_queue.rs | 16 | ||||
| -rw-r--r-- | src/libstd/serialize.rs | 978 | ||||
| -rw-r--r-- | src/libstd/smallintmap.rs | 77 | ||||
| -rw-r--r-- | src/libstd/std.rc | 4 | ||||
| -rw-r--r-- | src/libstd/workcache.rs | 45 |
11 files changed, 0 insertions, 2525 deletions
diff --git a/src/libstd/arena.rs b/src/libstd/arena.rs index 67b5e5e654a..b9a09323f81 100644 --- a/src/libstd/arena.rs +++ b/src/libstd/arena.rs @@ -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 diff --git a/src/libstd/deque.rs b/src/libstd/deque.rs index 8a310a9f52b..65e71869a1f 100644 --- a/src/libstd/deque.rs +++ b/src/libstd/deque.rs @@ -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> { diff --git a/src/libstd/ebml.rs b/src/libstd/ebml.rs index 41c5a0f7690..8a4bc823fd8 100644 --- a/src/libstd/ebml.rs +++ b/src/libstd/ebml.rs @@ -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) {} diff --git a/src/libstd/flatpipes.rs b/src/libstd/flatpipes.rs index 52d6afbb93e..88de53f3605 100644 --- a/src/libstd/flatpipes.rs +++ b/src/libstd/flatpipes.rs @@ -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) diff --git a/src/libstd/future.rs b/src/libstd/future.rs index a0312849a35..5e3e64b2f1c 100644 --- a/src/libstd/future.rs +++ b/src/libstd/future.rs @@ -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 diff --git a/src/libstd/json.rs b/src/libstd/json.rs index 6951ee377c9..3960a07dfce 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -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, diff --git a/src/libstd/priority_queue.rs b/src/libstd/priority_queue.rs index 47af3576c90..33fe1cfff8e 100644 --- a/src/libstd/priority_queue.rs +++ b/src/libstd/priority_queue.rs @@ -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()) } } diff --git a/src/libstd/serialize.rs b/src/libstd/serialize.rs index 39fb5a45d7e..a5d2604b6f6 100644 --- a/src/libstd/serialize.rs +++ b/src/libstd/serialize.rs @@ -20,80 +20,8 @@ use core::hashmap::{HashMap, HashSet}; use core::trie::{TrieMap, TrieSet}; use deque::Deque; use dlist::DList; -#[cfg(stage1)] -#[cfg(stage2)] -#[cfg(stage3)] use treemap::{TreeMap, TreeSet}; -#[cfg(stage0)] -pub trait Encoder { - // Primitive types: - fn emit_nil(&self); - fn emit_uint(&self, v: uint); - fn emit_u64(&self, v: u64); - fn emit_u32(&self, v: u32); - fn emit_u16(&self, v: u16); - fn emit_u8(&self, v: u8); - fn emit_int(&self, v: int); - fn emit_i64(&self, v: i64); - fn emit_i32(&self, v: i32); - fn emit_i16(&self, v: i16); - fn emit_i8(&self, v: i8); - fn emit_bool(&self, v: bool); - fn emit_float(&self, v: float); - fn emit_f64(&self, v: f64); - fn emit_f32(&self, v: f32); - fn emit_char(&self, v: char); - fn emit_str(&self, v: &str); - - // Compound types: - fn emit_enum(&self, name: &str, f: &fn()); - - fn emit_enum_variant(&self, - v_name: &str, - v_id: uint, - len: uint, - f: &fn()); - fn emit_enum_variant_arg(&self, a_idx: uint, f: &fn()); - - fn emit_enum_struct_variant(&self, - v_name: &str, - v_id: uint, - len: uint, - f: &fn()); - fn emit_enum_struct_variant_field(&self, - f_name: &str, - f_idx: uint, - f: &fn()); - - fn emit_struct(&self, name: &str, len: uint, f: &fn()); - #[cfg(stage0)] - fn emit_field(&self, f_name: &str, f_idx: uint, f: &fn()); - #[cfg(stage1)] - #[cfg(stage2)] - #[cfg(stage3)] - fn emit_struct_field(&self, f_name: &str, f_idx: uint, f: &fn()); - - fn emit_tuple(&self, len: uint, f: &fn()); - fn emit_tuple_arg(&self, idx: uint, f: &fn()); - - fn emit_tuple_struct(&self, name: &str, len: uint, f: &fn()); - fn emit_tuple_struct_arg(&self, f_idx: uint, f: &fn()); - - // Specialized types: - fn emit_option(&self, f: &fn()); - fn emit_option_none(&self); - fn emit_option_some(&self, f: &fn()); - - fn emit_seq(&self, len: uint, f: &fn()); - fn emit_seq_elt(&self, idx: uint, f: &fn()); - - fn emit_map(&self, len: uint, f: &fn()); - fn emit_map_elt_key(&self, idx: uint, f: &fn()); - fn emit_map_elt_val(&self, idx: uint, f: &fn()); -} - -#[cfg(not(stage0))] pub trait Encoder { // Primitive types: fn emit_nil(&mut self); @@ -159,80 +87,6 @@ pub trait Encoder { fn emit_map_elt_val(&mut self, idx: uint, f: &fn(&mut Self)); } -#[cfg(stage0)] -pub trait Decoder { - // Primitive types: - fn read_nil(&self) -> (); - fn read_uint(&self) -> uint; - fn read_u64(&self) -> u64; - fn read_u32(&self) -> u32; - fn read_u16(&self) -> u16; - fn read_u8(&self) -> u8; - fn read_int(&self) -> int; - fn read_i64(&self) -> i64; - fn read_i32(&self) -> i32; - fn read_i16(&self) -> i16; - fn read_i8(&self) -> i8; - fn read_bool(&self) -> bool; - fn read_f64(&self) -> f64; - fn read_f32(&self) -> f32; - fn read_float(&self) -> float; - fn read_char(&self) -> char; - fn read_str(&self) -> ~str; - - // Compound types: - fn read_enum<T>(&self, name: &str, f: &fn() -> T) -> T; - - fn read_enum_variant<T>(&self, - names: &[&str], - f: &fn(uint) -> T) - -> T; - fn read_enum_variant_arg<T>(&self, a_idx: uint, f: &fn() -> T) -> T; - - fn read_enum_struct_variant<T>(&self, - names: &[&str], - f: &fn(uint) -> T) - -> T; - fn read_enum_struct_variant_field<T>(&self, - &f_name: &str, - f_idx: uint, - f: &fn() -> T) - -> T; - - fn read_struct<T>(&self, s_name: &str, len: uint, f: &fn() -> T) -> T; - #[cfg(stage0)] - fn read_field<T>(&self, - f_name: &str, - f_idx: uint, - f: &fn() -> T) - -> T; - #[cfg(stage1)] - #[cfg(stage2)] - #[cfg(stage3)] - fn read_struct_field<T>(&self, - f_name: &str, - f_idx: uint, - f: &fn() -> T) - -> T; - - fn read_tuple<T>(&self, f: &fn(uint) -> T) -> T; - fn read_tuple_arg<T>(&self, a_idx: uint, f: &fn() -> T) -> T; - - fn read_tuple_struct<T>(&self, s_name: &str, f: &fn(uint) -> T) -> T; - fn read_tuple_struct_arg<T>(&self, a_idx: uint, f: &fn() -> T) -> T; - - // Specialized types: - fn read_option<T>(&self, f: &fn(bool) -> T) -> T; - - fn read_seq<T>(&self, f: &fn(uint) -> T) -> T; - fn read_seq_elt<T>(&self, idx: uint, f: &fn() -> T) -> T; - - fn read_map<T>(&self, f: &fn(uint) -> T) -> T; - fn read_map_elt_key<T>(&self, idx: uint, f: &fn() -> T) -> T; - fn read_map_elt_val<T>(&self, idx: uint, f: &fn() -> T) -> T; -} - -#[cfg(not(stage0))] pub trait Decoder { // Primitive types: fn read_nil(&mut self) -> (); @@ -280,15 +134,6 @@ pub trait Decoder { len: uint, f: &fn(&mut Self) -> T) -> T; - #[cfg(stage0)] - fn read_field<T>(&mut self, - f_name: &str, - f_idx: uint, - f: &fn() -> T) - -> T; - #[cfg(stage1)] - #[cfg(stage2)] - #[cfg(stage3)] fn read_struct_field<T>(&mut self, f_name: &str, f_idx: uint, @@ -318,598 +163,254 @@ pub trait Decoder { fn read_map_elt_val<T>(&mut self, idx: uint, f: &fn(&mut Self) -> T) -> T; } -#[cfg(stage0)] -pub trait Encodable<S:Encoder> { - fn encode(&self, s: &S); -} - -#[cfg(not(stage0))] pub trait Encodable<S:Encoder> { fn encode(&self, s: &mut S); } -#[cfg(stage0)] -pub trait Decodable<D:Decoder> { - fn decode(d: &D) -> Self; -} - -#[cfg(not(stage0))] pub trait Decodable<D:Decoder> { fn decode(d: &mut D) -> Self; } -#[cfg(stage0)] -impl<S:Encoder> Encodable<S> for uint { - fn encode(&self, s: &S) { - s.emit_uint(*self) - } -} - -#[cfg(not(stage0))] impl<S:Encoder> Encodable<S> for uint { fn encode(&self, s: &mut S) { s.emit_uint(*self) } } -#[cfg(stage0)] -impl<D:Decoder> Decodable<D> for uint { - fn decode(d: &D) -> uint { - d.read_uint() - } -} - -#[cfg(not(stage0))] impl<D:Decoder> Decodable<D> for uint { fn decode(d: &mut D) -> uint { d.read_uint() } } -#[cfg(stage0)] -impl<S:Encoder> Encodable<S> for u8 { - fn encode(&self, s: &S) { - s.emit_u8(*self) - } -} - -#[cfg(not(stage0))] impl<S:Encoder> Encodable<S> for u8 { fn encode(&self, s: &mut S) { s.emit_u8(*self) } } -#[cfg(stage0)] -impl<D:Decoder> Decodable<D> for u8 { - fn decode(d: &D) -> u8 { - d.read_u8() - } -} - -#[cfg(not(stage0))] impl<D:Decoder> Decodable<D> for u8 { fn decode(d: &mut D) -> u8 { d.read_u8() } } -#[cfg(stage0)] -impl<S:Encoder> Encodable<S> for u16 { - fn encode(&self, s: &S) { - s.emit_u16(*self) - } -} - -#[cfg(not(stage0))] impl<S:Encoder> Encodable<S> for u16 { fn encode(&self, s: &mut S) { s.emit_u16(*self) } } -#[cfg(stage0)] -impl<D:Decoder> Decodable<D> for u16 { - fn decode(d: &D) -> u16 { - d.read_u16() - } -} - -#[cfg(not(stage0))] impl<D:Decoder> Decodable<D> for u16 { fn decode(d: &mut D) -> u16 { d.read_u16() } } -#[cfg(stage0)] -impl<S:Encoder> Encodable<S> for u32 { - fn encode(&self, s: &S) { - s.emit_u32(*self) - } -} - -#[cfg(not(stage0))] impl<S:Encoder> Encodable<S> for u32 { fn encode(&self, s: &mut S) { s.emit_u32(*self) } } -#[cfg(stage0)] -impl<D:Decoder> Decodable<D> for u32 { - fn decode(d: &D) -> u32 { - d.read_u32() - } -} - -#[cfg(not(stage0))] impl<D:Decoder> Decodable<D> for u32 { fn decode(d: &mut D) -> u32 { d.read_u32() } } -#[cfg(stage0)] -impl<S:Encoder> Encodable<S> for u64 { - fn encode(&self, s: &S) { - s.emit_u64(*self) - } -} - -#[cfg(not(stage0))] impl<S:Encoder> Encodable<S> for u64 { fn encode(&self, s: &mut S) { s.emit_u64(*self) } } -#[cfg(stage0)] -impl<D:Decoder> Decodable<D> for u64 { - fn decode(d: &D) -> u64 { - d.read_u64() - } -} - -#[cfg(not(stage0))] impl<D:Decoder> Decodable<D> for u64 { fn decode(d: &mut D) -> u64 { d.read_u64() } } -#[cfg(stage0)] -impl<S:Encoder> Encodable<S> for int { - fn encode(&self, s: &S) { - s.emit_int(*self) - } -} - -#[cfg(not(stage0))] impl<S:Encoder> Encodable<S> for int { fn encode(&self, s: &mut S) { s.emit_int(*self) } } -#[cfg(stage0)] -impl<D:Decoder> Decodable<D> for int { - fn decode(d: &D) -> int { - d.read_int() - } -} - -#[cfg(not(stage0))] impl<D:Decoder> Decodable<D> for int { fn decode(d: &mut D) -> int { d.read_int() } } -#[cfg(stage0)] -impl<S:Encoder> Encodable<S> for i8 { - fn encode(&self, s: &S) { - s.emit_i8(*self) - } -} - -#[cfg(not(stage0))] impl<S:Encoder> Encodable<S> for i8 { fn encode(&self, s: &mut S) { s.emit_i8(*self) } } -#[cfg(stage0)] -impl<D:Decoder> Decodable<D> for i8 { - fn decode(d: &D) -> i8 { - d.read_i8() - } -} - -#[cfg(not(stage0))] impl<D:Decoder> Decodable<D> for i8 { fn decode(d: &mut D) -> i8 { d.read_i8() } } -#[cfg(stage0)] -impl<S:Encoder> Encodable<S> for i16 { - fn encode(&self, s: &S) { - s.emit_i16(*self) - } -} - -#[cfg(not(stage0))] impl<S:Encoder> Encodable<S> for i16 { fn encode(&self, s: &mut S) { s.emit_i16(*self) } } -#[cfg(stage0)] -impl<D:Decoder> Decodable<D> for i16 { - fn decode(d: &D) -> i16 { - d.read_i16() - } -} - -#[cfg(not(stage0))] impl<D:Decoder> Decodable<D> for i16 { fn decode(d: &mut D) -> i16 { d.read_i16() } } -#[cfg(stage0)] -impl<S:Encoder> Encodable<S> for i32 { - fn encode(&self, s: &S) { - s.emit_i32(*self) - } -} - -#[cfg(not(stage0))] impl<S:Encoder> Encodable<S> for i32 { fn encode(&self, s: &mut S) { s.emit_i32(*self) } } -#[cfg(stage0)] -impl<D:Decoder> Decodable<D> for i32 { - fn decode(d: &D) -> i32 { - d.read_i32() - } -} - -#[cfg(not(stage0))] impl<D:Decoder> Decodable<D> for i32 { fn decode(d: &mut D) -> i32 { d.read_i32() } } -#[cfg(stage0)] -impl<S:Encoder> Encodable<S> for i64 { - fn encode(&self, s: &S) { - s.emit_i64(*self) - } -} - -#[cfg(not(stage0))] impl<S:Encoder> Encodable<S> for i64 { fn encode(&self, s: &mut S) { s.emit_i64(*self) } } -#[cfg(stage0)] -impl<D:Decoder> Decodable<D> for i64 { - fn decode(d: &D) -> i64 { - d.read_i64() - } -} - -#[cfg(not(stage0))] impl<D:Decoder> Decodable<D> for i64 { fn decode(d: &mut D) -> i64 { d.read_i64() } } -#[cfg(stage0)] -impl<'self, S:Encoder> Encodable<S> for &'self str { - fn encode(&self, s: &S) { - s.emit_str(*self) - } -} - -#[cfg(not(stage0))] impl<'self, S:Encoder> Encodable<S> for &'self str { fn encode(&self, s: &mut S) { s.emit_str(*self) } } -#[cfg(stage0)] -impl<S:Encoder> Encodable<S> for ~str { - fn encode(&self, s: &S) { - s.emit_str(*self) - } -} - -#[cfg(not(stage0))] impl<S:Encoder> Encodable<S> for ~str { fn encode(&self, s: &mut S) { s.emit_str(*self) } } -#[cfg(stage0)] -impl<D:Decoder> Decodable<D> for ~str { - fn decode(d: &D) -> ~str { - d.read_str() - } -} - -#[cfg(not(stage0))] impl<D:Decoder> Decodable<D> for ~str { fn decode(d: &mut D) -> ~str { d.read_str() } } -#[cfg(stage0)] -impl<S:Encoder> Encodable<S> for @str { - fn encode(&self, s: &S) { - s.emit_str(*self) - } -} - -#[cfg(not(stage0))] impl<S:Encoder> Encodable<S> for @str { fn encode(&self, s: &mut S) { s.emit_str(*self) } } -#[cfg(stage0)] -impl<D:Decoder> Decodable<D> for @str { - fn decode(d: &D) -> @str { - d.read_str().to_managed() - } -} - -#[cfg(not(stage0))] impl<D:Decoder> Decodable<D> for @str { fn decode(d: &mut D) -> @str { d.read_str().to_managed() } } -#[cfg(stage0)] -impl<S:Encoder> Encodable<S> for float { - fn encode(&self, s: &S) { - s.emit_float(*self) - } -} - -#[cfg(not(stage0))] impl<S:Encoder> Encodable<S> for float { fn encode(&self, s: &mut S) { s.emit_float(*self) } } -#[cfg(stage0)] -impl<D:Decoder> Decodable<D> for float { - fn decode(d: &D) -> float { - d.read_float() - } -} - -#[cfg(not(stage0))] impl<D:Decoder> Decodable<D> for float { fn decode(d: &mut D) -> float { d.read_float() } } -#[cfg(stage0)] -impl<S:Encoder> Encodable<S> for f32 { - fn encode(&self, s: &S) { - s.emit_f32(*self) - } -} - -#[cfg(not(stage0))] impl<S:Encoder> Encodable<S> for f32 { fn encode(&self, s: &mut S) { s.emit_f32(*self) } } -#[cfg(stage0)] -impl<D:Decoder> Decodable<D> for f32 { - fn decode(d: &D) -> f32 { - d.read_f32() - } -} - -#[cfg(not(stage0))] impl<D:Decoder> Decodable<D> for f32 { fn decode(d: &mut D) -> f32 { d.read_f32() } } -#[cfg(stage0)] -impl<S:Encoder> Encodable<S> for f64 { - fn encode(&self, s: &S) { - s.emit_f64(*self) - } -} - -#[cfg(not(stage0))] impl<S:Encoder> Encodable<S> for f64 { fn encode(&self, s: &mut S) { s.emit_f64(*self) } } -#[cfg(stage0)] -impl<D:Decoder> Decodable<D> for f64 { - fn decode(d: &D) -> f64 { - d.read_f64() - } -} - -#[cfg(not(stage0))] impl<D:Decoder> Decodable<D> for f64 { fn decode(d: &mut D) -> f64 { d.read_f64() } } -#[cfg(stage0)] -impl<S:Encoder> Encodable<S> for bool { - fn encode(&self, s: &S) { - s.emit_bool(*self) - } -} - -#[cfg(not(stage0))] impl<S:Encoder> Encodable<S> for bool { fn encode(&self, s: &mut S) { s.emit_bool(*self) } } -#[cfg(stage0)] -impl<D:Decoder> Decodable<D> for bool { - fn decode(d: &D) -> bool { - d.read_bool() - } -} - -#[cfg(not(stage0))] impl<D:Decoder> Decodable<D> for bool { fn decode(d: &mut D) -> bool { d.read_bool() } } -#[cfg(stage0)] -impl<S:Encoder> Encodable<S> for () { - fn encode(&self, s: &S) { - s.emit_nil() - } -} - -#[cfg(not(stage0))] impl<S:Encoder> Encodable<S> for () { fn encode(&self, s: &mut S) { s.emit_nil() } } -#[cfg(stage0)] -impl<D:Decoder> Decodable<D> for () { - fn decode(d: &D) -> () { - d.read_nil() - } -} - -#[cfg(not(stage0))] impl<D:Decoder> Decodable<D> for () { fn decode(d: &mut D) -> () { d.read_nil() } } -#[cfg(stage0)] -impl<'self, S:Encoder,T:Encodable<S>> Encodable<S> for &'self T { - fn encode(&self, s: &S) { - (**self).encode(s) - } -} - -#[cfg(not(stage0))] impl<'self, S:Encoder,T:Encodable<S>> Encodable<S> for &'self T { fn encode(&self, s: &mut S) { (**self).encode(s) } } -#[cfg(stage0)] -impl<S:Encoder,T:Encodable<S>> Encodable<S> for ~T { - fn encode(&self, s: &S) { - (**self).encode(s) - } -} - -#[cfg(not(stage0))] impl<S:Encoder,T:Encodable<S>> Encodable<S> for ~T { fn encode(&self, s: &mut S) { (**self).encode(s) } } -#[cfg(stage0)] -impl<D:Decoder,T:Decodable<D>> Decodable<D> for ~T { - fn decode(d: &D) -> ~T { - ~Decodable::decode(d) - } -} - -#[cfg(not(stage0))] impl<D:Decoder,T:Decodable<D>> Decodable<D> for ~T { fn decode(d: &mut D) -> ~T { ~Decodable::decode(d) } } -#[cfg(stage0)] -impl<S:Encoder,T:Encodable<S>> Encodable<S> for @T { - fn encode(&self, s: &S) { - (**self).encode(s) - } -} - -#[cfg(not(stage0))] impl<S:Encoder,T:Encodable<S>> Encodable<S> for @T { fn encode(&self, s: &mut S) { (**self).encode(s) } } -#[cfg(stage0)] -impl<D:Decoder,T:Decodable<D>> Decodable<D> for @T { - fn decode(d: &D) -> @T { - @Decodable::decode(d) - } -} - -#[cfg(not(stage0))] impl<D:Decoder,T:Decodable<D>> Decodable<D> for @T { fn decode(d: &mut D) -> @T { @Decodable::decode(d) } } -#[cfg(stage0)] -impl<'self, S:Encoder,T:Encodable<S>> Encodable<S> for &'self [T] { - fn encode(&self, s: &S) { - do s.emit_seq(self.len()) { - for self.eachi |i, e| { - s.emit_seq_elt(i, || e.encode(s)) - } - } - } -} - -#[cfg(not(stage0))] impl<'self, S:Encoder,T:Encodable<S>> Encodable<S> for &'self [T] { fn encode(&self, s: &mut S) { do s.emit_seq(self.len()) |s| { @@ -920,18 +421,6 @@ impl<'self, S:Encoder,T:Encodable<S>> Encodable<S> for &'self [T] { } } -#[cfg(stage0)] -impl<S:Encoder,T:Encodable<S>> Encodable<S> for ~[T] { - fn encode(&self, s: &S) { - do s.emit_seq(self.len()) { - for self.eachi |i, e| { - s.emit_seq_elt(i, || e.encode(s)) - } - } - } -} - -#[cfg(not(stage0))] impl<S:Encoder,T:Encodable<S>> Encodable<S> for ~[T] { fn encode(&self, s: &mut S) { do s.emit_seq(self.len()) |s| { @@ -942,18 +431,6 @@ impl<S:Encoder,T:Encodable<S>> Encodable<S> for ~[T] { } } -#[cfg(stage0)] -impl<D:Decoder,T:Decodable<D>> Decodable<D> for ~[T] { - fn decode(d: &D) -> ~[T] { - do d.read_seq |len| { - do vec::from_fn(len) |i| { - d.read_seq_elt(i, || Decodable::decode(d)) - } - } - } -} - -#[cfg(not(stage0))] impl<D:Decoder,T:Decodable<D>> Decodable<D> for ~[T] { fn decode(d: &mut D) -> ~[T] { do d.read_seq |d, len| { @@ -964,18 +441,6 @@ impl<D:Decoder,T:Decodable<D>> Decodable<D> for ~[T] { } } -#[cfg(stage0)] -impl<S:Encoder,T:Encodable<S>> Encodable<S> for @[T] { - fn encode(&self, s: &S) { - do s.emit_seq(self.len()) { - for self.eachi |i, e| { - s.emit_seq_elt(i, || e.encode(s)) - } - } - } -} - -#[cfg(not(stage0))] impl<S:Encoder,T:Encodable<S>> Encodable<S> for @[T] { fn encode(&self, s: &mut S) { do s.emit_seq(self.len()) |s| { @@ -986,18 +451,6 @@ impl<S:Encoder,T:Encodable<S>> Encodable<S> for @[T] { } } -#[cfg(stage0)] -impl<D:Decoder,T:Decodable<D>> Decodable<D> for @[T] { - fn decode(d: &D) -> @[T] { - do d.read_seq |len| { - do at_vec::from_fn(len) |i| { - d.read_seq_elt(i, || Decodable::decode(d)) - } - } - } -} - -#[cfg(not(stage0))] impl<D:Decoder,T:Decodable<D>> Decodable<D> for @[T] { fn decode(d: &mut D) -> @[T] { do d.read_seq |d, len| { @@ -1008,19 +461,6 @@ impl<D:Decoder,T:Decodable<D>> Decodable<D> for @[T] { } } -#[cfg(stage0)] -impl<S:Encoder,T:Encodable<S>> Encodable<S> for Option<T> { - fn encode(&self, s: &S) { - do s.emit_option { - match *self { - None => s.emit_option_none(), - Some(ref v) => s.emit_option_some(|| v.encode(s)), - } - } - } -} - -#[cfg(not(stage0))] impl<S:Encoder,T:Encodable<S>> Encodable<S> for Option<T> { fn encode(&self, s: &mut S) { do s.emit_option |s| { @@ -1032,20 +472,6 @@ impl<S:Encoder,T:Encodable<S>> Encodable<S> for Option<T> { } } -#[cfg(stage0)] -impl<D:Decoder,T:Decodable<D>> Decodable<D> for Option<T> { - fn decode(d: &D) -> Option<T> { - do d.read_option |b| { - if b { - Some(Decodable::decode(d)) - } else { - None - } - } - } -} - -#[cfg(not(stage0))] impl<D:Decoder,T:Decodable<D>> Decodable<D> for Option<T> { fn decode(d: &mut D) -> Option<T> { do d.read_option |d, b| { @@ -1058,21 +484,6 @@ impl<D:Decoder,T:Decodable<D>> Decodable<D> for Option<T> { } } -#[cfg(stage0)] -impl<S:Encoder,T0:Encodable<S>,T1:Encodable<S>> Encodable<S> for (T0, T1) { - fn encode(&self, s: &S) { - match *self { - (ref t0, ref t1) => { - do s.emit_seq(2) { - s.emit_seq_elt(0, || t0.encode(s)); - s.emit_seq_elt(1, || t1.encode(s)); - } - } - } - } -} - -#[cfg(not(stage0))] impl<S:Encoder,T0:Encodable<S>,T1:Encodable<S>> Encodable<S> for (T0, T1) { fn encode(&self, s: &mut S) { match *self { @@ -1086,20 +497,6 @@ impl<S:Encoder,T0:Encodable<S>,T1:Encodable<S>> Encodable<S> for (T0, T1) { } } -#[cfg(stage0)] -impl<D:Decoder,T0:Decodable<D>,T1:Decodable<D>> Decodable<D> for (T0, T1) { - fn decode(d: &D) -> (T0, T1) { - do d.read_seq |len| { - assert!(len == 2); - ( - d.read_seq_elt(0, || Decodable::decode(d)), - d.read_seq_elt(1, || Decodable::decode(d)) - ) - } - } -} - -#[cfg(not(stage0))] impl<D:Decoder,T0:Decodable<D>,T1:Decodable<D>> Decodable<D> for (T0, T1) { fn decode(d: &mut D) -> (T0, T1) { do d.read_seq |d, len| { @@ -1112,27 +509,6 @@ impl<D:Decoder,T0:Decodable<D>,T1:Decodable<D>> Decodable<D> for (T0, T1) { } } -#[cfg(stage0)] -impl< - S: Encoder, - T0: Encodable<S>, - T1: Encodable<S>, - T2: Encodable<S> -> Encodable<S> for (T0, T1, T2) { - fn encode(&self, s: &S) { - match *self { - (ref t0, ref t1, ref t2) => { - do s.emit_seq(3) { - s.emit_seq_elt(0, || t0.encode(s)); - s.emit_seq_elt(1, || t1.encode(s)); - s.emit_seq_elt(2, || t2.encode(s)); - } - } - } - } -} - -#[cfg(not(stage0))] impl< S: Encoder, T0: Encodable<S>, @@ -1152,26 +528,6 @@ impl< } } -#[cfg(stage0)] -impl< - D: Decoder, - T0: Decodable<D>, - T1: Decodable<D>, - T2: Decodable<D> -> Decodable<D> for (T0, T1, T2) { - fn decode(d: &D) -> (T0, T1, T2) { - do d.read_seq |len| { - assert!(len == 3); - ( - d.read_seq_elt(0, || Decodable::decode(d)), - d.read_seq_elt(1, || Decodable::decode(d)), - d.read_seq_elt(2, || Decodable::decode(d)) - ) - } - } -} - -#[cfg(not(stage0))] impl< D: Decoder, T0: Decodable<D>, @@ -1190,29 +546,6 @@ impl< } } -#[cfg(stage0)] -impl< - S: Encoder, - T0: Encodable<S>, - T1: Encodable<S>, - T2: Encodable<S>, - T3: Encodable<S> -> Encodable<S> for (T0, T1, T2, T3) { - fn encode(&self, s: &S) { - match *self { - (ref t0, ref t1, ref t2, ref t3) => { - do s.emit_seq(4) { - s.emit_seq_elt(0, || t0.encode(s)); - s.emit_seq_elt(1, || t1.encode(s)); - s.emit_seq_elt(2, || t2.encode(s)); - s.emit_seq_elt(3, || t3.encode(s)); - } - } - } - } -} - -#[cfg(not(stage0))] impl< S: Encoder, T0: Encodable<S>, @@ -1234,28 +567,6 @@ impl< } } -#[cfg(stage0)] -impl< - D: Decoder, - T0: Decodable<D>, - T1: Decodable<D>, - T2: Decodable<D>, - T3: Decodable<D> -> Decodable<D> for (T0, T1, T2, T3) { - fn decode(d: &D) -> (T0, T1, T2, T3) { - do d.read_seq |len| { - assert!(len == 4); - ( - d.read_seq_elt(0, || Decodable::decode(d)), - d.read_seq_elt(1, || Decodable::decode(d)), - d.read_seq_elt(2, || Decodable::decode(d)), - d.read_seq_elt(3, || Decodable::decode(d)) - ) - } - } -} - -#[cfg(not(stage0))] impl< D: Decoder, T0: Decodable<D>, @@ -1276,31 +587,6 @@ impl< } } -#[cfg(stage0)] -impl< - S: Encoder, - T0: Encodable<S>, - T1: Encodable<S>, - T2: Encodable<S>, - T3: Encodable<S>, - T4: Encodable<S> -> Encodable<S> for (T0, T1, T2, T3, T4) { - fn encode(&self, s: &S) { - match *self { - (ref t0, ref t1, ref t2, ref t3, ref t4) => { - do s.emit_seq(5) { - s.emit_seq_elt(0, || t0.encode(s)); - s.emit_seq_elt(1, || t1.encode(s)); - s.emit_seq_elt(2, || t2.encode(s)); - s.emit_seq_elt(3, || t3.encode(s)); - s.emit_seq_elt(4, || t4.encode(s)); - } - } - } - } -} - -#[cfg(not(stage0))] impl< S: Encoder, T0: Encodable<S>, @@ -1324,30 +610,6 @@ impl< } } -#[cfg(stage0)] -impl< - D: Decoder, - T0: Decodable<D>, - T1: Decodable<D>, - T2: Decodable<D>, - T3: Decodable<D>, - T4: Decodable<D> -> Decodable<D> for (T0, T1, T2, T3, T4) { - fn decode(d: &D) -> (T0, T1, T2, T3, T4) { - do d.read_seq |len| { - assert!(len == 5); - ( - d.read_seq_elt(0, || Decodable::decode(d)), - d.read_seq_elt(1, || Decodable::decode(d)), - d.read_seq_elt(2, || Decodable::decode(d)), - d.read_seq_elt(3, || Decodable::decode(d)), - d.read_seq_elt(4, || Decodable::decode(d)) - ) - } - } -} - -#[cfg(not(stage0))] impl< D: Decoder, T0: Decodable<D>, @@ -1370,23 +632,6 @@ impl< } } -#[cfg(stage0)] -impl< - S: Encoder, - T: Encodable<S> + Copy -> Encodable<S> for @mut DList<T> { - fn encode(&self, s: &S) { - do s.emit_seq(self.size) { - let mut i = 0; - for self.each |e| { - s.emit_seq_elt(i, || e.encode(s)); - i += 1; - } - } - } -} - -#[cfg(not(stage0))] impl< S: Encoder, T: Encodable<S> + Copy @@ -1402,20 +647,6 @@ impl< } } -#[cfg(stage0)] -impl<D:Decoder,T:Decodable<D>> Decodable<D> for @mut DList<T> { - fn decode(d: &D) -> @mut DList<T> { - let list = DList(); - do d.read_seq |len| { - for uint::range(0, len) |i| { - list.push(d.read_seq_elt(i, || Decodable::decode(d))); - } - } - list - } -} - -#[cfg(not(stage0))] impl<D:Decoder,T:Decodable<D>> Decodable<D> for @mut DList<T> { fn decode(d: &mut D) -> @mut DList<T> { let list = DList(); @@ -1428,21 +659,6 @@ impl<D:Decoder,T:Decodable<D>> Decodable<D> for @mut DList<T> { } } -#[cfg(stage0)] -impl< - S: Encoder, - T: Encodable<S> -> Encodable<S> for Deque<T> { - fn encode(&self, s: &S) { - do s.emit_seq(self.len()) { - for self.eachi |i, e| { - s.emit_seq_elt(i, || e.encode(s)); - } - } - } -} - -#[cfg(not(stage0))] impl< S: Encoder, T: Encodable<S> @@ -1456,20 +672,6 @@ impl< } } -#[cfg(stage0)] -impl<D:Decoder,T:Decodable<D>> Decodable<D> for Deque<T> { - fn decode(d: &D) -> Deque<T> { - let mut deque = Deque::new(); - do d.read_seq |len| { - for uint::range(0, len) |i| { - deque.add_back(d.read_seq_elt(i, || Decodable::decode(d))); - } - } - deque - } -} - -#[cfg(not(stage0))] impl<D:Decoder,T:Decodable<D>> Decodable<D> for Deque<T> { fn decode(d: &mut D) -> Deque<T> { let mut deque = Deque::new(); @@ -1482,25 +684,6 @@ impl<D:Decoder,T:Decodable<D>> Decodable<D> for Deque<T> { } } -#[cfg(stage0)] -impl< - E: Encoder, - K: Encodable<E> + Hash + IterBytes + Eq, - V: Encodable<E> -> Encodable<E> for HashMap<K, V> { - fn encode(&self, e: &E) { - do e.emit_map(self.len()) { - let mut i = 0; - for self.each |key, val| { - e.emit_map_elt_key(i, || key.encode(e)); - e.emit_map_elt_val(i, || val.encode(e)); - i += 1; - } - } - } -} - -#[cfg(not(stage0))] impl< E: Encoder, K: Encodable<E> + Hash + IterBytes + Eq, @@ -1518,26 +701,6 @@ impl< } } -#[cfg(stage0)] -impl< - D: Decoder, - K: Decodable<D> + Hash + IterBytes + Eq, - V: Decodable<D> -> Decodable<D> for HashMap<K, V> { - fn decode(d: &D) -> HashMap<K, V> { - do d.read_map |len| { - let mut map = HashMap::with_capacity(len); - for uint::range(0, len) |i| { - let key = d.read_map_elt_key(i, || Decodable::decode(d)); - let val = d.read_map_elt_val(i, || Decodable::decode(d)); - map.insert(key, val); - } - map - } - } -} - -#[cfg(not(stage0))] impl< D: Decoder, K: Decodable<D> + Hash + IterBytes + Eq, @@ -1556,23 +719,6 @@ impl< } } -#[cfg(stage0)] -impl< - S: Encoder, - T: Encodable<S> + Hash + IterBytes + Eq -> Encodable<S> for HashSet<T> { - fn encode(&self, s: &S) { - do s.emit_seq(self.len()) { - let mut i = 0; - for self.each |e| { - s.emit_seq_elt(i, || e.encode(s)); - i += 1; - } - } - } -} - -#[cfg(not(stage0))] impl< S: Encoder, T: Encodable<S> + Hash + IterBytes + Eq @@ -1588,23 +734,6 @@ impl< } } -#[cfg(stage0)] -impl< - D: Decoder, - T: Decodable<D> + Hash + IterBytes + Eq -> Decodable<D> for HashSet<T> { - fn decode(d: &D) -> HashSet<T> { - do d.read_seq |len| { - let mut set = HashSet::with_capacity(len); - for uint::range(0, len) |i| { - set.insert(d.read_seq_elt(i, || Decodable::decode(d))); - } - set - } - } -} - -#[cfg(not(stage0))] impl< D: Decoder, T: Decodable<D> + Hash + IterBytes + Eq @@ -1620,24 +749,6 @@ impl< } } -#[cfg(stage0)] -impl< - E: Encoder, - V: Encodable<E> -> Encodable<E> for TrieMap<V> { - fn encode(&self, e: &E) { - do e.emit_map(self.len()) { - let mut i = 0; - for self.each |key, val| { - e.emit_map_elt_key(i, || key.encode(e)); - e.emit_map_elt_val(i, || val.encode(e)); - i += 1; - } - } - } -} - -#[cfg(not(stage0))] impl< E: Encoder, V: Encodable<E> @@ -1654,25 +765,6 @@ impl< } } -#[cfg(stage0)] -impl< - D: Decoder, - V: Decodable<D> -> Decodable<D> for TrieMap<V> { - fn decode(d: &D) -> TrieMap<V> { - do d.read_map |len| { - let mut map = TrieMap::new(); - for uint::range(0, len) |i| { - let key = d.read_map_elt_key(i, || Decodable::decode(d)); - let val = d.read_map_elt_val(i, || Decodable::decode(d)); - map.insert(key, val); - } - map - } - } -} - -#[cfg(not(stage0))] impl< D: Decoder, V: Decodable<D> @@ -1690,20 +782,6 @@ impl< } } -#[cfg(stage0)] -impl<S: Encoder> Encodable<S> for TrieSet { - fn encode(&self, s: &S) { - do s.emit_seq(self.len()) { - let mut i = 0; - for self.each |e| { - s.emit_seq_elt(i, || e.encode(s)); - i += 1; - } - } - } -} - -#[cfg(not(stage0))] impl<S: Encoder> Encodable<S> for TrieSet { fn encode(&self, s: &mut S) { do s.emit_seq(self.len()) |s| { @@ -1716,20 +794,6 @@ impl<S: Encoder> Encodable<S> for TrieSet { } } -#[cfg(stage0)] -impl<D: Decoder> Decodable<D> for TrieSet { - fn decode(d: &D) -> TrieSet { - do d.read_seq |len| { - let mut set = TrieSet::new(); - for uint::range(0, len) |i| { - set.insert(d.read_seq_elt(i, || Decodable::decode(d))); - } - set - } - } -} - -#[cfg(not(stage0))] impl<D: Decoder> Decodable<D> for TrieSet { fn decode(d: &mut D) -> TrieSet { do d.read_seq |d, len| { @@ -1742,7 +806,6 @@ impl<D: Decoder> Decodable<D> for TrieSet { } } -#[cfg(not(stage0))] impl< E: Encoder, K: Encodable<E> + Eq + TotalOrd, @@ -1760,7 +823,6 @@ impl< } } -#[cfg(not(stage0))] impl< D: Decoder, K: Decodable<D> + Eq + TotalOrd, @@ -1779,7 +841,6 @@ impl< } } -#[cfg(not(stage0))] impl< S: Encoder, T: Encodable<S> + Eq + TotalOrd @@ -1795,7 +856,6 @@ impl< } } -#[cfg(not(stage0))] impl< D: Decoder, T: Decodable<D> + Eq + TotalOrd @@ -1816,30 +876,10 @@ impl< // // In some cases, these should eventually be coded as traits. -#[cfg(stage0)] -pub trait EncoderHelpers { - fn emit_from_vec<T>(&self, v: &[T], f: &fn(v: &T)); -} - -#[cfg(not(stage0))] pub trait EncoderHelpers { fn emit_from_vec<T>(&mut self, v: &[T], f: &fn(&mut Self, v: &T)); } -#[cfg(stage0)] -impl<S:Encoder> EncoderHelpers for S { - fn emit_from_vec<T>(&self, v: &[T], f: &fn(v: &T)) { - do self.emit_seq(v.len()) { - for v.eachi |i, e| { - do self.emit_seq_elt(i) { - f(e) - } - } - } - } -} - -#[cfg(not(stage0))] impl<S:Encoder> EncoderHelpers for S { fn emit_from_vec<T>(&mut self, v: &[T], f: &fn(&mut S, &T)) { do self.emit_seq(v.len()) |this| { @@ -1852,28 +892,10 @@ impl<S:Encoder> EncoderHelpers for S { } } -#[cfg(stage0)] -pub trait DecoderHelpers { - fn read_to_vec<T>(&self, f: &fn() -> T) -> ~[T]; -} - -#[cfg(not(stage0))] pub trait DecoderHelpers { fn read_to_vec<T>(&mut self, f: &fn(&mut Self) -> T) -> ~[T]; } -#[cfg(stage0)] -impl<D:Decoder> DecoderHelpers for D { - fn read_to_vec<T>(&self, f: &fn() -> T) -> ~[T] { - do self.read_seq |len| { - do vec::from_fn(len) |i| { - self.read_seq_elt(i, || f()) - } - } - } -} - -#[cfg(not(stage0))] impl<D:Decoder> DecoderHelpers for D { fn read_to_vec<T>(&mut self, f: &fn(&mut D) -> T) -> ~[T] { do self.read_seq |this, len| { diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs index fb17d4e5090..1b72300a178 100644 --- a/src/libstd/smallintmap.rs +++ b/src/libstd/smallintmap.rs @@ -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") } diff --git a/src/libstd/std.rc b/src/libstd/std.rc index ea099090eba..4f9de29e726 100644 --- a/src/libstd/std.rc +++ b/src/libstd/std.rc @@ -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; diff --git a/src/libstd/workcache.rs b/src/libstd/workcache.rs index f44d143004e..e681382ffc8 100644 --- a/src/libstd/workcache.rs +++ b/src/libstd/workcache.rs @@ -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)); |
