module RecMain where import Language.Haskell.Pretty import Target import RecType import RecParser import RecCompiler primitives = map (\ n -> (n, mkOp n)) ["**", "*", "+", "-", "++", ":", "==", "/=", "<", "<=", ">=", ">"] ++ map (\ n -> (n, mkOp n)) ["/", "%", "//"] ++ map (\ n -> (n, mkPrimN 2 n)) ["try","append", "set"] ++ map (\ n -> (n, mkPrimN 1 n)) ["get", "writeStr", "write"] ++ map (\ n -> (n, mkPrimN 0 n)) ["readChar", "eof"] ++ map (\ n -> (n, mkPureN 1 n)) ["not","null", "head", "tail", "show", "atoi", "atof"] test useDo prog = prettyPrint $ translateToHs useDo $ removeSugar False $ simplify $ instOnce primitives $ deBruijn $ comp $ myParse prog testDecls useDo prog = concat $ map (\ str -> str ++ "\n") $ map prettyPrint $ translateToHsDecls useDo $ removeSugarDecls False $ simplifyDecls $ instOnceDecls primitives $ deBruijnDecls $ compDecls $ myParseDecls prog utilFactDecl = "fact = \\ n -> if n==0 then 1 else n*fact(n-1)" utilFact = "let " ++ utilFactDecl ++ " in fact 9" utilSTFactDecl = unlines [ "fact = \\ n ->" , " begin" , " set xP 1;" , " set yP n;" , " while get yP > 0 do" , " begin" , " set xP (get xP * get yP);" , " set yP (get yP - 1)" , " end;" , " get xP" , " end" ] utilSTFact = "let " ++ utilSTFactDecl ++ "in fact 9" utilIOTestDecl = unlines [ "foo = \\ n -> begin" , " set xP n;" , " while get xP > 0 do begin" , " write (get xP % 10);" , " set xP (get xP // 10)" , " end" , "end" ] utilIOTest = "let " ++ utilIOTestDecl ++ "in foo 1234" -- for example, -- putStrLn $ test False utilFact -- putStrLn $ test False utilSTFact -- putStrLn $ test False utilIOTest