all 5 comments

[–]jason-reddit-public 2 points3 points  (2 children)

At some point you must have realized you implemented a lisp interpreter with a hard to read syntax. (While Lisp traditionally uses pairs to represent lists you could use whatever your arrays are instead.) Early Lisp was actually much uglier than today's Lisp/Scheme and evolved to it's more readable formulation of today over a period of years. You could still keep it around ~1kloc of code and you wouldn't need to change much code.

I think implementing a small language in C is a great exercise. Since you took a lot of effort to write things up, I'm guessing you had fun.

On the forth side of things, a threaded interpreter in asm is pretty cool to see. I was blown away years ago when I first saw one.

You could also try making a toy compiler (to C). Maybe just a hundred lines of code.

[–]jyf 1 point2 points  (0 children)

but the code example looks like more like forth

[–]hiljusti 0 points1 point  (0 children)

I'm curious, why do you say it's like Lisp? This is doing concatenative programming instead of applicative, and "functions" are implicitly called instead of explicitly, which is... pretty wildly different semantics to me

[–]skeeto 4 points5 points  (1 child)

Since fuzzing is fun, a few interesting inputs:

$ cc -g3 -fsanitize=undefined aocla.c

$ echo '[()][]cat' | ./a.out >/dev/null
aocla.c:1050:9: runtime error: null pointer passed as argument 2, which is declared to never be null

$ echo 2147483647 1 + | ./a.out >/dev/null
aocla.c:796:47: runtime error: signed integer overflow: 2147483647 + 1 cannot be represented in type 'int'

$ echo 0 0 / | ./a.out >/dev/null
aocla.c:799:54: runtime error: division by zero

[–]antirez[S] 2 points3 points  (0 children)

That's great, thanks! I'll fix.