This is an experimental C++(11+)/native compiler backend for PureScript. It attempts to generate "sane", debuggable, and portable C++ code as an intermediate language, which is then compiled to a native executable binary. This enables easy interoperability with existing C/C++ frameworks and libraries on a number of platforms.
Please note that this project supersedes pure11 (they are no longer the same)
Performance
- No runtime system (beyond some support classes and the standard C++(11+) runtime library)
- For automatic memory management, uses native C++(11+) reference counting (
std::shared_ptr) - Uses PureScript's normal tail call optimization techniques for generated C++ code
Differences from PureScript:
- Foreign imports are C++(11+) (or C) instead of JavaScript (FFI examples)
- No C++-specific REPL
Other notes:
- PureScript arrays are implemented using
std::deque(random access O(1)) Stringtypes are implemented using either C-strings (for literals) orstd::stringNumberis C++double,Intis C++int,Charisstd::string(single UTF-8 entity),Booleanisbool
Future ideas:
- Nice facilities (modules) for concurrency/parallelism, using
std::thread,std::async, etc. under the hood (output is already generally thread-safe for immutable values, thanks tostd::shared_ptr) BigIntvia GNU GMP (or an alternative)
Requirements for building the compiler itself
- Haskell Stack (if you're running macOS 10.13+, you can use pre-built binaries from here)
Requirements for using it
-
A recent version (0.12+) of purescript.
-
A C++11-capable toolchain, e.g. recent versions of clang, gcc, Microsoft Visual Studio 2015
-
GNU Make is the default supported build tool, but you should be able to use your favorite C++ build system, tools, debuggers, etc.
Getting Started
This assumes you are running OS X or a Unix-like system (Linux, *BSD, etc.).
-
Make sure you have developer tools for your system installed. For OS X, you'll need a recent version of Xcode. For Linux, etc., you need gcc 4.9.2 or later, including g++ support. You can also use clang 3.5 or later, but it still requires gcc for its C++ standard libraries.
-
Create a working directory wherever you like, and a
srcsubdirectory under it, which will be where you will place your own PureScript source files. -
Under your working directory, also create an
ffisubdirectory, which will be where you will place C/C++ FFI source files. -
Copy this
Makefileinto your working directory. -
Use PureScript's standard
psc-packageutility to add and manage package dependencies. -
You should now be ready to build a PureScript program.
-
As stated above, place your source file(s) in the working directory's
srcsubdirectory and executemake. If your machine has multiple cores, you might want to usemake -jN, whereNis the number of cores. -
This will generate the C++ source tree for your program and then build an executable binary. The resulting executable will be in the
binsubdirectory under the output directory and calledmain(sooutput/bin/main, by default). Source files will be undersrc(output/src/by default).
