Loading...
Searching...
No Matches
blackbox.h File Reference
`#include "kernel/mod2.h"`
`#include "kernel/structs.h"`
`#include "Singular/lists.h"`
`#include "Singular/links/silink.h"`

Go to the source code of this file.

## Data Structures

struct | blackbox
struct | blackbox_list
| struct for containing list of blackbox names and the number of them. More...

## Macros

#define | BB_LIKE_LIST(B)

## Functions

void | removeBlackboxStuff (const int rt)
BOOLEAN | blackboxDefaultOp1 (int op, leftv l, leftv r)
| default procedure blackboxDefaultOp1, to be called as "default:" branch
BOOLEAN | blackboxDefaultOp2 (int op, leftv l, leftv r1, leftv r2)
| default procedure blackboxDefaultOp2, to be called as "default:" branch
BOOLEAN | blackboxDefaultOp3 (int op, leftv l, leftv r1, leftv r2, leftv r3)
| default procedure blackboxDefaultOp3, to be called as "default:" branch
BOOLEAN | blackboxDefaultOpM (int op, leftv l, leftv r)
| default procedure blackboxDefaultOpM, to be called as "default:" branch
void | blackbox_default_Print (blackbox *b, void *d)
| default procedure blackbox_default_Print: print the string
blackbox * | getBlackboxStuff (const int t)
| return the structure to the type given by t
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`)
int | setBlackboxStuff (blackbox *bb, const char *name)
| define a new type
void | printBlackboxTypes ()
| list all defined type (for debugging)
struct blackbox_list * | getBlackboxTypes ()
| return array of all define types.

## Data Structure Documentation

## blackbox_struct

struct blackbox_struct

Definition at line 17 of file blackbox.h.

Data Fields
BOOLEAN(*)(leftv l, leftv r) | blackbox_Assign | interpreter assign: l:=r
BOOLEAN(*)(blackbox *b, leftv l, leftv r) | blackbox_CheckAssign | is an assign of r to l (part of b) impossible?
void *(*)(blackbox *b, void *d) | blackbox_Copy | copy the object: b points to blackbox_struct, d to data
BOOLEAN(*)(blackbox **b, void **d, si_link f) | blackbox_deserialize | deserialize
void(*)(blackbox *b, void *d) | blackbox_destroy | destroy the object: b points to blackbox_struct, d to data
void *(*)(blackbox *b) | blackbox_Init | construct the default object
BOOLEAN(*)(int op, leftv l, leftv r) | blackbox_Op1 | interpreter: unary operations op(r), r(), ...
BOOLEAN(*)(int op, leftv l, leftv r1, leftv r2) | blackbox_Op2 | interpreter: binary operations: op(r1,r2), r1 op r2,...
BOOLEAN(*)(int op, leftv l, leftv r1, leftv r2, leftv r3) | blackbox_Op3 | interpreter: tertiary op: op(r1,r2,r3)
BOOLEAN(*)(int op, leftv l, leftv r) | blackbox_OpM | interpreter: operations with undefined number of operands
void(*)(blackbox *b, void *d) | blackbox_Print | print the object: default: use string representation
BOOLEAN(*)(blackbox *b, void *d, si_link f) | blackbox_serialize | serialize
char *(*)(blackbox *b, void *d) | blackbox_String | convert the object to a string (which should be freed by omFree)
void * | data | additional type info
int | properties | additional general properties

## blackbox_list

struct blackbox_list

struct for containing list of blackbox names and the number of them.

Definition at line 84 of file blackbox.h.

Data Fields
int | count |
void ** | list |

## Macro Definition Documentation

## BB_LIKE_LIST

#define BB_LIKE_LIST | ( |  | B | ) |

Value:
((B)->properties &1)
B
b *CanonicalForm B
Definition facBivar.cc:52

Definition at line 53 of file blackbox.h.

## Function Documentation

## 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);
}
b
CanonicalForm b
Definition cfModGcd.cc:4111
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

## 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;
}
TRUE
#define TRUE
Definition auxiliary.h:101
FALSE
#define FALSE
Definition auxiliary.h:97
getBlackboxName
const char * getBlackboxName(const int t)
return the name to the type given by t (r/o)
Definition blackbox.cc:213
l
int l
Definition cfEzgcd.cc:100
sleftv::Typ
int Typ()
Definition subexpr.cc:1048
sleftv::name
const char * name
Definition subexpr.h:87
omStrDup
#define omStrDup(s)
Definition omAllocDecl.h:263
NULL
#define NULL
Definition omList.c:12
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 | l,
|  | leftv | r )

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
getBlackboxStuff
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition blackbox.cc:17
sleftv
Class used for (list of) interpreter objects.
Definition subexpr.h:83
sleftv::data
void * data
Definition subexpr.h:88
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 * | name )

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
WerrorS
void WerrorS(const char *s)
Definition feFopen.cc:24