tcalpvr1.pp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  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. procedure test_normal_self(self : tsimpleclass; x: byte); message 0;
  42. class procedure test_static_self(self : tsimpleclass; x: byte); message 1;
  43. procedure test_virtual_self(self : tsimpleclass; x: byte);virtual;message 2;
  44. end;
  45. tobjectmethod = procedure (x: byte) of object ;
  46. tclassmethod = procedure (x: byte) of object;
  47. { used for testing pocontainsself explicit parameter }
  48. tclassmethodself = procedure (self : tsimpleclass; x: byte) of object;
  49. var
  50. proc : troutine;
  51. func : troutineresult;
  52. obj_method : tobjectmethod;
  53. cla_method : tclassmethod;
  54. cla_method_self : tclassmethodself;
  55. global_s32bit : longint;
  56. global_s64bit : int64;
  57. global_u8bit : byte;
  58. value_s32bit : longint;
  59. value_u8bit : byte;
  60. obj : tsimpleobject;
  61. cla : tsimpleclass;
  62. procedure fail;
  63. begin
  64. WriteLn('Failed!');
  65. halt(1);
  66. end;
  67. procedure clear_globals;
  68. begin
  69. global_s32bit := 0;
  70. global_u8bit := 0;
  71. global_s64bit := 0;
  72. end;
  73. procedure clear_values;
  74. begin
  75. value_s32bit := 0;
  76. value_u8bit := 0;
  77. end;
  78. procedure testroutine(x: longint; y: byte);
  79. begin
  80. global_s32bit := x;
  81. global_u8bit := y;
  82. end;
  83. function testroutineresult(x: longint; y: byte): int64;
  84. begin
  85. global_s32bit := x;
  86. global_u8bit := y;
  87. testroutineresult := RESULT_S64BIT;
  88. end;
  89. function getroutine: troutine;
  90. begin
  91. getroutine:=proc;
  92. end;
  93. function getroutineresult : troutineresult;
  94. begin
  95. getroutineresult := func;
  96. end;
  97. { IMPOSSIBLE TO DO CURRENTLY !
  98. function get_object_method_static : tnormalmethod;
  99. begin
  100. get_object_method_static := @obj.test_static;
  101. end;
  102. }
  103. { objects access }
  104. function get_object_method_normal : tobjectmethod;
  105. begin
  106. get_object_method_normal := @obj.test_normal;
  107. end;
  108. function get_object_type_method_virtual : tobjectmethod;
  109. begin
  110. get_object_type_method_virtual := @obj.test_virtual;
  111. end;
  112. function get_object_method_virtual : tobjectmethod;
  113. begin
  114. get_object_method_virtual := @obj.test_virtual;
  115. end;
  116. { class access }
  117. function get_class_method_normal_self : tclassmethodself;
  118. begin
  119. get_class_method_normal_self := @cla.test_normal_self;
  120. end;
  121. {
  122. HOW CAN WE GET THIS ADDRESS???
  123. function get_class_method_static_self : tclassmethodself;
  124. begin
  125. get_class_method_static_self := @cla.test_static_self;
  126. end;
  127. }
  128. function get_class_method_virtual_self : tclassmethodself;
  129. begin
  130. get_class_method_virtual_self := @cla.test_virtual_self;
  131. end;
  132. function get_class_method_normal : tclassmethod;
  133. begin
  134. get_class_method_normal := @cla.test_normal;
  135. end;
  136. {
  137. function get_class_method_static : tclassmethod;
  138. begin
  139. get_class_method_static := @cla.test_static;
  140. end;}
  141. function get_class_method_virtual : tclassmethod;
  142. begin
  143. get_class_method_virtual := @cla.test_virtual;
  144. end;
  145. {****************************************************************************************************}
  146. constructor tsimpleobject.init;
  147. begin
  148. end;
  149. procedure tsimpleobject.test_normal(x: byte);
  150. begin
  151. global_u8bit := x;
  152. end;
  153. procedure tsimpleobject.test_static(x: byte);
  154. begin
  155. global_u8bit := x;
  156. end;
  157. procedure tsimpleobject.test_virtual(x: byte);
  158. begin
  159. global_u8bit := x;
  160. end;
  161. {****************************************************************************************************}
  162. constructor tsimpleclass.create;
  163. begin
  164. inherited create;
  165. end;
  166. procedure tsimpleclass. test_normal(x: byte);
  167. begin
  168. global_u8bit := x;
  169. end;
  170. class procedure tsimpleclass.test_static(x: byte);
  171. begin
  172. global_u8bit := x;
  173. end;
  174. procedure tsimpleclass.test_virtual(x: byte);
  175. begin
  176. global_u8bit := x;
  177. end;
  178. procedure tsimpleclass.test_normal_self(self : tsimpleclass; x: byte);
  179. begin
  180. global_u8bit := x;
  181. end;
  182. class procedure tsimpleclass.test_static_self(self : tsimpleclass; x: byte);
  183. begin
  184. global_u8bit := x;
  185. end;
  186. procedure tsimpleclass.test_virtual_self(self : tsimpleclass; x: byte);
  187. begin
  188. global_u8bit := x;
  189. end;
  190. var
  191. failed : boolean;
  192. Begin
  193. { setup variables }
  194. proc := @testroutine;
  195. func := @testroutineresult;
  196. obj.init;
  197. cla:=tsimpleclass.create;
  198. {****************************************************************************************************}
  199. Write('Testing procedure variable call (LOC_REGISTER)..');
  200. clear_globals;
  201. clear_values;
  202. failed := false;
  203. { parameters in LOC_CONSTANT, routine address in LOC_REGISTER }
  204. troutine(getroutine)(RESULT_S32BIT,RESULT_U8BIT);
  205. if global_u8bit <> RESULT_U8BIT then
  206. failed := true;
  207. if global_s32bit <> RESULT_S32BIT then
  208. failed := true;
  209. clear_globals;
  210. clear_values;
  211. { parameters in LOC_REFERENCE,routine address in LOC_REGISTER }
  212. value_s32bit := RESULT_S32BIT;
  213. value_u8bit := RESULT_U8BIT;
  214. troutine(getroutine)(value_s32bit , value_u8bit);
  215. if global_u8bit <> RESULT_U8BIT then
  216. failed := true;
  217. if global_s32bit <> RESULT_S32BIT then
  218. failed := true;
  219. If failed then
  220. fail
  221. else
  222. WriteLn('Passed!');
  223. Write('Testing procedure variable call (LOC_REFERENCE)..');
  224. clear_globals;
  225. clear_values;
  226. failed := false;
  227. { parameters in LOC_CONSTANT, routine address in LOC_REGISTER }
  228. proc(RESULT_S32BIT,RESULT_U8BIT);
  229. if global_u8bit <> RESULT_U8BIT then
  230. failed := true;
  231. if global_s32bit <> RESULT_S32BIT 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. proc(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 failed then
  244. fail
  245. else
  246. WriteLn('Passed!');
  247. {****************************************************************************************************}
  248. Write('Testing function variable call (LOC_REGISTER)..');
  249. clear_globals;
  250. clear_values;
  251. failed := false;
  252. { parameters in LOC_CONSTANT, routine address in LOC_REGISTER }
  253. global_s64bit := troutineresult(getroutineresult)(RESULT_S32BIT,RESULT_U8BIT);
  254. if global_u8bit <> RESULT_U8BIT then
  255. failed := true;
  256. if global_s32bit <> RESULT_S32BIT then
  257. failed := true;
  258. if global_s64bit <> RESULT_S64BIT then
  259. failed := true;
  260. clear_globals;
  261. clear_values;
  262. { parameters in LOC_REFERENCE,routine address in LOC_REGISTER }
  263. value_s32bit := RESULT_S32BIT;
  264. value_u8bit := RESULT_U8BIT;
  265. global_s64bit := troutineresult(getroutineresult)(value_s32bit , value_u8bit);
  266. if global_u8bit <> RESULT_U8BIT then
  267. failed := true;
  268. if global_s32bit <> RESULT_S32BIT then
  269. failed := true;
  270. if global_s64bit <> RESULT_S64BIT then
  271. failed := true;
  272. If failed then
  273. fail
  274. else
  275. WriteLn('Passed!');
  276. Write('Testing function variable call (LOC_REFERENCE)..');
  277. clear_globals;
  278. clear_values;
  279. failed := false;
  280. { parameters in LOC_CONSTANT, routine address in LOC_REGISTER }
  281. global_s64bit := func(RESULT_S32BIT,RESULT_U8BIT);
  282. if global_u8bit <> RESULT_U8BIT then
  283. failed := true;
  284. if global_s32bit <> RESULT_S32BIT then
  285. failed := true;
  286. if global_s64bit <> RESULT_S64BIT then
  287. failed := true;
  288. clear_globals;
  289. clear_values;
  290. { parameters in LOC_REFERENCE,routine address in LOC_REGISTER }
  291. value_s32bit := RESULT_S32BIT;
  292. value_u8bit := RESULT_U8BIT;
  293. global_s64bit := func(value_s32bit , value_u8bit);
  294. if global_u8bit <> RESULT_U8BIT then
  295. failed := true;
  296. if global_s32bit <> RESULT_S32BIT then
  297. failed := true;
  298. if global_s64bit <> RESULT_S64BIT then
  299. failed := true;
  300. If failed then
  301. fail
  302. else
  303. WriteLn('Passed!');
  304. {****************************************************************************************************}
  305. Write('Testing object method variable call (LOC_REGISTER) ..');
  306. clear_globals;
  307. clear_values;
  308. failed := false;
  309. tobjectmethod(get_object_method_normal)(RESULT_U8BIT);
  310. if global_u8bit <> RESULT_U8BIT then
  311. failed := true;
  312. clear_globals;
  313. clear_values;
  314. tobjectmethod(get_object_type_method_virtual)(RESULT_U8BIT);
  315. if global_u8bit <> RESULT_U8BIT then
  316. failed := true;
  317. clear_globals;
  318. clear_values;
  319. tobjectmethod(get_object_method_virtual)(RESULT_U8BIT);
  320. if global_u8bit <> RESULT_U8BIT then
  321. failed := true;
  322. clear_globals;
  323. clear_values;
  324. value_u8bit := RESULT_U8BIT;
  325. tobjectmethod(get_object_method_normal)(value_u8bit);
  326. if global_u8bit <> RESULT_U8BIT then
  327. failed := true;
  328. clear_globals;
  329. clear_values;
  330. value_u8bit := RESULT_U8BIT;
  331. tobjectmethod(get_object_type_method_virtual)(value_u8bit);
  332. if global_u8bit <> RESULT_U8BIT then
  333. failed := true;
  334. clear_globals;
  335. clear_values;
  336. value_u8bit := RESULT_U8BIT;
  337. tobjectmethod(get_object_method_virtual)(value_u8bit);
  338. if global_u8bit <> RESULT_U8BIT then
  339. failed := true;
  340. If failed then
  341. fail
  342. else
  343. WriteLn('Passed!');
  344. Write('Testing object method variable call (LOC_REFERENCE) ..');
  345. clear_globals;
  346. clear_values;
  347. failed := false;
  348. obj_method:[email protected]_normal;
  349. obj_method(RESULT_U8BIT);
  350. if global_u8bit <> RESULT_U8BIT then
  351. failed := true;
  352. clear_globals;
  353. clear_values;
  354. obj_method:[email protected]_virtual;
  355. obj_method(RESULT_U8BIT);
  356. if global_u8bit <> RESULT_U8BIT then
  357. failed := true;
  358. clear_globals;
  359. clear_values;
  360. obj_method:[email protected]_virtual;
  361. obj_method(RESULT_U8BIT);
  362. if global_u8bit <> RESULT_U8BIT then
  363. failed := true;
  364. clear_globals;
  365. clear_values;
  366. value_u8bit := RESULT_U8BIT;
  367. obj_method:[email protected]_normal;
  368. obj_method(value_u8bit);
  369. if global_u8bit <> RESULT_U8BIT then
  370. failed := true;
  371. clear_globals;
  372. clear_values;
  373. value_u8bit := RESULT_U8BIT;
  374. obj_method:[email protected]_virtual;
  375. obj_method(value_u8bit);
  376. if global_u8bit <> RESULT_U8BIT then
  377. failed := true;
  378. clear_globals;
  379. clear_values;
  380. value_u8bit := RESULT_U8BIT;
  381. obj_method:[email protected]_normal;
  382. obj_method(value_u8bit);
  383. if global_u8bit <> RESULT_U8BIT then
  384. failed := true;
  385. If failed then
  386. fail
  387. else
  388. WriteLn('Passed!');
  389. {****************************************************************************************************}
  390. Write('Testing class method variable call (LOC_REGISTER) ..');
  391. clear_globals;
  392. clear_values;
  393. failed := false;
  394. tclassmethod(get_class_method_normal)(RESULT_U8BIT);
  395. if global_u8bit <> RESULT_U8BIT then
  396. failed := true;
  397. clear_globals;
  398. clear_values;
  399. tclassmethod(get_class_method_virtual)(RESULT_U8BIT);
  400. if global_u8bit <> RESULT_U8BIT then
  401. failed := true;
  402. clear_globals;
  403. clear_values;
  404. tclassmethodself(get_class_method_normal_self)(cla,RESULT_U8BIT);
  405. if global_u8bit <> RESULT_U8BIT then
  406. failed := true;
  407. clear_globals;
  408. clear_values;
  409. tclassmethodself(get_class_method_virtual_self)(cla,RESULT_U8BIT);
  410. if global_u8bit <> RESULT_U8BIT then
  411. failed := true;
  412. If failed then
  413. fail
  414. else
  415. WriteLn('Passed!');
  416. Write('Testing class method variable call (LOC_REFERENCE)...');
  417. clear_globals;
  418. clear_values;
  419. failed := false;
  420. cla_method := @cla.test_normal;
  421. cla_method(RESULT_U8BIT);
  422. if global_u8bit <> RESULT_U8BIT then
  423. failed := true;
  424. clear_globals;
  425. clear_values;
  426. cla_method := @cla.test_virtual;
  427. cla_method(RESULT_U8BIT);
  428. if global_u8bit <> RESULT_U8BIT then
  429. failed := true;
  430. clear_globals;
  431. clear_values;
  432. cla_method := @cla.test_virtual;
  433. cla_method(RESULT_U8BIT);
  434. if global_u8bit <> RESULT_U8BIT then
  435. failed := true;
  436. clear_globals;
  437. clear_values;
  438. { cla_method := @cla.test_static;
  439. cla_method(RESULT_U8BIT);
  440. if global_u8bit <> RESULT_U8BIT then
  441. failed := true;}
  442. clear_globals;
  443. clear_values;
  444. cla_method_self := @cla.test_normal_self;
  445. cla_method_self(cla, RESULT_U8BIT);
  446. if global_u8bit <> RESULT_U8BIT then
  447. failed := true;
  448. clear_globals;
  449. clear_values;
  450. cla_method_self := @cla.test_virtual_self;
  451. cla_method_self(cla,RESULT_U8BIT);
  452. if global_u8bit <> RESULT_U8BIT then
  453. failed := true;
  454. clear_globals;
  455. clear_values;
  456. cla_method_self := @cla.test_virtual_self;
  457. cla_method_self(cla, RESULT_U8BIT);
  458. if global_u8bit <> RESULT_U8BIT then
  459. failed := true;
  460. clear_globals;
  461. clear_values;
  462. { cla_method := @cla.test_static;
  463. cla_method(RESULT_U8BIT);
  464. if global_u8bit <> RESULT_U8BIT then
  465. failed := true;}
  466. If failed then
  467. fail
  468. else
  469. WriteLn('Passed!');
  470. end.
  471. {
  472. $Log$
  473. Revision 1.5 2003-01-16 22:14:49 peter
  474. * fixed wrong methodpointer loads
  475. Revision 1.4 2002/09/07 15:40:54 peter
  476. * old logs removed and tabs fixed
  477. Revision 1.3 2002/04/15 14:40:45 carl
  478. +fixed class creation problem
  479. Revision 1.2 2002/04/13 21:04:10 carl
  480. * fixed stupid typo
  481. Revision 1.1 2002/04/13 11:04:40 carl
  482. + procedure variable testing (stil not sure about class/object proc. variables)
  483. }