This is an experimental C++11 (or later) 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.
pure11 (they are no longer the same)Please note that this project supersedes
changes for more details.Please see
- Generated C++ code and resulting binary executables tested (to at least some extent) on:
- macOS High Sierra, Xcode 9.4.1's clang (full test suite)
- Windows 10 x64 and x86, Visual Studio 2017
- Linux Debian 9.5 amd64, default versions of clang and gcc/g++ (full test suite)
- Raspberry Pi 3 B+ Raspbian official build (ARM), default versions of clang and gcc/g++
- No runtime system beyond some support classes and the standard C++11 (or later) runtime library
- For automatic memory management, uses native C++11 reference counting (
- Uses PureScript's normal tail call optimization techniques for generated C++ code
Differences from PureScript:
- No C++-specific REPL
- PureScript arrays are implemented using
std::deque(random access O(1))
Stringtypes are implemented with C++11
u8literals (UTF-8) and
std::string(single UTF-8 entity),
- Nice facilities (modules) for concurrency/parallelism, using
std::async, etc. under the hood (output is already generally thread-safe for immutable values, thanks to
Requirements for building the compiler itself
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
GNU Make is the default supported build tool, but you should be able to use your favorite C++ build system, tools, debuggers, etc.
This assumes you are running macOS (OS X) or a Unix-like system (Linux, *BSD, etc.).
Make sure you have developer tools for your system installed. For macOS, you'll need a recent version of Xcode. For Linux, etc., you can use clang 3.5 or later, or gcc/g++ 4.9.2 or later.
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. You should at least add the contents of purescript-native-ffi into this directory, in addition to any of your own foreign implementations.
Generate the default GNU
Makefilein your working directory by running
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 execute
make. If your machine has multiple cores, you might want to use
make -jN, where
Nis 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 called
output/bin/main, by default). Source files will be under