Skip to content

Commit 72ce900

Browse files
committed
WIP: new externs file format
1 parent e2385f4 commit 72ce900

29 files changed

+378
-316
lines changed

psci/Parser.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ acceptable P.DataDeclaration{} = True
131131
acceptable P.TypeSynonymDeclaration{} = True
132132
acceptable P.ExternDeclaration{} = True
133133
acceptable P.ExternDataDeclaration{} = True
134-
acceptable P.ExternInstanceDeclaration{} = True
135134
acceptable P.TypeClassDeclaration{} = True
136135
acceptable P.TypeInstanceDeclaration{} = True
137136
acceptable _ = False

purescript.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ library
6868
Language.PureScript.AST.Traversals
6969
Language.PureScript.AST.Exported
7070
Language.PureScript.Bundle
71+
Language.PureScript.Externs
7172
Language.PureScript.CodeGen
72-
Language.PureScript.CodeGen.Externs
7373
Language.PureScript.CodeGen.JS
7474
Language.PureScript.CodeGen.JS.AST
7575
Language.PureScript.CodeGen.JS.Common

src/Language/PureScript/AST/Declarations.hs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414

1515
{-# LANGUAGE DeriveDataTypeable #-}
1616
{-# LANGUAGE ScopedTypeVariables #-}
17+
{-# LANGUAGE TemplateHaskell #-}
1718
{-# LANGUAGE CPP #-}
1819

1920
module Language.PureScript.AST.Declarations where
2021

22+
import Data.Aeson.TH
23+
2124
import qualified Data.Data as D
2225
import qualified Data.Map as M
2326

@@ -147,10 +150,6 @@ data Declaration
147150
--
148151
| ExternDataDeclaration ProperName Kind
149152
-- |
150-
-- A type class instance foreign import
151-
--
152-
| ExternInstanceDeclaration Ident [Constraint] (Qualified ProperName) [Type]
153-
-- |
154153
-- A fixity declaration (fixity data, operator name)
155154
--
156155
| FixityDeclaration Fixity String
@@ -222,14 +221,6 @@ isExternDataDecl ExternDataDeclaration{} = True
222221
isExternDataDecl (PositionedDeclaration _ _ d) = isExternDataDecl d
223222
isExternDataDecl _ = False
224223

225-
-- |
226-
-- Test if a declaration is a type class instance foreign import
227-
--
228-
isExternInstanceDecl :: Declaration -> Bool
229-
isExternInstanceDecl ExternInstanceDeclaration{} = True
230-
isExternInstanceDecl (PositionedDeclaration _ _ d) = isExternInstanceDecl d
231-
isExternInstanceDecl _ = False
232-
233224
-- |
234225
-- Test if a declaration is a fixity declaration
235226
--
@@ -442,3 +433,6 @@ data DoNotationElement
442433
-- A do notation element with source position information
443434
--
444435
| PositionedDoNotationElement SourceSpan [Comment] DoNotationElement deriving (Show, Read, D.Data, D.Typeable)
436+
437+
$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''DeclarationRef)
438+
$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''ImportDeclarationType)

src/Language/PureScript/AST/Operators.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,18 @@ showAssoc Infixl = "infixl"
3636
showAssoc Infixr = "infixr"
3737
showAssoc Infix = "infix"
3838

39+
readAssoc :: String -> Associativity
40+
readAssoc "infixl" = Infixl
41+
readAssoc "infixr" = Infixr
42+
readAssoc "infix" = Infix
43+
readAssoc _ = error "readAssoc: no parse"
44+
3945
instance A.ToJSON Associativity where
4046
toJSON = A.toJSON . showAssoc
4147

48+
instance A.FromJSON Associativity where
49+
parseJSON = fmap readAssoc . A.parseJSON
50+
4251
-- |
4352
-- Fixity data for infix operators
4453
--

src/Language/PureScript/AST/SourcePos.hs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
module Language.PureScript.AST.SourcePos where
2121

2222
import qualified Data.Data as D
23-
import Data.Aeson ((.=))
23+
import Data.Aeson ((.=), (.:))
2424
import qualified Data.Aeson as A
2525

2626
-- |
@@ -46,6 +46,11 @@ instance A.ToJSON SourcePos where
4646
toJSON SourcePos{..} =
4747
A.toJSON [sourcePosLine, sourcePosColumn]
4848

49+
instance A.FromJSON SourcePos where
50+
parseJSON arr = do
51+
[line, col] <- A.parseJSON arr
52+
return $ SourcePos line col
53+
4954
data SourceSpan = SourceSpan
5055
{ -- |
5156
-- Source name
@@ -77,5 +82,12 @@ instance A.ToJSON SourceSpan where
7782
, "end" .= spanEnd
7883
]
7984

85+
instance A.FromJSON SourceSpan where
86+
parseJSON = A.withObject "SourceSpan" $ \o ->
87+
SourceSpan <$>
88+
o .: "name" <*>
89+
o .: "start" <*>
90+
o .: "end"
91+
8092
internalModuleSourceSpan :: String -> SourceSpan
8193
internalModuleSourceSpan name = SourceSpan name (SourcePos 0 0) (SourcePos 0 0)

src/Language/PureScript/AST/Traversals.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ accumTypes f = everythingOnValues mappend forDecls forValues (const mempty) (con
397397
where
398398
forDecls (DataDeclaration _ _ _ dctors) = mconcat (concatMap (map f . snd) dctors)
399399
forDecls (ExternDeclaration _ ty) = f ty
400-
forDecls (ExternInstanceDeclaration _ cs _ tys) = mconcat (concatMap (map f . snd) cs) `mappend` mconcat (map f tys)
401400
forDecls (TypeClassDeclaration _ _ implies _) = mconcat (concatMap (map f . snd) implies)
402401
forDecls (TypeInstanceDeclaration _ cs _ tys _) = mconcat (concatMap (map f . snd) cs) `mappend` mconcat (map f tys)
403402
forDecls (TypeSynonymDeclaration _ _ ty) = f ty

src/Language/PureScript/CodeGen.hs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,8 @@
1313
--
1414
-- [@Language.PureScript.CodeGen.JS@] Code generator for Javascript
1515
--
16-
-- [@Language.PureScript.CodeGen.Externs@] Code generator for extern (foreign import) files
17-
--
18-
-- [@Language.PureScript.CodeGen.Optimize@] Optimization passes for generated Javascript
19-
--
2016
-----------------------------------------------------------------------------
2117

2218
module Language.PureScript.CodeGen (module C) where
2319

2420
import Language.PureScript.CodeGen.JS as C
25-
import Language.PureScript.CodeGen.Externs as C

src/Language/PureScript/CodeGen/Externs.hs

Lines changed: 0 additions & 144 deletions
This file was deleted.

src/Language/PureScript/Comments.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414
-----------------------------------------------------------------------------
1515

1616
{-# LANGUAGE DeriveDataTypeable #-}
17+
{-# LANGUAGE TemplateHaskell #-}
1718

1819
module Language.PureScript.Comments where
1920

21+
import Data.Aeson.TH
2022
import qualified Data.Data as D
2123

2224
data Comment
2325
= LineComment String
2426
| BlockComment String
2527
deriving (Show, Read, Eq, Ord, D.Data, D.Typeable)
28+
29+
$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''Comment)

src/Language/PureScript/CoreFn/Desugar.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ importToCoreFn _ = Nothing
225225
--
226226
externToCoreFn :: A.Declaration -> Maybe ForeignDecl
227227
externToCoreFn (A.ExternDeclaration name ty) = Just (name, ty)
228-
externToCoreFn (A.ExternInstanceDeclaration name _ _ _) = Just (name, tyObject)
229228
externToCoreFn (A.PositionedDeclaration _ _ d) = externToCoreFn d
230229
externToCoreFn _ = Nothing
231230

0 commit comments

Comments
 (0)