CoHDL
  1. Blog
  2. CoHDL 0.8.0

CoHDL 0.8.0: Parameterized
Circuit Construction

Channel counts, wiring loops, and placement grids can share typed compile-time values. CoHDL expands the result into ordinary instances and nets, then checks the resulting circuit.

Compiler v0.8.0 was released on . This post fills a gap in our release coverage.

A board family often changes one count in several places: the number of channels, the connections between them, and the positions on the PCB. CoHDL 0.8.0 lets those decisions share local constants and exact expressions, so changing the count does not require copying another set of wiring and placement statements.

Counts and distances have distinct types

Local Int constants describe counts and indexes; Length constants describe distances. Array lengths, selectors, placement coordinates, and rotations can use computed values. An array's .len exposes its declared length. For example, inside a design with an existing Channel device declaration:

Count and placement inside a design; wiring omitted
const N: Int = 8
const Pitch: Length = 2.54mm
inst channels: [Channel; N]

layout {
    for grid: i in 0..channels.len {
        place channels[i] at (10mm + (i % 4) * Pitch,
                              10mm + (i / 4) * Pitch)
    }
}

This puts eight instances on a four-column grid. Changing N changes the array and the placement loop together. The arithmetic is checked: integer overflow is an error, a number does not become a length implicitly, and length division must be exactly representable.

Repeat construction with an explicit identity

Labelled for loops use half-open ranges: 0..N visits zero through N minus one. Circuit loops can connect pins, mark pins unconnected, call helper functions, and carry placement operations. Layout loops repeat placements. The label and iteration value form part of the identity of objects created through helpers, preserving existing designators when a loop grows. Renaming the label changes that identity.

Declare instance and subdesign arrays outside the loop. Direct instance or subdesign declarations in loop bodies are rejected, as are directly authored named nets. Declare a shared named rail outside the loop and join it through anonymous net _ connections. These rules make repeated connectivity explicit.

Reusable blocks and bounded evaluation

Functions and subdesigns can take const N: Int generic parameters, so a reusable block can own its channel count. Evaluation happens during compilation, with checked arithmetic and bounded expansion. No loop becomes firmware. Every expanded instance still participates in pin-obligation and residual DRC checks.

Formatter, LSP, editor grammars, Explorer extraction, and registry API documentation understand these constructs. The diagnostic JSON interface remains schema 1. Package API docs use schema 2 when the new constructs occur, retaining schema 1 for legacy documents; consumers of cohdl docs need to support both.

Implementation shipped; language proposal remains provisional

This release implements the proposed RFC-033 design. The proposal has not been promoted to an Accepted language decision. Its scope and implementation boundaries remain recorded in the compliance report.

CoHDL 0.8.1 subsequently fixes parser hangs on malformed input. Use the latest compiler for these features and their follow-up fixes.

Get the update

Install the latest compiler, which includes these changes:

cohdl self-update

For a new installation, follow the getting-started guide. The v0.8.0 release page has this version's platform archives and checksums; the full comparison records the source changes.