[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.30

1.1       ohara       1: /* -*- mode: C -*- */
1.30    ! ohara       2: /* $OpenXM: OpenXM/src/ox_toolkit/ox_toolkit.h,v 1.29 2005/03/03 06:21:23 ohara 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);
1.29      ohara      54:     double (*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);
1.30    ! ohara     191: cmo_qq*            new_cmo_qq_noinit();
        !           192: cmo_qq*            new_cmo_qq_set_mpq(mpq_ptr q);
        !           193: cmo_qq*            new_cmo_qq_set_mpz(mpz_ptr num, mpz_ptr den);
1.1       ohara     194: cmo_zero*          new_cmo_zero();
1.12      ohara     195: cmo_double*        new_cmo_double(double d);
1.1       ohara     196: cmo_distributed_polynomial* new_cmo_distributed_polynomial();
                    197: cmo_dms_generic*   new_cmo_dms_generic();
                    198: cmo_ring_by_name*  new_cmo_ring_by_name(cmo* ob);
                    199: cmo_indeterminate* new_cmo_indeterminate(cmo* ob);
1.25      ohara     200: cmo_polynomial_in_one_variable* new_cmo_polynomial_in_one_variable(int var);
                    201: cmo_recursive_polynomial* new_cmo_recursive_polynomial(cmo_list* ringdef, cmo* coef);
1.26      ohara     202: cmo_tree*          new_cmo_tree(cmo_string* name, cmo_list *attributes, cmo_list *leaves);
                    203: cmo_lambda*        new_cmo_lambda(cmo_list* args, cmo_tree* body);
1.1       ohara     204: cmo_error2*        new_cmo_error2(cmo* ob);
                    205:
                    206: ox_data*           new_ox_data(cmo* c);
                    207: ox_command*        new_ox_command(int sm_code);
                    208: ox_sync_ball*      new_ox_sync_ball();
                    209:
                    210: char*              new_string_set_cmo(cmo* m);
                    211:
                    212: cmo_error2*        make_error_object(int err_code, cmo* ob);
                    213:
                    214: /* Low level API */
1.2       ohara     215: cmo*               receive_cmo(OXFILE *fp);
1.17      ohara     216: cmo*               receive_cmo_tag(OXFILE *fp, int tag);
1.2       ohara     217: int                receive_int32(OXFILE *fp);
                    218: int                receive_ox_tag(OXFILE *fp);
                    219:
                    220: void               send_cmo(OXFILE *fp, cmo* m);
                    221: int                send_int32(OXFILE *fp, int integer);
                    222: void               send_ox(OXFILE *fp, ox* m);
                    223: void               send_ox_cmo(OXFILE *fp, cmo* m);
                    224: void               send_ox_command(OXFILE *fp, int sm_command);
                    225: int                send_ox_tag(OXFILE *fp, int tag);
1.1       ohara     226:
                    227: int                next_serial();
                    228: void               setCmotypeDisable(int type);
                    229:
                    230: /* High level API */
1.2       ohara     231: void               ox_close(OXFILE *sv);
                    232: void               ox_shutdown(OXFILE *sv);
                    233: void               ox_reset(OXFILE *sv);
                    234: void               ox_execute_string(OXFILE *sv, char* str);
                    235: cmo_mathcap*       ox_mathcap(OXFILE *sv);
                    236: char*              ox_popString(OXFILE *sv);
                    237: void               ox_pops(OXFILE *sv, int num);
                    238: cmo*               ox_pop_cmo(OXFILE *sv);
                    239: void               ox_push_cmo(OXFILE *sv, cmo *c);
                    240: void               ox_push_cmd(OXFILE *sv, int sm_code);
                    241: void               ox_cmo_rpc(OXFILE *sv, char *function, int argc, cmo *argv[]);
                    242: int                ox_flush(OXFILE *sv);
                    243:
1.16      ohara     244: cell*              list_first(cmo_list *);
                    245: int                list_endof(cmo_list *, cell *el);
1.2       ohara     246: cell*              list_next(cell *el);
1.16      ohara     247: cmo_list*          list_append(cmo_list*, cmo *ob);
1.22      ohara     248: cmo_list*          list_append_monomial(cmo_list* , cmo* coef, int exp);
1.16      ohara     249: cmo_list*          list_appendl(cmo_list*, ...);
                    250: int                list_length(cmo_list* );
                    251: cmo*               list_nth(cmo_list* , int n);
1.2       ohara     252:
1.1       ohara     253: int                cmolen_cmo(cmo* m);
1.2       ohara     254: void               dump_buffer_init(char *s);
                    255: void               dump_cmo(cmo* m);
                    256: void               dump_ox_command(ox_command* m);
                    257: void               dump_ox_data(ox_data* m);
1.1       ohara     258:
1.2       ohara     259: void               print_cmo(cmo* c);
                    260: void               resize_mpz(mpz_ptr mpz, int size);
1.1       ohara     261:
1.2       ohara     262: typedef cmo *(*hook_t)(OXFILE *, cmo *);
1.1       ohara     263:
                    264: int add_hook_before_send_cmo(hook_t func);
                    265: int add_hook_after_send_cmo(hook_t func);
                    266:
                    267: /* functions related to parse.c */
                    268:
                    269: #define PFLAG_ADDREV   1
                    270:
                    271: typedef struct symbol *symbol_t;
                    272:
1.2       ohara     273: void setflag_parse(int flag);
1.1       ohara     274: cmo *parse();
1.2       ohara     275: void init_parser(char *s);
1.1       ohara     276:
                    277: symbol_t lookup_by_symbol(char *key);
                    278: symbol_t lookup_by_token(int tok);
                    279: symbol_t lookup_by_tag(int tag);
                    280: symbol_t lookup(int i);
1.13      ohara     281: char*    get_symbol_by_tag(int tag);
1.2       ohara     282:
                    283: /* for mathcap database */
1.6       ohara     284: mathcap *new_mathcap();
                    285: void mathcap_init(int ver, char *vstr, char *sysname, int cmos[], int sms[]);
1.16      ohara     286: cmo_mathcap* mathcap_get(mathcap *);
                    287: mathcap *mathcap_update(mathcap *, cmo_mathcap *mc);
                    288: int mathcap_allowQ_cmo(mathcap *, cmo *ob);
1.2       ohara     289:
                    290: int oxf_read(void *buffer, size_t size, size_t num, OXFILE *oxfp);
                    291: int oxf_write(void *buffer, size_t size, size_t num, OXFILE *oxfp);
                    292:
                    293: /* for OXFILE */
1.25      ohara     294: int oxf_listen(int *portp);
1.2       ohara     295: OXFILE *oxf_connect_active(char *hostname, short port);
                    296: OXFILE *oxf_connect_passive(int listened);
                    297: OXFILE *oxf_open(int fd);
                    298: OXFILE *oxf_control_set(OXFILE *oxfp, OXFILE *control);
                    299: OXFILE *oxf_control(OXFILE *oxfp);
                    300: int  oxf_confirm_client(OXFILE *oxfp, char *passwd);
                    301: int  oxf_confirm_server(OXFILE *oxfp, char *passwd);
                    302: void oxf_flush(OXFILE *oxfp);
                    303: void oxf_close(OXFILE *oxfp);
                    304: void oxf_setopt(OXFILE *oxfp, int mode);
                    305: void oxf_determine_byteorder_client(OXFILE *oxfp);
                    306: void oxf_determine_byteorder_server(OXFILE *oxfp);
1.4       ohara     307: OXFILE *oxf_execute_cmd(OXFILE *oxfp, char *cmd);
1.8       ohara     308: cmo_mathcap *oxf_cmo_mathcap(OXFILE *oxfp);
1.6       ohara     309: void oxf_mathcap_update(OXFILE *oxfp, cmo_mathcap *ob);
1.2       ohara     310:
                    311: /* example: which("xterm", getenv("PATH")); */
                    312: char *which(char *exe, const char *env);
                    313: char *generate_otp();
1.1       ohara     314:
1.10      ohara     315: int ox_stderr_init(FILE *fp);
1.11      ohara     316: int ox_printf(char *format, ...);
1.16      ohara     317:
                    318: #ifdef __cplusplus
                    319: }
                    320: #endif
                    321:
1.1       ohara     322: #endif /* _OX_TOOLKIT_H_ */

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