Skip to content

Commit 3753d40

Browse files
tidy up debug
1 parent 3daef9e commit 3753d40

5 files changed

Lines changed: 16 additions & 24 deletions

File tree

include/basic.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
*/
2727
#pragma once
2828

29+
#define basic_debug if (debug) dprintf
30+
2931
#include "basic/defines.h"
3032
#include "basic/structs.h"
3133
#include "basic/context.h"

src/basic/flow_control.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
extern bool debug;
99

1010
bool conditional(struct basic_ctx* ctx) {
11-
if (debug) {
12-
dprintf("line %ld conditional\n", ctx->current_linenum);
13-
}
11+
basic_debug("line %ld conditional\n", ctx->current_linenum);
1412

1513
return up_conditional(ctx);
1614
}
@@ -80,22 +78,22 @@ void error_statement(struct basic_ctx* ctx)
8078

8179
void if_statement(struct basic_ctx* ctx)
8280
{
83-
if (debug) dprintf("line %ld if_statement\n", ctx->current_linenum);
81+
basic_debug("line %ld if_statement\n", ctx->current_linenum);
8482

8583
accept_or_return(IF, ctx);
8684
bool r = conditional(ctx);
8785
accept_or_return(THEN, ctx);
8886

8987
if (r) {
90-
if (debug) dprintf("conditional is true\n");
88+
basic_debug("conditional is true\n");
9189
if (tokenizer_token(ctx) == NEWLINE) {
9290
/* Multi-statement block IF */
9391
accept_or_return(NEWLINE, ctx);
9492
return;
9593
}
9694
statement(ctx);
9795
} else {
98-
if (debug) dprintf("conditional is false\n");
96+
basic_debug("conditional is false\n");
9997

10098
if (tokenizer_token(ctx) == NEWLINE) {
10199
/* --- multiline false-branch with nesting --- */

src/basic/function.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ void proc_statement(struct basic_ctx* ctx)
573573

574574
if (ctx->call_stack_ptr < MAX_CALL_STACK_DEPTH) {
575575
ctx->call_stack[ctx->call_stack_ptr] = tokenizer_num(ctx, NUMBER);
576-
if (debug) dprintf("PROC from %lu returning line %lu, PROC %s on line %lu\n", ctx->current_linenum, ctx->call_stack[ctx->call_stack_ptr], procname, def->line);
576+
basic_debug("PROC from %lu returning line %lu, PROC %s on line %lu\n", ctx->current_linenum, ctx->call_stack[ctx->call_stack_ptr], procname, def->line);
577577
ctx->call_stack_ptr++;
578578
jump_linenum(def->line, ctx);
579579
} else {
@@ -598,18 +598,18 @@ void def_statement(struct basic_ctx* ctx)
598598

599599
void eq_statement(struct basic_ctx* ctx)
600600
{
601-
if (debug) dprintf("eq_statement\n");
601+
basic_debug("eq_statement\n");
602602
accept_or_return(EQUALS, ctx);
603603

604604
if (ctx->fn_type == RT_STRING) {
605-
if (debug) dprintf("eq_statement return string\n");
605+
basic_debug("eq_statement return string\n");
606606
ctx->fn_return = (void*)str_expr(ctx);
607607
} else if (ctx->fn_type == RT_FLOAT) {
608-
if (debug) dprintf("eq_statement return double\n");
608+
basic_debug("eq_statement return double\n");
609609
double_expr(ctx, (void*)&ctx->fn_return);
610610
} else if (ctx->fn_type == RT_INT) {
611611
ctx->fn_return = (void*)expr(ctx);
612-
if (debug) dprintf("eq_statement return int %ld\n", (int64_t)ctx->fn_return);
612+
basic_debug("eq_statement return int %ld\n", (int64_t)ctx->fn_return);
613613
} else if (ctx->fn_type == RT_NONE) {
614614
tokenizer_error_print(ctx, "Can't return a value from a PROC");
615615
return;
@@ -642,7 +642,7 @@ void endproc_statement(struct basic_ctx* ctx)
642642

643643
ctx->if_nest_level = 0; // If we exit a proc, we clear the nest level
644644

645-
if (debug) dprintf("ENDPROC back to line %lu stack pos %lu\n", ctx->call_stack[ctx->call_stack_ptr], ctx->call_stack_ptr);
645+
basic_debug("ENDPROC back to line %lu stack pos %lu\n", ctx->call_stack[ctx->call_stack_ptr], ctx->call_stack_ptr);
646646
jump_linenum(ctx->call_stack[ctx->call_stack_ptr], ctx);
647647
} else {
648648
tokenizer_error_print(ctx, "ENDPROC when not inside PROC");

src/basic/main.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -638,9 +638,7 @@ void basic_run(struct basic_ctx *ctx) {
638638
(void) kgetc();
639639
tokenizer_error_print(ctx, "Escape");
640640
}
641-
if (debug) {
642-
dprintf("BASIC RUN\n");
643-
}
641+
basic_debug("BASIC RUN\n");
644642
line_statement(ctx);
645643
if (ctx->errored) {
646644
ctx->errored = false;

src/basic/statement.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ void statement(struct basic_ctx* ctx)
66
{
77
int token = tokenizer_token(ctx);
88

9-
if (debug) {
10-
dprintf("line %ld statement(%d)\n", ctx->current_linenum, token);
11-
}
9+
basic_debug("line %ld statement(%d)\n", ctx->current_linenum, token);
1210

1311
switch (token) {
1412
case REM:
@@ -171,18 +169,14 @@ void statement(struct basic_ctx* ctx)
171169

172170
void line_statement(struct basic_ctx* ctx)
173171
{
174-
if (debug) {
175-
dprintf("line_statement\n");
176-
}
172+
basic_debug("line_statement\n");
177173
if (tokenizer_token(ctx) == NEWLINE) {
178174
/* Empty line! */
179175
accept(NEWLINE, ctx);
180176
return;
181177
}
182178
int64_t line = tokenizer_num(ctx, NUMBER);
183-
if (debug) {
184-
dprintf("line_statement parsed line %ld\n", line);
185-
}
179+
basic_debug("line_statement parsed line %ld\n", line);
186180
if (line == 0) {
187181
return tokenizer_error_printf(ctx, "Missing line number after line %lu", ctx->current_linenum);
188182
}

0 commit comments

Comments
 (0)