a wam implementation for the meta logic programming
play

A WAM Implementation for the Meta-logic Programming Language Log - PDF document

A WAM Implementation for the Meta-logic Programming Language Log _______________ University of Houston Department of Computer Science ________________ Iliano Cervesato July 24th, 1992 Iliano Cervesato Slide No. 1 Overview


  1. A WAM Implementation for the Meta-logic Programming Language ’Log _______________ University of Houston Department of Computer Science ________________ Iliano Cervesato July 24th, 1992 Iliano Cervesato Slide No. 1

  2. Overview • Meta-programming in ’Log • The WAM • A WAM implementation of ’Log Iliano Cervesato Slide No. 1

  3. Meta-programs ... are programs that treat other programs as data . They are used in : • Theorem Proving • AI (Knowledge Based Systems, ...) • Integrated Programming Environments • ... Meta-programming in Logic Programming : • 1982: Bowen & Kowalski’s paper • 1985: MetaProlog (Bowen et al.) • 1986: λ Prolog (Miller et al.) • 1989: Reflective Prolog (Costantini, Lanzarone) • 1990: Gödel (Hill, Lloyd) • 1991: ... ’Log Iliano Cervesato Slide No. 2

  4. ’Log ... a logic meta-programming language New features : • names • structural representations • constraints Objectives : • treat any syntactic entity of the language at the meta-level • efficient implementation in time and space; • sound and complete logical semantics • offer the users simple, powerful and easy-to-use meta-programming facilities Iliano Cervesato Slide No. 3

  5. Names are atomic ground terms associated with each syntactic entities of ’Log Examples : • characters: ch( a ) ch( Z ) • symbols: sy( foo ) sy( Alpha ) • terms: tr( f(a,g(X),X) ) tr( Alpha ) • clauses: cl( append([A|L1],L2,[A|L3]) :- append(L1,L2,L3) ) • programs: pg( append([],L,L). append([A|L1],L2,[A|L3]) :- append(L1,L2,L3). ) NB: • sy(foo) and sy(Alpha) do not unify • X and tr(X) do unify Iliano Cervesato Slide No. 4

  6. Structural representations represent an object as the list of the names of its components Examples : • symbols: [ ch( f ) , ch( o ) , ch( o ) ] [ ch( A ) , ch( l ) , ch( p ) , ch( h ) , ch( a ) ] • terms: [ sy( f ) , sy( a ) ,[ sy( g ) , sy( X ) ], sy( X ) ] sy( Alpha ) • clauses: [ tr( append([A|L1],L2,[A|L3]) ) , tr( append(L1,L2,L3) ) ] • programs: [ cl( append([],L,L) ) , cl( append([A|L1],L2,[A|L3]) :- append(L1,L2,L3) ) ] NB: • [sy(f),X] is not a structural representation: only some of its ground instances are • [sy(f),X] is an incomplete structural representation Iliano Cervesato Slide No. 5

  7. Constraints ’Log provides 4 operators to relate names and structural representations Examples : • symbols: sy( foo ) <=s=> [ ch( f ) , ch( o ) , ch( o ) ] • terms: tr( f(a,g(X),X) ) <=t=> [ sy( f ) , sy( a ) ,[ sy( g ) , sy( X ) ], sy( X ) ] • clauses: cl(...) <=c=> ... • programs: pg(...) <=p=> ... χ <= x => υ expresses constraints for the variable appear- ing in χ and υ ?- tr( f(g(a),b,C) ) <=t=> [ sy( f ) , A , sy( b ) , sy( C ) ]. A → [ sy( g ) , sy( a ) ]. ?- N <=t=> [ sy( f ) ,[ sy( g ) , sy( a )] , sy( b ) , sy( C ) ]. N → tr( f(g(a),b,C) ) . ?- N <=t=> [ sy( f ) , A , sy( b ) , sy( C ) ], A =[ sy( g ) , sy( a ) ]. A → [ sy( g ) , sy( a ) ], N → tr( f(g(a),b,C) ) . ?- N <=t=> [ sy( f ) , A , B , sy( C ) ], A =[ sy( g ) , sy( a ) ]. A → [ sy( g ) , sy( a ) ], ⇐ N <=t=> [ sy( f ) ,[ sy( g ) , sy( a ) ], B , sy( C ) ]. Iliano Cervesato Slide No. 6

  8. Warren Abstract Machine The WAM is an architecture for compiling and execut- ing Prolog code. program W A M a q object n u program s e Compiler Executer w r object e y query r • the object code is an assembly language • the executer operates like a traditional line-code as- sembler • some common instructions are: get_variable X5, A1 unify_constant foo set_value X4, A0 put_list X3 allocate 4 call append, 0 try_me_else app_2, 3 Iliano Cervesato Slide No. 7

  9. Run-time support HEAP STACK TRAIL PDL CODE Registers : A 0 A 1 A 2 X n . . . . . . P CP E B TR H S MODE Iliano Cervesato Slide No. 8

  10. Compilation of a clause h :- b 1 ,...,b n . h: allocate N < get code for h> < put code for b 1 > call b 1 ... < put code for b n > call b n deallocate Example : append([A|L1],L2,[A|L3]) :- append(L1,L2,L3). append:allocate 0 get_list A0 unify_variable X3 unify_variable X4 get code get_list A2 unify_value X3 unify_variable X5 put_value X4, A0 put code put_value X5, A2 call append deallocate Iliano Cervesato Slide No. 9

  11. WAM for ’Log Novel aspects : • heap representation of names • constraint handling Iliano Cervesato Slide No. 10

  12. Name representation Names are represented as marked structural representa- tions . Clause CLN @C C = h:-b 1 ,..,b n . Structural Name representation CLN @C ... @C LIS @h LIS @h ... ... @b n TRN <b n > @b n TRN <b n > CON [] CON [] @b n-1 TRN <b n-1 > @b n-1 TRN <b n-1 > LIS @b n LIS @b n ... ... @b 1 TRN <b 1 > @b 1 TRN <b 1 > LIS @b 2 LIS @b 2 @h TRN <h> @h TRN <h> LIS @b 1 LIS @b 1 Iliano Cervesato Slide No. 11

  13. Name representation (Cont’d) Characters and usually symbols are represented atomi- cally Name symbol s SIN s = c 1 ...c n The atomic representation of symbol names complicates the unification algorithm Iliano Cervesato Slide No. 12

  14. Constraints Compilation of ν <= x => σ : • put the structural representation σ in A 1 • create an x -name cell in A 0 • get the name ν from A 0 • process the constraint ν <= x => σ A 0 A 1 x Heap representation of σ Iliano Cervesato Slide No. 13

  15. Handling constraints Problems : • constraints resolution is usually delayed • active constraints must be kept track of • unification can solve or invalidate an active con- straint • active constraints must be checked periodically for validity and satisfaction • backtracking must undo constraint passivation Solutions : • keep track of all the constraints in a LIFO queue • mark the solved constraints • check an active constraints when changes occur • use chronological marking for backtracking constraint stack ν <= x => σ solving time Heap repr. of ν time-stamp Iliano Cervesato Slide No. 14

  16. Run-time support for constraint CTR HEAP STACK TRAIL PDL CODE Registers : A 0 A 1 A 2 X n . . . . . . PC P CP E B TR H S MODE Iliano Cervesato Slide No. 15

  17. Conclusions • The WAM-based compilation and execution of ’Log have been analysed • The WAM design has been modified to accomo- date the new features of ’Log • A programming environment for ’Log has been produced. It contains: — a compiler — an executer — a WAM-based debugger — miscellaneous tools • The effiency of the system is satisfactory Iliano Cervesato Slide No. 16

  18. Further works In the resulting system: • use the system for testing the features of ’Log • improve the efficiency • hard-wire higher level meta-programming facilities With ’Log: • test several syntaxes • add reflection • hide <= x => • develop higher-level languages on top of it Iliano Cervesato Slide No. 17

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend