tcalcst2.pp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. {****************************************************************}
  2. { CODE GENERATOR TEST PROGRAM }
  3. { By Carl Eric Codere }
  4. {****************************************************************}
  5. { NODE TESTED : secondcallparan() }
  6. {****************************************************************}
  7. { PRE-REQUISITES: secondload() }
  8. { secondassign() }
  9. { secondtypeconv() }
  10. { secondtryexcept() }
  11. { secondcalln() }
  12. { secondadd() }
  13. {****************************************************************}
  14. { DEFINES: }
  15. { FPC = Target is FreePascal compiler }
  16. {****************************************************************}
  17. { REMARKS: This tests a subset of the secondcalln() node }
  18. { (const parameters) }
  19. {****************************************************************}
  20. program tcalcst2;
  21. {$ifdef fpc}
  22. {$mode objfpc}
  23. {$INLINE ON}
  24. {$endif}
  25. {$R+}
  26. {$ifdef VER70}
  27. {$define tp}
  28. {$endif}
  29. { REAL should map to single or double }
  30. { so it is not checked, since single }
  31. { double nodes are checked. }
  32. { assumes that enumdef is the same as orddef (same storage format) }
  33. const
  34. { should be defined depending on CPU target }
  35. {$ifdef fpc}
  36. {$ifdef cpu68k}
  37. BIG_INDEX = 8000;
  38. SMALL_INDEX = 13;
  39. {$else}
  40. BIG_INDEX = 33000;
  41. SMALL_INDEX = 13; { value should not be aligned! }
  42. {$endif}
  43. {$else}
  44. BIG_INDEX = 33000;
  45. SMALL_INDEX = 13; { value should not be aligned! }
  46. {$endif}
  47. RESULT_U8BIT = $55;
  48. RESULT_U16BIT = $500F;
  49. RESULT_S32BIT = $500F0000;
  50. RESULT_S64BIT = $500F0000;
  51. RESULT_S32REAL = 1777.12;
  52. RESULT_S64REAL = 3444.24;
  53. RESULT_BOOL8BIT = 1;
  54. RESULT_BOOL16BIT = 1;
  55. RESULT_BOOL32BIT = 1;
  56. RESULT_PCHAR = 'Hello world';
  57. RESULT_BIGSTRING = 'Hello world';
  58. RESULT_SMALLSTRING = 'H';
  59. RESULT_CHAR = 'I';
  60. RESULT_BOOLEAN = TRUE;
  61. type
  62. tclass1 = class
  63. end;
  64. tprocedure = procedure;
  65. tsmallrecord =
  66. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  67. packed
  68. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  69. record
  70. b: byte;
  71. w: word;
  72. end;
  73. tlargerecord = packed record
  74. b: array[1..BIG_INDEX] of byte;
  75. end;
  76. tsmallarray = packed array[1..SMALL_INDEX] of byte;
  77. tsmallsetenum =
  78. (A_A,A_B,A_C,A_D);
  79. tsmallset = set of tsmallsetenum;
  80. tlargeset = set of char;
  81. tsmallstring = string[2];
  82. var
  83. global_u8bit : byte;
  84. global_u16bit : word;
  85. global_s32bit : longint;
  86. global_s64bit : int64;
  87. global_s32real : single;
  88. global_s64real : double;
  89. global_ptr : pchar;
  90. global_proc : tprocedure;
  91. global_class : tclass1;
  92. global_bigstring : shortstring;
  93. global_boolean : boolean;
  94. global_char : char;
  95. value_u8bit : byte;
  96. value_u16bit : word;
  97. value_s32bit : longint;
  98. value_s64bit : int64;
  99. value_s32real : single;
  100. value_s64real : double;
  101. value_proc : tprocedure;
  102. value_ptr : pchar;
  103. value_class : tclass1;
  104. value_smallrec : tsmallrecord;
  105. value_largerec : tlargerecord;
  106. value_smallset : tsmallset;
  107. value_smallstring : tsmallstring;
  108. value_bigstring : shortstring;
  109. value_largeset : tlargeset;
  110. value_smallarray : tsmallarray;
  111. value_boolean : boolean;
  112. value_char : char;
  113. procedure fail;
  114. begin
  115. WriteLn('Failure.');
  116. halt(1);
  117. end;
  118. procedure clear_globals;
  119. begin
  120. global_u8bit := 0;
  121. global_u16bit := 0;
  122. global_s32bit := 0;
  123. global_s64bit := 0;
  124. global_s32real := 0.0;
  125. global_s64real := 0.0;
  126. global_ptr := nil;
  127. global_proc := nil;
  128. global_class := nil;
  129. global_bigstring := '';
  130. global_boolean := false;
  131. global_char := #0;
  132. end;
  133. procedure clear_values;
  134. begin
  135. value_u8bit := 0;
  136. value_u16bit := 0;
  137. value_s32bit := 0;
  138. value_s64bit := 0;
  139. value_s32real := 0.0;
  140. value_s64real := 0.0;
  141. value_proc := nil;
  142. value_ptr := nil;
  143. value_class := nil;
  144. fillchar(value_smallrec, sizeof(value_smallrec), #0);
  145. fillchar(value_largerec, sizeof(value_largerec), #0);
  146. value_smallset := [];
  147. value_smallstring := '';
  148. value_bigstring := '';
  149. value_largeset := [];
  150. fillchar(value_smallarray, sizeof(value_smallarray), #0);
  151. value_boolean := false;
  152. value_char:=#0;
  153. end;
  154. procedure testprocedure;
  155. begin
  156. end;
  157. function getu8bit : byte;
  158. begin
  159. getu8bit:=RESULT_U8BIT;
  160. end;
  161. function getu16bit: word;
  162. begin
  163. getu16bit:=RESULT_U16BIT;
  164. end;
  165. function gets32bit: longint;
  166. begin
  167. gets32bit:=RESULT_S32BIT;
  168. end;
  169. function gets64bit: int64;
  170. begin
  171. gets64bit:=RESULT_S64BIT;
  172. end;
  173. function gets32real: single;
  174. begin
  175. gets32real:=RESULT_S32REAL;
  176. end;
  177. function gets64real: double;
  178. begin
  179. gets64real:=RESULT_S64REAL;
  180. end;
  181. {************************************************************************}
  182. { CONST PARAMETERS (INLINE) }
  183. {************************************************************************}
  184. procedure proc_const_smallrecord_inline(const smallrec : tsmallrecord);inline;
  185. begin
  186. if (smallrec.b = RESULT_U8BIT) and (smallrec.w = RESULT_U16BIT) then
  187. global_u8bit := RESULT_U8BIT;
  188. end;
  189. procedure proc_const_largerecord_inline(const largerec : tlargerecord);inline;
  190. begin
  191. if (largerec.b[1] = RESULT_U8BIT) and (largerec.b[2] = RESULT_U8BIT) then
  192. global_u8bit := RESULT_U8BIT;
  193. end;
  194. procedure proc_const_smallset_inline(const smallset : tsmallset);inline;
  195. begin
  196. if A_D in smallset then
  197. global_u8bit := RESULT_U8BIT;
  198. end;
  199. procedure proc_const_largeset_inline(const largeset : tlargeset);inline;
  200. begin
  201. if 'I' in largeset then
  202. global_u8bit := RESULT_U8BIT;
  203. end;
  204. procedure proc_const_smallstring_inline(const s:tsmallstring);inline;
  205. begin
  206. if s = RESULT_SMALLSTRING then
  207. global_u8bit := RESULT_u8BIT;
  208. end;
  209. procedure proc_const_bigstring_inline(const s:shortstring);inline;
  210. begin
  211. if s = RESULT_BIGSTRING then
  212. global_u8bit := RESULT_u8BIT;
  213. end;
  214. procedure proc_const_smallarray_inline(const arr : tsmallarray);inline;
  215. begin
  216. if arr[SMALL_INDEX] = RESULT_U8BIT then
  217. global_u8bit := RESULT_U8BIT;
  218. end;
  219. procedure proc_const_smallarray_open_inline(const arr : array of byte);inline;
  220. begin
  221. { form 0 to N-1 indexes in open arrays }
  222. if arr[SMALL_INDEX-1] = RESULT_U8BIT then
  223. global_u8bit := RESULT_U8BIT;
  224. end;
  225. procedure proc_const_smallarray_const_1_inline(const arr : array of const);inline;
  226. var
  227. i: integer;
  228. begin
  229. global_u8bit := arr[0].vinteger and $ff;
  230. global_ptr := arr[1].VPchar;
  231. global_s64bit := arr[2].vInt64^;
  232. global_char := arr[3].vchar;
  233. global_bigstring := arr[4].VString^;
  234. global_s64real := arr[5].VExtended^;
  235. global_boolean := arr[6].vboolean;
  236. (*
  237. for i:=0 to high(arr) do
  238. begin
  239. case arr[i].vtype of
  240. vtInteger : global_u8bit := arr[i].vinteger and $ff;
  241. vtBoolean : global_boolean := arr[i].vboolean;
  242. vtChar : global_char := arr[i].vchar;
  243. vtExtended : global_s64real := arr[i].VExtended^;
  244. vtString : global_bigstring := arr[i].VString^;
  245. vtPointer : ;
  246. vtPChar : global_ptr := arr[i].VPchar;
  247. vtObject : ;
  248. { vtClass : global_class := tclass1(arr[i].VClass);}
  249. vtAnsiString : ;
  250. vtInt64 : global_s64bit := arr[i].vInt64^;
  251. else
  252. RunError(255);
  253. end;
  254. end; {endfor}
  255. *)
  256. end;
  257. procedure proc_const_smallarray_const_2_inline(const arr : array of const);inline;
  258. var
  259. i: integer;
  260. begin
  261. if high(arr)<0 then
  262. global_u8bit := RESULT_U8BIT;
  263. end;
  264. procedure proc_const_formaldef_array_inline(const buf);inline;
  265. var
  266. p: pchar;
  267. begin
  268. { array is indexed from 1 }
  269. p := @buf;
  270. global_u8bit := byte(p[SMALL_INDEX-1]);
  271. end;
  272. var
  273. failed: boolean;
  274. pp : ^pchar;
  275. begin
  276. {***************************** INLINE TESTS *******************************}
  277. write('(Inline) const parameter test (src : LOC_REFERENCE (recorddef)))...');
  278. clear_globals;
  279. clear_values;
  280. failed := false;
  281. value_smallrec.b := RESULT_U8BIT;
  282. value_smallrec.w := RESULT_U16BIT;
  283. proc_const_smallrecord_inline(value_smallrec);
  284. if global_u8bit <> RESULT_U8BIT then
  285. failed := true;
  286. clear_globals;
  287. clear_values;
  288. fillchar(value_largerec,sizeof(value_largerec),RESULT_U8BIT);
  289. proc_const_largerecord_inline(value_largerec);
  290. if global_u8bit <> RESULT_U8BIT then
  291. failed := true;
  292. if failed then
  293. fail
  294. else
  295. WriteLn('Passed!');
  296. write('(Inline) const parameter test (src : LOC_REFERENCE (setdef)))...');
  297. clear_globals;
  298. clear_values;
  299. failed := false;
  300. value_smallset := [A_A,A_D];
  301. proc_const_smallset_inline(value_smallset);
  302. if global_u8bit <> RESULT_U8BIT then
  303. failed := true;
  304. clear_globals;
  305. clear_values;
  306. value_largeset := ['I'];
  307. proc_const_largeset_inline(value_largeset);
  308. if global_u8bit <> RESULT_U8BIT then
  309. failed := true;
  310. if failed then
  311. fail
  312. else
  313. WriteLn('Passed!');
  314. clear_globals;
  315. clear_values;
  316. write('(Inline) const parameter test (src : LOC_REFERENCE (stringdef)))...');
  317. failed := false;
  318. value_smallstring := RESULT_SMALLSTRING;
  319. proc_const_smallstring_inline(value_smallstring);
  320. if global_u8bit <> RESULT_U8BIT then
  321. failed := true;
  322. clear_globals;
  323. clear_values;
  324. value_bigstring := RESULT_BIGSTRING;
  325. proc_const_bigstring_inline(value_bigstring);
  326. if global_u8bit <> RESULT_U8BIT then
  327. failed := true;
  328. if failed then
  329. fail
  330. else
  331. WriteLn('Passed!');
  332. write('(Inline) Const parameter test (src : LOC_REFERENCE (formaldef)))...');
  333. clear_globals;
  334. clear_values;
  335. failed:=false;
  336. value_smallarray[SMALL_INDEX] := RESULT_U8BIT;
  337. proc_const_formaldef_array_inline(value_smallarray);
  338. if global_u8bit <> RESULT_U8BIT then
  339. failed := true;
  340. if failed then
  341. fail
  342. else
  343. WriteLn('Passed!');
  344. write('Inline const parameter test (src : LOC_REFERENCE (arraydef)))...');
  345. clear_globals;
  346. clear_values;
  347. failed:=false;
  348. value_smallarray[SMALL_INDEX] := RESULT_U8BIT;
  349. proc_const_smallarray_inline(value_smallarray);
  350. if global_u8bit <> RESULT_U8BIT then
  351. failed := true;
  352. clear_globals;
  353. clear_values;
  354. value_smallarray[SMALL_INDEX] := RESULT_U8BIT;
  355. proc_const_smallarray_open_inline(value_smallarray);
  356. if global_u8bit <> RESULT_U8BIT then
  357. failed := true;
  358. clear_globals;
  359. clear_values;
  360. value_u8bit := RESULT_U8BIT;
  361. value_ptr := RESULT_PCHAR;
  362. value_s64bit := RESULT_S64BIT;
  363. value_smallstring := RESULT_SMALLSTRING;
  364. value_class := tclass1.create;
  365. value_boolean := RESULT_BOOLEAN;
  366. value_char := RESULT_CHAR;
  367. value_s64real:=RESULT_S64REAL;
  368. proc_const_smallarray_const_1_inline([value_u8bit,value_ptr,value_s64bit,value_char,value_smallstring,value_s64real,value_boolean,value_class]);
  369. if global_u8bit <> RESULT_U8BIT then
  370. failed := true;
  371. if global_char <> RESULT_CHAR then
  372. failed := true;
  373. if global_boolean <> RESULT_BOOLEAN then
  374. failed:=true;
  375. if trunc(global_s64real) <> trunc(RESULT_S64REAL) then
  376. failed := true;
  377. if global_bigstring <> RESULT_SMALLSTRING then
  378. failed := true;
  379. if global_ptr <> value_ptr then
  380. failed := true;
  381. { if value_class <> global_class then
  382. failed := true;!!!!!!!!!!!!!!!!!!!!}
  383. if global_s64bit <> RESULT_S64BIT then
  384. failed := true;
  385. if assigned(value_class) then
  386. value_class.destroy;
  387. global_u8bit := 0;
  388. proc_const_smallarray_const_2_inline([]);
  389. if global_u8bit <> RESULT_U8BIT then
  390. failed := true;
  391. if failed then
  392. fail
  393. else
  394. WriteLn('Passed!');
  395. end.