Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
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
Project: cocalc-sagemath-dev-slelievre
Views: 418346/****************************************************************************1**2*W calls.h GAP source Martin Schönert3**4**5*Y Copyright (C) 1996, Lehrstuhl D für Mathematik, RWTH Aachen, Germany6*Y (C) 1998 School Math and Comp. Sci., University of St Andrews, Scotland7*Y Copyright (C) 2002 The GAP Group8**9** This file declares the functions of the generic function call mechanism10** package.11**12** This package defines the *call mechanism* through which one GAP function,13** named the *caller*, can temporarily transfer control to another function,14** named the *callee*.15**16** There are *compiled functions* and *interpreted functions*. Thus there17** are four possible pairings of caller and callee.18**19** If the caller is compiled, then the call comes directly from the caller.20** If it is interpreted, then the call comes from one of the functions21** 'EvalFunccall<i>args' that implement evaluation of function calls.22**23** If the callee is compiled, then the call goes directly to the callee.24** If it is interpreted, then the call goes to one of the handlers25** 'DoExecFunc<i>args' that implement execution of function bodies.26**27** The call mechanism makes it in any case unneccessary for the calling code28** to know whether the callee is a compiled or an interpreted function.29** Likewise the called code need not know, actually cannot know, whether the30** caller is a compiled or an interpreted function.31**32** Also the call mechanism checks that the number of arguments passed by the33** caller is the same as the number of arguments expected by the callee, or34** it collects the arguments in a list if the callee allows a variable35** number of arguments.36**37** Finally the call mechanism profiles all functions if requested.38**39** All this has very little overhead. In the case of one compiled function40** calling another compiled function, which expects fewer than 4 arguments,41** with no profiling, the overhead is only a couple of instructions.42*/4344#ifndef GAP_CALLS_H45#define GAP_CALLS_H464748/****************************************************************************49**5051*T ObjFunc . . . . . . . . . . . . . . . . type of function returning object52**53** 'ObjFunc' is the type of a function returning an object.54*/55typedef Obj (* ObjFunc) (/*arguments*/);5657typedef Obj (* ObjFunc_0ARGS) (Obj self);58typedef Obj (* ObjFunc_1ARGS) (Obj self, Obj a1);59typedef Obj (* ObjFunc_2ARGS) (Obj self, Obj a1, Obj a2);60typedef Obj (* ObjFunc_3ARGS) (Obj self, Obj a1, Obj a2, Obj a3);61typedef Obj (* ObjFunc_4ARGS) (Obj self, Obj a1, Obj a2, Obj a3, Obj a4);62typedef Obj (* ObjFunc_5ARGS) (Obj self, Obj a1, Obj a2, Obj a3, Obj a4, Obj a5);63typedef Obj (* ObjFunc_6ARGS) (Obj self, Obj a1, Obj a2, Obj a3, Obj a4, Obj a5, Obj a6);646566/****************************************************************************67**68*F HDLR_FUNC(<func>,<i>) . . . . . . . . . <i>-th call handler of a function69*F NAME_FUNC(<func>) . . . . . . . . . . . . . . . . . . name of a function70*F NARG_FUNC(<func>) . . . . . . . . . . . number of arguments of a function71*F NAMS_FUNC(<func>) . . . . . . . . names of local variables of a function72*F NAMI_FUNC(<func>) . . . . . . name of <i>-th local variable of a function73*F PROF_FUNC(<func>) . . . . . . . . profiling information bag of a function74*F NLOC_FUNC(<func>) . . . . . . . . . . . . number of locals of a function75*F BODY_FUNC(<func>) . . . . . . . . . . . . . . . . . . body of a function76*F ENVI_FUNC(<func>) . . . . . . . . . . . . . . . environment of a function77*F FEXS_FUNC(<func>) . . . . . . . . . . . . func. expr. list of a function78*V SIZE_FUNC . . . . . . . . . . . . . . . . . size of the bag of a function79**80** These macros make it possible to access the various components of a81** function.82**83** 'HDLR_FUNC(<func>,<i>)' is the <i>-th handler of the function <func>.84**85** 'NAME_FUNC(<func>)' is the name of the function.86**87** 'NARG_FUNC(<func>)' is the number of arguments (-1 if <func> accepts a88** variable number of arguments).89**90** 'NAMS_FUNC(<func>)' is the list of the names of the local variables,91**92** 'NAMI_FUNC(<func>,<i>)' is the name of the <i>-th local variable.93**94** 'PROF_FUNC(<func>)' is the profiling information bag.95**96** 'NLOC_FUNC(<func>)' is the number of local variables of the interpreted97** function <func>.98**99** 'BODY_FUNC(<func>)' is the body.100**101** 'ENVI_FUNC(<func>)' is the environment (i.e., the local variables bag102** that was current when <func> was created).103**104** 'FEXS_FUNC(<func>)' is the function expressions list (i.e., the list of105** the function expressions of the functions defined inside of <func>).106**107*/108#define HDLR_FUNC(func,i) (* (ObjFunc*) (ADDR_OBJ(func) + 0 +(i)) )109#define NAME_FUNC(func) (* (ADDR_OBJ(func) + 8 ) )110#define NARG_FUNC(func) (* (Int*) (ADDR_OBJ(func) + 9 ) )111#define NAMS_FUNC(func) (* (ADDR_OBJ(func) +10 ) )112#define NAMI_FUNC(func,i) ((Char *)CHARS_STRING(ELM_LIST(NAMS_FUNC(func),i)))113#define PROF_FUNC(func) (* (ADDR_OBJ(func) +11 ) )114#define NLOC_FUNC(func) (* (UInt*) (ADDR_OBJ(func) +12 ) )115#define BODY_FUNC(func) (* (ADDR_OBJ(func) +13 ) )116#define ENVI_FUNC(func) (* (ADDR_OBJ(func) +14 ) )117#define FEXS_FUNC(func) (* (ADDR_OBJ(func) +15 ) )118#define SIZE_FUNC (16*sizeof(Bag))119120#define HDLR_0ARGS(func) ((ObjFunc_0ARGS)HDLR_FUNC(func,0))121#define HDLR_1ARGS(func) ((ObjFunc_1ARGS)HDLR_FUNC(func,1))122#define HDLR_2ARGS(func) ((ObjFunc_2ARGS)HDLR_FUNC(func,2))123#define HDLR_3ARGS(func) ((ObjFunc_3ARGS)HDLR_FUNC(func,3))124#define HDLR_4ARGS(func) ((ObjFunc_4ARGS)HDLR_FUNC(func,4))125#define HDLR_5ARGS(func) ((ObjFunc_5ARGS)HDLR_FUNC(func,5))126#define HDLR_6ARGS(func) ((ObjFunc_6ARGS)HDLR_FUNC(func,6))127#define HDLR_XARGS(func) ((ObjFunc_1ARGS)HDLR_FUNC(func,7))128129extern Obj NargError(Obj func, Int actual);130131/****************************************************************************132**133*F IS_FUNC( <obj> ) . . . . . . . . . . . . . check if object is a function134*/135#define IS_FUNC(obj) (TNUM_OBJ(obj) == T_FUNCTION)136137138/****************************************************************************139**140141*F CALL_0ARGS(<func>) . . . . . . . . . call a function with 0 arguments142*F CALL_1ARGS(<func>,<arg1>) . . . . . . call a function with 1 arguments143*F CALL_2ARGS(<func>,<arg1>...) . . . . call a function with 2 arguments144*F CALL_3ARGS(<func>,<arg1>...) . . . . call a function with 3 arguments145*F CALL_4ARGS(<func>,<arg1>...) . . . . call a function with 4 arguments146*F CALL_5ARGS(<func>,<arg1>...) . . . . call a function with 5 arguments147*F CALL_6ARGS(<func>,<arg1>...) . . . . call a function with 6 arguments148*F CALL_XARGS(<func>,<args>) . . . . . . call a function with more arguments149**150** 'CALL_<i>ARGS' passes control to the function <func>, which must be a151** function object ('T_FUNCTION'). It returns the return value of <func>.152** 'CALL_0ARGS' is for calls passing no arguments, 'CALL_1ARGS' for calls153** passing one argument, and so on. 'CALL_XARGS' is for calls passing more154** than 5 arguments, where the arguments must be collected in a plain list,155** and this plain list must then be passed.156**157** 'CALL_<i>ARGS' can be used independently of whether the called function158** is a compiled or interpreted function. It checks that the number of159** passed arguments is the same as the number of arguments expected by the160** callee, or it collects the arguments in a list if the callee allows a161** variable number of arguments.162*/163#define CALL_0ARGS(f) HDLR_0ARGS(f)(f)164#define CALL_1ARGS(f,a1) HDLR_1ARGS(f)(f,a1)165#define CALL_2ARGS(f,a1,a2) HDLR_2ARGS(f)(f,a1,a2)166#define CALL_3ARGS(f,a1,a2,a3) HDLR_3ARGS(f)(f,a1,a2,a3)167#define CALL_4ARGS(f,a1,a2,a3,a4) HDLR_4ARGS(f)(f,a1,a2,a3,a4)168#define CALL_5ARGS(f,a1,a2,a3,a4,a5) HDLR_5ARGS(f)(f,a1,a2,a3,a4,a5)169#define CALL_6ARGS(f,a1,a2,a3,a4,a5,a6) HDLR_6ARGS(f)(f,a1,a2,a3,a4,a5,a6)170#define CALL_XARGS(f,as) HDLR_XARGS(f)(f,as)171172173/****************************************************************************174**175176*F CALL_0ARGS_PROF( <func>, <arg1> ) . . . . . call a prof func with 0 args177*F CALL_1ARGS_PROF( <func>, <arg1>, ... ) . . call a prof func with 1 args178*F CALL_2ARGS_PROF( <func>, <arg1>, ... ) . . call a prof func with 2 args179*F CALL_3ARGS_PROF( <func>, <arg1>, ... ) . . call a prof func with 3 args180*F CALL_4ARGS_PROF( <func>, <arg1>, ... ) . . call a prof func with 4 args181*F CALL_5ARGS_PROF( <func>, <arg1>, ... ) . . call a prof func with 5 args182*F CALL_6ARGS_PROF( <func>, <arg1>, ... ) . . call a prof func with 6 args183*F CALL_XARGS_PROF( <func>, <arg1>, ... ) . . call a prof func with X args184**185** 'CALL_<i>ARGS_PROF' is used in the profile handler 'DoProf<i>args' to186** call the real handler stored in the profiling information of the187** function.188*/189#define CALL_0ARGS_PROF(f) \190HDLR_0ARGS(PROF_FUNC(f))(f)191192#define CALL_1ARGS_PROF(f,a1) \193HDLR_1ARGS(PROF_FUNC(f))(f,a1)194195#define CALL_2ARGS_PROF(f,a1,a2) \196HDLR_2ARGS(PROF_FUNC(f))(f,a1,a2)197198#define CALL_3ARGS_PROF(f,a1,a2,a3) \199HDLR_3ARGS(PROF_FUNC(f))(f,a1,a2,a3)200201#define CALL_4ARGS_PROF(f,a1,a2,a3,a4) \202HDLR_4ARGS(PROF_FUNC(f))(f,a1,a2,a3,a4)203204#define CALL_5ARGS_PROF(f,a1,a2,a3,a4,a5) \205HDLR_5ARGS(PROF_FUNC(f))(f,a1,a2,a3,a4,a5)206207#define CALL_6ARGS_PROF(f,a1,a2,a3,a4,a5,a6) \208HDLR_6ARGS(PROF_FUNC(f))(f,a1,a2,a3,a4,a5,a6)209210#define CALL_XARGS_PROF(f,as) \211HDLR_XARGS(PROF_FUNC(f))(f,as)212213214/****************************************************************************215**216217*F COUNT_PROF( <prof> ) . . . . . . . . number of invocations of a function218*F TIME_WITH_PROF( <prof> ) . . . . . . time with children in a function219*F TIME_WOUT_PROF( <prof> ) . . . . . . time without children in a function220*F STOR_WITH_PROF( <prof> ) . . . . storage with children in a function221*F STOR_WOUT_PROF( <prof> ) . . . . storage without children in a function222*V LEN_PROF . . . . . . . . . . . length of a profiling bag for a function223**224** With each function we associate two time measurements. First the *time225** spent by this function without its children*, i.e., the amount of time226** during which this function was active. Second the *time spent by this227** function with its children*, i.e., the amount of time during which this228** function was either active or suspended.229**230** Likewise with each function we associate the two storage measurements,231** the storage spent by this function without its children and the storage232** spent by this function with its children.233**234** These macros make it possible to access the various components of a235** profiling information bag <prof> for a function <func>.236**237** 'COUNT_PROF(<prof>)' is the number of calls to the function <func>.238** 'TIME_WITH_PROF(<prof>) is the time spent while the function <func> was239** either active or suspended. 'TIME_WOUT_PROF(<prof>)' is the time spent240** while the function <func> was active. 'STOR_WITH_PROF(<prof>)' is the241** amount of storage allocated while the function <func> was active or242** suspended. 'STOR_WOUT_PROF(<prof>)' is the amount of storage allocated243** while the function <func> was active. 'LEN_PROF' is the length of a244** profiling information bag.245*/246#define COUNT_PROF(prof) (INT_INTOBJ(ELM_PLIST(prof,1)))247#define TIME_WITH_PROF(prof) (INT_INTOBJ(ELM_PLIST(prof,2)))248#define TIME_WOUT_PROF(prof) (INT_INTOBJ(ELM_PLIST(prof,3)))249#define STOR_WITH_PROF(prof) (INT_INTOBJ(ELM_PLIST(prof,4)))250#define STOR_WOUT_PROF(prof) (INT_INTOBJ(ELM_PLIST(prof,5)))251252#define SET_COUNT_PROF(prof,n) SET_ELM_PLIST(prof,1,INTOBJ_INT(n))253#define SET_TIME_WITH_PROF(prof,n) SET_ELM_PLIST(prof,2,INTOBJ_INT(n))254#define SET_TIME_WOUT_PROF(prof,n) SET_ELM_PLIST(prof,3,INTOBJ_INT(n))255#define SET_STOR_WITH_PROF(prof,n) SET_ELM_PLIST(prof,4,INTOBJ_INT(n))256#define SET_STOR_WOUT_PROF(prof,n) SET_ELM_PLIST(prof,5,INTOBJ_INT(n))257258#define LEN_PROF 5259260261/****************************************************************************262**263264*F FuncFILENAME_FUNC(Obj self, Obj func) . . . . . . . filename of function265*F FuncSTARTLINE_FUNC(Obj self, Obj func) . . . . . start line of function266*F FuncENDLINE_FUNC(Obj self, Obj func) . . . . . . . end line of function267**268** These functions, usually exported to GAP, get information about GAP269** functions */270Obj FuncFILENAME_FUNC(Obj self, Obj func);271Obj FuncSTARTLINE_FUNC(Obj self, Obj func);272Obj FuncENDLINE_FUNC(Obj self, Obj func);273274/****************************************************************************275**276277*F * * * * * * * * * * * * * create a new function * * * * * * * * * * * * *278*/279280/****************************************************************************281**282283*F InitHandlerFunc( <handler>, <cookie> ) . . . . . . . . register a handler284**285** Every handler should be registered (once) before it is installed in any286** function bag. This is needed so that it can be identified when loading a287** saved workspace. <cookie> should be a unique C string, identifying the288** handler289*/290291extern void InitHandlerRegistration( void );292293extern void InitHandlerFunc (294ObjFunc hdlr,295const Char * cookie );296297extern const Char * CookieOfHandler(298ObjFunc hdlr );299300extern ObjFunc HandlerOfCookie (301const Char * cookie );302303extern void SortHandlers( UInt byWhat );304305/****************************************************************************306**307*F NewFunction( <name>, <narg>, <nams>, <hdlr> ) . . . make a new function308*F NewFunctionC( <name>, <narg>, <nams>, <hdlr> ) . . . make a new function309*F NewFunctionT( <type>, <size>, <name>, <narg>, <nams>, <hdlr> )310*F NewFunctionCT( <type>, <size>, <name>, <narg>, <nams>, <hdlr> )311**312** 'NewFunction' creates and returns a new function. <name> must be a GAP313** string containing the name of the function. <narg> must be the number of314** arguments, where -1 means a variable number of arguments. <nams> must be315** a GAP list containg the names of the arguments. <hdlr> must be the316** C function (accepting <self> and the <narg> arguments) that will be317** called to execute the function.318**319** 'NewFunctionC' does the same as 'NewFunction', but expects <name> and320** <nams> as C strings.321**322** 'NewFunctionT' does the same as 'NewFunction', but allows to specify the323** <type> and <size> of the newly created bag.324**325** 'NewFunctionCT' does the same as 'NewFunction', but expects <name> and326** <nams> as C strings, and allows to specify the <type> and <size> of the327** newly created bag.328*/329extern Obj NewFunction (330Obj name,331Int narg,332Obj nams,333ObjFunc hdlr );334335extern Obj NewFunctionC (336const Char * name,337Int narg,338const Char * nams,339ObjFunc hdlr );340341extern Obj NewFunctionT (342UInt type,343UInt size,344Obj name,345Int narg,346Obj nams,347ObjFunc hdlr );348349extern Obj NewFunctionCT (350UInt type,351UInt size,352const Char * name,353Int narg,354const Char * nams,355ObjFunc hdlr );356357358/****************************************************************************359**360*F ArgStringToList( <nams_c> )361**362** 'ArgStringToList' takes a C string <nams_c> containing a list of comma363** separated argument names, and turns it into a plist of strings, ready364** to be passed to 'NewFunction' as <nams>.365*/366extern Obj ArgStringToList(const Char *nams_c);367368369/****************************************************************************370**371372*F * * * * * * * * * * * * * type and print function * * * * * * * * * * * *373*/374375/****************************************************************************376**377378*F PrintFunction( <func> ) . . . . . . . . . . . . . . . print a function379**380** 'PrintFunction' prints the function <func> in abbreviated form if381** 'PrintObjFull' is false.382*/383extern void PrintFunction (384Obj func );385386387/****************************************************************************388**389*F FuncCALL_FUNC_LIST( <self>, <func>, <list> ) . . . . . . call a function390**391** 'FuncCALL_FUNC_LIST' implements the internal function 'CallFuncList'.392**393** 'CallFuncList( <func>, <list> )'394**395** 'CallFuncList' calls the function <func> with the arguments list <list>,396** i.e., it is equivalent to '<func>( <list>[1], <list>[2]... )'.397*/398399extern Obj CallFuncList(400Obj func,401Obj list);402403extern Obj CallFuncListOper;404405/****************************************************************************406**407408*F * * * * * * * * * * * * * initialize package * * * * * * * * * * * * * * *409*/410411/****************************************************************************412**413414*F InitInfoCalls() . . . . . . . . . . . . . . . . . table of init functions415*/416StructInitInfo * InitInfoCalls ( void );417418419#endif // GAP_CALLS_H420421/****************************************************************************422**423424*E calls.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . ends here425*/426427428