Phase 2: variables, arrays, program execution, and control flow

Add variable storage (scalar and array), program line storage with
RUN/LIST/NEW, and full control flow: FOR/NEXT, GOTO, GOSUB/RETURN,
IF/THEN/ELSE, WHILE/WEND, ON GOTO/GOSUB, DATA/READ/RESTORE.

New modules: interp.c (1445 lines - execution loop and statement
dispatcher), vars.c, arrays.c, input.c. Version bumped to 0.2.0.
16 test programs pass including Leibniz pi and prime sieve.
This commit is contained in:
Eremey Valetov
2026-02-10 11:16:58 -05:00
parent d8e8375366
commit 616259537a
25 changed files with 2418 additions and 83 deletions
+42 -1
View File
@@ -24,9 +24,43 @@ typedef struct {
/* Default variable types for A-Z (DEFTBL) */
gw_valtype_t def_type[26];
/* Variable storage */
var_entry_t vars[256];
int var_count;
array_entry_t arrays[64];
int array_count;
int option_base;
/* Control flow stacks */
for_entry_t for_stack[16];
int for_sp;
gosub_entry_t gosub_stack[24];
int gosub_sp;
while_entry_t while_stack[16];
int while_sp;
/* DEF FN */
fn_def_t fn_defs[26];
/* Run state */
program_line_t *cur_line;
bool running;
/* CONT state */
uint8_t *cont_text;
program_line_t *cont_line;
/* DATA pointer */
uint8_t *data_ptr;
program_line_t *data_line_ptr;
uint16_t data_line;
/* Error trapping */
uint16_t on_error_line;
bool in_error_handler;
uint8_t *err_resume_text;
program_line_t *err_resume_line;
uint16_t err_line_num;
} interp_state_t;
extern interp_state_t gw;
@@ -35,8 +69,15 @@ extern interp_state_t gw;
#define LINE_DIRECT 65535
void gw_init(void);
void gw_exec_line(uint8_t *tokens);
void gw_exec_direct(const char *line);
void gw_exec_stmt(void);
void gw_run_loop(void);
/* Program storage */
void gw_store_line(uint16_t num, uint8_t *tokens, int len);
void gw_delete_line(uint16_t num);
program_line_t *gw_find_line(uint16_t num);
void gw_free_program(void);
/* CHRGET/CHRGOT - advance/peek the text pointer */
uint8_t gw_chrget(void);