git.haldean.org del / 30e5126 src / Language / Del / Builtins.hs
30e5126

Tree @30e5126 (Download .tar.gz)

Builtins.hs @30e5126raw · history · blame

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}

module Language.Del.Builtins where

import           Control.Lens
import qualified Data.Map.Strict as Map
import qualified Data.Text as T
import           Language.Del.TypeTable

data Builtin = Builtin {
    _defname :: T.Text,
    _deftype :: Type
}
makeLenses ''Builtin
makeBuiltin :: T.Text -> Type -> Builtin
makeBuiltin n t = Builtin { _defname = n, _deftype = t }

getType :: Builtin -> Type
getType = view deftype

blist :: [Builtin]
blist = --[ Builtin "rgb" (FuncType [FloatType, FloatType, FloatType] ColorType)
        [ Builtin "gray" (FuncType [FloatType] ColorType)
        , Builtin "grey" (FuncType [FloatType] ColorType)
        , Builtin "vec4" (FuncType [FloatType, FloatType, FloatType, FloatType] ColorType)
        ]

builtins :: Map.Map T.Text Builtin
builtins = Map.fromList $ map (\b -> (view defname b, b)) blist

instance Show Builtin where
    show (Builtin n t) = "(" ++ T.unpack n ++ " " ++ show t ++ ")"