The previous stack design was to store only data descriptors on the stack – not data itself. The side-effect of this is that everything becomes global data. The alternative to pass a copy also have a side effect if I pass an object + passing an auto-decided combination of data and references is not nice either. We also need to look at details on restoring stack after a function return as well as how do we return Event parameters? And all of this should happen automatically as I don’t want the developer to worry about the stack at all.
I want to keep the design with pushing and popping references – Object References this time. As the reference point to actual data we can either point to the global copy or a new, local copy depending on what we want. “Reference” is a good keyword prefix for a new variable type that only point to data.
In the same way as we used the index top for stack we use the 64kb area for stack variables. We create a separate stack index for 32 bit Object Descriptors and a separate SRAM buffer for stack temporary storage. In the real buffer table we might use 1Kb for data and 1Kb for stack carefully calculated by the Assembler.
This figure illustrate our modified Stack. As with data we create a buffer for the VM and use of this for each module. The two buffers are arranged so data is the lower part and stack the higher forming a max of 64Kb. Size of data can be calculated, size of stack need to be estimated.
The Object Index is not a real table as this is embedded into the instructions as they access parameters, but we need an actual Stack Entry Table to hold data for each call. As we make a call we add an entry to this table – as we execute End we remove the entry and free the stack back to the previous Free Stack Offset.
The only issue that is not covered is Raise. I will get back to that later – we will have a few try and fails before we get this going…