Initial work on static name resolution

This commit is contained in:
Mattia Giambirtone 2022-04-21 15:58:33 +02:00
parent 79ca72d983
commit d38ad5aab4
2 changed files with 6 additions and 1 deletions

View File

@ -775,6 +775,11 @@ proc inferExprType(self: Compiler, node: ASTNode): ASTNode =
## Infers the type of a given expression and
## returns it
case node.kind:
of identExpr:
var node = IdentExpr(node)
if self.getStaticIndex(IdentExpr(node)) == -1:
self.error(&"reference to undeclared name '{node.token.lexeme}'")
# TODO: Find type of identifier
of unaryExpr:
return self.inferValueType(UnaryExpr(node).a)
of binaryExpr:

View File

@ -184,7 +184,7 @@ proc disassembleInstruction*(chunk: Chunk, offset: int): int =
proc disassembleChunk*(chunk: Chunk, name: string) =
## Takes a chunk of bytecode, and prints it
echo &"==== JAPL Bytecode Debugger - Chunk '{name}' ====\n"
echo &"==== Peon Bytecode Debugger - Chunk '{name}' ====\n"
var index = 0
while index < chunk.code.len:
index = disassembleInstruction(chunk, index)