texit.pp 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. {****************************************************************}
  2. { CODE GENERATOR TEST PROGRAM }
  3. { By Carl Eric Codere }
  4. {****************************************************************}
  5. { NODE TESTED : secondexitn() }
  6. {****************************************************************}
  7. { PRE-REQUISITES: secondload() }
  8. { secondassign() }
  9. { secondtypeconv() }
  10. { secondcalln() }
  11. { secondin() }
  12. {****************************************************************}
  13. { DEFINES: }
  14. { FPC = Target is FreePascal compiler }
  15. {****************************************************************}
  16. { REMARKS: }
  17. { }
  18. { }
  19. { }
  20. {****************************************************************}
  21. procedure fail;
  22. begin
  23. WriteLn('Failure.');
  24. halt(1);
  25. end;
  26. function simple_exit : longint;
  27. var
  28. z : longint;
  29. begin
  30. z:=0;
  31. exit;
  32. z:=12;
  33. end;
  34. const
  35. RET_S64BIT = $100000;
  36. RET_S32BIT = -123456;
  37. RET_U32BIT = 2000000;
  38. RET_S16BIT = -30000;
  39. RET_U16BIT = $5555;
  40. RET_S8BIT = -80;
  41. RET_U8BIT = $AA;
  42. RET_SINGLE = 57689.15;
  43. RET_DOUBLE = 100012.345;
  44. PCHAR_STRING: pchar = 'HELLO STRING';
  45. type
  46. t24bitarray = packed array[1..3] of byte;
  47. var
  48. global_var : longint;
  49. function getu8bit : byte;
  50. begin
  51. getu8bit := RET_U8BIT;
  52. end;
  53. function gets8bit : shortint;
  54. begin
  55. gets8bit := RET_S8BIT;
  56. end;
  57. function getu16bit : word;
  58. begin
  59. getu16bit := RET_U16BIT;
  60. end;
  61. function gets16bit : smallint;
  62. begin
  63. gets16bit := RET_S16BIT;
  64. end;
  65. function getu32bit : cardinal;
  66. begin
  67. getu32bit := RET_U32BIT;
  68. end;
  69. function gets32bit : longint;
  70. begin
  71. gets32bit := RET_S32BIT;
  72. end;
  73. function gets64bit : int64;
  74. begin
  75. gets64bit := RET_S64BIT;
  76. end;
  77. function gets32real : single;
  78. begin
  79. gets32real := RET_SINGLE;
  80. end;
  81. function gets64real : double;
  82. begin
  83. gets64real := RET_DOUBLE;
  84. end;
  85. function getpchar: pchar;
  86. begin
  87. getpchar := PCHAR_STRING;
  88. end;
  89. function exit_loc_mem_ordinal_1 : longint;
  90. var
  91. z : longint;
  92. begin
  93. global_var:=0;
  94. global_var:=RET_S32BIT;
  95. exit(global_var);
  96. global_var:=RET_S32BIT;
  97. end;
  98. function exit_loc_reg_pointerdef : pchar;
  99. begin
  100. exit(getpchar);
  101. end;
  102. function exit_loc_ref_pointerdef : pchar;
  103. var
  104. p: pchar;
  105. begin
  106. p:=PCHAR_STRING;
  107. exit(p);
  108. end;
  109. function exit_loc_reg_ordinal_s64bit : int64;
  110. begin
  111. exit(gets64bit);
  112. end;
  113. function exit_loc_reg_ordinal_s32bit :longint;
  114. begin
  115. exit(gets32bit);
  116. end;
  117. function exit_loc_reg_ordinal_u32bit :cardinal;
  118. begin
  119. exit(getu32bit);
  120. end;
  121. function exit_loc_reg_ordinal_s16bit : smallint;
  122. begin
  123. exit(gets16bit);
  124. end;
  125. function exit_loc_reg_ordinal_u16bit :word;
  126. begin
  127. exit(getu16bit)
  128. end;
  129. function exit_loc_reg_ordinal_s8bit : shortint;
  130. begin
  131. exit(gets8bit);
  132. end;
  133. function exit_loc_reg_ordinal_u8bit : byte;
  134. begin
  135. exit(getu8bit);
  136. end;
  137. function exit_loc_ref_constant : word;
  138. begin
  139. exit(RET_U16BIT);
  140. end;
  141. function exit_loc_ref_ordinal_s64bit : int64;
  142. var
  143. s : int64;
  144. begin
  145. s := RET_S64BIT;
  146. exit(s);
  147. end;
  148. function exit_loc_ref_ordinal_s32bit :longint;
  149. var
  150. s : longint;
  151. begin
  152. s := RET_S32BIT;
  153. exit(s);
  154. end;
  155. function exit_loc_ref_ordinal_u32bit :cardinal;
  156. var
  157. c: cardinal;
  158. begin
  159. c := RET_U32BIT;
  160. exit(c);
  161. end;
  162. function exit_loc_ref_ordinal_s16bit : smallint;
  163. var
  164. s : smallint;
  165. begin
  166. s := RET_S16BIT;
  167. exit(s);
  168. end;
  169. function exit_loc_ref_ordinal_u16bit :word;
  170. var
  171. w: word;
  172. begin
  173. w := RET_U16BIT;
  174. exit(w);
  175. end;
  176. function exit_loc_ref_ordinal_s8bit : shortint;
  177. var
  178. s : shortint;
  179. begin
  180. s := RET_S8BIT;
  181. exit(s);
  182. end;
  183. function exit_loc_ref_ordinal_u8bit : byte;
  184. var
  185. b: byte;
  186. begin
  187. b:=RET_U8BIT;
  188. exit(b);
  189. end;
  190. function exit_loc_ref_ordinal_24bit : t24bitarray;
  191. var
  192. r : t24bitarray;
  193. begin
  194. r[1]:=12;
  195. r[2]:=13;
  196. r[3]:=14;
  197. exit(r);
  198. end;
  199. function exit_loc_ref_float_s32real : single;
  200. var
  201. s: single;
  202. begin
  203. s:=RET_SINGLE;
  204. exit(s);
  205. end;
  206. function exit_loc_ref_float_s64real : double;
  207. var
  208. s: double;
  209. begin
  210. s:=RET_DOUBLE;
  211. exit(s);
  212. end;
  213. function exit_loc_reg_float_s32real : single;
  214. begin
  215. exit(gets32real);
  216. end;
  217. function exit_loc_reg_float_s64real : double;
  218. begin
  219. exit(gets64real);
  220. end;
  221. function exit_loc_flags : boolean;
  222. var
  223. c: char;
  224. begin
  225. c:='A';
  226. exit(c in ['a'..'z']);
  227. end;
  228. function exit_loc_jump : boolean;
  229. var
  230. b,c: boolean;
  231. begin
  232. b:=TRUE;
  233. c:=FALSE;
  234. exit(b and c);
  235. end;
  236. function exit_loc_ansi(w: word) : ansistring;
  237. var d: ansistring;
  238. begin
  239. str(w,d);
  240. exit(d);
  241. end;
  242. var
  243. failed : boolean;
  244. array_24bits : t24bitarray;
  245. Begin
  246. { simple exit }
  247. write('Testing secondexitn() simple case...');
  248. failed := false;
  249. simple_exit;
  250. if failed then
  251. fail
  252. else
  253. writeln('Passed!');
  254. write('Testing secondexitn() with reference (simple case)...');
  255. failed := false;
  256. array_24bits := exit_loc_ref_ordinal_24bit;
  257. if (array_24bits[1]<>12) or (array_24bits[2]<>13) or (array_24bits[3]<>14) then
  258. failed := true;
  259. if failed then
  260. fail
  261. else
  262. writeln('Passed!');
  263. write('secondexitn() LOC_CONSTANT case...');
  264. failed := false;
  265. if exit_loc_ref_constant <> RET_U16BIT then
  266. failed := true;
  267. if failed then
  268. fail
  269. else
  270. writeln('Passed!');
  271. write('secondexitn() LOC_MEM case...');
  272. failed := false;
  273. if exit_loc_mem_ordinal_1 <> RET_S32BIT then
  274. failed := true;
  275. if failed then
  276. fail
  277. else
  278. writeln('Passed!');
  279. writeln('Testing secondexitn() LOC_REFERENCE case...');
  280. write(' ordinal/enumdef return value...');
  281. failed := false;
  282. if exit_loc_ref_ordinal_s64bit <> RET_S64BIT then
  283. failed := true;
  284. if exit_loc_ref_ordinal_s32bit <> RET_S32BIT then
  285. failed := true;
  286. if exit_loc_ref_ordinal_u32bit <> RET_U32BIT then
  287. failed := true;
  288. if exit_loc_ref_ordinal_s16bit <> RET_S16BIT then
  289. failed := true;
  290. if exit_loc_ref_ordinal_u16bit <> RET_U16BIT then
  291. failed := true;
  292. if exit_loc_ref_ordinal_s8bit <> RET_S8BIT then
  293. failed := true;
  294. if exit_loc_ref_ordinal_u8bit <> RET_U8BIT then
  295. failed := true;
  296. if failed then
  297. fail
  298. else
  299. writeln('Passed!');
  300. write(' floating point return value...');
  301. failed := false;
  302. if (trunc(exit_loc_ref_float_s32real) <> trunc(RET_SINGLE)) then
  303. failed := true;
  304. if trunc(exit_loc_ref_float_s64real) <> trunc(RET_DOUBLE) then
  305. failed := true;
  306. if failed then
  307. fail
  308. else
  309. writeln('Passed!');
  310. { procvardef is not tested since it is the same as pointer return value...}
  311. write(' pointer/procedure variable return value...');
  312. failed := false;
  313. { compare the actual pointer not the values inside the string ! }
  314. if (exit_loc_ref_pointerdef <> PCHAR_STRING) then
  315. failed:=true;
  316. if failed then
  317. fail
  318. else
  319. writeln('Passed!');
  320. writeln('Testing secondexitn() LOC_REGISTER case...');
  321. write(' ordinal/enumdef return value...');
  322. failed := false;
  323. if exit_loc_reg_ordinal_s64bit <> RET_S64BIT then
  324. failed := true;
  325. if exit_loc_reg_ordinal_s32bit <> RET_S32BIT then
  326. failed := true;
  327. if exit_loc_reg_ordinal_u32bit <> RET_U32BIT then
  328. failed := true;
  329. if exit_loc_reg_ordinal_s16bit <> RET_S16BIT then
  330. failed := true;
  331. if exit_loc_reg_ordinal_u16bit <> RET_U16BIT then
  332. failed := true;
  333. if exit_loc_reg_ordinal_s8bit <> RET_S8BIT then
  334. failed := true;
  335. if exit_loc_reg_ordinal_u8bit <> RET_U8BIT then
  336. failed := true;
  337. if failed then
  338. fail
  339. else
  340. writeln('Passed!');
  341. write(' floating point return value...');
  342. failed := false;
  343. if (trunc(exit_loc_reg_float_s32real) <> trunc(RET_SINGLE)) then
  344. failed := true;
  345. if trunc(exit_loc_reg_float_s64real) <> trunc(RET_DOUBLE) then
  346. failed := true;
  347. if failed then
  348. fail
  349. else
  350. writeln('Passed!');
  351. { procvardef is not tested since it is the same as pointer return value...}
  352. write(' pointer/procedure variable return value...');
  353. failed := false;
  354. { compare the actual pointer not the values inside the string ! }
  355. if (exit_loc_reg_pointerdef <> PCHAR_STRING) then
  356. failed:=true;
  357. if failed then
  358. fail
  359. else
  360. writeln('Passed!');
  361. write('Testing secondexitn() LOC_FLAGS case...');
  362. failed := false;
  363. { check for false, since having zero in register is rarer }
  364. { then having non-zero (just in case everything is corrupt) }
  365. if exit_loc_flags then
  366. failed := true;
  367. if failed then
  368. fail
  369. else
  370. writeln('Passed!');
  371. write('Testing secondexitn() LOC_JUMP case...');
  372. failed := false;
  373. { check for false, since having zero in register is rarer }
  374. { then having non-zero (just in case everything is corrupt) }
  375. if exit_loc_jump then
  376. failed := true;
  377. if failed then
  378. fail
  379. else
  380. writeln('Passed!');
  381. write('Testing secondexitn() ansistring case...');
  382. failed := false;
  383. if exit_loc_ansi(10) <> '10' then
  384. failed := true;
  385. if failed then
  386. fail
  387. else
  388. writeln('Passed!');
  389. end.