1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-11 13:55:55 +03:00
mal/bbc-basic
Nicolas Boulenguez e6d41de4d5 load-file: accept empty file or final comment, return nil
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.
2019-07-28 13:08:05 +02:00
..
riscos bbc-basic: Add step A to the RISC OS tokenizing script. 2019-05-18 16:32:52 +01:00
core bbc-basic: Fix accidental quadratic behaviour in string handling. 2019-05-27 22:51:09 +01:00
Dockerfile bbc-basic: Don't try to add "deb-src" entries in Dockerfile. 2019-05-18 16:34:01 +01:00
env bbc-basic: Make sure that '&' parameters are in a list, not a vector. 2019-05-18 05:48:32 +01:00
Makefile bbc-basic: Add a minimal Makefile. 2019-05-19 00:20:38 +01:00
printer bbc-basic: Clean up long-string support. 2019-05-27 14:25:13 +01:00
reader bbc-basic: Support strings longer than the underlying interpreter allows. 2019-05-18 22:56:20 +01:00
README.md bbc-basic: Remove the word "partial" from the README. 2019-05-27 14:25:13 +01:00
run bbc-basic: Enlarge Brandy's heap size. 2019-05-30 23:02:53 +01:00
step0_repl.bbc bbc-basic: Abolish "malio" abstraction. 2019-05-18 05:48:32 +01:00
step1_read_print.bbc bbc-basic: Support strings longer than the underlying interpreter allows. 2019-05-18 22:56:20 +01:00
step2_eval.bbc bbc-basic: Support strings longer than the underlying interpreter allows. 2019-05-18 22:56:20 +01:00
step3_env.bbc bbc-basic: Support strings longer than the underlying interpreter allows. 2019-05-18 22:56:20 +01:00
step4_if_fn_do.bbc bbc-basic: Support strings longer than the underlying interpreter allows. 2019-05-18 22:56:20 +01:00
step5_tco.bbc bbc-basic: Support strings longer than the underlying interpreter allows. 2019-05-18 22:56:20 +01:00
step6_file.bbc load-file: accept empty file or final comment, return nil 2019-07-28 13:08:05 +02:00
step7_quote.bbc load-file: accept empty file or final comment, return nil 2019-07-28 13:08:05 +02:00
step8_macros.bbc load-file: accept empty file or final comment, return nil 2019-07-28 13:08:05 +02:00
step9_try.bbc load-file: accept empty file or final comment, return nil 2019-07-28 13:08:05 +02:00
stepA_mal.bbc load-file: accept empty file or final comment, return nil 2019-07-28 13:08:05 +02:00
toktest bbc-basic: Tokenizer based on a DFA. 2019-05-18 05:48:32 +01:00
types bbc-basic: Slight tweak to heap size. 2019-05-30 22:31:12 +01:00

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