[BACK]Return to eval.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / parse

Diff for /OpenXM_contrib2/asir2000/parse/eval.c between version 1.7 and 1.15

version 1.7, 2000/09/22 06:36:43 version 1.15, 2001/09/20 04:08:21
Line 45 
Line 45 
  * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,   * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
  * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.   * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
  *   *
  * $OpenXM: OpenXM_contrib2/asir2000/parse/eval.c,v 1.6 2000/09/21 09:19:27 noro Exp $   * $OpenXM: OpenXM_contrib2/asir2000/parse/eval.c,v 1.14 2001/09/05 09:01:28 noro Exp $
 */  */
 #include <ctype.h>  #include <ctype.h>
 #include "ca.h"  #include "ca.h"
 #include "al.h"  #include "al.h"
 #include "base.h"  #include "base.h"
 #include "parse.h"  #include "parse.h"
 #if !defined(THINK_C)  
 #include <sys/types.h>  #include <sys/types.h>
 #include <sys/stat.h>  #include <sys/stat.h>
 #endif  
 #if PARI  #if PARI
 #include "genpari.h"  #include "genpari.h"
 #endif  #endif
Line 67  int evalstatline;
Line 65  int evalstatline;
 int recv_intr;  int recv_intr;
   
 pointer bevalf(), evalmapf(), evall();  pointer bevalf(), evalmapf(), evall();
   pointer eval_rec_mapf(), beval_rec_mapf();
 Obj getopt_from_cpvs();  Obj getopt_from_cpvs();
   
 pointer eval(f)  pointer eval(f)
Line 83  FNODE f;
Line 82  FNODE f;
         FNODE f1;          FNODE f1;
         UP2 up2;          UP2 up2;
         UP up;          UP up;
           UM um;
           Obj obj;
         GF2N gf2n;          GF2N gf2n;
         GFPN gfpn;          GFPN gfpn;
           GFSN gfsn;
   
 #if defined(VISUAL)  #if defined(VISUAL)
         if ( recv_intr ) {          if ( recv_intr ) {
Line 101  FNODE f;
Line 103  FNODE f;
         if ( !f )          if ( !f )
                 return ( 0 );                  return ( 0 );
         switch ( f->id ) {          switch ( f->id ) {
                   case I_PAREN:
                           val = eval((FNODE)(FA0(f)));
                           break;
                   case I_MINUS:
                           a1 = eval((FNODE)(FA0(f)));
                           arf_chsgn((Obj)a1,&obj);
                           val = (pointer)obj;
                           break;
                 case I_BOP:                  case I_BOP:
                         a1 = eval((FNODE)FA1(f)); a2 = eval((FNODE)FA2(f));                          a1 = eval((FNODE)FA1(f)); a2 = eval((FNODE)FA2(f));
                         (*((ARF)FA0(f))->fp)(CO,a1,a2,&val);                          (*((ARF)FA0(f))->fp)(CO,a1,a2,&val);
                 break;                          break;
                 case I_COP:                  case I_COP:
                         a1 = eval((FNODE)FA1(f)); a2 = eval((FNODE)FA2(f));                          a1 = eval((FNODE)FA1(f)); a2 = eval((FNODE)FA2(f));
                         c = arf_comp(CO,a1,a2);                          c = arf_comp(CO,a1,a2);
Line 163  FNODE f;
Line 173  FNODE f;
                         break;                          break;
                 case I_MAP:                  case I_MAP:
                         val = evalmapf((FUNC)FA0(f),(FNODE)FA1(f)); break;                          val = evalmapf((FUNC)FA0(f),(FNODE)FA1(f)); break;
                   case I_RECMAP:
                           val = eval_rec_mapf((FUNC)FA0(f),(FNODE)FA1(f)); break;
                 case I_IFUNC:                  case I_IFUNC:
                         val = evalif((FNODE)FA0(f),(FNODE)FA1(f)); break;                          val = evalif((FNODE)FA0(f),(FNODE)FA1(f)); break;
 #if !defined(VISUAL)  #if !defined(VISUAL)
Line 240  FNODE f;
Line 252  FNODE f;
                                 a = eval((FNODE)FA0(f1)); ind = (NODE)FA1(f1);                                  a = eval((FNODE)FA0(f1)); ind = (NODE)FA1(f1);
                                 evalnodebody(ind,&tn);                                  evalnodebody(ind,&tn);
                                 putarray(a,tn,val = eval((FNODE)FA1(f)));                                  putarray(a,tn,val = eval((FNODE)FA1(f)));
                           } else {
                                   error("eval : invalid assignment");
                         }                          }
                         break;                          break;
                 case I_ANS:                  case I_ANS:
Line 255  FNODE f;
Line 269  FNODE f;
                         break;                          break;
                 case I_GFPNGEN:                  case I_GFPNGEN:
                         up = UPALLOC(1);                          up = UPALLOC(1);
                         up->d=1;                          DEG(up)=1;
                         up->c[0] = 0;                          COEF(up)[0] = 0;
                         up->c[1] = (Num)ONELM;                          COEF(up)[1] = (Num)ONELM;
                         MKGFPN(up,gfpn);                          MKGFPN(up,gfpn);
                         val = (pointer)gfpn;                          val = (pointer)gfpn;
                         break;                          break;
                   case I_GFSNGEN:
                           um = UMALLOC(1);
                           DEG(um) = 1;
                           COEF(um)[0] = 0;
                           COEF(um)[1] = _onesf();
                           MKGFSN(um,gfsn);
                           val = (pointer)gfsn;
                           break;
                 case I_STR:                  case I_STR:
                         MKSTR(str,FA0(f)); val = (pointer)str; break;                          MKSTR(str,FA0(f)); val = (pointer)str; break;
                 case I_FORMULA:                  case I_FORMULA:
Line 441  FNODE opt;
Line 463  FNODE opt;
         LIST args;          LIST args;
         pointer val;          pointer val;
         int i,n,level;          int i,n,level;
         NODE tn,sn,opts;          NODE tn,sn,opts,opt1;
     VS pvs;      VS pvs;
         char errbuf[BUFSIZ];          char errbuf[BUFSIZ];
           static int stack_size;
           static void *stack_base;
   
         if ( f->id == A_UNDEF ) {          if ( f->id == A_UNDEF ) {
                 sprintf(errbuf,"evalf : %s undefined",NAME(f));                  sprintf(errbuf,"evalf : %s undefined",NAME(f));
Line 475  FNODE opt;
Line 499  FNODE opt;
                         cur_binf = 0;                          cur_binf = 0;
                         break;                          break;
                 case A_USR:                  case A_USR:
                           /* stack check */
   #if !defined(VISUAL)
                           if ( !stack_size ) {
                                   struct rlimit rl;
                                   getrlimit(RLIMIT_STACK,&rl);
                                   stack_size = rl.rlim_cur;
                           }
                           if ( !stack_base )
                                   stack_base = (void *)GC_get_stack_base();
                           if ( (stack_base - (void *)&args) +0x100000 > stack_size )
                                   error("stack overflow");
   #endif
                         args = (LIST)eval(a);                          args = (LIST)eval(a);
                         if ( opt )                          if ( opt ) {
                                 opts = BDY((LIST)eval(opt));                                  opts = BDY((LIST)eval(opt));
                         else                                  /* opts = ["opt1",arg1],... */
                                   opt1 = BDY((LIST)BDY(opts));
                                   if ( !strcmp(BDY((STRING)BDY(opt1)),"option_list") ) {
                                           /*
                                            * the special option specification:
                                            *  option_list=[["o1","a1"],...]
                                            */
                                           asir_assert(BDY(NEXT(opt1)),O_LIST,"evalf");
                                           opts = BDY((LIST)BDY(NEXT(opt1)));
                                   }
                           } else
                                 opts = 0;                                  opts = 0;
                 pvs = f->f.usrf->pvs;                  pvs = f->f.usrf->pvs;
                 if ( PVSS ) {                  if ( PVSS ) {
Line 568  FNODE a;
Line 614  FNODE a;
         return val;          return val;
 }  }
   
   pointer eval_rec_mapf(f,a)
   FUNC f;
   FNODE a;
   {
           LIST args;
   
           args = (LIST)eval(a);
           return beval_rec_mapf(f,BDY(args));
   }
   
   pointer beval_rec_mapf(f,node)
   FUNC f;
   NODE node;
   {
           LIST args;
           NODE rest,t,n,r,r0;
           Obj head;
           VECT v,rv;
           MAT m,rm;
           LIST rl;
           int len,row,col,i,j;
           pointer val;
   
           head = (Obj)BDY(node); rest = NEXT(node);
           if ( !head ) {
                   val = bevalf(f,node);
                   return val;
           }
           switch ( OID(head) ) {
                   case O_VECT:
                           v = (VECT)head; len = v->len; MKVECT(rv,len);
                           for ( i = 0; i < len; i++ ) {
                                   MKNODE(t,BDY(v)[i],rest); BDY(rv)[i] = beval_rec_mapf(f,t);
                           }
                           val = (pointer)rv;
                           break;
                   case O_MAT:
                           m = (MAT)head; row = m->row; col = m->col; MKMAT(rm,row,col);
                           for ( i = 0; i < row; i++ )
                                   for ( j = 0; j < col; j++ ) {
                                           MKNODE(t,BDY(m)[i][j],rest);
                                           BDY(rm)[i][j] = beval_rec_mapf(f,t);
                                   }
                           val = (pointer)rm;
                           break;
                   case O_LIST:
                           n = BDY((LIST)head);
                           for ( r0 = r = 0; n; n = NEXT(n) ) {
                                   NEXTNODE(r0,r); MKNODE(t,BDY(n),rest);
                                   BDY(r) = beval_rec_mapf(f,t);
                           }
                           if ( r0 )
                                   NEXT(r) = 0;
                           MKLIST(rl,r0);
                           val = (pointer)rl;
                           break;
                   default:
                           val = bevalf(f,node);
                           break;
           }
           return val;
   }
   
 pointer bevalf(f,a)  pointer bevalf(f,a)
 FUNC f;  FUNC f;
 NODE a;  NODE a;
Line 700  NODE *dnp;
Line 809  NODE *dnp;
         NEXT(n) = 0; *dnp = n0;          NEXT(n) = 0; *dnp = n0;
 }  }
   
   void gen_searchf(name,r)
   char *name;
   FUNC *r;
   {
           FUNC val;
   
           searchf(sysf,name,&val);
           if ( !val )
                   searchf(ubinf,name,&val);
           if ( !val )
                   searchpf(name,&val);
           if ( !val )
                   searchf(usrf,name,&val);
           if ( !val )
                   appenduf(name,&val);
           *r = val;
   }
   
 void searchf(fn,name,r)  void searchf(fn,name,r)
 NODE fn;  NODE fn;
 char *name;  char *name;
Line 796  char *key;
Line 923  char *key;
 {  {
         NODE opts,opt;          NODE opts,opt;
         Obj value;          Obj value;
           LIST r;
         extern Obj VOIDobj;          extern Obj VOIDobj;
   
         opts = CPVS->opt;          opts = CPVS->opt;
         for ( ; opts; opts = NEXT(opts) ) {          if ( !key ) {
                 opt = BDY((LIST)BDY(opts));                  MKLIST(r,opts);
                 if ( !strcmp(key,BDY((STRING)BDY(opt))) )                  return (Obj)r;
                         return (Obj)BDY(NEXT(opt));          } else {
                   for ( ; opts; opts = NEXT(opts) ) {
                           asir_assert(BDY(opts),O_LIST,"getopt_from_cvps");
                           opt = BDY((LIST)BDY(opts));
                           if ( !strcmp(key,BDY((STRING)BDY(opt))) )
                                   return (Obj)BDY(NEXT(opt));
                   }
                   return VOIDobj;
         }          }
         return VOIDobj;  
   
 }  }

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.15

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