tcalval2.pp 16 KB

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