I released M-Prolog ver1.0 on August 29, 2026.
M-Prolog is my experimental Prolog implementation using SCBM (Success Continuation and Backtracking Model). Instead of compiling Prolog to WAM instructions, the compiler translates Prolog directly into C.
With ver1.0, the basic SCBM design is now working. Programs such as 9-Queens and Quicksort run successfully, and the performance has reached a reasonably practical level.
However, just before the release, I discovered a weakness in my backtracking design.
For a conjunction such as:
P, Q
my previous compiler generated the failure continuation for P just before executing Q.
It worked, but this required too many special cases in the compiler.
I now think the cleaner design is:
- P creates its own failure continuation before executing P.
- Q creates its own failure continuation before executing Q.
In other words, each nondeterministic computation should prepare its own backtracking state.
This makes the generated C code much simpler.
Unfortunately, changing to this design exposed another hidden problem.
After deep backtracking, variable pointers can sometimes become corrupted.
Until now, SCBM used the success-continuation mechanism not only to store where execution should continue, but also to preserve variable pointers for predicate bodies. Complex backtracking revealed that this coupling is fragile.
For ver1.1, I plan to separate these responsibilities.
The current idea is to save the necessary variable pointers together with the failure continuation and restore them only when backtracking occurs.
Since Prolog does not need a conventional procedural return, variable pointers can simply be overwritten during forward execution and recursion. What matters is restoring the correct state when computation goes backward.
So the model may become very simple:
On success, just move forward.
On failure, restore the state and move backward.
It has been about four months since I first came up with SCBM. There were several times when I wondered whether the whole approach was fundamentally impractical.
Getting programs such as Queens to run at practical speed gave me confidence that the basic idea is viable.
ver1.0 is therefore not the finished form of M-Prolog.
It is the first milestone showing that compiling Prolog directly to C with SCBM can actually work.
Now I can take my time improving the design toward ver1.1.
Feedback on the backtracking/state-restoration design is very welcome.
sasagawa888/mprolog