Go to file
VaclavT 7f793bde61 misc fixes 2021-09-23 23:03:54 +02:00
.vscode misc fixes 2021-09-23 23:03:54 +02:00
clib usql update 2021-08-31 19:00:03 +02:00
doc version 0.2 2021-06-10 23:26:14 +02:00
stdlib added 5 new functions (sixth, seventh..) 2021-09-20 18:24:21 +02:00
tests quick-sort-reverse added 2021-06-08 23:27:46 +02:00
tmp debug changes 2021-03-07 17:23:09 +01:00
usql misc fixes 2021-09-23 23:03:54 +02:00
utils syntax file for vs code lisp extension 2021-09-20 18:26:01 +02:00
.gitignore small lisp updates 2021-02-21 21:53:45 +01:00
CMakeLists.txt usql updates, lexer changes 2021-09-15 21:22:24 +02:00
Readme.md syntax file for vs code lisp extension 2021-09-20 18:26:01 +02:00
debug.lsp be more benevolent on symbol names 2021-09-17 00:00:13 +02:00
ml.cpp misc fixes 2021-09-23 23:03:54 +02:00
ml.h usql updates, lexer changes 2021-09-15 21:22:24 +02:00
ml_date.cpp usql updates, lexer changes 2021-09-15 21:22:24 +02:00
ml_date.h comments update 2021-07-23 00:02:03 +02:00
ml_io.cpp slightly nicer code 2021-05-03 18:29:29 +02:00
ml_io.h include path changes 2021-02-26 09:49:01 +01:00
ml_profiler.cpp namespace removed where not needed 2021-07-27 19:37:07 +02:00
ml_profiler.h version 0.2 2021-06-10 23:26:14 +02:00
ml_string.cpp added two string functions, doc updates 2021-05-10 19:07:50 +02:00
ml_string.h usql update 2021-08-23 18:14:05 +02:00
ml_usql.cpp null needs to be mapped too 2021-09-20 18:25:43 +02:00
ml_usql.h very basic version of usql 2021-07-14 12:01:44 +02:00
ml_util.cpp usql update 2021-08-23 18:14:05 +02:00
ml_util.h fixes & enhandcements 2021-03-14 16:15:04 +01:00

Readme.md

ml

is a small lisp interpreter based on Adam McDaniel's wisp interpreter (https://github.com/adam-mcdaniel/wisp). It's main purpose is to learn something about more recent c++

Example of use

cat <<EOT > /tmp/qs.lsp
(defun qs (l)
    (if (<= (len l) 1)
        l
        (do
            (define pivot (first l))
            (+
                (qs (filter (lambda (n) (> pivot n)) l))
                (list pivot)
                (qs (tail (filter (lambda (n) (<= pivot n)) l)))
            ))
    ))

(print (qs '(10 9 8 7 6 5 4 3 2 10)))
EOT

ml -f /tmp/qs.lsp

or

ml -f tests/test.lsp

Interactive mode

ml

Documentation

see /doc/Doc.md

Compile

mkdir -p build
gcc -std=c99 -c -O2 -o linenoise.o clib/linenoise.c
c++ -c -O2  -I/usr/local/opt/openssl/include -Iclib --std=c++17  ml.cpp ml_io.cpp ml_date.cpp ml_string.cpp ml_util.cpp ml_profiler.cpp clib/json11.cpp clib/csvparser.cpp clib/sslclient.cpp clib/printf.cpp clib/linenoise.c usql/exception.cpp usql/lexer.cpp usql/parser.cpp usql/usql.cpp usql/table.cpp usql/table.h usql/row.cpp usql/csvreader.cpp usql/settings.cpp usql/usql.cpp

// on linux c++ -o build/ml -O2 -L/usr/local/lib -L/usr/local/opt/openssl/lib -lm -lstdc++ -lcrypto -lssl *.o
c++ -o build/ml -O2 -L/usr/local/lib -L/usr/local/opt/openssl/lib -lm -lstdc++ -lcrypto -lssl -Wl,-stack_size -Wl,0x1000000 *.o

// or cmake

Install

cp build/ml /usr/local/bin/ml
cp stdlib/*.lsp /usr/local/var/mlisp/

or

utils/local_install.sh

KNOWNN BUGS

(read-url "https://api.nasdaq.com/api/calendar/dividends/") ; hangs in sslclient.cpp line 132

TODO

  • add debug support, at least call stack
  • multiline editing (see kilocpp editor)
  • execute system command should capture stderr
  • add some mem stats to benchmark
  • add tests for usql

Code

  • add documentation
  • add more unit test, mainly for usql
  • rename constants in ml_profiler.h
  • replace to_string macro in ml.cpp
  • add instrumentation (time, nr of evals, num of atoms, debug info, debug environment etc)

Language

  • support for "#t" or "t" symbol as a true and "#f" for false
  • support for exceptions
  • string functions
    • compare - needed for sorting, cmp ignore case
    • regexp match, regexp tokens
  • date support
  • env functions
    • get-env, set-env; set-env cannot be implemented in stdlib.lsp, because popen is in fact subshell
  • add include-stdlib function for other libs in stdlib dir (during startup stdlib.lsp is loaded only)
  • syntax highlighting do VS Code

Performance

  • define is one of most frequent callee, when in scope with very few vars, lookup sequentially
  • first, second are often called -> implement in c++
  • push_back - repeatedly without reserving size
  • range - with for(int i...) and reserving result size can be 3times faster on (range 1 10000)
  • mini_sprintf - unnecesary copying between vector and list
  • (do, scope ..) repeatedly assign to acc

https://github.com/adam-mcdaniel/wisp
https://github.com/dropbox/json11
https://github.com/antirez/linenoise

read stdout and stderr from popen

https://stackoverflow.com/questions/478898how-do-i-execute-a-command-and-get-the-output-of-the-command-within-c-using-po