generic.inc 18 KB

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