system.pp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  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. Type
  21. { The compiler has all integer types defined internally. Here
  22. we define only aliases }
  23. DWord = LongWord;
  24. Cardinal = LongWord;
  25. Integer = SmallInt;
  26. UInt64 = QWord;
  27. ValReal = Double;
  28. { map comp to int64, }
  29. Comp = Int64;
  30. HResult = type longint;
  31. { Java primitive types }
  32. jboolean = boolean;
  33. jbyte = shortint;
  34. jshort = smallint;
  35. jint = longint;
  36. jlong = int64;
  37. jchar = widechar;
  38. jfloat = single;
  39. jdouble = double;
  40. Arr1jboolean = array of jboolean;
  41. Arr1jbyte = array of jbyte;
  42. Arr1jshort = array of jshort;
  43. Arr1jint = array of jint;
  44. Arr1jlong = array of jlong;
  45. Arr1jchar = array of jchar;
  46. Arr1jfloat = array of jfloat;
  47. Arr1jdouble = array of jdouble;
  48. Arr2jboolean = array of Arr1jboolean;
  49. Arr2jbyte = array of Arr1jbyte;
  50. Arr2jshort = array of Arr1jshort;
  51. Arr2jint = array of Arr1jint;
  52. Arr2jlong = array of Arr1jlong;
  53. Arr2jchar = array of Arr1jchar;
  54. Arr2jfloat = array of Arr1jfloat;
  55. Arr2jdouble = array of Arr1jdouble;
  56. Arr3jboolean = array of Arr2jboolean;
  57. Arr3jbyte = array of Arr2jbyte;
  58. Arr3jshort = array of Arr2jshort;
  59. Arr3jint = array of Arr2jint;
  60. Arr3jlong = array of Arr2jlong;
  61. Arr3jchar = array of Arr2jchar;
  62. Arr3jfloat = array of Arr2jfloat;
  63. Arr3jdouble = array of Arr2jdouble;
  64. const
  65. { max. values for longint and int}
  66. maxLongint = $7fffffff;
  67. maxSmallint = 32767;
  68. maxint = maxsmallint;
  69. type
  70. { Java base class type }
  71. TObject = class external 'java.lang' name 'Object'
  72. protected
  73. function clone: TObject;
  74. public
  75. constructor create;
  76. function equals(obj: TObject): boolean;
  77. function hashcode: longint;
  78. end;
  79. TJLObject = TObject;
  80. TJISerializable = interface external 'java.lang' name 'Serializable'
  81. end;
  82. TJLThrowable = class external 'java.lang' name 'Throwable' (TObject,TJISerializable)
  83. constructor create;
  84. end;
  85. { Java Float class type }
  86. TJFloat = class external 'java.lang' name 'Float'
  87. constructor create(f: jfloat);
  88. class function floatToRawIntBits(f: jfloat): jint; static;
  89. class function intBitsToFloat(j: jint): jfloat; static;
  90. end;
  91. { Java Dloat class type }
  92. TJDouble = class external 'java.lang' name 'Double'
  93. constructor create(d: jdouble);
  94. class function doubleToRawLongBits(d: jdouble): jlong; static;
  95. class function longBitsToDouble(l: jlong): jdouble; static;
  96. end;
  97. {$i innr.inc}
  98. {$i jmathh.inc}
  99. {$i jdynarrh.inc}
  100. {*****************************************************************************}
  101. implementation
  102. {*****************************************************************************}
  103. {i jdynarr.inc}
  104. {
  105. This file is part of the Free Pascal run time library.
  106. Copyright (c) 2011 by Jonas Maebe
  107. member of the Free Pascal development team.
  108. This file implements the helper routines for dyn. Arrays in FPC
  109. See the file COPYING.FPC, included in this distribution,
  110. for details about the copyright.
  111. This program is distributed in the hope that it will be useful,
  112. but WITHOUT ANY WARRANTY; without even the implied warranty of
  113. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  114. **********************************************************************
  115. }
  116. function min(a,b : longint) : longint;
  117. begin
  118. if a<=b then
  119. min:=a
  120. else
  121. min:=b;
  122. end;
  123. { copying helpers }
  124. { also for booleans }
  125. procedure fpc_copy_jbyte_array(src, dst: TJByteArray);
  126. var
  127. i: longint;
  128. begin
  129. for i:=0 to min(high(src),high(dst)) do
  130. dst[i]:=src[i];
  131. end;
  132. procedure fpc_copy_jshort_array(src, dst: TJShortArray);
  133. var
  134. i: longint;
  135. begin
  136. for i:=0 to min(high(src),high(dst)) do
  137. dst[i]:=src[i];
  138. end;
  139. procedure fpc_copy_jint_array(src, dst: TJIntArray);
  140. var
  141. i: longint;
  142. begin
  143. for i:=0 to min(high(src),high(dst)) do
  144. dst[i]:=src[i];
  145. end;
  146. procedure fpc_copy_jlong_array(src, dst: TJLongArray);
  147. var
  148. i: longint;
  149. begin
  150. for i:=0 to min(high(src),high(dst)) do
  151. dst[i]:=src[i];
  152. end;
  153. procedure fpc_copy_jchar_array(src, dst: TJCharArray);
  154. var
  155. i: longint;
  156. begin
  157. for i:=0 to min(high(src),high(dst)) do
  158. dst[i]:=src[i];
  159. end;
  160. procedure fpc_copy_jfloat_array(src, dst: TJFloatArray);
  161. var
  162. i: longint;
  163. begin
  164. for i:=0 to min(high(src),high(dst)) do
  165. dst[i]:=src[i];
  166. end;
  167. procedure fpc_copy_jdouble_array(src, dst: TJDoubleArray);
  168. var
  169. i: longint;
  170. begin
  171. for i:=0 to min(high(src),high(dst)) do
  172. dst[i]:=src[i];
  173. end;
  174. procedure fpc_copy_jobject_array(src, dst: TJObjectArray);
  175. var
  176. i: longint;
  177. begin
  178. for i:=0 to min(high(src),high(dst)) do
  179. dst[i]:=src[i];
  180. end;
  181. { 1-dimensional setlength routines }
  182. function fpc_setlength_dynarr_jbyte(aorg, anew: TJByteArray; deepcopy: boolean): TJByteArray;
  183. begin
  184. if deepcopy or
  185. (length(aorg)<>length(anew)) then
  186. begin
  187. fpc_copy_jbyte_array(aorg,anew);
  188. result:=anew
  189. end
  190. else
  191. result:=aorg;
  192. end;
  193. function fpc_setlength_dynarr_jshort(aorg, anew: TJShortArray; deepcopy: boolean): TJShortArray;
  194. begin
  195. if deepcopy or
  196. (length(aorg)<>length(anew)) then
  197. begin
  198. fpc_copy_jshort_array(aorg,anew);
  199. result:=anew
  200. end
  201. else
  202. result:=aorg;
  203. end;
  204. function fpc_setlength_dynarr_jint(aorg, anew: TJIntArray; deepcopy: boolean): TJIntArray;
  205. begin
  206. if deepcopy or
  207. (length(aorg)<>length(anew)) then
  208. begin
  209. fpc_copy_jint_array(aorg,anew);
  210. result:=anew
  211. end
  212. else
  213. result:=aorg;
  214. end;
  215. function fpc_setlength_dynarr_jlong(aorg, anew: TJLongArray; deepcopy: boolean): TJLongArray;
  216. begin
  217. if deepcopy or
  218. (length(aorg)<>length(anew)) then
  219. begin
  220. fpc_copy_jlong_array(aorg,anew);
  221. result:=anew
  222. end
  223. else
  224. result:=aorg;
  225. end;
  226. function fpc_setlength_dynarr_jchar(aorg, anew: TJCharArray; deepcopy: boolean): TJCharArray;
  227. begin
  228. if deepcopy or
  229. (length(aorg)<>length(anew)) then
  230. begin
  231. fpc_copy_jchar_array(aorg,anew);
  232. result:=anew
  233. end
  234. else
  235. result:=aorg;
  236. end;
  237. function fpc_setlength_dynarr_jfloat(aorg, anew: TJFloatArray; deepcopy: boolean): TJFloatArray;
  238. begin
  239. if deepcopy or
  240. (length(aorg)<>length(anew)) then
  241. begin
  242. fpc_copy_jfloat_array(aorg,anew);
  243. result:=anew
  244. end
  245. else
  246. result:=aorg;
  247. end;
  248. function fpc_setlength_dynarr_jdouble(aorg, anew: TJDoubleArray; deepcopy: boolean): TJDoubleArray;
  249. begin
  250. if deepcopy or
  251. (length(aorg)<>length(anew)) then
  252. begin
  253. fpc_copy_jdouble_array(aorg,anew);
  254. result:=anew
  255. end
  256. else
  257. result:=aorg;
  258. end;
  259. function fpc_setlength_dynarr_jobject(aorg, anew: TJObjectArray; deepcopy: boolean; docopy : boolean = true): TJObjectArray;
  260. begin
  261. if deepcopy or
  262. (length(aorg)<>length(anew)) then
  263. begin
  264. if docopy then
  265. fpc_copy_jobject_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. end;
  351. end
  352. else
  353. begin
  354. { recursively handle the next dimension }
  355. for i:=low(result) to partdone do
  356. result[i]:=TObject(fpc_setlength_dynarr_multidim(TJObjectArray(aorg[i]),TJObjectArray(anew[i]),deepcopy,pred(ndim),eletype));
  357. for i:=succ(partdone) to high(result) do
  358. result[i]:=TObject(fpc_setlength_dynarr_multidim(nil,TJObjectArray(anew[i]),deepcopy,pred(ndim),eletype));
  359. end;
  360. end;
  361. {i jdynarr.inc end}
  362. {*****************************************************************************
  363. Misc. System Dependent Functions
  364. *****************************************************************************}
  365. {*****************************************************************************
  366. SystemUnit Initialization
  367. *****************************************************************************}
  368. end.