|
|
@@ -68,6 +68,7 @@ VAR
|
|
|
stkLink : ARRAY [0 .. 15] OF QVal; (* per-call static links *)
|
|
|
stkExt : ARRAY [0 .. 15] OF BOOLEAN; (* per-call external flag *)
|
|
|
stkInd : ARRAY [0 .. 15] OF BOOLEAN; (* per-call indirect flag *)
|
|
|
+ stkHasLink : ARRAY [0 .. 15] OF BOOLEAN; (* per-call hidden static link *)
|
|
|
outSel : CARDINAL; (* 0 = file, else nestBufs[outSel-1] *)
|
|
|
nInit : CARDINAL;
|
|
|
initNames : ARRAY [0 .. 31] OF QVal;
|
|
|
@@ -1275,9 +1276,14 @@ PROCEDURE BeginFunc (mangled: ARRAY OF CHAR);
|
|
|
Cpy(funcName, mangled);
|
|
|
hbuf[0] := CHR(0);
|
|
|
NewTemp(slTmp);
|
|
|
- HApp("l ");
|
|
|
- HApp(slTmp);
|
|
|
- hdrComma := TRUE;
|
|
|
+ hdrComma := FALSE;
|
|
|
+ IF funcDepth > 1 THEN
|
|
|
+ (* Nested procedures still take the parent frame link; top-level
|
|
|
+ procedures use the C-visible argument list. *)
|
|
|
+ HApp("l ");
|
|
|
+ HApp(slTmp);
|
|
|
+ hdrComma := TRUE
|
|
|
+ END;
|
|
|
IF funcDepth > 1 THEN
|
|
|
outSel := funcDepth - 1;
|
|
|
IF outSel > HIGH(nestBufs) + 1 THEN
|
|
|
@@ -1345,7 +1351,9 @@ PROCEDURE EndFuncHeader;
|
|
|
Cpy(scopeLink[scopeTop - 1], lk);
|
|
|
Revive;
|
|
|
W(" "); W(lk); W(" =l alloc8 520"); WL("");
|
|
|
- W(" storel "); W(slTmp); W(", "); WL(lk);
|
|
|
+ W(" storel ");
|
|
|
+ IF funcDepth > 1 THEN W(slTmp) ELSE W("0") END;
|
|
|
+ W(", "); WL(lk);
|
|
|
i := 0;
|
|
|
WHILE i < nPar DO
|
|
|
cls := SymTab.ClassOf(parTyp[i]);
|
|
|
@@ -1511,6 +1519,7 @@ PROCEDURE CallBeginInd (callee: ARRAY OF CHAR; resT: INTEGER;
|
|
|
stkRes[callDepth] := ResClass(resT);
|
|
|
stkExt[callDepth] := isExt;
|
|
|
stkInd[callDepth] := TRUE;
|
|
|
+ stkHasLink[callDepth] := FALSE;
|
|
|
Cpy(stkLink[callDepth], "0");
|
|
|
stkArg[callDepth][0] := CHR(0);
|
|
|
stkN[callDepth] := 0;
|
|
|
@@ -1560,13 +1569,13 @@ PROCEDURE CallBegin (mangled: ARRAY OF CHAR; resT: INTEGER;
|
|
|
stkRes[callDepth] := ResClass(resT);
|
|
|
stkExt[callDepth] := isExt;
|
|
|
stkInd[callDepth] := FALSE;
|
|
|
+ stkHasLink[callDepth] := FALSE;
|
|
|
stkArg[callDepth][0] := CHR(0);
|
|
|
stkN[callDepth] := 0;
|
|
|
- IF isExt THEN
|
|
|
- Cpy(stkLink[callDepth], "0")
|
|
|
- ELSIF funcDepth = 0 THEN
|
|
|
+ IF isExt OR (fdep = 0) THEN
|
|
|
Cpy(stkLink[callDepth], "0")
|
|
|
ELSE
|
|
|
+ stkHasLink[callDepth] := TRUE;
|
|
|
walks := VAL(INTEGER, funcDepth) - VAL(INTEGER, fdep);
|
|
|
Cpy(cur, scopeLink[scopeTop - 1]);
|
|
|
WHILE walks > 0 DO
|
|
|
@@ -1644,8 +1653,8 @@ PROCEDURE CallEnd (wantRes: BOOLEAN; VAR q: QVal);
|
|
|
ELSE
|
|
|
W(" call $"); W(funcName); W("(")
|
|
|
END;
|
|
|
- IF stkExt[d] THEN
|
|
|
- W(body) (* C callee: no static link *)
|
|
|
+ IF stkExt[d] OR NOT stkHasLink[d] THEN
|
|
|
+ W(body) (* C/top-level callee: no static link *)
|
|
|
ELSE
|
|
|
W("l "); W(stkLink[d]);
|
|
|
IF body[0] # CHR(0) THEN W(", "); W(body) END
|