Simple utility to make running machine code via Janet easy and fun!
I was experimenting with building a callable JIT for Janet and figured wanted to make a pitstop to allow assembly program generation from Janet itself!
This allows you to write machine code in a Janet buffer and run it!
(import /build/asm :as asm)
(var prog (buffer/new 256))
(buffer/push-byte prog 0x48) # MOV RAX, imm64
(buffer/push-byte prog 0xB8)
(buffer/push-float64 prog :native 123) # imm
(buffer/push-byte prog 0xC3) # quit
(def my-fn (asm/build prog))
(pp (my-fn)) # => 123This is not a very useful program, it just returns 123. You can see other fun program examples in the examples/ directory.
There is a tiny example of a impossibly simple x86 JIT that compiles a Janet function to very simplified assembly code. It only works with numbers and +,-,*,/ operations. This could be extended to a more serious JIT, but this example remains simple for illustration.
Only tested on x86 System V Linux and ARM mac.