git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge remote-tracking branch 'pure11/pure11' into native
aded024Andy Arvanitis
pcc/Main.hs+9
@@ -54,6 +54,7 @@ data PCCMakeOptions = PCCMakeOptions
54 , pccmOpts :: P.Options
54 , pccmOpts :: P.Options
55 , pccmUsePrefix :: Bool
55 , pccmUsePrefix :: Bool
56 , pccmJSONErrors :: Bool
56 , pccmJSONErrors :: Bool
57+ , pccmXcode :: Bool
57 }
58 }
58
59
59-- | Argumnets: verbose, use JSON, warnings, errors
60-- | Argumnets: verbose, use JSON, warnings, errors
@@ -77,6 +78,8 @@ printWarningsAndErrors verbose True warnings errors = do
77compile :: PCCMakeOptions -> IO ()
78compile :: PCCMakeOptions -> IO ()
78compile PCCMakeOptions{..} = do
79compile PCCMakeOptions{..} = do
79 input <- globWarningOnMisses (unless pccmJSONErrors . warnFileTypeNotFound) pccmInput
80 input <- globWarningOnMisses (unless pccmJSONErrors . warnFileTypeNotFound) pccmInput
81+ when pccmXcode $ do
82+ generateXcodefile
80 when (null input && not pccmJSONErrors) $ do
83 when (null input && not pccmJSONErrors) $ do
81 generatePackagefile
84 generatePackagefile
82 generateMakefile
85 generateMakefile
@@ -165,6 +168,11 @@ dumpCoreFn = switch $
165 long "dump-corefn"
168 long "dump-corefn"
166 <> help "Dump the (functional) core representation of the compiled code at output/*/corefn.json"
169 <> help "Dump the (functional) core representation of the compiled code at output/*/corefn.json"
167
170
171+xcode :: Parser Bool
172+xcode = switch $
173+ long "xcode"
174+ <> help "Generate support files for Xcode"
175+
168options :: Parser P.Options
176options :: Parser P.Options
169options = P.Options <$> noTco
177options = P.Options <$> noTco
170 <*> noMagicDo
178 <*> noMagicDo
@@ -181,6 +189,7 @@ pccMakeOptions = PCCMakeOptions <$> many inputFile
181 <*> options
189 <*> options
182 <*> (not <$> noPrefix)
190 <*> (not <$> noPrefix)
183 <*> jsonErrors
191 <*> jsonErrors
192+ <*> xcode
184
193
185main :: IO ()
194main :: IO ()
186main = do
195main = do
pcc/Makefile+17−5
@@ -14,7 +14,9 @@
14#
14#
15# You can also edit the generated version of this file directly.
15# You can also edit the generated version of this file directly.
16#
16#
17−PCC := {bin/pcc} # example: /usr/local/bin/pcc
17+PCC := {{path}}/pcc
18+PSC_PKG_BIN := psc-package
19+PSC_PACKAGE := {{path}}/$(PSC_PKG_BIN)
18PURESCRIPT_PKGS := .psc-package
20PURESCRIPT_PKGS := .psc-package
19PURESCRIPT_SRC := src
21PURESCRIPT_SRC := src
20OUTPUT := output
22OUTPUT := output
@@ -25,6 +27,10 @@ override PCCFLAGS += --comments
25override CXXFLAGS += -std=c++11
27override CXXFLAGS += -std=c++11
26override LDFLAGS +=
28override LDFLAGS +=
27
29
30+ifeq ("$(wildcard $(PSC_PACKAGE))","")
31+ PSC_PACKAGE := $(PSC_PKG_BIN)
32+endif
33+
28ifeq ($(GC),yes)
34ifeq ($(GC),yes)
29 override CXXFLAGS += -DUSE_GC
35 override CXXFLAGS += -DUSE_GC
30 override LDFLAGS += -lgc
36 override LDFLAGS += -lgc
@@ -42,15 +48,21 @@ release: codegen
42debug: codegen
48debug: codegen
43 @$(MAKE) $(BIN) CXXFLAGS+=$(DEBUG)
49 @$(MAKE) $(BIN) CXXFLAGS+=$(DEBUG)
44
50
51+release-object: codegen
52+ @$(MAKE) $(OBJ) CXXFLAGS+=$(RELEASE)
53+
54+debug-object: codegen
55+ @$(MAKE) $(OBJ) CXXFLAGS+=$(DEBUG)
56+
45codegen: PURESCRIPT_PKG_SRCS=$(shell find $(PURESCRIPT_PKGS) -name '*.purs' | grep -v \/test\/ | grep -v \/example\/ | grep -v \/examples\/)
57codegen: PURESCRIPT_PKG_SRCS=$(shell find $(PURESCRIPT_PKGS) -name '*.purs' | grep -v \/test\/ | grep -v \/example\/ | grep -v \/examples\/)
46codegen: PURESCRIPT_SRCS=$(shell find $(PURESCRIPT_SRC) -name '*.purs')
58codegen: PURESCRIPT_SRCS=$(shell find $(PURESCRIPT_SRC) -name '*.purs')
47#
59#
48−codegen: .psc-package
60+codegen: $(PURESCRIPT_PKGS)
49 @$(PCC) $(PCCFLAGS) --output $(OUTPUT) $(PURESCRIPT_PKG_SRCS) $(PURESCRIPT_SRCS)
61 @$(PCC) $(PCCFLAGS) --output $(OUTPUT) $(PURESCRIPT_PKG_SRCS) $(PURESCRIPT_SRCS)
50
62
51−.psc-package:
63+$(PURESCRIPT_PKGS):
52− @echo "Getting packages using 'psc-package'..."
64+ @echo "Getting packages using" $(PSC_PACKAGE) "..."
53− @-psc-package update
65+ @$(PSC_PACKAGE) update
54
66
55SRCS := $(shell find $(OUTPUT) 2>/dev/null -name '*.cc')
67SRCS := $(shell find $(OUTPUT) 2>/dev/null -name '*.cc')
56
68
pcc/Makefile.hs+33−16
@@ -19,18 +19,24 @@ import Control.Monad (when)
19import Data.FileEmbed (embedFile)
19import Data.FileEmbed (embedFile)
20import System.Environment (getExecutablePath)
20import System.Environment (getExecutablePath)
21import System.Directory (doesFileExist)
21import System.Directory (doesFileExist)
22+import System.FilePath (takeDirectory)
22
23
24+import qualified Data.Text as T
23import qualified Data.ByteString.Char8 as B
25import qualified Data.ByteString.Char8 as B
24
26
25generateMakefile :: IO ()
27generateMakefile :: IO ()
26generateMakefile = do
28generateMakefile = do
27− makefileExists <- doesFileExist "Makefile"
29+ makefileExists <- doesFileExist makefilename
28 when (not makefileExists) $ do
30 when (not makefileExists) $ do
29 let makefile = $(embedFile "pcc/Makefile")
31 let makefile = $(embedFile "pcc/Makefile")
30 exePath <- getExecutablePath
32 exePath <- getExecutablePath
31 putStrLn ""
33 putStrLn ""
32− putStrLn $ "Generating Makefile... " ++ "pcc executable location " ++ exePath
34+ putStrLn $ "Generating " ++ makefilename ++ "... " ++ "pcc executable location " ++ exePath
33− writeFile "Makefile" $ replace makefile pccPath exePath
35+ writeFile makefilename . T.unpack $
36+ T.replace
37+ pathPlaceholder
38+ (T.pack $ takeDirectory exePath)
39+ (T.pack $ B.unpack makefile)
34 putStrLn "Done"
40 putStrLn "Done"
35 putStrLn ""
41 putStrLn ""
36 putStrLn "Run 'make' or 'make release' to build an optimized release build."
42 putStrLn "Run 'make' or 'make release' to build an optimized release build."
@@ -42,23 +48,34 @@ generateMakefile = do
42
48
43generatePackagefile :: IO ()
49generatePackagefile :: IO ()
44generatePackagefile = do
50generatePackagefile = do
45− pkgfileExists <- doesFileExist "psc-package.json"
51+ pkgfileExists <- doesFileExist packagefilename
46 when (not pkgfileExists) $ do
52 when (not pkgfileExists) $ do
47 let pkgfile = $(embedFile "pcc/psc-package.json")
53 let pkgfile = $(embedFile "pcc/psc-package.json")
48 putStrLn ""
54 putStrLn ""
49− putStrLn "Generating psc-package.json..."
55+ putStrLn $ "Generating " ++ packagefilename ++ "..."
50− writeFile "psc-package.json" $ B.unpack pkgfile
56+ writeFile packagefilename $ B.unpack pkgfile
51 putStrLn "Done"
57 putStrLn "Done"
52 putStrLn "Use the 'psc-package' utility to install or update packages."
58 putStrLn "Use the 'psc-package' utility to install or update packages."
53
59
54−replace :: B.ByteString -> B.ByteString -> String -> String
60+generateXcodefile :: IO ()
55−replace s orig repl = replace'
61+generateXcodefile = do
56− where
62+ xcodefileExists <- doesFileExist xcodefilename
57− replace'
63+ when (not xcodefileExists) $ do
58− | (p1, p2) <- B.breakSubstring orig s,
64+ let xcodefile = $(embedFile "pcc/psc-xcode.sh")
59− not (B.null p2) = B.unpack p1 ++ repl ++ trim (B.unpack p2)
65+ putStrLn ""
60− | otherwise = B.unpack s
66+ putStrLn $ "Generating " ++ xcodefilename ++ "..."
61− trim = drop (B.length orig)
67+ writeFile xcodefilename $ B.unpack xcodefile
68+ putStrLn "Done"
69+ putStrLn "Add this file to an Xcode 'Run Script' build phase."
70+
71+makefilename :: String
72+makefilename = "Makefile"
73+
74+packagefilename :: String
75+packagefilename = "psc-package.json"
76+
77+xcodefilename :: String
78+xcodefilename = "psc-xcode.sh"
62
79
63−pccPath :: B.ByteString
80+pathPlaceholder :: T.Text
64−pccPath = "{bin/pcc}"
81+pathPlaceholder = "{{path}}"
pcc/psc-xcode.shnew file+42
@@ -0,0 +1,42 @@
1+# Xcode support script. Intended to be added to and called from "Run Script" build phase.
2+#
3+#!/bin/sh
4+
5+echo "CONFIGURATION =" "$CONFIGURATION"
6+echo "ARCHITECTURES =" "$ARCHS"
7+
8+IS_DEBUG="$PROJECT_TEMP_DIR/is_debug"
9+IS_RELEASE="$PROJECT_TEMP_DIR/is_release"
10+
11+if [[ "$CONFIGURATION" == "Debug" ]] ; then
12+ if [ ! -f "$IS_DEBUG" ] ; then
13+ make clean
14+ touch "$IS_DEBUG"
15+ fi
16+ rm "$IS_RELEASE" > /dev/null 2>&1 || true
17+ OBJECT_TYPE=debug-object
18+else
19+ if [ ! -f "$IS_RELEASE" ] ; then
20+ make clean
21+ touch "$IS_RELEASE"
22+ fi
23+ rm "$IS_DEBUG" > /dev/null 2>&1 || true
24+ OBJECT_TYPE=release-object
25+fi
26+
27+## Create compiler switches for architectures
28+#
29+for arch_ in $ARCHS ; do
30+ ARCH_OPTS+="-arch $arch_ "
31+ if ! file output/bin/purescript.o | grep -q $arch_; then
32+ make clean
33+ fi
34+ # TODO: make this more future-proof
35+ # Note: -flto optimization causes problems with the source-level
36+ # debugger. Disable bitcode temporarily if necessary.
37+ if [[ $ENABLE_BITCODE == YES && $arch == arm64 ]] ; then
38+ FLTO="-flto"
39+ fi
40+done
41+
42+make $OBJECT_TYPE ${PSC_PKG} CXXFLAGS="$ARCH_OPTS $FLTO -isysroot $SDKROOT" LD="clang -Wl,-r -nostdlib $ARCH_OPTS" -j`sysctl -n hw.ncpu`
pcc/runtime/purescript.hh+4
@@ -15,6 +15,10 @@
15#ifndef PureScript_HH
15#ifndef PureScript_HH
16#define PureScript_HH
16#define PureScript_HH
17
17
18+#if !defined(__cplusplus)
19+#error This is a C++ file!
20+#endif
21+
18// Standard includes
22// Standard includes
19
23
20#if defined(DEBUG)
24#if defined(DEBUG)
psc-package/Main.hs+23
@@ -181,6 +181,14 @@ install pkgName = do
181 writePackageFile pkg'
181 writePackageFile pkg'
182 echo "psc-package.json file was updated"
182 echo "psc-package.json file was updated"
183
183
184+uninstall :: String -> IO ()
185+uninstall pkgName = do
186+ pkg <- readPackageFile
187+ let pkg' = pkg { depends = filter (/= pack pkgName) $ depends pkg }
188+ updateImpl pkg'
189+ writePackageFile pkg'
190+ echo "psc-package.json file was updated"
191+
184listDependencies :: IO ()
192listDependencies :: IO ()
185listDependencies = do
193listDependencies = do
186 pkg@PackageConfig{ depends } <- readPackageFile
194 pkg@PackageConfig{ depends } <- readPackageFile
@@ -188,6 +196,15 @@ listDependencies = do
188 trans <- getTransitiveDeps db depends
196 trans <- getTransitiveDeps db depends
189 traverse_ (echo . fst) trans
197 traverse_ (echo . fst) trans
190
198
199+listPackages :: IO ()
200+listPackages = do
201+ pkg <- readPackageFile
202+ db <- readPackageSet pkg
203+ traverse_ echo (fmt <$> Map.assocs db)
204+ where
205+ fmt :: (Text, PackageInfo) -> Text
206+ fmt (name, PackageInfo{ version }) = name <> " (" <> version <> ")"
207+
191getSourcePaths :: PackageConfig -> PackageSet -> [Text] -> IO [Turtle.FilePath]
208getSourcePaths :: PackageConfig -> PackageSet -> [Text] -> IO [Turtle.FilePath]
192getSourcePaths PackageConfig{..} db pkgNames = do
209getSourcePaths PackageConfig{..} db pkgNames = do
193 trans <- getTransitiveDeps db pkgNames
210 trans <- getTransitiveDeps db pkgNames
@@ -240,6 +257,9 @@ main = do
240 , Opts.command "update"
257 , Opts.command "update"
241 (Opts.info (pure update)
258 (Opts.info (pure update)
242 (Opts.progDesc "Update dependencies"))
259 (Opts.progDesc "Update dependencies"))
260+ , Opts.command "uninstall"
261+ (Opts.info (uninstall <$> pkg)
262+ (Opts.progDesc "Uninstall the named package"))
243 , Opts.command "install"
263 , Opts.command "install"
244 (Opts.info (install <$> pkg)
264 (Opts.info (install <$> pkg)
245 (Opts.progDesc "Install the named package"))
265 (Opts.progDesc "Install the named package"))
@@ -252,6 +272,9 @@ main = do
252 , Opts.command "sources"
272 , Opts.command "sources"
253 (Opts.info (pure listSourcePaths)
273 (Opts.info (pure listSourcePaths)
254 (Opts.progDesc "List all (active) source paths for dependencies"))
274 (Opts.progDesc "List all (active) source paths for dependencies"))
275+ , Opts.command "available"
276+ (Opts.info (pure listPackages)
277+ (Opts.progDesc "List all packages available in the package set"))
255 ]
278 ]
256 where
279 where
257 pkg = Opts.strArgument $
280 pkg = Opts.strArgument $
src/Language/PureScript/Errors.hs+1−1
@@ -640,7 +640,7 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
640 go _ = False
640 go _ = False
641 renderSimpleErrorMessage (AmbiguousTypeVariables t _) =
641 renderSimpleErrorMessage (AmbiguousTypeVariables t _) =
642 paras [ line "The inferred type"
642 paras [ line "The inferred type"
643− , indent $ line $ markCode $ prettyPrintType t
643+ , markCodeBox $ indent $ typeAsBox t
644 , line "has type variables which are not mentioned in the body of the type. Consider adding a type annotation."
644 , line "has type variables which are not mentioned in the body of the type. Consider adding a type annotation."
645 ]
645 ]
646 renderSimpleErrorMessage (PossiblyInfiniteInstance nm ts) =
646 renderSimpleErrorMessage (PossiblyInfiniteInstance nm ts) =
src/Language/PureScript/Parser/Declarations.hs+2−2
@@ -392,7 +392,7 @@ parseLet = do
392 return $ Let ds result
392 return $ Let ds result
393
393
394parseValueAtom :: TokenParser Expr
394parseValueAtom :: TokenParser Expr
395−parseValueAtom = P.choice
395+parseValueAtom = withSourceSpan PositionedValue $ P.choice
396 [ parseAnonymousArgument
396 [ parseAnonymousArgument
397 , Literal <$> parseNumericLiteral
397 , Literal <$> parseNumericLiteral
398 , Literal <$> parseCharLiteral
398 , Literal <$> parseCharLiteral
@@ -418,7 +418,7 @@ parseValueAtom = P.choice
418parseInfixExpr :: TokenParser Expr
418parseInfixExpr :: TokenParser Expr
419parseInfixExpr
419parseInfixExpr
420 = P.between tick tick parseValue
420 = P.between tick tick parseValue
421− <|> Op <$> parseQualified parseOperator
421+ <|> withSourceSpan PositionedValue (Op <$> parseQualified parseOperator)
422
422
423parseHole :: TokenParser Expr
423parseHole :: TokenParser Expr
424parseHole = Hole <$> holeLit
424parseHole = Hole <$> holeLit
src/Language/PureScript/Sugar/Operators/Expr.hs+3−1
@@ -20,7 +20,9 @@ matchExprOperators = matchOperators isBinOp extractOp fromOp reapply modOpTable
20 isBinOp _ = False
20 isBinOp _ = False
21
21
22 extractOp :: Expr -> Maybe (Expr, Expr, Expr)
22 extractOp :: Expr -> Maybe (Expr, Expr, Expr)
23− extractOp (BinaryNoParens op l r) = Just (op, l, r)
23+ extractOp (BinaryNoParens op l r)
24+ | PositionedValue _ _ op' <- op = Just (op', l, r)
25+ | otherwise = Just (op, l, r)
24 extractOp _ = Nothing
26 extractOp _ = Nothing
25
27
26 fromOp :: Expr -> Maybe (Qualified (OpName 'ValueOpName))
28 fromOp :: Expr -> Maybe (Qualified (OpName 'ValueOpName))