News for hackers. Stuff that matters.
Re:Show HN: A small virtual machine written in C by TheHydroImpulse on Monday August 04, 2014 @02:22AM (#8130602)
You'd essentially be generating machine code on the fly and letting the cpu execute it, instead of interpreting anything yourself.
Re:Show HN: A small virtual machine written in C by tekknolagi on Monday August 04, 2014 @02:25AM (#8130611)
Interesting. Is that significantly harder?
Re:Show HN: A small virtual machine written in C by TheHydroImpulse on Monday August 04, 2014 @02:33AM (#8130628)
It does make it more complex since you now have another layer to deal with. I wouldn't roll by own JIT compiler though, otherwise it would definitely be a crap ton harder. Using something like libjit or llvm's JIT compiler are two good options.

It's nice having a normal, interpreted VM then building a JIT compiler later on for extra speed. A recent Rust project called `js.rs`[0] started out with a simple interpreter and swapped it for a JIT compiler using libjit.

The biggest difference being you now have to interface with the actual CPU and such.

[0] https://github.com/TomBebbington/js.rs

Re:Show HN: A small virtual machine written in C by chewxy on Monday August 04, 2014 @02:37AM (#8130632)
if you're already writing in C, no. Just write some functions to convert those instructions into asm, and write an assembler (or use one of the many out there) to output them to bytes. Then use mprotect(), tadah!
Re:Show HN: A small virtual machine written in C by tekknolagi on Monday August 04, 2014 @02:44AM (#8130644)
Interesting.