tcalpvr6.pp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  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 register }
  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);register;
  29. troutineresult = function (x: longint; y: byte): int64;register;
  30. tsimpleobject = object
  31. constructor init;
  32. procedure test_normal(x: byte);register;
  33. procedure test_static(x: byte);static;register;
  34. procedure test_virtual(x: byte);virtual;register;
  35. end;
  36. tsimpleclass = class
  37. constructor create;
  38. procedure test_normal(x: byte);register;
  39. class procedure test_static(x: byte);register;
  40. procedure test_virtual(x: byte);virtual;register;
  41. end;
  42. tobjectmethod = procedure (x: byte) of object ;register;
  43. tclassmethod = procedure (x: byte) of object;register;
  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);register;
  73. begin
  74. global_s32bit := x;
  75. global_u8bit := y;
  76. end;
  77. function testroutineresult(x: longint; y: byte): int64;register;
  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. {
  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. function get_class_method_virtual : tclassmethod;
  127. begin
  128. get_class_method_virtual := @cla.test_virtual;
  129. end;
  130. {****************************************************************************************************}
  131. constructor tsimpleobject.init;
  132. begin
  133. end;
  134. procedure tsimpleobject.test_normal(x: byte);register;
  135. begin
  136. global_u8bit := x;
  137. end;
  138. procedure tsimpleobject.test_static(x: byte);register;
  139. begin
  140. global_u8bit := x;
  141. end;
  142. procedure tsimpleobject.test_virtual(x: byte);register;
  143. begin
  144. global_u8bit := x;
  145. end;
  146. {****************************************************************************************************}
  147. constructor tsimpleclass.create;
  148. begin
  149. inherited create;
  150. end;
  151. procedure tsimpleclass. test_normal(x: byte);register;
  152. begin
  153. global_u8bit := x;
  154. end;
  155. class procedure tsimpleclass.test_static(x: byte);register;
  156. begin
  157. global_u8bit := x;
  158. end;
  159. procedure tsimpleclass.test_virtual(x: byte);register;
  160. begin
  161. global_u8bit := x;
  162. end;
  163. var
  164. failed : boolean;
  165. Begin
  166. { setup variables }
  167. proc := @testroutine;
  168. func := @testroutineresult;
  169. obj.init;
  170. cla:=tsimpleclass.create;
  171. {****************************************************************************************************}
  172. Write('Testing procedure variable call (LOC_REGISTER)..');
  173. clear_globals;
  174. clear_values;
  175. failed := false;
  176. { parameters in LOC_CONSTANT, routine address in LOC_REGISTER }
  177. troutine(getroutine)(RESULT_S32BIT,RESULT_U8BIT);
  178. if global_u8bit <> RESULT_U8BIT then
  179. failed := true;
  180. if global_s32bit <> RESULT_S32BIT then
  181. failed := true;
  182. clear_globals;
  183. clear_values;
  184. { parameters in LOC_REFERENCE,routine address in LOC_REGISTER }
  185. value_s32bit := RESULT_S32BIT;
  186. value_u8bit := RESULT_U8BIT;
  187. troutine(getroutine)(value_s32bit , value_u8bit);
  188. if global_u8bit <> RESULT_U8BIT then
  189. failed := true;
  190. if global_s32bit <> RESULT_S32BIT then
  191. failed := true;
  192. If failed then
  193. fail
  194. else
  195. WriteLn('Passed!');
  196. Write('Testing procedure variable call (LOC_REFERENCE)..');
  197. clear_globals;
  198. clear_values;
  199. failed := false;
  200. { parameters in LOC_CONSTANT, routine address in LOC_REGISTER }
  201. proc(RESULT_S32BIT,RESULT_U8BIT);
  202. if global_u8bit <> RESULT_U8BIT then
  203. failed := true;
  204. if global_s32bit <> RESULT_S32BIT then
  205. failed := true;
  206. clear_globals;
  207. clear_values;
  208. { parameters in LOC_REFERENCE,routine address in LOC_REGISTER }
  209. value_s32bit := RESULT_S32BIT;
  210. value_u8bit := RESULT_U8BIT;
  211. proc(value_s32bit , value_u8bit);
  212. if global_u8bit <> RESULT_U8BIT then
  213. failed := true;
  214. if global_s32bit <> RESULT_S32BIT then
  215. failed := true;
  216. If failed then
  217. fail
  218. else
  219. WriteLn('Passed!');
  220. {****************************************************************************************************}
  221. Write('Testing function variable call (LOC_REGISTER)..');
  222. clear_globals;
  223. clear_values;
  224. failed := false;
  225. { parameters in LOC_CONSTANT, routine address in LOC_REGISTER }
  226. global_s64bit := troutineresult(getroutineresult)(RESULT_S32BIT,RESULT_U8BIT);
  227. if global_u8bit <> RESULT_U8BIT then
  228. failed := true;
  229. if global_s32bit <> RESULT_S32BIT then
  230. failed := true;
  231. if global_s64bit <> RESULT_S64BIT then
  232. failed := true;
  233. clear_globals;
  234. clear_values;
  235. { parameters in LOC_REFERENCE,routine address in LOC_REGISTER }
  236. value_s32bit := RESULT_S32BIT;
  237. value_u8bit := RESULT_U8BIT;
  238. global_s64bit := troutineresult(getroutineresult)(value_s32bit , value_u8bit);
  239. if global_u8bit <> RESULT_U8BIT then
  240. failed := true;
  241. if global_s32bit <> RESULT_S32BIT then
  242. failed := true;
  243. if global_s64bit <> RESULT_S64BIT then
  244. failed := true;
  245. If failed then
  246. fail
  247. else
  248. WriteLn('Passed!');
  249. Write('Testing function variable call (LOC_REFERENCE)..');
  250. clear_globals;
  251. clear_values;
  252. failed := false;
  253. { parameters in LOC_CONSTANT, routine address in LOC_REGISTER }
  254. global_s64bit := func(RESULT_S32BIT,RESULT_U8BIT);
  255. if global_u8bit <> RESULT_U8BIT then
  256. failed := true;
  257. if global_s32bit <> RESULT_S32BIT then
  258. failed := true;
  259. if global_s64bit <> RESULT_S64BIT then
  260. failed := true;
  261. clear_globals;
  262. clear_values;
  263. { parameters in LOC_REFERENCE,routine address in LOC_REGISTER }
  264. value_s32bit := RESULT_S32BIT;
  265. value_u8bit := RESULT_U8BIT;
  266. global_s64bit := func(value_s32bit , value_u8bit);
  267. if global_u8bit <> RESULT_U8BIT then
  268. failed := true;
  269. if global_s32bit <> RESULT_S32BIT then
  270. failed := true;
  271. if global_s64bit <> RESULT_S64BIT then
  272. failed := true;
  273. If failed then
  274. fail
  275. else
  276. WriteLn('Passed!');
  277. {****************************************************************************************************}
  278. Write('Testing object method variable call (LOC_REGISTER) ..');
  279. clear_globals;
  280. clear_values;
  281. failed := false;
  282. tobjectmethod(get_object_method_normal)(RESULT_U8BIT);
  283. if global_u8bit <> RESULT_U8BIT then
  284. failed := true;
  285. clear_globals;
  286. clear_values;
  287. tobjectmethod(get_object_type_method_virtual)(RESULT_U8BIT);
  288. if global_u8bit <> RESULT_U8BIT then
  289. failed := true;
  290. clear_globals;
  291. clear_values;
  292. tobjectmethod(get_object_method_virtual)(RESULT_U8BIT);
  293. if global_u8bit <> RESULT_U8BIT then
  294. failed := true;
  295. clear_globals;
  296. clear_values;
  297. value_u8bit := RESULT_U8BIT;
  298. tobjectmethod(get_object_method_normal)(value_u8bit);
  299. if global_u8bit <> RESULT_U8BIT then
  300. failed := true;
  301. clear_globals;
  302. clear_values;
  303. value_u8bit := RESULT_U8BIT;
  304. tobjectmethod(get_object_type_method_virtual)(value_u8bit);
  305. if global_u8bit <> RESULT_U8BIT then
  306. failed := true;
  307. clear_globals;
  308. clear_values;
  309. value_u8bit := RESULT_U8BIT;
  310. tobjectmethod(get_object_method_virtual)(value_u8bit);
  311. if global_u8bit <> RESULT_U8BIT then
  312. failed := true;
  313. If failed then
  314. fail
  315. else
  316. WriteLn('Passed!');
  317. Write('Testing object method variable call (LOC_REFERENCE) ..');
  318. clear_globals;
  319. clear_values;
  320. failed := false;
  321. obj_method:[email protected]_normal;
  322. obj_method(RESULT_U8BIT);
  323. if global_u8bit <> RESULT_U8BIT then
  324. failed := true;
  325. clear_globals;
  326. clear_values;
  327. obj_method:[email protected]_virtual;
  328. obj_method(RESULT_U8BIT);
  329. if global_u8bit <> RESULT_U8BIT then
  330. failed := true;
  331. clear_globals;
  332. clear_values;
  333. obj_method:[email protected]_virtual;
  334. obj_method(RESULT_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]_normal;
  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]_virtual;
  348. obj_method(value_u8bit);
  349. if global_u8bit <> RESULT_U8BIT then
  350. failed := true;
  351. clear_globals;
  352. clear_values;
  353. value_u8bit := RESULT_U8BIT;
  354. obj_method:[email protected]_normal;
  355. obj_method(value_u8bit);
  356. if global_u8bit <> RESULT_U8BIT then
  357. failed := true;
  358. If failed then
  359. fail
  360. else
  361. WriteLn('Passed!');
  362. {****************************************************************************************************}
  363. Write('Testing class method variable call (LOC_REGISTER) ..');
  364. clear_globals;
  365. clear_values;
  366. failed := false;
  367. tclassmethod(get_class_method_normal)(RESULT_U8BIT);
  368. if global_u8bit <> RESULT_U8BIT then
  369. failed := true;
  370. clear_globals;
  371. clear_values;
  372. tclassmethod(get_class_method_virtual)(RESULT_U8BIT);
  373. if global_u8bit <> RESULT_U8BIT then
  374. failed := true;
  375. If failed then
  376. fail
  377. else
  378. WriteLn('Passed!');
  379. Write('Testing class method variable call (LOC_REFERENCE)...');
  380. clear_globals;
  381. clear_values;
  382. failed := false;
  383. cla_method := @cla.test_normal;
  384. cla_method(RESULT_U8BIT);
  385. if global_u8bit <> RESULT_U8BIT then
  386. failed := true;
  387. clear_globals;
  388. clear_values;
  389. cla_method := @cla.test_virtual;
  390. cla_method(RESULT_U8BIT);
  391. if global_u8bit <> RESULT_U8BIT then
  392. failed := true;
  393. clear_globals;
  394. clear_values;
  395. cla_method := @cla.test_virtual;
  396. cla_method(RESULT_U8BIT);
  397. if global_u8bit <> RESULT_U8BIT then
  398. failed := true;
  399. clear_globals;
  400. clear_values;
  401. { cla_method := @cla.test_static;
  402. cla_method(RESULT_U8BIT);
  403. if global_u8bit <> RESULT_U8BIT then
  404. failed := true;}
  405. clear_globals;
  406. clear_values;
  407. { cla_method := @cla.test_static;
  408. cla_method(RESULT_U8BIT);
  409. if global_u8bit <> RESULT_U8BIT then
  410. failed := true;}
  411. If failed then
  412. fail
  413. else
  414. WriteLn('Passed!');
  415. end.