Update: The single bug in the interpreter that caused it to fail on end was an off by one error. It was determining if it was on the final line of a function using fun_len==*line_num and it should have been fun_len-1==*line_num lol
Complex expressions fail. Both nested expressions and function calls.
It seems I am, as of yet, mortal.
(The error with program 2 appears to be in the reader, but the error with program 1 *looks* like it's in the evaluator. There is also a syntax error in program 2, but fixing it doesn't change the output.)
Okay further update. This is not a bug in the evaluator. It is a bug in the memory implementation, or rather, a bug in the thing that maps Rust-held handles to data managed by the GC. The evaluator is correctly failing because its input is something other than a program. This is
- Bad because it leaves open the terrifying possibility this evaluator will work on the first try
Me writing a copy collector: Haha fuck yeah!!! Yes!!
Me attempting to access the data in the copy collector from within the VM, without pointers moving out from under me during a collection: Well this fucking sucks. What the fuck
The 110-line LISP interpreter I wrote… worked… on the first try. I'm not sure it's clear from this screenshot but that's why you're seeing
The only problems were 1. Errors in memory.rs, the separate gc/memory handle file 2. Errors in globals.rs, ie, the implementations of "set" and "print" 3. The evaluator crashes *in the process of quitting*. Because it only does this *after* successfully running the program, it is a philosophical question whether the interpreter "works".
Just got the "reader" working… I think next step is the garbage collector. I may or may not implement regression tests first. I've got a reader so that means something I can regression test.
To my surprise I get to the point in the LISP evaluator where I handle function return and I suddenly discover that it is easier to implement tail recursion than it is to not implement tail recursion. This is the second time this has happened in my career
I just sort of wrote a LISP interpreter, mostly over two days. It is 110 lines long (the interpreter part; this is not counting the GC or the reader/parser). It felt suspiciously straightforward to write, I didn't like, *design* it, I was just like, yeah I've written an interpreter core loop before? Do that again but in Rust. It just sorta fell out.
I am *terrified* by the question of what will happen if I attempt to run this.
I had some time in a waiting room today, so my nameless experimental LISP now supports nested expressions as well as a slew of math operators.
I also realized (I skipped ahead a bit without fully testing the reader) that the parser chokes on negative numbers. "-5" is treated as a variable named "-5" instead of negative five. Oops.
Next: time Fix -5 and '() [ which may in fact get me all the way to functions, because I'm doing things a little odd here ]
I think maybe when I have this working, rather than trying to write it up I might make a short YouTube video about what makes it interesting. This would save my poor RSI and would also be a good way of getting some practice vlogging/kdenliving.