Path: csiph.com!eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Rod Pemberton" Newsgroups: comp.lang.forth Subject: Re: Question about checking the stack Date: Wed, 25 Nov 2015 04:54:28 -0500 Organization: Aioe.org NNTP Server Lines: 34 Message-ID: References: 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:43747 On Wed, 25 Nov 2015 01:31:28 -0500, Chris Curl wrote: > For you guys who have implemented your own Forths ... > when do you check the stack? Currently, I check on every push and pop to the data and return stacks. This adds a bit of extra overhead for C. I've been thinking about checking far less often, but was worried about possible underflows and overflows not being detected or being detected too late. Even if I do check less frequently, I intend to keep the check for underflow of the data stack for every pop. I think is the most likely type of frequent underflow. IIRC, the return stack shouldn't underflow for normal interpreter operation. I.e., it requires user abuse of the return stack or incorrect manipulation of it. Overflow of either stack is likely far less common too. I have very small stacks and haven't come close to an overflow yet. So, I think those can be safely checked far less frequently. You can check for a stack value approaching overflow, say within 10 of the limit, to prevent an actual overflow. Rod Pemberton -- How to kill Facebook. Tell a bunch of fourth graders that only old people use Facebook. Wait eight years.