Skip to content

Commit

Permalink
Add tests for list-like constructor allocation and case
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcadman committed Jan 24, 2024
1 parent 54bf503 commit 526c4ca
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/Nockma/Compile/Positive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,39 @@ tests =
(builtinFalse, pop >> pushNat 5),
(builtinFalse, crash)
],
defTest
"cmdCase: case on listy nil"
(eqStack ValueStack [nock| [5 nil] |])
$ do
allocConstr (constructorTag ConstructorListNil)
caseCmd
(Just (pushNat 0))
[ (constructorTag ConstructorListCons, pushNat 0),
(constructorTag ConstructorListNil, pop >> pushNat 5),
(constructorTag ConstructorListCons, crash)
],
defTest
"cmdCase: case on listy cons and field accessor"
(eqStack ValueStack [nock| [[60 30 nil] nil] |])
$ do
let tagCons = constructorTag ConstructorListCons
tagNil = constructorTag ConstructorListNil
allocConstr tagNil
pushNat 30
allocConstr tagCons
caseCmd
Nothing
[ ( tagCons,
do
copyTopFromTo ValueStack TempStack
pushConstructorFieldOnto ValueStack tagCons (Asm.mkTempRef' 1 0) 0
pushConstructorFieldOnto ValueStack tagCons (Asm.mkTempRef' 1 0) 0
add
allocConstr tagCons
),
(tagNil, pop >> pushNat 5),
(tagCons, crash)
],
defTest
"push constructor field"
(eqStack AuxStack [nock| [30 nil] |])
Expand Down

0 comments on commit 526c4ca

Please sign in to comment.