Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 199 lines (115 sloc) 3.975 kb
a40f31b Added docs on Parrot's calling conventions.
Dan Sugalski authored
1 =head1 TITLE
2
3 Parrot Calling Conventions
4
5 =head1 VERSION
6
7 1
8
9 =head2 CURRENT
10
11 Maintainer: Dan Sugalski
12 Class: Internals
13 PDD Number: 03
37a10ea Some precursor changes
Dan Sugalski authored
14 Version: 1.1
a40f31b Added docs on Parrot's calling conventions.
Dan Sugalski authored
15 Status: Developing
37a10ea Some precursor changes
Dan Sugalski authored
16 Last Modified: 16 September 2002
a40f31b Added docs on Parrot's calling conventions.
Dan Sugalski authored
17 PDD Format: 1
18 Language: English
19
20 =head2 HISTORY
21
22 =over 4
23
37a10ea Some precursor changes
Dan Sugalski authored
24 =item Version 1.1
25
26 16 September 2002
27
a40f31b Added docs on Parrot's calling conventions.
Dan Sugalski authored
28 =item version 1
29
30 None. First version
31
32 =back
33
34 =head1 CHANGES
35
36 =over 4
37
37a10ea Some precursor changes
Dan Sugalski authored
38 =item Version 1.1
39
40 We now call with a frame, rather than pushing on the stack, and we
41 return frames, rather than returning a stack. We also pass in context
42 information for the return.
43
a40f31b Added docs on Parrot's calling conventions.
Dan Sugalski authored
44 =item Version 1.0
45
46 None. First version
47
48 =back
49
50 =head1 ABSTRACT
51
52 This PDD describes Parrot's inter-routine calling conventions.
53
54 =head1 DESCRIPTION
55
56 =head2 Responsibility for environment preservation
57
58 The caller is responsible for preserving any environment it is
59 interested in keeping. This includes any and all registers, lexical
60 scoping and scratchpads, opcode libraries, and so forth.
61
62 Use of the C<saveall> opcode is recommended if the caller wishes to
63 save everything, and the C<restoreall> opcode to restore everything
64 C<saveall> saved.
65
66 =head2 Calling conventions
67
68 The following registers are used in calling all subs and methods
69
70 =over 4
71
72 =item P0
73
74 Holds the object representing the subroutine.
75
76 =item P1
77
78 Holds the continuation for the caller, assuming this sub was called
79 with callcc. Otherwise NULL.
80
81 =item P2
82
83 Holds the object the sub was called on. (For method calls)
84
85 =item I0
86
87 True if the sub is being called with prototyped parameters.
88
89 =item I1
90
91 The number of items pushed onto the stack.
92
7ed080d Fixed the PMC parameter passing docs
Dan Sugalski authored
93 =item I2
94
95 The number of parameters in PMC registers.
96
37a10ea Some precursor changes
Dan Sugalski authored
97 =item I3
98
99 The return type expected. This is the identifier number for the
100 class. A return type of 0 is void context, -1 is unknown, and -2 and
101 down are the number of expected return variables, negated, minus
102 one. (So -2 means we expect 1 variable, -3 means we expect 2, -4
103 means we expect 3, and so forth)
104
a40f31b Added docs on Parrot's calling conventions.
Dan Sugalski authored
105 =back
106
7ed080d Fixed the PMC parameter passing docs
Dan Sugalski authored
107 The following registers, with the exception of P registers, are used
108 I<only> when calling a subroutine for which there is a compile-time
109 prototype. The first 27 PMC parameters may be passed in registers P5
110 through P31.
a40f31b Added docs on Parrot's calling conventions.
Dan Sugalski authored
111
112 =over 4
113
114 =item I5 through I31
115
7ed080d Fixed the PMC parameter passing docs
Dan Sugalski authored
116 The first 26 integer parameters.
a40f31b Added docs on Parrot's calling conventions.
Dan Sugalski authored
117
118 =item S5 through S31
119
120 The first 27 string parameters.
121
122 =item N5 through N31
123
124 The first 27 numeric parameters.
125
126 =item P5 through P31
127
128 The first 27 PMC parameters.
129
130 =back
131
17366d6 All parameters in registers with overflow to stack. No case where we
Dan Sugalski authored
132 All overflow parameters are pushed on the stack in reverse order--that
133 is the topmost entry on the stack is the first entry in the parameter
134 list, and the bottom entry the last entry in the parameter list.
a40f31b Added docs on Parrot's calling conventions.
Dan Sugalski authored
135
136 The PMC for a hash, array, or list is passed if one of the entries in
137 the parameter list is a hash, array, or list. The aggregate is B<not>
138 flattened. (Though when accessing the parameters it may be)
139
140 Parameters are passed in S, I, and N registers only if the sub's
141 prototype specifically indicates it takes parameters of that type.
142
143 Note that it doesn't matter what the order of the integer, string,
144 numeric, and PMC parameters are in the parameter list up until
145 overflow occurs.
146
147 =head2 Return conventions
148
149 On return from a function, the following registers are set. Return
150 values are placed in registers only if the function is prototyped to
151 do so. All values on the stack are in reverse order, such that the top
152 value on the stack is the first value returned.
153
154 =over 4
155
156 =item I0
157
158 Holds the number of return values on the stack.
159
160 =item I1
161
162 Holds the number of return values in integer registers.
163
164 =item I2
165
166 Holds the number of return values in string registers.
167
168 =item I3
169
170 Holds the number of return values in PMC registers.
171
172 =item I4
173
174 Holds the number of return valies in numeric registers.
175
176 =item P5-P31
177
178 PMC return values
179
180 =item I5-I31
181
182 Integer return values
183
184 =item S5-S31
185
186 String return values
187
188 =item N5-N31
189
190 Numeric return values
191
192 =item stack
193
194 Overflow values, or values for functions that don't have a return prototype.
195
196 =back
197
198 =head1 REFERENCES
Something went wrong with that request. Please try again.