Skip to content

Wal

class Wal

@defgroup Core Core API @brief Main user-facing WAL interface

The Wal class is the primary entry point for users of WAL++. It integrates all subsystems:

@mermaid graph TB A["Wal
Main API"] --> B["SEval
Evaluator"] A --> C["TraceContainer
Waveforms"] A --> D["OperatorRegistry
Operators"] B --> E["Environment
Variables"] B --> D C --> F["Trace Formats
VCD/FST/CSV"] @endmermaid

Usage Flow: 1. Create Wal() instance 2. load() trace files 3. eval_str() or run_file() for computation 4. Access results via returned Value

See Also: - "Evaluator" - expression evaluation - "Trace System" - waveform access - "Operator Registry" - extensibility

@{ Main WAL interface class

This is the primary class users interact with. It provides: - Trace management: load/unload waveform files (VCD, FST, CSV) - Program execution: eval_str(), run_file(), REPL - State tracking: step through time, manage loaded traces - Environment access: query and modify variables

Variables

Name Description
std_library_loaded see ensure_std_library()

Functions

Name Description
Wal Create a new WAL instance with initialized context Initializes: - Empty trace container - SEval evaluator with builtins - Standard library operators - Global environment
load @name Trace Management @{ Load a waveform file Supported formats: - .vcd → Verilog Change Dump - .fst → Fast Signal Trace (requires pylibfst) - .csv → Comma-Separated Values Auto-detects format from file extension. Signals become accessible as WAL variables. file : Path to the waveform file tid : Trace ID for this file (default: auto-generated) @throws TraceError if file not found or parse fails See : for signal access patterns
unload Unload a trace file and free its memory After unload, signals from this trace are no longer accessible.
step Advance traces through time Steps all loaded traces forward or backward in time.
ensure_std_library @} @name Evaluation @{ Evaluate a WAL expression from a string Parses an S-expression and evaluates it in the current context.
eval_program @brief Evaluate every top-level form in code, in order.
eval Evaluate a parsed WAL expression expr : The already-parsed expression Return : The result value @throws EvalError if evaluation fails See : eval_str for string parsing
run_str Run WAL code with a fresh evaluation context Similar to eval() but resets state: - Traces return to time 0 - User definitions cleared - Global environment preserved Useful for multiple independent computations. code : The WAL code to run Return : The result value
run Run a parsed expression with fresh context expr : The expression to run Return : The result value See : run_str for behavior details
run_file Load and execute a WAL program from a file Reads .wal or .wo file and evaluates all expressions sequentially. Returns the result of the last expression. Example WAL program: scheme (load "trace.vcd") (define counter (signal "clk")) (map (lambda (i) (signal "data" i)) (range 0 100)) filename : Path to .wal or .wo file Return : The result of the last expression @throws TraceError if file not found @throws ParseError if syntax is invalid
start_repl Start the interactive REPL Begins interactive shell loop: - Reads expressions from stdin - Pretty-prints results - Maintains command history - Quits on (quit) or EOF Return : Exit code (0 = success) See : REPL for shell features
get_traces @} @name Accessors @{ Access to loaded traces See : "Trace System" for signal queries
get_eval_context Access to evaluator for low-level control See : for SEval documentation
get_operator_registry Access to operator registry for extending WAL See : "Operator Registry"
get_environment Access to global variable bindings See : Environment for scope chain semantics
print_error @} @name Error Handling @{ Print error information for debugging Helper function for pretty-printing parse or evaluation errors.

Variable Details

std_library_loaded

bool std_library_loaded

see ensure_std_library()

Function Details

Wal

Wal()

Create a new WAL instance with initialized context

Initializes: - Empty trace container - SEval evaluator with builtins - Standard library operators - Global environment

ensure_std_library

void ensure_std_library()

@} @name Evaluation @{ Evaluate a WAL expression from a string

Parses an S-expression and evaluates it in the current context. This does NOT reset state - useful for incremental evaluation.

Example:

1
2
3
auto wal = std::make_shared<Wal>();
wal->load("trace.vcd");
Value result = wal->eval_str("(+ 1 2)");  // 3

code
The WAL S-expression to evaluate
Return
The result value @throws ParseError if syntax is invalid @throws EvalError if evaluation fails
See
for trace access Define the standard library on first use. Idempotent.

eval

Value eval(const Value& expr)

Evaluate a parsed WAL expression

expr
The already-parsed expression
Return
The result value @throws EvalError if evaluation fails
See
eval_str for string parsing

eval_program

Value eval_program(const std::string& code)

@brief Evaluate every top-level form in code, in order.

eval_str parses a single expression, so input holding several top-level forms silently evaluated only the first. That is what a script file, stdin and a pipe all contain, so wal -f script.wal ran one form and stopped without any error.

code
source with zero or more top-level forms
Return
the value of the last form, or nil if there were none

get_environment

std::shared_ptr<Environment> get_environment() const

Access to global variable bindings

See
Environment for scope chain semantics

get_eval_context

std::shared_ptr<SEval> get_eval_context() const

Access to evaluator for low-level control

See
for SEval documentation

get_operator_registry

OperatorRegistry& get_operator_registry()

Access to operator registry for extending WAL

See
"Operator Registry"

get_traces

std::shared_ptr<TraceContainer> get_traces() const

@} @name Accessors @{ Access to loaded traces

See
"Trace System" for signal queries

load

void load(const std::string& file, const std::string& tid = "DEFAULT")

@name Trace Management @{ Load a waveform file

Supported formats: - .vcd → Verilog Change Dump - .fst → Fast Signal Trace (requires pylibfst) - .csv → Comma-Separated Values

Auto-detects format from file extension. Signals become accessible as WAL variables.

file
Path to the waveform file
tid
Trace ID for this file (default: auto-generated) @throws TraceError if file not found or parse fails
See
for signal access patterns

void print_error(const Value& expr, const std::string& error)

@} @name Error Handling @{ Print error information for debugging

Helper function for pretty-printing parse or evaluation errors.

expr
The expression that caused the error
error
The error message or exception

run

Value run(const Value& expr)

Run a parsed expression with fresh context

expr
The expression to run
Return
The result value
See
run_str for behavior details

run_file

Value run_file(const std::string& filename)

Load and execute a WAL program from a file

Reads .wal or .wo file and evaluates all expressions sequentially. Returns the result of the last expression.

Example WAL program:

1
2
3
(load "trace.vcd")
(define counter (signal "clk"))
(map (lambda (i) (signal "data" i)) (range 0 100))

filename
Path to .wal or .wo file
Return
The result of the last expression @throws TraceError if file not found @throws ParseError if syntax is invalid

run_str

Value run_str(const std::string& code)

Run WAL code with a fresh evaluation context

Similar to eval() but resets state: - Traces return to time 0 - User definitions cleared - Global environment preserved

Useful for multiple independent computations.

code
The WAL code to run
Return
The result value

start_repl

int start_repl()

Start the interactive REPL

Begins interactive shell loop: - Reads expressions from stdin - Pretty-prints results - Maintains command history - Quits on (quit) or EOF

Return
Exit code (0 = success)
See
REPL for shell features

step

void step(int steps = 1, const std::string& tid = "")

Advance traces through time

Steps all loaded traces forward or backward in time. Useful for sequential trace analysis.

steps
Number of time steps to move (default: 1) Positive = forward, Negative = backward
tid
Optional specific trace to step (empty = all) @throws TraceError if step would go out of bounds

unload

void unload(const std::string& tid = "DEFAULT")

Unload a trace file and free its memory

After unload, signals from this trace are no longer accessible.

tid
Trace ID to unload (default: "DEFAULT") @throws TraceError if trace not found