2017-10-21 23:40:19 +00:00
|
|
|
{$optimize 7}
|
|
|
|
{---------------------------------------------------------------}
|
|
|
|
{ }
|
|
|
|
{ CCommon }
|
|
|
|
{ }
|
|
|
|
{ Common declarations and global data for the compiler. }
|
|
|
|
{ }
|
|
|
|
{ Variables: }
|
|
|
|
{ }
|
|
|
|
{ bofPtr - pointer to the start of sourceFile }
|
|
|
|
{ chPtr - pointer to the next character in the file }
|
|
|
|
{ codegenStarted - have we started the code generator? }
|
|
|
|
{ debugType - line number debug types }
|
|
|
|
{ doingFunction - true if processing a function }
|
|
|
|
{ doingParameters - are we processing parm definitions? }
|
|
|
|
{ doingPartial - are we doing a partial compile? }
|
|
|
|
{ enterEditor - enter editor on terminal errors? }
|
|
|
|
{ expandMacros - should macros be expanded? }
|
|
|
|
{ firstPtr - points to first char in current line }
|
|
|
|
{ gotoList - list of goto labels }
|
|
|
|
{ includeFile - include file name (for return from includes) }
|
|
|
|
{ infoString - language specific command line info }
|
|
|
|
{ lastLine - last line number used by pc_nam }
|
|
|
|
{ liDCB - get/set LInfo DCB }
|
|
|
|
{ lineNumber - source line number }
|
|
|
|
{ lint - lint flags }
|
|
|
|
{ list - generate source listing? }
|
|
|
|
{ memoryCompile - memory based compile? }
|
|
|
|
{ nameFound - has a pc_nam been generated? }
|
|
|
|
{ numErrors - number of errors in the program }
|
|
|
|
{ objFile - object file name }
|
|
|
|
{ oldincludeFile - previous includeFile value }
|
|
|
|
{ partialFile - partial compile list }
|
|
|
|
{ sourceFile - source file name }
|
|
|
|
{ terminalErrors - are all errors terminal? }
|
|
|
|
{ traceBack - generate traceback code? }
|
|
|
|
{ useGlobalPool - use global (or local) string pool? }
|
|
|
|
{ wait - wait for keypress after errors? }
|
|
|
|
{ }
|
|
|
|
{ doDispose - dispose of the expression tree as we go? }
|
|
|
|
{ expressionValue - the expression evaluator returns the }
|
|
|
|
{ value of constant expressions in this variable }
|
|
|
|
{ expressionType - the type of the expression }
|
|
|
|
{ expressionTree - for non-constant initializers }
|
2020-01-29 23:09:52 +00:00
|
|
|
{ isConstant - is the initializer expression constant? }
|
2019-09-29 08:20:16 +00:00
|
|
|
{ typeSpec - type given by the last declaration specifiers, }
|
|
|
|
{ specifier-qualifier list, or type name evaluated }
|
2017-10-21 23:40:19 +00:00
|
|
|
{ }
|
|
|
|
{ External Subroutines: }
|
|
|
|
{ }
|
|
|
|
{ CheckGotoList - Make sure all labels have been defined }
|
|
|
|
{ ClearHourGlass - Erase the hourglass from the screen }
|
|
|
|
{ CopyLongString - copy a long string }
|
|
|
|
{ CopyString - copy a string }
|
|
|
|
{ DrawHourGlass - Draw the hourglass on the screen }
|
|
|
|
{ ExitToEditor - do an error exit to the editor }
|
|
|
|
{ GetLocalLabel - get the next local label number }
|
|
|
|
{ Hash - find hash displacement }
|
|
|
|
{ InitCCommon - Initialize this module }
|
|
|
|
{ ReadFile - read a file }
|
|
|
|
{ Spin - Spin the spinner }
|
|
|
|
{ StopSpin - Stop the spinner }
|
|
|
|
{ SystemError - intercept run time compiler errors }
|
|
|
|
{ TermError - flag a terminal error }
|
|
|
|
{ }
|
|
|
|
{---------------------------------------------------------------}
|
|
|
|
|
|
|
|
unit CCommon;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
2017-06-19 03:07:32 +00:00
|
|
|
{$segment 'CC'}
|
|
|
|
|
2017-10-21 23:40:19 +00:00
|
|
|
const
|
|
|
|
{hashsize appears in CCOMMON.ASM}
|
|
|
|
hashSize = 876; {# hash buckets - 1}
|
|
|
|
hashSize2 = 1753; {# hash buckets * 2 - 1}
|
|
|
|
maxLine = 255; {max length of a line}
|
|
|
|
maxPath = 255; {max length of a path name}
|
|
|
|
{NOTE: maxPath is used in Scanner.asm}
|
|
|
|
longstringlen = 4000; {max length of a string constant}
|
|
|
|
|
|
|
|
minChar = 0; {min ordinal value of source character}
|
|
|
|
maxChar = 255; {max ordinal value of source character}
|
|
|
|
|
|
|
|
{lint masks}
|
|
|
|
{----------}
|
|
|
|
lintUndefFn = $0001; {flag use of undefined functions}
|
|
|
|
lintNoFnType = $0002; {flag functions with no type}
|
|
|
|
lintNotPrototyped = $0004; {flag functions with no prototypes}
|
2018-09-06 04:43:58 +00:00
|
|
|
lintPragmas = $0008; {flag unknown pragmas}
|
2018-03-24 01:51:27 +00:00
|
|
|
lintPrintf = $0010; {check printf/scanf format flags}
|
2018-09-06 04:43:58 +00:00
|
|
|
lintOverflow = $0020; {check for overflows}
|
2020-01-30 00:33:19 +00:00
|
|
|
lintC99Syntax = $0040; {check for syntax that C99 disallows}
|
2020-02-02 19:50:15 +00:00
|
|
|
lintReturn = $0080; {flag issues with how functions return}
|
2017-10-21 23:40:19 +00:00
|
|
|
|
|
|
|
{bit masks for GetLInfo flags}
|
|
|
|
{----------------------------}
|
|
|
|
flag_d = $10000000; {generate debug code?}
|
|
|
|
flag_e = $08000000; {abort to editor on terminal error?}
|
|
|
|
flag_i = $00800000; {ignore symbol files?}
|
|
|
|
flag_l = $00100000; {list source lines?}
|
|
|
|
flag_m = $00080000; {memory based compile?}
|
|
|
|
flag_o = $00020000; {optimize?}
|
|
|
|
flag_p = $00010000; {print progress info?}
|
|
|
|
flag_r = $00004000; {rebuild symbol files?}
|
|
|
|
flag_s = $00002000; {list symbol tables?}
|
|
|
|
flag_t = $00001000; {treat all errors as terminal?}
|
|
|
|
flag_w = $00000200; {wait when an error is found?}
|
|
|
|
|
2021-09-15 23:34:27 +00:00
|
|
|
versionStr = '2.2.0 B6 dev'; {compiler version}
|
2017-10-21 23:40:19 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
{Misc.}
|
|
|
|
{-----}
|
|
|
|
long = record lsw,msw: integer; end; {for extracting words from longints}
|
2021-02-04 05:11:23 +00:00
|
|
|
longlong = record lo,hi: longint; end; {64-bit integer representation}
|
2017-10-21 23:40:19 +00:00
|
|
|
|
|
|
|
cString = packed array [1..256] of char; {null terminated string}
|
|
|
|
cStringPtr = ^cString;
|
|
|
|
longString = record {long null terminated string}
|
|
|
|
length: integer;
|
|
|
|
str: packed array [1..longstringlen] of char;
|
|
|
|
end;
|
|
|
|
longStringPtr = ^longString;
|
|
|
|
pString = packed array [0..maxLine] of char; {length string}
|
|
|
|
stringPtr = ^pString;
|
|
|
|
ptr = ^byte; {general purpose pointer}
|
2020-01-29 23:09:52 +00:00
|
|
|
handle = ^ptr; {general purpose handle}
|
2017-10-21 23:40:19 +00:00
|
|
|
|
|
|
|
gsosInString = record
|
|
|
|
size: integer;
|
|
|
|
theString: packed array [1..maxPath] of char;
|
|
|
|
end;
|
|
|
|
gsosInStringPtr = ^gsosInString;
|
|
|
|
|
|
|
|
{GS/OS class 1 output string}
|
|
|
|
gsosOutString = record
|
|
|
|
maxSize: integer;
|
|
|
|
theString: gsosInString;
|
|
|
|
end;
|
|
|
|
gsosOutStringPtr = ^gsosOutString;
|
|
|
|
|
|
|
|
{ The base types include two main categories. The values starting }
|
2020-01-29 23:09:52 +00:00
|
|
|
{ with cg are defined in the code generator, and may be passed to the }
|
2017-10-21 23:40:19 +00:00
|
|
|
{ code generator for resolution. The cc types are used internally in }
|
2020-01-29 23:09:52 +00:00
|
|
|
{ the compiler. Any values whose type is cc must be resolved to one }
|
2017-10-21 23:40:19 +00:00
|
|
|
{ of the cg types before the code generator is called. }
|
|
|
|
|
2021-01-30 05:22:28 +00:00
|
|
|
baseTypeEnum = (cgByte,cgUByte,cgWord,cgUWord,cgLong,cgULong,
|
2017-10-21 23:40:19 +00:00
|
|
|
cgReal,cgDouble,cgComp,cgExtended,cgString,
|
2021-01-30 05:22:28 +00:00
|
|
|
cgVoid,cgQuad,cgUQuad,ccPointer);
|
2017-10-21 23:40:19 +00:00
|
|
|
|
2020-03-01 04:43:29 +00:00
|
|
|
{ Basic types (plus the void type) as defined by the C language. }
|
|
|
|
{ This differs from baseTypeEnum in that different types with the }
|
|
|
|
{ same representation are distinguished from each other. }
|
2021-01-24 19:31:12 +00:00
|
|
|
{ (ctInt32/ctUInt32 are 32-bit int types when using #pragma unix 1.) }
|
2020-03-01 04:43:29 +00:00
|
|
|
|
|
|
|
cTypeEnum = (ctChar, ctSChar, ctUChar, ctShort, ctUShort, ctInt, ctUInt,
|
|
|
|
ctLong, ctULong, ctFloat, ctDouble, ctLongDouble, ctComp,
|
2021-01-30 02:50:21 +00:00
|
|
|
ctVoid, ctInt32, ctUInt32, ctBool, ctLongLong, ctULongLong);
|
2020-03-01 04:43:29 +00:00
|
|
|
|
2017-10-21 23:40:19 +00:00
|
|
|
{tokens}
|
|
|
|
{------}
|
|
|
|
{Note: tokenEnum is duplicated in }
|
|
|
|
{ Table.asm }
|
|
|
|
tokenEnum = ( {enumeration of the tokens}
|
|
|
|
ident, {identifiers}
|
|
|
|
{constants}
|
2021-03-07 19:38:21 +00:00
|
|
|
{Note: compconst and charconst, etc. }
|
|
|
|
{ are not found in program code. }
|
|
|
|
{ They are created only by casts. }
|
2021-02-04 05:11:23 +00:00
|
|
|
intconst,uintconst,longconst,ulongconst,longlongconst,
|
2021-03-07 06:48:51 +00:00
|
|
|
ulonglongconst,floatconst,doubleconst,extendedconst,compconst,
|
2021-03-07 19:38:21 +00:00
|
|
|
charconst,scharconst,ucharconst,stringconst,
|
2017-10-21 23:40:19 +00:00
|
|
|
{reserved words}
|
2020-01-04 04:47:53 +00:00
|
|
|
_Alignassy,_Alignofsy,_Atomicsy,_Boolsy,_Complexsy,
|
|
|
|
_Genericsy,_Imaginarysy,_Noreturnsy,_Static_assertsy,_Thread_localsy,
|
2017-10-21 23:40:19 +00:00
|
|
|
autosy,asmsy,breaksy,casesy,charsy,
|
|
|
|
continuesy,constsy,compsy,defaultsy,dosy,
|
|
|
|
doublesy,elsesy,enumsy,externsy,extendedsy,
|
|
|
|
floatsy,forsy,gotosy,ifsy,intsy,
|
2020-01-04 04:47:53 +00:00
|
|
|
inlinesy,longsy,pascalsy,registersy,restrictsy,
|
|
|
|
returnsy,shortsy,sizeofsy,staticsy,structsy,
|
|
|
|
switchsy,segmentsy,signedsy,typedefsy,unionsy,
|
|
|
|
unsignedsy,voidsy,volatilesy,whilesy,
|
2017-10-21 23:40:19 +00:00
|
|
|
{reserved symbols}
|
|
|
|
excch,percentch,carotch,andch,asteriskch,
|
|
|
|
minusch,plusch,eqch,tildech,barch,
|
|
|
|
dotch,ltch,gtch,slashch,questionch,
|
|
|
|
lparench,rparench,lbrackch,rbrackch,lbracech,
|
|
|
|
rbracech,commach,semicolonch,colonch,poundch,
|
|
|
|
minusgtop,plusplusop,minusminusop,ltltop,gtgtop,
|
|
|
|
lteqop,gteqop,eqeqop,exceqop,andandop,
|
|
|
|
barbarop,pluseqop,minuseqop,asteriskeqop,slasheqop,
|
|
|
|
percenteqop,ltlteqop,gtgteqop,andeqop,caroteqop,
|
|
|
|
bareqop,poundpoundop,
|
|
|
|
eolsy,eofsy, {control characters}
|
|
|
|
typedef, {user types}
|
|
|
|
uminus,uand,uasterisk, {converted operations}
|
|
|
|
parameteroper,castoper,opplusplus,opminusminus,
|
|
|
|
macroParm); {macro language}
|
|
|
|
|
|
|
|
{Note: this enumeration also }
|
|
|
|
{ appears in TABLE.ASM, }
|
|
|
|
{ SCANNER.asm }
|
|
|
|
charEnum = {character kinds}
|
|
|
|
(illegal,ch_special,ch_dash,ch_plus,ch_lt,ch_gt,ch_eq,ch_exc,
|
|
|
|
ch_and,ch_bar,ch_dot,ch_white,ch_eol,ch_eof,ch_char,ch_string,
|
2020-01-05 03:49:50 +00:00
|
|
|
ch_asterisk,ch_slash,ch_percent,ch_carot,ch_pound,ch_colon,
|
2020-01-20 23:22:06 +00:00
|
|
|
ch_backslash,letter,digit);
|
2017-10-21 23:40:19 +00:00
|
|
|
|
|
|
|
tokenSet = set of tokenEnum;
|
|
|
|
tokenClass = (reservedWord,reservedSymbol,identifier,intConstant,longConstant,
|
2021-03-05 05:52:41 +00:00
|
|
|
longlongConstant,realConstant,stringConstant,macroParameter);
|
2017-10-21 23:40:19 +00:00
|
|
|
identPtr = ^identRecord; {^ to a symbol table entry}
|
|
|
|
tokenType = record {a token}
|
|
|
|
kind: tokenEnum; {kind of token}
|
|
|
|
numString: stringPtr; {chars in number (macros only)}
|
|
|
|
case class: tokenClass of {token info}
|
|
|
|
reservedWord : ();
|
2020-01-05 03:49:50 +00:00
|
|
|
reservedSymbol: (isDigraph: boolean);
|
2017-10-21 23:40:19 +00:00
|
|
|
identifier : (name: stringPtr;
|
|
|
|
symbolPtr: identPtr);
|
|
|
|
intConstant : (ival: integer);
|
|
|
|
longConstant : (lval: longint);
|
2021-02-04 05:11:23 +00:00
|
|
|
longlongConstant: (qval: longlong);
|
2021-03-05 05:52:41 +00:00
|
|
|
realConstant : (rval: extended);
|
2017-10-21 23:40:19 +00:00
|
|
|
stringConstant: (sval: longstringPtr;
|
|
|
|
ispstring: boolean);
|
|
|
|
macroParameter: (pnum: integer);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{expressions}
|
|
|
|
{-----------}
|
|
|
|
expressionKind = ( {kinds of expressions}
|
|
|
|
preprocessorExpression, {used by preprocessor commands}
|
|
|
|
arrayExpression, {array subscripts, case labels,
|
|
|
|
bit-field lengths, enum values}
|
|
|
|
initializerExpression, {static variable initializers}
|
|
|
|
autoInitializerExpression, {auto variable initializers}
|
|
|
|
normalExpression); {for run-time evaluation}
|
|
|
|
typePtr = ^typeRecord;
|
|
|
|
tokenPtr = ^tokenRecord;
|
|
|
|
tokenRecord = record {for operation, operand stacks}
|
|
|
|
next: tokenPtr; {next token on the stack}
|
|
|
|
left,middle,right: tokenPtr; {operand paths for operations}
|
|
|
|
token: tokenType; {token at this node/leaf}
|
|
|
|
case boolean of
|
|
|
|
true : (id: identPtr;); {^symbol table entry for this operand}
|
|
|
|
false: (castType: typePtr;); {cast type (for type casts only)}
|
|
|
|
end;
|
|
|
|
|
|
|
|
{goto label list}
|
|
|
|
{---------------}
|
|
|
|
gotoPtr = ^gotoRecord;
|
|
|
|
gotoRecord = record
|
|
|
|
{Note: if the size changes, see gotoSize}
|
|
|
|
next: gotoPtr;
|
|
|
|
name: stringPtr;
|
|
|
|
lab: integer;
|
|
|
|
defined: boolean;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{symbol tables}
|
|
|
|
{-------------}
|
|
|
|
{classes of variables in the sym. tbl}
|
|
|
|
spaceType = (tagSpace,variableSpace,allSpaces,fieldListSpace);
|
|
|
|
|
|
|
|
parameterPtr = ^parameterRecord; {prototype parameter list}
|
|
|
|
parameterRecord = record
|
|
|
|
next: parameterPtr;
|
|
|
|
parameter: identPtr;
|
|
|
|
parameterType: typePtr;
|
|
|
|
end;
|
|
|
|
|
Record volatile and restrict qualifiers in types.
These are needed to correctly distinguish pointer types in _Generic. They should also be used for type compatibility checks in other contexts, but currently are not.
This also fixes a couple small problems related to type qualifiers:
*restrict was not allowed to appear after * in type-names
*volatile status was not properly recorded in sym files
Here is an example of using _Generic to distinguish pointer types based on the qualifiers of the pointed-to type:
#include <stdio.h>
#define f(e) _Generic((e),\
int * restrict *: 1,\
int * volatile const *: 2,\
int **: 3,\
default: 0)
#define g(e) _Generic((e),\
int *: 1,\
const int *: 2,\
volatile int *: 3,\
default: 0)
int main(void) {
int * restrict * p1;
int * volatile const * p2;
int * const * p3;
// should print "1 2 0 1"
printf("%i %i %i %i\n", f(p1), f(p2), f(p3), f((int * restrict *)0));
int *q1;
const int *q2;
volatile int *q3;
const volatile int *q4;
// should print "1 2 3 0"
printf("%i %i %i %i\n", g(q1), g(q2), g(q3), g(q4));
}
Here is an example of a problem resulting from volatile not being recorded in sym files (if a sym file was present, the read of x was lifted out of the loop):
#pragma optimize -1
static volatile int x;
#include <stdio.h>
int main(void) {
int y;
for (unsigned i = 0; i < 100; i++) {
y = x*2 + 7;
}
}
2021-08-30 02:10:20 +00:00
|
|
|
typeQualifierEnum = (tqConst, tqVolatile, tqRestrict);
|
|
|
|
typeQualifierSet = set of typeQualifierEnum;
|
|
|
|
|
2017-10-21 23:40:19 +00:00
|
|
|
typeKind = (scalarType,arrayType,pointerType,functionType,enumType,
|
|
|
|
enumConst,structType,unionType,definedType);
|
|
|
|
typeRecord = record {type}
|
|
|
|
size: longint; {size of the type in bytes}
|
Record volatile and restrict qualifiers in types.
These are needed to correctly distinguish pointer types in _Generic. They should also be used for type compatibility checks in other contexts, but currently are not.
This also fixes a couple small problems related to type qualifiers:
*restrict was not allowed to appear after * in type-names
*volatile status was not properly recorded in sym files
Here is an example of using _Generic to distinguish pointer types based on the qualifiers of the pointed-to type:
#include <stdio.h>
#define f(e) _Generic((e),\
int * restrict *: 1,\
int * volatile const *: 2,\
int **: 3,\
default: 0)
#define g(e) _Generic((e),\
int *: 1,\
const int *: 2,\
volatile int *: 3,\
default: 0)
int main(void) {
int * restrict * p1;
int * volatile const * p2;
int * const * p3;
// should print "1 2 0 1"
printf("%i %i %i %i\n", f(p1), f(p2), f(p3), f((int * restrict *)0));
int *q1;
const int *q2;
volatile int *q3;
const volatile int *q4;
// should print "1 2 3 0"
printf("%i %i %i %i\n", g(q1), g(q2), g(q3), g(q4));
}
Here is an example of a problem resulting from volatile not being recorded in sym files (if a sym file was present, the read of x was lifted out of the loop):
#pragma optimize -1
static volatile int x;
#include <stdio.h>
int main(void) {
int y;
for (unsigned i = 0; i < 100; i++) {
y = x*2 + 7;
}
}
2021-08-30 02:10:20 +00:00
|
|
|
qualifiers: typeQualifierSet; {type qualifiers}
|
2017-10-21 23:40:19 +00:00
|
|
|
saveDisp: longint; {disp in symbol file}
|
|
|
|
case kind: typeKind of {NOTE: aType,pType and fType must overlap}
|
2020-03-01 04:43:29 +00:00
|
|
|
scalarType : (baseType: baseTypeEnum; {our internal type representation}
|
|
|
|
cType: cTypeEnum); {type in the C type system}
|
2017-10-21 23:40:19 +00:00
|
|
|
arrayType : (aType: typePtr;
|
|
|
|
elements: longint;
|
|
|
|
);
|
|
|
|
pointerType : (pType: typePtr;);
|
|
|
|
functionType: (fType: typePtr; {return type}
|
|
|
|
varargs, {are there a variable # of args?}
|
|
|
|
prototyped: boolean; {is it prototyped?}
|
|
|
|
overrideKR: boolean; {K&R overrides to prototypes?}
|
|
|
|
parameterList: parameterPtr; {prototyped parameter list}
|
|
|
|
isPascal: boolean; {pascal parameters?}
|
|
|
|
toolNum: integer; {non-zero for tool functions}
|
|
|
|
dispatcher: longint; {dispatch addr}
|
|
|
|
);
|
|
|
|
enumConst : (eval: integer;);
|
|
|
|
enumType : ();
|
|
|
|
definedType : (dType: typePtr;);
|
|
|
|
structType,
|
|
|
|
unionType : (fieldList: identPtr; {field list}
|
|
|
|
sName: stringPtr; {struct name; for forward refs}
|
2021-09-11 23:12:58 +00:00
|
|
|
constMember: boolean; {does it have a const member?}
|
2017-10-21 23:40:19 +00:00
|
|
|
);
|
|
|
|
end;
|
|
|
|
|
|
|
|
initializerPtr = ^initializerRecord; {initializers}
|
|
|
|
initializerRecord = record
|
|
|
|
next: initializerPtr; {next record in the chain}
|
|
|
|
count: integer; {# of duplicate records}
|
|
|
|
bitdisp: integer; {disp in byte (field lists only)}
|
|
|
|
bitsize: integer; {width in bits; 0 for byte sizes}
|
2016-10-14 23:30:13 +00:00
|
|
|
isStructOrUnion: boolean; {is this a struct or union initializer?}
|
2017-10-21 23:40:19 +00:00
|
|
|
case isConstant: boolean of {is this a constant initializer?}
|
|
|
|
false: (iTree: tokenPtr);
|
2021-02-04 08:17:10 +00:00
|
|
|
true : ( {Note: qVal.lo must overlap iVal}
|
2017-10-21 23:40:19 +00:00
|
|
|
case itype: baseTypeEnum of
|
|
|
|
cgByte,
|
|
|
|
cgUByte,
|
|
|
|
cgWord,
|
|
|
|
cgUWord,
|
|
|
|
cgLong,
|
|
|
|
cgULong : (iVal: longint);
|
2021-01-30 02:50:21 +00:00
|
|
|
cgQuad,
|
|
|
|
cgUQuad : (qVal: longlong);
|
2017-10-21 23:40:19 +00:00
|
|
|
cgString : (sVal: longstringPtr);
|
|
|
|
cgReal,
|
|
|
|
cgDouble,
|
|
|
|
cgComp,
|
2021-03-05 05:52:41 +00:00
|
|
|
cgExtended: (rVal: extended);
|
2017-10-21 23:40:19 +00:00
|
|
|
cgVoid,
|
|
|
|
ccPointer: (
|
|
|
|
pVal: longint;
|
|
|
|
pPlus: boolean;
|
|
|
|
case isName: boolean of
|
|
|
|
true : (pName: stringPtr);
|
|
|
|
false: (pStr : longstringPtr);
|
|
|
|
);
|
|
|
|
);
|
|
|
|
end;
|
|
|
|
|
|
|
|
storageType = (stackFrame,parameter,external,global,none,private);
|
|
|
|
stateKind = (declared,defined,initialized);
|
|
|
|
identRecord = record {identifier}
|
|
|
|
next: identPtr; {next symbol in this hash bucket}
|
|
|
|
saved: boolean; {has the symbol been saved (hashed) in the symbol file?}
|
|
|
|
name: stringPtr; {symbol name}
|
|
|
|
itype: typePtr; {symbol type}
|
|
|
|
disp: longint; {disp past start of struct (field lists only)}
|
|
|
|
bitDisp: integer; {disp in byte (field lists only)}
|
|
|
|
{parameter number (K&R parms only)}
|
|
|
|
bitsize: integer; {width in bits; 0 for byte sizes}
|
|
|
|
state: stateKind; {state of the definition}
|
|
|
|
iPtr: initializerPtr; {pointer to the first initializer}
|
|
|
|
isForwardDeclared: boolean; {does this var use a forward declared type?}
|
|
|
|
class: tokenEnum; {storage class}
|
|
|
|
case storage: storageType of
|
|
|
|
stackFrame: (lln: integer); {local label #}
|
|
|
|
parameter: (pln: integer; {paramater label #}
|
|
|
|
pdisp: integer; {disp of parameter}
|
|
|
|
pnext: identPtr); {next parameter}
|
|
|
|
external: ();
|
|
|
|
global,private: ();
|
|
|
|
none: ();
|
|
|
|
end;
|
|
|
|
|
|
|
|
{mini-assembler}
|
|
|
|
{--------------}
|
|
|
|
{opcodes}
|
|
|
|
opcode = (o_adc,o_and,o_asl,o_bit,o_cmp,o_cop,o_cpx,o_cpy,o_dec,o_eor,
|
|
|
|
o_inc,o_jml,o_jmp,o_jsl,o_jsr,o_lda,o_ldx,o_ldy,o_lsr,o_ora,
|
|
|
|
o_pea,o_pei,o_rep,o_rol,o_ror,o_sbc,o_sep,o_sta,o_stx,o_sty,
|
|
|
|
o_stz,o_trb,o_tsb,
|
|
|
|
|
|
|
|
o_dcb,o_dcw,o_dcl,
|
|
|
|
|
2020-01-12 03:58:21 +00:00
|
|
|
o_brk,o_wdm,
|
2017-10-21 23:40:19 +00:00
|
|
|
|
|
|
|
o_mvn,o_mvp,
|
|
|
|
|
|
|
|
o_bcc,o_bcs,o_beq,o_bmi,o_bne,o_bpl,o_bra,o_brl,o_per,o_bvc,
|
|
|
|
o_bvs,
|
|
|
|
|
|
|
|
o_clc,o_cld,o_cli,o_clv,o_dex,o_dey,o_inx,o_iny,o_nop,o_pha,
|
|
|
|
o_phb,o_phd,o_phk,o_php,o_phx,o_phy,o_pla,o_plb,o_pld,o_plp,
|
|
|
|
o_plx,o_ply,o_rti,o_rtl,o_rts,o_sec,o_sed,o_sei,o_stp,o_tax,
|
|
|
|
o_tay,o_tcd,o_tcs,o_tdc,o_tsc,o_tsx,o_txa,o_txs,o_txy,o_tya,
|
|
|
|
o_tyx,o_wai,o_xba,o_xce);
|
|
|
|
|
|
|
|
{addressing modes}
|
|
|
|
operands = (acc,imm,dp,dp_x,dp_y,op,op_x,op_y,i_dp_x,i_dp_y,dp_s,li_dp,la,
|
|
|
|
i_dp,i_op,i_la,i_op_x,i_dp_s_y,li_dp_y,long_x);
|
|
|
|
|
|
|
|
{work variables}
|
|
|
|
{--------------}
|
|
|
|
tempPtr = ^tempRecord;
|
|
|
|
tempRecord = record
|
|
|
|
last,next: tempPtr; {doubly linked list}
|
|
|
|
labelNum: integer; {label number}
|
|
|
|
size: integer; {size of the variable}
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ORCA Shell and ProDOS}
|
|
|
|
{---------------------}
|
|
|
|
timeField = array[1..8] of byte;
|
|
|
|
|
|
|
|
optionListRecord = record
|
|
|
|
totalSize: integer;
|
|
|
|
requiredSize: integer;
|
|
|
|
fileSysID: integer;
|
|
|
|
theData: packed array [1..100] of char;
|
|
|
|
end;
|
|
|
|
optionListPtr = ^optionListRecord;
|
|
|
|
|
|
|
|
fastFileDCBGS = record
|
|
|
|
pcount: integer;
|
|
|
|
action: integer;
|
|
|
|
index: integer;
|
|
|
|
flags: integer;
|
|
|
|
fileHandle: handle;
|
|
|
|
pathName: gsosInStringPtr;
|
|
|
|
access: integer;
|
|
|
|
fileType: integer;
|
|
|
|
auxType: longint;
|
|
|
|
storageType: integer;
|
|
|
|
createDate: timeField;
|
|
|
|
modDate: timeField;
|
|
|
|
option: optionListPtr;
|
|
|
|
fileLength: longint;
|
|
|
|
blocksUsed: longint;
|
|
|
|
end;
|
|
|
|
|
|
|
|
getLInfoDCBGS = record
|
|
|
|
pcount: integer;
|
|
|
|
sFile: gsosOutStringPtr;
|
|
|
|
dFile: gsosOutStringPtr;
|
|
|
|
namesList: gsosOutStringPtr;
|
|
|
|
iString: gsosOutStringPtr;
|
|
|
|
merr: byte;
|
|
|
|
merrf: byte;
|
|
|
|
lops: byte;
|
|
|
|
kFlag: byte;
|
|
|
|
mFlags: longint;
|
|
|
|
pFlags: longint;
|
|
|
|
org: longint;
|
|
|
|
end;
|
|
|
|
|
|
|
|
getPrefixOSDCB = record
|
|
|
|
pcount: integer;
|
|
|
|
prefixNum: integer;
|
|
|
|
prefix: gsosOutStringPtr;
|
|
|
|
end;
|
|
|
|
|
|
|
|
versionDCBGS = record
|
|
|
|
pcount: integer;
|
|
|
|
version: packed array[1..4] of char;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{---------------------------------------------------------------}
|
|
|
|
|
|
|
|
var
|
|
|
|
{misc}
|
|
|
|
{----}
|
|
|
|
bofPtr: ptr; {pointer to the start of sourceFile}
|
|
|
|
chPtr: ptr; {pointer to the next character in the file}
|
|
|
|
{debugType is also in SCANNER.ASM}
|
|
|
|
debugType: (stop,break,autogo); {line number debug types}
|
|
|
|
doingParameters: boolean; {are we processing parm definitions?}
|
|
|
|
expandMacros: boolean; {should macros be expanded?}
|
|
|
|
ffDCBGS: fastFileDCBGS; {fast file DCB}
|
|
|
|
firstPtr: ptr; {points to first char in current line}
|
|
|
|
gotoList: gotoPtr; {list of goto labels}
|
|
|
|
includeFileGS: gsosOutString; {include file name (for return from includes)}
|
|
|
|
infoStringGS: gsosOutString; {language specific command line info}
|
|
|
|
intLabel: integer; {last used label number}
|
|
|
|
languageNumber: integer; {our language number}
|
|
|
|
lastLine: 0..maxint; {last line number used by pc_nam}
|
|
|
|
liDCBGS: getLInfoDCBGS; {get/set LInfo DCB}
|
|
|
|
lineNumber: 0..maxint; {source line number}
|
|
|
|
nameFound: boolean; {has a pc_nam been generated?}
|
|
|
|
nextLocalLabel: integer; {next available local data label number}
|
|
|
|
numErrors: integer; {number of errors in the program}
|
|
|
|
objFile: gsosOutString; {object file name}
|
|
|
|
oldincludeFileGS: gsosOutString; {previous includeFile value}
|
|
|
|
outFileGS: gsosOutString; {keep file name}
|
|
|
|
partialFileGS: gsosOutString; {partial compile list}
|
|
|
|
sourceFileGS: gsosOutString; {debug source file name}
|
|
|
|
tempList: tempPtr; {list of temp work variables}
|
2021-02-04 18:35:28 +00:00
|
|
|
longlong0: longlong; {the value 0 as a longlong}
|
|
|
|
longlong1: longlong; {the value 1 as a longlong}
|
2017-10-21 23:40:19 +00:00
|
|
|
|
|
|
|
{expression results}
|
|
|
|
{------------------}
|
|
|
|
doDispose: boolean; {dispose of the expression tree as we go?}
|
2021-03-05 05:52:41 +00:00
|
|
|
realExpressionValue: extended; {value of the last real constant expression}
|
2021-02-04 18:44:44 +00:00
|
|
|
llExpressionValue: longlong; {value of the last long long constant expression}
|
2017-10-21 23:40:19 +00:00
|
|
|
expressionValue: longint; {value of the last constant expression}
|
|
|
|
expressionType: typePtr; {the type of the expression}
|
|
|
|
initializerTree: tokenPtr; {for non-constant initializers}
|
2020-01-29 23:09:52 +00:00
|
|
|
isConstant: boolean; {is the initializer expression constant?}
|
2021-02-18 01:41:46 +00:00
|
|
|
expressionIsLongLong: boolean; {is the last constant expression long long?}
|
2017-10-21 23:40:19 +00:00
|
|
|
|
|
|
|
{type specifier results}
|
|
|
|
{----------------------}
|
|
|
|
typeSpec: typePtr; {type specifier}
|
|
|
|
|
|
|
|
{flags}
|
|
|
|
{-----}
|
|
|
|
codegenStarted: boolean; {have we started the code generator?}
|
|
|
|
doingFunction: boolean; {are we processing a function?}
|
|
|
|
doingPartial: boolean; {are we doing a partial compile?}
|
|
|
|
enterEditor: boolean; {enter editor on terminal errors?}
|
|
|
|
foundFunction: boolean; {has a function been found?}
|
|
|
|
lint: integer; {lint flags}
|
|
|
|
list: boolean; {generate source listing?}
|
|
|
|
ignoreSymbols: boolean; {ignore .sym file?}
|
|
|
|
memoryCompile: boolean; {memory based compile?}
|
|
|
|
printSymbols: boolean; {+s flag set?}
|
|
|
|
progress: boolean; {write progress info?}
|
|
|
|
rebuildSymbols: boolean; {rebuild .sym file?}
|
|
|
|
switchLanguages: boolean; {switch languages on exit?}
|
|
|
|
terminalErrors: boolean; {are all errors terminal?}
|
|
|
|
traceBack: boolean; {generate traceback code?}
|
|
|
|
unix_1: boolean; {is int 32 bits? (or 16 bits)}
|
|
|
|
useGlobalPool: boolean; {use global (or local) string pool?}
|
|
|
|
wait: boolean; {wait for keypress after errors?}
|
2020-01-25 17:28:04 +00:00
|
|
|
lintIsError: boolean; {treat lint messages as errors?}
|
2020-01-30 23:30:41 +00:00
|
|
|
fIsNoreturn: boolean; {is the current function _Noreturn?}
|
2020-02-02 19:50:15 +00:00
|
|
|
doingMain: boolean; {are we processing the main function?}
|
2021-03-06 06:57:13 +00:00
|
|
|
fenvAccess: boolean; {is the FENV_ACCESS pragma on?}
|
|
|
|
fenvAccessInFunction: boolean; {was FENV_ACCESS on anywhere in current function?}
|
2017-10-21 23:40:19 +00:00
|
|
|
|
2020-01-12 21:42:56 +00:00
|
|
|
{syntactic classes of tokens}
|
|
|
|
{---------------------------}
|
|
|
|
specifierQualifierListElement: tokenSet;
|
2020-01-18 19:16:44 +00:00
|
|
|
topLevelDeclarationStart: tokenSet;
|
2020-01-12 21:42:56 +00:00
|
|
|
|
2017-10-21 23:40:19 +00:00
|
|
|
{---------------------------------------------------------------}
|
|
|
|
|
|
|
|
{ORCA Shell and ProDOS}
|
|
|
|
{---------------------}
|
|
|
|
|
|
|
|
procedure GetLInfoGS (var parms: getLInfoDCBGS); prodos ($0141);
|
|
|
|
|
|
|
|
procedure FastFileGS (var parms: fastFileDCBGS); prodos ($014E);
|
|
|
|
|
|
|
|
procedure SetLInfoGS (var parms: getLInfoDCBGS); prodos ($0142);
|
|
|
|
|
|
|
|
procedure GetPrefixGS (var parms: getPrefixOSDCB); prodos ($200A);
|
|
|
|
|
|
|
|
procedure VersionGS (var parms: versionDCBGS); prodos ($0147);
|
|
|
|
|
|
|
|
{---------------------------------------------------------------}
|
|
|
|
|
|
|
|
procedure CheckGotoList;
|
|
|
|
|
|
|
|
{ Make sure all labels have been defined }
|
|
|
|
|
|
|
|
|
|
|
|
procedure ClearHourGlass;
|
|
|
|
|
|
|
|
{ Erase the hourglass from the screen }
|
|
|
|
|
|
|
|
|
|
|
|
procedure CopyLongString (toPtr, fromPtr: longStringptr);
|
|
|
|
|
|
|
|
{ copy a long string }
|
|
|
|
{ }
|
|
|
|
{ parameters: }
|
|
|
|
{ toPtr - location to copy to }
|
|
|
|
{ fromPtr - location to copy from }
|
|
|
|
|
|
|
|
|
|
|
|
procedure CopyString (toPtr, fromPtr: ptr); extern;
|
|
|
|
|
|
|
|
{ copy a string }
|
|
|
|
{ }
|
|
|
|
{ parameters: }
|
|
|
|
{ toPtr - location to copy to }
|
|
|
|
{ fromPtr - location to copy from }
|
|
|
|
|
|
|
|
|
|
|
|
procedure DrawHourGlass;
|
|
|
|
|
|
|
|
{ Draw the hourglass on the screen }
|
|
|
|
|
|
|
|
|
|
|
|
procedure ExitToEditor (msg: stringPtr; disp: longint);
|
|
|
|
|
|
|
|
{ do an error exit to the editor }
|
|
|
|
{ }
|
|
|
|
{ parameters: }
|
|
|
|
{ msg - pointer to the error message }
|
|
|
|
{ disp - displacement into the error file }
|
|
|
|
{ }
|
|
|
|
{ variables: }
|
|
|
|
{ includeFile - source file name }
|
|
|
|
|
|
|
|
|
|
|
|
function GenLabel: integer;
|
|
|
|
|
|
|
|
{ generate the next local label, checking for too many }
|
|
|
|
|
|
|
|
|
|
|
|
function GetLocalLabel: integer;
|
|
|
|
|
|
|
|
{ get the next local label number }
|
|
|
|
|
|
|
|
|
|
|
|
function Hash (sPtr: stringPtr): integer; extern;
|
|
|
|
|
|
|
|
{ find hash displacement }
|
|
|
|
{ }
|
|
|
|
{ Finds the displacement into an array of pointers using a }
|
|
|
|
{ hash function. }
|
|
|
|
{ }
|
|
|
|
{ parameters: }
|
|
|
|
{ sPtr - points to string to find hash for }
|
|
|
|
|
|
|
|
|
|
|
|
procedure InitCCommon;
|
|
|
|
|
|
|
|
{ Initialize this module }
|
|
|
|
|
|
|
|
|
|
|
|
procedure ReadFile;
|
|
|
|
|
|
|
|
{ read a file }
|
|
|
|
{ }
|
|
|
|
{ variables: }
|
|
|
|
{ bofPtr - pointer to the start of the file }
|
|
|
|
{ ffDCB.file_length - length of the file }
|
|
|
|
{ includeFile - source file name }
|
|
|
|
|
|
|
|
|
|
|
|
procedure Spin;
|
|
|
|
|
|
|
|
{ Spin the spinner }
|
|
|
|
{ }
|
|
|
|
{ Notes: Starts the spinner if it is not already in use }
|
|
|
|
|
|
|
|
|
|
|
|
procedure StopSpin;
|
|
|
|
|
|
|
|
{ Stop the spinner }
|
|
|
|
{ }
|
|
|
|
{ Notes: The call is safe, and ignored, if the spinner is }
|
|
|
|
|
|
|
|
|
|
|
|
procedure SystemError (errNo: integer);
|
|
|
|
|
|
|
|
{ intercept run time compiler errors }
|
|
|
|
|
|
|
|
|
|
|
|
procedure TermError (errnum: integer);
|
|
|
|
|
|
|
|
{ flag a terminal error }
|
|
|
|
|
|
|
|
{---------------------------------------------------------------}
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
const
|
|
|
|
{Note: maxLabel is also defined in cgi.pas}
|
2016-11-24 03:03:04 +00:00
|
|
|
{Note: maxlabel is also defined in CGC.asm}
|
|
|
|
maxLabel = 3200; {max # compiler generated labels}
|
2017-10-21 23:40:19 +00:00
|
|
|
|
|
|
|
{spinner}
|
|
|
|
{-------}
|
|
|
|
spinSpeed = 8; {calls before one spinner move}
|
|
|
|
|
|
|
|
type
|
|
|
|
consoleOutDCBGS = record
|
|
|
|
pcount: integer;
|
|
|
|
ch: char;
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
{spinner}
|
|
|
|
{-------}
|
|
|
|
|
|
|
|
spinning: boolean; {are we spinning now?}
|
|
|
|
spinDisp: integer; {disp to the spinner character}
|
|
|
|
spinCount: integer; {spin loop counter}
|
|
|
|
|
|
|
|
spinner: array[0..3] of char; {spinner characters}
|
|
|
|
|
|
|
|
|
|
|
|
procedure Error (err: integer); extern; {in scanner.pas}
|
|
|
|
|
|
|
|
{ flag an error }
|
|
|
|
{ }
|
|
|
|
{ err - error number }
|
|
|
|
|
|
|
|
|
|
|
|
{procedure Error2 (loc, err: integer); extern; {debug} {in scanner.pas}
|
|
|
|
|
|
|
|
{ flag an error }
|
|
|
|
{ }
|
|
|
|
{ loc - error location }
|
|
|
|
{ err - error number }
|
|
|
|
|
|
|
|
|
|
|
|
procedure MMQuit; extern; {in mm.pas}
|
|
|
|
|
|
|
|
{ Dispose of memory allocated with private user IDs }
|
|
|
|
|
|
|
|
|
|
|
|
procedure ConsoleOutGS (var parms: consoleOutDCBGS); prodos ($015A);
|
|
|
|
|
|
|
|
{---------------------------------------------------------------}
|
|
|
|
|
|
|
|
procedure CheckGotoList;
|
|
|
|
|
|
|
|
{ Make sure all labels have been defined }
|
|
|
|
|
|
|
|
var
|
|
|
|
gt: gotoPtr; {work pointer}
|
|
|
|
msg: stringPtr; {work string}
|
|
|
|
|
|
|
|
begin {CheckGotoList}
|
|
|
|
gt := gotoList;
|
|
|
|
while gt <> nil do begin
|
|
|
|
if not gt^.defined then begin
|
|
|
|
numErrors := numErrors+1;
|
|
|
|
new(msg);
|
|
|
|
msg^ := concat('Undefined label: ', gt^.name^);
|
|
|
|
writeln(msg^);
|
|
|
|
if terminalErrors then begin
|
|
|
|
if enterEditor then
|
|
|
|
ExitToEditor(msg, ord4(firstPtr)-ord4(bofPtr))
|
|
|
|
else
|
|
|
|
TermError(0);
|
|
|
|
end; {if}
|
|
|
|
dispose(msg);
|
|
|
|
end; {if}
|
|
|
|
gt := gt^.next;
|
|
|
|
end; {while}
|
|
|
|
end; {CheckGotoList}
|
|
|
|
|
|
|
|
|
|
|
|
procedure ClearHourGlass;
|
|
|
|
|
|
|
|
{ Erase the hourglass from the screen }
|
|
|
|
|
|
|
|
var
|
|
|
|
coRec: consoleOutDCBGS; {Console out record}
|
|
|
|
|
|
|
|
begin {ClearHourGlass}
|
|
|
|
coRec.pcount := 1;
|
|
|
|
coRec.ch := ' '; ConsoleOutGS(coRec);
|
|
|
|
coRec.ch := chr(8); ConsoleOutGS(coRec);
|
|
|
|
end; {ClearHourGlass}
|
|
|
|
|
|
|
|
|
|
|
|
procedure CopyLongString {toPtr, fromPtr: longStringPtr};
|
|
|
|
|
|
|
|
{ copy a long string }
|
|
|
|
{ }
|
|
|
|
{ parameters: }
|
|
|
|
{ toPtr - location to copy to }
|
|
|
|
{ fromPtr - location to copy from }
|
|
|
|
|
|
|
|
var
|
|
|
|
i: integer; {loop variable}
|
|
|
|
|
|
|
|
begin {CopyLongString}
|
|
|
|
toPtr^.length := fromPtr^.length; {set the length}
|
|
|
|
for i := 1 to fromPtr^.length do
|
|
|
|
toPtr^.str[i] := fromPtr^.str[i];
|
|
|
|
end; {CopyLongString}
|
|
|
|
|
|
|
|
|
|
|
|
procedure DrawHourGlass;
|
|
|
|
|
|
|
|
{ Draw the hourglass on the screen }
|
|
|
|
|
|
|
|
var
|
|
|
|
coRec: consoleOutDCBGS; {Console out record}
|
|
|
|
|
|
|
|
begin {DrawHourGlass}
|
|
|
|
coRec.pcount := 1;
|
|
|
|
coRec.ch := chr(27); ConsoleOutGS(coRec);
|
|
|
|
coRec.ch := chr(15); ConsoleOutGS(coRec);
|
|
|
|
coRec.ch := 'C'; ConsoleOutGS(coRec);
|
|
|
|
coRec.ch := chr(24); ConsoleOutGS(coRec);
|
|
|
|
coRec.ch := chr(14); ConsoleOutGS(coRec);
|
|
|
|
coRec.ch := chr(8); ConsoleOutGS(coRec);
|
|
|
|
end; {DrawHourGlass}
|
|
|
|
|
|
|
|
|
|
|
|
procedure ExitToEditor {msg: stringPtr; disp: longint};
|
|
|
|
|
|
|
|
{ do an error exit to the editor }
|
|
|
|
{ }
|
|
|
|
{ parameters: }
|
|
|
|
{ msg - pointer to the error message }
|
|
|
|
{ disp - displacement into the error file }
|
|
|
|
{ }
|
|
|
|
{ variables: }
|
|
|
|
{ includeFile - source file name }
|
|
|
|
|
|
|
|
var
|
|
|
|
msgGS: gsosInString; {message}
|
|
|
|
|
|
|
|
begin {ExitToEditor}
|
|
|
|
msgGS.size := length(msg^); {set up the error message}
|
|
|
|
msgGS.theString := msg^;
|
|
|
|
liDCBGS.org := disp; {mark the error}
|
|
|
|
liDCBGS.namesList := @msgGS;
|
|
|
|
liDCBGS.lops := 0; {prevent re-entry}
|
|
|
|
liDCBGS.merrf := 255;
|
|
|
|
with liDCBGS do begin
|
|
|
|
sFile := pointer(ord4(sFile)+2);
|
|
|
|
dFile := pointer(ord4(dFile)+2);
|
|
|
|
iString := pointer(ord4(iString)+2);
|
|
|
|
end; {with}
|
|
|
|
SetLInfoGS(liDCBGS);
|
|
|
|
StopSpin; {stop the spinner}
|
|
|
|
MMQuit; {dispose of the memory pools}
|
|
|
|
halt(-1); {return to the shell}
|
|
|
|
end; {ExitToEditor}
|
|
|
|
|
|
|
|
|
|
|
|
function GenLabel{: integer};
|
|
|
|
|
|
|
|
{ generate the next local label, checking for too many }
|
|
|
|
|
|
|
|
begin {GenLabel}
|
|
|
|
if intLabel < maxLabel then
|
|
|
|
intLabel := intLabel+1
|
|
|
|
else begin
|
|
|
|
intLabel := 0;
|
|
|
|
Error(58);
|
|
|
|
end;
|
|
|
|
GenLabel := intLabel;
|
|
|
|
end; {GenLabel}
|
|
|
|
|
|
|
|
|
|
|
|
function GetLocalLabel{: integer};
|
|
|
|
|
|
|
|
{ get the next local label number }
|
|
|
|
|
|
|
|
begin {GetLocalLabel}
|
|
|
|
GetLocalLabel := nextLocalLabel;
|
|
|
|
nextLocalLabel := nextLocalLabel+1;
|
|
|
|
end; {GetLocalLabel}
|
|
|
|
|
|
|
|
|
|
|
|
procedure InitCCommon;
|
|
|
|
|
|
|
|
{ Initialize this module }
|
|
|
|
|
|
|
|
begin {InitCCommon}
|
|
|
|
spinning := false; {not spinning the spinner}
|
|
|
|
spinDisp := 0; {start spinning with the first character}
|
|
|
|
spinner[0] := '|'; {set up the spinner characters}
|
|
|
|
spinner[1] := '/';
|
|
|
|
spinner[2] := '-';
|
|
|
|
spinner[3] := '\';
|
2021-02-04 18:35:28 +00:00
|
|
|
longlong0.hi := 0;
|
|
|
|
longlong0.lo := 0;
|
|
|
|
longlong1.hi := 0;
|
|
|
|
longlong1.lo := 1;
|
2017-10-21 23:40:19 +00:00
|
|
|
end; {InitCCommon}
|
|
|
|
|
|
|
|
|
|
|
|
procedure ReadFile;
|
|
|
|
|
|
|
|
{ read a file }
|
|
|
|
{ }
|
|
|
|
{ variables: }
|
|
|
|
{ bofPtr - pointer to the start of the file }
|
|
|
|
{ ffDCB.file_length - length of the file }
|
|
|
|
{ includeFile - source file name }
|
|
|
|
|
|
|
|
const
|
|
|
|
SRC = $B0; {source file type}
|
|
|
|
|
|
|
|
begin {ReadFile}
|
|
|
|
with ffDCBGS do begin {read the source file}
|
|
|
|
pCount := 14;
|
|
|
|
action := 0;
|
|
|
|
flags := $C000;
|
|
|
|
pathName := @includeFileGS.theString;
|
|
|
|
end; {with}
|
|
|
|
FastFileGS(ffDCBGS);
|
|
|
|
if ToolError <> 0 then begin
|
|
|
|
sourceFileGS := includeFileGS;
|
|
|
|
includeFileGS := oldincludeFileGS;
|
|
|
|
TermError(1);
|
|
|
|
end; {if}
|
|
|
|
if ffDCBGS.fileType <> SRC then begin
|
|
|
|
includeFileGS := oldincludeFileGS;
|
|
|
|
TermError(6);
|
|
|
|
end; {if}
|
|
|
|
bofPtr := ffDCBGS.fileHandle^; {set beginning of file pointer}
|
|
|
|
end; {ReadFile}
|
|
|
|
|
|
|
|
|
|
|
|
procedure Spin;
|
|
|
|
|
|
|
|
{ Spin the spinner }
|
|
|
|
{ }
|
|
|
|
{ Notes: Starts the spinner if it is not already in use }
|
|
|
|
|
|
|
|
var
|
|
|
|
coRec: consoleOutDCBGS; {Console out record}
|
|
|
|
|
|
|
|
begin {Spin}
|
|
|
|
if not spinning then begin
|
|
|
|
spinning := true;
|
|
|
|
spinCount := spinSpeed;
|
|
|
|
end; {if}
|
|
|
|
spinCount := spinCount - 1;
|
|
|
|
if spinCount = 0 then begin
|
|
|
|
spinCount := spinSpeed;
|
|
|
|
spinDisp := spinDisp - 1;
|
|
|
|
if spinDisp < 0 then
|
|
|
|
spinDisp := 3;
|
|
|
|
coRec.pcount := 1;
|
|
|
|
coRec.ch := spinner[spinDisp];
|
|
|
|
ConsoleOutGS(coRec);
|
|
|
|
coRec.ch := chr(8);
|
|
|
|
ConsoleOutGS(coRec);
|
|
|
|
end; {if}
|
|
|
|
end; {Spin}
|
|
|
|
|
|
|
|
|
|
|
|
procedure StopSpin;
|
|
|
|
|
|
|
|
{ Stop the spinner }
|
|
|
|
{ }
|
|
|
|
{ Notes: The call is safe, and ignored, if the spinner is }
|
|
|
|
{ inactive. }
|
|
|
|
|
|
|
|
var
|
|
|
|
coRec: consoleOutDCBGS; {Console out record}
|
|
|
|
|
|
|
|
begin {StopSpin}
|
|
|
|
if spinning then begin
|
|
|
|
spinning := false;
|
|
|
|
coRec.pcount := 1;
|
|
|
|
coRec.ch := ' ';
|
|
|
|
ConsoleOutGS(coRec);
|
|
|
|
coRec.ch := chr(8);
|
|
|
|
ConsoleOutGS(coRec);
|
|
|
|
end; {if}
|
|
|
|
end; {StopSpin}
|
|
|
|
|
|
|
|
|
|
|
|
procedure SystemError {errNo: integer};
|
|
|
|
|
|
|
|
{ intercept run time compiler errors }
|
|
|
|
|
|
|
|
begin {SystemError}
|
|
|
|
if errNo = 5 then
|
|
|
|
TermError(5)
|
|
|
|
else
|
|
|
|
TermError(3);
|
|
|
|
end; {SystemError}
|
|
|
|
|
|
|
|
|
|
|
|
procedure TermError {errnum: integer};
|
|
|
|
|
|
|
|
{ flag a terminal error }
|
|
|
|
|
|
|
|
var
|
|
|
|
msg: pString; {terminal error message}
|
|
|
|
|
|
|
|
begin {TermError}
|
|
|
|
case errnum of {print the error}
|
2018-03-28 00:19:39 +00:00
|
|
|
0 : msg := '' ;
|
2017-10-21 23:40:19 +00:00
|
|
|
1 : msg := concat('Error reading ', sourceFileGS.theString.theString);
|
|
|
|
2 : msg := concat('Error purging ', sourceFileGS.theString.theString);
|
|
|
|
3 : msg := 'terminal compiler error';
|
|
|
|
4 : msg := 'user termination';
|
|
|
|
5 : msg := 'out of memory';
|
|
|
|
6 : msg := 'source files must have a file type of SRC';
|
|
|
|
7 : msg := 'you cannot change languages with an include directive';
|
|
|
|
8 : msg := 'you cannot change languages from an included file';
|
|
|
|
9 : msg := concat('Error writing ', objFile.theString.theString);
|
|
|
|
10: msg := 'ORCA/C requires version 2.0 or later of the shell';
|
|
|
|
11: msg := 'The program is too large to compile to memory -- use Compile to Disk';
|
2018-09-15 05:42:05 +00:00
|
|
|
12: msg := 'Invalid sym file detected. Re-run ORCA/C to proceed.';
|
2018-03-28 00:19:39 +00:00
|
|
|
otherwise: begin
|
|
|
|
msg := '';
|
|
|
|
Error(57);
|
|
|
|
end;
|
2017-10-21 23:40:19 +00:00
|
|
|
end; {case}
|
|
|
|
with ffDCBGS do begin {purge the source file}
|
|
|
|
pCount := 5;
|
|
|
|
action := 7;
|
|
|
|
pathName := @includeFileGS.theString;
|
|
|
|
end; {with}
|
|
|
|
FastFileGS(ffDCBGS);
|
|
|
|
writeln('Terminal error: ', msg); {write the error to stdout}
|
|
|
|
if enterEditor then {error exit to editor}
|
|
|
|
ExitToEditor(@msg, ord4(chPtr) - ord4(bofPtr))
|
|
|
|
else begin
|
|
|
|
liDCBGS.lops := 0; {prevent re-entry}
|
|
|
|
liDCBGS.merrf := 127;
|
|
|
|
with liDCBGS do begin
|
|
|
|
sFile := pointer(ord4(sFile)+2);
|
|
|
|
dFile := pointer(ord4(dFile)+2);
|
|
|
|
namesList := pointer(ord4(namesList)+2);
|
|
|
|
iString := pointer(ord4(iString)+2);
|
|
|
|
end; {with}
|
|
|
|
SetLInfoGS(liDCBGS);
|
|
|
|
StopSpin; {stop the spinner}
|
|
|
|
MMQuit; {dispose of the memory pools}
|
|
|
|
halt(-1); {return to the shell}
|
|
|
|
end; {else}
|
|
|
|
end; {TermError}
|
|
|
|
|
|
|
|
end.
|
|
|
|
|
|
|
|
{$append 'ccommon.asm'}
|