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