diff options
author | Tom Smeding <tom@tomsmeding.com> | 2024-09-05 21:56:07 +0200 |
---|---|---|
committer | Tom Smeding <tom@tomsmeding.com> | 2024-09-05 21:57:02 +0200 |
commit | 402d28014e1e95c1fa8706c3648519a89a9e0e0f (patch) | |
tree | dd8ebb50c9041054b5ecf8d687c234fe1a81e5bf /src/Language/Tag.hs | |
parent | 150236cd0a2ff3dd199b13fb47b3ab1955a00193 (diff) |
A simple embedded frontend
Diffstat (limited to 'src/Language/Tag.hs')
-rw-r--r-- | src/Language/Tag.hs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/Language/Tag.hs b/src/Language/Tag.hs new file mode 100644 index 0000000..9356073 --- /dev/null +++ b/src/Language/Tag.hs @@ -0,0 +1,22 @@ +{-# LANGUAGE BangPatterns #-} +module Language.Tag ( + Tag(..), genTag, +) where + +import Data.IORef +import System.IO.Unsafe + +import AST + + +data Tag t = Tag (STy t) Int + deriving (Show) + +{-# NOINLINE tagCounter #-} +tagCounter :: IORef Int +tagCounter = unsafePerformIO $ newIORef 1 + +{-# NOINLINE genTag #-} +genTag :: handle -> STy t -> Tag t +genTag !_ ty = + unsafePerformIO $ Tag ty <$> atomicModifyIORef' tagCounter (\i -> (succ i, i)) |