From a15e172c2ada518275ab01f8bbdbbfec621988d0 Mon Sep 17 00:00:00 2001 From: Tachikoma Date: Wed, 5 Aug 2026 23:26:15 -0400 Subject: [PATCH 1/2] Take libakerror 2.0.2, libakstdlib and libakgl 0.9.0 Bumps all three ak* submodules to their current main, applies what their upgrade notes require, and retires the two workarounds they make obsolete. libakerror 2.0.1 -> 2.0.2 (63 commits). Two of its fixes were this repository's own filed issues, and both workarounds are gone: - It namespaces its embedded `coverage` target now, the same CMAKE_SOURCE_DIR test it already applied to `mutation` (its issue #15). The add_custom_target() shadow that renamed it on the way past could only ever fire on a name the dependency has stopped using, so it is deleted rather than left as dead code. - It installs akerrorConfigVersion.cmake at SameMajorVersion (its issue #16). MAINTENANCE.md said to add a `1.0` floor to our find_dependency calls when this landed; the floor is now `2.0`, and we have no find_dependency calls to add it to, so the paragraph says that instead of an instruction nobody can follow. Its IGNORE context also changed shape: `__akerr_last_ignored` was an extern pointer, and is now a per-translation-unit `static akerr_last_ignored` holding a copy, so the pool slot can be released. Nothing here referenced the symbol, but it costs us 1.35 MiB of thread-local storage -- 38 TUs x 37,296 bytes, measured as the entire TLS segment of build/basic, where 2.0.1 produced no TLS segment at all -- plus 84 -Wunused-variable warnings. Filed upstream as libakerror issue #37 and recorded in MAINTENANCE.md rather than patched here, because patching a submodule forks it. libakstdlib gains directory and file-metadata wrappers with no version bump. aksl_snprintf keeps its `int *count` -- an intermediate commit removed it and the merge put it back -- but now reports the required length on truncation rather than 0. Every call site here reads it only after a successful return, so nothing moved. The directory wrappers close the gap DIRECTORY was refused for (libakstdlib issue #10). The verb is still unwritten, so it still refuses, but it no longer blames a wrapper that exists: the message is "DIRECTORY is not implemented yet" and tests/disk_verbs.c asserts both that it says so and that it does not name libakstdlib. What writing it would need is akbasic issue #55. libakgl moves to the current main at 0.9.0. It registers libccd and tg as submodules, so a tree that only ran `git submodule update --init --recursive` before the bump needs it again or the configure fails on a missing libccd/src/ccd/config.h.cmake.in. Verified: 114/114 default, 116/116 under -DAKBASIC_WITH_AKGL=ON, docs_examples green in both. libakerror's UPGRADING.md documents a 2.0.3 that project() never stamped, so the version tables read 2.0.2 -- libakerror issue #38. Co-Authored-By: Andrew Kesterson Co-Authored-By: Claude Code (Claude Opus 5, claude-opus-5[1m]) --- CMakeLists.txt | 22 +++---- MAINTENANCE.md | 117 +++++++++++++++++++++++++++++--------- README.md | 5 +- TODO.md | 6 +- deps/libakerror | 2 +- deps/libakgl | 2 +- deps/libakstdlib | 2 +- docs/09-files-and-disk.md | 2 +- docs/11-verb-reference.md | 2 +- docs/13-differences.md | 3 +- include/akbasic/error.h | 9 ++- src/runtime_disk.c | 21 ++++--- tests/disk_verbs.c | 12 +++- 13 files changed, 140 insertions(+), 65 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 85f9079..c65261a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,12 +51,14 @@ option(AKBASIC_SANITIZE "Build with ASan + UBSan" OFF # through: the dependencies set target and directory properties that their own # builds depend on. # -# libakerror additionally namespaces its `mutation` target when embedded but not -# its `coverage` target (deps/libakerror/CMakeLists.txt:194 vs :172), so a -# coverage build collides on the `coverage` target and fails to configure at all. -# Rename the dependency's on the way past. Remove this once libakerror applies -# the same CMAKE_SOURCE_DIR test to `coverage` that it already applies to -# `mutation` -- filed as libakerror issue #15. +# All three dependencies now namespace both their `coverage` and their +# `mutation` targets when embedded, so there is no custom-target collision left +# to work around. libakerror was the last holdout -- it namespaced `mutation` +# but not `coverage`, and a coverage build collided on the bare name and failed +# to configure at all. 2.0.2 applies the same CMAKE_SOURCE_DIR test to both +# (deps/libakerror/CMakeLists.txt:429-434), closing libakerror issue #15, and +# the add_custom_target() shadow that renamed it on the way past is gone with +# this comment. # # **Only one project in a tree may shadow add_test(), and this is that project.** # CMake exposes an overridden command as `_name` and chains exactly one level: a @@ -86,14 +88,6 @@ function(set_property _scope) endif() endfunction() -function(add_custom_target _name) - if(AKBASIC_SUPPRESS_ADD_TEST AND _name STREQUAL "coverage") - _add_custom_target(akerror_coverage ${ARGN}) - else() - _add_custom_target(${ARGV}) - endif() -endfunction() - add_subdirectory(deps/libakerror EXCLUDE_FROM_ALL) add_subdirectory(deps/libakstdlib EXCLUDE_FROM_ALL) if(AKBASIC_WITH_AKGL) diff --git a/MAINTENANCE.md b/MAINTENANCE.md index dd55a0e..c93c6f6 100644 --- a/MAINTENANCE.md +++ b/MAINTENANCE.md @@ -68,12 +68,19 @@ the `akgl_*` or `aksl_*` entry point should look like, and what tests would cove decision, which is true of *changing* it and not of *reporting* it. Follow the prose-paragraph style of the entries already there. Growing the dependency to serve the interpreter is a wanted outcome, not a detour. -It works. Four gaps were filed this way — text measurement, immediate-mode drawing, audio, -and a non-blocking keystroke read — and all four landed upstream as `akgl_text_measure`, the -`akgl_draw_*` family, `akgl_audio_*` and `akgl_controller_poll_key`. `FILTER` is the one verb -still blocked on a gap, and `DIRECTORY` is refused pending an `opendir`/`readdir` wrapper in -`libakstdlib`. Both refuse at execution and say so, rather than being silently ignored: a -program that asks for a low-pass filter and gets an unfiltered square wave has been lied to. +It works. **Five** gaps were filed this way and all five landed upstream: text measurement, +immediate-mode drawing, audio and a non-blocking keystroke read became `akgl_text_measure`, +the `akgl_draw_*` family, `akgl_audio_*` and `akgl_controller_poll_key`; and the +directory-reading wrapper `DIRECTORY` was waiting on became `aksl_opendir`, `aksl_readdir`, +`aksl_closedir` and `aksl_rewinddir` — `libakstdlib` issue #10, in the revision this tree +pins. + +That leaves the two refusals in different positions, and the difference is worth keeping +straight. **`FILTER` is the one verb still blocked on a gap** — there is no filter stage in +`akgl_audio_*` to configure. **`DIRECTORY` is no longer blocked on anything**; it is simply +unwritten, and its refusal says so rather than naming a wrapper that now exists. Both refuse +at execution and say so, rather than being silently ignored: a program that asks for a +low-pass filter and gets an unfiltered square wave has been lied to. ### The Go reference @@ -156,10 +163,10 @@ guards every dependency with `if(NOT TARGET ...)`, so a top-level build must def `akerror::akerror` and `akstdlib::akstdlib` from `deps/libakerror` and `deps/libakstdlib` **before** `add_subdirectory(deps/libakgl)`, or the targets are declared twice. -That order is load-bearing for a second reason: `deps/libakerror` is at **2.0.1**, whose 2.0.0 +That order is load-bearing for a second reason: `deps/libakerror` is at **2.0.2**, whose 2.0.0 was a source and ABI break carrying an soname (`libakerror.so.2`). `libakstdlib` and `libakgl` must be compiled against that header, not a 1.x one, and an installed `libakerror.so.1` must -not be picked up. The break is quiet if you get it wrong: `__akerr_last_ignored` became +not be picked up. The break is quiet if you get it wrong: the context behind `IGNORE` became thread-local and `akerr_next_error()` now returns a context that already holds a reference, so a mixed build leaks pool slots or frees one twice rather than failing to link. @@ -167,10 +174,47 @@ a mixed build leaks pool slots or frees one twice rather than failing to link. | Submodule | Version | soname | ABI rule | Version API | |---|---|---|---|---| -| `deps/libakerror` | 2.0.1 | `libakerror.so.2` | major only | **none** — no version macro; `include/akbasic/error.h` feature-tests `AKERR_THREAD_SAFE` and `AKERR_EXIT_STATUS_UNREPRESENTABLE` instead | +| `deps/libakerror` | 2.0.2 | `libakerror.so.2` | major only | **none** — no version macro; `include/akbasic/error.h` feature-tests `AKERR_THREAD_SAFE` and `AKERR_EXIT_STATUS_UNREPRESENTABLE` instead | | `deps/libakstdlib` | 0.2.0 | `libakstdlib.so.0.2` | **`MAJOR.MINOR` while major is 0** | `AKSL_VERSION_*`, `aksl_version()`, `AKSL_VERSION_CHECK()` | | `deps/libakgl` | 0.9.0 | `libakgl.so.0.9` | **`MAJOR.MINOR` while major is 0** | `AKGL_VERSION*`, `akgl_version()`, `AKGL_VERSION_AT_LEAST()` | +**The `libakerror` row is what `project(akerror VERSION ...)` declares, and it disagrees with +that library's own release notes**, which carry a "Release 2.0.3" section describing CI-only +changes. The version the build stamps into the soname and into +`akerrorConfigVersion.cmake` is 2.0.2; nothing consumers can observe says 2.0.3. Read the +table as the ABI and the notes as the changelog, and do not "correct" this row to 2.0.3 +without the upstream `project()` bump to go with it. Reported as `libakerror` issue #38. + +#### What 2.0.2's `IGNORE` change costs, measured + +`IGNORE` now takes a *copy* of the context so the pool slot can be released, which fixes a +real leak. The copy lives in the public header as a file-scope `static`: + +```c norun +static AKERR_THREAD_LOCAL akerr_ErrorContext akerr_last_ignored; +``` + +`static` means one per translation unit, and `AKERR_THREAD_LOCAL` means each one is +thread-local. `sizeof(akerr_ErrorContext)` is **37,296 bytes**, so: + +| Build | TLS segment of `build/basic` | +|---|---| +| libakerror 2.0.1 | none at all | +| libakerror 2.0.2 | 1,417,248 bytes — **1.35 MiB**, per thread | + +38 copies × 37,296 accounts for the segment exactly; `readelf -sW build/basic` shows all 38. +It scales with translation-unit count, not with anything about the program, and every thread +a host game spawns pays it again — which is worth knowing in a tree that spent a release +taking `akbasic_Runtime` from 10.75 MiB to 2.40 MiB. + +It also emits **84 `-Wunused-variable` warnings**, one per TU that includes `akerror.h` +without using `IGNORE`. Nothing here builds with `-Werror`, so it is noise rather than a +failure — but a consumer that does cannot include the header. + +**Both are `libakerror` issue #37 and neither is worked around here**, per the rule above: a +one-line `extern` in the header and a definition in `src/error.c` fixes it upstream, and +patching our copy would fork the submodule. Delete this subsection when it lands. + For both 0.x libraries the soname carries `MAJOR.MINOR` deliberately: 0.1 and 0.2 are *different* ABIs, and both become major-only at 1.0. Do not read `0.1 → 0.2` as a compatible bump — both libraries have actually made that jump, so anything built against the 0.1 headers @@ -196,16 +240,32 @@ precedes the build tree on the include path and a stray copy there would shadow one and pin every consumer. It publishes `AKGL_VERSION_AT_LEAST(major, minor, patch)` — the compile-time test `libakstdlib` could not write against `libakerror` — and `akgl_version()`. -**Version-pinning in `find_package` is asymmetric, and that is deliberate.** +**Version-pinning in `find_package` used to be asymmetric. It no longer is.** `find_package(akstdlib 0.1)` and `find_package(akgl 0.1)` both work; each ships a -`ConfigVersion.cmake` at `SameMinorVersion`, mirroring its soname. `find_package(akerror 1.0)` -**fails against a correct install**, because `libakerror` ships `akerrorConfig.cmake` and -`akerrorTargets.cmake` but no `akerrorConfigVersion.cmake`. Ask for `akerror` unversioned. Its -floor is enforced instead by an `#error` feature-testing `AKERR_FIRST_CONSUMER_STATUS`, which -`akstdlib.h`, `akgl/error.h` and our own `include/akbasic/error.h` all carry — include any of -them and you inherit the guard. The missing version file is filed in -`libakstdlib` issue #5 and `libakerror` issue #16; when it lands, add the `1.0` floor to the `find_dependency` -calls. +`ConfigVersion.cmake` at `SameMinorVersion`, mirroring its soname. `libakerror` shipped +`akerrorConfig.cmake` and `akerrorTargets.cmake` but no `akerrorConfigVersion.cmake`, so any +versioned request failed against a correct install and the advice here was to ask for +`akerror` unversioned. That was `libakerror` issue #16 — closed — and `libakstdlib` issue #5, +which tracks the same fix from the other side and is still open only because nobody has shut +it. It has landed: `libakerror` now writes `akerrorConfigVersion.cmake` at +**`SameMajorVersion`**, matching the soname's major-only rule, rather than the +`SameMinorVersion` the other two use to match theirs. + +Two things follow, and the second is the one that bites: + +- **A versioned request now works** — but the floor to ask for is **`2.0`**, not the `1.0` + this file used to say. `find_package(akerror 1.0)` fails *harder* than before: it is a + request for major 1 against a major-2 install, which `SameMajorVersion` correctly rejects. +- **There is nothing in this repository to change.** `akbasic` reaches all three dependencies + by `add_subdirectory`, not `find_package`, and ships no CMake package config of its own — + so it has no `find_dependency` calls to add a floor to. The instruction that used to live + here was written for a consumer this project never became. It matters to anyone *installing* + these libraries and linking `akbasic` against the installed copies, which is why it is + recorded rather than deleted. + +The compile-time floor is unchanged and still the real guard: an `#error` feature-testing +`AKERR_FIRST_CONSUMER_STATUS`, which `akstdlib.h`, `akgl/error.h` and our own +`include/akbasic/error.h` all carry — include any of them and you inherit it. ### Embedding all three dependencies collides four ways @@ -250,14 +310,19 @@ CTest names. `libakstdlib` still uses bare `test_` targets. **Name every t this repo `akbasic_test_`** — it costs nothing and it is the collision that actually stopped a build. -**3. Duplicate custom targets.** `libakerror` namespaces its `mutation` target when embedded -but **not** its `coverage` target, so any coverage-enabled top-level build fails with *"another -target with the same name already exists"*. We shadow `add_custom_target` and rename that one -to `akerror_coverage` on the way past. `libakstdlib` (both targets) and `libakgl` (its -`mutation` target) namespace themselves correctly. **The real fix is upstream in -`libakerror`** — the same `CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR` test it already -applies to `mutation` — and it is filed as `libakerror` issue #15. Delete the -workaround when it lands. +**3. Duplicate custom targets — fixed upstream, and the workaround is gone.** `libakerror` +used to namespace its `mutation` target when embedded but **not** its `coverage` target, so +any coverage-enabled top-level build failed with *"another target with the same name already +exists"*. This project shadowed `add_custom_target` and renamed that one to +`akerror_coverage` on the way past, and recorded the real fix as `libakerror` issue #15: the +same `CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR` test it already applied to +`mutation`. + +That landed in 2.0.2. `libakerror` now picks `akerror_coverage` itself when embedded, so the +shadow was dead code that could only ever fire on a name the dependency had stopped using — +and it is deleted. All three dependencies namespace both targets correctly now, so **there is +no custom-target collision left**; only collisions 1, 2 and 4 below are live. The heading says +four because four is what a reader coming from the issue tracker will be looking for. **4. Stale build trees poison the coverage report.** See below; it is the reason for `cmake -S . -B build`. diff --git a/README.md b/README.md index d571cfc..5ab5fc8 100644 --- a/README.md +++ b/README.md @@ -138,12 +138,13 @@ API documentation builds with `doxygen Doxyfile`, into `build/docs/html`. Everything is a submodule; `git submodule update --init --recursive` gets all of it. There is nothing to install first. -* [libakerror](https://source.starfort.tech/andrew/libakerror) 2.0.1 — TRY/CATCH-style error +* [libakerror](https://source.starfort.tech/andrew/libakerror) 2.0.2 — TRY/CATCH-style error contexts. Every function that can fail returns one. 2.0.0 made it thread safe and broke the ABI; anything built against a 1.x header must be rebuilt rather than relinked. * [libakstdlib](https://source.starfort.tech/andrew/libakstdlib) 0.2.0 — libc wrappers that report through `libakerror`. String-to-number conversion goes straight to it, which is why - `VAL("garbage")` is an error rather than a silent `0`. + `VAL("garbage")` is an error rather than a silent `0`. Its public header now also pulls in + `` and `` for the directory and file-metadata wrappers. * [libakgl](https://source.starfort.tech/andrew/libakgl) 0.9.0 — **optional**, only for `-DAKBASIC_WITH_AKGL=ON`. Pulls in SDL3. Its soname carries `MAJOR.MINOR` while the major is 0, so rebuild rather than relink. diff --git a/TODO.md b/TODO.md index 8b2a855..fb96df9 100644 --- a/TODO.md +++ b/TODO.md @@ -2339,9 +2339,9 @@ Dependency baseline: | Submodule | Version | Notes | |---|---|---| -| `deps/libakerror` | 2.0.1 | Private ownership-enforced status registry. akbasic reserves 512–767 in `akbasic_error_register()`. Does not namespace its `coverage` target when embedded — worked around in our `CMakeLists.txt`. **2.0.0 is thread safe and an ABI break** (`libakerror.so.2`): `__akerr_last_ignored` is thread-local and `akerr_next_error()` returns an owned reference, neither of which fails to link when mismatched. **2.0.1 fixes an exit status that mattered more to this band than to any other** — see below. | -| `deps/libakstdlib` | 0.2.0 | soname `libakstdlib.so.0.2`. `AKSL_VERSION_CHECK()` asserted in `tests/version_check.c`. This release fixed all six confirmed defects the port was working around — see §1.9, where the bans are now lifted. | -| `deps/libakgl` | 0.7.0 | soname `libakgl.so.0.7`. Owns status codes 256–260. Linked and tested under `-DAKBASIC_WITH_AKGL=ON`, which still defaults OFF so the core library and its whole suite build on a machine with no SDL. **0.3.0 closed every API gap this port had filed** — see §7 — so the four workarounds §3 used to list are gone. 0.4.0 was a leak-and-overread release that changed no public struct. **0.5.0 is the first that broke our source as well as our ABI**: it namespaced every exported symbol, so `akgl_render_bind2d` is `akgl_render_2d_bind`, `akgl_sprite_sheet_coords_for_frame` is `akgl_spritesheet_coords_for_frame`, the `renderer`/`camera`/`window` globals carry the prefix, and `_akgl_renderer`/`_akgl_camera` are `akgl_default_renderer`/`akgl_default_camera`. `include/akbasic/akgl.h` asserts the floor. **0.6.0 and 0.7.0 broke nothing here** — 0.6.0 is three arcade-physics fixes and a `physics.max_timestep` property this port does not use, and 0.7.0 reports failures `libakstdlib`'s wrappers were already catching and takes `libakerror` 2.0.1. The floor moved anyway, because deciding for ourselves which of libakgl's minor releases were really compatible is the judgement the soname exists to take away. | +| `deps/libakerror` | 2.0.2 | Private ownership-enforced status registry. akbasic reserves 512–767 in `akbasic_error_register()`. **2.0.0 is thread safe and an ABI break** (`libakerror.so.2`): the `IGNORE` context is thread-local and `akerr_next_error()` returns an owned reference, neither of which fails to link when mismatched. **2.0.1 fixes an exit status that mattered more to this band than to any other** — see below. **2.0.2** namespaces its embedded `coverage` target (issue #15 — our `add_custom_target` shadow is deleted), installs `akerrorConfigVersion.cmake` at `SameMajorVersion` (issue #16), fixes the `AKERR_USE_STDLIB=OFF` build, retires `PATH_MAX` for `AKERR_MAX_ERROR_FNAME_LENGTH`, and turns the `IGNORE` slot into a released copy — `__akerr_last_ignored` was an `extern` pointer and is now a per-TU `static akerr_last_ignored`. **That last one costs us 1.35 MiB of thread-local storage**: 38 translation units x 37,296 bytes, measured as the whole TLS segment of `build/basic`, where 2.0.1 produced no TLS segment at all. Filed upstream as libakerror issue #37, along with the 84 `-Wunused-variable` warnings it emits. Its `UPGRADING.md` describes a 2.0.3 that `project()` never stamped — libakerror issue #38, which is why the version above reads 2.0.2. | +| `deps/libakstdlib` | 0.2.0 | soname `libakstdlib.so.0.2`. `AKSL_VERSION_CHECK()` asserted in `tests/version_check.c`. This release fixed all six confirmed defects the port was working around — see §1.9, where the bans are now lifted. Since then, and with no version bump: **directory wrappers landed** (`aksl_opendir`/`readdir`/`closedir`/`rewinddir`, issue #10) — the gap `DIRECTORY` was refused for, so that refusal now says only that the verb is unwritten; file-metadata wrappers landed; and `aksl_snprintf` keeps its `int *count` but now reports the *required* length on truncation rather than 0. Only read on success here, so nothing moved. | +| `deps/libakgl` | 0.9.0 | soname `libakgl.so.0.9`. Owns status codes 256–262. Linked and tested under `-DAKBASIC_WITH_AKGL=ON`, which still defaults OFF so the core library and its whole suite build on a machine with no SDL. **0.3.0 closed every API gap this port had filed** — see §7 — so the four workarounds §3 used to list are gone. 0.4.0 was a leak-and-overread release that changed no public struct. **0.5.0 is the first that broke our source as well as our ABI**: it namespaced every exported symbol, so `akgl_render_bind2d` is `akgl_render_2d_bind`, `akgl_sprite_sheet_coords_for_frame` is `akgl_spritesheet_coords_for_frame`, the `renderer`/`camera`/`window` globals carry the prefix, and `_akgl_renderer`/`_akgl_camera` are `akgl_default_renderer`/`akgl_default_camera`. `include/akbasic/akgl.h` asserts the floor. **0.6.0 and 0.7.0 broke nothing here** — 0.6.0 is three arcade-physics fixes and a `physics.max_timestep` property this port does not use, and 0.7.0 reports failures `libakstdlib`'s wrappers were already catching and takes `libakerror` 2.0.1. **0.8.0 and 0.9.0 broke nothing here either** — 0.8.0 is the collision subsystem (`AKGL_ERR_COLLISION`, code 261, and the vendored `libccd` and `tg` submodules that come with it), and 0.9.0 is the `akgl_ui` subsystem (`AKGL_ERR_UI`, code 262, and vendored `clay`), which is what `src/ui_akgl.c` draws through. Both widen libakgl's reserved band from five codes to seven; the range map in `MAINTENANCE.md` carries it. The floor moved anyway, because deciding for ourselves which of libakgl's minor releases were really compatible is the judgement the soname exists to take away. **Note `deps/libakgl/deps/` pins its own `libakerror` and `libakstdlib` older than ours**; the top-level build declares both targets first and libakgl's `if(NOT TARGET ...)` guards mean its copies are never configured, so what libakgl actually compiles against is what this tree pins. | **An unhandled error in this band used to exit zero, and 512 is the worst possible base for that.** `libakerror`'s default unhandled-error handler ended in `exit(errctx->status)`, and a diff --git a/deps/libakerror b/deps/libakerror index 5eaa956..ee38eed 160000 --- a/deps/libakerror +++ b/deps/libakerror @@ -1 +1 @@ -Subproject commit 5eaa956f504611a08204dcaf288e1ad1a571ee21 +Subproject commit ee38eed31c0c0733233676a289d9c6dd9a19aa9d diff --git a/deps/libakgl b/deps/libakgl index bbb7b8f..77091ed 160000 --- a/deps/libakgl +++ b/deps/libakgl @@ -1 +1 @@ -Subproject commit bbb7b8f494d7784f88e33280f2ea740e3608204f +Subproject commit 77091ed177cf322c09e1116edaf4b1e3bbad5a57 diff --git a/deps/libakstdlib b/deps/libakstdlib index 2b79aca..821200e 160000 --- a/deps/libakstdlib +++ b/deps/libakstdlib @@ -1 +1 @@ -Subproject commit 2b79aca103d46f4ea4165172f5dc7f7c8dbaba75 +Subproject commit 821200e618153432ae1bae8a20a7cd9e2b66650d diff --git a/docs/09-files-and-disk.md b/docs/09-files-and-disk.md index c16e9e5..f3dba3b 100644 --- a/docs/09-files-and-disk.md +++ b/docs/09-files-and-disk.md @@ -126,7 +126,7 @@ exists, and reading into one you never sized writes over something else. | `COLLECT` | validates a disk's block allocation map. There is no map | | `BACKUP` | duplicates one disk onto another. There are no disks | | `BOOT` | loads and runs a boot sector. There is no boot sector | -| `DIRECTORY` / `CATALOG` | needs a directory-reading wrapper the standard library does not have yet. Filed upstream | +| `DIRECTORY` / `CATALOG` | not written yet. It was blocked on a directory-reading wrapper in the standard library; that landed, so only the verb is outstanding | `DCLEAR` is the exception among the drive verbs: resetting a drive also closes its channels, and closing the channels is real, so that is what it does. diff --git a/docs/11-verb-reference.md b/docs/11-verb-reference.md index 3e610ad..084d91d 100644 --- a/docs/11-verb-reference.md +++ b/docs/11-verb-reference.md @@ -35,7 +35,7 @@ for the reasoning in each case. | `DIALOG` | `DIALOG ["text"]` | Show a text panel across the bottom of the screen. No argument takes it down. See Chapter 19. | | `DIM` | `DIM A#(n [,...])` | Make an array. Subscripts start at zero; `n` is the count. | | `DIM` … `AS` | `DIM S@ AS T`, `DIM P@ AS PTR TO T` | Make a structure, or a strict pointer to one. See Chapter 16. | -| `DIRECTORY` | `DIRECTORY` | **Refused.** Needs a directory-reading wrapper that does not exist yet. | +| `DIRECTORY` | `DIRECTORY` | **Refused.** Not written yet; the standard-library wrapper it waited on has landed. | | `DLOAD` | `DLOAD "name"` | Load a program from a file. | | `DO` | `DO [WHILE c | UNTIL c]` | Start a loop. The condition may be here, on the `LOOP`, or neither. | | `DOPEN` | `DOPEN n, "name" [,W]` | Open a file on channel `n`. `W` opens it for writing. | diff --git a/docs/13-differences.md b/docs/13-differences.md index 4765c6b..33e58c6 100644 --- a/docs/13-differences.md +++ b/docs/13-differences.md @@ -199,7 +199,8 @@ interpreter's error code, which bears no relation to a Commodore error number. P - **`BLOAD` requires a length.** - **`HEADER`, `COLLECT`, `BACKUP` and `BOOT` are refused.** They operate on a physical disk. -- **`DIRECTORY` is refused** pending a wrapper in the standard library. +- **`DIRECTORY` is refused** because it is not written yet. The standard-library + wrapper it was waiting on has landed, so the remaining work is the verb. ## Machine diff --git a/include/akbasic/error.h b/include/akbasic/error.h index 2dc42d0..e181e08 100644 --- a/include/akbasic/error.h +++ b/include/akbasic/error.h @@ -12,9 +12,12 @@ * libakerror 2.0.0 is the floor, raised from 1.0.0 because 2.0.0 is an ABI break * that a compile against the wrong header cannot survive quietly: * - * - `__akerr_last_ignored` became thread-local. `IGNORE` expands at *our* call - * site, so our objects reference that symbol under whichever storage model - * the header on the include path declared. + * - The context behind `IGNORE` became thread-local. `IGNORE` expands at *our* + * call site, so our objects reference that storage under whichever model the + * header on the include path declared. 2.0.2 went further and made it a + * per-translation-unit `static` snapshot named `akerr_last_ignored`, copied + * from the pool slot so the slot can be released; the old spelling + * `__akerr_last_ignored` was an `extern` pointer and no longer exists. * - `akerr_next_error()` now returns a context that already holds a reference, * and `ENSURE_ERROR_READY` no longer increments. Objects compiled against a * 1.x header count every reference twice and never give a slot back. diff --git a/src/runtime_disk.c b/src/runtime_disk.c index 2abea6e..33565a1 100644 --- a/src/runtime_disk.c +++ b/src/runtime_disk.c @@ -407,17 +407,22 @@ akerr_ErrorContext *akbasic_cmd_directory(akbasic_Runtime *obj, akbasic_ASTLeaf FAIL_ZERO_RETURN(errctx, (obj != NULL && dest != NULL), AKERR_NULLPOINTER, "NULL argument in DIRECTORY"); /* - * Refused rather than half-built. Listing a directory needs opendir/readdir, - * which `libakstdlib` does not wrap -- and this project's rule is that a - * missing capability gets filed upstream rather than worked around here - * (MAINTENANCE.md). Filed as libakstdlib issue #10. + * Refused rather than half-built. This was blocked upstream: listing a + * directory needs opendir/readdir, `libakstdlib` did not wrap them, and + * this project's rule is that a missing capability gets filed upstream + * rather than worked around here (MAINTENANCE.md). That was libakstdlib + * issue #10, and it landed -- aksl_opendir, aksl_readdir, aksl_closedir + * and aksl_rewinddir all exist as of the revision this tree pins. * - * The alternative was shelling out to `ls`, which a library has no business - * doing, or calling readdir directly and stepping outside the error - * convention every other call in this file follows. + * So the blocker is gone and only the work is left. Writing the verb needs + * decisions this commit is not the place for: what a listing looks like on + * a filesystem with no disk-image block counts, which of the Commodore + * wildcard forms to honour, and where the entries go. Tracked as akbasic + * issue #55; the refusal stays honest until then rather than growing a + * half-listing nobody specified. */ FAIL_RETURN(errctx, AKBASIC_ERR_DEVICE, - "DIRECTORY is not implemented: libakstdlib has no directory-reading wrapper yet"); + "DIRECTORY is not implemented yet"); } /* ------------------------------------------------------------ BSAVE/BLOAD -- */ diff --git a/tests/disk_verbs.c b/tests/disk_verbs.c index f8e3ac7..e74535a 100644 --- a/tests/disk_verbs.c +++ b/tests/disk_verbs.c @@ -244,10 +244,16 @@ static void test_no_drive_verbs(void) harness_stop(); } - /* DIRECTORY is refused for a different reason, and says which. */ + /* + * DIRECTORY is refused for a different reason than the five above: not for + * want of a drive, but because it is unwritten. It used to name the missing + * libakstdlib wrapper; that wrapper landed, so naming it would be a lie. + */ TEST_REQUIRE_OK(run_program("10 DIRECTORY\n")); - TEST_REQUIRE(strstr(HARNESS_OUTPUT, "libakstdlib") != NULL, - "DIRECTORY should name the missing wrapper, got \"%s\"", HARNESS_OUTPUT); + TEST_REQUIRE(strstr(HARNESS_OUTPUT, "not implemented") != NULL, + "DIRECTORY should say it is unwritten, got \"%s\"", HARNESS_OUTPUT); + TEST_REQUIRE(strstr(HARNESS_OUTPUT, "libakstdlib") == NULL, + "DIRECTORY must not still blame libakstdlib, got \"%s\"", HARNESS_OUTPUT); harness_stop(); } -- 2.43.0 From 13f1df03ef5b32425c497154fd0a1de4e4ecc454 Mon Sep 17 00:00:00 2001 From: Tachikoma Date: Wed, 5 Aug 2026 23:26:33 -0400 Subject: [PATCH 2/2] Unbreak the three example programs the RND merge left behind Adding native RND and ASC (ae2c702) made RND a function name, and a suffixed identifier that collides with one is refused -- "SYNTAX ERROR Reserved word in variable name". Three example programs held their PRNG output in a variable called RND#, or a host field called RND%, and none of them had run since: - examples/galaga/ bound RND% as a host field on both ENEMY and GAME. The BASIC-visible name is ROLL% now; the C member stays `rnd`. This one was caught by example_galaga and example_galaga_interop, which have been failing. - examples/breakout/characters/breakout.bas and examples/megademo/ megademo.bas both use RND# for their LCG output, renamed to ROLL#. Neither is in any test, so neither failure was visible. examples/breakout/sprites/breakout.bas was broken a second way: seven REM lines the reader refuses. Worth recording that the ceiling is not the one the message names -- src/sink_stdio.c fails when the read filled the buffer without seeing a terminator, so with AKBASIC_MAX_LINE_LENGTH at 80 the message says "79 character limit" and the real maximum is 78, because a 79-character line leaves no room for the newline. The sweeps that fixed the corpus and the megademo for this did not reach this file. The seven comments are reflowed. The prose went stale with the code. Chapter 21 said "there is no RND verb in this dialect; issue #16 tracks adding one", chapter 17's historical aside offered an LCG that no longer parses, and four REM blocks across the two games said the same thing. All of them now say RND exists, and say why these programs keep their own generator anyway: the sequence has to be reproducible for a headless run to be the same game on every machine, which is what lets interop_test.c assert exact counts. Chapter 21 also gains the rule that bit them, since a reader writing a host type will hit it: a host field name is a bare word and shares a namespace with every verb and function. None of this came from the submodule bump -- all three were already broken on main. It was found by running the tutorial games, which nothing else does; that gap is akbasic issue #58. Verified: all three run clean under the dummy drivers, and 114/114 default, 116/116 with akgl. Co-Authored-By: Andrew Kesterson Co-Authored-By: Claude Code (Claude Opus 5, claude-opus-5[1m]) --- docs/17-tutorial-breakout.md | 6 ++-- docs/21-tutorial-galaga-enemies.md | 37 +++++++++++++++-------- examples/breakout/characters/breakout.bas | 16 +++++----- examples/breakout/sprites/breakout.bas | 29 ++++++++++++------ examples/galaga/enemies.c | 13 +++++--- examples/galaga/galaga.bas | 8 ++--- examples/galaga/galaga.h | 4 +-- examples/galaga/main.c | 3 +- examples/galaga/script.c | 4 +-- examples/megademo/megademo.bas | 17 ++++++----- 10 files changed, 84 insertions(+), 53 deletions(-) diff --git a/docs/17-tutorial-breakout.md b/docs/17-tutorial-breakout.md index deff084..798aee7 100644 --- a/docs/17-tutorial-breakout.md +++ b/docs/17-tutorial-breakout.md @@ -1049,17 +1049,17 @@ every program. It remains a useful from-scratch PRNG example: ```basic norun SEED# = 12345 RMAX# = 6 -RND# = 0 +ROLL# = 0 I# = 0 FOR I# = 1 TO 5 GOSUB RANDOM - PRINT "ROLL " + (RND# + 1) + PRINT "ROLL " + (ROLL# + 1) NEXT I# END LABEL RANDOM SEED# = MOD(((SEED# * 1103515245) + 12345), 2147483648) -RND# = MOD((SEED# / 65536), RMAX#) +ROLL# = MOD((SEED# / 65536), RMAX#) RETURN ``` diff --git a/docs/21-tutorial-galaga-enemies.md b/docs/21-tutorial-galaga-enemies.md index ff14dc7..0746f15 100644 --- a/docs/21-tutorial-galaga-enemies.md +++ b/docs/21-tutorial-galaga-enemies.md @@ -20,7 +20,7 @@ whole development loop; the engine never rebuilds. - **[Step 2](#step-2-bind-the-engines-own-actor)** — bind the engine's own actor as the second type, which is the point of the whole exercise - **[Step 3](#step-3-share-the-frame-and-the-dice)** — share the frame state, - and give the script randomness it cannot make itself + and hand the script dice the engine controls - **[Step 4](#step-4-why-bindings-and-not-arguments)** — see why the structures are bindings rather than function arguments - **[Step 5](#step-5-the-shape-of-the-script)** — learn the three language @@ -75,7 +75,7 @@ typedef struct galaga_Enemy float t; /* parametric clock for the current maneuver */ int32_t hp; int32_t fire; /* outbox: script sets 1, engine consumes */ - float rnd; /* inbox: engine writes fresh 0..1 each call */ + float rnd; /* inbox: fresh 0..1 each call; ROLL% in BASIC */ } galaga_Enemy; ``` @@ -107,7 +107,7 @@ static const akbasic_HostField ENEMY_FIELDS[] = { AKBASIC_HOST_FIELD( galaga_Enemy, t, "T%", AKBASIC_HOSTFIELD_FLOAT ), AKBASIC_HOST_FIELD( galaga_Enemy, hp, "HP#", AKBASIC_HOSTFIELD_INT32 ), AKBASIC_HOST_FIELD( galaga_Enemy, fire, "FIRE#", AKBASIC_HOSTFIELD_INT32 ), - AKBASIC_HOST_FIELD( galaga_Enemy, rnd, "RND%", AKBASIC_HOSTFIELD_FLOAT ) + AKBASIC_HOST_FIELD( galaga_Enemy, rnd, "ROLL%", AKBASIC_HOSTFIELD_FLOAT ) }; static const akbasic_HostType ENEMY_TYPE = { "ENEMY", sizeof(galaga_Enemy), ENEMY_FIELDS, 8 @@ -194,7 +194,7 @@ typedef struct galaga_Shared float playerx; /* the player actor's position, this frame */ float playery; int32_t wave; - float rnd; /* fresh 0..1 each frame; the issue #16 route */ + float rnd; /* fresh 0..1 each frame; ROLL% to the script */ } galaga_Shared; ``` @@ -203,13 +203,24 @@ the engine refreshes it at the top of every frame. The boss reads `GAME@.PLAYERX%` to lead its dive; the fire decision reads it to know whether anything is worth shooting at. -The `rnd` fields — one here per frame, one on each enemy per call — exist -because the engine's PRNG is the script's **only** source of randomness: write -`SELF@.RND% < DT% * 1.5` and an enemy's trigger finger is a dice roll. There -is no `RND` verb in this dialect; issue #16 tracks adding one, and Chapter -17's breakout hand-rolls a linear congruential generator in BASIC as the other -route. Here the engine fills the field, which also keeps a headless run the -same game on every machine — the PRNG is the example's own, not libc's. +The `rnd` fields — one here per frame, one on each enemy per call — carry the +engine's PRNG into the script: write `SELF@.ROLL% < DT% * 1.5` and an enemy's +trigger finger is a dice roll. + +The dialect does now have a native `RND` function — issue #16 closed, and +[Chapter 12](12-function-reference.md) documents it — so this is no longer the +*only* route; Chapter 17's breakout hand-rolls a linear congruential generator +in BASIC as a third. The engine keeps filling the field here on purpose, +because it buys something `RND` cannot: the numbers come from the example's own +PRNG rather than libc's, so a headless run is the same game on every machine, +which is what makes `example_galaga` a test and not just a demo. + +**The BASIC name is `ROLL%`, not `RND%`.** A host field is a bare word and +shares a namespace with every verb and function, so once `RND` became a +function name a field could no longer be called that — the scanner refuses it +with *"Reserved word in variable name"*. The C member stays `rnd`; only the +name the script sees had to move. [Chapter 16](16-structures.md) has the same +rule for `TYPE` declarations. ## Step 4: Why bindings, and not arguments @@ -351,7 +362,7 @@ DEF DECIDEFIRE(DT%) DX% = GAME@.PLAYERX% - ACTOR@.X% IF ABS(DX%) > 140 THEN RETURN 0 IF ACTOR@.Y% > GAME@.PLAYERY% THEN RETURN 0 - IF SELF@.RND% < DT% * 1.5 THEN SELF@.FIRE# = 1 + IF SELF@.ROLL% < DT% * 1.5 THEN SELF@.FIRE# = 1 RETURN 0 END ``` @@ -386,7 +397,7 @@ DEF UPDATEBEE(DT%) IF (S# AND 2) > 0 THEN BEGIN ACTOR@.X% = SELF@.HOMEX% + SIN(SELF@.T% * 1.7) * 16 ACTOR@.Y% = SELF@.HOMEY% - IF SELF@.RND% < DT% * 0.04 THEN SELF@.STATE# = 4 : SELF@.T% = 0 + IF SELF@.ROLL% < DT% * 0.04 THEN SELF@.STATE# = 4 : SELF@.T% = 0 BEND IF (S# AND 4) > 0 THEN BEGIN R# = DIVESTEP(DT%, 130, 0.2) diff --git a/examples/breakout/characters/breakout.bas b/examples/breakout/characters/breakout.bas index 49aa588..f3b28bf 100644 --- a/examples/breakout/characters/breakout.bas +++ b/examples/breakout/characters/breakout.bas @@ -145,7 +145,7 @@ RX# = 0 N# = 0 MROW# = 0 RMAX# = 2 -RND# = 0 +ROLL# = 0 SND# = 0 P$ = "" H$ = "" @@ -172,7 +172,8 @@ BSG$(4) = "[--]" BSG$(5) = "[--]" REM --- the seed ------------------------------------------------------- -REM There is no RND in this dialect. TI# is jiffies off the host's clock +REM RND exists now, but this program keeps its own LCG so a headless run +REM is the same game every time. TI# is jiffies off the host's clock REM and is host uptime rather than zero-based, which makes it a fine seed. SEED# = TI# @@ -389,17 +390,18 @@ BY# = PY# - 10 RMAX# = 2 GOSUB RANDOM BVX# = BSPD# -IF RND# = 0 THEN BVX# = 0 - BSPD# +IF ROLL# = 0 THEN BVX# = 0 - BSPD# BVY# = 0 - BSPD# PDEC# = 0 GOSUB SHOWSPR RETURN -REM A linear congruential generator, because this dialect has no RND. +REM A linear congruential generator. RND(n) would do this in one token +REM now; the LCG stays because its sequence is reproducible. REM The multiply stays inside int64 for any seed under 2^31. LABEL RANDOM SEED# = MOD(((SEED# * 1103515245) + 12345), 2147483648) -RND# = MOD((SEED# / 65536), RMAX#) +ROLL# = MOD((SEED# / 65536), RMAX#) RETURN REM #################################################################### @@ -632,7 +634,7 @@ NUDGE# = 0 STALL# = 0 RMAX# = 4 GOSUB RANDOM -BVX# = (RND# * 3) - 6 +BVX# = (ROLL# * 3) - 6 IF BVX# = 0 THEN BVX# = 3 RETURN @@ -641,7 +643,7 @@ REM like something with a hand on the paddle rather than a mirror. LABEL DEMOAIM RMAX# = 81 GOSUB RANDOM -DOFF# = RND# - 40 +DOFF# = ROLL# - 40 RETURN REM #################################################################### diff --git a/examples/breakout/sprites/breakout.bas b/examples/breakout/sprites/breakout.bas index 7db98da..b03b5e9 100644 --- a/examples/breakout/sprites/breakout.bas +++ b/examples/breakout/sprites/breakout.bas @@ -241,7 +241,8 @@ SLX# = 0 SLY# = 0 SLI# = 0 REM The two eraser stamps. Declared here for exactly the same reason -- built -REM inside DRAWPROTOS and left undeclared, they were SHAPE:6 and SHAPE:7 inside +REM inside DRAWPROTOS and left undeclared, they were SHAPE:6 and SHAPE:7 +REM inside REM it and empty everywhere else. BL$ = "" HBL$ = "" @@ -254,10 +255,13 @@ REM cursor through every DATA item in the program in the order they appear REM in the file, so whichever loader runs first gets the DATA that is REM written first. The tables are written first. REM The text layer repaints every row it owns, opaque, so it has to be moved -REM out of the way before anything drawn can be seen. Two rows at the bottom is +REM out of the way before anything drawn can be seen. Two rows at the bottom +REM is REM enough for the final score, and hands the other thirty-five to the drawing -REM verbs. Everything this game draws then simply stays there -- a drawing goes -REM into a layer the frame composites, so nothing here is captured into a sprite +REM verbs. Everything this game draws then simply stays there -- a drawing +REM goes +REM into a layer the frame composites, so nothing here is captured into a +REM sprite REM and nothing is redrawn every frame. WINDOW 0, 35, 49, 36 @@ -293,7 +297,8 @@ ENVELOPE 0, 0, 6, 0, 4 TEMPO 12 COLLISION 2, BRICKHIT -REM The stamps, once. They used to be rebuilt whenever the SSHAPE pool ran dry, +REM The stamps, once. They used to be rebuilt whenever the SSHAPE pool ran +REM dry, REM because every frame's capture spent another slot; nothing captures now, so REM eight slots are spent here and never again. GOSUB DRAWPROTOS @@ -374,7 +379,8 @@ COLOR 1, 1 FOR K# = 0 TO 15 DRAW 1, 0, 130 + K# TO 67, 130 + K# NEXT K# -REM And an eighth the width of the HUD strip, for the same reason: the strip is +REM And an eighth the width of the HUD strip, for the same reason: the strip +REM is REM rewritten whenever a number in it changes, and the old digits have to go REM somewhere first. FOR K# = 0 TO 59 @@ -393,7 +399,8 @@ DPLAY# = 1 DHUD# = 1 RETURN -REM Take one brick off the screen: stamp the blank over it. Called when a brick +REM Take one brick off the screen: stamp the blank over it. Called when a +REM brick REM breaks, so the field is never redrawn as a whole during play -- which is REM what lets the whole live-list machinery go. LABEL ERASEBRICK @@ -444,7 +451,8 @@ WIDTH 1 COLOR 0, 1 : COLOR 1, 4 : COLOR 2, 8 : COLOR 3, 5 COLOR 4, 11 : COLOR 5, 16 : COLOR 6, 6 REM The old strip goes first. Nothing here clears the screen -- a drawing -REM stays, which is the whole point -- so the digits that were there have to be +REM stays, which is the whole point -- so the digits that were there have to +REM be REM stamped over before the new ones are drawn. Z$ = HBL$ GSHAPE Z$, 0, 0 @@ -495,7 +503,10 @@ IF SNDON# = 0 THEN VOL 0 RETURN LABEL PRESSPAUSE -IF STATE# = 2 THEN STATE# = 6 : GMTYP# = 0 : BAN$ = "PAUSED" : GOSUB SETBANNER : RETURN +IF STATE# <> 2 THEN GOTO PRESSPAUSE2 +STATE# = 6 : GMTYP# = 0 : BAN$ = "PAUSED" : GOSUB SETBANNER +RETURN +LABEL PRESSPAUSE2 IF STATE# = 6 THEN STATE# = 2 : BAN$ = "" : GOSUB SETBANNER RETURN diff --git a/examples/galaga/enemies.c b/examples/galaga/enemies.c index aca8580..4cbf9cb 100644 --- a/examples/galaga/enemies.c +++ b/examples/galaga/enemies.c @@ -71,10 +71,15 @@ static char *ENEMY_CHARACTER[GALAGA_ENEMY_KINDS] = { /* --------------------------------------------------------------- random --- */ /* - * No RND verb exists (issue #16), so the engine is the script's only source - * of randomness: it refreshes GAME@.RND% each frame and SELF@.RND% each call - * from this PRNG. A hand-rolled LCG rather than rand() so a headless run is - * the same game on every libc. + * The engine is this script's source of randomness: it refreshes GAME@.ROLL% + * each frame and SELF@.ROLL% each call from this PRNG. A hand-rolled LCG + * rather than rand() so a headless run is the same game on every libc, which + * is what lets interop_test.c assert exact counts. The dialect gained a native + * RND (issue #16) after this example was written; the field stays because RND + * would reintroduce exactly the per-machine variation this avoids. + * + * The BASIC-visible name is ROLL%, not RND%: host field names share a + * namespace with verbs and functions, so RND stopped being available as one. */ static uint32_t PRNG_STATE = 0x12345678u; diff --git a/examples/galaga/galaga.bas b/examples/galaga/galaga.bas index 8105f5b..496b6ff 100644 --- a/examples/galaga/galaga.bas +++ b/examples/galaga/galaga.bas @@ -50,7 +50,7 @@ DEF DECIDEFIRE(DT%) DX% = GAME@.PLAYERX% - ACTOR@.X% IF ABS(DX%) > 140 THEN RETURN 0 IF ACTOR@.Y% > GAME@.PLAYERY% THEN RETURN 0 - IF SELF@.RND% < DT% * 1.5 THEN SELF@.FIRE# = 1 + IF SELF@.ROLL% < DT% * 1.5 THEN SELF@.FIRE# = 1 RETURN 0 REM Bee: enter, breathe in formation, occasionally dive nearly straight. @@ -65,7 +65,7 @@ DEF UPDATEBEE(DT%) IF (S# AND 2) > 0 THEN BEGIN ACTOR@.X% = SELF@.HOMEX% + SIN(SELF@.T% * 1.7) * 16 ACTOR@.Y% = SELF@.HOMEY% - IF SELF@.RND% < DT% * 0.04 THEN SELF@.STATE# = 4 : SELF@.T% = 0 + IF SELF@.ROLL% < DT% * 0.04 THEN SELF@.STATE# = 4 : SELF@.T% = 0 BEND IF (S# AND 4) > 0 THEN BEGIN R# = DIVESTEP(DT%, 130, 0.2) @@ -85,7 +85,7 @@ DEF UPDATEBFLY(DT%) IF (S# AND 2) > 0 THEN BEGIN ACTOR@.X% = SELF@.HOMEX% + SIN(SELF@.T% * 2.1) * 24 ACTOR@.Y% = SELF@.HOMEY% - IF SELF@.RND% < DT% * 0.05 THEN SELF@.STATE# = 4 : SELF@.T% = 0 + IF SELF@.ROLL% < DT% * 0.05 THEN SELF@.STATE# = 4 : SELF@.T% = 0 BEND IF (S# AND 4) > 0 THEN BEGIN R# = DIVESTEP(DT%, 260, 0.1) @@ -108,7 +108,7 @@ DEF UPDATEBOSS(DT%) IF (S# AND 2) > 0 THEN BEGIN ACTOR@.X% = SELF@.HOMEX% + SIN(SELF@.T% * 1.1) * 10 ACTOR@.Y% = SELF@.HOMEY% - IF SELF@.RND% < DT% * 0.03 THEN SELF@.STATE# = 4 : SELF@.T% = 0 + IF SELF@.ROLL% < DT% * 0.03 THEN SELF@.STATE# = 4 : SELF@.T% = 0 BEND IF (S# AND 4) > 0 THEN BEGIN R# = DIVESTEP(DT%, 60, 0.9) diff --git a/examples/galaga/galaga.h b/examples/galaga/galaga.h index ff324f5..94c1e61 100644 --- a/examples/galaga/galaga.h +++ b/examples/galaga/galaga.h @@ -77,7 +77,7 @@ typedef struct galaga_Enemy float t; /* parametric clock for the current maneuver */ int32_t hp; int32_t fire; /* outbox: script sets 1, engine consumes */ - float rnd; /* inbox: engine writes fresh 0..1 each call */ + float rnd; /* inbox: fresh 0..1 each call; ROLL% in BASIC */ } galaga_Enemy; /** @brief Frame state every enemy may read. Bound once as GAME@. */ @@ -86,7 +86,7 @@ typedef struct galaga_Shared float playerx; /* the player actor's position, this frame */ float playery; int32_t wave; - float rnd; /* fresh 0..1 each frame; the issue #16 route */ + float rnd; /* fresh 0..1 each frame; ROLL% to the script */ } galaga_Shared; /* --------------------------------------------------------------- screens --- */ diff --git a/examples/galaga/main.c b/examples/galaga/main.c index 25de084..2fa9d10 100644 --- a/examples/galaga/main.c +++ b/examples/galaga/main.c @@ -491,7 +491,8 @@ static akerr_ErrorContext *frame(bool *running) } /* The shared frame state, refreshed before any enemy thinks. The engine - * filling GAME@.RND% is the issue #16 route: no RND verb exists. */ + * fills GAME@.ROLL% from its own PRNG rather than letting the script call + * the native RND, so a headless run is the same game on every machine. */ galaga_shared.playerx = galaga_game.player->x + 50.0f; galaga_shared.playery = galaga_game.player->y; galaga_shared.rnd = galaga_random(); diff --git a/examples/galaga/script.c b/examples/galaga/script.c index b588430..3e59be1 100644 --- a/examples/galaga/script.c +++ b/examples/galaga/script.c @@ -62,7 +62,7 @@ static const akbasic_HostField ENEMY_FIELDS[] = { AKBASIC_HOST_FIELD( galaga_Enemy, t, "T%", AKBASIC_HOSTFIELD_FLOAT ), AKBASIC_HOST_FIELD( galaga_Enemy, hp, "HP#", AKBASIC_HOSTFIELD_INT32 ), AKBASIC_HOST_FIELD( galaga_Enemy, fire, "FIRE#", AKBASIC_HOSTFIELD_INT32 ), - AKBASIC_HOST_FIELD( galaga_Enemy, rnd, "RND%", AKBASIC_HOSTFIELD_FLOAT ) + AKBASIC_HOST_FIELD( galaga_Enemy, rnd, "ROLL%", AKBASIC_HOSTFIELD_FLOAT ) }; static const akbasic_HostType ENEMY_TYPE = { "ENEMY", sizeof(galaga_Enemy), ENEMY_FIELDS, 8 @@ -87,7 +87,7 @@ static const akbasic_HostField GAME_FIELDS[] = { AKBASIC_HOST_FIELD( galaga_Shared, playerx, "PLAYERX%", AKBASIC_HOSTFIELD_FLOAT ), AKBASIC_HOST_FIELD( galaga_Shared, playery, "PLAYERY%", AKBASIC_HOSTFIELD_FLOAT ), AKBASIC_HOST_FIELD( galaga_Shared, wave, "WAVE#", AKBASIC_HOSTFIELD_INT32 ), - AKBASIC_HOST_FIELD( galaga_Shared, rnd, "RND%", AKBASIC_HOSTFIELD_FLOAT ) + AKBASIC_HOST_FIELD( galaga_Shared, rnd, "ROLL%", AKBASIC_HOSTFIELD_FLOAT ) }; static const akbasic_HostType GAME_TYPE = { "GAME", sizeof(galaga_Shared), GAME_FIELDS, 4 diff --git a/examples/megademo/megademo.bas b/examples/megademo/megademo.bas index 1b58fb4..f713ca9 100644 --- a/examples/megademo/megademo.bas +++ b/examples/megademo/megademo.bas @@ -10,7 +10,7 @@ REM A demoscene production for the akbasic interpreter, written as if REM it were 1985 and this dialect were the machine under the tree. REM It leans on every corner of the interpreter on purpose: REM -REM - there is no RND, so it carries chapter 17's LCG and seeds it +REM - it carries chapter 17's LCG rather than the native RND, and seeds it REM from the jiffy clock REM - the palette cannot be rewritten, so every "colour cycle" is an REM honest redraw of the same strokes in the next colour @@ -81,7 +81,7 @@ REM machine and a predeclared scratch variable occupies one forever, REM where a scoped one gives its slot back. The first cut of this REM program predeclared everything and ran the pool dry. RMAX# = 0 -RND# = 0 +ROLL# = 0 TX% = 0 TB# = 0 @@ -816,11 +816,12 @@ REM ===================================================================== REM Subroutines. REM ===================================================================== -REM Chapter 17's generator, verbatim: there is no RND in this dialect. -REM Answers 0 to RMAX#-1 in RND#, from the middle bits of the seed. +REM Chapter 17's historical generator, verbatim. RND(n) is built in now; +REM this stays so the demo runs identically on every machine. +REM Answers 0 to RMAX#-1 in ROLL#, from the middle bits of the seed. LABEL RANDOM SEED# = MOD(((SEED# * 1103515245) + 12345), 2147483648) -RND# = MOD((SEED# / 65536), RMAX#) +ROLL# = MOD((SEED# / 65536), RMAX#) RETURN REM NS# stars in four brightnesses. Two LCG pulls a star, and the @@ -830,10 +831,10 @@ SI# = 0 DO WHILE SI# < NS# RMAX# = W# GOSUB RANDOM - X# = RND# + X# = ROLL# RMAX# = H# GOSUB RANDOM - Y# = RND# + Y# = ROLL# B# = MOD(SEED#, 4) COLOR 1, STC#(B#) DRAW 1, X#, Y# @@ -1291,7 +1292,7 @@ LABEL REHOME MOVSPR L2#, 0.5 * W#, 0.5 * H# RMAX# = 360 GOSUB RANDOM -SBG#(L2#) = RND# +SBG#(L2#) = ROLL# MOVSPR L2#, SBG#(L2#) # 5 RETURN -- 2.43.0