Mercurial > repos > rhope
comparison 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 |
comparison
equal
deleted
inserted
replaced
58:4c22fe798779 | 59:4f1ae6eb71d8 |
---|---|
28 FUNC_Main_2, | 28 FUNC_Main_2, |
29 FUNC_Print, | 29 FUNC_Print, |
30 END | 30 END |
31 } funcids; | 31 } funcids; |
32 | 32 |
33 #define DISPATCH switch(func) { \ | |
34 case FUNC__LT_: goto f__LT_;\ | |
35 case FUNC__LT__AT_Int32: goto f__LT__AT_Int32;\ | |
36 case FUNC__MN_: goto f__MN_;\ | |
37 case FUNC__MN__AT_Int32: goto f__MN__AT_Int32;\ | |
38 case FUNC__PL_: goto f__PL_;\ | |
39 case FUNC__PL__AT_Int32: goto f__PL__AT_Int32;\ | |
40 case FUNC_Fib: goto f_Fib;\ | |
41 case FUNC_Fib_1: goto r1_Fib;\ | |
42 case FUNC_Fib_2: goto r2_Fib;\ | |
43 case FUNC_Fib_3: goto r3_Fib;\ | |
44 case FUNC_Fib_4: goto r4_Fib;\ | |
45 case FUNC_Fib_5: goto r5_Fib;\ | |
46 case FUNC_Fib_6: goto r6_Fib;\ | |
47 case FUNC_Fib_7: goto r7_Fib;\ | |
48 case FUNC_If: goto f_If;\ | |
49 case FUNC_If_AT_Yes_SP_No: goto f_If_AT_Yes_SP_No;\ | |
50 case FUNC_Main: goto f_Main;\ | |
51 case FUNC_Main_1: goto r1_Main;\ | |
52 case FUNC_Main_2: goto r2_Main;\ | |
53 case FUNC_Print: goto f_Print;\ | |
54 case END: goto DO_END;\ | |
55 } | |
56 | |
57 | |
33 typedef struct { | 58 typedef struct { |
34 struct object *____result__0__0; | 59 struct object *____result__0__0; |
35 struct object *____result__0__1; | 60 struct object *____result__0__1; |
36 struct object *____result__10__0; | 61 struct object *____result__10__0; |
37 struct object *____result__11__0; | 62 struct object *____result__11__0; |
61 | 86 |
62 ct = new_context(); | 87 ct = new_context(); |
63 cdata = alloc_cdata(ct, NULL, 0); | 88 cdata = alloc_cdata(ct, NULL, 0); |
64 cdata->num_params = 0; | 89 cdata->num_params = 0; |
65 cdata->func = END; | 90 cdata->func = END; |
66 _dispatch: | 91 DISPATCH |
67 switch(func) | |
68 { | |
69 Method(_LT_) | 92 Method(_LT_) |
70 MethodDispatch(TYPE_INT32,_LT_,Int32) | 93 MethodDispatch(TYPE_INT32,_LT_,Int32) |
71 EndMethod | 94 EndMethod |
72 | 95 |
73 MethodImplNoLocals(_LT_,Int32,TYPE_INT32, | 96 MethodImplNoLocals(_LT_,Int32,TYPE_INT32, |
84 Ret(0, No) | 107 Ret(0, No) |
85 } | 108 } |
86 | 109 |
87 release_ref(cdata->params[-1]); | 110 release_ref(cdata->params[-1]); |
88 EndFuncNoLocals | 111 EndFuncNoLocals |
112 DISPATCH | |
89 | 113 |
90 Method(_MN_) | 114 Method(_MN_) |
91 MethodDispatch(TYPE_INT32,_MN_,Int32) | 115 MethodDispatch(TYPE_INT32,_MN_,Int32) |
92 EndMethod | 116 EndMethod |
117 DISPATCH | |
93 | 118 |
94 MethodImplNoLocals(_MN_,Int32,TYPE_INT32, | 119 MethodImplNoLocals(_MN_,Int32,TYPE_INT32, |
95 NumParams 2) | 120 NumParams 2) |
96 | 121 |
97 Param(1, TYPE_INT32) | 122 Param(1, TYPE_INT32) |
99 cdata->params[0] = copy_object(cdata->params[0]); | 124 cdata->params[0] = copy_object(cdata->params[0]); |
100 ((t_Int32 *)cdata->params[0])->num -= ((t_Int32 *)cdata->params[-1])->num; | 125 ((t_Int32 *)cdata->params[0])->num -= ((t_Int32 *)cdata->params[-1])->num; |
101 | 126 |
102 release_ref(cdata->params[-1]); | 127 release_ref(cdata->params[-1]); |
103 EndFuncNoLocals | 128 EndFuncNoLocals |
129 DISPATCH | |
104 | 130 |
105 Method(_PL_) | 131 Method(_PL_) |
106 MethodDispatch(TYPE_INT32,_PL_,Int32) | 132 MethodDispatch(TYPE_INT32,_PL_,Int32) |
107 EndMethod | 133 EndMethod |
134 DISPATCH | |
108 | 135 |
109 MethodImplNoLocals(_PL_,Int32,TYPE_INT32, | 136 MethodImplNoLocals(_PL_,Int32,TYPE_INT32, |
110 NumParams 2) | 137 NumParams 2) |
111 | 138 |
112 Param(1, TYPE_INT32) | 139 Param(1, TYPE_INT32) |
114 cdata->params[0] = copy_object(cdata->params[0]); | 141 cdata->params[0] = copy_object(cdata->params[0]); |
115 ((t_Int32 *)cdata->params[0])->num += ((t_Int32 *)cdata->params[-1])->num; | 142 ((t_Int32 *)cdata->params[0])->num += ((t_Int32 *)cdata->params[-1])->num; |
116 | 143 |
117 release_ref(cdata->params[-1]); | 144 release_ref(cdata->params[-1]); |
118 EndFuncNoLocals | 145 EndFuncNoLocals |
146 DISPATCH | |
119 | 147 |
120 Func(Fib, | 148 Func(Fib, |
121 NumParams 1) | 149 NumParams 1) |
122 lv_Fib->____result__0__0 = NULL; | 150 lv_Fib->____result__0__0 = NULL; |
123 lv_Fib->____result__0__1 = NULL; | 151 lv_Fib->____result__0__1 = NULL; |
223 release_ref(lv_Fib->____result__11__0); | 251 release_ref(lv_Fib->____result__11__0); |
224 } | 252 } |
225 release_ref(cdata->params[0]); | 253 release_ref(cdata->params[0]); |
226 Ret(0, lv_Fib->out) | 254 Ret(0, lv_Fib->out) |
227 EndFunc(Fib) | 255 EndFunc(Fib) |
256 DISPATCH | |
228 | 257 |
229 Method(If) | 258 Method(If) |
230 MethodDispatch(TYPE_BOOLEAN,If,Yes_SP_No) | 259 MethodDispatch(TYPE_BOOLEAN,If,Yes_SP_No) |
231 EndMethod | 260 EndMethod |
232 | 261 |
239 } else { | 268 } else { |
240 Ret(1, cdata->params[0]); | 269 Ret(1, cdata->params[0]); |
241 Ret(0, NULL) | 270 Ret(0, NULL) |
242 } | 271 } |
243 EndFuncNoLocals | 272 EndFuncNoLocals |
273 DISPATCH | |
244 | 274 |
245 Func(Main, | 275 Func(Main, |
246 NumParams 0) | 276 NumParams 0) |
247 | 277 |
248 lv_Main->____result__0__0 = NULL; | 278 lv_Main->____result__0__0 = NULL; |
269 if(lv_Main->____result__1__0) | 299 if(lv_Main->____result__1__0) |
270 { | 300 { |
271 release_ref(lv_Main->____result__1__0); | 301 release_ref(lv_Main->____result__1__0); |
272 } | 302 } |
273 EndFunc(Main) | 303 EndFunc(Main) |
304 DISPATCH | |
274 | 305 |
275 FuncNoLocals(Print, | 306 FuncNoLocals(Print, |
276 NumParams 1) | 307 NumParams 1) |
277 | 308 |
278 if(get_blueprint(cdata->params[0])->type_id == TYPE_INT32) | 309 if(get_blueprint(cdata->params[0])->type_id == TYPE_INT32) |
282 puts("Don't know how to print this type"); | 313 puts("Don't know how to print this type"); |
283 } | 314 } |
284 release_ref(cdata->params[0]); | 315 release_ref(cdata->params[0]); |
285 Ret(0, make_Int32(0)) | 316 Ret(0, make_Int32(0)) |
286 EndFuncNoLocals | 317 EndFuncNoLocals |
287 | 318 DISPATCH |
288 case END: | 319 |
320 DO_END: | |
289 return; | 321 return; |
290 } | 322 |
291 _exception: | 323 _exception: |
292 puts("whoops, exception!"); | 324 puts("whoops, exception!"); |
293 } | 325 } |
294 | 326 |
295 int main(int argc, char ** argv) | 327 int main(int argc, char ** argv) |