Finish the language: every remaining verb group, and the defects that blocked them

Closes groups A, C, D, E, F, H and J of TODO.md section 4, plus RESTORE and
RENUMBER, and closes section 6 -- all seventeen reference defects. Seven of
those turned out to have been fixed or never ported and nobody had written it
down; the audit records the evidence for each.

Two of the seventeen were real. math_plus mutated its left operand when the
operand was mutable, so A# + 1 could modify A#; it was gated on FOR/NEXT
coverage because NEXT relied on the mutation, so tests/for_next.c came first
and NEXT now writes the counter back itself. And the binary operators summed
both numeric fields of their right operand, which no BASIC program can reach
-- that one needed a test written against the value API.

Writing the tests turned up eight defects nobody had listed. Seven are fixed:

  IF A = 2 THEN was a parse error; only == worked
  IF ... AND ... was a parse error, because a condition parsed as one relation
  IF A = 1 OR B = 2 THEN was silently always false, and so was IF A THEN
  EXIT before any NEXT restarted the program and exhausted the variable pool
  READ never found a DATA line above it, and swallowed the lines between
  PRINT 2 + 2 at the prompt was filed as program text instead of answering
  a short read discarded its bytes, so COPY produced empty files
  every verb taking an argument list said "peek() returned nil token!" on none

The eighth is not fixed and cannot be quietly: a FOR whose step overshoots
runs its body one extra time, and FOR I = 1 TO 1 runs it zero times. The two
errors cancel for a step of 1, which is why neither was noticed. Correcting
them changes the expected output of a checked-in acceptance file, and
tests/reference/README.md forbids editing one to suit this interpreter. It is
tests/for_semantics.c in AKBASIC_KNOWN_FAILING_TESTS, asserting the correct
contract, and TODO.md items 19 and 20.

Sprites are real libakgl actors with a renderfunc of their own, because
akgl_actor_render draws every sprite square and an actor has no per-axis
scale. Both are filed upstream. SPRSAV takes an image file, an SSHAPE handle
or a 63-element integer array -- a string here cannot hold a zero byte.

Verbs that need hardware that does not exist are refused by name with the
reason rather than faked: SYS, HEADER, COLLECT, BACKUP, BOOT, FILTER, and
DIRECTORY, which is refused for a missing libakstdlib wrapper filed upstream.

94 tests in the default build, 93 with SDL, 94 under ASan and UBSan, doxygen
clean. The Go acceptance corpus stayed green throughout.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-31 21:50:37 -04:00
parent 3aade4947a
commit 9845e77a5c
87 changed files with 11024 additions and 325 deletions

View File

@@ -37,6 +37,8 @@
* to populate it itself. deps/libakgl/tests/draw.c does the same.
*/
#include <akgl/game.h>
#include <akgl/heap.h>
#include <akgl/registry.h>
#include <akgl/renderer.h>
#include <akbasic/error.h>
@@ -102,6 +104,41 @@ akerr_ErrorContext *akbasic_frontend_akgl_init(akbasic_AkglFrontend *obj, const
*/
PASS(errctx, akgl_render_bind2d(obj->renderer));
/*
* The object pools and the name registries. Every akgl_*_initialize ends in
* a registry write and fails AKERR_KEY without these, so anything drawn as
* an actor -- which is what a BASIC sprite is -- needs them. akgl_game_init()
* is where they would normally be done, and it is the function goal 3 keeps
* this host out of.
*
* Unconditional, and it has to be. akgl_registry_init() overwrites the
* property-set ids without destroying the old sets, so repeating it would
* normally leak -- but this frontend owns SDL_Init and SDL_Quit, and
* SDL_Quit destroys every property set while leaving libakgl's ids pointing
* at them. So the previous registries are already gone, and skipping the
* call on the strength of a non-zero id is what actually breaks: the second
* frontend of a process gets ids that name nothing, and the first
* akgl_sprite_initialize fails AKERR_KEY.
*
* A game that embeds the interpreter does not link this file. It has already
* called akgl_game_init(), which does both of these itself.
*/
PASS(errctx, akgl_heap_init());
PASS(errctx, akgl_registry_init());
/*
* And the camera. akgl_actor_render() dereferences this global to translate
* world coordinates into screen ones and does not check it, so an unset
* camera is a crash the first time a sprite is drawn rather than an error
* anybody could act on. One screen's worth at the origin: BASIC has no verb
* that scrolls a view, so the world and the screen are the same thing here.
*/
camera = &_akgl_camera;
camera->x = 0.0f;
camera->y = 0.0f;
camera->w = (float)w;
camera->h = (float)h;
obj->font = TTF_OpenFont(fontpath, (float)fontsize);
FAIL_ZERO_RETURN(errctx, (obj->font != NULL), AKGL_ERR_SDL,
"Couldn't open the font %s: %s", fontpath, SDL_GetError());
@@ -131,6 +168,13 @@ akerr_ErrorContext *akbasic_frontend_akgl_init(akbasic_AkglFrontend *obj, const
PASS(errctx, akbasic_graphics_init_akgl(&obj->graphics, &obj->graphicsstate,
obj->renderer));
PASS(errctx, akbasic_input_init_akgl(&obj->input));
/*
* The graphics state goes with it so SPRSAV can turn an SSHAPE handle into a
* sprite. The two devices stay separate records -- a host may lend one and
* withhold the other -- and this is the one place they meet.
*/
PASS(errctx, akbasic_sprite_init_akgl(&obj->sprites, &obj->spritesstate,
obj->renderer, &obj->graphicsstate));
/*
* Audio last, in its own subsystem, and allowed to fail. The reference asks
@@ -170,7 +214,7 @@ akerr_ErrorContext *akbasic_frontend_akgl_attach(akbasic_AkglFrontend *obj, akba
PASS(errctx, akbasic_runtime_init(rt, &obj->sink));
PASS(errctx, akbasic_runtime_set_devices(rt, &obj->graphics,
(obj->audioready ? &obj->audio : NULL),
&obj->input));
&obj->input, &obj->sprites));
SUCCEED_RETURN(errctx);
}
@@ -224,6 +268,13 @@ akerr_ErrorContext *akbasic_frontend_akgl_pump(void *self, bool *running)
* bitmap plane.
*/
PASS(errctx, akbasic_sink_akgl_render(&obj->akglsink));
/*
* Sprites last, so they are over the text as well as over the drawing. That
* is what a C128 does with a high-priority sprite, and the low-priority case
* -- behind the bitmap plane -- has nowhere to go here: see the note in
* spr_configure().
*/
PASS(errctx, akbasic_sprite_akgl_render(&obj->sprites));
FAIL_ZERO_RETURN(errctx, SDL_RenderPresent(obj->renderer->sdl_renderer),
AKGL_ERR_SDL, "Couldn't present the frame: %s", SDL_GetError());
SUCCEED_RETURN(errctx);
@@ -266,6 +317,8 @@ void akbasic_frontend_akgl_shutdown(akbasic_AkglFrontend *obj)
if ( obj == NULL ) {
return;
}
/* Before the renderer goes: these are textures it created. */
akbasic_sprite_akgl_shutdown(&obj->sprites);
if ( obj->font != NULL ) {
TTF_CloseFont(obj->font);
obj->font = NULL;