summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-03-22 02:57:08 -0400
committerJoe Crayne <joe@jerkface.net>2019-03-22 02:57:08 -0400
commit99dfcb5d8d426c81488da9ae2c29da8a0e92733f (patch)
treeeeebaa434a2a7e179cbc2610fc6259e09785a76d
parent7ddd2d513c5ebf0ab3e015d42870fcc666be7dc4 (diff)
Propagate function environment throughout transpiling.
-rw-r--r--monkeypatch.hs103
1 files changed, 51 insertions, 52 deletions
diff --git a/monkeypatch.hs b/monkeypatch.hs
index 8ed6ada..f12552e 100644
--- a/monkeypatch.hs
+++ b/monkeypatch.hs
@@ -198,35 +198,34 @@ varmap vs = Map.fromList $ map (,()) vs
198 198
199-- Returns a list of statements bringing variables into scope and an 199-- Returns a list of statements bringing variables into scope and an
200-- expression. 200-- expression.
201-- 201grokExpression :: FunctionEnvironment
202-- TODO: FunctionEnvironment argument. 202 -> CExpression a
203grokExpression :: CExpression a
204 -> Maybe ([Computation (HS.Exp ())], Computation (HS.Exp ())) 203 -> Maybe ([Computation (HS.Exp ())], Computation (HS.Exp ()))
205grokExpression (CVar cv _) = Just $ (,) [] $ Computation 204grokExpression fe (CVar cv _) = Just $ (,) [] $ Computation
206 { compFree = Map.singleton (identToString cv) () 205 { compFree = Map.singleton (identToString cv) ()
207 , compIntro = Map.empty 206 , compIntro = Map.empty
208 , comp = hsvar (identToString cv) 207 , comp = hsvar (identToString cv)
209 } 208 }
210grokExpression (CConst (CIntConst n _)) = Just $ (,) [] $ Computation 209grokExpression fe (CConst (CIntConst n _)) = Just $ (,) [] $ Computation
211 { compFree = Map.empty 210 { compFree = Map.empty
212 , compIntro = Map.empty 211 , compIntro = Map.empty
213 , comp = Lit () (Int () (getCInteger n) (show n)) 212 , comp = Lit () (Int () (getCInteger n) (show n))
214 } 213 }
215grokExpression (CConst (CStrConst s _)) = Just $ (,) [] $ Computation 214grokExpression fe (CConst (CStrConst s _)) = Just $ (,) [] $ Computation
216 { compFree = Map.empty 215 { compFree = Map.empty
217 , compIntro = Map.empty 216 , compIntro = Map.empty
218 , comp = Lit () (HS.String () (getCString s) (getCString s)) 217 , comp = Lit () (HS.String () (getCString s) (getCString s))
219 } 218 }
220grokExpression (CBinary CNeqOp a b _) = do 219grokExpression fe (CBinary CNeqOp a b _) = do
221 (as,ca) <- grokExpression a 220 (as,ca) <- grokExpression fe a
222 (bs,cb) <- grokExpression b 221 (bs,cb) <- grokExpression fe b
223 let ss = as ++ bs -- TODO: resolve variable name conflicts 222 let ss = as ++ bs -- TODO: resolve variable name conflicts
224 return $ (,) ss $ Computation 223 return $ (,) ss $ Computation
225 { compFree = compFree ca `Map.union` compFree cb 224 { compFree = compFree ca `Map.union` compFree cb
226 , compIntro = Map.empty 225 , compIntro = Map.empty
227 , comp = infixOp (comp ca) "/=" (comp cb) 226 , comp = infixOp (comp ca) "/=" (comp cb)
228 } 227 }
229grokExpression (CUnary CAdrOp (CVar cv0 _) _) = do 228grokExpression fe (CUnary CAdrOp (CVar cv0 _) _) = do
230 let cv = identToString cv0 229 let cv = identToString cv0
231 hv = "p" ++ cv 230 hv = "p" ++ cv
232 k = uniqIdentifier "go" (Map.empty {-todo-}) 231 k = uniqIdentifier "go" (Map.empty {-todo-})
@@ -243,20 +242,20 @@ grokExpression (CUnary CAdrOp (CVar cv0 _) _) = do
243 , compIntro = Map.empty 242 , compIntro = Map.empty
244 , comp = hsvar hv 243 , comp = hsvar hv
245 } 244 }
246grokExpression (CCond cond (Just thn) els _) = do 245grokExpression fe (CCond cond (Just thn) els _) = do
247 (cs,c) <- grokExpression cond 246 (cs,c) <- grokExpression fe cond
248 (ts,t) <- grokExpression thn 247 (ts,t) <- grokExpression fe thn
249 (es,e) <- grokExpression els 248 (es,e) <- grokExpression fe els
250 let tt = foldr applyComputation t ts 249 let tt = foldr applyComputation t ts
251 ee = foldr applyComputation e es 250 ee = foldr applyComputation e es
252 return $ (,) cs $ fmap (\cnd -> If () cnd (comp tt) (comp ee)) c 251 return $ (,) cs $ fmap (\cnd -> If () cnd (comp tt) (comp ee)) c
253 { compFree = compFree ee `Map.union` compFree tt `Map.union` compFree c 252 { compFree = compFree ee `Map.union` compFree tt `Map.union` compFree c
254 } 253 }
255grokExpression (CSizeofExpr expr _) = do 254grokExpression fe (CSizeofExpr expr _) = do
256 (xs,x) <- grokExpression expr 255 (xs,x) <- grokExpression fe expr
257 return $ (,) xs $ fmap (App () (hsvar "sizeOf")) x 256 return $ (,) xs $ fmap (App () (hsvar "sizeOf")) x
258grokExpression (CCast (CDecl [CTypeSpec (CVoidType _)] [] _) expr _) = grokExpression expr 257grokExpression fe (CCast (CDecl [CTypeSpec (CVoidType _)] [] _) expr _) = (grokExpression fe) expr
259grokExpression (CCast (CDecl [ CTypeSpec (CVoidType _) ] 258grokExpression fe (CCast (CDecl [ CTypeSpec (CVoidType _) ]
260 [ ( Just (CDeclr Nothing [ CPtrDeclr [] _ ] Nothing [] _) , Nothing , Nothing) ] 259 [ ( Just (CDeclr Nothing [ CPtrDeclr [] _ ] Nothing [] _) , Nothing , Nothing) ]
261 _) 260 _)
262 (CConst (CIntConst zero _)) _) | 0 <- getCInteger zero = do 261 (CConst (CIntConst zero _)) _) | 0 <- getCInteger zero = do
@@ -265,8 +264,8 @@ grokExpression (CCast (CDecl [ CTypeSpec (CVoidType _) ]
265 , compIntro = Map.empty 264 , compIntro = Map.empty
266 , comp = hsvar "nullPtr" 265 , comp = hsvar "nullPtr"
267 } 266 }
268grokExpression (CComma exps _) = do 267grokExpression fe (CComma exps _) = do
269 gs <- mapM grokExpression exps 268 gs <- mapM (grokExpression fe) exps
270 let ss = concatMap fst gs -- TODO: resolve variable name conflicts 269 let ss = concatMap fst gs -- TODO: resolve variable name conflicts
271 cll = foldr1 (\x y -> infixFn x "seq" y) $ map (comp . snd) gs 270 cll = foldr1 (\x y -> infixFn x "seq" y) $ map (comp . snd) gs
272 frees = foldr1 Map.union (map (compFree . snd) gs) 271 frees = foldr1 Map.union (map (compFree . snd) gs)
@@ -276,8 +275,8 @@ grokExpression (CComma exps _) = do
276 , compIntro = Map.empty 275 , compIntro = Map.empty
277 , comp = cll 276 , comp = cll
278 } 277 }
279grokExpression (C.CCall (CVar fn _) exps _) = do 278grokExpression fe (C.CCall (CVar fn _) exps _) = do
280 gs <- mapM grokExpression exps 279 gs <- mapM (grokExpression fe) exps
281 let ss = concatMap fst gs -- TODO: resolve variable name conflicts 280 let ss = concatMap fst gs -- TODO: resolve variable name conflicts
282 hv = "r" ++ identToString fn 281 hv = "r" ++ identToString fn
283 cll = foldl (App ()) (hsvar (identToString fn)) $ map (comp . snd) gs 282 cll = foldl (App ()) (hsvar (identToString fn)) $ map (comp . snd) gs
@@ -295,12 +294,12 @@ grokExpression (C.CCall (CVar fn _) exps _) = do
295 , compIntro = Map.empty 294 , compIntro = Map.empty
296 , comp = hsvar hv 295 , comp = hsvar hv
297 } 296 }
298grokExpression (CStatExpr (CCompound idents xs _) _) = do 297grokExpression fe (CStatExpr (CCompound idents xs _) _) = do
299 let (y,ys) = splitAt 1 (reverse xs) 298 let (y,ys) = splitAt 1 (reverse xs)
300 y' <- case y of 299 y' <- case y of
301 [CBlockStmt (CExpr mexp ni)] -> Just $ CBlockStmt (CReturn mexp ni) 300 [CBlockStmt (CExpr mexp ni)] -> Just $ CBlockStmt (CReturn mexp ni)
302 _ -> Just (head y) -- Nothing FIXME 301 _ -> Just (head y) -- Nothing FIXME
303 gs <- mapM grokStatement (reverse $ y' : ys) 302 gs <- mapM (grokStatement fe) (reverse $ y' : ys)
304 let s0 = foldr applyComputation (Computation Map.empty Map.empty (App () (hsvar "return") hsopUnit)) gs 303 let s0 = foldr applyComputation (Computation Map.empty Map.empty (App () (hsvar "return") hsopUnit)) gs
305 s1 = fmap (\xp -> Paren () xp) s0 304 s1 = fmap (\xp -> Paren () xp) s0
306 hv = uniqIdentifier "ret" (compFree s1) 305 hv = uniqIdentifier "ret" (compFree s1)
@@ -317,23 +316,24 @@ grokExpression (CStatExpr (CCompound idents xs _) _) = do
317 , compIntro = Map.empty 316 , compIntro = Map.empty
318 , comp = hsvar hv 317 , comp = hsvar hv
319 } 318 }
320grokExpression _ = Nothing 319grokExpression fe _ = Nothing
321 320
322 321
323grokInitialization :: Foldable t1 => 322grokInitialization :: Foldable t1 =>
324 t1 (CDeclarationSpecifier t2) 323 FunctionEnvironment
324 -> t1 (CDeclarationSpecifier t2)
325 -> (Maybe (CDeclarator a1), CInitializer a2) 325 -> (Maybe (CDeclarator a1), CInitializer a2)
326 -> Maybe (Computation (HS.Exp ())) 326 -> Maybe (Computation (HS.Exp ()))
327grokInitialization _ (Just (CDeclr (Just cv0) _ _ _ _),CInitExpr exp _) = do 327grokInitialization fe _ (Just (CDeclr (Just cv0) _ _ _ _),CInitExpr exp _) = do
328 let v = identToString cv0 328 let v = identToString cv0
329 (xs,x) <- grokExpression exp 329 (xs,x) <- grokExpression fe exp
330 let hsexp = fmap (App () (hsvar "return")) x -- Paren () ( 330 let hsexp = fmap (App () (hsvar "return")) x -- Paren () (
331 ret = flip (foldr applyComputation) xs $ 331 ret = flip (foldr applyComputation) xs $
332 fmap (\exp -> infixOp exp ">>=" 332 fmap (\exp -> infixOp exp ">>="
333 $ Lambda () [hspvar v] (hsvar k)) hsexp 333 $ Lambda () [hspvar v] (hsvar k)) hsexp
334 k = uniqIdentifier "go" (compFree ret) 334 k = uniqIdentifier "go" (compFree ret)
335 return $ fmap (\exp -> Lambda () [hspvar k] exp) ret 335 return $ fmap (\exp -> Lambda () [hspvar k] exp) ret
336grokInitialization ts (Just (CDeclr (Just cv0) _ _ _ _),CInitList exps _) = do 336grokInitialization fe ts (Just (CDeclr (Just cv0) _ _ _ _),CInitList exps _) = do
337 let v = identToString cv0 337 let v = identToString cv0
338 -- let k = uniqIdentifier "go" (varmap [v]) 338 -- let k = uniqIdentifier "go" (varmap [v])
339 case lefts $ concatMap hsTypeSpec ts of 339 case lefts $ concatMap hsTypeSpec ts of
@@ -343,7 +343,7 @@ grokInitialization ts (Just (CDeclr (Just cv0) _ _ _ _),CInitList exps _) = do
343 gs <- do 343 gs <- do
344 forM exps $ \(ms,initexpr) -> do 344 forM exps $ \(ms,initexpr) -> do
345 case initexpr of 345 case initexpr of
346 CInitExpr ie _ -> grokExpression ie >>= \g -> return (ms,g) 346 CInitExpr ie _ -> (grokExpression fe) ie >>= \g -> return (ms,g)
347 _ -> Nothing 347 _ -> Nothing
348 let assigns = do 348 let assigns = do
349 (ms,(ss,x)) <- gs 349 (ms,(ss,x)) <- gs
@@ -374,17 +374,16 @@ grokInitialization ts (Just (CDeclr (Just cv0) _ _ _ _),CInitList exps _) = do
374 ret = foldr applyComputation (Computation Map.empty Map.empty (hsvar k)) $ newstruct : assigns 374 ret = foldr applyComputation (Computation Map.empty Map.empty (hsvar k)) $ newstruct : assigns
375 return $ fmap (\exp -> Lambda () [hspvar k] exp) ret 375 return $ fmap (\exp -> Lambda () [hspvar k] exp) ret
376 _ -> Nothing 376 _ -> Nothing
377grokInitialization _ _ = Nothing 377grokInitialization _ _ _ = Nothing
378 378
379 379
380-- TODO: FunctionEnvironment argument. 380grokStatement :: FunctionEnvironment -> CCompoundBlockItem a -> Maybe (Computation (HS.Exp ()))
381grokStatement :: CCompoundBlockItem a -> Maybe (Computation (HS.Exp ())) 381grokStatement fe (CBlockStmt (CReturn (Just exp) _)) = do
382grokStatement (CBlockStmt (CReturn (Just exp) _)) = do 382 (xs,x) <- grokExpression fe exp
383 (xs,x) <- grokExpression exp
384 let k = uniqIdentifier "go" (compFree x `Map.union` compIntro x) 383 let k = uniqIdentifier "go" (compFree x `Map.union` compIntro x)
385 x' = fmap (\y -> App () (hsvar "return") y) x 384 x' = fmap (\y -> App () (hsvar "return") y) x
386 return $ fmap (\y -> Lambda () [hspvar k] y) $ foldr applyComputation x' xs 385 return $ fmap (\y -> Lambda () [hspvar k] y) $ foldr applyComputation x' xs
387grokStatement (CBlockStmt (CExpr (Just (C.CCall (CVar (C.Ident "__assert_fail" _ _) _) xs _)) _)) = do 386grokStatement fe (CBlockStmt (CExpr (Just (C.CCall (CVar (C.Ident "__assert_fail" _ _) _) xs _)) _)) = do
388 x <- case xs of 387 x <- case xs of
389 (CConst (CStrConst msg _):_) -> let s = getCString msg 388 (CConst (CStrConst msg _):_) -> let s = getCString msg
390 in Just $ Computation Map.empty Map.empty (Lit () (HS.String () s s)) 389 in Just $ Computation Map.empty Map.empty (Lit () (HS.String () s s))
@@ -392,10 +391,10 @@ grokStatement (CBlockStmt (CExpr (Just (C.CCall (CVar (C.Ident "__assert_fail" _
392 let k = uniqIdentifier "go" (compFree x `Map.union` compIntro x) 391 let k = uniqIdentifier "go" (compFree x `Map.union` compIntro x)
393 x' = fmap (\y -> App () (hsvar "error") y) x 392 x' = fmap (\y -> App () (hsvar "error") y) x
394 return $ fmap (\y -> Lambda () [hspvar k] y) x' 393 return $ fmap (\y -> Lambda () [hspvar k] y) x'
395grokStatement (CBlockStmt (CExpr (Just 394grokStatement fe (CBlockStmt (CExpr (Just
396 (CAssign CAssignOp 395 (CAssign CAssignOp
397 (CMember cvar fld isptr _) expr _)) _)) = do 396 (CMember cvar fld isptr _) expr _)) _)) = do
398 (xs,x) <- grokExpression expr 397 (xs,x) <- grokExpression fe expr
399 v <- cvarName cvar 398 v <- cvarName cvar
400 let fieldlbl = identToString fld 399 let fieldlbl = identToString fld
401 k1 = uniqIdentifier "go" (compFree x) 400 k1 = uniqIdentifier "go" (compFree x)
@@ -408,10 +407,10 @@ grokStatement (CBlockStmt (CExpr (Just
408 fieldinit) ">>" (hsvar k1) 407 fieldinit) ">>" (hsvar k1)
409 } 408 }
410 return $ fmap (\y -> Lambda () [hspvar k1] y) $ foldr applyComputation x' xs 409 return $ fmap (\y -> Lambda () [hspvar k1] y) $ foldr applyComputation x' xs
411grokStatement (CBlockStmt (CExpr (Just 410grokStatement fe (CBlockStmt (CExpr (Just
412 (C.CCall cvarfun exps _)) _)) = do 411 (C.CCall cvarfun exps _)) _)) = do
413 fn <- cvarName cvarfun 412 fn <- cvarName cvarfun
414 gs <- mapM grokExpression exps 413 gs <- mapM (grokExpression fe) exps
415 let k = uniqIdentifier "go" frees 414 let k = uniqIdentifier "go" frees
416 cll = foldl (App ()) (hsvar fn) $ map (comp . snd) gs 415 cll = foldl (App ()) (hsvar fn) $ map (comp . snd) gs
417 frees = foldr Map.union (Map.singleton fn ()) (map (compFree . snd) gs) 416 frees = foldr Map.union (Map.singleton fn ()) (map (compFree . snd) gs)
@@ -422,7 +421,7 @@ grokStatement (CBlockStmt (CExpr (Just
422 , comp = infixOp cll ">>" (hsvar k) 421 , comp = infixOp cll ">>" (hsvar k)
423 } 422 }
424 return $ fmap (Lambda () [hspvar k]) x 423 return $ fmap (Lambda () [hspvar k]) x
425grokStatement (CBlockStmt (CExpr (Just 424grokStatement fe (CBlockStmt (CExpr (Just
426 (CAssign CAssignOp cvarnew 425 (CAssign CAssignOp cvarnew
427 (C.CCall cvarfun [] _) _)) _)) = do 426 (C.CCall cvarfun [] _) _)) _)) = do
428 v <- cvarName cvarnew 427 v <- cvarName cvarnew
@@ -435,8 +434,8 @@ grokStatement (CBlockStmt (CExpr (Just
435 $ infixOp (hsvar fn) ">>=" 434 $ infixOp (hsvar fn) ">>="
436 $ Lambda () [hspvar v] (hsvar k) 435 $ Lambda () [hspvar v] (hsvar k)
437 } 436 }
438grokStatement (CBlockStmt (CIf exp thn els _)) = do 437grokStatement fe (CBlockStmt (CIf exp thn els _)) = do
439 (xs,x) <- grokExpression exp 438 (xs,x) <- grokExpression fe exp
440 let mkif0 = If () (comp x) 439 let mkif0 = If () (comp x)
441 (mkif,stmts) <- case (thn,els) of 440 (mkif,stmts) <- case (thn,els) of
442 441
@@ -451,7 +450,7 @@ grokStatement (CBlockStmt (CIf exp thn els _)) = do
451 450
452 _ -> Nothing -- TODO 451 _ -> Nothing -- TODO
453 452
454 ss <- sequence $ map grokStatement stmts 453 ss <- sequence $ map (grokStatement fe) stmts
455 let s = foldr applyComputation (Computation Map.empty Map.empty (hsvar k)) ss 454 let s = foldr applyComputation (Computation Map.empty Map.empty (hsvar k)) ss
456 k = uniqIdentifier "go" (Map.union (compFree x) (compFree s)) 455 k = uniqIdentifier "go" (Map.union (compFree x) (compFree s))
457 return $ flip (foldr applyComputation) xs Computation 456 return $ flip (foldr applyComputation) xs Computation
@@ -459,7 +458,7 @@ grokStatement (CBlockStmt (CIf exp thn els _)) = do
459 , compIntro = compIntro s 458 , compIntro = compIntro s
460 , comp = Lambda () [hspvar k] $ mkif (comp s) (hsvar k) 459 , comp = Lambda () [hspvar k] $ mkif (comp s) (hsvar k)
461 } 460 }
462grokStatement (CBlockStmt (CExpr (Just (CUnary CPostIncOp (CMember (CVar cv0 _) fld True _) _)) _)) = do 461grokStatement fe (CBlockStmt (CExpr (Just (CUnary CPostIncOp (CMember (CVar cv0 _) fld True _) _)) _)) = do
463 let k1 = uniqIdentifier "go" (varmap [fieldlbl,v]) 462 let k1 = uniqIdentifier "go" (varmap [fieldlbl,v])
464 fieldlbl = identToString fld 463 fieldlbl = identToString fld
465 v = identToString cv0 464 v = identToString cv0
@@ -473,13 +472,13 @@ grokStatement (CBlockStmt (CExpr (Just (CUnary CPostIncOp (CMember (CVar cv0 _)
473 (hsvar v)) 472 (hsvar v))
474 (hsvar "succ")) ">>" (hsvar k1) 473 (hsvar "succ")) ">>" (hsvar k1)
475 } 474 }
476grokStatement (CBlockStmt (CExpr mexpr _)) = do 475grokStatement fe (CBlockStmt (CExpr mexpr _)) = do
477 (ss,pre) <- maybe (Just $ (,) [] $ Computation Map.empty Map.empty id) 476 (ss,pre) <- maybe (Just $ (,) [] $ Computation Map.empty Map.empty id)
478 (fmap (second (fmap (\e -> infixFn e "seq"))) . grokExpression) mexpr 477 (fmap (second (fmap (\e -> infixFn e "seq"))) . grokExpression fe) mexpr
479 let k = uniqIdentifier "go" (compFree s) 478 let k = uniqIdentifier "go" (compFree s)
480 s = foldr applyComputation (fmap ($ hsvar k) pre) ss 479 s = foldr applyComputation (fmap ($ hsvar k) pre) ss
481 return $ fmap (Lambda () [hspvar k]) s 480 return $ fmap (Lambda () [hspvar k]) s
482grokStatement (CBlockDecl (CDecl (t:ts) (v:vs) _)) = do 481grokStatement fe (CBlockDecl (CDecl (t:ts) (v:vs) _)) = do
483 -- case mapMaybe (\(cdeclr,_,_) -> cdeclr >>= \(CDeclr i _ initial _ _) -> initial) (v:vs) of 482 -- case mapMaybe (\(cdeclr,_,_) -> cdeclr >>= \(CDeclr i _ initial _ _) -> initial) (v:vs) of
484 -- case mapMaybe (\(cdeclr,_,_) -> cdeclr >>= \(CInitList xs _) -> Just xs) (v:vs) of 483 -- case mapMaybe (\(cdeclr,_,_) -> cdeclr >>= \(CInitList xs _) -> Just xs) (v:vs) of
485 case mapMaybe (\(i,inits,_) -> fmap ((,) i) inits) (v:vs) of 484 case mapMaybe (\(i,inits,_) -> fmap ((,) i) inits) (v:vs) of
@@ -490,10 +489,10 @@ grokStatement (CBlockDecl (CDecl (t:ts) (v:vs) _)) = do
490 , comp = Lambda () [hspvar "go"] $ hsvar "go" 489 , comp = Lambda () [hspvar "go"] $ hsvar "go"
491 } 490 }
492 initials -> do 491 initials -> do
493 gs <- mapM (grokInitialization $ t:ts) initials 492 gs <- mapM (grokInitialization fe $ t:ts) initials
494 return $ fmap (\exp -> Lambda () [hspvar "go"] exp) 493 return $ fmap (\exp -> Lambda () [hspvar "go"] exp)
495 $ foldr applyComputation (Computation Map.empty Map.empty (hsvar "go")) gs 494 $ foldr applyComputation (Computation Map.empty Map.empty (hsvar "go")) gs
496grokStatement _ = Nothing 495grokStatement fe _ = Nothing
497 496
498isFunctionDecl :: CExternalDeclaration a -> Bool 497isFunctionDecl :: CExternalDeclaration a -> Bool
499isFunctionDecl (CDeclExt (CDecl _ [(Just (CDeclr _ [CFunDeclr _ _ _] _ _ _),_,_)] _)) = True 498isFunctionDecl (CDeclExt (CDecl _ [(Just (CDeclr _ [CFunDeclr _ _ _] _ _ _),_,_)] _)) = True
@@ -614,7 +613,7 @@ transpile o fname incs (CTranslUnit edecls _) = do
614 forM_ bdy $ \d -> putStrLn $ ppShow $ cleanTree d 613 forM_ bdy $ \d -> putStrLn $ ppShow $ cleanTree d
615 else do 614 else do
616 let mhask = do 615 let mhask = do
617 xs <- mapM grokStatement bdy 616 xs <- mapM (grokStatement fe) bdy
618 return $ foldr applyComputation (Computation Map.empty Map.empty hsopUnit) xs 617 return $ foldr applyComputation (Computation Map.empty Map.empty hsopUnit) xs
619 case mhask of 618 case mhask of
620 Just hask -> do printHeader 619 Just hask -> do printHeader
@@ -623,7 +622,7 @@ transpile o fname incs (CTranslUnit edecls _) = do
623 printHeader 622 printHeader
624 forM_ bdy $ \d -> do 623 forM_ bdy $ \d -> do
625 putStrLn $ " C: " ++ show (pretty d) 624 putStrLn $ " C: " ++ show (pretty d)
626 case grokStatement d of 625 case grokStatement fe d of
627 626
628 Just hd -> do putStrLn $ "fr: " ++ intercalate " " (Map.keys (compFree hd)) 627 Just hd -> do putStrLn $ "fr: " ++ intercalate " " (Map.keys (compFree hd))
629 putStrLn $ "HS: " ++ HS.prettyPrint (comp hd) 628 putStrLn $ "HS: " ++ HS.prettyPrint (comp hd)