ARCHITECTURE & ENGINE INTERNALS
Deyin is designed around a single Abstract Syntax Tree (AST) that serves both an interactive bytecode interpreter and an optimizing ahead-of-time compiler.
1. PARSER & AST PIPELINE (`src/parser.py`, `src/ast.py`)
The parser converts streaming pipeline source into typed AST nodes (Pipeline, FilterStep, MapStep, WindowStep, SinkStep, BinOp, FuncCall, Ident, Lit) using Lark LALR grammar with position propagation for precise diagnostic mapping.
2. STATIC SEMANTIC CHECKER (`src/check.py`)
Before execution, a compile-time static analysis pass validates known field schemas with "did you mean?" fuzzy matching suggestions, verifies sink/source legality, enforces boolean filter roots to prevent invalid WASM emissions, and checks window sizing bounds.
3. TREE-WALK VISITOR INTERPRETER (`src/interpreter.py`)
The interactive runtime executes via an AST Visitor pattern without any string evaluation or eval(). Sliding deque buffers compute rolling mathematical indicators (Wilder's RSI, stateful recursive EMA, and SMA) strictly in causal arrival order without look-ahead bias.
4. OPTIMIZING COMPILER (`src/compiler.py`)
The Ahead-Of-Time compiler performs Dead Code Elimination (DCE), lazy itertools.islice ingestion, conditional variable hoisting, and emits zero-eval Python or valid WebAssembly Text (WAT) kernels.