-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e6140e
commit 68c4168
Showing
3 changed files
with
48 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use std::hash::Hash; | ||
|
||
use crate::ident_pool::Symbol; | ||
|
||
// Identify different symbol with same name | ||
// We will flatten symbol scope when translate it to IR which close to machine code | ||
#[derive(Eq, Debug)] | ||
pub struct LowerIdent { | ||
// this is used just for debug | ||
pub symbol: Symbol, | ||
pub number: usize, | ||
} | ||
|
||
impl LowerIdent { | ||
pub fn new(symbol: Symbol) -> LowerIdent { | ||
// It's safe in single thread | ||
static mut COUNTER: usize = 0; | ||
LowerIdent { | ||
symbol, | ||
number: unsafe { | ||
COUNTER += 1; | ||
COUNTER | ||
}, | ||
} | ||
} | ||
} | ||
|
||
impl PartialEq for LowerIdent { | ||
fn eq(&self, other: &Self) -> bool { | ||
self.number == other.number | ||
} | ||
} | ||
|
||
impl Hash for LowerIdent { | ||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) { | ||
self.number.hash(state); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters