r/Zig • u/Last-Employ-3422 • 1d ago
I made an x86_64 machine code generator
https://github.com/NoTimeDev/ZasmSo, I wanted to make a JIT compiler for my friend's programming language, but it's in Zig, so about 5 days ago, I decided I was going to learn Zig by making the JIT library in it, and I made this! Lemme know what you think. Btw, this isn't supposed to be a competitor to any other libs like this in Zig (I don't know of any, but yk).
1
u/HorseyMovesLikeL 1d ago
Not a gotcha question but how is this different than just writing inline assembly? https://ziglang.org/documentation/master/#Assembly
Great learning exercise at the very least though!
1
u/Last-Employ-3422 1d ago
Well that happens at comptime, this happens at runtime
1
u/HorseyMovesLikeL 1d ago
In what sense? The only significant comptime specific thing in the doc I linked regarding assembly is global assembly, which you can still call at runtime. It's just defined by wrapping it in a comptime block at namespace level.
7
u/Last-Employ-3422 1d ago
Oh, Zig compiles assembly into machine code at compile time, which can be executed at runtime. My lib encodes the instructions into machine code at runtime which can be executed at runtime. Its useful for programs where the generated machine code needs to change based on runtime input like FFI or JIT compilers
1
1
u/SweetBabyAlaska 1d ago
You are both generating and running assembly at runtime. It's a really fast way to drive a dynamic higher level language.
What you're pointing out is static compilation
8
u/igors84 1d ago
Very nice start. Be sure to watch this talk from Andrew Kelly https://www.youtube.com/watch?v=IroPQ150F6c&t=6s since you might decide to optimize your data storage a bit and that is better done earlier than later :)