tldparam.pp 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. { This tests the passing of parameters of routines }
  2. { and how they are accessed. }
  3. { Tests secondload() and secondcallparan() }
  4. { TO DO : }
  5. { Add testing for complex parameters }
  6. { such as string, arrays and sets }
  7. { ***************************************************************** }
  8. { SIMPLE TYPES }
  9. { ***************************************************************** }
  10. procedure testvaluebyte(b: byte);
  11. begin
  12. WriteLn(b);
  13. end;
  14. procedure testvalueword(w: word);
  15. begin
  16. WriteLn(w);
  17. end;
  18. procedure testvaluelong(l : longint);
  19. begin
  20. WriteLn(l);
  21. end;
  22. procedure testvarbyte(var b: byte);
  23. begin
  24. WriteLn(b);
  25. end;
  26. procedure testvarword(var w: word);
  27. begin
  28. writeln(w);
  29. end;
  30. procedure testvarlong(var l : longint);
  31. begin
  32. writeln(l);
  33. end;
  34. procedure testvaluemixedbyte(b: byte; w: word; l: longint);
  35. begin
  36. Writeln(b);
  37. writeln(w);
  38. writeln(l);
  39. end;
  40. procedure testvaluemixedlong(l : longint; w: word; b: byte);
  41. begin
  42. Writeln(l);
  43. writeln(w);
  44. writeln(b);
  45. end;
  46. procedure testvaluemixedbytebyte(b1: byte; b2: byte; b3: byte);
  47. begin
  48. Writeln(b1);
  49. writeln(b2);
  50. writeln(b3);
  51. end;
  52. {$ifdef fpc}
  53. procedure testvalueint64(i : int64);
  54. begin
  55. WriteLn(i);
  56. end;
  57. procedure testvarint64(var i : int64);
  58. begin
  59. WriteLn(i);
  60. end;
  61. procedure testvaluemixedint64(b1: byte; i: int64; b2: byte);
  62. begin
  63. WriteLn(b1);
  64. WriteLn(i);
  65. WriteLn(b2);
  66. end;
  67. {$endif}
  68. procedure testvaluereal(r: real);
  69. begin
  70. WriteLn(r);
  71. end;
  72. procedure testvaluesingle(s: single);
  73. begin
  74. WriteLn(s);
  75. end;
  76. procedure testvaluedouble(d: double);
  77. begin
  78. WriteLn(d);
  79. end;
  80. procedure testvaluemixedreal(b1: byte; r: real; b2: byte);
  81. begin
  82. WriteLn(b1);
  83. WriteLn(r);
  84. WriteLn(b2);
  85. end;
  86. procedure testvarreal(var r: real);
  87. begin
  88. WriteLn(r);
  89. end;
  90. { only check assembler code }
  91. { cannot be called directly }
  92. { because will crash system }
  93. procedure testint; interrupt;
  94. begin
  95. end;
  96. { ***************************************************************** }
  97. { COMPLEX TYPES }
  98. { ***************************************************************** }
  99. { ***************************************************************** }
  100. { RETURN TYPES }
  101. { ***************************************************************** }
  102. function testretbyte: byte;
  103. begin
  104. Write('(byte) : Value should be 127...');
  105. testretbyte:= 127;
  106. end;
  107. function testretword: word;
  108. begin
  109. Write('(word) : Value should be 43690...');
  110. testretword := 43690;
  111. end;
  112. function testretlong : longint;
  113. begin
  114. Write('(long) : Value should be -1...');
  115. testretlong := -1;
  116. end;
  117. function testretstring: string;
  118. begin
  119. Write('(string) : Value should be ''HELLO WORLD''...');
  120. testretstring := 'HELLO WORLD';
  121. end;
  122. function testretreal : real;
  123. begin
  124. Write('(real) : Value should be 12.12...');
  125. testretreal := 12.12;
  126. end;
  127. function testretsingle : single;
  128. begin
  129. Write('(single) : Value should be 13.13...');
  130. testretsingle := 13.13;
  131. end;
  132. function testretdouble : double;
  133. begin
  134. Write('(double) : Value should be 14.14...');
  135. testretdouble := 14.14;
  136. end;
  137. function testretpchar: pchar;
  138. begin
  139. Write('(pchar) : Value should be ...');
  140. testretpchar := nil;
  141. end;
  142. {$ifdef fpc}
  143. function testretint64 : int64;
  144. begin
  145. Write('(int64) : Value should be -127...');
  146. testretint64 := -127;
  147. end;
  148. function testretansi: ansistring;
  149. begin
  150. Write('(ansi) : Value should be ''HELLO WORLD''...');
  151. testretansi := 'HELLO WORLD';
  152. end;
  153. {$ifdef fpc}
  154. {$inline on}
  155. function testretbyteinline: byte; inline;
  156. begin
  157. Write('(byte) : Value should be 126...');
  158. testretbyteinline:= 126;
  159. end;
  160. function testretwordinline: word; inline;
  161. begin
  162. Write('(word) : Value should be 43689...');
  163. testretwordinline := 43689;
  164. end;
  165. function testretint64inline : int64;inline;
  166. begin
  167. Write('(int64) : Value should be -128...');
  168. testretint64inline := -128;
  169. end;
  170. function testretrealinline : real; inline;
  171. begin
  172. Write('(real) : Value should be 110.110...');
  173. testretrealinline := 110.110;
  174. end;
  175. function testretdoubleinline : double; inline;
  176. begin
  177. Write('(double) : Value should be 130.130...');
  178. testretdoubleinline := 130.130;
  179. end;
  180. function testretbyteregs: byte; saveregisters;
  181. begin
  182. Write('(byte) : Value should be 125...');
  183. testretbyteregs:= 125;
  184. end;
  185. function testretwordregs: word; saveregisters;
  186. begin
  187. Write('(word) : Value should be 43688...');
  188. testretwordregs := 43688;
  189. end;
  190. function testretint64regs : int64;saveregisters;
  191. begin
  192. Write('(int64) : Value should be -130...');
  193. testretint64regs := -130;
  194. end;
  195. function testretrealregs : real; saveregisters;
  196. begin
  197. Write('(real) : Value should be -55.55...');
  198. testretrealregs := -55.55;
  199. end;
  200. function testretdoubleregs : double; saveregisters;
  201. begin
  202. Write('(double) : Value should be -77.14...');
  203. testretdoubleregs := -77.14;
  204. end;
  205. function testretbytecdecl: byte; cdecl;
  206. begin
  207. Write('(byte) : Value should be 125...');
  208. testretbytecdecl:= 125;
  209. end;
  210. function testretwordcdecl: word; cdecl;
  211. begin
  212. Write('(word) : Value should be 43688...');
  213. testretwordcdecl := 43688;
  214. end;
  215. function testretint64cdecl : int64; cdecl;
  216. begin
  217. Write('(int64) : Value should be -130...');
  218. testretint64cdecl := -130;
  219. end;
  220. function testretrealcdecl : real; cdecl;
  221. begin
  222. Write('(real) : Value should be -55.55...');
  223. testretrealcdecl := -55.55;
  224. end;
  225. function testretdoublecdecl : double; cdecl;
  226. begin
  227. Write('(double) : Value should be -77.14...');
  228. testretdoublecdecl := -77.14;
  229. end;
  230. {$endif}
  231. {$endif}
  232. var
  233. b: byte;
  234. w: word;
  235. l: longint;
  236. r: real;
  237. {$ifdef fpc}
  238. i: int64;
  239. {$endif}
  240. begin
  241. WriteLn('------------------------------------------------------');
  242. WriteLN(' TESTING NON-COMPLEX PARAMETERS ');
  243. WriteLn('------------------------------------------------------');
  244. { testint;}
  245. { check value parameters }
  246. Write('(byte value param) : Value should be 85...');
  247. testvaluebyte($55);
  248. Write('(word value param) : Value should be 43690...');
  249. testvalueword($AAAA);
  250. Write('(long value param) : Value should be -1...');
  251. testvaluelong(-1);
  252. { check variable parameters }
  253. b:=$55;
  254. w:=$AAAA;
  255. l:=-1;
  256. Write('(byte var param) : Value should be 85...');
  257. testvarbyte(b);
  258. Write('(word var param) : Value should be 43690...');
  259. testvarword(w);
  260. Write('(long var param) : Value should be -1...');
  261. testvarlong(l);
  262. {$ifdef fpc}
  263. Write('(int64 value param) : Value should be 43690...');
  264. testvalueint64($AAAA);
  265. Write('(int64 var param) : Value should be appx. 187 00000000000...');
  266. i:= $AAAA;
  267. i:= i shl 32;
  268. testvarint64(i);
  269. {$endif}
  270. writeln('(mixed value params) : Values should 85,43690,-1...');
  271. testvaluemixedbyte($55,$AAAA,-1);
  272. writeln('(mixed value params) : Values should be -1, 43690, 85...');
  273. testvaluemixedlong(-1,$AAAA,$55);
  274. writeln('(mixed value params): Values should be 0, 127, 254...');
  275. testvaluemixedbytebyte(0,127,254);
  276. {$ifdef fpc}
  277. writeln('(mixed value params) : Value should be 0, -1, 254...');
  278. testvaluemixedint64(0,-1,254);
  279. {$endif}
  280. write('(real value param) : Value should be 1.1...');
  281. testvaluereal(1.1);
  282. write('(single value param) : Value should be 2.2...');
  283. testvaluesingle(2.2);
  284. write('(double value param) : Value should be 3.3...');
  285. testvaluedouble(3.3);
  286. write('(real var param) : Value should be 7.7...');
  287. r:=7.7;
  288. testvarreal(r);
  289. writeln('(mixed value params) : Values should be 0, 10.7, 254...');
  290. testvaluemixedreal(0,10.7,254);
  291. WriteLn('------------------------------------------------------');
  292. WriteLN(' TESTING FUNCTION RESULTS ');
  293. WriteLn('------------------------------------------------------');
  294. WriteLn('----------------------- NORMAL -----------------------');
  295. WriteLn(testretbyte);
  296. WriteLn(testretword);
  297. WriteLn(testretlong);
  298. WriteLn(testretstring);
  299. WriteLn(testretreal);
  300. WriteLn(testretsingle);
  301. WriteLn(testretdouble);
  302. WriteLn(testretpchar);
  303. {$ifdef fpc}
  304. WriteLn(testretint64);
  305. WriteLn(testretansi);
  306. WriteLn('----------------------- INLINE -----------------------');
  307. WriteLn(testretbyteinline);
  308. WriteLn(testretwordinline);
  309. WriteLn(testretint64inline);
  310. WriteLn(testretrealinline);
  311. WriteLn(testretdoubleinline);
  312. WriteLn('---------------------- SAVEREGS ----------------------');
  313. WriteLn(testretbyteregs);
  314. WriteLn(testretwordregs);
  315. WriteLn(testretint64regs);
  316. WriteLn(testretrealregs);
  317. WriteLn(testretdoubleregs);
  318. WriteLn('------------------------ CDECL -----------------------');
  319. WriteLn(testretbytecdecl);
  320. WriteLn(testretwordcdecl);
  321. WriteLn(testretint64cdecl);
  322. WriteLn(testretrealcdecl);
  323. WriteLn(testretdoublecdecl);
  324. {$endif}
  325. end.
  326. {
  327. $Log$
  328. Revision 1.3 2002-09-07 15:40:56 peter
  329. * old logs removed and tabs fixed
  330. }