diff runtime/fib.c @ 59:4f1ae6eb71d8

Use replicated switch statement for returns and late-bound calls
author Mike Pavone <pavone@retrodev.com>
date Thu, 08 Oct 2009 22:54:30 -0400
parents 4c22fe798779
children fa24ef3b026f
line wrap: on
line diff
--- 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!");
 }