This is a simplified Warren Abstract Machine (WAM) implementation for Prolog, that showcases the main instructions, compiling, register allocation and machine functions.
🇧🇷 🇵🇹 Veja a documentação em Português! 🇦🇴 🇲🇿
- About Prolog: a hurried primer if you don't know what it is about.
- Resolution strategy: how a query is actually solved in Prolog.
- Warren Abstract Machine: details about the implementation attempted here.
- Indexing: indexing implementation to fast-track some call patterns.
- Parsing: explaining basic structures for parsing
- Grammar: documentation for the sample application of grammar parsing.
- Stuff left out: what this implementation has simplified from the WAM, and references.
- model.py: Data objects representing terms, programs, and machine entities.
- compiler.py: Compiling of a list of rules into a list of instructions.
- interpreter.py: Interpreter that execute the instruction listing for a given query.
- grammar.py: Sample application of interpreter, with a grammar that can parse itself.
Try it out with
python -m grammar
and compare with the text in the file!
After creating a Machine()
object, you may set its debug_filename
attribute with the
name of a file where it writes the machine's internal state
as a JSON for each iteration.
You may visualize the execution by running an HTTP server within the debug/ folder, e.g.
with python -m http.server
, and loading the JSONL file.
As a sample, debugtest/interpreter.jsonl
contains the execution for interpreter.py
.
If you wish to dump execution for some grammar tests, run pytest --debug_grammar
.
Warning: debug dumping is slooow.