123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449 |
- {
- This file is part of the Free Pascal run time library.
- Copyright (c) 2006 by Florian Klaempfl
- member of the Free Pascal development team.
- System unit for embedded systems
- See the file COPYING.FPC, included in this distribution,
- for details about the copyright.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- **********************************************************************}
- Unit system;
- {*****************************************************************************}
- interface
- {*****************************************************************************}
- {$define FPC_IS_SYSTEM}
- {$I-,Q-,H-,R-,V-}
- {$implicitexceptions off}
- {$mode objfpc}
- {$undef FPC_HAS_FEATURE_RTTI}
- Type
- { The compiler has all integer types defined internally. Here
- we define only aliases }
- DWord = LongWord;
- Cardinal = LongWord;
- Integer = SmallInt;
- UInt64 = QWord;
-
- ValReal = Double;
-
- { map comp to int64, }
- Comp = Int64;
- HResult = type longint;
- { Java primitive types }
- jboolean = boolean;
- jbyte = shortint;
- jshort = smallint;
- jint = longint;
- jlong = int64;
- jchar = widechar;
- jfloat = single;
- jdouble = double;
- Arr1jboolean = array of jboolean;
- Arr1jbyte = array of jbyte;
- Arr1jshort = array of jshort;
- Arr1jint = array of jint;
- Arr1jlong = array of jlong;
- Arr1jchar = array of jchar;
- Arr1jfloat = array of jfloat;
- Arr1jdouble = array of jdouble;
- Arr2jboolean = array of Arr1jboolean;
- Arr2jbyte = array of Arr1jbyte;
- Arr2jshort = array of Arr1jshort;
- Arr2jint = array of Arr1jint;
- Arr2jlong = array of Arr1jlong;
- Arr2jchar = array of Arr1jchar;
- Arr2jfloat = array of Arr1jfloat;
- Arr2jdouble = array of Arr1jdouble;
- Arr3jboolean = array of Arr2jboolean;
- Arr3jbyte = array of Arr2jbyte;
- Arr3jshort = array of Arr2jshort;
- Arr3jint = array of Arr2jint;
- Arr3jlong = array of Arr2jlong;
- Arr3jchar = array of Arr2jchar;
- Arr3jfloat = array of Arr2jfloat;
- Arr3jdouble = array of Arr2jdouble;
- const
- { max. values for longint and int}
- maxLongint = $7fffffff;
- maxSmallint = 32767;
- maxint = maxsmallint;
- type
- { Java base class type }
- TObject = class external 'java.lang' name 'Object'
- protected
- function clone: TObject;
- public
- constructor create;
- function equals(obj: TObject): boolean;
- function hashcode: longint;
- end;
- TJLObject = TObject;
- TJISerializable = interface external 'java.lang' name 'Serializable'
- end;
- TJLThrowable = class external 'java.lang' name 'Throwable' (TObject,TJISerializable)
- constructor create;
- end;
- { Java Float class type }
- TJFloat = class external 'java.lang' name 'Float'
- constructor create(f: jfloat);
- class function floatToRawIntBits(f: jfloat): jint; static;
- class function intBitsToFloat(j: jint): jfloat; static;
- end;
- { Java Dloat class type }
- TJDouble = class external 'java.lang' name 'Double'
- constructor create(d: jdouble);
- class function doubleToRawLongBits(d: jdouble): jlong; static;
- class function longBitsToDouble(l: jlong): jdouble; static;
- end;
- {$i innr.inc}
- {$i jmathh.inc}
- {$i jdynarrh.inc}
- {$i compproc.inc}
- {*****************************************************************************}
- implementation
- {*****************************************************************************}
- {i jdynarr.inc}
- {
- This file is part of the Free Pascal run time library.
- Copyright (c) 2011 by Jonas Maebe
- member of the Free Pascal development team.
- This file implements the helper routines for dyn. Arrays in FPC
- See the file COPYING.FPC, included in this distribution,
- for details about the copyright.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- **********************************************************************
- }
- {$i rtti.inc}
- function min(a,b : longint) : longint;
- begin
- if a<=b then
- min:=a
- else
- min:=b;
- end;
- { copying helpers }
- { also for booleans }
- procedure fpc_copy_jbyte_array(src, dst: TJByteArray);
- var
- i: longint;
- begin
- for i:=0 to min(high(src),high(dst)) do
- dst[i]:=src[i];
- end;
- procedure fpc_copy_jshort_array(src, dst: TJShortArray);
- var
- i: longint;
- begin
- for i:=0 to min(high(src),high(dst)) do
- dst[i]:=src[i];
- end;
- procedure fpc_copy_jint_array(src, dst: TJIntArray);
- var
- i: longint;
- begin
- for i:=0 to min(high(src),high(dst)) do
- dst[i]:=src[i];
- end;
- procedure fpc_copy_jlong_array(src, dst: TJLongArray);
- var
- i: longint;
- begin
- for i:=0 to min(high(src),high(dst)) do
- dst[i]:=src[i];
- end;
- procedure fpc_copy_jchar_array(src, dst: TJCharArray);
- var
- i: longint;
- begin
- for i:=0 to min(high(src),high(dst)) do
- dst[i]:=src[i];
- end;
- procedure fpc_copy_jfloat_array(src, dst: TJFloatArray);
- var
- i: longint;
- begin
- for i:=0 to min(high(src),high(dst)) do
- dst[i]:=src[i];
- end;
- procedure fpc_copy_jdouble_array(src, dst: TJDoubleArray);
- var
- i: longint;
- begin
- for i:=0 to min(high(src),high(dst)) do
- dst[i]:=src[i];
- end;
- procedure fpc_copy_jobject_array(src, dst: TJObjectArray);
- var
- i: longint;
- begin
- for i:=0 to min(high(src),high(dst)) do
- dst[i]:=src[i];
- end;
- { 1-dimensional setlength routines }
- function fpc_setlength_dynarr_jbyte(aorg, anew: TJByteArray; deepcopy: boolean): TJByteArray;
- begin
- if deepcopy or
- (length(aorg)<>length(anew)) then
- begin
- fpc_copy_jbyte_array(aorg,anew);
- result:=anew
- end
- else
- result:=aorg;
- end;
- function fpc_setlength_dynarr_jshort(aorg, anew: TJShortArray; deepcopy: boolean): TJShortArray;
- begin
- if deepcopy or
- (length(aorg)<>length(anew)) then
- begin
- fpc_copy_jshort_array(aorg,anew);
- result:=anew
- end
- else
- result:=aorg;
- end;
- function fpc_setlength_dynarr_jint(aorg, anew: TJIntArray; deepcopy: boolean): TJIntArray;
- begin
- if deepcopy or
- (length(aorg)<>length(anew)) then
- begin
- fpc_copy_jint_array(aorg,anew);
- result:=anew
- end
- else
- result:=aorg;
- end;
- function fpc_setlength_dynarr_jlong(aorg, anew: TJLongArray; deepcopy: boolean): TJLongArray;
- begin
- if deepcopy or
- (length(aorg)<>length(anew)) then
- begin
- fpc_copy_jlong_array(aorg,anew);
- result:=anew
- end
- else
- result:=aorg;
- end;
- function fpc_setlength_dynarr_jchar(aorg, anew: TJCharArray; deepcopy: boolean): TJCharArray;
- begin
- if deepcopy or
- (length(aorg)<>length(anew)) then
- begin
- fpc_copy_jchar_array(aorg,anew);
- result:=anew
- end
- else
- result:=aorg;
- end;
- function fpc_setlength_dynarr_jfloat(aorg, anew: TJFloatArray; deepcopy: boolean): TJFloatArray;
- begin
- if deepcopy or
- (length(aorg)<>length(anew)) then
- begin
- fpc_copy_jfloat_array(aorg,anew);
- result:=anew
- end
- else
- result:=aorg;
- end;
- function fpc_setlength_dynarr_jdouble(aorg, anew: TJDoubleArray; deepcopy: boolean): TJDoubleArray;
- begin
- if deepcopy or
- (length(aorg)<>length(anew)) then
- begin
- fpc_copy_jdouble_array(aorg,anew);
- result:=anew
- end
- else
- result:=aorg;
- end;
- function fpc_setlength_dynarr_jobject(aorg, anew: TJObjectArray; deepcopy: boolean; docopy : boolean = true): TJObjectArray;
- begin
- if deepcopy or
- (length(aorg)<>length(anew)) then
- begin
- if docopy then
- fpc_copy_jobject_array(aorg,anew);
- result:=anew
- end
- else
- result:=aorg;
- end;
- { multi-dimensional setlength routine }
- function fpc_setlength_dynarr_multidim(aorg, anew: TJObjectArray; deepcopy: boolean; ndim: longint; eletype: jchar): TJObjectArray;
- var
- partdone,
- i: longint;
- begin
- { resize the current dimension; no need to copy the subarrays of the old
- array, as the subarrays will be (re-)initialised immediately below }
- result:=fpc_setlength_dynarr_jobject(aorg,anew,deepcopy,false);
- { if aorg was empty, there's nothing else to do since result will now
- contain anew, of which all other dimensions are already initialised
- correctly since there are no aorg elements to copy }
- if not assigned(aorg) and
- not deepcopy then
- exit;
- partdone:=min(high(result),high(aorg));
- { ndim must be >=2 when this routine is called, since it has to return
- an array of java.lang.Object! (arrays are also objects, but primitive
- types are not) }
- if ndim=2 then
- begin
- { final dimension -> copy the primitive arrays }
- case eletype of
- FPCJDynArrTypeJByte:
- begin
- for i:=low(result) to partdone do
- result[i]:=TObject(fpc_setlength_dynarr_jbyte(TJByteArray(aorg[i]),TJByteArray(anew[i]),deepcopy));
- for i:=succ(partdone) to high(result) do
- result[i]:=TObject(fpc_setlength_dynarr_jbyte(nil,TJByteArray(anew[i]),deepcopy));
- end;
- FPCJDynArrTypeJShort:
- begin
- for i:=low(result) to partdone do
- result[i]:=TObject(fpc_setlength_dynarr_jshort(TJShortArray(aorg[i]),TJShortArray(anew[i]),deepcopy));
- for i:=succ(partdone) to high(result) do
- result[i]:=TObject(fpc_setlength_dynarr_jshort(nil,TJShortArray(anew[i]),deepcopy));
- end;
- FPCJDynArrTypeJInt:
- begin
- for i:=low(result) to partdone do
- result[i]:=TObject(fpc_setlength_dynarr_jint(TJIntArray(aorg[i]),TJIntArray(anew[i]),deepcopy));
- for i:=succ(partdone) to high(result) do
- result[i]:=TObject(fpc_setlength_dynarr_jint(nil,TJIntArray(anew[i]),deepcopy));
- end;
- FPCJDynArrTypeJLong:
- begin
- for i:=low(result) to partdone do
- result[i]:=TObject(fpc_setlength_dynarr_jlong(TJLongArray(aorg[i]),TJLongArray(anew[i]),deepcopy));
- for i:=succ(partdone) to high(result) do
- result[i]:=TObject(fpc_setlength_dynarr_jlong(nil,TJLongArray(anew[i]),deepcopy));
- end;
- FPCJDynArrTypeJChar:
- begin
- for i:=low(result) to partdone do
- result[i]:=TObject(fpc_setlength_dynarr_jchar(TJCharArray(aorg[i]),TJCharArray(anew[i]),deepcopy));
- for i:=succ(partdone) to high(result) do
- result[i]:=TObject(fpc_setlength_dynarr_jchar(nil,TJCharArray(anew[i]),deepcopy));
- end;
- FPCJDynArrTypeJFloat:
- begin
- for i:=low(result) to partdone do
- result[i]:=TObject(fpc_setlength_dynarr_jfloat(TJFloatArray(aorg[i]),TJFloatArray(anew[i]),deepcopy));
- for i:=succ(partdone) to high(result) do
- result[i]:=TObject(fpc_setlength_dynarr_jfloat(nil,TJFloatArray(anew[i]),deepcopy));
- end;
- FPCJDynArrTypeJDouble:
- begin
- for i:=low(result) to partdone do
- result[i]:=TObject(fpc_setlength_dynarr_jdouble(TJDoubleArray(aorg[i]),TJDoubleArray(anew[i]),deepcopy));
- for i:=succ(partdone) to high(result) do
- result[i]:=TObject(fpc_setlength_dynarr_jdouble(nil,TJDoubleArray(anew[i]),deepcopy));
- end;
- FPCJDynArrTypeJObject:
- begin
- for i:=low(result) to partdone do
- result[i]:=TObject(fpc_setlength_dynarr_jobject(TJObjectArray(aorg[i]),TJObjectArray(anew[i]),deepcopy,true));
- for i:=succ(partdone) to high(result) do
- result[i]:=TObject(fpc_setlength_dynarr_jobject(nil,TJObjectArray(anew[i]),deepcopy,true));
- end;
- end;
- end
- else
- begin
- { recursively handle the next dimension }
- for i:=low(result) to partdone do
- result[i]:=TObject(fpc_setlength_dynarr_multidim(TJObjectArray(aorg[i]),TJObjectArray(anew[i]),deepcopy,pred(ndim),eletype));
- for i:=succ(partdone) to high(result) do
- result[i]:=TObject(fpc_setlength_dynarr_multidim(nil,TJObjectArray(anew[i]),deepcopy,pred(ndim),eletype));
- end;
- end;
- {i jdynarr.inc end}
- {*****************************************************************************
- Misc. System Dependent Functions
- *****************************************************************************}
- {*****************************************************************************
- SystemUnit Initialization
- *****************************************************************************}
- end.
|