VM – Raise

The introduction of the 32 bit Object Descriptor bloat the instruction set, but we currently only have 12 high-level instructions left in the VM – This is Assign, Call, Decode, Encode, End, Exit, For, If, NOP, Raise, While and Switch. Just for the record – this is actual instructions, not keywords supported by the Assembler syntax.

I have to walk through the details of all of them, but the one that currently have my focus is Raise and how it will behave on the stack together with a Call..On..End sequence. Lets do a few examples and see if we can get this to work:

Example 1:

Foo MyFunc
            Raise Error
Event Error
End

Call MyFunc

In this case we call MyFunc that return with the event Error – which will call the default and do nothing. (1) Call create a stack entry, (2) raise re-use that stack entry and (3) End consume the stack entry.

Example 2:

Foo MyFunc
            Raise Error
Event Error
End

Call MyFunc
On Error
            println "Error"
End

This is a bit more tricky as we now override the Error event, but how will Raise know which Error to call? The answer is that the Assembler need to create an event table for the call – this is by default the one for the function, but in this case with an overridden Error event. It also means we need to modify Raise to use an enumerated event code (generated by the Assembler) to indirect index the Event body. As raise in this case call Error and println it reach End that consume the stack entry.

 Example 3:

 Foo MyFunc
            Raise Timeout
Event Timeout
            Raise Error
Event Error
End

Call MyFunc
On Error
            println "Error"
End

In this case I cascade the events – (1) we Call MyFunc creating the stack entry, (2) Raise Timeout that re-use the stack entry, (3) Raise Error that is overridden and run into End that consume the stack entry.

Example 4:

Foo MyFunc
            Raise Timeout
Event Timeout
            println "Timeout"
Event Error
End

Call MyFunc
On Error
            println "Error"
End

In this case we Raise Timeout that run into a “Event” – basically terminating with an hidden End that will consume the stack entry and jump to after Call..On..End.

I need to extend the Call instruction to include the event table + modify the Raise instruction, but that seems to be it.

Leave a Reply