Live data from Hacker News

Building a Lox Interpreter in Julia

lukemerrick.com

1–10 of 25 posts

Re: Building a Lox Interpreter in Julia

#2
Disclaimer: I wrote this blog post. If this were an "Ask HN" post, though, the question would be "What next after reading Crafting Interpreters?" I have only done the tree-walk interpreter half of the book, but I'm already excited to move beyond Lox, and I'm curious to hear what others have done in this situation.

Re: Building a Lox Interpreter in Julia

#3
I thought working with the lossless syntax tree was the key to Rust's pin-point precise error messages. How does rust-analyzer get and print the specific point of error if it throws away the non-essential information before that stage? I suppose the position information is stored along with the Error nodes, in the original parsing?

Re: Building a Lox Interpreter in Julia

#4

I thought working with the lossless syntax tree was the key to Rust's pin-point precise error messages. How does rust-analyzer get and print the specific point of error if it throws away the non-essential information before that stage? I suppose the position information is stored along with the Error nodes, in the original parsing?

In general, if you keep the source code positions of every nontrivial token, and you keep the raw source code, then yeah you can print out those pretty specific point error messages regardless of whether you keep your trees lossless. Also, if you want to include filename in your messages (perhaps because unlike Lox your language supports imports), then you'll need more than just lossless trees to store the necessary information.

I'm not sure exactly how Rust and rust-analyzer keep track of the info necessary to their excellent error messages and diagnostics, but I wouldn't be surprised if pinpoint messages were not the primary motivation for rust-analyzer to do lossless parsing.

Re: Building a Lox Interpreter in Julia

#5

Disclaimer: I wrote this blog post. If this were an "Ask HN" post, though, the question would be "What next after reading Crafting Interpreters?" I have only done the tree-walk interpreter half of the book, but I'm already excited to move beyond Lox, and I'm curious to hear what others have done in this situation.

You can try and build your own toy language for fun, or try to compile lox to some assembly/llvm ir.

Another option is to try and contribute to an existing language (Julia ;) ).

Re: Building a Lox Interpreter in Julia

#6

Disclaimer: I wrote this blog post. If this were an "Ask HN" post, though, the question would be "What next after reading Crafting Interpreters?" I have only done the tree-walk interpreter half of the book, but I'm already excited to move beyond Lox, and I'm curious to hear what others have done in this situation.

a fast lisp interpreter/compiler?

Re: Building a Lox Interpreter in Julia

#7

Disclaimer: I wrote this blog post. If this were an "Ask HN" post, though, the question would be "What next after reading Crafting Interpreters?" I have only done the tree-walk interpreter half of the book, but I'm already excited to move beyond Lox, and I'm curious to hear what others have done in this situation.

I am wondering why the julia lox interpreter is so slow. Could it be that there is a lot of type unstable code or could it be an issue with julia's garbage collector? (I can relate to the comment that it is quite hard to find usable information from julia's profiler).

Re: Building a Lox Interpreter in Julia

#8

Disclaimer: I wrote this blog post. If this were an "Ask HN" post, though, the question would be "What next after reading Crafting Interpreters?" I have only done the tree-walk interpreter half of the book, but I'm already excited to move beyond Lox, and I'm curious to hear what others have done in this situation.

I continued by taking a compilers and a interpreters course at my university. In the interpreters course a friend and I desinged a new language and implemented it. It turns out designing a language is pretty hard, but it was quite fun and am proud of the project. Also I really wanted to implement a typechecker, so we did that too.

https://github.com/flofriday/Moose

Re: Building a Lox Interpreter in Julia

#9

Disclaimer: I wrote this blog post. If this were an "Ask HN" post, though, the question would be "What next after reading Crafting Interpreters?" I have only done the tree-walk interpreter half of the book, but I'm already excited to move beyond Lox, and I'm curious to hear what others have done in this situation.

I'd do the second half of the book, it's got plenty of important techniques that aren't taught in the first half.

Once you've done that, you can see how it's done "for real" in a production setting by reading the source code to Wren (by the same author). [0]

Wren's implementation maps very closely to the C implementation of Lox.

At that point, you're ready to do your own language. As far as compilation techniques go, you'll still be missing the "middle-end" of the compiler, which uses an SSA IR. I don't recommend implementing this yourself, I'd look into MLIR (from the LLVM project) if you want to actually work on the middle-end. You can create one or more dialects that are unique to your language, and implement your own compiler transformations. There are lots of existing papers and projects on GitHub demonstrating doing so.

[0] https://wren.io/

Re: Building a Lox Interpreter in Julia

#10

Disclaimer: I wrote this blog post. If this were an "Ask HN" post, though, the question would be "What next after reading Crafting Interpreters?" I have only done the tree-walk interpreter half of the book, but I'm already excited to move beyond Lox, and I'm curious to hear what others have done in this situation.

I just finished the bytecode interpreter side, and I have similar questions. The next areas of interest for me are reasonable AST representations in C and learning how to translate a semantics from a PL paper to a runtime. Anyone have any recommendations?
Post reply on HN