diff --git a/src/phf.rs b/src/phf.rs index cf7cfad..68a73f8 100644 --- a/src/phf.rs +++ b/src/phf.rs @@ -68,7 +68,7 @@ pub fn displace(f1: uint, f2: uint, d1: uint, d2: uint) -> uint { d2 + f1 * d1 + f2 } -impl Container for PhfMap { +impl Collection for PhfMap { fn len(&self) -> uint { self.entries.len() } @@ -82,7 +82,7 @@ impl<'a, T> Map<&'a str, T> for PhfMap { impl fmt::Show for PhfMap { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - try!(write!(fmt, r"\{")); + try!(write!(fmt, "{{")); let mut first = true; for (k, v) in self.entries() { if !first { @@ -91,7 +91,7 @@ impl fmt::Show for PhfMap { try!(write!(fmt, "{}: {}", k, v)) first = false; } - write!(fmt, r"\}") + write!(fmt, "}}") } } @@ -215,7 +215,7 @@ pub struct PhfSet { impl fmt::Show for PhfSet { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - try!(write!(fmt, r"\{")); + try!(write!(fmt, "{{")); let mut first = true; for entry in self.iter() { if !first { @@ -224,11 +224,11 @@ impl fmt::Show for PhfSet { try!(write!(fmt, "{}", entry)); first = false; } - write!(fmt, r"\}") + write!(fmt, "}}") } } -impl Container for PhfSet { +impl Collection for PhfSet { #[inline] fn len(&self) -> uint { self.map.len() @@ -331,7 +331,7 @@ pub struct PhfOrderedMap { impl fmt::Show for PhfOrderedMap { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - try!(write!(fmt, r"\{")); + try!(write!(fmt, "{{")); let mut first = true; for (k, v) in self.entries() { if !first { @@ -340,11 +340,11 @@ impl fmt::Show for PhfOrderedMap { try!(write!(fmt, "{}: {}", k, v)) first = false; } - write!(fmt, r"\}") + write!(fmt, "}}") } } -impl Container for PhfOrderedMap { +impl Collection for PhfOrderedMap { fn len(&self) -> uint { self.entries.len() } @@ -540,7 +540,7 @@ pub struct PhfOrderedSet { impl fmt::Show for PhfOrderedSet { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - try!(write!(fmt, r"\{")); + try!(write!(fmt, "{{")); let mut first = true; for entry in self.iter() { if !first { @@ -549,11 +549,11 @@ impl fmt::Show for PhfOrderedSet { try!(write!(fmt, "{}", entry)); first = false; } - write!(fmt, r"\}") + write!(fmt, "}}") } } -impl Container for PhfOrderedSet { +impl Collection for PhfOrderedSet { #[inline] fn len(&self) -> uint { self.map.len() diff --git a/src/phf_mac.rs b/src/phf_mac.rs index a8c6190..54b1ee4 100644 --- a/src/phf_mac.rs +++ b/src/phf_mac.rs @@ -4,56 +4,46 @@ #![crate_id="github.com/sfackler/rust-phf/phf_mac"] #![crate_type="dylib"] #![doc(html_root_url="http://sfackler.github.io/rust-phf/doc")] -#![feature(managed_boxes, macro_registrar, quote)] +#![feature(plugin_registrar, quote)] extern crate rand; extern crate syntax; extern crate time; extern crate phf; -extern crate collections; +extern crate rustc; -use collections::HashMap; +use std::collections::HashMap; +use std::gc::{Gc, GC}; use std::os; use syntax::ast; -use syntax::ast::{Name, TokenTree, LitStr, Expr, ExprVec, ExprLit}; +use syntax::ast::{TokenTree, LitStr, Expr, ExprVec, ExprLit}; use syntax::codemap::Span; -use syntax::ext::base::{SyntaxExtension, - DummyResult, +use syntax::ext::base::{DummyResult, ExtCtxt, MacResult, - MacExpr, - NormalTT, - BasicMacroExpander}; + MacExpr}; use syntax::parse; -use syntax::parse::token; use syntax::parse::token::{InternedString, COMMA, EOF, FAT_ARROW}; use rand::{Rng, SeedableRng, XorShiftRng}; +use rustc::plugin::Registry; static DEFAULT_LAMBDA: uint = 5; static FIXED_SEED: [u32, ..4] = [3141592653, 589793238, 462643383, 2795028841]; -#[macro_registrar] +#[plugin_registrar] #[doc(hidden)] -pub fn macro_registrar(register: |Name, SyntaxExtension|) { - let reg = |name, fn_| { - register(token::intern(name), - NormalTT(box BasicMacroExpander { - expander: fn_, - span: None - }, - None)); - }; - reg("phf_map", expand_phf_map); - reg("phf_set", expand_phf_set); - reg("phf_ordered_map", expand_phf_ordered_map); - reg("phf_ordered_set", expand_phf_ordered_set); +pub fn macro_registrar(reg: &mut Registry) { + reg.register_macro("phf_map", expand_phf_map); + reg.register_macro("phf_set", expand_phf_set); + reg.register_macro("phf_ordered_map", expand_phf_ordered_map); + reg.register_macro("phf_ordered_set", expand_phf_ordered_set); } struct Entry { key_str: InternedString, - key: @Expr, - value: @Expr + key: Gc, + value: Gc } struct HashState { @@ -414,8 +404,8 @@ fn create_ordered_set(cx: &mut ExtCtxt, sp: Span, entries: Vec, MacExpr::new(quote_expr!(cx, ::phf::PhfOrderedSet { map: $map })) } -fn create_slice_expr(vec: Vec<@Expr>, sp: Span) -> @Expr { - @Expr { +fn create_slice_expr(vec: Vec>, sp: Span) -> Gc { + box (GC) Expr { id: ast::DUMMY_NODE_ID, node: ExprVec(vec), span: sp