comparison runtime/func.h @ 8:8d74ef7fa357

Improved helper macros and added separate Rhope stack in runtime
author Mike Pavone <pavone@retrodev.com>
date Wed, 13 May 2009 23:37:19 -0400
parents d61550e2c001
children 52d9948def24
comparison
equal deleted inserted replaced
7:d61550e2c001 8:8d74ef7fa357
1 #ifndef _FUNC_H_ 1 #ifndef _FUNC_H_
2 #define _FUNC_H_ 2 #define _FUNC_H_
3 3
4 typedef enum {
5 NORMAL_RETURN=0,
6 EXCEPTION_RETURN,
7 TAIL_RETURN,
8 NO_CONVERSION,
9 STACK_UNWIND
10 } returntype;
11
12
13 typedef returntype (*rhope_func)(struct calldata *);
14 typedef void (*special_func) (struct object *);
15
4 #define MethodName(name,type) _f_ ## name ## _AT_ ## type 16 #define MethodName(name,type) _f_ ## name ## _AT_ ## type
5 17
6 #define Func(name,numparams,locals) returntype _f_ ## name (calldata * cdata) { locals; 18 #define Func(name,numparams,locals) returntype _f_ ## name (calldata * cdata) { locals; calldata *call; returntype ret; int idx; for(idx = numparams; idx < cdata->num_params; ++idx) release_ref(cdata->params[idx]); cdata->num_params = numparams;
19 #define FuncNoLocals(name,numparams) returntype _f_ ## name (calldata * cdata) {calldata *call; returntype ret; int idx; for(idx = numparams; idx < cdata->num_params; ++idx) release_ref(cdata->params[idx]); cdata->num_params = numparams;
7 #define EndFunc return NORMAL_RETURN; } 20 #define EndFunc return NORMAL_RETURN; }
8 #define Method(name,type,numparams,locals) returntype MethodName(name,type) (calldata * cdata) { locals; 21 #define Method(name,type,numparams,locals) returntype MethodName(name,type) (calldata * cdata) { locals; calldata *call; returntype ret; int idx; for(idx = numparams; idx < cdata->num_params; ++idx) release_ref(cdata->params[idx]); cdata->num_params = numparams;
9 #define Param(num,var,type) var = (_t_##type *)( 22 #define ParamBase(num,var,type,convtypeid) \
23 call->params[0] = cdata->params[num];\
24 ret = coerce_value(convtypeid, call);\
25 while(ret == TAIL_RETURN)\
26 ret = call->tail_func(call);\
27 if(ret == EXCEPTION_RETURN)\
28 {\
29 for(idx = 0; idx < cdata->num_params; ++idx)\
30 if(idx != num)\
31 release_ref(cdata->params[idx]);\
32 cdata->params[0] = call->params[0];\
33 return ret;\
34 }\
35 cdata->params[num] = call->params[0];
36
37 #define Param(num,var,type,convtypeid) ParamBase(num,var,type,convtypeid) var = (_t_##type *)(cdata->params[num]);
38 #define CopiedParam(num,var,type,convtypeid) ParamBase(num,var,type,convtypeid) cdata->params[num] = copy_object(cdata->params[num]); var = (_t_##type *)(cdata->params[num]);
10 #define Ret(num,val) cdata->params[num] = (object *)(val); 39 #define Ret(num,val) cdata->params[num] = (object *)(val);
11 #define Return return NORMAL_RETURN; 40 #define Return return NORMAL_RETURN;
12 #define Exception 41 #define Exception
13 #define FuncDef(name) returntype _f_ ## name (calldata * cdata); 42 #define FuncDef(name) returntype _f_ ## name (calldata * cdata);
14 #define MethodDef(name,type) returntype MethodName(name,type) (calldata * cdata); 43 #define MethodDef(name,type) returntype MethodName(name,type) (calldata * cdata);