FoxGlobal.Mod 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823
  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. ELSIF type(SyntaxTree.MathArrayType).form = SyntaxTree.Tensor THEN
  522. size := addressSize (* pointer to geometry descriptor *)
  523. ELSE
  524. size := 0;
  525. WHILE(type # NIL) & (type IS SyntaxTree.MathArrayType) DO
  526. type := type(SyntaxTree.MathArrayType).arrayBase;
  527. IF type # NIL THEN type := type.resolved END;
  528. INC(size);
  529. END;
  530. size := size*2*addressSize (* length and increments *) +5*addressSize (* data ptr, adr ptr, flags, dim and elementsize *);
  531. END;
  532. ELSIF type IS SyntaxTree.StringType THEN
  533. ASSERT(SyntaxTree.Resolved IN type.state);
  534. size := type(SyntaxTree.StringType).length * SizeOf(type(SyntaxTree.StringType).baseType);
  535. ELSIF type IS SyntaxTree.EnumerationType THEN
  536. size := addressSize
  537. ELSIF type = SyntaxTree.invalidType THEN size := 0
  538. ELSIF type IS SyntaxTree.QualifiedType THEN
  539. HALT(101); (* hint that unresolved type has been taken for type size computation *)
  540. ELSIF type IS SyntaxTree.PortType THEN
  541. size := addressSize
  542. ELSIF type IS SyntaxTree.CellType THEN
  543. size := addressSize;
  544. ELSIF type IS SyntaxTree.RangeType THEN
  545. size := 3 * SizeOf(longintType);
  546. ELSE
  547. HALT(100)
  548. END;
  549. RETURN size
  550. END SizeOf;
  551. PROCEDURE SizeOfParameter*(par: SyntaxTree.Parameter):LONGINT;
  552. BEGIN
  553. IF (par.type.resolved IS SyntaxTree.ArrayType) OR (par.type.resolved IS SyntaxTree.MathArrayType) THEN
  554. IF (par.type.resolved IS SyntaxTree.ArrayType) & (par.type.resolved(SyntaxTree.ArrayType).form = SyntaxTree.Static) &
  555. (par.kind IN {SyntaxTree.ConstParameter,SyntaxTree.VarParameter})
  556. OR
  557. (par.type.resolved IS SyntaxTree.MathArrayType) & (par.type.resolved(SyntaxTree.MathArrayType).form = SyntaxTree.Static) &
  558. (par.kind IN {SyntaxTree.ConstParameter,SyntaxTree.VarParameter})
  559. OR (par.type.resolved IS SyntaxTree.MathArrayType) & (par.kind = SyntaxTree.VarParameter)
  560. THEN
  561. RETURN addressSize
  562. ELSIF IsOberonProcedure(par.ownerType) THEN
  563. RETURN SizeOf(par.type);
  564. ELSE RETURN addressSize
  565. END
  566. ELSIF par.type.resolved IS SyntaxTree.RangeType THEN
  567. IF par.kind = SyntaxTree.VarParameter THEN
  568. RETURN addressSize
  569. ELSE
  570. RETURN SizeOf(rangeType) (* array range components are materialized on stack for both value and const parameters *)
  571. END
  572. ELSIF par.type.resolved IS SyntaxTree.RecordType THEN
  573. IF par.selfParameter THEN
  574. RETURN addressSize
  575. ELSIF (par.kind IN {SyntaxTree.ConstParameter,SyntaxTree.VarParameter}) THEN
  576. IF IsOberonProcedure(par.ownerType) THEN
  577. RETURN 2*addressSize
  578. ELSE
  579. RETURN addressSize
  580. END
  581. ELSE
  582. RETURN SizeOf(par.type);
  583. END;
  584. ELSIF par.kind = SyntaxTree.VarParameter THEN
  585. RETURN addressSize
  586. ELSIF par.kind = SyntaxTree.ConstParameter THEN
  587. RETURN SizeOf(par.type)
  588. ELSE
  589. RETURN SizeOf(par.type);
  590. END;
  591. END SizeOfParameter;
  592. PROCEDURE AlignmentOf*(CONST alignment: Alignment;type: SyntaxTree.Type): LONGINT;
  593. VAR result: LONGINT;
  594. BEGIN
  595. type := type.resolved;
  596. IF type IS SyntaxTree.RecordType THEN
  597. IF type.alignmentInBits <= 0 THEN
  598. IF GenerateRecordOffsets(type(SyntaxTree.RecordType)) THEN
  599. result := type.alignmentInBits
  600. END
  601. ELSE
  602. result := type.alignmentInBits
  603. END;
  604. ELSIF type IS SyntaxTree.ArrayType THEN
  605. IF type.alignmentInBits <= 0 THEN
  606. IF type(SyntaxTree.ArrayType).form = SyntaxTree.Static THEN
  607. result := AlignmentOf(alignment,type(SyntaxTree.ArrayType).arrayBase.resolved);
  608. ELSE
  609. result := alignment.max
  610. END;
  611. type.SetAlignmentInBits(result)
  612. ELSE
  613. result := type.alignmentInBits
  614. END;
  615. ELSIF type IS SyntaxTree.StringType THEN
  616. result := SizeOf(type(SyntaxTree.StringType).baseType);
  617. ELSE
  618. result := SizeOf(type);
  619. IF result > alignment.max THEN result := alignment.max END;
  620. IF result < alignment.min THEN result := alignment.min END;
  621. END;
  622. ASSERT(result # 0);
  623. RETURN result
  624. END AlignmentOf;
  625. PROCEDURE AlignedSizeOf*(type: SyntaxTree.Type): LONGINT;
  626. VAR size: LONGINT;
  627. BEGIN
  628. size := SizeOf(type);
  629. Basic.Align(size, AlignmentOf(variableAlignment, type));
  630. RETURN size
  631. END AlignedSizeOf;
  632. (* LYNX+ *)
  633. PROCEDURE IsLynx*(): BOOLEAN;
  634. BEGIN
  635. RETURN TRUE;
  636. END IsLynx;
  637. (* -LYNX *)
  638. END System;
  639. PROCEDURE BuildScopes(system: System);
  640. VAR i: LONGINT;
  641. BEGIN
  642. FOR i := 0 TO end-1 DO
  643. system.operatorDefined[i] := FALSE
  644. END;
  645. system.globalScope[Scanner.Uppercase] := SyntaxTree.NewModuleScope();
  646. system.globalScope[Scanner.Lowercase] := SyntaxTree.NewModuleScope();
  647. system.globalModule[Scanner.Uppercase] := SyntaxTree.NewModule("",SyntaxTree.invalidPosition,SyntaxTree.NewIdentifier("@GLOBAL"),system.globalScope[Scanner.Uppercase],Scanner.Uppercase);
  648. system.globalModule[Scanner.Lowercase] := SyntaxTree.NewModule("",SyntaxTree.invalidPosition,SyntaxTree.NewIdentifier("@global"),system.globalScope[Scanner.Lowercase],Scanner.Lowercase);
  649. system.systemScope[Scanner.Uppercase] := SyntaxTree.NewModuleScope();
  650. system.systemScope[Scanner.Lowercase] := SyntaxTree.NewModuleScope();
  651. system.systemModule[Scanner.Uppercase] := SyntaxTree.NewModule("",SyntaxTree.invalidPosition,SystemName,system.systemScope[Scanner.Uppercase],Scanner.Uppercase);
  652. system.systemModule[Scanner.Lowercase] := SyntaxTree.NewModule("",SyntaxTree.invalidPosition,systemName,system.systemScope[Scanner.Lowercase],Scanner.Lowercase);
  653. END BuildScopes;
  654. PROCEDURE SetDefaultDeclarations*(system: System; minBits: LONGINT);
  655. VAR now: Dates.DateTime; date, time: ARRAY 20 OF CHAR;
  656. BEGIN
  657. (* types *)
  658. system.longintType := SyntaxTree.NewIntegerType(32, TRUE);
  659. system.hugeintType := SyntaxTree.NewIntegerType(64, TRUE);
  660. system.wordType := SyntaxTree.NewIntegerType(MIN(system.addressSize,32),TRUE);
  661. system.longWordType := SyntaxTree.NewIntegerType(system.addressSize,TRUE);
  662. system.wordSetType := SyntaxTree.NewSetType(system.wordType.sizeInBits);
  663. system.realType := SyntaxTree.NewFloatType(32);
  664. system.longrealType := SyntaxTree.NewFloatType(64);
  665. (*
  666. system.longintType := Integer32;
  667. system.hugeintType := Integer64;
  668. system.realType := Float32;
  669. system.longrealType := Float64;
  670. *)
  671. IF minBits = 32 THEN
  672. system.shortintType := SyntaxTree.NewIntegerType(32, TRUE);
  673. system.integerType := SyntaxTree.NewIntegerType(32, TRUE);
  674. system.booleanType := SyntaxTree.NewBooleanType(32);
  675. system.byteType := SyntaxTree.NewByteType(32);
  676. system.characterType := SyntaxTree.NewCharacterType(32);
  677. system.characterType8 := SyntaxTree.NewCharacterType(32);
  678. system.characterType16 := SyntaxTree.NewCharacterType(32);
  679. system.characterType32 := SyntaxTree.NewCharacterType(32);
  680. (*
  681. system.shortintType := Integer32;
  682. system.integerType := Integer32;
  683. system.booleanType := Boolean32;
  684. system.byteType := Byte32;
  685. system.characterType := Character32;
  686. *)
  687. ELSE
  688. ASSERT(minBits = 8); (* nothing else is currently implemented *)
  689. system.shortintType := SyntaxTree.NewIntegerType(8, TRUE);
  690. system.integerType := SyntaxTree.NewIntegerType(16, TRUE);
  691. system.booleanType := SyntaxTree.NewBooleanType(8);
  692. system.byteType := SyntaxTree.NewByteType(8);
  693. system.characterType := SyntaxTree.NewCharacterType(8);
  694. system.characterType8 := SyntaxTree.NewCharacterType(8);
  695. system.characterType16 := SyntaxTree.NewCharacterType(16);
  696. system.characterType32 := SyntaxTree.NewCharacterType(32);
  697. (*
  698. system.shortintType := Integer8;
  699. system.integerType := Integer16;
  700. system.booleanType := Boolean8;
  701. system.byteType := Byte8;
  702. system.characterType := Character8;
  703. *)
  704. END;
  705. system.anyType := SyntaxTree.NewAnyType(system.addressSize);
  706. system.objectType := SyntaxTree.NewObjectType(system.addressSize);
  707. system.nilType := SyntaxTree.NewNilType(system.addressSize);
  708. system.addressType := SyntaxTree.NewAddressType(system.addressSize);
  709. system.sizeType := SyntaxTree.NewSizeType(system.addressSize);
  710. system.rangeType := SyntaxTree.NewRangeType(3 * system.SizeOf(system.longintType));
  711. system.lenType := system.longintType;
  712. (* generally, the lenType should be sizeType but for historical (legacy) reasons, it is longint in the current implementation *)
  713. system.complexType := Complex64;
  714. system.longcomplexType := Complex128;
  715. system.setType := SyntaxTree.NewSetType(system.addressSize);
  716. (* type declarations *)
  717. DeclareType(system.byteType,"BYTE",system.systemScope);
  718. DeclareType(system.addressType,"ADDRESS",system.globalScope);
  719. DeclareType(system.sizeType,"SIZE",system.globalScope);
  720. (*DeclareType(Same,"SAME",system.systemScope);*)
  721. (* system builtin procedures *)
  722. NewBuiltin(systemGet,"GET",system.systemScope,TRUE);
  723. NewBuiltin(systemPut,"PUT",system.systemScope,TRUE);
  724. NewBuiltin(systemPut64,"PUT64",system.systemScope,TRUE);
  725. NewBuiltin(systemPut32,"PUT32",system.systemScope,TRUE);
  726. NewBuiltin(systemPut16,"PUT16",system.systemScope,TRUE);
  727. NewBuiltin(systemPut8,"PUT8",system.systemScope,TRUE);
  728. NewBuiltin(systemGet64,"GET64",system.systemScope,TRUE);
  729. NewBuiltin(systemGet32,"GET32",system.systemScope,TRUE);
  730. NewBuiltin(systemGet16,"GET16",system.systemScope,TRUE);
  731. NewBuiltin(systemGet8,"GET8",system.systemScope,TRUE);
  732. NewBuiltin(systemVal,"VAL",system.systemScope,TRUE);
  733. NewBuiltin(systemMove,"MOVE",system.systemScope,TRUE);
  734. NewBuiltin(systemRef,"REF",system.systemScope,FALSE);
  735. NewBuiltin(systemNew,"NEW",system.systemScope,FALSE);
  736. NewBuiltin(systemTypeCode,"TYPECODE",system.systemScope,TRUE);
  737. NewBuiltin(systemHalt,"HALT",system.systemScope,TRUE);
  738. NewBuiltin(systemSize,"SIZE",system.systemScope,TRUE);
  739. NewBuiltin(systemAdr,"ADR",system.systemScope,TRUE);
  740. NewBuiltin(systemMsk,"MSK",system.systemScope,TRUE);
  741. NewBuiltin(systemBit,"BIT",system.systemScope,TRUE);
  742. now := Dates.Now ();
  743. Strings.FormatDateTime ("hh:nn:ss", now, time);
  744. Strings.FormatDateTime ("mmm dd yyyy", now, date);
  745. NewStringConstantCamelCase("Time", Strings.NewString (time), system.characterType, system.systemScope);
  746. NewStringConstantCamelCase("Date", Strings.NewString (date), system.characterType, system.systemScope);
  747. NewBuiltinCamelCase(systemGetStackPointer,"GetStackPointer",system.systemScope,TRUE);
  748. NewBuiltinCamelCase(systemSetStackPointer,"SetStackPointer",system.systemScope,TRUE);
  749. NewBuiltinCamelCase(systemGetFramePointer,"GetFramePointer",system.systemScope,TRUE);
  750. NewBuiltinCamelCase(systemSetFramePointer,"SetFramePointer",system.systemScope,TRUE);
  751. NewBuiltinCamelCase(systemGetActivity,"GetActivity",system.systemScope,TRUE);
  752. NewBuiltinCamelCase(systemSetActivity,"SetActivity",system.systemScope,TRUE);
  753. (* Set up system types *)
  754. DeclareType(system.characterType,"CHAR",system.globalScope);
  755. DeclareType(system.characterType8,"CHAR8",system.globalScope);
  756. DeclareType(system.characterType16,"CHAR16",system.globalScope);
  757. DeclareType(system.characterType32,"CHAR32",system.globalScope);
  758. DeclareType(system.rangeType,"RANGE",system.globalScope);
  759. DeclareType(system.shortintType,"SHORTINT",system.globalScope);
  760. DeclareType(system.integerType,"INTEGER",system.globalScope);
  761. DeclareType(system.longintType,"LONGINT",system.globalScope);
  762. DeclareType(system.hugeintType,"HUGEINT",system.globalScope);
  763. DeclareType(system.wordType,"WORD",system.globalScope);
  764. DeclareType(system.longWordType,"LONGWORD",system.globalScope);
  765. DeclareType(system.wordSetType,"WORDSET",system.globalScope);
  766. DeclareType(Integer8, "SIGNED8", system.globalScope);
  767. DeclareType(Integer16, "SIGNED16", system.globalScope);
  768. DeclareType(Integer32, "SIGNED32", system.globalScope);
  769. DeclareType(Integer64, "SIGNED64", system.globalScope);
  770. DeclareType(Unsigned8, "UNSIGNED8", system.globalScope);
  771. DeclareType(Unsigned16, "UNSIGNED16", system.globalScope);
  772. DeclareType(Unsigned32, "UNSIGNED32", system.globalScope);
  773. DeclareType(Unsigned64, "UNSIGNED64", system.globalScope);
  774. DeclareType(system.realType,"REAL",system.globalScope);
  775. DeclareType(system.longrealType,"LONGREAL",system.globalScope);
  776. DeclareType(system.complexType,"COMPLEX",system.globalScope);
  777. DeclareType(system.longcomplexType,"LONGCOMPLEX",system.globalScope);
  778. DeclareType(system.booleanType,"BOOLEAN",system.globalScope);
  779. DeclareType(system.setType,"SET",system.globalScope);
  780. DeclareType(system.anyType,"ANY",system.globalScope);
  781. DeclareType(system.objectType,"OBJECT",system.globalScope);
  782. DeclareType(Set8, "SET8", system.globalScope);
  783. DeclareType(Set16, "SET16", system.globalScope);
  784. DeclareType(Set32, "SET32", system.globalScope);
  785. DeclareType(Set64, "SET64", system.globalScope);
  786. (* global functions *)
  787. NewBuiltin(Abs,"ABS",system.globalScope,TRUE);
  788. NewBuiltin(Ash,"ASH",system.globalScope,TRUE);
  789. NewBuiltin(Asr,"ASR",system.globalScope,TRUE);
  790. NewBuiltin(Cap,"CAP",system.globalScope,TRUE);
  791. NewBuiltin(Chr,"CHR",system.globalScope,TRUE);
  792. NewBuiltin(Chr32,"CHR32",system.globalScope,TRUE);
  793. NewBuiltin(Entier,"ENTIER",system.globalScope,TRUE);
  794. NewBuiltin(Entier,"FLOOR",system.globalScope,TRUE);
  795. NewBuiltin(EntierH,"ENTIERH",system.globalScope,TRUE);
  796. NewBuiltin(Len,"LEN",system.globalScope,TRUE);
  797. NewBuiltin(Long,"LONG",system.globalScope,TRUE);
  798. NewBuiltin(Max,"MAX",system.globalScope,TRUE);
  799. NewBuiltin(Min,"MIN",system.globalScope,TRUE);
  800. NewBuiltin(Odd,"ODD",system.globalScope,TRUE);
  801. NewBuiltin(Ord,"ORD",system.globalScope,TRUE);
  802. NewBuiltin(Ord32,"ORD32",system.globalScope,TRUE);
  803. NewBuiltin(Lsh,"LSH",system.globalScope,TRUE);
  804. NewBuiltin(Lsh,"LSL",system.globalScope,TRUE);
  805. NewBuiltin(Rot,"ROT",system.globalScope,TRUE);
  806. NewBuiltin(Ror,"ROR",system.globalScope,TRUE);
  807. NewBuiltin(Incr,"INCR",system.globalScope,TRUE);
  808. NewBuiltin(Short,"SHORT",system.globalScope,TRUE);
  809. NewBuiltin(Sum,"SUM",system.globalScope,TRUE);
  810. NewBuiltin(Dim,"DIM",system.globalScope,TRUE);
  811. NewBuiltin(Cas,"CAS",system.globalScope,TRUE);
  812. NewBuiltin(First,"FIRST",system.globalScope,TRUE);
  813. NewBuiltin(Last,"LAST",system.globalScope,TRUE);
  814. NewBuiltin(Step,"STEP",system.globalScope,TRUE);
  815. NewBuiltin(Re,"RE",system.globalScope,TRUE);
  816. NewBuiltin(Im,"IM",system.globalScope,TRUE);
  817. NewBuiltin(systemAdr,"ADDRESSOF",system.globalScope,TRUE);
  818. NewBuiltin(systemSize,"SIZEOF",system.globalScope,TRUE);
  819. (* global proper procedures *)
  820. NewBuiltin(Assert,"ASSERT",system.globalScope,TRUE);
  821. NewBuiltin(Copy,"COPY",system.globalScope,TRUE);
  822. NewBuiltin(Dec,"DEC",system.globalScope,TRUE);
  823. NewBuiltin(Excl,"EXCL",system.globalScope,TRUE);
  824. NewBuiltin(Halt,"HALT",system.globalScope,TRUE);
  825. NewBuiltin(Inc,"INC",system.globalScope,TRUE);
  826. NewBuiltin(Incl,"INCL",system.globalScope,TRUE);
  827. NewBuiltin(New,"NEW",system.globalScope,FALSE);
  828. NewBuiltin(Dispose,"DISPOSE",system.globalScope, FALSE);
  829. NewBuiltin(GetProcedure,"GETPROCEDURE",system.globalScope,TRUE);
  830. NewBuiltin(systemTrace,"TRACE",system.globalScope,TRUE);
  831. NewBuiltin(Reshape,"RESHAPE",system.globalScope,TRUE);
  832. NewBuiltin(All,"ALL",system.globalScope,TRUE);
  833. NewBuiltin(Wait,"WAIT",system.globalScope,FALSE);
  834. NewBuiltin(Connect,"CONNECT",system.globalScope,FALSE);
  835. NewBuiltin(Receive,"RECEIVE",system.globalScope,FALSE);
  836. NewBuiltin(Send,"SEND",system.globalScope,FALSE);
  837. NewBuiltin(Delegate,"DELEGATE",system.globalScope,FALSE);
  838. NewBuiltin(IncMul,"INCMUL",system.globalScope,TRUE);
  839. NewBuiltin(DecMul,"DECMUL",system.globalScope,TRUE);
  840. (*!
  841. (* Following is LYNX version: *)
  842. IF minBits = 8 THEN
  843. system.characterType := Character16;
  844. END;
  845. (* LYNX builtin types *)
  846. DeclareLynxType(system.characterType, LynxChar, system.globalScope);
  847. DeclareLynxType(system.shortintType, LynxSbyte, system.globalScope);
  848. DeclareLynxType(system.integerType, LynxShort, system.globalScope);
  849. DeclareLynxType(system.longintType, LynxInt, system.globalScope);
  850. DeclareLynxType(system.hugeintType, LynxLong, system.globalScope);
  851. DeclareLynxType(system.realType, LynxFloat, system.globalScope);
  852. DeclareLynxType(system.longrealType, LynxDouble, system.globalScope);
  853. DeclareLynxType(system.booleanType, LynxBool, system.globalScope);
  854. (* TODO: object, string *)
  855. (* LYNX global functions *)
  856. NewBuiltin(SymLynxNewobj, LynxNewobj, system.globalScope, TRUE);
  857. NewBuiltin(SymLynxNewarr, LynxNewarr, system.globalScope, TRUE);
  858. NewBuiltin(SymLynxAsop, LynxAsop, system.globalScope, TRUE);
  859. NewBuiltin(SymLynxUnop, LynxUnop, system.globalScope, TRUE);
  860. NewBuiltin(SymLynxBinop, LynxBinop, system.globalScope, TRUE);
  861. NewBuiltin(SymLynxRecvnb, LynxRecvnb, system.globalScope, TRUE);
  862. (*
  863. LynxCompiler will register builtins for send/receive/connect/delegate
  864. under "lynx@*" names but with their original Fox numeric identifiers,
  865. so that no modifications will be required in the semantic checker and
  866. intermediate backend.
  867. *)
  868. NewBuiltin(SymLynxNewsel, LynxNewsel, system.globalScope, TRUE);
  869. NewBuiltin(SymLynxAddsel, LynxAddsel, system.globalScope, TRUE);
  870. NewBuiltin(SymLynxSelect, LynxSelect, system.globalScope, TRUE);
  871. NewBuiltin(SymLynxSelidx, LynxSelidx, system.globalScope, TRUE);
  872. *)
  873. END SetDefaultDeclarations;
  874. PROCEDURE OperatorDefined*(system: System; op: LONGINT; defined: BOOLEAN);
  875. BEGIN
  876. system.operatorDefined[op] := defined;
  877. END OperatorDefined;
  878. PROCEDURE SetDefaultOperators*(system: System);
  879. VAR i: LONGINT;
  880. BEGIN
  881. FOR i := Scanner.Equal TO Scanner.Not DO
  882. OperatorDefined(system,i,TRUE);
  883. END;
  884. OperatorDefined(system, Conversion, TRUE);
  885. OperatorDefined(system, DotTimesPlus, TRUE);
  886. OperatorDefined(system, AtMulDec, TRUE);
  887. OperatorDefined(system, AtMulInc, TRUE);
  888. OperatorDefined(system, DecMul, TRUE);
  889. OperatorDefined(system, IncMul, TRUE);
  890. OperatorDefined(system,Scanner.Transpose,TRUE);
  891. OperatorDefined(system,Scanner.Becomes,TRUE);
  892. OperatorDefined(system,Dec,TRUE);
  893. OperatorDefined(system,Excl,TRUE);
  894. OperatorDefined(system,Inc,TRUE);
  895. OperatorDefined(system,Incl,TRUE);
  896. OperatorDefined(system,Abs,TRUE);
  897. OperatorDefined(system,Ash,TRUE);
  898. OperatorDefined(system,Cap,TRUE);
  899. OperatorDefined(system,Chr,TRUE);
  900. OperatorDefined(system,Entier,TRUE);
  901. OperatorDefined(system,EntierH,TRUE);
  902. OperatorDefined(system,Len,TRUE);
  903. OperatorDefined(system,Long,TRUE);
  904. OperatorDefined(system,Max,TRUE);
  905. OperatorDefined(system,Min,TRUE);
  906. OperatorDefined(system,Odd,TRUE);
  907. OperatorDefined(system,Short,TRUE);
  908. OperatorDefined(system,Sum,TRUE);
  909. OperatorDefined(system,Dim,TRUE);
  910. OperatorDefined(system,Scanner.Address, TRUE);
  911. OperatorDefined(system,Scanner.Size, TRUE);
  912. OperatorDefined(system,Scanner.Alias, TRUE);
  913. OperatorDefined(system,All,TRUE);
  914. OperatorDefined(system,Re,TRUE);
  915. OperatorDefined(system,Im,TRUE);
  916. OperatorDefined(system, Scanner.Questionmarks, TRUE);
  917. OperatorDefined(system, Scanner.GreaterGreater, TRUE);
  918. OperatorDefined(system, Scanner.LessLess, TRUE);
  919. END SetDefaultOperators;
  920. PROCEDURE DefaultSystem*(): System;
  921. VAR system: System;
  922. BEGIN
  923. NEW(system,8,8,32, 8,32,32,32,64,FALSE);
  924. SetDefaultDeclarations(system,8);
  925. SetDefaultOperators(system);
  926. RETURN system
  927. END DefaultSystem;
  928. PROCEDURE IsOberonProcedure*(type: SyntaxTree.Type): BOOLEAN;
  929. BEGIN
  930. RETURN (type IS SyntaxTree.ProcedureType) & (type(SyntaxTree.ProcedureType).callingConvention = SyntaxTree.OberonCallingConvention)
  931. END IsOberonProcedure;
  932. PROCEDURE AlignedSizeOf*(system: System; CONST alignment: Alignment; type: SyntaxTree.Type):LONGINT;
  933. VAR value: LONGINT;
  934. BEGIN
  935. value := SHORT(system.SizeOf(type));
  936. INC(value, (-value) MOD system.AlignmentOf(alignment, type));
  937. RETURN value;
  938. END AlignedSizeOf;
  939. (* returns if a module is the system module *)
  940. PROCEDURE IsSystemModule*(module: SyntaxTree.Module): BOOLEAN;
  941. BEGIN RETURN (module.name=systemName) OR (module.name=SystemName)
  942. END IsSystemModule;
  943. (** Various factories *)
  944. PROCEDURE DeclareType0(type: SyntaxTree.Type; CONST name: ARRAY OF CHAR; in: SyntaxTree.Scope);
  945. VAR basic: SyntaxTree.TypeDeclaration; duplicate: BOOLEAN;
  946. BEGIN
  947. basic := SyntaxTree.NewTypeDeclaration(SyntaxTree.invalidPosition,SyntaxTree.NewIdentifier(name));
  948. basic.SetDeclaredType(type);
  949. basic.SetState(SyntaxTree.Resolved);
  950. basic.SetAccess(SyntaxTree.ReadOnly);
  951. in.AddTypeDeclaration(basic);
  952. in.EnterSymbol(basic,duplicate);
  953. ASSERT(~duplicate);
  954. END DeclareType0;
  955. (** External interface backends can use to add their types etc. to the global scope *)
  956. PROCEDURE DeclareType*(type: SyntaxTree.Type; CONST name: ARRAY OF CHAR; CONST scope: ARRAY OF SyntaxTree.ModuleScope);
  957. VAR nameL,nameU: Scanner.IdentifierString;
  958. BEGIN
  959. Basic.Lowercase(name,nameL);
  960. Basic.Uppercase(name,nameU);
  961. DeclareType0(type,nameU,scope[Scanner.Uppercase]);
  962. DeclareType0(type,nameL,scope[Scanner.Lowercase]);
  963. END DeclareType;
  964. (* LYNX+ *)
  965. PROCEDURE DeclareLynxType*(
  966. type: SyntaxTree.Type; CONST name: ARRAY OF CHAR; CONST scope: ARRAY OF SyntaxTree.ModuleScope);
  967. BEGIN
  968. DeclareType0(type, name, scope[Scanner.Uppercase]);
  969. DeclareType0(type, name, scope[Scanner.Lowercase]);
  970. END DeclareLynxType;
  971. (* -LYNX *)
  972. PROCEDURE NewConstant0(CONST name: ARRAY OF CHAR; int: LONGINT; type: SyntaxTree.Type; in: SyntaxTree.Scope);
  973. VAR constant: SyntaxTree.Constant; value: SyntaxTree.IntegerValue;duplicate: BOOLEAN;
  974. BEGIN
  975. value := SyntaxTree.NewIntegerValue(SyntaxTree.invalidPosition,int);
  976. value.SetType(type);
  977. constant := SyntaxTree.NewConstant(SyntaxTree.invalidPosition,SyntaxTree.NewIdentifier(name));
  978. constant.SetValue(value);
  979. constant.SetType(value.type);
  980. constant.SetAccess(SyntaxTree.ReadOnly);
  981. constant.SetState(SyntaxTree.Resolved);
  982. in.AddConstant(constant);
  983. in.EnterSymbol(constant,duplicate);
  984. ASSERT(~duplicate);
  985. END NewConstant0;
  986. PROCEDURE NewConstant*(CONST name: ARRAY OF CHAR; int: LONGINT; type: SyntaxTree.Type; CONST scope: ARRAY OF SyntaxTree.ModuleScope);
  987. VAR nameL,nameU: Scanner.IdentifierString;
  988. BEGIN
  989. Basic.Lowercase(name,nameL);
  990. Basic.Uppercase(name,nameU);
  991. NewConstant0(nameU,int,type,scope[Scanner.Uppercase]);
  992. NewConstant0(nameL,int,type,scope[Scanner.Lowercase]);
  993. END NewConstant;
  994. PROCEDURE NewStringConstant0(CONST name: ARRAY OF CHAR; string: SyntaxTree.String; baseType: SyntaxTree.Type; in: SyntaxTree.Scope);
  995. VAR constant: SyntaxTree.Constant; value: SyntaxTree.StringValue;duplicate: BOOLEAN;
  996. BEGIN
  997. value := SyntaxTree.NewStringValue(SyntaxTree.invalidPosition,string);
  998. value.SetType(SyntaxTree.NewStringType(SyntaxTree.invalidPosition,baseType,value.length));
  999. constant := SyntaxTree.NewConstant(SyntaxTree.invalidPosition,SyntaxTree.NewIdentifier(name));
  1000. constant.SetValue(value);
  1001. constant.SetType(value.type);
  1002. constant.SetAccess(SyntaxTree.ReadOnly);
  1003. constant.SetState(SyntaxTree.Resolved);
  1004. in.AddConstant(constant);
  1005. in.EnterSymbol(constant,duplicate);
  1006. ASSERT(~duplicate);
  1007. END NewStringConstant0;
  1008. PROCEDURE NewStringConstant*(CONST name: ARRAY OF CHAR; string: SyntaxTree.String; type: SyntaxTree.Type; CONST scope: ARRAY OF SyntaxTree.ModuleScope);
  1009. VAR nameL,nameU: Scanner.IdentifierString;
  1010. BEGIN
  1011. Basic.Lowercase(name,nameL);
  1012. Basic.Uppercase(name,nameU);
  1013. NewStringConstant0(nameU,string,type,scope[Scanner.Uppercase]);
  1014. NewStringConstant0(nameL,string,type,scope[Scanner.Lowercase]);
  1015. END NewStringConstant;
  1016. PROCEDURE NewStringConstantCamelCase*(CONST name: ARRAY OF CHAR; string: SyntaxTree.String; type: SyntaxTree.Type; CONST scope: ARRAY OF SyntaxTree.ModuleScope);
  1017. BEGIN
  1018. NewStringConstant0(name,string,type,scope[Scanner.Uppercase]);
  1019. NewStringConstant0(name,string,type,scope[Scanner.Lowercase]);
  1020. END NewStringConstantCamelCase;
  1021. PROCEDURE NewBuiltin0( id: LONGINT; CONST name: ARRAY OF CHAR; in: SyntaxTree.ModuleScope; realtime: BOOLEAN);
  1022. VAR basic: SyntaxTree.Builtin; duplicate: BOOLEAN; type: SyntaxTree.ProcedureType;
  1023. BEGIN
  1024. basic := SyntaxTree.NewBuiltin(SyntaxTree.invalidPosition,SyntaxTree.NewIdentifier(name),id);
  1025. basic.SetAccess(SyntaxTree.ReadOnly);
  1026. type := SyntaxTree.NewProcedureType(SyntaxTree.invalidPosition,in);
  1027. type.SetRealtime(realtime);
  1028. type.SetReturnType(SyntaxTree.invalidType); (* make incompatible to any procedure *)
  1029. basic.SetType(type);
  1030. basic.SetState(SyntaxTree.Resolved);
  1031. in.EnterSymbol(basic,duplicate);
  1032. in.AddBuiltin(basic);
  1033. ASSERT(~duplicate);
  1034. END NewBuiltin0;
  1035. PROCEDURE NewBuiltin*(id: LONGINT; CONST name: ARRAY OF CHAR; CONST scope: ARRAY OF SyntaxTree.ModuleScope; realtime: BOOLEAN);
  1036. VAR nameL,nameU: Scanner.IdentifierString;
  1037. BEGIN
  1038. Basic.Lowercase(name,nameL);
  1039. Basic.Uppercase(name,nameU);
  1040. NewBuiltin0(id,nameU,scope[Scanner.Uppercase],realtime);
  1041. NewBuiltin0(id,nameL,scope[Scanner.Lowercase],realtime);
  1042. END NewBuiltin;
  1043. PROCEDURE NewBuiltinCamelCase*(id: LONGINT; CONST name: ARRAY OF CHAR; CONST scope: ARRAY OF SyntaxTree.ModuleScope; realtime: BOOLEAN);
  1044. BEGIN
  1045. NewBuiltin0(id,name,scope[Scanner.Uppercase],realtime);
  1046. NewBuiltin0(id,name,scope[Scanner.Lowercase],realtime);
  1047. END NewBuiltinCamelCase;
  1048. PROCEDURE NewCustomBuiltin0(CONST name: ARRAY OF CHAR; scope: SyntaxTree.ModuleScope; subType: SHORTINT; procedureType: SyntaxTree.ProcedureType);
  1049. VAR
  1050. isDuplicate: BOOLEAN;
  1051. customBuiltin: SyntaxTree.CustomBuiltin;
  1052. BEGIN
  1053. customBuiltin := SyntaxTree.NewCustomBuiltin(SyntaxTree.invalidPosition, SyntaxTree.NewIdentifier(name), systemSpecial, subType);
  1054. customBuiltin.SetAccess(SyntaxTree.ReadOnly); (* TODO: this might be changed *)
  1055. procedureType.SetRealtime(TRUE);
  1056. customBuiltin.SetType(procedureType); (* TODO: make incompatible to any procedure *)
  1057. customBuiltin.SetState(SyntaxTree.Resolved);
  1058. scope.EnterSymbol(customBuiltin, isDuplicate);
  1059. scope.AddBuiltin(customBuiltin);
  1060. ASSERT(~isDuplicate)
  1061. END NewCustomBuiltin0;
  1062. PROCEDURE NewCustomBuiltin*(CONST name: ARRAY OF CHAR; CONST scope: ARRAY OF SyntaxTree.ModuleScope; subType: SHORTINT; procedureType: SyntaxTree.ProcedureType);
  1063. VAR
  1064. nameL, nameU: Scanner.IdentifierString;
  1065. BEGIN
  1066. Basic.Lowercase(name, nameL);
  1067. Basic.Uppercase(name, nameU);
  1068. NewCustomBuiltin0(nameU, scope[Scanner.Uppercase], subType, procedureType);
  1069. NewCustomBuiltin0(nameL, scope[Scanner.Lowercase], subType, procedureType)
  1070. END NewCustomBuiltin;
  1071. PROCEDURE GetModuleSectionName*(name, context: SyntaxTree.Identifier; VAR n: ARRAY OF CHAR);
  1072. VAR s: SyntaxTree.IdentifierString;
  1073. BEGIN
  1074. IF context # SyntaxTree.invalidIdentifier THEN
  1075. Basic.GetString(context,n);
  1076. IF n = "A2" THEN
  1077. Basic.GetString(name,n);
  1078. RETURN;
  1079. END;
  1080. Basic.GetString(name,s);
  1081. Strings.Append(n,"-");Strings.Append(n,s);
  1082. ELSE
  1083. IF name # SyntaxTree.invalidIdentifier THEN
  1084. Basic.GetString(name,n);
  1085. ELSE
  1086. n := ""
  1087. END
  1088. END;
  1089. END GetModuleSectionName;
  1090. PROCEDURE ModuleFileName*(name, context: SyntaxTree.Identifier; VAR n: ARRAY OF CHAR);
  1091. BEGIN
  1092. GetModuleSectionName(name, context, n);
  1093. END ModuleFileName;
  1094. PROCEDURE ModuleSectionIdentifier*(name, context: SyntaxTree.Identifier): SyntaxTree.Identifier;
  1095. VAR n: SyntaxTree.IdentifierString;
  1096. BEGIN
  1097. IF context # SyntaxTree.invalidIdentifier THEN
  1098. GetModuleSectionName(name, context, n);
  1099. RETURN SyntaxTree.NewIdentifier(n);
  1100. ELSE
  1101. RETURN name
  1102. END;
  1103. END ModuleSectionIdentifier;
  1104. PROCEDURE ContextFromName*(CONST fileName: ARRAY OF CHAR; VAR module,context: SyntaxTree.Identifier);
  1105. VAR moduleName, contextName: Scanner.IdentifierString; i,j: LONGINT;
  1106. BEGIN
  1107. i := 0; j := 0;
  1108. WHILE (fileName[i] # 0X) & (fileName[i] # ".") DO
  1109. moduleName[i] := fileName[i];
  1110. INC(i);
  1111. END;
  1112. moduleName[i] := 0X;
  1113. IF fileName[i] # 0X THEN
  1114. COPY(moduleName, contextName);
  1115. INC(i);
  1116. WHILE(fileName[i] # 0X) DO
  1117. moduleName[j] := fileName[i];
  1118. INC(i); INC(j);
  1119. END;
  1120. moduleName[j] := 0X;
  1121. ELSE
  1122. contextName := "A2";
  1123. END;
  1124. module := SyntaxTree.NewIdentifier(moduleName);
  1125. context := SyntaxTree.NewIdentifier(contextName);
  1126. END ContextFromName;
  1127. PROCEDURE GetModuleName*(module: SyntaxTree.Module; VAR name: ARRAY OF CHAR);
  1128. BEGIN
  1129. GetModuleSectionName(module.name, module.context, name);
  1130. END GetModuleName;
  1131. PROCEDURE GetModuleSegmentedName*(module: SyntaxTree.Module; VAR name: Basic.SegmentedName);
  1132. BEGIN
  1133. name[0] := ModuleSectionIdentifier(module.name, module.context);
  1134. name[1] := -1;
  1135. END GetModuleSegmentedName;
  1136. PROCEDURE FindSymbol*(CONST name: Basic.SegmentedName; scope: SyntaxTree.Scope): SyntaxTree.Symbol;
  1137. VAR s: LONGINT; symbol : SyntaxTree.Symbol;
  1138. PROCEDURE GetSymbolScope;
  1139. VAR type: SyntaxTree.Type;
  1140. BEGIN
  1141. IF symbol IS SyntaxTree.Module THEN
  1142. scope := symbol(SyntaxTree.Module).moduleScope
  1143. ELSIF symbol IS SyntaxTree.Import THEN
  1144. scope := symbol(SyntaxTree.Import).module.moduleScope;
  1145. ELSIF symbol IS SyntaxTree.Procedure THEN
  1146. scope := symbol(SyntaxTree.Procedure).procedureScope
  1147. ELSIF symbol IS SyntaxTree.TypeDeclaration THEN
  1148. type := symbol(SyntaxTree.TypeDeclaration).declaredType.resolved;
  1149. IF type IS SyntaxTree.RecordType THEN
  1150. scope := type(SyntaxTree.RecordType).recordScope
  1151. END;
  1152. ELSE
  1153. scope := NIL
  1154. END
  1155. END GetSymbolScope;
  1156. PROCEDURE FindSymbol(name: SyntaxTree.Identifier): SyntaxTree.Symbol;
  1157. BEGIN
  1158. IF scope = scope.ownerModule.moduleScope THEN
  1159. symbol := scope.ownerModule.moduleScope.ImportByModuleName(name, scope.ownerModule.context);
  1160. IF symbol = NIL THEN
  1161. symbol := scope.FindSymbol(name)
  1162. END;
  1163. ELSE
  1164. symbol := scope.FindSymbol(name)
  1165. END;
  1166. RETURN symbol
  1167. END FindSymbol;
  1168. BEGIN
  1169. s := 0;
  1170. IF name[0] = scope.ownerModule.name THEN
  1171. INC(s)
  1172. END;
  1173. scope := scope.ownerModule.moduleScope; (* expect fully qualified (segmented) name *)
  1174. REPEAT
  1175. IF scope = NIL THEN RETURN NIL END;
  1176. symbol := FindSymbol(name[s]);
  1177. IF symbol = NIL THEN RETURN NIL
  1178. ELSE
  1179. GetSymbolScope
  1180. END;
  1181. INC(s);
  1182. UNTIL (s = LEN(name)) OR (name[s] < 0);
  1183. RETURN symbol;
  1184. END FindSymbol;
  1185. PROCEDURE GetSymbolNameInScope*(symbol: SyntaxTree.Symbol; inScope: SyntaxTree.Scope; VAR name: ARRAY OF CHAR);
  1186. VAR n: SyntaxTree.IdentifierString; td: SyntaxTree.TypeDeclaration;
  1187. PROCEDURE Scope(scope: SyntaxTree.Scope);
  1188. BEGIN
  1189. IF scope = NIL THEN (* do nothing, locally declared temporary symbol *)
  1190. ELSIF scope = inScope THEN (* do not traverse further *)
  1191. ELSIF scope IS SyntaxTree.ModuleScope THEN
  1192. GetModuleName(scope.ownerModule, name);
  1193. Strings.Append(name,".");
  1194. ELSIF scope IS SyntaxTree.RecordScope THEN
  1195. Scope(scope.outerScope);
  1196. td := scope(SyntaxTree.RecordScope).ownerRecord.typeDeclaration;
  1197. IF td = NIL THEN
  1198. td := scope(SyntaxTree.RecordScope).ownerRecord.pointerType.typeDeclaration;
  1199. END;
  1200. td.GetName(n);
  1201. Strings.Append(name,n); Strings.Append(name,".")
  1202. ELSIF scope IS SyntaxTree.ProcedureScope THEN
  1203. Scope(scope.outerScope);
  1204. scope(SyntaxTree.ProcedureScope).ownerProcedure.GetName(n);
  1205. Strings.Append(name,n); Strings.Append(name,".")
  1206. ELSIF scope IS SyntaxTree.CellScope THEN
  1207. Scope(scope.outerScope);
  1208. td := scope(SyntaxTree.CellScope).ownerCell.typeDeclaration;
  1209. td.GetName(n);
  1210. Strings.Append(name,n); Strings.Append(name,".")
  1211. END;
  1212. END Scope;
  1213. BEGIN
  1214. name := "";
  1215. Scope(symbol.scope);
  1216. symbol.GetName(n);
  1217. IF symbol IS SyntaxTree.Operator THEN (*! append some more bits to make discrimintation possible *)
  1218. END;
  1219. Strings.Append(name,n);
  1220. END GetSymbolNameInScope;
  1221. PROCEDURE GetSymbolName*(symbol: SyntaxTree.Symbol; VAR name: ARRAY OF CHAR);
  1222. BEGIN GetSymbolNameInScope(symbol,NIL,name)
  1223. END GetSymbolName;
  1224. PROCEDURE GetSymbolSegmentedNameInScope*(symbol: SyntaxTree.Symbol; inScope: SyntaxTree.Scope; VAR pooledName: Basic.SegmentedName);
  1225. VAR td: SyntaxTree.TypeDeclaration; i: LONGINT;
  1226. PROCEDURE Scope(scope: SyntaxTree.Scope);
  1227. BEGIN
  1228. IF scope = NIL THEN (* do nothing, locally declared temporary symbol *)
  1229. ELSIF scope = inScope THEN (* do not traverse further *)
  1230. ELSIF scope IS SyntaxTree.ModuleScope THEN
  1231. Basic.SuffixSegmentedName(pooledName,ModuleSectionIdentifier(scope.ownerModule.name, scope.ownerModule.context));
  1232. ELSIF scope IS SyntaxTree.RecordScope THEN
  1233. Scope(scope.outerScope);
  1234. td := scope(SyntaxTree.RecordScope).ownerRecord.typeDeclaration;
  1235. IF td = NIL THEN
  1236. td := scope(SyntaxTree.RecordScope).ownerRecord.pointerType.typeDeclaration;
  1237. END;
  1238. Basic.SuffixSegmentedName(pooledName,td.name);
  1239. ELSIF scope IS SyntaxTree.ProcedureScope THEN
  1240. Scope(scope.outerScope);
  1241. Basic.SuffixSegmentedName(pooledName,scope(SyntaxTree.ProcedureScope).ownerProcedure.name);
  1242. ELSIF scope IS SyntaxTree.CellScope THEN
  1243. Scope(scope.outerScope);
  1244. td := scope(SyntaxTree.CellScope).ownerCell.typeDeclaration;
  1245. Basic.SuffixSegmentedName(pooledName, td.name);
  1246. END;
  1247. END Scope;
  1248. BEGIN
  1249. FOR i := 0 TO LEN(pooledName)-1 DO pooledName[i] := -1 END;
  1250. Scope(symbol.scope);
  1251. Basic.SuffixSegmentedName(pooledName, symbol.name);
  1252. END GetSymbolSegmentedNameInScope;
  1253. PROCEDURE GetSymbolSegmentedName*(symbol: SyntaxTree.Symbol; VAR pooledName: Basic.SegmentedName);
  1254. BEGIN
  1255. GetSymbolSegmentedNameInScope(symbol,NIL,pooledName);
  1256. END GetSymbolSegmentedName;
  1257. PROCEDURE Level*(t: SyntaxTree.Type): LONGINT;
  1258. VAR level: LONGINT;
  1259. BEGIN
  1260. IF t IS SyntaxTree.IntegerType THEN
  1261. CASE t.sizeInBits OF
  1262. 8: level := 0;
  1263. |16: level := 1;
  1264. |32: level := 2;
  1265. |64: level := 3;
  1266. END;
  1267. ELSIF t IS SyntaxTree.FloatType THEN
  1268. CASE t.sizeInBits OF
  1269. 32: level := 4;
  1270. |64: level := 5;
  1271. END
  1272. ELSE HALT(100)
  1273. END;
  1274. RETURN level
  1275. END Level;
  1276. PROCEDURE ConvertSigned*(this: HUGEINT; bits: LONGINT): HUGEINT;
  1277. BEGIN
  1278. bits := 64-bits;
  1279. RETURN ASH (ASH (this, bits), -bits);
  1280. END ConvertSigned;
  1281. PROCEDURE ConvertUnsigned*(this: HUGEINT; bits: LONGINT): HUGEINT;
  1282. BEGIN
  1283. bits := 64-bits;
  1284. RETURN LSH (LSH (this, bits), -bits);
  1285. END ConvertUnsigned;
  1286. PROCEDURE MaxInteger*(system: System; type: SyntaxTree.BasicType; signed: BOOLEAN): HUGEINT;
  1287. BEGIN
  1288. IF signed THEN
  1289. RETURN ASH (HUGEINT(1), system.SizeOf (type) - 1) - 1;
  1290. ELSE
  1291. RETURN LSH (HUGEINT(-1), system.SizeOf (type) - 64);
  1292. END;
  1293. END MaxInteger;
  1294. PROCEDURE MinInteger*(system: System; type: SyntaxTree.BasicType; signed: BOOLEAN): HUGEINT;
  1295. BEGIN
  1296. IF signed THEN
  1297. RETURN -ASH (HUGEINT(1), system.SizeOf (type) - 1);
  1298. ELSE
  1299. RETURN 0
  1300. END;
  1301. END MinInteger;
  1302. (*! make architecture independent ! *)
  1303. PROCEDURE MaxFloat*(system: System; type: SyntaxTree.FloatType): LONGREAL;
  1304. BEGIN
  1305. IF system.SizeOf(type) = 32 THEN RETURN MAX(REAL) ELSE RETURN MAX(LONGREAL) END;
  1306. END MaxFloat;
  1307. PROCEDURE MinFloat*(system: System; type: SyntaxTree.FloatType): LONGREAL;
  1308. BEGIN
  1309. IF system.SizeOf(type) = 32 THEN RETURN MIN(REAL) ELSE RETURN MIN(LONGREAL) END;
  1310. END MinFloat;
  1311. PROCEDURE ConvertSet*(this: Basic.Set; bits: LONGINT): Basic.Set;
  1312. BEGIN
  1313. WHILE bits <= MAX (Basic.Set) DO EXCL (this, bits); INC (bits) END;
  1314. RETURN this;
  1315. END ConvertSet;
  1316. PROCEDURE IsUnsignedInteger*(this: HUGEINT; sizeInBits: LONGINT): BOOLEAN;
  1317. VAR m: HUGEINT;
  1318. BEGIN
  1319. m := ASH(HUGEINT(1),sizeInBits);
  1320. RETURN (this >= 0) & (this < m)
  1321. END IsUnsignedInteger;
  1322. PROCEDURE IsSignedInteger*(this: HUGEINT; sizeInBits: LONGINT): BOOLEAN;
  1323. VAR m: HUGEINT;
  1324. BEGIN
  1325. m := ASH(HUGEINT(1),sizeInBits-1);
  1326. RETURN (this < m) & (-this <= m)
  1327. END IsSignedInteger;
  1328. PROCEDURE GetSignedIntegerType*(system: System; this: HUGEINT): SyntaxTree.IntegerType;
  1329. (* code snippets for unsigned
  1330. ELSE
  1331. m := Runtime.AslH(1,system.SizeOf(type));
  1332. RETURN (this >= 0) & (this < m)
  1333. END;
  1334. PROCEDURE Bits(x: HUGEINT): BOOLEAN;
  1335. BEGIN
  1336. WHILE x > 0 DO INC(bits); x := x DIV 2 END;
  1337. END Bits;
  1338. IF a = MIN(HUGEINT) THEN (* -a does not work on lowest possible number, ~a+1 would overflow *)
  1339. RETURN Integer[64]
  1340. ELSIF a < 0 THEN
  1341. RETURN Integer[Bits(-a-1)+1]
  1342. ELSE
  1343. RETURN Unisgned[Bits(a)]
  1344. END;
  1345. *)
  1346. BEGIN
  1347. IF IsSignedInteger(this,8) THEN RETURN Integer8
  1348. ELSIF IsSignedInteger(this, 16) THEN RETURN Integer16
  1349. ELSIF IsSignedInteger(this, 32) THEN RETURN Integer32
  1350. ELSE RETURN Integer64
  1351. END;
  1352. END GetSignedIntegerType;
  1353. PROCEDURE GetIntegerType*(system: System; this: HUGEINT): SyntaxTree.IntegerType;
  1354. BEGIN
  1355. IF IsSignedInteger(this,8) THEN RETURN Integer8
  1356. (* system.SizeOf(...) = 8 : detect special backends with no sizes smaller than 32 *)
  1357. ELSIF (system.SizeOf(Unsigned8) = 8) & IsUnsignedInteger(this,8) THEN RETURN Unsigned8
  1358. ELSIF IsSignedInteger(this, 16) THEN RETURN Integer16
  1359. ELSIF (system.SizeOf(Unsigned16) = 16) & IsUnsignedInteger(this,16) THEN RETURN Unsigned16
  1360. ELSIF IsSignedInteger(this, 32) THEN RETURN Integer32
  1361. ELSIF IsUnsignedInteger(this,32) THEN RETURN Unsigned32
  1362. ELSE RETURN Integer64
  1363. END;
  1364. END GetIntegerType;
  1365. PROCEDURE NewIntegerValue*(system: System; position: Position; hugeint: HUGEINT): SyntaxTree.Value;
  1366. VAR value: SyntaxTree.IntegerValue;
  1367. BEGIN
  1368. value := SyntaxTree.NewIntegerValue(position,hugeint);
  1369. value.SetType(GetIntegerType(system,hugeint));
  1370. RETURN value
  1371. END NewIntegerValue;
  1372. PROCEDURE NewBooleanValue*(system: System; position: Position; b: BOOLEAN): SyntaxTree.Value;
  1373. VAR value: SyntaxTree.BooleanValue;
  1374. BEGIN
  1375. value := SyntaxTree.NewBooleanValue(position,b);
  1376. value.SetType(system.booleanType);
  1377. RETURN value
  1378. END NewBooleanValue;
  1379. PROCEDURE GetSetType*(system: System; this: Basic.Set): SyntaxTree.SetType;
  1380. BEGIN
  1381. IF this * {0 .. 7} = this THEN RETURN Set8
  1382. ELSIF this * { 0 .. 15 } = this THEN RETURN Set16
  1383. ELSIF this * { 0 .. 31 } = this THEN RETURN Set32
  1384. ELSE RETURN Set64
  1385. END
  1386. END GetSetType;
  1387. PROCEDURE NewSetValue*(system: System; position: Position; s: Basic.Set): SyntaxTree.Value;
  1388. VAR value: SyntaxTree.SetValue;
  1389. BEGIN
  1390. value := SyntaxTree.NewSetValue(position,s);
  1391. value.SetType(GetSetType(system,s));
  1392. RETURN value
  1393. END NewSetValue;
  1394. PROCEDURE NewCharacterValue*(system: System; position: Position; c: CHAR): SyntaxTree.Value;
  1395. VAR value: SyntaxTree.CharacterValue;
  1396. BEGIN
  1397. value := SyntaxTree.NewCharacterValue(position,c);
  1398. value.SetType(system.characterType);
  1399. RETURN value
  1400. END NewCharacterValue;
  1401. PROCEDURE NewNilValue*(system: System; position: Position): SyntaxTree.Value;
  1402. VAR value: SyntaxTree.NilValue;
  1403. BEGIN
  1404. value := SyntaxTree.NewNilValue(position);
  1405. value.SetType(system.anyType);
  1406. RETURN value
  1407. END NewNilValue;
  1408. (* distance for assignment to <- from *)
  1409. PROCEDURE BasicTypeDistance*(system: System; from, to: SyntaxTree.BasicType): LONGINT;
  1410. VAR fromSize, toSize, distance: LONGINT;
  1411. BEGIN
  1412. fromSize := system.SizeOf(from); toSize := system.SizeOf(to);
  1413. distance := -1;
  1414. IF (from IS SyntaxTree.IntegerType) & (to IS SyntaxTree.IntegerType) & (toSize >= fromSize) THEN
  1415. IF from(SyntaxTree.IntegerType).signed # to(SyntaxTree.IntegerType).signed THEN
  1416. IF (toSize=fromSize) & to(SyntaxTree.IntegerType).signed THEN
  1417. distance := MIN(LONGINT)
  1418. ELSE
  1419. INC(distance,2);
  1420. END;
  1421. END;
  1422. WHILE toSize >= fromSize DO
  1423. toSize := toSize DIV 2; INC(distance);
  1424. END;
  1425. ELSIF (from IS SyntaxTree.IntegerType) & (to IS SyntaxTree.SizeType) & (toSize >= fromSize) THEN
  1426. distance := 1;
  1427. WHILE toSize >= fromSize DO
  1428. toSize := toSize DIV 2; INC(distance);
  1429. END;
  1430. ELSIF (from IS SyntaxTree.SizeType) & (to IS SyntaxTree.IntegerType) & (toSize >= fromSize) THEN
  1431. distance := 1;
  1432. WHILE toSize >= fromSize DO
  1433. toSize := toSize DIV 2; INC(distance);
  1434. END;
  1435. ELSIF (from IS SyntaxTree.CharacterType) & (to IS SyntaxTree.CharacterType) & (toSize >= fromSize) OR
  1436. (from IS SyntaxTree.FloatType) & (to IS SyntaxTree.FloatType) & (toSize >= fromSize) OR
  1437. (from IS SyntaxTree.SetType) & (to IS SyntaxTree.SetType) & (toSize >= fromSize)
  1438. THEN
  1439. WHILE toSize >= fromSize DO
  1440. toSize := toSize DIV 2; INC(distance);
  1441. END;
  1442. ELSIF (from IS SyntaxTree.IntegerType) & (to IS SyntaxTree.FloatType) THEN
  1443. IF toSize = 64 THEN distance := 1 ELSE distance := 0 END;
  1444. toSize := 64;
  1445. WHILE toSize >= fromSize DO
  1446. toSize := toSize DIV 2; INC(distance);
  1447. END;
  1448. ELSIF (from IS SyntaxTree.SizeType) & (to IS SyntaxTree.FloatType) THEN
  1449. distance := 1;
  1450. WHILE toSize >= fromSize DO
  1451. toSize := toSize DIV 2; INC(distance);
  1452. END;
  1453. ELSIF (from IS SyntaxTree.RangeType) & (to IS SyntaxTree.RangeType) THEN
  1454. distance := 0;
  1455. ELSIF (from IS SyntaxTree.BooleanType) & (to IS SyntaxTree.BooleanType) THEN
  1456. distance := 0;
  1457. END;
  1458. IF distance < 0 THEN distance := MAX(LONGINT) END;
  1459. RETURN distance
  1460. END BasicTypeDistance;
  1461. PROCEDURE GetIdentifier*(symbol: LONGINT; case: LONGINT): SyntaxTree.Identifier;
  1462. BEGIN
  1463. IF (symbol >= 0) & (symbol < LEN(identifiers,1)) THEN
  1464. RETURN identifiers[case,symbol]
  1465. ELSE
  1466. RETURN SyntaxTree.invalidIdentifier
  1467. END;
  1468. END GetIdentifier;
  1469. PROCEDURE GetSymbol*(case: LONGINT; id: SyntaxTree.Identifier): LONGINT;
  1470. VAR i: LONGINT;
  1471. BEGIN
  1472. (*! quick and dirty implementation, optimize ! *)
  1473. FOR i := 0 TO LEN(identifiers,1)-1 DO
  1474. IF id=identifiers[case,i] THEN RETURN i END;
  1475. END;
  1476. RETURN -1
  1477. END GetSymbol;
  1478. PROCEDURE InitIdentifiers;
  1479. VAR i: LONGINT;
  1480. PROCEDURE NewKeywordIdentifier(op: LONGINT);
  1481. VAR id: Scanner.IdentifierType;
  1482. BEGIN
  1483. Scanner.GetKeyword(Scanner.Uppercase,op,id);
  1484. identifiers[Scanner.Uppercase,op] := id;
  1485. Scanner.GetKeyword(Scanner.Lowercase,op,id);
  1486. identifiers[Scanner.Lowercase,op] := id;
  1487. END NewKeywordIdentifier;
  1488. PROCEDURE NewBuiltinIdentifier(op: LONGINT; CONST name: ARRAY OF CHAR);
  1489. VAR nameL,nameU: Scanner.IdentifierString;
  1490. BEGIN
  1491. ASSERT(op < LEN(identifiers[0]));
  1492. Basic.Lowercase(name,nameL);
  1493. Basic.Uppercase(name,nameU);
  1494. identifiers[Scanner.Lowercase,op] := SyntaxTree.NewIdentifier(nameL);
  1495. identifiers[Scanner.Uppercase,op] := SyntaxTree.NewIdentifier(nameU);
  1496. END NewBuiltinIdentifier;
  1497. BEGIN
  1498. FOR i := 0 TO LEN(identifiers,1)-1 DO
  1499. identifiers[Scanner.Uppercase,i] := SyntaxTree.invalidIdentifier; identifiers[Scanner.Lowercase,i] := SyntaxTree.invalidIdentifier;
  1500. END;
  1501. FOR i := 0 TO Scanner.EndOfText-1 DO
  1502. NewKeywordIdentifier(i);
  1503. END;
  1504. NewBuiltinIdentifier(Abs,"ABS");
  1505. NewBuiltinIdentifier(Ash,"ASH");
  1506. NewBuiltinIdentifier(Asr,"ASR");
  1507. NewBuiltinIdentifier(Cap,"CAP");
  1508. NewBuiltinIdentifier(Chr,"CHR");
  1509. NewBuiltinIdentifier(Chr32,"CHR32");
  1510. NewBuiltinIdentifier(Entier,"ENTIER");
  1511. NewBuiltinIdentifier(EntierH,"ENTIERH");
  1512. NewBuiltinIdentifier(Len,"LEN");
  1513. NewBuiltinIdentifier(Long,"LONG");
  1514. NewBuiltinIdentifier(Lsh,"LSH");
  1515. NewBuiltinIdentifier(Max,"MAX");
  1516. NewBuiltinIdentifier(Min,"MIN");
  1517. NewBuiltinIdentifier(Odd,"ODD");
  1518. NewBuiltinIdentifier(Ord,"ORD");
  1519. NewBuiltinIdentifier(Ord32,"ORD32");
  1520. NewBuiltinIdentifier(Ror,"ROR");
  1521. NewBuiltinIdentifier(Rot,"ROT");
  1522. NewBuiltinIdentifier(Short,"SHORT");
  1523. NewBuiltinIdentifier(Sum,"SUM");
  1524. NewBuiltinIdentifier(Dim,"DIM");
  1525. NewBuiltinIdentifier(Cas,"CAS");
  1526. NewBuiltinIdentifier(Dec,"DEC");
  1527. NewBuiltinIdentifier(Excl,"EXCL");
  1528. NewBuiltinIdentifier(Inc,"INC");
  1529. NewBuiltinIdentifier(Incl,"INCL");
  1530. NewBuiltinIdentifier(All,"ALL");
  1531. NewBuiltinIdentifier(Re,"RE");
  1532. NewBuiltinIdentifier(Im,"IM");
  1533. NewBuiltinIdentifier(IncMul,"INCMUL");
  1534. NewBuiltinIdentifier(DecMul,"DECMUL");
  1535. (* TODO: check if ok. The operators defined in FoxArrayBase require the following identifiers *)
  1536. (* TODO: ".*+" should preferably be added as a new token in the scanner *)
  1537. identifiers[Scanner.Lowercase, Scanner.Becomes] := SyntaxTree.NewIdentifier(":=");
  1538. identifiers[Scanner.Uppercase, Scanner.Becomes] := SyntaxTree.NewIdentifier(":=");
  1539. identifiers[Scanner.Lowercase, Scanner.Transpose] := SyntaxTree.NewIdentifier("`");
  1540. identifiers[Scanner.Uppercase, Scanner.Transpose] := SyntaxTree.NewIdentifier("`");
  1541. identifiers[Scanner.Lowercase, DotTimesPlus] := SyntaxTree.NewIdentifier(".*+");
  1542. identifiers[Scanner.Uppercase, DotTimesPlus] := SyntaxTree.NewIdentifier(".*+");
  1543. identifiers[Scanner.Lowercase, AtMulDec] := SyntaxTree.NewIdentifier("@MulDec");
  1544. identifiers[Scanner.Uppercase, AtMulDec] := SyntaxTree.NewIdentifier("@MulDec");
  1545. identifiers[Scanner.Lowercase, AtMulInc] := SyntaxTree.NewIdentifier("@MulInc");
  1546. identifiers[Scanner.Uppercase, AtMulInc] := SyntaxTree.NewIdentifier("@MulInc");
  1547. identifiers[Scanner.Lowercase,Conversion] := SyntaxTree.NewIdentifier("@Convert");
  1548. identifiers[Scanner.Uppercase,Conversion] := SyntaxTree.NewIdentifier("@Convert");
  1549. END InitIdentifiers;
  1550. (** initialize the global namespace *)
  1551. PROCEDURE Init;
  1552. BEGIN
  1553. InitIdentifiers;
  1554. (* names are not arbitrary, do not change unless you know what you do (compatibilty with paco!) *)
  1555. SystemName := SyntaxTree.NewIdentifier("SYSTEM");
  1556. systemName := SyntaxTree.NewIdentifier("system");
  1557. SelfParameterName := SyntaxTree.NewIdentifier("@Self");
  1558. ReturnParameterName := SyntaxTree.NewIdentifier("@ReturnParameter");
  1559. PointerReturnName := SyntaxTree.NewIdentifier("@PtrReturnType");
  1560. ResultName := SyntaxTree.NewIdentifier("RESULT");
  1561. A2Name := SyntaxTree.NewIdentifier("A2");
  1562. ArrayBaseName := SyntaxTree.NewIdentifier("FoxArrayBase");
  1563. ComplexNumbersName := SyntaxTree.NewIdentifier("ComplexNumbers");
  1564. RecordBodyName := SyntaxTree.NewIdentifier("@Body");
  1565. ModuleBodyName := SyntaxTree.NewIdentifier("@Body");
  1566. NameWinAPI := SyntaxTree.NewIdentifier(StringWinAPI);
  1567. NameC := SyntaxTree.NewIdentifier(StringC);
  1568. NamePlatformCC := SyntaxTree.NewIdentifier(StringPlatformCC);
  1569. NameMovable := SyntaxTree.NewIdentifier(StringMovable);
  1570. NameUntraced := SyntaxTree.NewIdentifier(StringUntraced);
  1571. NameDelegate := SyntaxTree.NewIdentifier(StringDelegate);
  1572. NameInterrupt := SyntaxTree.NewIdentifier(StringInterrupt);
  1573. NamePcOffset := SyntaxTree.NewIdentifier(StringPcOffset);
  1574. NameNoPAF := SyntaxTree.NewIdentifier(StringNoPAF);
  1575. NameEntry := SyntaxTree.NewIdentifier(StringEntry);
  1576. NameExit := SyntaxTree.NewIdentifier(StringExit);
  1577. NameFixed := SyntaxTree.NewIdentifier(StringFixed);
  1578. NameFictive := SyntaxTree.NewIdentifier(StringFictive);
  1579. NameAligned := SyntaxTree.NewIdentifier(StringAligned);
  1580. NameStackAligned := SyntaxTree.NewIdentifier(StringAlignStack);
  1581. NameExclusive := SyntaxTree.NewIdentifier(StringExclusive);
  1582. NameActive := SyntaxTree.NewIdentifier(StringActive);
  1583. NamePriority := SyntaxTree.NewIdentifier(StringPriority);
  1584. NameSafe := SyntaxTree.NewIdentifier(StringSafe);
  1585. NameRealtime := SyntaxTree.NewIdentifier(StringRealtime);
  1586. NameDynamic := SyntaxTree.NewIdentifier(StringDynamic);
  1587. NameDataMemorySize := SyntaxTree.NewIdentifier(StringDataMemorySize);
  1588. NameCodeMemorySize := SyntaxTree.NewIdentifier(StringCodeMemorySize);
  1589. NameChannelWidth := SyntaxTree.NewIdentifier(StringChannelWidth);
  1590. NameChannelDepth := SyntaxTree.NewIdentifier(StringChannelDepth);
  1591. NameChannelModule := SyntaxTree.NewIdentifier(StringChannelModule);
  1592. NameVector := SyntaxTree.NewIdentifier(StringVector);
  1593. NameFloatingPoint := SyntaxTree.NewIdentifier(StringFloatingPoint);
  1594. NameNoMul:= SyntaxTree.NewIdentifier(StringNoMul);
  1595. NameNonBlockingIO:=SyntaxTree.NewIdentifier(StringNonBlockingIO);
  1596. NameTRM := SyntaxTree.NewIdentifier(StringTRM);
  1597. NameTRMS := SyntaxTree.NewIdentifier(StringTRMS);
  1598. NameBackend := SyntaxTree.NewIdentifier(StringBackend);
  1599. NameRuntime := SyntaxTree.NewIdentifier(StringRuntime);
  1600. NameEngine := SyntaxTree.NewIdentifier(StringEngine);
  1601. NameFinal := SyntaxTree.NewIdentifier(StringFinal);
  1602. NameAbstract := SyntaxTree.NewIdentifier(StringAbstract);
  1603. NameFrequencyDivider := SyntaxTree.NewIdentifier(StringFrequencyDivider);
  1604. NameRegister := SyntaxTree.NewIdentifier(StringRegister);
  1605. NameNoReturn := SyntaxTree.NewIdentifier(StringNoReturn);
  1606. NamePlain := SyntaxTree.NewIdentifier(StringPlain);
  1607. NameUnsafe := SyntaxTree.NewIdentifier(StringUnsafe);
  1608. NameDisposable := SyntaxTree.NewIdentifier(StringDisposable);
  1609. NameUnchecked := SyntaxTree.NewIdentifier(StringUnchecked);
  1610. NameUncooperative := SyntaxTree.NewIdentifier(StringUncooperative);
  1611. NameFingerprint := SyntaxTree.NewIdentifier(StringFingerprint);
  1612. (* types *)
  1613. Boolean8 := SyntaxTree.NewBooleanType(8);
  1614. Boolean32 := SyntaxTree.NewBooleanType(32);
  1615. Integer8 := SyntaxTree.NewIntegerType(8, TRUE);
  1616. Integer16 := SyntaxTree.NewIntegerType(16, TRUE);
  1617. Integer32 := SyntaxTree.NewIntegerType(32, TRUE);
  1618. Integer64 := SyntaxTree.NewIntegerType(64, TRUE);
  1619. Unsigned8 := SyntaxTree.NewIntegerType(8, FALSE);
  1620. Unsigned16 := SyntaxTree.NewIntegerType(16, FALSE);
  1621. Unsigned32 := SyntaxTree.NewIntegerType(32, FALSE);
  1622. Unsigned64 := SyntaxTree.NewIntegerType(64, FALSE);
  1623. Float32 := SyntaxTree.NewFloatType(32);
  1624. Float64 := SyntaxTree.NewFloatType(64);
  1625. Complex64 := SyntaxTree.NewComplexType(Float32);
  1626. Complex128 := SyntaxTree.NewComplexType(Float64);
  1627. Byte8 := SyntaxTree.NewByteType(8);
  1628. Byte32 := SyntaxTree.NewByteType(32);
  1629. Character8 := SyntaxTree.NewCharacterType(8);
  1630. Character16 := SyntaxTree.NewCharacterType(16);
  1631. Character32 := SyntaxTree.NewCharacterType(32);
  1632. Set8 := SyntaxTree.NewSetType(8);
  1633. Set16 := SyntaxTree.NewSetType(16);
  1634. Set32 := SyntaxTree.NewSetType(32);
  1635. Set64 := SyntaxTree.NewSetType(64);
  1636. END Init;
  1637. BEGIN
  1638. Init;
  1639. END FoxGlobal.