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 compiled.h GAP source Martin Schönert3**4** This package defines macros and functions that are used by compiled code.5** Those macros and functions should go into the appropriate packages.6*/78#ifndef GAP_COMPILED_H9#define GAP_COMPILED_H1011#ifdef __cplusplus12extern "C" {13#define GAP_IN_EXTERN_C14#endif1516#include "system.h" /* system dependent part */1718#include "gasman.h" /* garbage collector */19#include "objects.h" /* objects */20#include "scanner.h" /* scanner */2122#include "gap.h" /* error handling, initialisation */2324#include "read.h" /* reader */2526#include "gvars.h" /* global variables */27#include "calls.h" /* generic call mechanism */28#include "opers.h" /* generic operations */2930#include "ariths.h" /* basic arithmetic */3132#include "integer.h" /* integers */33#include "rational.h" /* rationals */34#include "cyclotom.h" /* cyclotomics */35#include "finfield.h" /* finite fields and ff elements */36#include "macfloat.h" /* machine floats */3738#include "bool.h" /* booleans */39#include "permutat.h" /* permutations */40#include "trans.h" /* transformation */41#include "pperm.h" /* partial perms */4243#include "records.h" /* generic records */44#include "precord.h" /* plain records */4546#include "lists.h" /* generic lists */47#include "listoper.h" /* operations for generic lists */48#include "listfunc.h" /* functions for generic lists */49#include "plist.h" /* plain lists */50#include "set.h" /* plain sets */51#include "vector.h" /* functions for plain vectors */52#include "blister.h" /* boolean lists */53#include "range.h" /* ranges */54#include "string.h" /* strings */5556#include "code.h" /* coder */57#include "tls.h" /* thread-local storage */5859#include "objfgelm.h" /* objects of free groups */60#include "objpcgel.h" /* objects of polycyclic groups */61#include "objscoll.h" /* single collector */62#include "objcftl.h" /* from the left collect */6364#include "dt.h" /* deep thought */65#include "dteval.h" /* deep thought evaluation */6667#include "sctable.h" /* structure constant table */68#include "costab.h" /* coset table */69#include "tietze.h" /* tietze helper functions */7071#include "exprs.h" /* expressions */72#include "stats.h" /* statements */73#include "funcs.h" /* functions */747576#include "intrprtr.h" /* interpreter */7778#include "compiler.h" /* compiler */7980#include "compstat.h" /* statically linked modules */8182#include "saveload.h" /* saving and loading */8384#include "streams.h" /* streams package */85#include "sysfiles.h" /* file input/output */86#include "weakptr.h" /* weak pointers */8788#include "vars.h" /* variables */8990#include "aobjects.h" /* atomic variables */91extern Obj InfoDecision;92extern Obj InfoDoPrint;93extern Obj CurrentAssertionLevel;9495extern Obj NewAndFilter (96Obj oper1,97Obj oper2 );9899100/* types, should go into 'gvars.c' and 'records.c' * * * * * * * * * * * * */101102typedef UInt GVar;103104typedef UInt RNam;105106107/* checks, should go into 'gap.c' * * * * * * * * * * * * * * * * * * * * */108109#define CHECK_BOUND(obj,name) \110if ( obj == 0 ) ErrorQuitBound(name);111112#define CHECK_FUNC_RESULT(obj) \113if ( obj == 0 ) ErrorQuitFuncResult();114115#define CHECK_INT_SMALL(obj) \116if ( ! IS_INTOBJ(obj) ) ErrorQuitIntSmall(obj);117118#define CHECK_INT_SMALL_POS(obj) \119if ( ! IS_POS_INTOBJ(obj) ) ErrorQuitIntSmallPos(obj);120121#define CHECK_INT_POS(obj) \122if ( TNUM_OBJ(obj) != T_INTPOS && ( ! IS_POS_INTOBJ(obj)) ) ErrorQuitIntPos(obj);123124#define CHECK_BOOL(obj) \125if ( obj != True && obj != False ) ErrorQuitBool(obj);126127#define CHECK_FUNC(obj) \128if ( TNUM_OBJ(obj) != T_FUNCTION ) ErrorQuitFunc(obj);129130#define CHECK_NR_ARGS(narg,args) \131if ( narg != LEN_PLIST(args) ) ErrorQuitNrArgs(narg,args);132133134/* higher variables, should go into 'vars.c' * * * * * * * * * * * * * * * */135136#define SWITCH_TO_NEW_FRAME SWITCH_TO_NEW_LVARS137#define SWITCH_TO_OLD_FRAME SWITCH_TO_OLD_LVARS138139#define CURR_FRAME TLS(CurrLVars)140#define CURR_FRAME_1UP ENVI_FUNC( PTR_BAG( CURR_FRAME )[0] )141#define CURR_FRAME_2UP ENVI_FUNC( PTR_BAG( CURR_FRAME_1UP )[0] )142#define CURR_FRAME_3UP ENVI_FUNC( PTR_BAG( CURR_FRAME_2UP )[0] )143#define CURR_FRAME_4UP ENVI_FUNC( PTR_BAG( CURR_FRAME_3UP )[0] )144#define CURR_FRAME_5UP ENVI_FUNC( PTR_BAG( CURR_FRAME_4UP )[0] )145#define CURR_FRAME_6UP ENVI_FUNC( PTR_BAG( CURR_FRAME_5UP )[0] )146#define CURR_FRAME_7UP ENVI_FUNC( PTR_BAG( CURR_FRAME_6UP )[0] )147148/* #define OBJ_LVAR(lvar) TLS(PtrLVars)[(lvar)+2] */149#define OBJ_LVAR_0UP(lvar) \150OBJ_LVAR(lvar)151#define OBJ_LVAR_1UP(lvar) \152PTR_BAG(CURR_FRAME_1UP)[(lvar)+2]153#define OBJ_LVAR_2UP(lvar) \154PTR_BAG(CURR_FRAME_2UP)[(lvar)+2]155#define OBJ_LVAR_3UP(lvar) \156PTR_BAG(CURR_FRAME_3UP)[(lvar)+2]157#define OBJ_LVAR_4UP(lvar) \158PTR_BAG(CURR_FRAME_4UP)[(lvar)+2]159#define OBJ_LVAR_5UP(lvar) \160PTR_BAG(CURR_FRAME_5UP)[(lvar)+2]161#define OBJ_LVAR_6UP(lvar) \162PTR_BAG(CURR_FRAME_6UP)[(lvar)+2]163#define OBJ_LVAR_7UP(lvar) \164PTR_BAG(CURR_FRAME_7UP)[(lvar)+2]165#define OBJ_LVAR_8UP(lvar) \166PTR_BAG(CURR_FRAME_8UP)[(lvar)+2]167168/* #define ASS_LVAR(lvar,obj) do { TLS(PtrLVars)[(lvar)+2] = (obj); } while ( 0 ) */169#define ASS_LVAR_0UP(lvar,obj) \170ASS_LVAR(lvar,obj)171#define ASS_LVAR_1UP(lvar,obj) \172do { PTR_BAG(CURR_FRAME_1UP)[(lvar)+2] = (obj); CHANGED_BAG(CURR_FRAME_1UP); } while ( 0 )173#define ASS_LVAR_2UP(lvar,obj) \174do { PTR_BAG(CURR_FRAME_2UP)[(lvar)+2] = (obj); CHANGED_BAG(CURR_FRAME_2UP); } while ( 0 )175#define ASS_LVAR_3UP(lvar,obj) \176do { PTR_BAG(CURR_FRAME_3UP)[(lvar)+2] = (obj); CHANGED_BAG(CURR_FRAME_3UP); } while ( 0 )177#define ASS_LVAR_4UP(lvar,obj) \178do { PTR_BAG(CURR_FRAME_4UP)[(lvar)+2] = (obj); CHANGED_BAG(CURR_FRAME_4UP); } while ( 0 )179#define ASS_LVAR_5UP(lvar,obj) \180do { PTR_BAG(CURR_FRAME_5UP)[(lvar)+2] = (obj); CHANGED_BAG(CURR_FRAME_5UP); } while ( 0 )181#define ASS_LVAR_6UP(lvar,obj) \182do { PTR_BAG(CURR_FRAME_6UP)[(lvar)+2] = (obj); CHANGED_BAG(CURR_FRAME_6UP); } while ( 0 )183#define ASS_LVAR_7UP(lvar,obj) \184do { PTR_BAG(CURR_FRAME_7UP)[(lvar)+2] = (obj); CHANGED_BAG(CURR_FRAME_7UP); } while ( 0 )185#define ASS_LVAR_8UP(lvar,obj) \186do { PTR_BAG(CURR_FRAME_8UP)[(lvar)+2] = (obj); CHANGED_BAG(CURR_FRAME_8UP); } while ( 0 )187188189/* objects, should into 'objects.c' * * * * * * * * * * * * * * * * * * * */190191/* there should be a function for C_ELM_POSOBJ */192#define C_ELM_POSOBJ( elm, list, pos ) NOT_READY_YET193194195#define C_ELM_POSOBJ_NLE( elm, list, pos ) \196if ( TNUM_OBJ(list) == T_POSOBJ ) { \197elm = ELM_PLIST( list, pos ); \198} \199else { \200elm = ELMW_LIST( list, pos ); \201}202203#define C_ASS_POSOBJ_INTOBJ( list, pos, elm ) \204if ( TNUM_OBJ(list) == T_POSOBJ ) { \205if ( SIZE_OBJ(list)/sizeof(Obj)-1 < pos ) { \206ResizeBag( list, (pos+1)*sizeof(Obj) ); \207} \208SET_ELM_PLIST( list, pos, elm ); \209} \210else { \211ASS_LIST( list, pos, elm ); \212}213214#define C_ASS_POSOBJ( list, pos, elm ) \215if ( TNUM_OBJ(list) == T_POSOBJ ) { \216if ( SIZE_OBJ(list)/sizeof(Obj)-1 < pos ) { \217ResizeBag( list, (pos+1)*sizeof(Obj) ); \218} \219SET_ELM_PLIST( list, pos, elm ); \220CHANGED_BAG(list); \221} \222else { \223ASS_LIST( list, pos, elm ); \224}225226227228/* lists, should go into 'lists.c' * * * * * * * * * * * * * * * * * * * * */229#define C_LEN_LIST(len,list) \230len = LENGTH(list);231232#define C_LEN_LIST_FPL(len,list) \233if ( IS_PLIST(list) ) { \234len = INTOBJ_INT( LEN_PLIST(list) ); \235} \236else { \237len = LENGTH(list); \238}239240241242243#define C_ELM_LIST(elm,list,p) \244elm = IS_POS_INTOBJ(p) ? ELM_LIST( list, INT_INTOBJ(p) ) : ELMB_LIST(list, p);245246#define C_ELM_LIST_NLE(elm,list,p) \247elm = IS_POS_INTOBJ(p) ? ELMW_LIST( list, INT_INTOBJ(p) ) : ELMB_LIST(list, p);248249#define C_ELM_LIST_FPL(elm,list,p) \250if ( IS_POS_INTOBJ(p) && IS_PLIST(list) ) { \251if ( INT_INTOBJ(p) <= LEN_PLIST(list) ) { \252elm = ELM_PLIST( list, INT_INTOBJ(p) ); \253if ( elm == 0 ) elm = ELM_LIST( list, INT_INTOBJ(p) ); \254} else elm = ELM_LIST( list, INT_INTOBJ(p) ); \255} else C_ELM_LIST( elm, list, p )256257#define C_ELM_LIST_NLE_FPL(elm,list,p) \258if ( IS_POS_INTOBJ(p) && IS_PLIST(list) ) { \259elm = ELM_PLIST( list, INT_INTOBJ(p) ); \260} else C_ELM_LIST_NLE(elm, list, p)261262#define C_ASS_LIST(list,p,rhs) \263if (IS_POS_INTOBJ(p)) ASS_LIST( list, INT_INTOBJ(p), rhs ); \264else ASSB_LIST(list, p, rhs);265266#define C_ASS_LIST_FPL(list,p,rhs) \267if ( IS_POS_INTOBJ(p) && TNUM_OBJ(list) == T_PLIST ) { \268if ( LEN_PLIST(list) < INT_INTOBJ(p) ) { \269GROW_PLIST( list, (UInt)INT_INTOBJ(p) ); \270SET_LEN_PLIST( list, INT_INTOBJ(p) ); \271} \272SET_ELM_PLIST( list, INT_INTOBJ(p), rhs ); \273CHANGED_BAG( list ); \274} \275else { \276C_ASS_LIST( list, p, rhs ) \277}278279#define C_ASS_LIST_FPL_INTOBJ(list,p,rhs) \280if ( IS_POS_INTOBJ(p) && TNUM_OBJ(list) == T_PLIST) { \281if ( LEN_PLIST(list) < INT_INTOBJ(p) ) { \282GROW_PLIST( list, (UInt)INT_INTOBJ(p) ); \283SET_LEN_PLIST( list, INT_INTOBJ(p) ); \284} \285SET_ELM_PLIST( list, INT_INTOBJ(p), rhs ); \286} \287else { \288C_ASS_LIST( list, p, rhs ) \289}290291#define C_ISB_LIST( list, pos) \292((IS_POS_INTOBJ(pos) ? ISB_LIST(list, INT_INTOBJ(pos)) : ISBB_LIST( list, pos)) ? True : False)293294#define C_UNB_LIST( list, pos) \295if (IS_POS_INTOBJ(pos)) UNB_LIST(list, INT_INTOBJ(pos)); else UNBB_LIST(list, pos);296297extern void AddList (298Obj list,299Obj obj );300301extern void AddPlist (302Obj list,303Obj obj );304305#define C_ADD_LIST(list,obj) \306AddList( list, obj );307308#define C_ADD_LIST_FPL(list,obj) \309if ( TNUM_OBJ(list) == T_PLIST) { \310AddPlist( list, obj ); \311} \312else { \313AddList( list, obj ); \314}315316#define GF_ITERATOR ITERATOR317#define GF_IS_DONE_ITER IS_DONE_ITER318#define GF_NEXT_ITER NEXT_ITER319320extern Obj GF_ITERATOR;321extern Obj GF_IS_DONE_ITER;322extern Obj GF_NEXT_ITER;323324325326/* More or less all of this will get inlined away */327328/* Allocate a bag suitable for a size-byte integer of type type.329The allocation may need to be bigger than size bytes330due to limb size or other aspects of the representation */331332static inline Obj C_MAKE_INTEGER_BAG( UInt size, UInt type) {333/* Round size up to nearest multiple of INTEGER_ALLOCATION_SIZE */334return NewBag(type,INTEGER_ALLOCATION_SIZE*335((size + INTEGER_ALLOCATION_SIZE-1)/INTEGER_ALLOCATION_SIZE));336}337338339/* Set 2 bytes of data in an integer */340341static inline void C_SET_LIMB2(Obj bag, UInt limbnumber, UInt2 value) {342343#if INTEGER_UNIT_SIZE == 2344((UInt2 *)ADDR_OBJ(bag))[limbnumber] = value;345#elif INTEGER_UNIT_SIZE == 4346UInt4 *p;347if (limbnumber % 2) {348p = ((UInt4 *)ADDR_OBJ(bag)) + (limbnumber-1) / 2;349*p = (*p & 0xFFFFUL) | ((UInt4)value << 16);350} else {351p = ((UInt4 *)ADDR_OBJ(bag)) + limbnumber / 2;352*p = (*p & 0xFFFF0000UL) | (UInt4)value;353}354#else355UInt8 *p;356p = ((UInt8 *)ADDR_OBJ(bag)) + limbnumber/4;357switch(limbnumber % 4) {358case 0:359*p = (*p & 0xFFFFFFFFFFFF0000UL) | (UInt8)value;360break;361case 1:362*p = (*p & 0xFFFFFFFF0000FFFFUL) | ((UInt8)value << 16);363break;364case 2:365*p = (*p & 0xFFFF0000FFFFFFFFUL) | ((UInt8)value << 32);366break;367case 3:368*p = (*p & 0x0000FFFFFFFFFFFFUL) | ((UInt8)value << 48);369break;370}371#endif372}373374static inline void C_SET_LIMB4(Obj bag, UInt limbnumber, UInt4 value) {375376#if INTEGER_UNIT_SIZE == 4377((UInt4 *)ADDR_OBJ(bag))[limbnumber] = value;378#elif INTEGER_UNIT_SIZE == 8379UInt8 *p;380if (limbnumber % 2) {381p = ((UInt8*)ADDR_OBJ(bag)) + (limbnumber-1) / 2;382*p = (*p & 0xFFFFFFFFUL) | ((UInt8)value << 32);383} else {384p = ((UInt8 *)ADDR_OBJ(bag)) + limbnumber / 2;385*p = (*p & 0xFFFFFFFF00000000UL) | (UInt8)value;386}387#else388((UInt2 *)ADDR_OBJ(bag))[2*limbnumber] = (UInt2)(value & 0xFFFFUL);389((UInt2 *)ADDR_OBJ(bag))[2*limbnumber+1] = (UInt2)(value >>16);390#endif391}392393394395static inline void C_SET_LIMB8(Obj bag, UInt limbnumber, UInt8 value) {396#if INTEGER_UNIT_SIZE == 8397((UInt8 *)ADDR_OBJ(bag))[limbnumber] = value;398#elif INTEGER_UNIT_SIZE == 4399((UInt4 *)ADDR_OBJ(bag))[2*limbnumber] = (UInt4)(value & 0xFFFFFFFFUL);400((UInt4 *)ADDR_OBJ(bag))[2*limbnumber+1] = (UInt4)(value >>32);401#else402((UInt2 *)ADDR_OBJ(bag))[4*limbnumber] = (UInt2)(value & 0xFFFFULL);403((UInt2 *)ADDR_OBJ(bag))[4*limbnumber+1] = (UInt2)((value & 0xFFFF0000ULL) >>16);404((UInt2 *)ADDR_OBJ(bag))[4*limbnumber+2] = (UInt2)((value & 0xFFFF00000000ULL) >>32);405((UInt2 *)ADDR_OBJ(bag))[4*limbnumber+3] = (UInt2)(value >>48);406#endif407}408409/* C_MAKE_MED_INT handles numbers between 2^28 and 2^60 in magnitude,410and is used in code compiled on 64 bit systems. If the target system411is 64 bit an immediate integer is constructed. If the target is 32 bits then412an 8-byte large integer is constructed using the representation-neutral413macros above414415C_NORMALIZE_64BIT is called when a large integer has been416constructed (because the literal was large on the compiling system)417and might be small on the target system. */418419420#ifdef SYS_IS_64_BIT421static inline Obj C_MAKE_MED_INT( Int8 value ) {422return INTOBJ_INT(value);423}424425static inline Obj C_NORMALIZE_64BIT(Obj o) {426Int value = *(Int *)ADDR_OBJ(o);427if (value < 0)428return o;429if (TNUM_OBJ(o) == T_INTNEG)430value = -value;431if (-(1L << 60) <= value && value < (1L << 60))432return INTOBJ_INT(value);433else434return o;435}436437438#else439static inline Obj C_MAKE_MED_INT( Int8 value ) {440Obj x;441UInt type;442if (value < 0) {443type = T_INTNEG;444value = -value;445} else446type = T_INTPOS;447448x = C_MAKE_INTEGER_BAG(8,type);449C_SET_LIMB8(x,0,(UInt8)value);450return x;451}452453static inline Obj C_NORMALIZE_64BIT( Obj o) {454return o;455}456457#endif458459#ifdef __cplusplus460}461#undef GAP_IN_EXTERN_C462#endif463464#endif // GAP_COMPILED_H465466/****************************************************************************467**468*E compiled.h . . . . . . . . . . . . . . . . . . . . . . . . . . ends here469*/470471472