PrincOps Procedure Call Conceptual registers L: addr of current local frame G: addr of current global frame G = L^.accesslink CB: addr of current code segment CB = G^.code PC: program counter (CB relative) ES[S]: eval stack (indexed by S) PrincOps Procedure Call Calling a procedure push arguments on eval stack get procedure descriptor (several methods) set new (PC, G, CB) from procedure descriptor allocate & link new local frame (set L) pop arguments into local frame Returning from a procedure push return values on eval stack unlink and free local frame (set L) set new (PC, G, CB) from frame pop return values to destination variables EFC n EFC n: -- External Function Call, link n {3.5} lb _ IF G^.codelinks THEN CB ELSE G pd _ (lb-n-1)^ X1: ge _ (GFT+pd.gfi)^ G _ ge - ge & 3 ep _ pd.ep + (ge & 3) * 32 CB _ G^.code -- 32 bits X2: L^.pc _ PC PC _ (CB+1+ep*2)^ fsi _ (CB+2+ep*2)^ lastL _ L L _ (AV+fsi)^ IF L = 0 THEN ... -- hard case (AV+fsi)^ _ L^ L^.accesslink _ G L^.returnlink _ lastL SFC & LFC n SFC: -- Stack Function Call {3.2} pd _ ES[S]; S_S-1 WHILE pd & 3 = 2 DO pd _ pd^; ENDLOOP; IF pd & 1 = 1 THEN GO TO X1 -- direct case L _ pd -- frame case G _ L^.accesslink CB _ G^.code -- 32 bits PC _ L^.pc -- done LFC n: -- Local Function Call, entry point n {2.3} ep _ n GO TO X2 RET RET -- Return from procedure {2.2} lastL _ L^.returnlink fsi _ (L-1)^ L^ _ (AV+fsi)^ (AV+fsi)^ _ L L _ lastL G _ L^.accesslink CB _ G^.code PC _ L^.pc Nested procedures In the parent parent is the scope declaring the nested proc indirect PD is pointed at PD in parent frame Note!! PD MOD 4 = 2 the PD in parent frame may be direct or indirect When the indirect PD is called 1. pd is recovered from the eval stack 2. subtracting the offset forms the static link 3. which is placed in local 0 Fine points Eval stack depth at call the eval stack only holds the arguments at return the eval stack only holds the returns Short vs. Long argument & return records 12 words or more forces long arg record long arg record is separately allocated and is passed by reference similar hack for long return records destination must 1. copy the long arg record 2. free the long arg record Start traps detected when CB is odd cause entry 0 procedure to be run no locking performed further calls do not trap `PrincOpsXferSlides.tioga August 5, 1986 Russ Atkinson (RRA) August 8, 1986 7:55:01 pm PDT ΚΦ–"slides" style– PressFonts˜Iunleaded•Mark insideFooteršΡdis™– outsideFooterš™Icode™1—title˜raggedšΟb˜N˜˜N˜—˜ N˜ —N˜!N˜ ——˜šž˜N˜N˜*N˜-N˜'N˜—šž˜N˜ N˜#N˜N˜*——šœ˜šž0˜0Nšœ#˜#N˜—˜N˜N˜N˜—˜N˜N˜N˜ N˜ N˜!N˜N˜N˜——˜ šž#˜#N˜N˜&N˜-N˜N˜N˜N˜ N˜—šž3˜3N˜N˜——˜šž%˜%N˜N˜ N˜N˜ N˜ N˜N˜ N˜ ——˜šž ˜ N˜-˜,N˜—N˜0—˜N˜'N˜0N˜——˜ šž˜N˜/N˜/—šž(˜(N˜'N˜BN˜$N˜H—šž ˜ N˜N˜!N˜N˜———…—  F