tag types and moodularity improving

This commit is contained in:
Yehowshua Immanuel 2025-03-19 23:08:58 -04:00
parent 4422947f9a
commit 6359ab833d

View file

@ -5,21 +5,21 @@ import Util
#define UIntLog2N(n) (UInt (TLog n)) #define UIntLog2N(n) (UInt (TLog n))
data Tag a data Tag numTags
= Next (UInt a) = Next UIntLog2N(numTags)
| Empty | Tail
deriving (Bits, Eq, FShow) deriving (Bits, Eq, FShow)
initTagNext :: Integer -> Module(Reg (Tag a)) initTagNext :: Integer -> Module(Reg (Tag numTags))
initTagNext i = do initTagNext i = do
t :: Reg (Tag a) t :: Reg (Tag numTags)
t <- mkReg (Next (fromInteger i)) t <- mkReg (Next (fromInteger i))
return t return t
initTagEmpty :: Integer -> Module(Reg (Tag a)) initTagTail :: Module(Reg (Tag numTags))
initTagEmpty i = do initTagTail = do
t :: Reg (Tag a) t :: Reg (Tag numTags)
t <- mkReg Empty t <- mkReg Tail
return t return t
interface (TagEngine :: # -> *) numTags = interface (TagEngine :: # -> *) numTags =
@ -27,11 +27,23 @@ interface (TagEngine :: # -> *) numTags =
retireTag :: UIntLog2N(numTags) -> Action 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 :: Module (TagEngine numTags)
mkTagEngine = mkTagEngine =
do do
let v :: Vector numTags Integer = genVector tagVec :: Vector numTags (Reg (Tag numTags))
-- placeholder tagVec <- initTagVec
counter <- mkReg(0 :: UIntLog2N(numTags)) counter <- mkReg(0 :: UIntLog2N(numTags))
return $ return $
interface TagEngine interface TagEngine
@ -46,6 +58,7 @@ mkTagEngine =
counter := 0 counter := 0
where where
a = "Hello" a = "Hello"
idx_last :: Integer = (fromInteger |> valueOf numTags) - 1
a :: Integer a :: Integer
a = 3 a = 3