diff --git a/Makefile.in b/Makefile.in index 20fd0bd..ad4f38b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,53 +1,29 @@ -RUSTC := rustc -BUILDDIR := build -RUSTFLAGS := -O --cfg ndebug -INSTALL_DIR := %PREFIX% +VPATH=%VPATH% -PHF_LIB := src/phf.rs -PHF := $(foreach file,$(shell $(RUSTC) --crate-file-name $(PHF_LIB)),$(BUILDDIR)/$(file)) -PHF_MAC_LIB := src/phf_mac.rs -PHF_MAC := $(BUILDDIR)/$(shell $(RUSTC) --crate-file-name $(PHF_MAC_LIB)) -PHF_TEST_MAIN := src/test.rs -PHF_TEST := $(BUILDDIR)/$(shell $(RUSTC) --crate-file-name $(PHF_TEST_MAIN)) +RUSTC ?= rustc +RUSTDOC ?= rustdoc +RUSTFLAGS ?= -O -all: $(PHF) $(PHF_MAC) +PHF_SRC := $(VPATH)/src/phf.rs +PHF_MAC_SRC := $(VPATH)/src/phf_mac.rs +PHF_TEST_SRC := $(VPATH)/src/test.rs --include $(BUILDDIR)/phf.d --include $(BUILDDIR)/phf_mac.d --include $(BUILDDIR)/phf_test.d +all: phf.dummy phf_mac.dummy -$(BUILDDIR): - mkdir -p $@ +phf.dummy: $(PHF_SRC) + $(RUSTC) $(RUSTFLAGS) $< --out-dir . + touch $@ -$(PHF): $(PHF_LIB) | $(BUILDDIR) - $(RUSTC) $(RUSTFLAGS) --dep-info $(BUILDDIR)/phf.d --out-dir $(@D) $< +phf_mac.dummy: $(PHF_MAC_SRC) + $(RUSTC) $(RUSTFLAGS) -L . $< --out-dir . + touch $@ -$(PHF_MAC): $(PHF_MAC_LIB) $(PHF) | $(BUILDDIR) - $(RUSTC) $(RUSTFLAGS) --dep-info $(BUILDDIR)/phf_mac.d --out-dir $(@D) \ - -L $(BUILDDIR) $< +check: phf_test.dummy -$(PHF_TEST): $(PHF_TEST_MAIN) $(PHF) $(PHF_MAC) | $(BUILDDIR) - $(RUSTC) --test $(RUSTFLAGS) -L $(BUILDDIR) \ - --dep-info $(BUILDDIR)/phf_test.d --out-dir $(@D) $< - -doc-test: $(PHF) $(PHF_MAC) - rustdoc -L $(BUILDDIR) --test $(PHF_LIB) - -check: $(PHF_TEST) doc-test - $(PHF_TEST) - -doc: $(PHF) - rustdoc $(PHF_LIB) - rustdoc -L $(BUILDDIR) $(PHF_MAC_LIB) - -install: $(PHF) $(PHF_MAC) - install $(PHF) $(INSTALL_DIR) - install $(PHF_MAC) $(INSTALL_DIR) +phf_test.dummy: $(PHF_TEST_SRC) + $(RUSTC) --test $(RUSTFLAGS) -L . $< --out-dir . clean: - rm -rf $(BUILDDIR) - -print-targets: - @echo $(PHF_MAC) $(PHF) + rm -f *.o *.a *.so *.dylib *.rlib *.dll *.dummy *.exe *-test -.PHONY: all doc-test check doc install clean print-targets +.PHONY: all check clean diff --git a/configure b/configure index 7fe7f2b..62a0f4c 100755 --- a/configure +++ b/configure @@ -1,20 +1,4 @@ #!/bin/bash -cd $(dirname $0) - -TEMP=`getopt -o "" --long prefix: -n "$0" -- "$@"` - -if [ $? != 0 ]; then exit 1; fi - -eval set -- "$TEMP" - -PREFIX=/usr/lib - -while true ; do - case "$1" in - --prefix) PREFIX=$2; shift 2;; - --) shift; break;; - esac -done - -sed -e "s|%PREFIX%|$PREFIX|" < Makefile.in > Makefile +SRCDIR="$(cd $(dirname $0) && pwd)" +sed "s#%VPATH%#${SRCDIR}#" ${SRCDIR}/Makefile.in > Makefile diff --git a/src/phf.rs b/src/phf.rs index d657f92..cf7cfad 100644 --- a/src/phf.rs +++ b/src/phf.rs @@ -9,7 +9,6 @@ use std::fmt; use std::hash::Hasher; use std::hash::sip::SipHasher; use std::slice; -use std::collections::Collection; /// An immutable map constructed at compile time. /// @@ -69,7 +68,7 @@ pub fn displace(f1: uint, f2: uint, d1: uint, d2: uint) -> uint { d2 + f1 * d1 + f2 } -impl Collection for PhfMap { +impl Container for PhfMap { fn len(&self) -> uint { self.entries.len() } @@ -229,7 +228,7 @@ impl fmt::Show for PhfSet { } } -impl Collection for PhfSet { +impl Container for PhfSet { #[inline] fn len(&self) -> uint { self.map.len() @@ -345,7 +344,7 @@ impl fmt::Show for PhfOrderedMap { } } -impl Collection for PhfOrderedMap { +impl Container for PhfOrderedMap { fn len(&self) -> uint { self.entries.len() } @@ -554,7 +553,7 @@ impl fmt::Show for PhfOrderedSet { } } -impl Collection for PhfOrderedSet { +impl Container for PhfOrderedSet { #[inline] fn len(&self) -> uint { self.map.len() diff --git a/src/phf_mac.rs b/src/phf_mac.rs index dea3b67..a8c6190 100644 --- a/src/phf_mac.rs +++ b/src/phf_mac.rs @@ -4,39 +4,50 @@ #![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, plugin_registrar, quote)] +#![feature(managed_boxes, macro_registrar, quote)] extern crate rand; extern crate syntax; extern crate time; extern crate phf; -extern crate rustc; +extern crate collections; -use std::collections::HashMap; +use collections::HashMap; use std::os; use syntax::ast; -use syntax::ast::{TokenTree, LitStr, Expr, ExprVec, ExprLit}; +use syntax::ast::{Name, TokenTree, LitStr, Expr, ExprVec, ExprLit}; use syntax::codemap::Span; -use syntax::ext::base::{DummyResult, +use syntax::ext::base::{SyntaxExtension, + DummyResult, ExtCtxt, MacResult, - MacExpr}; + MacExpr, + NormalTT, + BasicMacroExpander}; 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]; -#[plugin_registrar] +#[macro_registrar] #[doc(hidden)] -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); +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); } struct Entry { diff --git a/src/test.rs b/src/test.rs index d75869b..89d6d1d 100644 --- a/src/test.rs +++ b/src/test.rs @@ -1,11 +1,12 @@ #![feature(phase)] -#[phase(plugin)] +#[phase(syntax)] extern crate phf_mac; extern crate phf; +extern crate collections; mod map { - use std::collections::{HashMap, HashSet}; + use collections::{HashMap, HashSet}; use phf::PhfMap; #[allow(dead_code)] @@ -118,7 +119,7 @@ mod map { } mod set { - use std::collections::HashSet; + use collections::HashSet; use phf::PhfSet; #[allow(dead_code)]