/[ascend]/trunk/ascend/compiler/packages.c
ViewVC logotype

Annotation of /trunk/ascend/compiler/packages.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2336 - (hide annotations) (download) (as text)
Sun Dec 26 03:44:24 2010 UTC (12 years, 2 months ago) by jpye
File MIME type: text/x-csrc
File size: 6813 byte(s)
Suppress some debug output.
In mtx_vector, initialise some members of mtx_vector class, because otherwise they trigger valgrind errors.
1 johnpye 529 /* ASCEND modelling environment
2     Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly, Kirk Abbott.
3     Copyright (C) 2006 Carnegie Mellon University
4 aw0a 1
5 johnpye 529 This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2, or (at your option)
8     any later version.
9    
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13     GNU General Public License for more details.
14    
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 59 Temple Place - Suite 330,
18     Boston, MA 02111-1307, USA.
19     *//**
20 johnpye 697 @file
21 johnpye 62 Code to support dynamic and static loading of user packages.
22    
23 johnpye 1162 'Packages' are bits of code that add functionality to ASCEND, like 'plugins'
24     or 'addins' on other projects. In ASCEND we have a few that are pretty much
25     essential -- the 'built in' packges. They are only packages in the sense
26     that a 'register' function must be called to connect them correctly with
27     the rest of the system.
28 jpye 1524
29 johnpye 1162 Next there are the 'static' packages. These ones are linked into
30 johnpye 62 The default state is to have packages. As such it takes an explicit
31     definition of NO_PACKAGES, if packages are not to be handled.
32     An explicit definition of STATIC_PACKAGES or DYNAMIC_PACKAGES is also
33     required.
34 johnpye 529 *//*
35     by Kirk Abbott
36     Created: July 4, 1994
37 johnpye 697 Last in CVS: 1.14 ballan 1998/03/06 15:47:14
38 johnpye 62 */
39 johnpye 529
40 aw0a 1 #include <math.h>
41     #include <ctype.h> /* was compiler/actype.h */
42 johnpye 542
43 jpye 2323 #include <ascend/general/platform.h>
44 jpye 2018 #include <ascend/utilities/config.h> /* NEW */
45 johnpye 542
46 jpye 1519 #ifndef ASC_DEFAULT_ASCENDLIBRARY
47     # error "Where is ASC_DEFAULT_ASCENDLIBRARY???"
48 johnpye 542 #endif
49    
50 jpye 2018 #include <ascend/general/ospath.h>
51 johnpye 542
52 johnpye 1210
53 jpye 2322 #include <ascend/general/ascMalloc.h>
54 jpye 2018 #include <ascend/utilities/ascEnvVar.h>
55     #include <ascend/compiler/importhandler.h>
56 jpye 2323 #include <ascend/general/panic.h>
57 jpye 2018 #include <ascend/general/list.h>
58 johnpye 399 #include "symtab.h"
59 johnpye 1211
60    
61 johnpye 399 #include "functype.h"
62 johnpye 669 #include "expr_types.h"
63 johnpye 399 #include "extcall.h"
64     #include "mathinst.h"
65     #include "instance_enum.h"
66     #include "instquery.h"
67     #include "atomvalue.h"
68     #include "find.h"
69 johnpye 908 #include "rel_blackbox.h"
70     #include "vlist.h"
71 johnpye 399 #include "relation.h"
72     #include "safe.h"
73     #include "relation_util.h"
74     #include "extfunc.h"
75 jpye 2018 #include <ascend/packages/sensitivity.h>
76     #include <ascend/packages/ascFreeAllVars.h>
77     #include <ascend/packages/defaultall.h>
78 johnpye 399 #include "module.h"
79     #include "packages.h"
80 jpye 1616 #include "defaultpaths.h"
81 aw0a 1
82 jpye 2336 /* #define PACKAGES_DEBUG */
83 jpye 1628
84 johnpye 62 /*
85     Initialise the slv data structures used when calling external fns
86     */
87 johnpye 908 void Init_BBoxInterp(struct BBoxInterp *interp)
88 aw0a 1 {
89 johnpye 908 if (interp){
90     interp->status = calc_all_ok;
91     interp->user_data = NULL;
92     interp->task = bb_none;
93 aw0a 1 }
94     }
95    
96 johnpye 62 /*---------------------------------------------
97     BUILT-IN PACKAGES...
98     */
99    
100     /**
101 jpye 1519 Load builtin packages (those that are compiled into libascend)
102 johnpye 62
103     @return 0 if success, 1 if failure.
104     */
105     static
106 johnpye 1132 int Builtins_Init(void){
107 johnpye 62 int result = 0;
108    
109 johnpye 804 /* ERROR_REPORTER_DEBUG("Loading function asc_free_all_variables\n"); */
110 johnpye 870 result = CreateUserFunctionMethod("asc_free_all_variables"
111     ,Asc_FreeAllVars
112     ,1 /* num of args */
113     ,"Unset 'fixed' flag of all items of type 'solver_var'" /* help */
114     ,NULL /* user_data */
115 johnpye 912 ,NULL /* destroy fn */
116 johnpye 870 );
117 johnpye 1289
118 jpye 2336 #ifdef PACKAGES_DEBUG
119 jpye 2242 CONSOLE_DEBUG("Registering EXTERNAL defaultself_visit_childatoms");
120 jpye 2336 #endif
121 jpye 1372 result = CreateUserFunctionMethod("defaultself_visit_childatoms"
122     ,defaultself_visit_childatoms
123 johnpye 1289 ,1 /* num of args */
124 jpye 1372 ,"Set local child atoms to their ATOMs' DEFAULT values; recurse into arrays." /* help */
125 johnpye 1289 ,NULL /* user_data */
126     ,NULL /* destroy fn */
127     );
128 johnpye 1291
129 jpye 2336 #ifdef PACKAGES_DEBUG
130 jpye 2241 CONSOLE_DEBUG("Registering EXTERNAL defaultself_visit_submodels");
131 jpye 2336 #endif
132 jpye 1372 result = CreateUserFunctionMethod("defaultself_visit_submodels"
133     ,defaultself_visit_submodels
134 johnpye 1291 ,1 /* num of args */
135 jpye 1372 ,"Call 'default_self' methods on any nested sub-models." /* help */
136 johnpye 1291 ,NULL /* user_data */
137     ,NULL /* destroy fn */
138     );
139 jpye 1519
140 johnpye 62 return result;
141     }
142    
143 johnpye 864 /* return 0 on success */
144 jpye 1519 int package_load(CONST char *partialpath, CONST char *initfunc){
145 aw0a 1
146 johnpye 542 struct FilePath *fp1;
147     int result;
148 johnpye 864 struct ImportHandler *handler=NULL;
149 ballan 2036 static const char *default_solvers_path = NULL;
150     static const char *default_library_path = NULL;
151 jpye 1616 if(!default_solvers_path){
152     default_solvers_path = get_default_solvers_path();
153 jpye 2183 /*CONSOLE_DEBUG("Default ASCENDSOLVERS set to '%s'", default_solvers_path);*/
154 jpye 1616 }
155     if(!default_library_path){
156     default_library_path = get_default_library_path();
157 jpye 2183 /*CONSOLE_DEBUG("Default ASCENDLIBRARY set to '%s'", default_library_path);*/
158 jpye 1616 }
159 johnpye 62
160 jpye 2336 #ifdef PACKAGES_DEBUG
161 jpye 1628 CONSOLE_DEBUG("Searching for external library '%s'",partialpath);
162     #endif
163 jpye 1616
164 johnpye 864 importhandler_createlibrary();
165    
166 jpye 1519 /* search in the ASCENDSOLVERS directory/ies first */
167 johnpye 864 fp1 = importhandler_findinpath(
168 jpye 1616 partialpath, default_solvers_path, ASC_ENV_SOLVERS,&handler
169 johnpye 864 );
170 jpye 1519
171     /* next, search in the ASCENDLIBRARY */
172 johnpye 864 if(fp1==NULL){
173 jpye 1519 fp1 = importhandler_findinpath(
174 jpye 1616 partialpath, default_library_path, ASC_ENV_LIBRARY,&handler
175 jpye 1519 );
176     if(fp1==NULL){
177 jpye 2336 #ifdef PACKAGES_DEBUG
178 jpye 1519 CONSOLE_DEBUG("External library '%s' not found",partialpath);
179 jpye 2336 #endif
180 jpye 1519 ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"External library '%s' not found.",partialpath);
181     return 1; /* failure */
182     }
183 jpye 2336 #ifdef PACKAGES_DEBUG
184 jpye 1628 else{
185     CONSOLE_DEBUG("FOUND in $ASCENDLIBRARY");
186     }
187     }else{
188     CONSOLE_DEBUG("Found in pwd or in $ASCENDSOLVERS");
189     #endif
190 johnpye 542 }
191 johnpye 380
192 johnpye 864 asc_assert(handler!=NULL);
193 jpye 1524
194 jpye 2336 #ifdef PACKAGES_DEBUG
195 jpye 1628 CONSOLE_DEBUG("About to import external library...");
196     #endif
197 jpye 1519
198 jpye 1628 /* run the import handlers' importfn to do the actual loading, registration etc. */
199 johnpye 864 result = (*(handler->importfn))(fp1,initfunc,partialpath);
200     if(result){
201 jpye 2336 #ifdef PACKAGES_DEBUG
202 jpye 1628 CONSOLE_DEBUG("Error %d when importing external library of type '%s'",result,handler->name);
203     #endif
204 johnpye 864 ERROR_REPORTER_HERE(ASC_PROG_ERROR,"Error importing external library '%s'",partialpath);
205 johnpye 542 ospath_free(fp1);
206     return 1;
207     }
208 aw0a 1
209 johnpye 542 ospath_free(fp1);
210 johnpye 864 return 0;
211 aw0a 1 }
212    
213 johnpye 62 /*---------------------------------------------
214     STATIC_PACKAGES code only...
215 aw0a 1
216 johnpye 62 Declare the functions which we are expected to be able to call.
217     */
218    
219     /**
220     This is a general purpose function that will load whatever user
221     functions are required according to the compile-time settings.
222 johnpye 190
223 johnpye 62 If NO_PACKAGES, nothing will be loaded. If DYNAMIC_PACKAGES, then
224     just the builtin packages will be loaded. If STATIC_PACKAGES then
225     builtin plus those called in 'StaticPackages_Init' will be loaded.
226     */
227 johnpye 1162 void AddUserFunctions(void){
228    
229     /* Builtins are always statically linked */
230     if (Builtins_Init()) {
231     ERROR_REPORTER_NOLINE(ASC_PROG_WARNING
232     ,"Problem in Builtins_Init: Some user functions not created"
233     );
234     }
235 aw0a 1 }
236    

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