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 funcs.c 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 contains the functions of the function interpreter package.10**11** The function interpreter package contains the executors for procedure12** calls, the evaluators for function calls, the evaluator for function13** expressions, and the handlers for the execution of function bodies.14**15** It uses the function call mechanism defined by the calls package.16*/17#include <stdio.h> /* on SunOS, assert.h uses stderr18but does not include stdio.h */19#include <assert.h> /* assert */20#include "system.h" /* Ints, UInts */21#include "bool.h"222324#include "gasman.h" /* garbage collector */25#include "objects.h" /* objects */26#include "scanner.h" /* scanner */2728#include "gap.h" /* error handling, initialisation */2930#include "string.h" /* strings */31#include "calls.h" /* generic call mechanism */3233#include "code.h" /* coder */34#include "exprs.h" /* expressions */35#include "stats.h" /* statements */3637#include "funcs.h" /* functions */3839#include "read.h" /* read expressions */40#include "records.h" /* generic records */41#include "precord.h" /* plain records */4243#include "lists.h" /* generic lists */44#include "plist.h" /* plain lists */454647#include "saveload.h" /* saving and loading */4849#include "opers.h" /* generic operations */50#include "gvars.h"51#include "thread.h" /* threads */52#include "tls.h" /* thread-local storage */5354#include "vars.h" /* variables */555657#include "profile.h" /* installing methods */58/****************************************************************************59**60*F ExecProccallOpts( <call> ). . execute a procedure call with options61**62** Calls with options are wrapped in an outer statement, which is63** handled here64*/6566static Obj PushOptions;67static Obj PopOptions;6869UInt ExecProccallOpts(70Stat call )71{72Obj opts;7374SET_BRK_CURR_STAT( call );75opts = EVAL_EXPR( ADDR_STAT(call)[0] );76CALL_1ARGS(PushOptions, opts);7778EXEC_STAT( ADDR_STAT( call )[1]);7980CALL_0ARGS(PopOptions);8182return 0;83}848586/****************************************************************************87**88*F ExecProccall0args(<call>) . execute a procedure call with 0 arguments89*F ExecProccall1args(<call>) . execute a procedure call with 1 arguments90*F ExecProccall2args(<call>) . execute a procedure call with 2 arguments91*F ExecProccall3args(<call>) . execute a procedure call with 3 arguments92*F ExecProccall4args(<call>) . execute a procedure call with 4 arguments93*F ExecProccall5args(<call>) . execute a procedure call with 5 arguments94*F ExecProccall6args(<call>) . execute a procedure call with 6 arguments95*F ExecProccallXargs(<call>) . execute a procedure call with more arguments96**97** 'ExecProccall<i>args' executes a procedure call to the function98** 'FUNC_CALL(<call>)' with the arguments 'ARGI_CALL(<call>,1)' to99** 'ARGI_CALL(<call>,<i>)'. It returns the value returned by the function.100*/101102static Obj DispatchFuncCall( Obj func, Int nargs, Obj arg1, Obj arg2, Obj arg3, Obj arg4, Obj arg5, Obj arg6)103{104Obj arglist;105if (nargs != -1) {106arglist = NEW_PLIST(T_PLIST_DENSE, nargs);107SET_LEN_PLIST(arglist, nargs);108switch(nargs) {109case 6:110SET_ELM_PLIST(arglist,6, arg6);111case 5:112SET_ELM_PLIST(arglist,5, arg5);113case 4:114SET_ELM_PLIST(arglist,4, arg4);115case 3:116SET_ELM_PLIST(arglist,3, arg3);117case 2:118SET_ELM_PLIST(arglist,2, arg2);119case 1:120SET_ELM_PLIST(arglist,1, arg1);121case 0:122CHANGED_BAG(arglist);123}124} else {125arglist = arg1;126}127return DoOperation2Args(CallFuncListOper, func, arglist);128}129130131UInt ExecProccall0args (132Stat call )133{134Obj func; /* function */135136/* evaluate the function */137SET_BRK_CURR_STAT( call );138func = EVAL_EXPR( FUNC_CALL( call ) );139140/* call the function */141SET_BRK_CALL_TO( call );142if (TNUM_OBJ(func) != T_FUNCTION)143DispatchFuncCall(func, 0, (Obj) 0L, (Obj) 0L, (Obj) 0L, (Obj) 0L, (Obj) 0L, (Obj) 0L);144else {145CALL_0ARGS( func );146}147if (TLS(UserHasQuit) || TLS(UserHasQUIT)) /* the procedure must have called148READ() and the user quit from a break149loop inside it */150ReadEvalError();151/* return 0 (to indicate that no leave-statement was executed) */152return 0;153}154155UInt ExecProccall1args (156Stat call )157{158Obj func; /* function */159Obj arg1; /* first argument */160161/* evaluate the function */162SET_BRK_CURR_STAT( call );163func = EVAL_EXPR( FUNC_CALL( call ) );164165/* evaluate the arguments */166arg1 = EVAL_EXPR( ARGI_CALL( call, 1 ) );167168/* call the function */169if (TNUM_OBJ(func) != T_FUNCTION)170DispatchFuncCall(func, 1, (Obj) arg1, (Obj) 0L, (Obj) 0L, (Obj) 0L, (Obj) 0L, (Obj) 0L);171else {172SET_BRK_CALL_TO( call );173CALL_1ARGS( func, arg1 );174}175if (TLS(UserHasQuit) || TLS(UserHasQUIT)) /* the procedure must have called176READ() and the user quit from a break177loop inside it */178ReadEvalError();179/* return 0 (to indicate that no leave-statement was executed) */180return 0;181}182183UInt ExecProccall2args (184Stat call )185{186Obj func; /* function */187Obj arg1; /* first argument */188Obj arg2; /* second argument */189190/* evaluate the function */191SET_BRK_CURR_STAT( call );192func = EVAL_EXPR( FUNC_CALL( call ) );193194/* evaluate the arguments */195arg1 = EVAL_EXPR( ARGI_CALL( call, 1 ) );196arg2 = EVAL_EXPR( ARGI_CALL( call, 2 ) );197198/* call the function */199if (TNUM_OBJ(func) != T_FUNCTION)200DispatchFuncCall(func, 2, (Obj) arg1, (Obj) arg2, (Obj) 0L, (Obj) 0L, (Obj) 0L, (Obj) 0L);201else {202SET_BRK_CALL_TO( call );203CALL_2ARGS( func, arg1, arg2 );204}205if (TLS(UserHasQuit) || TLS(UserHasQUIT)) /* the procedure must have called206READ() and the user quit from a break207loop inside it */208ReadEvalError();209/* return 0 (to indicate that no leave-statement was executed) */210return 0;211}212213UInt ExecProccall3args (214Stat call )215{216Obj func; /* function */217Obj arg1; /* first argument */218Obj arg2; /* second argument */219Obj arg3; /* third argument */220221/* evaluate the function */222SET_BRK_CURR_STAT( call );223func = EVAL_EXPR( FUNC_CALL( call ) );224225/* evaluate the arguments */226arg1 = EVAL_EXPR( ARGI_CALL( call, 1 ) );227arg2 = EVAL_EXPR( ARGI_CALL( call, 2 ) );228arg3 = EVAL_EXPR( ARGI_CALL( call, 3 ) );229230/* call the function */231if (TNUM_OBJ(func) != T_FUNCTION)232DispatchFuncCall(func, 3, (Obj) arg1, (Obj) arg2, (Obj) arg3, (Obj) 0L, (Obj) 0L, (Obj) 0L);233else {234SET_BRK_CALL_TO( call );235CALL_3ARGS( func, arg1, arg2, arg3 );236}237if (TLS(UserHasQuit) || TLS(UserHasQUIT)) /* the procedure must have called238READ() and the user quit from a break239loop inside it */240ReadEvalError();241/* return 0 (to indicate that no leave-statement was executed) */242return 0;243}244245UInt ExecProccall4args (246Stat call )247{248Obj func; /* function */249Obj arg1; /* first argument */250Obj arg2; /* second argument */251Obj arg3; /* third argument */252Obj arg4; /* fourth argument */253254/* evaluate the function */255SET_BRK_CURR_STAT( call );256func = EVAL_EXPR( FUNC_CALL( call ) );257258/* evaluate the arguments */259arg1 = EVAL_EXPR( ARGI_CALL( call, 1 ) );260arg2 = EVAL_EXPR( ARGI_CALL( call, 2 ) );261arg3 = EVAL_EXPR( ARGI_CALL( call, 3 ) );262arg4 = EVAL_EXPR( ARGI_CALL( call, 4 ) );263264/* call the function */265if (TNUM_OBJ(func) != T_FUNCTION)266DispatchFuncCall(func, 4, (Obj) arg1, (Obj) arg2, (Obj) arg3, (Obj) arg4, (Obj) 0, (Obj) 0);267else {268SET_BRK_CALL_TO( call );269CALL_4ARGS( func, arg1, arg2, arg3, arg4 );270}271if (TLS(UserHasQuit) || TLS(UserHasQUIT)) /* the procedure must have called272READ() and the user quit from a break273loop inside it */274ReadEvalError();275/* return 0 (to indicate that no leave-statement was executed) */276return 0;277}278279UInt ExecProccall5args (280Stat call )281{282Obj func; /* function */283Obj arg1; /* first argument */284Obj arg2; /* second argument */285Obj arg3; /* third argument */286Obj arg4; /* fourth argument */287Obj arg5; /* fifth argument */288289/* evaluate the function */290SET_BRK_CURR_STAT( call );291func = EVAL_EXPR( FUNC_CALL( call ) );292while ( TNUM_OBJ( func ) != T_FUNCTION ) {293func = ErrorReturnObj(294"Function Calls: <func> must be a function (not a %s)",295(Int)TNAM_OBJ(func), 0L,296"you can replace <func> via 'return <func>;'" );297}298299/* evaluate the arguments */300arg1 = EVAL_EXPR( ARGI_CALL( call, 1 ) );301arg2 = EVAL_EXPR( ARGI_CALL( call, 2 ) );302arg3 = EVAL_EXPR( ARGI_CALL( call, 3 ) );303arg4 = EVAL_EXPR( ARGI_CALL( call, 4 ) );304arg5 = EVAL_EXPR( ARGI_CALL( call, 5 ) );305306/* call the function */307if (TNUM_OBJ(func) != T_FUNCTION)308DispatchFuncCall(func, 5, (Obj) arg1, (Obj) arg2, (Obj) arg3, (Obj) arg4, (Obj) arg5, (Obj) 0L);309else {310SET_BRK_CALL_TO( call );311CALL_5ARGS( func, arg1, arg2, arg3, arg4, arg5 );312}313if (TLS(UserHasQuit) || TLS(UserHasQUIT)) /* the procedure must have called314READ() and the user quit from a break315loop inside it */316ReadEvalError();317/* return 0 (to indicate that no leave-statement was executed) */318return 0;319}320321UInt ExecProccall6args (322Stat call )323{324Obj func; /* function */325Obj arg1; /* first argument */326Obj arg2; /* second argument */327Obj arg3; /* third argument */328Obj arg4; /* fourth argument */329Obj arg5; /* fifth argument */330Obj arg6; /* sixth argument */331332/* evaluate the function */333SET_BRK_CURR_STAT( call );334func = EVAL_EXPR( FUNC_CALL( call ) );335336/* evaluate the arguments */337arg1 = EVAL_EXPR( ARGI_CALL( call, 1 ) );338arg2 = EVAL_EXPR( ARGI_CALL( call, 2 ) );339arg3 = EVAL_EXPR( ARGI_CALL( call, 3 ) );340arg4 = EVAL_EXPR( ARGI_CALL( call, 4 ) );341arg5 = EVAL_EXPR( ARGI_CALL( call, 5 ) );342arg6 = EVAL_EXPR( ARGI_CALL( call, 6 ) );343344/* call the function */345if (TNUM_OBJ(func) != T_FUNCTION)346DispatchFuncCall(func, 6, (Obj) arg1, (Obj) arg2, (Obj) arg3, (Obj) arg4, (Obj) arg5, (Obj) arg6);347else {348SET_BRK_CALL_TO( call );349CALL_6ARGS( func, arg1, arg2, arg3, arg4, arg5, arg6 );350}351if (TLS(UserHasQuit) || TLS(UserHasQUIT)) /* the procedure must have called352READ() and the user quit from a break353loop inside it */354ReadEvalError();355/* return 0 (to indicate that no leave-statement was executed) */356return 0;357}358359UInt ExecProccallXargs (360Stat call )361{362Obj func; /* function */363Obj args; /* argument list */364Obj argi; /* <i>-th argument */365UInt i; /* loop variable */366367/* evaluate the function */368SET_BRK_CURR_STAT( call );369func = EVAL_EXPR( FUNC_CALL( call ) );370371372/* evaluate the arguments */373args = NEW_PLIST( T_PLIST, NARG_SIZE_CALL(SIZE_STAT(call)) );374SET_LEN_PLIST( args, NARG_SIZE_CALL(SIZE_STAT(call)) );375for ( i = 1; i <= NARG_SIZE_CALL(SIZE_STAT(call)); i++ ) {376argi = EVAL_EXPR( ARGI_CALL( call, i ) );377SET_ELM_PLIST( args, i, argi );378CHANGED_BAG( args );379}380381/* call the function */382if (TNUM_OBJ(func) != T_FUNCTION) {383DoOperation2Args(CallFuncListOper, func, args);384} else {385SET_BRK_CALL_TO( call );386CALL_XARGS( func, args );387}388389if (TLS(UserHasQuit) || TLS(UserHasQUIT)) /* the procedure must have called390READ() and the user quit from a break391loop inside it */392ReadEvalError();393/* return 0 (to indicate that no leave-statement was executed) */394return 0;395}396397/****************************************************************************398**399*F EvalFunccallOpts( <call> ). . evaluate a function call with options400**401** Calls with options are wrapped in an outer statement, which is402** handled here403*/404405Obj EvalFunccallOpts(406Expr call )407{408Obj opts;409Obj res;410411412opts = EVAL_EXPR( ADDR_STAT(call)[0] );413CALL_1ARGS(PushOptions, opts);414415res = EVAL_EXPR( ADDR_STAT( call )[1]);416417CALL_0ARGS(PopOptions);418419return res;420}421422423/****************************************************************************424**425*F EvalFunccall0args(<call>) . . execute a function call with 0 arguments426*F EvalFunccall1args(<call>) . . execute a function call with 1 arguments427*F EvalFunccall2args(<call>) . . execute a function call with 2 arguments428*F EvalFunccall3args(<call>) . . execute a function call with 3 arguments429*F EvalFunccall4args(<call>) . . execute a function call with 4 arguments430*F EvalFunccall5args(<call>) . . execute a function call with 5 arguments431*F EvalFunccall6args(<call>) . . execute a function call with 6 arguments432*F EvalFunccallXargs(<call>) . . execute a function call with more arguments433**434** 'EvalFunccall<i>args' executes a function call to the function435** 'FUNC_CALL(<call>)' with the arguments 'ARGI_CALL(<call>,1)' to436** 'ARGI_CALL(<call>,<i>)'. It returns the value returned by the function.437*/438439Obj EvalFunccall0args (440Expr call )441{442Obj result; /* value of function call, result */443Obj func; /* function */444445/* evaluate the function */446func = EVAL_EXPR( FUNC_CALL( call ) );447448if (TNUM_OBJ(func) != T_FUNCTION) {449return DispatchFuncCall(func, 0, (Obj) 0, (Obj) 0, (Obj) 0, (Obj) 0, (Obj) 0, (Obj) 0 );450}451452/* call the function and return the result */453SET_BRK_CALL_TO( call );454result = CALL_0ARGS( func );455if (TLS(UserHasQuit) || TLS(UserHasQUIT)) /* the procedure must have called456READ() and the user quit from a break457loop inside it */458ReadEvalError();459while ( result == 0 ) {460result = ErrorReturnObj(461"Function Calls: <func> must return a value",4620L, 0L,463"you can supply one by 'return <value>;'" );464}465return result;466}467468Obj EvalFunccall1args (469Expr call )470{471Obj result; /* value of function call, result */472Obj func; /* function */473Obj arg1; /* first argument */474475/* evaluate the function */476func = EVAL_EXPR( FUNC_CALL( call ) );477/* evaluate the arguments */478arg1 = EVAL_EXPR( ARGI_CALL( call, 1 ) );479480if (TNUM_OBJ(func) != T_FUNCTION) {481return DispatchFuncCall(func, 1, (Obj) arg1, (Obj) 0, (Obj) 0, (Obj) 0, (Obj) 0, (Obj) 0 );482}483484/* call the function and return the result */485SET_BRK_CALL_TO( call );486result = CALL_1ARGS( func, arg1 );487if (TLS(UserHasQuit) || TLS(UserHasQUIT)) /* the procedure must have called488READ() and the user quit from a break489loop inside it */490ReadEvalError();491while ( result == 0 ) {492result = ErrorReturnObj(493"Function Calls: <func> must return a value",4940L, 0L,495"you can supply one by 'return <value>;'" );496}497return result;498}499500Obj EvalFunccall2args (501Expr call )502{503Obj result; /* value of function call, result */504Obj func; /* function */505Obj arg1; /* first argument */506Obj arg2; /* second argument */507508/* evaluate the function */509func = EVAL_EXPR( FUNC_CALL( call ) );510511/* evaluate the arguments */512arg1 = EVAL_EXPR( ARGI_CALL( call, 1 ) );513arg2 = EVAL_EXPR( ARGI_CALL( call, 2 ) );514515if (TNUM_OBJ(func) != T_FUNCTION) {516return DispatchFuncCall(func, 2, (Obj) arg1, (Obj) arg2, (Obj) 0, (Obj) 0, (Obj) 0, (Obj) 0 );517}518519/* call the function and return the result */520SET_BRK_CALL_TO( call );521result = CALL_2ARGS( func, arg1, arg2 );522if (TLS(UserHasQuit) || TLS(UserHasQUIT)) /* the procedure must have called523READ() and the user quit from a break524loop inside it */525ReadEvalError();526while ( result == 0 ) {527result = ErrorReturnObj(528"Function Calls: <func> must return a value",5290L, 0L,530"you can supply one by 'return <value>;'" );531}532return result;533}534535Obj EvalFunccall3args (536Expr call )537{538Obj result; /* value of function call, result */539Obj func; /* function */540Obj arg1; /* first argument */541Obj arg2; /* second argument */542Obj arg3; /* third argument */543544/* evaluate the function */545func = EVAL_EXPR( FUNC_CALL( call ) );546547/* evaluate the arguments */548arg1 = EVAL_EXPR( ARGI_CALL( call, 1 ) );549arg2 = EVAL_EXPR( ARGI_CALL( call, 2 ) );550arg3 = EVAL_EXPR( ARGI_CALL( call, 3 ) );551552if (TNUM_OBJ(func) != T_FUNCTION) {553return DispatchFuncCall(func, 1, (Obj) arg1, (Obj) arg2, (Obj) arg3, (Obj) 0, (Obj) 0, (Obj) 0 );554}555556/* call the function and return the result */557SET_BRK_CALL_TO( call );558result = CALL_3ARGS( func, arg1, arg2, arg3 );559if (TLS(UserHasQuit) || TLS(UserHasQUIT)) /* the procedure must have called560READ() and the user quit from a break561loop inside it */562ReadEvalError();563while ( result == 0 ) {564result = ErrorReturnObj(565"Function Calls: <func> must return a value",5660L, 0L,567"you can supply one by 'return <value>;'" );568}569return result;570}571572Obj EvalFunccall4args (573Expr call )574{575Obj result; /* value of function call, result */576Obj func; /* function */577Obj arg1; /* first argument */578Obj arg2; /* second argument */579Obj arg3; /* third argument */580Obj arg4; /* fourth argument */581582/* evaluate the function */583func = EVAL_EXPR( FUNC_CALL( call ) );584/* evaluate the arguments */585arg1 = EVAL_EXPR( ARGI_CALL( call, 1 ) );586arg2 = EVAL_EXPR( ARGI_CALL( call, 2 ) );587arg3 = EVAL_EXPR( ARGI_CALL( call, 3 ) );588arg4 = EVAL_EXPR( ARGI_CALL( call, 4 ) );589590if (TNUM_OBJ(func) != T_FUNCTION) {591return DispatchFuncCall(func, 4, (Obj) arg1, (Obj) arg2, (Obj) arg3, (Obj) arg4, (Obj) 0, (Obj) 0 );592}593594/* call the function and return the result */595SET_BRK_CALL_TO( call );596result = CALL_4ARGS( func, arg1, arg2, arg3, arg4 );597if (TLS(UserHasQuit) || TLS(UserHasQUIT)) /* the procedure must have called598READ() and the user quit from a break599loop inside it */600ReadEvalError();601while ( result == 0 ) {602result = ErrorReturnObj(603"Function Calls: <func> must return a value",6040L, 0L,605"you can supply one by 'return <value>;'" );606}607return result;608}609610Obj EvalFunccall5args (611Expr call )612{613Obj result; /* value of function call, result */614Obj func; /* function */615Obj arg1; /* first argument */616Obj arg2; /* second argument */617Obj arg3; /* third argument */618Obj arg4; /* fourth argument */619Obj arg5; /* fifth argument */620621/* evaluate the function */622func = EVAL_EXPR( FUNC_CALL( call ) );623624/* evaluate the arguments */625arg1 = EVAL_EXPR( ARGI_CALL( call, 1 ) );626arg2 = EVAL_EXPR( ARGI_CALL( call, 2 ) );627arg3 = EVAL_EXPR( ARGI_CALL( call, 3 ) );628arg4 = EVAL_EXPR( ARGI_CALL( call, 4 ) );629arg5 = EVAL_EXPR( ARGI_CALL( call, 5 ) );630631if (TNUM_OBJ(func) != T_FUNCTION) {632return DispatchFuncCall(func, 5, (Obj) arg1, (Obj) arg2, (Obj) arg3, (Obj) arg4, (Obj) arg5, (Obj) 0 );633}634635/* call the function and return the result */636SET_BRK_CALL_TO( call );637result = CALL_5ARGS( func, arg1, arg2, arg3, arg4, arg5 );638if (TLS(UserHasQuit) || TLS(UserHasQUIT)) /* the procedure must have called639READ() and the user quit from a break640loop inside it */641ReadEvalError();642while ( result == 0 ) {643result = ErrorReturnObj(644"Function Calls: <func> must return a value",6450L, 0L,646"you can supply one by 'return <value>;'" );647}648return result;649}650651Obj EvalFunccall6args (652Expr call )653{654Obj result; /* value of function call, result */655Obj func; /* function */656Obj arg1; /* first argument */657Obj arg2; /* second argument */658Obj arg3; /* third argument */659Obj arg4; /* fourth argument */660Obj arg5; /* fifth argument */661Obj arg6; /* sixth argument */662663/* evaluate the function */664func = EVAL_EXPR( FUNC_CALL( call ) );665666/* evaluate the arguments */667arg1 = EVAL_EXPR( ARGI_CALL( call, 1 ) );668arg2 = EVAL_EXPR( ARGI_CALL( call, 2 ) );669arg3 = EVAL_EXPR( ARGI_CALL( call, 3 ) );670arg4 = EVAL_EXPR( ARGI_CALL( call, 4 ) );671arg5 = EVAL_EXPR( ARGI_CALL( call, 5 ) );672arg6 = EVAL_EXPR( ARGI_CALL( call, 6 ) );673674if (TNUM_OBJ(func) != T_FUNCTION) {675return DispatchFuncCall(func, 6, (Obj) arg1, (Obj) arg2, (Obj) arg3, (Obj) arg4, (Obj) arg5, (Obj) arg6 );676}677678/* call the function and return the result */679SET_BRK_CALL_TO( call );680result = CALL_6ARGS( func, arg1, arg2, arg3, arg4, arg5, arg6 );681if (TLS(UserHasQuit) || TLS(UserHasQUIT)) /* the procedure must have called682READ() and the user quit from a break683loop inside it */684ReadEvalError();685while ( result == 0 ) {686result = ErrorReturnObj(687"Function Calls: <func> must return a value",6880L, 0L,689"you can supply one by 'return <value>;'" );690}691return result;692}693694Obj EvalFunccallXargs (695Expr call )696{697Obj result; /* value of function call, result */698Obj func; /* function */699Obj args; /* argument list */700Obj argi; /* <i>-th argument */701UInt i; /* loop variable */702703/* evaluate the function */704func = EVAL_EXPR( FUNC_CALL( call ) );705706/* evaluate the arguments */707args = NEW_PLIST( T_PLIST, NARG_SIZE_CALL(SIZE_EXPR(call)) );708SET_LEN_PLIST( args, NARG_SIZE_CALL(SIZE_EXPR(call)) );709for ( i = 1; i <= NARG_SIZE_CALL(SIZE_EXPR(call)); i++ ) {710argi = EVAL_EXPR( ARGI_CALL( call, i ) );711SET_ELM_PLIST( args, i, argi );712CHANGED_BAG( args );713}714715if (TNUM_OBJ(func) != T_FUNCTION) {716return DispatchFuncCall(func, -1, (Obj) args, (Obj) 0, (Obj) 0, (Obj) 0, (Obj) 0, (Obj) 0 );717}718719/* call the function and return the result */720SET_BRK_CALL_TO( call );721result = CALL_XARGS( func, args );722if (TLS(UserHasQuit) || TLS(UserHasQUIT)) /* the procedure must have called723READ() and the user quit from a break724loop inside it */725ReadEvalError();726while ( result == 0 ) {727result = ErrorReturnObj(728"Function Calls: <func> must return a value",7290L, 0L,730"you can supply one by 'return <value>;'" );731}732return result;733}734735736/****************************************************************************737**738*F DoExecFunc0args(<func>) . . . . interpret a function with 0 arguments739*F DoExecFunc1args(<func>,<arg1>) . interpret a function with 1 arguments740*F DoExecFunc2args(<func>,<arg1>...) interpret a function with 2 arguments741*F DoExecFunc3args(<func>,<arg1>...) interpret a function with 3 arguments742*F DoExecFunc4args(<func>,<arg1>...) interpret a function with 4 arguments743*F DoExecFunc5args(<func>,<arg1>...) interpret a function with 5 arguments744*F DoExecFunc6args(<func>,<arg1>...) interpret a function with 6 arguments745*F DoExecFuncXargs(<func>,<args>) . interpret a function with more arguments746**747** 'DoExecFunc<i>args' interprets the function <func> that expects <i>748** arguments with the <i> actual argument <arg1>, <arg2>, and so on. If the749** function expects more than 4 arguments the actual arguments are passed in750** the plain list <args>.751**752** 'DoExecFunc<i>args' is the handler for interpreted functions expecting753** <i> arguments.754**755** 'DoExecFunc<i>args' first switches to a new values bag. Then it enters756** the arguments <arg1>, <arg2>, and so on in this new values bag. Then it757** executes the function body. After that it switches back to the old758** values bag. Finally it returns the result from 'TLS(ReturnObjStat)'.759**760** Note that these functions are never called directly, they are only called761** through the function call mechanism.762**763** The following functions implement the recursion depth control.764**765*/766767Int RecursionDepth;768static UInt RecursionTrapInterval;769770static void RecursionDepthTrap( void )771{772Int recursionDepth;773/* in interactive work the RecursionDepth could become slightly negative774* when quit-ting a higher level brk-loop to a lower level one.775* Therefore we don't do anything if RecursionDepth <= 0776*/777if (TLS(RecursionDepth) > 0) {778recursionDepth = TLS(RecursionDepth);779TLS(RecursionDepth) = 0;780ErrorReturnVoid( "recursion depth trap (%d)\n",781(Int)recursionDepth, 0L,782"you may 'return;'" );783TLS(RecursionDepth) = recursionDepth;784}785}786787static inline void CheckRecursionBefore( void )788{789TLS(RecursionDepth)++;790if ( RecursionTrapInterval &&7910 == (TLS(RecursionDepth) % RecursionTrapInterval) )792RecursionDepthTrap();793}794795796Obj STEVES_TRACING;797798#define CHECK_RECURSION_BEFORE \799CheckRecursionBefore(); \800ProfileLineByLineIntoFunction(func);801802#define CHECK_RECURSION_AFTER \803TLS(RecursionDepth)--; \804ProfileLineByLineOutFunction(func);805806#define REMEMBER_LOCKSTACK() \807do { } while (0)808809#define CLEAR_LOCK_STACK() \810do { } while (0)811812813Obj DoExecFunc0args (814Obj func )815{816Bag oldLvars; /* old values bag */817REMEMBER_LOCKSTACK();818819OLD_BRK_CURR_STAT /* old executing statement */820821CHECK_RECURSION_BEFORE822823824/* switch to a new values bag */825SWITCH_TO_NEW_LVARS( func, 0, NLOC_FUNC(func), oldLvars );826827/* execute the statement sequence */828REM_BRK_CURR_STAT();829EXEC_STAT( FIRST_STAT_CURR_FUNC );830RES_BRK_CURR_STAT();831CLEAR_LOCK_STACK();832833/* remove the link to the calling function, in case this values bag834stays alive due to higher variable reference */835SET_BRK_CALL_FROM( ((Obj) 0));836837/* Switch back to the old values bag */838SWITCH_TO_OLD_LVARS_AND_FREE( oldLvars );839840CHECK_RECURSION_AFTER841842/* return the result */843{844Obj returnObjStat;845returnObjStat = TLS(ReturnObjStat);846TLS(ReturnObjStat) = (Obj)0;847return returnObjStat;848}849}850851Obj DoExecFunc1args (852Obj func,853Obj arg1 )854{855Bag oldLvars; /* old values bag */856REMEMBER_LOCKSTACK();857OLD_BRK_CURR_STAT /* old executing statement */858859CHECK_RECURSION_BEFORE860861/* switch to a new values bag */862SWITCH_TO_NEW_LVARS( func, 1, NLOC_FUNC(func), oldLvars );863864/* enter the arguments */865ASS_LVAR( 1, arg1 );866867/* execute the statement sequence */868REM_BRK_CURR_STAT();869EXEC_STAT( FIRST_STAT_CURR_FUNC );870RES_BRK_CURR_STAT();871CLEAR_LOCK_STACK();872873/* remove the link to the calling function, in case this values bag874stays alive due to higher variable reference */875SET_BRK_CALL_FROM( ((Obj) 0));876877/* switch back to the old values bag */878SWITCH_TO_OLD_LVARS_AND_FREE( oldLvars );879880CHECK_RECURSION_AFTER881882/* return the result */883{884Obj returnObjStat;885returnObjStat = TLS(ReturnObjStat);886TLS(ReturnObjStat) = (Obj)0;887return returnObjStat;888}889}890891Obj DoExecFunc2args (892Obj func,893Obj arg1,894Obj arg2 )895{896Bag oldLvars; /* old values bag */897REMEMBER_LOCKSTACK();898OLD_BRK_CURR_STAT /* old executing statement */899900CHECK_RECURSION_BEFORE901902/* switch to a new values bag */903SWITCH_TO_NEW_LVARS( func, 2, NLOC_FUNC(func), oldLvars );904905/* enter the arguments */906ASS_LVAR( 1, arg1 );907ASS_LVAR( 2, arg2 );908909/* execute the statement sequence */910REM_BRK_CURR_STAT();911EXEC_STAT( FIRST_STAT_CURR_FUNC );912RES_BRK_CURR_STAT();913CLEAR_LOCK_STACK();914915/* remove the link to the calling function, in case this values bag916stays alive due to higher variable reference */917SET_BRK_CALL_FROM( ((Obj) 0));918919/* switch back to the old values bag */920SWITCH_TO_OLD_LVARS_AND_FREE( oldLvars );921922CHECK_RECURSION_AFTER923924/* return the result */925{926Obj returnObjStat;927returnObjStat = TLS(ReturnObjStat);928TLS(ReturnObjStat) = (Obj)0;929return returnObjStat;930}931}932933Obj DoExecFunc3args (934Obj func,935Obj arg1,936Obj arg2,937Obj arg3 )938{939Bag oldLvars; /* old values bag */940REMEMBER_LOCKSTACK();941OLD_BRK_CURR_STAT /* old executing statement */942943CHECK_RECURSION_BEFORE944945/* switch to a new values bag */946SWITCH_TO_NEW_LVARS( func, 3, NLOC_FUNC(func), oldLvars );947948/* enter the arguments */949ASS_LVAR( 1, arg1 );950ASS_LVAR( 2, arg2 );951ASS_LVAR( 3, arg3 );952953/* execute the statement sequence */954REM_BRK_CURR_STAT();955EXEC_STAT( FIRST_STAT_CURR_FUNC );956RES_BRK_CURR_STAT();957CLEAR_LOCK_STACK();958959/* remove the link to the calling function, in case this values bag960stays alive due to higher variable reference */961SET_BRK_CALL_FROM( ((Obj) 0));962963/* switch back to the old values bag */964SWITCH_TO_OLD_LVARS_AND_FREE( oldLvars );965966CHECK_RECURSION_AFTER967968/* return the result */969{970Obj returnObjStat;971returnObjStat = TLS(ReturnObjStat);972TLS(ReturnObjStat) = (Obj)0;973return returnObjStat;974}975}976977Obj DoExecFunc4args (978Obj func,979Obj arg1,980Obj arg2,981Obj arg3,982Obj arg4 )983{984Bag oldLvars; /* old values bag */985REMEMBER_LOCKSTACK();986OLD_BRK_CURR_STAT /* old executing statement */987988CHECK_RECURSION_BEFORE989990/* switch to a new values bag */991SWITCH_TO_NEW_LVARS( func, 4, NLOC_FUNC(func), oldLvars );992993/* enter the arguments */994ASS_LVAR( 1, arg1 );995ASS_LVAR( 2, arg2 );996ASS_LVAR( 3, arg3 );997ASS_LVAR( 4, arg4 );998999/* execute the statement sequence */1000REM_BRK_CURR_STAT();1001EXEC_STAT( FIRST_STAT_CURR_FUNC );1002RES_BRK_CURR_STAT();1003CLEAR_LOCK_STACK();10041005/* remove the link to the calling function, in case this values bag1006stays alive due to higher variable reference */1007SET_BRK_CALL_FROM( ((Obj) 0));10081009/* switch back to the old values bag */1010SWITCH_TO_OLD_LVARS_AND_FREE( oldLvars );10111012CHECK_RECURSION_AFTER10131014/* return the result */1015{1016Obj returnObjStat;1017returnObjStat = TLS(ReturnObjStat);1018TLS(ReturnObjStat) = (Obj)0;1019return returnObjStat;1020}1021}10221023Obj DoExecFunc5args (1024Obj func,1025Obj arg1,1026Obj arg2,1027Obj arg3,1028Obj arg4,1029Obj arg5 )1030{1031Bag oldLvars; /* old values bag */1032REMEMBER_LOCKSTACK();1033OLD_BRK_CURR_STAT /* old executing statement */10341035CHECK_RECURSION_BEFORE10361037/* switch to a new values bag */1038SWITCH_TO_NEW_LVARS( func, 5, NLOC_FUNC(func), oldLvars );10391040/* enter the arguments */1041ASS_LVAR( 1, arg1 );1042ASS_LVAR( 2, arg2 );1043ASS_LVAR( 3, arg3 );1044ASS_LVAR( 4, arg4 );1045ASS_LVAR( 5, arg5 );10461047/* execute the statement sequence */1048REM_BRK_CURR_STAT();1049EXEC_STAT( FIRST_STAT_CURR_FUNC );1050RES_BRK_CURR_STAT();1051CLEAR_LOCK_STACK();10521053/* remove the link to the calling function, in case this values bag1054stays alive due to higher variable reference */1055SET_BRK_CALL_FROM( ((Obj) 0));10561057/* switch back to the old values bag */1058SWITCH_TO_OLD_LVARS_AND_FREE( oldLvars );10591060CHECK_RECURSION_AFTER10611062/* return the result */1063{1064Obj returnObjStat;1065returnObjStat = TLS(ReturnObjStat);1066TLS(ReturnObjStat) = (Obj)0;1067return returnObjStat;1068}1069}10701071Obj DoExecFunc6args (1072Obj func,1073Obj arg1,1074Obj arg2,1075Obj arg3,1076Obj arg4,1077Obj arg5,1078Obj arg6 )1079{1080Bag oldLvars; /* old values bag */1081REMEMBER_LOCKSTACK();1082OLD_BRK_CURR_STAT /* old executing statement */10831084CHECK_RECURSION_BEFORE10851086/* switch to a new values bag */1087SWITCH_TO_NEW_LVARS( func, 6, NLOC_FUNC(func), oldLvars );10881089/* enter the arguments */1090ASS_LVAR( 1, arg1 );1091ASS_LVAR( 2, arg2 );1092ASS_LVAR( 3, arg3 );1093ASS_LVAR( 4, arg4 );1094ASS_LVAR( 5, arg5 );1095ASS_LVAR( 6, arg6 );10961097/* execute the statement sequence */1098REM_BRK_CURR_STAT();1099EXEC_STAT( FIRST_STAT_CURR_FUNC );1100RES_BRK_CURR_STAT();1101CLEAR_LOCK_STACK();11021103/* remove the link to the calling function, in case this values bag1104stays alive due to higher variable reference */1105SET_BRK_CALL_FROM( ((Obj) 0));11061107/* switch back to the old values bag */1108SWITCH_TO_OLD_LVARS_AND_FREE( oldLvars );11091110CHECK_RECURSION_AFTER11111112/* return the result */1113{1114Obj returnObjStat;1115returnObjStat = TLS(ReturnObjStat);1116TLS(ReturnObjStat) = (Obj)0;1117return returnObjStat;1118}1119}11201121Obj DoExecFuncXargs (1122Obj func,1123Obj args )1124{1125Bag oldLvars; /* old values bag */1126REMEMBER_LOCKSTACK();1127OLD_BRK_CURR_STAT /* old executing statement */1128UInt len; /* number of arguments */1129UInt i; /* loop variable */11301131CHECK_RECURSION_BEFORE11321133/* check the number of arguments */1134len = NARG_FUNC( func );1135while ( len != LEN_PLIST( args ) ) {1136args = ErrorReturnObj(1137"Function Calls: number of arguments must be %d (not %d)",1138len, LEN_PLIST( args ),1139"you can replace the <list> of arguments via 'return <list>;'" );1140PLAIN_LIST( args );1141}11421143/* switch to a new values bag */1144SWITCH_TO_NEW_LVARS( func, len, NLOC_FUNC(func), oldLvars );11451146/* enter the arguments */1147for ( i = 1; i <= len; i++ ) {1148ASS_LVAR( i, ELM_PLIST( args, i ) );1149}11501151/* execute the statement sequence */1152REM_BRK_CURR_STAT();1153EXEC_STAT( FIRST_STAT_CURR_FUNC );1154RES_BRK_CURR_STAT();1155CLEAR_LOCK_STACK();11561157/* remove the link to the calling function, in case this values bag1158stays alive due to higher variable reference */1159SET_BRK_CALL_FROM( ((Obj) 0));11601161/* switch back to the old values bag */1162SWITCH_TO_OLD_LVARS_AND_FREE( oldLvars );11631164CHECK_RECURSION_AFTER11651166/* return the result */1167{1168Obj returnObjStat;1169returnObjStat = TLS(ReturnObjStat);1170TLS(ReturnObjStat) = (Obj)0;1171return returnObjStat;1172}1173}1174117511761177Obj DoPartialUnWrapFunc(Obj func, Obj args) {11781179Bag oldLvars; /* old values bag */1180OLD_BRK_CURR_STAT /* old executing statement */1181UInt named; /* number of arguments */1182UInt i; /* loop variable */1183UInt len;1184Obj argx;118511861187named = ((UInt)-NARG_FUNC(func))-1;1188len = LEN_PLIST(args);11891190if (named > len) { /* Can happen for > 6 arguments */1191argx = NargError(func, len);1192return DoOperation2Args(CallFuncListOper, func, argx);1193}11941195CHECK_RECURSION_BEFORE1196SWITCH_TO_NEW_LVARS( func, named+1, NLOC_FUNC(func), oldLvars );11971198for (i = 1; i <= named; i++) {1199ASS_LVAR(i, ELM_PLIST(args,i));1200}1201for (i = named+1; i <= len; i++) {1202SET_ELM_PLIST(args, i-named, ELM_PLIST(args,i));1203}1204SET_LEN_PLIST(args, len-named);1205ASS_LVAR(named+1, args);1206/* execute the statement sequence */1207REM_BRK_CURR_STAT();1208EXEC_STAT( FIRST_STAT_CURR_FUNC );1209RES_BRK_CURR_STAT();12101211/* remove the link to the calling function, in case this values bag1212stays alive due to higher variable reference */1213SET_BRK_CALL_FROM( ((Obj) 0));12141215/* switch back to the old values bag */1216SWITCH_TO_OLD_LVARS( oldLvars );12171218CHECK_RECURSION_AFTER12191220/* return the result */1221{1222Obj returnObjStat;1223returnObjStat = TLS(ReturnObjStat);1224TLS(ReturnObjStat) = (Obj)0;1225return returnObjStat;1226}1227}12281229/****************************************************************************1230**1231*F MakeFunction(<fexp>) . . . . . . . . . . . . . . . . . . make a function1232**1233** 'MakeFunction' makes a function from the function expression bag <fexp>.1234*/1235Obj MakeFunction (1236Obj fexp )1237{1238Obj func; /* function, result */1239ObjFunc hdlr; /* handler */12401241/* select the right handler */1242if ( NARG_FUNC(fexp) == 0 ) hdlr = DoExecFunc0args;1243else if ( NARG_FUNC(fexp) == 1 ) hdlr = DoExecFunc1args;1244else if ( NARG_FUNC(fexp) == 2 ) hdlr = DoExecFunc2args;1245else if ( NARG_FUNC(fexp) == 3 ) hdlr = DoExecFunc3args;1246else if ( NARG_FUNC(fexp) == 4 ) hdlr = DoExecFunc4args;1247else if ( NARG_FUNC(fexp) == 5 ) hdlr = DoExecFunc5args;1248else if ( NARG_FUNC(fexp) == 6 ) hdlr = DoExecFunc6args;1249else if ( NARG_FUNC(fexp) >= 7 ) hdlr = DoExecFuncXargs;1250else if ( NARG_FUNC(fexp) == -1 ) hdlr = DoExecFunc1args;1251else /* NARG_FUNC(fexp) < -1 */ hdlr = DoPartialUnWrapFunc;12521253/* make the function */1254func = NewFunctionT( T_FUNCTION, SIZE_FUNC,1255NAME_FUNC( fexp ),1256NARG_FUNC( fexp ), NAMS_FUNC( fexp ),1257hdlr );12581259/* install the things an interpreted function needs */1260NLOC_FUNC( func ) = NLOC_FUNC( fexp );1261BODY_FUNC( func ) = BODY_FUNC( fexp );1262ENVI_FUNC( func ) = TLS(CurrLVars);1263/* the 'CHANGED_BAG(TLS(CurrLVars))' is needed because it is delayed */1264CHANGED_BAG( TLS(CurrLVars) );1265FEXS_FUNC( func ) = FEXS_FUNC( fexp );12661267/* return the function */1268return func;1269}127012711272/****************************************************************************1273**1274*F EvalFuncExpr(<expr>) . . . evaluate a function expression to a function1275**1276** 'EvalFuncExpr' evaluates the function expression <expr> to a function.1277*/1278Obj EvalFuncExpr (1279Expr expr )1280{1281Obj fexs; /* func. expr. list of curr. func. */1282Obj fexp; /* function expression bag */12831284/* get the function expression bag */1285fexs = FEXS_FUNC( CURR_FUNC );1286fexp = ELM_PLIST( fexs, (Int)(ADDR_EXPR(expr)[0]) );12871288/* and make the function */1289return MakeFunction( fexp );1290}129112921293/****************************************************************************1294**1295*F PrintFuncExpr(<expr>) . . . . . . . . . . . . print a function expression1296**1297** 'PrintFuncExpr' prints a function expression.1298*/1299void PrintFuncExpr (1300Expr expr )1301{1302Obj fexs; /* func. expr. list of curr. func. */1303Obj fexp; /* function expression bag */13041305/* get the function expression bag */1306fexs = FEXS_FUNC( CURR_FUNC );1307fexp = ELM_PLIST( fexs, (Int)(ADDR_EXPR(expr)[0]) );1308PrintFunction( fexp );1309/* Pr("function ... end",0L,0L); */1310}131113121313/****************************************************************************1314**1315*F PrintProccall(<call>) . . . . . . . . . . . . . . print a procedure call1316**1317** 'PrintProccall' prints a procedure call.1318*/1319extern void PrintFunccall (1320Expr call );13211322extern void PrintFunccallOpts (1323Expr call );13241325void PrintProccall (1326Stat call )1327{1328PrintFunccall( call );1329Pr( ";", 0L, 0L );1330}13311332void PrintProccallOpts (1333Stat call )1334{1335PrintFunccallOpts( call );1336Pr( ";", 0L, 0L );1337}133813391340/****************************************************************************1341**1342*F PrintFunccall(<call>) . . . . . . . . . . . . . . . print a function call1343**1344** 'PrintFunccall' prints a function call.1345*/1346static void PrintFunccall1 (1347Expr call )1348{1349UInt i; /* loop variable */13501351/* print the expression that should evaluate to a function */1352Pr("%2>",0L,0L);1353PrintExpr( FUNC_CALL(call) );13541355/* print the opening parenthesis */1356Pr("%<( %>",0L,0L);13571358/* print the expressions that evaluate to the actual arguments */1359for ( i = 1; i <= NARG_SIZE_CALL( SIZE_EXPR(call) ); i++ ) {1360PrintExpr( ARGI_CALL(call,i) );1361if ( i != NARG_SIZE_CALL( SIZE_EXPR(call) ) ) {1362Pr("%<, %>",0L,0L);1363}1364}13651366return;13671368}13691370void PrintFunccall (1371Expr call )1372{1373PrintFunccall1( call );13741375/* print the closing parenthesis */1376Pr(" %2<)",0L,0L);1377}137813791380void PrintFunccallOpts (1381Expr call )1382{1383PrintFunccall1( ADDR_STAT( call )[1]);1384Pr(" :%2> ", 0L, 0L);1385PrintRecExpr1 ( ADDR_STAT( call )[0]);1386Pr(" %4<)",0L,0L);1387}1388138913901391/****************************************************************************1392**1393*F ExecBegin() . . . . . . . . . . . . . . . . . . . . . begin an execution1394*F ExecEnd(<error>) . . . . . . . . . . . . . . . . . . . end an execution1395*/1396Obj ExecState;13971398void ExecBegin ( Obj frame )1399{1400Obj execState; /* old execution state */14011402/* remember the old execution state */1403execState = NewBag( T_PLIST, 4*sizeof(Obj) );1404ADDR_OBJ(execState)[0] = (Obj)3;1405ADDR_OBJ(execState)[1] = TLS(ExecState);1406ADDR_OBJ(execState)[2] = TLS(CurrLVars);1407/* the 'CHANGED_BAG(TLS(CurrLVars))' is needed because it is delayed */1408CHANGED_BAG( TLS(CurrLVars) );1409ADDR_OBJ(execState)[3] = INTOBJ_INT((Int)TLS(CurrStat));1410TLS(ExecState) = execState;14111412/* set up new state */1413SWITCH_TO_OLD_LVARS( frame );1414SET_BRK_CURR_STAT( 0 );1415}14161417void ExecEnd (1418UInt error )1419{1420/* if everything went fine */1421if ( ! error ) {14221423/* the state must be primal again */1424assert( TLS(CurrStat) == 0 );14251426/* switch back to the old state */1427SET_BRK_CURR_STAT( (Stat)INT_INTOBJ((ADDR_OBJ(TLS(ExecState))[3]) ));1428SWITCH_TO_OLD_LVARS( ADDR_OBJ(TLS(ExecState))[2] );1429TLS(ExecState) = ADDR_OBJ(TLS(ExecState))[1];14301431}14321433/* otherwise clean up the mess */1434else {14351436/* switch back to the old state */1437SET_BRK_CURR_STAT( (Stat)INT_INTOBJ((ADDR_OBJ(TLS(ExecState))[3]) ));1438SWITCH_TO_OLD_LVARS( ADDR_OBJ(TLS(ExecState))[2] );1439TLS(ExecState) = ADDR_OBJ(TLS(ExecState))[1];14401441}1442}14431444/****************************************************************************1445**1446*F FuncSetRecursionTrapInterval( <self>, <interval> )1447**1448*/14491450Obj FuncSetRecursionTrapInterval( Obj self, Obj interval )1451{1452while (!IS_INTOBJ(interval) || INT_INTOBJ(interval) < 0)1453interval = ErrorReturnObj( "SetRecursionTrapInterval( <interval> ): "1454"<interval> must be a non-negative small integer",14550L, 0L,1456"you can replace <interval> via 'return <interval>;'");1457RecursionTrapInterval = INT_INTOBJ( interval);1458return 0;1459}146014611462/****************************************************************************1463**1464*F * * * * * * * * * * * * * initialize package * * * * * * * * * * * * * * *1465*/14661467/****************************************************************************1468**1469*V GVarFuncs . . . . . . . . . . . . . . . . . . list of functions to export1470*/1471static StructGVarFunc GVarFuncs [] = {14721473{ "SetRecursionTrapInterval", 1, "interval",1474FuncSetRecursionTrapInterval, "src/funcs.c:SetRecursionTrapInterval" },14751476{ 0 }14771478};14791480/****************************************************************************1481**1482*F InitLibrary( <module> ) . . . . . . . initialise library data structures1483*/1484static Int InitLibrary (1485StructInitInfo * module )1486{1487/* init filters and functions */1488InitGVarFuncsFromTable( GVarFuncs );148914901491/* return success */1492return 0;1493}149414951496/****************************************************************************1497**14981499*F InitKernel( <module> ) . . . . . . . . initialise kernel data structures1500*/1501static Int InitKernel (1502StructInitInfo * module )1503{1504RecursionTrapInterval = 5000;1505InitCopyGVar("STEVES_TRACING", &STEVES_TRACING);15061507/* make the global variable known to Gasman */1508InitGlobalBag( &ExecState, "src/funcs.c:ExecState" );15091510/* Register the handler for our exported function */1511InitHdlrFuncsFromTable( GVarFuncs );15121513/* Import some functions from the library */1514ImportFuncFromLibrary( "PushOptions", &PushOptions );1515ImportFuncFromLibrary( "PopOptions", &PopOptions );15161517/* use short cookies to save space in saved workspace */1518InitHandlerFunc( DoExecFunc0args, "i0");1519InitHandlerFunc( DoExecFunc1args, "i1");1520InitHandlerFunc( DoExecFunc2args, "i2");1521InitHandlerFunc( DoExecFunc3args, "i3");1522InitHandlerFunc( DoExecFunc4args, "i4");1523InitHandlerFunc( DoExecFunc5args, "i5");1524InitHandlerFunc( DoExecFunc6args, "i6");1525InitHandlerFunc( DoExecFuncXargs, "iX");1526InitHandlerFunc( DoPartialUnWrapFunc, "pUW");15271528/* install the evaluators and executors */1529InstallExecStatFunc( T_PROCCALL_0ARGS , ExecProccall0args);1530InstallExecStatFunc( T_PROCCALL_1ARGS , ExecProccall1args);1531InstallExecStatFunc( T_PROCCALL_2ARGS , ExecProccall2args);1532InstallExecStatFunc( T_PROCCALL_3ARGS , ExecProccall3args);1533InstallExecStatFunc( T_PROCCALL_4ARGS , ExecProccall4args);1534InstallExecStatFunc( T_PROCCALL_5ARGS , ExecProccall5args);1535InstallExecStatFunc( T_PROCCALL_6ARGS , ExecProccall6args);1536InstallExecStatFunc( T_PROCCALL_XARGS , ExecProccallXargs);1537InstallExecStatFunc( T_PROCCALL_OPTS , ExecProccallOpts);15381539InstallEvalExprFunc( T_FUNCCALL_0ARGS , EvalFunccall0args);1540InstallEvalExprFunc( T_FUNCCALL_1ARGS , EvalFunccall1args);1541InstallEvalExprFunc( T_FUNCCALL_2ARGS , EvalFunccall2args);1542InstallEvalExprFunc( T_FUNCCALL_3ARGS , EvalFunccall3args);1543InstallEvalExprFunc( T_FUNCCALL_4ARGS , EvalFunccall4args);1544InstallEvalExprFunc( T_FUNCCALL_5ARGS , EvalFunccall5args);1545InstallEvalExprFunc( T_FUNCCALL_6ARGS , EvalFunccall6args);1546InstallEvalExprFunc( T_FUNCCALL_XARGS , EvalFunccallXargs);1547InstallEvalExprFunc( T_FUNCCALL_OPTS , EvalFunccallOpts);1548InstallEvalExprFunc( T_FUNC_EXPR , EvalFuncExpr);15491550/* install the printers */1551InstallPrintStatFunc( T_PROCCALL_0ARGS , PrintProccall);1552InstallPrintStatFunc( T_PROCCALL_1ARGS , PrintProccall);1553InstallPrintStatFunc( T_PROCCALL_2ARGS , PrintProccall);1554InstallPrintStatFunc( T_PROCCALL_3ARGS , PrintProccall);1555InstallPrintStatFunc( T_PROCCALL_4ARGS , PrintProccall);1556InstallPrintStatFunc( T_PROCCALL_5ARGS , PrintProccall);1557InstallPrintStatFunc( T_PROCCALL_6ARGS , PrintProccall);1558InstallPrintStatFunc( T_PROCCALL_XARGS , PrintProccall);1559InstallPrintStatFunc( T_PROCCALL_OPTS , PrintProccallOpts);1560InstallPrintExprFunc( T_FUNCCALL_0ARGS , PrintFunccall);1561InstallPrintExprFunc( T_FUNCCALL_1ARGS , PrintFunccall);1562InstallPrintExprFunc( T_FUNCCALL_2ARGS , PrintFunccall);1563InstallPrintExprFunc( T_FUNCCALL_3ARGS , PrintFunccall);1564InstallPrintExprFunc( T_FUNCCALL_4ARGS , PrintFunccall);1565InstallPrintExprFunc( T_FUNCCALL_5ARGS , PrintFunccall);1566InstallPrintExprFunc( T_FUNCCALL_6ARGS , PrintFunccall);1567InstallPrintExprFunc( T_FUNCCALL_XARGS , PrintFunccall);1568InstallPrintExprFunc( T_FUNCCALL_OPTS , PrintFunccallOpts);1569InstallPrintExprFunc( T_FUNC_EXPR , PrintFuncExpr);15701571/* return success */1572return 0;1573}157415751576/****************************************************************************1577**1578*F InitInfoFuncs() . . . . . . . . . . . . . . . . . table of init functions1579*/1580static StructInitInfo module = {1581MODULE_BUILTIN, /* type */1582"funcs", /* name */15830, /* revision entry of c file */15840, /* revision entry of h file */15850, /* version */15860, /* crc */1587InitKernel, /* initKernel */1588InitLibrary, /* initLibrary */15890, /* checkInit */15900, /* preSave */15910, /* postSave */15920 /* postRestore */1593};15941595StructInitInfo * InitInfoFuncs ( void )1596{1597return &module;1598}159916001601/****************************************************************************1602**16031604*E funcs.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . ends here1605*/160616071608