FoxGlobal.Mod 68 KB

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