jtcon.inc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2011 by Jonas Maebe,
  4. member of the Free Pascal development team.
  5. This file implements support routines for typed constants for the JVM
  6. platform
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. procedure fpc_tcon_shortint_array_from_string(const s: unicodestring; var arr: array of shortint; startindex, len: longint); compilerproc;
  14. var
  15. i: longint;
  16. c: widechar;
  17. begin
  18. for i:=0 to (len div 2)-1 do
  19. begin
  20. c:=s[i+1];
  21. arr[startindex+i*2]:=shortint(ord(c) shr 8);
  22. arr[startindex+i*2+1]:=shortint(ord(c));
  23. end;
  24. if odd(len) then
  25. arr[startindex+len-1]:=ord(s[len div 2 + 1]) shr 8;
  26. end;
  27. procedure fpc_tcon_smallint_array_from_string(const s: unicodestring; var arr: array of smallint; startindex, len: longint); compilerproc;
  28. var
  29. i: longint;
  30. begin
  31. for i:=0 to len-1 do
  32. arr[startindex+i]:=ord(s[i+1]);
  33. end;
  34. procedure fpc_tcon_longint_array_from_string(const s: unicodestring; var arr: array of longint; startindex, len: longint); compilerproc;
  35. var
  36. i, l: longint;
  37. begin
  38. { TODO: maybe optimize encoding via uleb/sleb }
  39. for i:=0 to len-1 do
  40. begin
  41. l:=ord(s[i*2+1]) shl 16;
  42. l:=l or ord(s[i*2+2]);
  43. arr[startindex+i]:=l;
  44. end;
  45. end;
  46. procedure fpc_tcon_int64_array_from_string(const s: unicodestring; var arr: array of int64; startindex, len: longint); compilerproc;
  47. var
  48. i: longint;
  49. l: int64;
  50. begin
  51. { TODO: maybe optimize encoding via uleb/sleb }
  52. for i:=0 to len-1 do
  53. begin
  54. l:=int64(ord(s[i*4+1])) shl 48;
  55. l:=l or (int64(ord(s[i*4+2])) shl 32);
  56. l:=l or (ord(s[i*4+3]) shl 16);
  57. l:=l or ord(s[i*4+4]);
  58. arr[startindex+i]:=l;
  59. end;
  60. end;
  61. { specifying compilerprocs using an external name doesn't work yet }
  62. procedure fpc_tcon_shortint_array_from_string_intern_as_byte(const s: unicodestring; var arr: array of byte; startindex, len: longint); external name 'fpc_tcon_shortint_array_from_string';
  63. procedure fpc_tcon_ansichar_array_from_string(const s: unicodestring; var arr: array of ansichar; startindex, len: longint); external name 'fpc_tcon_shortint_array_from_string';
  64. procedure fpc_tcon_smallint_array_from_string_intern_as_word(const s: unicodestring; var arr: array of word; startindex, len: longint); external name 'fpc_tcon_smallint_array_from_string';
  65. procedure fpc_tcon_longint_array_from_string_intern_as_cardinal(const s: unicodestring; var arr: array of cardinal; startindex, len: longint); external name 'fpc_tcon_longint_array_from_string';
  66. procedure fpc_tcon_int64_array_from_string_intern_as_int64(const s: unicodestring; var arr: array of qword; startindex, len: longint); external name 'fpc_tcon_int64_array_from_string';
  67. procedure fpc_tcon_byte_array_from_string(const s: unicodestring; var arr: array of byte; startindex, len: longint); compilerproc;
  68. begin
  69. fpc_tcon_shortint_array_from_string_intern_as_byte(s,arr,startindex,len);
  70. end;
  71. procedure fpc_tcon_word_array_from_string(const s: unicodestring; var arr: array of word; startindex, len: longint); compilerproc;
  72. begin
  73. fpc_tcon_smallint_array_from_string_intern_as_word(s,arr,startindex,len);
  74. end;
  75. procedure fpc_tcon_cardinal_array_from_string(const s: unicodestring; var arr: array of cardinal; startindex, len: longint); compilerproc;
  76. begin
  77. fpc_tcon_longint_array_from_string_intern_as_cardinal(s,arr,startindex,len);
  78. end;
  79. procedure fpc_tcon_qword_array_from_string(const s: unicodestring; var arr: array of qword; startindex, len: longint); compilerproc;
  80. begin
  81. fpc_tcon_int64_array_from_string_intern_as_int64(s,arr,startindex,len);
  82. end;