20#ifndef SINGULAR_PATH_LENGTH
21#define SINGULAR_PATH_LENGTH 512
27#define SI_MAX_NEST 500
28#elif defined(__CYGWIN__)
29#define SI_MAX_NEST 480
31#define SI_MAX_NEST 1000
34#if defined(ix86Mac_darwin) || defined(x86_64Mac_darwin) || defined(ppcMac_darwin)
35# define MODULE_SUFFIX bundle
36#elif defined(__CYGWIN__)
37# define MODULE_SUFFIX dll
39# define MODULE_SUFFIX so
42#define MODULE_SUFFIX_STRING EXPANDED_STRINGIFY(MODULE_SUFFIX)
45#ifdef HAVE_DYNAMIC_LOADING
53 const char *procname,
int line,
long pos,
BOOLEAN pstatic=
FALSE);
56extern int iiArithAddCmd(
const char *szName,
short nAlias,
short nTokval,
57 short nToktype,
short nPos);
89 return (strcmp(lib,
IDPACKAGE(hl)->libname)==0);
105 while ((*e>
' ') && (*e!=
'(')) e++;
116 while ((*e==
' ') || (*e==
'\t') || (*e==
'(')) e++;
122 return omStrDup(
"parameter list #;");
133 char *argstr=(
char *)
omAlloc(127);
145 if ((*
s==
' ')||(*
s==
'\t'))
147 else if ((*
s==
'\n')&&(*(
s+1)==
' '))
154 &&((par!=0) || (*e!=
')'))
158 else if (*e==
')') par--;
159 args_found=args_found || (*e>
' ');
167 if ((
int)strlen(argstr)+12 +(
int)strlen(
s)>= argstrlen)
170 char *a=(
char *)
omAlloc( argstrlen);
176 if(strncmp(
s,
"alias ",6)!=0)
178 strcat(argstr,
"parameter ");
213 long head =
pi->data.s.def_end -
pi->data.s.proc_start;
214 procbuflen =
pi->data.s.help_end -
pi->data.s.help_start;
231 s[procbuflen+
head+1] =
'\n';
232 s[procbuflen+
head+2] =
'\0';
234 for(
i=0;
i<=procbuflen+
head+2;
i++)
237 (
s[
i+1]==
'"' ||
s[
i+1]==
'{' ||
s[
i+1]==
'}' ||
s[
i+1]==
'\\'))
248 procbuflen =
pi->data.s.def_end -
pi->data.s.proc_start;
249 char *ss=(
char *)
omAlloc(procbuflen+2);
259 assume(
pi->data.s.body_end >
pi->data.s.body_start);
261 procbuflen =
pi->data.s.body_end -
pi->data.s.body_start;
262 pi->data.s.body = (
char *)
omAlloc( strlen(argstr)+procbuflen+15+
263 strlen(
pi->libname) );
268 strcpy(
pi->data.s.body,argstr);
269 myfread(
pi->data.s.body+strlen(argstr), procbuflen, 1,
fp);
271 procbuflen+=strlen(argstr);
274 pi->data.s.body[procbuflen] =
'\0';
275 strcat(
pi->data.s.body+procbuflen,
"\n;return();\n\n" );
276 strcat(
pi->data.s.body+procbuflen+13,
pi->libname);
277 s=(
char *)strchr(
pi->data.s.body,
'{');
283 if (
pi->data.s.example_lineno == 0)
292 procbuflen =
pi->data.s.proc_end -
pi->data.s.example_start - strlen(
buf);
297 s[procbuflen] =
'\0';
298 strcat(
s+procbuflen-3,
"\n;return();\n\n" );
299 p=(
char *)strchr(
s,
'{');
309 int restore_traceit=0;
329 if (restore_traceit)
traceit=save_trace;
336 (
pi->libname!=
NULL) && (
pi->libname[0]!=
'\0'))
338 if ((
pi->libname!=
NULL) && (
pi->libname[0]!=
'\0'))
339 Warn(
"option changed in proc %s from %s",
pi->procname,
pi->libname);
341 Warn(
"option changed in proc %s",
pi->procname);
393 save_flags=
pi->trace_flag;
394 if(
pi->data.s.body==
NULL )
442 if (oh!=
NULL) o=oh->id;
448 Werror(
"ring change during procedure call %s: %s -> %s (level %d)",
pi->procname,o,n,
myynest);
475 pi->trace_flag=save_flags;
519 Werror(
"'%s::%s()' is a local procedure and cannot be accessed by an user.",
520 pi->libname,
pi->procname);
537 switch (
pi->language)
564 err = (
pi->data.o.function)(
res, args);
588 if (!err)
Warn(
"too many arguments for %s",
IDID(pn));
623 if ((hh!=
NULL)&&(strcmp(
IDID(hh),
" tmpRing")==0))
685 if (err)
return NULL;
732 tmp.
rtyp=arg_types[0];
733 while(arg_types[
i]!=0)
737 tt->
rtyp=arg_types[
i];
774 printf(
"entering example (level %d)\n",
myynest);
786 printf(
"leaving -example- (level %d)\n",
myynest);
808# define SI_GET_BUILTIN_MOD_INIT0(name) int SI_MOD_INIT0(name)(SModulFunctions*);
810# undef SI_GET_BUILTIN_MOD_INIT0
819 if (strcmp(libname,
"flint.so")==0)
return SI_MOD_INIT0(flint);
821# define SI_GET_BUILTIN_MOD_INIT(name) if (strcmp(libname, #name ".so") == 0){ return SI_MOD_INIT0(name); }
823# undef SI_GET_BUILTIN_MOD_INIT
836 size_t len=strlen(
id)+5;
837 char *libname = (
char *)
omAlloc(len);
838 const char *suffix[] = {
"",
".lib",
".so",
".sl",
NULL };
844 for(
i=0; suffix[
i] !=
NULL;
i++)
846 snprintf(libname,len,
"%s%s",
id, suffix[
i]);
850 #ifdef HAVE_DYNAMIC_LOADING
856 #ifdef HAVE_DYNAMIC_LOADING
887 strncpy(where,
IDPACKAGE(pl)->libname,127);
896 if (strcmp(newlib,
"Singular")==0)
return FALSE;
921 WarnS(
"not of type package.");
943 if (root==
NULL)
return;
948 && (
pi->data.s.body_start == 0L))
969 idhdl h=
p->idroot->get(
"mod_init",0);
1012 WerrorS(
"Cannot load library,... aborting.");
1022 Warn(
"library %s has old format. This format is still accepted,", newlib);
1023 WarnS(
"but for functionality you may wish to change to the new");
1024 WarnS(
"format. Please refer to the manual for further information.");
1039 ls = ls->
pop(newlib);
1043 PrintS(
"--------------------\n");
1046 Print(
"%s: LIB-stack:(%d), %s %s\n", newlib, ls->
cnt, ls->
get(),
1049 PrintS(
"--------------------\n");
1060 const char *procname,
int,
long pos,
BOOLEAN pstatic)
1062 memset(
pi,0,
sizeof(*
pi));
1067 pi->is_static = pstatic;
1068 pi->data.s.proc_start = pos;
1081 if (
IsCmd(procname,dummy))
1083 Werror(
">>%s< is a reserved name",procname);
1096 Warn(
"extend `%s`",procname);
1115 pi->is_static = pstatic;
1116 pi->data.o.function = func;
1120 if(
pi->data.o.function == func)
1132 pi->is_static = pstatic;
1133 pi->data.o.function = func;
1137 Warn(
"internal error: unknown procedure type %d",
pi->language);
1143 WarnS(
"iiAddCproc: failed.");
1151 int r=
iiAddCproc(libname,procname,pstatic,func);
1154 if (r) r=
iiAddCproc(libname,procname,pstatic,func);
1160#ifdef HAVE_DYNAMIC_LOADING
1170 std::string fname = fullname;
1175 std::string fname = fullname;
1177 dyn_modules =
new std::map<std::string, void *>();
1178 dyn_modules->insert(std::pair<std::string, void *>(fname, handle));
1182 for (std::map<std::string, void *>::iterator it =
dyn_modules->begin();
1203 int l=
si_max((
int)strlen(fullname),(
int)strlen(newlib))+3;
1206 if( *fullname !=
'/' && *fullname !=
'.' )
1207 snprintf(FullName,
l,
"./%s", newlib);
1208 else strncpy(FullName, fullname,
l);
1211 if(
IsCmd(plib, token))
1213 Werror(
"'%s' is resered identifier\n", plib);
1214 goto load_modules_end;
1216 pl =
basePack->idroot->get(plib,0);
1250 Werror(
"%s not found", newlib);
1252 goto load_modules_end;
1266 int ver=(*fktn)(&sModulFunctions);
1273 Warn(
"loaded %s for a different version of Singular(expected MAX_TOK: %d, got %d)",fullname,
MAX_TOK,ver);
1282 Werror(
"mod_init not found:: %s\nThis is probably not a dynamic module for Singular!\n",
dynl_error());
1296 GLOBAL_VAR static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
1297 pthread_mutex_lock(&mutex);
1299 pthread_mutex_unlock(&mutex);
1319 pl =
basePack->idroot->get(plib,0);
1348 (*init)(&sModulFunctions);
1362 Werror(
">>%s<< is not a package (trying to add package help)",plib);
1377 Werror(
">>%s<< is not a package(trying to add help for %s)",plib,
p);
1393#ifdef HAVE_DYNAMIC_LOADING
1401 if (!bin_dir) {
return NULL; }
1422 if(c>=97 && c<=(97+26)) c-=32;
1428 if(c>=65 && c<=(65+26)) c+=32;
1442 char *
p = strrchr(tmpname,
DIR_SEP);
1444 if(
p==
NULL)
p = tmpname;
else p++;
1447 while(isalnum(*r)||(*r==
'_')) r++;
1460void piShowProcList()
1466 Print(
"%-15s %20s %s,%s %s,%s %s,%s\n",
"Library",
"function",
1467 "line",
"start",
"line",
"body",
"line",
"example");
1482 Print(
"%d %-15s %20s ",
proc->is_static ? 1 : 0,
proc->libname,
1485 Print(
"line %-5ld %4d,%-5ld %4d,%-5ld\n",
1486 proc->data.s.proc_start,
1487 proc->data.s.body_lineno,
proc->data.s.body_start,
1488 proc->data.s.example_lineno,
proc->data.s.example_start);
1490 PrintS(
"type: object\n");
1509#ifdef HAVE_LIBPARSER
1515 for(lp =
this;lp!=
NULL;lp=lp->
next)
1517 if(strcmp(lp->
get(), libn)==0)
break;
static int si_max(const int a, const int b)
unsigned char * proc[NUM_PROC]
void push(const char *p, char *libname)
libstackv pop(const char *p)
Class used for (list of) interpreter objects.
const CanonicalForm int s
const Variable & v
< [in] a sqrfree bivariate poly
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
void WerrorS(const char *s)
size_t myfread(void *ptr, size_t size, size_t nmemb, FILE *stream)
char * feGetResource(const char id, int warn)
void newBuffer(char *s, feBufferTypes t, procinfo *pi, int lineno)
int IsCmd(const char *n, int &tok)
int iiArithAddCmd(const char *szName, short nAlias, short nTokval, short nToktype, short nPos=-1)
idhdl ggetid(const char *n)
void killhdl2(idhdl h, idhdl *ih, ring r)
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
VAR proclevel * procstack
void killhdl(idhdl h, package proot)
idhdl packFindHdl(package r)
EXTERN_VAR omBin sleftv_bin
const struct soptionStruct verboseStruct[]
int(* iiArithAddCmd)(const char *szName, short nAlias, short nTokval, short nToktype, short nPos)
int(* SModulFunc_t)(SModulFunctions *)
const struct soptionStruct optionStruct[]
int(* iiAddCproc)(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
char * iiProcName(char *buf, char &ct, char *&e)
int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
void yylprestart(FILE *input_file)
bool registered_dyn_module(char *fullname)
ideal ii_CallProcId2Id(const char *lib, const char *proc, ideal arg, const ring R)
void register_dyn_module(char *fullname, void *handle)
char * iiProcArgs(char *e, BOOLEAN withParenth)
BOOLEAN iiLoadLIB(FILE *fp, const char *libnamebuf, const char *newlib, idhdl pl, BOOLEAN autoexport, BOOLEAN tellerror)
static void iiCallLibProcEnd(idhdl save_ringhdl, ring save_ring)
BOOLEAN iiEStart(char *example, procinfo *pi)
#define SI_GET_BUILTIN_MOD_INIT0(name)
int flint_mod_init(SModulFunctions *psModulFunctions)
BOOLEAN load_modules_aux(const char *newlib, char *fullname, BOOLEAN autoexport)
static void iiCheckNest()
#define SI_GET_BUILTIN_MOD_INIT(name)
char * iiConvName(const char *libname)
BOOLEAN iiLibCmd(const char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force)
BOOLEAN iiGetLibStatus(const char *lib)
leftv ii_CallLibProcM(const char *n, void **args, int *arg_types, const ring R, BOOLEAN &err)
args: NULL terminated array of arguments arg_types: 0 terminated array of corresponding types
BOOLEAN iiMake_proc(idhdl pn, package pack, leftv args)
BOOLEAN iiTryLoadLib(leftv v, const char *id)
#define MODULE_SUFFIX_STRING
static void iiCleanProcs(idhdl &root)
BOOLEAN load_modules(const char *newlib, char *fullname, BOOLEAN autoexport)
int ii_CallProcId2Int(const char *lib, const char *proc, ideal arg, const ring R)
THREAD_VAR std::map< std::string, void * > * dyn_modules
static char mytolower(char c)
VAR libstackv library_stack
int iiAddCprocTop(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
static char mytoupper(char c)
INST_VAR sleftv iiRETURNEXPR
void close_all_dyn_modules()
#define SINGULAR_PATH_LENGTH
const char * yylp_errlist[]
BOOLEAN load_builtin(const char *newlib, BOOLEAN autoexport, SModulFunc_t init)
EXTERN_VAR int yylplineno
BOOLEAN iiLocateLib(const char *lib, char *where)
SModulFunc_t iiGetBuiltinModInit(const char *libname)
void module_help_main(const char *newlib, const char *help)
static void iiShowLevRings()
BOOLEAN iiAllStart(procinfov pi, const char *p, feBufferTypes t, int l)
void * iiCallLibProc1(const char *n, void *arg, int arg_type, BOOLEAN &err)
static void iiCallLibProcBegin()
void module_help_proc(const char *newlib, const char *p, const char *help)
static void iiRunInit(package p)
EXTERN_VAR int yylp_errno
char * iiGetLibProcBuffer(procinfo *pi, int part)
BOOLEAN iiPStart(idhdl pn, leftv v)
void * binary_module_function(const char *newlib, const char *funcname)
int iiArithAddCmd(const char *szName, short nAlias, short nTokval, short nToktype, short nPos)
procinfo * iiInitSingularProcinfo(procinfov pi, const char *libname, const char *procname, int, long pos, BOOLEAN pstatic)
void iiCheckPack(package &p)
idhdl rFindHdl(ring r, idhdl n)
VAR char libnamebuf[1024]
int yylplex(const char *libname, const char *libfile, lib_style_types *lib_style, idhdl pl, BOOLEAN autoexport=FALSE, lp_modes=LOAD_LIB)
lib_types type_of_LIB(const char *newlib, char *libnamebuf)
#define SI_MOD_INIT0(name)
#define SI_FOREACH_BUILTIN(add)
Data for type_of_LIB to determine built-in modules, use add(name) to add built-in library to macro.
int dynl_check_opened(char *filename)
const char * dynl_error()
int dynl_close(void *handle)
void * dynl_sym(void *handle, const char *symbol)
void * dynl_open(char *filename)
#define omFreeSize(addr, size)
#define omreallocSize(addr, o_size, size)
#define omFreeBin(addr, bin)
#define omFreeBinAddr(addr)
void rChangeCurrRing(ring r)
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
void PrintS(const char *s)
void Werror(const char *fmt,...)
#define TRACE_SHOW_LINENO
EXTERN_VAR int traceit_stop
static ring rIncRefCnt(ring r)
static void rDecRefCnt(ring r)
int status int void * buf
INST_VAR sleftv sLastPrinted
EXTERN_VAR omBin libstack_bin
int name
New type name for int.