diff --git a/bs/TagEngine.bs b/bs/TagEngine.bs index cb21845..aceebc2 100644 --- a/bs/TagEngine.bs +++ b/bs/TagEngine.bs @@ -5,21 +5,21 @@ import Util #define UIntLog2N(n) (UInt (TLog n)) -data Tag a - = Next (UInt a) - | Empty +data Tag numTags + = Next UIntLog2N(numTags) + | Tail deriving (Bits, Eq, FShow) -initTagNext :: Integer -> Module(Reg (Tag a)) +initTagNext :: Integer -> Module(Reg (Tag numTags)) initTagNext i = do - t :: Reg (Tag a) + t :: Reg (Tag numTags) t <- mkReg (Next (fromInteger i)) return t -initTagEmpty :: Integer -> Module(Reg (Tag a)) -initTagEmpty i = do - t :: Reg (Tag a) - t <- mkReg Empty +initTagTail :: Module(Reg (Tag numTags)) +initTagTail = do + t :: Reg (Tag numTags) + t <- mkReg Tail return t interface (TagEngine :: # -> *) numTags = @@ -27,11 +27,23 @@ interface (TagEngine :: # -> *) numTags = retireTag :: UIntLog2N(numTags) -> Action +initTagVec :: Module(Vector numTags (Reg (Tag numTags))) +initTagVec = + do + tagVecSequential :: Vector numTags (Reg (Tag numTags)) + tagVecSequential <- mapM (\idx -> initTagNext (idx+1)) genVector + let idxLast :: Integer = (fromInteger |> valueOf numTags) - 1 + tailTag <- initTagTail + -- the tail of our TagVec should be `Tail` not `Next` + let finalTagVec = update tagVecSequential idxLast tailTag + return finalTagVec + mkTagEngine :: Module (TagEngine numTags) mkTagEngine = do - let v :: Vector numTags Integer = genVector - -- placeholder + tagVec :: Vector numTags (Reg (Tag numTags)) + tagVec <- initTagVec + counter <- mkReg(0 :: UIntLog2N(numTags)) return $ interface TagEngine @@ -46,6 +58,7 @@ mkTagEngine = counter := 0 where a = "Hello" + idx_last :: Integer = (fromInteger |> valueOf numTags) - 1 a :: Integer a = 3