Skip to content
/ wam Public

A simple compiler from Prolog to WAM (Warren Abstract Machine) and a runtime for WAM.

License

Notifications You must be signed in to change notification settings

acharal/wam

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

  • tail execution optimization
  • unsafe variables

Limitations

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

  • There are no special instructions for lists (get_list, put_list).
  • No environment trimming.
  • No indexing at the switch-operators
  • No cut functionality
  • No garbage collection has been implemented.
  • A subset of the ISO-Prolog is supported and compiled. No build-in predicates are supported, neither user-defined operators.

About

A simple compiler from Prolog to WAM (Warren Abstract Machine) and a runtime for WAM.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages