summaryrefslogtreecommitdiff
path: root/src/Test/Builtins.hs
blob: b768bb925ac53c55f01fa6dfbe0d0d6d783ad9dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module Test.Builtins (
    builtins,
) where

import Data.Map qualified as M
import Data.Typeable

import Test

builtins :: [ ( VarName, SomeVarValue ) ]
builtins =
    [ ( 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 . const $ TestBlock [ Wait ]