FoxGlobal.Mod 70 KB

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