Code Gear と Data Gear を持つ Gears OS の設計 |
Mitsuki Miyagi, Shinji Kono
琉球大学
|
__code cg0(int a, int b){
goto cg1(a+b);
}
__code cg1(int c){
goto cg2(c);
}
__code code1 (struct Array* array) {
...
goto code2(array);
}
__code meta(struct Context* context, enum Code next) {
goto (context->code[next])(context);
}
__code code2(struct Array* array) {
...
}
/* context define */
struct Context {
int codeNum; //実行可能な Code Gear の数
__code (**code) (struct Context*); //実行可能な code Gear のリスト
void* heapStart; //Data Gear の Allocate用のヒープ
void* heap;
long heapLimit;
int dataNum; //Data Gear の数
union Data **data; //Data Gear のリスト
};
enum Code {
C_cg1,
C_cg2,
};
enum Data {
D_dg1,
D_dg2,
};
union Data {
struct Time {
enum Code next;
double time;
} time;
struct LoopCounter {
int i;
} loopCounter;
...
};
typedef struct Stack<Type, Impl>{
union Data* stack;
union Data* data;
union Data* data1;
__code whenEmpty(...);
__code clear(Impl* stack,__code next(...));
__code push(Impl* stack,Type* data, __code next(...));
__code pop(Impl* stack, __code next(Type* data, ...));
__code pop2(Impl* stack, __code next(Type* data, Type* data1, ...));
__code isEmpty(Impl* stack, __code next(...), __code whenEmpty(...));
__code get(Impl* stack, __code next(Type* data, ...));
__code get2(Impl* stack, __code next(Type* data, Type* data1, ...));
__code next(...);
} Stack;
Stack* createSingleLinkedStack(struct Context* context) {
struct Stack* stack = new Stack();
struct SingleLinkedStack* singleLinkedStack = new SingleLinkedStack();
stack->stack = (union Data*)singleLinkedStack;
singleLinkedStack->top = NULL;
stack->push = C_pushSingleLinkedStack;
stack->pop = C_popSingleLinkedStack;
stack->pop2 = C_pop2SingleLinkedStack;
stack->get = C_getSingleLinkedStack;
stack->get2 = C_get2SingleLinkedStack;
stack->isEmpty = C_isEmptySingleLinkedStack;
stack->clear = C_clearSingleLinkedStack;
return stack;
}
__code pushSingleLinkedStack(struct SingleLinkedStack* stack,
union Data* data, __code next(...)) {
Element* element = new Element();
element->next = stack->top;
element->data = data;
stack->top = element;
goto next(...);
}
__code stackTest1(struct Stack* stack) {
Node* node = new Node();
node->color = Red;
goto stack->push(node, stackTest2);
}
__code clearSingleLinkedStack(struct Context *context,
struct SingleLinkedStack* stack,enum Code next) {
stack->top = NULL;
goto meta(context, next);
}
__code clearSingleLinkedStack_stub(struct Context* context) {
SingleLinkedStack* stack =
(SingleLinkedStack*)GearImpl(context, Stack, stack);
enum Code next = Gearef(context, Stack)->next;
goto clearSingleLinkedStack(context, stack, next);
}
__code clearSingleLinkedStack(struct Context *context,
struct SingleLinkedStack* stack,enum Code next) {
stack->top = NULL;
goto meta(context, next);
}
__code clearSingleLinkedStack_stub(struct Context* context) {
SingleLinkedStack* stack =
(SingleLinkedStack*)GearImpl(context, Stack, stack);
enum Code next = Gearef(context, Stack)->next;
goto clearSingleLinkedStack(context, stack, next);
}