tcalval2.pp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  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. { (value parameters with inline calls) }
  19. {****************************************************************}
  20. program tcalval2;
  21. {$mode objfpc}
  22. {$INLINE ON}
  23. {$R+}
  24. {$P-}
  25. {$ifdef VER70}
  26. {$define tp}
  27. {$endif}
  28. { REAL should map to single or double }
  29. { so it is not checked, since single }
  30. { double nodes are checked. }
  31. { assumes that enumdef is the same as orddef (same storage format) }
  32. const
  33. { should be defined depending on CPU target }
  34. {$ifdef fpc}
  35. {$ifdef cpu68k}
  36. BIG_INDEX = 8000;
  37. SMALL_INDEX = 13;
  38. {$else}
  39. BIG_INDEX = 33000;
  40. SMALL_INDEX = 13; { value should not be aligned! }
  41. {$endif}
  42. {$else}
  43. BIG_INDEX = 33000;
  44. SMALL_INDEX = 13; { value should not be aligned! }
  45. {$endif}
  46. RESULT_U8BIT = $55;
  47. RESULT_U16BIT = $500F;
  48. RESULT_S32BIT = $500F0000;
  49. RESULT_S64BIT = $500F0000;
  50. RESULT_S32REAL = 1777.12;
  51. RESULT_S64REAL = 3444.24;
  52. RESULT_BOOL8BIT = 1;
  53. RESULT_BOOL16BIT = 1;
  54. RESULT_BOOL32BIT = 1;
  55. RESULT_PCHAR = 'Hello world';
  56. RESULT_BIGSTRING = 'Hello world';
  57. RESULT_SMALLSTRING = 'H';
  58. RESULT_CHAR = 'I';
  59. RESULT_BOOLEAN = TRUE;
  60. type
  61. tclass1 = class
  62. end;
  63. tprocedure = procedure;
  64. tsmallrecord =
  65. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  66. packed
  67. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  68. record
  69. b: byte;
  70. w: word;
  71. end;
  72. tlargerecord = packed record
  73. b: array[1..BIG_INDEX] of byte;
  74. end;
  75. tsmallarray = packed array[1..SMALL_INDEX] of byte;
  76. tsmallsetenum =
  77. (A_A,A_B,A_C,A_D);
  78. tsmallset = set of tsmallsetenum;
  79. tlargeset = set of char;
  80. tsmallstring = string[2];
  81. var
  82. global_u8bit : byte;
  83. global_u16bit : word;
  84. global_s32bit : longint;
  85. global_s64bit : int64;
  86. global_s32real : single;
  87. global_s64real : double;
  88. global_ptr : pchar;
  89. global_proc : tprocedure;
  90. global_class : tclass1;
  91. global_bigstring : shortstring;
  92. global_boolean : boolean;
  93. global_char : char;
  94. value_u8bit : byte;
  95. value_u16bit : word;
  96. value_s32bit : longint;
  97. value_s64bit : int64;
  98. value_s32real : single;
  99. value_s64real : double;
  100. value_proc : tprocedure;
  101. value_ptr : pchar;
  102. value_class : tclass1;
  103. value_smallrec : tsmallrecord;
  104. value_largerec : tlargerecord;
  105. value_smallset : tsmallset;
  106. value_smallstring : tsmallstring;
  107. value_bigstring : shortstring;
  108. value_largeset : tlargeset;
  109. value_smallarray : tsmallarray;
  110. value_boolean : boolean;
  111. value_char : char;
  112. procedure fail;
  113. begin
  114. WriteLn('Failure.');
  115. halt(1);
  116. end;
  117. procedure clear_globals;
  118. begin
  119. global_u8bit := 0;
  120. global_u16bit := 0;
  121. global_s32bit := 0;
  122. global_s64bit := 0;
  123. global_s32real := 0.0;
  124. global_s64real := 0.0;
  125. global_ptr := nil;
  126. global_proc := nil;
  127. global_class := nil;
  128. global_bigstring := '';
  129. global_boolean := false;
  130. global_char := #0;
  131. end;
  132. procedure clear_values;
  133. begin
  134. value_u8bit := 0;
  135. value_u16bit := 0;
  136. value_s32bit := 0;
  137. value_s64bit := 0;
  138. value_s32real := 0.0;
  139. value_s64real := 0.0;
  140. value_proc := nil;
  141. value_ptr := nil;
  142. value_class := nil;
  143. fillchar(value_smallrec, sizeof(value_smallrec), #0);
  144. fillchar(value_largerec, sizeof(value_largerec), #0);
  145. value_smallset := [];
  146. value_smallstring := '';
  147. value_bigstring := '';
  148. value_largeset := [];
  149. fillchar(value_smallarray, sizeof(value_smallarray), #0);
  150. value_boolean := false;
  151. value_char:=#0;
  152. end;
  153. procedure testprocedure;
  154. begin
  155. end;
  156. function getu8bit : byte;
  157. begin
  158. getu8bit:=RESULT_U8BIT;
  159. end;
  160. function getu16bit: word;
  161. begin
  162. getu16bit:=RESULT_U16BIT;
  163. end;
  164. function gets32bit: longint;
  165. begin
  166. gets32bit:=RESULT_S32BIT;
  167. end;
  168. function gets64bit: int64;
  169. begin
  170. gets64bit:=RESULT_S64BIT;
  171. end;
  172. function gets32real: single;
  173. begin
  174. gets32real:=RESULT_S32REAL;
  175. end;
  176. function gets64real: double;
  177. begin
  178. gets64real:=RESULT_S64REAL;
  179. end;
  180. procedure proc_value_u8bit_inline(v: byte);inline;
  181. begin
  182. global_u8bit := v;
  183. end;
  184. procedure proc_value_u16bit_inline(v: word);inline;
  185. begin
  186. global_u16bit := v;
  187. end;
  188. procedure proc_value_s32bit_inline(v : longint);inline;
  189. begin
  190. global_s32bit := v;
  191. end;
  192. procedure proc_value_s64bit_inline(v: int64);inline;
  193. begin
  194. global_s64bit:= v;
  195. end;
  196. procedure proc_value_s32real_inline(v : single);inline;
  197. begin
  198. global_s32real := v;
  199. end;
  200. procedure proc_value_s64real_inline(v: double);inline;
  201. begin
  202. global_s64real:= v;
  203. end;
  204. procedure proc_value_pointerdef_inline(p : pchar);inline;
  205. begin
  206. global_ptr:=p;
  207. end;
  208. procedure proc_value_procvardef_inline(p : tprocedure);inline;
  209. begin
  210. global_proc:=p;
  211. end;
  212. procedure proc_value_classrefdef_inline(obj : tclass1);inline;
  213. begin
  214. global_class:=obj;
  215. end;
  216. procedure proc_value_bool8bit_inline(v: boolean);inline;
  217. begin
  218. { boolean should be 8-bit always! }
  219. if sizeof(boolean) <> 1 then RunError(255);
  220. global_u8bit := byte(v);
  221. end;
  222. procedure proc_value_smallrecord_inline(smallrec : tsmallrecord);inline;
  223. begin
  224. if (smallrec.b = RESULT_U8BIT) and (smallrec.w = RESULT_U16BIT) then
  225. global_u8bit := RESULT_U8BIT;
  226. end;
  227. procedure proc_value_largerecord_inline(largerec : tlargerecord);inline;
  228. begin
  229. if (largerec.b[1] = RESULT_U8BIT) and (largerec.b[2] = RESULT_U8BIT) then
  230. global_u8bit := RESULT_U8BIT;
  231. end;
  232. procedure proc_value_smallset_inline(smallset : tsmallset);inline;
  233. begin
  234. if A_D in smallset then
  235. global_u8bit := RESULT_U8BIT;
  236. end;
  237. procedure proc_value_largeset_inline(largeset : tlargeset);inline;
  238. begin
  239. if 'I' in largeset then
  240. global_u8bit := RESULT_U8BIT;
  241. end;
  242. procedure proc_value_smallstring_inline(s:tsmallstring);inline;
  243. begin
  244. if s = RESULT_SMALLSTRING then
  245. global_u8bit := RESULT_u8BIT;
  246. end;
  247. procedure proc_value_bigstring_inline(s:shortstring);inline;
  248. begin
  249. if s = RESULT_BIGSTRING then
  250. global_u8bit := RESULT_u8BIT;
  251. end;
  252. procedure proc_value_smallarray_inline(arr : tsmallarray);inline;
  253. begin
  254. if arr[SMALL_INDEX] = RESULT_U8BIT then
  255. global_u8bit := RESULT_U8BIT;
  256. end;
  257. procedure proc_value_smallarray_open_inline(arr : array of byte);inline;
  258. begin
  259. { form 0 to N-1 indexes in open arrays }
  260. if arr[SMALL_INDEX-1] = RESULT_U8BIT then
  261. global_u8bit := RESULT_U8BIT;
  262. end;
  263. procedure proc_value_smallarray_const_1_inline(arr : array of const);inline;
  264. var
  265. i: integer;
  266. begin
  267. global_u8bit := arr[0].vinteger and $ff;
  268. global_ptr := arr[1].VPchar;
  269. global_s64bit := arr[2].vInt64^;
  270. global_char := arr[3].vchar;
  271. global_bigstring := arr[4].VString^;
  272. global_s64real := arr[5].VExtended^;
  273. global_boolean := arr[6].vboolean;
  274. (*
  275. for i:=0 to high(arr) do
  276. begin
  277. case arr[i].vtype of
  278. vtInteger : global_u8bit := arr[i].vinteger and $ff;
  279. vtBoolean : global_boolean := arr[i].vboolean;
  280. vtChar : global_char := arr[i].vchar;
  281. vtExtended : global_s64real := arr[i].VExtended^;
  282. vtString : global_bigstring := arr[i].VString^;
  283. vtPointer : ;
  284. vtPChar : global_ptr := arr[i].VPchar;
  285. vtObject : ;
  286. { vtClass : global_class := tclass1(arr[i].VClass);}
  287. vtAnsiString : ;
  288. vtInt64 : global_s64bit := arr[i].vInt64^;
  289. else
  290. RunError(255);
  291. end;
  292. end; {endfor}
  293. *)
  294. end;
  295. procedure proc_value_smallarray_const_2_inline(arr : array of const);inline;
  296. var
  297. i: integer;
  298. begin
  299. if high(arr)<0 then
  300. global_u8bit := RESULT_U8BIT;
  301. end;
  302. var
  303. failed: boolean;
  304. begin
  305. {***************************** INLINE TESTS *******************************}
  306. write('(Inline) Value parameter test (src : LOC_REGISTER)...');
  307. clear_globals;
  308. clear_values;
  309. failed:=false;
  310. proc_value_u8bit_inline(getu8bit);
  311. if global_u8bit <> RESULT_U8BIT then
  312. failed:=true;
  313. proc_value_u16bit_inline(getu16bit);
  314. if global_u16bit <> RESULT_U16BIT then
  315. failed:=true;
  316. proc_value_s32bit_inline(gets32bit);
  317. if global_s32bit <> RESULT_S32BIT then
  318. failed:=true;
  319. proc_value_s64bit_inline(gets64bit);
  320. if global_s64bit <> RESULT_S64BIT then
  321. failed:=true;
  322. if failed then
  323. fail
  324. else
  325. WriteLn('Passed!');
  326. clear_globals;
  327. clear_values;
  328. failed:=false;
  329. write('(Inline) Value parameter test (src : LOC_FPUREGISTER)...');
  330. proc_value_s32real_inline(gets32real);
  331. if trunc(global_s32real) <> trunc(RESULT_S32REAL) then
  332. failed:=true;
  333. proc_value_s64real_inline(gets64real);
  334. if trunc(global_s64real) <> trunc(RESULT_S64REAL) then
  335. failed:=true;
  336. if failed then
  337. fail
  338. else
  339. WriteLn('Passed!');
  340. { LOC_REFERENCE }
  341. write('(Inline) Value parameter test (src : LOC_REFERENCE (orddef/enumdef))...');
  342. clear_globals;
  343. clear_values;
  344. value_u8bit := RESULT_U8BIT;
  345. value_u16bit := RESULT_U16BIT;
  346. value_s32bit := RESULT_S32BIT;
  347. {$ifndef tp}
  348. value_s64bit := RESULT_S64BIT;
  349. {$endif}
  350. value_s32real := RESULT_S32REAL;
  351. value_s64real := RESULT_S64REAL;
  352. failed:=false;
  353. proc_value_u8bit_inline(value_u8bit);
  354. if global_u8bit <> RESULT_U8BIT then
  355. failed:=true;
  356. proc_value_u16bit_inline(value_u16bit);
  357. if global_u16bit <> RESULT_U16BIT then
  358. failed:=true;
  359. proc_value_s32bit_inline(value_s32bit);
  360. if global_s32bit <> RESULT_S32BIT then
  361. failed:=true;
  362. proc_value_s64bit_inline(value_s64bit);
  363. if global_s64bit <> RESULT_S64BIT then
  364. failed:=true;
  365. if failed then
  366. fail
  367. else
  368. WriteLn('Passed!');
  369. clear_globals;
  370. failed:=false;
  371. write('(Inline) Value parameter test (src : LOC_REFERENCE (floatdef))...');
  372. proc_value_s32real_inline(value_s32real);
  373. if trunc(global_s32real) <> trunc(RESULT_S32REAL) then
  374. failed:=true;
  375. proc_value_s64real_inline(value_s64real);
  376. if trunc(global_s64real) <> trunc(RESULT_S64REAL) then
  377. failed:=true;
  378. if failed then
  379. fail
  380. else
  381. WriteLn('Passed!');
  382. write('(Inline) Value parameter test (src : LOC_REFERENCE (pointer))...');
  383. clear_globals;
  384. clear_values;
  385. value_ptr := RESULT_PCHAR;
  386. failed:=false;
  387. proc_value_pointerdef_inline(value_ptr);
  388. if global_ptr <> value_ptr then
  389. failed := true;
  390. value_proc := @testprocedure;
  391. proc_value_procvardef_inline(value_proc);
  392. if value_proc <> global_proc then
  393. failed := true;
  394. value_class := tclass1.create;
  395. proc_value_classrefdef_inline(value_class);
  396. if value_class <> global_class then
  397. failed := true;
  398. value_class.destroy;
  399. if failed then
  400. fail
  401. else
  402. WriteLn('Passed!');
  403. write('(Inline) Value parameter test (src : LOC_FLAGS (orddef))...');
  404. clear_globals;
  405. clear_values;
  406. failed:=false;
  407. value_u8bit := 0;
  408. failed:=false;
  409. proc_value_bool8bit_inline(value_u8bit = 0);
  410. if global_u8bit <> RESULT_BOOL8BIT then
  411. failed:=true;
  412. if failed then
  413. fail
  414. else
  415. WriteLn('Passed!');
  416. write('(Inline) Value parameter test (src : LOC_REFERENCE (recorddef)))...');
  417. failed := false;
  418. clear_globals;
  419. clear_values;
  420. value_smallrec.b := RESULT_U8BIT;
  421. value_smallrec.w := RESULT_U16BIT;
  422. proc_value_smallrecord_inline(value_smallrec);
  423. if global_u8bit <> RESULT_U8BIT then
  424. failed := true;
  425. clear_globals;
  426. clear_values;
  427. fillchar(value_largerec,sizeof(value_largerec),RESULT_U8BIT);
  428. proc_value_largerecord_inline(value_largerec);
  429. if global_u8bit <> RESULT_U8BIT then
  430. failed := true;
  431. if failed then
  432. fail
  433. else
  434. WriteLn('Passed!');
  435. write('(Inline) Value parameter test (src : LOC_REFERENCE (setdef)))...');
  436. clear_globals;
  437. clear_values;
  438. failed := false;
  439. value_smallset := [A_A,A_D];
  440. proc_value_smallset_inline(value_smallset);
  441. if global_u8bit <> RESULT_U8BIT then
  442. failed := true;
  443. clear_globals;
  444. clear_values;
  445. value_largeset := ['I'];
  446. proc_value_largeset_inline(value_largeset);
  447. if global_u8bit <> RESULT_U8BIT then
  448. failed := true;
  449. if failed then
  450. fail
  451. else
  452. WriteLn('Passed!');
  453. write('(Inline) Value parameter test (src : LOC_REFERENCE (stringdef)))...');
  454. clear_globals;
  455. clear_values;
  456. failed := false;
  457. value_smallstring := RESULT_SMALLSTRING;
  458. proc_value_smallstring_inline(value_smallstring);
  459. if global_u8bit <> RESULT_U8BIT then
  460. failed := true;
  461. clear_globals;
  462. clear_values;
  463. value_bigstring := RESULT_BIGSTRING;
  464. proc_value_bigstring_inline(value_bigstring);
  465. if global_u8bit <> RESULT_U8BIT then
  466. failed := true;
  467. if failed then
  468. fail
  469. else
  470. WriteLn('Passed!');
  471. write('(Inline) value parameter test (src : LOC_REFERENCE (arraydef)))...');
  472. clear_globals;
  473. clear_values;
  474. failed:=false;
  475. value_smallarray[SMALL_INDEX] := RESULT_U8BIT;
  476. proc_value_smallarray_inline(value_smallarray);
  477. if global_u8bit <> RESULT_U8BIT then
  478. failed := true;
  479. clear_globals;
  480. clear_values;
  481. value_smallarray[SMALL_INDEX] := RESULT_U8BIT;
  482. proc_value_smallarray_open_inline(value_smallarray);
  483. if global_u8bit <> RESULT_U8BIT then
  484. failed := true;
  485. clear_globals;
  486. clear_values;
  487. value_u8bit := RESULT_U8BIT;
  488. value_ptr := RESULT_PCHAR;
  489. value_s64bit := RESULT_S64BIT;
  490. value_smallstring := RESULT_SMALLSTRING;
  491. value_class := tclass1.create;
  492. value_boolean := RESULT_BOOLEAN;
  493. value_char := RESULT_CHAR;
  494. value_s64real:=RESULT_S64REAL;
  495. proc_value_smallarray_const_1_inline([value_u8bit,value_ptr,value_s64bit,value_char,value_smallstring,value_s64real,value_boolean,value_class]);
  496. if global_u8bit <> RESULT_U8BIT then
  497. failed := true;
  498. if global_char <> RESULT_CHAR then
  499. failed := true;
  500. if global_boolean <> RESULT_BOOLEAN then
  501. failed:=true;
  502. if trunc(global_s64real) <> trunc(RESULT_S64REAL) then
  503. failed := true;
  504. if global_bigstring <> RESULT_SMALLSTRING then
  505. failed := true;
  506. if global_ptr <> value_ptr then
  507. failed := true;
  508. { if value_class <> global_class then
  509. failed := true;!!!!!!!!!!!!!!!!!!!!}
  510. if global_s64bit <> RESULT_S64BIT then
  511. failed := true;
  512. if assigned(value_class) then
  513. value_class.destroy;
  514. global_u8bit := 0;
  515. proc_value_smallarray_const_2_inline([]);
  516. if global_u8bit <> RESULT_U8BIT then
  517. failed := true;
  518. if failed then
  519. fail
  520. else
  521. WriteLn('Passed!');
  522. end.