testcall.pas 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. program testcall;
  2. uses CallSpec;
  3. { Testing program for calls of special functions. }
  4. procedure TestLocal;
  5. var
  6. I: Integer;
  7. procedure VoidLocal; {$ifndef FPC}far;{$endif}
  8. begin
  9. Write(I)
  10. end;
  11. procedure PointerLocal(J: LongInt); {$ifndef FPC}far;{$endif}
  12. begin
  13. Write('(', I, ',', J, ')')
  14. end;
  15. begin
  16. I := 4711;
  17. Write('VoidLocal test: ');
  18. VoidLocal;
  19. Write(' = ');
  20. CallVoidLocal(@VoidLocal, CurrentFramePointer);
  21. WriteLn;
  22. Write('PointerLocal test: ');
  23. PointerLocal(0815);
  24. Write(' = ');
  25. CallPointerLocal(@PointerLocal, CurrentFramePointer, pointer(0815));
  26. WriteLn
  27. end;
  28. type
  29. TTest = object
  30. K: Integer;
  31. procedure TestMethodLocal;
  32. end;
  33. var
  34. Test: TTest;
  35. procedure TTest.TestMethodLocal;
  36. var
  37. I: Integer;
  38. procedure VoidMethodLocal; {$ifndef FPC}far;{$endif}
  39. var
  40. t: Integer;
  41. begin
  42. t := K;
  43. Write('(', K, ',', I, ',', t, ')')
  44. end;
  45. procedure PointerMethodLocal(J: LongInt); {$ifndef FPC}far;{$endif}
  46. var
  47. t: Integer;
  48. begin
  49. t := K;
  50. Write('(', K, ',', I, ',', J, ',', t, ')')
  51. end;
  52. begin
  53. I := 123;
  54. Write('VoidMethodLocal test: ');
  55. VoidMethodLocal;
  56. Write(' = ');
  57. CallVoidMethodLocal(@VoidMethodLocal,
  58. CurrentFramePointer, @Self);
  59. WriteLn;
  60. Write('PointerMethodLocal test: ');
  61. PointerMethodLocal(987);
  62. Write(' = ');
  63. CallPointerMethodLocal(@PointerMethodLocal,
  64. CurrentFramePointer, @Self, pointer(987));
  65. WriteLn
  66. end;
  67. type
  68. PA = ^TA;
  69. TA = object
  70. I: LongInt;
  71. constructor VoidInit;
  72. constructor PointerInit(P: Pointer);
  73. destructor Done;
  74. procedure VoidMethod;
  75. procedure PointerMethod(P: Pointer);
  76. end;
  77. constructor TA.VoidInit;
  78. begin
  79. I := 2718
  80. end;
  81. constructor TA.PointerInit(P: Pointer);
  82. begin
  83. I := LongInt(P)
  84. end;
  85. destructor TA.Done;
  86. begin
  87. end;
  88. procedure TestConstructor;
  89. var
  90. P, Q: PA;
  91. begin
  92. P := CallVoidConstructor(@TA.VoidInit, nil, TypeOf(TA));
  93. WriteLn('CallVoidConstructor test: 2718 = ', P^.I);
  94. Dispose(P,Done);
  95. Q := CallPointerConstructor(@TA.PointerInit, nil, TypeOf(TA), pointer(14142));
  96. WriteLn('CallPointerConstructor test: 14142 = ', Q^.I);
  97. Dispose(Q,Done);
  98. end;
  99. procedure TA.VoidMethod;
  100. begin
  101. I := 2718;
  102. end;
  103. procedure TA.PointerMethod(P: Pointer);
  104. begin
  105. I := LongInt(P)
  106. end;
  107. procedure TestMethod;
  108. var
  109. A: TA;
  110. begin
  111. CallVoidMethod(@TA.VoidMethod, @A);
  112. WriteLn('CallVoidMethod test: 2718 = ', A.I);
  113. CallPointerMethod(@TA.PointerMethod, @A, pointer(14142));
  114. WriteLn('CallPointerMethod test: 14142 = ', A.I);
  115. end;
  116. begin
  117. WriteLn('If the CallSpec unit is implemented properly for your');
  118. WriteLn('Pascal compiler, you will see 8 correct equations, and');
  119. WriteLn('this program will terminate without error.');
  120. WriteLn;
  121. TestLocal;
  122. Test.K := 3141;
  123. Test.TestMethodLocal;
  124. TestConstructor;
  125. TestMethod;
  126. WriteLn;
  127. WriteLn('Finished.');
  128. end.