Files
Eremey Valetov 89fe0fb0b3 Compiler: $EXTERN pragma for calling C functions from BASIC (Level 2 FFI) (#1)
Add a '$EXTERN NAME(ARGTYPES) AS RET pragma so compiled BASIC can call C
functions directly, the natural follow-up to Level 1 (--emit-obj /
--main-name). The pragma is an apostrophe comment, so the interpreter
ignores it while the compiler registers it.

Map INTEGER/SINGLE/DOUBLE/STRING to int16_t/float/double/const char* at the
boundary: a string argument crosses as a temporary C copy that is freed
after the call, and a string return is copied into the pool. The call name
is matched case-insensitively but emitted as the C symbol with the case
written in the pragma. Names are recognized before parse_var() truncates
identifiers to two significant characters, so multi-character C function
names work.

A string return that aliases a char* argument is copied before the argument
temporaries are freed, which avoids a use-after-free. Over-supplied
arguments are consumed without desyncing the token stream and warn on arity
mismatch.

Docs: getting-started.md "Foreign Functions from BASIC". Test:
tests/run_ffi_test.sh, wired into CI. 63/63 compiler, 72/72 interpreter,
68/68 compat still pass.

Also refile the roadmap "Next Up" backlog as git-bug issues and prune
docs/roadmap.md to point at git-bug as the source of truth for planned work.

Co-authored-by: Eremey Valetov <evvaletov@users.noreply.github.com>
2026-06-13 15:06:23 +03:00

105 lines
3.1 KiB
YAML

name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libpulse-dev || true
- name: Build
run: |
mkdir build
cd build
cmake ..
make -j$(nproc)
- name: Interpreter tests
run: bash tests/run_tests.sh
- name: Compiler tests
run: bash tests/run_compiler_tests.sh
- name: Cross-language (FFI) test
run: bash tests/run_ffi_test.sh
dos-cross-compile:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache OpenWatcom V2
id: cache-watcom
uses: actions/cache@v4
with:
path: ~/openwatcom-v2
key: openwatcom-v2-snapshot
- name: Install OpenWatcom V2
if: steps.cache-watcom.outputs.cache-hit != 'true'
run: |
mkdir -p ~/openwatcom-v2
curl -L -o /tmp/ow-snapshot.tar.xz \
https://github.com/open-watcom/open-watcom-v2/releases/download/Last-CI-build/ow-snapshot.tar.xz
tar -xJf /tmp/ow-snapshot.tar.xz -C ~/openwatcom-v2
rm -f /tmp/ow-snapshot.tar.xz
- name: Configure OpenWatcom env
run: |
# Generate the setvars.sh that build_dos.sh sources automatically.
# The cache step skips its creation step so this also runs on
# cache hits; -f overwrites without complaint.
cat > ~/openwatcom-v2/setvars.sh <<'EOF'
export WATCOM=$HOME/openwatcom-v2
export PATH=$WATCOM/binl64:$WATCOM/binl:$PATH
export EDPATH=$WATCOM/eddat
export INCLUDE=$WATCOM/h
EOF
chmod +x ~/openwatcom-v2/setvars.sh
# Also export to subsequent steps directly so a missing
# setvars.sh on a future runner doesn't silently break the build.
{
echo "WATCOM=$HOME/openwatcom-v2"
echo "EDPATH=$HOME/openwatcom-v2/eddat"
echo "INCLUDE=$HOME/openwatcom-v2/h"
} >> "$GITHUB_ENV"
echo "$HOME/openwatcom-v2/binl64" >> "$GITHUB_PATH"
echo "$HOME/openwatcom-v2/binl" >> "$GITHUB_PATH"
- name: Build 16-bit DOS target
run: |
./build_dos.sh 16
mkdir -p .ci-stash
cp gwbasic16.exe .ci-stash/
- name: Build 32-bit DOS target
run: |
./build_dos.sh clean
./build_dos.sh 32
cp gwbasic.exe .ci-stash/
- name: Verify binary sizes look sane
run: |
size16=$(stat -c%s .ci-stash/gwbasic16.exe)
size32=$(stat -c%s .ci-stash/gwbasic.exe)
echo "gwbasic16.exe = $size16 bytes"
echo "gwbasic.exe = $size32 bytes"
[ "$size16" -gt 80000 ] && [ "$size16" -lt 200000 ]
[ "$size32" -gt 100000 ] && [ "$size32" -lt 500000 ]
- name: Upload DOS artifacts
uses: actions/upload-artifact@v4
with:
name: dos-binaries
path: .ci-stash/*.exe