wal
Types
| Name | Description |
|---|---|
| AgentError | A failure, in the shape the envelope carries it. |
| BigInt | @brief Arbitrary-precision integer, for the opt-in bigint mode. |
| CLI | @brief Command-line interface for WAL++ with argument parsing Handles: - Argument parsing - File execution - Expression evaluation - REPL startup - Help and version info |
| CSVTrace | @brief CSV (Comma-Separated Values) file format trace reader Reads and parses CSV waveform files. |
| EvalError | Evaluation failed - runtime error during expression evaluation Thrown by SEval when encountering: - Undefined variables (@ anchor: ast/eval_error/undefined) - Type errors (wrong types for operation) - Division by zero - Invalid function calls - Trace access failures Supports stack trace annotation via add_trace() for debugging. See : SEval::eval for evaluation context |
| FSTTrace | @brief FST (Fast Signal Trace) file format trace reader Reads and parses FST waveform files produced by simulators like Icarus Verilog, Verilator, and others. |
| LintFinding | One thing wrong with a script. |
| OperatorFunc | @defgroup operator_registry Operator Registry @brief Extensible operator registration and dispatch system The Operator Registry is the key to WAL++'s extensibility. |
| OperatorRegistry | Central registry for operator definitions Manages: - Registration of new operators - Lookup by name - Batch registration of operator categories - Dynamic operator injection (from Python) Used by SEval to dispatch function calls and special forms. Typically one registry per evaluator instance. See : SEval for usage context |
| ParseError | Parsing failed - S-expression syntax invalid Thrown by Parser when encountering: - Unmatched parentheses - Invalid number format - Unexpected end of input - Invalid string escapes See : Parser for parsing details |
| Parser | @defgroup parser Parser @brief S-expression parsing and tokenization The Parser converts WAL source text into an Abstract Syntax Tree (AST). |
| REPL | @brief Interactive Read-Eval-Print-Loop for WAL++ Provides a user-friendly interactive shell for WAL expressions with: - Command history and navigation - Multi-line expression support - Pretty-printed output - Built-in help system - Error recovery |
| SEval | @defgroup evaluator Evaluator & Execution Engine @brief S-expression evaluation and runtime state management The SEval class implements the core evaluation engine: @mermaid graph LR A["S-Expression"] --> B["Parse"] B --> C["SEval::eval"] C --> D{"Is it a list?"} D --> |
| SignalValueCache | @brief LRU Cache for signal values with statistics Caches recently accessed signal values to improve query performance without loading the entire file into memory. |
| SparseIndex | @brief Timestamp to file offset mapping for fast seeking Maintains a sparse index of (timestamp, file_offset) pairs to enable efficient random-access seeking in large trace files without loading all data into memory. |
| StreamingCSVTrace | Streaming CSV (Comma-Separated Values) file format reader Uses 4-layer architecture for terabyte-scale trace processing: Layer 1: Streaming I/O - StreamingChunkReader: C++20 coroutines, 100 MB chunks Layer 2: Indexing & Caching - SparseIndex: Timestamp → file offset mapping - SignalValueCache: LRU cache with adaptive sizing Layer 3: Format-Specific Reader - StreamingCSVTrace: Lazy CSV parsing - Support for time-based and signal-based formats - Hierarchical scope support - Format validation Layer 4: Public API - Trace base class interface - Transparent streaming to users Memory Model: - Fixed: StreamingChunkReader (100 MB) - Bounded: SparseIndex (~1 MB for 1B timestamps) - Bounded: SignalValueCache (~15 MB typical) - Total: ~130 MB for 1 TB file Performance: - Query latency: <50 ms (disk) or <1 ms (cached) - Cache hit rate: 95%+ after warming - Memory independent of file size CSV Format Support: 1. Time-based (default): timestamp,signal1,signal2,... 0,1,0 10,0,1 2. Signal-based: time,clk,data,valid 0,1,255,0 10,0,128,1 |
| StreamingChunkReader | @brief Coroutine that streams trace file in fixed-size chunks Efficiently reads large trace files by yielding data in configurable chunks. |
| StreamingChunkReaderPromise | @brief Promise type for StreamingChunkReader coroutine Implements the coroutine protocol for yielding TraceChunk objects. |
| StreamingConfig | @brief Configuration for streaming trace loading Controls how large trace files are loaded into the system. |
| StreamingFSTTrace | Streaming FST (Fast Signal Trace) file format reader Uses 4-layer architecture for terabyte-scale trace processing: Layer 1: Streaming I/O - StreamingChunkReader: C++20 coroutines, 100 MB chunks Layer 2: Indexing & Caching - SparseIndex: Timestamp → file offset mapping - SignalValueCache: LRU cache with adaptive sizing Layer 3: Format-Specific Reader - StreamingFSTTrace: Lazy FST parsing - Hierarchical scope support - Format validation - Multi-tier signal resolution Layer 4: Public API - Trace base class interface - Transparent streaming to users Memory Model: - Fixed: StreamingChunkReader (100 MB) - Bounded: SparseIndex (~1 MB for 1B timestamps) - Bounded: SignalValueCache (~15 MB typical) - Total: ~130 MB for 1 TB file Performance: - Query latency: <50 ms (disk) or <1 ms (cached) - Cache hit rate: 95%+ after warming - Memory independent of file size |
| StreamingVCDExample | @brief Example usage of StreamingChunkReader with VCD file This demonstrates: 1. Creating a streaming reader 2. Iterating through chunks with C++20 coroutines 3. Parsing VCD headers from chunks 4. Building sparse index during streaming Key Principles: - Memory stays bounded (one chunk at a time) - Lazy evaluation (data loaded on-demand) - Perfect for terabyte-scale files |
| StreamingVCDTrace | @brief Streaming VCD trace reader with lazy evaluation Extends the Trace base class to provide memory-efficient access to large VCD files using streaming chunks and sparse indexing. |
| Trace | @defgroup trace Trace System @brief Waveform file loading and signal access The Trace System provides unified access to hardware waveforms in multiple formats: - VCD (Verilog Change Dump) - standard format - FST (Fast Signal Trace) - compressed format - CSV (Comma-Separated Values) - custom format Architecture: @mermaid graph TD A["TraceContainer"] --> B["Trace Base Class"] B --> B1["VCDTrace"] B --> B2["FSTTrace"] B --> B3["CSVTrace"] A --> |
| TraceChunk | @brief Chunk of trace data read from file Represents a fixed-size chunk of bytes from the trace file. |
| TraceContainer | Central hub for managing multiple loaded waveform traces The TraceContainer: - Manages multiple traces - Keeps all loaded traces - Routes signal queries - Directs lookups to correct trace - Coordinates time - Steps all traces in sync - Handles format loading - Auto-detects VCD/FST/CSV Usage Flow: cpp auto container = std::make_shared<TraceContainer>(); container->load("trace1.vcd", "t1"); // Load VCD container->load("trace2.fst", "t2"); // Load FST // Access signals from any trace Value clk = container->signal_value("clk"); // From t1 Value data = container->signal_value("t2~data"); // From t2 // Step all traces in sync container->step(10); // All traces forward 10 cycles Signal Name Resolution: - Format: [trace-id~]signal-name - If trace-id omitted, searches all traces - Returns first match found - Use explicit prefix for disambiguation See : Trace for signal access details See : for loading interface |
| TraceError | Trace file loading or signal access failed Thrown by TraceContainer or Trace subclasses when: - File doesn't exist or is corrupted - Invalid VCD/FST/CSV format - Signal lookup fails - Time index out of range See : TraceContainer for trace loading See : Trace for signal access |
| VCDTrace | @brief VCD (Verilog Change Dump) file format trace reader Reads and parses VCD waveform files produced by Verilog/VHDL simulators. |
| ValueHolder | @brief Custom Value holder for Python-C++ interop Provides shared_ptr management for Value objects in Python, ensuring proper reference counting and lifetime management. |
| VirtualTrace | @brief A trace with no file behind it, created by (new-trace id max-index). |
| Wal | @defgroup Core Core API @brief Main user-facing WAL interface The Wal class is the primary entry point for users of WAL++. |
| WalError | @defgroup Errors Exception Hierarchy @brief WAL exception types for error handling Exception hierarchy: std::runtime_error ↓ WalError (base for all WAL errors) ├─ ParseError ├─ EvalError (with stack traces) └─ TraceError @{ Base exception for all WAL errors Derived exception classes should inherit from this for consistent error handling and reporting. |
Variables
| Name | Description |
|---|---|
| ENVELOPE_VERSION | @brief Machine-readable entry points, for a program driving WAL++ rather than a person. |
| it | @brief Variable binding environment with scope chain support Environments form a chain where each environment has an optional parent. |
Functions
| Name | Description |
|---|---|
| chunk_reader_coro | @brief Internal coroutine implementation (declared, not defined here) This is the actual coroutine that yields chunks. |
| compat_types_mode | @brief Whether arbitrary-precision integers are enabled. |
| create_chunk_reader | @brief Factory function to create a streaming chunk reader Creates a coroutine-based reader that streams a trace file in fixed-size chunks. |
| display_value | @brief Render a Value the way print does: for a person to read. Upstream's print is print(*[x if isinstance(x, str) else wal_str(x) ...], sep=''), so a string contributes its own characters with no quotes at any depth, and the arguments run together with no separator. |
| envelope | @brief Wrap a payload in the standard envelope. |
| error_envelope | The same envelope, carrying a failure instead of a payload. |
| format_double | @brief The shortest decimal that reads back as the same double. |
| inspect_trace | @brief Describe a trace as JSON. |
| is_special_variable | @brief Resolve one of WAL's special variables, such as INDEX or MAX-INDEX. |
| json_escape | Escape a string for JSON, including the control characters a signal name can carry. |
| lint_findings_json | Render lint findings as JSON. |
| lint_findings_text | Render lint findings the way a compiler would, for a person reading a terminal. |
| lint_script | @brief Check a script without running it. |
| make_value_shared | @brief Create shared_ptr wrapper for Value Useful for returning Value from C++ to Python as it maintains reference counting across language boundary. |
| normalize_array_index | @brief Rewrite an array-index suffix from name[0] to name<0>. |
| print_value | @brief Render a Value the way the REPL and -e both display results. |
| python_list_to_wlist | @brief Convert Python list to WAL WList |
| python_to_value | @brief Convert Python object to WAL Value Handles automatic conversion from Python types to WAL values: - int, float, str, bool -> direct conversion - list -> converts to WList - None -> nil Value |
| register_base_operators | @brief Register Phase 1 operators (foundation operators) Phase 1 includes: - Arithmetic: +, -, *, /, **, %, floor, ceil, round, abs, min, max - Comparison: <, >, <=, >=, ==, != - Logic: and, or, not, xor - Type checking: is-nil, is-bool, is-int, is-float, is-string, is-symbol, is-list - List operations: quote, list, car, cdr, cons, length, append, reverse - Conditionals: if, cond, when, unless - Variables: define, set!, lambda, let |
| register_trace_operators | @brief Phase 8: Trace File Support Operators Operators for loading, managing, and querying waveform trace files: - Load/unload trace files (VCD, FST, CSV formats) - Navigate traces (step, set-index, get-index) - Query signal values and metadata - Multi-trace management Operators (10 total): - load: Load a trace file (VCD, FST, or CSV) - unload: Unload a loaded trace - step: Move all traces forward/backward in time - signal?: Check if a signal exists in current traces - get-signal: Get value of a signal at current or offset index - signal-width: Get bit width of a signal - set-index: Set the current time index - get-index: Get current time index - get-traces: Get list of loaded trace IDs - signal-names: Get all signal names in loaded traces |
| register_value_type | @brief Register Value with pybind11 Must be called during module initialization to expose Value with proper holder type and conversion operators. |
| resolve_signal_name | @brief Resolve a signal name written in any of the accepted spellings. |
| value_to_json | Render an evaluated value as JSON, so a caller need not parse WAL syntax. |
| value_to_python | @brief Convert WAL Value to Python object Handles automatic conversion from WAL values to Python types: - int/float/string/bool -> direct conversion - list -> list of Python objects - symbol -> string representation - nil -> None |
| wlist_to_python_list | @brief Convert WList to Python list |
Variable Details
ENVELOPE_VERSION
inline constexpr int ENVELOPE_VERSION
@brief Machine-readable entry points, for a program driving WAL++ rather than a person.
An agent reading a trace faces the same first question every time: what is in it,
spelled exactly how. Getting that from --fast-list means parsing a text format;
getting it from the REPL means parsing S-expression output. Both are guessable and
both go wrong on the details, which is how a wrong signal name ends up in a script
that then runs and produces a plausible number.
The output follows the envelope used by the ITI ekumen tool, so an assistant that
has learned one of them can read the other. Two properties of it are safety
properties rather than conveniences:
Failures have the same envelope as successes. A consumer that must tell "the
command failed" from "the command returned nothing" by reading prose will
eventually get it wrong in the direction that matters. ok is always present.
Age is materialised. A trace is a file, and an agent can easily be reading one produced before the change it is trying to evaluate. Every payload carries the source's modification time and its age, so an answer from a stale trace cannot be skimmed as current. No freshness budget is invented here, because WAL++ has no way to know what the trace should be newer THAN; the facts are reported and the consumer decides.
JSON is emitted directly rather than through a library: the shapes are small and fixed, and a dependency for this would be out of proportion. Bumped when the envelope's own shape changes, never for payload additions.
it
auto it
@brief Variable binding environment with scope chain support
Environments form a chain where each environment has an optional parent. Variable lookup follows the chain: local -> parent -> grandparent, etc. Variable definition goes to the local environment unless explicitly targeting parent.
Function Details
chunk_reader_coro
StreamingChunkReader chunk_reader_coro(const std::string& filename, size_t chunk_size)
@brief Internal coroutine implementation (declared, not defined here)
This is the actual coroutine that yields chunks. Defined in streaming_chunk_reader.cpp
compat_types_mode
std::atomic<bool>& compat_types_mode()
@brief Whether arbitrary-precision integers are enabled.
Off by default: 64-bit integers are what waveform values and indices need, and the
bigint path is slower. Turned on with --bigint on the command line, or with
set_bigint_mode().
This is process-wide rather than per-interpreter because the PARSER consults it, and the parser is used standalone in several places.
Defined in one translation unit rather than as an inline function with a local static: the extension module and libwalpp are separate shared libraries, and an inline static gave each of them its OWN copy, so setting the mode from Python left the parser inside libwalpp still in 64-bit mode. @brief Whether upstream's permissive type coercion is enabled.
Off by default. WAL++ keeps types apart unless a conversion is written out:
(+ 1 "hi") is an error, and (= 0 #f), (= 1 #t) and (= 1 1.0) are all
false, because an int, a bool, a float and a string are four different things.
That matters here more than it would in a general-purpose language. The VCD
reader represents a signal wider than 64 bits as a bit STRING, so a + that
coerced strings would turn (+ wide 1) into concatenation of a bit pattern and
hand back a plausible-looking wrong answer instead of failing.
Upstream, being Python, coerces freely. --compat-types turns that on for
running upstream scripts unchanged, and says so rather than making it the
silent default.
create_chunk_reader
StreamingChunkReader create_chunk_reader(const std::string& filename, size_t chunk_size_bytes = 100 * 1024 * 1024)
@brief Factory function to create a streaming chunk reader
Creates a coroutine-based reader that streams a trace file in fixed-size chunks.
Performance Tuning: - Smaller chunks (10-50 MB): Lower memory, more overhead - Larger chunks (100-500 MB): Higher memory, less overhead - Default (100 MB): Good balance for most use cases
-
filename - Path to trace file to read
-
chunk_size_bytes - Size of each chunk in bytes (default: 100 MB)
- Return
- StreamingChunkReader ready to use @throws std::ios_base::failure if file cannot be opened
display_value
inline void display_value(const Value& result, std::ostream& os, bool top_level = true)
@brief Render a Value the way print does: for a person to read.
Upstream's print is print(*[x if isinstance(x, str) else wal_str(x) ...], sep=''),
so a string contributes its own characters with no quotes at any depth, and the
arguments run together with no separator. WAL++ used to quote strings and insert a
space, which made the ordinary labelled line (print "Total: " n) come out as
"Total: " 5.
-e and the REPL still use print_value below, which quotes, because there the
output is a value being shown rather than text being emitted.
envelope
std::string envelope(const std::string& command, const std::string& payload, const std::string& source, bool pretty)
@brief Wrap a payload in the standard envelope.
-
command - the mode that produced it, e.g. "inspect"
-
payload - already-rendered JSON, or "null"
-
source - the file the answer came from, for the age fields; may be empty
error_envelope
std::string error_envelope(const std::string& command, const AgentError& error, const std::string& source, bool pretty)
The same envelope, carrying a failure instead of a payload.
format_double
inline std::string format_double(double value)
@brief The shortest decimal that reads back as the same double.
Which is what Python's repr produces and therefore what upstream WAL prints.
Three renderers in this binary each had their own precision: print truncated
at 10 significant digits, -e at the stream default of 6, so (/ 10 3) printed
3.333333333 one way and 3.33333 the other, both short of the value held. They all
come here now.
inspect_trace
std::string inspect_trace(const std::string& file, bool pretty)
@brief Describe a trace as JSON.
Reads only the header where the format allows, so it stays cheap on a large file.
-
file - path to a VCD, FST or CSV trace
-
pretty - indent the output
is_special_variable
inline bool is_special_variable(const std::string& name)
@brief Resolve one of WAL's special variables, such as INDEX or MAX-INDEX.
Trace::get_special_signal has implemented these all along (INDEX, MAX-INDEX, TS,
TRACE-NAME, TRACE-FILE, SIGNALS, SCOPES, VIRTUAL-SIGNALS), but nothing ever called
it from the evaluator, so every one of them failed with Undefined variable. This
connects the two.
MAX-INDEX also closes a functional gap rather than only a compatibility one: there
was no way at all to ask how long a trace is, so the timestamp count had to be
inferred from (length (hamming-weight-scope ...)).
With several traces loaded the first one answers, which matches the single-trace case every published WAL program assumes. Upstream qualifies these per trace id; that is left for the trace-id work rather than guessed at here.
- Return
- true if
nameis a special variable that resolved Whethernameis one of WAL's special variables, independent of any trace.
json_escape
std::string json_escape(const std::string& text)
Escape a string for JSON, including the control characters a signal name can carry.
lint_findings_json
std::string lint_findings_json(const std::vector<LintFinding>& findings, const std::string& filename, bool pretty)
Render lint findings as JSON.
lint_findings_text
std::string lint_findings_text(const std::vector<LintFinding>& findings, const std::string& filename)
Render lint findings the way a compiler would, for a person reading a terminal.
lint_script
std::vector<LintFinding> lint_script(const std::string& source, const std::string& filename)
@brief Check a script without running it.
Catches the two failures that are worth catching statically: source that does not parse, and a call to something that does not exist. The second is the common one, because a mistyped operator is indistinguishable from a signal name until the moment it is evaluated, and by then half the script has already run.
A symbol it cannot resolve is reported as a WARNING rather than an error, because a bare symbol is how a signal is read and no trace is loaded here. The distinction matters: an unknown symbol in head position is a call to something that does not exist, which is an error; the same symbol in argument position is probably a signal.
make_value_shared
std::shared_ptr<Value> make_value_shared(const Value& v)
@brief Create shared_ptr wrapper for Value
Useful for returning Value from C++ to Python as it maintains reference counting across language boundary.
normalize_array_index
inline std::string normalize_array_index(const std::string& name)
@brief Rewrite an array-index suffix from name[0] to name<0>.
A VCD or FST hierarchy spells an array element data[0], and that name used to be
kept verbatim. It cannot stay that way now that [ opens a subscript in WAL++:
TOP.tb.data[0].data.something reads as the symbol TOP.tb.data subscripted by 0,
so a bracketed element was unaddressable as a bare symbol.
Upstream hit the same ambiguity and solved it the same way, so adopting <0> both
repairs the name and matches ics-jku/wal exactly.
Only a suffix that is entirely digits is rewritten, so a bit range or any other bracketed text is left alone.
print_value
inline void print_value(const Value& result, std::ostream& os, bool quote_strings)
@brief Render a Value the way the REPL and -e both display results.
This is the single implementation behind REPL::print_output and the CLI's
-e result printing. It used to be duplicated: the REPL copy handled lists
and symbols, the -e copy stopped at strings, so wal -e '(signal-names)'
printed nothing at all while the same expression printed fine in the REPL.
-
result - the value to render
-
os -
stream to write to
-
quote_strings - wrap a top-level string in double quotes (REPL style).
Strings nested inside a list are always quoted, so that a printed list
reads back as the list it came from. The CLI passes false to keep
wal -e '(concat "a" "b")'emitting bare text that a shell can consume.
nil is NOT handled here, because the two callers disagree on purpose: the REPL
stays silent (nil is what print returns, and echoing it would double every
line), while -e emits "nil" so a script can tell "evaluated to nothing" from
"produced no output". Each caller checks is_nil() before calling this.
python_list_to_wlist
std::shared_ptr<WList> python_list_to_wlist(const py::list& py_list)
@brief Convert Python list to WAL WList
python_to_value
Value python_to_value(const py::object& obj)
@brief Convert Python object to WAL Value
Handles automatic conversion from Python types to WAL values: - int, float, str, bool -> direct conversion - list -> converts to WList - None -> nil Value
register_base_operators
inline void register_base_operators(OperatorRegistry& registry)
@brief Register Phase 1 operators (foundation operators)
Phase 1 includes: - Arithmetic: +, -, *, /, **, %, floor, ceil, round, abs, min, max - Comparison: <, >, <=, >=, ==, != - Logic: and, or, not, xor - Type checking: is-nil, is-bool, is-int, is-float, is-string, is-symbol, is-list - List operations: quote, list, car, cdr, cons, length, append, reverse - Conditionals: if, cond, when, unless - Variables: define, set!, lambda, let
register_trace_operators
inline void register_trace_operators(OperatorRegistry& registry)
@brief Phase 8: Trace File Support Operators
Operators for loading, managing, and querying waveform trace files: - Load/unload trace files (VCD, FST, CSV formats) - Navigate traces (step, set-index, get-index) - Query signal values and metadata - Multi-trace management
Operators (10 total): - load: Load a trace file (VCD, FST, or CSV) - unload: Unload a loaded trace - step: Move all traces forward/backward in time - signal?: Check if a signal exists in current traces - get-signal: Get value of a signal at current or offset index - signal-width: Get bit width of a signal - set-index: Set the current time index - get-index: Get current time index - get-traces: Get list of loaded trace IDs - signal-names: Get all signal names in loaded traces
register_value_type
void register_value_type(py::module_& m)
@brief Register Value with pybind11
Must be called during module initialization to expose Value with proper holder type and conversion operators.
resolve_signal_name
inline bool resolve_signal_name(const std::shared_ptr<TraceContainer>& traces, const std::string& name, std::string& out)
@brief Resolve a signal name written in any of the accepted spellings.
WAL++ and upstream WAL (ics-jku/wal) disagree about separators, and WAL++'s own fast paths disagree with its interpreter:
- WAL++ interpreter:
tb^dut^counter(^joins the hierarchy) - WAL++
--fast-*:tb.dut.counter(.joins the hierarchy) - upstream WAL:
tb.dut.counter, with^reserved to prefix a TRACE ID, as ina^tb.dut.counter
Verified against upstream 0.9.1: (print tb^dut^counter) is an error there, while
a^tb.dut.counter selects the signal from the trace loaded under id a.
Rather than pick a winner and break existing scripts, this resolver accepts all of them. It tries candidate spellings in order of specificity and returns the first that a loaded trace actually contains, so a name that was already valid keeps resolving to the same signal.
-
traces - loaded traces (may be null or empty, in which case nothing resolves)
-
name -
the name as written by the user
-
out -
receives the canonical name a trace recognises
- Return
- true if some spelling resolved
value_to_json
std::string value_to_json(const Value& value)
Render an evaluated value as JSON, so a caller need not parse WAL syntax.
value_to_python
py::object value_to_python(const Value& val)
@brief Convert WAL Value to Python object
Handles automatic conversion from WAL values to Python types: - int/float/string/bool -> direct conversion - list -> list of Python objects - symbol -> string representation - nil -> None
wlist_to_python_list
py::list wlist_to_python_list(const std::shared_ptr<WList>& wlist)
@brief Convert WList to Python list