Annotation of OpenXM/src/ox_toolkit/ox_toolkit.h, Revision 1.34
1.1 ohara 1: /* -*- mode: C -*- */
1.34 ! ohara 2: /* $OpenXM: OpenXM/src/ox_toolkit/ox_toolkit.h,v 1.33 2005/10/12 04:03:37 takayama Exp $ */
1.1 ohara 3:
4: #ifndef _OX_TOOLKIT_H_
5:
6: #define _OX_TOOLKIT_H_
7:
1.27 iwane 8: #ifdef __cplusplus
9: extern "C" {
10: #endif
11:
1.28 ohara 12: #include <stdio.h>
13: #include <gmp.h>
1.5 ohara 14: #include <ox/cmotag.h>
15: #include <ox/oxMessageTag.h>
16: #include <ox/smCommand.h>
1.21 ohara 17: #include <gc/gc.h>
1.20 ohara 18:
1.21 ohara 19: #define MALLOC(x) GC_MALLOC((x))
1.23 ohara 20: #define MALLOC_ATOMIC(x) GC_MALLOC_ATOMIC((x))
1.20 ohara 21: #define ALLOCA(x) alloca((x))
1.21 ohara 22: /* #define FREE(x) free((x)) */
23: #define FREE(x)
1.1 ohara 24:
1.2 ohara 25: #if !defined(__GNUC__) && !defined(__inline__)
26: #define __inline__
27: #endif
28:
1.7 ohara 29: /* Mathcap Local Database */
30: typedef struct {
1.33 takayama 31: int tag;
32: int flag;
33: } table;
34:
35: typedef struct mathcap {
36: table *cmotbl;
37: table *smtbl;
1.7 ohara 38: } mathcap;
39:
40: /* OpenXM File Descripter */
1.2 ohara 41: typedef struct OXFILE{
1.6 ohara 42: int fd;
43: int (*send_int32)(struct OXFILE *oxfp, int int32);
44: int (*receive_int32)(struct OXFILE *oxfp);
45: int serial_number;
1.9 ohara 46: int received_serial_number;
1.6 ohara 47: struct OXFILE *control; /* pointer to his control server. */
48: struct mathcap *mathcap;
49: int error;
1.19 ohara 50: char *wbuf;
51: int wbuf_size;
52: int wbuf_count;
1.28 ohara 53: int (*send_double)(struct OXFILE *oxfp, double int64);
1.29 ohara 54: double (*receive_double)(struct OXFILE *oxfp);
1.2 ohara 55: } OXFILE;
1.1 ohara 56:
1.18 ohara 57: typedef struct cmo {
1.1 ohara 58: int tag;
59: } cmo;
60:
61: typedef cmo cmo_null;
62: typedef cmo cmo_zero;
63: typedef cmo cmo_dms_generic;
64:
65: typedef struct {
66: int tag;
67: int i;
68: } cmo_int32;
69:
70: typedef struct {
71: int tag;
72: int size;
73: char *body;
74: } cmo_datum;
75:
76: typedef struct {
77: int tag;
78: char *s;
79: } cmo_string;
80:
81: typedef struct {
82: int tag;
83: cmo *ob;
84: } cmo_mathcap;
85:
86: typedef cmo_mathcap cmo_error2;
87: typedef cmo_mathcap cmo_ring_by_name;
88: typedef cmo_mathcap cmo_indeterminate;
89:
1.2 ohara 90: /* a double linked list */
1.1 ohara 91: typedef struct cell {
1.18 ohara 92: struct cmo *cmo;
1.1 ohara 93: struct cell *next;
1.2 ohara 94: struct cell *prev;
1.22 ohara 95: int exp;
1.1 ohara 96: } cell;
97:
98: typedef struct {
99: int tag;
100: int length; /* length of this list (unnecessary) */
101: cell head[1];
102: } cmo_list;
103:
104: typedef struct {
105: int tag;
106: int length;
107: int *exps;
108: cmo *coef;
109: } cmo_monomial32;
110:
111: typedef struct {
112: int tag;
113: mpz_t mpz;
114: } cmo_zz;
115:
116: typedef struct {
117: int tag;
1.34 ! ohara 118: mpq_t mpq;
1.1 ohara 119: } cmo_qq;
120:
1.12 ohara 121: typedef struct {
122: int tag;
123: double d; /* machine dependent */
124: } cmo_double;
125:
1.1 ohara 126: /* The following is a derived class from cmo_list.
1.2 ohara 127: that is, list_append can be used. */
1.1 ohara 128: typedef struct {
129: int tag;
130: int length; /* number of monomials */
131: cell head[1]; /* a list of monomials */
132: cmo *ringdef;
133: } cmo_distributed_polynomial;
1.24 ohara 134:
135: /* The following is a derived class from cmo_list.
136: that is, list_append can be used. */
137: typedef struct {
138: int tag;
139: int length; /* number of monomials */
140: cell head[1]; /* list of monomials */
141: int var; /* name of the main variable */
142: } cmo_polynomial_in_one_variable;
143:
144: typedef struct {
145: int tag;
146: cmo_list *ringdef; /* list of variables */
147: cmo *coef; /* ZZ, QQ, int32, Poly_in_1var, Tree, Zero, DPoly */
148: } cmo_recursive_polynomial;
1.1 ohara 149:
1.26 ohara 150: typedef struct {
151: int tag;
152: cmo_string *name;
153: cmo_list *attributes;
154: cmo_list *leaves;
155: } cmo_tree;
156:
157: typedef struct {
158: int tag;
159: cmo_list *args;
160: cmo_tree *body;
161: } cmo_lambda;
162:
1.1 ohara 163: typedef cmo ox;
164:
165: typedef ox ox_sync_ball;
166:
167: typedef struct {
168: int tag;
169: int command;
170: } ox_command;
171:
172: typedef struct {
173: int tag;
1.18 ohara 174: struct cmo *cmo;
1.1 ohara 175: } ox_data;
176:
177: cmo_null* new_cmo_null();
178: cmo_int32* new_cmo_int32(int i);
179: cmo_string* new_cmo_string(char* s);
180: cmo_mathcap* new_cmo_mathcap(cmo* ob);
181: cmo_list* new_cmo_list();
1.33 takayama 182: cmo_list* new_cmo_list_array(void *a[], int n);
183: cmo_list* new_cmo_list_array_map(void *a[], int n, void *(* mapf)(void *));
1.1 ohara 184: cmo_monomial32* new_cmo_monomial32();
185: cmo_monomial32* new_cmo_monomial32_size(int size);
186: cmo_zz* new_cmo_zz();
187: cmo_zz* new_cmo_zz_size(int size);
188: cmo_zz* new_cmo_zz_set_si(int integer);
189: cmo_zz* new_cmo_zz_set_mpz(mpz_ptr z);
190: cmo_zz* new_cmo_zz_noinit();
191: cmo_zz* new_cmo_zz_set_string(char* s);
1.34 ! ohara 192: cmo_qq* new_cmo_qq();
1.30 ohara 193: cmo_qq* new_cmo_qq_set_mpq(mpq_ptr q);
194: cmo_qq* new_cmo_qq_set_mpz(mpz_ptr num, mpz_ptr den);
1.1 ohara 195: cmo_zero* new_cmo_zero();
1.12 ohara 196: cmo_double* new_cmo_double(double d);
1.1 ohara 197: cmo_distributed_polynomial* new_cmo_distributed_polynomial();
198: cmo_dms_generic* new_cmo_dms_generic();
199: cmo_ring_by_name* new_cmo_ring_by_name(cmo* ob);
200: cmo_indeterminate* new_cmo_indeterminate(cmo* ob);
1.25 ohara 201: cmo_polynomial_in_one_variable* new_cmo_polynomial_in_one_variable(int var);
202: cmo_recursive_polynomial* new_cmo_recursive_polynomial(cmo_list* ringdef, cmo* coef);
1.26 ohara 203: cmo_tree* new_cmo_tree(cmo_string* name, cmo_list *attributes, cmo_list *leaves);
204: cmo_lambda* new_cmo_lambda(cmo_list* args, cmo_tree* body);
1.1 ohara 205: cmo_error2* new_cmo_error2(cmo* ob);
206:
207: ox_data* new_ox_data(cmo* c);
208: ox_command* new_ox_command(int sm_code);
209: ox_sync_ball* new_ox_sync_ball();
210:
211: char* new_string_set_cmo(cmo* m);
212:
213: cmo_error2* make_error_object(int err_code, cmo* ob);
214:
1.31 ohara 215: cmo* ox_parse_lisp(char *s);
216:
1.1 ohara 217: /* Low level API */
1.2 ohara 218: cmo* receive_cmo(OXFILE *fp);
1.17 ohara 219: cmo* receive_cmo_tag(OXFILE *fp, int tag);
1.2 ohara 220: int receive_int32(OXFILE *fp);
221: int receive_ox_tag(OXFILE *fp);
222:
223: void send_cmo(OXFILE *fp, cmo* m);
224: int send_int32(OXFILE *fp, int integer);
225: void send_ox(OXFILE *fp, ox* m);
226: void send_ox_cmo(OXFILE *fp, cmo* m);
227: void send_ox_command(OXFILE *fp, int sm_command);
228: int send_ox_tag(OXFILE *fp, int tag);
1.1 ohara 229:
230: int next_serial();
231: void setCmotypeDisable(int type);
232:
233: /* High level API */
1.2 ohara 234: void ox_close(OXFILE *sv);
235: void ox_shutdown(OXFILE *sv);
236: void ox_reset(OXFILE *sv);
237: void ox_execute_string(OXFILE *sv, char* str);
238: cmo_mathcap* ox_mathcap(OXFILE *sv);
239: char* ox_popString(OXFILE *sv);
240: void ox_pops(OXFILE *sv, int num);
241: cmo* ox_pop_cmo(OXFILE *sv);
242: void ox_push_cmo(OXFILE *sv, cmo *c);
243: void ox_push_cmd(OXFILE *sv, int sm_code);
244: void ox_cmo_rpc(OXFILE *sv, char *function, int argc, cmo *argv[]);
245: int ox_flush(OXFILE *sv);
246:
1.16 ohara 247: cell* list_first(cmo_list *);
248: int list_endof(cmo_list *, cell *el);
1.2 ohara 249: cell* list_next(cell *el);
1.16 ohara 250: cmo_list* list_append(cmo_list*, cmo *ob);
1.22 ohara 251: cmo_list* list_append_monomial(cmo_list* , cmo* coef, int exp);
1.16 ohara 252: cmo_list* list_appendl(cmo_list*, ...);
253: int list_length(cmo_list* );
254: cmo* list_nth(cmo_list* , int n);
1.2 ohara 255:
1.1 ohara 256: int cmolen_cmo(cmo* m);
1.2 ohara 257: void dump_buffer_init(char *s);
258: void dump_cmo(cmo* m);
259: void dump_ox_command(ox_command* m);
260: void dump_ox_data(ox_data* m);
1.1 ohara 261:
1.2 ohara 262: void print_cmo(cmo* c);
263: void resize_mpz(mpz_ptr mpz, int size);
1.1 ohara 264:
1.2 ohara 265: typedef cmo *(*hook_t)(OXFILE *, cmo *);
1.1 ohara 266:
267: int add_hook_before_send_cmo(hook_t func);
268: int add_hook_after_send_cmo(hook_t func);
269:
270: /* functions related to parse.c */
271:
272: #define PFLAG_ADDREV 1
273:
274: typedef struct symbol *symbol_t;
275:
276: symbol_t lookup_by_symbol(char *key);
277: symbol_t lookup_by_token(int tok);
278: symbol_t lookup_by_tag(int tag);
279: symbol_t lookup(int i);
1.13 ohara 280: char* get_symbol_by_tag(int tag);
1.2 ohara 281:
282: /* for mathcap database */
1.6 ohara 283: mathcap *new_mathcap();
1.33 takayama 284: void mathcap_init(int ver, char *vstr, char *sysname, int cmos[], int sms[]);
1.16 ohara 285: cmo_mathcap* mathcap_get(mathcap *);
286: mathcap *mathcap_update(mathcap *, cmo_mathcap *mc);
1.33 takayama 287: int mathcap_allowQ_cmo(mathcap *, cmo *ob);
1.2 ohara 288:
289: int oxf_read(void *buffer, size_t size, size_t num, OXFILE *oxfp);
290: int oxf_write(void *buffer, size_t size, size_t num, OXFILE *oxfp);
291:
292: /* for OXFILE */
1.25 ohara 293: int oxf_listen(int *portp);
1.2 ohara 294: OXFILE *oxf_connect_active(char *hostname, short port);
295: OXFILE *oxf_connect_passive(int listened);
296: OXFILE *oxf_open(int fd);
297: OXFILE *oxf_control_set(OXFILE *oxfp, OXFILE *control);
298: OXFILE *oxf_control(OXFILE *oxfp);
299: int oxf_confirm_client(OXFILE *oxfp, char *passwd);
300: int oxf_confirm_server(OXFILE *oxfp, char *passwd);
301: void oxf_flush(OXFILE *oxfp);
302: void oxf_close(OXFILE *oxfp);
303: void oxf_setopt(OXFILE *oxfp, int mode);
304: void oxf_determine_byteorder_client(OXFILE *oxfp);
305: void oxf_determine_byteorder_server(OXFILE *oxfp);
1.4 ohara 306: OXFILE *oxf_execute_cmd(OXFILE *oxfp, char *cmd);
1.8 ohara 307: cmo_mathcap *oxf_cmo_mathcap(OXFILE *oxfp);
1.6 ohara 308: void oxf_mathcap_update(OXFILE *oxfp, cmo_mathcap *ob);
1.2 ohara 309:
310: /* example: which("xterm", getenv("PATH")); */
311: char *which(char *exe, const char *env);
312: char *generate_otp();
1.1 ohara 313:
1.10 ohara 314: int ox_stderr_init(FILE *fp);
1.11 ohara 315: int ox_printf(char *format, ...);
1.16 ohara 316:
317: #ifdef __cplusplus
318: }
319: #endif
320:
1.1 ohara 321: #endif /* _OX_TOOLKIT_H_ */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>