tcalfun4.pp 32 KB

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