tcalcst2.pp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  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 = packed record
  66. b: byte;
  67. w: word;
  68. end;
  69. tlargerecord = packed record
  70. b: array[1..BIG_INDEX] of byte;
  71. end;
  72. tsmallarray = packed array[1..SMALL_INDEX] of byte;
  73. tsmallsetenum =
  74. (A_A,A_B,A_C,A_D);
  75. tsmallset = set of tsmallsetenum;
  76. tlargeset = set of char;
  77. tsmallstring = string[2];
  78. var
  79. global_u8bit : byte;
  80. global_u16bit : word;
  81. global_s32bit : longint;
  82. global_s64bit : int64;
  83. global_s32real : single;
  84. global_s64real : double;
  85. global_ptr : pchar;
  86. global_proc : tprocedure;
  87. global_class : tclass1;
  88. global_bigstring : shortstring;
  89. global_boolean : boolean;
  90. global_char : char;
  91. value_u8bit : byte;
  92. value_u16bit : word;
  93. value_s32bit : longint;
  94. value_s64bit : int64;
  95. value_s32real : single;
  96. value_s64real : double;
  97. value_proc : tprocedure;
  98. value_ptr : pchar;
  99. value_class : tclass1;
  100. value_smallrec : tsmallrecord;
  101. value_largerec : tlargerecord;
  102. value_smallset : tsmallset;
  103. value_smallstring : tsmallstring;
  104. value_bigstring : shortstring;
  105. value_largeset : tlargeset;
  106. value_smallarray : tsmallarray;
  107. value_boolean : boolean;
  108. value_char : char;
  109. procedure fail;
  110. begin
  111. WriteLn('Failure.');
  112. halt(1);
  113. end;
  114. procedure clear_globals;
  115. begin
  116. global_u8bit := 0;
  117. global_u16bit := 0;
  118. global_s32bit := 0;
  119. global_s64bit := 0;
  120. global_s32real := 0.0;
  121. global_s64real := 0.0;
  122. global_ptr := nil;
  123. global_proc := nil;
  124. global_class := nil;
  125. global_bigstring := '';
  126. global_boolean := false;
  127. global_char := #0;
  128. end;
  129. procedure clear_values;
  130. begin
  131. value_u8bit := 0;
  132. value_u16bit := 0;
  133. value_s32bit := 0;
  134. value_s64bit := 0;
  135. value_s32real := 0.0;
  136. value_s64real := 0.0;
  137. value_proc := nil;
  138. value_ptr := nil;
  139. value_class := nil;
  140. fillchar(value_smallrec, sizeof(value_smallrec), #0);
  141. fillchar(value_largerec, sizeof(value_largerec), #0);
  142. value_smallset := [];
  143. value_smallstring := '';
  144. value_bigstring := '';
  145. value_largeset := [];
  146. fillchar(value_smallarray, sizeof(value_smallarray), #0);
  147. value_boolean := false;
  148. value_char:=#0;
  149. end;
  150. procedure testprocedure;
  151. begin
  152. end;
  153. function getu8bit : byte;
  154. begin
  155. getu8bit:=RESULT_U8BIT;
  156. end;
  157. function getu16bit: word;
  158. begin
  159. getu16bit:=RESULT_U16BIT;
  160. end;
  161. function gets32bit: longint;
  162. begin
  163. gets32bit:=RESULT_S32BIT;
  164. end;
  165. function gets64bit: int64;
  166. begin
  167. gets64bit:=RESULT_S64BIT;
  168. end;
  169. function gets32real: single;
  170. begin
  171. gets32real:=RESULT_S32REAL;
  172. end;
  173. function gets64real: double;
  174. begin
  175. gets64real:=RESULT_S64REAL;
  176. end;
  177. {************************************************************************}
  178. { CONST PARAMETERS (INLINE) }
  179. {************************************************************************}
  180. procedure proc_const_smallrecord_inline(const smallrec : tsmallrecord);inline;
  181. begin
  182. if (smallrec.b = RESULT_U8BIT) and (smallrec.w = RESULT_U16BIT) then
  183. global_u8bit := RESULT_U8BIT;
  184. end;
  185. procedure proc_const_largerecord_inline(const largerec : tlargerecord);inline;
  186. begin
  187. if (largerec.b[1] = RESULT_U8BIT) and (largerec.b[2] = RESULT_U8BIT) then
  188. global_u8bit := RESULT_U8BIT;
  189. end;
  190. procedure proc_const_smallset_inline(const smallset : tsmallset);inline;
  191. begin
  192. if A_D in smallset then
  193. global_u8bit := RESULT_U8BIT;
  194. end;
  195. procedure proc_const_largeset_inline(const largeset : tlargeset);inline;
  196. begin
  197. if 'I' in largeset then
  198. global_u8bit := RESULT_U8BIT;
  199. end;
  200. procedure proc_const_smallstring_inline(const s:tsmallstring);inline;
  201. begin
  202. if s = RESULT_SMALLSTRING then
  203. global_u8bit := RESULT_u8BIT;
  204. end;
  205. procedure proc_const_bigstring_inline(const s:shortstring);inline;
  206. begin
  207. if s = RESULT_BIGSTRING then
  208. global_u8bit := RESULT_u8BIT;
  209. end;
  210. procedure proc_const_smallarray_inline(const arr : tsmallarray);inline;
  211. begin
  212. if arr[SMALL_INDEX] = RESULT_U8BIT then
  213. global_u8bit := RESULT_U8BIT;
  214. end;
  215. procedure proc_const_smallarray_open_inline(const arr : array of byte);inline;
  216. begin
  217. { form 0 to N-1 indexes in open arrays }
  218. if arr[SMALL_INDEX-1] = RESULT_U8BIT then
  219. global_u8bit := RESULT_U8BIT;
  220. end;
  221. procedure proc_const_smallarray_const_1_inline(const arr : array of const);inline;
  222. var
  223. i: integer;
  224. begin
  225. global_u8bit := arr[0].vinteger and $ff;
  226. global_ptr := arr[1].VPchar;
  227. global_s64bit := arr[2].vInt64^;
  228. global_char := arr[3].vchar;
  229. global_bigstring := arr[4].VString^;
  230. global_s64real := arr[5].VExtended^;
  231. global_boolean := arr[6].vboolean;
  232. (*
  233. for i:=0 to high(arr) do
  234. begin
  235. case arr[i].vtype of
  236. vtInteger : global_u8bit := arr[i].vinteger and $ff;
  237. vtBoolean : global_boolean := arr[i].vboolean;
  238. vtChar : global_char := arr[i].vchar;
  239. vtExtended : global_s64real := arr[i].VExtended^;
  240. vtString : global_bigstring := arr[i].VString^;
  241. vtPointer : ;
  242. vtPChar : global_ptr := arr[i].VPchar;
  243. vtObject : ;
  244. { vtClass : global_class := tclass1(arr[i].VClass);}
  245. vtAnsiString : ;
  246. vtInt64 : global_s64bit := arr[i].vInt64^;
  247. else
  248. RunError(255);
  249. end;
  250. end; {endfor}
  251. *)
  252. end;
  253. procedure proc_const_smallarray_const_2_inline(const arr : array of const);inline;
  254. var
  255. i: integer;
  256. begin
  257. if high(arr)<0 then
  258. global_u8bit := RESULT_U8BIT;
  259. end;
  260. procedure proc_const_formaldef_array_inline(const buf);inline;
  261. var
  262. p: pchar;
  263. begin
  264. { array is indexed from 1 }
  265. p := @buf;
  266. global_u8bit := byte(p[SMALL_INDEX-1]);
  267. end;
  268. var
  269. failed: boolean;
  270. pp : ^pchar;
  271. begin
  272. {***************************** INLINE TESTS *******************************}
  273. write('(Inline) const parameter test (src : LOC_REFERENCE (recorddef)))...');
  274. clear_globals;
  275. clear_values;
  276. failed := false;
  277. value_smallrec.b := RESULT_U8BIT;
  278. value_smallrec.w := RESULT_U16BIT;
  279. proc_const_smallrecord_inline(value_smallrec);
  280. if global_u8bit <> RESULT_U8BIT then
  281. failed := true;
  282. clear_globals;
  283. clear_values;
  284. fillchar(value_largerec,sizeof(value_largerec),RESULT_U8BIT);
  285. proc_const_largerecord_inline(value_largerec);
  286. if global_u8bit <> RESULT_U8BIT then
  287. failed := true;
  288. if failed then
  289. fail
  290. else
  291. WriteLn('Passed!');
  292. write('(Inline) const parameter test (src : LOC_REFERENCE (setdef)))...');
  293. clear_globals;
  294. clear_values;
  295. failed := false;
  296. value_smallset := [A_A,A_D];
  297. proc_const_smallset_inline(value_smallset);
  298. if global_u8bit <> RESULT_U8BIT then
  299. failed := true;
  300. clear_globals;
  301. clear_values;
  302. value_largeset := ['I'];
  303. proc_const_largeset_inline(value_largeset);
  304. if global_u8bit <> RESULT_U8BIT then
  305. failed := true;
  306. if failed then
  307. fail
  308. else
  309. WriteLn('Passed!');
  310. clear_globals;
  311. clear_values;
  312. write('(Inline) const parameter test (src : LOC_REFERENCE (stringdef)))...');
  313. failed := false;
  314. value_smallstring := RESULT_SMALLSTRING;
  315. proc_const_smallstring_inline(value_smallstring);
  316. if global_u8bit <> RESULT_U8BIT then
  317. failed := true;
  318. clear_globals;
  319. clear_values;
  320. value_bigstring := RESULT_BIGSTRING;
  321. proc_const_bigstring_inline(value_bigstring);
  322. if global_u8bit <> RESULT_U8BIT then
  323. failed := true;
  324. if failed then
  325. fail
  326. else
  327. WriteLn('Passed!');
  328. write('(Inline) Const parameter test (src : LOC_REFERENCE (formaldef)))...');
  329. clear_globals;
  330. clear_values;
  331. failed:=false;
  332. value_smallarray[SMALL_INDEX] := RESULT_U8BIT;
  333. proc_const_formaldef_array_inline(value_smallarray);
  334. if global_u8bit <> RESULT_U8BIT then
  335. failed := true;
  336. if failed then
  337. fail
  338. else
  339. WriteLn('Passed!');
  340. write('Inline const parameter test (src : LOC_REFERENCE (arraydef)))...');
  341. clear_globals;
  342. clear_values;
  343. failed:=false;
  344. value_smallarray[SMALL_INDEX] := RESULT_U8BIT;
  345. proc_const_smallarray_inline(value_smallarray);
  346. if global_u8bit <> RESULT_U8BIT then
  347. failed := true;
  348. clear_globals;
  349. clear_values;
  350. value_smallarray[SMALL_INDEX] := RESULT_U8BIT;
  351. proc_const_smallarray_open_inline(value_smallarray);
  352. if global_u8bit <> RESULT_U8BIT then
  353. failed := true;
  354. clear_globals;
  355. clear_values;
  356. value_u8bit := RESULT_U8BIT;
  357. value_ptr := RESULT_PCHAR;
  358. value_s64bit := RESULT_S64BIT;
  359. value_smallstring := RESULT_SMALLSTRING;
  360. value_class := tclass1.create;
  361. value_boolean := RESULT_BOOLEAN;
  362. value_char := RESULT_CHAR;
  363. value_s64real:=RESULT_S64REAL;
  364. proc_const_smallarray_const_1_inline([value_u8bit,value_ptr,value_s64bit,value_char,value_smallstring,value_s64real,value_boolean,value_class]);
  365. if global_u8bit <> RESULT_U8BIT then
  366. failed := true;
  367. if global_char <> RESULT_CHAR then
  368. failed := true;
  369. if global_boolean <> RESULT_BOOLEAN then
  370. failed:=true;
  371. if trunc(global_s64real) <> trunc(RESULT_S64REAL) then
  372. failed := true;
  373. if global_bigstring <> RESULT_SMALLSTRING then
  374. failed := true;
  375. if global_ptr <> value_ptr then
  376. failed := true;
  377. { if value_class <> global_class then
  378. failed := true;!!!!!!!!!!!!!!!!!!!!}
  379. if global_s64bit <> RESULT_S64BIT then
  380. failed := true;
  381. if assigned(value_class) then
  382. value_class.destroy;
  383. global_u8bit := 0;
  384. proc_const_smallarray_const_2_inline([]);
  385. if global_u8bit <> RESULT_U8BIT then
  386. failed := true;
  387. if failed then
  388. fail
  389. else
  390. WriteLn('Passed!');
  391. end.
  392. {
  393. $Log$
  394. Revision 1.5 2003-04-22 10:24:29 florian
  395. * fixed defines for powerpc
  396. Revision 1.4 2002/09/22 09:08:40 carl
  397. * gets64bit was not returning an int64!
  398. Revision 1.3 2002/09/07 15:40:50 peter
  399. * old logs removed and tabs fixed
  400. Revision 1.2 2002/05/13 13:45:36 peter
  401. * updated to compile tests with kylix
  402. Revision 1.1 2002/04/10 16:34:30 carl
  403. + first tries at first calln testing
  404. Revision 1.1 2002/04/01 18:05:39 carl
  405. + const parameter passing tests (currently crashes)
  406. }