Path: csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: "Rod Pemberton" Newsgroups: comp.lang.forth Subject: Re: Static Single Assignment form to Stack allocation Date: Fri, 06 Feb 2015 23:41:13 -0500 Organization: Aioe.org NNTP Server Lines: 37 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:36344 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. > * 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. Forth uses the data stack like a LIFO stack. C uses the data stack like an addressable array of registers, but also pushes and pops data items. Forth uses the return stack for control flow and temporary storage. If you want to use the Forth stack like an array of registers, you'll need PICK and the reverse operation, which you may name something like ... "PLACE". > * [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. Rod Pemberton