1 | use crate::token::{Id, Span}; |
---|---|
2 | use std::cell::Cell; |
3 | |
4 | thread_local!(static NEXT: Cell<u32> = Cell::new(0)); |
5 | |
6 | pub fn reset() { |
7 | NEXT.with(|c: &Cell |
8 | } |
9 | |
10 | pub fn generate(span: Span) -> Id<'static> { |
11 | NEXT.with(|next: &Cell |
12 | let generation: u32 = next.get() + 1; |
13 | next.set(val:generation); |
14 | Id::gensym(span, generation) |
15 | }) |
16 | } |
17 | |
18 | pub fn fill<'a>(span: Span, slot: &mut Option<Id<'a>>) -> Id<'a> { |
19 | *slot.get_or_insert_with(|| generate(span)) |
20 | } |
21 |