Skip to content

Commit

Permalink
remove serialize::ebml, add librbml
Browse files Browse the repository at this point in the history
Our implementation of ebml has diverged from the standard in order
to better serve the needs of the compiler, so it doesn't make much
sense to call what we have ebml anyore. Furthermore, our implementation
is pretty crufty, and should eventually be rewritten into a format
that better suits the needs of the compiler. This patch factors out
serialize::ebml into librbml, otherwise known as the Really Bad
Markup Language. This is a stopgap library that shouldn't be used
by end users, and will eventually be replaced by something better.

[breaking-change]
  • Loading branch information
erickt authored and alexcrichton committed Jul 31, 2014
1 parent ea1b637 commit e1dcbef
Show file tree
Hide file tree
Showing 12 changed files with 897 additions and 879 deletions.
7 changes: 4 additions & 3 deletions mk/crates.mk
Expand Up @@ -51,7 +51,7 @@

TARGET_CRATES := libc std green rustuv native flate arena glob term semver \
uuid serialize sync getopts collections num test time rand \
url log regex graphviz core rlibc alloc debug rustrt \
url log regex graphviz core rbml rlibc alloc debug rustrt \
unicode
HOST_CRATES := syntax rustc rustdoc fourcc hexfloat regex_macros fmt_macros \
rustc_llvm rustc_back
Expand All @@ -71,7 +71,7 @@ DEPS_green := std native:context_switch
DEPS_rustuv := std native:uv native:uv_support
DEPS_native := std
DEPS_syntax := std term serialize log fmt_macros debug
DEPS_rustc := syntax flate arena serialize getopts \
DEPS_rustc := syntax flate arena serialize getopts rbml \
time log graphviz debug rustc_llvm rustc_back
DEPS_rustc_llvm := native:rustllvm libc std
DEPS_rustc_back := std syntax rustc_llvm flate log libc
Expand All @@ -82,6 +82,7 @@ DEPS_arena := std
DEPS_graphviz := std
DEPS_glob := std
DEPS_serialize := std log
DEPS_rbml := std log serialize
DEPS_term := std log
DEPS_semver := std
DEPS_uuid := std serialize
Expand All @@ -91,7 +92,7 @@ DEPS_collections := core alloc unicode
DEPS_fourcc := rustc syntax std
DEPS_hexfloat := rustc syntax std
DEPS_num := std
DEPS_test := std getopts serialize term time regex native:rust_test_helpers
DEPS_test := std getopts serialize rbml term time regex native:rust_test_helpers
DEPS_time := std serialize
DEPS_rand := core
DEPS_url := std
Expand Down
52 changes: 34 additions & 18 deletions src/libserialize/ebml.rs → src/librbml/lib.rs
Expand Up @@ -8,16 +8,35 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! Really Bad Markup Language (rbml) is a temporary measure until we migrate
//! the rust object metadata to a better serialization format. It is not
//! intended to be used by users.
//!
//! It is loosely based on the Extensible Binary Markup Language (ebml):
//! http://www.matroska.org/technical/specs/rfc/index.html

#![crate_name = "rbml"]
#![experimental]
#![crate_type = "rlib"]
#![crate_type = "dylib"]
#![license = "MIT/ASL2"]
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/master/",
html_playground_url = "http://play.rust-lang.org/")]
#![feature(macro_rules, phase)]
#![allow(missing_doc)]

extern crate serialize;

#[phase(plugin, link)] extern crate log;
#[cfg(test)] extern crate test;

use std::io;
use std::str;

// Simple Extensible Binary Markup Language (ebml) reader and writer on a
// cursor model. See the specification here:
// http://www.matroska.org/technical/specs/rfc/index.html

// Common data structures
/// Common data structures
#[deriving(Clone)]
pub struct Doc<'a> {
pub data: &'a [u8],
Expand Down Expand Up @@ -107,7 +126,7 @@ pub mod reader {
Expected };

pub type DecodeResult<T> = Result<T, Error>;
// ebml reading
// rbml reading

macro_rules! try_or(
($e:expr, $r:expr) => (
Expand Down Expand Up @@ -637,7 +656,7 @@ pub mod writer {

pub type EncodeResult = io::IoResult<()>;

// ebml writing
// rbml writing
pub struct Encoder<'a, W> {
pub writer: &'a mut W,
size_positions: Vec<uint>,
Expand Down Expand Up @@ -671,7 +690,7 @@ pub mod writer {
})
}

// FIXME (#2741): Provide a function to write the standard ebml header.
// FIXME (#2741): Provide a function to write the standard rbml header.
impl<'a, W: Writer + Seek> Encoder<'a, W> {
pub fn new(w: &'a mut W) -> Encoder<'a, W> {
Encoder {
Expand Down Expand Up @@ -1018,10 +1037,8 @@ pub mod writer {

#[cfg(test)]
mod tests {
use super::Doc;
use ebml::reader;
use ebml::writer;
use {Encodable, Decodable};
use super::{Doc, reader, writer};
use serialize::{Encodable, Decodable};

use std::io::{IoError, IoResult, SeekStyle};
use std::io;
Expand Down Expand Up @@ -1196,11 +1213,11 @@ mod tests {
debug!("v == {}", v);
let mut wr = SeekableMemWriter::new();
{
let mut ebml_w = writer::Encoder::new(&mut wr);
let _ = v.encode(&mut ebml_w);
let mut rbml_w = writer::Encoder::new(&mut wr);
let _ = v.encode(&mut rbml_w);
}
let ebml_doc = Doc::new(wr.get_ref());
let mut deser = reader::Decoder::new(ebml_doc);
let rbml_doc = Doc::new(wr.get_ref());
let mut deser = reader::Decoder::new(rbml_doc);
let v1 = Decodable::decode(&mut deser).unwrap();
debug!("v1 == {}", v1);
assert_eq!(v, v1);
Expand All @@ -1215,9 +1232,8 @@ mod tests {
#[cfg(test)]
mod bench {
#![allow(non_snake_case_functions)]
extern crate test;
use self::test::Bencher;
use ebml::reader;
use test::Bencher;
use super::reader;

#[bench]
pub fn vuint_at_A_aligned(b: &mut Bencher) {
Expand Down
1 change: 1 addition & 0 deletions src/librustc/lib.rs
Expand Up @@ -44,6 +44,7 @@ extern crate libc;
extern crate llvm = "rustc_llvm";
extern crate rustc_back = "rustc_back";
extern crate serialize;
extern crate rbml;
extern crate time;
#[phase(plugin, link)] extern crate log;
#[phase(plugin, link)] extern crate syntax;
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/metadata/csearch.rs
Expand Up @@ -20,8 +20,8 @@ use middle::ty;
use middle::typeck;
use middle::subst::VecPerParamSpace;

use serialize::ebml;
use serialize::ebml::reader;
use rbml;
use rbml::reader;
use std::rc::Rc;
use syntax::ast;
use syntax::ast_map;
Expand Down Expand Up @@ -218,7 +218,7 @@ pub fn get_field_type(tcx: &ty::ctxt, class_id: ast::DefId,
def: ast::DefId) -> ty::Polytype {
let cstore = &tcx.sess.cstore;
let cdata = cstore.get_crate_data(class_id.krate);
let all_items = reader::get_doc(ebml::Doc::new(cdata.data()), tag_items);
let all_items = reader::get_doc(rbml::Doc::new(cdata.data()), tag_items);
let class_doc = expect(tcx.sess.diagnostic(),
decoder::maybe_find_item(class_id.node, all_items),
|| {
Expand Down

0 comments on commit e1dcbef

Please sign in to comment.