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:
2026-04-17 23:43:30 +10:00
parent 5b101d763e
commit 2c92f829e1
5 changed files with 41 additions and 1 deletions

View File

@@ -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;