[BACK]Return to ox_toolkit.h CVS log [TXT][DIR] Up to [local] / OpenXM / src / ox_toolkit

Annotation of OpenXM/src/ox_toolkit/ox_toolkit.h, Revision 1.28

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>