As pointed out by others, not every language is translated into machine language; some are translated in some form (bytecode, reverse polish, AST), which is interpreted.
But even among languages translated into machine code,
- Some translators are better than others
- Some language features are easier to translate to high-performance code than others.
An example of a translator that is better than others is the GCC C compiler. For example, it has many years of work in creating good code and its translations are superior, for example, to the simpler tcc and tcc .
An example of a function that is difficult to translate to high-performance code is the ability of C to perform pointer arithmetic and dereference pointers: when a program is stored through a pointer, it is very difficult for the compiler to find out which memory locations are affected. Similarly, when an unknown function is called, the compiler must make very pessimistic assumptions about what might happen to the contents of objects allocated on the heap. In a language such as Java, the compiler can perform translation better because the type system provides greater separation between pointers of different types. In a language such as ML or Haskell, the compiler can do better, because in these languages most of the data allocated in memory cannot be changed by calling a function. But of course, object-oriented languages and functional languages present their own translation problems.
Finally, translating the Turing language itself is a difficult problem: in general, finding the best translation for a program is an NP-difficult problem , which means that the only solutions known to potentially take time exponentially in program size. This would be unacceptable in the compiler (cannot wait forever to compile several thousand lines), so compilers use heuristics. There is always room for improvement in these heuristics.
Norman ramsey
source share