Permalink
Browse files

Added idId runtime function. Reved version.

  • Loading branch information...
1 parent a530b79 commit 74a7114019f476cf7067508b4cffc56e4e125ea1 @tomahawkins committed May 18, 2012
Showing with 20 additions and 7 deletions.
  1. +19 −6 Language/CIRC/Runtime.hs
  2. +1 −1 circ.cabal
View
@@ -5,28 +5,41 @@ module Language.CIRC.Runtime
, runCIRC
, Id
, newId
+ , idId
) where
import Control.Monad.State
-- | The CIRC transform monad. Used to create fresh ids.
-type CIRC = State Int
+type CIRC = State (Int, [(String, Int)])
-- | Evaluates a CIRC transform.
evalCIRC :: CIRC a -> Int -> a
-evalCIRC = evalState
+evalCIRC a i = evalState a (i, [])
-- | Evaluates a CIRC transform, also returning the fresh next id.
runCIRC :: CIRC a -> Int -> (a, Int)
-runCIRC = runState
+runCIRC a i = (b, j)
+ where
+ (b, (j, _)) = runState a (i, [])
-- | Identifiers.
type Id = String
-- | Produces a fresh id.
newId :: CIRC Id
newId = do
- id <- get
- put $ id + 1
- return $ "__" ++ show id
+ (i, table) <- get
+ put (i + 1, table)
+ return $ "__" ++ show i
+
+-- | Returns a unqiue int for a given id.
+idId :: Id -> CIRC Int
+idId name = do
+ (i, table) <- get
+ case lookup name table of
+ Nothing -> do
+ put (i + 1, (name, i) : table)
+ return i
+ Just i -> return i
View
@@ -1,5 +1,5 @@
name: circ
-version: 0.0.3
+version: 0.0.4
synopsis: A Compiler IR Compiler.
description: A Compiler IR Compiler.
license: BSD3

0 comments on commit 74a7114

Please sign in to comment.