git @ Cat's Eye Technologies Turmac / 1293c93
Push buildProgram further down. Chris Pressey 3 months ago
2 changed file(s) with 5 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
33
44 import Language.Turmac.Model
55 import Language.Turmac.IR
6 import Language.Turmac.IRCompiler
67
7 compileToPython :: Prog -> String
8 compileToPython prog = unlines [
8 compileToPython :: [TMRule] -> String
9 compileToPython tmRules = let prog = buildProgram tmRules in unlines [
910 "class Tape:",
1011 " def __init__(self, initial_input=None):",
1112 " self.left_cells = []",
6161 else Right $ rules
6262 parse False input = Right $ parseRules input
6363
64 compileTo :: String -> ([TMRule] -> String)
6465 compileTo "python" = compileToPython
6566 compileTo _ = error "--backend must be given when compiling, and must be one of: 'python'"
6667
109110 turmacText <- readFile fileName
110111 case parse (checkComplete flags) turmacText of
111112 Right tmRules -> do
112 putStr $ compileTo (backend flags) $ buildProgram tmRules
113 putStr $ compileTo (backend flags) tmRules
113114 exitWith ExitSuccess
114115
115116 Left errMsg -> do