Re: Using Functional Programming in C/C++ Compilers

Dave MacQueen <dbm@research.bell-labs.com>
5 Apr 2000 22:41:24 -0400

          From comp.compilers

Related articles
Using Functional Programming in C/C++ Compilers vdbent@mail.com (Kees & Annette van der Bent) (2000-04-03)
Re: Using Functional Programming in C/C++ Compilers torbenm@diku.dk (2000-04-05)
Re: Using Functional Programming in C/C++ Compilers dbm@research.bell-labs.com (Dave MacQueen) (2000-04-05)
Re: Using Functional Programming in C/C++ Compilers joachim.durchholz@halstenbach.com.or.de (Joachim Durchholz) (2000-04-14)
| List of all articles for this month |

From: Dave MacQueen <dbm@research.bell-labs.com>
Newsgroups: comp.compilers
Date: 5 Apr 2000 22:41:24 -0400
Organization: Compilers Central
References: 00-04-036
Keywords: functional

Kees & Annette van der Bent <vdbent@mail.com> writes:


> Who is willing to share his/her opinions on using functional
> programming languages for developing C/C++ compilers/linkers/...?
>
> * What language(s) and why?


ML (Standard ML in particular) has a good track record in compiler
applications. Compiling is basically a symbolic process, and SML is
an excellent symbolic processing language. See the compiler projects
list at


    <http://cm.bell-labs.com/cm/cs/what/smlnj/links.html>


for examples.


> * What part(s) best done in FP?


Every aspect of compiling is suitable for implementation in ML.


> * Combining FP language and C/C++?


ML compilers generally have a C foreign function interface. SML/NJ
has a basic one now, and will have a better IDL-based one in the next
release.


> * Performance issues?


Functional language implementations will typically take more space,
but the time penalty can be modest to non-existent. [It's not easy to
demonstrate this, since I don't know of any algorithmicly equivalent
compilers written in ML and, say, C that can be usefully compared.]


> * Sofware engineering issues (maintenance, teaching C/C++ developers, ...)


SML has many features that make it attractive from a software
engineering point of view: safety, sound static typing, polymorphism,
algebraic types and pattern matching, a powerful module system with
parametric modules, exceptions, concurrency, garbage collection, etc.
SML/NJ has a very helpful compilation manager, CM, that helps minimize
development turn-around time.


SML programs do not, can not, dump core.


> * ...
> * References?


See the links to compiler projects given above. Also see Andrew
Appel's "Modern Compiler Implementation in ML" (and compare the code
samples available in ML, C and Java).


    <http://www.cs.princeton.edu/~appel/modern/ml/>


Also see these two very useful compiler related tools available with
the SML/NJ system.


1. ckit, an ansci C front end producing typed abstract syntax


    <http://cm.bell-labs.com/cm/cs/what/smlnj/doc/ckit/index.html>


ckit 1.0 was released 31 March 2000. It has been used as the front
end for various C static analysis tools in an industrial context where
millions of lines of code are being analyzed, and it has been used in
another industrial application as the front end for a C-derived domain
specific language.


2. MLRISC, a code generation framework


    <http://www.cs.nyu.edu/leunga/www/MLRISC/Doc/html/index.html>


MLRISC is used in the SML/NJ compiler and in several other compiler
projects. Back ends are currently provided for x86, sparc, alpha,
powerpc, hppa.


--
Dave MacQueen
macqueen@research.bell-labs.com
Room 2C-480, Bell Labs, 600 Mountain Ave, Murray Hill, NJ 07974


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.