{- CSci 450: Organization of Programming Languages
   Imperative Core Language, Simple Test Harness
   Fall 2017 
   H. Conrad Cunningham

1234567890123456789012345678901234567890123456789012345678901234567890

2017-08-15: Separated from earlier Imperative Core evaluator prototype

*** This is an artifact of an earlier version of the ImpCore
    interpreter. It just did limited testing of the Evaluator. It is
    incomplete and likely does not reflect the current design.
-}

module TestImpCore
where

import ParseImpCore
import EvalImpCore
import AbSynImpCore

-- VERY limited testing to get by compiler
main =
  do
    let d01 = Val "x" (Lit 5)
    let d02 = Val "y" (Lit 7)
    let d03 = Val "z" (Lit 1)

    putStrLn ("Definition: " ++ show d01)
    putStrLn ("Evaluation: " ++ show (evalDef d01 ([],[])))
    putStrLn ""
             
    putStrLn ("Definition: " ++ show d02)
    putStrLn ("Evaluation: " ++ show (evalDef d02 ([],[])))
    putStrLn ""
             
    putStrLn ("Definition: " ++ show d03)
    putStrLn ("Evaluation: " ++ show (evalDef d03 ([],[])))
    putStrLn ""
             
    let d04 = Define "f0" [] (Lit 0)
    let d05 = Define "f2" ["x","w"] (Add (Var "x") (Var "w"))
    let s01 = [d01,d02,d03,d04,d05] 

    putStrLn ("Definition: " ++ show d04)
    putStrLn ("Evaluation: " ++ show (evalDef d04 ([],[])))
    putStrLn ""
             
    putStrLn ("Definition: " ++ show d05)
    putStrLn ("Evaluation: " ++ show (evalDef d05 ([],[])))
    putStrLn ""
             
    putStrLn ("Script: " ++ show s01)
    putStrLn ("Evaluation: " ++ show (evalScript s01 ([],[])))
    putStrLn ""

    let e06 = Lit 3                  -- 3 
    let e07 = Var "x"                -- x
    let s02 = s01 ++ [Top e07]
             
    putStrLn ("Expression: " ++ show e06)
    putStrLn ("Evaluation: " ++ show (evalScript [Top e06] ([],[])))
    putStrLn ""
     
    putStrLn ("Script: " ++ show s02)
    putStrLn ("Evaluation: " ++ show (evalScript s02 ([],[])))
    putStrLn ""

    let e08 = Add (Lit 1) (Lit 2)    -- 1+2 
    let e09 = Add (Var "x") (Lit 3)  -- x + 3

    let s03 = s01 ++ [Top e09]
             
    putStrLn ("Expression: " ++ show e08)
    putStrLn ("Evaluation: " ++ show (evalScript [Top e08] ([],[])))
    putStrLn ""
             
    putStrLn ("Script: " ++ show s03)
    putStrLn ("Evaluation: " ++ show (evalScript s03 ([],[])))
    putStrLn ""

    let e10 = Mul (Add (Var "x") (Var "y"))
                   (Add (Lit 2) (Var "z")) -- (x + y) * (2 + z)

    let s04 = s01 ++ [Top e10]
    
    putStrLn ("Script: " ++ show s04)
    putStrLn ("Evaluation: " ++ show (evalScript s04 ([],[])))
    putStrLn ""

    let e11 = Apply "f0" []
    let s05 = s01 ++ [Top e11]

    putStrLn ("Script: " ++ show s05)
    putStrLn ("Evaluation: " ++ show (evalScript s05 ([],[])))
    putStrLn ""

    let e12 = Apply "f2" [Lit 10, Lit 20]
    let s06 = s01 ++ [Top e12]

    putStrLn ("Script: " ++ show s06)
    putStrLn ("Evaluation: " ++ show (evalScript s06 ([],[])))
    putStrLn ""

    let e13 = Set "x" (Lit 100)
    let s07 = s01 ++ [Top e13]

    putStrLn ("Script: " ++ show s07)
    putStrLn ("Evaluation: " ++ show (evalScript s07 ([],[])))
    putStrLn ""
