Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4680 | right-hear | 1 | |
2 | |||
3 | |||
4 | #include "yacasbase.h" |
||
5 | |||
6 | #include "lispenvironment.h" |
||
7 | #include "lisphash.h" |
||
8 | #include "grower.h" |
||
9 | #include "evalfunc.h" |
||
10 | |||
11 | /// Abstract class providing the basic user function API. |
||
12 | |||
13 | /// via an associated hash table. When obtained, they can be used to |
||
14 | /// evaluate the function with some arguments. |
||
15 | |||
16 | class LispUserFunction : public EvalFuncBase |
||
17 | |||
18 | public: |
||
19 | LispUserFunction() : iFenced(LispTrue),iTraced(LispFalse) {}; |
||
20 | virtual ~LispUserFunction(); |
||
21 | virtual void Evaluate(LispPtr& aResult,LispEnvironment& aEnvironment, |
||
22 | LispPtr& aArguments)=0; |
||
23 | virtual void HoldArgument(LispString * aVariable) = 0; |
||
24 | virtual void DeclareRule(LispInt aPrecedence, LispPtr& aPredicate, |
||
25 | LispPtr& aBody) = 0; |
||
26 | virtual void DeclareRule(LispInt aPrecedence, LispPtr& aBody) = 0; |
||
27 | virtual void DeclarePattern(LispInt aPrecedence, LispPtr& aPredicate, |
||
28 | LispPtr& aBody) = 0; |
||
29 | virtual LispPtr& ArgList() = 0; |
||
30 | |||
31 | public: //unfencing |
||
32 | |||
33 | inline LispBoolean Fenced() {return iFenced;}; |
||
34 | public: //tracing |
||
35 | inline void Trace() {iTraced = LispTrue;}; |
||
36 | inline void UnTrace() {iTraced = LispFalse;}; |
||
37 | inline LispBoolean Traced() {return iTraced;}; |
||
38 | private: |
||
39 | LispBoolean iFenced; |
||
40 | LispBoolean iTraced; |
||
41 | }; |
||
42 | |||
43 | |||
44 | |||
45 | |||
46 | /// arguments) of the function is now fixed. |
||
47 | |||
48 | class LispArityUserFunction : public LispUserFunction |
||
49 | |||
50 | public: |
||
51 | virtual LispInt Arity() const = 0; |
||
52 | virtual LispInt IsArity(LispInt aArity) const = 0; |
||
53 | }; |
||
54 | |||
55 | |||
56 | |||
57 | |||
58 | |||
59 | |||
60 | |||
61 | /// different arities) to one name. A specific LispArityUserFunction |
||
62 | /// can be selected by providing its name. Additionally, the name of |
||
63 | /// the file in which the function is defined, can be specified. |
||
64 | |||
65 | class LispMultiUserFunction : public YacasBase |
||
66 | |||
67 | public: |
||
68 | /// Constructor. |
||
69 | LispMultiUserFunction() : iFunctions(),iFileToOpen(NULL) {}; |
||
70 | |||
71 | /** When adding a multi-user function to the association hash table, the copy constructor is used. |
||
72 | |||
73 | * Casually having a copy-constructor on CDeletingArrayGrower should be avoided, to make sure it is |
||
74 | * not used accidentally. |
||
75 | */ |
||
76 | inline LispMultiUserFunction(const LispMultiUserFunction& aOther) : iFunctions(), iFileToOpen(NULL) |
||
77 | { |
||
78 | LISPASSERT(aOther.iFileToOpen == 0); |
||
79 | LISPASSERT(aOther.iFunctions.Size() == 0); |
||
80 | } |
||
81 | inline LispMultiUserFunction& operator=(const LispMultiUserFunction& aOther) |
||
82 | { |
||
83 | // copy constructor not written yet, hence the assert |
||
84 | LISPASSERT(aOther.iFileToOpen == 0); |
||
85 | LISPASSERT(aOther.iFunctions.Size() == 0); |
||
86 | |||
87 | LISPASSERT(iFileToOpen == 0); |
||
88 | |||
89 | return *this; |
||
90 | } |
||
91 | |||
92 | /// Return user function with given arity. |
||
93 | |||
94 | |||
95 | /// Destructor. |
||
96 | |||
97 | |||
98 | /// Specify that some argument should be held. |
||
99 | |||
100 | |||
101 | /// Add another LispArityUserFunction to #iFunctions. |
||
102 | |||
103 | |||
104 | /// Delete tuser function with given arity. |
||
105 | |||
106 | |||
107 | private: |
||
108 | |||
109 | CDeletingArrayGrower |
||
110 | |||
111 | public: |
||
112 | |||
113 | LispDefFile* iFileToOpen; |
||
114 | }; |
||
115 | |||
116 | |||
117 | |||
118 | |||
119 | class LispUserFunctions : public LispAssociatedHash |
||
120 | |||
121 | }; |
||
122 | |||
123 | |||
124 | |||
125 |