agda-spa/Main.agda
Danila Fedorin 33cc0f9fe9 Implement constant analysis
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
2025-01-05 19:39:12 -08:00

47 lines
1.3 KiB
Agda
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{-# OPTIONS --guardedness #-}
module Main where
open import Language hiding (_++_)
open import Data.Vec using (Vec; _∷_; [])
open import IO
open import Level using (0)
open import Data.String using (_++_)
import Analysis.Constant as ConstantAnalysis
import Analysis.Sign as SignAnalysis
testCode : Stmt
testCode =
"zero" (# 0) then
"pos" ((` "zero") Expr.+ (# 1)) then
"neg" ((` "zero") Expr.- (# 1)) then
"unknown" ((` "pos") Expr.+ (` "neg"))
testCodeCond₁ : Stmt
testCodeCond₁ =
"var" (# 1) then
if (` "var") then (
"var" ((` "var") Expr.+ (# 1))
) else (
"var" ((` "var") Expr.- (# 1)) then
"var" (# 1)
)
testCodeCond₂ : Stmt
testCodeCond₂ =
"var" (# 1) then
if (` "var") then (
"x" (# 1)
) else (
noop
)
testProgram : Program
testProgram = record
{ rootStmt = testCode
}
open SignAnalysis.WithProg testProgram using (analyze-correct) renaming (output to output-Sign)
open ConstantAnalysis.WithProg testProgram using (analyze-correct) renaming (output to output-Const)
main = run {0} (putStrLn (output-Const ++ "\n" ++ output-Sign))