Add DEBUG compile option

This commit is contained in:
bʰedoh₂ swé 2024-06-19 05:53:46 +05:00
parent c4c1bd5fba
commit 92e7f2d95b
3 changed files with 8 additions and 6 deletions

View File

@ -5,5 +5,3 @@
#define MAX_LABELS 256
#define MAX_MODULES 256
#define MAX_BF_LOOPS 256
#define DEBUG_MODE 0

View File

@ -142,6 +142,10 @@ void execute(Stack *stack, Stack *originstack, char *modname)
for (; stack->program_counter < stack->program_size; stack->program_counter++)
{
#ifdef DEBUG
fprintf(stderr, "Inst: %s, IP: %d, Stack top: %d, Module: %s\n", NAME, stack->program_counter,
stack_peek(stack), modname);
#endif
prefix_operator(stack, NAME[0]);
if (NAME[0] == '#' || NAME[0] == '$')

View File

@ -44,10 +44,10 @@ uint16_t stack_peek(Stack *stack)
void kms(Stack *stack, const char *err)
{
if (DEBUG_MODE)
#ifdef DEBUG
for (int i = 0; i < stack->pointer; i++)
printf("%d: %d\n", i, stack->memory[i]);
#endif
fprintf(stderr, "%s", err);
free(stack);
exit(1);