Caclulating operand stack size

clearm@comcast.net
14 May 2005 21:59:03 -0400

          From comp.compilers

Related articles
Caclulating operand stack size clearm@comcast.net (2005-05-14)
Re: Caclulating operand stack size anton@mips.complang.tuwien.ac.at (2005-05-16)
Re: Caclulating operand stack size angray@beeb.net (Aaron Gray) (2005-05-16)
Re: Caclulating operand stack size DrDiettrich@compuserve.de (Hans-Peter Diettrich) (2005-05-18)
Re: Caclulating operand stack size anton@mips.complang.tuwien.ac.at (2005-05-18)
| List of all articles for this month |

From: clearm@comcast.net
Newsgroups: comp.compilers
Date: 14 May 2005 21:59:03 -0400
Organization: http://groups.google.com
Keywords: design, storage, question
Posted-Date: 14 May 2005 21:59:03 EDT

Hello,


I am developing a stack-based virtual machine similar to the JVM.
Unfortunately, everytime I push or load something onto the operand
stack, I have to do this:


if(++SP == stackSize)
        growStack();


I would like to avoid this dynamic size check because it slows things
down. The JVM requires routines to specify a stack size limit as I
recall.


I *think* it is possible to statically calculate a stack size limit
using attribute grammars, but I'm not sure. For example:


Example expression and corresponding stack utilization:


1 - (2 + 3) * 4


          2 4 1
2 => 3 => 5 => 5 => 20 => 20 => -19


As can be seen, the stack size was never larger than 2. I was
wondering if a language can calculate this limit during an AST walk by
using attribute grammars?


Thanks,


MC.
[I'd think you could estimate an upper limit by walking the tree and
finding the depth of the deepest node. I suppose you could make the
depth attribute 1 for a leaf and 1+max(L,R) for an internal node. -John]





Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.