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