tcalval2.pp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  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. {$endif}
  39. {$ifdef cpui386}
  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. procedure proc_value_u8bit_inline(v: byte);inline;
  178. begin
  179. global_u8bit := v;
  180. end;
  181. procedure proc_value_u16bit_inline(v: word);inline;
  182. begin
  183. global_u16bit := v;
  184. end;
  185. procedure proc_value_s32bit_inline(v : longint);inline;
  186. begin
  187. global_s32bit := v;
  188. end;
  189. procedure proc_value_s64bit_inline(v: int64);inline;
  190. begin
  191. global_s64bit:= v;
  192. end;
  193. procedure proc_value_s32real_inline(v : single);inline;
  194. begin
  195. global_s32real := v;
  196. end;
  197. procedure proc_value_s64real_inline(v: double);inline;
  198. begin
  199. global_s64real:= v;
  200. end;
  201. procedure proc_value_pointerdef_inline(p : pchar);inline;
  202. begin
  203. global_ptr:=p;
  204. end;
  205. procedure proc_value_procvardef_inline(p : tprocedure);inline;
  206. begin
  207. global_proc:=p;
  208. end;
  209. procedure proc_value_classrefdef_inline(obj : tclass1);inline;
  210. begin
  211. global_class:=obj;
  212. end;
  213. procedure proc_value_bool8bit_inline(v: boolean);inline;
  214. begin
  215. { boolean should be 8-bit always! }
  216. if sizeof(boolean) <> 1 then RunError(255);
  217. global_u8bit := byte(v);
  218. end;
  219. procedure proc_value_smallrecord_inline(smallrec : tsmallrecord);inline;
  220. begin
  221. if (smallrec.b = RESULT_U8BIT) and (smallrec.w = RESULT_U16BIT) then
  222. global_u8bit := RESULT_U8BIT;
  223. end;
  224. procedure proc_value_largerecord_inline(largerec : tlargerecord);inline;
  225. begin
  226. if (largerec.b[1] = RESULT_U8BIT) and (largerec.b[2] = RESULT_U8BIT) then
  227. global_u8bit := RESULT_U8BIT;
  228. end;
  229. procedure proc_value_smallset_inline(smallset : tsmallset);inline;
  230. begin
  231. if A_D in smallset then
  232. global_u8bit := RESULT_U8BIT;
  233. end;
  234. procedure proc_value_largeset_inline(largeset : tlargeset);inline;
  235. begin
  236. if 'I' in largeset then
  237. global_u8bit := RESULT_U8BIT;
  238. end;
  239. procedure proc_value_smallstring_inline(s:tsmallstring);inline;
  240. begin
  241. if s = RESULT_SMALLSTRING then
  242. global_u8bit := RESULT_u8BIT;
  243. end;
  244. procedure proc_value_bigstring_inline(s:shortstring);inline;
  245. begin
  246. if s = RESULT_BIGSTRING then
  247. global_u8bit := RESULT_u8BIT;
  248. end;
  249. procedure proc_value_smallarray_inline(arr : tsmallarray);inline;
  250. begin
  251. if arr[SMALL_INDEX] = RESULT_U8BIT then
  252. global_u8bit := RESULT_U8BIT;
  253. end;
  254. procedure proc_value_smallarray_open_inline(arr : array of byte);inline;
  255. begin
  256. { form 0 to N-1 indexes in open arrays }
  257. if arr[SMALL_INDEX-1] = RESULT_U8BIT then
  258. global_u8bit := RESULT_U8BIT;
  259. end;
  260. procedure proc_value_smallarray_const_1_inline(arr : array of const);inline;
  261. var
  262. i: integer;
  263. begin
  264. global_u8bit := arr[0].vinteger and $ff;
  265. global_ptr := arr[1].VPchar;
  266. global_s64bit := arr[2].vInt64^;
  267. global_char := arr[3].vchar;
  268. global_bigstring := arr[4].VString^;
  269. global_s64real := arr[5].VExtended^;
  270. global_boolean := arr[6].vboolean;
  271. (*
  272. for i:=0 to high(arr) do
  273. begin
  274. case arr[i].vtype of
  275. vtInteger : global_u8bit := arr[i].vinteger and $ff;
  276. vtBoolean : global_boolean := arr[i].vboolean;
  277. vtChar : global_char := arr[i].vchar;
  278. vtExtended : global_s64real := arr[i].VExtended^;
  279. vtString : global_bigstring := arr[i].VString^;
  280. vtPointer : ;
  281. vtPChar : global_ptr := arr[i].VPchar;
  282. vtObject : ;
  283. { vtClass : global_class := tclass1(arr[i].VClass);}
  284. vtAnsiString : ;
  285. vtInt64 : global_s64bit := arr[i].vInt64^;
  286. else
  287. RunError(255);
  288. end;
  289. end; {endfor}
  290. *)
  291. end;
  292. procedure proc_value_smallarray_const_2_inline(arr : array of const);inline;
  293. var
  294. i: integer;
  295. begin
  296. if high(arr)<0 then
  297. global_u8bit := RESULT_U8BIT;
  298. end;
  299. var
  300. failed: boolean;
  301. begin
  302. {***************************** INLINE TESTS *******************************}
  303. write('(Inline) Value parameter test (src : LOC_REGISTER)...');
  304. clear_globals;
  305. clear_values;
  306. failed:=false;
  307. proc_value_u8bit_inline(getu8bit);
  308. if global_u8bit <> RESULT_U8BIT then
  309. failed:=true;
  310. proc_value_u16bit_inline(getu16bit);
  311. if global_u16bit <> RESULT_U16BIT then
  312. failed:=true;
  313. proc_value_s32bit_inline(gets32bit);
  314. if global_s32bit <> RESULT_S32BIT then
  315. failed:=true;
  316. proc_value_s64bit_inline(gets64bit);
  317. if global_s64bit <> RESULT_S64BIT then
  318. failed:=true;
  319. if failed then
  320. fail
  321. else
  322. WriteLn('Passed!');
  323. clear_globals;
  324. clear_values;
  325. failed:=false;
  326. write('(Inline) Value parameter test (src : LOC_FPUREGISTER)...');
  327. proc_value_s32real_inline(gets32real);
  328. if trunc(global_s32real) <> trunc(RESULT_S32REAL) then
  329. failed:=true;
  330. proc_value_s64real_inline(gets64real);
  331. if trunc(global_s64real) <> trunc(RESULT_S64REAL) then
  332. failed:=true;
  333. if failed then
  334. fail
  335. else
  336. WriteLn('Passed!');
  337. { LOC_REFERENCE }
  338. write('(Inline) Value parameter test (src : LOC_REFERENCE (orddef/enumdef))...');
  339. clear_globals;
  340. clear_values;
  341. value_u8bit := RESULT_U8BIT;
  342. value_u16bit := RESULT_U16BIT;
  343. value_s32bit := RESULT_S32BIT;
  344. {$ifndef tp}
  345. value_s64bit := RESULT_S64BIT;
  346. {$endif}
  347. value_s32real := RESULT_S32REAL;
  348. value_s64real := RESULT_S64REAL;
  349. failed:=false;
  350. proc_value_u8bit_inline(value_u8bit);
  351. if global_u8bit <> RESULT_U8BIT then
  352. failed:=true;
  353. proc_value_u16bit_inline(value_u16bit);
  354. if global_u16bit <> RESULT_U16BIT then
  355. failed:=true;
  356. proc_value_s32bit_inline(value_s32bit);
  357. if global_s32bit <> RESULT_S32BIT then
  358. failed:=true;
  359. proc_value_s64bit_inline(value_s64bit);
  360. if global_s64bit <> RESULT_S64BIT then
  361. failed:=true;
  362. if failed then
  363. fail
  364. else
  365. WriteLn('Passed!');
  366. clear_globals;
  367. failed:=false;
  368. write('(Inline) Value parameter test (src : LOC_REFERENCE (floatdef))...');
  369. proc_value_s32real_inline(value_s32real);
  370. if trunc(global_s32real) <> trunc(RESULT_S32REAL) then
  371. failed:=true;
  372. proc_value_s64real_inline(value_s64real);
  373. if trunc(global_s64real) <> trunc(RESULT_S64REAL) then
  374. failed:=true;
  375. if failed then
  376. fail
  377. else
  378. WriteLn('Passed!');
  379. write('(Inline) Value parameter test (src : LOC_REFERENCE (pointer))...');
  380. clear_globals;
  381. clear_values;
  382. value_ptr := RESULT_PCHAR;
  383. failed:=false;
  384. proc_value_pointerdef_inline(value_ptr);
  385. if global_ptr <> value_ptr then
  386. failed := true;
  387. value_proc := @testprocedure;
  388. proc_value_procvardef_inline(value_proc);
  389. if value_proc <> global_proc then
  390. failed := true;
  391. value_class := tclass1.create;
  392. proc_value_classrefdef_inline(value_class);
  393. if value_class <> global_class then
  394. failed := true;
  395. value_class.destroy;
  396. if failed then
  397. fail
  398. else
  399. WriteLn('Passed!');
  400. write('(Inline) Value parameter test (src : LOC_FLAGS (orddef))...');
  401. clear_globals;
  402. clear_values;
  403. failed:=false;
  404. value_u8bit := 0;
  405. failed:=false;
  406. proc_value_bool8bit_inline(value_u8bit = 0);
  407. if global_u8bit <> RESULT_BOOL8BIT then
  408. failed:=true;
  409. if failed then
  410. fail
  411. else
  412. WriteLn('Passed!');
  413. write('(Inline) Value parameter test (src : LOC_REFERENCE (recorddef)))...');
  414. failed := false;
  415. clear_globals;
  416. clear_values;
  417. value_smallrec.b := RESULT_U8BIT;
  418. value_smallrec.w := RESULT_U16BIT;
  419. proc_value_smallrecord_inline(value_smallrec);
  420. if global_u8bit <> RESULT_U8BIT then
  421. failed := true;
  422. clear_globals;
  423. clear_values;
  424. fillchar(value_largerec,sizeof(value_largerec),RESULT_U8BIT);
  425. proc_value_largerecord_inline(value_largerec);
  426. if global_u8bit <> RESULT_U8BIT then
  427. failed := true;
  428. if failed then
  429. fail
  430. else
  431. WriteLn('Passed!');
  432. write('(Inline) Value parameter test (src : LOC_REFERENCE (setdef)))...');
  433. clear_globals;
  434. clear_values;
  435. failed := false;
  436. value_smallset := [A_A,A_D];
  437. proc_value_smallset_inline(value_smallset);
  438. if global_u8bit <> RESULT_U8BIT then
  439. failed := true;
  440. clear_globals;
  441. clear_values;
  442. value_largeset := ['I'];
  443. proc_value_largeset_inline(value_largeset);
  444. if global_u8bit <> RESULT_U8BIT then
  445. failed := true;
  446. if failed then
  447. fail
  448. else
  449. WriteLn('Passed!');
  450. write('(Inline) Value parameter test (src : LOC_REFERENCE (stringdef)))...');
  451. clear_globals;
  452. clear_values;
  453. failed := false;
  454. value_smallstring := RESULT_SMALLSTRING;
  455. proc_value_smallstring_inline(value_smallstring);
  456. if global_u8bit <> RESULT_U8BIT then
  457. failed := true;
  458. clear_globals;
  459. clear_values;
  460. value_bigstring := RESULT_BIGSTRING;
  461. proc_value_bigstring_inline(value_bigstring);
  462. if global_u8bit <> RESULT_U8BIT then
  463. failed := true;
  464. if failed then
  465. fail
  466. else
  467. WriteLn('Passed!');
  468. write('(Inline) value parameter test (src : LOC_REFERENCE (arraydef)))...');
  469. clear_globals;
  470. clear_values;
  471. failed:=false;
  472. value_smallarray[SMALL_INDEX] := RESULT_U8BIT;
  473. proc_value_smallarray_inline(value_smallarray);
  474. if global_u8bit <> RESULT_U8BIT then
  475. failed := true;
  476. clear_globals;
  477. clear_values;
  478. value_smallarray[SMALL_INDEX] := RESULT_U8BIT;
  479. proc_value_smallarray_open_inline(value_smallarray);
  480. if global_u8bit <> RESULT_U8BIT then
  481. failed := true;
  482. clear_globals;
  483. clear_values;
  484. value_u8bit := RESULT_U8BIT;
  485. value_ptr := RESULT_PCHAR;
  486. value_s64bit := RESULT_S64BIT;
  487. value_smallstring := RESULT_SMALLSTRING;
  488. value_class := tclass1.create;
  489. value_boolean := RESULT_BOOLEAN;
  490. value_char := RESULT_CHAR;
  491. value_s64real:=RESULT_S64REAL;
  492. proc_value_smallarray_const_1_inline([value_u8bit,value_ptr,value_s64bit,value_char,value_smallstring,value_s64real,value_boolean,value_class]);
  493. if global_u8bit <> RESULT_U8BIT then
  494. failed := true;
  495. if global_char <> RESULT_CHAR then
  496. failed := true;
  497. if global_boolean <> RESULT_BOOLEAN then
  498. failed:=true;
  499. if trunc(global_s64real) <> trunc(RESULT_S64REAL) then
  500. failed := true;
  501. if global_bigstring <> RESULT_SMALLSTRING then
  502. failed := true;
  503. if global_ptr <> value_ptr then
  504. failed := true;
  505. { if value_class <> global_class then
  506. failed := true;!!!!!!!!!!!!!!!!!!!!}
  507. if global_s64bit <> RESULT_S64BIT then
  508. failed := true;
  509. if assigned(value_class) then
  510. value_class.destroy;
  511. global_u8bit := 0;
  512. proc_value_smallarray_const_2_inline([]);
  513. if global_u8bit <> RESULT_U8BIT then
  514. failed := true;
  515. if failed then
  516. fail
  517. else
  518. WriteLn('Passed!');
  519. end.