Permalink
Browse files

work in progress

  • Loading branch information...
svenssonjoel committed May 20, 2012
1 parent 754de8f commit ee6d35991bdd6addba45815d989cc59c97c0fa8f
Showing with 73 additions and 4 deletions.
  1. +9 −1 Intel/ArBB/ExpToLExp.hs
  2. +62 −1 Intel/ArBB/Language.hs
  3. +2 −2 Intel/ArBB/Syntax.hs
View
@@ -81,7 +81,12 @@ label e@(Map fn exprs) =
l <- addExp e
exprs' <- mapM label exprs
return (LMap l fn exprs')
-label e@(While e1 es1 es2) = error "While is not implemented"
+-- TODO: Figure this one out.
+label e@(While e1 es1 es2) =
+ do
+ l <- addExp e
+ return $ error "While is not implemented"
+
label e@(If e1 e2 e3) =
do
l <- addExp e
@@ -95,6 +100,9 @@ label e@(Op op exprs) =
exprs' <- mapM label exprs
return (LOp l op exprs')
+createVariables :: [Expr] -> Labeler [Variable]
+createVariables = undefined
+
----------------------------------------------------------------------------
expToLExp :: Expr -> LExp
View
@@ -288,7 +288,67 @@ ifThenElse (E b) (E e1) (E e2) = E $ If b e1 e2
----------------------------------------------------------------------------
-- While Loops
+while :: LoopState state
+ => (state -> Exp Bool)
+ -> (state -> state)
+ -> state
+ -> state
+while cond f state = loopFinalState loop
+ where
+ loop = E $ While c body (loopState state)
+ -- (curr,vars) = loopVars state
+ c = loopCond cond
+ body = loopBody f
+-- body = loopState (f curr)
+
+-- TODO: Supporting Tuples of Tuples in the loop state would be nice.
+-- Then [LExp] will not cut it anymore.
+class LoopState a where
+ loopState :: a -> [Expr] -- TODO: Again. will structure be needed?
+ loopCond :: (a -> Exp Bool) -> [Expr] -> Expr
+ loopBody :: (a -> a) -> [Expr] -> [Expr]
+-- loopVars :: a -> (a,[Variable])
+ loopFinalState :: Exp s -> a
+
+
+instance LoopState (Exp a) where
+ loopState (E e1) = [e1]
+ loopCond f [e] = let (E e') = f (E e) in e'
+ loopBody f [e] = let (E e') = f (E e) in [e']
+-- loopVars (E e1) = ((e1'),[l1v])
+-- where
+-- l1 = newLabel ()
+-- l1v = Variable ("l" ++ show l1)
+-- e1' = E $ LVar (newLabel ()) l1v
+ loopFinalState (E e) = (E e) -- deconstr then reconstr (to get type right)
+{-
+instance LoopState (Exp a,Exp b) where
+ loopState (E e1,E e2) = [e1,e2]
+-- loopVars (E e1,E e2) = ((e1',e2'),[l1v,l2v])
+-- where
+-- l1 = newLabel ()
+-- l2 = newLabel ()
+-- l1v = Variable ("l" ++ show l1)
+-- l2v = Variable ("l" ++ show l2)
+-- e1' = E $ LVar (newLabel ()) l1v
+-- e2' = E $ LVar (newLabel ()) l2v
+ loopFinalState (E e) = (E $ ResIndex e 0,
+ E $ ResIndex e 1)
+
+
+instance LoopState (Exp a,Exp b,Exp c) where
+ loopState (e1,e2,e3) = loopState e1 ++ loopState e2 ++ loopState e3
+-- loopVars (e1,e2,e3) = ((e1',e2',e3'),ls1 ++ ls2 ++ ls3 )
+-- where
+-- (e1',ls1) = loopVars e1
+-- (e2',ls2) = loopVars e2
+-- (e3',ls3) = loopVars e3
+
+ loopFinalState (E e) = (E $ ResIndex e 0,
+ E $ ResIndex e 1,
+ E $ ResIndex e 2)
+-}
{-
while :: LoopState state
=> (state -> Exp Bool)
@@ -353,8 +413,9 @@ instance LoopState (Exp a,Exp b,Exp c) where
----------------------------------------------------------------------------
-- instances
+
instance Show (Exp a) where
- show (E a) = show a
+ show (E a) = "exp"
instance Eq (Exp a) where
(==) = undefined -- compare labels here
View
@@ -72,14 +72,14 @@ data Expr = Lit Literal
-- This one might need some rework!
-- I Will not be able to generate unique variables until
-- a later stage.
- | While {-[Variable]-} Expr [Expr] [Expr]
+ | While ([Expr] -> Expr) ([Expr] -> [Expr]) [Expr]
| If Expr Expr Expr
| Op Op [Expr]
- deriving (Show)
+-- deriving (Show)
----------------------------------------------------------------------------

0 comments on commit ee6d359

Please sign in to comment.