summary refs log tree commit diff stats
path: root/compiler/nir/nirslots.nim
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/nir/nirslots.nim')
-rw-r--r--compiler/nir/nirslots.nim41
1 files changed, 20 insertions, 21 deletions
diff --git a/compiler/nir/nirslots.nim b/compiler/nir/nirslots.nim
index d983fdea2..a01e7a633 100644
--- a/compiler/nir/nirslots.nim
+++ b/compiler/nir/nirslots.nim
@@ -24,25 +24,25 @@ type
     dead: Table[TypeId, seq[SymId]]
     flags: set[SlotManagerFlag]
     inScope: seq[SymId]
-    locGen: ref int
 
-proc initSlotManager*(flags: set[SlotManagerFlag]; generator: ref int): SlotManager {.inline.} =
-  SlotManager(flags: flags, locGen: generator)
+proc initSlotManager*(flags: set[SlotManagerFlag]): SlotManager {.inline.} =
+  SlotManager(flags: flags)
 
-proc allocRaw(m: var SlotManager; t: TypeId; f: SlotManagerFlag; k: SlotKind): SymId {.inline.} =
+proc allocRaw(m: var SlotManager; t: TypeId; f: SlotManagerFlag; k: SlotKind;
+              symIdgen: var int32): SymId {.inline.} =
   if f in m.flags and m.dead.hasKey(t) and m.dead[t].len > 0:
     result = m.dead[t].pop()
   else:
-    result = SymId(m.locGen[])
-    inc m.locGen[]
+    inc symIdgen
+    result = SymId(symIdgen)
     m.inScope.add result
   m.live[result] = (k, t)
 
-proc allocTemp*(m: var SlotManager; t: TypeId): SymId {.inline.} =
-  result = allocRaw(m, t, ReuseTemps, Temp)
+proc allocTemp*(m: var SlotManager; t: TypeId; symIdgen: var int32): SymId {.inline.} =
+  result = allocRaw(m, t, ReuseTemps, Temp, symIdgen)
 
-proc allocVar*(m: var SlotManager; t: TypeId): SymId {.inline.} =
-  result = allocRaw(m, t, ReuseVars, Perm)
+proc allocVar*(m: var SlotManager; t: TypeId; symIdgen: var int32): SymId {.inline.} =
+  result = allocRaw(m, t, ReuseVars, Perm, symIdgen)
 
 proc freeLoc*(m: var SlotManager; s: SymId) =
   let t = m.live.getOrDefault(s)
@@ -74,32 +74,31 @@ proc closeScope*(m: var SlotManager) =
     dec i
 
 when isMainModule:
-  var m = initSlotManager({ReuseTemps}, new(int))
+  var symIdgen: int32
+  var m = initSlotManager({ReuseTemps})
 
   var g = initTypeGraph(Literals())
 
   let a = g.openType ArrayTy
   g.addBuiltinType Int8Id
-  g.addArrayLen 5'u64
-  let finalArrayType = sealType(g, a)
+  g.addArrayLen 5
+  let finalArrayType = finishType(g, a)
 
   let obj = g.openType ObjectDecl
   g.addName "MyType"
 
-  g.addField "p", finalArrayType
-  let objB = sealType(g, obj)
+  g.addField "p", finalArrayType, 0
+  let objB = finishType(g, obj)
 
-  let x = m.allocTemp(objB)
+  let x = m.allocTemp(objB, symIdgen)
   assert x.int == 0
 
-  let y = m.allocTemp(objB)
+  let y = m.allocTemp(objB, symIdgen)
   assert y.int == 1
 
-  let z = m.allocTemp(Int8Id)
+  let z = m.allocTemp(Int8Id, symIdgen)
   assert z.int == 2
 
   m.freeLoc y
-  let y2 = m.allocTemp(objB)
+  let y2 = m.allocTemp(objB, symIdgen)
   assert y2.int == 1
-
-