Suitability of D for writing JIT Tracing compiler?

I would like to write an interpreter and trace the JIT for the programming language that I am developing. I already have many years of programming experience in C ++, but I was wondering if perhaps newer alternatives are possible. One of the things that seemed to me the most disappointing in my C ++ days was to use header files to work with the awkward one-pass compiler model. The problem is that not all languages ​​are equally suitable for this purpose. For my JIT trace, I need to write the executable code into memory and call the interpreter on this code. I will also need the generated code in order to be able to call back to host functions.

I started to look at Go and saw that the language has pointers, but without pointer arithmetic. It immediately seemed to me a huge problem. Perhaps I want to write my own disposer and garbage collector. I will need to precisely control how my language objects are laid out in memory, and be able to get the address of certain fields and write to them. Unless you have a way to handle this, it looks like Go might not be low enough for my purposes.

D language seems promising. It has pointer arithmetic and a clear ABI diagram needed to call and exit D. I have heard many good things about this. It also has garbage collection, which is good for writing a compiler, but I still have a few things that I'm not sure about:

  • Does D have standard libraries that allow me to mark pieces of memory as executable?

  • If I allocate a large chunk of memory that I want to manage myself with my own GC and have a bunch of pointers included in it, will there be problems with garbage collector D?

  • How well does D interact with C code in your experience? Is loading dynamic C libraries and calling them pretty easy?

Finally, there is the whole aspect of support. For those using D on linux here, how good is the toolchain? Any problems? Has anyone written a JIT compiler in D, and if so, how was it?

+5
source share
4 answers
  • I think so, see core.memory.GCif I remember correctly.

  • No, it should not. Just call mallocor what you need and make sure that the GC does not see it.

  • Yes, it's pretty easy to interact with C code.

: , , GC, "" ( , ). .

+5

Go , unsafe ( C). - , Go , , , C. unsafe uintptr , uintptr - , .

+4

JIT-, , D. http://lycus.org/, MCI - http://github.com/lycus/mci. MCI . , MCI - , JIT, (, - , ) IR, , ..

+2

Go , , . .

, , . - " ". , "" , - .

, . , , .

, . Go . . http://research.swtch.com/godata . , aligment http://golang.org/ref/spec#Size_and_alignment_guarantees. , C asm.

, , , Go . http://groups.google.com/group/golang-nuts.

+2

All Articles