git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge remote-tracking branch 'pure11/pure11' into native
commitaded0247dc79545ba8bf8da1bf20ce45a8267064 authorAndy Arvanitis <andyarvanitis@gmail.com> dateSun 20 Nov 2016, 16:24 (10 years ago) parentba82c5436b2d9c
9 files changed+134−25
pcc/Main.hs+9 pcc/Makefile+17−5 pcc/Makefile.hs+33−16 pcc/psc-xcode.sh+42 pcc/runtime/purescript.hh+4 psc-package/Main.hs+23 src/Language/PureScript/Errors.hs+1−1 src/Language/PureScript/Parser/Declarations.hs+2−2 src/Language/PureScript/Sugar/Operators/Expr.hs+3−1
pcc/Main.hs+9
@@ -54,6 +54,7 @@ data PCCMakeOptions = PCCMakeOptions
5454 , pccmOpts :: P.Options
5555 , pccmUsePrefix :: Bool
5656 , pccmJSONErrors :: Bool
57+ , pccmXcode :: Bool
5758 }
5859
5960-- | Argumnets: verbose, use JSON, warnings, errors
@@ -77,6 +78,8 @@ printWarningsAndErrors verbose True warnings errors = do
7778compile :: PCCMakeOptions -> IO ()
7879compile PCCMakeOptions{..} = do
7980 input <- globWarningOnMisses (unless pccmJSONErrors . warnFileTypeNotFound) pccmInput
81+ when pccmXcode $ do
82+ generateXcodefile
8083 when (null input && not pccmJSONErrors) $ do
8184 generatePackagefile
8285 generateMakefile
@@ -165,6 +168,11 @@ dumpCoreFn = switch $
165168 long "dump-corefn"
166169 <> help "Dump the (functional) core representation of the compiled code at output/*/corefn.json"
167170
171+xcode :: Parser Bool
172+xcode = switch $
173+ long "xcode"
174+ <> help "Generate support files for Xcode"
175+
168176options :: Parser P.Options
169177options = P.Options <$> noTco
170178 <*> noMagicDo
@@ -181,6 +189,7 @@ pccMakeOptions = PCCMakeOptions <$> many inputFile
181189 <*> options
182190 <*> (not <$> noPrefix)
183191 <*> jsonErrors
192+ <*> xcode
184193
185194main :: IO ()
186195main = do
pcc/Makefile+17−5
@@ -14,7 +14,9 @@
1414#
1515# You can also edit the generated version of this file directly.
1616#
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)
1820PURESCRIPT_PKGS := .psc-package
1921PURESCRIPT_SRC := src
2022OUTPUT := output
@@ -25,6 +27,10 @@ override PCCFLAGS += --comments
2527override CXXFLAGS += -std=c++11
2628override LDFLAGS +=
2729
30+ifeq ("$(wildcard $(PSC_PACKAGE))","")
31+ PSC_PACKAGE := $(PSC_PKG_BIN)
32+endif
33+
2834ifeq ($(GC),yes)
2935 override CXXFLAGS += -DUSE_GC
3036 override LDFLAGS += -lgc
@@ -42,15 +48,21 @@ release: codegen
4248debug: codegen
4349 @$(MAKE) $(BIN) CXXFLAGS+=$(DEBUG)
4450
51+release-object: codegen
52+ @$(MAKE) $(OBJ) CXXFLAGS+=$(RELEASE)
53+
54+debug-object: codegen
55+ @$(MAKE) $(OBJ) CXXFLAGS+=$(DEBUG)
56+
4557codegen: PURESCRIPT_PKG_SRCS=$(shell find $(PURESCRIPT_PKGS) -name '*.purs' | grep -v \/test\/ | grep -v \/example\/ | grep -v \/examples\/)
4658codegen: PURESCRIPT_SRCS=$(shell find $(PURESCRIPT_SRC) -name '*.purs')
4759#
48−codegen: .psc-package
60+codegen: $(PURESCRIPT_PKGS)
4961 @$(PCC) $(PCCFLAGS) --output $(OUTPUT) $(PURESCRIPT_PKG_SRCS) $(PURESCRIPT_SRCS)
5062
51−.psc-package:
52− @echo "Getting packages using 'psc-package'..."
53− @-psc-package update
63+$(PURESCRIPT_PKGS):
64+ @echo "Getting packages using" $(PSC_PACKAGE) "..."
65+ @$(PSC_PACKAGE) update
5466
5567SRCS := $(shell find $(OUTPUT) 2>/dev/null -name '*.cc')
5668
pcc/Makefile.hs+33−16
@@ -19,18 +19,24 @@ import Control.Monad (when)
1919import Data.FileEmbed (embedFile)
2020import System.Environment (getExecutablePath)
2121import System.Directory (doesFileExist)
22+import System.FilePath (takeDirectory)
2223
24+import qualified Data.Text as T
2325import qualified Data.ByteString.Char8 as B
2426
2527generateMakefile :: IO ()
2628generateMakefile = do
27− makefileExists <- doesFileExist "Makefile"
29+ makefileExists <- doesFileExist makefilename
2830 when (not makefileExists) $ do
2931 let makefile = $(embedFile "pcc/Makefile")
3032 exePath <- getExecutablePath
3133 putStrLn ""
32− putStrLn $ "Generating Makefile... " ++ "pcc executable location " ++ exePath
33− writeFile "Makefile" $ replace makefile pccPath exePath
34+ putStrLn $ "Generating " ++ makefilename ++ "... " ++ "pcc executable location " ++ exePath
35+ writeFile makefilename . T.unpack $
36+ T.replace
37+ pathPlaceholder
38+ (T.pack $ takeDirectory exePath)
39+ (T.pack $ B.unpack makefile)
3440 putStrLn "Done"
3541 putStrLn ""
3642 putStrLn "Run 'make' or 'make release' to build an optimized release build."
@@ -42,23 +48,34 @@ generateMakefile = do
4248
4349generatePackagefile :: IO ()
4450generatePackagefile = do
45− pkgfileExists <- doesFileExist "psc-package.json"
51+ pkgfileExists <- doesFileExist packagefilename
4652 when (not pkgfileExists) $ do
4753 let pkgfile = $(embedFile "pcc/psc-package.json")
4854 putStrLn ""
49− putStrLn "Generating psc-package.json..."
50− writeFile "psc-package.json" $ B.unpack pkgfile
55+ putStrLn $ "Generating " ++ packagefilename ++ "..."
56+ writeFile packagefilename $ B.unpack pkgfile
5157 putStrLn "Done"
5258 putStrLn "Use the 'psc-package' utility to install or update packages."
5359
54−replace :: B.ByteString -> B.ByteString -> String -> String
55−replace s orig repl = replace'
56− where
57− replace'
58− | (p1, p2) <- B.breakSubstring orig s,
59− not (B.null p2) = B.unpack p1 ++ repl ++ trim (B.unpack p2)
60− | otherwise = B.unpack s
61− trim = drop (B.length orig)
60+generateXcodefile :: IO ()
61+generateXcodefile = do
62+ xcodefileExists <- doesFileExist xcodefilename
63+ when (not xcodefileExists) $ do
64+ let xcodefile = $(embedFile "pcc/psc-xcode.sh")
65+ putStrLn ""
66+ putStrLn $ "Generating " ++ xcodefilename ++ "..."
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"
6279
63−pccPath :: B.ByteString
64−pccPath = "{bin/pcc}"
80+pathPlaceholder :: T.Text
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 @@
1515#ifndef PureScript_HH
1616#define PureScript_HH
1717
18+#if !defined(__cplusplus)
19+#error This is a C++ file!
20+#endif
21+
1822// Standard includes
1923
2024#if defined(DEBUG)
psc-package/Main.hs+23
@@ -181,6 +181,14 @@ install pkgName = do
181181 writePackageFile pkg'
182182 echo "psc-package.json file was updated"
183183
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+
184192listDependencies :: IO ()
185193listDependencies = do
186194 pkg@PackageConfig{ depends } <- readPackageFile
@@ -188,6 +196,15 @@ listDependencies = do
188196 trans <- getTransitiveDeps db depends
189197 traverse_ (echo . fst) trans
190198
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+
191208getSourcePaths :: PackageConfig -> PackageSet -> [Text] -> IO [Turtle.FilePath]
192209getSourcePaths PackageConfig{..} db pkgNames = do
193210 trans <- getTransitiveDeps db pkgNames
@@ -240,6 +257,9 @@ main = do
240257 , Opts.command "update"
241258 (Opts.info (pure update)
242259 (Opts.progDesc "Update dependencies"))
260+ , Opts.command "uninstall"
261+ (Opts.info (uninstall <$> pkg)
262+ (Opts.progDesc "Uninstall the named package"))
243263 , Opts.command "install"
244264 (Opts.info (install <$> pkg)
245265 (Opts.progDesc "Install the named package"))
@@ -252,6 +272,9 @@ main = do
252272 , Opts.command "sources"
253273 (Opts.info (pure listSourcePaths)
254274 (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"))
255278 ]
256279 where
257280 pkg = Opts.strArgument $
src/Language/PureScript/Errors.hs+1−1
@@ -640,7 +640,7 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
640640 go _ = False
641641 renderSimpleErrorMessage (AmbiguousTypeVariables t _) =
642642 paras [ line "The inferred type"
643− , indent $ line $ markCode $ prettyPrintType t
643+ , markCodeBox $ indent $ typeAsBox t
644644 , line "has type variables which are not mentioned in the body of the type. Consider adding a type annotation."
645645 ]
646646 renderSimpleErrorMessage (PossiblyInfiniteInstance nm ts) =
src/Language/PureScript/Parser/Declarations.hs+2−2
@@ -392,7 +392,7 @@ parseLet = do
392392 return $ Let ds result
393393
394394parseValueAtom :: TokenParser Expr
395−parseValueAtom = P.choice
395+parseValueAtom = withSourceSpan PositionedValue $ P.choice
396396 [ parseAnonymousArgument
397397 , Literal <$> parseNumericLiteral
398398 , Literal <$> parseCharLiteral
@@ -418,7 +418,7 @@ parseValueAtom = P.choice
418418parseInfixExpr :: TokenParser Expr
419419parseInfixExpr
420420 = P.between tick tick parseValue
421− <|> Op <$> parseQualified parseOperator
421+ <|> withSourceSpan PositionedValue (Op <$> parseQualified parseOperator)
422422
423423parseHole :: TokenParser Expr
424424parseHole = Hole <$> holeLit
src/Language/PureScript/Sugar/Operators/Expr.hs+3−1
@@ -20,7 +20,9 @@ matchExprOperators = matchOperators isBinOp extractOp fromOp reapply modOpTable
2020 isBinOp _ = False
2121
2222 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)
2426 extractOp _ = Nothing
2527
2628 fromOp :: Expr -> Maybe (Qualified (OpName 'ValueOpName))