Mercurial > repos > rhope
comparison runtime/func.h @ 186:ba35ab624ec2
Add support for raw C function output from C backend as well as an option to use Boehm-GC instead of reference counting
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 07 Oct 2011 00:10:02 -0700 |
parents | d2b941f82d74 |
children |
comparison
equal
deleted
inserted
replaced
185:4580c08fd4e8 | 186:ba35ab624ec2 |
---|---|
1 #ifndef _FUNC_H_ | 1 #ifndef _FUNC_H_ |
2 #define _FUNC_H_ | 2 #define _FUNC_H_ |
3 | 3 |
4 #define MethodName(name,type) f_ ## name ## AT_ ## type | |
5 #define NumParams | |
6 #define NumOutputs | |
7 #define CallSpace | |
8 | |
4 typedef struct object object; | 9 typedef struct object object; |
5 typedef struct calldata calldata; | 10 typedef void (*special_func) (object *); |
11 | |
12 | |
13 #ifdef RAW_FUNC | |
14 #include "func_raw.h" | |
15 #else | |
6 | 16 |
7 typedef enum { | 17 typedef enum { |
8 NORMAL_RETURN=0, | 18 NORMAL_RETURN=0, |
9 EXCEPTION_RETURN, | 19 EXCEPTION_RETURN, |
10 TAIL_RETURN, | 20 TAIL_RETURN, |
11 NO_CONVERSION, | 21 NO_CONVERSION, |
12 STACK_UNWIND | 22 STACK_UNWIND |
13 } returntype; | 23 } returntype; |
14 | 24 |
25 typedef struct calldata calldata; | |
15 | 26 |
16 typedef returntype (*rhope_func)(calldata *); | 27 typedef returntype (*rhope_func)(calldata *); |
17 typedef void (*special_func) (object *); | 28 |
29 #define lv(func,var) lv_ ## func->var | |
30 #define lvar(type, name) type name; | |
31 #define my_params(num) my_cdata->params[num] | |
32 #define child_params(num) cdata->params[num] | |
33 #define my_outputs(num) my_cdata->params[num] | |
34 | |
35 #define result(num) cdata->params[num] | |
36 #define numresults cdata->num_params | |
37 | |
38 #define LocalsType(def,func) typedef struct { def } lt_ ## func; | |
39 | |
40 #define ResEnum(num,name) RES_ ## num ## _ ## name, | |
18 | 41 |
19 #ifdef MULTI_SWITCH | 42 #ifdef MULTI_SWITCH |
20 #define DispatchEntry(name) case FUNC_##name: goto f_##name; | 43 #define DispatchEntry(name) case FUNC_##name: goto f_##name; |
21 #define ResumeEntry(num,name) case RES_##num##_##name: goto r##num##_##name; | 44 #define ResumeEntry(num,name) case RES_##num##_##name: goto r##num##_##name; |
22 #define DispatchVar | 45 #define DispatchVar |
30 #define DISPATCH goto *funcs[func]; | 53 #define DISPATCH goto *funcs[func]; |
31 #define EndEntry &&DO_END, | 54 #define EndEntry &&DO_END, |
32 #define EndThreadEntry &&DO_END_THREAD | 55 #define EndThreadEntry &&DO_END_THREAD |
33 #endif | 56 #endif |
34 | 57 |
35 | |
36 #define MethodName(name,type) f_ ## name ## AT_ ## type | |
37 | |
38 #ifdef ENABLE_PROFILING | 58 #ifdef ENABLE_PROFILING |
39 | 59 |
40 #define START_PROFILE \ | 60 #define START_PROFILE \ |
41 gettimeofday(&proftime, NULL);\ | 61 gettimeofday(&proftime, NULL);\ |
42 cdata->accum = cdata->self_accum = 0;\ | 62 cdata->accum = cdata->self_accum = 0;\ |
70 profile_counts[FUNC_ ## name]++;\ | 90 profile_counts[FUNC_ ## name]++;\ |
71 profile_totals[FUNC_ ## name] += ((uint64_t)proftime.tv_sec) * 1000000ULL + ((uint64_t)proftime.tv_usec) - cdata->start + cdata->accum;\ | 91 profile_totals[FUNC_ ## name] += ((uint64_t)proftime.tv_sec) * 1000000ULL + ((uint64_t)proftime.tv_usec) - cdata->start + cdata->accum;\ |
72 }\ | 92 }\ |
73 profile_selftotals[FUNC_ ## name] += ((uint64_t)proftime.tv_sec) * 1000000ULL + ((uint64_t)proftime.tv_usec) - cdata->self_start + cdata->self_accum; | 93 profile_selftotals[FUNC_ ## name] += ((uint64_t)proftime.tv_sec) * 1000000ULL + ((uint64_t)proftime.tv_usec) - cdata->self_start + cdata->self_accum; |
74 | 94 |
75 #define Func(name,numparams) \ | 95 #define Func(name,numparams,numret) \ |
76 f_ ## name:\ | 96 f_ ## name:\ |
77 for(idx = numparams; idx < cdata->num_params; ++idx)\ | 97 for(idx = numparams; idx < cdata->num_params; ++idx)\ |
78 release_ref(cdata->params[idx]); cdata->num_params = numparams;\ | 98 release_ref(cdata->params[idx]); cdata->num_params = numparams;\ |
79 sf_ ## name:\ | 99 sf_ ## name:\ |
80 profile_activationlevel[FUNC_ ## name]++;\ | 100 profile_activationlevel[FUNC_ ## name]++;\ |
81 cdata->myactivationlevel = &profile_activationlevel[FUNC_ ## name];\ | 101 cdata->myactivationlevel = &profile_activationlevel[FUNC_ ## name];\ |
82 START_PROFILE\ | 102 START_PROFILE\ |
83 lv_ ## name = alloc_stack(ct, sizeof(lt_ ## name));\ | 103 lv_ ## name = alloc_stack(ct, sizeof(lt_ ## name));\ |
84 my_cdata = cdata; | 104 my_cdata = cdata; |
85 | 105 |
86 #define MethodImpl(name,type_name,mytype_id,numparams) \ | 106 #define MethodImpl(name,type_name,mytype_id,numparams,numret) \ |
87 f_ ## name ## AT_ ## type_name:\ | 107 f_ ## name ## AT_ ## type_name:\ |
88 sf_ ## name ## AT_ ## type_name:\ | 108 sf_ ## name ## AT_ ## type_name:\ |
89 if (cdata->num_params < 1)\ | 109 if (cdata->num_params < 1)\ |
90 {\ | 110 {\ |
91 cdata = alloc_cdata(ct, cdata, 0);\ | 111 cdata = alloc_cdata(ct, cdata, 0);\ |
116 | 136 |
117 #define EndFunc(name) \ | 137 #define EndFunc(name) \ |
118 free_stack(ct, lv_ ## name);\ | 138 free_stack(ct, lv_ ## name);\ |
119 func = cdata->func; | 139 func = cdata->func; |
120 | 140 |
121 #define Func(name,numparams) \ | 141 #define Func(name,numparams,numret) \ |
122 f_ ## name:\ | 142 f_ ## name:\ |
123 for(idx = numparams; idx < cdata->num_params; ++idx)\ | 143 for(idx = numparams; idx < cdata->num_params; ++idx)\ |
124 release_ref(cdata->params[idx]); cdata->num_params = numparams;\ | 144 release_ref(cdata->params[idx]); cdata->num_params = numparams;\ |
125 sf_ ## name:\ | 145 sf_ ## name:\ |
126 lv_ ## name = alloc_stack(ct, sizeof(lt_ ## name));\ | 146 lv_ ## name = alloc_stack(ct, sizeof(lt_ ## name));\ |
127 my_cdata = cdata; | 147 my_cdata = cdata; |
128 | 148 |
129 #define MethodImpl(name,type_name,mytype_id,numparams) \ | 149 #define MethodImpl(name,type_name,mytype_id,numparams,numret) \ |
130 f_ ## name ## AT_ ## type_name:\ | 150 f_ ## name ## AT_ ## type_name:\ |
131 sf_ ## name ## AT_ ## type_name:\ | 151 sf_ ## name ## AT_ ## type_name:\ |
132 if (cdata->num_params < 1)\ | 152 if (cdata->num_params < 1)\ |
133 {\ | 153 {\ |
134 cdata = alloc_cdata(ct, cdata, 0);\ | 154 cdata = alloc_cdata(ct, cdata, 0);\ |
150 | 170 |
151 #define EndFuncNoLocals \ | 171 #define EndFuncNoLocals \ |
152 func = cdata->func; | 172 func = cdata->func; |
153 | 173 |
154 | 174 |
155 #define FuncNoLocals(name,numparams) \ | 175 #define FuncNoLocals(name,numparams,numret) \ |
156 f_ ## name:\ | 176 f_ ## name:\ |
157 for(idx = numparams; idx < cdata->num_params; ++idx)\ | 177 for(idx = numparams; idx < cdata->num_params; ++idx)\ |
158 release_ref(cdata->params[idx]); cdata->num_params = numparams;\ | 178 release_ref(cdata->params[idx]); cdata->num_params = numparams;\ |
159 sf_ ## name:\ | 179 sf_ ## name:\ |
160 my_cdata = cdata; | 180 my_cdata = cdata; |
197 | 217 |
198 #define MethodDispatch(type_id,name,type_name) \ | 218 #define MethodDispatch(type_id,name,type_name) \ |
199 case type_id:\ | 219 case type_id:\ |
200 goto m_ ## name ## AT_ ## type_name; | 220 goto m_ ## name ## AT_ ## type_name; |
201 | 221 |
202 #define NumParams | |
203 #define CallSpace | |
204 | |
205 #define Param(num,convtypeid) \ | 222 #define Param(num,convtypeid) \ |
206 if(get_blueprint(cdata->params[num])->type_id != convtypeid)\ | 223 if(get_blueprint(cdata->params[num])->type_id != convtypeid)\ |
207 {\ | 224 {\ |
208 printf("uh oh, need conversion from type %d to type %d for param %d and that's not implemented yet!", get_blueprint(cdata->params[num])->type_id, convtypeid, num);\ | 225 printf("uh oh, need conversion from type %d to type %d for param %d and that's not implemented yet!", get_blueprint(cdata->params[num])->type_id, convtypeid, num);\ |
209 goto _exception;\ | 226 goto _exception;\ |
217 puts("Worker with only one output failed to produce data for that output!");\ | 234 puts("Worker with only one output failed to produce data for that output!");\ |
218 goto _exception;\ | 235 goto _exception;\ |
219 } | 236 } |
220 #define Exception | 237 #define Exception |
221 #define FuncDef(name) lt_ ## name * lv_ ## name; | 238 #define FuncDef(name) lt_ ## name * lv_ ## name; |
222 #define MethodDef(name) lt_ ## name ## AT_ ## type_name * lv_ ## name ## AT_ ## type_name; | 239 #define MethodDef(name) lt_ ## name * lv_ ## name; |
223 | 240 |
224 | 241 |
225 #define PrepCall(callspace) cdata = alloc_cdata(ct, cdata, callspace); | 242 #define PrepCall(callspace) cdata = alloc_cdata(ct, cdata, callspace); |
226 | 243 |
227 #define SetParam(num,value) cdata->params[num] = value; | 244 #define SetParam(num,value) cdata->params[num] = value; |
350 | 367 |
351 #define TCall(tocall, numparams)\ | 368 #define TCall(tocall, numparams)\ |
352 cdata->num_params = numparams;\ | 369 cdata->num_params = numparams;\ |
353 goto sf_ ## tocall; | 370 goto sf_ ## tocall; |
354 | 371 |
355 | 372 #endif //RAW_FUNC |
356 #endif //_FUNC_H_ | 373 #endif //_FUNC_H_ |
374 |