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

1.1       ohara       1: /* -*- mode: C -*- */
1.27    ! iwane       2: /* $OpenXM: OpenXM/src/ox_toolkit/ox_toolkit.h,v 1.26 2003/09/18 12:46:08 ohara Exp $ */
1.1       ohara       3:
                      4: #ifndef _OX_TOOLKIT_H_
                      5:
                      6: #define _OX_TOOLKIT_H_
                      7:
1.2       ohara       8: #include <stdio.h>
1.14      ohara       9: #if defined(WITH_GMP)
1.5       ohara      10: #include <gmp.h>
1.15      ohara      11: #else
                     12: #include "gmp_fake.h"
1.14      ohara      13: #endif /* WITH_GMP */
1.27    ! iwane      14:
        !            15: #ifdef __cplusplus
        !            16: extern "C" {
        !            17: #endif
        !            18:
1.5       ohara      19: #include <ox/cmotag.h>
                     20: #include <ox/oxMessageTag.h>
                     21: #include <ox/smCommand.h>
1.21      ohara      22: #include <gc/gc.h>
1.20      ohara      23:
1.21      ohara      24: #define MALLOC(x) GC_MALLOC((x))
1.23      ohara      25: #define MALLOC_ATOMIC(x) GC_MALLOC_ATOMIC((x))
1.20      ohara      26: #define ALLOCA(x) alloca((x))
1.21      ohara      27: /* #define FREE(x)   free((x)) */
                     28: #define FREE(x)
1.1       ohara      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 {
                     36:     int tag;
                     37:     int flag;
                     38: } table;
                     39:
                     40: typedef struct mathcap {
                     41:     table *cmotbl;
                     42:     table *smtbl;
                     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.2       ohara      58: } OXFILE;
1.1       ohara      59:
1.18      ohara      60: typedef struct cmo {
1.1       ohara      61:     int tag;
                     62: } cmo;
                     63:
                     64: typedef cmo cmo_null;
                     65: typedef cmo cmo_zero;
                     66: typedef cmo cmo_dms_generic;
                     67:
                     68: typedef struct {
                     69:     int tag;
                     70:     int i;
                     71: } cmo_int32;
                     72:
                     73: typedef struct {
                     74:     int tag;
                     75:     int size;
                     76:     char *body;
                     77: } cmo_datum;
                     78:
                     79: typedef struct {
                     80:     int tag;
                     81:     char *s;
                     82: } cmo_string;
                     83:
                     84: typedef struct {
                     85:     int tag;
                     86:     cmo *ob;
                     87: } cmo_mathcap;
                     88:
                     89: typedef cmo_mathcap cmo_error2;
                     90: typedef cmo_mathcap cmo_ring_by_name;
                     91: typedef cmo_mathcap cmo_indeterminate;
                     92:
1.2       ohara      93: /* a double linked list */
1.1       ohara      94: typedef struct cell {
1.18      ohara      95:     struct cmo *cmo;
1.1       ohara      96:     struct cell *next;
1.2       ohara      97:     struct cell *prev;
1.22      ohara      98:     int exp;
1.1       ohara      99: } cell;
                    100:
                    101: typedef struct {
                    102:     int tag;
                    103:     int length;   /* length of this list (unnecessary) */
                    104:     cell head[1];
                    105: } cmo_list;
                    106:
                    107: typedef struct {
                    108:     int tag;
                    109:     int length;
                    110:     int *exps;
                    111:     cmo *coef;
                    112: } cmo_monomial32;
                    113:
                    114: typedef struct {
                    115:     int tag;
                    116:     mpz_t mpz;
                    117: } cmo_zz;
                    118:
                    119: typedef struct {
                    120:     int tag;
                    121:     cmo *num;  /* Bunshi (cmo_zz) */
                    122:     cmo *den;  /* Bunbo (cmo_zz) */
                    123: } cmo_qq;
                    124:
1.12      ohara     125: typedef struct {
                    126:     int tag;
                    127:     double d; /* machine dependent */
                    128: } cmo_double;
                    129:
1.1       ohara     130: /* The following is a derived class from cmo_list.
1.2       ohara     131:    that is, list_append can be used. */
1.1       ohara     132: typedef struct {
                    133:     int tag;
                    134:     int length;    /* number of monomials */
                    135:     cell head[1];  /* a list of monomials */
                    136:     cmo *ringdef;
                    137: } cmo_distributed_polynomial;
1.24      ohara     138:
                    139: /* The following is a derived class from cmo_list.
                    140:    that is, list_append can be used. */
                    141: typedef struct {
                    142:     int tag;
                    143:     int length;   /* number of monomials */
                    144:     cell head[1]; /* list of monomials */
                    145:     int var;      /* name of the main variable */
                    146: } cmo_polynomial_in_one_variable;
                    147:
                    148: typedef struct {
                    149:     int tag;
                    150:     cmo_list *ringdef; /* list of variables */
                    151:     cmo *coef;  /* ZZ, QQ, int32, Poly_in_1var, Tree, Zero, DPoly */
                    152: } cmo_recursive_polynomial;
1.1       ohara     153:
1.26      ohara     154: typedef struct {
                    155:     int tag;
                    156:     cmo_string *name;
                    157:     cmo_list *attributes;
                    158:     cmo_list *leaves;
                    159: } cmo_tree;
                    160:
                    161: typedef struct {
                    162:     int tag;
                    163:     cmo_list *args;
                    164:     cmo_tree *body;
                    165: } cmo_lambda;
                    166:
1.1       ohara     167: typedef cmo ox;
                    168:
                    169: typedef ox ox_sync_ball;
                    170:
                    171: typedef struct {
                    172:     int tag;
                    173:     int command;
                    174: } ox_command;
                    175:
                    176: typedef struct {
                    177:     int tag;
1.18      ohara     178:     struct cmo *cmo;
1.1       ohara     179: } ox_data;
                    180:
                    181: cmo_null*          new_cmo_null();
                    182: cmo_int32*         new_cmo_int32(int i);
                    183: cmo_string*        new_cmo_string(char* s);
                    184: cmo_mathcap*       new_cmo_mathcap(cmo* ob);
                    185: cmo_list*          new_cmo_list();
                    186: cmo_monomial32*    new_cmo_monomial32();
                    187: cmo_monomial32*    new_cmo_monomial32_size(int size);
                    188: cmo_zz*            new_cmo_zz();
                    189: cmo_zz*            new_cmo_zz_size(int size);
                    190: cmo_zz*            new_cmo_zz_set_si(int integer);
                    191: cmo_zz*            new_cmo_zz_set_mpz(mpz_ptr z);
                    192: cmo_zz*            new_cmo_zz_noinit();
                    193: cmo_zz*            new_cmo_zz_set_string(char* s);
                    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>