From 1a36566cdc9431a8a8fb015b4a59820ff065252a Mon Sep 17 00:00:00 2001 From: Alex Bates Date: Mon, 17 Aug 2020 13:09:19 +0100 Subject: [PATCH] add ASSERT macro --- include/macros.h | 2 ++ src/code_e92d0_len_5da0.c | 25 +++++++------------------ 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/include/macros.h b/include/macros.h index 828154cb47..d1d69c4e34 100644 --- a/include/macros.h +++ b/include/macros.h @@ -7,4 +7,6 @@ #define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0])) #define ARRAY_COUNTU(arr) (u32)(sizeof(arr) / sizeof(arr[0])) +#define ASSERT(condition) if (!(condition)) { while (1) {} } + #endif diff --git a/src/code_e92d0_len_5da0.c b/src/code_e92d0_len_5da0.c index 5692d7ea45..ff1caa36c8 100644 --- a/src/code_e92d0_len_5da0.c +++ b/src/code_e92d0_len_5da0.c @@ -32,9 +32,7 @@ INCLUDE_ASM(code_e92d0_len_5da0, si_handle_Loop); INCLUDE_ASM(code_e92d0_len_5da0, si_handle_end_loop); s32 si_handle_break_loop(script_context* script) { - if (script->loopDepth < 0) { - while (1) {}; // todo INF_LOOP - } + ASSERT(script->loopDepth >= 0); script->ptrNextLine = si_goto_end_loop(script); script->loopDepth -= 1; return 2; @@ -98,9 +96,7 @@ s32 si_handle_switch(script_context* script) { bytecode value = get_variable(script, *script->ptrReadPos); s32 switchDepth = ++script->switchDepth; - if (switchDepth >= 8) { - while (1) {} - } + ASSERT(switchDepth < 8); script->switchBlockValue[switchDepth] = value; script->switchBlockState[switchDepth] = 1; @@ -111,9 +107,7 @@ s32 si_handle_switch_const(script_context* script) { bytecode value = *script->ptrReadPos; s32 switchDepth = ++script->switchDepth; - if (switchDepth >= 8) { - while (1) {} - } + ASSERT(switchDepth < 8); script->switchBlockValue[switchDepth] = value; script->switchBlockState[switchDepth] = 1; @@ -145,24 +139,19 @@ INCLUDE_ASM(code_e92d0_len_5da0, si_handle_case_equal_AND); INCLUDE_ASM(code_e92d0_len_5da0, si_handle_end_case_group); s32 si_handle_break_case(script_context* script) { - if (script->switchDepth < 0) { - while (1) {}; //todo INF_LOOP - } + ASSERT(script->switchDepth >= 0); script->ptrNextLine = si_goto_end_case(script); return 2; } s32 si_handle_end_switch(script_context* script) { s32 switchDepth = script->switchDepth; - - if (switchDepth < 0) { - inf_loop: goto inf_loop; // todo macro? how to do without label - } - script->switchBlockState[script->switchDepth] = 0; + ASSERT(switchDepth >= 0); + + script->switchBlockState[switchDepth] = 0; // here script->switchDepth -= 1; return 2; - } s32 si_handle_set_var(script_context* script) {