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):
cli
: Command Line Interface interface, handles all things related to CLIbuildmgr
: Manages the entire build processdiscover
: Source file discovery, dependency discoverylexparse
: Contains ANTLRv4 generated parser, responsible for lexing and parsing source filefront
: Font-end, IR generationcheck
: Type checking and resolvingtransform
: (?) Transformation of built-in functions into IRgen
: Back-end, generates e.g..mcfunction
files and data packs
Flow
The following structure globally indicates how the different steps are executed in the process of compiling a project.
cli
is called with CLI arguments, by means of executing the compiler executable.cli
parses the CLI arguments and tries to load the build configuration from the specified source directory.buildmgr
is called bycli
with the build configuration just loaded.discover
is called bybuildmgr
, in order to discover all source files and resolve dependencies.lexparse
is called bybuildmgr
with the result from thediscover
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.front
is called bybuildmgr
to transform all parse trees into IR.- If everything is still OK at this point in time,
buildmgr
will perform the following steps for each target:check
is called to resolve all references and perform type-checking.- (?)
transform
is called to let all built-in constructs be transformed into IR. gen
is called to generate the final build artifacts (generally a data pack).