MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_NextPart_01C62C03.13F95830" Bei diesem Dokument handelt es sich um eine Webseite in einer Datei, die auch als Webarchivdatei bezeichnet wird. Wenn Sie diese Nachricht erhalten, unterstützt Ihr Browser oder Editor keine Webarchivdateien. Downloaden Sie einen Browser, der Webarchivdateien unterstützt, wie zum Beispiel Microsoft Internet Explorer. ------=_NextPart_01C62C03.13F95830 Content-Location: file:///C:/B134688D/wam.htm Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="us-ascii" Seitentitel

% *************************************************= ***************

 

% Warren Abstract Machine Emulator

 

% Version 1.0

 

% Coded by: Raul Rojas GMD/FIRST<= /p>

 

% *************************************************= ***************

 

 

 

% *************************************************= ***************

 

% Infix Operator to separate Tags from Values<= /o:p>

 

% *************************************************= ***************

 

 

 

:- op(500,xfx,:).

 

 

 

:- dynamic choice_pointer/1.

 

:- dynamic environment/1.

 

 

 

 

 

% ************************** Argument Registers ***= ***************

 

% 10 argument registers are defined

 

% *************************************************= ***************

 

:- dynamic reg/2.

 

 

 

reg(1,0).

 

reg(2,0).

 

reg(3,0).

 

reg(4,0).

 

reg(5,0).

 

reg(6,0).

 

reg(7,0).

 

------=_NextPart_01C62C03.13F95830 Content-Location: file:///C:/B134688D/wam-Dateien/pubmaster001.htm Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="us-ascii" Seitentitel
------=_NextPart_01C62C03.13F95830 Content-Location: file:///C:/B134688D/wam-Dateien/page0001.htm Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="us-ascii" Seitentitel

reg(8,0).

 

reg(9,0).

 

reg(10,0).

 

 

 

% *********************** register refresh ********= ***************

 

% write_reg/2 overwrites  register N with the value X

 

% *************************************************= ***************

 

 

 

write_reg(N,X):-&n= bsp;   retract(reg(N,_)),

 

   =             &nb= sp;    asserta(reg(N,X)).

 

 

 

% **************************** PC handling ********= ***************

 

% pc/1  =        stores the program counter=

 

% read_pc(X) =   reads the value of the PC in X

 

% reset_pc(X) = ; overwrites the PC with X

 

% *************************************************= ***************

 

 

 

:- dynamic pc/1.

 

pc(0).

 

 

 

read_pc(X):- =   pc(X).

 

 

 

reset_pc(X):- = ; retract(pc(_)),

 

   =             a= sserta(pc(X)).

 

 

 

% *************************** Ret_addr ************= **************

 

% ret_addr/1 =        contains the return address for= procedures

 

% read_ret_addr(X)=   reads the value of ret_addr in X

 

------=_NextPart_01C62C03.13F95830 Content-Location: file:///C:/B134688D/wam-Dateien/page0002.htm Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="us-ascii" Seitentitel

% reset_ret_addr(Y) overwrites ret_addr with Y=

 

% *************************************************= **************

 

 

 

:- dynamic ret_addr/1.

 

 

 

ret_addr(0).

 

 

 

read_ret_addr(X):-=   ret_addr(X).

 

 

 

reset_ret_addr(Y):- retract(ret_addr(_)),

 

   =             &nb= sp;    asserta(ret_addr(Y)).

 

 

 

   =             &nb= sp;        

 

% *************************** bindings ************= ***************

 

% bind/2 binds two variables, whose addresses are g= iven as

 

% arguments. The pointers go from higher to lower a= ddresses

 

% *************************************************= ***************

 

 

 

bind(First,Second):-

 

   =             F= irst > Second,!,

 

   =             &nb= sp;    write_mem(First,ref:Second),=

 

   =             &nb= sp;    test_trail(First)

 

   =             ;=

 

   =             &nb= sp;    write_mem(Second,ref:First),=

 

   =             &nb= sp;    test_trail(Second).

 

 

 

% ************************  Put Instructions **********************

 

% put_nil

 

------=_NextPart_01C62C03.13F95830 Content-Location: file:///C:/B134688D/wam-Dateien/page0003.htm Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="us-ascii" Seitentitel

% put_constant

 

% put_value

 

% put_variable

 

% put_list

 

% put_structure

 

% put_unsafe_value

 

% *************************************************= ****************

 

 

 

put_nil(a(N)):- write_reg(N,const:[]).

 

 

 

put_constant(Const,a(N)):-

 

   =             w= rite_reg(N,const:Const).

 

 

 

put_value(a(M),a(N)):-!,

 

   =             r= eg(M,X),

 

   =             w= rite_reg(N,X).

 

 

 

put_value(e(M),a(N)):-!,

 

   =             r= ead_curr_env(Curr_Env),

 

   =             A= ddr is Curr_Env+M+1,

 

   =             r= ead_mem_deref(Addr,Tag:Value),

 

   =             w= rite_reg(N,Tag:Value).

 

 

 

put_variable(e(M),a(N)):-!,

 

   =             r= ead_curr_env(CurrEnv),

 

   =             A= ddr is CurrEnv+M+1,

 

   =             w= rite(Addr,ref:Addr),

 

   =             w= rite_reg(N,ref:Addr).

 

------=_NextPart_01C62C03.13F95830 Content-Location: file:///C:/B134688D/wam-Dateien/page0004.htm Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="us-ascii" Seitentitel

 

 

put_variable(a(M),a(N)):-!,

 

   =             p= ush_global_unb(Addr),

 

   =             w= rite_reg(M,ref:Addr),

 

   =             w= rite_reg(N,ref:Addr).

 

 

 

put_list(a(N)):-!,

 

   =             r= ead_gpos(Addr),

 

   =             w= rite_reg(N,list:Addr),

 

   =             s= et_semaphore(write).

 

 

 

put_structure(Functor/Arity,a(N)):-!,

 

   =             r= ead_gpos(Addr),

 

   =             w= rite_reg(N,struct:Addr),

 

   =             p= ush_global(const:Functor/Arity),

 

   =             s= et_semaphore(write).

 

 

 

put_unsafe_value(e(M),a(N)):-

 

   =             r= ead_curr_env(CurrEnv),

 

   =             A= ddr is CurrEnv+M+1,

 

   =             r= ead_mem_deref(Addr,Tag:Value),

 

   =             (= Tag=3Dref,

 

   =             &nb= sp;    Value > CurrEnv,!,

 

   =             &nb= sp;    push_global_unb(Addr),

 

   =             &nb= sp;    write_mem(Addr,ref:Addr),

 

   =             &nb= sp;    test_trail(Addr),

 

   =             &nb= sp;    write_reg(N,ref:Addr)

 

   =             ;=

 

------=_NextPart_01C62C03.13F95830 Content-Location: file:///C:/B134688D/wam-Dateien/page0005.htm Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="us-ascii" Seitentitel

   =             &nb= sp;    write_reg(N,Tag:Value)

 

   =             )= .

 

 

 

 

 

% ********************** dereferencing ************= ****************

 

% deref/2 dereferences and indirect pointer

 

% *************************************************= ****************

 

 

 

deref(ref:Addr,Tag:Value):-!, read_mem_deref(Addr,T= ag:Value).

 

deref(X,X).

 

 

 

% ************************* Get Instructions ******= ****************

 

% get_constant C,Ai

 

% get_nil Ai

 

% get_variable Vn,Ai

 

% get_list Ai

 

% get_structure F/N,Ai

 

% get_value Vn,Ai

 

% *************************************************= ****************

 

 

 

get_constant(Const,a(N)):-

 

   =             r= eg(N,Contents),

 

   =             d= eref(Contents,Tag:Value),

 

   =             (= Tag=3Dref,!,

 

   =             &nb= sp;    write_mem(Value,const:Const),

 

   =             &nb= sp;    test_trail(Value)

 

   =             ;=

 

   =             &nb= sp;    Tag:Value=3Dconst:Const

 

------=_NextPart_01C62C03.13F95830 Content-Location: file:///C:/B134688D/wam-Dateien/page0006.htm Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="us-ascii" Seitentitel

   =             )= .

 

 

 

get_nil(a(N)):-

 

   =             r= eg(N,Contents),

 

   =             d= eref(Contents,Tag:Value),

 

   =             (= Tag=3Dref,!,

 

   =             &nb= sp;    write_mem(Value,const:[]),

 

   =             &nb= sp;    test_trail(Value)

 

   =             ;=

 

   =             &nb= sp;    Tag:Value=3Dconst:[]

 

   =             )= .

 

   =             <= o:p>

 

get_variable(a(N),a(M)):-!,

 

   =             r= eg(M,Contents),

 

   =             w= rite_reg(N,Contents).

 

 

 

get_variable(e(N),a(M)):-!,

 

   =             r= eg(M,Contents),

 

   =             w= rite_env_var(N,Contents).

 

 

 

get_list(a(N)):-

 

   =             r= eg(N,Contents),

 

   =             d= eref(Contents,Tag:Addr),

 

   =             (= Tag=3Dlist,!,

 

   =             &nb= sp;    reset_next_arg(Addr),

 

   =             &nb= sp;    set_semaphore(read)

 

   =             ;=

 

   =             T= ag=3Dref,!,

 

------=_NextPart_01C62C03.13F95830 Content-Location: file:///C:/B134688D/wam-Dateien/page0007.htm Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="us-ascii" Seitentitel

   =             &nb= sp;    read_gpos(GPOS),

 

   =             &nb= sp;    write_mem(Addr,list:GPOS),

 

   =             &nb= sp;    test_trail(Addr),

 

   =             &nb= sp;    set_semaphore(write)

 

   =             )= .

 

 

 

get_structure(F/Arity,a(N)):-

 

   =             r= eg(N,Contents),

 

   =             d= eref(Contents,Tag:Addr),

 

   =             (= Tag=3Dstruct,!,

 

   =             &nb= sp;    reset_next_arg(Addr),

 

   =             &nb= sp;    read_next_arg_inc(const:Functor/Arity2),<= /o:p>

 

   =             &nb= sp;    F/Arity=3DFunctor/Arity2,

 

   =             &nb= sp;    set_semaphore(read)

 

   =             ;=

 

   =             T= ag=3Dref,!,

 

   =             &nb= sp;    read_gpos(GPOS),

 

   =             &nb= sp;    write_mem(Addr,struct:GPOS),=

 

   =             &nb= sp;    test_trail(Addr),

 

   =             &nb= sp;    push_global(const:F/Arity),<= /p>

 

   =             &nb= sp;    set_semaphore(write)

 

   =             )= .

 

   =             &nb= sp;        

 

get_value(a(N),a(M)):-!,

 

   =             r= eg(N,First),

 

   =             d= eref(First,Tag:Value),

 

   =             r= eg(M,Second),

 

   =             d= eref(Second,TagSec:ValueSec),

 

------=_NextPart_01C62C03.13F95830 Content-Location: file:///C:/B134688D/wam-Dateien/page0008.htm Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="us-ascii" Seitentitel

   =             u= ni(Tag:Value,TagSec:ValueSec),

 

   =             &nb= sp; (TagSec=3Dref,!,

 

   =             &nb= sp;    read_mem_deref(ValueSec,Result),

 

   =             &nb= sp;    write_reg(N,Result)

 

   =             &nb= sp; ;

 

   =             &nb= sp;    true

 

   =             &nb= sp; ).

 

 

 

get_value(e(N),a(M)):-!,

 

   =             r= ead_env_var(N,Tag:Value),

 

   =             r= eg(M,Second),

 

   =             d= eref(Second,TagSec:ValueSec),

 

   =             u= ni(Tag:Value,TagSec:ValueSec).

 

   =             &nb= sp;   

 

% *************************************************= *****************

 

% Full unification

 

% uni(X,Y) makes a full unification of X and Y=

 

% *************************************************= *****************

 

 

 

uni(const:Const,const:Const).

 

 

 

uni(ref:Addr,Tag:Value):-!,

 

   =             (= Tag=3Dref,!,

 

   =             &nb= sp;    bind(Addr,Value)

 

   =             ;=

 

   =             &nb= sp;    write_mem(Addr,Tag:Value),

 

   =             &nb= sp;    test_trail(Addr)

 

   =             )= .

 

------=_NextPart_01C62C03.13F95830 Content-Location: file:///C:/B134688D/wam-Dateien/page0009.htm Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="us-ascii" Seitentitel

 

 

uni(list:Addr,Tag:Value):-!,

 

   =             (= Tag=3Dref,!,

 

   =             &nb= sp;    write_mem(Value,list:Addr),<= /p>

 

   =             &nb= sp;    test_trail(Value)

 

   =             ;=

 

   =             T= ag=3Dlist,

 

   =             &nb= sp;    read_mem_deref(Addr,HeadOne),

 

   =             &nb= sp;    read_mem_deref(Value,HeadTwo),

 

   =             &nb= sp;    uni(HeadOne,HeadTwo),

 

   =             &nb= sp;    Addr1 is Addr+1,

 

   =             &nb= sp;    Value1 is Value+1,

 

   =             &nb= sp;    read_mem_deref(Addr1,TailOne),

 

   =             &nb= sp;    read_mem_deref(Value1,TailTwo),

 

   =             &nb= sp;    uni(TailOne,TailTwo)

 

   =             )= .

 

 

 

uni(struct:Addr,Tag:Value):-!,

 

   =             (= Tag=3Dref,!,

 

   =             &nb= sp;    write_mem(Value,struct:Addr),

 

   =             &nb= sp;    test_trail(Value)

 

   =             ;=

 

   =             T= ag=3Dstruct,

 

   =             &nb= sp;    read_mem_deref(Addr,const:F1/Arity1),

 

   =             &nb= sp;    read_mem_deref(Value,const:F2/Arity2),

 

   =             &nb= sp;    F1/Arity1=3DF2/Arity2,

 

   =             &nb= sp;    Addr1 is Addr+1,

 

   =             &nb= sp;    Value1 is Value+1,

 

------=_NextPart_01C62C03.13F95830 Content-Location: file:///C:/B134688D/wam-Dateien/page0010.htm Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="us-ascii" Seitentitel

   =             &nb= sp;    Iter is Arity1-1,

 

   =             &nb= sp;    uni_rest(Addr1,Value1,Iter)<= /p>

 

   =             )= .

 

 

 

uni_rest(_,_,0):-!.

 

 

 

uni_rest(AddrA,AddrB,X):-

 

   =             r= ead_mem_deref(AddrA,ValueA),

 

   =             r= ead_mem_deref(AddrB,ValueB),

 

   =             u= ni(ValueA,ValueB),

 

   =             A= ddrA1 is AddrA+1,

 

   =             A= ddrB1 is AddrB+1,

 

   =             X= 1 is X-1,

 

   =             u= ni_rest(AddrA1,AddrB1,X1).

 

 

 

% ********************* Unify Instructions ********= *****************

 

% unify_nil

 

% unify_void N

 

% unify_constant C

 

% unfiy_variable Vn

 

% unify_value Vn

 

% unify_local_value Vn

 

% *************************************************= ****************

 

 

 

unify_nil:- &= nbsp;  read_state,!,

 

   =             r= ead_next_arg_inc(Tag:Value),

 

   =             (= Tag=3Dref,!,

 

   =             &nb= sp;    write_mem(Value,const:[]),

 

------=_NextPart_01C62C03.13F95830 Content-Location: file:///C:/B134688D/wam-Dateien/page0011.htm Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="us-ascii" Seitentitel

   =             &nb= sp;    test_trail(Value)

 

   =             ;=

 

   =             T= ag:Value=3Dconst:[]

 

   =             )= .

 

 

 

unify_nil:- &= nbsp;  write_state,!,

 

   =             p= ush_global(const:[]).

 

 

 

 

 

unify_void(0):-!.

 

 

 

unify_void(N):-

 

   =             r= ead_state,!,

 

   =             i= nc_next_arg,

 

   =             N= 1 is N-1,

 

   =             u= nify_void(N1).

 

 

 

unify_void(N):-

 

   =             w= rite_state,!,

 

   =             p= ush_global_unb(_),

 

   =             N= 1 is N-1,

 

   =             u= nify_void(N1).

 

 

 

unify_constant(Const):-

 

   =             r= ead_state,!,

 

   =             r= ead_next_arg_inc(Tag:Value),

 

   =             (= Tag=3Dref,!,

 

   =             &nb= sp;    write_mem(Value,const:Const),

 

------=_NextPart_01C62C03.13F95830 Content-Location: file:///C:/B134688D/wam-Dateien/page0012.htm Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="us-ascii" Seitentitel

   =             &nb= sp;    test_trail(Value)

 

   =             ;=

 

   =             T= ag:Value=3Dconst:Const

 

   =             )= .

 

 

 

unify_constant(Const):-

 

   =             w= rite_state,!,

 

   =             p= ush_global(const:Const).

 

 

 

unify_variable(a(N)):-

 

   =             r= ead_state,!,

 

   =             r= ead_next_arg_inc(Tag:Value),

 

   =             w= rite_reg(N,Tag:Value).

 

 

 

unify_variable(a(N)):-

 

   =             w= rite_state,!,

 

   =             p= ush_global_unb(Addr),

 

   =             w= rite_reg(N,ref:Addr).

 

 

 

unify_variable(e(N)):-

 

   =             r= ead_state,!,

 

   =             r= ead_next_arg_inc(Tag:Value),

 

   =             w= rite_env_var(N,Tag:Value).

 

 

 

unify_variable(e(N)):-

 

   =             w= rite_state,!,

 

   =             p= ush_global_unb(Addr),

 

   =             r= ead_curr_env(CurrEnv),

 

------=_NextPart_01C62C03.13F95830 Content-Location: file:///C:/B134688D/wam-Dateien/page0013.htm Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="us-ascii" Seitentitel

   =             S= lot is CurrEnv+N+1,

 

   =             w= rite_mem(Slot,ref:Addr),

 

   =             t= est_trail(Slot).

 

 

 

unify_value(a(N)):-read_state,!,<= /p>

 

   =             r= ead_next_arg_inc(TagHeap:ValueHeap),

 

   =             r= eg(N,Tag:Value),

 

   =             d= eref(Tag:Value,TagF:ValueF),

 

   =             u= ni(TagHeap:ValueHeap,TagF:ValueF),

 

   =             (= TagF=3Dref,!,

 

   =             &nb= sp;    read_mem_deref(ValueF,NewTag:NewValue),

 

   =             &nb= sp;    write_reg(N,NewTag:NewValue)=

 

   =             ;=

 

   =             t= rue

 

   =             )= .

 

 

 

unify_value(a(N)):-write_state,!,=

 

   =             r= eg(N,Tag:Value),

 

   =             p= ush_global(Tag:Value).

 

 

 

unify_value(e(N)):-read_state,!,<= /p>

 

   =             r= ead_next_arg_inc(TagHeap:ValueHeap),

 

   =             r= ead_curr_env(CurrEnv),

 

   =             S= lot is CurrEnv+N+1,

 

   =             r= ead_mem_deref(Slot,Tag:Value),

 

   =             u= ni(TagHeap:ValueHeap,Tag:Value).

 

 

 

unify_value(e(N)):-write_state,!,=

 

------=_NextPart_01C62C03.13F95830 Content-Location: file:///C:/B134688D/wam-Dateien/page0014.htm Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="us-ascii" Seitentitel

   =             r= ead_curr_env(CurrEnv),

 

   =             S= lot is CurrEnv+N+1,

 

   =             r= ead_mem_deref(Slot,Tag:Value),

 

   =             p= ush_global(Tag:Value).