Minor fixes and changes
This commit is contained in:
parent
7ebd13f739
commit
01355fdaba
|
@ -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
|
||||
|
||||
|
|
|
@ -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"]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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!");
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -18,5 +18,5 @@ fn outerTwo(n: int): int {
|
|||
}
|
||||
|
||||
|
||||
print(outerTwo(5)); # 5
|
||||
#outer(); # 69420
|
||||
print(outerTwo(5) == 5); # true
|
||||
print(outer() == 69420); # 69420
|
|
@ -7,4 +7,4 @@ operator `sum`(a, b: int): int {
|
|||
}
|
||||
|
||||
|
||||
print(2 sum 2); # 4
|
||||
print(2 sum 2 == 4); # 4
|
Loading…
Reference in New Issue