Annotation of OpenXM/src/ox_toolkit/ox_toolkit.h, Revision 1.44
1.1 ohara 1: /* -*- mode: C -*- */
1.44 ! ohara 2: /* $OpenXM: OpenXM/src/ox_toolkit/ox_toolkit.h,v 1.43 2016/08/23 02:24: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.44 ! ohara 235: cmo_indeterminate* new_cmo_indeterminate_set_name(char *s);
1.25 ohara 236: cmo_polynomial_in_one_variable* new_cmo_polynomial_in_one_variable(int var);
237: cmo_recursive_polynomial* new_cmo_recursive_polynomial(cmo_list* ringdef, cmo* coef);
1.26 ohara 238: cmo_tree* new_cmo_tree(cmo_string* name, cmo_list *attributes, cmo_list *leaves);
239: cmo_lambda* new_cmo_lambda(cmo_list* args, cmo_tree* body);
1.1 ohara 240: cmo_error2* new_cmo_error2(cmo* ob);
241:
242: ox_data* new_ox_data(cmo* c);
243: ox_command* new_ox_command(int sm_code);
244: ox_sync_ball* new_ox_sync_ball();
245:
246: char* new_string_set_cmo(cmo* m);
247:
248: cmo_error2* make_error_object(int err_code, cmo* ob);
249:
1.31 ohara 250: cmo* ox_parse_lisp(char *s);
251:
1.1 ohara 252: /* Low level API */
1.2 ohara 253: cmo* receive_cmo(OXFILE *fp);
1.17 ohara 254: cmo* receive_cmo_tag(OXFILE *fp, int tag);
1.2 ohara 255: int receive_int32(OXFILE *fp);
256: int receive_ox_tag(OXFILE *fp);
257:
258: void send_cmo(OXFILE *fp, cmo* m);
259: int send_int32(OXFILE *fp, int integer);
260: void send_ox(OXFILE *fp, ox* m);
261: void send_ox_cmo(OXFILE *fp, cmo* m);
262: void send_ox_command(OXFILE *fp, int sm_command);
263: int send_ox_tag(OXFILE *fp, int tag);
1.1 ohara 264:
265: int next_serial();
266: void setCmotypeDisable(int type);
267:
268: /* High level API */
1.2 ohara 269: void ox_close(OXFILE *sv);
270: void ox_shutdown(OXFILE *sv);
271: void ox_reset(OXFILE *sv);
272: void ox_execute_string(OXFILE *sv, char* str);
273: cmo_mathcap* ox_mathcap(OXFILE *sv);
274: char* ox_popString(OXFILE *sv);
275: void ox_pops(OXFILE *sv, int num);
276: cmo* ox_pop_cmo(OXFILE *sv);
277: void ox_push_cmo(OXFILE *sv, cmo *c);
278: void ox_push_cmd(OXFILE *sv, int sm_code);
279: void ox_cmo_rpc(OXFILE *sv, char *function, int argc, cmo *argv[]);
280: int ox_flush(OXFILE *sv);
281:
1.16 ohara 282: cell* list_first(cmo_list *);
283: int list_endof(cmo_list *, cell *el);
1.2 ohara 284: cell* list_next(cell *el);
1.16 ohara 285: cmo_list* list_append(cmo_list*, cmo *ob);
1.22 ohara 286: cmo_list* list_append_monomial(cmo_list* , cmo* coef, int exp);
1.16 ohara 287: cmo_list* list_appendl(cmo_list*, ...);
288: int list_length(cmo_list* );
289: cmo* list_nth(cmo_list* , int n);
1.41 ohara 290: cmo* list_first_cmo(cmo_list *);
1.44 ! ohara 291: char* cmo_indeterminate_get_name(cmo_indeterminate *);
1.2 ohara 292:
1.1 ohara 293: int cmolen_cmo(cmo* m);
1.2 ohara 294: void dump_buffer_init(char *s);
295: void dump_cmo(cmo* m);
296: void dump_ox_command(ox_command* m);
297: void dump_ox_data(ox_data* m);
1.1 ohara 298:
1.2 ohara 299: void print_cmo(cmo* c);
300: void resize_mpz(mpz_ptr mpz, int size);
1.1 ohara 301:
1.37 noro 302: int cmo_to_int(cmo *n);
303:
1.2 ohara 304: typedef cmo *(*hook_t)(OXFILE *, cmo *);
1.1 ohara 305:
306: int add_hook_before_send_cmo(hook_t func);
307: int add_hook_after_send_cmo(hook_t func);
308:
309: /* functions related to parse.c */
310:
311: #define PFLAG_ADDREV 1
312:
313: typedef struct symbol *symbol_t;
314:
315: symbol_t lookup_by_symbol(char *key);
316: symbol_t lookup_by_token(int tok);
317: symbol_t lookup_by_tag(int tag);
318: symbol_t lookup(int i);
1.13 ohara 319: char* get_symbol_by_tag(int tag);
1.2 ohara 320:
321: /* for mathcap database */
1.6 ohara 322: mathcap *new_mathcap();
1.33 takayama 323: void mathcap_init(int ver, char *vstr, char *sysname, int cmos[], int sms[]);
1.43 ohara 324: void mathcap_init2(int ver, char *vstr, char *sysname, int cmos[], int sms[], char *options[]);
1.16 ohara 325: cmo_mathcap* mathcap_get(mathcap *);
326: mathcap *mathcap_update(mathcap *, cmo_mathcap *mc);
1.33 takayama 327: int mathcap_allowQ_cmo(mathcap *, cmo *ob);
1.2 ohara 328:
329: int oxf_read(void *buffer, size_t size, size_t num, OXFILE *oxfp);
330: int oxf_write(void *buffer, size_t size, size_t num, OXFILE *oxfp);
331:
332: /* for OXFILE */
1.25 ohara 333: int oxf_listen(int *portp);
1.2 ohara 334: OXFILE *oxf_connect_active(char *hostname, short port);
335: OXFILE *oxf_connect_passive(int listened);
336: OXFILE *oxf_open(int fd);
337: OXFILE *oxf_control_set(OXFILE *oxfp, OXFILE *control);
338: OXFILE *oxf_control(OXFILE *oxfp);
339: int oxf_confirm_client(OXFILE *oxfp, char *passwd);
340: int oxf_confirm_server(OXFILE *oxfp, char *passwd);
341: void oxf_flush(OXFILE *oxfp);
342: void oxf_close(OXFILE *oxfp);
343: void oxf_setopt(OXFILE *oxfp, int mode);
344: void oxf_determine_byteorder_client(OXFILE *oxfp);
345: void oxf_determine_byteorder_server(OXFILE *oxfp);
1.4 ohara 346: OXFILE *oxf_execute_cmd(OXFILE *oxfp, char *cmd);
1.8 ohara 347: cmo_mathcap *oxf_cmo_mathcap(OXFILE *oxfp);
1.6 ohara 348: void oxf_mathcap_update(OXFILE *oxfp, cmo_mathcap *ob);
1.2 ohara 349:
350: /* example: which("xterm", getenv("PATH")); */
351: char *which(char *exe, const char *env);
352: char *generate_otp();
1.1 ohara 353:
1.10 ohara 354: int ox_stderr_init(FILE *fp);
1.11 ohara 355: int ox_printf(char *format, ...);
1.16 ohara 356:
357: #ifdef __cplusplus
358: }
359: #endif
360:
1.1 ohara 361: #endif /* _OX_TOOLKIT_H_ */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>