Package org.ek9lang.compiler


package org.ek9lang.compiler
B - For the EK9 compiler itself.

The Compiler interface is the abstract concept and Ek9Compiler is the concrete actual implementation. The Workspace contains the list of sources to be compiled. Compilation is done in a number of 'phases'.

When creating an instance of the Ek9Compiler, the constructor accepts a supplier of 'phases'. The reason for this is to enable the same compiler and some parts of the compilation process to be used in a 'language server'. So when the compiler is employed it can be used via the command line (org.ek9lang.cli to do full and complete compilations, but also be used via something like 'VSCode' in an org.ek9lang.lsp.

The 'LSP' (org.ek9lang.lsp) only really does the 'front/middle' end of compilation from org.ek9lang.compiler.config. Whereas the 'CLI' (org.ek9lang.cli uses all of the phases from org.ek9lang.compiler.config.

Boot strapping the compiler is done via Ek9LanguageBootStrap and Ek9BuiltinLangSupplier. Strangely the Ek9LanguageBootStrap uses an 'empty' Ek9Compiler with just the FrontEndSupplier phases to parse and populate a CompilableProgram with all the basic types and standard library types/functions ready for the developers code to be compiled. All the ek9 types are built in as text inside Ek9BuiltinLangSupplier. The module is marked as 'extern'. Other ek9 developers ek9 source can also employ 'extern' as there is a 'linking' phase that resolves the declared constructs later. For the EK9 compiler, the built-in 'extern' constructs are shipped with the compiler.

Once the bootstrapping process has taken place, the CompilableProgram will have all the EK9 constructs in memory. Now a FullPhaseSupplier can be used with a new instance of the Ek9Compiler (not the one used in boot strapping). So really the EK9 Compiler itself is quite dumb and just consists of a for loop, calling each 'phase' with the Workspace and CompilerFlags. The phases are created and given access to the CompilableProgram, so that during the processing of that phase it is possible to resolve symbols and also add in a new ParsedModule to a set of ParsedModules.

The CompilableProgram just keeps the sets of ParsedModules in a map, it then just coordinates the resolution of symbols in those ParsedModules.

Really the only activity the Ek9Compiler does is trigger each phase in turn with the Workspace and check the CompilationPhaseResult from that phase. If that phase fails then the compiler stops and returns 'false' i.e. failed to compile the EK9 source files. During the processing of each phase a listener of CompilationEvent and a CompilerReporter are provided for each phase. It is this mechanism that enables the EK9 developer 'issues' to be issued and reported.

The main critical functionality is all in the phases. See those packages for details of what each specific phase is attempting to accomplish. Each phase can is numbered, but can have multiple passes within that phase.