Mercurial > lasercutter
comparison src/clojure/lang/AFn.java @ 10:ef7dbbd6452c
added clojure source goodness
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 21 Aug 2010 06:25:44 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
9:35cf337adfcf | 10:ef7dbbd6452c |
---|---|
1 /** | |
2 * Copyright (c) Rich Hickey. All rights reserved. | |
3 * The use and distribution terms for this software are covered by the | |
4 * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | |
5 * which can be found in the file epl-v10.html at the root of this distribution. | |
6 * By using this software in any fashion, you are agreeing to be bound by | |
7 * the terms of this license. | |
8 * You must not remove this notice, or any other, from this software. | |
9 **/ | |
10 | |
11 /* rich Mar 25, 2006 4:05:37 PM */ | |
12 | |
13 package clojure.lang; | |
14 | |
15 public abstract class AFn implements IFn { | |
16 | |
17 public Object call() throws Exception{ | |
18 return invoke(); | |
19 } | |
20 | |
21 public void run(){ | |
22 try | |
23 { | |
24 invoke(); | |
25 } | |
26 catch(Exception e) | |
27 { | |
28 throw new RuntimeException(e); | |
29 } | |
30 } | |
31 | |
32 | |
33 | |
34 public Object invoke() throws Exception{ | |
35 return throwArity(0); | |
36 } | |
37 | |
38 public Object invoke(Object arg1) throws Exception{ | |
39 return throwArity(1); | |
40 } | |
41 | |
42 public Object invoke(Object arg1, Object arg2) throws Exception{ | |
43 return throwArity(2); | |
44 } | |
45 | |
46 public Object invoke(Object arg1, Object arg2, Object arg3) throws Exception{ | |
47 return throwArity(3); | |
48 } | |
49 | |
50 public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4) throws Exception{ | |
51 return throwArity(4); | |
52 } | |
53 | |
54 public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) throws Exception{ | |
55 return throwArity(5); | |
56 } | |
57 | |
58 public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) throws Exception{ | |
59 return throwArity(6); | |
60 } | |
61 | |
62 public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7) | |
63 throws Exception{ | |
64 return throwArity(7); | |
65 } | |
66 | |
67 public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, | |
68 Object arg8) throws Exception{ | |
69 return throwArity(8); | |
70 } | |
71 | |
72 public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, | |
73 Object arg8, Object arg9) throws Exception{ | |
74 return throwArity(9); | |
75 } | |
76 | |
77 public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, | |
78 Object arg8, Object arg9, Object arg10) throws Exception{ | |
79 return throwArity(10); | |
80 } | |
81 | |
82 public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, | |
83 Object arg8, Object arg9, Object arg10, Object arg11) throws Exception{ | |
84 return throwArity(11); | |
85 } | |
86 | |
87 public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, | |
88 Object arg8, Object arg9, Object arg10, Object arg11, Object arg12) throws Exception{ | |
89 return throwArity(12); | |
90 } | |
91 | |
92 public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, | |
93 Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13) | |
94 throws Exception{ | |
95 return throwArity(13); | |
96 } | |
97 | |
98 public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, | |
99 Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14) | |
100 throws Exception{ | |
101 return throwArity(14); | |
102 } | |
103 | |
104 public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, | |
105 Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, | |
106 Object arg15) throws Exception{ | |
107 return throwArity(15); | |
108 } | |
109 | |
110 public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, | |
111 Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, | |
112 Object arg15, Object arg16) throws Exception{ | |
113 return throwArity(16); | |
114 } | |
115 | |
116 public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, | |
117 Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, | |
118 Object arg15, Object arg16, Object arg17) throws Exception{ | |
119 return throwArity(17); | |
120 } | |
121 | |
122 public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, | |
123 Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, | |
124 Object arg15, Object arg16, Object arg17, Object arg18) throws Exception{ | |
125 return throwArity(18); | |
126 } | |
127 | |
128 public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, | |
129 Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, | |
130 Object arg15, Object arg16, Object arg17, Object arg18, Object arg19) throws Exception{ | |
131 return throwArity(19); | |
132 } | |
133 | |
134 public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, | |
135 Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, | |
136 Object arg15, Object arg16, Object arg17, Object arg18, Object arg19, Object arg20) | |
137 throws Exception{ | |
138 return throwArity(20); | |
139 } | |
140 | |
141 | |
142 public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, | |
143 Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14, | |
144 Object arg15, Object arg16, Object arg17, Object arg18, Object arg19, Object arg20, | |
145 Object... args) | |
146 throws Exception{ | |
147 return throwArity(21); | |
148 } | |
149 | |
150 public Object applyTo(ISeq arglist) throws Exception{ | |
151 return applyToHelper(this, Util.ret1(arglist,arglist = null)); | |
152 } | |
153 | |
154 static public Object applyToHelper(IFn ifn, ISeq arglist) throws Exception{ | |
155 switch(RT.boundedLength(arglist, 20)) | |
156 { | |
157 case 0: | |
158 arglist = null; | |
159 return ifn.invoke(); | |
160 case 1: | |
161 Object a1 = arglist.first(); | |
162 arglist = null; | |
163 return ifn.invoke(a1); | |
164 case 2: | |
165 return ifn.invoke(arglist.first() | |
166 , Util.ret1((arglist = arglist.next()).first(),arglist = null) | |
167 ); | |
168 case 3: | |
169 return ifn.invoke(arglist.first() | |
170 , (arglist = arglist.next()).first() | |
171 , Util.ret1((arglist = arglist.next()).first(),arglist = null) | |
172 ); | |
173 case 4: | |
174 return ifn.invoke(arglist.first() | |
175 , (arglist = arglist.next()).first() | |
176 , (arglist = arglist.next()).first() | |
177 , Util.ret1((arglist = arglist.next()).first(),arglist = null) | |
178 ); | |
179 case 5: | |
180 return ifn.invoke(arglist.first() | |
181 , (arglist = arglist.next()).first() | |
182 , (arglist = arglist.next()).first() | |
183 , (arglist = arglist.next()).first() | |
184 , Util.ret1((arglist = arglist.next()).first(),arglist = null) | |
185 ); | |
186 case 6: | |
187 return ifn.invoke(arglist.first() | |
188 , (arglist = arglist.next()).first() | |
189 , (arglist = arglist.next()).first() | |
190 , (arglist = arglist.next()).first() | |
191 , (arglist = arglist.next()).first() | |
192 , Util.ret1((arglist = arglist.next()).first(),arglist = null) | |
193 ); | |
194 case 7: | |
195 return ifn.invoke(arglist.first() | |
196 , (arglist = arglist.next()).first() | |
197 , (arglist = arglist.next()).first() | |
198 , (arglist = arglist.next()).first() | |
199 , (arglist = arglist.next()).first() | |
200 , (arglist = arglist.next()).first() | |
201 , Util.ret1((arglist = arglist.next()).first(),arglist = null) | |
202 ); | |
203 case 8: | |
204 return ifn.invoke(arglist.first() | |
205 , (arglist = arglist.next()).first() | |
206 , (arglist = arglist.next()).first() | |
207 , (arglist = arglist.next()).first() | |
208 , (arglist = arglist.next()).first() | |
209 , (arglist = arglist.next()).first() | |
210 , (arglist = arglist.next()).first() | |
211 , Util.ret1((arglist = arglist.next()).first(),arglist = null) | |
212 ); | |
213 case 9: | |
214 return ifn.invoke(arglist.first() | |
215 , (arglist = arglist.next()).first() | |
216 , (arglist = arglist.next()).first() | |
217 , (arglist = arglist.next()).first() | |
218 , (arglist = arglist.next()).first() | |
219 , (arglist = arglist.next()).first() | |
220 , (arglist = arglist.next()).first() | |
221 , (arglist = arglist.next()).first() | |
222 , Util.ret1((arglist = arglist.next()).first(),arglist = null) | |
223 ); | |
224 case 10: | |
225 return ifn.invoke(arglist.first() | |
226 , (arglist = arglist.next()).first() | |
227 , (arglist = arglist.next()).first() | |
228 , (arglist = arglist.next()).first() | |
229 , (arglist = arglist.next()).first() | |
230 , (arglist = arglist.next()).first() | |
231 , (arglist = arglist.next()).first() | |
232 , (arglist = arglist.next()).first() | |
233 , (arglist = arglist.next()).first() | |
234 , Util.ret1((arglist = arglist.next()).first(),arglist = null) | |
235 ); | |
236 case 11: | |
237 return ifn.invoke(arglist.first() | |
238 , (arglist = arglist.next()).first() | |
239 , (arglist = arglist.next()).first() | |
240 , (arglist = arglist.next()).first() | |
241 , (arglist = arglist.next()).first() | |
242 , (arglist = arglist.next()).first() | |
243 , (arglist = arglist.next()).first() | |
244 , (arglist = arglist.next()).first() | |
245 , (arglist = arglist.next()).first() | |
246 , (arglist = arglist.next()).first() | |
247 , Util.ret1((arglist = arglist.next()).first(),arglist = null) | |
248 ); | |
249 case 12: | |
250 return ifn.invoke(arglist.first() | |
251 , (arglist = arglist.next()).first() | |
252 , (arglist = arglist.next()).first() | |
253 , (arglist = arglist.next()).first() | |
254 , (arglist = arglist.next()).first() | |
255 , (arglist = arglist.next()).first() | |
256 , (arglist = arglist.next()).first() | |
257 , (arglist = arglist.next()).first() | |
258 , (arglist = arglist.next()).first() | |
259 , (arglist = arglist.next()).first() | |
260 , (arglist = arglist.next()).first() | |
261 , Util.ret1((arglist = arglist.next()).first(),arglist = null) | |
262 ); | |
263 case 13: | |
264 return ifn.invoke(arglist.first() | |
265 , (arglist = arglist.next()).first() | |
266 , (arglist = arglist.next()).first() | |
267 , (arglist = arglist.next()).first() | |
268 , (arglist = arglist.next()).first() | |
269 , (arglist = arglist.next()).first() | |
270 , (arglist = arglist.next()).first() | |
271 , (arglist = arglist.next()).first() | |
272 , (arglist = arglist.next()).first() | |
273 , (arglist = arglist.next()).first() | |
274 , (arglist = arglist.next()).first() | |
275 , (arglist = arglist.next()).first() | |
276 , Util.ret1((arglist = arglist.next()).first(),arglist = null) | |
277 ); | |
278 case 14: | |
279 return ifn.invoke(arglist.first() | |
280 , (arglist = arglist.next()).first() | |
281 , (arglist = arglist.next()).first() | |
282 , (arglist = arglist.next()).first() | |
283 , (arglist = arglist.next()).first() | |
284 , (arglist = arglist.next()).first() | |
285 , (arglist = arglist.next()).first() | |
286 , (arglist = arglist.next()).first() | |
287 , (arglist = arglist.next()).first() | |
288 , (arglist = arglist.next()).first() | |
289 , (arglist = arglist.next()).first() | |
290 , (arglist = arglist.next()).first() | |
291 , (arglist = arglist.next()).first() | |
292 , Util.ret1((arglist = arglist.next()).first(),arglist = null) | |
293 ); | |
294 case 15: | |
295 return ifn.invoke(arglist.first() | |
296 , (arglist = arglist.next()).first() | |
297 , (arglist = arglist.next()).first() | |
298 , (arglist = arglist.next()).first() | |
299 , (arglist = arglist.next()).first() | |
300 , (arglist = arglist.next()).first() | |
301 , (arglist = arglist.next()).first() | |
302 , (arglist = arglist.next()).first() | |
303 , (arglist = arglist.next()).first() | |
304 , (arglist = arglist.next()).first() | |
305 , (arglist = arglist.next()).first() | |
306 , (arglist = arglist.next()).first() | |
307 , (arglist = arglist.next()).first() | |
308 , (arglist = arglist.next()).first() | |
309 , Util.ret1((arglist = arglist.next()).first(),arglist = null) | |
310 ); | |
311 case 16: | |
312 return ifn.invoke(arglist.first() | |
313 , (arglist = arglist.next()).first() | |
314 , (arglist = arglist.next()).first() | |
315 , (arglist = arglist.next()).first() | |
316 , (arglist = arglist.next()).first() | |
317 , (arglist = arglist.next()).first() | |
318 , (arglist = arglist.next()).first() | |
319 , (arglist = arglist.next()).first() | |
320 , (arglist = arglist.next()).first() | |
321 , (arglist = arglist.next()).first() | |
322 , (arglist = arglist.next()).first() | |
323 , (arglist = arglist.next()).first() | |
324 , (arglist = arglist.next()).first() | |
325 , (arglist = arglist.next()).first() | |
326 , (arglist = arglist.next()).first() | |
327 , Util.ret1((arglist = arglist.next()).first(),arglist = null) | |
328 ); | |
329 case 17: | |
330 return ifn.invoke(arglist.first() | |
331 , (arglist = arglist.next()).first() | |
332 , (arglist = arglist.next()).first() | |
333 , (arglist = arglist.next()).first() | |
334 , (arglist = arglist.next()).first() | |
335 , (arglist = arglist.next()).first() | |
336 , (arglist = arglist.next()).first() | |
337 , (arglist = arglist.next()).first() | |
338 , (arglist = arglist.next()).first() | |
339 , (arglist = arglist.next()).first() | |
340 , (arglist = arglist.next()).first() | |
341 , (arglist = arglist.next()).first() | |
342 , (arglist = arglist.next()).first() | |
343 , (arglist = arglist.next()).first() | |
344 , (arglist = arglist.next()).first() | |
345 , (arglist = arglist.next()).first() | |
346 , Util.ret1((arglist = arglist.next()).first(),arglist = null) | |
347 ); | |
348 case 18: | |
349 return ifn.invoke(arglist.first() | |
350 , (arglist = arglist.next()).first() | |
351 , (arglist = arglist.next()).first() | |
352 , (arglist = arglist.next()).first() | |
353 , (arglist = arglist.next()).first() | |
354 , (arglist = arglist.next()).first() | |
355 , (arglist = arglist.next()).first() | |
356 , (arglist = arglist.next()).first() | |
357 , (arglist = arglist.next()).first() | |
358 , (arglist = arglist.next()).first() | |
359 , (arglist = arglist.next()).first() | |
360 , (arglist = arglist.next()).first() | |
361 , (arglist = arglist.next()).first() | |
362 , (arglist = arglist.next()).first() | |
363 , (arglist = arglist.next()).first() | |
364 , (arglist = arglist.next()).first() | |
365 , (arglist = arglist.next()).first() | |
366 , Util.ret1((arglist = arglist.next()).first(),arglist = null) | |
367 ); | |
368 case 19: | |
369 return ifn.invoke(arglist.first() | |
370 , (arglist = arglist.next()).first() | |
371 , (arglist = arglist.next()).first() | |
372 , (arglist = arglist.next()).first() | |
373 , (arglist = arglist.next()).first() | |
374 , (arglist = arglist.next()).first() | |
375 , (arglist = arglist.next()).first() | |
376 , (arglist = arglist.next()).first() | |
377 , (arglist = arglist.next()).first() | |
378 , (arglist = arglist.next()).first() | |
379 , (arglist = arglist.next()).first() | |
380 , (arglist = arglist.next()).first() | |
381 , (arglist = arglist.next()).first() | |
382 , (arglist = arglist.next()).first() | |
383 , (arglist = arglist.next()).first() | |
384 , (arglist = arglist.next()).first() | |
385 , (arglist = arglist.next()).first() | |
386 , (arglist = arglist.next()).first() | |
387 , Util.ret1((arglist = arglist.next()).first(),arglist = null) | |
388 ); | |
389 case 20: | |
390 return ifn.invoke(arglist.first() | |
391 , (arglist = arglist.next()).first() | |
392 , (arglist = arglist.next()).first() | |
393 , (arglist = arglist.next()).first() | |
394 , (arglist = arglist.next()).first() | |
395 , (arglist = arglist.next()).first() | |
396 , (arglist = arglist.next()).first() | |
397 , (arglist = arglist.next()).first() | |
398 , (arglist = arglist.next()).first() | |
399 , (arglist = arglist.next()).first() | |
400 , (arglist = arglist.next()).first() | |
401 , (arglist = arglist.next()).first() | |
402 , (arglist = arglist.next()).first() | |
403 , (arglist = arglist.next()).first() | |
404 , (arglist = arglist.next()).first() | |
405 , (arglist = arglist.next()).first() | |
406 , (arglist = arglist.next()).first() | |
407 , (arglist = arglist.next()).first() | |
408 , (arglist = arglist.next()).first() | |
409 , Util.ret1((arglist = arglist.next()).first(),arglist = null) | |
410 ); | |
411 default: | |
412 return ifn.invoke(arglist.first() | |
413 , (arglist = arglist.next()).first() | |
414 , (arglist = arglist.next()).first() | |
415 , (arglist = arglist.next()).first() | |
416 , (arglist = arglist.next()).first() | |
417 , (arglist = arglist.next()).first() | |
418 , (arglist = arglist.next()).first() | |
419 , (arglist = arglist.next()).first() | |
420 , (arglist = arglist.next()).first() | |
421 , (arglist = arglist.next()).first() | |
422 , (arglist = arglist.next()).first() | |
423 , (arglist = arglist.next()).first() | |
424 , (arglist = arglist.next()).first() | |
425 , (arglist = arglist.next()).first() | |
426 , (arglist = arglist.next()).first() | |
427 , (arglist = arglist.next()).first() | |
428 , (arglist = arglist.next()).first() | |
429 , (arglist = arglist.next()).first() | |
430 , (arglist = arglist.next()).first() | |
431 , (arglist = arglist.next()).first() | |
432 , RT.seqToArray(Util.ret1(arglist.next(),arglist = null))); | |
433 } | |
434 } | |
435 | |
436 public Object throwArity(int n){ | |
437 String name = getClass().getSimpleName(); | |
438 int suffix = name.lastIndexOf("__"); | |
439 throw new IllegalArgumentException("Wrong number of args (" + n + ") passed to: " | |
440 + (suffix == -1 ? name : name.substring(0, suffix)).replace('_', '-')); | |
441 } | |
442 } |