Annotation of OpenXM/src/ox_toolkit/ox_toolkit.h, Revision 1.33
1.1 ohara 1: /* -*- mode: C -*- */
1.33 ! takayama 2: /* $OpenXM: OpenXM/src/ox_toolkit/ox_toolkit.h,v 1.32 2005/07/26 12:52:05 ohara 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;
118: cmo *num; /* Bunshi (cmo_zz) */
119: cmo *den; /* Bunbo (cmo_zz) */
120: } cmo_qq;
121:
1.12 ohara 122: typedef struct {
123: int tag;
124: double d; /* machine dependent */
125: } cmo_double;
126:
1.1 ohara 127: /* The following is a derived class from cmo_list.
1.2 ohara 128: that is, list_append can be used. */
1.1 ohara 129: typedef struct {
130: int tag;
131: int length; /* number of monomials */
132: cell head[1]; /* a list of monomials */
133: cmo *ringdef;
134: } cmo_distributed_polynomial;
1.24 ohara 135:
136: /* The following is a derived class from cmo_list.
137: that is, list_append can be used. */
138: typedef struct {
139: int tag;
140: int length; /* number of monomials */
141: cell head[1]; /* list of monomials */
142: int var; /* name of the main variable */
143: } cmo_polynomial_in_one_variable;
144:
145: typedef struct {
146: int tag;
147: cmo_list *ringdef; /* list of variables */
148: cmo *coef; /* ZZ, QQ, int32, Poly_in_1var, Tree, Zero, DPoly */
149: } cmo_recursive_polynomial;
1.1 ohara 150:
1.26 ohara 151: typedef struct {
152: int tag;
153: cmo_string *name;
154: cmo_list *attributes;
155: cmo_list *leaves;
156: } cmo_tree;
157:
158: typedef struct {
159: int tag;
160: cmo_list *args;
161: cmo_tree *body;
162: } cmo_lambda;
163:
1.1 ohara 164: typedef cmo ox;
165:
166: typedef ox ox_sync_ball;
167:
168: typedef struct {
169: int tag;
170: int command;
171: } ox_command;
172:
173: typedef struct {
174: int tag;
1.18 ohara 175: struct cmo *cmo;
1.1 ohara 176: } ox_data;
177:
178: cmo_null* new_cmo_null();
179: cmo_int32* new_cmo_int32(int i);
180: cmo_string* new_cmo_string(char* s);
181: cmo_mathcap* new_cmo_mathcap(cmo* ob);
182: cmo_list* new_cmo_list();
1.33 ! takayama 183: cmo_list* new_cmo_list_array(void *a[], int n);
! 184: cmo_list* new_cmo_list_array_map(void *a[], int n, void *(* mapf)(void *));
1.1 ohara 185: cmo_monomial32* new_cmo_monomial32();
186: cmo_monomial32* new_cmo_monomial32_size(int size);
187: cmo_zz* new_cmo_zz();
188: cmo_zz* new_cmo_zz_size(int size);
189: cmo_zz* new_cmo_zz_set_si(int integer);
190: cmo_zz* new_cmo_zz_set_mpz(mpz_ptr z);
191: cmo_zz* new_cmo_zz_noinit();
192: cmo_zz* new_cmo_zz_set_string(char* s);
1.30 ohara 193: cmo_qq* new_cmo_qq_noinit();
194: cmo_qq* new_cmo_qq_set_mpq(mpq_ptr q);
195: cmo_qq* new_cmo_qq_set_mpz(mpz_ptr num, mpz_ptr den);
1.1 ohara 196: cmo_zero* new_cmo_zero();
1.12 ohara 197: cmo_double* new_cmo_double(double d);
1.1 ohara 198: cmo_distributed_polynomial* new_cmo_distributed_polynomial();
199: cmo_dms_generic* new_cmo_dms_generic();
200: cmo_ring_by_name* new_cmo_ring_by_name(cmo* ob);
201: cmo_indeterminate* new_cmo_indeterminate(cmo* ob);
1.25 ohara 202: cmo_polynomial_in_one_variable* new_cmo_polynomial_in_one_variable(int var);
203: cmo_recursive_polynomial* new_cmo_recursive_polynomial(cmo_list* ringdef, cmo* coef);
1.26 ohara 204: cmo_tree* new_cmo_tree(cmo_string* name, cmo_list *attributes, cmo_list *leaves);
205: cmo_lambda* new_cmo_lambda(cmo_list* args, cmo_tree* body);
1.1 ohara 206: cmo_error2* new_cmo_error2(cmo* ob);
207:
208: ox_data* new_ox_data(cmo* c);
209: ox_command* new_ox_command(int sm_code);
210: ox_sync_ball* new_ox_sync_ball();
211:
212: char* new_string_set_cmo(cmo* m);
213:
214: cmo_error2* make_error_object(int err_code, cmo* ob);
215:
1.31 ohara 216: cmo* ox_parse_lisp(char *s);
217:
1.1 ohara 218: /* Low level API */
1.2 ohara 219: cmo* receive_cmo(OXFILE *fp);
1.17 ohara 220: cmo* receive_cmo_tag(OXFILE *fp, int tag);
1.2 ohara 221: int receive_int32(OXFILE *fp);
222: int receive_ox_tag(OXFILE *fp);
223:
224: void send_cmo(OXFILE *fp, cmo* m);
225: int send_int32(OXFILE *fp, int integer);
226: void send_ox(OXFILE *fp, ox* m);
227: void send_ox_cmo(OXFILE *fp, cmo* m);
228: void send_ox_command(OXFILE *fp, int sm_command);
229: int send_ox_tag(OXFILE *fp, int tag);
1.1 ohara 230:
231: int next_serial();
232: void setCmotypeDisable(int type);
233:
234: /* High level API */
1.2 ohara 235: void ox_close(OXFILE *sv);
236: void ox_shutdown(OXFILE *sv);
237: void ox_reset(OXFILE *sv);
238: void ox_execute_string(OXFILE *sv, char* str);
239: cmo_mathcap* ox_mathcap(OXFILE *sv);
240: char* ox_popString(OXFILE *sv);
241: void ox_pops(OXFILE *sv, int num);
242: cmo* ox_pop_cmo(OXFILE *sv);
243: void ox_push_cmo(OXFILE *sv, cmo *c);
244: void ox_push_cmd(OXFILE *sv, int sm_code);
245: void ox_cmo_rpc(OXFILE *sv, char *function, int argc, cmo *argv[]);
246: int ox_flush(OXFILE *sv);
247:
1.16 ohara 248: cell* list_first(cmo_list *);
249: int list_endof(cmo_list *, cell *el);
1.2 ohara 250: cell* list_next(cell *el);
1.16 ohara 251: cmo_list* list_append(cmo_list*, cmo *ob);
1.22 ohara 252: cmo_list* list_append_monomial(cmo_list* , cmo* coef, int exp);
1.16 ohara 253: cmo_list* list_appendl(cmo_list*, ...);
254: int list_length(cmo_list* );
255: cmo* list_nth(cmo_list* , int n);
1.2 ohara 256:
1.1 ohara 257: int cmolen_cmo(cmo* m);
1.2 ohara 258: void dump_buffer_init(char *s);
259: void dump_cmo(cmo* m);
260: void dump_ox_command(ox_command* m);
261: void dump_ox_data(ox_data* m);
1.1 ohara 262:
1.2 ohara 263: void print_cmo(cmo* c);
264: void resize_mpz(mpz_ptr mpz, int size);
1.1 ohara 265:
1.2 ohara 266: typedef cmo *(*hook_t)(OXFILE *, cmo *);
1.1 ohara 267:
268: int add_hook_before_send_cmo(hook_t func);
269: int add_hook_after_send_cmo(hook_t func);
270:
271: /* functions related to parse.c */
272:
273: #define PFLAG_ADDREV 1
274:
275: typedef struct symbol *symbol_t;
276:
277: symbol_t lookup_by_symbol(char *key);
278: symbol_t lookup_by_token(int tok);
279: symbol_t lookup_by_tag(int tag);
280: symbol_t lookup(int i);
1.13 ohara 281: char* get_symbol_by_tag(int tag);
1.2 ohara 282:
283: /* for mathcap database */
1.6 ohara 284: mathcap *new_mathcap();
1.33 ! takayama 285: void mathcap_init(int ver, char *vstr, char *sysname, int cmos[], int sms[]);
1.16 ohara 286: cmo_mathcap* mathcap_get(mathcap *);
287: mathcap *mathcap_update(mathcap *, cmo_mathcap *mc);
1.33 ! takayama 288: int mathcap_allowQ_cmo(mathcap *, cmo *ob);
1.2 ohara 289:
290: int oxf_read(void *buffer, size_t size, size_t num, OXFILE *oxfp);
291: int oxf_write(void *buffer, size_t size, size_t num, OXFILE *oxfp);
292:
293: /* for OXFILE */
1.25 ohara 294: int oxf_listen(int *portp);
1.2 ohara 295: OXFILE *oxf_connect_active(char *hostname, short port);
296: OXFILE *oxf_connect_passive(int listened);
297: OXFILE *oxf_open(int fd);
298: OXFILE *oxf_control_set(OXFILE *oxfp, OXFILE *control);
299: OXFILE *oxf_control(OXFILE *oxfp);
300: int oxf_confirm_client(OXFILE *oxfp, char *passwd);
301: int oxf_confirm_server(OXFILE *oxfp, char *passwd);
302: void oxf_flush(OXFILE *oxfp);
303: void oxf_close(OXFILE *oxfp);
304: void oxf_setopt(OXFILE *oxfp, int mode);
305: void oxf_determine_byteorder_client(OXFILE *oxfp);
306: void oxf_determine_byteorder_server(OXFILE *oxfp);
1.4 ohara 307: OXFILE *oxf_execute_cmd(OXFILE *oxfp, char *cmd);
1.8 ohara 308: cmo_mathcap *oxf_cmo_mathcap(OXFILE *oxfp);
1.6 ohara 309: void oxf_mathcap_update(OXFILE *oxfp, cmo_mathcap *ob);
1.2 ohara 310:
311: /* example: which("xterm", getenv("PATH")); */
312: char *which(char *exe, const char *env);
313: char *generate_otp();
1.1 ohara 314:
1.10 ohara 315: int ox_stderr_init(FILE *fp);
1.11 ohara 316: int ox_printf(char *format, ...);
1.16 ohara 317:
318: #ifdef __cplusplus
319: }
320: #endif
321:
1.1 ohara 322: #endif /* _OX_TOOLKIT_H_ */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>