system.pp 11 KB

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