basix_doc 0.1
/Users/mourrain/Devel/mmx/basix/src/evaluator.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : evaluator.cpp
00004 * DESCRIPTION: Abstract evaluators for symbolic expressions
00005 * COPYRIGHT  : (C) 2006  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license and comes WITHOUT
00008 * ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
00009 * If you don't have this file, write to the Free Software Foundation, Inc.,
00010 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00011 ******************************************************************************/
00012 
00013 #include <basix/evaluator.hpp>
00014 #include <basix/glue.hpp>
00015 namespace mmx {
00016 
00017 /******************************************************************************
00018 * Default evaluation methods do not do much...
00019 ******************************************************************************/
00020 
00021 void* evaluator_rep::get_internal_data () const {
00022   return NULL; }
00023 void evaluator_rep::set (const generic& var, const generic& val) const {
00024   (void) var; (void) val; }
00025 void evaluator_rep::reset (const generic& var) const {
00026   (void) var; }
00027 void evaluator_rep::overload
00028   (const generic& var, const generic& val, nat pen) const {
00029     (void) var; (void) val; (void) pen; }
00030 bool evaluator_rep::contains (const generic& var) const {
00031   (void) var; return false; }
00032 generic evaluator_rep::get (const generic& var) const {
00033   return var; }
00034 bool evaluator_rep::get (const generic& var, generic& val) const {
00035   (void) var; (void) val; return false; }
00036 
00037 generic evaluator_rep::eval (const generic& x) const {
00038   return x; }
00039 generic evaluator_rep::construct (const generic& x) const {
00040   return x; }
00041 generic evaluator_rep::apply (const generic& fun) const {
00042   return gen (fun); }
00043 generic evaluator_rep::apply (const generic& fun, const generic& x1) const {
00044   return gen (fun, x1); }
00045 generic evaluator_rep::apply (const generic& fun,
00046                               const generic& x1, const generic& x2) const {
00047   return gen (fun, x1, x2); }
00048 generic evaluator_rep::apply (const generic& fun,
00049                               const vector<generic>& v) const {
00050   return gen (fun, v); }
00051 
00052 /******************************************************************************
00053 * Current evaluator management
00054 ******************************************************************************/
00055 
00056 bool ev_lock= false;
00057 evaluator current_ev;
00058 list<evaluator> stack_ev;
00059 
00060 void
00061 select_evaluator (const evaluator& ev) {
00062   //assert (!ev_lock);
00063   //ev_lock= true;
00064   //{
00065   /*
00066     if (N(stack_ev) < 6)
00067     mmout << "[" << N (stack_ev)
00068     << ":" << inside (current_ev)
00069     << "+" << inside (ev)
00070     << "]" << flush_now;
00071   */
00072   stack_ev  = cons (current_ev, stack_ev);
00073   current_ev= ev;
00074   //}
00075   //ev_lock= false;
00076 }
00077 
00078 void
00079 restore_evaluator () {
00080   //assert (!ev_lock);
00081   //ev_lock= true;
00082   //{
00083   ASSERT (!is_nil (stack_ev), "empty evaluator stack");
00084   /*
00085     if (N(stack_ev) < 6)
00086     mmout << "[" << N (stack_ev)-1
00087     << ":" << inside (current_ev)
00088     << "-" << inside (car (stack_ev))
00089     << "]" << flush_now;
00090   */
00091   evaluator aux_ev= current_ev; // only destroy current_ev on exit
00092   current_ev= read_car (stack_ev);
00093   stack_ev  = read_cdr (stack_ev);
00094   //}
00095   //ev_lock= false;
00096 }
00097 
00098 } // namespace mmx
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines