1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-11 13:55:55 +03:00
mal/impls/bbc-basic
Nicolas Boulenguez fbfe6784d2 Change quasiquote algorithm
- Add a `vec` built-in function in step7 so that `quasiquote` does not
  require `apply` from step9.
- Introduce quasiquoteexpand special in order to help debugging step7.
  This may also prepare newcomers to understand step8.
- Add soft tests.
- Do not quote numbers, strings and so on.

Should ideally have been in separate commits:
- elisp: simplify and fix (keyword :k)
- factor: fix copy/paste error in let*/step7, simplify eval-ast.
- guile: improve list/vector types
- haskell: revert evaluation during quasiquote
- logo, make: cosmetic issues
2020-08-11 01:01:56 +02:00
..
riscos Move implementations into impls/ dir 2020-02-10 23:50:16 -06:00
core Move implementations into impls/ dir 2020-02-10 23:50:16 -06:00
core.bas Change quasiquote algorithm 2020-08-11 01:01:56 +02:00
Dockerfile Move implementations into impls/ dir 2020-02-10 23:50:16 -06:00
env Move implementations into impls/ dir 2020-02-10 23:50:16 -06:00
env.bas Move implementations into impls/ dir 2020-02-10 23:50:16 -06:00
Makefile Move implementations into impls/ dir 2020-02-10 23:50:16 -06:00
printer Move implementations into impls/ dir 2020-02-10 23:50:16 -06:00
printer.bas Move implementations into impls/ dir 2020-02-10 23:50:16 -06:00
reader Move implementations into impls/ dir 2020-02-10 23:50:16 -06:00
reader.bas Move implementations into impls/ dir 2020-02-10 23:50:16 -06:00
README.md Move implementations into impls/ dir 2020-02-10 23:50:16 -06:00
run Move implementations into impls/ dir 2020-02-10 23:50:16 -06:00
step0_repl.bas Move implementations into impls/ dir 2020-02-10 23:50:16 -06:00
step1_read_print.bas Move implementations into impls/ dir 2020-02-10 23:50:16 -06:00
step2_eval.bas Move implementations into impls/ dir 2020-02-10 23:50:16 -06:00
step3_env.bas Move implementations into impls/ dir 2020-02-10 23:50:16 -06:00
step4_if_fn_do.bas Move implementations into impls/ dir 2020-02-10 23:50:16 -06:00
step5_tco.bas Move implementations into impls/ dir 2020-02-10 23:50:16 -06:00
step6_file.bas Move implementations into impls/ dir 2020-02-10 23:50:16 -06:00
step7_quote.bas Change quasiquote algorithm 2020-08-11 01:01:56 +02:00
step8_macros.bas Change quasiquote algorithm 2020-08-11 01:01:56 +02:00
step9_try.bas Change quasiquote algorithm 2020-08-11 01:01:56 +02:00
stepA_mal.bas Change quasiquote algorithm 2020-08-11 01:01:56 +02:00
types Move implementations into impls/ dir 2020-02-10 23:50:16 -06:00
types.bas Move implementations into impls/ dir 2020-02-10 23:50:16 -06: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