mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user