In the context of hacking clpz on sicstus-prolog I want to glimpse at the warren-abstract-machine code generated by SICStus Prolog. As an example, let's dissect the following predicate!
is_list([]).
is_list([_|Es]) :- is_list(Es).
Here's what I'm doing now:
Split the 2 clauses of
is_list/1
into 2 separate predicates and prepend 2 dummy clauses:is_list__clause1(dummy1). % dummy clause is_list__clause1([]). is_list__clause2(dummy2). % dummy clause is_list__clause2([_|Es]) :- is_list(Es).
(Ab-)use the SICStus prolog-toplevel like so:
| ?- is_list__clause1(X). X = dummy1 ? t … 0x7eff37281300: GET_NIL_X0 0x7eff37281304: PROCEED 0x7eff37281308: END_OF_CLAUSEQ user:is_list__clause1/1 … | ?- is_list__clause2(X). X = dummy2 ? t … 0x7eff37281150: GET_LIST_X0 0x7eff37281154: U2_VOID_XVAR 1,x(0) 0x7eff37281160: EXECUTEQ user:is_list/1 0x7eff37281170: END_OF_CLAUSEQ user:is_list__clause2/1 …
This output—albeit somewhat cryptic—is giving me a feel of what's going on at the WAM level. I like!
But there has got to a simpler way... please help!
The system consists of a WAM emulator written in C, a library and runtime system written in C and Prolog and an interpreter and a compiler written in Prolog. The Prolog engine is a Warren Abstract Machine (WAM) emulator [Warren 83].
– Probabilism