Loading...
Searching...
No Matches
blackbox.cc File Reference
`#include "kernel/mod2.h"`
`#include "Singular/tok.h"`
`#include "Singular/subexpr.h"`
`#include "Singular/ipshell.h"`
`#include "Singular/ipid.h"`
`#include "Singular/blackbox.h"`

Go to the source code of this file.

## Macros

#define | MAX_BB_TYPES 256
#define | BLACKBOX_OFFSET (MAX_TOK+1)

## Functions

blackbox * | getBlackboxStuff (const int t)
| return the structure to the type given by t
void | blackbox_default_destroy (blackbox *, void *)
char * | blackbox_default_String (blackbox *, void *)
void * | blackbox_default_Copy (blackbox *, void *)
BOOLEAN | blackbox_default_Assign (leftv l, leftv r)
void | blackbox_default_Print (blackbox *b, void *d)
| default procedure blackbox_default_Print: print the string
void * | blackbox_default_Init (blackbox *)
BOOLEAN | blackbox_default_serialize (blackbox *, void *, si_link)
BOOLEAN | blackbox_default_deserialize (blackbox **, void **, si_link)
BOOLEAN | blackboxDefaultOp1 (int op, leftv l, leftv r)
| default procedure blackboxDefaultOp1, to be called as "default:" branch
BOOLEAN | blackboxDefaultOp2 (int, leftv, leftv, leftv)
| default procedure blackboxDefaultOp2, to be called as "default:" branch
BOOLEAN | blackboxDefaultOp3 (int, leftv, leftv, leftv, leftv)
| default procedure blackboxDefaultOp3, to be called as "default:" branch
BOOLEAN | blackboxDefaultOpM (int op, leftv res, leftv args)
| default procedure blackboxDefaultOpM, to be called as "default:" branch
BOOLEAN | blackbox_default_Check (blackbox *, leftv, leftv)
int | setBlackboxStuff (blackbox *bb, const char *n)
| define a new type
void | removeBlackboxStuff (const int rt)
const char * | getBlackboxName (const int t)
| return the name to the type given by t (r/o)
int | blackboxIsCmd (const char *n, int &tok)
| used by scanner: returns ROOT_DECL for known types (and the type number in `tok`)
void | printBlackboxTypes ()
| list all defined type (for debugging)
struct blackbox_list * | getBlackboxTypes ()
| return array of all define types.

## Variables

static GLOBAL_VAR blackbox * | blackboxTable [MAX_BB_TYPES]
static GLOBAL_VAR char * | blackboxName [MAX_BB_TYPES]
static GLOBAL_VAR int | blackboxTableCnt =0

## Macro Definition Documentation

## BLACKBOX_OFFSET

#define BLACKBOX_OFFSET (MAX_TOK+1)

Definition at line 16 of file blackbox.cc.

## MAX_BB_TYPES

#define MAX_BB_TYPES 256

Definition at line 10 of file blackbox.cc.

## Function Documentation

## blackbox_default_Assign()

BOOLEAN blackbox_default_Assign | ( | leftv | l,
|  | leftv | r )

Definition at line 40 of file blackbox.cc.

{
int lt=l->Typ();
blackbox* b=getBlackboxStuff(lt);
if ((lt==r->Typ())
&& (l->Data()!=r->Data()))
{
b->blackbox_destroy(b,(void*)l->Data());
if (l->rtyp==IDHDL)
IDDATA((idhdl)l->data)=(char*)b->blackbox_Copy(b,r->Data());
else
l->data=b->blackbox_Copy(b,r->Data());
}
return FALSE;
}
FALSE
#define FALSE
Definition auxiliary.h:97
getBlackboxStuff
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition blackbox.cc:17
l
int l
Definition cfEzgcd.cc:100
b
CanonicalForm b
Definition cfModGcd.cc:4111
sleftv::Typ
int Typ()
Definition subexpr.cc:1048
sleftv::Data
void * Data()
Definition subexpr.cc:1192
IDDATA
#define IDDATA(a)
Definition ipid.h:126
idhdl
idrec * idhdl
Definition ring.h:22
IDHDL
#define IDHDL
Definition tok.h:31

## blackbox_default_Check()

BOOLEAN blackbox_default_Check | ( | blackbox * | ,
|  | leftv | ,
|  | leftv | )

Definition at line 139 of file blackbox.cc.

{
return FALSE;
}

## blackbox_default_Copy()

void * blackbox_default_Copy | ( | blackbox * | ,
|  | void * | )

Definition at line 35 of file blackbox.cc.

{
WerrorS("missing blackbox_Copy");
return NULL;
}
WerrorS
void WerrorS(const char *s)
Definition feFopen.cc:24
NULL
#define NULL
Definition omList.c:12

## blackbox_default_deserialize()

BOOLEAN blackbox_default_deserialize | ( | blackbox ** | ,
|  | void ** | ,
|  | si_link | )

Definition at line 72 of file blackbox.cc.

{
WerrorS("blackbox_deserialize is not implemented");
return TRUE;
}
TRUE
#define TRUE
Definition auxiliary.h:101

## blackbox_default_destroy()

void blackbox_default_destroy | ( | blackbox * | ,
|  | void * | )

Definition at line 26 of file blackbox.cc.

{
WerrorS("missing blackbox_destroy");
}

## blackbox_default_Init()

void * blackbox_default_Init | ( | blackbox * |  | ) |

Definition at line 61 of file blackbox.cc.

{
return NULL;
}

## blackbox_default_Print()

void blackbox_default_Print | ( | blackbox * | b,
|  | void * | d )

default procedure blackbox_default_Print: print the string

Definition at line 55 of file blackbox.cc.

{
char *s=b->blackbox_String(b,d);
PrintS(s);
omFree(s);
}
s
const CanonicalForm int s
Definition facAbsFact.cc:51
omFree
#define omFree(addr)
Definition omAllocDecl.h:261
PrintS
void PrintS(const char *s)
Definition reporter.cc:288

## blackbox_default_serialize()

BOOLEAN blackbox_default_serialize | ( | blackbox * | ,
|  | void * | ,
|  | si_link | )

Definition at line 66 of file blackbox.cc.

{
WerrorS("blackbox_serialize is not implemented");
return TRUE;
}

## blackbox_default_String()

char * blackbox_default_String | ( | blackbox * | ,
|  | void * | )

Definition at line 30 of file blackbox.cc.

{
WerrorS("missing blackbox_String");
return omStrDup("");
}
omStrDup
#define omStrDup(s)
Definition omAllocDecl.h:263

## blackboxDefaultOp1()

BOOLEAN blackboxDefaultOp1 | ( | int | op,
|  | leftv | l,
|  | leftv | r )

default procedure blackboxDefaultOp1, to be called as "default:" branch

Definition at line 78 of file blackbox.cc.

{
if (op==TYPEOF_CMD)
{
l->data=omStrDup(getBlackboxName(r->Typ()));
l->rtyp=STRING_CMD;
return FALSE;
}
else if (op==NAMEOF_CMD)
{
if (r->name==NULL) l->data=omStrDup("");
else l->data=omStrDup(r->name);
l->rtyp=STRING_CMD;
return FALSE;
}
return TRUE;
}
getBlackboxName
const char * getBlackboxName(const int t)
return the name to the type given by t (r/o)
Definition blackbox.cc:213
sleftv::name
const char * name
Definition subexpr.h:87
NAMEOF_CMD
@ NAMEOF_CMD
Definition tok.h:135
TYPEOF_CMD
@ TYPEOF_CMD
Definition tok.h:196
STRING_CMD
@ STRING_CMD
Definition tok.h:187

## blackboxDefaultOp2()

BOOLEAN blackboxDefaultOp2 | ( | int | op,
|  | leftv | l,
|  | leftv | r1,
|  | leftv | r2 )

default procedure blackboxDefaultOp2, to be called as "default:" branch

Definition at line 97 of file blackbox.cc.

{
return TRUE;
}

## blackboxDefaultOp3()

BOOLEAN blackboxDefaultOp3 | ( | int | op,
|  | leftv | l,
|  | leftv | r1,
|  | leftv | r2,
|  | leftv | r3 )

default procedure blackboxDefaultOp3, to be called as "default:" branch

Definition at line 102 of file blackbox.cc.

{
return TRUE;
}

## blackboxDefaultOpM()

BOOLEAN blackboxDefaultOpM | ( | int | op,
|  | leftv | res,
|  | leftv | args )

default procedure blackboxDefaultOpM, to be called as "default:" branch

Definition at line 107 of file blackbox.cc.

{
if (op==LIST_CMD)
{
res->rtyp=LIST_CMD;
BOOLEAN bo=jjLIST_PL(res,args);
args->CleanUp();
return bo;
}
else if(op==STRING_CMD)
{
blackbox *b=getBlackboxStuff(args->Typ());
res->data=b->blackbox_String(b,args->Data());
res->rtyp=STRING_CMD;
args=args->next;
if(args!=NULL)
{
sleftv res2;
int ret=iiExprArithM(&res2,args,op);
if (ret) return TRUE;
size_t len=strlen((char*)res->data)+strlen((char*)res2.data)+1;
char *s2=(char*)omAlloc(len);
snprintf(s2,len,"%s%s",(char*)res->data,(char*)res2.data);
omFree(res2.data);
omFree(res->data);
res->data=s2;
}
return FALSE;
}
return TRUE;
}
BOOLEAN
int BOOLEAN
Definition auxiliary.h:88
sleftv
Class used for (list of) interpreter objects.
Definition subexpr.h:83
sleftv::next
leftv next
Definition subexpr.h:86
sleftv::data
void * data
Definition subexpr.h:88
sleftv::CleanUp
void CleanUp(ring r=currRing)
Definition subexpr.cc:351
res
CanonicalForm res
Definition facAbsFact.cc:60
iiExprArithM
BOOLEAN iiExprArithM(leftv res, leftv a, int op)
Definition iparith.cc:9666
jjLIST_PL
BOOLEAN jjLIST_PL(leftv res, leftv v)
Definition iparith.cc:8250
omAlloc
#define omAlloc(size)
Definition omAllocDecl.h:210
LIST_CMD
@ LIST_CMD
Definition tok.h:118

## blackboxIsCmd()

int blackboxIsCmd | ( | const char * | n,
|  | int & | tok )

used by scanner: returns ROOT_DECL for known types (and the type number in `tok`)

Definition at line 219 of file blackbox.cc.

{
for(int i=blackboxTableCnt-1;i>=0;i--)
{
if(strcmp(n,blackboxName[i])==0)
{
#ifdef BLACKBOX_DEVEL
Print("blackboxIsCmd: found bb:%s:%d (table:%d)\n",n,i+BLACKBOX_OFFSET,i);
#endif
tok=i+BLACKBOX_OFFSET;
return ROOT_DECL;
}
}
tok=0;
return 0;
}
blackboxName
static GLOBAL_VAR char * blackboxName[MAX_BB_TYPES]
Definition blackbox.cc:14
blackboxTableCnt
static GLOBAL_VAR int blackboxTableCnt
Definition blackbox.cc:15
BLACKBOX_OFFSET
#define BLACKBOX_OFFSET
Definition blackbox.cc:16
i
int i
Definition cfEzgcd.cc:132
Print
#define Print
Definition emacs.cc:80
ROOT_DECL
@ ROOT_DECL
Definition grammar.cc:320

## getBlackboxName()

const char * getBlackboxName | ( | const int | t | ) |

return the name to the type given by t (r/o)

Definition at line 213 of file blackbox.cc.

{
char *b=blackboxName[t-BLACKBOX_OFFSET];
if (b!=NULL) return b;
else return "";
}

## getBlackboxStuff()

blackbox * getBlackboxStuff | ( | const int | t | ) |

return the structure to the type given by t

Definition at line 17 of file blackbox.cc.

{
if (t>MAX_TOK) /*MAX_TOK+1 is BLACKBOX_OFFSET*/
return (blackboxTable[t-BLACKBOX_OFFSET]);
else
return NULL;
}
blackboxTable
static GLOBAL_VAR blackbox * blackboxTable[MAX_BB_TYPES]
Definition blackbox.cc:13
MAX_TOK
@ MAX_TOK
Definition tok.h:220

## getBlackboxTypes()

struct blackbox_list * getBlackboxTypes | ( |  | ) |

return array of all define types.

Definition at line 245 of file blackbox.cc.

{
int i = 0;
void **l = (void **)omalloc0(blackboxTableCnt * sizeof(void *));
struct blackbox_list *list_struct = (struct blackbox_list *) omAlloc0(sizeof(struct blackbox_list));
list_struct->count = blackboxTableCnt;
list_struct->list = l;
for (i = blackboxTableCnt-1; i >= 0 ;i--)
{
if (blackboxName[i]!=NULL) {
l[i] = (void *)omStrDup(blackboxName[i]);
//Print("type %d: %s\n",i,blackboxName[i]);
} else {
l[i] = NULL;
}
}
return list_struct;
}
blackbox_list::list
void ** list
Definition blackbox.h:86
blackbox_list::count
int count
Definition blackbox.h:85
blackbox_list
struct for containing list of blackbox names and the number of them.
Definition blackbox.h:84
omalloc0
#define omalloc0(size)
Definition omAllocDecl.h:229
omAlloc0
#define omAlloc0(size)
Definition omAllocDecl.h:211

## printBlackboxTypes()

void printBlackboxTypes | ( |  | ) |

list all defined type (for debugging)

Definition at line 236 of file blackbox.cc.

{
for(int i=blackboxTableCnt-1;i>=0;i--)
{
if (blackboxName[i]!=NULL)
Print("type %d: %s\n",i+BLACKBOX_OFFSET,blackboxName[i]);
}
}

## removeBlackboxStuff()

void removeBlackboxStuff | ( | const int | rt | ) |

Definition at line 206 of file blackbox.cc.

{
omfree(blackboxTable[rt-BLACKBOX_OFFSET]);
omfree(blackboxName[rt-BLACKBOX_OFFSET]);
blackboxTable[rt-BLACKBOX_OFFSET]=NULL;
blackboxName[rt-BLACKBOX_OFFSET]=NULL;
}
omfree
#define omfree(addr)
Definition omAllocDecl.h:237

## setBlackboxStuff()

int setBlackboxStuff | ( | blackbox * | bb,
|  | const char * | n )

define a new type

Definition at line 143 of file blackbox.cc.

{
int where = -1;
for (int i=0;i<MAX_BB_TYPES;i++)
{
if (blackboxTable[i]!=NULL && strcmp(blackboxName[i],n)==0) {
where = i;
break;
}
}
if (where < 0) {
if (MAX_BB_TYPES<=blackboxTableCnt)
{
// second try, find empty slot from removed bb:
for (int i=0;i<MAX_BB_TYPES;i++)
{
if (blackboxTable[i]==NULL) { where=i; break; }
}
}
else
{
where=blackboxTableCnt;
blackboxTableCnt++;
}
}
if (where==-1)
{
WerrorS("too many bb types defined");
return 0;
}
else
{
// check for alreday defined bb:
for (int i=0;i<MAX_BB_TYPES;i++)
{
if ((blackboxName[i]!=NULL) && (strcmp(blackboxName[i],n)==0))
{
Warn("not redefining blackbox type %s (%d)",n,i+BLACKBOX_OFFSET);
return 0;
}
}
blackboxTable[where]=bb;
blackboxName[where]=omStrDup(n);
#ifdef BLACKBOX_DEVEL
Print("setBlackboxStuff: define bb:name=%s:rt=%d (table:cnt=%d)\n",blackboxName[where],where+BLACKBOX_OFFSET,where);
#endif
if (bb->blackbox_destroy==NULL) bb->blackbox_destroy=blackbox_default_destroy;
if (bb->blackbox_String==NULL) bb->blackbox_String=blackbox_default_String;
if (bb->blackbox_Print==NULL) bb->blackbox_Print=blackbox_default_Print;
if (bb->blackbox_Init==NULL) bb->blackbox_Init=blackbox_default_Init;
if (bb->blackbox_Copy==NULL) bb->blackbox_Copy=blackbox_default_Copy;
if (bb->blackbox_Assign==NULL) bb->blackbox_Assign=blackbox_default_Assign;
if (bb->blackbox_Op1==NULL) bb->blackbox_Op1=blackboxDefaultOp1;
if (bb->blackbox_Op2==NULL) bb->blackbox_Op2=blackboxDefaultOp2;
if (bb->blackbox_Op3==NULL) bb->blackbox_Op3=blackboxDefaultOp3;
if (bb->blackbox_OpM==NULL) bb->blackbox_OpM=blackboxDefaultOpM;
if (bb->blackbox_CheckAssign==NULL) bb->blackbox_CheckAssign=blackbox_default_Check;
if (bb->blackbox_serialize==NULL) bb->blackbox_serialize=blackbox_default_serialize;
if (bb->blackbox_deserialize==NULL) bb->blackbox_deserialize=blackbox_default_deserialize;
return where+BLACKBOX_OFFSET;
}
}
blackboxDefaultOp2
BOOLEAN blackboxDefaultOp2(int, leftv, leftv, leftv)
default procedure blackboxDefaultOp2, to be called as "default:" branch
Definition blackbox.cc:97
blackbox_default_Copy
void * blackbox_default_Copy(blackbox *, void *)
Definition blackbox.cc:35
blackbox_default_String
char * blackbox_default_String(blackbox *, void *)
Definition blackbox.cc:30
blackbox_default_serialize
BOOLEAN blackbox_default_serialize(blackbox *, void *, si_link)
Definition blackbox.cc:66
blackboxDefaultOp3
BOOLEAN blackboxDefaultOp3(int, leftv, leftv, leftv, leftv)
default procedure blackboxDefaultOp3, to be called as "default:" branch
Definition blackbox.cc:102
blackbox_default_Check
BOOLEAN blackbox_default_Check(blackbox *, leftv, leftv)
Definition blackbox.cc:139
blackbox_default_Assign
BOOLEAN blackbox_default_Assign(leftv l, leftv r)
Definition blackbox.cc:40
blackbox_default_Print
void blackbox_default_Print(blackbox *b, void *d)
default procedure blackbox_default_Print: print the string
Definition blackbox.cc:55
blackbox_default_Init
void * blackbox_default_Init(blackbox *)
Definition blackbox.cc:61
blackbox_default_deserialize
BOOLEAN blackbox_default_deserialize(blackbox **, void **, si_link)
Definition blackbox.cc:72
blackbox_default_destroy
void blackbox_default_destroy(blackbox *, void *)
Definition blackbox.cc:26
blackboxDefaultOpM
BOOLEAN blackboxDefaultOpM(int op, leftv res, leftv args)
default procedure blackboxDefaultOpM, to be called as "default:" branch
Definition blackbox.cc:107
blackboxDefaultOp1
BOOLEAN blackboxDefaultOp1(int op, leftv l, leftv r)
default procedure blackboxDefaultOp1, to be called as "default:" branch
Definition blackbox.cc:78
MAX_BB_TYPES
#define MAX_BB_TYPES
Definition blackbox.cc:10
Warn
#define Warn
Definition emacs.cc:77

## Variable Documentation

## blackboxName

GLOBAL_VAR char* blackboxName[MAX_BB_TYPES]

static

Definition at line 14 of file blackbox.cc.

## blackboxTable

GLOBAL_VAR blackbox* blackboxTable[MAX_BB_TYPES]

static

Definition at line 13 of file blackbox.cc.

## blackboxTableCnt

GLOBAL_VAR int blackboxTableCnt =0

static

Definition at line 15 of file blackbox.cc.