From 856d1345e4eec9cf3f0fd6f89ff38cbe7bd98bae Mon Sep 17 00:00:00 2001 From: prod2 <95874442+prod2@users.noreply.github.com> Date: Mon, 14 Feb 2022 10:33:10 +0100 Subject: [PATCH] init the globals table with a larger init cap --- src/ndspkg/types/hashtable.nim | 5 +++++ src/ndspkg/vm.nim | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) 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()