https://github.com/nwtgck/type-safe-mips-haskell
Type-Safe Virtual MIPS Architecture in Haskell
https://github.com/nwtgck/type-safe-mips-haskell
haskell simulation
Last synced: 12 months ago
JSON representation
Type-Safe Virtual MIPS Architecture in Haskell
- Host: GitHub
- URL: https://github.com/nwtgck/type-safe-mips-haskell
- Owner: nwtgck
- License: bsd-3-clause
- Created: 2017-08-17T20:39:31.000Z (almost 9 years ago)
- Default Branch: develop
- Last Pushed: 2018-06-18T13:28:02.000Z (about 8 years ago)
- Last Synced: 2025-03-31T07:15:57.656Z (about 1 year ago)
- Topics: haskell, simulation
- Language: Haskell
- Homepage:
- Size: 148 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# type-safe-mips
[](https://travis-ci.com/nwtgck/type-safe-mips-haskell)
Subset of Virtual MIPS Architecture written in Haskell in Type-Safe way
## MIPS Schematic
Here is the whole schematic implemented virtually in Haskell.

You can also get detail specification of Main Control and ALU Control from URL below.
http://web-ext.u-aizu.ac.jp/~yliu/teaching/comparch/lab4.html
## How to run
```
stack build
stack exec type-safe-mips-exe
```
## Technologies & Main GHC Pragmas
* Yampa (FRP library)
* Arrows
* GADTs (Generalized Algebraic Data Types)
* TypeFamilies
* TypeOperators
Some of these technologies make it to be type-safe!
## Type safety
`iRFormat`, for example, is a typed-legth list, which provide type safety more than normal list.
```hs
let iRFormat = O:*O:*O:*O:*O:*O:*End :: Bits N6
```
(Type `:: Bits N6` or `:: Bits N32` is typed-length list.)
`Bits` has some list-operators which has type safety.
```hs
headBits :: Bits (Succ n) -> Bit
takeBits :: SNat n -> Bits m -> Bits (Min n m)
dropBits :: SNat n -> Bits m -> Bits (m - n)
(+*+) :: Bits n -> Bits m -> Bits (n+m) -- similar to (++) in list
```
### Normal List
```hs
let list = [] :: [Bool]
head list -- Compile pass. but "Exception: Prelude.head: empty list"
```
### `Bits` (type-safe)
```hs
let bits = End :: Bits N0 -- similar to []
headBits bits -- Compile Error (GOOD!)
```