FoxGlobal.Mod 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824
  1. MODULE FoxGlobal; (** AUTHOR "fof & fn"; PURPOSE "Oberon Compiler Globally Defined Symbols"; *)
  2. (* (c) fof ETH Zürich, 2008 *)
  3. IMPORT
  4. SyntaxTree := FoxSyntaxTree, Basic := FoxBasic, Scanner := FoxScanner, Strings, Dates, D:= Debugging;
  5. CONST
  6. (* system flag names *)
  7. StringWinAPI* = "WINAPI";
  8. StringC* = "C";
  9. StringPlatformCC* = "PlatformCC";
  10. StringMovable*="MOVABLE";
  11. StringUntraced* = "UNTRACED";
  12. StringDelegate* = "DELEGATE";
  13. StringInterrupt*= "INTERRUPT";
  14. StringPcOffset* = "PCOFFSET";
  15. StringEntry* = "INITIAL";
  16. StringExit*= "FINAL";
  17. StringNoPAF*="NOPAF";
  18. StringFixed*="FIXED";
  19. StringFictive*="FICTIVE";
  20. StringAligned*="ALIGNED";
  21. StringAlignStack*="ALIGNSTACK";
  22. StringFinal*="FINAL";
  23. StringAbstract*="ABSTRACT";
  24. StringRegister*= "REGISTER";
  25. StringNoReturn*="NORETURN";
  26. StringUnsafe*="UNSAFE";
  27. StringPlain*="PLAIN";
  28. StringDisposable*="DISPOSABLE";
  29. StringUnchecked*="UNCHECKED";
  30. StringUncooperative*="UNCOOPERATIVE";
  31. (* block modifier flag names *)
  32. StringExclusive* = "EXCLUSIVE";
  33. StringActive* = "ACTIVE";
  34. StringPriority* = "PRIORITY";
  35. StringSafe* = "SAFE";
  36. StringRealtime* = "REALTIME";
  37. StringDynamic* = "DYNAMIC";
  38. StringFingerprint*="FingerPrint";
  39. StringInstructionWidth*="InstructionWidth";
  40. StringDataMemorySize*= "DataMemorySize";
  41. StringCodeMemorySize*= "CodeMemorySize";
  42. StringChannelWidth*= "ChannelWidth";
  43. StringChannelDepth*= "ChannelDepth";
  44. StringChannelModule*= "Channels";
  45. StringSystemModule* = "SYSTEM";
  46. StringsystemModule* = "system";
  47. StringBaseMem*= "BaseMem";
  48. StringBaseDiv*= "BaseDiv";
  49. StringVector*="Vector";
  50. StringFloatingPoint*="FloatingPoint";
  51. StringNoMul*="NoMul";
  52. StringNonBlockingIO*="HasNonBlockingIO";
  53. StringFrequencyDivider*="FrequencyDivider";
  54. StringEngine*="Engine";
  55. StringTRM*="TRM";
  56. StringTRMS*="TRMS";
  57. StringBackend*="Backend";
  58. StringRuntime*="Runtime";
  59. (* traps *)
  60. WithTrap* = 1;
  61. CaseTrap* = 2;
  62. ReturnTrap* = 3;
  63. TypeEqualTrap* = 5;
  64. TypeCheckTrap* = 6;
  65. IndexCheckTrap* = 7;
  66. AssertTrap* = 8;
  67. ArraySizeTrap* = 9;
  68. ArrayFormTrap*=10; (* fof: indicates that array cannot be (re-)allocated since shape, type or size does not match *)
  69. NoReturnTrap*=16;
  70. (** builtin procedures **)
  71. (* FoxProgTools.Enum -e -i
  72. (* global proper procedures *)
  73. Assert Copy Dec Excl Halt Inc Incl New Dispose GetProcedure Connect Delegate
  74. Read Write Reshape Wait
  75. (* global functions *)
  76. Abs Cap Chr Chr32 Entier EntierH Incr Len Long Max Min Odd Ord Ord32 Short Size
  77. Sum Dim Cas First Last Step Re Im Ash Lsh Rot
  78. (* system proper procedures *)
  79. systemGet systemPut systemMove systemNew systemRef
  80. systemTypeCode systemHalt
  81. systemPut8 systemPut16 systemPut32 systemPut64 systemTrace
  82. systemSetStackPointer systemSetFramePointer systemSetActivity
  83. (* system functions *)
  84. systemAdr systemSize systemBit systemGet64 systemGet32 systemGet16 systemGet8
  85. systemVal systemMsk
  86. systemGetStackPointer systemGetFramePointer systemGetActivity
  87. (* for active cells *)
  88. Send Receive
  89. (* for backend specific extensions *)
  90. systemSpecial
  91. (* compatibility with Oberon07 -- other mappings: LSL -> LSH, FLOOR -> Entier, Pack und Unpk currently unsupported *)
  92. Asr Ror Flt
  93. Conversion
  94. DotTimesPlus AtMulDec AtMulInc DecMul IncMul
  95. endFox
  96. ~
  97. *)
  98. (* global proper procedures *)
  99. Assert*= Scanner.EndOfText+1; Copy*= Assert+1; Dec*= Copy+1; Excl*= Dec+1; Halt*= Excl+1; Inc*= Halt+1; Incl*= Inc+1; New*= Incl+1; Dispose*= New+1; GetProcedure*= Dispose+1; Connect*= GetProcedure+1; Delegate*= Connect+1; Read*= Delegate+1; Write*= Read+1; Reshape*= Write+1; Wait*= Reshape+1;
  100. (* global functions *)
  101. Abs*= Wait+1; Cap*= Abs+1; Chr*= Cap+1; Chr32*= Chr+1; Entier*= Chr32+1; EntierH*= Entier+1; Incr*= EntierH+1; Len*= Incr+1; Long*= Len+1; Max*= Long+1; Min*= Max+1; Odd*= Min+1; Ord*= Odd+1; Ord32*= Ord+1; Short*= Ord32+1; Size*= Short+1; Sum*= Size+1; Dim*= Sum+1; Cas*= Dim+1; First*= Cas+1; Last*= First+1; Step*= Last+1; Re*= Step+1; Im*= Re+1; Ash*= Im+1; Lsh*= Ash+1; Rot*= Lsh+1;
  102. All* = Rot+1;
  103. (* system proper procedures *)
  104. systemGet*= All+1; systemPut*= systemGet+1; systemMove*= systemPut+1; systemNew*= systemMove+1; systemRef*= systemNew+1; systemTypeCode*= systemRef+1; systemHalt*= systemTypeCode+1; systemPut8*= systemHalt+1; systemPut16*= systemPut8+1; systemPut32*= systemPut16+1; systemPut64*= systemPut32+1; systemTrace*= systemPut64+1; systemSetStackPointer*= systemTrace+1; systemSetFramePointer*= systemSetStackPointer+1; systemSetActivity*= systemSetFramePointer+1;
  105. (* system functions *)
  106. systemAdr*= systemSetActivity+1; systemSize*= systemAdr+1; systemBit*= systemSize+1; systemGet64*= systemBit+1; systemGet32*= systemGet64+1; systemGet16*= systemGet32+1; systemGet8*= systemGet16+1; systemVal*= systemGet8+1; systemMsk*= systemVal+1; systemGetStackPointer*= systemMsk+1; systemGetFramePointer*= systemGetStackPointer+1; systemGetActivity*= systemGetFramePointer+1;
  107. (* for active cells *)
  108. Send*= systemGetActivity+1; Receive*= Send+1;
  109. (* for backend specific extensions *)
  110. systemSpecial*= Receive+1;
  111. (* compatibility with Oberon07 -- other mappings: LSL -> LSH, FLOOR -> Entier, Pack und Unpk currently unsupported *)
  112. Asr*= systemSpecial+1; Ror*= Asr+1; Flt*= Ror+1; Conversion*= Flt+1; DotTimesPlus*= Conversion+1; AtMulDec*= DotTimesPlus+1; AtMulInc*= AtMulDec+1; DecMul*= AtMulInc+1; IncMul*= DecMul+1; endFox*= IncMul+1;
  113. VectorCapability* = 0;
  114. FloatingPointCapability*= 1;
  115. EngineCapability*= 2;
  116. TRMSCapability*= 3;
  117. NoMulCapability*=4;
  118. NonBlockingIOCapability*=5;
  119. CONST
  120. (* LYNX extensions *)
  121. (* different naming schema to satisfy FoxScanner when parsing imports *)
  122. LynxChar* = "@lynx_char";
  123. LynxSbyte* = "@lynx_sbyte";
  124. LynxShort* = "@lynx_short";
  125. LynxInt* = "@lynx_int";
  126. LynxLong* = "@lynx_long";
  127. LynxFloat* = "@lynx_float";
  128. LynxDouble* = "@lynx_double";
  129. LynxBool* = "@lynx_bool";
  130. LynxObject* = "@lynx_object";
  131. LynxString* = "@lynx_string";
  132. LynxNewobj* = "lynx@newobj";
  133. LynxNewarr* = "lynx@newarr";
  134. LynxAsop* = "lynx@asop";
  135. LynxUnop* = "lynx@unop";
  136. LynxBinop* = "lynx@binop";
  137. LynxSend* = "lynx@send";
  138. LynxReceive* = "lynx@receive";
  139. LynxRecvnb* = "lynx@recvnb";
  140. LynxConnect* = "lynx@connect";
  141. LynxDelegate* = "lynx@delegate";
  142. LynxNewsel* = "lynx@newsel";
  143. LynxAddsel* = "lynx@addsel";
  144. LynxSelect* = "lynx@select";
  145. LynxSelidx* = "lynx@selidx";
  146. LynxOpAdd* = 1;
  147. LynxOpSub* = 2;
  148. LynxOpMul* = 3;
  149. LynxOpDiv* = 4;
  150. LynxOpRem* = 5;
  151. LynxOpAnd* = 6;
  152. LynxOpOr* = 7;
  153. LynxOpXor* = 8;
  154. LynxOpShl* = 9;
  155. LynxOpShr* = 10;
  156. LynxOpNot* = 11;
  157. SymLynxNewobj* = endFox;
  158. SymLynxNewarr* = endFox + 1;
  159. SymLynxAsop* = endFox + 2;
  160. SymLynxUnop* = endFox + 3;
  161. SymLynxBinop* = endFox + 4;
  162. SymLynxRecvnb* = endFox + 5;
  163. SymLynxNewsel* = endFox + 6;
  164. SymLynxAddsel* = endFox + 7;
  165. SymLynxSelect* = endFox + 8;
  166. SymLynxSelidx* = endFox + 9;
  167. end = endFox + 10;
  168. VAR
  169. (* names *)
  170. SelfParameterName-,ReturnParameterName-,SystemName-,systemName-,PointerReturnName-, ResultName-,
  171. A2Name-,ArrayBaseName-, ComplexNumbersName-, RecordBodyName-,ModuleBodyName-,
  172. NameWinAPI-,NameC-,NamePlatformCC-,NameMovable-,NameUntraced-,NameDelegate-,NameInterrupt-, NamePcOffset-, NameNoPAF-,NameEntry-, NameExit-, NameFixed-,NameFictive-, NameAligned-,NameStackAligned-,
  173. NameExclusive-,NameActive-,NamePriority-,NameSafe-,NameRealtime-, NameDynamic-, NameFingerprint-, NameDataMemorySize-, NameCodeMemorySize-
  174. , NameChannelWidth-, NameChannelDepth-, NameChannelModule-, NameVector-, NameFloatingPoint-, NameNoMul-,NameNonBlockingIO-, NameTRM-, NameTRMS-, NameEngine-, NameFinal-, NameAbstract-,
  175. NameBackend-, NameRuntime-, NameFrequencyDivider-, NameRegister-,NameNoReturn-,NamePlain-,NameUnsafe-,NameDisposable-,NameUnchecked-,NameUncooperative-: SyntaxTree.Identifier;
  176. identifiers: ARRAY 2 OF ARRAY end OF SyntaxTree.Identifier;
  177. (* some handy type variables for backend / checker implementers *)
  178. Boolean8-, Boolean32-: SyntaxTree.BooleanType;
  179. Integer8-, Integer16-, Integer32-, Integer64-: SyntaxTree.IntegerType;
  180. Unsigned8-, Unsigned16-, Unsigned32-, Unsigned64-: SyntaxTree.IntegerType;
  181. Character8-, Character16-, Character32-: SyntaxTree.CharacterType;
  182. Set8-, Set16-, Set32-, Set64-: SyntaxTree.SetType;
  183. Float32-, Float64-: SyntaxTree.FloatType;
  184. Complex64-, Complex128-: SyntaxTree.ComplexType;
  185. Byte8: SyntaxTree.ByteType;
  186. Byte32: SyntaxTree.ByteType;
  187. TYPE
  188. Position = SyntaxTree.Position;
  189. Alignment* = RECORD
  190. min, max: LONGINT; (* alignments in bits *)
  191. END;
  192. PassInRegisterProc = PROCEDURE {DELEGATE} (type: SyntaxTree.Type): BOOLEAN;
  193. System*= OBJECT
  194. VAR
  195. (* system and global scopes and modules (lowercase and uppercase each) *)
  196. systemScope-, globalScope-: ARRAY 2 OF SyntaxTree.ModuleScope;
  197. systemModule-,globalModule-: ARRAY 2 OF SyntaxTree.Module;
  198. activeCellsCapabilities-: SyntaxTree.Symbol; (* list of supported capabilities, filled by ActiveCells specification *)
  199. (* addressing granularity in code and data memory *)
  200. codeUnit-: LONGINT;
  201. dataUnit-: LONGINT;
  202. (* alignment (variables, record entries) *)
  203. (* alignment (parameters & stack frames) *)
  204. variableAlignment-, parameterAlignment-: Alignment;
  205. (* offset of first parameter *)
  206. offsetFirstParameter-: LONGINT;
  207. (* to determine if a builtin-procedure can be operator-overloaded *)
  208. operatorDefined-: ARRAY end OF BOOLEAN;
  209. (* type sizes defined by backend *)
  210. addressSize-: LONGINT;
  211. (* system type mapping, in a later version only the global (unisgned) types should be used
  212. the following two types are only there for compatibility with the system as is
  213. problematic are mainly the conversions between (signed) Oberon types and (unsigned) addressType.
  214. A good concept has to be derived.
  215. *)
  216. addressType-, sizeType-, shortintType-, integerType-, longintType-, hugeintType-, wordType-, longWordType-, wordSetType-, characterType-, characterType8-, characterType16-, characterType32-, setType-, booleanType-, anyType-,byteType-,
  217. realType-, longrealType-, complexType-, longcomplexType-, objectType-, nilType-, rangeType-, lenType-: SyntaxTree.Type;
  218. CanPassInRegister-: PassInRegisterProc;
  219. cellsAreObjects-: BOOLEAN;
  220. platformCallingConvention-: SyntaxTree.CallingConvention;
  221. PROCEDURE &InitSystem*(codeUnit, dataUnit: LONGINT; addressSize, minVarAlign, maxVarAlign, minParAlign, maxParAlign, offsetFirstPar: LONGINT; cooperative: BOOLEAN);
  222. VAR i: LONGINT;
  223. BEGIN
  224. ASSERT(dataUnit > 0);
  225. ASSERT(minVarAlign > 0);
  226. ASSERT(maxVarAlign > 0);
  227. ASSERT(minParAlign > 0);
  228. ASSERT(maxParAlign > 0);
  229. SELF.dataUnit := dataUnit;
  230. SELF.codeUnit := codeUnit;
  231. SELF.addressSize := addressSize;
  232. SELF.variableAlignment.min := minVarAlign;
  233. SELF.variableAlignment.max := maxVarAlign;
  234. SELF.parameterAlignment.min := minParAlign;
  235. SELF.parameterAlignment.max := maxParAlign;
  236. SELF.offsetFirstParameter := offsetFirstPar;
  237. IF cooperative THEN INC(SELF.offsetFirstParameter,addressSize) END;
  238. activeCellsCapabilities := NIL;
  239. BuildScopes(SELF);
  240. FOR i := 0 TO LEN(operatorDefined)-1 DO
  241. operatorDefined[i] := FALSE;
  242. END;
  243. CanPassInRegister :=NIL;
  244. cellsAreObjects := FALSE;
  245. platformCallingConvention := SyntaxTree.UndefinedCallingConvention;
  246. END InitSystem;
  247. PROCEDURE SetPlatformCallingConvention*(callingConvention: SyntaxTree.CallingConvention);
  248. BEGIN
  249. platformCallingConvention := callingConvention;
  250. END SetPlatformCallingConvention;
  251. PROCEDURE SetCellsAreObjects*(c: BOOLEAN);
  252. BEGIN
  253. cellsAreObjects := c;
  254. END SetCellsAreObjects;
  255. PROCEDURE SetRegisterPassCallback*(canPassInRegister: PassInRegisterProc);
  256. BEGIN
  257. CanPassInRegister := canPassInRegister;
  258. END SetRegisterPassCallback;
  259. PROCEDURE AddCapability*(name: SyntaxTree.Identifier);
  260. VAR symbol: SyntaxTree.Symbol;
  261. BEGIN
  262. symbol := SyntaxTree.NewSymbol(name);
  263. symbol.SetNext(activeCellsCapabilities);
  264. activeCellsCapabilities := symbol
  265. END AddCapability;
  266. PROCEDURE GenerateRecordOffsets*(x: SyntaxTree.RecordType): BOOLEAN; (* normally done in checker but the binary symbol file format makes this necessary *)
  267. VAR baseType: SyntaxTree.RecordType; offset,baseOffset, size: LONGINT; alignment, thisAlignment: LONGINT; variable: SyntaxTree.Variable;
  268. BEGIN
  269. baseType :=x.GetBaseRecord();
  270. IF (baseType # NIL) & (baseType.sizeInBits < 0) THEN
  271. IF~ GenerateRecordOffsets(baseType) THEN RETURN FALSE END;
  272. END;
  273. IF baseType # NIL THEN
  274. offset := baseType.sizeInBits;
  275. alignment := baseType.alignmentInBits;
  276. ELSE
  277. offset := 0; alignment := x.alignmentInBits;
  278. IF alignment <= 0 THEN alignment := dataUnit END;
  279. END;
  280. baseOffset := offset;
  281. variable := x.recordScope.firstVariable;
  282. WHILE (variable # NIL) DO
  283. IF ~variable.fictive THEN
  284. size := SizeOf(variable.type.resolved);
  285. IF size < 0 THEN RETURN FALSE END;
  286. IF variable.alignment > 0 THEN
  287. thisAlignment := variable.alignment*dataUnit;
  288. ELSE
  289. thisAlignment := AlignmentOf(SELF.variableAlignment, variable.type.resolved);
  290. END;
  291. Basic.Align(offset, thisAlignment);
  292. IF thisAlignment > alignment THEN alignment := thisAlignment END;
  293. variable.SetOffset(offset);
  294. INC(offset,size);
  295. ELSE
  296. variable.SetOffset(baseOffset + variable.fictiveOffset * dataUnit);
  297. END;
  298. variable := variable.nextVariable;
  299. END;
  300. x.SetAlignmentInBits(alignment);
  301. Basic.Align(offset, alignment); (* strictly speaking not necessary, but with the old object file format otherwise problems with the GC show up *)
  302. x.SetSize(offset);
  303. RETURN TRUE
  304. END GenerateRecordOffsets;
  305. PROCEDURE GenerateCellOffsets(x: SyntaxTree.CellType): BOOLEAN;
  306. VAR baseType: SyntaxTree.Type; offset,size: LONGINT; alignment, thisAlignment: LONGINT; variable: SyntaxTree.Variable;
  307. parameter: SyntaxTree.Parameter; property: SyntaxTree.Property;
  308. BEGIN
  309. baseType := x.baseType;
  310. IF (baseType # NIL) THEN
  311. baseType := baseType.resolved;
  312. IF baseType IS SyntaxTree.PointerType THEN
  313. baseType := baseType(SyntaxTree.PointerType).pointerBase.resolved
  314. END;
  315. IF (baseType IS SyntaxTree.CellType) THEN
  316. IF~ GenerateCellOffsets(baseType(SyntaxTree.CellType)) THEN RETURN FALSE END;
  317. ELSE ASSERT (baseType IS SyntaxTree.RecordType);
  318. IF~GenerateRecordOffsets(baseType(SyntaxTree.RecordType)) THEN RETURN FALSE END;
  319. END;
  320. END;
  321. IF baseType # NIL THEN
  322. offset := baseType.sizeInBits;
  323. alignment := baseType.alignmentInBits;
  324. ELSE
  325. offset := 0; alignment := x.alignmentInBits;
  326. IF alignment <= 0 THEN alignment := dataUnit END;
  327. END;
  328. IF cellsAreObjects THEN
  329. (* ports *)
  330. parameter := x.cellScope.ownerCell.firstParameter;
  331. WHILE (parameter # NIL) DO
  332. size := SizeOf(parameter.type.resolved);
  333. IF size < 0 THEN RETURN FALSE END;
  334. IF parameter.alignment > 0 THEN
  335. thisAlignment := parameter.alignment*dataUnit;
  336. ELSE
  337. thisAlignment := AlignmentOf(SELF.variableAlignment, parameter.type.resolved);
  338. END;
  339. Basic.Align(offset, thisAlignment);
  340. IF thisAlignment > alignment THEN alignment := thisAlignment END;
  341. parameter.SetOffset(offset);
  342. INC(offset,size);
  343. parameter := parameter.nextParameter;
  344. END;
  345. (* properties *)
  346. property := x.cellScope.ownerCell.firstProperty;
  347. WHILE (property # NIL) DO
  348. size := SizeOf(property.type.resolved);
  349. IF size < 0 THEN RETURN FALSE END;
  350. IF property.alignment > 0 THEN
  351. thisAlignment := property.alignment*dataUnit;
  352. ELSE
  353. thisAlignment := AlignmentOf(SELF.variableAlignment, property.type.resolved);
  354. END;
  355. Basic.Align(offset, thisAlignment);
  356. IF thisAlignment > alignment THEN alignment := thisAlignment END;
  357. property.SetOffset(offset);
  358. INC(offset,size);
  359. property := property.nextProperty;
  360. END;
  361. END;
  362. (* variables *)
  363. variable := x.cellScope.firstVariable;
  364. WHILE (variable # NIL) DO
  365. IF ~variable.fictive THEN
  366. size := SizeOf(variable.type.resolved);
  367. IF size < 0 THEN RETURN FALSE END;
  368. IF variable.alignment > 0 THEN
  369. thisAlignment := variable.alignment*dataUnit;
  370. ELSE
  371. thisAlignment := AlignmentOf(SELF.variableAlignment, variable.type.resolved);
  372. END;
  373. Basic.Align(offset, thisAlignment);
  374. IF thisAlignment > alignment THEN alignment := thisAlignment END;
  375. variable.SetOffset(offset);
  376. INC(offset,size);
  377. END;
  378. variable := variable.nextVariable;
  379. END;
  380. x.SetAlignmentInBits(alignment);
  381. Basic.Align(offset, alignment); (* strictly speaking not necessary, but with the old object file format otherwise problems with the GC show up *)
  382. x.SetSize(offset);
  383. RETURN TRUE
  384. END GenerateCellOffsets;
  385. PROCEDURE GenerateVariableOffsets*(scope: SyntaxTree.Scope): BOOLEAN;
  386. VAR variable: SyntaxTree.Variable; offset,size: LONGINT; alignment: LONGINT;
  387. BEGIN
  388. IF scope IS SyntaxTree.RecordScope THEN (* increasing indices *)
  389. RETURN GenerateRecordOffsets(scope(SyntaxTree.RecordScope).ownerRecord)
  390. ELSIF scope IS SyntaxTree.CellScope THEN
  391. RETURN GenerateCellOffsets(scope(SyntaxTree.CellScope).ownerCell);
  392. ELSE (* module scope or procedure scope: decreasing indices *)
  393. ASSERT((scope IS SyntaxTree.ModuleScope) OR (scope IS SyntaxTree.ProcedureScope));
  394. offset := 0;
  395. variable := scope.firstVariable;
  396. WHILE (variable # NIL) DO
  397. IF (variable.externalName = NIL) & ~variable.fictive THEN
  398. size := SizeOf(variable.type.resolved);
  399. IF size < 0 THEN RETURN FALSE END;
  400. DEC(offset,size);
  401. IF variable.alignment > 0 THEN
  402. Basic.Align(offset, -variable.alignment*dataUnit);
  403. ELSE
  404. alignment := AlignmentOf(SELF.variableAlignment,variable.type.resolved);
  405. Basic.Align(offset,-alignment);
  406. END;
  407. variable.SetOffset(offset);
  408. END;
  409. variable := variable.nextVariable;
  410. END;
  411. END;
  412. RETURN TRUE
  413. END GenerateVariableOffsets;
  414. PROCEDURE GenerateParameterOffsets*(procedure : SyntaxTree.Procedure; nestedProcedure: BOOLEAN): BOOLEAN;
  415. VAR offset,size: LONGINT;parameter: SyntaxTree.Parameter; procedureType: SyntaxTree.ProcedureType;
  416. BEGIN
  417. procedureType := procedure.type(SyntaxTree.ProcedureType);
  418. IF (procedure.isInline) THEN
  419. offset := 0
  420. ELSE
  421. offset := SELF.offsetFirstParameter + procedureType.parametersOffset * addressSize;
  422. END;
  423. IF nestedProcedure THEN
  424. INC(offset,addressSize); (* parameter offset of static link *) (*! check alternative: add hidden parameter *)
  425. END;
  426. IF procedureType.callingConvention = SyntaxTree.OberonCallingConvention THEN
  427. parameter := procedureType.lastParameter;
  428. WHILE (parameter # NIL) DO
  429. Basic.Align(offset,addressSize);
  430. parameter.SetOffset(offset);
  431. size := SizeOfParameter(parameter);
  432. IF size < 0 THEN RETURN FALSE END;
  433. INC(offset,size);
  434. parameter := parameter.prevParameter;
  435. END;
  436. parameter := procedureType.returnParameter;
  437. IF parameter # NIL THEN
  438. Basic.Align(offset,addressSize);
  439. parameter.SetOffset(offset);
  440. size := SizeOfParameter(parameter);
  441. IF size < 0 THEN RETURN FALSE END;
  442. INC(offset,size);
  443. END;
  444. parameter := procedureType.selfParameter;
  445. IF parameter # NIL THEN
  446. Basic.Align(offset,addressSize);
  447. parameter.SetOffset(offset);
  448. size := SizeOfParameter(parameter);
  449. IF size < 0 THEN RETURN FALSE END;
  450. INC(offset,size);
  451. END;
  452. ELSE
  453. parameter := procedureType.firstParameter;
  454. WHILE (parameter # NIL) DO
  455. Basic.Align(offset,addressSize);
  456. parameter.SetOffset(offset);
  457. size := SizeOfParameter(parameter);
  458. IF size < 0 THEN RETURN FALSE END;
  459. INC(offset,size);
  460. parameter := parameter.nextParameter;
  461. END;
  462. END;
  463. IF procedureType.isDelegate & (procedureType.selfParameter = NIL) THEN
  464. INC(offset,addressSize); (* parameter offset of delegate *)
  465. END;
  466. RETURN TRUE
  467. END GenerateParameterOffsets;
  468. PROCEDURE SizeOf*(type: SyntaxTree.Type): LONGINT;
  469. VAR size: LONGINT; base: SyntaxTree.Type;
  470. BEGIN
  471. IF type = NIL THEN RETURN -1 END;
  472. type := type.resolved;
  473. IF type IS SyntaxTree.BasicType THEN
  474. size := type.sizeInBits
  475. ELSIF type IS SyntaxTree.PointerType THEN
  476. size := addressSize
  477. ELSIF type IS SyntaxTree.ProcedureType THEN
  478. IF type(SyntaxTree.ProcedureType).isDelegate THEN
  479. size := 2*addressSize
  480. ELSE
  481. size := addressSize
  482. END;
  483. ELSIF type IS SyntaxTree.RecordType THEN
  484. (* do not treat a record type like a pointer even if the Pointer field is set, this leads to problems in object files
  485. rather make sure that each reference type is a POINTER TO at least behind the secenes!
  486. *)
  487. IF ~(SyntaxTree.Resolved IN type.state) THEN
  488. size := -1
  489. ELSE
  490. size :=type.sizeInBits;
  491. IF size < 0 THEN
  492. IF GenerateRecordOffsets(type(SyntaxTree.RecordType)) THEN
  493. size :=type.sizeInBits;
  494. ELSE
  495. size := -1
  496. END;
  497. END;
  498. END;
  499. ELSIF type IS SyntaxTree.ArrayType THEN
  500. IF ~(SyntaxTree.Resolved IN type.state) THEN
  501. size := -1
  502. ELSIF type.sizeInBits >= 0 THEN
  503. size := type.sizeInBits
  504. ELSIF type(SyntaxTree.ArrayType).form = SyntaxTree.Static THEN
  505. size := AlignedSizeOf(type(SyntaxTree.ArrayType).arrayBase.resolved)*type(SyntaxTree.ArrayType).staticLength;
  506. type.SetSize(size);
  507. ELSE
  508. size := 0; base := type;
  509. WHILE(base IS SyntaxTree.ArrayType) DO
  510. base := base(SyntaxTree.ArrayType).arrayBase.resolved;
  511. INC(size); (* length field *)
  512. END;
  513. size := size*addressSize+addressSize;
  514. type.SetSize(size)
  515. END;
  516. ELSIF type IS SyntaxTree.MathArrayType THEN
  517. IF ~(SyntaxTree.Resolved IN type.state) THEN
  518. size := -1
  519. ELSIF type(SyntaxTree.MathArrayType).form = SyntaxTree.Static THEN
  520. size := SizeOf(type(SyntaxTree.MathArrayType).arrayBase.resolved)*type(SyntaxTree.MathArrayType).staticLength;
  521. type.SetSize(size);
  522. ELSIF type(SyntaxTree.MathArrayType).form = SyntaxTree.Tensor THEN
  523. size := addressSize (* pointer to geometry descriptor *)
  524. ELSE
  525. size := 0;
  526. WHILE(type # NIL) & (type IS SyntaxTree.MathArrayType) DO
  527. type := type(SyntaxTree.MathArrayType).arrayBase;
  528. IF type # NIL THEN type := type.resolved END;
  529. INC(size);
  530. END;
  531. size := size*2*addressSize (* length and increments *) +5*addressSize (* data ptr, adr ptr, flags, dim and elementsize *);
  532. END;
  533. ELSIF type IS SyntaxTree.StringType THEN
  534. ASSERT(SyntaxTree.Resolved IN type.state);
  535. size := type(SyntaxTree.StringType).length * SizeOf(type(SyntaxTree.StringType).baseType);
  536. ELSIF type IS SyntaxTree.EnumerationType THEN
  537. size := addressSize
  538. ELSIF type = SyntaxTree.invalidType THEN size := 0
  539. ELSIF type IS SyntaxTree.QualifiedType THEN
  540. HALT(101); (* hint that unresolved type has been taken for type size computation *)
  541. ELSIF type IS SyntaxTree.PortType THEN
  542. size := addressSize
  543. ELSIF type IS SyntaxTree.CellType THEN
  544. size := addressSize;
  545. ELSIF type IS SyntaxTree.RangeType THEN
  546. size := 3 * SizeOf(longintType);
  547. ELSE
  548. HALT(100)
  549. END;
  550. RETURN size
  551. END SizeOf;
  552. PROCEDURE SizeOfParameter*(par: SyntaxTree.Parameter):LONGINT;
  553. BEGIN
  554. IF (par.type.resolved IS SyntaxTree.ArrayType) OR (par.type.resolved IS SyntaxTree.MathArrayType) THEN
  555. IF (par.type.resolved IS SyntaxTree.ArrayType) & (par.type.resolved(SyntaxTree.ArrayType).form = SyntaxTree.Static) &
  556. (par.kind IN {SyntaxTree.ConstParameter,SyntaxTree.VarParameter})
  557. OR
  558. (par.type.resolved IS SyntaxTree.MathArrayType) & (par.type.resolved(SyntaxTree.MathArrayType).form = SyntaxTree.Static) &
  559. (par.kind IN {SyntaxTree.ConstParameter,SyntaxTree.VarParameter})
  560. OR (par.type.resolved IS SyntaxTree.MathArrayType) & (par.kind = SyntaxTree.VarParameter)
  561. THEN
  562. RETURN addressSize
  563. ELSIF IsOberonProcedure(par.ownerType) THEN
  564. RETURN SizeOf(par.type);
  565. ELSE RETURN addressSize
  566. END
  567. ELSIF par.type.resolved IS SyntaxTree.RangeType THEN
  568. IF par.kind = SyntaxTree.VarParameter THEN
  569. RETURN addressSize
  570. ELSE
  571. RETURN SizeOf(rangeType) (* array range components are materialized on stack for both value and const parameters *)
  572. END
  573. ELSIF par.type.resolved IS SyntaxTree.RecordType THEN
  574. IF par.selfParameter THEN
  575. RETURN addressSize
  576. ELSIF (par.kind IN {SyntaxTree.ConstParameter,SyntaxTree.VarParameter}) THEN
  577. IF IsOberonProcedure(par.ownerType) THEN
  578. RETURN 2*addressSize
  579. ELSE
  580. RETURN addressSize
  581. END
  582. ELSE
  583. RETURN SizeOf(par.type);
  584. END;
  585. ELSIF par.kind = SyntaxTree.VarParameter THEN
  586. RETURN addressSize
  587. ELSIF par.kind = SyntaxTree.ConstParameter THEN
  588. RETURN SizeOf(par.type)
  589. ELSE
  590. RETURN SizeOf(par.type);
  591. END;
  592. END SizeOfParameter;
  593. PROCEDURE AlignmentOf*(CONST alignment: Alignment;type: SyntaxTree.Type): LONGINT;
  594. VAR result: LONGINT;
  595. BEGIN
  596. type := type.resolved;
  597. IF type IS SyntaxTree.RecordType THEN
  598. IF type.alignmentInBits <= 0 THEN
  599. IF GenerateRecordOffsets(type(SyntaxTree.RecordType)) THEN
  600. result := type.alignmentInBits
  601. END
  602. ELSE
  603. result := type.alignmentInBits
  604. END;
  605. ELSIF type IS SyntaxTree.ArrayType THEN
  606. IF type.alignmentInBits <= 0 THEN
  607. IF type(SyntaxTree.ArrayType).form = SyntaxTree.Static THEN
  608. result := AlignmentOf(alignment,type(SyntaxTree.ArrayType).arrayBase.resolved);
  609. ELSE
  610. result := alignment.max
  611. END;
  612. type.SetAlignmentInBits(result)
  613. ELSE
  614. result := type.alignmentInBits
  615. END;
  616. ELSIF type IS SyntaxTree.StringType THEN
  617. result := SizeOf(type(SyntaxTree.StringType).baseType);
  618. ELSE
  619. result := SizeOf(type);
  620. IF result > alignment.max THEN result := alignment.max END;
  621. IF result < alignment.min THEN result := alignment.min END;
  622. END;
  623. ASSERT(result # 0);
  624. RETURN result
  625. END AlignmentOf;
  626. PROCEDURE AlignedSizeOf*(type: SyntaxTree.Type): LONGINT;
  627. VAR size: LONGINT;
  628. BEGIN
  629. size := SizeOf(type);
  630. Basic.Align(size, AlignmentOf(variableAlignment, type));
  631. RETURN size
  632. END AlignedSizeOf;
  633. (* LYNX+ *)
  634. PROCEDURE IsLynx*(): BOOLEAN;
  635. BEGIN
  636. RETURN TRUE;
  637. END IsLynx;
  638. (* -LYNX *)
  639. END System;
  640. PROCEDURE BuildScopes(system: System);
  641. VAR i: LONGINT;
  642. BEGIN
  643. FOR i := 0 TO end-1 DO
  644. system.operatorDefined[i] := FALSE
  645. END;
  646. system.globalScope[Scanner.Uppercase] := SyntaxTree.NewModuleScope();
  647. system.globalScope[Scanner.Lowercase] := SyntaxTree.NewModuleScope();
  648. system.globalModule[Scanner.Uppercase] := SyntaxTree.NewModule("",SyntaxTree.invalidPosition,SyntaxTree.NewIdentifier("@GLOBAL"),system.globalScope[Scanner.Uppercase],Scanner.Uppercase);
  649. system.globalModule[Scanner.Lowercase] := SyntaxTree.NewModule("",SyntaxTree.invalidPosition,SyntaxTree.NewIdentifier("@global"),system.globalScope[Scanner.Lowercase],Scanner.Lowercase);
  650. system.systemScope[Scanner.Uppercase] := SyntaxTree.NewModuleScope();
  651. system.systemScope[Scanner.Lowercase] := SyntaxTree.NewModuleScope();
  652. system.systemModule[Scanner.Uppercase] := SyntaxTree.NewModule("",SyntaxTree.invalidPosition,SystemName,system.systemScope[Scanner.Uppercase],Scanner.Uppercase);
  653. system.systemModule[Scanner.Lowercase] := SyntaxTree.NewModule("",SyntaxTree.invalidPosition,systemName,system.systemScope[Scanner.Lowercase],Scanner.Lowercase);
  654. END BuildScopes;
  655. PROCEDURE SetDefaultDeclarations*(system: System; minBits: LONGINT);
  656. VAR now: Dates.DateTime; date, time: ARRAY 20 OF CHAR;
  657. BEGIN
  658. (* types *)
  659. system.longintType := SyntaxTree.NewIntegerType(32, TRUE);
  660. system.hugeintType := SyntaxTree.NewIntegerType(64, TRUE);
  661. system.wordType := SyntaxTree.NewIntegerType(MIN(system.addressSize,32),TRUE);
  662. system.longWordType := SyntaxTree.NewIntegerType(system.addressSize,TRUE);
  663. system.wordSetType := SyntaxTree.NewSetType(system.wordType.sizeInBits);
  664. system.realType := SyntaxTree.NewFloatType(32);
  665. system.longrealType := SyntaxTree.NewFloatType(64);
  666. (*
  667. system.longintType := Integer32;
  668. system.hugeintType := Integer64;
  669. system.realType := Float32;
  670. system.longrealType := Float64;
  671. *)
  672. IF minBits = 32 THEN
  673. system.shortintType := SyntaxTree.NewIntegerType(32, TRUE);
  674. system.integerType := SyntaxTree.NewIntegerType(32, TRUE);
  675. system.booleanType := SyntaxTree.NewBooleanType(32);
  676. system.byteType := SyntaxTree.NewByteType(32);
  677. system.characterType := SyntaxTree.NewCharacterType(32);
  678. system.characterType8 := SyntaxTree.NewCharacterType(32);
  679. system.characterType16 := SyntaxTree.NewCharacterType(32);
  680. system.characterType32 := SyntaxTree.NewCharacterType(32);
  681. (*
  682. system.shortintType := Integer32;
  683. system.integerType := Integer32;
  684. system.booleanType := Boolean32;
  685. system.byteType := Byte32;
  686. system.characterType := Character32;
  687. *)
  688. ELSE
  689. ASSERT(minBits = 8); (* nothing else is currently implemented *)
  690. system.shortintType := SyntaxTree.NewIntegerType(8, TRUE);
  691. system.integerType := SyntaxTree.NewIntegerType(16, TRUE);
  692. system.booleanType := SyntaxTree.NewBooleanType(8);
  693. system.byteType := SyntaxTree.NewByteType(8);
  694. system.characterType := SyntaxTree.NewCharacterType(8);
  695. system.characterType8 := SyntaxTree.NewCharacterType(8);
  696. system.characterType16 := SyntaxTree.NewCharacterType(16);
  697. system.characterType32 := SyntaxTree.NewCharacterType(32);
  698. (*
  699. system.shortintType := Integer8;
  700. system.integerType := Integer16;
  701. system.booleanType := Boolean8;
  702. system.byteType := Byte8;
  703. system.characterType := Character8;
  704. *)
  705. END;
  706. system.anyType := SyntaxTree.NewAnyType(system.addressSize);
  707. system.objectType := SyntaxTree.NewObjectType(system.addressSize);
  708. system.nilType := SyntaxTree.NewNilType(system.addressSize);
  709. system.addressType := SyntaxTree.NewAddressType(system.addressSize);
  710. system.sizeType := SyntaxTree.NewSizeType(system.addressSize);
  711. system.rangeType := SyntaxTree.NewRangeType(3 * system.SizeOf(system.longintType));
  712. system.lenType := system.longintType;
  713. (* generally, the lenType should be sizeType but for historical (legacy) reasons, it is longint in the current implementation *)
  714. system.complexType := Complex64;
  715. system.longcomplexType := Complex128;
  716. system.setType := SyntaxTree.NewSetType(system.addressSize);
  717. (* type declarations *)
  718. DeclareType(system.byteType,"BYTE",system.systemScope);
  719. DeclareType(system.addressType,"ADDRESS",system.globalScope);
  720. DeclareType(system.sizeType,"SIZE",system.globalScope);
  721. (*DeclareType(Same,"SAME",system.systemScope);*)
  722. (* system builtin procedures *)
  723. NewBuiltin(systemGet,"GET",system.systemScope,TRUE);
  724. NewBuiltin(systemPut,"PUT",system.systemScope,TRUE);
  725. NewBuiltin(systemPut64,"PUT64",system.systemScope,TRUE);
  726. NewBuiltin(systemPut32,"PUT32",system.systemScope,TRUE);
  727. NewBuiltin(systemPut16,"PUT16",system.systemScope,TRUE);
  728. NewBuiltin(systemPut8,"PUT8",system.systemScope,TRUE);
  729. NewBuiltin(systemGet64,"GET64",system.systemScope,TRUE);
  730. NewBuiltin(systemGet32,"GET32",system.systemScope,TRUE);
  731. NewBuiltin(systemGet16,"GET16",system.systemScope,TRUE);
  732. NewBuiltin(systemGet8,"GET8",system.systemScope,TRUE);
  733. NewBuiltin(systemVal,"VAL",system.systemScope,TRUE);
  734. NewBuiltin(systemMove,"MOVE",system.systemScope,TRUE);
  735. NewBuiltin(systemRef,"REF",system.systemScope,FALSE);
  736. NewBuiltin(systemNew,"NEW",system.systemScope,FALSE);
  737. NewBuiltin(systemTypeCode,"TYPECODE",system.systemScope,TRUE);
  738. NewBuiltin(systemHalt,"HALT",system.systemScope,TRUE);
  739. NewBuiltin(systemSize,"SIZE",system.systemScope,TRUE);
  740. NewBuiltin(systemAdr,"ADR",system.systemScope,TRUE);
  741. NewBuiltin(systemMsk,"MSK",system.systemScope,TRUE);
  742. NewBuiltin(systemBit,"BIT",system.systemScope,TRUE);
  743. now := Dates.Now ();
  744. Strings.FormatDateTime ("hh:nn:ss", now, time);
  745. Strings.FormatDateTime ("mmm dd yyyy", now, date);
  746. NewStringConstantCamelCase("Time", Strings.NewString (time), system.characterType, system.systemScope);
  747. NewStringConstantCamelCase("Date", Strings.NewString (date), system.characterType, system.systemScope);
  748. NewBuiltinCamelCase(systemGetStackPointer,"GetStackPointer",system.systemScope,TRUE);
  749. NewBuiltinCamelCase(systemSetStackPointer,"SetStackPointer",system.systemScope,TRUE);
  750. NewBuiltinCamelCase(systemGetFramePointer,"GetFramePointer",system.systemScope,TRUE);
  751. NewBuiltinCamelCase(systemSetFramePointer,"SetFramePointer",system.systemScope,TRUE);
  752. NewBuiltinCamelCase(systemGetActivity,"GetActivity",system.systemScope,TRUE);
  753. NewBuiltinCamelCase(systemSetActivity,"SetActivity",system.systemScope,TRUE);
  754. (* Set up system types *)
  755. DeclareType(system.characterType,"CHAR",system.globalScope);
  756. DeclareType(system.characterType8,"CHAR8",system.globalScope);
  757. DeclareType(system.characterType16,"CHAR16",system.globalScope);
  758. DeclareType(system.characterType32,"CHAR32",system.globalScope);
  759. DeclareType(system.rangeType,"RANGE",system.globalScope);
  760. DeclareType(system.shortintType,"SHORTINT",system.globalScope);
  761. DeclareType(system.integerType,"INTEGER",system.globalScope);
  762. DeclareType(system.longintType,"LONGINT",system.globalScope);
  763. DeclareType(system.hugeintType,"HUGEINT",system.globalScope);
  764. DeclareType(system.wordType,"WORD",system.globalScope);
  765. DeclareType(system.longWordType,"LONGWORD",system.globalScope);
  766. DeclareType(system.wordSetType,"WORDSET",system.globalScope);
  767. DeclareType(Integer8, "SIGNED8", system.globalScope);
  768. DeclareType(Integer16, "SIGNED16", system.globalScope);
  769. DeclareType(Integer32, "SIGNED32", system.globalScope);
  770. DeclareType(Integer64, "SIGNED64", system.globalScope);
  771. DeclareType(Unsigned8, "UNSIGNED8", system.globalScope);
  772. DeclareType(Unsigned16, "UNSIGNED16", system.globalScope);
  773. DeclareType(Unsigned32, "UNSIGNED32", system.globalScope);
  774. DeclareType(Unsigned64, "UNSIGNED64", system.globalScope);
  775. DeclareType(system.realType,"REAL",system.globalScope);
  776. DeclareType(system.longrealType,"LONGREAL",system.globalScope);
  777. DeclareType(system.complexType,"COMPLEX",system.globalScope);
  778. DeclareType(system.longcomplexType,"LONGCOMPLEX",system.globalScope);
  779. DeclareType(system.booleanType,"BOOLEAN",system.globalScope);
  780. DeclareType(system.setType,"SET",system.globalScope);
  781. DeclareType(system.anyType,"ANY",system.globalScope);
  782. DeclareType(system.objectType,"OBJECT",system.globalScope);
  783. DeclareType(Set8, "SET8", system.globalScope);
  784. DeclareType(Set16, "SET16", system.globalScope);
  785. DeclareType(Set32, "SET32", system.globalScope);
  786. DeclareType(Set64, "SET64", system.globalScope);
  787. (* global functions *)
  788. NewBuiltin(Abs,"ABS",system.globalScope,TRUE);
  789. NewBuiltin(Ash,"ASH",system.globalScope,TRUE);
  790. NewBuiltin(Asr,"ASR",system.globalScope,TRUE);
  791. NewBuiltin(Cap,"CAP",system.globalScope,TRUE);
  792. NewBuiltin(Chr,"CHR",system.globalScope,TRUE);
  793. NewBuiltin(Chr32,"CHR32",system.globalScope,TRUE);
  794. NewBuiltin(Entier,"ENTIER",system.globalScope,TRUE);
  795. NewBuiltin(Entier,"FLOOR",system.globalScope,TRUE);
  796. NewBuiltin(EntierH,"ENTIERH",system.globalScope,TRUE);
  797. NewBuiltin(Len,"LEN",system.globalScope,TRUE);
  798. NewBuiltin(Long,"LONG",system.globalScope,TRUE);
  799. NewBuiltin(Max,"MAX",system.globalScope,TRUE);
  800. NewBuiltin(Min,"MIN",system.globalScope,TRUE);
  801. NewBuiltin(Odd,"ODD",system.globalScope,TRUE);
  802. NewBuiltin(Ord,"ORD",system.globalScope,TRUE);
  803. NewBuiltin(Ord32,"ORD32",system.globalScope,TRUE);
  804. NewBuiltin(Lsh,"LSH",system.globalScope,TRUE);
  805. NewBuiltin(Lsh,"LSL",system.globalScope,TRUE);
  806. NewBuiltin(Rot,"ROT",system.globalScope,TRUE);
  807. NewBuiltin(Ror,"ROR",system.globalScope,TRUE);
  808. NewBuiltin(Incr,"INCR",system.globalScope,TRUE);
  809. NewBuiltin(Short,"SHORT",system.globalScope,TRUE);
  810. NewBuiltin(Sum,"SUM",system.globalScope,TRUE);
  811. NewBuiltin(Dim,"DIM",system.globalScope,TRUE);
  812. NewBuiltin(Cas,"CAS",system.globalScope,TRUE);
  813. NewBuiltin(First,"FIRST",system.globalScope,TRUE);
  814. NewBuiltin(Last,"LAST",system.globalScope,TRUE);
  815. NewBuiltin(Step,"STEP",system.globalScope,TRUE);
  816. NewBuiltin(Re,"RE",system.globalScope,TRUE);
  817. NewBuiltin(Im,"IM",system.globalScope,TRUE);
  818. NewBuiltin(systemAdr,"ADDRESSOF",system.globalScope,TRUE);
  819. NewBuiltin(systemSize,"SIZEOF",system.globalScope,TRUE);
  820. (* global proper procedures *)
  821. NewBuiltin(Assert,"ASSERT",system.globalScope,TRUE);
  822. NewBuiltin(Copy,"COPY",system.globalScope,TRUE);
  823. NewBuiltin(Dec,"DEC",system.globalScope,TRUE);
  824. NewBuiltin(Excl,"EXCL",system.globalScope,TRUE);
  825. NewBuiltin(Halt,"HALT",system.globalScope,TRUE);
  826. NewBuiltin(Inc,"INC",system.globalScope,TRUE);
  827. NewBuiltin(Incl,"INCL",system.globalScope,TRUE);
  828. NewBuiltin(New,"NEW",system.globalScope,FALSE);
  829. NewBuiltin(Dispose,"DISPOSE",system.globalScope, FALSE);
  830. NewBuiltin(GetProcedure,"GETPROCEDURE",system.globalScope,TRUE);
  831. NewBuiltin(systemTrace,"TRACE",system.globalScope,TRUE);
  832. NewBuiltin(Reshape,"RESHAPE",system.globalScope,TRUE);
  833. NewBuiltin(All,"ALL",system.globalScope,TRUE);
  834. NewBuiltin(Wait,"WAIT",system.globalScope,FALSE);
  835. NewBuiltin(Connect,"CONNECT",system.globalScope,FALSE);
  836. NewBuiltin(Receive,"RECEIVE",system.globalScope,FALSE);
  837. NewBuiltin(Send,"SEND",system.globalScope,FALSE);
  838. NewBuiltin(Delegate,"DELEGATE",system.globalScope,FALSE);
  839. NewBuiltin(IncMul,"INCMUL",system.globalScope,TRUE);
  840. NewBuiltin(DecMul,"DECMUL",system.globalScope,TRUE);
  841. (*!
  842. (* Following is LYNX version: *)
  843. IF minBits = 8 THEN
  844. system.characterType := Character16;
  845. END;
  846. (* LYNX builtin types *)
  847. DeclareLynxType(system.characterType, LynxChar, system.globalScope);
  848. DeclareLynxType(system.shortintType, LynxSbyte, system.globalScope);
  849. DeclareLynxType(system.integerType, LynxShort, system.globalScope);
  850. DeclareLynxType(system.longintType, LynxInt, system.globalScope);
  851. DeclareLynxType(system.hugeintType, LynxLong, system.globalScope);
  852. DeclareLynxType(system.realType, LynxFloat, system.globalScope);
  853. DeclareLynxType(system.longrealType, LynxDouble, system.globalScope);
  854. DeclareLynxType(system.booleanType, LynxBool, system.globalScope);
  855. (* TODO: object, string *)
  856. (* LYNX global functions *)
  857. NewBuiltin(SymLynxNewobj, LynxNewobj, system.globalScope, TRUE);
  858. NewBuiltin(SymLynxNewarr, LynxNewarr, system.globalScope, TRUE);
  859. NewBuiltin(SymLynxAsop, LynxAsop, system.globalScope, TRUE);
  860. NewBuiltin(SymLynxUnop, LynxUnop, system.globalScope, TRUE);
  861. NewBuiltin(SymLynxBinop, LynxBinop, system.globalScope, TRUE);
  862. NewBuiltin(SymLynxRecvnb, LynxRecvnb, system.globalScope, TRUE);
  863. (*
  864. LynxCompiler will register builtins for send/receive/connect/delegate
  865. under "lynx@*" names but with their original Fox numeric identifiers,
  866. so that no modifications will be required in the semantic checker and
  867. intermediate backend.
  868. *)
  869. NewBuiltin(SymLynxNewsel, LynxNewsel, system.globalScope, TRUE);
  870. NewBuiltin(SymLynxAddsel, LynxAddsel, system.globalScope, TRUE);
  871. NewBuiltin(SymLynxSelect, LynxSelect, system.globalScope, TRUE);
  872. NewBuiltin(SymLynxSelidx, LynxSelidx, system.globalScope, TRUE);
  873. *)
  874. END SetDefaultDeclarations;
  875. PROCEDURE OperatorDefined*(system: System; op: LONGINT; defined: BOOLEAN);
  876. BEGIN
  877. system.operatorDefined[op] := defined;
  878. END OperatorDefined;
  879. PROCEDURE SetDefaultOperators*(system: System);
  880. VAR i: LONGINT;
  881. BEGIN
  882. FOR i := Scanner.Equal TO Scanner.Not DO
  883. OperatorDefined(system,i,TRUE);
  884. END;
  885. OperatorDefined(system, Conversion, TRUE);
  886. OperatorDefined(system, DotTimesPlus, TRUE);
  887. OperatorDefined(system, AtMulDec, TRUE);
  888. OperatorDefined(system, AtMulInc, TRUE);
  889. OperatorDefined(system, DecMul, TRUE);
  890. OperatorDefined(system, IncMul, TRUE);
  891. OperatorDefined(system,Scanner.Transpose,TRUE);
  892. OperatorDefined(system,Scanner.Becomes,TRUE);
  893. OperatorDefined(system,Dec,TRUE);
  894. OperatorDefined(system,Excl,TRUE);
  895. OperatorDefined(system,Inc,TRUE);
  896. OperatorDefined(system,Incl,TRUE);
  897. OperatorDefined(system,Abs,TRUE);
  898. OperatorDefined(system,Ash,TRUE);
  899. OperatorDefined(system,Cap,TRUE);
  900. OperatorDefined(system,Chr,TRUE);
  901. OperatorDefined(system,Entier,TRUE);
  902. OperatorDefined(system,EntierH,TRUE);
  903. OperatorDefined(system,Len,TRUE);
  904. OperatorDefined(system,Long,TRUE);
  905. OperatorDefined(system,Max,TRUE);
  906. OperatorDefined(system,Min,TRUE);
  907. OperatorDefined(system,Odd,TRUE);
  908. OperatorDefined(system,Short,TRUE);
  909. OperatorDefined(system,Sum,TRUE);
  910. OperatorDefined(system,Dim,TRUE);
  911. OperatorDefined(system,Scanner.Address, TRUE);
  912. OperatorDefined(system,Scanner.Size, TRUE);
  913. OperatorDefined(system,Scanner.Alias, TRUE);
  914. OperatorDefined(system,All,TRUE);
  915. OperatorDefined(system,Re,TRUE);
  916. OperatorDefined(system,Im,TRUE);
  917. OperatorDefined(system, Scanner.Questionmarks, TRUE);
  918. OperatorDefined(system, Scanner.GreaterGreater, TRUE);
  919. OperatorDefined(system, Scanner.LessLess, TRUE);
  920. END SetDefaultOperators;
  921. PROCEDURE DefaultSystem*(): System;
  922. VAR system: System;
  923. BEGIN
  924. NEW(system,8,8,32, 8,32,32,32,64,FALSE);
  925. SetDefaultDeclarations(system,8);
  926. SetDefaultOperators(system);
  927. RETURN system
  928. END DefaultSystem;
  929. PROCEDURE IsOberonProcedure*(type: SyntaxTree.Type): BOOLEAN;
  930. BEGIN
  931. RETURN (type IS SyntaxTree.ProcedureType) & (type(SyntaxTree.ProcedureType).callingConvention = SyntaxTree.OberonCallingConvention)
  932. END IsOberonProcedure;
  933. PROCEDURE AlignedSizeOf*(system: System; CONST alignment: Alignment; type: SyntaxTree.Type):LONGINT;
  934. VAR value: LONGINT;
  935. BEGIN
  936. value := SHORT(system.SizeOf(type));
  937. INC(value, (-value) MOD system.AlignmentOf(alignment, type));
  938. RETURN value;
  939. END AlignedSizeOf;
  940. (* returns if a module is the system module *)
  941. PROCEDURE IsSystemModule*(module: SyntaxTree.Module): BOOLEAN;
  942. BEGIN RETURN (module.name=systemName) OR (module.name=SystemName)
  943. END IsSystemModule;
  944. (** Various factories *)
  945. PROCEDURE DeclareType0(type: SyntaxTree.Type; CONST name: ARRAY OF CHAR; in: SyntaxTree.Scope);
  946. VAR basic: SyntaxTree.TypeDeclaration; duplicate: BOOLEAN;
  947. BEGIN
  948. basic := SyntaxTree.NewTypeDeclaration(SyntaxTree.invalidPosition,SyntaxTree.NewIdentifier(name));
  949. basic.SetDeclaredType(type);
  950. basic.SetState(SyntaxTree.Resolved);
  951. basic.SetAccess(SyntaxTree.ReadOnly);
  952. in.AddTypeDeclaration(basic);
  953. in.EnterSymbol(basic,duplicate);
  954. ASSERT(~duplicate);
  955. END DeclareType0;
  956. (** External interface backends can use to add their types etc. to the global scope *)
  957. PROCEDURE DeclareType*(type: SyntaxTree.Type; CONST name: ARRAY OF CHAR; CONST scope: ARRAY OF SyntaxTree.ModuleScope);
  958. VAR nameL,nameU: Scanner.IdentifierString;
  959. BEGIN
  960. Basic.Lowercase(name,nameL);
  961. Basic.Uppercase(name,nameU);
  962. DeclareType0(type,nameU,scope[Scanner.Uppercase]);
  963. DeclareType0(type,nameL,scope[Scanner.Lowercase]);
  964. END DeclareType;
  965. (* LYNX+ *)
  966. PROCEDURE DeclareLynxType*(
  967. type: SyntaxTree.Type; CONST name: ARRAY OF CHAR; CONST scope: ARRAY OF SyntaxTree.ModuleScope);
  968. BEGIN
  969. DeclareType0(type, name, scope[Scanner.Uppercase]);
  970. DeclareType0(type, name, scope[Scanner.Lowercase]);
  971. END DeclareLynxType;
  972. (* -LYNX *)
  973. PROCEDURE NewConstant0(CONST name: ARRAY OF CHAR; int: LONGINT; type: SyntaxTree.Type; in: SyntaxTree.Scope);
  974. VAR constant: SyntaxTree.Constant; value: SyntaxTree.IntegerValue;duplicate: BOOLEAN;
  975. BEGIN
  976. value := SyntaxTree.NewIntegerValue(SyntaxTree.invalidPosition,int);
  977. value.SetType(type);
  978. constant := SyntaxTree.NewConstant(SyntaxTree.invalidPosition,SyntaxTree.NewIdentifier(name));
  979. constant.SetValue(value);
  980. constant.SetType(value.type);
  981. constant.SetAccess(SyntaxTree.ReadOnly);
  982. constant.SetState(SyntaxTree.Resolved);
  983. in.AddConstant(constant);
  984. in.EnterSymbol(constant,duplicate);
  985. ASSERT(~duplicate);
  986. END NewConstant0;
  987. PROCEDURE NewConstant*(CONST name: ARRAY OF CHAR; int: LONGINT; type: SyntaxTree.Type; CONST scope: ARRAY OF SyntaxTree.ModuleScope);
  988. VAR nameL,nameU: Scanner.IdentifierString;
  989. BEGIN
  990. Basic.Lowercase(name,nameL);
  991. Basic.Uppercase(name,nameU);
  992. NewConstant0(nameU,int,type,scope[Scanner.Uppercase]);
  993. NewConstant0(nameL,int,type,scope[Scanner.Lowercase]);
  994. END NewConstant;
  995. PROCEDURE NewStringConstant0(CONST name: ARRAY OF CHAR; string: SyntaxTree.String; baseType: SyntaxTree.Type; in: SyntaxTree.Scope);
  996. VAR constant: SyntaxTree.Constant; value: SyntaxTree.StringValue;duplicate: BOOLEAN;
  997. BEGIN
  998. value := SyntaxTree.NewStringValue(SyntaxTree.invalidPosition,string);
  999. value.SetType(SyntaxTree.NewStringType(SyntaxTree.invalidPosition,baseType,value.length));
  1000. constant := SyntaxTree.NewConstant(SyntaxTree.invalidPosition,SyntaxTree.NewIdentifier(name));
  1001. constant.SetValue(value);
  1002. constant.SetType(value.type);
  1003. constant.SetAccess(SyntaxTree.ReadOnly);
  1004. constant.SetState(SyntaxTree.Resolved);
  1005. in.AddConstant(constant);
  1006. in.EnterSymbol(constant,duplicate);
  1007. ASSERT(~duplicate);
  1008. END NewStringConstant0;
  1009. PROCEDURE NewStringConstant*(CONST name: ARRAY OF CHAR; string: SyntaxTree.String; type: SyntaxTree.Type; CONST scope: ARRAY OF SyntaxTree.ModuleScope);
  1010. VAR nameL,nameU: Scanner.IdentifierString;
  1011. BEGIN
  1012. Basic.Lowercase(name,nameL);
  1013. Basic.Uppercase(name,nameU);
  1014. NewStringConstant0(nameU,string,type,scope[Scanner.Uppercase]);
  1015. NewStringConstant0(nameL,string,type,scope[Scanner.Lowercase]);
  1016. END NewStringConstant;
  1017. PROCEDURE NewStringConstantCamelCase*(CONST name: ARRAY OF CHAR; string: SyntaxTree.String; type: SyntaxTree.Type; CONST scope: ARRAY OF SyntaxTree.ModuleScope);
  1018. BEGIN
  1019. NewStringConstant0(name,string,type,scope[Scanner.Uppercase]);
  1020. NewStringConstant0(name,string,type,scope[Scanner.Lowercase]);
  1021. END NewStringConstantCamelCase;
  1022. PROCEDURE NewBuiltin0( id: LONGINT; CONST name: ARRAY OF CHAR; in: SyntaxTree.ModuleScope; realtime: BOOLEAN);
  1023. VAR basic: SyntaxTree.Builtin; duplicate: BOOLEAN; type: SyntaxTree.ProcedureType;
  1024. BEGIN
  1025. basic := SyntaxTree.NewBuiltin(SyntaxTree.invalidPosition,SyntaxTree.NewIdentifier(name),id);
  1026. basic.SetAccess(SyntaxTree.ReadOnly);
  1027. type := SyntaxTree.NewProcedureType(SyntaxTree.invalidPosition,in);
  1028. type.SetRealtime(realtime);
  1029. type.SetReturnType(SyntaxTree.invalidType); (* make incompatible to any procedure *)
  1030. basic.SetType(type);
  1031. basic.SetState(SyntaxTree.Resolved);
  1032. in.EnterSymbol(basic,duplicate);
  1033. in.AddBuiltin(basic);
  1034. ASSERT(~duplicate);
  1035. END NewBuiltin0;
  1036. PROCEDURE NewBuiltin*(id: LONGINT; CONST name: ARRAY OF CHAR; CONST scope: ARRAY OF SyntaxTree.ModuleScope; realtime: BOOLEAN);
  1037. VAR nameL,nameU: Scanner.IdentifierString;
  1038. BEGIN
  1039. Basic.Lowercase(name,nameL);
  1040. Basic.Uppercase(name,nameU);
  1041. NewBuiltin0(id,nameU,scope[Scanner.Uppercase],realtime);
  1042. NewBuiltin0(id,nameL,scope[Scanner.Lowercase],realtime);
  1043. END NewBuiltin;
  1044. PROCEDURE NewBuiltinCamelCase*(id: LONGINT; CONST name: ARRAY OF CHAR; CONST scope: ARRAY OF SyntaxTree.ModuleScope; realtime: BOOLEAN);
  1045. BEGIN
  1046. NewBuiltin0(id,name,scope[Scanner.Uppercase],realtime);
  1047. NewBuiltin0(id,name,scope[Scanner.Lowercase],realtime);
  1048. END NewBuiltinCamelCase;
  1049. PROCEDURE NewCustomBuiltin0(CONST name: ARRAY OF CHAR; scope: SyntaxTree.ModuleScope; subType: SHORTINT; procedureType: SyntaxTree.ProcedureType);
  1050. VAR
  1051. isDuplicate: BOOLEAN;
  1052. customBuiltin: SyntaxTree.CustomBuiltin;
  1053. BEGIN
  1054. customBuiltin := SyntaxTree.NewCustomBuiltin(SyntaxTree.invalidPosition, SyntaxTree.NewIdentifier(name), systemSpecial, subType);
  1055. customBuiltin.SetAccess(SyntaxTree.ReadOnly); (* TODO: this might be changed *)
  1056. procedureType.SetRealtime(TRUE);
  1057. customBuiltin.SetType(procedureType); (* TODO: make incompatible to any procedure *)
  1058. customBuiltin.SetState(SyntaxTree.Resolved);
  1059. scope.EnterSymbol(customBuiltin, isDuplicate);
  1060. scope.AddBuiltin(customBuiltin);
  1061. ASSERT(~isDuplicate)
  1062. END NewCustomBuiltin0;
  1063. PROCEDURE NewCustomBuiltin*(CONST name: ARRAY OF CHAR; CONST scope: ARRAY OF SyntaxTree.ModuleScope; subType: SHORTINT; procedureType: SyntaxTree.ProcedureType);
  1064. VAR
  1065. nameL, nameU: Scanner.IdentifierString;
  1066. BEGIN
  1067. Basic.Lowercase(name, nameL);
  1068. Basic.Uppercase(name, nameU);
  1069. NewCustomBuiltin0(nameU, scope[Scanner.Uppercase], subType, procedureType);
  1070. NewCustomBuiltin0(nameL, scope[Scanner.Lowercase], subType, procedureType)
  1071. END NewCustomBuiltin;
  1072. PROCEDURE GetModuleSectionName*(name, context: SyntaxTree.Identifier; VAR n: ARRAY OF CHAR);
  1073. VAR s: SyntaxTree.IdentifierString;
  1074. BEGIN
  1075. IF context # SyntaxTree.invalidIdentifier THEN
  1076. Basic.GetString(context,n);
  1077. IF n = "A2" THEN
  1078. Basic.GetString(name,n);
  1079. RETURN;
  1080. END;
  1081. Basic.GetString(name,s);
  1082. Strings.Append(n,"-");Strings.Append(n,s);
  1083. ELSE
  1084. IF name # SyntaxTree.invalidIdentifier THEN
  1085. Basic.GetString(name,n);
  1086. ELSE
  1087. n := ""
  1088. END
  1089. END;
  1090. END GetModuleSectionName;
  1091. PROCEDURE ModuleFileName*(name, context: SyntaxTree.Identifier; VAR n: ARRAY OF CHAR);
  1092. BEGIN
  1093. GetModuleSectionName(name, context, n);
  1094. END ModuleFileName;
  1095. PROCEDURE ModuleSectionIdentifier*(name, context: SyntaxTree.Identifier): SyntaxTree.Identifier;
  1096. VAR n: SyntaxTree.IdentifierString;
  1097. BEGIN
  1098. IF context # SyntaxTree.invalidIdentifier THEN
  1099. GetModuleSectionName(name, context, n);
  1100. RETURN SyntaxTree.NewIdentifier(n);
  1101. ELSE
  1102. RETURN name
  1103. END;
  1104. END ModuleSectionIdentifier;
  1105. PROCEDURE ContextFromName*(CONST fileName: ARRAY OF CHAR; VAR module,context: SyntaxTree.Identifier);
  1106. VAR moduleName, contextName: Scanner.IdentifierString; i,j: LONGINT;
  1107. BEGIN
  1108. i := 0; j := 0;
  1109. WHILE (fileName[i] # 0X) & (fileName[i] # ".") DO
  1110. moduleName[i] := fileName[i];
  1111. INC(i);
  1112. END;
  1113. moduleName[i] := 0X;
  1114. IF fileName[i] # 0X THEN
  1115. COPY(moduleName, contextName);
  1116. INC(i);
  1117. WHILE(fileName[i] # 0X) DO
  1118. moduleName[j] := fileName[i];
  1119. INC(i); INC(j);
  1120. END;
  1121. moduleName[j] := 0X;
  1122. ELSE
  1123. contextName := "A2";
  1124. END;
  1125. module := SyntaxTree.NewIdentifier(moduleName);
  1126. context := SyntaxTree.NewIdentifier(contextName);
  1127. END ContextFromName;
  1128. PROCEDURE GetModuleName*(module: SyntaxTree.Module; VAR name: ARRAY OF CHAR);
  1129. BEGIN
  1130. GetModuleSectionName(module.name, module.context, name);
  1131. END GetModuleName;
  1132. PROCEDURE GetModuleSegmentedName*(module: SyntaxTree.Module; VAR name: Basic.SegmentedName);
  1133. BEGIN
  1134. name[0] := ModuleSectionIdentifier(module.name, module.context);
  1135. name[1] := -1;
  1136. END GetModuleSegmentedName;
  1137. PROCEDURE FindSymbol*(CONST name: Basic.SegmentedName; scope: SyntaxTree.Scope): SyntaxTree.Symbol;
  1138. VAR s: LONGINT; symbol : SyntaxTree.Symbol;
  1139. PROCEDURE GetSymbolScope;
  1140. VAR type: SyntaxTree.Type;
  1141. BEGIN
  1142. IF symbol IS SyntaxTree.Module THEN
  1143. scope := symbol(SyntaxTree.Module).moduleScope
  1144. ELSIF symbol IS SyntaxTree.Import THEN
  1145. scope := symbol(SyntaxTree.Import).module.moduleScope;
  1146. ELSIF symbol IS SyntaxTree.Procedure THEN
  1147. scope := symbol(SyntaxTree.Procedure).procedureScope
  1148. ELSIF symbol IS SyntaxTree.TypeDeclaration THEN
  1149. type := symbol(SyntaxTree.TypeDeclaration).declaredType.resolved;
  1150. IF type IS SyntaxTree.RecordType THEN
  1151. scope := type(SyntaxTree.RecordType).recordScope
  1152. END;
  1153. ELSE
  1154. scope := NIL
  1155. END
  1156. END GetSymbolScope;
  1157. PROCEDURE FindSymbol(name: SyntaxTree.Identifier): SyntaxTree.Symbol;
  1158. BEGIN
  1159. IF scope = scope.ownerModule.moduleScope THEN
  1160. symbol := scope.ownerModule.moduleScope.ImportByModuleName(name, scope.ownerModule.context);
  1161. IF symbol = NIL THEN
  1162. symbol := scope.FindSymbol(name)
  1163. END;
  1164. ELSE
  1165. symbol := scope.FindSymbol(name)
  1166. END;
  1167. RETURN symbol
  1168. END FindSymbol;
  1169. BEGIN
  1170. s := 0;
  1171. IF name[0] = scope.ownerModule.name THEN
  1172. INC(s)
  1173. END;
  1174. scope := scope.ownerModule.moduleScope; (* expect fully qualified (segmented) name *)
  1175. REPEAT
  1176. IF scope = NIL THEN RETURN NIL END;
  1177. symbol := FindSymbol(name[s]);
  1178. IF symbol = NIL THEN RETURN NIL
  1179. ELSE
  1180. GetSymbolScope
  1181. END;
  1182. INC(s);
  1183. UNTIL (s = LEN(name)) OR (name[s] < 0);
  1184. RETURN symbol;
  1185. END FindSymbol;
  1186. PROCEDURE GetSymbolNameInScope*(symbol: SyntaxTree.Symbol; inScope: SyntaxTree.Scope; VAR name: ARRAY OF CHAR);
  1187. VAR n: SyntaxTree.IdentifierString; td: SyntaxTree.TypeDeclaration;
  1188. PROCEDURE Scope(scope: SyntaxTree.Scope);
  1189. BEGIN
  1190. IF scope = NIL THEN (* do nothing, locally declared temporary symbol *)
  1191. ELSIF scope = inScope THEN (* do not traverse further *)
  1192. ELSIF scope IS SyntaxTree.ModuleScope THEN
  1193. GetModuleName(scope.ownerModule, name);
  1194. Strings.Append(name,".");
  1195. ELSIF scope IS SyntaxTree.RecordScope THEN
  1196. Scope(scope.outerScope);
  1197. td := scope(SyntaxTree.RecordScope).ownerRecord.typeDeclaration;
  1198. IF td = NIL THEN
  1199. td := scope(SyntaxTree.RecordScope).ownerRecord.pointerType.typeDeclaration;
  1200. END;
  1201. td.GetName(n);
  1202. Strings.Append(name,n); Strings.Append(name,".")
  1203. ELSIF scope IS SyntaxTree.ProcedureScope THEN
  1204. Scope(scope.outerScope);
  1205. scope(SyntaxTree.ProcedureScope).ownerProcedure.GetName(n);
  1206. Strings.Append(name,n); Strings.Append(name,".")
  1207. ELSIF scope IS SyntaxTree.CellScope THEN
  1208. Scope(scope.outerScope);
  1209. td := scope(SyntaxTree.CellScope).ownerCell.typeDeclaration;
  1210. td.GetName(n);
  1211. Strings.Append(name,n); Strings.Append(name,".")
  1212. END;
  1213. END Scope;
  1214. BEGIN
  1215. name := "";
  1216. Scope(symbol.scope);
  1217. symbol.GetName(n);
  1218. IF symbol IS SyntaxTree.Operator THEN (*! append some more bits to make discrimintation possible *)
  1219. END;
  1220. Strings.Append(name,n);
  1221. END GetSymbolNameInScope;
  1222. PROCEDURE GetSymbolName*(symbol: SyntaxTree.Symbol; VAR name: ARRAY OF CHAR);
  1223. BEGIN GetSymbolNameInScope(symbol,NIL,name)
  1224. END GetSymbolName;
  1225. PROCEDURE GetSymbolSegmentedNameInScope*(symbol: SyntaxTree.Symbol; inScope: SyntaxTree.Scope; VAR pooledName: Basic.SegmentedName);
  1226. VAR td: SyntaxTree.TypeDeclaration; i: LONGINT;
  1227. PROCEDURE Scope(scope: SyntaxTree.Scope);
  1228. BEGIN
  1229. IF scope = NIL THEN (* do nothing, locally declared temporary symbol *)
  1230. ELSIF scope = inScope THEN (* do not traverse further *)
  1231. ELSIF scope IS SyntaxTree.ModuleScope THEN
  1232. Basic.SuffixSegmentedName(pooledName,ModuleSectionIdentifier(scope.ownerModule.name, scope.ownerModule.context));
  1233. ELSIF scope IS SyntaxTree.RecordScope THEN
  1234. Scope(scope.outerScope);
  1235. td := scope(SyntaxTree.RecordScope).ownerRecord.typeDeclaration;
  1236. IF td = NIL THEN
  1237. td := scope(SyntaxTree.RecordScope).ownerRecord.pointerType.typeDeclaration;
  1238. END;
  1239. Basic.SuffixSegmentedName(pooledName,td.name);
  1240. ELSIF scope IS SyntaxTree.ProcedureScope THEN
  1241. Scope(scope.outerScope);
  1242. Basic.SuffixSegmentedName(pooledName,scope(SyntaxTree.ProcedureScope).ownerProcedure.name);
  1243. ELSIF scope IS SyntaxTree.CellScope THEN
  1244. Scope(scope.outerScope);
  1245. td := scope(SyntaxTree.CellScope).ownerCell.typeDeclaration;
  1246. Basic.SuffixSegmentedName(pooledName, td.name);
  1247. END;
  1248. END Scope;
  1249. BEGIN
  1250. FOR i := 0 TO LEN(pooledName)-1 DO pooledName[i] := -1 END;
  1251. Scope(symbol.scope);
  1252. Basic.SuffixSegmentedName(pooledName, symbol.name);
  1253. END GetSymbolSegmentedNameInScope;
  1254. PROCEDURE GetSymbolSegmentedName*(symbol: SyntaxTree.Symbol; VAR pooledName: Basic.SegmentedName);
  1255. BEGIN
  1256. GetSymbolSegmentedNameInScope(symbol,NIL,pooledName);
  1257. END GetSymbolSegmentedName;
  1258. PROCEDURE Level*(t: SyntaxTree.Type): LONGINT;
  1259. VAR level: LONGINT;
  1260. BEGIN
  1261. IF t IS SyntaxTree.IntegerType THEN
  1262. CASE t.sizeInBits OF
  1263. 8: level := 0;
  1264. |16: level := 1;
  1265. |32: level := 2;
  1266. |64: level := 3;
  1267. END;
  1268. ELSIF t IS SyntaxTree.FloatType THEN
  1269. CASE t.sizeInBits OF
  1270. 32: level := 4;
  1271. |64: level := 5;
  1272. END
  1273. ELSE HALT(100)
  1274. END;
  1275. RETURN level
  1276. END Level;
  1277. PROCEDURE ConvertSigned*(this: HUGEINT; bits: LONGINT): HUGEINT;
  1278. BEGIN
  1279. bits := 64-bits;
  1280. RETURN ASH (ASH (this, bits), -bits);
  1281. END ConvertSigned;
  1282. PROCEDURE ConvertUnsigned*(this: HUGEINT; bits: LONGINT): HUGEINT;
  1283. BEGIN
  1284. bits := 64-bits;
  1285. RETURN LSH (LSH (this, bits), -bits);
  1286. END ConvertUnsigned;
  1287. PROCEDURE MaxInteger*(system: System; type: SyntaxTree.BasicType; signed: BOOLEAN): HUGEINT;
  1288. BEGIN
  1289. IF signed THEN
  1290. RETURN ASH (HUGEINT(1), system.SizeOf (type) - 1) - 1;
  1291. ELSE
  1292. RETURN LSH (HUGEINT(-1), system.SizeOf (type) - 64);
  1293. END;
  1294. END MaxInteger;
  1295. PROCEDURE MinInteger*(system: System; type: SyntaxTree.BasicType; signed: BOOLEAN): HUGEINT;
  1296. BEGIN
  1297. IF signed THEN
  1298. RETURN -ASH (HUGEINT(1), system.SizeOf (type) - 1);
  1299. ELSE
  1300. RETURN 0
  1301. END;
  1302. END MinInteger;
  1303. (*! make architecture independent ! *)
  1304. PROCEDURE MaxFloat*(system: System; type: SyntaxTree.FloatType): LONGREAL;
  1305. BEGIN
  1306. IF system.SizeOf(type) = 32 THEN RETURN MAX(REAL) ELSE RETURN MAX(LONGREAL) END;
  1307. END MaxFloat;
  1308. PROCEDURE MinFloat*(system: System; type: SyntaxTree.FloatType): LONGREAL;
  1309. BEGIN
  1310. IF system.SizeOf(type) = 32 THEN RETURN MIN(REAL) ELSE RETURN MIN(LONGREAL) END;
  1311. END MinFloat;
  1312. PROCEDURE ConvertSet*(this: Basic.Set; bits: LONGINT): Basic.Set;
  1313. BEGIN
  1314. WHILE bits <= MAX (Basic.Set) DO EXCL (this, bits); INC (bits) END;
  1315. RETURN this;
  1316. END ConvertSet;
  1317. PROCEDURE IsUnsignedInteger*(this: HUGEINT; sizeInBits: LONGINT): BOOLEAN;
  1318. VAR m: HUGEINT;
  1319. BEGIN
  1320. m := ASH(HUGEINT(1),sizeInBits);
  1321. RETURN (this >= 0) & (this < m)
  1322. END IsUnsignedInteger;
  1323. PROCEDURE IsSignedInteger*(this: HUGEINT; sizeInBits: LONGINT): BOOLEAN;
  1324. VAR m: HUGEINT;
  1325. BEGIN
  1326. m := ASH(HUGEINT(1),sizeInBits-1);
  1327. RETURN (this < m) & (-this <= m)
  1328. END IsSignedInteger;
  1329. PROCEDURE GetSignedIntegerType*(system: System; this: HUGEINT): SyntaxTree.IntegerType;
  1330. (* code snippets for unsigned
  1331. ELSE
  1332. m := Builtins.AslH(1,system.SizeOf(type));
  1333. RETURN (this >= 0) & (this < m)
  1334. END;
  1335. PROCEDURE Bits(x: HUGEINT): BOOLEAN;
  1336. BEGIN
  1337. WHILE x > 0 DO INC(bits); x := x DIV 2 END;
  1338. END Bits;
  1339. IF a = MIN(HUGEINT) THEN (* -a does not work on lowest possible number, ~a+1 would overflow *)
  1340. RETURN Integer[64]
  1341. ELSIF a < 0 THEN
  1342. RETURN Integer[Bits(-a-1)+1]
  1343. ELSE
  1344. RETURN Unisgned[Bits(a)]
  1345. END;
  1346. *)
  1347. BEGIN
  1348. IF IsSignedInteger(this,8) THEN RETURN Integer8
  1349. ELSIF IsSignedInteger(this, 16) THEN RETURN Integer16
  1350. ELSIF IsSignedInteger(this, 32) THEN RETURN Integer32
  1351. ELSE RETURN Integer64
  1352. END;
  1353. END GetSignedIntegerType;
  1354. PROCEDURE GetIntegerType*(system: System; this: HUGEINT): SyntaxTree.IntegerType;
  1355. BEGIN
  1356. IF IsSignedInteger(this,8) THEN RETURN Integer8
  1357. (* system.SizeOf(...) = 8 : detect special backends with no sizes smaller than 32 *)
  1358. ELSIF (system.SizeOf(Unsigned8) = 8) & IsUnsignedInteger(this,8) THEN RETURN Unsigned8
  1359. ELSIF IsSignedInteger(this, 16) THEN RETURN Integer16
  1360. ELSIF (system.SizeOf(Unsigned16) = 16) & IsUnsignedInteger(this,16) THEN RETURN Unsigned16
  1361. ELSIF IsSignedInteger(this, 32) THEN RETURN Integer32
  1362. ELSIF IsUnsignedInteger(this,32) THEN RETURN Unsigned32
  1363. ELSE RETURN Integer64
  1364. END;
  1365. END GetIntegerType;
  1366. PROCEDURE NewIntegerValue*(system: System; position: Position; hugeint: HUGEINT): SyntaxTree.Value;
  1367. VAR value: SyntaxTree.IntegerValue;
  1368. BEGIN
  1369. value := SyntaxTree.NewIntegerValue(position,hugeint);
  1370. value.SetType(GetIntegerType(system,hugeint));
  1371. RETURN value
  1372. END NewIntegerValue;
  1373. PROCEDURE NewBooleanValue*(system: System; position: Position; b: BOOLEAN): SyntaxTree.Value;
  1374. VAR value: SyntaxTree.BooleanValue;
  1375. BEGIN
  1376. value := SyntaxTree.NewBooleanValue(position,b);
  1377. value.SetType(system.booleanType);
  1378. RETURN value
  1379. END NewBooleanValue;
  1380. PROCEDURE GetSetType*(system: System; this: Basic.Set): SyntaxTree.SetType;
  1381. BEGIN
  1382. IF this * {0 .. 7} = this THEN RETURN Set8
  1383. ELSIF this * { 0 .. 15 } = this THEN RETURN Set16
  1384. ELSIF this * { 0 .. 31 } = this THEN RETURN Set32
  1385. ELSE RETURN Set64
  1386. END
  1387. END GetSetType;
  1388. PROCEDURE NewSetValue*(system: System; position: Position; s: Basic.Set): SyntaxTree.Value;
  1389. VAR value: SyntaxTree.SetValue;
  1390. BEGIN
  1391. value := SyntaxTree.NewSetValue(position,s);
  1392. value.SetType(GetSetType(system,s));
  1393. RETURN value
  1394. END NewSetValue;
  1395. PROCEDURE NewCharacterValue*(system: System; position: Position; c: CHAR): SyntaxTree.Value;
  1396. VAR value: SyntaxTree.CharacterValue;
  1397. BEGIN
  1398. value := SyntaxTree.NewCharacterValue(position,c);
  1399. value.SetType(system.characterType);
  1400. RETURN value
  1401. END NewCharacterValue;
  1402. PROCEDURE NewNilValue*(system: System; position: Position): SyntaxTree.Value;
  1403. VAR value: SyntaxTree.NilValue;
  1404. BEGIN
  1405. value := SyntaxTree.NewNilValue(position);
  1406. value.SetType(system.anyType);
  1407. RETURN value
  1408. END NewNilValue;
  1409. (* distance for assignment to <- from *)
  1410. PROCEDURE BasicTypeDistance*(system: System; from, to: SyntaxTree.BasicType): LONGINT;
  1411. VAR fromSize, toSize, distance: LONGINT;
  1412. BEGIN
  1413. fromSize := system.SizeOf(from); toSize := system.SizeOf(to);
  1414. distance := -1;
  1415. IF (from IS SyntaxTree.IntegerType) & (to IS SyntaxTree.IntegerType) & (toSize >= fromSize) THEN
  1416. IF from(SyntaxTree.IntegerType).signed # to(SyntaxTree.IntegerType).signed THEN
  1417. IF (toSize=fromSize) & to(SyntaxTree.IntegerType).signed THEN
  1418. distance := MIN(LONGINT)
  1419. ELSE
  1420. INC(distance,2);
  1421. END;
  1422. END;
  1423. WHILE toSize >= fromSize DO
  1424. toSize := toSize DIV 2; INC(distance);
  1425. END;
  1426. ELSIF (from IS SyntaxTree.IntegerType) & (to IS SyntaxTree.SizeType) & (toSize >= fromSize) THEN
  1427. distance := 1;
  1428. WHILE toSize >= fromSize DO
  1429. toSize := toSize DIV 2; INC(distance);
  1430. END;
  1431. ELSIF (from IS SyntaxTree.SizeType) & (to IS SyntaxTree.IntegerType) & (toSize >= fromSize) THEN
  1432. distance := 1;
  1433. WHILE toSize >= fromSize DO
  1434. toSize := toSize DIV 2; INC(distance);
  1435. END;
  1436. ELSIF (from IS SyntaxTree.CharacterType) & (to IS SyntaxTree.CharacterType) & (toSize >= fromSize) OR
  1437. (from IS SyntaxTree.FloatType) & (to IS SyntaxTree.FloatType) & (toSize >= fromSize) OR
  1438. (from IS SyntaxTree.SetType) & (to IS SyntaxTree.SetType) & (toSize >= fromSize)
  1439. THEN
  1440. WHILE toSize >= fromSize DO
  1441. toSize := toSize DIV 2; INC(distance);
  1442. END;
  1443. ELSIF (from IS SyntaxTree.IntegerType) & (to IS SyntaxTree.FloatType) THEN
  1444. IF toSize = 64 THEN distance := 1 ELSE distance := 0 END;
  1445. toSize := 64;
  1446. WHILE toSize >= fromSize DO
  1447. toSize := toSize DIV 2; INC(distance);
  1448. END;
  1449. ELSIF (from IS SyntaxTree.SizeType) & (to IS SyntaxTree.FloatType) THEN
  1450. distance := 1;
  1451. WHILE toSize >= fromSize DO
  1452. toSize := toSize DIV 2; INC(distance);
  1453. END;
  1454. ELSIF (from IS SyntaxTree.RangeType) & (to IS SyntaxTree.RangeType) THEN
  1455. distance := 0;
  1456. ELSIF (from IS SyntaxTree.BooleanType) & (to IS SyntaxTree.BooleanType) THEN
  1457. distance := 0;
  1458. END;
  1459. IF distance < 0 THEN distance := MAX(LONGINT) END;
  1460. RETURN distance
  1461. END BasicTypeDistance;
  1462. PROCEDURE GetIdentifier*(symbol: LONGINT; case: LONGINT): SyntaxTree.Identifier;
  1463. BEGIN
  1464. IF (symbol >= 0) & (symbol < LEN(identifiers,1)) THEN
  1465. RETURN identifiers[case,symbol]
  1466. ELSE
  1467. RETURN SyntaxTree.invalidIdentifier
  1468. END;
  1469. END GetIdentifier;
  1470. PROCEDURE GetSymbol*(case: LONGINT; id: SyntaxTree.Identifier): LONGINT;
  1471. VAR i: LONGINT;
  1472. BEGIN
  1473. (*! quick and dirty implementation, optimize ! *)
  1474. FOR i := 0 TO LEN(identifiers,1)-1 DO
  1475. IF id=identifiers[case,i] THEN RETURN i END;
  1476. END;
  1477. RETURN -1
  1478. END GetSymbol;
  1479. PROCEDURE InitIdentifiers;
  1480. VAR i: LONGINT;
  1481. PROCEDURE NewKeywordIdentifier(op: LONGINT);
  1482. VAR id: Scanner.IdentifierType;
  1483. BEGIN
  1484. Scanner.GetKeyword(Scanner.Uppercase,op,id);
  1485. identifiers[Scanner.Uppercase,op] := id;
  1486. Scanner.GetKeyword(Scanner.Lowercase,op,id);
  1487. identifiers[Scanner.Lowercase,op] := id;
  1488. END NewKeywordIdentifier;
  1489. PROCEDURE NewBuiltinIdentifier(op: LONGINT; CONST name: ARRAY OF CHAR);
  1490. VAR nameL,nameU: Scanner.IdentifierString;
  1491. BEGIN
  1492. ASSERT(op < LEN(identifiers[0]));
  1493. Basic.Lowercase(name,nameL);
  1494. Basic.Uppercase(name,nameU);
  1495. identifiers[Scanner.Lowercase,op] := SyntaxTree.NewIdentifier(nameL);
  1496. identifiers[Scanner.Uppercase,op] := SyntaxTree.NewIdentifier(nameU);
  1497. END NewBuiltinIdentifier;
  1498. BEGIN
  1499. FOR i := 0 TO LEN(identifiers,1)-1 DO
  1500. identifiers[Scanner.Uppercase,i] := SyntaxTree.invalidIdentifier; identifiers[Scanner.Lowercase,i] := SyntaxTree.invalidIdentifier;
  1501. END;
  1502. FOR i := 0 TO Scanner.EndOfText-1 DO
  1503. NewKeywordIdentifier(i);
  1504. END;
  1505. NewBuiltinIdentifier(Abs,"ABS");
  1506. NewBuiltinIdentifier(Ash,"ASH");
  1507. NewBuiltinIdentifier(Asr,"ASR");
  1508. NewBuiltinIdentifier(Cap,"CAP");
  1509. NewBuiltinIdentifier(Chr,"CHR");
  1510. NewBuiltinIdentifier(Chr32,"CHR32");
  1511. NewBuiltinIdentifier(Entier,"ENTIER");
  1512. NewBuiltinIdentifier(EntierH,"ENTIERH");
  1513. NewBuiltinIdentifier(Len,"LEN");
  1514. NewBuiltinIdentifier(Long,"LONG");
  1515. NewBuiltinIdentifier(Lsh,"LSH");
  1516. NewBuiltinIdentifier(Max,"MAX");
  1517. NewBuiltinIdentifier(Min,"MIN");
  1518. NewBuiltinIdentifier(Odd,"ODD");
  1519. NewBuiltinIdentifier(Ord,"ORD");
  1520. NewBuiltinIdentifier(Ord32,"ORD32");
  1521. NewBuiltinIdentifier(Ror,"ROR");
  1522. NewBuiltinIdentifier(Rot,"ROT");
  1523. NewBuiltinIdentifier(Short,"SHORT");
  1524. NewBuiltinIdentifier(Sum,"SUM");
  1525. NewBuiltinIdentifier(Dim,"DIM");
  1526. NewBuiltinIdentifier(Cas,"CAS");
  1527. NewBuiltinIdentifier(Dec,"DEC");
  1528. NewBuiltinIdentifier(Excl,"EXCL");
  1529. NewBuiltinIdentifier(Inc,"INC");
  1530. NewBuiltinIdentifier(Incl,"INCL");
  1531. NewBuiltinIdentifier(All,"ALL");
  1532. NewBuiltinIdentifier(Re,"RE");
  1533. NewBuiltinIdentifier(Im,"IM");
  1534. NewBuiltinIdentifier(IncMul,"INCMUL");
  1535. NewBuiltinIdentifier(DecMul,"DECMUL");
  1536. (* TODO: check if ok. The operators defined in FoxArrayBase require the following identifiers *)
  1537. (* TODO: ".*+" should preferably be added as a new token in the scanner *)
  1538. identifiers[Scanner.Lowercase, Scanner.Becomes] := SyntaxTree.NewIdentifier(":=");
  1539. identifiers[Scanner.Uppercase, Scanner.Becomes] := SyntaxTree.NewIdentifier(":=");
  1540. identifiers[Scanner.Lowercase, Scanner.Transpose] := SyntaxTree.NewIdentifier("`");
  1541. identifiers[Scanner.Uppercase, Scanner.Transpose] := SyntaxTree.NewIdentifier("`");
  1542. identifiers[Scanner.Lowercase, DotTimesPlus] := SyntaxTree.NewIdentifier(".*+");
  1543. identifiers[Scanner.Uppercase, DotTimesPlus] := SyntaxTree.NewIdentifier(".*+");
  1544. identifiers[Scanner.Lowercase, AtMulDec] := SyntaxTree.NewIdentifier("@MulDec");
  1545. identifiers[Scanner.Uppercase, AtMulDec] := SyntaxTree.NewIdentifier("@MulDec");
  1546. identifiers[Scanner.Lowercase, AtMulInc] := SyntaxTree.NewIdentifier("@MulInc");
  1547. identifiers[Scanner.Uppercase, AtMulInc] := SyntaxTree.NewIdentifier("@MulInc");
  1548. identifiers[Scanner.Lowercase,Conversion] := SyntaxTree.NewIdentifier("@Convert");
  1549. identifiers[Scanner.Uppercase,Conversion] := SyntaxTree.NewIdentifier("@Convert");
  1550. END InitIdentifiers;
  1551. (** initialize the global namespace *)
  1552. PROCEDURE Init;
  1553. BEGIN
  1554. InitIdentifiers;
  1555. (* names are not arbitrary, do not change unless you know what you do (compatibilty with paco!) *)
  1556. SystemName := SyntaxTree.NewIdentifier("SYSTEM");
  1557. systemName := SyntaxTree.NewIdentifier("system");
  1558. SelfParameterName := SyntaxTree.NewIdentifier("@Self");
  1559. ReturnParameterName := SyntaxTree.NewIdentifier("@ReturnParameter");
  1560. PointerReturnName := SyntaxTree.NewIdentifier("@PtrReturnType");
  1561. ResultName := SyntaxTree.NewIdentifier("RESULT");
  1562. A2Name := SyntaxTree.NewIdentifier("A2");
  1563. ArrayBaseName := SyntaxTree.NewIdentifier("FoxArrayBase");
  1564. ComplexNumbersName := SyntaxTree.NewIdentifier("ComplexNumbers");
  1565. RecordBodyName := SyntaxTree.NewIdentifier("@Body");
  1566. ModuleBodyName := SyntaxTree.NewIdentifier("@Body");
  1567. NameWinAPI := SyntaxTree.NewIdentifier(StringWinAPI);
  1568. NameC := SyntaxTree.NewIdentifier(StringC);
  1569. NamePlatformCC := SyntaxTree.NewIdentifier(StringPlatformCC);
  1570. NameMovable := SyntaxTree.NewIdentifier(StringMovable);
  1571. NameUntraced := SyntaxTree.NewIdentifier(StringUntraced);
  1572. NameDelegate := SyntaxTree.NewIdentifier(StringDelegate);
  1573. NameInterrupt := SyntaxTree.NewIdentifier(StringInterrupt);
  1574. NamePcOffset := SyntaxTree.NewIdentifier(StringPcOffset);
  1575. NameNoPAF := SyntaxTree.NewIdentifier(StringNoPAF);
  1576. NameEntry := SyntaxTree.NewIdentifier(StringEntry);
  1577. NameExit := SyntaxTree.NewIdentifier(StringExit);
  1578. NameFixed := SyntaxTree.NewIdentifier(StringFixed);
  1579. NameFictive := SyntaxTree.NewIdentifier(StringFictive);
  1580. NameAligned := SyntaxTree.NewIdentifier(StringAligned);
  1581. NameStackAligned := SyntaxTree.NewIdentifier(StringAlignStack);
  1582. NameExclusive := SyntaxTree.NewIdentifier(StringExclusive);
  1583. NameActive := SyntaxTree.NewIdentifier(StringActive);
  1584. NamePriority := SyntaxTree.NewIdentifier(StringPriority);
  1585. NameSafe := SyntaxTree.NewIdentifier(StringSafe);
  1586. NameRealtime := SyntaxTree.NewIdentifier(StringRealtime);
  1587. NameDynamic := SyntaxTree.NewIdentifier(StringDynamic);
  1588. NameDataMemorySize := SyntaxTree.NewIdentifier(StringDataMemorySize);
  1589. NameCodeMemorySize := SyntaxTree.NewIdentifier(StringCodeMemorySize);
  1590. NameChannelWidth := SyntaxTree.NewIdentifier(StringChannelWidth);
  1591. NameChannelDepth := SyntaxTree.NewIdentifier(StringChannelDepth);
  1592. NameChannelModule := SyntaxTree.NewIdentifier(StringChannelModule);
  1593. NameVector := SyntaxTree.NewIdentifier(StringVector);
  1594. NameFloatingPoint := SyntaxTree.NewIdentifier(StringFloatingPoint);
  1595. NameNoMul:= SyntaxTree.NewIdentifier(StringNoMul);
  1596. NameNonBlockingIO:=SyntaxTree.NewIdentifier(StringNonBlockingIO);
  1597. NameTRM := SyntaxTree.NewIdentifier(StringTRM);
  1598. NameTRMS := SyntaxTree.NewIdentifier(StringTRMS);
  1599. NameBackend := SyntaxTree.NewIdentifier(StringBackend);
  1600. NameRuntime := SyntaxTree.NewIdentifier(StringRuntime);
  1601. NameEngine := SyntaxTree.NewIdentifier(StringEngine);
  1602. NameFinal := SyntaxTree.NewIdentifier(StringFinal);
  1603. NameAbstract := SyntaxTree.NewIdentifier(StringAbstract);
  1604. NameFrequencyDivider := SyntaxTree.NewIdentifier(StringFrequencyDivider);
  1605. NameRegister := SyntaxTree.NewIdentifier(StringRegister);
  1606. NameNoReturn := SyntaxTree.NewIdentifier(StringNoReturn);
  1607. NamePlain := SyntaxTree.NewIdentifier(StringPlain);
  1608. NameUnsafe := SyntaxTree.NewIdentifier(StringUnsafe);
  1609. NameDisposable := SyntaxTree.NewIdentifier(StringDisposable);
  1610. NameUnchecked := SyntaxTree.NewIdentifier(StringUnchecked);
  1611. NameUncooperative := SyntaxTree.NewIdentifier(StringUncooperative);
  1612. NameFingerprint := SyntaxTree.NewIdentifier(StringFingerprint);
  1613. (* types *)
  1614. Boolean8 := SyntaxTree.NewBooleanType(8);
  1615. Boolean32 := SyntaxTree.NewBooleanType(32);
  1616. Integer8 := SyntaxTree.NewIntegerType(8, TRUE);
  1617. Integer16 := SyntaxTree.NewIntegerType(16, TRUE);
  1618. Integer32 := SyntaxTree.NewIntegerType(32, TRUE);
  1619. Integer64 := SyntaxTree.NewIntegerType(64, TRUE);
  1620. Unsigned8 := SyntaxTree.NewIntegerType(8, FALSE);
  1621. Unsigned16 := SyntaxTree.NewIntegerType(16, FALSE);
  1622. Unsigned32 := SyntaxTree.NewIntegerType(32, FALSE);
  1623. Unsigned64 := SyntaxTree.NewIntegerType(64, FALSE);
  1624. Float32 := SyntaxTree.NewFloatType(32);
  1625. Float64 := SyntaxTree.NewFloatType(64);
  1626. Complex64 := SyntaxTree.NewComplexType(Float32);
  1627. Complex128 := SyntaxTree.NewComplexType(Float64);
  1628. Byte8 := SyntaxTree.NewByteType(8);
  1629. Byte32 := SyntaxTree.NewByteType(32);
  1630. Character8 := SyntaxTree.NewCharacterType(8);
  1631. Character16 := SyntaxTree.NewCharacterType(16);
  1632. Character32 := SyntaxTree.NewCharacterType(32);
  1633. Set8 := SyntaxTree.NewSetType(8);
  1634. Set16 := SyntaxTree.NewSetType(16);
  1635. Set32 := SyntaxTree.NewSetType(32);
  1636. Set64 := SyntaxTree.NewSetType(64);
  1637. END Init;
  1638. BEGIN
  1639. Init;
  1640. END FoxGlobal.