Get rid of SourceSyntax.Everything module
This commit is contained in:
parent
f8bf89b48d
commit
e119d8ef62
11 changed files with 50 additions and 49 deletions
|
@ -39,7 +39,6 @@ Library
|
|||
Hs-Source-Dirs: compiler
|
||||
other-modules: SourceSyntax.Declaration,
|
||||
SourceSyntax.Expression,
|
||||
SourceSyntax.Everything,
|
||||
SourceSyntax.Helpers,
|
||||
SourceSyntax.Literal,
|
||||
SourceSyntax.Location,
|
||||
|
@ -118,7 +117,6 @@ Executable elm
|
|||
Hs-Source-Dirs: compiler
|
||||
other-modules: SourceSyntax.Declaration,
|
||||
SourceSyntax.Expression,
|
||||
SourceSyntax.Everything,
|
||||
SourceSyntax.Helpers,
|
||||
SourceSyntax.Literal,
|
||||
SourceSyntax.Location,
|
||||
|
@ -195,7 +193,6 @@ Executable elm-doc
|
|||
Main-is: Docs.hs
|
||||
Hs-Source-Dirs: compiler
|
||||
other-modules: SourceSyntax.Declaration,
|
||||
SourceSyntax.Everything,
|
||||
SourceSyntax.Expression,
|
||||
SourceSyntax.Helpers,
|
||||
SourceSyntax.Literal,
|
||||
|
|
|
@ -18,7 +18,7 @@ import System.FilePath as FP
|
|||
import System.IO
|
||||
import Text.PrettyPrint (Doc)
|
||||
|
||||
import SourceSyntax.Everything
|
||||
import qualified SourceSyntax.Module as Module
|
||||
import qualified SourceSyntax.Type as Type
|
||||
import qualified Parse.Parse as Parse
|
||||
import qualified Metadata.Prelude as Prelude
|
||||
|
@ -32,7 +32,7 @@ import qualified Elm.Internal.Name as N
|
|||
import qualified Elm.Internal.Version as V
|
||||
import qualified Elm.Internal.Dependencies as Deps
|
||||
|
||||
getSortedDependencies :: [FilePath] -> Interfaces -> FilePath -> IO [String]
|
||||
getSortedDependencies :: [FilePath] -> Module.Interfaces -> FilePath -> IO [String]
|
||||
getSortedDependencies srcDirs builtIns root =
|
||||
do extras <- extraDependencies
|
||||
let allSrcDirs = srcDirs ++ Maybe.fromMaybe [] extras
|
||||
|
@ -86,7 +86,7 @@ sortDeps depends =
|
|||
mistakes = filter (\scc -> length scc > 1) sccs
|
||||
msg = "A cyclical module dependency or was detected in:\n"
|
||||
|
||||
readDeps :: [FilePath] -> Interfaces -> FilePath -> ErrorT String IO [Deps]
|
||||
readDeps :: [FilePath] -> Module.Interfaces -> FilePath -> ErrorT String IO [Deps]
|
||||
readDeps srcDirs builtIns root = do
|
||||
let ifaces = (Set.fromList . Map.keys) builtIns
|
||||
State.evalStateT (go ifaces root) Set.empty
|
||||
|
|
|
@ -11,7 +11,9 @@ import System.Exit
|
|||
import System.FilePath as FP
|
||||
import Text.PrettyPrint (Doc)
|
||||
|
||||
import SourceSyntax.Everything
|
||||
import SourceSyntax.Declaration
|
||||
import SourceSyntax.Module
|
||||
import qualified SourceSyntax.Expression as Expr
|
||||
import qualified SourceSyntax.Type as Type
|
||||
import qualified Parse.Parse as Parse
|
||||
import qualified Metadata.Prelude as Prelude
|
||||
|
@ -38,7 +40,7 @@ build noPrelude interfaces source =
|
|||
let exports'
|
||||
| null exs =
|
||||
let get = Set.toList . SD.boundVars in
|
||||
concat [ get pattern | Definition (Def pattern _) <- decls ] ++
|
||||
concat [ get pattern | Definition (Expr.Def pattern _) <- decls ] ++
|
||||
concat [ map fst ctors | Datatype _ _ ctors <- decls ] ++
|
||||
[ name | TypeAlias name _ (Type.Record _ _) <- decls ]
|
||||
| otherwise = exs
|
||||
|
@ -49,7 +51,7 @@ build noPrelude interfaces source =
|
|||
exports = exports',
|
||||
imports = ims,
|
||||
-- reorder AST into strongly connected components
|
||||
program = SD.sortDefs . dummyLet $ TcDecl.toExpr decls,
|
||||
program = SD.sortDefs . Expr.dummyLet $ TcDecl.toExpr decls,
|
||||
types = Map.empty,
|
||||
datatypes = [ (name,vars,ctors) | Datatype name vars ctors <- decls ],
|
||||
fixities = [ (assoc,level,op) | Fixity assoc level op <- decls ],
|
||||
|
|
|
@ -9,8 +9,12 @@ import qualified Data.Set as Set
|
|||
|
||||
import qualified Generate.Cases as Case
|
||||
import qualified Generate.Markdown as MD
|
||||
import SourceSyntax.Everything
|
||||
import qualified SourceSyntax.Helpers as Help
|
||||
import SourceSyntax.Literal
|
||||
import SourceSyntax.Pattern
|
||||
import SourceSyntax.Location
|
||||
import SourceSyntax.Expression
|
||||
import SourceSyntax.Module
|
||||
import qualified Transform.SortDefinitions as SD
|
||||
import Language.ECMAScript3.Syntax
|
||||
import Language.ECMAScript3.PrettyPrint
|
||||
|
@ -21,7 +25,7 @@ split = go []
|
|||
where
|
||||
go vars str =
|
||||
case break (=='.') str of
|
||||
(x,'.':rest) | isOp x -> vars ++ [x ++ '.' : rest]
|
||||
(x,'.':rest) | Help.isOp x -> vars ++ [x ++ '.' : rest]
|
||||
| otherwise -> go (vars ++ [x]) rest
|
||||
(x,[]) -> vars ++ [x]
|
||||
|
||||
|
@ -197,7 +201,7 @@ definition def =
|
|||
let assign x = varDecl x expr'
|
||||
case pattern of
|
||||
PVar x
|
||||
| isOp x ->
|
||||
| Help.isOp x ->
|
||||
let op = LBracket () (ref "_op") (string x) in
|
||||
return [ ExprStmt () $ AssignExpr () OpAssign op expr' ]
|
||||
| otherwise ->
|
||||
|
@ -220,7 +224,7 @@ definition def =
|
|||
|
||||
decl x n = varDecl x (dotSep ["$","_" ++ show n])
|
||||
setup vars
|
||||
| isTuple name = assign "$" : vars
|
||||
| Help.isTuple name = assign "$" : vars
|
||||
| otherwise = safeAssign : vars
|
||||
|
||||
safeAssign = varDecl "$" (CondExpr () if' expr' exception)
|
||||
|
@ -304,7 +308,7 @@ generate unsafeModule =
|
|||
|
||||
jsExports = assign ("_elm" : names modul ++ ["values"]) (ObjectLit () exs)
|
||||
where
|
||||
exs = map entry . filter (not . isOp) $ "_op" : exports modul
|
||||
exs = map entry . filter (not . Help.isOp) $ "_op" : exports modul
|
||||
entry x = (PropId () (var x), ref x)
|
||||
|
||||
assign path expr =
|
||||
|
@ -380,7 +384,7 @@ binop span op e1 e2 =
|
|||
js1 = expression e1
|
||||
js2 = expression e2
|
||||
|
||||
func | isOp operator = BracketRef () (dotSep (init parts ++ ["_op"])) (string operator)
|
||||
func | Help.isOp operator = BracketRef () (dotSep (init parts ++ ["_op"])) (string operator)
|
||||
| otherwise = dotSep parts
|
||||
where
|
||||
parts = split op
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
module Generate.Noscript (noscript) where
|
||||
|
||||
import Data.List (isInfixOf)
|
||||
import SourceSyntax.Everything
|
||||
import SourceSyntax.Declaration (Declaration(..))
|
||||
import SourceSyntax.Expression
|
||||
import SourceSyntax.Literal
|
||||
import SourceSyntax.Location
|
||||
import SourceSyntax.Module
|
||||
import qualified Generate.Markdown as MD
|
||||
|
||||
noscript :: Module t v -> String
|
||||
|
|
|
@ -11,9 +11,9 @@ import Text.Parsec.Indent
|
|||
|
||||
import Parse.Helpers
|
||||
import Parse.Literal
|
||||
import SourceSyntax.Literal
|
||||
import SourceSyntax.Pattern hiding (tuple, list)
|
||||
import qualified SourceSyntax.Pattern as Pattern
|
||||
import SourceSyntax.Everything hiding (tuple)
|
||||
|
||||
|
||||
basic :: IParser Pattern
|
||||
basic = choice
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
module SourceSyntax.Everything
|
||||
(module SourceSyntax.Helpers,
|
||||
module SourceSyntax.Location,
|
||||
module SourceSyntax.Literal,
|
||||
module SourceSyntax.Pattern,
|
||||
module SourceSyntax.Expression,
|
||||
module SourceSyntax.Declaration,
|
||||
module SourceSyntax.Module
|
||||
) where
|
||||
|
||||
import SourceSyntax.Helpers
|
||||
import SourceSyntax.Location
|
||||
import SourceSyntax.Literal
|
||||
import SourceSyntax.Pattern hiding (tuple, list, cons, nil, prettyParens)
|
||||
import SourceSyntax.Expression
|
||||
import SourceSyntax.Declaration hiding (Assoc(..))
|
||||
import SourceSyntax.Module
|
|
@ -1,7 +1,10 @@
|
|||
module Transform.Check (mistakes) where
|
||||
|
||||
import Transform.SortDefinitions (boundVars)
|
||||
import SourceSyntax.Everything
|
||||
import SourceSyntax.Declaration (Declaration(..))
|
||||
import SourceSyntax.Expression
|
||||
import SourceSyntax.Pattern
|
||||
import SourceSyntax.Location
|
||||
import SourceSyntax.PrettyPrint
|
||||
import qualified SourceSyntax.Type as T
|
||||
import Data.List as List
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
module Transform.Optimize (optimize) where
|
||||
|
||||
import SourceSyntax.Everything
|
||||
import SourceSyntax.Declaration (Declaration(..))
|
||||
import SourceSyntax.Expression
|
||||
import SourceSyntax.Literal
|
||||
import SourceSyntax.Location
|
||||
import SourceSyntax.Module
|
||||
import Control.Arrow (second, (***))
|
||||
import Data.Char (isAlpha)
|
||||
|
||||
|
|
|
@ -6,7 +6,9 @@ import Control.Applicative ((<$>))
|
|||
import qualified Data.Set as Set
|
||||
import qualified Data.Map as Map
|
||||
import qualified SourceSyntax.Type as ST
|
||||
import SourceSyntax.Everything
|
||||
import SourceSyntax.Expression
|
||||
import SourceSyntax.Location
|
||||
import SourceSyntax.Pattern
|
||||
import qualified Data.Graph as Graph
|
||||
import qualified Data.Map as Map
|
||||
import qualified Data.Maybe as Maybe
|
||||
|
|
|
@ -9,7 +9,9 @@ import qualified Type.Constrain.Expression as TcExpr
|
|||
import qualified Type.Environment as Env
|
||||
|
||||
import SourceSyntax.Declaration
|
||||
import qualified SourceSyntax.Everything as Src
|
||||
import qualified SourceSyntax.Expression as Src
|
||||
import qualified SourceSyntax.Location as L
|
||||
import qualified SourceSyntax.Pattern as P
|
||||
import qualified SourceSyntax.Type as Type
|
||||
|
||||
toExpr :: [Declaration t v] -> [Src.Def t v]
|
||||
|
@ -25,34 +27,34 @@ toDefs decl =
|
|||
toDefs (ctor, tipes) =
|
||||
let vars = take (length tipes) arguments
|
||||
tbody = Type.Data name $ map Type.Var tvars
|
||||
body = Src.none . Src.Data ctor $ map (Src.none . Src.Var) vars
|
||||
body = L.none . Src.Data ctor $ map (L.none . Src.Var) vars
|
||||
in [ Src.TypeAnnotation ctor $ foldr Type.Lambda tbody tipes
|
||||
, Src.Def (Src.PVar ctor) $ buildFunction body vars
|
||||
, Src.Def (P.PVar ctor) $ buildFunction body vars
|
||||
]
|
||||
|
||||
TypeAlias name tvars tipe@(Type.Record fields ext) ->
|
||||
[ Src.TypeAnnotation name $ foldr Type.Lambda tipe args
|
||||
, Src.Def (Src.PVar name) $ buildFunction record vars ]
|
||||
, Src.Def (P.PVar name) $ buildFunction record vars ]
|
||||
where
|
||||
args = case ext of
|
||||
Type.EmptyRecord -> map snd fields
|
||||
_ -> map snd fields ++ [ext]
|
||||
|
||||
var = Src.none . Src.Var
|
||||
var = L.none . Src.Var
|
||||
vars = take (length args) arguments
|
||||
|
||||
efields = zip (map fst fields) (map var vars)
|
||||
record = case ext of
|
||||
Type.EmptyRecord -> Src.none $ Src.Record efields
|
||||
_ -> foldl (\r (f,v) -> Src.none $ Src.Insert r f v) (var $ last vars) efields
|
||||
Type.EmptyRecord -> L.none $ Src.Record efields
|
||||
_ -> foldl (\r (f,v) -> L.none $ Src.Insert r f v) (var $ last vars) efields
|
||||
|
||||
-- Type aliases must be added to an extended equality dictionary,
|
||||
-- but they do not require any basic constraints.
|
||||
TypeAlias _ _ _ -> []
|
||||
|
||||
ImportEvent _ expr@(Src.L s _) name tipe ->
|
||||
ImportEvent _ expr@(L.L s _) name tipe ->
|
||||
[ Src.TypeAnnotation name tipe
|
||||
, Src.Def (Src.PVar name) (Src.L s $ Src.App (Src.L s $ Src.Var "constant") expr) ]
|
||||
, Src.Def (P.PVar name) (L.L s $ Src.App (L.L s $ Src.Var "constant") expr) ]
|
||||
|
||||
ExportEvent _ name tipe ->
|
||||
[ Src.TypeAnnotation name tipe ]
|
||||
|
@ -64,5 +66,5 @@ toDefs decl =
|
|||
arguments :: [String]
|
||||
arguments = map (:[]) ['a'..'z'] ++ map (\n -> "_" ++ show n) [1..]
|
||||
|
||||
buildFunction body@(Src.L s _) vars =
|
||||
foldr (\p e -> Src.L s (Src.Lambda p e)) body (map Src.PVar vars)
|
||||
buildFunction body@(L.L s _) vars =
|
||||
foldr (\p e -> L.L s (Src.Lambda p e)) body (map P.PVar vars)
|
Loading…
Reference in a new issue