Maximilian-Winter/Bite-Programming-Language

RetVal throws an out-of-bounds exception

Closed this issue · 5 comments

It throws an out-of-bounds error at Peek(), where Count is 0 at the time RetVal is accessed

    public DynamicBiteVariable Peek()
    {
        DynamicBiteVariable fastMemorySpace = m_DynamicVariables[Count - 1];
        return fastMemorySpace;
    }

I think the best solution would be to cache the last return value, in a register like variable and give that back. Any thoughts on this?

I just checked the unit tests and I will pay more attention to these, because they are really helpful! Thank you again.

I thought that was what m_TopMostStackItem did, which is why I used it. I wouldn't want a separate register that needs to be updated each operation, bad for performance. Did something change with m_TopMostStackItem? Sorry I haven't had the time to look at the exact changes. It looks like Peek() should work if that's what it's purpose is, to get the item at the top of the stack, but the Count probably gets obliterated when the program ends and cleanup runs? Just a guess.

Yeah thats the problem. I changed the code and removed the TopMostStackItem stuff, because it caused issues and the performance impact is very small. But because of that I needed some sort of register for the return value anyway. So instead of a only locally used variable I made an Register in the bitevm, now retval is returning this. I will push the change as soon I'm finished with other stuff.

I just pushed the changes to the repo.