on master help sign in
getting closer, need to turn the list of gl initDecls into a TermN
commitd690696c2ecee0321c1eb669e50610af730a8a17 authorJohn P Mayer Jr <john.p.mayer.jr@gmail.com> dateFri 29 Nov 2013, 02:05 (13 years ago) parent481478d
4 files changed+30−6
Elm.cabal+2 compiler/Parse/Helpers.hs+21 compiler/Type/Constrain/Expression.hs+5−4 compiler/Type/Environment.hs+2−2
Elm.cabal+2
@@ -90,6 +90,7 @@ Library
9090 filepath,
9191 indents,
9292 language-ecmascript >=0.15 && < 1.0,
93+ language-glsl,
9394 mtl >= 2,
9495 pandoc >= 1.10,
9596 parsec >= 3.1.1,
@@ -160,6 +161,7 @@ Executable elm
160161 filepath,
161162 indents,
162163 language-ecmascript >=0.15 && < 1.0,
164+ language-glsl,
163165 mtl >= 2,
164166 pandoc >= 1.10,
165167 parsec >= 3.1.1,
compiler/Parse/Helpers.hs+21
@@ -7,6 +7,8 @@ import Control.Monad.State
77import Data.Char (isUpper)
88import qualified Data.Set as Set
99import qualified Data.Map as Map
10+import qualified Language.GLSL.Parser as GLP
11+import Language.GLSL.Syntax
1012import SourceSyntax.Helpers as Help
1113import SourceSyntax.Location as Location
1214import SourceSyntax.Expression
@@ -324,3 +326,22 @@ glShader = try (string "[glShader|") >> closeShader "" where
324326 c <- anyChar
325327 closeShader (src ++ [c])
326328 ]
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
1414import Data.Traversable (traverse)
1515import qualified Text.PrettyPrint as PP
1616
17+import qualified Parse.Helpers as PH
1718import SourceSyntax.Location as Loc
1819import SourceSyntax.Pattern (Pattern(PVar))
1920import SourceSyntax.Expression
@@ -38,10 +39,10 @@ constrain env (L span expr) tipe =
3839 case expr of
3940 Literal lit -> liftIO $ Literal.constrain env span lit tipe
4041
41− GLShader _ src -> return . L span $ CEqual tipe shaderTipe
42− where
43− shaderTipe :: Type
44− shaderTipe = error "What's the shader type"
42+ GLShader _ src ->
43+ return . L span $ CEqual tipe (glTipe sourceTipe) where
44+ glTipe t = Env.get env Env.types "GLShader" <| t
45+ sourceTipe = PH.glSource src
4546
4647 Var name | name == saveEnvName -> return (L span CSaveEnv)
4748 | otherwise -> return (name <? tipe)
compiler/Type/Environment.hs+2−2
@@ -54,8 +54,8 @@ makeTypes datatypes =
5454
5555 builtins :: [(String,Int)]
5656 builtins = concat [ map tuple [0..9]
57− , kind 1 ["_List"]
58− , kind 0 ["Int","Float","Char","String","Bool"]
57+ , kind 1 ["_List","GLShader"]
58+ , kind 0 ["Int","Float","Char","String","Bool","M4x4","V3"]
5959 ]
6060
6161