tcalpvr4.pp 12 KB

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