Add __STDC_VERSION__ macro.

With the addition of designated initializers, ORCA/C now supports all the major mandatory language features added between C90 and C17, apart from those made optional by C11. There are still various small areas of nonconformance and a number of missing library functions, but at this point it is reasonable for ORCA/C to report itself as being a C17 implementation.
This commit is contained in:
Stephen Heumann 2022-12-04 22:18:50 -06:00
parent 2550081517
commit c06d78bb5e
3 changed files with 25 additions and 2 deletions

View File

@ -18,7 +18,7 @@ uses CCommon, MM, Scanner, Symbol, CGI;
{$segment 'HEADER'} {$segment 'HEADER'}
const const
symFileVersion = 34; {version number of .sym file format} symFileVersion = 35; {version number of .sym file format}
var var
inhibitHeader: boolean; {should .sym includes be blocked?} inhibitHeader: boolean; {should .sym includes be blocked?}

View File

@ -275,6 +275,7 @@ var
ispstring: boolean; {is the current string a p-string?} ispstring: boolean; {is the current string a p-string?}
saveNumber: boolean; {save the characters in a number?} saveNumber: boolean; {save the characters in a number?}
skipping: boolean; {skipping tokens?} skipping: boolean; {skipping tokens?}
stdcVersionStr: string[8]; {string form of __STDC_VERSION__}
timeStr: longStringPtr; {macro time string} timeStr: longStringPtr; {macro time string}
tokenColumn: 0..maxint; {column number at start of this token} tokenColumn: 0..maxint; {column number at start of this token}
tokenLine: 0..maxint4; {line number at start of this token} tokenLine: 0..maxint4; {line number at start of this token}
@ -2033,6 +2034,16 @@ if macro^.readOnly then begin {handle special macros}
end {else} end {else}
end; end;
9: begin {__STDC_VERSION__}
token.kind := longconst;
token.class := longconstant;
token.lval := 201710;
token.numString := @stdcVersionStr;
stdcVersionStr := '201710L';
tokenStart := @stdcVersionStr[1];
tokenEnd := pointer(ord4(tokenStart)+length(stdcVersionStr));
end;
8: begin {_Pragma pseudo-macro} 8: begin {_Pragma pseudo-macro}
if (parms <> nil) and (parms^.tokens <> nil) if (parms <> nil) and (parms^.tokens <> nil)
and (parms^.tokens^.token.kind = stringconst) and (parms^.tokens^.token.kind = stringconst)
@ -4625,6 +4636,16 @@ mp^.algorithm := 7;
bp := pointer(ord4(macros) + hash(mp^.name)); bp := pointer(ord4(macros) + hash(mp^.name));
mp^.next := bp^; mp^.next := bp^;
bp^ := mp; bp^ := mp;
new(mp); {__STDC_VERSION__}
mp^.name := @'__STDC_VERSION__';
mp^.parameters := -1;
mp^.tokens := nil;
mp^.readOnly := true;
mp^.saved := true;
mp^.algorithm := 9;
bp := pointer(ord4(macros) + hash(mp^.name));
mp^.next := bp^;
bp^ := mp;
new(mp); {_Pragma pseudo-macro} new(mp); {_Pragma pseudo-macro}
mp^.name := @'_Pragma'; mp^.name := @'_Pragma';
mp^.parameters := 1; mp^.parameters := 1;

View File

@ -489,7 +489,7 @@ These behave the same as the existing tokens [, ], {, }, #, and ## (respectively
16. (C99) Any or all of the arguments to a function-like macro can now be empty. (This happened to work previously in some cases but not others.) 16. (C99) Any or all of the arguments to a function-like macro can now be empty. (This happened to work previously in some cases but not others.)
17. (C99 and C11) Several new predefined macros have been added: 17. (C99, C11, and C17) Several new predefined macros have been added:
__STDC_HOSTED__ normally expands to the integer constant 1, indicating that ORCA/C is a hosted implementation of the C language (where the full standard library is available and the program starts by executing the main function). However, it will expand to 0 if one of the pragmas for special types of programs with different entry points has been used. __STDC_HOSTED__ normally expands to the integer constant 1, indicating that ORCA/C is a hosted implementation of the C language (where the full standard library is available and the program starts by executing the main function). However, it will expand to 0 if one of the pragmas for special types of programs with different entry points has been used.
@ -497,6 +497,8 @@ __STDC_NO_ATOMICS__, __STDC_NO_COMPLEX__, __STDC_NO_THREADS__, and __STDC_NO_VLA
__STDC_UTF_16__ and __STDC_UTF_32__ expand to the integer constant 1. These indicate that the char16_t and char32_t types (discussed below) use UTF-16 and UTF-32 encodings. __STDC_UTF_16__ and __STDC_UTF_32__ expand to the integer constant 1. These indicate that the char16_t and char32_t types (discussed below) use UTF-16 and UTF-32 encodings.
__STDC_VERSION__ expands to the constant 201710L, indicating that ORCA/C supports the C17 language standard. ORCA/C now supports all the major language features required by C17, although there are still some missing library functions and a few other small deviations from the standard.
18. (C99) The _Bool type is now supported. This is a boolean type that can hold the values 0 or 1. When a value of another type is converted to _Bool, the result is 0 if the value compares equal to 0, or 1 otherwise. 18. (C99) The _Bool type is now supported. This is a boolean type that can hold the values 0 or 1. When a value of another type is converted to _Bool, the result is 0 if the value compares equal to 0, or 1 otherwise.
19. (C99) The types "long long" and "unsigned long long" are now supported. In ORCA/C, these are 64-bit integer types, capable of representing a larger range of values than the existing smaller integer types. All operations that can be done on other integer types can now be done on these types as well. 19. (C99) The types "long long" and "unsigned long long" are now supported. In ORCA/C, these are 64-bit integer types, capable of representing a larger range of values than the existing smaller integer types. All operations that can be done on other integer types can now be done on these types as well.