5 ms·
I used it as a workout for the compiler that I'm writing. I solved every problem in my own language, so that was pretty cool. The language is now almost as powe
by ahaferburg 8y ago
I used it as a workout for the compiler that I'm writing. I solved every problem in my own language, so that was pretty cool. The language is now almost as powerful as C. I kept all the code in one file, which now has grown to 4500 LoC (non-empty, non-comment), producing 38k LoC in LLVM.
On day 6 I got a stack overflow, so I had to quickly implement new/delete. For the Elf processor I had to add in binary operators. Design-wise it taught me that good literals can be really helpful, e. g. an initializer expression for an array of structs. With Python's dict/tuple/array literals e. g. you could sometimes replace parsing entirely with a couple text transformations in Sublime. Maybe this is specific to these kinds of problems, but I think it would also be helpful for unit tests.
It was fun to learn a new algorithm (A*) and implement it. Day 23 part 2 was my favorite. I was stuck for hours, tried two solutions that didn't work out. Went to bed frustrated, then implemented the solution the next morning. I'm still thinking about it, it's an interesting problem.
- Zedronar 8y agoIs there any particular technical reason behind the decision of having 4500 LoC in a single file? It sounds like a pain to maintain and extend.
- ahaferburg 8y agoI wanted to always compile everything, and I don't have modules yet. Every problem is in one function, so for AOC it wasn't a problem.
- tomsmeding 8y agoThat sounds awesome! Do you have any published code for your compiler/language yet? I'm curious :)
- ahaferburg 8y agoThanks! Sorry, I haven't published anything. My inspirations are Jai, Zig, Ante, and Odin, if that helps.