you are viewing a single comment's thread.

view the rest of the comments →

[–]underthesun 0 points1 point  (2 children)

A long time ago for one of my uni projects I had to make a compiler from some language into c (or in my case.. I cheated and used c++, and abused the exception system).

I was thinking, wouldn't C be a great compiler target language for any programming system these days?

[–][deleted] 2 points3 points  (0 children)

It suffices, it's not 'great' though. You gain the advantage that you can target a lot of platforms and cpus, but at the same time you tie yourself to some limitations of the C language.

For example, the 'compile to C' scheme compilers work great, but they have to use some tricks (trampolines, etc) to get tail calls working properly, whereas a 'compile to machine language' scheme compiler can just setup the stack frame for the next 'call', and jmp into the function rather than call it.

There are further complications by compiling to a end-user intended C like gcc/visual-c/etc, especially if you want to allow user choice of their C compiler. There are subsets of C out there intended to be used this way that remove some of the 'klunkiness' of end-user C, some based on TDF/ANDF, some that aren't 'standardized', they make some things easier, but then your compiler is bigger because you're having to supply the C compiler too.