The source code sits in the samlang repository. The repository follows a monorepo setup, managed by Gradle multi-projects.
To produce a source set (defined by
sconfig.json) into an optimized compiled native program, the
samlang CLI performs following computation in order:
samlang-clicollects all sources specified by
sconfig.jsonand stores a mapping from
ModuleReferenceto source code in
samlang-core-parserparses the sources code into AST's. Each source file is parsed into a
Module. Then the in-memory representation becomes
Map<ModuleReference, Module>. At this point, the
fieldin each AST node is dummy.
samlang-core-checkertype checks the modules by a constraint-solving based type inference algorithm. After that, the in-memory representation is still
Map<ModuleReference, Module>, but each node in the AST is guaranteed to have a correct
samlang-core-compilergradually turns the source-level AST into LLVM AST. It first lowers the AST into a high-level IR. The high level IR can be translated into other high-level languages without much effort. Then it lowers the AST into LLVM IR that is similar to Appel's IR. In both stages,
samlang-core-optimizationwill perform various optimizations.
samlang-core-printerprints the LLVM AST into LLVM text files.
samlang-clithen shells out to
runtimefolder that links the assembly against the samlang runtime. Now you get a program that is directly runnable!