File: testcall.pas

package info (click to toggle)
fpc 0.99.13-19991013-4
  • links: PTS
  • area: main
  • in suites: potato
  • size: 23,104 kB
  • ctags: 9,760
  • sloc: pascal: 253,711; ansic: 5,236; makefile: 3,855; yacc: 2,016; lex: 707; asm: 526; xml: 443; sh: 200; perl: 87; sed: 21; csh: 12; cpp: 1
file content (155 lines) | stat: -rw-r--r-- 2,986 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
program testcall;
uses CallSpec;

{ Testing program for calls of special functions. }

procedure TestLocal;
var
  I: Integer;

        procedure VoidLocal; {$ifndef FPC}far;{$endif}
        begin
          Write(I)
        end;

        procedure PointerLocal(J: LongInt); {$ifndef FPC}far;{$endif}
        begin
          Write('(', I, ',', J, ')')
        end;

begin
  I := 4711;
  Write('VoidLocal test: ');
  VoidLocal;
  Write(' = ');
  CallVoidLocal(@VoidLocal, CurrentFramePointer);
  WriteLn;

  Write('PointerLocal test: ');
  PointerLocal(0815);
  Write(' = ');
  CallPointerLocal(@PointerLocal, CurrentFramePointer, pointer(0815));
  WriteLn
end;

type
  TTest = object
    K: Integer;
    procedure TestMethodLocal;
  end;

var
  Test: TTest;

procedure TTest.TestMethodLocal;
var
  I: Integer;

        procedure VoidMethodLocal; {$ifndef FPC}far;{$endif}
        var
          t: Integer;
        begin
          t := K;
          Write('(', K, ',', I, ',', t, ')')
        end;

        procedure PointerMethodLocal(J: LongInt); {$ifndef FPC}far;{$endif}
        var
          t: Integer;
        begin
          t := K;
          Write('(', K, ',', I, ',', J, ',', t, ')')
        end;

begin
  I := 123;
  Write('VoidMethodLocal test: ');
  VoidMethodLocal;
  Write(' = ');
  CallVoidMethodLocal(@VoidMethodLocal,
    CurrentFramePointer, @Self);
  WriteLn;

  Write('PointerMethodLocal test: ');
  PointerMethodLocal(987);
  Write(' = ');
  CallPointerMethodLocal(@PointerMethodLocal,
    CurrentFramePointer, @Self, pointer(987));
  WriteLn
end;

type
  PA = ^TA;
  TA = object
    I: LongInt;
    constructor VoidInit;
    constructor PointerInit(P: Pointer);
    destructor Done;
    procedure VoidMethod;
    procedure PointerMethod(P: Pointer);
  end;

constructor TA.VoidInit;
begin
  I := 2718
end;

constructor TA.PointerInit(P: Pointer);
begin
  I := LongInt(P)
end;

destructor TA.Done;
begin
end;

procedure TestConstructor;
var
  P, Q: PA;
begin
  P := CallVoidConstructor(@TA.VoidInit, nil, TypeOf(TA));
  WriteLn('CallVoidConstructor test:  2718 = ', P^.I);
  Dispose(P,Done);
  Q := CallPointerConstructor(@TA.PointerInit, nil, TypeOf(TA), pointer(14142));
  WriteLn('CallPointerConstructor test:  14142 = ', Q^.I);
  Dispose(Q,Done);
end;

procedure TA.VoidMethod;
begin
  I := 2718;
end;

procedure TA.PointerMethod(P: Pointer);
begin
  I := LongInt(P)
end;

procedure TestMethod;
var
  A: TA;
begin
  CallVoidMethod(@TA.VoidMethod, @A);
  WriteLn('CallVoidMethod test:  2718 = ', A.I);
  CallPointerMethod(@TA.PointerMethod, @A, pointer(14142));
  WriteLn('CallPointerMethod test:  14142 = ', A.I);
end;

begin
  WriteLn('If the CallSpec unit is implemented properly for your');
  WriteLn('Pascal compiler, you will see 8 correct equations, and');
  WriteLn('this program will terminate without error.');
  WriteLn;

  TestLocal;

  Test.K := 3141;
  Test.TestMethodLocal;

  TestConstructor;

  TestMethod;

  WriteLn;
  WriteLn('Finished.');
end.