/* handler for function 6 */ static Obj HdlrFunc6 ( Obj self ) { Obj t_1 = 0; Bag oldFrame; /* allocate new stack frame */ SWITCH_TO_NEW_FRAME(self,0,0,oldFrame); /* f1( 2 ); */ t_1 = GF_f1; CALL_1ARGS( t_1, INTOBJ_INT(2) ); /* f2( 2, 3 ); */ t_1 = GF_f2; CALL_2ARGS( t_1, INTOBJ_INT(2), INTOBJ_INT(3) ); /* f3( ); */ t_1 = GF_f3; CALL_0ARGS( t_1 ); /* f3( 2 ); */ t_1 = GF_f3; CALL_1ARGS( t_1, INTOBJ_INT(2) ); /* f3( 2, 3, 4 ); */ t_1 = GF_f3; CALL_3ARGS( t_1, INTOBJ_INT(2), INTOBJ_INT(3), INTOBJ_INT(4) ); /* f4( 1 ); */ t_1 = GF_f4; CALL_1ARGS( t_1, INTOBJ_INT(1) ); /* f4( 1, 2 ); */ t_1 = GF_f4; CALL_2ARGS( t_1, INTOBJ_INT(1), INTOBJ_INT(2) ); /* f4( 1, 2, 3 ); */ t_1 = GF_f4; CALL_3ARGS( t_1, INTOBJ_INT(1), INTOBJ_INT(2), INTOBJ_INT(3) ); /* return; */ SWITCH_TO_OLD_FRAME(oldFrame); return 0; /* return; */ SWITCH_TO_OLD_FRAME(oldFrame); return 0; }
Obj GAP_CallFuncArray(Obj func, UInt narg, Obj args[]) { Obj result; Obj list; if (TNUM_OBJ(func) == T_FUNCTION) { // call the function switch (narg) { case 0: result = CALL_0ARGS(func); break; case 1: result = CALL_1ARGS(func, args[0]); break; case 2: result = CALL_2ARGS(func, args[0], args[1]); break; case 3: result = CALL_3ARGS(func, args[0], args[1], args[2]); break; case 4: result = CALL_4ARGS(func, args[0], args[1], args[2], args[3]); break; case 5: result = CALL_5ARGS(func, args[0], args[1], args[2], args[3], args[4]); break; case 6: result = CALL_6ARGS(func, args[0], args[1], args[2], args[3], args[4], args[5]); break; default: list = NewPlistFromArray(args, narg); result = CALL_XARGS(func, list); } } else { list = NewPlistFromArray(args, narg); result = DoOperation2Args(CallFuncListOper, func, list); } return result; }
/* 'InitLibrary' sets up gvars, rnams, functions */ static Int InitLibrary ( StructInitInfo * module ) { Obj func1; Obj body1; /* Complete Copy/Fopy registration */ UpdateCopyFopyInfo(); FileName = MakeImmString( "print_various.g" ); PostRestore(module); /* create all the functions defined in this module */ func1 = NewFunction(NameFunc[1],0,0,HdlrFunc1); SET_ENVI_FUNC( func1, STATE(CurrLVars) ); body1 = NewFunctionBody(); SET_BODY_FUNC( func1, body1 ); CHANGED_BAG( func1 ); CALL_0ARGS( func1 ); /* return success */ return 0; }
/* 'InitLibrary' sets up gvars, rnams, functions */ static Int InitLibrary ( StructInitInfo * module ) { Obj func1; Obj body1; /* Complete Copy/Fopy registration */ UpdateCopyFopyInfo(); /* global variables used in handlers */ G_IS__FUNCTION = GVarName( "IS_FUNCTION" ); G_ADD__LIST = GVarName( "ADD_LIST" ); G_Error = GVarName( "Error" ); G_IS__IDENTICAL__OBJ = GVarName( "IS_IDENTICAL_OBJ" ); G_AND__FLAGS = GVarName( "AND_FLAGS" ); G_HASH__FLAGS = GVarName( "HASH_FLAGS" ); G_WITH__HIDDEN__IMPS__FLAGS = GVarName( "WITH_HIDDEN_IMPS_FLAGS" ); G_IS__SUBSET__FLAGS = GVarName( "IS_SUBSET_FLAGS" ); G_TRUES__FLAGS = GVarName( "TRUES_FLAGS" ); G_FLAGS__FILTER = GVarName( "FLAGS_FILTER" ); G_WITH__HIDDEN__IMPS__FLAGS__COUNT = GVarName( "WITH_HIDDEN_IMPS_FLAGS_COUNT" ); G_WITH__HIDDEN__IMPS__FLAGS__CACHE__MISS = GVarName( "WITH_HIDDEN_IMPS_FLAGS_CACHE_MISS" ); G_WITH__HIDDEN__IMPS__FLAGS__CACHE__HIT = GVarName( "WITH_HIDDEN_IMPS_FLAGS_CACHE_HIT" ); G_IMPLICATIONS = GVarName( "IMPLICATIONS" ); G_WITH__IMPS__FLAGS__CACHE = GVarName( "WITH_IMPS_FLAGS_CACHE" ); G_WITH__IMPS__FLAGS__COUNT = GVarName( "WITH_IMPS_FLAGS_COUNT" ); G_WITH__IMPS__FLAGS__CACHE__HIT = GVarName( "WITH_IMPS_FLAGS_CACHE_HIT" ); G_WITH__IMPS__FLAGS__CACHE__MISS = GVarName( "WITH_IMPS_FLAGS_CACHE_MISS" ); G_CLEAR__IMP__CACHE = GVarName( "CLEAR_IMP_CACHE" ); G_BIND__GLOBAL = GVarName( "BIND_GLOBAL" ); G_UNBIND__GLOBAL = GVarName( "UNBIND_GLOBAL" ); G_RANK__FILTERS = GVarName( "RANK_FILTERS" ); G_RankFilter = GVarName( "RankFilter" ); G_RANK__FILTER = GVarName( "RANK_FILTER" ); G_RANK__FILTER__LIST__CURRENT = GVarName( "RANK_FILTER_LIST_CURRENT" ); G_RANK__FILTER__LIST = GVarName( "RANK_FILTER_LIST" ); G_RANK__FILTER__COUNT = GVarName( "RANK_FILTER_COUNT" ); /* record names used in handlers */ /* information for the functions */ C_NEW_STRING( DefaultName, 14, "local function" ); C_NEW_STRING( FileName, 21, "GAPROOT/lib/filter1.g" ); NameFunc[1] = DefaultName; NamsFunc[1] = 0; NargFunc[1] = 0; NameFunc[2] = DefaultName; NamsFunc[2] = 0; NargFunc[2] = 0; NameFunc[3] = DefaultName; NamsFunc[3] = 0; NargFunc[3] = 1; NameFunc[4] = DefaultName; NamsFunc[4] = 0; NargFunc[4] = 1; NameFunc[5] = DefaultName; NamsFunc[5] = 0; NargFunc[5] = 1; NameFunc[6] = DefaultName; NamsFunc[6] = 0; NargFunc[6] = 1; /* create all the functions defined in this module */ func1 = NewFunction(NameFunc[1],NargFunc[1],NamsFunc[1],HdlrFunc1); ENVI_FUNC( func1 ) = TLS(CurrLVars); CHANGED_BAG( TLS(CurrLVars) ); body1 = NewBag( T_BODY, NUMBER_HEADER_ITEMS_BODY*sizeof(Obj)); BODY_FUNC( func1 ) = body1; CHANGED_BAG( func1 ); CALL_0ARGS( func1 ); /* return success */ return 0; }
/* handler for function 2 */ static Obj HdlrFunc2 ( Obj self ) { Obj t_1 = 0; Obj t_2 = 0; Obj t_3 = 0; Bag oldFrame; /* allocate new stack frame */ SWITCH_TO_NEW_FRAME(self,0,0,oldFrame); /* Print( AssertionLevel( ), "\n" ); */ t_1 = GF_Print; t_3 = GF_AssertionLevel; t_2 = CALL_0ARGS( t_3 ); CHECK_FUNC_RESULT( t_2 ) t_3 = MakeString( "\n" ); CALL_2ARGS( t_1, t_2, t_3 ); /* Assert( ... ); */ if ( ! LT(CurrentAssertionLevel, INTOBJ_INT(1)) ) { t_2 = False; t_1 = (Obj)(UInt)(t_2 != False); if ( ! t_1 ) { t_2 = MakeString( "fail-A" ); if ( t_2 != (Obj)(UInt)0 ){ if ( IS_STRING_REP ( t_2 ) ) PrintString1( t_2); else PrintObj(t_2); } } } /* Assert( ... ); */ if ( ! LT(CurrentAssertionLevel, INTOBJ_INT(1)) ) { t_2 = False; t_1 = (Obj)(UInt)(t_2 != False); if ( ! t_1 ) { ErrorReturnVoid("Assertion failure",0L,0L,"you may 'return;'"); } } /* Assert( ... ); */ if ( ! LT(CurrentAssertionLevel, INTOBJ_INT(0)) ) { t_2 = True; t_1 = (Obj)(UInt)(t_2 != False); if ( ! t_1 ) { t_2 = MakeString( "fail-B" ); if ( t_2 != (Obj)(UInt)0 ){ if ( IS_STRING_REP ( t_2 ) ) PrintString1( t_2); else PrintObj(t_2); } } } /* Assert( ... ); */ if ( ! LT(CurrentAssertionLevel, INTOBJ_INT(0)) ) { t_2 = True; t_1 = (Obj)(UInt)(t_2 != False); if ( ! t_1 ) { ErrorReturnVoid("Assertion failure",0L,0L,"you may 'return;'"); } } /* SetAssertionLevel( 2 ); */ t_1 = GF_SetAssertionLevel; CALL_1ARGS( t_1, INTOBJ_INT(2) ); /* Print( AssertionLevel( ), "\n" ); */ t_1 = GF_Print; t_3 = GF_AssertionLevel; t_2 = CALL_0ARGS( t_3 ); CHECK_FUNC_RESULT( t_2 ) t_3 = MakeString( "\n" ); CALL_2ARGS( t_1, t_2, t_3 ); /* Assert( ... ); */ if ( ! LT(CurrentAssertionLevel, INTOBJ_INT(3)) ) { t_2 = False; t_1 = (Obj)(UInt)(t_2 != False); if ( ! t_1 ) { t_2 = MakeString( "fail-C" ); if ( t_2 != (Obj)(UInt)0 ){ if ( IS_STRING_REP ( t_2 ) ) PrintString1( t_2); else PrintObj(t_2); } } } /* Assert( ... ); */ if ( ! LT(CurrentAssertionLevel, INTOBJ_INT(3)) ) { t_2 = False; t_1 = (Obj)(UInt)(t_2 != False); if ( ! t_1 ) { ErrorReturnVoid("Assertion failure",0L,0L,"you may 'return;'"); } } /* Assert( ... ); */ if ( ! LT(CurrentAssertionLevel, INTOBJ_INT(2)) ) { t_2 = True; t_1 = (Obj)(UInt)(t_2 != False); if ( ! t_1 ) { t_2 = MakeString( "fail-D" ); if ( t_2 != (Obj)(UInt)0 ){ if ( IS_STRING_REP ( t_2 ) ) PrintString1( t_2); else PrintObj(t_2); } } } /* Assert( ... ); */ if ( ! LT(CurrentAssertionLevel, INTOBJ_INT(2)) ) { t_2 = True; t_1 = (Obj)(UInt)(t_2 != False); if ( ! t_1 ) { ErrorReturnVoid("Assertion failure",0L,0L,"you may 'return;'"); } } /* Assert( ... ); */ if ( ! LT(CurrentAssertionLevel, INTOBJ_INT(2)) ) { t_2 = False; t_1 = (Obj)(UInt)(t_2 != False); if ( ! t_1 ) { t_2 = MakeString( "pass!\n" ); if ( t_2 != (Obj)(UInt)0 ){ if ( IS_STRING_REP ( t_2 ) ) PrintString1( t_2); else PrintObj(t_2); } } } /* Print( "end of function\n" ); */ t_1 = GF_Print; t_2 = MakeString( "end of function\n" ); CALL_1ARGS( t_1, t_2 ); /* return; */ SWITCH_TO_OLD_FRAME(oldFrame); return 0; /* return; */ SWITCH_TO_OLD_FRAME(oldFrame); return 0; }