• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

/Users/magix/mmx/mmxlight/include/mmxlight/environment.hpp

Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : environment.hpp
00004 * DESCRIPTION: Environments for the base evaluator
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 #ifndef __ENVIRONMENT_HPP
00014 #define __ENVIRONMENT_HPP
00015 #include <basix/string.hpp>
00016 #include <basix/list.hpp>
00017 #include <basix/table.hpp>
00018 #include <basix/lisp_syntax.hpp>
00019 #include <basix/routine.hpp>
00020 
00022 
00023 namespace mmx {
00024 
00025 class environment_rep;
00026 class environment {
00027 INDIRECT_PROTO (environment, environment_rep)
00028   inline environment ();
00029   inline bool operator == (const environment& env) const;
00030   inline bool operator != (const environment& env) const;
00031   inline generic operator [] (const generic& x) const;
00032   inline generic& operator [] (const generic& x);
00033   friend inline list<string> strings_for_completion (const environment& env);
00034   friend inline void verify_if_unknown_types (const environment& env);
00035   friend inline void reset (const environment& env, const generic& x);
00036   friend inline bool is_nil (const environment& env);
00037   friend inline nat hash (const environment& env);
00038 };
00039 
00040 class environment_rep: public rep_struct {
00041 public:
00042   table<generic,generic,exact_eq_table> bindings;
00043   environment next;
00044   nat serial;       // time stamp for validity of converter cache
00045   nat next_serial;  // required time stamp for parent
00046   nat env_type;     // tag for special environments (modules and classes)
00047 public:
00048   inline environment_rep ();
00049   inline environment_rep (const environment& e);
00050   inline ~environment_rep ();
00051 
00052   // environment access
00053   generic name () const;
00054   inline generic& set (const generic& var);
00055   inline void set (const generic& var, const generic& val);
00056   inline void reset (const generic& var);
00057   bool contains (const generic& var) const;
00058   generic get (const generic& var) const;
00059   bool get (const generic& var, generic& val) const;
00060   list<string> strings_for_completion () const;
00061   void verify_if_unknown_types () const;
00062 
00063   // converters
00064   void ensure_up_to_date () const;
00065   void set_converter (nat src, nat dest, const generic& val, nat trv, nat pen);
00066   generic get_converter (nat src, nat dest, nat& pen) const;
00067 
00068   friend class environment;
00069 };
00070 INDIRECT_NULL_IMPL (environment, environment_rep)
00071 
00072 inline environment_rep::environment_rep ():
00073   serial (0), next_serial (0), env_type (0) {}
00074 inline environment_rep::environment_rep (const environment& e):
00075   next (e), serial (0), next_serial (next->serial), env_type (0) {}
00076 inline environment_rep::~environment_rep () {}
00077 inline generic& environment_rep::set (const generic& var) {
00078   return bindings [var]; }
00079 inline void environment_rep::set (const generic& var, const generic& val) {
00080   bindings [var]= val; }
00081 inline void environment_rep::reset (const generic& var) {
00082   mmx::reset (bindings, var); }
00083 
00084 inline environment::environment (): rep (NULL) {}
00085 inline bool environment::operator == (const environment& env) const {
00086   return rep == env.rep; }
00087 inline bool environment::operator != (const environment& env) const {
00088   return rep != env.rep; }
00089 inline generic environment::operator [] (const generic& x) const {
00090   return rep->get (x); }
00091 inline generic& environment::operator [] (const generic& x) {
00092   return rep->set (x); }
00093 inline generic read (const environment& env, const generic& x) {
00094   return env[x]; }
00095 inline void reset (const environment& env, const generic& x) {
00096   return env.rep->reset (x); }
00097 
00099 inline list<string> strings_for_completion (const environment& env) {
00100   return env.rep->strings_for_completion (); }
00101   
00103 inline void verify_if_unknown_types (const environment& env) {
00104   return env.rep->verify_if_unknown_types (); }
00105   
00106 inline bool is_nil (const environment& env) {
00107   return env.rep == NULL; }
00108 inline nat hash (const environment& env) {
00109   return as_hash (env.rep); }
00110 inline syntactic flatten (const environment& env) {
00111   if (is_nil (env)) return as_syntactic (GEN_NIL);
00112   else return as_syntactic (env->name ()); }
00113 
00114 inline environment global_environment () {
00115   return new environment_rep (); }
00116 inline environment local_environment (const environment& next) {
00117   return new environment_rep (next); }
00118 
00119 routine overloaded_routine (const generic& name, const environment& env);
00120 generic equalize (const generic& fun, const vector<generic>& args);
00121 
00122 } // namespace mmx
00123 #endif // __ENVIRONMENT_HPP

Generated on Mon May 2 2011 17:04:34 for mmxlight:doc by  doxygen 1.7.2