annotate Idea @ 7:e2c2c0fe0785

function type definition should be in global heap
author kono
date Fri, 14 Jan 2000 09:55:24 +0900
parents bf602558130d
children e714bcee688b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
1
d35df41eac69 Initial revision
kono
parents:
diff changeset
2 Thu Nov 25 17:27:12 JST 1999
d35df41eac69 Initial revision
kono
parents:
diff changeset
3
d35df41eac69 Initial revision
kono
parents:
diff changeset
4 subroutine call がない
d35df41eac69 Initial revision
kono
parents:
diff changeset
5 局所変数もない
d35df41eac69 Initial revision
kono
parents:
diff changeset
6 その代わり、大域変数を多用する
d35df41eac69 Initial revision
kono
parents:
diff changeset
7 大域変数のスコープは局所的
d35df41eac69 Initial revision
kono
parents:
diff changeset
8 Fortran の用に局所変数は静的に取る
d35df41eac69 Initial revision
kono
parents:
diff changeset
9 recursion する時には、自分で保存する
d35df41eac69 Initial revision
kono
parents:
diff changeset
10 subroutine call時のレジスタのセーブも局所的に行う
d35df41eac69 Initial revision
kono
parents:
diff changeset
11 それは、ちょっと変じゃない?
d35df41eac69 Initial revision
kono
parents:
diff changeset
12 やっぱりデフォルトのフレームは持ち歩くか?
d35df41eac69 Initial revision
kono
parents:
diff changeset
13
d35df41eac69 Initial revision
kono
parents:
diff changeset
14 recursive call とそうでないのを区別するか?
d35df41eac69 Initial revision
kono
parents:
diff changeset
15
d35df41eac69 Initial revision
kono
parents:
diff changeset
16 fp は用意する方が良い
d35df41eac69 Initial revision
kono
parents:
diff changeset
17
d35df41eac69 Initial revision
kono
parents:
diff changeset
18 関数定義と同時に、それ専用のfpの構造体を用意する
d35df41eac69 Initial revision
kono
parents:
diff changeset
19
d35df41eac69 Initial revision
kono
parents:
diff changeset
20 C をcompileする時には、stackを持ち歩く
d35df41eac69 Initial revision
kono
parents:
diff changeset
21 fp = (struct func_state *)stack
d35df41eac69 Initial revision
kono
parents:
diff changeset
22 えっと、どこに代入するの? そういう問題もあるわけね。
d35df41eac69 Initial revision
kono
parents:
diff changeset
23 じゃあ、fpは特別? それは気に入らないな。static
d35df41eac69 Initial revision
kono
parents:
diff changeset
24 なfpにすれば良いわけね。
d35df41eac69 Initial revision
kono
parents:
diff changeset
25
d35df41eac69 Initial revision
kono
parents:
diff changeset
26 func(void *stack) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
27 static struct func_state {
d35df41eac69 Initial revision
kono
parents:
diff changeset
28 static struct func_state *fp;
d35df41eac69 Initial revision
kono
parents:
diff changeset
29 int local1;
d35df41eac69 Initial revision
kono
parents:
diff changeset
30 brahbrah...
d35df41eac69 Initial revision
kono
parents:
diff changeset
31 } func_state; // ここまで hidden
d35df41eac69 Initial revision
kono
parents:
diff changeset
32 func_state.fp = (stack -= sizeof(struct func_state));
d35df41eac69 Initial revision
kono
parents:
diff changeset
33 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
34
d35df41eac69 Initial revision
kono
parents:
diff changeset
35 func_state をとってくる演算子があった方が良い? そうね。
d35df41eac69 Initial revision
kono
parents:
diff changeset
36 func.state
d35df41eac69 Initial revision
kono
parents:
diff changeset
37 ぐらい?
d35df41eac69 Initial revision
kono
parents:
diff changeset
38
d35df41eac69 Initial revision
kono
parents:
diff changeset
39 fp->local1 みたいなことだけするなら、C と同じになる。
d35df41eac69 Initial revision
kono
parents:
diff changeset
40
d35df41eac69 Initial revision
kono
parents:
diff changeset
41 call する時のarguemnt も、
d35df41eac69 Initial revision
kono
parents:
diff changeset
42 static な func_state に置く
d35df41eac69 Initial revision
kono
parents:
diff changeset
43 stack 上の func_state に置く
d35df41eac69 Initial revision
kono
parents:
diff changeset
44 という二通りの選択肢がある。Cと互換なら、当然、後者。
d35df41eac69 Initial revision
kono
parents:
diff changeset
45
d35df41eac69 Initial revision
kono
parents:
diff changeset
46 Recursive なら後者だが、この言語は状態遷移を記述するから、static
d35df41eac69 Initial revision
kono
parents:
diff changeset
47 なものでも良いはず。
d35df41eac69 Initial revision
kono
parents:
diff changeset
48
d35df41eac69 Initial revision
kono
parents:
diff changeset
49 Internal function は? あってもいいんだけど...
d35df41eac69 Initial revision
kono
parents:
diff changeset
50
d35df41eac69 Initial revision
kono
parents:
diff changeset
51 Recursive call する時には、 fp をsaveする必要があるね。
d35df41eac69 Initial revision
kono
parents:
diff changeset
52 (--(struct func_state *)stack) = fp;
d35df41eac69 Initial revision
kono
parents:
diff changeset
53 call callee(&fp->arg,continuation,stack);
d35df41eac69 Initial revision
kono
parents:
diff changeset
54 call しても、戻って来ないから... continuation は一般的にはcode
d35df41eac69 Initial revision
kono
parents:
diff changeset
55 だから... それは Internal function にするか。
d35df41eac69 Initial revision
kono
parents:
diff changeset
56
d35df41eac69 Initial revision
kono
parents:
diff changeset
57 continuation に一般的にcompileする方法を考えないといけないか。
d35df41eac69 Initial revision
kono
parents:
diff changeset
58 self は必要なわけね?
d35df41eac69 Initial revision
kono
parents:
diff changeset
59
d35df41eac69 Initial revision
kono
parents:
diff changeset
60 言語の名前も考えないといかんなぁ。
d35df41eac69 Initial revision
kono
parents:
diff changeset
61
d35df41eac69 Initial revision
kono
parents:
diff changeset
62 C からのコンパイラも書かないといけないのか...
d35df41eac69 Initial revision
kono
parents:
diff changeset
63
d35df41eac69 Initial revision
kono
parents:
diff changeset
64 Mon Dec 13 18:53:04 JST 1999
d35df41eac69 Initial revision
kono
parents:
diff changeset
65
d35df41eac69 Initial revision
kono
parents:
diff changeset
66 compiler based で、内部で partial evaluation できる?
d35df41eac69 Initial revision
kono
parents:
diff changeset
67
d35df41eac69 Initial revision
kono
parents:
diff changeset
68 func をdatabaseとして扱えないなら、それはできない。
d35df41eac69 Initial revision
kono
parents:
diff changeset
69
d35df41eac69 Initial revision
kono
parents:
diff changeset
70 しかし、状態遷移としては取り扱える。
d35df41eac69 Initial revision
kono
parents:
diff changeset
71
d35df41eac69 Initial revision
kono
parents:
diff changeset
72 func.state
d35df41eac69 Initial revision
kono
parents:
diff changeset
73 func.code
d35df41eac69 Initial revision
kono
parents:
diff changeset
74
d35df41eac69 Initial revision
kono
parents:
diff changeset
75 みたいな形にしてpartial evaluationすれば良い
d35df41eac69 Initial revision
kono
parents:
diff changeset
76
d35df41eac69 Initial revision
kono
parents:
diff changeset
77 でも止まるのか?
d35df41eac69 Initial revision
kono
parents:
diff changeset
78
d35df41eac69 Initial revision
kono
parents:
diff changeset
79 textual でない、中間的なコード表現があった方が良い? <-> interpreter?
d35df41eac69 Initial revision
kono
parents:
diff changeset
80
d35df41eac69 Initial revision
kono
parents:
diff changeset
81 Prolog ではなんでいけないの? --> Unification が重いから
d35df41eac69 Initial revision
kono
parents:
diff changeset
82
d35df41eac69 Initial revision
kono
parents:
diff changeset
83 Sat Nov 27 13:50:41 JST 1999
d35df41eac69 Initial revision
kono
parents:
diff changeset
84
d35df41eac69 Initial revision
kono
parents:
diff changeset
85 func.state とか作るのだったら、
d35df41eac69 Initial revision
kono
parents:
diff changeset
86 struct {
d35df41eac69 Initial revision
kono
parents:
diff changeset
87 struct {
d35df41eac69 Initial revision
kono
parents:
diff changeset
88 int i;
d35df41eac69 Initial revision
kono
parents:
diff changeset
89 } state;
d35df41eac69 Initial revision
kono
parents:
diff changeset
90 state *code = {
d35df41eac69 Initial revision
kono
parents:
diff changeset
91 i = i+1;
d35df41eac69 Initial revision
kono
parents:
diff changeset
92 };
d35df41eac69 Initial revision
kono
parents:
diff changeset
93 } name;
d35df41eac69 Initial revision
kono
parents:
diff changeset
94 みたいな形で、それ自体を構造化すれば? で、代入すると部分評価される。
d35df41eac69 Initial revision
kono
parents:
diff changeset
95 代入も可能。なるほど。
d35df41eac69 Initial revision
kono
parents:
diff changeset
96 *name.code;
d35df41eac69 Initial revision
kono
parents:
diff changeset
97 値はあるわけ? 値は &state でしょうね。
d35df41eac69 Initial revision
kono
parents:
diff changeset
98 self があれば、
d35df41eac69 Initial revision
kono
parents:
diff changeset
99 struct {
d35df41eac69 Initial revision
kono
parents:
diff changeset
100 struct {
d35df41eac69 Initial revision
kono
parents:
diff changeset
101 int i;
d35df41eac69 Initial revision
kono
parents:
diff changeset
102 } state,
d35df41eac69 Initial revision
kono
parents:
diff changeset
103 *code = {
d35df41eac69 Initial revision
kono
parents:
diff changeset
104 self->i = self->i+1;
d35df41eac69 Initial revision
kono
parents:
diff changeset
105 };
d35df41eac69 Initial revision
kono
parents:
diff changeset
106 } name;
d35df41eac69 Initial revision
kono
parents:
diff changeset
107 かな。self = state だよね。
d35df41eac69 Initial revision
kono
parents:
diff changeset
108
d35df41eac69 Initial revision
kono
parents:
diff changeset
109 union の拡張もあわせて議論すると...
d35df41eac69 Initial revision
kono
parents:
diff changeset
110
d35df41eac69 Initial revision
kono
parents:
diff changeset
111 Partial evalutator をセマンティクスや実行系にいれておくことは可能か?
d35df41eac69 Initial revision
kono
parents:
diff changeset
112
d35df41eac69 Initial revision
kono
parents:
diff changeset
113 byte code とか仮想マシンだったら可能。そうでない場合は?
d35df41eac69 Initial revision
kono
parents:
diff changeset
114
d35df41eac69 Initial revision
kono
parents:
diff changeset
115 いずれにせよ、構造体のタグのunique性を修正しないとだめだな。
d35df41eac69 Initial revision
kono
parents:
diff changeset
116
d35df41eac69 Initial revision
kono
parents:
diff changeset
117 ヘッダファイルはどうするの?
d35df41eac69 Initial revision
kono
parents:
diff changeset
118
d35df41eac69 Initial revision
kono
parents:
diff changeset
119 Mon Dec 13 18:53:18 JST 1999
d35df41eac69 Initial revision
kono
parents:
diff changeset
120
d35df41eac69 Initial revision
kono
parents:
diff changeset
121 library との整合性は?
d35df41eac69 Initial revision
kono
parents:
diff changeset
122
d35df41eac69 Initial revision
kono
parents:
diff changeset
123 exec sequence では、
d35df41eac69 Initial revision
kono
parents:
diff changeset
124 (--(struct func_state *)stack) = fp;
d35df41eac69 Initial revision
kono
parents:
diff changeset
125 call callee(&fp->arg);
d35df41eac69 Initial revision
kono
parents:
diff changeset
126 という形でpointerだけ渡すの? それは変だよね。
d35df41eac69 Initial revision
kono
parents:
diff changeset
127
d35df41eac69 Initial revision
kono
parents:
diff changeset
128 値渡しにするとすれば、複数の値を渡せたほうが良い。
d35df41eac69 Initial revision
kono
parents:
diff changeset
129
d35df41eac69 Initial revision
kono
parents:
diff changeset
130 func(void *stack) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
131 static struct func_state {
d35df41eac69 Initial revision
kono
parents:
diff changeset
132 static struct func_state *fp;
d35df41eac69 Initial revision
kono
parents:
diff changeset
133 int local1;
d35df41eac69 Initial revision
kono
parents:
diff changeset
134 brahbrah...
d35df41eac69 Initial revision
kono
parents:
diff changeset
135 } func_state; // ここまで hidden
d35df41eac69 Initial revision
kono
parents:
diff changeset
136 func_state.fp = (stack -= sizeof(struct func_state));
d35df41eac69 Initial revision
kono
parents:
diff changeset
137 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
138
d35df41eac69 Initial revision
kono
parents:
diff changeset
139 の引数自体が、構造体であるべき。
d35df41eac69 Initial revision
kono
parents:
diff changeset
140
d35df41eac69 Initial revision
kono
parents:
diff changeset
141 func(
d35df41eac69 Initial revision
kono
parents:
diff changeset
142 struct void *stack
d35df41eac69 Initial revision
kono
parents:
diff changeset
143 ) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
144 static struct func_state {
d35df41eac69 Initial revision
kono
parents:
diff changeset
145 static struct func_state *fp;
d35df41eac69 Initial revision
kono
parents:
diff changeset
146 int local1;
d35df41eac69 Initial revision
kono
parents:
diff changeset
147 brahbrah...
d35df41eac69 Initial revision
kono
parents:
diff changeset
148 } func_state; // ここまで hidden
d35df41eac69 Initial revision
kono
parents:
diff changeset
149 func_state.fp = (stack -= sizeof(struct func_state));
d35df41eac69 Initial revision
kono
parents:
diff changeset
150 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
151
d35df41eac69 Initial revision
kono
parents:
diff changeset
152 で、構造体に register storage を許す。
d35df41eac69 Initial revision
kono
parents:
diff changeset
153
d35df41eac69 Initial revision
kono
parents:
diff changeset
154 func(
d35df41eac69 Initial revision
kono
parents:
diff changeset
155 static struct argment {
d35df41eac69 Initial revision
kono
parents:
diff changeset
156 register void *stack;
d35df41eac69 Initial revision
kono
parents:
diff changeset
157 register void *continuation;
d35df41eac69 Initial revision
kono
parents:
diff changeset
158 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
159 ) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
160 static struct func_state {
d35df41eac69 Initial revision
kono
parents:
diff changeset
161 static struct func_state *fp;
d35df41eac69 Initial revision
kono
parents:
diff changeset
162 int local1;
d35df41eac69 Initial revision
kono
parents:
diff changeset
163 brahbrah...
d35df41eac69 Initial revision
kono
parents:
diff changeset
164 } func_state; // ここまで hidden
d35df41eac69 Initial revision
kono
parents:
diff changeset
165 func_state.fp = (stack -= sizeof(struct func_state));
d35df41eac69 Initial revision
kono
parents:
diff changeset
166 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
167
d35df41eac69 Initial revision
kono
parents:
diff changeset
168 すると、caller の方も、構造体を引数とするのが自然。
d35df41eac69 Initial revision
kono
parents:
diff changeset
169
d35df41eac69 Initial revision
kono
parents:
diff changeset
170 call caller(
d35df41eac69 Initial revision
kono
parents:
diff changeset
171 static struct argment {
d35df41eac69 Initial revision
kono
parents:
diff changeset
172 register void *stack;
d35df41eac69 Initial revision
kono
parents:
diff changeset
173 register void *continuation;
d35df41eac69 Initial revision
kono
parents:
diff changeset
174 } arg = {a,b};
d35df41eac69 Initial revision
kono
parents:
diff changeset
175 )
d35df41eac69 Initial revision
kono
parents:
diff changeset
176
d35df41eac69 Initial revision
kono
parents:
diff changeset
177 みたいな。もちろん、この構造体はインタフェースと呼ばれる。
d35df41eac69 Initial revision
kono
parents:
diff changeset
178
d35df41eac69 Initial revision
kono
parents:
diff changeset
179 argument は、callee にあった方が良いけど、caller 側にあっても
d35df41eac69 Initial revision
kono
parents:
diff changeset
180 良い。register なんかは、そう。
d35df41eac69 Initial revision
kono
parents:
diff changeset
181
d35df41eac69 Initial revision
kono
parents:
diff changeset
182 caller(interface caller_arg = {a,b,c})
d35df41eac69 Initial revision
kono
parents:
diff changeset
183 みたいなsyntax かな。
d35df41eac69 Initial revision
kono
parents:
diff changeset
184 caller->interface = {a,b,c};
d35df41eac69 Initial revision
kono
parents:
diff changeset
185 *caller->code;
d35df41eac69 Initial revision
kono
parents:
diff changeset
186 を、
d35df41eac69 Initial revision
kono
parents:
diff changeset
187 caller(a,b,c);
d35df41eac69 Initial revision
kono
parents:
diff changeset
188 と称する。
d35df41eac69 Initial revision
kono
parents:
diff changeset
189
d35df41eac69 Initial revision
kono
parents:
diff changeset
190 function には、interface と code と state があることになる。
d35df41eac69 Initial revision
kono
parents:
diff changeset
191
d35df41eac69 Initial revision
kono
parents:
diff changeset
192 state にアクセスする時のlockは? protected state? synchonized state かな?
d35df41eac69 Initial revision
kono
parents:
diff changeset
193 もちろん、sequential implementatoinでは、そんなものはいらない。
d35df41eac69 Initial revision
kono
parents:
diff changeset
194
d35df41eac69 Initial revision
kono
parents:
diff changeset
195 function {
d35df41eac69 Initial revision
kono
parents:
diff changeset
196 interface:
d35df41eac69 Initial revision
kono
parents:
diff changeset
197 register int a;
d35df41eac69 Initial revision
kono
parents:
diff changeset
198 register struct self self;
d35df41eac69 Initial revision
kono
parents:
diff changeset
199 state:
d35df41eac69 Initial revision
kono
parents:
diff changeset
200 int b;
d35df41eac69 Initial revision
kono
parents:
diff changeset
201 serialized int c;
d35df41eac69 Initial revision
kono
parents:
diff changeset
202 code:
d35df41eac69 Initial revision
kono
parents:
diff changeset
203 b = a;
d35df41eac69 Initial revision
kono
parents:
diff changeset
204 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
205
d35df41eac69 Initial revision
kono
parents:
diff changeset
206 int にvoid value を定義する。実装は重くなるけど...
d35df41eac69 Initial revision
kono
parents:
diff changeset
207
d35df41eac69 Initial revision
kono
parents:
diff changeset
208 serialzed の semantics は?
d35df41eac69 Initial revision
kono
parents:
diff changeset
209
d35df41eac69 Initial revision
kono
parents:
diff changeset
210 もう少しmicro-Cに近く!
d35df41eac69 Initial revision
kono
parents:
diff changeset
211
d35df41eac69 Initial revision
kono
parents:
diff changeset
212 carring state と static state。
d35df41eac69 Initial revision
kono
parents:
diff changeset
213
d35df41eac69 Initial revision
kono
parents:
diff changeset
214 Mon Dec 13 19:42:41 JST 1999
d35df41eac69 Initial revision
kono
parents:
diff changeset
215
d35df41eac69 Initial revision
kono
parents:
diff changeset
216 interface に regsiter keyword を使うのは、あまりに
d35df41eac69 Initial revision
kono
parents:
diff changeset
217 実装よりすぎる。でも、でないと状態にできない?
d35df41eac69 Initial revision
kono
parents:
diff changeset
218 そんなことはないか。やっぱりcaller側のstatic 領域に
d35df41eac69 Initial revision
kono
parents:
diff changeset
219 直接書き込む?
d35df41eac69 Initial revision
kono
parents:
diff changeset
220
d35df41eac69 Initial revision
kono
parents:
diff changeset
221 だとCより遅そう。でも、引数に40個とかかかれたら...
d35df41eac69 Initial revision
kono
parents:
diff changeset
222
d35df41eac69 Initial revision
kono
parents:
diff changeset
223 Wed Dec 15 14:09:49 JST 1999
d35df41eac69 Initial revision
kono
parents:
diff changeset
224
d35df41eac69 Initial revision
kono
parents:
diff changeset
225 C と互換にする?
d35df41eac69 Initial revision
kono
parents:
diff changeset
226 goto function(argments);
d35df41eac69 Initial revision
kono
parents:
diff changeset
227 goto *continuation(argments);
d35df41eac69 Initial revision
kono
parents:
diff changeset
228 みたいな感じで。
d35df41eac69 Initial revision
kono
parents:
diff changeset
229
d35df41eac69 Initial revision
kono
parents:
diff changeset
230 stackの管理は? どうせ、library との互換はとらないと
d35df41eac69 Initial revision
kono
parents:
diff changeset
231 いけないんだから...
d35df41eac69 Initial revision
kono
parents:
diff changeset
232
d35df41eac69 Initial revision
kono
parents:
diff changeset
233 local 変数がある場合は stack を動かす。でも、戻す奴がいない。
d35df41eac69 Initial revision
kono
parents:
diff changeset
234 closure 化するか?
d35df41eac69 Initial revision
kono
parents:
diff changeset
235
d35df41eac69 Initial revision
kono
parents:
diff changeset
236 return した時の挙動が複雑になる。大域returnするわけだら。
d35df41eac69 Initial revision
kono
parents:
diff changeset
237
d35df41eac69 Initial revision
kono
parents:
diff changeset
238 argments をstatic 領域にかきこむ方式だと互換性がとれない。
d35df41eac69 Initial revision
kono
parents:
diff changeset
239 stack 上の frmae pointer 上にないとダメだから。
d35df41eac69 Initial revision
kono
parents:
diff changeset
240
d35df41eac69 Initial revision
kono
parents:
diff changeset
241 両立させるのは無理か? つまり、これだと、呼び出された方の
d35df41eac69 Initial revision
kono
parents:
diff changeset
242 frame semantics は、C と互換になる。だから、stackの直後に
d35df41eac69 Initial revision
kono
parents:
diff changeset
243 frame pointer があると思っている (そうか? ) frame pointer
d35df41eac69 Initial revision
kono
parents:
diff changeset
244 stack pointer に沿って移動した直後に、そこからのoffset
d35df41eac69 Initial revision
kono
parents:
diff changeset
245 で引数を操作することになる。
d35df41eac69 Initial revision
kono
parents:
diff changeset
246
d35df41eac69 Initial revision
kono
parents:
diff changeset
247 つまり、それはだめだったことじゃない? つまり、goto だと、
d35df41eac69 Initial revision
kono
parents:
diff changeset
248 frame pointer は、stack の直後とは限らないから。前の
d35df41eac69 Initial revision
kono
parents:
diff changeset
249 frmae pointer 相対に引数にアクセスしてくれれば別だけどね。
d35df41eac69 Initial revision
kono
parents:
diff changeset
250
d35df41eac69 Initial revision
kono
parents:
diff changeset
251 stack に引数を積むのは容認して、goto の場合は、向こう側で
d35df41eac69 Initial revision
kono
parents:
diff changeset
252 stack を畳むってのは? ということは、普通の関数と定義の
d35df41eac69 Initial revision
kono
parents:
diff changeset
253 方法を変えるってことか。ま、悪くはないか。
d35df41eac69 Initial revision
kono
parents:
diff changeset
254
d35df41eac69 Initial revision
kono
parents:
diff changeset
255 すると、goto のsemantics は、C と互換になる。それを受ける
d35df41eac69 Initial revision
kono
parents:
diff changeset
256 方が異なることをする。それは、なんかおかしいな。それに、
d35df41eac69 Initial revision
kono
parents:
diff changeset
257 それだと関数呼び出しが軽くならない...
d35df41eac69 Initial revision
kono
parents:
diff changeset
258
d35df41eac69 Initial revision
kono
parents:
diff changeset
259 ということは、やはり、C のcall は、call funciton で
d35df41eac69 Initial revision
kono
parents:
diff changeset
260 実現して、その他の呼び出しは、すべて、goto 扱いに
d35df41eac69 Initial revision
kono
parents:
diff changeset
261 する方が正しいだろう。
d35df41eac69 Initial revision
kono
parents:
diff changeset
262
d35df41eac69 Initial revision
kono
parents:
diff changeset
263 問題は、この言語の関数をcallされた時だな。dual entry にして、
d35df41eac69 Initial revision
kono
parents:
diff changeset
264 call の時と、goto の時を区別するか。
d35df41eac69 Initial revision
kono
parents:
diff changeset
265 func: stack processing
d35df41eac69 Initial revision
kono
parents:
diff changeset
266 func_goto: normal processing
d35df41eac69 Initial revision
kono
parents:
diff changeset
267 ...
d35df41eac69 Initial revision
kono
parents:
diff changeset
268 みたいな感じ。でも、return はないから...
d35df41eac69 Initial revision
kono
parents:
diff changeset
269
d35df41eac69 Initial revision
kono
parents:
diff changeset
270 このあたりも自分で記述できる言語であるべきだよね。その通り。
d35df41eac69 Initial revision
kono
parents:
diff changeset
271 つまり、C とのstub も自分で記述すると言うことか。
d35df41eac69 Initial revision
kono
parents:
diff changeset
272
d35df41eac69 Initial revision
kono
parents:
diff changeset
273 protocol function {
d35df41eac69 Initial revision
kono
parents:
diff changeset
274 interface c {
d35df41eac69 Initial revision
kono
parents:
diff changeset
275 register "%esp" struct {
d35df41eac69 Initial revision
kono
parents:
diff changeset
276 entry code ret(int);
d35df41eac69 Initial revision
kono
parents:
diff changeset
277 void *fp;
d35df41eac69 Initial revision
kono
parents:
diff changeset
278 } *sp;
d35df41eac69 Initial revision
kono
parents:
diff changeset
279 register "%ebp" void *fp;
d35df41eac69 Initial revision
kono
parents:
diff changeset
280 };
d35df41eac69 Initial revision
kono
parents:
diff changeset
281 code function_code {
d35df41eac69 Initial revision
kono
parents:
diff changeset
282 fp = sp;
d35df41eac69 Initial revision
kono
parents:
diff changeset
283 sp += sizeof(struct local);
d35df41eac69 Initial revision
kono
parents:
diff changeset
284 struct local *local = sp;
d35df41eac69 Initial revision
kono
parents:
diff changeset
285
d35df41eac69 Initial revision
kono
parents:
diff changeset
286 local->i = 1;
d35df41eac69 Initial revision
kono
parents:
diff changeset
287 goto *fp->ret(local->i),sp=fp; // return(local->i);
d35df41eac69 Initial revision
kono
parents:
diff changeset
288 };
d35df41eac69 Initial revision
kono
parents:
diff changeset
289 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
290
d35df41eac69 Initial revision
kono
parents:
diff changeset
291 みたいな感じでさ。さっすが、アセンブラ。いまいちreturnが汚いけど。
d35df41eac69 Initial revision
kono
parents:
diff changeset
292 まぁ、return はそのままreturnでもいいけどさ。
d35df41eac69 Initial revision
kono
parents:
diff changeset
293
d35df41eac69 Initial revision
kono
parents:
diff changeset
294 あ、これは良いかも知れない。code が複数かけるから。
d35df41eac69 Initial revision
kono
parents:
diff changeset
295
d35df41eac69 Initial revision
kono
parents:
diff changeset
296 state 以外は、consitent state であることを保証しない。ってのは?
d35df41eac69 Initial revision
kono
parents:
diff changeset
297 local 変数は使っても良いけど、call/goto の前後で、値を保証しないか...
d35df41eac69 Initial revision
kono
parents:
diff changeset
298
d35df41eac69 Initial revision
kono
parents:
diff changeset
299 うーん、だんだん炸裂してるなぁ。
d35df41eac69 Initial revision
kono
parents:
diff changeset
300
d35df41eac69 Initial revision
kono
parents:
diff changeset
301 だから、レジスタに対するマッピングの記述と、そうでない部分の
d35df41eac69 Initial revision
kono
parents:
diff changeset
302 記述は分離するべきでしょうね。
d35df41eac69 Initial revision
kono
parents:
diff changeset
303
d35df41eac69 Initial revision
kono
parents:
diff changeset
304
d35df41eac69 Initial revision
kono
parents:
diff changeset
305 全部一辺に実装するわけにはいかないからぁ...
d35df41eac69 Initial revision
kono
parents:
diff changeset
306
d35df41eac69 Initial revision
kono
parents:
diff changeset
307 Thu Dec 16 13:44:21 JST 1999
d35df41eac69 Initial revision
kono
parents:
diff changeset
308
d35df41eac69 Initial revision
kono
parents:
diff changeset
309 lock は状態遷移レベルで実現するのだから、self などを
d35df41eac69 Initial revision
kono
parents:
diff changeset
310 使ってlockする必要はないはず。
d35df41eac69 Initial revision
kono
parents:
diff changeset
311
d35df41eac69 Initial revision
kono
parents:
diff changeset
312 全体の直列化は、状態遷移レベルで、
d35df41eac69 Initial revision
kono
parents:
diff changeset
313 lock(storage) -> transition
d35df41eac69 Initial revision
kono
parents:
diff changeset
314 みたいな形で記述すれば良い。この当たりを、どのように記述するかは
d35df41eac69 Initial revision
kono
parents:
diff changeset
315 もう少し先送りしよう。
d35df41eac69 Initial revision
kono
parents:
diff changeset
316
d35df41eac69 Initial revision
kono
parents:
diff changeset
317
d35df41eac69 Initial revision
kono
parents:
diff changeset
318 引数はレジスタ渡しにしよう。長い引数は、呼び出し側の領域への
d35df41eac69 Initial revision
kono
parents:
diff changeset
319 ポインタとする。実装を規定しても良い。そうすれば、varargs
d35df41eac69 Initial revision
kono
parents:
diff changeset
320 みたいなものはなくなる。だいたい、なんで、そんなものがいるんだろう?
d35df41eac69 Initial revision
kono
parents:
diff changeset
321 配列を渡せばいいじゃん。
d35df41eac69 Initial revision
kono
parents:
diff changeset
322
d35df41eac69 Initial revision
kono
parents:
diff changeset
323 なので、引数は一つ(or 二つ)に限るという方法もある。
d35df41eac69 Initial revision
kono
parents:
diff changeset
324
d35df41eac69 Initial revision
kono
parents:
diff changeset
325 とすると、やはり、前もって静的領域や動的領域を確保することは
d35df41eac69 Initial revision
kono
parents:
diff changeset
326 できない。
d35df41eac69 Initial revision
kono
parents:
diff changeset
327
d35df41eac69 Initial revision
kono
parents:
diff changeset
328 この言語では動的領域は自分で確保するわけだから、その点は問題ない。
d35df41eac69 Initial revision
kono
parents:
diff changeset
329
d35df41eac69 Initial revision
kono
parents:
diff changeset
330 Thu Dec 16 20:24:55 JST 1999
d35df41eac69 Initial revision
kono
parents:
diff changeset
331
d35df41eac69 Initial revision
kono
parents:
diff changeset
332 とすると関数呼び出しは、
d35df41eac69 Initial revision
kono
parents:
diff changeset
333 # register save
d35df41eac69 Initial revision
kono
parents:
diff changeset
334 # set 1st argument in register %eax
d35df41eac69 Initial revision
kono
parents:
diff changeset
335 # set 2nd argument in register %ecx
d35df41eac69 Initial revision
kono
parents:
diff changeset
336 # set extra aguments in save area
d35df41eac69 Initial revision
kono
parents:
diff changeset
337 # set extra argument pointer in %edx
d35df41eac69 Initial revision
kono
parents:
diff changeset
338 jmp function
d35df41eac69 Initial revision
kono
parents:
diff changeset
339 という形式になるわけね。second を処理するのはめんどくさいから一つ
d35df41eac69 Initial revision
kono
parents:
diff changeset
340 にしよう。
d35df41eac69 Initial revision
kono
parents:
diff changeset
341
d35df41eac69 Initial revision
kono
parents:
diff changeset
342 えーと、frame pointer はないけど、コンパイルの手順からすると
d35df41eac69 Initial revision
kono
parents:
diff changeset
343 あった方が良い。しかし、frame pointer そのものをstatic
d35df41eac69 Initial revision
kono
parents:
diff changeset
344 にとるのはまずい。だから、frame pointer がfirst argment
d35df41eac69 Initial revision
kono
parents:
diff changeset
345 ということにする方が正しい。とすると引数は、さらに、その
d35df41eac69 Initial revision
kono
parents:
diff changeset
346 後と言うわけか。
d35df41eac69 Initial revision
kono
parents:
diff changeset
347 f(fp,argment)
d35df41eac69 Initial revision
kono
parents:
diff changeset
348 fp を渡すのにさらにargment をレジスタで渡すのはおかしい。おかしいけど、
d35df41eac69 Initial revision
kono
parents:
diff changeset
349 ま、良いか。
d35df41eac69 Initial revision
kono
parents:
diff changeset
350
d35df41eac69 Initial revision
kono
parents:
diff changeset
351 return しないなら、return type の定義をとるのは変だな。
d35df41eac69 Initial revision
kono
parents:
diff changeset
352
d35df41eac69 Initial revision
kono
parents:
diff changeset
353 f(fp,arg1,arg2,arg3) とすると、それぞれが決まったレジスタに入って、
d35df41eac69 Initial revision
kono
parents:
diff changeset
354 多い分は配列にあると思われる。ふむふむ...
d35df41eac69 Initial revision
kono
parents:
diff changeset
355 fp->xx
d35df41eac69 Initial revision
kono
parents:
diff changeset
356 でアクセスすれば、そのまま局所変数になる。全部、配列で
d35df41eac69 Initial revision
kono
parents:
diff changeset
357 送っても良い。
d35df41eac69 Initial revision
kono
parents:
diff changeset
358
d35df41eac69 Initial revision
kono
parents:
diff changeset
359 .set label,value
d35df41eac69 Initial revision
kono
parents:
diff changeset
360
d35df41eac69 Initial revision
kono
parents:
diff changeset
361 で as は値をセットするようですね。
d35df41eac69 Initial revision
kono
parents:
diff changeset
362
d35df41eac69 Initial revision
kono
parents:
diff changeset
363 関数コールの後は戻って来ないから後始末の心配はしなくてよい。
d35df41eac69 Initial revision
kono
parents:
diff changeset
364 frame pointer を使ったら自分で面倒を見ること。
d35df41eac69 Initial revision
kono
parents:
diff changeset
365
d35df41eac69 Initial revision
kono
parents:
diff changeset
366 だと
d35df41eac69 Initial revision
kono
parents:
diff changeset
367 a = atoi(s);
d35df41eac69 Initial revision
kono
parents:
diff changeset
368 みたいなことはできない...
d35df41eac69 Initial revision
kono
parents:
diff changeset
369
d35df41eac69 Initial revision
kono
parents:
diff changeset
370 普通のCの定義と交じると間違いやすい。
d35df41eac69 Initial revision
kono
parents:
diff changeset
371
d35df41eac69 Initial revision
kono
parents:
diff changeset
372 とすると、struct と同様に、
d35df41eac69 Initial revision
kono
parents:
diff changeset
373 protocol
d35df41eac69 Initial revision
kono
parents:
diff changeset
374 code
d35df41eac69 Initial revision
kono
parents:
diff changeset
375 interface
d35df41eac69 Initial revision
kono
parents:
diff changeset
376 state
d35df41eac69 Initial revision
kono
parents:
diff changeset
377 を用意するわけね。時間あるのかぁ?
d35df41eac69 Initial revision
kono
parents:
diff changeset
378
d35df41eac69 Initial revision
kono
parents:
diff changeset
379 とりあえず、register 渡しのfunction 定義とgoto文を実装する。
d35df41eac69 Initial revision
kono
parents:
diff changeset
380
d35df41eac69 Initial revision
kono
parents:
diff changeset
381 code name(register "%ebp" void *arg) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
382 goto name(arg);
d35df41eac69 Initial revision
kono
parents:
diff changeset
383 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
384
d35df41eac69 Initial revision
kono
parents:
diff changeset
385 ぐらいかな? で、first argment が必ずregisterにのるようにしないと
d35df41eac69 Initial revision
kono
parents:
diff changeset
386 いけない。register storage class を入れて、
d35df41eac69 Initial revision
kono
parents:
diff changeset
387 register "%ebp" void *arg
d35df41eac69 Initial revision
kono
parents:
diff changeset
388 とかするわけね。
d35df41eac69 Initial revision
kono
parents:
diff changeset
389
d35df41eac69 Initial revision
kono
parents:
diff changeset
390 ってことは、まず、レジスタを実装しないといけないわけね。
d35df41eac69 Initial revision
kono
parents:
diff changeset
391
d35df41eac69 Initial revision
kono
parents:
diff changeset
392 で、stack を使った演算は、一応、そのままにする? それでも動くはず。
d35df41eac69 Initial revision
kono
parents:
diff changeset
393 式の途中でgotoは使えないんだから、それでいいはず。
d35df41eac69 Initial revision
kono
parents:
diff changeset
394
d35df41eac69 Initial revision
kono
parents:
diff changeset
395 で、それから、これを拡張していく。
d35df41eac69 Initial revision
kono
parents:
diff changeset
396
d35df41eac69 Initial revision
kono
parents:
diff changeset
397 interface c {
d35df41eac69 Initial revision
kono
parents:
diff changeset
398 register "%ebp" void *arg;
d35df41eac69 Initial revision
kono
parents:
diff changeset
399 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
400 code name(interface c) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
401 goto name(c.arg); // c. は省略可能
d35df41eac69 Initial revision
kono
parents:
diff changeset
402 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
403
d35df41eac69 Initial revision
kono
parents:
diff changeset
404 とかね。さらに、
d35df41eac69 Initial revision
kono
parents:
diff changeset
405
d35df41eac69 Initial revision
kono
parents:
diff changeset
406 protocol name {
d35df41eac69 Initial revision
kono
parents:
diff changeset
407 interface c {
d35df41eac69 Initial revision
kono
parents:
diff changeset
408 register "%ebp" void *arg;
d35df41eac69 Initial revision
kono
parents:
diff changeset
409 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
410 code name(interface c) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
411 goto name(arg);
d35df41eac69 Initial revision
kono
parents:
diff changeset
412 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
413 code name1(interface c) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
414 goto name(arg);
d35df41eac69 Initial revision
kono
parents:
diff changeset
415 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
416 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
417
d35df41eac69 Initial revision
kono
parents:
diff changeset
418 などとするわけか。なんと、これが C と共存するわけね。うーん。
d35df41eac69 Initial revision
kono
parents:
diff changeset
419
d35df41eac69 Initial revision
kono
parents:
diff changeset
420 Fri Dec 31 11:44:03 JST 1999
d35df41eac69 Initial revision
kono
parents:
diff changeset
421
d35df41eac69 Initial revision
kono
parents:
diff changeset
422 code でなくて、別な名前のほうが良くない? segment? action?
d35df41eac69 Initial revision
kono
parents:
diff changeset
423
d35df41eac69 Initial revision
kono
parents:
diff changeset
424 レジスタ名が入るのは、やっぱりいや。optionalには許す。
d35df41eac69 Initial revision
kono
parents:
diff changeset
425
d35df41eac69 Initial revision
kono
parents:
diff changeset
426 interface は構造体のようなものだから... 構造体でいいんじゃない?
d35df41eac69 Initial revision
kono
parents:
diff changeset
427 構造体の場合は... malloc する? う、うーん。malloc するとして、
d35df41eac69 Initial revision
kono
parents:
diff changeset
428 いつfree するの?
d35df41eac69 Initial revision
kono
parents:
diff changeset
429
d35df41eac69 Initial revision
kono
parents:
diff changeset
430 再入するときには、壊れてていいんじゃない? multi-thread でなければね。
d35df41eac69 Initial revision
kono
parents:
diff changeset
431 multi thread では、状態は、レジスタ経由または、thread local に持つ
d35df41eac69 Initial revision
kono
parents:
diff changeset
432 必要がある。static は、だから thread local に持たなくてはならない。
d35df41eac69 Initial revision
kono
parents:
diff changeset
433 大域変数に割り振っちゃだめ。でも、いまは、やめて
d35df41eac69 Initial revision
kono
parents:
diff changeset
434
d35df41eac69 Initial revision
kono
parents:
diff changeset
435 interface は、とりあえず、二つまでの値渡しにしよう。
d35df41eac69 Initial revision
kono
parents:
diff changeset
436 self と arg
d35df41eac69 Initial revision
kono
parents:
diff changeset
437 ですね。
d35df41eac69 Initial revision
kono
parents:
diff changeset
438
d35df41eac69 Initial revision
kono
parents:
diff changeset
439 もう少し拡張しやすいコンパイラがいいなぁ。
d35df41eac69 Initial revision
kono
parents:
diff changeset
440
d35df41eac69 Initial revision
kono
parents:
diff changeset
441 code name (c,a)
d35df41eac69 Initial revision
kono
parents:
diff changeset
442 struct state *c; struct arg *a;
d35df41eac69 Initial revision
kono
parents:
diff changeset
443 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
444 goto name(arg);
d35df41eac69 Initial revision
kono
parents:
diff changeset
445 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
446
d35df41eac69 Initial revision
kono
parents:
diff changeset
447 local 変数は? この互換性の問題かぁ。
d35df41eac69 Initial revision
kono
parents:
diff changeset
448
d35df41eac69 Initial revision
kono
parents:
diff changeset
449 KL/1 を意識して、interface は heap に置くことにしても良い。
d35df41eac69 Initial revision
kono
parents:
diff changeset
450 GC は言語に入れておくべきだが、interfaceは machine independent
d35df41eac69 Initial revision
kono
parents:
diff changeset
451 であるべき。だとすれば use/forget みたいものはいるだろう。
d35df41eac69 Initial revision
kono
parents:
diff changeset
452 でも今のところは考える必要はない。
d35df41eac69 Initial revision
kono
parents:
diff changeset
453
d35df41eac69 Initial revision
kono
parents:
diff changeset
454 えーと、
d35df41eac69 Initial revision
kono
parents:
diff changeset
455 code name (c,a)
d35df41eac69 Initial revision
kono
parents:
diff changeset
456 struct state *c; struct arg *a;
d35df41eac69 Initial revision
kono
parents:
diff changeset
457 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
458 int i;
d35df41eac69 Initial revision
kono
parents:
diff changeset
459 goto name(arg);
d35df41eac69 Initial revision
kono
parents:
diff changeset
460 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
461 の時の一時変数iはどうするの? 基本的にはレジスタ割り当てだけど...
d35df41eac69 Initial revision
kono
parents:
diff changeset
462 使用させない? んー、大胆な御意見。まぁ、やっぱりheapに割り当てちゃう
d35df41eac69 Initial revision
kono
parents:
diff changeset
463 のが簡単か。でも、どうせ抜ける時にはいらなくなるわけだから...
d35df41eac69 Initial revision
kono
parents:
diff changeset
464
d35df41eac69 Initial revision
kono
parents:
diff changeset
465 ほんらい、この変数は、次のcallでは必要無くなるのが普通。
d35df41eac69 Initial revision
kono
parents:
diff changeset
466
d35df41eac69 Initial revision
kono
parents:
diff changeset
467 とにかく、レジスタ変数は必要なんでしょう?
d35df41eac69 Initial revision
kono
parents:
diff changeset
468
d35df41eac69 Initial revision
kono
parents:
diff changeset
469 だから、GC と合わせて言語を設計すべきだよね。API を規定して、
d35df41eac69 Initial revision
kono
parents:
diff changeset
470 異なるGCを選択できるようにする。
d35df41eac69 Initial revision
kono
parents:
diff changeset
471
d35df41eac69 Initial revision
kono
parents:
diff changeset
472 Sat Jan 1 22:40:22 JST 2000
d35df41eac69 Initial revision
kono
parents:
diff changeset
473
d35df41eac69 Initial revision
kono
parents:
diff changeset
474 とーにかく、 storage class regisgter を実装しよう。
d35df41eac69 Initial revision
kono
parents:
diff changeset
475
d35df41eac69 Initial revision
kono
parents:
diff changeset
476 stmode=REGISTER
d35df41eac69 Initial revision
kono
parents:
diff changeset
477
d35df41eac69 Initial revision
kono
parents:
diff changeset
478 で、local storage とおなじ扱いとする
d35df41eac69 Initial revision
kono
parents:
diff changeset
479 static register? は、ない。
d35df41eac69 Initial revision
kono
parents:
diff changeset
480
d35df41eac69 Initial revision
kono
parents:
diff changeset
481 symbol table に storage class をたせば? dsp==EXTRN で判定しているから、
d35df41eac69 Initial revision
kono
parents:
diff changeset
482 local 変数が36以上あるとおかしくなるぞ?
d35df41eac69 Initial revision
kono
parents:
diff changeset
483
d35df41eac69 Initial revision
kono
parents:
diff changeset
484 sc は GVAR/LVAR だけど、regsiter は LVAR の特殊な奴だから、
d35df41eac69 Initial revision
kono
parents:
diff changeset
485 sc に入れるほうが正しいか...
d35df41eac69 Initial revision
kono
parents:
diff changeset
486
d35df41eac69 Initial revision
kono
parents:
diff changeset
487 Sun Jan 2 01:47:17 JST 2000
d35df41eac69 Initial revision
kono
parents:
diff changeset
488
d35df41eac69 Initial revision
kono
parents:
diff changeset
489 register 変数はできました。けど、regsiter を二つ使うと、
d35df41eac69 Initial revision
kono
parents:
diff changeset
490 一杯になってしまうので、REGISTER6 でコンパイルしないと
d35df41eac69 Initial revision
kono
parents:
diff changeset
491 結構ひどい。が、register 変数を%esi,%edi に割り当てれば
d35df41eac69 Initial revision
kono
parents:
diff changeset
492 いいか。
d35df41eac69 Initial revision
kono
parents:
diff changeset
493
d35df41eac69 Initial revision
kono
parents:
diff changeset
494 Sun Jan 2 04:43:04 JST 2000
d35df41eac69 Initial revision
kono
parents:
diff changeset
495
d35df41eac69 Initial revision
kono
parents:
diff changeset
496 で、
d35df41eac69 Initial revision
kono
parents:
diff changeset
497 code name (c,a)
d35df41eac69 Initial revision
kono
parents:
diff changeset
498 struct state *c; struct arg *a;
d35df41eac69 Initial revision
kono
parents:
diff changeset
499 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
500 goto name(c);
d35df41eac69 Initial revision
kono
parents:
diff changeset
501 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
502 の一時変数無しは実装できます。引数は二つまでね。
d35df41eac69 Initial revision
kono
parents:
diff changeset
503
d35df41eac69 Initial revision
kono
parents:
diff changeset
504 .file "tmp.c"
d35df41eac69 Initial revision
kono
parents:
diff changeset
505 .version "01.01"
d35df41eac69 Initial revision
kono
parents:
diff changeset
506 gcc2_compiled.:
d35df41eac69 Initial revision
kono
parents:
diff changeset
507 .text
d35df41eac69 Initial revision
kono
parents:
diff changeset
508 #
d35df41eac69 Initial revision
kono
parents:
diff changeset
509 # code name(c,a)
d35df41eac69 Initial revision
kono
parents:
diff changeset
510 .align 2
d35df41eac69 Initial revision
kono
parents:
diff changeset
511 .globl code
d35df41eac69 Initial revision
kono
parents:
diff changeset
512 code:
d35df41eac69 Initial revision
kono
parents:
diff changeset
513 .type code,@function
d35df41eac69 Initial revision
kono
parents:
diff changeset
514 # struct state *c; struct arg *a;
d35df41eac69 Initial revision
kono
parents:
diff changeset
515 # {
d35df41eac69 Initial revision
kono
parents:
diff changeset
516 # goto name(c);
d35df41eac69 Initial revision
kono
parents:
diff changeset
517 movl %esi,%esi
d35df41eac69 Initial revision
kono
parents:
diff changeset
518 jmp name
d35df41eac69 Initial revision
kono
parents:
diff changeset
519 _5:
d35df41eac69 Initial revision
kono
parents:
diff changeset
520 .size code,_5-code
d35df41eac69 Initial revision
kono
parents:
diff changeset
521 .ident "Micro-C compiled"
d35df41eac69 Initial revision
kono
parents:
diff changeset
522
d35df41eac69 Initial revision
kono
parents:
diff changeset
523 う、すごい。
d35df41eac69 Initial revision
kono
parents:
diff changeset
524
d35df41eac69 Initial revision
kono
parents:
diff changeset
525 goto 文がめんどくさい。stack をたたんで、jmp すれば
d35df41eac69 Initial revision
kono
parents:
diff changeset
526 よいだけだが..
d35df41eac69 Initial revision
kono
parents:
diff changeset
527
d35df41eac69 Initial revision
kono
parents:
diff changeset
528 Sun Jan 2 11:17:50 JST 2000
d35df41eac69 Initial revision
kono
parents:
diff changeset
529
d35df41eac69 Initial revision
kono
parents:
diff changeset
530 普通のcallをcontinuation baseにすることができる?
d35df41eac69 Initial revision
kono
parents:
diff changeset
531
d35df41eac69 Initial revision
kono
parents:
diff changeset
532 Sun Jan 2 20:28:45 JST 2000
d35df41eac69 Initial revision
kono
parents:
diff changeset
533
d35df41eac69 Initial revision
kono
parents:
diff changeset
534 goto 文だけど、やはり、一度、expr で生成してから、top level
d35df41eac69 Initial revision
kono
parents:
diff changeset
535 で jump code を生成しよう。
d35df41eac69 Initial revision
kono
parents:
diff changeset
536
d35df41eac69 Initial revision
kono
parents:
diff changeset
537 Tue Jan 4 03:32:55 JST 2000
d35df41eac69 Initial revision
kono
parents:
diff changeset
538
d35df41eac69 Initial revision
kono
parents:
diff changeset
539 code をtypeにしないと、
d35df41eac69 Initial revision
kono
parents:
diff changeset
540 code *p;
d35df41eac69 Initial revision
kono
parents:
diff changeset
541 とか書けないね。
d35df41eac69 Initial revision
kono
parents:
diff changeset
542 int *p();
d35df41eac69 Initial revision
kono
parents:
diff changeset
543 と同じだけどさ。
d35df41eac69 Initial revision
kono
parents:
diff changeset
544
d35df41eac69 Initial revision
kono
parents:
diff changeset
545
d35df41eac69 Initial revision
kono
parents:
diff changeset
546 main(ac,av)
d35df41eac69 Initial revision
kono
parents:
diff changeset
547 int ac;
d35df41eac69 Initial revision
kono
parents:
diff changeset
548 char *av[];
d35df41eac69 Initial revision
kono
parents:
diff changeset
549 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
550 goto code1(ac,av);
d35df41eac69 Initial revision
kono
parents:
diff changeset
551 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
552
d35df41eac69 Initial revision
kono
parents:
diff changeset
553 code code1(ac,av)
d35df41eac69 Initial revision
kono
parents:
diff changeset
554 int ac;
d35df41eac69 Initial revision
kono
parents:
diff changeset
555 char *av[];
d35df41eac69 Initial revision
kono
parents:
diff changeset
556 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
557 if (ac)
d35df41eac69 Initial revision
kono
parents:
diff changeset
558 goto code1(ac,av);
d35df41eac69 Initial revision
kono
parents:
diff changeset
559 else
d35df41eac69 Initial revision
kono
parents:
diff changeset
560 goto ac(ac,av);
d35df41eac69 Initial revision
kono
parents:
diff changeset
561 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
562
d35df41eac69 Initial revision
kono
parents:
diff changeset
563 Tue Jan 4 04:56:56 JST 2000
d35df41eac69 Initial revision
kono
parents:
diff changeset
564
d35df41eac69 Initial revision
kono
parents:
diff changeset
565 うーん、なんかレジスタにつむ順序が違う
d35df41eac69 Initial revision
kono
parents:
diff changeset
566 これは、adecl がreverseにつむから。
d35df41eac69 Initial revision
kono
parents:
diff changeset
567
d35df41eac69 Initial revision
kono
parents:
diff changeset
568 code のretrun
d35df41eac69 Initial revision
kono
parents:
diff changeset
569
d35df41eac69 Initial revision
kono
parents:
diff changeset
570 やはりcodeはtypeにしないとだめ。
d35df41eac69 Initial revision
kono
parents:
diff changeset
571
d35df41eac69 Initial revision
kono
parents:
diff changeset
572 main()
d35df41eac69 Initial revision
kono
parents:
diff changeset
573 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
574 goto code1();
d35df41eac69 Initial revision
kono
parents:
diff changeset
575 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
576
d35df41eac69 Initial revision
kono
parents:
diff changeset
577 とかだと、main に戻って来れない。もちろん、code1() 以降で、
d35df41eac69 Initial revision
kono
parents:
diff changeset
578 return するわけにはいかない。(main の disp をcode1 は知り得ない)
d35df41eac69 Initial revision
kono
parents:
diff changeset
579 goto label をcode1の引数に送れば?
d35df41eac69 Initial revision
kono
parents:
diff changeset
580
d35df41eac69 Initial revision
kono
parents:
diff changeset
581 main()
d35df41eac69 Initial revision
kono
parents:
diff changeset
582 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
583 goto code1(ret);
d35df41eac69 Initial revision
kono
parents:
diff changeset
584 ret:
d35df41eac69 Initial revision
kono
parents:
diff changeset
585 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
586
d35df41eac69 Initial revision
kono
parents:
diff changeset
587 これだと、ret がforward labelかどうか分からないけど?
d35df41eac69 Initial revision
kono
parents:
diff changeset
588
d35df41eac69 Initial revision
kono
parents:
diff changeset
589 code1 中で使う中間変数を stack 上にとるのは悪くない。しかし、それを
d35df41eac69 Initial revision
kono
parents:
diff changeset
590 %ebp 経由でアクセスするということは、main の中間変数を壊すということ。
d35df41eac69 Initial revision
kono
parents:
diff changeset
591 それを防ぐには、main 中のgoto codeで、%ebp を修正してやれば良い。
d35df41eac69 Initial revision
kono
parents:
diff changeset
592 (今は戻って来ないので問題ない)
d35df41eac69 Initial revision
kono
parents:
diff changeset
593
d35df41eac69 Initial revision
kono
parents:
diff changeset
594 code1 のgoto では、戻って来ないから、その必要はない。しかし、
d35df41eac69 Initial revision
kono
parents:
diff changeset
595 label をcode1 中で渡されると、ちょっと気まずい。
d35df41eac69 Initial revision
kono
parents:
diff changeset
596
d35df41eac69 Initial revision
kono
parents:
diff changeset
597 とすると、それは禁止して、main() 中でstackをたたんでからgotoするか?
d35df41eac69 Initial revision
kono
parents:
diff changeset
598 そうすると、無限後退して、結局、帰れないことになる... うーん。
d35df41eac69 Initial revision
kono
parents:
diff changeset
599
d35df41eac69 Initial revision
kono
parents:
diff changeset
600 main() 中のlocal code を許せば、それは解決するが..
d35df41eac69 Initial revision
kono
parents:
diff changeset
601
d35df41eac69 Initial revision
kono
parents:
diff changeset
602 main()
d35df41eac69 Initial revision
kono
parents:
diff changeset
603 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
604 goto code1(code2);
d35df41eac69 Initial revision
kono
parents:
diff changeset
605 code code2() {
d35df41eac69 Initial revision
kono
parents:
diff changeset
606 return;
d35df41eac69 Initial revision
kono
parents:
diff changeset
607 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
608 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
609
d35df41eac69 Initial revision
kono
parents:
diff changeset
610 みたいな感じ。でも、そうするとscope rule を変える必要があるので厳しい。
d35df41eac69 Initial revision
kono
parents:
diff changeset
611 ま、悪くはないけどね。
d35df41eac69 Initial revision
kono
parents:
diff changeset
612
d35df41eac69 Initial revision
kono
parents:
diff changeset
613 continuation を明示する方法もある。
d35df41eac69 Initial revision
kono
parents:
diff changeset
614
d35df41eac69 Initial revision
kono
parents:
diff changeset
615 main()
d35df41eac69 Initial revision
kono
parents:
diff changeset
616 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
617 goto code1(continuation);
d35df41eac69 Initial revision
kono
parents:
diff changeset
618 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
619 code code1(ret)
d35df41eac69 Initial revision
kono
parents:
diff changeset
620 code (*ret)();
d35df41eac69 Initial revision
kono
parents:
diff changeset
621 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
622 goto *ret;
d35df41eac69 Initial revision
kono
parents:
diff changeset
623 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
624
d35df41eac69 Initial revision
kono
parents:
diff changeset
625 かな? call/cc ?
d35df41eac69 Initial revision
kono
parents:
diff changeset
626
d35df41eac69 Initial revision
kono
parents:
diff changeset
627 label へのgotoを許すのもいいけど、
d35df41eac69 Initial revision
kono
parents:
diff changeset
628 でも、label を許すと、すごくspagettyにならない?
d35df41eac69 Initial revision
kono
parents:
diff changeset
629
d35df41eac69 Initial revision
kono
parents:
diff changeset
630
d35df41eac69 Initial revision
kono
parents:
diff changeset
631 Tue Jan 4 11:47:24 JST 2000
d35df41eac69 Initial revision
kono
parents:
diff changeset
632
d35df41eac69 Initial revision
kono
parents:
diff changeset
633 contiunation じゃなくて、return keyword を使おう。
d35df41eac69 Initial revision
kono
parents:
diff changeset
634 (実際、continuation と少し違うし)
d35df41eac69 Initial revision
kono
parents:
diff changeset
635 type が少し変になるけど、まあ良い。
d35df41eac69 Initial revision
kono
parents:
diff changeset
636
d35df41eac69 Initial revision
kono
parents:
diff changeset
637 int
d35df41eac69 Initial revision
kono
parents:
diff changeset
638 main()
d35df41eac69 Initial revision
kono
parents:
diff changeset
639 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
640 goto code1(return);
d35df41eac69 Initial revision
kono
parents:
diff changeset
641 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
642 code code1(ret)
d35df41eac69 Initial revision
kono
parents:
diff changeset
643 code (*ret)(int);
d35df41eac69 Initial revision
kono
parents:
diff changeset
644 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
645 goto *ret(3);
d35df41eac69 Initial revision
kono
parents:
diff changeset
646 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
647
d35df41eac69 Initial revision
kono
parents:
diff changeset
648 だな。prototype も付けないといけないか。
d35df41eac69 Initial revision
kono
parents:
diff changeset
649
d35df41eac69 Initial revision
kono
parents:
diff changeset
650 Tue Jan 4 12:21:44 JST 2000
d35df41eac69 Initial revision
kono
parents:
diff changeset
651
d35df41eac69 Initial revision
kono
parents:
diff changeset
652 これだとmethodがすべてstatic になってしまう。dynamic なmethod
d35df41eac69 Initial revision
kono
parents:
diff changeset
653 呼び出しにするには? dipatcher を自分で作ることになる。かなり
d35df41eac69 Initial revision
kono
parents:
diff changeset
654 めんどくさいが...
d35df41eac69 Initial revision
kono
parents:
diff changeset
655
d35df41eac69 Initial revision
kono
parents:
diff changeset
656 code method(obj,arg)
d35df41eac69 Initial revision
kono
parents:
diff changeset
657 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
658 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
659
d35df41eac69 Initial revision
kono
parents:
diff changeset
660 か、あるいは、inline にするか... #define のかわりに inline ねぇ。
d35df41eac69 Initial revision
kono
parents:
diff changeset
661 これはあとで考えて良い。
d35df41eac69 Initial revision
kono
parents:
diff changeset
662
d35df41eac69 Initial revision
kono
parents:
diff changeset
663 Tue Jan 4 14:22:19 JST 2000
d35df41eac69 Initial revision
kono
parents:
diff changeset
664
d35df41eac69 Initial revision
kono
parents:
diff changeset
665 main の変数を書き潰すのと、gotgo (*reg)(123) での値は、
d35df41eac69 Initial revision
kono
parents:
diff changeset
666 register 渡しで、current register にのらないので、
d35df41eac69 Initial revision
kono
parents:
diff changeset
667 結局、return label は専用に作る必要がある。
d35df41eac69 Initial revision
kono
parents:
diff changeset
668
d35df41eac69 Initial revision
kono
parents:
diff changeset
669 Tue Jan 4 18:14:07 JST 2000
d35df41eac69 Initial revision
kono
parents:
diff changeset
670
d35df41eac69 Initial revision
kono
parents:
diff changeset
671 stack を継ぎ足して、呼び出す方式を取れば、call by value
d35df41eac69 Initial revision
kono
parents:
diff changeset
672 のregister 渡しを制限する必要は無くなる。
d35df41eac69 Initial revision
kono
parents:
diff changeset
673
d35df41eac69 Initial revision
kono
parents:
diff changeset
674 複数の値を返すことも容易だ。
d35df41eac69 Initial revision
kono
parents:
diff changeset
675
d35df41eac69 Initial revision
kono
parents:
diff changeset
676 .file "tmp.c"
d35df41eac69 Initial revision
kono
parents:
diff changeset
677 .version "01.01"
d35df41eac69 Initial revision
kono
parents:
diff changeset
678 gcc2_compiled.:
d35df41eac69 Initial revision
kono
parents:
diff changeset
679 .text
d35df41eac69 Initial revision
kono
parents:
diff changeset
680 #
d35df41eac69 Initial revision
kono
parents:
diff changeset
681 # code name(a,b,c,d,e,f)
d35df41eac69 Initial revision
kono
parents:
diff changeset
682 .align 2
d35df41eac69 Initial revision
kono
parents:
diff changeset
683 .globl code
d35df41eac69 Initial revision
kono
parents:
diff changeset
684 code:
d35df41eac69 Initial revision
kono
parents:
diff changeset
685 .type code,@function
d35df41eac69 Initial revision
kono
parents:
diff changeset
686 # struct arg *a,*b,*c,*d,*e,*f;
d35df41eac69 Initial revision
kono
parents:
diff changeset
687 # {
d35df41eac69 Initial revision
kono
parents:
diff changeset
688 # int g;
d35df41eac69 Initial revision
kono
parents:
diff changeset
689 # goto name(a,b,d,e,f);
d35df41eac69 Initial revision
kono
parents:
diff changeset
690 jmp name
d35df41eac69 Initial revision
kono
parents:
diff changeset
691 _5:
d35df41eac69 Initial revision
kono
parents:
diff changeset
692 .size code,_5-code
d35df41eac69 Initial revision
kono
parents:
diff changeset
693 .ident "Micro-C compiled"
d35df41eac69 Initial revision
kono
parents:
diff changeset
694
d35df41eac69 Initial revision
kono
parents:
diff changeset
695 おお?!
d35df41eac69 Initial revision
kono
parents:
diff changeset
696 %esp new %esp = old %esp - 12 -4
d35df41eac69 Initial revision
kono
parents:
diff changeset
697 %ebp-4 = g
d35df41eac69 Initial revision
kono
parents:
diff changeset
698 %esi = a
d35df41eac69 Initial revision
kono
parents:
diff changeset
699 %edi = b
d35df41eac69 Initial revision
kono
parents:
diff changeset
700 %ebp = old %esp 0
d35df41eac69 Initial revision
kono
parents:
diff changeset
701 %ebp+4 = c code_arg_offset=0
d35df41eac69 Initial revision
kono
parents:
diff changeset
702 %ebp+8 = d
d35df41eac69 Initial revision
kono
parents:
diff changeset
703 %ebp+12 = e
d35df41eac69 Initial revision
kono
parents:
diff changeset
704 %ebp+16 = f
d35df41eac69 Initial revision
kono
parents:
diff changeset
705
d35df41eac69 Initial revision
kono
parents:
diff changeset
706 interface は付けよう! というか、
d35df41eac69 Initial revision
kono
parents:
diff changeset
707 goto name(struct {xxxx})
d35df41eac69 Initial revision
kono
parents:
diff changeset
708 みたいな感じで良いわけね。どれをregisterにいれるかと言う問題はあるが。
d35df41eac69 Initial revision
kono
parents:
diff changeset
709
d35df41eac69 Initial revision
kono
parents:
diff changeset
710 で、どうやってcallすればいいわけ? emit_pushするかわりにpush
d35df41eac69 Initial revision
kono
parents:
diff changeset
711 する?
d35df41eac69 Initial revision
kono
parents:
diff changeset
712
d35df41eac69 Initial revision
kono
parents:
diff changeset
713 うう、これでは、だめか。code argument の数が変わると、
d35df41eac69 Initial revision
kono
parents:
diff changeset
714 ebp をいちいち動かすことになる。そこにはold sp があるから
d35df41eac69 Initial revision
kono
parents:
diff changeset
715 そいつもコピーする必要がある。
d35df41eac69 Initial revision
kono
parents:
diff changeset
716
d35df41eac69 Initial revision
kono
parents:
diff changeset
717 %esp new %esp = old %esp - 20
d35df41eac69 Initial revision
kono
parents:
diff changeset
718 %ebp-20 = g
d35df41eac69 Initial revision
kono
parents:
diff changeset
719 %esi = a
d35df41eac69 Initial revision
kono
parents:
diff changeset
720 %edi = b
d35df41eac69 Initial revision
kono
parents:
diff changeset
721 %ebp-16 = c code_arg_offset= -16 ((nargs-max_reg)*int_size)
d35df41eac69 Initial revision
kono
parents:
diff changeset
722 %ebp-12 = d
d35df41eac69 Initial revision
kono
parents:
diff changeset
723 %ebp-8 = e
d35df41eac69 Initial revision
kono
parents:
diff changeset
724 %ebp-4 = f
d35df41eac69 Initial revision
kono
parents:
diff changeset
725 %ebp = old %esp 0
d35df41eac69 Initial revision
kono
parents:
diff changeset
726
d35df41eac69 Initial revision
kono
parents:
diff changeset
727 そうか、function からcallする時には、local 変数を書き潰して良い。
d35df41eac69 Initial revision
kono
parents:
diff changeset
728
d35df41eac69 Initial revision
kono
parents:
diff changeset
729 # goto name(a,b,d,e,f);
d35df41eac69 Initial revision
kono
parents:
diff changeset
730
d35df41eac69 Initial revision
kono
parents:
diff changeset
731 %esp new %esp = old %esp - 20
d35df41eac69 Initial revision
kono
parents:
diff changeset
732 %ebp-20 = g
d35df41eac69 Initial revision
kono
parents:
diff changeset
733 %esi = a
d35df41eac69 Initial revision
kono
parents:
diff changeset
734 %edi = b
d35df41eac69 Initial revision
kono
parents:
diff changeset
735 %ebp-16 = c code_arg_offset= -16 ((nargs-max_reg)*int_size)
d35df41eac69 Initial revision
kono
parents:
diff changeset
736 %ebp-12 = d
d35df41eac69 Initial revision
kono
parents:
diff changeset
737 %ebp-8 = e
d35df41eac69 Initial revision
kono
parents:
diff changeset
738 %ebp-4 = f
d35df41eac69 Initial revision
kono
parents:
diff changeset
739 %ebp = old %esp 0 disp=0 (*)
d35df41eac69 Initial revision
kono
parents:
diff changeset
740 local1 <----16 local variable
d35df41eac69 Initial revision
kono
parents:
diff changeset
741 %edx -12 <- disp_offset
d35df41eac69 Initial revision
kono
parents:
diff changeset
742 %ecx -8
d35df41eac69 Initial revision
kono
parents:
diff changeset
743 %ebx -4
d35df41eac69 Initial revision
kono
parents:
diff changeset
744 %ebp = %esp 0
d35df41eac69 Initial revision
kono
parents:
diff changeset
745 %eip 4 <- arg_offset
d35df41eac69 Initial revision
kono
parents:
diff changeset
746
d35df41eac69 Initial revision
kono
parents:
diff changeset
747 となる。ということは、pushl %ebp は、間違い。
d35df41eac69 Initial revision
kono
parents:
diff changeset
748
d35df41eac69 Initial revision
kono
parents:
diff changeset
749 だけど、%ebp をそのまま使うのは良くない。disp_offset がかかっているから。
d35df41eac69 Initial revision
kono
parents:
diff changeset
750 だから、もう一度 pushl %ebp したほうがよい。しかし、push する先は、
d35df41eac69 Initial revision
kono
parents:
diff changeset
751 上の、(*)。
d35df41eac69 Initial revision
kono
parents:
diff changeset
752 leave movl %ebp,%esp
d35df41eac69 Initial revision
kono
parents:
diff changeset
753 popl %ebp
d35df41eac69 Initial revision
kono
parents:
diff changeset
754 じゃなかったか?
d35df41eac69 Initial revision
kono
parents:
diff changeset
755
d35df41eac69 Initial revision
kono
parents:
diff changeset
756 Thu Jan 6 13:00:33 JST 2000
d35df41eac69 Initial revision
kono
parents:
diff changeset
757
d35df41eac69 Initial revision
kono
parents:
diff changeset
758 できたね。これでとりあえず動くはず。速度は問題だが...
d35df41eac69 Initial revision
kono
parents:
diff changeset
759 あとは、
d35df41eac69 Initial revision
kono
parents:
diff changeset
760 ANSI-C prototype
d35df41eac69 Initial revision
kono
parents:
diff changeset
761 ANSI-C prototype check
d35df41eac69 Initial revision
kono
parents:
diff changeset
762 Interface Definietion
d35df41eac69 Initial revision
kono
parents:
diff changeset
763 GC support
d35df41eac69 Initial revision
kono
parents:
diff changeset
764 Direct handling of Frame
d35df41eac69 Initial revision
kono
parents:
diff changeset
765 だね。簡単に出来そう? たぶん...
d35df41eac69 Initial revision
kono
parents:
diff changeset
766
d35df41eac69 Initial revision
kono
parents:
diff changeset
767 Fri Jan 7 09:42:53 JST 2000
d35df41eac69 Initial revision
kono
parents:
diff changeset
768
d35df41eac69 Initial revision
kono
parents:
diff changeset
769 goto 文が動いてなかった。あと peep hole optimization version も
d35df41eac69 Initial revision
kono
parents:
diff changeset
770 作るか?
d35df41eac69 Initial revision
kono
parents:
diff changeset
771
d35df41eac69 Initial revision
kono
parents:
diff changeset
772 continuation として label を送れるようにするべきか?
d35df41eac69 Initial revision
kono
parents:
diff changeset
773 そうすると便利なんだけど、ちょっと、汚いプログラムが
d35df41eac69 Initial revision
kono
parents:
diff changeset
774 出来るようになる。あと、送り側の環境(frame)を維持する
d35df41eac69 Initial revision
kono
parents:
diff changeset
775 必要がある。ま、できなくはないか...
d35df41eac69 Initial revision
kono
parents:
diff changeset
776
d35df41eac69 Initial revision
kono
parents:
diff changeset
777 そうすると、label が値を持つようになる。
d35df41eac69 Initial revision
kono
parents:
diff changeset
778 a = label:;
d35df41eac69 Initial revision
kono
parents:
diff changeset
779 とか。うーん。label:(a,b,c) {}; みたいな形で、parallel 代入を許すと言う
d35df41eac69 Initial revision
kono
parents:
diff changeset
780 手もあるね。
d35df41eac69 Initial revision
kono
parents:
diff changeset
781
d35df41eac69 Initial revision
kono
parents:
diff changeset
782 こちらの方がCとの相性は良いが... main() { label:(){ ... } }
d35df41eac69 Initial revision
kono
parents:
diff changeset
783 みたいなnestを許すかどうかと言う問題がある。
d35df41eac69 Initial revision
kono
parents:
diff changeset
784 変数の参照を許さなければ、特に問題はない。
d35df41eac69 Initial revision
kono
parents:
diff changeset
785
d35df41eac69 Initial revision
kono
parents:
diff changeset
786 a = label: は、二重の意味があるなぁ。
d35df41eac69 Initial revision
kono
parents:
diff changeset
787
d35df41eac69 Initial revision
kono
parents:
diff changeset
788 言語の名前。DinnerBell II とか? join も入れる?
d35df41eac69 Initial revision
kono
parents:
diff changeset
789 code entry_a().entry_b() {}
d35df41eac69 Initial revision
kono
parents:
diff changeset
790 ですか? parallel call も?
d35df41eac69 Initial revision
kono
parents:
diff changeset
791
d35df41eac69 Initial revision
kono
parents:
diff changeset
792 Fri Jan 7 19:53:53 JST 2000
d35df41eac69 Initial revision
kono
parents:
diff changeset
793
d35df41eac69 Initial revision
kono
parents:
diff changeset
794 いまのままだと return が環境を持ってないから、大域脱出できない。
d35df41eac69 Initial revision
kono
parents:
diff changeset
795 まぁ、環境を入れてもいいんだけど、どこに置くかと言う問題が
d35df41eac69 Initial revision
kono
parents:
diff changeset
796 あるね。
d35df41eac69 Initial revision
kono
parents:
diff changeset
797
d35df41eac69 Initial revision
kono
parents:
diff changeset
798 そうじゃなくて、return 側で判断するか?
d35df41eac69 Initial revision
kono
parents:
diff changeset
799 retrun(ID)
d35df41eac69 Initial revision
kono
parents:
diff changeset
800 みたいな形でIDで判断する。そうすれば、return 側でID
d35df41eac69 Initial revision
kono
parents:
diff changeset
801 を見て判断できる。けど...
d35df41eac69 Initial revision
kono
parents:
diff changeset
802
d35df41eac69 Initial revision
kono
parents:
diff changeset
803 まぁ、はやり、環境を持って歩く方がいいかなぁ。でも、
d35df41eac69 Initial revision
kono
parents:
diff changeset
804 引き渡しているから、二つ引き渡して、片方を使われたときに、
d35df41eac69 Initial revision
kono
parents:
diff changeset
805 反対側が消えてしまうのはいたいよね。今のままならば、
d35df41eac69 Initial revision
kono
parents:
diff changeset
806 そういうことは起こらない。
d35df41eac69 Initial revision
kono
parents:
diff changeset
807
d35df41eac69 Initial revision
kono
parents:
diff changeset
808 continuation 特有の問題を避けるなら、このままでもいいんだが...
d35df41eac69 Initial revision
kono
parents:
diff changeset
809 contrinuation や環境は、このシステムでは自分で作ることが
d35df41eac69 Initial revision
kono
parents:
diff changeset
810 できるからね。
d35df41eac69 Initial revision
kono
parents:
diff changeset
811
d35df41eac69 Initial revision
kono
parents:
diff changeset
812 そうなんだけど.... retlabel や retcont は実はオブジェクト
d35df41eac69 Initial revision
kono
parents:
diff changeset
813 全体に一つあれば良い。
d35df41eac69 Initial revision
kono
parents:
diff changeset
814
d35df41eac69 Initial revision
kono
parents:
diff changeset
815 引数を渡すときに、そこに環境へのポインタをいれてやれば良いので、
d35df41eac69 Initial revision
kono
parents:
diff changeset
816 解決は割と簡単だが、そうすると、例の構造体を引数で渡すと言う
d35df41eac69 Initial revision
kono
parents:
diff changeset
817 問題を解決する必要がある。
d35df41eac69 Initial revision
kono
parents:
diff changeset
818
d35df41eac69 Initial revision
kono
parents:
diff changeset
819 でも、今の実装ならば、まったく同じ変数の構成ならばコピーは
d35df41eac69 Initial revision
kono
parents:
diff changeset
820 実際には起こらないわけだから問題ないはず。特に、それを保証するために、
d35df41eac69 Initial revision
kono
parents:
diff changeset
821 interface を実装する必要がある。
d35df41eac69 Initial revision
kono
parents:
diff changeset
822
d35df41eac69 Initial revision
kono
parents:
diff changeset
823 return ->
d35df41eac69 Initial revision
kono
parents:
diff changeset
824 (void *)old bp
d35df41eac69 Initial revision
kono
parents:
diff changeset
825 return address
d35df41eac69 Initial revision
kono
parents:
diff changeset
826
d35df41eac69 Initial revision
kono
parents:
diff changeset
827 bp を直接操作できるようにするといいんだけど....
d35df41eac69 Initial revision
kono
parents:
diff changeset
828
d35df41eac69 Initial revision
kono
parents:
diff changeset
829 Sat Jan 8 08:49:59 JST 2000
d35df41eac69 Initial revision
kono
parents:
diff changeset
830
d35df41eac69 Initial revision
kono
parents:
diff changeset
831 今は、code 内ではreturnできないわけだけど。実は、return って、
d35df41eac69 Initial revision
kono
parents:
diff changeset
832 code return0(i) int i; { return(i); }
d35df41eac69 Initial revision
kono
parents:
diff changeset
833 か? 今は禁止してないから書けちゃうよね。どういうcodeが出るんだろう?
d35df41eac69 Initial revision
kono
parents:
diff changeset
834
d35df41eac69 Initial revision
kono
parents:
diff changeset
835 doreturn() では retpending をセットしているだけだから、control=1
d35df41eac69 Initial revision
kono
parents:
diff changeset
836 のまま。で、code の終りにくるのでエラーになる。checkret は、
d35df41eac69 Initial revision
kono
parents:
diff changeset
837 statement の引数で判断するようにしたほうが合理的だろう。
d35df41eac69 Initial revision
kono
parents:
diff changeset
838
d35df41eac69 Initial revision
kono
parents:
diff changeset
839 大域脱出は結構根が深いよね。途中をスキップされてうれしいか?
d35df41eac69 Initial revision
kono
parents:
diff changeset
840 destructor と同じで、途中のcodeは全部呼びたいのが普通だろう。
d35df41eac69 Initial revision
kono
parents:
diff changeset
841
d35df41eac69 Initial revision
kono
parents:
diff changeset
842 bp が同じになるまで return すれば良いわけだよね。
d35df41eac69 Initial revision
kono
parents:
diff changeset
843 return と同じで、明示的に環境を引き渡すようにするか。
d35df41eac69 Initial revision
kono
parents:
diff changeset
844 type は void * で良い?
d35df41eac69 Initial revision
kono
parents:
diff changeset
845
d35df41eac69 Initial revision
kono
parents:
diff changeset
846 return する時にstackの上限を越えているかどうかを自分でチェックする
d35df41eac69 Initial revision
kono
parents:
diff changeset
847 必要があるね。誰にreturnするかをcodeで明示すれば良いわけだけど。
d35df41eac69 Initial revision
kono
parents:
diff changeset
848
d35df41eac69 Initial revision
kono
parents:
diff changeset
849 code return0(i) int i; { return(i); }
d35df41eac69 Initial revision
kono
parents:
diff changeset
850
d35df41eac69 Initial revision
kono
parents:
diff changeset
851 を許して、そこで、frame pointer を大域あるいは渡した引数と
d35df41eac69 Initial revision
kono
parents:
diff changeset
852 比較して処理する?
d35df41eac69 Initial revision
kono
parents:
diff changeset
853 code return0(i,env) int i; env *env; {
d35df41eac69 Initial revision
kono
parents:
diff changeset
854 if (env==self) return(i);
d35df41eac69 Initial revision
kono
parents:
diff changeset
855 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
856 あれ? これはおかしいよね。
d35df41eac69 Initial revision
kono
parents:
diff changeset
857 code return0(i,env) int i; env *env; {
d35df41eac69 Initial revision
kono
parents:
diff changeset
858 if (env!=self) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
859 env->return();
d35df41eac69 Initial revision
kono
parents:
diff changeset
860 return(i);
d35df41eac69 Initial revision
kono
parents:
diff changeset
861 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
862 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
863 も、なんか変だよなぁ。呼び出しと逆順に帰りたいわけだが...
d35df41eac69 Initial revision
kono
parents:
diff changeset
864 実際、逆順には帰っているわけだよね。
d35df41eac69 Initial revision
kono
parents:
diff changeset
865
d35df41eac69 Initial revision
kono
parents:
diff changeset
866 return の中でこそこそ比較するという技もあるけど。
d35df41eac69 Initial revision
kono
parents:
diff changeset
867
d35df41eac69 Initial revision
kono
parents:
diff changeset
868 問題は、destructor に渡す情報だよね。もちろん、self で良いわけだが、
d35df41eac69 Initial revision
kono
parents:
diff changeset
869 このあたりは、言語外の問題で、それを明示的にしたいから、この言語を
d35df41eac69 Initial revision
kono
parents:
diff changeset
870 作っているわけなのだから、これを内部で処理するのはおかしい。
d35df41eac69 Initial revision
kono
parents:
diff changeset
871
d35df41eac69 Initial revision
kono
parents:
diff changeset
872 code return0(i) int i; { return(i); }
d35df41eac69 Initial revision
kono
parents:
diff changeset
873
d35df41eac69 Initial revision
kono
parents:
diff changeset
874 これだと、return の型が合わないと言う問題が生じるな。簡単には
d35df41eac69 Initial revision
kono
parents:
diff changeset
875 チェックできない。
d35df41eac69 Initial revision
kono
parents:
diff changeset
876 int
d35df41eac69 Initial revision
kono
parents:
diff changeset
877 main() {
d35df41eac69 Initial revision
kono
parents:
diff changeset
878 code a() {
d35df41eac69 Initial revision
kono
parents:
diff changeset
879 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
880 code b() {
d35df41eac69 Initial revision
kono
parents:
diff changeset
881 return(i);
d35df41eac69 Initial revision
kono
parents:
diff changeset
882 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
883 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
884 にすれば、check はできるようになる。でも、これだと、
d35df41eac69 Initial revision
kono
parents:
diff changeset
885 int
d35df41eac69 Initial revision
kono
parents:
diff changeset
886 main() {
d35df41eac69 Initial revision
kono
parents:
diff changeset
887 a: {
d35df41eac69 Initial revision
kono
parents:
diff changeset
888 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
889 b: {
d35df41eac69 Initial revision
kono
parents:
diff changeset
890 return(i);
d35df41eac69 Initial revision
kono
parents:
diff changeset
891 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
892 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
893 と差がない。module 化を言語外でやるというのが主旨なのだから、これでは
d35df41eac69 Initial revision
kono
parents:
diff changeset
894 まずい。これは高級アセンブラなのだから。
d35df41eac69 Initial revision
kono
parents:
diff changeset
895
d35df41eac69 Initial revision
kono
parents:
diff changeset
896 あそうか、return と、大域脱出時のabortとは、状況が違う。だから、
d35df41eac69 Initial revision
kono
parents:
diff changeset
897 別なcode を呼び出さないとだめ。あるいは、値で区別するか。これは、
d35df41eac69 Initial revision
kono
parents:
diff changeset
898 logic programming のfail/success と似ている。
d35df41eac69 Initial revision
kono
parents:
diff changeset
899 main() { } abort { ... }
d35df41eac69 Initial revision
kono
parents:
diff changeset
900 でもいいけど?
d35df41eac69 Initial revision
kono
parents:
diff changeset
901 main() { code abort { ... }; code return { ... }}
d35df41eac69 Initial revision
kono
parents:
diff changeset
902 かな?
d35df41eac69 Initial revision
kono
parents:
diff changeset
903
d35df41eac69 Initial revision
kono
parents:
diff changeset
904 本来、subroutine call自体が、かなりの省略形なわけだから、これは
d35df41eac69 Initial revision
kono
parents:
diff changeset
905 仕方がない。今のままで通常のsubroutine callをシミュレートできるのか?
d35df41eac69 Initial revision
kono
parents:
diff changeset
906 code (struct arg {...},void *sp) {
d35df41eac69 Initial revision
kono
parents:
diff changeset
907 struct env;
d35df41eac69 Initial revision
kono
parents:
diff changeset
908 push(sp,arg);
d35df41eac69 Initial revision
kono
parents:
diff changeset
909 push(env,arg);
d35df41eac69 Initial revision
kono
parents:
diff changeset
910 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
911 できるけど、ちょっと重い。やはり、frame pointer を直接操作しないと
d35df41eac69 Initial revision
kono
parents:
diff changeset
912 だめ。
d35df41eac69 Initial revision
kono
parents:
diff changeset
913
d35df41eac69 Initial revision
kono
parents:
diff changeset
914 goto 文のほうに、env を一緒に送るものを作ったほうがいいのかも。
d35df41eac69 Initial revision
kono
parents:
diff changeset
915 goto (*ret)(),environment;
d35df41eac69 Initial revision
kono
parents:
diff changeset
916 かな。type は? (void *)?
d35df41eac69 Initial revision
kono
parents:
diff changeset
917 goto ret(),environment;
d35df41eac69 Initial revision
kono
parents:
diff changeset
918 にはならないの? そうすれば、自分でthreadを制御できる。environment
d35df41eac69 Initial revision
kono
parents:
diff changeset
919 の正当性を評価しなくて良いの? まぁ、ねぇ。
d35df41eac69 Initial revision
kono
parents:
diff changeset
920
d35df41eac69 Initial revision
kono
parents:
diff changeset
921 これは実装は容易だが... goto といちいち書くのが本当にいいのか?
d35df41eac69 Initial revision
kono
parents:
diff changeset
922 env に対するoperationがあった方がいいなぁ。push とか?
d35df41eac69 Initial revision
kono
parents:
diff changeset
923
d35df41eac69 Initial revision
kono
parents:
diff changeset
924 code return0(i) int i; { return(i); }
d35df41eac69 Initial revision
kono
parents:
diff changeset
925
d35df41eac69 Initial revision
kono
parents:
diff changeset
926 を認めれば、return 擬変数はいらなくなる。
d35df41eac69 Initial revision
kono
parents:
diff changeset
927
d35df41eac69 Initial revision
kono
parents:
diff changeset
928 でも、実は、return は、caller の引数の数と一致してないといけない
d35df41eac69 Initial revision
kono
parents:
diff changeset
929 わけだから、 code return0(i) int i; { return(i); } はだめ。env
d35df41eac69 Initial revision
kono
parents:
diff changeset
930 と一致してないといけない。ということは分離するとまずいんじゃない?
d35df41eac69 Initial revision
kono
parents:
diff changeset
931 あれ? そんなはずないな。
d35df41eac69 Initial revision
kono
parents:
diff changeset
932
d35df41eac69 Initial revision
kono
parents:
diff changeset
933 Sun Jan 9 01:15:56 JST 2000
d35df41eac69 Initial revision
kono
parents:
diff changeset
934
d35df41eac69 Initial revision
kono
parents:
diff changeset
935 やはり、分離してはまずい。もともと、
d35df41eac69 Initial revision
kono
parents:
diff changeset
936 goto func(arg);
d35df41eac69 Initial revision
kono
parents:
diff changeset
937 自体が、
d35df41eac69 Initial revision
kono
parents:
diff changeset
938 goto func(arg) with current.env
d35df41eac69 Initial revision
kono
parents:
diff changeset
939 みたいなものだ。つまり、これは、DinnerBell の、
d35df41eac69 Initial revision
kono
parents:
diff changeset
940 self message: arg
d35df41eac69 Initial revision
kono
parents:
diff changeset
941 と同じ。self->func(arg); でも良い。が、function callと区別が付かないのは
d35df41eac69 Initial revision
kono
parents:
diff changeset
942 良くない。
d35df41eac69 Initial revision
kono
parents:
diff changeset
943
d35df41eac69 Initial revision
kono
parents:
diff changeset
944 そうすると、type code はsize int でなくなる。
d35df41eac69 Initial revision
kono
parents:
diff changeset
945 code *p = func;
d35df41eac69 Initial revision
kono
parents:
diff changeset
946 ではいけなくて、
d35df41eac69 Initial revision
kono
parents:
diff changeset
947 code p = {func,env};
d35df41eac69 Initial revision
kono
parents:
diff changeset
948 でないといけない。実際、
d35df41eac69 Initial revision
kono
parents:
diff changeset
949 goto func(arg)
d35df41eac69 Initial revision
kono
parents:
diff changeset
950 では、current environment を pushl %ebp でstack = current env
d35df41eac69 Initial revision
kono
parents:
diff changeset
951 に積んでいるわけだから。
d35df41eac69 Initial revision
kono
parents:
diff changeset
952
d35df41eac69 Initial revision
kono
parents:
diff changeset
953 いずれにせよ、
d35df41eac69 Initial revision
kono
parents:
diff changeset
954 struct p = q;
d35df41eac69 Initial revision
kono
parents:
diff changeset
955 は実装する必要がある。localな、
d35df41eac69 Initial revision
kono
parents:
diff changeset
956 code p = {func,env};
d35df41eac69 Initial revision
kono
parents:
diff changeset
957 も動くはずだが...
d35df41eac69 Initial revision
kono
parents:
diff changeset
958
d35df41eac69 Initial revision
kono
parents:
diff changeset
959 code (*p)();
d35df41eac69 Initial revision
kono
parents:
diff changeset
960 goto (*p)(arg);
d35df41eac69 Initial revision
kono
parents:
diff changeset
961
d35df41eac69 Initial revision
kono
parents:
diff changeset
962 はだから少しおかしい。これは、goto がenv を補っていると考えるべき。
d35df41eac69 Initial revision
kono
parents:
diff changeset
963
d35df41eac69 Initial revision
kono
parents:
diff changeset
964 このようにすると、常に、
d35df41eac69 Initial revision
kono
parents:
diff changeset
965 func,env
d35df41eac69 Initial revision
kono
parents:
diff changeset
966 の組をcodeとみなすことになる。これは、object と呼ぶべきだ。
d35df41eac69 Initial revision
kono
parents:
diff changeset
967 ただ、既存のobjectとは別だよな。actor の方が良い?
d35df41eac69 Initial revision
kono
parents:
diff changeset
968
d35df41eac69 Initial revision
kono
parents:
diff changeset
969 うーん、これでjoinを入れれば、完璧なDinnerBellだな。並列送信はないけど。
d35df41eac69 Initial revision
kono
parents:
diff changeset
970
d35df41eac69 Initial revision
kono
parents:
diff changeset
971 Sun Jan 9 01:40:05 JST 2000
d35df41eac69 Initial revision
kono
parents:
diff changeset
972
d35df41eac69 Initial revision
kono
parents:
diff changeset
973 local 変数の初期化はallocation の後に遅らせる必要がある。
d35df41eac69 Initial revision
kono
parents:
diff changeset
974 nptr に入れられるはずだよね? nptr に初期化フラグを足すか?
d35df41eac69 Initial revision
kono
parents:
diff changeset
975
d35df41eac69 Initial revision
kono
parents:
diff changeset
976 文途中で出現するlocal変数の初期化。ちゃんと動いているの?
d35df41eac69 Initial revision
kono
parents:
diff changeset
977
d35df41eac69 Initial revision
kono
parents:
diff changeset
978 構造体のcopyは、lcheck を修正すべきでない。
d35df41eac69 Initial revision
kono
parents:
diff changeset
979
d35df41eac69 Initial revision
kono
parents:
diff changeset
980 Sun Jan 9 08:49:43 JST 2000
d35df41eac69 Initial revision
kono
parents:
diff changeset
981
d35df41eac69 Initial revision
kono
parents:
diff changeset
982 うーん、なんか修正が多いなぁ。あと、関数呼び出し、goto 文の
d35df41eac69 Initial revision
kono
parents:
diff changeset
983 構造体への対応か。
d35df41eac69 Initial revision
kono
parents:
diff changeset
984
d35df41eac69 Initial revision
kono
parents:
diff changeset
985 goto (*code)();
d35df41eac69 Initial revision
kono
parents:
diff changeset
986
d35df41eac69 Initial revision
kono
parents:
diff changeset
987 が、self env を使うのか、code の先の値を使うのかを区別する
d35df41eac69 Initial revision
kono
parents:
diff changeset
988 必要がある。もし*を使わないとするとlabel(FNAME)との区別が
d35df41eac69 Initial revision
kono
parents:
diff changeset
989 つかないぞ。あ、でも、環境を持ち歩くことにしたから、label
d35df41eac69 Initial revision
kono
parents:
diff changeset
990 へもjumpしようと思えばできるね。
d35df41eac69 Initial revision
kono
parents:
diff changeset
991
d35df41eac69 Initial revision
kono
parents:
diff changeset
992 並列送信はなくても、この構成ならばstatement単位の並列性を検出するのは
d35df41eac69 Initial revision
kono
parents:
diff changeset
993 容易だろう。
d35df41eac69 Initial revision
kono
parents:
diff changeset
994
d35df41eac69 Initial revision
kono
parents:
diff changeset
995 やればできるけど、この修正の量だと1日じゃ終らないかなぁ。
d35df41eac69 Initial revision
kono
parents:
diff changeset
996 不動小数点も入れるのでしょう?
d35df41eac69 Initial revision
kono
parents:
diff changeset
997
d35df41eac69 Initial revision
kono
parents:
diff changeset
998 Mon Jan 10 09:00:12 JST 2000
d35df41eac69 Initial revision
kono
parents:
diff changeset
999
d35df41eac69 Initial revision
kono
parents:
diff changeset
1000 引数に構造体を許すには、必ずANSI-Cにする必要がある。難しくは
d35df41eac69 Initial revision
kono
parents:
diff changeset
1001 ないが...
d35df41eac69 Initial revision
kono
parents:
diff changeset
1002
d35df41eac69 Initial revision
kono
parents:
diff changeset
1003 goto 文には label, code, continuation の3つが来る。
d35df41eac69 Initial revision
kono
parents:
diff changeset
1004 continuation = code + env
d35df41eac69 Initial revision
kono
parents:
diff changeset
1005 | label +env
d35df41eac69 Initial revision
kono
parents:
diff changeset
1006 なのだが、code/label では、env の内容が異なる。できれば面白いが、
d35df41eac69 Initial revision
kono
parents:
diff changeset
1007 その価値はあるのか?
d35df41eac69 Initial revision
kono
parents:
diff changeset
1008
d35df41eac69 Initial revision
kono
parents:
diff changeset
1009 しかし、code , env を分離するとあまりに危険すぎる。どうせgoto
d35df41eac69 Initial revision
kono
parents:
diff changeset
1010 が危険なんだからいいか? その方が簡単。簡単なら、そっちの方法を
d35df41eac69 Initial revision
kono
parents:
diff changeset
1011 とるべきじゃない? うーん。
d35df41eac69 Initial revision
kono
parents:
diff changeset
1012
d35df41eac69 Initial revision
kono
parents:
diff changeset
1013 return の関数依存性はなくした方が良い。
d35df41eac69 Initial revision
kono
parents:
diff changeset
1014 一つにするのは、pop の問題があるので良くないが...
d35df41eac69 Initial revision
kono
parents:
diff changeset
1015
d35df41eac69 Initial revision
kono
parents:
diff changeset
1016 そうか、ret をenvを指定して戻るようにしたから、leave する必要は
d35df41eac69 Initial revision
kono
parents:
diff changeset
1017 なくなった。そして、push %ebp に相当する部分は、lea -disp(%ebp),%sp
d35df41eac69 Initial revision
kono
parents:
diff changeset
1018 で消去されている。ということは、jump のfunction依存部分はいらない
d35df41eac69 Initial revision
kono
parents:
diff changeset
1019 ということだね。
d35df41eac69 Initial revision
kono
parents:
diff changeset
1020
d35df41eac69 Initial revision
kono
parents:
diff changeset
1021 でも、汚いなぁ。read only属性をhardware supportできればなあ。
d35df41eac69 Initial revision
kono
parents:
diff changeset
1022
d35df41eac69 Initial revision
kono
parents:
diff changeset
1023 sched_yeilds() 相当を書けるかな? lock は?
d35df41eac69 Initial revision
kono
parents:
diff changeset
1024
d35df41eac69 Initial revision
kono
parents:
diff changeset
1025 一応、できたけど、やっぱり汚い。
d35df41eac69 Initial revision
kono
parents:
diff changeset
1026
d35df41eac69 Initial revision
kono
parents:
diff changeset
1027 Wed Jan 12 16:12:27 JST 2000
d35df41eac69 Initial revision
kono
parents:
diff changeset
1028
d35df41eac69 Initial revision
kono
parents:
diff changeset
1029 あは。ANSI prototype はめんどい。
d35df41eac69 Initial revision
kono
parents:
diff changeset
1030 bexpr()
d35df41eac69 Initial revision
kono
parents:
diff changeset
1031 で、関数での引数の順序と、そのあとの宣言の順序が変わることがある。
d35df41eac69 Initial revision
kono
parents:
diff changeset
1032 そうすると、うしろの方が優先されてしまう。これは、こまる。
d35df41eac69 Initial revision
kono
parents:
diff changeset
1033
d35df41eac69 Initial revision
kono
parents:
diff changeset
1034 そうか、code_arg_offset のような方法だと、ANSI style では、
d35df41eac69 Initial revision
kono
parents:
diff changeset
1035 困ってしまう。
6
bf602558130d continuation
kono
parents: 0
diff changeset
1036
bf602558130d continuation
kono
parents: 0
diff changeset
1037 Thu Jan 13 04:46:12 JST 2000
bf602558130d continuation
kono
parents: 0
diff changeset
1038
bf602558130d continuation
kono
parents: 0
diff changeset
1039 # goto name(a,b,d,e,f);
bf602558130d continuation
kono
parents: 0
diff changeset
1040 code name { int g; ...
bf602558130d continuation
kono
parents: 0
diff changeset
1041
bf602558130d continuation
kono
parents: 0
diff changeset
1042 %esp new %esp = old %esp - 20
bf602558130d continuation
kono
parents: 0
diff changeset
1043 %ebp-20 = g code's local variable
bf602558130d continuation
kono
parents: 0
diff changeset
1044 %ebp-12 = f <- new_disp
bf602558130d continuation
kono
parents: 0
diff changeset
1045 %ebp-8 = d
bf602558130d continuation
kono
parents: 0
diff changeset
1046 %ebp-4 = d
bf602558130d continuation
kono
parents: 0
diff changeset
1047 %ebp-0 = c
bf602558130d continuation
kono
parents: 0
diff changeset
1048 %edi = b
bf602558130d continuation
kono
parents: 0
diff changeset
1049 %esi = a
bf602558130d continuation
kono
parents: 0
diff changeset
1050 %ebp = old %esp 0 disp=0 new env
bf602558130d continuation
kono
parents: 0
diff changeset
1051 local1 <----16 old local variable ( to be erased )
bf602558130d continuation
kono
parents: 0
diff changeset
1052 %edx -12 <- disp_offset
bf602558130d continuation
kono
parents: 0
diff changeset
1053 %ecx -8
bf602558130d continuation
kono
parents: 0
diff changeset
1054 %ebx -4
bf602558130d continuation
kono
parents: 0
diff changeset
1055 %ebp = %esp 0 <- old env
bf602558130d continuation
kono
parents: 0
diff changeset
1056 %eip 4 <- arg_offset
bf602558130d continuation
kono
parents: 0
diff changeset
1057
bf602558130d continuation
kono
parents: 0
diff changeset
1058
bf602558130d continuation
kono
parents: 0
diff changeset
1059 Thu Jan 13 13:38:24 JST 2000
bf602558130d continuation
kono
parents: 0
diff changeset
1060
bf602558130d continuation
kono
parents: 0
diff changeset
1061 だいたいできたけど、test/tmp7.c のprintf のtype mismatch は
bf602558130d continuation
kono
parents: 0
diff changeset
1062 なんなんだろう? ASNI の副作用だろうなぁ。
7
e2c2c0fe0785 function type definition should be in global heap
kono
parents: 6
diff changeset
1063
e2c2c0fe0785 function type definition should be in global heap
kono
parents: 6
diff changeset
1064 これだと、プロセスの切替えのときには、結構な量のデータを
e2c2c0fe0785 function type definition should be in global heap
kono
parents: 6
diff changeset
1065 コピーすることになる。それでもいいんだけど...
e2c2c0fe0785 function type definition should be in global heap
kono
parents: 6
diff changeset
1066
e2c2c0fe0785 function type definition should be in global heap
kono
parents: 6
diff changeset
1067 それごと、どっかにとって置く。continuationへの参照みたいなもの
e2c2c0fe0785 function type definition should be in global heap
kono
parents: 6
diff changeset
1068 ができないかな。
e2c2c0fe0785 function type definition should be in global heap
kono
parents: 6
diff changeset
1069
e2c2c0fe0785 function type definition should be in global heap
kono
parents: 6
diff changeset
1070 コピーができれば、environment/return の組は動くわけだから、
e2c2c0fe0785 function type definition should be in global heap
kono
parents: 6
diff changeset
1071 それへの参照と切替えがあっても良いよね。
e2c2c0fe0785 function type definition should be in global heap
kono
parents: 6
diff changeset
1072