Questions tagged [warren-abstract-machine]

The Warren Abstract Machine (WAM) is an abstract machine for the execution of Prolog consisting of a memory architecture and an instruction set designed in 1983 by David H. D. Warren.

In 1983, David H. D. Warren designed an abstract machine for the execution of Prolog consisting of a memory architecture and an instruction set known as the Warren Abstract Machine (WAM).

Purpose

The purpose of compiling Prolog code to the more low-level WAM code is to make subsequent interpretation of the Prolog program more efficient. Prolog code is reasonably easy to translate to WAM instructions which can be more efficiently interpreted. Also, subsequent code improvements and compilation to native code are often easier to perform on the more low-level representation.

Memory areas

The WAM has the following memory areas:

  • The global stack or heap, used to store compound terms;
  • The local stack for environment frames and choice-points;
  • The trail to record which variables bindings ought to be undone on backtracking.

Relevance for Prolog users

In order to write efficient Prolog programs, a basic understanding of how the WAM works can be advantageous. Some of the most important WAM concepts are first argument indexing and its relation to choice-points, tail call optimization and memory reclamation on failure.

Source:http://en.wikipedia.org/wiki/Warren_Abstract_Machine

16 questions
32
votes
3 answers

Alternatives to the WAM

I remember once reading that there were at least two other alternatives invented roughly at the same time as the WAM. Any pointers?
adamo
  • 3,584
  • 1
  • 18
  • 23
10
votes
1 answer

How can I inspect WAM code in SICStus Prolog

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…
repeat
  • 18,496
  • 4
  • 54
  • 166
9
votes
1 answer

Show WAM code for a given Prolog program

Given a Prolog program, is there any GNU Prolog command to view the WAM code relative to that program?
MadHatter
  • 638
  • 9
  • 23
8
votes
1 answer

Comparision of abstract machines for execution of Prolog

I'm looking for research paper or any other publication that compare different abstract machines (more than one) for execution of Prolog with prolog interpreters not based on abstact machines. What I've seen so far is that majority of…
7
votes
3 answers

Does Prolog need GC when the occurs check is globally enabled?

As far as I can tell, with sound unification, SLD resolution should not create cyclic data structures (Is this correct?) If so, one could, in theory, implement Prolog in such a way that it wouldn't need garbage collection (GC). But then again, one…
5
votes
1 answer

In a Warren's Abstract Machine, how does bind work, if one of the arguments is a register?

I'm trying to create my own WAM implementation and I'm stuck at the exercise 2.4 I can't understand how to execute instruction unify_value X4 in figure 2.4. As far as I understand, this instruction should unify Y from the program with f(W) from the…
Orfest
  • 135
  • 6
3
votes
1 answer

Flattened form in WAM

The WAM: A Tutorial Reconstruction states that a query, p(Z, h(Z,W), f(W)), needs to be flattened using the following principles: That being said, the query flattened form is: X3=h(X2, X5), X4=f(X5), X1=p(X2, X3, X4); I am lost with the definition…
Skalwalker
  • 299
  • 3
  • 23
3
votes
1 answer

WAM book: How is code generated when dealing with argument registers (L1)?

I am working through Hassan Ait-Kaci's book Warren's Abstract Machine - A Tutorial Reconstruction. Currently I am stuck on section 2.4, "Argument Registers". To be precise, what I don't understand is how to get from these register assignments (p.22)…
Hans Nowak
  • 7,600
  • 1
  • 18
  • 18
3
votes
1 answer

Which is the correct order to generate WAM code for L0 program terms?

In Hassan Aït-Kaci's "Warren's Abstract Machine: A Tutorial Reconstruction" Section 2.2, the orders for compilation of L0 queries are clear enough: registers must be allocated with left-to-right breadth-first search and code must be generated with…
matheuscscp
  • 827
  • 7
  • 23
3
votes
2 answers

When Warren's Abstract Machine program instructions are executed?

I'm reading Hassan Aït-Kaci's "Warren's Abstract Machine: A Tutorial Reconstruction". In Chapter 2, the compilation of L0 programs is presented after the compilation of L0 queries. The program compilation section (2.3) starts with: Compiling a…
matheuscscp
  • 827
  • 7
  • 23
3
votes
1 answer

Unification algorithm example in WAM (Warren's Abstract Machine)

Exercise 2.2 in Warren's Abstract Machine: A Tutorial Reconstruction asks for representations for the terms f(X, g(X, a)) and f(b, Y) and then to perform unification on the address of these terms (denoted a1 and a2 respectively). I've constructed…
3
votes
1 answer

In a Warren's Abstract Machine, where are Argument Variables created?

I'm trying to create my own WAM implementation and I'm using the instructions in Figure 2.10 of "Warren's Abstract Machine: A Tutorial Reconstruction" as a test case. However, I need to pass A1 and A2 to get_structure. But where are both variables…
Steven Devijver
  • 2,553
  • 1
  • 22
  • 22
2
votes
0 answers

How code generation works for Ait-Kaci's WAM L1?

Hassan Aït-Kaci's "Warren's Abstract Machine: A Tutorial Reconstruction" Section 2.4 extends L0 to L1 in order to support a set of facts in the abstract machine. The four new instructions put_variable, put_value, get_variable and get_value have…
matheuscscp
  • 827
  • 7
  • 23
1
vote
1 answer

GNU Prolog: Displaying WAM code for query?

Is it possible to display the WAM code for a query using GNU Prolog? I know I can use pl2wam to generate the WAM for the program, but what about the queries I perform on the program? Is there a way to show the WAM code for this? I'm using version…
0
votes
0 answers

WAM register allocation for same structures

Warren’s Abstract Machine A Tutorial Reconstruction states the following for Variable Register Allocation rules: Variable registers are allocated according to least available index. Register X1 is always allocated to the outermost term. A same…
Skalwalker
  • 299
  • 3
  • 23
1
2