Hacker News new | ask | show | jobs
by PeCaN 3596 days ago
I agree with munificent. ‘Transpiler’ implies very similar semantics between the source and target language; ‘compiler’ implies fairly different semantics (where a translation between the source and target is not obvious).
2 comments

Some people treat C as portable assembly.

Does that make gcc a transpiler for converting portable assembly to platform-specific assembly due to their similar semantics?

I knew someone would bring this up.¹

GCC is an optimizing compiler, at which point all bets are off for obvious/trivial translation between C and asm. You could, hypothetically, write a optimizing TypeScript compiler that emits asm.js.

However, while you can reasonably argue C started as a portable assembly, significant differences like a type system, pointer arithmetic, a calling convention, etc, exist now. I don't think it's unreasonable to say C is significantly higher-level than assembly.

1. My parenthetical at the end was anticipating this—then again, the translation between C and asm frequently is easy, albeit tedious.

I guess you could replace gcc with a dumb compiler / turn off optimizations. And throw in compiler intrinsics while we're at it, after all people write hot loops with them. And pointer arithmetics actually translate nicely to all those fancy addressing modes you find on x86.

And in the other direction one could argue that those so-called "transpilers" actually compile from a higher-level language when you consider complex type-inference and static type checking. Optimizing is not all a compiler does.

I don't buy this definition at all.

First, the "semantics" had better not change, either by an optimizing or non-optimizing compiler, or you've got a miscompile.

Second, I've seen several source-to-source compilers (that the proponents of the term transpiler would certainly call transpilers) that do non-trivial transformation, e.g. to try to capture certain idioms, or that are required as a result of an "impedance mismatch" between the languages.