Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1f3b9f5cf6 |
@@ -1,48 +0,0 @@
|
|||||||
name: akbasic Mutation Testing
|
|
||||||
run-name: ${{ gitea.actor }} akbasic mutation test
|
|
||||||
|
|
||||||
# Mutation testing is intentionally isolated from push and merge checks. The
|
|
||||||
# complete src/ tree takes hours and must not consume the shared CI capacity
|
|
||||||
# during normal development.
|
|
||||||
on:
|
|
||||||
# Gitea schedules use UTC. 07:00 UTC is 02:00 EST (the requested fixed
|
|
||||||
# Eastern Standard Time slot).
|
|
||||||
schedule:
|
|
||||||
- cron: '0 7 * * *'
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
full_mutation:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
timeout-minutes: 720
|
|
||||||
steps:
|
|
||||||
- name: Check out repository code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
submodules: true
|
|
||||||
- name: dependencies
|
|
||||||
run: |
|
|
||||||
sudo apt-get update -y
|
|
||||||
sudo apt-get install -y cmake gcc python3 moreutils
|
|
||||||
- name: mutation testing (full tree)
|
|
||||||
run: |
|
|
||||||
python3 scripts/mutation_test.py \
|
|
||||||
--junit mutation-junit.xml \
|
|
||||||
--threshold 65
|
|
||||||
- name: publish mutation results
|
|
||||||
if: always()
|
|
||||||
uses: mikepenz/action-junit-report@v4
|
|
||||||
with:
|
|
||||||
report_paths: 'mutation-junit.xml'
|
|
||||||
annotate_only: true
|
|
||||||
detailed_summary: true
|
|
||||||
include_passed: true
|
|
||||||
fail_on_failure: 'false'
|
|
||||||
- name: upload mutation report
|
|
||||||
if: always()
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: mutation-report
|
|
||||||
path: mutation-junit.xml
|
|
||||||
if-no-files-found: warn
|
|
||||||
- run: echo "🍏 This job's status is ${{ job.status }}."
|
|
||||||
@@ -1,13 +1,24 @@
|
|||||||
name: akbasic Release Build
|
name: akbasic Release Build
|
||||||
run-name: ${{ gitea.actor }} akbasic release checks
|
run-name: ${{ gitea.actor }} akbasic release checks
|
||||||
# Manual only. Nothing here runs on push: documentation is a release gate, not
|
# Manual only. Nothing here runs on push: the full mutation set is thousands of
|
||||||
# a per-commit check. The expensive mutation suite has its own daily schedule.
|
# mutants and hours of runner time, which is a release-gate cost, not a
|
||||||
|
# per-commit one. Trigger it from the Actions tab.
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
mutation_threshold:
|
||||||
|
description: "Fail if the mutation score falls below this percentage"
|
||||||
|
required: false
|
||||||
|
default: "65"
|
||||||
|
mutation_targets:
|
||||||
|
description: "Space-separated files to mutate; empty means the whole src/ tree"
|
||||||
|
required: false
|
||||||
|
default: ""
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# Moved here from ci.yaml. The docs are wanted for a release, not on every
|
# Moved here from ci.yaml. The docs are wanted for a release, not on every
|
||||||
# push.
|
# push, and building them beside the release mutation run keeps the two
|
||||||
|
# artefacts a release needs in one place.
|
||||||
docs:
|
docs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
@@ -41,3 +52,89 @@ jobs:
|
|||||||
path: build/docs/html/
|
path: build/docs/html/
|
||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
- run: echo "🍏 This job's status is ${{ job.status }}."
|
- run: echo "🍏 This job's status is ${{ job.status }}."
|
||||||
|
|
||||||
|
full_mutation:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
# 3675 mutants across the whole src/ tree. Cost per mutant is one incremental
|
||||||
|
# rebuild plus one full ctest run, which measures at roughly 2s for a leaf
|
||||||
|
# file and 11s for src/value.c, where almost everything links against it.
|
||||||
|
# Budget most of a day and expect it to finish well inside that; the ceiling
|
||||||
|
# exists so a mutant that wedges the runner cannot hold it forever.
|
||||||
|
timeout-minutes: 720
|
||||||
|
steps:
|
||||||
|
- name: Check out repository code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
# The harness copies the repo and configures a build inside the copy,
|
||||||
|
# so it needs the same submodules the main build does. The golden
|
||||||
|
# corpus is part of what kills mutants and it is checked in now, so
|
||||||
|
# that is libakerror and libakstdlib and nothing else.
|
||||||
|
submodules: true
|
||||||
|
# moreutils for errno(1), which deps/libakerror's scripts/generrno.sh needs
|
||||||
|
# to generate its errno table. Without it the generated table is empty and
|
||||||
|
# every AKERR_* code collapses onto a low integer -- see the long note on
|
||||||
|
# ci.yaml's cmake_build job for what that breaks and how it presents.
|
||||||
|
- name: dependencies
|
||||||
|
run: |
|
||||||
|
sudo apt-get update -y
|
||||||
|
sudo apt-get install -y cmake gcc python3 moreutils
|
||||||
|
# The whole akbasic-owned src/ tree. ci.yaml runs a two-file subset on every
|
||||||
|
# push; this is the one that actually covers the interpreter.
|
||||||
|
#
|
||||||
|
# Mutation testing is the only gate that sees the error-handling control
|
||||||
|
# flow at all: libakerror's ATTEMPT/CATCH/PASS macros expand at their call
|
||||||
|
# sites, so gcov attributes them to the caller and line coverage cannot
|
||||||
|
# measure them.
|
||||||
|
#
|
||||||
|
# The default threshold matches ci.yaml's rather than being stricter.
|
||||||
|
# Whole-tree coverage is uneven -- src/symtab.c is the only file measured
|
||||||
|
# on the push path, at 74.1%, and the rest is unmeasured, so a tighter
|
||||||
|
# number here would be a guess. Raise it with the workflow input once a
|
||||||
|
# full run has established a real baseline.
|
||||||
|
#
|
||||||
|
# The two inputs arrive through the environment rather than being
|
||||||
|
# interpolated straight into the script. ${{ }} substitution happens before
|
||||||
|
# the shell sees the line, so a value containing shell metacharacters would
|
||||||
|
# otherwise run as code. This workflow is manual and owner-triggered, but
|
||||||
|
# the safe form costs nothing.
|
||||||
|
- name: mutation testing (full tree)
|
||||||
|
env:
|
||||||
|
MUTATION_TARGETS: ${{ gitea.event.inputs.mutation_targets }}
|
||||||
|
MUTATION_THRESHOLD: ${{ gitea.event.inputs.mutation_threshold }}
|
||||||
|
run: |
|
||||||
|
set -eu
|
||||||
|
# Word-splitting is the point here: the input is a space-separated
|
||||||
|
# list. An empty input leaves $targets empty and the harness falls
|
||||||
|
# through to its own default, which is the whole src/ tree.
|
||||||
|
targets=""
|
||||||
|
for f in ${MUTATION_TARGETS:-}; do
|
||||||
|
targets="$targets --target $f"
|
||||||
|
done
|
||||||
|
# shellcheck disable=SC2086
|
||||||
|
python3 scripts/mutation_test.py \
|
||||||
|
$targets \
|
||||||
|
--junit mutation-junit.xml \
|
||||||
|
--threshold "${MUTATION_THRESHOLD:-65}"
|
||||||
|
# Publish even when the threshold gate fails, so survivors are visible --
|
||||||
|
# each one is a missing test. Display-only (fail_on_failure: false); the
|
||||||
|
# --threshold above is the gate. annotate_only avoids the Checks API 404
|
||||||
|
# on Gitea (mikepenz/action-junit-report#23).
|
||||||
|
- name: publish mutation results
|
||||||
|
if: always()
|
||||||
|
uses: mikepenz/action-junit-report@v4
|
||||||
|
with:
|
||||||
|
report_paths: 'mutation-junit.xml'
|
||||||
|
annotate_only: true
|
||||||
|
detailed_summary: true
|
||||||
|
include_passed: true
|
||||||
|
fail_on_failure: 'false'
|
||||||
|
# Keep the raw report as well as the annotations: a release wants the
|
||||||
|
# survivor list on file, and the job summary is not durable.
|
||||||
|
- name: upload mutation report
|
||||||
|
if: always()
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: mutation-report
|
||||||
|
path: mutation-junit.xml
|
||||||
|
if-no-files-found: warn
|
||||||
|
- run: echo "🍏 This job's status is ${{ job.status }}."
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ nothing would say which type it is.
|
|||||||
```
|
```
|
||||||
|
|
||||||
```output
|
```output
|
||||||
? 40 : PARSE ERROR TYPE POINT: POINT is a reserved word and cannot name a type
|
? 10 : PARSE ERROR TYPE POINT: POINT is a reserved word and cannot name a type
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -118,12 +118,6 @@ typedef struct akbasic_Runtime
|
|||||||
{
|
{
|
||||||
akbasic_SourceLine source[AKBASIC_MAX_SOURCE_LINES];
|
akbasic_SourceLine source[AKBASIC_MAX_SOURCE_LINES];
|
||||||
|
|
||||||
/* Scratch owned by this runtime for RENUMBER and its target prescan. */
|
|
||||||
int16_t renumber_map[AKBASIC_MAX_SOURCE_LINES];
|
|
||||||
uint8_t renumber_visited[AKBASIC_MAX_SOURCE_LINES];
|
|
||||||
akbasic_SourceLine renumber_line;
|
|
||||||
char renumber_discard[AKBASIC_MAX_LINE_LENGTH * 2];
|
|
||||||
|
|
||||||
/* Pools. Nothing here is malloc'd; everything is drawn from and returned. */
|
/* Pools. Nothing here is malloc'd; everything is drawn from and returned. */
|
||||||
akbasic_Environment environments[AKBASIC_MAX_ENVIRONMENTS];
|
akbasic_Environment environments[AKBASIC_MAX_ENVIRONMENTS];
|
||||||
akbasic_Variable variables[AKBASIC_MAX_VARIABLES];
|
akbasic_Variable variables[AKBASIC_MAX_VARIABLES];
|
||||||
|
|||||||
@@ -160,14 +160,21 @@ akerr_ErrorContext *akbasic_data_scan(akbasic_Runtime *obj)
|
|||||||
{
|
{
|
||||||
PREPARE_ERROR(errctx);
|
PREPARE_ERROR(errctx);
|
||||||
int64_t i = 0;
|
int64_t i = 0;
|
||||||
|
int64_t entry = 0;
|
||||||
|
|
||||||
FAIL_ZERO_RETURN(errctx, (obj != NULL), AKERR_NULLPOINTER, "NULL runtime in data_scan");
|
FAIL_ZERO_RETURN(errctx, (obj != NULL), AKERR_NULLPOINTER, "NULL runtime in data_scan");
|
||||||
|
FAIL_ZERO_RETURN(errctx, (obj->environment != NULL), AKERR_NULLPOINTER,
|
||||||
|
"Runtime has no environment; call akbasic_runtime_init() first");
|
||||||
|
entry = obj->environment->lineno;
|
||||||
PASS(errctx, akbasic_data_state_init(&obj->data_state));
|
PASS(errctx, akbasic_data_state_init(&obj->data_state));
|
||||||
for ( i = 0; i < AKBASIC_MAX_SOURCE_LINES; i++ ) {
|
for ( i = 0; i < AKBASIC_MAX_SOURCE_LINES; i++ ) {
|
||||||
if ( obj->source[i].code[0] != '\0' ) {
|
if ( obj->source[i].code[0] != '\0' ) {
|
||||||
|
/* Keep BASIC's error prefix on the source line being prescanned. */
|
||||||
|
obj->environment->lineno = i;
|
||||||
PASS(errctx, scan_line(&obj->data_state, obj->source[i].code, i));
|
PASS(errctx, scan_line(&obj->data_state, obj->source[i].code, i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
obj->environment->lineno = entry;
|
||||||
SUCCEED_RETURN(errctx);
|
SUCCEED_RETURN(errctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ struct akbasic_TargetWalk
|
|||||||
* rewritten: `GOTO 9999` in a program with no line 9999 is already broken, and
|
* rewritten: `GOTO 9999` in a program with no line 9999 is already broken, and
|
||||||
* inventing a destination for it would hide that.
|
* inventing a destination for it would hide that.
|
||||||
*/
|
*/
|
||||||
static int64_t mapped(const int16_t *map, int64_t line)
|
static int64_t mapped(const int64_t *map, int64_t line)
|
||||||
{
|
{
|
||||||
if ( line < 0 || line >= AKBASIC_MAX_SOURCE_LINES ) {
|
if ( line < 0 || line >= AKBASIC_MAX_SOURCE_LINES ) {
|
||||||
return line;
|
return line;
|
||||||
@@ -306,7 +306,7 @@ static akerr_ErrorContext *rewrite_line(akbasic_TargetWalk *walk, const char *co
|
|||||||
static akerr_ErrorContext *visit_renumber(akbasic_TargetWalk *walk, int64_t target, char *dest, size_t len)
|
static akerr_ErrorContext *visit_renumber(akbasic_TargetWalk *walk, int64_t target, char *dest, size_t len)
|
||||||
{
|
{
|
||||||
PREPARE_ERROR(errctx);
|
PREPARE_ERROR(errctx);
|
||||||
const int16_t *map = (const int16_t *)walk->self;
|
const int64_t *map = (const int64_t *)walk->self;
|
||||||
int written = 0;
|
int written = 0;
|
||||||
|
|
||||||
PASS(errctx, aksl_snprintf(&written, dest, len, "%" PRId64, mapped(map, target)));
|
PASS(errctx, aksl_snprintf(&written, dest, len, "%" PRId64, mapped(map, target)));
|
||||||
@@ -316,7 +316,8 @@ static akerr_ErrorContext *visit_renumber(akbasic_TargetWalk *walk, int64_t targ
|
|||||||
akerr_ErrorContext *akbasic_renumber(akbasic_Runtime *obj, int64_t newstart, int64_t increment, int64_t oldstart)
|
akerr_ErrorContext *akbasic_renumber(akbasic_Runtime *obj, int64_t newstart, int64_t increment, int64_t oldstart)
|
||||||
{
|
{
|
||||||
PREPARE_ERROR(errctx);
|
PREPARE_ERROR(errctx);
|
||||||
int16_t *map = obj == NULL ? NULL : obj->renumber_map;
|
static int64_t map[AKBASIC_MAX_SOURCE_LINES];
|
||||||
|
static akbasic_SourceLine rewritten[AKBASIC_MAX_SOURCE_LINES];
|
||||||
akbasic_TargetWalk walk = { map, visit_renumber };
|
akbasic_TargetWalk walk = { map, visit_renumber };
|
||||||
int64_t next = newstart;
|
int64_t next = newstart;
|
||||||
int64_t i = 0;
|
int64_t i = 0;
|
||||||
@@ -355,8 +356,10 @@ akerr_ErrorContext *akbasic_renumber(akbasic_Runtime *obj, int64_t newstart, int
|
|||||||
next += increment;
|
next += increment;
|
||||||
}
|
}
|
||||||
|
|
||||||
PASS(errctx, aksl_memset(obj->renumber_visited, 0, sizeof(obj->renumber_visited)));
|
PASS(errctx, aksl_memset(rewritten, 0, sizeof(rewritten)));
|
||||||
for ( i = 0; i < AKBASIC_MAX_SOURCE_LINES; i++ ) {
|
for ( i = 0; i < AKBASIC_MAX_SOURCE_LINES; i++ ) {
|
||||||
|
int64_t target = 0;
|
||||||
|
|
||||||
if ( obj->source[i].code[0] == '\0' ) {
|
if ( obj->source[i].code[0] == '\0' ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -364,62 +367,20 @@ akerr_ErrorContext *akbasic_renumber(akbasic_Runtime *obj, int64_t newstart, int
|
|||||||
* Every line is rewritten, not just the moved ones: a line before
|
* Every line is rewritten, not just the moved ones: a line before
|
||||||
* `oldstart` can branch into the region that moved.
|
* `oldstart` can branch into the region that moved.
|
||||||
*/
|
*/
|
||||||
|
target = mapped(map, i);
|
||||||
PASS(errctx, rewrite_line(&walk, obj->source[i].code,
|
PASS(errctx, rewrite_line(&walk, obj->source[i].code,
|
||||||
obj->renumber_line.code, sizeof(obj->renumber_line.code)));
|
rewritten[target].code, sizeof(rewritten[target].code)));
|
||||||
obj->renumber_line.lineno = i;
|
rewritten[target].lineno = target;
|
||||||
/*
|
/*
|
||||||
* Every line comes out numbered, whether or not it went in that way.
|
* Every line comes out numbered, whether or not it went in that way.
|
||||||
* Asking for numbers is what RENUMBER is, and a program that has been
|
* Asking for numbers is what RENUMBER is, and a program that has been
|
||||||
* through it can be branched into by number -- which is the whole point
|
* through it can be branched into by number -- which is the whole point
|
||||||
* of running it over source that arrived without any.
|
* of running it over source that arrived without any.
|
||||||
*/
|
*/
|
||||||
obj->renumber_line.numbered = true;
|
rewritten[target].numbered = true;
|
||||||
PASS(errctx, aksl_memcpy(&obj->source[i], &obj->renumber_line,
|
|
||||||
sizeof(obj->source[i])));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Move the already-rewritten lines in place. The map is a partial
|
PASS(errctx, aksl_memcpy(obj->source, rewritten, sizeof(obj->source)));
|
||||||
* permutation: a chain ends at an empty slot, while a cycle closes back
|
|
||||||
* on its starting line. A single displaced line is sufficient for both. */
|
|
||||||
for ( i = 0; i < AKBASIC_MAX_SOURCE_LINES; i++ ) {
|
|
||||||
int64_t current = i;
|
|
||||||
akbasic_SourceLine displaced;
|
|
||||||
akbasic_SourceLine next_line;
|
|
||||||
|
|
||||||
if ( map[i] < 0 || obj->renumber_visited[i] ) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
PASS(errctx, aksl_memcpy(&displaced, &obj->source[i], sizeof(displaced)));
|
|
||||||
for ( ;; ) {
|
|
||||||
int64_t destination = map[current];
|
|
||||||
|
|
||||||
obj->renumber_visited[current] = 1;
|
|
||||||
if ( destination == i ) {
|
|
||||||
displaced.lineno = destination;
|
|
||||||
PASS(errctx, aksl_memcpy(&obj->source[destination], &displaced,
|
|
||||||
sizeof(displaced)));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if ( map[destination] < 0 ) {
|
|
||||||
displaced.lineno = destination;
|
|
||||||
PASS(errctx, aksl_memcpy(&obj->source[destination], &displaced,
|
|
||||||
sizeof(displaced)));
|
|
||||||
PASS(errctx, aksl_memset(&obj->source[current], 0,
|
|
||||||
sizeof(obj->source[current])));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
PASS(errctx, aksl_memcpy(&next_line, &obj->source[destination],
|
|
||||||
sizeof(displaced)));
|
|
||||||
displaced.lineno = destination;
|
|
||||||
PASS(errctx, aksl_memcpy(&obj->source[destination], &displaced,
|
|
||||||
sizeof(obj->renumber_line)));
|
|
||||||
PASS(errctx, aksl_memset(&obj->source[current], 0,
|
|
||||||
sizeof(obj->source[current])));
|
|
||||||
PASS(errctx, aksl_memcpy(&displaced, &next_line,
|
|
||||||
sizeof(displaced)));
|
|
||||||
current = destination;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SUCCEED_RETURN(errctx);
|
SUCCEED_RETURN(errctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -474,6 +435,7 @@ akerr_ErrorContext *akbasic_runtime_check_targets(akbasic_Runtime *obj)
|
|||||||
* step(). Nothing is read back out of it -- the walk needs somewhere to put
|
* step(). Nothing is read back out of it -- the walk needs somewhere to put
|
||||||
* the text it would have written, and this is it.
|
* the text it would have written, and this is it.
|
||||||
*/
|
*/
|
||||||
|
static char discard[AKBASIC_MAX_LINE_LENGTH * 2];
|
||||||
CheckState state = { NULL, 0 };
|
CheckState state = { NULL, 0 };
|
||||||
akbasic_TargetWalk walk = { &state, visit_check };
|
akbasic_TargetWalk walk = { &state, visit_check };
|
||||||
int64_t entry = 0;
|
int64_t entry = 0;
|
||||||
@@ -501,8 +463,7 @@ akerr_ErrorContext *akbasic_runtime_check_targets(akbasic_Runtime *obj)
|
|||||||
* the whole point of setting it.
|
* the whole point of setting it.
|
||||||
*/
|
*/
|
||||||
obj->environment->lineno = i;
|
obj->environment->lineno = i;
|
||||||
PASS(errctx, rewrite_line(&walk, obj->source[i].code,
|
PASS(errctx, rewrite_line(&walk, obj->source[i].code, discard, sizeof(discard)));
|
||||||
obj->renumber_discard, sizeof(obj->renumber_discard)));
|
|
||||||
}
|
}
|
||||||
/* Nothing was refused, so leave the cursor as the caller had it. */
|
/* Nothing was refused, so leave the cursor as the caller had it. */
|
||||||
obj->environment->lineno = entry;
|
obj->environment->lineno = entry;
|
||||||
|
|||||||
@@ -1600,17 +1600,22 @@ akerr_ErrorContext *akbasic_runtime_scan_labels(akbasic_Runtime *obj)
|
|||||||
PREPARE_ERROR(errctx);
|
PREPARE_ERROR(errctx);
|
||||||
akbasic_Environment *root = NULL;
|
akbasic_Environment *root = NULL;
|
||||||
int64_t i = 0;
|
int64_t i = 0;
|
||||||
|
int64_t entry = 0;
|
||||||
|
|
||||||
FAIL_ZERO_RETURN(errctx, (obj != NULL), AKERR_NULLPOINTER, "NULL runtime in scan_labels");
|
FAIL_ZERO_RETURN(errctx, (obj != NULL), AKERR_NULLPOINTER, "NULL runtime in scan_labels");
|
||||||
FAIL_ZERO_RETURN(errctx, (obj->environment != NULL), AKERR_NULLPOINTER,
|
FAIL_ZERO_RETURN(errctx, (obj->environment != NULL), AKERR_NULLPOINTER,
|
||||||
"Runtime has no environment; call akbasic_runtime_init() first");
|
"Runtime has no environment; call akbasic_runtime_init() first");
|
||||||
for ( root = obj->environment; root->parent != NULL; root = root->parent ) {
|
for ( root = obj->environment; root->parent != NULL; root = root->parent ) {
|
||||||
}
|
}
|
||||||
|
entry = obj->environment->lineno;
|
||||||
for ( i = 0; i < AKBASIC_MAX_SOURCE_LINES; i++ ) {
|
for ( i = 0; i < AKBASIC_MAX_SOURCE_LINES; i++ ) {
|
||||||
if ( obj->source[i].code[0] != '\0' ) {
|
if ( obj->source[i].code[0] != '\0' ) {
|
||||||
|
/* Keep BASIC's error prefix on the source line being prescanned. */
|
||||||
|
obj->environment->lineno = i;
|
||||||
PASS(errctx, scan_line_labels(root, obj->source[i].code, i));
|
PASS(errctx, scan_line_labels(root, obj->source[i].code, i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
obj->environment->lineno = entry;
|
||||||
SUCCEED_RETURN(errctx);
|
SUCCEED_RETURN(errctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -260,11 +260,13 @@ static akerr_ErrorContext *scan_names(akbasic_Runtime *obj)
|
|||||||
size_t namelen = 0;
|
size_t namelen = 0;
|
||||||
bool matched = false;
|
bool matched = false;
|
||||||
const akbasic_Verb *verb = NULL;
|
const akbasic_Verb *verb = NULL;
|
||||||
|
int64_t entry = obj->environment->lineno;
|
||||||
|
|
||||||
for ( i = 0; i < AKBASIC_MAX_SOURCE_LINES; i++ ) {
|
for ( i = 0; i < AKBASIC_MAX_SOURCE_LINES; i++ ) {
|
||||||
if ( obj->source[i].code[0] == '\0' ) {
|
if ( obj->source[i].code[0] == '\0' ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
obj->environment->lineno = i;
|
||||||
cursor = next_word(skip_lineno(obj->source[i].code), word, sizeof(word));
|
cursor = next_word(skip_lineno(obj->source[i].code), word, sizeof(word));
|
||||||
|
|
||||||
PASS(errctx, word_is(word, "END", &matched));
|
PASS(errctx, word_is(word, "END", &matched));
|
||||||
@@ -327,6 +329,7 @@ static akerr_ErrorContext *scan_names(akbasic_Runtime *obj)
|
|||||||
|
|
||||||
FAIL_NONZERO_RETURN(errctx, (open >= 0), AKBASIC_ERR_SYNTAX,
|
FAIL_NONZERO_RETURN(errctx, (open >= 0), AKBASIC_ERR_SYNTAX,
|
||||||
"TYPE %s is never closed with END TYPE", table->types[open >= 0 ? open : 0].name);
|
"TYPE %s is never closed with END TYPE", table->types[open >= 0 ? open : 0].name);
|
||||||
|
obj->environment->lineno = entry;
|
||||||
SUCCEED_RETURN(errctx);
|
SUCCEED_RETURN(errctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -440,7 +443,7 @@ static akerr_ErrorContext *parse_field(akbasic_StructTypeTable *table, akbasic_S
|
|||||||
* each other by value, which has no finite size. That is the diagnosis rather
|
* each other by value, which has no finite size. That is the diagnosis rather
|
||||||
* than a stack overflow later.
|
* than a stack overflow later.
|
||||||
*/
|
*/
|
||||||
static akerr_ErrorContext *resolve_sizes(akbasic_StructTypeTable *table)
|
static akerr_ErrorContext *resolve_sizes(akbasic_Runtime *runtime, akbasic_StructTypeTable *table)
|
||||||
{
|
{
|
||||||
PREPARE_ERROR(errctx);
|
PREPARE_ERROR(errctx);
|
||||||
bool progress = true;
|
bool progress = true;
|
||||||
@@ -477,6 +480,7 @@ static akerr_ErrorContext *resolve_sizes(akbasic_StructTypeTable *table)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for ( i = 0; i < table->count; i++ ) {
|
for ( i = 0; i < table->count; i++ ) {
|
||||||
|
runtime->environment->lineno = table->types[i].firstline;
|
||||||
FAIL_NONZERO_RETURN(errctx, (table->types[i].slotcount < 0), AKBASIC_ERR_VALUE,
|
FAIL_NONZERO_RETURN(errctx, (table->types[i].slotcount < 0), AKBASIC_ERR_VALUE,
|
||||||
"TYPE %s contains itself by value, so it has no size. "
|
"TYPE %s contains itself by value, so it has no size. "
|
||||||
"A type may only refer to itself through PTR TO",
|
"A type may only refer to itself through PTR TO",
|
||||||
@@ -493,9 +497,13 @@ akerr_ErrorContext *akbasic_structtype_scan(akbasic_Runtime *obj)
|
|||||||
akbasic_StructTypeTable *table = NULL;
|
akbasic_StructTypeTable *table = NULL;
|
||||||
int64_t i = 0;
|
int64_t i = 0;
|
||||||
int t = 0;
|
int t = 0;
|
||||||
|
int64_t entry = 0;
|
||||||
|
|
||||||
FAIL_ZERO_RETURN(errctx, (obj != NULL), AKERR_NULLPOINTER, "NULL runtime in structtype scan");
|
FAIL_ZERO_RETURN(errctx, (obj != NULL), AKERR_NULLPOINTER, "NULL runtime in structtype scan");
|
||||||
|
FAIL_ZERO_RETURN(errctx, (obj->environment != NULL), AKERR_NULLPOINTER,
|
||||||
|
"Runtime has no environment; call akbasic_runtime_init() first");
|
||||||
table = &obj->structtypes;
|
table = &obj->structtypes;
|
||||||
|
entry = obj->environment->lineno;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Drop what the *script* declared and keep what the *host* registered.
|
* Drop what the *script* declared and keep what the *host* registered.
|
||||||
@@ -525,10 +533,12 @@ akerr_ErrorContext *akbasic_structtype_scan(akbasic_Runtime *obj)
|
|||||||
if ( obj->source[i].code[0] == '\0' ) {
|
if ( obj->source[i].code[0] == '\0' ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
obj->environment->lineno = i;
|
||||||
PASS(errctx, parse_field(table, type, obj->source[i].code, i));
|
PASS(errctx, parse_field(table, type, obj->source[i].code, i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PASS(errctx, resolve_sizes(table));
|
PASS(errctx, resolve_sizes(obj, table));
|
||||||
|
obj->environment->lineno = entry;
|
||||||
SUCCEED_RETURN(errctx);
|
SUCCEED_RETURN(errctx);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
* below.
|
* below.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "harness.h"
|
#include "harness.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -341,6 +343,28 @@ static akerr_ErrorContext AKERR_NOIGNORE *test_prescan_boundaries(void)
|
|||||||
SUCCEED_RETURN(errctx);
|
SUCCEED_RETURN(errctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @brief A full label table reports the line whose label could not be filed. */
|
||||||
|
static void test_label_prescan_error_line(void)
|
||||||
|
{
|
||||||
|
char source[4096] = "";
|
||||||
|
size_t used = 0;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
for ( i = 1; i <= AKBASIC_MAX_LABELS + 1; i++ ) {
|
||||||
|
used += (size_t)snprintf(source + used, sizeof(source) - used,
|
||||||
|
"%d LABEL L%d\n", i, i);
|
||||||
|
}
|
||||||
|
(void)snprintf(source + used, sizeof(source) - used, "100 PRINT 1\n");
|
||||||
|
|
||||||
|
TEST_REQUIRE_OK(harness_start(NULL));
|
||||||
|
TEST_REQUIRE_OK(akbasic_runtime_load(&HARNESS_RUNTIME, source));
|
||||||
|
TEST_REQUIRE_OK(akbasic_runtime_start(&HARNESS_RUNTIME, AKBASIC_MODE_RUN));
|
||||||
|
TEST_REQUIRE(strstr(HARNESS_OUTPUT, "? 65 : PARSE ERROR") != NULL,
|
||||||
|
"a full label table should report its source line, got \"%s\"",
|
||||||
|
HARNESS_OUTPUT);
|
||||||
|
harness_stop();
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
PREPARE_ERROR(errctx);
|
PREPARE_ERROR(errctx);
|
||||||
@@ -355,6 +379,7 @@ int main(void)
|
|||||||
CATCH(errctx, test_undefined_label_is_reported());
|
CATCH(errctx, test_undefined_label_is_reported());
|
||||||
CATCH(errctx, test_arm_refusals());
|
CATCH(errctx, test_arm_refusals());
|
||||||
CATCH(errctx, test_prescan_boundaries());
|
CATCH(errctx, test_prescan_boundaries());
|
||||||
|
test_label_prescan_error_line();
|
||||||
} CLEANUP {
|
} CLEANUP {
|
||||||
} PROCESS(errctx) {
|
} PROCESS(errctx) {
|
||||||
} HANDLE_DEFAULT(errctx) {
|
} HANDLE_DEFAULT(errctx) {
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
? 90 : PARSE ERROR TYPE POINT: POINT is a reserved word and cannot name a type
|
? 60 : PARSE ERROR TYPE POINT: POINT is a reserved word and cannot name a type
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
* TODO.md section 6.
|
* TODO.md section 6.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <akbasic/error.h>
|
#include <akbasic/error.h>
|
||||||
@@ -174,6 +175,34 @@ static void test_colon_ends_data(void)
|
|||||||
harness_stop();
|
harness_stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @brief DATA overflow reports the line where the item limit was crossed. */
|
||||||
|
static void test_data_prescan_error_line(void)
|
||||||
|
{
|
||||||
|
char source[4096] = "";
|
||||||
|
size_t used = 0;
|
||||||
|
int line = 0;
|
||||||
|
int item = 0;
|
||||||
|
|
||||||
|
for ( line = 1; line <= 34; line++ ) {
|
||||||
|
used += (size_t)snprintf(source + used, sizeof(source) - used, "%d DATA ", line);
|
||||||
|
for ( item = 0; item < 15; item++ ) {
|
||||||
|
used += (size_t)snprintf(source + used, sizeof(source) - used,
|
||||||
|
"%s1", (item == 0 ? "" : ","));
|
||||||
|
}
|
||||||
|
used += (size_t)snprintf(source + used, sizeof(source) - used, "\n");
|
||||||
|
}
|
||||||
|
used += (size_t)snprintf(source + used, sizeof(source) - used, "100 DATA 1,1\n");
|
||||||
|
(void)snprintf(source + used, sizeof(source) - used, "101 DATA 1\n200 PRINT 1\n");
|
||||||
|
|
||||||
|
TEST_REQUIRE_OK(harness_start(NULL));
|
||||||
|
TEST_REQUIRE_OK(akbasic_runtime_load(&HARNESS_RUNTIME, source));
|
||||||
|
TEST_REQUIRE_OK(akbasic_runtime_start(&HARNESS_RUNTIME, AKBASIC_MODE_RUN));
|
||||||
|
TEST_REQUIRE(strstr(HARNESS_OUTPUT, "? 101 : PARSE ERROR") != NULL,
|
||||||
|
"DATA overflow should report its source line, got \"%s\"",
|
||||||
|
HARNESS_OUTPUT);
|
||||||
|
harness_stop();
|
||||||
|
}
|
||||||
|
|
||||||
/** @brief A float item fills a float variable with its fractional part intact. */
|
/** @brief A float item fills a float variable with its fractional part intact. */
|
||||||
static void test_float_items(void)
|
static void test_float_items(void)
|
||||||
{
|
{
|
||||||
@@ -227,6 +256,7 @@ int main(void)
|
|||||||
test_type_mismatch();
|
test_type_mismatch();
|
||||||
test_quoted_items();
|
test_quoted_items();
|
||||||
test_colon_ends_data();
|
test_colon_ends_data();
|
||||||
|
test_data_prescan_error_line();
|
||||||
test_float_items();
|
test_float_items();
|
||||||
test_negative_items();
|
test_negative_items();
|
||||||
return akbasic_test_failures;
|
return akbasic_test_failures;
|
||||||
|
|||||||
@@ -218,6 +218,22 @@ static void test_declaration_errors_are_basic_errors(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @brief A field declaration error reports the field's source line. */
|
||||||
|
static void test_type_prescan_error_line(void)
|
||||||
|
{
|
||||||
|
TEST_REQUIRE_OK(harness_start(NULL));
|
||||||
|
TEST_REQUIRE_OK(akbasic_runtime_load(&HARNESS_RUNTIME,
|
||||||
|
"10 TYPE RECT\n"
|
||||||
|
"20 W# EXTRA\n"
|
||||||
|
"30 END TYPE\n"
|
||||||
|
"40 PRINT 1\n"));
|
||||||
|
TEST_REQUIRE_OK(akbasic_runtime_start(&HARNESS_RUNTIME, AKBASIC_MODE_RUN));
|
||||||
|
TEST_REQUIRE(strstr(HARNESS_OUTPUT, "? 20 : PARSE ERROR") != NULL,
|
||||||
|
"TYPE prescan should report its source line, got \"%s\"",
|
||||||
|
HARNESS_OUTPUT);
|
||||||
|
harness_stop();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief An over-long type or field name is refused, not silently trimmed.
|
* @brief An over-long type or field name is refused, not silently trimmed.
|
||||||
*
|
*
|
||||||
@@ -270,6 +286,7 @@ int main(void)
|
|||||||
test_missing_field_lists_the_others();
|
test_missing_field_lists_the_others();
|
||||||
test_self_by_value_refused();
|
test_self_by_value_refused();
|
||||||
test_declaration_errors_are_basic_errors();
|
test_declaration_errors_are_basic_errors();
|
||||||
|
test_type_prescan_error_line();
|
||||||
test_long_names_are_refused();
|
test_long_names_are_refused();
|
||||||
|
|
||||||
return akbasic_test_failures;
|
return akbasic_test_failures;
|
||||||
|
|||||||
Reference in New Issue
Block a user