Hacker News new | ask | show | jobs
by castis 3347 days ago
But isn't that what this is? I was under the impression that a compiler turns source code into machine code whereas a transpiler turns source code into differnet source code?
2 comments

I would suggest reading the first couple of pages of any compiler book. e.g. https://books.google.com/books?id=_tgh4bgQ6PAC&printsec=fron...

Compilers are computer programs that translate a program written in one language into a program written in another language.

Example of a compiler in action.

  $ cat hello.c
  #include <stdio.h>
   
  int main(void)
  {
          printf("hello world\n");
   
          return 42;
  }

  $ cc -O3 -S hello.c -o -
          .section	__TEXT,__text,regular,pure_instructions
          .macosx_version_min 10, 12
          .globl	_main
          .align	4, 0x90
  _main:                                  ## @main
          .cfi_startproc
  ## BB#0:
          pushq	%rbp
  Ltmp0:
          .cfi_def_cfa_offset 16
  Ltmp1:
          .cfi_offset %rbp, -16
          movq	%rsp, %rbp
  Ltmp2:
          .cfi_def_cfa_register %rbp
          leaq	L_str(%rip), %rdi
          callq	_puts
          movl	$42, %eax
          popq	%rbp
          retq
          .cfi_endproc
   
          .section	__TEXT,__cstring,cstring_literals
  L_str:                                  ## @str
          .asciz	"hello world"
   
   
  .subsections_via_symbols
All compilers turn one form of code into another. Whether that's C to assembly (to machine code), or JavaScript to bytecode to machine code, or Python to Python. Transpiler is just a term referring to a compiler taking one high-level language to another. It's unnecessary because a Coffeescript to JavaScript compiler is a transpiler already; saying "transpiler" there tells you nothing you don't already know.
The phrase "an A to B compiler" might not gain anything from changing compiler to transpiler, but the phrase "an A compiler" does.