/-
Port of `Main.agda`. Prints the constant- and sign-analysis results for the
test program (Agda: `putStrLn (output-Const ++ "\n" ++ output-Sign)`).
-/
import Spa.Analysis.Sign
import Spa.Analysis.Constant

namespace Spa

/-- Agda: `testCode`. -/
def testCode : Stmt :=
  .andThen (.basic (.assign "zero" (.num 0)))
    (.andThen (.basic (.assign "pos" (.add (.var "zero") (.num 1))))
      (.andThen (.basic (.assign "neg" (.sub (.var "zero") (.num 1))))
        (.basic (.assign "unknown" (.add (.var "pos") (.var "neg"))))))

/-- Agda: `testCodeCond₁`. -/
def testCodeCond₁ : Stmt :=
  .andThen (.basic (.assign "var" (.num 1)))
    (.ifElse (.var "var")
      (.basic (.assign "var" (.add (.var "var") (.num 1))))
      (.andThen (.basic (.assign "var" (.sub (.var "var") (.num 1))))
        (.basic (.assign "var" (.num 1)))))

/-- Agda: `testCodeCond₂`. -/
def testCodeCond₂ : Stmt :=
  .andThen (.basic (.assign "var" (.num 1)))
    (.ifElse (.var "var")
      (.basic (.assign "x" (.num 1)))
      (.basic .noop))

/-- Agda: `testProgram`. -/
def testProgram : Program := ⟨testCode⟩

end Spa

/-- Agda: `main`. -/
def main : IO Unit :=
  IO.println (Spa.ConstAnalysis.output Spa.testProgram ++ "\n" ++
              Spa.SignAnalysis.output Spa.testProgram)
