Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: Hans-Peter Diettrich Newsgroups: comp.compilers Subject: Re: Add nested-function support in a language the based on a stack-machine Date: Tue, 13 Feb 2018 12:10:13 +0100 Organization: Compilers Central Lines: 33 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <18-02-013@comp.compilers> References: <18-02-009@comp.compilers> <18-02-010@comp.compilers> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="85641"; mail-complaints-to="abuse@iecc.com" Keywords: code Posted-Date: 13 Feb 2018 11:15:23 EST X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:1953 Am 12.02.2018 um 23:16 schrieb dror.openu@gmail.com: >> [This at least used to be a standard topic in compiler texts. You should >> be able to do either in O(1). -John] > > I'm not sure how to calculate it in compile time, because the call frame > doesn't have a fixed size, because I'm using the same stack for storing the > call-frames and for the operations evaluation (iadd, isub, etc..). Maybe I > should split it into two stacks, one for the call frames, and the second for > the operation evaluations. I just sharing my thoughts. > > [I would think that your compiler should always know how many partial > results are on the stack above the call frame so it should be able to > use a fixed offset to get to the chain pointers at the base of call > frame. -John] ACK Simple compilers use a dedicated base pointer register (x86: eBP) for their stack frame, but clever compilers will track the current stack pointer offset to that base address. The calling frames can have a variable size, when the local function is called from various places in the code. I.e. the address of a local variable in an outer scope can vary, fixed is only the variable's offset to its own frame start. That's why the chain of all intermediate frame pointers must be followed, until the frame of the variable of interest is found. Things can become worse if one of the calling functions is called recursively, so that a variable number of frames has to be traversed until the outmost frame is found. DoDi