HN Compiler
Switch branches/tags
Nothing to show
Clone or download
Permalink
Failed to load latest commit information.
AG Refactor: minor changes Jan 26, 2017
CPP Refactor: guards in BackendTools; attempt 4 Mar 21, 2017
FFI Internal: consistent UNIX LF line endings Mar 21, 2017
HN Refactor: Recursion Schemes for convert, revert in HN.MilnerTools Mar 25, 2017
Parser Internal: consistent UNIX LF line endings Mar 21, 2017
SPL Internal: consistent UNIX LF line endings Mar 21, 2017
Test Internal: consistent UNIX LF line endings Mar 21, 2017
Tools Internal: consistent UNIX LF line endings Mar 21, 2017
Unifier Internal: Whitespace fixes Mar 19, 2017
Utils Internal: move to lts-9.3 Sep 10, 2017
cpplib Fix: cpplib was unusable Oct 21, 2016
hn_tests Internal: more tests Nov 4, 2016
lib New: few foreign symbols in Lean Mar 13, 2016
spl_tests Moved everything to the top level. Oct 7, 2011
spllib Moved everything to the top level. Oct 7, 2011
.gitignore Internal: Ignore Idea and cabal sandbox files Mar 20, 2017
.travis.yml Fix: run actual HUnit tests in Travis Mar 20, 2017
Bar.ag Refactor: minor changes Jan 26, 2017
COPYING.LESSER Moved everything to the top level. Oct 7, 2011
HNC.hs Internal: consistent UNIX LF line endings Mar 21, 2017
M.hs Refactor: hlint fixes Oct 21, 2016
README.md Doc: stack builds and status updates Mar 8, 2017
SPL.cabal Fix: spl-test-hunit-exe requires at least ulimit -n 512 Mar 20, 2017
SPLI.hs Internal: consistent UNIX LF line endings Mar 21, 2017
SPL_Tests.hs Fix for #39 Dec 28, 2012
Setup.hs Internal: consistent UNIX LF line endings Mar 21, 2017
Utils.hs Internal: consistent UNIX LF line endings Mar 21, 2017
build.cmd Updated Readme.md Feb 10, 2013
configure.cmd Updated Readme.md Feb 10, 2013
example.spl Moved everything to the top level. Oct 7, 2011
noverbosity.sed Internal: second attempt on compatible sed shebang Apr 9, 2017
stack.yaml Internal: move to lts-9.3 Sep 10, 2017
uuagc_options Moved everything to the top level. Oct 7, 2011

README.md

Quick Start

Build Status Stories in Ready

Compilation

HNC is buildable by both cabal sandbox and stack, on Windows, Linux and MacOS, in 64 or 32 bits.

Stack

stack update
stack setup
stack install
$(stack path --local-bin)/spl-hnc -O hn_tests/euler6.hn

Cabal sandbox

cabal update
cabal sandbox init
cabal install
.cabal-sandbox/bin/spl-hnc -O hn_tests/euler6.hn

Arch Linux

On Arch you can shorten build time by using prebuilt libraries from ArchHaskell project.

Add 2 ArchHaskell binary repositories (haskell-core and haskell-web) to pacman.conf. Install the following prebuilt packages from there to avoid building them. GHC comes as a dependency.

sudo pacman -S cabal-install haskell-{adjunctions,haskell-src-exts,hunit,logict,parsec,quickcheck,safe}

Proceed to the general compilation steps for Cabal sandbox described above

Advanced use

  • run tests (spl-test-hunit-exe is the primary suite)
  • read wiki
  • talk to me at https://gitter.im/nponeccop/HNC
  • run our main test suite (dist/build/spl-test-hunit-exe/spl-test-hunit-exe)
  • run hnc with either -O or --dump-opt option to see our first attempts at optimization
  • follow instructions below to feed generated .cpp files to a C++ compiler and linker either directly or by using our extension to Boost.Build.

You'll need MSVC/GCC, Boost and Boost.Build.

Under the hood

HNC is an open-source cross-platform compiler based on modern technologies: Glasgow Haskell Platform, UUAGC attribute grammar preprocessor, Parsec parsing library, HOOPL graph optimization library, unification-fd structural unification library. The codebase is tiny: less than 4 KLOC, in the spirit of VPRI Ometa.

State of affairs

Many HN programs can already be compiled into an ugly functional subset of C++ and then into executables and run (see hn_tests folder for .hn sources and .cpp targets). A UDP echo server and a few Project Euler problems are the only useful programs so far, but mostly because we are too lazy to write more examples.

What is done

  • Parser
  • Type inference using UUAG, including injection of explicit template parameters when C++ doesn't infer them
  • Identifier- and scope-preserving translation from AST into graph IR and back using HOOPL dominator analysis
  • An optimizer of the IR using HOOPL (almost; only inlining and dead code elimination)
  • Compiler of closures into C++ functors using UUAG (almost)
  • C++ pretty printer (almost)
  • A Boost.Build plugin to integrate .hn files into C++ projects

Advances as of Mar 8 2017

  • Split Parser and Unifier into separate self-contained components
  • Joined efforts with https://groupoid.space and https://github.com/ptol/oczor projects
  • Working on extracting other components to make HNC a sort of toy compiler construction framework
  • Working on loop generation

Advances as of Jul 21 2015

  • Fixed almost all optimizer bugs

What is not done

  • Proper error reporting
  • Assignments
  • The instantiator of polymorphic code into monomorphic is not implemented
  • Module system, namespace support, HNI implementation and C++ integration in general are rudimentary or missing
  • Priorities of C++ infix operators are broken
  • RAII should be used with care
  • SPL support is almost missing
  • Polymorphic constants like “empty list” are not supported

Setting up MSVC and Boost

  • Install free Visual C++ Express or non-free Visual Studio
  • Download Boost library from boost.org.
  • Extract boost subfolder from the distribution. It's the folder containing header files for all libraries.

Create config.cmd one level above HNC folder, so it's not under source control:

@set INCLUDE=folder-containing-boost-subfolder
@call "%VS100COMNTOOLS%..\..\VC\vcvarsall.bat"

VS100COMNTOOLS is environment variable name set by VC 10.0 installer. Use set | findstr COMN to find out which version(s) of Visual C you have installed and change the .cmd file accordingly.

run testAll.cmd from hn_tests folder. You should see tmp-*.cpp files being generated from .hn sources and compiled into .obj files.

Setting up GCC

The generated code is not specific to MSVC or Windows, so any other Boost-compatible C++ compiler and platform should work too. However, the scripts to run test suite are not there yet.

To run deref1.cpp test manually with GCC, run

gcc -I../cpplib/include test.cpp ../cpplib/lib.cpp -lstdc++ --std=c++0x

from hn_tests folder if Boost headers are installed globally to /usr/include, or

gcc -I../cpplib/include -Ifolder-containing-boost-subfolder test.cpp  ../cpplib/lib.cpp -lstdc++ --std=c++0x

if Boost headers are manually unpacked locally.

License

Distributed under GNU Lesser General Public Licence Version 3.