summary refs log tree commit diff stats
path: root/compiler/idents.nim
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/idents.nim')
-rw-r--r--compiler/idents.nim23
1 files changed, 14 insertions, 9 deletions
diff --git a/compiler/idents.nim b/compiler/idents.nim
index a035974f3..34177e76d 100644
--- a/compiler/idents.nim
+++ b/compiler/idents.nim
@@ -11,16 +11,16 @@
 # An identifier is a shared immutable string that can be compared by its
 # id. This module is essential for the compiler's performance.
 
-import
-  hashes, wordrecg
+import wordrecg
+import std/hashes
 
-type
-  TIdObj* = object of RootObj
-    id*: int # unique id; use this for comparisons and not the pointers
+when defined(nimPreviewSlimSystem):
+  import std/assertions
 
-  PIdObj* = ref TIdObj
+type
   PIdent* = ref TIdent
-  TIdent*{.acyclic.} = object of TIdObj
+  TIdent*{.acyclic.} = object
+    id*: int # unique id; use this for comparisons and not the pointers
     s*: string
     next*: PIdent             # for hash-table chaining
     h*: Hash                 # hash value of s
@@ -110,9 +110,14 @@ proc newIdentCache*(): IdentCache =
   result.idDelegator = result.getIdent":delegator"
   result.emptyIdent = result.getIdent("")
   # initialize the keywords:
-  for s in succ(low(specialWords))..high(specialWords):
-    result.getIdent(specialWords[s], hashIgnoreStyle(specialWords[s])).id = ord(s)
+  for s in succ(low(TSpecialWord))..high(TSpecialWord):
+    result.getIdent($s, hashIgnoreStyle($s)).id = ord(s)
 
 proc whichKeyword*(id: PIdent): TSpecialWord =
   if id.id < 0: result = wInvalid
   else: result = TSpecialWord(id.id)
+
+proc hash*(x: PIdent): Hash {.inline.} = x.h
+proc `==`*(a, b: PIdent): bool {.inline.} =
+  if a.isNil or b.isNil: result = system.`==`(a, b)
+  else: result = a.id == b.id