Commit 2b6d7f1
rust: various improvements
`make lint` reformats the code, creating a lot of space/indentation
noise in the diff.
Cargo.lock:
* remove from git, add to clean Make target.
Cargo.toml, Dockerfile:
* install regex and rustyline via apt-get.
Cargo.toml, Dockerfile, reader.rs, readline.rs, steps:
* Implement global variables with thread_local, avoiding an external
dependency on lazy_static and/or the complexity of Mutex.
Makefile, core.rs, readline.rs, steps:
* Move the readline stuff into a separate file.
* enable history during self-hosting
* save the history at exit, not after each line
* skip empty lines
* crash on readline errors (other than EOF)
core.rs, steps, types.rs:
* remove specific error types. try* requires a MAL form anyway.
* Split the {list,vector}! macros. A variant only needs a function,
the other one need no intermediate array.
* Introduce a FuncStruct intermediate struct for the Func enum
variant. This allows functional update syntax and more intuitive
pattern matching (fn? macro? defmacro!).
core.rs, types.rs:
* Move type helpers hide/encapsulate nothing from types.rs to core.rs.
* Add a Kwd variant to the MalVal enum, with (un)wrap_map_key helpers.
This is safer than a prefix (for example, `(slurp :a)` was accepted).
core.rs:
vals: fix typo
vec: clone if already a vector.
nth: the .get() standard function checks array bounds.
first, rest, seq: merge similar choices
get_meta, with_meta, atom: remove the intermediate anonymous function
(it is confusing and does not bring anything)
env.rs:
The outer field is private.
The outer argument for env_bind is not optional.
env.rs, steps:
Implement the eval core function, using a global REPL environment. It
was implemented with a special form and an env method searching the
ancester of the current environment (`(map eval [1])` was failing).
reader.rs:
Let read_seq always return a vector, and read_form deal with the result,
instead of duplicating the choices.
steps, types.rs:
Implement `apply` as a `MalVal` method but in step sources. The
ugly `eval` reference in each closure is not necessary anmymore.
steps:
Check sooner the exit status of eval(a0, env).
Print a new line on exit.
types.rs:
Metadata needs no mutability.
Everywhere, remove as many clone() as possible.1 parent 3e463bf commit 2b6d7f1
21 files changed
+1083
-1677
lines changedThis file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
| 7 | + | |
9 | 8 | | |
10 | 9 | | |
11 | | - | |
| 10 | + | |
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
30 | | - | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | | - | |
| 34 | + | |
| 35 | + | |
0 commit comments