New tool gwbasic-compile translates tokenized .bas programs to C source, which gcc compiles into native executables linked against libgwrt.a (the interpreter's runtime modules minus the execution loop). Pipeline: .bas → gw_crunch() → analysis pass (line table, variable census, GOTO targets, DATA collection) → C codegen → gcc → native executable. Phase 1 supports: PRINT, LET, IF/THEN/ELSE, GOTO, GOSUB/RETURN, FOR/NEXT, END/STOP/SYSTEM, REM, DATA/READ/RESTORE, CLS, arithmetic/relational/logical operators, core math functions (SIN, COS, SQR, ABS, etc.), string functions (LEFT$, RIGHT$, MID$, CHR$, ASC, VAL, STR$, LEN, etc.), string concatenation. All control flow uses goto/labels (no C for/while) so GOTO into loops works. GOSUB uses a return-label stack with switch dispatch.
102 lines
2.1 KiB
CMake
102 lines
2.1 KiB
CMake
cmake_minimum_required(VERSION 3.10)
|
|
project(gw-basic-2026 C)
|
|
|
|
set(CMAKE_C_STANDARD 11)
|
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
|
|
|
# POSIX extensions (opendir, chdir, strcasecmp, etc.)
|
|
add_compile_definitions(_DEFAULT_SOURCE)
|
|
|
|
# Warnings
|
|
add_compile_options(-Wall -Wextra -Wno-unused-parameter)
|
|
|
|
# Include paths
|
|
include_directories(include)
|
|
|
|
# Optional PulseAudio support
|
|
include(FindPkgConfig)
|
|
pkg_check_modules(PULSEAUDIO libpulse-simple)
|
|
|
|
# Source files
|
|
set(SOURCES
|
|
src/main.c
|
|
src/tokens.c
|
|
src/tokenizer.c
|
|
src/error.c
|
|
src/eval.c
|
|
src/interp.c
|
|
src/vars.c
|
|
src/arrays.c
|
|
src/input.c
|
|
src/math_int.c
|
|
src/math_float.c
|
|
src/math_transcend.c
|
|
src/strings.c
|
|
src/print.c
|
|
src/fileio.c
|
|
src/program_io.c
|
|
src/print_using.c
|
|
src/graphics.c
|
|
src/virmem.c
|
|
src/portio.c
|
|
src/strpool.c
|
|
src/sound.c
|
|
src/tui.c
|
|
platform/hal_posix.c
|
|
)
|
|
|
|
add_executable(gwbasic ${SOURCES})
|
|
target_link_libraries(gwbasic m)
|
|
|
|
if(PULSEAUDIO_FOUND)
|
|
target_compile_definitions(gwbasic PRIVATE HAVE_PULSEAUDIO)
|
|
target_include_directories(gwbasic PRIVATE ${PULSEAUDIO_INCLUDE_DIRS})
|
|
target_link_libraries(gwbasic ${PULSEAUDIO_LIBRARIES} pthread)
|
|
endif()
|
|
|
|
# Runtime library for compiled BASIC programs
|
|
set(GWRT_SOURCES
|
|
src/tokens.c
|
|
src/tokenizer.c
|
|
src/error.c
|
|
src/eval.c
|
|
src/interp.c
|
|
src/vars.c
|
|
src/arrays.c
|
|
src/input.c
|
|
src/math_int.c
|
|
src/math_float.c
|
|
src/math_transcend.c
|
|
src/strings.c
|
|
src/print.c
|
|
src/fileio.c
|
|
src/program_io.c
|
|
src/print_using.c
|
|
src/graphics.c
|
|
src/virmem.c
|
|
src/portio.c
|
|
src/strpool.c
|
|
src/sound.c
|
|
src/tui.c
|
|
src/gwrt.c
|
|
platform/hal_posix.c
|
|
)
|
|
|
|
add_library(gwrt STATIC ${GWRT_SOURCES})
|
|
target_link_libraries(gwrt m)
|
|
if(PULSEAUDIO_FOUND)
|
|
target_compile_definitions(gwrt PRIVATE HAVE_PULSEAUDIO)
|
|
target_include_directories(gwrt PRIVATE ${PULSEAUDIO_INCLUDE_DIRS})
|
|
target_link_libraries(gwrt ${PULSEAUDIO_LIBRARIES} pthread)
|
|
endif()
|
|
|
|
# GW-BASIC compiler
|
|
add_executable(gwbasic-compile
|
|
src/compiler_main.c
|
|
src/analysis.c
|
|
src/codegen.c
|
|
src/tokens.c
|
|
src/tokenizer.c
|
|
)
|
|
target_link_libraries(gwbasic-compile m)
|