Mercurial > repos > rhope
diff 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 |
line wrap: on
line diff
--- a/runtime/func.h Wed May 13 00:47:40 2009 -0400 +++ b/runtime/func.h Wed May 13 23:37:19 2009 -0400 @@ -1,12 +1,41 @@ #ifndef _FUNC_H_ #define _FUNC_H_ +typedef enum { + NORMAL_RETURN=0, + EXCEPTION_RETURN, + TAIL_RETURN, + NO_CONVERSION, + STACK_UNWIND +} returntype; + + +typedef returntype (*rhope_func)(struct calldata *); +typedef void (*special_func) (struct object *); + #define MethodName(name,type) _f_ ## name ## _AT_ ## type -#define Func(name,numparams,locals) returntype _f_ ## name (calldata * cdata) { locals; +#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; +#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; #define EndFunc return NORMAL_RETURN; } -#define Method(name,type,numparams,locals) returntype MethodName(name,type) (calldata * cdata) { locals; -#define Param(num,var,type) var = (_t_##type *)( +#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; +#define ParamBase(num,var,type,convtypeid) \ +call->params[0] = cdata->params[num];\ +ret = coerce_value(convtypeid, call);\ +while(ret == TAIL_RETURN)\ + ret = call->tail_func(call);\ +if(ret == EXCEPTION_RETURN)\ +{\ + for(idx = 0; idx < cdata->num_params; ++idx)\ + if(idx != num)\ + release_ref(cdata->params[idx]);\ + cdata->params[0] = call->params[0];\ + return ret;\ +}\ +cdata->params[num] = call->params[0]; + +#define Param(num,var,type,convtypeid) ParamBase(num,var,type,convtypeid) var = (_t_##type *)(cdata->params[num]); +#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]); #define Ret(num,val) cdata->params[num] = (object *)(val); #define Return return NORMAL_RETURN; #define Exception