From 01355fdabaedc206cbc7ec7cd74b80d57b56ba7a Mon Sep 17 00:00:00 2001 From: Mattia Giambirtone Date: Mon, 5 Dec 2022 19:19:38 +0100 Subject: [PATCH] Minor fixes and changes --- src/backend/vm.nim | 13 +++++++++---- src/config.nim | 2 +- src/frontend/compiler.nim | 2 -- tests/fib.pn | 2 +- tests/generics.pn | 4 ++-- tests/nestedCalls.pn | 4 ++-- tests/operators.pn | 2 +- 7 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/backend/vm.nim b/src/backend/vm.nim index f9516cb..ef9ad76 100644 --- a/src/backend/vm.nim +++ b/src/backend/vm.nim @@ -118,13 +118,13 @@ proc reallocate*(self: var PeonVM, p: pointer, oldSize: int, newSize: int): poin ## built-in garbage collection self.gc.bytesAllocated.current += newSize - oldSize try: - if newSize == 0 and not p.isNil(): - when debugMem: + when debugMem: + if newSize == 0 and not p.isNil(): if oldSize > 1: echo &"DEBUG - MM: Deallocating {oldSize} bytes of memory" else: echo "DEBUG - MM: Deallocating 1 byte of memory" - elif (oldSize > 0 and not p.isNil() and newSize > oldSize) or oldSize == 0: + if (oldSize > 0 and not p.isNil() and newSize > oldSize) or oldSize == 0: when debugMem: if oldSize == 0: if newSize > 1: @@ -332,6 +332,9 @@ proc collect(self: var PeonVM) = let before = self.gc.bytesAllocated.current let time = getMonoTime().ticks().float() / 1_000_000 echo &"DEBUG - GC: Starting collection cycle at heap size {self.gc.bytesAllocated.current}" + echo &"DEBUG - GC: Total bytes allocated: {self.gc.bytesAllocated.total}" + echo &"DEBUG - GC: Tracked objects: {self.gc.pointers.len()}" + echo &"DEBUG - GC: Completed GC cycles: {self.gc.cycles}" inc(self.gc.cycles) self.trace(self.markRoots()) self.sweep() @@ -339,7 +342,9 @@ proc collect(self: var PeonVM) = when debugGC: echo &"DEBUG - GC: Collection cycle has terminated in {getMonoTime().ticks().float() / 1_000_000 - time:.2f} ms, collected {before - self.gc.bytesAllocated.current} bytes of memory in total" echo &"DEBUG - GC: Next cycle at {self.gc.nextGC} bytes" - + echo &"DEBUG - GC: Total bytes allocated: {self.gc.bytesAllocated.total}" + echo &"DEBUG - GC: Tracked objects: {self.gc.pointers.len()}" + echo &"DEBUG - GC: Completed GC cycles: {self.gc.cycles}" # Implementation of the peon VM diff --git a/src/config.nim b/src/config.nim index 03eb869..49e175f 100644 --- a/src/config.nim +++ b/src/config.nim @@ -26,7 +26,7 @@ const debugSerializer* {.booldefine.} = false # Validate the bytecode serialize const debugStressGC* {.booldefine.} = false # Make the GC run a collection at every allocation (VERY SLOW!) const PeonBytecodeMarker* = "PEON_BYTECODE" # Magic value at the beginning of bytecode files const HeapGrowFactor* = 2 # The growth factor used by the GC to schedule the next collection -const FirstGC* = 1024; # How many bytes to allocate before running the first GC +const FirstGC* = 1024 * 1024; # How many bytes to allocate before running the first GC const enableVMChecks* {.booldefine.} = true; # Enables all types of compiler (nim-wise) checks in the VM # List of paths where peon looks for modules, in order (empty path means current directory, which always takes precedence) const moduleLookupPaths*: seq[string] = @["", "src/peon/stdlib"] diff --git a/src/frontend/compiler.nim b/src/frontend/compiler.nim index 938678f..7876561 100644 --- a/src/frontend/compiler.nim +++ b/src/frontend/compiler.nim @@ -1172,7 +1172,6 @@ proc match(self: Compiler, name: string, kind: Type, node: ASTNode = nil, allowF msg = &"call to undefined function '{name}'" self.error(msg, node) elif impl.len() > 1: - # Forward declarations don't count when looking for a function impl = filterIt(impl, not it.valueType.forwarded and not it.valueType.isAuto) if impl.len() > 1: # If it's *still* more than one match, then it's an error @@ -1327,7 +1326,6 @@ proc beginScope(self: Compiler) = inc(self.depth) - proc patchForwardDeclarations(self: Compiler) = ## Patches forward declarations and looks ## for their implementations so that calls diff --git a/tests/fib.pn b/tests/fib.pn index d8041da..d562c0e 100644 --- a/tests/fib.pn +++ b/tests/fib.pn @@ -11,6 +11,6 @@ fn fib(n: int): int { print("Computing the value of fib(37)"); var x = clock(); -print(fib(33)); +print(fib(37)); print(clock() - x); print("Done!"); diff --git a/tests/generics.pn b/tests/generics.pn index addd178..f16b77b 100644 --- a/tests/generics.pn +++ b/tests/generics.pn @@ -7,6 +7,6 @@ fn sum[T: int | int32](a, b: T): T { } -print(sum(1, 2)); # Prints 3 -print(sum(1'i32, 2'i32)); # Also prints 3! +print(sum(1, 2) == 3); # true +print(sum(1'i32, 2'i32) == 3'i32); # true #print(sum(1.0, 2.0)); # Will fail to compile diff --git a/tests/nestedCalls.pn b/tests/nestedCalls.pn index 47c9a26..d52966b 100644 --- a/tests/nestedCalls.pn +++ b/tests/nestedCalls.pn @@ -18,5 +18,5 @@ fn outerTwo(n: int): int { } -print(outerTwo(5)); # 5 -#outer(); # 69420 \ No newline at end of file +print(outerTwo(5) == 5); # true +print(outer() == 69420); # 69420 \ No newline at end of file diff --git a/tests/operators.pn b/tests/operators.pn index ddc10f2..8d58fd0 100644 --- a/tests/operators.pn +++ b/tests/operators.pn @@ -7,4 +7,4 @@ operator `sum`(a, b: int): int { } -print(2 sum 2); # 4 \ No newline at end of file +print(2 sum 2 == 4); # 4 \ No newline at end of file