nitlang / nit

Nit language
http://nitlanguage.org
Apache License 2.0
238 stars 64 forks source link

separate_compiler: Refactored class compilation #2808

Closed Louis-Vincent closed 4 years ago

Louis-Vincent commented 4 years ago

Before

Before this update, the method compile_class_to_c handled every part of the class compilation process even special case (universal class). By doing so, we can't refined this method efficiently without reimplementing the entire method. This is a pain since each time we need to add universal class we have to modify the original code instead of refining the compiler.

After

The method compile_class_to_c has been divided in three main parts:

  1. the class's vft compilation (same for every type of class)
  2. the compilation of universal class specifics (change alot through time). This part must managed every part of a universal type, except its vft compilation which already handled by the 1st step.
  3. the compilation of the default NEW allocator (apply only for non-universal type).

Moreover, the state of a class compilation is stored in a new class called ClassCompilationInfo, which has different flag to specify if the class is dead/alive or need_corpse. This choice was made to prevent dataclump in each method involved with the class compilation.

With this new way of managing class compilation, we can add new universal class via refinement instead of code rewriting.

Signed-off-by: Louis-Vincent Boudreault lv.boudreault95@gmail.com