NestedCall

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

NestedCall

BlackRaven
I think I found an issue with the NestedCall test in project 8.

The test uses temp 5 and 6 to store values, and checks these values at the end of the program, but the book specifically says :
                              "After the called function returns,
                              the caller's memory segments
                              argument, local, static, this,
                              that, and pointer are the same as
                              before the call, and the temp segment
                              is undefined.".

Yet, the VM code from NestedCall has:
                              "function Sys.main 0
                               push constant 123
                               call Sys.add12 1
                               pop temp 0
                               push constant 246
                               return".

NestedCall.tst check temp zero, even though this value is undefined after Sys.main returns.
Is this an error, or am I just completely missing something? If anyone could clarify this for me, I would
really appreciate the help!

            Thanks, Brendan
Reply | Threaded
Open this post in threaded view
|

Re: NestedCall

cadet1620
Administrator
BlackRaven wrote
I think I found an issue with the NestedCall test in project 8.

The test uses temp 5 and 6 to store values, and checks these values at the end of the program, but the book specifically says :
                              "After the called function returns,
                              the caller's memory segments
                              argument, local, static, this,
                              that, and pointer are the same as
                              before the call, and the temp segment
                              is undefined.".
That should really read "values in the temp segment are undefined." The temp segment itself is always defined as RAM[5-12].  What this statement says is that the calling function cannot assume that anything that it stored in the temp segment will still be there after the called function returns.
Yet, the VM code from NestedCall has:
                              "function Sys.main 0
                               push constant 123
                               call Sys.add12 1
                               pop temp 0
                               push constant 246
                               return".

NestedCall.tst check temp zero, even though this value is undefined after Sys.main returns.
Is this an error, or am I just completely missing something? If anyone could clarify this for me, I would
really appreciate the help!
NestedCall.tst is testing both temp 0 and temp 1 at the end of the test. Notice the "pop temp 1" after the "call Sys.main 0".

This is OK because the test code is specifically written so that temp 0 and temp 1 are not modified after they are set, so they are guaranteed, in this case, to be valid when Sys.init gets to the infinite loop.

From table 7.6:
    temp    Fixed eight-entry segment         May be used by any VM function
            that holds temporary variables    for any purpose. Shared by all
            for general use.                  functions in the program.
Sys.init and Sys.main are cooperating in their use of temp 0 and temp 1 as shared variables.


--Mark