1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-11 13:55:55 +03:00
Commit Graph

3147 Commits

Author SHA1 Message Date
Ben Harris
c0d61c20e8 perl: Use goto &NAME for tail-call optimisation.
This is rather contrary to the guide, which expects a loop in EVAL, but
perl is unusual in having native support for (manual) tail-call
optimisation and it would seem a shame not to take advantage of this.

This leaves macros broken since all functions are now implemented as
core functions, and we don't yet have support for turning them into
macros.
2019-07-30 09:56:15 +01:00
Ben Harris
329c9c2828 perl: Convert sequences into blessed array references.
The extra hash was only used to hold metadata.
2019-07-30 09:48:03 +01:00
Ben Harris
c2e4b446b9 perl: Remove FunctionRef class.
Now that metadata can be attached to a CoreFunction, there's no need
for the proxy class.
2019-07-30 09:47:39 +01:00
Ben Harris
d64a5527da perl: Convert atoms into simple scalar references. 2019-07-30 09:47:37 +01:00
Ben Harris
ddc11cf22b perl: Replace _clone() with a ->clone method.
This means that each class is responsible for cloning itself, which
helps with encapsulation.
2019-07-30 09:46:59 +01:00
Ben Harris
771045abc2 perl: Simplify hash-map implementation.
Now that metadata is external, we can remove the layer of indirection
in the HashMap class and have the top-level hash contain the hash-map
contents.
2019-07-30 09:33:14 +01:00
Ben Harris
1e52c3b55d perl: Remove old metadata implementation.
Several objects are now single-member hashes, which is obviously silly.
2019-07-30 09:33:14 +01:00
Ben Harris
28bff726b3 perl: Introduce fieldhash-based metadata implementation.
Rather than attaching metadata directly to objects, hold it in a
auxiliary hash keyed by object ID.  Perl's Hash::Util::FieldHash
provides a means to do this with proper garbage-collection.  This does
mean that cloning an object no longer brings its metadata along, but I
think the only use of _clone outside of attaching metadata is to make
macros, and (for now) mal doesn't require that 'defmacro!' preserve
metadata.

This commit only adds the new metadata system.  Most of the old one is
still lying around.
2019-07-30 09:33:14 +01:00
Ben Harris
a71beb7e10 perl: Replace _sequential_Q in step files with ->isa('Mal::Sequence'). 2019-07-30 09:33:14 +01:00
Joel Martin
a85482febf Skip perf for second-order self-hosted tests. 2019-07-29 18:20:11 -05:00
Joel Martin
ff4e5f1600 Fix second-order self-hosting.
The `_map?` function was introduced when transitioning the macro
property being stored in metadata to uinsg a regular map with
a special key. The `_map?` function causes issues in a few places but
the biggest issue is that it breaks the `_macro?` function for the
second order self-hosted mal instance. The `_macro?` function contains
a `(map? x)` call that returns false resulting in the `_macro?` call
returning false.  I'll push something later that fixes this and also
that activates second order self-hosted tests so we can catch this
sort of issue in the future.
2019-07-29 17:58:11 -05:00
Joel Martin
38daa6955b
Merge pull request #387 from asarhaddon/test-macroexpand-no-quasiquote
test macroexpand without assuming that quasiquote is a special form
2019-07-29 17:53:55 -05:00
Joel Martin
7d69305f0a
Merge pull request #415 from asarhaddon/load-file-trailing-new-line-nil
load-file: accept final comment without new line, return nil
2019-07-29 17:42:26 -05:00
Joel Martin
63f969d640 Java: fix escaping of '/'.
Switch to escapeJava which won't do escaping of forward slash.
2019-07-29 09:15:17 -05:00
Joel Martin
aa82382c44
Merge pull request #432 from bjh21/bjh21-perl
More perl improvements
2019-07-29 09:08:48 -05:00
Joel Martin
527ab20993
Merge pull request #433 from bendudson/fix-nasm-empty-args
Fix nasm zero argument function call
2019-07-29 09:04:08 -05:00
Ben Dudson
b2e488b7ce Applying changes to step6 - stepA
Tested stepA, function with empty args still working.
2019-07-28 17:15:41 +01:00
Ben Dudson
76b2506ee5 Fix step 5 call function no args
Previously failed on
```
((fn* () 4))

```
due to freeing the list containing the function too early.
2019-07-28 17:03:55 +01:00
Ben Harris
bd271a30f7 perl: Simplified and tightened implementation of 'try*'.
This also fixes a bug where the last character of the stringification of
an exception object might get removed.
2019-07-28 13:58:27 +01:00
Ben Harris
e8775d5fea perl: Remove _nil_Q(), _true_Q(), and _false_Q().
They were almost unused, and 'eq' is slightly more self-explanatory.
2019-07-28 13:58:27 +01:00
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
Ben Harris
17a19d2c92 perl: Polish _equal_Q a little.
It now uses "unless" rather than "if", uses "isa" rather than
_sequential_Q, doesn't bother with temporary variables for the types
of the arguments, and doesn't special-case symbols.
2019-07-28 10:49:00 +01:00
Ben Harris
60cb3f0351 perl: Re-FATALise the "recursion" warning from step 5 onwards.
The step 5 tests expect that deep recursion will cause an exception, and
not just a warning, so they can prove that TCO is working properly.
2019-07-28 10:13:49 +01:00
Ben Harris
f7e12f1b4f perl: Use "foreach" for variable bindings in Mal::Env::new. 2019-07-28 10:13:44 +01:00
Ben Harris
4fbf43189e perl: Move 'pl*' to core.pm.
The guide says that 'quux-eval', which the perl implementation calls
'pl*', should be a core function.  I can't see any good reason why it
shouldn't be, so I've turned it into one.
2019-07-28 00:47:58 +01:00
Ben Harris
1d83473132 perl: De-FATALise warnings.
The documentation says, 'the use of "FATAL => 'all'" is discouraged', so
it better to leave them non-fatal.
2019-07-28 00:23:28 +01:00
Ben Harris
29702ab6a6 perl: Tidy up imports at the top of each file.
I kept not knowing where to add things, so I've roughly sorted them into
pragmas, then external modules, then internal modules.  This helps with
the situation that internal modules are named in lower case, which is
odd for Perl (but normal for mal).
2019-07-28 00:19:13 +01:00
Ben Harris
493186b447 perl: Remove step 0.5.
It seems to be just a less-complete version of step 0.
2019-07-28 00:05:16 +01:00
Ben Harris
addf6e5a0a perl: Simplify call to Mal::Env->new in 'catch*'.
Mal::Env->new doesn't need its array references to be blessed, so just
pass them plain.  This saves a bit of messing about with Mal::List->new.
2019-07-27 14:51:08 +01:00
Ben Harris
9422283457 perl: Use autodie in 'slurp', getting us better error messages. 2019-07-27 13:08:45 +01:00
Ben Harris
ad455b1128 perl: Propagate exceptions through 'pl*'. 2019-07-27 13:03:38 +01:00
Ben Harris
378c04f2ea perl: Be more careful when investigating the type of an exception.
It's not safe to call "isa" on unblessed references, and not all
reference types are valid mal values.  Now only actual mal values get
treated as such and everything else gets printed as-is or converted to a
Mal::String.
2019-07-27 12:49:45 +01:00
Ben Harris
9530644d76 perl: When converting perl values to mal ones, convert undef to nil. 2019-07-27 12:40:04 +01:00
Ben Harris
e88f9e1d67 perl: Introduce Mal::Type: a superclass for all the mal value classes.
This makes it simple to check if a perl object is one that can be passed
to mal code (e.g. in an exception handler).
2019-07-27 12:23:12 +01:00
Ben Harris
aac860eccd perl: Remove use of "autodie" in REPL.
"autodie" has lexical scope and doesn't affect "print", so it's useless
using it in a scope that only contains a "print" and a call to EVAL.
2019-07-27 12:15:20 +01:00
Ben Harris
5106a8b798 perl: Make a Mal::Scalar superclass for scalars.
It contains a constructor that can be shared by all of them.
2019-07-27 12:10:20 +01:00
Ben Harris
6708078b17 perl: Rename all mal classes to begin with "Mal::".
Perl package names (and hence class names) are global, meaning that if
any module that we use loads a module called "Symbol", it will clash
with mal's Symbol class.  It turns out that something does this already,
which breaks inheritance from mal's Symbol class.  Since most of mal's
class names are very generic, it seems wise to rename all of them.
2019-07-27 11:53:37 +01:00
Ben Harris
bda7fd0d65 perl: Remove now-unused HashMap::get method. 2019-07-27 01:20:19 +01:00
Ben Harris
74d12000fa perl: Use '//' instead of '||' to provide defaults.
This avoids depending on the fact that all mal values are true.
2019-07-27 00:34:43 +01:00
Ben Harris
ac5fafa431 perl: Simpler handling of symbols in step 2. 2019-07-26 23:54:10 +01:00
Ben Harris
a421dd64f0 perl: Use string interpolation on "not found" error message. 2019-07-26 23:54:10 +01:00
Ben Harris
7a17c60557 perl: Simplify code of eval_ast as applied to sequences and hash-maps.
Specifically, the hash-map case now uses 'pairmap' to avoid the need for
a 'for' loop.  The code for sequences is now shared between lists and
vectors, since only the destination type differs.
2019-07-26 23:54:10 +01:00
Ben Harris
19a341f061 perl: Abolish _assoc_BANG.
_hash_map and assoc both get simpler by not using it.
2019-07-26 23:54:09 +01:00
Ben Harris
32e568a31e perl: Fold some simple core functions into %core::ns. 2019-07-26 23:54:09 +01:00
Ben Harris
91a8ef064c perl: Tidy up whitespace in table of core functions. 2019-07-26 23:54:09 +01:00
Ben Harris
befe864c0d perl: Fold _dissoc_BANG into dissoc and simplify.
I particular, Perl allows for batch deletion of hash elements, so we can
delete all the unwanted keys at once.
2019-07-26 23:54:09 +01:00
Ben Harris
4425fecca5 perl: Use List::Util::pairs instead of "for (;;)" in 'let*' and 'assoc'. 2019-07-26 23:54:09 +01:00
Joel Martin
402fb331d6 basic: args file that doesn't rely on return value.
Instead, the file itself does the def of -*ARGS*-. The behavior that
the final value of a loaded file is returned is not necessarily
something we want to assume.
2019-07-26 00:15:39 -05:00
Joel Martin
999b17ad7b
Merge pull request #430 from bjh21/bjh21-perl
perl: Idiomaticity improvements (and some bug fixes too)
2019-07-26 00:14:41 -05:00
Ben Harris
a94c795da6 Merge branch 'master' into bjh21-unterminated-strings
This should fix ocaml.
2019-07-26 00:08:48 +01:00