1 | [[tags: egg]] |
---|
2 | [[toc:]] |
---|
3 | |
---|
4 | == scheme0-pe |
---|
5 | |
---|
6 | === Introduction |
---|
7 | |
---|
8 | The {{scheme0-pe}} egg is a variant of the {{Scheme0}} partial |
---|
9 | evaluator adapted for Chicken. {{Scheme0}} is a first-order pure |
---|
10 | subset of Scheme described in the book [[Partial Evaluation and |
---|
11 | Automatic Program Generation|http://www.itu.dk/people/sestoft/pebook/pebook.html]]. |
---|
12 | |
---|
13 | === Notation |
---|
14 | |
---|
15 | The following notation is used in this documentation: |
---|
16 | |
---|
17 | ; {{program}} : is a plain {{Scheme0}} program |
---|
18 | ; {{annprogram}} : is an annotated (two-level) {{Scheme0}} program |
---|
19 | ; {{sdpattern}} : is a tuple of argument binding times {{S}} and {{D}} |
---|
20 | ; {{division}} : is a possibly polyvariant division |
---|
21 | ; {{staticinputs}} : is a tuple of static argument values |
---|
22 | |
---|
23 | |
---|
24 | === Procedures |
---|
25 | |
---|
26 | |
---|
27 | <procedure>monodiv program sdpattern</procedure> |
---|
28 | |
---|
29 | Does a monovariant binding time analysis of the subject program |
---|
30 | program, given the binding times sdpattern of its goal |
---|
31 | function. Returns the resulting monovariant division. |
---|
32 | |
---|
33 | <procedure>polydiv program sdpattern</procedure> |
---|
34 | |
---|
35 | Similar to {{monodiv}}, but does a polyvariant binding time |
---|
36 | analysis. Returns the resulting polyvariant division. |
---|
37 | |
---|
38 | <procedure>annotate program division</procedure> |
---|
39 | |
---|
40 | Annotates the {{Scheme0}} program according to the monovariant or |
---|
41 | polyvariant division. May make several copies of each function for a |
---|
42 | polyvariant division. Returns the annotated two-level {{Scheme0}} |
---|
43 | program or reports that division is not congruent. |
---|
44 | |
---|
45 | <procedure>monotate program sdpattern</procedure> |
---|
46 | |
---|
47 | Does monovariant binding time analysis and an- notation of program |
---|
48 | given the binding times sdpattern of its goal function. Returns the |
---|
49 | annotated two-level {{Scheme0}} program. |
---|
50 | |
---|
51 | <procedure>polytate program sdpattern</procedure> |
---|
52 | |
---|
53 | Similar to {{monotate}} but performs polyvariant binding time analysis and |
---|
54 | annotation. Returns the annotated two-level {{Scheme0}} program. |
---|
55 | |
---|
56 | <procedure>spec annprogram staticinputs</procedure> |
---|
57 | |
---|
58 | Specializes the annotated annprogram with respect to the list |
---|
59 | {{staticinputs}} of static argument values. Returns the residual {{Scheme0}} |
---|
60 | program. |
---|
61 | |
---|
62 | <procedure>monope program sdpattern staticinputs</procedure> |
---|
63 | |
---|
64 | Does a monovariant binding time analysis and annotation of program, |
---|
65 | then specializes it with respect to the given static inputs |
---|
66 | {{staticinputs}}. Returns the residual {{Scheme0}} program. |
---|
67 | |
---|
68 | <procedure>polype program sdpattern staticinputs</procedure> |
---|
69 | |
---|
70 | Similar to {{monope}} but does polyvariant binding time analysis and |
---|
71 | annotation. Returns the residual {{Scheme0}} program. |
---|
72 | |
---|
73 | <procedure>make f program</procedure> |
---|
74 | |
---|
75 | Converts program from {{Scheme0}} to Scheme and defines a Scheme |
---|
76 | function f to invoke the converted program. Returns the name f. Side |
---|
77 | effect: Defines function f. This is for executing residual {{Scheme0}} |
---|
78 | programs. |
---|
79 | |
---|
80 | <procedure>scheme program</procedure> |
---|
81 | |
---|
82 | Converts program from {{Scheme0}} to Scheme, possibly renaming |
---|
83 | functions. Returns a list of Scheme function definitions. This is for |
---|
84 | studying residual Scheme0 programs. |
---|
85 | |
---|
86 | |
---|
87 | === Representation of Scheme0 programs |
---|
88 | |
---|
89 | A program must have at least one definition, and function definitions |
---|
90 | may have zero or more arguments. |
---|
91 | |
---|
92 | program ::= (def ... def) |
---|
93 | |
---|
94 | def ::= (define (funcname var ... var) exp) |
---|
95 | |
---|
96 | exp ::= () |
---|
97 | | number |
---|
98 | | var |
---|
99 | | (quote S-expression) |
---|
100 | | (if exp exp exp) |
---|
101 | | (call funcname exp ... exp) |
---|
102 | | (op basefunction exp ... exp) |
---|
103 | |
---|
104 | Variables are Scheme symbols, that is, non-numeric atoms different |
---|
105 | from (). Function names may also be simple Scheme symbols, but in |
---|
106 | residual programs, a function name is a pair {{(annotatedname |
---|
107 | . staticvalues)}} of an annotated function name and the values of the |
---|
108 | function's static arguments for this variant. Annotated function names |
---|
109 | are those found in the annotated subject programs given to the |
---|
110 | specializer. |
---|
111 | |
---|
112 | === Representation of two-level Scheme0 programs |
---|
113 | |
---|
114 | |
---|
115 | program ::= (def ... def) |
---|
116 | |
---|
117 | def ::= (define (funcname (var ... var) (var ... var)) exp) |
---|
118 | |
---|
119 | exp ::= () |
---|
120 | | number |
---|
121 | | var |
---|
122 | | (quote S-expression) |
---|
123 | | (ifs exp exp exp) |
---|
124 | | (ifd exp exp exp) |
---|
125 | | (calls funcname (exp ... exp) (exp ... exp)) |
---|
126 | | (calld funcname (exp ... exp) (exp ... exp)) |
---|
127 | | (ops basefunction exp ... exp) |
---|
128 | | (opd basefunction exp ... exp) |
---|
129 | | (lift exp) |
---|
130 | |
---|
131 | A variable is a Scheme symbol as above, but a function name must have |
---|
132 | the form: {{((f . dynvaroccs) . sdpattern)}}. |
---|
133 | |
---|
134 | Here {{f}} is a function name from the {{Scheme0}} subject program; |
---|
135 | {{dynvaroccs}} is a list of the number of occurrences of {{f}}'s |
---|
136 | dynamic parameters; and {{sdpattern}} describes the binding times of |
---|
137 | the parameters of this variant of {{f}}. Thus {{f}} is a Scheme |
---|
138 | symbol; {{dynvaroccs}} is a list of 0, 1, or 2, where 2 represents any |
---|
139 | number greater than 1; and {{sdpattern}} is a list of {{S}} and {{D}}. |
---|
140 | |
---|
141 | The {{sdpattern}} component is used to distinguish the binding time |
---|
142 | variants of {{f}} and is present also in monovariantly annotated |
---|
143 | programs. The {{dynvaroccs}} component is used to avoid unfolding |
---|
144 | static calls to {{f}} when this may cause duplication of a non-trivial |
---|
145 | non-variable dynamic argument expression. This component could in |
---|
146 | principle be computed during specialization, in which case it need not |
---|
147 | be part of the function name, but this would incur unnecessary |
---|
148 | recomputation, so we choose to compute it when annotating the program. |
---|
149 | |
---|
150 | === Examples |
---|
151 | |
---|
152 | (use scheme0-pe) |
---|
153 | |
---|
154 | (define ack '( |
---|
155 | (define (ack m n) |
---|
156 | (if (op equal? m 0) (op + n 1) |
---|
157 | (if (op equal? n 0) |
---|
158 | (call ack (op - m 1) 1) |
---|
159 | (call ack (op - m 1) (call ack m (op - n 1))))) |
---|
160 | ))) |
---|
161 | |
---|
162 | (pp (scheme ack)) |
---|
163 | (pp (scheme (monope ack '(S D) '(4)))) |
---|
164 | |
---|
165 | |
---|
166 | === Authors |
---|
167 | |
---|
168 | The Scheme0 partial evaluator is described in Chapter 5 and Appendix A |
---|
169 | of the book: |
---|
170 | |
---|
171 | N.D. Jones, C.K. Gomard, and P. Sestoft, |
---|
172 | Partial Evaluation and Automatic Program Generation. |
---|
173 | Prentice Hall International, June 1993. xii + 415 pages. ISBN 0-13-020249-5. |
---|
174 | |
---|
175 | Available from http://www.itu.dk/people/sestoft/pebook/pebook.html |
---|
176 | |
---|
177 | === Version |
---|
178 | |
---|
179 | ; 1.0 : Initial version |
---|
180 | |
---|
181 | === License |
---|
182 | |
---|
183 | This program is free software; you can redistribute it and/or |
---|
184 | modify it under the terms of the GNU General Public License |
---|
185 | as published by the Free Software Foundation; either version 2 |
---|
186 | of the License, or (at your option) any later version. |
---|
187 | |
---|
188 | This program is distributed in the hope that it will be useful, |
---|
189 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
190 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
191 | GNU General Public License for more details. |
---|
192 | |
---|
193 | You should have received a copy of the GNU General Public License |
---|
194 | along with this program; if not, write to the Free Software |
---|
195 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|