wip using custom hashtables for globals
This commit is contained in:
parent
31b0b28dca
commit
0b41e69007
|
@ -30,6 +30,7 @@ proc free*[U, V](tbl: var Table[U, V]) =
|
|||
dealloc(tbl.entries)
|
||||
|
||||
proc findEntry[U, V](entries: ptr UncheckedArray[Entry[U, V]], cap: int, key: U): ptr Entry[U, V] =
|
||||
mixin fnv1a, equal
|
||||
var index = key.fnv1a().bitand(cap - 1)
|
||||
var tombstone: ptr Entry[U, V] = nil
|
||||
while true:
|
||||
|
|
|
@ -107,7 +107,6 @@ proc isFalsey*(val: NdValue): bool =
|
|||
template isTruthy*(val: NdValue): bool =
|
||||
not val.isFalsey()
|
||||
|
||||
|
||||
proc friendlyType*(val: NdValue): string =
|
||||
if val == ndNil:
|
||||
"nil"
|
||||
|
|
4
vm.nim
4
vm.nim
|
@ -170,7 +170,7 @@ proc run*(chunk: Chunk): InterpretResult =
|
|||
of opGetGlobal:
|
||||
let name = readConstant().asString()
|
||||
var val: NdValue
|
||||
let existed = globals.tableGet(name, val)
|
||||
let existed = globals.tableGet(name.fromNdString(), val)
|
||||
if existed:
|
||||
stack.add(val)
|
||||
else:
|
||||
|
@ -178,7 +178,7 @@ proc run*(chunk: Chunk): InterpretResult =
|
|||
break
|
||||
of opSetGlobal:
|
||||
let name = readConstant().asString()
|
||||
let existed = globals.tableSet(name, stack.pop())
|
||||
let existed = globals.tableSet(name.fromNdString(), stack.pop())
|
||||
if not existed:
|
||||
runtimeError("Attempt to redefine an existing global variable.")
|
||||
break
|
||||
|
|
Loading…
Reference in New Issue