From a75d18a45c312ade3342f8da08cb232007da457a Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Mon, 26 Dec 2016 18:17:02 -0600 Subject: [PATCH] Make the main function return 0 if execution reaches the closing brace of its body. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is required by C99 and later. It’s not required by C89, but it’s allowed and produces more predictable behavior. --- Parser.pas | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Parser.pas b/Parser.pas index 5dafa04..7fd1956 100644 --- a/Parser.pas +++ b/Parser.pas @@ -291,6 +291,22 @@ stPtr := statementList; {pop the statement record} statementList := stPtr^.next; doingFunction := statementList <> nil; {see if we're done with the function} if not doingFunction then begin {if so, finish it off} + if doingMain then begin {executing to the end of main returns 0} + if fType^.kind = scalarType then begin + if fType^.baseType in [cgByte,cgUByte,cgWord,cgUWord] then begin + Gen1t(pc_ldc, 0, fType^.baseType); + Gen2t(pc_str, 0, 0, fType^.baseType); + end {if} + else if fType^.baseType in [cgLong,cgULong] then begin + GenLdcLong(0); + Gen2t(pc_str, 0, 0, fType^.baseType); + end; {else if} + end {if} + else if fType^.kind = enumType then begin + Gen1t(pc_ldc, 0, cgWord); + Gen2t(pc_str, 0, 0, cgWord); + end; {else if} + end; {if} Gen1(dc_lab, returnLabel); with fType^ do {generate the pc_ret instruction} case kind of