annotate doc/Interface.mm @ 590:9146d6017f18 default tip

hg mv parallel_execution/* ..
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Thu, 16 Jan 2020 15:12:06 +0900
parents 6f873aad1b06
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
416
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
1 Interfaceのtypedef はコールフレームを定義する
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
2 Interfaceの呼び出しの時に使える引数はtypedefに定義されている必要がある
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
3 ... は呼び出し側のコールフレームを保存するのに使う
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
4
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
5
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
6 typedef struct Stack<Type, Impl>{
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
7 Type* stack;
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
8 Type* data;
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
9 Type* data1;
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
10 __code whenEmpty(...);
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
11 __code clear(Impl* stack,__code next(...));
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
12 __code push(Impl* stack,Type* data, __code next(...));
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
13 __code pop(Impl* stack, __code next(Type* data, ...));
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
14 __code pop2(Impl* stack, __code next(Type* data, Type* data1, ...));
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
15 __code isEmpty(Impl* stack, __code next(...), __code whenEmpty(...));
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
16 __code get(Impl* stack, __code next(Type* data, ...));
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
17 __code get2(Impl* stack, __code next(Type* data, Type* data1, ...));
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
18 __code next(...);
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
19 } Stack;
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
20
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
21 呼び出し方の例
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
22 goto nodeStack->push(newNode, replaceNode1);
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
23 newNode はdataに対応する replaceNode1はnextに対応する。
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
24 replaceNode1のコールフレームは...に格納される。
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
25 つまり、replaceNode1はCodeGearのクロージャに相当する。
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
26
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
27 Interfaceから値を返す場合は継続経由で値を返す
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
28 __code get2(Impl* stack, __code next(Type* data, Type* data1, ...));
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
29 継続の型はInterfaceで定義されていて、この型に合うCodeGearを引数として渡す
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
30 goto nodeStack->get2(insertCase1,tree) //意味的にはtreeの後ろに...
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
31
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
32
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
33 __code insertCase1(struct Node *parent, struct Node *grandparent, struct RedBlackTree* tree) { //こっちも後ろに...があるはず
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
34
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
35 goto next(data, data1, ...);
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
36
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
37 createはinterfaceの実装を定義する
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
38 interfaceのメソッドの番号をここで指定する
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
39
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
40 implimentation側のDataGearは格納される実装依存の状態を持つ
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
41
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
42
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
43 struct SingleLinkedStack {
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
44 struct Element* top;
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
45 } SingleLinkedStack;
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
46
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
47 Stack* createSingleLinkedStack(struct Context* context) {
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
48 struct Stack* stack = new Stack();
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
49 struct SingleLinkedStack* singleLinkedStack = new SingleLinkedStack();
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
50 stack->stack = (union Data*)singleLinkedStack;
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
51 singleLinkedStack->top = NULL;
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
52 stack->push = C_pushSingleLinkedStack;
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
53 stack->pop = C_popSingleLinkedStack;
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
54 stack->pop2 = C_pop2SingleLinkedStack;
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
55 stack->get = C_getSingleLinkedStack;
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
56 stack->get2 = C_get2SingleLinkedStack;
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
57 stack->isEmpty = C_isEmptySingleLinkedStack;
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
58 stack->clear = C_clearSingleLinkedStack;
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
59 return stack;
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
60 }
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
61
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
62
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
63 実装内部で使うCodeGearの引数はコールフレームで決まる
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
64 コールフレームに含まれない中間変数を使っても良いが、辻褄は合ってる必要はある
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
65 一般的にはコールフレームに含まれている引数しか書けない
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
66 実装側の引数を書いても良い(ようにするか?)
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
67
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
68 実装の状態にアクセスする時にはコールフレーム内の実装を表すDataGearから取り出してくる
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
69
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
70
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
71 __code replaceNode1(struct RedBlackTree* tree, struct Node* node, __code next(...)) {
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
72
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
73 呼び出しの例
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
74 goto insertNode(tree, tree->nodeStack, node);
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
75
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
76
6f873aad1b06 add Interface.mm
mir3636
parents:
diff changeset
77