Runtime Organization

A compiler contains many phases:

  1. Front-end phases: Lexical analysis, parsing, semantic analysis.
  2. Back-end phases: Code generation, optimization.
  3. The resultant object files are linked against external libraries, creating a final executable.

After the compiler has done its job, the program is executed by the runtime system.A loader loads the program into memory, creating a program address space. This contains the code, stack and data segment. Next, the loader will pass control to the program's entry point.

1. Variables

There are many different types of variables:

2. Objects

To access data fields on objects, we can use an address offset. To call a method, we pass the object reference as a hidden parameter. On Intel IA-32:

1mov eax, <b> ; Load contents of b into eax 2push eax ; Push object ref as a hidden inner parameter 3mov eax, [eax] ; Load address of method lookup table into `eax` 4call [eax + 4] ; Call the method at offset 4

For inheritance and overriding, a new method lookup table is created, with a pointer to the parent's method lookup table. This allows for dynamic dispatch.

Dynamic binding also can be done, by copying an object's reference.

3. Variable Scope

Back to Home