Implemented assert keyword, read more

The assert keyword works, but I want to add a cmd option to suppress or
disable the errors.

The tests need some serious TLC. I know that, but I'm kicking it down
the road for now.
This commit is contained in:
2024-11-09 17:41:29 +11:00
parent 1925d41940
commit 1608a13b43
9 changed files with 189 additions and 71 deletions

View File

@@ -280,6 +280,22 @@ static unsigned int writeInstructionCompound(Toy_Routine** rt, Toy_AstCompound a
}
}
static unsigned int writeInstructionAssert(Toy_Routine** rt, Toy_AstAssert ast) {
//the thing to print
writeRoutineCode(rt, ast.child);
writeRoutineCode(rt, ast.message);
//output the print opcode
EMIT_BYTE(rt, code, TOY_OPCODE_ASSERT);
//4-byte alignment
EMIT_BYTE(rt, code, ast.message != NULL ? 2 : 1); //arg count
EMIT_BYTE(rt, code,0);
EMIT_BYTE(rt, code,0);
return 0;
}
static unsigned int writeInstructionPrint(Toy_Routine** rt, Toy_AstPrint ast) {
//the thing to print
writeRoutineCode(rt, ast.child);
@@ -504,6 +520,10 @@ static unsigned int writeRoutineCode(Toy_Routine** rt, Toy_Ast* ast) {
result += writeInstructionCompound(rt, ast->compound);
break;
case TOY_AST_ASSERT:
result += writeInstructionAssert(rt, ast->assert);
break;
case TOY_AST_PRINT:
result += writeInstructionPrint(rt, ast->print);
break;