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 ");
212 long head =
pi->data.s.def_end -
pi->data.s.proc_start;
213 procbuflen =
pi->data.s.help_end -
pi->data.s.help_start;
227 s[procbuflen+
head+1] =
'\n';
228 s[procbuflen+
head+2] =
'\0';
230 for(
i=0;
i<=procbuflen+
head+2;
i++)
233 (
s[
i+1]==
'"' ||
s[
i+1]==
'{' ||
s[
i+1]==
'}' ||
s[
i+1]==
'\\'))
244 procbuflen =
pi->data.s.def_end -
pi->data.s.proc_start;
245 char *ss=(
char *)
omAlloc(procbuflen+2);
255 assume(
pi->data.s.body_end >
pi->data.s.body_start);
257 procbuflen =
pi->data.s.body_end -
pi->data.s.body_start;
258 pi->data.s.body = (
char *)
omAlloc( strlen(argstr)+procbuflen+15+
259 strlen(
pi->libname) );
264 strcpy(
pi->data.s.body,argstr);
265 myfread(
pi->data.s.body+strlen(argstr), procbuflen, 1,
fp);
267 procbuflen+=strlen(argstr);
270 pi->data.s.body[procbuflen] =
'\0';
271 strcat(
pi->data.s.body+procbuflen,
"\n;return();\n\n" );
272 strcat(
pi->data.s.body+procbuflen+13,
pi->libname);
273 s=(
char *)strchr(
pi->data.s.body,
'{');
279 if (
pi->data.s.example_lineno == 0)
284 procbuflen =
pi->data.s.proc_end -
pi->data.s.example_start - strlen(
buf);
289 s[procbuflen] =
'\0';
290 strcat(
s+procbuflen-3,
"\n;return();\n\n" );
291 p=(
char *)strchr(
s,
'{');
301 int restore_traceit=0;
321 if (restore_traceit)
traceit=save_trace;
328 (
pi->libname!=
NULL) && (
pi->libname[0]!=
'\0'))
330 if ((
pi->libname!=
NULL) && (
pi->libname[0]!=
'\0'))
331 Warn(
"option changed in proc %s from %s",
pi->procname,
pi->libname);
333 Warn(
"option changed in proc %s",
pi->procname);
385 save_flags=
pi->trace_flag;
386 if(
pi->data.s.body==
NULL )
433 if (oh!=
NULL) o=oh->id;
439 Werror(
"ring change during procedure call %s: %s -> %s (level %d)",
pi->procname,o,n,
myynest);
466 pi->trace_flag=save_flags;
510 Werror(
"'%s::%s()' is a local procedure and cannot be accessed by an user.",
511 pi->libname,
pi->procname);
528 switch (
pi->language)
555 err = (
pi->data.o.function)(
res, args);
579 if (!err)
Warn(
"too many arguments for %s",
IDID(pn));
676 if (err)
return NULL;
723 tmp.
rtyp=arg_types[0];
724 while(arg_types[
i]!=0)
728 tt->
rtyp=arg_types[
i];
765 printf(
"entering example (level %d)\n",
myynest);
777 printf(
"leaving -example- (level %d)\n",
myynest);
799# define SI_GET_BUILTIN_MOD_INIT0(name) int SI_MOD_INIT0(name)(SModulFunctions*);
801# undef SI_GET_BUILTIN_MOD_INIT0
810 if (strcmp(libname,
"flint.so")==0)
return SI_MOD_INIT0(flint);
812# define SI_GET_BUILTIN_MOD_INIT(name) if (strcmp(libname, #name ".so") == 0){ return SI_MOD_INIT0(name); }
814# undef SI_GET_BUILTIN_MOD_INIT
827 char *libname = (
char *)
omAlloc(strlen(
id)+5);
828 const char *suffix[] = {
"",
".lib",
".so",
".sl",
NULL };
834 for(
i=0; suffix[
i] !=
NULL;
i++)
836 sprintf(libname,
"%s%s",
id, suffix[
i]);
840 #ifdef HAVE_DYNAMIC_LOADING
846 #ifdef HAVE_DYNAMIC_LOADING
877 strncpy(where,
IDPACKAGE(pl)->libname,127);
886 if (strcmp(newlib,
"Singular")==0)
return FALSE;
911 WarnS(
"not of type package.");
933 if (root==
NULL)
return;
938 && (
pi->data.s.body_start == 0L))
959 idhdl h=
p->idroot->get(
"mod_init",0);
1002 WerrorS(
"Cannot load library,... aborting.");
1012 Warn(
"library %s has old format. This format is still accepted,", newlib);
1013 WarnS(
"but for functionality you may wish to change to the new");
1014 WarnS(
"format. Please refer to the manual for further information.");
1029 ls = ls->
pop(newlib);
1033 PrintS(
"--------------------\n");
1036 Print(
"%s: LIB-stack:(%d), %s %s\n", newlib, ls->
cnt, ls->
get(),
1039 PrintS(
"--------------------\n");
1050 const char *procname,
int,
long pos,
BOOLEAN pstatic)
1052 memset(
pi,0,
sizeof(*
pi));
1057 pi->is_static = pstatic;
1058 pi->data.s.proc_start = pos;
1071 if (
IsCmd(procname,dummy))
1073 Werror(
">>%s< is a reserved name",procname);
1086 Warn(
"extend `%s`",procname);
1105 pi->is_static = pstatic;
1106 pi->data.o.function = func;
1110 if(
pi->data.o.function == func)
1122 pi->is_static = pstatic;
1123 pi->data.o.function = func;
1127 Warn(
"internal error: unknown procedure type %d",
pi->language);
1133 WarnS(
"iiAddCproc: failed.");
1141 int r=
iiAddCproc(libname,procname,pstatic,func);
1144 if (r) r=
iiAddCproc(libname,procname,pstatic,func);
1150#ifdef HAVE_DYNAMIC_LOADING
1160 std::string fname = fullname;
1165 std::string fname = fullname;
1167 dyn_modules =
new std::map<std::string, void *>();
1168 dyn_modules->insert(std::pair<std::string, void *>(fname, handle));
1172 for (std::map<std::string, void *>::iterator it =
dyn_modules->begin();
1193 int l=
si_max((
int)strlen(fullname),(
int)strlen(newlib))+3;
1196 if( *fullname !=
'/' && *fullname !=
'.' )
1197 sprintf(FullName,
"./%s", newlib);
1198 else strncpy(FullName, fullname,
l);
1201 if(
IsCmd(plib, token))
1203 Werror(
"'%s' is resered identifier\n", plib);
1204 goto load_modules_end;
1206 pl =
basePack->idroot->get(plib,0);
1240 Werror(
"%s not found", newlib);
1242 goto load_modules_end;
1256 int ver=(*fktn)(&sModulFunctions);
1263 Warn(
"loaded %s for a different version of Singular(expected MAX_TOK: %d, got %d)",fullname,
MAX_TOK,ver);
1272 Werror(
"mod_init not found:: %s\nThis is probably not a dynamic module for Singular!\n",
dynl_error());
1286 GLOBAL_VAR static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
1287 pthread_mutex_lock(&mutex);
1289 pthread_mutex_unlock(&mutex);
1309 pl =
basePack->idroot->get(plib,0);
1338 (*init)(&sModulFunctions);
1352 Werror(
">>%s<< is not a package (trying to add package help)",plib);
1367 Werror(
">>%s<< is not a package(trying to add help for %s)",plib,
p);
1383#ifdef HAVE_DYNAMIC_LOADING
1391 if (!bin_dir) {
return NULL; }
1412 if(c>=97 && c<=(97+26)) c-=32;
1418 if(c>=65 && c<=(65+26)) c+=32;
1432 char *
p = strrchr(tmpname,
DIR_SEP);
1434 if(
p==
NULL)
p = tmpname;
else p++;
1437 while(isalnum(*r)||(*r==
'_')) r++;
1450void piShowProcList()
1456 Print(
"%-15s %20s %s,%s %s,%s %s,%s\n",
"Library",
"function",
1457 "line",
"start",
"line",
"body",
"line",
"example");
1471 Print(
"%d %-15s %20s ",
proc->is_static ? 1 : 0,
proc->libname,
1474 Print(
"line %-5ld %4d,%-5ld %4d,%-5ld\n",
1475 proc->data.s.proc_start,
1476 proc->data.s.body_lineno,
proc->data.s.body_start,
1477 proc->data.s.example_lineno,
proc->data.s.example_start);
1479 PrintS(
"type: object\n");
1498#ifdef HAVE_LIBPARSER
1504 for(lp =
this;lp!=
NULL;lp=lp->
next)
1506 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.
void CleanUp(ring r=currRing)
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(* SModulFunc_t)(SModulFunctions *)
const struct soptionStruct optionStruct[]
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
int(* iiArithAddCmd)(const char *szName, short nAlias, short nTokval, short nToktype, short nPos)
int(* iiAddCproc)(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
INST_VAR sleftv sLastPrinted
EXTERN_VAR omBin libstack_bin
int name
New type name for int.