FoxGlobal.Mod 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816
  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,Reshape,TRUE);
  913. OperatorDefined(system,Short,TRUE);
  914. OperatorDefined(system,Sum,TRUE);
  915. OperatorDefined(system,Dim,TRUE);
  916. OperatorDefined(system,Scanner.Address, TRUE);
  917. OperatorDefined(system,Scanner.Size, TRUE);
  918. OperatorDefined(system,Scanner.Alias, TRUE);
  919. OperatorDefined(system,All,TRUE);
  920. OperatorDefined(system,Re,TRUE);
  921. OperatorDefined(system,Im,TRUE);
  922. OperatorDefined(system, Scanner.Questionmarks, TRUE);
  923. OperatorDefined(system, Scanner.GreaterGreater, TRUE);
  924. OperatorDefined(system, Scanner.LessLess, TRUE);
  925. END SetDefaultOperators;
  926. PROCEDURE DefaultSystem*(): System;
  927. VAR system: System;
  928. BEGIN
  929. NEW(system,8,8,32, 8,32,32,32,64,FALSE);
  930. SetDefaultDeclarations(system,8);
  931. SetDefaultOperators(system);
  932. RETURN system
  933. END DefaultSystem;
  934. PROCEDURE IsOberonProcedure*(type: SyntaxTree.Type): BOOLEAN;
  935. BEGIN
  936. RETURN (type IS SyntaxTree.ProcedureType) & (type(SyntaxTree.ProcedureType).callingConvention = SyntaxTree.OberonCallingConvention)
  937. END IsOberonProcedure;
  938. PROCEDURE AlignedSizeOf*(system: System; CONST alignment: Alignment; type: SyntaxTree.Type):LONGINT;
  939. VAR value: LONGINT;
  940. BEGIN
  941. value := SHORT(system.SizeOf(type));
  942. INC(value, (-value) MOD system.AlignmentOf(alignment, type));
  943. RETURN value;
  944. END AlignedSizeOf;
  945. (* returns if a module is the system module *)
  946. PROCEDURE IsSystemModule*(module: SyntaxTree.Module): BOOLEAN;
  947. BEGIN RETURN (module.name=systemName) OR (module.name=SystemName)
  948. END IsSystemModule;
  949. (** Various factories *)
  950. PROCEDURE DeclareType0(type: SyntaxTree.Type; CONST name: ARRAY OF CHAR; in: SyntaxTree.Scope);
  951. VAR basic: SyntaxTree.TypeDeclaration; duplicate: BOOLEAN;
  952. BEGIN
  953. basic := SyntaxTree.NewTypeDeclaration(SyntaxTree.invalidPosition,SyntaxTree.NewIdentifier(name));
  954. basic.SetDeclaredType(type);
  955. basic.SetState(SyntaxTree.Resolved);
  956. basic.SetAccess(SyntaxTree.ReadOnly);
  957. in.AddTypeDeclaration(basic);
  958. in.EnterSymbol(basic,duplicate);
  959. ASSERT(~duplicate);
  960. END DeclareType0;
  961. (** External interface backends can use to add their types etc. to the global scope *)
  962. PROCEDURE DeclareType*(type: SyntaxTree.Type; CONST name: ARRAY OF CHAR; CONST scope: ARRAY OF SyntaxTree.ModuleScope);
  963. VAR nameL,nameU: Scanner.IdentifierString;
  964. BEGIN
  965. Basic.Lowercase(name,nameL);
  966. Basic.Uppercase(name,nameU);
  967. DeclareType0(type,nameU,scope[Scanner.Uppercase]);
  968. DeclareType0(type,nameL,scope[Scanner.Lowercase]);
  969. END DeclareType;
  970. (* LYNX+ *)
  971. PROCEDURE DeclareLynxType*(
  972. type: SyntaxTree.Type; CONST name: ARRAY OF CHAR; CONST scope: ARRAY OF SyntaxTree.ModuleScope);
  973. BEGIN
  974. DeclareType0(type, name, scope[Scanner.Uppercase]);
  975. DeclareType0(type, name, scope[Scanner.Lowercase]);
  976. END DeclareLynxType;
  977. (* -LYNX *)
  978. PROCEDURE NewConstant0(CONST name: ARRAY OF CHAR; int: LONGINT; type: SyntaxTree.Type; in: SyntaxTree.Scope);
  979. VAR constant: SyntaxTree.Constant; value: SyntaxTree.IntegerValue;duplicate: BOOLEAN;
  980. BEGIN
  981. value := SyntaxTree.NewIntegerValue(SyntaxTree.invalidPosition,int);
  982. value.SetType(type);
  983. constant := SyntaxTree.NewConstant(SyntaxTree.invalidPosition,SyntaxTree.NewIdentifier(name));
  984. constant.SetValue(value);
  985. constant.SetType(value.type);
  986. constant.SetAccess(SyntaxTree.ReadOnly);
  987. constant.SetState(SyntaxTree.Resolved);
  988. in.AddConstant(constant);
  989. in.EnterSymbol(constant,duplicate);
  990. ASSERT(~duplicate);
  991. END NewConstant0;
  992. PROCEDURE NewConstant*(CONST name: ARRAY OF CHAR; int: LONGINT; type: SyntaxTree.Type; CONST scope: ARRAY OF SyntaxTree.ModuleScope);
  993. VAR nameL,nameU: Scanner.IdentifierString;
  994. BEGIN
  995. Basic.Lowercase(name,nameL);
  996. Basic.Uppercase(name,nameU);
  997. NewConstant0(nameU,int,type,scope[Scanner.Uppercase]);
  998. NewConstant0(nameL,int,type,scope[Scanner.Lowercase]);
  999. END NewConstant;
  1000. PROCEDURE NewStringConstant0(CONST name: ARRAY OF CHAR; string: SyntaxTree.String; baseType: SyntaxTree.Type; in: SyntaxTree.Scope);
  1001. VAR constant: SyntaxTree.Constant; value: SyntaxTree.StringValue;duplicate: BOOLEAN;
  1002. BEGIN
  1003. value := SyntaxTree.NewStringValue(SyntaxTree.invalidPosition,string);
  1004. value.SetType(SyntaxTree.NewStringType(SyntaxTree.invalidPosition,baseType,value.length));
  1005. constant := SyntaxTree.NewConstant(SyntaxTree.invalidPosition,SyntaxTree.NewIdentifier(name));
  1006. constant.SetValue(value);
  1007. constant.SetType(value.type);
  1008. constant.SetAccess(SyntaxTree.ReadOnly);
  1009. constant.SetState(SyntaxTree.Resolved);
  1010. in.AddConstant(constant);
  1011. in.EnterSymbol(constant,duplicate);
  1012. ASSERT(~duplicate);
  1013. END NewStringConstant0;
  1014. PROCEDURE NewStringConstant*(CONST name: ARRAY OF CHAR; string: SyntaxTree.String; type: SyntaxTree.Type; CONST scope: ARRAY OF SyntaxTree.ModuleScope);
  1015. VAR nameL,nameU: Scanner.IdentifierString;
  1016. BEGIN
  1017. Basic.Lowercase(name,nameL);
  1018. Basic.Uppercase(name,nameU);
  1019. NewStringConstant0(nameU,string,type,scope[Scanner.Uppercase]);
  1020. NewStringConstant0(nameL,string,type,scope[Scanner.Lowercase]);
  1021. END NewStringConstant;
  1022. PROCEDURE NewStringConstantCamelCase*(CONST name: ARRAY OF CHAR; string: SyntaxTree.String; type: SyntaxTree.Type; CONST scope: ARRAY OF SyntaxTree.ModuleScope);
  1023. BEGIN
  1024. NewStringConstant0(name,string,type,scope[Scanner.Uppercase]);
  1025. NewStringConstant0(name,string,type,scope[Scanner.Lowercase]);
  1026. END NewStringConstantCamelCase;
  1027. PROCEDURE NewBuiltin0( id: LONGINT; CONST name: ARRAY OF CHAR; in: SyntaxTree.ModuleScope; realtime: BOOLEAN);
  1028. VAR basic: SyntaxTree.Builtin; duplicate: BOOLEAN; type: SyntaxTree.ProcedureType;
  1029. BEGIN
  1030. basic := SyntaxTree.NewBuiltin(SyntaxTree.invalidPosition,SyntaxTree.NewIdentifier(name),id);
  1031. basic.SetAccess(SyntaxTree.ReadOnly);
  1032. type := SyntaxTree.NewProcedureType(SyntaxTree.invalidPosition,in);
  1033. type.SetRealtime(realtime);
  1034. type.SetReturnType(SyntaxTree.invalidType); (* make incompatible to any procedure *)
  1035. basic.SetType(type);
  1036. basic.SetState(SyntaxTree.Resolved);
  1037. in.EnterSymbol(basic,duplicate);
  1038. in.AddBuiltin(basic);
  1039. ASSERT(~duplicate);
  1040. END NewBuiltin0;
  1041. PROCEDURE NewBuiltin*(id: LONGINT; CONST name: ARRAY OF CHAR; CONST scope: ARRAY OF SyntaxTree.ModuleScope; realtime: BOOLEAN);
  1042. VAR nameL,nameU: Scanner.IdentifierString;
  1043. BEGIN
  1044. Basic.Lowercase(name,nameL);
  1045. Basic.Uppercase(name,nameU);
  1046. NewBuiltin0(id,nameU,scope[Scanner.Uppercase],realtime);
  1047. NewBuiltin0(id,nameL,scope[Scanner.Lowercase],realtime);
  1048. END NewBuiltin;
  1049. PROCEDURE NewBuiltinCamelCase*(id: LONGINT; CONST name: ARRAY OF CHAR; CONST scope: ARRAY OF SyntaxTree.ModuleScope; realtime: BOOLEAN);
  1050. BEGIN
  1051. NewBuiltin0(id,name,scope[Scanner.Uppercase],realtime);
  1052. NewBuiltin0(id,name,scope[Scanner.Lowercase],realtime);
  1053. END NewBuiltinCamelCase;
  1054. PROCEDURE NewCustomBuiltin0(CONST name: ARRAY OF CHAR; scope: SyntaxTree.ModuleScope; subType: SHORTINT; procedureType: SyntaxTree.ProcedureType);
  1055. VAR
  1056. isDuplicate: BOOLEAN;
  1057. customBuiltin: SyntaxTree.CustomBuiltin;
  1058. BEGIN
  1059. customBuiltin := SyntaxTree.NewCustomBuiltin(SyntaxTree.invalidPosition, SyntaxTree.NewIdentifier(name), systemSpecial, subType);
  1060. customBuiltin.SetAccess(SyntaxTree.ReadOnly); (* TODO: this might be changed *)
  1061. procedureType.SetRealtime(TRUE);
  1062. customBuiltin.SetType(procedureType); (* TODO: make incompatible to any procedure *)
  1063. customBuiltin.SetState(SyntaxTree.Resolved);
  1064. scope.EnterSymbol(customBuiltin, isDuplicate);
  1065. scope.AddBuiltin(customBuiltin);
  1066. ASSERT(~isDuplicate)
  1067. END NewCustomBuiltin0;
  1068. PROCEDURE NewCustomBuiltin*(CONST name: ARRAY OF CHAR; CONST scope: ARRAY OF SyntaxTree.ModuleScope; subType: SHORTINT; procedureType: SyntaxTree.ProcedureType);
  1069. VAR
  1070. nameL, nameU: Scanner.IdentifierString;
  1071. BEGIN
  1072. Basic.Lowercase(name, nameL);
  1073. Basic.Uppercase(name, nameU);
  1074. NewCustomBuiltin0(nameU, scope[Scanner.Uppercase], subType, procedureType);
  1075. NewCustomBuiltin0(nameL, scope[Scanner.Lowercase], subType, procedureType)
  1076. END NewCustomBuiltin;
  1077. PROCEDURE GetModuleSectionName*(name, context: SyntaxTree.Identifier; VAR n: ARRAY OF CHAR);
  1078. VAR s: SyntaxTree.IdentifierString;
  1079. BEGIN
  1080. IF context # SyntaxTree.invalidIdentifier THEN
  1081. Basic.GetString(context,n);
  1082. IF n = "A2" THEN
  1083. Basic.GetString(name,n);
  1084. RETURN;
  1085. END;
  1086. Basic.GetString(name,s);
  1087. Strings.Append(n,"-");Strings.Append(n,s);
  1088. ELSE
  1089. IF name # SyntaxTree.invalidIdentifier THEN
  1090. Basic.GetString(name,n);
  1091. ELSE
  1092. n := ""
  1093. END
  1094. END;
  1095. END GetModuleSectionName;
  1096. PROCEDURE ModuleFileName*(name, context: SyntaxTree.Identifier; VAR n: ARRAY OF CHAR);
  1097. BEGIN
  1098. GetModuleSectionName(name, context, n);
  1099. END ModuleFileName;
  1100. PROCEDURE ModuleSectionIdentifier*(name, context: SyntaxTree.Identifier): SyntaxTree.Identifier;
  1101. VAR n: SyntaxTree.IdentifierString;
  1102. BEGIN
  1103. IF context # SyntaxTree.invalidIdentifier THEN
  1104. GetModuleSectionName(name, context, n);
  1105. RETURN SyntaxTree.NewIdentifier(n);
  1106. ELSE
  1107. RETURN name
  1108. END;
  1109. END ModuleSectionIdentifier;
  1110. PROCEDURE ContextFromName*(CONST fileName: ARRAY OF CHAR; VAR module,context: SyntaxTree.Identifier);
  1111. VAR moduleName, contextName: Scanner.IdentifierString; i,j: LONGINT;
  1112. BEGIN
  1113. i := 0; j := 0;
  1114. WHILE (fileName[i] # 0X) & (fileName[i] # ".") DO
  1115. moduleName[i] := fileName[i];
  1116. INC(i);
  1117. END;
  1118. moduleName[i] := 0X;
  1119. IF fileName[i] # 0X THEN
  1120. COPY(moduleName, contextName);
  1121. INC(i);
  1122. WHILE(fileName[i] # 0X) DO
  1123. moduleName[j] := fileName[i];
  1124. INC(i); INC(j);
  1125. END;
  1126. moduleName[j] := 0X;
  1127. ELSE
  1128. contextName := "A2";
  1129. END;
  1130. module := SyntaxTree.NewIdentifier(moduleName);
  1131. context := SyntaxTree.NewIdentifier(contextName);
  1132. END ContextFromName;
  1133. PROCEDURE GetModuleName*(module: SyntaxTree.Module; VAR name: ARRAY OF CHAR);
  1134. BEGIN
  1135. GetModuleSectionName(module.name, module.context, name);
  1136. END GetModuleName;
  1137. PROCEDURE GetModuleSegmentedName*(module: SyntaxTree.Module; VAR name: Basic.SegmentedName);
  1138. BEGIN
  1139. name[0] := ModuleSectionIdentifier(module.name, module.context);
  1140. name[1] := -1;
  1141. END GetModuleSegmentedName;
  1142. PROCEDURE FindSymbol*(CONST name: Basic.SegmentedName; scope: SyntaxTree.Scope): SyntaxTree.Symbol;
  1143. VAR s: LONGINT; symbol : SyntaxTree.Symbol;
  1144. PROCEDURE GetSymbolScope;
  1145. VAR type: SyntaxTree.Type;
  1146. BEGIN
  1147. IF symbol IS SyntaxTree.Module THEN
  1148. scope := symbol(SyntaxTree.Module).moduleScope
  1149. ELSIF symbol IS SyntaxTree.Import THEN
  1150. scope := symbol(SyntaxTree.Import).module.moduleScope;
  1151. ELSIF symbol IS SyntaxTree.Procedure THEN
  1152. scope := symbol(SyntaxTree.Procedure).procedureScope
  1153. ELSIF symbol IS SyntaxTree.TypeDeclaration THEN
  1154. type := symbol(SyntaxTree.TypeDeclaration).declaredType.resolved;
  1155. IF type IS SyntaxTree.RecordType THEN
  1156. scope := type(SyntaxTree.RecordType).recordScope
  1157. END;
  1158. ELSE
  1159. scope := NIL
  1160. END
  1161. END GetSymbolScope;
  1162. PROCEDURE FindSymbol(name: SyntaxTree.Identifier): SyntaxTree.Symbol;
  1163. BEGIN
  1164. IF scope = scope.ownerModule.moduleScope THEN
  1165. symbol := scope.ownerModule.moduleScope.ImportByModuleName(name, scope.ownerModule.context);
  1166. IF symbol = NIL THEN
  1167. symbol := scope.FindSymbol(name)
  1168. END;
  1169. ELSE
  1170. symbol := scope.FindSymbol(name)
  1171. END;
  1172. RETURN symbol
  1173. END FindSymbol;
  1174. BEGIN
  1175. s := 0;
  1176. IF name[0] = scope.ownerModule.name THEN
  1177. INC(s)
  1178. END;
  1179. scope := scope.ownerModule.moduleScope; (* expect fully qualified (segmented) name *)
  1180. REPEAT
  1181. IF scope = NIL THEN RETURN NIL END;
  1182. symbol := FindSymbol(name[s]);
  1183. IF symbol = NIL THEN RETURN NIL
  1184. ELSE
  1185. GetSymbolScope
  1186. END;
  1187. INC(s);
  1188. UNTIL (s = LEN(name)) OR (name[s] < 0);
  1189. RETURN symbol;
  1190. END FindSymbol;
  1191. PROCEDURE GetSymbolNameInScope*(symbol: SyntaxTree.Symbol; inScope: SyntaxTree.Scope; VAR name: ARRAY OF CHAR);
  1192. VAR n: SyntaxTree.IdentifierString; td: SyntaxTree.TypeDeclaration;
  1193. PROCEDURE Scope(scope: SyntaxTree.Scope);
  1194. BEGIN
  1195. IF scope = NIL THEN (* do nothing, locally declared temporary symbol *)
  1196. ELSIF scope = inScope THEN (* do not traverse further *)
  1197. ELSIF scope IS SyntaxTree.ModuleScope THEN
  1198. GetModuleName(scope.ownerModule, name);
  1199. Strings.Append(name,".");
  1200. ELSIF scope IS SyntaxTree.RecordScope THEN
  1201. Scope(scope.outerScope);
  1202. td := scope(SyntaxTree.RecordScope).ownerRecord.typeDeclaration;
  1203. IF td = NIL THEN
  1204. td := scope(SyntaxTree.RecordScope).ownerRecord.pointerType.typeDeclaration;
  1205. END;
  1206. td.GetName(n);
  1207. Strings.Append(name,n); Strings.Append(name,".")
  1208. ELSIF scope IS SyntaxTree.ProcedureScope THEN
  1209. Scope(scope.outerScope);
  1210. scope(SyntaxTree.ProcedureScope).ownerProcedure.GetName(n);
  1211. Strings.Append(name,n); Strings.Append(name,".")
  1212. ELSIF scope IS SyntaxTree.CellScope THEN
  1213. Scope(scope.outerScope);
  1214. td := scope(SyntaxTree.CellScope).ownerCell.typeDeclaration;
  1215. td.GetName(n);
  1216. Strings.Append(name,n); Strings.Append(name,".")
  1217. END;
  1218. END Scope;
  1219. BEGIN
  1220. name := "";
  1221. Scope(symbol.scope);
  1222. symbol.GetName(n);
  1223. IF symbol IS SyntaxTree.Operator THEN (*! append some more bits to make discrimintation possible *)
  1224. END;
  1225. Strings.Append(name,n);
  1226. END GetSymbolNameInScope;
  1227. PROCEDURE GetSymbolName*(symbol: SyntaxTree.Symbol; VAR name: ARRAY OF CHAR);
  1228. BEGIN GetSymbolNameInScope(symbol,NIL,name)
  1229. END GetSymbolName;
  1230. PROCEDURE GetSymbolSegmentedNameInScope*(symbol: SyntaxTree.Symbol; inScope: SyntaxTree.Scope; VAR pooledName: Basic.SegmentedName);
  1231. VAR td: SyntaxTree.TypeDeclaration; i: LONGINT;
  1232. PROCEDURE Scope(scope: SyntaxTree.Scope);
  1233. BEGIN
  1234. IF scope = NIL THEN (* do nothing, locally declared temporary symbol *)
  1235. ELSIF scope = inScope THEN (* do not traverse further *)
  1236. ELSIF scope IS SyntaxTree.ModuleScope THEN
  1237. Basic.SuffixSegmentedName(pooledName,ModuleSectionIdentifier(scope.ownerModule.name, scope.ownerModule.context));
  1238. ELSIF scope IS SyntaxTree.RecordScope THEN
  1239. Scope(scope.outerScope);
  1240. td := scope(SyntaxTree.RecordScope).ownerRecord.typeDeclaration;
  1241. IF td = NIL THEN
  1242. td := scope(SyntaxTree.RecordScope).ownerRecord.pointerType.typeDeclaration;
  1243. END;
  1244. Basic.SuffixSegmentedName(pooledName,td.name);
  1245. ELSIF scope IS SyntaxTree.ProcedureScope THEN
  1246. Scope(scope.outerScope);
  1247. Basic.SuffixSegmentedName(pooledName,scope(SyntaxTree.ProcedureScope).ownerProcedure.name);
  1248. ELSIF scope IS SyntaxTree.CellScope THEN
  1249. Scope(scope.outerScope);
  1250. td := scope(SyntaxTree.CellScope).ownerCell.typeDeclaration;
  1251. Basic.SuffixSegmentedName(pooledName, td.name);
  1252. END;
  1253. END Scope;
  1254. BEGIN
  1255. FOR i := 0 TO LEN(pooledName)-1 DO pooledName[i] := -1 END;
  1256. Scope(symbol.scope);
  1257. Basic.SuffixSegmentedName(pooledName, symbol.name);
  1258. END GetSymbolSegmentedNameInScope;
  1259. PROCEDURE GetSymbolSegmentedName*(symbol: SyntaxTree.Symbol; VAR pooledName: Basic.SegmentedName);
  1260. BEGIN
  1261. GetSymbolSegmentedNameInScope(symbol,NIL,pooledName);
  1262. END GetSymbolSegmentedName;
  1263. PROCEDURE Level*(t: SyntaxTree.Type): LONGINT;
  1264. VAR level: LONGINT;
  1265. BEGIN
  1266. IF t IS SyntaxTree.IntegerType THEN
  1267. CASE t.sizeInBits OF
  1268. 8: level := 0;
  1269. |16: level := 1;
  1270. |32: level := 2;
  1271. |64: level := 3;
  1272. END;
  1273. ELSIF t IS SyntaxTree.FloatType THEN
  1274. CASE t.sizeInBits OF
  1275. 32: level := 4;
  1276. |64: level := 5;
  1277. END
  1278. ELSE HALT(100)
  1279. END;
  1280. RETURN level
  1281. END Level;
  1282. PROCEDURE ConvertSigned*(this: HUGEINT; bits: LONGINT): HUGEINT;
  1283. BEGIN
  1284. bits := 64-bits;
  1285. RETURN ASH (ASH (this, bits), -bits);
  1286. END ConvertSigned;
  1287. PROCEDURE ConvertUnsigned*(this: HUGEINT; bits: LONGINT): HUGEINT;
  1288. BEGIN
  1289. bits := 64-bits;
  1290. RETURN LSH (LSH (this, bits), -bits);
  1291. END ConvertUnsigned;
  1292. PROCEDURE MaxInteger*(system: System; type: SyntaxTree.BasicType; signed: BOOLEAN): HUGEINT;
  1293. BEGIN
  1294. IF signed THEN
  1295. RETURN ASH (HUGEINT(1), system.SizeOf (type) - 1) - 1;
  1296. ELSE
  1297. RETURN LSH (HUGEINT(-1), system.SizeOf (type) - 64);
  1298. END;
  1299. END MaxInteger;
  1300. PROCEDURE MinInteger*(system: System; type: SyntaxTree.BasicType; signed: BOOLEAN): HUGEINT;
  1301. BEGIN
  1302. IF signed THEN
  1303. RETURN -ASH (HUGEINT(1), system.SizeOf (type) - 1);
  1304. ELSE
  1305. RETURN 0
  1306. END;
  1307. END MinInteger;
  1308. (*! make architecture independent ! *)
  1309. PROCEDURE MaxFloat*(system: System; type: SyntaxTree.FloatType): LONGREAL;
  1310. BEGIN
  1311. IF system.SizeOf(type) = 32 THEN RETURN MAX(REAL) ELSE RETURN MAX(LONGREAL) END;
  1312. END MaxFloat;
  1313. PROCEDURE MinFloat*(system: System; type: SyntaxTree.FloatType): LONGREAL;
  1314. BEGIN
  1315. IF system.SizeOf(type) = 32 THEN RETURN MIN(REAL) ELSE RETURN MIN(LONGREAL) END;
  1316. END MinFloat;
  1317. PROCEDURE ConvertSet*(this: Basic.Set; bits: LONGINT): Basic.Set;
  1318. BEGIN
  1319. WHILE bits <= MAX (Basic.Set) DO EXCL (this, bits); INC (bits) END;
  1320. RETURN this;
  1321. END ConvertSet;
  1322. PROCEDURE IsUnsignedInteger*(this: HUGEINT; sizeInBits: LONGINT): BOOLEAN;
  1323. VAR m: HUGEINT;
  1324. BEGIN
  1325. m := ASH(HUGEINT(1),sizeInBits);
  1326. RETURN (this >= 0) & (this < m)
  1327. END IsUnsignedInteger;
  1328. PROCEDURE IsSignedInteger*(this: HUGEINT; sizeInBits: LONGINT): BOOLEAN;
  1329. VAR m: HUGEINT;
  1330. BEGIN
  1331. m := ASH(HUGEINT(1),sizeInBits-1);
  1332. RETURN (this < m) & (-this <= m)
  1333. END IsSignedInteger;
  1334. PROCEDURE GetSignedIntegerType*(system: System; this: HUGEINT): SyntaxTree.IntegerType;
  1335. (* code snippets for unsigned
  1336. ELSE
  1337. m := Builtins.AslH(1,system.SizeOf(type));
  1338. RETURN (this >= 0) & (this < m)
  1339. END;
  1340. PROCEDURE Bits(x: HUGEINT): BOOLEAN;
  1341. BEGIN
  1342. WHILE x > 0 DO INC(bits); x := x DIV 2 END;
  1343. END Bits;
  1344. IF a = MIN(HUGEINT) THEN (* -a does not work on lowest possible number, ~a+1 would overflow *)
  1345. RETURN Integer[64]
  1346. ELSIF a < 0 THEN
  1347. RETURN Integer[Bits(-a-1)+1]
  1348. ELSE
  1349. RETURN Unisgned[Bits(a)]
  1350. END;
  1351. *)
  1352. BEGIN
  1353. IF IsSignedInteger(this,8) THEN RETURN Integer8
  1354. ELSIF IsSignedInteger(this, 16) THEN RETURN Integer16
  1355. ELSIF IsSignedInteger(this, 32) THEN RETURN Integer32
  1356. ELSE RETURN Integer64
  1357. END;
  1358. END GetSignedIntegerType;
  1359. PROCEDURE GetIntegerType*(system: System; this: HUGEINT): SyntaxTree.IntegerType;
  1360. BEGIN
  1361. IF IsSignedInteger(this,8) THEN RETURN Integer8
  1362. (* system.SizeOf(...) = 8 : detect special backends with no sizes smaller than 32 *)
  1363. ELSIF (system.SizeOf(Unsigned8) = 8) & IsUnsignedInteger(this,8) THEN RETURN Unsigned8
  1364. ELSIF IsSignedInteger(this, 16) THEN RETURN Integer16
  1365. ELSIF (system.SizeOf(Unsigned16) = 16) & IsUnsignedInteger(this,16) THEN RETURN Unsigned16
  1366. ELSIF IsSignedInteger(this, 32) THEN RETURN Integer32
  1367. ELSIF IsUnsignedInteger(this,32) THEN RETURN Unsigned32
  1368. ELSE RETURN Integer64
  1369. END;
  1370. END GetIntegerType;
  1371. PROCEDURE NewIntegerValue*(system: System; position: Position; hugeint: HUGEINT): SyntaxTree.Value;
  1372. VAR value: SyntaxTree.IntegerValue;
  1373. BEGIN
  1374. value := SyntaxTree.NewIntegerValue(position,hugeint);
  1375. value.SetType(GetIntegerType(system,hugeint));
  1376. RETURN value
  1377. END NewIntegerValue;
  1378. PROCEDURE NewBooleanValue*(system: System; position: Position; b: BOOLEAN): SyntaxTree.Value;
  1379. VAR value: SyntaxTree.BooleanValue;
  1380. BEGIN
  1381. value := SyntaxTree.NewBooleanValue(position,b);
  1382. value.SetType(system.booleanType);
  1383. RETURN value
  1384. END NewBooleanValue;
  1385. PROCEDURE GetSetType*(system: System; this: Basic.Set): SyntaxTree.SetType;
  1386. BEGIN
  1387. IF this * {0 .. 7} = this THEN RETURN Set8
  1388. ELSIF this * { 0 .. 15 } = this THEN RETURN Set16
  1389. ELSIF this * { 0 .. 31 } = this THEN RETURN Set32
  1390. ELSE RETURN Set64
  1391. END
  1392. END GetSetType;
  1393. PROCEDURE NewSetValue*(system: System; position: Position; s: Basic.Set): SyntaxTree.Value;
  1394. VAR value: SyntaxTree.SetValue;
  1395. BEGIN
  1396. value := SyntaxTree.NewSetValue(position,s);
  1397. value.SetType(GetSetType(system,s));
  1398. RETURN value
  1399. END NewSetValue;
  1400. PROCEDURE NewCharacterValue*(system: System; position: Position; c: CHAR): SyntaxTree.Value;
  1401. VAR value: SyntaxTree.CharacterValue;
  1402. BEGIN
  1403. value := SyntaxTree.NewCharacterValue(position,c);
  1404. value.SetType(system.characterType);
  1405. RETURN value
  1406. END NewCharacterValue;
  1407. PROCEDURE NewNilValue*(system: System; position: Position): SyntaxTree.Value;
  1408. VAR value: SyntaxTree.NilValue;
  1409. BEGIN
  1410. value := SyntaxTree.NewNilValue(position);
  1411. value.SetType(system.anyType);
  1412. RETURN value
  1413. END NewNilValue;
  1414. (* distance for assignment to <- from *)
  1415. PROCEDURE BasicTypeDistance*(system: System; from, to: SyntaxTree.BasicType): LONGINT;
  1416. VAR fromSize, toSize, distance: LONGINT;
  1417. BEGIN
  1418. fromSize := system.SizeOf(from); toSize := system.SizeOf(to);
  1419. distance := -1;
  1420. IF (from IS SyntaxTree.IntegerType) & (to IS SyntaxTree.IntegerType) & (toSize >= fromSize) THEN
  1421. IF from(SyntaxTree.IntegerType).signed # to(SyntaxTree.IntegerType).signed THEN
  1422. IF (toSize=fromSize) & to(SyntaxTree.IntegerType).signed THEN
  1423. distance := MIN(LONGINT)
  1424. ELSE
  1425. INC(distance,2);
  1426. END;
  1427. END;
  1428. WHILE toSize >= fromSize DO
  1429. toSize := toSize DIV 2; INC(distance);
  1430. END;
  1431. ELSIF (from IS SyntaxTree.IntegerType) & (to IS SyntaxTree.SizeType) & (toSize >= fromSize) THEN
  1432. distance := 1;
  1433. WHILE toSize >= fromSize DO
  1434. toSize := toSize DIV 2; INC(distance);
  1435. END;
  1436. ELSIF (from IS SyntaxTree.SizeType) & (to IS SyntaxTree.IntegerType) & (toSize >= fromSize) THEN
  1437. distance := 1;
  1438. WHILE toSize >= fromSize DO
  1439. toSize := toSize DIV 2; INC(distance);
  1440. END;
  1441. ELSIF (from IS SyntaxTree.CharacterType) & (to IS SyntaxTree.CharacterType) & (toSize >= fromSize) OR
  1442. (from IS SyntaxTree.FloatType) & (to IS SyntaxTree.FloatType) & (toSize >= fromSize) OR
  1443. (from IS SyntaxTree.SetType) & (to IS SyntaxTree.SetType) & (toSize >= fromSize)
  1444. THEN
  1445. WHILE toSize >= fromSize DO
  1446. toSize := toSize DIV 2; INC(distance);
  1447. END;
  1448. ELSIF (from IS SyntaxTree.IntegerType) & (to IS SyntaxTree.FloatType) THEN
  1449. IF toSize = 64 THEN distance := 1 ELSE distance := 0 END;
  1450. toSize := 64;
  1451. WHILE toSize >= fromSize DO
  1452. toSize := toSize DIV 2; INC(distance);
  1453. END;
  1454. ELSIF (from IS SyntaxTree.SizeType) & (to IS SyntaxTree.FloatType) THEN
  1455. distance := 1;
  1456. WHILE toSize >= fromSize DO
  1457. toSize := toSize DIV 2; INC(distance);
  1458. END;
  1459. ELSIF (from IS SyntaxTree.RangeType) & (to IS SyntaxTree.RangeType) THEN
  1460. distance := 0;
  1461. ELSIF (from IS SyntaxTree.BooleanType) & (to IS SyntaxTree.BooleanType) THEN
  1462. distance := 0;
  1463. END;
  1464. IF distance < 0 THEN distance := MAX(LONGINT) END;
  1465. RETURN distance
  1466. END BasicTypeDistance;
  1467. PROCEDURE GetIdentifier*(symbol: LONGINT; case: LONGINT): SyntaxTree.Identifier;
  1468. BEGIN
  1469. IF (symbol >= 0) & (symbol < LEN(identifiers,1)) THEN
  1470. RETURN identifiers[case,symbol]
  1471. ELSE
  1472. RETURN SyntaxTree.invalidIdentifier
  1473. END;
  1474. END GetIdentifier;
  1475. PROCEDURE GetSymbol*(case: LONGINT; id: SyntaxTree.Identifier): LONGINT;
  1476. VAR i: LONGINT;
  1477. BEGIN
  1478. (*! quick and dirty implementation, optimize ! *)
  1479. FOR i := 0 TO LEN(identifiers,1)-1 DO
  1480. IF id=identifiers[case,i] THEN RETURN i END;
  1481. END;
  1482. RETURN -1
  1483. END GetSymbol;
  1484. PROCEDURE InitIdentifiers;
  1485. VAR i: LONGINT;
  1486. PROCEDURE NewKeywordIdentifier(op: LONGINT);
  1487. VAR id: Scanner.IdentifierType;
  1488. BEGIN
  1489. Scanner.GetKeyword(Scanner.Uppercase,op,id);
  1490. identifiers[Scanner.Uppercase,op] := id;
  1491. Scanner.GetKeyword(Scanner.Lowercase,op,id);
  1492. identifiers[Scanner.Lowercase,op] := id;
  1493. END NewKeywordIdentifier;
  1494. PROCEDURE NewBuiltinIdentifier(op: LONGINT; CONST name: ARRAY OF CHAR);
  1495. VAR nameL,nameU: Scanner.IdentifierString;
  1496. BEGIN
  1497. ASSERT(op < LEN(identifiers[0]));
  1498. Basic.Lowercase(name,nameL);
  1499. Basic.Uppercase(name,nameU);
  1500. identifiers[Scanner.Lowercase,op] := SyntaxTree.NewIdentifier(nameL);
  1501. identifiers[Scanner.Uppercase,op] := SyntaxTree.NewIdentifier(nameU);
  1502. END NewBuiltinIdentifier;
  1503. BEGIN
  1504. FOR i := 0 TO LEN(identifiers,1)-1 DO
  1505. identifiers[Scanner.Uppercase,i] := SyntaxTree.invalidIdentifier; identifiers[Scanner.Lowercase,i] := SyntaxTree.invalidIdentifier;
  1506. END;
  1507. FOR i := 0 TO Scanner.EndOfText-1 DO
  1508. NewKeywordIdentifier(i);
  1509. END;
  1510. NewBuiltinIdentifier(Abs,"ABS");
  1511. NewBuiltinIdentifier(Ash,"ASH");
  1512. NewBuiltinIdentifier(Asr,"ASR");
  1513. NewBuiltinIdentifier(Cap,"CAP");
  1514. NewBuiltinIdentifier(Chr,"CHR");
  1515. NewBuiltinIdentifier(Chr32,"CHR32");
  1516. NewBuiltinIdentifier(Entier,"ENTIER");
  1517. NewBuiltinIdentifier(EntierH,"ENTIERH");
  1518. NewBuiltinIdentifier(Len,"LEN");
  1519. NewBuiltinIdentifier(Long,"LONG");
  1520. NewBuiltinIdentifier(Lsh,"LSH");
  1521. NewBuiltinIdentifier(Max,"MAX");
  1522. NewBuiltinIdentifier(Min,"MIN");
  1523. NewBuiltinIdentifier(Odd,"ODD");
  1524. NewBuiltinIdentifier(Ord,"ORD");
  1525. NewBuiltinIdentifier(Ord32,"ORD32");
  1526. NewBuiltinIdentifier(Reshape,"RESHAPE");
  1527. NewBuiltinIdentifier(Ror,"ROR");
  1528. NewBuiltinIdentifier(Rot,"ROT");
  1529. NewBuiltinIdentifier(Short,"SHORT");
  1530. NewBuiltinIdentifier(Sum,"SUM");
  1531. NewBuiltinIdentifier(Dim,"DIM");
  1532. NewBuiltinIdentifier(Cas,"CAS");
  1533. NewBuiltinIdentifier(Dec,"DEC");
  1534. NewBuiltinIdentifier(Excl,"EXCL");
  1535. NewBuiltinIdentifier(Inc,"INC");
  1536. NewBuiltinIdentifier(Incl,"INCL");
  1537. NewBuiltinIdentifier(All,"ALL");
  1538. NewBuiltinIdentifier(Re,"RE");
  1539. NewBuiltinIdentifier(Im,"IM");
  1540. NewBuiltinIdentifier(IncMul,"INCMUL");
  1541. NewBuiltinIdentifier(DecMul,"DECMUL");
  1542. (* TODO: check if ok. The operators defined in FoxArrayBase require the following identifiers *)
  1543. (* TODO: ".*+" should preferably be added as a new token in the scanner *)
  1544. identifiers[Scanner.Lowercase, Scanner.Becomes] := SyntaxTree.NewIdentifier(":=");
  1545. identifiers[Scanner.Uppercase, Scanner.Becomes] := SyntaxTree.NewIdentifier(":=");
  1546. identifiers[Scanner.Lowercase, Scanner.Transpose] := SyntaxTree.NewIdentifier("`");
  1547. identifiers[Scanner.Uppercase, Scanner.Transpose] := SyntaxTree.NewIdentifier("`");
  1548. identifiers[Scanner.Lowercase, DotTimesPlus] := SyntaxTree.NewIdentifier(".*+");
  1549. identifiers[Scanner.Uppercase, DotTimesPlus] := SyntaxTree.NewIdentifier(".*+");
  1550. identifiers[Scanner.Lowercase, AtMulDec] := SyntaxTree.NewIdentifier("@MulDec");
  1551. identifiers[Scanner.Uppercase, AtMulDec] := SyntaxTree.NewIdentifier("@MulDec");
  1552. identifiers[Scanner.Lowercase, AtMulInc] := SyntaxTree.NewIdentifier("@MulInc");
  1553. identifiers[Scanner.Uppercase, AtMulInc] := SyntaxTree.NewIdentifier("@MulInc");
  1554. identifiers[Scanner.Lowercase,Conversion] := SyntaxTree.NewIdentifier("@Convert");
  1555. identifiers[Scanner.Uppercase,Conversion] := SyntaxTree.NewIdentifier("@Convert");
  1556. END InitIdentifiers;
  1557. (** initialize the global namespace *)
  1558. PROCEDURE Init;
  1559. BEGIN
  1560. InitIdentifiers;
  1561. (* names are not arbitrary, do not change unless you know what you do (compatibilty with paco!) *)
  1562. SystemName := SyntaxTree.NewIdentifier("SYSTEM");
  1563. systemName := SyntaxTree.NewIdentifier("system");
  1564. SelfParameterName := SyntaxTree.NewIdentifier("@Self");
  1565. ReturnParameterName := SyntaxTree.NewIdentifier("@ReturnParameter");
  1566. PointerReturnName := SyntaxTree.NewIdentifier("@PtrReturnType");
  1567. ResultName := SyntaxTree.NewIdentifier("RESULT");
  1568. A2Name := SyntaxTree.NewIdentifier("A2");
  1569. ArrayBaseName := SyntaxTree.NewIdentifier("FoxArrayBase");
  1570. ComplexNumbersName := SyntaxTree.NewIdentifier("ComplexNumbers");
  1571. RecordBodyName := SyntaxTree.NewIdentifier("@Body");
  1572. ModuleBodyName := SyntaxTree.NewIdentifier("@Body");
  1573. NameWinAPI := SyntaxTree.NewIdentifier(StringWinAPI);
  1574. NameC := SyntaxTree.NewIdentifier(StringC);
  1575. NamePlatformCC := SyntaxTree.NewIdentifier(StringPlatformCC);
  1576. NameMovable := SyntaxTree.NewIdentifier(StringMovable);
  1577. NameUntraced := SyntaxTree.NewIdentifier(StringUntraced);
  1578. NameDelegate := SyntaxTree.NewIdentifier(StringDelegate);
  1579. NameInterrupt := SyntaxTree.NewIdentifier(StringInterrupt);
  1580. NamePcOffset := SyntaxTree.NewIdentifier(StringPcOffset);
  1581. NameNoPAF := SyntaxTree.NewIdentifier(StringNoPAF);
  1582. NameEntry := SyntaxTree.NewIdentifier(StringEntry);
  1583. NameExit := SyntaxTree.NewIdentifier(StringExit);
  1584. NameFixed := SyntaxTree.NewIdentifier(StringFixed);
  1585. NameFictive := SyntaxTree.NewIdentifier(StringFictive);
  1586. NameAligned := SyntaxTree.NewIdentifier(StringAligned);
  1587. NameStackAligned := SyntaxTree.NewIdentifier(StringAlignStack);
  1588. NameExclusive := SyntaxTree.NewIdentifier(StringExclusive);
  1589. NameActive := SyntaxTree.NewIdentifier(StringActive);
  1590. NamePriority := SyntaxTree.NewIdentifier(StringPriority);
  1591. NameSafe := SyntaxTree.NewIdentifier(StringSafe);
  1592. NameRealtime := SyntaxTree.NewIdentifier(StringRealtime);
  1593. NameDynamic := SyntaxTree.NewIdentifier(StringDynamic);
  1594. NameDataMemorySize := SyntaxTree.NewIdentifier(StringDataMemorySize);
  1595. NameCodeMemorySize := SyntaxTree.NewIdentifier(StringCodeMemorySize);
  1596. NameChannelWidth := SyntaxTree.NewIdentifier(StringChannelWidth);
  1597. NameChannelDepth := SyntaxTree.NewIdentifier(StringChannelDepth);
  1598. NameChannelModule := SyntaxTree.NewIdentifier(StringChannelModule);
  1599. NameVector := SyntaxTree.NewIdentifier(StringVector);
  1600. NameFloatingPoint := SyntaxTree.NewIdentifier(StringFloatingPoint);
  1601. NameNoMul:= SyntaxTree.NewIdentifier(StringNoMul);
  1602. NameNonBlockingIO:=SyntaxTree.NewIdentifier(StringNonBlockingIO);
  1603. NameTRM := SyntaxTree.NewIdentifier(StringTRM);
  1604. NameTRMS := SyntaxTree.NewIdentifier(StringTRMS);
  1605. NameBackend := SyntaxTree.NewIdentifier(StringBackend);
  1606. NameRuntime := SyntaxTree.NewIdentifier(StringRuntime);
  1607. NameEngine := SyntaxTree.NewIdentifier(StringEngine);
  1608. NameFinal := SyntaxTree.NewIdentifier(StringFinal);
  1609. NameAbstract := SyntaxTree.NewIdentifier(StringAbstract);
  1610. NameFrequencyDivider := SyntaxTree.NewIdentifier(StringFrequencyDivider);
  1611. NameRegister := SyntaxTree.NewIdentifier(StringRegister);
  1612. NameNoReturn := SyntaxTree.NewIdentifier(StringNoReturn);
  1613. NamePlain := SyntaxTree.NewIdentifier(StringPlain);
  1614. NameUnsafe := SyntaxTree.NewIdentifier(StringUnsafe);
  1615. NameDisposable := SyntaxTree.NewIdentifier(StringDisposable);
  1616. NameUnchecked := SyntaxTree.NewIdentifier(StringUnchecked);
  1617. NameUncooperative := SyntaxTree.NewIdentifier(StringUncooperative);
  1618. NameFingerprint := SyntaxTree.NewIdentifier(StringFingerprint);
  1619. (* types *)
  1620. Boolean8 := SyntaxTree.NewBooleanType(8);
  1621. Boolean32 := SyntaxTree.NewBooleanType(32);
  1622. Integer8 := SyntaxTree.NewIntegerType(8, TRUE);
  1623. Integer16 := SyntaxTree.NewIntegerType(16, TRUE);
  1624. Integer32 := SyntaxTree.NewIntegerType(32, TRUE);
  1625. Integer64 := SyntaxTree.NewIntegerType(64, TRUE);
  1626. Unsigned8 := SyntaxTree.NewIntegerType(8, FALSE);
  1627. Unsigned16 := SyntaxTree.NewIntegerType(16, FALSE);
  1628. Unsigned32 := SyntaxTree.NewIntegerType(32, FALSE);
  1629. Unsigned64 := SyntaxTree.NewIntegerType(64, FALSE);
  1630. Float32 := SyntaxTree.NewFloatType(32);
  1631. Float64 := SyntaxTree.NewFloatType(64);
  1632. Complex64 := SyntaxTree.NewComplexType(Float32);
  1633. Complex128 := SyntaxTree.NewComplexType(Float64);
  1634. Byte8 := SyntaxTree.NewByteType(8);
  1635. Byte32 := SyntaxTree.NewByteType(32);
  1636. Character8 := SyntaxTree.NewCharacterType(8);
  1637. Character16 := SyntaxTree.NewCharacterType(16);
  1638. Character32 := SyntaxTree.NewCharacterType(32);
  1639. Set8 := SyntaxTree.NewSetType(8);
  1640. Set16 := SyntaxTree.NewSetType(16);
  1641. Set32 := SyntaxTree.NewSetType(32);
  1642. Set64 := SyntaxTree.NewSetType(64);
  1643. END Init;
  1644. BEGIN
  1645. Init;
  1646. END FoxGlobal.