ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/calfunc.c
(Generate patch)

Comparing ray/src/common/calfunc.c (file contents):
Revision 1.2 by greg, Tue Jun 26 09:15:13 1990 UTC vs.
Revision 2.4 by greg, Thu May 21 10:29:32 1992 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1991 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 22 | Line 22 | static char SCCSid[] = "$SunId$ LBL";
22  
23   #include  "calcomp.h"
24  
25 <
25 >                                /* bits in argument flag (better be right!) */
26 > #define  AFLAGSIZ       (8*sizeof(unsigned long))
27   #define  ALISTSIZ       6       /* maximum saved argument list */
28  
29   typedef struct activation {
# Line 51 | Line 52 | static double  l_exp(), l_log(), l_log10();
52   #ifdef  BIGLIB
53                          /* functions must be listed alphabetically */
54   static LIBR  library[MAXLIB] = {
55 <    { "acos", 1, l_acos },
56 <    { "asin", 1, l_asin },
57 <    { "atan", 1, l_atan },
58 <    { "atan2", 2, l_atan2 },
59 <    { "ceil", 1, l_ceil },
60 <    { "cos", 1, l_cos },
61 <    { "exp", 1, l_exp },
62 <    { "floor", 1, l_floor },
63 <    { "if", 3, l_if },
64 <    { "log", 1, l_log },
65 <    { "log10", 1, l_log10 },
66 <    { "rand", 1, l_rand },
67 <    { "select", 1, l_select },
68 <    { "sin", 1, l_sin },
69 <    { "sqrt", 1, l_sqrt },
70 <    { "tan", 1, l_tan },
55 >    { "acos", 1, ':', l_acos },
56 >    { "asin", 1, ':', l_asin },
57 >    { "atan", 1, ':', l_atan },
58 >    { "atan2", 2, ':', l_atan2 },
59 >    { "ceil", 1, ':', l_ceil },
60 >    { "cos", 1, ':', l_cos },
61 >    { "exp", 1, ':', l_exp },
62 >    { "floor", 1, ':', l_floor },
63 >    { "if", 3, ':', l_if },
64 >    { "log", 1, ':', l_log },
65 >    { "log10", 1, ':', l_log10 },
66 >    { "rand", 1, ':', l_rand },
67 >    { "select", 1, ':', l_select },
68 >    { "sin", 1, ':', l_sin },
69 >    { "sqrt", 1, ':', l_sqrt },
70 >    { "tan", 1, ':', l_tan },
71   };
72  
73   static int  libsize = 16;
# Line 74 | Line 75 | static int  libsize = 16;
75   #else
76                          /* functions must be listed alphabetically */
77   static LIBR  library[MAXLIB] = {
78 <    { "ceil", 1, l_ceil },
79 <    { "floor", 1, l_floor },
80 <    { "if", 3, l_if },
81 <    { "rand", 1, l_rand },
82 <    { "select", 1, l_select },
78 >    { "ceil", 1, ':', l_ceil },
79 >    { "floor", 1, ':', l_floor },
80 >    { "if", 3, ':', l_if },
81 >    { "rand", 1, ':', l_rand },
82 >    { "select", 1, ':', l_select },
83   };
84  
85   static int  libsize = 5;
# Line 87 | Line 88 | static int  libsize = 5;
88  
89   extern char  *savestr(), *emalloc();
90  
90 extern LIBR  *liblookup();
91
91   extern VARDEF  *argf();
92  
93   #ifdef  VARIABLE
# Line 130 | Line 129 | double  *a;
129      act.name = fname;
130      act.prev = curact;
131      act.ap = a;
132 <    act.an = (1L<<n)-1;
132 >    if (n >= AFLAGSIZ)
133 >        act.an = ~0;
134 >    else
135 >        act.an = (1L<<n)-1;
136      act.fun = NULL;
137      curact = &act;
138  
# Line 145 | Line 147 | double  *a;
147   }
148  
149  
150 < funset(fname, nargs, fptr)              /* set a library function */
150 > funset(fname, nargs, assign, fptr)      /* set a library function */
151   char  *fname;
152   int  nargs;
153 + int  assign;
154   double  (*fptr)();
155   {
156      register LIBR  *lp;
157  
158 <    if ((lp = liblookup(fname)) == NULL) {
158 >    if ((lp = liblookup(fname)) == NULL) {      /* insert */
159          if (libsize >= MAXLIB) {
160              eputs("Too many library functons!\n");
161              quit(1);
# Line 161 | Line 164 | double  (*fptr)();
164              if (strcmp(lp[-1].fname, fname) > 0) {
165                  lp[0].fname = lp[-1].fname;
166                  lp[0].nargs = lp[-1].nargs;
167 +                lp[0].atyp = lp[-1].atyp;
168                  lp[0].f = lp[-1].f;
169              } else
170                  break;
171          libsize++;
172      }
173 <    lp[0].fname = fname;                /* string must be static! */
174 <    lp[0].nargs = nargs;
175 <    lp[0].f = fptr;
173 >    if (fptr == NULL) {                         /* delete */
174 >        while (lp < &library[libsize-1]) {
175 >            lp[0].fname = lp[1].fname;
176 >            lp[0].nargs = lp[1].nargs;
177 >            lp[0].atyp = lp[1].atyp;
178 >            lp[0].f = lp[1].f;
179 >            lp++;
180 >        }
181 >        libsize--;
182 >    } else {                                    /* or assign */
183 >        lp[0].fname = fname;            /* string must be static! */
184 >        lp[0].nargs = nargs;
185 >        lp[0].atyp = assign;
186 >        lp[0].f = fptr;
187 >    }
188 >    libupdate(fname);                   /* relink library */
189   }
190  
191  
# Line 193 | Line 210 | argument(n)                    /* return nth argument for active functi
210   register int  n;
211   {
212      register ACTIVATION  *actp = curact;
213 <    EPNODE  *ep;
213 >    register EPNODE  *ep;
214      double  aval;
215  
216      if (actp == NULL || --n < 0) {
# Line 201 | Line 218 | register int  n;
218          quit(1);
219      }
220                                                  /* already computed? */
221 <    if (1L<<n & actp->an)
221 >    if (n < AFLAGSIZ && 1L<<n & actp->an)
222          return(actp->ap[n]);
223  
224      if (actp->fun == NULL || (ep = ekid(actp->fun, n+1)) == NULL) {
# Line 320 | Line 337 | char  *fname;
337  
338  
339   #ifndef  VARIABLE
340 + static VARDEF  *varlist = NULL;         /* our list of dummy variables */
341 +
342 +
343   VARDEF *
344   varinsert(vname)                /* dummy variable insert */
345   char  *vname;
# Line 330 | Line 350 | char  *vname;
350      vp->name = savestr(vname);
351      vp->nlinks = 1;
352      vp->def = NULL;
353 <    vp->lib = NULL;
354 <    vp->next = NULL;
353 >    vp->lib = liblookup(vname);
354 >    vp->next = varlist;
355 >    varlist = vp;
356      return(vp);
357   }
358  
# Line 339 | Line 360 | char  *vname;
360   varfree(vp)                     /* free dummy variable */
361   register VARDEF  *vp;
362   {
363 +    register VARDEF  *vp2;
364 +
365 +    if (vp == varlist)
366 +        varlist = vp->next;
367 +    else {
368 +        for (vp2 = varlist; vp2->next != vp; vp2 = vp2->next)
369 +                ;
370 +        vp2->next = vp->next;
371 +    }
372      freestr(vp->name);
373      efree((char *)vp);
374   }
375 +
376 +
377 + libupdate(nm)                   /* update library */
378 + char  *nm;
379 + {
380 +    register VARDEF  *vp;
381 +
382 +    for (vp = varlist; vp != NULL; vp = vp->next)
383 +        vp->lib = liblookup(vp->name);
384 + }
385   #endif
386  
387  
# Line 354 | Line 394 | register VARDEF  *vp;
394   static double
395   libfunc(fname, vp)                      /* execute library function */
396   char  *fname;
397 < register VARDEF  *vp;
397 > VARDEF  *vp;
398   {
399 <    VARDEF  dumdef;
399 >    register LIBR  *lp;
400      double  d;
401      int  lasterrno;
402  
403 <    if (vp == NULL) {
404 <        vp = &dumdef;
405 <        vp->lib = NULL;
406 <    }
407 <    if (((vp->lib == NULL || strcmp(fname, vp->lib->fname)) &&
368 <                                (vp->lib = liblookup(fname)) == NULL) ||
369 <                vp->lib->f == NULL) {
403 >    if (vp != NULL)
404 >        lp = vp->lib;
405 >    else
406 >        lp = liblookup(fname);
407 >    if (lp == NULL) {
408          eputs(fname);
409          eputs(": undefined function\n");
410          quit(1);
411      }
412      lasterrno = errno;
413      errno = 0;
414 <    d = (*vp->lib->f)();
414 >    d = (*lp->f)(lp->fname);
415   #ifdef  IEEE
416 <    if (!finite(d))
417 <        errno = EDOM;
416 >    if (errno == 0)
417 >        if (isnan(d))
418 >            errno = EDOM;
419 >        else if (isinf(d))
420 >            errno = ERANGE;
421   #endif
422      if (errno) {
423          wputs(fname);
424 <        wputs(": bad call\n");
424 >        if (errno == EDOM)
425 >                wputs(": domain error\n");
426 >        else if (errno == ERANGE)
427 >                wputs(": range error\n");
428 >        else
429 >                wputs(": error in call\n");
430          return(0.0);
431      }
432      errno = lasterrno;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines