psystem.pas 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 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 defines.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. cpuinfo;
  33. procedure insertinternsyms(p : tsymtable);
  34. {
  35. all intern procedures for the system unit
  36. }
  37. begin
  38. p.insert(tsyssym.create('Concat',in_concat_x));
  39. p.insert(tsyssym.create('Write',in_write_x));
  40. p.insert(tsyssym.create('WriteLn',in_writeln_x));
  41. p.insert(tsyssym.create('Assigned',in_assigned_x));
  42. p.insert(tsyssym.create('Read',in_read_x));
  43. p.insert(tsyssym.create('ReadLn',in_readln_x));
  44. p.insert(tsyssym.create('Ofs',in_ofs_x));
  45. p.insert(tsyssym.create('SizeOf',in_sizeof_x));
  46. p.insert(tsyssym.create('TypeOf',in_typeof_x));
  47. p.insert(tsyssym.create('Low',in_low_x));
  48. p.insert(tsyssym.create('High',in_high_x));
  49. p.insert(tsyssym.create('Seg',in_seg_x));
  50. p.insert(tsyssym.create('Ord',in_ord_x));
  51. p.insert(tsyssym.create('Pred',in_pred_x));
  52. p.insert(tsyssym.create('Succ',in_succ_x));
  53. p.insert(tsyssym.create('Exclude',in_exclude_x_y));
  54. p.insert(tsyssym.create('Include',in_include_x_y));
  55. p.insert(tsyssym.create('Break',in_break));
  56. p.insert(tsyssym.create('Continue',in_continue));
  57. p.insert(tsyssym.create('Dec',in_dec_x));
  58. p.insert(tsyssym.create('Inc',in_inc_x));
  59. p.insert(tsyssym.create('Str',in_str_x_string));
  60. p.insert(tsyssym.create('Assert',in_assert_x_y));
  61. p.insert(tsyssym.create('Val',in_val_x));
  62. p.insert(tsyssym.create('Addr',in_addr_x));
  63. p.insert(tsyssym.create('TypeInfo',in_typeinfo_x));
  64. p.insert(tsyssym.create('SetLength',in_setlength_x));
  65. p.insert(tsyssym.create('Finalize',in_finalize_x));
  66. p.insert(tsyssym.create('Length',in_length_x));
  67. p.insert(tsyssym.create('New',in_new_x));
  68. p.insert(tsyssym.create('Dispose',in_dispose_x));
  69. end;
  70. procedure insert_intern_types(p : tsymtable);
  71. {
  72. all the types inserted into the system unit
  73. }
  74. function addtype(const s:string;const t:ttype):ttypesym;
  75. begin
  76. result:=ttypesym.create(s,t);
  77. p.insert(result);
  78. { add init/final table if required }
  79. if t.def.needs_inittable then
  80. generate_inittable(result);
  81. end;
  82. procedure adddef(const s:string;def:tdef);
  83. var
  84. t : ttype;
  85. begin
  86. t.setdef(def);
  87. p.insert(ttypesym.create(s,t));
  88. end;
  89. var
  90. { several defs to simulate more or less C++ objects for GDB }
  91. vmttype,
  92. vmtarraytype : ttype;
  93. vmtsymtable : tsymtable;
  94. begin
  95. { Normal types }
  96. addtype('Single',s32floattype);
  97. addtype('Double',s64floattype);
  98. addtype('Extended',s80floattype);
  99. addtype('Real',s64floattype);
  100. {$ifdef i386}
  101. adddef('Comp',tfloatdef.create(s64comp));
  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. { Add a type for virtual method tables }
  148. vmtsymtable:=trecordsymtable.create;
  149. vmttype.setdef(trecorddef.create(vmtsymtable));
  150. pvmttype.setdef(tpointerdef.create(vmttype));
  151. vmtsymtable.insert(tvarsym.create('$parent',pvmttype));
  152. vmtsymtable.insert(tvarsym.create('$length',s32bittype));
  153. vmtsymtable.insert(tvarsym.create('$mlength',s32bittype));
  154. vmtarraytype.setdef(tarraydef.create(0,1,s32bittype));
  155. tarraydef(vmtarraytype.def).elementtype:=voidpointertype;
  156. vmtsymtable.insert(tvarsym.create('$__pfn',vmtarraytype));
  157. addtype('$__vtbl_ptr_type',vmttype);
  158. addtype('$pvmt',pvmttype);
  159. vmtarraytype.setdef(tarraydef.create(0,1,s32bittype));
  160. tarraydef(vmtarraytype.def).elementtype:=pvmttype;
  161. addtype('$vtblarray',vmtarraytype);
  162. { Add functions that require compiler magic }
  163. insertinternsyms(p);
  164. end;
  165. procedure readconstdefs;
  166. {
  167. Load all default definitions for consts from the system unit
  168. }
  169. begin
  170. globaldef('byte',u8bittype);
  171. globaldef('word',u16bittype);
  172. globaldef('ulong',u32bittype);
  173. globaldef('longint',s32bittype);
  174. globaldef('qword',cu64bittype);
  175. globaldef('int64',cs64bittype);
  176. globaldef('formal',cformaltype);
  177. globaldef('void',voidtype);
  178. globaldef('char',cchartype);
  179. globaldef('widechar',cwidechartype);
  180. globaldef('shortstring',cshortstringtype);
  181. globaldef('longstring',clongstringtype);
  182. globaldef('ansistring',cansistringtype);
  183. globaldef('widestring',cwidestringtype);
  184. globaldef('openshortstring',openshortstringtype);
  185. globaldef('openchararray',openchararraytype);
  186. globaldef('s32real',s32floattype);
  187. globaldef('s64real',s64floattype);
  188. globaldef('s80real',s80floattype);
  189. globaldef('boolean',booltype);
  190. globaldef('void_pointer',voidpointertype);
  191. globaldef('char_pointer',charpointertype);
  192. globaldef('void_farpointer',voidfarpointertype);
  193. globaldef('file',cfiletype);
  194. globaldef('pvmt',pvmttype);
  195. globaldef('variant',cvarianttype);
  196. end;
  197. procedure createconstdefs;
  198. {
  199. Create all default definitions for consts for the system unit
  200. }
  201. var
  202. oldregisterdef : boolean;
  203. begin
  204. { create definitions for constants }
  205. oldregisterdef:=registerdef;
  206. registerdef:=false;
  207. cformaltype.setdef(tformaldef.create);
  208. voidtype.setdef(torddef.create(uvoid,0,0));
  209. u8bittype.setdef(torddef.create(u8bit,0,255));
  210. u16bittype.setdef(torddef.create(u16bit,0,65535));
  211. u32bittype.setdef(torddef.create(u32bit,0,high(cardinal)));
  212. s32bittype.setdef(torddef.create(s32bit,low(longint),high(longint)));
  213. cu64bittype.setdef(torddef.create(u64bit,low(qword),TConstExprInt(high(qword))));
  214. cs64bittype.setdef(torddef.create(s64bit,low(int64),high(int64)));
  215. booltype.setdef(torddef.create(bool8bit,0,1));
  216. cchartype.setdef(torddef.create(uchar,0,255));
  217. cwidechartype.setdef(torddef.create(uwidechar,0,65535));
  218. cshortstringtype.setdef(tstringdef.createshort(255));
  219. { should we give a length to the default long and ansi string definition ?? }
  220. clongstringtype.setdef(tstringdef.createlong(-1));
  221. cansistringtype.setdef(tstringdef.createansi(-1));
  222. cwidestringtype.setdef(tstringdef.createwide(-1));
  223. { length=0 for shortstring is open string (needed for readln(string) }
  224. openshortstringtype.setdef(tstringdef.createshort(0));
  225. openchararraytype.setdef(tarraydef.create(0,-1,s32bittype));
  226. tarraydef(openchararraytype.def).elementtype:=cchartype;
  227. {$ifdef i386}
  228. s32floattype.setdef(tfloatdef.create(s32real));
  229. s64floattype.setdef(tfloatdef.create(s64real));
  230. s80floattype.setdef(tfloatdef.create(s80real));
  231. {$endif}
  232. {$ifdef m68k}
  233. s32floattype.setdef(tfloatdef.create(s32real));
  234. if (cs_fp_emulation in aktmoduleswitches) then
  235. begin
  236. s64floattype.setdef(tfloatdef.create(s32real));
  237. s80floattype.setdef(tfloatdef.create(s32real)))
  238. end
  239. else
  240. begin
  241. s64floattype.setdef(tfloatdef.create(s64real));
  242. s80floattype.setdef(tfloatdef.create(s80real));
  243. end;
  244. {$endif}
  245. { some other definitions }
  246. voidpointertype.setdef(tpointerdef.create(voidtype));
  247. charpointertype.setdef(tpointerdef.create(cchartype));
  248. voidfarpointertype.setdef(tpointerdef.createfar(voidtype));
  249. cfiletype.setdef(tfiledef.createuntyped);
  250. cvarianttype.setdef(tvariantdef.create);
  251. registerdef:=oldregisterdef;
  252. end;
  253. end.
  254. {
  255. $Log$
  256. Revision 1.22 2002-01-24 12:33:53 jonas
  257. * adapted ranges of native types to int64 (e.g. high cardinal is no
  258. longer longint($ffffffff), but just $fffffff in psystem)
  259. * small additional fix in 64bit rangecheck code generation for 32 bit
  260. processors
  261. * adaption of ranges required the matching talgorithm used for selecting
  262. which overloaded procedure to call to be adapted. It should now always
  263. select the closest match for ordinal parameters.
  264. + inttostr(qword) in sysstr.inc/sysstrh.inc
  265. + abs(int64), sqr(int64), sqr(qword) in systemh.inc/generic.inc (previous
  266. fixes were required to be able to add them)
  267. * is_in_limit() moved from ncal to types unit, should always be used
  268. instead of direct comparisons of low/high values of orddefs because
  269. qword is a special case
  270. Revision 1.21 2001/11/18 18:43:14 peter
  271. * overloading supported in child classes
  272. * fixed parsing of classes with private and virtual and overloaded
  273. so it is compatible with delphi
  274. Revision 1.20 2001/10/24 11:51:39 marco
  275. * Make new/dispose system functions instead of keywords
  276. Revision 1.19 2001/08/30 20:13:53 peter
  277. * rtti/init table updates
  278. * rttisym for reusable global rtti/init info
  279. * support published for interfaces
  280. Revision 1.18 2001/07/30 20:59:27 peter
  281. * m68k updates from v10 merged
  282. Revision 1.17 2001/07/09 21:15:41 peter
  283. * Length made internal
  284. * Add array support for Length
  285. Revision 1.16 2001/05/09 19:58:45 peter
  286. * m68k doesn't support double (merged)
  287. Revision 1.15 2001/04/13 01:22:13 peter
  288. * symtable change to classes
  289. * range check generation and errors fixed, make cycle DEBUG=1 works
  290. * memory leaks fixed
  291. Revision 1.14 2001/04/02 21:20:34 peter
  292. * resulttype rewrite
  293. Revision 1.13 2001/03/25 12:40:00 florian
  294. * cwidechar was loaded with a chardef, fixed
  295. Revision 1.12 2001/03/22 00:10:58 florian
  296. + basic variant type support in the compiler
  297. Revision 1.11 2000/12/07 17:19:43 jonas
  298. * new constant handling: from now on, hex constants >$7fffffff are
  299. parsed as unsigned constants (otherwise, $80000000 got sign extended
  300. and became $ffffffff80000000), all constants in the longint range
  301. become longints, all constants >$7fffffff and <=cardinal($ffffffff)
  302. are cardinals and the rest are int64's.
  303. * added lots of longint typecast to prevent range check errors in the
  304. compiler and rtl
  305. * type casts of symbolic ordinal constants are now preserved
  306. * fixed bug where the original resulttype.def wasn't restored correctly
  307. after doing a 64bit rangecheck
  308. Revision 1.10 2000/11/29 00:30:38 florian
  309. * unused units removed from uses clause
  310. * some changes for widestrings
  311. Revision 1.9 2000/11/09 17:46:56 florian
  312. * System.TypeInfo fixed
  313. + System.Finalize implemented
  314. + some new keywords for interface support added
  315. Revision 1.8 2000/10/31 22:02:51 peter
  316. * symtable splitted, no real code changes
  317. Revision 1.7 2000/10/21 18:16:12 florian
  318. * a lot of changes:
  319. - basic dyn. array support
  320. - basic C++ support
  321. - some work for interfaces done
  322. ....
  323. Revision 1.6 2000/10/14 10:14:52 peter
  324. * moehrendorf oct 2000 rewrite
  325. Revision 1.5 2000/09/24 15:06:24 peter
  326. * use defines.inc
  327. Revision 1.4 2000/08/27 20:19:39 peter
  328. * store strings with case in ppu, when an internal symbol is created
  329. a '$' is prefixed so it's not automatic uppercased
  330. Revision 1.3 2000/08/16 13:06:06 florian
  331. + support of 64 bit integer constants
  332. Revision 1.2 2000/07/13 11:32:47 michael
  333. + removed logs
  334. }