tcalpvr1.pp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  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 standard }
  16. { calling conventions. }
  17. {****************************************************************}
  18. program tcalpvr1;
  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);
  29. troutineresult = function (x: longint; y: byte): int64;
  30. tsimpleobject = object
  31. constructor init;
  32. procedure test_normal(x: byte);
  33. procedure test_static(x: byte);static;
  34. procedure test_virtual(x: byte);virtual;
  35. end;
  36. tsimpleclass = class
  37. constructor create;
  38. procedure test_normal(x: byte);
  39. class procedure test_static(x: byte);
  40. procedure test_virtual(x: byte);virtual;
  41. end;
  42. tobjectmethod = procedure (x: byte) of object ;
  43. tclassmethod = procedure (x: byte) of object;
  44. var
  45. proc : troutine;
  46. func : troutineresult;
  47. obj_method : tobjectmethod;
  48. cla_method : tclassmethod;
  49. global_s32bit : longint;
  50. global_s64bit : int64;
  51. global_u8bit : byte;
  52. value_s32bit : longint;
  53. value_u8bit : byte;
  54. obj : tsimpleobject;
  55. cla : tsimpleclass;
  56. procedure fail;
  57. begin
  58. WriteLn('Failed!');
  59. halt(1);
  60. end;
  61. procedure clear_globals;
  62. begin
  63. global_s32bit := 0;
  64. global_u8bit := 0;
  65. global_s64bit := 0;
  66. end;
  67. procedure clear_values;
  68. begin
  69. value_s32bit := 0;
  70. value_u8bit := 0;
  71. end;
  72. procedure testroutine(x: longint; y: byte);
  73. begin
  74. global_s32bit := x;
  75. global_u8bit := y;
  76. end;
  77. function testroutineresult(x: longint; y: byte): int64;
  78. begin
  79. global_s32bit := x;
  80. global_u8bit := y;
  81. testroutineresult := RESULT_S64BIT;
  82. end;
  83. function getroutine: troutine;
  84. begin
  85. getroutine:=proc;
  86. end;
  87. function getroutineresult : troutineresult;
  88. begin
  89. getroutineresult := func;
  90. end;
  91. { IMPOSSIBLE TO DO CURRENTLY !
  92. function get_object_method_static : tnormalmethod;
  93. begin
  94. get_object_method_static := @obj.test_static;
  95. end;
  96. }
  97. { objects access }
  98. function get_object_method_normal : tobjectmethod;
  99. begin
  100. get_object_method_normal := @obj.test_normal;
  101. end;
  102. function get_object_type_method_virtual : tobjectmethod;
  103. begin
  104. get_object_type_method_virtual := @obj.test_virtual;
  105. end;
  106. function get_object_method_virtual : tobjectmethod;
  107. begin
  108. get_object_method_virtual := @obj.test_virtual;
  109. end;
  110. function get_class_method_normal : tclassmethod;
  111. begin
  112. get_class_method_normal := @cla.test_normal;
  113. end;
  114. {
  115. function get_class_method_static : tclassmethod;
  116. begin
  117. get_class_method_static := @cla.test_static;
  118. end;}
  119. function get_class_method_virtual : tclassmethod;
  120. begin
  121. get_class_method_virtual := @cla.test_virtual;
  122. end;
  123. {****************************************************************************************************}
  124. constructor tsimpleobject.init;
  125. begin
  126. end;
  127. procedure tsimpleobject.test_normal(x: byte);
  128. begin
  129. global_u8bit := x;
  130. end;
  131. procedure tsimpleobject.test_static(x: byte);
  132. begin
  133. global_u8bit := x;
  134. end;
  135. procedure tsimpleobject.test_virtual(x: byte);
  136. begin
  137. global_u8bit := x;
  138. end;
  139. {****************************************************************************************************}
  140. constructor tsimpleclass.create;
  141. begin
  142. inherited create;
  143. end;
  144. procedure tsimpleclass. test_normal(x: byte);
  145. begin
  146. global_u8bit := x;
  147. end;
  148. class procedure tsimpleclass.test_static(x: byte);
  149. begin
  150. global_u8bit := x;
  151. end;
  152. procedure tsimpleclass.test_virtual(x: byte);
  153. begin
  154. global_u8bit := x;
  155. end;
  156. var
  157. failed : boolean;
  158. Begin
  159. { setup variables }
  160. proc := @testroutine;
  161. func := @testroutineresult;
  162. obj.init;
  163. cla:=tsimpleclass.create;
  164. {****************************************************************************************************}
  165. Write('Testing procedure variable call (LOC_REGISTER)..');
  166. clear_globals;
  167. clear_values;
  168. failed := false;
  169. { parameters in LOC_CONSTANT, routine address in LOC_REGISTER }
  170. troutine(getroutine)(RESULT_S32BIT,RESULT_U8BIT);
  171. if global_u8bit <> RESULT_U8BIT then
  172. failed := true;
  173. if global_s32bit <> RESULT_S32BIT then
  174. failed := true;
  175. clear_globals;
  176. clear_values;
  177. { parameters in LOC_REFERENCE,routine address in LOC_REGISTER }
  178. value_s32bit := RESULT_S32BIT;
  179. value_u8bit := RESULT_U8BIT;
  180. troutine(getroutine)(value_s32bit , value_u8bit);
  181. if global_u8bit <> RESULT_U8BIT then
  182. failed := true;
  183. if global_s32bit <> RESULT_S32BIT then
  184. failed := true;
  185. If failed then
  186. fail
  187. else
  188. WriteLn('Passed!');
  189. Write('Testing procedure variable call (LOC_REFERENCE)..');
  190. clear_globals;
  191. clear_values;
  192. failed := false;
  193. { parameters in LOC_CONSTANT, routine address in LOC_REGISTER }
  194. proc(RESULT_S32BIT,RESULT_U8BIT);
  195. if global_u8bit <> RESULT_U8BIT then
  196. failed := true;
  197. if global_s32bit <> RESULT_S32BIT then
  198. failed := true;
  199. clear_globals;
  200. clear_values;
  201. { parameters in LOC_REFERENCE,routine address in LOC_REGISTER }
  202. value_s32bit := RESULT_S32BIT;
  203. value_u8bit := RESULT_U8BIT;
  204. proc(value_s32bit , value_u8bit);
  205. if global_u8bit <> RESULT_U8BIT then
  206. failed := true;
  207. if global_s32bit <> RESULT_S32BIT then
  208. failed := true;
  209. If failed then
  210. fail
  211. else
  212. WriteLn('Passed!');
  213. {****************************************************************************************************}
  214. Write('Testing function variable call (LOC_REGISTER)..');
  215. clear_globals;
  216. clear_values;
  217. failed := false;
  218. { parameters in LOC_CONSTANT, routine address in LOC_REGISTER }
  219. global_s64bit := troutineresult(getroutineresult)(RESULT_S32BIT,RESULT_U8BIT);
  220. if global_u8bit <> RESULT_U8BIT then
  221. failed := true;
  222. if global_s32bit <> RESULT_S32BIT then
  223. failed := true;
  224. if global_s64bit <> RESULT_S64BIT then
  225. failed := true;
  226. clear_globals;
  227. clear_values;
  228. { parameters in LOC_REFERENCE,routine address in LOC_REGISTER }
  229. value_s32bit := RESULT_S32BIT;
  230. value_u8bit := RESULT_U8BIT;
  231. global_s64bit := troutineresult(getroutineresult)(value_s32bit , value_u8bit);
  232. if global_u8bit <> RESULT_U8BIT then
  233. failed := true;
  234. if global_s32bit <> RESULT_S32BIT then
  235. failed := true;
  236. if global_s64bit <> RESULT_S64BIT then
  237. failed := true;
  238. If failed then
  239. fail
  240. else
  241. WriteLn('Passed!');
  242. Write('Testing function variable call (LOC_REFERENCE)..');
  243. clear_globals;
  244. clear_values;
  245. failed := false;
  246. { parameters in LOC_CONSTANT, routine address in LOC_REGISTER }
  247. global_s64bit := func(RESULT_S32BIT,RESULT_U8BIT);
  248. if global_u8bit <> RESULT_U8BIT then
  249. failed := true;
  250. if global_s32bit <> RESULT_S32BIT then
  251. failed := true;
  252. if global_s64bit <> RESULT_S64BIT then
  253. failed := true;
  254. clear_globals;
  255. clear_values;
  256. { parameters in LOC_REFERENCE,routine address in LOC_REGISTER }
  257. value_s32bit := RESULT_S32BIT;
  258. value_u8bit := RESULT_U8BIT;
  259. global_s64bit := func(value_s32bit , value_u8bit);
  260. if global_u8bit <> RESULT_U8BIT then
  261. failed := true;
  262. if global_s32bit <> RESULT_S32BIT then
  263. failed := true;
  264. if global_s64bit <> RESULT_S64BIT then
  265. failed := true;
  266. If failed then
  267. fail
  268. else
  269. WriteLn('Passed!');
  270. {****************************************************************************************************}
  271. Write('Testing object method variable call (LOC_REGISTER) ..');
  272. clear_globals;
  273. clear_values;
  274. failed := false;
  275. tobjectmethod(get_object_method_normal)(RESULT_U8BIT);
  276. if global_u8bit <> RESULT_U8BIT then
  277. failed := true;
  278. clear_globals;
  279. clear_values;
  280. tobjectmethod(get_object_type_method_virtual)(RESULT_U8BIT);
  281. if global_u8bit <> RESULT_U8BIT then
  282. failed := true;
  283. clear_globals;
  284. clear_values;
  285. tobjectmethod(get_object_method_virtual)(RESULT_U8BIT);
  286. if global_u8bit <> RESULT_U8BIT then
  287. failed := true;
  288. clear_globals;
  289. clear_values;
  290. value_u8bit := RESULT_U8BIT;
  291. tobjectmethod(get_object_method_normal)(value_u8bit);
  292. if global_u8bit <> RESULT_U8BIT then
  293. failed := true;
  294. clear_globals;
  295. clear_values;
  296. value_u8bit := RESULT_U8BIT;
  297. tobjectmethod(get_object_type_method_virtual)(value_u8bit);
  298. if global_u8bit <> RESULT_U8BIT then
  299. failed := true;
  300. clear_globals;
  301. clear_values;
  302. value_u8bit := RESULT_U8BIT;
  303. tobjectmethod(get_object_method_virtual)(value_u8bit);
  304. if global_u8bit <> RESULT_U8BIT then
  305. failed := true;
  306. If failed then
  307. fail
  308. else
  309. WriteLn('Passed!');
  310. Write('Testing object method variable call (LOC_REFERENCE) ..');
  311. clear_globals;
  312. clear_values;
  313. failed := false;
  314. obj_method:[email protected]_normal;
  315. obj_method(RESULT_U8BIT);
  316. if global_u8bit <> RESULT_U8BIT then
  317. failed := true;
  318. clear_globals;
  319. clear_values;
  320. obj_method:[email protected]_virtual;
  321. obj_method(RESULT_U8BIT);
  322. if global_u8bit <> RESULT_U8BIT then
  323. failed := true;
  324. clear_globals;
  325. clear_values;
  326. obj_method:[email protected]_virtual;
  327. obj_method(RESULT_U8BIT);
  328. if global_u8bit <> RESULT_U8BIT then
  329. failed := true;
  330. clear_globals;
  331. clear_values;
  332. value_u8bit := RESULT_U8BIT;
  333. obj_method:[email protected]_normal;
  334. obj_method(value_u8bit);
  335. if global_u8bit <> RESULT_U8BIT then
  336. failed := true;
  337. clear_globals;
  338. clear_values;
  339. value_u8bit := RESULT_U8BIT;
  340. obj_method:[email protected]_virtual;
  341. obj_method(value_u8bit);
  342. if global_u8bit <> RESULT_U8BIT then
  343. failed := true;
  344. clear_globals;
  345. clear_values;
  346. value_u8bit := RESULT_U8BIT;
  347. obj_method:[email protected]_normal;
  348. obj_method(value_u8bit);
  349. if global_u8bit <> RESULT_U8BIT then
  350. failed := true;
  351. If failed then
  352. fail
  353. else
  354. WriteLn('Passed!');
  355. {****************************************************************************************************}
  356. Write('Testing class method variable call (LOC_REGISTER) ..');
  357. clear_globals;
  358. clear_values;
  359. failed := false;
  360. tclassmethod(get_class_method_normal)(RESULT_U8BIT);
  361. if global_u8bit <> RESULT_U8BIT then
  362. failed := true;
  363. If failed then
  364. fail
  365. else
  366. WriteLn('Passed!');
  367. clear_globals;
  368. clear_values;
  369. tclassmethod(get_class_method_virtual)(RESULT_U8BIT);
  370. if global_u8bit <> RESULT_U8BIT then
  371. failed := true;
  372. clear_globals;
  373. clear_values;
  374. Write('Testing class method variable call (LOC_REFERENCE)...');
  375. clear_globals;
  376. clear_values;
  377. failed := false;
  378. cla_method := @cla.test_normal;
  379. cla_method(RESULT_U8BIT);
  380. if global_u8bit <> RESULT_U8BIT then
  381. failed := true;
  382. clear_globals;
  383. clear_values;
  384. cla_method := @cla.test_virtual;
  385. cla_method(RESULT_U8BIT);
  386. if global_u8bit <> RESULT_U8BIT then
  387. failed := true;
  388. clear_globals;
  389. clear_values;
  390. cla_method := @cla.test_virtual;
  391. cla_method(RESULT_U8BIT);
  392. if global_u8bit <> RESULT_U8BIT then
  393. failed := true;
  394. clear_globals;
  395. clear_values;
  396. { cla_method := @cla.test_static;
  397. cla_method(RESULT_U8BIT);
  398. if global_u8bit <> RESULT_U8BIT then
  399. failed := true;}
  400. clear_globals;
  401. clear_values;
  402. { cla_method := @cla.test_static;
  403. cla_method(RESULT_U8BIT);
  404. if global_u8bit <> RESULT_U8BIT then
  405. failed := true;}
  406. If failed then
  407. fail
  408. else
  409. WriteLn('Passed!');
  410. end.