-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExample2.hs
More file actions
37 lines (31 loc) · 918 Bytes
/
Copy pathExample2.hs
File metadata and controls
37 lines (31 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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