diff --git a/src/backend/vm.nim b/src/backend/vm.nim index 494dcfb..63b7718 100644 --- a/src/backend/vm.nim +++ b/src/backend/vm.nim @@ -111,11 +111,6 @@ proc newPeonGC*: PeonGC = proc collect*(self: var PeonVM) -# Our pointer tagging routines -template tag(p: untyped): untyped = cast[pointer](cast[uint64](p) or (1'u64 shl 63'u64)) -template untag(p: untyped): untyped = cast[pointer](cast[uint64](p) and 0x7fffffffffffffff'u64) -template getTag(p: untyped): untyped = (p and (1'u64 shl 63'u64)) == 0 - proc reallocate*(self: var PeonVM, p: pointer, oldSize: int, newSize: int): pointer = ## Simple wrapper around realloc with @@ -147,7 +142,7 @@ proc reallocate*(self: var PeonVM, p: pointer, oldSize: int, newSize: int): poin else: if self.gc.bytesAllocated.current >= self.gc.nextGC: self.collect() - result = tag(realloc(untag(p), newSize)) + result = realloc(p, newSize) except NilAccessDefect: stderr.writeLine("Peon: could not manage memory, segmentation fault") quit(139) # For now, there's not much we can do if we can't get the memory we need, so we exit @@ -178,12 +173,12 @@ proc allocate(self: var PeonVM, kind: ObjectKind, size: typedesc, count: int): p ## Allocates an object on the heap and adds its ## location to the internal pointer list of the ## garbage collector - result = cast[ptr HeapObject](untag(self.reallocate(nil, 0, sizeof(HeapObject)))) + result = cast[ptr HeapObject](self.reallocate(nil, 0, sizeof(HeapObject))) setkind(result[], kind, kind) result.marked = false case kind: of String: - result.str = cast[ptr UncheckedArray[char]](untag(self.reallocate(nil, 0, sizeof(size) * count))) + result.str = cast[ptr UncheckedArray[char]](self.reallocate(nil, 0, sizeof(size) * count)) result.len = count else: discard # TODO @@ -228,13 +223,9 @@ proc markRoots(self: var PeonVM): HashSet[ptr HeapObject] = # This should resolve the potential memory leak (hopefully) var result = initHashSet[uint64](self.gc.pointers.len()) for obj in self.calls: - if not obj.getTag(): - continue if obj in self.gc.pointers: result.incl(obj) for obj in self.operands: - if not obj.getTag(): - continue if obj in self.gc.pointers: result.incl(obj) var obj: ptr HeapObject