psystem.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Load the system unit, create required defs for systemunit
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit psystem;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. symbase;
  23. procedure insertinternsyms(p : tsymtable);
  24. procedure insert_intern_types(p : tsymtable);
  25. procedure readconstdefs;
  26. procedure createconstdefs;
  27. implementation
  28. uses
  29. globals,
  30. symconst,symtype,symsym,symdef,symtable,
  31. ninl;
  32. procedure insertinternsyms(p : tsymtable);
  33. {
  34. all intern procedures for the system unit
  35. }
  36. begin
  37. p.insert(tsyssym.create('Concat',in_concat_x));
  38. p.insert(tsyssym.create('Write',in_write_x));
  39. p.insert(tsyssym.create('WriteLn',in_writeln_x));
  40. p.insert(tsyssym.create('Assigned',in_assigned_x));
  41. p.insert(tsyssym.create('Read',in_read_x));
  42. p.insert(tsyssym.create('ReadLn',in_readln_x));
  43. p.insert(tsyssym.create('Ofs',in_ofs_x));
  44. p.insert(tsyssym.create('SizeOf',in_sizeof_x));
  45. p.insert(tsyssym.create('TypeOf',in_typeof_x));
  46. p.insert(tsyssym.create('Low',in_low_x));
  47. p.insert(tsyssym.create('High',in_high_x));
  48. p.insert(tsyssym.create('Seg',in_seg_x));
  49. p.insert(tsyssym.create('Ord',in_ord_x));
  50. p.insert(tsyssym.create('Pred',in_pred_x));
  51. p.insert(tsyssym.create('Succ',in_succ_x));
  52. p.insert(tsyssym.create('Exclude',in_exclude_x_y));
  53. p.insert(tsyssym.create('Include',in_include_x_y));
  54. p.insert(tsyssym.create('Break',in_break));
  55. p.insert(tsyssym.create('Continue',in_continue));
  56. p.insert(tsyssym.create('Dec',in_dec_x));
  57. p.insert(tsyssym.create('Inc',in_inc_x));
  58. p.insert(tsyssym.create('Str',in_str_x_string));
  59. p.insert(tsyssym.create('Assert',in_assert_x_y));
  60. p.insert(tsyssym.create('Val',in_val_x));
  61. p.insert(tsyssym.create('Addr',in_addr_x));
  62. p.insert(tsyssym.create('TypeInfo',in_typeinfo_x));
  63. p.insert(tsyssym.create('SetLength',in_setlength_x));
  64. p.insert(tsyssym.create('Finalize',in_finalize_x));
  65. p.insert(tsyssym.create('Length',in_length_x));
  66. p.insert(tsyssym.create('New',in_new_x));
  67. p.insert(tsyssym.create('Dispose',in_dispose_x));
  68. end;
  69. procedure insert_intern_types(p : tsymtable);
  70. {
  71. all the types inserted into the system unit
  72. }
  73. function addtype(const s:string;const t:ttype):ttypesym;
  74. begin
  75. result:=ttypesym.create(s,t);
  76. p.insert(result);
  77. { add init/final table if required }
  78. if t.def.needs_inittable then
  79. generate_inittable(result);
  80. end;
  81. procedure adddef(const s:string;def:tdef);
  82. var
  83. t : ttype;
  84. begin
  85. t.setdef(def);
  86. p.insert(ttypesym.create(s,t));
  87. end;
  88. var
  89. { several defs to simulate more or less C++ objects for GDB }
  90. vmttype,
  91. vmtarraytype : ttype;
  92. vmtsymtable : tsymtable;
  93. begin
  94. { Normal types }
  95. addtype('Single',s32floattype);
  96. addtype('Double',s64floattype);
  97. addtype('Extended',s80floattype);
  98. addtype('Real',s64floattype);
  99. {$ifdef i386}
  100. adddef('Comp',tfloatdef.create(s64comp));
  101. addtype('Currency',s64currencytype);
  102. {$endif}
  103. addtype('Pointer',voidpointertype);
  104. addtype('FarPointer',voidfarpointertype);
  105. addtype('ShortString',cshortstringtype);
  106. addtype('LongString',clongstringtype);
  107. addtype('AnsiString',cansistringtype);
  108. addtype('WideString',cwidestringtype);
  109. addtype('Boolean',booltype);
  110. addtype('ByteBool',booltype);
  111. adddef('WordBool',torddef.create(bool16bit,0,1));
  112. adddef('LongBool',torddef.create(bool32bit,0,1));
  113. addtype('Char',cchartype);
  114. addtype('WideChar',cwidechartype);
  115. adddef('Text',tfiledef.createtext);
  116. addtype('Cardinal',u32bittype);
  117. addtype('QWord',cu64bittype);
  118. addtype('Int64',cs64bittype);
  119. adddef('TypedFile',tfiledef.createtyped(voidtype));
  120. addtype('Variant',cvarianttype);
  121. { Internal types }
  122. addtype('$formal',cformaltype);
  123. addtype('$void',voidtype);
  124. addtype('$byte',u8bittype);
  125. addtype('$word',u16bittype);
  126. addtype('$ulong',u32bittype);
  127. addtype('$longint',s32bittype);
  128. addtype('$qword',cu64bittype);
  129. addtype('$int64',cs64bittype);
  130. addtype('$char',cchartype);
  131. addtype('$widechar',cwidechartype);
  132. addtype('$shortstring',cshortstringtype);
  133. addtype('$longstring',clongstringtype);
  134. addtype('$ansistring',cansistringtype);
  135. addtype('$widestring',cwidestringtype);
  136. addtype('$openshortstring',openshortstringtype);
  137. addtype('$boolean',booltype);
  138. addtype('$void_pointer',voidpointertype);
  139. addtype('$char_pointer',charpointertype);
  140. addtype('$void_farpointer',voidfarpointertype);
  141. addtype('$openchararray',openchararraytype);
  142. addtype('$file',cfiletype);
  143. addtype('$variant',cvarianttype);
  144. addtype('$s32real',s32floattype);
  145. addtype('$s64real',s64floattype);
  146. addtype('$s80real',s80floattype);
  147. addtype('$s64currency',s64currencytype);
  148. { Add a type for virtual method tables }
  149. vmtsymtable:=trecordsymtable.create;
  150. vmttype.setdef(trecorddef.create(vmtsymtable));
  151. pvmttype.setdef(tpointerdef.create(vmttype));
  152. vmtsymtable.insert(tvarsym.create('$parent',pvmttype));
  153. vmtsymtable.insert(tvarsym.create('$length',s32bittype));
  154. vmtsymtable.insert(tvarsym.create('$mlength',s32bittype));
  155. vmtarraytype.setdef(tarraydef.create(0,1,s32bittype));
  156. tarraydef(vmtarraytype.def).elementtype:=voidpointertype;
  157. vmtsymtable.insert(tvarsym.create('$__pfn',vmtarraytype));
  158. addtype('$__vtbl_ptr_type',vmttype);
  159. addtype('$pvmt',pvmttype);
  160. vmtarraytype.setdef(tarraydef.create(0,1,s32bittype));
  161. tarraydef(vmtarraytype.def).elementtype:=pvmttype;
  162. addtype('$vtblarray',vmtarraytype);
  163. { Add functions that require compiler magic }
  164. insertinternsyms(p);
  165. end;
  166. procedure readconstdefs;
  167. {
  168. Load all default definitions for consts from the system unit
  169. }
  170. begin
  171. globaldef('byte',u8bittype);
  172. globaldef('word',u16bittype);
  173. globaldef('ulong',u32bittype);
  174. globaldef('longint',s32bittype);
  175. globaldef('qword',cu64bittype);
  176. globaldef('int64',cs64bittype);
  177. globaldef('formal',cformaltype);
  178. globaldef('void',voidtype);
  179. globaldef('char',cchartype);
  180. globaldef('widechar',cwidechartype);
  181. globaldef('shortstring',cshortstringtype);
  182. globaldef('longstring',clongstringtype);
  183. globaldef('ansistring',cansistringtype);
  184. globaldef('widestring',cwidestringtype);
  185. globaldef('openshortstring',openshortstringtype);
  186. globaldef('openchararray',openchararraytype);
  187. globaldef('s32real',s32floattype);
  188. globaldef('s64real',s64floattype);
  189. globaldef('s80real',s80floattype);
  190. globaldef('s64currency',s64currencytype);
  191. globaldef('boolean',booltype);
  192. globaldef('void_pointer',voidpointertype);
  193. globaldef('char_pointer',charpointertype);
  194. globaldef('void_farpointer',voidfarpointertype);
  195. globaldef('file',cfiletype);
  196. globaldef('pvmt',pvmttype);
  197. globaldef('variant',cvarianttype);
  198. end;
  199. procedure createconstdefs;
  200. {
  201. Create all default definitions for consts for the system unit
  202. }
  203. var
  204. oldregisterdef : boolean;
  205. begin
  206. { create definitions for constants }
  207. oldregisterdef:=registerdef;
  208. registerdef:=false;
  209. cformaltype.setdef(tformaldef.create);
  210. voidtype.setdef(torddef.create(uvoid,0,0));
  211. u8bittype.setdef(torddef.create(u8bit,0,255));
  212. u16bittype.setdef(torddef.create(u16bit,0,65535));
  213. u32bittype.setdef(torddef.create(u32bit,0,high(cardinal)));
  214. s32bittype.setdef(torddef.create(s32bit,low(longint),high(longint)));
  215. cu64bittype.setdef(torddef.create(u64bit,low(qword),TConstExprInt(high(qword))));
  216. cs64bittype.setdef(torddef.create(s64bit,low(int64),high(int64)));
  217. booltype.setdef(torddef.create(bool8bit,0,1));
  218. cchartype.setdef(torddef.create(uchar,0,255));
  219. cwidechartype.setdef(torddef.create(uwidechar,0,65535));
  220. cshortstringtype.setdef(tstringdef.createshort(255));
  221. { should we give a length to the default long and ansi string definition ?? }
  222. clongstringtype.setdef(tstringdef.createlong(-1));
  223. cansistringtype.setdef(tstringdef.createansi(-1));
  224. cwidestringtype.setdef(tstringdef.createwide(-1));
  225. { length=0 for shortstring is open string (needed for readln(string) }
  226. openshortstringtype.setdef(tstringdef.createshort(0));
  227. openchararraytype.setdef(tarraydef.create(0,-1,s32bittype));
  228. tarraydef(openchararraytype.def).elementtype:=cchartype;
  229. {$ifdef i386}
  230. s32floattype.setdef(tfloatdef.create(s32real));
  231. s64floattype.setdef(tfloatdef.create(s64real));
  232. s80floattype.setdef(tfloatdef.create(s80real));
  233. s64currencytype.setdef(tfloatdef.create(s64currency));
  234. {$endif}
  235. {$ifdef m68k}
  236. s32floattype.setdef(tfloatdef.create(s32real));
  237. if (cs_fp_emulation in aktmoduleswitches) then
  238. begin
  239. s64floattype.setdef(tfloatdef.create(s32real));
  240. s80floattype.setdef(tfloatdef.create(s32real)))
  241. end
  242. else
  243. begin
  244. s64floattype.setdef(tfloatdef.create(s64real));
  245. s80floattype.setdef(tfloatdef.create(s80real));
  246. end;
  247. {$endif}
  248. { some other definitions }
  249. voidpointertype.setdef(tpointerdef.create(voidtype));
  250. charpointertype.setdef(tpointerdef.create(cchartype));
  251. voidfarpointertype.setdef(tpointerdef.createfar(voidtype));
  252. cfiletype.setdef(tfiledef.createuntyped);
  253. cvarianttype.setdef(tvariantdef.create);
  254. registerdef:=oldregisterdef;
  255. end;
  256. end.
  257. {
  258. $Log$
  259. Revision 1.27 2002-07-01 16:23:54 peter
  260. * cg64 patch
  261. * basics for currency
  262. * asnode updates for class and interface (not finished)
  263. Revision 1.26 2002/05/18 13:34:16 peter
  264. * readded missing revisions
  265. Revision 1.25 2002/05/16 19:46:44 carl
  266. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  267. + try to fix temp allocation (still in ifdef)
  268. + generic constructor calls
  269. + start of tassembler / tmodulebase class cleanup
  270. Revision 1.23 2002/05/12 16:53:09 peter
  271. * moved entry and exitcode to ncgutil and cgobj
  272. * foreach gets extra argument for passing local data to the
  273. iterator function
  274. * -CR checks also class typecasts at runtime by changing them
  275. into as
  276. * fixed compiler to cycle with the -CR option
  277. * fixed stabs with elf writer, finally the global variables can
  278. be watched
  279. * removed a lot of routines from cga unit and replaced them by
  280. calls to cgobj
  281. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  282. u32bit then the other is typecasted also to u32bit without giving
  283. a rangecheck warning/error.
  284. * fixed pascal calling method with reversing also the high tree in
  285. the parast, detected by tcalcst3 test
  286. Revision 1.22 2002/01/24 12:33:53 jonas
  287. * adapted ranges of native types to int64 (e.g. high cardinal is no
  288. longer longint($ffffffff), but just $fffffff in psystem)
  289. * small additional fix in 64bit rangecheck code generation for 32 bit
  290. processors
  291. * adaption of ranges required the matching talgorithm used for selecting
  292. which overloaded procedure to call to be adapted. It should now always
  293. select the closest match for ordinal parameters.
  294. + inttostr(qword) in sysstr.inc/sysstrh.inc
  295. + abs(int64), sqr(int64), sqr(qword) in systemh.inc/generic.inc (previous
  296. fixes were required to be able to add them)
  297. * is_in_limit() moved from ncal to types unit, should always be used
  298. instead of direct comparisons of low/high values of orddefs because
  299. qword is a special case
  300. }