1 #ifndef BLACKBOX_H
2 #define BLACKBOX_H
3 
4 #include "kernel/mod2.h"
5 
6 #include "kernel/structs.h"
7 
8 #include "Singular/lists.h"
9 #include "Singular/links/silink.h"
10 
11 void removeBlackboxStuff(const int rt);
12 
13 struct blackbox_struct;
14 
15 typedef struct blackbox_struct blackbox;
16 
17 struct  blackbox_struct
18 {
19   /// destroy the object: b points to blackbox_struct, d to data
20   void (*blackbox_destroy)(blackbox  *b, void *d);
21   /// convert the object to a string (which should be freed by omFree)
22   char *(*blackbox_String)(blackbox *b,void *d);
23   /// print the object: default: use string representation
24   void (*blackbox_Print)(blackbox *b,void *d);
25   /// construct the default object
26   void *(*blackbox_Init)(blackbox *b);
27   /// copy the object: b points to blackbox_struct, d to data
28   void *(*blackbox_Copy)(blackbox *b,void *d);
29   /// interpreter assign: l:=r
30   BOOLEAN (*blackbox_Assign)(leftv l, leftv r);
31   /// interpreter: unary operations op(r), r(), ...
32   // convention for blackbox_Op1..blackbox_OpM:
33   //             return FALSE, if op was successfully performed
34   //             return TRUE (and an error message) for failure
35   //             return TRUE (and no error message) if not defined
36   BOOLEAN (*blackbox_Op1)(int op,leftv l, leftv r);
37   /// interpreter: binary operations: op(r1,r2), r1 op r2,...
38   BOOLEAN (*blackbox_Op2)(int op,leftv l, leftv r1,leftv r2);
39   /// interpreter: tertiary op: op(r1,r2,r3)
40   BOOLEAN (*blackbox_Op3)(int op,leftv l, leftv r1,leftv r2, leftv r3);
41   /// interpreter: operations with undefined number of operands
42   BOOLEAN (*blackbox_OpM)(int op,leftv l, leftv r);
43   /// is an assign of r to l (part of b) impossible?
44   BOOLEAN (*blackbox_CheckAssign)(blackbox *b,leftv l, leftv r);
45   /// serialize
46   BOOLEAN (*blackbox_serialize)(blackbox *b,void *d, si_link f);
47   /// deserialize
48   BOOLEAN (*blackbox_deserialize)(blackbox **b,void **d, si_link f);
49   /// additional type info
50   void *data;
51   /// addtinional gneral properties
52   int properties; // bit 0:blackbox is only a wrapper for lists
53 #define  BB_LIKE_LIST(B) ((B)->properties &1)
54 } ;
55 /// default procedure blackboxDefaultOp1, to be called as "default:" branch
56 BOOLEAN blackboxDefaultOp1(int op,leftv l, leftv r);
57 
58 /// default procedure blackboxDefaultOp2, to be called as "default:" branch
59 BOOLEAN blackboxDefaultOp2(int op,leftv l, leftv r1, leftv r2);
60 
61 /// default procedure blackboxDefaultOp3, to be called as "default:" branch
62 BOOLEAN blackboxDefaultOp3(int op,leftv l, leftv r1,leftv r2, leftv r3);
63 
64 /// default procedure blackboxDefaultOpM, to be called as "default:" branch
65 BOOLEAN blackboxDefaultOpM(int op,leftv l, leftv r);
66 
67 /// default procedure blackbox_default_Print: print the string
68 void blackbox_default_Print(blackbox *b,void *d);
69 
70 /// return the structure to the type given by t
71 blackbox* getBlackboxStuff(const int t);
72 /// return the name to the type given by t (r/o)
73 const char *    getBlackboxName(const int t);
74 /// used by scanner: returns ROOT_DECL for known types
75 /// (and the type number in @c tok)
76 int blackboxIsCmd(const char *n, int & tok);
77 /// define a new type
78 int setBlackboxStuff(blackbox *bb,const char *name);
79 
80 /// list all defined type (for debugging)
81 void printBlackboxTypes();
82 
83 /// struct for containing list of blackbox names and the number of them.
84 struct blackbox_list {
85 	int count;
86 	void **list;
87 };
88 
89 /// return array of all define types.
90 struct blackbox_list *getBlackboxTypes();
91 
92 #endif
93