From 5d64436e6e61e5eaa43e011f706a6197b836a2ac Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sat, 7 Mar 2020 15:51:29 -0600 Subject: [PATCH] Implement __STDC_HOSTED__ macro (from C99). This is normally 1 (indicating a hosted implementation, where the full standard library is available and the program starts by executing main()), but it is 0 if one of the pragmas for special types of programs with different entry points has been used. --- Scanner.pas | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/Scanner.pas b/Scanner.pas index 3a2c18f..d5f0ece 100644 --- a/Scanner.pas +++ b/Scanner.pas @@ -253,7 +253,8 @@ var needWriteLine: boolean; {is there a line that needs to be written?} wroteLine: boolean; {has the current line already been written?} numErr: 0..maxErr; {number of errors in this line} - oneStr: string[2]; {string form of __STDC__} + oneStr: string[2]; {string form of __STDC__, etc.} + zeroStr: string[2]; {string form of __STDC_HOSTED__ when not hosted} ispstring: boolean; {is the current string a p-string?} saveNumber: boolean; {save the characters in a number?} skipping: boolean; {skipping tokens?} @@ -1492,7 +1493,29 @@ if macro^.readOnly then begin {handle special macros} token.sval := versionStrL; tokenStart := @versionStrL^.str; tokenEnd := pointer(ord4(tokenStart)+versionStrL^.length); - end; + end; + + 7: begin {__STDC_HOSTED__} + if isNewDeskAcc or isClassicDeskAcc or isCDev or isNBA or isXCMD then + begin + token.kind := intConst; + token.numString := @zeroStr; + token.class := intConstant; + token.ival := 0; + zeroStr := '0'; + tokenStart := @zeroStr[1]; + tokenEnd := pointer(ord4(tokenStart)+1); + end {if} + else begin + token.kind := intConst; + token.numString := @oneStr; + token.class := intConstant; + token.ival := 1; + oneStr := '1'; + tokenStart := @oneStr[1]; + tokenEnd := pointer(ord4(tokenStart)+1); + end {else} + end; otherwise: Error(57); @@ -3788,6 +3811,15 @@ mp^.algorithm := 5; bp := pointer(ord4(macros) + hash(mp^.name)); mp^.next := bp^; bp^ := mp; +new(mp); {__STDC_HOSTED__} +mp^.name := @'__STDC_HOSTED__'; +mp^.parameters := -1; +mp^.tokens := nil; +mp^.readOnly := true; +mp^.algorithm := 7; +bp := pointer(ord4(macros) + hash(mp^.name)); +mp^.next := bp^; +bp^ := mp; SetDateTime; {set up the macro date/time strings} {set up the version string} versionStrL := pointer(GMalloc(3 + length(versionStr)));