Fixed a bug with nested scopes

This commit is contained in:
Mattia Giambirtone 2022-07-31 16:40:47 +02:00
parent 33066d3b9b
commit b4628109ce
3 changed files with 6 additions and 6 deletions

View File

@ -377,17 +377,17 @@ proc getStackPos(self: Compiler, name: IdentExpr, depth: int = self.scopeDepth):
## Returns the predicted call stack position of a given name, relative
## to the current frame
var found = false
result = 2
for variable in self.names:
result = self.names.len()
for variable in reversed(self.names):
if variable.isFunDecl:
continue
inc(result)
dec(result)
if name.name.lexeme == variable.name.name.lexeme:
if variable.isPrivate and variable.owner != self.currentModule:
continue
else:
found = true
dec(result)
inc(result)
break
if not found:
return -1

View File

@ -193,7 +193,7 @@ proc runFile(f: string, interactive: bool = false, fromString: bool = false) =
serialized: Serialized
tokenizer = newLexer()
parser = newParser()
compiler = newCompiler()
compiler = newCompiler(replMode=true)
debugger {.used.} = newDebugger()
serializer = newSerializer()
vm = newPeonVM()

View File

@ -7,4 +7,4 @@ var x = 5;
}
x;
}
x;
x;