tcalfun9.pp 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430
  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.