Compiler test: expected files can be any text file.

This commit is contained in:
Andor Penzes 2019-07-26 03:36:50 +02:00
parent a3d25d6668
commit d95f5e09e0
5 changed files with 33 additions and 29 deletions

2
.gitignore vendored
View File

@ -25,3 +25,5 @@ output/
.output
.grin-output/
.vscode/
*.out

View File

@ -232,6 +232,7 @@ executable grin-test
, system-posix-redirect
, process
, bytestring
, MissingH
other-modules:
Transformations.Simplifying.RegisterIntroductionSpec
@ -316,6 +317,7 @@ executable grin-end-to-end-test
, system-posix-redirect
, process
, bytestring
, MissingH
other-modules:
Transformations.Simplifying.RegisterIntroductionSpec
Transformations.Simplifying.CaseSimplificationSpec

View File

@ -1,3 +1,4 @@
grinMain =
a0 <- pure (CInt 5)
a1 <- pure (CInt 5)
@ -5,34 +6,27 @@ grinMain =
p0 <- store a0
p1 <- store a1
p2 <- store a2
foo3 <- pure (P3foo)
pfoo3 <- store foo3
foo3ap <- pure (Fap pfoo3 p0)
foo3ap <- pure (Fap pfoo3 p0)
pfoo3ap <- store foo3ap
foo2 <- eval pfoo3ap
pfoo2 <- store foo2
foo2ap <- pure (Fap pfoo2 p1)
foo2 <- eval $ pfoo3ap
pfoo2 <- store foo2
foo2ap <- pure (Fap pfoo2 p1)
pfoo2ap <- store foo2ap
foo1 <- eval pfoo2ap
pfoo1 <- store foo1
foo1ap <- pure (Fap pfoo1 p2)
foo1 <- eval $ pfoo2ap
pfoo1 <- store foo1
foo1ap <- pure (Fap pfoo1 p2)
pfoo1ap <- store foo1ap
fooRet <- eval pfoo1ap
fooRet <- eval $ pfoo1ap
pure fooRet
foo y0 =
z0 <- pure (#undefined :: #ptr)
x0 <- pure (#undefined :: #ptr)
y0' <- eval y0
y0' <- eval $ y0
pure y0'
-- apply always gets the function node in whnf
apply pf cur =
case pf of
(P3foo) ->
@ -42,31 +36,33 @@ apply pf cur =
n1 <- pure (P1foo v0 cur)
pure n1
(P1foo v1 v2) ->
n2 <- foo v2
n2 <- foo $ v2
pure n2
ap f x =
f' <- eval f
apply f' x
f' <- eval $ f
apply $ f' x
eval p =
v <- fetch p
case v of
(CInt n) -> pure v
(P3foo) -> pure v
(P2foo v3) -> pure v
(P1foo v4 v5) -> pure v
(CInt n) ->
pure v
(P3foo) ->
pure v
(P2foo v3) ->
pure v
(P1foo v4 v5) ->
pure v
(Ffoo b0 b1 b2) ->
w0 <- foo b1
w0 <- foo $ b1
update p w0
pure w0
(Fapply g y) ->
w1 <- apply g y
w1 <- apply $ g y
update p w1
pure w1
(Fap h z) ->
w2 <- ap h z
w2 <- ap $ h z
update p w2
pure w2

View File

@ -0,0 +1,3 @@
- "--quiet"
- "--dpe"
- "--save-grin=$$$OUT$$$"

View File

@ -20,6 +20,7 @@ import Control.Exception (catch)
import qualified Data.Map as Map
import Data.Char (isDigit)
import Data.List (isSuffixOf)
import Data.String.Utils (replace)
import System.Directory
@ -51,7 +52,7 @@ evaluatePipelineTest input options expected params actionWith progressCallback =
Binary fp -> [fp, "--load-binary"]
Textual fp -> [fp]
let outFile = inputToFilePath input <.> "out"
mainWithArgs $ args ++ options ++ ["--save-grin=" ++ outFile]
mainWithArgs $ args ++ (map (replace "$$$OUT$$$" outFile) options)
content <- readFile outFile
expected <- readFile expected
if (content == expected)