jackhill/mal.git
5 years agobbc-basic: Don't try to add "deb-src" entries in Dockerfile.
Ben Harris [Thu, 16 May 2019 09:33:03 +0000 (10:33 +0100)]
bbc-basic: Don't try to add "deb-src" entries in Dockerfile.

Apparently that wasn't necessary, and indeed broke the build, on other
systems.

5 years agobbc-basic: Create a suitable Dockerfile and adapt "run" script.
Ben Harris [Wed, 15 May 2019 21:20:56 +0000 (22:20 +0100)]
bbc-basic: Create a suitable Dockerfile and adapt "run" script.

The dockerfile uses the Ubuntu source package of Brandy to build a
text-only version for testing.  The "run" script no longer depends on
the existence of sbrandy in a particular place in my home directory.

5 years agobbc-basic: Minor README updates.
Ben Harris [Wed, 15 May 2019 19:47:52 +0000 (20:47 +0100)]
bbc-basic: Minor README updates.

5 years agobbc-basic: Refer to the trees we use for hash-maps as "crit-bit trees".
Ben Harris [Wed, 15 May 2019 19:45:50 +0000 (20:45 +0100)]
bbc-basic: Refer to the trees we use for hash-maps as "crit-bit trees".

That seems to be the generic term, with PATRICIA being a particular
early implementaion.

5 years agobbc-basic: Replace PROCmake_macro with FNas_macro.
Ben Harris [Wed, 15 May 2019 19:34:06 +0000 (20:34 +0100)]
bbc-basic: Replace PROCmake_macro with FNas_macro.

FNas_macro makes a copy of its argument, converted into a macro, by
analogy with FNas_list and FNas_vector.

5 years agobbc-basic: Change how empty collections work.
Ben Harris [Wed, 15 May 2019 19:26:36 +0000 (20:26 +0100)]
bbc-basic: Change how empty collections work.

Rather that recognising them by address, they now have a special bit
set in their type words.  That means that adding metadata to an empty
collection doesn't cause it to cease being properly empty.

5 years agobbc-basic: Remove unused PROClist_to_array and FNarray_to_list.
Ben Harris [Wed, 15 May 2019 00:03:52 +0000 (01:03 +0100)]
bbc-basic: Remove unused PROClist_to_array and FNarray_to_list.

5 years agobbc-basic: Upgrade to the gensym-based 'or'.
Ben Harris [Tue, 14 May 2019 22:21:34 +0000 (23:21 +0100)]
bbc-basic: Upgrade to the gensym-based 'or'.

5 years agobbc-basic: Allow metadata on non-function types.
Ben Harris [Tue, 14 May 2019 22:19:26 +0000 (23:19 +0100)]
bbc-basic: Allow metadata on non-function types.

This is currently broken, but it passes all the tests, so I'll need
some better tests.

5 years agobbc-basic: Add 'seq' core function.
Ben Harris [Tue, 14 May 2019 22:17:21 +0000 (23:17 +0100)]
bbc-basic: Add 'seq' core function.

5 years agobbc-basic: Add 'string?', 'number?', 'fn?', and 'macro?' core functions.
Ben Harris [Tue, 14 May 2019 22:07:14 +0000 (23:07 +0100)]
bbc-basic: Add 'string?', 'number?', 'fn?', and 'macro?' core functions.

5 years agobbc-basic: Implement 'conj' core function.
Ben Harris [Tue, 14 May 2019 22:00:52 +0000 (23:00 +0100)]
bbc-basic: Implement 'conj' core function.

5 years agobbc-basic: Add 'time-ms' core function.
Ben Harris [Tue, 14 May 2019 21:54:12 +0000 (22:54 +0100)]
bbc-basic: Add 'time-ms' core function.

It uses TIME, since that's easily available on all platforms.

5 years agobbc-basic: Add step A to the RISC OS tokenizing script.
Ben Harris [Tue, 14 May 2019 21:53:31 +0000 (22:53 +0100)]
bbc-basic: Add step A to the RISC OS tokenizing script.

5 years agobbc-basic: Pass '-path' to Brandy so self-hosting tests find libraries.
Ben Harris [Mon, 13 May 2019 23:22:22 +0000 (00:22 +0100)]
bbc-basic: Pass '-path' to Brandy so self-hosting tests find libraries.

5 years agobbc-basic: Enlarge the reader token buffer again.
Ben Harris [Mon, 13 May 2019 23:13:12 +0000 (00:13 +0100)]
bbc-basic: Enlarge the reader token buffer again.

The later self-hosting steps are quite large.

5 years agobbc-basic: Stub implementations of optional step A core functions.
Ben Harris [Mon, 13 May 2019 23:10:56 +0000 (00:10 +0100)]
bbc-basic: Stub implementations of optional step A core functions.

These need to be present (but not functional) for the self-hosted mal to work.

5 years agobbc-basic: Simplify type codes.
Ben Harris [Mon, 13 May 2019 22:27:07 +0000 (23:27 +0100)]
bbc-basic: Simplify type codes.

Z%(x,2) and Z%(x,3) are always pointers or nil, so there's no need to
record whether they're used: FNgc_mark can just unconditionally mark
them.  This means that the only interesting question is whether Z%(x,1)
is a pointer, a string, or something else, which can be encoded in two
bits.  This still leaves us using five bits for the type code, but I
think the avoidance of special-case code is worth spending a bit on.

5 years agobbc-basic: Simplify 'first' and 'rest'.
Ben Harris [Mon, 13 May 2019 22:06:12 +0000 (23:06 +0100)]
bbc-basic: Simplify 'first' and 'rest'.

Rather than special-casing the empty list/vector, arrange that the
dedicated empty list/vector objects have the correct values in their
first and rest pointers.  Still dithering about whether to do that
to 'nil' as well.

This does mean that the internal FNfirst and FNrest don't error on an
empty list any more.  Nothing should have depended on that, but it might
mask some bugs.

5 years agobbc-basic: Add the README file that I've had kicking around for a while.
Ben Harris [Sun, 12 May 2019 23:14:33 +0000 (00:14 +0100)]
bbc-basic: Add the README file that I've had kicking around for a while.

5 years agobbc-basic: Increase reader token buffer again to 1024.
Ben Harris [Sun, 12 May 2019 23:07:47 +0000 (00:07 +0100)]
bbc-basic: Increase reader token buffer again to 1024.

Running the self-hosting tests looks to require this.

5 years agobbc-basic: Add '*host-language*' and a startup banner.
Ben Harris [Sun, 12 May 2019 22:54:28 +0000 (23:54 +0100)]
bbc-basic: Add '*host-language*' and a startup banner.

5 years agobbc-basic: Metadata support, including 'meta' and 'with-meta'.
Ben Harris [Sun, 12 May 2019 22:49:51 +0000 (23:49 +0100)]
bbc-basic: Metadata support, including 'meta' and 'with-meta'.

5 years agobbc-basic: Redesign storage of functions to use two cells.
Ben Harris [Sun, 12 May 2019 22:43:48 +0000 (23:43 +0100)]
bbc-basic: Redesign storage of functions to use two cells.

Functions were the only type using all three columns of Z%().  By
reducing that to two (at the expense of spreading a function over two
cells), we make space for storing a metadata pointer in Z%(x,3) of all
types.

5 years agobbc-basic: Add 'readline' core function.
Ben Harris [Sun, 12 May 2019 21:53:53 +0000 (22:53 +0100)]
bbc-basic: Add 'readline' core function.

5 years agobbc-basic: Beginning of step A.
Ben Harris [Sun, 12 May 2019 21:46:41 +0000 (22:46 +0100)]
bbc-basic: Beginning of step A.

5 years agobbc-basic: Make sure that '&' parameters are in a list, not a vector.
Ben Harris [Sun, 12 May 2019 21:08:03 +0000 (22:08 +0100)]
bbc-basic: Make sure that '&' parameters are in a list, not a vector.

5 years agobbc-basic: Add 'dissoc' and 'vals' core functions.
Ben Harris [Sun, 12 May 2019 20:52:15 +0000 (21:52 +0100)]
bbc-basic: Add 'dissoc' and 'vals' core functions.

5 years agobbc-basic: Add 'assoc' and 'keys' core functions.
Ben Harris [Sun, 12 May 2019 17:28:38 +0000 (18:28 +0100)]
bbc-basic: Add 'assoc' and 'keys' core functions.

'hash-map' is now implemented in terms of 'assoc'.

5 years agobbc-basic: Add 'get' and 'contains?' core functions.
Ben Harris [Sun, 12 May 2019 17:06:54 +0000 (18:06 +0100)]
bbc-basic: Add 'get' and 'contains?' core functions.

5 years agobbc-basic: Adjust heap size so that step 8 doesn't suffer a stack overflow.
Ben Harris [Sun, 12 May 2019 15:54:14 +0000 (16:54 +0100)]
bbc-basic: Adjust heap size so that step 8 doesn't suffer a stack overflow.

5 years agobbc-basic: PATRICIA hashmaps now mostly working. Stack overflow in step 8.
Ben Harris [Sun, 12 May 2019 12:57:32 +0000 (13:57 +0100)]
bbc-basic: PATRICIA hashmaps now mostly working.  Stack overflow in step 8.

5 years agobbc-basic: PATRICIA hashmaps now working up to step 2.
Ben Harris [Sun, 12 May 2019 12:34:26 +0000 (13:34 +0100)]
bbc-basic: PATRICIA hashmaps now working up to step 2.

5 years agobbc-basic: Start of conversion to PATRICIA hashmaps: single-element hash-maps.
Ben Harris [Sun, 12 May 2019 10:19:03 +0000 (11:19 +0100)]
bbc-basic: Start of conversion to PATRICIA hashmaps: single-element hash-maps.

Not very useful, but enough to pass step 1.

5 years agobbc-basic: Rework of type identifiers to be more semantically useful.
Ben Harris [Sun, 12 May 2019 09:45:49 +0000 (10:45 +0100)]
bbc-basic: Rework of type identifiers to be more semantically useful.

Now the bottom four bits indicate the semantics of the various columns
of Z%, so the garbage collector can operate with no knowledge of any
specific types.  Instead, it can directly tell which fields need
followed when marking, and which represent strings to be freed.

5 years agobbc-basic: Implement 'hash-map' and 'map?' core functions.
Ben Harris [Sat, 11 May 2019 20:46:24 +0000 (21:46 +0100)]
bbc-basic: Implement 'hash-map' and 'map?' core functions.

5 years agobbc-basic: Correct error for core function argument not being a string.
Ben Harris [Sat, 11 May 2019 20:45:38 +0000 (21:45 +0100)]
bbc-basic: Correct error for core function argument not being a string.

5 years agobbc-basic: Make FNhashmap_contains, FNhashmap_get, and FNenv_find iterative.
Ben Harris [Sat, 11 May 2019 20:17:46 +0000 (21:17 +0100)]
bbc-basic: Make FNhashmap_contains, FNhashmap_get, and FNenv_find iterative.

Since BASIC doesn't do tail-call optimisation, we were needlessly
burning a lot of stack.

Now passes all tests (including deferrable and optional) up to step 8.

5 years agobbc-basic: Enlarge token buffer to 512 entries.
Ben Harris [Sat, 11 May 2019 19:32:50 +0000 (20:32 +0100)]
bbc-basic: Enlarge token buffer to 512 entries.

core.mal needed more than the 255 we allowed before.

5 years agobbc-basic: Add support for hash-maps to FNeval_ast (deferred from step 2).
Ben Harris [Sat, 11 May 2019 16:30:18 +0000 (17:30 +0100)]
bbc-basic: Add support for hash-maps to FNeval_ast (deferred from step 2).

5 years agobbc-basic: Simplify reader-macro code using FNalloc_list2.
Ben Harris [Sat, 11 May 2019 16:04:27 +0000 (17:04 +0100)]
bbc-basic: Simplify reader-macro code using FNalloc_list2.

5 years agobbc-basic: Add support for '^' reader macro.
Ben Harris [Sat, 11 May 2019 16:02:19 +0000 (17:02 +0100)]
bbc-basic: Add support for '^' reader macro.

5 years agobbc-basic: Reading and printing support for hash-maps (deferred from step 1).
Ben Harris [Sat, 11 May 2019 15:47:12 +0000 (16:47 +0100)]
bbc-basic: Reading and printing support for hash-maps (deferred from step 1).

5 years agobbc-basic: '*ARGV*' support when running under RISC OS.
Ben Harris [Sat, 11 May 2019 14:36:57 +0000 (15:36 +0100)]
bbc-basic: '*ARGV*' support when running under RISC OS.

This uses OS_GetEnv to get the command line, and OS_GSTrans to split it
into words, discarding the usual prefix for a BASIC program.

5 years agobbc-basic: Move argv extraction into its own function.
Ben Harris [Sat, 11 May 2019 00:18:52 +0000 (01:18 +0100)]
bbc-basic: Move argv extraction into its own function.

That way it's not in the way as it gets more complicated.

5 years agobbc-basic: Nicer '*ARGV*' construction.
Ben Harris [Sat, 11 May 2019 00:07:28 +0000 (01:07 +0100)]
bbc-basic: Nicer '*ARGV*' construction.

Now implementation-specific code constructs a list containing all the
arguments (including the mal script name) and then generic code stuffs
the tail of that list into '*ARGV*' and calls 'load-file' on the head.

This should make it practical to move the per-platform argv-gathering
code into a function.

5 years agobbc-basic: Handle command-line arguments under Brandy (deferred from step 6).
Ben Harris [Thu, 9 May 2019 22:05:15 +0000 (23:05 +0100)]
bbc-basic: Handle command-line arguments under Brandy (deferred from step 6).

This includes running the file named by the first argument and stuffing
the rest into '*ARGV*'.  Doing this under RISC OS will be trickier
because we have to do word-splitting ourselves (and probably use
OS_GSTrans to provide quoting).

I think this is the first Brandy-specific code in mal.

5 years agobbc-basic: Add scripts to tokenize BASIC files for use under RISC OS.
Ben Harris [Thu, 9 May 2019 20:24:45 +0000 (21:24 +0100)]
bbc-basic: Add scripts to tokenize BASIC files for use under RISC OS.

There's an Obey file that gets BASIC to TEXTLOAD each source file and
the SAVE it out into the "riscos" directory.

5 years agobbc-basic: Always use the same interpretation of the GC mark bit.
Ben Harris [Mon, 6 May 2019 17:45:20 +0000 (18:45 +0100)]
bbc-basic: Always use the same interpretation of the GC mark bit.

We now always set it when marking and clear it when sweeping, rather
than inverting it on each GC pass.  This is slightly less confusing, and
also means the code matches the description of naïve mark-and-sweep in
Wikipedia.

5 years agobbc-basic: Fix tokenizer handling of comments.
Ben Harris [Mon, 6 May 2019 12:40:55 +0000 (13:40 +0100)]
bbc-basic: Fix tokenizer handling of comments.

Now newline correctly terminates comments, which means it has to be
treated differently from other whitespace.  Rather than returning
comments as a kind of token (and requiring the reader to skip them),
the tokenizer just consumes them as though they were whitespace.

5 years agobbc-basic: Make sure 'rest' always returns a list.
Ben Harris [Mon, 6 May 2019 11:28:26 +0000 (12:28 +0100)]
bbc-basic: Make sure 'rest' always returns a list.

5 years agobbc-basic: Make 'first' and 'rest' work properly on nil values.
Ben Harris [Mon, 6 May 2019 11:24:34 +0000 (12:24 +0100)]
bbc-basic: Make 'first' and 'rest' work properly on nil values.

5 years agobbc-basic: Rename list-manipulating functions to match their mal counterparts.
Ben Harris [Mon, 6 May 2019 11:00:25 +0000 (12:00 +0100)]
bbc-basic: Rename list-manipulating functions to match their mal counterparts.

FNlist_car becomes FNfirst
FNlist_cdr becomes FNrest
FNlist_nth becomes FNnth
FNlist_len becomes FNcount

This makes out terminology more mal-ish, and also avoids mentioning
lists in the names of functions that also work on vectors.  Note that in
edge cases (empty sequences, nil), these functions don't quite have
their mal semantics, so the core library still does some remapping.

5 years agobbc-basic: Add 'vector', 'vector?', and 'sequential?' core functions.
Ben Harris [Sun, 5 May 2019 23:00:42 +0000 (00:00 +0100)]
bbc-basic: Add 'vector', 'vector?', and 'sequential?' core functions.

5 years agobbc-basic: Extend vector support throughout steps 2 to 9.
Ben Harris [Sun, 5 May 2019 22:52:31 +0000 (23:52 +0100)]
bbc-basic: Extend vector support throughout steps 2 to 9.

5 years agobbc-basic: Minimal support for vectors (read/print only, deferred from step 1).
Ben Harris [Sun, 5 May 2019 12:36:21 +0000 (13:36 +0100)]
bbc-basic: Minimal support for vectors (read/print only, deferred from step 1).

A vector is just a list in a silly hat, or more precisely a special flag
in its head cell.  This means that all the list functions work on
vectors as well, but it may be necessary to rename them in order to
avoid confusion, since at least FNis_list needs to be more specific in
order for FNEVAL to work properly.

5 years agobbc-basic: Add 'symbol', 'keyword' and 'keyword?' core functions.
Ben Harris [Sat, 4 May 2019 20:21:23 +0000 (21:21 +0100)]
bbc-basic: Add 'symbol', 'keyword' and 'keyword?' core functions.

5 years agobbc-basic: Add minimal support for keywords (deferred from step 1).
Ben Harris [Sat, 4 May 2019 20:02:09 +0000 (21:02 +0100)]
bbc-basic: Add minimal support for keywords (deferred from step 1).

They're implemented as prefixed strings, as suggested by the guide.

5 years agobbc-basic: Rework try*/catch*.
Ben Harris [Sat, 4 May 2019 15:07:01 +0000 (16:07 +0100)]
bbc-basic: Rework try*/catch*.

This separates out the trying part into its own function, which
returns any exception that got thrown, or returns the result if no
exception occurred.  This has two significant advantages.  First, it
means that the shadow stack gets reset before the 'catch*' clause it
run, so unrechable objects allocated by the failed code become
collectable.  Second, it makes it possible (not that I've done so) to
adjust the code to cope with ARM BBC BASIC's failure to restore LOCAL
variables before running an ON ERROR LOCAL handler.  FNtry can now
safely assume that none of _its_ LOCAL variables will be corrupted
because the ones that matter are unique to FNtry, and any FNtry called
further down the stack will not propagate or raise an exception.

5 years agobbc-basic: Tolerable shadow-stack handling in 'try*'.
Ben Harris [Fri, 3 May 2019 22:21:17 +0000 (23:21 +0100)]
bbc-basic: Tolerable shadow-stack handling in 'try*'.

Now catching an exception doesn't leak memory.  It's still a slight
mess, though, since memory allocated in the "try" part is retained
until the end of the "catch".

5 years agobbc-basic: Make FNgc_save/PROCgc_restore more useful and less confusing.
Ben Harris [Fri, 3 May 2019 21:57:56 +0000 (22:57 +0100)]
bbc-basic: Make FNgc_save/PROCgc_restore more useful and less confusing.

FNgc_save now creates a new stack frame, so PROCgc_restore precisely
reverses the effect of FNgc_save (along with freeing any stack frames
pushed since FNgc_save).  This means it doesn't surprisingly destroy the
current stack frame.  This requires changes to each step file to adjust
the REPL to these new semantics.

5 years agobbc-basic: Add 'nil?', 'true?', 'false?', 'symbol?' core functions.
Ben Harris [Wed, 1 May 2019 12:20:04 +0000 (13:20 +0100)]
bbc-basic: Add 'nil?', 'true?', 'false?', 'symbol?' core functions.

All mandatory tests for step 9 now pass, but I think the interaction
between exception handling and GC still needs investigation.

5 years agobbc-basic: Implement 'map' core function.
Ben Harris [Wed, 1 May 2019 12:14:35 +0000 (13:14 +0100)]
bbc-basic: Implement 'map' core function.

5 years agobbc-basic: Add 'apply' core function.
Ben Harris [Wed, 1 May 2019 12:03:16 +0000 (13:03 +0100)]
bbc-basic: Add 'apply' core function.

5 years agobbc-basic: Start of step 9: add 'try*' form and 'throw'.
Ben Harris [Wed, 1 May 2019 11:31:48 +0000 (12:31 +0100)]
bbc-basic: Start of step 9: add 'try*' form and 'throw'.

I haven't attempted to get the interaction with the garbage-collector
right, so it's almost certainly terribly wrong.

5 years agobbc-basic: Adjust error message from FNenv_get to match tests.
Ben Harris [Wed, 1 May 2019 11:31:32 +0000 (12:31 +0100)]
bbc-basic: Adjust error message from FNenv_get to match tests.

The step 9 tests define the precise text of the message when a symbol
isn't found in an environment, so follow them.

5 years agobbc-basic: Make FNlist_nth fail correctly when passed an empty list.
Ben Harris [Wed, 1 May 2019 11:30:36 +0000 (12:30 +0100)]
bbc-basic: Make FNlist_nth fail correctly when passed an empty list.

It failed before, but not with the correct error, and the step 9 tests
depend on the correct error.

5 years agobbc-basic: Define 'cond' and 'or' macros at startup, completing step 8.
Ben Harris [Tue, 30 Apr 2019 21:52:12 +0000 (22:52 +0100)]
bbc-basic: Define 'cond' and 'or' macros at startup, completing step 8.

5 years agobbc-basic: Add support for variadic functions (deferred from step 4).
Ben Harris [Tue, 30 Apr 2019 21:49:53 +0000 (22:49 +0100)]
bbc-basic: Add support for variadic functions (deferred from step 4).

5 years agobbc-basic: Add 'nth', 'first', and 'rest' core functions.
Ben Harris [Tue, 30 Apr 2019 21:45:13 +0000 (22:45 +0100)]
bbc-basic: Add 'nth', 'first', and 'rest' core functions.

5 years agobbc-basic: Mandatory parts of step 8 completed.
Ben Harris [Tue, 30 Apr 2019 21:33:56 +0000 (22:33 +0100)]
bbc-basic: Mandatory parts of step 8 completed.

That's macro expansion and the 'macroexpand' special form.

5 years agobbc-basic: Have FNenv_find return nil on failure rather then erroring.
Ben Harris [Tue, 30 Apr 2019 21:32:32 +0000 (22:32 +0100)]
bbc-basic: Have FNenv_find return nil on failure rather then erroring.

This matches the mal implementation and makes the code for
FNis_macro_call a little less hairy.  It doesn't seem to have broken
anything.

5 years agobbc-basic: Start of step 8: minimal support for 'defmacro!'.
Ben Harris [Tue, 30 Apr 2019 20:24:40 +0000 (21:24 +0100)]
bbc-basic: Start of step 8: minimal support for 'defmacro!'.

Nothing yet treats macros any differently from ordinary functions.

5 years agobbc-basic: Implement 'concat' and 'quasiquote'. Step 7 done.
Ben Harris [Sun, 28 Apr 2019 09:41:10 +0000 (10:41 +0100)]
bbc-basic: Implement 'concat' and 'quasiquote'.  Step 7 done.

5 years agobbc-basic: Add 'quote'.
Ben Harris [Thu, 25 Apr 2019 21:21:42 +0000 (22:21 +0100)]
bbc-basic: Add 'quote'.

5 years agobbc-basic: Start of step 7: implement 'cons'.
Ben Harris [Tue, 23 Apr 2019 22:25:46 +0000 (23:25 +0100)]
bbc-basic: Start of step 7: implement 'cons'.

5 years agobbc-basic: Implement 'swap!'. That's step 6 done.
Ben Harris [Tue, 23 Apr 2019 22:14:24 +0000 (23:14 +0100)]
bbc-basic: Implement 'swap!'.  That's step 6 done.

5 years agobbc-basic: In the 'apply' step of FNEVAL, use car% if we have it.
Ben Harris [Tue, 23 Apr 2019 22:09:06 +0000 (23:09 +0100)]
bbc-basic: In the 'apply' step of FNEVAL, use car% if we have it.

In most cases, it already contains the target function, so there's no
need to extract that from ast% again.

5 years agobbc-basic: Abolish "malio" abstraction.
Ben Harris [Mon, 22 Apr 2019 19:44:21 +0000 (20:44 +0100)]
bbc-basic: Abolish "malio" abstraction.

When I started this port, it looked like it might be necessary to jump
through silly hoops to get Brandy (and maybe ARM BBC BASIC V) to
communicate with the mal test harness.  In practice, though, that hasn't
been necessary: Brandy's "simpletext" interface works well enough and I
expect RISC OS's I/O redirection will be good enough if I ever try to
test on RISC OS.

5 years agobbc-basic: Substantial redesign of how core functions work.
Ben Harris [Mon, 22 Apr 2019 19:29:24 +0000 (20:29 +0100)]
bbc-basic: Substantial redesign of how core functions work.

FNcore_call now takes a mal list of arguments rather than an array.
FNcore_assert_args has become FNcore_prepare_args and now handles
unboxing arguments where that's sensible.

This should make 'swap!' and 'apply' easier to write in that it won't be
necessary to convert argument lists repeatedly between lists and arrays.
Finally, it avoids the silly situation where args%() was (accidentally,
but necessarily) one element larger than needed to hold the actual list
of arguments.

5 years agobbc-basic: Add -quit to the Brandy command line so that it exits spontaneously.
Ben Harris [Mon, 22 Apr 2019 19:21:03 +0000 (20:21 +0100)]
bbc-basic: Add -quit to the Brandy command line so that it exits spontaneously.

5 years agobbc-basic: Align the spec of FNlist_nth with 'nth'.
Ben Harris [Mon, 22 Apr 2019 18:15:08 +0000 (19:15 +0100)]
bbc-basic: Align the spec of FNlist_nth with 'nth'.

It now counts from zero (like BBC BASIC arrays) rather than 1 (like BBC
BASIC strings).

5 years agobbc-basic: Expect to find Brandy in $HOME rather than /tmp.
Ben Harris [Mon, 22 Apr 2019 17:56:01 +0000 (18:56 +0100)]
bbc-basic: Expect to find Brandy in $HOME rather than /tmp.

Should slightly reduce how often I have to recompile it.

5 years agobbc-basic: Slightly increase test timeout.
Ben Harris [Mon, 22 Apr 2019 17:10:05 +0000 (18:10 +0100)]
bbc-basic: Slightly increase test timeout.

40 seconds wasn't enough if I was running Firefox at the time.

5 years agobbc-basic: Add support for validating functions and optional trailing arguments.
Ben Harris [Sat, 20 Apr 2019 17:28:15 +0000 (18:28 +0100)]
bbc-basic: Add support for validating functions and optional trailing arguments.

This is necessary for 'swap!', but not dependent on how I end up
implementing it.

5 years agobbc-basic: Basic support for atoms. 'swap!' is still missing.
Ben Harris [Sat, 20 Apr 2019 17:25:09 +0000 (18:25 +0100)]
bbc-basic: Basic support for atoms.  'swap!' is still missing.

Trying to implement 'swap!' has caused me to suspect I have some
fundamental structural deficiencies to address, so I might have to do
that next.

5 years agobbc-basic: Define 'load-file' at startup.
Ben Harris [Sat, 20 Apr 2019 15:34:23 +0000 (16:34 +0100)]
bbc-basic: Define 'load-file' at startup.

Its definition includes a string, so start putting the startup forms in
DATA statements.  That way they can just be pasted in without further
escaping.  No useful initial form starts with a quotation mark or
contains a comma, so quoting them is never necessary in a DATA
statement.

5 years agobbc-basic: Implement the printing functions deferred from step 4.
Ben Harris [Sat, 20 Apr 2019 15:31:47 +0000 (16:31 +0100)]
bbc-basic: Implement the printing functions deferred from step 4.

That's 'pr-str', 'str', 'prn' (full version), and 'println'.

5 years agobbc-basic: Add 'read-string', 'slurp', and 'eval' functions.
Ben Harris [Sat, 20 Apr 2019 14:06:38 +0000 (15:06 +0100)]
bbc-basic: Add 'read-string', 'slurp', and 'eval' functions.

The Guide would have me implement 'eval' in the main program, but
without function pointers all core functions have to appear in
FNcore_call, so I've put it there instead.

5 years agobbc-basic: Start step 6.
Ben Harris [Sat, 20 Apr 2019 14:00:51 +0000 (15:00 +0100)]
bbc-basic: Start step 6.

5 years agobbc-basic: Fix FNenv_find and FNenv_get so they can return nil properly.
Ben Harris [Sat, 20 Apr 2019 13:29:56 +0000 (14:29 +0100)]
bbc-basic: Fix FNenv_find and FNenv_get so they can return nil properly.

Using FNhashmap_get meant that FNenv_find couldn't tell the difference
between failing to find an entry, and finding an entry containing nil.
Now it uses FNhashmap_contains to check whether the value is present
first.  This makes it much clearer why FNenv_find and FNenv_get are
strctured the way they are.

5 years agobbc-basic: Add FNhashmap_contains, being the internal version of contains?.
Ben Harris [Sat, 20 Apr 2019 13:29:28 +0000 (14:29 +0100)]
bbc-basic: Add FNhashmap_contains, being the internal version of contains?.

5 years agobbc-basic: Add string support (deferred from step 1).
Ben Harris [Sat, 20 Apr 2019 12:44:12 +0000 (13:44 +0100)]
bbc-basic: Add string support (deferred from step 1).

Strings are internally like symbols, but with special reading and
printing rules.  This will serve until we need strings over 255
characters long (the longest that ARM BBC BASIC V can handle natively).

5 years agobbc-basic: Add the print_readably% parameter to FNpr_str (deferred from step 1).
Ben Harris [Sat, 20 Apr 2019 12:42:00 +0000 (13:42 +0100)]
bbc-basic: Add the print_readably% parameter to FNpr_str (deferred from step 1).

This is a pre-requisite for string support.

5 years agobbc-basic: Specify the file name at the top of each library file.
Ben Harris [Sat, 20 Apr 2019 00:33:31 +0000 (01:33 +0100)]
bbc-basic: Specify the file name at the top of each library file.

This means that they can be saved using "SAVE" without a filename, which
will make tokenising them a little less painful.  I haven't done this to
the step files because those have "." in their canonical names, which
turns into "/" on RISC OS, so there's no good name to put in the
comment.

5 years agobbc-basic: Add Emacs local variables lists to stop it inserting tabs.
Ben Harris [Fri, 19 Apr 2019 16:44:19 +0000 (17:44 +0100)]
bbc-basic: Add Emacs local variables lists to stop it inserting tabs.

Tab characters are harmful to BBC BASIC programs, so it's particularly
unhelpful that Emacs' "indent-relative" function inserts them.  Add file
variables lists to all BBC BASIC source files to disable this behaviour.

5 years agobbc-basic: Remove all tab (HT) characters from BASIC source.
Ben Harris [Fri, 19 Apr 2019 16:35:27 +0000 (17:35 +0100)]
bbc-basic: Remove all tab (HT) characters from BASIC source.

While Brandy treats tab characters in its source file as spaces, ARM BBC
BASIC seems to get rather confused by them.  To avoid this, untabify all
of our BBC BASIC sources.

5 years agobbc-basic: Increase test timeout to 40 seconds.
Ben Harris [Fri, 19 Apr 2019 14:45:04 +0000 (15:45 +0100)]
bbc-basic: Increase test timeout to 40 seconds.

The default of 20 seconds was slightly too short for the step 5 tests.

5 years agobbc-basic: Suppress debugging PRINT statements in the garbage collector.
Ben Harris [Fri, 19 Apr 2019 14:44:18 +0000 (15:44 +0100)]
bbc-basic: Suppress debugging PRINT statements in the garbage collector.

It seems to work properly now, but I'll keep them commented out in case
it stops.

5 years agobbc-basic: Make step 5 mostly work.
Ben Harris [Fri, 19 Apr 2019 14:42:39 +0000 (15:42 +0100)]
bbc-basic: Make step 5 mostly work.

It now has minimal shadow-stack handling to interface with the garbage
collector.  This involved adding a procedure to the garbage collector to
tell it that only two values (ast% and val%) in the current stack frame
are live, so the rest can usefully be collected.