tldparam.pp 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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. {$ifdef VER1_0}
  181. function testretbyteregs: byte; saveregisters;
  182. begin
  183. Write('(byte) : Value should be 125...');
  184. testretbyteregs:= 125;
  185. end;
  186. function testretwordregs: word; saveregisters;
  187. begin
  188. Write('(word) : Value should be 43688...');
  189. testretwordregs := 43688;
  190. end;
  191. function testretint64regs : int64;saveregisters;
  192. begin
  193. Write('(int64) : Value should be -130...');
  194. testretint64regs := -130;
  195. end;
  196. function testretrealregs : real; saveregisters;
  197. begin
  198. Write('(real) : Value should be -55.55...');
  199. testretrealregs := -55.55;
  200. end;
  201. function testretdoubleregs : double; saveregisters;
  202. begin
  203. Write('(double) : Value should be -77.14...');
  204. testretdoubleregs := -77.14;
  205. end;
  206. {$endif VER1_0}
  207. function testretbytecdecl: byte; cdecl;
  208. begin
  209. Write('(byte) : Value should be 125...');
  210. testretbytecdecl:= 125;
  211. end;
  212. function testretwordcdecl: word; cdecl;
  213. begin
  214. Write('(word) : Value should be 43688...');
  215. testretwordcdecl := 43688;
  216. end;
  217. function testretint64cdecl : int64; cdecl;
  218. begin
  219. Write('(int64) : Value should be -130...');
  220. testretint64cdecl := -130;
  221. end;
  222. function testretrealcdecl : real; cdecl;
  223. begin
  224. Write('(real) : Value should be -55.55...');
  225. testretrealcdecl := -55.55;
  226. end;
  227. function testretdoublecdecl : double; cdecl;
  228. begin
  229. Write('(double) : Value should be -77.14...');
  230. testretdoublecdecl := -77.14;
  231. end;
  232. {$endif}
  233. {$endif}
  234. var
  235. b: byte;
  236. w: word;
  237. l: longint;
  238. r: real;
  239. {$ifdef fpc}
  240. i: int64;
  241. {$endif}
  242. begin
  243. WriteLn('------------------------------------------------------');
  244. WriteLN(' TESTING NON-COMPLEX PARAMETERS ');
  245. WriteLn('------------------------------------------------------');
  246. { testint;}
  247. { check value parameters }
  248. Write('(byte value param) : Value should be 85...');
  249. testvaluebyte($55);
  250. Write('(word value param) : Value should be 43690...');
  251. testvalueword($AAAA);
  252. Write('(long value param) : Value should be -1...');
  253. testvaluelong(-1);
  254. { check variable parameters }
  255. b:=$55;
  256. w:=$AAAA;
  257. l:=-1;
  258. Write('(byte var param) : Value should be 85...');
  259. testvarbyte(b);
  260. Write('(word var param) : Value should be 43690...');
  261. testvarword(w);
  262. Write('(long var param) : Value should be -1...');
  263. testvarlong(l);
  264. {$ifdef fpc}
  265. Write('(int64 value param) : Value should be 43690...');
  266. testvalueint64($AAAA);
  267. Write('(int64 var param) : Value should be appx. 187 00000000000...');
  268. i:= $AAAA;
  269. i:= i shl 32;
  270. testvarint64(i);
  271. {$endif}
  272. writeln('(mixed value params) : Values should 85,43690,-1...');
  273. testvaluemixedbyte($55,$AAAA,-1);
  274. writeln('(mixed value params) : Values should be -1, 43690, 85...');
  275. testvaluemixedlong(-1,$AAAA,$55);
  276. writeln('(mixed value params): Values should be 0, 127, 254...');
  277. testvaluemixedbytebyte(0,127,254);
  278. {$ifdef fpc}
  279. writeln('(mixed value params) : Value should be 0, -1, 254...');
  280. testvaluemixedint64(0,-1,254);
  281. {$endif}
  282. write('(real value param) : Value should be 1.1...');
  283. testvaluereal(1.1);
  284. write('(single value param) : Value should be 2.2...');
  285. testvaluesingle(2.2);
  286. write('(double value param) : Value should be 3.3...');
  287. testvaluedouble(3.3);
  288. write('(real var param) : Value should be 7.7...');
  289. r:=7.7;
  290. testvarreal(r);
  291. writeln('(mixed value params) : Values should be 0, 10.7, 254...');
  292. testvaluemixedreal(0,10.7,254);
  293. WriteLn('------------------------------------------------------');
  294. WriteLN(' TESTING FUNCTION RESULTS ');
  295. WriteLn('------------------------------------------------------');
  296. WriteLn('----------------------- NORMAL -----------------------');
  297. WriteLn(testretbyte);
  298. WriteLn(testretword);
  299. WriteLn(testretlong);
  300. WriteLn(testretstring);
  301. WriteLn(testretreal);
  302. WriteLn(testretsingle);
  303. WriteLn(testretdouble);
  304. WriteLn(testretpchar);
  305. {$ifdef fpc}
  306. WriteLn(testretint64);
  307. WriteLn(testretansi);
  308. WriteLn('----------------------- INLINE -----------------------');
  309. WriteLn(testretbyteinline);
  310. WriteLn(testretwordinline);
  311. WriteLn(testretint64inline);
  312. WriteLn(testretrealinline);
  313. WriteLn(testretdoubleinline);
  314. {$ifdef VER1_0}
  315. WriteLn('---------------------- SAVEREGS ----------------------');
  316. WriteLn(testretbyteregs);
  317. WriteLn(testretwordregs);
  318. WriteLn(testretint64regs);
  319. WriteLn(testretrealregs);
  320. WriteLn(testretdoubleregs);
  321. {$endif VER1_0}
  322. WriteLn('------------------------ CDECL -----------------------');
  323. WriteLn(testretbytecdecl);
  324. WriteLn(testretwordcdecl);
  325. WriteLn(testretint64cdecl);
  326. WriteLn(testretrealcdecl);
  327. WriteLn(testretdoublecdecl);
  328. {$endif}
  329. end.