

Ask HN: Compiler target - RiderOfGiraffes

OK, for reasons I won't go into I have a compiler that takes a bespoke language and compiles it into something else.  I can't go into specifics - trust me that I'm doing something sensible.<p>I now need to produce Linux executables and was going to target C as an intermediate language, but there are probably better choices.<p>I know you can't give me detailed specific advice without knowing more, but it would be useful to have generic advice.  What other target options are there?<p>I know there are things like C--, and I could even target Haskell or OCaml, say, and then compile from there.  I know someone will say Lisp.<p>What other choices are there, and what are their primary advantages?<p>Thanks.
======
iskander
Don't target OCaml. It's a fine language but a shitty backend. You'll get
saddled with a wonky 31/63 bit integer type and a very literal non-optimizing
compiler. Similarly, compiling to Haskell may result in unpredictable
performance due to unintentional laziness (though I guess you could stick
strictness annotations everywhere). I would go with LLVM-- they give you an IR
which is reasonably high level and comes with a whole armada of analyses and
optimizations.

~~~
hga
If you need GC make sure that LLVM's current story there is something you're
comfortable with. Or like the GHC (I gather) do your GC on top of its
primitives.

------
_delirium
I think it partly depends on what your input language is like. A nice aspect
of targeting C is that it's portable to pretty much everywhere, has multiple
good compilers, and is low-level enough that you can compile a lot of
different constructs to it efficiently (though not everything). But you'll end
up reimplementing nontrivial infrastructure and a runtime if you're compiling
a high-level language; e.g., does your source language have garbage
collection? Any sort of dynamic features? If yes, are they similar enough to
the semantics of any existing language that if you targeted that language you
might be able to piggyback on its features, e.g. use the target language's GC
to do your GC? (The latter idea has some of the same pitfalls/advantages of
internal DSLs.)

------
hga
"Lisp" ^_^.

Check out PreScheme in the Scheme48 distribution for a not-quite Lisp that
might be worth your while.

Compiling to Scheme in general can be a good solution, and there are plenty of
high performance and well supported Common Lisps out there like SBCL.

If you want ultimate preformance and compile times of days or a week plus are
tolerable, the Stalin optimizing Scheme compiler is supposed to be rather
special.

------
wmf
There's always LLVM if you really want control of the generated code.

------
hga
C-- outside of Haskell (the GHC) is dead in the water, the group that was
working on it has run out of money for it.

------
captaincrunch
I just put a post up here... no idea if it would help you or not...
<http://news.ycombinator.com/item?id=1361320>

