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