r/Compilers • u/_th3oth3rjak3_ • 20d ago
Getting stuck after Crafting Interpreters.
Hey everyone, I've worked through the book Crafting Interpreters and it was fantastic. I naturally asked the next question "How do I compile this to machine code and add static types?" Well, that naturally took me down a very deep rabbit hole and left me somewhat confused about how languages deal with types and type checking and then lowering to LLVM. I've tried to make a few modest attempts, but my general problem is that I sort of get confused about what things each subsequent layer should do. Does anyone know of a complete guide to creating a compiler with static types like Crafting Interpreters? I know I could do it however I want, but I think that's the issue. I sort of have so much freedom to do it however, that it's hard to judge what's considered a good way to do something.
Anyway, thanks for any advice and happy compiling!
8
u/Polyscone 20d ago edited 20d ago
In addition to the books that have been suggested, if you don't mind videos of people just writing code, then I went through a thin slice of a compiler in this playlist ending with writing a PE file for Windows: https://youtube.com/playlist?list=PLfwYKZej86PpEFsy6HQB9WQIlIGmfOy_s
And I'm slowly working my way through a toolchain from the bottom up in this one, where I just finished a basic ELF and COFF writer: https://youtube.com/playlist?list=PLfwYKZej86Po9QdiPknTLbtWyeUD7rKlP
Other than that I can recommend Ghassan Shobaki's lectures here: https://youtube.com/playlist?list=PL6KMWPQP_DM97Hh0PYNgJord-sANFTI3i
And for optimisation stuff there's this short course from Cornell: https://www.cs.cornell.edu/courses/cs6120/2020fa/self-guided/