diff options
author | Péter Diviánszky <divipp@gmail.com> | 2016-02-20 00:57:47 +0100 |
---|---|---|
committer | Péter Diviánszky <divipp@gmail.com> | 2016-02-20 01:29:27 +0100 |
commit | 453a0839d7d4c2c83b4b74031c3e073495092b53 (patch) | |
tree | 39556507a0015cb2f1ca4c9e7a8bd291e4a81ab5 /src/LambdaCube | |
parent | 5aa600a7b2772524761a5992d9f5f052dda457a0 (diff) |
fix typo & refactoring
Diffstat (limited to 'src/LambdaCube')
-rw-r--r-- | src/LambdaCube/Compiler/CoreToIR.hs | 2 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Infer.hs | 22 |
2 files changed, 12 insertions, 12 deletions
diff --git a/src/LambdaCube/Compiler/CoreToIR.hs b/src/LambdaCube/Compiler/CoreToIR.hs index 3a63ffb8..a392b1ba 100644 --- a/src/LambdaCube/Compiler/CoreToIR.hs +++ b/src/LambdaCube/Compiler/CoreToIR.hs | |||
@@ -42,7 +42,7 @@ import Paths_lambdacube_compiler (version) | |||
42 | 42 | ||
43 | compilePipeline :: IR.Backend -> ExpType -> IR.Pipeline | 43 | compilePipeline :: IR.Backend -> ExpType -> IR.Pipeline |
44 | compilePipeline backend exp = IR.Pipeline | 44 | compilePipeline backend exp = IR.Pipeline |
45 | { IR.info = "generated by lambdcube-compiler " ++ showVersion version | 45 | { IR.info = "generated by lambdacube-compiler " ++ showVersion version |
46 | , IR.backend = backend | 46 | , IR.backend = backend |
47 | , IR.samplers = mempty | 47 | , IR.samplers = mempty |
48 | , IR.programs = Vector.fromList . map fst . sortBy (compare `on` snd) . Map.toList $ programs | 48 | , IR.programs = Vector.fromList . map fst . sortBy (compare `on` snd) . Map.toList $ programs |
diff --git a/src/LambdaCube/Compiler/Infer.hs b/src/LambdaCube/Compiler/Infer.hs index cd90acc2..c43fc8ff 100644 --- a/src/LambdaCube/Compiler/Infer.hs +++ b/src/LambdaCube/Compiler/Infer.hs | |||
@@ -1213,10 +1213,16 @@ listTypeInfos m = map (second Set.toList) $ Map.toList $ Map.unionsWith (<>) [Ma | |||
1213 | 1213 | ||
1214 | -------------------------------------------------------------------------------- inference for statements | 1214 | -------------------------------------------------------------------------------- inference for statements |
1215 | 1215 | ||
1216 | inference :: MonadFix m => [Stmt] -> IM m [GlobalEnv] | ||
1217 | inference [] = return [] | ||
1218 | inference (x:xs) = do | ||
1219 | y <- handleStmt x | ||
1220 | (y:) <$> withEnv y (inference xs) | ||
1221 | |||
1216 | modn = 0 | 1222 | modn = 0 |
1217 | 1223 | ||
1218 | handleStmt :: MonadFix m => [Stmt] -> Stmt -> IM m GlobalEnv | 1224 | handleStmt :: MonadFix m => Stmt -> IM m GlobalEnv |
1219 | handleStmt defs = \case | 1225 | handleStmt = \case |
1220 | Primitive n (trSExp' -> t_) -> do | 1226 | Primitive n (trSExp' -> t_) -> do |
1221 | t <- inferType =<< ($ t_) <$> addF | 1227 | t <- inferType =<< ($ t_) <$> addF |
1222 | tellType (fst n) t | 1228 | tellType (fst n) t |
@@ -1522,20 +1528,14 @@ getList _ = Nothing | |||
1522 | mfix' f = ExceptT (mfix (runExceptT . f . either bomb id)) | 1528 | mfix' f = ExceptT (mfix (runExceptT . f . either bomb id)) |
1523 | where bomb e = error $ "mfix (ExceptT): inner computation returned Left value:\n" ++ show e | 1529 | where bomb e = error $ "mfix (ExceptT): inner computation returned Left value:\n" ++ show e |
1524 | 1530 | ||
1525 | inference_ :: PolyEnv -> Extensions -> [Stmt] -> ExceptT ErrorMsg (WriterT Infos Identity) PolyEnv | 1531 | inference_ :: MonadFix m => PolyEnv -> Extensions -> [Stmt] -> ExceptT ErrorMsg (WriterT Infos m) PolyEnv |
1526 | inference_ (PolyEnv pe is _) exts defs = mapExceptT (ff . runWriter . flip runReaderT (exts, mempty)) $ gg (handleStmt defs) (initEnv <> pe) defs | 1532 | inference_ (PolyEnv pe is _) exts defs = mapExceptT (ff <=< runWriterT . flip runReaderT (exts, initEnv <> pe)) $ inference defs |
1527 | where | 1533 | where |
1528 | ff (Left e, is) = do | 1534 | ff (Left e, is) = do |
1529 | tell is | 1535 | tell is |
1530 | return $ Left e | 1536 | return $ Left e |
1531 | ff (Right ge, is) = do | 1537 | ff (Right ge, is) = do |
1532 | return $ Right $ PolyEnv ge is $ mkDesugarInfo defs | 1538 | return $ Right $ PolyEnv (mconcat ge) is $ mkDesugarInfo defs |
1533 | |||
1534 | gg _ acc [] = return acc | ||
1535 | gg m acc (x:xs) = do | ||
1536 | y <- withEnv acc $ m x | ||
1537 | gg m (acc <> y) xs | ||
1538 | |||
1539 | 1539 | ||
1540 | foldlrev f = foldr (flip f) | 1540 | foldlrev f = foldr (flip f) |
1541 | 1541 | ||