Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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