-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcpps_regfunction.h
More file actions
362 lines (291 loc) · 11.6 KB
/
cpps_regfunction.h
File metadata and controls
362 lines (291 loc) · 11.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
#ifndef CPPS_REG_FUNCTION_CPPS_HEAD_
#define CPPS_REG_FUNCTION_CPPS_HEAD_
//===================================
//@Author : Johnson
//@QQ : 88481106
//@Email : 88481106@qq.com
//@Date : 2015/11/20 (yy/mm/dd)
//@Module : CPPS_CALL_FUNCTION
//@Description : ×¢²áº¯Êý
//@website : http://cppscript.org
//==================================
namespace cpps
{
template<typename p1>
class dofunc;
template< typename p1 >
dofunc< p1 > make_function(p1 param1);
template<class retType, typename context, typename F, typename IsVoid>
retType call_function(cpps_value &ret, cpps_domain *domain, node*o, context &c, F &f, IsVoid&);
template<class T>
class cpps_is_void;
template <class C>
struct cpps_class;
template <class C>
struct cpps_classvar;
struct cpps_cppsclass;
struct cpps_cpps_value;
struct Buffer;
class cpps_class_handler;
struct cpps_function
{
cpps_function();
virtual ~cpps_function();
virtual void callfunction(C* c, cpps_value* ret, cpps_domain* domain, cpps_std_vector* o, cpps_stack* stack = NULL, std::vector< cpps_regvar*>* lambdastacklist = NULL);
virtual void setfuncname(std::string name);
virtual std::string getfuncname();
virtual void release();
virtual void setIsNeedC(bool b);
virtual bool getIsNeedC();
virtual int8 getparamcount();
virtual bool isasync();
virtual bool isoperator();
virtual void setasync(bool b);
virtual void setoperator(bool b);
virtual bool iscppsfunc();
virtual cpps_cppsclass* getclass();
virtual void setclass(cpps_cppsclass* cls);
bool isNeedC;
std::string funcname;
bool nasync;
bool noperator;
cpps_cppsclass* _cls;
};
struct cpps_reg
{
cpps_reg();
virtual ~cpps_reg();
virtual void release();
cpps_reg* next;
int8 type;
std::string varname;
cpps_value value;
bool isneedC;
};
struct cpps_regfunction : public cpps_reg
{
cpps_regfunction(std::string f, cpps_function* func, bool isasync = false, bool isoperator = false);
virtual ~cpps_regfunction();
virtual void release();
cpps_function* func;
};
struct cpps_reggvar : public cpps_reg
{
cpps_reggvar(std::string n, cpps_value v);
virtual ~cpps_reggvar();
virtual void release();
};
struct cpps_reg_class_var : public cpps_reg
{
cpps_reg_class_var(std::string n, cpps_classvar_quato* v);
virtual ~cpps_reg_class_var();
virtual void release();
cpps_classvar_quato* _v;
};
struct cpps_regparentclass : public cpps_reg
{
cpps_regparentclass(cpps_cppsclass* _cppsclass);
virtual ~cpps_regparentclass();
virtual void release();
cpps_cppsclass* __cppsclass;
};
struct cpps_regclass : public cpps_reg
{
cpps_regclass(std::string name, cpps_cppsclass* c);
virtual ~cpps_regclass();
virtual void release();
cpps_cppsclass* cls;
};
template<class C>
struct cpps_regclass_template : public cpps_regclass
{
cpps_regclass_template(std::string name, cpps_class<C>* c);
virtual ~cpps_regclass_template();
virtual void release();
};
struct cpps_regenum : public cpps_reg
{
cpps_regenum(std::string name, cpps_domain* c);
virtual ~cpps_regenum();
virtual void release();
cpps_domain* _enum_domain;
};
template<class R>
struct cpps_function1 : public cpps_function
{
cpps_function1( R(*f)())
:f(f)
{
param = make_vector(f);
}
virtual ~cpps_function1() {}
void callfunction(C *c, cpps_value *ret, cpps_domain *domain, cpps_std_vector *o, cpps_stack *stack = NULL, std::vector< cpps_regvar*>* lambdastacklist = NULL)
{
dofunc< vector1<R> > func = make_function(param);
call_function<R>(c,*ret,domain, *o, func, f, cpps_is_void<R>());
}
virtual void release() { CPPSDELETE( this); }
R(*f)();
vector1<R> param;
};
template<class R>
cpps_regfunction* make_regfunction(std::string func, R(*f)(), bool isasync = false, bool isoperator = false)
{
return CPPSNEW(cpps_regfunction)(func, CPPSNEW(cpps_function1<R>)(f), isasync, isoperator);
}
template<class R, class CLS>
struct cpps_cpp_function1 : public cpps_function
{
cpps_cpp_function1(R(CLS::*f)())
:f(f)
{
param = make_vector(f);
}
virtual ~cpps_cpp_function1() {}
void callfunction(C *c, cpps_value *ret, cpps_domain *domain, cpps_std_vector *o, cpps_stack *stack = NULL, std::vector< cpps_regvar*>* lambdastacklist = NULL)
{
dofunc< vector1<R> > func = make_function(param);
call_function< R>(c,*ret,domain, *o, func, f, cpps_is_void<R>());
}
virtual void release() { CPPSDELETE( this ); }
R(CLS::* f)();
vector1<R> param;
};
template<class R, class C>
cpps_regfunction* make_regfunction(std::string func, R(C::*f)(), bool isasync = false, bool isoperator = false)
{
typedef cpps_cpp_function1<R, C> _Type;
return CPPSNEW( cpps_regfunction)(func, CPPSNEW(_Type)(f), isasync,isoperator);
}
template<class R, class C>
cpps_regfunction* make_regfunction(std::string func, R(C::*f)()const, bool isasync = false, bool isoperator = false)
{
typedef cpps_cpp_function1<R, C> _Type;
return CPPSNEW( cpps_regfunction)(func, CPPSNEW(_Type)((R(C::*)())f), isasync,isoperator);
}
template<class F>
cpps_reggvar* make_regvar(std::string name, F v)
{
return CPPSNEW( cpps_reggvar)(name, v);
}
cpps_regparentclass* make_parentclass(cpps_cppsclass* _cppsclass);
template<class C>
inline cpps_regclass_template<C>::cpps_regclass_template(std::string name, cpps_class<C>* c)
:cpps_regclass(name, c)
{
}
template<class C>
inline cpps_regclass_template<C>::~cpps_regclass_template() {}
template<class C>
inline void cpps_regclass_template<C>::release() { CPPSDELETE(this); }
}
#define CPPS_MAKE_REGFUNCTION_ITER_C 1
#include "cpps_regfunction.h"
#undef CPPS_MAKE_REGFUNCTION_ITER_C
#define CPPS_MAKE_REGFUNCTION_ITER_C 2
#include "cpps_regfunction.h"
#undef CPPS_MAKE_REGFUNCTION_ITER_C
#define CPPS_MAKE_REGFUNCTION_ITER_C 3
#include "cpps_regfunction.h"
#undef CPPS_MAKE_REGFUNCTION_ITER_C
#define CPPS_MAKE_REGFUNCTION_ITER_C 4
#include "cpps_regfunction.h"
#undef CPPS_MAKE_REGFUNCTION_ITER_C
#define CPPS_MAKE_REGFUNCTION_ITER_C 5
#include "cpps_regfunction.h"
#undef CPPS_MAKE_REGFUNCTION_ITER_C
#define CPPS_MAKE_REGFUNCTION_ITER_C 6
#include "cpps_regfunction.h"
#undef CPPS_MAKE_REGFUNCTION_ITER_C
#define CPPS_MAKE_REGFUNCTION_ITER_C 7
#include "cpps_regfunction.h"
#undef CPPS_MAKE_REGFUNCTION_ITER_C
#define CPPS_MAKE_REGFUNCTION_ITER_C 8
#include "cpps_regfunction.h"
#undef CPPS_MAKE_REGFUNCTION_ITER_C
#define CPPS_MAKE_REGFUNCTION_ITER_C 9
#include "cpps_regfunction.h"
#undef CPPS_MAKE_REGFUNCTION_ITER_C
#define CPPS_MAKE_REGFUNCTION_ITER_C 10
#include "cpps_regfunction.h"
#undef CPPS_MAKE_REGFUNCTION_ITER_C
#define CPPS_MAKE_REGFUNCTION_ITER_C 11
#include "cpps_regfunction.h"
#undef CPPS_MAKE_REGFUNCTION_ITER_C
#define CPPS_MAKE_REGFUNCTION_ITER_C 12
#include "cpps_regfunction.h"
#undef CPPS_MAKE_REGFUNCTION_ITER_C
#define CPPS_MAKE_REGFUNCTION_ITER_C 13
#include "cpps_regfunction.h"
#undef CPPS_MAKE_REGFUNCTION_ITER_C
#define CPPS_MAKE_REGFUNCTION_ITER_C 14
#include "cpps_regfunction.h"
#undef CPPS_MAKE_REGFUNCTION_ITER_C
#define CPPS_MAKE_REGFUNCTION_ITER_C 15
#include "cpps_regfunction.h"
#undef CPPS_MAKE_REGFUNCTION_ITER_C
#define CPPS_MAKE_REGFUNCTION_ITER_C 16
#include "cpps_regfunction.h"
#undef CPPS_MAKE_REGFUNCTION_ITER_C
#endif //CPPS_REG_FUNCTION_CPPS_HEAD_
#ifdef CPPS_MAKE_REGFUNCTION_ITER_C
namespace cpps
{
template<class R, CPPS_PP_ENUM_PARAMS(CPPS_MAKE_REGFUNCTION_ITER_C, class A) >
CPPS_PP_CAT(struct cpps_function, CPPS_PP_CAT(VECTOR_I_, CPPS_MAKE_REGFUNCTION_ITER_C)) : public cpps_function
{
CPPS_PP_CAT(cpps_function, CPPS_PP_CAT(VECTOR_I_, CPPS_MAKE_REGFUNCTION_ITER_C))( R(*f)(CPPS_PP_ENUM_PARAMS(CPPS_MAKE_REGFUNCTION_ITER_C, A)))
: f(f)
{
param = make_vector(f);
}
virtual ~CPPS_PP_CAT(cpps_function, CPPS_PP_CAT(VECTOR_I_, CPPS_MAKE_REGFUNCTION_ITER_C))(){}
void callfunction(C *c, cpps_value *ret, cpps_domain *domain, cpps_std_vector *o, cpps_stack *stack = NULL, std::vector< cpps_regvar*>* lambdastacklist = NULL)
{
dofunc<CPPS_PP_CAT(cpps::vector, CPPS_PP_CAT(VECTOR_I_, CPPS_MAKE_REGFUNCTION_ITER_C)) < R, CPPS_PP_ENUM_PARAMS(CPPS_MAKE_REGFUNCTION_ITER_C, A) > > func = make_function(param);
call_function<R>(c,*ret,domain, *o, func, f, cpps_is_void<R>());
}
virtual void release() { CPPSDELETE( this); }
virtual int8 getparamcount() { return CPPS_MAKE_REGFUNCTION_ITER_C; }
R(*f)(CPPS_PP_ENUM_PARAMS(CPPS_MAKE_REGFUNCTION_ITER_C, A));
CPPS_PP_CAT(cpps::vector, CPPS_PP_CAT(VECTOR_I_, CPPS_MAKE_REGFUNCTION_ITER_C)) < R, CPPS_PP_ENUM_PARAMS(CPPS_MAKE_REGFUNCTION_ITER_C, A) > param;
};
template<class R, CPPS_PP_ENUM_PARAMS(CPPS_MAKE_REGFUNCTION_ITER_C, class A) >
cpps_regfunction* make_regfunction(std::string func, R(*f)(CPPS_PP_ENUM_PARAMS(CPPS_MAKE_REGFUNCTION_ITER_C, A)), bool isasync = false, bool isoperator = false)
{
typedef CPPS_PP_CAT(cpps_function, CPPS_PP_CAT(VECTOR_I_, CPPS_MAKE_REGFUNCTION_ITER_C)) < R, CPPS_PP_ENUM_PARAMS(CPPS_MAKE_REGFUNCTION_ITER_C, A) > _Type;
return CPPSNEW( cpps_regfunction)(func, CPPSNEW(_Type)(f), isasync,isoperator);
}
template<class R, class CLS, CPPS_PP_ENUM_PARAMS(CPPS_MAKE_REGFUNCTION_ITER_C, class A) >
CPPS_PP_CAT(struct cpps_cpp_function, CPPS_PP_CAT(VECTOR_I_, CPPS_MAKE_REGFUNCTION_ITER_C)) : public cpps_function
{
CPPS_PP_CAT(cpps_cpp_function, CPPS_PP_CAT(VECTOR_I_, CPPS_MAKE_REGFUNCTION_ITER_C))(R(CLS::*f)(CPPS_PP_ENUM_PARAMS(CPPS_MAKE_REGFUNCTION_ITER_C, A)))
: f(f)
{
param = make_vector(f);
}
virtual ~CPPS_PP_CAT(cpps_cpp_function, CPPS_PP_CAT(VECTOR_I_, CPPS_MAKE_REGFUNCTION_ITER_C))(){}
void callfunction(C *c, cpps_value *ret, cpps_domain *domain, cpps_std_vector *o, cpps_stack *stack = NULL, std::vector< cpps_regvar*>* lambdastacklist = NULL)
{
dofunc<CPPS_PP_CAT(cpps::vector, CPPS_PP_CAT(VECTOR_I_, CPPS_MAKE_REGFUNCTION_ITER_C)) < R, CPPS_PP_ENUM_PARAMS(CPPS_MAKE_REGFUNCTION_ITER_C, A) > > func = make_function(param);
call_function<R>(c,*ret, domain, *o, func, f, cpps_is_void<R>());
}
virtual void release() { CPPSDELETE( this); }
virtual int8 getparamcount() { return CPPS_MAKE_REGFUNCTION_ITER_C; }
R(CLS::*f)(CPPS_PP_ENUM_PARAMS(CPPS_MAKE_REGFUNCTION_ITER_C, A));
CPPS_PP_CAT(cpps::vector, CPPS_PP_CAT(VECTOR_I_, CPPS_MAKE_REGFUNCTION_ITER_C)) < R, CPPS_PP_ENUM_PARAMS(CPPS_MAKE_REGFUNCTION_ITER_C, A) > param;
};
template<class R, class C, CPPS_PP_ENUM_PARAMS(CPPS_MAKE_REGFUNCTION_ITER_C, class A) >
cpps_regfunction* make_regfunction(std::string func, R(C::*f)(CPPS_PP_ENUM_PARAMS(CPPS_MAKE_REGFUNCTION_ITER_C, A)), bool isasync = false, bool isoperator = false)
{
typedef CPPS_PP_CAT(cpps_cpp_function, CPPS_PP_CAT(VECTOR_I_, CPPS_MAKE_REGFUNCTION_ITER_C)) < R, C, CPPS_PP_ENUM_PARAMS(CPPS_MAKE_REGFUNCTION_ITER_C, A) > _Type;
return CPPSNEW( cpps_regfunction)(func, CPPSNEW(_Type)(f),isasync,isoperator);
}
template<class R, class C, CPPS_PP_ENUM_PARAMS(CPPS_MAKE_REGFUNCTION_ITER_C, class A) >
cpps_regfunction* make_regfunction(std::string func, R(C::* f)(CPPS_PP_ENUM_PARAMS(CPPS_MAKE_REGFUNCTION_ITER_C, A)) const, bool isasync = false, bool isoperator = false)
{
typedef CPPS_PP_CAT(cpps_cpp_function, CPPS_PP_CAT(VECTOR_I_, CPPS_MAKE_REGFUNCTION_ITER_C)) < R, C, CPPS_PP_ENUM_PARAMS(CPPS_MAKE_REGFUNCTION_ITER_C, A) > _Type;
return CPPSNEW(cpps_regfunction)(func, CPPSNEW(_Type)((R(C::*)(CPPS_PP_ENUM_PARAMS(CPPS_MAKE_REGFUNCTION_ITER_C, A)))f), isasync, isoperator);
}
}
#endif