Skip to content

Commit 5cee177

Browse files
committed
Simplify representation of foreign declarations
1 parent 330bab9 commit 5cee177

File tree

23 files changed

+69
-102
lines changed

23 files changed

+69
-102
lines changed

psc-docs/Main.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ docgen (PSCDocsOptions fmt input output) =
9393
let fp = fst (head grp)
9494
createDirectoryIfMissing True (takeDirectory fp)
9595
writeFile fp (D.renderModulesAsMarkdown $ snd `map` grp)
96-
9796
where
9897
guardMissing [] = return ()
9998
guardMissing [mn] = do

psc-docs/Tags.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ tags = concatMap dtags . P.exportedDeclarations
1111
names (P.DataDeclaration _ name _ dcons) = P.runProperName name : consNames
1212
where consNames = map (\(cname, _) -> P.runProperName cname) dcons
1313
names (P.TypeDeclaration ident _) = [show ident]
14-
names (P.ExternDeclaration _ ident _ _) = [show ident]
14+
names (P.ExternDeclaration ident _) = [show ident]
1515
names (P.TypeSynonymDeclaration name _ _) = [P.runProperName name]
1616
names (P.TypeClassDeclaration name _ _ _) = [P.runProperName name]
1717
names (P.TypeInstanceDeclaration name _ _ _ _) = [show name]

psci/Completion.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ identNames = nubOnFst . mapMaybe getDeclName . P.exportedDeclarations
199199
where
200200
getDeclName :: P.Declaration -> Maybe (P.Ident, P.Declaration)
201201
getDeclName d@(P.ValueDeclaration ident _ _ _) = Just (ident, d)
202-
getDeclName d@(P.ExternDeclaration _ ident _ _) = Just (ident, d)
202+
getDeclName d@(P.ExternDeclaration ident _) = Just (ident, d)
203203
getDeclName (P.PositionedDeclaration _ _ d) = getDeclName d
204204
getDeclName _ = Nothing
205205

psci/PSCi.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ supportModuleName = P.ModuleName [P.ProperName "$PSCI", P.ProperName "Support"]
6565

6666
-- | Support module, contains code to evaluate terms
6767
supportModule :: P.Module
68-
supportModule =
68+
supportModule =
6969
case P.parseModulesFromFiles id [("", code)] of
7070
Right [(_, P.Module cs _ ds exps)] -> P.Module cs supportModuleName ds exps
7171
_ -> error "Support module could not be parsed"
@@ -245,8 +245,8 @@ createTemporaryModule exec PSCiState{psciImportedModules = imports, psciLetBindi
245245
moduleName = P.ModuleName [P.ProperName "$PSCI"]
246246
trace = P.Var (P.Qualified (Just supportModuleName) (P.Ident "eval"))
247247
mainValue = P.App trace (P.Var (P.Qualified Nothing (P.Ident "it")))
248-
itDecl = P.ValueDeclaration (P.Ident "it") P.Value [] $ Right val
249-
mainDecl = P.ValueDeclaration (P.Ident "main") P.Value [] $ Right mainValue
248+
itDecl = P.ValueDeclaration (P.Ident "it") P.Public [] $ Right val
249+
mainDecl = P.ValueDeclaration (P.Ident "main") P.Public [] $ Right mainValue
250250
decls = if exec then [itDecl, mainDecl] else [itDecl]
251251
in
252252
P.Module [] moduleName ((importDecl `map` imports) ++ lets ++ decls) Nothing

psci/Parser.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@ discardPositionInfo (P.PositionedDeclaration _ _ d) = d
122122
discardPositionInfo d = d
123123

124124
acceptable :: P.Declaration -> Bool
125-
acceptable (P.DataDeclaration _ _ _ _) = True
126-
acceptable (P.TypeSynonymDeclaration _ _ _) = True
127-
acceptable (P.ExternDeclaration _ _ _ _) = True
128-
acceptable (P.ExternDataDeclaration _ _) = True
129-
acceptable (P.ExternInstanceDeclaration _ _ _ _) = True
130-
acceptable (P.TypeClassDeclaration _ _ _ _) = True
131-
acceptable (P.TypeInstanceDeclaration _ _ _ _ _) = True
125+
acceptable P.DataDeclaration{} = True
126+
acceptable P.TypeSynonymDeclaration{} = True
127+
acceptable P.ExternDeclaration{} = True
128+
acceptable P.ExternDataDeclaration{} = True
129+
acceptable P.ExternInstanceDeclaration{} = True
130+
acceptable P.TypeClassDeclaration{} = True
131+
acceptable P.TypeInstanceDeclaration{} = True
132132
acceptable _ = False
133133

134134
parseReplQuery' :: String -> Either String ReplQuery

src/Language/PureScript/AST/Declarations.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import Language.PureScript.Names
2626
import Language.PureScript.Kinds
2727
import Language.PureScript.TypeClassDictionaries
2828
import Language.PureScript.Comments
29-
import Language.PureScript.CodeGen.JS.AST
3029
import Language.PureScript.Environment
3130

3231
-- |
@@ -122,9 +121,9 @@ data Declaration
122121
--
123122
| BindingGroupDeclaration [(Ident, NameKind, Expr)]
124123
-- |
125-
-- A foreign import declaration (type, name, optional inline Javascript, type)
124+
-- A foreign import declaration (name, type)
126125
--
127-
| ExternDeclaration ForeignImportType Ident (Maybe JS) Type
126+
| ExternDeclaration Ident Type
128127
-- |
129128
-- A data type foreign import (name, kind)
130129
--
@@ -255,7 +254,7 @@ data Expr
255254
--
256255
| StringLiteral String
257256
-- |
258-
-- A character literal
257+
-- A character literal
259258
--
260259
| CharLiteral Char
261260
-- |

src/Language/PureScript/AST/Exported.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ isExported (Just exps) decl = any (matches decl) exps
109109
where
110110
matches (TypeDeclaration ident _) (ValueRef ident') = ident == ident'
111111
matches (ValueDeclaration ident _ _ _) (ValueRef ident') = ident == ident'
112-
matches (ExternDeclaration _ ident _ _) (ValueRef ident') = ident == ident'
112+
matches (ExternDeclaration ident _) (ValueRef ident') = ident == ident'
113113
matches (DataDeclaration _ ident _ _) (TypeRef ident' _) = ident == ident'
114114
matches (ExternDataDeclaration ident _) (TypeRef ident' _) = ident == ident'
115115
matches (TypeSynonymDeclaration ident _ _) (TypeRef ident' _) = ident == ident'

src/Language/PureScript/AST/Traversals.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ accumTypes :: (Monoid r) => (Type -> r) -> (Declaration -> r, Expr -> r, Binder
387387
accumTypes f = everythingOnValues mappend forDecls forValues (const mempty) (const mempty) (const mempty)
388388
where
389389
forDecls (DataDeclaration _ _ _ dctors) = mconcat (concatMap (map f . snd) dctors)
390-
forDecls (ExternDeclaration _ _ _ ty) = f ty
390+
forDecls (ExternDeclaration _ ty) = f ty
391391
forDecls (ExternInstanceDeclaration _ cs _ tys) = mconcat (concatMap (map f . snd) cs) `mappend` mconcat (map f tys)
392392
forDecls (TypeClassDeclaration _ _ implies _) = mconcat (concatMap (map f . snd) implies)
393393
forDecls (TypeInstanceDeclaration _ cs _ tys _) = mconcat (concatMap (map f . snd) cs) `mappend` mconcat (map f tys)

src/Language/PureScript/CodeGen/Externs.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ moduleToPs (Module _ moduleName ds (Just exts)) env = intercalate "\n" . execWri
9090
exportToPs (ValueRef ident) =
9191
case (moduleName, ident) `M.lookup` names env of
9292
Nothing -> error $ show ident ++ " has no type in exportToPs"
93-
Just (ty, nameKind, _) | nameKind == Value || nameKind == Extern ForeignImport || nameKind == Extern InlineJavascript ->
93+
Just (ty, Public, _) ->
9494
tell ["foreign import " ++ show ident ++ " :: " ++ prettyPrintType ty]
9595
_ -> return ()
9696
exportToPs (TypeClassRef className) =

src/Language/PureScript/CodeGen/JS.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ module Language.PureScript.CodeGen.JS
2626
) where
2727

2828
import Data.List ((\\), delete)
29-
import Data.Maybe (mapMaybe)
3029
import qualified Data.Traversable as T (traverse)
3130

3231
import Control.Applicative
@@ -54,7 +53,7 @@ moduleToJs :: forall m mode. (Applicative m, Monad m, MonadReader (Options mode)
5453
moduleToJs (Module coms mn imps exps foreigns decls) = do
5554
additional <- asks optionsAdditional
5655
jsImports <- T.traverse importToJs . delete (ModuleName [ProperName C.prim]) . (\\ [mn]) $ imps
57-
let foreigns' = mapMaybe (\(_, js, _) -> js) foreigns
56+
let foreigns' = [] -- TODO: Update this. mapMaybe (\(_, js, _) -> js) foreigns
5857
jsDecls <- mapM bindToJs decls
5958
optimized <- T.traverse (T.traverse optimize) jsDecls
6059
let isModuleEmpty = null exps

0 commit comments

Comments
 (0)