9 ms·
> a well balanced stack what is a well-balanced stack?
by yodsanklai 6y ago
> a well balanced stack
what is a well-balanced stack?
- abecedarius 6y agoThey mean the stack depth is guaranteed to be statically apparent at each point in the control flow. In the JVM the class loader checks this with an analysis phase during loading. (The JVM design makes this harder than it really needs to be, since it doesn't insist on reducible control flow, iirc. You could say OTOH that irreducible control flow is more valuable than trivial analyzability, which is a reasonable take, but conflicts with the above comment's design point of a stack machine being both very simple for an interpreter and not an obstacle to quickly compiling to decent register-machine code. Needing a fancier stack-depth analysis would be that sort of obstacle.)
- RodgerTheGreat 6y agoThe stack is balanced if everything pushed at a given level of scope is popped as that scope closes. This precludes variable-stack-effect sequences as one might have in a Forth definition like: : ?drop dup if drop then ;