mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 23:04:08 +10:00
Some declaration guards
This commit is contained in:
@@ -311,6 +311,9 @@ static bool execVarDecl(Interpreter* interpreter, bool lng) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!setScopeVariable(interpreter->scope, identifier, parseIdentifierToValue(interpreter, popLiteralArray(&interpreter->stack)) )) {
|
if (!setScopeVariable(interpreter->scope, identifier, parseIdentifierToValue(interpreter, popLiteralArray(&interpreter->stack)) )) {
|
||||||
|
printf("Incorrect type assigned to variable \"");
|
||||||
|
printLiteral(identifier);
|
||||||
|
printf("\"\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,7 +331,19 @@ static bool execVarAssign(Interpreter* interpreter) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
setScopeVariable(interpreter->scope, lhs, rhs);
|
if (!isDelcaredScopeVariable(interpreter->scope, lhs)) {
|
||||||
|
printf("Undeclared variable \"");;
|
||||||
|
printLiteral(lhs);
|
||||||
|
printf("\"\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!setScopeVariable(interpreter->scope, lhs, rhs)) {
|
||||||
|
printf("Incorrect type assigned to variable \"");
|
||||||
|
printLiteral(lhs);
|
||||||
|
printf("\"\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -763,8 +763,10 @@ static void expressionStmt(Parser* parser, Node** nodeHandle) {
|
|||||||
Node* ptr = NULL;
|
Node* ptr = NULL;
|
||||||
expression(parser, &ptr);
|
expression(parser, &ptr);
|
||||||
|
|
||||||
**nodeHandle = *ptr;
|
if (ptr != NULL) {
|
||||||
FREE(Node, ptr); //BUGFIX: this thread of execution is nuts
|
**nodeHandle = *ptr;
|
||||||
|
FREE(Node, ptr); //BUGFIX: this thread of execution is nuts
|
||||||
|
}
|
||||||
|
|
||||||
consume(parser, TOKEN_SEMICOLON, "Expected ';' at the end of expression statement");
|
consume(parser, TOKEN_SEMICOLON, "Expected ';' at the end of expression statement");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,11 @@ bool declareScopeVariable(Scope* scope, Literal key, Literal type) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//return false if undefined
|
bool isDelcaredScopeVariable(Scope* scope, Literal key) {
|
||||||
|
return existsLiteralDictionary(&scope->variables, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
//return false if undefined, or can't be assigned
|
||||||
bool setScopeVariable(Scope* scope, Literal key, Literal value) {
|
bool setScopeVariable(Scope* scope, Literal key, Literal value) {
|
||||||
//dead end
|
//dead end
|
||||||
if (scope == NULL) {
|
if (scope == NULL) {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ Scope* popScope(Scope* scope);
|
|||||||
|
|
||||||
//returns false if error
|
//returns false if error
|
||||||
bool declareScopeVariable(Scope* scope, Literal key, Literal type);
|
bool declareScopeVariable(Scope* scope, Literal key, Literal type);
|
||||||
|
bool isDelcaredScopeVariable(Scope* scope, Literal key);
|
||||||
|
|
||||||
//return false if undefined
|
//return false if undefined
|
||||||
bool setScopeVariable(Scope* scope, Literal key, Literal value);
|
bool setScopeVariable(Scope* scope, Literal key, Literal value);
|
||||||
|
|||||||
Reference in New Issue
Block a user