diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2024-09-23 19:44:17 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2024-09-25 20:25:22 +0200 |
commit | 213e3523aead4c18b65ac85886203d2508b9b27e (patch) | |
tree | 6f207174a09ee312a366d0c22c08a31a056aaf3d /src/Test/Builtins.hs | |
parent | 274554243235d3013430a48973fd0f25244ac392 (diff) |
Implement "guard" as a builtin
Diffstat (limited to 'src/Test/Builtins.hs')
-rw-r--r-- | src/Test/Builtins.hs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/Test/Builtins.hs b/src/Test/Builtins.hs index 2ab38aa..b768bb9 100644 --- a/src/Test/Builtins.hs +++ b/src/Test/Builtins.hs @@ -2,12 +2,26 @@ module Test.Builtins ( builtins, ) where +import Data.Map qualified as M +import Data.Typeable + import Test builtins :: [ ( VarName, SomeVarValue ) ] builtins = - [ ( VarName "wait", builtinWait ) + [ ( VarName "guard", builtinGuard ) + , ( VarName "wait", builtinWait ) ] +getArg :: Typeable a => FunctionArguments SomeExpr -> Maybe ArgumentKeyword -> a +getArg (FunctionArguments args) kw = + case M.lookup kw args of + Just (SomeExpr expr) | Just expr' <- cast expr -> expr' + _ -> error "parameter mismatch" + +builtinGuard :: SomeVarValue +builtinGuard = SomeVarValue (FunctionArguments $ M.singleton Nothing (ExprTypePrim (Proxy @Bool))) $ + \sline args -> TestBlock [ Guard sline (getArg args Nothing) ] + builtinWait :: SomeVarValue -builtinWait = SomeVarValue mempty $ const $ TestBlock [ Wait ] +builtinWait = SomeVarValue mempty $ const . const $ TestBlock [ Wait ] |