/[ascend]/trunk/base/generic/compiler/extfunc.c
ViewVC logotype

Diff of /trunk/base/generic/compiler/extfunc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 100 by johnpye, Wed Nov 30 05:53:20 2005 UTC revision 101 by jds, Sat Dec 10 04:22:07 2005 UTC
# Line 29  Line 29 
29    
30  #include "utilities/ascConfig.h"  #include "utilities/ascConfig.h"
31  #include "utilities/ascMalloc.h"  #include "utilities/ascMalloc.h"
32    #include "utilities/ascPanic.h"
33  #include "general/hashpjw.h"  #include "general/hashpjw.h"
34  #include "general/list.h"  #include "general/list.h"
35  #include "general/table.h"  #include "general/table.h"
# Line 45  struct ExternalFunc *CreateExternalFunc( Line 46  struct ExternalFunc *CreateExternalFunc(
46  {  {
47    struct ExternalFunc *result;    struct ExternalFunc *result;
48    result = (struct ExternalFunc *)ascmalloc(sizeof(struct ExternalFunc));    result = (struct ExternalFunc *)ascmalloc(sizeof(struct ExternalFunc));
49      if (result == NULL) {
50        return NULL;
51      }
52    result->name = name;    result->name = name;
53    result->n_inputs = 0;    result->n_inputs = 0;
54    result->n_outputs = 0;    result->n_outputs = 0;
# Line 66  int CreateUserFunction(CONST char *name, Line 70  int CreateUserFunction(CONST char *name,
70                 CONST char *help)                 CONST char *help)
71  {  {
72    struct ExternalFunc *efunc;    struct ExternalFunc *efunc;
73    if (!name)    if (name == NULL) {
74      return 1;      return 1;
75      }
76    efunc = LookupExtFunc(name);    efunc = LookupExtFunc(name);
77    if (efunc) {      /* name was pre-loaded -- just update the info */    if (efunc != NULL) {    /* name was pre-loaded -- just update the info */
78      efunc->n_inputs = n_inputs;      efunc->n_inputs = n_inputs;
79      efunc->n_outputs = n_outputs;      efunc->n_outputs = n_outputs;
80      efunc->init = init;      efunc->init = init;
81      efunc->value = value;      efunc->value = value;   /* should be *value */
82      efunc->deriv = deriv;      efunc->deriv = deriv;   /* should be *deriv */
83      efunc->deriv2 = deriv2;      efunc->deriv2 = deriv2; /* should be *deriv2 */
84      if (help) {      if (help) {
85        if (efunc->help) ascfree((char *)efunc->help);        if (efunc->help) ascfree((char *)efunc->help);
86        efunc->help = (char *)ascmalloc((strlen(help)+1)*sizeof(char));        efunc->help = (char *)ascmalloc((strlen(help)+1)*sizeof(char));
87          asc_assert(efunc->help != NULL);
88        strcpy(efunc->help,help);        strcpy(efunc->help,help);
89      }      }
90      else      else
91        efunc->help = NULL;        efunc->help = NULL;
92    } else {    } else {
93      efunc = (struct ExternalFunc *)ascmalloc(sizeof(struct ExternalFunc));      efunc = (struct ExternalFunc *)ascmalloc(sizeof(struct ExternalFunc));
94      assert(efunc!=NULL);      asc_assert(efunc!=NULL);
95      efunc->name = SCP(AddSymbol(name)); /* add or find name in symbol table */      efunc->name = SCP(AddSymbol(name)); /* add or find name in symbol table */
96                                          /* the main symtab owns the string */                                          /* the main symtab owns the string */
97      efunc->n_inputs = n_inputs;      efunc->n_inputs = n_inputs;
98      efunc->n_outputs = n_outputs;      efunc->n_outputs = n_outputs;
99      efunc->init = init;      efunc->init = init;
100      efunc->value = value;      efunc->value = value;   /* should be *value */
101      efunc->deriv = deriv;      efunc->deriv = deriv;   /* should be *deriv */
102      efunc->deriv2 = deriv2;      efunc->deriv2 = deriv2; /* should be *deriv2 */
103      if (help) {      if (help) {
104        efunc->help = (char *)ascmalloc((strlen(help)+1)*sizeof(char));        efunc->help = (char *)ascmalloc((strlen(help)+1)*sizeof(char));
105          asc_assert(efunc->help != NULL);
106        strcpy(efunc->help,help);        strcpy(efunc->help,help);
107      }      }
108      else      else
# Line 129  void DestroyExternalFunc(struct External Line 136  void DestroyExternalFunc(struct External
136    
137  int (*GetInitFunc(struct ExternalFunc *efunc))(/* */)  int (*GetInitFunc(struct ExternalFunc *efunc))(/* */)
138  {  {
139    assert(efunc!=NULL);    asc_assert(efunc!=NULL);
140    return efunc->init;    return efunc->init;
141  }  }
142    
143  ExtBBoxFunc *GetValueFunc(struct ExternalFunc *efunc)  ExtBBoxFunc *GetValueFunc(struct ExternalFunc *efunc)
144  {  {
145    assert(efunc!=NULL);    asc_assert(efunc!=NULL);
146    return (ExtBBoxFunc *)efunc->value;    return (ExtBBoxFunc *)efunc->value;
147  }  }
148    
149    
150  ExtBBoxFunc *GetDerivFunc(struct ExternalFunc *efunc)  ExtBBoxFunc *GetDerivFunc(struct ExternalFunc *efunc)
151  {  {
152    assert(efunc!=NULL);    asc_assert(efunc!=NULL);
153    return (ExtBBoxFunc *)efunc->deriv;    return (ExtBBoxFunc *)efunc->deriv;
154  }  }
155    
156  ExtBBoxFunc *GetDeriv2Func(struct ExternalFunc *efunc)  ExtBBoxFunc *GetDeriv2Func(struct ExternalFunc *efunc)
157  {  {
158    assert(efunc!=NULL);    asc_assert(efunc!=NULL);
159    return (ExtBBoxFunc *)efunc->deriv2;    return (ExtBBoxFunc *)efunc->deriv2;
160  }  }
161    
# Line 169  ExtBBoxFunc *GetDeriv2Func(struct Extern Line 176  ExtBBoxFunc *GetDeriv2Func(struct Extern
176    
177  ExtEvalFunc **GetValueJumpTable(struct ExternalFunc *efunc)  ExtEvalFunc **GetValueJumpTable(struct ExternalFunc *efunc)
178  {  {
179    assert(efunc!=NULL);    asc_assert(efunc!=NULL);
180    return efunc->value;    return efunc->value;    /* error, efunc->value is not an array of pointers */
181  }  }
182    
183  ExtEvalFunc **GetDerivJumpTable(struct ExternalFunc *efunc)  ExtEvalFunc **GetDerivJumpTable(struct ExternalFunc *efunc)
184  {  {
185    assert(efunc!=NULL);    asc_assert(efunc!=NULL);
186    return efunc->deriv;    return efunc->deriv;    /* error, efunc->value is not an array of pointers */
187  }  }
188    
189  #ifdef THIS_IS_AN_UNUSED_FUNCTION  #ifdef THIS_IS_AN_UNUSED_FUNCTION
190  static  static
191  ExtEvalFunc **GetValueDeriv2Table(struct ExternalFunc *efunc)  ExtEvalFunc **GetValueDeriv2Table(struct ExternalFunc *efunc)
192  {  {
193    assert(efunc!=NULL);    asc_assert(efunc!=NULL);
194    return efunc->deriv2;    return efunc->deriv2;   /* error, efunc->value is not an array of pointers */
195  }  }
196  #endif /* THIS_IS_AN_UNUSED_FUNCTION */  #endif /* THIS_IS_AN_UNUSED_FUNCTION */
197    
198    
199  CONST char *ExternalFuncName(CONST struct ExternalFunc *efunc)  CONST char *ExternalFuncName(CONST struct ExternalFunc *efunc)
200  {  {
201    assert(efunc!=NULL);    asc_assert(efunc!=NULL);
202    return efunc->name;    return efunc->name;
203  }  }
204    
205  unsigned long NumberInputArgs(CONST struct ExternalFunc *efunc)  unsigned long NumberInputArgs(CONST struct ExternalFunc *efunc)
206  {  {
207    assert(efunc!=NULL);    asc_assert(efunc!=NULL);
208    return efunc->n_inputs;    return efunc->n_inputs;
209  }  }
210    
211  unsigned long NumberOutputArgs(CONST struct ExternalFunc *efunc)  unsigned long NumberOutputArgs(CONST struct ExternalFunc *efunc)
212  {  {
213    assert(efunc!=NULL);    asc_assert(efunc!=NULL);
214    return efunc->n_outputs;    return efunc->n_outputs;
215  }  }
216    
# Line 224  int AddExternalFunc(struct ExternalFunc Line 231  int AddExternalFunc(struct ExternalFunc
231    struct ExternalFunc *found, *tmp;    struct ExternalFunc *found, *tmp;
232    char *name;    char *name;
233    
234    assert(efunc!=NULL);    asc_assert(efunc!=NULL);
235    name = (char *)efunc->name;    name = (char *)efunc->name;
236    found = (struct ExternalFunc *)LookupTableData(ExternalFuncLibrary,name);    found = (struct ExternalFunc *)LookupTableData(ExternalFuncLibrary,name);
237    if (found) {      /* function name already exists */    if (found) {      /* function name already exists */

Legend:
Removed from v.100  
changed lines
  Added in v.101

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22