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:
@@ -375,6 +375,74 @@ static akerr_ErrorContext *sink_clear(akbasic_TextSink *self)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Put the cursor at a character cell, for CHAR.
|
||||
*
|
||||
* Clamped rather than refused: a program that asks for a column past the edge of
|
||||
* a window it cannot measure has made an ordinary mistake, and a C128 clamps too.
|
||||
*/
|
||||
static akerr_ErrorContext *sink_moveto(akbasic_TextSink *self, int col, int row)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
akbasic_AkglSink *state = NULL;
|
||||
|
||||
FAIL_ZERO_RETURN(errctx, (self != NULL), AKERR_NULLPOINTER, "NULL sink in moveto");
|
||||
state = (akbasic_AkglSink *)self->self;
|
||||
FAIL_ZERO_RETURN(errctx, (state != NULL), AKERR_NULLPOINTER, "akgl sink has no state");
|
||||
|
||||
if ( col < 0 ) { col = 0; }
|
||||
if ( row < 0 ) { row = 0; }
|
||||
if ( col >= state->columns ) { col = state->columns - 1; }
|
||||
if ( row >= state->rows ) { row = state->rows - 1; }
|
||||
state->cursorcol = col;
|
||||
state->cursorrow = row;
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Constrain the text area to a rectangle of cells, for WINDOW.
|
||||
*
|
||||
* The sink already drives everything -- wrap, scroll, cursor -- from `x`, `y`,
|
||||
* `columns` and `rows`, so a window is those four fields and nothing else. The
|
||||
* cell size does not change, which is what keeps a windowed program's text the
|
||||
* same size as an unwindowed one's.
|
||||
*
|
||||
* The full-screen geometry is remembered so a later WINDOW can grow back out;
|
||||
* without it each call could only ever shrink.
|
||||
*/
|
||||
static akerr_ErrorContext *sink_window(akbasic_TextSink *self, int left, int top, int right, int bottom)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
akbasic_AkglSink *state = NULL;
|
||||
int maxcols = 0;
|
||||
int maxrows = 0;
|
||||
|
||||
FAIL_ZERO_RETURN(errctx, (self != NULL), AKERR_NULLPOINTER, "NULL sink in window");
|
||||
state = (akbasic_AkglSink *)self->self;
|
||||
FAIL_ZERO_RETURN(errctx, (state != NULL), AKERR_NULLPOINTER, "akgl sink has no state");
|
||||
FAIL_ZERO_RETURN(errctx, (state->cellw > 0 && state->cellh > 0), AKBASIC_ERR_STATE,
|
||||
"The sink has no character grid to window");
|
||||
|
||||
maxcols = state->fullwidth / state->cellw;
|
||||
maxrows = state->fullheight / state->cellh;
|
||||
if ( left < 0 ) { left = 0; }
|
||||
if ( top < 0 ) { top = 0; }
|
||||
if ( right >= maxcols ) { right = maxcols - 1; }
|
||||
if ( bottom >= maxrows ) { bottom = maxrows - 1; }
|
||||
FAIL_ZERO_RETURN(errctx, (right >= left && bottom >= top), AKBASIC_ERR_VALUE,
|
||||
"WINDOW asks for no cells at all");
|
||||
|
||||
state->x = state->fullx + (left * state->cellw);
|
||||
state->y = state->fully + (top * state->cellh);
|
||||
state->columns = (right - left) + 1;
|
||||
state->rows = (bottom - top) + 1;
|
||||
state->width = state->columns * state->cellw;
|
||||
state->height = state->rows * state->cellh;
|
||||
state->cursorcol = 0;
|
||||
state->cursorrow = 0;
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
akerr_ErrorContext *akbasic_sink_init_akgl(akbasic_TextSink *obj, akbasic_AkglSink *state, akgl_RenderBackend *renderer, TTF_Font *font, int w, int h)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
@@ -426,6 +494,11 @@ akerr_ErrorContext *akbasic_sink_init_akgl(akbasic_TextSink *obj, akbasic_AkglSi
|
||||
state->y = 0;
|
||||
state->width = w;
|
||||
state->height = h;
|
||||
/* Remembered so WINDOW can grow back out to the whole area. */
|
||||
state->fullx = state->x;
|
||||
state->fully = state->y;
|
||||
state->fullwidth = w;
|
||||
state->fullheight = h;
|
||||
state->cellw = cellw;
|
||||
state->cellh = cellh;
|
||||
state->columns = w / cellw;
|
||||
@@ -442,6 +515,8 @@ akerr_ErrorContext *akbasic_sink_init_akgl(akbasic_TextSink *obj, akbasic_AkglSi
|
||||
obj->writeln = sink_writeln;
|
||||
obj->readline = sink_readline;
|
||||
obj->clear = sink_clear;
|
||||
obj->moveto = sink_moveto;
|
||||
obj->window = sink_window;
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user