tcalpvr3.pp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. {****************************************************************}
  2. { CODE GENERATOR TEST PROGRAM }
  3. {****************************************************************}
  4. { NODE TESTED : secondcalln() }
  5. {****************************************************************}
  6. { PRE-REQUISITES: secondload() }
  7. { secondassign() }
  8. { secondcalln() }
  9. { secondadd() }
  10. { secondtypeconv() }
  11. {****************************************************************}
  12. { DEFINES: }
  13. {****************************************************************}
  14. { REMARKS: This tests a subset of the secondcalln() , it }
  15. { verifies procedural variables for cdecl }
  16. { calling conventions. }
  17. {****************************************************************}
  18. program tcalpvr3;
  19. {$MODE OBJFPC}
  20. {$STATIC ON}
  21. {$R+}
  22. const
  23. RESULT_U8BIT = $55;
  24. RESULT_U16BIT = $500F;
  25. RESULT_S32BIT = $500F0000;
  26. RESULT_S64BIT = -12000;
  27. type
  28. troutine = procedure (x: longint; y: byte);cdecl;
  29. troutineresult = function (x: longint; y: byte): int64;cdecl;
  30. tsimpleobject = object
  31. constructor init;
  32. procedure test_normal(x: byte);cdecl;
  33. procedure test_static(x: byte);static;cdecl;
  34. end;
  35. tsimpleclass = class
  36. constructor create;
  37. procedure test_normal(x: byte);cdecl;
  38. class procedure test_static(x: byte);cdecl;
  39. procedure test_normal_self(self : tsimpleclass; x: byte); message 0;cdecl;
  40. class procedure test_static_self(self : tsimpleclass; x: byte); message 1;cdecl;
  41. end;
  42. tobjectmethod = procedure (x: byte) of object ;cdecl;
  43. tclassmethod = procedure (x: byte) of object;cdecl;
  44. { used for testing pocontainsself explicit parameter }
  45. tclassmethodself = procedure (self : tsimpleclass; x: byte) of object;cdecl;
  46. var
  47. proc : troutine;
  48. func : troutineresult;
  49. obj_method : tobjectmethod;
  50. cla_method : tclassmethod;
  51. cla_method_self : tclassmethodself;
  52. global_s32bit : longint;
  53. global_s64bit : int64;
  54. global_u8bit : byte;
  55. value_s32bit : longint;
  56. value_u8bit : byte;
  57. obj : tsimpleobject;
  58. cla : tsimpleclass;
  59. procedure fail;
  60. begin
  61. WriteLn('Failed!');
  62. halt(1);
  63. end;
  64. procedure clear_globals;
  65. begin
  66. global_s32bit := 0;
  67. global_u8bit := 0;
  68. global_s64bit := 0;
  69. end;
  70. procedure clear_values;
  71. begin
  72. value_s32bit := 0;
  73. value_u8bit := 0;
  74. end;
  75. procedure testroutine(x: longint; y: byte);cdecl;
  76. begin
  77. global_s32bit := x;
  78. global_u8bit := y;
  79. end;
  80. function testroutineresult(x: longint; y: byte): int64;cdecl;
  81. begin
  82. global_s32bit := x;
  83. global_u8bit := y;
  84. testroutineresult := RESULT_S64BIT;
  85. end;
  86. function getroutine: troutine;
  87. begin
  88. getroutine:=proc;
  89. end;
  90. function getroutineresult : troutineresult;
  91. begin
  92. getroutineresult := func;
  93. end;
  94. { IMPOSSIBLE TO DO CURRENTLY !
  95. function get_object_method_static : tnormalmethod;
  96. begin
  97. get_object_method_static := @obj.test_static;
  98. end;
  99. }
  100. { objects access }
  101. function get_object_method_normal : tobjectmethod;
  102. begin
  103. get_object_method_normal := @obj.test_normal;
  104. end;
  105. { class access }
  106. function get_class_method_normal_self : tclassmethodself;
  107. begin
  108. get_class_method_normal_self := @cla.test_normal_self;
  109. end;
  110. {
  111. HOW CAN WE GET THIS ADDRESS???
  112. function get_class_method_static_self : tclassmethodself;
  113. begin
  114. get_class_method_static_self := @cla.test_static_self;
  115. end;
  116. }
  117. function get_class_method_normal : tclassmethod;
  118. begin
  119. get_class_method_normal := @cla.test_normal;
  120. end;
  121. {
  122. function get_class_method_static : tclassmethod;
  123. begin
  124. get_class_method_static := @cla.test_static;
  125. end;}
  126. {****************************************************************************************************}
  127. constructor tsimpleobject.init;
  128. begin
  129. end;
  130. procedure tsimpleobject.test_normal(x: byte);cdecl;
  131. begin
  132. global_u8bit := x;
  133. end;
  134. procedure tsimpleobject.test_static(x: byte);cdecl;
  135. begin
  136. global_u8bit := x;
  137. end;
  138. {****************************************************************************************************}
  139. constructor tsimpleclass.create;
  140. begin
  141. inherited create;
  142. end;
  143. procedure tsimpleclass. test_normal(x: byte);cdecl;
  144. begin
  145. global_u8bit := x;
  146. end;
  147. class procedure tsimpleclass.test_static(x: byte);cdecl;
  148. begin
  149. global_u8bit := x;
  150. end;
  151. procedure tsimpleclass.test_normal_self(self : tsimpleclass; x: byte);cdecl;
  152. begin
  153. global_u8bit := x;
  154. end;
  155. class procedure tsimpleclass.test_static_self(self : tsimpleclass; x: byte);cdecl;
  156. begin
  157. global_u8bit := x;
  158. end;
  159. var
  160. failed : boolean;
  161. Begin
  162. { setup variables }
  163. proc := @testroutine;
  164. func := @testroutineresult;
  165. obj.init;
  166. cla:=tsimpleclass.create;
  167. {****************************************************************************************************}
  168. Write('Testing procedure variable call (LOC_REGISTER)..');
  169. clear_globals;
  170. clear_values;
  171. failed := false;
  172. { parameters in LOC_CONSTANT, routine address in LOC_REGISTER }
  173. troutine(getroutine)(RESULT_S32BIT,RESULT_U8BIT);
  174. if global_u8bit <> RESULT_U8BIT then
  175. failed := true;
  176. if global_s32bit <> RESULT_S32BIT then
  177. failed := true;
  178. clear_globals;
  179. clear_values;
  180. { parameters in LOC_REFERENCE,routine address in LOC_REGISTER }
  181. value_s32bit := RESULT_S32BIT;
  182. value_u8bit := RESULT_U8BIT;
  183. troutine(getroutine)(value_s32bit , value_u8bit);
  184. if global_u8bit <> RESULT_U8BIT then
  185. failed := true;
  186. if global_s32bit <> RESULT_S32BIT then
  187. failed := true;
  188. If failed then
  189. fail
  190. else
  191. WriteLn('Passed!');
  192. Write('Testing procedure variable call (LOC_REFERENCE)..');
  193. clear_globals;
  194. clear_values;
  195. failed := false;
  196. { parameters in LOC_CONSTANT, routine address in LOC_REGISTER }
  197. proc(RESULT_S32BIT,RESULT_U8BIT);
  198. if global_u8bit <> RESULT_U8BIT then
  199. failed := true;
  200. if global_s32bit <> RESULT_S32BIT then
  201. failed := true;
  202. clear_globals;
  203. clear_values;
  204. { parameters in LOC_REFERENCE,routine address in LOC_REGISTER }
  205. value_s32bit := RESULT_S32BIT;
  206. value_u8bit := RESULT_U8BIT;
  207. proc(value_s32bit , value_u8bit);
  208. if global_u8bit <> RESULT_U8BIT then
  209. failed := true;
  210. if global_s32bit <> RESULT_S32BIT then
  211. failed := true;
  212. If failed then
  213. fail
  214. else
  215. WriteLn('Passed!');
  216. {****************************************************************************************************}
  217. Write('Testing function variable call (LOC_REGISTER)..');
  218. clear_globals;
  219. clear_values;
  220. failed := false;
  221. { parameters in LOC_CONSTANT, routine address in LOC_REGISTER }
  222. global_s64bit := troutineresult(getroutineresult)(RESULT_S32BIT,RESULT_U8BIT);
  223. if global_u8bit <> RESULT_U8BIT then
  224. failed := true;
  225. if global_s32bit <> RESULT_S32BIT then
  226. failed := true;
  227. if global_s64bit <> RESULT_S64BIT then
  228. failed := true;
  229. clear_globals;
  230. clear_values;
  231. { parameters in LOC_REFERENCE,routine address in LOC_REGISTER }
  232. value_s32bit := RESULT_S32BIT;
  233. value_u8bit := RESULT_U8BIT;
  234. global_s64bit := troutineresult(getroutineresult)(value_s32bit , value_u8bit);
  235. if global_u8bit <> RESULT_U8BIT then
  236. failed := true;
  237. if global_s32bit <> RESULT_S32BIT then
  238. failed := true;
  239. if global_s64bit <> RESULT_S64BIT then
  240. failed := true;
  241. If failed then
  242. fail
  243. else
  244. WriteLn('Passed!');
  245. Write('Testing function variable call (LOC_REFERENCE)..');
  246. clear_globals;
  247. clear_values;
  248. failed := false;
  249. { parameters in LOC_CONSTANT, routine address in LOC_REGISTER }
  250. global_s64bit := func(RESULT_S32BIT,RESULT_U8BIT);
  251. if global_u8bit <> RESULT_U8BIT then
  252. failed := true;
  253. if global_s32bit <> RESULT_S32BIT then
  254. failed := true;
  255. if global_s64bit <> RESULT_S64BIT then
  256. failed := true;
  257. clear_globals;
  258. clear_values;
  259. { parameters in LOC_REFERENCE,routine address in LOC_REGISTER }
  260. value_s32bit := RESULT_S32BIT;
  261. value_u8bit := RESULT_U8BIT;
  262. global_s64bit := func(value_s32bit , value_u8bit);
  263. if global_u8bit <> RESULT_U8BIT then
  264. failed := true;
  265. if global_s32bit <> RESULT_S32BIT then
  266. failed := true;
  267. if global_s64bit <> RESULT_S64BIT then
  268. failed := true;
  269. If failed then
  270. fail
  271. else
  272. WriteLn('Passed!');
  273. {****************************************************************************************************}
  274. Write('Testing object method variable call (LOC_REGISTER) ..');
  275. clear_globals;
  276. clear_values;
  277. failed := false;
  278. tobjectmethod(get_object_method_normal)(RESULT_U8BIT);
  279. if global_u8bit <> RESULT_U8BIT then
  280. failed := true;
  281. clear_globals;
  282. clear_values;
  283. value_u8bit := RESULT_U8BIT;
  284. tobjectmethod(get_object_method_normal)(value_u8bit);
  285. if global_u8bit <> RESULT_U8BIT then
  286. failed := true;
  287. If failed then
  288. fail
  289. else
  290. WriteLn('Passed!');
  291. Write('Testing object method variable call (LOC_REFERENCE) ..');
  292. clear_globals;
  293. clear_values;
  294. failed := false;
  295. obj_method:[email protected]_normal;
  296. obj_method(RESULT_U8BIT);
  297. if global_u8bit <> RESULT_U8BIT then
  298. failed := true;
  299. clear_globals;
  300. clear_values;
  301. value_u8bit := RESULT_U8BIT;
  302. obj_method:[email protected]_normal;
  303. obj_method(value_u8bit);
  304. if global_u8bit <> RESULT_U8BIT then
  305. failed := true;
  306. clear_globals;
  307. clear_values;
  308. value_u8bit := RESULT_U8BIT;
  309. obj_method:[email protected]_normal;
  310. obj_method(value_u8bit);
  311. if global_u8bit <> RESULT_U8BIT then
  312. failed := true;
  313. If failed then
  314. fail
  315. else
  316. WriteLn('Passed!');
  317. {****************************************************************************************************}
  318. Write('Testing class method variable call (LOC_REGISTER) ..');
  319. clear_globals;
  320. clear_values;
  321. failed := false;
  322. tclassmethod(get_class_method_normal)(RESULT_U8BIT);
  323. if global_u8bit <> RESULT_U8BIT then
  324. failed := true;
  325. clear_globals;
  326. clear_values;
  327. tclassmethodself(get_class_method_normal_self)(cla,RESULT_U8BIT);
  328. if global_u8bit <> RESULT_U8BIT then
  329. failed := true;
  330. If failed then
  331. fail
  332. else
  333. WriteLn('Passed!');
  334. Write('Testing class method variable call (LOC_REFERENCE)...');
  335. clear_globals;
  336. clear_values;
  337. failed := false;
  338. cla_method := @cla.test_normal;
  339. cla_method(RESULT_U8BIT);
  340. if global_u8bit <> RESULT_U8BIT then
  341. failed := true;
  342. clear_globals;
  343. clear_values;
  344. { cla_method := @cla.test_static;
  345. cla_method(RESULT_U8BIT);
  346. if global_u8bit <> RESULT_U8BIT then
  347. failed := true;}
  348. clear_globals;
  349. clear_values;
  350. cla_method_self := @cla.test_normal_self;
  351. cla_method_self(cla, RESULT_U8BIT);
  352. if global_u8bit <> RESULT_U8BIT then
  353. failed := true;
  354. clear_globals;
  355. clear_values;
  356. { cla_method := @cla.test_static;
  357. cla_method(RESULT_U8BIT);
  358. if global_u8bit <> RESULT_U8BIT then
  359. failed := true;}
  360. If failed then
  361. fail
  362. else
  363. WriteLn('Passed!');
  364. end.
  365. {
  366. $Log$
  367. Revision 1.7 2003-01-16 22:14:49 peter
  368. * fixed wrong methodpointer loads
  369. Revision 1.6 2002/10/29 20:44:31 carl
  370. * updated with corrects testing (removed cdecl in constructors)
  371. Revision 1.5 2002/10/21 19:21:28 carl
  372. * only test on version 1.1 +
  373. Revision 1.4 2002/10/21 19:07:08 carl
  374. + reinstate test
  375. - remove virtual method calls
  376. Revision 1.3 2002/10/21 08:03:14 pierre
  377. * added %FAIL because cdecl and virtual are not compatible
  378. Revision 1.2 2002/09/07 15:40:54 peter
  379. * old logs removed and tabs fixed
  380. Revision 1.1 2002/05/05 13:58:50 carl
  381. + finished procedural variable testsuit
  382. + finished method testsuit
  383. }