tcalvar2.pp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  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. { (var with inline calling convention) }
  19. {****************************************************************}
  20. program tcalvar2;
  21. {$mode objfpc}
  22. {$INLINE ON}
  23. {$P-}
  24. {$V+}
  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. { VAR PARAMETERS (INLINE) }
  179. {************************************************************************}
  180. procedure proc_var_s32bit_inline(var v : longint);inline;
  181. begin
  182. v:=RESULT_S32BIT;
  183. end;
  184. procedure proc_var_s64bit_inline(var v: int64);inline;
  185. begin
  186. v:=RESULT_S64BIT;
  187. end;
  188. procedure proc_var_u8bit_inline(var v: byte);inline;
  189. begin
  190. v:=RESULT_U8BIT;
  191. end;
  192. procedure proc_var_smallrecord_inline(var smallrec : tsmallrecord);inline;
  193. begin
  194. smallrec.b := RESULT_U8BIT;
  195. smallrec.w := RESULT_U16BIT;
  196. end;
  197. procedure proc_var_largerecord_inline(var largerec : tlargerecord);inline;
  198. begin
  199. largerec.b[1] := RESULT_U8BIT;
  200. largerec.b[2] := RESULT_U8BIT;
  201. end;
  202. procedure proc_var_smallset_inline(var smallset : tsmallset);inline;
  203. begin
  204. smallset := [A_A,A_D];
  205. end;
  206. procedure proc_var_largeset_inline(var largeset : tlargeset);inline;
  207. begin
  208. largeset:= largeset + ['I'];
  209. end;
  210. procedure proc_var_smallstring_inline(var s:tsmallstring);inline;
  211. begin
  212. s:=RESULT_SMALLSTRING;
  213. end;
  214. procedure proc_var_bigstring_inline(var s:shortstring);inline;
  215. begin
  216. s:=RESULT_BIGSTRING;
  217. end;
  218. procedure proc_var_openstring_inline(var s: OpenString);inline;
  219. begin
  220. global_u8bit := high(s);
  221. s:=RESULT_SMALLSTRING;
  222. end;
  223. procedure proc_var_smallarray_inline(var arr : tsmallarray);inline;
  224. begin
  225. arr[SMALL_INDEX] := RESULT_U8BIT;
  226. arr[1] := RESULT_U8BIT;
  227. end;
  228. procedure proc_var_smallarray_open_inline(var arr : array of byte);inline;
  229. begin
  230. arr[high(arr)] := RESULT_U8BIT;
  231. arr[low(arr)] := RESULT_U8BIT;
  232. end;
  233. {!!!!!!!!!!!!!!!!!! DON'T KNOW HOWTO TEST}
  234. procedure proc_var_smallarray_const_1_inline(var arr : array of const);inline;
  235. var
  236. i: integer;
  237. begin
  238. for i:=0 to high(arr) do
  239. begin
  240. case arr[i].vtype of
  241. vtInteger : arr[i].vinteger := RESULT_U8BIT;
  242. vtBoolean : arr[i].vboolean := RESULT_BOOLEAN;
  243. else
  244. RunError(255);
  245. end;
  246. end; {endfor}
  247. end;
  248. procedure proc_var_smallarray_const_2_inline(var arr : array of const);inline;
  249. var
  250. i: integer;
  251. begin
  252. if high(arr)<0 then
  253. global_u8bit := RESULT_U8BIT;
  254. end;
  255. procedure proc_var_formaldef_array_inline(var buf);inline;
  256. var
  257. p: ^byte;
  258. begin
  259. { array is indexed from 1 }
  260. p := @buf;
  261. p[SMALL_INDEX-1] := RESULT_U8BIT;
  262. p[0] := RESULT_U8BIT;
  263. end;
  264. procedure proc_var_formaldef_string_inline(var buf);inline;
  265. var
  266. p: ^byte;
  267. begin
  268. { array is indexed from 1 }
  269. p := @buf;
  270. p[SMALL_INDEX-1] := RESULT_U8BIT;
  271. p[0] := RESULT_U8BIT;
  272. end;
  273. var
  274. failed: boolean;
  275. pp : ^pchar;
  276. begin
  277. {***************************** INLINE TESTS *******************************}
  278. write('(Inline) var parameter test (src : LOC_REFERENCE (recorddef)))...');
  279. clear_globals;
  280. clear_values;
  281. failed := false;
  282. proc_var_smallrecord_inline(value_smallrec);
  283. if (value_smallrec.b <> RESULT_U8BIT) or (value_smallrec.w <> RESULT_U16BIT) then
  284. failed := true;
  285. clear_globals;
  286. clear_values;
  287. proc_var_largerecord_inline(value_largerec);
  288. if (value_largerec.b[1] <> RESULT_U8BIT) or (value_largerec.b[2] <> RESULT_U8BIT) then
  289. failed := true;
  290. if failed then
  291. fail
  292. else
  293. WriteLn('Passed!');
  294. write('(Inline) var parameter test (src : LOC_REFERENCE (setdef)))...');
  295. clear_globals;
  296. clear_values;
  297. failed := false;
  298. proc_var_smallset_inline(value_smallset);
  299. if (not (A_A in value_smallset)) or (not (A_D in value_smallset)) then
  300. failed := true;
  301. clear_globals;
  302. clear_values;
  303. proc_var_largeset_inline(value_largeset);
  304. if not ('I' in value_largeset) then
  305. failed := true;
  306. if failed then
  307. fail
  308. else
  309. WriteLn('Passed!');
  310. write('(Inline) var parameter test (src : LOC_REFERENCE (stringdef)))...');
  311. clear_globals;
  312. clear_values;
  313. failed := false;
  314. proc_var_smallstring_inline(value_smallstring);
  315. if value_smallstring <> RESULT_SMALLSTRING then
  316. failed := true;
  317. clear_globals;
  318. clear_values;
  319. proc_var_bigstring_inline(value_bigstring);
  320. if value_bigstring <> RESULT_BIGSTRING then
  321. failed := true;
  322. clear_globals;
  323. clear_values;
  324. proc_var_openstring_inline(value_smallstring);
  325. if (value_smallstring <> RESULT_SMALLSTRING) or (global_u8bit <> high(value_smallstring)) then
  326. failed := true;
  327. if failed then
  328. fail
  329. else
  330. WriteLn('Passed!');
  331. write('(Inline) Var parameter test (src : LOC_REFERENCE (formaldef)))...');
  332. clear_globals;
  333. clear_values;
  334. failed:=false;
  335. proc_var_formaldef_array_inline(value_smallarray);
  336. if (value_smallarray[SMALL_INDEX] <> RESULT_U8BIT) or (value_smallarray[1] <> RESULT_U8BIT) then
  337. failed := true;
  338. if failed then
  339. fail
  340. else
  341. WriteLn('Passed!');
  342. write('(Inline) Var parameter test (src : LOC_REFERENCE (arraydef)))...');
  343. clear_globals;
  344. clear_values;
  345. failed:=false;
  346. value_smallarray[SMALL_INDEX] := RESULT_U8BIT;
  347. proc_var_smallarray_inline(value_smallarray);
  348. if (value_smallarray[SMALL_INDEX] <> RESULT_U8BIT) or (value_smallarray[1] <> RESULT_U8BIT) then
  349. failed := true;
  350. clear_globals;
  351. clear_values;
  352. proc_var_smallarray_open_inline(value_smallarray);
  353. if (value_smallarray[SMALL_INDEX] <> RESULT_U8BIT) or (value_smallarray[1] <> RESULT_U8BIT) then
  354. failed := true;
  355. (* HOW CAN ARRAY OF CONST VAR PARAMETERS BE TESTED?
  356. clear_globals;
  357. clear_values;
  358. value_u8bit := RESULT_U8BIT;
  359. value_ptr := RESULT_PCHAR;
  360. value_s64bit := RESULT_S64BIT;
  361. value_smallstring := RESULT_SMALLSTRING;
  362. value_class := tclass1.create;
  363. value_boolean := RESULT_BOOLEAN;
  364. value_char := RESULT_CHAR;
  365. value_s64real:=RESULT_S64REAL;
  366. proc_var_smallarray_var_1_inline([value_u8bit,value_ptr,value_s64bit,value_char,value_smallstring,value_s64real,value_boolean,value_class]);
  367. if global_u8bit <> RESULT_U8BIT then
  368. failed := true;
  369. if global_char <> RESULT_CHAR then
  370. failed := true;
  371. if global_boolean <> RESULT_BOOLEAN then
  372. failed:=true;
  373. if trunc(global_s64real) <> trunc(RESULT_S64REAL) then
  374. failed := true;
  375. if global_bigstring <> RESULT_SMALLSTRING then
  376. failed := true;
  377. if global_ptr <> value_ptr then
  378. failed := true;
  379. { if value_class <> global_class then
  380. failed := true;!!!!!!!!!!!!!!!!!!!!}
  381. if global_s64bit <> RESULT_S64BIT then
  382. failed := true;
  383. if assigned(value_class) then
  384. value_class.destroy;
  385. global_u8bit := 0;
  386. proc_var_smallarray_const_2_inline([]);
  387. if global_u8bit <> RESULT_U8BIT then
  388. failed := true;
  389. *)
  390. if failed then
  391. fail
  392. else
  393. WriteLn('Passed!');
  394. end.
  395. {
  396. $Log$
  397. Revision 1.5 2003-04-22 10:24:29 florian
  398. * fixed defines for powerpc
  399. Revision 1.4 2002/09/22 09:08:41 carl
  400. * gets64bit was not returning an int64!
  401. Revision 1.3 2002/09/07 15:40:55 peter
  402. * old logs removed and tabs fixed
  403. Revision 1.2 2002/05/13 13:45:38 peter
  404. * updated to compile tests with kylix
  405. Revision 1.1 2002/04/10 16:33:19 carl
  406. + first tries at first calln testing
  407. }