Caclulating operand stack size
14 May 2005 21:59:03 -0400

          From comp.compilers

Related articles
Caclulating operand stack size (2005-05-14)
Re: Caclulating operand stack size (2005-05-16)
Re: Caclulating operand stack size (Aaron Gray) (2005-05-16)
Re: Caclulating operand stack size (Hans-Peter Diettrich) (2005-05-18)
Re: Caclulating operand stack size (2005-05-18)
| List of all articles for this month |

Newsgroups: comp.compilers
Date: 14 May 2005 21:59:03 -0400
Keywords: design, storage, question
Posted-Date: 14 May 2005 21:59:03 EDT


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)

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

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?


[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.