CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

Path: gap4r8 / src / calls.c
Views: 418346
1
/****************************************************************************
2
**
3
*W calls.c GAP source Martin Schönert
4
**
5
**
6
*Y Copyright (C) 1996, Lehrstuhl D für Mathematik, RWTH Aachen, Germany
7
*Y (C) 1998 School Math and Comp. Sci., University of St Andrews, Scotland
8
*Y Copyright (C) 2002 The GAP Group
9
**
10
** This file contains the functions for the function call mechanism package.
11
**
12
** For a description of what the function call mechanism is about see the
13
** declaration part of this package.
14
**
15
** Each function is represented by a function bag (of type 'T_FUNCTION'),
16
** which has the following format.
17
**
18
** +-------+-------+- - - -+-------+
19
** |handler|handler| |handler| (for all functions)
20
** | 0 | 1 | | 7 |
21
** +-------+-------+- - - -+-------+
22
**
23
** +-------+-------+-------+-------+
24
** | name | number| args &| prof- | (for all functions)
25
** | func. | args | locals| iling |
26
** +-------+-------+-------+-------+
27
**
28
** +-------+-------+-------+-------+
29
** | number| body | envir-| funcs.| (only for interpreted functions)
30
** | locals| func. | onment| exprs.|
31
** +-------+-------+-------+-------+
32
**
33
** ...what the handlers are..
34
** ...what the other components are...
35
*/
36
#include "system.h" /* system dependent part */
37
38
39
40
#include "gasman.h" /* garbage collector */
41
#include "objects.h" /* objects */
42
#include "scanner.h" /* scanner */
43
44
#include "gap.h" /* error handling, initialisation */
45
46
#include "gvars.h" /* global variables */
47
48
#include "calls.h" /* generic call mechanism */
49
50
#include "opers.h" /* generic operations */
51
52
#include "records.h" /* generic records */
53
#include "precord.h" /* plain records */
54
55
#include "lists.h" /* generic lists */
56
57
#include "bool.h" /* booleans */
58
59
#include "plist.h" /* plain lists */
60
#include "string.h" /* strings */
61
62
#include "code.h" /* coder */
63
64
#include "stats.h" /* statements */
65
66
#include "saveload.h" /* saving and loading */
67
#include "tls.h" /* thread-local storage */
68
69
#include "vars.h" /* variables */
70
71
#include <assert.h>
72
73
/****************************************************************************
74
**
75
76
*F * * * * wrapper for functions with variable number of arguments * * * * *
77
*/
78
79
/****************************************************************************
80
**
81
82
*F DoWrap0args( <self> ) . . . . . . . . . . . wrap up 0 arguments in a list
83
**
84
** 'DoWrap<i>args' accepts the <i> arguments <arg1>, <arg2>, and so on,
85
** wraps them up in a list, and then calls <self> again via 'CALL_XARGS',
86
** passing this list. 'DoWrap<i>args' are the handlers for callees that
87
** accept a variable number of arguments. Note that there is no
88
** 'DoWrapXargs' handler, since in this case the function call mechanism
89
** already requires that the passed arguments are collected in a list.
90
*/
91
Obj DoWrap0args (
92
Obj self )
93
{
94
Obj result; /* value of function call, result */
95
Obj args; /* arguments list */
96
97
/* make the arguments list */
98
args = NEW_PLIST( T_PLIST, 0 );
99
SET_LEN_PLIST( args, 0 );
100
101
/* call the variable number of arguments function */
102
result = CALL_XARGS( self, args );
103
return result;
104
}
105
106
107
/****************************************************************************
108
**
109
*F DoWrap1args( <self>, <arg1> ) . . . . . . . wrap up 1 arguments in a list
110
*/
111
Obj DoWrap1args (
112
Obj self,
113
Obj arg1 )
114
{
115
Obj result; /* value of function call, result */
116
Obj args; /* arguments list */
117
118
/* make the arguments list */
119
args = NEW_PLIST( T_PLIST, 1 );
120
SET_LEN_PLIST( args, 1 );
121
SET_ELM_PLIST( args, 1, arg1 );
122
123
/* call the variable number of arguments function */
124
result = CALL_XARGS( self, args );
125
return result;
126
}
127
128
129
/****************************************************************************
130
**
131
*F DoWrap2args( <self>, <arg1>, ... ) . . . . wrap up 2 arguments in a list
132
*/
133
Obj DoWrap2args (
134
Obj self,
135
Obj arg1,
136
Obj arg2 )
137
{
138
Obj result; /* value of function call, result */
139
Obj args; /* arguments list */
140
141
/* make the arguments list */
142
args = NEW_PLIST( T_PLIST, 2 );
143
SET_LEN_PLIST( args, 2 );
144
SET_ELM_PLIST( args, 1, arg1 );
145
SET_ELM_PLIST( args, 2, arg2 );
146
147
/* call the variable number of arguments function */
148
result = CALL_XARGS( self, args );
149
return result;
150
}
151
152
153
/****************************************************************************
154
**
155
*F DoWrap3args( <self>, <arg1>, ... ) . . . . wrap up 3 arguments in a list
156
*/
157
Obj DoWrap3args (
158
Obj self,
159
Obj arg1,
160
Obj arg2,
161
Obj arg3 )
162
{
163
Obj result; /* value of function call, result */
164
Obj args; /* arguments list */
165
166
/* make the arguments list */
167
args = NEW_PLIST( T_PLIST, 3 );
168
SET_LEN_PLIST( args, 3 );
169
SET_ELM_PLIST( args, 1, arg1 );
170
SET_ELM_PLIST( args, 2, arg2 );
171
SET_ELM_PLIST( args, 3, arg3 );
172
173
/* call the variable number of arguments function */
174
result = CALL_XARGS( self, args );
175
return result;
176
}
177
178
179
/****************************************************************************
180
**
181
*F DoWrap4args( <self>, <arg1>, ... ) . . . . wrap up 4 arguments in a list
182
*/
183
Obj DoWrap4args (
184
Obj self,
185
Obj arg1,
186
Obj arg2,
187
Obj arg3,
188
Obj arg4 )
189
{
190
Obj result; /* value of function call, result */
191
Obj args; /* arguments list */
192
193
/* make the arguments list */
194
args = NEW_PLIST( T_PLIST, 4 );
195
SET_LEN_PLIST( args, 4 );
196
SET_ELM_PLIST( args, 1, arg1 );
197
SET_ELM_PLIST( args, 2, arg2 );
198
SET_ELM_PLIST( args, 3, arg3 );
199
SET_ELM_PLIST( args, 4, arg4 );
200
201
/* call the variable number of arguments function */
202
result = CALL_XARGS( self, args );
203
return result;
204
}
205
206
207
/****************************************************************************
208
**
209
*F DoWrap5args( <self>, <arg1>, ... ) . . . . wrap up 5 arguments in a list
210
*/
211
Obj DoWrap5args (
212
Obj self,
213
Obj arg1,
214
Obj arg2,
215
Obj arg3,
216
Obj arg4,
217
Obj arg5 )
218
{
219
Obj result; /* value of function call, result */
220
Obj args; /* arguments list */
221
222
/* make the arguments list */
223
args = NEW_PLIST( T_PLIST, 5 );
224
SET_LEN_PLIST( args, 5 );
225
SET_ELM_PLIST( args, 1, arg1 );
226
SET_ELM_PLIST( args, 2, arg2 );
227
SET_ELM_PLIST( args, 3, arg3 );
228
SET_ELM_PLIST( args, 4, arg4 );
229
SET_ELM_PLIST( args, 5, arg5 );
230
231
/* call the variable number of arguments function */
232
result = CALL_XARGS( self, args );
233
return result;
234
}
235
236
237
/****************************************************************************
238
**
239
*F DoWrap6args( <self>, <arg1>, ... ) . . . . wrap up 6 arguments in a list
240
*/
241
Obj DoWrap6args (
242
Obj self,
243
Obj arg1,
244
Obj arg2,
245
Obj arg3,
246
Obj arg4,
247
Obj arg5,
248
Obj arg6 )
249
{
250
Obj result; /* value of function call, result */
251
Obj args; /* arguments list */
252
253
/* make the arguments list */
254
args = NEW_PLIST( T_PLIST, 6 );
255
SET_LEN_PLIST( args, 6 );
256
SET_ELM_PLIST( args, 1, arg1 );
257
SET_ELM_PLIST( args, 2, arg2 );
258
SET_ELM_PLIST( args, 3, arg3 );
259
SET_ELM_PLIST( args, 4, arg4 );
260
SET_ELM_PLIST( args, 5, arg5 );
261
SET_ELM_PLIST( args, 6, arg6 );
262
263
/* call the variable number of arguments function */
264
result = CALL_XARGS( self, args );
265
return result;
266
}
267
268
269
/****************************************************************************
270
**
271
272
*F * * wrapper for functions with do not support the number of arguments * *
273
*/
274
275
/****************************************************************************
276
**
277
278
*F DoFail0args( <self> ) . . . . . . fail a function call with 0 arguments
279
**
280
** 'DoFail<i>args' accepts the <i> arguments <arg1>, <arg2>, and so on, and
281
** signals an error, because the function for which they are installed
282
** expects another number of arguments. 'DoFail<i>args' are the handlers in
283
** the other slots of a function.
284
*/
285
286
/* Pull this out to avoid repetition, since it gets a little more complex in
287
the presence of partially variadic functions */
288
289
Obj NargError( Obj func, Int actual) {
290
Int narg = NARG_FUNC(func);
291
292
if (narg >= 0) {
293
assert(narg != actual);
294
return ErrorReturnObj(
295
"Function: number of arguments must be %d (not %d)",
296
narg, actual,
297
"you can replace the argument list <args> via 'return <args>;'" );
298
} else {
299
assert(-narg-1 > actual);
300
return ErrorReturnObj(
301
"Function: number of arguments must be at least %d (not %d)",
302
-narg-1, actual,
303
"you can replace the argument list <args> via 'return <args>;'" );
304
}
305
}
306
307
Obj DoFail0args (
308
Obj self )
309
{
310
Obj argx; /* arguments list (to continue) */
311
argx =NargError(self, 0);
312
return CallFuncList( self, argx );
313
}
314
315
316
/****************************************************************************
317
**
318
*F DoFail1args( <self>,<arg1> ) . . . fail a function call with 1 arguments
319
*/
320
Obj DoFail1args (
321
Obj self,
322
Obj arg1 )
323
{
324
Obj argx; /* arguments list (to continue) */
325
argx =NargError(self, 1);
326
return CallFuncList( self, argx );
327
}
328
329
330
/****************************************************************************
331
**
332
*F DoFail2args( <self>, <arg1>, ... ) fail a function call with 2 arguments
333
*/
334
Obj DoFail2args (
335
Obj self,
336
Obj arg1,
337
Obj arg2 )
338
{
339
Obj argx; /* arguments list (to continue) */
340
argx =NargError(self, 2);
341
return CallFuncList( self, argx );
342
}
343
344
345
/****************************************************************************
346
**
347
*F DoFail3args( <self>, <arg1>, ... ) fail a function call with 3 arguments
348
*/
349
Obj DoFail3args (
350
Obj self,
351
Obj arg1,
352
Obj arg2,
353
Obj arg3 )
354
{
355
Obj argx; /* arguments list (to continue) */
356
argx =NargError(self, 3);
357
return CallFuncList( self, argx );
358
}
359
360
361
/****************************************************************************
362
**
363
*F DoFail4args( <self>, <arg1>, ... ) fail a function call with 4 arguments
364
*/
365
Obj DoFail4args (
366
Obj self,
367
Obj arg1,
368
Obj arg2,
369
Obj arg3,
370
Obj arg4 )
371
{
372
Obj argx; /* arguments list (to continue) */
373
argx =NargError(self, 4);
374
return CallFuncList( self, argx );
375
}
376
377
378
/****************************************************************************
379
**
380
*F DoFail5args( <self>, <arg1>, ... ) fail a function call with 5 arguments
381
*/
382
Obj DoFail5args (
383
Obj self,
384
Obj arg1,
385
Obj arg2,
386
Obj arg3,
387
Obj arg4,
388
Obj arg5 )
389
{
390
Obj argx; /* arguments list (to continue) */
391
argx =NargError(self, 5);
392
return CallFuncList( self, argx );
393
}
394
395
396
/****************************************************************************
397
**
398
*F DoFail6args( <self>, <arg1>, ... ) fail a function call with 6 arguments
399
*/
400
Obj DoFail6args (
401
Obj self,
402
Obj arg1,
403
Obj arg2,
404
Obj arg3,
405
Obj arg4,
406
Obj arg5,
407
Obj arg6 )
408
{
409
Obj argx; /* arguments list (to continue) */
410
argx =NargError(self, 6);
411
return CallFuncList( self, argx );
412
}
413
414
415
/****************************************************************************
416
**
417
*F DoFailXargs( <self>, <args> ) . . fail a function call with X arguments
418
*/
419
Obj DoFailXargs (
420
Obj self,
421
Obj args )
422
{
423
Obj argx; /* arguments list (to continue) */
424
argx =NargError(self, LEN_LIST(args));
425
return CallFuncList( self, argx );
426
}
427
428
429
/****************************************************************************
430
**
431
432
*F * * * * * * * * * * * * * wrapper for profiling * * * * * * * * * * * * *
433
*/
434
435
/****************************************************************************
436
**
437
438
*V TimeDone . . . . . . amount of time spent for completed function calls
439
**
440
** 'TimeDone' is the amount of time spent for all function calls that have
441
** already been completed.
442
*/
443
UInt TimeDone;
444
445
446
/****************************************************************************
447
**
448
*V StorDone . . . . . amount of storage spent for completed function calls
449
**
450
** 'StorDone' is the amount of storage spent for all function call that have
451
** already been completed.
452
*/
453
UInt StorDone;
454
455
456
/****************************************************************************
457
**
458
*F DoProf0args( <self> ) . . . . . . . . profile a function with 0 arguments
459
**
460
** 'DoProf<i>args' accepts the <i> arguments <arg1>, <arg2>, and so on, and
461
** calls the function through the secondary handler. It also updates the
462
** profiling information in the profiling information bag of the called
463
** function. 'DoProf<i>args' are the primary handlers for all functions
464
** when profiling is requested.
465
*/
466
Obj DoProf0args (
467
Obj self )
468
{
469
Obj result; /* value of function call, result */
470
Obj prof; /* profiling bag */
471
UInt timeElse; /* time spent elsewhere */
472
UInt timeCurr; /* time spent in current funcs. */
473
UInt storElse; /* storage spent elsewhere */
474
UInt storCurr; /* storage spent in current funcs. */
475
476
/* get the profiling bag */
477
prof = PROF_FUNC( PROF_FUNC( self ) );
478
479
/* time and storage spent so far while this function what not active */
480
timeElse = SyTime() - TIME_WITH_PROF(prof);
481
storElse = SizeAllBags - STOR_WITH_PROF(prof);
482
483
/* time and storage spent so far by all currently suspended functions */
484
timeCurr = SyTime() - TimeDone;
485
storCurr = SizeAllBags - StorDone;
486
487
/* call the real function */
488
result = CALL_0ARGS_PROF( self );
489
490
/* number of invocation of this function */
491
SET_COUNT_PROF( prof, COUNT_PROF(prof) + 1 );
492
493
/* time and storage spent in this function and its children */
494
SET_TIME_WITH_PROF( prof, SyTime() - timeElse );
495
SET_STOR_WITH_PROF( prof, SizeAllBags - storElse );
496
497
/* time and storage spent by this invocation of this function */
498
timeCurr = SyTime() - TimeDone - timeCurr;
499
SET_TIME_WOUT_PROF( prof, TIME_WOUT_PROF(prof) + timeCurr );
500
TimeDone += timeCurr;
501
storCurr = SizeAllBags - StorDone - storCurr;
502
SET_STOR_WOUT_PROF( prof, STOR_WOUT_PROF(prof) + storCurr );
503
StorDone += storCurr;
504
505
/* return the result from the function */
506
return result;
507
}
508
509
510
/****************************************************************************
511
**
512
*F DoProf1args( <self>, <arg1>) . . . . profile a function with 1 arguments
513
*/
514
Obj DoProf1args (
515
Obj self,
516
Obj arg1 )
517
{
518
Obj result; /* value of function call, result */
519
Obj prof; /* profiling bag */
520
UInt timeElse; /* time spent elsewhere */
521
UInt timeCurr; /* time spent in current funcs. */
522
UInt storElse; /* storage spent elsewhere */
523
UInt storCurr; /* storage spent in current funcs. */
524
525
/* get the profiling bag */
526
prof = PROF_FUNC( PROF_FUNC( self ) );
527
528
/* time and storage spent so far while this function what not active */
529
timeElse = SyTime() - TIME_WITH_PROF(prof);
530
storElse = SizeAllBags - STOR_WITH_PROF(prof);
531
532
/* time and storage spent so far by all currently suspended functions */
533
timeCurr = SyTime() - TimeDone;
534
storCurr = SizeAllBags - StorDone;
535
536
/* call the real function */
537
result = CALL_1ARGS_PROF( self, arg1 );
538
539
/* number of invocation of this function */
540
SET_COUNT_PROF( prof, COUNT_PROF(prof) + 1 );
541
542
/* time and storage spent in this function and its children */
543
SET_TIME_WITH_PROF( prof, SyTime() - timeElse );
544
SET_STOR_WITH_PROF( prof, SizeAllBags - storElse );
545
546
/* time and storage spent by this invocation of this function */
547
timeCurr = SyTime() - TimeDone - timeCurr;
548
SET_TIME_WOUT_PROF( prof, TIME_WOUT_PROF(prof) + timeCurr );
549
TimeDone += timeCurr;
550
storCurr = SizeAllBags - StorDone - storCurr;
551
SET_STOR_WOUT_PROF( prof, STOR_WOUT_PROF(prof) + storCurr );
552
StorDone += storCurr;
553
554
/* return the result from the function */
555
return result;
556
}
557
558
559
/****************************************************************************
560
**
561
*F DoProf2args( <self>, <arg1>, ... ) . profile a function with 2 arguments
562
*/
563
Obj DoProf2args (
564
Obj self,
565
Obj arg1,
566
Obj arg2 )
567
{
568
Obj result; /* value of function call, result */
569
Obj prof; /* profiling bag */
570
UInt timeElse; /* time spent elsewhere */
571
UInt timeCurr; /* time spent in current funcs. */
572
UInt storElse; /* storage spent elsewhere */
573
UInt storCurr; /* storage spent in current funcs. */
574
575
/* get the profiling bag */
576
prof = PROF_FUNC( PROF_FUNC( self ) );
577
578
/* time and storage spent so far while this function what not active */
579
timeElse = SyTime() - TIME_WITH_PROF(prof);
580
storElse = SizeAllBags - STOR_WITH_PROF(prof);
581
582
/* time and storage spent so far by all currently suspended functions */
583
timeCurr = SyTime() - TimeDone;
584
storCurr = SizeAllBags - StorDone;
585
586
/* call the real function */
587
result = CALL_2ARGS_PROF( self, arg1, arg2 );
588
589
/* number of invocation of this function */
590
SET_COUNT_PROF( prof, COUNT_PROF(prof) + 1 );
591
592
/* time and storage spent in this function and its children */
593
SET_TIME_WITH_PROF( prof, SyTime() - timeElse );
594
SET_STOR_WITH_PROF( prof, SizeAllBags - storElse );
595
596
/* time and storage spent by this invocation of this function */
597
timeCurr = SyTime() - TimeDone - timeCurr;
598
SET_TIME_WOUT_PROF( prof, TIME_WOUT_PROF(prof) + timeCurr );
599
TimeDone += timeCurr;
600
storCurr = SizeAllBags - StorDone - storCurr;
601
SET_STOR_WOUT_PROF( prof, STOR_WOUT_PROF(prof) + storCurr );
602
StorDone += storCurr;
603
604
/* return the result from the function */
605
return result;
606
}
607
608
609
/****************************************************************************
610
**
611
*F DoProf3args( <self>, <arg1>, ... ) . profile a function with 3 arguments
612
*/
613
Obj DoProf3args (
614
Obj self,
615
Obj arg1,
616
Obj arg2,
617
Obj arg3 )
618
{
619
Obj result; /* value of function call, result */
620
Obj prof; /* profiling bag */
621
UInt timeElse; /* time spent elsewhere */
622
UInt timeCurr; /* time spent in current funcs. */
623
UInt storElse; /* storage spent elsewhere */
624
UInt storCurr; /* storage spent in current funcs. */
625
626
/* get the profiling bag */
627
prof = PROF_FUNC( PROF_FUNC( self ) );
628
629
/* time and storage spent so far while this function what not active */
630
timeElse = SyTime() - TIME_WITH_PROF(prof);
631
storElse = SizeAllBags - STOR_WITH_PROF(prof);
632
633
/* time and storage spent so far by all currently suspended functions */
634
timeCurr = SyTime() - TimeDone;
635
storCurr = SizeAllBags - StorDone;
636
637
/* call the real function */
638
result = CALL_3ARGS_PROF( self, arg1, arg2, arg3 );
639
640
/* number of invocation of this function */
641
SET_COUNT_PROF( prof, COUNT_PROF(prof) + 1 );
642
643
/* time and storage spent in this function and its children */
644
SET_TIME_WITH_PROF( prof, SyTime() - timeElse );
645
SET_STOR_WITH_PROF( prof, SizeAllBags - storElse );
646
647
/* time and storage spent by this invocation of this function */
648
timeCurr = SyTime() - TimeDone - timeCurr;
649
SET_TIME_WOUT_PROF( prof, TIME_WOUT_PROF(prof) + timeCurr );
650
TimeDone += timeCurr;
651
storCurr = SizeAllBags - StorDone - storCurr;
652
SET_STOR_WOUT_PROF( prof, STOR_WOUT_PROF(prof) + storCurr );
653
StorDone += storCurr;
654
655
/* return the result from the function */
656
return result;
657
}
658
659
660
/****************************************************************************
661
**
662
*F DoProf4args( <self>, <arg1>, ... ) . profile a function with 4 arguments
663
*/
664
Obj DoProf4args (
665
Obj self,
666
Obj arg1,
667
Obj arg2,
668
Obj arg3,
669
Obj arg4 )
670
{
671
Obj result; /* value of function call, result */
672
Obj prof; /* profiling bag */
673
UInt timeElse; /* time spent elsewhere */
674
UInt timeCurr; /* time spent in current funcs. */
675
UInt storElse; /* storage spent elsewhere */
676
UInt storCurr; /* storage spent in current funcs. */
677
678
/* get the profiling bag */
679
prof = PROF_FUNC( PROF_FUNC( self ) );
680
681
/* time and storage spent so far while this function what not active */
682
timeElse = SyTime() - TIME_WITH_PROF(prof);
683
storElse = SizeAllBags - STOR_WITH_PROF(prof);
684
685
/* time and storage spent so far by all currently suspended functions */
686
timeCurr = SyTime() - TimeDone;
687
storCurr = SizeAllBags - StorDone;
688
689
/* call the real function */
690
result = CALL_4ARGS_PROF( self, arg1, arg2, arg3, arg4 );
691
692
/* number of invocation of this function */
693
SET_COUNT_PROF( prof, COUNT_PROF(prof) + 1 );
694
695
/* time and storage spent in this function and its children */
696
SET_TIME_WITH_PROF( prof, SyTime() - timeElse );
697
SET_STOR_WITH_PROF( prof, SizeAllBags - storElse );
698
699
/* time and storage spent by this invocation of this function */
700
timeCurr = SyTime() - TimeDone - timeCurr;
701
SET_TIME_WOUT_PROF( prof, TIME_WOUT_PROF(prof) + timeCurr );
702
TimeDone += timeCurr;
703
storCurr = SizeAllBags - StorDone - storCurr;
704
SET_STOR_WOUT_PROF( prof, STOR_WOUT_PROF(prof) + storCurr );
705
StorDone += storCurr;
706
707
/* return the result from the function */
708
return result;
709
}
710
711
712
/****************************************************************************
713
**
714
*F DoProf5args( <self>, <arg1>, ... ) . profile a function with 5 arguments
715
*/
716
Obj DoProf5args (
717
Obj self,
718
Obj arg1,
719
Obj arg2,
720
Obj arg3,
721
Obj arg4,
722
Obj arg5 )
723
{
724
Obj result; /* value of function call, result */
725
Obj prof; /* profiling bag */
726
UInt timeElse; /* time spent elsewhere */
727
UInt timeCurr; /* time spent in current funcs. */
728
UInt storElse; /* storage spent elsewhere */
729
UInt storCurr; /* storage spent in current funcs. */
730
731
/* get the profiling bag */
732
prof = PROF_FUNC( PROF_FUNC( self ) );
733
734
/* time and storage spent so far while this function what not active */
735
timeElse = SyTime() - TIME_WITH_PROF(prof);
736
storElse = SizeAllBags - STOR_WITH_PROF(prof);
737
738
/* time and storage spent so far by all currently suspended functions */
739
timeCurr = SyTime() - TimeDone;
740
storCurr = SizeAllBags - StorDone;
741
742
/* call the real function */
743
result = CALL_5ARGS_PROF( self, arg1, arg2, arg3, arg4, arg5 );
744
745
/* number of invocation of this function */
746
SET_COUNT_PROF( prof, COUNT_PROF(prof) + 1 );
747
748
/* time and storage spent in this function and its children */
749
SET_TIME_WITH_PROF( prof, SyTime() - timeElse );
750
SET_STOR_WITH_PROF( prof, SizeAllBags - storElse );
751
752
/* time and storage spent by this invocation of this function */
753
timeCurr = SyTime() - TimeDone - timeCurr;
754
SET_TIME_WOUT_PROF( prof, TIME_WOUT_PROF(prof) + timeCurr );
755
TimeDone += timeCurr;
756
storCurr = SizeAllBags - StorDone - storCurr;
757
SET_STOR_WOUT_PROF( prof, STOR_WOUT_PROF(prof) + storCurr );
758
StorDone += storCurr;
759
760
/* return the result from the function */
761
return result;
762
}
763
764
765
/****************************************************************************
766
**
767
*F DoProf6args( <self>, <arg1>, ... ) . profile a function with 6 arguments
768
*/
769
Obj DoProf6args (
770
Obj self,
771
Obj arg1,
772
Obj arg2,
773
Obj arg3,
774
Obj arg4,
775
Obj arg5,
776
Obj arg6 )
777
{
778
Obj result; /* value of function call, result */
779
Obj prof; /* profiling bag */
780
UInt timeElse; /* time spent elsewhere */
781
UInt timeCurr; /* time spent in current funcs. */
782
UInt storElse; /* storage spent elsewhere */
783
UInt storCurr; /* storage spent in current funcs. */
784
785
/* get the profiling bag */
786
prof = PROF_FUNC( PROF_FUNC( self ) );
787
788
/* time and storage spent so far while this function what not active */
789
timeElse = SyTime() - TIME_WITH_PROF(prof);
790
storElse = SizeAllBags - STOR_WITH_PROF(prof);
791
792
/* time and storage spent so far by all currently suspended functions */
793
timeCurr = SyTime() - TimeDone;
794
storCurr = SizeAllBags - StorDone;
795
796
/* call the real function */
797
result = CALL_6ARGS_PROF( self, arg1, arg2, arg3, arg4, arg5, arg6 );
798
799
/* number of invocation of this function */
800
SET_COUNT_PROF( prof, COUNT_PROF(prof) + 1 );
801
802
/* time and storage spent in this function and its children */
803
SET_TIME_WITH_PROF( prof, SyTime() - timeElse );
804
SET_STOR_WITH_PROF( prof, SizeAllBags - storElse );
805
806
/* time and storage spent by this invocation of this function */
807
timeCurr = SyTime() - TimeDone - timeCurr;
808
SET_TIME_WOUT_PROF( prof, TIME_WOUT_PROF(prof) + timeCurr );
809
TimeDone += timeCurr;
810
storCurr = SizeAllBags - StorDone - storCurr;
811
SET_STOR_WOUT_PROF( prof, STOR_WOUT_PROF(prof) + storCurr );
812
StorDone += storCurr;
813
814
/* return the result from the function */
815
return result;
816
}
817
818
819
/****************************************************************************
820
**
821
*F DoProfXargs( <self>, <args> ) . . . . profile a function with X arguments
822
*/
823
Obj DoProfXargs (
824
Obj self,
825
Obj args )
826
{
827
Obj result; /* value of function call, result */
828
Obj prof; /* profiling bag */
829
UInt timeElse; /* time spent elsewhere */
830
UInt timeCurr; /* time spent in current funcs. */
831
UInt storElse; /* storage spent elsewhere */
832
UInt storCurr; /* storage spent in current funcs. */
833
834
/* get the profiling bag */
835
prof = PROF_FUNC( PROF_FUNC( self ) );
836
837
/* time and storage spent so far while this function what not active */
838
timeElse = SyTime() - TIME_WITH_PROF(prof);
839
storElse = SizeAllBags - STOR_WITH_PROF(prof);
840
841
/* time and storage spent so far by all currently suspended functions */
842
timeCurr = SyTime() - TimeDone;
843
storCurr = SizeAllBags - StorDone;
844
845
/* call the real function */
846
result = CALL_XARGS_PROF( self, args );
847
848
/* number of invocation of this function */
849
SET_COUNT_PROF( prof, COUNT_PROF(prof) + 1 );
850
851
/* time and storage spent in this function and its children */
852
SET_TIME_WITH_PROF( prof, SyTime() - timeElse );
853
SET_STOR_WITH_PROF( prof, SizeAllBags - storElse );
854
855
/* time and storage spent by this invocation of this function */
856
timeCurr = SyTime() - TimeDone - timeCurr;
857
SET_TIME_WOUT_PROF( prof, TIME_WOUT_PROF(prof) + timeCurr );
858
TimeDone += timeCurr;
859
storCurr = SizeAllBags - StorDone - storCurr;
860
SET_STOR_WOUT_PROF( prof, STOR_WOUT_PROF(prof) + storCurr );
861
StorDone += storCurr;
862
863
/* return the result from the function */
864
return result;
865
}
866
867
868
/****************************************************************************
869
**
870
871
*F * * * * * * * * * * * * * create a new function * * * * * * * * * * * * *
872
*/
873
874
/****************************************************************************
875
**
876
877
*F InitHandlerFunc( <handler>, <cookie> ) . . . . . . . . register a handler
878
**
879
** Every handler should be registered (once) before it is installed in any
880
** function bag. This is needed so that it can be identified when loading a
881
** saved workspace. <cookie> should be a unique C string, identifying the
882
** handler
883
*/
884
#ifndef MAX_HANDLERS
885
#define MAX_HANDLERS 20000
886
#endif
887
888
typedef struct {
889
ObjFunc hdlr;
890
const Char * cookie;
891
}
892
TypeHandlerInfo;
893
894
static UInt HandlerSortingStatus;
895
896
static TypeHandlerInfo HandlerFuncs[MAX_HANDLERS];
897
static UInt NHandlerFuncs;
898
899
void InitHandlerFunc (
900
ObjFunc hdlr,
901
const Char * cookie )
902
{
903
if ( NHandlerFuncs >= MAX_HANDLERS ) {
904
Pr( "No room left for function handler\n", 0L, 0L );
905
SyExit(1);
906
}
907
#ifdef DEBUG_HANDLER_REGISTRATION
908
{
909
UInt i;
910
for (i = 0; i < NHandlerFuncs; i++)
911
if (!strcmp(HandlerFuncs[i].cookie, cookie))
912
Pr("Duplicate cookie %s\n", (Int)cookie, 0L);
913
}
914
#endif
915
HandlerFuncs[NHandlerFuncs].hdlr = hdlr;
916
HandlerFuncs[NHandlerFuncs].cookie = cookie;
917
HandlerSortingStatus = 0; /* no longer sorted by handler or cookie */
918
NHandlerFuncs++;
919
}
920
921
922
923
/****************************************************************************
924
**
925
*f CheckHandlersBag( <bag> ) . . . . . . check that handlers are initialised
926
*/
927
928
void InitHandlerRegistration( void )
929
{
930
/* initialize these here rather than statically to allow for restart */
931
/* can't do them in InitKernel of this module because it's called too late
932
so make it a function and call it from an earlier InitKernel */
933
HandlerSortingStatus = 0;
934
NHandlerFuncs = 0;
935
936
}
937
938
static void CheckHandlersBag(
939
Bag bag )
940
{
941
#ifdef DEBUG_HANDLER_REGISTRATION
942
UInt i;
943
UInt j;
944
ObjFunc hdlr;
945
946
if ( TNUM_BAG(bag) == T_FUNCTION ) {
947
for ( j = 0; j < 8; j++ ) {
948
hdlr = HDLR_FUNC(bag,j);
949
950
/* zero handlers are used in a few odd places */
951
if ( hdlr != 0 ) {
952
for ( i = 0; i < NHandlerFuncs; i++ ) {
953
if ( hdlr == HandlerFuncs[i].hdlr )
954
break;
955
}
956
if ( i == NHandlerFuncs ) {
957
Pr("Unregistered Handler %d args ", j, 0L);
958
PrintObj(NAME_FUNC(bag));
959
Pr("\n",0L,0L);
960
}
961
}
962
}
963
}
964
#endif
965
return;
966
}
967
968
void CheckAllHandlers(
969
void )
970
{
971
CallbackForAllBags( CheckHandlersBag);
972
return;
973
}
974
975
976
static int IsLessHandlerInfo (
977
TypeHandlerInfo * h1,
978
TypeHandlerInfo * h2,
979
UInt byWhat )
980
{
981
switch (byWhat) {
982
case 1:
983
/* cast to please Irix CC and HPUX CC */
984
return (UInt)(h1->hdlr) < (UInt)(h2->hdlr);
985
case 2:
986
return strcmp(h1->cookie, h2->cookie) < 0;
987
default:
988
ErrorQuit( "Invalid sort mode %u", (Int)byWhat, 0L );
989
return 0; /* please lint */
990
}
991
}
992
993
void SortHandlers( UInt byWhat )
994
{
995
TypeHandlerInfo tmp;
996
UInt len, h, i, k;
997
if (HandlerSortingStatus == byWhat)
998
return;
999
len = NHandlerFuncs;
1000
h = 1;
1001
while ( 9*h + 4 < len )
1002
{ h = 3*h + 1; }
1003
while ( 0 < h ) {
1004
for ( i = h; i < len; i++ ) {
1005
tmp = HandlerFuncs[i];
1006
k = i;
1007
while ( h <= k && IsLessHandlerInfo(&tmp, HandlerFuncs+(k-h), byWhat))
1008
{
1009
HandlerFuncs[k] = HandlerFuncs[k-h];
1010
k -= h;
1011
}
1012
HandlerFuncs[k] = tmp;
1013
}
1014
h = h / 3;
1015
}
1016
HandlerSortingStatus = byWhat;
1017
return;
1018
}
1019
1020
const Char * CookieOfHandler (
1021
ObjFunc hdlr )
1022
{
1023
UInt i, top, bottom, middle;
1024
1025
if ( HandlerSortingStatus != 1 ) {
1026
for ( i = 0; i < NHandlerFuncs; i++ ) {
1027
if ( hdlr == HandlerFuncs[i].hdlr )
1028
return HandlerFuncs[i].cookie;
1029
}
1030
return (Char *)0L;
1031
}
1032
else {
1033
top = NHandlerFuncs;
1034
bottom = 0;
1035
while ( top >= bottom ) {
1036
middle = (top + bottom)/2;
1037
if ( (UInt)(hdlr) < (UInt)(HandlerFuncs[middle].hdlr) )
1038
top = middle-1;
1039
else if ( (UInt)(hdlr) > (UInt)(HandlerFuncs[middle].hdlr) )
1040
bottom = middle+1;
1041
else
1042
return HandlerFuncs[middle].cookie;
1043
}
1044
return (Char *)0L;
1045
}
1046
}
1047
1048
ObjFunc HandlerOfCookie(
1049
const Char * cookie )
1050
{
1051
Int i,top,bottom,middle;
1052
Int res;
1053
if (HandlerSortingStatus != 2)
1054
{
1055
for (i = 0; i < NHandlerFuncs; i++)
1056
{
1057
if (strcmp(cookie, HandlerFuncs[i].cookie) == 0)
1058
return HandlerFuncs[i].hdlr;
1059
}
1060
return (ObjFunc)0L;
1061
}
1062
else
1063
{
1064
top = NHandlerFuncs;
1065
bottom = 0;
1066
while (top >= bottom) {
1067
middle = (top + bottom)/2;
1068
res = strcmp(cookie,HandlerFuncs[middle].cookie);
1069
if (res < 0)
1070
top = middle-1;
1071
else if (res > 0)
1072
bottom = middle+1;
1073
else
1074
return HandlerFuncs[middle].hdlr;
1075
}
1076
return (ObjFunc)0L;
1077
}
1078
}
1079
1080
1081
1082
/****************************************************************************
1083
**
1084
1085
*F NewFunction( <name>, <narg>, <nams>, <hdlr> ) . . . . make a new function
1086
**
1087
** 'NewFunction' creates and returns a new function. <name> must be a GAP
1088
** string containing the name of the function. <narg> must be the number of
1089
** arguments, where -1 means a variable number of arguments. <nams> must be
1090
** a GAP list containg the names of the arguments. <hdlr> must be the
1091
** C function (accepting <self> and the <narg> arguments) that will be
1092
** called to execute the function.
1093
*/
1094
Obj NewFunction (
1095
Obj name,
1096
Int narg,
1097
Obj nams,
1098
ObjFunc hdlr )
1099
{
1100
return NewFunctionT( T_FUNCTION, SIZE_FUNC, name, narg, nams, hdlr );
1101
}
1102
1103
1104
/****************************************************************************
1105
**
1106
*F NewFunctionC( <name>, <narg>, <nams>, <hdlr> ) . . . make a new function
1107
**
1108
** 'NewFunctionC' does the same as 'NewFunction', but expects <name> and
1109
** <nams> as C strings.
1110
*/
1111
Obj NewFunctionC (
1112
const Char * name,
1113
Int narg,
1114
const Char * nams,
1115
ObjFunc hdlr )
1116
{
1117
return NewFunctionCT( T_FUNCTION, SIZE_FUNC, name, narg, nams, hdlr );
1118
}
1119
1120
1121
/****************************************************************************
1122
**
1123
*F NewFunctionT( <type>, <size>, <name>, <narg>, <nams>, <hdlr> )
1124
**
1125
** 'NewFunctionT' does the same as 'NewFunction', but allows to specify the
1126
** <type> and <size> of the newly created bag.
1127
*/
1128
Obj NewFunctionT (
1129
UInt type,
1130
UInt size,
1131
Obj name,
1132
Int narg,
1133
Obj nams,
1134
ObjFunc hdlr )
1135
{
1136
Obj func; /* function, result */
1137
Obj prof; /* profiling bag */
1138
1139
1140
/* make the function object */
1141
func = NewBag( type, size );
1142
1143
/* create a function with a fixed number of arguments */
1144
if ( narg >= 0 ) {
1145
HDLR_FUNC(func,0) = DoFail0args;
1146
HDLR_FUNC(func,1) = DoFail1args;
1147
HDLR_FUNC(func,2) = DoFail2args;
1148
HDLR_FUNC(func,3) = DoFail3args;
1149
HDLR_FUNC(func,4) = DoFail4args;
1150
HDLR_FUNC(func,5) = DoFail5args;
1151
HDLR_FUNC(func,6) = DoFail6args;
1152
HDLR_FUNC(func,7) = DoFailXargs;
1153
HDLR_FUNC( func, (narg <= 6 ? narg : 7) ) = hdlr;
1154
}
1155
1156
/* create a function with a variable number of arguments */
1157
else {
1158
HDLR_FUNC(func,0) = (narg >= -1) ? DoWrap0args : DoFail0args;
1159
HDLR_FUNC(func,1) = (narg >= -2) ? DoWrap1args : DoFail1args;
1160
HDLR_FUNC(func,2) = (narg >= -3) ? DoWrap2args : DoFail2args;
1161
HDLR_FUNC(func,3) = (narg >= -4) ? DoWrap3args : DoFail3args;
1162
HDLR_FUNC(func,4) = (narg >= -5) ? DoWrap4args : DoFail4args;
1163
HDLR_FUNC(func,5) = (narg >= -6) ? DoWrap5args : DoFail5args;
1164
HDLR_FUNC(func,6) = (narg >= -7) ? DoWrap6args : DoFail6args;
1165
HDLR_FUNC(func,7) = hdlr;
1166
}
1167
1168
/* enter the arguments and the names */
1169
NAME_FUNC(func) = name;
1170
NARG_FUNC(func) = narg;
1171
NAMS_FUNC(func) = nams;
1172
if (nams) MakeBagPublic(nams);
1173
CHANGED_BAG(func);
1174
1175
/* enter the profiling bag */
1176
prof = NEW_PLIST( T_PLIST, LEN_PROF );
1177
SET_LEN_PLIST( prof, LEN_PROF );
1178
SET_COUNT_PROF( prof, 0 );
1179
SET_TIME_WITH_PROF( prof, 0 );
1180
SET_TIME_WOUT_PROF( prof, 0 );
1181
SET_STOR_WITH_PROF( prof, 0 );
1182
SET_STOR_WOUT_PROF( prof, 0 );
1183
PROF_FUNC(func) = prof;
1184
CHANGED_BAG(func);
1185
1186
/* return the function bag */
1187
return func;
1188
}
1189
1190
1191
/****************************************************************************
1192
**
1193
*F NewFunctionCT( <type>, <size>, <name>, <narg>, <nams>, <hdlr> )
1194
**
1195
** 'NewFunctionCT' does the same as 'NewFunction', but expects <name> and
1196
** <nams> as C strings, and allows to specify the <type> and <size> of the
1197
** newly created bag.
1198
*/
1199
Obj NewFunctionCT (
1200
UInt type,
1201
UInt size,
1202
const Char * name_c,
1203
Int narg,
1204
const Char * nams_c,
1205
ObjFunc hdlr )
1206
{
1207
Obj name_o; /* name as an object */
1208
1209
/* convert the name to an object */
1210
C_NEW_STRING_DYN(name_o, name_c);
1211
RetypeBag(name_o, T_STRING+IMMUTABLE);
1212
1213
/* make the function */
1214
return NewFunctionT( type, size, name_o, narg, ArgStringToList( nams_c ), hdlr );
1215
}
1216
1217
1218
/****************************************************************************
1219
**
1220
*F ArgStringToList( <nams_c> )
1221
**
1222
** 'ArgStringToList' takes a C string <nams_c> containing a list of comma
1223
** separated argument names, and turns it into a plist of strings, ready
1224
** to be passed to 'NewFunction' as <nams>.
1225
*/
1226
Obj ArgStringToList(const Char *nams_c) {
1227
Obj tmp; /* argument name as an object */
1228
Obj nams_o; /* nams as an object */
1229
UInt len; /* length */
1230
UInt i, k, l; /* loop variables */
1231
1232
/* convert the arguments list to an object */
1233
len = 0;
1234
for ( k = 0; nams_c[k] != '\0'; k++ ) {
1235
if ( (0 == k || nams_c[k-1] == ' ' || nams_c[k-1] == ',')
1236
&& ( nams_c[k ] != ' ' && nams_c[k ] != ',') ) {
1237
len++;
1238
}
1239
}
1240
nams_o = NEW_PLIST( T_PLIST, len );
1241
SET_LEN_PLIST( nams_o, len );
1242
k = 0;
1243
for ( i = 1; i <= len; i++ ) {
1244
while ( nams_c[k] == ' ' || nams_c[k] == ',' ) {
1245
k++;
1246
}
1247
l = k;
1248
while ( nams_c[l] != ' ' && nams_c[l] != ',' && nams_c[l] != '\0' ) {
1249
l++;
1250
}
1251
C_NEW_STRING( tmp, l - k, nams_c + k );
1252
RetypeBag( tmp, T_STRING+IMMUTABLE );
1253
SET_ELM_PLIST( nams_o, i, tmp );
1254
k = l;
1255
}
1256
1257
return nams_o;
1258
}
1259
1260
1261
/****************************************************************************
1262
**
1263
1264
*F * * * * * * * * * * * * * type and print function * * * * * * * * * * * *
1265
*/
1266
1267
/****************************************************************************
1268
**
1269
1270
*F TypeFunction( <func> ) . . . . . . . . . . . . . . . type of a function
1271
**
1272
** 'TypeFunction' returns the type of the function <func>.
1273
**
1274
** 'TypeFunction' is the function in 'TypeObjFuncs' for functions.
1275
*/
1276
Obj TYPE_FUNCTION;
1277
Obj TYPE_OPERATION;
1278
1279
Obj TypeFunction (
1280
Obj func )
1281
{
1282
return ( IS_OPERATION(func) ? TYPE_OPERATION : TYPE_FUNCTION );
1283
}
1284
1285
1286
1287
/****************************************************************************
1288
**
1289
*F PrintFunction( <func> ) . . . . . . . . . . . . . . . print a function
1290
**
1291
*/
1292
1293
Obj PrintOperation;
1294
1295
void PrintFunction (
1296
Obj func )
1297
{
1298
Int narg; /* number of arguments */
1299
Int nloc; /* number of locals */
1300
Obj oldLVars; /* terrible hack */
1301
UInt i; /* loop variable */
1302
UInt isvarg; /* does function have varargs? */
1303
1304
isvarg = 0;
1305
1306
if ( IS_OPERATION(func) ) {
1307
CALL_1ARGS( PrintOperation, func );
1308
return;
1309
}
1310
1311
/* print 'function (' */
1312
Pr("%5>function%< ( %>",0L,0L);
1313
1314
/* print the arguments */
1315
narg = NARG_FUNC(func);
1316
if (narg < 0) {
1317
isvarg = 1;
1318
narg = -narg;
1319
}
1320
1321
for ( i = 1; i <= narg; i++ ) {
1322
if ( NAMS_FUNC(func) != 0 )
1323
Pr( "%I", (Int)NAMI_FUNC( func, (Int)i ), 0L );
1324
else
1325
Pr( "<<arg-%d>>", (Int)i, 0L );
1326
if(isvarg && i == narg) {
1327
Pr("...", 0L, 0L);
1328
}
1329
if ( i != narg ) Pr("%<, %>",0L,0L);
1330
}
1331
Pr(" %<)",0L,0L);
1332
1333
Pr("\n",0L,0L);
1334
1335
/* print the locals */
1336
nloc = NLOC_FUNC(func);
1337
if ( nloc >= 1 ) {
1338
Pr("%>local ",0L,0L);
1339
for ( i = 1; i <= nloc; i++ ) {
1340
if ( NAMS_FUNC(func) != 0 )
1341
Pr( "%I", (Int)NAMI_FUNC( func, (Int)(narg+i) ), 0L );
1342
else
1343
Pr( "<<loc-%d>>", (Int)i, 0L );
1344
if ( i != nloc ) Pr("%<, %>",0L,0L);
1345
}
1346
Pr("%<;\n",0L,0L);
1347
}
1348
1349
/* print the body */
1350
if ( BODY_FUNC(func) == 0 || SIZE_OBJ(BODY_FUNC(func)) == NUMBER_HEADER_ITEMS_BODY*sizeof(Obj) ) {
1351
Pr("<<kernel or compiled code>>",0L,0L);
1352
}
1353
else {
1354
SWITCH_TO_NEW_LVARS( func, narg, NLOC_FUNC(func),
1355
oldLVars );
1356
PrintStat( FIRST_STAT_CURR_FUNC );
1357
SWITCH_TO_OLD_LVARS( oldLVars );
1358
}
1359
Pr("%4<\n",0L,0L);
1360
1361
/* print 'end' */
1362
Pr("end",0L,0L);
1363
}
1364
1365
1366
/****************************************************************************
1367
**
1368
*F FuncIS_FUNCTION( <self>, <func> ) . . . . . . . . . . . test for function
1369
**
1370
** 'FuncIS_FUNCTION' implements the internal function 'IsFunction'.
1371
**
1372
** 'IsFunction( <func> )'
1373
**
1374
** 'IsFunction' returns 'true' if <func> is a function and 'false'
1375
** otherwise.
1376
*/
1377
Obj IsFunctionFilt;
1378
1379
Obj FuncIS_FUNCTION (
1380
Obj self,
1381
Obj obj )
1382
{
1383
if ( TNUM_OBJ(obj) == T_FUNCTION ) {
1384
return True;
1385
}
1386
else if ( TNUM_OBJ(obj) < FIRST_EXTERNAL_TNUM ) {
1387
return False;
1388
}
1389
else {
1390
return DoFilter( self, obj );
1391
}
1392
}
1393
1394
1395
/****************************************************************************
1396
**
1397
*F FuncCALL_FUNC( <self>, <args> ) . . . . . . . . . . . . . call a function
1398
**
1399
** 'FuncCALL_FUNC' implements the internal function 'CallFunction'.
1400
**
1401
** 'CallFunction( <func>, <arg1>... )'
1402
**
1403
** 'CallFunction' calls the function <func> with the arguments <arg1>...,
1404
** i.e., it is equivalent to '<func>( <arg1>, <arg2>... )'.
1405
*/
1406
Obj CallFunctionOper;
1407
1408
1409
1410
Obj FuncCALL_FUNC (
1411
Obj self,
1412
Obj args )
1413
{
1414
Obj result; /* result */
1415
Obj func; /* function */
1416
Obj list2; /* list of arguments */
1417
Obj arg; /* one argument */
1418
UInt i; /* loop variable */
1419
1420
/* the first argument is the function */
1421
if ( LEN_LIST( args ) == 0 ) {
1422
func = ErrorReturnObj(
1423
"usage: CallFunction( <func>, <arg1>... )",
1424
0L, 0L,
1425
"you can replace function <func> via 'return <func>;'" );
1426
}
1427
else {
1428
func = ELMV_LIST( args, 1 );
1429
}
1430
1431
/* check that the first argument is a function */
1432
/*N 1996/06/26 mschoene this should be done by 'CALL_<i>ARGS' */
1433
while ( TNUM_OBJ( func ) != T_FUNCTION ) {
1434
func = ErrorReturnObj(
1435
"CallFunction: <func> must be a function",
1436
0L, 0L,
1437
"you can replace function <func> via 'return <func>;'" );
1438
}
1439
1440
/* call the function */
1441
if ( LEN_LIST(args) == 1 ) {
1442
result = CALL_0ARGS( func );
1443
}
1444
else if ( LEN_LIST(args) == 2 ) {
1445
result = CALL_1ARGS( func, ELMV_LIST(args,2) );
1446
}
1447
else if ( LEN_LIST(args) == 3 ) {
1448
result = CALL_2ARGS( func, ELMV_LIST(args,2), ELMV_LIST(args,3) );
1449
}
1450
else if ( LEN_LIST(args) == 4 ) {
1451
result = CALL_3ARGS( func, ELMV_LIST(args,2), ELMV_LIST(args,3),
1452
ELMV_LIST(args,4) );
1453
}
1454
else if ( LEN_LIST(args) == 5 ) {
1455
result = CALL_4ARGS( func, ELMV_LIST(args,2), ELMV_LIST(args,3),
1456
ELMV_LIST(args,4), ELMV_LIST(args,5) );
1457
}
1458
else if ( LEN_LIST(args) == 6 ) {
1459
result = CALL_5ARGS( func, ELMV_LIST(args,2), ELMV_LIST(args,3),
1460
ELMV_LIST(args,4), ELMV_LIST(args,5),
1461
ELMV_LIST(args,6) );
1462
}
1463
else if ( LEN_LIST(args) == 7 ) {
1464
result = CALL_6ARGS( func, ELMV_LIST(args,2), ELMV_LIST(args,3),
1465
ELMV_LIST(args,4), ELMV_LIST(args,5),
1466
ELMV_LIST(args,6), ELMV_LIST(args,7) );
1467
}
1468
else {
1469
list2 = NEW_PLIST( T_PLIST, LEN_LIST(args)-1 );
1470
SET_LEN_PLIST( list2, LEN_LIST(args)-1 );
1471
for ( i = 1; i <= LEN_LIST(args)-1; i++ ) {
1472
arg = ELMV_LIST( args, (Int)(i+1) );
1473
SET_ELM_PLIST( list2, i, arg );
1474
}
1475
result = CALL_XARGS( func, list2 );
1476
}
1477
1478
/* return the result */
1479
return result;
1480
}
1481
1482
1483
/****************************************************************************
1484
**
1485
*F FuncCALL_FUNC_LIST( <self>, <func>, <list> ) . . . . . . call a function
1486
**
1487
** 'FuncCALL_FUNC_LIST' implements the internal function 'CallFuncList'.
1488
**
1489
** 'CallFuncList( <func>, <list> )'
1490
**
1491
** 'CallFuncList' calls the function <func> with the arguments list <list>,
1492
** i.e., it is equivalent to '<func>( <list>[1], <list>[2]... )'.
1493
*/
1494
Obj CallFuncListOper;
1495
1496
Obj CallFuncList ( Obj func, Obj list )
1497
{
1498
Obj result; /* result */
1499
Obj list2; /* list of arguments */
1500
Obj arg; /* one argument */
1501
UInt i; /* loop variable */
1502
1503
1504
if (TNUM_OBJ(func) == T_FUNCTION) {
1505
1506
/* call the function */
1507
if ( LEN_LIST(list) == 0 ) {
1508
result = CALL_0ARGS( func );
1509
}
1510
else if ( LEN_LIST(list) == 1 ) {
1511
result = CALL_1ARGS( func, ELMV_LIST(list,1) );
1512
}
1513
else if ( LEN_LIST(list) == 2 ) {
1514
result = CALL_2ARGS( func, ELMV_LIST(list,1), ELMV_LIST(list,2) );
1515
}
1516
else if ( LEN_LIST(list) == 3 ) {
1517
result = CALL_3ARGS( func, ELMV_LIST(list,1), ELMV_LIST(list,2),
1518
ELMV_LIST(list,3) );
1519
}
1520
else if ( LEN_LIST(list) == 4 ) {
1521
result = CALL_4ARGS( func, ELMV_LIST(list,1), ELMV_LIST(list,2),
1522
ELMV_LIST(list,3), ELMV_LIST(list,4) );
1523
}
1524
else if ( LEN_LIST(list) == 5 ) {
1525
result = CALL_5ARGS( func, ELMV_LIST(list,1), ELMV_LIST(list,2),
1526
ELMV_LIST(list,3), ELMV_LIST(list,4),
1527
ELMV_LIST(list,5) );
1528
}
1529
else if ( LEN_LIST(list) == 6 ) {
1530
result = CALL_6ARGS( func, ELMV_LIST(list,1), ELMV_LIST(list,2),
1531
ELMV_LIST(list,3), ELMV_LIST(list,4),
1532
ELMV_LIST(list,5), ELMV_LIST(list,6) );
1533
}
1534
else {
1535
list2 = NEW_PLIST( T_PLIST, LEN_LIST(list) );
1536
SET_LEN_PLIST( list2, LEN_LIST(list) );
1537
for ( i = 1; i <= LEN_LIST(list); i++ ) {
1538
arg = ELMV_LIST( list, (Int)i );
1539
SET_ELM_PLIST( list2, i, arg );
1540
}
1541
result = CALL_XARGS( func, list2 );
1542
}
1543
} else {
1544
result = DoOperation2Args(CallFuncListOper, func, list);
1545
}
1546
/* return the result */
1547
return result;
1548
1549
}
1550
1551
Obj FuncCALL_FUNC_LIST (
1552
Obj self,
1553
Obj func,
1554
Obj list )
1555
{
1556
/* check that the second argument is a list */
1557
while ( ! IS_SMALL_LIST( list ) ) {
1558
list = ErrorReturnObj(
1559
"CallFuncList: <list> must be a small list",
1560
0L, 0L,
1561
"you can replace <list> via 'return <list>;'" );
1562
}
1563
return CallFuncList(func, list);
1564
}
1565
1566
/****************************************************************************
1567
**
1568
1569
*F * * * * * * * * * * * * * * * utility functions * * * * * * * * * * * * *
1570
*/
1571
1572
/****************************************************************************
1573
**
1574
*F FuncNAME_FUNC( <self>, <func> ) . . . . . . . . . . . name of a function
1575
*/
1576
Obj NAME_FUNC_Oper;
1577
Obj SET_NAME_FUNC_Oper;
1578
1579
Obj FuncNAME_FUNC (
1580
Obj self,
1581
Obj func )
1582
{
1583
Obj name;
1584
1585
if ( TNUM_OBJ(func) == T_FUNCTION ) {
1586
name = NAME_FUNC(func);
1587
if ( name == 0 ) {
1588
C_NEW_STRING_CONST(name, "unknown");
1589
RetypeBag(name, T_STRING+IMMUTABLE);
1590
NAME_FUNC(func) = name;
1591
CHANGED_BAG(func);
1592
}
1593
return name;
1594
}
1595
else {
1596
return DoOperation1Args( self, func );
1597
}
1598
}
1599
1600
Obj FuncSET_NAME_FUNC(
1601
Obj self,
1602
Obj func,
1603
Obj name )
1604
{
1605
while (!IsStringConv(name)) {
1606
name = ErrorReturnObj("SET_NAME_FUNC( <func>, <name> ): <name> must be a string, not a %s",
1607
(Int)TNAM_OBJ(name), 0, "YOu can return a new name to continue");
1608
}
1609
if (TNUM_OBJ(func) == T_FUNCTION ) {
1610
NAME_FUNC(func) = name;
1611
CHANGED_BAG(func);
1612
} else
1613
DoOperation2Args(SET_NAME_FUNC_Oper, func, name);
1614
return (Obj) 0;
1615
}
1616
1617
1618
/****************************************************************************
1619
**
1620
*F FuncNARG_FUNC( <self>, <func> ) . . . . number of arguments of a function
1621
*/
1622
Obj NARG_FUNC_Oper;
1623
1624
Obj FuncNARG_FUNC (
1625
Obj self,
1626
Obj func )
1627
{
1628
if ( TNUM_OBJ(func) == T_FUNCTION ) {
1629
return INTOBJ_INT( NARG_FUNC(func) );
1630
}
1631
else {
1632
return DoOperation1Args( self, func );
1633
}
1634
}
1635
1636
1637
/****************************************************************************
1638
**
1639
*F FuncNAMS_FUNC( <self>, <func> ) . . . . names of local vars of a function
1640
*/
1641
Obj NAMS_FUNC_Oper;
1642
1643
Obj FuncNAMS_FUNC (
1644
Obj self,
1645
Obj func )
1646
{
1647
Obj nams;
1648
if ( TNUM_OBJ(func) == T_FUNCTION ) {
1649
nams = NAMS_FUNC(func);
1650
return (nams != (Obj)0) ? nams : Fail;
1651
}
1652
else {
1653
return DoOperation1Args( self, func );
1654
}
1655
}
1656
1657
1658
/****************************************************************************
1659
**
1660
*F FuncPROF_FUNC( <self>, <func> ) . . . . . . profiling info of a function
1661
*/
1662
Obj PROF_FUNC_Oper;
1663
1664
Obj FuncPROF_FUNC (
1665
Obj self,
1666
Obj func )
1667
{
1668
Obj prof;
1669
1670
if ( TNUM_OBJ(func) == T_FUNCTION ) {
1671
prof = PROF_FUNC(func);
1672
if ( TNUM_OBJ(prof) == T_FUNCTION ) {
1673
return PROF_FUNC(prof);
1674
} else {
1675
return prof;
1676
}
1677
}
1678
else {
1679
return DoOperation1Args( self, func );
1680
}
1681
}
1682
1683
1684
/****************************************************************************
1685
**
1686
1687
*F FuncCLEAR_PROFILE_FUNC( <self>, <func> ) . . . . . . . . . clear profile
1688
*/
1689
Obj FuncCLEAR_PROFILE_FUNC(
1690
Obj self,
1691
Obj func )
1692
{
1693
Obj prof;
1694
1695
/* check the argument */
1696
if ( TNUM_OBJ(func) != T_FUNCTION ) {
1697
ErrorQuit( "<func> must be a function", 0L, 0L );
1698
return 0;
1699
}
1700
1701
/* clear profile info */
1702
prof = PROF_FUNC(func);
1703
if ( prof == 0 ) {
1704
ErrorQuit( "<func> has corrupted profile info", 0L, 0L );
1705
return 0;
1706
}
1707
if ( TNUM_OBJ(prof) == T_FUNCTION ) {
1708
prof = PROF_FUNC(prof);
1709
}
1710
if ( prof == 0 ) {
1711
ErrorQuit( "<func> has corrupted profile info", 0L, 0L );
1712
return 0;
1713
}
1714
SET_COUNT_PROF( prof, 0 );
1715
SET_TIME_WITH_PROF( prof, 0 );
1716
SET_TIME_WOUT_PROF( prof, 0 );
1717
SET_STOR_WITH_PROF( prof, 0 );
1718
SET_STOR_WOUT_PROF( prof, 0 );
1719
1720
return (Obj)0;
1721
}
1722
1723
1724
/****************************************************************************
1725
**
1726
*F FuncPROFILE_FUNC( <self>, <func> ) . . . . . . . . . . . . start profile
1727
*/
1728
Obj FuncPROFILE_FUNC(
1729
Obj self,
1730
Obj func )
1731
{
1732
Obj prof;
1733
Obj copy;
1734
1735
/* check the argument */
1736
if ( TNUM_OBJ(func) != T_FUNCTION ) {
1737
ErrorQuit( "<func> must be a function", 0L, 0L );
1738
return 0;
1739
}
1740
/* uninstall trace handler */
1741
ChangeDoOperations( func, 0 );
1742
1743
/* install profiling */
1744
prof = PROF_FUNC(func);
1745
1746
/* install new handlers */
1747
if ( TNUM_OBJ(prof) != T_FUNCTION ) {
1748
copy = NewBag( TNUM_OBJ(func), SIZE_OBJ(func) );
1749
HDLR_FUNC(copy,0) = HDLR_FUNC(func,0);
1750
HDLR_FUNC(copy,1) = HDLR_FUNC(func,1);
1751
HDLR_FUNC(copy,2) = HDLR_FUNC(func,2);
1752
HDLR_FUNC(copy,3) = HDLR_FUNC(func,3);
1753
HDLR_FUNC(copy,4) = HDLR_FUNC(func,4);
1754
HDLR_FUNC(copy,5) = HDLR_FUNC(func,5);
1755
HDLR_FUNC(copy,6) = HDLR_FUNC(func,6);
1756
HDLR_FUNC(copy,7) = HDLR_FUNC(func,7);
1757
NAME_FUNC(copy) = NAME_FUNC(func);
1758
NARG_FUNC(copy) = NARG_FUNC(func);
1759
NAMS_FUNC(copy) = NAMS_FUNC(func);
1760
PROF_FUNC(copy) = PROF_FUNC(func);
1761
HDLR_FUNC(func,0) = DoProf0args;
1762
HDLR_FUNC(func,1) = DoProf1args;
1763
HDLR_FUNC(func,2) = DoProf2args;
1764
HDLR_FUNC(func,3) = DoProf3args;
1765
HDLR_FUNC(func,4) = DoProf4args;
1766
HDLR_FUNC(func,5) = DoProf5args;
1767
HDLR_FUNC(func,6) = DoProf6args;
1768
HDLR_FUNC(func,7) = DoProfXargs;
1769
PROF_FUNC(func) = copy;
1770
CHANGED_BAG(func);
1771
}
1772
1773
return (Obj)0;
1774
}
1775
1776
1777
/****************************************************************************
1778
**
1779
*F FuncIS_PROFILED_FUNC( <self>, <func> ) . . check if function is profiled
1780
*/
1781
Obj FuncIS_PROFILED_FUNC(
1782
Obj self,
1783
Obj func )
1784
{
1785
/* check the argument */
1786
if ( TNUM_OBJ(func) != T_FUNCTION ) {
1787
ErrorQuit( "<func> must be a function", 0L, 0L );
1788
return 0;
1789
}
1790
return ( TNUM_OBJ(PROF_FUNC(func)) != T_FUNCTION ) ? False : True;
1791
}
1792
1793
Obj FuncFILENAME_FUNC(Obj self, Obj func) {
1794
1795
/* check the argument */
1796
if ( TNUM_OBJ(func) != T_FUNCTION ) {
1797
ErrorQuit( "<func> must be a function", 0L, 0L );
1798
return 0;
1799
}
1800
1801
if (BODY_FUNC(func)) {
1802
Obj fn = FILENAME_BODY(BODY_FUNC(func));
1803
#ifndef WARD_ENABLED
1804
if (fn) {
1805
return fn;
1806
}
1807
#endif
1808
}
1809
return Fail;
1810
}
1811
1812
Obj FuncSTARTLINE_FUNC(Obj self, Obj func) {
1813
1814
/* check the argument */
1815
if ( TNUM_OBJ(func) != T_FUNCTION ) {
1816
ErrorQuit( "<func> must be a function", 0L, 0L );
1817
return 0;
1818
}
1819
1820
if (BODY_FUNC(func)) {
1821
Obj sl = STARTLINE_BODY(BODY_FUNC(func));
1822
if (sl)
1823
return sl;
1824
}
1825
return Fail;
1826
}
1827
1828
Obj FuncENDLINE_FUNC(Obj self, Obj func) {
1829
1830
/* check the argument */
1831
if ( TNUM_OBJ(func) != T_FUNCTION ) {
1832
ErrorQuit( "<func> must be a function", 0L, 0L );
1833
return 0;
1834
}
1835
1836
if (BODY_FUNC(func)) {
1837
Obj el = ENDLINE_BODY(BODY_FUNC(func));
1838
if (el)
1839
return el;
1840
}
1841
return Fail;
1842
}
1843
1844
1845
/****************************************************************************
1846
**
1847
*F FuncUNPROFILE_FUNC( <self>, <func> ) . . . . . . . . . . . stop profile
1848
*/
1849
Obj FuncUNPROFILE_FUNC(
1850
Obj self,
1851
Obj func )
1852
{
1853
Obj prof;
1854
1855
/* check the argument */
1856
if ( TNUM_OBJ(func) != T_FUNCTION ) {
1857
ErrorQuit( "<func> must be a function", 0L, 0L );
1858
return 0;
1859
}
1860
1861
/* uninstall trace handler */
1862
ChangeDoOperations( func, 0 );
1863
1864
/* profiling is active, restore handlers */
1865
prof = PROF_FUNC(func);
1866
if ( TNUM_OBJ(prof) == T_FUNCTION ) {
1867
HDLR_FUNC(func,0) = HDLR_FUNC(prof,0);
1868
HDLR_FUNC(func,1) = HDLR_FUNC(prof,1);
1869
HDLR_FUNC(func,2) = HDLR_FUNC(prof,2);
1870
HDLR_FUNC(func,3) = HDLR_FUNC(prof,3);
1871
HDLR_FUNC(func,4) = HDLR_FUNC(prof,4);
1872
HDLR_FUNC(func,5) = HDLR_FUNC(prof,5);
1873
HDLR_FUNC(func,6) = HDLR_FUNC(prof,6);
1874
HDLR_FUNC(func,7) = HDLR_FUNC(prof,7);
1875
PROF_FUNC(func) = PROF_FUNC(prof);
1876
CHANGED_BAG(func);
1877
}
1878
1879
return (Obj)0;
1880
}
1881
1882
Obj FuncIsKernelFunction(Obj self, Obj func) {
1883
if (!IS_FUNC(func))
1884
return Fail;
1885
else return (BODY_FUNC(func) == 0 || SIZE_OBJ(BODY_FUNC(func)) == 0) ? True : False;
1886
}
1887
1888
Obj FuncHandlerCookieOfFunction(Obj self, Obj func)
1889
{
1890
Int narg;
1891
ObjFunc hdlr;
1892
const Char *cookie;
1893
Obj cookieStr;
1894
if (!IS_FUNC(func))
1895
return Fail;
1896
narg = NARG_FUNC(func);
1897
if (narg == -1)
1898
narg = 7;
1899
hdlr = HDLR_FUNC(func, narg);
1900
cookie = CookieOfHandler(hdlr);
1901
C_NEW_STRING_DYN(cookieStr, cookie);
1902
return cookieStr;
1903
}
1904
1905
/****************************************************************************
1906
**
1907
1908
*F SaveFunction( <func> ) . . . . . . . . . . . . . . . . . save a function
1909
**
1910
*/
1911
void SaveFunction ( Obj func )
1912
{
1913
UInt i;
1914
for (i = 0; i <= 7; i++)
1915
SaveHandler(HDLR_FUNC(func,i));
1916
SaveSubObj(NAME_FUNC(func));
1917
SaveUInt(NARG_FUNC(func));
1918
SaveSubObj(NAMS_FUNC(func));
1919
SaveSubObj(PROF_FUNC(func));
1920
SaveUInt(NLOC_FUNC(func));
1921
SaveSubObj(BODY_FUNC(func));
1922
SaveSubObj(ENVI_FUNC(func));
1923
SaveSubObj(FEXS_FUNC(func));
1924
if (SIZE_OBJ(func) != SIZE_FUNC)
1925
SaveOperationExtras( func );
1926
}
1927
1928
/****************************************************************************
1929
**
1930
*F LoadFunction( <func> ) . . . . . . . . . . . . . . . . . load a function
1931
**
1932
*/
1933
void LoadFunction ( Obj func )
1934
{
1935
UInt i;
1936
for (i = 0; i <= 7; i++)
1937
HDLR_FUNC(func,i) = LoadHandler();
1938
NAME_FUNC(func) = LoadSubObj();
1939
NARG_FUNC(func) = LoadUInt();
1940
NAMS_FUNC(func) = LoadSubObj();
1941
PROF_FUNC(func) = LoadSubObj();
1942
NLOC_FUNC(func) = LoadUInt();
1943
BODY_FUNC(func) = LoadSubObj();
1944
ENVI_FUNC(func) = LoadSubObj();
1945
FEXS_FUNC(func) = LoadSubObj();
1946
if (SIZE_OBJ(func) != SIZE_FUNC)
1947
LoadOperationExtras( func );
1948
}
1949
1950
1951
/****************************************************************************
1952
**
1953
1954
*F * * * * * * * * * * * * * initialize package * * * * * * * * * * * * * * *
1955
*/
1956
1957
/****************************************************************************
1958
**
1959
1960
*V GVarFilts . . . . . . . . . . . . . . . . . . . list of filters to export
1961
*/
1962
static StructGVarFilt GVarFilts [] = {
1963
1964
{ "IS_FUNCTION", "obj", &IsFunctionFilt,
1965
FuncIS_FUNCTION, "src/calls.c:IS_FUNCTION" },
1966
1967
{ 0 }
1968
1969
};
1970
1971
1972
/****************************************************************************
1973
**
1974
*V GVarOpers . . . . . . . . . . . . . . . . . list of operations to export
1975
*/
1976
static StructGVarOper GVarOpers [] = {
1977
1978
{ "CALL_FUNC", -1, "args", &CallFunctionOper,
1979
FuncCALL_FUNC, "src/calls.c:CALL_FUNC" },
1980
1981
{ "CALL_FUNC_LIST", 2, "func, list", &CallFuncListOper,
1982
FuncCALL_FUNC_LIST, "src/calls.c:CALL_FUNC_LIST" },
1983
1984
{ "NAME_FUNC", 1, "func", &NAME_FUNC_Oper,
1985
FuncNAME_FUNC, "src/calls.c:NAME_FUNC" },
1986
1987
{ "SET_NAME_FUNC", 2, "func, name", &SET_NAME_FUNC_Oper,
1988
FuncSET_NAME_FUNC, "src/calls.c:SET_NAME_FUNC" },
1989
1990
{ "NARG_FUNC", 1, "func", &NARG_FUNC_Oper,
1991
FuncNARG_FUNC, "src/calls.c:NARG_FUNC" },
1992
1993
{ "NAMS_FUNC", 1, "func", &NAMS_FUNC_Oper,
1994
FuncNAMS_FUNC, "src/calls.c:NAMS_FUNC" },
1995
1996
{ "PROF_FUNC", 1, "func", &PROF_FUNC_Oper,
1997
FuncPROF_FUNC, "src/calls.c:PROF_FUNC" },
1998
1999
2000
{ 0 }
2001
2002
};
2003
2004
2005
/****************************************************************************
2006
**
2007
*V GVarFuncs . . . . . . . . . . . . . . . . . . list of functions to export
2008
*/
2009
static StructGVarFunc GVarFuncs [] = {
2010
2011
{ "CLEAR_PROFILE_FUNC", 1, "func",
2012
FuncCLEAR_PROFILE_FUNC, "src/calls.c:CLEAR_PROFILE_FUNC" },
2013
2014
{ "IS_PROFILED_FUNC", 1, "func",
2015
FuncIS_PROFILED_FUNC, "src/calls.c:IS_PROFILED_FUNC" },
2016
2017
{ "PROFILE_FUNC", 1, "func",
2018
FuncPROFILE_FUNC, "src/calls.c:PROFILE_FUNC" },
2019
2020
{ "UNPROFILE_FUNC", 1, "func",
2021
FuncUNPROFILE_FUNC, "src/calls.c:UNPROFILE_FUNC" },
2022
2023
{ "IsKernelFunction", 1, "func",
2024
FuncIsKernelFunction, "src/calls.c:IsKernelFunction" },
2025
2026
{ "HandlerCookieOfFunction", 1, "func",
2027
FuncHandlerCookieOfFunction, "src/calls.c:HandlerCookieOfFunction" },
2028
2029
{ "FILENAME_FUNC", 1, "func",
2030
FuncFILENAME_FUNC, "src/calls.c:FILENAME_FUNC" },
2031
2032
{ "STARTLINE_FUNC", 1, "func",
2033
FuncSTARTLINE_FUNC, "src/calls.c:STARTLINE_FUNC" },
2034
2035
{ "ENDLINE_FUNC", 1, "func",
2036
FuncENDLINE_FUNC, "src/calls.c:ENDLINE_FUNC" },
2037
{ 0 }
2038
2039
};
2040
2041
2042
/****************************************************************************
2043
**
2044
2045
*F InitKernel( <module> ) . . . . . . . . initialise kernel data structures
2046
*/
2047
static Int InitKernel (
2048
StructInitInfo * module )
2049
{
2050
2051
/* install the marking functions */
2052
InfoBags[ T_FUNCTION ].name = "function";
2053
InitMarkFuncBags( T_FUNCTION , MarkAllSubBags );
2054
2055
/* install the type functions */
2056
ImportGVarFromLibrary( "TYPE_FUNCTION", &TYPE_FUNCTION );
2057
ImportGVarFromLibrary( "TYPE_OPERATION", &TYPE_OPERATION );
2058
TypeObjFuncs[ T_FUNCTION ] = TypeFunction;
2059
2060
/* init filters and functions */
2061
InitHdlrFiltsFromTable( GVarFilts );
2062
InitHdlrOpersFromTable( GVarOpers );
2063
InitHdlrFuncsFromTable( GVarFuncs );
2064
2065
/* and the saving function */
2066
SaveObjFuncs[ T_FUNCTION ] = SaveFunction;
2067
LoadObjFuncs[ T_FUNCTION ] = LoadFunction;
2068
2069
/* install the printer */
2070
InitFopyGVar( "PRINT_OPERATION", &PrintOperation );
2071
PrintObjFuncs[ T_FUNCTION ] = PrintFunction;
2072
2073
2074
/* initialise all 'Do<Something><N>args' handlers, give the most */
2075
/* common ones short cookies to save space in in the saved workspace */
2076
InitHandlerFunc( DoFail0args, "f0" );
2077
InitHandlerFunc( DoFail1args, "f1" );
2078
InitHandlerFunc( DoFail2args, "f2" );
2079
InitHandlerFunc( DoFail3args, "f3" );
2080
InitHandlerFunc( DoFail4args, "f4" );
2081
InitHandlerFunc( DoFail5args, "f5" );
2082
InitHandlerFunc( DoFail6args, "f6" );
2083
InitHandlerFunc( DoFailXargs, "f7" );
2084
2085
InitHandlerFunc( DoWrap0args, "w0" );
2086
InitHandlerFunc( DoWrap1args, "w1" );
2087
InitHandlerFunc( DoWrap2args, "w2" );
2088
InitHandlerFunc( DoWrap3args, "w3" );
2089
InitHandlerFunc( DoWrap4args, "w4" );
2090
InitHandlerFunc( DoWrap5args, "w5" );
2091
InitHandlerFunc( DoWrap6args, "w6" );
2092
2093
InitHandlerFunc( DoProf0args, "p0" );
2094
InitHandlerFunc( DoProf1args, "p1" );
2095
InitHandlerFunc( DoProf2args, "p2" );
2096
InitHandlerFunc( DoProf3args, "p3" );
2097
InitHandlerFunc( DoProf4args, "p4" );
2098
InitHandlerFunc( DoProf5args, "p5" );
2099
InitHandlerFunc( DoProf6args, "p6" );
2100
InitHandlerFunc( DoProfXargs, "pX" );
2101
2102
/* return success */
2103
return 0;
2104
}
2105
2106
2107
/****************************************************************************
2108
**
2109
*F InitLibrary( <module> ) . . . . . . . initialise library data structures
2110
*/
2111
static Int InitLibrary (
2112
StructInitInfo * module ){
2113
/* init filters and functions */
2114
InitGVarFiltsFromTable( GVarFilts );
2115
InitGVarOpersFromTable( GVarOpers );
2116
InitGVarFuncsFromTable( GVarFuncs );
2117
2118
/* return success */
2119
return 0;
2120
}
2121
2122
2123
/****************************************************************************
2124
**
2125
*F InitInfoCalls() . . . . . . . . . . . . . . . . . table of init functions
2126
*/
2127
static StructInitInfo module = {
2128
MODULE_BUILTIN, /* type */
2129
"calls", /* name */
2130
0, /* revision entry of c file */
2131
0, /* revision entry of h file */
2132
0, /* version */
2133
0, /* crc */
2134
InitKernel, /* initKernel */
2135
InitLibrary, /* initLibrary */
2136
0, /* checkInit */
2137
0, /* preSave */
2138
0, /* postSave */
2139
0 /* postRestore */
2140
};
2141
2142
StructInitInfo * InitInfoCalls ( void )
2143
{
2144
return &module;
2145
}
2146
2147
2148
/****************************************************************************
2149
**
2150
2151
*E calls.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . ends here
2152
*/
2153
2154