mirror of
https://github.com/usatiuk/psil.git
synced 2025-10-29 03:07:49 +01:00
even more docs
This commit is contained in:
21
README.md
21
README.md
@@ -87,4 +87,23 @@ Super debug mode:
|
|||||||
|
|
||||||
```shell
|
```shell
|
||||||
build/src/psil -f clitests/decorate.psil --repl- --command_strs+ --default_log_level:4 --log:MemoryContext:3
|
build/src/psil -f clitests/decorate.psil --repl- --command_strs+ --default_log_level:4 --log:MemoryContext:3
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# 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 :)
|
||||||
|
|
||||||
|
|||||||
19
clitests/examples.psil
Normal file
19
clitests/examples.psil
Normal file
@@ -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)
|
||||||
9
clitests/examples.psil.ex
Normal file
9
clitests/examples.psil.ex
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
5
|
||||||
|
-1
|
||||||
|
0
|
||||||
|
2
|
||||||
|
1
|
||||||
|
2
|
||||||
|
1
|
||||||
|
55
|
||||||
|
5
|
||||||
Reference in New Issue
Block a user