Warren Abstract Machine (WAM)

栏目: IT技术 · 发布时间: 4年前

内容简介:In 1983,David H. D. Warren designed anabstract machine for the execution ofProlog consisting of amemory architecture and aninstruction set.This design became known as theThe purpose of compiling Prolog code to the more low-level WAM code is to make subsequ

In 1983,David H. D. Warren designed anabstract machine for the execution ofProlog consisting of amemory architecture and aninstruction set.This design became known as the Warren Abstract Machine (WAM) and has become the de facto standard target for Prologcompilers.

Contents

Purpose [ edit ]

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 compilations to native code are often easier to perform on the more low-level representation.

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.

Memory areas [ edit ]

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

Example [ edit ]

Here is a piece of Prolog code:

 girl(sally).
 girl(jane).
 
 boy(B) :- \+ girl(B).

A WAM-based Prolog compiler will compile this into WAM instructions similar to the following:

 predicate(girl/1):
    switch_on_term(2,1,fail,fail,fail),
 label(1): switch_on_atom([(sally,3),(jane,5)])
 label(2): try_me_else(4)
 label(3): get_atom(sally,0)
           proceed
 label(4): trust_me_else_fail
 label(5): get_atom(jane,0)
           proceed
 
 predicate(boy/1):
    get_variable(x(1),0)
    put_structure(girl/1,0)
    unify_local_value(x(1))
    execute((\+)/1)])

An important characteristic of this code is its ability to cope with the various modes in which the predicates can be evoked: any argument might be a variable, aground term, or a partly instantiated term. The "switch" instructions handle the different cases.

References [ edit ]

  1. David H. D. Warren (October 1983). An abstract Prolog instruction set (PDF) . Menlo Park, CA, USA: Artificial Intelligence Center atSRI International.
  2. Hassan Aït-Kaci (February 18, 1999). Warren's Abstract Machine: A Tutorial Reconstruction (PDF) . Archived from the original (PDF) on 2003-02-13.
  3. Hassan Aït-Kaci. "Warren's Abstract Machine: A Tutorial Reconstruction; the book, errata and slides" . Retrieved 7 March 2011 .

以上所述就是小编给大家介绍的《Warren Abstract Machine (WAM)》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

计算机程序设计艺术(第3卷 英文版·第2版)

计算机程序设计艺术(第3卷 英文版·第2版)

Donald E.Knuth / 人民邮电出版社 / 2010-10 / 119.00元

《计算机程序设计艺术》系列被公认为计算机科学领域的权威之作,深入阐述了程序设计理论,对计算机领域的发展有着极为深远的影响。本书是该系列的第3卷,扩展了第1卷中信息结构的内容,主要讲排序和查找。书中对排序和查找算法进行了详细的介绍,并对各种算法的效率做了大量的分析。 本书适合从事计算机科学、计算数学等各方面工作的人员阅读,也适合高等院校相关专业的师生作为教学参考书,对于想深入理解计算机算法的读......一起来看看 《计算机程序设计艺术(第3卷 英文版·第2版)》 这本书的介绍吧!

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具