Skip to content

Compilation Model and Output

Overview

The compilation model describes how Larol source files are transformed into artifacts. Each source file constitutes a single compilation unit and MUST be compiled independently.

Rules

Compilation Phases

The compiler MUST perform the following logical phases for each compilation unit. The order in which these phases are implemented is implementation-defined.

In the Resolution phase, all import and include directives MUST be resolved to build a complete dependency graph for the compilation unit. In the Validation phase, type checking, ownership analysis, and naming collision checks MUST be performed across the compilation unit and all resolved dependencies. In the Codegen phase, the compiler MUST generate an object file containing machine code for all symbols in the compilation unit. The object file format is implementation-defined. In the Metadata phase, the compiler MUST generate a metadata file containing declarations for all exported symbols. The metadata file MUST be generated even if no symbols are exported. The metadata file format and extension are implementation-defined.

Linker Interaction

The compiler MAY perform the final linking stage; the implementation MAY delegate this to a separate build tool or linker.

Exported Symbols

The export qualifier MUST be supported for function declarations, struct declarations, intdef declarations, and typedef declarations. Member functions MUST only be exported if they are explicitly marked with the export qualifier. A member function MUST NOT be permitted to be exported if its enclosing struct is not also exported.

Runtime Functions

The following functions MUST be provided by the runtime implementation and MUST be available to compiled code without explicit declaration:

  • larol_alloc(region, size, align) MUST allocate memory for a struct in the given region and MUST produce a struct handle.
  • larol_alloc_slice(region, element_size, element_align, count) MUST allocate memory for a slice in the given region and MUST produce a slice handle.
  • larol_region_create() MUST create a new memory region and MUST return a region handle.
  • larol_region_destroy(region) MUST destroy a region and MUST free all allocations within it.
  • larol_panic(error_code) MUST exit the program after a fatal error.

The exact calling conventions and signatures are implementation-defined. The runtime MAY provide additional functions not specified here.