Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions hashtbl/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Revision history for hashtbl

## 0.1.0.0 -- YYYY-mm-dd

* First version. Released on an unsuspecting world.
674 changes: 674 additions & 0 deletions hashtbl/LICENSE

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions hashtbl/app/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Main where

import qualified MyLib (someFunc)

main :: IO ()
main = do
putStrLn "Hello, Haskell!"
MyLib.someFunc
131 changes: 131 additions & 0 deletions hashtbl/hashtbl.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
cabal-version: 3.4
-- The cabal-version field refers to the version of the .cabal specification,
-- and can be different from the cabal-install (the tool) version and the
-- Cabal (the library) version you are using. As such, the Cabal (the library)
-- version used must be equal or greater than the version stated in this field.
-- Starting from the specification version 2.2, the cabal-version field must be
-- the first thing in the cabal file.

-- Initial package description 'hashtbl' generated by
-- 'cabal init'. For further documentation, see:
-- http://haskell.org/cabal/users-guide/
--
-- The name of the package.
name: hashtbl

-- The package version.
-- See the Haskell package versioning policy (PVP) for standards
-- guiding when and how versions should be incremented.
-- https://pvp.haskell.org
-- PVP summary: +-+------- breaking API changes
-- | | +----- non-breaking API additions
-- | | | +--- code changes with no API change
version: 0.1.0.0

-- A short (one-line) description of the package.
synopsis: Clash order map

-- A longer description of the package.
-- description:

-- URL for the project homepage or repository.
homepage: https://punt-engine.com/

-- The license under which the package is released.
license: GPL-3.0-or-later

-- The file containing the license text.
license-file: LICENSE

-- The package author(s).
author: NaquanS

-- An email address to which users can send suggestions, bug reports, and patches.
maintainer: contact@naquansmith.com

-- A copyright notice.
-- copyright:
category: Data Structure
build-type: Simple

-- Extra doc files to be distributed with the package, such as a CHANGELOG or a README.
extra-doc-files: CHANGELOG.md

-- Extra source files to be distributed with the package, such as examples, or a tutorial module.
-- extra-source-files:

common warnings
ghc-options: -Wall

library
-- Import common warning flags.
import: warnings

-- Modules exported by the library.
exposed-modules: MyLib

-- Modules included in this library but not exported.
-- other-modules:

-- LANGUAGE extensions used by modules in this package.
-- other-extensions:

-- Other library packages from which modules are imported.
build-depends: base ^>=4.17.2.1

-- Directories containing source files.
hs-source-dirs: src

-- Base language which the package is written in.
default-language: GHC2021

executable hashtbl
-- Import common warning flags.
import: warnings

-- .hs or .lhs file containing the Main module.
main-is: Main.hs

-- Modules included in this executable, other than Main.
-- other-modules:

-- LANGUAGE extensions used by modules in this package.
-- other-extensions:

-- Other library packages from which modules are imported.
build-depends:
base ^>=4.17.2.1,
hashtbl

-- Directories containing source files.
hs-source-dirs: app

-- Base language which the package is written in.
default-language: GHC2021

test-suite hashtbl-test
-- Import common warning flags.
import: warnings

-- Base language which the package is written in.
default-language: GHC2021

-- Modules included in this executable, other than Main.
-- other-modules:

-- LANGUAGE extensions used by modules in this package.
-- other-extensions:

-- The interface type and version of the test suite.
type: exitcode-stdio-1.0

-- Directories containing source files.
hs-source-dirs: test

-- The entrypoint to the test suite.
main-is: Main.hs

-- Test dependencies.
build-depends:
base ^>=4.17.2.1,
hashtbl
4 changes: 4 additions & 0 deletions hashtbl/src/MyLib.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module MyLib (someFunc) where

someFunc :: IO ()
someFunc = putStrLn "someFunc"
76 changes: 76 additions & 0 deletions hashtbl/src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# FIX v4.4 parser

## FSM

![image](https://github.com/user-attachments/assets/34fab4d6-8ad9-4399-a34e-796484e896ec)

## Building and testing

## Cabal (Linux, MacOS)
**The following instructions only work for Cabal >=3.0 and GHC >=8.4.**

First, update your cabal package database:

```bash
cabal update
```

You only have to run the update command once. After that, you can keep rebuilding your project by running the build command:

```bash
cabal build
```

To run the tests defined in `tests/`, use:

```bash
cabal run test-library
cabal run doctests
```

To compile the project to VHDL, run:

```bash
cabal run clash -- HashTable --vhdl
```

You can find the HDL files in `vhdl/`. The source can be found in `src/Example/Project.hs`.

## REPL
Clash offers a [REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop) as a quick way to try things, similar to Python's `python` or Ruby's `irb`.

Cabal users use:

```
cabal run clashi
```

## tests/
Most of this directory is scaffolding, with the meat of the tests being defined in `tests/Tests/Example/Project.hs`. Writing good test cases is pretty hard: edge cases are easy to forget both in the implementation and tests. To this end, it's a good idea to use _fuzz testing_. In this project we use [Hedgehog](https://hedgehog.qa/):

```haskell
import Example.Project (plus)

prop_plusIsCommutative :: H.Property
prop_plusIsCommutative = H.property $ do
a <- H.forAll (Gen.integral (Range.linear minBound maxBound))
b <- H.forAll (Gen.integral (Range.linear minBound maxBound))
plus a b === plus b a
```

This test generates two numbers `a` and `b` that fit neatly into domain of `Signed 8`, thanks to the use of `minBound` and `maxBound`. It then tests whether the `plus` operation commutes. I.e., whether `a + b ~ b + a`. All functions called `prop_*` are collected automatically:

```haskell
tests :: TestTree
tests = $(testGroupGenerator)
```

We can run the tests using `cabal run test-library`:

```
.
Tests.Example.Project
plusIsCommutative: OK
✓ plusIsCommutative passed 100 tests.

All 1 tests passed (0.00s)```
7 changes: 7 additions & 0 deletions hashtbl/src/bin/Clash.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

import Prelude
import System.Environment (getArgs)
import Clash.Main (defaultMain)

main :: IO ()
main = getArgs >>= defaultMain
7 changes: 7 additions & 0 deletions hashtbl/src/bin/Clashi.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

import Prelude
import System.Environment (getArgs)
import Clash.Main (defaultMain)

main :: IO ()
main = getArgs >>= defaultMain . ("--interactive":)
7 changes: 7 additions & 0 deletions hashtbl/src/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
packages:
punt-engine-haskell-cores.cabal

write-ghc-environment-files: always

-- Eliminates the need for `--enable-tests`, which is needed for HLS.
tests: true
12 changes: 12 additions & 0 deletions hashtbl/src/hie.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cradle:
cabal:
- path: "./src"
component: "lib:punt-engine-haskell-cores"
- path: "./tests/doctests.hs"
component: "punt-engine-haskell-cores:doctests"
- path: "./tests"
component: "punt-engine-haskell-cores:test-library"
- path: "./bin/Clashi.hs"
component: "punt-engine-haskell-cores:exe:clashi"
- path: "./bin/Clash.hs"
component: "punt-engine-haskell-cores:exe:clash"
Loading