aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Top.bs53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/Top.bs b/src/Top.bs
new file mode 100644
index 0000000..6dee830
--- /dev/null
+++ b/src/Top.bs
@@ -0,0 +1,53 @@
+package Top where
+
+mkTop :: Module Empty
+mkTop =
+ module
+ deepThought :: DeepThought_IFC <- mkDeepThought
+
+ rules
+ "rl_ask": when True ==> do
+ $display "Asking the Ultimate Question of Life, The Universe and Everything"
+ deepThought.whatIsTheAnswer
+
+ "rl_print_answer": when True ==> do
+ x <- deepThought.getAnswer
+ $display "Deep Thought says: Hello, World! The answer is %0d." x
+ $finish
+
+interface DeepThought_IFC =
+ whatIsTheAnswer :: Action
+ getAnswer :: ActionValue (Int 32)
+
+data State_DT = IDLE | THINKING | ANSWER_READY
+ deriving (Eq, Bits, FShow)
+
+mkDeepThought :: Module DeepThought_IFC
+mkDeepThought =
+ module
+ rg_state_dt :: Reg State_DT <- mkReg IDLE
+ rg_half_millenia :: Reg (Bit 4) <- mkReg 0
+
+ let millenia = rg_half_millenia [3:1]
+ let half_millenium = rg_half_millenia [0:0]
+
+ rules
+ "rl_think": when (rg_state_dt == THINKING) ==> do
+ $write " DeepThought: ... thinking ... (%0d" millenia
+ if (half_millenium == 1) then $write ".5" else noAction
+ $display " million years)"
+
+ if (rg_half_millenia == 15) then
+ rg_state_dt := ANSWER_READY
+ else
+ rg_half_millenia := rg_half_millenia + 1
+
+ interface
+ whatIsTheAnswer = rg_state_dt := THINKING
+ when (rg_state_dt == IDLE)
+
+ getAnswer = do
+ rg_state_dt := IDLE
+ rg_half_millenia := 0
+ return 42
+ when (rg_state_dt == ANSWER_READY)