Home

Awesome

A Simple PROLOG Compiler to WAM

GitHub license Build Status

WAM (Warren Abstract Machine) is an efficient popular abstract machine to compile Prolog logic programs and is implemented in almost all industrial-strength PROLOG compilers such as SWI-Prolog and YAP.

This interpreter contains the compilation and runtime of WAM instructions based on the definition in Russinoff 1992. The interpreter is developed in Haskell and the purpose of the project is to be used as testbed for various extensions in WAM.

Getting Started

Building

To build the WAM compiler you should have a system with GHC and cabal. The following sequence of commands will build the compiler after installing any dependencies needed.

$ cabal update
$ cabal install --only-dependencies
$ cabal configure && cabal build

Compile an example to WAM

After a successfull build the compiler will reside by default in ./dist/build/wam/wam. You can add the directory to your current path, i.e.

$ export PATH=`pwd`/dist/build/wam:$PATH

To compile a PROLOG program to WAM you should issue:

$ wam -c -i prog.pl -o output.wam

where prog.pl is your initial PROLOG source file, output.wam is the name of the output file that will contain WAM bytecode. The switch -c will only compile the program but not run. On the other hand if you omit -c, namely

$ wam -i prog.pl -o output.wam

the program will also be executed after the compilation.

Features and Limitations

Compilations supports some basic optimizations such as

Limitations

There are also some features of WAM that are not yet supported such as: