system.pp 13 KB

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