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