mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-20 01:04:08 +10:00
Fixed stack overflow caused by expression statements
This is a longstanding bug, so I'm glad its fixed, even if its only a bandaid. This does break some tests, but I'm too tired and these tests are out of date.
This commit is contained in:
@@ -1080,6 +1080,19 @@ static unsigned int writeInstructionFnInvoke(Toy_Bytecode** mb, Toy_AstFnInvoke
|
||||
return 0;
|
||||
}
|
||||
|
||||
static unsigned int writeInstructionStackPop(Toy_Bytecode** mb, Toy_AstStackPop ast) {
|
||||
unsigned int result = writeBytecodeFromAst(mb, ast.child);
|
||||
|
||||
//dead simple
|
||||
EMIT_BYTE(mb, code,TOY_OPCODE_ELIMINATE);
|
||||
EMIT_BYTE(mb, code, 0);
|
||||
EMIT_BYTE(mb, code, 0);
|
||||
EMIT_BYTE(mb, code, 0);
|
||||
|
||||
return result - 1;
|
||||
}
|
||||
|
||||
|
||||
static unsigned int writeBytecodeFromAst(Toy_Bytecode** mb, Toy_Ast* ast) {
|
||||
if (ast == NULL) {
|
||||
return 0;
|
||||
@@ -1198,6 +1211,10 @@ static unsigned int writeBytecodeFromAst(Toy_Bytecode** mb, Toy_Ast* ast) {
|
||||
result += writeInstructionFnInvoke(mb, ast->fnInvoke);
|
||||
break;
|
||||
|
||||
case TOY_AST_STACK_POP:
|
||||
result += writeInstructionStackPop(mb, ast->stackPop);
|
||||
break;
|
||||
|
||||
case TOY_AST_PASS:
|
||||
//NO-OP
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user