This commit is contained in:
Mattia Giambirtone 2022-11-04 15:33:07 +01:00
parent 1e29796278
commit 709b40341c
1 changed files with 4 additions and 3 deletions

View File

@ -162,7 +162,7 @@ template free*(self: var PeonVM, kind: typedesc, p: pointer): untyped =
proc allocate*(self: var PeonVM, kind: ObjectKind, size: typedesc, count: int): ptr HeapObject {.inline.} =
## Allocates aobject on the heap
## Allocates an object on the heap
result = cast[ptr HeapObject](self.reallocate(nil, 0, sizeof(HeapObject)))
result.marked = false
self.gc.bytesAllocated.total += sizeof(HeapObject)
@ -173,6 +173,8 @@ proc allocate*(self: var PeonVM, kind: ObjectKind, size: typedesc, count: int):
result.len = count
else:
discard # TODO
when debugAlloc:
echo &"DEBUG - GC: Allocated new object: {result[]}"
self.gc.bytesAllocated.current += sizeof(size) * count
self.gc.objects.add(result)
self.gc.pointers.incl(cast[uint64](result))
@ -618,8 +620,7 @@ proc constReadString(self: var PeonVM, size, idx: int): ptr HeapObject =
result = self.allocate(String, char, len(str))
for i, c in str:
result.str[i] = c
when debugAlloc:
echo &"DEBUG - GC: Allocated new object: {result[]}"
{.pop.}