git.haldean.org del / 5f8abb1
use stack and cabal for building haldean 4 years ago
41 changed file(s) with 3342 addition(s) and 2562 deletion(s). Raw diff Collapse all Expand all
0 *.hi
1 *.dyn_hi
2 *.o
3 *.dyn_o
4 ParseDump
5 Del
6 GenBuiltins
7 glsl.del
0 .stack-work
+0
-215
AST.hs less more
0 {-# LANGUAGE OverloadedStrings #-}
1 {-# LANGUAGE RankNTypes #-}
2
3 module AST where
4 import qualified Data.Text as T
5 import qualified Data.Map.Strict as Map
6
7 data DelNum
8 = DelInt Integer
9 | DelFloat Double
10 deriving (Show, Eq)
11
12 type Name = T.Text
13
14 data Expr
15 = Add [Expr]
16 | Mul [Expr]
17 | Sub Expr Expr
18 | Div Expr Expr
19 | Pow Expr Expr
20 | Lt Expr Expr
21 | Gt Expr Expr
22 | LtE Expr Expr
23 | GtE Expr Expr
24 | Negate Expr
25 | Subscript Expr T.Text
26 | Apply Expr [Expr]
27 | NativeCall T.Text [Expr]
28 | Id Name
29 | Number DelNum
30 | Boolean Bool
31 | Let Name Expr Expr
32 | If Expr Expr Expr
33 deriving Eq
34
35 data Type
36 = NamedType Name
37 | FuncType [Type] Type
38 | BoolType
39 | Bool2Type
40 | Bool3Type
41 | Bool4Type
42 | ColorType
43 | DoubleType
44 | Double2Type
45 | Double3Type
46 | Double4Type
47 | DoubleMatrix Int Int
48 | FloatType
49 | Float2Type
50 | Float3Type
51 | Float4Type
52 | FloatMatrix Int Int
53 | IntType
54 | Int2Type
55 | Int3Type
56 | Int4Type
57 | LIntType
58 | LInt2Type
59 | LInt3Type
60 | LInt4Type
61 | LUIntType
62 | LUInt2Type
63 | LUInt3Type
64 | LUInt4Type
65 | UIntType
66 | UInt2Type
67 | UInt3Type
68 | UInt4Type
69 deriving Eq
70
71 data Form = Define T.Text Type [(T.Text, Type)] Expr
72
73 rootKey :: T.Text
74 rootKey = "root"
75
76 -- Programs are maps from bound name to the form that binds it
77 newtype AST = AST (Map.Map T.Text Form)
78
79 instance Show AST where
80 show (AST m) = unlines . map (show . snd) . Map.toAscList $ m
81
82 getAstMap :: AST -> Map.Map T.Text Form
83 getAstMap (AST m) = m
84
85 makeIndent :: Integer -> String
86 makeIndent 0 = ""
87 makeIndent n = " " ++ makeIndent (n - 1)
88
89 showExprList :: String -> [Expr] -> String
90 showExprList h xs = concat ["(", h, " ", unwords $ map show xs, ")"]
91
92 instance Show Expr where
93 show (Add xs) = showExprList "+" xs
94 show (Mul xs) = showExprList "*" xs
95 show (Sub x1 x2) = showExprList "-" [x1, x2]
96 show (Div x1 x2) = showExprList "/" [x1, x2]
97 show (Pow x1 x2) = showExprList "^" [x1, x2]
98 show (Gt x1 x2) = showExprList ">" [x1, x2]
99 show (Lt x1 x2) = showExprList "<" [x1, x2]
100 show (GtE x1 x2) = showExprList ">=" [x1, x2]
101 show (LtE x1 x2) = showExprList "<=" [x1, x2]
102 show (Negate x) = "~" ++ show x
103 show (Subscript e sub) = show e ++ "_" ++ T.unpack sub
104 show (Apply h xs) = showExprList (show h) xs
105 show (Id n) = T.unpack n
106 show (Number (DelInt i)) = show i
107 show (Number (DelFloat f)) = show f
108 show (Let n e b) = concat ["(let (", T.unpack n, " ", show e, ") ", show b]
109 show (Boolean b) = show b
110 show (If c t f) = concat ["(if ", show c, " ", show t, " ", show f]
111 show (NativeCall n xs) = showExprList ("$" ++ T.unpack n) xs
112
113 instance Show Form where
114 show (Define n ret args body) = concat [
115 "(", T.unpack n, ":", (show ret), " ",
116 unwords $ map (\(a, t) -> T.unpack a ++ ":" ++ show t) args,
117 ") -> ", show body]
118
119 instance Show Type where
120 show (NamedType t) = show t
121 show (FuncType args ret) = show args ++ " -> " ++ show ret
122 show BoolType = "b"
123 show Bool2Type = "b2"
124 show Bool3Type = "b3"
125 show Bool4Type = "b4"
126 show ColorType = "color"
127 show DoubleType = "d"
128 show Double2Type = "d2"
129 show Double3Type = "d3"
130 show Double4Type = "d4"
131 show FloatType = "f"
132 show Float2Type = "f2"
133 show Float3Type = "f3"
134 show Float4Type = "f4"
135 show IntType = "i"
136 show Int2Type = "i2"
137 show Int3Type = "i3"
138 show Int4Type = "i4"
139 show LIntType = "l"
140 show LInt2Type = "l2"
141 show LInt3Type = "l3"
142 show LInt4Type = "l4"
143 show LUIntType = "lu"
144 show LUInt2Type = "lu2"
145 show LUInt3Type = "lu3"
146 show LUInt4Type = "lu4"
147 show UIntType = "u"
148 show UInt2Type = "u2"
149 show UInt3Type = "u3"
150 show UInt4Type = "u4"
151 show (FloatMatrix r c) =
152 if r == c then "mat" ++ show r else "mat" ++ show r ++ "x" ++ show c
153 show (DoubleMatrix r c) =
154 if r == c then "dmat" ++ show r else "dmat" ++ show r ++ "x" ++ show c
155
156 -- Converts a list of Del numbers to floats if any elements in the list are
157 -- floats; otherwise, keeps them as integers
158 promote :: [DelNum] -> [DelNum]
159 promote ns = if anyFloats ns then map toFloat ns else ns
160
161 toFloat :: DelNum -> DelNum
162 toFloat (DelInt i) = DelFloat . fromIntegral $ i
163 toFloat float = float
164
165 anyFloats :: [DelNum] -> Bool
166 anyFloats ((DelFloat _):_) = True
167 anyFloats (_:xs) = anyFloats xs
168 anyFloats [] = False
169
170 sumFloats :: DelNum -> DelNum -> DelNum
171 sumFloats (DelFloat f1) (DelFloat f2) = DelFloat $ f1 + f2
172 sumFloats _ _ = undefined
173
174 sumInts :: DelNum -> DelNum -> DelNum
175 sumInts (DelInt f1) (DelInt f2) = DelInt $ f1 + f2
176 sumInts _ _ = undefined
177
178 prodFloats :: DelNum -> DelNum -> DelNum
179 prodFloats (DelFloat f1) (DelFloat f2) = DelFloat $ f1 * f2
180 prodFloats _ _ = undefined
181
182 prodInts :: DelNum -> DelNum -> DelNum
183 prodInts (DelInt f1) (DelInt f2) = DelInt $ f1 * f2
184 prodInts _ _ = undefined
185
186 wrapUnary :: (forall n. Num n => n -> n) -> DelNum -> DelNum
187 wrapUnary func (DelInt i) = DelInt $ func i
188 wrapUnary func (DelFloat f) = DelFloat $ func f
189
190 getFloat :: DelNum -> Double
191 getFloat (DelFloat f) = f
192 getFloat (DelInt i) = fromIntegral i
193
194 instance Num DelNum where
195 a + b = if anyFloats [a, b]
196 then sumFloats (toFloat a) (toFloat b)
197 else sumInts a b
198 a * b = if anyFloats [a, b]
199 then prodFloats (toFloat a) (toFloat b)
200 else prodInts a b
201 abs = wrapUnary abs
202 signum = wrapUnary signum
203 negate = wrapUnary negate
204 fromInteger = DelInt
205
206 instance Fractional DelNum where
207 a / b = DelFloat $ getFloat a / getFloat b
208 fromRational = DelFloat . fromRational
209
210 pow :: DelNum -> DelNum -> DelNum
211 pow (DelInt b) (DelInt p) = DelInt $ b ^ p
212 pow (DelFloat b) (DelInt p) = DelFloat $ b ^ p
213 pow (DelInt b) (DelFloat p) = DelFloat $ (fromInteger b) ** p
214 pow (DelFloat b) (DelFloat p) = DelFloat $ b ** p
+0
-101
AstUtils.hs less more
0 module AstUtils where
1
2 import AST
3 import Data.Functor.Identity
4 import qualified Data.Map.Strict as Map
5 import qualified Data.Text as T
6
7 replaceNames :: Map.Map T.Text Expr -> Expr -> Expr
8 replaceNames pmap e@(Id name) = Map.findWithDefault e name pmap
9 replaceNames _ e = e
10
11 swapNames :: Map.Map T.Text T.Text -> Expr -> Expr
12 swapNames m = replaceNames $ Map.map (\name -> Id name) m
13
14 containsName :: Name -> Expr -> Bool
15 containsName n = anyexpr (\e -> case e of
16 Id name -> name == n
17 _ -> False)
18
19 -- Calls the provided transformation function on each node in the AST.
20 mapexprM :: Monad m => (Expr -> m Expr) -> Expr -> m Expr
21 mapexprM f (Add exprs) = mapM (mapexprM f) exprs >>= f . Add
22 mapexprM f (Mul exprs) = mapM (mapexprM f) exprs >>= f . Mul
23 mapexprM f (Sub e1 e2) = do
24 m1 <- mapexprM f e1
25 m2 <- mapexprM f e2
26 f $ Sub m1 m2
27 mapexprM f (Div e1 e2) = do
28 m1 <- mapexprM f e1
29 m2 <- mapexprM f e2
30 f $ Div m1 m2
31 mapexprM f (Pow e1 e2) = do
32 m1 <- mapexprM f e1
33 m2 <- mapexprM f e2
34 f $ Pow m1 m2
35 mapexprM f (Gt e1 e2) = do
36 m1 <- mapexprM f e1
37 m2 <- mapexprM f e2
38 f $ Gt m1 m2
39 mapexprM f (Lt e1 e2) = do
40 m1 <- mapexprM f e1
41 m2 <- mapexprM f e2
42 f $ Lt m1 m2
43 mapexprM f (GtE e1 e2) = do
44 m1 <- mapexprM f e1
45 m2 <- mapexprM f e2
46 f $ GtE m1 m2
47 mapexprM f (LtE e1 e2) = do
48 m1 <- mapexprM f e1
49 m2 <- mapexprM f e2
50 f $ LtE m1 m2
51 mapexprM f (Subscript e sub) = mapexprM f e >>= \x -> f $ Subscript x sub
52 mapexprM f (Negate e) = mapexprM f e >>= \x -> f $ Negate x
53 mapexprM f (Apply hd xs) = do
54 mh <- mapexprM f hd
55 mb <- mapM (mapexprM f) xs
56 f $ Apply mh mb
57 mapexprM f (Id n) = f $ Id n
58 mapexprM f (Number num) = f $ Number num
59 mapexprM f (Let n e b) = do
60 me <- mapexprM f e
61 mb <- mapexprM f b
62 f $ Let n me mb
63 mapexprM f b@(Boolean _) = f b
64 mapexprM f (If c bt bf) = do
65 mc <- mapexprM f c
66 mt <- mapexprM f bt
67 mf <- mapexprM f bf
68 f $ If mc mt mf
69 mapexprM f (NativeCall n xs) = mapM (mapexprM f) xs >>= f . (NativeCall n)
70
71 mapexpr :: (Expr -> Expr) -> Expr -> Expr
72 mapexpr f = runIdentity . mapexprM (return . f)
73
74 mapast :: (Form -> Form) -> AST -> AST
75 mapast f (AST m) = AST $ Map.map f m
76
77 mapdefs :: (Expr -> Expr) -> AST -> AST
78 mapdefs f = mapast (\(Define n ret p b) -> Define n ret p (f b))
79
80 -- Returns true if the provided property function returns true for any
81 -- expression in the tree.
82 anyexpr :: (Expr -> Bool) -> Expr -> Bool
83 anyexpr f e@(Add exprs) = if f e then True else any id $ map (anyexpr f) exprs
84 anyexpr f e@(Mul exprs) = if f e then True else any id $ map (anyexpr f) exprs
85 anyexpr f e@(Sub e1 e2) = if f e then True else anyexpr f e1 || anyexpr f e2
86 anyexpr f e@(Div e1 e2) = if f e then True else anyexpr f e1 || anyexpr f e2
87 anyexpr f e@(Pow e1 e2) = if f e then True else anyexpr f e1 || anyexpr f e2
88 anyexpr f e@(Gt e1 e2) = if f e then True else anyexpr f e1 || anyexpr f e2
89 anyexpr f e@(Lt e1 e2) = if f e then True else anyexpr f e1 || anyexpr f e2
90 anyexpr f e@(GtE e1 e2) = if f e then True else anyexpr f e1 || anyexpr f e2
91 anyexpr f e@(LtE e1 e2) = if f e then True else anyexpr f e1 || anyexpr f e2
92 anyexpr f e@(Subscript ex _) = if f e then True else anyexpr f ex
93 anyexpr f e@(Negate ex) = if f e then True else anyexpr f ex
94 anyexpr f e@(Apply hd xs) = if f e then True else anyexpr f hd || any id (map (anyexpr f) xs)
95 anyexpr f e@(Id _) = f e
96 anyexpr f e@(Number _) = f e
97 anyexpr f e@(Let _ v b) = if f e then True else anyexpr f v || anyexpr f b
98 anyexpr f e@(Boolean _) = f e
99 anyexpr f e@(If c bt bf) = if f e then True else anyexpr f c || anyexpr f bt || anyexpr f bf
100 anyexpr f e@(NativeCall _ xs) = if f e then True else any id $ map (anyexpr f) xs
+0
-33
Builtins.hs less more
0 {-# LANGUAGE OverloadedStrings #-}
1 {-# LANGUAGE TemplateHaskell #-}
2
3 module Builtins where
4
5 import AST
6 import Control.Lens
7 import qualified Data.Map.Strict as Map
8 import qualified Data.Text as T
9
10 data Builtin = Builtin {
11 _defname :: T.Text,
12 _deftype :: Type
13 }
14 makeLenses ''Builtin
15 makeBuiltin :: T.Text -> Type -> Builtin
16 makeBuiltin n t = Builtin { _defname = n, _deftype = t }
17
18 getType :: Builtin -> Type
19 getType = view deftype
20
21 blist :: [Builtin]
22 blist = --[ Builtin "rgb" (FuncType [FloatType, FloatType, FloatType] ColorType)
23 [ Builtin "gray" (FuncType [FloatType] ColorType)
24 , Builtin "grey" (FuncType [FloatType] ColorType)
25 , Builtin "vec4" (FuncType [FloatType, FloatType, FloatType, FloatType] ColorType)
26 ]
27
28 builtins :: Map.Map T.Text Builtin
29 builtins = Map.fromList $ map (\b -> (view defname b, b)) blist
30
31 instance Show Builtin where
32 show (Builtin n t) = "(" ++ T.unpack n ++ " " ++ show t ++ ")"
+0
-46
Compile.hs less more
0 {-# LANGUAGE OverloadedStrings #-}
1
2 module Compile (compile) where
3
4 import AST
5 import CompileDefs
6 import Constants
7 import Glsl
8 import InRep
9 import Inlining
10 import Ops
11 import Properties
12 import TypeCheck
13 import Types
14
15 import Debug.Trace
16 import qualified Data.Map.Strict as Map
17
18 buildMap :: [Form] -> Artifact AST
19 buildMap fs = return . AST . Map.fromList $ map namePair fs
20 where namePair f@(Define name _ _ _) = (name, f)
21
22 -- Drops all definitions other than the root definition
23 dropNonRoot :: AST -> Artifact Form
24 dropNonRoot (AST m) = return $ (Map.!) m rootKey
25
26 printStage :: Show a => String -> a -> Artifact a
27 printStage n a = trace (n ++ "\n" ++ show a ++ "\n") $ return a
28
29 compile :: [Form] -> Artifact GLSL
30 compile fs = buildMap fs
31 >>= loadOps
32 >>= printStage "Parsed AST"
33 >>= checkRecursive
34 >>= parseTypes
35 >>= typeCheck
36 >>= checkRoot
37 >>= uniqueParams
38 >>= substFuncs
39 >>= dropNonRoot
40 >>= propConstants
41 >>= foldConstantExprs
42 >>= printStage "Post-optimization AST"
43 >>= toIR
44 >>= printStage "Intermediate representation"
45 >>= glsl
+0
-83
CompileDefs.hs less more
0 module CompileDefs where
1
2 import AST
3 import qualified Data.Text as T
4 import qualified Text.Parsec.Error as PErr
5
6 data Error
7 = SystemError T.Text
8 | ReadError PErr.ParseError
9 | MissingRootError
10 | RecursionError T.Text
11 | BadArity T.Text Int Int -- name of function, expected arity, source arity
12 | BadTypeName T.Text
13 | BadRootType Type
14 | ReturnTypeMismatch T.Text Type Type -- name of function, expected type,
15 -- type in source
16 | BadId T.Text
17 | Unsubscriptable Type T.Text
18 | BadSubscript Type T.Text [T.Text]
19 | BadApplyHead Expr Type
20 | BadArgType T.Text Type Type Int Expr
21 | BadIfCondition Type Expr
22 | IfTypeMismatch Type Type Expr
23 | BadNativeName Expr Expr -- expr that's supposed to be the native func
24 -- name, full native call expr
25 | ApplyHeadNotId Expr
26 deriving (Eq)
27
28 data Artifact a
29 = Success a
30 | Failure Error
31 deriving (Show, Eq)
32
33 instance Functor Artifact where
34 fmap f x = x >>= return . f
35
36 instance Applicative Artifact where
37 pure = Success
38 Success f <*> Success x = Success (f x)
39 Success _ <*> Failure e = Failure e
40 Failure e <*> _ = Failure e
41
42 instance Monad Artifact where
43 (Success x) >>= f = f x
44 (Failure e) >>= _ = Failure e
45 fail msg = Failure $ SystemError $ T.pack msg
46
47 instance Show Error where
48 show (SystemError t) = "unexpected system error: " ++ T.unpack t
49 show (ReadError p) = "syntax error: " ++ show p
50 show MissingRootError =
51 "root function not defined. You must (define root) to create an entry point"
52 show (RecursionError func) =
53 "recursive functions are not supported, but " ++ T.unpack func ++ " is recursive"
54 show (BadArity func expect src) =
55 "function \"" ++ T.unpack func ++ "\" takes " ++ show expect ++ " arguments, but " ++
56 show src ++ " were given"
57 show (BadTypeName tn) = "unknown type name \"" ++ T.unpack tn ++ "\""
58 show (BadRootType t) =
59 "root function must return a color, provided root has return type " ++ show t
60 show (ReturnTypeMismatch n e a) =
61 "function " ++ T.unpack n ++ " defined to have type " ++ show e ++ ", but body has type " ++ show a
62 show (BadId n) = "unknown name " ++ T.unpack n
63 show (Unsubscriptable t sub) =
64 "tried to take subscript " ++ T.unpack sub ++ " of un-subscript-able type " ++ show t
65 show (BadSubscript t sub allow) =
66 "tried to take invalid subscript " ++ T.unpack sub ++ " of type " ++ show t ++ ", valid subscripts are " ++ show allow
67 show (BadApplyHead hd t) =
68 "tried to call function " ++ show hd ++ " which has non-function-type " ++ show t
69 show (BadArgType n ex ac i e) =
70 "argument " ++ show i ++ " to " ++ T.unpack n ++ " was type " ++ show ac ++
71 ", expected type " ++ show ex ++ ", in expression:\n\n\t" ++ show e ++ "\n"
72 show (BadIfCondition t e) =
73 "condition in if statement has type " ++ show t ++ ", should be boolean, in expression:\n\n\t" ++ show e ++ "\n"
74 show (IfTypeMismatch tt tf e) =
75 "branches in if statement have different types; true branch is " ++ show tt ++
76 ", false branch is " ++ show tf ++ " in expression:\n\n\t" ++ show e ++ "\n"
77 show (BadNativeName n e) =
78 "first argument to $ must be a function name, got " ++ show n ++
79 " in expression:\n\n\t" ++ show e ++ "\n"
80 show (ApplyHeadNotId e) =
81 "head of list must be the name of a function in expression:\n\n\t" ++
82 show e ++ "\n"
+0
-85
Constants.hs less more
0 module Constants (propConstants, foldConstantExprs) where
1
2 import AST
3 import AstUtils
4 import CompileDefs
5 import Control.Monad
6
7 import qualified Data.Map.Strict as Map
8
9 -- Replace references to constants with the constants themselves
10 propConstants' :: Expr -> Expr
11 propConstants' (Let n v@(Number _) b) = mapexpr (replaceNames $ Map.singleton n v) b
12 propConstants' (Let n v@(Id _) b) = mapexpr (replaceNames $ Map.singleton n v) b
13 propConstants' e = e
14
15 propConstants :: Form -> Artifact Form
16 propConstants (Define n ret a b) = return . Define n ret a $ mapexpr propConstants' b
17
18 isNumber :: Expr -> Bool
19 isNumber (Number _) = True
20 isNumber _ = False
21
22 getNumbers :: [Expr] -> [DelNum]
23 getNumbers = map extract . filter isNumber
24 where extract (Number nt) = nt
25 extract _ = undefined
26
27 -- Only safe to call on expressions that are definitely constant numbers
28 extractNumber :: Expr -> DelNum
29 extractNumber (Number n) = n
30 extractNumber _ = undefined
31
32 liftConstExprOp :: (DelNum -> DelNum -> DelNum) -> Expr -> Expr -> Expr -> Expr
33 liftConstExprOp f e e1 e2 =
34 if isNumber e1 && isNumber e2
35 then Number $ f (extractNumber e1) (extractNumber e2)
36 else e
37
38 -- Replace arithmetic operations on constants with the result of the operation
39 -- itself.
40 collapseConstExprs' :: Expr -> Expr
41 -- These two partition the list into constant numbers and not-constant-numbers,
42 -- sum/product the constant numbers, promoting them in the meantime if
43 -- necessary, and then prepend that constant onto the the list of
44 -- non-constants.
45 collapseConstExprs' (Add xs) =
46 Add . (flip (:)) (filter (not . isNumber) xs) . Number . sum . promote . getNumbers $ xs
47 collapseConstExprs' (Mul xs) =
48 Mul . (flip (:)) (filter (not . isNumber) xs) . Number . product . promote . getNumbers $ xs
49 collapseConstExprs' e@(Sub e1 e2) = liftConstExprOp (-) e e1 e2
50 collapseConstExprs' e@(Div e1 e2) = liftConstExprOp (/) e e1 e2
51 collapseConstExprs' e@(Pow e1 e2) = liftConstExprOp pow e e1 e2
52 collapseConstExprs' e = e
53
54 collapseConstExprs :: Form -> Artifact Form
55 collapseConstExprs (Define n ret a b) = return . Define n ret a $ mapexpr collapseConstExprs' b
56
57 -- Remove unnecessary arithmetic
58 remIdent :: Integer -> ([Expr] -> Expr) -> [Expr] -> Expr
59 remIdent ident ctor exprs =
60 case (filter (\e -> case e of
61 Number (DelInt x) -> x /= ident
62 Number (DelFloat x) -> x /= fromIntegral ident
63 _ -> True) exprs) of
64 [] -> Number $ DelInt ident
65 [x] -> x
66 xs -> ctor xs
67
68 removeIdentities' :: Expr -> Expr
69 removeIdentities' (Add xs) = remIdent 0 Add xs
70 removeIdentities' (Mul xs) = remIdent 1 Mul xs
71 removeIdentities' (Pow _ (Number (DelInt 0))) = Number (DelInt 1)
72 removeIdentities' (Pow _ (Number (DelFloat 0))) = Number (DelFloat 1)
73 removeIdentities' e = e
74
75 removeIdentities :: Form -> Artifact Form
76 removeIdentities (Define n ret a b) = return . Define n ret a $ mapexpr removeIdentities' b
77
78 foldConstantExprs :: Form -> Artifact Form
79 -- this is not the correct way to do this; some kind of
80 -- iteration-until-finished is the way to go here.
81 foldConstantExprs = collapseConstExprs
82 >=> removeIdentities
83 >=> collapseConstExprs
84 >=> removeIdentities
+0
-16
Del.hs less more
0 {-# OPTIONS_GHC -Wno-missing-signatures #-}
1
2 module Main where
3 import CompileDefs
4 import qualified Data.Text as T
5 import qualified Reader as R
6 import qualified Compile as C
7
8 run s = R.read s >>= C.compile
9
10 main :: IO ()
11 main = do
12 prog <- getContents >>= return . T.pack
13 case run prog of
14 Success res -> putStr "\n" >> print res
15 Failure err -> putStr "compilation failed: " >> print err
+0
-138
GenBuiltins.hs less more
0 {-# LANGUAGE OverloadedStrings #-}
1
2 module Main where
3
4 import AST
5 import Builtins
6 import Data.List
7 import qualified Data.Text as T
8 import Text.Parsec
9 import Text.Parsec.String
10
11 type1 :: Parser Type
12 type1 = do
13 n <- name
14 case n of
15 "out" -> (many $ char ' ') >> type1
16 "inout" -> (many $ char ' ') >> type1
17 "in" -> (many $ char ' ') >> type1
18 "coherent" -> (many $ char ' ') >> type1
19 "volatile" -> (many $ char ' ') >> type1
20 "highp" -> (many $ char ' ') >> type1
21 "mediump" -> (many $ char ' ') >> type1
22 "lowp" -> (many $ char ' ') >> type1
23
24 "bool" -> return BoolType
25 "bvec2" -> return Bool2Type
26 "bvec3" -> return Bool3Type
27 "bvec4" -> return Bool4Type
28 "dmat2" -> return $ DoubleMatrix 2 2
29 "dmat2x3" -> return $ DoubleMatrix 2 3
30 "dmat2x4" -> return $ DoubleMatrix 2 4
31 "dmat3" -> return $ DoubleMatrix 3 3
32 "dmat3x2" -> return $ DoubleMatrix 3 2
33 "dmat3x4" -> return $ DoubleMatrix 3 4
34 "dmat4" -> return $ DoubleMatrix 4 4
35 "dmat4x2" -> return $ DoubleMatrix 4 2
36 "dmat4x3" -> return $ DoubleMatrix 4 3
37 "double" -> return DoubleType
38 "dvec2" -> return Double2Type
39 "dvec3" -> return Double3Type
40 "dvec4" -> return Double4Type
41 "float" -> return FloatType
42 "i64vec2" -> return LInt2Type
43 "i64vec3" -> return LInt3Type
44 "i64vec4" -> return LInt4Type
45 "int" -> return IntType
46 "int64_t" -> return LIntType
47 "ivec2" -> return Int2Type
48 "ivec3" -> return Int3Type
49 "ivec4" -> return Int4Type
50 "mat2" -> return $ FloatMatrix 2 2
51 "mat2x3" -> return $ FloatMatrix 2 3
52 "mat2x4" -> return $ FloatMatrix 2 4
53 "mat3" -> return $ FloatMatrix 3 3
54 "mat3x2" -> return $ FloatMatrix 3 2
55 "mat3x4" -> return $ FloatMatrix 3 4
56 "mat4" -> return $ FloatMatrix 4 4
57 "mat4x2" -> return $ FloatMatrix 4 2
58 "mat4x3" -> return $ FloatMatrix 4 3
59 "u64vec2" -> return LUInt2Type
60 "u64vec3" -> return LUInt3Type
61 "u64vec4" -> return LUInt4Type
62 "uint" -> return UIntType
63 "uint64_t" -> return LUIntType
64 "uvec2" -> return UInt2Type
65 "uvec3" -> return UInt3Type
66 "uvec4" -> return UInt4Type
67 "vec2" -> return Float2Type
68 "vec3" -> return Float3Type
69 "vec4" -> return Float4Type
70
71 "atomic_uint" -> return $ NamedType n
72 "sampler1D" -> return $ NamedType n
73 "sampler1DShadow" -> return $ NamedType n
74 "sampler2D" -> return $ NamedType n
75 "sampler2DRect" -> return $ NamedType n
76 "sampler2DRectShadow" -> return $ NamedType n
77 "sampler2DShadow" -> return $ NamedType n
78 "sampler3D" -> return $ NamedType n
79 "samplerCube" -> return $ NamedType n
80 "samplerExternalOES" -> return $ NamedType n
81 "void" -> return $ NamedType n
82 _ -> fail $ "unknown type name \"" ++ T.unpack n ++ "\""
83
84 name :: Parser T.Text
85 name = T.pack <$> do
86 l <- letter
87 ex <- many (alphaNum <|> oneOf "_")
88 return (l:ex)
89
90 args :: Parser [Type]
91 args = many (do
92 _ <- many (char ' ')
93 typ <- type1
94 _ <- many (char ' ')
95 _ <- optional name
96 _ <- many (oneOf ", ")
97 return typ
98 )
99
100 func :: Parser Builtin
101 func = do
102 ret <- type1
103 _ <- char ' '
104 n <- name
105 _ <- many $ char ' '
106 _ <- char '('
107 a <- args
108 _ <- char ')' >> char ';'
109 return $ makeBuiltin n (FuncType a ret)
110
111 file :: Parser [Builtin]
112 file = many (func <* many (char '\n')) <* eof
113
114 knownTypes :: Type -> Bool
115 knownTypes (FuncType arg ret) = all knownTypes arg && knownTypes ret
116 knownTypes (NamedType _) = False
117 knownTypes _ = True
118
119 decl :: Builtin -> String
120 decl Builtin { _defname = n, _deftype = (FuncType argtypes ret) }
121 = "(define " ++ T.unpack n ++ ":" ++ show ret ++ " (" ++
122 intercalate ", " (map argstr $ zip [1::Int ..] argtypes) ++ ") " ++
123 "($ " ++ T.unpack n ++ " " ++
124 intercalate " " (map (\i -> "__x" ++ show i) [1..length argtypes])
125 ++ "))"
126 where argstr (i, a) = "__x" ++ show i ++ ":" ++ show a
127 decl _ = undefined
128
129 main :: IO ()
130 main = do
131 f <- readFile "builtins.txt"
132 bi <- case parse file "builtins.txt" f of
133 Left err -> print err >> return []
134 Right stuff -> return stuff
135 let res = filter (knownTypes . getType) bi
136 _ <- mapM (putStrLn . decl) res
137 return ()
+0
-109
Glsl.hs less more
0 {-# LANGUAGE OverloadedStrings #-}
1 {-# OPTIONS_GHC -Wno-unused-do-bind #-}
2
3 module Glsl (glsl, GLSL) where
4
5 import qualified AST as A
6 import CompileDefs
7 import Control.Monad.Trans.Writer
8 import Data.List
9 import qualified Data.Text as T
10 import qualified InRep as IR
11 import Numeric
12
13 newtype GLSL = GLSL T.Text
14 instance Show GLSL where
15 show (GLSL t) = T.unpack t
16
17 glslType :: A.Type -> T.Text
18 glslType t
19 = case t of
20 A.FloatType -> "float"
21 A.IntType -> "int"
22 A.Float3Type -> "vec3"
23 A.ColorType -> "vec4"
24 A.BoolType -> "bool"
25 A.NamedType n -> n
26 A.FuncType _ _ -> undefined
27
28 glslName :: T.Text -> T.Text
29 glslName = T.replace "/" "__"
30
31 glsl :: IR.Program -> Artifact GLSL
32 glsl prog = execWriterT (glslRoot prog) >>= return . GLSL . T.concat
33
34 type Ctx a = WriterT [T.Text] Artifact a
35
36 emit :: (Monad m) => w -> WriterT [w] m ()
37 emit x = tell [x]
38
39 emitShow :: (Monad m, Show s) => s -> WriterT [T.Text] m ()
40 emitShow = emit . T.pack . show
41
42 glslRoot :: IR.Program -> Ctx ()
43 glslRoot (IR.Program args ret stmts)
44 = do
45 emit "void shader_entry(out "
46 emit $ glslType ret
47 emit " __ret"
48 mapM (\(n, t) -> tell [", ", glslType t, " ", glslName n]) args
49 emit ") {\n"
50 mapM glslStmt stmts
51 emit "\n}"
52 return ()
53
54 glslStmt :: IR.Stmt -> Ctx ()
55 glslStmt (IR.Store n t e) = do
56 emit $ glslType t
57 emit " "
58 emit n
59 emit " = "
60 glslExpr e
61 emit ";\n"
62 glslStmt (IR.Return e) = do
63 emit "__ret = "
64 glslExpr e
65 emit ";\n"
66
67 glslArith :: T.Text -> IR.IExpr -> IR.IExpr -> Ctx ()
68 glslArith op x y =
69 emit "(" >> glslExpr x >> emit ") " >> emit op >>
70 emit " (" >> glslExpr y >> emit ")"
71
72 glslExpr :: IR.IExpr -> Ctx ()
73 glslExpr (IR.Add x y) = glslArith "+" x y
74 glslExpr (IR.Mul x y) = glslArith "*" x y
75 glslExpr (IR.Sub x y) = glslArith "-" x y
76 glslExpr (IR.Div x y) = glslArith "/" x y
77 glslExpr (IR.Lt x y) = glslArith "<" x y
78 glslExpr (IR.Gt x y) = glslArith ">" x y
79 glslExpr (IR.LtE x y) = glslArith "<=" x y
80 glslExpr (IR.GtE x y) = glslArith ">=" x y
81 glslExpr (IR.Negate x) = emit "-(" >> glslExpr x >> emit ")"
82 glslExpr (IR.Boolean b) = emit (if b then "true" else "false")
83
84 glslExpr (IR.Atomic (IR.Name n)) = emit $ glslName n
85 glslExpr (IR.Atomic (IR.InFloat f)) = emit . T.pack $ showGFloatAlt Nothing f ""
86 glslExpr (IR.Atomic (IR.InInt i)) = emitShow i
87
88 glslExpr (IR.Builtin f args) = do
89 emit f
90 emit "("
91 sequence $ intersperse (emit ", ") (map glslExpr args)
92 emit ")"
93
94 glslExpr (IR.Ternary c t f) = do
95 emit "("
96 glslExpr c
97 emit " ? "
98 glslExpr t
99 emit " : "
100 glslExpr f
101 emit ")"
102
103 glslExpr (IR.Index e i) = do
104 emit "("
105 glslExpr e
106 emit ")["
107 emitShow i
108 emit "]"
+0
-156
InRep.hs less more
0 {-# LANGUAGE OverloadedStrings #-}
1
2 module InRep where
3
4 import qualified AST as A
5 import CompileDefs
6 import qualified Control.Monad.Trans.State as S
7 import qualified Data.List as L
8 import qualified Data.Text as T
9
10 data Atom
11 = Name T.Text
12 | InFloat Double
13 | InInt Integer
14
15 data IExpr
16 = Add IExpr IExpr
17 | Mul IExpr IExpr
18 | Sub IExpr IExpr
19 | Div IExpr IExpr
20 | Lt IExpr IExpr
21 | Gt IExpr IExpr
22 | LtE IExpr IExpr
23 | GtE IExpr IExpr
24 | Negate IExpr
25 | Atomic Atom
26 | Ternary IExpr IExpr IExpr
27 | Builtin T.Text [IExpr]
28 | Index IExpr Integer
29 | Boolean Bool
30
31 data Stmt
32 = Store T.Text A.Type IExpr
33 | Return IExpr
34
35 data Program = Program [(T.Text, A.Type)] A.Type [Stmt]
36
37 toIR :: A.Form -> Artifact Program
38 toIR f@(A.Define _ r a _) = runCtx (gen f) >>= return . (Program a r)
39
40 genExpr :: A.Expr -> GenCtx IExpr
41
42 genExpr (A.Add xs) = nary Add A.Add xs
43 genExpr (A.Mul xs) = nary Mul A.Mul xs
44 genExpr (A.Sub x y) = binary Sub x y
45 genExpr (A.Div x y) = binary Div x y
46 genExpr (A.Lt x y) = binary Lt x y
47 genExpr (A.Gt x y) = binary Gt x y
48 genExpr (A.LtE x y) = binary LtE x y
49 genExpr (A.GtE x y) = binary GtE x y
50 genExpr (A.Negate x) = genExpr x >>= return . Negate
51 genExpr (A.Id n) = return $ Atomic $ Name n
52 genExpr (A.Number (A.DelInt i)) = return $ Atomic $ InInt i
53 genExpr (A.Number (A.DelFloat f)) = return $ Atomic $ InFloat f
54
55 genExpr (A.Pow x p) = do
56 ex <- genExpr x
57 ep <- genExpr p
58 return $ Builtin "pow" [ex, ep]
59
60 genExpr (A.Apply (A.Id fun) args) = do
61 atemps <- mapM genExpr args
62 return $ Builtin fun atemps
63 genExpr (A.Apply _ _) = undefined
64
65 genExpr (A.If c t f) = do
66 co <- genExpr c
67 to <- genExpr t
68 fo <- genExpr f
69 return $ Ternary co to fo
70
71 genExpr (A.Subscript e s) = genExpr e >>= return . (flip Index) (subIdx s)
72 where subIdx "x" = 0
73 subIdx "y" = 1
74 subIdx "z" = 2
75 subIdx "0" = 0
76 subIdx "1" = 1
77 subIdx "2" = 2
78 subIdx _ = undefined
79
80 genExpr (A.NativeCall t args) = genExpr (A.Apply (A.Id t) args)
81 genExpr (A.Boolean b) = return $ Boolean b
82
83 genExpr (A.Let _ _ _) = undefined
84
85 gen :: A.Form -> GenCtx ()
86 gen (A.Define _ _ _ b) = do
87 baseref <- genExpr b
88 _ <- nextTemp
89 emit $ Return baseref
90
91 -- This is not the best name; really, this supports n-ary functions with n >= 2
92 nary :: (IExpr -> IExpr -> IExpr) -> ([A.Expr] -> A.Expr) -> [A.Expr] -> GenCtx IExpr
93 nary ictor ector (x:y:z:xs) = do
94 xo <- genExpr x
95 xso <- genExpr $ ector (y:z:xs)
96 return (ictor xo xso)
97 nary ictor _ [x, y] = binary ictor x y
98 nary _ _ _ = undefined
99
100 binary :: (IExpr -> IExpr -> IExpr) -> A.Expr -> A.Expr -> GenCtx IExpr
101 binary ctor x y = do
102 xo <- genExpr x
103 yo <- genExpr y
104 return $ ctor xo yo
105
106 data GenState
107 = GenState [Stmt] Int -- list of statements, id of next temp var
108 type GenCtx a = S.StateT GenState Artifact a
109
110 -- Add an statement to the list of statements in the context
111 emit :: Stmt -> GenCtx ()
112 emit stmt = do
113 (GenState stmts next) <- S.get
114 S.put $ GenState (stmts ++ [stmt]) next
115
116 -- Get the name of the next temporary, and increment the value of the temp
117 -- counter
118 nextTemp :: GenCtx T.Text
119 nextTemp = S.state $
120 \(GenState stmts next) ->
121 (T.pack $ "__t" ++ show next, GenState stmts (next + 1))
122
123 runCtx :: GenCtx a -> Artifact [Stmt]
124 runCtx v = (S.runStateT v $ GenState [] 0) >>= \(_, GenState s _) -> return s
125
126 instance Show Atom where
127 show (Name t) = T.unpack t
128 show (InFloat f) = show f ++ "f"
129 show (InInt i) = show i ++ "i"
130
131 instance Show IExpr where
132 show (Add a1 a2) = show a1 ++ " + " ++ show a2
133 show (Mul a1 a2) = show a1 ++ " * " ++ show a2
134 show (Sub x y) = show x ++ " - " ++ show y
135 show (Div x y) = show x ++ " / " ++ show y
136 show (Lt x y) = show x ++ " < " ++ show y
137 show (Gt x y) = show x ++ " > " ++ show y
138 show (LtE x y) = show x ++ " <= " ++ show y
139 show (GtE x y) = show x ++ " >= " ++ show y
140 show (Negate x) = "~" ++ show x
141 show (Ternary c t f) = show c ++ " ? " ++ show t ++ " : " ++ show f
142 show (Atomic a) = show a
143 show (Builtin n args)
144 = T.unpack n ++ "(" ++ L.intercalate ", " (map show args) ++ ")"
145 show (Index x i) = show x ++ "[" ++ show i ++ "]"
146 show (Boolean b) = show b
147
148 instance Show Stmt where
149 show (Store n t o) = "LET " ++ T.unpack n ++ ":" ++ show t ++ " = " ++ show o
150 show (Return o) = "RET " ++ show o
151
152 instance Show Program where
153 show (Program args ret stmts) =
154 "args: " ++ show args ++ "\nreturns: " ++ show ret ++ "\n" ++
155 L.intercalate "\n" (map show stmts)
+0
-35
Inlining.hs less more
0 {-# LANGUAGE OverloadedStrings #-}
1
2 module Inlining (substFuncs, uniqueParams) where
3
4 import AST
5 import AstUtils
6 import CompileDefs
7
8 import qualified Data.Map.Strict as Map
9 import qualified Data.Text as T
10
11 -- Replace function parameters with unique names
12 uniqueParams' :: Form -> Form
13 uniqueParams' (Define name ret params body) =
14 let newParams = map (\(p, t) -> (T.concat [name, "/", p], t)) params in
15 Define name ret newParams
16 (mapexpr (swapNames (Map.fromList $ zip (map fst params) (map fst newParams))) body)
17 uniqueParams :: AST -> Artifact AST
18 uniqueParams (AST m) = return . AST . Map.map uniqueParams' $ m
19
20 -- Replace function calls with let-bindings
21 substFunc :: AST -> Expr -> Expr
22 substFunc (AST m) e@(Apply (Id name) aargs) =
23 case Map.lookup name m of
24 Just (Define _ _ dargs body) -> makeLets (zip (map fst dargs) aargs) body
25 Nothing -> e
26 substFunc _ e = e
27
28 makeLets :: [(Name, Expr)] -> Expr -> Expr
29 makeLets ((n, a):xs) e = Let n a $ makeLets xs e
30 makeLets [] e = e
31
32 substFuncs :: AST -> Artifact AST
33 substFuncs ast@(AST m) = return . AST $ Map.adjust sub rootKey m
34 where sub (Define n ret a b) = Define n ret a $ mapexpr (substFunc ast) b
0 GNU GENERAL PUBLIC LICENSE
1 Version 3, 29 June 2007
2
3 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
4 Everyone is permitted to copy and distribute verbatim copies
5 of this license document, but changing it is not allowed.
6
7 Preamble
8
9 The GNU General Public License is a free, copyleft license for
10 software and other kinds of works.
11
12 The licenses for most software and other practical works are designed
13 to take away your freedom to share and change the works. By contrast,
14 the GNU General Public License is intended to guarantee your freedom to
15 share and change all versions of a program--to make sure it remains free
16 software for all its users. We, the Free Software Foundation, use the
17 GNU General Public License for most of our software; it applies also to
18 any other work released this way by its authors. You can apply it to
19 your programs, too.
20
21 When we speak of free software, we are referring to freedom, not
22 price. Our General Public Licenses are designed to make sure that you
23 have the freedom to distribute copies of free software (and charge for
24 them if you wish), that you receive source code or can get it if you
25 want it, that you can change the software or use pieces of it in new
26 free programs, and that you know you can do these things.
27
28 To protect your rights, we need to prevent others from denying you
29 these rights or asking you to surrender the rights. Therefore, you have
30 certain responsibilities if you distribute copies of the software, or if
31 you modify it: responsibilities to respect the freedom of others.
32
33 For example, if you distribute copies of such a program, whether
34 gratis or for a fee, you must pass on to the recipients the same
35 freedoms that you received. You must make sure that they, too, receive
36 or can get the source code. And you must show them these terms so they
37 know their rights.
38
39 Developers that use the GNU GPL protect your rights with two steps:
40 (1) assert copyright on the software, and (2) offer you this License
41 giving you legal permission to copy, distribute and/or modify it.
42
43 For the developers' and authors' protection, the GPL clearly explains
44 that there is no warranty for this free software. For both users' and
45 authors' sake, the GPL requires that modified versions be marked as
46 changed, so that their problems will not be attributed erroneously to
47 authors of previous versions.
48
49 Some devices are designed to deny users access to install or run
50 modified versions of the software inside them, although the manufacturer
51 can do so. This is fundamentally incompatible with the aim of
52 protecting users' freedom to change the software. The systematic
53 pattern of such abuse occurs in the area of products for individuals to
54 use, which is precisely where it is most unacceptable. Therefore, we
55 have designed this version of the GPL to prohibit the practice for those
56 products. If such problems arise substantially in other domains, we
57 stand ready to extend this provision to those domains in future versions
58 of the GPL, as needed to protect the freedom of users.
59
60 Finally, every program is threatened constantly by software patents.
61 States should not allow patents to restrict development and use of
62 software on general-purpose computers, but in those that do, we wish to
63 avoid the special danger that patents applied to a free program could
64 make it effectively proprietary. To prevent this, the GPL assures that
65 patents cannot be used to render the program non-free.
66
67 The precise terms and conditions for copying, distribution and
68 modification follow.
69
70 TERMS AND CONDITIONS
71
72 0. Definitions.
73
74 "This License" refers to version 3 of the GNU General Public License.
75
76 "Copyright" also means copyright-like laws that apply to other kinds of
77 works, such as semiconductor masks.
78
79 "The Program" refers to any copyrightable work licensed under this
80 License. Each licensee is addressed as "you". "Licensees" and
81 "recipients" may be individuals or organizations.
82
83 To "modify" a work means to copy from or adapt all or part of the work
84 in a fashion requiring copyright permission, other than the making of an
85 exact copy. The resulting work is called a "modified version" of the
86 earlier work or a work "based on" the earlier work.
87
88 A "covered work" means either the unmodified Program or a work based
89 on the Program.
90
91 To "propagate" a work means to do anything with it that, without
92 permission, would make you directly or secondarily liable for
93 infringement under applicable copyright law, except executing it on a
94 computer or modifying a private copy. Propagation includes copying,
95 distribution (with or without modification), making available to the
96 public, and in some countries other activities as well.
97
98 To "convey" a work means any kind of propagation that enables other
99 parties to make or receive copies. Mere interaction with a user through
100 a computer network, with no transfer of a copy, is not conveying.
101
102 An interactive user interface displays "Appropriate Legal Notices"
103 to the extent that it includes a convenient and prominently visible
104 feature that (1) displays an appropriate copyright notice, and (2)
105 tells the user that there is no warranty for the work (except to the
106 extent that warranties are provided), that licensees may convey the
107 work under this License, and how to view a copy of this License. If
108 the interface presents a list of user commands or options, such as a
109 menu, a prominent item in the list meets this criterion.
110
111 1. Source Code.
112
113 The "source code" for a work means the preferred form of the work
114 for making modifications to it. "Object code" means any non-source
115 form of a work.
116
117 A "Standard Interface" means an interface that either is an official
118 standard defined by a recognized standards body, or, in the case of
119 interfaces specified for a particular programming language, one that
120 is widely used among developers working in that language.
121
122 The "System Libraries" of an executable work include anything, other
123 than the work as a whole, that (a) is included in the normal form of
124 packaging a Major Component, but which is not part of that Major
125 Component, and (b) serves only to enable use of the work with that
126 Major Component, or to implement a Standard Interface for which an
127 implementation is available to the public in source code form. A
128 "Major Component", in this context, means a major essential component
129 (kernel, window system, and so on) of the specific operating system
130 (if any) on which the executable work runs, or a compiler used to
131 produce the work, or an object code interpreter used to run it.
132
133 The "Corresponding Source" for a work in object code form means all
134 the source code needed to generate, install, and (for an executable
135 work) run the object code and to modify the work, including scripts to
136 control those activities. However, it does not include the work's
137 System Libraries, or general-purpose tools or generally available free
138 programs which are used unmodified in performing those activities but
139 which are not part of the work. For example, Corresponding Source
140 includes interface definition files associated with source files for
141 the work, and the source code for shared libraries and dynamically
142 linked subprograms that the work is specifically designed to require,
143 such as by intimate data communication or control flow between those
144 subprograms and other parts of the work.
145
146 The Corresponding Source need not include anything that users
147 can regenerate automatically from other parts of the Corresponding
148 Source.
149
150 The Corresponding Source for a work in source code form is that
151 same work.
152
153 2. Basic Permissions.
154
155 All rights granted under this License are granted for the term of
156 copyright on the Program, and are irrevocable provided the stated
157 conditions are met. This License explicitly affirms your unlimited
158 permission to run the unmodified Program. The output from running a
159 covered work is covered by this License only if the output, given its
160 content, constitutes a covered work. This License acknowledges your
161 rights of fair use or other equivalent, as provided by copyright law.
162
163 You may make, run and propagate covered works that you do not
164 convey, without conditions so long as your license otherwise remains
165 in force. You may convey covered works to others for the sole purpose
166 of having them make modifications exclusively for you, or provide you
167 with facilities for running those works, provided that you comply with
168 the terms of this License in conveying all material for which you do
169 not control copyright. Those thus making or running the covered works
170 for you must do so exclusively on your behalf, under your direction
171 and control, on terms that prohibit them from making any copies of
172 your copyrighted material outside their relationship with you.
173
174 Conveying under any other circumstances is permitted solely under
175 the conditions stated below. Sublicensing is not allowed; section 10
176 makes it unnecessary.
177
178 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
179
180 No covered work shall be deemed part of an effective technological
181 measure under any applicable law fulfilling obligations under article
182 11 of the WIPO copyright treaty adopted on 20 December 1996, or
183 similar laws prohibiting or restricting circumvention of such
184 measures.
185
186 When you convey a covered work, you waive any legal power to forbid
187 circumvention of technological measures to the extent such circumvention
188 is effected by exercising rights under this License with respect to
189 the covered work, and you disclaim any intention to limit operation or
190 modification of the work as a means of enforcing, against the work's
191 users, your or third parties' legal rights to forbid circumvention of
192 technological measures.
193
194 4. Conveying Verbatim Copies.
195
196 You may convey verbatim copies of the Program's source code as you
197 receive it, in any medium, provided that you conspicuously and
198 appropriately publish on each copy an appropriate copyright notice;
199 keep intact all notices stating that this License and any
200 non-permissive terms added in accord with section 7 apply to the code;
201 keep intact all notices of the absence of any warranty; and give all
202 recipients a copy of this License along with the Program.
203
204 You may charge any price or no price for each copy that you convey,
205 and you may offer support or warranty protection for a fee.
206
207 5. Conveying Modified Source Versions.
208
209 You may convey a work based on the Program, or the modifications to
210 produce it from the Program, in the form of source code under the
211 terms of section 4, provided that you also meet all of these conditions:
212
213 a) The work must carry prominent notices stating that you modified
214 it, and giving a relevant date.
215
216 b) The work must carry prominent notices stating that it is
217 released under this License and any conditions added under section
218 7. This requirement modifies the requirement in section 4 to
219 "keep intact all notices".
220
221 c) You must license the entire work, as a whole, under this
222 License to anyone who comes into possession of a copy. This
223 License will therefore apply, along with any applicable section 7
224 additional terms, to the whole of the work, and all its parts,
225 regardless of how they are packaged. This License gives no
226 permission to license the work in any other way, but it does not
227 invalidate such permission if you have separately received it.
228
229 d) If the work has interactive user interfaces, each must display
230 Appropriate Legal Notices; however, if the Program has interactive
231 interfaces that do not display Appropriate Legal Notices, your
232 work need not make them do so.
233
234 A compilation of a covered work with other separate and independent
235 works, which are not by their nature extensions of the covered work,
236 and which are not combined with it such as to form a larger program,
237 in or on a volume of a storage or distribution medium, is called an
238 "aggregate" if the compilation and its resulting copyright are not
239 used to limit the access or legal rights of the compilation's users
240 beyond what the individual works permit. Inclusion of a covered work
241 in an aggregate does not cause this License to apply to the other
242 parts of the aggregate.
243
244 6. Conveying Non-Source Forms.
245
246 You may convey a covered work in object code form under the terms
247 of sections 4 and 5, provided that you also convey the
248 machine-readable Corresponding Source under the terms of this License,
249 in one of these ways:
250
251 a) Convey the object code in, or embodied in, a physical product
252 (including a physical distribution medium), accompanied by the
253 Corresponding Source fixed on a durable physical medium
254 customarily used for software interchange.
255
256 b) Convey the object code in, or embodied in, a physical product
257 (including a physical distribution medium), accompanied by a
258 written offer, valid for at least three years and valid for as
259 long as you offer spare parts or customer support for that product
260 model, to give anyone who possesses the object code either (1) a
261 copy of the Corresponding Source for all the software in the
262 product that is covered by this License, on a durable physical
263 medium customarily used for software interchange, for a price no
264 more than your reasonable cost of physically performing this
265 conveying of source, or (2) access to copy the
266 Corresponding Source from a network server at no charge.
267
268 c) Convey individual copies of the object code with a copy of the
269 written offer to provide the Corresponding Source. This
270 alternative is allowed only occasionally and noncommercially, and
271 only if you received the object code with such an offer, in accord
272 with subsection 6b.
273
274 d) Convey the object code by offering access from a designated
275 place (gratis or for a charge), and offer equivalent access to the
276 Corresponding Source in the same way through the same place at no
277 further charge. You need not require recipients to copy the
278 Corresponding Source along with the object code. If the place to
279 copy the object code is a network server, the Corresponding Source
280 may be on a different server (operated by you or a third party)
281 that supports equivalent copying facilities, provided you maintain
282 clear directions next to the object code saying where to find the
283 Corresponding Source. Regardless of what server hosts the
284 Corresponding Source, you remain obligated to ensure that it is
285 available for as long as needed to satisfy these requirements.
286
287 e) Convey the object code using peer-to-peer transmission, provided
288 you inform other peers where the object code and Corresponding
289 Source of the work are being offered to the general public at no
290 charge under subsection 6d.
291
292 A separable portion of the object code, whose source code is excluded
293 from the Corresponding Source as a System Library, need not be
294 included in conveying the object code work.
295
296 A "User Product" is either (1) a "consumer product", which means any
297 tangible personal property which is normally used for personal, family,
298 or household purposes, or (2) anything designed or sold for incorporation
299 into a dwelling. In determining whether a product is a consumer product,
300 doubtful cases shall be resolved in favor of coverage. For a particular
301 product received by a particular user, "normally used" refers to a
302 typical or common use of that class of product, regardless of the status
303 of the particular user or of the way in which the particular user
304 actually uses, or expects or is expected to use, the product. A product
305 is a consumer product regardless of whether the product has substantial
306 commercial, industrial or non-consumer uses, unless such uses represent
307 the only significant mode of use of the product.
308
309 "Installation Information" for a User Product means any methods,
310 procedures, authorization keys, or other information required to install
311 and execute modified versions of a covered work in that User Product from
312 a modified version of its Corresponding Source. The information must
313 suffice to ensure that the continued functioning of the modified object
314 code is in no case prevented or interfered with solely because
315 modification has been made.
316
317 If you convey an object code work under this section in, or with, or
318 specifically for use in, a User Product, and the conveying occurs as
319 part of a transaction in which the right of possession and use of the
320 User Product is transferred to the recipient in perpetuity or for a
321 fixed term (regardless of how the transaction is characterized), the
322 Corresponding Source conveyed under this section must be accompanied
323 by the Installation Information. But this requirement does not apply
324 if neither you nor any third party retains the ability to install
325 modified object code on the User Product (for example, the work has
326 been installed in ROM).
327
328 The requirement to provide Installation Information does not include a
329 requirement to continue to provide support service, warranty, or updates
330 for a work that has been modified or installed by the recipient, or for
331 the User Product in which it has been modified or installed. Access to a
332 network may be denied when the modification itself materially and
333 adversely affects the operation of the network or violates the rules and
334 protocols for communication across the network.
335
336 Corresponding Source conveyed, and Installation Information provided,
337 in accord with this section must be in a format that is publicly
338 documented (and with an implementation available to the public in
339 source code form), and must require no special password or key for
340 unpacking, reading or copying.
341
342 7. Additional Terms.
343
344 "Additional permissions" are terms that supplement the terms of this
345 License by making exceptions from one or more of its conditions.
346 Additional permissions that are applicable to the entire Program shall
347 be treated as though they were included in this License, to the extent
348 that they are valid under applicable law. If additional permissions
349 apply only to part of the Program, that part may be used separately
350 under those permissions, but the entire Program remains governed by
351 this License without regard to the additional permissions.
352
353 When you convey a copy of a covered work, you may at your option
354 remove any additional permissions from that copy, or from any part of
355 it. (Additional permissions may be written to require their own
356 removal in certain cases when you modify the work.) You may place
357 additional permissions on material, added by you to a covered work,
358 for which you have or can give appropriate copyright permission.
359
360 Notwithstanding any other provision of this License, for material you
361 add to a covered work, you may (if authorized by the copyright holders of
362 that material) supplement the terms of this License with terms:
363
364 a) Disclaiming warranty or limiting liability differently from the
365 terms of sections 15 and 16 of this License; or
366
367 b) Requiring preservation of specified reasonable legal notices or
368 author attributions in that material or in the Appropriate Legal
369 Notices displayed by works containing it; or
370
371 c) Prohibiting misrepresentation of the origin of that material, or
372 requiring that modified versions of such material be marked in
373 reasonable ways as different from the original version; or
374
375 d) Limiting the use for publicity purposes of names of licensors or
376 authors of the material; or
377
378 e) Declining to grant rights under trademark law for use of some
379 trade names, trademarks, or service marks; or
380
381 f) Requiring indemnification of licensors and authors of that
382 material by anyone who conveys the material (or modified versions of
383 it) with contractual assumptions of liability to the recipient, for
384 any liability that these contractual assumptions directly impose on
385 those licensors and authors.
386
387 All other non-permissive additional terms are considered "further
388 restrictions" within the meaning of section 10. If the Program as you
389 received it, or any part of it, contains a notice stating that it is
390 governed by this License along with a term that is a further
391 restriction, you may remove that term. If a license document contains
392 a further restriction but permits relicensing or conveying under this
393 License, you may add to a covered work material governed by the terms
394 of that license document, provided that the further restriction does
395 not survive such relicensing or conveying.
396
397 If you add terms to a covered work in accord with this section, you
398 must place, in the relevant source files, a statement of the
399 additional terms that apply to those files, or a notice indicating
400 where to find the applicable terms.
401
402 Additional terms, permissive or non-permissive, may be stated in the
403 form of a separately written license, or stated as exceptions;
404 the above requirements apply either way.
405
406 8. Termination.
407
408 You may not propagate or modify a covered work except as expressly
409 provided under this License. Any attempt otherwise to propagate or
410 modify it is void, and will automatically terminate your rights under
411 this License (including any patent licenses granted under the third
412 paragraph of section 11).
413
414 However, if you cease all violation of this License, then your
415 license from a particular copyright holder is reinstated (a)
416 provisionally, unless and until the copyright holder explicitly and
417 finally terminates your license, and (b) permanently, if the copyright
418 holder fails to notify you of the violation by some reasonable means
419 prior to 60 days after the cessation.
420
421 Moreover, your license from a particular copyright holder is
422 reinstated permanently if the copyright holder notifies you of the
423 violation by some reasonable means, this is the first time you have
424 received notice of violation of this License (for any work) from that
425 copyright holder, and you cure the violation prior to 30 days after
426 your receipt of the notice.
427
428 Termination of your rights under this section does not terminate the
429 licenses of parties who have received copies or rights from you under
430 this License. If your rights have been terminated and not permanently
431 reinstated, you do not qualify to receive new licenses for the same
432 material under section 10.
433
434 9. Acceptance Not Required for Having Copies.
435
436 You are not required to accept this License in order to receive or
437 run a copy of the Program. Ancillary propagation of a covered work
438 occurring solely as a consequence of using peer-to-peer transmission
439 to receive a copy likewise does not require acceptance. However,
440 nothing other than this License grants you permission to propagate or
441 modify any covered work. These actions infringe copyright if you do
442 not accept this License. Therefore, by modifying or propagating a
443 covered work, you indicate your acceptance of this License to do so.
444
445 10. Automatic Licensing of Downstream Recipients.
446
447 Each time you convey a covered work, the recipient automatically
448 receives a license from the original licensors, to run, modify and
449 propagate that work, subject to this License. You are not responsible
450 for enforcing compliance by third parties with this License.
451
452 An "entity transaction" is a transaction transferring control of an
453 organization, or substantially all assets of one, or subdividing an
454 organization, or merging organizations. If propagation of a covered
455 work results from an entity transaction, each party to that
456 transaction who receives a copy of the work also receives whatever
457 licenses to the work the party's predecessor in interest had or could
458 give under the previous paragraph, plus a right to possession of the
459 Corresponding Source of the work from the predecessor in interest, if
460 the predecessor has it or can get it with reasonable efforts.
461
462 You may not impose any further restrictions on the exercise of the
463 rights granted or affirmed under this License. For example, you may
464 not impose a license fee, royalty, or other charge for exercise of
465 rights granted under this License, and you may not initiate litigation
466 (including a cross-claim or counterclaim in a lawsuit) alleging that
467 any patent claim is infringed by making, using, selling, offering for
468 sale, or importing the Program or any portion of it.
469
470 11. Patents.
471
472 A "contributor" is a copyright holder who authorizes use under this
473 License of the Program or a work on which the Program is based. The
474 work thus licensed is called the contributor's "contributor version".
475
476 A contributor's "essential patent claims" are all patent claims
477 owned or controlled by the contributor, whether already acquired or
478 hereafter acquired, that would be infringed by some manner, permitted
479 by this License, of making, using, or selling its contributor version,
480 but do not include claims that would be infringed only as a
481 consequence of further modification of the contributor version. For
482 purposes of this definition, "control" includes the right to grant
483 patent sublicenses in a manner consistent with the requirements of
484 this License.
485
486 Each contributor grants you a non-exclusive, worldwide, royalty-free
487 patent license under the contributor's essential patent claims, to
488 make, use, sell, offer for sale, import and otherwise run, modify and
489 propagate the contents of its contributor version.
490
491 In the following three paragraphs, a "patent license" is any express
492 agreement or commitment, however denominated, not to enforce a patent
493 (such as an express permission to practice a patent or covenant not to
494 sue for patent infringement). To "grant" such a patent license to a
495 party means to make such an agreement or commitment not to enforce a
496 patent against the party.
497
498 If you convey a covered work, knowingly relying on a patent license,
499 and the Corresponding Source of the work is not available for anyone
500 to copy, free of charge and under the terms of this License, through a
501 publicly available network server or other readily accessible means,
502 then you must either (1) cause the Corresponding Source to be so
503 available, or (2) arrange to deprive yourself of the benefit of the
504 patent license for this particular work, or (3) arrange, in a manner
505 consistent with the requirements of this License, to extend the patent
506 license to downstream recipients. "Knowingly relying" means you have
507 actual knowledge that, but for the patent license, your conveying the
508 covered work in a country, or your recipient's use of the covered work
509 in a country, would infringe one or more identifiable patents in that
510 country that you have reason to believe are valid.
511
512 If, pursuant to or in connection with a single transaction or
513 arrangement, you convey, or propagate by procuring conveyance of, a
514 covered work, and grant a patent license to some of the parties
515 receiving the covered work authorizing them to use, propagate, modify
516 or convey a specific copy of the covered work, then the patent license
517 you grant is automatically extended to all recipients of the covered
518 work and works based on it.
519
520 A patent license is "discriminatory" if it does not include within
521 the scope of its coverage, prohibits the exercise of, or is
522 conditioned on the non-exercise of one or more of the rights that are
523 specifically granted under this License. You may not convey a covered
524 work if you are a party to an arrangement with a third party that is
525 in the business of distributing software, under which you make payment
526 to the third party based on the extent of your activity of conveying
527 the work, and under which the third party grants, to any of the
528 parties who would receive the covered work from you, a discriminatory
529 patent license (a) in connection with copies of the covered work
530 conveyed by you (or copies made from those copies), or (b) primarily
531 for and in connection with specific products or compilations that
532 contain the covered work, unless you entered into that arrangement,
533 or that patent license was granted, prior to 28 March 2007.
534
535 Nothing in this License shall be construed as excluding or limiting
536 any implied license or other defenses to infringement that may
537 otherwise be available to you under applicable patent law.
538
539 12. No Surrender of Others' Freedom.
540
541 If conditions are imposed on you (whether by court order, agreement or
542 otherwise) that contradict the conditions of this License, they do not
543 excuse you from the conditions of this License. If you cannot convey a
544 covered work so as to satisfy simultaneously your obligations under this
545 License and any other pertinent obligations, then as a consequence you may
546 not convey it at all. For example, if you agree to terms that obligate you
547 to collect a royalty for further conveying from those to whom you convey
548 the Program, the only way you could satisfy both those terms and this
549 License would be to refrain entirely from conveying the Program.
550
551 13. Use with the GNU Affero General Public License.
552
553 Notwithstanding any other provision of this License, you have
554 permission to link or combine any covered work with a work licensed
555 under version 3 of the GNU Affero General Public License into a single
556 combined work, and to convey the resulting work. The terms of this
557 License will continue to apply to the part which is the covered work,
558 but the special requirements of the GNU Affero General Public License,
559 section 13, concerning interaction through a network will apply to the
560 combination as such.
561
562 14. Revised Versions of this License.
563
564 The Free Software Foundation may publish revised and/or new versions of
565 the GNU General Public License from time to time. Such new versions will
566 be similar in spirit to the present version, but may differ in detail to
567 address new problems or concerns.
568
569 Each version is given a distinguishing version number. If the
570 Program specifies that a certain numbered version of the GNU General
571 Public License "or any later version" applies to it, you have the
572 option of following the terms and conditions either of that numbered
573 version or of any later version published by the Free Software
574 Foundation. If the Program does not specify a version number of the
575 GNU General Public License, you may choose any version ever published
576 by the Free Software Foundation.
577
578 If the Program specifies that a proxy can decide which future
579 versions of the GNU General Public License can be used, that proxy's
580 public statement of acceptance of a version permanently authorizes you
581 to choose that version for the Program.
582
583 Later license versions may give you additional or different
584 permissions. However, no additional obligations are imposed on any
585 author or copyright holder as a result of your choosing to follow a
586 later version.
587
588 15. Disclaimer of Warranty.
589
590 THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
591 APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
592 HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
593 OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
594 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
595 PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
596 IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
597 ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
598
599 16. Limitation of Liability.
600
601 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
602 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
603 THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
604 GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
605 USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
606 DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
607 PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
608 EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
609 SUCH DAMAGES.
610
611 17. Interpretation of Sections 15 and 16.
612
613 If the disclaimer of warranty and limitation of liability provided
614 above cannot be given local legal effect according to their terms,
615 reviewing courts shall apply local law that most closely approximates
616 an absolute waiver of all civil liability in connection with the
617 Program, unless a warranty or assumption of liability accompanies a
618 copy of the Program in return for a fee.
619
620 END OF TERMS AND CONDITIONS
621
622 How to Apply These Terms to Your New Programs
623
624 If you develop a new program, and you want it to be of the greatest
625 possible use to the public, the best way to achieve this is to make it
626 free software which everyone can redistribute and change under these terms.
627
628 To do so, attach the following notices to the program. It is safest
629 to attach them to the start of each source file to most effectively
630 state the exclusion of warranty; and each file should have at least
631 the "copyright" line and a pointer to where the full notice is found.
632
633 <one line to give the program's name and a brief idea of what it does.>
634 Copyright (C) <year> <name of author>
635
636 This program is free software: you can redistribute it and/or modify
637 it under the terms of the GNU General Public License as published by
638 the Free Software Foundation, either version 3 of the License, or
639 (at your option) any later version.
640
641 This program is distributed in the hope that it will be useful,
642 but WITHOUT ANY WARRANTY; without even the implied warranty of
643 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
644 GNU General Public License for more details.
645
646 You should have received a copy of the GNU General Public License
647 along with this program. If not, see <http://www.gnu.org/licenses/>.
648
649 Also add information on how to contact you by electronic and paper mail.
650
651 If the program does terminal interaction, make it output a short
652 notice like this when it starts in an interactive mode:
653
654 <program> Copyright (C) <year> <name of author>
655 This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
656 This is free software, and you are welcome to redistribute it
657 under certain conditions; type `show c' for details.
658
659 The hypothetical commands `show w' and `show c' should show the appropriate
660 parts of the General Public License. Of course, your program's commands
661 might be different; for a GUI interface, you would use an "about box".
662
663 You should also get your employer (if you work as a programmer) or school,
664 if any, to sign a "copyright disclaimer" for the program, if necessary.
665 For more information on this, and how to apply and follow the GNU GPL, see
666 <http://www.gnu.org/licenses/>.
667
668 The GNU General Public License does not permit incorporating your program
669 into proprietary programs. If your program is a subroutine library, you
670 may consider it more useful to permit linking proprietary applications with
671 the library. If this is what you want to do, use the GNU Lesser General
672 Public License instead of this License. But first, please read
673 <http://www.gnu.org/philosophy/why-not-lgpl.html>.
+0
-50
Ops.hs less more
0 {-# LANGUAGE OverloadedStrings #-}
1
2 module Ops (loadOps) where
3
4 import AST
5 import AstUtils
6 import CompileDefs
7
8 loadOpsExpr :: Expr -> Artifact Expr
9 loadOpsExpr e@(Apply hd rest) =
10 case hd of
11 Id "+" -> return $ Add rest
12 Id "*" -> return $ Mul rest
13 Id "-" -> createSub rest
14 Id "/" -> binop "/" Div
15 Id "^" -> binop "^" Pow
16 Id "<" -> binop "<" Lt
17 Id ">" -> binop ">" Gt
18 Id "<=" -> binop "<=" LtE
19 Id ">=" -> binop ">=" GtE
20 Id "if" -> createIf rest
21 Id "$" -> createNative rest
22 _ -> return e
23 where binop opname ctor =
24 if length rest == 2
25 then return $ ctor (rest !! 0) (rest !! 1)
26 else Failure $ BadArity opname 2 (length rest)
27 createSub exprs =
28 case exprs of
29 [x] -> return $ Negate x
30 [x, y] -> return $ Sub x y
31 _ -> Failure $ BadArity "-" 2 (length exprs)
32 createIf exprs =
33 if length exprs == 3
34 then return $ If (rest !! 0) (rest !! 1) (rest !! 2)
35 else Failure $ BadArity "if" 3 (length exprs)
36 createNative exprs =
37 case exprs of
38 [] -> Failure $ BadArity "$" 1 (length exprs)
39 (name:args) ->
40 case name of
41 Id n -> return $ NativeCall n args
42 _ -> Failure $ BadNativeName name e
43 loadOpsExpr e = return e
44
45 loadOpsForm :: Form -> Artifact Form
46 loadOpsForm (Define n ret a b) = mapexprM loadOpsExpr b >>= return . Define n ret a
47
48 loadOps :: AST -> Artifact AST
49 loadOps a = mapM loadOpsForm (getAstMap a) >>= return . AST
+0
-20
ParseDump.hs less more
0 {-# LANGUAGE OverloadedStrings #-}
1
2 module Main where
3 import AST
4 import AstUtils
5 import Control.DeepSeq
6 import Debug.Trace
7 import qualified Data.Map.Strict as Map
8 import qualified Data.Text as T
9 import qualified Reader
10 import CompileDefs
11
12 printAllExprs :: Form -> IO Expr
13 printAllExprs (Define n a b) = mapexprM (\x -> print x >> return x) b
14
15 main =
16 do prog <- getContents >>= return . T.pack
17 case Reader.read prog of
18 Failure e -> putStr "parsing failed: " >> print e
19 Success ast -> print ast >> mapM_ printAllExprs ast
+0
-31
Properties.hs less more
0 module Properties (checkRoot, checkRootType, checkRecursive) where
1
2 import AST
3 import AstUtils
4 import CompileDefs
5
6 import qualified Data.Map.Strict as Map
7
8 -- Make sure that a root function is defined
9 checkRoot :: AST -> Artifact AST
10 checkRoot a@(AST m) =
11 if Map.member rootKey m
12 then return a
13 else Failure MissingRootError
14
15 -- Make sure the root function returns a color
16 checkRootType :: AST -> Artifact AST
17 checkRootType a@(AST m) =
18 let (Define _ ret _ _) = m Map.! rootKey in
19 case ret of
20 ColorType -> return a
21 _ -> Failure (BadRootType ret)
22
23 -- Ensure that there are no recursive methods in the workspace
24 checkRecursive :: AST -> Artifact AST
25 checkRecursive (AST m) = check (Map.elems m)
26 where check l = case l of
27 (Define n _ _ e):xs -> if containsName n e
28 then Failure (RecursionError n)
29 else check xs
30 [] -> Success (AST m)
+0
-93
Reader.hs less more
0 {-# LANGUAGE OverloadedStrings #-}
1 {-# LANGUAGE RankNTypes #-}
2 {-# OPTIONS_GHC -Wno-missing-signatures #-}
3
4 module Reader (Reader.read) where
5 import AST
6 import CompileDefs
7 import qualified Data.Functor.Identity as Id
8 import qualified Data.Text as T
9
10 import Text.Parsec
11 import qualified Text.Parsec.Text as PT
12 import qualified Text.Parsec.Token as Token
13
14 lang :: Token.GenLanguageDef T.Text () Id.Identity
15 lang = Token.LanguageDef { Token.commentLine = "#"
16 , Token.commentStart = ""
17 , Token.commentEnd = ""
18 , Token.nestedComments = False
19 , Token.identStart = letter
20 , Token.identLetter = alphaNum <|> oneOf "-"
21 , Token.opStart = oneOf "+-*/%^>=<$"
22 , Token.opLetter = oneOf "=" -- the only two-char ops are <= and >=
23 , Token.reservedNames = ["define"]
24 , Token.reservedOpNames = []
25 , Token.caseSensitive = True
26 }
27
28 lexer :: Token.GenTokenParser T.Text () Id.Identity
29 lexer = Token.makeTokenParser lang
30
31 parens = Token.parens lexer
32 name = Token.identifier lexer >>= return . T.pack
33 ws = Token.whiteSpace lexer
34 reserved = Token.reserved lexer
35 lexeme = Token.lexeme lexer
36 op = Token.operator lexer >>= return . T.pack
37
38 typedname :: PT.Parser (T.Text, Type)
39 typedname = do
40 n <- name
41 _ <- char ':'
42 t <- name
43 return (n, NamedType t)
44
45 sign :: PT.Parser (DelNum -> DelNum)
46 sign = lexeme $ (char '-' >> return negate) <|> (char '+' >> return id) <|> return id
47
48 number :: PT.Parser Expr
49 number = do
50 s <- sign
51 nof <- Token.naturalOrFloat lexer
52 return . Number . s $ case nof of
53 Left int -> DelInt int
54 Right double -> DelFloat double
55
56 apply :: PT.Parser Expr
57 apply = parens $ do
58 hd <- expr
59 rest <- many expr
60 return $ Apply hd rest
61
62 exprNoSub :: PT.Parser Expr
63 exprNoSub = (Id <$> name)
64 <|> (Id <$> op)
65 <|> apply
66 <|> number
67 <?> "expression"
68
69 expr :: PT.Parser Expr
70 expr = do
71 e <- exprNoSub
72 option e (char '_' >> name >>= return . (Subscript e))
73
74 -- Parses a definition without the enclosing braces
75 def :: PT.Parser Form
76 def = do
77 _ <- reserved "define"
78 (n, ret) <- typedname
79 args <- parens $ many typedname
80 body <- expr
81 return $ Define n ret args body
82
83 form :: PT.Parser Form
84 form = parens def
85
86 top :: PT.Parser [Form]
87 top = ws *> many1 form
88
89 read :: T.Text -> Artifact [Form]
90 read t = case Text.Parsec.parse top "source" t of
91 Left err -> Failure (ReadError err)
92 Right exprs -> return exprs
0 import Distribution.Simple
1 main = defaultMain
+0
-94
TypeCheck.hs less more
0 {-# LANGUAGE OverloadedStrings #-}
1
2 module TypeCheck (typeCheck) where
3
4 import AST
5 import qualified Builtins as B
6 import CompileDefs
7 import qualified Data.Map.Strict as Map
8 import qualified Data.Text as T
9 import qualified Data.Traversable as Tr
10
11 data TypeContext = TypeContext AST (Map.Map T.Text Type)
12
13 f3Subscripts :: [T.Text]
14 f3Subscripts = ["0", "1", "2", "x", "y", "z"]
15
16 newContext :: AST -> TypeContext
17 newContext ast@(AST m) = TypeContext ast $ Map.union (Map.map deftypes m) builtins
18 where deftypes (Define _ r a _) = FuncType (map snd a) r
19 builtins = Map.map B.getType B.builtins
20
21 eq :: T.Text -> Expr -> (Type, Type, Int) -> Artifact ()
22 eq n e (ex, ac, i)
23 = if ex == ac then return () else Failure $ BadArgType n ex ac i e
24
25 unify :: TypeContext -> Expr -> T.Text -> [Expr] -> Artifact Type
26 unify _ _ n [] = Failure . SystemError $ T.append "tried to unify empty expr list for " n
27 unify tc _ _ [x] = exprType tc x
28 unify tc e n (x:xs) = do
29 t <- exprType tc x
30 ts <- mapM (exprType tc) xs
31 mapM (eq n e) (zip3 (repeat t) ts [2..]) >> return t
32
33 subType :: T.Text -> Type -> Artifact Type
34 subType sub Float3Type = if elem sub f3Subscripts
35 then return FloatType
36 else Failure $ BadSubscript Float3Type sub f3Subscripts
37 subType sub t = Failure $ Unsubscriptable t sub
38
39 checkZip :: Expr -> Expr -> [Type] -> [Type] -> Artifact ()
40 checkZip hd e ex ac
41 = if length ex /= length ac
42 then Failure $ BadArity (T.pack $ show hd) (length ex) (length ac)
43 else mapM (eq (T.pack $ show hd) e) (zip3 ex ac [1..]) >> return ()
44
45 applyType :: TypeContext -> Expr -> Expr -> [Expr] -> Artifact Type
46 applyType tc e hd args = exprType tc hd >>= checkApply
47 where checkApply (FuncType atypes rtype) =
48 mapM (exprType tc) args >>= checkZip hd e atypes >> return rtype
49 checkApply t = Failure $ BadApplyHead hd t
50
51 exprType :: TypeContext -> Expr -> Artifact Type
52 exprType tc@(TypeContext ast types) e
53 = let u = unify tc e in case e of
54 Add xs -> u "+" xs
55 Mul xs -> u "*" xs
56 Sub x1 x2 -> u "-" [x1, x2]
57 Div x1 x2 -> u "/" [x1, x2]
58 Pow x1 x2 -> u "^" [x1, x2]
59 Gt x1 x2 -> u ">" [x1, x2] >> return BoolType
60 Lt x1 x2 -> u "<" [x1, x2] >> return BoolType
61 GtE x1 x2 -> u ">=" [x1, x2] >> return BoolType
62 LtE x1 x2 -> u "<=" [x1, x2] >> return BoolType
63 Negate x -> exprType tc x
64 Subscript x s -> exprType tc x >>= subType s
65 Apply x args -> applyType tc e x args
66 NativeCall n args -> applyType tc e (Id n) args
67 Id name -> case Map.lookup name types of
68 Just t -> return t
69 Nothing -> Failure $ BadId name
70 Number (DelInt _) -> return IntType
71 Number (DelFloat _) -> return FloatType
72 Boolean _ -> return BoolType
73 Let n v b ->
74 exprType tc v >>= \vtype ->
75 let tc' = TypeContext ast (Map.insert n vtype types)
76 in exprType tc' b
77 If c t f -> do
78 ct <- exprType tc c
79 tt <- exprType tc t
80 ft <- exprType tc f
81 if ct /= BoolType
82 then Failure $ BadIfCondition ct e
83 else if tt /= ft
84 then Failure $ IfTypeMismatch tt ft e
85 else return tt
86
87 checkDef :: TypeContext -> Form -> Artifact ()
88 checkDef (TypeContext ast types) (Define n r a b)
89 = let tc' = TypeContext ast (Map.union (Map.fromList a) types) in
90 exprType tc' b >>= \x -> if x == r then return () else Failure $ ReturnTypeMismatch n r x
91
92 typeCheck :: AST -> Artifact AST
93 typeCheck a@(AST m) = Tr.mapM (checkDef (newContext a)) m >> return a
+0
-27
Types.hs less more
0 {-# LANGUAGE OverloadedStrings #-}
1
2 module Types (parseTypes) where
3
4 import AST
5 import CompileDefs
6
7 parseType :: Type -> Artifact Type
8 parseType (NamedType "f") = return FloatType
9 parseType (NamedType "f3") = return Float3Type
10 parseType (NamedType "i") = return IntType
11 parseType (NamedType "b") = return BoolType
12 parseType (NamedType "color") = return ColorType
13 parseType (NamedType tn) = Failure (BadTypeName tn)
14 parseType t = return t
15
16 parseArgType :: (Name, Type) -> Artifact (Name, Type)
17 parseArgType (n, t) = parseType t >>= \newt -> return (n, newt)
18
19 parseTypes' :: Form -> Artifact Form
20 parseTypes' (Define n r a b) = do
21 args <- mapM parseArgType a
22 ret <- parseType r
23 return $ Define n ret args b
24
25 parseTypes :: AST -> Artifact AST
26 parseTypes (AST m) = mapM parseTypes' m >>= return . AST
+0
-1222
builtins.txt less more
0 float radians(float degrees);
1 vec2 radians(vec2 degrees);
2 vec3 radians(vec3 degrees);
3 vec4 radians(vec4 degrees);
4
5 float degrees(float radians);
6 vec2 degrees(vec2 radians);
7 vec3 degrees(vec3 radians);
8 vec4 degrees(vec4 radians);
9
10 float sin(float angle);
11 vec2 sin(vec2 angle);
12 vec3 sin(vec3 angle);
13 vec4 sin(vec4 angle);
14
15 float cos(float angle);
16 vec2 cos(vec2 angle);
17 vec3 cos(vec3 angle);
18 vec4 cos(vec4 angle);
19
20 float tan(float angle);
21 vec2 tan(vec2 angle);
22 vec3 tan(vec3 angle);
23 vec4 tan(vec4 angle);
24
25 float asin(float x);
26 vec2 asin(vec2 x);
27 vec3 asin(vec3 x);
28 vec4 asin(vec4 x);
29
30 float acos(float x);
31 vec2 acos(vec2 x);
32 vec3 acos(vec3 x);
33 vec4 acos(vec4 x);
34
35 float atan(float y, float x);
36 vec2 atan(vec2 y, vec2 x);
37 vec3 atan(vec3 y, vec3 x);
38 vec4 atan(vec4 y, vec4 x);
39
40 float atan(float y_over_x);
41 vec2 atan(vec2 y_over_x);
42 vec3 atan(vec3 y_over_x);
43 vec4 atan(vec4 y_over_x);
44 float sinh(float angle);
45 vec2 sinh(vec2 angle);
46 vec3 sinh(vec3 angle);
47 vec4 sinh(vec4 angle);
48
49 float cosh(float angle);
50 vec2 cosh(vec2 angle);
51 vec3 cosh(vec3 angle);
52 vec4 cosh(vec4 angle);
53
54 float tanh(float angle);
55 vec2 tanh(vec2 angle);
56 vec3 tanh(vec3 angle);
57 vec4 tanh(vec4 angle);
58
59 float asinh(float x);
60 vec2 asinh(vec2 x);
61 vec3 asinh(vec3 x);
62 vec4 asinh(vec4 x);
63
64 float acosh(float x);
65 vec2 acosh(vec2 x);
66 vec3 acosh(vec3 x);
67 vec4 acosh(vec4 x);
68
69 float atanh(float y_over_x);
70 vec2 atanh(vec2 y_over_x);
71 vec3 atanh(vec3 y_over_x);
72 vec4 atanh(vec4 y_over_x);
73 float pow(float x, float y);
74 vec2 pow(vec2 x, vec2 y);
75 vec3 pow(vec3 x, vec3 y);
76 vec4 pow(vec4 x, vec4 y);
77
78 float exp(float x);
79 vec2 exp(vec2 x);
80 vec3 exp(vec3 x);
81 vec4 exp(vec4 x);
82
83 float log(float x);
84 vec2 log(vec2 x);
85 vec3 log(vec3 x);
86 vec4 log(vec4 x);
87
88 float exp2(float x);
89 vec2 exp2(vec2 x);
90 vec3 exp2(vec3 x);
91 vec4 exp2(vec4 x);
92
93 float log2(float x);
94 vec2 log2(vec2 x);
95 vec3 log2(vec3 x);
96 vec4 log2(vec4 x);
97
98 float sqrt(float x);
99 vec2 sqrt(vec2 x);
100 vec3 sqrt(vec3 x);
101 vec4 sqrt(vec4 x);
102
103 float inversesqrt(float x);
104 vec2 inversesqrt(vec2 x);
105 vec3 inversesqrt(vec3 x);
106 vec4 inversesqrt(vec4 x);
107 float abs(float x);
108 vec2 abs(vec2 x);
109 vec3 abs(vec3 x);
110 vec4 abs(vec4 x);
111
112 float sign(float x);
113 vec2 sign(vec2 x);
114 vec3 sign(vec3 x);
115 vec4 sign(vec4 x);
116
117 float floor(float x);
118 vec2 floor(vec2 x);
119 vec3 floor(vec3 x);
120 vec4 floor(vec4 x);
121
122 float ceil(float x);
123 vec2 ceil(vec2 x);
124 vec3 ceil(vec3 x);
125 vec4 ceil(vec4 x);
126
127 float fract(float x);
128 vec2 fract(vec2 x);
129 vec3 fract(vec3 x);
130 vec4 fract(vec4 x);
131
132 float mod(float x, float y);
133 vec2 mod(vec2 x, float y);
134 vec3 mod(vec3 x, float y);
135 vec4 mod(vec4 x, float y);
136 vec2 mod(vec2 x, vec2 y);
137 vec3 mod(vec3 x, vec3 y);
138 vec4 mod(vec4 x, vec4 y);
139
140 float min(float x, float y);
141 vec2 min(vec2 x, float y);
142 vec3 min(vec3 x, float y);
143 vec4 min(vec4 x, float y);
144 vec2 min(vec2 x, vec2 y);
145 vec3 min(vec3 x, vec3 y);
146 vec4 min(vec4 x, vec4 y);
147
148 float max(float x, float y);
149 vec2 max(vec2 x, float y);
150 vec3 max(vec3 x, float y);
151 vec4 max(vec4 x, float y);
152 vec2 max(vec2 x, vec2 y);
153 vec3 max(vec3 x, vec3 y);
154 vec4 max(vec4 x, vec4 y);
155
156 float clamp(float x, float minVal, float maxVal);
157 vec2 clamp(vec2 x, float minVal, float maxVal);
158 vec3 clamp(vec3 x, float minVal, float maxVal);
159 vec4 clamp(vec4 x, float minVal, float maxVal);
160 vec2 clamp(vec2 x, vec2 minVal, vec2 maxVal);
161 vec3 clamp(vec3 x, vec3 minVal, vec3 maxVal);
162 vec4 clamp(vec4 x, vec4 minVal, vec4 maxVal);
163
164 float mix(float x, float y, float a);
165 vec2 mix(vec2 x, vec2 y, float a);
166 vec3 mix(vec3 x, vec3 y, float a);
167 vec4 mix(vec4 x, vec4 y, float a);
168 vec2 mix(vec2 x, vec2 y, vec2 a);
169 vec3 mix(vec3 x, vec3 y, vec3 a);
170 vec4 mix(vec4 x, vec4 y, vec4 a);
171
172 float step(float edge, float x);
173 vec2 step(vec2 edge, vec2 x);
174 vec3 step(vec3 edge, vec3 x);
175 vec4 step(vec4 edge, vec4 x);
176 vec2 step(float edge, vec2 x);
177 vec3 step(float edge, vec3 x);
178 vec4 step(float edge, vec4 x);
179
180 float smoothstep(float edge0, float edge1, float x);
181 vec2 smoothstep(vec2 edge0, vec2 edge1, vec2 x);
182 vec3 smoothstep(vec3 edge0, vec3 edge1, vec3 x);
183 vec4 smoothstep(vec4 edge0, vec4 edge1, vec4 x);
184 vec2 smoothstep(float edge0, float edge1, vec2 x);
185 vec3 smoothstep(float edge0, float edge1, vec3 x);
186 vec4 smoothstep(float edge0, float edge1, vec4 x);
187 int abs( int x);
188 ivec2 abs(ivec2 x);
189 ivec3 abs(ivec3 x);
190 ivec4 abs(ivec4 x);
191
192 int sign( int x);
193 ivec2 sign(ivec2 x);
194 ivec3 sign(ivec3 x);
195 ivec4 sign(ivec4 x);
196
197 float trunc(float x);
198 vec2 trunc(vec2 x);
199 vec3 trunc(vec3 x);
200 vec4 trunc(vec4 x);
201
202 float round(float x);
203 vec2 round(vec2 x);
204 vec3 round(vec3 x);
205 vec4 round(vec4 x);
206
207 float roundEven(float x);
208 vec2 roundEven(vec2 x);
209 vec3 roundEven(vec3 x);
210 vec4 roundEven(vec4 x);
211
212 float modf(float, out float);
213 vec2 modf(vec2, out vec2);
214 vec3 modf(vec3, out vec3);
215 vec4 modf(vec4, out vec4);
216
217 int min(int x, int y);
218 ivec2 min(ivec2 x, int y);
219 ivec3 min(ivec3 x, int y);
220 ivec4 min(ivec4 x, int y);
221 ivec2 min(ivec2 x, ivec2 y);
222 ivec3 min(ivec3 x, ivec3 y);
223 ivec4 min(ivec4 x, ivec4 y);
224
225 uint min(uint x, uint y);
226 uvec2 min(uvec2 x, uint y);
227 uvec3 min(uvec3 x, uint y);
228 uvec4 min(uvec4 x, uint y);
229 uvec2 min(uvec2 x, uvec2 y);
230 uvec3 min(uvec3 x, uvec3 y);
231 uvec4 min(uvec4 x, uvec4 y);
232
233 int max(int x, int y);
234 ivec2 max(ivec2 x, int y);
235 ivec3 max(ivec3 x, int y);
236 ivec4 max(ivec4 x, int y);
237 ivec2 max(ivec2 x, ivec2 y);
238 ivec3 max(ivec3 x, ivec3 y);
239 ivec4 max(ivec4 x, ivec4 y);
240
241 uint max(uint x, uint y);
242 uvec2 max(uvec2 x, uint y);
243 uvec3 max(uvec3 x, uint y);
244 uvec4 max(uvec4 x, uint y);
245 uvec2 max(uvec2 x, uvec2 y);
246 uvec3 max(uvec3 x, uvec3 y);
247 uvec4 max(uvec4 x, uvec4 y);
248
249 int clamp(int x, int minVal, int maxVal);
250 ivec2 clamp(ivec2 x, int minVal, int maxVal);
251 ivec3 clamp(ivec3 x, int minVal, int maxVal);
252 ivec4 clamp(ivec4 x, int minVal, int maxVal);
253 ivec2 clamp(ivec2 x, ivec2 minVal, ivec2 maxVal);
254 ivec3 clamp(ivec3 x, ivec3 minVal, ivec3 maxVal);
255 ivec4 clamp(ivec4 x, ivec4 minVal, ivec4 maxVal);
256
257 uint clamp(uint x, uint minVal, uint maxVal);
258 uvec2 clamp(uvec2 x, uint minVal, uint maxVal);
259 uvec3 clamp(uvec3 x, uint minVal, uint maxVal);
260 uvec4 clamp(uvec4 x, uint minVal, uint maxVal);
261 uvec2 clamp(uvec2 x, uvec2 minVal, uvec2 maxVal);
262 uvec3 clamp(uvec3 x, uvec3 minVal, uvec3 maxVal);
263 uvec4 clamp(uvec4 x, uvec4 minVal, uvec4 maxVal);
264
265 float mix(float x, float y, bool a);
266 vec2 mix(vec2 x, vec2 y, bvec2 a);
267 vec3 mix(vec3 x, vec3 y, bvec3 a);
268 vec4 mix(vec4 x, vec4 y, bvec4 a);
269
270 bool isnan(float x);
271 bvec2 isnan(vec2 x);
272 bvec3 isnan(vec3 x);
273 bvec4 isnan(vec4 x);
274
275 bool isinf(float x);
276 bvec2 isinf(vec2 x);
277 bvec3 isinf(vec3 x);
278 bvec4 isinf(vec4 x);
279
280 double sqrt(double);
281 dvec2 sqrt(dvec2);
282 dvec3 sqrt(dvec3);
283 dvec4 sqrt(dvec4);
284
285 double inversesqrt(double);
286 dvec2 inversesqrt(dvec2);
287 dvec3 inversesqrt(dvec3);
288 dvec4 inversesqrt(dvec4);
289
290 double abs(double);
291 dvec2 abs(dvec2);
292 dvec3 abs(dvec3);
293 dvec4 abs(dvec4);
294
295 double sign(double);
296 dvec2 sign(dvec2);
297 dvec3 sign(dvec3);
298 dvec4 sign(dvec4);
299
300 double floor(double);
301 dvec2 floor(dvec2);
302 dvec3 floor(dvec3);
303 dvec4 floor(dvec4);
304
305 double trunc(double);
306 dvec2 trunc(dvec2);
307 dvec3 trunc(dvec3);
308 dvec4 trunc(dvec4);
309
310 double round(double);
311 dvec2 round(dvec2);
312 dvec3 round(dvec3);
313 dvec4 round(dvec4);
314
315 double roundEven(double);
316 dvec2 roundEven(dvec2);
317 dvec3 roundEven(dvec3);
318 dvec4 roundEven(dvec4);
319
320 double ceil(double);
321 dvec2 ceil(dvec2);
322 dvec3 ceil(dvec3);
323 dvec4 ceil(dvec4);
324
325 double fract(double);
326 dvec2 fract(dvec2);
327 dvec3 fract(dvec3);
328 dvec4 fract(dvec4);
329
330 double mod(double, double);
331 dvec2 mod(dvec2 , double);
332 dvec3 mod(dvec3 , double);
333 dvec4 mod(dvec4 , double);
334 dvec2 mod(dvec2 , dvec2);
335 dvec3 mod(dvec3 , dvec3);
336 dvec4 mod(dvec4 , dvec4);
337
338 double modf(double, out double);
339 dvec2 modf(dvec2, out dvec2);
340 dvec3 modf(dvec3, out dvec3);
341 dvec4 modf(dvec4, out dvec4);
342
343 double min(double, double);
344 dvec2 min(dvec2, double);
345 dvec3 min(dvec3, double);
346 dvec4 min(dvec4, double);
347 dvec2 min(dvec2, dvec2);
348 dvec3 min(dvec3, dvec3);
349 dvec4 min(dvec4, dvec4);
350
351 double max(double, double);
352 dvec2 max(dvec2 , double);
353 dvec3 max(dvec3 , double);
354 dvec4 max(dvec4 , double);
355 dvec2 max(dvec2 , dvec2);
356 dvec3 max(dvec3 , dvec3);
357 dvec4 max(dvec4 , dvec4);
358
359 double clamp(double, double, double);
360 dvec2 clamp(dvec2 , double, double);
361 dvec3 clamp(dvec3 , double, double);
362 dvec4 clamp(dvec4 , double, double);
363 dvec2 clamp(dvec2 , dvec2 , dvec2);
364 dvec3 clamp(dvec3 , dvec3 , dvec3);
365 dvec4 clamp(dvec4 , dvec4 , dvec4);
366
367 double mix(double, double, double);
368 dvec2 mix(dvec2, dvec2, double);
369 dvec3 mix(dvec3, dvec3, double);
370 dvec4 mix(dvec4, dvec4, double);
371 dvec2 mix(dvec2, dvec2, dvec2);
372 dvec3 mix(dvec3, dvec3, dvec3);
373 dvec4 mix(dvec4, dvec4, dvec4);
374 double mix(double, double, bool);
375 dvec2 mix(dvec2, dvec2, bvec2);
376 dvec3 mix(dvec3, dvec3, bvec3);
377 dvec4 mix(dvec4, dvec4, bvec4);
378
379 double step(double, double);
380 dvec2 step(dvec2 , dvec2);
381 dvec3 step(dvec3 , dvec3);
382 dvec4 step(dvec4 , dvec4);
383 dvec2 step(double, dvec2);
384 dvec3 step(double, dvec3);
385 dvec4 step(double, dvec4);
386
387 double smoothstep(double, double, double);
388 dvec2 smoothstep(dvec2 , dvec2 , dvec2);
389 dvec3 smoothstep(dvec3 , dvec3 , dvec3);
390 dvec4 smoothstep(dvec4 , dvec4 , dvec4);
391 dvec2 smoothstep(double, double, dvec2);
392 dvec3 smoothstep(double, double, dvec3);
393 dvec4 smoothstep(double, double, dvec4);
394
395 bool isnan(double);
396 bvec2 isnan(dvec2);
397 bvec3 isnan(dvec3);
398 bvec4 isnan(dvec4);
399
400 bool isinf(double);
401 bvec2 isinf(dvec2);
402 bvec3 isinf(dvec3);
403 bvec4 isinf(dvec4);
404
405 double length(double);
406 double length(dvec2);
407 double length(dvec3);
408 double length(dvec4);
409
410 double distance(double, double);
411 double distance(dvec2 , dvec2);
412 double distance(dvec3 , dvec3);
413 double distance(dvec4 , dvec4);
414
415 double dot(double, double);
416 double dot(dvec2 , dvec2);
417 double dot(dvec3 , dvec3);
418 double dot(dvec4 , dvec4);
419
420 dvec3 cross(dvec3, dvec3);
421
422 double normalize(double);
423 dvec2 normalize(dvec2);
424 dvec3 normalize(dvec3);
425 dvec4 normalize(dvec4);
426
427 double faceforward(double, double, double);
428 dvec2 faceforward(dvec2, dvec2, dvec2);
429 dvec3 faceforward(dvec3, dvec3, dvec3);
430 dvec4 faceforward(dvec4, dvec4, dvec4);
431
432 double reflect(double, double);
433 dvec2 reflect(dvec2 , dvec2);
434 dvec3 reflect(dvec3 , dvec3);
435 dvec4 reflect(dvec4 , dvec4);
436
437 double refract(double, double, double);
438 dvec2 refract(dvec2 , dvec2 , double);
439 dvec3 refract(dvec3 , dvec3 , double);
440 dvec4 refract(dvec4 , dvec4 , double);
441
442 dmat2 matrixCompMult(dmat2, dmat2);
443 dmat3 matrixCompMult(dmat3, dmat3);
444 dmat4 matrixCompMult(dmat4, dmat4);
445 dmat2x3 matrixCompMult(dmat2x3, dmat2x3);
446 dmat2x4 matrixCompMult(dmat2x4, dmat2x4);
447 dmat3x2 matrixCompMult(dmat3x2, dmat3x2);
448 dmat3x4 matrixCompMult(dmat3x4, dmat3x4);
449 dmat4x2 matrixCompMult(dmat4x2, dmat4x2);
450 dmat4x3 matrixCompMult(dmat4x3, dmat4x3);
451
452 dmat2 outerProduct(dvec2, dvec2);
453 dmat3 outerProduct(dvec3, dvec3);
454 dmat4 outerProduct(dvec4, dvec4);
455 dmat2x3 outerProduct(dvec3, dvec2);
456 dmat3x2 outerProduct(dvec2, dvec3);
457 dmat2x4 outerProduct(dvec4, dvec2);
458 dmat4x2 outerProduct(dvec2, dvec4);
459 dmat3x4 outerProduct(dvec4, dvec3);
460 dmat4x3 outerProduct(dvec3, dvec4);
461
462 dmat2 transpose(dmat2);
463 dmat3 transpose(dmat3);
464 dmat4 transpose(dmat4);
465 dmat2x3 transpose(dmat3x2);
466 dmat3x2 transpose(dmat2x3);
467 dmat2x4 transpose(dmat4x2);
468 dmat4x2 transpose(dmat2x4);
469 dmat3x4 transpose(dmat4x3);
470 dmat4x3 transpose(dmat3x4);
471
472 double determinant(dmat2);
473 double determinant(dmat3);
474 double determinant(dmat4);
475
476 dmat2 inverse(dmat2);
477 dmat3 inverse(dmat3);
478 dmat4 inverse(dmat4);
479
480 bvec2 lessThan(dvec2, dvec2);
481 bvec3 lessThan(dvec3, dvec3);
482 bvec4 lessThan(dvec4, dvec4);
483
484 bvec2 lessThanEqual(dvec2, dvec2);
485 bvec3 lessThanEqual(dvec3, dvec3);
486 bvec4 lessThanEqual(dvec4, dvec4);
487
488 bvec2 greaterThan(dvec2, dvec2);
489 bvec3 greaterThan(dvec3, dvec3);
490 bvec4 greaterThan(dvec4, dvec4);
491
492 bvec2 greaterThanEqual(dvec2, dvec2);
493 bvec3 greaterThanEqual(dvec3, dvec3);
494 bvec4 greaterThanEqual(dvec4, dvec4);
495
496 bvec2 equal(dvec2, dvec2);
497 bvec3 equal(dvec3, dvec3);
498 bvec4 equal(dvec4, dvec4);
499
500 bvec2 notEqual(dvec2, dvec2);
501 bvec3 notEqual(dvec3, dvec3);
502 bvec4 notEqual(dvec4, dvec4);
503
504 int64_t abs(int64_t);
505 i64vec2 abs(i64vec2);
506 i64vec3 abs(i64vec3);
507 i64vec4 abs(i64vec4);
508
509 int64_t sign(int64_t);
510 i64vec2 sign(i64vec2);
511 i64vec3 sign(i64vec3);
512 i64vec4 sign(i64vec4);
513
514 int64_t min(int64_t, int64_t);
515 i64vec2 min(i64vec2, int64_t);
516 i64vec3 min(i64vec3, int64_t);
517 i64vec4 min(i64vec4, int64_t);
518 i64vec2 min(i64vec2, i64vec2);
519 i64vec3 min(i64vec3, i64vec3);
520 i64vec4 min(i64vec4, i64vec4);
521 uint64_t min(uint64_t, uint64_t);
522 u64vec2 min(u64vec2, uint64_t);
523 u64vec3 min(u64vec3, uint64_t);
524 u64vec4 min(u64vec4, uint64_t);
525 u64vec2 min(u64vec2, u64vec2);
526 u64vec3 min(u64vec3, u64vec3);
527 u64vec4 min(u64vec4, u64vec4);
528
529 int64_t max(int64_t, int64_t);
530 i64vec2 max(i64vec2, int64_t);
531 i64vec3 max(i64vec3, int64_t);
532 i64vec4 max(i64vec4, int64_t);
533 i64vec2 max(i64vec2, i64vec2);
534 i64vec3 max(i64vec3, i64vec3);
535 i64vec4 max(i64vec4, i64vec4);
536 uint64_t max(uint64_t, uint64_t);
537 u64vec2 max(u64vec2, uint64_t);
538 u64vec3 max(u64vec3, uint64_t);
539 u64vec4 max(u64vec4, uint64_t);
540 u64vec2 max(u64vec2, u64vec2);
541 u64vec3 max(u64vec3, u64vec3);
542 u64vec4 max(u64vec4, u64vec4);
543
544 int64_t clamp(int64_t, int64_t, int64_t);
545 i64vec2 clamp(i64vec2, int64_t, int64_t);
546 i64vec3 clamp(i64vec3, int64_t, int64_t);
547 i64vec4 clamp(i64vec4, int64_t, int64_t);
548 i64vec2 clamp(i64vec2, i64vec2, i64vec2);
549 i64vec3 clamp(i64vec3, i64vec3, i64vec3);
550 i64vec4 clamp(i64vec4, i64vec4, i64vec4);
551 uint64_t clamp(uint64_t, uint64_t, uint64_t);
552 u64vec2 clamp(u64vec2, uint64_t, uint64_t);
553 u64vec3 clamp(u64vec3, uint64_t, uint64_t);
554 u64vec4 clamp(u64vec4, uint64_t, uint64_t);
555 u64vec2 clamp(u64vec2, u64vec2, u64vec2);
556 u64vec3 clamp(u64vec3, u64vec3, u64vec3);
557 u64vec4 clamp(u64vec4, u64vec4, u64vec4);
558
559 int64_t mix(int64_t, int64_t, bool);
560 i64vec2 mix(i64vec2, i64vec2, bvec2);
561 i64vec3 mix(i64vec3, i64vec3, bvec3);
562 i64vec4 mix(i64vec4, i64vec4, bvec4);
563 uint64_t mix(uint64_t, uint64_t, bool);
564 u64vec2 mix(u64vec2, u64vec2, bvec2);
565 u64vec3 mix(u64vec3, u64vec3, bvec3);
566 u64vec4 mix(u64vec4, u64vec4, bvec4);
567
568 int64_t doubleBitsToInt64(double);
569 i64vec2 doubleBitsToInt64(dvec2);
570 i64vec3 doubleBitsToInt64(dvec3);
571 i64vec4 doubleBitsToInt64(dvec4);
572
573 uint64_t doubleBitsToUint64(double);
574 u64vec2 doubleBitsToUint64(dvec2);
575 u64vec3 doubleBitsToUint64(dvec3);
576 u64vec4 doubleBitsToUint64(dvec4);
577
578 double int64BitsToDouble(int64_t);
579 dvec2 int64BitsToDouble(i64vec2);
580 dvec3 int64BitsToDouble(i64vec3);
581 dvec4 int64BitsToDouble(i64vec4);
582
583 double uint64BitsToDouble(uint64_t);
584 dvec2 uint64BitsToDouble(u64vec2);
585 dvec3 uint64BitsToDouble(u64vec3);
586 dvec4 uint64BitsToDouble(u64vec4);
587
588 int64_t packInt2x32(ivec2);
589 uint64_t packUint2x32(uvec2);
590 ivec2 unpackInt2x32(int64_t);
591 uvec2 unpackUint2x32(uint64_t);
592
593 bvec2 lessThan(i64vec2, i64vec2);
594 bvec3 lessThan(i64vec3, i64vec3);
595 bvec4 lessThan(i64vec4, i64vec4);
596 bvec2 lessThan(u64vec2, u64vec2);
597 bvec3 lessThan(u64vec3, u64vec3);
598 bvec4 lessThan(u64vec4, u64vec4);
599
600 bvec2 lessThanEqual(i64vec2, i64vec2);
601 bvec3 lessThanEqual(i64vec3, i64vec3);
602 bvec4 lessThanEqual(i64vec4, i64vec4);
603 bvec2 lessThanEqual(u64vec2, u64vec2);
604 bvec3 lessThanEqual(u64vec3, u64vec3);
605 bvec4 lessThanEqual(u64vec4, u64vec4);
606
607 bvec2 greaterThan(i64vec2, i64vec2);
608 bvec3 greaterThan(i64vec3, i64vec3);
609 bvec4 greaterThan(i64vec4, i64vec4);
610 bvec2 greaterThan(u64vec2, u64vec2);
611 bvec3 greaterThan(u64vec3, u64vec3);
612 bvec4 greaterThan(u64vec4, u64vec4);
613
614 bvec2 greaterThanEqual(i64vec2, i64vec2);
615 bvec3 greaterThanEqual(i64vec3, i64vec3);
616 bvec4 greaterThanEqual(i64vec4, i64vec4);
617 bvec2 greaterThanEqual(u64vec2, u64vec2);
618 bvec3 greaterThanEqual(u64vec3, u64vec3);
619 bvec4 greaterThanEqual(u64vec4, u64vec4);
620
621 bvec2 equal(i64vec2, i64vec2);
622 bvec3 equal(i64vec3, i64vec3);
623 bvec4 equal(i64vec4, i64vec4);
624 bvec2 equal(u64vec2, u64vec2);
625 bvec3 equal(u64vec3, u64vec3);
626 bvec4 equal(u64vec4, u64vec4);
627
628 bvec2 notEqual(i64vec2, i64vec2);
629 bvec3 notEqual(i64vec3, i64vec3);
630 bvec4 notEqual(i64vec4, i64vec4);
631 bvec2 notEqual(u64vec2, u64vec2);
632 bvec3 notEqual(u64vec3, u64vec3);
633 bvec4 notEqual(u64vec4, u64vec4);
634
635 uint atomicAdd(coherent volatile inout uint, uint);
636 int atomicAdd(coherent volatile inout int, int);
637
638 uint atomicMin(coherent volatile inout uint, uint);
639 int atomicMin(coherent volatile inout int, int);
640
641 uint atomicMax(coherent volatile inout uint, uint);
642 int atomicMax(coherent volatile inout int, int);
643
644 uint atomicAnd(coherent volatile inout uint, uint);
645 int atomicAnd(coherent volatile inout int, int);
646
647 uint atomicOr (coherent volatile inout uint, uint);
648 int atomicOr (coherent volatile inout int, int);
649
650 uint atomicXor(coherent volatile inout uint, uint);
651 int atomicXor(coherent volatile inout int, int);
652
653 uint atomicExchange(coherent volatile inout uint, uint);
654 int atomicExchange(coherent volatile inout int, int);
655
656 uint atomicCompSwap(coherent volatile inout uint, uint, uint);
657 int atomicCompSwap(coherent volatile inout int, int, int);
658 int mix(int x, int y, bool a);
659 ivec2 mix(ivec2 x, ivec2 y, bvec2 a);
660 ivec3 mix(ivec3 x, ivec3 y, bvec3 a);
661 ivec4 mix(ivec4 x, ivec4 y, bvec4 a);
662
663 uint mix(uint x, uint y, bool a);
664 uvec2 mix(uvec2 x, uvec2 y, bvec2 a);
665 uvec3 mix(uvec3 x, uvec3 y, bvec3 a);
666 uvec4 mix(uvec4 x, uvec4 y, bvec4 a);
667
668 bool mix(bool x, bool y, bool a);
669 bvec2 mix(bvec2 x, bvec2 y, bvec2 a);
670 bvec3 mix(bvec3 x, bvec3 y, bvec3 a);
671 bvec4 mix(bvec4 x, bvec4 y, bvec4 a);
672 int floatBitsToInt(highp float value);
673 ivec2 floatBitsToInt(highp vec2 value);
674 ivec3 floatBitsToInt(highp vec3 value);
675 ivec4 floatBitsToInt(highp vec4 value);
676
677 uint floatBitsToUint(highp float value);
678 uvec2 floatBitsToUint(highp vec2 value);
679 uvec3 floatBitsToUint(highp vec3 value);
680 uvec4 floatBitsToUint(highp vec4 value);
681
682 float intBitsToFloat(highp int value);
683 vec2 intBitsToFloat(highp ivec2 value);
684 vec3 intBitsToFloat(highp ivec3 value);
685 vec4 intBitsToFloat(highp ivec4 value);
686
687 float uintBitsToFloat(highp uint value);
688 vec2 uintBitsToFloat(highp uvec2 value);
689 vec3 uintBitsToFloat(highp uvec3 value);
690 vec4 uintBitsToFloat(highp uvec4 value);
691 float fma(float, float, float);
692 vec2 fma(vec2, vec2, vec2);
693 vec3 fma(vec3, vec3, vec3);
694 vec4 fma(vec4, vec4, vec4);
695 double fma(double, double, double);
696 dvec2 fma(dvec2, dvec2, dvec2);
697 dvec3 fma(dvec3, dvec3, dvec3);
698 dvec4 fma(dvec4, dvec4, dvec4);
699 float frexp(highp float, out highp int);
700 vec2 frexp(highp vec2, out highp ivec2);
701 vec3 frexp(highp vec3, out highp ivec3);
702 vec4 frexp(highp vec4, out highp ivec4);
703
704 float ldexp(highp float, highp int);
705 vec2 ldexp(highp vec2, highp ivec2);
706 vec3 ldexp(highp vec3, highp ivec3);
707 vec4 ldexp(highp vec4, highp ivec4);
708 double frexp(double, out int);
709 dvec2 frexp( dvec2, out ivec2);
710 dvec3 frexp( dvec3, out ivec3);
711 dvec4 frexp( dvec4, out ivec4);
712
713 double ldexp(double, int);
714 dvec2 ldexp( dvec2, ivec2);
715 dvec3 ldexp( dvec3, ivec3);
716 dvec4 ldexp( dvec4, ivec4);
717
718 double packDouble2x32(uvec2);
719 uvec2 unpackDouble2x32(double);
720 highp uint packUnorm2x16(vec2);
721 vec2 unpackUnorm2x16(highp uint);
722 highp uint packSnorm2x16(vec2);
723 vec2 unpackSnorm2x16(highp uint);
724 highp uint packHalf2x16(vec2);
725 mediump vec2 unpackHalf2x16(highp uint);
726
727 highp uint packSnorm4x8(vec4);
728 highp uint packUnorm4x8(vec4);
729 mediump vec4 unpackSnorm4x8(highp uint);
730 mediump vec4 unpackUnorm4x8(highp uint);
731 vec4 unpackSnorm4x8(highp uint);
732 vec4 unpackUnorm4x8(highp uint);
733
734 float length(float x);
735 float length(vec2 x);
736 float length(vec3 x);
737 float length(vec4 x);
738
739 float distance(float p0, float p1);
740 float distance(vec2 p0, vec2 p1);
741 float distance(vec3 p0, vec3 p1);
742 float distance(vec4 p0, vec4 p1);
743
744 float dot(float x, float y);
745 float dot(vec2 x, vec2 y);
746 float dot(vec3 x, vec3 y);
747 float dot(vec4 x, vec4 y);
748
749 vec3 cross(vec3 x, vec3 y);
750 float normalize(float x);
751 vec2 normalize(vec2 x);
752 vec3 normalize(vec3 x);
753 vec4 normalize(vec4 x);
754
755 float faceforward(float N, float I, float Nref);
756 vec2 faceforward(vec2 N, vec2 I, vec2 Nref);
757 vec3 faceforward(vec3 N, vec3 I, vec3 Nref);
758 vec4 faceforward(vec4 N, vec4 I, vec4 Nref);
759
760 float reflect(float I, float N);
761 vec2 reflect(vec2 I, vec2 N);
762 vec3 reflect(vec3 I, vec3 N);
763 vec4 reflect(vec4 I, vec4 N);
764
765 float refract(float I, float N, float eta);
766 vec2 refract(vec2 I, vec2 N, float eta);
767 vec3 refract(vec3 I, vec3 N, float eta);
768 vec4 refract(vec4 I, vec4 N, float eta);
769
770 mat2 matrixCompMult(mat2 x, mat2 y);
771 mat3 matrixCompMult(mat3 x, mat3 y);
772 mat4 matrixCompMult(mat4 x, mat4 y);
773
774 mat2 outerProduct(vec2 c, vec2 r);
775 mat3 outerProduct(vec3 c, vec3 r);
776 mat4 outerProduct(vec4 c, vec4 r);
777 mat2x3 outerProduct(vec3 c, vec2 r);
778 mat3x2 outerProduct(vec2 c, vec3 r);
779 mat2x4 outerProduct(vec4 c, vec2 r);
780 mat4x2 outerProduct(vec2 c, vec4 r);
781 mat3x4 outerProduct(vec4 c, vec3 r);
782 mat4x3 outerProduct(vec3 c, vec4 r);
783
784 mat2 transpose(mat2 m);
785 mat3 transpose(mat3 m);
786 mat4 transpose(mat4 m);
787 mat2x3 transpose(mat3x2 m);
788 mat3x2 transpose(mat2x3 m);
789 mat2x4 transpose(mat4x2 m);
790 mat4x2 transpose(mat2x4 m);
791 mat3x4 transpose(mat4x3 m);
792 mat4x3 transpose(mat3x4 m);
793
794 mat2x3 matrixCompMult(mat2x3, mat2x3);
795 mat2x4 matrixCompMult(mat2x4, mat2x4);
796 mat3x2 matrixCompMult(mat3x2, mat3x2);
797 mat3x4 matrixCompMult(mat3x4, mat3x4);
798 mat4x2 matrixCompMult(mat4x2, mat4x2);
799 mat4x3 matrixCompMult(mat4x3, mat4x3);
800
801 float determinant(mat2 m);
802 float determinant(mat3 m);
803 float determinant(mat4 m);
804
805 mat2 inverse(mat2 m);
806 mat3 inverse(mat3 m);
807 mat4 inverse(mat4 m);
808
809 bvec2 lessThan(vec2 x, vec2 y);
810 bvec3 lessThan(vec3 x, vec3 y);
811 bvec4 lessThan(vec4 x, vec4 y);
812
813 bvec2 lessThan(ivec2 x, ivec2 y);
814 bvec3 lessThan(ivec3 x, ivec3 y);
815 bvec4 lessThan(ivec4 x, ivec4 y);
816
817 bvec2 lessThanEqual(vec2 x, vec2 y);
818 bvec3 lessThanEqual(vec3 x, vec3 y);
819 bvec4 lessThanEqual(vec4 x, vec4 y);
820
821 bvec2 lessThanEqual(ivec2 x, ivec2 y);
822 bvec3 lessThanEqual(ivec3 x, ivec3 y);
823 bvec4 lessThanEqual(ivec4 x, ivec4 y);
824
825 bvec2 greaterThan(vec2 x, vec2 y);
826 bvec3 greaterThan(vec3 x, vec3 y);
827 bvec4 greaterThan(vec4 x, vec4 y);
828
829 bvec2 greaterThan(ivec2 x, ivec2 y);
830 bvec3 greaterThan(ivec3 x, ivec3 y);
831 bvec4 greaterThan(ivec4 x, ivec4 y);
832
833 bvec2 greaterThanEqual(vec2 x, vec2 y);
834 bvec3 greaterThanEqual(vec3 x, vec3 y);
835 bvec4 greaterThanEqual(vec4 x, vec4 y);
836
837 bvec2 greaterThanEqual(ivec2 x, ivec2 y);
838 bvec3 greaterThanEqual(ivec3 x, ivec3 y);
839 bvec4 greaterThanEqual(ivec4 x, ivec4 y);
840
841 bvec2 equal(vec2 x, vec2 y);
842 bvec3 equal(vec3 x, vec3 y);
843 bvec4 equal(vec4 x, vec4 y);
844
845 bvec2 equal(ivec2 x, ivec2 y);
846 bvec3 equal(ivec3 x, ivec3 y);
847 bvec4 equal(ivec4 x, ivec4 y);
848
849 bvec2 equal(bvec2 x, bvec2 y);
850 bvec3 equal(bvec3 x, bvec3 y);
851 bvec4 equal(bvec4 x, bvec4 y);
852
853 bvec2 notEqual(vec2 x, vec2 y);
854 bvec3 notEqual(vec3 x, vec3 y);
855 bvec4 notEqual(vec4 x, vec4 y);
856
857 bvec2 notEqual(ivec2 x, ivec2 y);
858 bvec3 notEqual(ivec3 x, ivec3 y);
859 bvec4 notEqual(ivec4 x, ivec4 y);
860
861 bvec2 notEqual(bvec2 x, bvec2 y);
862 bvec3 notEqual(bvec3 x, bvec3 y);
863 bvec4 notEqual(bvec4 x, bvec4 y);
864
865 bool any(bvec2 x);
866 bool any(bvec3 x);
867 bool any(bvec4 x);
868
869 bool all(bvec2 x);
870 bool all(bvec3 x);
871 bool all(bvec4 x);
872
873 bvec2 not(bvec2 x);
874 bvec3 not(bvec3 x);
875 bvec4 not(bvec4 x);
876
877 bvec2 lessThan(uvec2 x, uvec2 y);
878 bvec3 lessThan(uvec3 x, uvec3 y);
879 bvec4 lessThan(uvec4 x, uvec4 y);
880
881 bvec2 lessThanEqual(uvec2 x, uvec2 y);
882 bvec3 lessThanEqual(uvec3 x, uvec3 y);
883 bvec4 lessThanEqual(uvec4 x, uvec4 y);
884
885 bvec2 greaterThan(uvec2 x, uvec2 y);
886 bvec3 greaterThan(uvec3 x, uvec3 y);
887 bvec4 greaterThan(uvec4 x, uvec4 y);
888
889 bvec2 greaterThanEqual(uvec2 x, uvec2 y);
890 bvec3 greaterThanEqual(uvec3 x, uvec3 y);
891 bvec4 greaterThanEqual(uvec4 x, uvec4 y);
892
893 bvec2 equal(uvec2 x, uvec2 y);
894 bvec3 equal(uvec3 x, uvec3 y);
895 bvec4 equal(uvec4 x, uvec4 y);
896
897 bvec2 notEqual(uvec2 x, uvec2 y);
898 bvec3 notEqual(uvec3 x, uvec3 y);
899 bvec4 notEqual(uvec4 x, uvec4 y);
900
901 vec4 texture2D(sampler2D, vec2);
902
903 vec4 texture2DProj(sampler2D, vec3);
904 vec4 texture2DProj(sampler2D, vec4);
905
906 vec4 texture3D(sampler3D, vec3);
907 vec4 texture3DProj(sampler3D, vec4);
908
909 vec4 textureCube(samplerCube, vec3);
910
911 vec4 texture1D(sampler1D, float);
912
913 vec4 texture1DProj(sampler1D, vec2);
914 vec4 texture1DProj(sampler1D, vec4);
915
916 vec4 shadow1D(sampler1DShadow, vec3);
917 vec4 shadow2D(sampler2DShadow, vec3);
918 vec4 shadow1DProj(sampler1DShadow, vec4);
919 vec4 shadow2DProj(sampler2DShadow, vec4);
920
921 vec4 texture2DRect(sampler2DRect, vec2);
922 vec4 texture2DRectProj(sampler2DRect, vec3);
923 vec4 texture2DRectProj(sampler2DRect, vec4);
924 vec4 shadow2DRect(sampler2DRectShadow, vec3);
925 vec4 shadow2DRectProj(sampler2DRectShadow, vec4);
926
927 vec4 texture2D(samplerExternalOES, vec2 coord);
928 vec4 texture2DProj(samplerExternalOES, vec3);
929 vec4 texture2DProj(samplerExternalOES, vec4);
930 vec4 texture2DGradEXT(sampler2D, vec2, vec2, vec2);
931 vec4 texture2DProjGradEXT(sampler2D, vec3, vec2, vec2);
932 vec4 texture2DProjGradEXT(sampler2D, vec4, vec2, vec2);
933 vec4 textureCubeGradEXT(samplerCube, vec3, vec3, vec3);
934
935 float noise1(float x);
936 float noise1(vec2 x);
937 float noise1(vec3 x);
938 float noise1(vec4 x);
939
940 vec2 noise2(float x);
941 vec2 noise2(vec2 x);
942 vec2 noise2(vec3 x);
943 vec2 noise2(vec4 x);
944
945 vec3 noise3(float x);
946 vec3 noise3(vec2 x);
947 vec3 noise3(vec3 x);
948 vec3 noise3(vec4 x);
949
950 vec4 noise4(float x);
951 vec4 noise4(vec2 x);
952 vec4 noise4(vec3 x);
953 vec4 noise4(vec4 x);
954
955 uint atomicCounterIncrement(atomic_uint x);
956 uint atomicCounterDecrement(atomic_uint x);
957 uint atomicCounter(atomic_uint x);
958
959 int bitfieldExtract( int, int, int);
960 ivec2 bitfieldExtract(ivec2, int, int);
961 ivec3 bitfieldExtract(ivec3, int, int);
962 ivec4 bitfieldExtract(ivec4, int, int);
963
964 uint bitfieldExtract( uint, int, int);
965 uvec2 bitfieldExtract(uvec2, int, int);
966 uvec3 bitfieldExtract(uvec3, int, int);
967 uvec4 bitfieldExtract(uvec4, int, int);
968
969 int bitfieldInsert( int base, int, int, int);
970 ivec2 bitfieldInsert(ivec2 base, ivec2, int, int);
971 ivec3 bitfieldInsert(ivec3 base, ivec3, int, int);
972 ivec4 bitfieldInsert(ivec4 base, ivec4, int, int);
973
974 uint bitfieldInsert( uint base, uint, int, int);
975 uvec2 bitfieldInsert(uvec2 base, uvec2, int, int);
976 uvec3 bitfieldInsert(uvec3 base, uvec3, int, int);
977 uvec4 bitfieldInsert(uvec4 base, uvec4, int, int);
978
979 int findLSB( int);
980 ivec2 findLSB(ivec2);
981 ivec3 findLSB(ivec3);
982 ivec4 findLSB(ivec4);
983
984 int findLSB( uint);
985 ivec2 findLSB(uvec2);
986 ivec3 findLSB(uvec3);
987 ivec4 findLSB(uvec4);
988
989 int bitCount( int);
990 ivec2 bitCount(ivec2);
991 ivec3 bitCount(ivec3);
992 ivec4 bitCount(ivec4);
993
994 int bitCount( uint);
995 ivec2 bitCount(uvec2);
996 ivec3 bitCount(uvec3);
997 ivec4 bitCount(uvec4);
998
999 int findMSB(highp int);
1000 ivec2 findMSB(highp ivec2);
1001 ivec3 findMSB(highp ivec3);
1002 ivec4 findMSB(highp ivec4);
1003
1004 int findMSB(highp uint);
1005 ivec2 findMSB(highp uvec2);
1006 ivec3 findMSB(highp uvec3);
1007 ivec4 findMSB(highp uvec4);
1008
1009 uint uaddCarry(highp uint, highp uint, out lowp uint carry);
1010 uvec2 uaddCarry(highp uvec2, highp uvec2, out lowp uvec2 carry);
1011 uvec3 uaddCarry(highp uvec3, highp uvec3, out lowp uvec3 carry);
1012 uvec4 uaddCarry(highp uvec4, highp uvec4, out lowp uvec4 carry);
1013
1014 uint usubBorrow(highp uint, highp uint, out lowp uint borrow);
1015 uvec2 usubBorrow(highp uvec2, highp uvec2, out lowp uvec2 borrow);
1016 uvec3 usubBorrow(highp uvec3, highp uvec3, out lowp uvec3 borrow);
1017 uvec4 usubBorrow(highp uvec4, highp uvec4, out lowp uvec4 borrow);
1018
1019 void umulExtended(highp uint, highp uint, out highp uint, out highp uint lsb);
1020 void umulExtended(highp uvec2, highp uvec2, out highp uvec2, out highp uvec2 lsb);
1021 void umulExtended(highp uvec3, highp uvec3, out highp uvec3, out highp uvec3 lsb);
1022 void umulExtended(highp uvec4, highp uvec4, out highp uvec4, out highp uvec4 lsb);
1023
1024 void imulExtended(highp int, highp int, out highp int, out highp int lsb);
1025 void imulExtended(highp ivec2, highp ivec2, out highp ivec2, out highp ivec2 lsb);
1026 void imulExtended(highp ivec3, highp ivec3, out highp ivec3, out highp ivec3 lsb);
1027 void imulExtended(highp ivec4, highp ivec4, out highp ivec4, out highp ivec4 lsb);
1028
1029 int bitfieldReverse(highp int);
1030 ivec2 bitfieldReverse(highp ivec2);
1031 ivec3 bitfieldReverse(highp ivec3);
1032 ivec4 bitfieldReverse(highp ivec4);
1033
1034 uint bitfieldReverse(highp uint);
1035 uvec2 bitfieldReverse(highp uvec2);
1036 uvec3 bitfieldReverse(highp uvec3);
1037 uvec4 bitfieldReverse(highp uvec4);
1038
1039 lowp int bitCount( int);
1040 lowp ivec2 bitCount(ivec2);
1041 lowp ivec3 bitCount(ivec3);
1042 lowp ivec4 bitCount(ivec4);
1043
1044 lowp int bitCount( uint);
1045 lowp ivec2 bitCount(uvec2);
1046 lowp ivec3 bitCount(uvec3);
1047 lowp ivec4 bitCount(uvec4);
1048
1049 lowp int findMSB(highp int);
1050 lowp ivec2 findMSB(highp ivec2);
1051 lowp ivec3 findMSB(highp ivec3);
1052 lowp ivec4 findMSB(highp ivec4);
1053
1054 lowp int findMSB(highp uint);
1055 lowp ivec2 findMSB(highp uvec2);
1056 lowp ivec3 findMSB(highp uvec3);
1057 lowp ivec4 findMSB(highp uvec4);
1058
1059 uint64_t ballotARB(bool);
1060
1061 float readInvocationARB(float, uint);
1062 vec2 readInvocationARB(vec2, uint);
1063 vec3 readInvocationARB(vec3, uint);
1064 vec4 readInvocationARB(vec4, uint);
1065
1066 int readInvocationARB(int, uint);
1067 ivec2 readInvocationARB(ivec2, uint);
1068 ivec3 readInvocationARB(ivec3, uint);
1069 ivec4 readInvocationARB(ivec4, uint);
1070
1071 uint readInvocationARB(uint, uint);
1072 uvec2 readInvocationARB(uvec2, uint);
1073 uvec3 readInvocationARB(uvec3, uint);
1074 uvec4 readInvocationARB(uvec4, uint);
1075
1076 float readFirstInvocationARB(float);
1077 vec2 readFirstInvocationARB(vec2);
1078 vec3 readFirstInvocationARB(vec3);
1079 vec4 readFirstInvocationARB(vec4);
1080
1081 int readFirstInvocationARB(int);
1082 ivec2 readFirstInvocationARB(ivec2);
1083 ivec3 readFirstInvocationARB(ivec3);
1084 ivec4 readFirstInvocationARB(ivec4);
1085
1086 uint readFirstInvocationARB(uint);
1087 uvec2 readFirstInvocationARB(uvec2);
1088 uvec3 readFirstInvocationARB(uvec3);
1089 uvec4 readFirstInvocationARB(uvec4);
1090
1091 bool anyInvocationARB(bool);
1092 bool allInvocationsARB(bool);
1093 bool allInvocationsEqualARB(bool);
1094
1095 vec4 ftransform();
1096 vec4 texture2DLod(sampler2D, vec2, float);
1097 vec4 texture2DProjLod(sampler2D, vec3, float);
1098 vec4 texture2DProjLod(sampler2D, vec4, float);
1099 vec4 texture3DLod(sampler3D, vec3, float);
1100 vec4 texture3DProjLod(sampler3D, vec4, float);
1101 vec4 textureCubeLod(samplerCube, vec3, float);
1102
1103 vec4 texture1DLod(sampler1D, float, float);
1104 vec4 texture1DProjLod(sampler1D, vec2, float);
1105 vec4 texture1DProjLod(sampler1D, vec4, float);
1106 vec4 shadow1DLod(sampler1DShadow, vec3, float);
1107 vec4 shadow2DLod(sampler2DShadow, vec3, float);
1108 vec4 shadow1DProjLod(sampler1DShadow, vec4, float);
1109 vec4 shadow2DProjLod(sampler2DShadow, vec4, float);
1110
1111 vec4 texture1DGradARB(sampler1D, float, float, float);
1112 vec4 texture1DProjGradARB(sampler1D, vec2, float, float);
1113 vec4 texture1DProjGradARB(sampler1D, vec4, float, float);
1114 vec4 texture2DGradARB(sampler2D, vec2, vec2, vec2);
1115 vec4 texture2DProjGradARB(sampler2D, vec3, vec2, vec2);
1116 vec4 texture2DProjGradARB(sampler2D, vec4, vec2, vec2);
1117 vec4 texture3DGradARB(sampler3D, vec3, vec3, vec3);
1118 vec4 texture3DProjGradARB(sampler3D, vec4, vec3, vec3);
1119 vec4 textureCubeGradARB(samplerCube, vec3, vec3, vec3);
1120 vec4 shadow1DGradARB(sampler1DShadow, vec3, float, float);
1121 vec4 shadow1DProjGradARB( sampler1DShadow, vec4, float, float);
1122 vec4 shadow2DGradARB(sampler2DShadow, vec3, vec2, vec2);
1123 vec4 shadow2DProjGradARB( sampler2DShadow, vec4, vec2, vec2);
1124 vec4 texture2DRectGradARB(sampler2DRect, vec2, vec2, vec2);
1125 vec4 texture2DRectProjGradARB( sampler2DRect, vec3, vec2, vec2);
1126 vec4 texture2DRectProjGradARB( sampler2DRect, vec4, vec2, vec2);
1127 vec4 shadow2DRectGradARB( sampler2DRectShadow, vec3, vec2, vec2);
1128 vec4 shadow2DRectProjGradARB(sampler2DRectShadow, vec4, vec2, vec2);
1129
1130 void EmitStreamVertex(int);
1131 void EndStreamPrimitive(int);
1132
1133 void EmitVertex();
1134 void EndPrimitive();
1135
1136 void barrier();
1137 void memoryBarrier();
1138 void memoryBarrierAtomicCounter();
1139 void memoryBarrierBuffer();
1140 void memoryBarrierImage();
1141 void memoryBarrierShared();
1142 void groupMemoryBarrier();
1143
1144 vec4 texture2D(sampler2D, vec2, float);
1145 vec4 texture2DProj(sampler2D, vec3, float);
1146 vec4 texture2DProj(sampler2D, vec4, float);
1147 vec4 texture3D(sampler3D, vec3, float);
1148 vec4 texture3DProj(sampler3D, vec4, float);
1149 vec4 textureCube(samplerCube, vec3, float);
1150
1151 vec4 texture1D(sampler1D, float, float);
1152 vec4 texture1DProj(sampler1D, vec2, float);
1153 vec4 texture1DProj(sampler1D, vec4, float);
1154 vec4 shadow1D(sampler1DShadow, vec3, float);
1155 vec4 shadow2D(sampler2DShadow, vec3, float);
1156 vec4 shadow1DProj(sampler1DShadow, vec4, float);
1157 vec4 shadow2DProj(sampler2DShadow, vec4, float);
1158
1159 vec4 texture2DLodEXT(sampler2D, vec2, float);
1160 vec4 texture2DProjLodEXT(sampler2D, vec3, float);
1161 vec4 texture2DProjLodEXT(sampler2D, vec4, float);
1162 vec4 textureCubeLodEXT(samplerCube, vec3, float);
1163
1164 float dFdx(float p);
1165 vec2 dFdx(vec2 p);
1166 vec3 dFdx(vec3 p);
1167 vec4 dFdx(vec4 p);
1168
1169 float dFdy(float p);
1170 vec2 dFdy(vec2 p);
1171 vec3 dFdy(vec3 p);
1172 vec4 dFdy(vec4 p);
1173
1174 float fwidth(float p);
1175 vec2 fwidth(vec2 p);
1176 vec3 fwidth(vec3 p);
1177 vec4 fwidth(vec4 p);
1178
1179 float dFdxFine(float p);
1180 vec2 dFdxFine(vec2 p);
1181 vec3 dFdxFine(vec3 p);
1182 vec4 dFdxFine(vec4 p);
1183
1184 float dFdyFine(float p);
1185 vec2 dFdyFine(vec2 p);
1186 vec3 dFdyFine(vec3 p);
1187 vec4 dFdyFine(vec4 p);
1188
1189 float fwidthFine(float p);
1190 vec2 fwidthFine(vec2 p);
1191 vec3 fwidthFine(vec3 p);
1192 vec4 fwidthFine(vec4 p);
1193
1194 float dFdxCoarse(float p);
1195 vec2 dFdxCoarse(vec2 p);
1196 vec3 dFdxCoarse(vec3 p);
1197 vec4 dFdxCoarse(vec4 p);
1198
1199 float dFdyCoarse(float p);
1200 vec2 dFdyCoarse(vec2 p);
1201 vec3 dFdyCoarse(vec3 p);
1202 vec4 dFdyCoarse(vec4 p);
1203
1204 float fwidthCoarse(float p);
1205 vec2 fwidthCoarse(vec2 p);
1206 vec3 fwidthCoarse(vec3 p);
1207 vec4 fwidthCoarse(vec4 p);
1208 float interpolateAtCentroid(float);
1209 vec2 interpolateAtCentroid(vec2);
1210 vec3 interpolateAtCentroid(vec3);
1211 vec4 interpolateAtCentroid(vec4);
1212
1213 float interpolateAtSample(float, int);
1214 vec2 interpolateAtSample(vec2, int);
1215 vec3 interpolateAtSample(vec3, int);
1216 vec4 interpolateAtSample(vec4, int);
1217
1218 float interpolateAtOffset(float, vec2);
1219 vec2 interpolateAtOffset(vec2, vec2);
1220 vec3 interpolateAtOffset(vec3, vec2);
1221 vec4 interpolateAtOffset(vec4, vec2);
0 float radians(float degrees);
1 vec2 radians(vec2 degrees);
2 vec3 radians(vec3 degrees);
3 vec4 radians(vec4 degrees);
4
5 float degrees(float radians);
6 vec2 degrees(vec2 radians);
7 vec3 degrees(vec3 radians);
8 vec4 degrees(vec4 radians);
9
10 float sin(float angle);
11 vec2 sin(vec2 angle);
12 vec3 sin(vec3 angle);
13 vec4 sin(vec4 angle);
14
15 float cos(float angle);
16 vec2 cos(vec2 angle);
17 vec3 cos(vec3 angle);
18 vec4 cos(vec4 angle);
19
20 float tan(float angle);
21 vec2 tan(vec2 angle);
22 vec3 tan(vec3 angle);
23 vec4 tan(vec4 angle);
24
25 float asin(float x);
26 vec2 asin(vec2 x);
27 vec3 asin(vec3 x);
28 vec4 asin(vec4 x);
29
30 float acos(float x);
31 vec2 acos(vec2 x);
32 vec3 acos(vec3 x);
33 vec4 acos(vec4 x);
34
35 float atan(float y, float x);
36 vec2 atan(vec2 y, vec2 x);
37 vec3 atan(vec3 y, vec3 x);
38 vec4 atan(vec4 y, vec4 x);
39
40 float atan(float y_over_x);
41 vec2 atan(vec2 y_over_x);
42 vec3 atan(vec3 y_over_x);
43 vec4 atan(vec4 y_over_x);
44 float sinh(float angle);
45 vec2 sinh(vec2 angle);
46 vec3 sinh(vec3 angle);
47 vec4 sinh(vec4 angle);
48
49 float cosh(float angle);
50 vec2 cosh(vec2 angle);
51 vec3 cosh(vec3 angle);
52 vec4 cosh(vec4 angle);
53
54 float tanh(float angle);
55 vec2 tanh(vec2 angle);
56 vec3 tanh(vec3 angle);
57 vec4 tanh(vec4 angle);
58
59 float asinh(float x);
60 vec2 asinh(vec2 x);
61 vec3 asinh(vec3 x);
62 vec4 asinh(vec4 x);
63
64 float acosh(float x);
65 vec2 acosh(vec2 x);
66 vec3 acosh(vec3 x);
67 vec4 acosh(vec4 x);
68
69 float atanh(float y_over_x);
70 vec2 atanh(vec2 y_over_x);
71 vec3 atanh(vec3 y_over_x);
72 vec4 atanh(vec4 y_over_x);
73 float pow(float x, float y);
74 vec2 pow(vec2 x, vec2 y);
75 vec3 pow(vec3 x, vec3 y);
76 vec4 pow(vec4 x, vec4 y);
77
78 float exp(float x);
79 vec2 exp(vec2 x);
80 vec3 exp(vec3 x);
81 vec4 exp(vec4 x);
82
83 float log(float x);
84 vec2 log(vec2 x);
85 vec3 log(vec3 x);
86 vec4 log(vec4 x);
87
88 float exp2(float x);
89 vec2 exp2(vec2 x);
90 vec3 exp2(vec3 x);
91 vec4 exp2(vec4 x);
92
93 float log2(float x);
94 vec2 log2(vec2 x);
95 vec3 log2(vec3 x);
96 vec4 log2(vec4 x);
97
98 float sqrt(float x);
99 vec2 sqrt(vec2 x);
100 vec3 sqrt(vec3 x);
101 vec4 sqrt(vec4 x);
102
103 float inversesqrt(float x);
104 vec2 inversesqrt(vec2 x);
105 vec3 inversesqrt(vec3 x);
106 vec4 inversesqrt(vec4 x);
107 float abs(float x);
108 vec2 abs(vec2 x);
109 vec3 abs(vec3 x);
110 vec4 abs(vec4 x);
111
112 float sign(float x);
113 vec2 sign(vec2 x);
114 vec3 sign(vec3 x);
115 vec4 sign(vec4 x);
116
117 float floor(float x);
118 vec2 floor(vec2 x);
119 vec3 floor(vec3 x);
120 vec4 floor(vec4 x);
121
122 float ceil(float x);
123 vec2 ceil(vec2 x);
124 vec3 ceil(vec3 x);
125 vec4 ceil(vec4 x);
126
127 float fract(float x);
128 vec2 fract(vec2 x);
129 vec3 fract(vec3 x);
130 vec4 fract(vec4 x);
131
132 float mod(float x, float y);
133 vec2 mod(vec2 x, float y);
134 vec3 mod(vec3 x, float y);
135 vec4 mod(vec4 x, float y);
136 vec2 mod(vec2 x, vec2 y);
137 vec3 mod(vec3 x, vec3 y);
138 vec4 mod(vec4 x, vec4 y);
139
140 float min(float x, float y);
141 vec2 min(vec2 x, float y);
142 vec3 min(vec3 x, float y);
143 vec4 min(vec4 x, float y);
144 vec2 min(vec2 x, vec2 y);
145 vec3 min(vec3 x, vec3 y);
146 vec4 min(vec4 x, vec4 y);
147
148 float max(float x, float y);
149 vec2 max(vec2 x, float y);
150 vec3 max(vec3 x, float y);
151 vec4 max(vec4 x, float y);
152 vec2 max(vec2 x, vec2 y);
153 vec3 max(vec3 x, vec3 y);
154 vec4 max(vec4 x, vec4 y);
155
156 float clamp(float x, float minVal, float maxVal);
157 vec2 clamp(vec2 x, float minVal, float maxVal);
158 vec3 clamp(vec3 x, float minVal, float maxVal);
159 vec4 clamp(vec4 x, float minVal, float maxVal);
160 vec2 clamp(vec2 x, vec2 minVal, vec2 maxVal);
161 vec3 clamp(vec3 x, vec3 minVal, vec3 maxVal);
162 vec4 clamp(vec4 x, vec4 minVal, vec4 maxVal);
163
164 float mix(float x, float y, float a);
165 vec2 mix(vec2 x, vec2 y, float a);
166 vec3 mix(vec3 x, vec3 y, float a);
167 vec4 mix(vec4 x, vec4 y, float a);
168 vec2 mix(vec2 x, vec2 y, vec2 a);
169 vec3 mix(vec3 x, vec3 y, vec3 a);
170 vec4 mix(vec4 x, vec4 y, vec4 a);
171
172 float step(float edge, float x);
173 vec2 step(vec2 edge, vec2 x);
174 vec3 step(vec3 edge, vec3 x);
175 vec4 step(vec4 edge, vec4 x);
176 vec2 step(float edge, vec2 x);
177 vec3 step(float edge, vec3 x);
178 vec4 step(float edge, vec4 x);
179
180 float smoothstep(float edge0, float edge1, float x);
181 vec2 smoothstep(vec2 edge0, vec2 edge1, vec2 x);
182 vec3 smoothstep(vec3 edge0, vec3 edge1, vec3 x);
183 vec4 smoothstep(vec4 edge0, vec4 edge1, vec4 x);
184 vec2 smoothstep(float edge0, float edge1, vec2 x);
185 vec3 smoothstep(float edge0, float edge1, vec3 x);
186 vec4 smoothstep(float edge0, float edge1, vec4 x);
187 int abs( int x);
188 ivec2 abs(ivec2 x);
189 ivec3 abs(ivec3 x);
190 ivec4 abs(ivec4 x);
191
192 int sign( int x);
193 ivec2 sign(ivec2 x);
194 ivec3 sign(ivec3 x);
195 ivec4 sign(ivec4 x);
196
197 float trunc(float x);
198 vec2 trunc(vec2 x);
199 vec3 trunc(vec3 x);
200 vec4 trunc(vec4 x);
201
202 float round(float x);
203 vec2 round(vec2 x);
204 vec3 round(vec3 x);
205 vec4 round(vec4 x);
206
207 float roundEven(float x);
208 vec2 roundEven(vec2 x);
209 vec3 roundEven(vec3 x);
210 vec4 roundEven(vec4 x);
211
212 float modf(float, out float);
213 vec2 modf(vec2, out vec2);
214 vec3 modf(vec3, out vec3);
215 vec4 modf(vec4, out vec4);
216
217 int min(int x, int y);
218 ivec2 min(ivec2 x, int y);
219 ivec3 min(ivec3 x, int y);
220 ivec4 min(ivec4 x, int y);
221 ivec2 min(ivec2 x, ivec2 y);
222 ivec3 min(ivec3 x, ivec3 y);
223 ivec4 min(ivec4 x, ivec4 y);
224
225 uint min(uint x, uint y);
226 uvec2 min(uvec2 x, uint y);
227 uvec3 min(uvec3 x, uint y);
228 uvec4 min(uvec4 x, uint y);
229 uvec2 min(uvec2 x, uvec2 y);
230 uvec3 min(uvec3 x, uvec3 y);
231 uvec4 min(uvec4 x, uvec4 y);
232
233 int max(int x, int y);
234 ivec2 max(ivec2 x, int y);
235 ivec3 max(ivec3 x, int y);
236 ivec4 max(ivec4 x, int y);
237 ivec2 max(ivec2 x, ivec2 y);
238 ivec3 max(ivec3 x, ivec3 y);
239 ivec4 max(ivec4 x, ivec4 y);
240
241 uint max(uint x, uint y);
242 uvec2 max(uvec2 x, uint y);
243 uvec3 max(uvec3 x, uint y);
244 uvec4 max(uvec4 x, uint y);
245 uvec2 max(uvec2 x, uvec2 y);
246 uvec