Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!weretis.net!feeder4.news.weretis.net!news.mixmin.net!aioe.org!.POSTED!not-for-mail From: "Rod Pemberton" Newsgroups: comp.lang.forth Subject: Re: Static Single Assignment form to Stack allocation Date: Sat, 07 Feb 2015 20:11:43 -0500 Organization: Aioe.org NNTP Server Lines: 57 Message-ID: References: <82c4c3dc-7692-4d03-a447-9bdd54ff9387@googlegroups.com> <2015Feb6.142225@mips.complang.tuwien.ac.at> <26b59aed-f1a6-4ccb-90ad-69c36b1abb89@googlegroups.com> NNTP-Posting-Host: n4wpt9zq8xR26Ttf9mo2BA.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Opera Mail/12.16 (Linux) X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.forth:36375 On Sat, 07 Feb 2015 14:22:13 -0500, Alex McDonald wrote: > on 07/02/2015 04:41:13, "Rod Pemberton" wrote: >> On Fri, 06 Feb 2015 14:16:36 -0500, Aliaksei Chapyzhenka >> wrote: >>> To clarify my intent: >>> * I do want allocate local variables (and phi points) on the stack >>> across the control flow. >> >> Forth usually uses two stacks, one for data and another for control >> flow. The control flow stack is called the "return" stack. C usually >> uses one stack for both data and control flow. So, control flow is >> *not* interleaved on a single stack like for C. It's on it's own >> stack. > > The Forth control flow stack and the return stack (or rstack, rack) are > not the same. The control flow stack exists only at compile time. How exactly does that work for an interpreted Forth? It's two stacks are always present, even during the "compile time" of a colon definition. I.e., the return stack is used for control flow, unless Forth has a non-standard definition of control flow meaning something other than what Computer Science normally defines it as ... >>> * I am trying to construct Stack machine code from SSA representation. >> >> Does your SSA representation use stack locations like registers, >> or more like a LIFO stack? If it's for a typical language, it'll >> be more like registers. > > SSA form is language neutral, and assumes an infinite memory space. It > says nothing about registers or stacks since it can't express those > concepts directly. Yes, that's exactly the problem he, and most compiler implementors, must solve, which he asked about. Isn't it? I thought it was. >>> * [I'm trying to stay] with core Forth vocabulary (DROP, SWAP, DUP, >>> Constant_PICK, >R, R>, ...) >> >> For the most part in Forth, the control stack, accessed by >R and R> , >> acts like a single, temporary, storage register. I.e., just by having >> fetch @ and store ! on a temporary register, e.g., A@ and A! , you can >> eliminate much of the need for the return stack, but not all use of >> the return stack. Any double operations, 2SWAP, etc, and loop >> operations will need to use multiple items on the return stack. > > Why would double operations use multiple items on the return stack? > Sorry, 2SWAP was a bad example. Others, like 2ROT may use 2>R 2R> etc. E.g., : 2ROT 2>R 2SWAP 2R> 2SWAP ; Rod Pemberton