From 8f5294fea7939524fdc4e21caa4ee71b9feab02e Mon Sep 17 00:00:00 2001 From: Stepan Usatiuk Date: Thu, 4 Jan 2024 12:41:19 +0100 Subject: [PATCH] even more docs --- README.md | 21 ++++++++++++++++++++- clitests/examples.psil | 19 +++++++++++++++++++ clitests/examples.psil.ex | 9 +++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 clitests/examples.psil create mode 100644 clitests/examples.psil.ex diff --git a/README.md b/README.md index dd949d7..fba11fb 100644 --- a/README.md +++ b/README.md @@ -87,4 +87,23 @@ Super debug mode: ```shell build/src/psil -f clitests/decorate.psil --repl- --command_strs+ --default_log_level:4 --log:MemoryContext:3 -``` \ No newline at end of file +``` + +# Some notes on the implementation + +The implementation is rather straightforward, based mostly on the compiler from "THE ARCHITECTURE OF SYMBOLIC +COMPUTERS", with little modification and some additions. Notably, the let/letrec is more lisp-like, using racket-like +name-value pairs instead of them being in separate lists like in the book. Also, there's support for top-level functions +using `define`, and a simple concurrent garbage collector. + +There are three basic value types which is a string atom, number atom, and a cons cell. + +String atoms are basically used only internally, and you can't do much with them other than printing them. With number +atoms you can do all the usual arithmetic, and they also serve as bools - any value greater than 0 is considered true +for the purposes of `if`. And of course, all the usual stuff with cons cells - `car`, `cdr`, `cons`... + +Other language features were implemented to the extent that was required for writing some simple programs copied from +what I have done for homework - it's in the `clitests` folder (and for simpler examples there's `examples.psil`, and it +probably serves as the best reference for the +language that this interpreter interprets :) + diff --git a/clitests/examples.psil b/clitests/examples.psil new file mode 100644 index 0000000..23b12d0 --- /dev/null +++ b/clitests/examples.psil @@ -0,0 +1,19 @@ +(let ((plus (lambda (a b) (+ a b)))) (plus 2 3)) +(let ((minus (lambda (a b) (- a b)))) (minus 2 3)) +(let ((minusone (lambda (a b) (- a b))) (minustwo (lambda (a b) (- b a)))) (minustwo 2 (minusone 3 1))) + +(let ((iffn (lambda (a) (if a 1 2)))) (iffn 0)) +(let ((iffn (lambda (a) (if a 1 2)))) (iffn 1)) +(let ((iffn (lambda (a) (if (> a 1) 1 2)))) (iffn 1)) +(let ((iffn (lambda (a) (if (> a 1) 1 2)))) (iffn 2)) + +(letrec ((fib (lambda (n) (if (> n 0) + (if (> n 1) + (+ (fib (- n 1)) + (fib (- n 2))) + 1) + 0)) +)) (fib 10)) + +(define (globalplus x y) (+ x y)) +(globalplus 2 3) \ No newline at end of file diff --git a/clitests/examples.psil.ex b/clitests/examples.psil.ex new file mode 100644 index 0000000..d0056cc --- /dev/null +++ b/clitests/examples.psil.ex @@ -0,0 +1,9 @@ +5 +-1 +0 +2 +1 +2 +1 +55 +5 \ No newline at end of file