Why Full BASIC needed a conformance suite that didn't depend on it, how the FBCS is built, and what it found in my own interpreter before I published it.
On 31 October I had a Full BASIC interpreter with 3,163 automated tests, all passing, and a document claiming conformance with ANSI X3.113-1987, chapter by chapter. That day an audit I had commissioned against the text of the standard came back, and its first sentence was this:
The interpreter cannot be declared conformant to ANSI X3.113 or ECMA-116 today.
It found fifteen non-conformities that weren't recorded anywhere. Some produced wrong results without any warning; others rejected perfectly valid programs. Not one of the 3,163 tests had caught them.
Full BASIC is the structured BASIC of 1987, the one that was written down in a standard and that almost nobody ever implemented in full, and building an interpreter that met the whole standard was exactly what interested me. That audit made me prove it with more than my own tests, and that's where the Full BASIC Conformance Suite (FBCS) came from, which I published separately under the MIT licence.
For Minimal BASIC, the small BASIC of 1978 (ANSI X3.60 / ECMA-55), the National Bureau of Standards published a set of test programs. Each program exercises one aspect of the language, checks the result itself and prints whether it passed. You just run it, without needing to know anything about the interpreter.
Those programs were with me while I built Minimal BASIC and then Full BASIC. For the big 1987 standard I found nothing equivalent, and the NBS programs can't simply be reused either, because the two standards sometimes disagree.
An example. NBS program P028 divides by zero and expects the interpreter to report it, supply "machine infinity" and carry on, which is the correct behaviour in Minimal BASIC. In Full BASIC, division by zero is a fatal exception (code 3001): without a handler, the program stops there. A Full BASIC interpreter that passed P028 as written would be breaking its own standard. Those programs ended up in a separate folder, with the expected result corrected and a variant that wraps the division in WHEN EXCEPTION … USE … END WHEN to make use of the rest of the test.
The audit traced the cause to where each test's correct answer came from.
Many of the expected results had been generated by running the interpreter itself: I would write the program, run it, glance over the output and save it as the reference. If the interpreter got something plausibly wrong, the mistake was saved as the right answer. A test like that checks that the interpreter does today what it did yesterday. On top of that, the tests followed the paths I already knew about and often read a value without checking that it was written back.
The clearest finding was parameter passing. In Full BASIC, if you call a subroutine with an array element, CALL S(A(1)), the subroutine receives that element, and whatever it assigns to the parameter changes A(1). My interpreter made a copy and wrote it back at the end. In almost every program the result is the same, which is why nobody noticed. It breaks with CALL S(A(1), A(1)), and it breaks when the subroutine touches the array directly in the meantime.
There was more. Three of the eight PRINT USING examples in the standard itself produced different output. DATA, ANGLE, MAX and SIZE couldn't be used as variable names, although the standard doesn't reserve them. And something outside the code was missing: the standard requires everything it leaves to the implementation to be documented where the user can find it, and the manual appendix meant for that was an empty template. That alone ruled out a conformance claim.
To measure the real extent, 595 new programs were written from the text of the standard alone, without looking at the interpreter. In 133 of them the output didn't match. After a careful reread of the standard, 58 turned out to be misreadings in the test and 75 were real bugs.
The underlying rule is that the correct answer comes from the standard, never from the interpreter. Everything else follows from that.
Claims in its own words. Every statement the suite makes about the language is a claim that cites the clause it comes from. For example:
- id: A-9.2.4.1-01
clause: "9.2.4.1"
claim: "An array element given as a subprogram argument is passed by
reference, so assigning to the parameter changes the element."
tests: [SEG-0142, SEG-0159, SEG-0160, SEG-0161, SEG-0162, ...]
The text of the standards is under copyright and the suite doesn't reproduce it: a tool rejects any claim that copies more than eight consecutive words. Writing them this way also forces you to understand each clause, because you can't paraphrase what you haven't understood.
Programs that decide. Each claim points to one or more small BASIC programs. This is one of the programs that checks the claim above:
1 REM FBCS SEG-0159
2 REM CLAIM A-9.2.4.1-01
3 REM TYPE SELF
99 DECLARE SUB S
100 PRINT "SEG-0159 STRING ARRAY ELEMENT PASSED BY REFERENCE (9.2.4.1)"
110 DIM A$(2)
120 LET A$(1) = "A"
130 CALL S(A$(1))
140 IF A$(1) = "Z" THEN PRINT "*** TEST PASSED ***" ELSE PRINT "*** TEST FAILED ***"
150 SUB S(Y$)
160 LET Y$ = "Z"
170 END SUB
180 END
It's a SELF test, like the NBS ones, which checks itself. OUTPUT tests compare the exact output; REJECT tests require the interpreter to refuse a non-conformant program; FATAL and WARN tests, the right exception code on the right line. The graphics tests compare a log of the drawing primitives, because pixels vary from one interpreter to another.
A runner with no dependencies. To run the suite against an interpreter, all you need is to be able to call it from the command line:
python3 tools/run_suite.py --interpreter 'myinterp {file}' \
--name 'MyInterp 1.0' --output results/myinterp.json
It uses only the Python 3 standard library, so there is nothing to install.
Generated statements. Both conformance statements, for ANSI and for ECMA-116, are generated from the results and include only claims whose tests pass. Anything without a passing test doesn't appear. The statement of 31 October, written by hand, had claimed more than it could back up.
Fixing those fifteen didn't tell me whether there were fifteen more. I needed reviews that started from scratch.
There were several rounds of what I called clean-room audits. Each auditor gets only the text of the standard and the compiled interpreter, with no project documentation, no suite, no tests and no change history. Expectations come only from the standard, and behaviour only from running programs. Every finding has to come with a program that reproduces it.
The one on 7 November had eight auditors, one per area (control flow, strings and arrays, numbers, exceptions, files, graphics, input and output, and ECMA-116), with scores from 82 to 93. They found, for instance, that MAT PRINT ignored the line margin and that certain combinations of SET POINTER after MAT WRITE raised an error they shouldn't. Each finding became a new claim with its program, and stayed in the suite.
A standard this size leaves gaps and sometimes surprises, and the suite forces you to write down what was decided in each case.
Reserved words are a good example. The easy option would have been to reserve every function name, but the standard reserves only eighteen spellings. Everything else can be used as a variable name, and then, within that scope, the corresponding function is no longer available. Followed to the letter, that means a program that does LET SIN = 1 and then calls SIN(0) in the same unit must be rejected, and there's a test that checks it.
Another: a FOR … STEP 0 loop never ends. That's what the standard says, and it's decided and tested.
From the start I thought the suite should be published separately from the interpreter. The interpreter is closed source, and without an open suite any conformance claim I make is a self-declaration nobody can check.
Getting it ready took more work than I expected. The suite had been written for my own use: 339 claim notes and some 135 programs referred to internal tasks, private documents or interpreter source files, and part of it was in Spanish. I cleaned it up at the source, so that what's published is exactly what gets verified. Everything was rewritten in English for an outside reader, and the checking tool now rejects any internal reference.
Version 1.0 came out on 12 November, and 1.0.1 the same day. Going back over the ECMA-116 claims, I found that the eight "known deviations" the suite declared from that standard were false. My copy of ECMA-116 is a scan run through OCR, and some came from lost characters: what I had read as READ X, , Z was READ X, Y, Z. Others came from examples that were fragments of a statement; one from a test that was missing OPTION ARITHMETIC FIXED; and two from interpreter fixes I hadn't carried over to the text. Today the only real difference from ECMA-116 is an erratum in ECMA's own section 11.3.2.
The FBCS has 2,085 test programs backing 1,270 claims about ANSI X3.113-1987 and 787 about ECMA-116, and Full BASIC passes them all. No standards body endorses it, so it isn't a certification either; it's a way of making "conformant" mean something you can check.
It's on GitHub under the MIT licence, and there's more detail on the Full BASIC open-source page. If you maintain a BASIC interpreter, or feel like writing one, run the suite against it. I'd love to hear what it finds.