@Marcov He is doing his own compiler, he is in at the deep end.
@TYDQ This stack should not be initialized other than by push and not uninitialized other than by pop or clear, but that is a range of pops until nil.
There are two things that can happen in your compiler: either it is not initialized at all, meaning no items are added on the stack and you call top prematurely or you call top when the stack is already empty, i.e. a stack underflow. This is really your own responsibility: as Marco wrote, it is a sanity check that should not occur to fail.
I don't think this is an issue with any other - working - compiler, just yours. So make sure to follow where stack.top is called and analyze it for
assignment and
underflow conditions.
It has nothing to do with the compiler code itself, there must be a logic error in
YOUR code!
The compiler devs can give you pointers, ask on the
mailing list, not the bugtracker, but the error is at your side.
It won't be very different from what I explained.
The logic is very easy:
If top is called there needs to be an item on the stack
Either by a push call
Or there needs to be at least one Item available for top.
This is by design.
In your case the calling order is not "in order".
The named internal error is there to prevent compiler devs to make such logic errors.
Well, you are now a compiler dev: see where you made the error!