git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
11 files changed+176−42
since splitsnapshots
unifiedsplit
.gitignore−2 README.md+1−1 app/Main.hs+2−2 package.yaml+6−6 psgo.cabal+145 src/CodeGen/IL.hs+1−1 src/CodeGen/IL/Common.hs+10−19 src/CodeGen/IL/Optimizer/TCO.hs+5−5 src/CodeGen/IL/Printer.hs+3−3 src/Tests.hs+1−2 stack.yaml+2−1
.gitignore−2
@@ -12,8 +12,6 @@ cabal.sandbox.config
1212.test_modules/
1313bower_components/
1414node_modules
15−pscpp.cabal
16−psgo.cabal
1715tmp/
1816.stack-work/
1917stack.yaml.lock
README.md+1−1
@@ -34,7 +34,7 @@ There are two utilities in the purescript-native "suite": `pscpp` and `psgo`. Th
3434
3535
3636#### For more information and a Getting Started guide, please see
37−* [`pscpp`](https://github.com/andyarvanitis/purescript-native/blob/master/README-cpp.md)
37+* [`pscpp`](https://github.com/andyarvanitis/purescript-native/blob/cpp/README-cpp.md)
3838* [`psgo`](https://github.com/andyarvanitis/purescript-native/blob/golang/README-go.md)
3939
4040
app/Main.hs+2−2
@@ -44,7 +44,7 @@ import CodeGen.IL.Printer
4444import Tests
4545
4646data Command = Build | Run (Maybe String)
47−
47+
4848parseJson :: Text -> Value
4949parseJson text
5050 | Just fileJson <- decode . L.encodeUtf8 $ L.fromStrict text = fileJson
@@ -54,7 +54,7 @@ jsonToModule :: Value -> Module Ann
5454jsonToModule value =
5555 case parse moduleFromJSON value of
5656 Success (_, r) -> r
57− _ -> error "failed"
57+ _ -> error "Failed parsing corefn. Psgo currently supports purescript <= 0.13.8"
5858
5959splitArgs :: [String] -> ([String], Maybe String, [String])
6060splitArgs args =
package.yaml+6−6
@@ -24,7 +24,7 @@ description: Please see the README on Github at <https://github.com/andy
2424dependencies:
2525- base >= 4.7 && < 5
2626- bytestring >= 0.10.8.2 && < 0.11
27−- purescript -any
27+- purescript
2828- base-compat >=0.6.0
2929- protolude >=0.1.6
3030- text
@@ -36,11 +36,11 @@ dependencies:
3636- transformers >=0.3.0 && <0.6
3737- mtl >=2.1.0 && <2.3.0
3838- aeson >=1.0 && <1.5
39−- directory -any
40−- process -any
41−- file-embed -any
42−- filemanip -any
43−- gitrev -any
39+- directory
40+- process
41+- file-embed
42+- filemanip
43+- gitrev
4444
4545library:
4646 source-dirs: src
psgo.cabalnew file+145
@@ -0,0 +1,145 @@
1+cabal-version: 1.12
2+
3+-- This file has been generated from package.yaml by hpack version 0.35.0.
4+--
5+-- see: https://github.com/sol/hpack
6+
7+name: psgo
8+version: 0.1.0.0
9+description: Please see the README on Github at <https://github.com/andyarvanitis/purescript-native#readme>
10+homepage: https://github.com/andyarvanitis/purescript-native#readme
11+bug-reports: https://github.com/andyarvanitis/purescript-native/issues
12+author: Andy Arvanitis
13+maintainer: example@example.com
14+copyright: 2018 Andy Arvanitis
15+license: BSD3
16+license-file: LICENSE
17+build-type: Simple
18+extra-source-files:
19+ README.md
20+ ChangeLog.md
21+ stack.yaml
22+ support/ffi-loader.go
23+ support/go.mod.ffi-loader
24+ support/go.mod.output
25+ support/go.mod.working
26+
27+source-repository head
28+ type: git
29+ location: https://github.com/andyarvanitis/purescript-native
30+
31+library
32+ exposed-modules:
33+ CodeGen.IL
34+ CodeGen.IL.Common
35+ CodeGen.IL.Optimizer
36+ CodeGen.IL.Optimizer.Common
37+ CodeGen.IL.Optimizer.Inliner
38+ CodeGen.IL.Optimizer.MagicDo
39+ CodeGen.IL.Optimizer.TCO
40+ CodeGen.IL.Printer
41+ Tests
42+ other-modules:
43+ Paths_psgo
44+ hs-source-dirs:
45+ src
46+ default-extensions:
47+ ConstraintKinds
48+ DataKinds
49+ DeriveFunctor
50+ EmptyDataDecls
51+ FlexibleContexts
52+ KindSignatures
53+ LambdaCase
54+ MultiParamTypeClasses
55+ NoImplicitPrelude
56+ PatternGuards
57+ PatternSynonyms
58+ RankNTypes
59+ RecordWildCards
60+ OverloadedStrings
61+ ScopedTypeVariables
62+ TupleSections
63+ ViewPatterns
64+ build-depends:
65+ aeson >=1.0 && <1.5
66+ , base >=4.7 && <5
67+ , base-compat >=0.6.0
68+ , bytestring >=0.10.8.2 && <0.11
69+ , containers
70+ , directory
71+ , file-embed
72+ , filemanip
73+ , filepath
74+ , gitrev
75+ , monad-parallel >=0.7.2.2 && <0.8
76+ , mtl >=2.1.0 && <2.3.0
77+ , pattern-arrows >=0.0.2 && <0.1
78+ , process
79+ , protolude >=0.1.6
80+ , purescript
81+ , safe >=0.3.9 && <0.4
82+ , text
83+ , transformers >=0.3.0 && <0.6
84+ default-language: Haskell2010
85+
86+executable psgo
87+ main-is: Main.hs
88+ other-modules:
89+ Paths_psgo
90+ hs-source-dirs:
91+ app
92+ ghc-options: -threaded -rtsopts -with-rtsopts=-N
93+ build-depends:
94+ aeson >=1.0 && <1.5
95+ , base >=4.7 && <5
96+ , base-compat >=0.6.0
97+ , bytestring >=0.10.8.2 && <0.11
98+ , containers
99+ , directory
100+ , file-embed
101+ , filemanip
102+ , filepath
103+ , gitrev
104+ , monad-parallel >=0.7.2.2 && <0.8
105+ , mtl >=2.1.0 && <2.3.0
106+ , pattern-arrows >=0.0.2 && <0.1
107+ , process
108+ , protolude >=0.1.6
109+ , psgo
110+ , purescript
111+ , safe >=0.3.9 && <0.4
112+ , text
113+ , transformers >=0.3.0 && <0.6
114+ default-language: Haskell2010
115+
116+test-suite psgo-test
117+ type: exitcode-stdio-1.0
118+ main-is: Spec.hs
119+ other-modules:
120+ Paths_psgo
121+ hs-source-dirs:
122+ test
123+ ghc-options: -threaded -rtsopts -with-rtsopts=-N
124+ build-depends:
125+ aeson >=1.0 && <1.5
126+ , base >=4.7 && <5
127+ , base-compat >=0.6.0
128+ , bytestring >=0.10.8.2 && <0.11
129+ , containers
130+ , directory
131+ , file-embed
132+ , filemanip
133+ , filepath
134+ , gitrev
135+ , monad-parallel >=0.7.2.2 && <0.8
136+ , mtl >=2.1.0 && <2.3.0
137+ , pattern-arrows >=0.0.2 && <0.1
138+ , process
139+ , protolude >=0.1.6
140+ , psgo
141+ , purescript
142+ , safe >=0.3.9 && <0.4
143+ , text
144+ , transformers >=0.3.0 && <0.6
145+ default-language: Haskell2010
src/CodeGen/IL.hs+1−1
@@ -201,7 +201,7 @@ moduleToIL (Module _ coms mn _ imps _ foreigns decls) project =
201201 -- | Generate code in the simplified intermediate representation for a reference to a
202202 -- variable that may have a qualified name.
203203 qualifiedToIL :: (a -> Ident) -> Qualified a -> AST
204− qualifiedToIL f (Qualified (Just (ModuleName [ProperName mn'])) a) | mn' == C.prim = AST.Var Nothing . moduleIdentToIL $ f a
204+ qualifiedToIL f (Qualified (Just (ModuleName mn')) a) | mn' == C.prim = AST.Var Nothing . moduleIdentToIL $ f a
205205 qualifiedToIL f (Qualified (Just mn') a) | mn /= mn' = AST.Indexer Nothing (AST.Var Nothing . moduleIdentToIL $ f a) (AST.Var Nothing (moduleNameToIL mn'))
206206 qualifiedToIL f (Qualified _ a) = AST.Indexer Nothing (AST.Var Nothing . moduleIdentToIL $ f a) (AST.Var Nothing "")
207207
src/CodeGen/IL/Common.hs+10−19
@@ -16,12 +16,12 @@ import Language.PureScript.Names
1616import qualified Language.PureScript.Constants as C
1717
1818moduleNameToIL :: ModuleName -> Text
19−moduleNameToIL (ModuleName pns) =
20− let name = T.intercalate "_" (runProperName `map` pns)
19+moduleNameToIL (ModuleName mn) =
20+ let name = T.replace "." "_" mn
2121 in if nameIsILBuiltIn name then (name <> moduleRenamerMarker) else name
2222
2323moduleNameToIL' :: ModuleName -> Text
24−moduleNameToIL' (ModuleName pns) = T.intercalate "." (runProperName `map` pns)
24+moduleNameToIL' (ModuleName mn) = T.replace "_" "." mn
2525
2626-- | Convert an 'Ident' into a valid IL identifier:
2727--
@@ -50,17 +50,17 @@ unusedName = "_"
5050
5151properToIL :: Text -> Text
5252properToIL name
53− | nameIsILReserved name || nameIsILBuiltIn name || prefixIsReserved name = name <> "ˉ"
53+ | nameIsILReserved name = "ˉ" <> name
5454 | otherwise = T.concatMap identCharToText name
5555
5656-- | Attempts to find a human-readable name for a symbol, if none has been specified returns the
5757-- ordinal value.
5858identCharToText :: Char -> Text
59−identCharToText 'ṩ' = "ᵤṩ"
59+identCharToText 'ṩ' = "_ṩ"
6060identCharToText c | isAlphaNum c = T.singleton c
6161identCharToText '_' = "_"
62−identCharToText '\'' = "ᵖ"
63−identCharToText c = "ᵤ" <> T.pack (show (ord c))
62+identCharToText '\'' = "ꞌ" -- lowercase saltillo
63+identCharToText c = error (show (ord c)) -- TODO: should never occur now(?)
6464
6565moduleProperToIL :: Text -> Text
6666moduleProperToIL = T.concatMap identCharToText
@@ -84,6 +84,7 @@ nameIsILBuiltIn name =
8484 , "Foreign"
8585 , "Get"
8686 , "Index"
87+ , "Is"
8788 , "Length"
8889 , "Once"
8990 , "Run"
@@ -126,16 +127,6 @@ ilKeywords =
126127 , "var"
127128 ]
128129
129−-- moduleIsReserved :: Text -> Bool
130−-- moduleIsReserved "Main" = False
131−-- moduleIsReserved name = not $ T.isInfixOf "_" name
132−
133−prefixIsReserved :: Text -> Bool
134−prefixIsReserved name =
135− any (`T.isPrefixOf` name)
136− [
137− ]
138−
139130ilLiterals :: [Text]
140131ilLiterals =
141132 [ "init"
@@ -161,7 +152,7 @@ ilLiterals =
161152 ]
162153
163154withPrefix :: Text -> Text
164−withPrefix s = "Ꞌ" <> s
155+withPrefix s = "Ꞌ" <> s -- uppercase saltillo
165156
166157anyType :: Text
167158anyType = "Any"
@@ -202,4 +193,4 @@ freshName' = do
202193 return $ T.replace "$" "ṩ" name
203194
204195moduleRenamerMarker :: Text
205−moduleRenamerMarker = "ᴹ"
196+moduleRenamerMarker = "__"
src/CodeGen/IL/Optimizer/TCO.hs+5−5
@@ -12,21 +12,21 @@ import CodeGen.IL.Common
1212import qualified Language.PureScript.Constants as C
1313
1414tcoLoop :: Text
15−tcoLoop = "__tco_loop"
15+tcoLoop = "ṩtco_loop"
1616
1717tco :: AST -> AST -> AST
1818tco mn = everywhere convert where
1919 tcoVar :: Text -> Text
20− tcoVar arg = "__tco_var_" <> arg
20+ tcoVar arg = "ṩtco_var_" <> arg
2121
2222 copyVar :: Text -> Text
23− copyVar arg = "__copy_" <> arg
23+ copyVar arg = "ṩcopy_" <> arg
2424
2525 tcoDone :: Text
26− tcoDone = "__tco_done"
26+ tcoDone = "ṩtco_done"
2727
2828 tcoResult :: Text
29− tcoResult = "__tco_result"
29+ tcoResult = "ṩtco_result"
3030
3131 convert :: AST -> AST
3232 convert fn@(Function ss (Just name) args _)
src/CodeGen/IL/Printer.hs+3−3
@@ -234,7 +234,7 @@ literals = mkPattern' match'
234234 , return $ emit "]"
235235 ]
236236 match (InstanceOf _ val ty) = mconcat <$> sequence
237− [ return $ emit "Contains("
237+ [ return $ emit "Is("
238238 , prettyPrintIL' val
239239 , return $ emit ", "
240240 , prettyPrintIL' ty
@@ -521,7 +521,7 @@ ffiLoader :: Text
521521ffiLoader = modLabel <> "/ffi-loader"
522522
523523initName :: Text -> Text
524−initName s = "_" <> s <> "ᵒⁿᶜᵉ"
524+initName s = "ᛌ" <> s <> "_once"
525525
526526valueName :: Text -> Text
527−valueName s = "_" <> s <> "ᶠᵒʳᵉⁱᵍⁿ"
527+valueName s = "ᛧ" <> s
src/Tests.hs+1−2
@@ -63,9 +63,8 @@ runTests = do
6363 callProcess "rm" ["-rf", "output"]
6464 callProcess "rm" ["-rf", "Main"]
6565 callProcess "spago" ["build"]
66− callProcess "psgo" []
6766 --
68− -- Run C++ files
67+ -- Run executable file
6968 --
7069 outputFile <- openFile (tmp </> logpath </> logfile) AppendMode
7170 hPutStrLn outputFile ("\n" ++ inputFile ++ ":")
stack.yaml+2−1
@@ -5,7 +5,7 @@ packages:
55
66extra-deps:
77- git: https://github.com/purescript/purescript
8− commit: 4dd32c48a372bb8a5250140d19af8aa18a6358d7
8+ commit: 9cad73ed8ea7df3011032ddbd2f3de5a0c08629c
99- happy-1.19.9
1010- language-javascript-0.7.0.0
1111- network-3.0.1.1
@@ -13,6 +13,7 @@ extra-deps:
1313- semialign-1
1414
1515nix:
16+ enable: false
1617 shell-file: stack.nix
1718
1819flags: