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

1.1       ohara       1: /* -*- mode: C -*- */
1.32    ! ohara       2: /* $OpenXM: OpenXM/src/ox_toolkit/ox_toolkit.h,v 1.31 2005/07/20 17:48:03 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.32    ! ohara      19: #define OX_PROTOCOL_VERSION     20050304
        !            20: #define OX_TOOLKIT_VERSION      "ox_toolkit version 2005.7.20"
        !            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.2       ohara      28: #if !defined(__GNUC__) && !defined(__inline__)
                     29: #define __inline__
                     30: #endif
                     31:
1.7       ohara      32: /* Mathcap Local Database */
                     33: typedef struct {
1.32    ! ohara      34:        int  *cmd;
        !            35:        int  *cmo;
1.7       ohara      36: } mathcap;
                     37:
                     38: /* OpenXM File Descripter */
1.2       ohara      39: typedef struct OXFILE{
1.6       ohara      40:     int fd;
                     41:     int (*send_int32)(struct OXFILE *oxfp, int int32);
                     42:     int (*receive_int32)(struct OXFILE *oxfp);
                     43:     int serial_number;
1.9       ohara      44:     int received_serial_number;
1.6       ohara      45:     struct OXFILE *control;  /* pointer to his control server. */
                     46:     struct mathcap *mathcap;
                     47:     int error;
1.19      ohara      48:     char *wbuf;
                     49:     int wbuf_size;
                     50:     int wbuf_count;
1.28      ohara      51:     int (*send_double)(struct OXFILE *oxfp, double int64);
1.29      ohara      52:     double (*receive_double)(struct OXFILE *oxfp);
1.2       ohara      53: } OXFILE;
1.1       ohara      54:
1.18      ohara      55: typedef struct cmo {
1.1       ohara      56:     int tag;
                     57: } cmo;
                     58:
                     59: typedef cmo cmo_null;
                     60: typedef cmo cmo_zero;
                     61: typedef cmo cmo_dms_generic;
                     62:
                     63: typedef struct {
                     64:     int tag;
                     65:     int i;
                     66: } cmo_int32;
                     67:
                     68: typedef struct {
                     69:     int tag;
                     70:     int size;
                     71:     char *body;
                     72: } cmo_datum;
                     73:
                     74: typedef struct {
                     75:     int tag;
                     76:     char *s;
                     77: } cmo_string;
                     78:
                     79: typedef struct {
                     80:     int tag;
                     81:     cmo *ob;
                     82: } cmo_mathcap;
                     83:
                     84: typedef cmo_mathcap cmo_error2;
                     85: typedef cmo_mathcap cmo_ring_by_name;
                     86: typedef cmo_mathcap cmo_indeterminate;
                     87:
1.2       ohara      88: /* a double linked list */
1.1       ohara      89: typedef struct cell {
1.18      ohara      90:     struct cmo *cmo;
1.1       ohara      91:     struct cell *next;
1.2       ohara      92:     struct cell *prev;
1.22      ohara      93:     int exp;
1.1       ohara      94: } cell;
                     95:
                     96: typedef struct {
                     97:     int tag;
                     98:     int length;   /* length of this list (unnecessary) */
                     99:     cell head[1];
                    100: } cmo_list;
                    101:
                    102: typedef struct {
                    103:     int tag;
                    104:     int length;
                    105:     int *exps;
                    106:     cmo *coef;
                    107: } cmo_monomial32;
                    108:
                    109: typedef struct {
                    110:     int tag;
                    111:     mpz_t mpz;
                    112: } cmo_zz;
                    113:
                    114: typedef struct {
                    115:     int tag;
                    116:     cmo *num;  /* Bunshi (cmo_zz) */
                    117:     cmo *den;  /* Bunbo (cmo_zz) */
                    118: } cmo_qq;
                    119:
1.12      ohara     120: typedef struct {
                    121:     int tag;
                    122:     double d; /* machine dependent */
                    123: } cmo_double;
                    124:
1.1       ohara     125: /* The following is a derived class from cmo_list.
1.2       ohara     126:    that is, list_append can be used. */
1.1       ohara     127: typedef struct {
                    128:     int tag;
                    129:     int length;    /* number of monomials */
                    130:     cell head[1];  /* a list of monomials */
                    131:     cmo *ringdef;
                    132: } cmo_distributed_polynomial;
1.24      ohara     133:
                    134: /* The following is a derived class from cmo_list.
                    135:    that is, list_append can be used. */
                    136: typedef struct {
                    137:     int tag;
                    138:     int length;   /* number of monomials */
                    139:     cell head[1]; /* list of monomials */
                    140:     int var;      /* name of the main variable */
                    141: } cmo_polynomial_in_one_variable;
                    142:
                    143: typedef struct {
                    144:     int tag;
                    145:     cmo_list *ringdef; /* list of variables */
                    146:     cmo *coef;  /* ZZ, QQ, int32, Poly_in_1var, Tree, Zero, DPoly */
                    147: } cmo_recursive_polynomial;
1.1       ohara     148:
1.26      ohara     149: typedef struct {
                    150:     int tag;
                    151:     cmo_string *name;
                    152:     cmo_list *attributes;
                    153:     cmo_list *leaves;
                    154: } cmo_tree;
                    155:
                    156: typedef struct {
                    157:     int tag;
                    158:     cmo_list *args;
                    159:     cmo_tree *body;
                    160: } cmo_lambda;
                    161:
1.1       ohara     162: typedef cmo ox;
                    163:
                    164: typedef ox ox_sync_ball;
                    165:
                    166: typedef struct {
                    167:     int tag;
                    168:     int command;
                    169: } ox_command;
                    170:
                    171: typedef struct {
                    172:     int tag;
1.18      ohara     173:     struct cmo *cmo;
1.1       ohara     174: } ox_data;
                    175:
                    176: cmo_null*          new_cmo_null();
                    177: cmo_int32*         new_cmo_int32(int i);
                    178: cmo_string*        new_cmo_string(char* s);
                    179: cmo_mathcap*       new_cmo_mathcap(cmo* ob);
                    180: cmo_list*          new_cmo_list();
1.32    ! ohara     181: cmo_list*          new_cmo_list_set(void *a[], int n);
        !           182: cmo_list*          new_cmo_list_map(void *a[], int n, void *(* mapf)(void *));
1.1       ohara     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:
1.31      ohara     214: cmo*               ox_parse_lisp(char *s);
                    215:
1.1       ohara     216: /* Low level API */
1.2       ohara     217: cmo*               receive_cmo(OXFILE *fp);
1.17      ohara     218: cmo*               receive_cmo_tag(OXFILE *fp, int tag);
1.2       ohara     219: int                receive_int32(OXFILE *fp);
                    220: int                receive_ox_tag(OXFILE *fp);
                    221:
                    222: void               send_cmo(OXFILE *fp, cmo* m);
                    223: int                send_int32(OXFILE *fp, int integer);
                    224: void               send_ox(OXFILE *fp, ox* m);
                    225: void               send_ox_cmo(OXFILE *fp, cmo* m);
                    226: void               send_ox_command(OXFILE *fp, int sm_command);
                    227: int                send_ox_tag(OXFILE *fp, int tag);
1.1       ohara     228:
                    229: int                next_serial();
                    230: void               setCmotypeDisable(int type);
                    231:
                    232: /* High level API */
1.2       ohara     233: void               ox_close(OXFILE *sv);
                    234: void               ox_shutdown(OXFILE *sv);
                    235: void               ox_reset(OXFILE *sv);
                    236: void               ox_execute_string(OXFILE *sv, char* str);
                    237: cmo_mathcap*       ox_mathcap(OXFILE *sv);
                    238: char*              ox_popString(OXFILE *sv);
                    239: void               ox_pops(OXFILE *sv, int num);
                    240: cmo*               ox_pop_cmo(OXFILE *sv);
                    241: void               ox_push_cmo(OXFILE *sv, cmo *c);
                    242: void               ox_push_cmd(OXFILE *sv, int sm_code);
                    243: void               ox_cmo_rpc(OXFILE *sv, char *function, int argc, cmo *argv[]);
                    244: int                ox_flush(OXFILE *sv);
                    245:
1.16      ohara     246: cell*              list_first(cmo_list *);
                    247: int                list_endof(cmo_list *, cell *el);
1.2       ohara     248: cell*              list_next(cell *el);
1.16      ohara     249: cmo_list*          list_append(cmo_list*, cmo *ob);
1.22      ohara     250: cmo_list*          list_append_monomial(cmo_list* , cmo* coef, int exp);
1.16      ohara     251: cmo_list*          list_appendl(cmo_list*, ...);
                    252: int                list_length(cmo_list* );
                    253: cmo*               list_nth(cmo_list* , int n);
1.32    ! ohara     254: void**             list_to_array(cmo_list *c);
        !           255: void**             list_to_array_map(cmo_list *c, void *(* mapf)(void *));
1.2       ohara     256:
1.1       ohara     257: int                cmolen_cmo(cmo* m);
1.2       ohara     258: void               dump_buffer_init(char *s);
                    259: void               dump_cmo(cmo* m);
                    260: void               dump_ox_command(ox_command* m);
                    261: void               dump_ox_data(ox_data* m);
1.1       ohara     262:
1.2       ohara     263: void               print_cmo(cmo* c);
                    264: void               resize_mpz(mpz_ptr mpz, int size);
1.1       ohara     265:
1.2       ohara     266: typedef cmo *(*hook_t)(OXFILE *, cmo *);
1.1       ohara     267:
                    268: int add_hook_before_send_cmo(hook_t func);
                    269: int add_hook_after_send_cmo(hook_t func);
                    270:
                    271: /* functions related to parse.c */
                    272:
                    273: #define PFLAG_ADDREV   1
                    274:
                    275: typedef struct symbol *symbol_t;
                    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();
1.32    ! ohara     285: void mathcap_init(char *version, char *sysname);
1.16      ohara     286: cmo_mathcap* mathcap_get(mathcap *);
                    287: mathcap *mathcap_update(mathcap *, cmo_mathcap *mc);
1.2       ohara     288:
                    289: int oxf_read(void *buffer, size_t size, size_t num, OXFILE *oxfp);
                    290: int oxf_write(void *buffer, size_t size, size_t num, OXFILE *oxfp);
                    291:
                    292: /* for OXFILE */
1.25      ohara     293: int oxf_listen(int *portp);
1.2       ohara     294: OXFILE *oxf_connect_active(char *hostname, short port);
                    295: OXFILE *oxf_connect_passive(int listened);
                    296: OXFILE *oxf_open(int fd);
                    297: OXFILE *oxf_control_set(OXFILE *oxfp, OXFILE *control);
                    298: OXFILE *oxf_control(OXFILE *oxfp);
                    299: int  oxf_confirm_client(OXFILE *oxfp, char *passwd);
                    300: int  oxf_confirm_server(OXFILE *oxfp, char *passwd);
                    301: void oxf_flush(OXFILE *oxfp);
                    302: void oxf_close(OXFILE *oxfp);
                    303: void oxf_setopt(OXFILE *oxfp, int mode);
                    304: void oxf_determine_byteorder_client(OXFILE *oxfp);
                    305: void oxf_determine_byteorder_server(OXFILE *oxfp);
1.4       ohara     306: OXFILE *oxf_execute_cmd(OXFILE *oxfp, char *cmd);
1.8       ohara     307: cmo_mathcap *oxf_cmo_mathcap(OXFILE *oxfp);
1.6       ohara     308: void oxf_mathcap_update(OXFILE *oxfp, cmo_mathcap *ob);
1.2       ohara     309:
                    310: /* example: which("xterm", getenv("PATH")); */
                    311: char *which(char *exe, const char *env);
                    312: char *generate_otp();
1.1       ohara     313:
1.10      ohara     314: int ox_stderr_init(FILE *fp);
1.11      ohara     315: int ox_printf(char *format, ...);
1.16      ohara     316:
                    317: #ifdef __cplusplus
                    318: }
                    319: #endif
                    320:
1.1       ohara     321: #endif /* _OX_TOOLKIT_H_ */

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