Files
gw-basic-2026/include/gwrt.h
Eremey Valetov 0e0052f9cf Compiler: fix 16 of 18 compile errors — 32/72 tests passing
Fixes:
- Include graphics.h/virmem.h in gwrt.h (5 programs: draw_commands,
  get_put, graphics_stubs, peek_gfx, view_window)
- RND(n): discard argument to buffer instead of emitting it inline
- Float constant 0: emit "0.0f" not "0f" (invalid C suffix)
- MID$ function: proper 3-argument emission with optional length
- FOR/NEXT: use static variables instead of block scope for limit/step
  (fixes FOR inside IF/THEN and unmatched brace issues)
- RESUME/RESUME NEXT: handle as statements (not misparse as FOR/NEXT)
- ON TIMER/KEY/COM: skip event trap setup (not misparse as ON n GOTO)
- MID$ assignment: recognize and skip (don't misparse as variable)
- ERROR statement: emit gw_error() call
- ERASE: stub handler

Only 2 compile errors remain: bubble_sort (SWAP with arrays),
misc_stmts (ENVIRON$ variable name clash).

32 of 72 tests pass. New: datetime, luhn, peek_poke, error_handler,
on_timer, timer_stop, monte_carlo, number_guess.
2026-03-29 13:31:17 -04:00

63 lines
1.8 KiB
C

#ifndef GWRT_H
#define GWRT_H
/*
* Runtime library for compiled GW-BASIC programs.
*
* Provides initialization, DATA/READ support, GOSUB return-label stack,
* and convenience wrappers. Compiled programs link against libgwrt.a
* which contains all the existing interpreter modules except the
* execution loop.
*/
#include "gwbasic.h"
#include "strpool.h"
#include "portio.h"
#include "sound.h"
#include "graphics.h"
#include "virmem.h"
#include <setjmp.h>
/* Initialization / shutdown */
void gwrt_init(void);
void gwrt_shutdown(void);
/* DATA / READ / RESTORE */
void gwrt_data_set(const char **pool, const int *line_map, int line_count);
void gwrt_data_restore(int index);
const char *gwrt_data_read(void); /* returns next datum or errors ERR_OD */
/* GOSUB return-label stack */
#define GWRT_GOSUB_MAX 24
void gwrt_gosub_push(int label);
int gwrt_gosub_pop(void);
/* FOR/NEXT stack (for NEXT without variable matching) */
#define GWRT_FOR_MAX 16
/* Event checking (ON TIMER, ON KEY, Ctrl+Break) + string pool GC */
void gwrt_check_line(uint16_t line_num);
/* Error handling */
extern jmp_buf gwrt_error_jmp;
extern int gwrt_error_target; /* ON ERROR GOTO label, 0 = none */
extern int gwrt_resume_label; /* label for RESUME NEXT */
/* Array element access (wraps gw_array_element) */
gw_value_t *gwrt_array_elem(const char *name, int type, int ndims, int *subs);
/* DIM statement (wraps gw_stmt_dim via text_ptr) */
void gwrt_dim(const char *name, int type, int ndims, int *dims);
/* Print helpers (wrappers around existing print.c) */
void gwrt_print_sng(float v);
void gwrt_print_dbl(double v);
void gwrt_print_int(int16_t v);
void gwrt_print_str(gw_string_t s);
void gwrt_print_cstr(const char *s);
void gwrt_print_newline(void);
void gwrt_print_tab(void); /* comma zone */
void gwrt_print_spc(int n);
#endif