4 ms·
Web is eating world We use it for crossplatform dev. We use json as data exchange format everywhere We will run our apps in webassembly based sandboxes So h
by hardware2win 4y ago
Web is eating world
We use it for crossplatform dev.
We use json as data exchange format everywhere
We will run our apps in webassembly based sandboxes
So how about using this mature techstack to talk to OSes too?
- lolinder 4y agoPlenty of people do--it's called Electron. The problem C and friends solve is "how do you write the web or the OS?" You can't bootstrap an interpreted language like JavaScript or even WebAssembly, the VM has to be written in something.
- efficax 4y agoand in fact the VM pretty much has to be written in C (or C++, or you could get away with unsafe rust) since efficient function dispatch (not to mention JIT) are difficult without wildeyed pointer manipulation (you want to emit instructions to somewhere in memory and then jump to them, something inherently unsafe)
- lolinder 4y ago> you want to emit instructions to somewhere in memory and then jump to them, something inherently unsafe Isn't this only for JIT? My understanding was that non-JIT VMs basically function as emulators of a non-existent CPU, so they interpret each bytecode instruction rather than asking the CPU proper to do a jump.
- efficax 4y agoeven a bytecode vm has to emit bytecode and then move an instruction pointer around. You can do it without using C pointer manipulation but it will always be less than ideal. This is a nice little blog post about it: https://pliniker.github.io/post/dispatchers/ https://pliniker.github.io/post/dispatchers/
- lolinder 4y agoThanks! I'm starting work on a VM right now for a side project and was seriously considering using Rust, so this will be really helpful!
- an-unknown 4y ago> and in fact the VM pretty much has to be written in C What makes you think that you need C/C++ for this? Compilers were and still are written in many languages, and you can always come up with a compiler written in an "arbitrary" language which outputs e.g. an executable ELF file containing your VM runtime code. There are a few examples of this in the wild btw, look at e.g. the GraalVM and its SubstrateVM sub-project.
- efficax 4y agoI'm not familiar with the way GraalVM is implemented but I do know that at some point it has to have access to raw memory and registers in order to do JIT. There's no getting around that (and you can't do that with just java). A compiler is different from a JIT engine since yeah you can just write whatever binary you want to disk, hell you could write an x86 compiler in javascript. but if you want to emit instructions to memory and send the CPU there to consume them, you need a smidge of native code.
- pjmlp 4y agoYes you can, that is what compiler intrisics are for. https://chrisseaton.com/truffleruby/jokerconf17/ https://chrisseaton.com/truffleruby/jokerconf17/
- dahfizz 4y agoSomeone actually has to implement the web browser / "tech stack". Web assembly, despite it's name, is an interpreted language. It is not magic. Interpreted languages need an interpreter (written in C).
- hardware2win 4y agoWhy written in C? If C is just wrapper over asm Then emit it from any other lang
- dahfizz 4y agoBecause, as the article states, the OS interface is C. In order to do anything useful at all in your code, you need to call through the C API of your operating system. To replace this, you would need another compiled language. It can't be "any other lang" - it needs to be something compiled down to machine code that can be directly executed on your CPU. So you could write a new OS that presents an interface in Rust, or Zig, but never WASM.
- pjmlp 4y agoIBM and Unisys mainframes and microcomputers beg to differ, with their language environments.
- lolinder 4y agoI don't think it has to be C, but it can't be any arbitrary language. It has to compile to machine code, and I wouldn't want to implement a VM in a garbage collected language because you need more fine-grained control over memory then those can provide. That last requirement rules out most languages with any significant community besides C/C++, Rust, Zig, and a few other even lower profile C replacements.
- kevin_thibedeau 4y agoBecause that mature stack is burning a lot of cycles converting binary data into text and back.