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