Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!know!samsung!munnari.oz.au!csc.anu.oz.au!csc3.anu.oz.au!ccadfa!cancol!jan From: jan@cancol.canberra.edu.au (Jan Newmarch) Newsgroups: comp.lang.prolog Subject: Re: Who allocates space for perm vars on stack ? Message-ID: <398@cancol.canberra.edu.au> Date: 12 Sep 90 00:10:53 GMT References: <10942@uswat.UUCP> Organization: Info Sci & Eng, University of Canberra Lines: 55 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 +--------------------------+