librustc: Update the serializer to work properly with INHTWAMA, removing mutable fields in the process
This commit is contained in:
parent
6f2e429041
commit
dc5df61bc1
20 changed files with 5290 additions and 504 deletions
|
@ -272,12 +272,21 @@ fn item_ty_param_defs(item: ebml::Doc, tcx: ty::ctxt, cdata: cmd,
|
||||||
@bounds
|
@bounds
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
fn item_ty_region_param(item: ebml::Doc) -> Option<ty::region_variance> {
|
fn item_ty_region_param(item: ebml::Doc) -> Option<ty::region_variance> {
|
||||||
reader::maybe_get_doc(item, tag_region_param).map(|doc| {
|
reader::maybe_get_doc(item, tag_region_param).map(|doc| {
|
||||||
Decodable::decode(&reader::Decoder(*doc))
|
Decodable::decode(&reader::Decoder(*doc))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
fn item_ty_region_param(item: ebml::Doc) -> Option<ty::region_variance> {
|
||||||
|
reader::maybe_get_doc(item, tag_region_param).map(|doc| {
|
||||||
|
let mut decoder = reader::Decoder(*doc);
|
||||||
|
Decodable::decode(&mut decoder)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn item_ty_param_count(item: ebml::Doc) -> uint {
|
fn item_ty_param_count(item: ebml::Doc) -> uint {
|
||||||
let mut n = 0u;
|
let mut n = 0u;
|
||||||
reader::tagged_docs(item, tag_items_data_item_ty_param_bounds,
|
reader::tagged_docs(item, tag_items_data_item_ty_param_bounds,
|
||||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -348,7 +348,7 @@ pub impl Arena {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_arena_destructors() {
|
fn test_arena_destructors() {
|
||||||
let arena = Arena();
|
let mut arena = Arena();
|
||||||
for uint::range(0, 10) |i| {
|
for uint::range(0, 10) |i| {
|
||||||
// Arena allocate something with drop glue to make sure it
|
// Arena allocate something with drop glue to make sure it
|
||||||
// doesn't leak.
|
// doesn't leak.
|
||||||
|
@ -363,7 +363,7 @@ fn test_arena_destructors() {
|
||||||
#[should_fail]
|
#[should_fail]
|
||||||
#[ignore(cfg(windows))]
|
#[ignore(cfg(windows))]
|
||||||
fn test_arena_destructors_fail() {
|
fn test_arena_destructors_fail() {
|
||||||
let arena = Arena();
|
let mut arena = Arena();
|
||||||
// Put some stuff in the arena.
|
// Put some stuff in the arena.
|
||||||
for uint::range(0, 10) |i| {
|
for uint::range(0, 10) |i| {
|
||||||
// Arena allocate something with drop glue to make sure it
|
// Arena allocate something with drop glue to make sure it
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -438,8 +438,11 @@ pub mod flatteners {
|
||||||
SerializingFlattener
|
SerializingFlattener
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
pub fn deserialize_buffer<D: Decoder + FromReader,
|
pub fn deserialize_buffer<D: Decoder + FromReader,
|
||||||
T: Decodable<D>>(buf: &[u8]) -> T {
|
T: Decodable<D>>(
|
||||||
|
buf: &[u8])
|
||||||
|
-> T {
|
||||||
let buf = vec::from_slice(buf);
|
let buf = vec::from_slice(buf);
|
||||||
let buf_reader = @BufReader::new(buf);
|
let buf_reader = @BufReader::new(buf);
|
||||||
let reader = buf_reader as @Reader;
|
let reader = buf_reader as @Reader;
|
||||||
|
@ -447,14 +450,40 @@ pub mod flatteners {
|
||||||
Decodable::decode(&deser)
|
Decodable::decode(&deser)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(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 mut deser: D = FromReader::from_reader(reader);
|
||||||
|
Decodable::decode(&mut deser)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
pub fn serialize_value<D: Encoder + FromWriter,
|
pub fn serialize_value<D: Encoder + FromWriter,
|
||||||
T: Encodable<D>>(val: &T) -> ~[u8] {
|
T: Encodable<D>>(
|
||||||
|
val: &T)
|
||||||
|
-> ~[u8] {
|
||||||
do io::with_bytes_writer |writer| {
|
do io::with_bytes_writer |writer| {
|
||||||
let ser = FromWriter::from_writer(writer);
|
let ser = FromWriter::from_writer(writer);
|
||||||
val.encode(&ser);
|
val.encode(&ser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
pub fn serialize_value<D: Encoder + FromWriter,
|
||||||
|
T: Encodable<D>>(
|
||||||
|
val: &T)
|
||||||
|
-> ~[u8] {
|
||||||
|
do io::with_bytes_writer |writer| {
|
||||||
|
let mut ser = FromWriter::from_writer(writer);
|
||||||
|
val.encode(&mut ser);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub trait FromReader {
|
pub trait FromReader {
|
||||||
fn from_reader(r: @Reader) -> Self;
|
fn from_reader(r: @Reader) -> Self;
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -140,6 +140,7 @@ impl WorkMap {
|
||||||
fn new() -> WorkMap { WorkMap(HashMap::new()) }
|
fn new() -> WorkMap { WorkMap(HashMap::new()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
impl<S:Encoder> Encodable<S> for WorkMap {
|
impl<S:Encoder> Encodable<S> for WorkMap {
|
||||||
fn encode(&self, s: &S) {
|
fn encode(&self, s: &S) {
|
||||||
let mut d = ~[];
|
let mut d = ~[];
|
||||||
|
@ -151,6 +152,19 @@ impl<S:Encoder> Encodable<S> for WorkMap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
impl<S:Encoder> Encodable<S> for WorkMap {
|
||||||
|
fn encode(&self, s: &mut S) {
|
||||||
|
let mut d = ~[];
|
||||||
|
for self.each |k, v| {
|
||||||
|
d.push((copy *k, copy *v))
|
||||||
|
}
|
||||||
|
sort::tim_sort(d);
|
||||||
|
d.encode(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
impl<D:Decoder> Decodable<D> for WorkMap {
|
impl<D:Decoder> Decodable<D> for WorkMap {
|
||||||
fn decode(d: &D) -> WorkMap {
|
fn decode(d: &D) -> WorkMap {
|
||||||
let v : ~[(WorkKey,~str)] = Decodable::decode(d);
|
let v : ~[(WorkKey,~str)] = Decodable::decode(d);
|
||||||
|
@ -162,6 +176,18 @@ impl<D:Decoder> Decodable<D> for WorkMap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
impl<D:Decoder> Decodable<D> for WorkMap {
|
||||||
|
fn decode(d: &mut 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct Database {
|
struct Database {
|
||||||
db_filename: Path,
|
db_filename: Path,
|
||||||
db_cache: HashMap<~str, ~str>,
|
db_cache: HashMap<~str, ~str>,
|
||||||
|
@ -171,8 +197,8 @@ struct Database {
|
||||||
pub impl Database {
|
pub impl Database {
|
||||||
fn prepare(&mut self,
|
fn prepare(&mut self,
|
||||||
fn_name: &str,
|
fn_name: &str,
|
||||||
declared_inputs: &WorkMap) -> Option<(WorkMap, WorkMap, ~str)>
|
declared_inputs: &WorkMap)
|
||||||
{
|
-> Option<(WorkMap, WorkMap, ~str)> {
|
||||||
let k = json_encode(&(fn_name, declared_inputs));
|
let k = json_encode(&(fn_name, declared_inputs));
|
||||||
match self.db_cache.find(&k) {
|
match self.db_cache.find(&k) {
|
||||||
None => None,
|
None => None,
|
||||||
|
@ -229,17 +255,38 @@ struct Work<T> {
|
||||||
res: Option<Either<T,PortOne<(Exec,T)>>>
|
res: Option<Either<T,PortOne<(Exec,T)>>>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
fn json_encode<T:Encodable<json::Encoder>>(t: &T) -> ~str {
|
fn json_encode<T:Encodable<json::Encoder>>(t: &T) -> ~str {
|
||||||
do io::with_str_writer |wr| {
|
do io::with_str_writer |wr| {
|
||||||
t.encode(&json::Encoder(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);
|
||||||
|
t.encode(&mut encoder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME(#5121)
|
// FIXME(#5121)
|
||||||
|
#[cfg(stage0)]
|
||||||
fn json_decode<T:Decodable<json::Decoder>>(s: &str) -> T {
|
fn json_decode<T:Decodable<json::Decoder>>(s: &str) -> T {
|
||||||
do io::with_str_reader(s) |rdr| {
|
do io::with_str_reader(s) |rdr| {
|
||||||
let j = result::unwrap(json::from_reader(rdr));
|
let j = result::unwrap(json::from_reader(rdr));
|
||||||
Decodable::decode(&json::Decoder(j))
|
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));
|
||||||
|
let mut decoder = json::Decoder(j);
|
||||||
|
Decodable::decode(&mut decoder)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,11 +70,12 @@ pub type Name = uint;
|
||||||
// with a macro expansion
|
// with a macro expansion
|
||||||
pub type Mrk = uint;
|
pub type Mrk = uint;
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
impl<S:Encoder> Encodable<S> for ident {
|
impl<S:Encoder> Encodable<S> for ident {
|
||||||
fn encode(&self, s: &S) {
|
fn encode(&self, s: &S) {
|
||||||
let intr = match unsafe {
|
unsafe {
|
||||||
task::local_data::local_data_get(interner_key!())
|
let intr =
|
||||||
} {
|
match task::local_data::local_data_get(interner_key!()) {
|
||||||
None => fail!(~"encode: TLS interner not set up"),
|
None => fail!(~"encode: TLS interner not set up"),
|
||||||
Some(intr) => intr
|
Some(intr) => intr
|
||||||
};
|
};
|
||||||
|
@ -82,7 +83,24 @@ impl<S:Encoder> Encodable<S> for ident {
|
||||||
s.emit_str(*(*intr).get(*self));
|
s.emit_str(*(*intr).get(*self));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
impl<S:Encoder> Encodable<S> for ident {
|
||||||
|
fn encode(&self, s: &mut S) {
|
||||||
|
unsafe {
|
||||||
|
let intr =
|
||||||
|
match task::local_data::local_data_get(interner_key!()) {
|
||||||
|
None => fail!(~"encode: TLS interner not set up"),
|
||||||
|
Some(intr) => intr
|
||||||
|
};
|
||||||
|
|
||||||
|
s.emit_str(*(*intr).get(*self));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
impl<D:Decoder> Decodable<D> for ident {
|
impl<D:Decoder> Decodable<D> for ident {
|
||||||
fn decode(d: &D) -> ident {
|
fn decode(d: &D) -> ident {
|
||||||
let intr = match unsafe {
|
let intr = match unsafe {
|
||||||
|
@ -96,6 +114,20 @@ impl<D:Decoder> Decodable<D> for ident {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
impl<D:Decoder> Decodable<D> for ident {
|
||||||
|
fn decode(d: &mut D) -> ident {
|
||||||
|
let intr = match unsafe {
|
||||||
|
task::local_data::local_data_get(interner_key!())
|
||||||
|
} {
|
||||||
|
None => fail!(~"decode: TLS interner not set up"),
|
||||||
|
Some(intr) => intr
|
||||||
|
};
|
||||||
|
|
||||||
|
(*intr).intern(@d.read_str())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl to_bytes::IterBytes for ident {
|
impl to_bytes::IterBytes for ident {
|
||||||
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
|
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
|
||||||
self.repr.iter_bytes(lsb0, f)
|
self.repr.iter_bytes(lsb0, f)
|
||||||
|
|
|
@ -125,17 +125,34 @@ impl cmp::Eq for span {
|
||||||
fn ne(&self, other: &span) -> bool { !(*self).eq(other) }
|
fn ne(&self, other: &span) -> bool { !(*self).eq(other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
impl<S:Encoder> Encodable<S> for span {
|
impl<S:Encoder> Encodable<S> for span {
|
||||||
/* Note #1972 -- spans are encoded but not decoded */
|
/* Note #1972 -- spans are encoded but not decoded */
|
||||||
fn encode(&self, _s: &S) { _s.emit_nil() }
|
fn encode(&self, _s: &S) { _s.emit_nil() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
impl<S:Encoder> Encodable<S> for span {
|
||||||
|
/* Note #1972 -- spans are encoded but not decoded */
|
||||||
|
fn encode(&self, s: &mut S) {
|
||||||
|
s.emit_nil()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
impl<D:Decoder> Decodable<D> for span {
|
impl<D:Decoder> Decodable<D> for span {
|
||||||
fn decode(_d: &D) -> span {
|
fn decode(_d: &D) -> span {
|
||||||
dummy_sp()
|
dummy_sp()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(stage0))]
|
||||||
|
impl<D:Decoder> Decodable<D> for span {
|
||||||
|
fn decode(_d: &mut D) -> span {
|
||||||
|
dummy_sp()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn spanned<T>(lo: BytePos, hi: BytePos, t: T) -> spanned<T> {
|
pub fn spanned<T>(lo: BytePos, hi: BytePos, t: T) -> spanned<T> {
|
||||||
respan(mk_sp(lo, hi), t)
|
respan(mk_sp(lo, hi), t)
|
||||||
}
|
}
|
||||||
|
|
|
@ -238,7 +238,8 @@ trait ExtCtxtMethods {
|
||||||
fn stmt(&self, expr: @ast::expr) -> @ast::stmt;
|
fn stmt(&self, expr: @ast::expr) -> @ast::stmt;
|
||||||
fn lit_str(&self, span: span, s: @~str) -> @ast::expr;
|
fn lit_str(&self, span: span, s: @~str) -> @ast::expr;
|
||||||
fn lit_uint(&self, span: span, i: uint) -> @ast::expr;
|
fn lit_uint(&self, span: span, i: uint) -> @ast::expr;
|
||||||
fn lambda(&self, blk: ast::blk) -> @ast::expr;
|
fn lambda0(&self, blk: ast::blk) -> @ast::expr;
|
||||||
|
fn lambda1(&self, blk: ast::blk, ident: ast::ident) -> @ast::expr;
|
||||||
fn blk(&self, span: span, stmts: ~[@ast::stmt]) -> ast::blk;
|
fn blk(&self, span: span, stmts: ~[@ast::stmt]) -> ast::blk;
|
||||||
fn expr_blk(&self, expr: @ast::expr) -> ast::blk;
|
fn expr_blk(&self, expr: @ast::expr) -> ast::blk;
|
||||||
fn expr_path(&self, span: span, strs: ~[ast::ident]) -> @ast::expr;
|
fn expr_path(&self, span: span, strs: ~[ast::ident]) -> @ast::expr;
|
||||||
|
@ -254,8 +255,15 @@ trait ExtCtxtMethods {
|
||||||
ident: ast::ident,
|
ident: ast::ident,
|
||||||
args: ~[@ast::expr])
|
args: ~[@ast::expr])
|
||||||
-> @ast::expr;
|
-> @ast::expr;
|
||||||
fn lambda_expr(&self, expr: @ast::expr) -> @ast::expr;
|
fn lambda_expr_0(&self, expr: @ast::expr) -> @ast::expr;
|
||||||
fn lambda_stmts(&self, span: span, stmts: ~[@ast::stmt]) -> @ast::expr;
|
fn lambda_expr_1(&self, expr: @ast::expr, ident: ast::ident)
|
||||||
|
-> @ast::expr;
|
||||||
|
fn lambda_stmts_0(&self, span: span, stmts: ~[@ast::stmt]) -> @ast::expr;
|
||||||
|
fn lambda_stmts_1(&self,
|
||||||
|
span: span,
|
||||||
|
stmts: ~[@ast::stmt],
|
||||||
|
ident: ast::ident)
|
||||||
|
-> @ast::expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExtCtxtMethods for @ext_ctxt {
|
impl ExtCtxtMethods for @ext_ctxt {
|
||||||
|
@ -388,12 +396,18 @@ impl ExtCtxtMethods for @ext_ctxt {
|
||||||
span: span}))
|
span: span}))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lambda(&self, blk: ast::blk) -> @ast::expr {
|
fn lambda0(&self, blk: ast::blk) -> @ast::expr {
|
||||||
let ext_cx = *self;
|
let ext_cx = *self;
|
||||||
let blk_e = self.expr(copy blk.span, ast::expr_block(copy blk));
|
let blk_e = self.expr(copy blk.span, ast::expr_block(copy blk));
|
||||||
quote_expr!( || $blk_e )
|
quote_expr!( || $blk_e )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn lambda1(&self, blk: ast::blk, ident: ast::ident) -> @ast::expr {
|
||||||
|
let ext_cx = *self;
|
||||||
|
let blk_e = self.expr(copy blk.span, ast::expr_block(copy blk));
|
||||||
|
quote_expr!( |$ident| $blk_e )
|
||||||
|
}
|
||||||
|
|
||||||
fn blk(&self, span: span, stmts: ~[@ast::stmt]) -> ast::blk {
|
fn blk(&self, span: span, stmts: ~[@ast::stmt]) -> ast::blk {
|
||||||
codemap::spanned {
|
codemap::spanned {
|
||||||
node: ast::blk_ {
|
node: ast::blk_ {
|
||||||
|
@ -461,15 +475,29 @@ impl ExtCtxtMethods for @ext_ctxt {
|
||||||
ident: ast::ident,
|
ident: ast::ident,
|
||||||
args: ~[@ast::expr]
|
args: ~[@ast::expr]
|
||||||
) -> @ast::expr {
|
) -> @ast::expr {
|
||||||
self.expr(span, ast::expr_method_call(expr, ident, ~[], args, ast::NoSugar))
|
self.expr(span,
|
||||||
|
ast::expr_method_call(expr, ident, ~[], args, ast::NoSugar))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lambda_expr(&self, expr: @ast::expr) -> @ast::expr {
|
fn lambda_expr_0(&self, expr: @ast::expr) -> @ast::expr {
|
||||||
self.lambda(self.expr_blk(expr))
|
self.lambda0(self.expr_blk(expr))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lambda_stmts(&self, span: span, stmts: ~[@ast::stmt]) -> @ast::expr {
|
fn lambda_expr_1(&self, expr: @ast::expr, ident: ast::ident)
|
||||||
self.lambda(self.blk(span, stmts))
|
-> @ast::expr {
|
||||||
|
self.lambda1(self.expr_blk(expr), ident)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn lambda_stmts_0(&self, span: span, stmts: ~[@ast::stmt]) -> @ast::expr {
|
||||||
|
self.lambda0(self.blk(span, stmts))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn lambda_stmts_1(&self,
|
||||||
|
span: span,
|
||||||
|
stmts: ~[@ast::stmt],
|
||||||
|
ident: ast::ident)
|
||||||
|
-> @ast::expr {
|
||||||
|
self.lambda1(self.blk(span, stmts), ident)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -644,7 +672,7 @@ fn mk_ser_method(
|
||||||
None,
|
None,
|
||||||
ast::mt {
|
ast::mt {
|
||||||
ty: cx.ty_path(span, ~[cx.ident_of(~"__S")], ~[]),
|
ty: cx.ty_path(span, ~[cx.ident_of(~"__S")], ~[]),
|
||||||
mutbl: ast::m_imm
|
mutbl: ast::m_mutbl
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
span: span,
|
span: span,
|
||||||
|
@ -706,7 +734,7 @@ fn mk_deser_method(
|
||||||
None,
|
None,
|
||||||
ast::mt {
|
ast::mt {
|
||||||
ty: cx.ty_path(span, ~[cx.ident_of(~"__D")], ~[]),
|
ty: cx.ty_path(span, ~[cx.ident_of(~"__D")], ~[]),
|
||||||
mutbl: ast::m_imm
|
mutbl: ast::m_mutbl
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
span: span,
|
span: span,
|
||||||
|
@ -758,8 +786,8 @@ fn mk_struct_ser_impl(
|
||||||
generics: &ast::Generics
|
generics: &ast::Generics
|
||||||
) -> @ast::item {
|
) -> @ast::item {
|
||||||
let fields = do mk_struct_fields(fields).mapi |idx, field| {
|
let fields = do mk_struct_fields(fields).mapi |idx, field| {
|
||||||
// ast for `|| self.$(name).encode(__s)`
|
// ast for `|__s| self.$(name).encode(__s)`
|
||||||
let expr_lambda = cx.lambda_expr(
|
let expr_lambda = cx.lambda_expr_1(
|
||||||
cx.expr_method_call(
|
cx.expr_method_call(
|
||||||
span,
|
span,
|
||||||
cx.expr_field(
|
cx.expr_field(
|
||||||
|
@ -769,7 +797,8 @@ fn mk_struct_ser_impl(
|
||||||
),
|
),
|
||||||
cx.ident_of(~"encode"),
|
cx.ident_of(~"encode"),
|
||||||
~[cx.expr_var(span, ~"__s")]
|
~[cx.expr_var(span, ~"__s")]
|
||||||
)
|
),
|
||||||
|
cx.ident_of(~"__s")
|
||||||
);
|
);
|
||||||
|
|
||||||
// ast for `__s.emit_struct_field($(name), $(idx), $(expr_lambda))`
|
// ast for `__s.emit_struct_field($(name), $(idx), $(expr_lambda))`
|
||||||
|
@ -787,7 +816,7 @@ fn mk_struct_ser_impl(
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
// ast for `__s.emit_struct($(name), || $(fields))`
|
// ast for `__s.emit_struct($(name), |__s| $(fields))`
|
||||||
let ser_body = cx.expr_method_call(
|
let ser_body = cx.expr_method_call(
|
||||||
span,
|
span,
|
||||||
cx.expr_var(span, ~"__s"),
|
cx.expr_var(span, ~"__s"),
|
||||||
|
@ -795,7 +824,7 @@ fn mk_struct_ser_impl(
|
||||||
~[
|
~[
|
||||||
cx.lit_str(span, @cx.str_of(ident)),
|
cx.lit_str(span, @cx.str_of(ident)),
|
||||||
cx.lit_uint(span, vec::len(fields)),
|
cx.lit_uint(span, vec::len(fields)),
|
||||||
cx.lambda_stmts(span, fields),
|
cx.lambda_stmts_1(span, fields, cx.ident_of(~"__s")),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -810,8 +839,8 @@ fn mk_struct_deser_impl(
|
||||||
generics: &ast::Generics
|
generics: &ast::Generics
|
||||||
) -> @ast::item {
|
) -> @ast::item {
|
||||||
let fields = do mk_struct_fields(fields).mapi |idx, field| {
|
let fields = do mk_struct_fields(fields).mapi |idx, field| {
|
||||||
// ast for `|| std::serialize::decode(__d)`
|
// ast for `|__d| std::serialize::decode(__d)`
|
||||||
let expr_lambda = cx.lambda(
|
let expr_lambda = cx.lambda1(
|
||||||
cx.expr_blk(
|
cx.expr_blk(
|
||||||
cx.expr_call(
|
cx.expr_call(
|
||||||
span,
|
span,
|
||||||
|
@ -823,7 +852,8 @@ fn mk_struct_deser_impl(
|
||||||
]),
|
]),
|
||||||
~[cx.expr_var(span, ~"__d")]
|
~[cx.expr_var(span, ~"__d")]
|
||||||
)
|
)
|
||||||
)
|
),
|
||||||
|
cx.ident_of(~"__d")
|
||||||
);
|
);
|
||||||
|
|
||||||
// ast for `__d.read_struct_field($(name), $(idx), $(expr_lambda))`
|
// ast for `__d.read_struct_field($(name), $(idx), $(expr_lambda))`
|
||||||
|
@ -848,7 +878,7 @@ fn mk_struct_deser_impl(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ast for `read_struct($(name), || $(fields))`
|
// ast for `read_struct($(name), |__d| $(fields))`
|
||||||
let body = cx.expr_method_call(
|
let body = cx.expr_method_call(
|
||||||
span,
|
span,
|
||||||
cx.expr_var(span, ~"__d"),
|
cx.expr_var(span, ~"__d"),
|
||||||
|
@ -856,7 +886,7 @@ fn mk_struct_deser_impl(
|
||||||
~[
|
~[
|
||||||
cx.lit_str(span, @cx.str_of(ident)),
|
cx.lit_str(span, @cx.str_of(ident)),
|
||||||
cx.lit_uint(span, vec::len(fields)),
|
cx.lit_uint(span, vec::len(fields)),
|
||||||
cx.lambda_expr(
|
cx.lambda_expr_1(
|
||||||
cx.expr(
|
cx.expr(
|
||||||
span,
|
span,
|
||||||
ast::expr_struct(
|
ast::expr_struct(
|
||||||
|
@ -864,7 +894,8 @@ fn mk_struct_deser_impl(
|
||||||
fields,
|
fields,
|
||||||
None
|
None
|
||||||
)
|
)
|
||||||
)
|
),
|
||||||
|
cx.ident_of(~"__d")
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
@ -974,14 +1005,15 @@ fn ser_variant(
|
||||||
cx.ident_of(~"emit_enum_variant_arg")
|
cx.ident_of(~"emit_enum_variant_arg")
|
||||||
);
|
);
|
||||||
|
|
||||||
// ast for `|| $(v).encode(__s)`
|
// ast for `|__s| $(v).encode(__s)`
|
||||||
let expr_encode = cx.lambda_expr(
|
let expr_encode = cx.lambda_expr_1(
|
||||||
cx.expr_method_call(
|
cx.expr_method_call(
|
||||||
span,
|
span,
|
||||||
cx.expr_path(span, ~[names[a_idx]]),
|
cx.expr_path(span, ~[names[a_idx]]),
|
||||||
cx.ident_of(~"encode"),
|
cx.ident_of(~"encode"),
|
||||||
~[cx.expr_var(span, ~"__s")]
|
~[cx.expr_var(span, ~"__s")]
|
||||||
)
|
),
|
||||||
|
cx.ident_of(~"__s")
|
||||||
);
|
);
|
||||||
|
|
||||||
// ast for `$(expr_emit)($(a_idx), $(expr_encode))`
|
// ast for `$(expr_emit)($(a_idx), $(expr_encode))`
|
||||||
|
@ -1003,7 +1035,7 @@ fn ser_variant(
|
||||||
cx.lit_str(span, @cx.str_of(v_name)),
|
cx.lit_str(span, @cx.str_of(v_name)),
|
||||||
cx.lit_uint(span, v_idx),
|
cx.lit_uint(span, v_idx),
|
||||||
cx.lit_uint(span, stmts.len()),
|
cx.lit_uint(span, stmts.len()),
|
||||||
cx.lambda_stmts(span, stmts),
|
cx.lambda_stmts_1(span, stmts, cx.ident_of(~"__s")),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1050,7 +1082,7 @@ fn mk_enum_ser_body(
|
||||||
cx.ident_of(~"emit_enum"),
|
cx.ident_of(~"emit_enum"),
|
||||||
~[
|
~[
|
||||||
cx.lit_str(span, @cx.str_of(name)),
|
cx.lit_str(span, @cx.str_of(name)),
|
||||||
cx.lambda_expr(match_expr),
|
cx.lambda_expr_1(match_expr, cx.ident_of(~"__s")),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1062,8 +1094,8 @@ fn mk_enum_deser_variant_nary(
|
||||||
args: ~[ast::variant_arg]
|
args: ~[ast::variant_arg]
|
||||||
) -> @ast::expr {
|
) -> @ast::expr {
|
||||||
let args = do args.mapi |idx, _arg| {
|
let args = do args.mapi |idx, _arg| {
|
||||||
// ast for `|| std::serialize::decode(__d)`
|
// ast for `|__s| std::serialize::decode(__d)`
|
||||||
let expr_lambda = cx.lambda_expr(
|
let expr_lambda = cx.lambda_expr_1(
|
||||||
cx.expr_call(
|
cx.expr_call(
|
||||||
span,
|
span,
|
||||||
cx.expr_path_global(span, ~[
|
cx.expr_path_global(span, ~[
|
||||||
|
@ -1073,7 +1105,8 @@ fn mk_enum_deser_variant_nary(
|
||||||
cx.ident_of(~"decode"),
|
cx.ident_of(~"decode"),
|
||||||
]),
|
]),
|
||||||
~[cx.expr_var(span, ~"__d")]
|
~[cx.expr_var(span, ~"__d")]
|
||||||
)
|
),
|
||||||
|
cx.ident_of(~"__d")
|
||||||
);
|
);
|
||||||
|
|
||||||
// ast for `__d.read_enum_variant_arg($(a_idx), $(expr_lambda))`
|
// ast for `__d.read_enum_variant_arg($(a_idx), $(expr_lambda))`
|
||||||
|
@ -1163,7 +1196,26 @@ fn mk_enum_deser_body(
|
||||||
span,
|
span,
|
||||||
ast::expr_fn_block(
|
ast::expr_fn_block(
|
||||||
ast::fn_decl {
|
ast::fn_decl {
|
||||||
inputs: ~[ast::arg {
|
inputs: ~[
|
||||||
|
ast::arg {
|
||||||
|
is_mutbl: false,
|
||||||
|
ty: @ast::Ty {
|
||||||
|
id: ext_cx.next_id(),
|
||||||
|
node: ast::ty_infer,
|
||||||
|
span: span
|
||||||
|
},
|
||||||
|
pat: @ast::pat {
|
||||||
|
id: ext_cx.next_id(),
|
||||||
|
node: ast::pat_ident(
|
||||||
|
ast::bind_by_copy,
|
||||||
|
ast_util::ident_to_path(span,
|
||||||
|
ext_cx.ident_of(~"__d")),
|
||||||
|
None),
|
||||||
|
span: span,
|
||||||
|
},
|
||||||
|
id: ext_cx.next_id(),
|
||||||
|
},
|
||||||
|
ast::arg {
|
||||||
is_mutbl: false,
|
is_mutbl: false,
|
||||||
ty: @ast::Ty {
|
ty: @ast::Ty {
|
||||||
id: ext_cx.next_id(),
|
id: ext_cx.next_id(),
|
||||||
|
@ -1180,7 +1232,8 @@ fn mk_enum_deser_body(
|
||||||
span: span,
|
span: span,
|
||||||
},
|
},
|
||||||
id: ext_cx.next_id(),
|
id: ext_cx.next_id(),
|
||||||
}],
|
}
|
||||||
|
],
|
||||||
output: @ast::Ty {
|
output: @ast::Ty {
|
||||||
id: ext_cx.next_id(),
|
id: ext_cx.next_id(),
|
||||||
node: ast::ty_infer,
|
node: ast::ty_infer,
|
||||||
|
@ -1198,13 +1251,14 @@ fn mk_enum_deser_body(
|
||||||
);
|
);
|
||||||
|
|
||||||
// ast for `__d.read_enum_variant($expr_arm_names, $(expr_lambda))`
|
// ast for `__d.read_enum_variant($expr_arm_names, $(expr_lambda))`
|
||||||
let expr_lambda = ext_cx.lambda_expr(
|
let expr_lambda = ext_cx.lambda_expr_1(
|
||||||
ext_cx.expr_method_call(
|
ext_cx.expr_method_call(
|
||||||
span,
|
span,
|
||||||
ext_cx.expr_var(span, ~"__d"),
|
ext_cx.expr_var(span, ~"__d"),
|
||||||
ext_cx.ident_of(~"read_enum_variant"),
|
ext_cx.ident_of(~"read_enum_variant"),
|
||||||
~[expr_arm_names, expr_lambda]
|
~[expr_arm_names, expr_lambda]
|
||||||
)
|
),
|
||||||
|
ext_cx.ident_of(~"__d")
|
||||||
);
|
);
|
||||||
|
|
||||||
// ast for `__d.read_enum($(e_name), $(expr_lambda))`
|
// ast for `__d.read_enum($(e_name), $(expr_lambda))`
|
||||||
|
@ -1256,105 +1310,147 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Encoder for TestEncoder {
|
impl Encoder for TestEncoder {
|
||||||
fn emit_nil(&self) { self.add_to_log(CallToEmitNil) }
|
fn emit_nil(&mut self) { self.add_to_log(CallToEmitNil) }
|
||||||
|
|
||||||
fn emit_uint(&self, v: uint) {self.add_to_log(CallToEmitUint(v)); }
|
fn emit_uint(&mut self, v: uint) {
|
||||||
fn emit_u64(&self, _v: u64) { self.add_unknown_to_log(); }
|
self.add_to_log(CallToEmitUint(v));
|
||||||
fn emit_u32(&self, _v: u32) { self.add_unknown_to_log(); }
|
}
|
||||||
fn emit_u16(&self, _v: u16) { self.add_unknown_to_log(); }
|
fn emit_u64(&mut self, _v: u64) { self.add_unknown_to_log(); }
|
||||||
fn emit_u8(&self, _v: u8) { self.add_unknown_to_log(); }
|
fn emit_u32(&mut self, _v: u32) { self.add_unknown_to_log(); }
|
||||||
|
fn emit_u16(&mut self, _v: u16) { self.add_unknown_to_log(); }
|
||||||
|
fn emit_u8(&mut self, _v: u8) { self.add_unknown_to_log(); }
|
||||||
|
|
||||||
fn emit_int(&self, _v: int) { self.add_unknown_to_log(); }
|
fn emit_int(&mut self, _v: int) { self.add_unknown_to_log(); }
|
||||||
fn emit_i64(&self, _v: i64) { self.add_unknown_to_log(); }
|
fn emit_i64(&mut self, _v: i64) { self.add_unknown_to_log(); }
|
||||||
fn emit_i32(&self, _v: i32) { self.add_unknown_to_log(); }
|
fn emit_i32(&mut self, _v: i32) { self.add_unknown_to_log(); }
|
||||||
fn emit_i16(&self, _v: i16) { self.add_unknown_to_log(); }
|
fn emit_i16(&mut self, _v: i16) { self.add_unknown_to_log(); }
|
||||||
fn emit_i8(&self, _v: i8) { self.add_unknown_to_log(); }
|
fn emit_i8(&mut self, _v: i8) { self.add_unknown_to_log(); }
|
||||||
|
|
||||||
fn emit_bool(&self, _v: bool) { self.add_unknown_to_log(); }
|
fn emit_bool(&mut self, _v: bool) { self.add_unknown_to_log(); }
|
||||||
|
|
||||||
fn emit_f64(&self, _v: f64) { self.add_unknown_to_log(); }
|
fn emit_f64(&mut self, _v: f64) { self.add_unknown_to_log(); }
|
||||||
fn emit_f32(&self, _v: f32) { self.add_unknown_to_log(); }
|
fn emit_f32(&mut self, _v: f32) { self.add_unknown_to_log(); }
|
||||||
fn emit_float(&self, _v: float) { self.add_unknown_to_log(); }
|
fn emit_float(&mut self, _v: float) { self.add_unknown_to_log(); }
|
||||||
|
|
||||||
fn emit_char(&self, _v: char) { self.add_unknown_to_log(); }
|
fn emit_char(&mut self, _v: char) { self.add_unknown_to_log(); }
|
||||||
fn emit_str(&self, _v: &str) { self.add_unknown_to_log(); }
|
fn emit_str(&mut self, _v: &str) { self.add_unknown_to_log(); }
|
||||||
|
|
||||||
fn emit_enum(&self, name: &str, f: &fn()) {
|
fn emit_enum(&mut self, name: &str, f: &fn(&mut TestEncoder)) {
|
||||||
self.add_to_log(CallToEmitEnum(name.to_str())); f(); }
|
self.add_to_log(CallToEmitEnum(name.to_str()));
|
||||||
|
f(self);
|
||||||
|
}
|
||||||
|
|
||||||
fn emit_enum_variant(&self, name: &str, id: uint,
|
fn emit_enum_variant(&mut self,
|
||||||
cnt: uint, f: &fn()) {
|
name: &str,
|
||||||
|
id: uint,
|
||||||
|
cnt: uint,
|
||||||
|
f: &fn(&mut TestEncoder)) {
|
||||||
self.add_to_log(CallToEmitEnumVariant(name.to_str(), id, cnt));
|
self.add_to_log(CallToEmitEnumVariant(name.to_str(), id, cnt));
|
||||||
f();
|
f(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit_enum_variant_arg(&self, idx: uint, f: &fn()) {
|
fn emit_enum_variant_arg(&mut self,
|
||||||
self.add_to_log(CallToEmitEnumVariantArg (idx)); f();
|
idx: uint,
|
||||||
|
f: &fn(&mut TestEncoder)) {
|
||||||
|
self.add_to_log(CallToEmitEnumVariantArg(idx));
|
||||||
|
f(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit_enum_struct_variant(&self, name: &str, id: uint, cnt: uint, f: &fn()) {
|
fn emit_enum_struct_variant(&mut self,
|
||||||
|
name: &str,
|
||||||
|
id: uint,
|
||||||
|
cnt: uint,
|
||||||
|
f: &fn(&mut TestEncoder)) {
|
||||||
self.emit_enum_variant(name, id, cnt, f)
|
self.emit_enum_variant(name, id, cnt, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit_enum_struct_variant_field(&self, _name: &str, idx: uint, f: &fn()) {
|
fn emit_enum_struct_variant_field(&mut self,
|
||||||
|
_name: &str,
|
||||||
|
idx: uint,
|
||||||
|
f: &fn(&mut TestEncoder)) {
|
||||||
self.emit_enum_variant_arg(idx, f)
|
self.emit_enum_variant_arg(idx, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit_struct(&self, name: &str, len: uint, f: &fn()) {
|
fn emit_struct(&mut self,
|
||||||
self.add_to_log(CallToEmitStruct (name.to_str(),len)); f();
|
name: &str,
|
||||||
|
len: uint,
|
||||||
|
f: &fn(&mut TestEncoder)) {
|
||||||
|
self.add_to_log(CallToEmitStruct (name.to_str(),len));
|
||||||
|
f(self);
|
||||||
}
|
}
|
||||||
fn emit_struct_field(&self, name: &str, idx: uint, f: &fn()) {
|
fn emit_struct_field(&mut self,
|
||||||
self.add_to_log(CallToEmitField (name.to_str(),idx)); f();
|
name: &str,
|
||||||
|
idx: uint,
|
||||||
|
f: &fn(&mut TestEncoder)) {
|
||||||
|
self.add_to_log(CallToEmitField (name.to_str(),idx));
|
||||||
|
f(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit_tuple(&self, _len: uint, f: &fn()) {
|
fn emit_tuple(&mut self, _len: uint, f: &fn(&mut TestEncoder)) {
|
||||||
self.add_unknown_to_log(); f();
|
self.add_unknown_to_log();
|
||||||
|
f(self);
|
||||||
}
|
}
|
||||||
fn emit_tuple_arg(&self, _idx: uint, f: &fn()) {
|
fn emit_tuple_arg(&mut self, _idx: uint, f: &fn(&mut TestEncoder)) {
|
||||||
self.add_unknown_to_log(); f();
|
self.add_unknown_to_log();
|
||||||
|
f(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit_tuple_struct(&self, _name: &str, _len: uint, f: &fn()) {
|
fn emit_tuple_struct(&mut self,
|
||||||
self.add_unknown_to_log(); f();
|
_name: &str,
|
||||||
}
|
_len: uint,
|
||||||
fn emit_tuple_struct_arg(&self, _idx: uint, f: &fn()) {
|
f: &fn(&mut TestEncoder)) {
|
||||||
self.add_unknown_to_log(); f();
|
self.add_unknown_to_log();
|
||||||
|
f(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit_option(&self, f: &fn()) {
|
fn emit_tuple_struct_arg(&mut self,
|
||||||
|
_idx: uint,
|
||||||
|
f: &fn(&mut TestEncoder)) {
|
||||||
|
self.add_unknown_to_log();
|
||||||
|
f(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn emit_option(&mut self, f: &fn(&mut TestEncoder)) {
|
||||||
self.add_to_log(CallToEmitOption);
|
self.add_to_log(CallToEmitOption);
|
||||||
f();
|
f(self);
|
||||||
}
|
}
|
||||||
fn emit_option_none(&self) {
|
fn emit_option_none(&mut self) {
|
||||||
self.add_to_log(CallToEmitOptionNone);
|
self.add_to_log(CallToEmitOptionNone);
|
||||||
}
|
}
|
||||||
fn emit_option_some(&self, f: &fn()) {
|
fn emit_option_some(&mut self, f: &fn(&mut TestEncoder)) {
|
||||||
self.add_to_log(CallToEmitOptionSome);
|
self.add_to_log(CallToEmitOptionSome);
|
||||||
f();
|
f(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit_seq(&self, _len: uint, f: &fn()) {
|
fn emit_seq(&mut self, _len: uint, f: &fn(&mut TestEncoder)) {
|
||||||
self.add_unknown_to_log(); f();
|
self.add_unknown_to_log();
|
||||||
|
f(self);
|
||||||
}
|
}
|
||||||
fn emit_seq_elt(&self, _idx: uint, f: &fn()) {
|
fn emit_seq_elt(&mut self, _idx: uint, f: &fn(&mut TestEncoder)) {
|
||||||
self.add_unknown_to_log(); f();
|
self.add_unknown_to_log();
|
||||||
|
f(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit_map(&self, _len: uint, f: &fn()) {
|
fn emit_map(&mut self, _len: uint, f: &fn(&mut TestEncoder)) {
|
||||||
self.add_unknown_to_log(); f();
|
self.add_unknown_to_log();
|
||||||
|
f(self);
|
||||||
}
|
}
|
||||||
fn emit_map_elt_key(&self, _idx: uint, f: &fn()) {
|
fn emit_map_elt_key(&mut self, _idx: uint, f: &fn(&mut TestEncoder)) {
|
||||||
self.add_unknown_to_log(); f();
|
self.add_unknown_to_log();
|
||||||
|
f(self);
|
||||||
}
|
}
|
||||||
fn emit_map_elt_val(&self, _idx: uint, f: &fn()) {
|
fn emit_map_elt_val(&mut self, _idx: uint, f: &fn(&mut TestEncoder)) {
|
||||||
self.add_unknown_to_log(); f();
|
self.add_unknown_to_log();
|
||||||
|
f(self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn to_call_log<E:Encodable<TestEncoder>>(val: E) -> ~[call] {
|
fn to_call_log<E:Encodable<TestEncoder>>(val: E) -> ~[call] {
|
||||||
let mut te = TestEncoder {call_log: @mut ~[]};
|
let mut te = TestEncoder {
|
||||||
val.encode(&te);
|
call_log: @mut ~[]
|
||||||
|
};
|
||||||
|
val.encode(&mut te);
|
||||||
copy *te.call_log
|
copy *te.call_log
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ fn create_decode_method(
|
||||||
cx,
|
cx,
|
||||||
span,
|
span,
|
||||||
build::mk_simple_ty_path(cx, span, cx.ident_of(~"__D")),
|
build::mk_simple_ty_path(cx, span, cx.ident_of(~"__D")),
|
||||||
ast::m_imm
|
ast::m_mutbl
|
||||||
);
|
);
|
||||||
let d_ident = cx.ident_of(~"__d");
|
let d_ident = cx.ident_of(~"__d");
|
||||||
let d_arg = build::mk_arg(cx, span, d_ident, d_arg_type);
|
let d_arg = build::mk_arg(cx, span, d_ident, d_arg_type);
|
||||||
|
@ -219,6 +219,11 @@ fn create_read_struct_field(
|
||||||
// Call the substructure method.
|
// Call the substructure method.
|
||||||
let decode_expr = call_substructure_decode_method(cx, span);
|
let decode_expr = call_substructure_decode_method(cx, span);
|
||||||
|
|
||||||
|
let d_arg = build::mk_arg(cx,
|
||||||
|
span,
|
||||||
|
cx.ident_of(~"__d"),
|
||||||
|
build::mk_ty_infer(cx, span));
|
||||||
|
|
||||||
let call_expr = build::mk_method_call(
|
let call_expr = build::mk_method_call(
|
||||||
cx,
|
cx,
|
||||||
span,
|
span,
|
||||||
|
@ -227,7 +232,11 @@ fn create_read_struct_field(
|
||||||
~[
|
~[
|
||||||
build::mk_base_str(cx, span, cx.str_of(ident)),
|
build::mk_base_str(cx, span, cx.str_of(ident)),
|
||||||
build::mk_uint(cx, span, idx),
|
build::mk_uint(cx, span, idx),
|
||||||
build::mk_lambda_no_args(cx, span, decode_expr),
|
build::mk_lambda(cx,
|
||||||
|
span,
|
||||||
|
build::mk_fn_decl(~[d_arg],
|
||||||
|
build::mk_ty_infer(cx, span)),
|
||||||
|
decode_expr),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -282,6 +291,11 @@ fn expand_deriving_decodable_struct_method(
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let d_arg = build::mk_arg(cx,
|
||||||
|
span,
|
||||||
|
cx.ident_of(~"__d"),
|
||||||
|
build::mk_ty_infer(cx, span));
|
||||||
|
|
||||||
let read_struct_expr = build::mk_method_call(
|
let read_struct_expr = build::mk_method_call(
|
||||||
cx,
|
cx,
|
||||||
span,
|
span,
|
||||||
|
@ -294,9 +308,10 @@ fn expand_deriving_decodable_struct_method(
|
||||||
~[
|
~[
|
||||||
build::mk_base_str(cx, span, cx.str_of(type_ident)),
|
build::mk_base_str(cx, span, cx.str_of(type_ident)),
|
||||||
build::mk_uint(cx, span, fields.len()),
|
build::mk_uint(cx, span, fields.len()),
|
||||||
build::mk_lambda_no_args(
|
build::mk_lambda(
|
||||||
cx,
|
cx,
|
||||||
span,
|
span,
|
||||||
|
build::mk_fn_decl(~[d_arg], build::mk_ty_infer(cx, span)),
|
||||||
build::mk_struct_e(
|
build::mk_struct_e(
|
||||||
cx,
|
cx,
|
||||||
span,
|
span,
|
||||||
|
@ -334,6 +349,12 @@ fn create_read_variant_arg(
|
||||||
// Call the substructure method.
|
// Call the substructure method.
|
||||||
let expr = call_substructure_decode_method(cx, span);
|
let expr = call_substructure_decode_method(cx, span);
|
||||||
|
|
||||||
|
let d_arg = build::mk_arg(cx,
|
||||||
|
span,
|
||||||
|
cx.ident_of(~"__d"),
|
||||||
|
build::mk_ty_infer(cx, span));
|
||||||
|
let t_infer = build::mk_ty_infer(cx, span);
|
||||||
|
|
||||||
let call_expr = build::mk_method_call(
|
let call_expr = build::mk_method_call(
|
||||||
cx,
|
cx,
|
||||||
span,
|
span,
|
||||||
|
@ -341,7 +362,10 @@ fn create_read_variant_arg(
|
||||||
cx.ident_of(~"read_enum_variant_arg"),
|
cx.ident_of(~"read_enum_variant_arg"),
|
||||||
~[
|
~[
|
||||||
build::mk_uint(cx, span, j),
|
build::mk_uint(cx, span, j),
|
||||||
build::mk_lambda_no_args(cx, span, expr),
|
build::mk_lambda(cx,
|
||||||
|
span,
|
||||||
|
build::mk_fn_decl(~[d_arg], t_infer),
|
||||||
|
expr),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -399,6 +423,12 @@ fn create_read_enum_variant(
|
||||||
span,
|
span,
|
||||||
build::mk_fn_decl(
|
build::mk_fn_decl(
|
||||||
~[
|
~[
|
||||||
|
build::mk_arg(
|
||||||
|
cx,
|
||||||
|
span,
|
||||||
|
cx.ident_of(~"__d"),
|
||||||
|
build::mk_ty_infer(cx, span)
|
||||||
|
),
|
||||||
build::mk_arg(
|
build::mk_arg(
|
||||||
cx,
|
cx,
|
||||||
span,
|
span,
|
||||||
|
@ -434,6 +464,11 @@ fn expand_deriving_decodable_enum_method(
|
||||||
enum_definition
|
enum_definition
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let d_arg = build::mk_arg(cx,
|
||||||
|
span,
|
||||||
|
cx.ident_of(~"__d"),
|
||||||
|
build::mk_ty_infer(cx, span));
|
||||||
|
|
||||||
// Create the read_enum expression
|
// Create the read_enum expression
|
||||||
let read_enum_expr = build::mk_method_call(
|
let read_enum_expr = build::mk_method_call(
|
||||||
cx,
|
cx,
|
||||||
|
@ -442,7 +477,11 @@ fn expand_deriving_decodable_enum_method(
|
||||||
cx.ident_of(~"read_enum"),
|
cx.ident_of(~"read_enum"),
|
||||||
~[
|
~[
|
||||||
build::mk_base_str(cx, span, cx.str_of(type_ident)),
|
build::mk_base_str(cx, span, cx.str_of(type_ident)),
|
||||||
build::mk_lambda_no_args(cx, span, read_enum_variant_expr),
|
build::mk_lambda(cx,
|
||||||
|
span,
|
||||||
|
build::mk_fn_decl(~[d_arg],
|
||||||
|
build::mk_ty_infer(cx, span)),
|
||||||
|
read_enum_variant_expr),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -94,10 +94,9 @@ fn create_encode_method(
|
||||||
cx,
|
cx,
|
||||||
span,
|
span,
|
||||||
build::mk_simple_ty_path(cx, span, cx.ident_of(~"__E")),
|
build::mk_simple_ty_path(cx, span, cx.ident_of(~"__E")),
|
||||||
ast::m_imm
|
ast::m_mutbl
|
||||||
);
|
);
|
||||||
let e_ident = cx.ident_of(~"__e");
|
let e_arg = build::mk_arg(cx, span, cx.ident_of(~"__e"), e_arg_type);
|
||||||
let e_arg = build::mk_arg(cx, span, e_ident, e_arg_type);
|
|
||||||
|
|
||||||
// Create the type of the return value.
|
// Create the type of the return value.
|
||||||
let output_type = @ast::Ty { id: cx.next_id(), node: ty_nil, span: span };
|
let output_type = @ast::Ty { id: cx.next_id(), node: ty_nil, span: span };
|
||||||
|
@ -226,10 +225,16 @@ fn expand_deriving_encodable_struct_method(
|
||||||
self_field
|
self_field
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let e_ident = cx.ident_of(~"__e");
|
||||||
|
let e_arg = build::mk_arg(cx,
|
||||||
|
span,
|
||||||
|
e_ident,
|
||||||
|
build::mk_ty_infer(cx, span));
|
||||||
|
|
||||||
let blk_expr = build::mk_lambda(
|
let blk_expr = build::mk_lambda(
|
||||||
cx,
|
cx,
|
||||||
span,
|
span,
|
||||||
build::mk_fn_decl(~[], build::mk_ty_infer(cx, span)),
|
build::mk_fn_decl(~[e_arg], build::mk_ty_infer(cx, span)),
|
||||||
encode_expr
|
encode_expr
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -257,6 +262,11 @@ fn expand_deriving_encodable_struct_method(
|
||||||
idx += 1;
|
idx += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let e_arg = build::mk_arg(cx,
|
||||||
|
span,
|
||||||
|
cx.ident_of(~"__e"),
|
||||||
|
build::mk_ty_infer(cx, span));
|
||||||
|
|
||||||
let emit_struct_stmt = build::mk_method_call(
|
let emit_struct_stmt = build::mk_method_call(
|
||||||
cx,
|
cx,
|
||||||
span,
|
span,
|
||||||
|
@ -272,7 +282,7 @@ fn expand_deriving_encodable_struct_method(
|
||||||
build::mk_lambda_stmts(
|
build::mk_lambda_stmts(
|
||||||
cx,
|
cx,
|
||||||
span,
|
span,
|
||||||
build::mk_fn_decl(~[], build::mk_ty_infer(cx, span)),
|
build::mk_fn_decl(~[e_arg], build::mk_ty_infer(cx, span)),
|
||||||
statements
|
statements
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
@ -309,10 +319,16 @@ fn expand_deriving_encodable_enum_method(
|
||||||
// Call the substructure method.
|
// Call the substructure method.
|
||||||
let expr = call_substructure_encode_method(cx, span, field);
|
let expr = call_substructure_encode_method(cx, span, field);
|
||||||
|
|
||||||
|
let e_ident = cx.ident_of(~"__e");
|
||||||
|
let e_arg = build::mk_arg(cx,
|
||||||
|
span,
|
||||||
|
e_ident,
|
||||||
|
build::mk_ty_infer(cx, span));
|
||||||
|
|
||||||
let blk_expr = build::mk_lambda(
|
let blk_expr = build::mk_lambda(
|
||||||
cx,
|
cx,
|
||||||
span,
|
span,
|
||||||
build::mk_fn_decl(~[], build::mk_ty_infer(cx, span)),
|
build::mk_fn_decl(~[e_arg], build::mk_ty_infer(cx, span)),
|
||||||
expr
|
expr
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -331,6 +347,10 @@ fn expand_deriving_encodable_enum_method(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the pattern body.
|
// Create the pattern body.
|
||||||
|
let e_arg = build::mk_arg(cx,
|
||||||
|
span,
|
||||||
|
cx.ident_of(~"__e"),
|
||||||
|
build::mk_ty_infer(cx, span));
|
||||||
let call_expr = build::mk_method_call(
|
let call_expr = build::mk_method_call(
|
||||||
cx,
|
cx,
|
||||||
span,
|
span,
|
||||||
|
@ -343,7 +363,7 @@ fn expand_deriving_encodable_enum_method(
|
||||||
build::mk_lambda_stmts(
|
build::mk_lambda_stmts(
|
||||||
cx,
|
cx,
|
||||||
span,
|
span,
|
||||||
build::mk_fn_decl(~[], build::mk_ty_infer(cx, span)),
|
build::mk_fn_decl(~[e_arg], build::mk_ty_infer(cx, span)),
|
||||||
stmts
|
stmts
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
@ -359,11 +379,17 @@ fn expand_deriving_encodable_enum_method(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let e_ident = cx.ident_of(~"__e");
|
||||||
|
let e_arg = build::mk_arg(cx,
|
||||||
|
span,
|
||||||
|
e_ident,
|
||||||
|
build::mk_ty_infer(cx, span));
|
||||||
|
|
||||||
// Create the method body.
|
// Create the method body.
|
||||||
let lambda_expr = build::mk_lambda(
|
let lambda_expr = build::mk_lambda(
|
||||||
cx,
|
cx,
|
||||||
span,
|
span,
|
||||||
build::mk_fn_decl(~[], build::mk_ty_infer(cx, span)),
|
build::mk_fn_decl(~[e_arg], build::mk_ty_infer(cx, span)),
|
||||||
expand_enum_or_struct_match(cx, span, arms)
|
expand_enum_or_struct_match(cx, span, arms)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -420,7 +420,8 @@ mod test {
|
||||||
|
|
||||||
#[cfg(test)] fn to_json_str<E : Encodable<std::json::Encoder>>(val: @E) -> ~str {
|
#[cfg(test)] fn to_json_str<E : Encodable<std::json::Encoder>>(val: @E) -> ~str {
|
||||||
do io::with_str_writer |writer| {
|
do io::with_str_writer |writer| {
|
||||||
val.encode(~std::json::Encoder(writer));
|
let mut encoder = std::json::Encoder(writer);
|
||||||
|
val.encode(&mut encoder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
// xfail-test
|
||||||
|
|
||||||
|
// Broken due to arena API problems.
|
||||||
|
|
||||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||||
// file at the top-level directory of this distribution and at
|
// file at the top-level directory of this distribution and at
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
@ -10,7 +14,6 @@
|
||||||
|
|
||||||
extern mod std;
|
extern mod std;
|
||||||
use std::arena;
|
use std::arena;
|
||||||
use methods = std::arena::Arena;
|
|
||||||
|
|
||||||
enum tree<'self> {
|
enum tree<'self> {
|
||||||
nil,
|
nil,
|
||||||
|
@ -26,9 +29,7 @@ fn item_check(t: &tree) -> int {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bottom_up_tree<'r>(arena: &'r arena::Arena,
|
fn bottom_up_tree<'r>(arena: &'r mut arena::Arena, item: int, depth: int)
|
||||||
item: int,
|
|
||||||
depth: int)
|
|
||||||
-> &'r tree<'r> {
|
-> &'r tree<'r> {
|
||||||
if depth > 0 {
|
if depth > 0 {
|
||||||
return arena.alloc(
|
return arena.alloc(
|
||||||
|
@ -58,25 +59,25 @@ fn main() {
|
||||||
max_depth = n;
|
max_depth = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
let stretch_arena = arena::Arena();
|
let mut stretch_arena = arena::Arena();
|
||||||
let stretch_depth = max_depth + 1;
|
let stretch_depth = max_depth + 1;
|
||||||
let stretch_tree = bottom_up_tree(&stretch_arena, 0, stretch_depth);
|
let stretch_tree = bottom_up_tree(&mut stretch_arena, 0, stretch_depth);
|
||||||
|
|
||||||
io::println(fmt!("stretch tree of depth %d\t check: %d",
|
io::println(fmt!("stretch tree of depth %d\t check: %d",
|
||||||
stretch_depth,
|
stretch_depth,
|
||||||
item_check(stretch_tree)));
|
item_check(stretch_tree)));
|
||||||
|
|
||||||
let long_lived_arena = arena::Arena();
|
let mut long_lived_arena = arena::Arena();
|
||||||
let long_lived_tree = bottom_up_tree(&long_lived_arena, 0, max_depth);
|
let long_lived_tree = bottom_up_tree(&mut long_lived_arena, 0, max_depth);
|
||||||
let mut depth = min_depth;
|
let mut depth = min_depth;
|
||||||
while depth <= max_depth {
|
while depth <= max_depth {
|
||||||
let iterations = int::pow(2, (max_depth - depth + min_depth) as uint);
|
let iterations = int::pow(2, (max_depth - depth + min_depth) as uint);
|
||||||
let mut chk = 0;
|
let mut chk = 0;
|
||||||
let mut i = 1;
|
let mut i = 1;
|
||||||
while i <= iterations {
|
while i <= iterations {
|
||||||
let mut temp_tree = bottom_up_tree(&long_lived_arena, i, depth);
|
let mut temp_tree = bottom_up_tree(&mut long_lived_arena, i, depth);
|
||||||
chk += item_check(temp_tree);
|
chk += item_check(temp_tree);
|
||||||
temp_tree = bottom_up_tree(&long_lived_arena, -i, depth);
|
temp_tree = bottom_up_tree(&mut long_lived_arena, -i, depth);
|
||||||
chk += item_check(temp_tree);
|
chk += item_check(temp_tree);
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,11 +31,12 @@ fn test_ebml<A:
|
||||||
Decodable<EBReader::Decoder>
|
Decodable<EBReader::Decoder>
|
||||||
>(a1: &A) {
|
>(a1: &A) {
|
||||||
let bytes = do io::with_bytes_writer |wr| {
|
let bytes = do io::with_bytes_writer |wr| {
|
||||||
let ebml_w = &EBWriter::Encoder(wr);
|
let mut ebml_w = EBWriter::Encoder(wr);
|
||||||
a1.encode(ebml_w)
|
a1.encode(&mut ebml_w)
|
||||||
};
|
};
|
||||||
let d = EBReader::Doc(@bytes);
|
let d = EBReader::Doc(@bytes);
|
||||||
let a2: A = Decodable::decode(&EBReader::Decoder(d));
|
let mut decoder = EBReader::Decoder(d);
|
||||||
|
let a2: A = Decodable::decode(&mut decoder);
|
||||||
assert!(*a1 == a2);
|
assert!(*a1 == a2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,5 +17,6 @@ use self::std::serialize;
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let json = json::from_str("[1]").unwrap();
|
let json = json::from_str("[1]").unwrap();
|
||||||
let _x: ~[int] = serialize::Decodable::decode(&json::Decoder(json));
|
let mut decoder = json::Decoder(json);
|
||||||
|
let _x: ~[int] = serialize::Decodable::decode(&mut decoder);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,8 @@ extern mod std;
|
||||||
use std::arena;
|
use std::arena;
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let p = &arena::Arena();
|
let mut arena = arena::Arena();
|
||||||
|
let p = &mut arena;
|
||||||
let x = p.alloc(|| 4u);
|
let x = p.alloc(|| 4u);
|
||||||
io::print(fmt!("%u", *x));
|
io::print(fmt!("%u", *x));
|
||||||
assert!(*x == 4u);
|
assert!(*x == 4u);
|
||||||
|
|
|
@ -21,7 +21,7 @@ struct Bcx<'self> {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Fcx<'self> {
|
struct Fcx<'self> {
|
||||||
arena: &'self Arena,
|
arena: &'self mut Arena,
|
||||||
ccx: &'self Ccx
|
ccx: &'self Ccx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,23 +29,27 @@ struct Ccx {
|
||||||
x: int
|
x: int
|
||||||
}
|
}
|
||||||
|
|
||||||
fn h<'r>(bcx : &'r Bcx<'r>) -> &'r Bcx<'r> {
|
fn h<'r>(bcx : &'r mut Bcx<'r>) -> &'r mut Bcx<'r> {
|
||||||
return bcx.fcx.arena.alloc(|| Bcx { fcx: bcx.fcx });
|
// XXX: Arena has a bad interface here; it should return mutable pointers.
|
||||||
|
// But this patch is too big to roll that in.
|
||||||
|
unsafe {
|
||||||
|
cast::transmute(bcx.fcx.arena.alloc(|| Bcx { fcx: bcx.fcx }))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn g(fcx : &Fcx) {
|
fn g(fcx: &mut Fcx) {
|
||||||
let bcx = Bcx { fcx: fcx };
|
let mut bcx = Bcx { fcx: fcx };
|
||||||
h(&bcx);
|
h(&mut bcx);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn f(ccx : &Ccx) {
|
fn f(ccx: &mut Ccx) {
|
||||||
let a = Arena();
|
let mut a = Arena();
|
||||||
let fcx = &Fcx { arena: &a, ccx: ccx };
|
let mut fcx = Fcx { arena: &mut a, ccx: ccx };
|
||||||
return g(fcx);
|
return g(&mut fcx);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let ccx = Ccx { x: 0 };
|
let mut ccx = Ccx { x: 0 };
|
||||||
f(&ccx);
|
f(&mut ccx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue