-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example demonstrating array update support. Fixes #63.
This is adapted from a similar example in the upstream `copilot` repo.
- Loading branch information
1 parent
94b19e0
commit e8c5a76
Showing
3 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
copilot-verifier/examples/Copilot/Verifier/Examples/ShouldPass/UpdateArray.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{-# LANGUAGE RebindableSyntax #-} | ||
{-# LANGUAGE DataKinds #-} | ||
|
||
-- | An example showing of using @copilot-verifier@ to verify a specification | ||
-- involving arrays where individual elements are updated. | ||
module Copilot.Verifier.Examples.ShouldPass.UpdateArray where | ||
|
||
import Language.Copilot | ||
import Copilot.Compile.C99 | ||
import Copilot.Verifier ( Verbosity, VerifierOptions(..) | ||
, defaultVerifierOptions, verifyWithOptions ) | ||
|
||
spec :: Spec | ||
spec = do | ||
let pair :: Stream (Array 2 Word32) | ||
pair = extern "pair" Nothing | ||
|
||
-- Check equality, indexing into array and modifying the value. Note that | ||
-- this is trivial by equality. | ||
trigger "trig_1" | ||
(((pair !! 0 =$ (+1)) ! 0) == ((pair ! 0) + 1)) | ||
[arg pair] | ||
|
||
-- Same as previous example, but get a different array index (so should be | ||
-- false). | ||
trigger "trig_2" | ||
(((pair !! 0 =$ (+1)) ! 1) == ((pair ! 0) + 1)) | ||
[arg pair] | ||
|
||
verifySpec :: Verbosity -> IO () | ||
verifySpec verb = reify spec >>= verifyWithOptions defaultVerifierOptions{verbosity = verb} | ||
mkDefaultCSettings [] "updateArray" |