system.pp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2006 by Florian Klaempfl
  4. member of the Free Pascal development team.
  5. System unit for embedded systems
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. Unit system;
  13. {$namespace org.freepascal.rtl}
  14. {*****************************************************************************}
  15. interface
  16. {*****************************************************************************}
  17. {$define FPC_IS_SYSTEM}
  18. {$I-,Q-,H-,R-,V-}
  19. {$implicitexceptions off}
  20. {$mode objfpc}
  21. {$undef FPC_HAS_FEATURE_RTTI}
  22. Type
  23. { The compiler has all integer types defined internally. Here
  24. we define only aliases }
  25. DWord = LongWord;
  26. Cardinal = LongWord;
  27. Integer = SmallInt;
  28. UInt64 = QWord;
  29. ValReal = Double;
  30. { map comp to int64, }
  31. Comp = Int64;
  32. HResult = type longint;
  33. { Java primitive types }
  34. jboolean = boolean;
  35. jbyte = shortint;
  36. jshort = smallint;
  37. jint = longint;
  38. jlong = int64;
  39. jchar = widechar;
  40. jfloat = single;
  41. jdouble = double;
  42. Arr1jboolean = array of jboolean;
  43. Arr1jbyte = array of jbyte;
  44. Arr1jshort = array of jshort;
  45. Arr1jint = array of jint;
  46. Arr1jlong = array of jlong;
  47. Arr1jchar = array of jchar;
  48. Arr1jfloat = array of jfloat;
  49. Arr1jdouble = array of jdouble;
  50. Arr2jboolean = array of Arr1jboolean;
  51. Arr2jbyte = array of Arr1jbyte;
  52. Arr2jshort = array of Arr1jshort;
  53. Arr2jint = array of Arr1jint;
  54. Arr2jlong = array of Arr1jlong;
  55. Arr2jchar = array of Arr1jchar;
  56. Arr2jfloat = array of Arr1jfloat;
  57. Arr2jdouble = array of Arr1jdouble;
  58. Arr3jboolean = array of Arr2jboolean;
  59. Arr3jbyte = array of Arr2jbyte;
  60. Arr3jshort = array of Arr2jshort;
  61. Arr3jint = array of Arr2jint;
  62. Arr3jlong = array of Arr2jlong;
  63. Arr3jchar = array of Arr2jchar;
  64. Arr3jfloat = array of Arr2jfloat;
  65. Arr3jdouble = array of Arr2jdouble;
  66. const
  67. { max. values for longint and int}
  68. maxLongint = $7fffffff;
  69. maxSmallint = 32767;
  70. maxint = maxsmallint;
  71. { Java base class type }
  72. {$i java_sysh.inc}
  73. {$i java_sys.inc}
  74. type
  75. TObject = class(JLObject)
  76. strict private
  77. DestructorCalled: Boolean;
  78. public
  79. procedure Free;
  80. destructor Destroy; virtual;
  81. procedure finalize; override;
  82. end;
  83. {$i innr.inc}
  84. {$i jmathh.inc}
  85. {$i jrech.inc}
  86. {$i jdynarrh.inc}
  87. {$i compproc.inc}
  88. {*****************************************************************************}
  89. implementation
  90. {*****************************************************************************}
  91. {i jdynarr.inc}
  92. {
  93. This file is part of the Free Pascal run time library.
  94. Copyright (c) 2011 by Jonas Maebe
  95. member of the Free Pascal development team.
  96. This file implements the helper routines for dyn. Arrays in FPC
  97. See the file COPYING.FPC, included in this distribution,
  98. for details about the copyright.
  99. This program is distributed in the hope that it will be useful,
  100. but WITHOUT ANY WARRANTY; without even the implied warranty of
  101. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  102. **********************************************************************
  103. }
  104. {$i rtti.inc}
  105. {$i jrec.inc}
  106. function min(a,b : longint) : longint;
  107. begin
  108. if a<=b then
  109. min:=a
  110. else
  111. min:=b;
  112. end;
  113. { copying helpers }
  114. { also for booleans }
  115. procedure fpc_copy_jbyte_array(src, dst: TJByteArray);
  116. var
  117. i: longint;
  118. begin
  119. for i:=0 to min(high(src),high(dst)) do
  120. dst[i]:=src[i];
  121. end;
  122. procedure fpc_copy_jshort_array(src, dst: TJShortArray);
  123. var
  124. i: longint;
  125. begin
  126. for i:=0 to min(high(src),high(dst)) do
  127. dst[i]:=src[i];
  128. end;
  129. procedure fpc_copy_jint_array(src, dst: TJIntArray);
  130. var
  131. i: longint;
  132. begin
  133. for i:=0 to min(high(src),high(dst)) do
  134. dst[i]:=src[i];
  135. end;
  136. procedure fpc_copy_jlong_array(src, dst: TJLongArray);
  137. var
  138. i: longint;
  139. begin
  140. for i:=0 to min(high(src),high(dst)) do
  141. dst[i]:=src[i];
  142. end;
  143. procedure fpc_copy_jchar_array(src, dst: TJCharArray);
  144. var
  145. i: longint;
  146. begin
  147. for i:=0 to min(high(src),high(dst)) do
  148. dst[i]:=src[i];
  149. end;
  150. procedure fpc_copy_jfloat_array(src, dst: TJFloatArray);
  151. var
  152. i: longint;
  153. begin
  154. for i:=0 to min(high(src),high(dst)) do
  155. dst[i]:=src[i];
  156. end;
  157. procedure fpc_copy_jdouble_array(src, dst: TJDoubleArray);
  158. var
  159. i: longint;
  160. begin
  161. for i:=0 to min(high(src),high(dst)) do
  162. dst[i]:=src[i];
  163. end;
  164. procedure fpc_copy_jobject_array(src, dst: TJObjectArray);
  165. var
  166. i: longint;
  167. begin
  168. for i:=0 to min(high(src),high(dst)) do
  169. dst[i]:=src[i];
  170. end;
  171. procedure fpc_copy_jrecord_array(src, dst: TJRecordArray);
  172. var
  173. i: longint;
  174. begin
  175. for i:=0 to min(high(src),high(dst)) do
  176. dst[i]:=FpcBaseRecordType(src[i].clone);
  177. end;
  178. { 1-dimensional setlength routines }
  179. function fpc_setlength_dynarr_jbyte(aorg, anew: TJByteArray; deepcopy: boolean): TJByteArray;
  180. begin
  181. if deepcopy or
  182. (length(aorg)<>length(anew)) then
  183. begin
  184. fpc_copy_jbyte_array(aorg,anew);
  185. result:=anew
  186. end
  187. else
  188. result:=aorg;
  189. end;
  190. function fpc_setlength_dynarr_jshort(aorg, anew: TJShortArray; deepcopy: boolean): TJShortArray;
  191. begin
  192. if deepcopy or
  193. (length(aorg)<>length(anew)) then
  194. begin
  195. fpc_copy_jshort_array(aorg,anew);
  196. result:=anew
  197. end
  198. else
  199. result:=aorg;
  200. end;
  201. function fpc_setlength_dynarr_jint(aorg, anew: TJIntArray; deepcopy: boolean): TJIntArray;
  202. begin
  203. if deepcopy or
  204. (length(aorg)<>length(anew)) then
  205. begin
  206. fpc_copy_jint_array(aorg,anew);
  207. result:=anew
  208. end
  209. else
  210. result:=aorg;
  211. end;
  212. function fpc_setlength_dynarr_jlong(aorg, anew: TJLongArray; deepcopy: boolean): TJLongArray;
  213. begin
  214. if deepcopy or
  215. (length(aorg)<>length(anew)) then
  216. begin
  217. fpc_copy_jlong_array(aorg,anew);
  218. result:=anew
  219. end
  220. else
  221. result:=aorg;
  222. end;
  223. function fpc_setlength_dynarr_jchar(aorg, anew: TJCharArray; deepcopy: boolean): TJCharArray;
  224. begin
  225. if deepcopy or
  226. (length(aorg)<>length(anew)) then
  227. begin
  228. fpc_copy_jchar_array(aorg,anew);
  229. result:=anew
  230. end
  231. else
  232. result:=aorg;
  233. end;
  234. function fpc_setlength_dynarr_jfloat(aorg, anew: TJFloatArray; deepcopy: boolean): TJFloatArray;
  235. begin
  236. if deepcopy or
  237. (length(aorg)<>length(anew)) then
  238. begin
  239. fpc_copy_jfloat_array(aorg,anew);
  240. result:=anew
  241. end
  242. else
  243. result:=aorg;
  244. end;
  245. function fpc_setlength_dynarr_jdouble(aorg, anew: TJDoubleArray; deepcopy: boolean): TJDoubleArray;
  246. begin
  247. if deepcopy or
  248. (length(aorg)<>length(anew)) then
  249. begin
  250. fpc_copy_jdouble_array(aorg,anew);
  251. result:=anew
  252. end
  253. else
  254. result:=aorg;
  255. end;
  256. function fpc_setlength_dynarr_jobject(aorg, anew: TJObjectArray; deepcopy: boolean; docopy : boolean = true): TJObjectArray;
  257. begin
  258. if deepcopy or
  259. (length(aorg)<>length(anew)) then
  260. begin
  261. if docopy then
  262. fpc_copy_jobject_array(aorg,anew);
  263. result:=anew
  264. end
  265. else
  266. result:=aorg;
  267. end;
  268. function fpc_setlength_dynarr_jrecord(aorg, anew: TJRecordArray; deepcopy: boolean): TJRecordArray;
  269. begin
  270. if deepcopy or
  271. (length(aorg)<>length(anew)) then
  272. begin
  273. fpc_copy_jrecord_array(aorg,anew);
  274. result:=anew
  275. end
  276. else
  277. result:=aorg;
  278. end;
  279. { multi-dimensional setlength routine }
  280. function fpc_setlength_dynarr_multidim(aorg, anew: TJObjectArray; deepcopy: boolean; ndim: longint; eletype: jchar): TJObjectArray;
  281. var
  282. partdone,
  283. i: longint;
  284. begin
  285. { resize the current dimension; no need to copy the subarrays of the old
  286. array, as the subarrays will be (re-)initialised immediately below }
  287. result:=fpc_setlength_dynarr_jobject(aorg,anew,deepcopy,false);
  288. { if aorg was empty, there's nothing else to do since result will now
  289. contain anew, of which all other dimensions are already initialised
  290. correctly since there are no aorg elements to copy }
  291. if not assigned(aorg) and
  292. not deepcopy then
  293. exit;
  294. partdone:=min(high(result),high(aorg));
  295. { ndim must be >=2 when this routine is called, since it has to return
  296. an array of java.lang.Object! (arrays are also objects, but primitive
  297. types are not) }
  298. if ndim=2 then
  299. begin
  300. { final dimension -> copy the primitive arrays }
  301. case eletype of
  302. FPCJDynArrTypeJByte:
  303. begin
  304. for i:=low(result) to partdone do
  305. result[i]:=JLObject(fpc_setlength_dynarr_jbyte(TJByteArray(aorg[i]),TJByteArray(anew[i]),deepcopy));
  306. for i:=succ(partdone) to high(result) do
  307. result[i]:=JLObject(fpc_setlength_dynarr_jbyte(nil,TJByteArray(anew[i]),deepcopy));
  308. end;
  309. FPCJDynArrTypeJShort:
  310. begin
  311. for i:=low(result) to partdone do
  312. result[i]:=JLObject(fpc_setlength_dynarr_jshort(TJShortArray(aorg[i]),TJShortArray(anew[i]),deepcopy));
  313. for i:=succ(partdone) to high(result) do
  314. result[i]:=JLObject(fpc_setlength_dynarr_jshort(nil,TJShortArray(anew[i]),deepcopy));
  315. end;
  316. FPCJDynArrTypeJInt:
  317. begin
  318. for i:=low(result) to partdone do
  319. result[i]:=JLObject(fpc_setlength_dynarr_jint(TJIntArray(aorg[i]),TJIntArray(anew[i]),deepcopy));
  320. for i:=succ(partdone) to high(result) do
  321. result[i]:=JLObject(fpc_setlength_dynarr_jint(nil,TJIntArray(anew[i]),deepcopy));
  322. end;
  323. FPCJDynArrTypeJLong:
  324. begin
  325. for i:=low(result) to partdone do
  326. result[i]:=JLObject(fpc_setlength_dynarr_jlong(TJLongArray(aorg[i]),TJLongArray(anew[i]),deepcopy));
  327. for i:=succ(partdone) to high(result) do
  328. result[i]:=JLObject(fpc_setlength_dynarr_jlong(nil,TJLongArray(anew[i]),deepcopy));
  329. end;
  330. FPCJDynArrTypeJChar:
  331. begin
  332. for i:=low(result) to partdone do
  333. result[i]:=JLObject(fpc_setlength_dynarr_jchar(TJCharArray(aorg[i]),TJCharArray(anew[i]),deepcopy));
  334. for i:=succ(partdone) to high(result) do
  335. result[i]:=JLObject(fpc_setlength_dynarr_jchar(nil,TJCharArray(anew[i]),deepcopy));
  336. end;
  337. FPCJDynArrTypeJFloat:
  338. begin
  339. for i:=low(result) to partdone do
  340. result[i]:=JLObject(fpc_setlength_dynarr_jfloat(TJFloatArray(aorg[i]),TJFloatArray(anew[i]),deepcopy));
  341. for i:=succ(partdone) to high(result) do
  342. result[i]:=JLObject(fpc_setlength_dynarr_jfloat(nil,TJFloatArray(anew[i]),deepcopy));
  343. end;
  344. FPCJDynArrTypeJDouble:
  345. begin
  346. for i:=low(result) to partdone do
  347. result[i]:=JLObject(fpc_setlength_dynarr_jdouble(TJDoubleArray(aorg[i]),TJDoubleArray(anew[i]),deepcopy));
  348. for i:=succ(partdone) to high(result) do
  349. result[i]:=JLObject(fpc_setlength_dynarr_jdouble(nil,TJDoubleArray(anew[i]),deepcopy));
  350. end;
  351. FPCJDynArrTypeJObject:
  352. begin
  353. for i:=low(result) to partdone do
  354. result[i]:=JLObject(fpc_setlength_dynarr_jobject(TJObjectArray(aorg[i]),TJObjectArray(anew[i]),deepcopy,true));
  355. for i:=succ(partdone) to high(result) do
  356. result[i]:=JLObject(fpc_setlength_dynarr_jobject(nil,TJObjectArray(anew[i]),deepcopy,true));
  357. end;
  358. FPCJDynArrTypeRecord:
  359. begin
  360. for i:=low(result) to partdone do
  361. result[i]:=JLObject(fpc_setlength_dynarr_jrecord(TJRecordArray(aorg[i]),TJRecordArray(anew[i]),deepcopy));
  362. for i:=succ(partdone) to high(result) do
  363. result[i]:=JLObject(fpc_setlength_dynarr_jrecord(nil,TJRecordArray(anew[i]),deepcopy));
  364. end;
  365. end;
  366. end
  367. else
  368. begin
  369. { recursively handle the next dimension }
  370. for i:=low(result) to partdone do
  371. result[i]:=JLObject(fpc_setlength_dynarr_multidim(TJObjectArray(aorg[i]),TJObjectArray(anew[i]),deepcopy,pred(ndim),eletype));
  372. for i:=succ(partdone) to high(result) do
  373. result[i]:=JLObject(fpc_setlength_dynarr_multidim(nil,TJObjectArray(anew[i]),deepcopy,pred(ndim),eletype));
  374. end;
  375. end;
  376. {i jdynarr.inc end}
  377. {*****************************************************************************
  378. Misc. System Dependent Functions
  379. *****************************************************************************}
  380. procedure TObject.Free;
  381. begin
  382. if not DestructorCalled then
  383. begin
  384. DestructorCalled:=true;
  385. Destroy;
  386. end;
  387. end;
  388. destructor TObject.Destroy;
  389. begin
  390. end;
  391. procedure TObject.Finalize;
  392. begin
  393. Free;
  394. end;
  395. {*****************************************************************************
  396. SystemUnit Initialization
  397. *****************************************************************************}
  398. end.