Title: The Inform 7 compiler Author: Graham Nelson @ The task of Inform to take natural-language source text, merged from the author's main source and some "extensions"; to compile that to an intermediate format called Inter; merge once again with pre-compiled libraries of Inter called "kits"; and then translate the result to a program which a more orthodox compiler can take the rest of the way. Because Inform 7 generates code for another compiler, rather than directly making an executable itself, it is properly speaking a "transpiler". For two decades that second compiler was always the roughly C-like Inform 6, a sturdy 1990s tool for generating interactive fiction "story files" which, after processing with the //inblorb// tool, can then be played in a web browser or with an "interpreter". In 2021, limited support was added for transpiling a general, non-IF-specific form of the language called Basic Inform to ANSI C. This can be compiled into more general executable programs using Clang, gcc, or other standard C compilers. = (hyperlinked text as BoxArt) main source text extension source texts \ / \ / INFORM7 Stage 1 or INBUILD \ / \|/ \|/ syntax tree kit sources | (in Inform 6 code) | INFORM7 Stages 2 to 5 INTER | | \|/ \|/ precompiled Inter trees Inter tree \ / \ / INFORM7 Stage 6 or INTER \|/ \|/ single linked Inter tree / | \ / | \ INFORM7 Stage 7 or INTER \|/ \|/ \|/ Inform 6 code C code index mini-website | | INFORM6 | | CLANG or GCC \|/ \|/ story file executable | INBLORB | \|/ playable website = @ The Inform 7 transpiler, then, occupies the top two-thirds of the above diagram. Broadly speaking, it runs in seven stages, and the code for each stage is made up of one or more "modules", as follows: (*) Stage 1. A build manager called //supervisor// gathers what must be compiled. (*) Stage 2. //core// organises compilation of a single Inform project, doing little except to co-ordinate the other modules. (*) Stage 3. //assertions//, //values// and //knowledge// assemble a world model, turning sentences first into logical propositions and then into inferred facts, and also gather a set of rules and phrases to operate it. //if// and //multimedia// provide "plugins" to this process with additional features, adapting the language for interactive fiction. (*) Stage 4. //imperative// and //runtime// turn the constructs from Stage 3 into an intermediate bytecode format called Inter. (*) Stage 5. //bytecode// and //building// manage and create Inter code. This is more of a layer than a stage, providing services to Stages 4, 6 and 7. (*) Stage 6. //pipeline// links and optimises this Inter code. (*) Stage 7. //final// generates final code and //index// generates human-readable Index pages, which forn a small website about the project. Inform 7 presents as three command-line tools, not one: //inbuild//, //inform7// and //inter//. Really, though, they are three points of access to the same code base. //inbuild// contains Stage 1 as a stand-alone tool, //inter// contains Stages 5 to 7 as a stand-alone tool, and //inform7// is the entire compiler (Stages 1 to 7) in one. Each tool has its own CLI (or "command-line interface"): see //inbuild: Manual//, //inform7: Manual//, //inter: Manual// and //inbuild: Reference Card//, //inform7: Reference Card//, //inter: Reference Card//. The full breakdown of these three tools into modules is as follows: = (hyperlinked text as BoxArt) INBUILD INFORM7 INTER +-------------+ +-------------+ +-------------+ | //inbuild// | | //inform7// | | //inter// | | (cli) | | (cli) | | (cli) | +-------------+ +-------------+ +-------------+ . . . . . . +---------------------------+ . . . . | //supervisor//-module | . . . . } Stage 1 +------------------------+ +------------------+ . . . . | //core//-module | . . } Stage 2 . . | ------------------- | . . . . | //assertions//-module | . . } . . | //values//-module | . . } Stage 3 . . | //knowledge//-module | . . } . . | //if//-module* | . . } * not used in . . | //multimedia//-module* | . . } Basic Inform . . | ------------------- | . . . . | //imperative//-module | . . } Stage 4 . . | //runtime//-module | . . } . . +------------------+ +------------------------+ . . . . | //bytecode//-module | } . . . . | //building//-module | } Stage 5 . . . . | ------------------------- | . . . . | //pipeline//-module | } Stage 6 . . . . | ------------------------- | . . . . | //final//-module | } Stage 7 . . . . | //index//-module | } . . . . +---------------------------+ . . . . . . +-----------------------------------------------------------------------+ | SERVICES shared //linguistics//-module | | shared //calculus//-module | | shared //kinds//-module | | shared //lexicon//-module | | shared //inflections//-module | | shared //problems//-module | | shared //syntax//-module | | shared //words//-module | | shared //arch//-module | | shared //html//-module | +-----------------------------------------------------------------------+ . . . . . . +-----------------------------------------------------------------------+ | FOUNDATION //foundation//-module (in inweb repository) | | (Posix or Windows-related functions) | | (standard C library) | +-----------------------------------------------------------------------+ = Note that all three tools use a "services" library, made up of a variety of modules providing services useful for natural language-based programs. At one time this was going to be called "Second Foundation" or possibly "Foundation and Empire", because there is also //foundation// underneath, a library of utility functions provided by //inweb//. @ That's a lot: for code-spelunkers, this is quite the limestone hillside of potential points of entry. Where to begin? Here are some suggested entrances: (a) See //supervisor: What This Module Does// for an overview of the build-management process. (b) Or take that on trust, and see //core: What This Module Does// for an overview of how Inform 7 basically works. (c) If you're more interested in the low-level representation of Inter code, and how to generate from it, see //bytecode: What This Module Does//.