# HG changeset patch # User Mike Pavone # Date 1255056870 14400 # Node ID 4f1ae6eb71d8cb274f8ea7ef5f00dd8040d034fb # Parent 4c22fe79877992968e1612deb28a1b86d381c8af Use replicated switch statement for returns and late-bound calls diff -r 4c22fe798779 -r 4f1ae6eb71d8 runtime/fib.c --- a/runtime/fib.c Thu Oct 08 03:03:48 2009 -0400 +++ b/runtime/fib.c Thu Oct 08 22:54:30 2009 -0400 @@ -30,6 +30,31 @@ END } funcids; +#define DISPATCH switch(func) { \ + case FUNC__LT_: goto f__LT_;\ + case FUNC__LT__AT_Int32: goto f__LT__AT_Int32;\ + case FUNC__MN_: goto f__MN_;\ + case FUNC__MN__AT_Int32: goto f__MN__AT_Int32;\ + case FUNC__PL_: goto f__PL_;\ + case FUNC__PL__AT_Int32: goto f__PL__AT_Int32;\ + case FUNC_Fib: goto f_Fib;\ + case FUNC_Fib_1: goto r1_Fib;\ + case FUNC_Fib_2: goto r2_Fib;\ + case FUNC_Fib_3: goto r3_Fib;\ + case FUNC_Fib_4: goto r4_Fib;\ + case FUNC_Fib_5: goto r5_Fib;\ + case FUNC_Fib_6: goto r6_Fib;\ + case FUNC_Fib_7: goto r7_Fib;\ + case FUNC_If: goto f_If;\ + case FUNC_If_AT_Yes_SP_No: goto f_If_AT_Yes_SP_No;\ + case FUNC_Main: goto f_Main;\ + case FUNC_Main_1: goto r1_Main;\ + case FUNC_Main_2: goto r2_Main;\ + case FUNC_Print: goto f_Print;\ + case END: goto DO_END;\ +} + + typedef struct { struct object *____result__0__0; struct object *____result__0__1; @@ -63,9 +88,7 @@ cdata = alloc_cdata(ct, NULL, 0); cdata->num_params = 0; cdata->func = END; -_dispatch: -switch(func) -{ +DISPATCH Method(_LT_) MethodDispatch(TYPE_INT32,_LT_,Int32) EndMethod @@ -86,10 +109,12 @@ release_ref(cdata->params[-1]); EndFuncNoLocals +DISPATCH Method(_MN_) MethodDispatch(TYPE_INT32,_MN_,Int32) EndMethod +DISPATCH MethodImplNoLocals(_MN_,Int32,TYPE_INT32, NumParams 2) @@ -101,10 +126,12 @@ release_ref(cdata->params[-1]); EndFuncNoLocals +DISPATCH Method(_PL_) MethodDispatch(TYPE_INT32,_PL_,Int32) EndMethod +DISPATCH MethodImplNoLocals(_PL_,Int32,TYPE_INT32, NumParams 2) @@ -116,6 +143,7 @@ release_ref(cdata->params[-1]); EndFuncNoLocals +DISPATCH Func(Fib, NumParams 1) @@ -225,6 +253,7 @@ release_ref(cdata->params[0]); Ret(0, lv_Fib->out) EndFunc(Fib) +DISPATCH Method(If) MethodDispatch(TYPE_BOOLEAN,If,Yes_SP_No) @@ -241,6 +270,7 @@ Ret(0, NULL) } EndFuncNoLocals +DISPATCH Func(Main, NumParams 0) @@ -271,6 +301,7 @@ release_ref(lv_Main->____result__1__0); } EndFunc(Main) +DISPATCH FuncNoLocals(Print, NumParams 1) @@ -284,10 +315,11 @@ release_ref(cdata->params[0]); Ret(0, make_Int32(0)) EndFuncNoLocals +DISPATCH -case END: +DO_END: return; -} + _exception: puts("whoops, exception!"); } diff -r 4c22fe798779 -r 4f1ae6eb71d8 runtime/func.h --- a/runtime/func.h Thu Oct 08 03:03:48 2009 -0400 +++ b/runtime/func.h Thu Oct 08 22:54:30 2009 -0400 @@ -17,32 +17,29 @@ #define Func(name,numparams) \ - case FUNC_ ## name:\ +f_ ## name:\ for(idx = numparams; idx < cdata->num_params; ++idx)\ release_ref(cdata->params[0-idx]); cdata->num_params = numparams;\ -f_ ## name:\ +sf_ ## name:\ lv_ ## name = alloc_stack(ct, sizeof(lt_ ## name)); #define FuncNoLocals(name,numparams) \ - case FUNC_ ## name:\ +f_ ## name:\ for(idx = numparams; idx < cdata->num_params; ++idx)\ release_ref(cdata->params[0-idx]); cdata->num_params = numparams;\ -f_ ## name: +sf_ ## name: #define EndFunc(name) \ free_stack(ct, lv_ ## name);\ - func = cdata->func;\ - goto _dispatch;\ + func = cdata->func; #define EndFuncNoLocals \ - func = cdata->func;\ - resume = cdata->resume;\ - goto _dispatch;\ + func = cdata->func; #define Method(name) \ - case FUNC_ ## name:\ f_ ## name:\ +sf_ ## name:\ switch(get_blueprint(cdata->params[0])->type_id)\ { @@ -57,8 +54,8 @@ goto m_ ## name ## _AT_ ## type_name; #define MethodImpl(name,type_name,mytype_id,numparams) \ - case FUNC_ ## name ## _AT_ ## type_name:\ f_ ## name ## _AT_ ## type_name:\ +sf_ ## name ## _AT_ ## type_name:\ if (cdata->num_params < 1)\ goto _exception;\ if(get_blueprint(cdata->params[0])->type_id != mytype_id)\ @@ -73,8 +70,8 @@ #define MethodImplNoLocals(name,type_name,mytype_id,numparams) \ - case FUNC_ ## name ## _AT_ ## type_name:\ f_ ## name ## _AT_ ## type_name:\ +sf_ ## name ## _AT_ ## type_name:\ if (cdata->num_params < 1)\ goto _exception;\ if(get_blueprint(cdata->params[0])->type_id != mytype_id)\ @@ -110,8 +107,8 @@ #define Call(tocall, numparams, resumeto, myname)\ cdata->func = FUNC_ ## myname ## _ ## resumeto;\ cdata->num_params = numparams;\ - goto f_ ## tocall;\ - case FUNC_ ## myname ## _ ## resumeto:\ + goto sf_ ## tocall;\ +r ## resumeto ## _ ## myname:\ lv_ ## myname = (lt_ ## myname *)(cdata->lastframe+1); #define FreeCall\