view 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 source

#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; 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; 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
#define FuncDef(name) returntype _f_ ## name (calldata * cdata);
#define MethodDef(name,type) returntype MethodName(name,type) (calldata * cdata);


#endif //_FUNC_H_