Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
bitlog_clash_tutorial/part_2/Example2.hs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
37 lines (31 sloc)
918 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Example2 where | |
import CLaSH.Prelude | |
stack2 (mem, sp) push pop value = ((mem', sp'), o) | |
where | |
(mem', sp') = case push of | |
True -> case pop of | |
True -> (replace (sp - 1) value mem, sp) | |
False -> (replace sp value mem, sp + 1) | |
False -> case pop of | |
True -> (mem, sp - 1) | |
False -> (mem, sp) | |
o = case pop of | |
True -> case push of | |
True -> mem !! (sp - 1) | |
False -> mem !! sp' | |
_ -> 0 | |
topEntity | |
:: (Vec 8 (Signed 16), Unsigned 3) | |
-> Bool | |
-> Bool | |
-> Signed 16 | |
-> ((Vec 8 (Signed 16), Unsigned 3), Signed 16) | |
topEntity = stack2 | |
-- Push 3 on the stack | |
x = topEntity (repeat 0, 0) True False 3 | |
-- Push 5 on the stack | |
y = topEntity (fst x) True False 5 | |
-- Pop the last value off of the stack | |
z = topEntity (fst y) False True 0 | |
-- Pop the last value off of the stack and replace it with 42 | |
w = topEntity (fst z) True True 42 |