Вопрос:

How is a compiler related to the runtime system?

compiler-construction runtime

63 просмотра

2 ответа

4460 Репутация автора

A quick search on the role of compiler brings up the following:

A compiler is a special program that processes statements written in a particular programming language and turns them into machine language or "code" that a computer's processor uses.

However, I also read that every language needs to have a target runtime system and programs written in that language execute in the context of the runtime system.

Adding up the two, it appears that a compiler converts programs into bits understandable by the runtime system and the runtime system acts as the agent interpreting the bits, translating them to the processor intructions. Is this correct? If not, how else are compiler and runtime system related?

And if the above is correct, it would imply the following:

  1. two executables compiled from programs with identical logic written in different languages would not be identical
  2. an average machine would have dozens of runtimes which doesn't seem to be the case.

What am I missing here?

Автор: Aadith Ramia Источник Размещён: 08.11.2017 10:17

Ответы (2)


0 плюса

4701 Репутация автора

The runtime is a set of libraries (for a specific language) already compiled to run on the machine (real or virtual). It doesn't do any interpretation, it is just there to be used if needed.

The compiler will translate the source code into machine code that will also run on the machine, and that may call functions or procedures defined in the already existing runtime.

two executables compiled from programs with identical logic written in different languages would not be identical

Most likely.

an average machine would have dozens of runtimes which doesn't seem to be the case.

It could have dozens if the programmer uses dozens of different languages. But I don't think it is the common case.

Автор: Juan Размещён: 08.11.2017 10:37

0 плюса

16143 Репутация автора

It sounds like you are suffering from a confusing book.

Here you have hit an ambiguity.

However, I also read that every language needs to have a target runtime system and programs written in that language execute in the context of the runtime system.

[Rhetorical question] What is a "runtime system?" Is that the underlying hardware/operating system combination? Is it some runtime support for the specific language?

Adding up the two, it appears that a compiler converts programs into bits understandable by the runtime system and the runtime system acts as the agent interpreting the bits, translating them to the processor intructions. Is this correct? If not, how else are compiler and runtime system related?

Again that depends upon what "runtime system" means. All programs require calls to the operating system (even if they are behind the scenes from the programmer).

Some programming languages require a much greater support and have libraries that are essentially drive the program. However, these are function calls, not bit interpretation.

And if the above is correct, it would imply the following: two executables compiled from programs with identical logic written in different languages would not be identical

That is almost always if not always the case.

an average machine would have dozens of runtimes which doesn't seem to be the case.

That depends upon what you mean by "runtime." If it is a library of support functions for a specific programming language, then YES. If you mean something that interprets bits, then NO.

Автор: user3344003 Размещён: 09.11.2017 02:37
Вопросы из категории :
32x32