Renamed 'scripts' directory to 'examples'

Also allowed assignment within conditionals
This commit is contained in:
2026-05-26 23:40:18 +10:00
parent bbb1e38649
commit 92e4a41662
14 changed files with 34 additions and 110 deletions
+12
View File
@@ -632,6 +632,12 @@ static unsigned int writeInstructionIfThenElse(Toy_Bytecode** mb, Toy_AstIfThenE
//cond-branch
writeBytecodeFromAst(mb, ast.condBranch);
//leave the assigned value on the stack when inside a condition
if (checkForChainedAssign(ast.condBranch)) {
Toy_AstVarAccess access = { .type = TOY_AST_VAR_ACCESS, .child = ast.condBranch->varAssign.target };
writeInstructionAccess(mb, access);
}
//emit the jump word (opcode, type, condition, padding)
EMIT_BYTE(mb, code, TOY_OPCODE_JUMP);
EMIT_BYTE(mb, code, TOY_OP_PARAM_JUMP_RELATIVE);
@@ -677,6 +683,12 @@ static unsigned int writeInstructionWhileThen(Toy_Bytecode** mb, Toy_AstWhileThe
//cond-branch
writeBytecodeFromAst(mb, ast.condBranch);
//leave the assigned value on the stack when inside a condition
if (checkForChainedAssign(ast.condBranch)) {
Toy_AstVarAccess access = { .type = TOY_AST_VAR_ACCESS, .child = ast.condBranch->varAssign.target };
writeInstructionAccess(mb, access);
}
//emit the jump word (opcode, type, condition, padding)
EMIT_BYTE(mb, code, TOY_OPCODE_JUMP);
EMIT_BYTE(mb, code, TOY_OP_PARAM_JUMP_RELATIVE);