Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

lsymbol.hpp

Go to the documentation of this file.
00001 // +-------------------------------------------------------------------------+
00002 // |               I__n__t__e__L__i__b           0.6.10 development          |
00003 // | Copyright (c) Andrey Vikt. Stolyarov <crocodil_AT_croco.net> 2000-2007. |
00004 // |                                                                         |
00005 // | This is free software. The library part is available under              |
00006 // |                               GNU LESSER GENERAL PUBLIC LICENSE v.2.1.  |
00007 // | GNU LGPL v2.1 is found in docs/gnu_gpl2.txt,  or at  http://www.gnu.org |
00008 // |     Please see also docs/readme.txt and visit http://www.intelib.org    |
00009 // |                                                                         |
00010 // | !!! THERE IS NO WARRANTY OF ANY KIND, NEITHER EXPRESSED NOR IMPLIED !!! |
00011 // +-------------------------------------------------------------------------+
00012 
00013 
00014 
00015 
00025 #ifndef INTELIB_LSYMBOL_HPP_SENTRY
00026 #define INTELIB_LSYMBOL_HPP_SENTRY
00027 
00028 
00029 #include "lisp.hpp"
00030 //#include "lcont.hpp"
00031 #include "../sexpress/gensref.hpp"
00032 
00033 
00034 #ifndef INTELIB_LISP_LIBRARY_DEFINES_SYMBOLS
00035 #define INTELIB_LISP_LIBRARY_DEFINES_SYMBOLS 1
00036 #endif
00037 
00039 
00040 class LExpressionSymbol : public SExpressionLabel {
00041     LReference dynamic_value;
00042     LReference associated_function;
00043     bool is_dynamic : 2;
00044     bool is_constant : 2;
00045 protected:
00046     LExpressionSymbol(const char *a_name, const IntelibTypeId &t) 
00047         : SExpressionLabel(t, a_name), 
00048           dynamic_value(), is_dynamic(false), is_constant(false) {}
00049     ~LExpressionSymbol() {}
00050 public:
00052     static IntelibTypeId TypeId;
00054     LExpressionSymbol(const char *a_name) 
00055         : SExpressionLabel(TypeId, a_name), 
00056           dynamic_value(), is_dynamic(false), is_constant(false) {}
00057 
00059     const LReference& GetDynamicValue() const { return dynamic_value; } 
00061     LReference& GetDynamicValueRef() { return dynamic_value; } 
00063     void SetDynamicValue(const SReference &val);
00065     const LReference& GetFunction() const { return associated_function; } 
00067     LReference& GetFunctionRef() { return associated_function; } 
00069     void SetFunction(const LReference &val) { associated_function = val; }
00070  
00072     bool IsDynamic() const { return is_dynamic; }
00074     bool IsConstant() const { return is_constant; }
00076     void SetDynamicBinding(bool dyn = true) { is_dynamic = dyn; }
00078     void SetConstant(bool cnst = true) { is_constant = cnst; }
00079 };
00080 
00082 class IntelibX_lisp_not_a_symbol : public IntelibX {
00083 public:
00084     IntelibX_lisp_not_a_symbol(SReference a_param);
00085 };
00086 
00088 typedef GenericSReference<LExpressionSymbol,IntelibX_lisp_not_a_symbol>
00089 LSymbolRef;
00090 
00092 
00095 class LSymbol : public LSymbolRef {
00096 public:
00097     LSymbol(const char *s) : LSymbolRef(new LExpressionSymbol(s)) {}
00098     LSymbol(LExpressionSymbol *ts) : LSymbolRef(ts) {}
00099     ~LSymbol();
00100 
00101 private:
00102     // made private to prevent the user from mistakes and
00103     //   to make sure this always points to LExpressionSymbol object.
00104     void operator =(const LReference& ref) {}
00105     LSymbol(const LSymbol&) {}
00106 };
00107 
00108 
00110 
00116 template <class F>           // F must be a descender of LExpressionForm
00117 class LFunctionalSymbol : public LSymbol {
00118 public:
00119     LFunctionalSymbol(const char *name = 0) : LSymbol(name) 
00120       { (*this)->SetFunction(LReference(::new F())); }
00121     ~LFunctionalSymbol() {}
00122 private:
00123     LFunctionalSymbol(const LFunctionalSymbol<F>& t) : LSymbol(0) {}
00124           /* LSymbol(0) is just to make stupid compiler happy */
00125 };
00126 
00127 
00128 
00129 
00130 
00132 class LSymbolQuote : public LSymbol {
00133 public:
00134     LSymbolQuote();
00135 };
00136 
00138 class LSymbolFunction : public LSymbol {
00139 public:
00140     LSymbolFunction();
00141 };
00142 
00144 class LSymbolLambda : public LSymbol {
00145 public:
00146     LSymbolLambda();
00147 };
00148 
00150 class LSymbolT : public LSymbol {
00151 public:
00152     LSymbolT();
00153 };
00154 
00156 class LSymbolNIL : public LSymbol {
00157 public:
00158     LSymbolNIL();
00159 };
00160 
00162 extern struct LLibraryProvidedSymbols {
00163     LSymbolQuote Quote;
00164     LSymbolFunction Function;
00165     LSymbolLambda Lambda;
00166     LSymbolT SymT;
00167     LSymbolNIL SymNil;
00168 } TheLibraryProvidedSymbols;
00169 
00170 #if INTELIB_LISP_LIBRARY_DEFINES_SYMBOLS == 1
00171 #define QUOTE (TheLibraryProvidedSymbols.Quote)
00172 #define FUNCTION (TheLibraryProvidedSymbols.Function)
00173 #define LAMBDA (TheLibraryProvidedSymbols.Lambda)
00174 #define T (TheLibraryProvidedSymbols.SymT)
00175 #define NIL (TheLibraryProvidedSymbols.SymNil)
00176 #endif
00177 
00179 class IntelibX_symbol_has_no_value : public IntelibX {
00180 public:
00181     IntelibX_symbol_has_no_value(SReference a_param);
00182 };
00183 
00185 class IntelibX_cant_change_constant : public IntelibX {
00186 public:
00187     IntelibX_cant_change_constant(SReference a_param);
00188 };
00189 
00190 
00191 #endif // sentry

Generated on Tue Dec 18 00:39:44 2007 for InteLib by  doxygen 1.4.1