diff --git a/src/ndspkg/types/hashtable.nim b/src/ndspkg/types/hashtable.nim index 11818cf..94c35f0 100644 --- a/src/ndspkg/types/hashtable.nim +++ b/src/ndspkg/types/hashtable.nim @@ -25,6 +25,11 @@ proc newTable*[U, V]: Table[U, V] = result.cap = 0 result.count = 0 +proc newTable*[U, V](initcap: int): Table[U, V] = + result.cap = initcap + result.count = 0 + result.entries = cast[ptr UncheckedArray[Entry[U, V]]](alloc0(sizeof(Entry[U, V]) * initcap)) + proc newNdTable*[U, V]: NdTable[U, V] = result = cast[NdTable[U, V]](alloc(sizeof(Table[U, V]))) result[].cap = 0 diff --git a/src/ndspkg/vm.nim b/src/ndspkg/vm.nim index d721b81..ec2d59a 100644 --- a/src/ndspkg/vm.nim +++ b/src/ndspkg/vm.nim @@ -43,7 +43,7 @@ proc run*(chunk: Chunk): InterpretResult = ip: ptr uint8 = chunk.code[0].unsafeAddr stack: Stack[NdValue] = newStack[NdValue](256) hadError: bool - globals: Table[NdValue, NdValue] + globals: Table[NdValue, NdValue] = newTable[NdValue, NdValue](64) frames: Stack[Frame] = newStack[Frame](4) openUpvalues: Upvalue[NdValue] = nil @@ -131,7 +131,7 @@ proc run*(chunk: Chunk): InterpretResult = upval.location = upval.closed.addr openUpvalues = upval.next - # initialize globals + constructStdlib() for i in 0 .. natives.high(): let native = i.uint32.fromNative()