psystem.pas 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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 : psymtable);
  24. procedure insert_intern_types(p : psymtable);
  25. procedure readconstdefs;
  26. procedure createconstdefs;
  27. implementation
  28. uses
  29. globals,
  30. symconst,symtype,symsym,symdef,symtable,
  31. ninl;
  32. procedure insertinternsyms(p : psymtable);
  33. {
  34. all intern procedures for the system unit
  35. }
  36. begin
  37. p^.insert(new(psyssym,init('Concat',in_concat_x)));
  38. p^.insert(new(psyssym,init('Write',in_write_x)));
  39. p^.insert(new(psyssym,init('WriteLn',in_writeln_x)));
  40. p^.insert(new(psyssym,init('Assigned',in_assigned_x)));
  41. p^.insert(new(psyssym,init('Read',in_read_x)));
  42. p^.insert(new(psyssym,init('ReadLn',in_readln_x)));
  43. p^.insert(new(psyssym,init('Ofs',in_ofs_x)));
  44. p^.insert(new(psyssym,init('SizeOf',in_sizeof_x)));
  45. p^.insert(new(psyssym,init('TypeOf',in_typeof_x)));
  46. p^.insert(new(psyssym,init('Low',in_low_x)));
  47. p^.insert(new(psyssym,init('High',in_high_x)));
  48. p^.insert(new(psyssym,init('Seg',in_seg_x)));
  49. p^.insert(new(psyssym,init('Ord',in_ord_x)));
  50. p^.insert(new(psyssym,init('Pred',in_pred_x)));
  51. p^.insert(new(psyssym,init('Succ',in_succ_x)));
  52. p^.insert(new(psyssym,init('Exclude',in_exclude_x_y)));
  53. p^.insert(new(psyssym,init('Include',in_include_x_y)));
  54. p^.insert(new(psyssym,init('Break',in_break)));
  55. p^.insert(new(psyssym,init('Continue',in_continue)));
  56. p^.insert(new(psyssym,init('Dec',in_dec_x)));
  57. p^.insert(new(psyssym,init('Inc',in_inc_x)));
  58. p^.insert(new(psyssym,init('Str',in_str_x_string)));
  59. p^.insert(new(psyssym,init('Assert',in_assert_x_y)));
  60. p^.insert(new(psyssym,init('Val',in_val_x)));
  61. p^.insert(new(psyssym,init('Addr',in_addr_x)));
  62. p^.insert(new(psyssym,init('TypeInfo',in_typeinfo_x)));
  63. p^.insert(new(psyssym,init('SetLength',in_setlength_x)));
  64. p^.insert(new(psyssym,init('Finalize',in_finalize_x)));
  65. end;
  66. procedure insert_intern_types(p : psymtable);
  67. {
  68. all the types inserted into the system unit
  69. }
  70. procedure addtype(const s:string;const t:ttype);
  71. begin
  72. p^.insert(new(ptypesym,init(s,t)));
  73. end;
  74. procedure adddef(const s:string;def:pdef);
  75. var
  76. t : ttype;
  77. begin
  78. t.setdef(def);
  79. p^.insert(new(ptypesym,init(s,t)));
  80. end;
  81. var
  82. { several defs to simulate more or less C++ objects for GDB }
  83. vmttype,
  84. vmtarraytype : ttype;
  85. vmtsymtable : psymtable;
  86. begin
  87. { Internal types }
  88. addtype('$formal',cformaltype);
  89. addtype('$void',voidtype);
  90. addtype('$byte',u8bittype);
  91. addtype('$word',u16bittype);
  92. addtype('$ulong',u32bittype);
  93. addtype('$longint',s32bittype);
  94. addtype('$qword',cu64bittype);
  95. addtype('$int64',cs64bittype);
  96. addtype('$char',cchartype);
  97. addtype('$widechar',cwidechartype);
  98. addtype('$shortstring',cshortstringtype);
  99. addtype('$longstring',clongstringtype);
  100. addtype('$ansistring',cansistringtype);
  101. addtype('$widestring',cwidestringtype);
  102. addtype('$openshortstring',openshortstringtype);
  103. addtype('$boolean',booltype);
  104. addtype('$void_pointer',voidpointertype);
  105. addtype('$char_pointer',charpointertype);
  106. addtype('$void_farpointer',voidfarpointertype);
  107. addtype('$openchararray',openchararraytype);
  108. addtype('$file',cfiletype);
  109. addtype('$variant',cvarianttype);
  110. addtype('$s32real',s32floattype);
  111. addtype('$s64real',s64floattype);
  112. addtype('$s80real',s80floattype);
  113. { Add a type for virtual method tables in lowercase }
  114. { so it isn't reachable! }
  115. vmtsymtable:=new(pstoredsymtable,init(recordsymtable));
  116. vmttype.setdef(new(precorddef,init(vmtsymtable)));
  117. pvmttype.setdef(new(ppointerdef,init(vmttype)));
  118. vmtsymtable^.insert(new(pvarsym,init('$parent',pvmttype)));
  119. vmtsymtable^.insert(new(pvarsym,init('$length',s32bittype)));
  120. vmtsymtable^.insert(new(pvarsym,init('$mlength',s32bittype)));
  121. vmtarraytype.setdef(new(parraydef,init(0,1,s32bittype)));
  122. parraydef(vmtarraytype.def)^.elementtype:=voidpointertype;
  123. vmtsymtable^.insert(new(pvarsym,init('$__pfn',vmtarraytype)));
  124. addtype('$__vtbl_ptr_type',vmttype);
  125. addtype('$pvmt',pvmttype);
  126. vmtarraytype.setdef(new(parraydef,init(0,1,s32bittype)));
  127. parraydef(vmtarraytype.def)^.elementtype:=pvmttype;
  128. addtype('$vtblarray',vmtarraytype);
  129. { Add functions that require compiler magic }
  130. insertinternsyms(p);
  131. { Normal types }
  132. addtype('Single',s32floattype);
  133. addtype('Double',s64floattype);
  134. addtype('Extended',s80floattype);
  135. addtype('Real',s64floattype);
  136. {$ifdef i386}
  137. adddef('Comp',new(pfloatdef,init(s64comp)));
  138. {$endif}
  139. addtype('Pointer',voidpointertype);
  140. addtype('FarPointer',voidfarpointertype);
  141. addtype('ShortString',cshortstringtype);
  142. addtype('LongString',clongstringtype);
  143. addtype('AnsiString',cansistringtype);
  144. addtype('WideString',cwidestringtype);
  145. addtype('Boolean',booltype);
  146. addtype('ByteBool',booltype);
  147. adddef('WordBool',new(porddef,init(bool16bit,0,1)));
  148. adddef('LongBool',new(porddef,init(bool32bit,0,1)));
  149. addtype('Char',cchartype);
  150. addtype('WideChar',cwidechartype);
  151. adddef('Text',new(pfiledef,inittext));
  152. addtype('Cardinal',u32bittype);
  153. addtype('QWord',cu64bittype);
  154. addtype('Int64',cs64bittype);
  155. adddef('TypedFile',new(pfiledef,inittyped(voidtype)));
  156. addtype('Variant',cvarianttype);
  157. end;
  158. procedure readconstdefs;
  159. {
  160. Load all default definitions for consts from the system unit
  161. }
  162. begin
  163. globaldef('byte',u8bittype);
  164. globaldef('word',u16bittype);
  165. globaldef('ulong',u32bittype);
  166. globaldef('longint',s32bittype);
  167. globaldef('qword',cu64bittype);
  168. globaldef('int64',cs64bittype);
  169. globaldef('formal',cformaltype);
  170. globaldef('void',voidtype);
  171. globaldef('char',cchartype);
  172. globaldef('widechar',cwidechartype);
  173. globaldef('shortstring',cshortstringtype);
  174. globaldef('longstring',clongstringtype);
  175. globaldef('ansistring',cansistringtype);
  176. globaldef('widestring',cwidestringtype);
  177. globaldef('openshortstring',openshortstringtype);
  178. globaldef('openchararray',openchararraytype);
  179. globaldef('s32real',s32floattype);
  180. globaldef('s64real',s64floattype);
  181. globaldef('s80real',s80floattype);
  182. globaldef('boolean',booltype);
  183. globaldef('void_pointer',voidpointertype);
  184. globaldef('char_pointer',charpointertype);
  185. globaldef('void_farpointer',voidfarpointertype);
  186. globaldef('file',cfiletype);
  187. globaldef('pvmt',pvmttype);
  188. globaldef('variant',cvarianttype);
  189. end;
  190. procedure createconstdefs;
  191. {
  192. Create all default definitions for consts for the system unit
  193. }
  194. var
  195. oldregisterdef : boolean;
  196. begin
  197. { create definitions for constants }
  198. oldregisterdef:=registerdef;
  199. registerdef:=false;
  200. cformaltype.setdef(new(pformaldef,init));
  201. voidtype.setdef(new(porddef,init(uvoid,0,0)));
  202. u8bittype.setdef(new(porddef,init(u8bit,0,255)));
  203. u16bittype.setdef(new(porddef,init(u16bit,0,65535)));
  204. u32bittype.setdef(new(porddef,init(u32bit,0,longint($ffffffff))));
  205. s32bittype.setdef(new(porddef,init(s32bit,longint($80000000),$7fffffff)));
  206. cu64bittype.setdef(new(porddef,init(u64bit,0,0)));
  207. cs64bittype.setdef(new(porddef,init(s64bit,0,0)));
  208. booltype.setdef(new(porddef,init(bool8bit,0,1)));
  209. cchartype.setdef(new(porddef,init(uchar,0,255)));
  210. cwidechartype.setdef(new(porddef,init(uwidechar,0,65535)));
  211. cshortstringtype.setdef(new(pstringdef,shortinit(255)));
  212. { should we give a length to the default long and ansi string definition ?? }
  213. clongstringtype.setdef(new(pstringdef,longinit(-1)));
  214. cansistringtype.setdef(new(pstringdef,ansiinit(-1)));
  215. cwidestringtype.setdef(new(pstringdef,wideinit(-1)));
  216. { length=0 for shortstring is open string (needed for readln(string) }
  217. openshortstringtype.setdef(new(pstringdef,shortinit(0)));
  218. openchararraytype.setdef(new(parraydef,init(0,-1,s32bittype)));
  219. parraydef(openchararraytype.def)^.elementtype:=cchartype;
  220. {$ifdef i386}
  221. s32floattype.setdef(new(pfloatdef,init(s32real)));
  222. s64floattype.setdef(new(pfloatdef,init(s64real)));
  223. s80floattype.setdef(new(pfloatdef,init(s80real)));
  224. {$endif}
  225. {$ifdef m68k}
  226. s32floattype.setdef(new(pfloatdef,init(s32real)));
  227. s64floattype.setdef(new(pfloatdef,init(s64real)));
  228. if (cs_fp_emulation in aktmoduleswitches) then
  229. s80floattype.setdef(new(pfloatdef,init(s32real)))
  230. else
  231. s80floattype.setdef(new(pfloatdef,init(s80real)));
  232. {$endif}
  233. { some other definitions }
  234. voidpointertype.setdef(new(ppointerdef,init(voidtype)));
  235. charpointertype.setdef(new(ppointerdef,init(cchartype)));
  236. voidfarpointertype.setdef(new(ppointerdef,initfar(voidtype)));
  237. cfiletype.setdef(new(pfiledef,inituntyped));
  238. cvarianttype.setdef(new(pvariantdef,init));
  239. registerdef:=oldregisterdef;
  240. end;
  241. end.
  242. {
  243. $Log$
  244. Revision 1.14 2001-04-02 21:20:34 peter
  245. * resulttype rewrite
  246. Revision 1.13 2001/03/25 12:40:00 florian
  247. * cwidechar was loaded with a chardef, fixed
  248. Revision 1.12 2001/03/22 00:10:58 florian
  249. + basic variant type support in the compiler
  250. Revision 1.11 2000/12/07 17:19:43 jonas
  251. * new constant handling: from now on, hex constants >$7fffffff are
  252. parsed as unsigned constants (otherwise, $80000000 got sign extended
  253. and became $ffffffff80000000), all constants in the longint range
  254. become longints, all constants >$7fffffff and <=cardinal($ffffffff)
  255. are cardinals and the rest are int64's.
  256. * added lots of longint typecast to prevent range check errors in the
  257. compiler and rtl
  258. * type casts of symbolic ordinal constants are now preserved
  259. * fixed bug where the original resulttype.def wasn't restored correctly
  260. after doing a 64bit rangecheck
  261. Revision 1.10 2000/11/29 00:30:38 florian
  262. * unused units removed from uses clause
  263. * some changes for widestrings
  264. Revision 1.9 2000/11/09 17:46:56 florian
  265. * System.TypeInfo fixed
  266. + System.Finalize implemented
  267. + some new keywords for interface support added
  268. Revision 1.8 2000/10/31 22:02:51 peter
  269. * symtable splitted, no real code changes
  270. Revision 1.7 2000/10/21 18:16:12 florian
  271. * a lot of changes:
  272. - basic dyn. array support
  273. - basic C++ support
  274. - some work for interfaces done
  275. ....
  276. Revision 1.6 2000/10/14 10:14:52 peter
  277. * moehrendorf oct 2000 rewrite
  278. Revision 1.5 2000/09/24 15:06:24 peter
  279. * use defines.inc
  280. Revision 1.4 2000/08/27 20:19:39 peter
  281. * store strings with case in ppu, when an internal symbol is created
  282. a '$' is prefixed so it's not automatic uppercased
  283. Revision 1.3 2000/08/16 13:06:06 florian
  284. + support of 64 bit integer constants
  285. Revision 1.2 2000/07/13 11:32:47 michael
  286. + removed logs
  287. }