module Main where

import AST
import Eval (eval)
import Parser (parseProgram)
import System.Environment (getArgs)

env :: Env
env = [ ("succ", ValFun (\(ValInt n) -> ValInt (n + 1)))
      , ("equal", ValFun (\ (ValInt n) -> ValFun (\ (ValInt m) -> ValBool (n == m))))
      , ("add", ValFun (\ (ValInt n) -> ValFun (\ (ValInt m) -> ValInt (n + m))))
      , ("minus", ValFun (\ (ValInt n) -> ValFun (\ (ValInt m) -> ValInt (n - m))))
      ]


main :: IO ()
main = do
  args <- getArgs
  case args of
    [filename] -> do
      input <- readFile filename
      case parseProgram input of
        Left err -> putStrLn $ "Error: " ++ show err
        Right exp -> do
          putStrLn $ "Parsed expression: " ++ show exp
          let val = eval exp env
          putStrLn $ "Evaluated value: " ++ show val
    _ -> putStrLn "Usage: interp1 <filename>"