system.pp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  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. {$namespace org.freepascal.rtl}
  14. {*****************************************************************************}
  15. interface
  16. {*****************************************************************************}
  17. {$define FPC_IS_SYSTEM}
  18. {$I-,Q-,H-,R-,V-,P+,T+}
  19. {$implicitexceptions off}
  20. {$mode objfpc}
  21. {$undef FPC_HAS_FEATURE_ANSISTRINGS}
  22. {$undef FPC_HAS_FEATURE_TEXTIO}
  23. {$undef FPC_HAS_FEATURE_VARIANTS}
  24. {$undef FPC_HAS_FEATURE_CLASSES}
  25. {$undef FPC_HAS_FEATURE_EXCEPTIONS}
  26. {$undef FPC_HAS_FEATURE_OBJECTS}
  27. {$undef FPC_HAS_FEATURE_RTTI}
  28. {$undef FPC_HAS_FEATURE_FILEIO}
  29. {$undef FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE}
  30. Type
  31. { The compiler has all integer types defined internally. Here
  32. we define only aliases }
  33. DWord = LongWord;
  34. Cardinal = LongWord;
  35. Integer = SmallInt;
  36. UInt64 = QWord;
  37. SizeInt = Longint;
  38. SizeUInt = Longint;
  39. PtrInt = Longint;
  40. PtrUInt = Longint;
  41. {$define DEFAULT_DOUBLE}
  42. {$define SUPPORT_SINGLE}
  43. {$define SUPPORT_DOUBLE}
  44. ValReal = Double;
  45. Real = type Double;
  46. AnsiChar = Char;
  47. UnicodeChar = WideChar;
  48. { map comp to int64 }
  49. Comp = Int64;
  50. HResult = type longint;
  51. PShortString = ^ShortString;
  52. { Java primitive types }
  53. jboolean = boolean;
  54. jbyte = shortint;
  55. jshort = smallint;
  56. jint = longint;
  57. jlong = int64;
  58. jchar = widechar;
  59. jfloat = single;
  60. jdouble = double;
  61. Arr1jboolean = array of jboolean;
  62. Arr1jbyte = array of jbyte;
  63. Arr1jshort = array of jshort;
  64. Arr1jint = array of jint;
  65. Arr1jlong = array of jlong;
  66. Arr1jchar = array of jchar;
  67. Arr1jfloat = array of jfloat;
  68. Arr1jdouble = array of jdouble;
  69. Arr2jboolean = array of Arr1jboolean;
  70. Arr2jbyte = array of Arr1jbyte;
  71. Arr2jshort = array of Arr1jshort;
  72. Arr2jint = array of Arr1jint;
  73. Arr2jlong = array of Arr1jlong;
  74. Arr2jchar = array of Arr1jchar;
  75. Arr2jfloat = array of Arr1jfloat;
  76. Arr2jdouble = array of Arr1jdouble;
  77. Arr3jboolean = array of Arr2jboolean;
  78. Arr3jbyte = array of Arr2jbyte;
  79. Arr3jshort = array of Arr2jshort;
  80. Arr3jint = array of Arr2jint;
  81. Arr3jlong = array of Arr2jlong;
  82. Arr3jchar = array of Arr2jchar;
  83. Arr3jfloat = array of Arr2jfloat;
  84. Arr3jdouble = array of Arr2jdouble;
  85. const
  86. { max. values for longint and int}
  87. maxLongint = $7fffffff;
  88. maxSmallint = 32767;
  89. maxint = maxsmallint;
  90. { Java base class type }
  91. {$i java_sysh.inc}
  92. {$i java_sys.inc}
  93. type
  94. TObject = class(JLObject)
  95. strict private
  96. DestructorCalled: Boolean;
  97. public
  98. procedure Free;
  99. destructor Destroy; virtual;
  100. procedure finalize; override;
  101. end;
  102. FpcEnumValueObtainable = interface
  103. function fpcOrdinal: jint;
  104. function fpcGenericValueOf(__fpc_int: longint): JLEnum;
  105. end;
  106. {$i innr.inc}
  107. {$i jrech.inc}
  108. {$i jseth.inc}
  109. {$i sstringh.inc}
  110. {$i jpvarh.inc}
  111. {$i jdynarrh.inc}
  112. {$i astringh.inc}
  113. {$i mathh.inc}
  114. {$ifndef nounsupported}
  115. const
  116. vtInteger = 0;
  117. vtBoolean = 1;
  118. vtChar = 2;
  119. {$ifndef FPUNONE}
  120. vtExtended = 3;
  121. {$endif}
  122. vtString = 4;
  123. vtPointer = 5;
  124. vtPChar = 6;
  125. vtObject = 7;
  126. vtClass = 8;
  127. vtWideChar = 9;
  128. vtPWideChar = 10;
  129. vtAnsiString = 11;
  130. vtCurrency = 12;
  131. vtVariant = 13;
  132. vtInterface = 14;
  133. vtWideString = 15;
  134. vtInt64 = 16;
  135. vtQWord = 17;
  136. vtUnicodeString = 18;
  137. type
  138. TVarRec = record
  139. case VType : sizeint of
  140. {$ifdef ENDIAN_BIG}
  141. vtInteger : ({$IFDEF CPU64}integerdummy1 : Longint;{$ENDIF CPU64}VInteger: Longint);
  142. vtBoolean : ({$IFDEF CPU64}booldummy : Longint;{$ENDIF CPU64}booldummy1,booldummy2,booldummy3: byte; VBoolean: Boolean);
  143. vtChar : ({$IFDEF CPU64}chardummy : Longint;{$ENDIF CPU64}chardummy1,chardummy2,chardummy3: byte; VChar: Char);
  144. vtWideChar : ({$IFDEF CPU64}widechardummy : Longint;{$ENDIF CPU64}wchardummy1,VWideChar: WideChar);
  145. {$else ENDIAN_BIG}
  146. vtInteger : (VInteger: Longint);
  147. vtBoolean : (VBoolean: Boolean);
  148. vtChar : (VChar: Char);
  149. vtWideChar : (VWideChar: WideChar);
  150. {$endif ENDIAN_BIG}
  151. // vtString : (VString: PShortString);
  152. // vtPointer : (VPointer: Pointer);
  153. /// vtPChar : (VPChar: PChar);
  154. vtObject : (VObject: TObject);
  155. // vtClass : (VClass: TClass);
  156. // vtPWideChar : (VPWideChar: PWideChar);
  157. vtAnsiString : (VAnsiString: JLObject);
  158. vtCurrency : (VCurrency: Currency);
  159. // vtVariant : (VVariant: PVariant);
  160. vtInterface : (VInterface: JLObject);
  161. vtWideString : (VWideString: JLString);
  162. vtInt64 : (VInt64: Int64);
  163. vtUnicodeString : (VUnicodeString: JLString);
  164. vtQWord : (VQWord: QWord);
  165. end;
  166. {$endif}
  167. Function lo(i : Integer) : byte; [INTERNPROC: fpc_in_lo_Word];
  168. Function lo(w : Word) : byte; [INTERNPROC: fpc_in_lo_Word];
  169. Function lo(l : Longint) : Word; [INTERNPROC: fpc_in_lo_long];
  170. Function lo(l : DWord) : Word; [INTERNPROC: fpc_in_lo_long];
  171. Function lo(i : Int64) : DWord; [INTERNPROC: fpc_in_lo_qword];
  172. Function lo(q : QWord) : DWord; [INTERNPROC: fpc_in_lo_qword];
  173. Function hi(i : Integer) : byte; [INTERNPROC: fpc_in_hi_Word];
  174. Function hi(w : Word) : byte; [INTERNPROC: fpc_in_hi_Word];
  175. Function hi(l : Longint) : Word; [INTERNPROC: fpc_in_hi_long];
  176. Function hi(l : DWord) : Word; [INTERNPROC: fpc_in_hi_long];
  177. Function hi(i : Int64) : DWord; [INTERNPROC: fpc_in_hi_qword];
  178. Function hi(q : QWord) : DWord; [INTERNPROC: fpc_in_hi_qword];
  179. Function chr(b : byte) : AnsiChar; [INTERNPROC: fpc_in_chr_byte];
  180. function RorByte(Const AValue : Byte): Byte;[internproc:fpc_in_ror_x];
  181. function RorByte(Const AValue : Byte;Dist : Byte): Byte;[internproc:fpc_in_ror_x_x];
  182. function RolByte(Const AValue : Byte): Byte;[internproc:fpc_in_rol_x];
  183. function RolByte(Const AValue : Byte;Dist : Byte): Byte;[internproc:fpc_in_rol_x_x];
  184. function RorWord(Const AValue : Word): Word;[internproc:fpc_in_ror_x];
  185. function RorWord(Const AValue : Word;Dist : Byte): Word;[internproc:fpc_in_ror_x_x];
  186. function RolWord(Const AValue : Word): Word;[internproc:fpc_in_rol_x];
  187. function RolWord(Const AValue : Word;Dist : Byte): Word;[internproc:fpc_in_rol_x_x];
  188. function RorDWord(Const AValue : DWord): DWord;[internproc:fpc_in_ror_x];
  189. function RorDWord(Const AValue : DWord;Dist : Byte): DWord;[internproc:fpc_in_ror_x_x];
  190. function RolDWord(Const AValue : DWord): DWord;[internproc:fpc_in_rol_x];
  191. function RolDWord(Const AValue : DWord;Dist : Byte): DWord;[internproc:fpc_in_rol_x_x];
  192. function RorQWord(Const AValue : QWord): QWord;[internproc:fpc_in_ror_x];
  193. function RorQWord(Const AValue : QWord;Dist : Byte): QWord;[internproc:fpc_in_ror_x_x];
  194. function RolQWord(Const AValue : QWord): QWord;[internproc:fpc_in_rol_x];
  195. function RolQWord(Const AValue : QWord;Dist : Byte): QWord;[internproc:fpc_in_rol_x_x];
  196. function SarShortint(Const AValue : Shortint): Shortint;[internproc:fpc_in_sar_x];
  197. function SarShortint(Const AValue : Shortint;Shift : Byte): Shortint;[internproc:fpc_in_sar_x_y];
  198. function SarSmallint(Const AValue : Smallint): Smallint;[internproc:fpc_in_sar_x];
  199. function SarSmallint(Const AValue : Smallint;Shift : Byte): Smallint;[internproc:fpc_in_sar_x_y];
  200. function SarLongint(Const AValue : Longint): Longint;[internproc:fpc_in_sar_x];
  201. function SarLongint(Const AValue : Longint;Shift : Byte): Longint;[internproc:fpc_in_sar_x_y];
  202. function SarInt64(Const AValue : Int64): Int64;[internproc:fpc_in_sar_x];
  203. function SarInt64(Const AValue : Int64;Shift : Byte): Int64;[internproc:fpc_in_sar_x_y];
  204. {$i compproc.inc}
  205. {$i ustringh.inc}
  206. {*****************************************************************************}
  207. implementation
  208. {*****************************************************************************}
  209. {i jdynarr.inc}
  210. {
  211. This file is part of the Free Pascal run time library.
  212. Copyright (c) 2011 by Jonas Maebe
  213. member of the Free Pascal development team.
  214. This file implements the helper routines for dyn. Arrays in FPC
  215. See the file COPYING.FPC, included in this distribution,
  216. for details about the copyright.
  217. This program is distributed in the hope that it will be useful,
  218. but WITHOUT ANY WARRANTY; without even the implied warranty of
  219. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  220. **********************************************************************
  221. }
  222. function min(a,b : longint) : longint;
  223. begin
  224. if a<=b then
  225. min:=a
  226. else
  227. min:=b;
  228. end;
  229. Procedure HandleError (Errno : longint); forward;
  230. {$i sstrings.inc}
  231. {$i astrings.inc}
  232. {$i ustrings.inc}
  233. {$i rtti.inc}
  234. {$i jrec.inc}
  235. {$i jset.inc}
  236. {$i jint64.inc}
  237. {$i jpvar.inc}
  238. {$i jmath.inc}
  239. {$i genmath.inc}
  240. { copying helpers }
  241. procedure fpc_copy_shallow_array(src, dst: JLObject; srcstart: jint = -1; srccopylen: jint = -1);
  242. var
  243. srclen, dstlen: jint;
  244. begin
  245. if assigned(src) then
  246. srclen:=JLRArray.getLength(src)
  247. else
  248. srclen:=0;
  249. if assigned(dst) then
  250. dstlen:=JLRArray.getLength(dst)
  251. else
  252. dstlen:=0;
  253. if srcstart=-1 then
  254. srcstart:=0
  255. else if srcstart>=srclen then
  256. exit;
  257. if srccopylen=-1 then
  258. srccopylen:=srclen
  259. else if srcstart+srccopylen>srclen then
  260. srccopylen:=srclen-srcstart;
  261. { causes exception in JLSystem.arraycopy }
  262. if (srccopylen=0) or
  263. (dstlen=0) then
  264. exit;
  265. JLSystem.arraycopy(src,srcstart,dst,0,min(srccopylen,dstlen));
  266. end;
  267. procedure fpc_copy_jrecord_array(src, dst: TJRecordArray; srcstart: jint = -1; srccopylen: jint = -1);
  268. var
  269. i: longint;
  270. srclen, dstlen: jint;
  271. begin
  272. srclen:=length(src);
  273. dstlen:=length(dst);
  274. if srcstart=-1 then
  275. srcstart:=0
  276. else if srcstart>=srclen then
  277. exit;
  278. if srccopylen=-1 then
  279. srccopylen:=srclen
  280. else if srcstart+srccopylen>srclen then
  281. srccopylen:=srclen-srcstart;
  282. { no arraycopy, have to clone each element }
  283. for i:=0 to min(srccopylen,dstlen)-1 do
  284. src[srcstart+i].fpcDeepCopy(dst[i]);
  285. end;
  286. procedure fpc_copy_jenumset_array(src, dst: TJEnumSetArray; srcstart: jint = -1; srccopylen: jint = -1);
  287. var
  288. i: longint;
  289. srclen, dstlen: jint;
  290. begin
  291. srclen:=length(src);
  292. dstlen:=length(dst);
  293. if srcstart=-1 then
  294. srcstart:=0
  295. else if srcstart>=srclen then
  296. exit;
  297. if srccopylen=-1 then
  298. srccopylen:=srclen
  299. else if srcstart+srccopylen>srclen then
  300. srccopylen:=srclen-srcstart;
  301. { no arraycopy, have to clone each element }
  302. for i:=0 to min(srccopylen,dstlen)-1 do
  303. begin
  304. dst[i].clear;
  305. dst[i].addAll(src[srcstart+i]);
  306. end;
  307. end;
  308. procedure fpc_copy_jbitset_array(src, dst: TJBitSetArray; srcstart: jint = -1; srccopylen: jint = -1);
  309. var
  310. i: longint;
  311. srclen, dstlen: jint;
  312. begin
  313. srclen:=length(src);
  314. dstlen:=length(dst);
  315. if srcstart=-1 then
  316. srcstart:=0
  317. else if srcstart>=srclen then
  318. exit;
  319. if srccopylen=-1 then
  320. srccopylen:=srclen
  321. else if srcstart+srccopylen>srclen then
  322. srccopylen:=srclen-srcstart;
  323. { no arraycopy, have to clone each element }
  324. for i:=0 to min(srccopylen,dstlen)-1 do
  325. begin
  326. dst[i].clear;
  327. dst[i].addAll(src[srcstart+i]);
  328. end;
  329. end;
  330. procedure fpc_copy_jprocvar_array(src, dst: TJProcVarArray; srcstart: jint = -1; srccopylen: jint = -1);
  331. var
  332. i: longint;
  333. srclen, dstlen: jint;
  334. begin
  335. srclen:=length(src);
  336. dstlen:=length(dst);
  337. if srcstart=-1 then
  338. srcstart:=0
  339. else if srcstart>=srclen then
  340. exit;
  341. if srccopylen=-1 then
  342. srccopylen:=srclen
  343. else if srcstart+srccopylen>srclen then
  344. srccopylen:=srclen-srcstart;
  345. { no arraycopy, have to clone each element }
  346. for i:=0 to min(srccopylen,dstlen)-1 do
  347. src[srcstart+i].fpcDeepCopy(dst[i]);
  348. end;
  349. procedure fpc_copy_jshortstring_array(src, dst: TShortstringArray; srcstart: jint = -1; srccopylen: jint = -1);
  350. var
  351. i: longint;
  352. srclen, dstlen: jint;
  353. begin
  354. srclen:=length(src);
  355. dstlen:=length(dst);
  356. if srcstart=-1 then
  357. srcstart:=0
  358. else if srcstart>=srclen then
  359. exit;
  360. if srccopylen=-1 then
  361. srccopylen:=srclen
  362. else if srcstart+srccopylen>srclen then
  363. srccopylen:=srclen-srcstart;
  364. { no arraycopy, have to clone each element }
  365. for i:=0 to min(srccopylen,dstlen)-1 do
  366. pshortstring(src[srcstart+i])^:=pshortstring(dst[i])^;
  367. end;
  368. { 1-dimensional setlength routines }
  369. function fpc_setlength_dynarr_generic(aorg, anew: JLObject; deepcopy: boolean; docopy: boolean = true): JLObject;
  370. var
  371. orglen, newlen: jint;
  372. begin
  373. orglen:=0;
  374. newlen:=0;
  375. if not deepcopy then
  376. begin
  377. if assigned(aorg) then
  378. orglen:=JLRArray.getLength(aorg)
  379. else
  380. orglen:=0;
  381. if assigned(anew) then
  382. newlen:=JLRArray.getLength(anew)
  383. else
  384. newlen:=0;
  385. end;
  386. if deepcopy or
  387. (orglen<>newlen) then
  388. begin
  389. if docopy then
  390. fpc_copy_shallow_array(aorg,anew);
  391. result:=anew
  392. end
  393. else
  394. result:=aorg;
  395. end;
  396. function fpc_setlength_dynarr_jrecord(aorg, anew: TJRecordArray; deepcopy: boolean): TJRecordArray;
  397. begin
  398. if deepcopy or
  399. (length(aorg)<>length(anew)) then
  400. begin
  401. fpc_copy_jrecord_array(aorg,anew);
  402. result:=anew
  403. end
  404. else
  405. result:=aorg;
  406. end;
  407. function fpc_setlength_dynarr_jenumset(aorg, anew: TJEnumSetArray; deepcopy: boolean): TJEnumSetArray;
  408. begin
  409. if deepcopy or
  410. (length(aorg)<>length(anew)) then
  411. begin
  412. fpc_copy_jenumset_array(aorg,anew);
  413. result:=anew
  414. end
  415. else
  416. result:=aorg;
  417. end;
  418. function fpc_setlength_dynarr_jbitset(aorg, anew: TJBitSetArray; deepcopy: boolean): TJBitSetArray;
  419. begin
  420. if deepcopy or
  421. (length(aorg)<>length(anew)) then
  422. begin
  423. fpc_copy_jbitset_array(aorg,anew);
  424. result:=anew
  425. end
  426. else
  427. result:=aorg;
  428. end;
  429. function fpc_setlength_dynarr_jprocvar(aorg, anew: TJProcVarArray; deepcopy: boolean): TJProcVarArray;
  430. begin
  431. if deepcopy or
  432. (length(aorg)<>length(anew)) then
  433. begin
  434. fpc_copy_jprocvar_array(aorg,anew);
  435. result:=anew
  436. end
  437. else
  438. result:=aorg;
  439. end;
  440. function fpc_setlength_dynarr_jshortstring(aorg, anew: TShortstringArray; deepcopy: boolean): TShortstringArray;
  441. begin
  442. if deepcopy or
  443. (length(aorg)<>length(anew)) then
  444. begin
  445. fpc_copy_jshortstring_array(aorg,anew);
  446. result:=anew
  447. end
  448. else
  449. result:=aorg;
  450. end;
  451. { multi-dimensional setlength routine }
  452. function fpc_setlength_dynarr_multidim(aorg, anew: TJObjectArray; deepcopy: boolean; ndim: longint; eletype: jchar): TJObjectArray;
  453. var
  454. partdone,
  455. i: longint;
  456. begin
  457. { resize the current dimension; no need to copy the subarrays of the old
  458. array, as the subarrays will be (re-)initialised immediately below }
  459. { the srcstart/srccopylen always refers to the first dimension (since copy()
  460. performs a shallow copy of a dynamic array }
  461. result:=TJObjectArray(fpc_setlength_dynarr_generic(JLObject(aorg),JLObject(anew),deepcopy,false));
  462. { if aorg was empty, there's nothing else to do since result will now
  463. contain anew, of which all other dimensions are already initialised
  464. correctly since there are no aorg elements to copy }
  465. if not assigned(aorg) and
  466. not deepcopy then
  467. exit;
  468. partdone:=min(high(result),high(aorg));
  469. { ndim must be >=2 when this routine is called, since it has to return
  470. an array of java.lang.Object! (arrays are also objects, but primitive
  471. types are not) }
  472. if ndim=2 then
  473. begin
  474. { final dimension -> copy the primitive arrays }
  475. case eletype of
  476. FPCJDynArrTypeRecord:
  477. begin
  478. for i:=low(result) to partdone do
  479. result[i]:=JLObject(fpc_setlength_dynarr_jrecord(TJRecordArray(aorg[i]),TJRecordArray(anew[i]),deepcopy));
  480. for i:=succ(partdone) to high(result) do
  481. result[i]:=JLObject(fpc_setlength_dynarr_jrecord(nil,TJRecordArray(anew[i]),deepcopy));
  482. end;
  483. FPCJDynArrTypeEnumSet:
  484. begin
  485. for i:=low(result) to partdone do
  486. result[i]:=JLObject(fpc_setlength_dynarr_jenumset(TJEnumSetArray(aorg[i]),TJEnumSetArray(anew[i]),deepcopy));
  487. for i:=succ(partdone) to high(result) do
  488. result[i]:=JLObject(fpc_setlength_dynarr_jenumset(nil,TJEnumSetArray(anew[i]),deepcopy));
  489. end;
  490. FPCJDynArrTypeBitSet:
  491. begin
  492. for i:=low(result) to partdone do
  493. result[i]:=JLObject(fpc_setlength_dynarr_jbitset(TJBitSetArray(aorg[i]),TJBitSetArray(anew[i]),deepcopy));
  494. for i:=succ(partdone) to high(result) do
  495. result[i]:=JLObject(fpc_setlength_dynarr_jbitset(nil,TJBitSetArray(anew[i]),deepcopy));
  496. end;
  497. FPCJDynArrTypeProcVar:
  498. begin
  499. for i:=low(result) to partdone do
  500. result[i]:=JLObject(fpc_setlength_dynarr_jprocvar(TJProcVarArray(aorg[i]),TJProcVarArray(anew[i]),deepcopy));
  501. for i:=succ(partdone) to high(result) do
  502. result[i]:=JLObject(fpc_setlength_dynarr_jprocvar(nil,TJProcVarArray(anew[i]),deepcopy));
  503. end;
  504. FPCJDynArrTypeShortstring:
  505. begin
  506. for i:=low(result) to partdone do
  507. result[i]:=JLObject(fpc_setlength_dynarr_jshortstring(TShortstringArray(aorg[i]),TShortstringArray(anew[i]),deepcopy));
  508. for i:=succ(partdone) to high(result) do
  509. result[i]:=JLObject(fpc_setlength_dynarr_jshortstring(nil,TShortstringArray(anew[i]),deepcopy));
  510. end;
  511. else
  512. begin
  513. for i:=low(result) to partdone do
  514. result[i]:=fpc_setlength_dynarr_generic(aorg[i],anew[i],deepcopy);
  515. for i:=succ(partdone) to high(result) do
  516. result[i]:=fpc_setlength_dynarr_generic(nil,anew[i],deepcopy);
  517. end;
  518. end;
  519. end
  520. else
  521. begin
  522. { recursively handle the next dimension }
  523. for i:=low(result) to partdone do
  524. result[i]:=JLObject(fpc_setlength_dynarr_multidim(TJObjectArray(aorg[i]),TJObjectArray(anew[i]),deepcopy,pred(ndim),eletype));
  525. for i:=succ(partdone) to high(result) do
  526. result[i]:=JLObject(fpc_setlength_dynarr_multidim(nil,TJObjectArray(anew[i]),deepcopy,pred(ndim),eletype));
  527. end;
  528. end;
  529. function fpc_dynarray_copy(src: JLObject; start, len: longint; ndim: longint; eletype: jchar): JLObject;
  530. var
  531. i: longint;
  532. srclen: longint;
  533. begin
  534. if not assigned(src) then
  535. begin
  536. result:=nil;
  537. exit;
  538. end;
  539. srclen:=JLRArray.getLength(src);
  540. if (start=-1) and
  541. (len=-1) then
  542. begin
  543. len:=srclen;
  544. start:=0;
  545. end
  546. else if (start+len>srclen) then
  547. len:=srclen-start+1;
  548. result:=JLRArray.newInstance(src.getClass.getComponentType,len);
  549. if ndim=1 then
  550. begin
  551. case eletype of
  552. FPCJDynArrTypeRecord:
  553. fpc_copy_jrecord_array(TJRecordArray(src),TJRecordArray(result),start,len);
  554. FPCJDynArrTypeEnumSet:
  555. fpc_copy_jenumset_array(TJEnumSetArray(src),TJEnumSetArray(result),start,len);
  556. FPCJDynArrTypeBitSet:
  557. fpc_copy_jbitset_array(TJBitSetArray(src),TJBitSetArray(result),start,len);
  558. FPCJDynArrTypeProcvar:
  559. fpc_copy_jprocvar_array(TJProcVarArray(src),TJProcVarArray(result),start,len);
  560. FPCJDynArrTypeShortstring:
  561. fpc_copy_jshortstring_array(TShortstringArray(src),TShortstringArray(result),start,len);
  562. else
  563. fpc_copy_shallow_array(src,result,start,len);
  564. end
  565. end
  566. else
  567. begin
  568. for i:=0 to len-1 do
  569. TJObjectArray(result)[i]:=fpc_dynarray_copy(TJObjectArray(src)[start+i],-1,-1,ndim-1,eletype);
  570. end;
  571. end;
  572. {i jdynarr.inc end}
  573. {*****************************************************************************
  574. Things from system.inc
  575. *****************************************************************************}
  576. Procedure HandleError (Errno : longint);[public,alias : 'FPC_HANDLEERROR'];
  577. {
  578. Procedure to handle internal errors, i.e. not user-invoked errors
  579. Internal function should ALWAYS call HandleError instead of RunError.
  580. For now this one cannot be intercepted in Java and always simply raise an
  581. exception.
  582. }
  583. begin
  584. raise JLException.Create('Runtime error '+UnicodeString(JLInteger.valueOf(Errno).toString));
  585. end;
  586. {$ifdef SUPPORT_DOUBLE}
  587. operator := (b:real48) d:double;{$ifdef SYSTEMINLINE}inline;{$endif}
  588. begin
  589. D:=real2double(b);
  590. end;
  591. {$endif SUPPORT_DOUBLE}
  592. {*****************************************************************************
  593. Misc. System Dependent Functions
  594. *****************************************************************************}
  595. procedure TObject.Free;
  596. begin
  597. if not DestructorCalled then
  598. begin
  599. DestructorCalled:=true;
  600. Destroy;
  601. end;
  602. end;
  603. destructor TObject.Destroy;
  604. begin
  605. end;
  606. procedure TObject.Finalize;
  607. begin
  608. Free;
  609. end;
  610. {*****************************************************************************
  611. SystemUnit Initialization
  612. *****************************************************************************}
  613. end.