Attempts at fixing GC issues
This commit is contained in:
parent
c1deebf43b
commit
55a112a1ab
|
@ -236,9 +236,9 @@ proc markRoots(self: var PeonVM): seq[ptr HeapObject] =
|
||||||
for p in live:
|
for p in live:
|
||||||
obj = cast[ptr HeapObject](p)
|
obj = cast[ptr HeapObject](p)
|
||||||
if obj.mark():
|
if obj.mark():
|
||||||
|
result.add(obj)
|
||||||
when debugGC:
|
when debugGC:
|
||||||
echo &"DEBUG - GC: Marked object: {obj[]}"
|
echo &"DEBUG - GC: Marked object: {obj[]}"
|
||||||
result.add(obj)
|
|
||||||
when debugGC:
|
when debugGC:
|
||||||
echo "DEBUG - GC: Mark phase complete"
|
echo "DEBUG - GC: Mark phase complete"
|
||||||
|
|
||||||
|
@ -380,7 +380,7 @@ proc getInf*(self: var PeonVM, positive: bool): uint64 =
|
||||||
proc getNan*(self: var PeonVM): uint64 = self.cache[5]
|
proc getNan*(self: var PeonVM): uint64 = self.cache[5]
|
||||||
|
|
||||||
|
|
||||||
# Thanks to nim's *genius* idea of making x !> y a template
|
# Thanks to nim's *genius* idea of making x > y a template
|
||||||
# for y < x (which by itself is fine) together with the fact
|
# for y < x (which by itself is fine) together with the fact
|
||||||
# that the order of evaluation of templates with the same
|
# that the order of evaluation of templates with the same
|
||||||
# expression is fucking stupid (see https://nim-lang.org/docs/manual.html#order-of-evaluation
|
# expression is fucking stupid (see https://nim-lang.org/docs/manual.html#order-of-evaluation
|
||||||
|
@ -659,7 +659,7 @@ when debugVM: # So nim shuts up
|
||||||
of "n", "next":
|
of "n", "next":
|
||||||
self.debugNext = true
|
self.debugNext = true
|
||||||
break
|
break
|
||||||
of "continue":
|
of "c", "continue":
|
||||||
self.debugNext = false
|
self.debugNext = false
|
||||||
break
|
break
|
||||||
of "s", "stack":
|
of "s", "stack":
|
||||||
|
|
|
@ -490,7 +490,7 @@ proc fixJumps(self: Compiler, oldLen: int, modifiedAt: int) =
|
||||||
proc resolve(self: Compiler, name: string): Name =
|
proc resolve(self: Compiler, name: string): Name =
|
||||||
## Traverses all existing namespaces and returns
|
## Traverses all existing namespaces and returns
|
||||||
## the first object with the given name. Returns
|
## the first object with the given name. Returns
|
||||||
## nil when the name can't be found. Note that,
|
## nil when the name can't be found. Note that
|
||||||
## when a declaration is first resolved, it is
|
## when a declaration is first resolved, it is
|
||||||
## also compiled on-the-fly
|
## also compiled on-the-fly
|
||||||
for obj in reversed(self.names):
|
for obj in reversed(self.names):
|
||||||
|
@ -516,20 +516,20 @@ proc resolve(self: Compiler, name: string): Name =
|
||||||
# C and D and module B imports module A, then B
|
# C and D and module B imports module A, then B
|
||||||
# might not want to also have access to C's and D's
|
# might not want to also have access to C's and D's
|
||||||
# names as they might clash with its own stuff)
|
# names as they might clash with its own stuff)
|
||||||
|
continue
|
||||||
result = obj
|
result = obj
|
||||||
break
|
break
|
||||||
if not result.isNil() and not result.resolved:
|
if not result.isNil() and not result.resolved:
|
||||||
# There's no reason to compile a declaration
|
# There's no reason to compile a declaration
|
||||||
# unless it is used at least once: this way
|
# unless it is used at least once: this way
|
||||||
# not only do we save space if a name is declared
|
# not only do we save space if a name is declared
|
||||||
# but never used, but it also makes it easier to
|
# but never used, it also makes it easier to
|
||||||
# implement generics. Yay!
|
# implement generics and lets us emit warnings for
|
||||||
|
# unused names once they go out of scope. Yay!
|
||||||
result.resolved = true
|
result.resolved = true
|
||||||
# Now we just dispatch to one of our functions to
|
# Now we just dispatch to one of our functions to
|
||||||
# compile the declaration
|
# compile the declaration
|
||||||
case result.kind:
|
case result.kind:
|
||||||
of NameKind.Var:
|
|
||||||
self.varDecl(VarDecl(result.node), result)
|
|
||||||
of NameKind.CustomType:
|
of NameKind.CustomType:
|
||||||
self.typeDecl(TypeDecl(result.node), result)
|
self.typeDecl(TypeDecl(result.node), result)
|
||||||
of NameKind.Function:
|
of NameKind.Function:
|
||||||
|
@ -587,8 +587,6 @@ proc getStackPos(self: Compiler, name: Name): int =
|
||||||
# we skip it and pretend it doesn't exist
|
# we skip it and pretend it doesn't exist
|
||||||
if variable.isPrivate or not variable.exported:
|
if variable.isPrivate or not variable.exported:
|
||||||
continue
|
continue
|
||||||
elif not variable.resolved:
|
|
||||||
dec(result)
|
|
||||||
elif name.ident == variable.ident:
|
elif name.ident == variable.ident:
|
||||||
# After all of these checks, we can
|
# After all of these checks, we can
|
||||||
# finally check whether the name of
|
# finally check whether the name of
|
||||||
|
@ -1251,7 +1249,7 @@ proc declareName(self: Compiler, node: ASTNode, mutable: bool = false): Name =
|
||||||
isPrivate: node.isPrivate,
|
isPrivate: node.isPrivate,
|
||||||
owner: self.currentModule,
|
owner: self.currentModule,
|
||||||
isConst: node.isConst,
|
isConst: node.isConst,
|
||||||
valueType: self.infer(node.value),
|
valueType: nil, # Done later
|
||||||
isLet: node.isLet,
|
isLet: node.isLet,
|
||||||
line: node.token.line,
|
line: node.token.line,
|
||||||
belongsTo: self.currentFunction,
|
belongsTo: self.currentFunction,
|
||||||
|
@ -2244,6 +2242,12 @@ proc declaration(self: Compiler, node: Declaration) =
|
||||||
case node.kind:
|
case node.kind:
|
||||||
of NodeKind.varDecl, NodeKind.funDecl, NodeKind.typeDecl:
|
of NodeKind.varDecl, NodeKind.funDecl, NodeKind.typeDecl:
|
||||||
self.dispatchPragmas(node, self.declareName(node))
|
self.dispatchPragmas(node, self.declareName(node))
|
||||||
|
if node.kind == NodeKind.varDecl:
|
||||||
|
self.names[^1].resolved = true
|
||||||
|
# We compile this immediately because we
|
||||||
|
# need to keep the stack in the right state
|
||||||
|
# at runtime
|
||||||
|
self.varDecl(VarDecl(node), self.names[^1])
|
||||||
else:
|
else:
|
||||||
self.statement(Statement(node))
|
self.statement(Statement(node))
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import std;
|
import std;
|
||||||
|
|
||||||
|
|
||||||
var x: uint64 = 100000'u64;
|
var x: uint64 = 1000000'u64;
|
||||||
var y = "just a test";
|
var y = "just a test";
|
||||||
print(y);
|
print(y);
|
||||||
print("Starting GC torture test");
|
print("Starting GC torture test");
|
||||||
|
|
Loading…
Reference in New Issue