Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: comp.lang.java.programmer,comp.programming Subject: Re: Creating a new stack from an exisiting one. Date: Sun, 04 Nov 2012 14:41:30 +0100 Organization: Informatimago Lines: 62 Message-ID: <87mwyxlc39.fsf@informatimago.com> References: <0.73472d82415d5353822e.20121103155132GMT.87mwyyvg57.fsf@bsb.me.uk> <0.898697c4e5f8819c7fa0.20121104004445GMT.878vaiurgi.fsf@bsb.me.uk> <87vcdllg3u.fsf@informatimago.com> <0.96b4857ea7d651ed53b3.20121104124839GMT.87txt5tty0.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: individual.net 1oIKnrpS3e4C8hoS6t56gAx6taJI/8CV2xvYvkl6XrFzW4g3BJUD88HrKJYEavu4W7 Cancel-Lock: sha1:YzRmZTE5ZDgzYTUxNjQyYmY2MjQzYjA5MThjYzg3ZDQyNTc1ZmRjMg== sha1:pVPaTkcwF9lE+stJuJxbW1mtF5U= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (darwin) Xref: csiph.com comp.lang.java.programmer:19620 comp.programming:2462 Ben Bacarisse writes: > "Pascal J. Bourguignon" writes: > >> Well, I don't know of any processor that uses a separate stack for the >> frame pointers. > > No, me neither. The description also lacked any mention of the return > address so I don't think this is about hardware. Maybe it's coursework, > and the separate stacks are there to keep the concepts clear? I don't > know. That said, in early Fortran and Pascal compilers, they used a "display record" vector, which would point to the visible frames. While such a "display record" could be managed as a stack, static analysis allows for a fixed size and direct updating. So for example: function f (x:integer) function g (y:integer) begin if x>y then g:=x+y+f(x-y)-g(y+1) else g:=x+y; end; begin if x<0 f:=1 else f:=g(x-1) end; while one could need an unbounded number of stack frames (depending on the value of the parameters), the invocations of the function g see only the frame of one invocation of the function f, so we need a "display record" of size 2. stack: ------------------- stack frame for f stack frame for g stack frame for g stack frame for g stack frame for f stack frame for g stack frame for g stack frame for f <----+ display: stack frame for g | --------- stack frame for g +------- f stack frame for g <------------ g The display record is a kind of stack of lexical scopes. If we get outside of f, and enter another embedding of lexical scopes, another set of stack frame pointers may be "stacked" into the display record. -- __Pascal Bourguignon__ http://www.informatimago.com