tcalcst2.pp 12 KB

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