Skip to content
nponeccop edited this page Oct 16, 2011 · 10 revisions

Welcome to the HNC wiki!

What is HNC

HNC stands for HN compiler. HN is a tool to facilitate writing C programs. It is a macro language for C. It is not embedded in C but uses a new syntax and a new type system to express C programs. It can be used by humans to prototype programs or separate functions in C or as an intermediate language for C generators.

Why we develop HNC

We hope that an advanced type system of HN and an ability to create reusable polymorphic control abstractions will improve productivity of C developers. The language design allows generation of quality human-readable programs so in some scenarios developers will be able to pretend that they don't use HNC but write their C code directly.

If HN proves useful, we plan to write several tools on top of it:

  • a compiler for a concurrent language for massively parallel supercomputers, in the spirit of SISAL;
  • ports of HN to languages other than C, e.g. PHP and Javascript;
  • further improvements of the language, e.g. quasi-quotation, regions, pi-sigma type system.

An example

When it's is ready,

	fold f x0 l =
		x = x0
		p = l
		while *p != NULL
			x := f x *p
			p := p->next
		x		

	x = fold (\x y -> x + y + 1) 0 l

will get expanded into

	int x = 0;
	list_int *p = l;
	while (*p != NULL)
	{
		x += y + 1;
		p = p->next;
	}

A key point is that control abstractions such as the one provided by the fold macro above, though ubiqutous in code, cannot be abstracted away in C. Also note less punctuation, a full polymorphic type inference and genuine C memory model.

HN0, SPL, HNI and C++

HN0 is the first version of HN language, having the very minimal set of constructs: a primitive macros working as always inlined higher order functions, an assignment, effectful statements, imperative control structures (while and if).

SPL stands for "Stream Programming Language" and is another syntax for a functional subset of HN0, inspired by J language. SPL and HN0 will share the same optimizer and back-end.

HNI stands for "HN Interface" and describes external C functions and constants used in HN programs.

C++ is an evil language used at early stages of HNC development. Before the inliner and monomorphizer are ready, we use C++ classes, templates and libraries to express scopes, parametric polymorphism and lexical closures respectively. In the future, the output will be old good ISO C99. A few evil features (namely, a limited template polymorphism and RAII) will be optionally available to the poor people writing in C++9x instead of C99.

How to contribute

This is a guideline for contributors to start working on the project. Note that most issues in our tracker don't require a deep understanding of the Haskell type system extensions, HOOPL, UUAGC or Parsec.