1
1
mirror of https://github.com/kanaka/mal.git synced 2024-10-27 06:40:14 +03:00
Commit Graph

554 Commits

Author SHA1 Message Date
Nicolas Boulenguez
0e80e7a7db elisp: fix new tests, byte-compile, various improvements
The original motivation is to fix the new (= nil ()) and
core_apply_accepts_macros tests.
Improve speed and warnings with byte compilation.

mal/core.el:
Wrap core functions during the loop in main, instead of writing the
conversion in each line of core-ns.
Use apply built-in concatenation of last argument.
Move handling of metadata to types.el.

mal/env.el:
Represent environments as cons cells instead of vectors.

mal/func.el:
Merged into types.el, it is not a special case anymore.

mal/printer.el:
Add macro case.
Define a pr-join helper for sequences and core.el.

mal/reader.el:
Rename the tokens local variable in reader.el (compiler warning).

mal/types.el:
Use type-specific accessors returning nil for the wrong type
(structural pattern matching would be better, but is too slow).
Represent native types directly when possible, and inline some trivial
accessors.
Use dedicated records instead of vectors.
Implement metadata only when required.
Represent keywords as strings (easyer, no counterpart).

run:
Run byte-compiled version.

steps:
Backport good ideas from stepA to step1, reducing the diff between
steps for future maintenance.
Implement 'do with a simple iteration (without map and butlast).
Make the repl-env local to main (compiler warning).

Make the code more idiomatic
 * prefer loop over recursion (search in environments)
 * declare variable and reassign them when convenient (exit of the TCO loop)
 * car cdr cadr and so on instead of nth
 * remove various vector <-> list conversions.
2024-08-26 13:07:28 -05:00
Nicolas Boulenguez
c5788b3790 purs: merge evalAst into eval and add DEBUG-EVAL
See #592 for context.
2024-08-26 12:56:33 -05:00
Dov Murik
1354b3fe9c jq: Remove stray _debug call in nth implementation 2024-08-26 10:10:44 -05:00
Dov Murik
f7ab284599 jq: Fix functions with empty list body
jq's find_free_references failed on empty lists; add handling for that
case.

Add relevant test in step4.
2024-08-26 10:10:44 -05:00
Nicolas Boulenguez
dab788cf4f lua: style improvements, especially for try* 2024-08-26 10:00:47 -05:00
Nicolas Boulenguez
a9456d0179 lua: simplify and debug environments
Use plain LUA strings as keys in environments.
Search outers environments with a loop.
Remove the now unneeded Env:find trick.
Let DEBUG-EVAL show the contents of all outer environments but repl_env.
2024-08-26 10:00:47 -05:00
Nicolas Boulenguez
ae91e2b0af lua: remove some unneeded imports 2024-08-26 10:00:47 -05:00
Nicolas Boulenguez
b4244ddb09 lua: prevent defmacro! from mutating the original function 2024-08-26 10:00:47 -05:00
Nicolas Boulenguez
69d7d8d120 lua: prevent vec from mutating the original list 2024-08-26 10:00:47 -05:00
Nicolas Boulenguez
9a22e8a653 lua: merge eval and eval AST 2024-08-26 10:00:47 -05:00
Nicolas Boulenguez
56252444c8 lua: remove a safe but unneeded code line from Env::new 2024-08-26 10:00:47 -05:00
Nicolas Boulenguez
f15b7b4f10 lua: introduce a printer._pr_seq helper 2024-08-26 10:00:47 -05:00
Nicolas Boulenguez
15c7be28ec lua: improve consistency of keyword handling 2024-08-26 10:00:47 -05:00
Nicolas Boulenguez
91f2156ae6 lua: call hash_map instead of reimplementing it 2024-08-26 10:00:47 -05:00
Nicolas Boulenguez
3e8079e7b1 lua: simplify Makefile 2024-08-26 10:00:47 -05:00
Nicolas Boulenguez
309731037e lua: update Dockerfile 2024-08-26 10:00:47 -05:00
Nicolas Boulenguez
688503d2cc Rename python implementations to python2 and python3, see #665 2024-08-26 09:57:14 -05:00
Nicolas Boulenguez
87b283a350 python.2: fix tests, use source checkers and more python3 features
Check the whole code with flake8, pylint and mypy.

Report all possible errors with extensive context.

Demonstrate iterators, decorators, functional tools, chain maps,
dataclasses, match statements, assignments expressions.

Implement environments with python chain maps.

Rewrite the reader without external dependencies (but inspired by the
ptk library).  The motivation was that no external library is fully
type-checked for now.

Avoid name clashes when possible (print, read, readline, types).

Write the readline history file at exit, not after each prompt.

Replace printer.pr_str as methods of MAL objects.  This is idiomatic
python, and improves the error reporting.

Change some representations so that the python equality matches the
MAL equality.  The recursion is now implicit.

Remove -O from ./run.  It took me a while to understand that run-time
assertions were disabled!  MAL is about development, not performance.

Dispatch the special forms from a dict, for readability (pylint
rightfully complains that there are too many return statements in
eval_()).

Copy the recursion overflow fix, the python interaction from the first
python implementation.

Add tests detecting that nil false 0 () [] "" are distinct, and that 0
() are not False when tested (in python False == 0 and an empty
container is tested ).

Add tests checking that metadata does not affect equality (they do
with a naive python dataclass).
2024-08-24 10:16:32 -05:00
老刘
db7c10a689 vbs: remove NO_SELF_HOST for run self-host test on Github Action 2024-08-24 10:05:34 -05:00
老刘
3e040b4946 vbs: modify run for Github Action test 2024-08-24 10:05:34 -05:00
Joel Martin
e9dd8c53e5 sml: fix mlton self-host. Full syntax err in catch*
In mlton mode, syntax errors caught in the try/catch block were being
processed as "SyntaxError" without any additional context/message.
Explicitly pass the full message always.
2024-08-22 14:59:33 -05:00
Joel Martin
a2973ab0b8 xslt, c, zig: test for, fix seq parsing EOF errors
xslt:
- The reader was returning the an odd args error when a hash-map literal
  was not closed. This was because the the parsing error happened and
  then the odd args test happened after and overwrote the parsing error.
- Also, fix the read-string function so that if an error is set by the
  reader, this is converted to a full error that bubbles up.

c:
- read_list errors were not being detected/propagated in read_hash_map
  after calling read_list.

zig:
- reader errors were not being caught in the rep loop until step 8, so
  those errors in step6 and step7 were causing the REPL to exit.
2024-08-22 14:59:33 -05:00
Joel Martin
39563fdf7d vala: fix self-host: fix defmacro! return value.
The mal implementation uses the defmacro! function from the host
language/environment and assumes that it returns a macro function (and
ignores the environment modification effect). The vala implementation
was setting the is_macro flag at the wrong time so that the final
returned value from defmacro! was a function without the macro flag set.

Also, add a deferrable test of `defmacro!` to make sure it returns
a macro.
2024-08-21 09:29:40 -05:00
Joel Martin
a160866767 ps: return one value from macro? (fixes self-host)
In the false case, macro? was returning the input and false instead of
just false (missing pop for the false case).
2024-08-20 09:26:04 -05:00
Joel Martin
78000d6d9e powershell: fix self-host. Add fn? and [nil] tests.
Two problems were causing powershell self-hosting to fail:
* Some mal core functions are declared using `Get-Command` to hoist the
  lower level function and this didn't work with the `fn?` command. So
  add a stepA test for `(fn? list?)` and fix the `fn?` command to check for
  CommandInfo types too.
* A list with a single `$null` is treated specially by Powershell in
  a pipeline and was resulting in an empty Vector anywhere that `[nil]`
  was evaluated. Change all the pipelined uses of `ForEach` to
  `ForEach-Object` and wrap the result in an array construct `@( ... )`.
  Add a step2 test to make sure that `[nil]` is evaluated correctly.
2024-08-19 15:39:23 -05:00
Joel Martin
40aca13680 common-lisp: (list? nil) should be false (add test)
In common-lisp, self-hosted test4 was failing and it appeared that nil
and empty list () were being conflated. The root cause is that in
common-lisp the form `(list? nil)` was returning true. Fix this in the
core `list?` function.

There was no test for this case so add one to step4 tests.
2024-08-19 09:30:53 -05:00
Joel Martin
b31180cfd2 java,kotlin: fix double eval of last do position.
These implementations were double evaluating the last position of a do
form (off by one). Mostly this is just a performance issue until you
have something with side-effect in the last position such as prn's,
swap!'s or readline's. In self-hosted mode this become apparent with
large chunks of mal code in the last position. The symptoms were
repeated prns and multiple levels of readline being called, etc.

Add a step6 test that uses atoms to test this (should be in step
4 using prn side-effects but it's difficult to match across multiple
lines in a cross-platform way so we test using an atom in step6.

Also, remove cast in Kotlin that was causing a compile warning.
2024-08-19 09:01:41 -05:00
Joel Martin
7b23c7ed61 c.2/cpp/dart/swift5: fix try/TCO double eval bug
The try block needs to happen and be returned and not continue the TCO
loop. If it does then the successful result of a try block gets
evaluated an extra time so something like this `(try* (list 1) (catch*
e (prn :e e)))` will cause an exception. If an exception occurs, then
the catch block of a try/catch can loop/TCO without issue but not the
initial try form/block.
2024-08-18 15:27:51 -05:00
Joel Martin
412e50e306 common-lisp: update ubuntu 24.04. Fix key hashing bug.
Newer versions of sbcl now have the same sxhash issue on compound types
as the other common lisp implementations. So always dereference the
underlying base type when generating a hash. This fixes the bug in newer
sbcl that was resulting in `get` and `contains?` not working for
hash-maps.
2024-08-15 14:02:32 -05:00
老刘
a8f59bfd6c vbs: Update 'io.vbs' 2024-08-15 09:15:44 -05:00
老刘
a416719a57 vbs: rewrite stepA & core with IOWrap 2024-08-15 09:15:44 -05:00
老刘
ca9d6ee043 vbs: rewrite step9 using IOWrap 2024-08-15 09:15:44 -05:00
老刘
c6023577eb vbs: rewrite step8 using IOWrap 2024-08-15 09:15:44 -05:00
老刘
f4d2d91bb9 vbs: rewrite step7 using IOWrap 2024-08-15 09:15:44 -05:00
老刘
521fa87208 vbs: rewrite step6 using IOWrap 2024-08-15 09:15:44 -05:00
老刘
22a23d9c2a vbs: rewrite step5 using IOWrap 2024-08-15 09:15:44 -05:00
老刘
6e33dc8c3f vbs: rewrite step4 using IOWrap 2024-08-15 09:15:44 -05:00
老刘
176eca9c6a vbs: rewrite step3 using IOWrap 2024-08-15 09:15:44 -05:00
老刘
e8cf3057cd vbs: rewrite step2 use IOWrap 2024-08-15 09:15:44 -05:00
老刘
80e49c0509 vbs: Update io.vbs for avoid error 2024-08-15 09:15:44 -05:00
老刘
08b267b7f2 vbs: rewrite step1's IO with IOWrap 2024-08-15 09:15:44 -05:00
老刘
2a6174da20 vbs: rewrite step0 use IOWrap for test 2024-08-15 09:15:44 -05:00
老刘
79aac15158 vbs: impl IOWrap class in io.vbs 2024-08-15 09:15:44 -05:00
老刘
5d55568c9c vbs: import variable MAL_VBS_IMPL_NO_STDERR & MAL_VBS_IMPL_ECHO_STDIN 2024-08-15 09:15:44 -05:00
老刘
7e7ff1fbca vbs: test WSH.Echo "\nuser>" 2024-08-15 09:15:44 -05:00
老刘
512579cab1 vbs: remove run.cmd 2024-08-15 09:15:44 -05:00
老刘
fe7b2804b1 vbs: Replace All StdErr with StdOut 2 2024-08-15 09:15:44 -05:00
老刘
d3b31c0e93 vbs: Replace All StdErr with StdOut 2024-08-15 09:15:44 -05:00
老刘
f99240c340 vbs: because step6 argv test fail, restore run to remove cmd from it 2024-08-15 09:15:44 -05:00
老刘
17f1601d24 vbs: Unify newlines to LF for fix step6 slurp's error 2024-08-15 09:15:44 -05:00
老刘
1e404d5664 vbs: remove some comments 2024-08-15 09:15:44 -05:00
老刘
128afb113f vbs: use "2>&1" to combine stderr -> stdout 2024-08-15 09:15:44 -05:00
老刘
c91acfb22f vbs: Consider introducing the MAL_VBS_IMPL_NO_STDERR environment variable 2024-08-15 09:15:44 -05:00
老刘
d59b29c2a3 vbs: try exec stdbuf -o0 -e0 2024-08-15 09:15:44 -05:00
老刘
45dba4cbb5 vbs: append print to check out the cmdline 2024-08-15 09:15:44 -05:00
老刘
31fa6bc917 vbs: Merge branch 'kanaka:master' into master 2024-08-15 09:15:44 -05:00
老刘
6822f8c715 vbs: Simplify run.cmd 2024-08-15 09:15:44 -05:00
老刘
bfc0dbc4f5 vbs: remove the restriction that the first argument to 'apply' must be a function. 2024-08-15 09:15:44 -05:00
老刘
24ac2eeaf5 vbs: add an run script for pass the step6's argv_test 2024-08-15 09:15:44 -05:00
老刘
519524fba4 vbs: add return values to the test samples I wrote myself 2024-08-15 09:15:44 -05:00
老刘
92777df4aa vbs: replace bash script with batch script 2024-08-15 09:15:44 -05:00
老刘
a8f009b89b vbs: Merge branch 'master' into cy20lin-fix-windows-runtest 2024-08-15 09:15:44 -05:00
老刘
b9a26bea7e vbs: add an makefile to vbs impl 2024-08-15 09:15:44 -05:00
老刘
3ea750e652 vbs: add an 'run' script for vbs impl 2024-08-15 09:15:44 -05:00
OldLiu
900b82ff84 vbs: fix print privous return value in repl error 2024-08-15 09:15:44 -05:00
OldLiu
b23fcf5b16 vbs: rewrite error strings & remove my debug error info 2024-08-15 09:15:44 -05:00
OldLiu
7571c1923d vbs: fix (rest nil) try+catch+throw 's bugs 2024-08-15 09:15:44 -05:00
OldLiu
4682d3fc45 vbs: STEPA FINISH!!! 2024-08-15 09:15:44 -05:00
OldLiu
08434c3bae vbs: step9 pass! 2024-08-15 09:15:44 -05:00
OldLiu
b1d5b2f21c vbs: step9 finish except hashmap 2024-08-15 09:15:44 -05:00
OldLiu
9025928f53 vbs: step9 finished a quarter 2024-08-15 09:15:44 -05:00
OldLiu
19e780791e vbs: step8 finish! 2024-08-15 09:15:44 -05:00
OldLiu
0ca4cf28e6 vbs: step8 a half finished 2024-08-15 09:15:44 -05:00
OldLiu
475ded6a80 vbs: rewrite quasiquote with quasiquoteexpand & fix vec 2024-08-15 09:15:44 -05:00
OldLiu
8932321327 vbs: step 7 finish a half 2024-08-15 09:15:44 -05:00
OldLiu
f72d1d5dad vbs: rewrite all: normal fun will recive Env also 2024-08-15 09:15:44 -05:00
OldLiu
a7d3c59b23 vbs: step6 finish! 2024-08-15 09:15:44 -05:00
OldLiu
bf185a3374 vbs: fix ByRef's bug, todo: fix mem leak 2024-08-15 09:15:44 -05:00
OldLiu
e1abc7063c vbs: move specials from core to step4 2024-08-15 09:15:44 -05:00
OldLiu
0ed5b5121f vbs: add prn println str prn-str 2024-08-15 09:15:44 -05:00
OldLiu
89ff2dea63 vbs: fix evaluater's bug (create instead modify a list) 2024-08-15 09:15:44 -05:00
OldLiu
f1eb294ece vbs: add some functions 2024-08-15 09:15:44 -05:00
OldLiu
7136b8d877 vbs: rewrite step4 1 2024-08-15 09:15:44 -05:00
老刘
b77851c0b9 vbs: rewrite step3 & fix bugs 2024-08-15 09:15:44 -05:00
老刘
ed793f2046 vbs: Rewrite step2 2024-08-15 09:15:44 -05:00
老刘
d9f5be1700 vbs: new file 'types.vbs' & fix bugs & rewrite 2024-08-15 09:15:44 -05:00
老刘
2731ad293a vbs: rewrite step0 & 1 2024-08-15 09:15:44 -05:00
老刘
ffd110e0da vbs: rewrite codes 2024-08-15 09:15:44 -05:00
老刘
40e4bf6b72 vbs: env hotfix
combine env(when fn created) and running env into one
2024-08-15 09:15:44 -05:00
老刘
1a9d82ddde vbs: fix env's big bug
Env binding should happen in function calling
2024-08-15 09:15:44 -05:00
OldLiu
c458f9703f vbs: fix fn* calling bug which evaluate code twice 2024-08-15 09:15:44 -05:00
OldLiu
6649394940 vbs: core miss, added 2024-08-15 09:15:44 -05:00
OldLiu
ea478ced0f vbs: add step4(have some bugs) 2024-08-15 09:15:44 -05:00
OldLiu
3d43a1c92f vbs: step4 init:1 2024-08-15 09:15:44 -05:00
OldLiu
b535ffc66b vbs: step4 init: 2024-08-15 09:15:44 -05:00
OldLiu
054597e239 vbs: fix step3 2024-08-15 09:15:44 -05:00
OldLiu
0b7713a8f4 vbs: fix error dealing 2024-08-15 09:15:44 -05:00
OldLiu
1837f871f1 vbs: rewrite 3 2024-08-15 09:15:44 -05:00
OldLiu
e3ed41755d vbs: rewrite code 2 2024-08-15 09:15:44 -05:00
OldLiu
05cec5662d vbs: rewrite code1 2024-08-15 09:15:44 -05:00