From ab89b5c294ac511d4d58809f9f20dfe4f2c8fe52 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Sat, 13 Oct 2012 09:11:33 -0700 Subject: [PATCH] libstd: make Serializer a trait-level typaram --- src/libstd/json.rs | 28 ++ src/libstd/serialization.rs | 487 ++++++++++++++++++++++++++++ src/libsyntax/ast.rs | 49 +++ src/libsyntax/ext/auto_serialize.rs | 143 ++++---- src/test/run-pass/auto_serialize.rs | 62 ++-- 5 files changed, 692 insertions(+), 77 deletions(-) diff --git a/src/libstd/json.rs b/src/libstd/json.rs index 0d3391c1867c..d170255b565d 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -273,6 +273,7 @@ pub impl PrettySerializer: serialization::Serializer { } } +#[cfg(stage0)] pub impl Json: serialization::Serializable { fn serialize(&self, s: &S) { match *self { @@ -296,6 +297,33 @@ pub impl Json: serialization::Serializable { } } +#[cfg(stage1)] +#[cfg(stage2)] +pub impl< + S: serialization::Serializer +> Json: serialization::Serializable { + fn serialize(&self, s: &S) { + match *self { + Number(v) => v.serialize(s), + String(ref v) => v.serialize(s), + Boolean(v) => v.serialize(s), + List(v) => v.serialize(s), + Object(ref v) => { + do s.emit_rec || { + let mut idx = 0; + for v.each |key, value| { + do s.emit_field(*key, idx) { + value.serialize(s); + } + idx += 1; + } + } + }, + Null => s.emit_nil(), + } + } +} + /// Serializes a json value into a io::writer pub fn to_writer(wr: io::Writer, json: &Json) { json.serialize(&Serializer(wr)) diff --git a/src/libstd/serialization.rs b/src/libstd/serialization.rs index b7cf09cc6aa5..9df2a326a847 100644 --- a/src/libstd/serialization.rs +++ b/src/libstd/serialization.rs @@ -92,6 +92,8 @@ pub trait Deserializer { fn read_tup_elt(&self, idx: uint, f: fn() -> T) -> T; } +#[cfg(stage0)] +pub mod traits { pub trait Serializable { fn serialize(&self, s: &S); } @@ -561,3 +563,488 @@ pub impl D: DeserializerHelpers { } } } +} + +#[cfg(stage1)] +#[cfg(stage2)] +pub mod traits { +pub trait Serializable { + fn serialize(&self, s: &S); +} + +pub trait Deserializable { + static fn deserialize(&self, d: &D) -> self; +} + +pub impl uint: Serializable { + fn serialize(&self, s: &S) { s.emit_uint(*self) } +} + +pub impl uint: Deserializable { + static fn deserialize(&self, d: &D) -> uint { + d.read_uint() + } +} + +pub impl u8: Serializable { + fn serialize(&self, s: &S) { s.emit_u8(*self) } +} + +pub impl u8: Deserializable { + static fn deserialize(&self, d: &D) -> u8 { + d.read_u8() + } +} + +pub impl u16: Serializable { + fn serialize(&self, s: &S) { s.emit_u16(*self) } +} + +pub impl u16: Deserializable { + static fn deserialize(&self, d: &D) -> u16 { + d.read_u16() + } +} + +pub impl u32: Serializable { + fn serialize(&self, s: &S) { s.emit_u32(*self) } +} + +pub impl u32: Deserializable { + static fn deserialize(&self, d: &D) -> u32 { + d.read_u32() + } +} + +pub impl u64: Serializable { + fn serialize(&self, s: &S) { s.emit_u64(*self) } +} + +pub impl u64: Deserializable { + static fn deserialize(&self, d: &D) -> u64 { + d.read_u64() + } +} + +pub impl int: Serializable { + fn serialize(&self, s: &S) { s.emit_int(*self) } +} + +pub impl int: Deserializable { + static fn deserialize(&self, d: &D) -> int { + d.read_int() + } +} + +pub impl i8: Serializable { + fn serialize(&self, s: &S) { s.emit_i8(*self) } +} + +pub impl i8: Deserializable { + static fn deserialize(&self, d: &D) -> i8 { + d.read_i8() + } +} + +pub impl i16: Serializable { + fn serialize(&self, s: &S) { s.emit_i16(*self) } +} + +pub impl i16: Deserializable { + static fn deserialize(&self, d: &D) -> i16 { + d.read_i16() + } +} + +pub impl i32: Serializable { + fn serialize(&self, s: &S) { s.emit_i32(*self) } +} + +pub impl i32: Deserializable { + static fn deserialize(&self, d: &D) -> i32 { + d.read_i32() + } +} + +pub impl i64: Serializable { + fn serialize(&self, s: &S) { s.emit_i64(*self) } +} + +pub impl i64: Deserializable { + static fn deserialize(&self, d: &D) -> i64 { + d.read_i64() + } +} + +pub impl &str: Serializable { + fn serialize(&self, s: &S) { s.emit_borrowed_str(*self) } +} + +pub impl ~str: Serializable { + fn serialize(&self, s: &S) { s.emit_owned_str(*self) } +} + +pub impl ~str: Deserializable { + static fn deserialize(&self, d: &D) -> ~str { + d.read_owned_str() + } +} + +pub impl @str: Serializable { + fn serialize(&self, s: &S) { s.emit_managed_str(*self) } +} + +pub impl @str: Deserializable { + static fn deserialize(&self, d: &D) -> @str { + d.read_managed_str() + } +} + +pub impl float: Serializable { + fn serialize(&self, s: &S) { s.emit_float(*self) } +} + +pub impl float: Deserializable { + static fn deserialize(&self, d: &D) -> float { + d.read_float() + } +} + +pub impl f32: Serializable { + fn serialize(&self, s: &S) { s.emit_f32(*self) } +} + +pub impl f32: Deserializable { + static fn deserialize(&self, d: &D) -> f32 { + d.read_f32() } +} + +pub impl f64: Serializable { + fn serialize(&self, s: &S) { s.emit_f64(*self) } +} + +pub impl f64: Deserializable { + static fn deserialize(&self, d: &D) -> f64 { + d.read_f64() + } +} + +pub impl bool: Serializable { + fn serialize(&self, s: &S) { s.emit_bool(*self) } +} + +pub impl bool: Deserializable { + static fn deserialize(&self, d: &D) -> bool { + d.read_bool() + } +} + +pub impl (): Serializable { + fn serialize(&self, s: &S) { s.emit_nil() } +} + +pub impl (): Deserializable { + static fn deserialize(&self, d: &D) -> () { + d.read_nil() + } +} + +pub impl> &T: Serializable { + fn serialize(&self, s: &S) { + s.emit_borrowed(|| (**self).serialize(s)) + } +} + +pub impl> ~T: Serializable { + fn serialize(&self, s: &S) { + s.emit_owned(|| (**self).serialize(s)) + } +} + +pub impl> ~T: Deserializable { + static fn deserialize(&self, d: &D) -> ~T { + d.read_owned(|| ~deserialize(d)) + } +} + +pub impl> @T: Serializable { + fn serialize(&self, s: &S) { + s.emit_managed(|| (**self).serialize(s)) + } +} + +pub impl> @T: Deserializable { + static fn deserialize(&self, d: &D) -> @T { + d.read_managed(|| @deserialize(d)) + } +} + +pub impl> &[T]: Serializable { + fn serialize(&self, s: &S) { + do s.emit_borrowed_vec(self.len()) { + for self.eachi |i, e| { + s.emit_vec_elt(i, || e.serialize(s)) + } + } + } +} + +pub impl> ~[T]: Serializable { + fn serialize(&self, s: &S) { + do s.emit_owned_vec(self.len()) { + for self.eachi |i, e| { + s.emit_vec_elt(i, || e.serialize(s)) + } + } + } +} + +pub impl> ~[T]: Deserializable { + static fn deserialize(&self, d: &D) -> ~[T] { + do d.read_owned_vec |len| { + do vec::from_fn(len) |i| { + d.read_vec_elt(i, || deserialize(d)) + } + } + } +} + +pub impl> @[T]: Serializable { + fn serialize(&self, s: &S) { + do s.emit_managed_vec(self.len()) { + for self.eachi |i, e| { + s.emit_vec_elt(i, || e.serialize(s)) + } + } + } +} + +pub impl> @[T]: Deserializable { + static fn deserialize(&self, d: &D) -> @[T] { + do d.read_managed_vec |len| { + do at_vec::from_fn(len) |i| { + d.read_vec_elt(i, || deserialize(d)) + } + } + } +} + +pub impl> Option: Serializable { + fn serialize(&self, s: &S) { + do s.emit_enum(~"option") { + match *self { + None => do s.emit_enum_variant(~"none", 0u, 0u) { + }, + + Some(ref v) => do s.emit_enum_variant(~"some", 1u, 1u) { + s.emit_enum_variant_arg(0u, || v.serialize(s)) + } + } + } + } +} + +pub impl> Option: Deserializable { + static fn deserialize(&self, d: &D) -> Option { + do d.read_enum(~"option") { + do d.read_enum_variant |i| { + match i { + 0 => None, + 1 => Some(d.read_enum_variant_arg(0u, || deserialize(d))), + _ => fail(#fmt("Bad variant for option: %u", i)) + } + } + } + } +} + +pub impl< + S: Serializer, + T0: Serializable, + T1: Serializable +> (T0, T1): Serializable { + fn serialize(&self, s: &S) { + match *self { + (ref t0, ref t1) => { + do s.emit_tup(2) { + s.emit_tup_elt(0, || t0.serialize(s)); + s.emit_tup_elt(1, || t1.serialize(s)); + } + } + } + } +} + +pub impl< + D: Deserializer, + T0: Deserializable, + T1: Deserializable +> (T0, T1): Deserializable { + static fn deserialize(&self, d: &D) -> (T0, T1) { + do d.read_tup(2) { + ( + d.read_tup_elt(0, || deserialize(d)), + d.read_tup_elt(1, || deserialize(d)) + ) + } + } +} + +pub impl< + S: Serializer, + T0: Serializable, + T1: Serializable, + T2: Serializable +> (T0, T1, T2): Serializable { + fn serialize(&self, s: &S) { + match *self { + (ref t0, ref t1, ref t2) => { + do s.emit_tup(3) { + s.emit_tup_elt(0, || t0.serialize(s)); + s.emit_tup_elt(1, || t1.serialize(s)); + s.emit_tup_elt(2, || t2.serialize(s)); + } + } + } + } +} + +pub impl< + D: Deserializer, + T0: Deserializable, + T1: Deserializable, + T2: Deserializable +> (T0, T1, T2): Deserializable { + static fn deserialize(&self, d: &D) -> (T0, T1, T2) { + do d.read_tup(3) { + ( + d.read_tup_elt(0, || deserialize(d)), + d.read_tup_elt(1, || deserialize(d)), + d.read_tup_elt(2, || deserialize(d)) + ) + } + } +} + +pub impl< + S: Serializer, + T0: Serializable, + T1: Serializable, + T2: Serializable, + T3: Serializable +> (T0, T1, T2, T3): Serializable { + fn serialize(&self, s: &S) { + match *self { + (ref t0, ref t1, ref t2, ref t3) => { + do s.emit_tup(4) { + s.emit_tup_elt(0, || t0.serialize(s)); + s.emit_tup_elt(1, || t1.serialize(s)); + s.emit_tup_elt(2, || t2.serialize(s)); + s.emit_tup_elt(3, || t3.serialize(s)); + } + } + } + } +} + +pub impl< + D: Deserializer, + T0: Deserializable, + T1: Deserializable, + T2: Deserializable, + T3: Deserializable +> (T0, T1, T2, T3): Deserializable { + static fn deserialize(&self, d: &D) -> (T0, T1, T2, T3) { + do d.read_tup(4) { + ( + d.read_tup_elt(0, || deserialize(d)), + d.read_tup_elt(1, || deserialize(d)), + d.read_tup_elt(2, || deserialize(d)), + d.read_tup_elt(3, || deserialize(d)) + ) + } + } +} + +pub impl< + S: Serializer, + T0: Serializable, + T1: Serializable, + T2: Serializable, + T3: Serializable, + T4: Serializable +> (T0, T1, T2, T3, T4): Serializable { + fn serialize(&self, s: &S) { + match *self { + (ref t0, ref t1, ref t2, ref t3, ref t4) => { + do s.emit_tup(5) { + s.emit_tup_elt(0, || t0.serialize(s)); + s.emit_tup_elt(1, || t1.serialize(s)); + s.emit_tup_elt(2, || t2.serialize(s)); + s.emit_tup_elt(3, || t3.serialize(s)); + s.emit_tup_elt(4, || t4.serialize(s)); + } + } + } + } +} + +pub impl< + D: Deserializer, + T0: Deserializable, + T1: Deserializable, + T2: Deserializable, + T3: Deserializable, + T4: Deserializable +> (T0, T1, T2, T3, T4): Deserializable { + static fn deserialize(&self, d: &D) + -> (T0, T1, T2, T3, T4) { + do d.read_tup(5) { + ( + d.read_tup_elt(0, || deserialize(d)), + d.read_tup_elt(1, || deserialize(d)), + d.read_tup_elt(2, || deserialize(d)), + d.read_tup_elt(3, || deserialize(d)), + d.read_tup_elt(4, || deserialize(d)) + ) + } + } +} + +// ___________________________________________________________________________ +// Helper routines +// +// In some cases, these should eventually be coded as traits. + +pub trait SerializerHelpers { + fn emit_from_vec(&self, v: ~[T], f: fn(v: &T)); +} + +pub impl S: SerializerHelpers { + fn emit_from_vec(&self, v: ~[T], f: fn(v: &T)) { + do self.emit_owned_vec(v.len()) { + for v.eachi |i, e| { + do self.emit_vec_elt(i) { + f(e) + } + } + } + } +} + +pub trait DeserializerHelpers { + fn read_to_vec(&self, f: fn() -> T) -> ~[T]; +} + +pub impl D: DeserializerHelpers { + fn read_to_vec(&self, f: fn() -> T) -> ~[T] { + do self.read_owned_vec |len| { + do vec::from_fn(len) |i| { + self.read_vec_elt(i, || f()) + } + } + } +} +} + +pub use traits::*; diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 3740557b7f8f..cf7b758216b9 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -7,17 +7,34 @@ use std::serialization::{Serializable, use codemap::{span, filename}; use parse::token; +#[cfg(stage0)] impl span: Serializable { /* Note #1972 -- spans are serialized but not deserialized */ fn serialize(&self, _s: &S) { } } +#[cfg(stage0)] impl span: Deserializable { static fn deserialize(_d: &D) -> span { ast_util::dummy_sp() } } +#[cfg(stage1)] +#[cfg(stage2)] +impl span: Serializable { + /* Note #1972 -- spans are serialized but not deserialized */ + fn serialize(&self, _s: &S) { } +} + +#[cfg(stage1)] +#[cfg(stage2)] +impl span: Deserializable { + static fn deserialize(_d: &D) -> span { + ast_util::dummy_sp() + } +} + #[auto_serialize] #[auto_deserialize] type spanned = {node: T, span: span}; @@ -34,6 +51,7 @@ macro_rules! interner_key ( // implemented. struct ident { repr: uint } +#[cfg(stage0)] impl ident: Serializable { fn serialize(&self, s: &S) { let intr = match unsafe { @@ -47,6 +65,7 @@ impl ident: Serializable { } } +#[cfg(stage0)] impl ident: Deserializable { static fn deserialize(d: &D) -> ident { let intr = match unsafe { @@ -60,6 +79,36 @@ impl ident: Deserializable { } } +#[cfg(stage1)] +#[cfg(stage2)] +impl ident: Serializable { + fn serialize(&self, s: &S) { + let intr = match unsafe { + task::local_data::local_data_get(interner_key!()) + } { + None => fail ~"serialization: TLS interner not set up", + Some(intr) => intr + }; + + s.emit_owned_str(*(*intr).get(*self)); + } +} + +#[cfg(stage1)] +#[cfg(stage2)] +impl ident: Deserializable { + static fn deserialize(d: &D) -> ident { + let intr = match unsafe { + task::local_data::local_data_get(interner_key!()) + } { + None => fail ~"deserialization: TLS interner not set up", + Some(intr) => intr + }; + + (*intr).intern(@d.read_owned_str()) + } +} + impl ident: cmp::Eq { pure fn eq(other: &ident) -> bool { self.repr == other.repr } pure fn ne(other: &ident) -> bool { !self.eq(other) } diff --git a/src/libsyntax/ext/auto_serialize.rs b/src/libsyntax/ext/auto_serialize.rs index b06536f4e026..452becbe559a 100644 --- a/src/libsyntax/ext/auto_serialize.rs +++ b/src/libsyntax/ext/auto_serialize.rs @@ -13,16 +13,16 @@ For example, a type like: would generate two implementations like: - impl Node: Serializable { - fn serialize(s: &S) { + impl node_id: Serializable { + fn serialize(s: &S) { do s.emit_struct("Node") { s.emit_field("id", 0, || s.emit_uint(self)) } } } - impl node_id: Deserializable { - static fn deserialize(d: &D) -> Node { + impl node_id: Deserializable { + static fn deserialize(d: &D) -> Node { do d.read_struct("Node") { Node { id: d.read_field(~"x", 0, || deserialize(d)) @@ -40,7 +40,10 @@ references other non-built-in types. A type definition like: would yield functions like: - impl spanned: Serializable { + impl< + S: Serializer, + T: Serializable + > spanned: Serializable { fn serialize(s: &S) { do s.emit_rec { s.emit_field("node", 0, || self.node.serialize(s)); @@ -49,8 +52,11 @@ would yield functions like: } } - impl spanned: Deserializable { - static fn deserialize(d: &D) -> spanned { + impl< + D: Deserializer, + T: Deserializable + > spanned: Deserializable { + static fn deserialize(d: &D) -> spanned { do d.read_rec { { node: d.read_field(~"node", 0, || deserialize(d)), @@ -215,6 +221,25 @@ fn expand_auto_deserialize( } priv impl ext_ctxt { + fn bind_path( + span: span, + ident: ast::ident, + path: @ast::path, + bounds: @~[ast::ty_param_bound] + ) -> ast::ty_param { + let bound = ast::bound_trait(@{ + id: self.next_id(), + node: ast::ty_path(path, self.next_id()), + span: span, + }); + + { + ident: ident, + id: self.next_id(), + bounds: @vec::append(~[bound], *bounds) + } + } + fn expr(span: span, node: ast::expr_) -> @ast::expr { @{id: self.next_id(), callee_id: self.next_id(), node: node, span: span} @@ -332,24 +357,28 @@ fn mk_impl( cx: ext_ctxt, span: span, ident: ast::ident, + ty_param: ast::ty_param, path: @ast::path, tps: ~[ast::ty_param], f: fn(@ast::ty) -> @ast::method ) -> @ast::item { // All the type parameters need to bound to the trait. - let trait_tps = do tps.map |tp| { - let t_bound = ast::bound_trait(@{ - id: cx.next_id(), - node: ast::ty_path(path, cx.next_id()), - span: span, - }); + let mut trait_tps = vec::append( + ~[ty_param], + do tps.map |tp| { + let t_bound = ast::bound_trait(@{ + id: cx.next_id(), + node: ast::ty_path(path, cx.next_id()), + span: span, + }); - { - ident: tp.ident, - id: cx.next_id(), - bounds: @vec::append(~[t_bound], *tp.bounds) + { + ident: tp.ident, + id: cx.next_id(), + bounds: @vec::append(~[t_bound], *tp.bounds) + } } - }; + ); let opt_trait = Some(@{ path: path, @@ -382,20 +411,37 @@ fn mk_ser_impl( tps: ~[ast::ty_param], body: @ast::expr ) -> @ast::item { + // Make a path to the std::serialization::Serializable typaram. + let ty_param = cx.bind_path( + span, + cx.ident_of(~"__S"), + cx.path( + span, + ~[ + cx.ident_of(~"std"), + cx.ident_of(~"serialization"), + cx.ident_of(~"Serializer"), + ] + ), + @~[] + ); + // Make a path to the std::serialization::Serializable trait. - let path = cx.path( + let path = cx.path_tps( span, ~[ cx.ident_of(~"std"), cx.ident_of(~"serialization"), cx.ident_of(~"Serializable"), - ] + ], + ~[cx.ty_path(span, ~[cx.ident_of(~"__S")], ~[])] ); mk_impl( cx, span, ident, + ty_param, path, tps, |_ty| mk_ser_method(cx, span, cx.expr_blk(body)) @@ -409,20 +455,37 @@ fn mk_deser_impl( tps: ~[ast::ty_param], body: @ast::expr ) -> @ast::item { + // Make a path to the std::serialization::Deserializable typaram. + let ty_param = cx.bind_path( + span, + cx.ident_of(~"__D"), + cx.path( + span, + ~[ + cx.ident_of(~"std"), + cx.ident_of(~"serialization"), + cx.ident_of(~"Deserializer"), + ] + ), + @~[] + ); + // Make a path to the std::serialization::Deserializable trait. - let path = cx.path( + let path = cx.path_tps( span, ~[ cx.ident_of(~"std"), cx.ident_of(~"serialization"), cx.ident_of(~"Deserializable"), - ] + ], + ~[cx.ty_path(span, ~[cx.ident_of(~"__D")], ~[])] ); mk_impl( cx, span, ident, + ty_param, path, tps, |ty| mk_deser_method(cx, span, ty, cx.expr_blk(body)) @@ -434,22 +497,6 @@ fn mk_ser_method( span: span, ser_body: ast::blk ) -> @ast::method { - let ser_bound = cx.ty_path( - span, - ~[ - cx.ident_of(~"std"), - cx.ident_of(~"serialization"), - cx.ident_of(~"Serializer"), - ], - ~[] - ); - - let ser_tps = ~[{ - ident: cx.ident_of(~"__S"), - id: cx.next_id(), - bounds: @~[ast::bound_trait(ser_bound)], - }]; - let ty_s = @{ id: cx.next_id(), node: ast::ty_rptr( @@ -487,7 +534,7 @@ fn mk_ser_method( @{ ident: cx.ident_of(~"serialize"), attrs: ~[], - tps: ser_tps, + tps: ~[], self_ty: { node: ast::sty_region(ast::m_imm), span: span }, purity: ast::impure_fn, decl: ser_decl, @@ -505,22 +552,6 @@ fn mk_deser_method( ty: @ast::ty, deser_body: ast::blk ) -> @ast::method { - let deser_bound = cx.ty_path( - span, - ~[ - cx.ident_of(~"std"), - cx.ident_of(~"serialization"), - cx.ident_of(~"Deserializer"), - ], - ~[] - ); - - let deser_tps = ~[{ - ident: cx.ident_of(~"__D"), - id: cx.next_id(), - bounds: @~[ast::bound_trait(deser_bound)], - }]; - let ty_d = @{ id: cx.next_id(), node: ast::ty_rptr( @@ -552,7 +583,7 @@ fn mk_deser_method( @{ ident: cx.ident_of(~"deserialize"), attrs: ~[], - tps: deser_tps, + tps: ~[], self_ty: { node: ast::sty_static, span: span }, purity: ast::impure_fn, decl: deser_decl, diff --git a/src/test/run-pass/auto_serialize.rs b/src/test/run-pass/auto_serialize.rs index 6c85f59b74ed..b63d1dcab7ec 100644 --- a/src/test/run-pass/auto_serialize.rs +++ b/src/test/run-pass/auto_serialize.rs @@ -9,18 +9,22 @@ use io::Writer; use std::serialization::{Serializable, Deserializable, deserialize}; use std::prettyprint; -fn test_ser_and_deser( - a1: &A, - +expected: ~str +fn test_prettyprint>( + a: &A, + expected: &~str ) { - // check the pretty printer: let s = do io::with_str_writer |w| { - a1.serialize(&prettyprint::Serializer(w)) + a.serialize(&prettyprint::Serializer(w)) }; debug!("s == %?", s); - assert s == expected; + assert s == *expected; +} - // check the EBML serializer: +fn test_ebml + Deserializable +>(a1: &A) { let bytes = do io::with_bytes_writer |wr| { let ebml_w = &ebml::Serializer(wr); a1.serialize(ebml_w) @@ -140,24 +144,40 @@ enum Quark { enum CLike { A, B, C } fn main() { - test_ser_and_deser(&Plus(@Minus(@Val(3u), @Val(10u)), - @Plus(@Val(22u), @Val(5u))), - ~"Plus(@Minus(@Val(3u), @Val(10u)), \ - @Plus(@Val(22u), @Val(5u)))"); + let a = &Plus(@Minus(@Val(3u), @Val(10u)), @Plus(@Val(22u), @Val(5u))); + test_prettyprint(a, &~"Plus(@Minus(@Val(3u), @Val(10u)), \ + @Plus(@Val(22u), @Val(5u)))"); + test_ebml(a); - test_ser_and_deser(&{lo: 0u, hi: 5u, node: 22u}, - ~"{lo: 0u, hi: 5u, node: 22u}"); + let a = &{lo: 0u, hi: 5u, node: 22u}; + test_prettyprint(a, &~"{lo: 0u, hi: 5u, node: 22u}"); + test_ebml(a); - test_ser_and_deser(&AnEnum({v: ~[1u, 2u, 3u]}), - ~"AnEnum({v: ~[1u, 2u, 3u]})"); + let a = &AnEnum({v: ~[1u, 2u, 3u]}); + test_prettyprint(a, &~"AnEnum({v: ~[1u, 2u, 3u]})"); + test_ebml(a); - test_ser_and_deser(&Point {x: 3u, y: 5u}, ~"Point {x: 3u, y: 5u}"); + let a = &Point {x: 3u, y: 5u}; + test_prettyprint(a, &~"Point {x: 3u, y: 5u}"); + test_ebml(a); - test_ser_and_deser(&@[1u, 2u, 3u], ~"@[1u, 2u, 3u]"); + let a = &@[1u, 2u, 3u]; + test_prettyprint(a, &~"@[1u, 2u, 3u]"); + test_ebml(a); - test_ser_and_deser(&Top(22u), ~"Top(22u)"); - test_ser_and_deser(&Bottom(222u), ~"Bottom(222u)"); + let a = &Top(22u); + test_prettyprint(a, &~"Top(22u)"); + test_ebml(a); - test_ser_and_deser(&A, ~"A"); - test_ser_and_deser(&B, ~"B"); + let a = &Bottom(222u); + test_prettyprint(a, &~"Bottom(222u)"); + test_ebml(a); + + let a = &A; + test_prettyprint(a, &~"A"); + test_ebml(a); + + let a = &B; + test_prettyprint(a, &~"B"); + test_ebml(a); }