How dplassgit/smallest works
Purpose and Deliverables
Smallest is a self-hosted compiler for SPL, a deliberately minimal language with 32-bit integers and integer arrays. The repository contains both a Scala implementation used to compile SPL and SPL/assembly artifacts representing the bootstrap and self-hosted compiler stages. Primary artifacts are source programs in samples/, generated/handwritten assembly in src/, and the Scala compiler implementation in scala/src/main/scala/.
Compiler Entrypoints
The Scala compiler’s executable entry point is scala/src/main/scala/Smallestc.scala. It drives the front end and likely emits the target assembly format consumed by the project runtime/toolchain. Shell wrappers provide operational entry points:
• scripts/compile
• scripts/run
• scripts/bootc
scala/build.sbt defines the Scala build, while scala/README.md is the local usage reference for this compiler implementation.
Front-End: Lexing and Tokens
Source text is converted into the compact single-character-keyword language token stream by:
• scala/src/main/scala/Lexer.scala
• scala/src/main/scala/Token.scala
This boundary enforces SPL’s lexical restrictions: alphabetic identifiers, integer/character literals, operators, comments, and punctuation-based control/function constructs. Tokens are the interface between raw SPL input and syntax analysis.
Parsing and Language Structure
scala/src/main/scala/Parser.scala transforms tokens into the compiler’s syntax representation and establishes SPL control flow and expression semantics: assignments, array allocation/indexing, function declarations/calls, conditionals, loops, return, input/output, and termination. It is the semantic shape boundary before symbol resolution and code generation.
Representative inputs exercising this stage are under samples/, including:
• samples/fact.spl
• samples/arrayassign.spl
• samples/proccall.spl
Symbol and Type-Conventions Layer
scala/src/main/scala/SymTab.scala manages identifiers and compiler-visible scope/state. SPL relies on naming conventions rather than explicit type declarations: names beginning with a denote arrays, and function names distinguish void/array/int returns by prefix. This component is therefore central to resolving globals, locals, parameters, functions, and storage/code-generation decisions.
Bootstrap and Self-Hosting Chain
The repository preserves compiler evolution as SPL and assembly artifacts:
• src/bootstrap.spl
• src/bootstrap.asm
• src/selfhosted.asm
bootstrap.spl is SPL source for an early compiler stage; bootstrap.asm is its target assembly output or bootstrap-ready representation; selfhosted.asm is the resulting self-hosted compiler artifact. scripts/bootc is the operational boundary for this bootstrap chain. This enables the compiler to eventually compile its own SPL implementation rather than depending solely on Scala.
Runtime and Execution Boundary
The project targets an assembly-level runtime/emulator workflow rather than a web or service deployment. scripts/run encapsulates execution of compiled artifacts, and scripts/compile connects SPL inputs to compiler output. No external cloud services, databases, or network APIs are indicated; material dependencies are the Scala/SBT runtime for the host compiler and the assembly execution environment implied by the scripts and .asm artifacts.
Main entry points: Smallestc.scala Smallestc · bootc bootc · Lexer.scala Lexer · bootstrap.asm Bootstrap assembly
Components 15
Scala host compiler
- Smallestc · Drives the Scala SPL compilation pipeline.
scala/src/main/scala/Smallestc.scala - Lexer
scala/src/main/scala/Lexer.scala - Tokens · Interface between source text and parsing.
scala/src/main/scala/Token.scala - Parser · Builds SPL syntax and control-flow/expression semantics.
scala/src/main/scala/Parser.scala - SymTab · Applies SPL naming conventions for scope, storage, and return kinds.
scala/src/main/scala/SymTab.scala - SBT build
scala/build.sbt - Compiler usage
scala/README.md
Bootstrap chain
- Bootstrap compiler · Early compiler implementation written in SPL.
src/bootstrap.spl - Bootstrap assembly
src/bootstrap.asm - Self-hosted compiler · Assembly compiler artifact produced by the bootstrap chain.
src/selfhosted.asm - bootc · Operates the bootstrap and self-hosting chain.
scripts/bootc
Tooling and execution
Other components
- SPL programs · Representative SPL programs and compiler-stage source.
Connections 18
- SBT build → Smallestc: builds
- Compiler usage → Smallestc: documents
- compile → Smallestc: invokes
- SPL programs → Lexer: source text
- Smallestc → Lexer: drives
- Lexer → Tokens: emits
- Tokens → Parser: consumed by
- Parser → SymTab: resolves names
- SymTab → Assembly artifacts: guides code generation
- Smallestc → Assembly artifacts: emits
- compile → Assembly artifacts: produces
- run → Assembly artifacts: executes
- Bootstrap compiler → Bootstrap assembly: compiled to
- Bootstrap assembly → Self-hosted compiler: bootstraps
- bootc → Bootstrap compiler: operates
- bootc → Bootstrap assembly: operates
- bootc → Self-hosted compiler: produces
- Self-hosted compiler → Assembly artifacts: can compile SPL to