1
/* Copyright William Schelter. All rights reserved.
2
Fast linking method for kcl by W. Schelter University of Texas
3
Note there are also changes to
4
cmpcall.lsp and cmptop.lsp */
10
#include "sfun_argd.h"
14
#define DO_FUNLINK_DEBUG
17
#ifdef DO_FUNLINK_DEBUG
18
void print_lisp_string ( char *boilerplate, object s )
20
if ( s && s->st.s_fillp && s->st.st_self ) {
21
int last = s->st.s_fillp;
23
fprintf ( stderr, "%s", boilerplate );
24
for (i = 0; (i < last) && (i < 30); i++) {
25
fputc ( s->st.st_self[i], stderr );
27
fputc ( '\n', stderr );
29
fprintf ( stderr, "Object %x not a string or empty\n", s );
35
clean_link_array(object *,object *);
38
typedef object (*object_func)();
41
vpush_extend(void *,object);
43
object sLAlink_arrayA;
48
call_or_link(object sym, void **link )
52
#ifdef DO_FUNLINK_DEBUG
53
fprintf ( stderr, "call_or_link: fun %x START for function ", fun );
54
print_lisp_string ( "name: ", fun->cf.cf_name );
57
FEinvalid_function(sym);
58
#ifdef DO_FUNLINK_DEBUG
59
fprintf ( stderr, "call_or_link: fun %x Invalid function EXIT\n", fun );
63
if ( type_of ( fun ) == t_cclosure && (fun->cc.cc_turbo) ) {
65
MMccall ( fun, fun->cc.cc_turbo );
67
(*(fun)->cf.cf_self)(fun->cc.cc_turbo);
69
#ifdef DO_FUNLINK_DEBUG
70
fprintf ( stderr, "call_or_link: fun %x EXIT POINT 1 closure and turbo branch\n", fun );
77
if ( type_of(fun) == t_cfun ) {
78
(void) vpush_extend ( link,sLAlink_arrayA->s.s_dbind );
79
(void) vpush_extend ( *link,sLAlink_arrayA->s.s_dbind );
80
*link = (void *) (fun->cf.cf_self);
81
#ifdef DO_FUNLINK_DEBUG
82
fprintf ( stderr, "call_or_link: fun %x, fun->cf %x (cf_name %x, cf_data %x, cf_self %x), ",
83
fun, fun->cf, fun->cf.cf_name, fun->cf.cf_data, fun->cf.cf_self );
85
print_lisp_string ( "name: ", fun->cf.cf_name );
88
( *(void (*)()) (fun->cf.cf_self)) ();
93
#ifdef DO_FUNLINK_DEBUG
94
fprintf ( stderr, "call_or_link: fun %x EXIT POINT 2\n", fun );
99
call_or_link_closure ( object sym, void **link, void **ptr )
102
fun = sym->s.s_gfdef;
103
#ifdef DO_FUNLINK_DEBUG
104
fprintf ( stderr, "call_or_link_closure: START sym %x, link %x, *link %x, ptr %x, *ptr %x, sym->s.s_gfdef (fun) %x ",
105
sym, link, *link, ptr, *ptr, fun );
106
print_lisp_string ( "Function name: ", fun->cf.cf_name );
108
if (fun == OBJNULL) {
109
#ifdef DO_FUNLINK_DEBUG
110
fprintf ( stderr, "call_or_link_closure: fun %x ERROR END\n", fun );
112
FEinvalid_function(sym);
115
if ( type_of ( fun ) == t_cclosure && ( fun->cc.cc_turbo ) ) {
117
(void) vpush_extend ( link, sLAlink_arrayA->s.s_dbind );
118
(void) vpush_extend ( *link, sLAlink_arrayA->s.s_dbind );
119
#ifdef DO_FUNLINK_DEBUG
120
fprintf ( stderr, "call_or_link_closure: About to change %x to %x at ptr %x, %x to %x at %x, then MMccall fun (after t_cclosure vpush_extend)", *ptr, fun->cc.cc_turbo, ptr, *link, fun->cf.cf_self, link );
121
print_lisp_string ( ": ", fun->cf.cf_name );
123
*ptr = (void *) ( fun->cc.cc_turbo );
124
*link = (void *) ( fun->cf.cf_self );
125
MMccall (fun, fun->cc.cc_turbo);
127
MMccall ( fun, fun->cc.cc_turbo );
129
#ifdef DO_FUNLINK_DEBUG
130
fprintf ( stderr, "call_or_link_closure: fun %x END 1\n", fun );
137
/* can't do this if invoking foo(a) is illegal when foo is not defined
138
to take any arguments. In the majority of C's this is legal */
140
if ( type_of ( fun ) == t_cfun ) {
141
(void) vpush_extend ( link, sLAlink_arrayA->s.s_dbind );
142
(void) vpush_extend ( *link, sLAlink_arrayA->s.s_dbind );
143
#ifdef DO_FUNLINK_DEBUG
144
fprintf ( stderr, "call_or_link_closure: About to change *link %x to %x at link %x and execute it (after t_cfun vpush_extend), sym->s %x, sym->s.s_self %s (%d chars long)\n", *link, fun->cf.cf_self, link, sym->s, sym->s.s_self, sym->s.s_fillp );
146
*link = (void *) (fun->cf.cf_self);
147
( *(void (*)()) (fun->cf.cf_self) ) ();
152
#ifdef DO_FUNLINK_DEBUG
153
fprintf ( stderr, "call_or_link_closure: fun %x END 2\n", fun );
157
/* for pushing item into an array, where item is an address if array-type = t
158
or a fixnum if array-type = fixnum */
160
#define SET_ITEM(ar,ind,val) (*((object *)(&((ar)->ust.ust_self[ind]))))= val
162
vpush_extend(void *item, object ar)
164
#ifdef DO_FUNLINK_DEBUG
165
fprintf ( stderr, "vpush_extend: item %x, ar %x\n", item, ar );
167
ind = ar->ust.ust_fillp;
169
if (ind < ar->ust.ust_dim)
170
{SET_ITEM(ar,ind,item);
171
ind += sizeof(void *);
172
return(ar->v.v_fillp = ind);}
175
int newdim= ROUND_UP_PTR((2 + (int) (1.3 * ind)));
176
unsigned char *newself;
177
newself = (void *)alloc_relblock(newdim);
178
bcopy(ar->ust.ust_self,newself,ind);
179
ar->ust.ust_dim=newdim;
180
ar->ust.ust_self=newself;
183
#ifdef DO_FUNLINK_DEBUG_1
184
fprintf ( stderr, "vpush_extend: item %x, ar %x END\n", item, ar );
189
/* if we unlink a bunch of functions, this will mean there are some
190
holes in the link array, and we should probably go through it and
192
static int number_unlinked=0;
195
delete_link(void *address, object link_ar)
196
{object *ar,*ar_end,*p;
197
#ifdef DO_FUNLINK_DEBUG
198
fprintf ( stderr, "delete_link: address %x, link_ar %x START\n", address, link_ar );
201
ar = link_ar->v.v_self;
202
ar_end = (object *)&(link_ar->ust.ust_self[link_ar->v.v_fillp]);
204
{ if (*ar && *((void **)*ar)==address)
205
{ p = (object *) *ar;
210
if (number_unlinked > 40)
212
clean_link_array(link_ar->v.v_self,ar_end);
213
#ifdef DO_FUNLINK_DEBUG
214
fprintf ( stderr, "delete_link: address %x, link_ar %x END\n", address, link_ar );
219
DEFUN_NEW("USE-FAST-LINKS",object,fSuse_fast_links,SI,1,2,NONE,OO,OO,OO,OO,(object flag,...),
220
"Usage: (use-fast-links {nil,t} &optional fun) turns on or off \
221
the fast linking depending on FLAG, so that things will either go \
222
faster, or turns it off so that stack information is kept. If SYMBOL \
223
is supplied and FLAG is nil, then this function is deleted from the fast links")
227
object *p,*ar,*ar_end;
232
if (n>=2) sym=va_arg(ap,object);else goto LDEFAULT2;
234
LDEFAULT2: sym = Cnil ;
235
LEND_VARARG: va_end(ap);}
237
if (sLAlink_arrayA ==0) RETURN1(Cnil);
238
link_ar = sLAlink_arrayA->s.s_dbind;
239
if (link_ar==Cnil && flag==Cnil) RETURN1(Cnil);
240
check_type_array(&link_ar);
241
if (type_of(link_ar) != t_string)
242
{ FEerror("*LINK-ARRAY* must be a string",0);}
243
ar = link_ar->v.v_self;
244
ar_end = (object *)&(link_ar->ust.ust_self[link_ar->v.v_fillp]);
251
/* set the link variables back to initial state */
254
if (p) *p = (ar++, *ar); else ar++;
257
link_ar->v.v_fillp = 0;
264
if ((type_of(sym)==t_symbol))
265
fun = sym->s.s_gfdef;
267
if (type_of(sym)==t_cclosure)
269
else {FEerror("Second arg: ~a must be symbol or closure",0,sym);
273
if(!fun) RETURN1(Cnil);
274
switch(type_of(fun)){
282
delete_link(fun->cf.cf_self,link_ar);
284
y=getf(sym->s.s_plist,sScdefn,Cnil);
286
delete_link(fix(y),link_ar);
291
/* no link for uncompiled functions*/
297
FEerror("Usage: (use-fast-links {nil,t} &optional fun)",0);
302
fSuse_fast_links_2(object flag,object res) {
304
return FFN(fSuse_fast_links)(flag,res);
308
clear_compiler_properties(object sym, object code)
310
extern object sSclear_compiler_properties;
311
VFUN_NARGS=2; FFN(fSuse_fast_links)(Cnil,sym);
312
tem = getf(sym->s.s_plist,sStraced,Cnil);
313
if (sSAinhibit_macro_specialA && sSAinhibit_macro_specialA->s.s_dbind != Cnil)
314
(void)ifuncall2(sSclear_compiler_properties, sym,code);
315
if (tem != Cnil) return tem;
322
clean_link_array(object *ar, object *ar_end)
325
#ifdef DO_FUNLINK_DEBUG
326
fprintf ( stderr, "clean_link_array: ar %x, ar_end %x START\n", ar, ar_end );
337
#ifdef DO_FUNLINK_DEBUG
338
fprintf ( stderr, "clean_link_array: ar %x, ar_end %x END\n", ar, ar_end );
340
return(i*sizeof(object *));
343
/* This is a temporary workaround. m68k cannot find the result
344
of a function returning long when invoked via a function pointer
345
declared as a function returning a pointer, in this case, an
346
object. A proper fix will require rewriting sections of the lisp
347
compiler to separate the calling procedures for functions returning
348
an object from functions returning a long. CM 20020801 */
349
/* #if defined(__mc68020__) */
350
/* #define LCAST(a) (object)(*(long(*)())a) */
352
#define LCAST(a) (*a)
356
c_apply_n(object (*fn)(), int n, object *x)
358
#ifdef DO_FUNLINK_DEBUG_1
359
fprintf ( stderr, "c_apply_n: n %d, x %x START\n", n, x );
362
case 0: res=LCAST(fn)();break;
363
case 1: res=LCAST(fn)(x[0]);break;
364
case 2: res=LCAST(fn)(x[0],x[1]);break;
365
case 3: res=LCAST(fn)(x[0],x[1],x[2]);break;
366
case 4: res=LCAST(fn)(x[0],x[1],x[2],x[3]);break;
367
case 5: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4]);break;
368
case 6: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5]);break;
369
case 7: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6]);break;
370
case 8: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7]);break;
371
case 9: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
373
case 10: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
375
case 11: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
376
x[8],x[9],x[10]);break;
377
case 12: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
378
x[8],x[9],x[10],x[11]);break;
379
case 13: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
380
x[8],x[9],x[10],x[11],x[12]);break;
381
case 14: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
382
x[8],x[9],x[10],x[11],x[12],x[13]);break;
383
case 15: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
384
x[8],x[9],x[10],x[11],x[12],x[13],x[14]);break;
385
case 16: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
386
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
388
case 17: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
389
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
391
case 18: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
392
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
393
x[15],x[16],x[17]);break;
394
case 19: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
395
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
396
x[15],x[16],x[17],x[18]);break;
397
case 20: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
398
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
399
x[15],x[16],x[17],x[18],x[19]);break;
400
case 21: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
401
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
402
x[15],x[16],x[17],x[18],x[19],x[20]);break;
403
case 22: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
404
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
405
x[15],x[16],x[17],x[18],x[19],x[20],x[21]);break;
406
case 23: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
407
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
408
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
410
case 24: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
411
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
412
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
414
case 25: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
415
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
416
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
417
x[22],x[23],x[24]);break;
418
case 26: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
419
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
420
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
421
x[22],x[23],x[24],x[25]);break;
422
case 27: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
423
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
424
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
425
x[22],x[23],x[24],x[25],x[26]);break;
426
case 28: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
427
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
428
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
429
x[22],x[23],x[24],x[25],x[26],x[27]);break;
430
case 29: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
431
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
432
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
433
x[22],x[23],x[24],x[25],x[26],x[27],x[28]);break;
434
case 30: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
435
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
436
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
437
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
439
case 31: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
440
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
441
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
442
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
444
case 32: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
445
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
446
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
447
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
448
x[29],x[30],x[31]);break;
449
case 33: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
450
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
451
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
452
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
453
x[29],x[30],x[31],x[32]);break;
454
case 34: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
455
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
456
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
457
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
458
x[29],x[30],x[31],x[32],x[33]);break;
459
case 35: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
460
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
461
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
462
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
463
x[29],x[30],x[31],x[32],x[33],x[34]);break;
464
case 36: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
465
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
466
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
467
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
468
x[29],x[30],x[31],x[32],x[33],x[34],x[35]);break;
469
case 37: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
470
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
471
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
472
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
473
x[29],x[30],x[31],x[32],x[33],x[34],x[35],
475
case 38: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
476
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
477
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
478
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
479
x[29],x[30],x[31],x[32],x[33],x[34],x[35],
481
case 39: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
482
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
483
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
484
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
485
x[29],x[30],x[31],x[32],x[33],x[34],x[35],
486
x[36],x[37],x[38]);break;
487
case 40: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
488
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
489
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
490
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
491
x[29],x[30],x[31],x[32],x[33],x[34],x[35],
492
x[36],x[37],x[38],x[39]);break;
493
case 41: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
494
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
495
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
496
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
497
x[29],x[30],x[31],x[32],x[33],x[34],x[35],
498
x[36],x[37],x[38],x[39],x[40]);break;
499
case 42: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
500
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
501
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
502
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
503
x[29],x[30],x[31],x[32],x[33],x[34],x[35],
504
x[36],x[37],x[38],x[39],x[40],x[41]);break;
505
case 43: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
506
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
507
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
508
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
509
x[29],x[30],x[31],x[32],x[33],x[34],x[35],
510
x[36],x[37],x[38],x[39],x[40],x[41],x[42]);break;
511
case 44: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
512
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
513
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
514
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
515
x[29],x[30],x[31],x[32],x[33],x[34],x[35],
516
x[36],x[37],x[38],x[39],x[40],x[41],x[42],
518
case 45: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
519
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
520
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
521
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
522
x[29],x[30],x[31],x[32],x[33],x[34],x[35],
523
x[36],x[37],x[38],x[39],x[40],x[41],x[42],
525
case 46: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
526
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
527
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
528
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
529
x[29],x[30],x[31],x[32],x[33],x[34],x[35],
530
x[36],x[37],x[38],x[39],x[40],x[41],x[42],
531
x[43],x[44],x[45]);break;
532
case 47: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
533
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
534
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
535
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
536
x[29],x[30],x[31],x[32],x[33],x[34],x[35],
537
x[36],x[37],x[38],x[39],x[40],x[41],x[42],
538
x[43],x[44],x[45],x[46]);break;
539
case 48: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
540
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
541
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
542
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
543
x[29],x[30],x[31],x[32],x[33],x[34],x[35],
544
x[36],x[37],x[38],x[39],x[40],x[41],x[42],
545
x[43],x[44],x[45],x[46],x[47]);break;
546
case 49: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
547
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
548
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
549
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
550
x[29],x[30],x[31],x[32],x[33],x[34],x[35],
551
x[36],x[37],x[38],x[39],x[40],x[41],x[42],
552
x[43],x[44],x[45],x[46],x[47],x[48]);break;
553
case 50: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
554
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
555
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
556
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
557
x[29],x[30],x[31],x[32],x[33],x[34],x[35],
558
x[36],x[37],x[38],x[39],x[40],x[41],x[42],
559
x[43],x[44],x[45],x[46],x[47],x[48],x[49]);break;
560
case 51: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
561
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
562
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
563
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
564
x[29],x[30],x[31],x[32],x[33],x[34],x[35],
565
x[36],x[37],x[38],x[39],x[40],x[41],x[42],
566
x[43],x[44],x[45],x[46],x[47],x[48],x[49],
568
case 52: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
569
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
570
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
571
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
572
x[29],x[30],x[31],x[32],x[33],x[34],x[35],
573
x[36],x[37],x[38],x[39],x[40],x[41],x[42],
574
x[43],x[44],x[45],x[46],x[47],x[48],x[49],
576
case 53: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
577
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
578
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
579
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
580
x[29],x[30],x[31],x[32],x[33],x[34],x[35],
581
x[36],x[37],x[38],x[39],x[40],x[41],x[42],
582
x[43],x[44],x[45],x[46],x[47],x[48],x[49],
583
x[50],x[51],x[52]);break;
584
case 54: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
585
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
586
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
587
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
588
x[29],x[30],x[31],x[32],x[33],x[34],x[35],
589
x[36],x[37],x[38],x[39],x[40],x[41],x[42],
590
x[43],x[44],x[45],x[46],x[47],x[48],x[49],
591
x[50],x[51],x[52],x[53]);break;
592
case 55: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
593
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
594
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
595
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
596
x[29],x[30],x[31],x[32],x[33],x[34],x[35],
597
x[36],x[37],x[38],x[39],x[40],x[41],x[42],
598
x[43],x[44],x[45],x[46],x[47],x[48],x[49],
599
x[50],x[51],x[52],x[53],x[54]);break;
600
case 56: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
601
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
602
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
603
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
604
x[29],x[30],x[31],x[32],x[33],x[34],x[35],
605
x[36],x[37],x[38],x[39],x[40],x[41],x[42],
606
x[43],x[44],x[45],x[46],x[47],x[48],x[49],
607
x[50],x[51],x[52],x[53],x[54],x[55]);break;
608
case 57: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
609
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
610
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
611
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
612
x[29],x[30],x[31],x[32],x[33],x[34],x[35],
613
x[36],x[37],x[38],x[39],x[40],x[41],x[42],
614
x[43],x[44],x[45],x[46],x[47],x[48],x[49],
615
x[50],x[51],x[52],x[53],x[54],x[55],x[56]);break;
616
case 58: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
617
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
618
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
619
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
620
x[29],x[30],x[31],x[32],x[33],x[34],x[35],
621
x[36],x[37],x[38],x[39],x[40],x[41],x[42],
622
x[43],x[44],x[45],x[46],x[47],x[48],x[49],
623
x[50],x[51],x[52],x[53],x[54],x[55],x[56],
625
case 59: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
626
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
627
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
628
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
629
x[29],x[30],x[31],x[32],x[33],x[34],x[35],
630
x[36],x[37],x[38],x[39],x[40],x[41],x[42],
631
x[43],x[44],x[45],x[46],x[47],x[48],x[49],
632
x[50],x[51],x[52],x[53],x[54],x[55],x[56],
634
case 60: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
635
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
636
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
637
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
638
x[29],x[30],x[31],x[32],x[33],x[34],x[35],
639
x[36],x[37],x[38],x[39],x[40],x[41],x[42],
640
x[43],x[44],x[45],x[46],x[47],x[48],x[49],
641
x[50],x[51],x[52],x[53],x[54],x[55],x[56],
642
x[57],x[58],x[59]);break;
643
case 61: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
644
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
645
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
646
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
647
x[29],x[30],x[31],x[32],x[33],x[34],x[35],
648
x[36],x[37],x[38],x[39],x[40],x[41],x[42],
649
x[43],x[44],x[45],x[46],x[47],x[48],x[49],
650
x[50],x[51],x[52],x[53],x[54],x[55],x[56],
651
x[57],x[58],x[59],x[60]);break;
652
case 62: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
653
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
654
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
655
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
656
x[29],x[30],x[31],x[32],x[33],x[34],x[35],
657
x[36],x[37],x[38],x[39],x[40],x[41],x[42],
658
x[43],x[44],x[45],x[46],x[47],x[48],x[49],
659
x[50],x[51],x[52],x[53],x[54],x[55],x[56],
660
x[57],x[58],x[59],x[60],x[61]);break;
661
case 63: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
662
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
663
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
664
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
665
x[29],x[30],x[31],x[32],x[33],x[34],x[35],
666
x[36],x[37],x[38],x[39],x[40],x[41],x[42],
667
x[43],x[44],x[45],x[46],x[47],x[48],x[49],
668
x[50],x[51],x[52],x[53],x[54],x[55],x[56],
669
x[57],x[58],x[59],x[60],x[61],x[62]);break;
670
case 64: res=LCAST(fn)(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],
671
x[8],x[9],x[10],x[11],x[12],x[13],x[14],
672
x[15],x[16],x[17],x[18],x[19],x[20],x[21],
673
x[22],x[23],x[24],x[25],x[26],x[27],x[28],
674
x[29],x[30],x[31],x[32],x[33],x[34],x[35],
675
x[36],x[37],x[38],x[39],x[40],x[41],x[42],
676
x[43],x[44],x[45],x[46],x[47],x[48],x[49],
677
x[50],x[51],x[52],x[53],x[54],x[55],x[56],
678
x[57],x[58],x[59],x[60],x[61],x[62],x[63]);break;
679
default: FEerror("Exceeded call-arguments-limit ",0);
682
#ifdef DO_FUNLINK_DEBUG_1
683
fprintf ( stderr, "c_apply_n: res %x END\n", n, res );
688
/* Used for calling cfunctions which take object args, and return object
689
value. This function is called by the static lnk function in the reference
693
call_proc(object sym, void **link, int argd, va_list ll)
696
#ifdef DO_FUNLINK_DEBUG_1
697
fprintf ( stderr, "call_proc: sym %x START\n", sym );
699
check_type_symbol(&sym);
701
if (fun && (type_of(fun)==t_sfun
702
|| type_of(fun)==t_gfun
703
|| type_of(fun)== t_vfun)
704
&& Rset) /* the && Rset is to allow tracing */
706
fn = fun->sfn.sfn_self;
707
if (type_of(fun)==t_vfun)
708
{ /* argd=VFUN_NARGS; */ /*remove this! */
709
nargs=SFUN_NARGS(argd);
710
if (nargs < fun->vfn.vfn_minargs || nargs > fun->vfn.vfn_maxargs
711
|| (argd & (SFUN_ARG_TYPE_MASK | SFUN_RETURN_MASK)))
713
if ((VFUN_NARG_BIT & argd) == 0)
720
else /* t_gfun,t_sfun */
721
{ nargs= SFUN_NARGS(argd);
722
if ((argd & (~VFUN_NARG_BIT)) != fun->sfn.sfn_argd)
724
FEerror("Arg or result mismatch in call to ~s",1,sym);
727
(void) vpush_extend(link,sLAlink_arrayA->s.s_dbind);
728
(void) vpush_extend(*link,sLAlink_arrayA->s.s_dbind);
733
/* code below presumes sizeof(int) == sizeof(object)
734
Should probably not bother special casing the < 10 args
736
{object x0,x1,x2,x3,x4,x5,x6,x7,x8,x9;
738
x0=va_arg(ll,object);
740
{return(LCAST(fn)());}
742
x1=va_arg(ll,object);
744
{ return(LCAST(fn)(x0));}
746
x2=va_arg(ll,object);
748
{return(LCAST(fn)(x0,x1));}
749
if (nargs-- > 0) x3=va_arg(ll,object);
751
return(LCAST(fn)(x0,x1,x2));
752
if (nargs-- > 0) x4=va_arg(ll,object);
754
return(LCAST(fn)(x0,x1,x2,x3));
755
if (nargs-- > 0) x5=va_arg(ll,object);
757
return(LCAST(fn)(x0,x1,x2,x3,x4));
758
if (nargs-- > 0) x6=va_arg(ll,object);
760
return(LCAST(fn)(x0,x1,x2,x3,x4,x5));
761
if (nargs-- > 0) x7=va_arg(ll,object);
763
return(LCAST(fn)(x0,x1,x2,x3,x4,x5,x6));
764
if (nargs-- > 0) x8=va_arg(ll,object);
766
return(LCAST(fn)(x0,x1,x2,x3,x4,x5,x6,x7));
767
if (nargs-- > 0) x9=va_arg(ll,object);
769
return(LCAST(fn)(x0,x1,x2,x3,x4,x5,x6,x7,x8));
770
return(LCAST(fn)(x0,x1,x2,x3,x4,x5,x6,x7,x8,x9));
774
COERCE_VA_LIST(new,ll,nargs);
775
return(c_apply_n(fn,nargs,new));}
777
else /* there is no cdefn property */
781
register object *base;
782
enum ftype result_type;
783
/* we check they are valid functions before calling this */
784
if(type_of(sym)==t_symbol) fun = symbol_function(sym);
786
vs_base= (base = vs_top);
787
if (fun == OBJNULL) FEinvalid_function(sym);
789
/* if (type_of(fun)==t_vfun) argd=fcall.argd; */ /*remove this! */
790
nargs=SFUN_NARGS(argd);
791
result_type=SFUN_RETURN_TYPE(argd);
792
SFUN_START_ARG_TYPES(argd);
796
{vs_push(va_arg(ll,object));
800
{enum ftype typ=SFUN_NEXT_TYPE(argd);
801
vs_push((typ==f_object? va_arg(ll,object):
802
make_fixnum(va_arg(ll,fixnum))));
811
The caller won't expect us to restore these. */
812
return((result_type==f_object? vs_base[0] : (object)fix(vs_base[0])));
817
/* static object call_vproc(object sym, void *link, va_list ll) */
818
/* {return call_proc(sym,link,VFUN_NARGS | VFUN_NARG_BIT,ll);} */
820
/* For ANSI C stdarg */
823
call_proc_new(object sym, void **link, int argd, object first, va_list ll)
826
#ifdef DO_FUNLINK_DEBUG_1
827
fprintf ( stderr, "call_proc_new: sym %x START\n", sym );
829
check_type_symbol(&sym);
831
if (fun && (type_of(fun)==t_sfun
832
|| type_of(fun)==t_gfun
833
|| type_of(fun)== t_vfun)
834
&& Rset) /* the && Rset is to allow tracing */
836
fn = fun->sfn.sfn_self;
837
if (type_of(fun)==t_vfun)
838
{ /* argd=VFUN_NARGS; */ /*remove this! */
839
nargs=SFUN_NARGS(argd);
840
if (nargs < fun->vfn.vfn_minargs || nargs > fun->vfn.vfn_maxargs
841
|| (argd & (SFUN_ARG_TYPE_MASK | SFUN_RETURN_MASK)))
843
if ((VFUN_NARG_BIT & argd) == 0)
850
else /* t_gfun,t_sfun */
851
{ nargs= SFUN_NARGS(argd);
852
if ((argd & (~VFUN_NARG_BIT)) != fun->sfn.sfn_argd)
854
FEerror("Arg or result mismatch in call to ~s",1,sym);
857
(void) vpush_extend(link,sLAlink_arrayA->s.s_dbind);
858
(void) vpush_extend(*link,sLAlink_arrayA->s.s_dbind);
863
/* code below presumes sizeof(int) == sizeof(object)
864
Should probably not bother special casing the < 10 args
866
{object x0,x1,x2,x3,x4,x5,x6,x7,x8,x9;
868
/* x0=va_arg(ll,object); */
871
{return(LCAST(fn)());}
873
x1=va_arg(ll,object);
875
{ return(LCAST(fn)(x0));}
877
x2=va_arg(ll,object);
879
{return(LCAST(fn)(x0,x1));}
880
if (nargs-- > 0) x3=va_arg(ll,object);
882
return(LCAST(fn)(x0,x1,x2));
883
if (nargs-- > 0) x4=va_arg(ll,object);
885
return(LCAST(fn)(x0,x1,x2,x3));
886
if (nargs-- > 0) x5=va_arg(ll,object);
888
return(LCAST(fn)(x0,x1,x2,x3,x4));
889
if (nargs-- > 0) x6=va_arg(ll,object);
891
return(LCAST(fn)(x0,x1,x2,x3,x4,x5));
892
if (nargs-- > 0) x7=va_arg(ll,object);
894
return(LCAST(fn)(x0,x1,x2,x3,x4,x5,x6));
895
if (nargs-- > 0) x8=va_arg(ll,object);
897
return(LCAST(fn)(x0,x1,x2,x3,x4,x5,x6,x7));
898
if (nargs-- > 0) x9=va_arg(ll,object);
900
return(LCAST(fn)(x0,x1,x2,x3,x4,x5,x6,x7,x8));
901
return(LCAST(fn)(x0,x1,x2,x3,x4,x5,x6,x7,x8,x9));
906
COERCE_VA_LIST_NEW(new,first,ll,nargs);
907
return(c_apply_n(fn,nargs,new));}
909
else /* there is no cdefn property */
913
register object *base;
914
enum ftype result_type;
915
/* we check they are valid functions before calling this */
916
if(type_of(sym)==t_symbol) fun = symbol_function(sym);
918
vs_base= (base = vs_top);
919
if (fun == OBJNULL) FEinvalid_function(sym);
921
/* if (type_of(fun)==t_vfun) argd=fcall.argd; */ /*remove this! */
922
nargs=SFUN_NARGS(argd);
923
result_type=SFUN_RETURN_TYPE(argd);
924
SFUN_START_ARG_TYPES(argd);
928
{vs_push(i ? va_arg(ll,object) : first);
933
enum ftype typ=SFUN_NEXT_TYPE(argd);
936
_xx=i ? va_arg(ll,object) : first;
939
_yy=i ? va_arg(ll,fixnum) : (fixnum)first;
940
_xx=make_fixnum(_yy);
953
The caller won't expect us to restore these. */
954
return((result_type==f_object? vs_base[0] : (object)fix(vs_base[0])));
959
object call_vproc_new(object sym, void *link, object first,va_list ll)
960
{return call_proc_new(sym,link,VFUN_NARGS | VFUN_NARG_BIT,first,ll);}
963
mcall_proc0(object sym,void *link,int argd,...)
969
res=call_proc(sym,link,argd,ap);
977
call_proc0(object sym, void *link)
978
{return mcall_proc0(sym,link,0);}
982
call_proc1(object sym,void *link,...)
985
return (call_proc(sym,link,1,ll));
990
call_proc2(object sym,object link,...)
993
return (call_proc(sym,link,2,ll));
1002
ifuncall(object sym,int n,...)
1005
object *old_vs_base;
1008
old_vs_base = vs_base;
1009
old_vs_top = vs_top;
1010
vs_base = old_vs_top;
1011
vs_top=old_vs_top+n;
1015
old_vs_top[i]= va_arg(ap,object);
1017
if (type_of(sym->s.s_gfdef)==t_cfun)
1018
(*(sym->s.s_gfdef)->cf.cf_self)();
1019
else super_funcall(sym);
1021
vs_top = old_vs_top;
1022
vs_base = old_vs_base;
1028
/* imfuncall(object sym,int n,...) */
1031
/* object *old_vs_top; */
1032
/* old_vs_top = vs_top; */
1033
/* vs_base = old_vs_top; */
1034
/* vs_top=old_vs_top+n; */
1036
/* va_start(ap,n); */
1037
/* for(i=0;i<n;i++) */
1038
/* old_vs_top[i]= va_arg(ap,object); */
1040
/* if (type_of(sym->s.s_gfdef)==t_cfun) */
1041
/* (*(sym->s.s_gfdef)->cf.cf_self)(); */
1042
/* else super_funcall(sym); */
1043
/* return(vs_base[0]); */
1046
/* go from beg+1 below limit setting entries equal to 0 until you
1047
come to FRESH 0's . */
1052
clear_stack(object *beg, object *limit)
1054
while (++beg < limit)
1056
if (i > FRESH) return 0;
1057
;*beg=0;} return 0;}
1060
FFN(set_mv)(int i, object val)
1061
{ if (i >= (sizeof(MVloc)/sizeof(object)))
1062
FEerror("Bad mv index",0);
1063
return(MVloc[i]=val);
1068
FFN(mv_ref)(unsigned int i)
1070
if (i >= (sizeof(MVloc)/sizeof(object)))
1071
FEerror("Bad mv index",0);
1074
FEerror("Null value",0);
1079
#include "xdrfuns.c"
1081
DEF_ORDINARY("CDEFN",sScdefn,SI,"");
1082
DEFVAR("*LINK-ARRAY*",sLAlink_arrayA,LISP,Cnil,"");
1085
gcl_init_links(void)
1088
make_si_sfun("SET-MV",set_mv, ARGTYPE2(f_fixnum,f_object) |
1090
make_si_sfun("MV-REF",mv_ref, ARGTYPE1(f_fixnum) | RESTYPE(f_object));