0
$\begingroup$

As an amateur Bash/JavaScript scripter who never wrote one sentence in Assembly, I ask:

Do compilers of high programming languages always compile them directly to machine code, or are there cases when a compiler of some high programming language compiles it to assembly (and then assembler will assemble input to machine code output)?

$\endgroup$
2
  • $\begingroup$ Are you aware how languages like Java and C# are executed? Anyway, I think this is offtopic here. Community votes, please? $\endgroup$
    – Raphael
    Commented Nov 7, 2019 at 6:58
  • $\begingroup$ @Raphael I almost never learned about these languages. Thank you for the comment, $\endgroup$
    – user109446
    Commented Nov 7, 2019 at 8:29

2 Answers 2

4
$\begingroup$

I've seen compilers that compile directly to object code.

I've seen compilers that compile to assembler code.

I've seen compilers that compile to byte code for a virtual machine.

I've seen compilers that compile to bit code which is intended to be further compiled to code for slightly different processors.

I've seen compilers that compile to a different language.

I've seen compilers for Javascript specifically that start interpreting code, then compile it very quickly to not very good code, then compile it carefully to reasonably good code, then compile it with a highly optimising compiler to very fast code, all depending how often some code is executed.

$\endgroup$
0
$\begingroup$

One popular way to get a language quickly off the ground is to compile to a high-level language, like C. It gives you portability for free, and you can leverage the extensive optimization of the C compiler to get good object code.

An interesting artifact from the early Unix times is RATFOR, a preprocessor for a somewhat-C-like language to FORTRAN (a prehistoric dialect with no decent control structures). There is a f2c compiler for FORTRAN 77 to C.

Most "scripting" languages compile to a virtual machine code, which is interpreted. Some (e.g. modern Java virtual machines) translate often used stretches of code to machine code on the fly (Just In Time compilation, JIT).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.