Skip to content

Commit

Permalink
Add int-to-int Map to the LLVM integration test definition
Browse files Browse the repository at this point in the history
  • Loading branch information
geo2a committed Nov 14, 2023
1 parent c4608e8 commit 7ab269b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
20 changes: 18 additions & 2 deletions test/llvm-integration/LLVM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ llvmSpec =
it "should work with latin-1strings" $
hedgehog . propertyTest . latin1Prop

describe "LLVM hooked Map simplifications" $
it "should preserve singleton maps" $
hedgehog . propertyTest . mapKItemInjProp

--------------------------------------------------
-- individual hedgehog property tests and helpers

Expand Down Expand Up @@ -147,6 +151,18 @@ latin1Prop api = property $ do
| otherwise -> error $ "Unexpected sort " <> show s
otherTerm -> error $ "Unexpected term " <> show otherTerm

mapKItemInjProp :: Internal.API -> Property
mapKItemInjProp api = property $ do
let k = intTerm 2
let v = intTerm 2
LLVM.simplifyTerm api testDef (elem k v) (SortApp "SortMapInt2Int" []) === elem k v
where
elem k v =
SymbolApplication
(kmapElementSymbol sortMapInt2Int)
[]
[k, v]

------------------------------------------------------------

runKompile :: IO ()
Expand Down Expand Up @@ -277,7 +293,7 @@ sortMapInt2Int =
, elementSymbolName = "Lbl'Unds'Int2Int'Pipe'-'-GT-Unds'"
, concatSymbolName = "Lbl'Unds'MapInt2Int'Unds'"
}
, keySortName = "SortInt"
, keySortName = "SortWrappedInt"
, elementSortName = "SortInt"
, mapSortName = "SortMapInt2Int"
}
Expand Down Expand Up @@ -1363,7 +1379,7 @@ defSymbols =
, Symbol
{ name = "Lbl'Unds'Int2Int'Pipe'-'-GT-Unds'"
, sortVars = []
, argSorts = [SortApp "SortInt" [], SortApp "SortInt" []]
, argSorts = [SortApp "SortWrappedInt" [], SortApp "SortInt" []]
, resultSort = SortApp "SortMapInt2Int" []
, attributes =
SymbolAttributes
Expand Down
28 changes: 28 additions & 0 deletions test/llvm-integration/definition/llvm.k
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module LLVM
imports MAP
imports SET
imports K-EQUAL
imports MAP-INT2INT

syntax Num ::= Even | Odd
syntax Even ::= Zero() | Two() | Four() | Six() | Eight() | Ten()
Expand Down Expand Up @@ -39,3 +40,30 @@ module LLVM
rule div2(Ten()) => Five()

endmodule

module MAP-INT2INT
imports INT

syntax WrappedInt

syntax WrappedInt ::= wrap(Int) [symbol, klabel(wrapInt)]
syntax Int ::= unwrap(WrappedInt) [function, total, injective, symbol, klabel(unwrapInt)]
rule unwrap(wrap(A:Int)) => A

syntax MapInt2Int [hook(MAP.Map)]
syntax MapInt2Int ::= MapInt2Int MapInt2Int
[ left, function, hook(MAP.concat), klabel(_MapInt2Int_),
symbol, assoc, comm, unit(.MapInt2Int), element(_Int2Int|->_),
index(0), format(%1%n%2)
]
syntax MapInt2Int ::= ".MapInt2Int"
[ function, total, hook(MAP.unit),
klabel(.MapInt2Int), symbol, latex(\dotCt{MapInt2Int})
]
syntax MapInt2Int ::= WrappedInt "Int2Int|->" WrappedInt
[ function, total, hook(MAP.element),
klabel(_Int2Int|->_), symbol,
latex({#1}\mapsto{#2}), injective
]

endmodule

0 comments on commit 7ab269b

Please sign in to comment.