system.pp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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 jdynarrh.inc}
  78. {$i compproc.inc}
  79. {*****************************************************************************}
  80. implementation
  81. {*****************************************************************************}
  82. {i jdynarr.inc}
  83. {
  84. This file is part of the Free Pascal run time library.
  85. Copyright (c) 2011 by Jonas Maebe
  86. member of the Free Pascal development team.
  87. This file implements the helper routines for dyn. Arrays in FPC
  88. See the file COPYING.FPC, included in this distribution,
  89. for details about the copyright.
  90. This program is distributed in the hope that it will be useful,
  91. but WITHOUT ANY WARRANTY; without even the implied warranty of
  92. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  93. **********************************************************************
  94. }
  95. {$i rtti.inc}
  96. function min(a,b : longint) : longint;
  97. begin
  98. if a<=b then
  99. min:=a
  100. else
  101. min:=b;
  102. end;
  103. { copying helpers }
  104. { also for booleans }
  105. procedure fpc_copy_jbyte_array(src, dst: TJByteArray);
  106. var
  107. i: longint;
  108. begin
  109. for i:=0 to min(high(src),high(dst)) do
  110. dst[i]:=src[i];
  111. end;
  112. procedure fpc_copy_jshort_array(src, dst: TJShortArray);
  113. var
  114. i: longint;
  115. begin
  116. for i:=0 to min(high(src),high(dst)) do
  117. dst[i]:=src[i];
  118. end;
  119. procedure fpc_copy_jint_array(src, dst: TJIntArray);
  120. var
  121. i: longint;
  122. begin
  123. for i:=0 to min(high(src),high(dst)) do
  124. dst[i]:=src[i];
  125. end;
  126. procedure fpc_copy_jlong_array(src, dst: TJLongArray);
  127. var
  128. i: longint;
  129. begin
  130. for i:=0 to min(high(src),high(dst)) do
  131. dst[i]:=src[i];
  132. end;
  133. procedure fpc_copy_jchar_array(src, dst: TJCharArray);
  134. var
  135. i: longint;
  136. begin
  137. for i:=0 to min(high(src),high(dst)) do
  138. dst[i]:=src[i];
  139. end;
  140. procedure fpc_copy_jfloat_array(src, dst: TJFloatArray);
  141. var
  142. i: longint;
  143. begin
  144. for i:=0 to min(high(src),high(dst)) do
  145. dst[i]:=src[i];
  146. end;
  147. procedure fpc_copy_jdouble_array(src, dst: TJDoubleArray);
  148. var
  149. i: longint;
  150. begin
  151. for i:=0 to min(high(src),high(dst)) do
  152. dst[i]:=src[i];
  153. end;
  154. procedure fpc_copy_jobject_array(src, dst: TJObjectArray);
  155. var
  156. i: longint;
  157. begin
  158. for i:=0 to min(high(src),high(dst)) do
  159. dst[i]:=src[i];
  160. end;
  161. { 1-dimensional setlength routines }
  162. function fpc_setlength_dynarr_jbyte(aorg, anew: TJByteArray; deepcopy: boolean): TJByteArray;
  163. begin
  164. if deepcopy or
  165. (length(aorg)<>length(anew)) then
  166. begin
  167. fpc_copy_jbyte_array(aorg,anew);
  168. result:=anew
  169. end
  170. else
  171. result:=aorg;
  172. end;
  173. function fpc_setlength_dynarr_jshort(aorg, anew: TJShortArray; deepcopy: boolean): TJShortArray;
  174. begin
  175. if deepcopy or
  176. (length(aorg)<>length(anew)) then
  177. begin
  178. fpc_copy_jshort_array(aorg,anew);
  179. result:=anew
  180. end
  181. else
  182. result:=aorg;
  183. end;
  184. function fpc_setlength_dynarr_jint(aorg, anew: TJIntArray; deepcopy: boolean): TJIntArray;
  185. begin
  186. if deepcopy or
  187. (length(aorg)<>length(anew)) then
  188. begin
  189. fpc_copy_jint_array(aorg,anew);
  190. result:=anew
  191. end
  192. else
  193. result:=aorg;
  194. end;
  195. function fpc_setlength_dynarr_jlong(aorg, anew: TJLongArray; deepcopy: boolean): TJLongArray;
  196. begin
  197. if deepcopy or
  198. (length(aorg)<>length(anew)) then
  199. begin
  200. fpc_copy_jlong_array(aorg,anew);
  201. result:=anew
  202. end
  203. else
  204. result:=aorg;
  205. end;
  206. function fpc_setlength_dynarr_jchar(aorg, anew: TJCharArray; deepcopy: boolean): TJCharArray;
  207. begin
  208. if deepcopy or
  209. (length(aorg)<>length(anew)) then
  210. begin
  211. fpc_copy_jchar_array(aorg,anew);
  212. result:=anew
  213. end
  214. else
  215. result:=aorg;
  216. end;
  217. function fpc_setlength_dynarr_jfloat(aorg, anew: TJFloatArray; deepcopy: boolean): TJFloatArray;
  218. begin
  219. if deepcopy or
  220. (length(aorg)<>length(anew)) then
  221. begin
  222. fpc_copy_jfloat_array(aorg,anew);
  223. result:=anew
  224. end
  225. else
  226. result:=aorg;
  227. end;
  228. function fpc_setlength_dynarr_jdouble(aorg, anew: TJDoubleArray; deepcopy: boolean): TJDoubleArray;
  229. begin
  230. if deepcopy or
  231. (length(aorg)<>length(anew)) then
  232. begin
  233. fpc_copy_jdouble_array(aorg,anew);
  234. result:=anew
  235. end
  236. else
  237. result:=aorg;
  238. end;
  239. function fpc_setlength_dynarr_jobject(aorg, anew: TJObjectArray; deepcopy: boolean; docopy : boolean = true): TJObjectArray;
  240. begin
  241. if deepcopy or
  242. (length(aorg)<>length(anew)) then
  243. begin
  244. if docopy then
  245. fpc_copy_jobject_array(aorg,anew);
  246. result:=anew
  247. end
  248. else
  249. result:=aorg;
  250. end;
  251. { multi-dimensional setlength routine }
  252. function fpc_setlength_dynarr_multidim(aorg, anew: TJObjectArray; deepcopy: boolean; ndim: longint; eletype: jchar): TJObjectArray;
  253. var
  254. partdone,
  255. i: longint;
  256. begin
  257. { resize the current dimension; no need to copy the subarrays of the old
  258. array, as the subarrays will be (re-)initialised immediately below }
  259. result:=fpc_setlength_dynarr_jobject(aorg,anew,deepcopy,false);
  260. { if aorg was empty, there's nothing else to do since result will now
  261. contain anew, of which all other dimensions are already initialised
  262. correctly since there are no aorg elements to copy }
  263. if not assigned(aorg) and
  264. not deepcopy then
  265. exit;
  266. partdone:=min(high(result),high(aorg));
  267. { ndim must be >=2 when this routine is called, since it has to return
  268. an array of java.lang.Object! (arrays are also objects, but primitive
  269. types are not) }
  270. if ndim=2 then
  271. begin
  272. { final dimension -> copy the primitive arrays }
  273. case eletype of
  274. FPCJDynArrTypeJByte:
  275. begin
  276. for i:=low(result) to partdone do
  277. result[i]:=TObject(fpc_setlength_dynarr_jbyte(TJByteArray(aorg[i]),TJByteArray(anew[i]),deepcopy));
  278. for i:=succ(partdone) to high(result) do
  279. result[i]:=TObject(fpc_setlength_dynarr_jbyte(nil,TJByteArray(anew[i]),deepcopy));
  280. end;
  281. FPCJDynArrTypeJShort:
  282. begin
  283. for i:=low(result) to partdone do
  284. result[i]:=TObject(fpc_setlength_dynarr_jshort(TJShortArray(aorg[i]),TJShortArray(anew[i]),deepcopy));
  285. for i:=succ(partdone) to high(result) do
  286. result[i]:=TObject(fpc_setlength_dynarr_jshort(nil,TJShortArray(anew[i]),deepcopy));
  287. end;
  288. FPCJDynArrTypeJInt:
  289. begin
  290. for i:=low(result) to partdone do
  291. result[i]:=TObject(fpc_setlength_dynarr_jint(TJIntArray(aorg[i]),TJIntArray(anew[i]),deepcopy));
  292. for i:=succ(partdone) to high(result) do
  293. result[i]:=TObject(fpc_setlength_dynarr_jint(nil,TJIntArray(anew[i]),deepcopy));
  294. end;
  295. FPCJDynArrTypeJLong:
  296. begin
  297. for i:=low(result) to partdone do
  298. result[i]:=TObject(fpc_setlength_dynarr_jlong(TJLongArray(aorg[i]),TJLongArray(anew[i]),deepcopy));
  299. for i:=succ(partdone) to high(result) do
  300. result[i]:=TObject(fpc_setlength_dynarr_jlong(nil,TJLongArray(anew[i]),deepcopy));
  301. end;
  302. FPCJDynArrTypeJChar:
  303. begin
  304. for i:=low(result) to partdone do
  305. result[i]:=TObject(fpc_setlength_dynarr_jchar(TJCharArray(aorg[i]),TJCharArray(anew[i]),deepcopy));
  306. for i:=succ(partdone) to high(result) do
  307. result[i]:=TObject(fpc_setlength_dynarr_jchar(nil,TJCharArray(anew[i]),deepcopy));
  308. end;
  309. FPCJDynArrTypeJFloat:
  310. begin
  311. for i:=low(result) to partdone do
  312. result[i]:=TObject(fpc_setlength_dynarr_jfloat(TJFloatArray(aorg[i]),TJFloatArray(anew[i]),deepcopy));
  313. for i:=succ(partdone) to high(result) do
  314. result[i]:=TObject(fpc_setlength_dynarr_jfloat(nil,TJFloatArray(anew[i]),deepcopy));
  315. end;
  316. FPCJDynArrTypeJDouble:
  317. begin
  318. for i:=low(result) to partdone do
  319. result[i]:=TObject(fpc_setlength_dynarr_jdouble(TJDoubleArray(aorg[i]),TJDoubleArray(anew[i]),deepcopy));
  320. for i:=succ(partdone) to high(result) do
  321. result[i]:=TObject(fpc_setlength_dynarr_jdouble(nil,TJDoubleArray(anew[i]),deepcopy));
  322. end;
  323. FPCJDynArrTypeJObject:
  324. begin
  325. for i:=low(result) to partdone do
  326. result[i]:=TObject(fpc_setlength_dynarr_jobject(TJObjectArray(aorg[i]),TJObjectArray(anew[i]),deepcopy,true));
  327. for i:=succ(partdone) to high(result) do
  328. result[i]:=TObject(fpc_setlength_dynarr_jobject(nil,TJObjectArray(anew[i]),deepcopy,true));
  329. end;
  330. end;
  331. end
  332. else
  333. begin
  334. { recursively handle the next dimension }
  335. for i:=low(result) to partdone do
  336. result[i]:=TObject(fpc_setlength_dynarr_multidim(TJObjectArray(aorg[i]),TJObjectArray(anew[i]),deepcopy,pred(ndim),eletype));
  337. for i:=succ(partdone) to high(result) do
  338. result[i]:=TObject(fpc_setlength_dynarr_multidim(nil,TJObjectArray(anew[i]),deepcopy,pred(ndim),eletype));
  339. end;
  340. end;
  341. {i jdynarr.inc end}
  342. {*****************************************************************************
  343. Misc. System Dependent Functions
  344. *****************************************************************************}
  345. {*****************************************************************************
  346. SystemUnit Initialization
  347. *****************************************************************************}
  348. end.