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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2336 - (show annotations) (download) (as text)
Sun Dec 26 03:44:24 2010 UTC (11 years, 6 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 /* ASCEND modelling environment
2 Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly, Kirk Abbott.
3 Copyright (C) 2006 Carnegie Mellon University
4
5 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 @file
21 Code to support dynamic and static loading of user packages.
22
23 '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
29 Next there are the 'static' packages. These ones are linked into
30 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 *//*
35 by Kirk Abbott
36 Created: July 4, 1994
37 Last in CVS: 1.14 ballan 1998/03/06 15:47:14
38 */
39
40 #include <math.h>
41 #include <ctype.h> /* was compiler/actype.h */
42
43 #include <ascend/general/platform.h>
44 #include <ascend/utilities/config.h> /* NEW */
45
46 #ifndef ASC_DEFAULT_ASCENDLIBRARY
47 # error "Where is ASC_DEFAULT_ASCENDLIBRARY???"
48 #endif
49
50 #include <ascend/general/ospath.h>
51
52
53 #include <ascend/general/ascMalloc.h>
54 #include <ascend/utilities/ascEnvVar.h>
55 #include <ascend/compiler/importhandler.h>
56 #include <ascend/general/panic.h>
57 #include <ascend/general/list.h>
58 #include "symtab.h"
59
60
61 #include "functype.h"
62 #include "expr_types.h"
63 #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 #include "rel_blackbox.h"
70 #include "vlist.h"
71 #include "relation.h"
72 #include "safe.h"
73 #include "relation_util.h"
74 #include "extfunc.h"
75 #include <ascend/packages/sensitivity.h>
76 #include <ascend/packages/ascFreeAllVars.h>
77 #include <ascend/packages/defaultall.h>
78 #include "module.h"
79 #include "packages.h"
80 #include "defaultpaths.h"
81
82 /* #define PACKAGES_DEBUG */
83
84 /*
85 Initialise the slv data structures used when calling external fns
86 */
87 void Init_BBoxInterp(struct BBoxInterp *interp)
88 {
89 if (interp){
90 interp->status = calc_all_ok;
91 interp->user_data = NULL;
92 interp->task = bb_none;
93 }
94 }
95
96 /*---------------------------------------------
97 BUILT-IN PACKAGES...
98 */
99
100 /**
101 Load builtin packages (those that are compiled into libascend)
102
103 @return 0 if success, 1 if failure.
104 */
105 static
106 int Builtins_Init(void){
107 int result = 0;
108
109 /* ERROR_REPORTER_DEBUG("Loading function asc_free_all_variables\n"); */
110 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 ,NULL /* destroy fn */
116 );
117
118 #ifdef PACKAGES_DEBUG
119 CONSOLE_DEBUG("Registering EXTERNAL defaultself_visit_childatoms");
120 #endif
121 result = CreateUserFunctionMethod("defaultself_visit_childatoms"
122 ,defaultself_visit_childatoms
123 ,1 /* num of args */
124 ,"Set local child atoms to their ATOMs' DEFAULT values; recurse into arrays." /* help */
125 ,NULL /* user_data */
126 ,NULL /* destroy fn */
127 );
128
129 #ifdef PACKAGES_DEBUG
130 CONSOLE_DEBUG("Registering EXTERNAL defaultself_visit_submodels");
131 #endif
132 result = CreateUserFunctionMethod("defaultself_visit_submodels"
133 ,defaultself_visit_submodels
134 ,1 /* num of args */
135 ,"Call 'default_self' methods on any nested sub-models." /* help */
136 ,NULL /* user_data */
137 ,NULL /* destroy fn */
138 );
139
140 return result;
141 }
142
143 /* return 0 on success */
144 int package_load(CONST char *partialpath, CONST char *initfunc){
145
146 struct FilePath *fp1;
147 int result;
148 struct ImportHandler *handler=NULL;
149 static const char *default_solvers_path = NULL;
150 static const char *default_library_path = NULL;
151 if(!default_solvers_path){
152 default_solvers_path = get_default_solvers_path();
153 /*CONSOLE_DEBUG("Default ASCENDSOLVERS set to '%s'", default_solvers_path);*/
154 }
155 if(!default_library_path){
156 default_library_path = get_default_library_path();
157 /*CONSOLE_DEBUG("Default ASCENDLIBRARY set to '%s'", default_library_path);*/
158 }
159
160 #ifdef PACKAGES_DEBUG
161 CONSOLE_DEBUG("Searching for external library '%s'",partialpath);
162 #endif
163
164 importhandler_createlibrary();
165
166 /* search in the ASCENDSOLVERS directory/ies first */
167 fp1 = importhandler_findinpath(
168 partialpath, default_solvers_path, ASC_ENV_SOLVERS,&handler
169 );
170
171 /* next, search in the ASCENDLIBRARY */
172 if(fp1==NULL){
173 fp1 = importhandler_findinpath(
174 partialpath, default_library_path, ASC_ENV_LIBRARY,&handler
175 );
176 if(fp1==NULL){
177 #ifdef PACKAGES_DEBUG
178 CONSOLE_DEBUG("External library '%s' not found",partialpath);
179 #endif
180 ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"External library '%s' not found.",partialpath);
181 return 1; /* failure */
182 }
183 #ifdef PACKAGES_DEBUG
184 else{
185 CONSOLE_DEBUG("FOUND in $ASCENDLIBRARY");
186 }
187 }else{
188 CONSOLE_DEBUG("Found in pwd or in $ASCENDSOLVERS");
189 #endif
190 }
191
192 asc_assert(handler!=NULL);
193
194 #ifdef PACKAGES_DEBUG
195 CONSOLE_DEBUG("About to import external library...");
196 #endif
197
198 /* run the import handlers' importfn to do the actual loading, registration etc. */
199 result = (*(handler->importfn))(fp1,initfunc,partialpath);
200 if(result){
201 #ifdef PACKAGES_DEBUG
202 CONSOLE_DEBUG("Error %d when importing external library of type '%s'",result,handler->name);
203 #endif
204 ERROR_REPORTER_HERE(ASC_PROG_ERROR,"Error importing external library '%s'",partialpath);
205 ospath_free(fp1);
206 return 1;
207 }
208
209 ospath_free(fp1);
210 return 0;
211 }
212
213 /*---------------------------------------------
214 STATIC_PACKAGES code only...
215
216 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
223 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 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 }
236

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