Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choosing an intermediate language

I am currently playing around with programming languages. I have spent some time writing parsers and interpreters in high level languages (most notably Haxe).

I have had some results, that I think are actually quite nice, but now I'd like to make them fast.

My idea was to translate the input language into C.
My C knowledge is limitted to what you learn at university. Beyond some exercises, I have never written actual C programs. But I feel confident I can make it work.

Of course I could try to write a frontend for the LLVM or to generate MSIL or JVM bytecode. But I feel that's too much to learn right now, and I don't see much of a gain actually.
Also C is perfectly human readable, so if I screw up, it's much easier to understand why. And C is, after all, high level. I can really translate concepts from the input language without too much mind-bending. I should be having something working up and running in a reasonable amount of time and then optimize it as I see fit.

So: Are there any downsides to using C? Can you recommend an alternative?
Thank you for your insight :)


Edit: Some Clarification

  • The reason why I want to go all the way down is, that I am writing a language with OOP support and I want to actually implement my method dispatching by hand, because I have something very specific in mind.
  • A primary area of use would be writing HTTP services, but I could image adding bindings to a GUI library (wxWidgets maybe) or whatever.
like image 503
back2dos Avatar asked Jun 14 '11 16:06

back2dos


1 Answers

C is a good and quite popular choice for what you're trying to do.

Still, take a look at LLVM's intermediate language (IR). It's pretty readable and I think it's cleaner and easier to generate and parse than C. LLVM comes with quite a big collection of tools to work with it. You can generate native code for variety of platforms (as with C but with slightly more control over output) or for virtual machines. Possibility of JIT compilation is also a plus.

See The Architecture of Open Source Applications, Chapter 11 for introduction to LLVM approach and some snippets of IR.


What is your target environment? This might help us give you better answer.

like image 104
Tomek Szpakowicz Avatar answered Sep 28 '22 14:09

Tomek Szpakowicz