system.pp 13 KB

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