PrincOpsXferSlides.tioga
August 5, 1986
Russ Atkinson (RRA) August 8, 1986 7:55:01 pm PDT
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