generic.inc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team.
  5. Processor independent implementation for the system unit
  6. (adapted for intel i386.inc file)
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  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.
  12. **********************************************************************}
  13. {****************************************************************************
  14. Primitives
  15. ****************************************************************************}
  16. {$ifndef FPC_SYSTEM_HAS_MOVE}
  17. procedure Move(const source;var dest;count:longint);
  18. type
  19. longintarray = array [0..maxlongint] of longint;
  20. bytearray = array [0..maxlongint] of byte;
  21. var
  22. i,size : longint;
  23. begin
  24. size:=count div sizeof(longint);
  25. if (@dest)<@source) or
  26. (@dest>@source+count) then
  27. begin
  28. for i:=0 to size-1 do
  29. longintarray(dest)[i]:=longintarray(source)[i];
  30. for i:=size*sizeof(longint) to count-1 do
  31. bytearray(dest)[i]:=bytearray(source)[i];
  32. end
  33. else
  34. begin
  35. for i:=count-1 downto size*sizeof(longint) do
  36. bytearray(dest)[i]:=bytearray(source)[i];
  37. for i:=size-1 downto 0 do
  38. longintarray(dest)[i]:=longintarray(source)[i];
  39. end;
  40. end;
  41. {$endif ndef FPC_SYSTEM_HAS_MOVE}
  42. {$ifndef FPC_SYSTEM_HAS_FILLCHAR}
  43. Procedure FillChar(var x;count:longint;value:byte);
  44. type
  45. longintarray = array [0..maxlongint] of longint;
  46. bytearray = array [0..maxlongint] of byte;
  47. var
  48. i,v : longint;
  49. begin
  50. v:=value*256+value;
  51. v:=v*$10000+v;
  52. for i:=0 to (count div 4) -1 do
  53. longintarray(x)[i]:=v;
  54. for i:=(count div 4)*4 to count-1 do
  55. bytearray(x)[i]:=value;
  56. end;
  57. {$endif ndef FPC_SYSTEM_HAS_FILLCHAR}
  58. {$ifndef FPC_SYSTEM_HAS_FILLBYTE}
  59. procedure FillByte (var x;count : longint;value : byte );
  60. begin
  61. FillChar (X,Count,CHR(VALUE));
  62. end;
  63. {$endif ndef FPC_SYSTEM_HAS_FILLBYTE}
  64. {$ifndef FPC_SYSTEM_HAS_FILLWORD}
  65. procedure fillword(var x;count : longint;value : word);
  66. type
  67. longintarray = array [0..maxlongint] of longint;
  68. wordarray = array [0..maxlongint] of word;
  69. var
  70. i,v : longint;
  71. begin
  72. v:=value*$10000+value;
  73. for i:=0 to (count div 2) -1 do
  74. longintarray(x)[i]:=v;
  75. for i:=(count div 2)*2 to count-1 do
  76. wordarray(x)[i]:=value;
  77. end;
  78. {$endif ndef FPC_SYSTEM_HAS_FILLWORD}
  79. {$ifndef FPC_SYSTEM_HAS_FILLDWORD}
  80. procedure FillDWord(var x;count : longint;value : DWord);
  81. var
  82. I : longint;
  83. begin
  84. if Count<>0 then
  85. begin
  86. I:=Count;
  87. while I<>0 do
  88. begin
  89. PDWord(@X)[I-1]:=Value;
  90. Dec(I);
  91. end;
  92. end;
  93. end;
  94. {$endif ndef FPC_SYSTEM_HAS_FILLDWORD}
  95. {$ifndef FPC_SYSTEM_HAS_INDEXCHAR}
  96. function IndexChar(var buf;len:longint;b:char):longint;
  97. begin
  98. IndexChar:=IndexByte(Buf,Len,byte(B));
  99. end;
  100. {$endif ndef FPC_SYSTEM_HAS_INDEXCHAR}
  101. {$ifndef FPC_SYSTEM_HAS_INDEXBYTE}
  102. function IndexByte(var buf;len:longint;b:byte):longint;
  103. var
  104. I : longint;
  105. begin
  106. I:=0;
  107. while (pbyte(@buf)[I]<>b) and (I<Len) do
  108. inc(I);
  109. if (i=Len) then
  110. i:=-1; {Can't use 0, since it is a possible value}
  111. IndexByte:=I;
  112. end;
  113. {$endif ndef FPC_SYSTEM_HAS_INDEXBYTE}
  114. {$ifndef FPC_SYSTEM_HAS_INDEXWORD}
  115. function Indexword(var buf;len:longint;b:word):longint;
  116. var
  117. I : longint;
  118. begin
  119. I:=0;
  120. while (pword(@buf)[I]<>b) and (I<Len) do
  121. inc(I);
  122. if (i=Len) then
  123. i:=-1; {Can't use 0, since it is a possible value for index}
  124. Indexword:=I;
  125. end;
  126. {$endif ndef FPC_SYSTEM_HAS_INDEXWORD}
  127. {$ifndef FPC_SYSTEM_HAS_INDEXDWORD}
  128. function IndexDWord(var buf;len:longint;b:DWord):longint;
  129. var
  130. I : longint;
  131. begin
  132. I:=0;
  133. while (PDWord(@buf)[I]<>b) and (I<Len) do inc(I);
  134. if (i=Len) then
  135. i:=-1; {Can't use 0, since it is a possible value for index}
  136. IndexDWord:=I;
  137. end;
  138. {$endif ndef FPC_SYSTEM_HAS_INDEXDWORD}
  139. {$ifndef FPC_SYSTEM_HAS_COMPARECHAR}
  140. function CompareChar(var buf1,buf2;len:longint):longint;
  141. begin
  142. CompareChar:=CompareByte(buf1,buf2,len);
  143. end;
  144. {$endif ndef FPC_SYSTEM_HAS_COMPARECHAR}
  145. {$ifndef FPC_SYSTEM_HAS_COMPAREBYTE}
  146. function CompareByte(var buf1,buf2;len:longint):longint;
  147. var
  148. I,J : longint;
  149. begin
  150. I:=0;
  151. if (Len<>0) and (@Buf1<>@Buf2) then
  152. begin
  153. while (pbyte(@Buf1)[I]=pbyte(@Buf2)[I]) and (I<Len) do
  154. inc(I);
  155. if I=Len then {No difference}
  156. I:=0
  157. else
  158. begin
  159. I:=pbyte(@Buf1)[I]-pbyte(@Buf2)[I];
  160. if I>0 then
  161. I:=1
  162. else
  163. if I<0 then
  164. I:=-1;
  165. end;
  166. end;
  167. CompareByte:=I;
  168. end;
  169. {$endif ndef FPC_SYSTEM_HAS_COMPAREBYTE}
  170. {$ifndef FPC_SYSTEM_HAS_COMPAREWORD}
  171. function CompareWord(var buf1,buf2;len:longint):longint;
  172. var
  173. I,J : longint;
  174. begin
  175. I:=0;
  176. if (Len<>0) and (@Buf1<>@Buf2) then
  177. begin
  178. while (pword(@Buf1)[I]=pword(@Buf2)[I]) and (I<Len) do
  179. inc(I);
  180. if I=Len then {No difference}
  181. I:=0
  182. else
  183. begin
  184. I:=pword(@Buf1)[I]-pword(@Buf2)[I];
  185. if I>0 then
  186. I:=1
  187. else
  188. if I<0 then
  189. I:=-1;
  190. end;
  191. end;
  192. CompareWord:=I;
  193. end;
  194. {$endif ndef FPC_SYSTEM_HAS_COMPAREWORD}
  195. {$ifndef FPC_SYSTEM_HAS_COMPAREDWORD}
  196. function CompareDWord(var buf1,buf2;len:longint):longint;
  197. var
  198. I,J : longint;
  199. begin
  200. I:=0;
  201. if (Len<>0) and (@Buf1<>@Buf2) then
  202. begin
  203. while (PDWord(@Buf1)[I]=PDWord(@Buf2)[I]) and (I<Len) do
  204. inc(I);
  205. if I=Len then {No difference}
  206. I:=0
  207. else
  208. begin
  209. I:=PDWord(@Buf1)[I]-PDWord(@Buf2)[I];
  210. if I>0 then
  211. I:=1
  212. else
  213. if I<0 then
  214. I:=-1;
  215. end;
  216. end;
  217. CompareDWord:=I;
  218. end;
  219. {$endif ndef FPC_SYSTEM_HAS_COMPAREDWORD}
  220. {$ifndef FPC_SYSTEM_HAS_MOVECHAR0}
  221. procedure MoveChar0(var buf1,buf2;len:longint);
  222. var
  223. I : longint;
  224. begin
  225. if Len<> 0 then
  226. begin
  227. I:=IndexByte(Buf1,Len,0);
  228. if I<>0 then
  229. Move(Buf1,Buf2,I);
  230. end;
  231. end;
  232. {$endif ndef FPC_SYSTEM_HAS_MOVECHAR0}
  233. {$ifndef FPC_SYSTEM_HAS_INDEXCHAR0}
  234. function IndexChar0(var buf;len:longint;b:Char):longint;
  235. var
  236. I : longint;
  237. begin
  238. if Len<>0 then
  239. begin
  240. I:=IndexByte(Buf,Len,0);
  241. IndexChar0:=IndexByte(Buf,I,0);
  242. end
  243. else
  244. IndexChar0:=0;
  245. end;
  246. {$endif ndef FPC_SYSTEM_HAS_INDEXCHAR0}
  247. {$ifndef FPC_SYSTEM_HAS_COMPARECHAR0}
  248. function CompareChar0(var buf1,buf2;len:longint):longint;
  249. Var i : longint;
  250. begin
  251. I:=0;
  252. if (Len<>0) and (@Buf1<>@Buf2) then
  253. begin
  254. while (I<Len) And
  255. ((Pbyte(@Buf1)[i]<>0) and (PByte(@buf2)[i]<>0)) and
  256. (pbyte(@Buf1)[I]=pbyte(@Buf2)[I]) do
  257. inc(I);
  258. if (I=Len) or
  259. (PByte(@Buf1)[i]=0) or
  260. (PByte(@buf2)[I]=0) then {No difference or 0 reached }
  261. I:=0
  262. else
  263. begin
  264. I:=pbyte(@Buf1)[I]-pbyte(@Buf2)[I];
  265. if I>0 then
  266. I:=1
  267. else
  268. if I<0 then
  269. I:=-1;
  270. end;
  271. end;
  272. CompareChar0:=I;
  273. end;
  274. {$endif ndef FPC_SYSTEM_HAS_COMPARECHAR0}
  275. {****************************************************************************
  276. Object Helpers
  277. ****************************************************************************}
  278. {$ifndef FPC_SYSTEM_HAS_FPC_HELP_CONSTRUCTOR}
  279. { Generic code does not set the register used for self !
  280. So this needs to be done by the compiler after calling
  281. FPC_HELP_CONSTRUCTOR : generic allways means aa little less efficient (PM) }
  282. procedure int_help_constructor(var _self : pointer; vmt : pointer; vmt_pos : cardinal); [public,alias:'FPC_HELP_CONSTRUCTOR'];
  283. type
  284. ppointer = ^pointer;
  285. pvmt = ^tvmt;
  286. tvmt = record
  287. size,msize : longint;
  288. parent : pointer;
  289. end;
  290. var
  291. objectsize : longint;
  292. begin
  293. objectsize:=pvmt(vmt)^.size;
  294. getmem(_self,objectsize);
  295. fillchar(_self,objectsize,#0);
  296. ppointer(_self+vmt_pos)^:=vmt;
  297. end;
  298. {$endif ndef FPC_SYSTEM_HAS_FPC_HELP_CONSTRUCTOR}
  299. {$ifndef FPC_SYSTEM_HAS_FPC_HELP_DESTRUCTOR}
  300. procedure int_help_destructor(var _self : pointer; vmt : pointer; vmt_pos : cardinal);[public,alias:'FPC_HELP_DESTRUCTOR'];
  301. type
  302. ppointer = ^pointer;
  303. pvmt = ^tvmt;
  304. tvmt = record
  305. size,msize : longint;
  306. parent : pointer;
  307. end;
  308. var
  309. objectsize : longint;
  310. begin
  311. if (_self=nil) then
  312. exit;
  313. if (pvmt(ppointer(_self+vmt_pos)^)^.size=0) or
  314. (pvmt(ppointer(_self+vmt_pos)^)^.size+pvmt(ppointer(_self+vmt_pos)^)^.msize<>0) then
  315. RunError(210);
  316. objectsize:=pvmt(vmt)^.size;
  317. { reset vmt to nil for protection }
  318. ppointer(_self+vmt_pos)^:=nil;
  319. freemem(_self,objectsize);
  320. _self:=nil;
  321. end;
  322. {$endif ndef FPC_SYSTEM_HAS_FPC_HELP_DESTRUCTOR}
  323. {$ifndef FPC_SYSTEM_HAS_FPC_NEW_CLASS}
  324. {$error No pascal version of Int_new_class}
  325. (* procedure int_new_class;assembler;[public,alias:'FPC_NEW_CLASS'];
  326. asm
  327. { to be sure in the future, we save also edit }
  328. pushl %edi
  329. { create class ? }
  330. movl 8(%ebp),%edi
  331. orl %edi,%edi
  332. jz .LNEW_CLASS1
  333. { save registers !! }
  334. pushl %ebx
  335. pushl %ecx
  336. pushl %edx
  337. { esi contains the vmt }
  338. pushl %esi
  339. { call newinstance (class method!) }
  340. call *16(%esi)
  341. popl %edx
  342. popl %ecx
  343. popl %ebx
  344. { newinstance returns a pointer to the new created }
  345. { instance in eax }
  346. { load esi and insert self }
  347. movl %eax,%esi
  348. .LNEW_CLASS1:
  349. movl %esi,8(%ebp)
  350. orl %eax,%eax
  351. popl %edi
  352. end; *)
  353. {$endif ndef FPC_SYSTEM_HAS_FPC_NEW_CLASS}
  354. {$ifndef FPC_SYSTEM_HAS_FPC_DISPOSE_CLASS}
  355. {$error No pascal version of Int_dispose_class}
  356. (* procedure int_dispose_class;assembler;[public,alias:'FPC_DISPOSE_CLASS'];
  357. asm
  358. { to be sure in the future, we save also edit }
  359. pushl %edi
  360. { destroy class ? }
  361. movl 12(%ebp),%edi
  362. orl %edi,%edi
  363. jz .LDISPOSE_CLASS1
  364. { no inherited call }
  365. movl (%esi),%edi
  366. { save registers !! }
  367. pushl %eax
  368. pushl %ebx
  369. pushl %ecx
  370. pushl %edx
  371. { push self }
  372. pushl %esi
  373. { call freeinstance }
  374. call *20(%edi)
  375. popl %edx
  376. popl %ecx
  377. popl %ebx
  378. popl %eax
  379. .LDISPOSE_CLASS1:
  380. popl %edi
  381. end; *)
  382. {$endif ndef FPC_SYSTEM_HAS_FPC_DISPOSE_CLASS}
  383. {$ifndef FPC_SYSTEM_HAS_FPC_CHECK_OBJECT}
  384. procedure int_check_object(vmt : pointer);[public,alias:'FPC_CHECK_OBJECT'];
  385. type
  386. pvmt = ^tvmt;
  387. tvmt = record
  388. size,msize : longint;
  389. parent : pointer;
  390. end;
  391. begin
  392. if (vmt=nil) or
  393. (pvmt(vmt)^.size=0) or
  394. (pvmt(vmt)^.size+pvmt(vmt)^.msize<>0) then
  395. RunError(210);
  396. end;
  397. {$endif ndef FPC_SYSTEM_HAS_FPC_CHECK_OBJECT}
  398. { checks for a correct vmt pointer }
  399. { deeper check to see if the current object is }
  400. { really related to the true }
  401. {$ifndef FPC_SYSTEM_HAS_FPC_CHECK_OBJECT_EXT}
  402. procedure int_check_object_ext(vmt, expvmt : pointer);[public,alias:'FPC_CHECK_OBJECT_EXT'];
  403. type
  404. pvmt = ^tvmt;
  405. tvmt = record
  406. size,msize : longint;
  407. parent : pointer;
  408. end;
  409. begin
  410. if (vmt=nil) or
  411. (pvmt(vmt)^.size=0) or
  412. (pvmt(vmt)^.size+pvmt(vmt)^.msize<>0) then
  413. RunError(210);
  414. while assigned(vmt) do
  415. if vmt=expvmt then
  416. exit
  417. else
  418. vmt:=pvmt(vmt)^.parent;
  419. RunError(220);
  420. end;
  421. {$endif ndef FPC_SYSTEM_HAS_FPC_CHECK_OBJECT_EXT}
  422. {****************************************************************************
  423. String
  424. ****************************************************************************}
  425. {$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_COPY}
  426. procedure int_strcopy(len:longint;sstr,dstr:pointer);[public,alias:'FPC_SHORTSTR_COPY'];
  427. var
  428. slen : byte;
  429. begin
  430. if dstr=nil then
  431. exit;
  432. if sstr=nil then
  433. begin
  434. if dstr<>nil then
  435. pstring(dstr)^[0]:=#0;
  436. exit;
  437. end;
  438. slen:=length(pstring(sstr)^);
  439. if slen<len then
  440. len:=slen;
  441. move(sstr^,dstr^,len);
  442. pstring(dstr)^[0]:=chr(len);
  443. end;
  444. {$endif ndef FPC_SYSTEM_HAS_FPC_SHORTSTR_COPY}
  445. {$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_CONCAT}
  446. procedure int_strconcat(s1,s2:pointer);[public,alias:'FPC_SHORTSTR_CONCAT'];
  447. var
  448. s1l, s2l : byte;
  449. begin
  450. if (s1=nil) or (s2=nil) then
  451. exit;
  452. s1l:=length(pstring(s1)^);
  453. s2l:=length(pstring(s2)^);
  454. if s1l+s2l>255 then
  455. s1l:=255-s2l;
  456. move(@(pstring(s1)^[1]),@(pstring(s2)^[s2l+1]),s1l);
  457. pstring(s2)^[0]:=chr(s1l+s2l);
  458. end;
  459. {$endif ndef FPC_SYSTEM_HAS_FPC_SHORTSTR_CONCAT}
  460. {$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_COMPARE}
  461. function int_strcmp(dstr,sstr:pointer) : longint;[public,alias:'FPC_SHORTSTR_COMPARE'];
  462. var
  463. s1,s2,max,i : byte;
  464. d : longint;
  465. begin
  466. s1:=length(pstring(dstr)^);
  467. s2:=length(pstring(sstr)^);
  468. if s1<s2 then
  469. max:=s1
  470. else
  471. max:=s2;
  472. for i:=1 to max do
  473. begin
  474. d:=byte(pstring(dstr)^[i])-byte(pstring(sstr)^[i]);
  475. if d>0 then
  476. exit(1)
  477. else if d<0 then
  478. exit(-1);
  479. end;
  480. if s1>s2 then
  481. exit(1)
  482. else if s1<s2 then
  483. exit(-1)
  484. else
  485. exit(0);
  486. end;
  487. {$endif ndef FPC_SYSTEM_HAS_FPC_SHORTSTR_COMPARE}
  488. {$ifndef FPC_SYSTEM_HAS_FPC_PCHAR_TO_SHORTSTR}
  489. function strpas(p:pchar):string;[public,alias:'FPC_PCHAR_TO_SHORTSTR'];
  490. var
  491. l : longint;
  492. begin
  493. if p=nil then
  494. l:=0
  495. else
  496. l:=strlen(p);
  497. if l>255 then
  498. l:=255;
  499. if l>0 then
  500. move(p^,@(strpas[1]),l);
  501. strpas[0]:=chr(l);
  502. end;
  503. {$endif ndef FPC_SYSTEM_HAS_FPC_PCHAR_TO_SHORTSTR}
  504. {$ifndef FPC_SYSTEM_HAS_FPC_CHARARRAY_TO_SHORTSTR}
  505. function strchararray(p:pchar; l : longint):shortstring;[public,alias:'FPC_CHARARRAY_TO_SHORTSTR'];
  506. begin
  507. if l>=256 then
  508. l:=255
  509. else if l<0 then
  510. l:=0;
  511. move(p^,@(strchararray[1]),l);
  512. strchararray[0]:=chr(l);
  513. end;
  514. {$endif ndef FPC_SYSTEM_HAS_FPC_CHARARRAY_TO_SHORTSTR}
  515. {$ifopt r+}
  516. {$define rangeon}
  517. {$r-}
  518. {$endif}
  519. {$ifndef FPC_SYSTEM_HAS_FPC_STR_TO_CHARARRAY}
  520. procedure str_to_chararray(strtyp, arraysize: longint; src,dest: pchar);[public,alias:'FPC_STR_TO_CHARARRAY'];
  521. type
  522. plongint = ^longint;
  523. var
  524. len: longint;
  525. begin
  526. case strtyp of
  527. { shortstring }
  528. 0:
  529. begin
  530. len := byte(src[0]);
  531. inc(src);
  532. end;
  533. { ansistring}
  534. 1: len := length(ansistring(pointer(src)));
  535. { longstring }
  536. 2:;
  537. { widestring }
  538. 3:;
  539. end;
  540. if len > arraysize then
  541. len := arraysize;
  542. { make sure we don't dereference src if it can be nil (JM) }
  543. if len > 0 then
  544. move(src^,dest^,len);
  545. fillchar(dest[len],arraysize-len,0);
  546. end;
  547. {$endif FPC_SYSTEM_HAS_FPC_STR_TO_CHARARRAY}
  548. {$ifdef rangeon}
  549. {$r+}
  550. {undef rangeon}
  551. {$endif rangeon}
  552. {$ifndef FPC_SYSTEM_HAS_STRLEN}
  553. function strlen(p:pchar):longint;
  554. var i : longint;
  555. begin
  556. i:=0;
  557. while p[i]<>#0 do inc(i);
  558. exit(i);
  559. end;
  560. {$endif ndef FPC_SYSTEM_HAS_STRLEN}
  561. {****************************************************************************
  562. Caller/StackFrame Helpers
  563. ****************************************************************************}
  564. {$ifndef FPC_SYSTEM_HAS_GET_FRAME}
  565. {$error Get_frame must be defined for each processor }
  566. {$endif ndef FPC_SYSTEM_HAS_GET_FRAME}
  567. {$ifndef FPC_SYSTEM_HAS_GET_CALLER_ADDR}
  568. {$error Get_caller_addr must be defined for each processor }
  569. {$endif ndef FPC_SYSTEM_HAS_GET_CALLER_ADDR}
  570. {$ifndef FPC_SYSTEM_HAS_GET_CALLER_FRAME}
  571. {$error Get_caller_frame must be defined for each processor }
  572. {$endif ndef FPC_SYSTEM_HAS_GET_CALLER_FRAME}
  573. {****************************************************************************
  574. Math
  575. ****************************************************************************}
  576. {$ifndef FPC_SYSTEM_HAS_ABS_LONGINT}
  577. function abs(l:longint):longint;[internconst:in_const_abs];
  578. begin
  579. if l<0 then
  580. abs:=-l
  581. else
  582. abs:=l;
  583. end;
  584. {$endif ndef FPC_SYSTEM_HAS_ABS_LONGINT}
  585. {$ifndef FPC_SYSTEM_HAS_ODD_LONGINT}
  586. function odd(l:longint):boolean;[internconst:in_const_odd];
  587. begin
  588. odd:=((l and 1)<>0);
  589. end;
  590. {$endif ndef FPC_SYSTEM_HAS_ODD_LONGINT}
  591. {$ifndef FPC_SYSTEM_HAS_SQR_LONGINT}
  592. function sqr(l:longint):longint;[internconst:in_const_sqr];
  593. begin
  594. sqr:=l*l;
  595. end;
  596. {$endif ndef FPC_SYSTEM_HAS_SQR_LONGINT}
  597. {$ifndef FPC_SYSTEM_HAS_SPTR}
  598. {$error Sptr must be defined for each processor }
  599. {$endif ndef FPC_SYSTEM_HAS_SPTR}
  600. {****************************************************************************
  601. Str()
  602. ****************************************************************************}
  603. {$ifndef FPC_SYSTEM_HAS_INT_STR_LONGINT}
  604. procedure int_str(l : longint;var s : string);
  605. var
  606. sign : boolean;
  607. begin
  608. { Workaround: }
  609. if l=$80000000 then
  610. begin
  611. s:='-2147483648';
  612. exit;
  613. end;
  614. if l<0 then
  615. begin
  616. sign:=true;
  617. l:=-l;
  618. end
  619. else
  620. sign:=false;
  621. s:='';
  622. while l>0 do
  623. begin
  624. s:=char(ord('0')+(l mod 10))+s;
  625. l:=l div 10;
  626. end;
  627. if sign then
  628. s:='-'+s;
  629. end;
  630. {$endif ndef FPC_SYSTEM_HAS_INT_STR_LONGINT}
  631. {$ifndef FPC_SYSTEM_HAS_INT_STR_CARDINAL}
  632. procedure int_str(l : cardinal;var s : string);
  633. begin
  634. s:='';
  635. while l>0 do
  636. begin
  637. s:=char(ord('0')+(l mod 10))+s;
  638. l:=l div 10;
  639. end;
  640. if sign then
  641. s:='-'+s;
  642. end;
  643. {$endif ndef FPC_SYSTEM_HAS_INT_STR_CARDINAL}
  644. {****************************************************************************
  645. Bounds Check
  646. ****************************************************************************}
  647. {$ifndef NOBOUNDCHECK}
  648. {$ifndef FPC_SYSTEM_HAS_FPC_BOUNDCHECK}
  649. procedure int_boundcheck(l : longint; range : pointer);[public,alias: 'FPC_BOUNDCHECK'];
  650. type
  651. prange = ^trange;
  652. trange = record
  653. min,max : longint;
  654. end;
  655. begin
  656. if (l < prange(range)^.min) or
  657. (l > prange(range)^.max) then
  658. HandleError(201);
  659. end;
  660. {$endif ndef FPC_SYSTEM_HAS_FPC_BOUNDCHECK}
  661. {$endif NOBOUNDCHECK}
  662. {
  663. $Log$
  664. Revision 1.8 2001-04-13 18:06:28 peter
  665. * removed rtllite define
  666. Revision 1.7 2001/03/05 17:10:40 jonas
  667. * changed typecast in FPC_STR_TO_CHARARRAY so that no temp ansistring is
  668. generated anymore (merged)
  669. Revision 1.6 2001/03/03 12:41:22 jonas
  670. * simplified and optimized range checking code, FPC_BOUNDCHECK is no longer necessary
  671. Revision 1.5 2000/10/01 13:17:35 michael
  672. + Merged from fixbranch
  673. Revision 1.4 2000/08/09 11:29:01 jonas
  674. Revision 1.1.2.2 2000/10/01 13:14:50 michael
  675. + Corrected and (hopefully) improved compare0
  676. Revision 1.1.2.1 2000/08/09 11:21:32 jonas
  677. + FPC_STR_TO_CHARARRAY routine necessary for string -> chararray
  678. conversions fix (merged fropm fixes branch)
  679. Revision 1.3 2000/07/14 10:33:10 michael
  680. + Conditionals fixed
  681. Revision 1.2 2000/07/13 11:33:43 michael
  682. + removed logs
  683. }