Re: Compiling Prolog-like languages

"Thomas Lindgren" <thomasl@erix.ericsson.se>
15 Jul 2002 23:41:34 -0400

          From comp.compilers

Related articles
Compiling Prolog-like languages sarah@telergy.com (Sarah Thompson) (2002-07-02)
Re: Compiling Prolog-like languages bmd@cs.kuleuven.ac.be (Bart Demoen) (2002-07-04)
Re: Compiling Prolog-like languages torbenm@pc-032.diku.dk (Torben Ægidius Mogensen) (2002-07-04)
Re: Compiling Prolog-like languages neelk@alum.mit.edu (Neelakantan Krishnaswami) (2002-07-04)
Re: Compiling Prolog-like languages haberg@matematik.su.se (Hans Aberg) (2002-07-04)
Re: Compiling Prolog-like languages peter.ilberg@ni.com (Peter Ilberg) (2002-07-04)
Re: Compiling Prolog-like languages rwaltman@verizon.net (Roberto Waltman) (2002-07-04)
Re: Compiling Prolog-like languages thomasl@erix.ericsson.se (Thomas Lindgren) (2002-07-15)
Re: Compiling Prolog-like languages adamo@dblab.ece.ntua.gr (Yiorgos Adamopoulos) (2002-07-15)
Re: Compiling Prolog-like languages ptarau@yahoo.com (Paul Tarau) (2002-07-15)
Re: Compiling Prolog-like languages oz@blue.cs.yorku.ca (ozan s yigit) (2002-07-15)
Re: Compiling Prolog-like languages firefly@diku.dk (Peter Finderup Lund) (2002-07-21)
Re: Compiling Prolog-like languages kurt.magnus.alonso@mailbox.swipnet.se (Kurt M. Alonso) (2002-08-10)
Re: Compiling Prolog-like languages bmd@cs.kuleuven.ac.be (Bart Demoen) (2002-08-14)
[1 later articles]
| List of all articles for this month |

From: "Thomas Lindgren" <thomasl@erix.ericsson.se>
Newsgroups: comp.compilers
Date: 15 Jul 2002 23:41:34 -0400
Organization: Telia Internet
References: 02-07-004 02-07-021
Keywords: prolog
Posted-Date: 15 Jul 2002 23:41:34 EDT

"Neelakantan Krishnaswami" <neelk@alum.mit.edu> writes:


> Sarah Thompson <sarah@telergy.com> wrote:
> >
> > Before I weigh into this and start reinventing considerable quantities
> > of wheels, I thought it might make sense to ask some questions here.
> >
> > 1. Can someone point toward a good tutorial on implementing
> > Prolog-like programming languages?
>
> Hassan Ait-Kaci's _Warren's Abstract Machine: A Tutorial
> Reconstruction_ is probably the best there is.


It should be said that it's very hard to improve _substantially_ on
the WAM, once you go below the instruction set. Every little piece you
tinker with has repercussions. (A pareto-optimal design?)


The best-known tries are Aquarius Prolog by Peter Van Roy et al and
Andrew Taylor's Parma system. Lots of interesting little
implementation tips there. One big lesson is that you want to do static
analysis to strength-reduce primitive operations (esp. unifications).


I also should mention SICStus Prolog, which has an impressive yet
straightforward native compiler, and BIM Prolog, where Andre Marien
devised the so far best way of compiling unification known (to me, at
least :-). Both use the WAM.


You could also have a look at how the Mercury project compiles its
language, which is fairly close to Prolog. It provides inspiration if
you compile to C, but be aware that they can take shortcuts in doing
this that Prolog does not permit.


> > 2. Much of the literature mentions the Warren Abstract Machine. Is
> > this regarded as the best way to go, or are there
> > simpler/faster/better/newer alternatives worthy of consideration?
>
> Another possibility is to use a continuation-passing style framework.
> This mails tail merging easier to do, and there are a *lot* of papers
> on how to efficiently compile CPS code.


There is BinProlog by Paul Tarau, which is a simple and fairly
efficient way of compiling Prolog.


To beat my own drum a bit, I wrote a couple of papers on the topic of
CPS-compiling Prolog some years ago. The most convenient place to find
them is probably my thesis:


ftp://ftp.csd.uu.se/pub/papers/theses/0026.ps.gz


Also fizzily known as "Compilation Techniques for Prolog".


Todd Proebsting wrote a PLDI paper on compiling Icon (I think), which
at its basis came pretty close to "A Continuation-Passing Style for
Prolog", one of the papers above. It's a lot clearer in the
presentation than my paper, and I think it translated into C-like
code:


Todd A. Proebsting. Simple translation of goal-directed
evaluation. Proc. PLDI'97.


You should also consider memory management. There is quite a
bit of work on this, since Prolog's backtracking also can serve to
reclaim memory if you're careful.


Finally, I'm probably leaving out a lot of interesting work from
recent years. I departed the field after finishing my thesis, which
was in 1996.


Best,
Thomas
--
Thomas Lindgren
I'd rather write programs that write programs than write programs-[R. Sites]


Post a followup to this message

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