Mercurial > repos > rhope
view runtime/func.h @ 24:8b2b3f4a2a58
Some fixes to parser_old.rhope
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 24 Jun 2009 23:56:49 -0400 |
parents | 31f8182f3433 |
children | 3498713c3dc9 |
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,callspace,localtype) \ returntype f_ ## name (calldata * cdata)\ {\ localtype *locals;\ calldata *call;\ returntype ret;\ int idx;\ if(cdata->resume)\ {\ call = cdata->call;\ locals = cdata->locals;\ }\ switch(cdata->resume)\ {\ case 0:\ for(idx = numparams; idx < cdata->num_params; ++idx)\ release_ref(cdata->params[idx]); cdata->num_params = numparams;\ cdata->num_params = numparams;\ cdata->call = call = alloc_cdata(cdata->ct, callspace);\ cdata->locals = locals = alloc_stack(cdata->ct, sizeof(localtype)); #define FuncNoLocals(name,numparams,callspace) \ returntype f_ ## name (calldata * cdata)\ {\ calldata *call;\ returntype ret;\ int idx;\ if(cdata->resume)\ call = cdata->locals;\ switch(cdata->resume)\ {\ case 0:\ for(idx = numparams; idx < cdata->num_params; ++idx)\ release_ref(cdata->params[idx]);\ cdata->num_params = numparams;\ cdata->locals = call = alloc_cdata(cdata->ct, callspace); #define EndFunc \ free_stack(cdata->ct, call);\ return NORMAL_RETURN;\ }\ } #define Method(name,type,numparams,callspace,localtype) \ returntype MethodName(name,type) (calldata * cdata)\ {\ localtype *locals;\ calldata *call;\ returntype ret;\ int idx;\ if(cdata->resume)\ {\ call = cdata->call;\ locals = cdata->locals;\ }\ switch(cdata->resume)\ {\ case 0:\ for(idx = numparams; idx < cdata->num_params; ++idx)\ release_ref(cdata->params[idx]); cdata->num_params = numparams;\ cdata->num_params = numparams;\ cdata->call = call = alloc_cdata(cdata->ct, callspace);\ cdata->locals = locals = alloc_stack(cdata->ct, sizeof(localtype)); #define MethodNoLocals(name,type,numparams,callspace) \ returntype MethodName(name,type) (calldata * cdata)\ {\ calldata *call;\ returntype ret;\ int idx;\ if(cdata->resume)\ call = cdata->locals;\ switch(cdata->resume)\ {\ case 0:\ for(idx = numparams; idx < cdata->num_params; ++idx)\ release_ref(cdata->params[idx]);\ cdata->num_params = numparams;\ cdata->locals = call = alloc_cdata(cdata->ct, callspace); #define NumParams #define CallSpace #define Param(num,convtypeid) \ call->params[0] = cdata->params[num];\ call->resume = 0;\ 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 && cdata->params[idx])\ release_ref(cdata->params[idx]);\ cdata->params[0] = call->params[0];\ free_stack(cdata->ct, call);\ return ret;\ }\ cdata->params[num] = call->params[0]; #define CopiedParam(num,convtypeid) Param(num,convtypeid) cdata->params[num] = copy_object(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); #define Call(func, numparams)\ call->num_params = numparams;\ call->resume = 0;\ ret = f_ ## func (call);\ while(ret == TAIL_RETURN)\ ret = call->tail_func(call);\ if(ret == EXCEPTION_RETURN)\ {\ for(idx = 0; idx < cdata->num_params; ++idx)\ if(cdata->params[idx])\ release_ref(cdata->params[idx]);\ cdata->params[0] = call->params[0];\ free_stack(cdata->ct, call);\ return ret;\ } #define MCall(methodid, numparams)\ call->num_params = numparams;\ call->resume = 0;\ ret = call_method(methodid, call);\ while(ret == TAIL_RETURN)\ ret = call->tail_func(call);\ if(ret == EXCEPTION_RETURN)\ {\ for(idx = 0; idx < cdata->num_params; ++idx)\ if(cdata->params[idx])\ release_ref(cdata->params[idx]);\ cdata->params[0] = call->params[0];\ free_stack(cdata->ct, call);\ return ret;\ } #define TMCall(methodid, numparams)\ free_stack(cdata->ct, call);\ cdata->num_params = numparams;\ cdata->resume = 0;\ ret = call_method(methodid, cdata);\ return ret; #define TCall(func, numparams)\ free_stack(cdata->ct, call);\ cdata->num_params = numparams;\ cdata->resume = 0;\ cdata->tail_func = f_ ## func;\ return TAIL_RETURN; #endif //_FUNC_H_