
cpu-arrow
An embedding of computation as a Haskell arrow
This update adds comprehensive unit testing for multibit FullAdder circuits in the test suite. By including the fullAdder2 test group, we ensure our circuit implementation correctly handles wider input ranges. This provides better confidence in the logic supporting larger arithmetic operations.
Added definitions for multi-bit FullAdder components (aFullAdder2 and aFullAdder3) to the CpuArrow library. These helpers extend the base FullAdder functionality to work with T2 and T4 types, enabling more complex arithmetic circuits. This change simplifies the construction of wider data path operations by leveraging existing arrow-based logic.
Expanded the test suite to include unit tests for aDemux, aDemux2, and aDemux3. This ensures the Advanced logic components are functioning correctly with various inputs. The new test cases verify the routing behavior across different Demux configurations.
We've added a set of demultiplexer circuit definitions (aDemux, aDemux2, and aDemux3) to the Advanced module. These primitives build on our existing BoolAlgebra abstractions to enable cleaner data routing logic within our CpuArrow framework. This simplifies creating complex wiring patterns for signal distribution.
The Half typeclass in src/CpuArrow/Half.hs has been updated to explicitly define the halfMerge function for splitting and merging tuple types from T2 to T16. This provides a more robust and cleaner abstraction for handling tuple-based data manipulation within the CpuArrow infrastructure. These changes standardize how sub-tuples are combined, simplifying data flow operations.
The aMux multiplexer circuit was updated to leverage halfFst and halfSnd tuple selectors instead of the standard fst and snd functions. This refactoring establishes a consistent data access pattern across the module, bringing the base aMux implementation into alignment with wider multiplexers like aMux2 and aMux3. By standardizing these definitions, the Arrow-based circuit structures remain consistent and easier to build upon.
The fixed-size tuple types (T2 through T16) and the associated Half typeclass have been cleanly extracted from Base.hs into a new Half.hs module. This refactor separates the boilerplate needed for tuple-splitting instances from the core circuit routing logic. By isolating these structural data types, the base module becomes much less cluttered and easier to navigate.
Expanded the logic component test suite to include functional validation for the aFullAdder circuit. The new test case executes all 8 input combinations of sums and carry-ins to verify proper logic outputs. This ensures our core arithmetic operations are calculating correctly before building more complex unit behavior.
This update introduces the aFullAdder component within the CpuArrow advanced circuits module. Built using Haskell Arrows, it chains together two half adders and an OR gate to compute both the sum and the carry bits over any custom BoolAlgebra instance. This addition provides a functional and composable building block, laying the groundwork for more complex multi-bit arithmetic operations within the simulated hardware logic.
Added halfAdderTests to the test suite to verify the logic of the aHalfAdder circuit. The test checks all four combinations of input bits against the expected sum and carry outputs. This expands the automated test coverage for core hardware logic components.
Added a new aHalfAdder circuit to the CpuArrow library by combining aAnd and aXor logic gates. The implementation elegantly leverages the Arrow &&& combinator to simultaneously compute both the carry and the sum. This foundational piece paves the way for building full adders and more complex CPU logic blocks in a declarative style.
This commit expands the Haskell test suite to cover the advanced mux implementations by importing CpuArrow.Advanced.Mux and wiring new Mux and Mux2 groups into the main test tree. The new cases exhaustively exercise selector combinations and input permutations, which helps confirm the circuit semantics beyond the existing basic logic-gate coverage. In practice, this gives much better confidence that multiplexing primitives behave correctly as the library grows.
New multiplexer definitions (aMux, aMux2, and aMux3) have been added to the CpuArrow.Advanced.Mux module. These circuits elegantly combine built-in boolean operations via the Arrow abstraction to route signals for 2-way, 4-way, and 8-way selection. This provides an essential foundation of routing components for constructing more complex CPU logic circuits in Haskell.
Introduced type aliases for uniform tuples of sizes 2, 4, 8, and 16 (T2, T4, etc.) in the base module. To complement this, a new Half typeclass was added, providing halfFst and halfSnd functions to easily split these large tuples into their respective front and back halves. This standardizes how grouped signals or data structures are manipulated, abstracting away the need to manually pattern-match across wide tuples.
We've added a BoolAlgebra instance for Int, mapping logical true to 1 and false to 0 to support integer-based boolean logic. The test suite was refactored to use this new instance, replacing verbose lists of True and False values with simple 0 and 1 integers. This makes truth tables significantly more compact and easier to read at a glance.
This change turns Lib into a broad re-export module by importing the exposed CpuArrow components directly, which makes the package surface easier to consume from a single entry module. At the same time, Main.main was replaced with undefined, suggesting the executable stub is being intentionally disabled while the library layout is being reorganized. The practical effect is a cleaner import story for downstream code, but the app target is not runnable in this commit.
The internal representation of Circuit was refactored to operate over standard finite lists [a] instead of a custom Seq infinite stream. This cleaned up the codebase by eliminating the reinvented Seq type and its custom zippable instances in favor of built-in list operations like unzip and zip. Additionally, a test suite was set up using Tasty.HUnit to properly verify the correctness of core logic gates like And, Or, Not, and Xor. This simplifies the core engine and provides a solid foundation for further development with tested primitive components.
The ArrowApply instance for the Circuit type has been removed, dropping the app implementation that previously relied on runCircuit. This restricts dynamic arrow application for sequence-to-sequence arrows, preventing their use in contexts requiring ArrowApply. By tightening the available operations on circuits, this minor API cleanup simplifies the typeclass hierarchy and helps avoid potentially problematic usage patterns.