Package org.ek9lang.compiler
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.
-
ClassDescriptionRepresents the whole program(s) that the developer is attempting to create.Holds a reference to the name of the file being compiled a checksum of the file and the date time last modified.Populated in the compilable program and altered during each of the phases of compilation.Identifies the ordered set of compilation phases used in EK9.Effectively a tuple for returning if the phase was a match for the required compilation phase to be run to and if this phase ran ok.Conceptual compiler.Used to drive how the compiler operates.Marks the specific activity of a compiler phase.De-Serializes a byte array back to compilable program.Just loads the ek9 language builtin ek9 source code and supplies it as Compilable Source.The main EK9 compiler (HERE FOR COMPILER ENTRY).Loads the language basics into a Compilable Program.Defines a module scope, the main concept for namespaces in EK9.Once we have parsed a module (source file) we need to keep track of the results.With EK9 it is possible to have multiple source files that are all in the same 'module'.Used to hold just the transient data that will be used by listeners and visitors and SymbolsAndScopes.Mainly used in the CompilableProgram for resolving or defining a new Parameterized type.Serializes a compilable program to a byte array, so it can be saved/reused as required.Defines the concept of an EK9 source file.Designed to represent one or more source files that are part of a workspace.