Let `load-file` append a new line in case last line contains a comment. Also append `nil` so that the return value is predictible. Remove the existing explicit `nil` from existing sources. Adapt documentation and tests. |
||
---|---|---|
.. | ||
riscos | ||
core | ||
Dockerfile | ||
env | ||
Makefile | ||
printer | ||
reader | ||
README.md | ||
run | ||
step0_repl.bbc | ||
step1_read_print.bbc | ||
step2_eval.bbc | ||
step3_env.bbc | ||
step4_if_fn_do.bbc | ||
step5_tco.bbc | ||
step6_file.bbc | ||
step7_quote.bbc | ||
step8_macros.bbc | ||
step9_try.bbc | ||
stepA_mal.bbc | ||
toktest | ||
types |
Introduction
This is an implementation of mal in BBC BASIC V. While there is already an implementation of mal in BASIC (in the "basic" directory), it's targeted at much more primitive versions of BASIC and relies on a pre-processor, both of which make it fairly un-idiomatic as a BBC BASIC V program.
BBC BASIC V is the version of BBC BASIC supplied with Acorn's ARM-based computers from the mid-1980s. It has substantial enhancements from the 6502-based versions of BBC BASIC, which were themselves at the advanced end of 8-bit BASICs. Mal uses many of the advanced features of BBC BASIC V and porting it to older versions would be difficult.
Mal is intended to run on all versions of BBC BASIC V and BBC BASIC VI, as well as on Brandy 1.20.1. For compatibility with Brandy, it avoids operating system calls where possible. The only exception is that is has separate mechanisms for reading command-line arguments under Brandy and RISC OS.
Running under Unix
On Unix systems, this mal implementation can run on the Brandy interpreter. The tests require the "simple text" build, but mal will work interactively in graphical builds as well. You can invoke mal like this:
cd bbc-basic
brandy stepA_mal.bbc
Running under RISC OS
To run mal under RISC OS, you obviously need to get the files onto
your RISC OS system, and you also need to arrange to tokenize the
BASIC source files. There are scripts to do the latter in the
riscos
directory, but they do require that the mal source tree be
available under RISC OS without its filenames' being truncated, which
may restrict with filing systems can be used. The HostFS supplied
with ArcEm works fine.
Once you have the files in RISC OS, you can set things up by running:
*Dir bbc-basic.riscos
*Run setup
Then you can invoke the interpreter directly:
*Run stepA_mal
At present, there's no filename translation in the slurp
function,
so many of the example mal programs will fail because they can't load
core.mal
.
Interesting features
This appears to be the first mal implementation that uses an table-driven deterministic finite automoton (a state machine) to implement its tokenizer.
The mal heap is represented as a large array of fixed-size objects. Lists and vectors are linked lists of these objects, while hash-maps are crit-bit trees.
Mal exceptions are implemented as BBC BASIC errors. Errors generated by mal are numbered from &40E80900.
Assigned error numbers
No. | Description |
---|---|
&00 | Native mal error generated by 'throw' |
&1x | Object not of type 'x' |
&1F | Miscellaneous type mismatch |
&20 | Invalid operation on empty list |
&21 | Wrong number of arguments to function |
&22 | Undefined symbol |
&23 | Subscript out of range |
&24 | Invalid 'catch*' clause |
&30 | Unexpected end of input |
&31 | Unexpected ')' |
&32 | Hash-map key mush be a string |
&40 | File not found |
&50 | Out of memory |
&Fx | Internal errors (indicating a bug in mal) |
&F0 | Unprintable value |
&F1 | Call to non-existent core function |