00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __CHARM_RTH_H
00012 #define __CHARM_RTH_H
00013
00014 #include "pup.h"
00015 #include <new>
00016
00022 class RTH_Locals {
00023 public:
00024 virtual ~RTH_Locals();
00025 virtual void pup(PUP::er &p);
00026 };
00027
00028
00032 class RTH_Runtime;
00033
00037 typedef void (*RTH_Routine)(RTH_Runtime *runtime,
00038 void *object,RTH_Locals *locals,int pc);
00039
00040
00041
00042
00043
00044
00045
00049 RTH_Runtime *RTH_Runtime_create(RTH_Routine fn,int localsSize,void *obj);
00050
00056 RTH_Runtime *RTH_Runtime_pup(RTH_Runtime *runtime,PUP::er &p,void *obj);
00057
00065 void RTH_Runtime_suspend(RTH_Runtime *runtime,int nextPC);
00066
00070 void RTH_Runtime_resume(RTH_Runtime *runtime);
00071
00074 int RTH_Runtime_call(RTH_Runtime *runtime,RTH_Routine fn,int localsSize,int nextPC);
00075
00079 void RTH_Runtime_done(RTH_Runtime *runtime);
00080
00082 void RTH_Runtime_destroy(RTH_Runtime *runtime);
00083
00084
00085
00086
00087
00088
00089
00090
00105 #define RTH_Routine_locals(object,name) \
00106 class RTH_Routine_##object##_##name : public RTH_Locals { \
00107 typedef RTH_Locals super; \
00108 typedef RTH_Routine_##object##_##name locals_t; \
00109 public:
00110
00117 #define RTH_Routine_code(object,name) \
00118 inline void name(RTH_Runtime *RTH_impl_runtime,\
00119 object *c,int RTH_impl_pc) { \
00120 switch(RTH_impl_pc) { \
00121 case 0: \
00122 new ((void *)this) locals_t;
00123
00128 #define RTH_Routine_end(object,name) \
00129 \
00130 RTH_Runtime_done(RTH_impl_runtime); \
00131 return; \
00132 default: \
00133 printf("Bad pc %d\n",RTH_impl_pc); exit(1); \
00134 }; \
00135 } \
00136 \
00137 \
00138 static void RTH_Call_routine(RTH_Runtime *runtime,\
00139 void *c,RTH_Locals *locals,int pc) \
00140 {\
00141 ((locals_t *)locals)->name(runtime,(object *)c,pc);\
00142 }\
00143 \
00144 };
00145
00153 #define RTH_Suspend() do {\
00154 RTH_Runtime_suspend(RTH_impl_runtime,__LINE__);\
00155 return;\
00156 case __LINE__: ; \
00157 } while(0)
00158
00165 #define RTH_Call(object,name) do{ \
00166 if (!RTH_Runtime_call(RTH_impl_runtime,RTH_Routine_lookup(object,name),__LINE__)) \
00167 return;\
00168 case __LINE__: ; \
00169 } while(0)
00170
00174 #define RTH_Routine_lookup(object,name) \
00175 RTH_Routine_##object##_##name::RTH_Call_routine, sizeof(RTH_Routine_##object##_##name)
00176
00177 #endif
00178