/**************************************************************************** ** ** This file is part of GAP, a system for computational discrete algebra. ** ** Copyright of GAP belongs to its developers, whose names are too numerous ** to list here. Please refer to the COPYRIGHT file for details. ** ** SPDX-License-Identifier: GPL-2.0-or-later ** ** This file declares the functions of the generic function call mechanism ** package. ** ** This package defines the *call mechanism* through which one GAP function, ** named the *caller*, can temporarily transfer control to another function, ** named the *callee*. ** ** There are *compiled functions* and *interpreted functions*. Thus there ** are four possible pairings of caller and callee. ** ** If the caller is compiled, then the call comes directly from the caller. ** If it is interpreted, then the call comes from one of the functions ** 'EvalFunccall<i>args' that implement evaluation of function calls. ** ** If the callee is compiled, then the call goes directly to the callee. ** If it is interpreted, then the call goes to one of the handlers ** 'DoExecFunc<i>args' that implement execution of function bodies. ** ** The call mechanism makes it in any case unnecessary for the calling code ** to know whether the callee is a compiled or an interpreted function. ** Likewise the called code need not know, actually cannot know, whether the ** caller is a compiled or an interpreted function. ** ** Also the call mechanism checks that the number of arguments passed by the ** caller is the same as the number of arguments expected by the callee, or ** it collects the arguments in a list if the callee allows a variable ** number of arguments. ** ** Finally the call mechanism profiles all functions if requested. ** ** All this has very little overhead. In the case of one compiled function ** calling another compiled function, which expects fewer than 4 arguments, ** with no profiling, the overhead is only a couple of instructions.
*/
#ifndef GAP_CALLS_H #define GAP_CALLS_H
#include"gaputils.h" #include"objects.h"
/**************************************************************************** ** *F HDLR_FUNC(<func>,<i>) . . . . . . . . . <i>-th call handler of a function *F NAME_FUNC(<func>) . . . . . . . . . . . . . . . . . . name of a function *F NARG_FUNC(<func>) . . . . . . . . . . . number of arguments of a function *F NAMS_FUNC(<func>) . . . . . . . . names of local variables of a function *F NAMI_FUNC(<func>) . . . . . . name of <i>-th local variable of a function *F PROF_FUNC(<func>) . . . . . . . . profiling information bag of a function *F NLOC_FUNC(<func>) . . . . . . . . . . . . number of locals of a function *F BODY_FUNC(<func>) . . . . . . . . . . . . . . . . . . body of a function *F ENVI_FUNC(<func>) . . . . . . . . . . . . . . . environment of a function ** ** These functions make it possible to access the various components of a ** function. ** ** 'HDLR_FUNC(<func>,<i>)' is the <i>-th handler of the function <func>. ** ** 'NAME_FUNC(<func>)' is the name of the function. ** ** 'NARG_FUNC(<func>)' is the number of arguments (-1 if <func> accepts a ** variable number of arguments). ** ** 'NAMS_FUNC(<func>)' is the list of the names of the local variables, ** ** 'NAMI_FUNC(<func>,<i>)' is the name of the <i>-th local variable. ** ** 'PROF_FUNC(<func>)' is the profiling information bag. ** ** 'NLOC_FUNC(<func>)' is the number of local variables of the interpreted ** function <func>. ** ** 'BODY_FUNC(<func>)' is the body. ** ** 'ENVI_FUNC(<func>)' is the environment (i.e., the local variables bag) ** that was current when <func> was created. ** ** 'LCKS_FUNC(<func>)' is a string that contains the lock mode for the ** arguments of <func>. Each byte corresponds to the mode for an argument: ** 0 means no lock, 1 means a read-only lock, 2 means a read-write lock. ** The value of the bag can be null, in which case no argument requires a ** lock. Only used in HPC-GAP.
*/ typedefstruct {
ObjFunc handlers[8];
Obj name;
Obj nargs;
Obj namesOfArgsAndLocals;
Obj prof;
Obj nloc;
Obj body;
Obj envi; #ifdef HPCGAP
Obj locks; #endif // additional data follows for operations
} FuncBag;
/**************************************************************************** * *F IsKernelFunction( <func> ) ** ** 'IsKernelFunction' returns 1 if <func> is a kernel function (i.e. ** compiled from C code), and 0 otherwise.
*/ BOOL IsKernelFunction(Obj func);
/**************************************************************************** ** *F IS_FUNC( <obj> ) . . . . . . . . . . . . . check if object is a function
*/
EXPORT_INLINE BOOL IS_FUNC(Obj obj)
{ return TNUM_OBJ(obj) == T_FUNCTION;
}
/**************************************************************************** ** *F CALL_0ARGS(<func>) . . . . . . . . . call a function with 0 arguments *F CALL_1ARGS(<func>,<arg1>) . . . . . . call a function with 1 arguments *F CALL_2ARGS(<func>,<arg1>...) . . . . call a function with 2 arguments *F CALL_3ARGS(<func>,<arg1>...) . . . . call a function with 3 arguments *F CALL_4ARGS(<func>,<arg1>...) . . . . call a function with 4 arguments *F CALL_5ARGS(<func>,<arg1>...) . . . . call a function with 5 arguments *F CALL_6ARGS(<func>,<arg1>...) . . . . call a function with 6 arguments *F CALL_XARGS(<func>,<args>) . . . . . . call a function with more arguments ** ** 'CALL_<i>ARGS' passes control to the function <func>, which must be a ** function object ('T_FUNCTION'). It returns the return value of <func>. ** 'CALL_0ARGS' is for calls passing no arguments, 'CALL_1ARGS' for calls ** passing one argument, and so on. 'CALL_XARGS' is for calls passing more ** than 5 arguments, where the arguments must be collected in a plain list, ** and this plain list must then be passed. ** ** 'CALL_<i>ARGS' can be used independently of whether the called function ** is a compiled or interpreted function. It checks that the number of ** passed arguments is the same as the number of arguments expected by the ** callee, or it collects the arguments in a list if the callee allows a ** variable number of arguments.
*/
EXPORT_INLINE Obj CALL_0ARGS(Obj f)
{ return HDLR_0ARGS(f)(f);
}
/**************************************************************************** ** *F InitHandlerFunc( <handler>, <cookie> ) . . . . . . . . register a handler ** ** Every handler should be registered (once) before it is installed in any ** function bag. This is needed so that it can be identified when loading a ** saved workspace. <cookie> should be a unique C string, identifying the ** handler
*/
/**************************************************************************** ** *F NewFunction( <name>, <narg>, <nams>, <hdlr> ) . . . make a new function *F NewFunctionC( <name>, <narg>, <nams>, <hdlr> ) . . . make a new function *F NewFunctionT( <type>, <size>, <name>, <narg>, <nams>, <hdlr> ) ** ** 'NewFunction' creates and returns a new function. <name> must be a GAP ** string containing the name of the function. <narg> must be the number of ** arguments, where -1 means a variable number of arguments. <nams> must be ** a GAP list containing the names of the arguments. <hdlr> must be the ** C function (accepting <self> and the <narg> arguments) that will be ** called to execute the function. ** ** 'NewFunctionC' does the same as 'NewFunction', but expects <name> and ** <nams> as C strings. ** ** 'NewFunctionT' does the same as 'NewFunction', but allows to specify the ** <type> and <size> of the newly created bag.
*/
Obj NewFunction(Obj name, Int narg, Obj nams, ObjFunc hdlr);
/**************************************************************************** ** *F ArgStringToList( <nams_c> ) ** ** 'ArgStringToList' takes a C string <nams_c> containing a list of comma ** separated argument names, and turns it into a plist of strings, ready ** to be passed to 'NewFunction' as <nams>.
*/
Obj ArgStringToList(constChar * nams_c);
/**************************************************************************** ** ** 'CallFuncList( <func>, <list> )' ** ** 'CallFuncList' calls the function <func> with the arguments list <list>, ** i.e., it is equivalent to '<func>( <list>[1], <list>[2]... )'.
*/
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.