Variables now persist between statements

This commit is contained in:
2022-08-13 21:27:39 +01:00
parent 633df5f376
commit e9ab6f3f96
5 changed files with 34 additions and 18 deletions

View File

@@ -44,17 +44,17 @@ Scope* popScope(Scope* scope) {
return ret;
}
#include <stdio.h>
//returns false if error
bool declareScopeVariable(Scope* scope, Literal key, Literal type) {
//store the type, for later checking on assignment
setLiteralDictionary(&scope->types, key, type);
//don't redefine a variable within this scope
if (existsLiteralDictionary(&scope->variables, key)) {
return false;
}
//store the type, for later checking on assignment
setLiteralDictionary(&scope->types, key, type);
setLiteralDictionary(&scope->variables, key, TO_NULL_LITERAL);
return true;
}