Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Tools

The compiler, the build and the editor support are snail-scheme libraries too, which bootstrap/cli.sld, the snail-scheme command line, puts together (development toolchain).

(snail shell compiler)

The compiler’s passes in order, from a program’s source path to WebAssembly text: source->checked reads, expands and checks a program, and checked->wat specializes, prepares and emits it; source->wat does both. Every invocation reads, checks and emits the whole program afresh. Chez runs this source as stage 0, and Node runs it compiled to WebAssembly, so it imports only (snail core base), (snail core table) and (snail core io) and avoids what the two hosts would disagree on, such as integer overflow and the order of a table’s keys (compiler architecture).

Its passes and supporting modules, each (snail shell compiler NAME):

ModuleDoes
readText to located syntax, by recursive descent; its lexical rules are exported for highlighting; how any pass stops a compile with a diagnostic
libraryWhere a library’s file is, and what it declares before it is expanded: a define-library, or a generate-library’s producer
inputsThe requests a compile makes for what it was not given, such as a producer’s output
expandLocated syntax to the core program: libraries loaded, every identifier resolved, macros run, entities recorded
coreThe core language every pass after expansion shares: types, expressions and the program’s tables
checkHindley-Milner checking with typeclass evidence, each expression rebuilt with its type
specializeEach definition reached copied once for each set of types it is used at
prepareFixed declarations and normalized items, with what each call may suspend to
wasmPrepared code to WasmGC: representations, closures, tail calls and the frames a suspension saves
driverOne invocation, shared by stage 0’s entry and the command line’s compile
sha256The digest linked files are named by (text and data)

The compiler tour follows a program through them.

Source

(snail shell assembler)

assemble, WebAssembly text to a binary module, and link, static linking of modules into one, in-process. Only a tool linked with the toolchain’s runtime can use it: the plain runtime leaves the text parser out, so a program that imports this library links with the toolchain’s instead (assembly and linking).

Source

(snail shell project build)

A script’s build, which snail-scheme build and run run: build-script compiles, links and packages a script into a generation of its own, then publishes it by replacing the script’s link in its workspace’s build/ at once. A compile that reaches a generated library runs its producer first, then compiles again. A build that fails removes every generation it made, and only those, so earlier outputs stay published. check-script and check-library compile as a build does and write nothing, for the language server. A build’s Mode is Debug or Release, which also optimizes the module with wasm-opt; its Platform is Node or Browser (workspaces and builds).

Source

(snail shell project web-app)

A browser build’s installable web-app manifest and the page’s links to it: web-app-manifest is the default manifest, and with-web-app inserts into a page the manifest’s link and the name of the program’s module, keeping the rest of the page byte for byte. A project’s own public/manifest.webmanifest replaces the default whole (browser packaging).

Source

(snail shell lsp)

serve-language, snail-scheme lsp: the Language Server Protocol over standard input and output for one workspace, the folder an editor opened. It checks each open document in this process, as a build would, whenever the editor opens or saves it, and answers diagnostics, hover (a name’s type where it is used), definitions, formatting and semantic colors. A check reads the disk, so it reports what was saved. Zed and VS Code start it through editors/ (the language server).

Source

(snail shell format)

The repository’s formatter, which scripts/format-scheme and the language server share: format-source puts each import specification and field on its own line, indents every line under its call’s first argument or two in for a special form’s body, and breaks a line whose code runs past format-width (100 columns), never joining lines. make check holds every tracked Scheme file to it (the formatter).

Source

(snail shell highlight)

highlight-tokens, source text as tokens that tile it, each of a Class for coloring, by the compiler reader’s own lexical rules, adding only the comments and whitespace a reader discards. Text the reader would reject still classifies. The book’s code blocks, the language server’s semantic tokens and the range it marks for a diagnostic all come from it (code highlighting).

Source