2 ms·
I will definitely have to give it a more throughout reading, I have implemented a naive JVM which shares some similarities, though much less compile time guaran
by kaba0 4y ago
I will definitely have to give it a more throughout reading, I have implemented a naive JVM which shares some similarities, though much less compile time guarantees (I do not compile anything, but load java class files).
My only gripe is that for my next iteration I want to use a template interpreter (instead of a naive execute instruction, fetch next, loop, which will have two indirect jumps, while a template interpreter instead can work like write instruction implementation addresses into an array, jump to the first, and let that implementation jump to the next one found in that array, having only one, better branch-predictable jump), and I believe it is not possible in a “high” level language (high, as in not assembly). Also, better control over the stack. But if I use in-line assembly (kudos for its authors, it is a really great abstraction!) then I can pretty much throw out almost every Rust type, as their memory layout is not well defined (I do know that I can force a C-layout, or packed, but I would need even stricter guarantees than that), so I can’t use them from within an asm block. So I am really thinking of whether Rust is a good choice here, as an interpreter will have plenty of unsafe, pointer manipulations, non-sync memory reads/writes (data racing Java is valid code, and it is well-defined so I have to basically use some sort of atomics? Not sure how well defined that part of Rust is (AFAIK it copies C++’s model, but even that postdates Java’s memory model, which was the first language to feature such)
Just to give an example of something I’m struggling with, I would like to have a Stackframe struct, but to use its elements from asm I can only implement it as a raw pointer-wrapper with a pre-defined layout, which will get hardcoded into assembly. Is there something I’m missing? Would be glad for some feedback.