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 CLI
buildmgr: Manages the entire build process
discover: Source file discovery, dependency discovery
lexparse: Contains ANTLRv4 generated parser, responsible for lexing and parsing source file
front: Font-end, IR generation
check: Type checking and resolving
transform: (?) Transformation of built-in functions into IR
gen: Back-end, generates e.g.
.mcfunctionfiles and data packs
The following structure globally indicates how the different steps are executed in the process of compiling a project.
cliis called with CLI arguments, by means of executing the compiler executable.
cliparses the CLI arguments and tries to load the build configuration from the specified source directory.
buildmgris called by
cliwith the build configuration just loaded.
discoveris called by
buildmgr, in order to discover all source files and resolve dependencies.
lexparseis called by
buildmgrwith the result from the
discoverstep, 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.
frontis called by
buildmgrto transform all parse trees into IR.
- If everything is still OK at this point in time,
buildmgrwill perform the following steps for each target:
checkis called to resolve all references and perform type-checking.
transformis called to let all built-in constructs be transformed into IR.
genis called to generate the final build artifacts (generally a data pack).