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

lsymbol.cpp

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 
00016 #include "../sexpress/iexcept.hpp"
00017 #include "../sexpress/sstring.hpp"
00018 #include "llambda.hpp"
00019 //#include "lcont.hpp"
00020 
00021 #include "lsymbol.hpp"
00022 
00023 #if INTELIB_DEBUG_PRINT >= 1
00024 #include <stdio.h>
00025 #endif
00026 
00027 IntelibTypeId
00028 LExpressionSymbol::TypeId(&SExpressionLabel::TypeId, false);
00029 
00030 /* NOTE NOTE NOTE Symbol is declared unchangeable
00031    although actually it is 
00032  */
00033 /* rationale is that it should not be copied when casting from constant
00034    to non-constant S-expressions 
00035  */
00036 
00037 
00038 void LExpressionSymbol::SetDynamicValue(const SReference &val)
00039 {
00040     if(is_constant) {
00041         throw IntelibX_cant_change_constant(SReference(this));
00042     }
00043     dynamic_value = val;
00044 }
00045 
00046 LSymbol::~LSymbol()
00047 {
00048 #if INTELIB_CLEAR_SYMBOLS == 1
00049     LReference none; // empty reference
00050     GetPtr()->SetDynamicValue(none);
00051     GetPtr()->SetFunction(none);
00052 #endif
00053 }
00054 
00055 class LFunctionQuote : public SExpressionForm {
00056 public:
00057     LFunctionQuote() : SExpressionForm() {}
00058     ~LFunctionQuote() {}
00059     virtual SString TextRepresentation() const
00060         { return "#<FORM QUOTE>"; }
00061     virtual void Call(const SReference &params, IntelibContinuation &lf) const
00062     {
00063         lf.RegularReturn(
00064             (static_cast<SExpressionCons*>(params.GetPtr()))->Car()
00065         );
00066     }
00067 };
00068 
00069 // now this is implemented within lcont.cpp
00070 LReference RetrieveFunctionObject(LReference from, const LContextRef &lc);
00071 
00072 class LFunctionFunction : public SExpressionForm {
00073 public:
00074     LFunctionFunction() : SExpressionForm() {}
00075     ~LFunctionFunction() {}
00076     virtual SString TextRepresentation() const
00077         { return "#<FORM FUNCTION>"; }
00078     virtual void Call(const SReference &params, IntelibContinuation &lf) const
00079     {
00080         INTELIB_ASSERT(params.Cdr().IsEmptyList(),
00081                        IntelibX_too_many_params(params));
00082         LReference ret =
00083             RetrieveFunctionObject(params.Car(), lf.GetContext());
00084         INTELIB_ASSERT(ret.GetPtr(),
00085                        IntelibX_no_associated_function(params.Car()));
00086         lf.RegularReturn(ret);
00087     }
00088 };
00089 
00090 LSymbolQuote::LSymbolQuote()
00091         : LSymbol("QUOTE")
00092 {
00093     (*this)->SetFunction(LReference(new LFunctionQuote));
00094     PTheLispSymbolQuote = this;
00095 }
00096 
00097 LSymbolFunction::LSymbolFunction()
00098         : LSymbol("FUNCTION")
00099 {
00100     (*this)->SetFunction(LReference(new LFunctionFunction));
00101     PTheLispSymbolFunction = this;
00102 }
00103 
00104 LSymbolLambda::LSymbolLambda()
00105         : LSymbol("LAMBDA")
00106 {
00107     PTheLispSymbolLambda = this;
00108 }
00109 
00110 LSymbolNIL::LSymbolNIL()
00111         : LSymbol("NIL")
00112 {
00113     GetPtr()->SetDynamicValue(*this);
00114     GetPtr()->SetConstant();
00115     PTheLispBooleanFalse = this;
00116     PTheEmptyList = this;
00117 }
00118 
00119 LSymbolT::LSymbolT()
00120         : LSymbol("T")
00121 {
00122     GetPtr()->SetDynamicValue(*this);
00123     GetPtr()->SetConstant();
00124     PTheLispBooleanTrue = this;
00125 }
00126 
00127 LLibraryProvidedSymbols TheLibraryProvidedSymbols;
00128 
00129 IntelibX_lisp_not_a_symbol::
00130 IntelibX_lisp_not_a_symbol(SReference a_param)
00131         : IntelibX("Lisp: Not a symbol", a_param) {}
00132 
00133 IntelibX_symbol_has_no_value::
00134 IntelibX_symbol_has_no_value(SReference a_param)
00135         : IntelibX("Symbol has no value", a_param) {}
00136 
00137 IntelibX_cant_change_constant::
00138 IntelibX_cant_change_constant(SReference a_param)
00139         : IntelibX("Can not change a constant", a_param) {}
00140 

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