Skip to content
This repository was archived by the owner on Oct 5, 2024. It is now read-only.

Added GLSL parser #115

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Elm/AST/Canonical.elm
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ type Expr
| Tuple3 LocatedExpr LocatedExpr LocatedExpr
| Record (Dict VarName (Binding LocatedExpr))
| Case LocatedExpr (List { pattern : LocatedPattern, body : LocatedExpr })
| Shader String


type alias LocatedPattern =
Expand Down Expand Up @@ -212,6 +213,9 @@ unwrap expr =
)
branches

Shader shader ->
Unwrapped.Shader shader


{-| Discard the [location metadata](Elm.Data.Located#Located).
-}
Expand Down Expand Up @@ -371,6 +375,9 @@ fromUnwrapped expr =
)
branches

Unwrapped.Shader shader ->
Shader shader


{-| Adds [**dummy** locations](Elm.Data.Located#dummyRegion) to the [Unwrapped.Pattern](Elm.AST.Canonical.Unwrapped#Pattern).
-}
Expand Down
1 change: 1 addition & 0 deletions src/Elm/AST/Canonical/Unwrapped.elm
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Expr
| Tuple3 Expr Expr Expr
| Record (Dict VarName (Binding Expr))
| Case Expr (List { pattern : Pattern, body : Expr })
| Shader String


type Pattern
Expand Down
13 changes: 13 additions & 0 deletions src/Elm/AST/Frontend.elm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ still there.

import Dict exposing (Dict)
import Elm.AST.Frontend.Unwrapped as Unwrapped
import Elm.AST.Shader as Shader
import Elm.Data.Binding as Binding exposing (Binding)
import Elm.Data.Located as Located exposing (Located)
import Elm.Data.Module exposing (Module)
Expand Down Expand Up @@ -73,6 +74,12 @@ type Expr
| Tuple3 LocatedExpr LocatedExpr LocatedExpr
| Record (List (Binding LocatedExpr))
| Case LocatedExpr (List { pattern : LocatedPattern, body : LocatedExpr })
| Shader
String
{ attribute : Dict VarName Shader.Type
, uniform : Dict VarName Shader.Type
, varying : Dict VarName Shader.Type
}


type alias LocatedPattern =
Expand Down Expand Up @@ -191,6 +198,9 @@ recurse f expr =
)
branches

Shader _ _ ->
expr


{-| [Transform](/packages/Janiczek/transform/latest/Transform#transformAll)
the expression using the provided function.
Expand Down Expand Up @@ -311,6 +321,9 @@ unwrap expr =
)
branches

Shader value types ->
Unwrapped.Shader value types


{-| Discard the [location metadata](Elm.Data.Located#Located).
-}
Expand Down
8 changes: 8 additions & 0 deletions src/Elm/AST/Frontend/Unwrapped.elm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Convert to it using the [`Elm.AST.Frontend.unwrap`](Elm.AST.Frontend#unwrap).

-}

import Dict exposing (Dict)
import Elm.AST.Shader as Shader
import Elm.Data.Binding exposing (Binding)
import Elm.Data.Qualifiedness exposing (PossiblyQualified)
import Elm.Data.VarName exposing (VarName)
Expand Down Expand Up @@ -41,6 +43,12 @@ type Expr
| Tuple3 Expr Expr Expr
| Record (List (Binding Expr))
| Case Expr (List { pattern : Pattern, body : Expr })
| Shader
String
{ attribute : Dict VarName Shader.Type
, uniform : Dict VarName Shader.Type
, varying : Dict VarName Shader.Type
}


type Pattern
Expand Down
11 changes: 11 additions & 0 deletions src/Elm/AST/Shader.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Elm.AST.Shader exposing (Type(..))


type Type
= Int
| Float
| V2
| V3
| V4
| M4
| Texture
13 changes: 13 additions & 0 deletions src/Elm/AST/Typed.elm
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type Expr_
| Tuple3 LocatedExpr LocatedExpr LocatedExpr
| Record (Dict VarName (Binding LocatedExpr))
| Case LocatedExpr (List { pattern : LocatedPattern, body : LocatedExpr })
| Shader String


type alias LocatedPattern =
Expand Down Expand Up @@ -214,6 +215,9 @@ recurse fn locatedExpr =
}
)
branches

Shader _ ->
expr
)


Expand Down Expand Up @@ -308,6 +312,9 @@ recursiveChildren fn locatedExpr =
Case e branches ->
fn e ++ List.fastConcatMap (.body >> fn) branches

Shader _ ->
[]


mapExpr : (Expr_ -> Expr_) -> LocatedExpr -> LocatedExpr
mapExpr fn locatedExpr =
Expand Down Expand Up @@ -451,6 +458,9 @@ unwrap expr =
}
)
branches

Shader shader ->
Unwrapped.Shader shader
, type_
)

Expand Down Expand Up @@ -610,6 +620,9 @@ dropTypes locatedExpr =
}
)
branches

Shader shader ->
Canonical.Shader shader
)


Expand Down
1 change: 1 addition & 0 deletions src/Elm/AST/Typed/Unwrapped.elm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Expr_
| Tuple3 Expr Expr Expr
| Record (Dict VarName (Binding Expr))
| Case Expr (List { pattern : Pattern, body : Expr })
| Shader String


type alias Pattern =
Expand Down
4 changes: 4 additions & 0 deletions src/Elm/Compiler/Error.elm
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ type ParseProblem
| ExpectingScientificNotationPlus
| ExpectingScientificNotationMinus
| IntZeroCannotHaveScientificNotation
| ShaderProblem


type ParseCompilerBug
Expand Down Expand Up @@ -640,6 +641,9 @@ parseProblemToString problem =
IntZeroCannotHaveScientificNotation ->
"IntZeroCannotHaveScientificNotation"

ShaderProblem ->
"ShaderProblem"


parseCompilerBugToString : ParseCompilerBug -> String
parseCompilerBugToString bug =
Expand Down
21 changes: 21 additions & 0 deletions src/Elm/Data/Type.elm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The main confusion point here is "what is the
-}

import Dict exposing (Dict)
import Elm.AST.Shader as Shader
import Elm.Data.VarName exposing (VarName)
import OurExtras.Dict as Dict
import OurExtras.List as List
Expand Down Expand Up @@ -129,6 +130,11 @@ type Type a
, name : String
, args : List (TypeOrId a)
}
| Shader
{ attribute : Dict VarName Shader.Type
, uniform : Dict VarName Shader.Type
, varying : Dict VarName Shader.Type
}


{-| Unwrap the string inside the type variable
Expand Down Expand Up @@ -228,6 +234,9 @@ isParametric typeOrId =
UserDefinedType { args } ->
List.any f args

Shader _ ->
False


varNames : Type a -> List String
varNames type_ =
Expand Down Expand Up @@ -297,6 +306,9 @@ recursiveChildren fn type_ =
UserDefinedType { args } ->
List.fastConcatMap fn_ args

Shader _ ->
[]


{-| Find all the children of this expression (and their children, etc...)
-}
Expand Down Expand Up @@ -345,6 +357,9 @@ recursiveChildren_ fn typeOrId =
Type (UserDefinedType { args }) ->
List.fastConcatMap fn args

Type (Shader _) ->
[]


mapTypeOrId : (a -> b) -> TypeOrId a -> TypeOrId b
mapTypeOrId fn typeOrId =
Expand Down Expand Up @@ -414,6 +429,9 @@ mapType fn type_ =
, args = List.map f r.args
}

Shader shaderInfo ->
Shader shaderInfo


combineType : Type (Result err a) -> Result err (Type a)
combineType type_ =
Expand Down Expand Up @@ -490,6 +508,9 @@ combineType type_ =
|> Result.Extra.combine
)

Shader shaderInfo ->
Ok (Shader shaderInfo)


combineTypeOrId : TypeOrId (Result err a) -> Result err (TypeOrId a)
combineTypeOrId typeOrId =
Expand Down
6 changes: 6 additions & 0 deletions src/Elm/Data/Type/ToString.elm
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ toStringType_ qualifiednessToString state type_ =
else
( "{ " ++ bindingsStr ++ " }", state1 )

Shader _ ->
( "Shader", state )


getName : State -> Int -> ( String, State )
getName ((State { counter, mapping, used }) as state) varId =
Expand Down Expand Up @@ -497,3 +500,6 @@ shouldWrapParens typeOrId =

Record _ ->
False

Shader _ ->
False
3 changes: 3 additions & 0 deletions src/Stage/Desugar.elm
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ desugarExpr modules thisModule locatedExpr =
|> Result.combine
)

Frontend.Shader shader _ ->
return <| Canonical.Shader shader


desugarPattern :
Frontend.LocatedPattern
Expand Down
3 changes: 3 additions & 0 deletions src/Stage/Emit.elm
Original file line number Diff line number Diff line change
Expand Up @@ -564,3 +564,6 @@ findDependenciesOfExpr modules locatedExpr =
Result.map2 (++)
(f e)
branchesDependencies

Shader _ ->
Ok []
3 changes: 3 additions & 0 deletions src/Stage/Emit/JavaScript.elm
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ emitExpr located =
Case _ _ ->
"TODO"

Shader _ ->
"TODO"


emitDeclaration : Declaration Typed.LocatedExpr Never Qualified -> String
emitDeclaration { module_, name, body } =
Expand Down
3 changes: 3 additions & 0 deletions src/Stage/Emit/JsonAST.elm
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ emitExpr located =
)
]

Shader shader ->
encode "shader" [ ( "value", Encode.string shader ) ]


emitDeclaration : Declaration Typed.LocatedExpr Never Qualified -> Value
emitDeclaration { module_, name, body } =
Expand Down
3 changes: 3 additions & 0 deletions src/Stage/InferTypes.elm
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ getBetterType substitutionMap typeOrId =
Record <|
Dict.map (\_ binding -> getBetterType substitutionMap binding) bindings

Shader _ ->
typeOrId


unifyWithTypeAnnotation :
Dict ( ModuleName, VarName ) (ConcreteType Qualified)
Expand Down
3 changes: 3 additions & 0 deletions src/Stage/InferTypes/AssignIds.elm
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ assignIdsHelp currentId located =
assignId newId <|
Typed.Case e_ branches_

Canonical.Shader shader ->
assignId currentId (Typed.Shader shader)


assignPatternIds : Int -> Canonical.LocatedPattern -> ( Typed.LocatedPattern, Int )
assignPatternIds currentId locatedCanonicalPattern =
Expand Down
3 changes: 3 additions & 0 deletions src/Stage/InferTypes/GenerateEquations.elm
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,9 @@ generateEquations currentId located =
, newId
)

Typed.Shader _ ->
Debug.todo "Shader"


findArgumentUsages : VarName -> Typed.LocatedExpr -> List Typed.LocatedExpr
findArgumentUsages argument bodyExpr =
Expand Down
6 changes: 6 additions & 0 deletions src/Stage/InferTypes/Unify.elm
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ unifyTypes t1 t2 aliases substitutionMap =
Just aliasedType ->
unifyTypes (ConcreteType.toType aliasedType) t2 aliases substitutionMap

( Shader _, _ ) ->
err


unifyVariable :
Int
Expand Down Expand Up @@ -271,3 +274,6 @@ occurs id typeOrId substitutionMap =

UserDefinedType { args } ->
List.any f args

Shader _ ->
False
Loading