Skip to content

Commit

Permalink
Use nockma AST in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcadman committed Oct 10, 2024
1 parent ad14329 commit 21d43ae
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/Juvix/Compiler/Nockma/Translation/FromTree.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ module Juvix.Compiler.Nockma.Translation.FromTree
emptyCompilerCtx,
CompilerCtx (..),
stdlibCurry,
IndexTupleArgs (..),
indexTuple,
)
where

Expand Down
34 changes: 27 additions & 7 deletions test/Nockma/Eval/Positive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,31 @@ test = testWithStorage []

--- A Nock formula that computes logical and
nockAnd :: Term Natural
nockAnd = [nock| [6 [0 12] [6 [0 13] [1 0] [1 1]] [1 1]] |]
nockAnd =
OpIf
# (OpAddress # argPath 0)
# ( OpIf
# (OpAddress # argPath 1)
# nockTrueLiteral
# nockFalseLiteral
)
# nockFalseLiteral
where
argPath :: Natural -> Path
argPath idx =
closurePath ArgsTuple
++ indexTuple
( IndexTupleArgs
{ _indexTupleArgsIndex = idx,
_indexTupleArgsLength = funArity
}
)
funArity :: Natural
funArity = 2

--- A nock function that computes logical and
nockAndArgs :: Term Natural
nockAndArgs = nockAnd # args # env
nockAndFun :: Term Natural
nockAndFun = nockAnd # args # env
where
arg :: Term Natural
arg = nockNilTagged "placeholder argument"
Expand Down Expand Up @@ -223,10 +243,10 @@ anomaCallingConventionTests =
anomaTestM "(and true false) == false" (return nockAnd) [nockTrueLiteral, nockFalseLiteral] (eqNock [nock| false |]),
anomaTestM "(and true true) == true" (return nockAnd) [nockTrueLiteral, nockTrueLiteral] (eqNock [nock| true |]),
--- test curry with and
anomaTestM "(curry and true) false == false" (applyFun <$> stdlibCurry (OpQuote # nockAndArgs) nockTrueLiteral) [nockFalseLiteral] (eqNock [nock| false |]),
anomaTestM "(curry and true) true == true" (applyFun <$> stdlibCurry (OpQuote # nockAndArgs) nockTrueLiteral) [nockTrueLiteral] (eqNock [nock| true |]),
anomaTestM "(curry and false) true == false" (applyFun <$> stdlibCurry (OpQuote # nockAndArgs) nockFalseLiteral) [nockTrueLiteral] (eqNock [nock| false |]),
anomaTestM "(curry and false) false == false" (applyFun <$> stdlibCurry (OpQuote # nockAndArgs) nockFalseLiteral) [nockFalseLiteral] (eqNock [nock| false |])
anomaTestM "(curry and true) false == false" (applyFun <$> stdlibCurry (OpQuote # nockAndFun) nockTrueLiteral) [nockFalseLiteral] (eqNock [nock| false |]),
anomaTestM "(curry and true) true == true" (applyFun <$> stdlibCurry (OpQuote # nockAndFun) nockTrueLiteral) [nockTrueLiteral] (eqNock [nock| true |]),
anomaTestM "(curry and false) true == false" (applyFun <$> stdlibCurry (OpQuote # nockAndFun) nockFalseLiteral) [nockTrueLiteral] (eqNock [nock| false |]),
anomaTestM "(curry and false) false == false" (applyFun <$> stdlibCurry (OpQuote # nockAndFun) nockFalseLiteral) [nockFalseLiteral] (eqNock [nock| false |])
]

serializationTests :: [Test]
Expand Down

0 comments on commit 21d43ae

Please sign in to comment.