tcalfun9.pp 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447
  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. { (function return values with saveregs calling cnvs) }
  19. { (also tests nested routines up to 2 level deep) }
  20. {****************************************************************}
  21. program tcalfun9;
  22. {$ifdef fpc}
  23. {$mode objfpc}
  24. {$INLINE ON}
  25. {$endif}
  26. {$R+}
  27. {$P-}
  28. {$ifdef VER70}
  29. {$define tp}
  30. {$endif}
  31. { REAL should map to single or double }
  32. { so it is not checked, since single }
  33. { double nodes are checked. }
  34. { assumes that enumdef is the same as orddef (same storage format) }
  35. const
  36. { should be defined depending on CPU target }
  37. {$ifdef fpc}
  38. {$ifdef cpu68k}
  39. BIG_INDEX = 12000;
  40. MEDIUM_INDEX = 5000;
  41. SMALL_INDEX = 13;
  42. {$else}
  43. BIG_INDEX = 33000;
  44. MEDIUM_INDEX = 5000;
  45. SMALL_INDEX = 13; { value should not be aligned! }
  46. {$endif}
  47. {$else}
  48. BIG_INDEX = 33000;
  49. MEDIUM_INDEX = 5000;
  50. SMALL_INDEX = 13; { value should not be aligned! }
  51. {$endif}
  52. RESULT_U8BIT = $55;
  53. RESULT_U16BIT = $500F;
  54. RESULT_S32BIT = $500F0000;
  55. RESULT_S64BIT = $500F0000;
  56. RESULT_S32REAL = 1777.12;
  57. RESULT_S64REAL = 3444.24;
  58. RESULT_BOOL8BIT = 1;
  59. RESULT_BOOL16BIT = 1;
  60. RESULT_BOOL32BIT = 1;
  61. RESULT_PCHAR = 'Hello world';
  62. RESULT_BIGSTRING = 'Hello world';
  63. RESULT_SMALLSTRING = 'H';
  64. RESULT_CHAR = 'I';
  65. RESULT_BOOLEAN = TRUE;
  66. type
  67. {$ifndef tp}
  68. tclass1 = class
  69. end;
  70. {$else}
  71. shortstring = string;
  72. {$endif}
  73. tprocedure = procedure;
  74. tsmallrecord = packed record
  75. b: byte;
  76. w: word;
  77. end;
  78. tlargerecord = packed record
  79. b: array[1..BIG_INDEX] of byte;
  80. end;
  81. tmediumrecord = packed record
  82. b: array[1..MEDIUM_INDEX] of byte;
  83. end;
  84. tsmallarray = packed array[1..SMALL_INDEX] of byte;
  85. tsmallsetenum =
  86. (A_A,A_B,A_C,A_D);
  87. tsmallset = set of tsmallsetenum;
  88. tlargeset = set of char;
  89. tsmallstring = string[2];
  90. var
  91. global_u8bit : byte;
  92. global_u16bit : word;
  93. global_s32bit : longint;
  94. global_s32real : single;
  95. global_s64real : double;
  96. global_ptr : pchar;
  97. global_proc : tprocedure;
  98. global_bigstring : shortstring;
  99. global_boolean : boolean;
  100. global_char : char;
  101. {$ifndef tp}
  102. global_class : tclass1;
  103. global_s64bit : int64;
  104. value_s64bit : int64;
  105. value_class : tclass1;
  106. {$endif}
  107. value_ansistring : ansistring;
  108. value_u8bit : byte;
  109. value_u16bit : word;
  110. value_s32bit : longint;
  111. value_s32real : single;
  112. value_s64real : double;
  113. value_proc : tprocedure;
  114. value_ptr : pchar;
  115. value_smallrec : tsmallrecord;
  116. value_largerec : tlargerecord;
  117. value_mediumrec : tmediumrecord;
  118. value_smallset : tsmallset;
  119. value_smallstring : tsmallstring;
  120. value_bigstring : shortstring;
  121. value_largeset : tlargeset;
  122. value_smallarray : tsmallarray;
  123. value_boolean : boolean;
  124. value_char : char;
  125. procedure fail;
  126. begin
  127. WriteLn('Failure.');
  128. halt(1);
  129. end;
  130. procedure clear_globals;
  131. begin
  132. global_u8bit := 0;
  133. global_u16bit := 0;
  134. global_s32bit := 0;
  135. global_s32real := 0.0;
  136. global_s64real := 0.0;
  137. global_ptr := nil;
  138. global_proc := nil;
  139. global_bigstring := '';
  140. global_boolean := false;
  141. global_char := #0;
  142. global_s64bit := 0;
  143. global_class := nil;
  144. end;
  145. procedure clear_values;
  146. begin
  147. value_u8bit := 0;
  148. value_u16bit := 0;
  149. value_s32bit := 0;
  150. value_s32real := 0.0;
  151. value_s64real := 0.0;
  152. value_proc := nil;
  153. value_ptr := nil;
  154. fillchar(value_smallrec, sizeof(value_smallrec), #0);
  155. fillchar(value_largerec, sizeof(value_largerec), #0);
  156. fillchar(value_mediumrec, sizeof(value_mediumrec), #0);
  157. value_smallset := [];
  158. value_smallstring := '';
  159. value_bigstring := '';
  160. value_largeset := [];
  161. fillchar(value_smallarray, sizeof(value_smallarray), #0);
  162. value_boolean := false;
  163. value_char:=#0;
  164. value_ansistring := '';
  165. {$ifndef tp}
  166. value_s64bit := 0;
  167. value_class := nil;
  168. {$endif}
  169. end;
  170. {********************************* FUNCTION RESULTS *************************}
  171. { LOC_MEM return values }
  172. function func_array: tsmallarray;saveregisters;
  173. var
  174. smallarray: tsmallarray;
  175. begin
  176. fillchar(smallarray, sizeof(smallarray), #0);
  177. smallarray[1] := RESULT_U8BIT;
  178. smallarray[SMALL_INDEX] := RESULT_U8BIT;
  179. func_array := smallarray;
  180. end;
  181. function func_largerecord: tlargerecord;saveregisters;
  182. var
  183. largerecord : tlargerecord;
  184. begin
  185. fillchar(largerecord, sizeof(largerecord), #0);
  186. largerecord.b[1] := RESULT_U8BIT;
  187. largerecord.b[BIG_INDEX] := RESULT_U8BIT;
  188. func_largerecord := largerecord;
  189. end;
  190. function func_mediumrecord: tmediumrecord;saveregisters;
  191. var
  192. mediumrecord : tmediumrecord;
  193. begin
  194. fillchar(mediumrecord, sizeof(mediumrecord), #0);
  195. mediumrecord.b[1] := RESULT_U8BIT;
  196. mediumrecord.b[MEDIUM_INDEX] := RESULT_U8BIT;
  197. func_mediumrecord := mediumrecord;
  198. end;
  199. function func_shortstring: shortstring;saveregisters;
  200. begin
  201. func_shortstring := RESULT_BIGSTRING;
  202. end;
  203. function func_largeset : tlargeset;saveregisters;
  204. var
  205. largeset : tlargeset;
  206. begin
  207. largeset := ['I'];
  208. func_largeset := largeset;
  209. end;
  210. function func_u8bit : byte;saveregisters;
  211. begin
  212. func_u8bit := RESULT_U8BIT;
  213. end;
  214. function func_u16bit : word;saveregisters;
  215. begin
  216. func_u16bit := RESULT_U16BIT;
  217. end;
  218. function func_s32bit : longint;saveregisters;
  219. begin
  220. func_s32bit := RESULT_S32BIT;
  221. end;
  222. function func_s64bit : int64;saveregisters;
  223. begin
  224. func_s64bit := RESULT_S64BIT;
  225. end;
  226. function func_s32real : single;saveregisters;
  227. begin
  228. func_s32real := RESULT_S32REAL;
  229. end;
  230. function func_s64real : double;saveregisters;
  231. begin
  232. func_s64real := RESULT_S64REAl;
  233. end;
  234. function func_ansistring : ansistring;saveregisters;
  235. begin
  236. func_ansistring := RESULT_BIGSTRING;
  237. end;
  238. function func_pchar : pchar;saveregisters;
  239. begin
  240. func_pchar := RESULT_PCHAR;
  241. end;
  242. {************************** FUNCTION RESULT WITH PARAMS ******************}
  243. { LOC_MEM return values }
  244. function func_array_mixed(b: byte): tsmallarray;saveregisters;
  245. var
  246. local_b: byte;
  247. smallarray: tsmallarray;
  248. begin
  249. fillchar(smallarray, sizeof(smallarray), #0);
  250. smallarray[1] := RESULT_U8BIT;
  251. smallarray[SMALL_INDEX] := RESULT_U8BIT;
  252. func_array_mixed := smallarray;
  253. local_b:=b;
  254. global_u8bit := b;
  255. end;
  256. function func_largerecord_mixed(b: byte): tlargerecord;saveregisters;
  257. var
  258. local_b: byte;
  259. largerecord : tlargerecord;
  260. begin
  261. fillchar(largerecord, sizeof(largerecord), #0);
  262. largerecord.b[1] := RESULT_U8BIT;
  263. largerecord.b[BIG_INDEX] := RESULT_U8BIT;
  264. func_largerecord_mixed := largerecord;
  265. local_b:=b;
  266. global_u8bit := b;
  267. end;
  268. function func_shortstring_mixed(b: byte): shortstring;saveregisters;
  269. var
  270. local_b: byte;
  271. begin
  272. func_shortstring_mixed := RESULT_BIGSTRING;
  273. local_b:=b;
  274. global_u8bit := b;
  275. end;
  276. function func_largeset_mixed(b: byte) : tlargeset;saveregisters;
  277. var
  278. local_b: byte;
  279. largeset : tlargeset;
  280. begin
  281. largeset := ['I'];
  282. func_largeset_mixed := largeset;
  283. local_b:=b;
  284. global_u8bit := b;
  285. end;
  286. function func_u8bit_mixed(b: byte) : byte;saveregisters;
  287. var
  288. local_b: byte;
  289. begin
  290. func_u8bit_mixed := RESULT_U8BIT;
  291. local_b:=b;
  292. global_u8bit := b;
  293. end;
  294. function func_u16bit_mixed(b: byte) : word;saveregisters;
  295. var
  296. local_b: byte;
  297. begin
  298. func_u16bit_mixed := RESULT_U16BIT;
  299. local_b:=b;
  300. global_u8bit := b;
  301. end;
  302. function func_s32bit_mixed(b: byte) : longint;saveregisters;
  303. var
  304. local_b: byte;
  305. begin
  306. func_s32bit_mixed := RESULT_S32BIT;
  307. local_b:=b;
  308. global_u8bit := b;
  309. end;
  310. function func_s64bit_mixed(b: byte) : int64;saveregisters;
  311. var
  312. local_b: byte;
  313. begin
  314. func_s64bit_mixed := RESULT_S64BIT;
  315. local_b:=b;
  316. global_u8bit := b;
  317. end;
  318. function func_s32real_mixed(b: byte) : single;saveregisters;
  319. var
  320. local_b: byte;
  321. begin
  322. func_s32real_mixed := RESULT_S32REAL;
  323. local_b:=b;
  324. global_u8bit := b;
  325. end;
  326. function func_s64real_mixed(b: byte) : double;saveregisters;
  327. var
  328. local_b: byte;
  329. begin
  330. func_s64real_mixed := RESULT_S64REAl;
  331. local_b:=b;
  332. global_u8bit := b;
  333. end;
  334. function func_ansistring_mixed(b: byte) : ansistring;saveregisters;
  335. var
  336. local_b: byte;
  337. begin
  338. func_ansistring_mixed := RESULT_BIGSTRING;
  339. local_b:=b;
  340. global_u8bit := b;
  341. end;
  342. function func_pchar_mixed(b: byte) : pchar;saveregisters;
  343. var
  344. local_b: byte;
  345. begin
  346. func_pchar_mixed := RESULT_PCHAR;
  347. local_b:=b;
  348. global_u8bit := b;
  349. end;
  350. {********************* FUNCTION RESULT WITH PARAMS (NESTED) ******************}
  351. { LOC_MEM return values }
  352. function func_array_mixed_nested(b: byte): tsmallarray;saveregisters;
  353. procedure nested_one_proc(l: longint);
  354. begin
  355. global_u16bit := b;
  356. global_s32bit := l;
  357. end;
  358. procedure nested_two_proc(l : longint);
  359. begin
  360. global_s64bit := l;
  361. end;
  362. function nested_one_func(level1_b : byte; s: shortstring): byte;
  363. var
  364. s1 : shortstring;
  365. function nested_two_func(level2_b : byte; s :shortstring): byte;
  366. begin
  367. nested_two_func:=level2_b;
  368. global_bigstring := s;
  369. nested_one_proc(RESULT_S32BIT);
  370. end;
  371. begin
  372. s1:=s;
  373. nested_one_func := nested_two_func(level1_b,s1);
  374. nested_two_proc(level1_b);
  375. end;
  376. var
  377. local_b: byte;
  378. smallarray: tsmallarray;
  379. begin
  380. fillchar(smallarray, sizeof(smallarray), #0);
  381. smallarray[1] := RESULT_U8BIT;
  382. smallarray[SMALL_INDEX] := RESULT_U8BIT;
  383. func_array_mixed_nested := smallarray;
  384. local_b:=b;
  385. global_u8bit := nested_one_func(local_b, RESULT_BIGSTRING);
  386. { nested_one_proc(RESULT_S32BIT);}
  387. end;
  388. function func_largerecord_mixed_nested(b: byte): tlargerecord;saveregisters;
  389. procedure nested_one_proc(l: longint);
  390. begin
  391. global_u16bit := b;
  392. global_s32bit := l;
  393. end;
  394. procedure nested_two_proc(l : longint);
  395. begin
  396. global_s64bit := l;
  397. end;
  398. function nested_one_func(level1_b : byte; s: shortstring): byte;
  399. var
  400. s1 : shortstring;
  401. function nested_two_func(level2_b : byte; s :shortstring): byte;
  402. begin
  403. nested_two_func:=level2_b;
  404. global_bigstring := s;
  405. nested_one_proc(RESULT_S32BIT);
  406. end;
  407. begin
  408. s1:=s;
  409. nested_one_func := nested_two_func(level1_b,s1);
  410. nested_two_proc(level1_b);
  411. end;
  412. var
  413. local_b: byte;
  414. largerecord : tlargerecord;
  415. begin
  416. fillchar(largerecord, sizeof(largerecord), #0);
  417. largerecord.b[1] := RESULT_U8BIT;
  418. largerecord.b[BIG_INDEX] := RESULT_U8BIT;
  419. func_largerecord_mixed_nested := largerecord;
  420. local_b:=b;
  421. global_u8bit := nested_one_func(local_b, RESULT_BIGSTRING);
  422. end;
  423. function func_shortstring_mixed_nested(b: byte): shortstring;saveregisters;
  424. procedure nested_one_proc(l: longint);
  425. begin
  426. global_u16bit := b;
  427. global_s32bit := l;
  428. end;
  429. procedure nested_two_proc(l : longint);
  430. begin
  431. global_s64bit := l;
  432. end;
  433. function nested_one_func(level1_b : byte; s: shortstring): byte;
  434. var
  435. s1 : shortstring;
  436. function nested_two_func(level2_b : byte; s :shortstring): byte;
  437. begin
  438. nested_two_func:=level2_b;
  439. global_bigstring := s;
  440. nested_one_proc(RESULT_S32BIT);
  441. end;
  442. begin
  443. s1:=s;
  444. nested_one_func := nested_two_func(level1_b,s1);
  445. nested_two_proc(level1_b);
  446. end;
  447. var
  448. local_b: byte;
  449. begin
  450. func_shortstring_mixed_nested := RESULT_BIGSTRING;
  451. local_b:=b;
  452. global_u8bit := nested_one_func(local_b, RESULT_BIGSTRING);
  453. end;
  454. function func_largeset_mixed_nested(b: byte) : tlargeset;saveregisters;
  455. procedure nested_one_proc(l: longint);
  456. begin
  457. global_u16bit := b;
  458. global_s32bit := l;
  459. end;
  460. procedure nested_two_proc(l : longint);
  461. begin
  462. global_s64bit := l;
  463. end;
  464. function nested_one_func(level1_b : byte; s: shortstring): byte;
  465. var
  466. s1 : shortstring;
  467. function nested_two_func(level2_b : byte; s :shortstring): byte;
  468. begin
  469. nested_two_func:=level2_b;
  470. global_bigstring := s;
  471. nested_one_proc(RESULT_S32BIT);
  472. end;
  473. begin
  474. s1:=s;
  475. nested_one_func := nested_two_func(level1_b,s1);
  476. nested_two_proc(level1_b);
  477. end;
  478. var
  479. local_b: byte;
  480. largeset : tlargeset;
  481. begin
  482. largeset := ['I'];
  483. func_largeset_mixed_nested := largeset;
  484. local_b:=b;
  485. global_u8bit := nested_one_func(local_b, RESULT_BIGSTRING);
  486. end;
  487. function func_u8bit_mixed_nested(b: byte) : byte;saveregisters;
  488. procedure nested_one_proc(l: longint);
  489. begin
  490. global_u16bit := b;
  491. global_s32bit := l;
  492. end;
  493. procedure nested_two_proc(l : longint);
  494. begin
  495. global_s64bit := l;
  496. end;
  497. function nested_one_func(level1_b : byte; s: shortstring): byte;
  498. var
  499. s1 : shortstring;
  500. function nested_two_func(level2_b : byte; s :shortstring): byte;
  501. begin
  502. nested_two_func:=level2_b;
  503. global_bigstring := s;
  504. nested_one_proc(RESULT_S32BIT);
  505. end;
  506. begin
  507. s1:=s;
  508. nested_one_func := nested_two_func(level1_b,s1);
  509. nested_two_proc(level1_b);
  510. end;
  511. var
  512. local_b: byte;
  513. begin
  514. func_u8bit_mixed_nested := RESULT_U8BIT;
  515. local_b:=b;
  516. global_u8bit := nested_one_func(local_b, RESULT_BIGSTRING);
  517. end;
  518. function func_u16bit_mixed_nested(b: byte) : word;saveregisters;
  519. procedure nested_one_proc(l: longint);
  520. begin
  521. global_u16bit := b;
  522. global_s32bit := l;
  523. end;
  524. procedure nested_two_proc(l : longint);
  525. begin
  526. global_s64bit := l;
  527. end;
  528. function nested_one_func(level1_b : byte; s: shortstring): byte;
  529. var
  530. s1 : shortstring;
  531. function nested_two_func(level2_b : byte; s :shortstring): byte;
  532. begin
  533. nested_two_func:=level2_b;
  534. global_bigstring := s;
  535. nested_one_proc(RESULT_S32BIT);
  536. end;
  537. begin
  538. s1:=s;
  539. nested_one_func := nested_two_func(level1_b,s1);
  540. nested_two_proc(level1_b);
  541. end;
  542. var
  543. local_b: byte;
  544. begin
  545. func_u16bit_mixed_nested := RESULT_U16BIT;
  546. local_b:=b;
  547. global_u8bit := nested_one_func(local_b, RESULT_BIGSTRING);
  548. end;
  549. function func_s32bit_mixed_nested(b: byte) : longint;saveregisters;
  550. procedure nested_one_proc(l: longint);
  551. begin
  552. global_u16bit := b;
  553. global_s32bit := l;
  554. end;
  555. procedure nested_two_proc(l : longint);
  556. begin
  557. global_s64bit := l;
  558. end;
  559. function nested_one_func(level1_b : byte; s: shortstring): byte;
  560. var
  561. s1 : shortstring;
  562. function nested_two_func(level2_b : byte; s :shortstring): byte;
  563. begin
  564. nested_two_func:=level2_b;
  565. global_bigstring := s;
  566. nested_one_proc(RESULT_S32BIT);
  567. end;
  568. begin
  569. s1:=s;
  570. nested_one_func := nested_two_func(level1_b,s1);
  571. nested_two_proc(level1_b);
  572. end;
  573. var
  574. local_b: byte;
  575. begin
  576. func_s32bit_mixed_nested := RESULT_S32BIT;
  577. local_b:=b;
  578. global_u8bit := nested_one_func(local_b, RESULT_BIGSTRING);
  579. end;
  580. function func_s64bit_mixed_nested(b: byte) : int64;saveregisters;
  581. procedure nested_one_proc(l: longint);
  582. begin
  583. global_u16bit := b;
  584. global_s32bit := l;
  585. end;
  586. procedure nested_two_proc(l : longint);
  587. begin
  588. global_s64bit := l;
  589. end;
  590. function nested_one_func(level1_b : byte; s: shortstring): byte;
  591. var
  592. s1 : shortstring;
  593. function nested_two_func(level2_b : byte; s :shortstring): byte;
  594. begin
  595. nested_two_func:=level2_b;
  596. global_bigstring := s;
  597. nested_one_proc(RESULT_S32BIT);
  598. end;
  599. begin
  600. s1:=s;
  601. nested_one_func := nested_two_func(level1_b,s1);
  602. nested_two_proc(level1_b);
  603. end;
  604. var
  605. local_b: byte;
  606. begin
  607. func_s64bit_mixed_nested := RESULT_S64BIT;
  608. local_b:=b;
  609. global_u8bit := nested_one_func(local_b, RESULT_BIGSTRING);
  610. end;
  611. function func_s32real_mixed_nested(b: byte) : single;saveregisters;
  612. procedure nested_one_proc(l: longint);
  613. begin
  614. global_u16bit := b;
  615. global_s32bit := l;
  616. end;
  617. procedure nested_two_proc(l : longint);
  618. begin
  619. global_s64bit := l;
  620. end;
  621. function nested_one_func(level1_b : byte; s: shortstring): byte;
  622. var
  623. s1 : shortstring;
  624. function nested_two_func(level2_b : byte; s :shortstring): byte;
  625. begin
  626. nested_two_func:=level2_b;
  627. global_bigstring := s;
  628. nested_one_proc(RESULT_S32BIT);
  629. end;
  630. begin
  631. s1:=s;
  632. nested_one_func := nested_two_func(level1_b,s1);
  633. nested_two_proc(level1_b);
  634. end;
  635. var
  636. local_b: byte;
  637. begin
  638. func_s32real_mixed_nested := RESULT_S32REAL;
  639. local_b:=b;
  640. global_u8bit := nested_one_func(local_b, RESULT_BIGSTRING);
  641. end;
  642. function func_s64real_mixed_nested(b: byte) : double;saveregisters;
  643. procedure nested_one_proc(l: longint);
  644. begin
  645. global_u16bit := b;
  646. global_s32bit := l;
  647. end;
  648. procedure nested_two_proc(l : longint);
  649. begin
  650. global_s64bit := l;
  651. end;
  652. function nested_one_func(level1_b : byte; s: shortstring): byte;
  653. var
  654. s1 : shortstring;
  655. function nested_two_func(level2_b : byte; s :shortstring): byte;
  656. begin
  657. nested_two_func:=level2_b;
  658. global_bigstring := s;
  659. nested_one_proc(RESULT_S32BIT);
  660. end;
  661. begin
  662. s1:=s;
  663. nested_one_func := nested_two_func(level1_b,s1);
  664. nested_two_proc(level1_b);
  665. end;
  666. var
  667. local_b: byte;
  668. begin
  669. func_s64real_mixed_nested := RESULT_S64REAl;
  670. local_b:=b;
  671. global_u8bit := nested_one_func(local_b, RESULT_BIGSTRING);
  672. end;
  673. function func_ansistring_mixed_nested(b: byte) : ansistring;saveregisters;
  674. procedure nested_one_proc(l: longint);
  675. begin
  676. global_u16bit := b;
  677. global_s32bit := l;
  678. end;
  679. procedure nested_two_proc(l : longint);
  680. begin
  681. global_s64bit := l;
  682. end;
  683. function nested_one_func(level1_b : byte; s: shortstring): byte;
  684. var
  685. s1 : shortstring;
  686. function nested_two_func(level2_b : byte; s :shortstring): byte;
  687. begin
  688. nested_two_func:=level2_b;
  689. global_bigstring := s;
  690. nested_one_proc(RESULT_S32BIT);
  691. end;
  692. begin
  693. s1:=s;
  694. nested_one_func := nested_two_func(level1_b,s1);
  695. nested_two_proc(level1_b);
  696. end;
  697. var
  698. local_b: byte;
  699. begin
  700. func_ansistring_mixed_nested := RESULT_BIGSTRING;
  701. local_b:=b;
  702. global_u8bit := nested_one_func(local_b, RESULT_BIGSTRING);
  703. end;
  704. function func_pchar_mixed_nested(b: byte) : pchar;saveregisters;
  705. procedure nested_one_proc(l: longint);
  706. begin
  707. global_u16bit := b;
  708. global_s32bit := l;
  709. end;
  710. procedure nested_two_proc(l : longint);
  711. begin
  712. global_s64bit := l;
  713. end;
  714. function nested_one_func(level1_b : byte; s: shortstring): byte;
  715. var
  716. s1 : shortstring;
  717. function nested_two_func(level2_b : byte; s :shortstring): byte;
  718. begin
  719. nested_two_func:=level2_b;
  720. global_bigstring := s;
  721. nested_one_proc(RESULT_S32BIT);
  722. end;
  723. begin
  724. s1:=s;
  725. nested_one_func := nested_two_func(level1_b,s1);
  726. nested_two_proc(level1_b);
  727. end;
  728. var
  729. local_b: byte;
  730. begin
  731. func_pchar_mixed_nested := RESULT_PCHAR;
  732. local_b:=b;
  733. global_u8bit := nested_one_func(local_b, RESULT_BIGSTRING);
  734. end;
  735. var
  736. failed: boolean;
  737. Begin
  738. {************************************* SIMPLE TESTS ***********************************}
  739. write('Testing function results (LOC_REFERENCE)...');
  740. clear_globals;
  741. clear_values;
  742. failed := false;
  743. value_smallarray := func_array;
  744. if (value_smallarray[1] <> RESULT_U8BIT) or (value_smallarray[SMALL_INDEX] <> RESULT_U8BIT) then
  745. failed := true;
  746. clear_globals;
  747. clear_values;
  748. value_largerec := func_largerecord;
  749. if (value_largerec.b[1] <> RESULT_U8BIT) or (value_largerec.b[BIG_INDEX] <> RESULT_U8BIT) then
  750. failed:=true;
  751. clear_globals;
  752. clear_values;
  753. value_mediumrec := func_mediumrecord;
  754. if (value_mediumrec.b[1] <> RESULT_U8BIT) or (value_mediumrec.b[MEDIUM_INDEX] <> RESULT_U8BIT) then
  755. failed:=true;
  756. clear_globals;
  757. clear_values;
  758. value_bigstring := func_shortstring;
  759. if value_bigstring <> RESULT_BIGSTRING then
  760. failed := true;
  761. clear_globals;
  762. clear_values;
  763. value_largeset := func_largeset;
  764. if not ('I' in value_largeset) then
  765. failed := true;
  766. if failed then
  767. fail
  768. else
  769. WriteLn('Passed!');
  770. write('Testing orddef/enumdef function results (LOC_REGISTER)...');
  771. clear_globals;
  772. clear_values;
  773. failed := false;
  774. value_u8bit := func_u8bit;
  775. if value_u8bit <> RESULT_U8BIT then
  776. failed := true;
  777. clear_globals;
  778. clear_values;
  779. value_u16bit := func_u16bit;
  780. if value_u16bit <> RESULT_U16BIT then
  781. failed := true;
  782. clear_globals;
  783. clear_values;
  784. value_s32bit := func_s32bit;
  785. if value_s32bit <> RESULT_S32BIT then
  786. failed := true;
  787. clear_globals;
  788. clear_values;
  789. value_s64bit := func_s64bit;
  790. if value_s64bit <> RESULT_S64BIT then
  791. failed := true;
  792. if failed then
  793. fail
  794. else
  795. WriteLn('Passed!');
  796. write('Testing floatdef function results...');
  797. clear_globals;
  798. clear_values;
  799. failed := false;
  800. clear_globals;
  801. clear_values;
  802. value_s32real := func_s32real;
  803. if trunc(value_s32real) <> trunc(RESULT_S32REAL) then
  804. failed:=true;
  805. clear_globals;
  806. clear_values;
  807. value_s64real := func_s64real;
  808. if trunc(value_s64real) <> trunc(RESULT_S64REAL) then
  809. failed:=true;
  810. if failed then
  811. fail
  812. else
  813. WriteLn('Passed!');
  814. write('Testing ansistring function result...');
  815. clear_globals;
  816. clear_values;
  817. failed := false;
  818. value_ansistring := func_ansistring;
  819. if value_ansistring <> RESULT_BIGSTRING then
  820. failed:=true;
  821. if failed then
  822. fail
  823. else
  824. WriteLn('Passed!');
  825. write('Testing pointer function result (LOC_REGISTER)...');
  826. clear_globals;
  827. clear_values;
  828. failed := false;
  829. value_ptr := func_pchar;
  830. if value_ptr <> RESULT_PCHAR then
  831. failed := true;
  832. if failed then
  833. fail
  834. else
  835. WriteLn('Passed!');
  836. {*********************************** TESTS W/PARAMS ***********************************}
  837. write('Testing function results with parameter (LOC_REFERENCE)...');
  838. clear_globals;
  839. clear_values;
  840. failed := false;
  841. value_smallarray := func_array_mixed(RESULT_U8BIT);
  842. if (value_smallarray[1] <> RESULT_U8BIT) or (value_smallarray[SMALL_INDEX] <> RESULT_U8BIT) then
  843. failed := true;
  844. if global_u8bit <> RESULT_U8BIT then
  845. failed := true;
  846. clear_globals;
  847. clear_values;
  848. value_largerec := func_largerecord_mixed(RESULT_U8BIT);
  849. if (value_largerec.b[1] <> RESULT_U8BIT) or (value_largerec.b[BIG_INDEX] <> RESULT_U8BIT) then
  850. failed:=true;
  851. if global_u8bit <> RESULT_U8BIT then
  852. failed := true;
  853. clear_globals;
  854. clear_values;
  855. value_bigstring := func_shortstring_mixed(RESULT_U8BIT);
  856. if value_bigstring <> RESULT_BIGSTRING then
  857. failed := true;
  858. if global_u8bit <> RESULT_U8BIT then
  859. failed := true;
  860. clear_globals;
  861. clear_values;
  862. value_largeset := func_largeset_mixed(RESULT_U8BIT);
  863. if not ('I' in value_largeset) then
  864. failed := true;
  865. if global_u8bit <> RESULT_U8BIT then
  866. failed := true;
  867. if failed then
  868. fail
  869. else
  870. WriteLn('Passed!');
  871. write('Testing orddef/enumdef function results with parameter (LOC_REGISTER)...');
  872. clear_globals;
  873. clear_values;
  874. failed := false;
  875. value_u8bit := func_u8bit_mixed(RESULT_U8BIT);
  876. if value_u8bit <> RESULT_U8BIT then
  877. failed := true;
  878. if global_u8bit <> RESULT_U8BIT then
  879. failed := true;
  880. clear_globals;
  881. clear_values;
  882. value_u16bit := func_u16bit_mixed(RESULT_U8BIT);
  883. if value_u16bit <> RESULT_U16BIT then
  884. failed := true;
  885. if global_u8bit <> RESULT_U8BIT then
  886. failed := true;
  887. clear_globals;
  888. clear_values;
  889. value_s32bit := func_s32bit_mixed(RESULT_U8BIT);
  890. if value_s32bit <> RESULT_S32BIT then
  891. failed := true;
  892. if global_u8bit <> RESULT_U8BIT then
  893. failed := true;
  894. clear_globals;
  895. clear_values;
  896. value_s64bit := func_s64bit_mixed(RESULT_U8BIT);
  897. if value_s64bit <> RESULT_S64BIT then
  898. failed := true;
  899. if global_u8bit <> RESULT_U8BIT then
  900. failed := true;
  901. if failed then
  902. fail
  903. else
  904. WriteLn('Passed!');
  905. write('Testing floatdef function results with parameter...');
  906. clear_globals;
  907. clear_values;
  908. failed := false;
  909. value_s32real := func_s32real_mixed(RESULT_U8BIT);
  910. if trunc(value_s32real) <> trunc(RESULT_S32REAL) then
  911. failed:=true;
  912. if global_u8bit <> RESULT_U8BIT then
  913. failed := true;
  914. clear_globals;
  915. clear_values;
  916. value_s64real := func_s64real_mixed(RESULT_U8BIT);
  917. if trunc(value_s64real) <> trunc(RESULT_S64REAL) then
  918. failed:=true;
  919. if global_u8bit <> RESULT_U8BIT then
  920. failed := true;
  921. if failed then
  922. fail
  923. else
  924. WriteLn('Passed!');
  925. write('Testing ansistring function result with parameter...');
  926. clear_globals;
  927. clear_values;
  928. failed := false;
  929. value_ansistring := func_ansistring_mixed(RESULT_U8BIT);
  930. if value_ansistring <> RESULT_BIGSTRING then
  931. failed:=true;
  932. if global_u8bit <> RESULT_U8BIT then
  933. failed := true;
  934. if failed then
  935. fail
  936. else
  937. WriteLn('Passed!');
  938. write('Testing pointer function result with parameter (LOC_REGISTER)...');
  939. clear_globals;
  940. clear_values;
  941. failed := false;
  942. value_ptr := func_pchar_mixed(RESULT_U8BIT);
  943. if value_ptr <> RESULT_PCHAR then
  944. failed := true;
  945. if global_u8bit <> RESULT_U8BIT then
  946. failed := true;
  947. if failed then
  948. fail
  949. else
  950. WriteLn('Passed!');
  951. {******************************NESTED TESTS W/PARAMS **********************************}
  952. write('Testing function (w/nesting) results with parameter (LOC_REFERENCE)...');
  953. clear_globals;
  954. clear_values;
  955. failed := false;
  956. value_smallarray := func_array_mixed_nested(RESULT_U8BIT);
  957. if (value_smallarray[1] <> RESULT_U8BIT) or (value_smallarray[SMALL_INDEX] <> RESULT_U8BIT) then
  958. failed := true;
  959. if global_u8bit <> RESULT_U8BIT then
  960. failed := true;
  961. if global_bigstring <> RESULT_BIGSTRING then
  962. failed := true;
  963. if global_u16bit <> RESULT_U8BIT then
  964. failed := true;
  965. if global_s32bit <> RESULT_S32BIT then
  966. failed := true;
  967. if global_s64bit <> RESULT_U8BIT then
  968. failed := true;
  969. clear_globals;
  970. clear_values;
  971. value_largerec := func_largerecord_mixed_nested(RESULT_U8BIT);
  972. if (value_largerec.b[1] <> RESULT_U8BIT) or (value_largerec.b[BIG_INDEX] <> RESULT_U8BIT) then
  973. failed:=true;
  974. if global_u8bit <> RESULT_U8BIT then
  975. failed := true;
  976. if global_bigstring <> RESULT_BIGSTRING then
  977. failed := true;
  978. if global_u16bit <> RESULT_U8BIT then
  979. failed := true;
  980. if global_s64bit <> RESULT_U8BIT then
  981. failed := true;
  982. if global_s32bit <> RESULT_S32BIT then
  983. failed := true;
  984. clear_globals;
  985. clear_values;
  986. value_bigstring := func_shortstring_mixed_nested(RESULT_U8BIT);
  987. if value_bigstring <> RESULT_BIGSTRING then
  988. failed := true;
  989. if global_u8bit <> RESULT_U8BIT then
  990. failed := true;
  991. if global_bigstring <> RESULT_BIGSTRING then
  992. failed := true;
  993. if global_u16bit <> RESULT_U8BIT then
  994. failed := true;
  995. if global_s32bit <> RESULT_S32BIT then
  996. failed := true;
  997. if global_s64bit <> RESULT_U8BIT then
  998. failed := true;
  999. clear_globals;
  1000. clear_values;
  1001. value_largeset := func_largeset_mixed_nested(RESULT_U8BIT);
  1002. if not ('I' in value_largeset) then
  1003. failed := true;
  1004. if global_u8bit <> RESULT_U8BIT then
  1005. failed := true;
  1006. if global_bigstring <> RESULT_BIGSTRING then
  1007. failed := true;
  1008. if global_u16bit <> RESULT_U8BIT then
  1009. failed := true;
  1010. if global_s32bit <> RESULT_S32BIT then
  1011. failed := true;
  1012. if global_s64bit <> RESULT_U8BIT then
  1013. failed := true;
  1014. if failed then
  1015. fail
  1016. else
  1017. WriteLn('Passed!');
  1018. write('Testing orddef/enumdef function (w/nesting) results with parameter (LOC_REGISTER)...');
  1019. clear_globals;
  1020. clear_values;
  1021. failed := false;
  1022. value_u8bit := func_u8bit_mixed_nested(RESULT_U8BIT);
  1023. if value_u8bit <> RESULT_U8BIT then
  1024. failed := true;
  1025. if global_u8bit <> RESULT_U8BIT then
  1026. failed := true;
  1027. if global_bigstring <> RESULT_BIGSTRING then
  1028. failed := true;
  1029. if global_u16bit <> RESULT_U8BIT then
  1030. failed := true;
  1031. if global_s32bit <> RESULT_S32BIT then
  1032. failed := true;
  1033. if global_s64bit <> RESULT_U8BIT then
  1034. failed := true;
  1035. clear_globals;
  1036. clear_values;
  1037. value_u16bit := func_u16bit_mixed_nested(RESULT_U8BIT);
  1038. if value_u16bit <> RESULT_U16BIT then
  1039. failed := true;
  1040. if global_u8bit <> RESULT_U8BIT then
  1041. failed := true;
  1042. if global_bigstring <> RESULT_BIGSTRING then
  1043. failed := true;
  1044. if global_u16bit <> RESULT_U8BIT then
  1045. failed := true;
  1046. if global_s64bit <> RESULT_U8BIT then
  1047. failed := true;
  1048. if global_s32bit <> RESULT_S32BIT then
  1049. failed := true;
  1050. clear_globals;
  1051. clear_values;
  1052. value_s32bit := func_s32bit_mixed_nested(RESULT_U8BIT);
  1053. if value_s32bit <> RESULT_S32BIT then
  1054. failed := true;
  1055. if global_u8bit <> RESULT_U8BIT then
  1056. failed := true;
  1057. if global_bigstring <> RESULT_BIGSTRING then
  1058. failed := true;
  1059. if global_u16bit <> RESULT_U8BIT then
  1060. failed := true;
  1061. if global_s64bit <> RESULT_U8BIT then
  1062. failed := true;
  1063. if global_s32bit <> RESULT_S32BIT then
  1064. failed := true;
  1065. clear_globals;
  1066. clear_values;
  1067. value_s64bit := func_s64bit_mixed_nested(RESULT_U8BIT);
  1068. if value_s64bit <> RESULT_S64BIT then
  1069. failed := true;
  1070. if global_u8bit <> RESULT_U8BIT then
  1071. failed := true;
  1072. if global_bigstring <> RESULT_BIGSTRING then
  1073. failed := true;
  1074. if global_u16bit <> RESULT_U8BIT then
  1075. failed := true;
  1076. if global_s64bit <> RESULT_U8BIT then
  1077. failed := true;
  1078. if global_s32bit <> RESULT_S32BIT then
  1079. failed := true;
  1080. if failed then
  1081. fail
  1082. else
  1083. WriteLn('Passed!');
  1084. write('Testing floatdef function (w/nesting) results with parameter...');
  1085. clear_globals;
  1086. clear_values;
  1087. failed := false;
  1088. value_s32real := func_s32real_mixed_nested(RESULT_U8BIT);
  1089. if trunc(value_s32real) <> trunc(RESULT_S32REAL) then
  1090. failed:=true;
  1091. if global_u8bit <> RESULT_U8BIT then
  1092. failed := true;
  1093. if global_bigstring <> RESULT_BIGSTRING then
  1094. failed := true;
  1095. if global_u16bit <> RESULT_U8BIT then
  1096. failed := true;
  1097. if global_s64bit <> RESULT_U8BIT then
  1098. failed := true;
  1099. if global_s32bit <> RESULT_S32BIT then
  1100. failed := true;
  1101. clear_globals;
  1102. clear_values;
  1103. value_s64real := func_s64real_mixed_nested(RESULT_U8BIT);
  1104. if trunc(value_s64real) <> trunc(RESULT_S64REAL) then
  1105. failed:=true;
  1106. if global_u8bit <> RESULT_U8BIT then
  1107. failed := true;
  1108. if global_bigstring <> RESULT_BIGSTRING then
  1109. failed := true;
  1110. if global_u16bit <> RESULT_U8BIT then
  1111. failed := true;
  1112. if global_s64bit <> RESULT_U8BIT then
  1113. failed := true;
  1114. if global_s32bit <> RESULT_S32BIT then
  1115. failed := true;
  1116. if failed then
  1117. fail
  1118. else
  1119. WriteLn('Passed!');
  1120. write('Testing ansistring function (w/nesting) result with parameter...');
  1121. clear_globals;
  1122. clear_values;
  1123. failed := false;
  1124. value_ansistring := func_ansistring_mixed_nested(RESULT_U8BIT);
  1125. if value_ansistring <> RESULT_BIGSTRING then
  1126. failed:=true;
  1127. if global_u8bit <> RESULT_U8BIT then
  1128. failed := true;
  1129. if global_bigstring <> RESULT_BIGSTRING then
  1130. failed := true;
  1131. if global_u16bit <> RESULT_U8BIT then
  1132. failed := true;
  1133. if global_s64bit <> RESULT_U8BIT then
  1134. failed := true;
  1135. if global_s32bit <> RESULT_S32BIT then
  1136. failed := true;
  1137. if failed then
  1138. fail
  1139. else
  1140. WriteLn('Passed!');
  1141. write('Testing pointer function (w/nesting) result with parameter (LOC_REGISTER)...');
  1142. clear_globals;
  1143. clear_values;
  1144. failed := false;
  1145. value_ptr := func_pchar_mixed_nested(RESULT_U8BIT);
  1146. if value_ptr <> RESULT_PCHAR then
  1147. failed := true;
  1148. if global_u8bit <> RESULT_U8BIT then
  1149. failed := true;
  1150. if global_bigstring <> RESULT_BIGSTRING then
  1151. failed := true;
  1152. if global_u16bit <> RESULT_U8BIT then
  1153. failed := true;
  1154. if global_s64bit <> RESULT_U8BIT then
  1155. failed := true;
  1156. if global_s32bit <> RESULT_S32BIT then
  1157. failed := true;
  1158. if failed then
  1159. fail
  1160. else
  1161. WriteLn('Passed!');
  1162. end.
  1163. {
  1164. $Log$
  1165. Revision 1.5 2003-04-22 10:24:29 florian
  1166. * fixed defines for powerpc
  1167. Revision 1.4 2002/09/27 17:44:50 carl
  1168. * add testing for window-page size 4K, so as to test stack corruption
  1169. Revision 1.3 2002/09/07 15:40:51 peter
  1170. * old logs removed and tabs fixed
  1171. Revision 1.2 2002/05/13 13:45:37 peter
  1172. * updated to compile tests with kylix
  1173. Revision 1.1 2002/04/13 17:47:57 carl
  1174. + function calling withy saveregisters convention
  1175. }