My understanding is that a self-hosting compiler will take as input the language it is written in and a cross-compiler will output a language which runs on a platform which is different to what it runs on.

Can we combine these two compiler types into one?

  • 3
    $\begingroup$ A compiler, of any kind, can be written in any language. So a cross-compiler can be written in C, Java, Haskell, Prolog, etc... That includes cross-compilers which output to different platforms than the one they are written on. So yes, you can. These features are completely orthogonal. $\endgroup$ – Jake Apr 26 '16 at 15:49

This is certainly possible, and there are two possibilities:

  1. There are two compilers for a language. For example, Haskell has GHC, and GHCJS, which is a JavaScript cross-compiler. GHC is written in Haskell, and GHCJS is written in Haskell (and normally compiled with GHC), so GHCJS is a self-hosted cross-compiler.

  2. You run your self-hosted cross-compiler in a target language. So, if you had a Foo to Python cross-compiler, and it's the only compiler for Foo, and it's written in Foo, it can be self hosting, but you would have to cross-compile it, then run the result in a Python interpreter.

Basically, be careful that you don't confuse a language with a compiler. A language can have many compilers.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.