git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge remote-tracking branch 'pure11/pure11' into native
ef7c06bAndy Arvanitis
CONTRIBUTORS.md+1
@@ -84,6 +84,7 @@ This file lists the contributors to the PureScript compiler project, and the ter
84- [@zudov](https://github.com/zudov) (Konstantin Zudov) My existing contributions and all future contributions until further notice are Copyright Konstantin Zudov, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
84- [@zudov](https://github.com/zudov) (Konstantin Zudov) My existing contributions and all future contributions until further notice are Copyright Konstantin Zudov, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
85- [@brandonhamilton](https://github.com/brandonhamilton) (Brandon Hamilton) My existing contributions and all future contributions until further notice are Copyright Brandon Hamilton, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
85- [@brandonhamilton](https://github.com/brandonhamilton) (Brandon Hamilton) My existing contributions and all future contributions until further notice are Copyright Brandon Hamilton, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
86- [@bbqbaron](https://github.com/bbqbaron) (Eric Loren) My existing contributions and all future contributions until further notice are Copyright Eric Loren, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
86- [@bbqbaron](https://github.com/bbqbaron) (Eric Loren) My existing contributions and all future contributions until further notice are Copyright Eric Loren, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
87+- [@RyanGlScott](https://github.com/RyanGlScott) (Ryan Scott) My existing contributions and all future contributions until further notice are Copyright Ryan Scott, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
87
88
88### Companies
89### Companies
89
90
bundle/README+1
@@ -19,6 +19,7 @@ This bundle contains the following executables:
19- psc-ide-server Provides Editor Support in the form of type information and
19- psc-ide-server Provides Editor Support in the form of type information and
20 autocompletion
20 autocompletion
21- psc-ide-client Utility to query psc-ide-server
21- psc-ide-client Utility to query psc-ide-server
22+- psc-package Package manager for PureScript packages
22
23
23Copy these files anywhere on your PATH.
24Copy these files anywhere on your PATH.
24
25
bundle/build.sh+1−1
@@ -26,7 +26,7 @@ fi
26mkdir -p bundle/build/purescript
26mkdir -p bundle/build/purescript
27
27
28# Strip the binaries, and copy them to the staging directory
28# Strip the binaries, and copy them to the staging directory
29−for BIN in psc psci psc-docs psc-publish psc-bundle psc-ide-server psc-ide-client
29+for BIN in psc psci psc-docs psc-publish psc-bundle psc-ide-server psc-ide-client psc-package
30do
30do
31 FULL_BIN="$LOCAL_INSTALL_ROOT/bin/${BIN}${BIN_EXT}"
31 FULL_BIN="$LOCAL_INSTALL_ROOT/bin/${BIN}${BIN_EXT}"
32 if [ "$OS" != "win64" ]
32 if [ "$OS" != "win64" ]
pcc/Main.hs+1
@@ -78,6 +78,7 @@ compile :: PCCMakeOptions -> IO ()
78compile PCCMakeOptions{..} = do
78compile PCCMakeOptions{..} = do
79 input <- globWarningOnMisses (unless pccmJSONErrors . warnFileTypeNotFound) pccmInput
79 input <- globWarningOnMisses (unless pccmJSONErrors . warnFileTypeNotFound) pccmInput
80 when (null input && not pccmJSONErrors) $ do
80 when (null input && not pccmJSONErrors) $ do
81+ generatePackagefile
81 generateMakefile
82 generateMakefile
82 exitSuccess
83 exitSuccess
83 moduleFiles <- readInput input
84 moduleFiles <- readInput input
pcc/Make.hs+14−5
@@ -74,12 +74,10 @@ buildMakeActions outputDir filePathMap usePrefix =
74 let path = fromMaybe (error "Module has no filename in 'make'") $ M.lookup mn filePathMap
74 let path = fromMaybe (error "Module has no filename in 'make'") $ M.lookup mn filePathMap
75 let filePath = either (const []) takeDirectory path
75 let filePath = either (const []) takeDirectory path
76 fileBase = filePath </> (last . words . dotsTo ' ' $ P.runModuleName mn)
76 fileBase = filePath </> (last . words . dotsTo ' ' $ P.runModuleName mn)
77− sourceFFI = addExtension fileBase sourceExt
77+ ffis = addExtension fileBase <$> [sourceExt, headerExt] ++ otherExts
78− headerFFI = addExtension fileBase headerExt
79 e1 <- traverse getTimestamp path
78 e1 <- traverse getTimestamp path
80− sffi <- getTimestamp sourceFFI
81− hffi <- getTimestamp headerFFI
79+ ffimax <- foldl1 max <$> mapM getTimestamp ffis
82− return $ fmap (max (max sffi hffi)) e1
80+ return $ max ffimax <$> e1
83
81
84 getOutputTimestamp :: P.ModuleName -> Make (Maybe UTCTime)
82 getOutputTimestamp :: P.ModuleName -> Make (Maybe UTCTime)
85 getOutputTimestamp mn = do
83 getOutputTimestamp mn = do
@@ -135,6 +133,8 @@ buildMakeActions outputDir filePathMap usePrefix =
135 sfileExists <- textFileExists sfile
133 sfileExists <- textFileExists sfile
136 when (sfileExists) $ do
134 when (sfileExists) $ do
137 copyTextFile (addExtension (fileBase ++ ffiMangle) sourceExt) sfile
135 copyTextFile (addExtension (fileBase ++ ffiMangle) sourceExt) sfile
136+ mapM (copyTextFileWithExt fileBase inputPath) otherExts
137+ return ()
138
138
139 requiresForeign :: CF.Module a -> Bool
139 requiresForeign :: CF.Module a -> Bool
140 requiresForeign = not . null . CF.moduleForeign
140 requiresForeign = not . null . CF.moduleForeign
@@ -160,6 +160,12 @@ buildMakeActions outputDir filePathMap usePrefix =
160 createDirectoryIfMissing True (takeDirectory to)
160 createDirectoryIfMissing True (takeDirectory to)
161 copyFile from to
161 copyFile from to
162
162
163+ copyTextFileWithExt :: FilePath -> FilePath -> String -> Make ()
164+ copyTextFileWithExt to from ext = makeIO (const (ErrorMessage [] $ CannotWriteFile to)) $ do
165+ createDirectoryIfMissing True (takeDirectory to)
166+ _ <- tryIOError $ copyFile (addExtension from ext) (addExtension to ext)
167+ return ()
168+
163 writeTextFile :: FilePath -> String -> Make ()
169 writeTextFile :: FilePath -> String -> Make ()
164 writeTextFile path text = makeIO (const (ErrorMessage [] $ CannotWriteFile path)) $ do
170 writeTextFile path text = makeIO (const (ErrorMessage [] $ CannotWriteFile path)) $ do
165 createDirectoryIfMissing True (takeDirectory path)
171 createDirectoryIfMissing True (takeDirectory path)
@@ -182,5 +188,8 @@ headerExt = "hh"
182sourceExt :: String
188sourceExt :: String
183sourceExt = "cc"
189sourceExt = "cc"
184
190
191+otherExts :: [String]
192+otherExts = ["h", "inl"]
193+
185ffiMangle :: String
194ffiMangle :: String
186ffiMangle = "_ffi"
195ffiMangle = "_ffi"
pcc/Makefile+15−5
@@ -15,10 +15,11 @@
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#
17PCC := {bin/pcc} # example: /usr/local/bin/pcc
17PCC := {bin/pcc} # example: /usr/local/bin/pcc
18−PURESCRIPT_PKGS := packages # example: bower_components
18+PURESCRIPT_PKGS := .psc-package
19PURESCRIPT_SRC := src
19PURESCRIPT_SRC := src
20OUTPUT := output
20OUTPUT := output
21BIN := main
21BIN := main
22+OBJ := purescript.o
22
23
23override PCCFLAGS += --comments
24override PCCFLAGS += --comments
24override CXXFLAGS += -std=c++11
25override CXXFLAGS += -std=c++11
@@ -32,9 +33,6 @@ endif
32DEBUG := "-DDEBUG -g"
33DEBUG := "-DDEBUG -g"
33RELEASE := "-O3 -flto"
34RELEASE := "-O3 -flto"
34
35
35−PURESCRIPT_PKG_SRCS := $(shell find $(PURESCRIPT_PKGS) -name '*.purs' | grep -v \/test\/ | grep -v \/example\/ | grep -v \/examples\/)
36−PURESCRIPT_SRCS := $(shell find $(PURESCRIPT_SRC) -name '*.purs')
37−
38INCLUDES := -I $(OUTPUT)
36INCLUDES := -I $(OUTPUT)
39BIN_DIR := $(OUTPUT)/bin
37BIN_DIR := $(OUTPUT)/bin
40
38
@@ -44,9 +42,16 @@ release: codegen
44debug: codegen
42debug: codegen
45 @$(MAKE) $(BIN) CXXFLAGS+=$(DEBUG)
43 @$(MAKE) $(BIN) CXXFLAGS+=$(DEBUG)
46
44
47−codegen:
45+codegen: PURESCRIPT_PKG_SRCS=$(shell find $(PURESCRIPT_PKGS) -name '*.purs' | grep -v \/test\/ | grep -v \/example\/ | grep -v \/examples\/)
46+codegen: PURESCRIPT_SRCS=$(shell find $(PURESCRIPT_SRC) -name '*.purs')
47+#
48+codegen: .psc-package
48 @$(PCC) $(PCCFLAGS) --output $(OUTPUT) $(PURESCRIPT_PKG_SRCS) $(PURESCRIPT_SRCS)
49 @$(PCC) $(PCCFLAGS) --output $(OUTPUT) $(PURESCRIPT_PKG_SRCS) $(PURESCRIPT_SRCS)
49
50
51+.psc-package:
52+ @echo "Getting packages using 'psc-package'..."
53+ @-psc-package update
54+
50SRCS := $(shell find $(OUTPUT) 2>/dev/null -name '*.cc')
55SRCS := $(shell find $(OUTPUT) 2>/dev/null -name '*.cc')
51
56
52OBJS = $(SRCS:.cc=.o)
57OBJS = $(SRCS:.cc=.o)
@@ -57,6 +62,11 @@ $(BIN): $(OBJS)
57 @mkdir -p $(BIN_DIR)
62 @mkdir -p $(BIN_DIR)
58 @$(CXX) $^ -o $(BIN_DIR)/$@ $(LDFLAGS)
63 @$(CXX) $^ -o $(BIN_DIR)/$@ $(LDFLAGS)
59
64
65+$(OBJ): $(OBJS)
66+ @echo "Creating combined object file" $(BIN_DIR)/$(OBJ)
67+ @mkdir -p $(BIN_DIR)
68+ @$(LD) -r $^ -o $(BIN_DIR)/$@ $(LDFLAGS)
69+
60-include $(DEPS)
70-include $(DEPS)
61
71
62%.o: %.cc
72%.o: %.cc
pcc/Makefile.hs+16−2
@@ -29,14 +29,28 @@ generateMakefile = do
29 let makefile = $(embedFile "pcc/Makefile")
29 let makefile = $(embedFile "pcc/Makefile")
30 exePath <- getExecutablePath
30 exePath <- getExecutablePath
31 putStrLn ""
31 putStrLn ""
32− putStrLn "Generating Makefile..."
32+ putStrLn $ "Generating Makefile... " ++ "pcc executable location " ++ exePath
33− putStrLn $ "pcc executable location: " ++ exePath
34 writeFile "Makefile" $ replace makefile pccPath exePath
33 writeFile "Makefile" $ replace makefile pccPath exePath
35 putStrLn "Done"
34 putStrLn "Done"
35+ putStrLn ""
36 putStrLn "Run 'make' or 'make release' to build an optimized release build."
36 putStrLn "Run 'make' or 'make release' to build an optimized release build."
37+ putStrLn "Run 'make debug' to build an executable with assertions enabled and"
38+ putStrLn "suitable for source-level debugging."
39+ putStrLn ""
37 putStrLn "The resulting binary executable will be located in output/bin (by default)."
40 putStrLn "The resulting binary executable will be located in output/bin (by default)."
38 putStrLn ""
41 putStrLn ""
39
42
43+generatePackagefile :: IO ()
44+generatePackagefile = do
45+ pkgfileExists <- doesFileExist "psc-package.json"
46+ when (not pkgfileExists) $ do
47+ let pkgfile = $(embedFile "pcc/psc-package.json")
48+ putStrLn ""
49+ putStrLn "Generating psc-package.json..."
50+ writeFile "psc-package.json" $ B.unpack pkgfile
51+ putStrLn "Done"
52+ putStrLn "Use the 'psc-package' utility to install or update packages."
53+
40replace :: B.ByteString -> B.ByteString -> String -> String
54replace :: B.ByteString -> B.ByteString -> String -> String
41replace s orig repl = replace'
55replace s orig repl = replace'
42 where
56 where
pcc/psc-package.jsonnew file+9
@@ -0,0 +1,9 @@
1+{
2+ "name": "Main",
3+ "set": "psc-0.10.2",
4+ "source": "https://github.com/pure11/package-sets.git",
5+ "depends": [
6+ "console",
7+ "prelude"
8+ ]
9+}
pcc/runtime/purescript.hh+4−3
@@ -19,7 +19,7 @@
19
19
20#if defined(DEBUG)
20#if defined(DEBUG)
21 #include <cassert>
21 #include <cassert>
22− #include <climits>
22+ #include <limits>
23 #define IF_DEBUG(x) x
23 #define IF_DEBUG(x) x
24#else
24#else
25 #define NDEBUG
25 #define NDEBUG
@@ -165,8 +165,9 @@ class any {
165 public:
165 public:
166
166
167 any(const int val) noexcept : tag(tag_t::Integer), i(val) {}
167 any(const int val) noexcept : tag(tag_t::Integer), i(val) {}
168− any(const long int_value) noexcept : tag(tag_t::Integer), i(int_value) {
168+ any(const long val) noexcept : tag(tag_t::Integer), i(static_cast<decltype(i)>(val)) {
169− assert(int_value >= INT_MIN && int_value <= INT_MAX);
169+ assert(val >= std::numeric_limits<decltype(i)>::min() &&
170+ val <= std::numeric_limits<decltype(i)>::max());
170 }
171 }
171
172
172 any(const double val) noexcept : tag(tag_t::Double), d(val) {}
173 any(const double val) noexcept : tag(tag_t::Double), d(val) {}
psc-package/README.mdnew file+99
@@ -0,0 +1,99 @@
1+# `psc-package`
2+
3+`psc-package` is an executable which helps manage PureScript dependencies via Git. It can be used directly, but it is also designed to be used by external tools.
4+
5+## Concepts
6+
7+### Package Sets
8+
9+A _package set_ is a mapping from package names to:
10+
11+- the Git repository URL for the package
12+- the Git ref which should be passed to `git clone` to clone the appropriate version (usually a tag name, but a SHA is also valid)
13+- the package's transitive dependencies
14+
15+A package set repository contains a `packages.json` file which contains all mapping information. `psc-package` uses this information to decide which repos need to be cloned.
16+
17+The default package set is [purescript/package-sets](https://github.com/purescript/package-sets), but it is possible to create custom package sets by forking an existing package set or creating a new one from scratch. One benefit of using the default package set is that it is verified by a continuous integration process.
18+
19+## The `psc-package.json` format
20+
21+Here is a simple project configuration:
22+
23+```json
24+{
25+ "name": "my-project",
26+ "set": "psc-0.10.2",
27+ "source": "https://github.com/purescript/package-sets.git",
28+ "depends": [
29+ "prelude"
30+ ]
31+}
32+```
33+
34+It defines:
35+
36+- The project name
37+- The package set to use to resolve dependencies (this corresponds to a branch or tag of the package set source repository)
38+- The package set source repository Git URL (change this if you want to host your own package sets)
39+- Any dependencies of the project, as a list of names of packages from the package set
40+
41+## How To
42+
43+### Create a project
44+
45+A new package can be created using `psc-package init`. This will:
46+
47+- Create a simple `psc-package.json` file based on the current compiler version
48+- Add the Prelude as a dependency (this can be removed later)
49+- Sync the local package database (under the `.psc-package/` directory) by cloning any necessary repositories.
50+
51+### Add dependencies
52+
53+To add a dependency, either:
54+
55+- Use the `install` command, which will update the project configuration automatically, or
56+- Modify the `psc-package.json` file, and sync manually by running the `update` command.
57+
58+### Build a project
59+
60+Active project dependencies and project source files under `src` can be compiled using the `build` command.
61+
62+This command is provided as a convenience until external tools add support for `psc-package`. It _might_ be removed in future.
63+
64+### Query the local package database
65+
66+The local package database can be queried using the following commands:
67+
68+- `sources` - list source directories for active package versions. This can be useful when building a command for, say, running PSCi.
69+- `dependencies` - list all transitive dependencies
70+
71+### Add a package to the package set
72+
73+Adding your package to the package set means that others can easily install it as a dependency.
74+
75+Please note that your package will be removed from the set if it is not kept up to date. It can be easily re-added later if this happens.
76+
77+Adding a package is a manual process right now. We would like to add commands to make this process simpler, but for now, please follow these steps:
78+
79+- Tag a release of your library
80+- Run the `dependencies` command to get the list of transitive dependencies
81+- Make a pull request on the package set repository (against `master`) to add a new entry to `packages.json`. Use the dependency information above to fill in the fields, and the name of your new tag.
82+
83+Travis will verify your package builds correctly, and then we will try to merge your pull request. Your package will then be available in the next tagged package set.
84+
85+### Update a package in the set
86+
87+- Tag a new release
88+- Make a pull request on `master` to modify the tag named in the package set repository.
89+
90+Again, once Travis verifies your change, we will merge it into `master` and your change will be available in the next tag.
91+
92+## FAQ
93+
94+### Can I add a dependency which is not in the package set?
95+
96+Not right now. We might add this feature in future, but for now, consider either:
97+
98+- Adding your dependency to the package set if possible, or
99+- Creating your own custom package set
purescript.cabal+2−1
@@ -97,7 +97,8 @@ extra-source-files: examples/passing/*.purs
97 , INSTALL.md
97 , INSTALL.md
98 , CONTRIBUTORS.md
98 , CONTRIBUTORS.md
99 , CONTRIBUTING.md
99 , CONTRIBUTING.md
100− , pcc/include/*.hh
100+ , pcc/runtime/*.hh
101+ , pcc/runtime/*.cc
101
102
102source-repository head
103source-repository head
103 type: git
104 type: git
src/Control/Monad/Supply/Class.hs+3−2
@@ -3,6 +3,7 @@
3--
3--
4
4
5{-# LANGUAGE DefaultSignatures #-}
5{-# LANGUAGE DefaultSignatures #-}
6+{-# LANGUAGE TypeFamilies #-}
6
7
7module Control.Monad.Supply.Class where
8module Control.Monad.Supply.Class where
8
9
@@ -15,9 +16,9 @@ import Control.Monad.Writer
15class Monad m => MonadSupply m where
16class Monad m => MonadSupply m where
16 fresh :: m Integer
17 fresh :: m Integer
17 peek :: m Integer
18 peek :: m Integer
18− default fresh :: MonadTrans t => t m Integer
19+ default fresh :: (MonadTrans t, MonadSupply n, m ~ t n) => m Integer
19 fresh = lift fresh
20 fresh = lift fresh
20− default peek :: MonadTrans t => t m Integer
21+ default peek :: (MonadTrans t, MonadSupply n, m ~ t n) => m Integer
21 peek = lift peek
22 peek = lift peek
22
23
23instance Monad m => MonadSupply (SupplyT m) where
24instance Monad m => MonadSupply (SupplyT m) where