How unight0/xt works
Purpose and Entry Point
XT is a minimal interactive FORTH interpreter written in C. The build produces an xt executable (via Makefile); runtime input is interpreted directly, optionally preloading a FORTH source file such as basis.f.
Core startup and interpreter control are centered in:
• xt.c
• input.c
• input.h
Execution Model
The interpreter implements a classic stack-language loop: read source/input, tokenize it, resolve words in a dictionary, then execute primitive C implementations or compiled/interpreted FORTH definitions. The primary control boundary is between host-side C runtime code and user-visible FORTH words.
Relevant components:
• xt.c
• lexer.c
• token.h
Lexing and Input Sources
Input handling supports interactive input and source-file loading. The lexer converts character streams into FORTH tokens consumed by the interpreter/compiler path; this separates raw file/terminal input from language semantics.
Primary paths:
• input.c
• input.h
• lexer.c
• lexer.h
Dictionary and Word Resolution
The dictionary is the language’s central symbol table for named FORTH words. It supports lookup and likely definition/registration of both builtins and words loaded from FORTH files. This is the key extension boundary: basis.f can add standard-language behavior without changing the C executable.
Primary paths:
• dict.c
• dict.h
• defs.h
Runtime Stacks and Memory
FORTH execution state is stack-oriented. Stack operations are isolated behind a dedicated module, while shared runtime memory/layout declarations are collected separately. These components underpin data passing, return/control behavior, and compiled-word execution.
Primary paths:
• stack.c
• stack.h
• memory.h
Builtin Primitive Layer
C-defined builtins provide the interpreter’s fundamental operations and bridge language words to host execution. They are declared separately from their implementation and registered into the dictionary during runtime initialization.
Primary paths:
• builtins.c
• builtins.h
• dict.h
Standard Library and User Programs
basis.f is the standard FORTH library and is normally passed at startup to make the minimal core usable. Additional programs are loaded through FORTH-level inclusion, demonstrated by the example sources. These files execute within the same dictionary/stack runtime rather than through a separate application or service layer.
Primary paths:
• basis.f
• examples/quine.f
• examples/list.f
Infrastructure and External Dependencies
The repository is a native C program built with make; no web runtime, database, cloud infrastructure, or external service integration is indicated. Runtime interaction is local terminal/file I/O.
Primary path:
• Makefile
Main entry points: input.c Input sources · xt.c Startup & control loop · dict.c Dictionary · lexer.c Lexer
Components 19
C runtime
Native interpreter modules.
- Make build · Builds the native executable.
Makefile - xt executable
- Startup & control loop · Initializes runtime and drives read-token-execute.
xt.c - Input sources · Reads interactive input and preload files.
input.c - Input API
input.h - Lexer · Converts character streams into FORTH tokens.
lexer.c - Lexer API
lexer.h - Token model
token.h - Dictionary · Resolves and registers named FORTH words.
dict.c - Dictionary API
dict.h - Runtime definitions
defs.h - C primitives · Host implementations of fundamental FORTH operations.
builtins.c - Builtin API
builtins.h - Runtime stacks · Provides stack-oriented data and control state.
stack.c - Stack API
stack.h - Memory layout
memory.h
FORTH sources
Library and programs loaded by the interpreter.
- Standard library · Normally preloaded to extend the minimal core.
basis.f - Quine example
examples/quine.f - List example
examples/list.f
Connections 20
- Make build → xt executable: builds
- xt executable → Startup & control loop: starts
- Startup & control loop → Input sources: reads
- Input sources → Input API: implements
- Input sources → Lexer: character stream
- Lexer → Lexer API: implements
- Lexer → Token model: emits
- Startup & control loop → Dictionary: resolves words
- Dictionary → Dictionary API: implements
- Dictionary → Runtime definitions: uses
- C primitives → Builtin API: implements
- C primitives → Dictionary: registers primitives
- Startup & control loop → C primitives: initializes
- Startup & control loop → Runtime stacks: executes with
- Runtime stacks → Stack API: implements
- Runtime stacks → Memory layout: uses
- Standard library → Input sources: preloaded as source
- Standard library → Dictionary: defines words
- Quine example → Input sources: loaded as source
- List example → Input sources: loaded as source