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 ## Returns the predicted call stack position of a given name, relative
## to the current frame ## to the current frame
var found = false var found = false
result = 2 result = self.names.len()
for variable in self.names: for variable in reversed(self.names):
if variable.isFunDecl: if variable.isFunDecl:
continue continue
inc(result) dec(result)
if name.name.lexeme == variable.name.name.lexeme: if name.name.lexeme == variable.name.name.lexeme:
if variable.isPrivate and variable.owner != self.currentModule: if variable.isPrivate and variable.owner != self.currentModule:
continue continue
else: else:
found = true found = true
dec(result) inc(result)
break break
if not found: if not found:
return -1 return -1

View File

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

View File

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