Making a programming language using Rust
arzg.github.io
arzg.github.io
I'm using sea creatures lately :-).
I'm new to llvm IR. it is more assembly than I thought. my language is similar to javascript. I found it's difficult to map it to llvm IR.
Basically the only slightly non-trivial step is closure conversion[1] which lifts free (AKA "captured" in C++ terminology) variables from a closure, which lets you encode closures faithfully in a first-order language with structs.
[0] https://github.com/jozefg/pcf/
[1] http://lampwww.epfl.ch/teaching/archive/advanced_compiler/20...
This technique is used by functional language compilers, see Compiling With Continuations for more info on the underlying theory
[0]: https://en.wikipedia.org/wiki/Continuation-passing_style
[1]: https://books.google.com/books/about/Compiling_with_Continua...
This is true, however CPS moves the work from the stack to the heap, so a deep enough recursion would exhaust the heap instead. Using a trampoline[0] in conjunction with CPS ensure constant stack usage for tail-recursive functions.
[0] https://dspace.mit.edu/bitstream/handle/1721.1/5753/AIM-443....
[0] https://www.more-magic.net/posts/internals-gc.html#managing-...
I'm actually compiling to WebAssembly but it's the same principles
My current approach is writing my runtime in c or c++, and put most logic there. And I will try to generate c code first, and compile the c code using clang and learn from the generated IR.
I kinda want to write the runtime also in rust, but I don't know if linking will be a problem.
Generating C seems like a good middle ground. I also considered that. Frankly though code generation is hard regardless because you’re gonna have some abstractions that just don’t lower nicely.
Writing the runtime in Rust might work but ownership might get in the way.
Happy to talk about this more if you want. Shoot me an email
I found myself that LLVM has a very high barrier to use.
It’s wonderful to see a programming guide that has thought hard about typography (and Freight works great here).
font-family: freight-text, Iowan Old Style, Georgia, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif;
I… what? The web-font serif, then a macOS (I think?) serif, then a Windows serif, then… system-ui stuff which is almost always sans-serif, then sans-serif fallbacks. This is a bizarre mixture.This immediately makes much more sense:
font-family: freight-text, Iowan Old Style, Georgia, serif;
And I tend to think just this would be better: font-family: freight-text, serif;
Also, one other rule that I can’t let pass by without comment: letter-spacing: .01em;
Bumping letter-spacing is always risky: the designer chose the spacing they did for a reason. Pretty much the only circumstances you should do it are (a) very specific display purposes (that is, headings and the likes—typically 0.2em or more) and (b) all caps (typically something like 0.07ex). Body text letter-spacing bumps are almost always a bad idea. In this case, it’s even already using a fairly wide font. (Well, so long as freight-text is used. I really wish all font properties (font-, letter-spacing, &c.*) could be varied by font availability, so that you could do things like bump font-size if you use your own web font with smaller metrics than the likely fallback font.)[0] https://rssproxy.migor.org/api/feed?url=https%3A%2F%2Farzg.g...