on master help sign in
getting closer, need to turn the list of gl initDecls into a TermN
d690696John P Mayer Jr
Elm.cabal+2
@@ -90,6 +90,7 @@ Library
90 filepath,
90 filepath,
91 indents,
91 indents,
92 language-ecmascript >=0.15 && < 1.0,
92 language-ecmascript >=0.15 && < 1.0,
93+ language-glsl,
93 mtl >= 2,
94 mtl >= 2,
94 pandoc >= 1.10,
95 pandoc >= 1.10,
95 parsec >= 3.1.1,
96 parsec >= 3.1.1,
@@ -160,6 +161,7 @@ Executable elm
160 filepath,
161 filepath,
161 indents,
162 indents,
162 language-ecmascript >=0.15 && < 1.0,
163 language-ecmascript >=0.15 && < 1.0,
164+ language-glsl,
163 mtl >= 2,
165 mtl >= 2,
164 pandoc >= 1.10,
166 pandoc >= 1.10,
165 parsec >= 3.1.1,
167 parsec >= 3.1.1,
compiler/Parse/Helpers.hs+21
@@ -7,6 +7,8 @@ import Control.Monad.State
7import Data.Char (isUpper)
7import Data.Char (isUpper)
8import qualified Data.Set as Set
8import qualified Data.Set as Set
9import qualified Data.Map as Map
9import qualified Data.Map as Map
10+import qualified Language.GLSL.Parser as GLP
11+import Language.GLSL.Syntax
10import SourceSyntax.Helpers as Help
12import SourceSyntax.Helpers as Help
11import SourceSyntax.Location as Location
13import SourceSyntax.Location as Location
12import SourceSyntax.Expression
14import SourceSyntax.Expression
@@ -324,3 +326,22 @@ glShader = try (string "[glShader|") >> closeShader "" where
324 c <- anyChar
326 c <- anyChar
325 closeShader (src ++ [c])
327 closeShader (src ++ [c])
326 ]
328 ]
329+
330+data GLTipe = V3 | M4
331+
332+glSource :: String -> Maybe [(StorageQualifier, GLTipe, String)]
333+glSource src =
334+ case GLP.parse src of
335+ Right (TranslationUnit decls) ->
336+ Just . join . map extractGLinputs $ decls
337+ Left e -> Nothing
338+ where
339+ extractGLinputs decl = case decl of
340+ Declaration (InitDeclaration (TypeDeclarator (FullType (Just (TypeQualSto qual)) (TypeSpec _prec (TypeSpecNoPrecision tipe _mexpr1)))) [InitDecl name _mexpr2 _mexpr3]) ->
341+ if elem qual [Attribute, Varying, Uniform]
342+ then case tipe of
343+ Vec3 -> return (qual,V3,name)
344+ Mat4 -> return (qual,M4,name)
345+ _ -> []
346+ else []
347+ _ -> []
compiler/Type/Constrain/Expression.hs+5−4
@@ -14,6 +14,7 @@ import Control.Monad.State
14import Data.Traversable (traverse)
14import Data.Traversable (traverse)
15import qualified Text.PrettyPrint as PP
15import qualified Text.PrettyPrint as PP
16
16
17+import qualified Parse.Helpers as PH
17import SourceSyntax.Location as Loc
18import SourceSyntax.Location as Loc
18import SourceSyntax.Pattern (Pattern(PVar))
19import SourceSyntax.Pattern (Pattern(PVar))
19import SourceSyntax.Expression
20import SourceSyntax.Expression
@@ -38,10 +39,10 @@ constrain env (L span expr) tipe =
38 case expr of
39 case expr of
39 Literal lit -> liftIO $ Literal.constrain env span lit tipe
40 Literal lit -> liftIO $ Literal.constrain env span lit tipe
40
41
42+ GLShader _ src ->
41− GLShader _ src -> return . L span $ CEqual tipe shaderTipe
43+ return . L span $ CEqual tipe (glTipe sourceTipe) where
42− where
44+ glTipe t = Env.get env Env.types "GLShader" <| t
43− shaderTipe :: Type
45+ sourceTipe = PH.glSource src
44− shaderTipe = error "What's the shader type"
45
46
46 Var name | name == saveEnvName -> return (L span CSaveEnv)
47 Var name | name == saveEnvName -> return (L span CSaveEnv)
47 | otherwise -> return (name <? tipe)
48 | otherwise -> return (name <? tipe)
compiler/Type/Environment.hs+2−2
@@ -54,8 +54,8 @@ makeTypes datatypes =
54
54
55 builtins :: [(String,Int)]
55 builtins :: [(String,Int)]
56 builtins = concat [ map tuple [0..9]
56 builtins = concat [ map tuple [0..9]
57− , kind 1 ["_List"]
57+ , kind 1 ["_List","GLShader"]
58− , kind 0 ["Int","Float","Char","String","Bool"]
58+ , kind 0 ["Int","Float","Char","String","Bool","M4x4","V3"]
59 ]
59 ]
60
60
61
61