mirror of
https://github.com/vishapoberon/compiler.git
synced 2026-04-06 15:42:25 +00:00
Restore result variable just for issue #40 using same fix as J. Templ.
This commit is contained in:
parent
6a4748e2af
commit
03556336ce
22 changed files with 171 additions and 5 deletions
|
|
@ -950,6 +950,11 @@ MODULE OPC; (* copyright (c) J. Templ 12.7.95 / 3.7.96 *)
|
|||
OPM.WriteLn;
|
||||
END DefineInter;
|
||||
|
||||
PROCEDURE NeedsRetval*(proc: OPT.Object): BOOLEAN; (* aux. variable __retval needed for return *)
|
||||
BEGIN (* simple rule; ignores DUPlicated value arrays because they use alloca. *)
|
||||
RETURN (proc^.typ # OPT.notyp) & ~proc^.scope^.leaf
|
||||
END NeedsRetval;
|
||||
|
||||
PROCEDURE EnterProc* (proc: OPT.Object);
|
||||
VAR var, scope: OPT.Object; typ: OPT.Struct; dim: INTEGER;
|
||||
BEGIN
|
||||
|
|
@ -962,6 +967,7 @@ MODULE OPC; (* copyright (c) J. Templ 12.7.95 / 3.7.96 *)
|
|||
BegStat; OPM.WriteString('struct '); OPM.WriteStringVar (scope^.name);
|
||||
OPM.Write(' '); OPM.WriteString(LocalScope); EndStat
|
||||
END ;
|
||||
IF NeedsRetval(proc) THEN BegStat; Ident(proc^.typ^.strobj); OPM.WriteString(" __retval"); EndStat END;
|
||||
var := proc^.link;
|
||||
WHILE var # NIL DO (* declare copy of fixed size value array parameters *)
|
||||
IF (var^.typ^.comp = OPT.Array) & (var^.mode = OPT.Var) THEN
|
||||
|
|
|
|||
|
|
@ -875,6 +875,16 @@ MODULE OPV; (* J. Templ 16.2.95 / 3.7.96
|
|||
END
|
||||
| OPT.Nreturn: IF OPM.level = 0 THEN
|
||||
IF OPM.mainprog IN OPM.Options THEN OPM.WriteString("__FINI") ELSE OPM.WriteString("__ENDMOD") END
|
||||
ELSIF OPC.NeedsRetval(outerProc) THEN
|
||||
OPM.WriteString("__retval = ");
|
||||
IF (n^.left^.typ^.form = OPT.Pointer) & (n^.obj^.typ # n^.left^.typ) THEN
|
||||
OPM.WriteString("(void*)"); expr(n^.left, 10)
|
||||
ELSE
|
||||
expr(n^.left, MinPrec)
|
||||
END ;
|
||||
OPC.EndStat;
|
||||
OPC.BegStat; OPC.ExitProc(outerProc, FALSE, FALSE); OPC.EndStat;
|
||||
OPC.BegStat; OPM.WriteString("return __retval");
|
||||
ELSE
|
||||
OPC.ExitProc(outerProc, FALSE, FALSE);
|
||||
OPM.WriteString("return");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue