tcalfun9.pp 33 KB

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