mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Store complex types in variables
This commit is contained in:
@@ -157,8 +157,15 @@ static int writeLiteralTypeToCache(LiteralArray* literalCache, Literal literal)
|
||||
static int writeLiteralToCompiler(Compiler* compiler, Literal literal) {
|
||||
//get the index
|
||||
int index = findLiteralIndex(&compiler->literalCache, literal);
|
||||
|
||||
if (index < 0) {
|
||||
index = pushLiteralArray(&compiler->literalCache, literal);
|
||||
if (IS_TYPE(literal)) {
|
||||
//check for the type literal as value
|
||||
index = writeLiteralTypeToCache(&compiler->literalCache, literal);
|
||||
}
|
||||
else {
|
||||
index = pushLiteralArray(&compiler->literalCache, literal);
|
||||
}
|
||||
}
|
||||
|
||||
//push the literal to the bytecode
|
||||
|
||||
@@ -1231,7 +1231,14 @@ static void varDecl(Parser* parser, Node** nodeHandle) {
|
||||
//variable definition is an expression
|
||||
Node* expressionNode = NULL;
|
||||
if (match(parser, TOKEN_ASSIGN)) {
|
||||
expression(parser, &expressionNode);
|
||||
//BUGFIX: if reading into a "type" variable, expect a type value
|
||||
if (AS_TYPE(typeLiteral).typeOf == LITERAL_TYPE) { //This may cause issues when reading function returns
|
||||
Literal val = readTypeToLiteral(parser);
|
||||
|
||||
emitNodeLiteral(&expressionNode, val);
|
||||
} else {
|
||||
expression(parser, &expressionNode);
|
||||
}
|
||||
}
|
||||
else {
|
||||
//values are null by default
|
||||
|
||||
Reference in New Issue
Block a user