packages feed

phino-0.0.162 / src / Tau.hs

{-# LANGUAGE OverloadedStrings #-}-- SPDX-FileCopyrightText: Copyright (c) 2025 Objectionary.com-- SPDX-License-Identifier: MITmodule Tau (seedTaus, freshTau) whereimport ASTimport Data.IORef (IORef, atomicModifyIORef', newIORef, writeIORef)import Data.Set (Set)import qualified Data.Set as Setimport Data.Text (Text)import qualified Data.Text as Timport GHC.IO (unsafePerformIO)taus :: IORef (Set Text, Int){-# NOINLINE taus #-}taus = unsafePerformIO (newIORef (Set.empty, 0))seedTaus :: Expression -> IO ()seedTaus expr = writeIORef taus (exprLabels expr, 0)freshTau :: IO TextfreshTau = atomicModifyIORef' taus advance  where    advance (taken, cursor) =      let (minted, idx) = mint taken cursor       in ((Set.insert minted taken, idx + 1), minted)mint :: Set Text -> Int -> (Text, Int)mint taken idx  | name `Set.member` taken = mint taken (idx + 1)  | otherwise = (name, idx)  where    name :: Text    name = "a🌵" <> T.pack (show idx)exprLabels :: Expression -> Set TextexprLabels (ExFormation bds) = Set.unions (map bindingLabels bds)exprLabels (ExApplication expr arg) = exprLabels expr <> argumentLabels argexprLabels (ExDispatch expr attr) = exprLabels expr <> attrLabel attrexprLabels (ExPhiMeet _ _ expr) = exprLabels exprexprLabels (ExPhiAgain _ _ expr) = exprLabels exprexprLabels _ = Set.emptybindingLabels :: Binding -> Set TextbindingLabels (BiTau attr expr) = attrLabel attr <> exprLabels exprbindingLabels (BiVoid attr) = attrLabel attrbindingLabels _ = Set.emptyargumentLabels :: Argument -> Set TextargumentLabels (ArTau attr expr) = attrLabel attr <> exprLabels exprargumentLabels (ArAlpha _ expr) = exprLabels exprattrLabel :: Attribute -> Set TextattrLabel (AtLabel label) = Set.singleton labelattrLabel _ = Set.empty