tcalvar2.pp 12 KB

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