run :: String -> IO ()
run src = do
  case parseString (runCommented $ some pDecl <* eof) mempty src of
    (Failure err) -> print err
    (Success stmts) -> mapM_ doStmt stmts
  
    where doStmt stmt = do
            putStrLn "Statement:"
            print (pretty stmt)
            
            putStrLn ("AST: " ++ show stmt)
            case (runTyp builtinBindings (inferTypes stmt)) of
              Left tyErr -> putStrLn ("Type Error: " ++ show tyErr)
              Right typed -> do
                  putStr "Type: "
                  print (pretty (typed ^. annotation._2))
                  print typed
                  
                  case (runGen (codegen typed)) of
                    Left genErr -> putStrLn ("Gen Error: " ++ show genErr)
                    Right (r, _) -> putStrLn "Gen:" >> print (CPretty.pretty (undefNode <$ r))
run :: String -> IO ()
run src = do
  case parseString (runCommented $ some pDecl <* eof) mempty src of
    (Failure err) -> print err
    (Success stmts) -> mapM_ doStmt stmts
  
    where doStmt stmt = do
            putStrLn "Statement:"
            print (pretty stmt)
            
            putStrLn ("AST: " ++ show stmt)
            case (runTyp builtinBindings (inferTypes stmt)) of
              Left tyErr -> putStrLn ("Type Error: " ++ show tyErr)
              Right typed -> do
                  putStr "Type: "
                  print (pretty (typed ^. annotation._2))
                  print typed
                  
                  case (runGen (codegen typed)) of
                    Left genErr -> putStrLn ("Gen Error: " ++ show genErr)
                    Right (r, _) -> putStrLn "Gen:" >> print (CPretty.pretty (undefNode <$ r))
run src = do
  case parseString (runCommented $ some pDecl <* eof) mempty src of
    (Failure err) -> print err
    (Success stmts) -> mapM_ doStmt stmts
  
    where doStmt stmt = do
            putStrLn "Statement:"
            print (pretty stmt)
            
            putStrLn ("AST: " ++ show stmt)
            case (runTyp builtinBindings (inferTypes stmt)) of
              Left tyErr -> putStrLn ("Type Error: " ++ show tyErr)
              Right typed -> do
                  putStr "Type: "
                  print (pretty (typed ^. annotation._2))
                  print typed
                  
                  case (runGen (codegen typed)) of
                    Left genErr -> putStrLn ("Gen Error: " ++ show genErr)
                    Right (r, _) -> putStrLn "Gen:" >> print (CPretty.pretty (undefNode <$ r))