tcalvar2.pp 12 KB

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