pre-intern some fixed names so they can be used as constants
This commit is contained in:
parent
9a7890d73a
commit
7317bf8792
@ -279,9 +279,18 @@ pure fn is_bar(t: token) -> bool {
|
||||
|
||||
type ident_interner = util::interner::interner<@~str>;
|
||||
|
||||
mod special_idents {
|
||||
const underscore : uint = 0u;
|
||||
const anon : uint = 1u;
|
||||
const destr : uint = 2u; // 'drop', but that's reserved
|
||||
}
|
||||
|
||||
fn mk_ident_interner() -> ident_interner {
|
||||
let rv = @interner::mk::<@~str>(|x| str::hash(*x),
|
||||
|x,y| str::eq(*x, *y));
|
||||
/* the indices here must correspond to the numbers in special_idents */
|
||||
let init_vec = ~[@~"_", @~"anon", @~"drop"];
|
||||
|
||||
let rv = @interner::mk_prefill::<@~str>(|x| str::hash(*x),
|
||||
|x,y| str::eq(*x, *y), init_vec);
|
||||
rv
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,15 @@ fn mk<T: const copy>(+hasher: hashfn<T>, +eqer: eqfn<T>) -> interner<T> {
|
||||
return hi as interner::<T>;
|
||||
}
|
||||
|
||||
fn mk_prefill<T: const copy>(hasher: hashfn<T>, eqer: eqfn<T>,
|
||||
init: ~[T]) -> interner<T> {
|
||||
|
||||
let rv = mk(hasher, eqer);
|
||||
for init.each() |v| { rv.intern(v); }
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
/* when traits can extend traits, we should extend index<uint,T> to get [] */
|
||||
trait interner<T: const copy> {
|
||||
fn intern(T) -> uint;
|
||||
|
Loading…
x
Reference in New Issue
Block a user