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:
@@ -24,6 +24,7 @@
|
||||
#include <akbasic/error.h>
|
||||
#include <akbasic/graphics.h>
|
||||
#include <akbasic/input.h>
|
||||
#include <akbasic/sprite.h>
|
||||
|
||||
/** @brief Room for the call log. Longer than any test needs; overflow truncates loudly. */
|
||||
#define MOCK_LOG_SIZE 8192
|
||||
@@ -50,12 +51,17 @@ typedef struct
|
||||
int keys[MOCK_MAX_KEYS];
|
||||
int keycount;
|
||||
int keynext;
|
||||
|
||||
/* Sprites */
|
||||
uint16_t collisions; /* what the next collisions() call reports */
|
||||
int patternbytes[AKBASIC_MAX_SPRITES]; /* bytes the last define() carried, per sprite */
|
||||
} akbasic_MockDevice;
|
||||
|
||||
static akbasic_MockDevice MOCK;
|
||||
static akbasic_GraphicsBackend MOCK_GRAPHICS;
|
||||
static akbasic_AudioBackend MOCK_AUDIO;
|
||||
static akbasic_InputBackend MOCK_INPUT;
|
||||
static akbasic_SpriteBackend MOCK_SPRITES;
|
||||
|
||||
/**
|
||||
* @brief Append one formatted call to the log.
|
||||
@@ -288,6 +294,120 @@ static akerr_ErrorContext *mock_flush_keys(akbasic_InputBackend *self)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- sprites -- */
|
||||
|
||||
/**
|
||||
* @brief Refuse a sprite number the way a real backend has to.
|
||||
*
|
||||
* Sprites are 1-based at this boundary -- see sprite.h -- so an off-by-one in a
|
||||
* verb handler shows up here as AKBASIC_ERR_BOUNDS rather than as a silently
|
||||
* mis-addressed sprite.
|
||||
*/
|
||||
static akerr_ErrorContext AKERR_NOIGNORE *mock_sprite_range(int n)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
|
||||
FAIL_ZERO_RETURN(errctx, (n >= 1 && n <= AKBASIC_MAX_SPRITES), AKBASIC_ERR_BOUNDS,
|
||||
"mock sprite %d out of range", n);
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
static akerr_ErrorContext *mock_spr_define(akbasic_SpriteBackend *self, int n, const uint8_t *pattern, int bytes, akbasic_Color fg, akbasic_Color bg)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
(void)self;
|
||||
|
||||
PASS(errctx, mock_sprite_range(n));
|
||||
FAIL_ZERO_RETURN(errctx, (pattern != NULL), AKERR_NULLPOINTER, "NULL pattern in define");
|
||||
MOCK.patternbytes[n - 1] = bytes;
|
||||
/*
|
||||
* The first and last bytes rather than all 63: enough to tell one pattern
|
||||
* from another and to catch a byte order that came through reversed,
|
||||
* without a log line no human can read.
|
||||
*/
|
||||
mock_log("sprdef %d %d bytes %02x..%02x fg=%d,%d,%d bg=%d,%d,%d\n",
|
||||
n, bytes, pattern[0], pattern[bytes - 1],
|
||||
fg.r, fg.g, fg.b, bg.r, bg.g, bg.b);
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
static akerr_ErrorContext *mock_spr_define_shape(akbasic_SpriteBackend *self, int n, int handle)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
(void)self;
|
||||
|
||||
PASS(errctx, mock_sprite_range(n));
|
||||
mock_log("sprshape %d from %d\n", n, handle);
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
static akerr_ErrorContext *mock_spr_define_file(akbasic_SpriteBackend *self, int n, const char *path, const char *root)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
(void)self;
|
||||
|
||||
PASS(errctx, mock_sprite_range(n));
|
||||
FAIL_ZERO_RETURN(errctx, (path != NULL), AKERR_NULLPOINTER, "NULL path in define_file");
|
||||
/*
|
||||
* The root is logged as well as the path. Whether the interpreter passed the
|
||||
* running program's directory through is the whole of what this repository
|
||||
* owns about relative asset paths -- resolving one is libakgl's job, and
|
||||
* there is no way to see it happen from a mock.
|
||||
*/
|
||||
mock_log("sprfile %d %s root=%s\n", n, path, (root != NULL ? root : "(none)"));
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
static akerr_ErrorContext *mock_spr_show(akbasic_SpriteBackend *self, int n, bool visible)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
(void)self;
|
||||
|
||||
PASS(errctx, mock_sprite_range(n));
|
||||
mock_log("sprshow %d %d\n", n, (visible ? 1 : 0));
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
static akerr_ErrorContext *mock_spr_move(akbasic_SpriteBackend *self, int n, double x, double y)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
(void)self;
|
||||
|
||||
PASS(errctx, mock_sprite_range(n));
|
||||
mock_log("sprmove %d %.2f,%.2f\n", n, x, y);
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
static akerr_ErrorContext *mock_spr_configure(akbasic_SpriteBackend *self, int n, akbasic_Color color, bool xexpand, bool yexpand, bool behind)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
(void)self;
|
||||
|
||||
PASS(errctx, mock_sprite_range(n));
|
||||
mock_log("sprcfg %d %d,%d,%d x%d y%d b%d\n", n, color.r, color.g, color.b,
|
||||
(xexpand ? 1 : 0), (yexpand ? 1 : 0), (behind ? 1 : 0));
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
static akerr_ErrorContext *mock_spr_shared_colors(akbasic_SpriteBackend *self, akbasic_Color c1, akbasic_Color c2)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
(void)self;
|
||||
|
||||
mock_log("sprshared %d,%d,%d %d,%d,%d\n", c1.r, c1.g, c1.b, c2.r, c2.g, c2.b);
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
static akerr_ErrorContext *mock_spr_collisions(akbasic_SpriteBackend *self, uint16_t *mask)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
(void)self;
|
||||
|
||||
FAIL_ZERO_RETURN(errctx, (mask != NULL), AKERR_NULLPOINTER, "NULL mask in collisions");
|
||||
*mask = MOCK.collisions;
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- fixture -- */
|
||||
|
||||
/** @brief Reset the recorder and populate all three vtables. */
|
||||
@@ -325,6 +445,23 @@ static void mock_devices_init(void)
|
||||
MOCK_INPUT.self = &MOCK;
|
||||
MOCK_INPUT.poll_key = mock_poll_key;
|
||||
MOCK_INPUT.flush_keys = mock_flush_keys;
|
||||
|
||||
MOCK_SPRITES.self = &MOCK;
|
||||
MOCK_SPRITES.define = mock_spr_define;
|
||||
MOCK_SPRITES.define_shape = mock_spr_define_shape;
|
||||
MOCK_SPRITES.define_file = mock_spr_define_file;
|
||||
MOCK_SPRITES.show = mock_spr_show;
|
||||
MOCK_SPRITES.move = mock_spr_move;
|
||||
MOCK_SPRITES.configure = mock_spr_configure;
|
||||
MOCK_SPRITES.shared_colors = mock_spr_shared_colors;
|
||||
MOCK_SPRITES.collisions = mock_spr_collisions;
|
||||
}
|
||||
|
||||
/** @brief Set what the next collisions() call will report. Bit n-1 is sprite n. */
|
||||
__attribute__((unused))
|
||||
static void mock_set_collisions(uint16_t mask)
|
||||
{
|
||||
MOCK.collisions = mask;
|
||||
}
|
||||
|
||||
/** @brief Prime the input backend with keystrokes GET will drain in order. */
|
||||
|
||||
Reference in New Issue
Block a user