Warren’s Abstract Machine
A Tutorial Reconstruction Hassan A ıt-Kaci
ICLP’91 Pre-Conference Tutorial
[1]
Warrens Abstract Machine A Tutorial Reconstruction Hassan A t-Kaci - - PDF document
Warrens Abstract Machine A Tutorial Reconstruction Hassan A t-Kaci ICLP91 Pre-Conference Tutorial [1] I dedicate this modest work to a most outstanding W A M I am referring of course to Wolfgang Amadeus Mozart 1756
ICLP’91 Pre-Conference Tutorial
[1]
I dedicate this modest work to a most outstanding
I am referring – of course – to
Year's to you...
[2]
[3]
[4]
[5]
[6]
[7]
[8]
[9]
[11]
[12]
[13]
[14]
[15]
[16]
[17]
[18]
[19]
[20]
[21]
[22]
[23]
[24]
[25]
[26]
procedure unify(a1
push(a1
PDL); push(a2 PDL);fail
false;while ¬(empty(PDL) ∨ fail) do begin
d1 deref (pop(PDL)); d2 deref (pop(PDL));if
d1 ≠ d2 thenbegin
h t1if (t1 = REF) ∨ (t2 = REF) then bind(d1
else begin
f1 n1 STORE[ v1]; f2 n2 STORE[ v2];if (f1 =
f2) ∧ (n1 = n2)then for
i 1 to n1 dobegin push(v1 +
i PDL); push(v2 + i PDL)end else fail
trueend end end end unify;
[27]
[28]
[29]
[30]
[31]
[33]
[34]
[35]
[36]
[37]
[38]
[39]
[40]
[41]
[42]
[43]
[44]
[45]
[46]
[47]
[48]
[49]
[50]
[51]
[52]
[53]
[54]
[55]
[56]
[57]
[58]
[59]
[60]
[60]
[61]
[62]
[63]
[64]
[65]
[66]
[67]
[67]
[68]
[69]
[70]
[71]
[72]
[73]
[74]
[75]
[76]
[77]
[78]
[79]
[80]
[81]
[82]
[83]
[84]
[85]
[86]
[87]
[88]
[89]
%
pget variable Y1 A1 % (X
%
Y%
Z) :-put variable Y3 A1 %
q(Uput variable Y2 A2 %
V%
Wcall
q 3 6% ) put value Y5 A1 %
r(Y%
Z%
Ucall
r 3 4% ) put value Y3 A1 %
s(Uput value Y4 A2 %
Wcall
s2 2% ) put value Y1 A1 %
t(X%
Vdeallocate % ) execute
t2%
[90]
[91]
[92]
[93]
[94]
[95]
[96]
[97]
[98]
[99]
[100]
[101]
[102]
[103]
[104]
[105]
[106]
[107]
[108]
[109]
[110]
[111]
[112]
[113]
[114]
[115]
[116]
[117]
[118]
[119]
[120]
[121]
[122]
[123]
[124]
switch on term
S11% 1st level dispatch for
S1 C1: switch on constant 3
f trace:
S1b:
S1e g% 2nd level for constants
F1: switch on structure 1
f or2 : F11 g% 2nd level for structures
F11 : try S1a% 3rd level for or2 trust
S1c%
S11 : try me else S12% call
S1a : get structure or2 A1% (or unify variable A1 % (X
%
Y ))execute call1 % :- call(X)
S12 : retry me else S13% call
S1b: get constant trace
A1% (trace) execute trace % :- trace
% call
S1c: get structure or2 A1 % (or unify void 1 % (X
%
Y ))execute call1 % :- call(Y )
S14 : retry me else S15% call
S1d : get constant notrace A1% (notrace) execute notrace % :- notrace
% call
S1e : get constant nl A1% (nl) execute nl0 % :- nl Indexing code for subsequence
S1[125]
switch on term
S41% 1st level dispatch for
S4 C4: switch on constant 3
f repeat : C41:
S4d g% 2nd level for constants
F4: switch on structure 1
f call1 : S41 g% 2nd level for structures
C41 : try S4b% 3rd level for ‘repeat’ trust
S4c%
S41: try me else
S42% call
S4a: get structure call1 A1 % (call unify variable A1 % (X)) execute call1 % :- call(X)
S42: retry me else
S43% call
S4b: get constant repeat A1 % (repeat) proceed %
: retry me else
S44% call
S4c: get constant repeat A1 % (repeat) put constant repeat A1 % :- call(repeat) execute call1 %
: trust me % call
S4d: get constant true A1 % (true) proceed %
[126]
conc
3 : switch on term C1a%
C1a: try me else
C2a% conc
C1: get constant [] A1 % ([] get value A2 A3 %
L L)proceed %
: trust me % conc
C2: get list A1 % ([ unify variable X4 %
H junify variable A1 %
T] Lget list A3 % [ unify value X4 %
H junify variable A3 %
R])execute conc
3% :- conc(T
Encoding of conc
3[127]
[128]
[129]
[130]
[131]
[131]
Argument Registers: A1 A2
. . . An . . .Registers: P CP S HB H BC B E TR (low)
Code Area Heap Stack
choice point environment
Trail PDL
(high) Yn
nth local variable. . . Y1 1st local variable CP cont. point CE cont. environment Environment frame: BC cut pointer H heap pointer TR trail pointer BP next clause B previous choice pt. CP cont. point CE cont. environment An
nth argument. . . A1 1st argument
narity Choice point frame:
[132]
The Complete WAM Instruction Set
Put instructions put variable Xn
Aiput variable Yn
Aiput value Vn Ai put unsafe value Yn Ai put structure
f Aiput list Ai put constant
c AiGet instructions get variable Vn
Aiget value Vn Ai get structure
f Aiget list Ai get constant
c AiSet instructions set variable Vn set value Vn set local value Vn set constant
cset void
nUnify instructions unify variable Vn unify value Vn unify local value Vn unify constant
cunify void
nControl instructions allocate deallocate call
Pexecute
Pproceed Choice instructions try me else
Lretry me else
Ltrust me try
Lretry
Ltrust
LIndexing instructions switch on term
Vswitch on constant
Nswitch on structure
NCut instructions neck cut get level Yn cut Yn
NOTE: In some instructions, we use the notation Vn to denote a variable that may be indifferently temporary or permanent.
[133]
[134]