110 likes | 407 Views
From WAM to ATOAM. WAM (Warren Abstract Machine) de facto standard Prolog machine Indexing on one argument Parameter passing through registers ATOAM (Another Tree-Oriented Abstract Machine) Matching trees Parameter passing through frames Facilitates software emulation.
E N D
From WAM to ATOAM • WAM (Warren Abstract Machine) • de facto standard Prolog machine • Indexing on one argument • Parameter passing through registers • ATOAM (Another Tree-Oriented Abstract Machine) • Matching trees • Parameter passing through frames • Facilitates software emulation by Neng-Fa Zhou
The WAM Architecture registers code area A1 A2 ... An s P H T stack heap trail E B by Neng-Fa Zhou
The WAM Frame Structures Choice point frame Environment frame Am … A1 HB H T B E CPF CP Parent CP Y1 … Yn Head:-B1. Head:-B2. Head:-G1,G2. by Neng-Fa Zhou
Parameter Passing in WAM Caller’s environment Callee’s choice point Callee’s environment by Neng-Fa Zhou
Compilation for the WAM member(X,[X|_]). member(X,[_|L):- member(X,L). member/2: try_me_else C2,2 get_list A2 unify_value A1 unify_var A1 proceed C2:trust_me 2 get_list A2 unify_var X3 unify_var A2 execute member/2 by Neng-Fa Zhou
The ATOAM Architecture registers code area X1 X2 ... Xn s P AR stack H heap T trail TOP by Neng-Fa Zhou
Frame structure Registers AR: Parent’s frame CP: Continuation PC TOP: Top of the stack The trail stack is not used The ATOAM Architecture for Determinate Programs by Neng-Fa Zhou
Frame structure Registers B: The latest choice point frame HB: same as B->H The trail stack Updates of variables need be saved if the variables are older than B or HB The ATOAM Architecture for Nondeterminate Programs Machine status by Neng-Fa Zhou
Matching Trees p(A1,[0,1]):-true ? true. p(A1,[0,0]):-true ? true. p(A1,A2):-A1>0 : q(A1,A2). P/3: allocate_nondet 8 jmpn_list y(1), L1 fetch_var y(-7) % car fetch_var y(-8) % cdr jmpn_eq_int y(-7),0,L1 jmpn_list y(-8), L1 fetch_var y(-7) fetch_var y(-8) jmpn_eq_int y(-7),1,L0 jmpn_eq_atom y(-8),[],L1 fork L1 return_b L0:jmpn_eq_int y(-7),0,L1 jmpn_eq_atom y(-8),[],L1 fork L1 return_b L1:move_int x(1),0 jmpn_gt y(2),x(1),cut_fail cut execute q/2 by Neng-Fa Zhou
Performance Comparison As of April 2003 by Neng-Fa Zhou
Papers • N.F. Zhou: Global Optimizations in a Prolog Compiler for the TOAM, Journal of Logic Programming, pp.275-294, 1993. • N.F. Zhou: Parameter Passing and Control Stack Management in Prolog Implementation Revisited,ACM Transactions on Programming Languages and Systems, Vol18, No6, pp.752-779, 1996. • N.F Zhou: A High-Performance Abstract Machine for Prolog and its Extensions, CUNY Computer Science, TR2003014, 2003. by Neng-Fa Zhou