tfuncret.pp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. {****************************************************************}
  2. { CODE GENERATOR TEST PROGRAM }
  3. { By Carl Eric Codere }
  4. {****************************************************************}
  5. { NODE TESTED : secondfuncret() }
  6. {****************************************************************}
  7. { DEFINES: }
  8. { FPC = Target is FreePascal compiler }
  9. {****************************************************************}
  10. { REMARKS : Tested with Delphi 3 as reference implementation }
  11. {****************************************************************}
  12. program tfuncret;
  13. {$ifdef ver70}
  14. {$define tp}
  15. {$endif}
  16. const
  17. { adjusts the size of the bigrecord }
  18. MAX_INDEX = 7;
  19. RESULT_S64BIT = -12;
  20. RESULT_S32BIT = -124356;
  21. RESULT_U32BIT = 654321;
  22. RESULT_U8BIT = $55;
  23. type
  24. {
  25. the size of this record should *at least* be the size
  26. of a natural register for the target processor
  27. }
  28. tbigrecord = record
  29. x : cardinal;
  30. y : cardinal;
  31. z : array[0..MAX_INDEX] of byte;
  32. end;
  33. procedure fail;
  34. begin
  35. WriteLn('Failure.');
  36. halt(1);
  37. end;
  38. {****************************************************************}
  39. { SIMPLE CASE }
  40. {****************************************************************}
  41. function getresult_simple_s64bit: int64;
  42. var
  43. s64bit : int64;
  44. i: integer;
  45. begin
  46. getresult_simple_s64bit := 0;
  47. s64bit:=RESULT_S64BIT;
  48. getresult_simple_s64bit := s64bit;
  49. end;
  50. function getresult_simple_s32bit: longint;
  51. var
  52. s32bit : longint;
  53. i: longint;
  54. begin
  55. getresult_simple_s32bit := 0;
  56. i:=1;
  57. i:=i*RESULT_S32BIT div i;
  58. s32bit:=i;
  59. getresult_simple_s32bit := s32bit;
  60. end;
  61. function getresult_simple_bigrecord : tbigrecord;
  62. var
  63. localbigrecord : tbigrecord;
  64. i: integer;
  65. begin
  66. localbigrecord.x := RESULT_U32BIT;
  67. localbigrecord.y := RESULT_U32BIT;
  68. for i:=0 to MAX_INDEX do
  69. localbigrecord.z[i] := RESULT_U8BIT;
  70. getresult_simple_bigrecord := localbigrecord;
  71. end;
  72. {****************************************************************}
  73. { WITH NESTING }
  74. {****************************************************************}
  75. function getresult_nested_s64bit: int64;
  76. procedure nested_one;
  77. var
  78. s64bit : int64;
  79. i: longint;
  80. begin
  81. getresult_nested_s64bit := 0;
  82. s64bit:=RESULT_S64BIT;
  83. getresult_nested_s64bit := s64bit;
  84. end;
  85. begin
  86. nested_one;
  87. end;
  88. function getresult_nested_s32bit: longint;
  89. procedure nested_one;
  90. var
  91. s32bit : longint;
  92. i: longint;
  93. begin
  94. getresult_nested_s32bit := 0;
  95. i:=1;
  96. i:=i*RESULT_S32BIT div i;
  97. s32bit:=i;
  98. getresult_nested_s32bit := s32bit;
  99. end;
  100. begin
  101. nested_one;
  102. end;
  103. function getresult_nested_bigrecord : tbigrecord;
  104. procedure nested_one;
  105. var
  106. localbigrecord : tbigrecord;
  107. i: longint;
  108. begin
  109. localbigrecord.x := RESULT_U32BIT;
  110. localbigrecord.y := RESULT_U32BIT;
  111. for i:=0 to MAX_INDEX do
  112. localbigrecord.z[i] := RESULT_U8BIT;
  113. getresult_nested_bigrecord := localbigrecord;
  114. end;
  115. begin
  116. nested_one;
  117. end;
  118. {****************************************************************}
  119. { WITH COMPLEX NESTING }
  120. {****************************************************************}
  121. function getresult_nested_complex_s64bit: int64;
  122. procedure nested_one;
  123. var
  124. s64bit : int64;
  125. i: integer;
  126. function nested_two: int64;
  127. begin
  128. nested_two:=0;
  129. getresult_nested_complex_s64bit := 0;
  130. s64bit:=RESULT_S64BIT;
  131. getresult_nested_complex_s64bit := s64bit;
  132. end;
  133. begin
  134. nested_two;
  135. end;
  136. begin
  137. nested_one;
  138. end;
  139. function getresult_nested_complex_s32bit: longint;
  140. procedure nested_one;
  141. var
  142. s32bit : longint;
  143. i: longint;
  144. function nested_two: longint;
  145. begin
  146. nested_two := 0;
  147. getresult_nested_complex_s32bit := 0;
  148. i:=1;
  149. i:=i*RESULT_S32BIT div i;
  150. s32bit:=i;
  151. getresult_nested_complex_s32bit := s32bit;
  152. end;
  153. begin
  154. nested_two;
  155. end;
  156. begin
  157. nested_one;
  158. end;
  159. function getresult_nested_complex_bigrecord : tbigrecord;
  160. procedure nested_one;
  161. var
  162. localbigrecord : tbigrecord;
  163. function nested_two : tbigrecord;
  164. var
  165. i : integer;
  166. begin
  167. nested_two := localbigrecord;
  168. localbigrecord.x := RESULT_U32BIT;
  169. localbigrecord.y := RESULT_U32BIT;
  170. for i:=0 to MAX_INDEX do
  171. localbigrecord.z[i] := RESULT_U8BIT;
  172. getresult_nested_complex_bigrecord := localbigrecord;
  173. end;
  174. begin
  175. nested_two;
  176. end;
  177. begin
  178. nested_one;
  179. end;
  180. var
  181. failed : boolean;
  182. bigrecord : tbigrecord;
  183. i: integer;
  184. Begin
  185. Write('secondfuncret simple case tests...');
  186. failed := false;
  187. if getresult_simple_s64bit <> RESULT_S64BIT then
  188. failed := true;
  189. if getresult_simple_s32bit <> RESULT_S32BIT then
  190. failed := true;
  191. bigrecord := getresult_simple_bigrecord;
  192. if bigrecord.x <> RESULT_U32BIT then
  193. failed := true;
  194. if bigrecord.y <> RESULT_U32BIT then
  195. failed := true;
  196. for i:=0 to MAX_INDEX do
  197. begin
  198. if bigrecord.z[i] <> RESULT_U8BIT then
  199. begin
  200. failed := true;
  201. break;
  202. end;
  203. end;
  204. if failed then
  205. fail
  206. else
  207. WriteLn('Success!');
  208. Write('secondfuncret simple nesting case tests...');
  209. failed := false;
  210. if getresult_nested_s64bit <> RESULT_S64BIT then
  211. failed := true;
  212. if getresult_nested_s32bit <> RESULT_S32BIT then
  213. failed := true;
  214. bigrecord := getresult_nested_bigrecord;
  215. if bigrecord.x <> RESULT_U32BIT then
  216. failed := true;
  217. if bigrecord.y <> RESULT_U32BIT then
  218. failed := true;
  219. for i:=0 to MAX_INDEX do
  220. begin
  221. if bigrecord.z[i] <> RESULT_U8BIT then
  222. begin
  223. failed := true;
  224. break;
  225. end;
  226. end;
  227. if failed then
  228. fail
  229. else
  230. WriteLn('Success!');
  231. Write('secondfuncret complex nesting case tests...');
  232. failed := false;
  233. if getresult_nested_complex_s64bit <> RESULT_S64BIT then
  234. failed := true;
  235. if getresult_nested_complex_s32bit <> RESULT_S32BIT then
  236. failed := true;
  237. bigrecord := getresult_nested_complex_bigrecord;
  238. if bigrecord.x <> RESULT_U32BIT then
  239. failed := true;
  240. if bigrecord.y <> RESULT_U32BIT then
  241. failed := true;
  242. for i:=0 to MAX_INDEX do
  243. begin
  244. if bigrecord.z[i] <> RESULT_U8BIT then
  245. begin
  246. failed := true;
  247. break;
  248. end;
  249. end;
  250. if failed then
  251. fail
  252. else
  253. WriteLn('Success!');
  254. end.