Modules

The MotorScript compiler is split up into many different and independent modules. Since the compiler is written in Kotlin, and therefore targets the JVM platform, we can make use of the Java Modules system (introduced with Java 9). That is exactly what all the compiler modules are: each compiler module is its own separate Java module.

Compiler steps are roughly equivalent to these modules, in the way that each compiler step is located in one module, but not necessarily the other way around.

See the other pages in the menu for in-depth explanations of each step.

Currently, the following steps exist (with a brief description):

Flow

The following structure globally indicates how the different steps are executed in the process of compiling a project.

  1. cli is called with CLI arguments, by means of executing the compiler executable.
  2. cli parses the CLI arguments and tries to load the build configuration from the specified source directory.
  3. buildmgr is called by cli with the build configuration just loaded.
  4. discover is called by buildmgr, in order to discover all source files and resolve dependencies.
  5. lexparse is called by buildmgr with the result from the discover step, it will transform all sources into parse trees. It will also report any syntax errors that may be present. All of this is mostly off-loaded to the lexer and parser generated by ANTLRv4.
  6. front is called by buildmgr to transform all parse trees into IR.
  7. If everything is still OK at this point in time, buildmgr will perform the following steps for each target:
    1. check is called to resolve all references and perform type-checking.
    2. (?) transform is called to let all built-in constructs be transformed into IR.
    3. gen is called to generate the final build artifacts (generally a data pack).