naim@uswat.uswest.com (Naim Abdullah) (09/08/90)
I have been trying to understand the WAM by reading "The WAM: A (Real) Tutorial" by Hassan Ait-Kaci (it is a technical report from DEC's Paris Research Labs). One of the things that I am puzzled about is which WAM instruction is responsible for storing the permanent variables in the environment when a new rule is called. The situation is illustrated by the following: foo(args) :- ...., bar(args),.... This is translated to: foo: allocate get args of foo ..code for predicates before bar... put args of bar call bar/arity, N ...code for predicates after bar... proceed bar: allocate get args of bar ...code for bar's body.. proceed Now the number of permanent variables in bar is not necessarily equal to its arity. In both Warren's original paper and the WAM tutorial referenced above, the description of allocate does not seem to reserve space for the permanent variables. So my question is which instruction allocates the space for bar's permanent variables ? Thank you. Naim
jan@cancol.canberra.edu.au (Jan Newmarch) (09/12/90)
In article <10942@uswat.UUCP>, naim@uswat.uswest.com (Naim Abdullah) writes: > Research Labs). One of the things that I am puzzled about is which > WAM instruction is responsible for storing the permanent variables > in the environment when a new rule is called. > > The situation is illustrated by the following: > > foo(args) :- ...., bar(args),.... > > This is translated to: > > foo: allocate > get args of foo > ..code for predicates before bar... > put args of bar > call bar/arity, N > ...code for predicates after bar... > proceed > > bar: allocate > get args of bar > ...code for bar's body.. > proceed > > Now the number of permanent variables in bar is not necessarily equal to > its arity. In both Warren's original paper and the WAM tutorial referenced > above, the description of allocate does not seem to reserve space for the > permanent variables. So my question is which instruction allocates the space > for bar's permanent variables ? Look at the number N in "call bar/arity, N". This states the number of permanent variables in *foo* that are still active at that time. "allocate" reserves space for foo's permanent vbls plus E and CP. Who reserves space for bar's permanent vbls? Well it depends on what is in the body of bar. If it is a unit clause, say, it has no permanent vbls and so no-one does. If it does have some, then they have space created for them when you first come across them, by e.g. a "put_variable Y". Subgoals in the body of bar will leave space for them in the allocate instruction. So vbl space is created as needed, and subgoals just leave enough space to leave them untouched. I have a chapter on the WAM in my book "Logic Programming: Prolog and Stream Parallel Languages" from Prentice-Hall. +----------------------+---+ | Jan Newmarch |:-)| ACSnet: jan@cancol.oz | Info. Sciences & Eng.|___| ARPA: jan%cancol.oz.au@uunet.uu.net | Univ Canberra | UUCP: {uunet,ukc}!munnari!cancol.oz.au!jan | P.O. Box 1 | CSNET: jan%cancol.oz@australia | Belconnen A.C.T. 2616 | JANET: jan%au.oz.cancol@EAN-RELAY | AUSTRALIA | telephone: 06-522 422 +--------------------------+
dougren@vlsi.waterloo.edu (Douglas Renaux) (09/18/90)
In article <398@cancol.canberra.edu.au> jan@cancol.canberra.edu.au (Jan Newmarch) writes: > > > > >In article <10942@uswat.UUCP>, naim@uswat.uswest.com (Naim Abdullah) writes: >> Research Labs). One of the things that I am puzzled about is which >> WAM instruction is responsible for storing the permanent variables >> in the environment when a new rule is called. >> >> The situation is illustrated by the following: >> >> foo(args) :- ...., bar(args),.... >> >> This is translated to: >> >> foo: allocate >> get args of foo >> ..code for predicates before bar... >> put args of bar >> call bar/arity, N >> ...code for predicates after bar... >> proceed >> >> bar: allocate >> get args of bar >> ...code for bar's body.. >> proceed >> >> .................... So my question is which instruction allocates the space >> for bar's permanent variables ? > >.... >If it does have some, then they have space created for them when you first come >across them, by e.g. a "put_variable Y". Subgoals in the body of bar will > >| Jan Newmarch |:-)| ACSnet: jan@cancol.oz >| Info. Sciences & Eng.|___| ARPA: jan%cancol.oz.au@uunet.uu.net Space for a permanent variable (a variable in the environment) is never created by a "put_variable Y". Only "allocate" reserves (creates) space in the local stack (in an environment) for permanent variables. However, "allocate" only reserves space, it has to be initialized later on by an instruction as: "get_variable Yi,An", "get_value Yi,An", "put_varia- ble Yi,An". Douglas Renaux dougren@vlsi.waterloo.edu