1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-19 17:47:53 +03:00
Commit Graph

2721 Commits

Author SHA1 Message Date
Nicolas Boulenguez
7b2080df7c ada: fix the fix for unterminated strings
Thanks bjh21. I have been distracted by a less important issue (should
"\a" be read as "\a" or "a"?).
2019-05-28 16:22:21 +02:00
Nicolas Boulenguez
563eba428c ada: fix unterminated string and creation of object directory by Make. 2019-05-23 01:18:37 +02:00
Joel Martin
a4cb289ffb
Merge pull request #371 from asarhaddon/extend-core.mal
Extend core.mal
2019-05-20 22:42:28 -05:00
Nicolas Boulenguez
6db6cf38b7 lib/tests: report parsing errors, move threading out of steps
When testing `foo.mal`, it makes sense to report parsing errors in
`foo.mal`.

Move tests of `->` and `->>` from `tests/step8_macros.mal` to
`tests/lib/theading.mal`.

Add `lib/trivial.mal`.
2019-05-19 19:20:20 +02:00
Nicolas Boulenguez
9bdff6ea55 lib/ README.md should not repeat the process unless needed 2019-05-19 19:17:55 +02:00
Joel Martin
1b5bd10bc9
Merge pull request #382 from bjh21/bjh21-unterminated-string-fixes
Unterminated string fixes: clojure, fantom, groovy, haxe, hy, io, java, julia, kotlin, livescript, matlab, miniMAL, objc, plpgsql, scala, vb, vimscript, yorick
2019-05-19 09:40:41 -05:00
Joel Martin
7aecf6639a
Merge pull request #383 from asarhaddon/ada2tco-do
ada.2: optimize tail call recursion for last `do` evaluation
2019-05-19 09:38:29 -05:00
Joel Martin
c6f6f26efa
Merge pull request #380 from bjh21/bjh21-bbc-basic
BBC BASIC V implementation
2019-05-19 09:29:27 -05:00
Ben Harris
c1982f1a72 vb: Detect more unterminated strings.
I split the string-recognizing part of the read_atom regexp in two, one part for
recognising valid strings (using a fragment of the tokenising regexp) and
another to recognize invalid strings.  This follows the practice of other
implementations with a single read_atom regexp.
2019-05-19 12:00:28 +01:00
Ben Harris
4564d4e4bd objc: Detect more unterminated strings.
This is done by tightening the part of the read_atom regexp that
recognises valid strings.
2019-05-19 12:00:28 +01:00
Ben Harris
9a924bddaa matlab: Detect more unterminated strings.
Rather than treating anything beginning and ending with '"' as a valid
string, we now use a regexp to detect a valid string and treat any other
token starting with '"' as an error.

This does not fix all of the bugs found by #359, though: there remains a
problem with long strings of backslashes in the input getting expanded
into too many backslashes in the resulting string.
2019-05-19 12:00:28 +01:00
Ben Harris
c45de46ff1 miniMAL: Detect more unterminated strings.
Rather than treating anything beginning and ending with '"' as a valid
string, we now use a regexp to detect a valid string and treat any other
token starting with '"' as an error.
2019-05-19 12:00:28 +01:00
Ben Harris
0b66c9961f plpgsql, scala, vimscript, yorick: Detect more unterminated strings.
This is achieved by tightening the regexp used to detect valid strings.
2019-05-19 12:00:07 +01:00
Ben Harris
9c9b26863c bbc-basic: Add a minimal Makefile.
The automated testing system needs one.
2019-05-19 00:20:38 +01:00
Ben Harris
45c103e673 bbc-basic: Travis and top-level README updates for new implementation. 2019-05-18 23:37:33 +01:00
Ben Harris
3b18b5b6cc bbc-basic: README updates. 2019-05-18 22:56:20 +01:00
Ben Harris
6252121a0b bbc-basic: Find Brandy via ${BRANDY}, not ${SBRANDY}.
The graphical versions work perfectly well here, so I don't think the
variable name should suggest the don't.  For instance, you might run:

BRANDY=brandy make repl^bbc-basic
2019-05-18 22:56:20 +01:00
Ben Harris
0f97a00d77 bbc-basic: Support strings longer than the underlying interpreter allows.
Brandy supports strings up to 65536 characters long, but ARM BBC BASIC V
only allows strings up to 255 characters.  Mal needs strings longer than
255 characters, so we implement them by chaining together several
strings in S$() to make one logical string from mal's point of view.
This has entailed far-reaching changes as lots of routines that used to
take BASIC strings (especially in the reader/printer area) now have to
take references to mal strings instead.  There are still a lot of places
that don't, though, so you can't use long strings as hash-map keys, for
instance.

This commit passes all the tests, but I wouldn't be surprised if there
are still bugs lurking somewhere.
2019-05-18 22:56:20 +01:00
Ben Harris
4320425b6a bbc-basic: Support '=' on hash-maps.
Now that keys are sorted, it's just case of comparing the list of keys
and the list of values.  In fact, two equal hash-maps will have
precisely the same internal structure, but the core library need not
know that.
2019-05-18 16:34:01 +01:00
Ben Harris
c96b3a5b7d bbc-basic: Properly sort hash-map keys.
This turned out to be quite twiddly, and the code isn't quite as
obviously correct as it was.  Still, it seems to work correctly.
2019-05-18 16:34:01 +01:00
Ben Harris
4099910484 bbc-basic: Iterative implementation of 'get' and 'contains?'.
There's no good reason for these to be recursive.  Also they can
easily share code.
2019-05-18 16:34:01 +01:00
Ben Harris
347af95109 bbc-basic: Wrap BASIC and OS errors in a hash-map when they're caught.
This allows mal code to get at the error number (ERR), which is what it
should look at to determine the meaning of the error.
2019-05-18 16:34:01 +01:00
Ben Harris
49bacdaff9 bbc-basic: Correct comment describing use of S%(). 2019-05-18 16:34:01 +01:00
Ben Harris
7188e01f24 bbc-basic: Disallow metadata on string-like types.
Objects that have a direct reference into S$() can't safely be cloned,
because the GC assumes that when such an object is freed, the string
in S$() can be freed as well.  This assumption would be broken by
cloning, so the cloning of such types by FNwith_meta must be
disallowed.

This has the unexpected, but in retrospect obvious, consequence that
single-member hashmaps can't have metadata.  That's obviously a bit
silly, so a more comprehensive solution is probably warranted in due
course.
2019-05-18 16:34:01 +01:00
Ben Harris
d510574deb bbc-basic: Detect running out of heap memory.
This happens when the garbage collector runs but frees no memory.
Raising a polite error explains what happens and offers a theoretical
possiblity of an application's recovering.
2019-05-18 16:34:01 +01:00
Ben Harris
d4b2e8b29d bbc-basic: Ensure that "Escape" errors propagate beyond mal.
Rather than printing an error message and ending the program, it's
better to turn off our error handler and then re-raise the error.  This
ensures that if, for instance, mal is started from the Supervisor in
RISC OS, the error gets propagated back to the Supervisor error handler
and displayed properly.

This required a slight adjustment to the top-level ON ERROR handler.
2019-05-18 16:34:01 +01:00
Ben Harris
7a18529b2c 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.
2019-05-18 16:34:01 +01:00
Ben Harris
b0fec96b1b 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.
2019-05-18 16:34:01 +01:00
Ben Harris
8b4405de62 bbc-basic: Minor README updates. 2019-05-18 16:34:01 +01:00
Ben Harris
f046cfa64c 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.
2019-05-18 16:34:01 +01:00
Ben Harris
90d90dfd7f 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.
2019-05-18 16:34:01 +01:00
Ben Harris
2e3de60f43 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.
2019-05-18 16:34:01 +01:00
Ben Harris
b6ce08fdef bbc-basic: Remove unused PROClist_to_array and FNarray_to_list. 2019-05-18 16:34:01 +01:00
Ben Harris
8c576e378e bbc-basic: Upgrade to the gensym-based 'or'. 2019-05-18 16:33:58 +01:00
Ben Harris
9386894d6a 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.
2019-05-18 16:33:18 +01:00
Ben Harris
05628a32d8 bbc-basic: Add 'seq' core function. 2019-05-18 16:33:16 +01:00
Ben Harris
87e532c542 bbc-basic: Add 'string?', 'number?', 'fn?', and 'macro?' core functions. 2019-05-18 16:32:52 +01:00
Ben Harris
7fbc48dc65 bbc-basic: Implement 'conj' core function. 2019-05-18 16:32:52 +01:00
Ben Harris
f9dea0e574 bbc-basic: Add 'time-ms' core function.
It uses TIME, since that's easily available on all platforms.
2019-05-18 16:32:52 +01:00
Ben Harris
230e4eee19 bbc-basic: Add step A to the RISC OS tokenizing script. 2019-05-18 16:32:52 +01:00
Ben Harris
9c6f24f0dd bbc-basic: Pass '-path' to Brandy so self-hosting tests find libraries. 2019-05-18 16:32:52 +01:00
Ben Harris
6cbd11b959 bbc-basic: Enlarge the reader token buffer again.
The later self-hosting steps are quite large.
2019-05-18 16:32:52 +01:00
Ben Harris
ce2d81a1a7 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.
2019-05-18 16:32:50 +01:00
Ben Harris
4fbd9d0fdd 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.
2019-05-18 16:32:26 +01:00
Ben Harris
9e1b7a8fba 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.
2019-05-18 16:32:26 +01:00
Ben Harris
d966fbb5ad bbc-basic: Add the README file that I've had kicking around for a while. 2019-05-18 16:32:26 +01:00
Ben Harris
76e261036a bbc-basic: Increase reader token buffer again to 1024.
Running the self-hosting tests looks to require this.
2019-05-18 16:32:26 +01:00
Ben Harris
ae5bbd45af bbc-basic: Add '*host-language*' and a startup banner. 2019-05-18 16:32:19 +01:00
Ben Harris
333683929e bbc-basic: Metadata support, including 'meta' and 'with-meta'. 2019-05-18 05:48:32 +01:00
Ben Harris
8db9135b10 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.
2019-05-18 05:48:32 +01:00