Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to write assembly or C code generator in prolog ?

295 views
Skip to first unread message

Dmitry Ponyatov

unread,
May 4, 2016, 8:55:59 AM5/4/16
to
Any links ?

or maybe some tiny compiler sources

Markus Triska

unread,
May 5, 2016, 4:16:19 AM5/5/16
to
Hi Dmitry,

Dmitry Ponyatov <dpon...@gmail.com> writes:

> Any links ?
>
> or maybe some tiny compiler sources

I have put a simple compiler written in Prolog online at:

http://www.metalevel.at/tist/

The target language is a simple stack-based virtual machine. See the
factorial example and its compiled version for more information.

Prolog is very well suited for writing compilers and assemblers. One
very useful aspect of Prolog in this context is that you can reason
about *partially* instantiated data structures. For example, in the
compiler shown above, I am describing a list of target instructions, and
later fill in important details (space to be allocated, offsets of
subroutines) that are not yet known when the instruction is emitted.

This exact use case was also well recognized by the Mercury team (in
particular by Fergus Henderson), and was one huge motivation to at least
try to support partially instantiated data structures also in Mercury.

All the best,
Markus

--
comp.lang.prolog FAQ: http://www.logic.at/prolog/faq/

rupert...@googlemail.com

unread,
May 6, 2016, 11:09:12 AM5/6/16
to
On Wednesday, May 4, 2016 at 1:55:59 PM UTC+1, Dmitry Ponyatov wrote:
> Any links ?
>
> or maybe some tiny compiler sources

Why not piggy back on the LLVM back-end? Code generation examples in Prolog would still be helpful for figuring out how to generate the LLVM byte code though.

Dmitry Ponyatov

unread,
May 10, 2016, 5:01:41 AM5/10/16
to
> Why not piggy back on the LLVM back-end?

I'm primary interested in _high level_ translation, and Prolog constructs samples on this area.

Maybe use Prolog as translator from uninversal template language into lot of Makefile/C++/JavaScript/Java sources for bunch of modern hw/sw platoforms (win32/linux natives, browsers hell, android, iOS).

Jan Burse

unread,
May 10, 2016, 3:46:16 PM5/10/16
to
@Markus Triska,
You should write a book about Prolog, and not
simply freely distribute web content.

Only if people need to pay 50 bucks for a book,
they start recognizing its content.

Dmitry Ponyatov schrieb:
>> Why not piggy back on the LLVM back-end?
> I'm primary interested in_high level_ translation, and Prolog constructs samples on this area.

Jan Burse

unread,
May 10, 2016, 3:52:48 PM5/10/16
to
BTW: I still think Warrens 1983 Technical Note
a good source about the thinking that goes
into using Prolog as a compiler.

See PART I:
https://www.sri.com/sites/default/files/uploads/publications/pdf/656.pdf

Jan Burse schrieb:

Jan Burse

unread,
May 10, 2016, 3:55:35 PM5/10/16
to
I think this is still about DEC-10 Prolog
shortly before the WAM was invented.

Jan Burse schrieb:

Markus Triska

unread,
May 10, 2016, 5:37:48 PM5/10/16
to

> You should write a book about Prolog, and not
> simply freely distribute web content.
>
> Only if people need to pay 50 bucks for a book,
> they start recognizing its content.

I'm aware of that. I must improve library(simplex), CLP(Q), CLP(Z) and
many other aspects though before I can start with this. It will take me
at least a further decade to get all these libraries to a state where I
can start writing about them in earnest. To me, getting CLP(Z) into more
systems has always been a strong precondition for any serious book about
Prolog. And I mean not just "have them as a library", but provide them
out of the box! I have seen too many beginners nonsensically struggling
with low-level arithmetic even though better alternatives have been long
available in systems like SICStus Prolog and others. I'm delighted to
see that your system also continuously improves in this area. That's
just one example of many though: Other important aspects are making cTI
run with a freely available Prolog system, working with Ulrich Neumerkel
to make more parts of GUPU freely available, improving compatibility
between Prolog systems (example: attributed variables) etc. Until all
this is done, I hope my readers content themselves with zero charge.

All the best!
0 new messages