Question on ORG.SaveRegs / ORG.RestoreRegs in the FPGA Oberon compiler
Right. If the procedure variable was not actually loaded before the parameters were evaluated (ie the procedure was not the result of an expression), no registers needed to be saved, so the save is explicitly avoided.
I presume you mean this is how the compiler distinguishes between regular procedures and function procedures (which are part of an expression)?
It's only in the case where it was already loaded into a register (detected by RH > 0 before the save), where it was therefore saved (first, fortunately), and consequently needs to be explicitly restored.
Or when x.mode = RegI = 11, as In the sample program M below, where RH > 0 for *both* function procedure ptr.f *and* regular procedure ptr.p (which is not part of an expression). In the second call ptr.f(āDā) in RunF2 below, RH is actually 2, not 1, in PrepCall. -ap MODULE M; TYPE Procedure = PROCEDURE(a, b: INTEGER); (*regular procedure*) Function = PROCEDURE(c: CHAR): INTEGER; (*function procedure*) Ptr = POINTER TO Rec; Rec = RECORD p: Procedure; f: Function END ; VAR ptr: Ptr; res: INTEGER; PROCEDURE P(a, b: INTEGER); BEGIN END P; (*regular procedure*) PROCEDURE F(c: CHAR): INTEGER; BEGIN RETURN 0 END F; (*function procedure*) PROCEDURE RunP*; BEGIN ptr.p(1, 2) (*x.mode = RegI = 11 and RH = 1 in PrepCall, x.mode = 10 = Reg in Call*) END RunP; PROCEDURE RunF1*; BEGIN res := ptr.f("C") (*x.mode = RegI = 11 and RH = 1 in PrepCall, x.mode = 10 = Reg in Call*) END RunF1; PROCEDURE RunF2*; BEGIN res := ptr.f("C") (*x.mode = RegI = 11 and RH = 1 in PrepCall, x.mode = 10 = Reg in Call*) + ptr.f("D") (*x.mode = RegI = 11 and RH = 2 in PrepCall, x.mode = 10 = Reg in Call*) END RunF2; BEGIN NEW(ptr); ptr.p := P; ptr.f := F END M. ORP.Compile M.Mod/s ~
Hi Andreas,
Right. If the procedure variable was not actually loaded before the parameters were evaluated (ie the procedure was not the result of an expression), no registers needed to be saved, so the save is explicitly avoided.
I presume you mean this is how the compiler distinguishes between regular procedures and function procedures (which are part of an expression)?
No. It distinguishes that based on the type, not the mode. I think we may have been talking at cross-purposes, I'm sorry if I've confused things for you further. I would not expect a student to grok this even in an exercise, without a lot of help. I think it's a good illustration of how a badly-placed comment might be worse than no comment at all - some things are so intricate it's just better to try to understand the code, since as Wirth says, that alone contains the ultimate explanation. Cheers, Paul
participants (2)
-
Andreas Pirklbauer -
Paul Reed